@osfactory/otel-hook 0.11.0 → 0.13.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.
- package/README.md +32 -5
- package/dist/{adapter-DiLknaTF.d.ts → adapter-DyCb7y1N.d.ts} +2 -2
- package/dist/cli.js +507 -108
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +3 -3
- package/dist/config.js +16 -3
- package/dist/config.js.map +1 -1
- package/dist/{destinations-BIl3gGzx.d.ts → destinations-DvqsPulb.d.ts} +1 -1
- package/dist/{events-CSD_YiJ2.d.ts → events-fcomX6d5.d.ts} +22 -0
- package/dist/{export-destinations-QWKGGEjk.d.ts → export-destinations-Bey2djRk.d.ts} +11 -6
- package/dist/{filesystem-store-D3SCNmbX.d.ts → filesystem-store-B3CpiIRl.d.ts} +1 -1
- package/dist/{hook-BOecWGSz.d.ts → hook-D5imE0Qc.d.ts} +11 -5
- package/dist/index.d.ts +14 -14
- package/dist/index.js +525 -143
- package/dist/index.js.map +1 -1
- package/dist/install.d.ts +4 -4
- package/dist/install.js +19 -2
- package/dist/install.js.map +1 -1
- package/dist/integration.d.ts +16 -10
- package/dist/integration.js +447 -111
- package/dist/integration.js.map +1 -1
- package/dist/lifecycle.d.ts +3 -3
- package/dist/lifecycle.js +10 -2
- package/dist/lifecycle.js.map +1 -1
- package/dist/{memory-Cs51jyRk.d.ts → memory-B3r6sZtC.d.ts} +2 -2
- package/dist/{metric-model-DDnWxL9d.d.ts → metric-model-CFIeUwqd.d.ts} +6 -2
- package/dist/model.d.ts +1 -1
- package/dist/model.js +9 -1
- package/dist/model.js.map +1 -1
- package/dist/{payload-ChtrEX6A.d.ts → payload-CdDKeRpH.d.ts} +1 -1
- package/dist/{ports-CeqLq31i.d.ts → ports-DhpSDIkp.d.ts} +41 -3
- package/dist/providers.d.ts +30 -14
- package/dist/providers.js +131 -42
- package/dist/providers.js.map +1 -1
- package/dist/{registry-CcJNF3WY.d.ts → registry-BKQhhIO3.d.ts} +2 -2
- package/dist/runtime.d.ts +97 -9
- package/dist/runtime.js +269 -26
- package/dist/runtime.js.map +1 -1
- package/dist/{schema-DMnoU1V_.d.ts → schema-SpFM6YQY.d.ts} +24 -1
- package/dist/state.d.ts +4 -4
- package/dist/state.js +9 -1
- package/dist/state.js.map +1 -1
- package/dist/telemetry.d.ts +6 -6
- package/dist/telemetry.js +80 -22
- package/dist/telemetry.js.map +1 -1
- package/dist/testing.d.ts +10 -8
- package/dist/testing.js +161 -30
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
package/dist/providers.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { e as ProviderContext, P as ProviderAdapter, d as ProviderCapabilities, b as DeliveryIdentifierSupport, A as AdapterDescription } from './adapter-
|
|
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-
|
|
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-
|
|
1
|
+
import { e as ProviderContext, P as ProviderAdapter, d as ProviderCapabilities, b as DeliveryIdentifierSupport, A as AdapterDescription } from './adapter-DyCb7y1N.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-DyCb7y1N.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-fcomX6d5.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-
|
|
7
|
-
export { B as BUILT_IN_PROVIDERS, D as DetectionCandidate, R as RegistryDetectionResult, c as createProviderRegistry } from './registry-
|
|
8
|
-
import { v as ClaudeUsage } from './payload-
|
|
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-
|
|
10
|
-
import { P as PayloadEnricher } from './ports-
|
|
6
|
+
import { P as ProviderRegistry } from './registry-BKQhhIO3.js';
|
|
7
|
+
export { B as BUILT_IN_PROVIDERS, D as DetectionCandidate, R as RegistryDetectionResult, c as createProviderRegistry } from './registry-BKQhhIO3.js';
|
|
8
|
+
import { v as ClaudeUsage } from './payload-CdDKeRpH.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-CdDKeRpH.js';
|
|
10
|
+
import { P as PayloadEnricher } from './ports-DhpSDIkp.js';
|
|
11
11
|
import 'zod';
|
|
12
12
|
import './errors.js';
|
|
13
13
|
import './taxonomy-DwhTtuWd.js';
|
|
14
14
|
import './policy-CimmCfRp.js';
|
|
15
15
|
import './content-M9xIKG7h.js';
|
|
16
16
|
import './service-CbI9CObT.js';
|
|
17
|
-
import './schema-
|
|
17
|
+
import './schema-SpFM6YQY.js';
|
|
18
18
|
|
|
19
19
|
/** Fields the factory supplies; an adapter never sets them itself. */
|
|
20
|
-
type ManagedFields = "schemaVersion" | "eventId" | "invocationId" | "sessionId" | "sequence" | "provenance" | "workspace" | "extensions" | "subagentId" | "target" | "occurredAt";
|
|
20
|
+
type ManagedFields = "schemaVersion" | "eventId" | "invocationId" | "sessionId" | "sequence" | "provenance" | "workspace" | "extensions" | "subagentId" | "contextAttributes" | "target" | "occurredAt";
|
|
21
21
|
type Draft<TEvent extends CanonicalEvent> = Omit<TEvent, ManagedFields> & {
|
|
22
22
|
/** Defaults to the clock reading at build time. */
|
|
23
23
|
readonly occurredAt?: number;
|
|
@@ -194,10 +194,16 @@ type ReadClaudeTranscriptRangeOptions = {
|
|
|
194
194
|
readonly maxRangeBytes?: number;
|
|
195
195
|
/** Budget for the whole range read. Default 500 ms, clamped to 10 ms..5 s. */
|
|
196
196
|
readonly rangeTimeoutMillis?: number;
|
|
197
|
+
/**
|
|
198
|
+
* Read subagent `agentId`'s requests (its sidechain records) instead of the
|
|
199
|
+
* main thread's. For a subagent's own transcript, `agent_transcript_path`.
|
|
200
|
+
*/
|
|
201
|
+
readonly agentId?: string;
|
|
197
202
|
};
|
|
198
203
|
/**
|
|
199
|
-
* Sum every main-thread model request
|
|
200
|
-
* of the transcript. Never
|
|
204
|
+
* Sum every main-thread model request (or, with `agentId`, every request of that
|
|
205
|
+
* subagent) written between `fromOffset` and the end of the transcript. Never
|
|
206
|
+
* throws, never rejects.
|
|
201
207
|
*
|
|
202
208
|
* Records of one request share a `message.id` and each repeats its usage, so the
|
|
203
209
|
* last record per id is the one counted; a record without an id counts alone.
|
|
@@ -218,11 +224,12 @@ declare const readClaudeTranscriptRange: (transcriptPath: string, fromOffset: nu
|
|
|
218
224
|
* already carries is never overwritten. Never throws, never rejects.
|
|
219
225
|
*/
|
|
220
226
|
declare const attachClaudeTranscriptTurn: (payload: unknown, options?: ReadClaudeTranscriptTurnOptions) => Promise<unknown>;
|
|
221
|
-
type ClaudeTranscriptUsageEnricherOptions = ReadClaudeTranscriptTurnOptions & ReadClaudeTranscriptRangeOptions
|
|
227
|
+
type ClaudeTranscriptUsageEnricherOptions = ReadClaudeTranscriptTurnOptions & Omit<ReadClaudeTranscriptRangeOptions, "agentId">;
|
|
222
228
|
declare const CLAUDE_TRANSCRIPT_USAGE_ENRICHER_ID = "claude-transcript-usage";
|
|
223
229
|
/**
|
|
224
230
|
* The hook-runtime side of `providers.claudeCode.readTranscriptUsage`: attach
|
|
225
|
-
* each turn's model and **summed** usage to its `Stop` / `StopFailure
|
|
231
|
+
* each turn's model and **summed** usage to its `Stop` / `StopFailure`, and each
|
|
232
|
+
* subagent run's to its `SubagentStop`.
|
|
226
233
|
*
|
|
227
234
|
* The runtime keeps a byte cursor per session (state value `read-cursor`):
|
|
228
235
|
*
|
|
@@ -240,6 +247,15 @@ declare const CLAUDE_TRANSCRIPT_USAGE_ENRICHER_ID = "claude-transcript-usage";
|
|
|
240
247
|
* the next turn's range includes this one: tokens are counted late, never
|
|
241
248
|
* twice and never lost.
|
|
242
249
|
*
|
|
250
|
+
* `SubagentStop` does the same over the subagent's own transcript
|
|
251
|
+
* (`agent_transcript_path`), with a cursor of its own per subagent (see
|
|
252
|
+
* {@link PayloadEnricher.cursorScope}), summing that agent's sidechain records.
|
|
253
|
+
* A subagent with no cursor yet is read from the start of its file: the file is
|
|
254
|
+
* that subagent's alone, so the first stop is its exact total, not a fallback.
|
|
255
|
+
* The parent's cursor is never touched, and the parent's `Stop` never counts
|
|
256
|
+
* sidechain records, so a subagent's requests are counted once, on its own
|
|
257
|
+
* generation (issue #68).
|
|
258
|
+
*
|
|
243
259
|
* A payload that already carries `usage` (a wrapper attached it) is left as it
|
|
244
260
|
* is, and the cursor moves past it so those tokens are not counted again.
|
|
245
261
|
*/
|
package/dist/providers.js
CHANGED
|
@@ -647,7 +647,15 @@ var baseEventFields = {
|
|
|
647
647
|
* factory, never by hand.
|
|
648
648
|
*/
|
|
649
649
|
subagentId: subagentIdSchema.optional(),
|
|
650
|
-
extensions: extensionsSchema.default(emptyExtensions)
|
|
650
|
+
extensions: extensionsSchema.default(emptyExtensions),
|
|
651
|
+
/**
|
|
652
|
+
* Attributes of the session context segment in force when the event
|
|
653
|
+
* occurred (`docs/session-context.md`), stamped by the core from a file a
|
|
654
|
+
* harness wrote. Exported on every record of the event, over the same keys
|
|
655
|
+
* from the Resource. Absent when no context applies. Set by the core only,
|
|
656
|
+
* never by an adapter.
|
|
657
|
+
*/
|
|
658
|
+
contextAttributes: z9.record(z9.string().min(1).max(255), z9.union([z9.string(), z9.number(), z9.boolean()])).optional()
|
|
651
659
|
};
|
|
652
660
|
var event = (shape) => z9.strictObject({ ...baseEventFields, ...shape });
|
|
653
661
|
var sessionStartEventSchema = event({
|
|
@@ -1006,6 +1014,7 @@ var createEventFactory = (input) => {
|
|
|
1006
1014
|
const rest = { ...drafted };
|
|
1007
1015
|
delete rest.target;
|
|
1008
1016
|
delete rest.subagentId;
|
|
1017
|
+
delete rest.contextAttributes;
|
|
1009
1018
|
const sanitized = extensions === void 0 ? { extensions: {}, droppedKeys: [] } : context.privacy.sanitizeExtensions(extensions);
|
|
1010
1019
|
dropped.push(...sanitized.droppedKeys);
|
|
1011
1020
|
const currentSequence = sequence;
|
|
@@ -1314,7 +1323,16 @@ var subagentStopPayloadSchema = z12.object({
|
|
|
1314
1323
|
last_assistant_message: z12.string().optional(),
|
|
1315
1324
|
/** True when this stop fired because a hook continued the subagent's turn. */
|
|
1316
1325
|
stop_hook_active: z12.boolean().optional(),
|
|
1317
|
-
|
|
1326
|
+
/**
|
|
1327
|
+
* The subagent run's tokens since its previous stop — harness- or
|
|
1328
|
+
* enricher-supplied, never upstream. Reported on the subagent's own
|
|
1329
|
+
* generation, never on the parent turn (issue #68).
|
|
1330
|
+
*/
|
|
1331
|
+
usage: claudeUsageSchema.optional(),
|
|
1332
|
+
/** Harness-supplied, never upstream: the subagent's model, from its transcript. */
|
|
1333
|
+
model: z12.string().min(1).max(256).optional().catch(void 0),
|
|
1334
|
+
/** Harness-supplied, never upstream: see `stopPayloadSchema.usage_partial`. */
|
|
1335
|
+
usage_partial: z12.boolean().optional().catch(void 0)
|
|
1318
1336
|
});
|
|
1319
1337
|
var preCompactPayloadSchema = z12.object({
|
|
1320
1338
|
...commonFields,
|
|
@@ -1959,6 +1977,8 @@ var BUILT_IN_TOOL_KIND = Object.freeze({
|
|
|
1959
1977
|
WebFetch: "network",
|
|
1960
1978
|
WebSearch: "network",
|
|
1961
1979
|
Task: "delegate",
|
|
1980
|
+
// Current Claude Code releases (observed on 2.1.332) name the subagent tool `Agent`.
|
|
1981
|
+
Agent: "delegate",
|
|
1962
1982
|
TodoWrite: "other",
|
|
1963
1983
|
ExitPlanMode: "other",
|
|
1964
1984
|
AskUserQuestion: "other",
|
|
@@ -2132,14 +2152,39 @@ var parseClaudeCode = (input, context) => {
|
|
|
2132
2152
|
delegationDepth: 1
|
|
2133
2153
|
});
|
|
2134
2154
|
break;
|
|
2135
|
-
case "SubagentStop":
|
|
2155
|
+
case "SubagentStop": {
|
|
2156
|
+
const usage = withPartialUsage(extractedUsage ?? payload.usage, payload.usage_partial);
|
|
2157
|
+
if (usage.usage !== void 0 || payload.model !== void 0) {
|
|
2158
|
+
const generationId = context.ids.newOpaqueId([
|
|
2159
|
+
"claude-subagent-generation",
|
|
2160
|
+
payload.session_id,
|
|
2161
|
+
payload.agent_id,
|
|
2162
|
+
...payload.stop_hook_active === true ? [String(input.sequenceBase)] : []
|
|
2163
|
+
]);
|
|
2164
|
+
const models = generationModels(payload.model, void 0);
|
|
2165
|
+
factory.build({ type: "generation.start", generationId, model: models.request });
|
|
2166
|
+
factory.build({
|
|
2167
|
+
type: "generation.end",
|
|
2168
|
+
generationId,
|
|
2169
|
+
model: models.response,
|
|
2170
|
+
outcome: "ok",
|
|
2171
|
+
outputContent: [
|
|
2172
|
+
payload.last_assistant_message === void 0 ? context.privacy.describeUnavailableContent({ kind: "response", role: "assistant" }) : context.privacy.describeContent({
|
|
2173
|
+
kind: "response",
|
|
2174
|
+
role: "assistant",
|
|
2175
|
+
text: payload.last_assistant_message
|
|
2176
|
+
})
|
|
2177
|
+
],
|
|
2178
|
+
...usage
|
|
2179
|
+
});
|
|
2180
|
+
}
|
|
2136
2181
|
factory.build({
|
|
2137
2182
|
type: "subagent.end",
|
|
2138
2183
|
subagentInvocationId: subagentInvocationIdFor(context, payload.session_id, payload.agent_id),
|
|
2139
|
-
outcome: "ok"
|
|
2140
|
-
...withUsage(payload.usage)
|
|
2184
|
+
outcome: "ok"
|
|
2141
2185
|
});
|
|
2142
2186
|
break;
|
|
2187
|
+
}
|
|
2143
2188
|
case "PreCompact":
|
|
2144
2189
|
return {
|
|
2145
2190
|
status: "ignored",
|
|
@@ -2259,7 +2304,8 @@ var clamp = (value, fallback, min, max) => {
|
|
|
2259
2304
|
};
|
|
2260
2305
|
var asRecord5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
2261
2306
|
var isTranscriptPath = (transcriptPath) => typeof transcriptPath === "string" && transcriptPath.length > 0 && !transcriptPath.includes("\0") && path.isAbsolute(transcriptPath) && path.extname(transcriptPath) === ".jsonl";
|
|
2262
|
-
var
|
|
2307
|
+
var isRecordOfAgent = (record, agentId) => record.isSidechain === true && (typeof record.agentId !== "string" || record.agentId === agentId);
|
|
2308
|
+
var assistantRecordOf = (line, agentId) => {
|
|
2263
2309
|
if (!line.includes('"assistant"')) {
|
|
2264
2310
|
return void 0;
|
|
2265
2311
|
}
|
|
@@ -2270,7 +2316,10 @@ var assistantRecordOf = (line) => {
|
|
|
2270
2316
|
return void 0;
|
|
2271
2317
|
}
|
|
2272
2318
|
const record = asRecord5(parsed);
|
|
2273
|
-
if (record === void 0 || record.type !== "assistant"
|
|
2319
|
+
if (record === void 0 || record.type !== "assistant") {
|
|
2320
|
+
return void 0;
|
|
2321
|
+
}
|
|
2322
|
+
if (agentId === void 0 ? record.isSidechain === true : !isRecordOfAgent(record, agentId)) {
|
|
2274
2323
|
return void 0;
|
|
2275
2324
|
}
|
|
2276
2325
|
const message = asRecord5(record.message);
|
|
@@ -2363,7 +2412,7 @@ var completeLinesEnd = (bytes, start) => {
|
|
|
2363
2412
|
const lastNewline = bytes.lastIndexOf(10);
|
|
2364
2413
|
return lastNewline < 0 ? start : start + lastNewline + 1;
|
|
2365
2414
|
};
|
|
2366
|
-
var readTail = (transcriptPath, maxTailBytes) => withRegularFile(transcriptPath, async (handle, size) => {
|
|
2415
|
+
var readTail = (transcriptPath, maxTailBytes, agentId) => withRegularFile(transcriptPath, async (handle, size) => {
|
|
2367
2416
|
const length = Math.min(size, maxTailBytes);
|
|
2368
2417
|
const start = size - length;
|
|
2369
2418
|
const bytes = await readBytes(handle, start, length);
|
|
@@ -2373,7 +2422,7 @@ var readTail = (transcriptPath, maxTailBytes) => withRegularFile(transcriptPath,
|
|
|
2373
2422
|
lines.shift();
|
|
2374
2423
|
}
|
|
2375
2424
|
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
2376
|
-
const record = assistantRecordOf((lines[index] ?? "").trim());
|
|
2425
|
+
const record = assistantRecordOf((lines[index] ?? "").trim(), agentId);
|
|
2377
2426
|
if (record !== void 0) {
|
|
2378
2427
|
return {
|
|
2379
2428
|
turn: {
|
|
@@ -2387,10 +2436,11 @@ var readTail = (transcriptPath, maxTailBytes) => withRegularFile(transcriptPath,
|
|
|
2387
2436
|
}
|
|
2388
2437
|
return { turn: { status: "unavailable", reason: "no-assistant-message" }, endOffset };
|
|
2389
2438
|
});
|
|
2390
|
-
var boundedTail = async (transcriptPath, options) => withTimeout(
|
|
2439
|
+
var boundedTail = async (transcriptPath, options, agentId) => withTimeout(
|
|
2391
2440
|
readTail(
|
|
2392
2441
|
transcriptPath,
|
|
2393
|
-
clamp(options.maxTailBytes, DEFAULT_CLAUDE_TRANSCRIPT_TAIL_BYTES, MIN_TAIL_BYTES, MAX_TAIL_BYTES)
|
|
2442
|
+
clamp(options.maxTailBytes, DEFAULT_CLAUDE_TRANSCRIPT_TAIL_BYTES, MIN_TAIL_BYTES, MAX_TAIL_BYTES),
|
|
2443
|
+
agentId
|
|
2394
2444
|
),
|
|
2395
2445
|
clamp(options.timeoutMillis, DEFAULT_CLAUDE_TRANSCRIPT_TIMEOUT_MILLIS, MIN_TIMEOUT_MILLIS, MAX_TIMEOUT_MILLIS),
|
|
2396
2446
|
{ status: "unavailable", reason: "unreadable" }
|
|
@@ -2430,7 +2480,7 @@ var readClaudeTranscriptRange = async (transcriptPath, fromOffset, options = {})
|
|
|
2430
2480
|
let anonymous = 0;
|
|
2431
2481
|
let model;
|
|
2432
2482
|
for (const line of complete.split("\n")) {
|
|
2433
|
-
const record = assistantRecordOf(line.trim());
|
|
2483
|
+
const record = assistantRecordOf(line.trim(), options.agentId);
|
|
2434
2484
|
if (record === void 0) {
|
|
2435
2485
|
continue;
|
|
2436
2486
|
}
|
|
@@ -2492,6 +2542,20 @@ var attachClaudeTranscriptTurn = async (payload, options = {}) => {
|
|
|
2492
2542
|
};
|
|
2493
2543
|
var CLAUDE_TRANSCRIPT_USAGE_ENRICHER_ID = "claude-transcript-usage";
|
|
2494
2544
|
var sourceDigest = (transcriptPath) => createHash("sha256").update(transcriptPath, "utf8").digest("hex").slice(0, 32);
|
|
2545
|
+
var SUBAGENT_STOP = "SubagentStop";
|
|
2546
|
+
var agentIdOf = (record) => {
|
|
2547
|
+
const agentId = record.agent_id ?? record.agentId;
|
|
2548
|
+
return typeof agentId === "string" && agentId.length > 0 && agentId.length <= 256 ? agentId : void 0;
|
|
2549
|
+
};
|
|
2550
|
+
var agentTranscriptPathOf = (record) => record.agent_transcript_path ?? record.agentTranscriptPath;
|
|
2551
|
+
var subagentCursorScope = (payload) => {
|
|
2552
|
+
const record = asRecord5(payload);
|
|
2553
|
+
if (record === void 0 || eventNameOf(record) !== SUBAGENT_STOP) {
|
|
2554
|
+
return void 0;
|
|
2555
|
+
}
|
|
2556
|
+
const agentId = agentIdOf(record);
|
|
2557
|
+
return agentId === void 0 ? void 0 : `agent-${createHash("sha256").update(agentId, "utf8").digest("hex").slice(0, 32)}`;
|
|
2558
|
+
};
|
|
2495
2559
|
var createClaudeTranscriptUsageEnricher = (options = {}) => {
|
|
2496
2560
|
const fileSize = async (transcriptPath) => {
|
|
2497
2561
|
try {
|
|
@@ -2501,6 +2565,46 @@ var createClaudeTranscriptUsageEnricher = (options = {}) => {
|
|
|
2501
2565
|
return thrown?.code === "ENOENT" ? "absent" : void 0;
|
|
2502
2566
|
}
|
|
2503
2567
|
};
|
|
2568
|
+
const readOptions = (agentId) => ({
|
|
2569
|
+
...options.maxRangeBytes === void 0 ? {} : { maxRangeBytes: options.maxRangeBytes },
|
|
2570
|
+
...options.rangeTimeoutMillis === void 0 ? {} : { rangeTimeoutMillis: options.rangeTimeoutMillis },
|
|
2571
|
+
...agentId === void 0 ? {} : { agentId }
|
|
2572
|
+
});
|
|
2573
|
+
const attachSince = async (record, transcriptPath, fromOffset, agentId) => {
|
|
2574
|
+
const source = sourceDigest(transcriptPath);
|
|
2575
|
+
const attach = (model, usage, partial) => ({
|
|
2576
|
+
...record,
|
|
2577
|
+
...record.model === void 0 && model !== void 0 ? { model } : {},
|
|
2578
|
+
...usage === void 0 ? {} : { usage, usage_partial: partial }
|
|
2579
|
+
});
|
|
2580
|
+
if (fromOffset !== void 0) {
|
|
2581
|
+
const range = await readClaudeTranscriptRange(transcriptPath, fromOffset, readOptions(agentId));
|
|
2582
|
+
if (range.status === "found") {
|
|
2583
|
+
return {
|
|
2584
|
+
payload: attach(range.model, range.usage, false),
|
|
2585
|
+
cursor: { source, offset: range.endOffset },
|
|
2586
|
+
notes: [`summed ${String(range.requestCount)} request(s) since the last stop`]
|
|
2587
|
+
};
|
|
2588
|
+
}
|
|
2589
|
+
if (range.reason !== "truncated" && range.reason !== "over-cap") {
|
|
2590
|
+
return { payload: record, notes: [`transcript range not read (${range.reason}); cursor kept`] };
|
|
2591
|
+
}
|
|
2592
|
+
}
|
|
2593
|
+
const tail = await boundedTail(transcriptPath, options, agentId);
|
|
2594
|
+
if (tail === TIMED_OUT || !("turn" in tail)) {
|
|
2595
|
+
return { payload: record, notes: [`transcript tail not read (${tail === TIMED_OUT ? "timeout" : tail.reason})`] };
|
|
2596
|
+
}
|
|
2597
|
+
const why = fromOffset === void 0 ? "no cursor for this transcript" : "range not summable within bounds";
|
|
2598
|
+
return {
|
|
2599
|
+
payload: tail.turn.status === "found" ? attach(tail.turn.model, tail.turn.usage, true) : record,
|
|
2600
|
+
cursor: { source, offset: tail.endOffset },
|
|
2601
|
+
notes: [`${why}; attached the last request only (usage_partial)`]
|
|
2602
|
+
};
|
|
2603
|
+
};
|
|
2604
|
+
const skipAttached = async (payload, transcriptPath) => {
|
|
2605
|
+
const size = await fileSize(transcriptPath);
|
|
2606
|
+
return typeof size === "number" ? { payload, cursor: { source: sourceDigest(transcriptPath), offset: size } } : { payload };
|
|
2607
|
+
};
|
|
2504
2608
|
const enrich = async (input) => {
|
|
2505
2609
|
const unchanged = { payload: input.payload };
|
|
2506
2610
|
const record = asRecord5(input.payload);
|
|
@@ -2508,6 +2612,18 @@ var createClaudeTranscriptUsageEnricher = (options = {}) => {
|
|
|
2508
2612
|
return unchanged;
|
|
2509
2613
|
}
|
|
2510
2614
|
const eventName = eventNameOf(record);
|
|
2615
|
+
if (eventName === SUBAGENT_STOP) {
|
|
2616
|
+
const agentTranscriptPath = agentTranscriptPathOf(record);
|
|
2617
|
+
const agentId = agentIdOf(record);
|
|
2618
|
+
if (agentId === void 0 || !isTranscriptPath(agentTranscriptPath)) {
|
|
2619
|
+
return unchanged;
|
|
2620
|
+
}
|
|
2621
|
+
if (hasUsage(record)) {
|
|
2622
|
+
return skipAttached(input.payload, agentTranscriptPath);
|
|
2623
|
+
}
|
|
2624
|
+
const cursor2 = input.cursor?.source === sourceDigest(agentTranscriptPath) ? input.cursor : void 0;
|
|
2625
|
+
return attachSince(record, agentTranscriptPath, cursor2?.offset ?? 0, agentId);
|
|
2626
|
+
}
|
|
2511
2627
|
const transcriptPath = transcriptPathOf(record);
|
|
2512
2628
|
if (typeof eventName !== "string" || !isTranscriptPath(transcriptPath)) {
|
|
2513
2629
|
return unchanged;
|
|
@@ -2528,41 +2644,14 @@ var createClaudeTranscriptUsageEnricher = (options = {}) => {
|
|
|
2528
2644
|
return unchanged;
|
|
2529
2645
|
}
|
|
2530
2646
|
if (hasUsage(record)) {
|
|
2531
|
-
|
|
2532
|
-
return typeof size === "number" ? { payload: input.payload, cursor: { source, offset: size } } : unchanged;
|
|
2647
|
+
return skipAttached(input.payload, transcriptPath);
|
|
2533
2648
|
}
|
|
2534
|
-
|
|
2535
|
-
...record,
|
|
2536
|
-
...record.model === void 0 && model !== void 0 ? { model } : {},
|
|
2537
|
-
...usage === void 0 ? {} : { usage, usage_partial: partial }
|
|
2538
|
-
});
|
|
2539
|
-
if (cursor !== void 0) {
|
|
2540
|
-
const range = await readClaudeTranscriptRange(transcriptPath, cursor.offset, options);
|
|
2541
|
-
if (range.status === "found") {
|
|
2542
|
-
return {
|
|
2543
|
-
payload: attach(range.model, range.usage, false),
|
|
2544
|
-
cursor: { source, offset: range.endOffset },
|
|
2545
|
-
notes: [`summed ${String(range.requestCount)} request(s) since the last stop`]
|
|
2546
|
-
};
|
|
2547
|
-
}
|
|
2548
|
-
if (range.reason !== "truncated" && range.reason !== "over-cap") {
|
|
2549
|
-
return { ...unchanged, notes: [`transcript range not read (${range.reason}); cursor kept`] };
|
|
2550
|
-
}
|
|
2551
|
-
}
|
|
2552
|
-
const tail = await boundedTail(transcriptPath, options);
|
|
2553
|
-
if (tail === TIMED_OUT || !("turn" in tail)) {
|
|
2554
|
-
return { ...unchanged, notes: [`transcript tail not read (${tail === TIMED_OUT ? "timeout" : tail.reason})`] };
|
|
2555
|
-
}
|
|
2556
|
-
const why = cursor === void 0 ? "no cursor for this transcript" : "range not summable within bounds";
|
|
2557
|
-
return {
|
|
2558
|
-
payload: tail.turn.status === "found" ? attach(tail.turn.model, tail.turn.usage, true) : input.payload,
|
|
2559
|
-
cursor: { source, offset: tail.endOffset },
|
|
2560
|
-
notes: [`${why}; attached the last request only (usage_partial)`]
|
|
2561
|
-
};
|
|
2649
|
+
return attachSince(record, transcriptPath, cursor?.offset, void 0);
|
|
2562
2650
|
};
|
|
2563
2651
|
return Object.freeze({
|
|
2564
2652
|
id: CLAUDE_TRANSCRIPT_USAGE_ENRICHER_ID,
|
|
2565
2653
|
providerId: CLAUDE_CODE_PROVIDER_ID,
|
|
2654
|
+
cursorScope: subagentCursorScope,
|
|
2566
2655
|
enrich
|
|
2567
2656
|
});
|
|
2568
2657
|
};
|