@adhdev/daemon-core 0.9.82-rc.44 → 0.9.82-rc.440

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.
Files changed (425) hide show
  1. package/dist/boot/daemon-lifecycle.d.ts +9 -0
  2. package/dist/boot/process-hardening.d.ts +50 -0
  3. package/dist/build-info.d.ts +37 -0
  4. package/dist/chat/source-machine.d.ts +166 -0
  5. package/dist/chat/source-resolver.d.ts +104 -0
  6. package/dist/chat/subscription-updates.d.ts +1 -0
  7. package/dist/cli-adapter-types.d.ts +68 -2
  8. package/dist/cli-adapters/cli-script-runner.d.ts +117 -0
  9. package/dist/cli-adapters/cli-state-engine.d.ts +200 -0
  10. package/dist/cli-adapters/provider-cli-adapter.d.ts +126 -64
  11. package/dist/cli-adapters/provider-cli-parse.d.ts +5 -0
  12. package/dist/cli-adapters/provider-cli-runtime.d.ts +34 -0
  13. package/dist/cli-adapters/provider-cli-shared.d.ts +74 -0
  14. package/dist/cli-adapters/pty-write-chunking.d.ts +34 -0
  15. package/dist/cli-adapters/raw-terminal-io.d.ts +37 -0
  16. package/dist/cli-adapters/resolve-executable.d.ts +69 -0
  17. package/dist/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +6 -3
  18. package/dist/cli-adapters/terminal-backends/types.d.ts +10 -2
  19. package/dist/cli-adapters/terminal-screen.d.ts +4 -11
  20. package/dist/commands/chat-commands-debug-bundle.d.ts +14 -0
  21. package/dist/commands/chat-commands-read.d.ts +7 -0
  22. package/dist/commands/chat-commands-scope.d.ts +39 -0
  23. package/dist/commands/chat-commands-shared.d.ts +33 -0
  24. package/dist/commands/chat-commands-write.d.ts +14 -0
  25. package/dist/commands/chat-commands.d.ts +10 -23
  26. package/dist/commands/cli-manager.d.ts +15 -1
  27. package/dist/commands/handler.d.ts +125 -0
  28. package/dist/commands/high-family/index.d.ts +3 -0
  29. package/dist/commands/high-family/mesh-coordinator-launch.d.ts +2 -0
  30. package/dist/commands/high-family/mesh-events.d.ts +2 -0
  31. package/dist/commands/high-family/mesh-status.d.ts +2 -0
  32. package/dist/commands/high-family/types.d.ts +60 -0
  33. package/dist/commands/low-family/coordinator-prompt.d.ts +9 -0
  34. package/dist/commands/low-family/daemon-lifecycle.d.ts +2 -0
  35. package/dist/commands/low-family/diagnostics.d.ts +2 -0
  36. package/dist/commands/low-family/index.d.ts +3 -0
  37. package/dist/commands/low-family/mesh-ledger.d.ts +10 -0
  38. package/dist/commands/low-family/mesh-node-logs.d.ts +2 -0
  39. package/dist/commands/low-family/notification.d.ts +2 -0
  40. package/dist/commands/low-family/refine-config.d.ts +2 -0
  41. package/dist/commands/low-family/session-host.d.ts +2 -0
  42. package/dist/commands/low-family/spec-providerdev.d.ts +11 -0
  43. package/dist/commands/low-family/status-meta.d.ts +2 -0
  44. package/dist/commands/low-family/types.d.ts +33 -0
  45. package/dist/commands/med-family/cli-agent.d.ts +2 -0
  46. package/dist/commands/med-family/fast-forward.d.ts +2 -0
  47. package/dist/commands/med-family/ide.d.ts +10 -0
  48. package/dist/commands/med-family/index.d.ts +3 -0
  49. package/dist/commands/med-family/mesh-crud.d.ts +29 -0
  50. package/dist/commands/med-family/mesh-host-pairing.d.ts +2 -0
  51. package/dist/commands/med-family/mesh-queue.d.ts +2 -0
  52. package/dist/commands/med-family/mesh-restart.d.ts +2 -0
  53. package/dist/commands/med-family/types.d.ts +142 -0
  54. package/dist/commands/mesh-coordinator.d.ts +85 -1
  55. package/dist/commands/router.d.ts +276 -2
  56. package/dist/commands/upgrade-helper.d.ts +41 -1
  57. package/dist/config/chat-history.d.ts +9 -0
  58. package/dist/config/config.d.ts +5 -0
  59. package/dist/config/mesh-config.d.ts +120 -1
  60. package/dist/config/mesh-json-config.d.ts +199 -0
  61. package/dist/config/repo-settings.d.ts +77 -0
  62. package/dist/daemon/dev-server.d.ts +0 -2
  63. package/dist/detection/ide-detector.d.ts +13 -0
  64. package/dist/detection/win32-ide-version.d.ts +37 -0
  65. package/dist/git/change-impact-config.d.ts +159 -0
  66. package/dist/git/git-commands.d.ts +11 -1
  67. package/dist/git/git-diff.d.ts +6 -0
  68. package/dist/git/git-executor.d.ts +11 -0
  69. package/dist/git/git-status.d.ts +57 -0
  70. package/dist/git/git-types.d.ts +2 -50
  71. package/dist/git/git-worktree.d.ts +71 -1
  72. package/dist/git/index.d.ts +3 -1
  73. package/dist/index.d.ts +64 -14
  74. package/dist/index.js +50679 -20122
  75. package/dist/index.js.map +1 -1
  76. package/dist/index.mjs +47546 -17153
  77. package/dist/index.mjs.map +1 -1
  78. package/dist/installer.d.ts +1 -4
  79. package/dist/ipc/local-ipc-server.d.ts +91 -0
  80. package/dist/launch.d.ts +1 -1
  81. package/dist/logging/async-batch-writer.d.ts +10 -0
  82. package/dist/logging/log-redactor.d.ts +24 -0
  83. package/dist/logging/log-tail-reader.d.ts +81 -0
  84. package/dist/logging/logger.d.ts +1 -1
  85. package/dist/mesh/contracts.d.ts +164 -0
  86. package/dist/mesh/coordinator-prompt.d.ts +89 -0
  87. package/dist/mesh/coordinator-registry.d.ts +59 -0
  88. package/dist/mesh/mesh-active-work.d.ts +174 -0
  89. package/dist/mesh/mesh-clone-grace.d.ts +8 -0
  90. package/dist/mesh/mesh-coordinator-config.d.ts +21 -0
  91. package/dist/mesh/mesh-delivery-policy.d.ts +131 -0
  92. package/dist/mesh/mesh-event-classify.d.ts +5 -0
  93. package/dist/mesh/mesh-event-forwarding.d.ts +41 -0
  94. package/dist/mesh/mesh-event-trace.d.ts +21 -0
  95. package/dist/mesh/mesh-events-coordinator.d.ts +4 -0
  96. package/dist/mesh/mesh-events-pending.d.ts +69 -0
  97. package/dist/mesh/mesh-events-stale.d.ts +61 -0
  98. package/dist/mesh/mesh-events-utils.d.ts +75 -0
  99. package/dist/mesh/mesh-events.d.ts +6 -49
  100. package/dist/mesh/mesh-fast-forward.d.ts +81 -0
  101. package/dist/mesh/mesh-host-ownership.d.ts +29 -0
  102. package/dist/mesh/mesh-init.d.ts +128 -0
  103. package/dist/mesh/mesh-ledger-reconciliation.d.ts +23 -4
  104. package/dist/mesh/mesh-ledger.d.ts +77 -1
  105. package/dist/mesh/mesh-magi-status.d.ts +63 -0
  106. package/dist/mesh/mesh-missions.d.ts +189 -0
  107. package/dist/mesh/mesh-node-identity.d.ts +289 -0
  108. package/dist/mesh/mesh-queue-assignment.d.ts +113 -0
  109. package/dist/mesh/mesh-reconcile-loop.d.ts +65 -0
  110. package/dist/mesh/mesh-refine-batch.d.ts +68 -0
  111. package/dist/mesh/mesh-refine-gates.d.ts +428 -0
  112. package/dist/mesh/mesh-refine-status.d.ts +62 -0
  113. package/dist/mesh/mesh-review-inbox.d.ts +90 -0
  114. package/dist/mesh/mesh-routing.d.ts +70 -0
  115. package/dist/mesh/mesh-runtime-store.d.ts +450 -0
  116. package/dist/mesh/mesh-scheduling-runtime.d.ts +78 -0
  117. package/dist/mesh/mesh-task-inflight.d.ts +46 -0
  118. package/dist/mesh/mesh-task-stats.d.ts +49 -0
  119. package/dist/mesh/mesh-unresolved-forward-outbox.d.ts +30 -0
  120. package/dist/mesh/mesh-warmup-deadline.d.ts +68 -0
  121. package/dist/mesh/mesh-work-queue.d.ts +300 -5
  122. package/dist/mesh/preview-freshness.d.ts +18 -0
  123. package/dist/mesh/refine-config.d.ts +216 -0
  124. package/dist/mesh/worktree-bootstrap-config.d.ts +145 -0
  125. package/dist/providers/acp-provider-instance.d.ts +5 -0
  126. package/dist/providers/approval-utils.d.ts +20 -0
  127. package/dist/providers/chat-message-normalization.d.ts +31 -1
  128. package/dist/providers/cli-provider-instance.d.ts +252 -3
  129. package/dist/providers/contracts.d.ts +149 -6
  130. package/dist/providers/external-sources.d.ts +71 -0
  131. package/dist/providers/manual-attendance.d.ts +63 -0
  132. package/dist/providers/native-history/antigravity-cli-transcript.d.ts +100 -0
  133. package/dist/providers/native-history/claude-cli-transcript.d.ts +70 -0
  134. package/dist/providers/native-history/codex-cli-transcript.d.ts +73 -0
  135. package/dist/providers/native-history/constants.d.ts +12 -0
  136. package/dist/providers/native-history/dispatcher.d.ts +27 -0
  137. package/dist/providers/native-history/hermes-cli-transcript.d.ts +30 -0
  138. package/dist/providers/native-history/index.d.ts +13 -0
  139. package/dist/providers/provider-instance-manager.d.ts +29 -0
  140. package/dist/providers/provider-instance.d.ts +23 -1
  141. package/dist/providers/provider-loader.d.ts +26 -4
  142. package/dist/providers/provider-trust.d.ts +31 -0
  143. package/dist/providers/read-chat-contract.d.ts +29 -0
  144. package/dist/providers/sdk/v1/builders/acp/detect-status.d.ts +68 -0
  145. package/dist/providers/sdk/v1/builders/cli/detect-status.d.ts +86 -0
  146. package/dist/providers/sdk/v1/builders/cli/parse-approval-squash.d.ts +59 -0
  147. package/dist/providers/sdk/v1/builders/cli/parse-approval.d.ts +65 -0
  148. package/dist/providers/sdk/v1/builders/cli/parse-session.d.ts +91 -0
  149. package/dist/providers/sdk/v1/builders/cli/visible-region.d.ts +42 -0
  150. package/dist/providers/sdk/v1/fixture-tooling/format.d.ts +126 -0
  151. package/dist/providers/sdk/v1/fixture-tooling/index.d.ts +8 -0
  152. package/dist/providers/sdk/v1/fixture-tooling/replay.d.ts +38 -0
  153. package/dist/providers/sdk/v1/index.d.ts +30 -0
  154. package/dist/providers/sdk/v1/sandbox/README-design.d.ts +193 -0
  155. package/dist/providers/sdk/v1/sandbox/require-whitelist.d.ts +74 -0
  156. package/dist/providers/sdk/v1/sandbox/script-runner.d.ts +98 -0
  157. package/dist/providers/sdk/v1/types/cli/index.d.ts +277 -0
  158. package/dist/providers/sdk/v1/types/common/index.d.ts +203 -0
  159. package/dist/providers/sdk/v1/validators/index.d.ts +5 -0
  160. package/dist/providers/sdk/v1/validators/manifest.d.ts +40 -0
  161. package/dist/providers/sdk/v1/validators/taint.d.ts +52 -0
  162. package/dist/providers/spec/adapter.d.ts +91 -0
  163. package/dist/providers/spec/cli-adapter.d.ts +223 -0
  164. package/dist/providers/spec/evaluator.d.ts +45 -0
  165. package/dist/providers/spec/fsm-driver.d.ts +422 -0
  166. package/dist/providers/spec/fsm-evaluator.d.ts +76 -0
  167. package/dist/providers/spec/fsm-loader.d.ts +14 -0
  168. package/dist/providers/spec/fsm-types.d.ts +174 -0
  169. package/dist/providers/spec/native-history-executor.d.ts +41 -0
  170. package/dist/providers/spec/pre-launch-trust.d.ts +16 -0
  171. package/dist/providers/spec/route.d.ts +4 -0
  172. package/dist/providers/spec/types.d.ts +222 -0
  173. package/dist/providers/status-monitor.d.ts +7 -7
  174. package/dist/providers/transcript-v2.d.ts +176 -0
  175. package/dist/providers/types/interactive-prompt.d.ts +84 -0
  176. package/dist/providers/working-dir.d.ts +17 -0
  177. package/dist/repo-mesh-types.d.ts +509 -13
  178. package/dist/runtime-defaults.d.ts +2 -0
  179. package/dist/sessions/registry.d.ts +6 -0
  180. package/dist/shared-types-extra.d.ts +2 -4
  181. package/dist/shared-types.d.ts +59 -2
  182. package/dist/status/normalize.d.ts +1 -1
  183. package/dist/status/normalize.js +1 -0
  184. package/dist/status/normalize.js.map +1 -1
  185. package/dist/status/normalize.mjs +1 -0
  186. package/dist/status/normalize.mjs.map +1 -1
  187. package/dist/status/reporter.d.ts +2 -0
  188. package/dist/status/snapshot.d.ts +26 -0
  189. package/dist/system/hash.d.ts +8 -0
  190. package/dist/system/load-better-sqlite3.d.ts +21 -0
  191. package/dist/types.d.ts +5 -0
  192. package/package.json +7 -3
  193. package/src/agent-stream/poller.ts +2 -3
  194. package/src/agent-stream/provider-adapter.ts +1 -1
  195. package/src/boot/daemon-lifecycle.ts +63 -12
  196. package/src/boot/process-hardening.ts +89 -0
  197. package/src/build-info.ts +73 -0
  198. package/src/chat/source-machine.ts +534 -0
  199. package/src/chat/source-resolver.ts +0 -0
  200. package/src/chat/subscription-updates.ts +20 -1
  201. package/src/cli-adapter-types.d.ts +3 -1
  202. package/src/cli-adapter-types.ts +68 -2
  203. package/src/cli-adapters/cli-script-runner.ts +421 -0
  204. package/src/cli-adapters/cli-state-engine.ts +1246 -0
  205. package/src/cli-adapters/provider-cli-adapter.d.ts +1 -1
  206. package/src/cli-adapters/provider-cli-adapter.ts +914 -1144
  207. package/src/cli-adapters/provider-cli-parse.d.ts +2 -0
  208. package/src/cli-adapters/provider-cli-parse.ts +19 -0
  209. package/src/cli-adapters/provider-cli-runtime.ts +56 -7
  210. package/src/cli-adapters/provider-cli-shared.d.ts +4 -0
  211. package/src/cli-adapters/provider-cli-shared.ts +121 -11
  212. package/src/cli-adapters/pty-transport.ts +2 -1
  213. package/src/cli-adapters/pty-write-chunking.ts +106 -0
  214. package/src/cli-adapters/raw-terminal-io.ts +252 -0
  215. package/src/cli-adapters/resolve-executable.ts +204 -0
  216. package/src/cli-adapters/session-host-transport.ts +2 -1
  217. package/src/cli-adapters/terminal-backends/ghostty-vt-backend.ts +63 -29
  218. package/src/cli-adapters/terminal-backends/types.ts +10 -3
  219. package/src/cli-adapters/terminal-screen.ts +16 -81
  220. package/src/commands/WINDOWS-UPGRADE-LOCK-FAILURE.md +198 -0
  221. package/src/commands/chat-commands-debug-bundle.ts +398 -0
  222. package/src/commands/chat-commands-read.ts +2327 -0
  223. package/src/commands/chat-commands-scope.ts +54 -0
  224. package/src/commands/chat-commands-shared.ts +114 -0
  225. package/src/commands/chat-commands-write.ts +891 -0
  226. package/src/commands/chat-commands.ts +19 -1841
  227. package/src/commands/cli-manager.ts +572 -27
  228. package/src/commands/handler.ts +841 -2
  229. package/src/commands/high-family/index.ts +28 -0
  230. package/src/commands/high-family/mesh-coordinator-launch.ts +678 -0
  231. package/src/commands/high-family/mesh-events.ts +80 -0
  232. package/src/commands/high-family/mesh-status.ts +714 -0
  233. package/src/commands/high-family/types.ts +76 -0
  234. package/src/commands/low-family/coordinator-prompt.ts +72 -0
  235. package/src/commands/low-family/daemon-lifecycle.ts +107 -0
  236. package/src/commands/low-family/diagnostics.ts +57 -0
  237. package/src/commands/low-family/index.ts +37 -0
  238. package/src/commands/low-family/mesh-ledger.ts +62 -0
  239. package/src/commands/low-family/mesh-node-logs.ts +87 -0
  240. package/src/commands/low-family/notification.ts +116 -0
  241. package/src/commands/low-family/refine-config.ts +106 -0
  242. package/src/commands/low-family/session-host.ts +274 -0
  243. package/src/commands/low-family/spec-providerdev.ts +217 -0
  244. package/src/commands/low-family/status-meta.ts +112 -0
  245. package/src/commands/low-family/types.ts +39 -0
  246. package/src/commands/med-family/cli-agent.ts +238 -0
  247. package/src/commands/med-family/fast-forward.ts +230 -0
  248. package/src/commands/med-family/ide.ts +163 -0
  249. package/src/commands/med-family/index.ts +37 -0
  250. package/src/commands/med-family/mesh-crud.ts +1242 -0
  251. package/src/commands/med-family/mesh-host-pairing.ts +234 -0
  252. package/src/commands/med-family/mesh-queue.ts +167 -0
  253. package/src/commands/med-family/mesh-restart.ts +92 -0
  254. package/src/commands/med-family/types.ts +143 -0
  255. package/src/commands/mesh-coordinator.ts +334 -124
  256. package/src/commands/router.ts +2846 -3484
  257. package/src/commands/stream-commands.ts +8 -0
  258. package/src/commands/upgrade-helper.ts +310 -45
  259. package/src/config/chat-history.ts +493 -24
  260. package/src/config/config.ts +12 -0
  261. package/src/config/mesh-config.ts +593 -22
  262. package/src/config/mesh-json-config.ts +376 -0
  263. package/src/config/recent-activity.ts +8 -2
  264. package/src/config/repo-settings.ts +111 -0
  265. package/src/daemon/dev-auto-implement.ts +3 -2
  266. package/src/daemon/dev-cli-debug.ts +10 -1
  267. package/src/daemon/dev-server.ts +0 -541
  268. package/src/detection/cli-detector.ts +28 -9
  269. package/src/detection/ide-detector.ts +55 -16
  270. package/src/detection/win32-ide-version.ts +106 -0
  271. package/src/git/change-impact-config.ts +354 -0
  272. package/src/git/git-commands.ts +59 -15
  273. package/src/git/git-diff.ts +81 -11
  274. package/src/git/git-executor.ts +12 -0
  275. package/src/git/git-status.ts +767 -48
  276. package/src/git/git-types.ts +14 -62
  277. package/src/git/git-worktree.ts +261 -4
  278. package/src/git/index.ts +17 -0
  279. package/src/index.ts +196 -12
  280. package/src/installer.d.ts +1 -1
  281. package/src/installer.ts +8 -6
  282. package/src/ipc/local-ipc-server.ts +278 -0
  283. package/src/launch.d.ts +1 -1
  284. package/src/launch.ts +37 -28
  285. package/src/logging/async-batch-writer.ts +55 -0
  286. package/src/logging/command-log.ts +7 -5
  287. package/src/logging/log-redactor.ts +100 -0
  288. package/src/logging/log-tail-reader.ts +341 -0
  289. package/src/logging/logger.ts +14 -7
  290. package/src/mesh/contracts.ts +338 -0
  291. package/src/mesh/coordinator-prompt.ts +415 -34
  292. package/src/mesh/coordinator-registry.ts +121 -0
  293. package/src/mesh/mesh-active-work.ts +645 -0
  294. package/src/mesh/mesh-clone-grace.ts +68 -0
  295. package/src/mesh/mesh-coordinator-config.ts +97 -0
  296. package/src/mesh/mesh-delivery-policy.ts +315 -0
  297. package/src/mesh/mesh-event-classify.ts +51 -0
  298. package/src/mesh/mesh-event-forwarding.ts +1897 -0
  299. package/src/mesh/mesh-event-trace.ts +67 -0
  300. package/src/mesh/mesh-events-coordinator.ts +32 -0
  301. package/src/mesh/mesh-events-pending.ts +656 -0
  302. package/src/mesh/mesh-events-stale.ts +389 -0
  303. package/src/mesh/mesh-events-utils.ts +443 -0
  304. package/src/mesh/mesh-events.ts +33 -1035
  305. package/src/mesh/mesh-fast-forward.ts +843 -0
  306. package/src/mesh/mesh-host-ownership.ts +111 -0
  307. package/src/mesh/mesh-init.ts +350 -0
  308. package/src/mesh/mesh-ledger-reconciliation.ts +12 -7
  309. package/src/mesh/mesh-ledger.ts +656 -102
  310. package/src/mesh/mesh-magi-status.ts +223 -0
  311. package/src/mesh/mesh-missions.ts +449 -0
  312. package/src/mesh/mesh-node-identity.ts +1887 -0
  313. package/src/mesh/mesh-queue-assignment.ts +1924 -0
  314. package/src/mesh/mesh-reconcile-loop.ts +1997 -0
  315. package/src/mesh/mesh-refine-batch.ts +205 -0
  316. package/src/mesh/mesh-refine-gates.ts +1673 -0
  317. package/src/mesh/mesh-refine-status.ts +231 -0
  318. package/src/mesh/mesh-review-inbox.ts +307 -0
  319. package/src/mesh/mesh-routing.ts +291 -0
  320. package/src/mesh/mesh-runtime-store.ts +1853 -0
  321. package/src/mesh/mesh-scheduling-runtime.ts +198 -0
  322. package/src/mesh/mesh-task-inflight.ts +70 -0
  323. package/src/mesh/mesh-task-stats.ts +161 -0
  324. package/src/mesh/mesh-unresolved-forward-outbox.ts +185 -0
  325. package/src/mesh/mesh-warmup-deadline.ts +152 -0
  326. package/src/mesh/mesh-work-queue.ts +1254 -141
  327. package/src/mesh/preview-freshness.ts +118 -0
  328. package/src/mesh/refine-config.ts +423 -0
  329. package/src/mesh/worktree-bootstrap-config.ts +450 -0
  330. package/src/providers/acp-provider-instance.ts +43 -10
  331. package/src/providers/approval-utils.d.ts +5 -0
  332. package/src/providers/approval-utils.ts +57 -5
  333. package/src/providers/chat-message-normalization.ts +92 -4
  334. package/src/providers/cli-provider-instance.ts +2001 -106
  335. package/src/providers/contracts.d.ts +55 -0
  336. package/src/providers/contracts.ts +160 -6
  337. package/src/providers/extension-provider-instance.ts +12 -7
  338. package/src/providers/external-sources.ts +218 -0
  339. package/src/providers/ide-provider-instance.ts +35 -12
  340. package/src/providers/manual-attendance.ts +85 -0
  341. package/src/providers/native-history/antigravity-cli-transcript.ts +643 -0
  342. package/src/providers/native-history/claude-cli-transcript.ts +396 -0
  343. package/src/providers/native-history/codex-cli-transcript.ts +479 -0
  344. package/src/providers/native-history/constants.ts +19 -0
  345. package/src/providers/native-history/dispatcher.ts +345 -0
  346. package/src/providers/native-history/hermes-cli-transcript.ts +260 -0
  347. package/src/providers/native-history/index.ts +30 -0
  348. package/src/providers/provider-instance-manager.ts +71 -0
  349. package/src/providers/provider-instance.ts +19 -1
  350. package/src/providers/provider-loader.ts +668 -50
  351. package/src/providers/provider-schema.ts +87 -14
  352. package/src/providers/provider-trust.ts +114 -0
  353. package/src/providers/read-chat-contract.ts +76 -16
  354. package/src/providers/sdk/README.md +49 -0
  355. package/src/providers/sdk/v1/builders/acp/detect-status.ts +144 -0
  356. package/src/providers/sdk/v1/builders/cli/detect-status.ts +313 -0
  357. package/src/providers/sdk/v1/builders/cli/parse-approval-squash.ts +158 -0
  358. package/src/providers/sdk/v1/builders/cli/parse-approval.ts +250 -0
  359. package/src/providers/sdk/v1/builders/cli/parse-session.ts +276 -0
  360. package/src/providers/sdk/v1/builders/cli/visible-region.ts +143 -0
  361. package/src/providers/sdk/v1/fixture-tooling/format.ts +130 -0
  362. package/src/providers/sdk/v1/fixture-tooling/index.ts +22 -0
  363. package/src/providers/sdk/v1/fixture-tooling/replay.ts +352 -0
  364. package/src/providers/sdk/v1/index.ts +152 -0
  365. package/src/providers/sdk/v1/sandbox/README-design.ts +195 -0
  366. package/src/providers/sdk/v1/sandbox/require-whitelist.ts +472 -0
  367. package/src/providers/sdk/v1/sandbox/script-runner.ts +150 -0
  368. package/src/providers/sdk/v1/schemas/cli/provider.schema.json +509 -0
  369. package/src/providers/sdk/v1/schemas/primitives/acp-session-protocol-v1.json +131 -0
  370. package/src/providers/sdk/v1/schemas/primitives/native-history-codex-rollout-v1.json +66 -0
  371. package/src/providers/sdk/v1/schemas/primitives/tui-approval-squash-v1.json +91 -0
  372. package/src/providers/sdk/v1/schemas/primitives/tui-assistant-block-v1.json +91 -0
  373. package/src/providers/sdk/v1/schemas/primitives/tui-cue-ordering-v1.json +47 -0
  374. package/src/providers/sdk/v1/schemas/primitives/tui-dispatch-order-v1.json +32 -0
  375. package/src/providers/sdk/v1/schemas/primitives/tui-footer-chrome-v1.json +42 -0
  376. package/src/providers/sdk/v1/schemas/primitives/tui-index-finder-v1.json +27 -0
  377. package/src/providers/sdk/v1/schemas/primitives/tui-modal-v1.json +125 -0
  378. package/src/providers/sdk/v1/schemas/primitives/tui-prompt-marker-v1.json +45 -0
  379. package/src/providers/sdk/v1/schemas/primitives/tui-session-id-extraction-v1.json +46 -0
  380. package/src/providers/sdk/v1/schemas/primitives/tui-settled-prompt-v1.json +71 -0
  381. package/src/providers/sdk/v1/schemas/primitives/tui-spinner-v1.json +83 -0
  382. package/src/providers/sdk/v1/schemas/primitives/tui-transcript-pty-v1.json +83 -0
  383. package/src/providers/sdk/v1/schemas/primitives/tui-visible-region-v1.json +57 -0
  384. package/src/providers/sdk/v1/schemas/primitives/tui-welcome-screen-v1.json +35 -0
  385. package/src/providers/sdk/v1/types/cli/index.ts +365 -0
  386. package/src/providers/sdk/v1/types/common/index.ts +229 -0
  387. package/src/providers/sdk/v1/validators/index.ts +19 -0
  388. package/src/providers/sdk/v1/validators/manifest.ts +110 -0
  389. package/src/providers/sdk/v1/validators/taint.ts +309 -0
  390. package/src/providers/spec/adapter.ts +235 -0
  391. package/src/providers/spec/cli-adapter.ts +1056 -0
  392. package/src/providers/spec/evaluator.ts +407 -0
  393. package/src/providers/spec/fsm-driver.ts +1410 -0
  394. package/src/providers/spec/fsm-evaluator.ts +272 -0
  395. package/src/providers/spec/fsm-loader.ts +120 -0
  396. package/src/providers/spec/fsm-types.ts +273 -0
  397. package/src/providers/spec/native-history-executor.ts +1143 -0
  398. package/src/providers/spec/pre-launch-trust.ts +104 -0
  399. package/src/providers/spec/route.ts +51 -0
  400. package/src/providers/spec/types.ts +262 -0
  401. package/src/providers/status-monitor.d.ts +7 -7
  402. package/src/providers/status-monitor.ts +37 -22
  403. package/src/providers/transcript-v2.ts +567 -0
  404. package/src/providers/types/interactive-prompt.ts +536 -0
  405. package/src/providers/version-archive.ts +64 -24
  406. package/src/providers/working-dir.ts +23 -0
  407. package/src/repo-mesh-types.ts +748 -14
  408. package/src/runtime-defaults.ts +39 -0
  409. package/src/sessions/registry.ts +6 -0
  410. package/src/shared-types-extra.ts +2 -4
  411. package/src/shared-types.d.ts +8 -0
  412. package/src/shared-types.ts +64 -1
  413. package/src/status/builders.ts +26 -6
  414. package/src/status/normalize.ts +2 -0
  415. package/src/status/reporter.ts +19 -1
  416. package/src/status/snapshot.ts +95 -26
  417. package/src/system/hash.ts +23 -0
  418. package/src/system/host-memory.ts +29 -12
  419. package/src/system/load-better-sqlite3.ts +68 -0
  420. package/src/types.ts +5 -0
  421. package/dist/cli-adapters/terminal-backends/xterm-backend.d.ts +0 -17
  422. package/dist/mesh/mesh-sync.d.ts +0 -53
  423. package/src/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +0 -16
  424. package/src/cli-adapters/terminal-backends/xterm-backend.ts +0 -97
  425. package/src/mesh/mesh-sync.ts +0 -111
@@ -0,0 +1,234 @@
1
+ /**
2
+ * RF-ROUTER MED family — Mesh Host manual-pairing commands.
3
+ *
4
+ * get_mesh_host_pairing, configure_mesh_host_pairing,
5
+ * create_mesh_host_pairing_token, apply_mesh_host_join and
6
+ * join_mesh_host_pairing. These read/mutate the mesh host pairing metadata and,
7
+ * for join, apply the request to the host over mesh-command dispatch or a
8
+ * standalone HTTP command. Extracted verbatim from executeDaemonCommand; pairing
9
+ * helpers are imported from router.js, identical to the original references.
10
+ */
11
+ import { resolveMeshHostStatus } from '../../mesh/mesh-host-ownership.js';
12
+ import { buildMemberJoinNode, normalizeStandaloneHostCommandUrl } from '../router.js';
13
+ import type { MedFamilyContext, MedFamilyHandler } from './types.js';
14
+
15
+ export const meshHostPairingHandlers: Record<string, MedFamilyHandler> = {
16
+ get_mesh_host_pairing: async (ctx: MedFamilyContext, args: any) => {
17
+ const meshId = typeof args?.meshId === 'string' ? args.meshId.trim() : '';
18
+ if (!meshId) return { success: false, error: 'meshId required' };
19
+ const meshRecord = await ctx.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
20
+ const mesh = meshRecord?.mesh;
21
+ if (!mesh) return { success: false, error: 'Mesh not found' };
22
+ const meshHost = resolveMeshHostStatus(mesh);
23
+ const pairingStatus = meshHost.pairing?.status || 'not_configured';
24
+ return {
25
+ success: true,
26
+ code: pairingStatus === 'not_configured' ? 'mesh_host_pairing_not_configured' : 'mesh_host_pairing_pending',
27
+ meshId,
28
+ hostAddress: meshHost.hostAddress,
29
+ meshHost,
30
+ manualPairing: {
31
+ status: pairingStatus,
32
+ joinImplemented: true,
33
+ protocol: 'standalone_command_direct_v1',
34
+ description: 'Standalone manual pairing can save address/token metadata, apply a host join over direct standalone command HTTP or injected mesh command dispatch, and check persisted status. P2P signaling remains outside this slice.',
35
+ },
36
+ };
37
+ },
38
+
39
+ configure_mesh_host_pairing: async (ctx: MedFamilyContext, args: any) => {
40
+ const meshId = typeof args?.meshId === 'string' ? args.meshId.trim() : '';
41
+ const hostAddress = typeof args?.hostAddress === 'string' ? args.hostAddress.trim() : '';
42
+ const token = typeof args?.token === 'string' ? args.token.trim() : '';
43
+ if (!meshId) return { success: false, error: 'meshId required' };
44
+ if (!hostAddress || !token) return { success: false, error: 'hostAddress and token required' };
45
+ try {
46
+ const { configureMeshHostPairing } = await import('../../config/mesh-config.js');
47
+ const configured = configureMeshHostPairing(meshId, { hostAddress, token });
48
+ if (!configured) return { success: false, error: 'Mesh not found' };
49
+ ctx.inlineMeshCache.set(meshId, configured.mesh);
50
+ const meshHost = resolveMeshHostStatus(configured.mesh);
51
+ return {
52
+ success: true,
53
+ code: 'mesh_host_pairing_pending',
54
+ meshId,
55
+ hostAddress: configured.hostAddress,
56
+ meshHost,
57
+ manualPairing: {
58
+ status: meshHost.pairing?.status || 'pairing',
59
+ joinImplemented: true,
60
+ protocol: 'standalone_command_direct_v1',
61
+ description: 'Manual Mesh Host pairing config was saved locally. Use join_mesh_host_pairing to apply it to the host. Raw token was not persisted.',
62
+ },
63
+ };
64
+ } catch (e: any) {
65
+ return { success: false, code: 'mesh_host_pairing_invalid', meshId, hostAddress, error: e.message };
66
+ }
67
+ },
68
+
69
+ create_mesh_host_pairing_token: async (ctx: MedFamilyContext, args: any) => {
70
+ const meshId = typeof args?.meshId === 'string' ? args.meshId.trim() : '';
71
+ if (!meshId) return { success: false, error: 'meshId required' };
72
+ try {
73
+ const { createMeshHostPairingToken } = await import('../../config/mesh-config.js');
74
+ const created = createMeshHostPairingToken(meshId, {
75
+ token: typeof args?.token === 'string' ? args.token : undefined,
76
+ expiresAt: typeof args?.expiresAt === 'string' ? args.expiresAt : undefined,
77
+ });
78
+ if (!created) return { success: false, error: 'Mesh not found' };
79
+ ctx.inlineMeshCache.set(meshId, created.mesh);
80
+ ctx.invalidateAggregateMeshStatus(meshId);
81
+ return {
82
+ success: true,
83
+ code: 'mesh_host_pairing_token_created',
84
+ meshId,
85
+ token: created.token,
86
+ tokenId: created.tokenId,
87
+ expiresAt: created.expiresAt,
88
+ meshHost: resolveMeshHostStatus(created.mesh),
89
+ warning: 'Raw token is returned once and is not persisted; share it with member daemons over a trusted channel.',
90
+ };
91
+ } catch (e: any) {
92
+ return { success: false, code: 'mesh_host_pairing_token_invalid', meshId, error: e.message };
93
+ }
94
+ },
95
+
96
+ apply_mesh_host_join: async (ctx: MedFamilyContext, args: any) => {
97
+ const meshId = typeof args?.meshId === 'string' ? args.meshId.trim() : '';
98
+ const token = typeof args?.token === 'string' ? args.token.trim() : '';
99
+ const memberNode = args?.memberNode && typeof args.memberNode === 'object' && !Array.isArray(args.memberNode)
100
+ ? args.memberNode
101
+ : null;
102
+ if (!meshId) return { success: false, error: 'meshId required' };
103
+ if (!token || !memberNode) return { success: false, error: 'token and memberNode required' };
104
+ try {
105
+ const { applyMeshHostJoinRequest } = await import('../../config/mesh-config.js');
106
+ const applied = applyMeshHostJoinRequest(meshId, {
107
+ token,
108
+ memberNode: memberNode as any,
109
+ memberMeshId: typeof args?.memberMeshId === 'string' ? args.memberMeshId : undefined,
110
+ });
111
+ if (!applied) return { success: false, error: 'Mesh not found' };
112
+ if (!applied.accepted) {
113
+ return {
114
+ success: false,
115
+ code: 'mesh_host_join_rejected',
116
+ meshId,
117
+ tokenId: applied.tokenId,
118
+ meshHost: applied.meshHost ? resolveMeshHostStatus({ meshHost: applied.meshHost }) : undefined,
119
+ error: applied.reason,
120
+ };
121
+ }
122
+ ctx.inlineMeshCache.set(meshId, applied.mesh);
123
+ ctx.invalidateAggregateMeshStatus(meshId);
124
+ try {
125
+ const { appendLedgerEntry } = await import('../../mesh/mesh-ledger.js');
126
+ appendLedgerEntry(meshId, {
127
+ kind: 'node_joined',
128
+ nodeId: applied.node.id,
129
+ payload: { role: 'member', tokenId: applied.tokenId, workspace: applied.node.workspace },
130
+ });
131
+ } catch { /* ledger append is best-effort */ }
132
+ return {
133
+ success: true,
134
+ code: 'mesh_host_join_accepted',
135
+ meshId,
136
+ node: applied.node,
137
+ tokenId: applied.tokenId,
138
+ meshHost: resolveMeshHostStatus(applied.mesh),
139
+ };
140
+ } catch (e: any) {
141
+ return { success: false, code: 'mesh_host_join_failed', meshId, error: e.message };
142
+ }
143
+ },
144
+
145
+ join_mesh_host_pairing: async (ctx: MedFamilyContext, args: any) => {
146
+ const meshId = typeof args?.meshId === 'string' ? args.meshId.trim() : '';
147
+ const token = typeof args?.token === 'string' ? args.token.trim() : '';
148
+ if (!meshId) return { success: false, error: 'meshId required' };
149
+ if (!token) return { success: false, error: 'token required because raw pairing tokens are not persisted' };
150
+ const meshRecord = await ctx.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
151
+ const mesh = meshRecord?.mesh;
152
+ if (!mesh) return { success: false, error: 'Mesh not found' };
153
+ const meshHost = resolveMeshHostStatus(mesh);
154
+ if (meshHost.role !== 'member') {
155
+ return { success: false, code: 'mesh_host_join_not_member', meshId, meshHost, error: 'join_mesh_host_pairing must run from a member daemon configured with a Mesh Host address/token.' };
156
+ }
157
+ try {
158
+ const { tokenIdForManualPairing, markMeshHostPairingJoined } = await import('../../config/mesh-config.js');
159
+ const tokenId = tokenIdForManualPairing(token);
160
+ if (meshHost.pairing?.tokenId && meshHost.pairing.tokenId !== tokenId) {
161
+ return { success: false, code: 'mesh_host_join_rejected', meshId, tokenId, meshHost, error: 'invalid pairing token' };
162
+ }
163
+ const memberNode = buildMemberJoinNode(mesh, args, ctx.deps.statusInstanceId);
164
+ if (!memberNode) return { success: false, error: 'member node metadata unavailable' };
165
+ const hostMeshId = typeof args?.hostMeshId === 'string' && args.hostMeshId.trim() ? args.hostMeshId.trim() : meshId;
166
+ const hostDaemonId = typeof args?.hostDaemonId === 'string' && args.hostDaemonId.trim()
167
+ ? args.hostDaemonId.trim()
168
+ : meshHost.hostDaemonId;
169
+ let hostResult: any;
170
+ let transport: string;
171
+ if (hostDaemonId && ctx.deps.dispatchMeshCommand) {
172
+ transport = 'mesh_command_dispatch';
173
+ hostResult = await ctx.deps.dispatchMeshCommand(hostDaemonId, 'apply_mesh_host_join', {
174
+ meshId: hostMeshId,
175
+ token,
176
+ memberMeshId: meshId,
177
+ memberNode,
178
+ });
179
+ } else if (meshHost.hostAddress) {
180
+ transport = 'standalone_http_command';
181
+ const commandUrl = normalizeStandaloneHostCommandUrl(meshHost.hostAddress);
182
+ const response = await fetch(commandUrl, {
183
+ method: 'POST',
184
+ headers: { 'Content-Type': 'application/json' },
185
+ body: JSON.stringify({ type: 'apply_mesh_host_join', payload: { meshId: hostMeshId, token, memberMeshId: meshId, memberNode } }),
186
+ });
187
+ hostResult = await response.json().catch(() => ({ success: false, error: `Host returned HTTP ${response.status}` }));
188
+ if (!response.ok && hostResult?.success !== false) hostResult = { success: false, error: `Host returned HTTP ${response.status}` };
189
+ } else {
190
+ return {
191
+ success: false,
192
+ code: 'mesh_host_join_transport_unavailable',
193
+ meshId,
194
+ meshHost,
195
+ error: 'No hostDaemonId dispatch path or hostAddress HTTP command path is available. P2P signaling join is not implemented in this slice.',
196
+ };
197
+ }
198
+ if (!hostResult?.success) {
199
+ return { success: false, code: hostResult?.code || 'mesh_host_join_rejected', meshId, meshHost, transport, error: hostResult?.error || 'Mesh Host rejected join request', hostResult };
200
+ }
201
+ const joined = meshRecord.inline
202
+ ? null
203
+ : markMeshHostPairingJoined(meshId, {
204
+ tokenId: hostResult.tokenId || tokenId,
205
+ hostDaemonId: hostResult.meshHost?.hostDaemonId || hostDaemonId,
206
+ hostNodeId: hostResult.meshHost?.hostNodeId,
207
+ joinedAt: hostResult.meshHost?.pairing?.joinedAt,
208
+ });
209
+ if (joined) {
210
+ ctx.inlineMeshCache.set(meshId, joined.mesh);
211
+ ctx.invalidateAggregateMeshStatus(meshId);
212
+ }
213
+ return {
214
+ success: true,
215
+ code: 'mesh_host_join_applied',
216
+ meshId,
217
+ hostMeshId,
218
+ transport,
219
+ node: hostResult.node,
220
+ tokenId: hostResult.tokenId || tokenId,
221
+ meshHost: joined ? resolveMeshHostStatus(joined.mesh) : { ...meshHost, pairing: { ...(meshHost.pairing || {}), status: 'paired', tokenId: hostResult.tokenId || tokenId } },
222
+ hostResult,
223
+ manualPairing: {
224
+ status: 'paired',
225
+ joinImplemented: true,
226
+ protocol: 'standalone_command_direct_v1',
227
+ description: 'Mesh Host accepted the join and local member pairing status was marked paired. P2P runtime signaling remains outside this slice.',
228
+ },
229
+ };
230
+ } catch (e: any) {
231
+ return { success: false, code: 'mesh_host_join_failed', meshId, meshHost, error: e.message };
232
+ }
233
+ },
234
+ };
@@ -0,0 +1,167 @@
1
+ /**
2
+ * RF-ROUTER MED family — mesh work-queue commands.
3
+ *
4
+ * get_mesh_queue (view with dependency annotation), cancel_mesh_queue_task,
5
+ * requeue_mesh_queue_task and trigger_mesh_queue. The mutating commands gate on
6
+ * the Mesh Host owner check (ctx.requireMeshHostMutationOwner). trigger preflights
7
+ * a preferred-node claim before the round-robin trigger. Extracted verbatim from
8
+ * executeDaemonCommand.
9
+ */
10
+ import { readStringValue } from '../router.js';
11
+ import type { MedFamilyContext, MedFamilyHandler } from './types.js';
12
+
13
+ export const meshQueueHandlers: Record<string, MedFamilyHandler> = {
14
+ get_mesh_queue: async (_ctx: MedFamilyContext, args: any) => {
15
+ const meshId = typeof args?.meshId === 'string' ? args.meshId.trim() : '';
16
+ if (!meshId) return { success: false, error: 'meshId required' };
17
+ try {
18
+ const { getMeshQueueStats, getQueue, describeTaskDependencyState } = await import('../../mesh/mesh-work-queue.js');
19
+ const status = Array.isArray(args?.status)
20
+ ? args.status.map((s: any) => typeof s === 'string' ? s.trim() : '').filter(Boolean)
21
+ : undefined;
22
+ const rawQueue = getQueue(meshId, { status: status as any });
23
+ // M1: annotate dependency state at view time (waitingOn / dependenciesSatisfied).
24
+ const statusById = new Map(getQueue(meshId).map(task => [task.id, task.status]));
25
+ const queue = rawQueue.map(task =>
26
+ Array.isArray(task.dependsOn) && task.dependsOn.length > 0
27
+ ? { ...task, ...describeTaskDependencyState(task, statusById) }
28
+ : task);
29
+ const summary = getMeshQueueStats(meshId);
30
+ return {
31
+ success: true,
32
+ queue,
33
+ summary,
34
+ sourceOfTruth: {
35
+ kind: 'mesh_work_queue_file',
36
+ activeStatuses: ['pending', 'assigned'],
37
+ historicalStatuses: ['completed', 'failed', 'cancelled'],
38
+ notes: 'pending/assigned are active work; completed/failed/cancelled are historical records.',
39
+ },
40
+ };
41
+ } catch (e: any) {
42
+ return { success: false, error: e.message };
43
+ }
44
+ },
45
+
46
+ cancel_mesh_queue_task: async (ctx: MedFamilyContext, args: any) => {
47
+ const meshId = typeof args?.meshId === 'string' ? args.meshId.trim() : '';
48
+ const taskId = typeof args?.taskId === 'string' ? args.taskId.trim() : '';
49
+ if (!meshId || !taskId) return { success: false, error: 'meshId and taskId required' };
50
+ const ownerFailure = await ctx.requireMeshHostMutationOwner(meshId, args?.inlineMesh, 'queue cancellation');
51
+ if (ownerFailure) return ownerFailure;
52
+ try {
53
+ const { cancelTask } = await import('../../mesh/mesh-work-queue.js');
54
+ const reason = typeof args?.reason === 'string' ? args.reason : undefined;
55
+ const task = cancelTask(meshId, taskId, { reason });
56
+ if (!task) return { success: false, error: `Queue task '${taskId}' not found` };
57
+ return { success: true, task };
58
+ } catch (e: any) {
59
+ return { success: false, error: e.message };
60
+ }
61
+ },
62
+
63
+ requeue_mesh_queue_task: async (ctx: MedFamilyContext, args: any) => {
64
+ const meshId = typeof args?.meshId === 'string' ? args.meshId.trim() : '';
65
+ const taskId = typeof args?.taskId === 'string' ? args.taskId.trim() : '';
66
+ if (!meshId || !taskId) return { success: false, error: 'meshId and taskId required' };
67
+ const ownerFailure = await ctx.requireMeshHostMutationOwner(meshId, args?.inlineMesh, 'queue requeue');
68
+ if (ownerFailure) return ownerFailure;
69
+ try {
70
+ const { requeueTask, getQueue } = await import('../../mesh/mesh-work-queue.js');
71
+ // CANON-IDENTITY single-flight hardening (restart-safe): the in-memory in-flight
72
+ // mark requeueTask consults is process-local and is lost across a daemon restart.
73
+ // Independently of that mark, if the row is still 'assigned' to a session this
74
+ // daemon hosts that is actively generating, requeueing would flip it back to
75
+ // pending and let a SECOND session claim the SAME task (the duplicate dispatch).
76
+ // Refuse unless force. A genuinely dead/stale session is not generating, so this
77
+ // observation passes and a legitimate requeue proceeds. force=true (operator
78
+ // override) bypasses BOTH this and the in-memory guard.
79
+ // MAGI-NOTE: a future consensus group fan-out (separate mission) will exempt
80
+ // group-tagged tasks from this guard; the exemption hook belongs here.
81
+ if (args?.force !== true) {
82
+ const { isSessionActivelyGenerating } = await import('../../mesh/mesh-events.js');
83
+ const existing = getQueue(meshId).find((t: any) => t?.id === taskId) as { status?: string; assignedSessionId?: string } | undefined;
84
+ if (existing?.status === 'assigned' && existing.assignedSessionId
85
+ && isSessionActivelyGenerating(ctx.deps as any, existing.assignedSessionId)) {
86
+ return {
87
+ success: false,
88
+ error: `Task '${taskId}' is actively dispatched/generating (live session ${existing.assignedSessionId}); requeue refused to avoid a duplicate second dispatch. Pass force:true to override, or cancel and re-enqueue.`,
89
+ task: existing,
90
+ };
91
+ }
92
+ }
93
+ const task = requeueTask(meshId, taskId, {
94
+ reason: typeof args?.reason === 'string' ? args.reason : undefined,
95
+ targetNodeId: typeof args?.targetNodeId === 'string' ? args.targetNodeId.trim() : undefined,
96
+ targetSessionId: typeof args?.targetSessionId === 'string' ? args.targetSessionId.trim() : undefined,
97
+ clearTargetNode: args?.clearTargetNode === true,
98
+ clearTargetSession: args?.clearTargetSession !== false,
99
+ // CANON-IDENTITY: an in-flight (actively-generating) task is refused by
100
+ // default to avoid a duplicate second dispatch; an explicit operator
101
+ // force overrides that guard (and the retry cap).
102
+ force: args?.force === true,
103
+ });
104
+ if (!task) return { success: false, error: `Queue task '${taskId}' not found` };
105
+ // The single-flight guard returns the row UNCHANGED (still 'assigned') when it
106
+ // refuses an in-flight requeue — surface that as a clear, non-success signal so
107
+ // the coordinator does not believe a second dispatch was opened.
108
+ if (task.status === 'assigned' && args?.force !== true) {
109
+ return {
110
+ success: false,
111
+ error: `Task '${taskId}' is actively dispatched/generating; requeue refused to avoid a duplicate second dispatch. Pass force:true to override, or cancel and re-enqueue.`,
112
+ task,
113
+ };
114
+ }
115
+ return { success: true, task };
116
+ } catch (e: any) {
117
+ return { success: false, error: e.message };
118
+ }
119
+ },
120
+
121
+ trigger_mesh_queue: async (ctx: MedFamilyContext, args: any) => {
122
+ const meshId = typeof args?.meshId === 'string' ? args.meshId.trim() : '';
123
+ if (!meshId) return { success: false, error: 'meshId required' };
124
+ const ownerFailure = await ctx.requireMeshHostMutationOwner(meshId, args?.inlineMesh, 'queue trigger');
125
+ if (ownerFailure) return ownerFailure;
126
+ try {
127
+ const { triggerMeshQueue, tryAssignQueueTask } = await import('../../mesh/mesh-events.js');
128
+
129
+ // Bug A fix: when preferredNodeId is provided, attempt to claim a pending
130
+ // task for the preferred node's idle session first, before the general
131
+ // round-robin trigger picks a different node.
132
+ const preferredNodeId = typeof args?.preferredNodeId === 'string' ? args.preferredNodeId.trim() : '';
133
+ if (preferredNodeId) {
134
+ const cliInstances = ctx.deps.instanceManager.getByCategory('cli');
135
+ // Sort: preferred node's sessions first, others after
136
+ const sorted = [...cliInstances].sort((a, b) => {
137
+ const aSettings = a.getState().settings as Record<string, unknown> || {};
138
+ const bSettings = b.getState().settings as Record<string, unknown> || {};
139
+ const aNode = readStringValue(aSettings.meshNodeId, aSettings.nodeId);
140
+ const bNode = readStringValue(bSettings.meshNodeId, bSettings.nodeId);
141
+ return (aNode === preferredNodeId ? -1 : 0) - (bNode === preferredNodeId ? -1 : 0);
142
+ });
143
+ for (const inst of sorted) {
144
+ const state = inst.getState();
145
+ const settings = state.settings as Record<string, unknown> || {};
146
+ const nodeId = readStringValue(settings.meshNodeId, settings.nodeId);
147
+ if (!nodeId || nodeId !== preferredNodeId) continue;
148
+ const meshNodeFor = readStringValue(settings.meshNodeFor);
149
+ if (meshNodeFor !== meshId) continue;
150
+ const status = (readStringValue(state.status) || '').toLowerCase();
151
+ if (status !== 'idle') continue;
152
+ const sessionId = typeof state.instanceId === 'string' ? state.instanceId : '';
153
+ const providerType = readStringValue(state.type, settings.providerType) || '';
154
+ if (sessionId && providerType) {
155
+ tryAssignQueueTask(ctx.deps as any, meshId, nodeId, sessionId, providerType);
156
+ break;
157
+ }
158
+ }
159
+ }
160
+
161
+ const trigger = await triggerMeshQueue(ctx.deps as any, meshId);
162
+ return { success: true, trigger };
163
+ } catch (e: any) {
164
+ return { success: false, error: e.message };
165
+ }
166
+ },
167
+ };
@@ -0,0 +1,92 @@
1
+ /**
2
+ * RF-ROUTER MED family — coordinator-triggered daemon restart.
3
+ *
4
+ * restart_daemon_node exposes the existing dashboard "preview update" path
5
+ * (low-family daemon_upgrade: update-to-latest-on-channel + detached restart) as
6
+ * a mesh command, so a coordinator can roll a worker daemon onto a freshly
7
+ * deployed version without a manual restart round-trip. It mirrors
8
+ * fast_forward_mesh_node's remote-forward shape — resolve the target node, and
9
+ * if it belongs to a remote daemon forward the command there so the owning
10
+ * daemon (not the coordinator) restarts itself — and adds an idle-gate: a node
11
+ * with a generating / waiting_approval / starting session is refused so an
12
+ * in-flight turn is never killed mid-restart.
13
+ *
14
+ * v1 reuses daemon_upgrade verbatim rather than adding a restart-only path:
15
+ * the goal is "pick up a just-deployed version", which inherently needs the
16
+ * npm reinstall the upgrade helper already performs. Already-latest is a no-op
17
+ * (no restart), matching the dashboard button.
18
+ */
19
+ import { daemonIdsEquivalent, meshNodeIdMatches } from '@adhdev/mesh-shared';
20
+ import { daemonLifecycleHandlers } from '../low-family/daemon-lifecycle.js';
21
+ import type { CommandRouterResult } from '../router.js';
22
+ import type { MedFamilyContext, MedFamilyHandler } from './types.js';
23
+
24
+ // Session states that must block a restart: an in-flight turn or a pending
25
+ // approval would be lost when the daemon exits to re-spawn. Mirrors the
26
+ // daemon-cloud mandatory-update idle-gate (hasBlockingSessionsForMandatoryUpdate).
27
+ const RESTART_BLOCKING_STATES = new Set(['generating', 'waiting_approval', 'starting']);
28
+
29
+ function hasBlockingSessions(ctx: MedFamilyContext): boolean {
30
+ const states = ctx.deps.instanceManager.collectAllStates();
31
+ for (const state of states) {
32
+ if (RESTART_BLOCKING_STATES.has(String(state.status || ''))) return true;
33
+ const childStates = 'extensions' in state && Array.isArray((state as any).extensions)
34
+ ? (state as any).extensions
35
+ : [];
36
+ for (const child of childStates) {
37
+ if (RESTART_BLOCKING_STATES.has(String(child?.status || ''))) return true;
38
+ }
39
+ }
40
+ return false;
41
+ }
42
+
43
+ export const meshRestartHandlers: Record<string, MedFamilyHandler> = {
44
+ restart_daemon_node: async (ctx: MedFamilyContext, args: any): Promise<CommandRouterResult> => {
45
+ const meshId = typeof args?.meshId === 'string' ? args.meshId.trim() : '';
46
+ const nodeId = typeof args?.nodeId === 'string' ? args.nodeId.trim() : '';
47
+
48
+ // Resolve the target node's owning daemon so a command that lands on a
49
+ // non-owner daemon is forwarded rather than restarting the wrong daemon.
50
+ // preferInline so inline-cache-only worktree nodes still resolve.
51
+ let nodeDaemonId: string | undefined;
52
+ if (meshId && nodeId) {
53
+ const meshRecord = await ctx.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
54
+ const node = meshRecord?.mesh?.nodes?.find((n: any) => meshNodeIdMatches(n, nodeId));
55
+ nodeDaemonId = typeof node?.daemonId === 'string' ? node.daemonId.trim() : undefined;
56
+ }
57
+
58
+ const selfDaemonId = ctx.deps.statusInstanceId;
59
+ // daemonIdsEquivalent: a legacy-form daemonId resolving to this machine's
60
+ // core is local — execute here instead of forwarding (and P2P self-dial).
61
+ // Equivalent → local. _meshDirectDispatch prevents re-forwarding once the
62
+ // call has landed on the owning daemon.
63
+ const isRemote = nodeDaemonId && selfDaemonId && !daemonIdsEquivalent(nodeDaemonId, selfDaemonId);
64
+ if (isRemote && ctx.deps.dispatchMeshCommand && !args?._meshDirectDispatch) {
65
+ const forwarded = await ctx.deps.dispatchMeshCommand(nodeDaemonId!, 'restart_daemon_node', {
66
+ ...(typeof args === 'object' && args !== null ? args as Record<string, unknown> : {}),
67
+ _meshDirectDispatch: true,
68
+ });
69
+ return (forwarded ?? { success: false, error: 'no response from remote node' }) as CommandRouterResult;
70
+ }
71
+
72
+ // Idle-gate: refuse if any session on THIS daemon is mid-turn / awaiting
73
+ // approval / starting. The coordinator restarts other (idle) nodes freely;
74
+ // restarting the coordinator's OWN daemon is naturally refused while its
75
+ // calling turn is 'generating' (accepted v1 limitation — call other nodes
76
+ // first, the coordinator last when it has gone idle).
77
+ if (hasBlockingSessions(ctx)) {
78
+ return {
79
+ success: false,
80
+ restarted: false,
81
+ code: 'blocking_sessions',
82
+ reason: 'Daemon has an active session (generating / waiting_approval / starting); restart refused to avoid interrupting in-flight work. Retry when the node is idle.',
83
+ };
84
+ }
85
+
86
+ // Reuse the battle-tested dashboard "preview update" path: update to the
87
+ // latest published version on the resolved channel, then detached-restart.
88
+ // Already-latest is a no-op (no restart), matching the dashboard button.
89
+ const result = await daemonLifecycleHandlers.daemon_upgrade({ deps: ctx.deps }, args);
90
+ return { ...result, restarted: (result as any)?.restarting === true };
91
+ },
92
+ };
@@ -0,0 +1,143 @@
1
+ /**
2
+ * RF-ROUTER MED family — shared types for the extracted medium-coupling command
3
+ * handlers. Like the LOW family, each handler is a function of (context, args)
4
+ * that returns the exact CommandRouterResult the original `executeDaemonCommand`
5
+ * switch case returned, so the router facade is unchanged.
6
+ *
7
+ * Unlike the LOW family, MED handlers need a handful of router-private
8
+ * collaborators (mesh resolution, owner gating, inline-cache mutation, worktree /
9
+ * session cleanup, refine job starters, IDE launch). The router binds these onto
10
+ * MedFamilyContext at dispatch; they are NOT reachable from `deps`. The IDE family
11
+ * also needs `launchIde` to break the original `launch_ide`/`restart_*`
12
+ * self-recursion through executeDaemonCommand.
13
+ *
14
+ * Registry dispatch: DaemonCommandRouter.executeDaemonCommand looks up the cmd in
15
+ * medFamilyRegistry BEFORE its switch; a hit returns the handler result, a miss
16
+ * falls through to the remaining switch (and ultimately CommandHandler delegation).
17
+ */
18
+ import type { CommandRouterDeps, CommandRouterResult, MeshGitProbeCache } from '../router.js';
19
+ import type { RepoMeshSessionCleanupMode } from '../../repo-mesh-types.js';
20
+ import type { WorktreeBootstrapState } from '../../mesh/worktree-bootstrap-config.js';
21
+
22
+ /** Mesh record resolved from the router's inline-mesh cache + local config. */
23
+ export type ResolvedMeshForCommand = {
24
+ mesh: any;
25
+ inline: boolean;
26
+ source: 'inline_cache' | 'inline_bootstrap' | 'local_config';
27
+ } | null;
28
+
29
+ /** Result of the router's local worktree-node cleanup. */
30
+ export type CleanupLocalWorktreeNodeResult =
31
+ | { success: true; skipped?: boolean; removedPath?: string; repoRoot?: string; reason?: string; fallback?: string; forced?: boolean; convergence?: Record<string, unknown>; recovered?: boolean; residue?: boolean; residueWarning?: string; residueError?: string }
32
+ | { success: false; code: string; error: string; recoveryHint: string; convergence?: Record<string, unknown> };
33
+
34
+ /**
35
+ * Result of the non-destructive local-worktree removability precheck. `ok:false`
36
+ * carries the same refusal `code`/`error`/`recoveryHint` that the destructive
37
+ * cleanup would have returned, so callers can refuse a removal BEFORE performing
38
+ * any irreversible step (e.g. stopping/deleting delegated sessions).
39
+ */
40
+ export type WorktreeRemovalPrecheckResult =
41
+ | { ok: true }
42
+ | { ok: false; code: string; error: string; recoveryHint: string };
43
+
44
+ /**
45
+ * Router-private collaborators injected at dispatch. Each is a bound method or
46
+ * field of DaemonCommandRouter; handlers that don't need a given collaborator
47
+ * simply ignore it. The router owns this instance state (inline-mesh cache,
48
+ * aggregate-status cache, session/worktree cleanup, refine jobs), so it cannot be
49
+ * read from `deps` — the registry receives bound references instead.
50
+ */
51
+ export interface MedFamilyContext {
52
+ deps: CommandRouterDeps;
53
+
54
+ /** Bound `DaemonCommandRouter.getMeshForCommand`. */
55
+ getMeshForCommand: (
56
+ meshId: string,
57
+ inlineMesh?: unknown,
58
+ options?: { preferInline?: boolean },
59
+ ) => Promise<ResolvedMeshForCommand>;
60
+
61
+ /** Bound `DaemonCommandRouter.getCachedInlineMesh`. */
62
+ getCachedInlineMesh: (meshId: string, inlineMesh?: unknown) => any | undefined;
63
+
64
+ /** Bound `DaemonCommandRouter.requireMeshHostMutationOwner` (owner gate). */
65
+ requireMeshHostMutationOwner: (meshId: string, inlineMesh: unknown, operation: string) => Promise<CommandRouterResult | null>;
66
+
67
+ /** Bound `DaemonCommandRouter.invalidateAggregateMeshStatus`. */
68
+ invalidateAggregateMeshStatus: (meshId: string) => void;
69
+
70
+ /** Bound `DaemonCommandRouter.updateInlineMeshNode`. */
71
+ updateInlineMeshNode: (meshId: string, mesh: any, node: any) => void;
72
+
73
+ /** Bound `DaemonCommandRouter.removeInlineMeshNode`. */
74
+ removeInlineMeshNode: (meshId: string, mesh: any, nodeId: string) => boolean;
75
+
76
+ /** Bound `DaemonCommandRouter.normalizeMeshSessionCleanupMode`. */
77
+ normalizeMeshSessionCleanupMode: (value: unknown) => RepoMeshSessionCleanupMode;
78
+
79
+ /** Bound `DaemonCommandRouter.cleanupMeshSessions`. */
80
+ cleanupMeshSessions: (args: {
81
+ meshId: string;
82
+ nodeId: string;
83
+ node: any;
84
+ mode: RepoMeshSessionCleanupMode;
85
+ sessionIds?: string[];
86
+ dryRun?: boolean;
87
+ source?: 'mesh_cleanup_sessions' | 'mesh_remove_node' | 'magi_session_cleanup';
88
+ requireAutoLaunchedForTaskIds?: Record<string, string>;
89
+ }) => Promise<{ success: boolean; [key: string]: unknown }>;
90
+
91
+ /** Bound `DaemonCommandRouter.cleanupLocalWorktreeNode`. */
92
+ cleanupLocalWorktreeNode: (args: {
93
+ mesh: any;
94
+ node: any;
95
+ nodeId: string;
96
+ force?: boolean;
97
+ }) => Promise<CleanupLocalWorktreeNodeResult>;
98
+
99
+ /**
100
+ * Bound `DaemonCommandRouter.precheckLocalWorktreeRemovable` — purely
101
+ * non-destructive validation of whether a local worktree node can be removed.
102
+ * Called BEFORE session cleanup so a refusal does not orphan the session.
103
+ */
104
+ precheckLocalWorktreeRemovable: (args: {
105
+ mesh: any;
106
+ node: any;
107
+ nodeId: string;
108
+ force?: boolean;
109
+ }) => Promise<WorktreeRemovalPrecheckResult>;
110
+
111
+ /** Bound `DaemonCommandRouter.startMeshRefineJob` (async execute path). */
112
+ startMeshRefineJob: (meshId: string, nodeId: string, args: any) => Promise<CommandRouterResult>;
113
+
114
+ /** Bound `DaemonCommandRouter.batchRefineMeshNodes` (dry-run batch plan). */
115
+ batchRefineMeshNodes: (meshId: string, requestedNodeIds: string[] | undefined, args: any) => Promise<CommandRouterResult>;
116
+
117
+ /** Bound `DaemonCommandRouter.startMeshRefineBatchJob` (async batch execute). */
118
+ startMeshRefineBatchJob: (meshId: string, requestedNodeIds: string[] | undefined, args: any) => Promise<CommandRouterResult>;
119
+
120
+ /** Bound `DaemonCommandRouter.stopIde` (CDP disconnect + cleanup + optional kill). */
121
+ stopIde: (ideType: string, killProcess?: boolean) => Promise<void>;
122
+
123
+ /**
124
+ * Module-level `launchIde` helper bound to this context. The original
125
+ * `launch_ide` case body, lifted into a free function so `restart_session` /
126
+ * `restart_ide` can invoke the IDE launch directly instead of recursing
127
+ * through `executeDaemonCommand('launch_ide')` (which would re-enter the
128
+ * registry). Byte-identical to the original case body.
129
+ */
130
+ launchIde: (args: any) => Promise<CommandRouterResult>;
131
+
132
+ /** Router's inline-mesh cache (read/write of resolved mesh records). */
133
+ inlineMeshCache: Map<string, any>;
134
+
135
+ /** Router's mesh git-probe cache (reused direct-truth probes for get_mesh). */
136
+ meshGitProbeCache: MeshGitProbeCache;
137
+ }
138
+
139
+ export type MedFamilyHandler = (ctx: MedFamilyContext, args: any) => Promise<CommandRouterResult | null>;
140
+
141
+ export type MedFamilyRegistry = Map<string, MedFamilyHandler>;
142
+
143
+ export type { WorktreeBootstrapState };