@namzu/sdk 34.2.0 → 35.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/CHANGELOG.md +133 -0
- package/README.md +2 -6
- package/dist/agents/PipelineAgent.d.ts.map +1 -1
- package/dist/agents/PipelineAgent.js +118 -100
- package/dist/agents/PipelineAgent.js.map +1 -1
- package/dist/agents/ReactiveAgent.d.ts.map +1 -1
- package/dist/agents/ReactiveAgent.js +2 -0
- package/dist/agents/ReactiveAgent.js.map +1 -1
- package/dist/agents/RouterAgent.d.ts.map +1 -1
- package/dist/agents/RouterAgent.js +105 -61
- package/dist/agents/RouterAgent.js.map +1 -1
- package/dist/agents/SupervisorAgent.d.ts.map +1 -1
- package/dist/agents/SupervisorAgent.js +8 -4
- package/dist/agents/SupervisorAgent.js.map +1 -1
- package/dist/agents/budget.d.ts +6 -0
- package/dist/agents/budget.d.ts.map +1 -0
- package/dist/agents/budget.js +33 -0
- package/dist/agents/budget.js.map +1 -0
- package/dist/agents/explore.d.ts +20 -0
- package/dist/agents/explore.d.ts.map +1 -0
- package/dist/agents/explore.js +26 -0
- package/dist/agents/explore.js.map +1 -0
- package/dist/agents/file-definitions.d.ts +80 -0
- package/dist/agents/file-definitions.d.ts.map +1 -0
- package/dist/agents/file-definitions.js +179 -0
- package/dist/agents/file-definitions.js.map +1 -0
- package/dist/agents/index.d.ts +3 -0
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +2 -0
- package/dist/agents/index.js.map +1 -1
- package/dist/bridge/a2a/mapper.d.ts.map +1 -1
- package/dist/bridge/a2a/mapper.js +6 -0
- package/dist/bridge/a2a/mapper.js.map +1 -1
- package/dist/bridge/sse/mapper.d.ts.map +1 -1
- package/dist/bridge/sse/mapper.js +22 -0
- package/dist/bridge/sse/mapper.js.map +1 -1
- package/dist/bus/lock.d.ts.map +1 -1
- package/dist/bus/lock.js +1 -10
- package/dist/bus/lock.js.map +1 -1
- package/dist/compaction/consolidation.d.ts +31 -0
- package/dist/compaction/consolidation.d.ts.map +1 -0
- package/dist/compaction/consolidation.js +63 -0
- package/dist/compaction/consolidation.js.map +1 -0
- package/dist/compaction/factory.d.ts.map +1 -1
- package/dist/compaction/factory.js +3 -0
- package/dist/compaction/factory.js.map +1 -1
- package/dist/compaction/index.d.ts +6 -1
- package/dist/compaction/index.d.ts.map +1 -1
- package/dist/compaction/index.js +6 -0
- package/dist/compaction/index.js.map +1 -1
- package/dist/compaction/manager.d.ts +7 -0
- package/dist/compaction/manager.d.ts.map +1 -1
- package/dist/compaction/manager.js +31 -0
- package/dist/compaction/manager.js.map +1 -1
- package/dist/compaction/plan.d.ts +23 -0
- package/dist/compaction/plan.d.ts.map +1 -1
- package/dist/compaction/plan.js +41 -24
- package/dist/compaction/plan.js.map +1 -1
- package/dist/compaction/salience/bm25.d.ts +26 -0
- package/dist/compaction/salience/bm25.d.ts.map +1 -0
- package/dist/compaction/salience/bm25.js +56 -0
- package/dist/compaction/salience/bm25.js.map +1 -0
- package/dist/compaction/salience/goal.d.ts +21 -0
- package/dist/compaction/salience/goal.d.ts.map +1 -0
- package/dist/compaction/salience/goal.js +32 -0
- package/dist/compaction/salience/goal.js.map +1 -0
- package/dist/compaction/salience/index.d.ts +4 -0
- package/dist/compaction/salience/index.d.ts.map +1 -0
- package/dist/compaction/salience/index.js +4 -0
- package/dist/compaction/salience/index.js.map +1 -0
- package/dist/compaction/salience/minhash.d.ts +17 -0
- package/dist/compaction/salience/minhash.d.ts.map +1 -0
- package/dist/compaction/salience/minhash.js +54 -0
- package/dist/compaction/salience/minhash.js.map +1 -0
- package/dist/compaction/salience/score.d.ts +64 -0
- package/dist/compaction/salience/score.d.ts.map +1 -0
- package/dist/compaction/salience/score.js +256 -0
- package/dist/compaction/salience/score.js.map +1 -0
- package/dist/compaction/salience/tokenize.d.ts +20 -0
- package/dist/compaction/salience/tokenize.d.ts.map +1 -0
- package/dist/compaction/salience/tokenize.js +92 -0
- package/dist/compaction/salience/tokenize.js.map +1 -0
- package/dist/compaction/salience/working-set.d.ts +59 -0
- package/dist/compaction/salience/working-set.d.ts.map +1 -0
- package/dist/compaction/salience/working-set.js +137 -0
- package/dist/compaction/salience/working-set.js.map +1 -0
- package/dist/compaction/serializer.d.ts +2 -0
- package/dist/compaction/serializer.d.ts.map +1 -1
- package/dist/compaction/serializer.js +15 -0
- package/dist/compaction/serializer.js.map +1 -1
- package/dist/compaction/token-estimate.d.ts +13 -0
- package/dist/compaction/token-estimate.d.ts.map +1 -0
- package/dist/compaction/token-estimate.js +58 -0
- package/dist/compaction/token-estimate.js.map +1 -0
- package/dist/compaction/tool-result-editing.d.ts +10 -2
- package/dist/compaction/tool-result-editing.d.ts.map +1 -1
- package/dist/compaction/tool-result-editing.js +22 -24
- package/dist/compaction/tool-result-editing.js.map +1 -1
- package/dist/compaction/types.d.ts +22 -1
- package/dist/compaction/types.d.ts.map +1 -1
- package/dist/compaction/wire.d.ts +3 -1
- package/dist/compaction/wire.d.ts.map +1 -1
- package/dist/compaction/wire.js +2 -0
- package/dist/compaction/wire.js.map +1 -1
- package/dist/config/runtime.d.ts +58 -28
- package/dist/config/runtime.d.ts.map +1 -1
- package/dist/config/runtime.js +13 -1
- package/dist/config/runtime.js.map +1 -1
- package/dist/connector/builtins/http.d.ts.map +1 -1
- package/dist/connector/builtins/http.js +2 -8
- package/dist/connector/builtins/http.js.map +1 -1
- package/dist/connector/builtins/webhook.js +2 -2
- package/dist/connector/builtins/webhook.js.map +1 -1
- package/dist/connector/mcp/adapter.d.ts +2 -0
- package/dist/connector/mcp/adapter.d.ts.map +1 -1
- package/dist/connector/mcp/adapter.js +30 -0
- package/dist/connector/mcp/adapter.js.map +1 -1
- package/dist/connector/tools/adapter.js +2 -2
- package/dist/connector/tools/adapter.js.map +1 -1
- package/dist/connector/tools/definitions.js +2 -2
- package/dist/connector/tools/definitions.js.map +1 -1
- package/dist/constants/compaction/index.d.ts +1 -0
- package/dist/constants/compaction/index.d.ts.map +1 -1
- package/dist/constants/compaction/index.js +1 -0
- package/dist/constants/compaction/index.js.map +1 -1
- package/dist/constants/telemetry/index.d.ts +0 -1
- package/dist/constants/telemetry/index.d.ts.map +1 -1
- package/dist/constants/telemetry/index.js +0 -1
- package/dist/constants/telemetry/index.js.map +1 -1
- package/dist/contracts/a2a.d.ts +5 -5
- package/dist/contracts/api.d.ts +4 -2
- package/dist/contracts/api.d.ts.map +1 -1
- package/dist/contracts/schemas.d.ts +1 -15
- package/dist/contracts/schemas.d.ts.map +1 -1
- package/dist/contracts/schemas.js +5 -20
- package/dist/contracts/schemas.js.map +1 -1
- package/dist/invariants/index.d.ts +1 -1
- package/dist/manager/agent/lifecycle.d.ts +2 -18
- package/dist/manager/agent/lifecycle.d.ts.map +1 -1
- package/dist/manager/agent/lifecycle.js +373 -340
- package/dist/manager/agent/lifecycle.js.map +1 -1
- package/dist/manager/run/persistence.d.ts +3 -0
- package/dist/manager/run/persistence.d.ts.map +1 -1
- package/dist/manager/run/persistence.js +35 -5
- package/dist/manager/run/persistence.js.map +1 -1
- package/dist/plugin/index.d.ts +2 -0
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +1 -0
- package/dist/plugin/index.js.map +1 -1
- package/dist/plugin/shell-hook.d.ts +128 -0
- package/dist/plugin/shell-hook.d.ts.map +1 -0
- package/dist/plugin/shell-hook.js +299 -0
- package/dist/plugin/shell-hook.js.map +1 -0
- package/dist/prompt/coding-agent-doctrine.d.ts +63 -0
- package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -0
- package/dist/prompt/coding-agent-doctrine.js +100 -0
- package/dist/prompt/coding-agent-doctrine.js.map +1 -0
- package/dist/prompt/index.d.ts +2 -0
- package/dist/prompt/index.d.ts.map +1 -1
- package/dist/prompt/index.js +1 -0
- package/dist/prompt/index.js.map +1 -1
- package/dist/provider/errors.d.ts +1 -1
- package/dist/provider/errors.js +1 -1
- package/dist/provider/fallback.d.ts +2 -0
- package/dist/provider/fallback.d.ts.map +1 -1
- package/dist/provider/fallback.js +3 -1
- package/dist/provider/fallback.js.map +1 -1
- package/dist/provider/retry.d.ts +2 -0
- package/dist/provider/retry.d.ts.map +1 -1
- package/dist/provider/retry.js +3 -1
- package/dist/provider/retry.js.map +1 -1
- package/dist/provider/token-budget.d.ts +13 -0
- package/dist/provider/token-budget.d.ts.map +1 -0
- package/dist/provider/token-budget.js +102 -0
- package/dist/provider/token-budget.js.map +1 -0
- package/dist/public-runtime.d.ts +12 -12
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +14 -9
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +2 -0
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +2 -0
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +12 -2
- package/dist/public-types.d.ts.map +1 -1
- package/dist/registry/command/kernel-commands.d.ts.map +1 -1
- package/dist/registry/command/kernel-commands.js +18 -6
- package/dist/registry/command/kernel-commands.js.map +1 -1
- package/dist/registry/tool/execute.d.ts.map +1 -1
- package/dist/registry/tool/execute.js +4 -1
- package/dist/registry/tool/execute.js.map +1 -1
- package/dist/run/LimitChecker.js +1 -1
- package/dist/run/LimitChecker.js.map +1 -1
- package/dist/run/drain.js +1 -1
- package/dist/run/reporter.d.ts.map +1 -1
- package/dist/run/reporter.js +15 -0
- package/dist/run/reporter.js.map +1 -1
- package/dist/run/token-budget.d.ts +108 -0
- package/dist/run/token-budget.d.ts.map +1 -0
- package/dist/run/token-budget.js +591 -0
- package/dist/run/token-budget.js.map +1 -0
- package/dist/runtime/jobs/registry.d.ts +29 -0
- package/dist/runtime/jobs/registry.d.ts.map +1 -1
- package/dist/runtime/jobs/registry.js +98 -18
- package/dist/runtime/jobs/registry.js.map +1 -1
- package/dist/runtime/query/checkpoint.d.ts.map +1 -1
- package/dist/runtime/query/checkpoint.js +10 -3
- package/dist/runtime/query/checkpoint.js.map +1 -1
- package/dist/runtime/query/context.d.ts +2 -26
- package/dist/runtime/query/context.d.ts.map +1 -1
- package/dist/runtime/query/context.js +1 -29
- package/dist/runtime/query/context.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +12 -9
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +95 -46
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/guard.d.ts.map +1 -1
- package/dist/runtime/query/guard.js +8 -0
- package/dist/runtime/query/guard.js.map +1 -1
- package/dist/runtime/query/index.d.ts +35 -4
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +152 -52
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/index.js +16 -5
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.js +98 -30
- package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context.d.ts +2 -0
- package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/context.js.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.js +29 -7
- package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
- package/dist/runtime/query/iteration/phases/working-memory.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/working-memory.js +25 -15
- package/dist/runtime/query/iteration/phases/working-memory.js.map +1 -1
- package/dist/runtime/query/plugin-hooks.d.ts +1 -1
- package/dist/runtime/query/plugin-hooks.d.ts.map +1 -1
- package/dist/runtime/query/plugin-hooks.js +20 -1
- package/dist/runtime/query/plugin-hooks.js.map +1 -1
- package/dist/runtime/query/repeat-call.d.ts +20 -2
- package/dist/runtime/query/repeat-call.d.ts.map +1 -1
- package/dist/runtime/query/repeat-call.js +35 -7
- package/dist/runtime/query/repeat-call.js.map +1 -1
- package/dist/runtime/query/result.d.ts.map +1 -1
- package/dist/runtime/query/result.js +9 -0
- package/dist/runtime/query/result.js.map +1 -1
- package/dist/runtime/query/review-policy.d.ts +142 -0
- package/dist/runtime/query/review-policy.d.ts.map +1 -0
- package/dist/runtime/query/review-policy.js +144 -0
- package/dist/runtime/query/review-policy.js.map +1 -0
- package/dist/runtime/query/run-state.d.ts.map +1 -1
- package/dist/runtime/query/run-state.js +4 -0
- package/dist/runtime/query/run-state.js.map +1 -1
- package/dist/runtime/query/steering.d.ts +4 -0
- package/dist/runtime/query/steering.d.ts.map +1 -1
- package/dist/runtime/query/steering.js +29 -0
- package/dist/runtime/query/steering.js.map +1 -1
- package/dist/runtime/query/token-budget.d.ts +7 -0
- package/dist/runtime/query/token-budget.d.ts.map +1 -0
- package/dist/runtime/query/token-budget.js +101 -0
- package/dist/runtime/query/token-budget.js.map +1 -0
- package/dist/runtime/query/tool-output-budget.d.ts +2 -0
- package/dist/runtime/query/tool-output-budget.d.ts.map +1 -1
- package/dist/runtime/query/tool-output-budget.js +29 -11
- package/dist/runtime/query/tool-output-budget.js.map +1 -1
- package/dist/runtime/query/tool-pause.d.ts.map +1 -1
- package/dist/runtime/query/tool-pause.js +4 -2
- package/dist/runtime/query/tool-pause.js.map +1 -1
- package/dist/runtime/query/tooling.d.ts +4 -0
- package/dist/runtime/query/tooling.d.ts.map +1 -1
- package/dist/runtime/query/tooling.js +4 -0
- package/dist/runtime/query/tooling.js.map +1 -1
- package/dist/sandbox/provider/local.d.ts +3 -1
- package/dist/sandbox/provider/local.d.ts.map +1 -1
- package/dist/sandbox/provider/local.js +112 -12
- package/dist/sandbox/provider/local.js.map +1 -1
- package/dist/scheduler/delegating.d.ts +1 -0
- package/dist/scheduler/delegating.d.ts.map +1 -1
- package/dist/scheduler/delegating.js +29 -12
- package/dist/scheduler/delegating.js.map +1 -1
- package/dist/scheduler/local.d.ts +1 -0
- package/dist/scheduler/local.d.ts.map +1 -1
- package/dist/scheduler/local.js +4 -7
- package/dist/scheduler/local.js.map +1 -1
- package/dist/session/index.d.ts +0 -1
- package/dist/session/index.d.ts.map +1 -1
- package/dist/session/index.js +0 -1
- package/dist/session/index.js.map +1 -1
- package/dist/session/workspace/path-builder.d.ts.map +1 -1
- package/dist/session/workspace/path-builder.js +5 -4
- package/dist/session/workspace/path-builder.js.map +1 -1
- package/dist/store/feedback/disk.d.ts.map +1 -1
- package/dist/store/feedback/disk.js +4 -6
- package/dist/store/feedback/disk.js.map +1 -1
- package/dist/store/index.d.ts +2 -0
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +1 -0
- package/dist/store/index.js.map +1 -1
- package/dist/store/memory/disk.d.ts.map +1 -1
- package/dist/store/memory/disk.js +3 -12
- package/dist/store/memory/disk.js.map +1 -1
- package/dist/store/run/checkpoint-disk.d.ts +3 -3
- package/dist/store/run/checkpoint-disk.d.ts.map +1 -1
- package/dist/store/run/checkpoint-disk.js +14 -26
- package/dist/store/run/checkpoint-disk.js.map +1 -1
- package/dist/store/run/claim-disk.js +1 -1
- package/dist/store/run/conformance.d.ts +1 -1
- package/dist/store/run/conformance.d.ts.map +1 -1
- package/dist/store/run/conformance.js +41 -33
- package/dist/store/run/conformance.js.map +1 -1
- package/dist/store/run/disk.d.ts.map +1 -1
- package/dist/store/run/disk.js +20 -4
- package/dist/store/run/disk.js.map +1 -1
- package/dist/store/run/token-budget-disk.d.ts +37 -0
- package/dist/store/run/token-budget-disk.d.ts.map +1 -0
- package/dist/store/run/token-budget-disk.js +208 -0
- package/dist/store/run/token-budget-disk.js.map +1 -0
- package/dist/store/session/disk.d.ts +4 -13
- package/dist/store/session/disk.d.ts.map +1 -1
- package/dist/store/session/disk.js +34 -31
- package/dist/store/session/disk.js.map +1 -1
- package/dist/store/session/memory.d.ts +2 -0
- package/dist/store/session/memory.d.ts.map +1 -1
- package/dist/store/session/memory.js +41 -2
- package/dist/store/session/memory.js.map +1 -1
- package/dist/store/task/disk.d.ts.map +1 -1
- package/dist/store/task/disk.js +7 -8
- package/dist/store/task/disk.js.map +1 -1
- package/dist/store/topic/memory.d.ts +2 -0
- package/dist/store/topic/memory.d.ts.map +1 -1
- package/dist/store/topic/memory.js +13 -1
- package/dist/store/topic/memory.js.map +1 -1
- package/dist/test-support/ids.d.ts +4 -19
- package/dist/test-support/ids.d.ts.map +1 -1
- package/dist/test-support/ids.js +51 -59
- package/dist/test-support/ids.js.map +1 -1
- package/dist/tools/advisory/index.d.ts.map +1 -1
- package/dist/tools/advisory/index.js +3 -1
- package/dist/tools/advisory/index.js.map +1 -1
- package/dist/tools/builtins/bash.d.ts +2 -0
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +9 -11
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/computer-use.d.ts +2 -2
- package/dist/tools/builtins/computer-use.d.ts.map +1 -1
- package/dist/tools/builtins/computer-use.js +4 -2
- package/dist/tools/builtins/computer-use.js.map +1 -1
- package/dist/tools/builtins/edit.js +2 -2
- package/dist/tools/builtins/edit.js.map +1 -1
- package/dist/tools/builtins/glob.js +3 -3
- package/dist/tools/builtins/glob.js.map +1 -1
- package/dist/tools/builtins/grep.js +2 -2
- package/dist/tools/builtins/grep.js.map +1 -1
- package/dist/tools/builtins/ls.js +2 -2
- package/dist/tools/builtins/ls.js.map +1 -1
- package/dist/tools/builtins/lsp.js +2 -2
- package/dist/tools/builtins/lsp.js.map +1 -1
- package/dist/tools/builtins/read-file.js +2 -2
- package/dist/tools/builtins/read-file.js.map +1 -1
- package/dist/tools/builtins/write-file.js +2 -2
- package/dist/tools/builtins/write-file.js.map +1 -1
- package/dist/tools/coordinator/ask-user-question.d.ts +33 -0
- package/dist/tools/coordinator/ask-user-question.d.ts.map +1 -0
- package/dist/tools/coordinator/ask-user-question.js +237 -0
- package/dist/tools/coordinator/ask-user-question.js.map +1 -0
- package/dist/tools/coordinator/index.d.ts +1 -2
- package/dist/tools/coordinator/index.d.ts.map +1 -1
- package/dist/tools/coordinator/index.js +4 -220
- package/dist/tools/coordinator/index.js.map +1 -1
- package/dist/tools/memory/read.d.ts.map +1 -1
- package/dist/tools/memory/read.js +2 -4
- package/dist/tools/memory/read.js.map +1 -1
- package/dist/tools/paths.d.ts +13 -0
- package/dist/tools/paths.d.ts.map +1 -1
- package/dist/tools/paths.js +53 -0
- package/dist/tools/paths.js.map +1 -1
- package/dist/tools/roster.d.ts +27 -0
- package/dist/tools/roster.d.ts.map +1 -0
- package/dist/tools/roster.js +42 -0
- package/dist/tools/roster.js.map +1 -0
- package/dist/types/agent/base.d.ts +5 -0
- package/dist/types/agent/base.d.ts.map +1 -1
- package/dist/types/agent/pipeline.d.ts +3 -0
- package/dist/types/agent/pipeline.d.ts.map +1 -1
- package/dist/types/agent/router.d.ts +2 -3
- package/dist/types/agent/router.d.ts.map +1 -1
- package/dist/types/agent/scheduler.d.ts +3 -0
- package/dist/types/agent/scheduler.d.ts.map +1 -1
- package/dist/types/agent/task.d.ts +5 -16
- package/dist/types/agent/task.d.ts.map +1 -1
- package/dist/types/agent/task.js.map +1 -1
- package/dist/types/common/index.d.ts.map +1 -1
- package/dist/types/common/index.js +3 -0
- package/dist/types/common/index.js.map +1 -1
- package/dist/types/computer-use/index.d.ts +8 -0
- package/dist/types/computer-use/index.d.ts.map +1 -1
- package/dist/types/computer-use/index.js.map +1 -1
- package/dist/types/hitl/index.d.ts +5 -0
- package/dist/types/hitl/index.d.ts.map +1 -1
- package/dist/types/hitl/index.js.map +1 -1
- package/dist/types/ids/brand.d.ts +5 -47
- package/dist/types/ids/brand.d.ts.map +1 -1
- package/dist/types/ids/brand.js +2 -39
- package/dist/types/ids/brand.js.map +1 -1
- package/dist/types/ids/index.d.ts +59 -69
- package/dist/types/ids/index.d.ts.map +1 -1
- package/dist/types/ids/index.js +12 -10
- package/dist/types/ids/index.js.map +1 -1
- package/dist/types/permission/index.d.ts +9 -0
- package/dist/types/permission/index.d.ts.map +1 -1
- package/dist/types/permission/index.js +9 -1
- package/dist/types/permission/index.js.map +1 -1
- package/dist/types/plugin/index.d.ts +45 -4
- package/dist/types/plugin/index.d.ts.map +1 -1
- package/dist/types/plugin/index.js +7 -0
- package/dist/types/plugin/index.js.map +1 -1
- package/dist/types/run/config.d.ts +3 -0
- package/dist/types/run/config.d.ts.map +1 -1
- package/dist/types/run/emergency.d.ts +5 -0
- package/dist/types/run/emergency.d.ts.map +1 -1
- package/dist/types/run/emergency.js.map +1 -1
- package/dist/types/run/entity.d.ts +6 -2
- package/dist/types/run/entity.d.ts.map +1 -1
- package/dist/types/run/events.d.ts +35 -0
- package/dist/types/run/events.d.ts.map +1 -1
- package/dist/types/run/events.js.map +1 -1
- package/dist/types/run/index.d.ts +1 -0
- package/dist/types/run/index.d.ts.map +1 -1
- package/dist/types/run/index.js +1 -0
- package/dist/types/run/index.js.map +1 -1
- package/dist/types/run/state.d.ts +16 -15
- package/dist/types/run/state.d.ts.map +1 -1
- package/dist/types/run/state.js +41 -22
- package/dist/types/run/state.js.map +1 -1
- package/dist/types/run/stop-reason.d.ts +3 -14
- package/dist/types/run/stop-reason.d.ts.map +1 -1
- package/dist/types/run/token-budget-store.d.ts +29 -0
- package/dist/types/run/token-budget-store.d.ts.map +1 -0
- package/dist/types/run/token-budget-store.js +25 -0
- package/dist/types/run/token-budget-store.js.map +1 -0
- package/dist/types/sandbox/index.d.ts +27 -2
- package/dist/types/sandbox/index.d.ts.map +1 -1
- package/dist/types/sandbox/index.js.map +1 -1
- package/dist/types/session/store.d.ts +8 -0
- package/dist/types/session/store.d.ts.map +1 -1
- package/dist/types/tool/index.d.ts +15 -0
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/dist/utils/frontmatter.d.ts +1 -1
- package/dist/utils/frontmatter.js +1 -1
- package/dist/utils/id-format.d.ts +3 -0
- package/dist/utils/id-format.d.ts.map +1 -0
- package/dist/utils/id-format.js +9 -0
- package/dist/utils/id-format.js.map +1 -0
- package/dist/utils/id.d.ts +65 -32
- package/dist/utils/id.d.ts.map +1 -1
- package/dist/utils/id.js +168 -148
- package/dist/utils/id.js.map +1 -1
- package/dist/utils/log/exception.js +1 -1
- package/dist/utils/log/exception.js.map +1 -1
- package/dist/utils/log/index.d.ts.map +1 -1
- package/dist/utils/log/index.js +1 -2
- package/dist/utils/log/index.js.map +1 -1
- package/dist/utils/log/templates.d.ts.map +1 -1
- package/dist/utils/log/templates.js +0 -1
- package/dist/utils/log/templates.js.map +1 -1
- package/package.json +1 -1
- package/src/agents/AGENTS.md +1 -1
- package/src/agents/PipelineAgent.ts +129 -109
- package/src/agents/ReactiveAgent.ts +2 -0
- package/src/agents/RouterAgent.ts +120 -73
- package/src/agents/SupervisorAgent.ts +12 -4
- package/src/agents/budget.ts +42 -0
- package/src/agents/explore.ts +29 -0
- package/src/agents/file-definitions.ts +237 -0
- package/src/agents/index.ts +15 -0
- package/src/bridge/a2a/mapper.ts +6 -0
- package/src/bridge/sse/mapper.ts +22 -0
- package/src/bus/lock.ts +1 -10
- package/src/compaction/consolidation.ts +79 -0
- package/src/compaction/factory.ts +3 -0
- package/src/compaction/index.ts +34 -4
- package/src/compaction/manager.ts +39 -1
- package/src/compaction/plan.ts +52 -21
- package/src/compaction/salience/bm25.ts +72 -0
- package/src/compaction/salience/goal.ts +44 -0
- package/src/compaction/salience/index.ts +19 -0
- package/src/compaction/salience/minhash.ts +53 -0
- package/src/compaction/salience/score.ts +305 -0
- package/src/compaction/salience/tokenize.ts +89 -0
- package/src/compaction/salience/working-set.ts +187 -0
- package/src/compaction/serializer.ts +16 -0
- package/src/compaction/token-estimate.ts +57 -0
- package/src/compaction/tool-result-editing.ts +28 -26
- package/src/compaction/types.ts +24 -1
- package/src/compaction/wire.ts +5 -1
- package/src/config/runtime.ts +13 -1
- package/src/connector/builtins/http.ts +2 -8
- package/src/connector/builtins/webhook.ts +2 -2
- package/src/connector/mcp/adapter.ts +32 -0
- package/src/connector/tools/adapter.ts +2 -2
- package/src/connector/tools/definitions.ts +2 -2
- package/src/constants/compaction/index.ts +1 -0
- package/src/constants/telemetry/index.ts +0 -1
- package/src/contracts/api.ts +5 -1
- package/src/contracts/schemas.ts +6 -20
- package/src/invariants/index.ts +1 -1
- package/src/manager/agent/lifecycle.ts +380 -352
- package/src/manager/run/persistence.ts +35 -5
- package/src/plugin/index.ts +19 -0
- package/src/plugin/shell-hook.ts +403 -0
- package/src/prompt/coding-agent-doctrine.ts +118 -0
- package/src/prompt/index.ts +8 -0
- package/src/provider/errors.ts +1 -1
- package/src/provider/fallback.ts +4 -1
- package/src/provider/retry.ts +4 -1
- package/src/provider/token-budget.ts +114 -0
- package/src/public-runtime.ts +54 -27
- package/src/public-tools.ts +5 -0
- package/src/public-types.ts +65 -0
- package/src/registry/command/kernel-commands.ts +16 -6
- package/src/registry/tool/execute.ts +4 -1
- package/src/run/LimitChecker.ts +1 -1
- package/src/run/drain.ts +1 -1
- package/src/run/reporter.ts +15 -0
- package/src/run/token-budget.ts +692 -0
- package/src/runtime/jobs/registry.ts +123 -17
- package/src/runtime/query/checkpoint.ts +10 -3
- package/src/runtime/query/context.ts +3 -57
- package/src/runtime/query/executor.ts +128 -58
- package/src/runtime/query/guard.ts +8 -0
- package/src/runtime/query/index.ts +201 -62
- package/src/runtime/query/iteration/index.ts +24 -6
- package/src/runtime/query/iteration/phases/compaction.ts +130 -31
- package/src/runtime/query/iteration/phases/context.ts +2 -0
- package/src/runtime/query/iteration/phases/tool-review.ts +39 -7
- package/src/runtime/query/iteration/phases/working-memory.ts +23 -14
- package/src/runtime/query/plugin-hooks.ts +24 -2
- package/src/runtime/query/repeat-call.ts +42 -7
- package/src/runtime/query/result.ts +9 -0
- package/src/runtime/query/review-policy.ts +231 -0
- package/src/runtime/query/run-state.ts +4 -0
- package/src/runtime/query/steering.ts +32 -0
- package/src/runtime/query/token-budget.ts +127 -0
- package/src/runtime/query/tool-output-budget.ts +33 -10
- package/src/runtime/query/tool-pause.ts +4 -2
- package/src/runtime/query/tooling.ts +8 -0
- package/src/sandbox/provider/local.ts +123 -13
- package/src/scheduler/delegating.ts +35 -13
- package/src/scheduler/local.ts +5 -7
- package/src/session/index.ts +0 -1
- package/src/session/workspace/path-builder.ts +5 -4
- package/src/store/feedback/disk.ts +4 -6
- package/src/store/index.ts +2 -0
- package/src/store/memory/disk.ts +3 -11
- package/src/store/run/checkpoint-disk.ts +14 -27
- package/src/store/run/claim-disk.ts +1 -1
- package/src/store/run/conformance.ts +55 -39
- package/src/store/run/disk.ts +19 -4
- package/src/store/run/token-budget-disk.ts +247 -0
- package/src/store/session/disk.ts +36 -29
- package/src/store/session/memory.ts +38 -1
- package/src/store/task/disk.ts +7 -8
- package/src/store/topic/memory.ts +13 -1
- package/src/test-support/ids.ts +62 -59
- package/src/tools/advisory/index.ts +3 -1
- package/src/tools/builtins/bash.ts +11 -12
- package/src/tools/builtins/computer-use.ts +6 -2
- package/src/tools/builtins/edit.ts +2 -2
- package/src/tools/builtins/glob.ts +3 -3
- package/src/tools/builtins/grep.ts +2 -2
- package/src/tools/builtins/ls.ts +2 -2
- package/src/tools/builtins/lsp.ts +2 -2
- package/src/tools/builtins/read-file.ts +2 -2
- package/src/tools/builtins/write-file.ts +2 -2
- package/src/tools/coordinator/ask-user-question.ts +284 -0
- package/src/tools/coordinator/index.ts +5 -248
- package/src/tools/memory/read.ts +2 -4
- package/src/tools/paths.ts +64 -0
- package/src/tools/roster.ts +46 -0
- package/src/types/agent/base.ts +6 -0
- package/src/types/agent/pipeline.ts +3 -0
- package/src/types/agent/router.ts +2 -3
- package/src/types/agent/scheduler.ts +4 -0
- package/src/types/agent/task.ts +5 -18
- package/src/types/common/index.ts +3 -0
- package/src/types/computer-use/index.ts +8 -0
- package/src/types/hitl/index.ts +5 -0
- package/src/types/ids/brand.ts +5 -48
- package/src/types/ids/index.ts +66 -75
- package/src/types/permission/index.ts +11 -0
- package/src/types/plugin/index.ts +49 -1
- package/src/types/run/config.ts +3 -0
- package/src/types/run/emergency.ts +5 -0
- package/src/types/run/entity.ts +6 -2
- package/src/types/run/events.ts +37 -0
- package/src/types/run/index.ts +1 -0
- package/src/types/run/state.ts +58 -30
- package/src/types/run/stop-reason.ts +3 -14
- package/src/types/run/token-budget-store.ts +54 -0
- package/src/types/sandbox/index.ts +32 -0
- package/src/types/session/store.ts +8 -0
- package/src/types/tool/index.ts +15 -0
- package/src/utils/frontmatter.ts +1 -1
- package/src/utils/id-format.ts +9 -0
- package/src/utils/id.ts +222 -181
- package/src/utils/log/exception.ts +1 -1
- package/src/utils/log/index.ts +1 -2
- package/src/utils/log/templates.ts +0 -1
- package/dist/session/migration/errors.d.ts +0 -26
- package/dist/session/migration/errors.d.ts.map +0 -1
- package/dist/session/migration/errors.js +0 -22
- package/dist/session/migration/errors.js.map +0 -1
- package/dist/session/migration/filesystem.d.ts +0 -122
- package/dist/session/migration/filesystem.d.ts.map +0 -1
- package/dist/session/migration/filesystem.js +0 -379
- package/dist/session/migration/filesystem.js.map +0 -1
- package/dist/session/migration/id-prefix.d.ts +0 -113
- package/dist/session/migration/id-prefix.d.ts.map +0 -1
- package/dist/session/migration/id-prefix.js +0 -132
- package/dist/session/migration/id-prefix.js.map +0 -1
- package/dist/session/migration/index.d.ts +0 -12
- package/dist/session/migration/index.d.ts.map +0 -1
- package/dist/session/migration/index.js +0 -12
- package/dist/session/migration/index.js.map +0 -1
- package/dist/session/migration/marker.d.ts +0 -57
- package/dist/session/migration/marker.d.ts.map +0 -1
- package/dist/session/migration/marker.js +0 -123
- package/dist/session/migration/marker.js.map +0 -1
- package/src/session/migration/errors.ts +0 -23
- package/src/session/migration/filesystem.ts +0 -468
- package/src/session/migration/id-prefix.ts +0 -166
- package/src/session/migration/index.ts +0 -41
- package/src/session/migration/marker.ts +0 -142
|
@@ -2,9 +2,11 @@ import { AUTO_CONTINUATION_USER_MESSAGE } from '../../constants/continuation.js'
|
|
|
2
2
|
import { EMPTY_TOKEN_USAGE } from '../../constants/limits.js'
|
|
3
3
|
import { NAMZU } from '../../constants/telemetry/index.js'
|
|
4
4
|
import { resolveModelPricing } from '../../pricing/index.js'
|
|
5
|
+
import type { TokenBudget } from '../../run/token-budget.js'
|
|
5
6
|
import { DiskCheckpointStore } from '../../store/run/checkpoint-disk.js'
|
|
6
7
|
import { RunDiskStore } from '../../store/run/disk.js'
|
|
7
8
|
import { getActiveSpanContext } from '../../telemetry/runtime-accessors.js'
|
|
9
|
+
import { mergeTokenUsage } from '../../types/common/index.js'
|
|
8
10
|
import { type CostInfo, type TokenUsage, accumulateTokenUsage } from '../../types/common/index.js'
|
|
9
11
|
import type { RunId, SessionId, TenantId } from '../../types/ids/index.js'
|
|
10
12
|
import type { Message } from '../../types/message/index.js'
|
|
@@ -38,6 +40,7 @@ export interface PricingSubject {
|
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
export class RunPersistence {
|
|
43
|
+
readonly budget?: TokenBudget
|
|
41
44
|
private run: Run
|
|
42
45
|
private runStore: RunStore
|
|
43
46
|
private checkpointStore: CheckpointStore
|
|
@@ -54,6 +57,7 @@ export class RunPersistence {
|
|
|
54
57
|
private readonly _projectId: ProjectId
|
|
55
58
|
|
|
56
59
|
constructor(config: RunPersistenceConfig) {
|
|
60
|
+
this.budget = config.budget
|
|
57
61
|
this.pricing = config.pricing
|
|
58
62
|
this.log = config.log
|
|
59
63
|
this._sessionId = config.sessionId
|
|
@@ -148,11 +152,24 @@ export class RunPersistence {
|
|
|
148
152
|
}
|
|
149
153
|
|
|
150
154
|
get tokenUsage(): TokenUsage {
|
|
151
|
-
return this.
|
|
155
|
+
return this.budget
|
|
156
|
+
? mergeTokenUsage(this.run.tokenUsage, this.budget.ownUsage)
|
|
157
|
+
: this.run.tokenUsage
|
|
152
158
|
}
|
|
153
159
|
|
|
154
160
|
get costInfo(): CostInfo {
|
|
155
|
-
|
|
161
|
+
const unpriced = Math.max(0, this.tokenUsage.totalTokens - this.run.tokenUsage.totalTokens)
|
|
162
|
+
return unpriced > 0
|
|
163
|
+
? { ...this.run.costInfo, unpricedTokens: this.run.costInfo.unpricedTokens + unpriced }
|
|
164
|
+
: this.run.costInfo
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private syncBudget(): void {
|
|
168
|
+
if (!this.budget) return
|
|
169
|
+
this.run.costInfo = this.costInfo
|
|
170
|
+
this.run.tokenUsage = this.tokenUsage
|
|
171
|
+
this.run.budget = this.budget.summary()
|
|
172
|
+
this.run.budgetBinding = this.budget.binding
|
|
156
173
|
}
|
|
157
174
|
|
|
158
175
|
get currentIteration(): number {
|
|
@@ -160,11 +177,18 @@ export class RunPersistence {
|
|
|
160
177
|
}
|
|
161
178
|
|
|
162
179
|
getRun(): Readonly<Run> {
|
|
163
|
-
return this.run
|
|
180
|
+
if (!this.budget) return this.run
|
|
181
|
+
return {
|
|
182
|
+
...this.run,
|
|
183
|
+
tokenUsage: this.tokenUsage,
|
|
184
|
+
costInfo: this.costInfo,
|
|
185
|
+
budget: this.budget.summary(),
|
|
186
|
+
budgetBinding: this.budget.binding,
|
|
187
|
+
}
|
|
164
188
|
}
|
|
165
189
|
|
|
166
190
|
getSession(): Readonly<Run> {
|
|
167
|
-
return this.
|
|
191
|
+
return this.getRun()
|
|
168
192
|
}
|
|
169
193
|
|
|
170
194
|
getRunStore(): RunStore {
|
|
@@ -525,6 +549,8 @@ export class RunPersistence {
|
|
|
525
549
|
this.run.tokenUsage = { ...tokenUsage }
|
|
526
550
|
this.run.costInfo = { ...costInfo }
|
|
527
551
|
this.run.currentIteration = currentIteration
|
|
552
|
+
this.budget?.recordUsage(tokenUsage)
|
|
553
|
+
this.syncBudget()
|
|
528
554
|
}
|
|
529
555
|
|
|
530
556
|
/**
|
|
@@ -588,7 +614,9 @@ export class RunPersistence {
|
|
|
588
614
|
id: generateEmergencySaveId(),
|
|
589
615
|
runId: this.run.id,
|
|
590
616
|
messages: this.run.messages,
|
|
591
|
-
tokenUsage: this.
|
|
617
|
+
tokenUsage: this.tokenUsage,
|
|
618
|
+
budgetBinding: this.budget?.binding,
|
|
619
|
+
budgetAccountId: this.budget?.accountId,
|
|
592
620
|
currentIteration: this.run.currentIteration,
|
|
593
621
|
startedAt: this.run.startedAt,
|
|
594
622
|
savedAt: Date.now(),
|
|
@@ -673,6 +701,8 @@ export class RunPersistence {
|
|
|
673
701
|
}
|
|
674
702
|
|
|
675
703
|
async persist(): Promise<void> {
|
|
704
|
+
await this.budget?.flush()
|
|
705
|
+
this.syncBudget()
|
|
676
706
|
await this.runStore.writeRunMeta(this.run)
|
|
677
707
|
await this.runStore.writeMessages(this.run, this._lastEventSeq)
|
|
678
708
|
// Optional on the contract: a backend whose runs are already queryable
|
package/src/plugin/index.ts
CHANGED
|
@@ -2,3 +2,22 @@ export { discoverPlugins, loadPluginManifest, discoverAllPluginDirs } from './lo
|
|
|
2
2
|
export type { PluginDiscoveryOptions, PluginEnablementCapabilities } from './loader.js'
|
|
3
3
|
export { PluginLifecycleManager } from './lifecycle.js'
|
|
4
4
|
export { PluginResolver } from './resolver.js'
|
|
5
|
+
export {
|
|
6
|
+
attachShellHooks,
|
|
7
|
+
createShellHook,
|
|
8
|
+
DEFAULT_SHELL_HOOK_TIMEOUT_MS,
|
|
9
|
+
MAX_SHELL_HOOK_TIMEOUT_MS,
|
|
10
|
+
runShellHook,
|
|
11
|
+
SHELL_HOOK_EVENTS,
|
|
12
|
+
SHELL_HOOKS_PLUGIN_ID,
|
|
13
|
+
shellHookMatches,
|
|
14
|
+
shellHookVerdict,
|
|
15
|
+
} from './shell-hook.js'
|
|
16
|
+
export type {
|
|
17
|
+
ShellHookEntry,
|
|
18
|
+
ShellHookEvent,
|
|
19
|
+
ShellHookInput,
|
|
20
|
+
ShellHookOptions,
|
|
21
|
+
ShellHookOutcome,
|
|
22
|
+
ShellHooksConfig,
|
|
23
|
+
} from './shell-hook.js'
|
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A shell command as a plugin hook.
|
|
3
|
+
*
|
|
4
|
+
* The lifecycle manager carries a hook system — `pre_tool_use`,
|
|
5
|
+
* `post_tool_use`, `run_start`, `run_end` and the rest — and `registerHook`
|
|
6
|
+
* lets a host attach a handler without a plugin on disk. What every host then
|
|
7
|
+
* writes for itself is the same adapter: run a command, hand it the event,
|
|
8
|
+
* read its exit code. This file is that adapter, once, so an operator
|
|
9
|
+
* application, an ACP server and an embedder all offer the same contract and
|
|
10
|
+
* an operator's hook script works under all three.
|
|
11
|
+
*
|
|
12
|
+
* ## The contract
|
|
13
|
+
*
|
|
14
|
+
* The command runs with `sh -c` in `cwd`. It receives one JSON object on
|
|
15
|
+
* stdin — `event`, `cwd`, `run_id`, and for tool events `tool_name`,
|
|
16
|
+
* `tool_input` and (after the call) `tool_result` — and the same facts as
|
|
17
|
+
* `NAMZU_HOOK_EVENT`, `NAMZU_RUN_ID`, `NAMZU_TOOL_NAME` and, when the input
|
|
18
|
+
* names a file, `NAMZU_TOOL_PATH`. Its exit code is its answer:
|
|
19
|
+
*
|
|
20
|
+
* - `0` — carry on.
|
|
21
|
+
* - `2` — **block.** Before a tool (`pre_tool_use`) the call is skipped and the
|
|
22
|
+
* model is told why, with the hook's stderr as the reason. On any other
|
|
23
|
+
* event a 2 is reported and the run carries on: there is nothing left to
|
|
24
|
+
* block once the tool has run or the run has started.
|
|
25
|
+
* - anything else — the hook's own failure. Reported through the logger,
|
|
26
|
+
* never blocking. A formatter that crashed must not stop the agent editing,
|
|
27
|
+
* and a script missing its interpreter (127) must not read as "forbidden".
|
|
28
|
+
*
|
|
29
|
+
* `2` rather than any non-zero, because a verdict and a failure are different
|
|
30
|
+
* facts and one exit code cannot carry both.
|
|
31
|
+
*
|
|
32
|
+
* ## What a hook cannot do here
|
|
33
|
+
*
|
|
34
|
+
* Modify a tool's input or replace its result. The hook protocol allows both
|
|
35
|
+
* (`modify`, `replace`); this adapter exposes neither, because a shell command
|
|
36
|
+
* that rewrites what the model asked for deserves its own design and audit,
|
|
37
|
+
* not a JSON field on stdout nobody reviewed.
|
|
38
|
+
*
|
|
39
|
+
* ## Bounds
|
|
40
|
+
*
|
|
41
|
+
* Each hook has a deadline (`timeoutMs`, default 30 s, capped at ten minutes)
|
|
42
|
+
* and its output is captured to a bound. A hook that times out is reported
|
|
43
|
+
* and does not block: one that could not answer in time has not answered no.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
import { spawn } from 'node:child_process'
|
|
47
|
+
|
|
48
|
+
import type { PluginId } from '../types/ids/index.js'
|
|
49
|
+
import type {
|
|
50
|
+
PluginCompactionInfo,
|
|
51
|
+
PluginHookContext,
|
|
52
|
+
PluginHookDefinition,
|
|
53
|
+
PluginHookEvent,
|
|
54
|
+
PluginHookResult,
|
|
55
|
+
} from '../types/plugin/index.js'
|
|
56
|
+
import { asPluginId } from '../utils/id.js'
|
|
57
|
+
import { NOOP_LOGGER } from '../utils/log/create-logger.js'
|
|
58
|
+
import type { Logger } from '../utils/logger.js'
|
|
59
|
+
import type { PluginLifecycleManager } from './lifecycle.js'
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The events a shell hook may attach to: the ones an operator can act on
|
|
63
|
+
* from a script. The model-call and iteration events stay in-process —
|
|
64
|
+
* they carry the messages, and a shell is not where those go.
|
|
65
|
+
*/
|
|
66
|
+
export type ShellHookEvent = Extract<
|
|
67
|
+
PluginHookEvent,
|
|
68
|
+
| 'user_prompt_submit'
|
|
69
|
+
| 'session_start'
|
|
70
|
+
| 'session_end'
|
|
71
|
+
| 'pre_tool_use'
|
|
72
|
+
| 'post_tool_use'
|
|
73
|
+
| 'pre_compact'
|
|
74
|
+
| 'post_compact'
|
|
75
|
+
| 'subagent_stop'
|
|
76
|
+
| 'run_start'
|
|
77
|
+
| 'run_end'
|
|
78
|
+
>
|
|
79
|
+
|
|
80
|
+
export const SHELL_HOOK_EVENTS: readonly ShellHookEvent[] = [
|
|
81
|
+
'user_prompt_submit',
|
|
82
|
+
'session_start',
|
|
83
|
+
'session_end',
|
|
84
|
+
'pre_tool_use',
|
|
85
|
+
'post_tool_use',
|
|
86
|
+
'pre_compact',
|
|
87
|
+
'post_compact',
|
|
88
|
+
'subagent_stop',
|
|
89
|
+
'run_start',
|
|
90
|
+
'run_end',
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
/** One shell command at one event. */
|
|
94
|
+
export interface ShellHookEntry {
|
|
95
|
+
/** Run with `sh -c`, in the working directory, with the event JSON on stdin. */
|
|
96
|
+
readonly command: string
|
|
97
|
+
/** Tool names this applies to: `*`, a name, or `a|b|prefix*`. Absent means every tool. */
|
|
98
|
+
readonly matcher?: string
|
|
99
|
+
/** Deadline in milliseconds; default `DEFAULT_SHELL_HOOK_TIMEOUT_MS`, capped at `MAX_SHELL_HOOK_TIMEOUT_MS`. */
|
|
100
|
+
readonly timeoutMs?: number
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Event → entries, the shape a host's config file carries. */
|
|
104
|
+
export type ShellHooksConfig = { readonly [event in ShellHookEvent]?: readonly ShellHookEntry[] }
|
|
105
|
+
|
|
106
|
+
/** The plugin id host shell hooks register under when the host names none. */
|
|
107
|
+
export const SHELL_HOOKS_PLUGIN_ID: PluginId = asPluginId('6d6f6bec-9d54-485b-90ca-52edbac1009d')
|
|
108
|
+
|
|
109
|
+
export const DEFAULT_SHELL_HOOK_TIMEOUT_MS = 30_000
|
|
110
|
+
export const MAX_SHELL_HOOK_TIMEOUT_MS = 10 * 60_000
|
|
111
|
+
/** Captured output bound per stream. */
|
|
112
|
+
const MAX_CAPTURE_BYTES = 64 * 1024
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* `matcher` against a tool name: `*`, or a `|`-separated list of names, each
|
|
116
|
+
* of which may end in `*`. Case-sensitive, because tool names are. A matcher
|
|
117
|
+
* on an event with no tool (`run_start`) matches nothing unless it is `*`.
|
|
118
|
+
*/
|
|
119
|
+
export function shellHookMatches(
|
|
120
|
+
matcher: string | undefined,
|
|
121
|
+
toolName: string | undefined,
|
|
122
|
+
): boolean {
|
|
123
|
+
if (matcher === undefined || matcher.trim() === '' || matcher.trim() === '*') return true
|
|
124
|
+
if (toolName === undefined) return false
|
|
125
|
+
return matcher.split('|').some((part) => {
|
|
126
|
+
const candidate = part.trim()
|
|
127
|
+
if (candidate.length === 0) return false
|
|
128
|
+
return candidate.endsWith('*')
|
|
129
|
+
? toolName.startsWith(candidate.slice(0, -1))
|
|
130
|
+
: toolName === candidate
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** What one hook run came back with, before it is mapped to a verdict. */
|
|
135
|
+
export interface ShellHookOutcome {
|
|
136
|
+
readonly exitCode: number | null
|
|
137
|
+
readonly timedOut: boolean
|
|
138
|
+
readonly stdout: string
|
|
139
|
+
readonly stderr: string
|
|
140
|
+
/** Set when the process could not be started at all. */
|
|
141
|
+
readonly spawnError?: string
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface ShellHookInput {
|
|
145
|
+
readonly event: ShellHookEvent
|
|
146
|
+
readonly cwd: string
|
|
147
|
+
readonly runId: string
|
|
148
|
+
readonly sessionId?: string
|
|
149
|
+
readonly parentRunId?: string
|
|
150
|
+
readonly prompt?: string
|
|
151
|
+
readonly compaction?: PluginCompactionInfo
|
|
152
|
+
readonly toolName?: string
|
|
153
|
+
readonly toolInput?: unknown
|
|
154
|
+
readonly toolResult?: {
|
|
155
|
+
readonly success: boolean
|
|
156
|
+
readonly output: string
|
|
157
|
+
readonly error?: string
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Run one hook command to completion, bounded by its deadline and capture. */
|
|
162
|
+
export function runShellHook(
|
|
163
|
+
entry: ShellHookEntry,
|
|
164
|
+
input: ShellHookInput,
|
|
165
|
+
signal?: AbortSignal,
|
|
166
|
+
): Promise<ShellHookOutcome> {
|
|
167
|
+
const timeoutMs = Math.min(
|
|
168
|
+
MAX_SHELL_HOOK_TIMEOUT_MS,
|
|
169
|
+
Math.max(1, entry.timeoutMs ?? DEFAULT_SHELL_HOOK_TIMEOUT_MS),
|
|
170
|
+
)
|
|
171
|
+
const payload = JSON.stringify({
|
|
172
|
+
event: input.event,
|
|
173
|
+
cwd: input.cwd,
|
|
174
|
+
run_id: input.runId,
|
|
175
|
+
...(input.sessionId !== undefined ? { session_id: input.sessionId } : {}),
|
|
176
|
+
...(input.parentRunId !== undefined ? { parent_run_id: input.parentRunId } : {}),
|
|
177
|
+
...(input.prompt !== undefined ? { prompt: input.prompt } : {}),
|
|
178
|
+
...(input.compaction !== undefined ? { compaction: input.compaction } : {}),
|
|
179
|
+
...(input.toolName !== undefined ? { tool_name: input.toolName } : {}),
|
|
180
|
+
...(input.toolInput !== undefined ? { tool_input: input.toolInput } : {}),
|
|
181
|
+
...(input.toolResult !== undefined ? { tool_result: input.toolResult } : {}),
|
|
182
|
+
})
|
|
183
|
+
const toolPath = pathOf(input.toolInput)
|
|
184
|
+
return new Promise((resolve) => {
|
|
185
|
+
let child: ReturnType<typeof spawn>
|
|
186
|
+
try {
|
|
187
|
+
child = spawn('sh', ['-c', entry.command], {
|
|
188
|
+
cwd: input.cwd,
|
|
189
|
+
env: {
|
|
190
|
+
...process.env,
|
|
191
|
+
NAMZU_HOOK_EVENT: input.event,
|
|
192
|
+
NAMZU_RUN_ID: input.runId,
|
|
193
|
+
...(input.sessionId !== undefined ? { NAMZU_SESSION_ID: input.sessionId } : {}),
|
|
194
|
+
...(input.toolName !== undefined ? { NAMZU_TOOL_NAME: input.toolName } : {}),
|
|
195
|
+
...(toolPath !== undefined ? { NAMZU_TOOL_PATH: toolPath } : {}),
|
|
196
|
+
},
|
|
197
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
198
|
+
// Its own process group, so the deadline can kill everything the
|
|
199
|
+
// command started. `sh -c 'sleep 5'` is one process under a shell
|
|
200
|
+
// that execs its last command and two under one that forks it;
|
|
201
|
+
// killing only the shell in the second case leaves `sleep` holding
|
|
202
|
+
// the stdout pipe, and the outcome cannot settle until it exits on
|
|
203
|
+
// its own — the hook's deadline becomes the grandchild's.
|
|
204
|
+
detached: process.platform !== 'win32',
|
|
205
|
+
})
|
|
206
|
+
} catch (error) {
|
|
207
|
+
resolve({
|
|
208
|
+
exitCode: null,
|
|
209
|
+
timedOut: false,
|
|
210
|
+
stdout: '',
|
|
211
|
+
stderr: '',
|
|
212
|
+
spawnError: error instanceof Error ? error.message : String(error),
|
|
213
|
+
})
|
|
214
|
+
return
|
|
215
|
+
}
|
|
216
|
+
let stdout = ''
|
|
217
|
+
let stderr = ''
|
|
218
|
+
let timedOut = false
|
|
219
|
+
let settled = false
|
|
220
|
+
const capture = (current: string, chunk: Buffer): string =>
|
|
221
|
+
current.length >= MAX_CAPTURE_BYTES
|
|
222
|
+
? current
|
|
223
|
+
: (current + chunk.toString('utf8')).slice(0, MAX_CAPTURE_BYTES)
|
|
224
|
+
child.stdout?.on('data', (chunk: Buffer) => {
|
|
225
|
+
stdout = capture(stdout, chunk)
|
|
226
|
+
})
|
|
227
|
+
child.stderr?.on('data', (chunk: Buffer) => {
|
|
228
|
+
stderr = capture(stderr, chunk)
|
|
229
|
+
})
|
|
230
|
+
const finish = (outcome: ShellHookOutcome) => {
|
|
231
|
+
if (settled) return
|
|
232
|
+
settled = true
|
|
233
|
+
clearTimeout(timer)
|
|
234
|
+
signal?.removeEventListener('abort', onAbort)
|
|
235
|
+
resolve(outcome)
|
|
236
|
+
}
|
|
237
|
+
const killTree = () => {
|
|
238
|
+
if (child.pid !== undefined && process.platform !== 'win32') {
|
|
239
|
+
try {
|
|
240
|
+
process.kill(-child.pid, 'SIGKILL')
|
|
241
|
+
return
|
|
242
|
+
} catch {
|
|
243
|
+
// The group is already gone, or this platform has no groups;
|
|
244
|
+
// the child alone is the best that can be done.
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
child.kill('SIGKILL')
|
|
248
|
+
}
|
|
249
|
+
const timer = setTimeout(() => {
|
|
250
|
+
timedOut = true
|
|
251
|
+
killTree()
|
|
252
|
+
}, timeoutMs)
|
|
253
|
+
const onAbort = () => killTree()
|
|
254
|
+
signal?.addEventListener('abort', onAbort, { once: true })
|
|
255
|
+
child.on('error', (error) => {
|
|
256
|
+
finish({ exitCode: null, timedOut, stdout, stderr, spawnError: error.message })
|
|
257
|
+
})
|
|
258
|
+
child.on('close', (code) => {
|
|
259
|
+
finish({ exitCode: code, timedOut, stdout, stderr })
|
|
260
|
+
})
|
|
261
|
+
child.on('exit', () => {
|
|
262
|
+
// After a kill, a survivor that still holds the pipes must not hold
|
|
263
|
+
// the outcome: drop our ends so `close` follows `exit` promptly.
|
|
264
|
+
if (timedOut || signal?.aborted) {
|
|
265
|
+
child.stdout?.destroy()
|
|
266
|
+
child.stderr?.destroy()
|
|
267
|
+
}
|
|
268
|
+
})
|
|
269
|
+
child.stdin?.on('error', () => {
|
|
270
|
+
// A hook that never reads stdin closes it; that is not a failure.
|
|
271
|
+
})
|
|
272
|
+
child.stdin?.end(payload)
|
|
273
|
+
})
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function pathOf(toolInput: unknown): string | undefined {
|
|
277
|
+
if (toolInput === null || typeof toolInput !== 'object') return undefined
|
|
278
|
+
const record = toolInput as Record<string, unknown>
|
|
279
|
+
for (const key of ['path', 'file_path', 'filePath']) {
|
|
280
|
+
const value = record[key]
|
|
281
|
+
if (typeof value === 'string' && value.length > 0) return value
|
|
282
|
+
}
|
|
283
|
+
return undefined
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* The verdict, from the outcome and the event. Pure apart from the logger,
|
|
288
|
+
* so the mapping — the part that decides what the model is told — is
|
|
289
|
+
* testable without a process.
|
|
290
|
+
*/
|
|
291
|
+
export function shellHookVerdict(
|
|
292
|
+
event: ShellHookEvent,
|
|
293
|
+
entry: ShellHookEntry,
|
|
294
|
+
outcome: ShellHookOutcome,
|
|
295
|
+
log: Logger = NOOP_LOGGER,
|
|
296
|
+
): PluginHookResult {
|
|
297
|
+
const attrs = { 'namzu.hook.event': event, 'namzu.hook.command': entry.command }
|
|
298
|
+
if (outcome.spawnError !== undefined) {
|
|
299
|
+
log.warn('hook could not start', { ...attrs, 'namzu.hook.error': outcome.spawnError })
|
|
300
|
+
return { action: 'continue' }
|
|
301
|
+
}
|
|
302
|
+
if (outcome.timedOut) {
|
|
303
|
+
log.warn('hook timed out', attrs)
|
|
304
|
+
return { action: 'continue' }
|
|
305
|
+
}
|
|
306
|
+
if (outcome.exitCode === 0) {
|
|
307
|
+
// On the prompt event, what the hook printed is context for the
|
|
308
|
+
// model — the branch, the time, a ticket. Everywhere else stdout is
|
|
309
|
+
// the operator's to read and the model's business not at all.
|
|
310
|
+
const text = outcome.stdout.trim()
|
|
311
|
+
if (event === 'user_prompt_submit' && text.length > 0) return { action: 'annotate', text }
|
|
312
|
+
return { action: 'continue' }
|
|
313
|
+
}
|
|
314
|
+
if (outcome.exitCode === 2) {
|
|
315
|
+
const reason =
|
|
316
|
+
outcome.stderr.trim() || outcome.stdout.trim() || `blocked by hook \`${entry.command}\``
|
|
317
|
+
if (event === 'pre_tool_use' || event === 'user_prompt_submit')
|
|
318
|
+
return { action: 'skip', reason }
|
|
319
|
+
log.warn('hook returned 2 on an event it cannot block', {
|
|
320
|
+
...attrs,
|
|
321
|
+
'namzu.hook.reason': reason,
|
|
322
|
+
})
|
|
323
|
+
return { action: 'continue' }
|
|
324
|
+
}
|
|
325
|
+
log.warn('hook failed', {
|
|
326
|
+
...attrs,
|
|
327
|
+
'namzu.hook.exit': outcome.exitCode ?? -1,
|
|
328
|
+
'namzu.hook.stderr': outcome.stderr.trim().slice(0, 500),
|
|
329
|
+
})
|
|
330
|
+
return { action: 'continue' }
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export interface ShellHookOptions {
|
|
334
|
+
/** Where the command runs and what `cwd` says on stdin. */
|
|
335
|
+
readonly cwd: string
|
|
336
|
+
readonly log?: Logger
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/** One entry as a hook definition the lifecycle manager accepts. */
|
|
340
|
+
export function createShellHook(
|
|
341
|
+
event: ShellHookEvent,
|
|
342
|
+
entry: ShellHookEntry,
|
|
343
|
+
options: ShellHookOptions,
|
|
344
|
+
): PluginHookDefinition {
|
|
345
|
+
const log = options.log ?? NOOP_LOGGER
|
|
346
|
+
return {
|
|
347
|
+
event,
|
|
348
|
+
handler: async (context: PluginHookContext) => {
|
|
349
|
+
if (!shellHookMatches(entry.matcher, context.toolName)) return { action: 'continue' }
|
|
350
|
+
const outcome = await runShellHook(
|
|
351
|
+
entry,
|
|
352
|
+
{
|
|
353
|
+
event,
|
|
354
|
+
cwd: options.cwd,
|
|
355
|
+
runId: String(context.runId),
|
|
356
|
+
...(context.sessionId !== undefined ? { sessionId: String(context.sessionId) } : {}),
|
|
357
|
+
...(context.parentRunId !== undefined
|
|
358
|
+
? { parentRunId: String(context.parentRunId) }
|
|
359
|
+
: {}),
|
|
360
|
+
...(context.prompt !== undefined ? { prompt: context.prompt } : {}),
|
|
361
|
+
...(context.compaction !== undefined ? { compaction: context.compaction } : {}),
|
|
362
|
+
...(context.toolName !== undefined ? { toolName: context.toolName } : {}),
|
|
363
|
+
...(context.toolInput !== undefined ? { toolInput: context.toolInput } : {}),
|
|
364
|
+
...(context.toolResult !== undefined
|
|
365
|
+
? {
|
|
366
|
+
toolResult: {
|
|
367
|
+
success: context.toolResult.success,
|
|
368
|
+
output: context.toolResult.output,
|
|
369
|
+
...(context.toolResult.error !== undefined
|
|
370
|
+
? { error: context.toolResult.error }
|
|
371
|
+
: {}),
|
|
372
|
+
},
|
|
373
|
+
}
|
|
374
|
+
: {}),
|
|
375
|
+
},
|
|
376
|
+
context.signal,
|
|
377
|
+
)
|
|
378
|
+
return shellHookVerdict(event, entry, outcome, log)
|
|
379
|
+
},
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Register every entry on the manager, in file order within an event. The
|
|
385
|
+
* manager runs `post_*` hooks in reverse, as it does for plugins, so a
|
|
386
|
+
* formatter registered last runs first after a write. Returns how many were
|
|
387
|
+
* attached.
|
|
388
|
+
*/
|
|
389
|
+
export function attachShellHooks(
|
|
390
|
+
manager: Pick<PluginLifecycleManager, 'registerHook'>,
|
|
391
|
+
hooks: ShellHooksConfig,
|
|
392
|
+
options: ShellHookOptions & { readonly pluginId?: PluginId },
|
|
393
|
+
): number {
|
|
394
|
+
const pluginId = options.pluginId ?? SHELL_HOOKS_PLUGIN_ID
|
|
395
|
+
let count = 0
|
|
396
|
+
for (const event of SHELL_HOOK_EVENTS) {
|
|
397
|
+
for (const entry of hooks[event] ?? []) {
|
|
398
|
+
manager.registerHook(pluginId, createShellHook(event, entry, options))
|
|
399
|
+
count += 1
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return count
|
|
403
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a coding agent works, as text the model reads.
|
|
3
|
+
*
|
|
4
|
+
* A system prompt built from the kernel says WHO the agent is and what tools
|
|
5
|
+
* it has. Nothing said HOW it should work: whether to act or ask, how much of
|
|
6
|
+
* a request to deliver, what to do when a test fails, when a shell command is
|
|
7
|
+
* the wrong tool, what is off-limits in git without a person saying so. Every
|
|
8
|
+
* one of those was left to the underlying model's defaults, and the defaults
|
|
9
|
+
* differ per provider — so the same session felt like a different agent
|
|
10
|
+
* depending on which model was behind it, and an operator experienced the gap
|
|
11
|
+
* as "it narrates instead of doing", "it stopped halfway", "it asked me three
|
|
12
|
+
* things it could have decided".
|
|
13
|
+
*
|
|
14
|
+
* This lived in the operator application first. It moved here because none of
|
|
15
|
+
* it is about that application: every rule names a builtin tool of this kernel
|
|
16
|
+
* (`read`, `edit`, `bash`, `task_create`, `Agent`) or a behaviour any coding
|
|
17
|
+
* agent built on it wants, and a second host would otherwise copy the text and
|
|
18
|
+
* let the two drift.
|
|
19
|
+
*
|
|
20
|
+
* Two texts, not one, and the split is by TOOL SET rather than by topic.
|
|
21
|
+
* `CODING_AGENT_WORKING_DOCTRINE` names only the builtins and is meant for the
|
|
22
|
+
* parent and for every delegated sub-agent, because a delegated task edits the
|
|
23
|
+
* same repository under the same rules. `CODING_AGENT_DELEGATION_DOCTRINE`
|
|
24
|
+
* names `task_create` and `Agent`, which a sub-agent does not have, and so is
|
|
25
|
+
* for the parent only. An adversarial review caught a draft ordering children
|
|
26
|
+
* to plan with a tool they could not call; a rule about a tool the reader does
|
|
27
|
+
* not have is not guidance, it is an instruction to fail.
|
|
28
|
+
*
|
|
29
|
+
* Each rule names a behaviour, not a value; a rule about one repository
|
|
30
|
+
* belongs in that repository's instructions file, which the model receives
|
|
31
|
+
* separately. A host that wants its own identity block puts it in
|
|
32
|
+
* `systemPrompt`; the contribution below lands after it.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
import type { PromptContribution } from './contributions.js'
|
|
36
|
+
|
|
37
|
+
export const CODING_AGENT_WORKING_DOCTRINE = `## How you work
|
|
38
|
+
|
|
39
|
+
### Delivering work
|
|
40
|
+
- Act when you have enough information. Do not re-derive facts already established, and do not re-open a decision the user has already made.
|
|
41
|
+
- The requested scope is the deliverable. Do not quietly narrow it, widen it, or turn it into something adjacent. Read ambiguity the way a careful colleague would; make the routine judgment calls yourself and check in only when different readings would produce materially different work.
|
|
42
|
+
- Finish the whole task, not just the easy parts. If one part is blocked — a tool or capability you do not have, an input that is missing — say so plainly, do not improvise a result for it, finish every other part in full, and say explicitly what you left out and why. Scaling the work down is the user's call.
|
|
43
|
+
- If you find a real problem with the task as stated, say so in a sentence or two, then keep going under a stated assumption. Reserve blocking questions for cases where proceeding under any assumption would be unsafe or would make the work useless if wrong.
|
|
44
|
+
- If the user repeats or reaffirms a request after you raised a concern, that is their decision: say so and do the full request.
|
|
45
|
+
|
|
46
|
+
### Reporting
|
|
47
|
+
- Report outcomes faithfully. If tests fail, say so and show the output. If you skipped a step, say it was skipped. When something is done and verified, state it plainly without hedging.
|
|
48
|
+
- Never present a green run on a subset as a green run. Name what was actually executed.
|
|
49
|
+
- Reference code as \`path:line\` so the user can jump to it.
|
|
50
|
+
- Correct an earlier statement only when the error would change the user's code, conclusions or decisions; state it once, plainly, and continue. No apologies, no tally of past mistakes.
|
|
51
|
+
|
|
52
|
+
### Reading and editing code
|
|
53
|
+
- Read a file before you edit it, and read enough of the surrounding code to match its comment density, naming and idiom. Code that reads like the file it lives in is the goal; code that reads like a different author is a defect.
|
|
54
|
+
- Prefer the dedicated tools over shell equivalents: \`read\` over \`cat\`, the \`grep\` tool over running \`grep\` or \`rg\` through bash, \`glob\` over \`find\` or \`ls -R\`, \`edit\` over \`sed -i\`. To change an existing file use \`edit\`; use \`write\` only to create a file or when the user asked for a whole-file rewrite. The dedicated tools are bounded, previewable and permission-aware; a shell command is none of those.
|
|
55
|
+
- Independent tool calls go in one response. Reading three files, or running a grep and a glob, does not need three turns. Tools that mutate the workspace — \`bash\`, \`edit\`, \`write\` — are applied one after another even when you emit them together; read-only tools run in parallel.
|
|
56
|
+
- After a change, run the checks that would catch a mistake in it — the package's tests, typecheck, lint — before you report it done. A change you did not verify is a change you are guessing about.
|
|
57
|
+
- Never leave the working tree in a state you have not described. If you created scratch files, say where; if you touched files outside the request, say which.
|
|
58
|
+
|
|
59
|
+
### Working with git
|
|
60
|
+
- Never push, force-push, reset, rebase, clean, or otherwise discard or rewrite history unless the user explicitly asked for that action. Approval for one push does not extend to the next.
|
|
61
|
+
- Before any command that could discard uncommitted work, run \`git status\`. If there are changes there that you did not make, stop and ask rather than stashing, committing or discarding somebody else's work.
|
|
62
|
+
- Commit only when the user asks, on the branch that is checked out. Do not create or switch branches unless the user asks or the project's instructions require it.
|
|
63
|
+
- After a broad \`git add\`, review what was staged before committing; a file whose name looks harmless can still carry a secret.
|
|
64
|
+
|
|
65
|
+
### Keeping the user informed
|
|
66
|
+
- Before a batch of tool calls, say in one short line what you are about to do and why. When you have been working for a while without saying anything, say in a few words where you are, then continue. One line, not a paragraph; the tool rows on screen already show the details.
|
|
67
|
+
- Keep the final reply short and specific: what changed, what was verified, what is left. Do not restate the transcript.`
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Parent-only: rules about `task_create` / `task_update` and `Agent`, which a
|
|
71
|
+
* delegated sub-agent does not have. See the module comment for the split.
|
|
72
|
+
*/
|
|
73
|
+
export const CODING_AGENT_DELEGATION_DOCTRINE = `### Planning and delegating
|
|
74
|
+
- For work that is genuinely multi-step — several files, several distinct stages, anything you would write a checklist for — open a task list with \`task_create\` and keep it current with \`task_update\`, marking each step done when it is done rather than at the end. Do not open one for a single inspect-edit-test cycle; the list is for the user to follow, and a list of one item tells them nothing.
|
|
75
|
+
- When the \`Agent\` tool is available, delegate genuinely independent work through it and give each delegation a short, specific description; the user watches those descriptions, not the prompts. Each sub-agent starts with no context, so the prompt must carry everything it needs.
|
|
76
|
+
- Delegate lookups — where something is defined, which files reference it, how a module works — with \`subagent_type: "explore"\`: it has reading and searching tools only and never interrupts the user for permission. Reserve the default sub-agent for work that changes files or runs commands.`
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* For a session whose permission layer refuses every mutation. Says what that
|
|
80
|
+
* layer will enforce anyway, so the model plans instead of discovering the
|
|
81
|
+
* boundary one refused call at a time.
|
|
82
|
+
*/
|
|
83
|
+
export const PLAN_MODE_DOCTRINE = `## Plan mode
|
|
84
|
+
|
|
85
|
+
You are in plan mode. Read, search and think; do not change anything. \`read\`, \`grep\`, \`glob\` and the other read-only tools work as usual, and you may keep a task list. Any \`edit\`, \`write\` or shell command that changes state will be refused, so do not attempt one.
|
|
86
|
+
|
|
87
|
+
When you have understood the task, reply with the plan: what you would change, in which files, in what order, and what you would verify. Be concrete — name files and functions — and short enough to read in one screen. Then stop and wait; the user will leave plan mode to have the plan carried out, and that switch is their approval.`
|
|
88
|
+
|
|
89
|
+
export const CODING_AGENT_DOCTRINE_CONTRIBUTION_ID = 'namzu.coding-agent-doctrine'
|
|
90
|
+
|
|
91
|
+
export interface CodingAgentDoctrineOptions {
|
|
92
|
+
/**
|
|
93
|
+
* Include the parent-only delegation rules. Default `true`; a host
|
|
94
|
+
* building the prompt of a delegated sub-agent, which has no `Agent` or
|
|
95
|
+
* `task_create`, passes `false`.
|
|
96
|
+
*/
|
|
97
|
+
delegation?: boolean
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The doctrine as a `static` contribution: it depends on nothing that changes
|
|
102
|
+
* inside a run, so it belongs in the cached prefix. Register it on the
|
|
103
|
+
* `PromptContributionRegistry` handed to `query`; it renders after
|
|
104
|
+
* `systemPrompt` and the skills section.
|
|
105
|
+
*/
|
|
106
|
+
export function codingAgentDoctrineContribution(
|
|
107
|
+
options: CodingAgentDoctrineOptions = {},
|
|
108
|
+
): PromptContribution {
|
|
109
|
+
const text =
|
|
110
|
+
options.delegation === false
|
|
111
|
+
? CODING_AGENT_WORKING_DOCTRINE
|
|
112
|
+
: `${CODING_AGENT_WORKING_DOCTRINE}\n\n${CODING_AGENT_DELEGATION_DOCTRINE}`
|
|
113
|
+
return {
|
|
114
|
+
id: CODING_AGENT_DOCTRINE_CONTRIBUTION_ID,
|
|
115
|
+
placement: 'static',
|
|
116
|
+
render: () => text,
|
|
117
|
+
}
|
|
118
|
+
}
|
package/src/prompt/index.ts
CHANGED
|
@@ -13,3 +13,11 @@ export type {
|
|
|
13
13
|
PromptContributionContext,
|
|
14
14
|
PromptPlacement,
|
|
15
15
|
} from './contributions.js'
|
|
16
|
+
export {
|
|
17
|
+
CODING_AGENT_DELEGATION_DOCTRINE,
|
|
18
|
+
CODING_AGENT_DOCTRINE_CONTRIBUTION_ID,
|
|
19
|
+
CODING_AGENT_WORKING_DOCTRINE,
|
|
20
|
+
PLAN_MODE_DOCTRINE,
|
|
21
|
+
codingAgentDoctrineContribution,
|
|
22
|
+
} from './coding-agent-doctrine.js'
|
|
23
|
+
export type { CodingAgentDoctrineOptions } from './coding-agent-doctrine.js'
|
package/src/provider/errors.ts
CHANGED
|
@@ -412,7 +412,7 @@ function vendorRetryAfter(err: unknown): string | undefined {
|
|
|
412
412
|
* isolation — that is what would catch a driver that stops going through
|
|
413
413
|
* `providerVendorError`/`providerHttpError` and attaches one directly.
|
|
414
414
|
* `packages/sdk/src/provider/__tests__/errors.test.ts` pins the same thing
|
|
415
|
-
* against this shared function directly. See
|
|
415
|
+
* against this shared function directly. See "index".
|
|
416
416
|
*
|
|
417
417
|
* `name` is checked too, because AWS models its failures as distinct classes
|
|
418
418
|
* (`ThrottlingException`, `ValidationException`, `AccessDeniedException`) rather
|