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,56 @@
|
|
|
1
|
+
import { createRequire as __hookRunnerCreateRequire } from 'node:module';
|
|
2
|
+
const require = __hookRunnerCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
SESSION_ATTRIBUTES,
|
|
5
|
+
log
|
|
6
|
+
} from "./chunk-7OM5CYES.js";
|
|
7
|
+
import {
|
|
8
|
+
sessionStateDir
|
|
9
|
+
} from "./chunk-DNSTWC26.js";
|
|
10
|
+
import {
|
|
11
|
+
loadJson,
|
|
12
|
+
writeJsonAtomic
|
|
13
|
+
} from "./chunk-52RY6LQT.js";
|
|
14
|
+
|
|
15
|
+
// lib/quality/quality-sampler.ts
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
var SAMPLING_CONFIG = {
|
|
18
|
+
SAMPLE_RATE: 0.05,
|
|
19
|
+
MAX_TURNS_PER_SESSION: 3,
|
|
20
|
+
/** Share of sampled sessions scored by the canary instead of a model. */
|
|
21
|
+
CANARY_RATE: 0.02
|
|
22
|
+
};
|
|
23
|
+
var FLAG_FILE = "quality-flag.json";
|
|
24
|
+
function getFlagPath(sessionId) {
|
|
25
|
+
return join(sessionStateDir(sessionId), FLAG_FILE);
|
|
26
|
+
}
|
|
27
|
+
function readSessionFlag(sessionId) {
|
|
28
|
+
const flag = loadJson(getFlagPath(sessionId));
|
|
29
|
+
if (typeof flag?.sampled !== "boolean") return void 0;
|
|
30
|
+
return { sampled: flag.sampled, canary: flag.canary === true };
|
|
31
|
+
}
|
|
32
|
+
var FLAG_WRITE_FAILED_MESSAGE = "Quality sampling flag not written; the next hook in this session re-rolls";
|
|
33
|
+
function shouldSampleSession(sessionId) {
|
|
34
|
+
const existing = readSessionFlag(sessionId);
|
|
35
|
+
if (existing) return existing.sampled;
|
|
36
|
+
const sampled = Math.random() < SAMPLING_CONFIG.SAMPLE_RATE;
|
|
37
|
+
const flag = {
|
|
38
|
+
sampled,
|
|
39
|
+
canary: sampled && Math.random() < SAMPLING_CONFIG.CANARY_RATE,
|
|
40
|
+
decidedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
41
|
+
};
|
|
42
|
+
if (!writeJsonAtomic(getFlagPath(sessionId), flag, { silent: true })) {
|
|
43
|
+
log("WARN", FLAG_WRITE_FAILED_MESSAGE, { [SESSION_ATTRIBUTES.SESSION_ID]: sessionId });
|
|
44
|
+
}
|
|
45
|
+
return sampled;
|
|
46
|
+
}
|
|
47
|
+
function getSessionSamplingInfo(sessionId) {
|
|
48
|
+
return readSessionFlag(sessionId) ?? { sampled: false, canary: false };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export {
|
|
52
|
+
SAMPLING_CONFIG,
|
|
53
|
+
shouldSampleSession,
|
|
54
|
+
getSessionSamplingInfo
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=chunk-PJHWHJ3K.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../lib/quality/quality-sampler.ts"],
|
|
4
|
+
"sourcesContent": ["/** T2 session sampling decision, persisted so every hook in the session reuses it. */\n\nimport { join } from 'node:path';\nimport { loadJson, writeJsonAtomic } from '../core/file-utils.js';\nimport { SESSION_ATTRIBUTES } from '../otel/attributes.js';\nimport { log } from '../otel/otel.js';\nimport { sessionStateDir } from '../session/session-state.js';\n\nexport const SAMPLING_CONFIG = {\n SAMPLE_RATE: 0.05,\n MAX_TURNS_PER_SESSION: 3,\n /** Share of sampled sessions scored by the canary instead of a model. */\n CANARY_RATE: 0.02,\n} as const;\n\nconst FLAG_FILE = 'quality-flag.json';\n\ninterface SessionFlag {\n sampled: boolean;\n canary: boolean;\n decidedAt: string;\n}\n\nfunction getFlagPath(sessionId: string): string {\n return join(sessionStateDir(sessionId), FLAG_FILE);\n}\n\n/** A flag without a boolean `sampled` is treated like an unreadable one. */\nfunction readSessionFlag(sessionId: string): Pick<SessionFlag, 'sampled' | 'canary'> | undefined {\n const flag = loadJson<Partial<SessionFlag>>(getFlagPath(sessionId));\n if (typeof flag?.sampled !== 'boolean') return undefined;\n return { sampled: flag.sampled, canary: flag.canary === true };\n}\n\nexport const FLAG_WRITE_FAILED_MESSAGE = 'Quality sampling flag not written; the next hook in this session re-rolls';\n\nexport function shouldSampleSession(sessionId: string): boolean {\n const existing = readSessionFlag(sessionId);\n if (existing) return existing.sampled;\n\n const sampled = Math.random() < SAMPLING_CONFIG.SAMPLE_RATE;\n const flag: SessionFlag = {\n sampled,\n canary: sampled && Math.random() < SAMPLING_CONFIG.CANARY_RATE,\n decidedAt: new Date().toISOString(),\n };\n // Silent on stderr, which hooks must keep clean; the warn log carries the failure instead.\n if (!writeJsonAtomic(getFlagPath(sessionId), flag, { silent: true })) {\n log('WARN', FLAG_WRITE_FAILED_MESSAGE, { [SESSION_ATTRIBUTES.SESSION_ID]: sessionId });\n }\n return sampled;\n}\n\nexport function getSessionSamplingInfo(sessionId: string): { sampled: boolean; canary: boolean } {\n return readSessionFlag(sessionId) ?? { sampled: false, canary: false };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;AAEA,SAAS,YAAY;AAMd,IAAM,kBAAkB;AAAA,EAC7B,aAAa;AAAA,EACb,uBAAuB;AAAA;AAAA,EAEvB,aAAa;AACf;AAEA,IAAM,YAAY;AAQlB,SAAS,YAAY,WAA2B;AAC9C,SAAO,KAAK,gBAAgB,SAAS,GAAG,SAAS;AACnD;AAGA,SAAS,gBAAgB,WAAwE;AAC/F,QAAM,OAAO,SAA+B,YAAY,SAAS,CAAC;AAClE,MAAI,OAAO,MAAM,YAAY,UAAW,QAAO;AAC/C,SAAO,EAAE,SAAS,KAAK,SAAS,QAAQ,KAAK,WAAW,KAAK;AAC/D;AAEO,IAAM,4BAA4B;AAElC,SAAS,oBAAoB,WAA4B;AAC9D,QAAM,WAAW,gBAAgB,SAAS;AAC1C,MAAI,SAAU,QAAO,SAAS;AAE9B,QAAM,UAAU,KAAK,OAAO,IAAI,gBAAgB;AAChD,QAAM,OAAoB;AAAA,IACxB;AAAA,IACA,QAAQ,WAAW,KAAK,OAAO,IAAI,gBAAgB;AAAA,IACnD,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,EACpC;AAEA,MAAI,CAAC,gBAAgB,YAAY,SAAS,GAAG,MAAM,EAAE,QAAQ,KAAK,CAAC,GAAG;AACpE,QAAI,QAAQ,2BAA2B,EAAE,CAAC,mBAAmB,UAAU,GAAG,UAAU,CAAC;AAAA,EACvF;AACA,SAAO;AACT;AAEO,SAAS,uBAAuB,WAA0D;AAC/F,SAAO,gBAAgB,SAAS,KAAK,EAAE,SAAS,OAAO,QAAQ,MAAM;AACvE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { createRequire as __hookRunnerCreateRequire } from 'node:module';
|
|
2
|
+
const require = __hookRunnerCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
claudeJsonPath
|
|
5
|
+
} from "./chunk-GG2I4TGI.js";
|
|
6
|
+
import {
|
|
7
|
+
sessionStateDir
|
|
8
|
+
} from "./chunk-DNSTWC26.js";
|
|
9
|
+
import {
|
|
10
|
+
CLAUDE_HOME,
|
|
11
|
+
findUp,
|
|
12
|
+
loadJson,
|
|
13
|
+
writeJson
|
|
14
|
+
} from "./chunk-52RY6LQT.js";
|
|
15
|
+
|
|
16
|
+
// lib/mcp/mcp-config.ts
|
|
17
|
+
import { createHash } from "node:crypto";
|
|
18
|
+
import { basename, join, sep } from "node:path";
|
|
19
|
+
var MCP_CONFIG_FILENAME = ".mcp.json";
|
|
20
|
+
var MCP_SERVERS_ROOT = join(CLAUDE_HOME, "mcp-servers");
|
|
21
|
+
var mcpConfigCache = null;
|
|
22
|
+
function readServers(filePath, into) {
|
|
23
|
+
const config = loadJson(filePath);
|
|
24
|
+
if (!config?.mcpServers) return false;
|
|
25
|
+
for (const [name, serverConfig] of Object.entries(config.mcpServers)) {
|
|
26
|
+
into.set(name, serverConfig);
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
function loadMcpConfigs(cwd) {
|
|
31
|
+
const currentCwd = cwd || process.cwd();
|
|
32
|
+
if (mcpConfigCache?.cwd === currentCwd) {
|
|
33
|
+
return mcpConfigCache;
|
|
34
|
+
}
|
|
35
|
+
const globalServers = /* @__PURE__ */ new Map();
|
|
36
|
+
const projectServers = /* @__PURE__ */ new Map();
|
|
37
|
+
const userServers = /* @__PURE__ */ new Map();
|
|
38
|
+
readServers(join(CLAUDE_HOME, MCP_CONFIG_FILENAME), globalServers);
|
|
39
|
+
readServers(claudeJsonPath(), userServers);
|
|
40
|
+
const userMcpPaths = [
|
|
41
|
+
join(CLAUDE_HOME, "mcp_config.json"),
|
|
42
|
+
join(CLAUDE_HOME, "config", "mcp_config.json")
|
|
43
|
+
];
|
|
44
|
+
for (const userMcpPath of userMcpPaths) {
|
|
45
|
+
readServers(userMcpPath, userServers);
|
|
46
|
+
}
|
|
47
|
+
findUp(currentCwd, (dir) => readServers(join(dir, MCP_CONFIG_FILENAME), projectServers) ? dir : null);
|
|
48
|
+
mcpConfigCache = {
|
|
49
|
+
global: globalServers,
|
|
50
|
+
project: projectServers,
|
|
51
|
+
user: userServers,
|
|
52
|
+
cwd: currentCwd
|
|
53
|
+
};
|
|
54
|
+
return mcpConfigCache;
|
|
55
|
+
}
|
|
56
|
+
function getAllMcpServers(cwd) {
|
|
57
|
+
const configs = loadMcpConfigs(cwd);
|
|
58
|
+
return new Map([...configs.global, ...configs.user, ...configs.project]);
|
|
59
|
+
}
|
|
60
|
+
var CWD_HASH_HEX_CHARS = 8;
|
|
61
|
+
function cwdHash(cwd) {
|
|
62
|
+
return createHash("md5").update(cwd).digest("hex").slice(0, CWD_HASH_HEX_CHARS);
|
|
63
|
+
}
|
|
64
|
+
function scopeCachePath(sessionId, cwd) {
|
|
65
|
+
return join(sessionStateDir(sessionId), `mcp-scope-${cwdHash(cwd)}.json`);
|
|
66
|
+
}
|
|
67
|
+
function loadScopeCache(sessionId, cwd) {
|
|
68
|
+
const entry = loadJson(scopeCachePath(sessionId, cwd));
|
|
69
|
+
return entry?.cwd === cwd ? entry.scopes : null;
|
|
70
|
+
}
|
|
71
|
+
function buildAndPersistScopeCache(sessionId, cwd) {
|
|
72
|
+
const configs = loadMcpConfigs(cwd);
|
|
73
|
+
const scopes = {};
|
|
74
|
+
for (const name of configs.project.keys()) scopes[name] = "project";
|
|
75
|
+
for (const name of configs.user.keys()) if (!(name in scopes)) scopes[name] = "user";
|
|
76
|
+
for (const name of configs.global.keys()) if (!(name in scopes)) scopes[name] = "global";
|
|
77
|
+
writeJson(scopeCachePath(sessionId, cwd), { cwd, scopes });
|
|
78
|
+
return scopes;
|
|
79
|
+
}
|
|
80
|
+
function getMcpScopeCached(serverName, sessionId, cwd) {
|
|
81
|
+
const cached = loadScopeCache(sessionId, cwd);
|
|
82
|
+
const scopes = cached ?? buildAndPersistScopeCache(sessionId, cwd);
|
|
83
|
+
return scopes[serverName] ?? "unknown";
|
|
84
|
+
}
|
|
85
|
+
function serverCheckoutDir(config) {
|
|
86
|
+
for (const part of [config.command, ...config.args ?? []]) {
|
|
87
|
+
if (part?.startsWith(MCP_SERVERS_ROOT + sep)) {
|
|
88
|
+
const firstSegment = part.slice(MCP_SERVERS_ROOT.length + 1).split(sep)[0];
|
|
89
|
+
if (firstSegment) return join(MCP_SERVERS_ROOT, firstSegment);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return void 0;
|
|
93
|
+
}
|
|
94
|
+
function getProjectMismatchPatterns(cwd) {
|
|
95
|
+
const patterns = [];
|
|
96
|
+
for (const config of getAllMcpServers(cwd).values()) {
|
|
97
|
+
const dir = serverCheckoutDir(config);
|
|
98
|
+
if (dir && !patterns.some((p) => p.path === dir)) {
|
|
99
|
+
patterns.push({ path: dir, project: basename(dir) });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
patterns.push(
|
|
103
|
+
{ path: MCP_SERVERS_ROOT, project: ".claude (or specific MCP project)" },
|
|
104
|
+
{ path: CLAUDE_HOME, project: ".claude" }
|
|
105
|
+
);
|
|
106
|
+
return patterns;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export {
|
|
110
|
+
getAllMcpServers,
|
|
111
|
+
getMcpScopeCached,
|
|
112
|
+
getProjectMismatchPatterns
|
|
113
|
+
};
|
|
114
|
+
//# sourceMappingURL=chunk-RIGVYJ2O.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../lib/mcp/mcp-config.ts"],
|
|
4
|
+
"sourcesContent": ["/** MCP config loading and scope detection; per-scope maps hold full server definitions so mcp-status.ts shares the cache. */\n\nimport { createHash } from 'node:crypto';\nimport { basename, join, sep } from 'node:path';\nimport { CLAUDE_HOME } from '../core/constants.js';\nimport { findUp, loadJson, writeJson } from '../core/file-utils.js';\nimport { claudeJsonPath } from '../core/identity-key-resolver.js';\nimport { sessionStateDir } from '../session/session-state.js';\n\nexport type McpScope = 'global' | 'project' | 'user' | 'unknown';\n\nconst MCP_CONFIG_FILENAME = '.mcp.json';\n\n/** Directory holding in-repo MCP server checkouts (e.g. observability-toolkit). */\nconst MCP_SERVERS_ROOT = join(CLAUDE_HOME, 'mcp-servers');\n\n/** Server definition as it appears under `mcpServers` in an MCP config file. */\nexport interface McpServerConfig {\n command?: string;\n args?: string[];\n type?: string;\n url?: string;\n description?: string;\n}\n\ninterface McpConfig {\n mcpServers?: Record<string, McpServerConfig>;\n}\n\ninterface McpConfigCache {\n global: Map<string, McpServerConfig>;\n project: Map<string, McpServerConfig>;\n user: Map<string, McpServerConfig>;\n cwd: string;\n}\n\nlet mcpConfigCache: McpConfigCache | null = null;\n\n/** @returns true if the file declared `mcpServers`: the project walk stops on the nearest file that does. */\nfunction readServers(filePath: string, into: Map<string, McpServerConfig>): boolean {\n const config = loadJson<McpConfig>(filePath);\n if (!config?.mcpServers) return false;\n for (const [name, serverConfig] of Object.entries(config.mcpServers)) {\n into.set(name, serverConfig);\n }\n return true;\n}\n\nfunction loadMcpConfigs(cwd?: string): McpConfigCache {\n const currentCwd = cwd || process.cwd();\n\n if (mcpConfigCache?.cwd === currentCwd) {\n return mcpConfigCache;\n }\n\n const globalServers = new Map<string, McpServerConfig>();\n const projectServers = new Map<string, McpServerConfig>();\n const userServers = new Map<string, McpServerConfig>();\n\n readServers(join(CLAUDE_HOME, MCP_CONFIG_FILENAME), globalServers);\n\n // `claudeJsonPath` holds servers from `claude mcp add`, which appear in no `.mcp.json`;\n // read first so mcp_config.json candidates win on a name collision.\n readServers(claudeJsonPath(), userServers);\n const userMcpPaths = [\n join(CLAUDE_HOME, 'mcp_config.json'),\n join(CLAUDE_HOME, 'config', 'mcp_config.json'),\n ];\n for (const userMcpPath of userMcpPaths) {\n readServers(userMcpPath, userServers);\n }\n\n findUp(currentCwd, dir => readServers(join(dir, MCP_CONFIG_FILENAME), projectServers) ? dir : null);\n\n mcpConfigCache = {\n global: globalServers,\n project: projectServers,\n user: userServers,\n cwd: currentCwd,\n };\n\n return mcpConfigCache;\n}\n\n/** Every configured server keyed by name; project > user > global. Fresh copy. */\nexport function getAllMcpServers(cwd?: string): Map<string, McpServerConfig> {\n const configs = loadMcpConfigs(cwd);\n return new Map([...configs.global, ...configs.user, ...configs.project]);\n}\n\nexport function clearMcpConfigCache(): void {\n mcpConfigCache = null;\n}\n\n// Session-scoped scope cache (PT5): the in-memory cache never warms across spawn-per-event\n// processes, so the resolved server\u2192scope map is persisted to disk per (session, cwd).\n\ntype ScopeDiskEntry = { cwd: string; scopes: Record<string, McpScope> };\n\nconst CWD_HASH_HEX_CHARS = 8;\n\n/** Not a security boundary; it only distinguishes `~/a/web` from `~/b/web` in a filename. */\nfunction cwdHash(cwd: string): string {\n return createHash('md5').update(cwd).digest('hex').slice(0, CWD_HASH_HEX_CHARS);\n}\n\nfunction scopeCachePath(sessionId: string, cwd: string): string {\n return join(sessionStateDir(sessionId), `mcp-scope-${cwdHash(cwd)}.json`);\n}\n\n/** Persisted scope map for this (session, cwd), or null on miss. */\nfunction loadScopeCache(sessionId: string, cwd: string): Record<string, McpScope> | null {\n const entry = loadJson<ScopeDiskEntry>(scopeCachePath(sessionId, cwd));\n return entry?.cwd === cwd ? entry.scopes : null;\n}\n\n/** Compute and persist the scope map; fails open on write error. */\nfunction buildAndPersistScopeCache(sessionId: string, cwd: string): Record<string, McpScope> {\n const configs = loadMcpConfigs(cwd);\n const scopes: Record<string, McpScope> = {};\n\n for (const name of configs.project.keys()) scopes[name] = 'project';\n for (const name of configs.user.keys()) if (!(name in scopes)) scopes[name] = 'user';\n for (const name of configs.global.keys()) if (!(name in scopes)) scopes[name] = 'global';\n\n writeJson(scopeCachePath(sessionId, cwd), { cwd, scopes } satisfies ScopeDiskEntry);\n return scopes;\n}\n\n/** Scope lookup backed by the persisted map; falls back to the live walk when unreadable. */\nexport function getMcpScopeCached(serverName: string, sessionId: string, cwd: string): McpScope {\n const cached = loadScopeCache(sessionId, cwd);\n const scopes = cached ?? buildAndPersistScopeCache(sessionId, cwd);\n return scopes[serverName] ?? 'unknown';\n}\n\n/** A path fragment that, appearing in a \"not found\" error, names the project to activate. */\nexport interface ProjectMismatchPattern {\n path: string;\n project: string;\n}\n\n/** In-repo checkout directory a server runs from; undefined for remote/npx/uvx servers. */\nfunction serverCheckoutDir(config: McpServerConfig): string | undefined {\n for (const part of [config.command, ...(config.args ?? [])]) {\n if (part?.startsWith(MCP_SERVERS_ROOT + sep)) {\n const firstSegment = part.slice(MCP_SERVERS_ROOT.length + 1).split(sep)[0];\n if (firstSegment) return join(MCP_SERVERS_ROOT, firstSegment);\n }\n }\n return undefined;\n}\n\n/**\n * Path\u2192project table for \"wrong project activated\" errors, derived from configured\n * servers (PT6). Most-specific first: checkout dirs, mcp-servers root, CLAUDE_HOME\n * (bare '/hooks' fragments matched unrelated repos). Project name = checkout basename.\n */\nexport function getProjectMismatchPatterns(cwd?: string): ProjectMismatchPattern[] {\n const patterns: ProjectMismatchPattern[] = [];\n for (const config of getAllMcpServers(cwd).values()) {\n const dir = serverCheckoutDir(config);\n if (dir && !patterns.some((p) => p.path === dir)) {\n patterns.push({ path: dir, project: basename(dir) });\n }\n }\n patterns.push(\n { path: MCP_SERVERS_ROOT, project: '.claude (or specific MCP project)' },\n { path: CLAUDE_HOME, project: '.claude' }\n );\n return patterns;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;AAEA,SAAS,kBAAkB;AAC3B,SAAS,UAAU,MAAM,WAAW;AAQpC,IAAM,sBAAsB;AAG5B,IAAM,mBAAmB,KAAK,aAAa,aAAa;AAsBxD,IAAI,iBAAwC;AAG5C,SAAS,YAAY,UAAkB,MAA6C;AAClF,QAAM,SAAS,SAAoB,QAAQ;AAC3C,MAAI,CAAC,QAAQ,WAAY,QAAO;AAChC,aAAW,CAAC,MAAM,YAAY,KAAK,OAAO,QAAQ,OAAO,UAAU,GAAG;AACpE,SAAK,IAAI,MAAM,YAAY;AAAA,EAC7B;AACA,SAAO;AACT;AAEA,SAAS,eAAe,KAA8B;AACpD,QAAM,aAAa,OAAO,QAAQ,IAAI;AAEtC,MAAI,gBAAgB,QAAQ,YAAY;AACtC,WAAO;AAAA,EACT;AAEA,QAAM,gBAAgB,oBAAI,IAA6B;AACvD,QAAM,iBAAiB,oBAAI,IAA6B;AACxD,QAAM,cAAc,oBAAI,IAA6B;AAErD,cAAY,KAAK,aAAa,mBAAmB,GAAG,aAAa;AAIjE,cAAY,eAAe,GAAG,WAAW;AACzC,QAAM,eAAe;AAAA,IACnB,KAAK,aAAa,iBAAiB;AAAA,IACnC,KAAK,aAAa,UAAU,iBAAiB;AAAA,EAC/C;AACA,aAAW,eAAe,cAAc;AACtC,gBAAY,aAAa,WAAW;AAAA,EACtC;AAEA,SAAO,YAAY,SAAO,YAAY,KAAK,KAAK,mBAAmB,GAAG,cAAc,IAAI,MAAM,IAAI;AAElG,mBAAiB;AAAA,IACf,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,MAAM;AAAA,IACN,KAAK;AAAA,EACP;AAEA,SAAO;AACT;AAGO,SAAS,iBAAiB,KAA4C;AAC3E,QAAM,UAAU,eAAe,GAAG;AAClC,SAAO,IAAI,IAAI,CAAC,GAAG,QAAQ,QAAQ,GAAG,QAAQ,MAAM,GAAG,QAAQ,OAAO,CAAC;AACzE;AAWA,IAAM,qBAAqB;AAG3B,SAAS,QAAQ,KAAqB;AACpC,SAAO,WAAW,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,KAAK,EAAE,MAAM,GAAG,kBAAkB;AAChF;AAEA,SAAS,eAAe,WAAmB,KAAqB;AAC9D,SAAO,KAAK,gBAAgB,SAAS,GAAG,aAAa,QAAQ,GAAG,CAAC,OAAO;AAC1E;AAGA,SAAS,eAAe,WAAmB,KAA8C;AACvF,QAAM,QAAQ,SAAyB,eAAe,WAAW,GAAG,CAAC;AACrE,SAAO,OAAO,QAAQ,MAAM,MAAM,SAAS;AAC7C;AAGA,SAAS,0BAA0B,WAAmB,KAAuC;AAC3F,QAAM,UAAU,eAAe,GAAG;AAClC,QAAM,SAAmC,CAAC;AAE1C,aAAW,QAAQ,QAAQ,QAAQ,KAAK,EAAG,QAAO,IAAI,IAAI;AAC1D,aAAW,QAAQ,QAAQ,KAAK,KAAK,EAAG,KAAI,EAAE,QAAQ,QAAS,QAAO,IAAI,IAAI;AAC9E,aAAW,QAAQ,QAAQ,OAAO,KAAK,EAAG,KAAI,EAAE,QAAQ,QAAS,QAAO,IAAI,IAAI;AAEhF,YAAU,eAAe,WAAW,GAAG,GAAG,EAAE,KAAK,OAAO,CAA0B;AAClF,SAAO;AACT;AAGO,SAAS,kBAAkB,YAAoB,WAAmB,KAAuB;AAC9F,QAAM,SAAS,eAAe,WAAW,GAAG;AAC5C,QAAM,SAAS,UAAU,0BAA0B,WAAW,GAAG;AACjE,SAAO,OAAO,UAAU,KAAK;AAC/B;AASA,SAAS,kBAAkB,QAA6C;AACtE,aAAW,QAAQ,CAAC,OAAO,SAAS,GAAI,OAAO,QAAQ,CAAC,CAAE,GAAG;AAC3D,QAAI,MAAM,WAAW,mBAAmB,GAAG,GAAG;AAC5C,YAAM,eAAe,KAAK,MAAM,iBAAiB,SAAS,CAAC,EAAE,MAAM,GAAG,EAAE,CAAC;AACzE,UAAI,aAAc,QAAO,KAAK,kBAAkB,YAAY;AAAA,IAC9D;AAAA,EACF;AACA,SAAO;AACT;AAOO,SAAS,2BAA2B,KAAwC;AACjF,QAAM,WAAqC,CAAC;AAC5C,aAAW,UAAU,iBAAiB,GAAG,EAAE,OAAO,GAAG;AACnD,UAAM,MAAM,kBAAkB,MAAM;AACpC,QAAI,OAAO,CAAC,SAAS,KAAK,CAAC,MAAM,EAAE,SAAS,GAAG,GAAG;AAChD,eAAS,KAAK,EAAE,MAAM,KAAK,SAAS,SAAS,GAAG,EAAE,CAAC;AAAA,IACrD;AAAA,EACF;AACA,WAAS;AAAA,IACP,EAAE,MAAM,kBAAkB,SAAS,oCAAoC;AAAA,IACvE,EAAE,MAAM,aAAa,SAAS,UAAU;AAAA,EAC1C;AACA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { createRequire as __hookRunnerCreateRequire } from 'node:module';
|
|
2
|
+
const require = __hookRunnerCreateRequire(import.meta.url);
|
|
3
|
+
|
|
4
|
+
// lib/core/units.ts
|
|
5
|
+
var TIME_MS = {
|
|
6
|
+
MS: 1,
|
|
7
|
+
SECOND: 1e3,
|
|
8
|
+
MINUTE: 6e4,
|
|
9
|
+
DAY: 864e5,
|
|
10
|
+
WEEK: 6048e5
|
|
11
|
+
};
|
|
12
|
+
var DURATION_MS = {
|
|
13
|
+
THREE_SECONDS: 3e3,
|
|
14
|
+
FIVE_SECONDS: 5e3,
|
|
15
|
+
TEN_SECONDS: 1e4,
|
|
16
|
+
FIFTEEN_SECONDS: 15e3,
|
|
17
|
+
THIRTY_SECONDS: 3e4,
|
|
18
|
+
FIVE_MINUTES: 3e5,
|
|
19
|
+
TEN_MINUTES: 6e5,
|
|
20
|
+
THIRTY_MINUTES: 18e5,
|
|
21
|
+
THREE_DAYS: 2592e5,
|
|
22
|
+
THIRTY_DAYS: 2592e6
|
|
23
|
+
};
|
|
24
|
+
var NANOSECONDS_PER_MILLISECOND = 1e6;
|
|
25
|
+
var PERCENT_PER_UNIT = 100;
|
|
26
|
+
var TENTHS_PER_UNIT = 10;
|
|
27
|
+
function roundTo(value, scale) {
|
|
28
|
+
return Math.round(value * scale) / scale;
|
|
29
|
+
}
|
|
30
|
+
function formatPercent(ratio) {
|
|
31
|
+
return `${(ratio * PERCENT_PER_UNIT).toFixed(0)}%`;
|
|
32
|
+
}
|
|
33
|
+
var KB = 1 << 10;
|
|
34
|
+
var BYTES = {
|
|
35
|
+
KB,
|
|
36
|
+
MB: KB * KB
|
|
37
|
+
// 1,048,576
|
|
38
|
+
};
|
|
39
|
+
var isNonNegativeInteger = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
40
|
+
var isByteCount = (value) => isNonNegativeInteger(value);
|
|
41
|
+
var CHARS_PER_TOKEN = 4;
|
|
42
|
+
function estimateTokenCount(chars) {
|
|
43
|
+
return Math.ceil(chars / CHARS_PER_TOKEN);
|
|
44
|
+
}
|
|
45
|
+
var UNITS = {
|
|
46
|
+
MILLISECOND: "ms",
|
|
47
|
+
/** Seconds, for the `otel.sdk.exporter.*` instruments whose semconv fixes the unit. */
|
|
48
|
+
SECOND: "s",
|
|
49
|
+
BYTE: "By",
|
|
50
|
+
USD: "USD",
|
|
51
|
+
/** Dimensionless fraction — utilization, hit rate, completed/total. */
|
|
52
|
+
RATIO: "1",
|
|
53
|
+
ALERT: "{alert}",
|
|
54
|
+
CHECK: "{check}",
|
|
55
|
+
COMMIT: "{commit}",
|
|
56
|
+
COMPLETION: "{completion}",
|
|
57
|
+
ERROR: "{error}",
|
|
58
|
+
FAILURE: "{failure}",
|
|
59
|
+
FILE: "{file}",
|
|
60
|
+
/** One LLM API response. Unit fixed by `gen_ai.invoke_agent.inference_calls`. */
|
|
61
|
+
INFERENCE_CALL: "{inference_call}",
|
|
62
|
+
INVOCATION: "{invocation}",
|
|
63
|
+
MATCH: "{match}",
|
|
64
|
+
NOTIFICATION: "{notification}",
|
|
65
|
+
REJECTION: "{rejection}",
|
|
66
|
+
RETRY: "{retry}",
|
|
67
|
+
RESULT: "{result}",
|
|
68
|
+
RUN: "{run}",
|
|
69
|
+
SESSION: "{session}",
|
|
70
|
+
SKIP: "{skip}",
|
|
71
|
+
SYNC: "{sync}",
|
|
72
|
+
TASK: "{task}",
|
|
73
|
+
TOKEN: "{token}",
|
|
74
|
+
/** One tool invocation. Unit fixed by `gen_ai.invoke_agent.tool_calls`. */
|
|
75
|
+
TOOL_CALL: "{tool_call}",
|
|
76
|
+
WARNING: "{warning}"
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export {
|
|
80
|
+
TIME_MS,
|
|
81
|
+
DURATION_MS,
|
|
82
|
+
NANOSECONDS_PER_MILLISECOND,
|
|
83
|
+
PERCENT_PER_UNIT,
|
|
84
|
+
TENTHS_PER_UNIT,
|
|
85
|
+
roundTo,
|
|
86
|
+
formatPercent,
|
|
87
|
+
BYTES,
|
|
88
|
+
isNonNegativeInteger,
|
|
89
|
+
isByteCount,
|
|
90
|
+
estimateTokenCount,
|
|
91
|
+
UNITS
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=chunk-RWRGC7ZK.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../lib/core/units.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Unit multipliers, named durations, and OTel instrument unit strings.\n * Use a `DURATION_MS` entry when one matches exactly; otherwise compose from `TIME_MS`.\n */\n\nexport const TIME_MS = {\n MS: 1,\n SECOND: 1_000,\n MINUTE: 60_000,\n DAY: 86_400_000,\n WEEK: 604_800_000,\n} as const;\n\nexport const DURATION_MS = {\n THREE_SECONDS: 3_000,\n FIVE_SECONDS: 5_000,\n TEN_SECONDS: 10_000,\n FIFTEEN_SECONDS: 15_000,\n THIRTY_SECONDS: 30_000,\n FIVE_MINUTES: 300_000,\n TEN_MINUTES: 600_000,\n THIRTY_MINUTES: 1_800_000,\n THREE_DAYS: 259_200_000,\n THIRTY_DAYS: 2_592_000_000,\n} as const;\n\n// OTel HrTime is [seconds, nanoseconds].\nexport const NANOSECONDS_PER_SECOND = 1_000_000_000;\nexport const NANOSECONDS_PER_MILLISECOND = 1_000_000;\n\n// Semconv: \"Instruments for utilization metrics ... SHOULD use the default unit 1\", so percentages divide by this.\nexport const PERCENT_PER_UNIT = 100;\n\n/** Scale for rounding to one decimal place: `roundTo(x, TENTHS_PER_UNIT)`. */\nexport const TENTHS_PER_UNIT = 10;\n\n/** Round to the decimal place `scale` names (10 \u2192 tenths, 100 \u2192 hundredths). */\nexport function roundTo(value: number, scale: number): number {\n return Math.round(value * scale) / scale;\n}\n\n/** A 0\u20131 ratio as a whole-number percentage for banner text, `42%`. */\nexport function formatPercent(ratio: number): string {\n return `${(ratio * PERCENT_PER_UNIT).toFixed(0)}%`;\n}\n\nexport const KB = 1 << 10; // 1024 bytes per KB\n\n/** Binary (1024-based) byte multipliers. */\nexport const BYTES = {\n KB,\n MB: KB * KB, // 1,048,576\n} as const;\n\n/** A count of anything, as persisted state must hold it: a non-negative safe integer. */\nexport const isNonNegativeInteger = (value: unknown): value is number =>\n typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;\n\n/** A file size or read length. */\nexport const isByteCount = (value: number): boolean => isNonNegativeInteger(value);\n\n/** Characters per token: rough estimate used for context-window math. */\nexport const CHARS_PER_TOKEN = 4;\n\n/** One chars-per-token ratio for every estimate (PT7). Never for `gen_ai.usage.*`. */\nexport function estimateTokenCount(chars: number): number {\n return Math.ceil(chars / CHARS_PER_TOKEN);\n}\n\n/**\n * Metric descriptor `unit` per the semconv units rule: UCUM for real dimensions,\n * `1` for dimensionless ratios, a singular `{thing}` annotation for counts.\n * https://opentelemetry.io/docs/specs/semconv/general/metrics/#instrument-units\n *\n * - Arbitrary 0\u20131 scores (judge, tool correctness, structure score) correctly have\n * no unit; `RATIO` is only for genuine fractions.\n * - A metric's unit must match at every call site: instruments are cached by name\n * with first-creation options (`metric-units.test.ts` enforces this).\n */\nexport const UNITS = {\n MILLISECOND: 'ms',\n /** Seconds, for the `otel.sdk.exporter.*` instruments whose semconv fixes the unit. */\n SECOND: 's',\n BYTE: 'By',\n USD: 'USD',\n /** Dimensionless fraction \u2014 utilization, hit rate, completed/total. */\n RATIO: '1',\n\n ALERT: '{alert}',\n CHECK: '{check}',\n COMMIT: '{commit}',\n COMPLETION: '{completion}',\n ERROR: '{error}',\n FAILURE: '{failure}',\n FILE: '{file}',\n /** One LLM API response. Unit fixed by `gen_ai.invoke_agent.inference_calls`. */\n INFERENCE_CALL: '{inference_call}',\n INVOCATION: '{invocation}',\n MATCH: '{match}',\n NOTIFICATION: '{notification}',\n REJECTION: '{rejection}',\n RETRY: '{retry}',\n RESULT: '{result}',\n RUN: '{run}',\n SESSION: '{session}',\n SKIP: '{skip}',\n SYNC: '{sync}',\n TASK: '{task}',\n TOKEN: '{token}',\n /** One tool invocation. Unit fixed by `gen_ai.invoke_agent.tool_calls`. */\n TOOL_CALL: '{tool_call}',\n WARNING: '{warning}',\n} as const;\n"],
|
|
5
|
+
"mappings": ";;;;AAKO,IAAM,UAAU;AAAA,EACrB,IAAI;AAAA,EACJ,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,KAAK;AAAA,EACL,MAAM;AACR;AAEO,IAAM,cAAc;AAAA,EACzB,eAAe;AAAA,EACf,cAAc;AAAA,EACd,aAAa;AAAA,EACb,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,cAAc;AAAA,EACd,aAAa;AAAA,EACb,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ,aAAa;AACf;AAIO,IAAM,8BAA8B;AAGpC,IAAM,mBAAmB;AAGzB,IAAM,kBAAkB;AAGxB,SAAS,QAAQ,OAAe,OAAuB;AAC5D,SAAO,KAAK,MAAM,QAAQ,KAAK,IAAI;AACrC;AAGO,SAAS,cAAc,OAAuB;AACnD,SAAO,IAAI,QAAQ,kBAAkB,QAAQ,CAAC,CAAC;AACjD;AAEO,IAAM,KAAK,KAAK;AAGhB,IAAM,QAAQ;AAAA,EACnB;AAAA,EACA,IAAI,KAAK;AAAA;AACX;AAGO,IAAM,uBAAuB,CAAC,UACnC,OAAO,UAAU,YAAY,OAAO,cAAc,KAAK,KAAK,SAAS;AAGhE,IAAM,cAAc,CAAC,UAA2B,qBAAqB,KAAK;AAG1E,IAAM,kBAAkB;AAGxB,SAAS,mBAAmB,OAAuB;AACxD,SAAO,KAAK,KAAK,QAAQ,eAAe;AAC1C;AAYO,IAAM,QAAQ;AAAA,EACnB,aAAa;AAAA;AAAA,EAEb,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,KAAK;AAAA;AAAA,EAEL,OAAO;AAAA,EAEP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA;AAAA,EAEN,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,cAAc;AAAA,EACd,WAAW;AAAA,EACX,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,KAAK;AAAA,EACL,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA;AAAA,EAEP,WAAW;AAAA,EACX,SAAS;AACX;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { createRequire as __hookRunnerCreateRequire } from 'node:module';
|
|
2
|
+
const require = __hookRunnerCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
GIT_TIMEOUT_MS,
|
|
5
|
+
THRESHOLDS
|
|
6
|
+
} from "./chunk-52RY6LQT.js";
|
|
7
|
+
|
|
8
|
+
// lib/core/child-result.ts
|
|
9
|
+
var MAX_BUFFER_EXCEEDED_CODE = "ERR_CHILD_PROCESS_STDIO_MAXBUFFER";
|
|
10
|
+
function classifyExecError(error) {
|
|
11
|
+
if (!error || typeof error !== "object") return "verdict";
|
|
12
|
+
const e = error;
|
|
13
|
+
if (e.code === MAX_BUFFER_EXCEEDED_CODE) return "output-overflow";
|
|
14
|
+
if (e.killed === true || e.code === "ETIMEDOUT") return "timeout";
|
|
15
|
+
if (e.code === "ENOENT" || e.code === "EACCES") return "not-found";
|
|
16
|
+
return "verdict";
|
|
17
|
+
}
|
|
18
|
+
function settledValue(result) {
|
|
19
|
+
return result.status === "fulfilled" ? result.value : void 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// lib/git/git-exec.ts
|
|
23
|
+
import { execFile, execFileSync } from "node:child_process";
|
|
24
|
+
import { promisify } from "node:util";
|
|
25
|
+
var execFileAsync = promisify(execFile);
|
|
26
|
+
var REMOTE_URL_ARGS = ["remote", "get-url", "origin"];
|
|
27
|
+
function gitArgv(repoRoot, args) {
|
|
28
|
+
return ["-C", repoRoot, "-c", "core.quotePath=false", ...args];
|
|
29
|
+
}
|
|
30
|
+
async function git(repoRoot, args, timeoutMs = GIT_TIMEOUT_MS.HOOK_PATH) {
|
|
31
|
+
const { stdout } = await execFileAsync("git", gitArgv(repoRoot, args), {
|
|
32
|
+
encoding: "utf8",
|
|
33
|
+
timeout: timeoutMs,
|
|
34
|
+
maxBuffer: THRESHOLDS.GIT_MAX_BUFFER_BYTES
|
|
35
|
+
});
|
|
36
|
+
return stdout;
|
|
37
|
+
}
|
|
38
|
+
function gitSync(repoRoot, args, timeoutMs) {
|
|
39
|
+
return execFileSync("git", gitArgv(repoRoot, args), {
|
|
40
|
+
encoding: "utf8",
|
|
41
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
42
|
+
timeout: timeoutMs,
|
|
43
|
+
maxBuffer: THRESHOLDS.GIT_MAX_BUFFER_BYTES
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export {
|
|
48
|
+
classifyExecError,
|
|
49
|
+
settledValue,
|
|
50
|
+
REMOTE_URL_ARGS,
|
|
51
|
+
git,
|
|
52
|
+
gitSync
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=chunk-SRMAJQMV.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../lib/core/child-result.ts", "../../../lib/git/git-exec.ts"],
|
|
4
|
+
"sourcesContent": ["/** Child-process outcome classification shared by every handler that spawns one. */\n\n/**\n * Why a promisified `exec`/`execFile` rejected: 'verdict' is a non-zero exit (and the fallback),\n * 'output-overflow' is past `maxBuffer`, 'not-found' is ENOENT/EACCES.\n */\nexport type ExecOutcome = 'verdict' | 'timeout' | 'output-overflow' | 'not-found';\n\nconst MAX_BUFFER_EXCEEDED_CODE = 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER';\n\nexport function classifyExecError(error: unknown): ExecOutcome {\n if (!error || typeof error !== 'object') return 'verdict';\n const e = error as { killed?: boolean; code?: string | number };\n // Checked before `killed`, which Node also sets on this error.\n if (e.code === MAX_BUFFER_EXCEEDED_CODE) return 'output-overflow';\n if (e.killed === true || e.code === 'ETIMEDOUT') return 'timeout';\n if (e.code === 'ENOENT' || e.code === 'EACCES') return 'not-found';\n return 'verdict';\n}\n\n/** Resolved value of an `allSettled` result, or undefined when it rejected. */\nexport function settledValue<T>(result: PromiseSettledResult<T>): T | undefined {\n return result.status === 'fulfilled' ? result.value : undefined;\n}\n", "/**\n * Thin wrapper around the `git` binary, kept as a leaf module.\n */\n\nimport { execFile, execFileSync } from 'node:child_process';\nimport { promisify } from 'node:util';\nimport { THRESHOLDS, GIT_TIMEOUT_MS } from '../core/constants.js';\n\nconst execFileAsync = promisify(execFile);\n\n/** `git remote get-url origin`: the one remote probe, sync or async. */\nexport const REMOTE_URL_ARGS = ['remote', 'get-url', 'origin'] as const;\n\nfunction gitArgv(repoRoot: string, args: readonly string[]): string[] {\n return ['-C', repoRoot, '-c', 'core.quotePath=false', ...args];\n}\n\n/** `timeoutMs` lets a detached caller exceed the hook-path default. */\nexport async function git(repoRoot: string, args: readonly string[], timeoutMs: number = GIT_TIMEOUT_MS.HOOK_PATH): Promise<string> {\n const { stdout } = await execFileAsync('git', gitArgv(repoRoot, args), {\n encoding: 'utf8',\n timeout: timeoutMs,\n maxBuffer: THRESHOLDS.GIT_MAX_BUFFER_BYTES,\n });\n return stdout;\n}\n\n/** Synchronous `git`, stderr discarded; for the few callers that cannot await. */\nexport function gitSync(repoRoot: string, args: readonly string[], timeoutMs: number): string {\n return execFileSync('git', gitArgv(repoRoot, args), {\n encoding: 'utf8',\n stdio: ['ignore', 'pipe', 'ignore'],\n timeout: timeoutMs,\n maxBuffer: THRESHOLDS.GIT_MAX_BUFFER_BYTES,\n });\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAQA,IAAM,2BAA2B;AAE1B,SAAS,kBAAkB,OAA6B;AAC7D,MAAI,CAAC,SAAS,OAAO,UAAU,SAAU,QAAO;AAChD,QAAM,IAAI;AAEV,MAAI,EAAE,SAAS,yBAA0B,QAAO;AAChD,MAAI,EAAE,WAAW,QAAQ,EAAE,SAAS,YAAa,QAAO;AACxD,MAAI,EAAE,SAAS,YAAY,EAAE,SAAS,SAAU,QAAO;AACvD,SAAO;AACT;AAGO,SAAS,aAAgB,QAAgD;AAC9E,SAAO,OAAO,WAAW,cAAc,OAAO,QAAQ;AACxD;;;ACnBA,SAAS,UAAU,oBAAoB;AACvC,SAAS,iBAAiB;AAG1B,IAAM,gBAAgB,UAAU,QAAQ;AAGjC,IAAM,kBAAkB,CAAC,UAAU,WAAW,QAAQ;AAE7D,SAAS,QAAQ,UAAkB,MAAmC;AACpE,SAAO,CAAC,MAAM,UAAU,MAAM,wBAAwB,GAAG,IAAI;AAC/D;AAGA,eAAsB,IAAI,UAAkB,MAAyB,YAAoB,eAAe,WAA4B;AAClI,QAAM,EAAE,OAAO,IAAI,MAAM,cAAc,OAAO,QAAQ,UAAU,IAAI,GAAG;AAAA,IACrE,UAAU;AAAA,IACV,SAAS;AAAA,IACT,WAAW,WAAW;AAAA,EACxB,CAAC;AACD,SAAO;AACT;AAGO,SAAS,QAAQ,UAAkB,MAAyB,WAA2B;AAC5F,SAAO,aAAa,OAAO,QAAQ,UAAU,IAAI,GAAG;AAAA,IAClD,UAAU;AAAA,IACV,OAAO,CAAC,UAAU,QAAQ,QAAQ;AAAA,IAClC,SAAS;AAAA,IACT,WAAW,WAAW;AAAA,EACxB,CAAC;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createRequire as __hookRunnerCreateRequire } from 'node:module';
|
|
2
|
+
const require = __hookRunnerCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
emitToolCorrectness
|
|
5
|
+
} from "./chunk-MC75VXMX.js";
|
|
6
|
+
import {
|
|
7
|
+
UNKNOWN_ERROR_TYPE
|
|
8
|
+
} from "./chunk-7OM5CYES.js";
|
|
9
|
+
import {
|
|
10
|
+
UNITS
|
|
11
|
+
} from "./chunk-RWRGC7ZK.js";
|
|
12
|
+
|
|
13
|
+
// handlers/post-tool-outcome.ts
|
|
14
|
+
function outcomeSpanAttributes(analysis, keys) {
|
|
15
|
+
return {
|
|
16
|
+
[keys.successAttr]: !analysis.hasError,
|
|
17
|
+
[keys.outputSizeAttr]: analysis.outputSize,
|
|
18
|
+
[keys.hasErrorAttr]: analysis.hasError,
|
|
19
|
+
...analysis.errorType ? { [keys.errorTypeAttr]: analysis.errorType } : {},
|
|
20
|
+
...analysis.errorCategory ? { [keys.errorCategoryAttr]: analysis.errorCategory } : {}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function recordOutcome(ctx, analysis, keys, report) {
|
|
24
|
+
emitToolCorrectness(!analysis.hasError, report.toolName, report.sessionId);
|
|
25
|
+
if (analysis.hasError) {
|
|
26
|
+
const errorType = analysis.errorType ?? UNKNOWN_ERROR_TYPE;
|
|
27
|
+
ctx.logger.warn(report.errorMessage, {
|
|
28
|
+
...report.logLabels,
|
|
29
|
+
[keys.errorTypeAttr]: errorType,
|
|
30
|
+
...report.errorLogExtras ?? {}
|
|
31
|
+
});
|
|
32
|
+
ctx.span.recordException(new Error(report.exceptionMessage));
|
|
33
|
+
} else {
|
|
34
|
+
ctx.logger.info(report.successMessage, { ...report.logLabels, [keys.outputSizeAttr]: analysis.outputSize });
|
|
35
|
+
}
|
|
36
|
+
ctx.recordMetric(keys.completionsMetric, 1, {
|
|
37
|
+
...report.metricLabels,
|
|
38
|
+
[keys.successAttr]: String(!analysis.hasError)
|
|
39
|
+
}, { unit: UNITS.COMPLETION });
|
|
40
|
+
ctx.recordMetric(keys.outputSizeMetric, analysis.outputSize, report.metricLabels, { unit: UNITS.BYTE });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
outcomeSpanAttributes,
|
|
45
|
+
recordOutcome
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=chunk-TRMFD36J.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../handlers/post-tool-outcome.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Shared outcome reporting for PostToolUse handlers.\n * Both builtin and MCP run the same sequence \u2014 emitToolCorrectness, log, completions\n * metric, output-size metric \u2014 keyed on different attribute and metric names.\n * Imported by post-tool.ts and post-tool-mcp.ts; not used elsewhere.\n */\n\nimport type { Attributes } from '@opentelemetry/api';\nimport { UNITS } from '../lib/core/units.js';\nimport { UNKNOWN_ERROR_TYPE } from '../lib/otel/attributes.js';\nimport type { HookContext } from '../lib/otel/otel-monitor.js';\nimport { emitToolCorrectness } from '../lib/quality/quality-signals.js';\nimport type { OutputAnalysis } from '../lib/runtime/output-analyzer.js';\n\n/** Attribute and metric key names that differ between builtin and MCP post-tool handlers. */\nexport interface OutcomeKeys {\n successAttr: string;\n outputSizeAttr: string;\n hasErrorAttr: string;\n errorTypeAttr: string;\n errorCategoryAttr: string;\n completionsMetric: string;\n outputSizeMetric: string;\n}\n\n/**\n * Returns the SUCCESS/OUTPUT_SIZE/HAS_ERROR/ERROR_TYPE/ERROR_CATEGORY fragment\n * for the calling handler's key schema. Spread this into ctx.addAttributes alongside\n * handler-specific keys.\n */\nexport function outcomeSpanAttributes(analysis: OutputAnalysis, keys: OutcomeKeys): Attributes {\n return {\n [keys.successAttr]: !analysis.hasError,\n [keys.outputSizeAttr]: analysis.outputSize,\n [keys.hasErrorAttr]: analysis.hasError,\n ...(analysis.errorType ? { [keys.errorTypeAttr]: analysis.errorType } : {}),\n ...(analysis.errorCategory ? { [keys.errorCategoryAttr]: analysis.errorCategory } : {}),\n };\n}\n\nexport interface OutcomeReport {\n toolName: string;\n sessionId: string;\n /** Base labels for warn and info logs. */\n logLabels: Attributes;\n /** Extra fields merged only into the error warn log (e.g. a remediation suggestion). */\n errorLogExtras?: Attributes;\n /** Labels for the completions and output-size metrics. */\n metricLabels: Attributes;\n successMessage: string;\n errorMessage: string;\n /** Full exception text; callers may append handler-specific context (e.g. a remediation hint). */\n exceptionMessage: string;\n}\n\n/**\n * Runs the shared post-tool outcome sequence: emitToolCorrectness, warn/recordException\n * or info, completions metric, output-size metric. Handler-specific extras (error metrics,\n * completeness records, stderr) run in the caller after this returns.\n */\nexport function recordOutcome(ctx: HookContext, analysis: OutputAnalysis, keys: OutcomeKeys, report: OutcomeReport): void {\n emitToolCorrectness(!analysis.hasError, report.toolName, report.sessionId);\n\n if (analysis.hasError) {\n const errorType = analysis.errorType ?? UNKNOWN_ERROR_TYPE;\n ctx.logger.warn(report.errorMessage, {\n ...report.logLabels,\n [keys.errorTypeAttr]: errorType,\n ...(report.errorLogExtras ?? {}),\n });\n ctx.span.recordException(new Error(report.exceptionMessage));\n } else {\n ctx.logger.info(report.successMessage, { ...report.logLabels, [keys.outputSizeAttr]: analysis.outputSize });\n }\n\n ctx.recordMetric(keys.completionsMetric, 1, {\n ...report.metricLabels,\n [keys.successAttr]: String(!analysis.hasError),\n }, { unit: UNITS.COMPLETION });\n\n ctx.recordMetric(keys.outputSizeMetric, analysis.outputSize, report.metricLabels, { unit: UNITS.BYTE });\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;AA8BO,SAAS,sBAAsB,UAA0B,MAA+B;AAC7F,SAAO;AAAA,IACL,CAAC,KAAK,WAAW,GAAG,CAAC,SAAS;AAAA,IAC9B,CAAC,KAAK,cAAc,GAAG,SAAS;AAAA,IAChC,CAAC,KAAK,YAAY,GAAG,SAAS;AAAA,IAC9B,GAAI,SAAS,YAAY,EAAE,CAAC,KAAK,aAAa,GAAG,SAAS,UAAU,IAAI,CAAC;AAAA,IACzE,GAAI,SAAS,gBAAgB,EAAE,CAAC,KAAK,iBAAiB,GAAG,SAAS,cAAc,IAAI,CAAC;AAAA,EACvF;AACF;AAsBO,SAAS,cAAc,KAAkB,UAA0B,MAAmB,QAA6B;AACxH,sBAAoB,CAAC,SAAS,UAAU,OAAO,UAAU,OAAO,SAAS;AAEzE,MAAI,SAAS,UAAU;AACrB,UAAM,YAAY,SAAS,aAAa;AACxC,QAAI,OAAO,KAAK,OAAO,cAAc;AAAA,MACnC,GAAG,OAAO;AAAA,MACV,CAAC,KAAK,aAAa,GAAG;AAAA,MACtB,GAAI,OAAO,kBAAkB,CAAC;AAAA,IAChC,CAAC;AACD,QAAI,KAAK,gBAAgB,IAAI,MAAM,OAAO,gBAAgB,CAAC;AAAA,EAC7D,OAAO;AACL,QAAI,OAAO,KAAK,OAAO,gBAAgB,EAAE,GAAG,OAAO,WAAW,CAAC,KAAK,cAAc,GAAG,SAAS,WAAW,CAAC;AAAA,EAC5G;AAEA,MAAI,aAAa,KAAK,mBAAmB,GAAG;AAAA,IAC1C,GAAG,OAAO;AAAA,IACV,CAAC,KAAK,WAAW,GAAG,OAAO,CAAC,SAAS,QAAQ;AAAA,EAC/C,GAAG,EAAE,MAAM,MAAM,WAAW,CAAC;AAE7B,MAAI,aAAa,KAAK,kBAAkB,SAAS,YAAY,OAAO,cAAc,EAAE,MAAM,MAAM,KAAK,CAAC;AACxG;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createRequire as __hookRunnerCreateRequire } from 'node:module';
|
|
2
|
+
const require = __hookRunnerCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
__esm
|
|
5
|
+
} from "./chunk-GNNKUMRF.js";
|
|
6
|
+
|
|
7
|
+
// node_modules/@opentelemetry/resources/build/esm/detectors/platform/node/machine-id/execAsync.js
|
|
8
|
+
import * as child_process from "child_process";
|
|
9
|
+
import * as util from "util";
|
|
10
|
+
var execAsync;
|
|
11
|
+
var init_execAsync = __esm({
|
|
12
|
+
"node_modules/@opentelemetry/resources/build/esm/detectors/platform/node/machine-id/execAsync.js"() {
|
|
13
|
+
execAsync = util.promisify(child_process.exec);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
execAsync,
|
|
19
|
+
init_execAsync
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=chunk-U4IOZYQ3.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../node_modules/@opentelemetry/resources/src/detectors/platform/node/machine-id/execAsync.ts"],
|
|
4
|
+
"sourcesContent": ["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport * as child_process from 'child_process';\nimport * as util from 'util';\n\nexport const execAsync = util.promisify(child_process.exec);\n"],
|
|
5
|
+
"mappings": ";;;;;;;AAKA,YAAY,mBAAmB;AAC/B,YAAY,UAAU;AANtB,IAQa;AARb;;AAQO,IAAM,YAAiB,eAAwB,kBAAI;;;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { createRequire as __hookRunnerCreateRequire } from 'node:module';
|
|
2
|
+
const require = __hookRunnerCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
hasOtlpAuth,
|
|
5
|
+
hasUnshippedTelemetry
|
|
6
|
+
} from "./chunk-JRNNLOPR.js";
|
|
7
|
+
import {
|
|
8
|
+
recordShipperStatus,
|
|
9
|
+
shipPreflight
|
|
10
|
+
} from "./chunk-YGFN3LN2.js";
|
|
11
|
+
import {
|
|
12
|
+
canResolveIdentityKey,
|
|
13
|
+
resolveOtlpEndpoint
|
|
14
|
+
} from "./chunk-GG2I4TGI.js";
|
|
15
|
+
import {
|
|
16
|
+
CLAUDE_HOME,
|
|
17
|
+
SHIP_TELEMETRY_ARG,
|
|
18
|
+
TELEMETRY_DIR,
|
|
19
|
+
errorSummary,
|
|
20
|
+
findUp
|
|
21
|
+
} from "./chunk-52RY6LQT.js";
|
|
22
|
+
|
|
23
|
+
// lib/core/detached-runner.ts
|
|
24
|
+
import { spawn } from "node:child_process";
|
|
25
|
+
import { existsSync } from "node:fs";
|
|
26
|
+
import { dirname, join } from "node:path";
|
|
27
|
+
import { fileURLToPath } from "node:url";
|
|
28
|
+
var HOOK_RUNNER_FILE = "hook-runner.js";
|
|
29
|
+
var INSTALLED_RUNNER_PATH = join(CLAUDE_HOME, "hooks", "dist", HOOK_RUNNER_FILE);
|
|
30
|
+
function hookRunnerPath() {
|
|
31
|
+
const ownBuildRunner = findUp(dirname(fileURLToPath(import.meta.url)), (dir) => {
|
|
32
|
+
const candidate = join(dir, HOOK_RUNNER_FILE);
|
|
33
|
+
return existsSync(candidate) ? candidate : null;
|
|
34
|
+
});
|
|
35
|
+
return ownBuildRunner ?? INSTALLED_RUNNER_PATH;
|
|
36
|
+
}
|
|
37
|
+
function spawnDetachedRunner(args, commandPrefix) {
|
|
38
|
+
const runnerPath = hookRunnerPath();
|
|
39
|
+
if (!existsSync(runnerPath)) {
|
|
40
|
+
return { ok: false, reason: "no-runner", detail: runnerPath };
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const nodeArgs = [runnerPath, ...args];
|
|
44
|
+
const fullArgs = commandPrefix ? [...commandPrefix, process.execPath, ...nodeArgs] : [process.execPath, ...nodeArgs];
|
|
45
|
+
const command = fullArgs[0];
|
|
46
|
+
const spawnArgs = fullArgs.slice(1);
|
|
47
|
+
const child = spawn(command, spawnArgs, {
|
|
48
|
+
detached: true,
|
|
49
|
+
stdio: "ignore"
|
|
50
|
+
});
|
|
51
|
+
child.on("error", () => {
|
|
52
|
+
});
|
|
53
|
+
child.unref();
|
|
54
|
+
return { ok: true };
|
|
55
|
+
} catch (error) {
|
|
56
|
+
return { ok: false, reason: "spawn-failed", detail: errorSummary(error) };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// lib/shipper/telemetry-shipper.ts
|
|
61
|
+
function spawnTelemetryShipper() {
|
|
62
|
+
const preflight = shipPreflight({
|
|
63
|
+
// Resolved exactly as `shipTelemetry` resolves it: a spawn guard stricter than
|
|
64
|
+
// the child's silently makes the child's resolution unreachable.
|
|
65
|
+
endpoint: resolveOtlpEndpoint(),
|
|
66
|
+
// Both auth sources, in the child's order, since checking one makes the other unreachable:
|
|
67
|
+
// identity map (TKR3; file-only, the child fetches the key from Doppler), then env auth
|
|
68
|
+
// (OBTOOL_API_KEY / OTLP header vars) for unmapped accounts and `doppler run` scripts.
|
|
69
|
+
hasAuth: () => canResolveIdentityKey() || hasOtlpAuth()
|
|
70
|
+
});
|
|
71
|
+
if ("skipped" in preflight) return;
|
|
72
|
+
if (!hasUnshippedTelemetry(TELEMETRY_DIR)) return;
|
|
73
|
+
const result = spawnDetachedRunner([SHIP_TELEMETRY_ARG]);
|
|
74
|
+
if (!result.ok) {
|
|
75
|
+
recordShipperStatus({ outcome: result.reason, detail: result.detail });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export {
|
|
80
|
+
spawnDetachedRunner,
|
|
81
|
+
spawnTelemetryShipper
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=chunk-UEXDE3WP.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../lib/core/detached-runner.ts", "../../../lib/shipper/telemetry-shipper.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Start `hook-runner.js <args>` as a detached, unref'd child. The environment is inherited\n * (stripped by CLAUDE_CODE_SUBPROCESS_ENV_SCRUB). Pass a `commandPrefix` such as a doppler\n * run command to inject secrets into the child's environment before the node invocation.\n */\n\nimport { spawn } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { CLAUDE_HOME } from './constants.js';\nimport { findUp } from './file-utils.js';\nimport { errorSummary } from './format-utils.js';\n\nconst HOOK_RUNNER_FILE = 'hook-runner.js';\nconst INSTALLED_RUNNER_PATH = join(CLAUDE_HOME, 'hooks', 'dist', HOOK_RUNNER_FILE);\n\n/** This build's own runner; running from source (tests) finds none and falls back. */\nfunction hookRunnerPath(): string {\n const ownBuildRunner = findUp(dirname(fileURLToPath(import.meta.url)), (dir) => {\n const candidate = join(dir, HOOK_RUNNER_FILE);\n return existsSync(candidate) ? candidate : null;\n });\n return ownBuildRunner ?? INSTALLED_RUNNER_PATH;\n}\n\ninterface SpawnOk {\n ok: true;\n}\n\ninterface SpawnFailure {\n ok: false;\n reason: 'no-runner' | 'spawn-failed';\n /** The runner path for `no-runner`; the error summary for `spawn-failed`. */\n detail: string;\n}\n\nexport type SpawnResult = SpawnOk | SpawnFailure;\n\n/**\n * When `commandPrefix` is provided (e.g. `['doppler', 'run', '--project', 'p', '--config', 'c', '--']`),\n * the full command becomes `commandPrefix[0] commandPrefix[1..] node hook-runner.js args`.\n */\nexport function spawnDetachedRunner(args: readonly string[], commandPrefix?: readonly string[]): SpawnResult {\n const runnerPath = hookRunnerPath();\n if (!existsSync(runnerPath)) {\n return { ok: false, reason: 'no-runner', detail: runnerPath };\n }\n try {\n const nodeArgs = [runnerPath, ...args];\n const fullArgs = commandPrefix\n ? [...commandPrefix, process.execPath, ...nodeArgs]\n : [process.execPath, ...nodeArgs];\n const command = fullArgs[0] as string;\n const spawnArgs = fullArgs.slice(1);\n const child = spawn(command, spawnArgs, {\n detached: true,\n stdio: 'ignore',\n });\n // Absorb async ENOENT/EPERM errors; a missing executable emits these after spawn()\n // returns and would otherwise raise an uncaught exception in the Stop hook.\n // Accepted trade-off: spawnDetachedRunner already returned ok:true, so the caller\n // cannot distinguish this from a successful spawn. The binary is a system-level\n // requirement; this listener only prevents a crash, not the silent evaluation drop.\n child.on('error', () => {});\n child.unref();\n return { ok: true };\n } catch (error) {\n return { ok: false, reason: 'spawn-failed', detail: errorSummary(error) };\n }\n}\n", "/**\n * Detached telemetry shipper spawn, shared by Stop, SessionEnd and the quality\n * evaluator. Detached and unref'd on purpose: SessionEnd runs under a\n * hard 1.5 s ceiling for the whole event.\n */\n\nimport { SHIP_TELEMETRY_ARG, TELEMETRY_DIR } from '../core/constants.js';\nimport { spawnDetachedRunner } from '../core/detached-runner.js';\nimport { canResolveIdentityKey } from '../core/identity-key-resolver.js';\nimport { resolveOtlpEndpoint } from '../core/settings-env.js';\nimport { hasOtlpAuth } from '../otel/otlp-headers.js';\nimport { hasUnshippedTelemetry } from './shipper-cursor.js';\nimport { recordShipperStatus, shipPreflight } from './shipper-status.js';\n\n/**\n * Start the detached shipper, or record why not. Every guard is a state in which\n * telemetry stops arriving, so each writes a status record. The spawning path\n * writes nothing (the child owns the outcome), nor does the nothing-to-ship\n * path (HDF2): a stale `updatedAt` means no run was needed, not that shipping is broken.\n */\nexport function spawnTelemetryShipper(): void {\n const preflight = shipPreflight({\n // Resolved exactly as `shipTelemetry` resolves it: a spawn guard stricter than\n // the child's silently makes the child's resolution unreachable.\n endpoint: resolveOtlpEndpoint(),\n // Both auth sources, in the child's order, since checking one makes the other unreachable:\n // identity map (TKR3; file-only, the child fetches the key from Doppler), then env auth\n // (OBTOOL_API_KEY / OTLP header vars) for unmapped accounts and `doppler run` scripts.\n hasAuth: () => canResolveIdentityKey() || hasOtlpAuth(),\n });\n if ('skipped' in preflight) return;\n // Cheap cursor check before a Node boot plus Doppler fetch; SessionEnd right\n // after a Stop is the common empty case. A failed delivery holds the cursor, so it still spawns.\n if (!hasUnshippedTelemetry(TELEMETRY_DIR)) return;\n const result = spawnDetachedRunner([SHIP_TELEMETRY_ARG]);\n if (!result.ok) {\n recordShipperStatus({ outcome: result.reason, detail: result.detail });\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAMA,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAC3B,SAAS,SAAS,YAAY;AAC9B,SAAS,qBAAqB;AAK9B,IAAM,mBAAmB;AACzB,IAAM,wBAAwB,KAAK,aAAa,SAAS,QAAQ,gBAAgB;AAGjF,SAAS,iBAAyB;AAChC,QAAM,iBAAiB,OAAO,QAAQ,cAAc,YAAY,GAAG,CAAC,GAAG,CAAC,QAAQ;AAC9E,UAAM,YAAY,KAAK,KAAK,gBAAgB;AAC5C,WAAO,WAAW,SAAS,IAAI,YAAY;AAAA,EAC7C,CAAC;AACD,SAAO,kBAAkB;AAC3B;AAmBO,SAAS,oBAAoB,MAAyB,eAAgD;AAC3G,QAAM,aAAa,eAAe;AAClC,MAAI,CAAC,WAAW,UAAU,GAAG;AAC3B,WAAO,EAAE,IAAI,OAAO,QAAQ,aAAa,QAAQ,WAAW;AAAA,EAC9D;AACA,MAAI;AACF,UAAM,WAAW,CAAC,YAAY,GAAG,IAAI;AACrC,UAAM,WAAW,gBACb,CAAC,GAAG,eAAe,QAAQ,UAAU,GAAG,QAAQ,IAChD,CAAC,QAAQ,UAAU,GAAG,QAAQ;AAClC,UAAM,UAAU,SAAS,CAAC;AAC1B,UAAM,YAAY,SAAS,MAAM,CAAC;AAClC,UAAM,QAAQ,MAAM,SAAS,WAAW;AAAA,MACtC,UAAU;AAAA,MACV,OAAO;AAAA,IACT,CAAC;AAMD,UAAM,GAAG,SAAS,MAAM;AAAA,IAAC,CAAC;AAC1B,UAAM,MAAM;AACZ,WAAO,EAAE,IAAI,KAAK;AAAA,EACpB,SAAS,OAAO;AACd,WAAO,EAAE,IAAI,OAAO,QAAQ,gBAAgB,QAAQ,aAAa,KAAK,EAAE;AAAA,EAC1E;AACF;;;AClDO,SAAS,wBAA8B;AAC5C,QAAM,YAAY,cAAc;AAAA;AAAA;AAAA,IAG9B,UAAU,oBAAoB;AAAA;AAAA;AAAA;AAAA,IAI9B,SAAS,MAAM,sBAAsB,KAAK,YAAY;AAAA,EACxD,CAAC;AACD,MAAI,aAAa,UAAW;AAG5B,MAAI,CAAC,sBAAsB,aAAa,EAAG;AAC3C,QAAM,SAAS,oBAAoB,CAAC,kBAAkB,CAAC;AACvD,MAAI,CAAC,OAAO,IAAI;AACd,wBAAoB,EAAE,SAAS,OAAO,QAAQ,QAAQ,OAAO,OAAO,CAAC;AAAA,EACvE;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createRequire as __hookRunnerCreateRequire } from 'node:module';
|
|
2
|
+
const require = __hookRunnerCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
ERROR_TYPE_ATTR,
|
|
5
|
+
POST_TOOL_HANDLER_ATTRS,
|
|
6
|
+
POST_TOOL_METRICS,
|
|
7
|
+
recordMetric
|
|
8
|
+
} from "./chunk-7OM5CYES.js";
|
|
9
|
+
import {
|
|
10
|
+
errorMessage,
|
|
11
|
+
errorTypeName,
|
|
12
|
+
writeStderr
|
|
13
|
+
} from "./chunk-52RY6LQT.js";
|
|
14
|
+
import {
|
|
15
|
+
UNITS
|
|
16
|
+
} from "./chunk-RWRGC7ZK.js";
|
|
17
|
+
|
|
18
|
+
// lib/runtime/run-handlers.ts
|
|
19
|
+
function lazy(load) {
|
|
20
|
+
return async (...args) => {
|
|
21
|
+
await (await load())(...args);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
var REJECTION_LOG_PREFIX = "[post-tool]";
|
|
25
|
+
async function runHandlers(label, ...handlers) {
|
|
26
|
+
const results = await Promise.allSettled(handlers);
|
|
27
|
+
const errors = [];
|
|
28
|
+
for (const [i, r] of results.entries()) {
|
|
29
|
+
if (r.status === "rejected") {
|
|
30
|
+
const errorMsg = errorMessage(r.reason);
|
|
31
|
+
writeStderr(
|
|
32
|
+
`${REJECTION_LOG_PREFIX} Handler ${i} in "${label}" group rejected:`,
|
|
33
|
+
errorMsg
|
|
34
|
+
);
|
|
35
|
+
recordMetric(POST_TOOL_METRICS.HANDLER_REJECTIONS, 1, {
|
|
36
|
+
[POST_TOOL_HANDLER_ATTRS.GROUP]: label,
|
|
37
|
+
[POST_TOOL_HANDLER_ATTRS.INDEX]: String(i),
|
|
38
|
+
[ERROR_TYPE_ATTR]: errorTypeName(r.reason)
|
|
39
|
+
}, { unit: UNITS.REJECTION });
|
|
40
|
+
errors.push({ index: i, error: errorMsg });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return { failures: errors.length, total: handlers.length, errors };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
lazy,
|
|
48
|
+
runHandlers
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=chunk-UW3GQZSM.js.map
|