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,158 @@
|
|
|
1
|
+
import { createRequire as __hookRunnerCreateRequire } from 'node:module';
|
|
2
|
+
const require = __hookRunnerCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
UNKNOWN_ERROR_TYPE
|
|
5
|
+
} from "./chunk-7OM5CYES.js";
|
|
6
|
+
import {
|
|
7
|
+
BUILTIN_TOOLS_BY_CATEGORY,
|
|
8
|
+
EDIT_TOOLS,
|
|
9
|
+
TASK_TOOLS,
|
|
10
|
+
THRESHOLDS,
|
|
11
|
+
countNonEmptyLines
|
|
12
|
+
} from "./chunk-52RY6LQT.js";
|
|
13
|
+
|
|
14
|
+
// lib/runtime/output-analyzer.ts
|
|
15
|
+
var TIMEOUT_PATTERN = /\btimeout\b|\btimed?\s*out\b/i;
|
|
16
|
+
var ERROR_PATTERN = /\berror\b/i;
|
|
17
|
+
var ZERO_ERRORS_PATTERN = /\b0 errors?\b/i;
|
|
18
|
+
var FAILED_PATTERN = /\bfailed\b/i;
|
|
19
|
+
var ZERO_FAILED_PATTERN = /\b0 failed\b/i;
|
|
20
|
+
var EXCEPTION_PATTERN = /\bexception\b/i;
|
|
21
|
+
var WRITE_SUCCESS_PATTERN = /has been (?:updated|written) successfully/;
|
|
22
|
+
var WRITE_ERROR_PATTERN = /^Error\b/m;
|
|
23
|
+
var PERMISSION_DENIED_MARKER = "Permission denied";
|
|
24
|
+
var RATE_LIMIT_PATTERN = /\b429\b|rate.?limit|too many requests|throttl/i;
|
|
25
|
+
var AGENT_ERROR_PATTERN = /(?:\berror:|\b[A-Za-z]+Error:|(?<!no )\berror\s+(?:occurred|detected|found|raised|thrown)\b|\berror\s+TS\d+:)/i;
|
|
26
|
+
var SCAN_HEAD_TAIL_CHUNK_BYTES = 5e3;
|
|
27
|
+
function boundedScanText(output, strategy = "head") {
|
|
28
|
+
if (output.length <= THRESHOLDS.LARGE_OUTPUT_BYTES) return output;
|
|
29
|
+
return strategy === "head" ? output.slice(0, THRESHOLDS.LARGE_OUTPUT_BYTES) : output.slice(0, SCAN_HEAD_TAIL_CHUNK_BYTES) + output.slice(-SCAN_HEAD_TAIL_CHUNK_BYTES);
|
|
30
|
+
}
|
|
31
|
+
function mentionsRateLimit(output) {
|
|
32
|
+
return RATE_LIMIT_PATTERN.test(boundedScanText(output, "head-tail"));
|
|
33
|
+
}
|
|
34
|
+
function mentionsAgentError(output) {
|
|
35
|
+
return AGENT_ERROR_PATTERN.test(boundedScanText(output, "head-tail"));
|
|
36
|
+
}
|
|
37
|
+
var ERROR_CATEGORIES = [
|
|
38
|
+
{ pattern: /econnrefused|etimedout|enotfound|econnreset|enetunreach|socket hang up|connection refused|connection.?failed|connection.?error/i, category: "network", errorType: "connection" },
|
|
39
|
+
{ pattern: RATE_LIMIT_PATTERN, category: "rate_limit" },
|
|
40
|
+
{ pattern: /\b401\b|\b403\b|unauthorized|invalid.?credentials|auth.{0,40}fail/i, category: "auth", errorType: "authentication" },
|
|
41
|
+
{ pattern: TIMEOUT_PATTERN, category: "timeout" },
|
|
42
|
+
{ pattern: /\b400\b|invalid.?input|validation|bad request/i, category: "validation" },
|
|
43
|
+
{ pattern: /permission/i, category: "permission" },
|
|
44
|
+
{ pattern: /not found|\b404\b/i, category: "not_found" },
|
|
45
|
+
{ pattern: /no active project|invalid.?project|missing.?configuration|not.?configured|config.?error/i, category: "configuration" }
|
|
46
|
+
];
|
|
47
|
+
function classifyBoundedText(text) {
|
|
48
|
+
for (const { pattern, category, errorType } of ERROR_CATEGORIES) {
|
|
49
|
+
if (pattern.test(text)) return { errorType: errorType ?? category, errorCategory: category };
|
|
50
|
+
}
|
|
51
|
+
return { errorType: UNKNOWN_ERROR_TYPE, errorCategory: UNKNOWN_ERROR_TYPE };
|
|
52
|
+
}
|
|
53
|
+
function classifyError(output, strategy = "head") {
|
|
54
|
+
return classifyBoundedText(boundedScanText(output, strategy));
|
|
55
|
+
}
|
|
56
|
+
function hasErrorWording(output) {
|
|
57
|
+
return output.split("\n").some(
|
|
58
|
+
(line) => ERROR_PATTERN.test(line) && !ZERO_ERRORS_PATTERN.test(line)
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
function hasFailureWording(output) {
|
|
62
|
+
return hasErrorWording(output) || FAILED_PATTERN.test(output) && !ZERO_FAILED_PATTERN.test(output);
|
|
63
|
+
}
|
|
64
|
+
function analyzeOutput(output) {
|
|
65
|
+
const coerced = output ?? "";
|
|
66
|
+
const text = boundedScanText(coerced);
|
|
67
|
+
const hasError = hasFailureWording(text) || EXCEPTION_PATTERN.test(text);
|
|
68
|
+
const classified = hasError ? classifyBoundedText(text) : void 0;
|
|
69
|
+
return {
|
|
70
|
+
outputSize: coerced.length,
|
|
71
|
+
hasError,
|
|
72
|
+
errorType: classified?.errorType,
|
|
73
|
+
errorCategory: classified?.errorCategory
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
var NOT_FOUND = { errorType: "not_found", errorCategory: "not_found" };
|
|
77
|
+
var PERMISSION = { errorType: "permission", errorCategory: "permission" };
|
|
78
|
+
var TIMEOUT = { errorType: "timeout", errorCategory: "timeout" };
|
|
79
|
+
var labelled = (errorType) => ({ errorType });
|
|
80
|
+
function firstMatch(output, markers) {
|
|
81
|
+
for (const [marker, detected] of markers) {
|
|
82
|
+
if (output.includes(marker)) return detected;
|
|
83
|
+
}
|
|
84
|
+
return void 0;
|
|
85
|
+
}
|
|
86
|
+
function detectWriteError(output) {
|
|
87
|
+
if (WRITE_SUCCESS_PATTERN.test(output)) return void 0;
|
|
88
|
+
if (!WRITE_ERROR_PATTERN.test(output) && !output.includes(PERMISSION_DENIED_MARKER)) return void 0;
|
|
89
|
+
return firstMatch(output, [
|
|
90
|
+
[PERMISSION_DENIED_MARKER, PERMISSION],
|
|
91
|
+
["not found", NOT_FOUND]
|
|
92
|
+
]) ?? labelled("write_error");
|
|
93
|
+
}
|
|
94
|
+
function detectWriteErrorLine(output) {
|
|
95
|
+
return WRITE_ERROR_PATTERN.test(output) ? labelled("write_error") : void 0;
|
|
96
|
+
}
|
|
97
|
+
function detectBashError(output) {
|
|
98
|
+
const marker = firstMatch(output, [
|
|
99
|
+
["command not found", labelled("command_not_found")],
|
|
100
|
+
[PERMISSION_DENIED_MARKER, PERMISSION],
|
|
101
|
+
["No such file or directory", NOT_FOUND]
|
|
102
|
+
]);
|
|
103
|
+
if (marker) return marker;
|
|
104
|
+
return output.includes("error:") && !output.includes("0 error") ? labelled("execution_error") : void 0;
|
|
105
|
+
}
|
|
106
|
+
function detectFetchError(output) {
|
|
107
|
+
if (TIMEOUT_PATTERN.test(output)) return TIMEOUT;
|
|
108
|
+
return output.includes("Error fetching") || output.includes("Failed to fetch") ? labelled("fetch_error") : void 0;
|
|
109
|
+
}
|
|
110
|
+
function failureAs(errorType) {
|
|
111
|
+
return (output) => hasFailureWording(output) ? labelled(errorType) : void 0;
|
|
112
|
+
}
|
|
113
|
+
var detectReadError = (output) => firstMatch(output, [
|
|
114
|
+
["does not exist", NOT_FOUND],
|
|
115
|
+
[PERMISSION_DENIED_MARKER, PERMISSION],
|
|
116
|
+
["Is a directory", labelled("invalid_path")]
|
|
117
|
+
]);
|
|
118
|
+
var detectorEntries = (tools, detector) => Array.from(tools, (tool) => [tool, detector]);
|
|
119
|
+
var ERROR_DETECTORS = new Map([
|
|
120
|
+
["Read", detectReadError],
|
|
121
|
+
...detectorEntries(EDIT_TOOLS, detectWriteError),
|
|
122
|
+
...detectorEntries(BUILTIN_TOOLS_BY_CATEGORY.shell, detectBashError),
|
|
123
|
+
...detectorEntries(BUILTIN_TOOLS_BY_CATEGORY.web, detectFetchError),
|
|
124
|
+
...detectorEntries(BUILTIN_TOOLS_BY_CATEGORY.planning, detectWriteErrorLine),
|
|
125
|
+
...detectorEntries(BUILTIN_TOOLS_BY_CATEGORY.notebook, detectWriteErrorLine),
|
|
126
|
+
[TASK_TOOLS.KILL_SHELL, failureAs("shell_error")],
|
|
127
|
+
[TASK_TOOLS.OUTPUT, failureAs("task_error")]
|
|
128
|
+
]);
|
|
129
|
+
var EMPTY_RESULT_MARKERS = {
|
|
130
|
+
Glob: "No files found",
|
|
131
|
+
Grep: "No matches found"
|
|
132
|
+
};
|
|
133
|
+
function countResultLines(output, emptyMarker) {
|
|
134
|
+
return output.includes(emptyMarker) ? 0 : countNonEmptyLines(output);
|
|
135
|
+
}
|
|
136
|
+
function analyzeBuiltinOutput(toolName, output) {
|
|
137
|
+
const coerced = output ?? "";
|
|
138
|
+
const safeOutput = boundedScanText(coerced);
|
|
139
|
+
const detected = ERROR_DETECTORS.get(toolName)?.(safeOutput);
|
|
140
|
+
const emptyMarker = EMPTY_RESULT_MARKERS[toolName];
|
|
141
|
+
return {
|
|
142
|
+
outputSize: coerced.length,
|
|
143
|
+
hasError: detected !== void 0,
|
|
144
|
+
errorType: detected?.errorType,
|
|
145
|
+
errorCategory: detected && (detected.errorCategory ?? classifyBoundedText(safeOutput).errorCategory),
|
|
146
|
+
resultCount: emptyMarker === void 0 ? void 0 : countResultLines(safeOutput, emptyMarker)
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export {
|
|
151
|
+
boundedScanText,
|
|
152
|
+
mentionsRateLimit,
|
|
153
|
+
mentionsAgentError,
|
|
154
|
+
classifyError,
|
|
155
|
+
analyzeOutput,
|
|
156
|
+
analyzeBuiltinOutput
|
|
157
|
+
};
|
|
158
|
+
//# sourceMappingURL=chunk-LYY6RCIE.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../lib/runtime/output-analyzer.ts"],
|
|
4
|
+
"sourcesContent": ["/** Tool-output failure detection. Patterns are module-scope (H2). */\n\nimport { BUILTIN_TOOLS_BY_CATEGORY, EDIT_TOOLS, THRESHOLDS, TASK_TOOLS } from '../core/constants.js';\nimport { countNonEmptyLines } from '../core/format-utils.js';\nimport { UNKNOWN_ERROR_TYPE } from '../otel/attributes.js';\n\ntype ErrorCategory =\n | 'network' | 'auth' | 'rate_limit' | 'timeout' | 'validation'\n | 'not_found' | 'permission' | 'configuration' | 'unknown' | 'interrupt';\n\nexport interface OutputAnalysis {\n outputSize: number;\n hasError: boolean;\n errorType?: string;\n errorCategory?: ErrorCategory;\n}\n\ninterface BuiltinOutputAnalysis extends OutputAnalysis {\n resultCount?: number;\n}\n\n/** Word boundary: not setTimeout/clearTimeout in code content. */\nconst TIMEOUT_PATTERN = /\\btimeout\\b|\\btimed?\\s*out\\b/i;\n\nconst ERROR_PATTERN = /\\berror\\b/i;\nconst ZERO_ERRORS_PATTERN = /\\b0 errors?\\b/i;\nconst FAILED_PATTERN = /\\bfailed\\b/i;\nconst ZERO_FAILED_PATTERN = /\\b0 failed\\b/i;\nconst EXCEPTION_PATTERN = /\\bexception\\b/i;\n\nconst WRITE_SUCCESS_PATTERN = /has been (?:updated|written) successfully/;\nconst WRITE_ERROR_PATTERN = /^Error\\b/m;\nconst PERMISSION_DENIED_MARKER = 'Permission denied';\n\nconst RATE_LIMIT_PATTERN = /\\b429\\b|rate.?limit|too many requests|throttl/i;\n\n// Real error signals only; excludes audit-report phrases like \"error count\" or \"no error found\".\nconst AGENT_ERROR_PATTERN =\n /(?:\\berror:|\\b[A-Za-z]+Error:|(?<!no )\\berror\\s+(?:occurred|detected|found|raised|thrown)\\b|\\berror\\s+TS\\d+:)/i;\n\nconst SCAN_HEAD_TAIL_CHUNK_BYTES = 5000;\n\n/** `head`: tool errors print first. `head-tail`: agent output and failure text put the decisive line last. */\ntype ScanStrategy = 'head' | 'head-tail';\n\n/** The one scan-bounding policy (PT10); the analyzers apply it themselves, so no caller can hand them an unbounded payload. */\nexport function boundedScanText(output: string, strategy: ScanStrategy = 'head'): string {\n if (output.length <= THRESHOLDS.LARGE_OUTPUT_BYTES) return output;\n return strategy === 'head'\n ? output.slice(0, THRESHOLDS.LARGE_OUTPUT_BYTES)\n : output.slice(0, SCAN_HEAD_TAIL_CHUNK_BYTES) + output.slice(-SCAN_HEAD_TAIL_CHUNK_BYTES);\n}\n\nexport function mentionsRateLimit(output: string): boolean {\n return RATE_LIMIT_PATTERN.test(boundedScanText(output, 'head-tail'));\n}\n\n/** Narrower than `analyzeOutput`: agent output routinely discusses errors without having hit one. */\nexport function mentionsAgentError(output: string): boolean {\n return AGENT_ERROR_PATTERN.test(boundedScanText(output, 'head-tail'));\n}\n\ninterface ErrorCategoryRule {\n readonly pattern: RegExp;\n readonly category: ErrorCategory;\n /** Telemetry label when it differs from the category. */\n readonly errorType?: string;\n}\n\n/** First match wins. The `auth` gap is bounded: `.*` on a single-line JSON payload backtracked for ~13 ms per `auth` hit. */\nconst ERROR_CATEGORIES: readonly ErrorCategoryRule[] = [\n { pattern: /econnrefused|etimedout|enotfound|econnreset|enetunreach|socket hang up|connection refused|connection.?failed|connection.?error/i, category: 'network', errorType: 'connection' },\n { pattern: RATE_LIMIT_PATTERN, category: 'rate_limit' },\n { pattern: /\\b401\\b|\\b403\\b|unauthorized|invalid.?credentials|auth.{0,40}fail/i, category: 'auth', errorType: 'authentication' },\n { pattern: TIMEOUT_PATTERN, category: 'timeout' },\n { pattern: /\\b400\\b|invalid.?input|validation|bad request/i, category: 'validation' },\n { pattern: /permission/i, category: 'permission' },\n { pattern: /not found|\\b404\\b/i, category: 'not_found' },\n { pattern: /no active project|invalid.?project|missing.?configuration|not.?configured|config.?error/i, category: 'configuration' },\n];\n\nexport interface ErrorClassification {\n errorType: string;\n errorCategory: ErrorCategory;\n}\n\nfunction classifyBoundedText(text: string): ErrorClassification {\n for (const { pattern, category, errorType } of ERROR_CATEGORIES) {\n if (pattern.test(text)) return { errorType: errorType ?? category, errorCategory: category };\n }\n return { errorType: UNKNOWN_ERROR_TYPE, errorCategory: UNKNOWN_ERROR_TYPE };\n}\n\n/** Classification only; the text is already known to be an error. */\nexport function classifyError(output: string, strategy: ScanStrategy = 'head'): ErrorClassification {\n return classifyBoundedText(boundedScanText(output, strategy));\n}\n\n/** Per line, so a \"0 errors\" summary cannot suppress a genuine error elsewhere (OA-002). */\nfunction hasErrorWording(output: string): boolean {\n return output.split('\\n').some(line =>\n ERROR_PATTERN.test(line) && !ZERO_ERRORS_PATTERN.test(line)\n );\n}\n\nfunction hasFailureWording(output: string): boolean {\n return hasErrorWording(output) ||\n (FAILED_PATTERN.test(output) && !ZERO_FAILED_PATTERN.test(output));\n}\n\nexport function analyzeOutput(output: string | undefined): OutputAnalysis {\n const coerced = output ?? '';\n const text = boundedScanText(coerced);\n const hasError = hasFailureWording(text) || EXCEPTION_PATTERN.test(text);\n const classified = hasError ? classifyBoundedText(text) : undefined;\n\n return {\n outputSize: coerced.length,\n hasError,\n errorType: classified?.errorType,\n errorCategory: classified?.errorCategory,\n };\n}\n\n/** What a per-tool detector found. A marker that is unambiguous for its tool names the category itself; otherwise it is derived from the text. */\ninterface DetectedError {\n readonly errorType: string;\n readonly errorCategory?: ErrorCategory;\n}\n\nconst NOT_FOUND: DetectedError = { errorType: 'not_found', errorCategory: 'not_found' };\nconst PERMISSION: DetectedError = { errorType: 'permission', errorCategory: 'permission' };\nconst TIMEOUT: DetectedError = { errorType: 'timeout', errorCategory: 'timeout' };\n\nconst labelled = (errorType: string): DetectedError => ({ errorType });\n\n/** In order: most specific marker first. */\nfunction firstMatch(output: string, markers: ReadonlyArray<[string, DetectedError]>): DetectedError | undefined {\n for (const [marker, detected] of markers) {\n if (output.includes(marker)) return detected;\n }\n return undefined;\n}\n\nfunction detectWriteError(output: string): DetectedError | undefined {\n // Success first: edited file content (\"throw new Error(...)\") is otherwise a false positive.\n if (WRITE_SUCCESS_PATTERN.test(output)) return undefined;\n if (!WRITE_ERROR_PATTERN.test(output) && !output.includes(PERMISSION_DENIED_MARKER)) return undefined;\n return firstMatch(output, [\n [PERMISSION_DENIED_MARKER, PERMISSION],\n ['not found', NOT_FOUND],\n ]) ?? labelled('write_error');\n}\n\nfunction detectWriteErrorLine(output: string): DetectedError | undefined {\n return WRITE_ERROR_PATTERN.test(output) ? labelled('write_error') : undefined;\n}\n\nfunction detectBashError(output: string): DetectedError | undefined {\n const marker = firstMatch(output, [\n ['command not found', labelled('command_not_found')],\n [PERMISSION_DENIED_MARKER, PERMISSION],\n ['No such file or directory', NOT_FOUND],\n ]);\n if (marker) return marker;\n return output.includes('error:') && !output.includes('0 error') ? labelled('execution_error') : undefined;\n}\n\nfunction detectFetchError(output: string): DetectedError | undefined {\n if (TIMEOUT_PATTERN.test(output)) return TIMEOUT;\n return output.includes('Error fetching') || output.includes('Failed to fetch') ? labelled('fetch_error') : undefined;\n}\n\n/** Generic failure wording reported under a tool-specific label. */\nfunction failureAs(errorType: string): ErrorDetector {\n return output => (hasFailureWording(output) ? labelled(errorType) : undefined);\n}\n\ntype ErrorDetector = (output: string) => DetectedError | undefined;\n\nconst detectReadError: ErrorDetector = output => firstMatch(output, [\n ['does not exist', NOT_FOUND],\n [PERMISSION_DENIED_MARKER, PERMISSION],\n ['Is a directory', labelled('invalid_path')],\n]);\n\nconst detectorEntries = (tools: Iterable<string>, detector: ErrorDetector): Array<[string, ErrorDetector]> =>\n Array.from(tools, tool => [tool, detector]);\n\n/**\n * Keyed from the harness's own tool groups, so a tool added to a group gets its group's detector\n * instead of silently reading as success. Tools absent here always report success.\n */\nconst ERROR_DETECTORS: ReadonlyMap<string, ErrorDetector> = new Map([\n ['Read', detectReadError],\n ...detectorEntries(EDIT_TOOLS, detectWriteError),\n ...detectorEntries(BUILTIN_TOOLS_BY_CATEGORY.shell, detectBashError),\n ...detectorEntries(BUILTIN_TOOLS_BY_CATEGORY.web, detectFetchError),\n ...detectorEntries(BUILTIN_TOOLS_BY_CATEGORY.planning, detectWriteErrorLine),\n ...detectorEntries(BUILTIN_TOOLS_BY_CATEGORY.notebook, detectWriteErrorLine),\n [TASK_TOOLS.KILL_SHELL, failureAs('shell_error')],\n [TASK_TOOLS.OUTPUT, failureAs('task_error')],\n]);\n\nconst EMPTY_RESULT_MARKERS: Partial<Record<string, string>> = {\n Glob: 'No files found',\n Grep: 'No matches found',\n};\n\nfunction countResultLines(output: string, emptyMarker: string): number {\n return output.includes(emptyMarker) ? 0 : countNonEmptyLines(output);\n}\n\nexport function analyzeBuiltinOutput(toolName: string, output: string | undefined): BuiltinOutputAnalysis {\n const coerced = output ?? '';\n const safeOutput = boundedScanText(coerced);\n\n const detected = ERROR_DETECTORS.get(toolName)?.(safeOutput);\n const emptyMarker = EMPTY_RESULT_MARKERS[toolName];\n\n return {\n outputSize: coerced.length,\n hasError: detected !== undefined,\n errorType: detected?.errorType,\n errorCategory: detected && (detected.errorCategory ?? classifyBoundedText(safeOutput).errorCategory),\n resultCount: emptyMarker === undefined ? undefined : countResultLines(safeOutput, emptyMarker),\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAsBA,IAAM,kBAAkB;AAExB,IAAM,gBAAgB;AACtB,IAAM,sBAAsB;AAC5B,IAAM,iBAAiB;AACvB,IAAM,sBAAsB;AAC5B,IAAM,oBAAoB;AAE1B,IAAM,wBAAwB;AAC9B,IAAM,sBAAsB;AAC5B,IAAM,2BAA2B;AAEjC,IAAM,qBAAqB;AAG3B,IAAM,sBACJ;AAEF,IAAM,6BAA6B;AAM5B,SAAS,gBAAgB,QAAgB,WAAyB,QAAgB;AACvF,MAAI,OAAO,UAAU,WAAW,mBAAoB,QAAO;AAC3D,SAAO,aAAa,SAChB,OAAO,MAAM,GAAG,WAAW,kBAAkB,IAC7C,OAAO,MAAM,GAAG,0BAA0B,IAAI,OAAO,MAAM,CAAC,0BAA0B;AAC5F;AAEO,SAAS,kBAAkB,QAAyB;AACzD,SAAO,mBAAmB,KAAK,gBAAgB,QAAQ,WAAW,CAAC;AACrE;AAGO,SAAS,mBAAmB,QAAyB;AAC1D,SAAO,oBAAoB,KAAK,gBAAgB,QAAQ,WAAW,CAAC;AACtE;AAUA,IAAM,mBAAiD;AAAA,EACrD,EAAE,SAAS,mIAAmI,UAAU,WAAW,WAAW,aAAa;AAAA,EAC3L,EAAE,SAAS,oBAAoB,UAAU,aAAa;AAAA,EACtD,EAAE,SAAS,sEAAsE,UAAU,QAAQ,WAAW,iBAAiB;AAAA,EAC/H,EAAE,SAAS,iBAAiB,UAAU,UAAU;AAAA,EAChD,EAAE,SAAS,kDAAkD,UAAU,aAAa;AAAA,EACpF,EAAE,SAAS,eAAe,UAAU,aAAa;AAAA,EACjD,EAAE,SAAS,sBAAsB,UAAU,YAAY;AAAA,EACvD,EAAE,SAAS,4FAA4F,UAAU,gBAAgB;AACnI;AAOA,SAAS,oBAAoB,MAAmC;A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,EACxB,GAAG,gBAAgB,YAAY,gBAAgB;AAAA,EAC/C,GAAG,gBAAgB,0BAA0B,OAAO,eAAe;AAAA,EACnE,GAAG,gBAAgB,0BAA0B,KAAK,gBAAgB;AAAA,EAClE,GAAG,gBAAgB,0BAA0B,UAAU,oBAAoB;AAAA,EAC3E,GAAG,gBAAgB,0BAA0B,UAAU,oBAAoB;AAAA,EAC3E,CAAC,WAAW,YAAY,UAAU,aAAa,CAAC;AAAA,EAChD,CAAC,WAAW,QAAQ,UAAU,YAAY,CAAC;AAC7C,CAAC;AAED,IAAM,uBAAwD;AAAA,EAC5D,MAAM;AAAA,EACN,MAAM;AACR;AAEA,SAAS,iBAAiB,QAAgB,aAA6B;AACrE,SAAO,OAAO,SAAS,WAAW,IAAI,IAAI,mBAAmB,MAAM;AACrE;AAEO,SAAS,qBAAqB,UAAkB,QAAmD;AACxG,QAAM,UAAU,UAAU;AAC1B,QAAM,aAAa,gBAAgB,OAAO;AAE1C,QAAM,WAAW,gBAAgB,IAAI,QAAQ,IAAI,UAAU;AAC3D,QAAM,cAAc,qBAAqB,QAAQ;AAEjD,SAAO;AAAA,IACL,YAAY,QAAQ;AAAA,IACpB,UAAU,aAAa;AAAA,IACvB,WAAW,UAAU;AAAA,IACrB,eAAe,aAAa,SAAS,iBAAiB,oBAAoB,UAAU,EAAE;AAAA,IACtF,aAAa,gBAAgB,SAAY,SAAY,iBAAiB,YAAY,WAAW;AAAA,EAC/F;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createRequire as __hookRunnerCreateRequire } from 'node:module';
|
|
2
|
+
const require = __hookRunnerCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
THRESHOLDS,
|
|
5
|
+
memoizeIn
|
|
6
|
+
} from "./chunk-52RY6LQT.js";
|
|
7
|
+
|
|
8
|
+
// lib/runtime/tool-output.ts
|
|
9
|
+
var ResponseTooLarge = class extends Error {
|
|
10
|
+
};
|
|
11
|
+
function stringifyBounded(value) {
|
|
12
|
+
let remaining = THRESHOLDS.MAX_JSON_SIZE_BYTES;
|
|
13
|
+
try {
|
|
14
|
+
const json = JSON.stringify(value, (_key, v) => {
|
|
15
|
+
if (typeof v === "string") {
|
|
16
|
+
remaining -= v.length;
|
|
17
|
+
if (remaining < 0) throw new ResponseTooLarge();
|
|
18
|
+
}
|
|
19
|
+
return v;
|
|
20
|
+
});
|
|
21
|
+
return json.length > THRESHOLDS.MAX_JSON_SIZE_BYTES ? `[response truncated: ${json.length} chars]` : json;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
return error instanceof ResponseTooLarge ? "[response too large to serialize]" : "[unserializable response]";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function resolveUncached(input) {
|
|
27
|
+
if (input.tool_response == null) return input.tool_output ?? "";
|
|
28
|
+
if (typeof input.tool_response === "string") {
|
|
29
|
+
return input.tool_response.slice(0, THRESHOLDS.MAX_JSON_SIZE_BYTES);
|
|
30
|
+
}
|
|
31
|
+
return stringifyBounded(input.tool_response);
|
|
32
|
+
}
|
|
33
|
+
var resolvedByInput = /* @__PURE__ */ new WeakMap();
|
|
34
|
+
function resolveOutputText(input) {
|
|
35
|
+
return memoizeIn(resolvedByInput, input, () => resolveUncached(input));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
resolveOutputText
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=chunk-M4R4QIQH.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../lib/runtime/tool-output.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * One bounded string view of `tool_response` (preferred) or legacy `tool_output`\n * for every PostToolUse handler. Serialisation of an oversized payload is abandoned\n * part-way (ER4) and replaced by a sentinel, never truncated into malformed JSON.\n */\n\nimport { THRESHOLDS } from '../core/constants.js';\nimport { memoizeIn } from '../core/file-utils.js';\nimport type { PostToolHookInput } from './hook-input.js';\n\ntype OutputSource = Pick<PostToolHookInput, 'tool_output' | 'tool_response'>;\n\n/** Thrown from the replacer to abandon serialisation early; never escapes `stringifyBounded`. */\nclass ResponseTooLarge extends Error {}\n\n/** Stringify, bailing once string content alone passes the limit, so a huge payload is never materialised. */\nfunction stringifyBounded(value: unknown): string {\n let remaining = THRESHOLDS.MAX_JSON_SIZE_BYTES;\n try {\n const json = JSON.stringify(value, (_key, v: unknown) => {\n if (typeof v === 'string') {\n remaining -= v.length;\n if (remaining < 0) throw new ResponseTooLarge();\n }\n return v;\n });\n return json.length > THRESHOLDS.MAX_JSON_SIZE_BYTES\n ? `[response truncated: ${json.length} chars]`\n : json;\n } catch (error) {\n return error instanceof ResponseTooLarge ? '[response too large to serialize]' : '[unserializable response]';\n }\n}\n\nfunction resolveUncached(input: OutputSource): string {\n if (input.tool_response == null) return input.tool_output ?? '';\n if (typeof input.tool_response === 'string') {\n return input.tool_response.slice(0, THRESHOLDS.MAX_JSON_SIZE_BYTES);\n }\n return stringifyBounded(input.tool_response);\n}\n\n/** Keyed on the input object: router and handlers all ask for the same object's text. */\nconst resolvedByInput = new WeakMap<OutputSource, string>();\n\n/** One resolution per event. */\nexport function resolveOutputText(input: OutputSource): string {\n return memoizeIn(resolvedByInput, input, () => resolveUncached(input));\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAaA,IAAM,mBAAN,cAA+B,MAAM;AAAC;AAGtC,SAAS,iBAAiB,OAAwB;AAChD,MAAI,YAAY,WAAW;AAC3B,MAAI;AACF,UAAM,OAAO,KAAK,UAAU,OAAO,CAAC,MAAM,MAAe;AACvD,UAAI,OAAO,MAAM,UAAU;AACzB,qBAAa,EAAE;AACf,YAAI,YAAY,EAAG,OAAM,IAAI,iBAAiB;AAAA,MAChD;AACA,aAAO;AAAA,IACT,CAAC;AACD,WAAO,KAAK,SAAS,WAAW,sBAC5B,wBAAwB,KAAK,MAAM,YACnC;AAAA,EACN,SAAS,OAAO;AACd,WAAO,iBAAiB,mBAAmB,sCAAsC;AAAA,EACnF;AACF;AAEA,SAAS,gBAAgB,OAA6B;AACpD,MAAI,MAAM,iBAAiB,KAAM,QAAO,MAAM,eAAe;AAC7D,MAAI,OAAO,MAAM,kBAAkB,UAAU;AAC3C,WAAO,MAAM,cAAc,MAAM,GAAG,WAAW,mBAAmB;AAAA,EACpE;AACA,SAAO,iBAAiB,MAAM,aAAa;AAC7C;AAGA,IAAM,kBAAkB,oBAAI,QAA8B;AAGnD,SAAS,kBAAkB,OAA6B;AAC7D,SAAO,UAAU,iBAAiB,OAAO,MAAM,gBAAgB,KAAK,CAAC;AACvE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { createRequire as __hookRunnerCreateRequire } from 'node:module';
|
|
2
|
+
const require = __hookRunnerCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
boundedScanText
|
|
5
|
+
} from "./chunk-LYY6RCIE.js";
|
|
6
|
+
import {
|
|
7
|
+
AGENT_ATTRS,
|
|
8
|
+
GENAI_TOOL_NAME_ATTR,
|
|
9
|
+
HOOK_NAME_ATTR,
|
|
10
|
+
LOGS_FILE_PREFIX,
|
|
11
|
+
SESSION_ATTRIBUTES,
|
|
12
|
+
appendTelemetryRecords,
|
|
13
|
+
init_esm,
|
|
14
|
+
millisToHrTime,
|
|
15
|
+
recordMetric
|
|
16
|
+
} from "./chunk-7OM5CYES.js";
|
|
17
|
+
import {
|
|
18
|
+
SERVICE_VERSION,
|
|
19
|
+
SeverityNumber,
|
|
20
|
+
getServiceName
|
|
21
|
+
} from "./chunk-GG2I4TGI.js";
|
|
22
|
+
import {
|
|
23
|
+
THRESHOLDS
|
|
24
|
+
} from "./chunk-52RY6LQT.js";
|
|
25
|
+
import {
|
|
26
|
+
UNITS
|
|
27
|
+
} from "./chunk-RWRGC7ZK.js";
|
|
28
|
+
|
|
29
|
+
// lib/otel/evaluation-attrs.ts
|
|
30
|
+
var EVALUATION_RESULT_EVENT = "gen_ai.evaluation.result";
|
|
31
|
+
var EVALUATION_SCHEMA_URL = "https://integritystudio.ai/schemas/evaluation/1.0.0";
|
|
32
|
+
var EVALUATOR_KIND = {
|
|
33
|
+
RULE: "rule",
|
|
34
|
+
LLM: "llm",
|
|
35
|
+
HUMAN: "human",
|
|
36
|
+
GROUND_TRUTH: "ground_truth"
|
|
37
|
+
};
|
|
38
|
+
var EVALUATION_COHORT = {
|
|
39
|
+
NORMAL: "normal",
|
|
40
|
+
SEED: "seed",
|
|
41
|
+
CANARY: "canary",
|
|
42
|
+
BACKFILL: "backfill"
|
|
43
|
+
};
|
|
44
|
+
var EVALUATION_ATTRS = {
|
|
45
|
+
NAME: "gen_ai.evaluation.name",
|
|
46
|
+
SCORE_VALUE: "gen_ai.evaluation.score.value",
|
|
47
|
+
EXPLANATION: "gen_ai.evaluation.explanation",
|
|
48
|
+
EVALUATOR_KIND: "integritystudio.evaluation.evaluator.kind",
|
|
49
|
+
COHORT: "integritystudio.evaluation.cohort",
|
|
50
|
+
PRODUCER: "integritystudio.evaluation.producer",
|
|
51
|
+
/** Semconv's link to the evaluated response when no span of it exists: the judged turn's last API `message.id`. */
|
|
52
|
+
RESPONSE_ID: "gen_ai.response.id",
|
|
53
|
+
/**
|
|
54
|
+
* The judge's own `gen_ai.client.operation` span (OBP21), so Gate 3b can read the judge model off it.
|
|
55
|
+
* A vendor link, never the event's parent: semconv parents the event to the operation evaluated, and the judge call is not that.
|
|
56
|
+
*/
|
|
57
|
+
JUDGE_TRACE_ID: "integritystudio.evaluation.judge.trace_id",
|
|
58
|
+
JUDGE_SPAN_ID: "integritystudio.evaluation.judge.span_id",
|
|
59
|
+
/** Which turn an LLM judge scored (G3B1): index plus `userText` hash, never the text. */
|
|
60
|
+
TURN_INDEX: "integritystudio.evaluation.turn.index",
|
|
61
|
+
TURN_USER_TEXT_HASH: "integritystudio.evaluation.turn.user_text_hash",
|
|
62
|
+
META_ORIGINAL_EVALUATION: "integritystudio.meta.original_evaluation",
|
|
63
|
+
/** Content-derived, written on both the file and log-event copies so ingest keeps whichever arrives first (HDF12). */
|
|
64
|
+
ID: "integritystudio.evaluation.id"
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// lib/quality/quality-signals.ts
|
|
68
|
+
import { createHash } from "node:crypto";
|
|
69
|
+
init_esm();
|
|
70
|
+
var QUALITY_METRIC_NAMES = {
|
|
71
|
+
TOOL_CORRECTNESS: "integritystudio.llm.tool.correctness",
|
|
72
|
+
COHERENCE_HEURISTIC: "integritystudio.llm.output.coherence_heuristic",
|
|
73
|
+
TASK_COMPLETION: "integritystudio.llm.task.completion",
|
|
74
|
+
EVALUATION_LATENCY: "integritystudio.evaluation.latency",
|
|
75
|
+
LLM_RELEVANCE: "integritystudio.llm.judge.relevance",
|
|
76
|
+
LLM_COHERENCE: "integritystudio.llm.judge.coherence",
|
|
77
|
+
LLM_EXPLANATION_QUALITY: "integritystudio.llm.judge.explanation_quality",
|
|
78
|
+
LLM_JUDGE_FAILURES: "integritystudio.quality.llm_judge_failures",
|
|
79
|
+
EVAL_WRITE_FAILURES: "integritystudio.quality.eval_write_failures",
|
|
80
|
+
META_EVAL_ARM_UNAVAILABLE: "integritystudio.quality.meta_eval_arm_unavailable"
|
|
81
|
+
};
|
|
82
|
+
function recordRuleMetric(...[name, value, labels, options]) {
|
|
83
|
+
recordMetric(name, value, { ...labels, [EVALUATION_ATTRS.EVALUATOR_KIND]: EVALUATOR_KIND.RULE }, options);
|
|
84
|
+
}
|
|
85
|
+
function emitToolCorrectness(success, toolName, sessionId) {
|
|
86
|
+
recordRuleMetric(QUALITY_METRIC_NAMES.TOOL_CORRECTNESS, success ? 1 : 0, {
|
|
87
|
+
[GENAI_TOOL_NAME_ATTR]: toolName,
|
|
88
|
+
[SESSION_ATTRIBUTES.SESSION_ID]: sessionId
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
var COHERENCE_SCORES = {
|
|
92
|
+
EMPTY: 0,
|
|
93
|
+
TRUNCATED: 0.3,
|
|
94
|
+
BASE: 0.5,
|
|
95
|
+
BONUS_STRUCTURE: 0.2,
|
|
96
|
+
BONUS_CODE: 0.15,
|
|
97
|
+
BONUS_ACTIONS: 0.15,
|
|
98
|
+
MAX: 1
|
|
99
|
+
};
|
|
100
|
+
var EMPTY_OUTPUT_THRESHOLD = 50;
|
|
101
|
+
var STRUCTURE_PATTERN = /^#+\s|^\|.*\|/m;
|
|
102
|
+
var CODE_FENCE_PATTERN = /```/;
|
|
103
|
+
var ACTION_PATTERN = /\b(TODO|FIXME|Action|Recommend)\b/i;
|
|
104
|
+
function extractCoherenceSignals(output) {
|
|
105
|
+
const outputSize = output.length;
|
|
106
|
+
const scanSample = boundedScanText(output, "head-tail");
|
|
107
|
+
return {
|
|
108
|
+
hasStructure: STRUCTURE_PATTERN.test(scanSample),
|
|
109
|
+
hasCode: CODE_FENCE_PATTERN.test(scanSample),
|
|
110
|
+
hasActions: ACTION_PATTERN.test(scanSample),
|
|
111
|
+
truncated: output.endsWith("...") || outputSize >= THRESHOLDS.LARGE_OUTPUT_BYTES,
|
|
112
|
+
empty: outputSize < EMPTY_OUTPUT_THRESHOLD,
|
|
113
|
+
outputSize
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function computeCoherenceHeuristic(signals) {
|
|
117
|
+
if (signals.empty) return COHERENCE_SCORES.EMPTY;
|
|
118
|
+
if (signals.truncated) return COHERENCE_SCORES.TRUNCATED;
|
|
119
|
+
let score = COHERENCE_SCORES.BASE;
|
|
120
|
+
if (signals.hasStructure) score += COHERENCE_SCORES.BONUS_STRUCTURE;
|
|
121
|
+
if (signals.hasCode) score += COHERENCE_SCORES.BONUS_CODE;
|
|
122
|
+
if (signals.hasActions) score += COHERENCE_SCORES.BONUS_ACTIONS;
|
|
123
|
+
return Math.min(score, COHERENCE_SCORES.MAX);
|
|
124
|
+
}
|
|
125
|
+
function emitCoherenceHeuristic(signals, agentType, sessionId) {
|
|
126
|
+
recordRuleMetric(QUALITY_METRIC_NAMES.COHERENCE_HEURISTIC, computeCoherenceHeuristic(signals), {
|
|
127
|
+
[AGENT_ATTRS.TYPE]: agentType,
|
|
128
|
+
[SESSION_ATTRIBUTES.SESSION_ID]: sessionId
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function emitTaskCompletion(completionRatio, sessionId) {
|
|
132
|
+
recordRuleMetric(QUALITY_METRIC_NAMES.TASK_COMPLETION, completionRatio, {
|
|
133
|
+
[SESSION_ATTRIBUTES.SESSION_ID]: sessionId
|
|
134
|
+
}, { unit: UNITS.RATIO });
|
|
135
|
+
}
|
|
136
|
+
function emitEvaluationLatency(durationMs, hookName) {
|
|
137
|
+
recordRuleMetric(QUALITY_METRIC_NAMES.EVALUATION_LATENCY, durationMs, {
|
|
138
|
+
[HOOK_NAME_ATTR]: hookName
|
|
139
|
+
}, { unit: UNITS.MILLISECOND });
|
|
140
|
+
}
|
|
141
|
+
var EVALUATION_ID_LENGTH = 32;
|
|
142
|
+
function evaluationId(entry) {
|
|
143
|
+
return createHash("sha256").update(JSON.stringify(entry)).digest("hex").slice(0, EVALUATION_ID_LENGTH);
|
|
144
|
+
}
|
|
145
|
+
function evaluationEventLine(attributes, now) {
|
|
146
|
+
const hrTime = millisToHrTime(now.getTime());
|
|
147
|
+
const serviceName = getServiceName();
|
|
148
|
+
return {
|
|
149
|
+
timestamp: hrTime,
|
|
150
|
+
observedTimestamp: hrTime,
|
|
151
|
+
severityNumber: SeverityNumber.INFO,
|
|
152
|
+
severityText: "INFO",
|
|
153
|
+
eventName: EVALUATION_RESULT_EVENT,
|
|
154
|
+
attributes,
|
|
155
|
+
resource: { serviceName, serviceVersion: SERVICE_VERSION }
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function appendEvaluation(record) {
|
|
159
|
+
const now = /* @__PURE__ */ new Date();
|
|
160
|
+
const entry = {
|
|
161
|
+
timestamp: now.toISOString(),
|
|
162
|
+
name: EVALUATION_RESULT_EVENT,
|
|
163
|
+
attributes: {
|
|
164
|
+
[EVALUATION_ATTRS.NAME]: record.name,
|
|
165
|
+
[EVALUATION_ATTRS.SCORE_VALUE]: record.score,
|
|
166
|
+
[EVALUATION_ATTRS.EVALUATOR_KIND]: record.kind,
|
|
167
|
+
[EVALUATION_ATTRS.COHORT]: record.cohort,
|
|
168
|
+
[EVALUATION_ATTRS.PRODUCER]: record.producer,
|
|
169
|
+
[SESSION_ATTRIBUTES.SESSION_ID]: record.sessionId,
|
|
170
|
+
...record.judgeSpan && {
|
|
171
|
+
[EVALUATION_ATTRS.JUDGE_TRACE_ID]: record.judgeSpan.traceId,
|
|
172
|
+
[EVALUATION_ATTRS.JUDGE_SPAN_ID]: record.judgeSpan.spanId
|
|
173
|
+
},
|
|
174
|
+
...record.turn && {
|
|
175
|
+
[EVALUATION_ATTRS.TURN_INDEX]: record.turn.index,
|
|
176
|
+
[EVALUATION_ATTRS.TURN_USER_TEXT_HASH]: record.turn.userTextHash
|
|
177
|
+
},
|
|
178
|
+
...record.turn?.responseId && { [EVALUATION_ATTRS.RESPONSE_ID]: record.turn.responseId },
|
|
179
|
+
...record.explanation && { [EVALUATION_ATTRS.EXPLANATION]: record.explanation },
|
|
180
|
+
...record.extraAttributes ?? {}
|
|
181
|
+
},
|
|
182
|
+
schemaUrl: EVALUATION_SCHEMA_URL
|
|
183
|
+
};
|
|
184
|
+
const attributes = { ...entry.attributes, [EVALUATION_ATTRS.ID]: evaluationId(entry) };
|
|
185
|
+
try {
|
|
186
|
+
appendTelemetryRecords(LOGS_FILE_PREFIX, [evaluationEventLine(attributes, now)], now);
|
|
187
|
+
} catch {
|
|
188
|
+
recordMetric(QUALITY_METRIC_NAMES.EVAL_WRITE_FAILURES, 1, {
|
|
189
|
+
[EVALUATION_ATTRS.NAME]: record.name,
|
|
190
|
+
[SESSION_ATTRIBUTES.SESSION_ID]: record.sessionId
|
|
191
|
+
}, { unit: UNITS.FAILURE });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export {
|
|
196
|
+
EVALUATOR_KIND,
|
|
197
|
+
EVALUATION_COHORT,
|
|
198
|
+
EVALUATION_ATTRS,
|
|
199
|
+
QUALITY_METRIC_NAMES,
|
|
200
|
+
emitToolCorrectness,
|
|
201
|
+
extractCoherenceSignals,
|
|
202
|
+
emitCoherenceHeuristic,
|
|
203
|
+
emitTaskCompletion,
|
|
204
|
+
emitEvaluationLatency,
|
|
205
|
+
appendEvaluation
|
|
206
|
+
};
|
|
207
|
+
//# sourceMappingURL=chunk-MC75VXMX.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../lib/otel/evaluation-attrs.ts", "../../../lib/quality/quality-signals.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Evaluation attribute keys, evaluator kinds and cohorts (OBP16). No imports, so\n * scripts needing only the names never load `otel.js` (RDB4); `quality-signals.ts`\n * re-exports it. Kind, cohort and producer were one overloaded field until\n * OBP16; `cohort` is now required so it cannot be omitted again.\n */\n\n/** GenAI evaluation event and its `gen_ai.evaluation.*` keys: semantic-conventions-genai, source dated in otel/attributes.ts. */\nexport const EVALUATION_RESULT_EVENT = 'gen_ai.evaluation.result';\n\n/**\n * Stamped on every record (AA3 \u00A7 Migration) so the next rename of an\n * `integritystudio.evaluation.*` key is a `rename_attributes` entry, not a\n * dual-reader. Bump the version and publish a schema file on any rename or\n * removal; mirrored in the toolkit's `dashboard/scripts/eval-record.ts`.\n */\nexport const EVALUATION_SCHEMA_URL = 'https://integritystudio.ai/schemas/evaluation/1.0.0';\n\nexport const EVALUATOR_KIND = {\n RULE: 'rule',\n LLM: 'llm',\n HUMAN: 'human',\n GROUND_TRUTH: 'ground_truth',\n} as const;\n\nexport type EvaluatorKind = (typeof EVALUATOR_KIND)[keyof typeof EVALUATOR_KIND];\n\n/** `CANARY` scores are random by design and must be excluded from any analysis of judge behaviour. */\nexport const EVALUATION_COHORT = {\n NORMAL: 'normal',\n SEED: 'seed',\n CANARY: 'canary',\n BACKFILL: 'backfill',\n} as const;\n\nexport type EvaluationCohort = (typeof EVALUATION_COHORT)[keyof typeof EVALUATION_COHORT];\n\n/** `score.unit` (OBP20) and `judge.model` (OBP22) were removed: every score is [0,1], and the judge span carries the model. */\nexport const EVALUATION_ATTRS = {\n NAME: 'gen_ai.evaluation.name',\n SCORE_VALUE: 'gen_ai.evaluation.score.value',\n EXPLANATION: 'gen_ai.evaluation.explanation',\n EVALUATOR_KIND: 'integritystudio.evaluation.evaluator.kind',\n COHORT: 'integritystudio.evaluation.cohort',\n PRODUCER: 'integritystudio.evaluation.producer',\n /** Semconv's link to the evaluated response when no span of it exists: the judged turn's last API `message.id`. */\n RESPONSE_ID: 'gen_ai.response.id',\n /**\n * The judge's own `gen_ai.client.operation` span (OBP21), so Gate 3b can read the judge model off it.\n * A vendor link, never the event's parent: semconv parents the event to the operation evaluated, and the judge call is not that.\n */\n JUDGE_TRACE_ID: 'integritystudio.evaluation.judge.trace_id',\n JUDGE_SPAN_ID: 'integritystudio.evaluation.judge.span_id',\n /** Which turn an LLM judge scored (G3B1): index plus `userText` hash, never the text. */\n TURN_INDEX: 'integritystudio.evaluation.turn.index',\n TURN_USER_TEXT_HASH: 'integritystudio.evaluation.turn.user_text_hash',\n META_ORIGINAL_EVALUATION: 'integritystudio.meta.original_evaluation',\n /** Content-derived, written on both the file and log-event copies so ingest keeps whichever arrives first (HDF12). */\n ID: 'integritystudio.evaluation.id',\n} as const;\n", "/** T1 rule-based quality signals, and the evaluation record writer. */\n\nimport { createHash } from 'node:crypto';\nimport { SeverityNumber } from '@opentelemetry/api-logs';\nimport { millisToHrTime } from '@opentelemetry/core';\nimport { THRESHOLDS } from '../core/constants.js';\nimport { UNITS } from '../core/units.js';\nimport { AGENT_ATTRS, GENAI_TOOL_NAME_ATTR, HOOK_NAME_ATTR, SESSION_ATTRIBUTES } from '../otel/attributes.js';\nimport {\n EVALUATOR_KIND, type EvaluatorKind, type EvaluationCohort, EVALUATION_ATTRS,\n EVALUATION_RESULT_EVENT, EVALUATION_SCHEMA_URL,\n} from '../otel/evaluation-attrs.js';\nimport { appendTelemetryRecords, LOGS_FILE_PREFIX, type ExportedLog } from '../otel/file-exporters.js';\nimport { recordMetric } from '../otel/otel.js';\nimport { getServiceName, SERVICE_VERSION } from '../otel/service-identity.js';\nimport { boundedScanText } from '../runtime/output-analyzer.js';\n\nexport {\n EVALUATOR_KIND, type EvaluatorKind,\n EVALUATION_COHORT, type EvaluationCohort,\n EVALUATION_ATTRS,\n} from '../otel/evaluation-attrs.js';\n\n// Scores are unitless 0\u20131 indexes (see UNITS); TASK_COMPLETION is a real fraction, unit `1`.\nexport const QUALITY_METRIC_NAMES = {\n TOOL_CORRECTNESS: 'integritystudio.llm.tool.correctness',\n COHERENCE_HEURISTIC: 'integritystudio.llm.output.coherence_heuristic',\n TASK_COMPLETION: 'integritystudio.llm.task.completion',\n EVALUATION_LATENCY: 'integritystudio.evaluation.latency',\n LLM_RELEVANCE: 'integritystudio.llm.judge.relevance',\n LLM_COHERENCE: 'integritystudio.llm.judge.coherence',\n LLM_EXPLANATION_QUALITY: 'integritystudio.llm.judge.explanation_quality',\n LLM_JUDGE_FAILURES: 'integritystudio.quality.llm_judge_failures',\n EVAL_WRITE_FAILURES: 'integritystudio.quality.eval_write_failures',\n META_EVAL_ARM_UNAVAILABLE: 'integritystudio.quality.meta_eval_arm_unavailable',\n} as const;\n\n/** Every T1 signal is rule-scored; stamping the evaluator kind here keeps a new one from omitting it. */\nfunction recordRuleMetric(...[name, value, labels, options]: Parameters<typeof recordMetric>): void {\n recordMetric(name, value, { ...labels, [EVALUATION_ATTRS.EVALUATOR_KIND]: EVALUATOR_KIND.RULE }, options);\n}\n\nexport function emitToolCorrectness(success: boolean, toolName: string, sessionId: string): void {\n recordRuleMetric(QUALITY_METRIC_NAMES.TOOL_CORRECTNESS, success ? 1.0 : 0.0, {\n [GENAI_TOOL_NAME_ATTR]: toolName,\n [SESSION_ATTRIBUTES.SESSION_ID]: sessionId,\n });\n}\n\nexport const COHERENCE_SCORES = {\n EMPTY: 0.0,\n TRUNCATED: 0.3,\n BASE: 0.5,\n BONUS_STRUCTURE: 0.2,\n BONUS_CODE: 0.15,\n BONUS_ACTIONS: 0.15,\n MAX: 1.0,\n} as const;\n\ninterface CoherenceSignals {\n hasStructure: boolean;\n hasCode: boolean;\n hasActions: boolean;\n truncated: boolean;\n empty: boolean;\n outputSize: number;\n}\n\nconst EMPTY_OUTPUT_THRESHOLD = 50;\n\nconst STRUCTURE_PATTERN = /^#+\\s|^\\|.*\\|/m;\nconst CODE_FENCE_PATTERN = /```/;\nconst ACTION_PATTERN = /\\b(TODO|FIXME|Action|Recommend)\\b/i;\n\n/** Pattern scans run on a head+tail sample; size signals use the full output. */\nexport function extractCoherenceSignals(output: string): CoherenceSignals {\n const outputSize = output.length;\n const scanSample = boundedScanText(output, 'head-tail');\n return {\n hasStructure: STRUCTURE_PATTERN.test(scanSample),\n hasCode: CODE_FENCE_PATTERN.test(scanSample),\n hasActions: ACTION_PATTERN.test(scanSample),\n truncated: output.endsWith('...') || outputSize >= THRESHOLDS.LARGE_OUTPUT_BYTES,\n empty: outputSize < EMPTY_OUTPUT_THRESHOLD,\n outputSize,\n };\n}\n\nexport function computeCoherenceHeuristic(signals: CoherenceSignals): number {\n if (signals.empty) return COHERENCE_SCORES.EMPTY;\n if (signals.truncated) return COHERENCE_SCORES.TRUNCATED;\n\n let score = COHERENCE_SCORES.BASE;\n if (signals.hasStructure) score += COHERENCE_SCORES.BONUS_STRUCTURE;\n if (signals.hasCode) score += COHERENCE_SCORES.BONUS_CODE;\n if (signals.hasActions) score += COHERENCE_SCORES.BONUS_ACTIONS;\n\n return Math.min(score, COHERENCE_SCORES.MAX);\n}\n\nexport function emitCoherenceHeuristic(signals: CoherenceSignals, agentType: string, sessionId: string): void {\n recordRuleMetric(QUALITY_METRIC_NAMES.COHERENCE_HEURISTIC, computeCoherenceHeuristic(signals), {\n [AGENT_ATTRS.TYPE]: agentType,\n [SESSION_ATTRIBUTES.SESSION_ID]: sessionId,\n });\n}\n\nexport function emitTaskCompletion(completionRatio: number, sessionId: string): void {\n recordRuleMetric(QUALITY_METRIC_NAMES.TASK_COMPLETION, completionRatio, {\n [SESSION_ATTRIBUTES.SESSION_ID]: sessionId,\n }, { unit: UNITS.RATIO });\n}\n\nexport function emitEvaluationLatency(durationMs: number, hookName: string): void {\n recordRuleMetric(QUALITY_METRIC_NAMES.EVALUATION_LATENCY, durationMs, {\n [HOOK_NAME_ATTR]: hookName,\n }, { unit: UNITS.MILLISECOND });\n}\n\n/** Locates the judged turn without storing its text (G3B1). */\nexport interface JudgedTurnRef {\n index: number;\n userTextHash: string;\n responseId?: string;\n}\n\ninterface EvaluationRecord {\n name: string;\n score: number;\n kind: EvaluatorKind;\n /** No default: an omitted cohort lets canary scores pass as model output (OBP16). */\n cohort: EvaluationCohort;\n producer: string;\n sessionId: string;\n /** Absent for rule-based and canary records. */\n judgeSpan?: { traceId: string; spanId: string };\n /** Absent for rule-based records (G3B1). */\n turn?: JudgedTurnRef;\n explanation?: string;\n extraAttributes?: Record<string, string | number | boolean>;\n}\n\n/** Matches `EVALUATION_ID_LENGTH` in the dashboard's `evaluation-delivery.ts`. */\nconst EVALUATION_ID_LENGTH = 32;\n\ntype EvaluationAttributes = Record<string, string | number | boolean>;\n\n/** The hash input for `evaluationId`; every field is part of the id. */\ninterface EvaluationEntry {\n timestamp: string;\n name: string;\n attributes: EvaluationAttributes;\n schemaUrl: string;\n}\n\n/** Content-derived, one per record. Must be 32 lowercase hex: ingest stores any other shape as a NULL `evaluation_id`. */\nfunction evaluationId(entry: EvaluationEntry): string {\n return createHash('sha256').update(JSON.stringify(entry)).digest('hex').slice(0, EVALUATION_ID_LENGTH);\n}\n\n/** The record as a log event in the exporter's shape (HDF12), appended directly through `appendTelemetryRecords`. */\nfunction evaluationEventLine(attributes: EvaluationAttributes, now: Date): ExportedLog {\n const hrTime = millisToHrTime(now.getTime());\n const serviceName = getServiceName();\n return {\n timestamp: hrTime,\n observedTimestamp: hrTime,\n severityNumber: SeverityNumber.INFO,\n severityText: 'INFO',\n eventName: EVALUATION_RESULT_EVENT,\n attributes,\n resource: { serviceName, serviceVersion: SERVICE_VERSION },\n };\n}\n\nexport function appendEvaluation(record: EvaluationRecord): void {\n const now = new Date();\n\n const entry: EvaluationEntry = {\n timestamp: now.toISOString(),\n name: EVALUATION_RESULT_EVENT,\n attributes: {\n [EVALUATION_ATTRS.NAME]: record.name,\n [EVALUATION_ATTRS.SCORE_VALUE]: record.score,\n [EVALUATION_ATTRS.EVALUATOR_KIND]: record.kind,\n [EVALUATION_ATTRS.COHORT]: record.cohort,\n [EVALUATION_ATTRS.PRODUCER]: record.producer,\n [SESSION_ATTRIBUTES.SESSION_ID]: record.sessionId,\n ...(record.judgeSpan && {\n [EVALUATION_ATTRS.JUDGE_TRACE_ID]: record.judgeSpan.traceId,\n [EVALUATION_ATTRS.JUDGE_SPAN_ID]: record.judgeSpan.spanId,\n }),\n ...(record.turn && {\n [EVALUATION_ATTRS.TURN_INDEX]: record.turn.index,\n [EVALUATION_ATTRS.TURN_USER_TEXT_HASH]: record.turn.userTextHash,\n }),\n ...(record.turn?.responseId && { [EVALUATION_ATTRS.RESPONSE_ID]: record.turn.responseId }),\n ...(record.explanation && { [EVALUATION_ATTRS.EXPLANATION]: record.explanation }),\n ...(record.extraAttributes ?? {}),\n },\n schemaUrl: EVALUATION_SCHEMA_URL,\n };\n const attributes = { ...entry.attributes, [EVALUATION_ATTRS.ID]: evaluationId(entry) };\n\n try {\n // Every cohort ships, canary included; identityKeyRef is a record field, never an attribute (TKR8).\n appendTelemetryRecords(LOGS_FILE_PREFIX, [evaluationEventLine(attributes, now)], now);\n } catch {\n recordMetric(QUALITY_METRIC_NAMES.EVAL_WRITE_FAILURES, 1, {\n [EVALUATION_ATTRS.NAME]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AA,MACA,GAAI,OAAO,QAAQ;AAAA,QACjB,CAAC,iBAAiB,UAAU,GAAG,OAAO,KAAK;AAAA,QAC3C,CAAC,iBAAiB,mBAAmB,GAAG,OAAO,KAAK;AAAA,MACtD;AAAA,MACA,GAAI,OAAO,MAAM,cAAc,EAAE,CAAC,iBAAiB,WAAW,GAAG,OAAO,KAAK,WAAW;AAAA,MACxF,GAAI,OAAO,eAAe,EAAE,CAAC,iBAAiB,WAAW,GAAG,OAAO,YAAY;AAAA,MAC/E,GAAI,OAAO,mBAAmB,CAAC;AAAA,IACjC;AAAA,IACA,WAAW;AAAA,EACb;AACA,QAAM,aAAa,EAAE,GAAG,MAAM,YAAY,CAAC,iBAAiB,EAAE,GAAG,aAAa,KAAK,EAAE;AAErF,MAAI;AAEF,2BAAuB,kBAAkB,CAAC,oBAAoB,YAAY,GAAG,CAAC,GAAG,GAAG;AAAA,EACtF,QAAQ;AACN,iBAAa,qBAAqB,qBAAqB,GAAG;AAAA,MACxD,CAAC,iBAAiB,IAAI,GAAG,OAAO;AAAA,MAChC,CAAC,mBAAmB,UAAU,GAAG,OAAO;AAAA,IAC1C,GAAG,EAAE,MAAM,MAAM,QAAQ,CAAC;AAAA,EAC5B;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { createRequire as __hookRunnerCreateRequire } from 'node:module';
|
|
2
|
+
const require = __hookRunnerCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
AGENT_TOOLS,
|
|
5
|
+
BUILTIN_TOOLS,
|
|
6
|
+
EDIT_TOOLS,
|
|
7
|
+
GIT_COMMIT_SUBCOMMAND,
|
|
8
|
+
MCP_TOOL_PREFIX,
|
|
9
|
+
PLUGIN_TOOLS
|
|
10
|
+
} from "./chunk-52RY6LQT.js";
|
|
11
|
+
|
|
12
|
+
// lib/runtime/tool-input.ts
|
|
13
|
+
import { homedir } from "node:os";
|
|
14
|
+
import { extname, isAbsolute, join, resolve } from "node:path";
|
|
15
|
+
function isEditTool(name) {
|
|
16
|
+
return EDIT_TOOLS.has(name);
|
|
17
|
+
}
|
|
18
|
+
function readString(toolInput, key) {
|
|
19
|
+
const val = toolInput?.[key];
|
|
20
|
+
return typeof val === "string" ? val : void 0;
|
|
21
|
+
}
|
|
22
|
+
function getStringField(input, key) {
|
|
23
|
+
return readString(input.tool_input, key);
|
|
24
|
+
}
|
|
25
|
+
function getScalarText(toolInput, key) {
|
|
26
|
+
const value = toolInput?.[key];
|
|
27
|
+
if (typeof value === "string") return value;
|
|
28
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
29
|
+
return void 0;
|
|
30
|
+
}
|
|
31
|
+
function spawnedAgentType(input) {
|
|
32
|
+
return AGENT_TOOLS.has(input.tool_name ?? "") ? getStringField(input, "subagent_type") : void 0;
|
|
33
|
+
}
|
|
34
|
+
function mayRunGitCommit(input) {
|
|
35
|
+
return input.tool_name === "Bash" && (getStringField(input, "command")?.includes(GIT_COMMIT_SUBCOMMAND) ?? false);
|
|
36
|
+
}
|
|
37
|
+
var LEADING_CD_PATTERN = /^[ \t]*cd[ \t]+(?:"([^"]+)"|'([^']+)'|([^\s;&|]+))[ \t]*(?:&&|;|\n|$)/;
|
|
38
|
+
var UNEXPANDED_TARGET_PATTERN = /[$`\\]|^~[^/]/;
|
|
39
|
+
var HOME_PREFIX = "~";
|
|
40
|
+
function toolWorkingDirectory(input) {
|
|
41
|
+
const target = input.tool_name === "Bash" ? leadingCdTarget(getStringField(input, "command")) : void 0;
|
|
42
|
+
return target ? resolveCdTarget(target, input.cwd) : input.cwd;
|
|
43
|
+
}
|
|
44
|
+
function leadingCdTarget(command) {
|
|
45
|
+
const match = LEADING_CD_PATTERN.exec(command ?? "");
|
|
46
|
+
const target = match?.[1] ?? match?.[2] ?? match?.[3];
|
|
47
|
+
return target === void 0 || target === "-" || UNEXPANDED_TARGET_PATTERN.test(target) ? void 0 : target;
|
|
48
|
+
}
|
|
49
|
+
function resolveCdTarget(target, cwd) {
|
|
50
|
+
if (target === HOME_PREFIX || target.startsWith(`${HOME_PREFIX}/`)) return join(homedir(), target.slice(HOME_PREFIX.length));
|
|
51
|
+
if (isAbsolute(target)) return target;
|
|
52
|
+
return resolve(cwd, target);
|
|
53
|
+
}
|
|
54
|
+
function getTargetPath(toolInput) {
|
|
55
|
+
return readString(toolInput, "file_path") ?? readString(toolInput, "notebook_path");
|
|
56
|
+
}
|
|
57
|
+
function getFileExtension(filePath) {
|
|
58
|
+
return extname(filePath).slice(1);
|
|
59
|
+
}
|
|
60
|
+
function joinMultiEditField(toolInput, field) {
|
|
61
|
+
const edits = Array.isArray(toolInput?.edits) ? toolInput.edits : [];
|
|
62
|
+
return edits.map((e) => e && typeof e === "object" ? e[field] : void 0).filter((s) => typeof s === "string" && s !== "").join("\n");
|
|
63
|
+
}
|
|
64
|
+
function getReplacedText(toolInput, toolName) {
|
|
65
|
+
if (toolName === "MultiEdit") return joinMultiEditField(toolInput, "old_string") || null;
|
|
66
|
+
if (toolName !== "Edit") return null;
|
|
67
|
+
return readString(toolInput, "old_string") || null;
|
|
68
|
+
}
|
|
69
|
+
function writtenText(text, isPartial) {
|
|
70
|
+
return text ? { text, isPartial } : null;
|
|
71
|
+
}
|
|
72
|
+
function getWrittenText(toolInput, toolName) {
|
|
73
|
+
switch (toolName) {
|
|
74
|
+
case "Write":
|
|
75
|
+
return writtenText(readString(toolInput, "content"), false);
|
|
76
|
+
case "Edit":
|
|
77
|
+
return writtenText(readString(toolInput, "new_string"), true);
|
|
78
|
+
case "MultiEdit":
|
|
79
|
+
return writtenText(joinMultiEditField(toolInput, "new_string"), true);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function classifyToolCategory(toolName, subType) {
|
|
83
|
+
if (subType === "mcp" || toolName.startsWith(MCP_TOOL_PREFIX)) return "mcp";
|
|
84
|
+
if (subType === "plugin" || PLUGIN_TOOLS.has(toolName)) return "plugin";
|
|
85
|
+
if (subType === "agent" || AGENT_TOOLS.has(toolName)) return "agent";
|
|
86
|
+
if (subType === "builtin" || BUILTIN_TOOLS.has(toolName)) return "builtin";
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export {
|
|
91
|
+
isEditTool,
|
|
92
|
+
readString,
|
|
93
|
+
getStringField,
|
|
94
|
+
getScalarText,
|
|
95
|
+
spawnedAgentType,
|
|
96
|
+
mayRunGitCommit,
|
|
97
|
+
toolWorkingDirectory,
|
|
98
|
+
getTargetPath,
|
|
99
|
+
getFileExtension,
|
|
100
|
+
getReplacedText,
|
|
101
|
+
getWrittenText,
|
|
102
|
+
classifyToolCategory
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=chunk-NKZU4RRG.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../lib/runtime/tool-input.ts"],
|
|
4
|
+
"sourcesContent": ["/** Tool-input extraction and routing helpers shared by pre-tool and post-tool handlers. */\n\nimport { homedir } from 'node:os';\nimport { extname, isAbsolute, join, resolve } from 'node:path';\nimport { AGENT_TOOLS, BUILTIN_TOOLS, EDIT_TOOLS, GIT_COMMIT_SUBCOMMAND, PLUGIN_TOOLS, type BUILTIN_TOOLS_BY_CATEGORY, MCP_TOOL_PREFIX } from '../core/constants.js';\nimport type { HookInput } from './hook-input.js';\n\n/** The file-mutating tools, derived from the same `file` category row as `EDIT_TOOLS` so neither can drift. */\ntype EditTool = Exclude<(typeof BUILTIN_TOOLS_BY_CATEGORY)['file'][number], 'Read'>;\n\nexport function isEditTool(name: string): name is EditTool {\n return EDIT_TOOLS.has(name);\n}\n\ntype WithToolInput = Pick<HookInput, 'tool_input'>;\n\n/** The raw `tool_input` record every reader below takes. */\nexport type ToolInputRecord = Record<string, unknown> | undefined;\n\ntype ToolCategory = 'mcp' | 'plugin' | 'agent' | 'builtin';\n\n/** String field of a raw `tool_input`; undefined unless already a string, since `String()` yields \"[object Object]\" (CQ-007). */\nexport function readString(toolInput: ToolInputRecord, key: string): string | undefined {\n const val = toolInput?.[key];\n return typeof val === 'string' ? val : undefined;\n}\n\n/** `readString` on a hook payload. */\nexport function getStringField(input: WithToolInput, key: string): string | undefined {\n return readString(input.tool_input, key);\n}\n\n/** Scalar field of a raw `tool_input` as text; objects and arrays are dropped rather than read as \"[object Object]\". */\nexport function getScalarText(toolInput: ToolInputRecord, key: string): string | undefined {\n const value = toolInput?.[key];\n if (typeof value === 'string') return value;\n if (typeof value === 'number' || typeof value === 'boolean') return String(value);\n return undefined;\n}\n\n/** The agent an Agent tool call spawns (`Task` is the pre-rename alias); undefined for every other tool. */\nexport function spawnedAgentType(input: Pick<HookInput, 'tool_name' | 'tool_input'>): string | undefined {\n return AGENT_TOOLS.has(input.tool_name ?? '') ? getStringField(input, 'subagent_type') : undefined;\n}\n\n/** Fast pre-screen for a Bash command that may have committed, before loading `git-commit.ts`. */\nexport function mayRunGitCommit(input: Pick<HookInput, 'tool_name' | 'tool_input'>): boolean {\n return input.tool_name === 'Bash' && (getStringField(input, 'command')?.includes(GIT_COMMIT_SUBCOMMAND) ?? false);\n}\n\n/** `cd <dir>` opening a command and followed by `&&`, `;`, a newline or the end; the target may be quoted. `cd dir || x` is not matched, since that cd may have failed. */\nconst LEADING_CD_PATTERN = /^[ \\t]*cd[ \\t]+(?:\"([^\"]+)\"|'([^']+)'|([^\\s;&|]+))[ \\t]*(?:&&|;|\\n|$)/;\n/** Shell expansion the hook cannot evaluate (`$VAR`, `$(\u2026)`, backticks, escapes, `~user`); such a target falls back to `cwd` rather than becoming a made-up path. */\nconst UNEXPANDED_TARGET_PATTERN = /[$`\\\\]|^~[^/]/;\nconst HOME_PREFIX = '~';\n\n/**\n * Where a tool's work happened: a Bash command's leading `cd` target, else the event's `cwd`.\n * Claude Code resets the shell to the project directory when a `cd` leaves it, so `cwd` alone\n * never shows work done in another repo.\n */\nexport function toolWorkingDirectory(input: Pick<HookInput, 'tool_name' | 'tool_input'> & { cwd: string }): string {\n const target = input.tool_name === 'Bash' ? leadingCdTarget(getStringField(input, 'command')) : undefined;\n return target ? resolveCdTarget(target, input.cwd) : input.cwd;\n}\n\n/** The directory a command's opening `cd` names; undefined for none, or for `cd -`. */\nfunction leadingCdTarget(command: string | undefined): string | undefined {\n const match = LEADING_CD_PATTERN.exec(command ?? '');\n const target = match?.[1] ?? match?.[2] ?? match?.[3];\n return target === undefined || target === '-' || UNEXPANDED_TARGET_PATTERN.test(target) ? undefined : target;\n}\n\nfunction resolveCdTarget(target: string, cwd: string): string {\n if (target === HOME_PREFIX || target.startsWith(`${HOME_PREFIX}/`)) return join(homedir(), target.slice(HOME_PREFIX.length));\n if (isAbsolute(target)) return target;\n return resolve(cwd, target);\n}\n\n/** The file a tool targets: `file_path`, or NotebookEdit's `notebook_path`. */\nexport function getTargetPath(toolInput: ToolInputRecord): string | undefined {\n return readString(toolInput, 'file_path') ?? readString(toolInput, 'notebook_path');\n}\n\n/** Extension without the dot; '' for `Makefile`, dotfiles, or a dot only in a directory name. */\nexport function getFileExtension(filePath: string): string {\n return extname(filePath).slice(1);\n}\n\n/** Non-empty `field` values across a MultiEdit's `edits[]`, joined by newlines; '' when none. */\nfunction joinMultiEditField(toolInput: ToolInputRecord, field: 'old_string' | 'new_string'): string {\n const edits = Array.isArray(toolInput?.edits) ? toolInput.edits : [];\n return (edits as unknown[])\n .map((e) => (e && typeof e === 'object' ? (e as Record<string, unknown>)[field] : undefined))\n .filter((s): s is string => typeof s === 'string' && s !== '')\n .join('\\n');\n}\n\n/** Text an edit tool replaces; null for Write, which replaces a whole file. */\nexport function getReplacedText(toolInput: ToolInputRecord, toolName: EditTool): string | null {\n if (toolName === 'MultiEdit') return joinMultiEditField(toolInput, 'old_string') || null;\n if (toolName !== 'Edit') return null;\n return readString(toolInput, 'old_string') || null;\n}\n\ninterface WrittenText {\n text: string;\n isPartial: boolean;\n}\n\nfunction writtenText(text: string | undefined, isPartial: boolean): WrittenText | null {\n return text ? { text, isPartial } : null;\n}\n\n/**\n * Text written by an edit tool plus whether it is a partial hunk (Write: whole file).\n * Null when the input carries no content; callers gate on {@link isEditTool} (HSF5).\n * The switch is exhaustive over `EditTool`, so a new file tool fails to compile here.\n */\nexport function getWrittenText(toolInput: ToolInputRecord, toolName: EditTool): WrittenText | null {\n switch (toolName) {\n case 'Write': return writtenText(readString(toolInput, 'content'), false);\n case 'Edit': return writtenText(readString(toolInput, 'new_string'), true);\n case 'MultiEdit': return writtenText(joinMultiEditField(toolInput, 'new_string'), true);\n }\n}\n\n/** Routing category (mcp > plugin > agent > builtin, by subType hint or name); null when unrecognised. */\nexport function classifyToolCategory(toolName: string, subType?: string): ToolCategory | null {\n if (subType === 'mcp' || toolName.startsWith(MCP_TOOL_PREFIX)) return 'mcp';\n if (subType === 'plugin' || PLUGIN_TOOLS.has(toolName)) return 'plugin';\n if (subType === 'agent' || AGENT_TOOLS.has(toolName)) return 'agent';\n if (subType === 'builtin' || BUILTIN_TOOLS.has(toolName)) return 'builtin';\n return null;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;AAEA,SAAS,eAAe;AACxB,SAAS,SAAS,YAAY,MAAM,eAAe;AAO5C,SAAS,WAAW,MAAgC;AACzD,SAAO,WAAW,IAAI,IAAI;AAC5B;AAUO,SAAS,WAAW,WAA4B,KAAiC;AACtF,QAAM,MAAM,YAAY,GAAG;AAC3B,SAAO,OAAO,QAAQ,WAAW,MAAM;AACzC;AAGO,SAAS,eAAe,OAAsB,KAAiC;AACpF,SAAO,WAAW,MAAM,YAAY,GAAG;AACzC;AAGO,SAAS,cAAc,WAA4B,KAAiC;AACzF,QAAM,QAAQ,YAAY,GAAG;AAC7B,MAAI,OAAO,UAAU,SAAU,QAAO;AACtC,MAAI,OAAO,UAAU,YAAY,OAAO,UAAU,UAAW,QAAO,OAAO,KAAK;AAChF,SAAO;AACT;AAGO,SAAS,iBAAiB,OAAwE;AACvG,SAAO,YAAY,IAAI,MAA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