@osfactory/otel-hook 0.9.0 → 0.10.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 (49) hide show
  1. package/README.md +42 -1
  2. package/dist/{adapter-BJiz6lqM.d.ts → adapter-B9RwW6TO.d.ts} +14 -2
  3. package/dist/cli.js +1272 -784
  4. package/dist/cli.js.map +1 -1
  5. package/dist/config.d.ts +5 -3
  6. package/dist/config.js +28 -5
  7. package/dist/config.js.map +1 -1
  8. package/dist/{destinations-C6Bm89W6.d.ts → destinations-DWOkVxV1.d.ts} +1 -1
  9. package/dist/{events-B3MHoJTD.d.ts → events-CSD_YiJ2.d.ts} +2 -0
  10. package/dist/{export-destinations-d8tZV0G4.d.ts → export-destinations-lORbe25J.d.ts} +5 -5
  11. package/dist/{filesystem-store-r-nNA3BA.d.ts → filesystem-store-DX3dGIgu.d.ts} +1 -1
  12. package/dist/{hook-zA1b4cWd.d.ts → hook-BAxXoKsp.d.ts} +10 -5
  13. package/dist/index.d.ts +14 -14
  14. package/dist/index.js +643 -110
  15. package/dist/index.js.map +1 -1
  16. package/dist/install.d.ts +4 -4
  17. package/dist/install.js +31 -2
  18. package/dist/install.js.map +1 -1
  19. package/dist/integration.d.ts +17 -10
  20. package/dist/integration.js +3864 -3107
  21. package/dist/integration.js.map +1 -1
  22. package/dist/lifecycle.d.ts +3 -3
  23. package/dist/lifecycle.js +8 -1
  24. package/dist/lifecycle.js.map +1 -1
  25. package/dist/{memory-Bl9ANVff.d.ts → memory-aJilVG4R.d.ts} +2 -2
  26. package/dist/model.d.ts +1 -1
  27. package/dist/model.js +7 -0
  28. package/dist/model.js.map +1 -1
  29. package/dist/{payload-Ci8_ERm6.d.ts → payload-D7gc0-WQ.d.ts} +41 -2
  30. package/dist/{ports-n7KFOpKo.d.ts → ports-plO5MKrY.d.ts} +63 -2
  31. package/dist/providers.d.ts +146 -10
  32. package/dist/providers.js +397 -13
  33. package/dist/providers.js.map +1 -1
  34. package/dist/{registry-B8ZHc2bc.d.ts → registry-C7XO4DzD.d.ts} +2 -2
  35. package/dist/runtime.d.ts +8 -8
  36. package/dist/runtime.js +1356 -1217
  37. package/dist/runtime.js.map +1 -1
  38. package/dist/{schema-BxiVsU-d.d.ts → schema-CHb3GU1r.d.ts} +30 -1
  39. package/dist/{semconv-fPRb-dpU.d.ts → semconv-Dw7gcQcg.d.ts} +1 -1
  40. package/dist/state.d.ts +4 -4
  41. package/dist/state.js +607 -39
  42. package/dist/state.js.map +1 -1
  43. package/dist/telemetry.d.ts +6 -6
  44. package/dist/telemetry.js +13 -3
  45. package/dist/telemetry.js.map +1 -1
  46. package/dist/testing.d.ts +10 -8
  47. package/dist/testing.js +209 -25
  48. package/dist/testing.js.map +1 -1
  49. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { OtelHookErrorInfo } from './errors.js';
3
- import { b as CanonicalEvent, J as WorktreeKind } from './events-B3MHoJTD.js';
3
+ import { b as CanonicalEvent, J as WorktreeKind } from './events-CSD_YiJ2.js';
4
4
  import { E as EpochMillis, I as InvocationId, d as EventId, b as Attributes } from './primitives-CJ8-rn-f.js';
5
5
 
6
6
  /**
@@ -100,6 +100,17 @@ declare const stateValueSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
100
100
  }, z.core.$strict>, z.ZodObject<{
101
101
  kind: z.ZodLiteral<"attributes">;
102
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>, z.ZodObject<{
104
+ kind: z.ZodLiteral<"session-model">;
105
+ model: z.ZodObject<{
106
+ modelId: z.ZodString;
107
+ vendor: z.ZodOptional<z.ZodString>;
108
+ family: z.ZodOptional<z.ZodString>;
109
+ }, z.core.$strict>;
110
+ }, z.core.$strict>, z.ZodObject<{
111
+ kind: z.ZodLiteral<"read-cursor">;
112
+ source: z.ZodString;
113
+ offset: z.ZodNumber;
103
114
  }, z.core.$strict>], "kind">;
104
115
  type StateValue = z.infer<typeof stateValueSchema>;
105
116
  declare const stateRecordSchema: z.ZodObject<{
@@ -141,6 +152,17 @@ declare const stateRecordSchema: z.ZodObject<{
141
152
  }, z.core.$strict>, z.ZodObject<{
142
153
  kind: z.ZodLiteral<"attributes">;
143
154
  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]>>]>>;
155
+ }, z.core.$strict>, z.ZodObject<{
156
+ kind: z.ZodLiteral<"session-model">;
157
+ model: z.ZodObject<{
158
+ modelId: z.ZodString;
159
+ vendor: z.ZodOptional<z.ZodString>;
160
+ family: z.ZodOptional<z.ZodString>;
161
+ }, z.core.$strict>;
162
+ }, z.core.$strict>, z.ZodObject<{
163
+ kind: z.ZodLiteral<"read-cursor">;
164
+ source: z.ZodString;
165
+ offset: z.ZodNumber;
144
166
  }, z.core.$strict>], "kind">;
145
167
  }, z.core.$strict>;
146
168
  type StateRecord = z.infer<typeof stateRecordSchema>;
@@ -222,5 +244,44 @@ type LocatedWorktree = {
222
244
  interface WorktreeLocator {
223
245
  locate(absolutePath: string): Promise<LocatedWorktree | undefined>;
224
246
  }
247
+ /** Where an enricher stopped reading a session's source; see the `read-cursor` state value. */
248
+ type ReadCursor = {
249
+ /** Opaque digest naming the source, so a cursor never applies to another file. */
250
+ readonly source: string;
251
+ /** Byte offset the next read starts at. */
252
+ readonly offset: number;
253
+ };
254
+ type PayloadEnrichmentInput = {
255
+ readonly payload: unknown;
256
+ readonly sessionId: string;
257
+ /** The cursor this enricher stored for this session last time, if any. */
258
+ readonly cursor?: ReadCursor;
259
+ };
260
+ type PayloadEnrichment = {
261
+ /** The payload the adapter parses: the input, or a copy with fields attached. */
262
+ readonly payload: unknown;
263
+ /** A cursor to store for this session; absent leaves the stored one as it is. */
264
+ readonly cursor?: ReadCursor;
265
+ /** Short, non-sensitive notes for the debug log (why a read fell back, ...). */
266
+ readonly notes?: readonly string[];
267
+ };
268
+ /**
269
+ * Host-side step that attaches facts to a provider payload before its adapter
270
+ * parses it — for facts the provider writes somewhere other than the hook
271
+ * payload, such as Claude Code's transcript.
272
+ *
273
+ * Not an adapter capability, on purpose: adapters get no filesystem handle (ADR
274
+ * 0003). An enricher is configured by the host, runs inside the session lock so
275
+ * its cursor is read and written atomically, and must be bounded and never throw
276
+ * (a throw is contained and the original payload is parsed). It never runs for a
277
+ * redelivered callback, which is not a new observation.
278
+ */
279
+ interface PayloadEnricher {
280
+ /** Stable id; namespaces the enricher's cursor in the state store. */
281
+ readonly id: string;
282
+ /** The provider whose payloads it enriches. Others are never passed to it. */
283
+ readonly providerId: string;
284
+ enrich(input: PayloadEnrichmentInput): Promise<PayloadEnrichment>;
285
+ }
225
286
 
226
- 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 WorktreeLocator as W, type InvocationIdSeed as a, type LocatedWorktree as b, type LogLevel as c, type Logger as d, type StateStore as e, type StateValue as f, type TelemetrySink as g, appliedDeliverySchema as h, stateValueSchema as i, logLevelSchema as l, stateRecordSchema as s };
287
+ export { type AppliedDelivery as A, type Clock as C, type EventIdSeed as E, type IdGenerator as I, LOG_LEVEL_RANK as L, type PayloadEnricher as P, type ReadCursor as R, type StateRecord as S, type TelemetryEmitResult as T, type WorktreeLocator as W, type InvocationIdSeed as a, type LocatedWorktree as b, type LogLevel as c, type Logger as d, type PayloadEnrichment as e, type PayloadEnrichmentInput as f, type StateStore as g, type StateValue as h, type TelemetrySink as i, appliedDeliverySchema as j, stateValueSchema as k, logLevelSchema as l, stateRecordSchema as s };
@@ -1,19 +1,20 @@
1
- import { e as ProviderContext, P as ProviderAdapter, d as ProviderCapabilities, b as DeliveryIdentifierSupport, A as AdapterDescription } from './adapter-BJiz6lqM.js';
2
- export { D as DELIVERY_COMPONENT_PATTERN, a as DELIVERY_GAP_REASON_PATTERN, M as MAX_DELIVERY_COMPONENTS, c as MAX_DELIVERY_GAPS, f as ProviderDeliveryClaim, g as ProviderDeliveryGaps, h as ProviderDetection, i as ProviderDetectionInput, j as ProviderHookResponse, k as ProviderHookResponseInput, l as ProviderIdentityInput, m as ProviderParseInput, n as ProviderParseResult, S as SILENT_HOOK_RESPONSE, o as adapterSupports, p as asProviderId, q as deliveryComponentSchema, r as deliveryGapReasonSchema, s as deliveryIdentifierSupportSchema, t as describeAdapter, u as providerCapabilitiesSchema, v as providerDeliveryClaimSchema, w as providerDeliveryGapsSchema, x as providerDetectionSchema, y as providerHookResponseSchema, z as readDeliveryClaim, B as readDeliveryGap, C as unknownDetection } from './adapter-BJiz6lqM.js';
3
- import { b as CanonicalEvent, u as TargetHint, q as SessionStartEvent, p as SessionEndEvent, P as PromptSubmittedEvent, l as GenerationStartEvent, G as GenerationEndEvent, A as ToolStartEvent, y as ToolEndEvent, t as SubagentStartEvent, r as SubagentEndEvent, g as CompactionPerformedEvent, i as ErrorRaisedEvent } from './events-B3MHoJTD.js';
1
+ import { e as ProviderContext, P as ProviderAdapter, d as ProviderCapabilities, b as DeliveryIdentifierSupport, A as AdapterDescription } from './adapter-B9RwW6TO.js';
2
+ export { D as DELIVERY_COMPONENT_PATTERN, a as DELIVERY_GAP_REASON_PATTERN, M as MAX_DELIVERY_COMPONENTS, c as MAX_DELIVERY_GAPS, f as ProviderDeliveryClaim, g as ProviderDeliveryGaps, h as ProviderDetection, i as ProviderDetectionInput, j as ProviderHookResponse, k as ProviderHookResponseInput, l as ProviderIdentityInput, m as ProviderParseInput, n as ProviderParseResult, S as SILENT_HOOK_RESPONSE, o as adapterSupports, p as asProviderId, q as deliveryComponentSchema, r as deliveryGapReasonSchema, s as deliveryIdentifierSupportSchema, t as describeAdapter, u as providerCapabilitiesSchema, v as providerDeliveryClaimSchema, w as providerDeliveryGapsSchema, x as providerDetectionSchema, y as providerHookResponseSchema, z as readDeliveryClaim, B as readDeliveryGap, C as unknownDetection } from './adapter-B9RwW6TO.js';
3
+ import { b as CanonicalEvent, u as TargetHint, q as SessionStartEvent, p as SessionEndEvent, P as PromptSubmittedEvent, l as GenerationStartEvent, G as GenerationEndEvent, A as ToolStartEvent, y as ToolEndEvent, t as SubagentStartEvent, r as SubagentEndEvent, g as CompactionPerformedEvent, i as ErrorRaisedEvent } from './events-CSD_YiJ2.js';
4
4
  import { d as InvocationIdentity } from './identity-BrVBs901.js';
5
5
  import { d as EventId } from './primitives-CJ8-rn-f.js';
6
- import { P as ProviderRegistry } from './registry-B8ZHc2bc.js';
7
- export { B as BUILT_IN_PROVIDERS, D as DetectionCandidate, R as RegistryDetectionResult, c as createProviderRegistry } from './registry-B8ZHc2bc.js';
8
- export { A as ANTIGRAVITY_CAPABILITIES, a as ANTIGRAVITY_HOOK_EVENT_NAMES, b as ANTIGRAVITY_PROVIDER_ID, c as AntigravityAdapterOptions, d as AntigravityHookEventName, C as CLAUDE_CODE_PROVIDER_ID, e as CLAUDE_HOOK_EVENT_NAMES, f as CODEX_ADAPTER_VERSION, g as CODEX_HOOK_EVENT_NAMES, h as CODEX_PROVIDER_ID, i as CURSOR_DECISION_EVENTS, j as CURSOR_HOOK_EVENT_NAMES, k as CURSOR_PROVIDER_ID, l as CURSOR_UNMODELLED_HOOK_EVENT_NAMES, m as ClaudeHookEventName, n as CodexHookEventName, o as CursorHookEventName, D as DEFAULT_GEMINI_CAPABILITIES, G as GEMINI_ADAPTER_VERSION, p as GEMINI_HOOK_EVENT_NAMES, q as GEMINI_PROVIDER_ID, r as GeminiAdapterOptions, s as GeminiHookEventName, t as createAntigravityAdapter, u as createGeminiCliAdapter } from './payload-Ci8_ERm6.js';
6
+ import { P as ProviderRegistry } from './registry-C7XO4DzD.js';
7
+ export { B as BUILT_IN_PROVIDERS, D as DetectionCandidate, R as RegistryDetectionResult, c as createProviderRegistry } from './registry-C7XO4DzD.js';
8
+ import { v as ClaudeUsage } from './payload-D7gc0-WQ.js';
9
+ export { A as ANTIGRAVITY_CAPABILITIES, a as ANTIGRAVITY_HOOK_EVENT_NAMES, b as ANTIGRAVITY_PROVIDER_ID, c as AntigravityAdapterOptions, d as AntigravityHookEventName, C as CLAUDE_CODE_PROVIDER_ID, e as CLAUDE_HOOK_EVENT_NAMES, f as CODEX_ADAPTER_VERSION, g as CODEX_HOOK_EVENT_NAMES, h as CODEX_PROVIDER_ID, i as CURSOR_DECISION_EVENTS, j as CURSOR_HOOK_EVENT_NAMES, k as CURSOR_PROVIDER_ID, l as CURSOR_UNMODELLED_HOOK_EVENT_NAMES, m as ClaudeHookEventName, n as CodexHookEventName, o as CursorHookEventName, D as DEFAULT_GEMINI_CAPABILITIES, G as GEMINI_ADAPTER_VERSION, p as GEMINI_HOOK_EVENT_NAMES, q as GEMINI_PROVIDER_ID, r as GeminiAdapterOptions, s as GeminiHookEventName, t as createAntigravityAdapter, u as createGeminiCliAdapter } from './payload-D7gc0-WQ.js';
10
+ import { P as PayloadEnricher } from './ports-plO5MKrY.js';
9
11
  import 'zod';
10
12
  import './errors.js';
11
13
  import './taxonomy-DwhTtuWd.js';
12
14
  import './policy-CimmCfRp.js';
13
15
  import './content-M9xIKG7h.js';
14
16
  import './service-CbI9CObT.js';
15
- import './ports-n7KFOpKo.js';
16
- import './schema-BxiVsU-d.js';
17
+ import './schema-CHb3GU1r.js';
17
18
 
18
19
  /** Fields the factory supplies; an adapter never sets them itself. */
19
20
  type ManagedFields = "schemaVersion" | "eventId" | "invocationId" | "sessionId" | "sequence" | "provenance" | "workspace" | "extensions" | "subagentId" | "target" | "occurredAt";
@@ -91,7 +92,8 @@ declare const createClaudeCodeAdapter: (options?: ClaudeCodeAdapterOptions) => P
91
92
  * - `reportsCachedInput`/`reportsCacheCreation` are true because the payload
92
93
  * schema *accepts* Anthropic's `message.usage` shape when a wrapping harness
93
94
  * attaches it. No hook callback in the protocol carries a token counter, and
94
- * this adapter never reads the transcript to find them.
95
+ * this adapter never reads the transcript to find them; `transcript.ts` is the
96
+ * bounded helper a wrapper calls to attach them (issue #64).
95
97
  * - `cacheCreationAccounting` is `included-in-input` because `input_tokens` is
96
98
  * the fresh portion only, so the adapter folds all three input buckets into one
97
99
  * inclusive total (see `usage.ts`).
@@ -109,6 +111,140 @@ declare const createClaudeCodeAdapter: (options?: ClaudeCodeAdapterOptions) => P
109
111
  */
110
112
  declare const CLAUDE_CODE_CAPABILITIES: ProviderCapabilities;
111
113
 
114
+ /**
115
+ * Bounded readers for one Claude Code session transcript, and the enricher that
116
+ * uses them to attach a turn's model and token usage to a `Stop` payload.
117
+ *
118
+ * None of this is part of the Claude Code adapter, and the adapter never calls
119
+ * it: `ProviderContext` gives adapters no filesystem handle (ADR 0003). Two
120
+ * callers use it instead:
121
+ *
122
+ * - a wrapping harness, through {@link attachClaudeTranscriptTurn}, which reads
123
+ * the last assistant message only;
124
+ * - the hook runtime, through {@link createClaudeTranscriptUsageEnricher}, when
125
+ * the host turns on `providers.claudeCode.readTranscriptUsage` — the one
126
+ * sanctioned exception to "no transcript reads in the hook". It sums the whole
127
+ * turn, from a byte cursor the runtime keeps in the state store.
128
+ *
129
+ * Why the transcript at all: no Claude Code hook callback carries a token
130
+ * counter, and only `SessionStart` names a model. The per-turn model
131
+ * (`message.model`, which follows `/model`) and the Anthropic usage object
132
+ * (`message.usage`) exist only on assistant transcript records, one record per
133
+ * content block, each repeating its request's `message.id`.
134
+ *
135
+ * Every bound is hard, and nothing here throws:
136
+ * - only regular `.jsonl` files at an absolute path are opened, so a FIFO or a
137
+ * device cannot stall the hook, and no directory is ever listed;
138
+ * - a read is capped in bytes and raced against a time budget;
139
+ * - a malformed or truncated line is skipped, never fatal.
140
+ *
141
+ * Nothing but model ids and numeric counters leaves this module: a record's
142
+ * content (prompt, response, thinking, tool input) is parsed only to be dropped.
143
+ */
144
+ type ClaudeTranscriptUnavailableReason = "invalid-path" | "not-a-file" | "unreadable" | "timeout" | "no-assistant-message";
145
+ type ClaudeTranscriptTurn = {
146
+ readonly status: "found";
147
+ /** `message.model`; absent when the record named none. */
148
+ readonly model?: string;
149
+ /** `message.usage`, coerced onto the shape the `Stop` schema accepts. */
150
+ readonly usage?: ClaudeUsage;
151
+ } | {
152
+ readonly status: "unavailable";
153
+ readonly reason: ClaudeTranscriptUnavailableReason;
154
+ };
155
+ type ReadClaudeTranscriptTurnOptions = {
156
+ /** Bytes read from the end of the file. Default 1 MiB, clamped to 64 KiB..16 MiB. */
157
+ readonly maxTailBytes?: number;
158
+ /** Budget for the whole read. Default 250 ms, clamped to 10 ms..5 s. */
159
+ readonly timeoutMillis?: number;
160
+ };
161
+ declare const DEFAULT_CLAUDE_TRANSCRIPT_TAIL_BYTES = 1048576;
162
+ declare const DEFAULT_CLAUDE_TRANSCRIPT_TIMEOUT_MILLIS = 250;
163
+ declare const DEFAULT_CLAUDE_TRANSCRIPT_RANGE_BYTES = 8388608;
164
+ declare const DEFAULT_CLAUDE_TRANSCRIPT_RANGE_TIMEOUT_MILLIS = 500;
165
+ /**
166
+ * Read the model and usage of the last main-thread assistant message in a
167
+ * Claude Code transcript. Never throws, never rejects.
168
+ *
169
+ * The usage is that **one message's** — the final model request of the turn. A
170
+ * turn that called tools made several requests, and the earlier ones are not
171
+ * summed in; {@link readClaudeTranscriptRange} sums a whole turn.
172
+ */
173
+ declare const readClaudeTranscriptTurn: (transcriptPath: string, options?: ReadClaudeTranscriptTurnOptions) => Promise<ClaudeTranscriptTurn>;
174
+ type ClaudeTranscriptRange = {
175
+ readonly status: "found";
176
+ /** Model of the last main-thread assistant record in the range. */
177
+ readonly model?: string;
178
+ /** Summed usage of every distinct request; absent when none reported usage. */
179
+ readonly usage?: ClaudeUsage;
180
+ /** Distinct main-thread requests (by `message.id`) in the range. */
181
+ readonly requestCount: number;
182
+ /** Offset just past the last complete line read: the next range starts here. */
183
+ readonly endOffset: number;
184
+ } | {
185
+ readonly status: "unavailable";
186
+ readonly reason: "invalid-path" | "not-a-file" | "unreadable" | "timeout"
187
+ /** The file is shorter than the offset: it was replaced or truncated. */
188
+ | "truncated"
189
+ /** More than the range cap was written since the offset. */
190
+ | "over-cap";
191
+ };
192
+ type ReadClaudeTranscriptRangeOptions = {
193
+ /** Most bytes a range may span. Default 8 MiB, clamped to 64 KiB..64 MiB. */
194
+ readonly maxRangeBytes?: number;
195
+ /** Budget for the whole range read. Default 500 ms, clamped to 10 ms..5 s. */
196
+ readonly rangeTimeoutMillis?: number;
197
+ };
198
+ /**
199
+ * Sum every main-thread model request written between `fromOffset` and the end
200
+ * of the transcript. Never throws, never rejects.
201
+ *
202
+ * Records of one request share a `message.id` and each repeats its usage, so the
203
+ * last record per id is the one counted; a record without an id counts alone.
204
+ * A trailing partial line is left for the next range.
205
+ */
206
+ declare const readClaudeTranscriptRange: (transcriptPath: string, fromOffset: number, options?: ReadClaudeTranscriptRangeOptions) => Promise<ClaudeTranscriptRange>;
207
+ /**
208
+ * Attach the last assistant message's `{ model, usage }` to a Claude Code
209
+ * `Stop` / `StopFailure` payload, for a wrapper to hand to otel-hook.
210
+ *
211
+ * The usage is one request's, so it is attached with `usage_partial: true`,
212
+ * which the exported generation reports as `otelhook.usage.partial`. For whole
213
+ * turn totals, turn on `providers.claudeCode.readTranscriptUsage` instead.
214
+ *
215
+ * Returns the payload unchanged when it is not a stop, names no
216
+ * `transcript_path`, already carries both fields, or the transcript yields
217
+ * nothing — so a wrapper can call it unconditionally. A field the payload
218
+ * already carries is never overwritten. Never throws, never rejects.
219
+ */
220
+ declare const attachClaudeTranscriptTurn: (payload: unknown, options?: ReadClaudeTranscriptTurnOptions) => Promise<unknown>;
221
+ type ClaudeTranscriptUsageEnricherOptions = ReadClaudeTranscriptTurnOptions & ReadClaudeTranscriptRangeOptions;
222
+ declare const CLAUDE_TRANSCRIPT_USAGE_ENRICHER_ID = "claude-transcript-usage";
223
+ /**
224
+ * The hook-runtime side of `providers.claudeCode.readTranscriptUsage`: attach
225
+ * each turn's model and **summed** usage to its `Stop` / `StopFailure`.
226
+ *
227
+ * The runtime keeps a byte cursor per session (state value `read-cursor`):
228
+ *
229
+ * - `SessionStart` records where the transcript ends now (0 when it does not
230
+ * exist yet), unless a cursor for the same transcript is already stored — a
231
+ * compaction restart must not skip the turn it interrupted.
232
+ * - `Stop` sums every main-thread request from the cursor to the end, and moves
233
+ * the cursor there. That is the exact turn total: `usage_partial: false`.
234
+ * - With no usable cursor (enabled mid-session, an expired or lost store, a
235
+ * different transcript), a range over the cap, or a transcript that shrank, it
236
+ * falls back to the last request in the bounded tail, attaches it with
237
+ * `usage_partial: true`, and moves the cursor to the end so the next turn is
238
+ * exact again.
239
+ * - A timeout or an unreadable file attaches nothing and keeps the cursor, so
240
+ * the next turn's range includes this one: tokens are counted late, never
241
+ * twice and never lost.
242
+ *
243
+ * A payload that already carries `usage` (a wrapper attached it) is left as it
244
+ * is, and the cursor moves past it so those tokens are not counted again.
245
+ */
246
+ declare const createClaudeTranscriptUsageEnricher: (options?: ClaudeTranscriptUsageEnricherOptions) => PayloadEnricher;
247
+
112
248
  /**
113
249
  * Provider adapter for Cursor's agent hooks.
114
250
  *
@@ -271,4 +407,4 @@ declare const DELIVERY_IDENTIFIER_SUMMARY: Readonly<Record<DeliveryIdentifierSup
271
407
  */
272
408
  declare const describeProviderCatalog: (options?: DefaultRegistryOptions) => readonly ProviderCatalogEntry[];
273
409
 
274
- export { ANTIGRAVITY_PROMOTION_GATES, ANTIGRAVITY_PROVIDER_MATURITY, AdapterDescription, type AntigravityProviderMaturity, CLAUDE_CODE_CAPABILITIES, CODEX_CAPABILITIES, CURSOR_ADAPTER_VERSION, CURSOR_CAPABILITIES, type CanonicalEventDraft, type ClaudeCodeAdapterOptions, type CursorAdapterOptions, DELIVERY_IDENTIFIER_SUMMARY, type DefaultRegistryOptions, DeliveryIdentifierSupport, EXPERIMENTAL_PROVIDER_IDS, type EventFactory, type EventFactoryInput, PROVIDER_DESCRIPTORS, ProviderAdapter, ProviderCapabilities, type ProviderCatalogEntry, ProviderContext, type ProviderDescriptor, type ProviderMaturity, ProviderRegistry, createClaudeCodeAdapter, createCodexAdapter, createCursorAdapter, createDefaultProviderRegistry, createEventFactory, describeProviderCatalog, findProviderDescriptor, isExperimentalProvider };
410
+ export { ANTIGRAVITY_PROMOTION_GATES, ANTIGRAVITY_PROVIDER_MATURITY, AdapterDescription, type AntigravityProviderMaturity, CLAUDE_CODE_CAPABILITIES, CLAUDE_TRANSCRIPT_USAGE_ENRICHER_ID, CODEX_CAPABILITIES, CURSOR_ADAPTER_VERSION, CURSOR_CAPABILITIES, type CanonicalEventDraft, type ClaudeCodeAdapterOptions, type ClaudeTranscriptRange, type ClaudeTranscriptTurn, type ClaudeTranscriptUsageEnricherOptions, type CursorAdapterOptions, DEFAULT_CLAUDE_TRANSCRIPT_RANGE_BYTES, DEFAULT_CLAUDE_TRANSCRIPT_RANGE_TIMEOUT_MILLIS, DEFAULT_CLAUDE_TRANSCRIPT_TAIL_BYTES, DEFAULT_CLAUDE_TRANSCRIPT_TIMEOUT_MILLIS, DELIVERY_IDENTIFIER_SUMMARY, type DefaultRegistryOptions, DeliveryIdentifierSupport, EXPERIMENTAL_PROVIDER_IDS, type EventFactory, type EventFactoryInput, PROVIDER_DESCRIPTORS, ProviderAdapter, ProviderCapabilities, type ProviderCatalogEntry, ProviderContext, type ProviderDescriptor, type ProviderMaturity, ProviderRegistry, type ReadClaudeTranscriptRangeOptions, type ReadClaudeTranscriptTurnOptions, attachClaudeTranscriptTurn, createClaudeCodeAdapter, createClaudeTranscriptUsageEnricher, createCodexAdapter, createCursorAdapter, createDefaultProviderRegistry, createEventFactory, describeProviderCatalog, findProviderDescriptor, isExperimentalProvider, readClaudeTranscriptRange, readClaudeTranscriptTurn };