@namzu/sdk 30.2.0 → 31.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 +556 -0
- package/README.md +43 -2
- package/dist/advisory/executor.d.ts +2 -1
- package/dist/advisory/executor.d.ts.map +1 -1
- package/dist/advisory/executor.js +4 -1
- package/dist/advisory/executor.js.map +1 -1
- package/dist/agents/ReactiveAgent.d.ts.map +1 -1
- package/dist/agents/ReactiveAgent.js +12 -0
- package/dist/agents/ReactiveAgent.js.map +1 -1
- package/dist/agents/RouterAgent.d.ts.map +1 -1
- package/dist/agents/RouterAgent.js +21 -3
- package/dist/agents/RouterAgent.js.map +1 -1
- package/dist/agents/SupervisorAgent.d.ts.map +1 -1
- package/dist/agents/SupervisorAgent.js +34 -11
- package/dist/agents/SupervisorAgent.js.map +1 -1
- package/dist/agents/runAgent.d.ts +12 -0
- package/dist/agents/runAgent.d.ts.map +1 -1
- package/dist/agents/runAgent.js +26 -2
- package/dist/agents/runAgent.js.map +1 -1
- package/dist/authorization/command-line.d.ts +81 -0
- package/dist/authorization/command-line.d.ts.map +1 -0
- package/dist/authorization/command-line.js +347 -0
- package/dist/authorization/command-line.js.map +1 -0
- package/dist/authorization/rules.d.ts.map +1 -1
- package/dist/authorization/rules.js +22 -1
- package/dist/authorization/rules.js.map +1 -1
- package/dist/bridge/a2a/client.d.ts +23 -5
- package/dist/bridge/a2a/client.d.ts.map +1 -1
- package/dist/bridge/a2a/client.js +320 -73
- package/dist/bridge/a2a/client.js.map +1 -1
- package/dist/bridge/a2a/mapper.d.ts.map +1 -1
- package/dist/bridge/a2a/mapper.js +4 -0
- package/dist/bridge/a2a/mapper.js.map +1 -1
- package/dist/bridge/acp/server.d.ts +13 -1
- package/dist/bridge/acp/server.d.ts.map +1 -1
- package/dist/bridge/acp/server.js +150 -44
- package/dist/bridge/acp/server.js.map +1 -1
- package/dist/bridge/mcp/connector/adapter.d.ts +3 -2
- package/dist/bridge/mcp/connector/adapter.d.ts.map +1 -1
- package/dist/bridge/mcp/connector/adapter.js +17 -21
- package/dist/bridge/mcp/connector/adapter.js.map +1 -1
- package/dist/bridge/sse/mapper.d.ts.map +1 -1
- package/dist/bridge/sse/mapper.js +3 -0
- package/dist/bridge/sse/mapper.js.map +1 -1
- package/dist/compaction/dangling.d.ts +29 -2
- package/dist/compaction/dangling.d.ts.map +1 -1
- package/dist/compaction/dangling.js +172 -35
- package/dist/compaction/dangling.js.map +1 -1
- package/dist/compaction/index.d.ts +3 -2
- package/dist/compaction/index.d.ts.map +1 -1
- package/dist/compaction/index.js +1 -1
- package/dist/compaction/index.js.map +1 -1
- package/dist/compaction/manual.d.ts +11 -1
- package/dist/compaction/manual.d.ts.map +1 -1
- package/dist/compaction/manual.js +89 -14
- package/dist/compaction/manual.js.map +1 -1
- package/dist/compaction/plan.d.ts +19 -6
- package/dist/compaction/plan.d.ts.map +1 -1
- package/dist/compaction/plan.js +18 -4
- package/dist/compaction/plan.js.map +1 -1
- package/dist/compaction/retention.d.ts +10 -7
- package/dist/compaction/retention.d.ts.map +1 -1
- package/dist/compaction/retention.js +26 -8
- package/dist/compaction/retention.js.map +1 -1
- package/dist/compaction/summary.d.ts +4 -4
- package/dist/compaction/summary.js +4 -4
- package/dist/compaction/verifier.d.ts +19 -1
- package/dist/compaction/verifier.d.ts.map +1 -1
- package/dist/compaction/verifier.js +20 -1
- package/dist/compaction/verifier.js.map +1 -1
- package/dist/config/runtime.d.ts +6 -6
- package/dist/connector/BaseConnector.d.ts +6 -4
- package/dist/connector/BaseConnector.d.ts.map +1 -1
- package/dist/connector/BaseConnector.js +8 -2
- package/dist/connector/BaseConnector.js.map +1 -1
- package/dist/connector/builtins/http.d.ts +16 -4
- package/dist/connector/builtins/http.d.ts.map +1 -1
- package/dist/connector/builtins/http.js +177 -44
- package/dist/connector/builtins/http.js.map +1 -1
- package/dist/connector/builtins/webhook.d.ts +15 -4
- package/dist/connector/builtins/webhook.d.ts.map +1 -1
- package/dist/connector/builtins/webhook.js +165 -45
- package/dist/connector/builtins/webhook.js.map +1 -1
- package/dist/connector/execution-contract.d.ts +11 -0
- package/dist/connector/execution-contract.d.ts.map +1 -0
- package/dist/connector/execution-contract.js +14 -0
- package/dist/connector/execution-contract.js.map +1 -0
- package/dist/connector/http-operation.d.ts +48 -0
- package/dist/connector/http-operation.d.ts.map +1 -0
- package/dist/connector/http-operation.js +205 -0
- package/dist/connector/http-operation.js.map +1 -0
- package/dist/connector/mcp/adapter.d.ts.map +1 -1
- package/dist/connector/mcp/adapter.js +8 -3
- package/dist/connector/mcp/adapter.js.map +1 -1
- package/dist/connector/mcp/client.d.ts +14 -8
- package/dist/connector/mcp/client.d.ts.map +1 -1
- package/dist/connector/mcp/client.js +160 -44
- package/dist/connector/mcp/client.js.map +1 -1
- package/dist/connector/mcp/http-sse.d.ts +8 -2
- package/dist/connector/mcp/http-sse.d.ts.map +1 -1
- package/dist/connector/mcp/http-sse.js +70 -17
- package/dist/connector/mcp/http-sse.js.map +1 -1
- package/dist/connector/mcp/prompt-adapter.d.ts.map +1 -1
- package/dist/connector/mcp/prompt-adapter.js +9 -2
- package/dist/connector/mcp/prompt-adapter.js.map +1 -1
- package/dist/connector/mcp/stdio.d.ts +2 -2
- package/dist/connector/mcp/stdio.d.ts.map +1 -1
- package/dist/connector/mcp/stdio.js +14 -50
- package/dist/connector/mcp/stdio.js.map +1 -1
- package/dist/connector/mcp/streamable-http.d.ts +7 -2
- package/dist/connector/mcp/streamable-http.d.ts.map +1 -1
- package/dist/connector/mcp/streamable-http.js +66 -18
- package/dist/connector/mcp/streamable-http.js.map +1 -1
- package/dist/connector/tools/adapter.d.ts +2 -2
- package/dist/connector/tools/adapter.d.ts.map +1 -1
- package/dist/connector/tools/adapter.js +23 -14
- package/dist/connector/tools/adapter.js.map +1 -1
- package/dist/connector/tools/definitions.d.ts.map +1 -1
- package/dist/connector/tools/definitions.js +5 -2
- package/dist/connector/tools/definitions.js.map +1 -1
- package/dist/connector/tools/result.d.ts +4 -0
- package/dist/connector/tools/result.d.ts.map +1 -0
- package/dist/connector/tools/result.js +20 -0
- package/dist/connector/tools/result.js.map +1 -0
- package/dist/connector/web/guarded-fetch.d.ts +4 -2
- package/dist/connector/web/guarded-fetch.d.ts.map +1 -1
- package/dist/connector/web/guarded-fetch.js +157 -43
- package/dist/connector/web/guarded-fetch.js.map +1 -1
- package/dist/constants/sandbox/index.d.ts +3 -2
- package/dist/constants/sandbox/index.d.ts.map +1 -1
- package/dist/constants/sandbox/index.js +3 -2
- package/dist/constants/sandbox/index.js.map +1 -1
- package/dist/contracts/api.d.ts +2 -0
- package/dist/contracts/api.d.ts.map +1 -1
- package/dist/contracts/schemas.d.ts +38 -12
- package/dist/contracts/schemas.d.ts.map +1 -1
- package/dist/contracts/schemas.js +7 -0
- package/dist/contracts/schemas.js.map +1 -1
- package/dist/directory/derive-supervisor.d.ts.map +1 -1
- package/dist/directory/derive-supervisor.js +8 -0
- package/dist/directory/derive-supervisor.js.map +1 -1
- package/dist/directory/derive.d.ts.map +1 -1
- package/dist/directory/derive.js +8 -0
- package/dist/directory/derive.js.map +1 -1
- package/dist/directory/load.d.ts.map +1 -1
- package/dist/directory/load.js +2 -0
- package/dist/directory/load.js.map +1 -1
- package/dist/directory/types.d.ts +4 -0
- package/dist/directory/types.d.ts.map +1 -1
- package/dist/eval/experiment.d.ts +10 -10
- package/dist/eval/experiment.d.ts.map +1 -1
- package/dist/eval/experiment.js +121 -91
- package/dist/eval/experiment.js.map +1 -1
- package/dist/eval/judge.d.ts +6 -0
- package/dist/eval/judge.d.ts.map +1 -1
- package/dist/eval/judge.js +7 -2
- package/dist/eval/judge.js.map +1 -1
- package/dist/eval/types.d.ts +7 -1
- package/dist/eval/types.d.ts.map +1 -1
- package/dist/manager/agent/lifecycle.d.ts +12 -10
- package/dist/manager/agent/lifecycle.d.ts.map +1 -1
- package/dist/manager/agent/lifecycle.js +16 -3
- package/dist/manager/agent/lifecycle.js.map +1 -1
- package/dist/manager/connector/environment.d.ts +2 -2
- package/dist/manager/connector/environment.d.ts.map +1 -1
- package/dist/manager/connector/environment.js +2 -2
- package/dist/manager/connector/environment.js.map +1 -1
- package/dist/manager/connector/lifecycle.d.ts +10 -2
- package/dist/manager/connector/lifecycle.d.ts.map +1 -1
- package/dist/manager/connector/lifecycle.js +273 -24
- package/dist/manager/connector/lifecycle.js.map +1 -1
- package/dist/manager/connector/tenant.d.ts +5 -4
- package/dist/manager/connector/tenant.d.ts.map +1 -1
- package/dist/manager/connector/tenant.js +47 -22
- package/dist/manager/connector/tenant.js.map +1 -1
- package/dist/manager/goal/activation.d.ts +23 -0
- package/dist/manager/goal/activation.d.ts.map +1 -0
- package/dist/manager/goal/activation.js +41 -0
- package/dist/manager/goal/activation.js.map +1 -0
- package/dist/manager/index.d.ts +3 -2
- package/dist/manager/index.d.ts.map +1 -1
- package/dist/manager/index.js.map +1 -1
- package/dist/manager/run/persistence.d.ts +2 -0
- package/dist/manager/run/persistence.d.ts.map +1 -1
- package/dist/manager/run/persistence.js +5 -1
- package/dist/manager/run/persistence.js.map +1 -1
- package/dist/manager/topic/dependency.d.ts +24 -0
- package/dist/manager/topic/dependency.d.ts.map +1 -0
- package/dist/manager/topic/dependency.js +13 -0
- package/dist/manager/topic/dependency.js.map +1 -0
- package/dist/manager/topic/lifecycle.d.ts +9 -21
- package/dist/manager/topic/lifecycle.d.ts.map +1 -1
- package/dist/manager/topic/lifecycle.js +17 -29
- package/dist/manager/topic/lifecycle.js.map +1 -1
- package/dist/plugin/index.d.ts +1 -0
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js.map +1 -1
- package/dist/plugin/lifecycle.d.ts +15 -0
- package/dist/plugin/lifecycle.d.ts.map +1 -1
- package/dist/plugin/lifecycle.js +144 -38
- package/dist/plugin/lifecycle.js.map +1 -1
- package/dist/plugin/loader.d.ts +3 -3
- package/dist/plugin/loader.d.ts.map +1 -1
- package/dist/plugin/loader.js +58 -12
- package/dist/plugin/loader.js.map +1 -1
- package/dist/provider/collect-chat-completion.d.ts.map +1 -1
- package/dist/provider/collect-chat-completion.js +4 -0
- package/dist/provider/collect-chat-completion.js.map +1 -1
- package/dist/provider/fallback.d.ts +3 -1
- package/dist/provider/fallback.d.ts.map +1 -1
- package/dist/provider/fallback.js +62 -10
- package/dist/provider/fallback.js.map +1 -1
- package/dist/provider/idle-timeout.d.ts +4 -0
- package/dist/provider/idle-timeout.d.ts.map +1 -1
- package/dist/provider/idle-timeout.js +131 -15
- package/dist/provider/idle-timeout.js.map +1 -1
- package/dist/provider/index.d.ts +2 -0
- package/dist/provider/index.d.ts.map +1 -1
- package/dist/provider/index.js +1 -0
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/instrumentation.d.ts.map +1 -1
- package/dist/provider/instrumentation.js +1 -0
- package/dist/provider/instrumentation.js.map +1 -1
- package/dist/provider/retry.d.ts.map +1 -1
- package/dist/provider/retry.js +13 -1
- package/dist/provider/retry.js.map +1 -1
- package/dist/public-runtime.d.ts +57 -24
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +42 -35
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +1 -0
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +5 -0
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +33 -12
- package/dist/public-types.d.ts.map +1 -1
- package/dist/rag/embedding.d.ts +8 -3
- package/dist/rag/embedding.d.ts.map +1 -1
- package/dist/rag/embedding.js +120 -9
- package/dist/rag/embedding.js.map +1 -1
- package/dist/rag/index.d.ts +1 -1
- package/dist/rag/index.d.ts.map +1 -1
- package/dist/rag/index.js +1 -1
- package/dist/rag/index.js.map +1 -1
- package/dist/rag/ingestion.d.ts +2 -2
- package/dist/rag/ingestion.d.ts.map +1 -1
- package/dist/rag/ingestion.js +15 -3
- package/dist/rag/ingestion.js.map +1 -1
- package/dist/rag/knowledge-base.d.ts +3 -3
- package/dist/rag/knowledge-base.d.ts.map +1 -1
- package/dist/rag/knowledge-base.js +8 -4
- package/dist/rag/knowledge-base.js.map +1 -1
- package/dist/rag/operation.d.ts +10 -0
- package/dist/rag/operation.d.ts.map +1 -0
- package/dist/rag/operation.js +26 -0
- package/dist/rag/operation.js.map +1 -0
- package/dist/rag/rag-tool.d.ts.map +1 -1
- package/dist/rag/rag-tool.js +6 -3
- package/dist/rag/rag-tool.js.map +1 -1
- package/dist/rag/retriever.d.ts +2 -2
- package/dist/rag/retriever.d.ts.map +1 -1
- package/dist/rag/retriever.js +31 -15
- package/dist/rag/retriever.js.map +1 -1
- package/dist/rag/vector-store.d.ts +3 -3
- package/dist/rag/vector-store.d.ts.map +1 -1
- package/dist/rag/vector-store.js +4 -2
- package/dist/rag/vector-store.js.map +1 -1
- package/dist/registry/command/kernel-commands.d.ts +16 -4
- package/dist/registry/command/kernel-commands.d.ts.map +1 -1
- package/dist/registry/command/kernel-commands.js +171 -0
- package/dist/registry/command/kernel-commands.js.map +1 -1
- package/dist/run/reporter.d.ts.map +1 -1
- package/dist/run/reporter.js +9 -0
- package/dist/run/reporter.js.map +1 -1
- package/dist/run-query/index.d.ts +15 -1
- package/dist/run-query/index.d.ts.map +1 -1
- package/dist/run-query/index.js +69 -15
- package/dist/run-query/index.js.map +1 -1
- package/dist/runtime/query/context.d.ts.map +1 -1
- package/dist/runtime/query/context.js +10 -3
- package/dist/runtime/query/context.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +3 -0
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +80 -18
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/guard.d.ts +9 -0
- package/dist/runtime/query/guard.d.ts.map +1 -1
- package/dist/runtime/query/guard.js +11 -0
- package/dist/runtime/query/guard.js.map +1 -1
- package/dist/runtime/query/index.d.ts +30 -1
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +548 -95
- 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 +74 -14
- 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 +94 -53
- package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context.d.ts +3 -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 +21 -0
- package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
- package/dist/runtime/query/iteration/stream-turn.d.ts.map +1 -1
- package/dist/runtime/query/iteration/stream-turn.js +4 -0
- package/dist/runtime/query/iteration/stream-turn.js.map +1 -1
- package/dist/runtime/query/project-instructions.d.ts +69 -0
- package/dist/runtime/query/project-instructions.d.ts.map +1 -0
- package/dist/runtime/query/project-instructions.js +137 -0
- package/dist/runtime/query/project-instructions.js.map +1 -0
- package/dist/runtime/query/request-rich-content.d.ts +22 -0
- package/dist/runtime/query/request-rich-content.d.ts.map +1 -0
- package/dist/runtime/query/request-rich-content.js +122 -0
- package/dist/runtime/query/request-rich-content.js.map +1 -0
- package/dist/runtime/query/result.d.ts.map +1 -1
- package/dist/runtime/query/result.js +12 -1
- package/dist/runtime/query/result.js.map +1 -1
- package/dist/runtime/query/resume-pending.d.ts.map +1 -1
- package/dist/runtime/query/resume-pending.js +19 -20
- package/dist/runtime/query/resume-pending.js.map +1 -1
- package/dist/runtime/query/resume-run.d.ts.map +1 -1
- package/dist/runtime/query/resume-run.js +54 -8
- package/dist/runtime/query/resume-run.js.map +1 -1
- package/dist/runtime/query/run-state.d.ts +5 -0
- package/dist/runtime/query/run-state.d.ts.map +1 -1
- package/dist/runtime/query/run-state.js +6 -1
- package/dist/runtime/query/run-state.js.map +1 -1
- package/dist/runtime/query/sandbox-lifecycle.d.ts +54 -0
- package/dist/runtime/query/sandbox-lifecycle.d.ts.map +1 -0
- package/dist/runtime/query/sandbox-lifecycle.js +167 -0
- package/dist/runtime/query/sandbox-lifecycle.js.map +1 -0
- package/dist/sandbox/isolation.d.ts.map +1 -1
- package/dist/sandbox/isolation.js +9 -0
- package/dist/sandbox/isolation.js.map +1 -1
- package/dist/sandbox/provider/local.d.ts +56 -6
- package/dist/sandbox/provider/local.d.ts.map +1 -1
- package/dist/sandbox/provider/local.js +181 -76
- package/dist/sandbox/provider/local.js.map +1 -1
- package/dist/sandbox/terminal.d.ts +13 -5
- package/dist/sandbox/terminal.d.ts.map +1 -1
- package/dist/sandbox/terminal.js +11 -3
- package/dist/sandbox/terminal.js.map +1 -1
- package/dist/session/errors.d.ts +28 -29
- package/dist/session/errors.d.ts.map +1 -1
- package/dist/session/errors.js +28 -29
- package/dist/session/errors.js.map +1 -1
- package/dist/session/handoff/broadcast.d.ts +5 -8
- package/dist/session/handoff/broadcast.d.ts.map +1 -1
- package/dist/session/handoff/broadcast.js +16 -6
- package/dist/session/handoff/broadcast.js.map +1 -1
- package/dist/session/handoff/single.d.ts +5 -8
- package/dist/session/handoff/single.d.ts.map +1 -1
- package/dist/session/handoff/single.js +7 -4
- package/dist/session/handoff/single.js.map +1 -1
- package/dist/store/attachment/index.d.ts +11 -3
- package/dist/store/attachment/index.d.ts.map +1 -1
- package/dist/store/attachment/index.js +49 -4
- package/dist/store/attachment/index.js.map +1 -1
- package/dist/store/feedback/conformance.d.ts.map +1 -1
- package/dist/store/feedback/conformance.js +32 -0
- package/dist/store/feedback/conformance.js.map +1 -1
- package/dist/store/feedback/disk.d.ts +8 -6
- package/dist/store/feedback/disk.d.ts.map +1 -1
- package/dist/store/feedback/disk.js +111 -76
- package/dist/store/feedback/disk.js.map +1 -1
- package/dist/store/goal/index.d.ts +111 -0
- package/dist/store/goal/index.d.ts.map +1 -0
- package/dist/store/goal/index.js +436 -0
- package/dist/store/goal/index.js.map +1 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +1 -1
- package/dist/store/index.js.map +1 -1
- package/dist/store/kv/revision-record-store.d.ts +70 -0
- package/dist/store/kv/revision-record-store.d.ts.map +1 -0
- package/dist/store/kv/revision-record-store.js +290 -0
- package/dist/store/kv/revision-record-store.js.map +1 -0
- package/dist/store/memory/disk.d.ts +9 -7
- package/dist/store/memory/disk.d.ts.map +1 -1
- package/dist/store/memory/disk.js +256 -98
- package/dist/store/memory/disk.js.map +1 -1
- package/dist/store/run/disk.d.ts +10 -2
- package/dist/store/run/disk.d.ts.map +1 -1
- package/dist/store/run/disk.js +70 -4
- package/dist/store/run/disk.js.map +1 -1
- package/dist/store/run/memory.d.ts +4 -2
- package/dist/store/run/memory.d.ts.map +1 -1
- package/dist/store/run/memory.js +15 -1
- package/dist/store/run/memory.js.map +1 -1
- package/dist/store/session/disk.d.ts +9 -0
- package/dist/store/session/disk.d.ts.map +1 -1
- package/dist/store/session/disk.js +57 -5
- package/dist/store/session/disk.js.map +1 -1
- package/dist/store/session/memory.d.ts +1 -0
- package/dist/store/session/memory.d.ts.map +1 -1
- package/dist/store/session/memory.js +14 -0
- package/dist/store/session/memory.js.map +1 -1
- package/dist/store/topic/memory.d.ts +1 -2
- package/dist/store/topic/memory.d.ts.map +1 -1
- package/dist/store/topic/memory.js +4 -5
- package/dist/store/topic/memory.js.map +1 -1
- package/dist/store/topic/objective.d.ts +8 -4
- package/dist/store/topic/objective.d.ts.map +1 -1
- package/dist/store/topic/objective.js +185 -100
- package/dist/store/topic/objective.js.map +1 -1
- package/dist/store/topic/state.d.ts +1 -2
- package/dist/store/topic/state.d.ts.map +1 -1
- package/dist/store/topic/state.js +50 -62
- package/dist/store/topic/state.js.map +1 -1
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +20 -0
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/computer-use.d.ts +9 -1
- package/dist/tools/builtins/computer-use.d.ts.map +1 -1
- package/dist/tools/builtins/computer-use.js.map +1 -1
- package/dist/tools/builtins/content-fingerprint.d.ts +8 -7
- package/dist/tools/builtins/content-fingerprint.d.ts.map +1 -1
- package/dist/tools/builtins/content-fingerprint.js +9 -10
- package/dist/tools/builtins/content-fingerprint.js.map +1 -1
- package/dist/tools/builtins/edit.d.ts +6 -1
- package/dist/tools/builtins/edit.d.ts.map +1 -1
- package/dist/tools/builtins/edit.js +166 -27
- package/dist/tools/builtins/edit.js.map +1 -1
- package/dist/tools/builtins/write-file.d.ts.map +1 -1
- package/dist/tools/builtins/write-file.js +45 -19
- package/dist/tools/builtins/write-file.js.map +1 -1
- package/dist/tools/command-arguments.d.ts +43 -0
- package/dist/tools/command-arguments.d.ts.map +1 -0
- package/dist/tools/command-arguments.js +52 -0
- package/dist/tools/command-arguments.js.map +1 -0
- package/dist/tools/coordinator/index.d.ts +2 -0
- package/dist/tools/coordinator/index.d.ts.map +1 -1
- package/dist/tools/coordinator/index.js +3 -1
- package/dist/tools/coordinator/index.js.map +1 -1
- package/dist/tools/defineTool.d.ts +10 -0
- package/dist/tools/defineTool.d.ts.map +1 -1
- package/dist/tools/defineTool.js +1 -0
- package/dist/tools/defineTool.js.map +1 -1
- package/dist/tools/env-scrub.d.ts +7 -5
- package/dist/tools/env-scrub.d.ts.map +1 -1
- package/dist/tools/env-scrub.js +7 -5
- package/dist/tools/env-scrub.js.map +1 -1
- package/dist/tools/goal/index.d.ts +20 -0
- package/dist/tools/goal/index.d.ts.map +1 -0
- package/dist/tools/goal/index.js +104 -0
- package/dist/tools/goal/index.js.map +1 -0
- package/dist/tools/memory/index.d.ts +16 -0
- package/dist/tools/memory/index.d.ts.map +1 -1
- package/dist/tools/memory/index.js +6 -2
- package/dist/tools/memory/index.js.map +1 -1
- package/dist/tools/memory/search.d.ts +4 -1
- package/dist/tools/memory/search.d.ts.map +1 -1
- package/dist/tools/memory/search.js +10 -2
- package/dist/tools/memory/search.js.map +1 -1
- package/dist/types/agent/base.d.ts +11 -3
- package/dist/types/agent/base.d.ts.map +1 -1
- package/dist/types/agent/factory.d.ts +2 -0
- package/dist/types/agent/factory.d.ts.map +1 -1
- package/dist/types/agent/reactive.d.ts +2 -0
- package/dist/types/agent/reactive.d.ts.map +1 -1
- package/dist/types/agent/supervisor.d.ts +6 -0
- package/dist/types/agent/supervisor.d.ts.map +1 -1
- package/dist/types/agent/task.d.ts +6 -2
- package/dist/types/agent/task.d.ts.map +1 -1
- package/dist/types/connector/core.d.ts +13 -8
- package/dist/types/connector/core.d.ts.map +1 -1
- package/dist/types/connector/definition.d.ts +37 -18
- package/dist/types/connector/definition.d.ts.map +1 -1
- package/dist/types/connector/http.d.ts +6 -0
- package/dist/types/connector/http.d.ts.map +1 -1
- package/dist/types/connector/mcp.d.ts +24 -6
- package/dist/types/connector/mcp.d.ts.map +1 -1
- package/dist/types/connector/tenant.d.ts +17 -7
- package/dist/types/connector/tenant.d.ts.map +1 -1
- package/dist/types/connector/webhook.d.ts +6 -0
- package/dist/types/connector/webhook.d.ts.map +1 -1
- package/dist/types/goal/index.d.ts +46 -0
- package/dist/types/goal/index.d.ts.map +1 -0
- package/dist/types/goal/index.js +2 -0
- package/dist/types/goal/index.js.map +1 -0
- package/dist/types/ids/index.d.ts +2 -0
- package/dist/types/ids/index.d.ts.map +1 -1
- package/dist/types/ids/index.js.map +1 -1
- package/dist/types/message/index.d.ts +75 -10
- package/dist/types/message/index.d.ts.map +1 -1
- package/dist/types/message/index.js +49 -3
- package/dist/types/message/index.js.map +1 -1
- package/dist/types/plugin/index.d.ts +7 -5
- package/dist/types/plugin/index.d.ts.map +1 -1
- package/dist/types/plugin/index.js.map +1 -1
- package/dist/types/provider/chat.d.ts +27 -4
- package/dist/types/provider/chat.d.ts.map +1 -1
- package/dist/types/provider/interface.d.ts +18 -7
- package/dist/types/provider/interface.d.ts.map +1 -1
- package/dist/types/provider/stream.d.ts +6 -0
- package/dist/types/provider/stream.d.ts.map +1 -1
- package/dist/types/rag/embedding.d.ts +15 -2
- package/dist/types/rag/embedding.d.ts.map +1 -1
- package/dist/types/rag/ingestion.d.ts +2 -2
- package/dist/types/rag/ingestion.d.ts.map +1 -1
- package/dist/types/rag/knowledge-base.d.ts +3 -3
- package/dist/types/rag/knowledge-base.d.ts.map +1 -1
- package/dist/types/rag/retrieval.d.ts +2 -2
- package/dist/types/rag/retrieval.d.ts.map +1 -1
- package/dist/types/rag/scope.d.ts +4 -0
- package/dist/types/rag/scope.d.ts.map +1 -1
- package/dist/types/rag/vector.d.ts +5 -2
- package/dist/types/rag/vector.d.ts.map +1 -1
- package/dist/types/run/config.d.ts +20 -0
- package/dist/types/run/config.d.ts.map +1 -1
- package/dist/types/run/events.d.ts +25 -1
- package/dist/types/run/events.d.ts.map +1 -1
- package/dist/types/run/events.js.map +1 -1
- package/dist/types/run/metadata.d.ts +2 -0
- package/dist/types/run/metadata.d.ts.map +1 -1
- package/dist/types/run/step.d.ts +2 -6
- package/dist/types/run/step.d.ts.map +1 -1
- package/dist/types/run/step.js.map +1 -1
- package/dist/types/run/store.d.ts +55 -2
- package/dist/types/run/store.d.ts.map +1 -1
- package/dist/types/sandbox/index.d.ts +47 -6
- package/dist/types/sandbox/index.d.ts.map +1 -1
- package/dist/types/sandbox/index.js +23 -10
- package/dist/types/sandbox/index.js.map +1 -1
- package/dist/types/session/store.d.ts +13 -0
- package/dist/types/session/store.d.ts.map +1 -1
- package/dist/types/tool/index.d.ts +33 -11
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/dist/types/topic/entity.d.ts +3 -4
- package/dist/types/topic/entity.d.ts.map +1 -1
- package/dist/types/topic/store.d.ts +3 -3
- package/dist/utils/id.d.ts +3 -1
- package/dist/utils/id.d.ts.map +1 -1
- package/dist/utils/id.js +4 -0
- package/dist/utils/id.js.map +1 -1
- package/dist/utils/process-environment.d.ts +26 -0
- package/dist/utils/process-environment.d.ts.map +1 -0
- package/dist/utils/process-environment.js +78 -0
- package/dist/utils/process-environment.js.map +1 -0
- package/dist/vault/InMemoryCredentialVault.d.ts +2 -0
- package/dist/vault/InMemoryCredentialVault.d.ts.map +1 -1
- package/dist/vault/InMemoryCredentialVault.js +24 -4
- package/dist/vault/InMemoryCredentialVault.js.map +1 -1
- package/dist/vault/instrumentation.d.ts.map +1 -1
- package/dist/vault/instrumentation.js +15 -0
- package/dist/vault/instrumentation.js.map +1 -1
- package/package.json +1 -1
- package/src/advisory/executor.ts +4 -1
- package/src/agents/ReactiveAgent.ts +12 -0
- package/src/agents/RouterAgent.ts +25 -3
- package/src/agents/SupervisorAgent.ts +33 -11
- package/src/agents/runAgent.ts +38 -2
- package/src/authorization/command-line.ts +390 -0
- package/src/authorization/rules.ts +22 -1
- package/src/bridge/a2a/client.ts +384 -97
- package/src/bridge/a2a/mapper.ts +5 -0
- package/src/bridge/acp/server.ts +184 -42
- package/src/bridge/mcp/connector/adapter.ts +28 -20
- package/src/bridge/sse/mapper.ts +3 -0
- package/src/compaction/dangling.ts +203 -38
- package/src/compaction/index.ts +9 -2
- package/src/compaction/manual.ts +125 -18
- package/src/compaction/plan.ts +42 -11
- package/src/compaction/retention.ts +23 -8
- package/src/compaction/summary.ts +4 -4
- package/src/compaction/verifier.ts +66 -0
- package/src/connector/BaseConnector.ts +19 -4
- package/src/connector/builtins/http.ts +236 -46
- package/src/connector/builtins/webhook.ts +207 -47
- package/src/connector/execution-contract.ts +27 -0
- package/src/connector/http-operation.ts +238 -0
- package/src/connector/mcp/adapter.ts +8 -3
- package/src/connector/mcp/client.ts +207 -58
- package/src/connector/mcp/http-sse.ts +91 -23
- package/src/connector/mcp/prompt-adapter.ts +8 -2
- package/src/connector/mcp/stdio.ts +21 -46
- package/src/connector/mcp/streamable-http.ts +86 -22
- package/src/connector/tools/adapter.ts +23 -14
- package/src/connector/tools/definitions.ts +5 -2
- package/src/connector/tools/result.ts +21 -0
- package/src/connector/web/guarded-fetch.ts +188 -48
- package/src/constants/sandbox/index.ts +3 -2
- package/src/contracts/api.ts +2 -0
- package/src/contracts/schemas.ts +7 -0
- package/src/directory/derive-supervisor.ts +8 -0
- package/src/directory/derive.ts +8 -0
- package/src/directory/load.ts +2 -0
- package/src/directory/types.ts +4 -0
- package/src/eval/experiment.ts +160 -111
- package/src/eval/judge.ts +13 -2
- package/src/eval/types.ts +7 -1
- package/src/manager/agent/lifecycle.ts +28 -12
- package/src/manager/connector/environment.ts +3 -1
- package/src/manager/connector/lifecycle.ts +364 -24
- package/src/manager/connector/tenant.ts +56 -23
- package/src/manager/goal/activation.ts +52 -0
- package/src/manager/index.ts +10 -2
- package/src/manager/run/persistence.ts +6 -1
- package/src/manager/topic/dependency.ts +39 -0
- package/src/manager/topic/lifecycle.ts +19 -31
- package/src/plugin/index.ts +1 -0
- package/src/plugin/lifecycle.ts +180 -39
- package/src/plugin/loader.ts +70 -13
- package/src/provider/collect-chat-completion.ts +3 -0
- package/src/provider/fallback.ts +79 -11
- package/src/provider/idle-timeout.ts +143 -17
- package/src/provider/index.ts +2 -0
- package/src/provider/instrumentation.ts +1 -0
- package/src/provider/retry.ts +16 -1
- package/src/public-runtime.ts +190 -32
- package/src/public-tools.ts +5 -0
- package/src/public-types.ts +85 -11
- package/src/rag/embedding.ts +147 -19
- package/src/rag/index.ts +1 -1
- package/src/rag/ingestion.ts +16 -2
- package/src/rag/knowledge-base.ts +13 -4
- package/src/rag/operation.ts +28 -0
- package/src/rag/rag-tool.ts +6 -3
- package/src/rag/retriever.ts +62 -11
- package/src/rag/vector-store.ts +8 -2
- package/src/registry/command/kernel-commands.ts +223 -4
- package/src/run/reporter.ts +10 -0
- package/src/run-query/index.ts +84 -15
- package/src/runtime/query/context.ts +13 -3
- package/src/runtime/query/executor.ts +90 -17
- package/src/runtime/query/guard.ts +12 -0
- package/src/runtime/query/index.ts +652 -103
- package/src/runtime/query/iteration/index.ts +89 -13
- package/src/runtime/query/iteration/phases/compaction.ts +120 -55
- package/src/runtime/query/iteration/phases/context.ts +4 -0
- package/src/runtime/query/iteration/phases/tool-review.ts +28 -0
- package/src/runtime/query/iteration/stream-turn.ts +3 -0
- package/src/runtime/query/project-instructions.ts +212 -0
- package/src/runtime/query/request-rich-content.ts +153 -0
- package/src/runtime/query/result.ts +12 -1
- package/src/runtime/query/resume-pending.ts +20 -18
- package/src/runtime/query/resume-run.ts +52 -8
- package/src/runtime/query/run-state.ts +11 -1
- package/src/runtime/query/sandbox-lifecycle.ts +210 -0
- package/src/sandbox/isolation.ts +9 -0
- package/src/sandbox/provider/local.ts +255 -90
- package/src/sandbox/terminal.ts +13 -5
- package/src/session/errors.ts +68 -42
- package/src/session/handoff/broadcast.ts +20 -14
- package/src/session/handoff/single.ts +14 -13
- package/src/store/attachment/index.ts +65 -3
- package/src/store/feedback/conformance.ts +39 -0
- package/src/store/feedback/disk.ts +128 -82
- package/src/store/goal/index.ts +594 -0
- package/src/store/index.ts +1 -1
- package/src/store/kv/revision-record-store.ts +346 -0
- package/src/store/memory/disk.ts +288 -113
- package/src/store/run/disk.ts +96 -5
- package/src/store/run/memory.ts +22 -2
- package/src/store/session/disk.ts +93 -6
- package/src/store/session/memory.ts +22 -0
- package/src/store/topic/memory.ts +4 -5
- package/src/store/topic/objective.ts +215 -100
- package/src/store/topic/state.ts +100 -63
- package/src/tools/builtins/bash.ts +21 -0
- package/src/tools/builtins/computer-use.ts +9 -1
- package/src/tools/builtins/content-fingerprint.ts +9 -12
- package/src/tools/builtins/edit.ts +190 -27
- package/src/tools/builtins/write-file.ts +55 -19
- package/src/tools/command-arguments.ts +54 -0
- package/src/tools/coordinator/index.ts +4 -1
- package/src/tools/defineTool.ts +11 -0
- package/src/tools/env-scrub.ts +7 -5
- package/src/tools/goal/index.ts +129 -0
- package/src/tools/memory/index.ts +26 -3
- package/src/tools/memory/search.ts +20 -3
- package/src/types/agent/base.ts +12 -3
- package/src/types/agent/factory.ts +2 -0
- package/src/types/agent/reactive.ts +2 -0
- package/src/types/agent/supervisor.ts +6 -0
- package/src/types/agent/task.ts +6 -2
- package/src/types/connector/core.ts +13 -8
- package/src/types/connector/definition.ts +54 -20
- package/src/types/connector/http.ts +7 -0
- package/src/types/connector/mcp.ts +27 -6
- package/src/types/connector/tenant.ts +21 -7
- package/src/types/connector/webhook.ts +7 -0
- package/src/types/goal/index.ts +50 -0
- package/src/types/ids/index.ts +2 -0
- package/src/types/message/index.ts +143 -9
- package/src/types/plugin/index.ts +7 -5
- package/src/types/provider/chat.ts +35 -4
- package/src/types/provider/interface.ts +22 -7
- package/src/types/provider/stream.ts +6 -0
- package/src/types/rag/embedding.ts +16 -2
- package/src/types/rag/ingestion.ts +2 -1
- package/src/types/rag/knowledge-base.ts +7 -3
- package/src/types/rag/retrieval.ts +2 -1
- package/src/types/rag/scope.ts +5 -0
- package/src/types/rag/vector.ts +5 -2
- package/src/types/run/config.ts +20 -0
- package/src/types/run/events.ts +28 -3
- package/src/types/run/metadata.ts +2 -0
- package/src/types/run/step.ts +2 -7
- package/src/types/run/store.ts +60 -2
- package/src/types/sandbox/index.ts +57 -14
- package/src/types/session/store.ts +18 -0
- package/src/types/tool/index.ts +33 -11
- package/src/types/topic/entity.ts +3 -4
- package/src/types/topic/store.ts +3 -3
- package/src/utils/id.ts +6 -0
- package/src/utils/process-environment.ts +101 -0
- package/src/vault/InMemoryCredentialVault.ts +29 -4
- package/src/vault/instrumentation.ts +24 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EMPTY_TOKEN_USAGE } from '../constants/limits.js'
|
|
2
2
|
import { collectChatCompletion } from '../provider/collect-chat-completion.js'
|
|
3
|
+
import { resolveStreamIdleTimeoutMs, withStreamIdleTimeout } from '../provider/idle-timeout.js'
|
|
3
4
|
import { FallbackResolver } from '../runtime/decision/fallback.js'
|
|
4
5
|
import { DecisionParser } from '../runtime/decision/parser.js'
|
|
5
6
|
import type {
|
|
@@ -61,13 +62,19 @@ export class RouterAgent extends AbstractAgent<RouterAgentConfig, RouterAgentRes
|
|
|
61
62
|
config: RouterAgentConfig,
|
|
62
63
|
listener?: RunEventListener,
|
|
63
64
|
): Promise<RouterAgentResult> {
|
|
65
|
+
// Resolve before a run id/event exists, matching query(): malformed
|
|
66
|
+
// liveness policy is a caller config error, not a failed model run.
|
|
67
|
+
const streamIdleTimeoutMs = resolveStreamIdleTimeoutMs(config.streamIdleTimeoutMs)
|
|
68
|
+
const signal = input.signal
|
|
69
|
+
? AbortSignal.any([input.signal, this.abortController.signal])
|
|
70
|
+
: this.abortController.signal
|
|
64
71
|
const startTime = Date.now()
|
|
65
72
|
const runId = this.createRunId()
|
|
66
73
|
this.bindRun(runId, config.logger)
|
|
67
74
|
|
|
68
75
|
await this.emitEvent({ type: 'run_started', runId }, listener)
|
|
69
76
|
|
|
70
|
-
const decision = await this.route(input, config)
|
|
77
|
+
const decision = await this.route(input, config, streamIdleTimeoutMs, signal)
|
|
71
78
|
|
|
72
79
|
let targetRoute = config.routes.find((r) => r.agentId === decision.agentId)
|
|
73
80
|
|
|
@@ -149,7 +156,12 @@ export class RouterAgent extends AbstractAgent<RouterAgentConfig, RouterAgentRes
|
|
|
149
156
|
}
|
|
150
157
|
}
|
|
151
158
|
|
|
152
|
-
private async route(
|
|
159
|
+
private async route(
|
|
160
|
+
input: AgentInput,
|
|
161
|
+
config: RouterAgentConfig,
|
|
162
|
+
streamIdleTimeoutMs: number,
|
|
163
|
+
signal: AbortSignal,
|
|
164
|
+
): Promise<RoutingDecision> {
|
|
153
165
|
// `this.log`, not a fresh `getRootLogger()` child — bound by `bindRun` in
|
|
154
166
|
// `runExclusive` before this is called, so a routing warning below
|
|
155
167
|
// carries the SAME `namzu.run.id` as the run it is routing. The old
|
|
@@ -209,15 +221,20 @@ export class RouterAgent extends AbstractAgent<RouterAgentConfig, RouterAgentRes
|
|
|
209
221
|
// Every routing attempt is a billed model call; a fallback after
|
|
210
222
|
// three failed parses still cost three calls.
|
|
211
223
|
let routingUsage: TokenUsage = { ...EMPTY_TOKEN_USAGE }
|
|
224
|
+
const routingProvider = withStreamIdleTimeout(config.provider, {
|
|
225
|
+
idleTimeoutMs: streamIdleTimeoutMs,
|
|
226
|
+
log,
|
|
227
|
+
})
|
|
212
228
|
|
|
213
229
|
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
214
230
|
try {
|
|
215
231
|
const response = await collectChatCompletion(
|
|
216
|
-
|
|
232
|
+
routingProvider.chatStream({
|
|
217
233
|
model: config.model,
|
|
218
234
|
messages: [createSystemMessage(prompt), createUserMessage(userContent)],
|
|
219
235
|
temperature: 0,
|
|
220
236
|
maxTokens: 200,
|
|
237
|
+
signal,
|
|
221
238
|
}),
|
|
222
239
|
)
|
|
223
240
|
|
|
@@ -265,6 +282,11 @@ export class RouterAgent extends AbstractAgent<RouterAgentConfig, RouterAgentRes
|
|
|
265
282
|
}
|
|
266
283
|
}
|
|
267
284
|
} catch (err) {
|
|
285
|
+
// Provider-idle expiry aborts only the wrapper's private transport
|
|
286
|
+
// and is eligible for the router's declared fallback. A caller or
|
|
287
|
+
// agent cancellation owns this fused signal and must not be
|
|
288
|
+
// reinterpreted as permission to start a delegate.
|
|
289
|
+
if (signal.aborted) throw signal.reason
|
|
268
290
|
log.warn('Routing LLM call failed', {
|
|
269
291
|
'namzu.router.attempt': attempt + 1,
|
|
270
292
|
'exception.message': String(err),
|
|
@@ -4,7 +4,7 @@ import { drainQuery } from '../runtime/query/index.js'
|
|
|
4
4
|
import { PendingAnswers, QuestionParkBinding } from '../runtime/query/question-park.js'
|
|
5
5
|
import { CompletionInbox } from '../scheduler/completion-inbox.js'
|
|
6
6
|
import { LocalTaskScheduler } from '../scheduler/local.js'
|
|
7
|
-
import { buildCoordinatorTools } from '../tools/coordinator/index.js'
|
|
7
|
+
import { ASK_USER_QUESTION_TOOL_NAME, buildCoordinatorTools } from '../tools/coordinator/index.js'
|
|
8
8
|
import type {
|
|
9
9
|
AgentInput,
|
|
10
10
|
AgentMetadata,
|
|
@@ -151,17 +151,19 @@ export class SupervisorAgent extends AbstractAgent<SupervisorAgentConfig, Superv
|
|
|
151
151
|
parentRunId: runId,
|
|
152
152
|
parentAgentId: this.metadata.id,
|
|
153
153
|
parentAbortController: this.abortController,
|
|
154
|
-
|
|
154
|
+
// This context describes the CURRENT supervisor. AgentManager owns
|
|
155
|
+
// the increment when it constructs the child. Resetting a delegated
|
|
156
|
+
// supervisor to zero here made every grandchild depth one again.
|
|
157
|
+
depth: config.depth ?? 0,
|
|
155
158
|
budgetTracker: {
|
|
156
159
|
total: config.tokenBudget,
|
|
157
160
|
remaining: config.tokenBudget,
|
|
158
161
|
},
|
|
159
162
|
factoryOptions: mergedFactoryOptions,
|
|
160
|
-
// The supervisor already hands this to its OWN run
|
|
161
|
-
//
|
|
162
|
-
//
|
|
163
|
-
// Without
|
|
164
|
-
// human and the workers it launched approved themselves.
|
|
163
|
+
// The supervisor already hands this to its OWN run. Handing it to
|
|
164
|
+
// the spawn context makes a worker's REVIEW-tier calls reach the
|
|
165
|
+
// same person. It does not grant the root-only question tool.
|
|
166
|
+
// Without the handler, workers silently auto-approved themselves.
|
|
165
167
|
...(config.resumeHandler ? { resumeHandler: config.resumeHandler } : {}),
|
|
166
168
|
tenantId,
|
|
167
169
|
topicId,
|
|
@@ -210,6 +212,7 @@ export class SupervisorAgent extends AbstractAgent<SupervisorAgentConfig, Superv
|
|
|
210
212
|
// runs again — which is how a leak of one listener per run becomes a leak
|
|
211
213
|
// of one per ATTEMPT.
|
|
212
214
|
try {
|
|
215
|
+
const isRootAgent = (config.depth ?? 0) === 0
|
|
213
216
|
const coordinatorToolDefs = buildCoordinatorTools({
|
|
214
217
|
gateway,
|
|
215
218
|
completionInbox,
|
|
@@ -224,10 +227,11 @@ export class SupervisorAgent extends AbstractAgent<SupervisorAgentConfig, Superv
|
|
|
224
227
|
taskStore: input.taskStore,
|
|
225
228
|
runId,
|
|
226
229
|
getPlanManager: () => planManagerRef,
|
|
227
|
-
//
|
|
228
|
-
//
|
|
229
|
-
//
|
|
230
|
-
|
|
230
|
+
// A human-question tool belongs only to the root agent. The handler
|
|
231
|
+
// itself still reaches `drainQuery` below: delegated REVIEW-tier
|
|
232
|
+
// tool calls must keep asking the operator instead of falling back
|
|
233
|
+
// to unattended auto-approval.
|
|
234
|
+
...(isRootAgent && config.resumeHandler ? { resumeHandler: config.resumeHandler } : {}),
|
|
231
235
|
questionParks,
|
|
232
236
|
pendingAnswers,
|
|
233
237
|
...(config.onPlanApproved ? { onPlanApproved: config.onPlanApproved } : {}),
|
|
@@ -236,6 +240,10 @@ export class SupervisorAgent extends AbstractAgent<SupervisorAgentConfig, Superv
|
|
|
236
240
|
const tools = new ToolRegistry()
|
|
237
241
|
if (config.tools) {
|
|
238
242
|
for (const tool of config.tools.getAll()) {
|
|
243
|
+
// The boundary is semantic, not an implementation detail of the
|
|
244
|
+
// built-in builder. A host registry containing the same capability
|
|
245
|
+
// must not reopen it for a delegated agent.
|
|
246
|
+
if (!isRootAgent && tool.name === ASK_USER_QUESTION_TOOL_NAME) continue
|
|
239
247
|
tools.register(tool, config.tools.getAvailability(tool.name))
|
|
240
248
|
}
|
|
241
249
|
}
|
|
@@ -307,6 +315,14 @@ export class SupervisorAgent extends AbstractAgent<SupervisorAgentConfig, Superv
|
|
|
307
315
|
model: config.model,
|
|
308
316
|
tokenBudget: config.tokenBudget,
|
|
309
317
|
timeoutMs: config.timeoutMs,
|
|
318
|
+
...(config.streamIdleTimeoutMs !== undefined
|
|
319
|
+
? { streamIdleTimeoutMs: config.streamIdleTimeoutMs }
|
|
320
|
+
: {}),
|
|
321
|
+
...(config.maxRequestRichContentBytes !== undefined
|
|
322
|
+
? {
|
|
323
|
+
maxRequestRichContentBytes: config.maxRequestRichContentBytes,
|
|
324
|
+
}
|
|
325
|
+
: {}),
|
|
310
326
|
maxIterations: config.maxIterations,
|
|
311
327
|
temperature: config.temperature,
|
|
312
328
|
env: config.env,
|
|
@@ -359,6 +375,9 @@ export class SupervisorAgent extends AbstractAgent<SupervisorAgentConfig, Superv
|
|
|
359
375
|
// corrected for twice.
|
|
360
376
|
...(config.steering ? { steering: config.steering } : {}),
|
|
361
377
|
...(config.inboundMessages ? { inboundMessages: config.inboundMessages } : {}),
|
|
378
|
+
...(config.projectInstructionContext
|
|
379
|
+
? { projectInstructionContext: config.projectInstructionContext }
|
|
380
|
+
: {}),
|
|
362
381
|
...(config.authorizationGate ? { authorizationGate: config.authorizationGate } : {}),
|
|
363
382
|
// The one hop between the config and the tool. `drainQuery`
|
|
364
383
|
// registers `structured_output` from this and the loop
|
|
@@ -366,6 +385,9 @@ export class SupervisorAgent extends AbstractAgent<SupervisorAgentConfig, Superv
|
|
|
366
385
|
// came from — only `ReactiveAgent` was passing it.
|
|
367
386
|
...(config.structuredOutput ? { structuredOutput: config.structuredOutput } : {}),
|
|
368
387
|
...(config.sandboxProvider ? { sandboxProvider: config.sandboxProvider } : {}),
|
|
388
|
+
...(config.sandboxTeardownTimeoutMs !== undefined
|
|
389
|
+
? { sandboxTeardownTimeoutMs: config.sandboxTeardownTimeoutMs }
|
|
390
|
+
: {}),
|
|
369
391
|
// Working-memory / compaction seam (optional; absent => unchanged
|
|
370
392
|
// run path, byte-identical for every existing consumer).
|
|
371
393
|
...(config.compactionConfig ? { compactionConfig: config.compactionConfig } : {}),
|
package/src/agents/runAgent.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { ToolRegistry } from '../registry/tool/execute.js'
|
|
2
2
|
import { drainQuery } from '../runtime/query/index.js'
|
|
3
|
+
import type { ProjectInstructionContext } from '../runtime/query/project-instructions.js'
|
|
3
4
|
import type { AuthorizationGateConfig } from '../types/authorization/index.js'
|
|
4
5
|
import type { ProjectId, SessionId, TenantId, TopicId } from '../types/ids/index.js'
|
|
5
6
|
import type { Message } from '../types/message/index.js'
|
|
6
7
|
import type { LLMProvider, ReasoningEffort, ThinkingConfig } from '../types/provider/index.js'
|
|
7
8
|
import type { Run, RunEventListener } from '../types/run/index.js'
|
|
9
|
+
import type { SandboxProvider } from '../types/sandbox/index.js'
|
|
8
10
|
import type { Skill } from '../types/skills/index.js'
|
|
9
11
|
import type { StructuredOutputConfig } from '../types/structured-output/index.js'
|
|
10
12
|
import type { ToolRegistryContract } from '../types/tool/index.js'
|
|
@@ -62,6 +64,10 @@ export interface RunAgentOptions extends AgentIdentity {
|
|
|
62
64
|
model: string
|
|
63
65
|
|
|
64
66
|
tools?: ToolRegistryContract
|
|
67
|
+
/** Execute sandbox-aware tools inside this provider's boundary. */
|
|
68
|
+
sandboxProvider?: SandboxProvider
|
|
69
|
+
/** Sandbox teardown wait; defaults to 30 seconds and `0` is unbounded. */
|
|
70
|
+
sandboxTeardownTimeoutMs?: number
|
|
65
71
|
|
|
66
72
|
/**
|
|
67
73
|
* Skills to put in front of the model.
|
|
@@ -97,6 +103,10 @@ export interface RunAgentOptions extends AgentIdentity {
|
|
|
97
103
|
maxIterations?: number
|
|
98
104
|
tokenBudget?: number
|
|
99
105
|
timeoutMs?: number
|
|
106
|
+
/** Maximum provider-stream silence; defaults to five minutes. `0` disables. */
|
|
107
|
+
streamIdleTimeoutMs?: number
|
|
108
|
+
/** Accumulated inline image/document bytes per provider request. `0` disables. */
|
|
109
|
+
maxRequestRichContentBytes?: number
|
|
100
110
|
temperature?: number
|
|
101
111
|
|
|
102
112
|
/**
|
|
@@ -134,6 +144,8 @@ export interface RunAgentOptions extends AgentIdentity {
|
|
|
134
144
|
|
|
135
145
|
signal?: AbortSignal
|
|
136
146
|
listener?: RunEventListener
|
|
147
|
+
/** Live project policy for hosts that discover nested instruction scopes. */
|
|
148
|
+
projectInstructionContext?: ProjectInstructionContext
|
|
137
149
|
}
|
|
138
150
|
|
|
139
151
|
export interface RunAgentResult {
|
|
@@ -225,13 +237,23 @@ export async function runAgent(options: RunAgentOptions): Promise<RunAgentResult
|
|
|
225
237
|
|
|
226
238
|
const messages: Message[] =
|
|
227
239
|
typeof options.prompt === 'string'
|
|
228
|
-
? [
|
|
240
|
+
? [
|
|
241
|
+
{
|
|
242
|
+
role: 'user',
|
|
243
|
+
content: options.prompt,
|
|
244
|
+
timestamp: Date.now(),
|
|
245
|
+
} as Message,
|
|
246
|
+
]
|
|
229
247
|
: options.prompt
|
|
230
248
|
|
|
231
249
|
const run = await drainQuery(
|
|
232
250
|
{
|
|
233
251
|
provider: options.provider,
|
|
234
252
|
tools: options.tools ?? new ToolRegistry(),
|
|
253
|
+
...(options.sandboxProvider ? { sandboxProvider: options.sandboxProvider } : {}),
|
|
254
|
+
...(options.sandboxTeardownTimeoutMs !== undefined
|
|
255
|
+
? { sandboxTeardownTimeoutMs: options.sandboxTeardownTimeoutMs }
|
|
256
|
+
: {}),
|
|
235
257
|
messages,
|
|
236
258
|
workingDirectory: options.workingDirectory ?? process.cwd(),
|
|
237
259
|
runConfig: {
|
|
@@ -239,6 +261,12 @@ export async function runAgent(options: RunAgentOptions): Promise<RunAgentResult
|
|
|
239
261
|
maxIterations: options.maxIterations ?? DEFAULT_MAX_ITERATIONS,
|
|
240
262
|
tokenBudget: options.tokenBudget ?? DEFAULT_TOKEN_BUDGET,
|
|
241
263
|
timeoutMs: options.timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
264
|
+
...(options.streamIdleTimeoutMs !== undefined
|
|
265
|
+
? { streamIdleTimeoutMs: options.streamIdleTimeoutMs }
|
|
266
|
+
: {}),
|
|
267
|
+
...(options.maxRequestRichContentBytes !== undefined
|
|
268
|
+
? { maxRequestRichContentBytes: options.maxRequestRichContentBytes }
|
|
269
|
+
: {}),
|
|
242
270
|
...(options.temperature !== undefined ? { temperature: options.temperature } : {}),
|
|
243
271
|
...(options.thinking ? { thinking: options.thinking } : {}),
|
|
244
272
|
...(options.effort ? { effort: options.effort } : {}),
|
|
@@ -256,10 +284,18 @@ export async function runAgent(options: RunAgentOptions): Promise<RunAgentResult
|
|
|
256
284
|
...(options.verificationGate ? { verificationGate: options.verificationGate } : {}),
|
|
257
285
|
...(options.authorizationGate ? { authorizationGate: options.authorizationGate } : {}),
|
|
258
286
|
...(options.structuredOutput ? { structuredOutput: options.structuredOutput } : {}),
|
|
287
|
+
...(options.projectInstructionContext
|
|
288
|
+
? { projectInstructionContext: options.projectInstructionContext }
|
|
289
|
+
: {}),
|
|
259
290
|
...identity,
|
|
260
291
|
},
|
|
261
292
|
options.listener,
|
|
262
293
|
)
|
|
263
294
|
|
|
264
|
-
return {
|
|
295
|
+
return {
|
|
296
|
+
output: run.result,
|
|
297
|
+
structuredOutput: run.structuredOutput,
|
|
298
|
+
run,
|
|
299
|
+
identity,
|
|
300
|
+
}
|
|
265
301
|
}
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Break a command line into the commands it actually runs.
|
|
3
|
+
*
|
|
4
|
+
* ## The hole this closes
|
|
5
|
+
*
|
|
6
|
+
* A pattern rule tests a regular expression against an argument's value. When
|
|
7
|
+
* that value is a command line, the value and the command are not the same
|
|
8
|
+
* thing: `git push origin main` is one command, and
|
|
9
|
+
* `true; git push origin main` is two, of which the second is the one the rule
|
|
10
|
+
* was written about. An anchored pattern sees only the first.
|
|
11
|
+
*
|
|
12
|
+
* Measured against the gate, with the rule from this repository's own
|
|
13
|
+
* documentation (`^git push`, deny):
|
|
14
|
+
*
|
|
15
|
+
* git push origin main -> deny
|
|
16
|
+
* echo hi && git push origin main -> did not match
|
|
17
|
+
* true; git push origin main -> did not match
|
|
18
|
+
* bash -c "git push origin main" -> did not match
|
|
19
|
+
*
|
|
20
|
+
* A rule that fails to match reaches the permission mode, and a run with no
|
|
21
|
+
* terminal resolves that to `auto`. So an operator's prohibition was bypassed
|
|
22
|
+
* by typing four characters in front of it, in exactly the unattended case the
|
|
23
|
+
* prohibition exists for. The `bash` tool's own description tells the model to
|
|
24
|
+
* "use `&&` / `;` chaining for compound commands", so the evading form is not
|
|
25
|
+
* an exotic input — it is the documented one.
|
|
26
|
+
*
|
|
27
|
+
* ## Why splitting alone would make things worse
|
|
28
|
+
*
|
|
29
|
+
* Applied naively this widens `allow` in the same motion it fixes `deny`. An
|
|
30
|
+
* allow rule matching `^git status` would go on matching the first segment of
|
|
31
|
+
* `git status && rm -rf ~` and hand back `allow` for the whole line. So the
|
|
32
|
+
* caller must read the two decisions differently, and {@link evaluateRule}
|
|
33
|
+
* does:
|
|
34
|
+
*
|
|
35
|
+
* - **deny** matches when ANY segment matches. One prohibited command poisons
|
|
36
|
+
* the line it rides on.
|
|
37
|
+
* - **allow** matches only when EVERY segment matches, and never when the line
|
|
38
|
+
* is {@link CommandLineDecomposition.opaque}. Permission is a claim about the
|
|
39
|
+
* whole line, and a claim that cannot be checked is not granted.
|
|
40
|
+
*
|
|
41
|
+
* That asymmetry is the same one `refuse-do-not-degrade` describes: when the
|
|
42
|
+
* analysis is uncertain, the uncertainty spends against the permissive answer.
|
|
43
|
+
*
|
|
44
|
+
* ## What `opaque` means
|
|
45
|
+
*
|
|
46
|
+
* Some lines contain text that is not the command that runs. Command
|
|
47
|
+
* substitution (`$(…)`, backticks, `<(…)`) executes something whose text is
|
|
48
|
+
* not in the line at all, and `eval` runs a string assembled at runtime. No
|
|
49
|
+
* decomposition of the source can be a decomposition of what ran, so the line
|
|
50
|
+
* is marked opaque and `allow` declines it. `deny` still tests what is visible,
|
|
51
|
+
* because a deny that matches too much costs a prompt and a deny that matches
|
|
52
|
+
* too little costs the thing it was written to prevent.
|
|
53
|
+
*
|
|
54
|
+
* ## What it deliberately does not do
|
|
55
|
+
*
|
|
56
|
+
* A value with no chain operator, no nested shell and nothing opaque comes back
|
|
57
|
+
* as itself, byte for byte. That keeps every rule about a non-command argument
|
|
58
|
+
* — a path, a number, a URL — behaving exactly as it did, and confines this
|
|
59
|
+
* machinery to the case that motivated it.
|
|
60
|
+
*
|
|
61
|
+
* It is a decomposition, not a shell. `xargs sh -c`, a command read from a
|
|
62
|
+
* file, and a shell invoked through an interpreter it does not recognise all
|
|
63
|
+
* pass through as ordinary text. Each of those either denies as before or, for
|
|
64
|
+
* an allow rule, fails to match every segment and so declines. The failure mode
|
|
65
|
+
* is a prompt, never a silent grant.
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
/** The commands a line runs, and whether that list can be trusted as complete. */
|
|
69
|
+
export interface CommandLineDecomposition {
|
|
70
|
+
/**
|
|
71
|
+
* The individual commands, in source order. Never empty: a line that
|
|
72
|
+
* decomposes to nothing yields the original.
|
|
73
|
+
*/
|
|
74
|
+
readonly segments: readonly string[]
|
|
75
|
+
/**
|
|
76
|
+
* True when the line runs something this decomposition cannot see, so
|
|
77
|
+
* `segments` is a lower bound rather than the whole story.
|
|
78
|
+
*/
|
|
79
|
+
readonly opaque: boolean
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Shells whose `-c` argument is another command line.
|
|
84
|
+
*
|
|
85
|
+
* Matched on the basename, so `/bin/bash` and `bash` are the same entry. An
|
|
86
|
+
* interpreter absent from this list is not a hole that grants anything: its
|
|
87
|
+
* payload stays inside one segment, where an allow rule fails to match it.
|
|
88
|
+
*/
|
|
89
|
+
const NESTED_SHELLS = new Set(['sh', 'bash', 'zsh', 'dash', 'ksh', 'ash', 'busybox'])
|
|
90
|
+
|
|
91
|
+
/** Commands whose argument is code assembled at runtime. */
|
|
92
|
+
const RUNTIME_EVALUATORS = new Set(['eval', 'source', '.'])
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Depth and width limits.
|
|
96
|
+
*
|
|
97
|
+
* A line that exceeds either is reported opaque rather than truncated: a
|
|
98
|
+
* shortened list of segments would read as complete to `allow`, which is the
|
|
99
|
+
* one reading that must never be wrong.
|
|
100
|
+
*/
|
|
101
|
+
const MAX_DEPTH = 4
|
|
102
|
+
const MAX_SEGMENTS = 64
|
|
103
|
+
|
|
104
|
+
export function decomposeCommandLine(command: string): CommandLineDecomposition {
|
|
105
|
+
const state: WalkState = { opaque: false, structured: false }
|
|
106
|
+
const segments = split(command, state, 0)
|
|
107
|
+
|
|
108
|
+
// The untouched-value case, kept exact. Nothing was cut and nothing was
|
|
109
|
+
// unpacked, so there is no decomposition to report and the value goes back
|
|
110
|
+
// as it arrived — which is what keeps a rule about a path or a URL seeing
|
|
111
|
+
// the string it always saw, punctuation and surrounding space included.
|
|
112
|
+
if (!state.structured) return { segments: [command], opaque: state.opaque }
|
|
113
|
+
|
|
114
|
+
if (segments.length === 0) return { segments: [command], opaque: state.opaque }
|
|
115
|
+
if (segments.length > MAX_SEGMENTS) {
|
|
116
|
+
return { segments: segments.slice(0, MAX_SEGMENTS), opaque: true }
|
|
117
|
+
}
|
|
118
|
+
return { segments, opaque: state.opaque }
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
interface WalkState {
|
|
122
|
+
opaque: boolean
|
|
123
|
+
/**
|
|
124
|
+
* Whether anything was cut or unpacked. False means the value is not a
|
|
125
|
+
* command line as far as this module can tell, and it goes back untouched.
|
|
126
|
+
*/
|
|
127
|
+
structured: boolean
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Walk the line once, quote-aware, cutting at every top-level separator.
|
|
132
|
+
*
|
|
133
|
+
* Quote tracking is the whole reason this is not a `String.split`: `echo "a &&
|
|
134
|
+
* b"` is one command that prints a literal, and a splitter that cannot tell
|
|
135
|
+
* would report a second command named `b"` — inventing a segment is as wrong as
|
|
136
|
+
* missing one, because `allow` requires every segment to match.
|
|
137
|
+
*/
|
|
138
|
+
function split(command: string, state: WalkState, depth: number): string[] {
|
|
139
|
+
const segments: string[] = []
|
|
140
|
+
let current = ''
|
|
141
|
+
let quote: "'" | '"' | null = null
|
|
142
|
+
|
|
143
|
+
const cut = (): void => {
|
|
144
|
+
const trimmed = trimSegment(current)
|
|
145
|
+
current = ''
|
|
146
|
+
if (trimmed === '') return
|
|
147
|
+
for (const piece of expand(trimmed, state, depth)) segments.push(piece)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
for (let i = 0; i < command.length; i += 1) {
|
|
151
|
+
const char = command[i] as string
|
|
152
|
+
|
|
153
|
+
if (quote === "'") {
|
|
154
|
+
// Single quotes suspend everything, including the backslash. This is
|
|
155
|
+
// the branch that keeps `echo 'a && b'` one command.
|
|
156
|
+
if (char === "'") quote = null
|
|
157
|
+
current += char
|
|
158
|
+
continue
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (char === '\\') {
|
|
162
|
+
// An escaped separator is a literal, so both characters go through
|
|
163
|
+
// untouched and the next loop never sees the separator as one.
|
|
164
|
+
current += char + (command[i + 1] ?? '')
|
|
165
|
+
i += 1
|
|
166
|
+
continue
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (quote === '"') {
|
|
170
|
+
if (char === '"') quote = null
|
|
171
|
+
// Substitution is live inside double quotes, which is exactly where
|
|
172
|
+
// it hides best.
|
|
173
|
+
else if (isSubstitutionStart(command, i)) state.opaque = true
|
|
174
|
+
current += char
|
|
175
|
+
continue
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (char === "'" || char === '"') {
|
|
179
|
+
quote = char
|
|
180
|
+
current += char
|
|
181
|
+
continue
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (isSubstitutionStart(command, i)) {
|
|
185
|
+
state.opaque = true
|
|
186
|
+
current += char
|
|
187
|
+
continue
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const separator = separatorAt(command, i)
|
|
191
|
+
if (separator > 0) {
|
|
192
|
+
state.structured = true
|
|
193
|
+
cut()
|
|
194
|
+
i += separator - 1
|
|
195
|
+
continue
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
current += char
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// An unterminated quote means the line does not parse. Whatever it runs is
|
|
202
|
+
// not what this walk saw, so the caller must not treat the result as a
|
|
203
|
+
// complete account.
|
|
204
|
+
if (quote !== null) state.opaque = true
|
|
205
|
+
|
|
206
|
+
cut()
|
|
207
|
+
return segments
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Length of the separator starting at `index`, or 0.
|
|
212
|
+
*
|
|
213
|
+
* The redirection cases are why this is a function. `2>&1` and `&>log` contain
|
|
214
|
+
* `&` and are not separators; splitting there would manufacture a segment named
|
|
215
|
+
* `1`, which no allow rule matches, and a command that redirects its output
|
|
216
|
+
* would stop being approvable for a reason nobody could see.
|
|
217
|
+
*/
|
|
218
|
+
function separatorAt(command: string, index: number): number {
|
|
219
|
+
const char = command[index]
|
|
220
|
+
const next = command[index + 1]
|
|
221
|
+
|
|
222
|
+
if (char === '\n') return 1
|
|
223
|
+
if (char === ';') return next === ';' ? 2 : 1
|
|
224
|
+
if (char === '&') {
|
|
225
|
+
if (next === '&') return 2
|
|
226
|
+
if (next === '>') return 0
|
|
227
|
+
if (command[index - 1] === '>') return 0
|
|
228
|
+
return 1
|
|
229
|
+
}
|
|
230
|
+
if (char === '|') {
|
|
231
|
+
if (next === '|') return 2
|
|
232
|
+
// `|&` pipes stderr as well; still a pipe, and both sides still run.
|
|
233
|
+
if (next === '&') return 2
|
|
234
|
+
return 1
|
|
235
|
+
}
|
|
236
|
+
return 0
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** Whether a command substitution opens here. */
|
|
240
|
+
function isSubstitutionStart(command: string, index: number): boolean {
|
|
241
|
+
const char = command[index]
|
|
242
|
+
if (char === '`') return true
|
|
243
|
+
if (char === '$' && command[index + 1] === '(') return true
|
|
244
|
+
// Process substitution: `diff <(a) <(b)` runs `a` and `b`.
|
|
245
|
+
if ((char === '<' || char === '>') && command[index + 1] === '(') return true
|
|
246
|
+
return false
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Strip the grouping punctuation a split leaves behind.
|
|
251
|
+
*
|
|
252
|
+
* `(cd build && make)` cuts into `(cd build` and `make)`. Leaving the bracket on
|
|
253
|
+
* would stop an allow rule matching a command it names, and — worse — stop a
|
|
254
|
+
* deny rule matching one, since `^make` does not match `make)`.
|
|
255
|
+
*/
|
|
256
|
+
function trimSegment(segment: string): string {
|
|
257
|
+
return segment
|
|
258
|
+
.trim()
|
|
259
|
+
.replace(/^[({\s]+/, '')
|
|
260
|
+
.replace(/[)}\s]+$/, '')
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Turn one segment into the commands it stands for.
|
|
265
|
+
*
|
|
266
|
+
* A shell invoked with `-c` carries a whole second command line in an argument,
|
|
267
|
+
* and that argument is where the smuggling this module exists for is easiest:
|
|
268
|
+
* `bash -c "git push"` contains no separator at all, so nothing above this
|
|
269
|
+
* function would have looked inside it.
|
|
270
|
+
*
|
|
271
|
+
* The outer segment is kept alongside the inner ones. A rule that denies the
|
|
272
|
+
* interpreter itself must still fire, and for `allow` the extra segment only
|
|
273
|
+
* makes the requirement stricter — which is the safe direction.
|
|
274
|
+
*/
|
|
275
|
+
function expand(segment: string, state: WalkState, depth: number): string[] {
|
|
276
|
+
const words = tokenize(segment)
|
|
277
|
+
const head = words[0]
|
|
278
|
+
if (head === undefined) return [segment]
|
|
279
|
+
|
|
280
|
+
if (RUNTIME_EVALUATORS.has(basename(head.text))) {
|
|
281
|
+
// The argument is source text assembled elsewhere. Even when it is a
|
|
282
|
+
// visible literal, what runs is decided at runtime.
|
|
283
|
+
state.opaque = true
|
|
284
|
+
return [segment]
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (!NESTED_SHELLS.has(basename(head.text))) return [segment]
|
|
288
|
+
|
|
289
|
+
const flag = words.findIndex(
|
|
290
|
+
(word, index) => index > 0 && word.quoted === null && word.text === '-c',
|
|
291
|
+
)
|
|
292
|
+
if (flag < 0) return [segment]
|
|
293
|
+
|
|
294
|
+
const payload = words[flag + 1]
|
|
295
|
+
if (payload === undefined) {
|
|
296
|
+
// `bash -c` with nothing after it is either a syntax error or an
|
|
297
|
+
// argument this tokenizer failed to read. Neither may be reported as
|
|
298
|
+
// "there is no nested command".
|
|
299
|
+
state.opaque = true
|
|
300
|
+
return [segment]
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (depth + 1 >= MAX_DEPTH) {
|
|
304
|
+
state.opaque = true
|
|
305
|
+
return [segment]
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const nested = split(payload.text, state, depth + 1)
|
|
309
|
+
if (nested.length === 0) return [segment]
|
|
310
|
+
state.structured = true
|
|
311
|
+
return [segment, ...nested]
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
interface Word {
|
|
315
|
+
readonly text: string
|
|
316
|
+
/** The quote that wrapped it, or null when it was bare. */
|
|
317
|
+
readonly quoted: "'" | '"' | null
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Split a segment into words, removing one layer of quoting.
|
|
322
|
+
*
|
|
323
|
+
* The quote is reported rather than discarded because `-c` must be the flag and
|
|
324
|
+
* not a literal: `echo "-c"` names no nested shell, and treating its next word
|
|
325
|
+
* as a command line would decompose a string that never runs.
|
|
326
|
+
*/
|
|
327
|
+
function tokenize(segment: string): Word[] {
|
|
328
|
+
const words: Word[] = []
|
|
329
|
+
let current = ''
|
|
330
|
+
let quote: "'" | '"' | null = null
|
|
331
|
+
let sawQuote: "'" | '"' | null = null
|
|
332
|
+
let open = false
|
|
333
|
+
|
|
334
|
+
const push = (): void => {
|
|
335
|
+
if (open) words.push({ text: current, quoted: sawQuote })
|
|
336
|
+
current = ''
|
|
337
|
+
sawQuote = null
|
|
338
|
+
open = false
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
for (let i = 0; i < segment.length; i += 1) {
|
|
342
|
+
const char = segment[i] as string
|
|
343
|
+
|
|
344
|
+
if (quote === "'") {
|
|
345
|
+
// Single quotes suspend the backslash too, so this branch precedes
|
|
346
|
+
// the escape below rather than sharing it.
|
|
347
|
+
if (char === "'") quote = null
|
|
348
|
+
else current += char
|
|
349
|
+
open = true
|
|
350
|
+
continue
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (char === '\\' && i + 1 < segment.length) {
|
|
354
|
+
current += segment[i + 1]
|
|
355
|
+
i += 1
|
|
356
|
+
open = true
|
|
357
|
+
continue
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if (quote === '"') {
|
|
361
|
+
if (char === '"') quote = null
|
|
362
|
+
else current += char
|
|
363
|
+
open = true
|
|
364
|
+
continue
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
if (char === "'" || char === '"') {
|
|
368
|
+
quote = char
|
|
369
|
+
sawQuote = char
|
|
370
|
+
open = true
|
|
371
|
+
continue
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (char === ' ' || char === '\t') {
|
|
375
|
+
push()
|
|
376
|
+
continue
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
current += char
|
|
380
|
+
open = true
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
push()
|
|
384
|
+
return words
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function basename(word: string): string {
|
|
388
|
+
const cut = word.lastIndexOf('/')
|
|
389
|
+
return cut < 0 ? word : word.slice(cut + 1)
|
|
390
|
+
}
|