@namzu/sdk 45.1.0 → 48.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 +436 -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 +13 -2
- package/dist/authorization/gate.d.ts.map +1 -1
- package/dist/authorization/gate.js +37 -5
- 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 +27 -1
- package/dist/authorization/rules.js.map +1 -1
- package/dist/authorization/shell-lexer.d.ts +39 -0
- package/dist/authorization/shell-lexer.d.ts.map +1 -1
- package/dist/authorization/shell-lexer.js +113 -69
- 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 +60 -4
- package/dist/connector/mcp/adapter.js.map +1 -1
- package/dist/connector/mcp/client.d.ts +13 -4
- package/dist/connector/mcp/client.d.ts.map +1 -1
- package/dist/connector/mcp/client.js +20 -3
- 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/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/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.map +1 -1
- package/dist/manager/agent/lifecycle.js +9 -0
- 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/learning-observation.d.ts +4 -4
- package/dist/manager/resident/learning.d.ts +36 -36
- 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/pricing/catalogue.generated.d.ts.map +1 -1
- package/dist/pricing/catalogue.generated.js +28 -4
- package/dist/pricing/catalogue.generated.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 +27 -14
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +49 -11
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +9 -6
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +13 -5
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +16 -5
- 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 +22 -0
- package/dist/registry/tool/callable.d.ts.map +1 -0
- package/dist/registry/tool/callable.js +28 -0
- package/dist/registry/tool/callable.js.map +1 -0
- 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 -720
- 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 +82 -13
- package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.js +227 -17
- package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +37 -5
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +103 -14
- 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 +65 -3
- package/dist/runtime/query/review-policy.d.ts.map +1 -1
- package/dist/runtime/query/review-policy.js +143 -22
- 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/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 +18 -0
- package/dist/skills/registry.d.ts.map +1 -1
- package/dist/skills/registry.js +20 -0
- package/dist/skills/registry.js.map +1 -1
- package/dist/store/evidence/index-page.d.ts +2 -2
- 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/computer-use-coordinates.d.ts +65 -0
- package/dist/tools/builtins/computer-use-coordinates.d.ts.map +1 -0
- package/dist/tools/builtins/computer-use-coordinates.js +123 -0
- package/dist/tools/builtins/computer-use-coordinates.js.map +1 -0
- package/dist/tools/builtins/computer-use-image.d.ts +77 -0
- package/dist/tools/builtins/computer-use-image.d.ts.map +1 -0
- package/dist/tools/builtins/computer-use-image.js +223 -0
- package/dist/tools/builtins/computer-use-image.js.map +1 -0
- package/dist/tools/builtins/computer-use.d.ts +519 -14
- package/dist/tools/builtins/computer-use.d.ts.map +1 -1
- package/dist/tools/builtins/computer-use.js +1196 -183
- 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/index.d.ts +2 -1
- package/dist/tools/builtins/index.d.ts.map +1 -1
- package/dist/tools/builtins/index.js +1 -1
- package/dist/tools/builtins/index.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/skill.d.ts +74 -0
- package/dist/tools/builtins/skill.d.ts.map +1 -1
- package/dist/tools/builtins/skill.js +214 -174
- package/dist/tools/builtins/skill.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 +12 -0
- package/dist/tools/defineTool.d.ts.map +1 -1
- package/dist/tools/defineTool.js +24 -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/present.d.ts.map +1 -1
- package/dist/tools/schedules/present.js +2 -0
- package/dist/tools/schedules/present.js.map +1 -1
- package/dist/tools/schedules/schedule-tool.d.ts +6 -5
- package/dist/tools/schedules/schedule-tool.d.ts.map +1 -1
- package/dist/tools/schedules/schedule-tool.js +208 -37
- package/dist/tools/schedules/schedule-tool.js.map +1 -1
- package/dist/tools/schedules/types.d.ts +120 -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/supervisor.d.ts +5 -2
- package/dist/types/agent/supervisor.d.ts.map +1 -1
- package/dist/types/authorization/index.d.ts +70 -12
- package/dist/types/authorization/index.d.ts.map +1 -1
- package/dist/types/authorization/index.js +11 -0
- package/dist/types/authorization/index.js.map +1 -1
- package/dist/types/computer-use/index.d.ts +176 -0
- package/dist/types/computer-use/index.d.ts.map +1 -1
- package/dist/types/computer-use/index.js.map +1 -1
- package/dist/types/connector/mcp.d.ts +32 -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/tool/index.d.ts +171 -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 +3 -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 +46 -5
- package/src/authorization/program.ts +773 -0
- package/src/authorization/reexec-wrapper.ts +589 -0
- package/src/authorization/rules.ts +36 -1
- package/src/authorization/shell-lexer.ts +136 -63
- 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 +58 -3
- package/src/connector/mcp/client.ts +20 -4
- package/src/connector/mcp/discovery.ts +60 -0
- package/src/connector/mcp/index.ts +13 -0
- package/src/connector/mcp/mcp-toolset.ts +515 -0
- 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 +9 -0
- 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/pricing/catalogue.generated.ts +28 -4
- package/src/pricing/rates.source.json +27 -6
- 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 +152 -9
- package/src/public-tools.ts +43 -5
- package/src/public-types.ts +65 -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 +36 -0
- package/src/registry/tool/execute.ts +16 -839
- 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 +288 -22
- package/src/runtime/query/executor.ts +129 -16
- 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 +190 -24
- 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/skills/index.ts +1 -1
- package/src/skills/registry.ts +33 -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/computer-use-coordinates.ts +144 -0
- package/src/tools/builtins/computer-use-image.ts +278 -0
- package/src/tools/builtins/computer-use.ts +1495 -191
- package/src/tools/builtins/edit.ts +12 -2
- package/src/tools/builtins/index.ts +7 -1
- package/src/tools/builtins/json-string-hint.ts +16 -0
- package/src/tools/builtins/search-tools.ts +7 -20
- package/src/tools/builtins/skill.ts +304 -174
- 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 +38 -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/present.ts +2 -0
- package/src/tools/schedules/schedule-tool.ts +238 -39
- package/src/tools/schedules/types.ts +120 -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/supervisor.ts +5 -2
- package/src/types/authorization/index.ts +33 -0
- package/src/types/computer-use/index.ts +202 -0
- package/src/types/connector/mcp.ts +32 -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/tool/index.ts +173 -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,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-session peer messaging: the live-session registry, the
|
|
3
|
+
* `namzu-peer/1` transport, and the runtime-context rendering for a
|
|
4
|
+
* delivered message or notice (design "Sessions that talk", Part 1, §1.1-1.3,
|
|
5
|
+
* §1.7, and the SDK half of §1.4/§1.8, 2026-09-24).
|
|
6
|
+
*
|
|
7
|
+
* This module is the transport and storage layer only. Inbox policy —
|
|
8
|
+
* bounded queues, the mode-mismatch hold/approve flow, `/peers off`,
|
|
9
|
+
* subscriber bookkeeping and its 24h expiry, and drain-at-iteration-boundary
|
|
10
|
+
* injection — is host (CLI) territory and is not implemented here.
|
|
11
|
+
*
|
|
12
|
+
* @experimental
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export { parsePeerAddress, pipePeerAddress, PeerAddressError, udsPeerAddress } from './address.js'
|
|
16
|
+
export type { PeerAddress } from './address.js'
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
hardenPeerRuntimeDir,
|
|
20
|
+
LONGEST_PEER_SOCKET_FILE_NAME_LENGTH,
|
|
21
|
+
PeerDirectoryError,
|
|
22
|
+
peerSocketFileName,
|
|
23
|
+
resolvePeerRuntimeDir,
|
|
24
|
+
} from './dir.js'
|
|
25
|
+
export type { HardenPeerDirectory, PeerRuntimeDir, ResolvePeerRuntimeDirOptions } from './dir.js'
|
|
26
|
+
|
|
27
|
+
export { derivePeerRef, PEER_RECORD_VERSION, PeerRecordSchema } from './record.js'
|
|
28
|
+
export type { PeerRecord } from './record.js'
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
isPeerRecordLive,
|
|
32
|
+
listLivePeers,
|
|
33
|
+
PeerRegistryError,
|
|
34
|
+
readPeerRecord,
|
|
35
|
+
readPeerRecords,
|
|
36
|
+
removePeerRecord,
|
|
37
|
+
writePeerRecord,
|
|
38
|
+
} from './registry.js'
|
|
39
|
+
export type { ListLivePeersOptions, PeerLivenessOptions } from './registry.js'
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
DEFAULT_PEER_READ_DEADLINE_MS,
|
|
43
|
+
DeliverRequestSchema,
|
|
44
|
+
DeliverResponseSchema,
|
|
45
|
+
DeliverStatusSchema,
|
|
46
|
+
MAX_PEER_CONNECTIONS,
|
|
47
|
+
MAX_PEER_MESSAGE_TEXT_BYTES,
|
|
48
|
+
MAX_PEER_REQUEST_BYTES,
|
|
49
|
+
NoticeRequestSchema,
|
|
50
|
+
NoticeResponseSchema,
|
|
51
|
+
PEER_PROTOCOL_VERSION,
|
|
52
|
+
PeerFromSchema,
|
|
53
|
+
PeerNoticeAboutSchema,
|
|
54
|
+
PeerNoticePayloadSchema,
|
|
55
|
+
PeerRefSchema,
|
|
56
|
+
PeerRequestSchema,
|
|
57
|
+
PeerSessionKindSchema,
|
|
58
|
+
PeerSessionStateSchema,
|
|
59
|
+
PingRequestSchema,
|
|
60
|
+
PingResponseSchema,
|
|
61
|
+
SubscribeIdleRequestSchema,
|
|
62
|
+
SubscribeIdleResponseSchema,
|
|
63
|
+
} from './protocol.js'
|
|
64
|
+
export type {
|
|
65
|
+
DeliverRequest,
|
|
66
|
+
DeliverResponse,
|
|
67
|
+
DeliverStatus,
|
|
68
|
+
NoticeRequest,
|
|
69
|
+
NoticeResponse,
|
|
70
|
+
PeerFrom,
|
|
71
|
+
PeerNoticeAbout,
|
|
72
|
+
PeerNoticePayload,
|
|
73
|
+
PeerRequest,
|
|
74
|
+
PeerResponse,
|
|
75
|
+
PeerSessionKind,
|
|
76
|
+
PeerSessionState,
|
|
77
|
+
PingRequest,
|
|
78
|
+
PingResponse,
|
|
79
|
+
SubscribeIdleRequest,
|
|
80
|
+
SubscribeIdleResponse,
|
|
81
|
+
} from './protocol.js'
|
|
82
|
+
|
|
83
|
+
export {
|
|
84
|
+
createPeerEndpoint,
|
|
85
|
+
MAX_OUTSTANDING_PEERS,
|
|
86
|
+
MAX_OUTSTANDING_PER_PEER,
|
|
87
|
+
OUTSTANDING_EXPIRY_MS,
|
|
88
|
+
PeerEndpointError,
|
|
89
|
+
} from './endpoint.js'
|
|
90
|
+
export type { CreatePeerEndpointOptions, PeerEndpoint } from './endpoint.js'
|
|
91
|
+
|
|
92
|
+
export { PeerClient, PeerClientError, pingPeer } from './client.js'
|
|
93
|
+
export type { PeerClientOptions, PeerClientResult } from './client.js'
|
|
94
|
+
|
|
95
|
+
export { formatPeerMessage, formatPeerNotice } from './envelope.js'
|
|
96
|
+
export type { PeerMessageEnvelopeInput } from './envelope.js'
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `namzu-peer/1` wire protocol: newline-delimited JSON, one request and
|
|
3
|
+
* one response per connection, a closed set of four operations (design
|
|
4
|
+
* §1.1, §1.3).
|
|
5
|
+
*
|
|
6
|
+
* Two deliberate departures from the design note, both narrow and both
|
|
7
|
+
* documented where they matter most:
|
|
8
|
+
*
|
|
9
|
+
* 1. **`ping` carries no token.** Every other op requires and verifies the
|
|
10
|
+
* recipient's token; `ping` is idempotent, has no side effect, and its
|
|
11
|
+
* answer (`{ok, state}`) discloses nothing the OS-user directory
|
|
12
|
+
* permission does not already gate (design §1.1: "the directory
|
|
13
|
+
* permission is the real gate"). `PeerClient.ping(address)` — the shape
|
|
14
|
+
* the spec's own client API names — takes no record and so has no token
|
|
15
|
+
* to send.
|
|
16
|
+
* 2. **`notice`'s `delivery` kind carries an optional `outcome`.** The design
|
|
17
|
+
* lists `notice`'s payload as `{kind, about, detail?}` with prose detail
|
|
18
|
+
* ("approved" / "denied" / "expired") for a delivery outcome, but gives
|
|
19
|
+
* `formatSystemEvent` a closed status set that a delivery notice must
|
|
20
|
+
* report from (`queued` | `held` | `refused`). `outcome` supplies that
|
|
21
|
+
* machine-readable status without parsing `detail`'s prose.
|
|
22
|
+
*
|
|
23
|
+
* @experimental
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { z } from 'zod'
|
|
27
|
+
|
|
28
|
+
export const PEER_PROTOCOL_VERSION = 'namzu-peer/1'
|
|
29
|
+
|
|
30
|
+
/** One request line, or one response line, must not exceed this many bytes. */
|
|
31
|
+
export const MAX_PEER_REQUEST_BYTES = 64 * 1024
|
|
32
|
+
/** `deliver.text` must not exceed this many UTF-8 bytes. */
|
|
33
|
+
export const MAX_PEER_MESSAGE_TEXT_BYTES = 32 * 1024
|
|
34
|
+
/** A connection that has not completed one request/response by this deadline is dropped. */
|
|
35
|
+
export const DEFAULT_PEER_READ_DEADLINE_MS = 2_000
|
|
36
|
+
/** Concurrent connections a `createPeerEndpoint` server accepts before refusing new ones. */
|
|
37
|
+
export const MAX_PEER_CONNECTIONS = 16
|
|
38
|
+
|
|
39
|
+
export const PeerSessionKindSchema = z.enum(['tui', 'exec', 'resident', 'scheduled'])
|
|
40
|
+
export type PeerSessionKind = z.infer<typeof PeerSessionKindSchema>
|
|
41
|
+
|
|
42
|
+
export const PeerSessionStateSchema = z.enum(['busy', 'idle', 'awaiting-permission'])
|
|
43
|
+
export type PeerSessionState = z.infer<typeof PeerSessionStateSchema>
|
|
44
|
+
|
|
45
|
+
const REF_PATTERN = /^[0-9a-f]{6}$/
|
|
46
|
+
|
|
47
|
+
/** First 6 hex characters of `sha256(sessionId)` — see `registry.ts` `derivePeerRef`. */
|
|
48
|
+
export const PeerRefSchema = z.string().regex(REF_PATTERN, 'must be 6 lowercase hex characters')
|
|
49
|
+
|
|
50
|
+
function byteLimitedString(maxBytes: number, message: string) {
|
|
51
|
+
return z
|
|
52
|
+
.string()
|
|
53
|
+
.min(1)
|
|
54
|
+
.refine((value) => Buffer.byteLength(value, 'utf8') <= maxBytes, { message })
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The sender's asserted identity, checked by the recipient against its own registry (§1.3). */
|
|
58
|
+
export const PeerFromSchema = z
|
|
59
|
+
.object({
|
|
60
|
+
sessionId: z.string().min(1),
|
|
61
|
+
ref: PeerRefSchema,
|
|
62
|
+
name: z.string(),
|
|
63
|
+
address: z.string().min(1),
|
|
64
|
+
mode: z.string().min(1),
|
|
65
|
+
kind: PeerSessionKindSchema,
|
|
66
|
+
})
|
|
67
|
+
.strict()
|
|
68
|
+
export type PeerFrom = z.infer<typeof PeerFromSchema>
|
|
69
|
+
|
|
70
|
+
// ─── ping ──────────────────────────────────────────────────────────────────
|
|
71
|
+
|
|
72
|
+
export const PingRequestSchema = z
|
|
73
|
+
.object({
|
|
74
|
+
protocol: z.literal(PEER_PROTOCOL_VERSION),
|
|
75
|
+
op: z.literal('ping'),
|
|
76
|
+
})
|
|
77
|
+
.strict()
|
|
78
|
+
export type PingRequest = z.infer<typeof PingRequestSchema>
|
|
79
|
+
|
|
80
|
+
export const PingResponseSchema = z
|
|
81
|
+
.object({
|
|
82
|
+
ok: z.boolean(),
|
|
83
|
+
state: PeerSessionStateSchema,
|
|
84
|
+
})
|
|
85
|
+
.strict()
|
|
86
|
+
export type PingResponse = z.infer<typeof PingResponseSchema>
|
|
87
|
+
|
|
88
|
+
// ─── deliver ─────────────────────────────────────────────────────────────
|
|
89
|
+
|
|
90
|
+
export const DeliverRequestSchema = z
|
|
91
|
+
.object({
|
|
92
|
+
protocol: z.literal(PEER_PROTOCOL_VERSION),
|
|
93
|
+
op: z.literal('deliver'),
|
|
94
|
+
token: z.string().min(1),
|
|
95
|
+
id: z.string().min(1),
|
|
96
|
+
from: PeerFromSchema,
|
|
97
|
+
text: byteLimitedString(
|
|
98
|
+
MAX_PEER_MESSAGE_TEXT_BYTES,
|
|
99
|
+
`must be at most ${MAX_PEER_MESSAGE_TEXT_BYTES} UTF-8 bytes`,
|
|
100
|
+
),
|
|
101
|
+
inReplyTo: z.string().min(1).optional(),
|
|
102
|
+
subscribeIdle: z.boolean().optional(),
|
|
103
|
+
})
|
|
104
|
+
.strict()
|
|
105
|
+
export type DeliverRequest = z.infer<typeof DeliverRequestSchema>
|
|
106
|
+
|
|
107
|
+
export const DeliverStatusSchema = z.enum(['queued', 'held', 'refused'])
|
|
108
|
+
export type DeliverStatus = z.infer<typeof DeliverStatusSchema>
|
|
109
|
+
|
|
110
|
+
export const DeliverResponseSchema = z
|
|
111
|
+
.object({
|
|
112
|
+
status: DeliverStatusSchema,
|
|
113
|
+
reason: z.string().optional(),
|
|
114
|
+
})
|
|
115
|
+
.strict()
|
|
116
|
+
export type DeliverResponse = z.infer<typeof DeliverResponseSchema>
|
|
117
|
+
|
|
118
|
+
// ─── subscribe_idle ────────────────────────────────────────────────────────
|
|
119
|
+
|
|
120
|
+
export const SubscribeIdleRequestSchema = z
|
|
121
|
+
.object({
|
|
122
|
+
protocol: z.literal(PEER_PROTOCOL_VERSION),
|
|
123
|
+
op: z.literal('subscribe_idle'),
|
|
124
|
+
token: z.string().min(1),
|
|
125
|
+
id: z.string().min(1),
|
|
126
|
+
from: PeerFromSchema,
|
|
127
|
+
})
|
|
128
|
+
.strict()
|
|
129
|
+
export type SubscribeIdleRequest = z.infer<typeof SubscribeIdleRequestSchema>
|
|
130
|
+
|
|
131
|
+
export const SubscribeIdleResponseSchema = z
|
|
132
|
+
.object({
|
|
133
|
+
status: z.enum(['subscribed', 'refused']),
|
|
134
|
+
})
|
|
135
|
+
.strict()
|
|
136
|
+
export type SubscribeIdleResponse = z.infer<typeof SubscribeIdleResponseSchema>
|
|
137
|
+
|
|
138
|
+
// ─── notice ────────────────────────────────────────────────────────────────
|
|
139
|
+
|
|
140
|
+
export const PeerNoticeAboutSchema = z
|
|
141
|
+
.object({
|
|
142
|
+
sessionId: z.string().min(1),
|
|
143
|
+
name: z.string(),
|
|
144
|
+
ref: PeerRefSchema,
|
|
145
|
+
})
|
|
146
|
+
.strict()
|
|
147
|
+
export type PeerNoticeAbout = z.infer<typeof PeerNoticeAboutSchema>
|
|
148
|
+
|
|
149
|
+
export const NoticeRequestSchema = z
|
|
150
|
+
.object({
|
|
151
|
+
protocol: z.literal(PEER_PROTOCOL_VERSION),
|
|
152
|
+
op: z.literal('notice'),
|
|
153
|
+
token: z.string().min(1),
|
|
154
|
+
/**
|
|
155
|
+
* The sender's asserted identity, checked the same way `deliver` and
|
|
156
|
+
* `subscribe_idle` check theirs (§1.3): the recipient's endpoint runs it
|
|
157
|
+
* through `verifySender` before calling `onNotice`. A notice with no
|
|
158
|
+
* `from` — the shape this protocol shipped with first — is not a
|
|
159
|
+
* well-formed request at all, the same as a `deliver` with no `from`.
|
|
160
|
+
*/
|
|
161
|
+
from: PeerFromSchema,
|
|
162
|
+
kind: z.enum(['idle', 'exited', 'delivery']),
|
|
163
|
+
about: PeerNoticeAboutSchema,
|
|
164
|
+
/** Only meaningful, and only ever set, when `kind === 'delivery'`. */
|
|
165
|
+
outcome: DeliverStatusSchema.optional(),
|
|
166
|
+
detail: z.string().optional(),
|
|
167
|
+
})
|
|
168
|
+
.strict()
|
|
169
|
+
export type NoticeRequest = z.infer<typeof NoticeRequestSchema>
|
|
170
|
+
|
|
171
|
+
export const NoticeResponseSchema = z
|
|
172
|
+
.object({
|
|
173
|
+
ok: z.boolean(),
|
|
174
|
+
})
|
|
175
|
+
.strict()
|
|
176
|
+
export type NoticeResponse = z.infer<typeof NoticeResponseSchema>
|
|
177
|
+
|
|
178
|
+
/** The notice payload alone, with no envelope — what a host builds and what `formatPeerNotice` renders. */
|
|
179
|
+
export const PeerNoticePayloadSchema = NoticeRequestSchema.omit({
|
|
180
|
+
protocol: true,
|
|
181
|
+
op: true,
|
|
182
|
+
token: true,
|
|
183
|
+
})
|
|
184
|
+
export type PeerNoticePayload = z.infer<typeof PeerNoticePayloadSchema>
|
|
185
|
+
|
|
186
|
+
// ─── the closed op set ───────────────────────────────────────────────────
|
|
187
|
+
|
|
188
|
+
export const PeerRequestSchema = z.discriminatedUnion('op', [
|
|
189
|
+
PingRequestSchema,
|
|
190
|
+
DeliverRequestSchema,
|
|
191
|
+
SubscribeIdleRequestSchema,
|
|
192
|
+
NoticeRequestSchema,
|
|
193
|
+
])
|
|
194
|
+
export type PeerRequest = z.infer<typeof PeerRequestSchema>
|
|
195
|
+
|
|
196
|
+
export type PeerResponse = PingResponse | DeliverResponse | SubscribeIdleResponse | NoticeResponse
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The live-session registry record (design §1.2): one JSON file per
|
|
3
|
+
* participating session, written into a hardened runtime directory's
|
|
4
|
+
* `sessions/` subdirectory (`resolvePeerRuntimeDir`, `dir.ts`).
|
|
5
|
+
*
|
|
6
|
+
* Kept separate from `registry.ts` (which reads and writes these files) so
|
|
7
|
+
* `client.ts` can depend on the record SHAPE without depending on file I/O,
|
|
8
|
+
* and `registry.ts` can depend on `client.ts` (to ping a peer for liveness)
|
|
9
|
+
* without a cycle.
|
|
10
|
+
*
|
|
11
|
+
* @experimental
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { createHash } from 'node:crypto'
|
|
15
|
+
import { z } from 'zod'
|
|
16
|
+
import {
|
|
17
|
+
PEER_PROTOCOL_VERSION,
|
|
18
|
+
PeerRefSchema,
|
|
19
|
+
PeerSessionKindSchema,
|
|
20
|
+
PeerSessionStateSchema,
|
|
21
|
+
} from './protocol.js'
|
|
22
|
+
|
|
23
|
+
/** Bumped only if the on-disk record shape changes incompatibly. */
|
|
24
|
+
export const PEER_RECORD_VERSION = 1
|
|
25
|
+
|
|
26
|
+
export const PeerRecordSchema = z
|
|
27
|
+
.object({
|
|
28
|
+
v: z.literal(PEER_RECORD_VERSION),
|
|
29
|
+
sessionId: z.string().min(1),
|
|
30
|
+
/** First 6 hex characters of `sha256(sessionId)`; disambiguates a colliding display name. */
|
|
31
|
+
ref: PeerRefSchema,
|
|
32
|
+
pid: z.number().int().positive(),
|
|
33
|
+
startedAt: z.number().int().nonnegative(),
|
|
34
|
+
kind: PeerSessionKindSchema,
|
|
35
|
+
/** Absent until the operator or the host sets one; the display name then falls back (design §1.2). */
|
|
36
|
+
title: z.string().optional(),
|
|
37
|
+
cwd: z.string().min(1),
|
|
38
|
+
/** The host's own permission-mode vocabulary; the SDK does not constrain its spelling. */
|
|
39
|
+
permissionMode: z.string().min(1),
|
|
40
|
+
state: PeerSessionStateSchema,
|
|
41
|
+
acceptsMessages: z.boolean(),
|
|
42
|
+
address: z.string().min(1),
|
|
43
|
+
token: z.string().min(1),
|
|
44
|
+
protocol: z.literal(PEER_PROTOCOL_VERSION),
|
|
45
|
+
cliVersion: z.string(),
|
|
46
|
+
})
|
|
47
|
+
.strict()
|
|
48
|
+
|
|
49
|
+
export type PeerRecord = z.infer<typeof PeerRecordSchema>
|
|
50
|
+
|
|
51
|
+
const PEER_REF_HEX_LENGTH = 6
|
|
52
|
+
|
|
53
|
+
/** `ref`: the first 6 hex characters of `sha256(sessionId)`, for a short, stable, collision-resistant tag. */
|
|
54
|
+
export function derivePeerRef(sessionId: string): string {
|
|
55
|
+
return createHash('sha256').update(sessionId, 'utf8').digest('hex').slice(0, PEER_REF_HEX_LENGTH)
|
|
56
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The live-session registry: one JSON file per participating session under a
|
|
3
|
+
* hardened runtime directory's `sessions/` subdirectory (design §1.2).
|
|
4
|
+
*
|
|
5
|
+
* @experimental
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { randomBytes } from 'node:crypto'
|
|
9
|
+
import {
|
|
10
|
+
closeSync,
|
|
11
|
+
fsyncSync,
|
|
12
|
+
lstatSync,
|
|
13
|
+
openSync,
|
|
14
|
+
readFileSync,
|
|
15
|
+
readdirSync,
|
|
16
|
+
renameSync,
|
|
17
|
+
unlinkSync,
|
|
18
|
+
writeSync,
|
|
19
|
+
} from 'node:fs'
|
|
20
|
+
import { basename, dirname, join } from 'node:path'
|
|
21
|
+
import { parsePeerAddress } from './address.js'
|
|
22
|
+
import { pingPeer } from './client.js'
|
|
23
|
+
import { type PeerRecord, PeerRecordSchema } from './record.js'
|
|
24
|
+
|
|
25
|
+
const RECORD_FILE_MODE = 0o600
|
|
26
|
+
|
|
27
|
+
export class PeerRegistryError extends Error {
|
|
28
|
+
override readonly name = 'PeerRegistryError'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function recordPath(sessionsDir: string, sessionId: string): string {
|
|
32
|
+
return join(sessionsDir, `${sessionId}.json`)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function temporaryPathBeside(path: string): string {
|
|
36
|
+
return join(
|
|
37
|
+
dirname(path),
|
|
38
|
+
`.${basename(path)}.${process.pid}.${randomBytes(6).toString('hex')}.tmp`,
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Publish `record` at `<sessionsDir>/<sessionId>.json`: fsynced temporary, then rename, mode 0600. */
|
|
43
|
+
export function writePeerRecord(sessionsDir: string, record: PeerRecord): void {
|
|
44
|
+
const validated = PeerRecordSchema.safeParse(record)
|
|
45
|
+
if (!validated.success) {
|
|
46
|
+
throw new PeerRegistryError(`Invalid peer record: ${validated.error.message}`)
|
|
47
|
+
}
|
|
48
|
+
const parsed = validated.data
|
|
49
|
+
const path = recordPath(sessionsDir, parsed.sessionId)
|
|
50
|
+
const temporary = temporaryPathBeside(path)
|
|
51
|
+
const fd = openSync(temporary, 'wx', RECORD_FILE_MODE)
|
|
52
|
+
try {
|
|
53
|
+
writeSync(fd, `${JSON.stringify(parsed)}\n`)
|
|
54
|
+
fsyncSync(fd)
|
|
55
|
+
} finally {
|
|
56
|
+
closeSync(fd)
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
renameSync(temporary, path)
|
|
60
|
+
} catch (error) {
|
|
61
|
+
try {
|
|
62
|
+
unlinkSync(temporary)
|
|
63
|
+
} catch {
|
|
64
|
+
// The rename already failed; a leftover temporary file is not this
|
|
65
|
+
// call's failure to report.
|
|
66
|
+
}
|
|
67
|
+
throw error
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function parseRecordText(text: string): PeerRecord | undefined {
|
|
72
|
+
let parsed: unknown
|
|
73
|
+
try {
|
|
74
|
+
parsed = JSON.parse(text)
|
|
75
|
+
} catch {
|
|
76
|
+
return undefined
|
|
77
|
+
}
|
|
78
|
+
const result = PeerRecordSchema.safeParse(parsed)
|
|
79
|
+
return result.success ? result.data : undefined
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** One session's record, or `undefined` if it has none or its file does not parse. */
|
|
83
|
+
export function readPeerRecord(sessionsDir: string, sessionId: string): PeerRecord | undefined {
|
|
84
|
+
let text: string
|
|
85
|
+
try {
|
|
86
|
+
text = readFileSync(recordPath(sessionsDir, sessionId), 'utf8')
|
|
87
|
+
} catch (error) {
|
|
88
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return undefined
|
|
89
|
+
throw error
|
|
90
|
+
}
|
|
91
|
+
return parseRecordText(text)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Every registry record in `sessionsDir` that parses.
|
|
96
|
+
*
|
|
97
|
+
* A file that fails to parse (mid-write, truncated, from a newer namzu) is
|
|
98
|
+
* skipped rather than thrown on: one malformed record must not make every
|
|
99
|
+
* other live session invisible to `list_sessions`.
|
|
100
|
+
*/
|
|
101
|
+
export function readPeerRecords(sessionsDir: string): PeerRecord[] {
|
|
102
|
+
let entries: string[]
|
|
103
|
+
try {
|
|
104
|
+
entries = readdirSync(sessionsDir)
|
|
105
|
+
} catch (error) {
|
|
106
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return []
|
|
107
|
+
throw error
|
|
108
|
+
}
|
|
109
|
+
const records: PeerRecord[] = []
|
|
110
|
+
for (const entry of entries) {
|
|
111
|
+
if (!entry.endsWith('.json')) continue
|
|
112
|
+
let text: string
|
|
113
|
+
try {
|
|
114
|
+
text = readFileSync(join(sessionsDir, entry), 'utf8')
|
|
115
|
+
} catch {
|
|
116
|
+
continue // Vanished between readdir and read; not this reader's concern.
|
|
117
|
+
}
|
|
118
|
+
const record = parseRecordText(text)
|
|
119
|
+
if (record) records.push(record)
|
|
120
|
+
}
|
|
121
|
+
return records
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Remove a path only if it is owned by `uid`; `undefined` skips the check (tests, or a platform with no uid). */
|
|
125
|
+
function removeIfOwned(path: string, uid: number | undefined): void {
|
|
126
|
+
let entry: ReturnType<typeof lstatSync>
|
|
127
|
+
try {
|
|
128
|
+
entry = lstatSync(path)
|
|
129
|
+
} catch (error) {
|
|
130
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return
|
|
131
|
+
throw error
|
|
132
|
+
}
|
|
133
|
+
if (uid !== undefined && entry.uid !== uid) return
|
|
134
|
+
try {
|
|
135
|
+
unlinkSync(path)
|
|
136
|
+
} catch (error) {
|
|
137
|
+
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Remove a session's registry record. Owner-checked: never unlinks a path this uid does not own. */
|
|
142
|
+
export function removePeerRecord(
|
|
143
|
+
sessionsDir: string,
|
|
144
|
+
sessionId: string,
|
|
145
|
+
uid: number | undefined,
|
|
146
|
+
): void {
|
|
147
|
+
removeIfOwned(recordPath(sessionsDir, sessionId), uid)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Remove a stale UDS socket file, only when it is a socket owned by `uid`. A `pipe:`/`a2a:` address is left alone. */
|
|
151
|
+
function removeStaleSocketIfOwned(address: string, uid: number | undefined): void {
|
|
152
|
+
let parsed: ReturnType<typeof parsePeerAddress>
|
|
153
|
+
try {
|
|
154
|
+
parsed = parsePeerAddress(address)
|
|
155
|
+
} catch {
|
|
156
|
+
return
|
|
157
|
+
}
|
|
158
|
+
if (parsed.scheme !== 'uds') return
|
|
159
|
+
let entry: ReturnType<typeof lstatSync>
|
|
160
|
+
try {
|
|
161
|
+
entry = lstatSync(parsed.path)
|
|
162
|
+
} catch {
|
|
163
|
+
return
|
|
164
|
+
}
|
|
165
|
+
if (!entry.isSocket()) return
|
|
166
|
+
if (uid !== undefined && entry.uid !== uid) return
|
|
167
|
+
try {
|
|
168
|
+
unlinkSync(parsed.path)
|
|
169
|
+
} catch {
|
|
170
|
+
// Already gone, or another process just recreated it — either way there
|
|
171
|
+
// is nothing left for this cleanup pass to do.
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function defaultIsPidAlive(pid: number): boolean {
|
|
176
|
+
try {
|
|
177
|
+
process.kill(pid, 0)
|
|
178
|
+
return true
|
|
179
|
+
} catch (error) {
|
|
180
|
+
// EPERM means the process exists but is owned by someone else, which
|
|
181
|
+
// cannot happen for a uid-owned registry entry under normal operation;
|
|
182
|
+
// treated as alive because this check cannot disprove it either way.
|
|
183
|
+
return (error as NodeJS.ErrnoException).code === 'EPERM'
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface PeerLivenessOptions {
|
|
188
|
+
/** Default 500ms (design §1.2). */
|
|
189
|
+
readonly pingTimeoutMs?: number
|
|
190
|
+
/** Injectable for tests. Defaults to `process.kill(pid, 0)`. */
|
|
191
|
+
readonly isPidAlive?: (pid: number) => boolean
|
|
192
|
+
/** Injectable for tests. Defaults to an unauthenticated `ping` (`pingPeer` in `client.ts`). */
|
|
193
|
+
readonly ping?: (address: string, timeoutMs: number) => Promise<boolean>
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* A record is live iff its pid is alive AND its address answers a ping
|
|
198
|
+
* within the timeout (design §1.2). Shared by {@link listLivePeers} and by
|
|
199
|
+
* `createPeerEndpoint`'s default `verifySender` (`endpoint.ts`), so both
|
|
200
|
+
* apply exactly the same definition of "live".
|
|
201
|
+
*/
|
|
202
|
+
export async function isPeerRecordLive(
|
|
203
|
+
record: PeerRecord,
|
|
204
|
+
options: PeerLivenessOptions = {},
|
|
205
|
+
): Promise<boolean> {
|
|
206
|
+
const isPidAlive = options.isPidAlive ?? defaultIsPidAlive
|
|
207
|
+
const ping = options.ping ?? pingPeer
|
|
208
|
+
const timeoutMs = options.pingTimeoutMs ?? 500
|
|
209
|
+
return isPidAlive(record.pid) && (await ping(record.address, timeoutMs))
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export interface ListLivePeersOptions extends PeerLivenessOptions {
|
|
213
|
+
readonly sessionsDir: string
|
|
214
|
+
/** Owner-checks every removal; `undefined` skips the check (tests, or a platform with no uid). */
|
|
215
|
+
readonly uid: number | undefined
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Every record in the registry that is live (see {@link isPeerRecordLive}).
|
|
220
|
+
*
|
|
221
|
+
* A record that is not live is DEAD: its registry file and, if it names a
|
|
222
|
+
* UDS socket, the socket file are removed — but only when owned by this
|
|
223
|
+
* uid, so one user's stale cleanup pass can never touch another's files
|
|
224
|
+
* even if it could somehow see them.
|
|
225
|
+
*/
|
|
226
|
+
export async function listLivePeers(options: ListLivePeersOptions): Promise<PeerRecord[]> {
|
|
227
|
+
const records = readPeerRecords(options.sessionsDir)
|
|
228
|
+
const live: PeerRecord[] = []
|
|
229
|
+
await Promise.all(
|
|
230
|
+
records.map(async (record) => {
|
|
231
|
+
const alive = await isPeerRecordLive(record, options)
|
|
232
|
+
if (alive) {
|
|
233
|
+
live.push(record)
|
|
234
|
+
return
|
|
235
|
+
}
|
|
236
|
+
removePeerRecord(options.sessionsDir, record.sessionId, options.uid)
|
|
237
|
+
removeStaleSocketIfOwned(record.address, options.uid)
|
|
238
|
+
}),
|
|
239
|
+
)
|
|
240
|
+
return live
|
|
241
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { PluginHookDefinition, PluginMCPServerConfig } from '../types/plugin/index.js'
|
|
2
|
+
import { PluginManifestSchema, assertPluginHookEvent } from '../types/plugin/index.js'
|
|
3
|
+
import type { ToolDefinition } from '../types/tool/index.js'
|
|
4
|
+
|
|
5
|
+
/** A host-authored plugin that needs no manifest file or dynamic import. */
|
|
6
|
+
export interface DefinedPlugin {
|
|
7
|
+
readonly name: string
|
|
8
|
+
readonly version: string
|
|
9
|
+
readonly description: string
|
|
10
|
+
readonly tools: readonly ToolDefinition[]
|
|
11
|
+
readonly hooks: readonly PluginHookDefinition[]
|
|
12
|
+
readonly instructions?: string
|
|
13
|
+
readonly mcpServers: readonly PluginMCPServerConfig[]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface DefinePluginOptions {
|
|
17
|
+
readonly name: string
|
|
18
|
+
readonly version?: string
|
|
19
|
+
readonly description?: string
|
|
20
|
+
readonly tools?: readonly ToolDefinition[]
|
|
21
|
+
readonly hooks?: readonly PluginHookDefinition[]
|
|
22
|
+
readonly instructions?: string
|
|
23
|
+
readonly mcpServers?: readonly PluginMCPServerConfig[]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Validate and snapshot a plugin supplied directly by the host. */
|
|
27
|
+
export function definePlugin(options: DefinePluginOptions): DefinedPlugin {
|
|
28
|
+
const version = options.version ?? '0.0.0'
|
|
29
|
+
const description = options.description ?? `In-code plugin ${options.name}`
|
|
30
|
+
PluginManifestSchema.parse({
|
|
31
|
+
name: options.name,
|
|
32
|
+
version,
|
|
33
|
+
description,
|
|
34
|
+
instructions: options.instructions,
|
|
35
|
+
mcpServers: options.mcpServers,
|
|
36
|
+
})
|
|
37
|
+
for (const hook of options.hooks ?? []) assertPluginHookEvent(hook.event)
|
|
38
|
+
const toolNames = new Set<string>()
|
|
39
|
+
for (const tool of options.tools ?? []) {
|
|
40
|
+
if (toolNames.has(tool.name))
|
|
41
|
+
throw new Error(`Plugin "${options.name}" declares tool "${tool.name}" twice.`)
|
|
42
|
+
toolNames.add(tool.name)
|
|
43
|
+
}
|
|
44
|
+
const serverNames = new Set<string>()
|
|
45
|
+
for (const server of options.mcpServers ?? []) {
|
|
46
|
+
if (serverNames.has(server.name)) {
|
|
47
|
+
throw new Error(`Plugin "${options.name}" declares MCP server "${server.name}" twice.`)
|
|
48
|
+
}
|
|
49
|
+
serverNames.add(server.name)
|
|
50
|
+
}
|
|
51
|
+
return Object.freeze({
|
|
52
|
+
name: options.name,
|
|
53
|
+
version,
|
|
54
|
+
description,
|
|
55
|
+
tools: Object.freeze([...(options.tools ?? [])]),
|
|
56
|
+
hooks: Object.freeze([...(options.hooks ?? [])]),
|
|
57
|
+
...(options.instructions !== undefined ? { instructions: options.instructions } : {}),
|
|
58
|
+
mcpServers: Object.freeze(
|
|
59
|
+
(options.mcpServers ?? []).map((server) =>
|
|
60
|
+
Object.freeze({
|
|
61
|
+
...server,
|
|
62
|
+
...(server.args ? { args: Object.freeze([...server.args]) } : {}),
|
|
63
|
+
...(server.env ? { env: Object.freeze({ ...server.env }) } : {}),
|
|
64
|
+
}),
|
|
65
|
+
),
|
|
66
|
+
),
|
|
67
|
+
})
|
|
68
|
+
}
|
package/src/plugin/index.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { discoverPlugins, loadPluginManifest, discoverAllPluginDirs } from './loader.js'
|
|
2
|
+
export { definePlugin } from './define.js'
|
|
3
|
+
export type { DefinedPlugin, DefinePluginOptions } from './define.js'
|
|
2
4
|
export type { PluginDiscoveryOptions, PluginEnablementCapabilities } from './loader.js'
|
|
3
5
|
export { PluginLifecycleManager } from './lifecycle.js'
|
|
4
6
|
export { PluginResolver } from './resolver.js'
|