@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/src/network/service.ts
CHANGED
|
@@ -26,6 +26,16 @@ import { networkInterfaces, hostname as osHostname, platform as osPlatform } fro
|
|
|
26
26
|
import { z } from 'zod'
|
|
27
27
|
import { type AuditEntry, type AuditSink, createFileAuditSink, textHash } from './audit.js'
|
|
28
28
|
import { type NetworkClock, systemClock } from './clock.js'
|
|
29
|
+
import {
|
|
30
|
+
type ComputerSecretSource,
|
|
31
|
+
computerJoinProof,
|
|
32
|
+
computerMemberProof,
|
|
33
|
+
computerSecretFingerprint,
|
|
34
|
+
ensureComputerSecret,
|
|
35
|
+
readComputerSecret,
|
|
36
|
+
verifyComputerJoinProof,
|
|
37
|
+
verifyComputerMemberProof,
|
|
38
|
+
} from './computer.js'
|
|
29
39
|
import {
|
|
30
40
|
type DiscoveredEndpoint,
|
|
31
41
|
type ListenAddress,
|
|
@@ -35,7 +45,17 @@ import {
|
|
|
35
45
|
} from './discovery.js'
|
|
36
46
|
import { createNetworkIdentity, createSystemGatewayReader } from './fingerprint.js'
|
|
37
47
|
import { type MachineKey, generateMachineKey, machineIdOf, shortMachineId } from './identity.js'
|
|
38
|
-
import {
|
|
48
|
+
import {
|
|
49
|
+
JOIN_ADDRESS_WINDOW_MS,
|
|
50
|
+
JOIN_BACKOFF_DENIED_MS,
|
|
51
|
+
JOIN_BACKOFF_OTHER_MS,
|
|
52
|
+
JOIN_EXPIRY_MS,
|
|
53
|
+
JOIN_ORPHAN_MS,
|
|
54
|
+
JoinTable,
|
|
55
|
+
type PendingJoin,
|
|
56
|
+
formatJoinCode,
|
|
57
|
+
joinCode,
|
|
58
|
+
} from './join.js'
|
|
39
59
|
import {
|
|
40
60
|
HoldQueue,
|
|
41
61
|
type MailSetting,
|
|
@@ -103,6 +123,8 @@ export const FRESH_NETWORK_MS = 60_000
|
|
|
103
123
|
export const INTERFACE_RECHECK_MS = 30_000
|
|
104
124
|
export const ROSTER_FRESH_MS = 15_000
|
|
105
125
|
const MAX_NEARBY_NETWORKS = 8
|
|
126
|
+
/** Wrong computer proofs one address may send in a join window before its proofs are no longer checked. */
|
|
127
|
+
const MAX_PROOF_FAILURES = 5
|
|
106
128
|
|
|
107
129
|
/** A message from a session on another machine, as the host receives it. */
|
|
108
130
|
export interface RemoteMail {
|
|
@@ -127,7 +149,10 @@ export interface NetworkHost {
|
|
|
127
149
|
deliverLocal(
|
|
128
150
|
sessionRef: string,
|
|
129
151
|
mail: RemoteMail,
|
|
130
|
-
): Promise<{
|
|
152
|
+
): Promise<{
|
|
153
|
+
readonly status: 'queued' | 'refused'
|
|
154
|
+
readonly reason?: string
|
|
155
|
+
}>
|
|
131
156
|
/** Record a role on a local session; false when there is no such session. Never touches permissions. */
|
|
132
157
|
setLocalRole?(
|
|
133
158
|
sessionRef: string,
|
|
@@ -156,7 +181,11 @@ export interface HeldMail {
|
|
|
156
181
|
}
|
|
157
182
|
|
|
158
183
|
export type NetworkEvent =
|
|
159
|
-
| {
|
|
184
|
+
| {
|
|
185
|
+
readonly type: 'state'
|
|
186
|
+
readonly state: NetworkState
|
|
187
|
+
readonly reason?: string
|
|
188
|
+
}
|
|
160
189
|
| { readonly type: 'founded'; readonly netId: string }
|
|
161
190
|
| {
|
|
162
191
|
readonly type: 'join-waiting'
|
|
@@ -164,7 +193,11 @@ export type NetworkEvent =
|
|
|
164
193
|
readonly shownCode: string
|
|
165
194
|
readonly endpoint: HostPort
|
|
166
195
|
}
|
|
167
|
-
| {
|
|
196
|
+
| {
|
|
197
|
+
readonly type: 'joined'
|
|
198
|
+
readonly netId: string
|
|
199
|
+
readonly members: number
|
|
200
|
+
}
|
|
168
201
|
| {
|
|
169
202
|
readonly type: 'join-ended'
|
|
170
203
|
readonly result: 'denied' | 'expired' | 'refused' | 'cancelled'
|
|
@@ -172,12 +205,12 @@ export type NetworkEvent =
|
|
|
172
205
|
}
|
|
173
206
|
| { readonly type: 'join-request'; readonly request: PendingJoin }
|
|
174
207
|
| {
|
|
175
|
-
/** A join was admitted without asking
|
|
208
|
+
/** A join was admitted without asking: a trusted network, `network.autoAdmit` `always`, or another home of the same person on this computer (`same-computer`, proven by the computer secret). */
|
|
176
209
|
readonly type: 'join-auto'
|
|
177
210
|
readonly requestId: string
|
|
178
211
|
readonly name: string
|
|
179
212
|
readonly machineId: string
|
|
180
|
-
readonly mode: 'trusted-network' | 'always'
|
|
213
|
+
readonly mode: 'trusted-network' | 'always' | 'same-computer'
|
|
181
214
|
/** The name of the trusted network, when that is why. */
|
|
182
215
|
readonly network?: string
|
|
183
216
|
readonly at: number
|
|
@@ -187,8 +220,16 @@ export type NetworkEvent =
|
|
|
187
220
|
readonly requestId: string
|
|
188
221
|
readonly result: 'allow' | 'deny' | 'expired'
|
|
189
222
|
}
|
|
190
|
-
| {
|
|
191
|
-
|
|
223
|
+
| {
|
|
224
|
+
readonly type: 'member-added'
|
|
225
|
+
readonly machineId: string
|
|
226
|
+
readonly name?: string
|
|
227
|
+
}
|
|
228
|
+
| {
|
|
229
|
+
readonly type: 'member-removed'
|
|
230
|
+
readonly machineId: string
|
|
231
|
+
readonly name?: string
|
|
232
|
+
}
|
|
192
233
|
| { readonly type: 'removed-self' }
|
|
193
234
|
| { readonly type: 'nearby'; readonly networks: readonly string[] }
|
|
194
235
|
| { readonly type: 'held'; readonly mail: HeldMail }
|
|
@@ -250,6 +291,15 @@ export interface NetworkServiceOptions {
|
|
|
250
291
|
* network, or never. Read at each request.
|
|
251
292
|
*/
|
|
252
293
|
readonly autoAdmit?: () => AutoAdmitSetting
|
|
294
|
+
/**
|
|
295
|
+
* The computer secret this home may use (the host decides; see `resolveComputerSecret`). Absent: this home
|
|
296
|
+
* never proves or accepts a same-computer join and asks like any other machine.
|
|
297
|
+
*/
|
|
298
|
+
readonly machineSecret?: ComputerSecretSource
|
|
299
|
+
/** Whether a proof of the same computer admits without asking. Read at each request; default true. */
|
|
300
|
+
readonly sameComputer?: () => boolean
|
|
301
|
+
/** Tighten a directory the service creates (the CLI's also restricts a Windows ACL). */
|
|
302
|
+
readonly hardenDirectory?: (path: string) => void
|
|
253
303
|
/** Which local network an address is on (see `fingerprint.ts`); undefined when unknown. Tests inject one. */
|
|
254
304
|
readonly networkIdentity?: (address: string) => Promise<string | undefined>
|
|
255
305
|
readonly audit?: AuditSink
|
|
@@ -298,6 +348,10 @@ const PeerEntrySchema = z
|
|
|
298
348
|
const AdmittedFrameSchema = z
|
|
299
349
|
.object({
|
|
300
350
|
status: z.literal('admitted'),
|
|
351
|
+
/** Only when the member admitted this machine on the computer proof. */
|
|
352
|
+
sameComputer: z.literal(true).optional(),
|
|
353
|
+
/** The member's counter-proof (base64 HMAC, 44 characters); the joiner marks the member only when it verifies. */
|
|
354
|
+
computerMemberProof: z.string().length(44).optional(),
|
|
301
355
|
netId: z.string().length(16).optional(),
|
|
302
356
|
admissions: z.array(AdmissionSchema).max(MAX_MEMBERS * 2),
|
|
303
357
|
revocations: z.array(RevocationSchema).max(MAX_MEMBERS * 2),
|
|
@@ -305,10 +359,17 @@ const AdmittedFrameSchema = z
|
|
|
305
359
|
})
|
|
306
360
|
.strict()
|
|
307
361
|
const PendingFrameSchema = z
|
|
308
|
-
.object({
|
|
362
|
+
.object({
|
|
363
|
+
status: z.literal('pending'),
|
|
364
|
+
nonce: z.string(),
|
|
365
|
+
netId: z.string().length(16),
|
|
366
|
+
})
|
|
309
367
|
.strict()
|
|
310
368
|
const EndFrameSchema = z
|
|
311
|
-
.object({
|
|
369
|
+
.object({
|
|
370
|
+
status: z.enum(['denied', 'expired', 'refused']),
|
|
371
|
+
reason: z.string().optional(),
|
|
372
|
+
})
|
|
312
373
|
.strict()
|
|
313
374
|
const HelloReplySchema = z
|
|
314
375
|
.object({
|
|
@@ -317,7 +378,10 @@ const HelloReplySchema = z
|
|
|
317
378
|
})
|
|
318
379
|
.strict()
|
|
319
380
|
const SyncReplySchema = z
|
|
320
|
-
.object({
|
|
381
|
+
.object({
|
|
382
|
+
admissions: z.array(AdmissionSchema),
|
|
383
|
+
revocations: z.array(RevocationSchema),
|
|
384
|
+
})
|
|
321
385
|
.strict()
|
|
322
386
|
/** Words from another machine that reach a screen or a model: no control characters, one line, short. */
|
|
323
387
|
function cleanReason(value: string | undefined): string | undefined {
|
|
@@ -374,11 +438,18 @@ export interface NetworkService {
|
|
|
374
438
|
setRole(
|
|
375
439
|
target: { readonly machineId: string; readonly sessionRef?: string },
|
|
376
440
|
role: string | null,
|
|
377
|
-
): Promise<{
|
|
441
|
+
): Promise<{
|
|
442
|
+
readonly status: 'applied' | 'refused'
|
|
443
|
+
readonly reason?: string
|
|
444
|
+
}>
|
|
378
445
|
send(
|
|
379
446
|
target: { readonly machineId: string; readonly sessionRef: string },
|
|
380
447
|
text: string,
|
|
381
|
-
from: {
|
|
448
|
+
from: {
|
|
449
|
+
readonly sessionRef: string
|
|
450
|
+
readonly sessionName: string
|
|
451
|
+
readonly mode: string
|
|
452
|
+
},
|
|
382
453
|
options?: { readonly inReplyTo?: string; readonly hops?: number },
|
|
383
454
|
): Promise<{
|
|
384
455
|
readonly id: string
|
|
@@ -450,7 +521,10 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
450
521
|
const store = options.store ?? createNetworkStore({ home: options.home })
|
|
451
522
|
const audit: AuditSink =
|
|
452
523
|
options.audit ??
|
|
453
|
-
createFileAuditSink({
|
|
524
|
+
createFileAuditSink({
|
|
525
|
+
dir: store.dir,
|
|
526
|
+
report: (m) => options.host.report?.(m),
|
|
527
|
+
})
|
|
454
528
|
const discovery = options.discovery
|
|
455
529
|
const host = options.host
|
|
456
530
|
const platform = options.platform ?? osPlatform()
|
|
@@ -474,9 +548,31 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
474
548
|
const peerState = new Map<string, PeerState>()
|
|
475
549
|
const nearby = new Map<string, DiscoveredEndpoint[]>()
|
|
476
550
|
const pendingConns = new Map<string, ServerContext>()
|
|
551
|
+
/** Requests admitted by the computer proof: their `admitted` frame says so. */
|
|
552
|
+
const proven = new Set<string>()
|
|
553
|
+
const unavailableSeen = new Set<string>()
|
|
554
|
+
/** Machines of this computer, by proof, in either direction. */
|
|
555
|
+
let sameComputerIds: Set<string> | undefined
|
|
556
|
+
let sameComputerFp: string | undefined
|
|
557
|
+
/** Failed proofs per source address: past a few in a minute the proof is no longer even checked. */
|
|
558
|
+
const proofFailures = new Map<string, { at: number; count: number }>()
|
|
559
|
+
const mismatchSeen = new Set<string>()
|
|
560
|
+
/** Cancels for the timers of requests whose connection dropped. */
|
|
561
|
+
const orphanTimers = new Map<string, () => void>()
|
|
562
|
+
/** What a waiting request was made of, so the same machine asking again with the same nonce gets the same code. */
|
|
563
|
+
const askNonces = new Map<
|
|
564
|
+
string,
|
|
565
|
+
{ readonly joinerNonce: string; readonly memberNonce: string }
|
|
566
|
+
>()
|
|
477
567
|
const sent = new Map<
|
|
478
568
|
string,
|
|
479
|
-
{
|
|
569
|
+
{
|
|
570
|
+
machineId: string
|
|
571
|
+
at: number
|
|
572
|
+
session: string
|
|
573
|
+
bytes: number
|
|
574
|
+
textHash: string
|
|
575
|
+
}
|
|
480
576
|
>()
|
|
481
577
|
const seenMail: string[] = []
|
|
482
578
|
const inFlight = new Set<string>()
|
|
@@ -484,6 +580,7 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
484
580
|
let cancelBrowse: (() => void) | undefined
|
|
485
581
|
let cancelRecheck: (() => void) | undefined
|
|
486
582
|
let joining = false
|
|
583
|
+
let joinEndpoint: HostPort | undefined
|
|
487
584
|
let joinClient: NetClient | undefined
|
|
488
585
|
let joinCancelled = false
|
|
489
586
|
let foundedAt: number | undefined
|
|
@@ -546,7 +643,11 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
546
643
|
const names = new Set(list.map((n) => n.name.toLowerCase()))
|
|
547
644
|
let n = list.length + 1
|
|
548
645
|
while (names.has(`network ${n}`)) n++
|
|
549
|
-
return {
|
|
646
|
+
return {
|
|
647
|
+
id,
|
|
648
|
+
...(known ? { trusted: known.name } : {}),
|
|
649
|
+
suggestedName: `Network ${n}`,
|
|
650
|
+
}
|
|
550
651
|
}
|
|
551
652
|
|
|
552
653
|
async function trustNetwork(address: string, name?: string): Promise<TrustedNetwork> {
|
|
@@ -613,7 +714,10 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
613
714
|
async function untrustNetwork(query: string): Promise<TrustedNetwork> {
|
|
614
715
|
const list = await trustedList()
|
|
615
716
|
const gone = findTrusted(list, query)
|
|
616
|
-
await store.writeTrustedNetworks({
|
|
717
|
+
await store.writeTrustedNetworks({
|
|
718
|
+
v: 1,
|
|
719
|
+
networks: list.filter((n) => n.id !== gone.id),
|
|
720
|
+
})
|
|
617
721
|
logAudit({ event: 'network_untrusted', reason: gone.name })
|
|
618
722
|
return gone
|
|
619
723
|
}
|
|
@@ -643,7 +747,11 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
643
747
|
event: 'join_expired',
|
|
644
748
|
machine: { id12: entry.viaMachineId.slice(0, 12), name: entry.name },
|
|
645
749
|
})
|
|
646
|
-
emit({
|
|
750
|
+
emit({
|
|
751
|
+
type: 'join-settled',
|
|
752
|
+
requestId: entry.requestId,
|
|
753
|
+
result: 'expired',
|
|
754
|
+
})
|
|
647
755
|
},
|
|
648
756
|
})
|
|
649
757
|
const heldQueue = new HoldQueue<HeldMail>({
|
|
@@ -660,8 +768,16 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
660
768
|
void notifySender(mail, 'expired', 'The message was not answered in time and has expired.')
|
|
661
769
|
},
|
|
662
770
|
})
|
|
663
|
-
const mailBuckets = new TokenBuckets({
|
|
664
|
-
|
|
771
|
+
const mailBuckets = new TokenBuckets({
|
|
772
|
+
capacity: 30,
|
|
773
|
+
refillPerSecond: 0.5,
|
|
774
|
+
clock,
|
|
775
|
+
})
|
|
776
|
+
const roleBuckets = new TokenBuckets({
|
|
777
|
+
capacity: 6,
|
|
778
|
+
refillPerSecond: 0.1,
|
|
779
|
+
clock,
|
|
780
|
+
})
|
|
665
781
|
const pairs = new SlidingCounter(clock, 60_000)
|
|
666
782
|
|
|
667
783
|
const selfName = () => machine?.name ?? 'this machine'
|
|
@@ -690,11 +806,118 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
690
806
|
if (m.status === 'ok' && m.value.machineId === key.machineId) {
|
|
691
807
|
machine = { ...m.value, name }
|
|
692
808
|
} else {
|
|
693
|
-
machine = {
|
|
809
|
+
machine = {
|
|
810
|
+
v: 1,
|
|
811
|
+
machineId: key.machineId,
|
|
812
|
+
name,
|
|
813
|
+
createdAt: clock.now(),
|
|
814
|
+
}
|
|
694
815
|
}
|
|
695
816
|
await store.writeMachine(machine)
|
|
696
817
|
}
|
|
697
818
|
|
|
819
|
+
// ─── the computer secret ───────────────────────────────────────────────
|
|
820
|
+
|
|
821
|
+
/** The secret, read afresh each time (a rotation or a loosened file takes effect at once). Never repaired. */
|
|
822
|
+
async function computerSecret(): Promise<Buffer | undefined> {
|
|
823
|
+
const source = options.machineSecret
|
|
824
|
+
if (!source) return undefined
|
|
825
|
+
const read = await readComputerSecret(source).catch(
|
|
826
|
+
() => ({ status: 'unsafe', reason: 'the secret cannot be read' }) as const,
|
|
827
|
+
)
|
|
828
|
+
if (read.status === 'ok') return read.secret
|
|
829
|
+
if (read.status === 'unsafe' && !unavailableSeen.has(read.reason)) {
|
|
830
|
+
unavailableSeen.add(read.reason)
|
|
831
|
+
logAudit({ event: 'same_computer_unavailable', reason: read.reason })
|
|
832
|
+
}
|
|
833
|
+
return undefined
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
async function ensureSecret(): Promise<void> {
|
|
837
|
+
const source = options.machineSecret
|
|
838
|
+
if (!source) return
|
|
839
|
+
try {
|
|
840
|
+
await ensureComputerSecret(source, options.hardenDirectory)
|
|
841
|
+
} catch {
|
|
842
|
+
// no secret: this home asks like any other
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
/** Remembered machines of the secret this home reads now; marks earned under another secret are not shown. */
|
|
847
|
+
async function sameComputerSet(secret: Buffer): Promise<Set<string>> {
|
|
848
|
+
if (!sameComputerIds || sameComputerFp !== computerSecretFingerprint(secret)) {
|
|
849
|
+
const fp = computerSecretFingerprint(secret)
|
|
850
|
+
const r = await store.readSameComputer().catch(() => undefined)
|
|
851
|
+
sameComputerFp = fp
|
|
852
|
+
sameComputerIds = new Set(r?.status === 'ok' && r.value.fp === fp ? r.value.machines : [])
|
|
853
|
+
}
|
|
854
|
+
return sameComputerIds
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
async function rememberSameComputer(machineId: string, secret: Buffer): Promise<void> {
|
|
858
|
+
const set = await sameComputerSet(secret)
|
|
859
|
+
if (set.has(machineId)) return
|
|
860
|
+
set.add(machineId)
|
|
861
|
+
await store
|
|
862
|
+
.writeSameComputer({
|
|
863
|
+
v: 1,
|
|
864
|
+
fp: computerSecretFingerprint(secret),
|
|
865
|
+
machines: [...set].slice(-64),
|
|
866
|
+
})
|
|
867
|
+
.catch(() => undefined)
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
/** Whether this request proves the joiner holds the computer secret, and the person allows acting on it. */
|
|
871
|
+
async function provesSameComputer(
|
|
872
|
+
request: Extract<NetRequest, { op: 'join_request' }>,
|
|
873
|
+
joinerId: string,
|
|
874
|
+
sourceAddress: string,
|
|
875
|
+
): Promise<boolean> {
|
|
876
|
+
if (request.computerProof === undefined) return false
|
|
877
|
+
const failed = proofFailures.get(sourceAddress)
|
|
878
|
+
if (
|
|
879
|
+
failed &&
|
|
880
|
+
clock.now() - failed.at < JOIN_ADDRESS_WINDOW_MS &&
|
|
881
|
+
failed.count >= MAX_PROOF_FAILURES
|
|
882
|
+
)
|
|
883
|
+
return false
|
|
884
|
+
if (options.sameComputer?.() === false) return false
|
|
885
|
+
if ((options.autoAdmit?.() ?? 'trusted-networks') === 'never') return false
|
|
886
|
+
const secret = await computerSecret()
|
|
887
|
+
if (!secret) return false
|
|
888
|
+
const ok = verifyComputerJoinProof(
|
|
889
|
+
secret,
|
|
890
|
+
request.computerProof,
|
|
891
|
+
joinerId,
|
|
892
|
+
selfId(),
|
|
893
|
+
request.nonce,
|
|
894
|
+
)
|
|
895
|
+
if (!ok) {
|
|
896
|
+
const now = clock.now()
|
|
897
|
+
const prev = proofFailures.get(sourceAddress)
|
|
898
|
+
proofFailures.set(sourceAddress, {
|
|
899
|
+
at: prev && now - prev.at < JOIN_ADDRESS_WINDOW_MS ? prev.at : now,
|
|
900
|
+
count: prev && now - prev.at < JOIN_ADDRESS_WINDOW_MS ? prev.count + 1 : 1,
|
|
901
|
+
})
|
|
902
|
+
if (proofFailures.size > 256)
|
|
903
|
+
proofFailures.delete(proofFailures.keys().next().value as string)
|
|
904
|
+
// One line per joiner and address, not one per request.
|
|
905
|
+
const seen = `${sourceAddress}|${joinerId}`
|
|
906
|
+
if (!mismatchSeen.has(seen)) {
|
|
907
|
+
if (mismatchSeen.size > 256) mismatchSeen.clear()
|
|
908
|
+
mismatchSeen.add(seen)
|
|
909
|
+
logAudit({
|
|
910
|
+
event: 'same_computer_mismatch',
|
|
911
|
+
machine: {
|
|
912
|
+
id12: shortMachineId(joinerId),
|
|
913
|
+
name: sanitizeName(request.machineName),
|
|
914
|
+
},
|
|
915
|
+
})
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
return ok
|
|
919
|
+
}
|
|
920
|
+
|
|
698
921
|
function defaultName(): string {
|
|
699
922
|
const raw = (options.hostname ?? osHostname()).split('.')[0] ?? ''
|
|
700
923
|
return raw.trim().length > 0 ? raw : 'this-machine'
|
|
@@ -797,13 +1020,21 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
797
1020
|
await persistMembership()
|
|
798
1021
|
for (const id of added) {
|
|
799
1022
|
if (id !== selfId())
|
|
800
|
-
emit({
|
|
1023
|
+
emit({
|
|
1024
|
+
type: 'member-added',
|
|
1025
|
+
machineId: id,
|
|
1026
|
+
name: peerState.get(id)?.name,
|
|
1027
|
+
})
|
|
801
1028
|
}
|
|
802
1029
|
for (const id of removed) {
|
|
803
1030
|
if (id === selfId()) continue
|
|
804
1031
|
for (const l of netListeners) l.closeMachine(id)
|
|
805
1032
|
logAudit({ event: 'removed', machine: who(id) })
|
|
806
|
-
emit({
|
|
1033
|
+
emit({
|
|
1034
|
+
type: 'member-removed',
|
|
1035
|
+
machineId: id,
|
|
1036
|
+
name: peerState.get(id)?.name,
|
|
1037
|
+
})
|
|
807
1038
|
}
|
|
808
1039
|
if (!merged.members.has(selfId())) await handleSelfRemoved()
|
|
809
1040
|
return added.length > 0 || removed.length > 0
|
|
@@ -1074,14 +1305,21 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1074
1305
|
|
|
1075
1306
|
async function advertise(): Promise<void> {
|
|
1076
1307
|
if (netId && port !== undefined) {
|
|
1077
|
-
discovery.start({
|
|
1308
|
+
discovery.start({
|
|
1309
|
+
netId,
|
|
1310
|
+
port,
|
|
1311
|
+
addresses: addresses.map((a) => a.address),
|
|
1312
|
+
})
|
|
1078
1313
|
}
|
|
1079
1314
|
}
|
|
1080
1315
|
|
|
1081
1316
|
async function found(): Promise<void> {
|
|
1082
1317
|
if (!key || netId) return
|
|
1083
1318
|
const founding = createFounding(key, clock.now())
|
|
1084
|
-
const next = evaluateMembership({
|
|
1319
|
+
const next = evaluateMembership({
|
|
1320
|
+
admissions: [founding],
|
|
1321
|
+
revocations: [],
|
|
1322
|
+
})
|
|
1085
1323
|
netId = next.netId
|
|
1086
1324
|
foundedAt = clock.now()
|
|
1087
1325
|
adopt(next)
|
|
@@ -1100,6 +1338,7 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1100
1338
|
if (!tls || !netId || foundedAt === undefined || closed) return
|
|
1101
1339
|
if (joining || declinedNets.has(endpoint.netId)) return
|
|
1102
1340
|
if (clock.now() - foundedAt > FRESH_NETWORK_MS) return
|
|
1341
|
+
if (await backingOff(endpoint.netId)) return
|
|
1103
1342
|
const keyText = `${endpoint.host}:${endpoint.port}`
|
|
1104
1343
|
if (probing.has(keyText)) return
|
|
1105
1344
|
probing.add(keyText)
|
|
@@ -1112,7 +1351,10 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1112
1351
|
clock,
|
|
1113
1352
|
})
|
|
1114
1353
|
try {
|
|
1115
|
-
const reply = (await client.request({
|
|
1354
|
+
const reply = (await client.request({
|
|
1355
|
+
protocol: NET_PROTOCOL,
|
|
1356
|
+
op: 'ping_net',
|
|
1357
|
+
})) as {
|
|
1116
1358
|
netId?: unknown
|
|
1117
1359
|
ageMs?: unknown
|
|
1118
1360
|
}
|
|
@@ -1134,7 +1376,9 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1134
1376
|
if (!younger) return
|
|
1135
1377
|
declinedNets.add(endpoint.netId)
|
|
1136
1378
|
emit({ type: 'nearby', networks: [endpoint.netId] })
|
|
1137
|
-
await
|
|
1379
|
+
await joinNetwork({ host: endpoint.host, port: endpoint.port }, endpoint.netId).catch(
|
|
1380
|
+
() => undefined,
|
|
1381
|
+
)
|
|
1138
1382
|
}
|
|
1139
1383
|
|
|
1140
1384
|
async function afterBrowse(): Promise<void> {
|
|
@@ -1146,8 +1390,17 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1146
1390
|
const target = (
|
|
1147
1391
|
nearby.get(nets[0] as string) as DiscoveredEndpoint[]
|
|
1148
1392
|
)[0] as DiscoveredEndpoint
|
|
1393
|
+
if (await backingOff(target.netId)) {
|
|
1394
|
+
setState(
|
|
1395
|
+
'searching',
|
|
1396
|
+
'This machine asked to join a Namzu network lately; it will not ask again yet.',
|
|
1397
|
+
)
|
|
1398
|
+
return
|
|
1399
|
+
}
|
|
1149
1400
|
setState('searching', 'Asking to join a Namzu network nearby.')
|
|
1150
|
-
void
|
|
1401
|
+
void joinNetwork({ host: target.host, port: target.port }, target.netId).catch(
|
|
1402
|
+
() => undefined,
|
|
1403
|
+
)
|
|
1151
1404
|
return
|
|
1152
1405
|
}
|
|
1153
1406
|
setState('ambiguous', `Found ${nets.length} Namzu networks nearby.`)
|
|
@@ -1166,13 +1419,18 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1166
1419
|
return
|
|
1167
1420
|
}
|
|
1168
1421
|
await loadIdentity()
|
|
1422
|
+
await ensureSecret()
|
|
1169
1423
|
await loadNetwork()
|
|
1170
1424
|
await startListeners(list)
|
|
1171
1425
|
logAudit({ event: 'network_on' })
|
|
1172
1426
|
offDiscovery.push(discovery.onFound(onEndpoint))
|
|
1173
1427
|
if (netId) {
|
|
1174
1428
|
setState('ready')
|
|
1175
|
-
discovery.start({
|
|
1429
|
+
discovery.start({
|
|
1430
|
+
netId,
|
|
1431
|
+
port: port as number,
|
|
1432
|
+
addresses: list.map((a) => a.address),
|
|
1433
|
+
})
|
|
1176
1434
|
for (const id of view?.members.keys() ?? []) {
|
|
1177
1435
|
if (id === selfId()) continue
|
|
1178
1436
|
void reconnect(id)
|
|
@@ -1239,8 +1497,30 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1239
1497
|
cancelRecheck = clock.setTimer(tick, INTERFACE_RECHECK_MS)
|
|
1240
1498
|
}
|
|
1241
1499
|
|
|
1242
|
-
|
|
1500
|
+
/**
|
|
1501
|
+
* Whether this machine asked `target` lately and was told no (or never answered): the ask is one per
|
|
1502
|
+
* machine, kept in the machine's own network directory, so a terminal that opens later, or takes the
|
|
1503
|
+
* lead from one that closed, does not ask again at once. A person's own `join` never waits on this.
|
|
1504
|
+
*/
|
|
1505
|
+
async function backingOff(target: string): Promise<boolean> {
|
|
1506
|
+
const attempt = await store.readJoinAttempt().catch(() => undefined)
|
|
1507
|
+
if (attempt?.status !== 'ok') return false
|
|
1508
|
+
const { value } = attempt
|
|
1509
|
+
if (value.target !== target || !value.result || value.endedAt === undefined) return false
|
|
1510
|
+
const wait = value.result === 'denied' ? JOIN_BACKOFF_DENIED_MS : JOIN_BACKOFF_OTHER_MS
|
|
1511
|
+
return clock.now() - value.endedAt < wait
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
/** A person's request: asks now, whatever happened to an earlier ask. */
|
|
1515
|
+
function join(
|
|
1243
1516
|
endpoint: HostPort,
|
|
1517
|
+
): Promise<'joined' | 'denied' | 'expired' | 'refused' | 'cancelled'> {
|
|
1518
|
+
return joinNetwork(endpoint, undefined)
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
async function joinNetwork(
|
|
1522
|
+
endpoint: HostPort,
|
|
1523
|
+
netIdHint: string | undefined,
|
|
1244
1524
|
): Promise<'joined' | 'denied' | 'expired' | 'refused' | 'cancelled'> {
|
|
1245
1525
|
if (!tls || !key) throw new NetworkError('off', 'The Namzu network is not running.')
|
|
1246
1526
|
if (view && view.members.size > 1)
|
|
@@ -1248,25 +1528,94 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1248
1528
|
if (joining) throw new NetworkError('invalid', 'A request to join is already waiting.')
|
|
1249
1529
|
joining = true
|
|
1250
1530
|
const publicKey = key.publicKeyDer.toString('base64')
|
|
1251
|
-
|
|
1531
|
+
// One ask per machine and network: while it waits, a repeat (another terminal, a restart) uses the
|
|
1532
|
+
// same nonce, so the machine asked finds the same request and shows the same code.
|
|
1533
|
+
// A person's ask only knows the address until the member answers; the record is then keyed by the
|
|
1534
|
+
// network id, so a refusal of a person's ask backs the machine's own asks off like any other.
|
|
1535
|
+
let target = netIdHint ?? `${endpoint.host}:${endpoint.port}`
|
|
1536
|
+
const prior = await store.readJoinAttempt().catch(() => undefined)
|
|
1537
|
+
const reuse =
|
|
1538
|
+
prior?.status === 'ok' &&
|
|
1539
|
+
prior.value.target === target &&
|
|
1540
|
+
prior.value.result === undefined &&
|
|
1541
|
+
clock.now() - prior.value.startedAt < JOIN_EXPIRY_MS
|
|
1542
|
+
const nonce =
|
|
1543
|
+
reuse && prior?.status === 'ok' ? prior.value.nonce : randomBytes(16).toString('base64')
|
|
1544
|
+
if (!reuse)
|
|
1545
|
+
await store
|
|
1546
|
+
.writeJoinAttempt({ v: 1, target, nonce, startedAt: clock.now() })
|
|
1547
|
+
.catch(() => undefined)
|
|
1548
|
+
const settle = async (result: 'denied' | 'expired' | 'refused' | 'joined' | 'cancelled') => {
|
|
1549
|
+
if (result === 'joined' || result === 'cancelled') {
|
|
1550
|
+
await store.clearJoinAttempt().catch(() => undefined)
|
|
1551
|
+
return
|
|
1552
|
+
}
|
|
1553
|
+
await store
|
|
1554
|
+
.writeJoinAttempt({
|
|
1555
|
+
v: 1,
|
|
1556
|
+
target,
|
|
1557
|
+
nonce,
|
|
1558
|
+
startedAt: reuse && prior?.status === 'ok' ? prior.value.startedAt : clock.now(),
|
|
1559
|
+
result,
|
|
1560
|
+
endedAt: clock.now(),
|
|
1561
|
+
})
|
|
1562
|
+
.catch(() => undefined)
|
|
1563
|
+
}
|
|
1252
1564
|
let client: NetClient | undefined
|
|
1253
1565
|
joinCancelled = false
|
|
1254
1566
|
try {
|
|
1255
1567
|
client = await connectTo(endpoint, undefined).catch(() => undefined)
|
|
1256
1568
|
if (!client) {
|
|
1257
|
-
client = await dialNet({
|
|
1569
|
+
client = await dialNet({
|
|
1570
|
+
identity: tls,
|
|
1571
|
+
host: endpoint.host,
|
|
1572
|
+
port: endpoint.port,
|
|
1573
|
+
clock,
|
|
1574
|
+
})
|
|
1258
1575
|
}
|
|
1259
1576
|
joinClient = client
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1577
|
+
joinEndpoint = endpoint
|
|
1578
|
+
const secret = await computerSecret()
|
|
1579
|
+
const ask = (conn: NetClient, withProof: boolean) =>
|
|
1580
|
+
conn.request({
|
|
1581
|
+
protocol: NET_PROTOCOL,
|
|
1582
|
+
op: 'join_request',
|
|
1583
|
+
machineName: selfName(),
|
|
1584
|
+
publicKey,
|
|
1585
|
+
nonce,
|
|
1586
|
+
...(withProof && secret
|
|
1587
|
+
? {
|
|
1588
|
+
computerProof: computerJoinProof(
|
|
1589
|
+
secret,
|
|
1590
|
+
key?.machineId as string,
|
|
1591
|
+
conn.peer.machineId,
|
|
1592
|
+
nonce,
|
|
1593
|
+
),
|
|
1594
|
+
}
|
|
1595
|
+
: {}),
|
|
1596
|
+
})
|
|
1597
|
+
let first = await ask(client, true)
|
|
1598
|
+
if (
|
|
1599
|
+
secret &&
|
|
1600
|
+
typeof first === 'object' &&
|
|
1601
|
+
first !== null &&
|
|
1602
|
+
(first as { error?: unknown }).error === 'bad_request'
|
|
1603
|
+
) {
|
|
1604
|
+
// An older member does not know the proof field and closed on it: ask again plainly.
|
|
1605
|
+
client.close()
|
|
1606
|
+
client = await dialNet({
|
|
1607
|
+
identity: tls,
|
|
1608
|
+
host: endpoint.host,
|
|
1609
|
+
port: endpoint.port,
|
|
1610
|
+
clock,
|
|
1611
|
+
})
|
|
1612
|
+
joinClient = client
|
|
1613
|
+
first = await ask(client, false)
|
|
1614
|
+
}
|
|
1267
1615
|
const pending = PendingFrameSchema.safeParse(first)
|
|
1268
1616
|
if (!pending.success) {
|
|
1269
1617
|
const reason = EndFrameSchema.safeParse(first)
|
|
1618
|
+
await settle('refused')
|
|
1270
1619
|
emit({
|
|
1271
1620
|
type: 'join-ended',
|
|
1272
1621
|
result: 'refused',
|
|
@@ -1274,13 +1623,20 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1274
1623
|
})
|
|
1275
1624
|
return 'refused'
|
|
1276
1625
|
}
|
|
1626
|
+
target = pending.data.netId
|
|
1277
1627
|
const code = joinCode(key.machineId, client.peer.machineId, nonce, pending.data.nonce)
|
|
1278
|
-
emit({
|
|
1628
|
+
emit({
|
|
1629
|
+
type: 'join-waiting',
|
|
1630
|
+
code,
|
|
1631
|
+
shownCode: formatJoinCode(code),
|
|
1632
|
+
endpoint,
|
|
1633
|
+
})
|
|
1279
1634
|
let final: unknown
|
|
1280
1635
|
try {
|
|
1281
1636
|
final = await client.nextFrame()
|
|
1282
1637
|
} catch (error) {
|
|
1283
1638
|
if (!joinCancelled) throw error
|
|
1639
|
+
await settle('cancelled')
|
|
1284
1640
|
emit({ type: 'join-ended', result: 'cancelled' })
|
|
1285
1641
|
return 'cancelled'
|
|
1286
1642
|
}
|
|
@@ -1294,14 +1650,23 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1294
1650
|
? 'expired'
|
|
1295
1651
|
: 'refused'
|
|
1296
1652
|
: 'refused'
|
|
1297
|
-
|
|
1653
|
+
await settle(result)
|
|
1654
|
+
emit({
|
|
1655
|
+
type: 'join-ended',
|
|
1656
|
+
result,
|
|
1657
|
+
reason: end.success ? end.data.reason : undefined,
|
|
1658
|
+
})
|
|
1298
1659
|
return result
|
|
1299
1660
|
}
|
|
1300
1661
|
const verdict = evaluateMembership(
|
|
1301
|
-
{
|
|
1662
|
+
{
|
|
1663
|
+
admissions: admitted.data.admissions,
|
|
1664
|
+
revocations: admitted.data.revocations,
|
|
1665
|
+
},
|
|
1302
1666
|
pending.data.netId,
|
|
1303
1667
|
)
|
|
1304
1668
|
if (verdict.netId !== pending.data.netId || !verdict.members.has(key.machineId)) {
|
|
1669
|
+
await settle('refused')
|
|
1305
1670
|
emit({
|
|
1306
1671
|
type: 'join-ended',
|
|
1307
1672
|
result: 'refused',
|
|
@@ -1315,6 +1680,7 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1315
1680
|
netId = verdict.netId
|
|
1316
1681
|
foundedAt = undefined
|
|
1317
1682
|
await persistMembership()
|
|
1683
|
+
await settle('joined')
|
|
1318
1684
|
for (const p of admitted.data.peers) {
|
|
1319
1685
|
if (p.machineId === key.machineId) continue
|
|
1320
1686
|
const existing = peerState.get(p.machineId)
|
|
@@ -1325,14 +1691,34 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1325
1691
|
})
|
|
1326
1692
|
}
|
|
1327
1693
|
remember(client.peer.machineId, endpoint)
|
|
1694
|
+
// Mutual: the member's claim counts only with its own proof, so a machine that merely sets the flag is not marked.
|
|
1695
|
+
if (
|
|
1696
|
+
admitted.data.sameComputer === true &&
|
|
1697
|
+
admitted.data.computerMemberProof !== undefined &&
|
|
1698
|
+
secret &&
|
|
1699
|
+
verifyComputerMemberProof(
|
|
1700
|
+
secret,
|
|
1701
|
+
admitted.data.computerMemberProof,
|
|
1702
|
+
client.peer.machineId,
|
|
1703
|
+
key.machineId,
|
|
1704
|
+
nonce,
|
|
1705
|
+
pending.data.nonce,
|
|
1706
|
+
)
|
|
1707
|
+
)
|
|
1708
|
+
await rememberSameComputer(client.peer.machineId, secret)
|
|
1328
1709
|
setState('ready')
|
|
1329
|
-
emit({
|
|
1710
|
+
emit({
|
|
1711
|
+
type: 'joined',
|
|
1712
|
+
netId: netId as string,
|
|
1713
|
+
members: verdict.members.size,
|
|
1714
|
+
})
|
|
1330
1715
|
await advertise()
|
|
1331
1716
|
for (const id of verdict.members.keys()) if (id !== key.machineId) void reconnect(id)
|
|
1332
1717
|
return 'joined'
|
|
1333
1718
|
} finally {
|
|
1334
1719
|
joining = false
|
|
1335
1720
|
joinClient = undefined
|
|
1721
|
+
joinEndpoint = undefined
|
|
1336
1722
|
client?.close()
|
|
1337
1723
|
}
|
|
1338
1724
|
}
|
|
@@ -1341,6 +1727,18 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1341
1727
|
if (!joining || !joinClient) return false
|
|
1342
1728
|
joinCancelled = true
|
|
1343
1729
|
joinClient.close()
|
|
1730
|
+
// Closing alone leaves the request waiting on the other machine; say that it is withdrawn.
|
|
1731
|
+
const at = joinEndpoint
|
|
1732
|
+
if (tls && at)
|
|
1733
|
+
void dialNet({ identity: tls, host: at.host, port: at.port, clock })
|
|
1734
|
+
.then(async (client) => {
|
|
1735
|
+
try {
|
|
1736
|
+
await client.request({ protocol: NET_PROTOCOL, op: 'join_cancel' })
|
|
1737
|
+
} finally {
|
|
1738
|
+
client.close()
|
|
1739
|
+
}
|
|
1740
|
+
})
|
|
1741
|
+
.catch(() => undefined)
|
|
1344
1742
|
return true
|
|
1345
1743
|
}
|
|
1346
1744
|
|
|
@@ -1348,17 +1746,31 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1348
1746
|
|
|
1349
1747
|
function peersForJoiner(): z.infer<typeof PeerEntrySchema>[] {
|
|
1350
1748
|
const out: z.infer<typeof PeerEntrySchema>[] = [
|
|
1351
|
-
{
|
|
1749
|
+
{
|
|
1750
|
+
machineId: selfId(),
|
|
1751
|
+
name: selfName(),
|
|
1752
|
+
addresses: ourHostPorts().slice(0, 8),
|
|
1753
|
+
},
|
|
1352
1754
|
]
|
|
1353
1755
|
for (const [id, p] of peerState) {
|
|
1354
1756
|
if (isMember(id) && id !== selfId())
|
|
1355
|
-
out.push({
|
|
1757
|
+
out.push({
|
|
1758
|
+
machineId: id,
|
|
1759
|
+
name: p.name,
|
|
1760
|
+
addresses: p.addresses.slice(0, 4),
|
|
1761
|
+
})
|
|
1356
1762
|
}
|
|
1357
1763
|
return out.slice(0, MAX_MEMBERS)
|
|
1358
1764
|
}
|
|
1359
1765
|
|
|
1360
1766
|
function admittedFrame() {
|
|
1361
|
-
return {
|
|
1767
|
+
return {
|
|
1768
|
+
status: 'admitted',
|
|
1769
|
+
netId,
|
|
1770
|
+
admissions: adm,
|
|
1771
|
+
revocations: rev,
|
|
1772
|
+
peers: peersForJoiner(),
|
|
1773
|
+
}
|
|
1362
1774
|
}
|
|
1363
1775
|
|
|
1364
1776
|
function buildSelfRoster(): Roster {
|
|
@@ -1399,6 +1811,12 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1399
1811
|
: { ok: true }
|
|
1400
1812
|
case 'join_request':
|
|
1401
1813
|
return handleJoinRequest(request, ctx)
|
|
1814
|
+
case 'join_cancel': {
|
|
1815
|
+
// Only the machine that asked can withdraw its own request, and only the one it asked here.
|
|
1816
|
+
const waiting = joiners.findByJoiner(peerId)
|
|
1817
|
+
if (waiting?.local) retireJoin(waiting)
|
|
1818
|
+
return { ok: true }
|
|
1819
|
+
}
|
|
1402
1820
|
case 'hello': {
|
|
1403
1821
|
const p = peerState.get(peerId) ?? {
|
|
1404
1822
|
name: request.machineName,
|
|
@@ -1411,13 +1829,26 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1411
1829
|
peerState.set(peerId, p)
|
|
1412
1830
|
for (const a of request.addresses) remember(peerId, a)
|
|
1413
1831
|
void persistPeers()
|
|
1414
|
-
return {
|
|
1832
|
+
return {
|
|
1833
|
+
machineName: selfName(),
|
|
1834
|
+
addresses: ourHostPorts().slice(0, 8),
|
|
1835
|
+
}
|
|
1415
1836
|
}
|
|
1416
1837
|
case 'members_sync': {
|
|
1417
1838
|
await mergeIn(request.admissions, request.revocations)
|
|
1418
1839
|
return { admissions: adm, revocations: rev }
|
|
1419
1840
|
}
|
|
1420
1841
|
case 'join_pending': {
|
|
1842
|
+
// The same machine asking through another member replaces what was waiting from it.
|
|
1843
|
+
const earlier = joiners.findByJoiner(machineIdOf(Buffer.from(request.publicKey, 'base64')))
|
|
1844
|
+
if (earlier && !earlier.local && earlier.requestId !== request.requestId) {
|
|
1845
|
+
joiners.settle(earlier.requestId, 'deny')
|
|
1846
|
+
emit({
|
|
1847
|
+
type: 'join-settled',
|
|
1848
|
+
requestId: earlier.requestId,
|
|
1849
|
+
result: 'deny',
|
|
1850
|
+
})
|
|
1851
|
+
}
|
|
1421
1852
|
const created = joiners.addRemote({
|
|
1422
1853
|
requestId: request.requestId,
|
|
1423
1854
|
name: sanitizeName(request.name),
|
|
@@ -1452,38 +1883,75 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1452
1883
|
const joinerKey = Buffer.from(request.publicKey, 'base64')
|
|
1453
1884
|
const joinerId = machineIdOf(joinerKey)
|
|
1454
1885
|
if (joinerId !== ctx.peer.machineId)
|
|
1455
|
-
return {
|
|
1886
|
+
return {
|
|
1887
|
+
status: 'refused',
|
|
1888
|
+
reason: 'The key does not match the connection.',
|
|
1889
|
+
}
|
|
1456
1890
|
if (view.members.has(joinerId)) return { ...admittedFrame() }
|
|
1457
1891
|
if (view.removed.has(joinerId))
|
|
1458
|
-
return {
|
|
1459
|
-
|
|
1892
|
+
return {
|
|
1893
|
+
status: 'refused',
|
|
1894
|
+
reason: 'This machine was removed from the network.',
|
|
1895
|
+
}
|
|
1896
|
+
// A machine has one request waiting, however many times it asks: the same ask again (same nonce,
|
|
1897
|
+
// as when another terminal of that machine takes over) keeps the request and its code and only
|
|
1898
|
+
// takes over the held connection; a different ask replaces the old one.
|
|
1899
|
+
const prior = joiners.findByJoiner(joinerId)
|
|
1900
|
+
const known = prior ? askNonces.get(prior.requestId) : undefined
|
|
1901
|
+
if (prior?.local && known && known.joinerNonce === request.nonce) {
|
|
1902
|
+
const old = pendingConns.get(prior.requestId)
|
|
1903
|
+
pendingConns.set(prior.requestId, ctx)
|
|
1904
|
+
ctx.holdOpen()
|
|
1905
|
+
watchHeld(prior.requestId, ctx)
|
|
1906
|
+
ctx.write({ status: 'pending', nonce: known.memberNonce, netId })
|
|
1907
|
+
old?.close()
|
|
1908
|
+
return undefined
|
|
1909
|
+
}
|
|
1910
|
+
// A different ask is a new request and meets the same one-a-minute limit as any address; check
|
|
1911
|
+
// before the old one is retired, so a refused ask leaves it standing.
|
|
1912
|
+
// The proof is the only evidence of the same computer: no address, name or hint is read.
|
|
1913
|
+
const same = await provesSameComputer(request, joinerId, ctx.sourceAddress).catch(() => false)
|
|
1914
|
+
if (!same && joiners.tooSoon(ctx.sourceAddress))
|
|
1915
|
+
return { status: 'refused', reason: 'Asked again too soon.' }
|
|
1916
|
+
if (prior) retireJoin(prior)
|
|
1917
|
+
const auto:
|
|
1918
|
+
| {
|
|
1919
|
+
mode: 'trusted-network' | 'always' | 'same-computer'
|
|
1920
|
+
network?: string
|
|
1921
|
+
}
|
|
1922
|
+
| undefined = same
|
|
1923
|
+
? { mode: 'same-computer' }
|
|
1924
|
+
: await autoAdmitMode(ctx.sourceAddress).catch(() => undefined)
|
|
1460
1925
|
const nonceM = randomBytes(16).toString('base64')
|
|
1461
1926
|
const code = joinCode(joinerId, selfId(), request.nonce, nonceM)
|
|
1462
1927
|
const requestId = randomUUID()
|
|
1463
|
-
const added = joiners.addLocal(
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1928
|
+
const added = joiners.addLocal(
|
|
1929
|
+
{
|
|
1930
|
+
requestId,
|
|
1931
|
+
name: sanitizeName(request.machineName),
|
|
1932
|
+
code,
|
|
1933
|
+
sourceAddr: ctx.sourceAddress,
|
|
1934
|
+
viaMachineId: selfId(),
|
|
1935
|
+
joinerMachineId: joinerId,
|
|
1936
|
+
joinerPublicKey: request.publicKey,
|
|
1937
|
+
},
|
|
1938
|
+
same,
|
|
1939
|
+
)
|
|
1472
1940
|
if (!added.ok)
|
|
1473
1941
|
return {
|
|
1474
1942
|
status: 'refused',
|
|
1475
1943
|
reason:
|
|
1476
1944
|
added.reason === 'rate' ? 'Asked again too soon.' : 'Too many requests are waiting.',
|
|
1477
1945
|
}
|
|
1946
|
+
askNonces.set(requestId, {
|
|
1947
|
+
joinerNonce: request.nonce,
|
|
1948
|
+
memberNonce: nonceM,
|
|
1949
|
+
})
|
|
1950
|
+
if (askNonces.size > 64)
|
|
1951
|
+
for (const id of askNonces.keys()) if (!joiners.get(id)) askNonces.delete(id)
|
|
1478
1952
|
ctx.holdOpen()
|
|
1479
1953
|
pendingConns.set(requestId, ctx)
|
|
1480
|
-
ctx
|
|
1481
|
-
pendingConns.delete(requestId)
|
|
1482
|
-
if (joiners.get(requestId)) {
|
|
1483
|
-
joiners.settle(requestId, 'deny')
|
|
1484
|
-
emit({ type: 'join-settled', requestId, result: 'deny' })
|
|
1485
|
-
}
|
|
1486
|
-
})
|
|
1954
|
+
watchHeld(requestId, ctx)
|
|
1487
1955
|
// The joiner must read `pending` before any decision can reach it, so write it first.
|
|
1488
1956
|
ctx.write({ status: 'pending', nonce: nonceM, netId })
|
|
1489
1957
|
logAudit({
|
|
@@ -1492,6 +1960,7 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1492
1960
|
})
|
|
1493
1961
|
if (auto) {
|
|
1494
1962
|
try {
|
|
1963
|
+
if (auto.mode === 'same-computer') proven.add(requestId)
|
|
1495
1964
|
// Admitted without asking: nobody is shown a request, so the other members are not told of one.
|
|
1496
1965
|
emit({
|
|
1497
1966
|
type: 'join-auto',
|
|
@@ -1505,12 +1974,15 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1505
1974
|
await decideJoin(
|
|
1506
1975
|
requestId,
|
|
1507
1976
|
'allow',
|
|
1508
|
-
auto.mode === '
|
|
1509
|
-
? 'automatically (
|
|
1510
|
-
:
|
|
1977
|
+
auto.mode === 'same-computer'
|
|
1978
|
+
? 'automatically (same computer)'
|
|
1979
|
+
: auto.mode === 'always'
|
|
1980
|
+
? 'automatically (network.autoAdmit is always)'
|
|
1981
|
+
: `automatically (trusted network ${auto.network})`,
|
|
1511
1982
|
)
|
|
1512
1983
|
return undefined
|
|
1513
1984
|
} catch {
|
|
1985
|
+
proven.delete(requestId)
|
|
1514
1986
|
// fall through: the request waits for a person like any other
|
|
1515
1987
|
}
|
|
1516
1988
|
}
|
|
@@ -1519,6 +1991,44 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1519
1991
|
return undefined
|
|
1520
1992
|
}
|
|
1521
1993
|
|
|
1994
|
+
/**
|
|
1995
|
+
* A waiting request outlives its connection: the terminal of the joining machine that asked may close
|
|
1996
|
+
* (another one of the same machine asks again and finds the same request and code), and an Allow given
|
|
1997
|
+
* meanwhile still lets the machine in. It ends by an answer, by the joiner's `join_cancel`, by a
|
|
1998
|
+
* newer request from the same machine, or by its ten minutes.
|
|
1999
|
+
*/
|
|
2000
|
+
function watchHeld(requestId: string, ctx: ServerContext): void {
|
|
2001
|
+
orphanTimers.get(requestId)?.()
|
|
2002
|
+
orphanTimers.delete(requestId)
|
|
2003
|
+
ctx.onClose(() => {
|
|
2004
|
+
if (pendingConns.get(requestId) !== ctx) return
|
|
2005
|
+
pendingConns.delete(requestId)
|
|
2006
|
+
// Long enough for another terminal of the machine to take over; a stranger that asks and leaves
|
|
2007
|
+
// does not keep a slot for ten minutes.
|
|
2008
|
+
orphanTimers.set(
|
|
2009
|
+
requestId,
|
|
2010
|
+
clock.setTimer(() => {
|
|
2011
|
+
orphanTimers.delete(requestId)
|
|
2012
|
+
const entry = joiners.get(requestId)
|
|
2013
|
+
if (entry?.local && !pendingConns.has(requestId)) retireJoin(entry)
|
|
2014
|
+
}, JOIN_ORPHAN_MS),
|
|
2015
|
+
)
|
|
2016
|
+
})
|
|
2017
|
+
}
|
|
2018
|
+
|
|
2019
|
+
/** A request that a newer one from the same machine replaced: gone from every screen, nobody told it no. */
|
|
2020
|
+
function retireJoin(entry: PendingJoin): void {
|
|
2021
|
+
orphanTimers.get(entry.requestId)?.()
|
|
2022
|
+
orphanTimers.delete(entry.requestId)
|
|
2023
|
+
const conn = pendingConns.get(entry.requestId)
|
|
2024
|
+
pendingConns.delete(entry.requestId)
|
|
2025
|
+
askNonces.delete(entry.requestId)
|
|
2026
|
+
joiners.settle(entry.requestId, 'deny')
|
|
2027
|
+
emit({ type: 'join-settled', requestId: entry.requestId, result: 'deny' })
|
|
2028
|
+
conn?.close()
|
|
2029
|
+
if (entry.local) void gossipDecision(entry.requestId, 'deny', undefined, selfId())
|
|
2030
|
+
}
|
|
2031
|
+
|
|
1522
2032
|
async function gossipPending(entry: PendingJoin, publicKey: string): Promise<void> {
|
|
1523
2033
|
const frame = {
|
|
1524
2034
|
protocol: NET_PROTOCOL,
|
|
@@ -1541,7 +2051,11 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1541
2051
|
/** The name a joiner gave itself, so the members that let it in show it before its own greeting arrives. */
|
|
1542
2052
|
function rememberJoinerName(machineId: string, name: string): void {
|
|
1543
2053
|
if (peerState.has(machineId)) return
|
|
1544
|
-
peerState.set(machineId, {
|
|
2054
|
+
peerState.set(machineId, {
|
|
2055
|
+
name: sanitizeName(name),
|
|
2056
|
+
addresses: [],
|
|
2057
|
+
online: false,
|
|
2058
|
+
})
|
|
1545
2059
|
}
|
|
1546
2060
|
|
|
1547
2061
|
async function handleJoinDecision(
|
|
@@ -1561,7 +2075,11 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1561
2075
|
rememberJoinerName(request.admission.machineId, entry.name)
|
|
1562
2076
|
await mergeIn([request.admission], [])
|
|
1563
2077
|
}
|
|
1564
|
-
emit({
|
|
2078
|
+
emit({
|
|
2079
|
+
type: 'join-settled',
|
|
2080
|
+
requestId: request.requestId,
|
|
2081
|
+
result: request.decision,
|
|
2082
|
+
})
|
|
1565
2083
|
return { ok: true }
|
|
1566
2084
|
}
|
|
1567
2085
|
if (joiners.decide(request.requestId, request.decision) !== 'ok')
|
|
@@ -1571,34 +2089,69 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1571
2089
|
if (request.decision === 'allow') {
|
|
1572
2090
|
const a = request.admission
|
|
1573
2091
|
if (!a || a.machineId !== entry.joinerMachineId || a.admittedBy !== from) {
|
|
1574
|
-
conn?.write({
|
|
2092
|
+
conn?.write({
|
|
2093
|
+
status: 'refused',
|
|
2094
|
+
reason: 'The admission did not match the request.',
|
|
2095
|
+
})
|
|
1575
2096
|
conn?.close()
|
|
1576
2097
|
return { ok: false }
|
|
1577
2098
|
}
|
|
1578
2099
|
rememberJoinerName(a.machineId, entry.name)
|
|
1579
2100
|
await mergeIn([a], [])
|
|
1580
2101
|
if (!isMember(a.machineId)) {
|
|
1581
|
-
conn?.write({
|
|
2102
|
+
conn?.write({
|
|
2103
|
+
status: 'refused',
|
|
2104
|
+
reason: 'The admission did not check out.',
|
|
2105
|
+
})
|
|
1582
2106
|
conn?.close()
|
|
1583
2107
|
return { ok: false }
|
|
1584
2108
|
}
|
|
1585
|
-
|
|
2109
|
+
const memberSecret = proven.has(request.requestId) ? await computerSecret() : undefined
|
|
2110
|
+
const asked = askNonces.get(request.requestId)
|
|
2111
|
+
if (memberSecret) await rememberSameComputer(a.machineId, memberSecret)
|
|
2112
|
+
conn?.write(
|
|
2113
|
+
memberSecret && asked
|
|
2114
|
+
? {
|
|
2115
|
+
...admittedFrame(),
|
|
2116
|
+
sameComputer: true as const,
|
|
2117
|
+
computerMemberProof: computerMemberProof(
|
|
2118
|
+
memberSecret,
|
|
2119
|
+
selfId(),
|
|
2120
|
+
a.machineId,
|
|
2121
|
+
asked.joinerNonce,
|
|
2122
|
+
asked.memberNonce,
|
|
2123
|
+
),
|
|
2124
|
+
}
|
|
2125
|
+
: admittedFrame(),
|
|
2126
|
+
)
|
|
2127
|
+
proven.delete(request.requestId)
|
|
1586
2128
|
logAudit({
|
|
1587
2129
|
event: 'join_allowed',
|
|
1588
2130
|
machine: { id12: shortMachineId(a.machineId), name: entry.name },
|
|
1589
2131
|
decision: note ?? `by ${shortMachineId(from)}`,
|
|
1590
2132
|
})
|
|
1591
|
-
emit({
|
|
2133
|
+
emit({
|
|
2134
|
+
type: 'join-settled',
|
|
2135
|
+
requestId: request.requestId,
|
|
2136
|
+
result: 'allow',
|
|
2137
|
+
})
|
|
1592
2138
|
void pushSync()
|
|
1593
2139
|
void gossipDecision(request.requestId, 'allow', a, from)
|
|
1594
2140
|
} else {
|
|
1595
2141
|
conn?.write({ status: 'denied' })
|
|
1596
2142
|
logAudit({
|
|
1597
2143
|
event: 'join_denied',
|
|
1598
|
-
machine: {
|
|
2144
|
+
machine: {
|
|
2145
|
+
id12: shortMachineId(entry.joinerMachineId ?? ''),
|
|
2146
|
+
name: entry.name,
|
|
2147
|
+
},
|
|
1599
2148
|
decision: `by ${shortMachineId(from)}`,
|
|
1600
2149
|
})
|
|
1601
|
-
emit({
|
|
2150
|
+
emit({
|
|
2151
|
+
type: 'join-settled',
|
|
2152
|
+
requestId: request.requestId,
|
|
2153
|
+
result: 'deny',
|
|
2154
|
+
})
|
|
1602
2155
|
void gossipDecision(request.requestId, 'deny', undefined, from)
|
|
1603
2156
|
}
|
|
1604
2157
|
conn?.close()
|
|
@@ -1682,7 +2235,11 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1682
2235
|
joiners.settle(entry.requestId, decision)
|
|
1683
2236
|
if (reply?.ok === false)
|
|
1684
2237
|
throw new NetworkError('refused', 'That request was already decided on another machine.')
|
|
1685
|
-
emit({
|
|
2238
|
+
emit({
|
|
2239
|
+
type: 'join-settled',
|
|
2240
|
+
requestId: entry.requestId,
|
|
2241
|
+
result: decision,
|
|
2242
|
+
})
|
|
1686
2243
|
return entry
|
|
1687
2244
|
}
|
|
1688
2245
|
|
|
@@ -1703,15 +2260,27 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1703
2260
|
|
|
1704
2261
|
async function handleRoleSet(request: RoleSetRequest, from: string): Promise<unknown> {
|
|
1705
2262
|
if (!roleBuckets.take(from))
|
|
1706
|
-
return {
|
|
2263
|
+
return {
|
|
2264
|
+
status: 'refused',
|
|
2265
|
+
reason: 'Too many role changes from that machine.',
|
|
2266
|
+
}
|
|
1707
2267
|
const role = request.role === null ? null : (sanitizeRole(request.role) ?? null)
|
|
1708
2268
|
const byName = peerState.get(from)?.name ?? sanitizeName(request.by.machineName)
|
|
1709
2269
|
if ('machine' in request.target) {
|
|
1710
2270
|
if (!machine) return { status: 'refused', reason: 'No machine.' }
|
|
1711
|
-
machine = {
|
|
2271
|
+
machine = {
|
|
2272
|
+
...machine,
|
|
2273
|
+
...(role === null ? { role: undefined } : { role }),
|
|
2274
|
+
}
|
|
1712
2275
|
await store.writeMachine(machine)
|
|
1713
2276
|
logAudit({ event: 'role_set', ...roleAudit(from, 'machine', role) })
|
|
1714
|
-
emit({
|
|
2277
|
+
emit({
|
|
2278
|
+
type: 'role',
|
|
2279
|
+
target: 'machine',
|
|
2280
|
+
role,
|
|
2281
|
+
byMachine: byName,
|
|
2282
|
+
at: request.at,
|
|
2283
|
+
})
|
|
1715
2284
|
return { status: 'applied' }
|
|
1716
2285
|
}
|
|
1717
2286
|
const ref = request.target.sessionRef
|
|
@@ -1731,7 +2300,13 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1731
2300
|
const ok = host.setLocalRole(ref, role, { by: byName, at: request.at })
|
|
1732
2301
|
if (!ok) return { status: 'refused', reason: 'That session is not running here.' }
|
|
1733
2302
|
logAudit({ event: 'role_set', ...roleAudit(from, ref, role) })
|
|
1734
|
-
emit({
|
|
2303
|
+
emit({
|
|
2304
|
+
type: 'role',
|
|
2305
|
+
target: ref,
|
|
2306
|
+
role,
|
|
2307
|
+
byMachine: byName,
|
|
2308
|
+
at: request.at,
|
|
2309
|
+
})
|
|
1735
2310
|
return { status: 'applied' }
|
|
1736
2311
|
}
|
|
1737
2312
|
|
|
@@ -1789,7 +2364,10 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
1789
2364
|
if (stale) {
|
|
1790
2365
|
try {
|
|
1791
2366
|
const roster = RosterSchema.safeParse(
|
|
1792
|
-
await callMachine(machineId, {
|
|
2367
|
+
await callMachine(machineId, {
|
|
2368
|
+
protocol: NET_PROTOCOL,
|
|
2369
|
+
op: 'roster',
|
|
2370
|
+
}),
|
|
1793
2371
|
)
|
|
1794
2372
|
if (roster.success) applyRoster(machineId, roster.data)
|
|
1795
2373
|
} catch {
|
|
@@ -2089,6 +2667,9 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
2089
2667
|
}
|
|
2090
2668
|
const now = clock.now()
|
|
2091
2669
|
const own = buildSelfRoster()
|
|
2670
|
+
// A live fact: remembered machines count only while this home can still read the secret.
|
|
2671
|
+
const rosterSecret = await computerSecret()
|
|
2672
|
+
const sameSet = rosterSecret ? await sameComputerSet(rosterSecret) : new Set<string>()
|
|
2092
2673
|
const machines: RosterMachineView[] = [
|
|
2093
2674
|
{
|
|
2094
2675
|
machineId: selfId(),
|
|
@@ -2110,6 +2691,7 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
2110
2691
|
status: online || (opts.refresh === false && p?.online === true) ? 'online' : 'offline',
|
|
2111
2692
|
seenAt: p?.seenAt,
|
|
2112
2693
|
role: p?.role,
|
|
2694
|
+
...(sameSet.has(id) ? { sameComputer: true } : {}),
|
|
2113
2695
|
sessions: p?.sessions
|
|
2114
2696
|
? online
|
|
2115
2697
|
? p.sessions
|
|
@@ -2139,6 +2721,10 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
2139
2721
|
)
|
|
2140
2722
|
for (const c of pendingConns.values()) c.close()
|
|
2141
2723
|
pendingConns.clear()
|
|
2724
|
+
for (const cancel of orphanTimers.values()) cancel()
|
|
2725
|
+
orphanTimers.clear()
|
|
2726
|
+
// A terminal that stops lets go of its waiting ask without withdrawing it, as when its process ends.
|
|
2727
|
+
joinClient?.close()
|
|
2142
2728
|
await discovery.close().catch(() => undefined)
|
|
2143
2729
|
await Promise.all(netListeners.splice(0).map((l) => l.close()))
|
|
2144
2730
|
}
|
|
@@ -2161,7 +2747,11 @@ export function createNamzuNetwork(options: NetworkServiceOptions): NetworkServi
|
|
|
2161
2747
|
reason: stateReason,
|
|
2162
2748
|
machine:
|
|
2163
2749
|
machine && key
|
|
2164
|
-
? {
|
|
2750
|
+
? {
|
|
2751
|
+
id: key.machineId,
|
|
2752
|
+
name: machine.name ?? selfName(),
|
|
2753
|
+
role: machine.role,
|
|
2754
|
+
}
|
|
2165
2755
|
: undefined,
|
|
2166
2756
|
netId,
|
|
2167
2757
|
members: view?.members.size ?? 0,
|