surshar / claude-code
Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.
Built by Anthropic · github.com/anthropics
| 1 | import type { ProcessRunResult } from 'claude-code' |
| 2 | |
| 3 | import type { Facts } from '../../facts' |
| 4 | import { archOf } from './arch-of' |
| 5 | import type { Machine } from './machine' |
| 6 | import { PROBE_SCRIPT } from './probe-script' |
| 7 | |
| 8 | /** |
| 9 | * Probes the machine once: on Windows (the `OS` variable says so) from the |
| 10 | * environment alone, elsewhere with one `sh` run of PROBE_SCRIPT. |
| 11 | * |
| 12 | * A probe that fails or exits non-zero leaves the system unnamed |
| 13 | * (`unknown`) and the lists empty; nothing is retried. |
| 14 | * |
| 15 | * @param run runs one program to its end |
| 16 | * @param facts the variables as read, for the Windows answer |
| 17 | * @returns the machine as probed |
| 18 | */ |
| 19 | export async function machineOf( |
| 20 | run: (argv: readonly string[]) => Promise<ProcessRunResult>, |
| 21 | facts: Facts, |
| 22 | ): Promise<Machine> { |
| 23 | if (facts.os === 'Windows_NT') { |
| 24 | return { |
| 25 | platformRaw: 'win32', |
| 26 | arch: archOf(facts.processorArchitecture ?? ''), |
| 27 | kernel: undefined, |
| 28 | packageManagers: '', |
| 29 | runtimes: '', |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | let result: ProcessRunResult | undefined |
| 34 | |
| 35 | try { |
| 36 | result = await run(['sh', '-c', PROBE_SCRIPT]) |
| 37 | } catch { |
| 38 | result = undefined |
| 39 | } |
| 40 | |
| 41 | const [system = '', kernel = '', machine = '', managers = '', runtimes = ''] = |
| 42 | (result?.exitCode === 0 ? result.stdout.split('\n') : []).map(line => |
| 43 | line.trim(), |
| 44 | ) |
| 45 | |
| 46 | return { |
| 47 | platformRaw: system.toLowerCase() || 'unknown', |
| 48 | arch: archOf(machine), |
| 49 | kernel: kernel || undefined, |
| 50 | packageManagers: managers.replace(/,$/, ''), |
| 51 | runtimes: runtimes.replace(/,$/, ''), |
| 52 | } |
| 53 | } |