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 / telemetry-deps / telemetry-deps.ts
121 lines · 2.7 KBRaw
1import type {
2 FsEntry,
3 HttpInit,
4 HttpResponse,
5 ProcessRunResult,
6 SessionAuthorization,
7 SessionRepo,
8 Timer,
9} from 'claude-code'
10
11import type { ConfigLocation } from '../config-location'
12import type Deployment from '../deployment'
13import type { Environment } from '../environment'
14import type { Facts } from '../facts'
15import type { PolicyPins } from '../policy-pins'
16
17/**
18 * What `telemetryOf` reaches on the nouns beneath, each a call on the
19 * plugin's own `$`.
20 *
21 * The session, the environment, files, one process, the clock, one fetch
22 * and the debug log.
23 */
24export type TelemetryDeps = {
25 /**
26 * Resolves the session's held credential, or null.
27 */
28 authorize: () => Promise<SessionAuthorization>
29
30 /**
31 * The session's id, for the batch.
32 */
33 id: () => Promise<string>
34
35 /**
36 * The session's model, for the batch.
37 */
38 model: () => Promise<string>
39
40 /**
41 * Whether a person is at the prompt: what `session.start` said, else
42 * whether the session draws on a terminal.
43 */
44 isInteractive: () => Promise<boolean>
45
46 /**
47 * Reads, before each batch, the build's user type and every analytics-off
48 * variable.
49 */
50 environment: () => Promise<Environment>
51
52 /**
53 * Reads the managed policy's gateway pins.
54 */
55 policy: () => Promise<PolicyPins>
56
57 /**
58 * Reads, once a session, the variables that describe it in a row.
59 */
60 facts: () => Promise<Facts>
61
62 /**
63 * Reads, once a session, whether each deployment's variable holds.
64 */
65 deployment: () => Promise<readonly Deployment.DeploymentSignal[]>
66
67 /**
68 * Reads where the CLI's global config file is.
69 */
70 configLocation: () => Promise<ConfigLocation>
71
72 /**
73 * The directory the session runs in.
74 */
75 cwd: () => Promise<string>
76
77 /**
78 * The repository the session runs in, or null.
79 */
80 repo: () => Promise<SessionRepo | null>
81
82 /**
83 * Reads a file as text; rejects when it cannot be read.
84 */
85 read: (path: string) => Promise<string>
86
87 /**
88 * Lists a directory; rejects when it cannot be listed.
89 */
90 list: (path: string) => Promise<readonly FsEntry[]>
91
92 /**
93 * Whether a path exists.
94 */
95 exists: (path: string) => Promise<boolean>
96
97 /**
98 * Runs one program to its end.
99 */
100 run: (argv: readonly string[]) => Promise<ProcessRunResult>
101
102 /**
103 * Posts a batch to the ingest with the credential handle.
104 */
105 fetch: (url: string, init: HttpInit) => Promise<HttpResponse>
106
107 /**
108 * Calls `fn` once after `ms` milliseconds.
109 */
110 after: (ms: number, fn: () => void) => Timer
111
112 /**
113 * Resolves after `ms` milliseconds.
114 */
115 sleep: (ms: number) => Promise<void>
116
117 /**
118 * Writes one line to the debug log.
119 */
120 debug: (text: string) => void
121}