observability-toolkit-hooks 0.0.0-stage → 1.0.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/CONFIG.md +144 -0
- package/README.md +201 -2
- package/dist/handlers/compact.js +38 -0
- package/dist/handlers/mcp-status.js +66 -0
- package/dist/handlers/notification.js +45 -0
- package/dist/handlers/post-tool-agent.js +157 -0
- package/dist/handlers/post-tool-changelog-sync.js +148 -0
- package/dist/handlers/post-tool-code-structure.js +116 -0
- package/dist/handlers/post-tool-edit-ledger.js +15 -0
- package/dist/handlers/post-tool-failure.js +83 -0
- package/dist/handlers/post-tool-git.js +79 -0
- package/dist/handlers/post-tool-mcp.js +105 -0
- package/dist/handlers/post-tool-outcome.js +48 -0
- package/dist/handlers/post-tool-task-state.js +74 -0
- package/dist/handlers/post-tool.js +132 -0
- package/dist/handlers/pre-tool-agent.js +192 -0
- package/dist/handlers/pre-tool.js +218 -0
- package/dist/handlers/session-end.js +39 -0
- package/dist/handlers/session-start.js +262 -0
- package/dist/handlers/stop-error-reminder.js +195 -0
- package/dist/handlers/stop-quality-evaluation.js +58 -0
- package/dist/handlers/stop-session-summary.js +62 -0
- package/dist/handlers/stop-token-metrics.js +83 -0
- package/dist/handlers/stop.js +25 -0
- package/dist/handlers/subagent.js +105 -0
- package/dist/handlers/tool-event-router.js +39 -0
- package/dist/handlers/user-prompt.js +218 -0
- package/dist/hook-runner.js +10 -0
- package/dist/hook-runner.js.map +7 -0
- package/dist/lib/agent/agent-context.js +123 -0
- package/dist/lib/agent/agent-evaluations.js +155 -0
- package/dist/lib/agent/agent-file-budget.js +65 -0
- package/dist/lib/agent/agent-sources.js +165 -0
- package/dist/lib/agent/synth-spans.js +51 -0
- package/dist/lib/core/bounded-label.js +6 -0
- package/dist/lib/core/category-rules.js +11 -0
- package/dist/lib/core/child-result.js +19 -0
- package/dist/lib/core/config-dir-recovery.js +22 -0
- package/dist/lib/core/constants.js +171 -0
- package/dist/lib/core/detached-runner.js +55 -0
- package/dist/lib/core/file-utils.js +353 -0
- package/dist/lib/core/format-utils.js +51 -0
- package/dist/lib/core/http-utils.js +74 -0
- package/dist/lib/core/http1-fetch.js +14 -0
- package/dist/lib/core/identity-key-resolver.js +149 -0
- package/dist/lib/core/jsonl-tail.js +207 -0
- package/dist/lib/core/load-envrc.js +72 -0
- package/dist/lib/core/parsers.js +43 -0
- package/dist/lib/core/regex.js +27 -0
- package/dist/lib/core/settings-env.js +31 -0
- package/dist/lib/core/shell-command.js +122 -0
- package/dist/lib/core/units.js +97 -0
- package/dist/lib/git/git-cache.js +158 -0
- package/dist/lib/git/git-commit.js +189 -0
- package/dist/lib/git/git-exec.js +30 -0
- package/dist/lib/mcp/mcp-completeness.js +40 -0
- package/dist/lib/mcp/mcp-config.js +118 -0
- package/dist/lib/mcp/mcp-failure-latch.js +22 -0
- package/dist/lib/mcp/mcp-identity-launcher.js +43 -0
- package/dist/lib/otel/attributes.js +322 -0
- package/dist/lib/otel/evaluation-attrs.js +51 -0
- package/dist/lib/otel/file-exporters.js +169 -0
- package/dist/lib/otel/host-resource.js +61 -0
- package/dist/lib/otel/otel-headers-helper.js +26 -0
- package/dist/lib/otel/otel-monitor.js +181 -0
- package/dist/lib/otel/otel.js +235 -0
- package/dist/lib/otel/otlp-headers.js +101 -0
- package/dist/lib/otel/otlp-post.js +122 -0
- package/dist/lib/otel/otlp-serialize.js +142 -0
- package/dist/lib/otel/otlp-signal.js +2 -0
- package/dist/lib/otel/remote-spans.js +142 -0
- package/dist/lib/otel/service-identity.js +10 -0
- package/dist/lib/otel/telemetry-alerts.js +43 -0
- package/dist/lib/otel/token-metrics.js +122 -0
- package/dist/lib/otel/trace-context.js +81 -0
- package/dist/lib/quality/judge-meta-eval.js +70 -0
- package/dist/lib/quality/judge-prompts.js +104 -0
- package/dist/lib/quality/judge-providers.js +193 -0
- package/dist/lib/quality/judge-transport.js +93 -0
- package/dist/lib/quality/llm-judge.js +170 -0
- package/dist/lib/quality/quality-budget.js +99 -0
- package/dist/lib/quality/quality-degradation.js +156 -0
- package/dist/lib/quality/quality-eval-handoff.js +74 -0
- package/dist/lib/quality/quality-evaluator.js +178 -0
- package/dist/lib/quality/quality-sampler.js +43 -0
- package/dist/lib/quality/quality-signals.js +150 -0
- package/dist/lib/runtime/categorizers.js +101 -0
- package/dist/lib/runtime/hook-input.js +16 -0
- package/dist/lib/runtime/hook-output.js +50 -0
- package/dist/lib/runtime/output-analyzer.js +160 -0
- package/dist/lib/runtime/run-handlers.js +32 -0
- package/dist/lib/runtime/tool-input.js +111 -0
- package/dist/lib/runtime/tool-output.js +44 -0
- package/dist/lib/runtime/unknown-tool.js +32 -0
- package/dist/lib/session/edit-ledger.js +29 -0
- package/dist/lib/session/forked-skill.js +39 -0
- package/dist/lib/session/handoffs.js +77 -0
- package/dist/lib/session/session-state.js +169 -0
- package/dist/lib/session/skill-rules.js +196 -0
- package/dist/lib/session/task-tracker.js +83 -0
- package/dist/lib/shipper/shipper-credentials.js +38 -0
- package/dist/lib/shipper/shipper-cursor.js +89 -0
- package/dist/lib/shipper/shipper-status.js +174 -0
- package/dist/lib/shipper/span-shipper.js +272 -0
- package/dist/lib/shipper/telemetry-shipper.js +39 -0
- package/dist/lib/transcript/agent-transcript-metrics.js +34 -0
- package/dist/lib/transcript/context-breakdown.js +134 -0
- package/dist/lib/transcript/context-history.js +69 -0
- package/dist/lib/transcript/context-tracker.js +226 -0
- package/dist/lib/transcript/message-count.js +49 -0
- package/dist/lib/transcript/model-ids.js +36 -0
- package/dist/lib/transcript/model-pricing.js +153 -0
- package/dist/lib/transcript/token-metrics-checkpoint.js +152 -0
- package/dist/lib/transcript/tool-call-durations.js +64 -0
- package/dist/lib/transcript/transcript-entry.js +67 -0
- package/dist/lib/transcript/transcript-fold.js +130 -0
- package/dist/lib/transcript/transcript-layout.js +39 -0
- package/dist/lib/transcript/transcript-parser.js +117 -0
- package/dist/runner/agent-context-4XTCLMLZ.js +23 -0
- package/dist/runner/agent-context-4XTCLMLZ.js.map +7 -0
- package/dist/runner/agent-file-budget-Q33ESBBE.js +68 -0
- package/dist/runner/agent-file-budget-Q33ESBBE.js.map +7 -0
- package/dist/runner/agent-transcript-metrics-W5CZZFMI.js +39 -0
- package/dist/runner/agent-transcript-metrics-W5CZZFMI.js.map +7 -0
- package/dist/runner/chunk-2NTNAJZE.js +49 -0
- package/dist/runner/chunk-2NTNAJZE.js.map +7 -0
- package/dist/runner/chunk-4KWBQTTG.js +78 -0
- package/dist/runner/chunk-4KWBQTTG.js.map +7 -0
- package/dist/runner/chunk-52RY6LQT.js +699 -0
- package/dist/runner/chunk-52RY6LQT.js.map +7 -0
- package/dist/runner/chunk-7OM5CYES.js +8695 -0
- package/dist/runner/chunk-7OM5CYES.js.map +7 -0
- package/dist/runner/chunk-7PEOKGYR.js +1568 -0
- package/dist/runner/chunk-7PEOKGYR.js.map +7 -0
- package/dist/runner/chunk-AGSGKELQ.js +126 -0
- package/dist/runner/chunk-AGSGKELQ.js.map +7 -0
- package/dist/runner/chunk-AVM7PJFW.js +12 -0
- package/dist/runner/chunk-AVM7PJFW.js.map +7 -0
- package/dist/runner/chunk-C3WHUMU5.js +178 -0
- package/dist/runner/chunk-C3WHUMU5.js.map +7 -0
- package/dist/runner/chunk-DGB4NSSD.js +157 -0
- package/dist/runner/chunk-DGB4NSSD.js.map +7 -0
- package/dist/runner/chunk-DNSTWC26.js +151 -0
- package/dist/runner/chunk-DNSTWC26.js.map +7 -0
- package/dist/runner/chunk-FDJJ3TYU.js +449 -0
- package/dist/runner/chunk-FDJJ3TYU.js.map +7 -0
- package/dist/runner/chunk-FGKYDQHZ.js +137 -0
- package/dist/runner/chunk-FGKYDQHZ.js.map +7 -0
- package/dist/runner/chunk-GG2I4TGI.js +582 -0
- package/dist/runner/chunk-GG2I4TGI.js.map +7 -0
- package/dist/runner/chunk-GNNKUMRF.js +60 -0
- package/dist/runner/chunk-GNNKUMRF.js.map +7 -0
- package/dist/runner/chunk-I7TD2QVR.js +118 -0
- package/dist/runner/chunk-I7TD2QVR.js.map +7 -0
- package/dist/runner/chunk-IJ4SLUBV.js +78 -0
- package/dist/runner/chunk-IJ4SLUBV.js.map +7 -0
- package/dist/runner/chunk-IY7AP7NA.js +32 -0
- package/dist/runner/chunk-IY7AP7NA.js.map +7 -0
- package/dist/runner/chunk-J3F3Z3EQ.js +177 -0
- package/dist/runner/chunk-J3F3Z3EQ.js.map +7 -0
- package/dist/runner/chunk-JLEO5OHU.js +104 -0
- package/dist/runner/chunk-JLEO5OHU.js.map +7 -0
- package/dist/runner/chunk-JRNNLOPR.js +168 -0
- package/dist/runner/chunk-JRNNLOPR.js.map +7 -0
- package/dist/runner/chunk-KGSA5JYP.js +82 -0
- package/dist/runner/chunk-KGSA5JYP.js.map +7 -0
- package/dist/runner/chunk-LBCZAYFR.js +125 -0
- package/dist/runner/chunk-LBCZAYFR.js.map +7 -0
- package/dist/runner/chunk-LHWRXY2G.js +41 -0
- package/dist/runner/chunk-LHWRXY2G.js.map +7 -0
- package/dist/runner/chunk-LQ2LGUYJ.js +41 -0
- package/dist/runner/chunk-LQ2LGUYJ.js.map +7 -0
- package/dist/runner/chunk-LYY6RCIE.js +158 -0
- package/dist/runner/chunk-LYY6RCIE.js.map +7 -0
- package/dist/runner/chunk-M4R4QIQH.js +41 -0
- package/dist/runner/chunk-M4R4QIQH.js.map +7 -0
- package/dist/runner/chunk-MC75VXMX.js +207 -0
- package/dist/runner/chunk-MC75VXMX.js.map +7 -0
- package/dist/runner/chunk-NKZU4RRG.js +104 -0
- package/dist/runner/chunk-NKZU4RRG.js.map +7 -0
- package/dist/runner/chunk-PJHWHJ3K.js +56 -0
- package/dist/runner/chunk-PJHWHJ3K.js.map +7 -0
- package/dist/runner/chunk-RIGVYJ2O.js +114 -0
- package/dist/runner/chunk-RIGVYJ2O.js.map +7 -0
- package/dist/runner/chunk-RWRGC7ZK.js +93 -0
- package/dist/runner/chunk-RWRGC7ZK.js.map +7 -0
- package/dist/runner/chunk-SRMAJQMV.js +54 -0
- package/dist/runner/chunk-SRMAJQMV.js.map +7 -0
- package/dist/runner/chunk-TRMFD36J.js +47 -0
- package/dist/runner/chunk-TRMFD36J.js.map +7 -0
- package/dist/runner/chunk-U4IOZYQ3.js +21 -0
- package/dist/runner/chunk-U4IOZYQ3.js.map +7 -0
- package/dist/runner/chunk-UEXDE3WP.js +83 -0
- package/dist/runner/chunk-UEXDE3WP.js.map +7 -0
- package/dist/runner/chunk-UW3GQZSM.js +50 -0
- package/dist/runner/chunk-UW3GQZSM.js.map +7 -0
- package/dist/runner/chunk-V2GSP6VR.js +46 -0
- package/dist/runner/chunk-V2GSP6VR.js.map +7 -0
- package/dist/runner/chunk-VOV4Y5VU.js +81 -0
- package/dist/runner/chunk-VOV4Y5VU.js.map +7 -0
- package/dist/runner/chunk-VT5T6OEI.js +65 -0
- package/dist/runner/chunk-VT5T6OEI.js.map +7 -0
- package/dist/runner/chunk-VUYVFWIN.js +12 -0
- package/dist/runner/chunk-VUYVFWIN.js.map +7 -0
- package/dist/runner/chunk-VVGOPPEN.js +36 -0
- package/dist/runner/chunk-VVGOPPEN.js.map +7 -0
- package/dist/runner/chunk-VXFSLM6P.js +14 -0
- package/dist/runner/chunk-VXFSLM6P.js.map +7 -0
- package/dist/runner/chunk-W3EK7JUT.js +26125 -0
- package/dist/runner/chunk-W3EK7JUT.js.map +7 -0
- package/dist/runner/chunk-WJHNCOUF.js +52 -0
- package/dist/runner/chunk-WJHNCOUF.js.map +7 -0
- package/dist/runner/chunk-WU7ANGCW.js +269 -0
- package/dist/runner/chunk-WU7ANGCW.js.map +7 -0
- package/dist/runner/chunk-X7XLMSZX.js +44 -0
- package/dist/runner/chunk-X7XLMSZX.js.map +7 -0
- package/dist/runner/chunk-XSO3B4QN.js +124 -0
- package/dist/runner/chunk-XSO3B4QN.js.map +7 -0
- package/dist/runner/chunk-YGFN3LN2.js +174 -0
- package/dist/runner/chunk-YGFN3LN2.js.map +7 -0
- package/dist/runner/chunk-YHYDBLVB.js +33 -0
- package/dist/runner/chunk-YHYDBLVB.js.map +7 -0
- package/dist/runner/compact-36NP3PKT.js +60 -0
- package/dist/runner/compact-36NP3PKT.js.map +7 -0
- package/dist/runner/getMachineId-bsd-AGENNHN6.js +42 -0
- package/dist/runner/getMachineId-bsd-AGENNHN6.js.map +7 -0
- package/dist/runner/getMachineId-bsd-I5WZGCL4.js +33 -0
- package/dist/runner/getMachineId-bsd-I5WZGCL4.js.map +7 -0
- package/dist/runner/getMachineId-bsd-ZXK225P7.js +33 -0
- package/dist/runner/getMachineId-bsd-ZXK225P7.js.map +7 -0
- package/dist/runner/getMachineId-darwin-47GDLEXL.js +42 -0
- package/dist/runner/getMachineId-darwin-47GDLEXL.js.map +7 -0
- package/dist/runner/getMachineId-darwin-5CRLMDD6.js +33 -0
- package/dist/runner/getMachineId-darwin-5CRLMDD6.js.map +7 -0
- package/dist/runner/getMachineId-darwin-ADG4I32N.js +33 -0
- package/dist/runner/getMachineId-darwin-ADG4I32N.js.map +7 -0
- package/dist/runner/getMachineId-linux-5KVS3T2M.js +27 -0
- package/dist/runner/getMachineId-linux-5KVS3T2M.js.map +7 -0
- package/dist/runner/getMachineId-linux-GDFB5GSO.js +34 -0
- package/dist/runner/getMachineId-linux-GDFB5GSO.js.map +7 -0
- package/dist/runner/getMachineId-linux-NQMWCRO3.js +27 -0
- package/dist/runner/getMachineId-linux-NQMWCRO3.js.map +7 -0
- package/dist/runner/getMachineId-unsupported-5PFIGMVX.js +18 -0
- package/dist/runner/getMachineId-unsupported-5PFIGMVX.js.map +7 -0
- package/dist/runner/getMachineId-unsupported-DW27K3ZX.js +18 -0
- package/dist/runner/getMachineId-unsupported-DW27K3ZX.js.map +7 -0
- package/dist/runner/getMachineId-unsupported-XV3FHTHD.js +25 -0
- package/dist/runner/getMachineId-unsupported-XV3FHTHD.js.map +7 -0
- package/dist/runner/getMachineId-win-5JVMW3EI.js +44 -0
- package/dist/runner/getMachineId-win-5JVMW3EI.js.map +7 -0
- package/dist/runner/getMachineId-win-SNESQF7R.js +35 -0
- package/dist/runner/getMachineId-win-SNESQF7R.js.map +7 -0
- package/dist/runner/getMachineId-win-UJYHSBM2.js +35 -0
- package/dist/runner/getMachineId-win-UJYHSBM2.js.map +7 -0
- package/dist/runner/git-commit-BA53DOJQ.js +30 -0
- package/dist/runner/git-commit-BA53DOJQ.js.map +7 -0
- package/dist/runner/hook-runner-JHH6PGKE.js +220 -0
- package/dist/runner/hook-runner-JHH6PGKE.js.map +7 -0
- package/dist/runner/judge-transport-R4TF5LEH.js +91 -0
- package/dist/runner/judge-transport-R4TF5LEH.js.map +7 -0
- package/dist/runner/mcp-status-QEUH2KGX.js +89 -0
- package/dist/runner/mcp-status-QEUH2KGX.js.map +7 -0
- package/dist/runner/notification-FKMBCSXF.js +69 -0
- package/dist/runner/notification-FKMBCSXF.js.map +7 -0
- package/dist/runner/post-tool-3MRHTBKH.js +192 -0
- package/dist/runner/post-tool-3MRHTBKH.js.map +7 -0
- package/dist/runner/post-tool-agent-BB34MNHI.js +370 -0
- package/dist/runner/post-tool-agent-BB34MNHI.js.map +7 -0
- package/dist/runner/post-tool-changelog-sync-OP2TT2I7.js +147 -0
- package/dist/runner/post-tool-changelog-sync-OP2TT2I7.js.map +7 -0
- package/dist/runner/post-tool-code-structure-LE7J2SC2.js +130 -0
- package/dist/runner/post-tool-code-structure-LE7J2SC2.js.map +7 -0
- package/dist/runner/post-tool-edit-ledger-IJMEYHKF.js +30 -0
- package/dist/runner/post-tool-edit-ledger-IJMEYHKF.js.map +7 -0
- package/dist/runner/post-tool-failure-XTH2I2Z7.js +111 -0
- package/dist/runner/post-tool-failure-XTH2I2Z7.js.map +7 -0
- package/dist/runner/post-tool-git-E46HZGZO.js +94 -0
- package/dist/runner/post-tool-git-E46HZGZO.js.map +7 -0
- package/dist/runner/post-tool-mcp-AMCDY5GH.js +144 -0
- package/dist/runner/post-tool-mcp-AMCDY5GH.js.map +7 -0
- package/dist/runner/post-tool-task-state-TLDOI33H.js +100 -0
- package/dist/runner/post-tool-task-state-TLDOI33H.js.map +7 -0
- package/dist/runner/pre-tool-SQE2FZQO.js +245 -0
- package/dist/runner/pre-tool-SQE2FZQO.js.map +7 -0
- package/dist/runner/pre-tool-agent-OZUPVFUI.js +218 -0
- package/dist/runner/pre-tool-agent-OZUPVFUI.js.map +7 -0
- package/dist/runner/quality-evaluator-XYNDKDRG.js +901 -0
- package/dist/runner/quality-evaluator-XYNDKDRG.js.map +7 -0
- package/dist/runner/session-end-3MJTDLLA.js +57 -0
- package/dist/runner/session-end-3MJTDLLA.js.map +7 -0
- package/dist/runner/session-start-5ZMCLKBS.js +352 -0
- package/dist/runner/session-start-5ZMCLKBS.js.map +7 -0
- package/dist/runner/shipper-status-MADX6SPG.js +37 -0
- package/dist/runner/shipper-status-MADX6SPG.js.map +7 -0
- package/dist/runner/span-shipper-4HQDHC47.js +3408 -0
- package/dist/runner/span-shipper-4HQDHC47.js.map +7 -0
- package/dist/runner/stop-RTKSIYJV.js +596 -0
- package/dist/runner/stop-RTKSIYJV.js.map +7 -0
- package/dist/runner/subagent-CBCG4OLZ.js +116 -0
- package/dist/runner/subagent-CBCG4OLZ.js.map +7 -0
- package/dist/runner/token-metrics-AD2RAFGM.js +31 -0
- package/dist/runner/token-metrics-AD2RAFGM.js.map +7 -0
- package/dist/runner/user-prompt-T5NZ2UJD.js +376 -0
- package/dist/runner/user-prompt-T5NZ2UJD.js.map +7 -0
- package/package.json +68 -5
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../lib/agent/agent-file-budget.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Per-invocation file-write budget for scoped agents (AA1g), disk-based to survive\n * spawn-per-event. Callers MUST reset at invocation start (trap 2); any I/O error\n * fails open, never a false denial (trap 1).\n */\n\nimport { join } from 'node:path';\nimport { loadJson, writeJsonAtomic, withFileLock } from '../core/file-utils.js';\nimport { sessionStateDir } from '../session/session-state.js';\n\n/** Maximum distinct files auto-error-resolver may write per invocation. */\nexport const AUTO_ERROR_RESOLVER_FILE_BUDGET = 3;\n\nconst BUDGET_FILE = 'agent-file-budget.json';\nconst LOCK_FILE = 'agent-file-budget.lock';\n\ninterface BudgetEntry {\n /** Distinct file paths written this invocation, in insertion order. */\n filePaths: string[];\n}\n\ntype BudgetStore = Record<string, BudgetEntry>;\n\ntype BudgetCheck = { allowed: boolean; count: number };\n\nfunction budgetFilePath(sessionId: string): string {\n return join(sessionStateDir(sessionId), BUDGET_FILE);\n}\n\nfunction lockFilePath(sessionId: string): string {\n return join(sessionStateDir(sessionId), LOCK_FILE);\n}\n\n/** Locked load\u2013mutate\u2013save; an unchanged store is not written back. Throws, callers own the fail-open. */\nfunction mutateBudgetStore<T>(\n sessionId: string,\n fn: (store: BudgetStore) => { result: T; changed: boolean },\n): T {\n return withFileLock(lockFilePath(sessionId), () => {\n const storePath = budgetFilePath(sessionId);\n const store = loadJson<BudgetStore>(storePath) ?? {};\n const { result, changed } = fn(store);\n if (changed) writeJsonAtomic(storePath, store, { silent: true });\n return result;\n });\n}\n\n/** Reset at spawn so a previous invocation's count cannot carry over; a failed reset is caught by fail-open on the check side. */\nexport function resetAgentFileBudget(sessionId: string, agentType: string): void {\n if (!sessionId || !agentType) return;\n try {\n mutateBudgetStore(sessionId, (store) => {\n delete store[agentType];\n return { result: undefined, changed: true };\n });\n } catch {\n // best-effort\n }\n}\n\n/** Record a write attempt; re-editing a tracked path is free. Fails open on I/O error (AA1g trap 1). */\nexport function checkAndRecordFilePath(\n sessionId: string,\n agentType: string,\n filePath: string,\n budget: number,\n): BudgetCheck {\n if (!sessionId || !agentType || !filePath) return { allowed: true, count: 0 };\n\n try {\n return mutateBudgetStore<BudgetCheck>(sessionId, (store) => {\n const entry: BudgetEntry = store[agentType] ?? { filePaths: [] };\n\n if (entry.filePaths.includes(filePath)) {\n return { result: { allowed: true, count: entry.filePaths.length }, changed: false };\n }\n\n if (entry.filePaths.length >= budget) {\n return { result: { allowed: false, count: entry.filePaths.length }, changed: false };\n }\n\n entry.filePaths = [...entry.filePaths, filePath];\n store[agentType] = entry;\n return { result: { allowed: true, count: entry.filePaths.length }, changed: true };\n });\n } catch {\n return { allowed: true, count: 0 };\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAMA,SAAS,YAAY;AAKd,IAAM,kCAAkC;AAE/C,IAAM,cAAc;AACpB,IAAM,YAAY;AAWlB,SAAS,eAAe,WAA2B;AACjD,SAAO,KAAK,gBAAgB,SAAS,GAAG,WAAW;AACrD;AAEA,SAAS,aAAa,WAA2B;AAC/C,SAAO,KAAK,gBAAgB,SAAS,GAAG,SAAS;AACnD;AAGA,SAAS,kBACP,WACA,IACG;AACH,SAAO,aAAa,aAAa,SAAS,GAAG,MAAM;AACjD,UAAM,YAAY,eAAe,SAAS;AAC1C,UAAM,QAAQ,SAAsB,SAAS,KAAK,CAAC;AACnD,UAAM,EAAE,QAAQ,QAAQ,IAAI,GAAG,KAAK;AACpC,QAAI,QAAS,iBAAgB,WAAW,OAAO,EAAE,QAAQ,KAAK,CAAC;AAC/D,WAAO;AAAA,EACT,CAAC;AACH;AAGO,SAAS,qBAAqB,WAAmB,WAAyB;AAC/E,MAAI,CAAC,aAAa,CAAC,UAAW;AAC9B,MAAI;AACF,sBAAkB,WAAW,CAAC,UAAU;AACtC,aAAO,MAAM,SAAS;AACtB,aAAO,EAAE,QAAQ,QAAW,SAAS,KAAK;AAAA,IAC5C,CAAC;AAAA,EACH,QAAQ;AAAA,EAER;AACF;AAGO,SAAS,uBACd,WACA,WACA,UACA,QACa;AACb,MAAI,CAAC,aAAa,CAAC,aAAa,CAAC,SAAU,QAAO,EAAE,SAAS,MAAM,OAAO,EAAE;AAE5E,MAAI;AACF,WAAO,kBAA+B,WAAW,CAAC,UAAU;AAC1D,YAAM,QAAqB,MAAM,SAAS,KAAK,EAAE,WAAW,CAAC,EAAE;AAE/D,UAAI,MAAM,UAAU,SAAS,QAAQ,GAAG;AACtC,eAAO,EAAE,QAAQ,EAAE,SAAS,MAAM,OAAO,MAAM,UAAU,OAAO,GAAG,SAAS,MAAM;AAAA,MACpF;AAEA,UAAI,MAAM,UAAU,UAAU,QAAQ;AACpC,eAAO,EAAE,QAAQ,EAAE,SAAS,OAAO,OAAO,MAAM,UAAU,OAAO,GAAG,SAAS,MAAM;AAAA,MACrF;AAEA,YAAM,YAAY,CAAC,GAAG,MAAM,WAAW,QAAQ;AAC/C,YAAM,SAAS,IAAI;AACnB,aAAO,EAAE,QAAQ,EAAE,SAAS,MAAM,OAAO,MAAM,UAAU,OAAO,GAAG,SAAS,KAAK;AAAA,IACnF,CAAC;AAAA,EACH,QAAQ;AACN,WAAO,EAAE,SAAS,MAAM,OAAO,EAAE;AAAA,EACnC;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createRequire as __hookRunnerCreateRequire } from 'node:module';
|
|
2
|
+
const require = __hookRunnerCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
INITIAL_MODEL,
|
|
5
|
+
emptyAccumulator,
|
|
6
|
+
foldTranscriptFrom
|
|
7
|
+
} from "./chunk-AGSGKELQ.js";
|
|
8
|
+
import "./chunk-VT5T6OEI.js";
|
|
9
|
+
import "./chunk-4KWBQTTG.js";
|
|
10
|
+
import "./chunk-YHYDBLVB.js";
|
|
11
|
+
import {
|
|
12
|
+
THRESHOLDS
|
|
13
|
+
} from "./chunk-52RY6LQT.js";
|
|
14
|
+
import "./chunk-RWRGC7ZK.js";
|
|
15
|
+
import "./chunk-GNNKUMRF.js";
|
|
16
|
+
|
|
17
|
+
// lib/transcript/agent-transcript-metrics.ts
|
|
18
|
+
import { statSync } from "node:fs";
|
|
19
|
+
function readAgentTranscriptMeasures(path) {
|
|
20
|
+
const acc = emptyAccumulator();
|
|
21
|
+
try {
|
|
22
|
+
if (statSync(path).size > THRESHOLDS.AGENT_TRANSCRIPT_MAX_READ_BYTES) return null;
|
|
23
|
+
foldTranscriptFrom(path, 0, acc);
|
|
24
|
+
} catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const { stats, modelTotals, toolCalls, toolDurations } = acc;
|
|
28
|
+
return {
|
|
29
|
+
inferenceCalls: stats.messageCount,
|
|
30
|
+
toolCalls,
|
|
31
|
+
model: stats.model === INITIAL_MODEL ? void 0 : stats.model,
|
|
32
|
+
tokenUsageByModel: Object.fromEntries([...modelTotals]),
|
|
33
|
+
toolDurations
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
readAgentTranscriptMeasures
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=agent-transcript-metrics-W5CZZFMI.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../lib/transcript/agent-transcript-metrics.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Per-invocation agent measures from a subagent's transcript. From the\n * transcript, not the hook stream: no hook event marks an API response, and the\n * PostToolUse success payload carries no duration, so measuring it there would\n * put a store touch on every tool call.\n *\n * Same fold as the Stop checkpoint (transcript-fold.ts), driven from offset 0 with no\n * persisted state, so a response, its model and its usage are counted by one rule on both\n * paths: `inferenceCalls` counts distinct `message.id`s among lines carrying usage, not\n * assistant lines (one response spans several JSONL entries).\n */\n\nimport { statSync } from 'node:fs';\nimport { THRESHOLDS } from '../core/constants.js';\nimport type { ToolDuration } from './tool-call-durations.js';\nimport { emptyAccumulator, foldTranscriptFrom, INITIAL_MODEL, type ModelTotals } from './transcript-fold.js';\n\ninterface AgentTranscriptMeasures {\n /** Distinct `message.id`s among lines carrying usage. */\n inferenceCalls: number;\n /** Every `tool_use` block, hooked or not. */\n toolCalls: number;\n model?: string;\n /** Keyed by model, since an agent can run on more than one. */\n tokenUsageByModel: Record<string, ModelTotals>;\n /** Unpaired calls contribute nothing. */\n toolDurations: ToolDuration[];\n}\n\n/** Null when missing, unreadable or over the read budget: a zero would read as an agent that made no calls. */\nexport function readAgentTranscriptMeasures(path: string): AgentTranscriptMeasures | null {\n const acc = emptyAccumulator();\n try {\n if (statSync(path).size > THRESHOLDS.AGENT_TRANSCRIPT_MAX_READ_BYTES) return null;\n foldTranscriptFrom(path, 0, acc);\n } catch {\n return null;\n }\n\n const { stats, modelTotals, toolCalls, toolDurations } = acc;\n return {\n inferenceCalls: stats.messageCount,\n toolCalls,\n model: stats.model === INITIAL_MODEL ? undefined : stats.model,\n tokenUsageByModel: Object.fromEntries([...modelTotals]),\n toolDurations,\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAYA,SAAS,gBAAgB;AAkBlB,SAAS,4BAA4B,MAA8C;AACxF,QAAM,MAAM,iBAAiB;AAC7B,MAAI;AACF,QAAI,SAAS,IAAI,EAAE,OAAO,WAAW,gCAAiC,QAAO;AAC7E,uBAAmB,MAAM,GAAG,GAAG;AAAA,EACjC,QAAQ;AACN,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,OAAO,aAAa,WAAW,cAAc,IAAI;AACzD,SAAO;AAAA,IACL,gBAAgB,MAAM;AAAA,IACtB;AAAA,IACA,OAAO,MAAM,UAAU,gBAAgB,SAAY,MAAM;AAAA,IACzD,mBAAmB,OAAO,YAAY,CAAC,GAAG,WAAW,CAAC;AAAA,IACtD;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createRequire as __hookRunnerCreateRequire } from 'node:module';
|
|
2
|
+
const require = __hookRunnerCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
getHookTrigger
|
|
5
|
+
} from "./chunk-WU7ANGCW.js";
|
|
6
|
+
import {
|
|
7
|
+
HOOK_EXIT,
|
|
8
|
+
writeStderr
|
|
9
|
+
} from "./chunk-52RY6LQT.js";
|
|
10
|
+
|
|
11
|
+
// lib/runtime/hook-output.ts
|
|
12
|
+
var sections = [];
|
|
13
|
+
var stdoutWriter = (chunk) => {
|
|
14
|
+
process.stdout.write(chunk);
|
|
15
|
+
};
|
|
16
|
+
var writer = stdoutWriter;
|
|
17
|
+
function writePlainContext(text) {
|
|
18
|
+
writer(`${text}
|
|
19
|
+
`);
|
|
20
|
+
}
|
|
21
|
+
function addAdditionalContext(text) {
|
|
22
|
+
const trimmed = text.trim();
|
|
23
|
+
if (trimmed) sections.push(trimmed);
|
|
24
|
+
}
|
|
25
|
+
function flushAdditionalContext() {
|
|
26
|
+
if (sections.length === 0) return;
|
|
27
|
+
const additionalContext = peekAdditionalContext();
|
|
28
|
+
sections.length = 0;
|
|
29
|
+
writer(`${JSON.stringify({
|
|
30
|
+
hookSpecificOutput: { hookEventName: getHookTrigger(), additionalContext }
|
|
31
|
+
})}
|
|
32
|
+
`);
|
|
33
|
+
}
|
|
34
|
+
function peekAdditionalContext() {
|
|
35
|
+
return sections.join("\n\n");
|
|
36
|
+
}
|
|
37
|
+
function denyToolUse(reason) {
|
|
38
|
+
flushAdditionalContext();
|
|
39
|
+
writeStderr(reason);
|
|
40
|
+
process.exit(HOOK_EXIT.BLOCKING);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
writePlainContext,
|
|
45
|
+
addAdditionalContext,
|
|
46
|
+
flushAdditionalContext,
|
|
47
|
+
denyToolUse
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=chunk-2NTNAJZE.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../lib/runtime/hook-output.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Model-facing stdout. Plain stdout reaches the model only on UserPromptSubmit,\n * UserPromptExpansion and SessionStart; every other event needs the JSON\n * `hookSpecificOutput.additionalContext` payload. Handlers queue sections and the\n * runner flushes once per process, because one process can host several handlers\n * and two JSON objects on stdout do not parse. An empty queue emits nothing, so a\n * plain-stdout event never gains a stray JSON line.\n */\n\nimport { HOOK_EXIT } from '../core/constants.js';\nimport { writeStderr } from '../core/format-utils.js';\nimport { getHookTrigger } from '../otel/otel-monitor.js';\n\nconst sections: string[] = [];\n\n/** Indirected so tests never patch process.stdout, which the test reporter shares. */\ntype PayloadWriter = (chunk: string) => void;\n\nconst stdoutWriter: PayloadWriter = (chunk) => { process.stdout.write(chunk); };\n\nlet writer: PayloadWriter = stdoutWriter;\n\n/** Test seam. */\nexport function setHookOutputWriter(next?: PayloadWriter): void {\n writer = next ?? stdoutWriter;\n}\n\n/** Reaches the model only on SessionStart, UserPromptSubmit and UserPromptExpansion; elsewhere use `addAdditionalContext`. */\nexport function writePlainContext(text: string): void {\n writer(`${text}\\n`);\n}\n\nexport function addAdditionalContext(text: string): void {\n const trimmed = text.trim();\n if (trimmed) sections.push(trimmed);\n}\n\n/** Draining makes a second call a no-op: `denyToolUse` flushes before exit 2 and the runner flushes at the end. */\nexport function flushAdditionalContext(): void {\n if (sections.length === 0) return;\n\n const additionalContext = peekAdditionalContext();\n sections.length = 0;\n\n writer(`${JSON.stringify({\n hookSpecificOutput: { hookEventName: getHookTrigger(), additionalContext },\n })}\\n`);\n}\n\n/** Test seam. */\nexport function resetAdditionalContext(): void {\n sections.length = 0;\n}\n\nexport function peekAdditionalContext(): string {\n return sections.join('\\n\\n');\n}\n\n/** Only exit 2 blocks, with stderr as the reason; exit 1 fails open silently (CCH5). */\nexport function denyToolUse(reason: string): never {\n flushAdditionalContext();\n writeStderr(reason);\n process.exit(HOOK_EXIT.BLOCKING);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAaA,IAAM,WAAqB,CAAC;AAK5B,IAAM,eAA8B,CAAC,UAAU;AAAE,UAAQ,OAAO,MAAM,KAAK;AAAG;AAE9E,IAAI,SAAwB;AAQrB,SAAS,kBAAkB,MAAoB;AACpD,SAAO,GAAG,IAAI;AAAA,CAAI;AACpB;AAEO,SAAS,qBAAqB,MAAoB;AACvD,QAAM,UAAU,KAAK,KAAK;AAC1B,MAAI,QAAS,UAAS,KAAK,OAAO;AACpC;AAGO,SAAS,yBAA+B;AAC7C,MAAI,SAAS,WAAW,EAAG;AAE3B,QAAM,oBAAoB,sBAAsB;AAChD,WAAS,SAAS;AAElB,SAAO,GAAG,KAAK,UAAU;AAAA,IACvB,oBAAoB,EAAE,eAAe,eAAe,GAAG,kBAAkB;AAAA,EAC3E,CAAC,CAAC;AAAA,CAAI;AACR;AAOO,SAAS,wBAAgC;AAC9C,SAAO,SAAS,KAAK,MAAM;AAC7B;AAGO,SAAS,YAAY,QAAuB;AACjD,yBAAuB;AACvB,cAAY,MAAM;AAClB,UAAQ,KAAK,UAAU,QAAQ;AACjC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { createRequire as __hookRunnerCreateRequire } from 'node:module';
|
|
2
|
+
const require = __hookRunnerCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
alternation
|
|
5
|
+
} from "./chunk-YHYDBLVB.js";
|
|
6
|
+
import {
|
|
7
|
+
SYNTHETIC_MODEL,
|
|
8
|
+
isJsonObject
|
|
9
|
+
} from "./chunk-52RY6LQT.js";
|
|
10
|
+
|
|
11
|
+
// lib/transcript/transcript-entry.ts
|
|
12
|
+
var SYSTEM_RECORD_TYPE = "system";
|
|
13
|
+
var TURN_DURATION_SUBTYPE = "turn_duration";
|
|
14
|
+
var USER_RECORD_TYPE = "user";
|
|
15
|
+
var ASSISTANT_RECORD_TYPE = "assistant";
|
|
16
|
+
var CONVERSATION_RECORD_TYPES = /* @__PURE__ */ new Set([USER_RECORD_TYPE, ASSISTANT_RECORD_TYPE]);
|
|
17
|
+
function fieldMarkers(field, value) {
|
|
18
|
+
return [`"${field}":"${value}"`, `"${field}": "${value}"`];
|
|
19
|
+
}
|
|
20
|
+
var CONVERSATION_TYPE_TOKEN = new RegExp(`"${alternation([...CONVERSATION_RECORD_TYPES])}"`);
|
|
21
|
+
function mayBeConversational(line) {
|
|
22
|
+
return CONVERSATION_TYPE_TOKEN.test(line);
|
|
23
|
+
}
|
|
24
|
+
function toBlocks(content) {
|
|
25
|
+
if (!Array.isArray(content)) return [];
|
|
26
|
+
return content.filter((block) => isJsonObject(block));
|
|
27
|
+
}
|
|
28
|
+
function classifyEntry(entry) {
|
|
29
|
+
if (entry.type === USER_RECORD_TYPE) return "prompt";
|
|
30
|
+
if (entry.type !== ASSISTANT_RECORD_TYPE) return "other";
|
|
31
|
+
return entry.message?.model === SYNTHETIC_MODEL ? "notice" : "response";
|
|
32
|
+
}
|
|
33
|
+
function isModelResponse(entry) {
|
|
34
|
+
return classifyEntry(entry) === "response";
|
|
35
|
+
}
|
|
36
|
+
function responseUsage(entry) {
|
|
37
|
+
return isModelResponse(entry) ? entry.message?.usage : void 0;
|
|
38
|
+
}
|
|
39
|
+
function isFailedRequest(entry) {
|
|
40
|
+
return entry.type !== void 0 && CONVERSATION_RECORD_TYPES.has(entry.type) && entry.isApiErrorMessage === true;
|
|
41
|
+
}
|
|
42
|
+
function tokenCount(value) {
|
|
43
|
+
return typeof value === "number" && Number.isFinite(value) ? value : 0;
|
|
44
|
+
}
|
|
45
|
+
function inputTokensIncludingCache(inputTokens, cacheCreationTokens, cacheReadTokens) {
|
|
46
|
+
return inputTokens + cacheCreationTokens + cacheReadTokens;
|
|
47
|
+
}
|
|
48
|
+
function usageCounts(usage) {
|
|
49
|
+
return {
|
|
50
|
+
inputTokens: tokenCount(usage.input_tokens),
|
|
51
|
+
cacheCreationTokens: tokenCount(usage.cache_creation_input_tokens),
|
|
52
|
+
cacheReadTokens: tokenCount(usage.cache_read_input_tokens),
|
|
53
|
+
outputTokens: tokenCount(usage.output_tokens)
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function promptTokens(usage) {
|
|
57
|
+
const counts = usageCounts(usage);
|
|
58
|
+
return inputTokensIncludingCache(counts.inputTokens, counts.cacheCreationTokens, counts.cacheReadTokens);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export {
|
|
62
|
+
SYSTEM_RECORD_TYPE,
|
|
63
|
+
TURN_DURATION_SUBTYPE,
|
|
64
|
+
USER_RECORD_TYPE,
|
|
65
|
+
ASSISTANT_RECORD_TYPE,
|
|
66
|
+
CONVERSATION_RECORD_TYPES,
|
|
67
|
+
fieldMarkers,
|
|
68
|
+
mayBeConversational,
|
|
69
|
+
toBlocks,
|
|
70
|
+
classifyEntry,
|
|
71
|
+
responseUsage,
|
|
72
|
+
isFailedRequest,
|
|
73
|
+
tokenCount,
|
|
74
|
+
inputTokensIncludingCache,
|
|
75
|
+
usageCounts,
|
|
76
|
+
promptTokens
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=chunk-4KWBQTTG.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../lib/transcript/transcript-entry.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * The Claude Code transcript JSONL record, shared by every transcript reader. A line's\n * role is its record `type`, never `message.role`: `api-request-blob` replays carry a\n * `message.role` and are not conversation.\n */\n\nimport { SYNTHETIC_MODEL } from '../core/constants.js';\nimport { isJsonObject } from '../core/file-utils.js';\nimport { alternation } from '../core/regex.js';\n\nexport interface TranscriptUsage {\n input_tokens?: number;\n output_tokens?: number;\n cache_creation_input_tokens?: number;\n cache_read_input_tokens?: number;\n cache_creation?: { ephemeral_5m_input_tokens?: number; ephemeral_1h_input_tokens?: number };\n output_tokens_details?: { thinking_tokens?: number };\n}\n\nexport interface TranscriptEntry {\n type?: string;\n subtype?: string;\n timestamp?: string;\n /** Set on Claude Code's notices for a failed request (rate limit, server error, login). */\n isApiErrorMessage?: boolean;\n message?: {\n id?: string;\n model?: string;\n content?: unknown;\n usage?: TranscriptUsage;\n };\n}\n\nexport const SYSTEM_RECORD_TYPE = 'system';\nexport const TURN_DURATION_SUBTYPE = 'turn_duration';\n\n/** One element of `message.content`, or of a `tool_result` block's own `content`. */\nexport interface ContentBlock {\n type?: string;\n text?: unknown;\n content?: unknown;\n id?: string;\n name?: string;\n tool_use_id?: string;\n is_error?: boolean;\n}\n\nexport const USER_RECORD_TYPE = 'user';\nexport const ASSISTANT_RECORD_TYPE = 'assistant';\nexport const CONVERSATION_RECORD_TYPES: ReadonlySet<string> = new Set([USER_RECORD_TYPE, ASSISTANT_RECORD_TYPE]);\n\n/** Both spacing variants the JSON serializer emits for a `\"key\": \"value\"` field. */\nexport function fieldMarkers(field: string, value: string): [string, string] {\n return [`\"${field}\":\"${value}\"`, `\"${field}\": \"${value}\"`];\n}\n\n/** Matches a conversation record type as a JSON string token, wherever its field sits; one regex pass is ~8x cheaper than one `includes` per type. */\nconst CONVERSATION_TYPE_TOKEN = new RegExp(`\"${alternation([...CONVERSATION_RECORD_TYPES])}\"`);\n\n/** Skips parsing the attachment, snapshot and system lines that make up most of a transcript. */\nexport function mayBeConversational(line: string): boolean {\n return CONVERSATION_TYPE_TOKEN.test(line);\n}\n\nexport function toBlocks(content: unknown): ContentBlock[] {\n if (!Array.isArray(content)) return [];\n return content.filter((block): block is ContentBlock => isJsonObject(block));\n}\n\n/**\n * - `prompt`: a user record, typed text or tool results\n * - `response`: an assistant record from a real model, including one flagged\n * `isApiErrorMessage`, whose usage may still have been billed\n * - `notice`: an assistant record Claude Code wrote itself (`<synthetic>` model). It carries\n * a `message.id` and zero usage, so a reader counting calls or the serving model must skip\n * it. OTel GenAI semconv rules it out: `gen_ai.response.model` is \"the name of the model\n * that generated the response\", and \"Instrumentation SHOULD NOT synthesize output content\n * for a failed operation\" (semantic-conventions-genai, source dated in otel/attributes.ts).\n * - `other`: every non-conversation record\n */\nexport type EntryKind = 'prompt' | 'response' | 'notice' | 'other';\n\nexport function classifyEntry(entry: TranscriptEntry): EntryKind {\n if (entry.type === USER_RECORD_TYPE) return 'prompt';\n if (entry.type !== ASSISTANT_RECORD_TYPE) return 'other';\n return entry.message?.model === SYNTHETIC_MODEL ? 'notice' : 'response';\n}\n\nexport function isModelResponse(entry: TranscriptEntry): boolean {\n return classifyEntry(entry) === 'response';\n}\n\n/** A billed response's usage record; undefined for a notice, a prompt, or a response without one. */\nexport function responseUsage(entry: TranscriptEntry): TranscriptUsage | undefined {\n return isModelResponse(entry) ? entry.message?.usage : undefined;\n}\n\n/** A conversation record Claude Code flagged for a request that was never answered (rate limit, server error, login). */\nexport function isFailedRequest(entry: TranscriptEntry): boolean {\n return entry.type !== undefined && CONVERSATION_RECORD_TYPES.has(entry.type) && entry.isApiErrorMessage === true;\n}\n\n/** A missing or non-finite count reads as 0. */\nexport function tokenCount(value: number | undefined): number {\n return typeof value === 'number' && Number.isFinite(value) ? value : 0;\n}\n\n/** Input as the semconv counts it: \"input (prompt) tokens used, including cached tokens\", written or read. */\nexport function inputTokensIncludingCache(inputTokens: number, cacheCreationTokens: number, cacheReadTokens: number): number {\n return inputTokens + cacheCreationTokens + cacheReadTokens;\n}\n\n/** One call's counts as the API reports them: the cache counts are not part of `inputTokens`. */\ninterface UsageCounts {\n inputTokens: number;\n cacheCreationTokens: number;\n cacheReadTokens: number;\n outputTokens: number;\n}\n\nexport function usageCounts(usage: TranscriptUsage): UsageCounts {\n return {\n inputTokens: tokenCount(usage.input_tokens),\n cacheCreationTokens: tokenCount(usage.cache_creation_input_tokens),\n cacheReadTokens: tokenCount(usage.cache_read_input_tokens),\n outputTokens: tokenCount(usage.output_tokens),\n };\n}\n\n/** Everything one call read as input, from its raw usage record. */\nexport function promptTokens(usage: TranscriptUsage): number {\n const counts = usageCounts(usage);\n return inputTokensIncludingCache(counts.inputTokens, counts.cacheCreationTokens, counts.cacheReadTokens);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAiCO,IAAM,qBAAqB;AAC3B,IAAM,wBAAwB;AAa9B,IAAM,mBAAmB;AACzB,IAAM,wBAAwB;AAC9B,IAAM,4BAAiD,oBAAI,IAAI,CAAC,kBAAkB,qBAAqB,CAAC;AAGxG,SAAS,aAAa,OAAe,OAAiC;AAC3E,SAAO,CAAC,IAAI,KAAK,MAAM,KAAK,KAAK,IAAI,KAAK,OAAO,KAAK,GAAG;AAC3D;AAGA,IAAM,0BAA0B,IAAI,OAAO,IAAI,YAAY,CAAC,GAAG,yBAAyB,CAAC,CAAC,GAAG;AAGtF,SAAS,oBAAoB,MAAuB;AACzD,SAAO,wBAAwB,KAAK,IAAI;AAC1C;AAEO,SAAS,SAAS,SAAkC;AACzD,MAAI,CAAC,MAAM,QAAQ,OAAO,EAAG,QAAO,CAAC;AACrC,SAAO,QAAQ,OAAO,CAAC,UAAiC,aAAa,KAAK,CAAC;AAC7E;AAeO,SAAS,cAAc,OAAmC;AAC/D,MAAI,MAAM,SAAS,iBAAkB,QAAO;AAC5C,MAAI,MAAM,SAAS,sBAAuB,QAAO;AACjD,SAAO,MAAM,SAAS,UAAU,kBAAkB,WAAW;AAC/D;AAEO,SAAS,gBAAgB,OAAiC;AAC/D,SAAO,cAAc,KAAK,MAAM;AAClC;AAGO,SAAS,cAAc,OAAqD;AACjF,SAAO,gBAAgB,KAAK,IAAI,MAAM,SAAS,QAAQ;AACzD;AAGO,SAAS,gBAAgB,OAAiC;AAC/D,SAAO,MAAM,SAAS,UAAa,0BAA0B,IAAI,MAAM,IAAI,KAAK,MAAM,sBAAsB;AAC9G;AAGO,SAAS,WAAW,OAAmC;AAC5D,SAAO,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,IAAI,QAAQ;AACvE;AAGO,SAAS,0BAA0B,aAAqB,qBAA6B,iBAAiC;AAC3H,SAAO,cAAc,sBAAsB;AAC7C;AAUO,SAAS,YAAY,OAAqC;AAC/D,SAAO;AAAA,IACL,aAAa,WAAW,MAAM,YAAY;AAAA,IAC1C,qBAAqB,WAAW,MAAM,2BAA2B;AAAA,IACjE,iBAAiB,WAAW,MAAM,uBAAuB;AAAA,IACzD,cAAc,WAAW,MAAM,aAAa;AAAA,EAC9C;AACF;AAGO,SAAS,aAAa,OAAgC;AAC3D,QAAM,SAAS,YAAY,KAAK;AAChC,SAAO,0BAA0B,OAAO,aAAa,OAAO,qBAAqB,OAAO,eAAe;AACzG;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|