@hop-top/kit 0.5.0-alpha.1 → 0.5.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/README.md +333 -9
  3. package/dist/aim-CTp-kJW2.d.ts +139 -0
  4. package/dist/aim.d.ts +1 -116
  5. package/dist/alias-dhhr08Ei.d.ts +88 -0
  6. package/dist/alias.d.ts +2 -73
  7. package/dist/api-miiso81x.d.ts +77 -0
  8. package/dist/api.d.ts +1 -62
  9. package/dist/auth-2-jfgiHn.d.ts +34 -0
  10. package/dist/auth.d.ts +1 -26
  11. package/dist/cli-DLygZLi9.d.ts +450 -0
  12. package/dist/cli.d.ts +6 -309
  13. package/dist/cli.js +192 -63
  14. package/dist/config-BUY7_W2n.d.ts +103 -0
  15. package/dist/config.d.ts +1 -97
  16. package/dist/errcorrect-BcX1Ft0K.d.ts +44 -0
  17. package/dist/errcorrect.d.ts +1 -37
  18. package/dist/error-DISJKeDu.d.ts +144 -0
  19. package/dist/id/index.d.ts +2 -83
  20. package/dist/index-Bc5c7Ty5.d.ts +328 -0
  21. package/dist/index-C3Zw4wDJ.d.ts +359 -0
  22. package/dist/index-MLrRDvEG.d.ts +1073 -0
  23. package/dist/index-QSffbLnj.d.ts +94 -0
  24. package/dist/index.d.ts +28 -0
  25. package/dist/index.js +6794 -0
  26. package/dist/llm-B5XUWH8T.d.ts +231 -0
  27. package/dist/llm.d.ts +1 -188
  28. package/dist/mcp/index.d.ts +2 -0
  29. package/dist/mcp/index.js +1453 -0
  30. package/dist/netpolicy-asvCfwi8.d.ts +138 -0
  31. package/dist/netpolicy.d.ts +1 -0
  32. package/dist/netpolicy.js +118 -0
  33. package/dist/output-4aXs91GY.d.ts +396 -0
  34. package/dist/output.d.ts +3 -213
  35. package/dist/output.js +567 -43
  36. package/dist/progress-CAzyxeWl.d.ts +38 -0
  37. package/dist/progress.d.ts +1 -30
  38. package/dist/provenance-SMFHm5gx.d.ts +30 -0
  39. package/dist/provenance.d.ts +1 -24
  40. package/dist/routellm-PGSt2D1y.d.ts +75 -0
  41. package/dist/routellm.d.ts +2 -64
  42. package/dist/rpc-D5xLEf8V.d.ts +32 -0
  43. package/dist/rpc.d.ts +2 -25
  44. package/dist/safety-CUaYEjZc.d.ts +30 -0
  45. package/dist/safety.d.ts +1 -24
  46. package/dist/scope-BrhYB4ij.d.ts +141 -0
  47. package/dist/scope.d.ts +1 -121
  48. package/dist/serve-DE-jscpb.d.ts +646 -0
  49. package/dist/serve.d.ts +3 -0
  50. package/dist/serve.js +1019 -0
  51. package/dist/stream-CrjeCp0M.d.ts +44 -0
  52. package/dist/stream.d.ts +1 -35
  53. package/dist/telemetry/index.d.ts +1 -315
  54. package/dist/telemetry/index.js +12 -1
  55. package/dist/tui/index.d.ts +5 -298
  56. package/dist/tui/index.js +3 -10
  57. package/dist/upgrade-p_zh3pvV.d.ts +102 -0
  58. package/dist/upgrade.d.ts +1 -95
  59. package/dist/xdg-DB7Shoib.d.ts +179 -0
  60. package/dist/xdg.d.ts +1 -169
  61. package/package.json +26 -3
  62. package/src/cli.offline.test.ts +93 -0
  63. package/src/cli.parity.test.ts +192 -0
  64. package/src/cli.ts +112 -12
  65. package/src/index.test.ts +58 -0
  66. package/src/index.ts +37 -0
  67. package/src/log.parity.test.ts +105 -0
  68. package/src/log.ts +64 -13
  69. package/src/mcp/bridge.test.ts +150 -0
  70. package/src/mcp/bridge.ts +246 -0
  71. package/src/mcp/conformance.test.ts +336 -0
  72. package/src/mcp/dispatch.ts +313 -0
  73. package/src/mcp/index.ts +138 -0
  74. package/src/mcp/legacy.ts +314 -0
  75. package/src/mcp/mcp.test.ts +697 -0
  76. package/src/mcp/modern-confirm.test.ts +520 -0
  77. package/src/mcp/modern-confirm.ts +452 -0
  78. package/src/mcp/modern.ts +723 -0
  79. package/src/mcp/tasks.ts +82 -0
  80. package/src/mcp/testtree.ts +250 -0
  81. package/src/mcp/types.ts +504 -0
  82. package/src/netpolicy.test.ts +202 -0
  83. package/src/netpolicy.ts +231 -0
  84. package/src/output/dispatch.ts +10 -2
  85. package/src/output/error.ts +316 -0
  86. package/src/output/formatter.ts +29 -5
  87. package/src/output/formatters/csv.ts +48 -12
  88. package/src/output/formatters/json.ts +4 -25
  89. package/src/output/formatters/project.ts +34 -0
  90. package/src/output/formatters/table.ts +8 -6
  91. package/src/output/formatters/text.ts +7 -3
  92. package/src/output/formatters/yaml.ts +5 -22
  93. package/src/output/projection.test.ts +298 -0
  94. package/src/output/projection.ts +33 -59
  95. package/src/output/template.ts +11 -21
  96. package/src/output.surface.test.ts +41 -0
  97. package/src/output.ts +41 -3
  98. package/src/serve.test.ts +1257 -0
  99. package/src/serve.ts +1665 -0
  100. package/src/telemetry/client.test.ts +31 -0
  101. package/src/telemetry/client.ts +7 -1
  102. package/src/telemetry/offline.test.ts +64 -0
  103. package/src/tui/parity.test.ts +120 -31
  104. package/src/tui/parity.ts +58 -7
  105. package/test/output/csv.test.ts +164 -0
  106. package/test/output/error.test.ts +246 -0
  107. package/src/tui/parity.json +0 -74
@@ -0,0 +1,359 @@
1
+ /**
2
+ * @module telemetry/mode
3
+ * @package @hop-top/kit
4
+ *
5
+ * Telemetry Mode + env-variable precedence — the TS mirror of
6
+ * `go/runtime/telemetry/mode.go`. Three tiers control what an emit
7
+ * call ships:
8
+ *
9
+ * - `Mode.Off`: default; emit is a no-op.
10
+ * - `Mode.Anon`: anonymous payload (installation_id, command_path,
11
+ * exit_code, duration_ms, occurred_at, kit_version, sdk_lang/version).
12
+ * - `Mode.Full`: anon + args + flags, both post-redact.
13
+ *
14
+ * See the event-schema doc at `sdk/docs/telemetry-event-schema.md`
15
+ * for the on-wire shape.
16
+ *
17
+ * The env-precedence rule is intentionally simple:
18
+ *
19
+ * 1. If `KIT_APP_PREFIX=spaced` is set AND `SPACED_TELEMETRY_MODE` has
20
+ * a parseable value, that wins.
21
+ * 2. Otherwise `KIT_TELEMETRY_MODE` is consulted.
22
+ * 3. Anything else (missing, garbage, whitespace) → `Mode.Off`.
23
+ */
24
+ /**
25
+ * Mode controls how much detail the telemetry emitter ships.
26
+ *
27
+ * Encoded as a string-literal union so the on-disk / on-wire token IS
28
+ * the enum value. Mirrors Go's `Mode.String()` which renders these same
29
+ * three lowercase tokens.
30
+ */
31
+ declare const Mode: {
32
+ readonly Off: "off";
33
+ readonly Anon: "anon";
34
+ readonly Full: "full";
35
+ };
36
+ type Mode = (typeof Mode)[keyof typeof Mode];
37
+ /**
38
+ * parseMode maps a string token (case-insensitive: "off", "anon",
39
+ * "full") to a Mode. Empty / null / undefined input returns
40
+ * `[Mode.Off, true]` so an unset env var doesn't masquerade as an
41
+ * error. Unknown tokens return `[Mode.Off, false]` so callers can
42
+ * distinguish "operator typoed the env var" from "operator opted out".
43
+ *
44
+ * Mirrors `telemetry.ParseMode` in `go/runtime/telemetry/mode.go`.
45
+ */
46
+ declare function parseMode(s: string | undefined | null): [Mode, boolean];
47
+ /**
48
+ * resolveMode reads the env vars in canonical precedence order and
49
+ * returns the resolved Mode. Defaults to `Mode.Off`.
50
+ *
51
+ * Precedence (mirrors `telemetry.readEnvMode`):
52
+ *
53
+ * 1. `<APP>_TELEMETRY_MODE` where `<APP>` = uppercased `KIT_APP_PREFIX`.
54
+ * 2. `KIT_TELEMETRY_MODE`.
55
+ * 3. `Mode.Off`.
56
+ *
57
+ * Unparseable values at any tier are skipped (NOT a hard error); the
58
+ * resolver falls through to the next tier and ultimately to Off.
59
+ *
60
+ * @param env Inject a custom env map for testing. Defaults to `process.env`.
61
+ */
62
+ declare function resolveMode(env?: NodeJS.ProcessEnv): Mode;
63
+
64
+ /**
65
+ * @module telemetry/installId
66
+ * @package @hop-top/kit
67
+ *
68
+ * Persisted anonymous installation identifier — the TS mirror of
69
+ * `go/runtime/telemetry/installid.go`.
70
+ *
71
+ * On-disk format: 32 raw bytes from `crypto.randomBytes` stored at
72
+ * `<XDG_STATE_HOME>/kit/telemetry/installation_id`. The surface API
73
+ * returns the lowercase hex SHA-256 of those bytes (64 chars) so the
74
+ * file format stays canonical across polyglot SDKs (Go / Py / TS / Rs /
75
+ * PHP) while the hashed string is what flows through events.
76
+ *
77
+ * Perms: file 0600, parent dir 0700.
78
+ */
79
+ /**
80
+ * installIdPath returns the canonical on-disk path used by this module.
81
+ * Useful for SDK consumers and compliance checks that need to verify
82
+ * the storage location without invoking the read path.
83
+ */
84
+ declare function installIdPath(): string;
85
+ /**
86
+ * getInstallId returns the persisted anonymous install identifier as
87
+ * lowercase hex SHA-256 of 32 random bytes stored on disk. It generates
88
+ * and persists the bytes on first call. Concurrent first calls across
89
+ * processes are race-safe via a tmp + rename pattern with an
90
+ * existence-precheck: if a peer already wrote a valid file by the time
91
+ * we go to rename, we adopt their bytes.
92
+ *
93
+ * Mirrors `telemetry.InstallationID` in Go.
94
+ */
95
+ declare function getInstallId(): Promise<string>;
96
+ /**
97
+ * rotate atomically replaces the persisted bytes with 32 fresh
98
+ * `crypto.randomBytes` and returns the new hex. Used by the
99
+ * `kit consent reset` CLI flow.
100
+ *
101
+ * Mirrors `telemetry.Rotate` in Go.
102
+ */
103
+ declare function rotate(): Promise<string>;
104
+ /**
105
+ * resetForTest deletes the persisted file. Test helper exposed so
106
+ * adopters can drive first-run code paths in their own tests. Never
107
+ * call from production code.
108
+ *
109
+ * Mirrors `telemetry.ResetForTest` in Go.
110
+ */
111
+ declare function resetForTest(): Promise<void>;
112
+
113
+ /**
114
+ * @module telemetry/consent
115
+ * @package @hop-top/kit
116
+ *
117
+ * Read-only consent-file loader — the TS mirror of the read path in
118
+ * `go/core/consent/file_store.go`.
119
+ *
120
+ * On-disk shape (YAML under `<XDG_CONFIG_HOME>/kit/config.yaml` at the
121
+ * `kit.telemetry.consent` partition):
122
+ *
123
+ * ```yaml
124
+ * kit:
125
+ * telemetry:
126
+ * consent:
127
+ * state: granted # | denied
128
+ * prompt_version: 1
129
+ * decision_source: prompt # | flag | config | env
130
+ * decided_at: 2026-05-19T12:00:00Z
131
+ * ```
132
+ *
133
+ * A pre-refactor layout at `<XDG_CONFIG_HOME>/kit/telemetry.yaml` (with
134
+ * a bare `telemetry.consent` block at the top level) is read as a
135
+ * fallback so installs that have not been migrated yet still work.
136
+ *
137
+ * This TS module is **read-only**: writing the consent file remains the
138
+ * job of the Go `kit consent` CLI. SDK consumers just need to know
139
+ * whether emission is allowed.
140
+ *
141
+ * Anything that isn't a clean, parseable, `state: granted` block
142
+ * collapses to `deniedConsent` — a fail-closed default so a corrupt
143
+ * config can never accidentally enable emission.
144
+ */
145
+ /**
146
+ * Consent is the resolved telemetry decision for the current
147
+ * installation. The shape mirrors the relevant subset of the Go
148
+ * `consent.Decision` struct.
149
+ */
150
+ interface Consent {
151
+ /** allowed is true only when state == "granted". */
152
+ readonly allowed: boolean;
153
+ /** promptVersion records which prompt revision the user accepted. */
154
+ readonly promptVersion: number;
155
+ /**
156
+ * decisionSource records how the decision was captured —
157
+ * "prompt" | "flag" | "config" | "env". Defaults to "config" when
158
+ * the file is missing or unreadable.
159
+ */
160
+ readonly decisionSource: string;
161
+ /** decidedAt is the RFC3339 timestamp of the decision, if present. */
162
+ readonly decidedAt?: string;
163
+ }
164
+ /**
165
+ * deniedConsent is the canonical fail-closed default. Returned whenever
166
+ * the file is missing, unreadable, malformed, or carries an unknown
167
+ * state value.
168
+ */
169
+ declare const deniedConsent: Consent;
170
+ /**
171
+ * consentPath returns the canonical on-disk path used by this module
172
+ * (`<XDG_CONFIG_HOME>/kit/config.yaml`). Useful for `kit telemetry
173
+ * status` diagnostics and SDK consumers that want to surface the
174
+ * location.
175
+ */
176
+ declare function consentPath(): string;
177
+ /**
178
+ * loadConsent reads and parses the consent file, returning a fully
179
+ * resolved Consent struct. Failure modes fold to `deniedConsent`:
180
+ *
181
+ * - File missing → denied.
182
+ * - File unreadable → denied.
183
+ * - YAML parse error → denied.
184
+ * - Missing `kit.telemetry.consent` block (and no legacy) → denied.
185
+ * - `state` neither "granted" nor "denied" → denied.
186
+ *
187
+ * `state: "denied"` returns a Consent with `allowed=false` but with the
188
+ * other fields populated, so callers can distinguish an explicit deny
189
+ * from a fail-closed default.
190
+ *
191
+ * Read order: canonical `config.yaml` (`kit.telemetry.consent`) first,
192
+ * then legacy `telemetry.yaml` (`telemetry.consent`) as a fallback.
193
+ */
194
+ declare function loadConsent(): Promise<Consent>;
195
+
196
+ /**
197
+ * redactString applies every pattern in the opinionated set to `s`.
198
+ * Returns a new string; the input is never mutated.
199
+ */
200
+ declare function redactString(s: string): string;
201
+ /**
202
+ * redact returns a NEW value with the opinionated regex set applied to
203
+ * every reachable string. Walks plain objects and arrays recursively.
204
+ * Non-string scalars (number, boolean, null, undefined, bigint, symbol)
205
+ * pass through unchanged. Input is never mutated.
206
+ *
207
+ * NOT parity with `go/core/redact`. Use a per-Client redactor callback
208
+ * for stricter or custom rules; this is the default-on backstop.
209
+ */
210
+ declare function redact(value: unknown): unknown;
211
+
212
+ /** Sink kinds understood by the Client. */
213
+ type SinkKind = 'https' | 'jsonl';
214
+ /**
215
+ * ClientOptions tune the Client. Every field has an env-var equivalent
216
+ * so adopters can configure via the process environment without a
217
+ * code-side touch.
218
+ */
219
+ interface ClientOptions {
220
+ /** HTTPS endpoint for the `https` sink. Env: `KIT_TELEMETRY_ENDPOINT`. */
221
+ endpoint?: string;
222
+ /** Sink kind. Env: `KIT_TELEMETRY_SINK`. Default `jsonl`. */
223
+ sink?: SinkKind;
224
+ /** Target file for the `jsonl` sink. Env: `KIT_TELEMETRY_SINK_FILE`. */
225
+ sinkFile?: string;
226
+ /** Bounded queue capacity. Env: `KIT_TELEMETRY_QUEUE_SIZE`. Default 1024. */
227
+ queueSize?: number;
228
+ /** Custom redactor — runs BEFORE the default opinionated redact pass. */
229
+ redactor?: (attrs: Record<string, unknown>) => Record<string, unknown>;
230
+ /** SDK version surfaced in the envelope's `sdk_version` field. */
231
+ sdkVersion?: string;
232
+ }
233
+ /**
234
+ * Envelope shape this Client emits. Aligned with the cross-language
235
+ * event-schema doc's "common fields" plus the TS/Py free-form `event`
236
+ * + `attrs` extension.
237
+ *
238
+ * `attrs` is `null` when `mode === Mode.Anon` (matches the rs SDK's
239
+ * ``Value::Null`` strip) — the key stays for envelope-shape stability,
240
+ * the payload is dropped to avoid PII leakage. In `Mode.Full` it carries
241
+ * the caller's attrs dict after the redactor pipeline.
242
+ */
243
+ interface Envelope {
244
+ schema_version: string;
245
+ sdk_lang: 'ts';
246
+ sdk_version: string;
247
+ installation_id: string;
248
+ mode: Mode;
249
+ occurred_at: string;
250
+ event: string;
251
+ attrs: Record<string, unknown> | null;
252
+ }
253
+ /**
254
+ * Client is the non-blocking telemetry emitter. Construct one per
255
+ * process (or per long-lived adopter context) and call `record()` from
256
+ * any path; call `shutdown()` before process exit to drain queued
257
+ * events.
258
+ */
259
+ declare class Client {
260
+ private readonly endpoint?;
261
+ private readonly sinkKind;
262
+ private readonly sinkFile;
263
+ private readonly queueCap;
264
+ private readonly userRedactor?;
265
+ private readonly sdkVersion;
266
+ private readonly queue;
267
+ private dropped;
268
+ private installIdPromise?;
269
+ private flushTimer?;
270
+ private flushing;
271
+ private closed;
272
+ constructor(opts?: ClientOptions);
273
+ /**
274
+ * record enqueues an event for background delivery. Returns
275
+ * synchronously; never throws. Gating order: closed → consent → mode.
276
+ * Queue-full bumps `droppedCount` and returns silently.
277
+ */
278
+ record(event: string, attrs?: Record<string, unknown>): void;
279
+ /** Saturation counter — reads, not writes. */
280
+ get droppedCount(): number;
281
+ /**
282
+ * shutdown stops the flush timer, drains pending events to the sink,
283
+ * and resolves once drained OR the timeout elapses (default 5000ms).
284
+ * Idempotent.
285
+ */
286
+ shutdown(timeoutMs?: number): Promise<void>;
287
+ /**
288
+ * drainOnce ships every event currently in the queue (snapshot at
289
+ * call time) to the configured sink. Errors bump `dropped` but never
290
+ * propagate.
291
+ */
292
+ private drainOnce;
293
+ /**
294
+ * envelopeBatch materialises pending records into on-wire envelopes,
295
+ * applying the user redactor first and then the default `redact()`
296
+ * pass. install_id is resolved lazily + cached.
297
+ */
298
+ private envelopeBatch;
299
+ /**
300
+ * shipHttps POSTs the batch as NDJSON. One retry on 5xx OR network
301
+ * error, then drops the batch. `AbortController` enforces the
302
+ * connect + total timeouts.
303
+ */
304
+ private shipHttps;
305
+ /**
306
+ * shipJsonl appends envelopes as NDJSON to `sinkFile`. Rotates to
307
+ * `<sinkFile>.1` once the file crosses `JSONL_ROTATE_BYTES`. Single
308
+ * append per batch keeps the I/O cost predictable.
309
+ */
310
+ private shipJsonl;
311
+ /** Rotate the JSONL sink when it crosses the size threshold. */
312
+ private maybeRotateJsonl;
313
+ }
314
+
315
+ /**
316
+ * @module telemetry
317
+ * @package @hop-top/kit
318
+ *
319
+ * SDK-side telemetry primitives — TS mirror of
320
+ * `go/runtime/telemetry` (Mode + install_id) and the read path of
321
+ * `go/core/consent` (consent file reader).
322
+ *
323
+ * This module covers the three building blocks SDK consumers need
324
+ * before composing an emitter:
325
+ *
326
+ * - `Mode` / `parseMode` / `resolveMode` — what tier do we emit?
327
+ * - `getInstallId` / `rotate` / `installIdPath` — anonymous installation id.
328
+ * - `loadConsent` / `consentPath` / `Consent` — has the operator opted in?
329
+ *
330
+ * The emit path itself, the BatchProcessor, and the OTLP exporter land
331
+ * in follow-up sdk-telemetry tasks.
332
+ *
333
+ * Ground truth:
334
+ * - Event-schema doc `sdk/docs/telemetry-event-schema.md`
335
+ */
336
+
337
+ type index_Client = Client;
338
+ declare const index_Client: typeof Client;
339
+ type index_ClientOptions = ClientOptions;
340
+ type index_Consent = Consent;
341
+ type index_Envelope = Envelope;
342
+ type index_Mode = Mode;
343
+ type index_SinkKind = SinkKind;
344
+ declare const index_consentPath: typeof consentPath;
345
+ declare const index_deniedConsent: typeof deniedConsent;
346
+ declare const index_getInstallId: typeof getInstallId;
347
+ declare const index_installIdPath: typeof installIdPath;
348
+ declare const index_loadConsent: typeof loadConsent;
349
+ declare const index_parseMode: typeof parseMode;
350
+ declare const index_redact: typeof redact;
351
+ declare const index_redactString: typeof redactString;
352
+ declare const index_resetForTest: typeof resetForTest;
353
+ declare const index_resolveMode: typeof resolveMode;
354
+ declare const index_rotate: typeof rotate;
355
+ declare namespace index {
356
+ export { index_Client as Client, type index_ClientOptions as ClientOptions, type index_Consent as Consent, type index_Envelope as Envelope, type index_Mode as Mode, type index_SinkKind as SinkKind, index_consentPath as consentPath, index_deniedConsent as deniedConsent, index_getInstallId as getInstallId, index_installIdPath as installIdPath, index_loadConsent as loadConsent, index_parseMode as parseMode, index_redact as redact, index_redactString as redactString, index_resetForTest as resetForTest, index_resolveMode as resolveMode, index_rotate as rotate };
357
+ }
358
+
359
+ export { Client as C, type Envelope as E, Mode as M, type SinkKind as S, type ClientOptions as a, type Consent as b, consentPath as c, deniedConsent as d, installIdPath as e, redactString as f, getInstallId as g, resetForTest as h, index as i, resolveMode as j, rotate as k, loadConsent as l, parseMode as p, redact as r };