@adhdev/daemon-core 0.9.82-rc.39 → 0.9.82-rc.390
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/dist/boot/daemon-lifecycle.d.ts +9 -0
- package/dist/boot/process-hardening.d.ts +50 -0
- package/dist/build-info.d.ts +37 -0
- package/dist/chat/source-machine.d.ts +166 -0
- package/dist/chat/source-resolver.d.ts +104 -0
- package/dist/chat/subscription-updates.d.ts +1 -0
- package/dist/cli-adapter-types.d.ts +67 -2
- package/dist/cli-adapters/cli-script-runner.d.ts +117 -0
- package/dist/cli-adapters/cli-state-engine.d.ts +198 -0
- package/dist/cli-adapters/provider-cli-adapter.d.ts +121 -64
- package/dist/cli-adapters/provider-cli-parse.d.ts +4 -0
- package/dist/cli-adapters/provider-cli-runtime.d.ts +34 -0
- package/dist/cli-adapters/provider-cli-shared.d.ts +74 -0
- package/dist/cli-adapters/pty-write-chunking.d.ts +34 -0
- package/dist/cli-adapters/raw-terminal-io.d.ts +37 -0
- package/dist/cli-adapters/resolve-executable.d.ts +14 -0
- package/dist/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +6 -3
- package/dist/cli-adapters/terminal-backends/types.d.ts +10 -2
- package/dist/cli-adapters/terminal-screen.d.ts +4 -11
- package/dist/commands/chat-commands-debug-bundle.d.ts +14 -0
- package/dist/commands/chat-commands-read.d.ts +7 -0
- package/dist/commands/chat-commands-scope.d.ts +39 -0
- package/dist/commands/chat-commands-shared.d.ts +33 -0
- package/dist/commands/chat-commands-write.d.ts +14 -0
- package/dist/commands/chat-commands.d.ts +10 -23
- package/dist/commands/cli-manager.d.ts +15 -1
- package/dist/commands/handler.d.ts +125 -0
- package/dist/commands/high-family/index.d.ts +3 -0
- package/dist/commands/high-family/mesh-coordinator-launch.d.ts +2 -0
- package/dist/commands/high-family/mesh-events.d.ts +2 -0
- package/dist/commands/high-family/mesh-status.d.ts +2 -0
- package/dist/commands/high-family/types.d.ts +60 -0
- package/dist/commands/low-family/coordinator-prompt.d.ts +9 -0
- package/dist/commands/low-family/daemon-lifecycle.d.ts +2 -0
- package/dist/commands/low-family/diagnostics.d.ts +2 -0
- package/dist/commands/low-family/index.d.ts +3 -0
- package/dist/commands/low-family/mesh-ledger.d.ts +10 -0
- package/dist/commands/low-family/mesh-node-logs.d.ts +2 -0
- package/dist/commands/low-family/notification.d.ts +2 -0
- package/dist/commands/low-family/refine-config.d.ts +2 -0
- package/dist/commands/low-family/session-host.d.ts +2 -0
- package/dist/commands/low-family/spec-providerdev.d.ts +11 -0
- package/dist/commands/low-family/status-meta.d.ts +2 -0
- package/dist/commands/low-family/types.d.ts +33 -0
- package/dist/commands/med-family/cli-agent.d.ts +2 -0
- package/dist/commands/med-family/fast-forward.d.ts +2 -0
- package/dist/commands/med-family/ide.d.ts +10 -0
- package/dist/commands/med-family/index.d.ts +3 -0
- package/dist/commands/med-family/mesh-crud.d.ts +2 -0
- package/dist/commands/med-family/mesh-host-pairing.d.ts +2 -0
- package/dist/commands/med-family/mesh-queue.d.ts +2 -0
- package/dist/commands/med-family/mesh-restart.d.ts +2 -0
- package/dist/commands/med-family/types.d.ts +116 -0
- package/dist/commands/mesh-coordinator.d.ts +85 -1
- package/dist/commands/router.d.ts +237 -2
- package/dist/commands/upgrade-helper.d.ts +41 -1
- package/dist/config/chat-history.d.ts +9 -0
- package/dist/config/config.d.ts +5 -0
- package/dist/config/mesh-config.d.ts +77 -1
- package/dist/daemon/dev-server.d.ts +0 -2
- package/dist/detection/ide-detector.d.ts +13 -0
- package/dist/detection/win32-ide-version.d.ts +37 -0
- package/dist/git/change-impact-config.d.ts +159 -0
- package/dist/git/git-commands.d.ts +11 -1
- package/dist/git/git-diff.d.ts +6 -0
- package/dist/git/git-executor.d.ts +11 -0
- package/dist/git/git-status.d.ts +23 -0
- package/dist/git/git-types.d.ts +2 -50
- package/dist/git/git-worktree.d.ts +22 -0
- package/dist/git/index.d.ts +2 -0
- package/dist/index.d.ts +57 -13
- package/dist/index.js +46306 -18259
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +46439 -18533
- package/dist/index.mjs.map +1 -1
- package/dist/installer.d.ts +1 -4
- package/dist/ipc/local-ipc-server.d.ts +91 -0
- package/dist/launch.d.ts +1 -1
- package/dist/logging/async-batch-writer.d.ts +10 -0
- package/dist/logging/log-redactor.d.ts +24 -0
- package/dist/logging/log-tail-reader.d.ts +81 -0
- package/dist/logging/logger.d.ts +1 -1
- package/dist/mesh/contracts.d.ts +164 -0
- package/dist/mesh/coordinator-prompt.d.ts +89 -0
- package/dist/mesh/coordinator-registry.d.ts +59 -0
- package/dist/mesh/mesh-active-work.d.ts +174 -0
- package/dist/mesh/mesh-coordinator-config.d.ts +21 -0
- package/dist/mesh/mesh-delivery-policy.d.ts +131 -0
- package/dist/mesh/mesh-event-classify.d.ts +5 -0
- package/dist/mesh/mesh-event-forwarding.d.ts +19 -0
- package/dist/mesh/mesh-event-trace.d.ts +21 -0
- package/dist/mesh/mesh-events-coordinator.d.ts +4 -0
- package/dist/mesh/mesh-events-pending.d.ts +55 -0
- package/dist/mesh/mesh-events-stale.d.ts +52 -0
- package/dist/mesh/mesh-events-utils.d.ts +64 -0
- package/dist/mesh/mesh-events.d.ts +6 -49
- package/dist/mesh/mesh-fast-forward.d.ts +81 -0
- package/dist/mesh/mesh-host-ownership.d.ts +9 -0
- package/dist/mesh/mesh-init.d.ts +86 -0
- package/dist/mesh/mesh-ledger-reconciliation.d.ts +23 -4
- package/dist/mesh/mesh-ledger.d.ts +77 -1
- package/dist/mesh/mesh-missions.d.ts +164 -0
- package/dist/mesh/mesh-node-identity.d.ts +289 -0
- package/dist/mesh/mesh-queue-assignment.d.ts +86 -0
- package/dist/mesh/mesh-reconcile-loop.d.ts +65 -0
- package/dist/mesh/mesh-refine-batch.d.ts +68 -0
- package/dist/mesh/mesh-refine-gates.d.ts +428 -0
- package/dist/mesh/mesh-refine-status.d.ts +62 -0
- package/dist/mesh/mesh-review-inbox.d.ts +90 -0
- package/dist/mesh/mesh-routing.d.ts +70 -0
- package/dist/mesh/mesh-runtime-store.d.ts +447 -0
- package/dist/mesh/mesh-scheduling-runtime.d.ts +78 -0
- package/dist/mesh/mesh-task-stats.d.ts +49 -0
- package/dist/mesh/mesh-unresolved-forward-outbox.d.ts +30 -0
- package/dist/mesh/mesh-warmup-deadline.d.ts +68 -0
- package/dist/mesh/mesh-work-queue.d.ts +247 -5
- package/dist/mesh/preview-freshness.d.ts +18 -0
- package/dist/mesh/refine-config.d.ts +216 -0
- package/dist/mesh/worktree-bootstrap-config.d.ts +135 -0
- package/dist/providers/acp-provider-instance.d.ts +5 -0
- package/dist/providers/approval-utils.d.ts +20 -0
- package/dist/providers/chat-message-normalization.d.ts +13 -1
- package/dist/providers/cli-provider-instance.d.ts +157 -3
- package/dist/providers/contracts.d.ts +139 -6
- package/dist/providers/external-sources.d.ts +71 -0
- package/dist/providers/manual-attendance.d.ts +63 -0
- package/dist/providers/native-history/antigravity-cli-transcript.d.ts +100 -0
- package/dist/providers/native-history/claude-cli-transcript.d.ts +70 -0
- package/dist/providers/native-history/codex-cli-transcript.d.ts +73 -0
- package/dist/providers/native-history/constants.d.ts +12 -0
- package/dist/providers/native-history/dispatcher.d.ts +27 -0
- package/dist/providers/native-history/hermes-cli-transcript.d.ts +30 -0
- package/dist/providers/native-history/index.d.ts +13 -0
- package/dist/providers/provider-instance-manager.d.ts +14 -0
- package/dist/providers/provider-instance.d.ts +23 -1
- package/dist/providers/provider-loader.d.ts +26 -4
- package/dist/providers/provider-trust.d.ts +31 -0
- package/dist/providers/read-chat-contract.d.ts +29 -0
- package/dist/providers/sdk/v1/builders/acp/detect-status.d.ts +68 -0
- package/dist/providers/sdk/v1/builders/cli/detect-status.d.ts +86 -0
- package/dist/providers/sdk/v1/builders/cli/parse-approval-squash.d.ts +59 -0
- package/dist/providers/sdk/v1/builders/cli/parse-approval.d.ts +65 -0
- package/dist/providers/sdk/v1/builders/cli/parse-session.d.ts +91 -0
- package/dist/providers/sdk/v1/builders/cli/visible-region.d.ts +42 -0
- package/dist/providers/sdk/v1/fixture-tooling/format.d.ts +126 -0
- package/dist/providers/sdk/v1/fixture-tooling/index.d.ts +8 -0
- package/dist/providers/sdk/v1/fixture-tooling/replay.d.ts +38 -0
- package/dist/providers/sdk/v1/index.d.ts +30 -0
- package/dist/providers/sdk/v1/sandbox/README-design.d.ts +193 -0
- package/dist/providers/sdk/v1/sandbox/require-whitelist.d.ts +74 -0
- package/dist/providers/sdk/v1/sandbox/script-runner.d.ts +98 -0
- package/dist/providers/sdk/v1/types/cli/index.d.ts +277 -0
- package/dist/providers/sdk/v1/types/common/index.d.ts +203 -0
- package/dist/providers/sdk/v1/validators/index.d.ts +5 -0
- package/dist/providers/sdk/v1/validators/manifest.d.ts +40 -0
- package/dist/providers/sdk/v1/validators/taint.d.ts +52 -0
- package/dist/providers/spec/adapter.d.ts +91 -0
- package/dist/providers/spec/cli-adapter.d.ts +223 -0
- package/dist/providers/spec/evaluator.d.ts +45 -0
- package/dist/providers/spec/fsm-driver.d.ts +407 -0
- package/dist/providers/spec/fsm-evaluator.d.ts +76 -0
- package/dist/providers/spec/fsm-loader.d.ts +14 -0
- package/dist/providers/spec/fsm-types.d.ts +174 -0
- package/dist/providers/spec/native-history-executor.d.ts +41 -0
- package/dist/providers/spec/pre-launch-trust.d.ts +16 -0
- package/dist/providers/spec/route.d.ts +4 -0
- package/dist/providers/spec/types.d.ts +222 -0
- package/dist/providers/status-monitor.d.ts +7 -7
- package/dist/providers/transcript-v2.d.ts +176 -0
- package/dist/providers/types/interactive-prompt.d.ts +84 -0
- package/dist/providers/working-dir.d.ts +17 -0
- package/dist/repo-mesh-types.d.ts +376 -13
- package/dist/runtime-defaults.d.ts +2 -0
- package/dist/sessions/registry.d.ts +6 -0
- package/dist/shared-types-extra.d.ts +2 -4
- package/dist/shared-types.d.ts +59 -2
- package/dist/status/normalize.d.ts +1 -1
- package/dist/status/normalize.js +1 -0
- package/dist/status/normalize.js.map +1 -1
- package/dist/status/normalize.mjs +1 -0
- package/dist/status/normalize.mjs.map +1 -1
- package/dist/status/reporter.d.ts +2 -0
- package/dist/status/snapshot.d.ts +26 -0
- package/dist/system/hash.d.ts +8 -0
- package/dist/system/load-better-sqlite3.d.ts +21 -0
- package/dist/types.d.ts +5 -0
- package/package.json +7 -3
- package/src/agent-stream/poller.ts +2 -3
- package/src/agent-stream/provider-adapter.ts +1 -1
- package/src/boot/daemon-lifecycle.ts +63 -12
- package/src/boot/process-hardening.ts +89 -0
- package/src/build-info.ts +73 -0
- package/src/chat/source-machine.ts +534 -0
- package/src/chat/source-resolver.ts +0 -0
- package/src/chat/subscription-updates.ts +20 -1
- package/src/cli-adapter-types.d.ts +1 -0
- package/src/cli-adapter-types.ts +68 -2
- package/src/cli-adapters/cli-script-runner.ts +421 -0
- package/src/cli-adapters/cli-state-engine.ts +1221 -0
- package/src/cli-adapters/provider-cli-adapter.d.ts +1 -1
- package/src/cli-adapters/provider-cli-adapter.ts +836 -1141
- package/src/cli-adapters/provider-cli-parse.d.ts +1 -0
- package/src/cli-adapters/provider-cli-parse.ts +13 -0
- package/src/cli-adapters/provider-cli-runtime.ts +56 -7
- package/src/cli-adapters/provider-cli-shared.d.ts +4 -0
- package/src/cli-adapters/provider-cli-shared.ts +121 -11
- package/src/cli-adapters/pty-transport.ts +2 -1
- package/src/cli-adapters/pty-write-chunking.ts +106 -0
- package/src/cli-adapters/raw-terminal-io.ts +252 -0
- package/src/cli-adapters/resolve-executable.ts +90 -0
- package/src/cli-adapters/session-host-transport.ts +2 -1
- package/src/cli-adapters/terminal-backends/ghostty-vt-backend.ts +53 -29
- package/src/cli-adapters/terminal-backends/types.ts +10 -3
- package/src/cli-adapters/terminal-screen.ts +16 -81
- package/src/commands/WINDOWS-UPGRADE-LOCK-FAILURE.md +198 -0
- package/src/commands/chat-commands-debug-bundle.ts +398 -0
- package/src/commands/chat-commands-read.ts +2327 -0
- package/src/commands/chat-commands-scope.ts +54 -0
- package/src/commands/chat-commands-shared.ts +114 -0
- package/src/commands/chat-commands-write.ts +880 -0
- package/src/commands/chat-commands.ts +19 -1841
- package/src/commands/cli-manager.ts +513 -26
- package/src/commands/handler.ts +841 -2
- package/src/commands/high-family/index.ts +28 -0
- package/src/commands/high-family/mesh-coordinator-launch.ts +657 -0
- package/src/commands/high-family/mesh-events.ts +80 -0
- package/src/commands/high-family/mesh-status.ts +678 -0
- package/src/commands/high-family/types.ts +76 -0
- package/src/commands/low-family/coordinator-prompt.ts +72 -0
- package/src/commands/low-family/daemon-lifecycle.ts +107 -0
- package/src/commands/low-family/diagnostics.ts +57 -0
- package/src/commands/low-family/index.ts +37 -0
- package/src/commands/low-family/mesh-ledger.ts +62 -0
- package/src/commands/low-family/mesh-node-logs.ts +87 -0
- package/src/commands/low-family/notification.ts +116 -0
- package/src/commands/low-family/refine-config.ts +106 -0
- package/src/commands/low-family/session-host.ts +274 -0
- package/src/commands/low-family/spec-providerdev.ts +217 -0
- package/src/commands/low-family/status-meta.ts +112 -0
- package/src/commands/low-family/types.ts +39 -0
- package/src/commands/med-family/cli-agent.ts +230 -0
- package/src/commands/med-family/fast-forward.ts +230 -0
- package/src/commands/med-family/ide.ts +163 -0
- package/src/commands/med-family/index.ts +37 -0
- package/src/commands/med-family/mesh-crud.ts +836 -0
- package/src/commands/med-family/mesh-host-pairing.ts +234 -0
- package/src/commands/med-family/mesh-queue.ts +131 -0
- package/src/commands/med-family/mesh-restart.ts +92 -0
- package/src/commands/med-family/types.ts +120 -0
- package/src/commands/mesh-coordinator.ts +334 -124
- package/src/commands/router.ts +2476 -3207
- package/src/commands/stream-commands.ts +8 -0
- package/src/commands/upgrade-helper.ts +310 -45
- package/src/config/chat-history.ts +483 -24
- package/src/config/config.ts +12 -0
- package/src/config/mesh-config.ts +353 -22
- package/src/config/recent-activity.ts +8 -2
- package/src/daemon/dev-auto-implement.ts +3 -2
- package/src/daemon/dev-cli-debug.ts +10 -1
- package/src/daemon/dev-server.ts +0 -541
- package/src/detection/cli-detector.ts +28 -9
- package/src/detection/ide-detector.ts +55 -16
- package/src/detection/win32-ide-version.ts +106 -0
- package/src/git/change-impact-config.ts +354 -0
- package/src/git/git-commands.ts +55 -14
- package/src/git/git-diff.ts +81 -11
- package/src/git/git-executor.ts +12 -0
- package/src/git/git-status.ts +574 -43
- package/src/git/git-types.ts +14 -62
- package/src/git/git-worktree.ts +76 -1
- package/src/git/index.ts +16 -0
- package/src/index.ts +171 -12
- package/src/installer.d.ts +1 -1
- package/src/installer.ts +8 -6
- package/src/ipc/local-ipc-server.ts +278 -0
- package/src/launch.d.ts +1 -1
- package/src/launch.ts +37 -28
- package/src/logging/async-batch-writer.ts +55 -0
- package/src/logging/command-log.ts +7 -5
- package/src/logging/log-redactor.ts +100 -0
- package/src/logging/log-tail-reader.ts +341 -0
- package/src/logging/logger.ts +14 -7
- package/src/mesh/contracts.ts +338 -0
- package/src/mesh/coordinator-prompt.ts +381 -33
- package/src/mesh/coordinator-registry.ts +121 -0
- package/src/mesh/mesh-active-work.ts +645 -0
- package/src/mesh/mesh-coordinator-config.ts +97 -0
- package/src/mesh/mesh-delivery-policy.ts +315 -0
- package/src/mesh/mesh-event-classify.ts +51 -0
- package/src/mesh/mesh-event-forwarding.ts +1665 -0
- package/src/mesh/mesh-event-trace.ts +67 -0
- package/src/mesh/mesh-events-coordinator.ts +30 -0
- package/src/mesh/mesh-events-pending.ts +590 -0
- package/src/mesh/mesh-events-stale.ts +363 -0
- package/src/mesh/mesh-events-utils.ts +425 -0
- package/src/mesh/mesh-events.ts +32 -1035
- package/src/mesh/mesh-fast-forward.ts +839 -0
- package/src/mesh/mesh-host-ownership.ts +73 -0
- package/src/mesh/mesh-init.ts +260 -0
- package/src/mesh/mesh-ledger-reconciliation.ts +12 -7
- package/src/mesh/mesh-ledger.ts +596 -102
- package/src/mesh/mesh-missions.ts +322 -0
- package/src/mesh/mesh-node-identity.ts +1887 -0
- package/src/mesh/mesh-queue-assignment.ts +1491 -0
- package/src/mesh/mesh-reconcile-loop.ts +1527 -0
- package/src/mesh/mesh-refine-batch.ts +197 -0
- package/src/mesh/mesh-refine-gates.ts +1652 -0
- package/src/mesh/mesh-refine-status.ts +231 -0
- package/src/mesh/mesh-review-inbox.ts +307 -0
- package/src/mesh/mesh-routing.ts +291 -0
- package/src/mesh/mesh-runtime-store.ts +1795 -0
- package/src/mesh/mesh-scheduling-runtime.ts +199 -0
- package/src/mesh/mesh-task-stats.ts +161 -0
- package/src/mesh/mesh-unresolved-forward-outbox.ts +185 -0
- package/src/mesh/mesh-warmup-deadline.ts +152 -0
- package/src/mesh/mesh-work-queue.ts +1141 -141
- package/src/mesh/preview-freshness.ts +118 -0
- package/src/mesh/refine-config.ts +423 -0
- package/src/mesh/worktree-bootstrap-config.ts +331 -0
- package/src/providers/acp-provider-instance.ts +43 -10
- package/src/providers/approval-utils.d.ts +5 -0
- package/src/providers/approval-utils.ts +57 -5
- package/src/providers/chat-message-normalization.ts +46 -6
- package/src/providers/cli-provider-instance.ts +1552 -102
- package/src/providers/contracts.d.ts +55 -0
- package/src/providers/contracts.ts +150 -6
- package/src/providers/extension-provider-instance.ts +12 -7
- package/src/providers/external-sources.ts +218 -0
- package/src/providers/ide-provider-instance.ts +35 -12
- package/src/providers/manual-attendance.ts +85 -0
- package/src/providers/native-history/antigravity-cli-transcript.ts +643 -0
- package/src/providers/native-history/claude-cli-transcript.ts +396 -0
- package/src/providers/native-history/codex-cli-transcript.ts +479 -0
- package/src/providers/native-history/constants.ts +19 -0
- package/src/providers/native-history/dispatcher.ts +339 -0
- package/src/providers/native-history/hermes-cli-transcript.ts +230 -0
- package/src/providers/native-history/index.ts +30 -0
- package/src/providers/provider-instance-manager.ts +30 -0
- package/src/providers/provider-instance.ts +19 -1
- package/src/providers/provider-loader.ts +668 -50
- package/src/providers/provider-schema.ts +87 -14
- package/src/providers/provider-trust.ts +114 -0
- package/src/providers/read-chat-contract.ts +76 -16
- package/src/providers/sdk/README.md +49 -0
- package/src/providers/sdk/v1/builders/acp/detect-status.ts +144 -0
- package/src/providers/sdk/v1/builders/cli/detect-status.ts +313 -0
- package/src/providers/sdk/v1/builders/cli/parse-approval-squash.ts +158 -0
- package/src/providers/sdk/v1/builders/cli/parse-approval.ts +250 -0
- package/src/providers/sdk/v1/builders/cli/parse-session.ts +276 -0
- package/src/providers/sdk/v1/builders/cli/visible-region.ts +143 -0
- package/src/providers/sdk/v1/fixture-tooling/format.ts +130 -0
- package/src/providers/sdk/v1/fixture-tooling/index.ts +22 -0
- package/src/providers/sdk/v1/fixture-tooling/replay.ts +352 -0
- package/src/providers/sdk/v1/index.ts +152 -0
- package/src/providers/sdk/v1/sandbox/README-design.ts +195 -0
- package/src/providers/sdk/v1/sandbox/require-whitelist.ts +472 -0
- package/src/providers/sdk/v1/sandbox/script-runner.ts +150 -0
- package/src/providers/sdk/v1/schemas/cli/provider.schema.json +504 -0
- package/src/providers/sdk/v1/schemas/primitives/acp-session-protocol-v1.json +131 -0
- package/src/providers/sdk/v1/schemas/primitives/native-history-codex-rollout-v1.json +66 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-approval-squash-v1.json +91 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-assistant-block-v1.json +91 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-cue-ordering-v1.json +47 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-dispatch-order-v1.json +32 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-footer-chrome-v1.json +42 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-index-finder-v1.json +27 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-modal-v1.json +125 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-prompt-marker-v1.json +45 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-session-id-extraction-v1.json +46 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-settled-prompt-v1.json +71 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-spinner-v1.json +83 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-transcript-pty-v1.json +83 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-visible-region-v1.json +57 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-welcome-screen-v1.json +35 -0
- package/src/providers/sdk/v1/types/cli/index.ts +365 -0
- package/src/providers/sdk/v1/types/common/index.ts +229 -0
- package/src/providers/sdk/v1/validators/index.ts +19 -0
- package/src/providers/sdk/v1/validators/manifest.ts +110 -0
- package/src/providers/sdk/v1/validators/taint.ts +309 -0
- package/src/providers/spec/adapter.ts +235 -0
- package/src/providers/spec/cli-adapter.ts +1056 -0
- package/src/providers/spec/evaluator.ts +407 -0
- package/src/providers/spec/fsm-driver.ts +1304 -0
- package/src/providers/spec/fsm-evaluator.ts +272 -0
- package/src/providers/spec/fsm-loader.ts +120 -0
- package/src/providers/spec/fsm-types.ts +273 -0
- package/src/providers/spec/native-history-executor.ts +1128 -0
- package/src/providers/spec/pre-launch-trust.ts +104 -0
- package/src/providers/spec/route.ts +51 -0
- package/src/providers/spec/types.ts +262 -0
- package/src/providers/status-monitor.d.ts +7 -7
- package/src/providers/status-monitor.ts +37 -22
- package/src/providers/transcript-v2.ts +567 -0
- package/src/providers/types/interactive-prompt.ts +536 -0
- package/src/providers/version-archive.ts +64 -24
- package/src/providers/working-dir.ts +23 -0
- package/src/repo-mesh-types.ts +542 -14
- package/src/runtime-defaults.ts +39 -0
- package/src/sessions/registry.ts +6 -0
- package/src/shared-types-extra.ts +2 -4
- package/src/shared-types.d.ts +8 -0
- package/src/shared-types.ts +64 -1
- package/src/status/builders.ts +26 -6
- package/src/status/normalize.ts +2 -0
- package/src/status/reporter.ts +19 -1
- package/src/status/snapshot.ts +95 -26
- package/src/system/hash.ts +23 -0
- package/src/system/host-memory.ts +29 -12
- package/src/system/load-better-sqlite3.ts +68 -0
- package/src/types.ts +5 -0
- package/dist/cli-adapters/terminal-backends/xterm-backend.d.ts +0 -17
- package/dist/mesh/mesh-sync.d.ts +0 -53
- package/src/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +0 -16
- package/src/cli-adapters/terminal-backends/xterm-backend.ts +0 -97
- package/src/mesh/mesh-sync.ts +0 -111
|
@@ -0,0 +1,836 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RF-ROUTER MED family — mesh CRUD + node CRUD commands.
|
|
3
|
+
*
|
|
4
|
+
* Mesh records (list/get/create/update/delete_mesh) and node lifecycle
|
|
5
|
+
* (add/update/remove/clone_mesh_node, cleanup_mesh_sessions,
|
|
6
|
+
* retry_mesh_node_bootstrap). get_mesh hydrates direct git truth; the mutating
|
|
7
|
+
* node commands gate on the Mesh Host owner check and bust the aggregate-status
|
|
8
|
+
* cache; clone/remove/retry forward to the owning daemon for remote worktrees.
|
|
9
|
+
* Extracted verbatim from executeDaemonCommand; the inline-cache, session/worktree
|
|
10
|
+
* cleanup and aggregate-status collaborators come from ctx.
|
|
11
|
+
*/
|
|
12
|
+
import { daemonIdsEquivalent, meshNodeIdMatches } from '@adhdev/mesh-shared';
|
|
13
|
+
import { resolveMeshHostStatus, normalizeMeshDaemonRole } from '../../mesh/mesh-host-ownership.js';
|
|
14
|
+
import {
|
|
15
|
+
loadMeshWorktreeBootstrapConfig,
|
|
16
|
+
runMeshWorktreeBootstrap,
|
|
17
|
+
type WorktreeBootstrapState,
|
|
18
|
+
} from '../../mesh/worktree-bootstrap-config.js';
|
|
19
|
+
import { handleMeshForwardEvent, queuePendingMeshCoordinatorEvent } from '../../mesh/mesh-events.js';
|
|
20
|
+
import { loadConfig } from '../../config/config.js';
|
|
21
|
+
import {
|
|
22
|
+
hydrateInlineMeshDirectTruth,
|
|
23
|
+
normalizeProviderRoles,
|
|
24
|
+
readMeshNodeMachineId,
|
|
25
|
+
} from '../router.js';
|
|
26
|
+
import type { CommandRouterResult } from '../router.js';
|
|
27
|
+
import type { MedFamilyContext, MedFamilyHandler } from './types.js';
|
|
28
|
+
|
|
29
|
+
export const meshCrudHandlers: Record<string, MedFamilyHandler> = {
|
|
30
|
+
list_meshes: async (_ctx: MedFamilyContext, _args: any) => {
|
|
31
|
+
try {
|
|
32
|
+
const { listMeshes } = await import('../../config/mesh-config.js');
|
|
33
|
+
return { success: true, meshes: listMeshes() };
|
|
34
|
+
} catch (e: any) {
|
|
35
|
+
return { success: false, error: e.message };
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
get_mesh: async (ctx: MedFamilyContext, args: any) => {
|
|
40
|
+
const meshId = typeof args?.meshId === 'string' ? args.meshId.trim() : '';
|
|
41
|
+
if (!meshId) return { success: false, error: 'meshId required' };
|
|
42
|
+
const meshRecord = await ctx.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
43
|
+
if (!meshRecord?.mesh) return { success: false, error: 'Mesh not found' };
|
|
44
|
+
|
|
45
|
+
const requireDirectPeerTruth = args?.requireDirectPeerTruth === true;
|
|
46
|
+
// Only an explicit refresh fans out a blocking peer probe.
|
|
47
|
+
// Default loads are satisfied from held standing-state git truth.
|
|
48
|
+
const probeRemotePeers = args?.refresh === true || args?.forceRefresh === true;
|
|
49
|
+
const directTruth = await hydrateInlineMeshDirectTruth({
|
|
50
|
+
mesh: meshRecord.mesh,
|
|
51
|
+
meshSource: meshRecord.source,
|
|
52
|
+
dispatchMeshCommand: ctx.deps.dispatchMeshCommand,
|
|
53
|
+
getMeshPeerConnectionStatus: ctx.deps.getMeshPeerConnectionStatus,
|
|
54
|
+
statusInstanceId: ctx.deps.statusInstanceId,
|
|
55
|
+
localMachineId: loadConfig().machineId || '',
|
|
56
|
+
probeRemotePeers,
|
|
57
|
+
probeCache: ctx.meshGitProbeCache,
|
|
58
|
+
});
|
|
59
|
+
const directTruthSatisfied = meshRecord.source !== 'inline_bootstrap' || directTruth.directEvidenceCount > 0;
|
|
60
|
+
const sourceOfTruth = {
|
|
61
|
+
membership: meshRecord.source === 'inline_cache'
|
|
62
|
+
? 'coordinator_inline_mesh_cache'
|
|
63
|
+
: meshRecord.source === 'local_config'
|
|
64
|
+
? 'local_mesh_config'
|
|
65
|
+
: 'inline_bootstrap_snapshot',
|
|
66
|
+
coordinatorOwnsLiveTruth: directTruthSatisfied,
|
|
67
|
+
directPeerTruth: {
|
|
68
|
+
required: requireDirectPeerTruth,
|
|
69
|
+
satisfied: directTruthSatisfied,
|
|
70
|
+
directEvidenceCount: directTruth.directEvidenceCount,
|
|
71
|
+
localConfirmedCount: directTruth.localConfirmedCount,
|
|
72
|
+
peerAttemptedCount: directTruth.peerAttemptedCount,
|
|
73
|
+
peerConfirmedCount: directTruth.peerConfirmedCount,
|
|
74
|
+
unavailableNodeIds: directTruth.unavailableNodeIds,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
if (requireDirectPeerTruth && !directTruthSatisfied) {
|
|
78
|
+
return {
|
|
79
|
+
success: false,
|
|
80
|
+
code: 'mesh_direct_peer_truth_unavailable',
|
|
81
|
+
error: 'Selected coordinator could not confirm direct mesh truth yet. Bootstrap inventory stays unavailable until direct get_mesh probes succeed.',
|
|
82
|
+
sourceOfTruth,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return { success: true, mesh: meshRecord.mesh, sourceOfTruth };
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
create_mesh: async (_ctx: MedFamilyContext, args: any) => {
|
|
89
|
+
const name = typeof args?.name === 'string' ? args.name.trim() : '';
|
|
90
|
+
const repoIdentity = typeof args?.repoIdentity === 'string' ? args.repoIdentity.trim() : '';
|
|
91
|
+
const repoRemoteUrl = typeof args?.repoRemoteUrl === 'string' ? args.repoRemoteUrl.trim() : undefined;
|
|
92
|
+
const defaultBranch = typeof args?.defaultBranch === 'string' ? args.defaultBranch.trim() : undefined;
|
|
93
|
+
if (!name) return { success: false, error: 'name required' };
|
|
94
|
+
try {
|
|
95
|
+
const { createMesh } = await import('../../config/mesh-config.js');
|
|
96
|
+
const meshHost = args?.meshHost && typeof args.meshHost === 'object' && !Array.isArray(args.meshHost)
|
|
97
|
+
? args.meshHost
|
|
98
|
+
: undefined;
|
|
99
|
+
const mesh = createMesh({ name, repoIdentity, repoRemoteUrl, defaultBranch, policy: args?.policy, meshHost });
|
|
100
|
+
return { success: true, mesh };
|
|
101
|
+
} catch (e: any) {
|
|
102
|
+
return { success: false, error: e.message };
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
update_mesh: async (ctx: MedFamilyContext, args: any) => {
|
|
107
|
+
const meshId = typeof args?.meshId === 'string' ? args.meshId.trim() : '';
|
|
108
|
+
if (!meshId) return { success: false, error: 'meshId required' };
|
|
109
|
+
try {
|
|
110
|
+
const { updateMesh } = await import('../../config/mesh-config.js');
|
|
111
|
+
const patch: Record<string, unknown> = {};
|
|
112
|
+
if (typeof args?.name === 'string') patch.name = args.name;
|
|
113
|
+
if (typeof args?.defaultBranch === 'string') patch.defaultBranch = args.defaultBranch;
|
|
114
|
+
if (args?.policy && typeof args.policy === 'object' && !Array.isArray(args.policy)) patch.policy = args.policy;
|
|
115
|
+
if (args?.coordinator && typeof args.coordinator === 'object' && !Array.isArray(args.coordinator)) patch.coordinator = args.coordinator;
|
|
116
|
+
if (args?.meshHost && typeof args.meshHost === 'object' && !Array.isArray(args.meshHost)) patch.meshHost = args.meshHost;
|
|
117
|
+
if (!Object.keys(patch).length) return { success: false, error: 'No updates provided' };
|
|
118
|
+
const mesh = updateMesh(meshId, patch as any);
|
|
119
|
+
if (!mesh) return { success: false, error: 'Mesh not found' };
|
|
120
|
+
ctx.inlineMeshCache.set(meshId, mesh);
|
|
121
|
+
ctx.invalidateAggregateMeshStatus(meshId);
|
|
122
|
+
return { success: true, mesh };
|
|
123
|
+
} catch (e: any) {
|
|
124
|
+
return { success: false, error: e.message };
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
delete_mesh: async (_ctx: MedFamilyContext, args: any) => {
|
|
129
|
+
const meshId = typeof args?.meshId === 'string' ? args.meshId.trim() : '';
|
|
130
|
+
if (!meshId) return { success: false, error: 'meshId required' };
|
|
131
|
+
try {
|
|
132
|
+
const { deleteMesh } = await import('../../config/mesh-config.js');
|
|
133
|
+
const deleted = deleteMesh(meshId);
|
|
134
|
+
return { success: true, deleted };
|
|
135
|
+
} catch (e: any) {
|
|
136
|
+
return { success: false, error: e.message };
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
add_mesh_node: async (ctx: MedFamilyContext, args: any) => {
|
|
141
|
+
const meshId = typeof args?.meshId === 'string' ? args.meshId.trim() : '';
|
|
142
|
+
const workspace = typeof args?.workspace === 'string' ? args.workspace.trim() : '';
|
|
143
|
+
if (!meshId) return { success: false, error: 'meshId required' };
|
|
144
|
+
if (!workspace) return { success: false, error: 'workspace required' };
|
|
145
|
+
const ownerFailure = await ctx.requireMeshHostMutationOwner(meshId, args?.inlineMesh, 'node addition');
|
|
146
|
+
if (ownerFailure) return ownerFailure;
|
|
147
|
+
try {
|
|
148
|
+
const { addNode } = await import('../../config/mesh-config.js');
|
|
149
|
+
const providerPriority = Array.isArray(args?.providerPriority)
|
|
150
|
+
? args.providerPriority.map((type: any) => typeof type === 'string' ? type.trim() : '').filter(Boolean)
|
|
151
|
+
: [];
|
|
152
|
+
const readOnly = args?.readOnly === true;
|
|
153
|
+
const providerRoles = normalizeProviderRoles(args?.providerRoles);
|
|
154
|
+
const policy = {
|
|
155
|
+
...(readOnly ? { readOnly: true } : {}),
|
|
156
|
+
...(providerPriority.length ? { providerPriority } : {}),
|
|
157
|
+
...(providerRoles.length ? { providerRoles } : {}),
|
|
158
|
+
};
|
|
159
|
+
const role = normalizeMeshDaemonRole(args?.role);
|
|
160
|
+
const daemonId = typeof args?.daemonId === 'string' && args.daemonId.trim() ? args.daemonId.trim() : undefined;
|
|
161
|
+
const machineId = typeof args?.machineId === 'string' && args.machineId.trim() ? args.machineId.trim() : undefined;
|
|
162
|
+
const repoRoot = typeof args?.repoRoot === 'string' && args.repoRoot.trim() ? args.repoRoot.trim() : undefined;
|
|
163
|
+
const node = addNode(meshId, {
|
|
164
|
+
workspace,
|
|
165
|
+
...(repoRoot ? { repoRoot } : {}),
|
|
166
|
+
...(daemonId ? { daemonId } : {}),
|
|
167
|
+
...(machineId ? { machineId } : {}),
|
|
168
|
+
...(policy ? { policy } : {}),
|
|
169
|
+
...(role ? { role } : {}),
|
|
170
|
+
});
|
|
171
|
+
if (!node) return { success: false, error: 'Mesh not found' };
|
|
172
|
+
// mesh_status hands back a coordinator-memory aggregate
|
|
173
|
+
// snapshot keyed on (meshId, queueRevision). Adding a
|
|
174
|
+
// node touches neither, so without an explicit cache
|
|
175
|
+
// bust the dashboard graph keeps rendering the pre-add
|
|
176
|
+
// node list (empty for a fresh mesh) even after the
|
|
177
|
+
// user clicks Refresh.
|
|
178
|
+
ctx.invalidateAggregateMeshStatus(meshId);
|
|
179
|
+
return { success: true, node };
|
|
180
|
+
} catch (e: any) {
|
|
181
|
+
return { success: false, error: e.message };
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
|
|
185
|
+
update_mesh_node: async (ctx: MedFamilyContext, args: any) => {
|
|
186
|
+
const meshId = typeof args?.meshId === 'string' ? args.meshId.trim() : '';
|
|
187
|
+
const nodeId = typeof args?.nodeId === 'string' ? args.nodeId.trim() : '';
|
|
188
|
+
if (!meshId || !nodeId) return { success: false, error: 'meshId and nodeId required' };
|
|
189
|
+
const ownerFailure = await ctx.requireMeshHostMutationOwner(meshId, args?.inlineMesh, 'node update');
|
|
190
|
+
if (ownerFailure) return ownerFailure;
|
|
191
|
+
try {
|
|
192
|
+
const { updateNode } = await import('../../config/mesh-config.js');
|
|
193
|
+
const policy = args?.policy && typeof args.policy === 'object' && !Array.isArray(args.policy)
|
|
194
|
+
? { ...(args.policy as Record<string, unknown>) }
|
|
195
|
+
: {};
|
|
196
|
+
if (Array.isArray(args?.providerPriority)) {
|
|
197
|
+
const providerPriority = args.providerPriority
|
|
198
|
+
.map((type: any) => typeof type === 'string' ? type.trim() : '')
|
|
199
|
+
.filter(Boolean);
|
|
200
|
+
delete (policy as any).provider_priority;
|
|
201
|
+
if (providerPriority.length) {
|
|
202
|
+
(policy as any).providerPriority = providerPriority;
|
|
203
|
+
} else {
|
|
204
|
+
delete (policy as any).providerPriority;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// providerRoles: per-(node, provider) role label + maxParallel cap.
|
|
208
|
+
// Passing an explicit (possibly empty) array clears/replaces the
|
|
209
|
+
// declarations; omitting the arg leaves any value already on policy
|
|
210
|
+
// untouched (a full policy object passed by the caller still carries it).
|
|
211
|
+
if (Array.isArray(args?.providerRoles)) {
|
|
212
|
+
const providerRoles = normalizeProviderRoles(args.providerRoles);
|
|
213
|
+
if (providerRoles.length) {
|
|
214
|
+
(policy as any).providerRoles = providerRoles;
|
|
215
|
+
} else {
|
|
216
|
+
delete (policy as any).providerRoles;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const patch: Record<string, unknown> = { policy: policy as any };
|
|
220
|
+
if (typeof args?.systemPrompt === 'string') {
|
|
221
|
+
const trimmed = (args.systemPrompt as string).trim();
|
|
222
|
+
patch.systemPrompt = trimmed || undefined;
|
|
223
|
+
} else if (args?.systemPrompt === null) {
|
|
224
|
+
patch.systemPrompt = undefined;
|
|
225
|
+
}
|
|
226
|
+
const node = updateNode(meshId, nodeId, patch as any);
|
|
227
|
+
if (!node) return { success: false, error: 'Mesh node not found' };
|
|
228
|
+
// Provider priority / systemPrompt changes don't touch
|
|
229
|
+
// the queue revision, so without a manual bust the
|
|
230
|
+
// cached aggregate keeps surfacing pre-update values
|
|
231
|
+
// (priority chip, coordinator prompt preview, etc.).
|
|
232
|
+
ctx.invalidateAggregateMeshStatus(meshId);
|
|
233
|
+
return { success: true, node };
|
|
234
|
+
} catch (e: any) {
|
|
235
|
+
return { success: false, error: e.message };
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
cleanup_mesh_sessions: async (ctx: MedFamilyContext, args: any) => {
|
|
240
|
+
const meshId = typeof args?.meshId === 'string' ? args.meshId.trim() : '';
|
|
241
|
+
const nodeId = typeof args?.nodeId === 'string' ? args.nodeId.trim() : '';
|
|
242
|
+
if (!meshId || !nodeId) return { success: false, error: 'meshId and nodeId required' };
|
|
243
|
+
const ownerFailure = await ctx.requireMeshHostMutationOwner(meshId, args?.inlineMesh, 'node removal');
|
|
244
|
+
if (ownerFailure) return ownerFailure;
|
|
245
|
+
try {
|
|
246
|
+
// preferInline so inline-cache-only clone nodes resolve (matches owner check above).
|
|
247
|
+
const meshRecord = await ctx.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
248
|
+
const mesh = meshRecord?.mesh;
|
|
249
|
+
if (!mesh) return { success: false, error: 'Mesh not found' };
|
|
250
|
+
const node = mesh?.nodes?.find((n: any) => meshNodeIdMatches(n, nodeId));
|
|
251
|
+
if (!node) return { success: false, error: `Node '${nodeId}' not found in mesh` };
|
|
252
|
+
const mode = ctx.normalizeMeshSessionCleanupMode(args?.mode ?? mesh?.policy?.sessionCleanupOnNodeRemove);
|
|
253
|
+
const sessionIds = Array.isArray(args?.sessionIds)
|
|
254
|
+
? args.sessionIds.map((id: any) => typeof id === 'string' ? id.trim() : '').filter(Boolean)
|
|
255
|
+
: undefined;
|
|
256
|
+
const result = await ctx.cleanupMeshSessions({
|
|
257
|
+
meshId,
|
|
258
|
+
nodeId,
|
|
259
|
+
node,
|
|
260
|
+
mode,
|
|
261
|
+
sessionIds,
|
|
262
|
+
dryRun: args?.dryRun === true,
|
|
263
|
+
source: 'mesh_cleanup_sessions',
|
|
264
|
+
});
|
|
265
|
+
return result;
|
|
266
|
+
} catch (e: any) {
|
|
267
|
+
return { success: false, error: e.message };
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
|
|
271
|
+
remove_mesh_node: async (ctx: MedFamilyContext, args: any) => {
|
|
272
|
+
const meshId = typeof args?.meshId === 'string' ? args.meshId.trim() : '';
|
|
273
|
+
const nodeId = typeof args?.nodeId === 'string' ? args.nodeId.trim() : '';
|
|
274
|
+
if (!meshId || !nodeId) return { success: false, error: 'meshId and nodeId required' };
|
|
275
|
+
try {
|
|
276
|
+
// preferInline so removal can resolve inline-cache-only clone worktree nodes.
|
|
277
|
+
const meshRecord = await ctx.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
278
|
+
const mesh = meshRecord?.mesh;
|
|
279
|
+
const node = mesh?.nodes?.find((n: any) => meshNodeIdMatches(n, nodeId));
|
|
280
|
+
|
|
281
|
+
// Guard: refuse to remove the coordinator's OWN local base node
|
|
282
|
+
// (same machine, NOT a worktree). Removing it breaks live mesh
|
|
283
|
+
// membership — the coordinator can no longer be reached and has
|
|
284
|
+
// to be restarted. Worktree clones are always safe to remove;
|
|
285
|
+
// only the non-worktree node bound to this daemon is protected.
|
|
286
|
+
// An explicit force:true overrides for intentional mesh teardown.
|
|
287
|
+
if (node && !args?._meshDirectDispatch && node.isLocalWorktree !== true && args?.force !== true) {
|
|
288
|
+
const nodeDaemonId = typeof node.daemonId === 'string' ? node.daemonId.trim() : '';
|
|
289
|
+
const nodeMachineId = readMeshNodeMachineId(node as Record<string, unknown>) || '';
|
|
290
|
+
const selfDaemonId = ctx.deps.statusInstanceId || '';
|
|
291
|
+
const selfMachineId = (() => { try { return loadConfig().machineId || ''; } catch { return ''; } })();
|
|
292
|
+
// Identity match is form-safe: a daemon answers to the same machine
|
|
293
|
+
// under interchangeable id forms (bare `mach_X`, cloud `daemon_mach_X`,
|
|
294
|
+
// standalone `standalone_mach_X`). statusInstanceId/loadConfig().machineId
|
|
295
|
+
// and the node's stored daemonId/machineId frequently hold DIFFERENT forms
|
|
296
|
+
// of the same machine, so a raw `===` would miss the self-match and let the
|
|
297
|
+
// coordinator delete its own live base node (the very accident this guard
|
|
298
|
+
// exists to prevent). daemonIdsEquivalent collapses every form to its
|
|
299
|
+
// machine core before comparing, so a same-machine match is caught
|
|
300
|
+
// regardless of which form each side carries. This only widens matches
|
|
301
|
+
// (every raw-`===` hit still matches) — fail-open → fail-closed.
|
|
302
|
+
const isCoordinatorBaseNode =
|
|
303
|
+
(!!selfDaemonId && (daemonIdsEquivalent(nodeDaemonId, selfDaemonId) || daemonIdsEquivalent(nodeMachineId, selfDaemonId)))
|
|
304
|
+
|| (!!selfMachineId && (daemonIdsEquivalent(nodeDaemonId, selfMachineId) || daemonIdsEquivalent(nodeMachineId, selfMachineId)));
|
|
305
|
+
if (isCoordinatorBaseNode) {
|
|
306
|
+
return {
|
|
307
|
+
success: false,
|
|
308
|
+
removed: false,
|
|
309
|
+
code: 'mesh_remove_coordinator_base_node_protected',
|
|
310
|
+
error: `Refusing to remove the coordinator's own base node '${typeof node.workspace === 'string' ? node.workspace : nodeId}'. `
|
|
311
|
+
+ `It is the local non-worktree node bound to this coordinator daemon; removing it breaks live mesh membership and forces a restart.`,
|
|
312
|
+
recoveryHint: 'Remove worktree clone nodes instead, or pass force:true only if you are intentionally tearing down this mesh and accept that the coordinator must be re-registered/restarted.',
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Default worktree session cleanup ON: when the caller OMITS a mode and the
|
|
318
|
+
// node is a local worktree, default to 'stop_and_delete' instead of the mesh
|
|
319
|
+
// policy ('preserve' by default). A worktree's chat session has no reason to
|
|
320
|
+
// outlive the worktree's node + directory + branch, and leaving it on
|
|
321
|
+
// 'preserve' is what orphaned chats after a worktree remove. An explicit mode
|
|
322
|
+
// (including an explicit 'preserve') is always honored — only the OMITTED case
|
|
323
|
+
// changes, and only for worktrees. Base nodes keep arg ?? policy ?? preserve.
|
|
324
|
+
const explicitCleanupMode = args?.sessionCleanupMode ?? args?.session_cleanup_mode;
|
|
325
|
+
const sessionCleanupMode = ctx.normalizeMeshSessionCleanupMode(
|
|
326
|
+
explicitCleanupMode
|
|
327
|
+
?? (node?.isLocalWorktree === true ? 'stop_and_delete' : undefined)
|
|
328
|
+
?? mesh?.policy?.sessionCleanupOnNodeRemove,
|
|
329
|
+
);
|
|
330
|
+
// Explicit sessionIds (e.g. supplied by refine auto-cleanup) bypass the
|
|
331
|
+
// workspace-only-match guard so a delegate session that lacks a
|
|
332
|
+
// meta.meshNodeId binding can still be stopped/deleted.
|
|
333
|
+
const explicitSessionIds = Array.isArray(args?.sessionIds)
|
|
334
|
+
? (args.sessionIds as unknown[]).filter((v): v is string => typeof v === 'string' && v.trim().length > 0).map(v => v.trim())
|
|
335
|
+
: undefined;
|
|
336
|
+
let sessionCleanup: Record<string, unknown> | undefined;
|
|
337
|
+
if (node && sessionCleanupMode !== 'preserve') {
|
|
338
|
+
sessionCleanup = await ctx.cleanupMeshSessions({
|
|
339
|
+
meshId,
|
|
340
|
+
nodeId,
|
|
341
|
+
node,
|
|
342
|
+
mode: sessionCleanupMode,
|
|
343
|
+
...(explicitSessionIds && explicitSessionIds.length > 0 ? { sessionIds: explicitSessionIds } : {}),
|
|
344
|
+
source: 'mesh_remove_node',
|
|
345
|
+
});
|
|
346
|
+
if (sessionCleanup.success === false) return { success: false, removed: false, sessionCleanup };
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
let worktreeCleanup: Record<string, unknown> | undefined;
|
|
350
|
+
if (node?.isLocalWorktree) {
|
|
351
|
+
const nodeDaemonId = typeof node.daemonId === 'string' ? node.daemonId.trim() : undefined;
|
|
352
|
+
// daemonIdsEquivalent: an equivalent-form daemonId is this machine —
|
|
353
|
+
// clean up locally, do not forward. Equivalent → local.
|
|
354
|
+
const isRemoteWorktree = nodeDaemonId && !daemonIdsEquivalent(nodeDaemonId, ctx.deps.statusInstanceId) && ctx.deps.dispatchMeshCommand
|
|
355
|
+
&& !args?._meshDirectDispatch;
|
|
356
|
+
if (isRemoteWorktree) {
|
|
357
|
+
// Worktree lives on a different machine — ask that daemon to clean it up.
|
|
358
|
+
// _meshDirectDispatch prevents re-forwarding when stored daemonId uses legacy format.
|
|
359
|
+
const forwarded = await ctx.deps.dispatchMeshCommand!(nodeDaemonId!, 'remove_mesh_node', {
|
|
360
|
+
...(typeof args === 'object' && args !== null ? args as Record<string, unknown> : {}),
|
|
361
|
+
_meshDirectDispatch: true,
|
|
362
|
+
});
|
|
363
|
+
return (forwarded ?? { success: false, error: 'no response from remote node' }) as CommandRouterResult;
|
|
364
|
+
}
|
|
365
|
+
const cleanupResult = await ctx.cleanupLocalWorktreeNode({ mesh, node, nodeId, force: args?.force === true });
|
|
366
|
+
// De-gating: membership removal is NOT gated on the worktree
|
|
367
|
+
// directory actually being deleted. cleanupLocalWorktreeNode now
|
|
368
|
+
// returns success:true (with a residue flag) whenever the path is
|
|
369
|
+
// proven managed and the only remaining problem is leftover
|
|
370
|
+
// directory bytes (e.g. Windows EINVAL). A success:false here means
|
|
371
|
+
// a genuinely-unsafe condition — missing metadata, a non-managed /
|
|
372
|
+
// unexpected path, a branch mismatch, a dirty worktree, or an
|
|
373
|
+
// unverified force fallback — and those still block removal.
|
|
374
|
+
if (cleanupResult.success === false) {
|
|
375
|
+
return {
|
|
376
|
+
success: false,
|
|
377
|
+
removed: false,
|
|
378
|
+
code: cleanupResult.code,
|
|
379
|
+
error: cleanupResult.error,
|
|
380
|
+
recoveryHint: cleanupResult.recoveryHint,
|
|
381
|
+
...(sessionCleanup ? { sessionCleanup } : {}),
|
|
382
|
+
worktreeCleanup: cleanupResult,
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
worktreeCleanup = cleanupResult;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
let removed = false;
|
|
389
|
+
if (meshRecord?.inline) {
|
|
390
|
+
removed = ctx.removeInlineMeshNode(meshId, mesh, nodeId);
|
|
391
|
+
// Inline meshes share the same aggregate snapshot cache as
|
|
392
|
+
// local-config meshes; without this bust the removed node
|
|
393
|
+
// keeps showing up in the dashboard graph until the cache
|
|
394
|
+
// ages out on its own.
|
|
395
|
+
if (removed) ctx.invalidateAggregateMeshStatus(meshId);
|
|
396
|
+
// Node was already absent from the inline mesh (e.g. removed by a
|
|
397
|
+
// prior refine cleanup). Treat as removed so caller gets removed:true.
|
|
398
|
+
if (!removed && !node) removed = true;
|
|
399
|
+
} else {
|
|
400
|
+
const { removeNode } = await import('../../config/mesh-config.js');
|
|
401
|
+
removed = removeNode(meshId, nodeId);
|
|
402
|
+
// Node already absent from config (e.g. removed by a prior refine
|
|
403
|
+
// cleanup after a successful Refinery merge). Treat as removed so
|
|
404
|
+
// the response is accurate.
|
|
405
|
+
if (!removed && !node) removed = true;
|
|
406
|
+
if (removed) ctx.invalidateAggregateMeshStatus(meshId);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// Record in task ledger
|
|
410
|
+
if (removed) {
|
|
411
|
+
try {
|
|
412
|
+
const { appendLedgerEntry } = await import('../../mesh/mesh-ledger.js');
|
|
413
|
+
appendLedgerEntry(meshId, {
|
|
414
|
+
kind: 'node_removed',
|
|
415
|
+
nodeId,
|
|
416
|
+
payload: {
|
|
417
|
+
worktree: !!node?.isLocalWorktree,
|
|
418
|
+
sessionCleanupMode,
|
|
419
|
+
workspace: typeof node?.workspace === 'string' ? node.workspace : undefined,
|
|
420
|
+
daemonId: typeof node?.daemonId === 'string' ? node.daemonId : undefined,
|
|
421
|
+
worktreeBranch: typeof node?.worktreeBranch === 'string' ? node.worktreeBranch : undefined,
|
|
422
|
+
worktreeCleanupFallback: typeof worktreeCleanup?.fallback === 'string' ? worktreeCleanup.fallback : undefined,
|
|
423
|
+
forced: worktreeCleanup?.forced === true ? true : undefined,
|
|
424
|
+
forceFallbackReason: typeof worktreeCleanup?.reason === 'string' ? worktreeCleanup.reason : undefined,
|
|
425
|
+
branchRefDeleted: typeof worktreeCleanup?.branchRefDeleted === 'boolean' ? worktreeCleanup.branchRefDeleted : undefined,
|
|
426
|
+
branchRefReason: typeof worktreeCleanup?.branchRefReason === 'string' ? worktreeCleanup.branchRefReason : undefined,
|
|
427
|
+
},
|
|
428
|
+
});
|
|
429
|
+
} catch { /* ledger append is best-effort */ }
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// Surface leftover-directory residue at the top level so callers
|
|
433
|
+
// see the node was dropped from the mesh even though the worktree
|
|
434
|
+
// directory could not be fully removed (best-effort, non-gating).
|
|
435
|
+
const residueWarning = worktreeCleanup?.residue === true && typeof worktreeCleanup?.residueWarning === 'string'
|
|
436
|
+
? worktreeCleanup.residueWarning
|
|
437
|
+
: undefined;
|
|
438
|
+
|
|
439
|
+
// Surface a preserved-branch warning at the top level so callers see
|
|
440
|
+
// that the branch ref was intentionally NOT deleted (unmerged work is
|
|
441
|
+
// never silently dropped). When the branch ref WAS deleted, the nested
|
|
442
|
+
// worktreeCleanup.branchRefDeleted flag already records it.
|
|
443
|
+
const branchRefWarning = typeof worktreeCleanup?.branchRefWarning === 'string'
|
|
444
|
+
? worktreeCleanup.branchRefWarning
|
|
445
|
+
: undefined;
|
|
446
|
+
|
|
447
|
+
// Orphan guard: if the session cleanup still left any LIVE session skipped
|
|
448
|
+
// (e.g. a future skip reason, or a workspace-only session on a base node),
|
|
449
|
+
// surface it at the top level so the caller knows a manual mesh_cleanup_sessions
|
|
450
|
+
// is still required for those sessionIds. Without this, a skipped-live session
|
|
451
|
+
// silently outlives a removed node (the very NODE-REMOVE-SESSION-ORPHAN bug).
|
|
452
|
+
const skippedLiveSessionIds = Array.isArray(sessionCleanup?.skippedLiveSessionIds)
|
|
453
|
+
? (sessionCleanup!.skippedLiveSessionIds as unknown[]).filter((v): v is string => typeof v === 'string')
|
|
454
|
+
: [];
|
|
455
|
+
const orphanedSessionsRemaining = skippedLiveSessionIds.length > 0;
|
|
456
|
+
const orphanNextAction = orphanedSessionsRemaining
|
|
457
|
+
? `Live session(s) [${skippedLiveSessionIds.join(', ')}] were skipped and still survive this node removal. `
|
|
458
|
+
+ `Run mesh_cleanup_sessions with mode:'stop_and_delete' and sessionIds:[${skippedLiveSessionIds.map(id => `'${id}'`).join(', ')}] to release them.`
|
|
459
|
+
: undefined;
|
|
460
|
+
return {
|
|
461
|
+
success: true,
|
|
462
|
+
removed,
|
|
463
|
+
...(residueWarning ? { residueWarning } : {}),
|
|
464
|
+
...(branchRefWarning ? { branchRefWarning } : {}),
|
|
465
|
+
...(sessionCleanup ? { sessionCleanup } : {}),
|
|
466
|
+
...(worktreeCleanup ? { worktreeCleanup } : {}),
|
|
467
|
+
...(orphanedSessionsRemaining
|
|
468
|
+
? { orphanedSessionsRemaining: true, nextAction: orphanNextAction }
|
|
469
|
+
: {}),
|
|
470
|
+
};
|
|
471
|
+
} catch (e: any) {
|
|
472
|
+
return { success: false, error: e.message };
|
|
473
|
+
}
|
|
474
|
+
},
|
|
475
|
+
|
|
476
|
+
clone_mesh_node: async (ctx: MedFamilyContext, args: any) => {
|
|
477
|
+
const meshId = typeof args?.meshId === 'string' ? args.meshId.trim() : '';
|
|
478
|
+
const sourceNodeId = typeof args?.sourceNodeId === 'string' ? args.sourceNodeId.trim() : '';
|
|
479
|
+
const branch = typeof args?.branch === 'string' ? args.branch.trim() : '';
|
|
480
|
+
const baseBranch = typeof args?.baseBranch === 'string' ? args.baseBranch.trim() : undefined;
|
|
481
|
+
if (!meshId) return { success: false, error: 'meshId required' };
|
|
482
|
+
if (!sourceNodeId) return { success: false, error: 'sourceNodeId required' };
|
|
483
|
+
if (!branch) return { success: false, error: 'branch required' };
|
|
484
|
+
const ownerFailure = await ctx.requireMeshHostMutationOwner(meshId, args?.inlineMesh, 'worktree clone');
|
|
485
|
+
if (ownerFailure) return ownerFailure;
|
|
486
|
+
|
|
487
|
+
try {
|
|
488
|
+
// Resolve with preferInline so the clone writes the new node into the
|
|
489
|
+
// same representation that get_mesh reads back. The MCP coordinator
|
|
490
|
+
// passes inlineMesh on every mesh command, so when it owns an inline
|
|
491
|
+
// mesh the membership read path (get_mesh, preferInline: true) returns
|
|
492
|
+
// the inline cache. Without preferInline here, clone could resolve to a
|
|
493
|
+
// local-config mesh and write the node only to config — leaving the
|
|
494
|
+
// inline cache (and therefore get_mesh / refreshMeshFromDaemon) without
|
|
495
|
+
// the node, so the new worktree node is never visible in live mesh
|
|
496
|
+
// membership even though worktree_bootstrap_complete fires.
|
|
497
|
+
const meshRecord = await ctx.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
498
|
+
const mesh = meshRecord?.mesh;
|
|
499
|
+
if (!mesh) return { success: false, error: 'Mesh not found' };
|
|
500
|
+
|
|
501
|
+
const sourceNode = mesh.nodes?.find((n: any) => meshNodeIdMatches(n, sourceNodeId));
|
|
502
|
+
if (!sourceNode) return { success: false, error: `Source node '${sourceNodeId}' not found in mesh` };
|
|
503
|
+
|
|
504
|
+
// Forward to the source node's daemon if it's on a different machine.
|
|
505
|
+
// _meshDirectDispatch prevents infinite re-forwarding when the stored daemonId
|
|
506
|
+
// uses a legacy format that doesn't match the receiving daemon's statusInstanceId.
|
|
507
|
+
const sourceDaemonId = typeof sourceNode.daemonId === 'string' ? sourceNode.daemonId.trim() : undefined;
|
|
508
|
+
// daemonIdsEquivalent: an equivalent-form source daemonId is this machine —
|
|
509
|
+
// clone locally, do not forward. Equivalent → local.
|
|
510
|
+
if (sourceDaemonId && !daemonIdsEquivalent(sourceDaemonId, ctx.deps.statusInstanceId) && ctx.deps.dispatchMeshCommand
|
|
511
|
+
&& !args?._meshDirectDispatch) {
|
|
512
|
+
const forwarded = await ctx.deps.dispatchMeshCommand(sourceDaemonId, 'clone_mesh_node', {
|
|
513
|
+
...(typeof args === 'object' && args !== null ? args as Record<string, unknown> : {}),
|
|
514
|
+
_meshDirectDispatch: true,
|
|
515
|
+
});
|
|
516
|
+
return (forwarded ?? { success: false, error: 'no response from remote node' }) as CommandRouterResult;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
const repoRoot = sourceNode.repoRoot || sourceNode.workspace;
|
|
520
|
+
const { createWorktree } = await import('../../git/git-worktree.js');
|
|
521
|
+
const result = await createWorktree({
|
|
522
|
+
repoRoot,
|
|
523
|
+
branch,
|
|
524
|
+
baseBranch,
|
|
525
|
+
meshName: mesh.name,
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
let node: any;
|
|
529
|
+
if (meshRecord.inline) {
|
|
530
|
+
const { randomUUID } = await import('crypto');
|
|
531
|
+
node = {
|
|
532
|
+
id: `node_${randomUUID().replace(/-/g, '')}`,
|
|
533
|
+
workspace: result.worktreePath,
|
|
534
|
+
repoRoot: result.worktreePath,
|
|
535
|
+
daemonId: sourceNode.daemonId,
|
|
536
|
+
machineId: sourceNode.machineId ?? (sourceNode as any).machine_id,
|
|
537
|
+
userOverrides: { ...(sourceNode.userOverrides || {}) },
|
|
538
|
+
policy: { ...(sourceNode.policy || {}) },
|
|
539
|
+
isLocalWorktree: true,
|
|
540
|
+
worktreeBranch: result.branch,
|
|
541
|
+
clonedFromNodeId: sourceNodeId,
|
|
542
|
+
};
|
|
543
|
+
ctx.updateInlineMeshNode(meshId, mesh, node);
|
|
544
|
+
} else {
|
|
545
|
+
const { addNode } = await import('../../config/mesh-config.js');
|
|
546
|
+
node = addNode(meshId, {
|
|
547
|
+
workspace: result.worktreePath,
|
|
548
|
+
repoRoot: result.worktreePath,
|
|
549
|
+
daemonId: sourceNode.daemonId,
|
|
550
|
+
machineId: sourceNode.machineId ?? (sourceNode as any).machine_id,
|
|
551
|
+
userOverrides: { ...(sourceNode.userOverrides || {}) },
|
|
552
|
+
isLocalWorktree: true,
|
|
553
|
+
worktreeBranch: result.branch,
|
|
554
|
+
clonedFromNodeId: sourceNodeId,
|
|
555
|
+
policy: { ...(sourceNode.policy || {}) },
|
|
556
|
+
});
|
|
557
|
+
if (!node) return { success: false, error: 'Failed to register worktree node' };
|
|
558
|
+
// Also reconcile the freshly-registered node into any warmed inline
|
|
559
|
+
// cache for this mesh. get_mesh (preferInline: true) reads the inline
|
|
560
|
+
// cache first when one exists; if we only wrote to local config the
|
|
561
|
+
// node would be invisible to membership reads. updateInlineMeshNode is
|
|
562
|
+
// a no-op when no inline cache is present.
|
|
563
|
+
const inlineForReconcile = ctx.getCachedInlineMesh(meshId);
|
|
564
|
+
if (inlineForReconcile) ctx.updateInlineMeshNode(meshId, inlineForReconcile, node);
|
|
565
|
+
ctx.invalidateAggregateMeshStatus(meshId);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
const persistWorktreeSetupState = async (bootstrapState: WorktreeBootstrapState): Promise<void> => {
|
|
569
|
+
node.worktreeBootstrap = bootstrapState;
|
|
570
|
+
if (meshRecord.inline) {
|
|
571
|
+
ctx.updateInlineMeshNode(meshId, mesh, node);
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
try {
|
|
575
|
+
const { updateNode } = await import('../../config/mesh-config.js');
|
|
576
|
+
updateNode(meshId, node.id, { worktreeBootstrap: bootstrapState });
|
|
577
|
+
ctx.invalidateAggregateMeshStatus(meshId);
|
|
578
|
+
} catch { /* bootstrap status persistence is best-effort */ }
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
const appendCloneLedger = async (initSubmodules: boolean, bootstrapState: WorktreeBootstrapState): Promise<void> => {
|
|
582
|
+
try {
|
|
583
|
+
const { appendLedgerEntry } = await import('../../mesh/mesh-ledger.js');
|
|
584
|
+
appendLedgerEntry(meshId, {
|
|
585
|
+
kind: 'node_cloned',
|
|
586
|
+
nodeId: node.id,
|
|
587
|
+
payload: {
|
|
588
|
+
sourceNodeId,
|
|
589
|
+
branch: result.branch,
|
|
590
|
+
worktreePath: result.worktreePath,
|
|
591
|
+
submodulesInitialized: initSubmodules,
|
|
592
|
+
worktreeBootstrap: {
|
|
593
|
+
status: bootstrapState.status,
|
|
594
|
+
required: bootstrapState.required,
|
|
595
|
+
configSource: bootstrapState.configSource,
|
|
596
|
+
configSourceType: bootstrapState.configSourceType,
|
|
597
|
+
lastCommand: bootstrapState.lastCommand,
|
|
598
|
+
exitCode: bootstrapState.exitCode,
|
|
599
|
+
},
|
|
600
|
+
},
|
|
601
|
+
});
|
|
602
|
+
} catch { /* ledger append is best-effort */ }
|
|
603
|
+
};
|
|
604
|
+
|
|
605
|
+
const initSubmodules = (sourceNode.policy as any)?.initSubmodulesOnClone !== false;
|
|
606
|
+
const loadedBootstrap = loadMeshWorktreeBootstrapConfig(mesh, result.worktreePath);
|
|
607
|
+
const runningBootstrapState: WorktreeBootstrapState = {
|
|
608
|
+
status: 'running',
|
|
609
|
+
required: loadedBootstrap.config?.required !== false,
|
|
610
|
+
configSource: loadedBootstrap.path || loadedBootstrap.source,
|
|
611
|
+
configSourceType: loadedBootstrap.sourceType,
|
|
612
|
+
startedAt: new Date().toISOString(),
|
|
613
|
+
};
|
|
614
|
+
await persistWorktreeSetupState(runningBootstrapState);
|
|
615
|
+
|
|
616
|
+
const finishWorktreeSetup = async (): Promise<{ submodulesInitialized: boolean; bootstrapState: WorktreeBootstrapState }> => {
|
|
617
|
+
let submodulesInitialized = false;
|
|
618
|
+
if (initSubmodules) {
|
|
619
|
+
try {
|
|
620
|
+
const { runGit } = await import('../../git/git-executor.js');
|
|
621
|
+
await runGit(
|
|
622
|
+
{ workspace: result.worktreePath, repoRoot: result.worktreePath, isGitRepo: true },
|
|
623
|
+
['submodule', 'update', '--init', '--recursive'],
|
|
624
|
+
{ timeoutMs: 120000 },
|
|
625
|
+
);
|
|
626
|
+
submodulesInitialized = true;
|
|
627
|
+
|
|
628
|
+
// Sync oss submodule to source node HEAD (best-effort)
|
|
629
|
+
const sourceWorkspace = sourceNode.repoRoot || sourceNode.workspace;
|
|
630
|
+
if (sourceWorkspace) {
|
|
631
|
+
try {
|
|
632
|
+
const { runGit: rg } = await import('../../git/git-executor.js');
|
|
633
|
+
const sourceCtx = { workspace: sourceWorkspace, repoRoot: sourceWorkspace, isGitRepo: true };
|
|
634
|
+
const worktreeCtx = { workspace: result.worktreePath, repoRoot: result.worktreePath, isGitRepo: true };
|
|
635
|
+
|
|
636
|
+
// Read source node's oss submodule SHA
|
|
637
|
+
const sourceStatusOut = await rg(sourceCtx, ['submodule', 'status', 'oss'], { timeoutMs: 10000 });
|
|
638
|
+
const sourceStatusLine = (typeof sourceStatusOut === 'string' ? sourceStatusOut : (sourceStatusOut as any)?.stdout ?? '').trim();
|
|
639
|
+
const sourceShaMatch = sourceStatusLine.match(/^[+\- ]?([0-9a-f]{40})/);
|
|
640
|
+
const sourceSha = sourceShaMatch?.[1];
|
|
641
|
+
|
|
642
|
+
if (sourceSha) {
|
|
643
|
+
// Read worktree's current oss HEAD
|
|
644
|
+
const ossCtx = { workspace: `${result.worktreePath}/oss`, repoRoot: `${result.worktreePath}/oss`, isGitRepo: true };
|
|
645
|
+
const worktreeOssHeadOut = await rg(ossCtx, ['rev-parse', 'HEAD'], { timeoutMs: 10000 });
|
|
646
|
+
const worktreeOssSha = (typeof worktreeOssHeadOut === 'string' ? worktreeOssHeadOut : (worktreeOssHeadOut as any)?.stdout ?? '').trim();
|
|
647
|
+
|
|
648
|
+
if (worktreeOssSha !== sourceSha) {
|
|
649
|
+
// Fetch target SHA from source node's oss directory
|
|
650
|
+
await rg(ossCtx, ['fetch', `${sourceWorkspace}/oss`, 'HEAD'], { timeoutMs: 60000 });
|
|
651
|
+
await rg(ossCtx, ['checkout', sourceSha], { timeoutMs: 10000 });
|
|
652
|
+
await rg(worktreeCtx, ['add', 'oss'], { timeoutMs: 10000 });
|
|
653
|
+
await rg(worktreeCtx, ['commit', '-m', 'chore: sync oss to source node HEAD on clone'], { timeoutMs: 10000 });
|
|
654
|
+
console.log(`[mesh] Synced oss submodule to source HEAD ${sourceSha.slice(0, 8)} in worktree`);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
} catch (ossErr: any) {
|
|
658
|
+
console.warn('[mesh] oss submodule sync to source HEAD failed (best-effort):', ossErr.message);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
} catch (subErr: any) {
|
|
662
|
+
// Submodule init is best-effort; don't fail the clone
|
|
663
|
+
console.warn('[mesh] Submodule init failed for worktree:', subErr.message);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
const bootstrapState: WorktreeBootstrapState = await runMeshWorktreeBootstrap(mesh, result.worktreePath);
|
|
667
|
+
await persistWorktreeSetupState(bootstrapState);
|
|
668
|
+
await appendCloneLedger(submodulesInitialized, bootstrapState);
|
|
669
|
+
return { submodulesInitialized, bootstrapState };
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
const requestedSetupWaitMs = Number(args?.setupWaitMs ?? args?.bootstrapWaitMs ?? 8000);
|
|
673
|
+
const setupWaitMs = Number.isFinite(requestedSetupWaitMs)
|
|
674
|
+
? Math.min(Math.max(requestedSetupWaitMs, 0), 14000)
|
|
675
|
+
: 8000;
|
|
676
|
+
const setupPromise = finishWorktreeSetup();
|
|
677
|
+
const setupResult = await Promise.race([
|
|
678
|
+
setupPromise.then((value) => ({ completed: true as const, value })),
|
|
679
|
+
new Promise<{ completed: false }>((resolve) => setTimeout(() => resolve({ completed: false }), setupWaitMs)),
|
|
680
|
+
]);
|
|
681
|
+
|
|
682
|
+
const emitBootstrapEvent = (eventStatus: 'bootstrap_complete' | 'bootstrap_failed', bootstrapState: WorktreeBootstrapState, startedAtMs: number, extraPayload?: Record<string, unknown>): void => {
|
|
683
|
+
try {
|
|
684
|
+
const durationMs = Date.now() - startedAtMs;
|
|
685
|
+
const event = `worktree_${eventStatus}` as const;
|
|
686
|
+
const metadataEvent = {
|
|
687
|
+
source: 'clone_mesh_node_bootstrap',
|
|
688
|
+
nodeId: node.id,
|
|
689
|
+
status: eventStatus,
|
|
690
|
+
worktreePath: result.worktreePath,
|
|
691
|
+
durationMs,
|
|
692
|
+
bootstrapStatus: bootstrapState.status,
|
|
693
|
+
...(bootstrapState.error ? { error: bootstrapState.error } : {}),
|
|
694
|
+
...(bootstrapState.exitCode !== undefined ? { exitCode: bootstrapState.exitCode } : {}),
|
|
695
|
+
...(extraPayload || {}),
|
|
696
|
+
};
|
|
697
|
+
if (typeof ctx.deps.instanceManager?.getByCategory === 'function') {
|
|
698
|
+
const forwarded = handleMeshForwardEvent(
|
|
699
|
+
{ instanceManager: ctx.deps.instanceManager } as any,
|
|
700
|
+
{ event, meshId, nodeId: node.id, workspace: result.worktreePath, metadataEvent },
|
|
701
|
+
);
|
|
702
|
+
if (forwarded?.success === true) return;
|
|
703
|
+
}
|
|
704
|
+
queuePendingMeshCoordinatorEvent({
|
|
705
|
+
event,
|
|
706
|
+
meshId,
|
|
707
|
+
nodeLabel: node.id,
|
|
708
|
+
nodeId: node.id,
|
|
709
|
+
workspace: result.worktreePath,
|
|
710
|
+
metadataEvent,
|
|
711
|
+
queuedAt: Date.now(),
|
|
712
|
+
});
|
|
713
|
+
} catch { /* event emission is best-effort */ }
|
|
714
|
+
};
|
|
715
|
+
|
|
716
|
+
const bootstrapStartedMs = Date.now();
|
|
717
|
+
|
|
718
|
+
if (!setupResult.completed) {
|
|
719
|
+
setupPromise
|
|
720
|
+
.then(({ bootstrapState }) => {
|
|
721
|
+
emitBootstrapEvent('bootstrap_complete', bootstrapState, bootstrapStartedMs);
|
|
722
|
+
})
|
|
723
|
+
.catch((error: any) => {
|
|
724
|
+
const failedState: WorktreeBootstrapState = {
|
|
725
|
+
...runningBootstrapState,
|
|
726
|
+
status: 'failed',
|
|
727
|
+
completedAt: new Date().toISOString(),
|
|
728
|
+
error: error?.message || String(error),
|
|
729
|
+
};
|
|
730
|
+
void persistWorktreeSetupState(failedState);
|
|
731
|
+
void appendCloneLedger(false, failedState);
|
|
732
|
+
emitBootstrapEvent('bootstrap_failed', failedState, bootstrapStartedMs, { error: error?.message || String(error) });
|
|
733
|
+
});
|
|
734
|
+
return {
|
|
735
|
+
success: true,
|
|
736
|
+
async: true,
|
|
737
|
+
status: 'accepted',
|
|
738
|
+
node,
|
|
739
|
+
worktreePath: result.worktreePath,
|
|
740
|
+
branch: result.branch,
|
|
741
|
+
worktreeBootstrap: runningBootstrapState,
|
|
742
|
+
worktreeSetup: {
|
|
743
|
+
status: 'running',
|
|
744
|
+
setupWaitMs,
|
|
745
|
+
message: 'Worktree node is registered; submodule/bootstrap setup is continuing in the background.',
|
|
746
|
+
},
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
const { submodulesInitialized, bootstrapState } = setupResult.value;
|
|
751
|
+
emitBootstrapEvent('bootstrap_complete', bootstrapState, bootstrapStartedMs);
|
|
752
|
+
return {
|
|
753
|
+
success: true,
|
|
754
|
+
node,
|
|
755
|
+
worktreePath: result.worktreePath,
|
|
756
|
+
branch: result.branch,
|
|
757
|
+
submodulesInitialized,
|
|
758
|
+
worktreeBootstrap: bootstrapState,
|
|
759
|
+
};
|
|
760
|
+
} catch (e: any) {
|
|
761
|
+
return { success: false, error: e.message };
|
|
762
|
+
}
|
|
763
|
+
},
|
|
764
|
+
|
|
765
|
+
retry_mesh_node_bootstrap: async (ctx: MedFamilyContext, args: any) => {
|
|
766
|
+
const meshId = typeof args?.meshId === 'string' ? args.meshId.trim() : '';
|
|
767
|
+
const nodeId = typeof args?.nodeId === 'string' ? args.nodeId.trim() : '';
|
|
768
|
+
if (!meshId) return { success: false, error: 'meshId required' };
|
|
769
|
+
if (!nodeId) return { success: false, error: 'nodeId required' };
|
|
770
|
+
const ownerFailure = await ctx.requireMeshHostMutationOwner(meshId, args?.inlineMesh, 'bootstrap retry');
|
|
771
|
+
if (ownerFailure) return ownerFailure;
|
|
772
|
+
|
|
773
|
+
try {
|
|
774
|
+
// preferInline so bootstrap-retry can resolve inline-cache-only clone worktree nodes.
|
|
775
|
+
const meshRecord = await ctx.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
776
|
+
const mesh = meshRecord?.mesh;
|
|
777
|
+
if (!mesh) return { success: false, error: 'Mesh not found' };
|
|
778
|
+
|
|
779
|
+
const node = mesh.nodes?.find((n: any) => meshNodeIdMatches(n, nodeId));
|
|
780
|
+
if (!node) return { success: false, error: `Node '${nodeId}' not found in mesh` };
|
|
781
|
+
if (!node.isLocalWorktree) return { success: false, error: 'Node is not a local worktree node' };
|
|
782
|
+
|
|
783
|
+
// Bootstrap runs scripts in the worktree path — forward to the node's daemon if remote.
|
|
784
|
+
// _meshDirectDispatch prevents re-forwarding when stored daemonId uses legacy format.
|
|
785
|
+
const nodeDaemonId = typeof node.daemonId === 'string' ? node.daemonId.trim() : undefined;
|
|
786
|
+
// daemonIdsEquivalent: an equivalent-form daemonId is this machine —
|
|
787
|
+
// bootstrap locally, do not forward. Equivalent → local.
|
|
788
|
+
if (nodeDaemonId && !daemonIdsEquivalent(nodeDaemonId, ctx.deps.statusInstanceId) && ctx.deps.dispatchMeshCommand
|
|
789
|
+
&& !args?._meshDirectDispatch) {
|
|
790
|
+
const forwarded = await ctx.deps.dispatchMeshCommand(nodeDaemonId, 'retry_mesh_node_bootstrap', {
|
|
791
|
+
...(typeof args === 'object' && args !== null ? args as Record<string, unknown> : {}),
|
|
792
|
+
_meshDirectDispatch: true,
|
|
793
|
+
});
|
|
794
|
+
return (forwarded ?? { success: false, error: 'no response from remote node' }) as CommandRouterResult;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
const currentBootstrap = node.worktreeBootstrap as WorktreeBootstrapState | undefined;
|
|
798
|
+
if (currentBootstrap?.status === 'running') {
|
|
799
|
+
return { success: false, error: 'Bootstrap is already running for this node' };
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
const worktreePath: string = node.workspace || node.repoRoot;
|
|
803
|
+
if (!worktreePath) return { success: false, error: 'Node has no workspace path' };
|
|
804
|
+
|
|
805
|
+
const loadedBootstrap = loadMeshWorktreeBootstrapConfig(mesh, worktreePath);
|
|
806
|
+
const runningState: WorktreeBootstrapState = {
|
|
807
|
+
status: 'running',
|
|
808
|
+
required: loadedBootstrap.config?.required !== false,
|
|
809
|
+
configSource: loadedBootstrap.path || loadedBootstrap.source,
|
|
810
|
+
configSourceType: loadedBootstrap.sourceType,
|
|
811
|
+
startedAt: new Date().toISOString(),
|
|
812
|
+
};
|
|
813
|
+
|
|
814
|
+
const persistState = async (bootstrapState: WorktreeBootstrapState): Promise<void> => {
|
|
815
|
+
node.worktreeBootstrap = bootstrapState;
|
|
816
|
+
if (meshRecord.inline) {
|
|
817
|
+
ctx.updateInlineMeshNode(meshId, mesh, node);
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
try {
|
|
821
|
+
const { updateNode } = await import('../../config/mesh-config.js');
|
|
822
|
+
updateNode(meshId, node.id, { worktreeBootstrap: bootstrapState });
|
|
823
|
+
ctx.invalidateAggregateMeshStatus(meshId);
|
|
824
|
+
} catch { /* best-effort */ }
|
|
825
|
+
};
|
|
826
|
+
|
|
827
|
+
await persistState(runningState);
|
|
828
|
+
const bootstrapState = await runMeshWorktreeBootstrap(mesh, worktreePath);
|
|
829
|
+
await persistState(bootstrapState);
|
|
830
|
+
|
|
831
|
+
return { success: true, bootstrapState };
|
|
832
|
+
} catch (e: any) {
|
|
833
|
+
return { success: false, error: e.message };
|
|
834
|
+
}
|
|
835
|
+
},
|
|
836
|
+
};
|