@namzu/sdk 46.0.0 → 48.1.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 +351 -8
- package/README.md +7 -8
- package/dist/advisory/history.d.ts.map +1 -1
- package/dist/advisory/history.js +21 -1
- package/dist/advisory/history.js.map +1 -1
- package/dist/advisory/index.d.ts +1 -1
- package/dist/advisory/index.d.ts.map +1 -1
- package/dist/advisory/index.js +1 -1
- package/dist/advisory/index.js.map +1 -1
- package/dist/advisory/registry.d.ts +17 -0
- package/dist/advisory/registry.d.ts.map +1 -1
- package/dist/advisory/registry.js +26 -0
- package/dist/advisory/registry.js.map +1 -1
- package/dist/agents/PipelineAgent.d.ts +2 -46
- package/dist/agents/PipelineAgent.d.ts.map +1 -1
- package/dist/agents/PipelineAgent.js +2 -242
- package/dist/agents/PipelineAgent.js.map +1 -1
- package/dist/agents/QueryAgent.d.ts +21 -0
- package/dist/agents/QueryAgent.d.ts.map +1 -0
- package/dist/agents/QueryAgent.js +214 -0
- package/dist/agents/QueryAgent.js.map +1 -0
- package/dist/agents/ReactiveAgent.d.ts +4 -16
- package/dist/agents/ReactiveAgent.d.ts.map +1 -1
- package/dist/agents/ReactiveAgent.js +4 -183
- package/dist/agents/ReactiveAgent.js.map +1 -1
- package/dist/agents/RouterAgent.d.ts +2 -20
- package/dist/agents/RouterAgent.d.ts.map +1 -1
- package/dist/agents/RouterAgent.js +2 -266
- package/dist/agents/RouterAgent.js.map +1 -1
- package/dist/agents/SupervisorAgent.d.ts +3 -43
- package/dist/agents/SupervisorAgent.d.ts.map +1 -1
- package/dist/agents/SupervisorAgent.js +3 -418
- package/dist/agents/SupervisorAgent.js.map +1 -1
- package/dist/agents/defineAgent.d.ts +2 -1
- package/dist/agents/defineAgent.d.ts.map +1 -1
- package/dist/agents/defineAgent.js +6 -1
- package/dist/agents/defineAgent.js.map +1 -1
- package/dist/agents/examples/PipelineAgent.d.ts +46 -0
- package/dist/agents/examples/PipelineAgent.d.ts.map +1 -0
- package/dist/agents/examples/PipelineAgent.js +242 -0
- package/dist/agents/examples/PipelineAgent.js.map +1 -0
- package/dist/agents/examples/RouterAgent.d.ts +22 -0
- package/dist/agents/examples/RouterAgent.d.ts.map +1 -0
- package/dist/agents/examples/RouterAgent.js +268 -0
- package/dist/agents/examples/RouterAgent.js.map +1 -0
- package/dist/agents/examples/SupervisorAgent.d.ts +45 -0
- package/dist/agents/examples/SupervisorAgent.d.ts.map +1 -0
- package/dist/agents/examples/SupervisorAgent.js +406 -0
- package/dist/agents/examples/SupervisorAgent.js.map +1 -0
- package/dist/agents/explore.d.ts +6 -3
- package/dist/agents/explore.d.ts.map +1 -1
- package/dist/agents/explore.js +6 -3
- package/dist/agents/explore.js.map +1 -1
- package/dist/agents/forward-options.d.ts +11 -0
- package/dist/agents/forward-options.d.ts.map +1 -0
- package/dist/agents/forward-options.js +15 -0
- package/dist/agents/forward-options.js.map +1 -0
- package/dist/agents/index.d.ts +1 -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/agents/runAgent.d.ts +19 -8
- package/dist/agents/runAgent.d.ts.map +1 -1
- package/dist/agents/runAgent.js +99 -29
- package/dist/agents/runAgent.js.map +1 -1
- package/dist/authorization/command-line.d.ts +2 -0
- package/dist/authorization/command-line.d.ts.map +1 -1
- package/dist/authorization/command-line.js +2 -2
- package/dist/authorization/command-line.js.map +1 -1
- package/dist/authorization/gate.d.ts +8 -0
- package/dist/authorization/gate.d.ts.map +1 -1
- package/dist/authorization/gate.js +12 -1
- package/dist/authorization/gate.js.map +1 -1
- package/dist/authorization/program.d.ts +151 -0
- package/dist/authorization/program.d.ts.map +1 -0
- package/dist/authorization/program.js +713 -0
- package/dist/authorization/program.js.map +1 -0
- package/dist/authorization/reexec-wrapper.d.ts +106 -0
- package/dist/authorization/reexec-wrapper.d.ts.map +1 -0
- package/dist/authorization/reexec-wrapper.js +532 -0
- package/dist/authorization/reexec-wrapper.js.map +1 -0
- package/dist/authorization/rules.d.ts +9 -0
- package/dist/authorization/rules.d.ts.map +1 -1
- package/dist/authorization/rules.js +8 -1
- package/dist/authorization/rules.js.map +1 -1
- package/dist/authorization/shell-lexer.d.ts +19 -4
- package/dist/authorization/shell-lexer.d.ts.map +1 -1
- package/dist/authorization/shell-lexer.js +91 -65
- package/dist/authorization/shell-lexer.js.map +1 -1
- package/dist/bridge/sse/mapper.d.ts.map +1 -1
- package/dist/bridge/sse/mapper.js +6 -0
- package/dist/bridge/sse/mapper.js.map +1 -1
- package/dist/capabilities/index.d.ts +54 -0
- package/dist/capabilities/index.d.ts.map +1 -0
- package/dist/capabilities/index.js +92 -0
- package/dist/capabilities/index.js.map +1 -0
- package/dist/config/registry.d.ts +2 -1
- package/dist/config/registry.d.ts.map +1 -1
- package/dist/config/registry.js +3 -2
- package/dist/config/registry.js.map +1 -1
- package/dist/connector/index.d.ts +4 -4
- package/dist/connector/index.d.ts.map +1 -1
- package/dist/connector/index.js +3 -3
- package/dist/connector/index.js.map +1 -1
- package/dist/connector/mcp/adapter.d.ts +16 -1
- package/dist/connector/mcp/adapter.d.ts.map +1 -1
- package/dist/connector/mcp/adapter.js +71 -4
- package/dist/connector/mcp/adapter.js.map +1 -1
- package/dist/connector/mcp/client.d.ts +32 -4
- package/dist/connector/mcp/client.d.ts.map +1 -1
- package/dist/connector/mcp/client.js +383 -5
- package/dist/connector/mcp/client.js.map +1 -1
- package/dist/connector/mcp/discovery.d.ts +24 -1
- package/dist/connector/mcp/discovery.d.ts.map +1 -1
- package/dist/connector/mcp/discovery.js +44 -0
- package/dist/connector/mcp/discovery.js.map +1 -1
- package/dist/connector/mcp/era.d.ts.map +1 -1
- package/dist/connector/mcp/era.js +7 -0
- package/dist/connector/mcp/era.js.map +1 -1
- package/dist/connector/mcp/index.d.ts +2 -0
- package/dist/connector/mcp/index.d.ts.map +1 -1
- package/dist/connector/mcp/index.js +11 -0
- package/dist/connector/mcp/index.js.map +1 -1
- package/dist/connector/mcp/mcp-toolset.d.ts +133 -0
- package/dist/connector/mcp/mcp-toolset.d.ts.map +1 -0
- package/dist/connector/mcp/mcp-toolset.js +399 -0
- package/dist/connector/mcp/mcp-toolset.js.map +1 -0
- package/dist/connector/mcp/streamable-http.d.ts +15 -0
- package/dist/connector/mcp/streamable-http.d.ts.map +1 -1
- package/dist/connector/mcp/streamable-http.js +281 -6
- package/dist/connector/mcp/streamable-http.js.map +1 -1
- package/dist/connector/tools/index.d.ts +2 -2
- package/dist/connector/tools/index.d.ts.map +1 -1
- package/dist/connector/tools/index.js +1 -1
- package/dist/connector/tools/index.js.map +1 -1
- package/dist/connector/tools/router.d.ts +15 -13
- package/dist/connector/tools/router.d.ts.map +1 -1
- package/dist/connector/tools/router.js +30 -51
- package/dist/connector/tools/router.js.map +1 -1
- package/dist/contracts/a2a.d.ts +2 -2
- package/dist/directory/derive-supervisor.d.ts +2 -2
- package/dist/directory/derive-supervisor.d.ts.map +1 -1
- package/dist/directory/derive-supervisor.js +6 -7
- package/dist/directory/derive-supervisor.js.map +1 -1
- package/dist/directory/derive.d.ts.map +1 -1
- package/dist/directory/derive.js +5 -5
- package/dist/directory/derive.js.map +1 -1
- package/dist/execution/code-runtime/types.d.ts +2 -2
- package/dist/execution/code-runtime/types.js +1 -1
- package/dist/invariants/index.d.ts +2 -1
- package/dist/invariants/index.d.ts.map +1 -1
- package/dist/invariants/index.js +3 -2
- package/dist/invariants/index.js.map +1 -1
- package/dist/manager/agent/lifecycle.d.ts +1 -0
- package/dist/manager/agent/lifecycle.d.ts.map +1 -1
- package/dist/manager/agent/lifecycle.js +146 -18
- package/dist/manager/agent/lifecycle.js.map +1 -1
- package/dist/manager/connector/environment.d.ts +6 -0
- package/dist/manager/connector/environment.d.ts.map +1 -1
- package/dist/manager/connector/environment.js +11 -4
- package/dist/manager/connector/environment.js.map +1 -1
- package/dist/manager/connector/index.d.ts +2 -2
- package/dist/manager/connector/index.d.ts.map +1 -1
- package/dist/manager/connector/index.js +2 -2
- package/dist/manager/connector/index.js.map +1 -1
- package/dist/manager/connector/tenant.d.ts +6 -0
- package/dist/manager/connector/tenant.d.ts.map +1 -1
- package/dist/manager/connector/tenant.js +11 -4
- package/dist/manager/connector/tenant.js.map +1 -1
- package/dist/manager/index.d.ts +2 -2
- package/dist/manager/index.d.ts.map +1 -1
- package/dist/manager/index.js +2 -2
- package/dist/manager/index.js.map +1 -1
- package/dist/manager/resident/initiative.d.ts +6 -6
- package/dist/manager/resident/learning-observation.d.ts +4 -4
- package/dist/manager/resident/learning.d.ts +36 -36
- package/dist/manager/resident/outbox.d.ts +4 -4
- package/dist/manager/session/attribution.d.ts +22 -0
- package/dist/manager/session/attribution.d.ts.map +1 -0
- package/dist/manager/session/attribution.js +64 -0
- package/dist/manager/session/attribution.js.map +1 -0
- package/dist/manager/session/turn-recorder.d.ts +14 -0
- package/dist/manager/session/turn-recorder.d.ts.map +1 -1
- package/dist/manager/session/turn-recorder.js +208 -55
- package/dist/manager/session/turn-recorder.js.map +1 -1
- package/dist/peers/address.d.ts +36 -0
- package/dist/peers/address.d.ts.map +1 -0
- package/dist/peers/address.js +52 -0
- package/dist/peers/address.js.map +1 -0
- package/dist/peers/client.d.ts +47 -0
- package/dist/peers/client.d.ts.map +1 -0
- package/dist/peers/client.js +132 -0
- package/dist/peers/client.js.map +1 -0
- package/dist/peers/dir.d.ts +88 -0
- package/dist/peers/dir.d.ts.map +1 -0
- package/dist/peers/dir.js +139 -0
- package/dist/peers/dir.js.map +1 -0
- package/dist/peers/endpoint.d.ts +144 -0
- package/dist/peers/endpoint.d.ts.map +1 -0
- package/dist/peers/endpoint.js +420 -0
- package/dist/peers/endpoint.js.map +1 -0
- package/dist/peers/envelope.d.ts +42 -0
- package/dist/peers/envelope.d.ts.map +1 -0
- package/dist/peers/envelope.js +110 -0
- package/dist/peers/envelope.js.map +1 -0
- package/dist/peers/index.d.ts +30 -0
- package/dist/peers/index.d.ts.map +1 -0
- package/dist/peers/index.js +22 -0
- package/dist/peers/index.js.map +1 -0
- package/dist/peers/protocol.d.ts +645 -0
- package/dist/peers/protocol.d.ts.map +1 -0
- package/dist/peers/protocol.js +151 -0
- package/dist/peers/protocol.js.map +1 -0
- package/dist/peers/record.d.ts +71 -0
- package/dist/peers/record.d.ts.map +1 -0
- package/dist/peers/record.js +45 -0
- package/dist/peers/record.js.map +1 -0
- package/dist/peers/registry.d.ts +54 -0
- package/dist/peers/registry.d.ts.map +1 -0
- package/dist/peers/registry.js +213 -0
- package/dist/peers/registry.js.map +1 -0
- package/dist/plugin/define.d.ts +24 -0
- package/dist/plugin/define.d.ts.map +1 -0
- package/dist/plugin/define.js +42 -0
- package/dist/plugin/define.js.map +1 -0
- 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/lifecycle.d.ts +27 -3
- package/dist/plugin/lifecycle.d.ts.map +1 -1
- package/dist/plugin/lifecycle.js +242 -92
- package/dist/plugin/lifecycle.js.map +1 -1
- package/dist/plugin/resolver.d.ts +2 -2
- package/dist/plugin/resolver.d.ts.map +1 -1
- package/dist/plugin/resolver.js.map +1 -1
- package/dist/plugin/shell-hook.d.ts.map +1 -1
- package/dist/plugin/shell-hook.js +17 -3
- package/dist/plugin/shell-hook.js.map +1 -1
- package/dist/probe/errors.d.ts +2 -1
- package/dist/probe/errors.d.ts.map +1 -1
- package/dist/probe/errors.js +3 -2
- package/dist/probe/errors.js.map +1 -1
- package/dist/prompt/coding-agent-doctrine.d.ts +18 -7
- package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
- package/dist/prompt/coding-agent-doctrine.js +11 -6
- package/dist/prompt/coding-agent-doctrine.js.map +1 -1
- package/dist/prompt/contributions.d.ts +4 -1
- package/dist/prompt/contributions.d.ts.map +1 -1
- package/dist/prompt/contributions.js +7 -2
- package/dist/prompt/contributions.js.map +1 -1
- package/dist/prompt/index.d.ts +1 -1
- package/dist/prompt/index.d.ts.map +1 -1
- package/dist/prompt/index.js +1 -1
- package/dist/prompt/index.js.map +1 -1
- package/dist/provider/collect-chat-completion.d.ts +6 -1
- package/dist/provider/collect-chat-completion.d.ts.map +1 -1
- package/dist/provider/collect-chat-completion.js +88 -10
- package/dist/provider/collect-chat-completion.js.map +1 -1
- package/dist/provider/mock.d.ts.map +1 -1
- package/dist/provider/mock.js +23 -6
- package/dist/provider/mock.js.map +1 -1
- package/dist/provider/registry.d.ts +2 -1
- package/dist/provider/registry.d.ts.map +1 -1
- package/dist/provider/registry.js +3 -2
- package/dist/provider/registry.js.map +1 -1
- package/dist/provider/tool-call-framing.d.ts +164 -0
- package/dist/provider/tool-call-framing.d.ts.map +1 -0
- package/dist/provider/tool-call-framing.js +163 -0
- package/dist/provider/tool-call-framing.js.map +1 -0
- package/dist/public-runtime.d.ts +24 -11
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +45 -9
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +6 -4
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +8 -3
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +13 -2
- package/dist/public-types.d.ts.map +1 -1
- package/dist/read-model/registry.d.ts +2 -1
- package/dist/read-model/registry.d.ts.map +1 -1
- package/dist/read-model/registry.js +3 -2
- package/dist/read-model/registry.js.map +1 -1
- package/dist/registry/ManagedRegistry.d.ts +30 -0
- package/dist/registry/ManagedRegistry.d.ts.map +1 -1
- package/dist/registry/ManagedRegistry.js +45 -6
- package/dist/registry/ManagedRegistry.js.map +1 -1
- package/dist/registry/collision.d.ts +57 -0
- package/dist/registry/collision.d.ts.map +1 -0
- package/dist/registry/collision.js +41 -0
- package/dist/registry/collision.js.map +1 -0
- package/dist/registry/command/index.d.ts +5 -3
- package/dist/registry/command/index.d.ts.map +1 -1
- package/dist/registry/command/index.js +6 -4
- package/dist/registry/command/index.js.map +1 -1
- package/dist/registry/index.d.ts +3 -4
- package/dist/registry/index.d.ts.map +1 -1
- package/dist/registry/index.js +2 -2
- package/dist/registry/index.js.map +1 -1
- package/dist/registry/plugin/index.d.ts.map +1 -1
- package/dist/registry/plugin/index.js +14 -1
- package/dist/registry/plugin/index.js.map +1 -1
- package/dist/registry/tool/callable.d.ts +7 -7
- package/dist/registry/tool/callable.d.ts.map +1 -1
- package/dist/registry/tool/callable.js +6 -7
- package/dist/registry/tool/callable.js.map +1 -1
- package/dist/registry/tool/execute.d.ts +14 -77
- package/dist/registry/tool/execute.d.ts.map +1 -1
- package/dist/registry/tool/execute.js +15 -727
- package/dist/registry/tool/execute.js.map +1 -1
- package/dist/registry/tool/portable.d.ts +25 -0
- package/dist/registry/tool/portable.d.ts.map +1 -1
- package/dist/registry/tool/portable.js +50 -0
- package/dist/registry/tool/portable.js.map +1 -1
- package/dist/registry/tool/presentation.d.ts +6 -5
- package/dist/registry/tool/presentation.d.ts.map +1 -1
- package/dist/registry/tool/presentation.js +3 -3
- package/dist/registry/tool/presentation.js.map +1 -1
- package/dist/runtime/bidi/session.d.ts +5 -4
- package/dist/runtime/bidi/session.d.ts.map +1 -1
- package/dist/runtime/bidi/session.js +18 -1
- package/dist/runtime/bidi/session.js.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.d.ts +45 -2
- package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.js +189 -5
- package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +33 -3
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +86 -10
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/file-evidence-replay.d.ts +1 -1
- package/dist/runtime/query/file-evidence-replay.d.ts.map +1 -1
- package/dist/runtime/query/file-evidence-replay.js +8 -7
- package/dist/runtime/query/file-evidence-replay.js.map +1 -1
- package/dist/runtime/query/fork/prepare.d.ts +4 -1
- package/dist/runtime/query/fork/prepare.d.ts.map +1 -1
- package/dist/runtime/query/fork/prepare.js +4 -0
- package/dist/runtime/query/fork/prepare.js.map +1 -1
- package/dist/runtime/query/guardrail-presets.d.ts +4 -3
- package/dist/runtime/query/guardrail-presets.d.ts.map +1 -1
- package/dist/runtime/query/guardrail-presets.js +4 -3
- package/dist/runtime/query/guardrail-presets.js.map +1 -1
- package/dist/runtime/query/index.d.ts +23 -10
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +149 -70
- 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 +8 -1
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.js +1 -1
- package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context.d.ts +2 -2
- package/dist/runtime/query/iteration/phases/context.d.ts.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 +55 -2
- 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 +342 -116
- package/dist/runtime/query/iteration/stream-turn.js.map +1 -1
- package/dist/runtime/query/iteration/tool-input.d.ts +79 -0
- package/dist/runtime/query/iteration/tool-input.d.ts.map +1 -0
- package/dist/runtime/query/iteration/tool-input.js +291 -0
- package/dist/runtime/query/iteration/tool-input.js.map +1 -0
- package/dist/runtime/query/observation-context.d.ts +2 -2
- package/dist/runtime/query/observation-context.d.ts.map +1 -1
- package/dist/runtime/query/observation-context.js.map +1 -1
- package/dist/runtime/query/prelude-lease.d.ts +18 -0
- package/dist/runtime/query/prelude-lease.d.ts.map +1 -0
- package/dist/runtime/query/prelude-lease.js +121 -0
- package/dist/runtime/query/prelude-lease.js.map +1 -0
- package/dist/runtime/query/prepare-turn.d.ts.map +1 -1
- package/dist/runtime/query/prepare-turn.js +386 -187
- package/dist/runtime/query/prepare-turn.js.map +1 -1
- package/dist/runtime/query/prompt-cache.d.ts +2 -2
- package/dist/runtime/query/prompt-cache.d.ts.map +1 -1
- package/dist/runtime/query/prompt.d.ts +2 -2
- package/dist/runtime/query/prompt.d.ts.map +1 -1
- package/dist/runtime/query/prompt.js +1 -1
- package/dist/runtime/query/prompt.js.map +1 -1
- package/dist/runtime/query/resume-session.d.ts.map +1 -1
- package/dist/runtime/query/resume-session.js +37 -2
- package/dist/runtime/query/resume-session.js.map +1 -1
- package/dist/runtime/query/review-policy.d.ts +22 -3
- package/dist/runtime/query/review-policy.d.ts.map +1 -1
- package/dist/runtime/query/review-policy.js +84 -6
- package/dist/runtime/query/review-policy.js.map +1 -1
- package/dist/runtime/query/tooling.d.ts +3 -2
- package/dist/runtime/query/tooling.d.ts.map +1 -1
- package/dist/runtime/query/tooling.js.map +1 -1
- package/dist/runtime/query/turn-state.d.ts.map +1 -1
- package/dist/runtime/query/turn-state.js +5 -0
- package/dist/runtime/query/turn-state.js.map +1 -1
- package/dist/runtime/system-events.d.ts +112 -0
- package/dist/runtime/system-events.d.ts.map +1 -0
- package/dist/runtime/system-events.js +183 -0
- package/dist/runtime/system-events.js.map +1 -0
- package/dist/scheduler/delegating.d.ts +2 -1
- package/dist/scheduler/delegating.d.ts.map +1 -1
- package/dist/scheduler/delegating.js +3 -2
- package/dist/scheduler/delegating.js.map +1 -1
- package/dist/scheduler/local.d.ts.map +1 -1
- package/dist/scheduler/local.js +2 -0
- package/dist/scheduler/local.js.map +1 -1
- package/dist/session/retention/archive.js +1 -1
- package/dist/session/retention/archive.js.map +1 -1
- package/dist/skills/index.d.ts +1 -1
- package/dist/skills/index.d.ts.map +1 -1
- package/dist/skills/index.js +1 -1
- package/dist/skills/index.js.map +1 -1
- package/dist/skills/registry.d.ts +12 -0
- package/dist/skills/registry.d.ts.map +1 -1
- package/dist/skills/registry.js +19 -0
- package/dist/skills/registry.js.map +1 -1
- package/dist/store/evidence/index-page.d.ts +2 -2
- package/dist/store/session/disk.d.ts.map +1 -1
- package/dist/store/session/disk.js +2 -0
- package/dist/store/session/disk.js.map +1 -1
- package/dist/store/session-log/conformance.d.ts +1 -1
- package/dist/store/session-log/conformance.d.ts.map +1 -1
- package/dist/store/session-log/conformance.js +49 -8
- package/dist/store/session-log/conformance.js.map +1 -1
- package/dist/store/session-log/core.d.ts +8 -3
- package/dist/store/session-log/core.d.ts.map +1 -1
- package/dist/store/session-log/core.js +2 -1
- package/dist/store/session-log/core.js.map +1 -1
- package/dist/store/session-log/fold.d.ts +12 -0
- package/dist/store/session-log/fold.d.ts.map +1 -1
- package/dist/store/session-log/fold.js +57 -7
- package/dist/store/session-log/fold.js.map +1 -1
- package/dist/store/session-log/index.d.ts +2 -2
- package/dist/store/session-log/index.d.ts.map +1 -1
- package/dist/store/session-log/index.js +1 -1
- package/dist/store/session-log/index.js.map +1 -1
- package/dist/test-support/toolset.d.ts +19 -0
- package/dist/test-support/toolset.d.ts.map +1 -0
- package/dist/test-support/toolset.js +20 -0
- package/dist/test-support/toolset.js.map +1 -0
- package/dist/tools/builtins/bash.d.ts +29 -0
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +19 -9
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/browser-url.d.ts +1 -1
- package/dist/tools/builtins/browser-url.js +1 -1
- package/dist/tools/builtins/browser.d.ts +6 -6
- package/dist/tools/builtins/browser.js +2 -2
- package/dist/tools/builtins/browser.js.map +1 -1
- package/dist/tools/builtins/computer-use.d.ts.map +1 -1
- package/dist/tools/builtins/computer-use.js +19 -11
- package/dist/tools/builtins/computer-use.js.map +1 -1
- package/dist/tools/builtins/edit.d.ts.map +1 -1
- package/dist/tools/builtins/edit.js +9 -1
- package/dist/tools/builtins/edit.js.map +1 -1
- package/dist/tools/builtins/json-string-hint.d.ts +15 -0
- package/dist/tools/builtins/json-string-hint.d.ts.map +1 -0
- package/dist/tools/builtins/json-string-hint.js +17 -0
- package/dist/tools/builtins/json-string-hint.js.map +1 -0
- package/dist/tools/builtins/search-tools.d.ts.map +1 -1
- package/dist/tools/builtins/search-tools.js +7 -15
- package/dist/tools/builtins/search-tools.js.map +1 -1
- package/dist/tools/builtins/write-file.d.ts.map +1 -1
- package/dist/tools/builtins/write-file.js +11 -0
- package/dist/tools/builtins/write-file.js.map +1 -1
- package/dist/tools/command-shell.d.ts +10 -0
- package/dist/tools/command-shell.d.ts.map +1 -1
- package/dist/tools/command-shell.js +45 -1
- package/dist/tools/command-shell.js.map +1 -1
- package/dist/tools/coordinator/agent.d.ts.map +1 -1
- package/dist/tools/coordinator/agent.js +5 -0
- package/dist/tools/coordinator/agent.js.map +1 -1
- package/dist/tools/coordinator/ask-user-question.d.ts.map +1 -1
- package/dist/tools/coordinator/ask-user-question.js +26 -13
- package/dist/tools/coordinator/ask-user-question.js.map +1 -1
- package/dist/tools/coordinator/index.d.ts.map +1 -1
- package/dist/tools/coordinator/index.js +5 -0
- package/dist/tools/coordinator/index.js.map +1 -1
- package/dist/tools/coordinator/question-options.d.ts +78 -0
- package/dist/tools/coordinator/question-options.d.ts.map +1 -0
- package/dist/tools/coordinator/question-options.js +153 -0
- package/dist/tools/coordinator/question-options.js.map +1 -0
- package/dist/tools/defineTool.d.ts +10 -0
- package/dist/tools/defineTool.d.ts.map +1 -1
- package/dist/tools/defineTool.js +17 -0
- package/dist/tools/defineTool.js.map +1 -1
- package/dist/tools/memory/search.d.ts.map +1 -1
- package/dist/tools/memory/search.js +4 -1
- package/dist/tools/memory/search.js.map +1 -1
- package/dist/tools/memory/update.d.ts.map +1 -1
- package/dist/tools/memory/update.js +8 -5
- package/dist/tools/memory/update.js.map +1 -1
- package/dist/tools/render-nonce.d.ts +47 -0
- package/dist/tools/render-nonce.d.ts.map +1 -0
- package/dist/tools/render-nonce.js +63 -0
- package/dist/tools/render-nonce.js.map +1 -0
- package/dist/tools/roster.d.ts +46 -19
- package/dist/tools/roster.d.ts.map +1 -1
- package/dist/tools/roster.js +63 -33
- package/dist/tools/roster.js.map +1 -1
- package/dist/tools/schedules/schedule-tool.d.ts.map +1 -1
- package/dist/tools/schedules/schedule-tool.js +94 -14
- package/dist/tools/schedules/schedule-tool.js.map +1 -1
- package/dist/tools/schedules/types.d.ts +52 -6
- package/dist/tools/schedules/types.d.ts.map +1 -1
- package/dist/tools/trusted-read-only.d.ts +9 -5
- package/dist/tools/trusted-read-only.d.ts.map +1 -1
- package/dist/tools/trusted-read-only.js +14 -10
- package/dist/tools/trusted-read-only.js.map +1 -1
- package/dist/tools/untrusted-envelope.d.ts +67 -28
- package/dist/tools/untrusted-envelope.d.ts.map +1 -1
- package/dist/tools/untrusted-envelope.js +108 -59
- package/dist/tools/untrusted-envelope.js.map +1 -1
- package/dist/toolsets/combine.d.ts +44 -0
- package/dist/toolsets/combine.d.ts.map +1 -0
- package/dist/toolsets/combine.js +153 -0
- package/dist/toolsets/combine.js.map +1 -0
- package/dist/toolsets/manager.d.ts +201 -0
- package/dist/toolsets/manager.d.ts.map +1 -0
- package/dist/toolsets/manager.js +837 -0
- package/dist/toolsets/manager.js.map +1 -0
- package/dist/toolsets/source-glob.d.ts +15 -0
- package/dist/toolsets/source-glob.d.ts.map +1 -0
- package/dist/toolsets/source-glob.js +23 -0
- package/dist/toolsets/source-glob.js.map +1 -0
- package/dist/toolsets/toolset.d.ts +20 -0
- package/dist/toolsets/toolset.d.ts.map +1 -0
- package/dist/toolsets/toolset.js +28 -0
- package/dist/toolsets/toolset.js.map +1 -0
- package/dist/toolsets/types.d.ts +128 -0
- package/dist/toolsets/types.d.ts.map +1 -0
- package/dist/toolsets/types.js +33 -0
- package/dist/toolsets/types.js.map +1 -0
- package/dist/toolsets/wrappers.d.ts +59 -0
- package/dist/toolsets/wrappers.d.ts.map +1 -0
- package/dist/toolsets/wrappers.js +165 -0
- package/dist/toolsets/wrappers.js.map +1 -0
- package/dist/types/agent/base.d.ts +27 -16
- package/dist/types/agent/base.d.ts.map +1 -1
- package/dist/types/agent/index.d.ts +1 -0
- package/dist/types/agent/index.d.ts.map +1 -1
- package/dist/types/agent/index.js +1 -0
- package/dist/types/agent/index.js.map +1 -1
- package/dist/types/agent/pipeline.d.ts +2 -0
- package/dist/types/agent/pipeline.d.ts.map +1 -1
- package/dist/types/agent/query.d.ts +117 -0
- package/dist/types/agent/query.d.ts.map +1 -0
- package/dist/types/agent/query.js +2 -0
- package/dist/types/agent/query.js.map +1 -0
- package/dist/types/agent/reactive.d.ts +2 -129
- package/dist/types/agent/reactive.d.ts.map +1 -1
- package/dist/types/agent/router.d.ts +2 -0
- package/dist/types/agent/router.d.ts.map +1 -1
- package/dist/types/agent/scheduler.d.ts +6 -1
- package/dist/types/agent/scheduler.d.ts.map +1 -1
- package/dist/types/agent/supervisor.d.ts +5 -2
- package/dist/types/agent/supervisor.d.ts.map +1 -1
- package/dist/types/agent/task.d.ts +19 -1
- package/dist/types/agent/task.d.ts.map +1 -1
- package/dist/types/agent/task.js.map +1 -1
- package/dist/types/authorization/index.d.ts +49 -12
- package/dist/types/authorization/index.d.ts.map +1 -1
- package/dist/types/authorization/index.js +6 -0
- package/dist/types/authorization/index.js.map +1 -1
- package/dist/types/connector/mcp.d.ts +45 -0
- package/dist/types/connector/mcp.d.ts.map +1 -1
- package/dist/types/errors/index.d.ts +15 -0
- package/dist/types/errors/index.d.ts.map +1 -1
- package/dist/types/errors/index.js.map +1 -1
- package/dist/types/hitl/index.d.ts +57 -0
- package/dist/types/hitl/index.d.ts.map +1 -1
- package/dist/types/hitl/index.js.map +1 -1
- package/dist/types/message/index.d.ts +130 -9
- package/dist/types/message/index.d.ts.map +1 -1
- package/dist/types/message/index.js +4 -1
- package/dist/types/message/index.js.map +1 -1
- package/dist/types/plugin/index.d.ts +22 -4
- package/dist/types/plugin/index.d.ts.map +1 -1
- package/dist/types/plugin/index.js +1 -0
- package/dist/types/plugin/index.js.map +1 -1
- package/dist/types/provider/chat.d.ts +5 -0
- package/dist/types/provider/chat.d.ts.map +1 -1
- package/dist/types/provider/config.d.ts +8 -3
- package/dist/types/provider/config.d.ts.map +1 -1
- package/dist/types/provider/stream.d.ts +39 -0
- package/dist/types/provider/stream.d.ts.map +1 -1
- package/dist/types/sandbox/index.d.ts +1 -1
- package/dist/types/session/events.d.ts +14 -3
- package/dist/types/session/events.d.ts.map +1 -1
- package/dist/types/session/events.js.map +1 -1
- package/dist/types/session/sub-session.d.ts +2 -0
- package/dist/types/session/sub-session.d.ts.map +1 -1
- package/dist/types/tool/index.d.ts +152 -91
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/dist/types/toolset/index.d.ts +10 -40
- package/dist/types/toolset/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/advisory/history.ts +27 -2
- package/src/advisory/index.ts +1 -1
- package/src/advisory/registry.ts +33 -0
- package/src/agents/AGENTS.md +14 -7
- package/src/agents/PipelineAgent.ts +2 -303
- package/src/agents/QueryAgent.ts +269 -0
- package/src/agents/ReactiveAgent.ts +6 -216
- package/src/agents/RouterAgent.ts +2 -337
- package/src/agents/SupervisorAgent.ts +3 -476
- package/src/agents/defineAgent.ts +13 -2
- package/src/agents/examples/PipelineAgent.ts +302 -0
- package/src/agents/examples/RouterAgent.ts +338 -0
- package/src/agents/examples/SupervisorAgent.ts +472 -0
- package/src/agents/explore.ts +6 -3
- package/src/agents/forward-options.ts +37 -0
- package/src/agents/index.ts +2 -0
- package/src/agents/runAgent.ts +144 -37
- package/src/authorization/command-line.ts +2 -2
- package/src/authorization/gate.ts +21 -1
- package/src/authorization/program.ts +773 -0
- package/src/authorization/reexec-wrapper.ts +589 -0
- package/src/authorization/rules.ts +18 -1
- package/src/authorization/shell-lexer.ts +104 -59
- package/src/bridge/sse/mapper.ts +6 -0
- package/src/capabilities/index.ts +157 -0
- package/src/config/registry.ts +4 -1
- package/src/connector/index.ts +9 -2
- package/src/connector/mcp/adapter.ts +73 -3
- package/src/connector/mcp/client.ts +425 -6
- package/src/connector/mcp/discovery.ts +60 -0
- package/src/connector/mcp/era.ts +7 -0
- package/src/connector/mcp/index.ts +13 -0
- package/src/connector/mcp/mcp-toolset.ts +515 -0
- package/src/connector/mcp/streamable-http.ts +302 -5
- package/src/connector/tools/index.ts +2 -2
- package/src/connector/tools/router.ts +35 -58
- package/src/directory/derive-supervisor.ts +12 -8
- package/src/directory/derive.ts +8 -5
- package/src/execution/code-runtime/types.ts +2 -2
- package/src/invariants/index.ts +4 -1
- package/src/manager/agent/lifecycle.ts +167 -19
- package/src/manager/connector/environment.ts +17 -4
- package/src/manager/connector/index.ts +2 -2
- package/src/manager/connector/tenant.ts +17 -4
- package/src/manager/index.ts +2 -2
- package/src/manager/session/attribution.ts +79 -0
- package/src/manager/session/turn-recorder.ts +211 -55
- package/src/peers/address.ts +58 -0
- package/src/peers/client.ts +202 -0
- package/src/peers/dir.ts +176 -0
- package/src/peers/endpoint.ts +564 -0
- package/src/peers/envelope.ts +121 -0
- package/src/peers/index.ts +96 -0
- package/src/peers/protocol.ts +196 -0
- package/src/peers/record.ts +56 -0
- package/src/peers/registry.ts +241 -0
- package/src/plugin/define.ts +68 -0
- package/src/plugin/index.ts +2 -0
- package/src/plugin/lifecycle.ts +286 -106
- package/src/plugin/resolver.ts +6 -3
- package/src/plugin/shell-hook.ts +21 -5
- package/src/probe/errors.ts +4 -1
- package/src/prompt/coding-agent-doctrine.ts +22 -10
- package/src/prompt/contributions.ts +12 -2
- package/src/prompt/index.ts +1 -0
- package/src/provider/collect-chat-completion.ts +96 -11
- package/src/provider/mock.ts +24 -6
- package/src/provider/registry.ts +4 -1
- package/src/provider/tool-call-framing.ts +226 -0
- package/src/public-runtime.ts +136 -7
- package/src/public-tools.ts +24 -4
- package/src/public-types.ts +60 -6
- package/src/read-model/registry.ts +7 -2
- package/src/registry/ManagedRegistry.ts +57 -6
- package/src/registry/collision.ts +64 -0
- package/src/registry/command/index.ts +7 -3
- package/src/registry/index.ts +3 -9
- package/src/registry/plugin/index.ts +14 -1
- package/src/registry/tool/callable.ts +8 -9
- package/src/registry/tool/execute.ts +16 -846
- package/src/registry/tool/portable.ts +59 -0
- package/src/registry/tool/presentation.ts +6 -5
- package/src/runtime/bidi/session.ts +24 -5
- package/src/runtime/query/executor/tool-call-admission.ts +228 -6
- package/src/runtime/query/executor.ts +110 -12
- package/src/runtime/query/file-evidence-replay.ts +8 -7
- package/src/runtime/query/fork/prepare.ts +6 -1
- package/src/runtime/query/guardrail-presets.ts +4 -3
- package/src/runtime/query/index.ts +199 -101
- package/src/runtime/query/iteration/index.ts +13 -3
- package/src/runtime/query/iteration/phases/compaction.ts +1 -1
- package/src/runtime/query/iteration/phases/context.ts +2 -2
- package/src/runtime/query/iteration/phases/tool-review.ts +59 -2
- package/src/runtime/query/iteration/stream-turn.ts +390 -136
- package/src/runtime/query/iteration/tool-input.ts +284 -0
- package/src/runtime/query/observation-context.ts +2 -2
- package/src/runtime/query/prelude-lease.ts +132 -0
- package/src/runtime/query/prepare-turn.ts +477 -198
- package/src/runtime/query/prompt-cache.ts +2 -2
- package/src/runtime/query/prompt.ts +4 -4
- package/src/runtime/query/resume-session.ts +42 -3
- package/src/runtime/query/review-policy.ts +87 -9
- package/src/runtime/query/tooling.ts +3 -6
- package/src/runtime/query/turn-state.ts +4 -0
- package/src/runtime/system-events.ts +246 -0
- package/src/scheduler/delegating.ts +7 -2
- package/src/scheduler/local.ts +2 -0
- package/src/session/retention/archive.ts +1 -1
- package/src/skills/index.ts +1 -1
- package/src/skills/registry.ts +25 -0
- package/src/store/session/disk.ts +3 -0
- package/src/store/session-log/conformance.ts +51 -8
- package/src/store/session-log/core.ts +10 -4
- package/src/store/session-log/fold.ts +33 -7
- package/src/store/session-log/index.ts +2 -0
- package/src/test-support/toolset.ts +23 -0
- package/src/tools/builtins/bash.ts +27 -10
- package/src/tools/builtins/browser-url.ts +1 -1
- package/src/tools/builtins/browser.ts +2 -2
- package/src/tools/builtins/computer-use.ts +21 -11
- package/src/tools/builtins/edit.ts +12 -2
- package/src/tools/builtins/json-string-hint.ts +16 -0
- package/src/tools/builtins/search-tools.ts +7 -20
- package/src/tools/builtins/write-file.ts +12 -0
- package/src/tools/command-shell.ts +46 -1
- package/src/tools/coordinator/agent.ts +6 -0
- package/src/tools/coordinator/ask-user-question.ts +29 -15
- package/src/tools/coordinator/index.ts +6 -0
- package/src/tools/coordinator/question-options.ts +195 -0
- package/src/tools/defineTool.ts +28 -0
- package/src/tools/memory/search.ts +4 -1
- package/src/tools/memory/update.ts +8 -5
- package/src/tools/render-nonce.ts +69 -0
- package/src/tools/roster.ts +84 -33
- package/src/tools/schedules/schedule-tool.ts +107 -14
- package/src/tools/schedules/types.ts +52 -6
- package/src/tools/trusted-read-only.ts +19 -10
- package/src/tools/untrusted-envelope.ts +121 -57
- package/src/toolsets/combine.ts +181 -0
- package/src/toolsets/manager.ts +996 -0
- package/src/toolsets/source-glob.ts +22 -0
- package/src/toolsets/toolset.ts +31 -0
- package/src/toolsets/types.ts +154 -0
- package/src/toolsets/wrappers.ts +191 -0
- package/src/types/agent/base.ts +29 -16
- package/src/types/agent/index.ts +1 -0
- package/src/types/agent/pipeline.ts +2 -0
- package/src/types/agent/query.ts +129 -0
- package/src/types/agent/reactive.ts +5 -142
- package/src/types/agent/router.ts +2 -0
- package/src/types/agent/scheduler.ts +6 -1
- package/src/types/agent/supervisor.ts +5 -2
- package/src/types/agent/task.ts +21 -1
- package/src/types/authorization/index.ts +12 -0
- package/src/types/connector/mcp.ts +46 -0
- package/src/types/errors/index.ts +15 -0
- package/src/types/hitl/index.ts +57 -0
- package/src/types/message/index.ts +135 -7
- package/src/types/plugin/index.ts +44 -21
- package/src/types/provider/chat.ts +5 -0
- package/src/types/provider/config.ts +8 -3
- package/src/types/provider/stream.ts +39 -0
- package/src/types/sandbox/index.ts +1 -1
- package/src/types/session/events.ts +14 -3
- package/src/types/session/sub-session.ts +2 -0
- package/src/types/tool/index.ts +154 -105
- package/src/types/toolset/index.ts +10 -47
- package/dist/registry/toolset/catalog.d.ts +0 -42
- package/dist/registry/toolset/catalog.d.ts.map +0 -1
- package/dist/registry/toolset/catalog.js +0 -234
- package/dist/registry/toolset/catalog.js.map +0 -1
- package/src/registry/toolset/catalog.ts +0 -308
|
@@ -0,0 +1,589 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One layer of a re-exec wrapper (`sudo`, `env`, `nice`, `timeout`, …): the
|
|
3
|
+
* shared "what does this wrapper's own name, options and mandatory
|
|
4
|
+
* arguments consume, and what is left" logic behind two different
|
|
5
|
+
* questions that must never quietly disagree about where a wrapper ends:
|
|
6
|
+
*
|
|
7
|
+
* - the shell lexer's `nestedShellCommand` (`shell-lexer.ts`), which reads a
|
|
8
|
+
* literal `-c` payload as a command line of its own — and needs to look
|
|
9
|
+
* PAST a wrapper to find one, since `env -i bash -c "…"` and
|
|
10
|
+
* `nice -n 5 sh -ec "…"` hide the shell exactly as `bash -c "…"` does,
|
|
11
|
+
* just one or more words later;
|
|
12
|
+
* - `program.ts`'s `resolveChain`, which asks the same question — is there
|
|
13
|
+
* a shell hiding behind this wrapper — for the live `bash` tool's
|
|
14
|
+
* escalation, the scheduled-run floor and `verifyScheduledScript`, and
|
|
15
|
+
* which ALSO needs to know which `NAME=value` pairs a layer skipped past
|
|
16
|
+
* (`sudo`'s, `env`'s), to feed a poisoning one (`PATH=`, `LD_PRELOAD=`)
|
|
17
|
+
* into its own check — this module reports them, but is not itself the
|
|
18
|
+
* one that judges a name poisoning.
|
|
19
|
+
*
|
|
20
|
+
* A security review found the two questions above answered independently:
|
|
21
|
+
* the lexer's own nested-shell detection only ever looked at the literal
|
|
22
|
+
* head, so `env -i bash -c "$X"` read as an ordinary, unremarkable command
|
|
23
|
+
* (never opaque, so never escalated and never denied on the recovered
|
|
24
|
+
* text), and `toybox sh -c "$X"` was missed entirely (only `busybox` was
|
|
25
|
+
* named); separately, `sudo`'s own unwrapping never skipped a `NAME=value`
|
|
26
|
+
* pair the way `env`'s did, so `sudo VAR=value $(echo ls)` reported the
|
|
27
|
+
* assignment word itself as the program and never looked at the real one.
|
|
28
|
+
* Both questions now go through `unwrapReexecChain`/`shellInvocation`/
|
|
29
|
+
* `shellDashC` here.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import type { ShellWord } from './shell-lexer.js'
|
|
33
|
+
|
|
34
|
+
export const LITERAL = (w: ShellWord): boolean => !w.expands
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The last path segment of a word's value. Duplicated from `shell-lexer.ts`
|
|
38
|
+
* (not imported) so this module stays free of a runtime dependency back on
|
|
39
|
+
* it — `shell-lexer.ts` imports FROM here for its own `nestedShellCommand`,
|
|
40
|
+
* and a value-level import cycle between the two would be fragile. Both
|
|
41
|
+
* copies are the same three lines; keep them in sync by hand.
|
|
42
|
+
*/
|
|
43
|
+
function basename(word: string): string {
|
|
44
|
+
const cut = word.lastIndexOf('/')
|
|
45
|
+
return cut < 0 ? word : word.slice(cut + 1)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** `NAME=value` read off an assignment word's own text, or null. */
|
|
49
|
+
export function assignmentName(word: ShellWord): string | null {
|
|
50
|
+
const text = word.text.replace(/\\\n/g, '')
|
|
51
|
+
const match = /^([A-Za-z_][A-Za-z0-9_]*)\+?=/.exec(text)
|
|
52
|
+
return match && word.value.startsWith(match[0]) ? (match[1] as string) : null
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Shells whose `-c` this reads, by basename. `shell-lexer.ts` exports this
|
|
57
|
+
* same set as `NESTED_SHELLS`, so the lexer and wrapper reader cannot drift.
|
|
58
|
+
*/
|
|
59
|
+
export const PLAIN_SHELL_NAMES: ReadonlySet<string> = new Set([
|
|
60
|
+
'sh',
|
|
61
|
+
'bash',
|
|
62
|
+
'dash',
|
|
63
|
+
'zsh',
|
|
64
|
+
'ksh',
|
|
65
|
+
'ash',
|
|
66
|
+
'mksh',
|
|
67
|
+
])
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* `rest`, with the `NAME=value` pairs this layer itself skipped over
|
|
71
|
+
* (`env`'s, `sudo`'s) — empty for every other wrapper. A caller that only
|
|
72
|
+
* wants "where does unwrapping continue" reads `.rest`; `program.ts` also
|
|
73
|
+
* reads `.assignments` to judge whether one of them poisons the resolution
|
|
74
|
+
* environment for the command this wrapper runs.
|
|
75
|
+
*/
|
|
76
|
+
export type WrapperStep =
|
|
77
|
+
| { readonly rest: readonly ShellWord[]; readonly assignments: readonly string[] }
|
|
78
|
+
| { readonly unknown: string }
|
|
79
|
+
| { readonly none: true }
|
|
80
|
+
|
|
81
|
+
const NO_ASSIGNMENTS: readonly string[] = []
|
|
82
|
+
|
|
83
|
+
function justRest(rest: readonly ShellWord[]): WrapperStep {
|
|
84
|
+
return { rest, assignments: NO_ASSIGNMENTS }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Skip a wrapper's own recognised, argument-taking or bare options over
|
|
89
|
+
* `words`, stopping at the first word that is not one of them. An
|
|
90
|
+
* option-shaped word (`-x`, `--long`) this does not recognise is `unknown`,
|
|
91
|
+
* never treated as the program; a word this cannot classify because it
|
|
92
|
+
* expands is left for the caller. `explicit`, when given, names options
|
|
93
|
+
* that ARE recognised but never lead to a named program at all (`sudo -i`
|
|
94
|
+
* runs a runtime-chosen login shell) — checked before `flags`/`withArg`.
|
|
95
|
+
*/
|
|
96
|
+
export function skipOptions(
|
|
97
|
+
words: readonly ShellWord[],
|
|
98
|
+
flags: ReadonlySet<string>,
|
|
99
|
+
withArg: ReadonlySet<string>,
|
|
100
|
+
explicit?: ReadonlyMap<string, string>,
|
|
101
|
+
): WrapperStep {
|
|
102
|
+
let i = 0
|
|
103
|
+
while (i < words.length) {
|
|
104
|
+
const w = words[i] as ShellWord
|
|
105
|
+
if (!LITERAL(w)) return justRest(words.slice(i))
|
|
106
|
+
if (w.value === '--') return justRest(words.slice(i + 1))
|
|
107
|
+
const reason = explicit?.get(w.value)
|
|
108
|
+
if (reason !== undefined) return { unknown: reason }
|
|
109
|
+
if (flags.has(w.value)) {
|
|
110
|
+
i += 1
|
|
111
|
+
continue
|
|
112
|
+
}
|
|
113
|
+
if (withArg.has(w.value)) {
|
|
114
|
+
i += 2
|
|
115
|
+
continue
|
|
116
|
+
}
|
|
117
|
+
const eq = w.value.indexOf('=')
|
|
118
|
+
if (w.value.startsWith('--') && eq > 0 && withArg.has(w.value.slice(0, eq))) {
|
|
119
|
+
i += 1
|
|
120
|
+
continue
|
|
121
|
+
}
|
|
122
|
+
// A short option's value attached to its flag (`-c2`, `-n10`, `-oL`).
|
|
123
|
+
if (!w.value.startsWith('--') && w.value.length > 2 && withArg.has(w.value.slice(0, 2))) {
|
|
124
|
+
i += 1
|
|
125
|
+
continue
|
|
126
|
+
}
|
|
127
|
+
if (/^--?[A-Za-z]/.test(w.value)) {
|
|
128
|
+
return { unknown: `an option this does not read: ${w.value}` }
|
|
129
|
+
}
|
|
130
|
+
return justRest(words.slice(i))
|
|
131
|
+
}
|
|
132
|
+
return { none: true }
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Skip leading `NAME=value` words, collecting each name (no judgement about which one — that is `program.ts`'s business). */
|
|
136
|
+
function skipAssignmentWords(words: readonly ShellWord[]): WrapperStep {
|
|
137
|
+
let i = 0
|
|
138
|
+
const assignments: string[] = []
|
|
139
|
+
while (i < words.length) {
|
|
140
|
+
const w = words[i] as ShellWord
|
|
141
|
+
if (!LITERAL(w)) return { rest: words.slice(i), assignments }
|
|
142
|
+
const name = assignmentName(w)
|
|
143
|
+
if (name === null) return { rest: words.slice(i), assignments }
|
|
144
|
+
assignments.push(name)
|
|
145
|
+
i += 1
|
|
146
|
+
}
|
|
147
|
+
return { none: true }
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** `env [-i] [-0] [-u NAME]… [-C dir] [NAME=value]… [program [args]]`. */
|
|
151
|
+
function unwrapEnv(words: readonly ShellWord[]): WrapperStep {
|
|
152
|
+
let i = 0
|
|
153
|
+
const assignments: string[] = []
|
|
154
|
+
for (;;) {
|
|
155
|
+
const w = words[i]
|
|
156
|
+
if (w === undefined) return { none: true }
|
|
157
|
+
if (!LITERAL(w)) return { rest: words.slice(i), assignments }
|
|
158
|
+
if (w.value === '--') return { rest: words.slice(i + 1), assignments }
|
|
159
|
+
if (w.value === '-i' || w.value === '-0' || w.value === '--ignore-environment') {
|
|
160
|
+
i += 1
|
|
161
|
+
continue
|
|
162
|
+
}
|
|
163
|
+
if (w.value === '-u' || w.value === '-C' || w.value === '--unset' || w.value === '--chdir') {
|
|
164
|
+
i += 2
|
|
165
|
+
continue
|
|
166
|
+
}
|
|
167
|
+
if (/^--(?:unset|chdir)=/.test(w.value)) {
|
|
168
|
+
i += 1
|
|
169
|
+
continue
|
|
170
|
+
}
|
|
171
|
+
const name = assignmentName(w)
|
|
172
|
+
if (name !== null) {
|
|
173
|
+
assignments.push(name)
|
|
174
|
+
i += 1
|
|
175
|
+
continue
|
|
176
|
+
}
|
|
177
|
+
if (/^--?[A-Za-z]/.test(w.value)) return { unknown: `an option this does not read: ${w.value}` }
|
|
178
|
+
return { rest: words.slice(i), assignments }
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* One level of a re-exec wrapper's own name and options, or `null` when
|
|
184
|
+
* `words[0]` does not name one this reads. `words` is already known
|
|
185
|
+
* literal and non-empty by the caller.
|
|
186
|
+
*/
|
|
187
|
+
export function skipOneReexecWrapper(words: readonly ShellWord[]): WrapperStep | null {
|
|
188
|
+
const head = words[0] as ShellWord
|
|
189
|
+
const name = basename(head.value)
|
|
190
|
+
const rest = words.slice(1)
|
|
191
|
+
switch (name) {
|
|
192
|
+
case 'env':
|
|
193
|
+
return unwrapEnv(rest)
|
|
194
|
+
case 'sudo': {
|
|
195
|
+
const skipped = skipOptions(
|
|
196
|
+
rest,
|
|
197
|
+
new Set(['-A', '-b', '-E', '-H', '-k', '-K', '-n', '-P', '-S', '-v']),
|
|
198
|
+
new Set(['-g', '-h', '-p', '-u', '-U', '--group', '--host', '--user']),
|
|
199
|
+
new Map([
|
|
200
|
+
['-i', 'sudo -i runs a runtime-chosen login shell, not a named program'],
|
|
201
|
+
['--login', 'sudo --login runs a runtime-chosen login shell, not a named program'],
|
|
202
|
+
['-s', 'sudo -s runs a runtime-chosen shell, not a named program'],
|
|
203
|
+
['--shell', 'sudo --shell runs a runtime-chosen shell, not a named program'],
|
|
204
|
+
['-e', 'sudo -e (sudoedit) opens a runtime-chosen editor, not a named program'],
|
|
205
|
+
['--edit', 'sudo --edit (sudoedit) opens a runtime-chosen editor, not a named program'],
|
|
206
|
+
]),
|
|
207
|
+
)
|
|
208
|
+
if ('unknown' in skipped) return skipped
|
|
209
|
+
// A `sudo NAME=value…` pair sets an environment variable for the
|
|
210
|
+
// sudo'd command only, same as `env`'s.
|
|
211
|
+
return skipAssignmentWords('none' in skipped ? [] : skipped.rest)
|
|
212
|
+
}
|
|
213
|
+
case 'sudoedit':
|
|
214
|
+
return { unknown: 'sudoedit always opens a runtime-chosen editor, not a named program' }
|
|
215
|
+
case 'doas':
|
|
216
|
+
return skipOptions(rest, new Set(['-n']), new Set(['-C', '-u']))
|
|
217
|
+
case 'pkexec':
|
|
218
|
+
return skipOptions(rest, new Set(['--disable-internal-agent']), new Set(['--user']))
|
|
219
|
+
case 'nice': {
|
|
220
|
+
const first = rest[0]
|
|
221
|
+
if (first !== undefined && LITERAL(first) && /^-\d+$/.test(first.value)) {
|
|
222
|
+
return justRest(rest.slice(1))
|
|
223
|
+
}
|
|
224
|
+
return skipOptions(rest, new Set([]), new Set(['-n', '--adjustment']))
|
|
225
|
+
}
|
|
226
|
+
case 'ionice': {
|
|
227
|
+
const skipped = skipOptions(rest, new Set(['-t']), new Set(['-c', '-n']))
|
|
228
|
+
if (rest.some((w) => LITERAL(w) && w.value === '-p')) return { none: true }
|
|
229
|
+
return skipped
|
|
230
|
+
}
|
|
231
|
+
case 'nohup':
|
|
232
|
+
return skipOptions(rest, new Set([]), new Set([]))
|
|
233
|
+
case 'setsid':
|
|
234
|
+
return skipOptions(rest, new Set(['-w', '-c', '-f']), new Set([]))
|
|
235
|
+
case 'timeout': {
|
|
236
|
+
const skipped = skipOptions(
|
|
237
|
+
rest,
|
|
238
|
+
new Set(['--preserve-status', '--foreground', '-v', '--verbose']),
|
|
239
|
+
new Set(['-s', '-k', '--signal', '--kill-after']),
|
|
240
|
+
)
|
|
241
|
+
if ('rest' in skipped) {
|
|
242
|
+
const duration = skipped.rest[0]
|
|
243
|
+
if (duration === undefined) return { none: true }
|
|
244
|
+
return justRest(skipped.rest.slice(1))
|
|
245
|
+
}
|
|
246
|
+
return skipped
|
|
247
|
+
}
|
|
248
|
+
case 'stdbuf':
|
|
249
|
+
return skipOptions(
|
|
250
|
+
rest,
|
|
251
|
+
new Set([]),
|
|
252
|
+
new Set(['-i', '-o', '-e', '--input', '--output', '--error']),
|
|
253
|
+
)
|
|
254
|
+
case 'chrt': {
|
|
255
|
+
if (rest.some((w) => LITERAL(w) && (w.value === '-p' || w.value === '-m')))
|
|
256
|
+
return { none: true }
|
|
257
|
+
const skipped = skipOptions(
|
|
258
|
+
rest,
|
|
259
|
+
new Set(['-b', '-d', '-f', '-i', '-o', '-r', '-a', '-v', '--all-tasks', '--verbose']),
|
|
260
|
+
new Set([]),
|
|
261
|
+
)
|
|
262
|
+
if ('rest' in skipped) {
|
|
263
|
+
const priority = skipped.rest[0]
|
|
264
|
+
if (priority === undefined) return { none: true }
|
|
265
|
+
return justRest(skipped.rest.slice(1))
|
|
266
|
+
}
|
|
267
|
+
return skipped
|
|
268
|
+
}
|
|
269
|
+
case 'taskset': {
|
|
270
|
+
if (rest.some((w) => LITERAL(w) && w.value === '-p')) return { none: true }
|
|
271
|
+
const skipped = skipOptions(
|
|
272
|
+
rest,
|
|
273
|
+
new Set(['-a', '--all-tasks']),
|
|
274
|
+
new Set(['-c', '--cpu-list']),
|
|
275
|
+
)
|
|
276
|
+
if ('rest' in skipped) {
|
|
277
|
+
const usedCpuList = rest.some(
|
|
278
|
+
(w) =>
|
|
279
|
+
LITERAL(w) &&
|
|
280
|
+
(w.value === '-c' ||
|
|
281
|
+
w.value === '--cpu-list' ||
|
|
282
|
+
w.value.startsWith('--cpu-list=') ||
|
|
283
|
+
(w.value.startsWith('-c') && !w.value.startsWith('--') && w.value.length > 2)),
|
|
284
|
+
)
|
|
285
|
+
if (usedCpuList) return skipped
|
|
286
|
+
const mask = skipped.rest[0]
|
|
287
|
+
if (mask === undefined) return { none: true }
|
|
288
|
+
return justRest(skipped.rest.slice(1))
|
|
289
|
+
}
|
|
290
|
+
return skipped
|
|
291
|
+
}
|
|
292
|
+
case 'time':
|
|
293
|
+
return skipOptions(rest, new Set(['-p', '--portability']), new Set([]))
|
|
294
|
+
case 'command': {
|
|
295
|
+
if (rest.some((w) => LITERAL(w) && (w.value === '-v' || w.value === '-V')))
|
|
296
|
+
return { none: true }
|
|
297
|
+
return skipOptions(rest, new Set(['-p']), new Set([]))
|
|
298
|
+
}
|
|
299
|
+
case 'builtin':
|
|
300
|
+
return justRest(rest)
|
|
301
|
+
case 'exec':
|
|
302
|
+
return skipOptions(rest, new Set(['-c', '-l']), new Set(['-a']))
|
|
303
|
+
case 'busybox':
|
|
304
|
+
case 'toybox':
|
|
305
|
+
// A multi-call binary: the next word names the applet to run.
|
|
306
|
+
return justRest(rest)
|
|
307
|
+
case 'unshare':
|
|
308
|
+
return skipOptions(
|
|
309
|
+
rest,
|
|
310
|
+
new Set([
|
|
311
|
+
'-i',
|
|
312
|
+
'--ipc',
|
|
313
|
+
'-m',
|
|
314
|
+
'--mount',
|
|
315
|
+
'-n',
|
|
316
|
+
'--net',
|
|
317
|
+
'-p',
|
|
318
|
+
'--pid',
|
|
319
|
+
'-u',
|
|
320
|
+
'--uts',
|
|
321
|
+
'-U',
|
|
322
|
+
'--user',
|
|
323
|
+
'-C',
|
|
324
|
+
'--cgroup',
|
|
325
|
+
'-T',
|
|
326
|
+
'--time',
|
|
327
|
+
'-f',
|
|
328
|
+
'--fork',
|
|
329
|
+
'-r',
|
|
330
|
+
'--map-root-user',
|
|
331
|
+
'-c',
|
|
332
|
+
'--map-current-user',
|
|
333
|
+
'--mount-proc',
|
|
334
|
+
]),
|
|
335
|
+
new Set([
|
|
336
|
+
'-R',
|
|
337
|
+
'--root',
|
|
338
|
+
'-w',
|
|
339
|
+
'--wd',
|
|
340
|
+
'-S',
|
|
341
|
+
'--setuid',
|
|
342
|
+
'-G',
|
|
343
|
+
'--setgid',
|
|
344
|
+
'-s',
|
|
345
|
+
'--setgroups',
|
|
346
|
+
'--propagation',
|
|
347
|
+
]),
|
|
348
|
+
)
|
|
349
|
+
case 'nsenter':
|
|
350
|
+
return skipOptions(
|
|
351
|
+
rest,
|
|
352
|
+
new Set([
|
|
353
|
+
'-m',
|
|
354
|
+
'--mount',
|
|
355
|
+
'-u',
|
|
356
|
+
'--uts',
|
|
357
|
+
'-i',
|
|
358
|
+
'--ipc',
|
|
359
|
+
'-n',
|
|
360
|
+
'--net',
|
|
361
|
+
'-p',
|
|
362
|
+
'--pid',
|
|
363
|
+
'-C',
|
|
364
|
+
'--cgroup',
|
|
365
|
+
'-U',
|
|
366
|
+
'--user',
|
|
367
|
+
'-T',
|
|
368
|
+
'--time',
|
|
369
|
+
'--preserve-credentials',
|
|
370
|
+
'-r',
|
|
371
|
+
'--root',
|
|
372
|
+
'-w',
|
|
373
|
+
'--wd',
|
|
374
|
+
'-F',
|
|
375
|
+
'--no-fork',
|
|
376
|
+
'-Z',
|
|
377
|
+
'--follow-context',
|
|
378
|
+
]),
|
|
379
|
+
new Set(['-t', '--target', '-S', '--setuid', '-G', '--setgid']),
|
|
380
|
+
)
|
|
381
|
+
case 'chroot': {
|
|
382
|
+
const skipped = skipOptions(
|
|
383
|
+
rest,
|
|
384
|
+
new Set(['--skip-chdir']),
|
|
385
|
+
new Set(['--groups', '--userspec']),
|
|
386
|
+
)
|
|
387
|
+
if ('unknown' in skipped) return skipped
|
|
388
|
+
const afterOptions = 'none' in skipped ? [] : skipped.rest
|
|
389
|
+
const newroot = afterOptions[0]
|
|
390
|
+
if (newroot === undefined) return { none: true }
|
|
391
|
+
const remaining = afterOptions.slice(1)
|
|
392
|
+
return remaining.length === 0
|
|
393
|
+
? { unknown: 'chroot without a command runs an interactive shell, not a named program' }
|
|
394
|
+
: justRest(remaining)
|
|
395
|
+
}
|
|
396
|
+
case 'setpriv':
|
|
397
|
+
return skipOptions(
|
|
398
|
+
rest,
|
|
399
|
+
new Set([
|
|
400
|
+
'--clear-groups',
|
|
401
|
+
'--keep-groups',
|
|
402
|
+
'--no-new-privs',
|
|
403
|
+
'--reset-env',
|
|
404
|
+
'-d',
|
|
405
|
+
'--dump',
|
|
406
|
+
]),
|
|
407
|
+
new Set([
|
|
408
|
+
'--inh-caps',
|
|
409
|
+
'--ambient-caps',
|
|
410
|
+
'--bounding-set',
|
|
411
|
+
'--groups',
|
|
412
|
+
'--pdeathsig',
|
|
413
|
+
'--securebits',
|
|
414
|
+
'--reuid',
|
|
415
|
+
'--ruid',
|
|
416
|
+
'--regid',
|
|
417
|
+
'--rgid',
|
|
418
|
+
'--selinux-label',
|
|
419
|
+
'--apparmor-profile',
|
|
420
|
+
]),
|
|
421
|
+
)
|
|
422
|
+
case 'prlimit': {
|
|
423
|
+
if (rest.some((w) => LITERAL(w) && (w.value === '-p' || w.value === '--pid')))
|
|
424
|
+
return { none: true }
|
|
425
|
+
const resources = [
|
|
426
|
+
'--as',
|
|
427
|
+
'--core',
|
|
428
|
+
'--cpu',
|
|
429
|
+
'--data',
|
|
430
|
+
'--fsize',
|
|
431
|
+
'--locks',
|
|
432
|
+
'--memlock',
|
|
433
|
+
'--msgqueue',
|
|
434
|
+
'--nice',
|
|
435
|
+
'--nofile',
|
|
436
|
+
'--nproc',
|
|
437
|
+
'--rss',
|
|
438
|
+
'--rtprio',
|
|
439
|
+
'--rttime',
|
|
440
|
+
'--sigpending',
|
|
441
|
+
'--stack',
|
|
442
|
+
]
|
|
443
|
+
return skipOptions(
|
|
444
|
+
rest,
|
|
445
|
+
new Set(['--noheadings', '--raw', '--verbose', ...resources]),
|
|
446
|
+
new Set(['-o', '--output', ...resources]),
|
|
447
|
+
)
|
|
448
|
+
}
|
|
449
|
+
case 'numactl': {
|
|
450
|
+
if (
|
|
451
|
+
rest.some(
|
|
452
|
+
(w) =>
|
|
453
|
+
LITERAL(w) &&
|
|
454
|
+
(w.value === '--show' ||
|
|
455
|
+
w.value === '--hardware' ||
|
|
456
|
+
w.value === '-s' ||
|
|
457
|
+
w.value === '-H'),
|
|
458
|
+
)
|
|
459
|
+
) {
|
|
460
|
+
return { none: true }
|
|
461
|
+
}
|
|
462
|
+
return skipOptions(
|
|
463
|
+
rest,
|
|
464
|
+
new Set(['--localalloc', '-l']),
|
|
465
|
+
new Set(['--interleave', '--membind', '--cpunodebind', '--physcpubind', '--preferred']),
|
|
466
|
+
)
|
|
467
|
+
}
|
|
468
|
+
default:
|
|
469
|
+
return null
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Every name {@link skipOneReexecWrapper} recognises — kept in sync BY HAND
|
|
475
|
+
* with its `switch`. A cheap pre-check for a caller (the parser's own
|
|
476
|
+
* `inspect()`) that wants to skip the more expensive chain-following for
|
|
477
|
+
* the overwhelming majority of simple commands that do not start with any
|
|
478
|
+
* of these.
|
|
479
|
+
*/
|
|
480
|
+
export const REEXEC_WRAPPER_NAMES: ReadonlySet<string> = new Set([
|
|
481
|
+
'env',
|
|
482
|
+
'sudo',
|
|
483
|
+
'sudoedit',
|
|
484
|
+
'doas',
|
|
485
|
+
'pkexec',
|
|
486
|
+
'nice',
|
|
487
|
+
'ionice',
|
|
488
|
+
'nohup',
|
|
489
|
+
'setsid',
|
|
490
|
+
'timeout',
|
|
491
|
+
'stdbuf',
|
|
492
|
+
'chrt',
|
|
493
|
+
'taskset',
|
|
494
|
+
'time',
|
|
495
|
+
'command',
|
|
496
|
+
'builtin',
|
|
497
|
+
'exec',
|
|
498
|
+
'busybox',
|
|
499
|
+
'toybox',
|
|
500
|
+
'unshare',
|
|
501
|
+
'nsenter',
|
|
502
|
+
'chroot',
|
|
503
|
+
'setpriv',
|
|
504
|
+
'prlimit',
|
|
505
|
+
'numactl',
|
|
506
|
+
])
|
|
507
|
+
|
|
508
|
+
/** How many re-exec wrappers a chain unwraps before giving up (`sudo env nice … prog`). */
|
|
509
|
+
const MAX_WRAPPER_DEPTH = 8
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Follow a chain of re-exec wrappers all the way through: `words` with every
|
|
513
|
+
* layer `skipOneReexecWrapper` recognises peeled off, and every `NAME=value`
|
|
514
|
+
* pair skipped along the way, or why it could not be followed to the end.
|
|
515
|
+
* `{ none: true }` when a wrapper consumed everything (nothing left to be a
|
|
516
|
+
* program at all).
|
|
517
|
+
*/
|
|
518
|
+
export function unwrapReexecChain(words: readonly ShellWord[]): WrapperStep {
|
|
519
|
+
let current = words
|
|
520
|
+
const assignments: string[] = []
|
|
521
|
+
for (let depth = 0; depth < MAX_WRAPPER_DEPTH; depth += 1) {
|
|
522
|
+
const head = current[0]
|
|
523
|
+
if (head === undefined) return { none: true }
|
|
524
|
+
if (!LITERAL(head)) return { rest: current, assignments }
|
|
525
|
+
const step = skipOneReexecWrapper(current)
|
|
526
|
+
if (step === null) return { rest: current, assignments }
|
|
527
|
+
if ('unknown' in step) return step
|
|
528
|
+
if ('none' in step) return { none: true }
|
|
529
|
+
assignments.push(...step.assignments)
|
|
530
|
+
if (step.rest.length === 0) return { none: true }
|
|
531
|
+
current = step.rest
|
|
532
|
+
}
|
|
533
|
+
return { unknown: 'too many re-exec wrappers to follow' }
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/** Where a shell is directly named, or reached through one hop of busybox/toybox applet dispatch. */
|
|
537
|
+
export function shellInvocation(
|
|
538
|
+
words: readonly ShellWord[],
|
|
539
|
+
): { readonly shell: string; readonly rest: readonly ShellWord[] } | null {
|
|
540
|
+
const head = words[0]
|
|
541
|
+
if (head === undefined || !LITERAL(head)) return null
|
|
542
|
+
const name = basename(head.value)
|
|
543
|
+
if (PLAIN_SHELL_NAMES.has(name)) return { shell: name, rest: words.slice(1) }
|
|
544
|
+
if (name === 'busybox' || name === 'toybox') {
|
|
545
|
+
const applet = words[1]
|
|
546
|
+
if (applet !== undefined && LITERAL(applet) && PLAIN_SHELL_NAMES.has(basename(applet.value))) {
|
|
547
|
+
return { shell: basename(applet.value), rest: words.slice(2) }
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
return null
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* A shell's own `-c` among its other options (clustered short forms
|
|
555
|
+
* included, `-ec`, `-lc`), the argument right after it, or why none was
|
|
556
|
+
* found. This is exactly the scan `nestedShellCommand` used to run only for
|
|
557
|
+
* a literal head; factored out so a wrapped shell (`env -i bash -c "…"`,
|
|
558
|
+
* `nice -n 5 sh -ec "…"`) is read the identical way.
|
|
559
|
+
*/
|
|
560
|
+
export function shellDashC(
|
|
561
|
+
rest: readonly ShellWord[],
|
|
562
|
+
): { readonly payload: ShellWord } | { readonly none: true } | { readonly unknown: string } {
|
|
563
|
+
let command = false
|
|
564
|
+
let payload: ShellWord | undefined
|
|
565
|
+
for (let i = 0; i < rest.length; i += 1) {
|
|
566
|
+
const word = rest[i] as ShellWord
|
|
567
|
+
if (!LITERAL(word)) return { unknown: 'nested shell option' }
|
|
568
|
+
const value = word.value
|
|
569
|
+
if (value === '--' || value === '-') {
|
|
570
|
+
payload = rest[i + 1]
|
|
571
|
+
break
|
|
572
|
+
}
|
|
573
|
+
if (value.startsWith('--')) {
|
|
574
|
+
if (value === '--rcfile' || value === '--init-file') i += 1
|
|
575
|
+
continue
|
|
576
|
+
}
|
|
577
|
+
if (/^[-+][A-Za-z]+$/.test(value)) {
|
|
578
|
+
if (value.startsWith('-') && value.includes('c')) command = true
|
|
579
|
+
if (/[oO]$/.test(value)) i += 1
|
|
580
|
+
continue
|
|
581
|
+
}
|
|
582
|
+
payload = word
|
|
583
|
+
break
|
|
584
|
+
}
|
|
585
|
+
if (!command) return { none: true }
|
|
586
|
+
if (payload === undefined) return { unknown: 'nested shell without a command' }
|
|
587
|
+
if (!LITERAL(payload)) return { unknown: 'nested shell command is expanded at runtime' }
|
|
588
|
+
return { payload }
|
|
589
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { DANGEROUS_PATTERNS } from '../constants/tools/index.js'
|
|
2
2
|
import { isTrustedReadOnly } from '../tools/trusted-read-only.js'
|
|
3
|
+
import { matchesSourceIdGlob } from '../toolsets/source-glob.js'
|
|
4
|
+
import type { ToolSourceRef } from '../toolsets/types.js'
|
|
3
5
|
import type { AuthorizationRule, GateDecision } from '../types/authorization/index.js'
|
|
4
6
|
import type { ToolDefinition } from '../types/tool/index.js'
|
|
5
7
|
import { decodedCommands, decomposeCommandLine } from './command-line.js'
|
|
@@ -12,6 +14,14 @@ export interface EvaluateRuleOptions {
|
|
|
12
14
|
* opaque. `ToolDefinition.commandDialect` supplies it for a tool.
|
|
13
15
|
*/
|
|
14
16
|
readonly commandDialect?: ShellDialect
|
|
17
|
+
/**
|
|
18
|
+
* Where the tool named by this call came from, when the caller has a
|
|
19
|
+
* `ToolManager` to ask (`ToolManager.sourceOf`). `allow_read_only` reads
|
|
20
|
+
* this to decide whether an MCP server's own `readOnlyHint` is trusted;
|
|
21
|
+
* absent, `isTrustedReadOnly` treats the tool as host-defined, matching a
|
|
22
|
+
* caller with no manager to ask.
|
|
23
|
+
*/
|
|
24
|
+
readonly toolSource?: ToolSourceRef
|
|
15
25
|
}
|
|
16
26
|
|
|
17
27
|
export function evaluateRule(
|
|
@@ -31,7 +41,7 @@ export function evaluateRule(
|
|
|
31
41
|
// A server's own claim about its own tool cannot settle this. See
|
|
32
42
|
// `isTrustedReadOnly`: a self-declaration may raise the requirement
|
|
33
43
|
// and never lower it.
|
|
34
|
-
if (!isTrustedReadOnly(toolDef, toolInput)) return null
|
|
44
|
+
if (!isTrustedReadOnly(toolDef, toolInput, options.toolSource)) return null
|
|
35
45
|
|
|
36
46
|
// Read-only is a claim about the DATA a call returns, not about the
|
|
37
47
|
// CHANNEL it travels over. A tool can be `readOnlyHint: true` AND
|
|
@@ -80,6 +90,13 @@ export function evaluateRule(
|
|
|
80
90
|
return nameSet?.has(toolName) ? 'deny' : null
|
|
81
91
|
}
|
|
82
92
|
|
|
93
|
+
case 'by_source': {
|
|
94
|
+
const source = options.toolSource
|
|
95
|
+
return source !== undefined && rule.sources.some((id) => matchesSourceIdGlob(source.id, id))
|
|
96
|
+
? rule.decision
|
|
97
|
+
: null
|
|
98
|
+
}
|
|
99
|
+
|
|
83
100
|
case 'custom_pattern': {
|
|
84
101
|
if (!compiledPattern) return null
|
|
85
102
|
|