@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,485 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DNS-SD over multicast DNS for the Namzu network, with a codec for exactly the
|
|
3
|
+
* subset it needs and no dependency (`node:dgram` only, injected).
|
|
4
|
+
*
|
|
5
|
+
* Service: `_namzu-net._tcp.local`. One instance per machine, labelled
|
|
6
|
+
* `namzu-<8 random hex>` (random per process start), and a target host
|
|
7
|
+
* `namzu-<same 8 hex>.local`. The TXT record carries two keys, `v=1` and
|
|
8
|
+
* `n=<netId>`. Nothing else is announced: no hostname, no machine name, no
|
|
9
|
+
* session title, no machine id. A stranger learns that "a Namzu network `n` has
|
|
10
|
+
* a listener at this address and port" and nothing more.
|
|
11
|
+
*
|
|
12
|
+
* Subset of RFC 6762 / 6763 implemented:
|
|
13
|
+
* - records PTR (12), SRV (33), TXT (16), A (1); AAAA (28) is decoded and
|
|
14
|
+
* ignored (phase 1 listens and announces on IPv4 only);
|
|
15
|
+
* - questions for the service's PTR; answers carrying the whole instance;
|
|
16
|
+
* - names on the wire without compression when sending, with compression
|
|
17
|
+
* pointers followed (bounded) when reading;
|
|
18
|
+
* - TTL 0 on the PTR as a goodbye;
|
|
19
|
+
* - UDP 5353 on 224.0.0.251, `reuseAddr`, one membership per private interface.
|
|
20
|
+
*
|
|
21
|
+
* Packets are capped at 1500 bytes in both directions; labels at 63 bytes and
|
|
22
|
+
* names at 255; sections at 64 records. Anything malformed is dropped silently.
|
|
23
|
+
*
|
|
24
|
+
* @experimental
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { randomBytes } from 'node:crypto'
|
|
28
|
+
import type { NetworkClock } from './clock.js'
|
|
29
|
+
import { isPrivateNetworkAddress } from './discovery.js'
|
|
30
|
+
import type {
|
|
31
|
+
Advertisement,
|
|
32
|
+
DiscoveredEndpoint,
|
|
33
|
+
ListenAddress,
|
|
34
|
+
NetworkDiscovery,
|
|
35
|
+
} from './discovery.js'
|
|
36
|
+
|
|
37
|
+
export const MDNS_PORT = 5353
|
|
38
|
+
export const MDNS_GROUP = '224.0.0.251'
|
|
39
|
+
export const SERVICE_NAME = '_namzu-net._tcp.local'
|
|
40
|
+
export const MAX_PACKET_BYTES = 1500
|
|
41
|
+
export const RECORD_TTL_SECONDS = 120
|
|
42
|
+
export const REQUERY_MS = 60_000
|
|
43
|
+
|
|
44
|
+
const TYPE = { A: 1, PTR: 12, TXT: 16, AAAA: 28, SRV: 33 } as const
|
|
45
|
+
const CLASS_IN = 1
|
|
46
|
+
const CACHE_FLUSH = 0x8000
|
|
47
|
+
const MAX_LABEL = 63
|
|
48
|
+
const MAX_NAME = 255
|
|
49
|
+
const MAX_RECORDS = 64
|
|
50
|
+
|
|
51
|
+
export type DnsData =
|
|
52
|
+
| { readonly type: 'PTR'; readonly target: string }
|
|
53
|
+
| { readonly type: 'SRV'; readonly port: number; readonly target: string }
|
|
54
|
+
| { readonly type: 'TXT'; readonly entries: readonly string[] }
|
|
55
|
+
| { readonly type: 'A'; readonly address: string }
|
|
56
|
+
| { readonly type: 'AAAA' }
|
|
57
|
+
|
|
58
|
+
export interface DnsRecord {
|
|
59
|
+
readonly name: string
|
|
60
|
+
readonly ttl: number
|
|
61
|
+
readonly data: DnsData
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface DnsMessage {
|
|
65
|
+
readonly questions: readonly { readonly name: string; readonly type: number }[]
|
|
66
|
+
readonly answers: readonly DnsRecord[]
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function encodeName(name: string): Buffer {
|
|
70
|
+
const labels = name.split('.').filter((l) => l.length > 0)
|
|
71
|
+
const parts: Buffer[] = []
|
|
72
|
+
let total = 1
|
|
73
|
+
for (const label of labels) {
|
|
74
|
+
const bytes = Buffer.from(label, 'utf8')
|
|
75
|
+
if (bytes.length === 0 || bytes.length > MAX_LABEL) throw new RangeError('label length')
|
|
76
|
+
total += bytes.length + 1
|
|
77
|
+
parts.push(Buffer.from([bytes.length]), bytes)
|
|
78
|
+
}
|
|
79
|
+
if (total > MAX_NAME) throw new RangeError('name length')
|
|
80
|
+
parts.push(Buffer.from([0]))
|
|
81
|
+
return Buffer.concat(parts)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function u16(n: number): Buffer {
|
|
85
|
+
const b = Buffer.alloc(2)
|
|
86
|
+
b.writeUInt16BE(n)
|
|
87
|
+
return b
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function u32(n: number): Buffer {
|
|
91
|
+
const b = Buffer.alloc(4)
|
|
92
|
+
b.writeUInt32BE(n)
|
|
93
|
+
return b
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function encodeRecord(record: DnsRecord): Buffer {
|
|
97
|
+
let type: number
|
|
98
|
+
let rdata: Buffer
|
|
99
|
+
const d = record.data
|
|
100
|
+
switch (d.type) {
|
|
101
|
+
case 'PTR':
|
|
102
|
+
type = TYPE.PTR
|
|
103
|
+
rdata = encodeName(d.target)
|
|
104
|
+
break
|
|
105
|
+
case 'SRV':
|
|
106
|
+
type = TYPE.SRV
|
|
107
|
+
rdata = Buffer.concat([u16(0), u16(0), u16(d.port), encodeName(d.target)])
|
|
108
|
+
break
|
|
109
|
+
case 'TXT': {
|
|
110
|
+
type = TYPE.TXT
|
|
111
|
+
const parts = d.entries.map((e) => {
|
|
112
|
+
const bytes = Buffer.from(e, 'utf8')
|
|
113
|
+
if (bytes.length > 255) throw new RangeError('txt entry')
|
|
114
|
+
return Buffer.concat([Buffer.from([bytes.length]), bytes])
|
|
115
|
+
})
|
|
116
|
+
rdata = parts.length > 0 ? Buffer.concat(parts) : Buffer.from([0])
|
|
117
|
+
break
|
|
118
|
+
}
|
|
119
|
+
case 'A': {
|
|
120
|
+
type = TYPE.A
|
|
121
|
+
rdata = Buffer.from(d.address.split('.').map(Number))
|
|
122
|
+
if (rdata.length !== 4) throw new RangeError('address')
|
|
123
|
+
break
|
|
124
|
+
}
|
|
125
|
+
case 'AAAA':
|
|
126
|
+
throw new RangeError('AAAA is not announced')
|
|
127
|
+
}
|
|
128
|
+
const cls = type === TYPE.PTR ? CLASS_IN : CLASS_IN | CACHE_FLUSH
|
|
129
|
+
return Buffer.concat([
|
|
130
|
+
encodeName(record.name),
|
|
131
|
+
u16(type),
|
|
132
|
+
u16(cls),
|
|
133
|
+
u32(record.ttl),
|
|
134
|
+
u16(rdata.length),
|
|
135
|
+
rdata,
|
|
136
|
+
])
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function header(questions: number, answers: number, response: boolean): Buffer {
|
|
140
|
+
return Buffer.concat([
|
|
141
|
+
u16(0),
|
|
142
|
+
u16(response ? 0x8400 : 0),
|
|
143
|
+
u16(questions),
|
|
144
|
+
u16(answers),
|
|
145
|
+
u16(0),
|
|
146
|
+
u16(0),
|
|
147
|
+
])
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** A query for the Namzu service: one PTR question. */
|
|
151
|
+
export function encodeQuery(): Buffer {
|
|
152
|
+
return Buffer.concat([
|
|
153
|
+
header(1, 0, false),
|
|
154
|
+
encodeName(SERVICE_NAME),
|
|
155
|
+
u16(TYPE.PTR),
|
|
156
|
+
u16(CLASS_IN),
|
|
157
|
+
])
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export interface InstanceAnnouncement {
|
|
161
|
+
/** Random per process start: `namzu-<8 hex>`. */
|
|
162
|
+
readonly instance: string
|
|
163
|
+
readonly netId: string
|
|
164
|
+
readonly port: number
|
|
165
|
+
/** IPv4 addresses only. */
|
|
166
|
+
readonly addresses: readonly string[]
|
|
167
|
+
readonly ttl?: number
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function instanceFullName(instance: string): string {
|
|
171
|
+
return `${instance}.${SERVICE_NAME}`
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** The records of one announcement: PTR, SRV, TXT and A. A TTL of 0 is the goodbye. */
|
|
175
|
+
export function announcementRecords(a: InstanceAnnouncement): DnsRecord[] {
|
|
176
|
+
const ttl = a.ttl ?? RECORD_TTL_SECONDS
|
|
177
|
+
const host = `${a.instance}.local`
|
|
178
|
+
const full = instanceFullName(a.instance)
|
|
179
|
+
return [
|
|
180
|
+
{ name: SERVICE_NAME, ttl, data: { type: 'PTR', target: full } },
|
|
181
|
+
{ name: full, ttl, data: { type: 'SRV', port: a.port, target: host } },
|
|
182
|
+
{ name: full, ttl, data: { type: 'TXT', entries: ['v=1', `n=${a.netId}`] } },
|
|
183
|
+
...a.addresses.map((address): DnsRecord => ({ name: host, ttl, data: { type: 'A', address } })),
|
|
184
|
+
]
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function encodeAnnouncement(a: InstanceAnnouncement): Buffer {
|
|
188
|
+
const records = announcementRecords(a)
|
|
189
|
+
const out = Buffer.concat([header(0, records.length, true), ...records.map(encodeRecord)])
|
|
190
|
+
if (out.length > MAX_PACKET_BYTES) throw new RangeError('announcement too large')
|
|
191
|
+
return out
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function readName(buf: Buffer, start: number): { name: string; next: number } | undefined {
|
|
195
|
+
const labels: string[] = []
|
|
196
|
+
let pos = start
|
|
197
|
+
let next: number | undefined
|
|
198
|
+
let jumps = 0
|
|
199
|
+
let total = 0
|
|
200
|
+
for (;;) {
|
|
201
|
+
if (pos >= buf.length) return undefined
|
|
202
|
+
const len = buf[pos] as number
|
|
203
|
+
if (len === 0) {
|
|
204
|
+
pos += 1
|
|
205
|
+
break
|
|
206
|
+
}
|
|
207
|
+
if ((len & 0xc0) === 0xc0) {
|
|
208
|
+
if (pos + 1 >= buf.length) return undefined
|
|
209
|
+
const target = ((len & 0x3f) << 8) | (buf[pos + 1] as number)
|
|
210
|
+
if (next === undefined) next = pos + 2
|
|
211
|
+
if (++jumps > 8 || target >= buf.length) return undefined
|
|
212
|
+
pos = target
|
|
213
|
+
continue
|
|
214
|
+
}
|
|
215
|
+
if ((len & 0xc0) !== 0 || len > MAX_LABEL || pos + 1 + len > buf.length) return undefined
|
|
216
|
+
total += len + 1
|
|
217
|
+
if (total > MAX_NAME) return undefined
|
|
218
|
+
labels.push(buf.toString('utf8', pos + 1, pos + 1 + len))
|
|
219
|
+
pos += 1 + len
|
|
220
|
+
}
|
|
221
|
+
return { name: labels.join('.'), next: next ?? pos }
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** Decode a message; undefined for anything malformed or over the caps. Never throws. */
|
|
225
|
+
export function decodeMessage(buf: Buffer): DnsMessage | undefined {
|
|
226
|
+
try {
|
|
227
|
+
if (buf.length < 12 || buf.length > MAX_PACKET_BYTES) return undefined
|
|
228
|
+
const qd = buf.readUInt16BE(4)
|
|
229
|
+
const an = buf.readUInt16BE(6)
|
|
230
|
+
if (qd > MAX_RECORDS || an > MAX_RECORDS) return undefined
|
|
231
|
+
let pos = 12
|
|
232
|
+
const questions: { name: string; type: number }[] = []
|
|
233
|
+
for (let i = 0; i < qd; i++) {
|
|
234
|
+
const n = readName(buf, pos)
|
|
235
|
+
if (!n || n.next + 4 > buf.length) return undefined
|
|
236
|
+
questions.push({ name: n.name, type: buf.readUInt16BE(n.next) })
|
|
237
|
+
pos = n.next + 4
|
|
238
|
+
}
|
|
239
|
+
const answers: DnsRecord[] = []
|
|
240
|
+
for (let i = 0; i < an; i++) {
|
|
241
|
+
const n = readName(buf, pos)
|
|
242
|
+
if (!n || n.next + 10 > buf.length) return undefined
|
|
243
|
+
const type = buf.readUInt16BE(n.next)
|
|
244
|
+
const ttl = buf.readUInt32BE(n.next + 4)
|
|
245
|
+
const rdlen = buf.readUInt16BE(n.next + 8)
|
|
246
|
+
const rstart = n.next + 10
|
|
247
|
+
if (rstart + rdlen > buf.length) return undefined
|
|
248
|
+
pos = rstart + rdlen
|
|
249
|
+
let data: DnsData | undefined
|
|
250
|
+
if (type === TYPE.PTR) {
|
|
251
|
+
const t = readName(buf, rstart)
|
|
252
|
+
if (t) data = { type: 'PTR', target: t.name }
|
|
253
|
+
} else if (type === TYPE.SRV && rdlen >= 7) {
|
|
254
|
+
const t = readName(buf, rstart + 6)
|
|
255
|
+
if (t) data = { type: 'SRV', port: buf.readUInt16BE(rstart + 4), target: t.name }
|
|
256
|
+
} else if (type === TYPE.TXT) {
|
|
257
|
+
const entries: string[] = []
|
|
258
|
+
let p = rstart
|
|
259
|
+
while (p < rstart + rdlen) {
|
|
260
|
+
const l = buf[p] as number
|
|
261
|
+
if (p + 1 + l > rstart + rdlen) return undefined
|
|
262
|
+
if (l > 0) entries.push(buf.toString('utf8', p + 1, p + 1 + l))
|
|
263
|
+
p += 1 + l
|
|
264
|
+
}
|
|
265
|
+
data = { type: 'TXT', entries }
|
|
266
|
+
} else if (type === TYPE.A && rdlen === 4) {
|
|
267
|
+
data = { type: 'A', address: [...buf.subarray(rstart, rstart + 4)].join('.') }
|
|
268
|
+
} else if (type === TYPE.AAAA) {
|
|
269
|
+
data = { type: 'AAAA' }
|
|
270
|
+
}
|
|
271
|
+
if (data) answers.push({ name: n.name, ttl, data })
|
|
272
|
+
}
|
|
273
|
+
return { questions, answers }
|
|
274
|
+
} catch {
|
|
275
|
+
return undefined
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export interface FoundInstance {
|
|
280
|
+
readonly instance: string
|
|
281
|
+
readonly netId: string
|
|
282
|
+
readonly port: number
|
|
283
|
+
readonly addresses: readonly string[]
|
|
284
|
+
readonly goodbye: boolean
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Join the PTR, SRV, TXT and A records of a message into the instances of the Namzu service they describe.
|
|
289
|
+
* An instance is reported only when it carries a port, a valid `n` and at least one address (or is a goodbye).
|
|
290
|
+
*/
|
|
291
|
+
export function instancesFrom(message: DnsMessage): FoundInstance[] {
|
|
292
|
+
const ptrs = message.answers.filter(
|
|
293
|
+
(r) => r.name.toLowerCase() === SERVICE_NAME && r.data.type === 'PTR',
|
|
294
|
+
)
|
|
295
|
+
const out: FoundInstance[] = []
|
|
296
|
+
for (const ptr of ptrs) {
|
|
297
|
+
if (ptr.data.type !== 'PTR') continue
|
|
298
|
+
const full = ptr.data.target
|
|
299
|
+
const suffix = `.${SERVICE_NAME}`
|
|
300
|
+
if (!full.toLowerCase().endsWith(suffix)) continue
|
|
301
|
+
const instance = full.slice(0, full.length - suffix.length)
|
|
302
|
+
const srv = message.answers.find((r) => r.name === full && r.data.type === 'SRV')
|
|
303
|
+
const txt = message.answers.find((r) => r.name === full && r.data.type === 'TXT')
|
|
304
|
+
if (!srv || srv.data.type !== 'SRV') continue
|
|
305
|
+
let netId: string | undefined
|
|
306
|
+
let version: string | undefined
|
|
307
|
+
if (txt && txt.data.type === 'TXT') {
|
|
308
|
+
for (const e of txt.data.entries) {
|
|
309
|
+
if (e.startsWith('n=')) netId = e.slice(2)
|
|
310
|
+
if (e.startsWith('v=')) version = e.slice(2)
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (version !== '1' || netId === undefined || !/^[0-9a-f]{16}$/.test(netId)) continue
|
|
314
|
+
const target = srv.data.target
|
|
315
|
+
const addresses = message.answers
|
|
316
|
+
.filter((r) => r.name === target && r.data.type === 'A')
|
|
317
|
+
.map((r) => (r.data.type === 'A' ? r.data.address : ''))
|
|
318
|
+
.filter((a) => a.length > 0)
|
|
319
|
+
const goodbye = ptr.ttl === 0
|
|
320
|
+
if (addresses.length === 0 && !goodbye) continue
|
|
321
|
+
out.push({ instance, netId, port: srv.data.port, addresses, goodbye })
|
|
322
|
+
}
|
|
323
|
+
return out
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** The slice of `node:dgram` this module uses; tests supply a fake. */
|
|
327
|
+
export interface DgramSocketLike {
|
|
328
|
+
on(
|
|
329
|
+
event: 'message',
|
|
330
|
+
listener: (msg: Buffer, rinfo: { address: string; port: number }) => void,
|
|
331
|
+
): unknown
|
|
332
|
+
on(event: 'error', listener: (error: Error) => void): unknown
|
|
333
|
+
bind(port: number, callback?: () => void): unknown
|
|
334
|
+
addMembership(group: string, iface?: string): void
|
|
335
|
+
setMulticastTTL?(ttl: number): void
|
|
336
|
+
setMulticastLoopback?(flag: boolean): void
|
|
337
|
+
send(msg: Buffer, port: number, address: string, callback?: (error: Error | null) => void): void
|
|
338
|
+
close(callback?: () => void): void
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export interface DgramLike {
|
|
342
|
+
createSocket(options: { type: 'udp4'; reuseAddr: boolean }): DgramSocketLike
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export interface MdnsOptions {
|
|
346
|
+
readonly dgram: DgramLike
|
|
347
|
+
/** IPv4 addresses of the private interfaces to join and announce on. */
|
|
348
|
+
readonly interfaces: () => readonly ListenAddress[]
|
|
349
|
+
readonly clock: NetworkClock
|
|
350
|
+
/** Injected for tests; defaults to `crypto.randomBytes`. */
|
|
351
|
+
readonly randomHex?: () => string
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const MAX_KNOWN_INSTANCES = 64
|
|
355
|
+
|
|
356
|
+
export function createMdnsDiscovery(options: MdnsOptions): NetworkDiscovery {
|
|
357
|
+
const foundListeners = new Set<(e: DiscoveredEndpoint) => void>()
|
|
358
|
+
const lostListeners = new Set<(e: DiscoveredEndpoint) => void>()
|
|
359
|
+
const instance = `namzu-${(options.randomHex ?? (() => randomBytes(4).toString('hex')))()}`
|
|
360
|
+
const known = new Map<string, DiscoveredEndpoint[]>()
|
|
361
|
+
let socket: DgramSocketLike | undefined
|
|
362
|
+
let ad: Advertisement | undefined
|
|
363
|
+
let cancelRequery: (() => void) | undefined
|
|
364
|
+
let closed = false
|
|
365
|
+
|
|
366
|
+
const send = (packet: Buffer) => {
|
|
367
|
+
socket?.send(packet, MDNS_PORT, MDNS_GROUP, () => undefined)
|
|
368
|
+
}
|
|
369
|
+
const announce = (ttl?: number) => {
|
|
370
|
+
if (!ad) return
|
|
371
|
+
const addresses = ad.addresses.filter((a) => /^\d+\.\d+\.\d+\.\d+$/.test(a))
|
|
372
|
+
if (addresses.length === 0) return
|
|
373
|
+
try {
|
|
374
|
+
send(encodeAnnouncement({ instance, netId: ad.netId, port: ad.port, addresses, ttl }))
|
|
375
|
+
} catch {
|
|
376
|
+
// an over-large or malformed announcement is not sent
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
const requery = () => {
|
|
380
|
+
if (closed) return
|
|
381
|
+
send(encodeQuery())
|
|
382
|
+
cancelRequery = options.clock.setTimer(requery, REQUERY_MS)
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const onMessage = (msg: Buffer, rinfo?: { address: string; port: number }) => {
|
|
386
|
+
// A packet from a public or malformed source is dropped: only private networks are served.
|
|
387
|
+
const source = rinfo?.address
|
|
388
|
+
if (source !== undefined && !isPrivateNetworkAddress(source)) return
|
|
389
|
+
const message = decodeMessage(msg)
|
|
390
|
+
if (!message) return
|
|
391
|
+
if (
|
|
392
|
+
ad &&
|
|
393
|
+
message.questions.some((q) => q.name.toLowerCase() === SERVICE_NAME && q.type === TYPE.PTR)
|
|
394
|
+
)
|
|
395
|
+
announce()
|
|
396
|
+
for (const found of instancesFrom(message)) {
|
|
397
|
+
if (found.instance === instance) continue
|
|
398
|
+
// An announcement may only name addresses that are the sender's or on its subnet,
|
|
399
|
+
// so a host cannot send every member to a third machine.
|
|
400
|
+
const sameSubnet = (a: string) =>
|
|
401
|
+
source === undefined ||
|
|
402
|
+
a === source ||
|
|
403
|
+
(isPrivateNetworkAddress(a) &&
|
|
404
|
+
a.split('.').slice(0, 3).join('.') === source.split('.').slice(0, 3).join('.'))
|
|
405
|
+
const addresses = found.addresses.filter(sameSubnet)
|
|
406
|
+
if (addresses.length === 0 && !found.goodbye) continue
|
|
407
|
+
if (!known.has(found.instance) && known.size >= MAX_KNOWN_INSTANCES) continue
|
|
408
|
+
const endpoints = addresses.map(
|
|
409
|
+
(host): DiscoveredEndpoint => ({ netId: found.netId, host, port: found.port }),
|
|
410
|
+
)
|
|
411
|
+
if (found.goodbye) {
|
|
412
|
+
for (const e of known.get(found.instance) ?? []) for (const l of [...lostListeners]) l(e)
|
|
413
|
+
known.delete(found.instance)
|
|
414
|
+
continue
|
|
415
|
+
}
|
|
416
|
+
const before = known.get(found.instance) ?? []
|
|
417
|
+
known.set(found.instance, endpoints)
|
|
418
|
+
for (const e of endpoints) {
|
|
419
|
+
if (before.some((b) => b.host === e.host && b.port === e.port && b.netId === e.netId))
|
|
420
|
+
continue
|
|
421
|
+
for (const l of [...foundListeners]) l(e)
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
return {
|
|
427
|
+
start(advertisement) {
|
|
428
|
+
if (closed) return
|
|
429
|
+
// A later start only changes what is announced; the socket and its group stay.
|
|
430
|
+
if (advertisement) ad = advertisement
|
|
431
|
+
if (socket) {
|
|
432
|
+
for (const i of options.interfaces()) {
|
|
433
|
+
try {
|
|
434
|
+
if (i.family === 4) socket.addMembership(MDNS_GROUP, i.address)
|
|
435
|
+
} catch {
|
|
436
|
+
// already a member on this interface, or no multicast there
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
if (advertisement) announce()
|
|
440
|
+
else if (ad) {
|
|
441
|
+
// Browse only from now on: withdraw what was announced.
|
|
442
|
+
announce(0)
|
|
443
|
+
ad = undefined
|
|
444
|
+
}
|
|
445
|
+
return
|
|
446
|
+
}
|
|
447
|
+
const s = options.dgram.createSocket({ type: 'udp4', reuseAddr: true })
|
|
448
|
+
socket = s
|
|
449
|
+
s.on('error', () => undefined)
|
|
450
|
+
s.on('message', onMessage)
|
|
451
|
+
s.bind(MDNS_PORT, () => {
|
|
452
|
+
try {
|
|
453
|
+
s.setMulticastTTL?.(255)
|
|
454
|
+
s.setMulticastLoopback?.(true)
|
|
455
|
+
for (const i of options.interfaces())
|
|
456
|
+
if (i.family === 4) s.addMembership(MDNS_GROUP, i.address)
|
|
457
|
+
} catch {
|
|
458
|
+
// no multicast on this interface; the manual address path still works
|
|
459
|
+
}
|
|
460
|
+
announce()
|
|
461
|
+
requery()
|
|
462
|
+
})
|
|
463
|
+
},
|
|
464
|
+
onFound(listener) {
|
|
465
|
+
foundListeners.add(listener)
|
|
466
|
+
return () => foundListeners.delete(listener)
|
|
467
|
+
},
|
|
468
|
+
onLost(listener) {
|
|
469
|
+
lostListeners.add(listener)
|
|
470
|
+
return () => lostListeners.delete(listener)
|
|
471
|
+
},
|
|
472
|
+
async close() {
|
|
473
|
+
if (closed) return
|
|
474
|
+
closed = true
|
|
475
|
+
cancelRequery?.()
|
|
476
|
+
announce(0)
|
|
477
|
+
const s = socket
|
|
478
|
+
socket = undefined
|
|
479
|
+
await new Promise<void>((resolve) => {
|
|
480
|
+
if (!s) return resolve()
|
|
481
|
+
s.close(() => resolve())
|
|
482
|
+
})
|
|
483
|
+
},
|
|
484
|
+
}
|
|
485
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How machines of one network find each other, behind an interface so tests
|
|
3
|
+
* (and a host with its own mechanism) can supply a different one, and which
|
|
4
|
+
* network interfaces the network may listen on.
|
|
5
|
+
*
|
|
6
|
+
* What is advertised is only an opaque network fingerprint and a port: no
|
|
7
|
+
* hostname, no machine name, no session title. A stranger on the LAN learns
|
|
8
|
+
* that "a Namzu network `n` has a listener here" and nothing else.
|
|
9
|
+
*
|
|
10
|
+
* @experimental
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { NetworkInterfaceInfo } from 'node:os'
|
|
14
|
+
|
|
15
|
+
export interface DiscoveredEndpoint {
|
|
16
|
+
readonly netId: string
|
|
17
|
+
readonly host: string
|
|
18
|
+
readonly port: number
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface Advertisement {
|
|
22
|
+
readonly netId: string
|
|
23
|
+
readonly port: number
|
|
24
|
+
readonly addresses: readonly string[]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface NetworkDiscovery {
|
|
28
|
+
/** Start browsing; with an advertisement, also announce it. `undefined` browses only. */
|
|
29
|
+
start(advertisement: Advertisement | undefined): void
|
|
30
|
+
onFound(listener: (endpoint: DiscoveredEndpoint) => void): () => void
|
|
31
|
+
onLost(listener: (endpoint: DiscoveredEndpoint) => void): () => void
|
|
32
|
+
close(): Promise<void>
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function parseIPv4(address: string): [number, number, number, number] | undefined {
|
|
36
|
+
const parts = address.split('.')
|
|
37
|
+
if (parts.length !== 4) return undefined
|
|
38
|
+
const nums = parts.map((p) => (/^\d{1,3}$/.test(p) ? Number(p) : Number.NaN))
|
|
39
|
+
if (nums.some((n) => Number.isNaN(n) || n > 255)) return undefined
|
|
40
|
+
return nums as [number, number, number, number]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* RFC 1918, link-local, CGNAT/overlay (100.64/10, e.g. Tailscale) and IPv6 ULA / link-local.
|
|
45
|
+
* Loopback is not "private" here: it is never advertised and is only used in tests.
|
|
46
|
+
*/
|
|
47
|
+
export function isPrivateNetworkAddress(address: string): boolean {
|
|
48
|
+
const v4 = parseIPv4(address)
|
|
49
|
+
if (v4) {
|
|
50
|
+
const [a, b] = v4
|
|
51
|
+
return (
|
|
52
|
+
a === 10 ||
|
|
53
|
+
(a === 172 && b >= 16 && b <= 31) ||
|
|
54
|
+
(a === 192 && b === 168) ||
|
|
55
|
+
(a === 169 && b === 254) ||
|
|
56
|
+
(a === 100 && b >= 64 && b <= 127)
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
const lower = address.toLowerCase().split('%')[0] ?? ''
|
|
60
|
+
if (!lower.includes(':')) return false
|
|
61
|
+
const first = Number.parseInt(lower.split(':')[0] || '0', 16)
|
|
62
|
+
if (Number.isNaN(first)) return false
|
|
63
|
+
if ((first & 0xfe00) === 0xfc00) return true
|
|
64
|
+
if ((first & 0xffc0) === 0xfe80) return true
|
|
65
|
+
return false
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface ListenAddress {
|
|
69
|
+
/** The address as a person reads it. */
|
|
70
|
+
readonly address: string
|
|
71
|
+
/** What to bind to (link-local IPv6 needs its zone). */
|
|
72
|
+
readonly bindHost: string
|
|
73
|
+
readonly family: 4 | 6
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface PrivateInterfaceOptions {
|
|
77
|
+
readonly allowLoopback?: boolean
|
|
78
|
+
/** Take every non-internal address, private or not (an explicit `network.enabled: true`). */
|
|
79
|
+
readonly anyAddress?: boolean
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The addresses the network may listen on, from `os.networkInterfaces()`. Never `0.0.0.0` or `::`. */
|
|
83
|
+
export function privateInterfaces(
|
|
84
|
+
interfaces: NodeJS.Dict<NetworkInterfaceInfo[]>,
|
|
85
|
+
options: PrivateInterfaceOptions = {},
|
|
86
|
+
): ListenAddress[] {
|
|
87
|
+
const out: ListenAddress[] = []
|
|
88
|
+
for (const [name, list] of Object.entries(interfaces)) {
|
|
89
|
+
for (const info of list ?? []) {
|
|
90
|
+
const family = info.family === 'IPv6' ? 6 : 4
|
|
91
|
+
if (info.internal) {
|
|
92
|
+
if (options.allowLoopback && family === 4)
|
|
93
|
+
out.push({ address: info.address, bindHost: info.address, family })
|
|
94
|
+
continue
|
|
95
|
+
}
|
|
96
|
+
if (!options.anyAddress && !isPrivateNetworkAddress(info.address)) continue
|
|
97
|
+
const linkLocal6 = family === 6 && /^fe[89ab]/i.test(info.address)
|
|
98
|
+
out.push({
|
|
99
|
+
address: info.address,
|
|
100
|
+
bindHost:
|
|
101
|
+
linkLocal6 && !info.address.includes('%') ? `${info.address}%${name}` : info.address,
|
|
102
|
+
family,
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return out
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface FakeDiscovery extends NetworkDiscovery {
|
|
110
|
+
readonly advertised: Advertisement | undefined
|
|
111
|
+
readonly started: boolean
|
|
112
|
+
emitFound(endpoint: DiscoveredEndpoint): void
|
|
113
|
+
emitLost(endpoint: DiscoveredEndpoint): void
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** A discovery that does nothing by itself; the caller says what was found. For tests and for `peers add`. */
|
|
117
|
+
export function createFakeDiscovery(): FakeDiscovery {
|
|
118
|
+
const found = new Set<(e: DiscoveredEndpoint) => void>()
|
|
119
|
+
const lost = new Set<(e: DiscoveredEndpoint) => void>()
|
|
120
|
+
let advertised: Advertisement | undefined
|
|
121
|
+
let started = false
|
|
122
|
+
return {
|
|
123
|
+
get advertised() {
|
|
124
|
+
return advertised
|
|
125
|
+
},
|
|
126
|
+
get started() {
|
|
127
|
+
return started
|
|
128
|
+
},
|
|
129
|
+
start(ad) {
|
|
130
|
+
started = true
|
|
131
|
+
advertised = ad
|
|
132
|
+
},
|
|
133
|
+
onFound(l) {
|
|
134
|
+
found.add(l)
|
|
135
|
+
return () => found.delete(l)
|
|
136
|
+
},
|
|
137
|
+
onLost(l) {
|
|
138
|
+
lost.add(l)
|
|
139
|
+
return () => lost.delete(l)
|
|
140
|
+
},
|
|
141
|
+
async close() {
|
|
142
|
+
started = false
|
|
143
|
+
advertised = undefined
|
|
144
|
+
},
|
|
145
|
+
emitFound(e) {
|
|
146
|
+
for (const l of [...found]) l(e)
|
|
147
|
+
},
|
|
148
|
+
emitLost(e) {
|
|
149
|
+
for (const l of [...lost]) l(e)
|
|
150
|
+
},
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export interface DiscoveryHub {
|
|
155
|
+
/** One discovery per machine; an advertisement from any is found by every other that is browsing, now or later. */
|
|
156
|
+
create(): NetworkDiscovery
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** An in-process "LAN": advertisements reach every other machine's discovery. Tests only. */
|
|
160
|
+
export function createDiscoveryHub(): DiscoveryHub {
|
|
161
|
+
const members = new Set<{
|
|
162
|
+
ad: Advertisement | undefined
|
|
163
|
+
browsing: boolean
|
|
164
|
+
found: Set<(e: DiscoveredEndpoint) => void>
|
|
165
|
+
lost: Set<(e: DiscoveredEndpoint) => void>
|
|
166
|
+
}>()
|
|
167
|
+
const endpointsOf = (ad: Advertisement): DiscoveredEndpoint[] =>
|
|
168
|
+
ad.addresses.map((host) => ({ netId: ad.netId, host, port: ad.port }))
|
|
169
|
+
return {
|
|
170
|
+
create() {
|
|
171
|
+
const me = {
|
|
172
|
+
ad: undefined as Advertisement | undefined,
|
|
173
|
+
browsing: false,
|
|
174
|
+
found: new Set<(e: DiscoveredEndpoint) => void>(),
|
|
175
|
+
lost: new Set<(e: DiscoveredEndpoint) => void>(),
|
|
176
|
+
}
|
|
177
|
+
members.add(me)
|
|
178
|
+
return {
|
|
179
|
+
start(ad) {
|
|
180
|
+
me.browsing = true
|
|
181
|
+
me.ad = ad
|
|
182
|
+
for (const other of members) {
|
|
183
|
+
if (other === me) continue
|
|
184
|
+
if (other.ad) for (const e of endpointsOf(other.ad)) for (const l of [...me.found]) l(e)
|
|
185
|
+
if (ad)
|
|
186
|
+
for (const e of endpointsOf(ad))
|
|
187
|
+
for (const l of [...other.found]) if (other.browsing) l(e)
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
onFound(l) {
|
|
191
|
+
me.found.add(l)
|
|
192
|
+
return () => me.found.delete(l)
|
|
193
|
+
},
|
|
194
|
+
onLost(l) {
|
|
195
|
+
me.lost.add(l)
|
|
196
|
+
return () => me.lost.delete(l)
|
|
197
|
+
},
|
|
198
|
+
async close() {
|
|
199
|
+
const ad = me.ad
|
|
200
|
+
me.ad = undefined
|
|
201
|
+
me.browsing = false
|
|
202
|
+
members.delete(me)
|
|
203
|
+
if (ad)
|
|
204
|
+
for (const other of members)
|
|
205
|
+
for (const e of endpointsOf(ad)) for (const l of [...other.lost]) l(e)
|
|
206
|
+
},
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
}
|
|
210
|
+
}
|