@osfactory/otel-hook 0.1.0

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 (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1020 -0
  3. package/dist/adapter-DIgRACtL.d.ts +303 -0
  4. package/dist/cli.js +12607 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/config.d.ts +233 -0
  7. package/dist/config.js +996 -0
  8. package/dist/config.js.map +1 -0
  9. package/dist/content-CoB7aNP1.d.ts +118 -0
  10. package/dist/diagnostics.d.ts +58 -0
  11. package/dist/diagnostics.js +46 -0
  12. package/dist/diagnostics.js.map +1 -0
  13. package/dist/errors.d.ts +91 -0
  14. package/dist/errors.js +322 -0
  15. package/dist/errors.js.map +1 -0
  16. package/dist/events-VxBnDFaO.d.ts +2044 -0
  17. package/dist/filesystem-store-J8jjDMTh.d.ts +65 -0
  18. package/dist/hook-CGpo-vks.d.ts +292 -0
  19. package/dist/identity-BrVBs901.d.ts +227 -0
  20. package/dist/index.d.ts +44 -0
  21. package/dist/index.js +11798 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/install.d.ts +1021 -0
  24. package/dist/install.js +3271 -0
  25. package/dist/install.js.map +1 -0
  26. package/dist/integration.d.ts +303 -0
  27. package/dist/integration.js +5942 -0
  28. package/dist/integration.js.map +1 -0
  29. package/dist/keys-Dej5bN3L.d.ts +7 -0
  30. package/dist/lifecycle.d.ts +428 -0
  31. package/dist/lifecycle.js +1077 -0
  32. package/dist/lifecycle.js.map +1 -0
  33. package/dist/memory-DXVBc8V9.d.ts +94 -0
  34. package/dist/model.d.ts +45 -0
  35. package/dist/model.js +1023 -0
  36. package/dist/model.js.map +1 -0
  37. package/dist/otlp-log-sink-CeIFDDpn.d.ts +457 -0
  38. package/dist/payload-CHr53E_v.d.ts +201 -0
  39. package/dist/policy-D1CrlYn3.d.ts +73 -0
  40. package/dist/ports-Q8x0ODhs.d.ts +200 -0
  41. package/dist/primitives-CJ8-rn-f.d.ts +75 -0
  42. package/dist/privacy.d.ts +51 -0
  43. package/dist/privacy.js +633 -0
  44. package/dist/privacy.js.map +1 -0
  45. package/dist/providers.d.ts +257 -0
  46. package/dist/providers.js +4398 -0
  47. package/dist/providers.js.map +1 -0
  48. package/dist/registry-BzYmC9OC.d.ts +49 -0
  49. package/dist/runtime.d.ts +32 -0
  50. package/dist/runtime.js +2907 -0
  51. package/dist/runtime.js.map +1 -0
  52. package/dist/schema-Cn0-xz8L.d.ts +224 -0
  53. package/dist/semconv-Baoz-0OI.d.ts +188 -0
  54. package/dist/service-j4jEO6cZ.d.ts +68 -0
  55. package/dist/state.d.ts +36 -0
  56. package/dist/state.js +710 -0
  57. package/dist/state.js.map +1 -0
  58. package/dist/taxonomy-DwhTtuWd.d.ts +87 -0
  59. package/dist/telemetry.d.ts +77 -0
  60. package/dist/telemetry.js +2294 -0
  61. package/dist/telemetry.js.map +1 -0
  62. package/dist/testing.d.ts +155 -0
  63. package/dist/testing.js +6513 -0
  64. package/dist/testing.js.map +1 -0
  65. package/package.json +124 -0
@@ -0,0 +1,201 @@
1
+ import * as zod from 'zod';
2
+ import { g as ProviderId } from './primitives-CJ8-rn-f.js';
3
+ import { d as ProviderCapabilities, P as ProviderAdapter } from './adapter-DIgRACtL.js';
4
+
5
+ /** Stable, hyphenated provider id for Claude Code. */
6
+ declare const CLAUDE_CODE_PROVIDER_ID: string & zod.$brand<"ProviderId">;
7
+
8
+ /** Every `hook_event_name` this adapter recognizes. */
9
+ declare const CLAUDE_HOOK_EVENT_NAMES: readonly ["SessionStart", "SessionEnd", "UserPromptSubmit", "PreToolUse", "PostToolUse", "PostToolUseFailure", "PermissionRequest", "SubagentStart", "SubagentStop", "PreCompact", "PostCompact", "Stop", "StopFailure"];
10
+ type ClaudeHookEventName = (typeof CLAUDE_HOOK_EVENT_NAMES)[number];
11
+
12
+ /**
13
+ * Cursor agent-hook payload contract.
14
+ *
15
+ * ## Provenance
16
+ *
17
+ * Nothing in this module is invented. Every field, spelling, and unit below is
18
+ * established by one or both of:
19
+ *
20
+ * 1. **Cursor's published hooks reference** — `cursor.com/docs/agent/hooks` and
21
+ * `cursor.com/docs/hooks.md` (two URLs serving the same reference; both read
22
+ * 2026-07-29). Source of the event-name list, the shared envelope, each
23
+ * event's input fields, each event's stdout response, the `hooks.json`
24
+ * schema, exit-code semantics, and the statement that `duration` and
25
+ * `duration_ms` are milliseconds while `timeout` is seconds.
26
+ * 2. **Real redacted captures** — `colinsurprenant/director`, under
27
+ * `hack/canary/cursor-cli/findings/`: two Cursor CLI runs (`2026.07.17-3e2a980`,
28
+ * captured 2026-07-21 and 2026-07-22) and two Cursor IDE runs (`3.12.17`,
29
+ * captured 2026-07-21), each registering the full agent-hook set and recording
30
+ * the exact key list of all 54 payload files it saved. Source of the fields
31
+ * the reference omits, of which keys are actually optional, and of the two
32
+ * lifecycle facts in "Surface dependence" below.
33
+ *
34
+ * The redacted fixtures under `fixtures/parity/cursor/` restate those captured
35
+ * shapes with synthetic values; their provenance sidecars name this capture set.
36
+ * No real path, email, transcript, prompt, or credential is copied into this
37
+ * repository — see `CLAUDE.md`.
38
+ *
39
+ * ## Envelope
40
+ *
41
+ * Keys are snake_case throughout, and there is exactly one generation of the
42
+ * shape: no camelCase variant and no legacy alias table is documented or
43
+ * observed, so none is modelled. **There is no timestamp field anywhere** — not
44
+ * in the reference, and not in any captured payload's key list — so the adapter
45
+ * reads `occurredAt` from the injected clock, as the Claude Code adapter does.
46
+ *
47
+ * ## Surface dependence (captured, not documented)
48
+ *
49
+ * The same `hooks.json` produces different event subsets on Cursor's two
50
+ * surfaces, which is why the registration planner's default set is chosen the
51
+ * way it is:
52
+ *
53
+ * - `stop` and `afterAgentResponse` fired in the IDE runs and in neither CLI
54
+ * run; `sessionEnd` fired in both CLI runs and in neither IDE run.
55
+ * - One shell invocation fires **four** hooks. The CLI capture's `fired.log`
56
+ * records `preToolUse`, `beforeShellExecution`, `afterShellExecution`,
57
+ * `postToolUse` in that order for a single `printenv` call, with
58
+ * `afterShellExecution` and `postToolUse` reporting the identical
59
+ * `duration` of 169.812. Registering both pairs would report one tool call
60
+ * twice.
61
+ *
62
+ * ## Forward compatibility
63
+ *
64
+ * Event objects are `z.object` (unknown keys stripped), not `z.strictObject`:
65
+ * Cursor adds payload fields between releases — the reference already documents
66
+ * a `preToolUse.agent_message` that no captured payload carries — and a
67
+ * telemetry hook that rejects a payload for gaining a field fails closed on the
68
+ * one thing it should tolerate.
69
+ */
70
+ declare const CURSOR_PROVIDER_ID: "cursor";
71
+ /**
72
+ * Agent-session hook events this adapter interprets, in Cursor's own spelling.
73
+ *
74
+ * The reference groups its hooks as "agent", "tab", and "app lifecycle". Only
75
+ * the agent group is here; see {@link CURSOR_UNMODELLED_HOOK_EVENT_NAMES}.
76
+ */
77
+ declare const CURSOR_HOOK_EVENT_NAMES: readonly ["sessionStart", "sessionEnd", "beforeSubmitPrompt", "afterAgentResponse", "afterAgentThought", "preToolUse", "postToolUse", "postToolUseFailure", "beforeShellExecution", "afterShellExecution", "beforeMCPExecution", "afterMCPExecution", "beforeReadFile", "afterFileEdit", "subagentStart", "subagentStop", "preCompact", "stop"];
78
+ type CursorHookEventName = (typeof CURSOR_HOOK_EVENT_NAMES)[number];
79
+ /**
80
+ * Event names Cursor documents that this adapter deliberately does not model,
81
+ * each with the reason. Recognized by name so a payload carrying one is
82
+ * reported as "known, unmodelled" rather than as an unrecognized provider.
83
+ */
84
+ declare const CURSOR_UNMODELLED_HOOK_EVENT_NAMES: Readonly<Record<string, string>>;
85
+ /**
86
+ * Events whose stdout Cursor reads a decision from, and the field it reads.
87
+ *
88
+ * Taken from the reference's per-event "Output" sections. `beforeSubmitPrompt`
89
+ * is the one event keyed `continue` rather than `permission`; the shell and MCP
90
+ * gates additionally accept `"ask"`, which this tool never emits.
91
+ */
92
+ declare const CURSOR_DECISION_EVENTS: Readonly<Record<string, "permission" | "continue">>;
93
+
94
+ /** Stable identifier for this adapter across releases. */
95
+ declare const CODEX_PROVIDER_ID: ProviderId;
96
+ /** Adapter package version, independent of the Codex CLI's own version. */
97
+ declare const CODEX_ADAPTER_VERSION = "0.1.0";
98
+
99
+ declare const CODEX_HOOK_EVENT_NAMES: readonly ["SessionStart", "UserPromptSubmit", "PreToolUse", "PermissionRequest", "PostToolUse", "PreCompact", "PostCompact", "SubagentStart", "SubagentStop", "Stop"];
100
+ type CodexHookEventName = (typeof CODEX_HOOK_EVENT_NAMES)[number];
101
+
102
+ declare const GEMINI_PROVIDER_ID: "gemini-cli";
103
+ declare const GEMINI_ADAPTER_VERSION = "0.1.0";
104
+ declare const DEFAULT_GEMINI_CAPABILITIES: ProviderCapabilities;
105
+ type GeminiAdapterOptions = {
106
+ readonly id?: string;
107
+ readonly version?: string;
108
+ readonly capabilities?: Partial<ProviderCapabilities>;
109
+ };
110
+ /**
111
+ * Provider adapter for the Gemini CLI's command hooks.
112
+ *
113
+ * Detection is purely structural (the protocol carries no provider tag), so
114
+ * confidence is `exact` only when the full event-specific shape validates, and
115
+ * `weak` when the payload merely looks like this protocol. All eleven hook events
116
+ * in the CLI's `HookEventName` enum are recognized; `AfterAgent`,
117
+ * `BeforeToolSelection`, and `Notification` carry no canonical telemetry and are
118
+ * parsed as `ignored`.
119
+ *
120
+ * `AfterModel` fires once per streaming chunk. A chunk that carries no
121
+ * `usageMetadata` is ignored; a chunk that carries one completes a
122
+ * `generation.end` for the generation its `llm_request` identifies. Several
123
+ * chunks of one stream may each carry a snapshot, and each closes the *same*
124
+ * generation: the snapshots are cumulative, so the runtime diffs them against the
125
+ * generation's stored baseline and the stream is billed once in total rather than
126
+ * once per chunk. See `./usage.ts` for why that is the correct reading, and
127
+ * `./delivery.ts` for the identity trade-offs this protocol imposes.
128
+ */
129
+ declare const createGeminiCliAdapter: (options?: GeminiAdapterOptions) => ProviderAdapter;
130
+
131
+ /**
132
+ * Zod schemas for the Gemini CLI command hook protocol.
133
+ *
134
+ * Shapes follow the public Gemini CLI hooks reference
135
+ * (https://geminicli.com/docs/hooks/reference/,
136
+ * https://github.com/google-gemini/gemini-cli/blob/main/docs/hooks/writing-hooks.md)
137
+ * cross-checked field by field against the CLI source that *produces* these
138
+ * payloads, pinned at `google-gemini/gemini-cli@3499c84`:
139
+ *
140
+ * - `packages/core/src/hooks/types.ts` — `HookEventName` and the per-event input
141
+ * interfaces.
142
+ * - `packages/core/src/hooks/hookTranslator.ts` — `LLMRequest` / `LLMResponse`,
143
+ * the "decoupled", SDK-agnostic shapes the model events carry.
144
+ * - `packages/core/src/hooks/hookEventHandler.ts` — how each input is assembled.
145
+ *
146
+ * Every hook receives the base fields below plus event-specific fields keyed by
147
+ * `hook_event_name`. Unknown extra fields are stripped rather than rejected,
148
+ * since the CLI is free to add fields the adapter does not yet model.
149
+ */
150
+ declare const GEMINI_HOOK_EVENT_NAMES: readonly ["SessionStart", "SessionEnd", "BeforeAgent", "AfterAgent", "BeforeModel", "AfterModel", "BeforeToolSelection", "BeforeTool", "AfterTool", "PreCompress", "Notification"];
151
+ type GeminiHookEventName = (typeof GEMINI_HOOK_EVENT_NAMES)[number];
152
+
153
+ declare const ANTIGRAVITY_PROVIDER_ID: "antigravity";
154
+ /**
155
+ * What this adapter can honestly observe from the five documented command
156
+ * hooks. Only PreToolUse/PostToolUse carry a lifecycle fact the canonical
157
+ * model can represent without inventing anything: PreInvocation,
158
+ * PostInvocation, and Stop expose invocation/execution bookkeeping, not a
159
+ * session or generation identity (no `modelId`, no genuine start/end
160
+ * signal), so none of them produce an event — see `parse()` below and
161
+ * `./maturity.ts` for what would need to change that.
162
+ */
163
+ declare const ANTIGRAVITY_CAPABILITIES: ProviderCapabilities;
164
+ type AntigravityAdapterOptions = {
165
+ readonly id?: string;
166
+ readonly version?: string;
167
+ };
168
+ /**
169
+ * Experimental Google Antigravity adapter.
170
+ *
171
+ * Maps the five documented camelCase command hooks onto canonical events
172
+ * conservatively: fields the hooks do not expose (model identifiers, usage,
173
+ * a genuine session start/end signal) are never fabricated. PreInvocation,
174
+ * PostInvocation, and Stop report invocation and execution-completion
175
+ * bookkeeping only — none of it converts to a canonical event without
176
+ * inventing a session or generation identity, so all three are ignored with
177
+ * a diagnostic reason. See ADR 0003 for the adapter contract this implements
178
+ * and `./maturity.ts` for what would need to be verified before this leaves
179
+ * `experimental`.
180
+ */
181
+ declare const createAntigravityAdapter: (options?: AntigravityAdapterOptions) => ProviderAdapter;
182
+
183
+ /**
184
+ * Raw hook payload shapes for Google Antigravity.
185
+ *
186
+ * Provenance: synthetic, reconstructed from the documented camelCase command
187
+ * hooks and field names the integration task specified as verified —
188
+ * `conversationId`, `workspacePaths`, `stepIdx`, `invocationNum`,
189
+ * `transcriptPath`, `artifactDirectoryPath` — plus the five hook names
190
+ * (`PreInvocation`, `PostInvocation`, `PreToolUse`, `PostToolUse`, `Stop`).
191
+ * Every other field below (`toolName`, `toolInput`, `toolResponse`, `isError`,
192
+ * `fullyIdle`, `agentVersion`) is an inferred reconstruction needed for the
193
+ * hook to carry any tool or lifecycle fact at all; none of it has been
194
+ * confirmed against a real Antigravity capture. See `./maturity.ts` for the
195
+ * promotion gates that require that confirmation. No fixture in this package
196
+ * is a copy of a real transcript, path, or credential.
197
+ */
198
+ declare const ANTIGRAVITY_HOOK_EVENT_NAMES: readonly ["PreInvocation", "PostInvocation", "PreToolUse", "PostToolUse", "Stop"];
199
+ type AntigravityHookEventName = (typeof ANTIGRAVITY_HOOK_EVENT_NAMES)[number];
200
+
201
+ export { ANTIGRAVITY_CAPABILITIES as A, CLAUDE_CODE_PROVIDER_ID as C, DEFAULT_GEMINI_CAPABILITIES as D, GEMINI_ADAPTER_VERSION as G, ANTIGRAVITY_HOOK_EVENT_NAMES as a, ANTIGRAVITY_PROVIDER_ID as b, type AntigravityAdapterOptions as c, type AntigravityHookEventName as d, CLAUDE_HOOK_EVENT_NAMES as e, CODEX_ADAPTER_VERSION as f, CODEX_HOOK_EVENT_NAMES as g, CODEX_PROVIDER_ID as h, CURSOR_DECISION_EVENTS as i, CURSOR_HOOK_EVENT_NAMES as j, CURSOR_PROVIDER_ID as k, CURSOR_UNMODELLED_HOOK_EVENT_NAMES as l, type ClaudeHookEventName as m, type CodexHookEventName as n, type CursorHookEventName as o, GEMINI_HOOK_EVENT_NAMES as p, GEMINI_PROVIDER_ID as q, type GeminiAdapterOptions as r, type GeminiHookEventName as s, createAntigravityAdapter as t, createGeminiCliAdapter as u };
@@ -0,0 +1,73 @@
1
+ import { z } from 'zod';
2
+ import { a as ContentDisclosure } from './content-CoB7aNP1.js';
3
+
4
+ /**
5
+ * How much content the library is permitted to disclose.
6
+ *
7
+ * `omit` is the default and the only mode that requires no trust in the
8
+ * downstream collector.
9
+ */
10
+ declare const contentModeSchema: z.ZodEnum<{
11
+ raw: "raw";
12
+ omit: "omit";
13
+ mask: "mask";
14
+ redact: "redact";
15
+ }>;
16
+ type ContentMode = z.infer<typeof contentModeSchema>;
17
+ declare const CONTENT_MODE_DISCLOSURE: Readonly<Record<ContentMode, ContentDisclosure>>;
18
+ /**
19
+ * Default secret-key patterns, matched case-insensitively against object keys at
20
+ * every depth. A key matching any of these has its value replaced before the
21
+ * value itself is ever inspected.
22
+ */
23
+ declare const DEFAULT_SECRET_KEY_PATTERNS: readonly string[];
24
+ /**
25
+ * Default secret-value patterns applied to disclosed text in `redact` mode.
26
+ * These are heuristics; they reduce accidental disclosure but are not a
27
+ * substitute for `omit`.
28
+ */
29
+ declare const DEFAULT_SECRET_VALUE_PATTERNS: readonly string[];
30
+ declare const privacyLimitsSchema: z.ZodObject<{
31
+ maxStringLength: z.ZodNumber;
32
+ maxDepth: z.ZodNumber;
33
+ maxArrayLength: z.ZodNumber;
34
+ maxEventsPerInvocation: z.ZodNumber;
35
+ maxObjectKeys: z.ZodNumber;
36
+ }, z.core.$strict>;
37
+ type PrivacyLimits = z.infer<typeof privacyLimitsSchema>;
38
+ declare const privacyPolicySchema: z.ZodObject<{
39
+ contentMode: z.ZodEnum<{
40
+ raw: "raw";
41
+ omit: "omit";
42
+ mask: "mask";
43
+ redact: "redact";
44
+ }>;
45
+ allowRawContent: z.ZodBoolean;
46
+ hashSalt: z.ZodString;
47
+ maskCharacter: z.ZodString;
48
+ redactionPlaceholder: z.ZodString;
49
+ secretKeyPatterns: z.ZodReadonly<z.ZodArray<z.ZodString>>;
50
+ secretValuePatterns: z.ZodReadonly<z.ZodArray<z.ZodString>>;
51
+ limits: z.ZodObject<{
52
+ maxStringLength: z.ZodNumber;
53
+ maxDepth: z.ZodNumber;
54
+ maxArrayLength: z.ZodNumber;
55
+ maxEventsPerInvocation: z.ZodNumber;
56
+ maxObjectKeys: z.ZodNumber;
57
+ }, z.core.$strict>;
58
+ }, z.core.$strict>;
59
+ type PrivacyPolicy = z.infer<typeof privacyPolicySchema>;
60
+ declare const DEFAULT_PRIVACY_LIMITS: PrivacyLimits;
61
+ declare const DEFAULT_PRIVACY_POLICY: PrivacyPolicy;
62
+ type PolicyResolution = {
63
+ readonly policy: PrivacyPolicy;
64
+ /** Non-sensitive notes about deterministic downgrades that were applied. */
65
+ readonly notes: readonly string[];
66
+ };
67
+ /**
68
+ * Validate a policy and apply the one deterministic downgrade the library
69
+ * enforces: `raw` without `allowRawContent` becomes `omit`.
70
+ */
71
+ declare const resolvePrivacyPolicy: (policy: PrivacyPolicy) => PolicyResolution;
72
+
73
+ export { CONTENT_MODE_DISCLOSURE as C, DEFAULT_PRIVACY_LIMITS as D, type PolicyResolution as P, type ContentMode as a, DEFAULT_PRIVACY_POLICY as b, DEFAULT_SECRET_KEY_PATTERNS as c, DEFAULT_SECRET_VALUE_PATTERNS as d, type PrivacyLimits as e, type PrivacyPolicy as f, contentModeSchema as g, privacyPolicySchema as h, privacyLimitsSchema as p, resolvePrivacyPolicy as r };
@@ -0,0 +1,200 @@
1
+ import { z } from 'zod';
2
+ import { OtelHookErrorInfo } from './errors.js';
3
+ import { b as CanonicalEvent } from './events-VxBnDFaO.js';
4
+ import { E as EpochMillis, I as InvocationId, d as EventId, b as Attributes } from './primitives-CJ8-rn-f.js';
5
+
6
+ /**
7
+ * Time source.
8
+ *
9
+ * Injected rather than read from `Date.now()` so tests are deterministic and so
10
+ * a host with its own time authority can supply it.
11
+ */
12
+ interface Clock {
13
+ /** Wall-clock time in whole milliseconds since the Unix epoch. */
14
+ now(): EpochMillis;
15
+ /** Monotonic reading for durations; unrelated to wall clock. */
16
+ monotonicMillis(): number;
17
+ }
18
+ /** Stable inputs from which an invocation id is derived. */
19
+ type InvocationIdSeed = {
20
+ readonly providerId: string;
21
+ readonly sessionId: string;
22
+ readonly sourceEventName?: string;
23
+ readonly occurredAt: number;
24
+ /** Provider-supplied uniqueness, e.g. a request id. */
25
+ readonly discriminator?: string;
26
+ };
27
+ /** Stable inputs from which an event id is derived. */
28
+ type EventIdSeed = {
29
+ readonly invocationId: string;
30
+ readonly sequence: number;
31
+ readonly eventType: string;
32
+ readonly discriminator?: string;
33
+ };
34
+ /**
35
+ * Identifier factory.
36
+ *
37
+ * Seeds are structured rather than free-form so the default implementation can
38
+ * be a pure function of its inputs: replaying the same source data produces the
39
+ * same ids, which lets a collector dedupe instead of double-counting.
40
+ */
41
+ interface IdGenerator {
42
+ newInvocationId(seed: InvocationIdSeed): InvocationId;
43
+ newEventId(seed: EventIdSeed): EventId;
44
+ /** Short opaque id for spans and generations, derived from its parts. */
45
+ newOpaqueId(parts: readonly string[]): string;
46
+ }
47
+ /**
48
+ * Which delivery's observations are already folded into a stored total.
49
+ *
50
+ * The reason this rides *inside* the total's own record rather than beside it: the
51
+ * store has no multi-key transaction, so a marker in a second key could be written
52
+ * without the total or the other way round, and a marker that can disagree with
53
+ * what it describes is worse than none. In one record the two move together under a
54
+ * single write, which is what makes re-applying a redelivered callback's usage a
55
+ * no-op instead of a double count.
56
+ *
57
+ * `callbackId` is an opaque digest supplied by the caller, never a host's raw
58
+ * delivery id: a state record is somewhere a raw provider or host identifier must
59
+ * not appear as a side effect of deduplicating on it.
60
+ */
61
+ declare const appliedDeliverySchema: z.ZodObject<{
62
+ callbackId: z.ZodString;
63
+ applications: z.ZodNumber;
64
+ }, z.core.$strict>;
65
+ type AppliedDelivery = z.infer<typeof appliedDeliverySchema>;
66
+ /** Values the state store may hold. Restricted so state stays inspectable. */
67
+ declare const stateValueSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
68
+ kind: z.ZodLiteral<"usage-cumulative">;
69
+ usage: z.ZodObject<{
70
+ temporality: z.ZodEnum<{
71
+ delta: "delta";
72
+ cumulative: "cumulative";
73
+ }>;
74
+ inputTokens: z.ZodNumber;
75
+ cachedInputTokens: z.ZodNumber;
76
+ cacheCreationInputTokens: z.ZodNumber;
77
+ cacheCreationAccounting: z.ZodEnum<{
78
+ "included-in-input": "included-in-input";
79
+ "disjoint-from-input": "disjoint-from-input";
80
+ "not-reported": "not-reported";
81
+ }>;
82
+ outputTokens: z.ZodNumber;
83
+ reasoningOutputTokens: z.ZodNumber;
84
+ uncachedInputTokens: z.ZodNumber;
85
+ totalTokens: z.ZodNumber;
86
+ providerTotalTokens: z.ZodOptional<z.ZodNumber>;
87
+ providerTotalAgreement: z.ZodEnum<{
88
+ unreported: "unreported";
89
+ agrees: "agrees";
90
+ disagrees: "disagrees";
91
+ }>;
92
+ }, z.core.$strict>;
93
+ appliedDelivery: z.ZodOptional<z.ZodObject<{
94
+ callbackId: z.ZodString;
95
+ applications: z.ZodNumber;
96
+ }, z.core.$strict>>;
97
+ }, z.core.$strict>, z.ZodObject<{
98
+ kind: z.ZodLiteral<"sequence">;
99
+ next: z.ZodNumber;
100
+ }, z.core.$strict>, z.ZodObject<{
101
+ kind: z.ZodLiteral<"attributes">;
102
+ attributes: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>]>>;
103
+ }, z.core.$strict>], "kind">;
104
+ type StateValue = z.infer<typeof stateValueSchema>;
105
+ declare const stateRecordSchema: z.ZodObject<{
106
+ revision: z.ZodNumber;
107
+ updatedAt: z.ZodNumber;
108
+ value: z.ZodDiscriminatedUnion<[z.ZodObject<{
109
+ kind: z.ZodLiteral<"usage-cumulative">;
110
+ usage: z.ZodObject<{
111
+ temporality: z.ZodEnum<{
112
+ delta: "delta";
113
+ cumulative: "cumulative";
114
+ }>;
115
+ inputTokens: z.ZodNumber;
116
+ cachedInputTokens: z.ZodNumber;
117
+ cacheCreationInputTokens: z.ZodNumber;
118
+ cacheCreationAccounting: z.ZodEnum<{
119
+ "included-in-input": "included-in-input";
120
+ "disjoint-from-input": "disjoint-from-input";
121
+ "not-reported": "not-reported";
122
+ }>;
123
+ outputTokens: z.ZodNumber;
124
+ reasoningOutputTokens: z.ZodNumber;
125
+ uncachedInputTokens: z.ZodNumber;
126
+ totalTokens: z.ZodNumber;
127
+ providerTotalTokens: z.ZodOptional<z.ZodNumber>;
128
+ providerTotalAgreement: z.ZodEnum<{
129
+ unreported: "unreported";
130
+ agrees: "agrees";
131
+ disagrees: "disagrees";
132
+ }>;
133
+ }, z.core.$strict>;
134
+ appliedDelivery: z.ZodOptional<z.ZodObject<{
135
+ callbackId: z.ZodString;
136
+ applications: z.ZodNumber;
137
+ }, z.core.$strict>>;
138
+ }, z.core.$strict>, z.ZodObject<{
139
+ kind: z.ZodLiteral<"sequence">;
140
+ next: z.ZodNumber;
141
+ }, z.core.$strict>, z.ZodObject<{
142
+ kind: z.ZodLiteral<"attributes">;
143
+ attributes: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>]>>;
144
+ }, z.core.$strict>], "kind">;
145
+ }, z.core.$strict>;
146
+ type StateRecord = z.infer<typeof stateRecordSchema>;
147
+ /**
148
+ * Durable-ish key/value state.
149
+ *
150
+ * Needed because a hook process is short-lived but usage accounting spans an
151
+ * entire session. The interface is intentionally minimal: no transactions, no
152
+ * queries, nothing a file or a KV row cannot provide.
153
+ */
154
+ interface StateStore {
155
+ read(key: string): Promise<StateRecord | undefined>;
156
+ /** Writes unconditionally, returning the stored record. */
157
+ write(key: string, value: StateValue): Promise<StateRecord>;
158
+ delete(key: string): Promise<void>;
159
+ keys(prefix: string): Promise<readonly string[]>;
160
+ }
161
+ type TelemetryEmitResult = {
162
+ readonly accepted: number;
163
+ readonly rejected: number;
164
+ readonly errors: readonly OtelHookErrorInfo[];
165
+ };
166
+ /**
167
+ * Destination for canonical events.
168
+ *
169
+ * The sink receives canonical events only — never provider payloads — so an
170
+ * exporter cannot become a second, unaudited disclosure path.
171
+ */
172
+ interface TelemetrySink {
173
+ emit(events: readonly CanonicalEvent[]): Promise<TelemetryEmitResult>;
174
+ flush(): Promise<void>;
175
+ shutdown(): Promise<void>;
176
+ }
177
+ declare const logLevelSchema: z.ZodEnum<{
178
+ error: "error";
179
+ silent: "silent";
180
+ warn: "warn";
181
+ info: "info";
182
+ debug: "debug";
183
+ }>;
184
+ type LogLevel = z.infer<typeof logLevelSchema>;
185
+ declare const LOG_LEVEL_RANK: Readonly<Record<LogLevel, number>>;
186
+ /**
187
+ * Diagnostic logger.
188
+ *
189
+ * Fields are attribute values, not arbitrary objects, so a log line cannot
190
+ * become a way to print a provider payload. Implementations must never write to
191
+ * stdout (ADR 0004).
192
+ */
193
+ interface Logger {
194
+ error(message: string, fields?: Attributes): void;
195
+ warn(message: string, fields?: Attributes): void;
196
+ info(message: string, fields?: Attributes): void;
197
+ debug(message: string, fields?: Attributes): void;
198
+ }
199
+
200
+ export { type AppliedDelivery as A, type Clock as C, type EventIdSeed as E, type IdGenerator as I, LOG_LEVEL_RANK as L, type StateRecord as S, type TelemetryEmitResult as T, type InvocationIdSeed as a, type LogLevel as b, type Logger as c, type StateStore as d, type StateValue as e, type TelemetrySink as f, appliedDeliverySchema as g, stateValueSchema as h, logLevelSchema as l, stateRecordSchema as s };
@@ -0,0 +1,75 @@
1
+ import { z } from 'zod';
2
+
3
+ /** Maximum length accepted for short identifier-like strings. */
4
+ declare const MAX_IDENTIFIER_LENGTH = 256;
5
+ /** Maximum length accepted for a single string attribute value. */
6
+ declare const MAX_ATTRIBUTE_STRING_LENGTH = 4096;
7
+ /** Maximum number of entries accepted in an attribute array value. */
8
+ declare const MAX_ATTRIBUTE_ARRAY_LENGTH = 128;
9
+ declare const nonEmptyStringSchema: z.ZodString;
10
+ /** Wall-clock time as whole milliseconds since the Unix epoch. */
11
+ declare const epochMillisSchema: z.ZodNumber;
12
+ type EpochMillis = z.infer<typeof epochMillisSchema>;
13
+ /** Non-negative duration in milliseconds; may be fractional. */
14
+ declare const durationMillisSchema: z.ZodNumber;
15
+ /** Token counts are always non-negative integers. */
16
+ declare const tokenCountSchema: z.ZodNumber;
17
+ /** Monotonically increasing per-invocation ordering key. */
18
+ declare const sequenceNumberSchema: z.ZodNumber;
19
+ declare const invocationIdSchema: z.core.$ZodBranded<z.ZodString, "InvocationId", "out">;
20
+ type InvocationId = z.infer<typeof invocationIdSchema>;
21
+ declare const sessionIdSchema: z.core.$ZodBranded<z.ZodString, "SessionId", "out">;
22
+ type SessionId = z.infer<typeof sessionIdSchema>;
23
+ declare const eventIdSchema: z.core.$ZodBranded<z.ZodString, "EventId", "out">;
24
+ type EventId = z.infer<typeof eventIdSchema>;
25
+ /**
26
+ * Workspace identifiers are opaque, privacy-safe handles of the form
27
+ * `<scheme>:<token>`. Filesystem paths cannot satisfy this pattern, which keeps
28
+ * home directories and repository paths out of telemetry by construction.
29
+ */
30
+ declare const WORKSPACE_ID_PATTERN: RegExp;
31
+ declare const workspaceIdSchema: z.core.$ZodBranded<z.ZodString, "WorkspaceId", "out">;
32
+ type WorkspaceId = z.infer<typeof workspaceIdSchema>;
33
+ /** Provider ids are lowercase, hyphenated, and stable across releases. */
34
+ declare const PROVIDER_ID_PATTERN: RegExp;
35
+ declare const providerIdSchema: z.core.$ZodBranded<z.ZodString, "ProviderId", "out">;
36
+ type ProviderId = z.infer<typeof providerIdSchema>;
37
+ /** Sentinel used whenever the source provider could not be established. */
38
+ declare const UNKNOWN_PROVIDER_ID: "unknown";
39
+ type UnknownProviderId = typeof UNKNOWN_PROVIDER_ID;
40
+ declare const resolvedProviderIdSchema: z.ZodUnion<readonly [z.core.$ZodBranded<z.ZodString, "ProviderId", "out">, z.ZodLiteral<"unknown">]>;
41
+ type ResolvedProviderId = z.infer<typeof resolvedProviderIdSchema>;
42
+ declare const isUnknownProvider: (value: ResolvedProviderId) => value is UnknownProviderId;
43
+ /**
44
+ * Attribute values are restricted to OpenTelemetry-compatible primitives.
45
+ *
46
+ * This restriction is a containment boundary, not a convenience: because no
47
+ * nested object can be represented, a raw provider payload cannot be smuggled
48
+ * out of an adapter through attributes or extensions.
49
+ */
50
+ declare const attributePrimitiveSchema: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
51
+ type AttributePrimitive = z.infer<typeof attributePrimitiveSchema>;
52
+ declare const attributeValueSchema: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>]>;
53
+ type AttributeValue = z.infer<typeof attributeValueSchema>;
54
+ declare const attributesSchema: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>]>>;
55
+ type Attributes = z.infer<typeof attributesSchema>;
56
+ /** Ordered confidence ladder for provider detection. */
57
+ declare const detectionConfidenceSchema: z.ZodEnum<{
58
+ none: "none";
59
+ weak: "weak";
60
+ strong: "strong";
61
+ exact: "exact";
62
+ }>;
63
+ type DetectionConfidence = z.infer<typeof detectionConfidenceSchema>;
64
+ declare const DETECTION_CONFIDENCE_RANK: Readonly<Record<DetectionConfidence, number>>;
65
+ declare const compareDetectionConfidence: (a: DetectionConfidence, b: DetectionConfidence) => number;
66
+ /** How the observed data reached this process. */
67
+ declare const sourceTransportSchema: z.ZodEnum<{
68
+ "hook-stdin": "hook-stdin";
69
+ "cli-argument": "cli-argument";
70
+ "library-call": "library-call";
71
+ "test-fixture": "test-fixture";
72
+ }>;
73
+ type SourceTransport = z.infer<typeof sourceTransportSchema>;
74
+
75
+ export { type AttributePrimitive as A, tokenCountSchema as B, workspaceIdSchema as C, DETECTION_CONFIDENCE_RANK as D, type EpochMillis as E, type InvocationId as I, MAX_ATTRIBUTE_ARRAY_LENGTH as M, PROVIDER_ID_PATTERN as P, type ResolvedProviderId as R, type SessionId as S, UNKNOWN_PROVIDER_ID as U, WORKSPACE_ID_PATTERN as W, type AttributeValue as a, type Attributes as b, type DetectionConfidence as c, type EventId as d, MAX_ATTRIBUTE_STRING_LENGTH as e, MAX_IDENTIFIER_LENGTH as f, type ProviderId as g, type SourceTransport as h, type UnknownProviderId as i, type WorkspaceId as j, attributePrimitiveSchema as k, attributeValueSchema as l, attributesSchema as m, compareDetectionConfidence as n, detectionConfidenceSchema as o, durationMillisSchema as p, epochMillisSchema as q, eventIdSchema as r, invocationIdSchema as s, isUnknownProvider as t, nonEmptyStringSchema as u, providerIdSchema as v, resolvedProviderIdSchema as w, sequenceNumberSchema as x, sessionIdSchema as y, sourceTransportSchema as z };
@@ -0,0 +1,51 @@
1
+ export { C as CONTENT_MODE_DISCLOSURE, a as ContentMode, D as DEFAULT_PRIVACY_LIMITS, b as DEFAULT_PRIVACY_POLICY, c as DEFAULT_SECRET_KEY_PATTERNS, d as DEFAULT_SECRET_VALUE_PATTERNS, P as PolicyResolution, e as PrivacyLimits, f as PrivacyPolicy, g as contentModeSchema, p as privacyLimitsSchema, h as privacyPolicySchema, r as resolvePrivacyPolicy } from './policy-D1CrlYn3.js';
2
+ import { P as PrivacyService } from './service-j4jEO6cZ.js';
3
+ export { D as DescribeContentInput, a as DescribeStructuredInput, S as SanitizeExtensionsResult, b as SanitizeResult, c as SanitizeStats, d as SanitizedValue, e as createPrivacyService } from './service-j4jEO6cZ.js';
4
+ import { W as WorkspaceIdentity } from './identity-BrVBs901.js';
5
+ import 'zod';
6
+ import './content-CoB7aNP1.js';
7
+ import './primitives-CJ8-rn-f.js';
8
+
9
+ /**
10
+ * Raw material a caller can offer for workspace identification.
11
+ *
12
+ * Paths and remote URLs are accepted here and immediately hashed. Neither is
13
+ * retained, so a home directory cannot reach an exporter through this path.
14
+ */
15
+ type WorkspaceKeyInput = {
16
+ readonly kind: "git-remote";
17
+ readonly remoteUrl: string;
18
+ } | {
19
+ readonly kind: "git-root";
20
+ readonly absolutePath: string;
21
+ } | {
22
+ readonly kind: "working-directory";
23
+ readonly absolutePath: string;
24
+ } | {
25
+ readonly kind: "explicit";
26
+ readonly value: string;
27
+ } | {
28
+ readonly kind: "unknown";
29
+ };
30
+ type WorkspaceLabels = {
31
+ /** Bare repository name, e.g. `otel-hook`. Never an owner path or URL. */
32
+ readonly repositoryName?: string;
33
+ readonly vcsBranchName?: string;
34
+ /** Revision identifier; hashed before it is stored. */
35
+ readonly vcsRevisionId?: string;
36
+ };
37
+ /**
38
+ * Canonicalize a git remote so equivalent spellings hash identically:
39
+ * scheme, credentials, port, trailing `.git`, and case are removed.
40
+ */
41
+ declare const canonicalizeGitRemote: (remoteUrl: string) => string;
42
+ /**
43
+ * Derive privacy-safe workspace identity.
44
+ *
45
+ * The identifier is a salted hash namespaced by key source, so a directory-keyed
46
+ * workspace and a remote-keyed workspace never collide even if the underlying
47
+ * strings match.
48
+ */
49
+ declare const deriveWorkspaceIdentity: (privacy: PrivacyService, input: WorkspaceKeyInput, labels?: WorkspaceLabels) => WorkspaceIdentity;
50
+
51
+ export { PrivacyService, type WorkspaceKeyInput, type WorkspaceLabels, canonicalizeGitRemote, deriveWorkspaceIdentity };