@sema-agent/server 1.185.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/LICENSE +102 -0
- package/README.md +207 -0
- package/deploy/sema-up/README.md +145 -0
- package/deploy/sema-up/chart/Chart.yaml +11 -0
- package/deploy/sema-up/chart/templates/gitea.yaml +63 -0
- package/deploy/sema-up/chart/templates/minio.yaml +62 -0
- package/deploy/sema-up/chart/templates/namespace-sandbox.yaml +9 -0
- package/deploy/sema-up/chart/templates/pg-cluster.yaml +57 -0
- package/deploy/sema-up/chart/templates/registry.yaml +88 -0
- package/deploy/sema-up/chart/templates/sandbox-rbac.yaml +45 -0
- package/deploy/sema-up/chart/templates/server-v4pro.yaml +76 -0
- package/deploy/sema-up/chart/templates/server.yaml +88 -0
- package/deploy/sema-up/chart/values-full-single.yaml +9 -0
- package/deploy/sema-up/chart/values.yaml +100 -0
- package/deploy/sema-up/cluster-up.sh +432 -0
- package/deploy/sema-up/kube-up.sh +377 -0
- package/deploy/sema-up/lib/parse-machines.py +117 -0
- package/deploy/sema-up/machines.example.yaml +53 -0
- package/deploy/sema-up/preflight.sh +168 -0
- package/deploy/sema-up/sema-up.sh +758 -0
- package/deploy/sema-up/smoke.sh +100 -0
- package/deploy/sema-up/stack/compose.dataroot.yaml +16 -0
- package/deploy/sema-up/stack/compose.yaml +155 -0
- package/deploy/sema-up/stack/sema-stack-cluster.yaml +189 -0
- package/dist/approval.d.ts +27 -0
- package/dist/approval.d.ts.map +1 -0
- package/dist/approval.js +127 -0
- package/dist/approval.js.map +1 -0
- package/dist/audit.d.ts +29 -0
- package/dist/audit.d.ts.map +1 -0
- package/dist/audit.js +95 -0
- package/dist/audit.js.map +1 -0
- package/dist/auth-bridge.d.ts +29 -0
- package/dist/auth-bridge.d.ts.map +1 -0
- package/dist/auth-bridge.js +145 -0
- package/dist/auth-bridge.js.map +1 -0
- package/dist/bake-runner/main.d.ts +20 -0
- package/dist/bake-runner/main.d.ts.map +1 -0
- package/dist/bake-runner/main.js +216 -0
- package/dist/bake-runner/main.js.map +1 -0
- package/dist/bake-runner/protocol.d.ts +49 -0
- package/dist/bake-runner/protocol.d.ts.map +1 -0
- package/dist/bake-runner/protocol.js +86 -0
- package/dist/bake-runner/protocol.js.map +1 -0
- package/dist/bake-runner/runner.d.ts +86 -0
- package/dist/bake-runner/runner.d.ts.map +1 -0
- package/dist/bake-runner/runner.js +228 -0
- package/dist/bake-runner/runner.js.map +1 -0
- package/dist/bench/l8/artifact.d.ts +62 -0
- package/dist/bench/l8/artifact.d.ts.map +1 -0
- package/dist/bench/l8/artifact.js +129 -0
- package/dist/bench/l8/artifact.js.map +1 -0
- package/dist/bench/l8/escape.d.ts +18 -0
- package/dist/bench/l8/escape.d.ts.map +1 -0
- package/dist/bench/l8/escape.js +9 -0
- package/dist/bench/l8/escape.js.map +1 -0
- package/dist/bench/l8/index.d.ts +5 -0
- package/dist/bench/l8/index.d.ts.map +1 -0
- package/dist/bench/l8/index.js +5 -0
- package/dist/bench/l8/index.js.map +1 -0
- package/dist/bench/l8/probes.d.ts +75 -0
- package/dist/bench/l8/probes.d.ts.map +1 -0
- package/dist/bench/l8/probes.js +178 -0
- package/dist/bench/l8/probes.js.map +1 -0
- package/dist/bench/l8/run-probes.d.ts +21 -0
- package/dist/bench/l8/run-probes.d.ts.map +1 -0
- package/dist/bench/l8/run-probes.js +130 -0
- package/dist/bench/l8/run-probes.js.map +1 -0
- package/dist/bench/s1/arms.d.ts +84 -0
- package/dist/bench/s1/arms.d.ts.map +1 -0
- package/dist/bench/s1/arms.js +329 -0
- package/dist/bench/s1/arms.js.map +1 -0
- package/dist/bench/s1/live-deps.d.ts +25 -0
- package/dist/bench/s1/live-deps.d.ts.map +1 -0
- package/dist/bench/s1/live-deps.js +449 -0
- package/dist/bench/s1/live-deps.js.map +1 -0
- package/dist/bench/s1/oracle.d.ts +34 -0
- package/dist/bench/s1/oracle.d.ts.map +1 -0
- package/dist/bench/s1/oracle.js +29 -0
- package/dist/bench/s1/oracle.js.map +1 -0
- package/dist/bench/s1/repair-oracle-adapter.d.ts +9 -0
- package/dist/bench/s1/repair-oracle-adapter.d.ts.map +1 -0
- package/dist/bench/s1/repair-oracle-adapter.js +27 -0
- package/dist/bench/s1/repair-oracle-adapter.js.map +1 -0
- package/dist/bench/s1/reviewer.d.ts +31 -0
- package/dist/bench/s1/reviewer.d.ts.map +1 -0
- package/dist/bench/s1/reviewer.js +26 -0
- package/dist/bench/s1/reviewer.js.map +1 -0
- package/dist/bench/s1/row.d.ts +29 -0
- package/dist/bench/s1/row.d.ts.map +1 -0
- package/dist/bench/s1/row.js +55 -0
- package/dist/bench/s1/row.js.map +1 -0
- package/dist/bench/s1/run-firm.d.ts +49 -0
- package/dist/bench/s1/run-firm.d.ts.map +1 -0
- package/dist/bench/s1/run-firm.js +291 -0
- package/dist/bench/s1/run-firm.js.map +1 -0
- package/dist/bench/s1/runner-ctx.d.ts +44 -0
- package/dist/bench/s1/runner-ctx.d.ts.map +1 -0
- package/dist/bench/s1/runner-ctx.js +59 -0
- package/dist/bench/s1/runner-ctx.js.map +1 -0
- package/dist/bench/s1/tasks.d.ts +48 -0
- package/dist/bench/s1/tasks.d.ts.map +1 -0
- package/dist/bench/s1/tasks.js +194 -0
- package/dist/bench/s1/tasks.js.map +1 -0
- package/dist/boot-reclaim.d.ts +10 -0
- package/dist/boot-reclaim.d.ts.map +1 -0
- package/dist/boot-reclaim.js +13 -0
- package/dist/boot-reclaim.js.map +1 -0
- package/dist/brain.d.ts +8 -0
- package/dist/brain.d.ts.map +1 -0
- package/dist/brain.js +83 -0
- package/dist/brain.js.map +1 -0
- package/dist/budget.d.ts +25 -0
- package/dist/budget.d.ts.map +1 -0
- package/dist/budget.js +107 -0
- package/dist/budget.js.map +1 -0
- package/dist/capabilities/builtin-tools.d.ts +3 -0
- package/dist/capabilities/builtin-tools.d.ts.map +1 -0
- package/dist/capabilities/builtin-tools.js +11 -0
- package/dist/capabilities/builtin-tools.js.map +1 -0
- package/dist/capabilities/code-review-council.d.ts +21 -0
- package/dist/capabilities/code-review-council.d.ts.map +1 -0
- package/dist/capabilities/code-review-council.js +113 -0
- package/dist/capabilities/code-review-council.js.map +1 -0
- package/dist/capabilities/collab-wire.d.ts +34 -0
- package/dist/capabilities/collab-wire.d.ts.map +1 -0
- package/dist/capabilities/collab-wire.js +2 -0
- package/dist/capabilities/collab-wire.js.map +1 -0
- package/dist/capabilities/collab-workflows.d.ts +40 -0
- package/dist/capabilities/collab-workflows.d.ts.map +1 -0
- package/dist/capabilities/collab-workflows.js +90 -0
- package/dist/capabilities/collab-workflows.js.map +1 -0
- package/dist/capabilities/oa-tools.d.ts +9 -0
- package/dist/capabilities/oa-tools.d.ts.map +1 -0
- package/dist/capabilities/oa-tools.js +44 -0
- package/dist/capabilities/oa-tools.js.map +1 -0
- package/dist/capabilities/prompt.d.ts +3 -0
- package/dist/capabilities/prompt.d.ts.map +1 -0
- package/dist/capabilities/prompt.js +6 -0
- package/dist/capabilities/prompt.js.map +1 -0
- package/dist/capabilities/prompts/code-review.d.ts +11 -0
- package/dist/capabilities/prompts/code-review.d.ts.map +1 -0
- package/dist/capabilities/prompts/code-review.js +39 -0
- package/dist/capabilities/prompts/code-review.js.map +1 -0
- package/dist/capabilities/prompts/identity.d.ts +2 -0
- package/dist/capabilities/prompts/identity.d.ts.map +1 -0
- package/dist/capabilities/prompts/identity.js +6 -0
- package/dist/capabilities/prompts/identity.js.map +1 -0
- package/dist/capabilities/prompts/team.d.ts +6 -0
- package/dist/capabilities/prompts/team.d.ts.map +1 -0
- package/dist/capabilities/prompts/team.js +6 -0
- package/dist/capabilities/prompts/team.js.map +1 -0
- package/dist/capabilities/repo-tools.d.ts +19 -0
- package/dist/capabilities/repo-tools.d.ts.map +1 -0
- package/dist/capabilities/repo-tools.js +98 -0
- package/dist/capabilities/repo-tools.js.map +1 -0
- package/dist/capabilities/scenarios.d.ts +72 -0
- package/dist/capabilities/scenarios.d.ts.map +1 -0
- package/dist/capabilities/scenarios.js +241 -0
- package/dist/capabilities/scenarios.js.map +1 -0
- package/dist/capabilities/select-environment-tool.d.ts +22 -0
- package/dist/capabilities/select-environment-tool.d.ts.map +1 -0
- package/dist/capabilities/select-environment-tool.js +86 -0
- package/dist/capabilities/select-environment-tool.js.map +1 -0
- package/dist/capabilities/skills.d.ts +12 -0
- package/dist/capabilities/skills.d.ts.map +1 -0
- package/dist/capabilities/skills.js +50 -0
- package/dist/capabilities/skills.js.map +1 -0
- package/dist/capabilities/team.d.ts +31 -0
- package/dist/capabilities/team.d.ts.map +1 -0
- package/dist/capabilities/team.js +66 -0
- package/dist/capabilities/team.js.map +1 -0
- package/dist/config-provider.d.ts +47 -0
- package/dist/config-provider.d.ts.map +1 -0
- package/dist/config-provider.js +156 -0
- package/dist/config-provider.js.map +1 -0
- package/dist/config.d.ts +272 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +605 -0
- package/dist/config.js.map +1 -0
- package/dist/degenerate-instrument.d.ts +17 -0
- package/dist/degenerate-instrument.d.ts.map +1 -0
- package/dist/degenerate-instrument.js +113 -0
- package/dist/degenerate-instrument.js.map +1 -0
- package/dist/elicitation.d.ts +47 -0
- package/dist/elicitation.d.ts.map +1 -0
- package/dist/elicitation.js +151 -0
- package/dist/elicitation.js.map +1 -0
- package/dist/env-facts.d.ts +18 -0
- package/dist/env-facts.d.ts.map +1 -0
- package/dist/env-facts.js +26 -0
- package/dist/env-facts.js.map +1 -0
- package/dist/finance/cost-taxonomy.d.ts +34 -0
- package/dist/finance/cost-taxonomy.d.ts.map +1 -0
- package/dist/finance/cost-taxonomy.js +26 -0
- package/dist/finance/cost-taxonomy.js.map +1 -0
- package/dist/fleet/fleet-bus.d.ts +137 -0
- package/dist/fleet/fleet-bus.d.ts.map +1 -0
- package/dist/fleet/fleet-bus.js +249 -0
- package/dist/fleet/fleet-bus.js.map +1 -0
- package/dist/fleet-client.d.ts +50 -0
- package/dist/fleet-client.d.ts.map +1 -0
- package/dist/fleet-client.js +150 -0
- package/dist/fleet-client.js.map +1 -0
- package/dist/fleet-lease.d.ts +76 -0
- package/dist/fleet-lease.d.ts.map +1 -0
- package/dist/fleet-lease.js +124 -0
- package/dist/fleet-lease.js.map +1 -0
- package/dist/hooks/hook-runner.d.ts +41 -0
- package/dist/hooks/hook-runner.d.ts.map +1 -0
- package/dist/hooks/hook-runner.js +975 -0
- package/dist/hooks/hook-runner.js.map +1 -0
- package/dist/http/idempotency.d.ts +12 -0
- package/dist/http/idempotency.d.ts.map +1 -0
- package/dist/http/idempotency.js +49 -0
- package/dist/http/idempotency.js.map +1 -0
- package/dist/http/server.d.ts +185 -0
- package/dist/http/server.d.ts.map +1 -0
- package/dist/http/server.js +4845 -0
- package/dist/http/server.js.map +1 -0
- package/dist/http/wire-gate.d.ts +3 -0
- package/dist/http/wire-gate.d.ts.map +1 -0
- package/dist/http/wire-gate.js +6 -0
- package/dist/http/wire-gate.js.map +1 -0
- package/dist/images/bake-validate.d.ts +41 -0
- package/dist/images/bake-validate.d.ts.map +1 -0
- package/dist/images/bake-validate.js +183 -0
- package/dist/images/bake-validate.js.map +1 -0
- package/dist/images/manifest.d.ts +36 -0
- package/dist/images/manifest.d.ts.map +1 -0
- package/dist/images/manifest.js +69 -0
- package/dist/images/manifest.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/key-resolver.d.ts +5 -0
- package/dist/key-resolver.d.ts.map +1 -0
- package/dist/key-resolver.js +15 -0
- package/dist/key-resolver.js.map +1 -0
- package/dist/leader/diffout.d.ts +24 -0
- package/dist/leader/diffout.d.ts.map +1 -0
- package/dist/leader/diffout.js +54 -0
- package/dist/leader/diffout.js.map +1 -0
- package/dist/leader/diffup.d.ts +14 -0
- package/dist/leader/diffup.d.ts.map +1 -0
- package/dist/leader/diffup.js +81 -0
- package/dist/leader/diffup.js.map +1 -0
- package/dist/leader/endpoint.d.ts +30 -0
- package/dist/leader/endpoint.d.ts.map +1 -0
- package/dist/leader/endpoint.js +76 -0
- package/dist/leader/endpoint.js.map +1 -0
- package/dist/leader/fanout.d.ts +46 -0
- package/dist/leader/fanout.d.ts.map +1 -0
- package/dist/leader/fanout.js +109 -0
- package/dist/leader/fanout.js.map +1 -0
- package/dist/leader/grader-env-factory.d.ts +36 -0
- package/dist/leader/grader-env-factory.d.ts.map +1 -0
- package/dist/leader/grader-env-factory.js +73 -0
- package/dist/leader/grader-env-factory.js.map +1 -0
- package/dist/leader/leader.d.ts +102 -0
- package/dist/leader/leader.d.ts.map +1 -0
- package/dist/leader/leader.js +354 -0
- package/dist/leader/leader.js.map +1 -0
- package/dist/leader/merge.d.ts +109 -0
- package/dist/leader/merge.d.ts.map +1 -0
- package/dist/leader/merge.js +184 -0
- package/dist/leader/merge.js.map +1 -0
- package/dist/leader/planner.d.ts +26 -0
- package/dist/leader/planner.d.ts.map +1 -0
- package/dist/leader/planner.js +137 -0
- package/dist/leader/planner.js.map +1 -0
- package/dist/leader/repair-oracle.d.ts +34 -0
- package/dist/leader/repair-oracle.d.ts.map +1 -0
- package/dist/leader/repair-oracle.js +83 -0
- package/dist/leader/repair-oracle.js.map +1 -0
- package/dist/leader/repair-wire.d.ts +49 -0
- package/dist/leader/repair-wire.d.ts.map +1 -0
- package/dist/leader/repair-wire.js +90 -0
- package/dist/leader/repair-wire.js.map +1 -0
- package/dist/leader/wire.d.ts +66 -0
- package/dist/leader/wire.d.ts.map +1 -0
- package/dist/leader/wire.js +452 -0
- package/dist/leader/wire.js.map +1 -0
- package/dist/lsp/e2b-bridge.d.ts +8 -0
- package/dist/lsp/e2b-bridge.d.ts.map +1 -0
- package/dist/lsp/e2b-bridge.js +71 -0
- package/dist/lsp/e2b-bridge.js.map +1 -0
- package/dist/lsp/e2b-manager.d.ts +16 -0
- package/dist/lsp/e2b-manager.d.ts.map +1 -0
- package/dist/lsp/e2b-manager.js +49 -0
- package/dist/lsp/e2b-manager.js.map +1 -0
- package/dist/lsp/lsp-frames.d.ts +2 -0
- package/dist/lsp/lsp-frames.d.ts.map +1 -0
- package/dist/lsp/lsp-frames.js +25 -0
- package/dist/lsp/lsp-frames.js.map +1 -0
- package/dist/lsp/manager.d.ts +41 -0
- package/dist/lsp/manager.d.ts.map +1 -0
- package/dist/lsp/manager.js +84 -0
- package/dist/lsp/manager.js.map +1 -0
- package/dist/lsp/types.d.ts +2 -0
- package/dist/lsp/types.d.ts.map +1 -0
- package/dist/lsp/types.js +2 -0
- package/dist/lsp/types.js.map +1 -0
- package/dist/lsp/ws-transport.d.ts +28 -0
- package/dist/lsp/ws-transport.d.ts.map +1 -0
- package/dist/lsp/ws-transport.js +209 -0
- package/dist/lsp/ws-transport.js.map +1 -0
- package/dist/lsp-evict.d.ts +2 -0
- package/dist/lsp-evict.d.ts.map +1 -0
- package/dist/lsp-evict.js +14 -0
- package/dist/lsp-evict.js.map +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +1526 -0
- package/dist/main.js.map +1 -0
- package/dist/memory-export.d.ts +3 -0
- package/dist/memory-export.d.ts.map +1 -0
- package/dist/memory-export.js +8 -0
- package/dist/memory-export.js.map +1 -0
- package/dist/memory-sync-client.d.ts +29 -0
- package/dist/memory-sync-client.d.ts.map +1 -0
- package/dist/memory-sync-client.js +133 -0
- package/dist/memory-sync-client.js.map +1 -0
- package/dist/memory-sync.d.ts +41 -0
- package/dist/memory-sync.d.ts.map +1 -0
- package/dist/memory-sync.js +183 -0
- package/dist/memory-sync.js.map +1 -0
- package/dist/model-select.d.ts +8 -0
- package/dist/model-select.d.ts.map +1 -0
- package/dist/model-select.js +12 -0
- package/dist/model-select.js.map +1 -0
- package/dist/observability/cost-quota.d.ts +21 -0
- package/dist/observability/cost-quota.d.ts.map +1 -0
- package/dist/observability/cost-quota.js +42 -0
- package/dist/observability/cost-quota.js.map +1 -0
- package/dist/observability/logger.d.ts +9 -0
- package/dist/observability/logger.d.ts.map +1 -0
- package/dist/observability/logger.js +35 -0
- package/dist/observability/logger.js.map +1 -0
- package/dist/observability/metrics.d.ts +76 -0
- package/dist/observability/metrics.d.ts.map +1 -0
- package/dist/observability/metrics.js +263 -0
- package/dist/observability/metrics.js.map +1 -0
- package/dist/observability/otel-exporter.d.ts +37 -0
- package/dist/observability/otel-exporter.d.ts.map +1 -0
- package/dist/observability/otel-exporter.js +95 -0
- package/dist/observability/otel-exporter.js.map +1 -0
- package/dist/observability/principal-context.d.ts +5 -0
- package/dist/observability/principal-context.d.ts.map +1 -0
- package/dist/observability/principal-context.js +9 -0
- package/dist/observability/principal-context.js.map +1 -0
- package/dist/observability/rate-limit.d.ts +18 -0
- package/dist/observability/rate-limit.d.ts.map +1 -0
- package/dist/observability/rate-limit.js +30 -0
- package/dist/observability/rate-limit.js.map +1 -0
- package/dist/observability/tool-trace.d.ts +6 -0
- package/dist/observability/tool-trace.d.ts.map +1 -0
- package/dist/observability/tool-trace.js +73 -0
- package/dist/observability/tool-trace.js.map +1 -0
- package/dist/orchestration/hardened-vm-runner.d.ts +26 -0
- package/dist/orchestration/hardened-vm-runner.d.ts.map +1 -0
- package/dist/orchestration/hardened-vm-runner.js +217 -0
- package/dist/orchestration/hardened-vm-runner.js.map +1 -0
- package/dist/orchestration/hardened-vm-worker-runner.d.ts +4 -0
- package/dist/orchestration/hardened-vm-worker-runner.d.ts.map +1 -0
- package/dist/orchestration/hardened-vm-worker-runner.js +79 -0
- package/dist/orchestration/hardened-vm-worker-runner.js.map +1 -0
- package/dist/orchestration/hardened-vm-worker.d.ts +2 -0
- package/dist/orchestration/hardened-vm-worker.d.ts.map +1 -0
- package/dist/orchestration/hardened-vm-worker.js +80 -0
- package/dist/orchestration/hardened-vm-worker.js.map +1 -0
- package/dist/orchestration/subagent-steer.d.ts +12 -0
- package/dist/orchestration/subagent-steer.d.ts.map +1 -0
- package/dist/orchestration/subagent-steer.js +45 -0
- package/dist/orchestration/subagent-steer.js.map +1 -0
- package/dist/orchestration/workflow-agent-steer.d.ts +14 -0
- package/dist/orchestration/workflow-agent-steer.d.ts.map +1 -0
- package/dist/orchestration/workflow-agent-steer.js +41 -0
- package/dist/orchestration/workflow-agent-steer.js.map +1 -0
- package/dist/orchestration/workflow-completion-inbox.d.ts +101 -0
- package/dist/orchestration/workflow-completion-inbox.d.ts.map +1 -0
- package/dist/orchestration/workflow-completion-inbox.js +327 -0
- package/dist/orchestration/workflow-completion-inbox.js.map +1 -0
- package/dist/orchestration/workflow-notify-journal.d.ts +120 -0
- package/dist/orchestration/workflow-notify-journal.d.ts.map +1 -0
- package/dist/orchestration/workflow-notify-journal.js +297 -0
- package/dist/orchestration/workflow-notify-journal.js.map +1 -0
- package/dist/per-task-image.d.ts +27 -0
- package/dist/per-task-image.d.ts.map +1 -0
- package/dist/per-task-image.js +37 -0
- package/dist/per-task-image.js.map +1 -0
- package/dist/plan-cache-probe.d.ts +21 -0
- package/dist/plan-cache-probe.d.ts.map +1 -0
- package/dist/plan-cache-probe.js +79 -0
- package/dist/plan-cache-probe.js.map +1 -0
- package/dist/plugins/approval-exemption-store.d.ts +56 -0
- package/dist/plugins/approval-exemption-store.d.ts.map +1 -0
- package/dist/plugins/approval-exemption-store.js +216 -0
- package/dist/plugins/approval-exemption-store.js.map +1 -0
- package/dist/plugins/background-shell-support.d.ts +64 -0
- package/dist/plugins/background-shell-support.d.ts.map +1 -0
- package/dist/plugins/background-shell-support.js +235 -0
- package/dist/plugins/background-shell-support.js.map +1 -0
- package/dist/plugins/blob-backend.d.ts +44 -0
- package/dist/plugins/blob-backend.d.ts.map +1 -0
- package/dist/plugins/blob-backend.js +188 -0
- package/dist/plugins/blob-backend.js.map +1 -0
- package/dist/plugins/caching-session-store.d.ts +51 -0
- package/dist/plugins/caching-session-store.d.ts.map +1 -0
- package/dist/plugins/caching-session-store.js +142 -0
- package/dist/plugins/caching-session-store.js.map +1 -0
- package/dist/plugins/file-outcome-sink.d.ts +20 -0
- package/dist/plugins/file-outcome-sink.d.ts.map +1 -0
- package/dist/plugins/file-outcome-sink.js +14 -0
- package/dist/plugins/file-outcome-sink.js.map +1 -0
- package/dist/plugins/file-resume-anchor-store.d.ts +19 -0
- package/dist/plugins/file-resume-anchor-store.d.ts.map +1 -0
- package/dist/plugins/file-resume-anchor-store.js +103 -0
- package/dist/plugins/file-resume-anchor-store.js.map +1 -0
- package/dist/plugins/file-run-store.d.ts +95 -0
- package/dist/plugins/file-run-store.d.ts.map +1 -0
- package/dist/plugins/file-run-store.js +446 -0
- package/dist/plugins/file-run-store.js.map +1 -0
- package/dist/plugins/file-workflow-journal-store.d.ts +2 -0
- package/dist/plugins/file-workflow-journal-store.d.ts.map +1 -0
- package/dist/plugins/file-workflow-journal-store.js +2 -0
- package/dist/plugins/file-workflow-journal-store.js.map +1 -0
- package/dist/plugins/host-platform.d.ts +19 -0
- package/dist/plugins/host-platform.d.ts.map +1 -0
- package/dist/plugins/host-platform.js +71 -0
- package/dist/plugins/host-platform.js.map +1 -0
- package/dist/plugins/local-checkpoint-store.d.ts +41 -0
- package/dist/plugins/local-checkpoint-store.d.ts.map +1 -0
- package/dist/plugins/local-checkpoint-store.js +217 -0
- package/dist/plugins/local-checkpoint-store.js.map +1 -0
- package/dist/plugins/local-session-store.d.ts +69 -0
- package/dist/plugins/local-session-store.d.ts.map +1 -0
- package/dist/plugins/local-session-store.js +431 -0
- package/dist/plugins/local-session-store.js.map +1 -0
- package/dist/plugins/memory-engine-pg.d.ts +47 -0
- package/dist/plugins/memory-engine-pg.d.ts.map +1 -0
- package/dist/plugins/memory-engine-pg.js +306 -0
- package/dist/plugins/memory-engine-pg.js.map +1 -0
- package/dist/plugins/memory-engine-tidb.d.ts +40 -0
- package/dist/plugins/memory-engine-tidb.d.ts.map +1 -0
- package/dist/plugins/memory-engine-tidb.js +296 -0
- package/dist/plugins/memory-engine-tidb.js.map +1 -0
- package/dist/plugins/memory-engine-vector-util.d.ts +2 -0
- package/dist/plugins/memory-engine-vector-util.d.ts.map +1 -0
- package/dist/plugins/memory-engine-vector-util.js +2 -0
- package/dist/plugins/memory-engine-vector-util.js.map +1 -0
- package/dist/plugins/memory-resume-anchor-store.d.ts +12 -0
- package/dist/plugins/memory-resume-anchor-store.d.ts.map +1 -0
- package/dist/plugins/memory-resume-anchor-store.js +31 -0
- package/dist/plugins/memory-resume-anchor-store.js.map +1 -0
- package/dist/plugins/memory-run-store.d.ts +75 -0
- package/dist/plugins/memory-run-store.d.ts.map +1 -0
- package/dist/plugins/memory-run-store.js +267 -0
- package/dist/plugins/memory-run-store.js.map +1 -0
- package/dist/plugins/memory-sync-store-pg.d.ts +78 -0
- package/dist/plugins/memory-sync-store-pg.d.ts.map +1 -0
- package/dist/plugins/memory-sync-store-pg.js +152 -0
- package/dist/plugins/memory-sync-store-pg.js.map +1 -0
- package/dist/plugins/memory-sync-store-tidb.d.ts +32 -0
- package/dist/plugins/memory-sync-store-tidb.d.ts.map +1 -0
- package/dist/plugins/memory-sync-store-tidb.js +146 -0
- package/dist/plugins/memory-sync-store-tidb.js.map +1 -0
- package/dist/plugins/pg-approval-store.d.ts +28 -0
- package/dist/plugins/pg-approval-store.d.ts.map +1 -0
- package/dist/plugins/pg-approval-store.js +107 -0
- package/dist/plugins/pg-approval-store.js.map +1 -0
- package/dist/plugins/pg-breaker-state.d.ts +20 -0
- package/dist/plugins/pg-breaker-state.d.ts.map +1 -0
- package/dist/plugins/pg-breaker-state.js +89 -0
- package/dist/plugins/pg-breaker-state.js.map +1 -0
- package/dist/plugins/pg-checkpoint-store.d.ts +34 -0
- package/dist/plugins/pg-checkpoint-store.d.ts.map +1 -0
- package/dist/plugins/pg-checkpoint-store.js +193 -0
- package/dist/plugins/pg-checkpoint-store.js.map +1 -0
- package/dist/plugins/pg-cost-quota.d.ts +18 -0
- package/dist/plugins/pg-cost-quota.d.ts.map +1 -0
- package/dist/plugins/pg-cost-quota.js +189 -0
- package/dist/plugins/pg-cost-quota.js.map +1 -0
- package/dist/plugins/pg-file-snapshot-store.d.ts +26 -0
- package/dist/plugins/pg-file-snapshot-store.d.ts.map +1 -0
- package/dist/plugins/pg-file-snapshot-store.js +181 -0
- package/dist/plugins/pg-file-snapshot-store.js.map +1 -0
- package/dist/plugins/pg-image-bake.d.ts +42 -0
- package/dist/plugins/pg-image-bake.d.ts.map +1 -0
- package/dist/plugins/pg-image-bake.js +471 -0
- package/dist/plugins/pg-image-bake.js.map +1 -0
- package/dist/plugins/pg-image-index.d.ts +23 -0
- package/dist/plugins/pg-image-index.d.ts.map +1 -0
- package/dist/plugins/pg-image-index.js +252 -0
- package/dist/plugins/pg-image-index.js.map +1 -0
- package/dist/plugins/pg-outcome-ledger.d.ts +23 -0
- package/dist/plugins/pg-outcome-ledger.d.ts.map +1 -0
- package/dist/plugins/pg-outcome-ledger.js +102 -0
- package/dist/plugins/pg-outcome-ledger.js.map +1 -0
- package/dist/plugins/pg-pool.d.ts +7 -0
- package/dist/plugins/pg-pool.d.ts.map +1 -0
- package/dist/plugins/pg-pool.js +233 -0
- package/dist/plugins/pg-pool.js.map +1 -0
- package/dist/plugins/pg-rate-limiter.d.ts +49 -0
- package/dist/plugins/pg-rate-limiter.d.ts.map +1 -0
- package/dist/plugins/pg-rate-limiter.js +193 -0
- package/dist/plugins/pg-rate-limiter.js.map +1 -0
- package/dist/plugins/pg-resume-anchor-store.d.ts +14 -0
- package/dist/plugins/pg-resume-anchor-store.d.ts.map +1 -0
- package/dist/plugins/pg-resume-anchor-store.js +23 -0
- package/dist/plugins/pg-resume-anchor-store.js.map +1 -0
- package/dist/plugins/pg-run-store.d.ts +76 -0
- package/dist/plugins/pg-run-store.d.ts.map +1 -0
- package/dist/plugins/pg-run-store.js +301 -0
- package/dist/plugins/pg-run-store.js.map +1 -0
- package/dist/plugins/pg-session-policy-store.d.ts +12 -0
- package/dist/plugins/pg-session-policy-store.d.ts.map +1 -0
- package/dist/plugins/pg-session-policy-store.js +88 -0
- package/dist/plugins/pg-session-policy-store.js.map +1 -0
- package/dist/plugins/pg-session-storage.d.ts +59 -0
- package/dist/plugins/pg-session-storage.d.ts.map +1 -0
- package/dist/plugins/pg-session-storage.js +484 -0
- package/dist/plugins/pg-session-storage.js.map +1 -0
- package/dist/plugins/pg-session-store.d.ts +2 -0
- package/dist/plugins/pg-session-store.d.ts.map +1 -0
- package/dist/plugins/pg-session-store.js +2 -0
- package/dist/plugins/pg-session-store.js.map +1 -0
- package/dist/plugins/pg-tool-result-store.d.ts +16 -0
- package/dist/plugins/pg-tool-result-store.d.ts.map +1 -0
- package/dist/plugins/pg-tool-result-store.js +52 -0
- package/dist/plugins/pg-tool-result-store.js.map +1 -0
- package/dist/plugins/pg-workflow-journal-store.d.ts +11 -0
- package/dist/plugins/pg-workflow-journal-store.d.ts.map +1 -0
- package/dist/plugins/pg-workflow-journal-store.js +28 -0
- package/dist/plugins/pg-workflow-journal-store.js.map +1 -0
- package/dist/plugins/pg-workflow-run-store.d.ts +55 -0
- package/dist/plugins/pg-workflow-run-store.d.ts.map +1 -0
- package/dist/plugins/pg-workflow-run-store.js +216 -0
- package/dist/plugins/pg-workflow-run-store.js.map +1 -0
- package/dist/plugins/remote-env-adb.d.ts +119 -0
- package/dist/plugins/remote-env-adb.d.ts.map +1 -0
- package/dist/plugins/remote-env-adb.js +502 -0
- package/dist/plugins/remote-env-adb.js.map +1 -0
- package/dist/plugins/remote-env-e2b.d.ts +162 -0
- package/dist/plugins/remote-env-e2b.d.ts.map +1 -0
- package/dist/plugins/remote-env-e2b.js +931 -0
- package/dist/plugins/remote-env-e2b.js.map +1 -0
- package/dist/plugins/remote-env-host.d.ts +141 -0
- package/dist/plugins/remote-env-host.d.ts.map +1 -0
- package/dist/plugins/remote-env-host.js +868 -0
- package/dist/plugins/remote-env-host.js.map +1 -0
- package/dist/plugins/remote-env-k8s.d.ts +209 -0
- package/dist/plugins/remote-env-k8s.d.ts.map +1 -0
- package/dist/plugins/remote-env-k8s.js +1206 -0
- package/dist/plugins/remote-env-k8s.js.map +1 -0
- package/dist/plugins/remote-env-local-docker.d.ts +124 -0
- package/dist/plugins/remote-env-local-docker.d.ts.map +1 -0
- package/dist/plugins/remote-env-local-docker.js +597 -0
- package/dist/plugins/remote-env-local-docker.js.map +1 -0
- package/dist/plugins/remote-env-ssh.d.ts +122 -0
- package/dist/plugins/remote-env-ssh.d.ts.map +1 -0
- package/dist/plugins/remote-env-ssh.js +511 -0
- package/dist/plugins/remote-env-ssh.js.map +1 -0
- package/dist/plugins/remote-shell.d.ts +7 -0
- package/dist/plugins/remote-shell.d.ts.map +1 -0
- package/dist/plugins/remote-shell.js +25 -0
- package/dist/plugins/remote-shell.js.map +1 -0
- package/dist/plugins/s3-presign.d.ts +13 -0
- package/dist/plugins/s3-presign.d.ts.map +1 -0
- package/dist/plugins/s3-presign.js +55 -0
- package/dist/plugins/s3-presign.js.map +1 -0
- package/dist/plugins/scheduler-support.d.ts +39 -0
- package/dist/plugins/scheduler-support.d.ts.map +1 -0
- package/dist/plugins/scheduler-support.js +141 -0
- package/dist/plugins/scheduler-support.js.map +1 -0
- package/dist/plugins/session-store.d.ts +7 -0
- package/dist/plugins/session-store.d.ts.map +1 -0
- package/dist/plugins/session-store.js +14 -0
- package/dist/plugins/session-store.js.map +1 -0
- package/dist/plugins/store-backend.d.ts +88 -0
- package/dist/plugins/store-backend.d.ts.map +1 -0
- package/dist/plugins/store-backend.js +197 -0
- package/dist/plugins/store-backend.js.map +1 -0
- package/dist/plugins/tidb-approval-store.d.ts +39 -0
- package/dist/plugins/tidb-approval-store.d.ts.map +1 -0
- package/dist/plugins/tidb-approval-store.js +81 -0
- package/dist/plugins/tidb-approval-store.js.map +1 -0
- package/dist/plugins/tidb-breaker-state.d.ts +18 -0
- package/dist/plugins/tidb-breaker-state.d.ts.map +1 -0
- package/dist/plugins/tidb-breaker-state.js +75 -0
- package/dist/plugins/tidb-breaker-state.js.map +1 -0
- package/dist/plugins/tidb-checkpoint-store.d.ts +50 -0
- package/dist/plugins/tidb-checkpoint-store.d.ts.map +1 -0
- package/dist/plugins/tidb-checkpoint-store.js +196 -0
- package/dist/plugins/tidb-checkpoint-store.js.map +1 -0
- package/dist/plugins/tidb-cost-quota.d.ts +16 -0
- package/dist/plugins/tidb-cost-quota.d.ts.map +1 -0
- package/dist/plugins/tidb-cost-quota.js +34 -0
- package/dist/plugins/tidb-cost-quota.js.map +1 -0
- package/dist/plugins/tidb-file-snapshot-store.d.ts +26 -0
- package/dist/plugins/tidb-file-snapshot-store.d.ts.map +1 -0
- package/dist/plugins/tidb-file-snapshot-store.js +183 -0
- package/dist/plugins/tidb-file-snapshot-store.js.map +1 -0
- package/dist/plugins/tidb-image-bake.d.ts +102 -0
- package/dist/plugins/tidb-image-bake.d.ts.map +1 -0
- package/dist/plugins/tidb-image-bake.js +400 -0
- package/dist/plugins/tidb-image-bake.js.map +1 -0
- package/dist/plugins/tidb-image-index.d.ts +71 -0
- package/dist/plugins/tidb-image-index.d.ts.map +1 -0
- package/dist/plugins/tidb-image-index.js +192 -0
- package/dist/plugins/tidb-image-index.js.map +1 -0
- package/dist/plugins/tidb-outcome-ledger.d.ts +58 -0
- package/dist/plugins/tidb-outcome-ledger.d.ts.map +1 -0
- package/dist/plugins/tidb-outcome-ledger.js +98 -0
- package/dist/plugins/tidb-outcome-ledger.js.map +1 -0
- package/dist/plugins/tidb-pool.d.ts +11 -0
- package/dist/plugins/tidb-pool.d.ts.map +1 -0
- package/dist/plugins/tidb-pool.js +485 -0
- package/dist/plugins/tidb-pool.js.map +1 -0
- package/dist/plugins/tidb-rate-limiter.d.ts +15 -0
- package/dist/plugins/tidb-rate-limiter.d.ts.map +1 -0
- package/dist/plugins/tidb-rate-limiter.js +34 -0
- package/dist/plugins/tidb-rate-limiter.js.map +1 -0
- package/dist/plugins/tidb-resume-anchor-store.d.ts +14 -0
- package/dist/plugins/tidb-resume-anchor-store.d.ts.map +1 -0
- package/dist/plugins/tidb-resume-anchor-store.js +23 -0
- package/dist/plugins/tidb-resume-anchor-store.js.map +1 -0
- package/dist/plugins/tidb-run-store.d.ts +107 -0
- package/dist/plugins/tidb-run-store.d.ts.map +1 -0
- package/dist/plugins/tidb-run-store.js +321 -0
- package/dist/plugins/tidb-run-store.js.map +1 -0
- package/dist/plugins/tidb-session-policy-store.d.ts +12 -0
- package/dist/plugins/tidb-session-policy-store.d.ts.map +1 -0
- package/dist/plugins/tidb-session-policy-store.js +88 -0
- package/dist/plugins/tidb-session-policy-store.js.map +1 -0
- package/dist/plugins/tidb-session-storage.d.ts +15 -0
- package/dist/plugins/tidb-session-storage.d.ts.map +1 -0
- package/dist/plugins/tidb-session-storage.js +101 -0
- package/dist/plugins/tidb-session-storage.js.map +1 -0
- package/dist/plugins/tidb-session-store.d.ts +46 -0
- package/dist/plugins/tidb-session-store.d.ts.map +1 -0
- package/dist/plugins/tidb-session-store.js +360 -0
- package/dist/plugins/tidb-session-store.js.map +1 -0
- package/dist/plugins/tidb-tool-result-store.d.ts +15 -0
- package/dist/plugins/tidb-tool-result-store.d.ts.map +1 -0
- package/dist/plugins/tidb-tool-result-store.js +41 -0
- package/dist/plugins/tidb-tool-result-store.js.map +1 -0
- package/dist/plugins/tidb-workflow-journal-store.d.ts +11 -0
- package/dist/plugins/tidb-workflow-journal-store.d.ts.map +1 -0
- package/dist/plugins/tidb-workflow-journal-store.js +28 -0
- package/dist/plugins/tidb-workflow-journal-store.js.map +1 -0
- package/dist/plugins/tidb-workflow-run-store.d.ts +61 -0
- package/dist/plugins/tidb-workflow-run-store.d.ts.map +1 -0
- package/dist/plugins/tidb-workflow-run-store.js +227 -0
- package/dist/plugins/tidb-workflow-run-store.js.map +1 -0
- package/dist/plugins/web-search.d.ts +27 -0
- package/dist/plugins/web-search.d.ts.map +1 -0
- package/dist/plugins/web-search.js +143 -0
- package/dist/plugins/web-search.js.map +1 -0
- package/dist/plugins/workflow-journal-limits.d.ts +2 -0
- package/dist/plugins/workflow-journal-limits.d.ts.map +1 -0
- package/dist/plugins/workflow-journal-limits.js +2 -0
- package/dist/plugins/workflow-journal-limits.js.map +1 -0
- package/dist/plugins/worktree-isolation.d.ts +16 -0
- package/dist/plugins/worktree-isolation.d.ts.map +1 -0
- package/dist/plugins/worktree-isolation.js +55 -0
- package/dist/plugins/worktree-isolation.js.map +1 -0
- package/dist/plugins/write-behind-counter.d.ts +43 -0
- package/dist/plugins/write-behind-counter.d.ts.map +1 -0
- package/dist/plugins/write-behind-counter.js +144 -0
- package/dist/plugins/write-behind-counter.js.map +1 -0
- package/dist/project-memory.d.ts +14 -0
- package/dist/project-memory.d.ts.map +1 -0
- package/dist/project-memory.js +96 -0
- package/dist/project-memory.js.map +1 -0
- package/dist/question.d.ts +42 -0
- package/dist/question.d.ts.map +1 -0
- package/dist/question.js +140 -0
- package/dist/question.js.map +1 -0
- package/dist/resource-suspend.d.ts +11 -0
- package/dist/resource-suspend.d.ts.map +1 -0
- package/dist/resource-suspend.js +6 -0
- package/dist/resource-suspend.js.map +1 -0
- package/dist/router/route-orchestration.d.ts +31 -0
- package/dist/router/route-orchestration.d.ts.map +1 -0
- package/dist/router/route-orchestration.js +49 -0
- package/dist/router/route-orchestration.js.map +1 -0
- package/dist/run-local.d.ts +26 -0
- package/dist/run-local.d.ts.map +1 -0
- package/dist/run-local.js +337 -0
- package/dist/run-local.js.map +1 -0
- package/dist/runs.d.ts +39 -0
- package/dist/runs.d.ts.map +1 -0
- package/dist/runs.js +392 -0
- package/dist/runs.js.map +1 -0
- package/dist/runtime-caps-resolver.d.ts +32 -0
- package/dist/runtime-caps-resolver.d.ts.map +1 -0
- package/dist/runtime-caps-resolver.js +134 -0
- package/dist/runtime-caps-resolver.js.map +1 -0
- package/dist/runtime-governance.d.ts +18 -0
- package/dist/runtime-governance.d.ts.map +1 -0
- package/dist/runtime-governance.js +103 -0
- package/dist/runtime-governance.js.map +1 -0
- package/dist/sandbox-pkg-source.d.ts +11 -0
- package/dist/sandbox-pkg-source.d.ts.map +1 -0
- package/dist/sandbox-pkg-source.js +56 -0
- package/dist/sandbox-pkg-source.js.map +1 -0
- package/dist/sealed-key.d.ts +29 -0
- package/dist/sealed-key.d.ts.map +1 -0
- package/dist/sealed-key.js +122 -0
- package/dist/sealed-key.js.map +1 -0
- package/dist/security.d.ts +153 -0
- package/dist/security.d.ts.map +1 -0
- package/dist/security.js +292 -0
- package/dist/security.js.map +1 -0
- package/dist/sema-registry.d.ts +187 -0
- package/dist/sema-registry.d.ts.map +1 -0
- package/dist/sema-registry.js +456 -0
- package/dist/sema-registry.js.map +1 -0
- package/dist/session-sync.d.ts +96 -0
- package/dist/session-sync.d.ts.map +1 -0
- package/dist/session-sync.js +181 -0
- package/dist/session-sync.js.map +1 -0
- package/dist/session-titler.d.ts +30 -0
- package/dist/session-titler.d.ts.map +1 -0
- package/dist/session-titler.js +77 -0
- package/dist/session-titler.js.map +1 -0
- package/dist/spec-fields.d.ts +5 -0
- package/dist/spec-fields.d.ts.map +1 -0
- package/dist/spec-fields.js +43 -0
- package/dist/spec-fields.js.map +1 -0
- package/dist/task-cwd.d.ts +15 -0
- package/dist/task-cwd.d.ts.map +1 -0
- package/dist/task-cwd.js +33 -0
- package/dist/task-cwd.js.map +1 -0
- package/dist/task-mcp.d.ts +20 -0
- package/dist/task-mcp.d.ts.map +1 -0
- package/dist/task-mcp.js +93 -0
- package/dist/task-mcp.js.map +1 -0
- package/dist/task-settings.d.ts +36 -0
- package/dist/task-settings.d.ts.map +1 -0
- package/dist/task-settings.js +141 -0
- package/dist/task-settings.js.map +1 -0
- package/dist/task-workflow.d.ts +25 -0
- package/dist/task-workflow.d.ts.map +1 -0
- package/dist/task-workflow.js +43 -0
- package/dist/task-workflow.js.map +1 -0
- package/dist/trace/artifacts.d.ts +17 -0
- package/dist/trace/artifacts.d.ts.map +1 -0
- package/dist/trace/artifacts.js +65 -0
- package/dist/trace/artifacts.js.map +1 -0
- package/dist/trace/project.d.ts +170 -0
- package/dist/trace/project.d.ts.map +1 -0
- package/dist/trace/project.js +239 -0
- package/dist/trace/project.js.map +1 -0
- package/dist/trace/redact.d.ts +5 -0
- package/dist/trace/redact.d.ts.map +1 -0
- package/dist/trace/redact.js +83 -0
- package/dist/trace/redact.js.map +1 -0
- package/dist/usage-analytics.d.ts +36 -0
- package/dist/usage-analytics.d.ts.map +1 -0
- package/dist/usage-analytics.js +89 -0
- package/dist/usage-analytics.js.map +1 -0
- package/package.json +78 -0
|
@@ -0,0 +1,975 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { HooksConfig, DEFAULT_HOOK_TIMEOUT_SECONDS, HOOK_EVENT_OWNER, } from "@sema-agent/registry-core/hooks";
|
|
3
|
+
import { redactSecrets } from "../trace/redact.js";
|
|
4
|
+
export const MAX_HOOK_ENTRIES_PER_EVENT = 32;
|
|
5
|
+
export const MAX_HOOK_COMMAND_CHARS = 8_192;
|
|
6
|
+
export const MAX_HOOK_TIMEOUT_SECONDS = 600;
|
|
7
|
+
export const MAX_HOOK_EVENT_TOTAL_SECONDS = 120;
|
|
8
|
+
export const MAX_HOOK_MATCHER_GROUPS = 16;
|
|
9
|
+
export const MAX_HOOK_HTTP_HEADERS = 32;
|
|
10
|
+
export const MAX_HOOK_OUTPUT_BYTES = 1024 * 1024;
|
|
11
|
+
const MAX_HOOK_FEEDBACK_CHARS = 4_096;
|
|
12
|
+
const MAX_TOOL_RESPONSE_CHARS = 32_768;
|
|
13
|
+
const MAX_TOOL_INPUT_CHARS = 262_144;
|
|
14
|
+
const HOOK_ENV_ALLOWLIST = [
|
|
15
|
+
"PATH", "HOME", "SHELL", "USER", "LOGNAME", "TERM", "TZ",
|
|
16
|
+
"LANG", "LC_ALL", "LC_CTYPE", "LC_MESSAGES", "TMPDIR",
|
|
17
|
+
];
|
|
18
|
+
function hookEnv(ctx) {
|
|
19
|
+
const env = { CLAUDE_PROJECT_DIR: ctx.cwd };
|
|
20
|
+
for (const k of HOOK_ENV_ALLOWLIST) {
|
|
21
|
+
const v = process.env[k];
|
|
22
|
+
if (typeof v === "string")
|
|
23
|
+
env[k] = v;
|
|
24
|
+
}
|
|
25
|
+
return { ...env, ...ctx.shellEnv };
|
|
26
|
+
}
|
|
27
|
+
const LIT_EVENTS = [
|
|
28
|
+
"PreToolUse",
|
|
29
|
+
"PostToolUse",
|
|
30
|
+
"PostToolUseFailure",
|
|
31
|
+
"PostToolBatch",
|
|
32
|
+
"UserPromptSubmit",
|
|
33
|
+
"Stop",
|
|
34
|
+
"StopFailure",
|
|
35
|
+
"PreCompact",
|
|
36
|
+
"PostCompact",
|
|
37
|
+
];
|
|
38
|
+
const BRAIN_TO_TURN_ERROR = {
|
|
39
|
+
auth: "authentication_failed",
|
|
40
|
+
rate_limit: "rate_limit",
|
|
41
|
+
invalid_request: "invalid_request",
|
|
42
|
+
server: "server_error",
|
|
43
|
+
max_output_tokens: "max_output_tokens",
|
|
44
|
+
};
|
|
45
|
+
function toAssistantTurnError(errorKind) {
|
|
46
|
+
return (errorKind !== undefined ? BRAIN_TO_TURN_ERROR[errorKind] : undefined) ?? "unknown";
|
|
47
|
+
}
|
|
48
|
+
export function parseHooksConfig(raw) {
|
|
49
|
+
const parsed = HooksConfig.safeParse(raw);
|
|
50
|
+
if (!parsed.success) {
|
|
51
|
+
const first = parsed.error.issues[0];
|
|
52
|
+
return { error: `settings.hooks: ${first ? `${first.path.join(".")}: ${first.message}` : "invalid shape"}` };
|
|
53
|
+
}
|
|
54
|
+
const config = parsed.data;
|
|
55
|
+
for (const [event, groups] of Object.entries(config)) {
|
|
56
|
+
if (!groups)
|
|
57
|
+
continue;
|
|
58
|
+
if (groups.length > MAX_HOOK_MATCHER_GROUPS) {
|
|
59
|
+
return { error: `settings.hooks.${event}: ${groups.length} matcher groups exceeds cap ${MAX_HOOK_MATCHER_GROUPS}` };
|
|
60
|
+
}
|
|
61
|
+
let entries = 0;
|
|
62
|
+
for (const group of groups) {
|
|
63
|
+
for (const entry of group.hooks) {
|
|
64
|
+
entries++;
|
|
65
|
+
if (entry.type === "command" && entry.command.length > MAX_HOOK_COMMAND_CHARS) {
|
|
66
|
+
return { error: `settings.hooks.${event}: command exceeds ${MAX_HOOK_COMMAND_CHARS} chars` };
|
|
67
|
+
}
|
|
68
|
+
if (entry.type === "http") {
|
|
69
|
+
if (entry.url.length > MAX_HOOK_COMMAND_CHARS) {
|
|
70
|
+
return { error: `settings.hooks.${event}: url exceeds ${MAX_HOOK_COMMAND_CHARS} chars` };
|
|
71
|
+
}
|
|
72
|
+
const headerEntries = Object.entries(entry.headers ?? {});
|
|
73
|
+
if (headerEntries.length > MAX_HOOK_HTTP_HEADERS) {
|
|
74
|
+
return { error: `settings.hooks.${event}: ${headerEntries.length} headers exceeds cap ${MAX_HOOK_HTTP_HEADERS}` };
|
|
75
|
+
}
|
|
76
|
+
const headerChars = headerEntries.reduce((n, [k, v]) => n + k.length + v.length, 0);
|
|
77
|
+
if (headerChars > MAX_HOOK_COMMAND_CHARS) {
|
|
78
|
+
return { error: `settings.hooks.${event}: headers exceed ${MAX_HOOK_COMMAND_CHARS} chars total` };
|
|
79
|
+
}
|
|
80
|
+
if ((entry.allowedEnvVars?.length ?? 0) > MAX_HOOK_HTTP_HEADERS) {
|
|
81
|
+
return { error: `settings.hooks.${event}: allowedEnvVars exceeds cap ${MAX_HOOK_HTTP_HEADERS}` };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (entries > MAX_HOOK_ENTRIES_PER_EVENT) {
|
|
87
|
+
return { error: `settings.hooks.${event}: ${entries} entries exceeds cap ${MAX_HOOK_ENTRIES_PER_EVENT}` };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return { config };
|
|
91
|
+
}
|
|
92
|
+
export function hookMatcherMatches(matcher, value) {
|
|
93
|
+
if (matcher === undefined || matcher === "" || matcher === "*")
|
|
94
|
+
return true;
|
|
95
|
+
if (matcher === value)
|
|
96
|
+
return true;
|
|
97
|
+
try {
|
|
98
|
+
return new RegExp(`^(?:${matcher})$`).test(value);
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return "invalid";
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export function hookIfMatches(cond, payload) {
|
|
105
|
+
if (cond.length > 500 || (cond.match(/\*/g)?.length ?? 0) > 16)
|
|
106
|
+
return "unevaluable";
|
|
107
|
+
const p = (payload ?? {});
|
|
108
|
+
const toolName = typeof p.tool_name === "string" ? p.tool_name : undefined;
|
|
109
|
+
if (!toolName)
|
|
110
|
+
return "unevaluable";
|
|
111
|
+
const m = /^([^(]+?)(?:\((.*)\))?$/s.exec(cond.trim());
|
|
112
|
+
if (!m)
|
|
113
|
+
return "unevaluable";
|
|
114
|
+
const nameOk = hookMatcherMatches(m[1].trim(), toolName);
|
|
115
|
+
if (nameOk === "invalid")
|
|
116
|
+
return "unevaluable";
|
|
117
|
+
if (!nameOk)
|
|
118
|
+
return "not_matched";
|
|
119
|
+
const spec = m[2];
|
|
120
|
+
if (spec === undefined || spec === "*" || spec === "")
|
|
121
|
+
return true;
|
|
122
|
+
const input = p.tool_input;
|
|
123
|
+
const primary = input && (typeof input.command === "string" ? input.command : typeof input.file_path === "string" ? input.file_path : typeof input.path === "string" ? input.path : undefined);
|
|
124
|
+
if (primary === undefined)
|
|
125
|
+
return "unevaluable";
|
|
126
|
+
try {
|
|
127
|
+
const re = new RegExp(`^${spec.split("*").map((s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join(".*")}$`);
|
|
128
|
+
return re.test(primary) ? true : "not_matched";
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
return "unevaluable";
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const MAX_LLM_ENTRIES_PER_EVENT = 4;
|
|
135
|
+
const DEFAULT_PROMPT_HOOK_TIMEOUT_SECONDS = 30;
|
|
136
|
+
const DEFAULT_AGENT_HOOK_TIMEOUT_SECONDS = 120;
|
|
137
|
+
function clip(s, n) {
|
|
138
|
+
return s.length > n ? `${s.slice(0, n)}…(${s.length})` : s;
|
|
139
|
+
}
|
|
140
|
+
function runCommandHook(entry, payload, ctx) {
|
|
141
|
+
return new Promise((resolve) => {
|
|
142
|
+
const timeoutMs = Math.min(entry.timeout ?? DEFAULT_HOOK_TIMEOUT_SECONDS, MAX_HOOK_TIMEOUT_SECONDS) * 1000;
|
|
143
|
+
let child;
|
|
144
|
+
try {
|
|
145
|
+
child = spawn("/bin/sh", ["-c", entry.command], {
|
|
146
|
+
cwd: ctx.cwd,
|
|
147
|
+
env: hookEnv(ctx),
|
|
148
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
149
|
+
detached: true,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
catch (e) {
|
|
153
|
+
resolve({ code: null, stdout: "", stderr: "", timedOut: false, spawnError: String(e) });
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
let stdout = "";
|
|
157
|
+
let stderr = "";
|
|
158
|
+
let timedOut = false;
|
|
159
|
+
let settled = false;
|
|
160
|
+
const settle = (code) => {
|
|
161
|
+
if (settled)
|
|
162
|
+
return;
|
|
163
|
+
settled = true;
|
|
164
|
+
clearTimeout(timer);
|
|
165
|
+
resolve({ code, stdout, stderr, timedOut });
|
|
166
|
+
};
|
|
167
|
+
const timer = setTimeout(() => {
|
|
168
|
+
timedOut = true;
|
|
169
|
+
try {
|
|
170
|
+
if (child.pid)
|
|
171
|
+
process.kill(-child.pid, "SIGKILL");
|
|
172
|
+
else
|
|
173
|
+
child.kill("SIGKILL");
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
child.kill("SIGKILL");
|
|
177
|
+
}
|
|
178
|
+
settle(null);
|
|
179
|
+
}, timeoutMs);
|
|
180
|
+
child.stdout?.on("data", (d) => {
|
|
181
|
+
if (stdout.length < MAX_HOOK_OUTPUT_BYTES)
|
|
182
|
+
stdout += d.toString("utf8").slice(0, MAX_HOOK_OUTPUT_BYTES - stdout.length);
|
|
183
|
+
});
|
|
184
|
+
child.stderr?.on("data", (d) => {
|
|
185
|
+
if (stderr.length < MAX_HOOK_OUTPUT_BYTES)
|
|
186
|
+
stderr += d.toString("utf8").slice(0, MAX_HOOK_OUTPUT_BYTES - stderr.length);
|
|
187
|
+
});
|
|
188
|
+
child.on("error", (e) => {
|
|
189
|
+
clearTimeout(timer);
|
|
190
|
+
if (!settled) {
|
|
191
|
+
settled = true;
|
|
192
|
+
resolve({ code: null, stdout, stderr, timedOut, spawnError: String(e) });
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
child.on("close", (code) => settle(code));
|
|
196
|
+
child.stdin?.on("error", () => { });
|
|
197
|
+
child.stdin?.end(`${JSON.stringify(boundedToolInputPayload(payload))}\n`);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
function fireAsyncCommandHook(entry, payload, ctx, event) {
|
|
201
|
+
try {
|
|
202
|
+
const rewake = entry.asyncRewake === true;
|
|
203
|
+
const timeoutMs = Math.min(entry.timeout ?? DEFAULT_HOOK_TIMEOUT_SECONDS, MAX_HOOK_TIMEOUT_SECONDS) * 1000;
|
|
204
|
+
const child = spawn("/bin/sh", ["-c", entry.command], {
|
|
205
|
+
cwd: ctx.cwd,
|
|
206
|
+
env: hookEnv(ctx),
|
|
207
|
+
stdio: ["pipe", "ignore", rewake ? "pipe" : "ignore"],
|
|
208
|
+
detached: true,
|
|
209
|
+
});
|
|
210
|
+
const timer = setTimeout(() => {
|
|
211
|
+
try {
|
|
212
|
+
if (child.pid)
|
|
213
|
+
process.kill(-child.pid, "SIGKILL");
|
|
214
|
+
else
|
|
215
|
+
child.kill("SIGKILL");
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
child.kill("SIGKILL");
|
|
219
|
+
}
|
|
220
|
+
}, timeoutMs);
|
|
221
|
+
timer.unref?.();
|
|
222
|
+
let stderr = "";
|
|
223
|
+
if (rewake) {
|
|
224
|
+
child.stderr?.on("data", (d) => {
|
|
225
|
+
if (stderr.length < MAX_HOOK_OUTPUT_BYTES)
|
|
226
|
+
stderr += d.toString("utf8").slice(0, MAX_HOOK_OUTPUT_BYTES - stderr.length);
|
|
227
|
+
});
|
|
228
|
+
child.stderr?.unref?.();
|
|
229
|
+
}
|
|
230
|
+
child.on("error", () => clearTimeout(timer));
|
|
231
|
+
child.on("close", (code) => {
|
|
232
|
+
clearTimeout(timer);
|
|
233
|
+
if (!rewake || code !== 2)
|
|
234
|
+
return;
|
|
235
|
+
const text = stderr.trim();
|
|
236
|
+
if (!ctx.wake) {
|
|
237
|
+
ctx.logger.warn("hook_async_rewake_dropped", { event, reason: "no_wake_pipeline" });
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (!text) {
|
|
241
|
+
ctx.logger.warn("hook_async_rewake_dropped", { event, reason: "empty_stderr" });
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
void ctx.wake(text).then((delivered) => {
|
|
245
|
+
if (delivered)
|
|
246
|
+
ctx.logger.info("hook_async_rewake_delivered", { event, chars: text.length });
|
|
247
|
+
else
|
|
248
|
+
ctx.logger.warn("hook_async_rewake_dropped", { event, reason: "no_live_stream" });
|
|
249
|
+
}, (e) => ctx.logger.warn("hook_async_rewake_dropped", { event, reason: "wake_failed", error: String(e).slice(0, 200) }));
|
|
250
|
+
});
|
|
251
|
+
child.stdin?.on("error", () => { });
|
|
252
|
+
child.stdin?.end(`${JSON.stringify(boundedToolInputPayload(payload))}\n`);
|
|
253
|
+
child.unref();
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
async function runLlmHook(entry, payload, ctx) {
|
|
259
|
+
const call = entry.type === "prompt" ? ctx.hookLlm : ctx.hookAgent;
|
|
260
|
+
if (!call)
|
|
261
|
+
return { code: null, stdout: "", stderr: "", timedOut: false, spawnError: `no ${entry.type} hook carrier wired on this deployment` };
|
|
262
|
+
const defSec = entry.type === "prompt" ? DEFAULT_PROMPT_HOOK_TIMEOUT_SECONDS : DEFAULT_AGENT_HOOK_TIMEOUT_SECONDS;
|
|
263
|
+
const timeoutMs = Math.min(entry.timeout ?? defSec, MAX_HOOK_TIMEOUT_SECONDS) * 1000;
|
|
264
|
+
const args = clip(JSON.stringify(boundedToolInputPayload(payload)), MAX_TOOL_INPUT_CHARS);
|
|
265
|
+
const prompt = entry.prompt.split("$ARGUMENTS").join(args);
|
|
266
|
+
const hardTop = new Promise((r) => setTimeout(() => r({ ok: false, error: "__hook_llm_hard_timeout__" }), timeoutMs + 5_000).unref?.());
|
|
267
|
+
const res = await Promise.race([call({ prompt, ...(entry.model ? { model: entry.model } : {}), timeoutMs }), hardTop]).catch((e) => ({ ok: false, error: String(e) }));
|
|
268
|
+
if (!res.ok) {
|
|
269
|
+
return res.error === "__hook_llm_hard_timeout__"
|
|
270
|
+
? { code: null, stdout: "", stderr: "", timedOut: true }
|
|
271
|
+
: { code: null, stdout: "", stderr: "", timedOut: false, spawnError: clip(res.error, 500) };
|
|
272
|
+
}
|
|
273
|
+
return { code: 0, stdout: clip(res.text, 1024 * 1024), stderr: "", timedOut: false };
|
|
274
|
+
}
|
|
275
|
+
async function runHttpHook(entry, payload, ctx) {
|
|
276
|
+
const timeoutMs = Math.min(entry.timeout ?? DEFAULT_HOOK_TIMEOUT_SECONDS, MAX_HOOK_TIMEOUT_SECONDS) * 1000;
|
|
277
|
+
const allowed = new Set(entry.allowedEnvVars ?? []);
|
|
278
|
+
const envSource = hookEnv(ctx);
|
|
279
|
+
const headers = { "content-type": "application/json" };
|
|
280
|
+
for (const [k, v] of Object.entries(entry.headers ?? {})) {
|
|
281
|
+
headers[k] = v.replace(/\$([A-Za-z_][A-Za-z0-9_]*)/g, (whole, name) => {
|
|
282
|
+
if (!allowed.has(name))
|
|
283
|
+
return whole;
|
|
284
|
+
const ev = envSource[name];
|
|
285
|
+
return typeof ev === "string" ? ev : whole;
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
const ac = new AbortController();
|
|
289
|
+
const timer = setTimeout(() => ac.abort(), timeoutMs);
|
|
290
|
+
try {
|
|
291
|
+
const res = await fetch(entry.url, {
|
|
292
|
+
method: "POST",
|
|
293
|
+
headers,
|
|
294
|
+
body: `${JSON.stringify(boundedToolInputPayload(payload))}\n`,
|
|
295
|
+
signal: ac.signal,
|
|
296
|
+
redirect: "error",
|
|
297
|
+
});
|
|
298
|
+
let body = "";
|
|
299
|
+
const reader = res.body?.getReader();
|
|
300
|
+
if (reader) {
|
|
301
|
+
const decoder = new TextDecoder();
|
|
302
|
+
let bytes = 0;
|
|
303
|
+
while (bytes < MAX_HOOK_OUTPUT_BYTES) {
|
|
304
|
+
const { done, value } = await reader.read();
|
|
305
|
+
if (done)
|
|
306
|
+
break;
|
|
307
|
+
const budget = MAX_HOOK_OUTPUT_BYTES - bytes;
|
|
308
|
+
const chunk = value.byteLength > budget ? value.subarray(0, budget) : value;
|
|
309
|
+
bytes += chunk.byteLength;
|
|
310
|
+
body += decoder.decode(chunk, { stream: true });
|
|
311
|
+
if (value.byteLength > budget)
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
body += decoder.decode();
|
|
315
|
+
await reader.cancel().catch(() => undefined);
|
|
316
|
+
}
|
|
317
|
+
if (res.ok) {
|
|
318
|
+
const trimmed = body.trim();
|
|
319
|
+
if (trimmed === "")
|
|
320
|
+
return { code: 0, stdout: "{}", stderr: "", timedOut: false };
|
|
321
|
+
if (!parseHookStdout(body)) {
|
|
322
|
+
ctx.logger.warn("hook_http_non_json_response", { url: clip(entry.url, 300), preview: clip(trimmed, 200) });
|
|
323
|
+
return { code: 0, stdout: "", stderr: "", timedOut: false };
|
|
324
|
+
}
|
|
325
|
+
return { code: 0, stdout: body, stderr: "", timedOut: false };
|
|
326
|
+
}
|
|
327
|
+
return { code: res.status, stdout: "", stderr: body, timedOut: false };
|
|
328
|
+
}
|
|
329
|
+
catch (e) {
|
|
330
|
+
if (ac.signal.aborted)
|
|
331
|
+
return { code: null, stdout: "", stderr: "", timedOut: true };
|
|
332
|
+
return { code: null, stdout: "", stderr: "", timedOut: false, spawnError: String(e) };
|
|
333
|
+
}
|
|
334
|
+
finally {
|
|
335
|
+
clearTimeout(timer);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
function boundedInputValue(v) {
|
|
339
|
+
let s;
|
|
340
|
+
try {
|
|
341
|
+
s = JSON.stringify(v);
|
|
342
|
+
}
|
|
343
|
+
catch {
|
|
344
|
+
return { __unserializable__: true };
|
|
345
|
+
}
|
|
346
|
+
if (s === undefined || s.length <= MAX_TOOL_INPUT_CHARS)
|
|
347
|
+
return v;
|
|
348
|
+
return { __truncated__: true, chars: s.length };
|
|
349
|
+
}
|
|
350
|
+
function boundedToolInputPayload(payload) {
|
|
351
|
+
if (!payload || typeof payload !== "object")
|
|
352
|
+
return payload;
|
|
353
|
+
const p = payload;
|
|
354
|
+
if (!("tool_input" in p))
|
|
355
|
+
return payload;
|
|
356
|
+
const bounded = boundedInputValue(p.tool_input);
|
|
357
|
+
return bounded === p.tool_input ? payload : { ...p, tool_input: bounded };
|
|
358
|
+
}
|
|
359
|
+
function parseHookStdout(stdout) {
|
|
360
|
+
const t = stdout.trim();
|
|
361
|
+
if (!t.startsWith("{"))
|
|
362
|
+
return undefined;
|
|
363
|
+
try {
|
|
364
|
+
const v = JSON.parse(t);
|
|
365
|
+
return v !== null && typeof v === "object" && !Array.isArray(v) ? v : undefined;
|
|
366
|
+
}
|
|
367
|
+
catch {
|
|
368
|
+
return undefined;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
async function runMatchingEntries(event, groups, matchValue, payload, ctx, onceFired, deadlineAt, keyBase) {
|
|
372
|
+
const results = [];
|
|
373
|
+
let llmEntries = 0;
|
|
374
|
+
let gi = -1;
|
|
375
|
+
for (const group of groups) {
|
|
376
|
+
gi++;
|
|
377
|
+
const m = hookMatcherMatches(group.matcher, matchValue);
|
|
378
|
+
if (m === "invalid") {
|
|
379
|
+
ctx.logger.warn("hook_matcher_invalid", { event, matcher: clip(group.matcher ?? "", 200) });
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
if (!m)
|
|
383
|
+
continue;
|
|
384
|
+
let ei = -1;
|
|
385
|
+
for (const entry of group.hooks) {
|
|
386
|
+
ei++;
|
|
387
|
+
const onceKey = `${keyBase ?? event}:${gi}:${ei}`;
|
|
388
|
+
if (entry.once && onceFired.has(onceKey))
|
|
389
|
+
continue;
|
|
390
|
+
if (entry.type !== "command" && entry.type !== "http" && entry.type !== "prompt" && entry.type !== "agent") {
|
|
391
|
+
ctx.logger.warn("hook_entries_skipped", { event, type: entry.type, reason: "type_not_supported" });
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
if (entry.type === "prompt" || entry.type === "agent") {
|
|
395
|
+
const carrier = entry.type === "prompt" ? ctx.hookLlm : ctx.hookAgent;
|
|
396
|
+
if (!carrier) {
|
|
397
|
+
ctx.logger.warn("hook_entries_skipped", { event, type: entry.type, reason: "llm_carrier_unavailable" });
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
if (llmEntries >= MAX_LLM_ENTRIES_PER_EVENT) {
|
|
401
|
+
ctx.logger.warn("hook_entries_skipped", { event, type: entry.type, reason: "llm_entries_per_event_cap", cap: MAX_LLM_ENTRIES_PER_EVENT });
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
if (entry.type === "command" && entry.shell === "powershell") {
|
|
406
|
+
ctx.logger.warn("hook_entries_skipped", { event, type: entry.type, reason: "powershell_not_supported" });
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
if (entry.if !== undefined) {
|
|
410
|
+
const iv = hookIfMatches(entry.if, payload);
|
|
411
|
+
if (iv !== true) {
|
|
412
|
+
ctx.logger.warn("hook_entries_skipped", { event, type: entry.type, reason: iv === "unevaluable" ? "if_unevaluable" : "if_not_matched", if: clip(entry.if, 200) });
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
if (entry.type === "command" && (entry.async || entry.asyncRewake)) {
|
|
417
|
+
if (entry.once)
|
|
418
|
+
onceFired.add(onceKey);
|
|
419
|
+
fireAsyncCommandHook(entry, payload, ctx, event);
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
if (Date.now() > deadlineAt) {
|
|
423
|
+
ctx.logger.warn("hook_event_deadline_exceeded", { event, budgetSec: MAX_HOOK_EVENT_TOTAL_SECONDS });
|
|
424
|
+
return results;
|
|
425
|
+
}
|
|
426
|
+
if (entry.once)
|
|
427
|
+
onceFired.add(onceKey);
|
|
428
|
+
if (entry.type === "prompt" || entry.type === "agent")
|
|
429
|
+
llmEntries++;
|
|
430
|
+
const run = entry.type === "http" ? await runHttpHook(entry, payload, ctx)
|
|
431
|
+
: entry.type === "prompt" || entry.type === "agent" ? await runLlmHook(entry, payload, ctx)
|
|
432
|
+
: await runCommandHook(entry, payload, ctx);
|
|
433
|
+
if (run.spawnError) {
|
|
434
|
+
ctx.logger.warn(entry.type === "http" ? "hook_http_request_failed" : entry.type === "prompt" || entry.type === "agent" ? "hook_llm_failed" : "hook_command_spawn_failed", { event, type: entry.type, error: clip(run.spawnError, 300) });
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
if (run.timedOut) {
|
|
438
|
+
ctx.logger.warn("hook_command_timeout", { event, timeoutSec: Math.min(entry.timeout ?? DEFAULT_HOOK_TIMEOUT_SECONDS, MAX_HOOK_TIMEOUT_SECONDS) });
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
results.push({ entry, run });
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
return results;
|
|
445
|
+
}
|
|
446
|
+
function basePayload(ctx) {
|
|
447
|
+
return {
|
|
448
|
+
session_id: ctx.sessionId,
|
|
449
|
+
transcript_path: "",
|
|
450
|
+
cwd: ctx.cwd,
|
|
451
|
+
...(ctx.permissionMode ? { permission_mode: ctx.permissionMode } : {}),
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
function ignoreMatchers(groups) {
|
|
455
|
+
return groups.map((g) => (g.matcher === undefined ? g : { ...g, matcher: undefined }));
|
|
456
|
+
}
|
|
457
|
+
async function runObserveOnlyEvent(event, groups, matchValue, payload, ctx, onceFired) {
|
|
458
|
+
const singles = await runMatchingEntries(event, groups, matchValue, payload, ctx, onceFired, Date.now() + MAX_HOOK_EVENT_TOTAL_SECONDS * 1000);
|
|
459
|
+
for (const { run } of singles) {
|
|
460
|
+
if (run.code !== 0) {
|
|
461
|
+
ctx.logger.warn("hook_command_failed", { event, code: run.code, stderr: clip(run.stderr, 300) });
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
464
|
+
const out = parseHookStdout(run.stdout);
|
|
465
|
+
if (!out)
|
|
466
|
+
continue;
|
|
467
|
+
if (typeof out.systemMessage === "string")
|
|
468
|
+
ctx.logger.warn("hook_system_message", { event, message: clip(out.systemMessage, 500) });
|
|
469
|
+
if (out.decision !== undefined || out.continue === false || out.hookSpecificOutput !== undefined) {
|
|
470
|
+
ctx.logger.warn("hook_result_unsupported", { event });
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
export function buildTaskHooks(config, ctx) {
|
|
475
|
+
const configured = Object.keys(config).filter((e) => (config[e]?.length ?? 0) > 0);
|
|
476
|
+
const dark = configured.filter((e) => HOOK_EVENT_OWNER[e] === "engine" && !LIT_EVENTS.includes(e));
|
|
477
|
+
if (dark.length > 0) {
|
|
478
|
+
ctx.logger.warn("hook_events_not_fired", { events: dark, phase: 2 });
|
|
479
|
+
}
|
|
480
|
+
const shellOwned = configured.filter((e) => HOOK_EVENT_OWNER[e] === "shell");
|
|
481
|
+
if (shellOwned.length > 0) {
|
|
482
|
+
ctx.logger.debug("hook_events_shell_owned", { events: shellOwned });
|
|
483
|
+
}
|
|
484
|
+
const lit = (e) => {
|
|
485
|
+
const groups = config[e];
|
|
486
|
+
return groups && groups.length > 0 ? groups : undefined;
|
|
487
|
+
};
|
|
488
|
+
const pre = lit("PreToolUse");
|
|
489
|
+
const post = lit("PostToolUse");
|
|
490
|
+
const postFailure = lit("PostToolUseFailure");
|
|
491
|
+
const postBatch = lit("PostToolBatch");
|
|
492
|
+
const promptSubmit = lit("UserPromptSubmit");
|
|
493
|
+
const stopEntries = lit("Stop");
|
|
494
|
+
const stopFailureEntries = lit("StopFailure");
|
|
495
|
+
const preCompactEntries = lit("PreCompact");
|
|
496
|
+
const postCompactEntries = lit("PostCompact");
|
|
497
|
+
if (!pre && !post && !postFailure && !postBatch && !promptSubmit && !stopEntries && !stopFailureEntries && !preCompactEntries && !postCompactEntries) {
|
|
498
|
+
return undefined;
|
|
499
|
+
}
|
|
500
|
+
const onceFired = new Set();
|
|
501
|
+
const hooks = {};
|
|
502
|
+
if (pre) {
|
|
503
|
+
hooks.preToolUse = async (toolName, input, tctx) => {
|
|
504
|
+
let currentInput = input;
|
|
505
|
+
let rewritten = false;
|
|
506
|
+
let asked;
|
|
507
|
+
const contexts = [];
|
|
508
|
+
const deadlineAt = Date.now() + MAX_HOOK_EVENT_TOTAL_SECONDS * 1000;
|
|
509
|
+
let gi = -1;
|
|
510
|
+
for (const group of pre) {
|
|
511
|
+
gi++;
|
|
512
|
+
const m = hookMatcherMatches(group.matcher, toolName);
|
|
513
|
+
if (m === "invalid") {
|
|
514
|
+
ctx.logger.warn("hook_matcher_invalid", { event: "PreToolUse", matcher: clip(group.matcher ?? "", 200) });
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
if (!m)
|
|
518
|
+
continue;
|
|
519
|
+
const payload = {
|
|
520
|
+
...basePayload(ctx),
|
|
521
|
+
hook_event_name: "PreToolUse",
|
|
522
|
+
tool_name: toolName,
|
|
523
|
+
tool_input: currentInput,
|
|
524
|
+
tool_use_id: tctx.toolCallId,
|
|
525
|
+
};
|
|
526
|
+
const singles = await runMatchingEntries("PreToolUse", [{ ...group, matcher: undefined }], toolName, payload, ctx, onceFired, deadlineAt, `PreToolUse:${gi}`);
|
|
527
|
+
for (const { run } of singles) {
|
|
528
|
+
if (run.code === 2) {
|
|
529
|
+
const reason = clip(run.stderr.trim(), MAX_HOOK_FEEDBACK_CHARS) || "blocked by a PreToolUse hook";
|
|
530
|
+
return { action: "deny", message: reason, ...(contexts.length ? { additionalContext: contexts.join("\n") } : {}) };
|
|
531
|
+
}
|
|
532
|
+
if (run.code !== 0) {
|
|
533
|
+
ctx.logger.warn("hook_command_failed", { event: "PreToolUse", code: run.code, stderr: clip(run.stderr, 300) });
|
|
534
|
+
continue;
|
|
535
|
+
}
|
|
536
|
+
const out = parseHookStdout(run.stdout);
|
|
537
|
+
if (!out)
|
|
538
|
+
continue;
|
|
539
|
+
if (typeof out.systemMessage === "string")
|
|
540
|
+
ctx.logger.warn("hook_system_message", { event: "PreToolUse", message: clip(out.systemMessage, 500) });
|
|
541
|
+
if (out.continue === false) {
|
|
542
|
+
const reason = clip(typeof out.stopReason === "string" ? out.stopReason : "hook requested stop", MAX_HOOK_FEEDBACK_CHARS);
|
|
543
|
+
return { action: "deny", message: reason, ...(contexts.length ? { additionalContext: contexts.join("\n") } : {}) };
|
|
544
|
+
}
|
|
545
|
+
if (out.decision === "block") {
|
|
546
|
+
const reason = clip(typeof out.reason === "string" ? out.reason : "blocked by a PreToolUse hook", MAX_HOOK_FEEDBACK_CHARS);
|
|
547
|
+
return { action: "deny", message: reason, ...(contexts.length ? { additionalContext: contexts.join("\n") } : {}) };
|
|
548
|
+
}
|
|
549
|
+
const hso = out.hookSpecificOutput;
|
|
550
|
+
if (hso !== null && typeof hso === "object" && hso.hookEventName === "PreToolUse") {
|
|
551
|
+
const h = hso;
|
|
552
|
+
if (typeof h.additionalContext === "string")
|
|
553
|
+
contexts.push(clip(h.additionalContext, MAX_HOOK_FEEDBACK_CHARS));
|
|
554
|
+
const decision = h.permissionDecision;
|
|
555
|
+
if (decision === "deny") {
|
|
556
|
+
const reason = clip(typeof h.permissionDecisionReason === "string" ? h.permissionDecisionReason : "denied by a PreToolUse hook", MAX_HOOK_FEEDBACK_CHARS);
|
|
557
|
+
return { action: "deny", message: reason, ...(contexts.length ? { additionalContext: contexts.join("\n") } : {}) };
|
|
558
|
+
}
|
|
559
|
+
if (decision === "ask") {
|
|
560
|
+
asked = clip(typeof h.permissionDecisionReason === "string" ? h.permissionDecisionReason : "a PreToolUse hook requires approval", MAX_HOOK_FEEDBACK_CHARS);
|
|
561
|
+
}
|
|
562
|
+
if (decision === "allow" || decision === undefined) {
|
|
563
|
+
if (h.updatedInput !== null && typeof h.updatedInput === "object") {
|
|
564
|
+
currentInput = h.updatedInput;
|
|
565
|
+
rewritten = true;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
if (asked !== undefined) {
|
|
572
|
+
return {
|
|
573
|
+
action: "ask",
|
|
574
|
+
message: asked,
|
|
575
|
+
...(rewritten ? { updatedInput: currentInput } : {}),
|
|
576
|
+
...(contexts.length ? { additionalContext: contexts.join("\n") } : {}),
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
if (rewritten || contexts.length > 0) {
|
|
580
|
+
return {
|
|
581
|
+
action: "allow",
|
|
582
|
+
...(rewritten ? { updatedInput: currentInput } : {}),
|
|
583
|
+
...(contexts.length ? { additionalContext: contexts.join("\n") } : {}),
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
return undefined;
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
if (post) {
|
|
590
|
+
hooks.postToolUse = async (toolName, input, output, tctx) => {
|
|
591
|
+
const contexts = [];
|
|
592
|
+
const responseText = output.content
|
|
593
|
+
.map((c) => (c && typeof c === "object" && typeof c.text === "string" ? c.text : ""))
|
|
594
|
+
.join("");
|
|
595
|
+
const payload = {
|
|
596
|
+
...basePayload(ctx),
|
|
597
|
+
hook_event_name: "PostToolUse",
|
|
598
|
+
tool_name: toolName,
|
|
599
|
+
tool_input: input,
|
|
600
|
+
tool_response: { isError: output.isError, text: clip(responseText, MAX_TOOL_RESPONSE_CHARS) },
|
|
601
|
+
tool_use_id: tctx.toolCallId,
|
|
602
|
+
};
|
|
603
|
+
const singles = await runMatchingEntries("PostToolUse", post, toolName, payload, ctx, onceFired, Date.now() + MAX_HOOK_EVENT_TOTAL_SECONDS * 1000);
|
|
604
|
+
for (const { run } of singles) {
|
|
605
|
+
if (run.code === 2) {
|
|
606
|
+
const fb = clip(run.stderr.trim(), MAX_HOOK_FEEDBACK_CHARS);
|
|
607
|
+
if (fb)
|
|
608
|
+
contexts.push(fb);
|
|
609
|
+
continue;
|
|
610
|
+
}
|
|
611
|
+
if (run.code !== 0) {
|
|
612
|
+
ctx.logger.warn("hook_command_failed", { event: "PostToolUse", code: run.code, stderr: clip(run.stderr, 300) });
|
|
613
|
+
continue;
|
|
614
|
+
}
|
|
615
|
+
const out = parseHookStdout(run.stdout);
|
|
616
|
+
if (!out)
|
|
617
|
+
continue;
|
|
618
|
+
if (typeof out.systemMessage === "string")
|
|
619
|
+
ctx.logger.warn("hook_system_message", { event: "PostToolUse", message: clip(out.systemMessage, 500) });
|
|
620
|
+
if (out.continue === false) {
|
|
621
|
+
ctx.logger.warn("hook_continue_false_unsupported", { event: "PostToolUse" });
|
|
622
|
+
}
|
|
623
|
+
if (out.decision === "block" && typeof out.reason === "string")
|
|
624
|
+
contexts.push(clip(out.reason, MAX_HOOK_FEEDBACK_CHARS));
|
|
625
|
+
const hso = out.hookSpecificOutput;
|
|
626
|
+
if (hso !== null && typeof hso === "object" && hso.hookEventName === "PostToolUse") {
|
|
627
|
+
const h = hso;
|
|
628
|
+
if (typeof h.additionalContext === "string")
|
|
629
|
+
contexts.push(clip(h.additionalContext, MAX_HOOK_FEEDBACK_CHARS));
|
|
630
|
+
if (h.updatedMCPToolOutput !== undefined) {
|
|
631
|
+
ctx.logger.warn("hook_updated_mcp_output_unsupported", { event: "PostToolUse" });
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
return contexts.length > 0 ? { additionalContext: contexts.join("\n") } : undefined;
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
if (postFailure) {
|
|
639
|
+
hooks.postToolUseFailure = async (toolName, input, f, tctx) => {
|
|
640
|
+
const contexts = [];
|
|
641
|
+
const payload = {
|
|
642
|
+
...basePayload(ctx),
|
|
643
|
+
hook_event_name: "PostToolUseFailure",
|
|
644
|
+
tool_name: toolName,
|
|
645
|
+
tool_input: input,
|
|
646
|
+
tool_use_id: tctx.toolCallId,
|
|
647
|
+
error: clip(f.error, MAX_TOOL_RESPONSE_CHARS),
|
|
648
|
+
is_interrupt: f.isInterrupt,
|
|
649
|
+
};
|
|
650
|
+
const singles = await runMatchingEntries("PostToolUseFailure", postFailure, toolName, payload, ctx, onceFired, Date.now() + MAX_HOOK_EVENT_TOTAL_SECONDS * 1000);
|
|
651
|
+
for (const { run } of singles) {
|
|
652
|
+
if (run.code === 2) {
|
|
653
|
+
const fb = clip(run.stderr.trim(), MAX_HOOK_FEEDBACK_CHARS);
|
|
654
|
+
if (fb)
|
|
655
|
+
contexts.push(fb);
|
|
656
|
+
continue;
|
|
657
|
+
}
|
|
658
|
+
if (run.code !== 0) {
|
|
659
|
+
ctx.logger.warn("hook_command_failed", { event: "PostToolUseFailure", code: run.code, stderr: clip(run.stderr, 300) });
|
|
660
|
+
continue;
|
|
661
|
+
}
|
|
662
|
+
const out = parseHookStdout(run.stdout);
|
|
663
|
+
if (!out)
|
|
664
|
+
continue;
|
|
665
|
+
if (typeof out.systemMessage === "string")
|
|
666
|
+
ctx.logger.warn("hook_system_message", { event: "PostToolUseFailure", message: clip(out.systemMessage, 500) });
|
|
667
|
+
if (out.continue === false)
|
|
668
|
+
ctx.logger.warn("hook_continue_false_unsupported", { event: "PostToolUseFailure" });
|
|
669
|
+
if (out.decision === "block" && typeof out.reason === "string")
|
|
670
|
+
contexts.push(clip(out.reason, MAX_HOOK_FEEDBACK_CHARS));
|
|
671
|
+
const hso = out.hookSpecificOutput;
|
|
672
|
+
if (hso !== null && typeof hso === "object" && hso.hookEventName === "PostToolUseFailure") {
|
|
673
|
+
const h = hso;
|
|
674
|
+
if (typeof h.additionalContext === "string")
|
|
675
|
+
contexts.push(clip(h.additionalContext, MAX_HOOK_FEEDBACK_CHARS));
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
return contexts.length > 0 ? { additionalContext: contexts.join("\n") } : undefined;
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
if (postBatch) {
|
|
682
|
+
hooks.postToolBatch = async (calls) => {
|
|
683
|
+
const contexts = [];
|
|
684
|
+
const payload = {
|
|
685
|
+
...basePayload(ctx),
|
|
686
|
+
hook_event_name: "PostToolBatch",
|
|
687
|
+
tool_calls: calls.map((c) => ({
|
|
688
|
+
tool_name: c.toolName,
|
|
689
|
+
tool_input: boundedInputValue(c.input),
|
|
690
|
+
tool_use_id: c.toolCallId,
|
|
691
|
+
tool_response: { isError: c.isError, ...(c.response !== undefined ? { text: clip(c.response, MAX_TOOL_RESPONSE_CHARS) } : {}) },
|
|
692
|
+
})),
|
|
693
|
+
};
|
|
694
|
+
const singles = await runMatchingEntries("PostToolBatch", ignoreMatchers(postBatch), "", payload, ctx, onceFired, Date.now() + MAX_HOOK_EVENT_TOTAL_SECONDS * 1000);
|
|
695
|
+
for (const { run } of singles) {
|
|
696
|
+
if (run.code === 2) {
|
|
697
|
+
const fb = clip(run.stderr.trim(), MAX_HOOK_FEEDBACK_CHARS);
|
|
698
|
+
if (fb)
|
|
699
|
+
contexts.push(fb);
|
|
700
|
+
continue;
|
|
701
|
+
}
|
|
702
|
+
if (run.code !== 0) {
|
|
703
|
+
ctx.logger.warn("hook_command_failed", { event: "PostToolBatch", code: run.code, stderr: clip(run.stderr, 300) });
|
|
704
|
+
continue;
|
|
705
|
+
}
|
|
706
|
+
const out = parseHookStdout(run.stdout);
|
|
707
|
+
if (!out)
|
|
708
|
+
continue;
|
|
709
|
+
if (typeof out.systemMessage === "string")
|
|
710
|
+
ctx.logger.warn("hook_system_message", { event: "PostToolBatch", message: clip(out.systemMessage, 500) });
|
|
711
|
+
if (out.continue === false)
|
|
712
|
+
ctx.logger.warn("hook_continue_false_unsupported", { event: "PostToolBatch" });
|
|
713
|
+
if (out.decision === "block" && typeof out.reason === "string")
|
|
714
|
+
contexts.push(clip(out.reason, MAX_HOOK_FEEDBACK_CHARS));
|
|
715
|
+
if (out.hookSpecificOutput !== undefined)
|
|
716
|
+
ctx.logger.warn("hook_result_unsupported", { event: "PostToolBatch" });
|
|
717
|
+
}
|
|
718
|
+
return contexts.length > 0 ? { additionalContext: contexts.join("\n") } : undefined;
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
if (promptSubmit) {
|
|
722
|
+
hooks.userPromptSubmit = async (prompt) => {
|
|
723
|
+
const contexts = [];
|
|
724
|
+
const payload = { ...basePayload(ctx), hook_event_name: "UserPromptSubmit", prompt: clip(prompt, MAX_TOOL_INPUT_CHARS) };
|
|
725
|
+
const singles = await runMatchingEntries("UserPromptSubmit", ignoreMatchers(promptSubmit), "", payload, ctx, onceFired, Date.now() + MAX_HOOK_EVENT_TOTAL_SECONDS * 1000);
|
|
726
|
+
for (const { run } of singles) {
|
|
727
|
+
if (run.code === 2) {
|
|
728
|
+
const reason = clip(run.stderr.trim(), MAX_HOOK_FEEDBACK_CHARS) || "blocked by a UserPromptSubmit hook";
|
|
729
|
+
return { block: reason, ...(contexts.length ? { additionalContext: contexts.join("\n") } : {}) };
|
|
730
|
+
}
|
|
731
|
+
if (run.code !== 0) {
|
|
732
|
+
ctx.logger.warn("hook_command_failed", { event: "UserPromptSubmit", code: run.code, stderr: clip(run.stderr, 300) });
|
|
733
|
+
continue;
|
|
734
|
+
}
|
|
735
|
+
const out = parseHookStdout(run.stdout);
|
|
736
|
+
if (!out)
|
|
737
|
+
continue;
|
|
738
|
+
if (typeof out.systemMessage === "string")
|
|
739
|
+
ctx.logger.warn("hook_system_message", { event: "UserPromptSubmit", message: clip(out.systemMessage, 500) });
|
|
740
|
+
if (out.continue === false) {
|
|
741
|
+
const reason = clip(typeof out.stopReason === "string" ? out.stopReason : "hook requested stop", MAX_HOOK_FEEDBACK_CHARS);
|
|
742
|
+
return { block: reason, ...(contexts.length ? { additionalContext: contexts.join("\n") } : {}) };
|
|
743
|
+
}
|
|
744
|
+
if (out.decision === "block") {
|
|
745
|
+
const reason = clip(typeof out.reason === "string" ? out.reason : "blocked by a UserPromptSubmit hook", MAX_HOOK_FEEDBACK_CHARS);
|
|
746
|
+
return { block: reason, ...(contexts.length ? { additionalContext: contexts.join("\n") } : {}) };
|
|
747
|
+
}
|
|
748
|
+
const hso = out.hookSpecificOutput;
|
|
749
|
+
if (hso !== null && typeof hso === "object" && hso.hookEventName === "UserPromptSubmit") {
|
|
750
|
+
const h = hso;
|
|
751
|
+
if (typeof h.additionalContext === "string")
|
|
752
|
+
contexts.push(clip(h.additionalContext, MAX_HOOK_FEEDBACK_CHARS));
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
return contexts.length > 0 ? { additionalContext: contexts.join("\n") } : undefined;
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
if (stopEntries) {
|
|
759
|
+
hooks.stop = async (sctx) => {
|
|
760
|
+
const payload = { ...basePayload(ctx), hook_event_name: "Stop", stop_hook_active: sctx.stopHookActive };
|
|
761
|
+
const singles = await runMatchingEntries("Stop", ignoreMatchers(stopEntries), "", payload, ctx, onceFired, Date.now() + MAX_HOOK_EVENT_TOTAL_SECONDS * 1000);
|
|
762
|
+
let block;
|
|
763
|
+
let sawContinueFalse = false;
|
|
764
|
+
for (const { run } of singles) {
|
|
765
|
+
if (run.code === 2) {
|
|
766
|
+
if (block === undefined)
|
|
767
|
+
block = clip(run.stderr.trim(), MAX_HOOK_FEEDBACK_CHARS) || "blocked by a Stop hook";
|
|
768
|
+
continue;
|
|
769
|
+
}
|
|
770
|
+
if (run.code !== 0) {
|
|
771
|
+
ctx.logger.warn("hook_command_failed", { event: "Stop", code: run.code, stderr: clip(run.stderr, 300) });
|
|
772
|
+
continue;
|
|
773
|
+
}
|
|
774
|
+
const out = parseHookStdout(run.stdout);
|
|
775
|
+
if (!out)
|
|
776
|
+
continue;
|
|
777
|
+
if (typeof out.systemMessage === "string")
|
|
778
|
+
ctx.logger.warn("hook_system_message", { event: "Stop", message: clip(out.systemMessage, 500) });
|
|
779
|
+
if (out.continue === false)
|
|
780
|
+
sawContinueFalse = true;
|
|
781
|
+
if (out.decision === "block" && block === undefined) {
|
|
782
|
+
block = clip(typeof out.reason === "string" ? out.reason : "blocked by a Stop hook", MAX_HOOK_FEEDBACK_CHARS);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
if (sawContinueFalse)
|
|
786
|
+
return undefined;
|
|
787
|
+
return block !== undefined ? { block } : undefined;
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
if (stopFailureEntries) {
|
|
791
|
+
hooks.stopFailure = async (fctx) => {
|
|
792
|
+
const turnError = toAssistantTurnError(fctx.errorKind);
|
|
793
|
+
const payload = {
|
|
794
|
+
...basePayload(ctx),
|
|
795
|
+
hook_event_name: "StopFailure",
|
|
796
|
+
error: turnError,
|
|
797
|
+
...(fctx.error ? { error_details: clip(redactSecrets(fctx.error), MAX_HOOK_FEEDBACK_CHARS) } : {}),
|
|
798
|
+
};
|
|
799
|
+
await runObserveOnlyEvent("StopFailure", stopFailureEntries, turnError, payload, ctx, onceFired);
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
if (preCompactEntries) {
|
|
803
|
+
hooks.preCompact = async (pctx) => {
|
|
804
|
+
const payload = {
|
|
805
|
+
...basePayload(ctx),
|
|
806
|
+
hook_event_name: "PreCompact",
|
|
807
|
+
trigger: pctx.trigger,
|
|
808
|
+
custom_instructions: pctx.customInstructions ?? null,
|
|
809
|
+
};
|
|
810
|
+
const singles = await runMatchingEntries("PreCompact", preCompactEntries, pctx.trigger, payload, ctx, onceFired, Date.now() + MAX_HOOK_EVENT_TOTAL_SECONDS * 1000);
|
|
811
|
+
for (const { run } of singles) {
|
|
812
|
+
if (run.code === 2) {
|
|
813
|
+
return { block: clip(run.stderr.trim(), MAX_HOOK_FEEDBACK_CHARS) || "blocked by a PreCompact hook" };
|
|
814
|
+
}
|
|
815
|
+
if (run.code !== 0) {
|
|
816
|
+
ctx.logger.warn("hook_command_failed", { event: "PreCompact", code: run.code, stderr: clip(run.stderr, 300) });
|
|
817
|
+
continue;
|
|
818
|
+
}
|
|
819
|
+
const out = parseHookStdout(run.stdout);
|
|
820
|
+
if (!out)
|
|
821
|
+
continue;
|
|
822
|
+
if (typeof out.systemMessage === "string")
|
|
823
|
+
ctx.logger.warn("hook_system_message", { event: "PreCompact", message: clip(out.systemMessage, 500) });
|
|
824
|
+
if (out.continue === false) {
|
|
825
|
+
ctx.logger.warn("hook_continue_false_unsupported", { event: "PreCompact" });
|
|
826
|
+
}
|
|
827
|
+
if (out.decision === "block") {
|
|
828
|
+
return { block: clip(typeof out.reason === "string" ? out.reason : "blocked by a PreCompact hook", MAX_HOOK_FEEDBACK_CHARS) };
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
return undefined;
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
if (postCompactEntries) {
|
|
835
|
+
hooks.postCompact = async (cctx) => {
|
|
836
|
+
const payload = {
|
|
837
|
+
...basePayload(ctx),
|
|
838
|
+
hook_event_name: "PostCompact",
|
|
839
|
+
trigger: cctx.trigger,
|
|
840
|
+
compact_summary: clip(cctx.summary, MAX_TOOL_RESPONSE_CHARS),
|
|
841
|
+
};
|
|
842
|
+
await runObserveOnlyEvent("PostCompact", postCompactEntries, cctx.trigger, payload, ctx, onceFired);
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
return hooks;
|
|
846
|
+
}
|
|
847
|
+
export function composeHooks(deployment, task) {
|
|
848
|
+
if (!deployment)
|
|
849
|
+
return task;
|
|
850
|
+
const d = deployment;
|
|
851
|
+
const t = task;
|
|
852
|
+
const out = {};
|
|
853
|
+
if (d.preToolUse || t.preToolUse) {
|
|
854
|
+
out.preToolUse = async (toolName, input, ctx) => {
|
|
855
|
+
let current = input;
|
|
856
|
+
const contexts = [];
|
|
857
|
+
let asked;
|
|
858
|
+
for (const slot of [d.preToolUse?.bind(d), t.preToolUse?.bind(t)]) {
|
|
859
|
+
if (!slot)
|
|
860
|
+
continue;
|
|
861
|
+
const r = await slot(toolName, current, ctx);
|
|
862
|
+
if (!r)
|
|
863
|
+
continue;
|
|
864
|
+
if (r.additionalContext)
|
|
865
|
+
contexts.push(r.additionalContext);
|
|
866
|
+
if (r.action === "deny")
|
|
867
|
+
return { ...r, ...(contexts.length ? { additionalContext: contexts.join("\n") } : {}) };
|
|
868
|
+
if (r.action === "ask")
|
|
869
|
+
asked = r;
|
|
870
|
+
if (r.action === "allow" && r.updatedInput !== undefined) {
|
|
871
|
+
current = r.updatedInput;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
if (asked) {
|
|
875
|
+
const askedUpdated = asked.updatedInput;
|
|
876
|
+
return {
|
|
877
|
+
...asked,
|
|
878
|
+
...(askedUpdated === undefined && current !== input ? { updatedInput: current } : {}),
|
|
879
|
+
...(contexts.length ? { additionalContext: contexts.join("\n") } : {}),
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
if (current !== input || contexts.length > 0) {
|
|
883
|
+
return {
|
|
884
|
+
action: "allow",
|
|
885
|
+
...(current !== input ? { updatedInput: current } : {}),
|
|
886
|
+
...(contexts.length ? { additionalContext: contexts.join("\n") } : {}),
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
return undefined;
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
if (d.postToolUse || t.postToolUse) {
|
|
893
|
+
out.postToolUse = async (toolName, input, output, ctx) => {
|
|
894
|
+
const rd = d.postToolUse ? await d.postToolUse(toolName, input, output, ctx) : undefined;
|
|
895
|
+
const rt = t.postToolUse ? await t.postToolUse(toolName, input, output, ctx) : undefined;
|
|
896
|
+
if (!rd && !rt)
|
|
897
|
+
return undefined;
|
|
898
|
+
const contexts = [rd?.additionalContext, rt?.additionalContext].filter((c) => typeof c === "string" && c.length > 0);
|
|
899
|
+
const updatedOutput = rt?.updatedOutput ?? rd?.updatedOutput;
|
|
900
|
+
return {
|
|
901
|
+
...(updatedOutput ? { updatedOutput } : {}),
|
|
902
|
+
...(contexts.length ? { additionalContext: contexts.join("\n") } : {}),
|
|
903
|
+
};
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
if (d.postToolUseFailure || t.postToolUseFailure) {
|
|
907
|
+
out.postToolUseFailure = async (toolName, input, failure, ctx) => {
|
|
908
|
+
const rd = d.postToolUseFailure ? await d.postToolUseFailure(toolName, input, failure, ctx) : undefined;
|
|
909
|
+
const rt = t.postToolUseFailure ? await t.postToolUseFailure(toolName, input, failure, ctx) : undefined;
|
|
910
|
+
const contexts = [rd?.additionalContext, rt?.additionalContext].filter((c) => typeof c === "string" && c.length > 0);
|
|
911
|
+
return contexts.length ? { additionalContext: contexts.join("\n") } : undefined;
|
|
912
|
+
};
|
|
913
|
+
}
|
|
914
|
+
if (d.postToolBatch || t.postToolBatch) {
|
|
915
|
+
out.postToolBatch = async (calls) => {
|
|
916
|
+
const rd = d.postToolBatch ? await d.postToolBatch(calls) : undefined;
|
|
917
|
+
const rt = t.postToolBatch ? await t.postToolBatch(calls) : undefined;
|
|
918
|
+
const contexts = [rd?.additionalContext, rt?.additionalContext].filter((c) => typeof c === "string" && c.length > 0);
|
|
919
|
+
return contexts.length ? { additionalContext: contexts.join("\n") } : undefined;
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
if (d.userPromptSubmit || t.userPromptSubmit) {
|
|
923
|
+
out.userPromptSubmit = async (prompt) => {
|
|
924
|
+
const rd = d.userPromptSubmit ? await d.userPromptSubmit(prompt) : undefined;
|
|
925
|
+
if (rd?.block)
|
|
926
|
+
return rd;
|
|
927
|
+
const rt = t.userPromptSubmit ? await t.userPromptSubmit(prompt) : undefined;
|
|
928
|
+
if (!rd && !rt)
|
|
929
|
+
return undefined;
|
|
930
|
+
const contexts = [rd?.additionalContext, rt?.additionalContext].filter((c) => typeof c === "string" && c.length > 0);
|
|
931
|
+
return { ...(rt?.block ? { block: rt.block } : {}), ...(contexts.length ? { additionalContext: contexts.join("\n") } : {}) };
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
if (d.stop || t.stop) {
|
|
935
|
+
out.stop = async (sctx) => {
|
|
936
|
+
const rd = d.stop ? await d.stop(sctx) : undefined;
|
|
937
|
+
if (rd?.block)
|
|
938
|
+
return rd;
|
|
939
|
+
const rt = t.stop ? await t.stop(sctx) : undefined;
|
|
940
|
+
if (!rd && !rt)
|
|
941
|
+
return undefined;
|
|
942
|
+
const contexts = [rd?.additionalContext, rt?.additionalContext].filter((c) => typeof c === "string" && c.length > 0);
|
|
943
|
+
return { ...(rt?.block ? { block: rt.block } : {}), ...(contexts.length ? { additionalContext: contexts.join("\n") } : {}) };
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
if (d.preCompact || t.preCompact) {
|
|
947
|
+
out.preCompact = async (pctx) => {
|
|
948
|
+
const rd = d.preCompact ? await d.preCompact(pctx) : undefined;
|
|
949
|
+
const rt = t.preCompact ? await t.preCompact(pctx) : undefined;
|
|
950
|
+
if (!rd && !rt)
|
|
951
|
+
return undefined;
|
|
952
|
+
const block = rd?.block ?? rt?.block;
|
|
953
|
+
const instructions = [rd?.additionalInstructions, rt?.additionalInstructions].filter((c) => typeof c === "string" && c.length > 0);
|
|
954
|
+
return {
|
|
955
|
+
...(block !== undefined ? { block } : {}),
|
|
956
|
+
...(instructions.length ? { additionalInstructions: instructions.join("\n") } : {}),
|
|
957
|
+
};
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
for (const slot of ["stopFailure", "postCompact", "permissionDenied"]) {
|
|
961
|
+
const ds = d[slot];
|
|
962
|
+
const ts = t[slot];
|
|
963
|
+
if (ds && ts) {
|
|
964
|
+
out[slot] = async (...args) => {
|
|
965
|
+
await ds(...args);
|
|
966
|
+
await ts(...args);
|
|
967
|
+
};
|
|
968
|
+
}
|
|
969
|
+
else if (ds || ts) {
|
|
970
|
+
out[slot] = (ds ?? ts);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
return out;
|
|
974
|
+
}
|
|
975
|
+
//# sourceMappingURL=hook-runner.js.map
|