@namzu/sdk 68.0.1 → 69.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +96 -0
- package/dist/agents/QueryAgent.d.ts.map +1 -1
- package/dist/agents/QueryAgent.js +2 -0
- package/dist/agents/QueryAgent.js.map +1 -1
- package/dist/authorization/skill-grant.d.ts.map +1 -1
- package/dist/authorization/skill-grant.js +1 -0
- package/dist/authorization/skill-grant.js.map +1 -1
- package/dist/bridge/acp/permission.d.ts +10 -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 +12 -0
- package/dist/bridge/acp/server.d.ts.map +1 -1
- package/dist/bridge/acp/server.js +21 -0
- package/dist/bridge/acp/server.js.map +1 -1
- package/dist/compaction/context-window.d.ts +8 -0
- package/dist/compaction/context-window.d.ts.map +1 -1
- package/dist/compaction/context-window.js +14 -0
- package/dist/compaction/context-window.js.map +1 -1
- package/dist/compaction/loaded-skills.d.ts +10 -0
- package/dist/compaction/loaded-skills.d.ts.map +1 -1
- package/dist/compaction/loaded-skills.js +45 -1
- package/dist/compaction/loaded-skills.js.map +1 -1
- package/dist/compaction/manager.d.ts +8 -0
- package/dist/compaction/manager.d.ts.map +1 -1
- package/dist/compaction/manager.js +31 -0
- package/dist/compaction/manager.js.map +1 -1
- package/dist/compaction/manual.d.ts.map +1 -1
- package/dist/compaction/manual.js +7 -1
- package/dist/compaction/manual.js.map +1 -1
- package/dist/compaction/model-summary.js +2 -2
- package/dist/compaction/model-summary.js.map +1 -1
- package/dist/compaction/restore.d.ts +8 -0
- package/dist/compaction/restore.d.ts.map +1 -1
- package/dist/compaction/restore.js +65 -0
- package/dist/compaction/restore.js.map +1 -1
- package/dist/compaction/salience/working-set.d.ts.map +1 -1
- package/dist/compaction/salience/working-set.js +2 -2
- package/dist/compaction/salience/working-set.js.map +1 -1
- package/dist/compaction/tool-result-editing.d.ts +6 -0
- package/dist/compaction/tool-result-editing.d.ts.map +1 -1
- package/dist/compaction/tool-result-editing.js +7 -1
- package/dist/compaction/tool-result-editing.js.map +1 -1
- package/dist/compaction/types.d.ts +2 -0
- package/dist/compaction/types.d.ts.map +1 -1
- package/dist/compaction/wire.d.ts.map +1 -1
- package/dist/compaction/wire.js +4 -0
- package/dist/compaction/wire.js.map +1 -1
- package/dist/connector/index.d.ts +2 -2
- package/dist/connector/index.d.ts.map +1 -1
- package/dist/connector/index.js +1 -1
- package/dist/connector/index.js.map +1 -1
- package/dist/connector/mcp/client.d.ts +29 -0
- package/dist/connector/mcp/client.d.ts.map +1 -1
- package/dist/connector/mcp/client.js +59 -2
- package/dist/connector/mcp/client.js.map +1 -1
- package/dist/connector/mcp/errors.d.ts +7 -0
- package/dist/connector/mcp/errors.d.ts.map +1 -1
- package/dist/connector/mcp/errors.js +14 -0
- package/dist/connector/mcp/errors.js.map +1 -1
- package/dist/connector/mcp/index.d.ts +5 -1
- package/dist/connector/mcp/index.d.ts.map +1 -1
- package/dist/connector/mcp/index.js +3 -1
- package/dist/connector/mcp/index.js.map +1 -1
- package/dist/connector/mcp/skill-source.d.ts +144 -0
- package/dist/connector/mcp/skill-source.d.ts.map +1 -0
- package/dist/connector/mcp/skill-source.js +375 -0
- package/dist/connector/mcp/skill-source.js.map +1 -0
- package/dist/connector/mcp/skills.d.ts +137 -0
- package/dist/connector/mcp/skills.d.ts.map +1 -0
- package/dist/connector/mcp/skills.js +303 -0
- package/dist/connector/mcp/skills.js.map +1 -0
- package/dist/manager/session/turn-recorder.d.ts.map +1 -1
- package/dist/manager/session/turn-recorder.js +23 -1
- package/dist/manager/session/turn-recorder.js.map +1 -1
- package/dist/network/audit.d.ts +1 -1
- package/dist/network/audit.d.ts.map +1 -1
- package/dist/network/audit.js +2 -0
- package/dist/network/audit.js.map +1 -1
- package/dist/network/computer.d.ts +107 -0
- package/dist/network/computer.d.ts.map +1 -0
- package/dist/network/computer.js +250 -0
- package/dist/network/computer.js.map +1 -0
- package/dist/network/index.d.ts +2 -0
- package/dist/network/index.d.ts.map +1 -1
- package/dist/network/index.js +1 -0
- package/dist/network/index.js.map +1 -1
- package/dist/network/join.d.ts +13 -1
- package/dist/network/join.d.ts.map +1 -1
- package/dist/network/join.js +21 -3
- package/dist/network/join.js.map +1 -1
- package/dist/network/roster.d.ts +5 -0
- package/dist/network/roster.d.ts.map +1 -1
- package/dist/network/roster.js.map +1 -1
- package/dist/network/service.d.ts +12 -2
- package/dist/network/service.d.ts.map +1 -1
- package/dist/network/service.js +539 -60
- package/dist/network/service.js.map +1 -1
- package/dist/network/store.d.ts +33 -1
- package/dist/network/store.d.ts.map +1 -1
- package/dist/network/store.js +48 -4
- package/dist/network/store.js.map +1 -1
- package/dist/network/transport.d.ts +1 -1
- package/dist/network/transport.js +1 -1
- package/dist/network/wire.d.ts +14 -0
- package/dist/network/wire.d.ts.map +1 -1
- package/dist/network/wire.js +17 -1
- package/dist/network/wire.js.map +1 -1
- package/dist/plugin/shell-hook-tool-names.d.ts.map +1 -1
- package/dist/plugin/shell-hook-tool-names.js +1 -0
- package/dist/plugin/shell-hook-tool-names.js.map +1 -1
- package/dist/plugin/shell-hook.d.ts +8 -3
- package/dist/plugin/shell-hook.d.ts.map +1 -1
- package/dist/plugin/shell-hook.js +132 -7
- package/dist/plugin/shell-hook.js.map +1 -1
- package/dist/prompt/coding-agent-doctrine.d.ts +4 -4
- package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
- package/dist/prompt/coding-agent-doctrine.js +7 -2
- package/dist/prompt/coding-agent-doctrine.js.map +1 -1
- package/dist/provider/fallback.d.ts.map +1 -1
- package/dist/provider/fallback.js +9 -0
- package/dist/provider/fallback.js.map +1 -1
- package/dist/provider/idle-timeout.d.ts.map +1 -1
- package/dist/provider/idle-timeout.js +8 -0
- package/dist/provider/idle-timeout.js.map +1 -1
- package/dist/provider/instrumentation.d.ts.map +1 -1
- package/dist/provider/instrumentation.js +10 -0
- package/dist/provider/instrumentation.js.map +1 -1
- package/dist/provider/model-window-suffix.d.ts.map +1 -1
- package/dist/provider/model-window-suffix.js +2 -0
- package/dist/provider/model-window-suffix.js.map +1 -1
- package/dist/provider/retry.d.ts.map +1 -1
- package/dist/provider/retry.js +8 -0
- package/dist/provider/retry.js.map +1 -1
- package/dist/public-runtime.d.ts +10 -7
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +12 -5
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +7 -4
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +9 -3
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +4 -1
- package/dist/public-types.d.ts.map +1 -1
- package/dist/registry/tool/presentation.d.ts +8 -1
- package/dist/registry/tool/presentation.d.ts.map +1 -1
- package/dist/registry/tool/presentation.js +14 -5
- package/dist/registry/tool/presentation.js.map +1 -1
- package/dist/runtime/jobs/registry.d.ts.map +1 -1
- package/dist/runtime/jobs/registry.js +2 -1
- package/dist/runtime/jobs/registry.js.map +1 -1
- package/dist/runtime/query/auto-review/classifier.d.ts.map +1 -1
- package/dist/runtime/query/auto-review/classifier.js +19 -3
- package/dist/runtime/query/auto-review/classifier.js.map +1 -1
- package/dist/runtime/query/auto-review/failure.d.ts +12 -0
- package/dist/runtime/query/auto-review/failure.d.ts.map +1 -0
- package/dist/runtime/query/auto-review/failure.js +46 -0
- package/dist/runtime/query/auto-review/failure.js.map +1 -0
- package/dist/runtime/query/auto-review/index.d.ts +1 -0
- package/dist/runtime/query/auto-review/index.d.ts.map +1 -1
- package/dist/runtime/query/auto-review/index.js +1 -0
- package/dist/runtime/query/auto-review/index.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 +10 -1
- package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +12 -0
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +43 -9
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/file-evidence-replay.d.ts.map +1 -1
- package/dist/runtime/query/file-evidence-replay.js +6 -6
- package/dist/runtime/query/file-evidence-replay.js.map +1 -1
- package/dist/runtime/query/index.d.ts +4 -0
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +40 -1
- 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 +2 -0
- 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 +21 -3
- package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context.d.ts +4 -0
- package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/context.js.map +1 -1
- package/dist/runtime/query/iteration/phases/per-call-review.d.ts +6 -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 +24 -9
- package/dist/runtime/query/iteration/phases/per-call-review.js.map +1 -1
- package/dist/runtime/query/iteration/step-shaping.d.ts.map +1 -1
- package/dist/runtime/query/iteration/step-shaping.js +4 -0
- package/dist/runtime/query/iteration/step-shaping.js.map +1 -1
- package/dist/runtime/query/prepare-turn.d.ts +5 -1
- package/dist/runtime/query/prepare-turn.d.ts.map +1 -1
- package/dist/runtime/query/prepare-turn.js +13 -3
- package/dist/runtime/query/prepare-turn.js.map +1 -1
- package/dist/runtime/query/review-policy.d.ts +15 -4
- package/dist/runtime/query/review-policy.d.ts.map +1 -1
- package/dist/runtime/query/review-policy.js +15 -4
- package/dist/runtime/query/review-policy.js.map +1 -1
- package/dist/runtime/query/shell-line-escalation.d.ts +24 -0
- package/dist/runtime/query/shell-line-escalation.d.ts.map +1 -0
- package/dist/runtime/query/shell-line-escalation.js +38 -0
- package/dist/runtime/query/shell-line-escalation.js.map +1 -0
- package/dist/runtime/query/tooling.d.ts +7 -0
- package/dist/runtime/query/tooling.d.ts.map +1 -1
- package/dist/runtime/query/tooling.js +2 -0
- package/dist/runtime/query/tooling.js.map +1 -1
- package/dist/runtime/query/turn/outcome-ledger.d.ts +4 -0
- package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
- package/dist/runtime/query/turn/outcome-ledger.js +47 -1
- package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
- package/dist/sandbox/provider/local.d.ts.map +1 -1
- package/dist/sandbox/provider/local.js +3 -1
- package/dist/sandbox/provider/local.js.map +1 -1
- package/dist/scheduler/local.d.ts.map +1 -1
- package/dist/scheduler/local.js +3 -1
- package/dist/scheduler/local.js.map +1 -1
- package/dist/skills/index.d.ts +4 -0
- package/dist/skills/index.d.ts.map +1 -1
- package/dist/skills/index.js +2 -0
- package/dist/skills/index.js.map +1 -1
- package/dist/skills/inline-shell-host.d.ts +103 -0
- package/dist/skills/inline-shell-host.d.ts.map +1 -0
- package/dist/skills/inline-shell-host.js +238 -0
- package/dist/skills/inline-shell-host.js.map +1 -0
- package/dist/skills/inline-shell.d.ts +176 -0
- package/dist/skills/inline-shell.d.ts.map +1 -0
- package/dist/skills/inline-shell.js +646 -0
- package/dist/skills/inline-shell.js.map +1 -0
- package/dist/store/index.d.ts +2 -0
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +1 -0
- package/dist/store/index.js.map +1 -1
- package/dist/store/task/file.d.ts +124 -0
- package/dist/store/task/file.d.ts.map +1 -0
- package/dist/store/task/file.js +498 -0
- package/dist/store/task/file.js.map +1 -0
- package/dist/teams/backend.d.ts +28 -0
- package/dist/teams/backend.d.ts.map +1 -0
- package/dist/teams/backend.js +2 -0
- package/dist/teams/backend.js.map +1 -0
- package/dist/teams/fs-sync.d.ts +19 -0
- package/dist/teams/fs-sync.d.ts.map +1 -0
- package/dist/teams/fs-sync.js +81 -0
- package/dist/teams/fs-sync.js.map +1 -0
- package/dist/teams/index.d.ts +14 -0
- package/dist/teams/index.d.ts.map +1 -0
- package/dist/teams/index.js +11 -0
- package/dist/teams/index.js.map +1 -0
- package/dist/teams/names.d.ts +15 -0
- package/dist/teams/names.d.ts.map +1 -0
- package/dist/teams/names.js +43 -0
- package/dist/teams/names.js.map +1 -0
- package/dist/teams/store.d.ts +133 -0
- package/dist/teams/store.d.ts.map +1 -0
- package/dist/teams/store.js +536 -0
- package/dist/teams/store.js.map +1 -0
- package/dist/teams/types.d.ts +97 -0
- package/dist/teams/types.d.ts.map +1 -0
- package/dist/teams/types.js +70 -0
- package/dist/teams/types.js.map +1 -0
- package/dist/tools/admit-facts.d.ts.map +1 -1
- package/dist/tools/admit-facts.js +28 -0
- package/dist/tools/admit-facts.js.map +1 -1
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +5 -2
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/browser.js +1 -1
- package/dist/tools/builtins/browser.js.map +1 -1
- package/dist/tools/builtins/computer-use.d.ts +60 -2
- package/dist/tools/builtins/computer-use.d.ts.map +1 -1
- package/dist/tools/builtins/computer-use.js +695 -80
- package/dist/tools/builtins/computer-use.js.map +1 -1
- package/dist/tools/builtins/content-fingerprint.d.ts.map +1 -1
- package/dist/tools/builtins/content-fingerprint.js +2 -1
- package/dist/tools/builtins/content-fingerprint.js.map +1 -1
- package/dist/tools/builtins/edit-apply.d.ts +1 -0
- package/dist/tools/builtins/edit-apply.d.ts.map +1 -1
- package/dist/tools/builtins/edit-apply.js +108 -21
- package/dist/tools/builtins/edit-apply.js.map +1 -1
- package/dist/tools/builtins/edit-match.d.ts +37 -0
- package/dist/tools/builtins/edit-match.d.ts.map +1 -1
- package/dist/tools/builtins/edit-match.js +193 -0
- package/dist/tools/builtins/edit-match.js.map +1 -1
- package/dist/tools/builtins/edit.d.ts.map +1 -1
- package/dist/tools/builtins/edit.js +14 -7
- package/dist/tools/builtins/edit.js.map +1 -1
- package/dist/tools/builtins/exit-semantics.d.ts +8 -0
- package/dist/tools/builtins/exit-semantics.d.ts.map +1 -1
- package/dist/tools/builtins/exit-semantics.js +19 -0
- package/dist/tools/builtins/exit-semantics.js.map +1 -1
- package/dist/tools/builtins/index.d.ts +3 -1
- package/dist/tools/builtins/index.d.ts.map +1 -1
- package/dist/tools/builtins/index.js +1 -0
- package/dist/tools/builtins/index.js.map +1 -1
- package/dist/tools/builtins/present-file.d.ts +24 -0
- package/dist/tools/builtins/present-file.d.ts.map +1 -0
- package/dist/tools/builtins/present-file.js +116 -0
- package/dist/tools/builtins/present-file.js.map +1 -0
- package/dist/tools/builtins/read-file.js +1 -1
- package/dist/tools/builtins/read-file.js.map +1 -1
- package/dist/tools/builtins/read-render.d.ts +12 -1
- package/dist/tools/builtins/read-render.d.ts.map +1 -1
- package/dist/tools/builtins/read-render.js +16 -3
- package/dist/tools/builtins/read-render.js.map +1 -1
- package/dist/tools/builtins/search-tools.d.ts +10 -0
- package/dist/tools/builtins/search-tools.d.ts.map +1 -1
- package/dist/tools/builtins/search-tools.js +36 -2
- package/dist/tools/builtins/search-tools.js.map +1 -1
- package/dist/tools/builtins/skill.d.ts +31 -0
- package/dist/tools/builtins/skill.d.ts.map +1 -1
- package/dist/tools/builtins/skill.js +232 -88
- package/dist/tools/builtins/skill.js.map +1 -1
- package/dist/tools/builtins/wait-for-job.d.ts.map +1 -1
- package/dist/tools/builtins/wait-for-job.js +5 -0
- package/dist/tools/builtins/wait-for-job.js.map +1 -1
- package/dist/tools/builtins/web.d.ts.map +1 -1
- package/dist/tools/builtins/web.js +13 -2
- package/dist/tools/builtins/web.js.map +1 -1
- package/dist/tools/task/create.d.ts.map +1 -1
- package/dist/tools/task/create.js +13 -4
- package/dist/tools/task/create.js.map +1 -1
- package/dist/tools/task/get.d.ts +8 -0
- package/dist/tools/task/get.d.ts.map +1 -0
- package/dist/tools/task/get.js +51 -0
- package/dist/tools/task/get.js.map +1 -0
- package/dist/tools/task/index.d.ts +7 -0
- package/dist/tools/task/index.d.ts.map +1 -1
- package/dist/tools/task/index.js +10 -2
- package/dist/tools/task/index.js.map +1 -1
- package/dist/tools/task/list.d.ts.map +1 -1
- package/dist/tools/task/list.js +10 -2
- package/dist/tools/task/list.js.map +1 -1
- package/dist/tools/task/number.d.ts +13 -0
- package/dist/tools/task/number.d.ts.map +1 -0
- package/dist/tools/task/number.js +30 -0
- package/dist/tools/task/number.js.map +1 -0
- package/dist/tools/task/present.d.ts.map +1 -1
- package/dist/tools/task/present.js +17 -3
- package/dist/tools/task/present.js.map +1 -1
- package/dist/tools/task/update.d.ts +2 -1
- package/dist/tools/task/update.d.ts.map +1 -1
- package/dist/tools/task/update.js +87 -20
- package/dist/tools/task/update.js.map +1 -1
- package/dist/types/acp/index.d.ts +10 -0
- package/dist/types/acp/index.d.ts.map +1 -1
- package/dist/types/agent/base.d.ts +4 -0
- package/dist/types/agent/base.d.ts.map +1 -1
- package/dist/types/agent/scheduler.d.ts +9 -0
- package/dist/types/agent/scheduler.d.ts.map +1 -1
- package/dist/types/computer-use/index.d.ts +7 -0
- package/dist/types/computer-use/index.d.ts.map +1 -1
- package/dist/types/computer-use/index.js.map +1 -1
- package/dist/types/connector/mcp.d.ts +10 -0
- package/dist/types/connector/mcp.d.ts.map +1 -1
- package/dist/types/permission/index.d.ts +20 -0
- package/dist/types/permission/index.d.ts.map +1 -1
- package/dist/types/permission/index.js +25 -0
- package/dist/types/permission/index.js.map +1 -1
- package/dist/types/plugin/index.d.ts +47 -3
- package/dist/types/plugin/index.d.ts.map +1 -1
- package/dist/types/plugin/index.js +4 -0
- package/dist/types/plugin/index.js.map +1 -1
- package/dist/types/provider/chat.d.ts +8 -0
- package/dist/types/provider/chat.d.ts.map +1 -1
- package/dist/types/provider/interface.d.ts +16 -0
- package/dist/types/provider/interface.d.ts.map +1 -1
- package/dist/types/provider/model.d.ts +6 -0
- package/dist/types/provider/model.d.ts.map +1 -1
- package/dist/types/provider/stream.d.ts +2 -0
- package/dist/types/provider/stream.d.ts.map +1 -1
- package/dist/types/tool/index.d.ts +28 -2
- 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 +15 -0
- package/dist/types/tool/presentation.d.ts.map +1 -1
- package/dist/utils/node-on-path.d.ts +27 -0
- package/dist/utils/node-on-path.d.ts.map +1 -0
- package/dist/utils/node-on-path.js +70 -0
- package/dist/utils/node-on-path.js.map +1 -0
- package/package.json +1 -1
- package/src/agents/QueryAgent.ts +2 -0
- package/src/authorization/skill-grant.ts +1 -0
- package/src/bridge/acp/permission.ts +11 -1
- package/src/bridge/acp/server.ts +26 -0
- package/src/compaction/context-window.ts +18 -0
- package/src/compaction/loaded-skills.ts +42 -1
- package/src/compaction/manager.ts +28 -0
- package/src/compaction/manual.ts +9 -1
- package/src/compaction/model-summary.ts +2 -2
- package/src/compaction/restore.ts +69 -0
- package/src/compaction/salience/working-set.ts +6 -2
- package/src/compaction/tool-result-editing.ts +8 -1
- package/src/compaction/types.ts +2 -0
- package/src/compaction/wire.ts +4 -0
- package/src/connector/index.ts +27 -0
- package/src/connector/mcp/client.ts +71 -2
- package/src/connector/mcp/errors.ts +14 -0
- package/src/connector/mcp/index.ts +36 -0
- package/src/connector/mcp/skill-source.ts +499 -0
- package/src/connector/mcp/skills.ts +367 -0
- package/src/manager/session/turn-recorder.ts +24 -1
- package/src/network/audit.ts +2 -0
- package/src/network/computer.ts +347 -0
- package/src/network/index.ts +20 -0
- package/src/network/join.ts +21 -2
- package/src/network/roster.ts +5 -0
- package/src/network/service.ts +674 -84
- package/src/network/store.ts +57 -4
- package/src/network/transport.ts +1 -1
- package/src/network/wire.ts +18 -1
- package/src/plugin/shell-hook-tool-names.ts +1 -0
- package/src/plugin/shell-hook.ts +144 -7
- package/src/prompt/coding-agent-doctrine.ts +7 -2
- package/src/provider/fallback.ts +10 -0
- package/src/provider/idle-timeout.ts +9 -0
- package/src/provider/instrumentation.ts +12 -0
- package/src/provider/model-window-suffix.ts +2 -0
- package/src/provider/retry.ts +9 -0
- package/src/public-runtime.ts +100 -0
- package/src/public-tools.ts +18 -0
- package/src/public-types.ts +29 -0
- package/src/registry/tool/presentation.ts +14 -4
- package/src/runtime/jobs/registry.ts +2 -1
- package/src/runtime/query/auto-review/classifier.ts +19 -3
- package/src/runtime/query/auto-review/failure.ts +50 -0
- package/src/runtime/query/auto-review/index.ts +1 -0
- package/src/runtime/query/executor/tool-call-admission.ts +10 -1
- package/src/runtime/query/executor.ts +57 -8
- package/src/runtime/query/file-evidence-replay.ts +6 -5
- package/src/runtime/query/index.ts +62 -0
- package/src/runtime/query/iteration/index.ts +2 -0
- package/src/runtime/query/iteration/phases/compaction.ts +25 -2
- package/src/runtime/query/iteration/phases/context.ts +4 -0
- package/src/runtime/query/iteration/phases/per-call-review.ts +24 -7
- package/src/runtime/query/iteration/step-shaping.ts +4 -0
- package/src/runtime/query/prepare-turn.ts +20 -2
- package/src/runtime/query/review-policy.ts +31 -5
- package/src/runtime/query/shell-line-escalation.ts +49 -0
- package/src/runtime/query/tooling.ts +6 -0
- package/src/runtime/query/turn/outcome-ledger.ts +56 -1
- package/src/sandbox/provider/local.ts +3 -1
- package/src/scheduler/local.ts +3 -1
- package/src/skills/index.ts +43 -0
- package/src/skills/inline-shell-host.ts +303 -0
- package/src/skills/inline-shell.ts +765 -0
- package/src/store/index.ts +8 -0
- package/src/store/task/file.ts +641 -0
- package/src/teams/backend.ts +29 -0
- package/src/teams/fs-sync.ts +91 -0
- package/src/teams/index.ts +47 -0
- package/src/teams/names.ts +49 -0
- package/src/teams/store.ts +607 -0
- package/src/teams/types.ts +102 -0
- package/src/tools/admit-facts.ts +26 -0
- package/src/tools/builtins/bash.ts +5 -2
- package/src/tools/builtins/browser.ts +1 -1
- package/src/tools/builtins/computer-use.ts +799 -86
- package/src/tools/builtins/content-fingerprint.ts +2 -1
- package/src/tools/builtins/edit-apply.ts +124 -24
- package/src/tools/builtins/edit-match.ts +200 -0
- package/src/tools/builtins/edit.ts +16 -7
- package/src/tools/builtins/exit-semantics.ts +23 -0
- package/src/tools/builtins/index.ts +3 -0
- package/src/tools/builtins/present-file.ts +127 -0
- package/src/tools/builtins/read-file.ts +1 -1
- package/src/tools/builtins/read-render.ts +18 -3
- package/src/tools/builtins/search-tools.ts +36 -2
- package/src/tools/builtins/skill.ts +291 -95
- package/src/tools/builtins/wait-for-job.ts +5 -0
- package/src/tools/builtins/web.ts +15 -2
- package/src/tools/task/create.ts +13 -4
- package/src/tools/task/get.ts +53 -0
- package/src/tools/task/index.ts +14 -2
- package/src/tools/task/list.ts +10 -2
- package/src/tools/task/number.ts +32 -0
- package/src/tools/task/present.ts +18 -3
- package/src/tools/task/update.ts +94 -20
- package/src/types/acp/index.ts +11 -1
- package/src/types/agent/base.ts +6 -0
- package/src/types/agent/scheduler.ts +9 -0
- package/src/types/computer-use/index.ts +7 -0
- package/src/types/connector/mcp.ts +10 -0
- package/src/types/permission/index.ts +29 -0
- package/src/types/plugin/index.ts +95 -39
- package/src/types/provider/chat.ts +9 -0
- package/src/types/provider/interface.ts +18 -0
- package/src/types/provider/model.ts +6 -0
- package/src/types/provider/stream.ts +2 -0
- package/src/types/tool/index.ts +23 -2
- package/src/types/tool/presentation.ts +14 -0
- package/src/utils/node-on-path.ts +81 -0
package/dist/network/service.js
CHANGED
|
@@ -25,10 +25,11 @@ import { networkInterfaces, hostname as osHostname, platform as osPlatform } fro
|
|
|
25
25
|
import { z } from 'zod';
|
|
26
26
|
import { createFileAuditSink, textHash } from './audit.js';
|
|
27
27
|
import { systemClock } from './clock.js';
|
|
28
|
+
import { computerJoinProof, computerMemberProof, computerSecretFingerprint, ensureComputerSecret, readComputerSecret, verifyComputerJoinProof, verifyComputerMemberProof, } from './computer.js';
|
|
28
29
|
import { isPrivateNetworkAddress, privateInterfaces, } from './discovery.js';
|
|
29
30
|
import { createNetworkIdentity, createSystemGatewayReader } from './fingerprint.js';
|
|
30
31
|
import { generateMachineKey, machineIdOf, shortMachineId } from './identity.js';
|
|
31
|
-
import { JoinTable, formatJoinCode, joinCode } from './join.js';
|
|
32
|
+
import { JOIN_ADDRESS_WINDOW_MS, JOIN_BACKOFF_DENIED_MS, JOIN_BACKOFF_OTHER_MS, JOIN_EXPIRY_MS, JOIN_ORPHAN_MS, JoinTable, formatJoinCode, joinCode, } from './join.js';
|
|
32
33
|
import { HoldQueue, SlidingCounter, TokenBuckets, decideMail, } from './mail-policy.js';
|
|
33
34
|
import { AdmissionSchema, RevocationSchema, admittedBy, createFounding, evaluateMembership, mergeMembership, signAdmission, signRevocation, } from './membership.js';
|
|
34
35
|
import { offlineSessions, resolveSessionTarget, } from './roster.js';
|
|
@@ -46,6 +47,8 @@ export const FRESH_NETWORK_MS = 60_000;
|
|
|
46
47
|
export const INTERFACE_RECHECK_MS = 30_000;
|
|
47
48
|
export const ROSTER_FRESH_MS = 15_000;
|
|
48
49
|
const MAX_NEARBY_NETWORKS = 8;
|
|
50
|
+
/** Wrong computer proofs one address may send in a join window before its proofs are no longer checked. */
|
|
51
|
+
const MAX_PROOF_FAILURES = 5;
|
|
49
52
|
/** Strip the IPv4-in-IPv6 prefix a socket may report. */
|
|
50
53
|
const plainAddress = (address) => address.replace(/^::ffff:/i, '');
|
|
51
54
|
const PeerEntrySchema = z
|
|
@@ -58,6 +61,10 @@ const PeerEntrySchema = z
|
|
|
58
61
|
const AdmittedFrameSchema = z
|
|
59
62
|
.object({
|
|
60
63
|
status: z.literal('admitted'),
|
|
64
|
+
/** Only when the member admitted this machine on the computer proof. */
|
|
65
|
+
sameComputer: z.literal(true).optional(),
|
|
66
|
+
/** The member's counter-proof (base64 HMAC, 44 characters); the joiner marks the member only when it verifies. */
|
|
67
|
+
computerMemberProof: z.string().length(44).optional(),
|
|
61
68
|
netId: z.string().length(16).optional(),
|
|
62
69
|
admissions: z.array(AdmissionSchema).max(MAX_MEMBERS * 2),
|
|
63
70
|
revocations: z.array(RevocationSchema).max(MAX_MEMBERS * 2),
|
|
@@ -65,10 +72,17 @@ const AdmittedFrameSchema = z
|
|
|
65
72
|
})
|
|
66
73
|
.strict();
|
|
67
74
|
const PendingFrameSchema = z
|
|
68
|
-
.object({
|
|
75
|
+
.object({
|
|
76
|
+
status: z.literal('pending'),
|
|
77
|
+
nonce: z.string(),
|
|
78
|
+
netId: z.string().length(16),
|
|
79
|
+
})
|
|
69
80
|
.strict();
|
|
70
81
|
const EndFrameSchema = z
|
|
71
|
-
.object({
|
|
82
|
+
.object({
|
|
83
|
+
status: z.enum(['denied', 'expired', 'refused']),
|
|
84
|
+
reason: z.string().optional(),
|
|
85
|
+
})
|
|
72
86
|
.strict();
|
|
73
87
|
const HelloReplySchema = z
|
|
74
88
|
.object({
|
|
@@ -77,7 +91,10 @@ const HelloReplySchema = z
|
|
|
77
91
|
})
|
|
78
92
|
.strict();
|
|
79
93
|
const SyncReplySchema = z
|
|
80
|
-
.object({
|
|
94
|
+
.object({
|
|
95
|
+
admissions: z.array(AdmissionSchema),
|
|
96
|
+
revocations: z.array(RevocationSchema),
|
|
97
|
+
})
|
|
81
98
|
.strict();
|
|
82
99
|
/** Words from another machine that reach a screen or a model: no control characters, one line, short. */
|
|
83
100
|
function cleanReason(value) {
|
|
@@ -132,7 +149,10 @@ export function createNamzuNetwork(options) {
|
|
|
132
149
|
const clock = options.clock ?? systemClock;
|
|
133
150
|
const store = options.store ?? createNetworkStore({ home: options.home });
|
|
134
151
|
const audit = options.audit ??
|
|
135
|
-
createFileAuditSink({
|
|
152
|
+
createFileAuditSink({
|
|
153
|
+
dir: store.dir,
|
|
154
|
+
report: (m) => options.host.report?.(m),
|
|
155
|
+
});
|
|
136
156
|
const discovery = options.discovery;
|
|
137
157
|
const host = options.host;
|
|
138
158
|
const platform = options.platform ?? osPlatform();
|
|
@@ -155,6 +175,19 @@ export function createNamzuNetwork(options) {
|
|
|
155
175
|
const peerState = new Map();
|
|
156
176
|
const nearby = new Map();
|
|
157
177
|
const pendingConns = new Map();
|
|
178
|
+
/** Requests admitted by the computer proof: their `admitted` frame says so. */
|
|
179
|
+
const proven = new Set();
|
|
180
|
+
const unavailableSeen = new Set();
|
|
181
|
+
/** Machines of this computer, by proof, in either direction. */
|
|
182
|
+
let sameComputerIds;
|
|
183
|
+
let sameComputerFp;
|
|
184
|
+
/** Failed proofs per source address: past a few in a minute the proof is no longer even checked. */
|
|
185
|
+
const proofFailures = new Map();
|
|
186
|
+
const mismatchSeen = new Set();
|
|
187
|
+
/** Cancels for the timers of requests whose connection dropped. */
|
|
188
|
+
const orphanTimers = new Map();
|
|
189
|
+
/** What a waiting request was made of, so the same machine asking again with the same nonce gets the same code. */
|
|
190
|
+
const askNonces = new Map();
|
|
158
191
|
const sent = new Map();
|
|
159
192
|
const seenMail = [];
|
|
160
193
|
const inFlight = new Set();
|
|
@@ -162,6 +195,7 @@ export function createNamzuNetwork(options) {
|
|
|
162
195
|
let cancelBrowse;
|
|
163
196
|
let cancelRecheck;
|
|
164
197
|
let joining = false;
|
|
198
|
+
let joinEndpoint;
|
|
165
199
|
let joinClient;
|
|
166
200
|
let joinCancelled = false;
|
|
167
201
|
let foundedAt;
|
|
@@ -217,7 +251,11 @@ export function createNamzuNetwork(options) {
|
|
|
217
251
|
let n = list.length + 1;
|
|
218
252
|
while (names.has(`network ${n}`))
|
|
219
253
|
n++;
|
|
220
|
-
return {
|
|
254
|
+
return {
|
|
255
|
+
id,
|
|
256
|
+
...(known ? { trusted: known.name } : {}),
|
|
257
|
+
suggestedName: `Network ${n}`,
|
|
258
|
+
};
|
|
221
259
|
}
|
|
222
260
|
async function trustNetwork(address, name) {
|
|
223
261
|
const ref = await networkOf(address);
|
|
@@ -275,7 +313,10 @@ export function createNamzuNetwork(options) {
|
|
|
275
313
|
async function untrustNetwork(query) {
|
|
276
314
|
const list = await trustedList();
|
|
277
315
|
const gone = findTrusted(list, query);
|
|
278
|
-
await store.writeTrustedNetworks({
|
|
316
|
+
await store.writeTrustedNetworks({
|
|
317
|
+
v: 1,
|
|
318
|
+
networks: list.filter((n) => n.id !== gone.id),
|
|
319
|
+
});
|
|
279
320
|
logAudit({ event: 'network_untrusted', reason: gone.name });
|
|
280
321
|
return gone;
|
|
281
322
|
}
|
|
@@ -302,7 +343,11 @@ export function createNamzuNetwork(options) {
|
|
|
302
343
|
event: 'join_expired',
|
|
303
344
|
machine: { id12: entry.viaMachineId.slice(0, 12), name: entry.name },
|
|
304
345
|
});
|
|
305
|
-
emit({
|
|
346
|
+
emit({
|
|
347
|
+
type: 'join-settled',
|
|
348
|
+
requestId: entry.requestId,
|
|
349
|
+
result: 'expired',
|
|
350
|
+
});
|
|
306
351
|
},
|
|
307
352
|
});
|
|
308
353
|
const heldQueue = new HoldQueue({
|
|
@@ -319,8 +364,16 @@ export function createNamzuNetwork(options) {
|
|
|
319
364
|
void notifySender(mail, 'expired', 'The message was not answered in time and has expired.');
|
|
320
365
|
},
|
|
321
366
|
});
|
|
322
|
-
const mailBuckets = new TokenBuckets({
|
|
323
|
-
|
|
367
|
+
const mailBuckets = new TokenBuckets({
|
|
368
|
+
capacity: 30,
|
|
369
|
+
refillPerSecond: 0.5,
|
|
370
|
+
clock,
|
|
371
|
+
});
|
|
372
|
+
const roleBuckets = new TokenBuckets({
|
|
373
|
+
capacity: 6,
|
|
374
|
+
refillPerSecond: 0.1,
|
|
375
|
+
clock,
|
|
376
|
+
});
|
|
324
377
|
const pairs = new SlidingCounter(clock, 60_000);
|
|
325
378
|
const selfName = () => machine?.name ?? 'this machine';
|
|
326
379
|
const isMember = (machineId) => view?.members.has(machineId) === true;
|
|
@@ -346,10 +399,107 @@ export function createNamzuNetwork(options) {
|
|
|
346
399
|
machine = { ...m.value, name };
|
|
347
400
|
}
|
|
348
401
|
else {
|
|
349
|
-
machine = {
|
|
402
|
+
machine = {
|
|
403
|
+
v: 1,
|
|
404
|
+
machineId: key.machineId,
|
|
405
|
+
name,
|
|
406
|
+
createdAt: clock.now(),
|
|
407
|
+
};
|
|
350
408
|
}
|
|
351
409
|
await store.writeMachine(machine);
|
|
352
410
|
}
|
|
411
|
+
// ─── the computer secret ───────────────────────────────────────────────
|
|
412
|
+
/** The secret, read afresh each time (a rotation or a loosened file takes effect at once). Never repaired. */
|
|
413
|
+
async function computerSecret() {
|
|
414
|
+
const source = options.machineSecret;
|
|
415
|
+
if (!source)
|
|
416
|
+
return undefined;
|
|
417
|
+
const read = await readComputerSecret(source).catch(() => ({ status: 'unsafe', reason: 'the secret cannot be read' }));
|
|
418
|
+
if (read.status === 'ok')
|
|
419
|
+
return read.secret;
|
|
420
|
+
if (read.status === 'unsafe' && !unavailableSeen.has(read.reason)) {
|
|
421
|
+
unavailableSeen.add(read.reason);
|
|
422
|
+
logAudit({ event: 'same_computer_unavailable', reason: read.reason });
|
|
423
|
+
}
|
|
424
|
+
return undefined;
|
|
425
|
+
}
|
|
426
|
+
async function ensureSecret() {
|
|
427
|
+
const source = options.machineSecret;
|
|
428
|
+
if (!source)
|
|
429
|
+
return;
|
|
430
|
+
try {
|
|
431
|
+
await ensureComputerSecret(source, options.hardenDirectory);
|
|
432
|
+
}
|
|
433
|
+
catch {
|
|
434
|
+
// no secret: this home asks like any other
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
/** Remembered machines of the secret this home reads now; marks earned under another secret are not shown. */
|
|
438
|
+
async function sameComputerSet(secret) {
|
|
439
|
+
if (!sameComputerIds || sameComputerFp !== computerSecretFingerprint(secret)) {
|
|
440
|
+
const fp = computerSecretFingerprint(secret);
|
|
441
|
+
const r = await store.readSameComputer().catch(() => undefined);
|
|
442
|
+
sameComputerFp = fp;
|
|
443
|
+
sameComputerIds = new Set(r?.status === 'ok' && r.value.fp === fp ? r.value.machines : []);
|
|
444
|
+
}
|
|
445
|
+
return sameComputerIds;
|
|
446
|
+
}
|
|
447
|
+
async function rememberSameComputer(machineId, secret) {
|
|
448
|
+
const set = await sameComputerSet(secret);
|
|
449
|
+
if (set.has(machineId))
|
|
450
|
+
return;
|
|
451
|
+
set.add(machineId);
|
|
452
|
+
await store
|
|
453
|
+
.writeSameComputer({
|
|
454
|
+
v: 1,
|
|
455
|
+
fp: computerSecretFingerprint(secret),
|
|
456
|
+
machines: [...set].slice(-64),
|
|
457
|
+
})
|
|
458
|
+
.catch(() => undefined);
|
|
459
|
+
}
|
|
460
|
+
/** Whether this request proves the joiner holds the computer secret, and the person allows acting on it. */
|
|
461
|
+
async function provesSameComputer(request, joinerId, sourceAddress) {
|
|
462
|
+
if (request.computerProof === undefined)
|
|
463
|
+
return false;
|
|
464
|
+
const failed = proofFailures.get(sourceAddress);
|
|
465
|
+
if (failed &&
|
|
466
|
+
clock.now() - failed.at < JOIN_ADDRESS_WINDOW_MS &&
|
|
467
|
+
failed.count >= MAX_PROOF_FAILURES)
|
|
468
|
+
return false;
|
|
469
|
+
if (options.sameComputer?.() === false)
|
|
470
|
+
return false;
|
|
471
|
+
if ((options.autoAdmit?.() ?? 'trusted-networks') === 'never')
|
|
472
|
+
return false;
|
|
473
|
+
const secret = await computerSecret();
|
|
474
|
+
if (!secret)
|
|
475
|
+
return false;
|
|
476
|
+
const ok = verifyComputerJoinProof(secret, request.computerProof, joinerId, selfId(), request.nonce);
|
|
477
|
+
if (!ok) {
|
|
478
|
+
const now = clock.now();
|
|
479
|
+
const prev = proofFailures.get(sourceAddress);
|
|
480
|
+
proofFailures.set(sourceAddress, {
|
|
481
|
+
at: prev && now - prev.at < JOIN_ADDRESS_WINDOW_MS ? prev.at : now,
|
|
482
|
+
count: prev && now - prev.at < JOIN_ADDRESS_WINDOW_MS ? prev.count + 1 : 1,
|
|
483
|
+
});
|
|
484
|
+
if (proofFailures.size > 256)
|
|
485
|
+
proofFailures.delete(proofFailures.keys().next().value);
|
|
486
|
+
// One line per joiner and address, not one per request.
|
|
487
|
+
const seen = `${sourceAddress}|${joinerId}`;
|
|
488
|
+
if (!mismatchSeen.has(seen)) {
|
|
489
|
+
if (mismatchSeen.size > 256)
|
|
490
|
+
mismatchSeen.clear();
|
|
491
|
+
mismatchSeen.add(seen);
|
|
492
|
+
logAudit({
|
|
493
|
+
event: 'same_computer_mismatch',
|
|
494
|
+
machine: {
|
|
495
|
+
id12: shortMachineId(joinerId),
|
|
496
|
+
name: sanitizeName(request.machineName),
|
|
497
|
+
},
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
return ok;
|
|
502
|
+
}
|
|
353
503
|
function defaultName() {
|
|
354
504
|
const raw = (options.hostname ?? osHostname()).split('.')[0] ?? '';
|
|
355
505
|
return raw.trim().length > 0 ? raw : 'this-machine';
|
|
@@ -439,7 +589,11 @@ export function createNamzuNetwork(options) {
|
|
|
439
589
|
await persistMembership();
|
|
440
590
|
for (const id of added) {
|
|
441
591
|
if (id !== selfId())
|
|
442
|
-
emit({
|
|
592
|
+
emit({
|
|
593
|
+
type: 'member-added',
|
|
594
|
+
machineId: id,
|
|
595
|
+
name: peerState.get(id)?.name,
|
|
596
|
+
});
|
|
443
597
|
}
|
|
444
598
|
for (const id of removed) {
|
|
445
599
|
if (id === selfId())
|
|
@@ -447,7 +601,11 @@ export function createNamzuNetwork(options) {
|
|
|
447
601
|
for (const l of netListeners)
|
|
448
602
|
l.closeMachine(id);
|
|
449
603
|
logAudit({ event: 'removed', machine: who(id) });
|
|
450
|
-
emit({
|
|
604
|
+
emit({
|
|
605
|
+
type: 'member-removed',
|
|
606
|
+
machineId: id,
|
|
607
|
+
name: peerState.get(id)?.name,
|
|
608
|
+
});
|
|
451
609
|
}
|
|
452
610
|
if (!merged.members.has(selfId()))
|
|
453
611
|
await handleSelfRemoved();
|
|
@@ -715,14 +873,21 @@ export function createNamzuNetwork(options) {
|
|
|
715
873
|
}
|
|
716
874
|
async function advertise() {
|
|
717
875
|
if (netId && port !== undefined) {
|
|
718
|
-
discovery.start({
|
|
876
|
+
discovery.start({
|
|
877
|
+
netId,
|
|
878
|
+
port,
|
|
879
|
+
addresses: addresses.map((a) => a.address),
|
|
880
|
+
});
|
|
719
881
|
}
|
|
720
882
|
}
|
|
721
883
|
async function found() {
|
|
722
884
|
if (!key || netId)
|
|
723
885
|
return;
|
|
724
886
|
const founding = createFounding(key, clock.now());
|
|
725
|
-
const next = evaluateMembership({
|
|
887
|
+
const next = evaluateMembership({
|
|
888
|
+
admissions: [founding],
|
|
889
|
+
revocations: [],
|
|
890
|
+
});
|
|
726
891
|
netId = next.netId;
|
|
727
892
|
foundedAt = clock.now();
|
|
728
893
|
adopt(next);
|
|
@@ -743,6 +908,8 @@ export function createNamzuNetwork(options) {
|
|
|
743
908
|
return;
|
|
744
909
|
if (clock.now() - foundedAt > FRESH_NETWORK_MS)
|
|
745
910
|
return;
|
|
911
|
+
if (await backingOff(endpoint.netId))
|
|
912
|
+
return;
|
|
746
913
|
const keyText = `${endpoint.host}:${endpoint.port}`;
|
|
747
914
|
if (probing.has(keyText))
|
|
748
915
|
return;
|
|
@@ -756,7 +923,10 @@ export function createNamzuNetwork(options) {
|
|
|
756
923
|
clock,
|
|
757
924
|
});
|
|
758
925
|
try {
|
|
759
|
-
const reply = (await client.request({
|
|
926
|
+
const reply = (await client.request({
|
|
927
|
+
protocol: NET_PROTOCOL,
|
|
928
|
+
op: 'ping_net',
|
|
929
|
+
}));
|
|
760
930
|
if (reply.netId === endpoint.netId && typeof reply.ageMs === 'number')
|
|
761
931
|
theirAge = reply.ageMs;
|
|
762
932
|
}
|
|
@@ -782,7 +952,7 @@ export function createNamzuNetwork(options) {
|
|
|
782
952
|
return;
|
|
783
953
|
declinedNets.add(endpoint.netId);
|
|
784
954
|
emit({ type: 'nearby', networks: [endpoint.netId] });
|
|
785
|
-
await
|
|
955
|
+
await joinNetwork({ host: endpoint.host, port: endpoint.port }, endpoint.netId).catch(() => undefined);
|
|
786
956
|
}
|
|
787
957
|
async function afterBrowse() {
|
|
788
958
|
cancelBrowse = undefined;
|
|
@@ -793,8 +963,12 @@ export function createNamzuNetwork(options) {
|
|
|
793
963
|
return found();
|
|
794
964
|
if (nets.length === 1) {
|
|
795
965
|
const target = nearby.get(nets[0])[0];
|
|
966
|
+
if (await backingOff(target.netId)) {
|
|
967
|
+
setState('searching', 'This machine asked to join a Namzu network lately; it will not ask again yet.');
|
|
968
|
+
return;
|
|
969
|
+
}
|
|
796
970
|
setState('searching', 'Asking to join a Namzu network nearby.');
|
|
797
|
-
void
|
|
971
|
+
void joinNetwork({ host: target.host, port: target.port }, target.netId).catch(() => undefined);
|
|
798
972
|
return;
|
|
799
973
|
}
|
|
800
974
|
setState('ambiguous', `Found ${nets.length} Namzu networks nearby.`);
|
|
@@ -813,13 +987,18 @@ export function createNamzuNetwork(options) {
|
|
|
813
987
|
return;
|
|
814
988
|
}
|
|
815
989
|
await loadIdentity();
|
|
990
|
+
await ensureSecret();
|
|
816
991
|
await loadNetwork();
|
|
817
992
|
await startListeners(list);
|
|
818
993
|
logAudit({ event: 'network_on' });
|
|
819
994
|
offDiscovery.push(discovery.onFound(onEndpoint));
|
|
820
995
|
if (netId) {
|
|
821
996
|
setState('ready');
|
|
822
|
-
discovery.start({
|
|
997
|
+
discovery.start({
|
|
998
|
+
netId,
|
|
999
|
+
port: port,
|
|
1000
|
+
addresses: list.map((a) => a.address),
|
|
1001
|
+
});
|
|
823
1002
|
for (const id of view?.members.keys() ?? []) {
|
|
824
1003
|
if (id === selfId())
|
|
825
1004
|
continue;
|
|
@@ -892,7 +1071,26 @@ export function createNamzuNetwork(options) {
|
|
|
892
1071
|
};
|
|
893
1072
|
cancelRecheck = clock.setTimer(tick, INTERFACE_RECHECK_MS);
|
|
894
1073
|
}
|
|
895
|
-
|
|
1074
|
+
/**
|
|
1075
|
+
* Whether this machine asked `target` lately and was told no (or never answered): the ask is one per
|
|
1076
|
+
* machine, kept in the machine's own network directory, so a terminal that opens later, or takes the
|
|
1077
|
+
* lead from one that closed, does not ask again at once. A person's own `join` never waits on this.
|
|
1078
|
+
*/
|
|
1079
|
+
async function backingOff(target) {
|
|
1080
|
+
const attempt = await store.readJoinAttempt().catch(() => undefined);
|
|
1081
|
+
if (attempt?.status !== 'ok')
|
|
1082
|
+
return false;
|
|
1083
|
+
const { value } = attempt;
|
|
1084
|
+
if (value.target !== target || !value.result || value.endedAt === undefined)
|
|
1085
|
+
return false;
|
|
1086
|
+
const wait = value.result === 'denied' ? JOIN_BACKOFF_DENIED_MS : JOIN_BACKOFF_OTHER_MS;
|
|
1087
|
+
return clock.now() - value.endedAt < wait;
|
|
1088
|
+
}
|
|
1089
|
+
/** A person's request: asks now, whatever happened to an earlier ask. */
|
|
1090
|
+
function join(endpoint) {
|
|
1091
|
+
return joinNetwork(endpoint, undefined);
|
|
1092
|
+
}
|
|
1093
|
+
async function joinNetwork(endpoint, netIdHint) {
|
|
896
1094
|
if (!tls || !key)
|
|
897
1095
|
throw new NetworkError('off', 'The Namzu network is not running.');
|
|
898
1096
|
if (view && view.members.size > 1)
|
|
@@ -901,25 +1099,84 @@ export function createNamzuNetwork(options) {
|
|
|
901
1099
|
throw new NetworkError('invalid', 'A request to join is already waiting.');
|
|
902
1100
|
joining = true;
|
|
903
1101
|
const publicKey = key.publicKeyDer.toString('base64');
|
|
904
|
-
|
|
1102
|
+
// One ask per machine and network: while it waits, a repeat (another terminal, a restart) uses the
|
|
1103
|
+
// same nonce, so the machine asked finds the same request and shows the same code.
|
|
1104
|
+
// A person's ask only knows the address until the member answers; the record is then keyed by the
|
|
1105
|
+
// network id, so a refusal of a person's ask backs the machine's own asks off like any other.
|
|
1106
|
+
let target = netIdHint ?? `${endpoint.host}:${endpoint.port}`;
|
|
1107
|
+
const prior = await store.readJoinAttempt().catch(() => undefined);
|
|
1108
|
+
const reuse = prior?.status === 'ok' &&
|
|
1109
|
+
prior.value.target === target &&
|
|
1110
|
+
prior.value.result === undefined &&
|
|
1111
|
+
clock.now() - prior.value.startedAt < JOIN_EXPIRY_MS;
|
|
1112
|
+
const nonce = reuse && prior?.status === 'ok' ? prior.value.nonce : randomBytes(16).toString('base64');
|
|
1113
|
+
if (!reuse)
|
|
1114
|
+
await store
|
|
1115
|
+
.writeJoinAttempt({ v: 1, target, nonce, startedAt: clock.now() })
|
|
1116
|
+
.catch(() => undefined);
|
|
1117
|
+
const settle = async (result) => {
|
|
1118
|
+
if (result === 'joined' || result === 'cancelled') {
|
|
1119
|
+
await store.clearJoinAttempt().catch(() => undefined);
|
|
1120
|
+
return;
|
|
1121
|
+
}
|
|
1122
|
+
await store
|
|
1123
|
+
.writeJoinAttempt({
|
|
1124
|
+
v: 1,
|
|
1125
|
+
target,
|
|
1126
|
+
nonce,
|
|
1127
|
+
startedAt: reuse && prior?.status === 'ok' ? prior.value.startedAt : clock.now(),
|
|
1128
|
+
result,
|
|
1129
|
+
endedAt: clock.now(),
|
|
1130
|
+
})
|
|
1131
|
+
.catch(() => undefined);
|
|
1132
|
+
};
|
|
905
1133
|
let client;
|
|
906
1134
|
joinCancelled = false;
|
|
907
1135
|
try {
|
|
908
1136
|
client = await connectTo(endpoint, undefined).catch(() => undefined);
|
|
909
1137
|
if (!client) {
|
|
910
|
-
client = await dialNet({
|
|
1138
|
+
client = await dialNet({
|
|
1139
|
+
identity: tls,
|
|
1140
|
+
host: endpoint.host,
|
|
1141
|
+
port: endpoint.port,
|
|
1142
|
+
clock,
|
|
1143
|
+
});
|
|
911
1144
|
}
|
|
912
1145
|
joinClient = client;
|
|
913
|
-
|
|
1146
|
+
joinEndpoint = endpoint;
|
|
1147
|
+
const secret = await computerSecret();
|
|
1148
|
+
const ask = (conn, withProof) => conn.request({
|
|
914
1149
|
protocol: NET_PROTOCOL,
|
|
915
1150
|
op: 'join_request',
|
|
916
1151
|
machineName: selfName(),
|
|
917
1152
|
publicKey,
|
|
918
1153
|
nonce,
|
|
1154
|
+
...(withProof && secret
|
|
1155
|
+
? {
|
|
1156
|
+
computerProof: computerJoinProof(secret, key?.machineId, conn.peer.machineId, nonce),
|
|
1157
|
+
}
|
|
1158
|
+
: {}),
|
|
919
1159
|
});
|
|
1160
|
+
let first = await ask(client, true);
|
|
1161
|
+
if (secret &&
|
|
1162
|
+
typeof first === 'object' &&
|
|
1163
|
+
first !== null &&
|
|
1164
|
+
first.error === 'bad_request') {
|
|
1165
|
+
// An older member does not know the proof field and closed on it: ask again plainly.
|
|
1166
|
+
client.close();
|
|
1167
|
+
client = await dialNet({
|
|
1168
|
+
identity: tls,
|
|
1169
|
+
host: endpoint.host,
|
|
1170
|
+
port: endpoint.port,
|
|
1171
|
+
clock,
|
|
1172
|
+
});
|
|
1173
|
+
joinClient = client;
|
|
1174
|
+
first = await ask(client, false);
|
|
1175
|
+
}
|
|
920
1176
|
const pending = PendingFrameSchema.safeParse(first);
|
|
921
1177
|
if (!pending.success) {
|
|
922
1178
|
const reason = EndFrameSchema.safeParse(first);
|
|
1179
|
+
await settle('refused');
|
|
923
1180
|
emit({
|
|
924
1181
|
type: 'join-ended',
|
|
925
1182
|
result: 'refused',
|
|
@@ -927,8 +1184,14 @@ export function createNamzuNetwork(options) {
|
|
|
927
1184
|
});
|
|
928
1185
|
return 'refused';
|
|
929
1186
|
}
|
|
1187
|
+
target = pending.data.netId;
|
|
930
1188
|
const code = joinCode(key.machineId, client.peer.machineId, nonce, pending.data.nonce);
|
|
931
|
-
emit({
|
|
1189
|
+
emit({
|
|
1190
|
+
type: 'join-waiting',
|
|
1191
|
+
code,
|
|
1192
|
+
shownCode: formatJoinCode(code),
|
|
1193
|
+
endpoint,
|
|
1194
|
+
});
|
|
932
1195
|
let final;
|
|
933
1196
|
try {
|
|
934
1197
|
final = await client.nextFrame();
|
|
@@ -936,6 +1199,7 @@ export function createNamzuNetwork(options) {
|
|
|
936
1199
|
catch (error) {
|
|
937
1200
|
if (!joinCancelled)
|
|
938
1201
|
throw error;
|
|
1202
|
+
await settle('cancelled');
|
|
939
1203
|
emit({ type: 'join-ended', result: 'cancelled' });
|
|
940
1204
|
return 'cancelled';
|
|
941
1205
|
}
|
|
@@ -949,11 +1213,20 @@ export function createNamzuNetwork(options) {
|
|
|
949
1213
|
? 'expired'
|
|
950
1214
|
: 'refused'
|
|
951
1215
|
: 'refused';
|
|
952
|
-
|
|
1216
|
+
await settle(result);
|
|
1217
|
+
emit({
|
|
1218
|
+
type: 'join-ended',
|
|
1219
|
+
result,
|
|
1220
|
+
reason: end.success ? end.data.reason : undefined,
|
|
1221
|
+
});
|
|
953
1222
|
return result;
|
|
954
1223
|
}
|
|
955
|
-
const verdict = evaluateMembership({
|
|
1224
|
+
const verdict = evaluateMembership({
|
|
1225
|
+
admissions: admitted.data.admissions,
|
|
1226
|
+
revocations: admitted.data.revocations,
|
|
1227
|
+
}, pending.data.netId);
|
|
956
1228
|
if (verdict.netId !== pending.data.netId || !verdict.members.has(key.machineId)) {
|
|
1229
|
+
await settle('refused');
|
|
957
1230
|
emit({
|
|
958
1231
|
type: 'join-ended',
|
|
959
1232
|
result: 'refused',
|
|
@@ -968,6 +1241,7 @@ export function createNamzuNetwork(options) {
|
|
|
968
1241
|
netId = verdict.netId;
|
|
969
1242
|
foundedAt = undefined;
|
|
970
1243
|
await persistMembership();
|
|
1244
|
+
await settle('joined');
|
|
971
1245
|
for (const p of admitted.data.peers) {
|
|
972
1246
|
if (p.machineId === key.machineId)
|
|
973
1247
|
continue;
|
|
@@ -979,8 +1253,18 @@ export function createNamzuNetwork(options) {
|
|
|
979
1253
|
});
|
|
980
1254
|
}
|
|
981
1255
|
remember(client.peer.machineId, endpoint);
|
|
1256
|
+
// Mutual: the member's claim counts only with its own proof, so a machine that merely sets the flag is not marked.
|
|
1257
|
+
if (admitted.data.sameComputer === true &&
|
|
1258
|
+
admitted.data.computerMemberProof !== undefined &&
|
|
1259
|
+
secret &&
|
|
1260
|
+
verifyComputerMemberProof(secret, admitted.data.computerMemberProof, client.peer.machineId, key.machineId, nonce, pending.data.nonce))
|
|
1261
|
+
await rememberSameComputer(client.peer.machineId, secret);
|
|
982
1262
|
setState('ready');
|
|
983
|
-
emit({
|
|
1263
|
+
emit({
|
|
1264
|
+
type: 'joined',
|
|
1265
|
+
netId: netId,
|
|
1266
|
+
members: verdict.members.size,
|
|
1267
|
+
});
|
|
984
1268
|
await advertise();
|
|
985
1269
|
for (const id of verdict.members.keys())
|
|
986
1270
|
if (id !== key.machineId)
|
|
@@ -990,6 +1274,7 @@ export function createNamzuNetwork(options) {
|
|
|
990
1274
|
finally {
|
|
991
1275
|
joining = false;
|
|
992
1276
|
joinClient = undefined;
|
|
1277
|
+
joinEndpoint = undefined;
|
|
993
1278
|
client?.close();
|
|
994
1279
|
}
|
|
995
1280
|
}
|
|
@@ -998,21 +1283,48 @@ export function createNamzuNetwork(options) {
|
|
|
998
1283
|
return false;
|
|
999
1284
|
joinCancelled = true;
|
|
1000
1285
|
joinClient.close();
|
|
1286
|
+
// Closing alone leaves the request waiting on the other machine; say that it is withdrawn.
|
|
1287
|
+
const at = joinEndpoint;
|
|
1288
|
+
if (tls && at)
|
|
1289
|
+
void dialNet({ identity: tls, host: at.host, port: at.port, clock })
|
|
1290
|
+
.then(async (client) => {
|
|
1291
|
+
try {
|
|
1292
|
+
await client.request({ protocol: NET_PROTOCOL, op: 'join_cancel' });
|
|
1293
|
+
}
|
|
1294
|
+
finally {
|
|
1295
|
+
client.close();
|
|
1296
|
+
}
|
|
1297
|
+
})
|
|
1298
|
+
.catch(() => undefined);
|
|
1001
1299
|
return true;
|
|
1002
1300
|
}
|
|
1003
1301
|
// ─── request handling ──────────────────────────────────────────────────
|
|
1004
1302
|
function peersForJoiner() {
|
|
1005
1303
|
const out = [
|
|
1006
|
-
{
|
|
1304
|
+
{
|
|
1305
|
+
machineId: selfId(),
|
|
1306
|
+
name: selfName(),
|
|
1307
|
+
addresses: ourHostPorts().slice(0, 8),
|
|
1308
|
+
},
|
|
1007
1309
|
];
|
|
1008
1310
|
for (const [id, p] of peerState) {
|
|
1009
1311
|
if (isMember(id) && id !== selfId())
|
|
1010
|
-
out.push({
|
|
1312
|
+
out.push({
|
|
1313
|
+
machineId: id,
|
|
1314
|
+
name: p.name,
|
|
1315
|
+
addresses: p.addresses.slice(0, 4),
|
|
1316
|
+
});
|
|
1011
1317
|
}
|
|
1012
1318
|
return out.slice(0, MAX_MEMBERS);
|
|
1013
1319
|
}
|
|
1014
1320
|
function admittedFrame() {
|
|
1015
|
-
return {
|
|
1321
|
+
return {
|
|
1322
|
+
status: 'admitted',
|
|
1323
|
+
netId,
|
|
1324
|
+
admissions: adm,
|
|
1325
|
+
revocations: rev,
|
|
1326
|
+
peers: peersForJoiner(),
|
|
1327
|
+
};
|
|
1016
1328
|
}
|
|
1017
1329
|
function buildSelfRoster() {
|
|
1018
1330
|
const sessions = host
|
|
@@ -1051,6 +1363,13 @@ export function createNamzuNetwork(options) {
|
|
|
1051
1363
|
: { ok: true };
|
|
1052
1364
|
case 'join_request':
|
|
1053
1365
|
return handleJoinRequest(request, ctx);
|
|
1366
|
+
case 'join_cancel': {
|
|
1367
|
+
// Only the machine that asked can withdraw its own request, and only the one it asked here.
|
|
1368
|
+
const waiting = joiners.findByJoiner(peerId);
|
|
1369
|
+
if (waiting?.local)
|
|
1370
|
+
retireJoin(waiting);
|
|
1371
|
+
return { ok: true };
|
|
1372
|
+
}
|
|
1054
1373
|
case 'hello': {
|
|
1055
1374
|
const p = peerState.get(peerId) ?? {
|
|
1056
1375
|
name: request.machineName,
|
|
@@ -1064,13 +1383,26 @@ export function createNamzuNetwork(options) {
|
|
|
1064
1383
|
for (const a of request.addresses)
|
|
1065
1384
|
remember(peerId, a);
|
|
1066
1385
|
void persistPeers();
|
|
1067
|
-
return {
|
|
1386
|
+
return {
|
|
1387
|
+
machineName: selfName(),
|
|
1388
|
+
addresses: ourHostPorts().slice(0, 8),
|
|
1389
|
+
};
|
|
1068
1390
|
}
|
|
1069
1391
|
case 'members_sync': {
|
|
1070
1392
|
await mergeIn(request.admissions, request.revocations);
|
|
1071
1393
|
return { admissions: adm, revocations: rev };
|
|
1072
1394
|
}
|
|
1073
1395
|
case 'join_pending': {
|
|
1396
|
+
// The same machine asking through another member replaces what was waiting from it.
|
|
1397
|
+
const earlier = joiners.findByJoiner(machineIdOf(Buffer.from(request.publicKey, 'base64')));
|
|
1398
|
+
if (earlier && !earlier.local && earlier.requestId !== request.requestId) {
|
|
1399
|
+
joiners.settle(earlier.requestId, 'deny');
|
|
1400
|
+
emit({
|
|
1401
|
+
type: 'join-settled',
|
|
1402
|
+
requestId: earlier.requestId,
|
|
1403
|
+
result: 'deny',
|
|
1404
|
+
});
|
|
1405
|
+
}
|
|
1074
1406
|
const created = joiners.addRemote({
|
|
1075
1407
|
requestId: request.requestId,
|
|
1076
1408
|
name: sanitizeName(request.name),
|
|
@@ -1103,12 +1435,42 @@ export function createNamzuNetwork(options) {
|
|
|
1103
1435
|
const joinerKey = Buffer.from(request.publicKey, 'base64');
|
|
1104
1436
|
const joinerId = machineIdOf(joinerKey);
|
|
1105
1437
|
if (joinerId !== ctx.peer.machineId)
|
|
1106
|
-
return {
|
|
1438
|
+
return {
|
|
1439
|
+
status: 'refused',
|
|
1440
|
+
reason: 'The key does not match the connection.',
|
|
1441
|
+
};
|
|
1107
1442
|
if (view.members.has(joinerId))
|
|
1108
1443
|
return { ...admittedFrame() };
|
|
1109
1444
|
if (view.removed.has(joinerId))
|
|
1110
|
-
return {
|
|
1111
|
-
|
|
1445
|
+
return {
|
|
1446
|
+
status: 'refused',
|
|
1447
|
+
reason: 'This machine was removed from the network.',
|
|
1448
|
+
};
|
|
1449
|
+
// A machine has one request waiting, however many times it asks: the same ask again (same nonce,
|
|
1450
|
+
// as when another terminal of that machine takes over) keeps the request and its code and only
|
|
1451
|
+
// takes over the held connection; a different ask replaces the old one.
|
|
1452
|
+
const prior = joiners.findByJoiner(joinerId);
|
|
1453
|
+
const known = prior ? askNonces.get(prior.requestId) : undefined;
|
|
1454
|
+
if (prior?.local && known && known.joinerNonce === request.nonce) {
|
|
1455
|
+
const old = pendingConns.get(prior.requestId);
|
|
1456
|
+
pendingConns.set(prior.requestId, ctx);
|
|
1457
|
+
ctx.holdOpen();
|
|
1458
|
+
watchHeld(prior.requestId, ctx);
|
|
1459
|
+
ctx.write({ status: 'pending', nonce: known.memberNonce, netId });
|
|
1460
|
+
old?.close();
|
|
1461
|
+
return undefined;
|
|
1462
|
+
}
|
|
1463
|
+
// A different ask is a new request and meets the same one-a-minute limit as any address; check
|
|
1464
|
+
// before the old one is retired, so a refused ask leaves it standing.
|
|
1465
|
+
// The proof is the only evidence of the same computer: no address, name or hint is read.
|
|
1466
|
+
const same = await provesSameComputer(request, joinerId, ctx.sourceAddress).catch(() => false);
|
|
1467
|
+
if (!same && joiners.tooSoon(ctx.sourceAddress))
|
|
1468
|
+
return { status: 'refused', reason: 'Asked again too soon.' };
|
|
1469
|
+
if (prior)
|
|
1470
|
+
retireJoin(prior);
|
|
1471
|
+
const auto = same
|
|
1472
|
+
? { mode: 'same-computer' }
|
|
1473
|
+
: await autoAdmitMode(ctx.sourceAddress).catch(() => undefined);
|
|
1112
1474
|
const nonceM = randomBytes(16).toString('base64');
|
|
1113
1475
|
const code = joinCode(joinerId, selfId(), request.nonce, nonceM);
|
|
1114
1476
|
const requestId = randomUUID();
|
|
@@ -1120,21 +1482,23 @@ export function createNamzuNetwork(options) {
|
|
|
1120
1482
|
viaMachineId: selfId(),
|
|
1121
1483
|
joinerMachineId: joinerId,
|
|
1122
1484
|
joinerPublicKey: request.publicKey,
|
|
1123
|
-
});
|
|
1485
|
+
}, same);
|
|
1124
1486
|
if (!added.ok)
|
|
1125
1487
|
return {
|
|
1126
1488
|
status: 'refused',
|
|
1127
1489
|
reason: added.reason === 'rate' ? 'Asked again too soon.' : 'Too many requests are waiting.',
|
|
1128
1490
|
};
|
|
1491
|
+
askNonces.set(requestId, {
|
|
1492
|
+
joinerNonce: request.nonce,
|
|
1493
|
+
memberNonce: nonceM,
|
|
1494
|
+
});
|
|
1495
|
+
if (askNonces.size > 64)
|
|
1496
|
+
for (const id of askNonces.keys())
|
|
1497
|
+
if (!joiners.get(id))
|
|
1498
|
+
askNonces.delete(id);
|
|
1129
1499
|
ctx.holdOpen();
|
|
1130
1500
|
pendingConns.set(requestId, ctx);
|
|
1131
|
-
ctx
|
|
1132
|
-
pendingConns.delete(requestId);
|
|
1133
|
-
if (joiners.get(requestId)) {
|
|
1134
|
-
joiners.settle(requestId, 'deny');
|
|
1135
|
-
emit({ type: 'join-settled', requestId, result: 'deny' });
|
|
1136
|
-
}
|
|
1137
|
-
});
|
|
1501
|
+
watchHeld(requestId, ctx);
|
|
1138
1502
|
// The joiner must read `pending` before any decision can reach it, so write it first.
|
|
1139
1503
|
ctx.write({ status: 'pending', nonce: nonceM, netId });
|
|
1140
1504
|
logAudit({
|
|
@@ -1143,6 +1507,8 @@ export function createNamzuNetwork(options) {
|
|
|
1143
1507
|
});
|
|
1144
1508
|
if (auto) {
|
|
1145
1509
|
try {
|
|
1510
|
+
if (auto.mode === 'same-computer')
|
|
1511
|
+
proven.add(requestId);
|
|
1146
1512
|
// Admitted without asking: nobody is shown a request, so the other members are not told of one.
|
|
1147
1513
|
emit({
|
|
1148
1514
|
type: 'join-auto',
|
|
@@ -1153,12 +1519,15 @@ export function createNamzuNetwork(options) {
|
|
|
1153
1519
|
...(auto.network ? { network: auto.network } : {}),
|
|
1154
1520
|
at: clock.now(),
|
|
1155
1521
|
});
|
|
1156
|
-
await decideJoin(requestId, 'allow', auto.mode === '
|
|
1157
|
-
? 'automatically (
|
|
1158
|
-
:
|
|
1522
|
+
await decideJoin(requestId, 'allow', auto.mode === 'same-computer'
|
|
1523
|
+
? 'automatically (same computer)'
|
|
1524
|
+
: auto.mode === 'always'
|
|
1525
|
+
? 'automatically (network.autoAdmit is always)'
|
|
1526
|
+
: `automatically (trusted network ${auto.network})`);
|
|
1159
1527
|
return undefined;
|
|
1160
1528
|
}
|
|
1161
1529
|
catch {
|
|
1530
|
+
proven.delete(requestId);
|
|
1162
1531
|
// fall through: the request waits for a person like any other
|
|
1163
1532
|
}
|
|
1164
1533
|
}
|
|
@@ -1166,6 +1535,42 @@ export function createNamzuNetwork(options) {
|
|
|
1166
1535
|
void gossipPending(added.entry, request.publicKey);
|
|
1167
1536
|
return undefined;
|
|
1168
1537
|
}
|
|
1538
|
+
/**
|
|
1539
|
+
* A waiting request outlives its connection: the terminal of the joining machine that asked may close
|
|
1540
|
+
* (another one of the same machine asks again and finds the same request and code), and an Allow given
|
|
1541
|
+
* meanwhile still lets the machine in. It ends by an answer, by the joiner's `join_cancel`, by a
|
|
1542
|
+
* newer request from the same machine, or by its ten minutes.
|
|
1543
|
+
*/
|
|
1544
|
+
function watchHeld(requestId, ctx) {
|
|
1545
|
+
orphanTimers.get(requestId)?.();
|
|
1546
|
+
orphanTimers.delete(requestId);
|
|
1547
|
+
ctx.onClose(() => {
|
|
1548
|
+
if (pendingConns.get(requestId) !== ctx)
|
|
1549
|
+
return;
|
|
1550
|
+
pendingConns.delete(requestId);
|
|
1551
|
+
// Long enough for another terminal of the machine to take over; a stranger that asks and leaves
|
|
1552
|
+
// does not keep a slot for ten minutes.
|
|
1553
|
+
orphanTimers.set(requestId, clock.setTimer(() => {
|
|
1554
|
+
orphanTimers.delete(requestId);
|
|
1555
|
+
const entry = joiners.get(requestId);
|
|
1556
|
+
if (entry?.local && !pendingConns.has(requestId))
|
|
1557
|
+
retireJoin(entry);
|
|
1558
|
+
}, JOIN_ORPHAN_MS));
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1561
|
+
/** A request that a newer one from the same machine replaced: gone from every screen, nobody told it no. */
|
|
1562
|
+
function retireJoin(entry) {
|
|
1563
|
+
orphanTimers.get(entry.requestId)?.();
|
|
1564
|
+
orphanTimers.delete(entry.requestId);
|
|
1565
|
+
const conn = pendingConns.get(entry.requestId);
|
|
1566
|
+
pendingConns.delete(entry.requestId);
|
|
1567
|
+
askNonces.delete(entry.requestId);
|
|
1568
|
+
joiners.settle(entry.requestId, 'deny');
|
|
1569
|
+
emit({ type: 'join-settled', requestId: entry.requestId, result: 'deny' });
|
|
1570
|
+
conn?.close();
|
|
1571
|
+
if (entry.local)
|
|
1572
|
+
void gossipDecision(entry.requestId, 'deny', undefined, selfId());
|
|
1573
|
+
}
|
|
1169
1574
|
async function gossipPending(entry, publicKey) {
|
|
1170
1575
|
const frame = {
|
|
1171
1576
|
protocol: NET_PROTOCOL,
|
|
@@ -1186,7 +1591,11 @@ export function createNamzuNetwork(options) {
|
|
|
1186
1591
|
function rememberJoinerName(machineId, name) {
|
|
1187
1592
|
if (peerState.has(machineId))
|
|
1188
1593
|
return;
|
|
1189
|
-
peerState.set(machineId, {
|
|
1594
|
+
peerState.set(machineId, {
|
|
1595
|
+
name: sanitizeName(name),
|
|
1596
|
+
addresses: [],
|
|
1597
|
+
online: false,
|
|
1598
|
+
});
|
|
1190
1599
|
}
|
|
1191
1600
|
async function handleJoinDecision(request, from, note) {
|
|
1192
1601
|
const entry = joiners.get(request.requestId);
|
|
@@ -1201,7 +1610,11 @@ export function createNamzuNetwork(options) {
|
|
|
1201
1610
|
rememberJoinerName(request.admission.machineId, entry.name);
|
|
1202
1611
|
await mergeIn([request.admission], []);
|
|
1203
1612
|
}
|
|
1204
|
-
emit({
|
|
1613
|
+
emit({
|
|
1614
|
+
type: 'join-settled',
|
|
1615
|
+
requestId: request.requestId,
|
|
1616
|
+
result: request.decision,
|
|
1617
|
+
});
|
|
1205
1618
|
return { ok: true };
|
|
1206
1619
|
}
|
|
1207
1620
|
if (joiners.decide(request.requestId, request.decision) !== 'ok')
|
|
@@ -1211,24 +1624,45 @@ export function createNamzuNetwork(options) {
|
|
|
1211
1624
|
if (request.decision === 'allow') {
|
|
1212
1625
|
const a = request.admission;
|
|
1213
1626
|
if (!a || a.machineId !== entry.joinerMachineId || a.admittedBy !== from) {
|
|
1214
|
-
conn?.write({
|
|
1627
|
+
conn?.write({
|
|
1628
|
+
status: 'refused',
|
|
1629
|
+
reason: 'The admission did not match the request.',
|
|
1630
|
+
});
|
|
1215
1631
|
conn?.close();
|
|
1216
1632
|
return { ok: false };
|
|
1217
1633
|
}
|
|
1218
1634
|
rememberJoinerName(a.machineId, entry.name);
|
|
1219
1635
|
await mergeIn([a], []);
|
|
1220
1636
|
if (!isMember(a.machineId)) {
|
|
1221
|
-
conn?.write({
|
|
1637
|
+
conn?.write({
|
|
1638
|
+
status: 'refused',
|
|
1639
|
+
reason: 'The admission did not check out.',
|
|
1640
|
+
});
|
|
1222
1641
|
conn?.close();
|
|
1223
1642
|
return { ok: false };
|
|
1224
1643
|
}
|
|
1225
|
-
|
|
1644
|
+
const memberSecret = proven.has(request.requestId) ? await computerSecret() : undefined;
|
|
1645
|
+
const asked = askNonces.get(request.requestId);
|
|
1646
|
+
if (memberSecret)
|
|
1647
|
+
await rememberSameComputer(a.machineId, memberSecret);
|
|
1648
|
+
conn?.write(memberSecret && asked
|
|
1649
|
+
? {
|
|
1650
|
+
...admittedFrame(),
|
|
1651
|
+
sameComputer: true,
|
|
1652
|
+
computerMemberProof: computerMemberProof(memberSecret, selfId(), a.machineId, asked.joinerNonce, asked.memberNonce),
|
|
1653
|
+
}
|
|
1654
|
+
: admittedFrame());
|
|
1655
|
+
proven.delete(request.requestId);
|
|
1226
1656
|
logAudit({
|
|
1227
1657
|
event: 'join_allowed',
|
|
1228
1658
|
machine: { id12: shortMachineId(a.machineId), name: entry.name },
|
|
1229
1659
|
decision: note ?? `by ${shortMachineId(from)}`,
|
|
1230
1660
|
});
|
|
1231
|
-
emit({
|
|
1661
|
+
emit({
|
|
1662
|
+
type: 'join-settled',
|
|
1663
|
+
requestId: request.requestId,
|
|
1664
|
+
result: 'allow',
|
|
1665
|
+
});
|
|
1232
1666
|
void pushSync();
|
|
1233
1667
|
void gossipDecision(request.requestId, 'allow', a, from);
|
|
1234
1668
|
}
|
|
@@ -1236,10 +1670,17 @@ export function createNamzuNetwork(options) {
|
|
|
1236
1670
|
conn?.write({ status: 'denied' });
|
|
1237
1671
|
logAudit({
|
|
1238
1672
|
event: 'join_denied',
|
|
1239
|
-
machine: {
|
|
1673
|
+
machine: {
|
|
1674
|
+
id12: shortMachineId(entry.joinerMachineId ?? ''),
|
|
1675
|
+
name: entry.name,
|
|
1676
|
+
},
|
|
1240
1677
|
decision: `by ${shortMachineId(from)}`,
|
|
1241
1678
|
});
|
|
1242
|
-
emit({
|
|
1679
|
+
emit({
|
|
1680
|
+
type: 'join-settled',
|
|
1681
|
+
requestId: request.requestId,
|
|
1682
|
+
result: 'deny',
|
|
1683
|
+
});
|
|
1243
1684
|
void gossipDecision(request.requestId, 'deny', undefined, from);
|
|
1244
1685
|
}
|
|
1245
1686
|
conn?.close();
|
|
@@ -1296,7 +1737,11 @@ export function createNamzuNetwork(options) {
|
|
|
1296
1737
|
joiners.settle(entry.requestId, decision);
|
|
1297
1738
|
if (reply?.ok === false)
|
|
1298
1739
|
throw new NetworkError('refused', 'That request was already decided on another machine.');
|
|
1299
|
-
emit({
|
|
1740
|
+
emit({
|
|
1741
|
+
type: 'join-settled',
|
|
1742
|
+
requestId: entry.requestId,
|
|
1743
|
+
result: decision,
|
|
1744
|
+
});
|
|
1300
1745
|
return entry;
|
|
1301
1746
|
}
|
|
1302
1747
|
// ─── roles ─────────────────────────────────────────────────────────────
|
|
@@ -1314,16 +1759,28 @@ export function createNamzuNetwork(options) {
|
|
|
1314
1759
|
}
|
|
1315
1760
|
async function handleRoleSet(request, from) {
|
|
1316
1761
|
if (!roleBuckets.take(from))
|
|
1317
|
-
return {
|
|
1762
|
+
return {
|
|
1763
|
+
status: 'refused',
|
|
1764
|
+
reason: 'Too many role changes from that machine.',
|
|
1765
|
+
};
|
|
1318
1766
|
const role = request.role === null ? null : (sanitizeRole(request.role) ?? null);
|
|
1319
1767
|
const byName = peerState.get(from)?.name ?? sanitizeName(request.by.machineName);
|
|
1320
1768
|
if ('machine' in request.target) {
|
|
1321
1769
|
if (!machine)
|
|
1322
1770
|
return { status: 'refused', reason: 'No machine.' };
|
|
1323
|
-
machine = {
|
|
1771
|
+
machine = {
|
|
1772
|
+
...machine,
|
|
1773
|
+
...(role === null ? { role: undefined } : { role }),
|
|
1774
|
+
};
|
|
1324
1775
|
await store.writeMachine(machine);
|
|
1325
1776
|
logAudit({ event: 'role_set', ...roleAudit(from, 'machine', role) });
|
|
1326
|
-
emit({
|
|
1777
|
+
emit({
|
|
1778
|
+
type: 'role',
|
|
1779
|
+
target: 'machine',
|
|
1780
|
+
role,
|
|
1781
|
+
byMachine: byName,
|
|
1782
|
+
at: request.at,
|
|
1783
|
+
});
|
|
1327
1784
|
return { status: 'applied' };
|
|
1328
1785
|
}
|
|
1329
1786
|
const ref = request.target.sessionRef;
|
|
@@ -1344,7 +1801,13 @@ export function createNamzuNetwork(options) {
|
|
|
1344
1801
|
if (!ok)
|
|
1345
1802
|
return { status: 'refused', reason: 'That session is not running here.' };
|
|
1346
1803
|
logAudit({ event: 'role_set', ...roleAudit(from, ref, role) });
|
|
1347
|
-
emit({
|
|
1804
|
+
emit({
|
|
1805
|
+
type: 'role',
|
|
1806
|
+
target: ref,
|
|
1807
|
+
role,
|
|
1808
|
+
byMachine: byName,
|
|
1809
|
+
at: request.at,
|
|
1810
|
+
});
|
|
1348
1811
|
return { status: 'applied' };
|
|
1349
1812
|
}
|
|
1350
1813
|
async function setRole(target, role) {
|
|
@@ -1394,7 +1857,10 @@ export function createNamzuNetwork(options) {
|
|
|
1394
1857
|
const stale = !p || p.rosterAt === undefined || clock.now() - p.rosterAt > ROSTER_FRESH_MS;
|
|
1395
1858
|
if (stale) {
|
|
1396
1859
|
try {
|
|
1397
|
-
const roster = RosterSchema.safeParse(await callMachine(machineId, {
|
|
1860
|
+
const roster = RosterSchema.safeParse(await callMachine(machineId, {
|
|
1861
|
+
protocol: NET_PROTOCOL,
|
|
1862
|
+
op: 'roster',
|
|
1863
|
+
}));
|
|
1398
1864
|
if (roster.success)
|
|
1399
1865
|
applyRoster(machineId, roster.data);
|
|
1400
1866
|
}
|
|
@@ -1692,6 +2158,9 @@ export function createNamzuNetwork(options) {
|
|
|
1692
2158
|
}
|
|
1693
2159
|
const now = clock.now();
|
|
1694
2160
|
const own = buildSelfRoster();
|
|
2161
|
+
// A live fact: remembered machines count only while this home can still read the secret.
|
|
2162
|
+
const rosterSecret = await computerSecret();
|
|
2163
|
+
const sameSet = rosterSecret ? await sameComputerSet(rosterSecret) : new Set();
|
|
1695
2164
|
const machines = [
|
|
1696
2165
|
{
|
|
1697
2166
|
machineId: selfId(),
|
|
@@ -1712,6 +2181,7 @@ export function createNamzuNetwork(options) {
|
|
|
1712
2181
|
status: online || (opts.refresh === false && p?.online === true) ? 'online' : 'offline',
|
|
1713
2182
|
seenAt: p?.seenAt,
|
|
1714
2183
|
role: p?.role,
|
|
2184
|
+
...(sameSet.has(id) ? { sameComputer: true } : {}),
|
|
1715
2185
|
sessions: p?.sessions
|
|
1716
2186
|
? online
|
|
1717
2187
|
? p.sessions
|
|
@@ -1737,6 +2207,11 @@ export function createNamzuNetwork(options) {
|
|
|
1737
2207
|
for (const c of pendingConns.values())
|
|
1738
2208
|
c.close();
|
|
1739
2209
|
pendingConns.clear();
|
|
2210
|
+
for (const cancel of orphanTimers.values())
|
|
2211
|
+
cancel();
|
|
2212
|
+
orphanTimers.clear();
|
|
2213
|
+
// A terminal that stops lets go of its waiting ask without withdrawing it, as when its process ends.
|
|
2214
|
+
joinClient?.close();
|
|
1740
2215
|
await discovery.close().catch(() => undefined);
|
|
1741
2216
|
await Promise.all(netListeners.splice(0).map((l) => l.close()));
|
|
1742
2217
|
}
|
|
@@ -1758,7 +2233,11 @@ export function createNamzuNetwork(options) {
|
|
|
1758
2233
|
state,
|
|
1759
2234
|
reason: stateReason,
|
|
1760
2235
|
machine: machine && key
|
|
1761
|
-
? {
|
|
2236
|
+
? {
|
|
2237
|
+
id: key.machineId,
|
|
2238
|
+
name: machine.name ?? selfName(),
|
|
2239
|
+
role: machine.role,
|
|
2240
|
+
}
|
|
1762
2241
|
: undefined,
|
|
1763
2242
|
netId,
|
|
1764
2243
|
members: view?.members.size ?? 0,
|