@namzu/sdk 65.3.0 → 67.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 +153 -0
- package/dist/account/lock.d.ts +4 -12
- package/dist/account/lock.d.ts.map +1 -1
- package/dist/account/lock.js +5 -140
- package/dist/account/lock.js.map +1 -1
- package/dist/account/registry.d.ts.map +1 -1
- package/dist/account/registry.js +50 -6
- package/dist/account/registry.js.map +1 -1
- package/dist/account/types.d.ts +7 -5
- package/dist/account/types.d.ts.map +1 -1
- package/dist/account/types.js +6 -7
- package/dist/account/types.js.map +1 -1
- package/dist/authorization/dangerous-commands.d.ts +64 -0
- package/dist/authorization/dangerous-commands.d.ts.map +1 -0
- package/dist/authorization/dangerous-commands.js +479 -0
- package/dist/authorization/dangerous-commands.js.map +1 -0
- package/dist/authorization/gate.d.ts.map +1 -1
- package/dist/authorization/gate.js +19 -5
- package/dist/authorization/gate.js.map +1 -1
- package/dist/authorization/protected-paths.d.ts +11 -6
- package/dist/authorization/protected-paths.d.ts.map +1 -1
- package/dist/authorization/protected-paths.js +13 -8
- package/dist/authorization/protected-paths.js.map +1 -1
- package/dist/authorization/readonly-commands.d.ts +6 -1
- package/dist/authorization/readonly-commands.d.ts.map +1 -1
- package/dist/authorization/readonly-commands.js +35 -1
- package/dist/authorization/readonly-commands.js.map +1 -1
- package/dist/authorization/removal.d.ts +10 -0
- package/dist/authorization/removal.d.ts.map +1 -1
- package/dist/authorization/removal.js +7 -7
- package/dist/authorization/removal.js.map +1 -1
- package/dist/authorization/rules.d.ts +10 -0
- package/dist/authorization/rules.d.ts.map +1 -1
- package/dist/authorization/rules.js +60 -14
- package/dist/authorization/rules.js.map +1 -1
- package/dist/authorization/shell-lexer.d.ts +10 -0
- package/dist/authorization/shell-lexer.d.ts.map +1 -1
- package/dist/authorization/shell-lexer.js +15 -0
- package/dist/authorization/shell-lexer.js.map +1 -1
- package/dist/bridge/acp/permission.d.ts +5 -0
- package/dist/bridge/acp/permission.d.ts.map +1 -1
- package/dist/bridge/acp/permission.js.map +1 -1
- package/dist/bridge/acp/server.d.ts +8 -1
- package/dist/bridge/acp/server.d.ts.map +1 -1
- package/dist/bridge/acp/server.js +48 -6
- package/dist/bridge/acp/server.js.map +1 -1
- package/dist/compaction/context-breakdown.d.ts +25 -6
- package/dist/compaction/context-breakdown.d.ts.map +1 -1
- package/dist/compaction/context-breakdown.js +27 -7
- package/dist/compaction/context-breakdown.js.map +1 -1
- package/dist/compaction/dangling.d.ts.map +1 -1
- package/dist/compaction/dangling.js +2 -0
- package/dist/compaction/dangling.js.map +1 -1
- package/dist/compaction/extractor.d.ts +7 -1
- package/dist/compaction/extractor.d.ts.map +1 -1
- package/dist/compaction/extractor.js +8 -1
- package/dist/compaction/extractor.js.map +1 -1
- package/dist/compaction/index.d.ts +1 -1
- package/dist/compaction/index.d.ts.map +1 -1
- package/dist/compaction/index.js +1 -1
- package/dist/compaction/index.js.map +1 -1
- package/dist/compaction/managers/structured.js +2 -2
- package/dist/compaction/managers/structured.js.map +1 -1
- package/dist/compaction/manual.d.ts.map +1 -1
- package/dist/compaction/manual.js +11 -6
- package/dist/compaction/manual.js.map +1 -1
- package/dist/compaction/model-summary.d.ts.map +1 -1
- package/dist/compaction/model-summary.js +7 -1
- package/dist/compaction/model-summary.js.map +1 -1
- package/dist/compaction/summary.d.ts +13 -2
- package/dist/compaction/summary.d.ts.map +1 -1
- package/dist/compaction/summary.js +46 -3
- package/dist/compaction/summary.js.map +1 -1
- package/dist/constants/tools/index.d.ts +18 -1
- package/dist/constants/tools/index.d.ts.map +1 -1
- package/dist/constants/tools/index.js +28 -16
- package/dist/constants/tools/index.js.map +1 -1
- package/dist/manager/session/turn-recorder.d.ts +6 -0
- package/dist/manager/session/turn-recorder.d.ts.map +1 -1
- package/dist/manager/session/turn-recorder.js +29 -1
- package/dist/manager/session/turn-recorder.js.map +1 -1
- package/dist/network/audit.d.ts +49 -0
- package/dist/network/audit.d.ts.map +1 -0
- package/dist/network/audit.js +84 -0
- package/dist/network/audit.js.map +1 -0
- package/dist/network/clock.d.ts +21 -0
- package/dist/network/clock.d.ts.map +1 -0
- package/dist/network/clock.js +51 -0
- package/dist/network/clock.js.map +1 -0
- package/dist/network/discovery-mdns.d.ts +120 -0
- package/dist/network/discovery-mdns.d.ts.map +1 -0
- package/dist/network/discovery-mdns.js +442 -0
- package/dist/network/discovery-mdns.js.map +1 -0
- package/dist/network/discovery.d.ts +63 -0
- package/dist/network/discovery.d.ts.map +1 -0
- package/dist/network/discovery.js +163 -0
- package/dist/network/discovery.js.map +1 -0
- package/dist/network/fingerprint.d.ts +73 -0
- package/dist/network/fingerprint.d.ts.map +1 -0
- package/dist/network/fingerprint.js +208 -0
- package/dist/network/fingerprint.js.map +1 -0
- package/dist/network/identity.d.ts +38 -0
- package/dist/network/identity.d.ts.map +1 -0
- package/dist/network/identity.js +71 -0
- package/dist/network/identity.js.map +1 -0
- package/dist/network/index.d.ts +39 -0
- package/dist/network/index.d.ts.map +1 -0
- package/dist/network/index.js +25 -0
- package/dist/network/index.js.map +1 -0
- package/dist/network/join.d.ts +69 -0
- package/dist/network/join.d.ts.map +1 -0
- package/dist/network/join.js +136 -0
- package/dist/network/join.js.map +1 -0
- package/dist/network/mail-policy.d.ts +97 -0
- package/dist/network/mail-policy.d.ts.map +1 -0
- package/dist/network/mail-policy.js +147 -0
- package/dist/network/mail-policy.js.map +1 -0
- package/dist/network/membership.d.ts +76 -0
- package/dist/network/membership.d.ts.map +1 -0
- package/dist/network/membership.js +225 -0
- package/dist/network/membership.js.map +1 -0
- package/dist/network/roster.d.ts +59 -0
- package/dist/network/roster.d.ts.map +1 -0
- package/dist/network/roster.js +120 -0
- package/dist/network/roster.js.map +1 -0
- package/dist/network/service.d.ts +303 -0
- package/dist/network/service.d.ts.map +1 -0
- package/dist/network/service.js +1891 -0
- package/dist/network/service.js.map +1 -0
- package/dist/network/store.d.ts +141 -0
- package/dist/network/store.d.ts.map +1 -0
- package/dist/network/store.js +198 -0
- package/dist/network/store.js.map +1 -0
- package/dist/network/transport.d.ts +96 -0
- package/dist/network/transport.d.ts.map +1 -0
- package/dist/network/transport.js +342 -0
- package/dist/network/transport.js.map +1 -0
- package/dist/network/wire.d.ts +345 -0
- package/dist/network/wire.d.ts.map +1 -0
- package/dist/network/wire.js +212 -0
- package/dist/network/wire.js.map +1 -0
- package/dist/network/x509.d.ts +28 -0
- package/dist/network/x509.d.ts.map +1 -0
- package/dist/network/x509.js +84 -0
- package/dist/network/x509.js.map +1 -0
- package/dist/pals/activity/causality.d.ts.map +1 -1
- package/dist/pals/activity/causality.js +14 -2
- package/dist/pals/activity/causality.js.map +1 -1
- package/dist/peers/endpoint.d.ts.map +1 -1
- package/dist/peers/endpoint.js +6 -0
- package/dist/peers/endpoint.js.map +1 -1
- package/dist/peers/envelope.d.ts +18 -0
- package/dist/peers/envelope.d.ts.map +1 -1
- package/dist/peers/envelope.js +68 -5
- package/dist/peers/envelope.js.map +1 -1
- package/dist/peers/index.d.ts +5 -4
- package/dist/peers/index.d.ts.map +1 -1
- package/dist/peers/index.js +3 -2
- package/dist/peers/index.js.map +1 -1
- package/dist/peers/mode-word.d.ts +10 -0
- package/dist/peers/mode-word.d.ts.map +1 -0
- package/dist/peers/mode-word.js +19 -0
- package/dist/peers/mode-word.js.map +1 -0
- package/dist/peers/protocol.d.ts +42 -0
- package/dist/peers/protocol.d.ts.map +1 -1
- package/dist/peers/protocol.js +22 -1
- package/dist/peers/protocol.js.map +1 -1
- package/dist/peers/record.d.ts +8 -0
- package/dist/peers/record.d.ts.map +1 -1
- package/dist/peers/record.js +5 -0
- package/dist/peers/record.js.map +1 -1
- package/dist/plugin/session-hook-env.d.ts.map +1 -1
- package/dist/plugin/session-hook-env.js +22 -2
- package/dist/plugin/session-hook-env.js.map +1 -1
- package/dist/plugin/shell-hook.d.ts +16 -2
- package/dist/plugin/shell-hook.d.ts.map +1 -1
- package/dist/plugin/shell-hook.js +183 -14
- package/dist/plugin/shell-hook.js.map +1 -1
- package/dist/prompt/coding-agent-doctrine.d.ts +4 -2
- package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
- package/dist/prompt/coding-agent-doctrine.js +33 -38
- package/dist/prompt/coding-agent-doctrine.js.map +1 -1
- package/dist/public-runtime.d.ts +14 -6
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +22 -5
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +3 -2
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +2 -2
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +7 -2
- package/dist/public-types.d.ts.map +1 -1
- package/dist/runtime/jobs/registry.d.ts +29 -1
- package/dist/runtime/jobs/registry.d.ts.map +1 -1
- package/dist/runtime/jobs/registry.js +64 -0
- package/dist/runtime/jobs/registry.js.map +1 -1
- package/dist/runtime/query/auto-review/classifier.d.ts +30 -6
- package/dist/runtime/query/auto-review/classifier.d.ts.map +1 -1
- package/dist/runtime/query/auto-review/classifier.js +40 -12
- package/dist/runtime/query/auto-review/classifier.js.map +1 -1
- package/dist/runtime/query/auto-review/feedback.d.ts +37 -0
- package/dist/runtime/query/auto-review/feedback.d.ts.map +1 -0
- package/dist/runtime/query/auto-review/feedback.js +45 -0
- package/dist/runtime/query/auto-review/feedback.js.map +1 -0
- package/dist/runtime/query/auto-review/git-status.d.ts +59 -0
- package/dist/runtime/query/auto-review/git-status.d.ts.map +1 -0
- package/dist/runtime/query/auto-review/git-status.js +379 -0
- package/dist/runtime/query/auto-review/git-status.js.map +1 -0
- package/dist/runtime/query/auto-review/index.d.ts +3 -3
- package/dist/runtime/query/auto-review/index.d.ts.map +1 -1
- package/dist/runtime/query/auto-review/index.js +2 -2
- package/dist/runtime/query/auto-review/index.js.map +1 -1
- package/dist/runtime/query/auto-review/prompt.d.ts.map +1 -1
- package/dist/runtime/query/auto-review/prompt.js +6 -1
- package/dist/runtime/query/auto-review/prompt.js.map +1 -1
- package/dist/runtime/query/auto-review/transcript.d.ts +14 -1
- package/dist/runtime/query/auto-review/transcript.d.ts.map +1 -1
- package/dist/runtime/query/auto-review/transcript.js +48 -2
- package/dist/runtime/query/auto-review/transcript.js.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.js +40 -3
- package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +32 -10
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +78 -17
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/index.d.ts +9 -0
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +54 -17
- 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 +17 -3
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.js +5 -2
- package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/context.js +5 -0
- package/dist/runtime/query/iteration/phases/context.js.map +1 -1
- package/dist/runtime/query/iteration/phases/per-call-review.d.ts +1 -2
- package/dist/runtime/query/iteration/phases/per-call-review.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/per-call-review.js +2 -5
- package/dist/runtime/query/iteration/phases/per-call-review.js.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.js +6 -1
- package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
- package/dist/runtime/query/pasted-frames.d.ts +34 -0
- package/dist/runtime/query/pasted-frames.d.ts.map +1 -0
- package/dist/runtime/query/pasted-frames.js +108 -0
- package/dist/runtime/query/pasted-frames.js.map +1 -0
- package/dist/runtime/query/path-escalation.d.ts +6 -0
- package/dist/runtime/query/path-escalation.d.ts.map +1 -1
- package/dist/runtime/query/path-escalation.js +15 -3
- package/dist/runtime/query/path-escalation.js.map +1 -1
- package/dist/runtime/query/request-interrupted-turns.d.ts +20 -0
- package/dist/runtime/query/request-interrupted-turns.d.ts.map +1 -0
- package/dist/runtime/query/request-interrupted-turns.js +43 -0
- package/dist/runtime/query/request-interrupted-turns.js.map +1 -0
- package/dist/runtime/query/review-policy.d.ts +16 -6
- package/dist/runtime/query/review-policy.d.ts.map +1 -1
- package/dist/runtime/query/review-policy.js +111 -15
- package/dist/runtime/query/review-policy.js.map +1 -1
- package/dist/runtime/query/turn/outcome-ledger.d.ts +9 -0
- package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
- package/dist/runtime/query/turn/outcome-ledger.js +94 -6
- package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
- package/dist/runtime/query/unanswered.d.ts +19 -0
- package/dist/runtime/query/unanswered.d.ts.map +1 -0
- package/dist/runtime/query/unanswered.js +25 -0
- package/dist/runtime/query/unanswered.js.map +1 -0
- package/dist/runtime/system-events.d.ts +4 -4
- package/dist/runtime/system-events.d.ts.map +1 -1
- package/dist/runtime/system-events.js +2 -0
- package/dist/runtime/system-events.js.map +1 -1
- package/dist/session/workspace/git-worktree.d.ts +8 -0
- package/dist/session/workspace/git-worktree.d.ts.map +1 -1
- package/dist/session/workspace/git-worktree.js +21 -3
- package/dist/session/workspace/git-worktree.js.map +1 -1
- package/dist/store/evidence/source-kind.d.ts +1 -1
- package/dist/store/evidence/source-kind.d.ts.map +1 -1
- package/dist/store/evidence/source-kind.js +1 -1
- package/dist/store/evidence/source-kind.js.map +1 -1
- package/dist/store/session-index/sqlite.d.ts.map +1 -1
- package/dist/store/session-index/sqlite.js +42 -3
- package/dist/store/session-index/sqlite.js.map +1 -1
- package/dist/store/session-log/disk.js +1 -1
- package/dist/store/session-log/disk.js.map +1 -1
- package/dist/store/session-log/lease.d.ts.map +1 -1
- package/dist/store/session-log/lease.js +3 -2
- package/dist/store/session-log/lease.js.map +1 -1
- package/dist/tools/admit-facts.d.ts.map +1 -1
- package/dist/tools/admit-facts.js +2 -0
- package/dist/tools/admit-facts.js.map +1 -1
- package/dist/tools/builtins/bash.d.ts +10 -2
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +56 -17
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/browser-local.d.ts +117 -0
- package/dist/tools/builtins/browser-local.d.ts.map +1 -0
- package/dist/tools/builtins/browser-local.js +437 -0
- package/dist/tools/builtins/browser-local.js.map +1 -0
- package/dist/tools/builtins/browser.d.ts +18 -1
- package/dist/tools/builtins/browser.d.ts.map +1 -1
- package/dist/tools/builtins/browser.js +84 -6
- package/dist/tools/builtins/browser.js.map +1 -1
- package/dist/tools/builtins/computer-use-window-id.d.ts +16 -0
- package/dist/tools/builtins/computer-use-window-id.d.ts.map +1 -0
- package/dist/tools/builtins/computer-use-window-id.js +52 -0
- package/dist/tools/builtins/computer-use-window-id.js.map +1 -0
- package/dist/tools/builtins/computer-use.d.ts +65 -7
- package/dist/tools/builtins/computer-use.d.ts.map +1 -1
- package/dist/tools/builtins/computer-use.js +384 -71
- package/dist/tools/builtins/computer-use.js.map +1 -1
- package/dist/tools/builtins/content-fingerprint.d.ts +6 -0
- package/dist/tools/builtins/content-fingerprint.d.ts.map +1 -1
- package/dist/tools/builtins/content-fingerprint.js +7 -1
- package/dist/tools/builtins/content-fingerprint.js.map +1 -1
- package/dist/tools/builtins/edit.d.ts.map +1 -1
- package/dist/tools/builtins/edit.js +89 -7
- package/dist/tools/builtins/edit.js.map +1 -1
- package/dist/tools/builtins/file-write-result.d.ts.map +1 -1
- package/dist/tools/builtins/file-write-result.js +2 -1
- package/dist/tools/builtins/file-write-result.js.map +1 -1
- package/dist/tools/builtins/grep.js +1 -1
- package/dist/tools/builtins/grep.js.map +1 -1
- package/dist/tools/builtins/job.d.ts.map +1 -1
- package/dist/tools/builtins/job.js +4 -2
- package/dist/tools/builtins/job.js.map +1 -1
- package/dist/tools/builtins/monitor.d.ts.map +1 -1
- package/dist/tools/builtins/monitor.js +6 -1
- package/dist/tools/builtins/monitor.js.map +1 -1
- package/dist/tools/builtins/search-tools.d.ts +12 -1
- package/dist/tools/builtins/search-tools.d.ts.map +1 -1
- package/dist/tools/builtins/search-tools.js +166 -20
- package/dist/tools/builtins/search-tools.js.map +1 -1
- package/dist/tools/builtins/shell-read-credit.d.ts +18 -6
- package/dist/tools/builtins/shell-read-credit.d.ts.map +1 -1
- package/dist/tools/builtins/shell-read-credit.js +95 -27
- package/dist/tools/builtins/shell-read-credit.js.map +1 -1
- package/dist/tools/builtins/wait-for-job.d.ts.map +1 -1
- package/dist/tools/builtins/wait-for-job.js +14 -3
- package/dist/tools/builtins/wait-for-job.js.map +1 -1
- package/dist/tools/builtins/web-guidance.d.ts +6 -0
- package/dist/tools/builtins/web-guidance.d.ts.map +1 -1
- package/dist/tools/builtins/web-guidance.js +6 -0
- package/dist/tools/builtins/web-guidance.js.map +1 -1
- package/dist/tools/builtins/web.d.ts.map +1 -1
- package/dist/tools/builtins/web.js +2 -1
- package/dist/tools/builtins/web.js.map +1 -1
- package/dist/tools/builtins/write-file.d.ts.map +1 -1
- package/dist/tools/builtins/write-file.js +32 -2
- package/dist/tools/builtins/write-file.js.map +1 -1
- package/dist/tools/command-shell.d.ts +1 -1
- package/dist/tools/command-shell.d.ts.map +1 -1
- package/dist/tools/command-shell.js +6 -8
- package/dist/tools/command-shell.js.map +1 -1
- package/dist/tools/defineTool.d.ts +2 -0
- package/dist/tools/defineTool.d.ts.map +1 -1
- package/dist/tools/defineTool.js +17 -1
- package/dist/tools/defineTool.js.map +1 -1
- package/dist/tools/schedules/index.d.ts +1 -0
- package/dist/tools/schedules/index.d.ts.map +1 -1
- package/dist/tools/schedules/index.js +1 -0
- package/dist/tools/schedules/index.js.map +1 -1
- package/dist/tools/schedules/loop-tool.d.ts.map +1 -1
- package/dist/tools/schedules/loop-tool.js +8 -6
- package/dist/tools/schedules/loop-tool.js.map +1 -1
- package/dist/tools/schedules/present.js +1 -1
- package/dist/tools/schedules/present.js.map +1 -1
- package/dist/tools/schedules/timer-tools.d.ts +36 -0
- package/dist/tools/schedules/timer-tools.d.ts.map +1 -0
- package/dist/tools/schedules/timer-tools.js +234 -0
- package/dist/tools/schedules/timer-tools.js.map +1 -0
- package/dist/tools/schedules/types.d.ts +68 -3
- package/dist/tools/schedules/types.d.ts.map +1 -1
- package/dist/tools/task/create.d.ts.map +1 -1
- package/dist/tools/task/create.js +2 -0
- package/dist/tools/task/create.js.map +1 -1
- package/dist/toolsets/manager.d.ts +49 -7
- package/dist/toolsets/manager.d.ts.map +1 -1
- package/dist/toolsets/manager.js +239 -40
- package/dist/toolsets/manager.js.map +1 -1
- package/dist/turn/evidence-query.d.ts +18 -1
- package/dist/turn/evidence-query.d.ts.map +1 -1
- package/dist/turn/evidence-query.js +177 -35
- package/dist/turn/evidence-query.js.map +1 -1
- package/dist/turn/evidence-recall.d.ts +8 -1
- package/dist/turn/evidence-recall.d.ts.map +1 -1
- package/dist/turn/evidence-recall.js +82 -22
- package/dist/turn/evidence-recall.js.map +1 -1
- package/dist/turn/history-shed.d.ts +15 -0
- package/dist/turn/history-shed.d.ts.map +1 -0
- package/dist/turn/history-shed.js +23 -0
- package/dist/turn/history-shed.js.map +1 -0
- package/dist/types/acp/index.d.ts +26 -0
- package/dist/types/acp/index.d.ts.map +1 -1
- package/dist/types/authorization/index.d.ts +9 -1
- package/dist/types/authorization/index.d.ts.map +1 -1
- package/dist/types/authorization/index.js +11 -2
- package/dist/types/authorization/index.js.map +1 -1
- package/dist/types/hitl/index.d.ts +10 -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 +56 -1
- package/dist/types/message/index.d.ts.map +1 -1
- package/dist/types/message/index.js +2 -1
- package/dist/types/message/index.js.map +1 -1
- package/dist/types/permission/index.d.ts +14 -0
- package/dist/types/permission/index.d.ts.map +1 -1
- package/dist/types/permission/index.js +14 -0
- package/dist/types/permission/index.js.map +1 -1
- package/dist/types/plugin/index.d.ts +148 -1
- package/dist/types/plugin/index.d.ts.map +1 -1
- package/dist/types/plugin/index.js +9 -0
- package/dist/types/plugin/index.js.map +1 -1
- package/dist/types/provider/index.d.ts +1 -0
- package/dist/types/provider/index.d.ts.map +1 -1
- package/dist/types/provider/interface.d.ts +12 -0
- package/dist/types/provider/interface.d.ts.map +1 -1
- package/dist/types/provider/limits.d.ts +33 -0
- package/dist/types/provider/limits.d.ts.map +1 -0
- package/dist/types/provider/limits.js +7 -0
- package/dist/types/provider/limits.js.map +1 -0
- package/dist/types/tool/index.d.ts +30 -0
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/dist/types/tool/presentation.d.ts +4 -0
- package/dist/types/tool/presentation.d.ts.map +1 -1
- package/dist/utils/file-lock.d.ts +88 -0
- package/dist/utils/file-lock.d.ts.map +1 -0
- package/dist/utils/file-lock.js +281 -0
- package/dist/utils/file-lock.js.map +1 -0
- package/dist/utils/state-backup.d.ts +87 -0
- package/dist/utils/state-backup.d.ts.map +1 -0
- package/dist/utils/state-backup.js +272 -0
- package/dist/utils/state-backup.js.map +1 -0
- package/dist/utils/temp-sweep.d.ts +66 -0
- package/dist/utils/temp-sweep.d.ts.map +1 -0
- package/dist/utils/temp-sweep.js +311 -0
- package/dist/utils/temp-sweep.js.map +1 -0
- package/dist/utils/temp.d.ts +14 -0
- package/dist/utils/temp.d.ts.map +1 -1
- package/dist/utils/temp.js +70 -2
- package/dist/utils/temp.js.map +1 -1
- package/package.json +1 -1
- package/src/account/lock.ts +13 -133
- package/src/account/registry.ts +75 -21
- package/src/account/types.ts +8 -9
- package/src/authorization/dangerous-commands.ts +542 -0
- package/src/authorization/gate.ts +19 -5
- package/src/authorization/protected-paths.ts +13 -8
- package/src/authorization/readonly-commands.ts +35 -1
- package/src/authorization/removal.ts +7 -7
- package/src/authorization/rules.ts +75 -15
- package/src/authorization/shell-lexer.ts +19 -0
- package/src/bridge/acp/permission.ts +2 -0
- package/src/bridge/acp/server.ts +66 -6
- package/src/compaction/context-breakdown.ts +53 -11
- package/src/compaction/dangling.ts +2 -0
- package/src/compaction/extractor.ts +9 -1
- package/src/compaction/index.ts +1 -0
- package/src/compaction/managers/structured.ts +2 -2
- package/src/compaction/manual.ts +11 -3
- package/src/compaction/model-summary.ts +8 -1
- package/src/compaction/summary.ts +54 -7
- package/src/constants/tools/index.ts +30 -16
- package/src/manager/session/turn-recorder.ts +37 -1
- package/src/network/audit.ts +113 -0
- package/src/network/clock.ts +62 -0
- package/src/network/discovery-mdns.ts +485 -0
- package/src/network/discovery.ts +210 -0
- package/src/network/fingerprint.ts +241 -0
- package/src/network/identity.ts +98 -0
- package/src/network/index.ts +134 -0
- package/src/network/join.ts +177 -0
- package/src/network/mail-policy.ts +199 -0
- package/src/network/membership.ts +290 -0
- package/src/network/roster.ts +165 -0
- package/src/network/service.ts +2304 -0
- package/src/network/store.ts +261 -0
- package/src/network/transport.ts +445 -0
- package/src/network/wire.ts +250 -0
- package/src/network/x509.ts +114 -0
- package/src/pals/activity/causality.ts +16 -2
- package/src/peers/endpoint.ts +6 -0
- package/src/peers/envelope.ts +82 -5
- package/src/peers/index.ts +10 -2
- package/src/peers/mode-word.ts +18 -0
- package/src/peers/protocol.ts +24 -1
- package/src/peers/record.ts +5 -0
- package/src/plugin/session-hook-env.ts +25 -2
- package/src/plugin/shell-hook.ts +208 -14
- package/src/prompt/coding-agent-doctrine.ts +33 -38
- package/src/public-runtime.ts +107 -1
- package/src/public-tools.ts +11 -0
- package/src/public-types.ts +67 -1
- package/src/runtime/jobs/registry.ts +93 -3
- package/src/runtime/query/auto-review/classifier.ts +76 -14
- package/src/runtime/query/auto-review/feedback.ts +50 -0
- package/src/runtime/query/auto-review/git-status.ts +437 -0
- package/src/runtime/query/auto-review/index.ts +7 -2
- package/src/runtime/query/auto-review/prompt.ts +6 -1
- package/src/runtime/query/auto-review/transcript.ts +67 -4
- package/src/runtime/query/executor/tool-call-admission.ts +49 -3
- package/src/runtime/query/executor.ts +104 -21
- package/src/runtime/query/index.ts +66 -17
- package/src/runtime/query/iteration/index.ts +24 -3
- package/src/runtime/query/iteration/phases/compaction.ts +4 -0
- package/src/runtime/query/iteration/phases/context.ts +5 -0
- package/src/runtime/query/iteration/phases/per-call-review.ts +8 -13
- package/src/runtime/query/iteration/phases/tool-review.ts +7 -1
- package/src/runtime/query/pasted-frames.ts +119 -0
- package/src/runtime/query/path-escalation.ts +27 -3
- package/src/runtime/query/request-interrupted-turns.ts +47 -0
- package/src/runtime/query/review-policy.ts +125 -22
- package/src/runtime/query/turn/outcome-ledger.ts +99 -6
- package/src/runtime/query/unanswered.ts +35 -0
- package/src/runtime/system-events.ts +2 -0
- package/src/session/workspace/git-worktree.ts +34 -3
- package/src/store/evidence/source-kind.ts +1 -1
- package/src/store/session-index/sqlite.ts +40 -3
- package/src/store/session-log/disk.ts +1 -1
- package/src/store/session-log/lease.ts +3 -2
- package/src/tools/admit-facts.ts +2 -0
- package/src/tools/builtins/bash.ts +62 -19
- package/src/tools/builtins/browser-local.ts +504 -0
- package/src/tools/builtins/browser.ts +108 -6
- package/src/tools/builtins/computer-use-window-id.ts +50 -0
- package/src/tools/builtins/computer-use.ts +460 -68
- package/src/tools/builtins/content-fingerprint.ts +8 -1
- package/src/tools/builtins/edit.ts +93 -7
- package/src/tools/builtins/file-write-result.ts +2 -1
- package/src/tools/builtins/grep.ts +1 -1
- package/src/tools/builtins/job.ts +4 -2
- package/src/tools/builtins/monitor.ts +6 -1
- package/src/tools/builtins/search-tools.ts +196 -21
- package/src/tools/builtins/shell-read-credit.ts +97 -33
- package/src/tools/builtins/wait-for-job.ts +13 -3
- package/src/tools/builtins/web-guidance.ts +6 -0
- package/src/tools/builtins/web.ts +2 -1
- package/src/tools/builtins/write-file.ts +31 -3
- package/src/tools/command-shell.ts +6 -8
- package/src/tools/defineTool.ts +20 -1
- package/src/tools/schedules/index.ts +11 -0
- package/src/tools/schedules/loop-tool.ts +10 -6
- package/src/tools/schedules/present.ts +1 -1
- package/src/tools/schedules/timer-tools.ts +258 -0
- package/src/tools/schedules/types.ts +72 -3
- package/src/tools/task/create.ts +2 -0
- package/src/toolsets/manager.ts +262 -46
- package/src/turn/evidence-query.ts +183 -42
- package/src/turn/evidence-recall.ts +96 -19
- package/src/turn/history-shed.ts +30 -0
- package/src/types/acp/index.ts +24 -0
- package/src/types/authorization/index.ts +20 -3
- package/src/types/hitl/index.ts +10 -0
- package/src/types/message/index.ts +65 -0
- package/src/types/permission/index.ts +18 -0
- package/src/types/plugin/index.ts +205 -26
- package/src/types/provider/index.ts +1 -0
- package/src/types/provider/interface.ts +13 -0
- package/src/types/provider/limits.ts +35 -0
- package/src/types/tool/index.ts +30 -2
- package/src/types/tool/presentation.ts +4 -0
- package/src/utils/file-lock.ts +328 -0
- package/src/utils/state-backup.ts +318 -0
- package/src/utils/temp-sweep.ts +327 -0
- package/src/utils/temp.ts +73 -2
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-machine state of the Namzu network, under `<home>/network/`:
|
|
3
|
+
*
|
|
4
|
+
* ```
|
|
5
|
+
* machine.json machine.key.pem machine.cert.pem network.json
|
|
6
|
+
* members.json peers.json session-roles.json trusted-networks.json leader.lock audit.jsonl
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* The directory is 0700 and every file 0600, written atomically. Reads are
|
|
10
|
+
* zod-parsed; a corrupt file is renamed aside to `<file>.corrupt-<ts>` and the
|
|
11
|
+
* feature degrades instead of throwing. Nothing is created until a caller
|
|
12
|
+
* writes; an off machine leaves nothing behind.
|
|
13
|
+
*
|
|
14
|
+
* @experimental
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { existsSync } from 'node:fs'
|
|
18
|
+
import { readFile, rename, rm } from 'node:fs/promises'
|
|
19
|
+
import { join } from 'node:path'
|
|
20
|
+
import { z } from 'zod'
|
|
21
|
+
import { hardenPeerRuntimeDir } from '../peers/dir.js'
|
|
22
|
+
import { atomicWriteFile } from '../utils/atomic-write.js'
|
|
23
|
+
import { type MachineKey, exportMachineKeyPem, importMachineKeyPem } from './identity.js'
|
|
24
|
+
import { AdmissionSchema, RevocationSchema } from './membership.js'
|
|
25
|
+
|
|
26
|
+
const FILE_MODE = 0o600
|
|
27
|
+
|
|
28
|
+
export const MachineFileSchema = z
|
|
29
|
+
.object({
|
|
30
|
+
v: z.literal(1),
|
|
31
|
+
machineId: z.string().length(64),
|
|
32
|
+
name: z.string().max(80).optional(),
|
|
33
|
+
role: z.string().max(500).optional(),
|
|
34
|
+
listenPort: z.number().int().min(1).max(65535).optional(),
|
|
35
|
+
createdAt: z.number().int().nonnegative(),
|
|
36
|
+
})
|
|
37
|
+
.strict()
|
|
38
|
+
export type MachineFile = z.infer<typeof MachineFileSchema>
|
|
39
|
+
|
|
40
|
+
export const NetworkFileSchema = z
|
|
41
|
+
.object({
|
|
42
|
+
v: z.literal(1),
|
|
43
|
+
netId: z.string().length(16),
|
|
44
|
+
founderPublicKey: z.string().min(1),
|
|
45
|
+
createdAt: z.number().int().nonnegative(),
|
|
46
|
+
})
|
|
47
|
+
.strict()
|
|
48
|
+
export type NetworkFile = z.infer<typeof NetworkFileSchema>
|
|
49
|
+
|
|
50
|
+
export const MembersFileSchema = z
|
|
51
|
+
.object({
|
|
52
|
+
v: z.literal(1),
|
|
53
|
+
rev: z.number().int().nonnegative(),
|
|
54
|
+
members: z.array(AdmissionSchema),
|
|
55
|
+
revoked: z.array(RevocationSchema),
|
|
56
|
+
})
|
|
57
|
+
.strict()
|
|
58
|
+
export type MembersFile = z.infer<typeof MembersFileSchema>
|
|
59
|
+
|
|
60
|
+
const AddressSchema = z
|
|
61
|
+
.object({
|
|
62
|
+
host: z.string().min(1).max(255),
|
|
63
|
+
port: z.number().int().min(1).max(65535),
|
|
64
|
+
at: z.number().int().nonnegative(),
|
|
65
|
+
manual: z.boolean().optional(),
|
|
66
|
+
})
|
|
67
|
+
.strict()
|
|
68
|
+
export type RememberedAddress = z.infer<typeof AddressSchema>
|
|
69
|
+
|
|
70
|
+
export const PeersFileSchema = z
|
|
71
|
+
.object({
|
|
72
|
+
v: z.literal(1),
|
|
73
|
+
machines: z.record(
|
|
74
|
+
z.string(),
|
|
75
|
+
z.object({ name: z.string().max(80), addresses: z.array(AddressSchema).max(4) }).strict(),
|
|
76
|
+
),
|
|
77
|
+
})
|
|
78
|
+
.strict()
|
|
79
|
+
export type PeersFile = z.infer<typeof PeersFileSchema>
|
|
80
|
+
|
|
81
|
+
export const SessionRolesFileSchema = z
|
|
82
|
+
.object({
|
|
83
|
+
v: z.literal(1),
|
|
84
|
+
roles: z
|
|
85
|
+
.array(
|
|
86
|
+
z
|
|
87
|
+
.object({
|
|
88
|
+
conversationId: z.string().min(1),
|
|
89
|
+
role: z.string().max(500),
|
|
90
|
+
by: z.string().max(80),
|
|
91
|
+
at: z.number().int().nonnegative(),
|
|
92
|
+
})
|
|
93
|
+
.strict(),
|
|
94
|
+
)
|
|
95
|
+
.max(64),
|
|
96
|
+
})
|
|
97
|
+
.strict()
|
|
98
|
+
export type SessionRolesFile = z.infer<typeof SessionRolesFileSchema>
|
|
99
|
+
|
|
100
|
+
export const TrustedNetworksFileSchema = z
|
|
101
|
+
.object({
|
|
102
|
+
v: z.literal(1),
|
|
103
|
+
networks: z
|
|
104
|
+
.array(
|
|
105
|
+
z
|
|
106
|
+
.object({
|
|
107
|
+
/** Fingerprint of the local network (see `fingerprint.ts`); not a secret. */
|
|
108
|
+
id: z.string().length(16),
|
|
109
|
+
name: z.string().min(1).max(40),
|
|
110
|
+
trustedAt: z.number().int().nonnegative(),
|
|
111
|
+
})
|
|
112
|
+
.strict(),
|
|
113
|
+
)
|
|
114
|
+
.max(64),
|
|
115
|
+
})
|
|
116
|
+
.strict()
|
|
117
|
+
export type TrustedNetworksFile = z.infer<typeof TrustedNetworksFileSchema>
|
|
118
|
+
|
|
119
|
+
export const LeaderLockSchema = z
|
|
120
|
+
.object({
|
|
121
|
+
pid: z.number().int().positive(),
|
|
122
|
+
startedAt: z.number().int().nonnegative(),
|
|
123
|
+
port: z.number().int().min(0).max(65535),
|
|
124
|
+
})
|
|
125
|
+
.strict()
|
|
126
|
+
export type LeaderLock = z.infer<typeof LeaderLockSchema>
|
|
127
|
+
|
|
128
|
+
export type ReadResult<T> =
|
|
129
|
+
| { readonly status: 'ok'; readonly value: T }
|
|
130
|
+
| { readonly status: 'missing' }
|
|
131
|
+
| { readonly status: 'corrupt' }
|
|
132
|
+
|
|
133
|
+
export interface NetworkStoreOptions {
|
|
134
|
+
/** The Namzu home (`~/.namzu`). The store works in `<home>/network`. */
|
|
135
|
+
readonly home: string
|
|
136
|
+
/** Tighten the directory; the CLI supplies one that also restricts a Windows ACL. */
|
|
137
|
+
readonly hardenDirectory?: (path: string) => void
|
|
138
|
+
readonly now?: () => number
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface NetworkStore {
|
|
142
|
+
readonly dir: string
|
|
143
|
+
/** True when the directory exists: some network state may be there. */
|
|
144
|
+
exists(): boolean
|
|
145
|
+
file(name: string): string
|
|
146
|
+
readMachine(): Promise<ReadResult<MachineFile>>
|
|
147
|
+
writeMachine(value: MachineFile): Promise<void>
|
|
148
|
+
readKey(): Promise<ReadResult<MachineKey>>
|
|
149
|
+
writeKey(key: MachineKey): Promise<void>
|
|
150
|
+
readCertificate(): Promise<string | undefined>
|
|
151
|
+
writeCertificate(pem: string): Promise<void>
|
|
152
|
+
readNetwork(): Promise<ReadResult<NetworkFile>>
|
|
153
|
+
writeNetwork(value: NetworkFile): Promise<void>
|
|
154
|
+
readMembers(): Promise<ReadResult<MembersFile>>
|
|
155
|
+
writeMembers(value: MembersFile): Promise<void>
|
|
156
|
+
readPeers(): Promise<ReadResult<PeersFile>>
|
|
157
|
+
writePeers(value: PeersFile): Promise<void>
|
|
158
|
+
readSessionRoles(): Promise<ReadResult<SessionRolesFile>>
|
|
159
|
+
writeSessionRoles(value: SessionRolesFile): Promise<void>
|
|
160
|
+
readTrustedNetworks(): Promise<ReadResult<TrustedNetworksFile>>
|
|
161
|
+
writeTrustedNetworks(value: TrustedNetworksFile): Promise<void>
|
|
162
|
+
/** Forget the network and the identity (a removed machine starts over). The audit log stays. */
|
|
163
|
+
reset(): Promise<void>
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function createNetworkStore(options: NetworkStoreOptions): NetworkStore {
|
|
167
|
+
const dir = join(options.home, 'network')
|
|
168
|
+
const now = options.now ?? Date.now
|
|
169
|
+
const harden =
|
|
170
|
+
options.hardenDirectory ?? ((path: string) => hardenPeerRuntimeDir(path, process.getuid?.()))
|
|
171
|
+
let hardened = false
|
|
172
|
+
const ensure = () => {
|
|
173
|
+
if (hardened) return
|
|
174
|
+
harden(dir)
|
|
175
|
+
hardened = true
|
|
176
|
+
}
|
|
177
|
+
const file = (name: string) => join(dir, name)
|
|
178
|
+
|
|
179
|
+
async function setAside(path: string): Promise<void> {
|
|
180
|
+
await rename(path, `${path}.corrupt-${now()}`).catch(() => undefined)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async function readText(path: string): Promise<string | undefined> {
|
|
184
|
+
try {
|
|
185
|
+
return await readFile(path, 'utf8')
|
|
186
|
+
} catch {
|
|
187
|
+
return undefined
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async function readJson<T>(name: string, schema: z.ZodType<T>): Promise<ReadResult<T>> {
|
|
192
|
+
const path = file(name)
|
|
193
|
+
const text = await readText(path)
|
|
194
|
+
if (text === undefined) return { status: 'missing' }
|
|
195
|
+
try {
|
|
196
|
+
const parsed = schema.safeParse(JSON.parse(text))
|
|
197
|
+
if (parsed.success) return { status: 'ok', value: parsed.data }
|
|
198
|
+
} catch {
|
|
199
|
+
// fall through to corrupt
|
|
200
|
+
}
|
|
201
|
+
await setAside(path)
|
|
202
|
+
return { status: 'corrupt' }
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
async function writeJson(name: string, value: unknown): Promise<void> {
|
|
206
|
+
ensure()
|
|
207
|
+
await atomicWriteFile(file(name), `${JSON.stringify(value, null, 2)}\n`, { mode: FILE_MODE })
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
dir,
|
|
212
|
+
exists: () => existsSync(dir),
|
|
213
|
+
file,
|
|
214
|
+
readMachine: () => readJson('machine.json', MachineFileSchema),
|
|
215
|
+
writeMachine: (v) => writeJson('machine.json', MachineFileSchema.parse(v)),
|
|
216
|
+
async readKey() {
|
|
217
|
+
const path = file('machine.key.pem')
|
|
218
|
+
const text = await readText(path)
|
|
219
|
+
if (text === undefined) return { status: 'missing' }
|
|
220
|
+
try {
|
|
221
|
+
return { status: 'ok', value: importMachineKeyPem(text) }
|
|
222
|
+
} catch {
|
|
223
|
+
await setAside(path)
|
|
224
|
+
return { status: 'corrupt' }
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
async writeKey(key) {
|
|
228
|
+
ensure()
|
|
229
|
+
await atomicWriteFile(file('machine.key.pem'), exportMachineKeyPem(key), { mode: FILE_MODE })
|
|
230
|
+
},
|
|
231
|
+
readCertificate: () => readText(file('machine.cert.pem')),
|
|
232
|
+
async writeCertificate(pem) {
|
|
233
|
+
ensure()
|
|
234
|
+
await atomicWriteFile(file('machine.cert.pem'), pem, { mode: FILE_MODE })
|
|
235
|
+
},
|
|
236
|
+
readNetwork: () => readJson('network.json', NetworkFileSchema),
|
|
237
|
+
writeNetwork: (v) => writeJson('network.json', NetworkFileSchema.parse(v)),
|
|
238
|
+
readMembers: () => readJson('members.json', MembersFileSchema),
|
|
239
|
+
writeMembers: (v) => writeJson('members.json', MembersFileSchema.parse(v)),
|
|
240
|
+
readPeers: () => readJson('peers.json', PeersFileSchema),
|
|
241
|
+
writePeers: (v) => writeJson('peers.json', PeersFileSchema.parse(v)),
|
|
242
|
+
readSessionRoles: () => readJson('session-roles.json', SessionRolesFileSchema),
|
|
243
|
+
writeSessionRoles: (v) => writeJson('session-roles.json', SessionRolesFileSchema.parse(v)),
|
|
244
|
+
readTrustedNetworks: () => readJson('trusted-networks.json', TrustedNetworksFileSchema),
|
|
245
|
+
writeTrustedNetworks: (v) =>
|
|
246
|
+
writeJson('trusted-networks.json', TrustedNetworksFileSchema.parse(v)),
|
|
247
|
+
async reset() {
|
|
248
|
+
for (const name of [
|
|
249
|
+
'machine.json',
|
|
250
|
+
'machine.key.pem',
|
|
251
|
+
'machine.cert.pem',
|
|
252
|
+
'network.json',
|
|
253
|
+
'members.json',
|
|
254
|
+
'peers.json',
|
|
255
|
+
'session-roles.json',
|
|
256
|
+
]) {
|
|
257
|
+
await rm(file(name), { force: true })
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
}
|
|
261
|
+
}
|
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mutually authenticated TLS between machines of one network.
|
|
3
|
+
*
|
|
4
|
+
* Both sides present their machine certificate (`x509.ts`), request the
|
|
5
|
+
* other's, and then pin: the SPKI of the certificate the peer actually used is
|
|
6
|
+
* hashed to a machine id and checked against membership. A connection from a
|
|
7
|
+
* key that is not a member may send exactly `ping_net` and `join_request`, in
|
|
8
|
+
* a 4 KiB line, within two seconds; anything else closes the socket and is
|
|
9
|
+
* audited. Membership is re-checked on every request, so a removal closes
|
|
10
|
+
* even a long-lived connection.
|
|
11
|
+
*
|
|
12
|
+
* Framing is the `namzu-peer/1` one: newline-delimited JSON, one response per
|
|
13
|
+
* request. Nothing here decides what a request means; the service does.
|
|
14
|
+
*
|
|
15
|
+
* @experimental
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { X509Certificate } from 'node:crypto'
|
|
19
|
+
import { type Server, type TLSSocket, connect, createServer } from 'node:tls'
|
|
20
|
+
import type { NetworkClock } from './clock.js'
|
|
21
|
+
import { type MachineKey, exportMachineKeyPem, machineIdOf } from './identity.js'
|
|
22
|
+
import {
|
|
23
|
+
MAX_NET_LINE_BYTES,
|
|
24
|
+
MAX_PREAUTH_LINE_BYTES,
|
|
25
|
+
type NetRequest,
|
|
26
|
+
NetRequestSchema,
|
|
27
|
+
PREAUTH_OPS,
|
|
28
|
+
} from './wire.js'
|
|
29
|
+
|
|
30
|
+
export type NetworkErrorCode =
|
|
31
|
+
| 'unattended'
|
|
32
|
+
| 'off'
|
|
33
|
+
| 'dial'
|
|
34
|
+
| 'timeout'
|
|
35
|
+
| 'not_member'
|
|
36
|
+
| 'bad_frame'
|
|
37
|
+
| 'refused'
|
|
38
|
+
| 'no_network'
|
|
39
|
+
| 'unknown_target'
|
|
40
|
+
| 'invalid'
|
|
41
|
+
|
|
42
|
+
export class NetworkError extends Error {
|
|
43
|
+
override readonly name = 'NetworkError'
|
|
44
|
+
constructor(
|
|
45
|
+
readonly code: NetworkErrorCode,
|
|
46
|
+
message: string,
|
|
47
|
+
) {
|
|
48
|
+
super(message)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** What a machine presents on TLS: its key and its certificate. */
|
|
53
|
+
export interface TlsIdentity {
|
|
54
|
+
readonly key: MachineKey
|
|
55
|
+
readonly certificatePem: string
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface PeerInfo {
|
|
59
|
+
readonly machineId: string
|
|
60
|
+
readonly publicKeyDer: Buffer
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function peerOf(socket: TLSSocket): PeerInfo | undefined {
|
|
64
|
+
const cert = socket.getPeerCertificate(true)
|
|
65
|
+
if (!cert || !cert.raw) return undefined
|
|
66
|
+
try {
|
|
67
|
+
const publicKeyDer = new X509Certificate(cert.raw).publicKey.export({
|
|
68
|
+
type: 'spki',
|
|
69
|
+
format: 'der',
|
|
70
|
+
})
|
|
71
|
+
return { machineId: machineIdOf(publicKeyDer), publicKeyDer }
|
|
72
|
+
} catch {
|
|
73
|
+
return undefined
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export const FIRST_LINE_DEADLINE_MS = 2_000
|
|
78
|
+
export const IDLE_DEADLINE_MS = 30_000
|
|
79
|
+
export const DIAL_DEADLINE_MS = 3_000
|
|
80
|
+
export const MAX_UNAUTH_PER_ADDRESS = 4
|
|
81
|
+
export const MAX_UNAUTH_TOTAL = 16
|
|
82
|
+
export const MAX_AUTH_CONNECTIONS = 32
|
|
83
|
+
|
|
84
|
+
export interface ServerContext {
|
|
85
|
+
readonly peer: PeerInfo
|
|
86
|
+
/** Whether the peer is a member right now. */
|
|
87
|
+
readonly member: boolean
|
|
88
|
+
readonly sourceAddress: string
|
|
89
|
+
/** Keep the connection open past the deadlines (a pending join); the handler owns closing it. */
|
|
90
|
+
holdOpen(): void
|
|
91
|
+
/** Write a further frame on this connection. */
|
|
92
|
+
write(frame: unknown): void
|
|
93
|
+
onClose(callback: () => void): void
|
|
94
|
+
close(): void
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface RefusedConnection {
|
|
98
|
+
readonly sourceAddress: string
|
|
99
|
+
readonly machineId: string | undefined
|
|
100
|
+
readonly reason:
|
|
101
|
+
| 'not_member'
|
|
102
|
+
| 'oversize'
|
|
103
|
+
| 'bad_frame'
|
|
104
|
+
| 'too_many'
|
|
105
|
+
| 'no_certificate'
|
|
106
|
+
| 'deadline'
|
|
107
|
+
readonly op?: string
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface NetListenerOptions {
|
|
111
|
+
readonly identity: TlsIdentity
|
|
112
|
+
readonly clock: NetworkClock
|
|
113
|
+
readonly isMember: (machineId: string) => boolean
|
|
114
|
+
readonly handle: (request: NetRequest, context: ServerContext) => Promise<unknown>
|
|
115
|
+
readonly onRefused?: (info: RefusedConnection) => void
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface NetListener {
|
|
119
|
+
/** Bind and return the port actually bound. */
|
|
120
|
+
listen(host: string, port: number): Promise<number>
|
|
121
|
+
/** Close every open connection of one machine (it was removed). */
|
|
122
|
+
closeMachine(machineId: string): void
|
|
123
|
+
close(): Promise<void>
|
|
124
|
+
readonly connections: number
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function lines(onLine: (line: string) => void, onOversize: () => void, limit: () => number) {
|
|
128
|
+
let buffer = ''
|
|
129
|
+
return (chunk: Buffer) => {
|
|
130
|
+
buffer += chunk.toString('utf8')
|
|
131
|
+
for (;;) {
|
|
132
|
+
const at = buffer.indexOf('\n')
|
|
133
|
+
if (at < 0) break
|
|
134
|
+
const line = buffer.slice(0, at)
|
|
135
|
+
buffer = buffer.slice(at + 1)
|
|
136
|
+
if (Buffer.byteLength(line, 'utf8') > limit()) return onOversize()
|
|
137
|
+
if (line.trim().length > 0) onLine(line)
|
|
138
|
+
}
|
|
139
|
+
if (Buffer.byteLength(buffer, 'utf8') > limit()) onOversize()
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function createNetListener(options: NetListenerOptions): NetListener {
|
|
144
|
+
const sockets = new Set<TLSSocket>()
|
|
145
|
+
const byMachine = new Map<string, Set<TLSSocket>>()
|
|
146
|
+
const unauthByAddress = new Map<string, number>()
|
|
147
|
+
let unauthTotal = 0
|
|
148
|
+
let authTotal = 0
|
|
149
|
+
const servers: Server[] = []
|
|
150
|
+
|
|
151
|
+
const track = (server: Server) => {
|
|
152
|
+
server.on('secureConnection', (socket: TLSSocket) => {
|
|
153
|
+
const sourceAddress = socket.remoteAddress ?? 'unknown'
|
|
154
|
+
sockets.add(socket)
|
|
155
|
+
socket.on('error', () => socket.destroy())
|
|
156
|
+
const peer = peerOf(socket)
|
|
157
|
+
const refuse = (reason: RefusedConnection['reason'], op?: string) => {
|
|
158
|
+
options.onRefused?.({ sourceAddress, machineId: peer?.machineId, reason, op })
|
|
159
|
+
socket.destroy()
|
|
160
|
+
}
|
|
161
|
+
if (!peer) return refuse('no_certificate')
|
|
162
|
+
|
|
163
|
+
let counted: 'auth' | 'unauth' | undefined
|
|
164
|
+
let held = false
|
|
165
|
+
let cancelDeadline: (() => void) | undefined
|
|
166
|
+
const closers: Array<() => void> = []
|
|
167
|
+
const memberNow = () => options.isMember(peer.machineId)
|
|
168
|
+
const count = (kind: 'auth' | 'unauth') => {
|
|
169
|
+
counted = kind
|
|
170
|
+
if (kind === 'auth') {
|
|
171
|
+
authTotal++
|
|
172
|
+
const set = byMachine.get(peer.machineId) ?? new Set<TLSSocket>()
|
|
173
|
+
byMachine.set(peer.machineId, set)
|
|
174
|
+
set.add(socket)
|
|
175
|
+
} else {
|
|
176
|
+
unauthTotal++
|
|
177
|
+
unauthByAddress.set(sourceAddress, (unauthByAddress.get(sourceAddress) ?? 0) + 1)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const uncount = () => {
|
|
181
|
+
if (counted === 'auth') {
|
|
182
|
+
authTotal--
|
|
183
|
+
byMachine.get(peer.machineId)?.delete(socket)
|
|
184
|
+
} else if (counted === 'unauth') {
|
|
185
|
+
unauthTotal--
|
|
186
|
+
const n = (unauthByAddress.get(sourceAddress) ?? 1) - 1
|
|
187
|
+
if (n <= 0) unauthByAddress.delete(sourceAddress)
|
|
188
|
+
else unauthByAddress.set(sourceAddress, n)
|
|
189
|
+
}
|
|
190
|
+
counted = undefined
|
|
191
|
+
}
|
|
192
|
+
const isMember = memberNow()
|
|
193
|
+
if (isMember) {
|
|
194
|
+
if (authTotal >= MAX_AUTH_CONNECTIONS) return refuse('too_many')
|
|
195
|
+
count('auth')
|
|
196
|
+
} else {
|
|
197
|
+
if (
|
|
198
|
+
unauthTotal >= MAX_UNAUTH_TOTAL ||
|
|
199
|
+
(unauthByAddress.get(sourceAddress) ?? 0) >= MAX_UNAUTH_PER_ADDRESS
|
|
200
|
+
) {
|
|
201
|
+
return refuse('too_many')
|
|
202
|
+
}
|
|
203
|
+
count('unauth')
|
|
204
|
+
}
|
|
205
|
+
socket.on('close', () => {
|
|
206
|
+
cancelDeadline?.()
|
|
207
|
+
uncount()
|
|
208
|
+
sockets.delete(socket)
|
|
209
|
+
for (const c of closers) c()
|
|
210
|
+
})
|
|
211
|
+
const arm = (ms: number, reason: 'deadline') => {
|
|
212
|
+
cancelDeadline?.()
|
|
213
|
+
cancelDeadline = options.clock.setTimer(() => {
|
|
214
|
+
if (!held) refuse(reason)
|
|
215
|
+
}, ms)
|
|
216
|
+
}
|
|
217
|
+
arm(FIRST_LINE_DEADLINE_MS, 'deadline')
|
|
218
|
+
|
|
219
|
+
let queue: Promise<void> = Promise.resolve()
|
|
220
|
+
const context: ServerContext = {
|
|
221
|
+
peer,
|
|
222
|
+
get member() {
|
|
223
|
+
return memberNow()
|
|
224
|
+
},
|
|
225
|
+
sourceAddress,
|
|
226
|
+
holdOpen() {
|
|
227
|
+
held = true
|
|
228
|
+
cancelDeadline?.()
|
|
229
|
+
},
|
|
230
|
+
write(frame) {
|
|
231
|
+
if (!socket.destroyed) socket.write(`${JSON.stringify(frame)}\n`)
|
|
232
|
+
},
|
|
233
|
+
onClose(cb) {
|
|
234
|
+
closers.push(cb)
|
|
235
|
+
},
|
|
236
|
+
close() {
|
|
237
|
+
socket.end()
|
|
238
|
+
},
|
|
239
|
+
}
|
|
240
|
+
const handleLine = (line: string) => {
|
|
241
|
+
cancelDeadline?.()
|
|
242
|
+
const member = memberNow()
|
|
243
|
+
if (isMember && !member) return refuse('not_member')
|
|
244
|
+
if (!member && counted === 'auth') return refuse('not_member')
|
|
245
|
+
let parsed: unknown
|
|
246
|
+
try {
|
|
247
|
+
parsed = JSON.parse(line)
|
|
248
|
+
} catch {
|
|
249
|
+
return refuse('bad_frame')
|
|
250
|
+
}
|
|
251
|
+
const request = NetRequestSchema.safeParse(parsed)
|
|
252
|
+
if (!request.success) {
|
|
253
|
+
socket.write(`${JSON.stringify({ error: 'bad_request' })}\n`)
|
|
254
|
+
return refuse('bad_frame')
|
|
255
|
+
}
|
|
256
|
+
if (!member && !PREAUTH_OPS.has(request.data.op))
|
|
257
|
+
return refuse('not_member', request.data.op)
|
|
258
|
+
queue = queue.then(async () => {
|
|
259
|
+
try {
|
|
260
|
+
const response = await options.handle(request.data, context)
|
|
261
|
+
if (!socket.destroyed && response !== undefined) context.write(response)
|
|
262
|
+
} catch {
|
|
263
|
+
if (!socket.destroyed) context.write({ error: 'internal' })
|
|
264
|
+
}
|
|
265
|
+
if (!held && !socket.destroyed)
|
|
266
|
+
arm(member ? IDLE_DEADLINE_MS : FIRST_LINE_DEADLINE_MS, 'deadline')
|
|
267
|
+
})
|
|
268
|
+
}
|
|
269
|
+
socket.on(
|
|
270
|
+
'data',
|
|
271
|
+
lines(
|
|
272
|
+
handleLine,
|
|
273
|
+
() => refuse('oversize'),
|
|
274
|
+
() => (memberNow() ? MAX_NET_LINE_BYTES : MAX_PREAUTH_LINE_BYTES),
|
|
275
|
+
),
|
|
276
|
+
)
|
|
277
|
+
})
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return {
|
|
281
|
+
async listen(host, port) {
|
|
282
|
+
const server = createServer({
|
|
283
|
+
key: exportMachineKeyPem(options.identity.key),
|
|
284
|
+
cert: options.identity.certificatePem,
|
|
285
|
+
requestCert: true,
|
|
286
|
+
rejectUnauthorized: false,
|
|
287
|
+
minVersion: 'TLSv1.3',
|
|
288
|
+
handshakeTimeout: 10_000,
|
|
289
|
+
})
|
|
290
|
+
server.maxConnections = 64
|
|
291
|
+
server.on('tlsClientError', () => undefined)
|
|
292
|
+
track(server)
|
|
293
|
+
await new Promise<void>((resolve, reject) => {
|
|
294
|
+
server.once('error', reject)
|
|
295
|
+
server.listen({ host, port }, () => {
|
|
296
|
+
server.off('error', reject)
|
|
297
|
+
resolve()
|
|
298
|
+
})
|
|
299
|
+
})
|
|
300
|
+
servers.push(server)
|
|
301
|
+
return (server.address() as { port: number }).port
|
|
302
|
+
},
|
|
303
|
+
closeMachine(machineId) {
|
|
304
|
+
for (const s of [...(byMachine.get(machineId) ?? [])]) s.destroy()
|
|
305
|
+
},
|
|
306
|
+
async close() {
|
|
307
|
+
for (const s of sockets) s.destroy()
|
|
308
|
+
await Promise.all(servers.splice(0).map((s) => new Promise<void>((r) => s.close(() => r()))))
|
|
309
|
+
},
|
|
310
|
+
get connections() {
|
|
311
|
+
return sockets.size
|
|
312
|
+
},
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export interface DialOptions {
|
|
317
|
+
readonly identity: TlsIdentity
|
|
318
|
+
readonly host: string
|
|
319
|
+
readonly port: number
|
|
320
|
+
readonly clock: NetworkClock
|
|
321
|
+
/** Refuse to continue unless the peer is this machine. */
|
|
322
|
+
readonly expectMachineId?: string
|
|
323
|
+
/** Refuse to continue unless this says the peer is acceptable (for example, a member). */
|
|
324
|
+
readonly accept?: (peer: PeerInfo) => boolean
|
|
325
|
+
readonly dialDeadlineMs?: number
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export interface NetClient {
|
|
329
|
+
readonly peer: PeerInfo
|
|
330
|
+
/** Send one request and wait for the next frame. */
|
|
331
|
+
request(request: object, deadlineMs?: number): Promise<unknown>
|
|
332
|
+
/** Wait for the next frame, with no deadline (a pending join). */
|
|
333
|
+
nextFrame(): Promise<unknown>
|
|
334
|
+
close(): void
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export const REQUEST_DEADLINE_MS = 2_000
|
|
338
|
+
|
|
339
|
+
export function dialNet(options: DialOptions): Promise<NetClient> {
|
|
340
|
+
return new Promise((resolve, reject) => {
|
|
341
|
+
const socket = connect({
|
|
342
|
+
host: options.host.split('%')[0],
|
|
343
|
+
port: options.port,
|
|
344
|
+
key: exportMachineKeyPem(options.identity.key),
|
|
345
|
+
cert: options.identity.certificatePem,
|
|
346
|
+
rejectUnauthorized: false,
|
|
347
|
+
minVersion: 'TLSv1.3',
|
|
348
|
+
})
|
|
349
|
+
const frames: unknown[] = []
|
|
350
|
+
const waiters: Array<{ resolve: (v: unknown) => void; reject: (e: Error) => void }> = []
|
|
351
|
+
let dead: Error | undefined
|
|
352
|
+
const fail = (error: Error) => {
|
|
353
|
+
dead ??= error
|
|
354
|
+
for (const w of waiters.splice(0)) w.reject(error)
|
|
355
|
+
socket.destroy()
|
|
356
|
+
}
|
|
357
|
+
const cancelDial = options.clock.setTimer(() => {
|
|
358
|
+
if (!settled) {
|
|
359
|
+
settled = true
|
|
360
|
+
reject(new NetworkError('timeout', 'The other machine did not answer in time.'))
|
|
361
|
+
socket.destroy()
|
|
362
|
+
}
|
|
363
|
+
}, options.dialDeadlineMs ?? DIAL_DEADLINE_MS)
|
|
364
|
+
let settled = false
|
|
365
|
+
socket.on('error', (err) => {
|
|
366
|
+
if (!settled) {
|
|
367
|
+
settled = true
|
|
368
|
+
cancelDial()
|
|
369
|
+
reject(new NetworkError('dial', `Could not connect: ${err.message}`))
|
|
370
|
+
}
|
|
371
|
+
fail(new NetworkError('dial', 'The connection failed.'))
|
|
372
|
+
})
|
|
373
|
+
socket.on('close', () => fail(new NetworkError('dial', 'The connection closed.')))
|
|
374
|
+
socket.on(
|
|
375
|
+
'data',
|
|
376
|
+
lines(
|
|
377
|
+
(line) => {
|
|
378
|
+
let value: unknown
|
|
379
|
+
try {
|
|
380
|
+
value = JSON.parse(line)
|
|
381
|
+
} catch {
|
|
382
|
+
return fail(
|
|
383
|
+
new NetworkError('bad_frame', 'The other machine sent something unreadable.'),
|
|
384
|
+
)
|
|
385
|
+
}
|
|
386
|
+
const waiter = waiters.shift()
|
|
387
|
+
if (waiter) waiter.resolve(value)
|
|
388
|
+
else frames.push(value)
|
|
389
|
+
},
|
|
390
|
+
() => fail(new NetworkError('bad_frame', 'The other machine sent too much.')),
|
|
391
|
+
() => MAX_NET_LINE_BYTES,
|
|
392
|
+
),
|
|
393
|
+
)
|
|
394
|
+
socket.once('secureConnect', () => {
|
|
395
|
+
cancelDial()
|
|
396
|
+
if (settled) return
|
|
397
|
+
const peer = peerOf(socket)
|
|
398
|
+
if (!peer) {
|
|
399
|
+
settled = true
|
|
400
|
+
socket.destroy()
|
|
401
|
+
return reject(
|
|
402
|
+
new NetworkError('not_member', 'The other machine did not present a certificate.'),
|
|
403
|
+
)
|
|
404
|
+
}
|
|
405
|
+
if (
|
|
406
|
+
(options.expectMachineId !== undefined && peer.machineId !== options.expectMachineId) ||
|
|
407
|
+
(options.accept && !options.accept(peer))
|
|
408
|
+
) {
|
|
409
|
+
settled = true
|
|
410
|
+
socket.destroy()
|
|
411
|
+
return reject(new NetworkError('not_member', 'That machine is not the one expected.'))
|
|
412
|
+
}
|
|
413
|
+
settled = true
|
|
414
|
+
const next = (): Promise<unknown> => {
|
|
415
|
+
if (frames.length > 0) return Promise.resolve(frames.shift())
|
|
416
|
+
if (dead) return Promise.reject(dead)
|
|
417
|
+
return new Promise((res, rej) => waiters.push({ resolve: res, reject: rej }))
|
|
418
|
+
}
|
|
419
|
+
resolve({
|
|
420
|
+
peer,
|
|
421
|
+
nextFrame: next,
|
|
422
|
+
request(request, deadlineMs = REQUEST_DEADLINE_MS) {
|
|
423
|
+
socket.write(`${JSON.stringify(request)}\n`)
|
|
424
|
+
return new Promise<unknown>((res, rej) => {
|
|
425
|
+
const cancel = options.clock.setTimer(
|
|
426
|
+
() => rej(new NetworkError('timeout', 'The other machine did not answer in time.')),
|
|
427
|
+
deadlineMs,
|
|
428
|
+
)
|
|
429
|
+
next().then(
|
|
430
|
+
(v) => {
|
|
431
|
+
cancel()
|
|
432
|
+
res(v)
|
|
433
|
+
},
|
|
434
|
+
(e) => {
|
|
435
|
+
cancel()
|
|
436
|
+
rej(e)
|
|
437
|
+
},
|
|
438
|
+
)
|
|
439
|
+
})
|
|
440
|
+
},
|
|
441
|
+
close: () => socket.destroy(),
|
|
442
|
+
})
|
|
443
|
+
})
|
|
444
|
+
})
|
|
445
|
+
}
|