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