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 | /** |
| 2 | * The `$.telemetry` noun as every caller sees it: the one contract for the |
| 3 | * noun, merged into `claude-code` beside the engine's own declarations. |
| 4 | * |
| 5 | * The telemetry mod adds the noun in the `engine.create` fold and checks its |
| 6 | * return against `EngineInterface['telemetry']`; a mod that calls it, and a |
| 7 | * test that answers it with `on('telemetry.log', …)`, read the same types by |
| 8 | * including this folder in their tsconfig. Nothing here is imported: the file |
| 9 | * is ambient, so it merges wherever it is included. |
| 10 | */ |
| 11 | declare module 'claude-code' { |
| 12 | interface EngineInterface { |
| 13 | /** |
| 14 | * A plugin's analytics, one first-party row per call; present only where |
| 15 | * the telemetry mod is seated (internal builds), absent everywhere else. |
| 16 | */ |
| 17 | telemetry: Telemetry |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * A plugin's analytics, sent one event at a time through `$.telemetry`. |
| 22 | * |
| 23 | * Internal builds alone: the telemetry mod adds the noun in the |
| 24 | * `engine.create` fold, so a plugin on an external build, or one where the |
| 25 | * mod is off, finds no `$.telemetry` and its call throws. |
| 26 | */ |
| 27 | export type Telemetry = { |
| 28 | /** |
| 29 | * Sends one event, `tengu_plugin_<event>`, as one first-party row; |
| 30 | * resolves once the ingest accepted it. |
| 31 | * |
| 32 | * The calling mod names itself in `event`; one already named `tengu_…` is |
| 33 | * sent as named. A value is a finite number, a boolean or a |
| 34 | * TelemetryChoice; free text is refused. One input, as every op on `$` |
| 35 | * takes. |
| 36 | * |
| 37 | * @param entry the event's name, a snake_case token, and its properties by |
| 38 | * snake_case key |
| 39 | * @example |
| 40 | * await $.telemetry.log({ |
| 41 | * event: "suggest_learning_survey_answered", |
| 42 | * props: { |
| 43 | * answer: 2, |
| 44 | * page: { value: "ready", of: ["ready", "later"] }, |
| 45 | * }, |
| 46 | * }) |
| 47 | */ |
| 48 | log: (entry: TelemetryLogEntry) => Promise<void> |
| 49 | |
| 50 | /** |
| 51 | * Marks one use of a feature as the CLI's own feature events do, one |
| 52 | * `tengu_feature_<kind>` row; resolves once the ingest accepted it. |
| 53 | * |
| 54 | * The row carries `feature_name`, `error_code` on sad or bad (`reason`, |
| 55 | * required there and refused on ok) and the entry's `props`, checked as |
| 56 | * `log`'s are; it joins the product-wide feature surface, so no prefix. |
| 57 | * |
| 58 | * @param entry the feature, how it went, why when not ok, and the row's |
| 59 | * properties by snake_case key |
| 60 | * @example |
| 61 | * await $.telemetry.mark({ feature: "learn_page", kind: "ok" }) |
| 62 | * await $.telemetry.mark({ |
| 63 | * feature: "learn_page", |
| 64 | * kind: "sad", |
| 65 | * reason: "blocked", |
| 66 | * }) |
| 67 | */ |
| 68 | mark: (entry: TelemetryMarkEntry) => Promise<void> |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * What `$.telemetry.log` takes: the event's name after the prefix, and its |
| 73 | * properties by snake_case key. |
| 74 | */ |
| 75 | export type TelemetryLogEntry = { |
| 76 | event: string |
| 77 | props?: Readonly<Record<string, TelemetryProp>> |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * What `$.telemetry.mark` takes: the feature, how it went, why when not |
| 82 | * ok, and the properties the row carries beside them by snake_case key. |
| 83 | */ |
| 84 | export type TelemetryMarkEntry = { |
| 85 | feature: string |
| 86 | kind: TelemetryMarkKind |
| 87 | reason?: string |
| 88 | props?: Readonly<Record<string, TelemetryProp>> |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * How a feature went, as the CLI's own feature events count it. |
| 93 | * |
| 94 | * `ok`: used, the person got what they asked. `sad`: degraded, a fallback |
| 95 | * or a partial, the person still got something. `bad`: failed, the person |
| 96 | * got nothing. |
| 97 | */ |
| 98 | export type TelemetryMarkKind = 'ok' | 'sad' | 'bad' |
| 99 | |
| 100 | /** |
| 101 | * A property's value: a finite number, a boolean, or a TelemetryChoice; |
| 102 | * never free text. |
| 103 | */ |
| 104 | export type TelemetryProp = number | boolean | TelemetryChoice |
| 105 | |
| 106 | /** |
| 107 | * A string property: the value and the list it is chosen from, declared |
| 108 | * beside it, so no free text reaches the row. |
| 109 | * |
| 110 | * Every member of `of` is a lowercase token of letters, digits, `_` and |
| 111 | * `-`, which may start with a digit, at most 32 of them; `value` is one of |
| 112 | * them. |
| 113 | */ |
| 114 | export type TelemetryChoice = { value: string; of: readonly string[] } |
| 115 | } |