spacehub

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

claude-code / mods / telemetry / hooks / context / probe-of / probe-of.ts
65 lines · 2.1 KBRaw
1import Batching from '../../batching'
2import type { TelemetryDeps } from '../../telemetry-deps'
3import Identity from '../identity'
4import Machine from '../machine'
5import type { Probe } from '../probe'
6import { remoteHashOf } from '../remote-hash-of'
7import { vcsOf } from '../vcs-of'
8import { linuxFilesOf } from './linux-files-of'
9
10/**
11 * Gathers what holds for the whole session through the nouns beneath: the
12 * variables, the global config, one machine probe, the directory, the engine.
13 *
14 * Each read that fails leaves its part empty, the engine's version saying so
15 * once in the debug log; the Linux files are read on Linux alone.
16 *
17 * @param deps the calls on the nouns beneath
18 * @param isInteractive whether a person is at the prompt
19 * @returns what was gathered, for context-of to shape
20 */
21export async function probeOf(
22 deps: TelemetryDeps,
23 isInteractive: boolean,
24): Promise<Probe> {
25 const [facts, signals, location, environment, cwd, repo, engine] =
26 await Promise.all([
27 deps.facts(),
28 deps.deployment(),
29 deps.configLocation(),
30 deps.environment(),
31 deps.cwd().catch(() => undefined),
32 deps.repo().catch(() => null),
33 deps.version().catch((error: unknown) => {
34 deps.debug(
35 "telemetry: the engine's version is not readable here, so the " +
36 `version columns stay empty (${Batching.messageOf(error)})`,
37 )
38
39 return undefined
40 }),
41 ])
42
43 const [identity, machine, vcs, remoteHash] = await Promise.all([
44 Identity.identityOf(deps.read, location, environment.userType === 'ant'),
45 Machine.machineOf(deps.run, facts),
46 cwd === undefined ? undefined : vcsOf(deps.list, cwd, facts.hasP4Port),
47 remoteHashOf(repo?.remote),
48 ])
49
50 const files = await linuxFilesOf(deps, machine.platformRaw === 'linux')
51
52 return {
53 facts,
54 signals: [...signals, ...files.fileSignals],
55 identity,
56 machine,
57 platform: Machine.platformOf(facts.hostPlatform, machine.platformRaw),
58 isInteractive,
59 distro: files.distro,
60 wslVersion: files.wslVersion,
61 vcs,
62 remoteHash,
63 engine,
64 }
65}