@adhdev/daemon-core 0.9.82-rc.39 → 0.9.82-rc.391

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 (415) 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 +67 -2
  8. package/dist/cli-adapters/cli-script-runner.d.ts +117 -0
  9. package/dist/cli-adapters/cli-state-engine.d.ts +198 -0
  10. package/dist/cli-adapters/provider-cli-adapter.d.ts +121 -64
  11. package/dist/cli-adapters/provider-cli-parse.d.ts +4 -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 +14 -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 +2 -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 +116 -0
  54. package/dist/commands/mesh-coordinator.d.ts +85 -1
  55. package/dist/commands/router.d.ts +237 -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 +77 -1
  60. package/dist/daemon/dev-server.d.ts +0 -2
  61. package/dist/detection/ide-detector.d.ts +13 -0
  62. package/dist/detection/win32-ide-version.d.ts +37 -0
  63. package/dist/git/change-impact-config.d.ts +159 -0
  64. package/dist/git/git-commands.d.ts +11 -1
  65. package/dist/git/git-diff.d.ts +6 -0
  66. package/dist/git/git-executor.d.ts +11 -0
  67. package/dist/git/git-status.d.ts +23 -0
  68. package/dist/git/git-types.d.ts +2 -50
  69. package/dist/git/git-worktree.d.ts +22 -0
  70. package/dist/git/index.d.ts +2 -0
  71. package/dist/index.d.ts +57 -13
  72. package/dist/index.js +46318 -18260
  73. package/dist/index.js.map +1 -1
  74. package/dist/index.mjs +46450 -18533
  75. package/dist/index.mjs.map +1 -1
  76. package/dist/installer.d.ts +1 -4
  77. package/dist/ipc/local-ipc-server.d.ts +91 -0
  78. package/dist/launch.d.ts +1 -1
  79. package/dist/logging/async-batch-writer.d.ts +10 -0
  80. package/dist/logging/log-redactor.d.ts +24 -0
  81. package/dist/logging/log-tail-reader.d.ts +81 -0
  82. package/dist/logging/logger.d.ts +1 -1
  83. package/dist/mesh/contracts.d.ts +164 -0
  84. package/dist/mesh/coordinator-prompt.d.ts +89 -0
  85. package/dist/mesh/coordinator-registry.d.ts +59 -0
  86. package/dist/mesh/mesh-active-work.d.ts +174 -0
  87. package/dist/mesh/mesh-coordinator-config.d.ts +21 -0
  88. package/dist/mesh/mesh-delivery-policy.d.ts +131 -0
  89. package/dist/mesh/mesh-event-classify.d.ts +5 -0
  90. package/dist/mesh/mesh-event-forwarding.d.ts +19 -0
  91. package/dist/mesh/mesh-event-trace.d.ts +21 -0
  92. package/dist/mesh/mesh-events-coordinator.d.ts +4 -0
  93. package/dist/mesh/mesh-events-pending.d.ts +55 -0
  94. package/dist/mesh/mesh-events-stale.d.ts +52 -0
  95. package/dist/mesh/mesh-events-utils.d.ts +64 -0
  96. package/dist/mesh/mesh-events.d.ts +6 -49
  97. package/dist/mesh/mesh-fast-forward.d.ts +81 -0
  98. package/dist/mesh/mesh-host-ownership.d.ts +9 -0
  99. package/dist/mesh/mesh-init.d.ts +86 -0
  100. package/dist/mesh/mesh-ledger-reconciliation.d.ts +23 -4
  101. package/dist/mesh/mesh-ledger.d.ts +77 -1
  102. package/dist/mesh/mesh-missions.d.ts +164 -0
  103. package/dist/mesh/mesh-node-identity.d.ts +289 -0
  104. package/dist/mesh/mesh-queue-assignment.d.ts +86 -0
  105. package/dist/mesh/mesh-reconcile-loop.d.ts +65 -0
  106. package/dist/mesh/mesh-refine-batch.d.ts +68 -0
  107. package/dist/mesh/mesh-refine-gates.d.ts +428 -0
  108. package/dist/mesh/mesh-refine-status.d.ts +62 -0
  109. package/dist/mesh/mesh-review-inbox.d.ts +90 -0
  110. package/dist/mesh/mesh-routing.d.ts +70 -0
  111. package/dist/mesh/mesh-runtime-store.d.ts +447 -0
  112. package/dist/mesh/mesh-scheduling-runtime.d.ts +78 -0
  113. package/dist/mesh/mesh-task-stats.d.ts +49 -0
  114. package/dist/mesh/mesh-unresolved-forward-outbox.d.ts +30 -0
  115. package/dist/mesh/mesh-warmup-deadline.d.ts +68 -0
  116. package/dist/mesh/mesh-work-queue.d.ts +247 -5
  117. package/dist/mesh/preview-freshness.d.ts +18 -0
  118. package/dist/mesh/refine-config.d.ts +216 -0
  119. package/dist/mesh/worktree-bootstrap-config.d.ts +135 -0
  120. package/dist/providers/acp-provider-instance.d.ts +5 -0
  121. package/dist/providers/approval-utils.d.ts +20 -0
  122. package/dist/providers/chat-message-normalization.d.ts +13 -1
  123. package/dist/providers/cli-provider-instance.d.ts +157 -3
  124. package/dist/providers/contracts.d.ts +139 -6
  125. package/dist/providers/external-sources.d.ts +71 -0
  126. package/dist/providers/manual-attendance.d.ts +63 -0
  127. package/dist/providers/native-history/antigravity-cli-transcript.d.ts +100 -0
  128. package/dist/providers/native-history/claude-cli-transcript.d.ts +70 -0
  129. package/dist/providers/native-history/codex-cli-transcript.d.ts +73 -0
  130. package/dist/providers/native-history/constants.d.ts +12 -0
  131. package/dist/providers/native-history/dispatcher.d.ts +27 -0
  132. package/dist/providers/native-history/hermes-cli-transcript.d.ts +30 -0
  133. package/dist/providers/native-history/index.d.ts +13 -0
  134. package/dist/providers/provider-instance-manager.d.ts +14 -0
  135. package/dist/providers/provider-instance.d.ts +23 -1
  136. package/dist/providers/provider-loader.d.ts +26 -4
  137. package/dist/providers/provider-trust.d.ts +31 -0
  138. package/dist/providers/read-chat-contract.d.ts +29 -0
  139. package/dist/providers/sdk/v1/builders/acp/detect-status.d.ts +68 -0
  140. package/dist/providers/sdk/v1/builders/cli/detect-status.d.ts +86 -0
  141. package/dist/providers/sdk/v1/builders/cli/parse-approval-squash.d.ts +59 -0
  142. package/dist/providers/sdk/v1/builders/cli/parse-approval.d.ts +65 -0
  143. package/dist/providers/sdk/v1/builders/cli/parse-session.d.ts +91 -0
  144. package/dist/providers/sdk/v1/builders/cli/visible-region.d.ts +42 -0
  145. package/dist/providers/sdk/v1/fixture-tooling/format.d.ts +126 -0
  146. package/dist/providers/sdk/v1/fixture-tooling/index.d.ts +8 -0
  147. package/dist/providers/sdk/v1/fixture-tooling/replay.d.ts +38 -0
  148. package/dist/providers/sdk/v1/index.d.ts +30 -0
  149. package/dist/providers/sdk/v1/sandbox/README-design.d.ts +193 -0
  150. package/dist/providers/sdk/v1/sandbox/require-whitelist.d.ts +74 -0
  151. package/dist/providers/sdk/v1/sandbox/script-runner.d.ts +98 -0
  152. package/dist/providers/sdk/v1/types/cli/index.d.ts +277 -0
  153. package/dist/providers/sdk/v1/types/common/index.d.ts +203 -0
  154. package/dist/providers/sdk/v1/validators/index.d.ts +5 -0
  155. package/dist/providers/sdk/v1/validators/manifest.d.ts +40 -0
  156. package/dist/providers/sdk/v1/validators/taint.d.ts +52 -0
  157. package/dist/providers/spec/adapter.d.ts +91 -0
  158. package/dist/providers/spec/cli-adapter.d.ts +223 -0
  159. package/dist/providers/spec/evaluator.d.ts +45 -0
  160. package/dist/providers/spec/fsm-driver.d.ts +407 -0
  161. package/dist/providers/spec/fsm-evaluator.d.ts +76 -0
  162. package/dist/providers/spec/fsm-loader.d.ts +14 -0
  163. package/dist/providers/spec/fsm-types.d.ts +174 -0
  164. package/dist/providers/spec/native-history-executor.d.ts +41 -0
  165. package/dist/providers/spec/pre-launch-trust.d.ts +16 -0
  166. package/dist/providers/spec/route.d.ts +4 -0
  167. package/dist/providers/spec/types.d.ts +222 -0
  168. package/dist/providers/status-monitor.d.ts +7 -7
  169. package/dist/providers/transcript-v2.d.ts +176 -0
  170. package/dist/providers/types/interactive-prompt.d.ts +84 -0
  171. package/dist/providers/working-dir.d.ts +17 -0
  172. package/dist/repo-mesh-types.d.ts +376 -13
  173. package/dist/runtime-defaults.d.ts +2 -0
  174. package/dist/sessions/registry.d.ts +6 -0
  175. package/dist/shared-types-extra.d.ts +2 -4
  176. package/dist/shared-types.d.ts +59 -2
  177. package/dist/status/normalize.d.ts +1 -1
  178. package/dist/status/normalize.js +1 -0
  179. package/dist/status/normalize.js.map +1 -1
  180. package/dist/status/normalize.mjs +1 -0
  181. package/dist/status/normalize.mjs.map +1 -1
  182. package/dist/status/reporter.d.ts +2 -0
  183. package/dist/status/snapshot.d.ts +26 -0
  184. package/dist/system/hash.d.ts +8 -0
  185. package/dist/system/load-better-sqlite3.d.ts +21 -0
  186. package/dist/types.d.ts +5 -0
  187. package/package.json +7 -3
  188. package/src/agent-stream/poller.ts +2 -3
  189. package/src/agent-stream/provider-adapter.ts +1 -1
  190. package/src/boot/daemon-lifecycle.ts +63 -12
  191. package/src/boot/process-hardening.ts +89 -0
  192. package/src/build-info.ts +73 -0
  193. package/src/chat/source-machine.ts +534 -0
  194. package/src/chat/source-resolver.ts +0 -0
  195. package/src/chat/subscription-updates.ts +20 -1
  196. package/src/cli-adapter-types.d.ts +1 -0
  197. package/src/cli-adapter-types.ts +68 -2
  198. package/src/cli-adapters/cli-script-runner.ts +421 -0
  199. package/src/cli-adapters/cli-state-engine.ts +1221 -0
  200. package/src/cli-adapters/provider-cli-adapter.d.ts +1 -1
  201. package/src/cli-adapters/provider-cli-adapter.ts +836 -1141
  202. package/src/cli-adapters/provider-cli-parse.d.ts +1 -0
  203. package/src/cli-adapters/provider-cli-parse.ts +13 -0
  204. package/src/cli-adapters/provider-cli-runtime.ts +56 -7
  205. package/src/cli-adapters/provider-cli-shared.d.ts +4 -0
  206. package/src/cli-adapters/provider-cli-shared.ts +121 -11
  207. package/src/cli-adapters/pty-transport.ts +2 -1
  208. package/src/cli-adapters/pty-write-chunking.ts +106 -0
  209. package/src/cli-adapters/raw-terminal-io.ts +252 -0
  210. package/src/cli-adapters/resolve-executable.ts +90 -0
  211. package/src/cli-adapters/session-host-transport.ts +2 -1
  212. package/src/cli-adapters/terminal-backends/ghostty-vt-backend.ts +53 -29
  213. package/src/cli-adapters/terminal-backends/types.ts +10 -3
  214. package/src/cli-adapters/terminal-screen.ts +16 -81
  215. package/src/commands/WINDOWS-UPGRADE-LOCK-FAILURE.md +198 -0
  216. package/src/commands/chat-commands-debug-bundle.ts +398 -0
  217. package/src/commands/chat-commands-read.ts +2327 -0
  218. package/src/commands/chat-commands-scope.ts +54 -0
  219. package/src/commands/chat-commands-shared.ts +114 -0
  220. package/src/commands/chat-commands-write.ts +880 -0
  221. package/src/commands/chat-commands.ts +19 -1841
  222. package/src/commands/cli-manager.ts +513 -26
  223. package/src/commands/handler.ts +841 -2
  224. package/src/commands/high-family/index.ts +28 -0
  225. package/src/commands/high-family/mesh-coordinator-launch.ts +657 -0
  226. package/src/commands/high-family/mesh-events.ts +80 -0
  227. package/src/commands/high-family/mesh-status.ts +678 -0
  228. package/src/commands/high-family/types.ts +76 -0
  229. package/src/commands/low-family/coordinator-prompt.ts +72 -0
  230. package/src/commands/low-family/daemon-lifecycle.ts +107 -0
  231. package/src/commands/low-family/diagnostics.ts +57 -0
  232. package/src/commands/low-family/index.ts +37 -0
  233. package/src/commands/low-family/mesh-ledger.ts +62 -0
  234. package/src/commands/low-family/mesh-node-logs.ts +87 -0
  235. package/src/commands/low-family/notification.ts +116 -0
  236. package/src/commands/low-family/refine-config.ts +106 -0
  237. package/src/commands/low-family/session-host.ts +274 -0
  238. package/src/commands/low-family/spec-providerdev.ts +217 -0
  239. package/src/commands/low-family/status-meta.ts +112 -0
  240. package/src/commands/low-family/types.ts +39 -0
  241. package/src/commands/med-family/cli-agent.ts +230 -0
  242. package/src/commands/med-family/fast-forward.ts +230 -0
  243. package/src/commands/med-family/ide.ts +163 -0
  244. package/src/commands/med-family/index.ts +37 -0
  245. package/src/commands/med-family/mesh-crud.ts +836 -0
  246. package/src/commands/med-family/mesh-host-pairing.ts +234 -0
  247. package/src/commands/med-family/mesh-queue.ts +131 -0
  248. package/src/commands/med-family/mesh-restart.ts +92 -0
  249. package/src/commands/med-family/types.ts +120 -0
  250. package/src/commands/mesh-coordinator.ts +334 -124
  251. package/src/commands/router.ts +2476 -3207
  252. package/src/commands/stream-commands.ts +8 -0
  253. package/src/commands/upgrade-helper.ts +310 -45
  254. package/src/config/chat-history.ts +483 -24
  255. package/src/config/config.ts +12 -0
  256. package/src/config/mesh-config.ts +353 -22
  257. package/src/config/recent-activity.ts +8 -2
  258. package/src/daemon/dev-auto-implement.ts +3 -2
  259. package/src/daemon/dev-cli-debug.ts +10 -1
  260. package/src/daemon/dev-server.ts +0 -541
  261. package/src/detection/cli-detector.ts +28 -9
  262. package/src/detection/ide-detector.ts +55 -16
  263. package/src/detection/win32-ide-version.ts +106 -0
  264. package/src/git/change-impact-config.ts +354 -0
  265. package/src/git/git-commands.ts +55 -14
  266. package/src/git/git-diff.ts +81 -11
  267. package/src/git/git-executor.ts +12 -0
  268. package/src/git/git-status.ts +574 -43
  269. package/src/git/git-types.ts +14 -62
  270. package/src/git/git-worktree.ts +76 -1
  271. package/src/git/index.ts +16 -0
  272. package/src/index.ts +171 -12
  273. package/src/installer.d.ts +1 -1
  274. package/src/installer.ts +8 -6
  275. package/src/ipc/local-ipc-server.ts +278 -0
  276. package/src/launch.d.ts +1 -1
  277. package/src/launch.ts +37 -28
  278. package/src/logging/async-batch-writer.ts +55 -0
  279. package/src/logging/command-log.ts +7 -5
  280. package/src/logging/log-redactor.ts +100 -0
  281. package/src/logging/log-tail-reader.ts +341 -0
  282. package/src/logging/logger.ts +14 -7
  283. package/src/mesh/contracts.ts +338 -0
  284. package/src/mesh/coordinator-prompt.ts +381 -33
  285. package/src/mesh/coordinator-registry.ts +121 -0
  286. package/src/mesh/mesh-active-work.ts +645 -0
  287. package/src/mesh/mesh-coordinator-config.ts +97 -0
  288. package/src/mesh/mesh-delivery-policy.ts +315 -0
  289. package/src/mesh/mesh-event-classify.ts +51 -0
  290. package/src/mesh/mesh-event-forwarding.ts +1693 -0
  291. package/src/mesh/mesh-event-trace.ts +67 -0
  292. package/src/mesh/mesh-events-coordinator.ts +30 -0
  293. package/src/mesh/mesh-events-pending.ts +590 -0
  294. package/src/mesh/mesh-events-stale.ts +363 -0
  295. package/src/mesh/mesh-events-utils.ts +425 -0
  296. package/src/mesh/mesh-events.ts +32 -1035
  297. package/src/mesh/mesh-fast-forward.ts +839 -0
  298. package/src/mesh/mesh-host-ownership.ts +73 -0
  299. package/src/mesh/mesh-init.ts +260 -0
  300. package/src/mesh/mesh-ledger-reconciliation.ts +12 -7
  301. package/src/mesh/mesh-ledger.ts +596 -102
  302. package/src/mesh/mesh-missions.ts +322 -0
  303. package/src/mesh/mesh-node-identity.ts +1887 -0
  304. package/src/mesh/mesh-queue-assignment.ts +1491 -0
  305. package/src/mesh/mesh-reconcile-loop.ts +1527 -0
  306. package/src/mesh/mesh-refine-batch.ts +197 -0
  307. package/src/mesh/mesh-refine-gates.ts +1652 -0
  308. package/src/mesh/mesh-refine-status.ts +231 -0
  309. package/src/mesh/mesh-review-inbox.ts +307 -0
  310. package/src/mesh/mesh-routing.ts +291 -0
  311. package/src/mesh/mesh-runtime-store.ts +1795 -0
  312. package/src/mesh/mesh-scheduling-runtime.ts +199 -0
  313. package/src/mesh/mesh-task-stats.ts +161 -0
  314. package/src/mesh/mesh-unresolved-forward-outbox.ts +185 -0
  315. package/src/mesh/mesh-warmup-deadline.ts +152 -0
  316. package/src/mesh/mesh-work-queue.ts +1141 -141
  317. package/src/mesh/preview-freshness.ts +118 -0
  318. package/src/mesh/refine-config.ts +423 -0
  319. package/src/mesh/worktree-bootstrap-config.ts +331 -0
  320. package/src/providers/acp-provider-instance.ts +43 -10
  321. package/src/providers/approval-utils.d.ts +5 -0
  322. package/src/providers/approval-utils.ts +57 -5
  323. package/src/providers/chat-message-normalization.ts +46 -6
  324. package/src/providers/cli-provider-instance.ts +1552 -102
  325. package/src/providers/contracts.d.ts +55 -0
  326. package/src/providers/contracts.ts +150 -6
  327. package/src/providers/extension-provider-instance.ts +12 -7
  328. package/src/providers/external-sources.ts +218 -0
  329. package/src/providers/ide-provider-instance.ts +35 -12
  330. package/src/providers/manual-attendance.ts +85 -0
  331. package/src/providers/native-history/antigravity-cli-transcript.ts +643 -0
  332. package/src/providers/native-history/claude-cli-transcript.ts +396 -0
  333. package/src/providers/native-history/codex-cli-transcript.ts +479 -0
  334. package/src/providers/native-history/constants.ts +19 -0
  335. package/src/providers/native-history/dispatcher.ts +339 -0
  336. package/src/providers/native-history/hermes-cli-transcript.ts +230 -0
  337. package/src/providers/native-history/index.ts +30 -0
  338. package/src/providers/provider-instance-manager.ts +30 -0
  339. package/src/providers/provider-instance.ts +19 -1
  340. package/src/providers/provider-loader.ts +668 -50
  341. package/src/providers/provider-schema.ts +87 -14
  342. package/src/providers/provider-trust.ts +114 -0
  343. package/src/providers/read-chat-contract.ts +76 -16
  344. package/src/providers/sdk/README.md +49 -0
  345. package/src/providers/sdk/v1/builders/acp/detect-status.ts +144 -0
  346. package/src/providers/sdk/v1/builders/cli/detect-status.ts +313 -0
  347. package/src/providers/sdk/v1/builders/cli/parse-approval-squash.ts +158 -0
  348. package/src/providers/sdk/v1/builders/cli/parse-approval.ts +250 -0
  349. package/src/providers/sdk/v1/builders/cli/parse-session.ts +276 -0
  350. package/src/providers/sdk/v1/builders/cli/visible-region.ts +143 -0
  351. package/src/providers/sdk/v1/fixture-tooling/format.ts +130 -0
  352. package/src/providers/sdk/v1/fixture-tooling/index.ts +22 -0
  353. package/src/providers/sdk/v1/fixture-tooling/replay.ts +352 -0
  354. package/src/providers/sdk/v1/index.ts +152 -0
  355. package/src/providers/sdk/v1/sandbox/README-design.ts +195 -0
  356. package/src/providers/sdk/v1/sandbox/require-whitelist.ts +472 -0
  357. package/src/providers/sdk/v1/sandbox/script-runner.ts +150 -0
  358. package/src/providers/sdk/v1/schemas/cli/provider.schema.json +504 -0
  359. package/src/providers/sdk/v1/schemas/primitives/acp-session-protocol-v1.json +131 -0
  360. package/src/providers/sdk/v1/schemas/primitives/native-history-codex-rollout-v1.json +66 -0
  361. package/src/providers/sdk/v1/schemas/primitives/tui-approval-squash-v1.json +91 -0
  362. package/src/providers/sdk/v1/schemas/primitives/tui-assistant-block-v1.json +91 -0
  363. package/src/providers/sdk/v1/schemas/primitives/tui-cue-ordering-v1.json +47 -0
  364. package/src/providers/sdk/v1/schemas/primitives/tui-dispatch-order-v1.json +32 -0
  365. package/src/providers/sdk/v1/schemas/primitives/tui-footer-chrome-v1.json +42 -0
  366. package/src/providers/sdk/v1/schemas/primitives/tui-index-finder-v1.json +27 -0
  367. package/src/providers/sdk/v1/schemas/primitives/tui-modal-v1.json +125 -0
  368. package/src/providers/sdk/v1/schemas/primitives/tui-prompt-marker-v1.json +45 -0
  369. package/src/providers/sdk/v1/schemas/primitives/tui-session-id-extraction-v1.json +46 -0
  370. package/src/providers/sdk/v1/schemas/primitives/tui-settled-prompt-v1.json +71 -0
  371. package/src/providers/sdk/v1/schemas/primitives/tui-spinner-v1.json +83 -0
  372. package/src/providers/sdk/v1/schemas/primitives/tui-transcript-pty-v1.json +83 -0
  373. package/src/providers/sdk/v1/schemas/primitives/tui-visible-region-v1.json +57 -0
  374. package/src/providers/sdk/v1/schemas/primitives/tui-welcome-screen-v1.json +35 -0
  375. package/src/providers/sdk/v1/types/cli/index.ts +365 -0
  376. package/src/providers/sdk/v1/types/common/index.ts +229 -0
  377. package/src/providers/sdk/v1/validators/index.ts +19 -0
  378. package/src/providers/sdk/v1/validators/manifest.ts +110 -0
  379. package/src/providers/sdk/v1/validators/taint.ts +309 -0
  380. package/src/providers/spec/adapter.ts +235 -0
  381. package/src/providers/spec/cli-adapter.ts +1056 -0
  382. package/src/providers/spec/evaluator.ts +407 -0
  383. package/src/providers/spec/fsm-driver.ts +1304 -0
  384. package/src/providers/spec/fsm-evaluator.ts +272 -0
  385. package/src/providers/spec/fsm-loader.ts +120 -0
  386. package/src/providers/spec/fsm-types.ts +273 -0
  387. package/src/providers/spec/native-history-executor.ts +1128 -0
  388. package/src/providers/spec/pre-launch-trust.ts +104 -0
  389. package/src/providers/spec/route.ts +51 -0
  390. package/src/providers/spec/types.ts +262 -0
  391. package/src/providers/status-monitor.d.ts +7 -7
  392. package/src/providers/status-monitor.ts +37 -22
  393. package/src/providers/transcript-v2.ts +567 -0
  394. package/src/providers/types/interactive-prompt.ts +536 -0
  395. package/src/providers/version-archive.ts +64 -24
  396. package/src/providers/working-dir.ts +23 -0
  397. package/src/repo-mesh-types.ts +542 -14
  398. package/src/runtime-defaults.ts +39 -0
  399. package/src/sessions/registry.ts +6 -0
  400. package/src/shared-types-extra.ts +2 -4
  401. package/src/shared-types.d.ts +8 -0
  402. package/src/shared-types.ts +64 -1
  403. package/src/status/builders.ts +26 -6
  404. package/src/status/normalize.ts +2 -0
  405. package/src/status/reporter.ts +19 -1
  406. package/src/status/snapshot.ts +95 -26
  407. package/src/system/hash.ts +23 -0
  408. package/src/system/host-memory.ts +29 -12
  409. package/src/system/load-better-sqlite3.ts +68 -0
  410. package/src/types.ts +5 -0
  411. package/dist/cli-adapters/terminal-backends/xterm-backend.d.ts +0 -17
  412. package/dist/mesh/mesh-sync.d.ts +0 -53
  413. package/src/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +0 -16
  414. package/src/cli-adapters/terminal-backends/xterm-backend.ts +0 -97
  415. 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,131 @@
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 } = await import('../../mesh/mesh-work-queue.js');
71
+ const task = requeueTask(meshId, taskId, {
72
+ reason: typeof args?.reason === 'string' ? args.reason : undefined,
73
+ targetNodeId: typeof args?.targetNodeId === 'string' ? args.targetNodeId.trim() : undefined,
74
+ targetSessionId: typeof args?.targetSessionId === 'string' ? args.targetSessionId.trim() : undefined,
75
+ clearTargetNode: args?.clearTargetNode === true,
76
+ clearTargetSession: args?.clearTargetSession !== false,
77
+ });
78
+ if (!task) return { success: false, error: `Queue task '${taskId}' not found` };
79
+ return { success: true, task };
80
+ } catch (e: any) {
81
+ return { success: false, error: e.message };
82
+ }
83
+ },
84
+
85
+ trigger_mesh_queue: async (ctx: MedFamilyContext, args: any) => {
86
+ const meshId = typeof args?.meshId === 'string' ? args.meshId.trim() : '';
87
+ if (!meshId) return { success: false, error: 'meshId required' };
88
+ const ownerFailure = await ctx.requireMeshHostMutationOwner(meshId, args?.inlineMesh, 'queue trigger');
89
+ if (ownerFailure) return ownerFailure;
90
+ try {
91
+ const { triggerMeshQueue, tryAssignQueueTask } = await import('../../mesh/mesh-events.js');
92
+
93
+ // Bug A fix: when preferredNodeId is provided, attempt to claim a pending
94
+ // task for the preferred node's idle session first, before the general
95
+ // round-robin trigger picks a different node.
96
+ const preferredNodeId = typeof args?.preferredNodeId === 'string' ? args.preferredNodeId.trim() : '';
97
+ if (preferredNodeId) {
98
+ const cliInstances = ctx.deps.instanceManager.getByCategory('cli');
99
+ // Sort: preferred node's sessions first, others after
100
+ const sorted = [...cliInstances].sort((a, b) => {
101
+ const aSettings = a.getState().settings as Record<string, unknown> || {};
102
+ const bSettings = b.getState().settings as Record<string, unknown> || {};
103
+ const aNode = readStringValue(aSettings.meshNodeId, aSettings.nodeId);
104
+ const bNode = readStringValue(bSettings.meshNodeId, bSettings.nodeId);
105
+ return (aNode === preferredNodeId ? -1 : 0) - (bNode === preferredNodeId ? -1 : 0);
106
+ });
107
+ for (const inst of sorted) {
108
+ const state = inst.getState();
109
+ const settings = state.settings as Record<string, unknown> || {};
110
+ const nodeId = readStringValue(settings.meshNodeId, settings.nodeId);
111
+ if (!nodeId || nodeId !== preferredNodeId) continue;
112
+ const meshNodeFor = readStringValue(settings.meshNodeFor);
113
+ if (meshNodeFor !== meshId) continue;
114
+ const status = (readStringValue(state.status) || '').toLowerCase();
115
+ if (status !== 'idle') continue;
116
+ const sessionId = typeof state.instanceId === 'string' ? state.instanceId : '';
117
+ const providerType = readStringValue(state.type, settings.providerType) || '';
118
+ if (sessionId && providerType) {
119
+ tryAssignQueueTask(ctx.deps as any, meshId, nodeId, sessionId, providerType);
120
+ break;
121
+ }
122
+ }
123
+ }
124
+
125
+ const trigger = await triggerMeshQueue(ctx.deps as any, meshId);
126
+ return { success: true, trigger };
127
+ } catch (e: any) {
128
+ return { success: false, error: e.message };
129
+ }
130
+ },
131
+ };
@@ -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,120 @@
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
+ * Router-private collaborators injected at dispatch. Each is a bound method or
36
+ * field of DaemonCommandRouter; handlers that don't need a given collaborator
37
+ * simply ignore it. The router owns this instance state (inline-mesh cache,
38
+ * aggregate-status cache, session/worktree cleanup, refine jobs), so it cannot be
39
+ * read from `deps` — the registry receives bound references instead.
40
+ */
41
+ export interface MedFamilyContext {
42
+ deps: CommandRouterDeps;
43
+
44
+ /** Bound `DaemonCommandRouter.getMeshForCommand`. */
45
+ getMeshForCommand: (
46
+ meshId: string,
47
+ inlineMesh?: unknown,
48
+ options?: { preferInline?: boolean },
49
+ ) => Promise<ResolvedMeshForCommand>;
50
+
51
+ /** Bound `DaemonCommandRouter.getCachedInlineMesh`. */
52
+ getCachedInlineMesh: (meshId: string, inlineMesh?: unknown) => any | undefined;
53
+
54
+ /** Bound `DaemonCommandRouter.requireMeshHostMutationOwner` (owner gate). */
55
+ requireMeshHostMutationOwner: (meshId: string, inlineMesh: unknown, operation: string) => Promise<CommandRouterResult | null>;
56
+
57
+ /** Bound `DaemonCommandRouter.invalidateAggregateMeshStatus`. */
58
+ invalidateAggregateMeshStatus: (meshId: string) => void;
59
+
60
+ /** Bound `DaemonCommandRouter.updateInlineMeshNode`. */
61
+ updateInlineMeshNode: (meshId: string, mesh: any, node: any) => void;
62
+
63
+ /** Bound `DaemonCommandRouter.removeInlineMeshNode`. */
64
+ removeInlineMeshNode: (meshId: string, mesh: any, nodeId: string) => boolean;
65
+
66
+ /** Bound `DaemonCommandRouter.normalizeMeshSessionCleanupMode`. */
67
+ normalizeMeshSessionCleanupMode: (value: unknown) => RepoMeshSessionCleanupMode;
68
+
69
+ /** Bound `DaemonCommandRouter.cleanupMeshSessions`. */
70
+ cleanupMeshSessions: (args: {
71
+ meshId: string;
72
+ nodeId: string;
73
+ node: any;
74
+ mode: RepoMeshSessionCleanupMode;
75
+ sessionIds?: string[];
76
+ dryRun?: boolean;
77
+ source?: 'mesh_cleanup_sessions' | 'mesh_remove_node';
78
+ }) => Promise<{ success: boolean; [key: string]: unknown }>;
79
+
80
+ /** Bound `DaemonCommandRouter.cleanupLocalWorktreeNode`. */
81
+ cleanupLocalWorktreeNode: (args: {
82
+ mesh: any;
83
+ node: any;
84
+ nodeId: string;
85
+ force?: boolean;
86
+ }) => Promise<CleanupLocalWorktreeNodeResult>;
87
+
88
+ /** Bound `DaemonCommandRouter.startMeshRefineJob` (async execute path). */
89
+ startMeshRefineJob: (meshId: string, nodeId: string, args: any) => Promise<CommandRouterResult>;
90
+
91
+ /** Bound `DaemonCommandRouter.batchRefineMeshNodes` (dry-run batch plan). */
92
+ batchRefineMeshNodes: (meshId: string, requestedNodeIds: string[] | undefined, args: any) => Promise<CommandRouterResult>;
93
+
94
+ /** Bound `DaemonCommandRouter.startMeshRefineBatchJob` (async batch execute). */
95
+ startMeshRefineBatchJob: (meshId: string, requestedNodeIds: string[] | undefined, args: any) => Promise<CommandRouterResult>;
96
+
97
+ /** Bound `DaemonCommandRouter.stopIde` (CDP disconnect + cleanup + optional kill). */
98
+ stopIde: (ideType: string, killProcess?: boolean) => Promise<void>;
99
+
100
+ /**
101
+ * Module-level `launchIde` helper bound to this context. The original
102
+ * `launch_ide` case body, lifted into a free function so `restart_session` /
103
+ * `restart_ide` can invoke the IDE launch directly instead of recursing
104
+ * through `executeDaemonCommand('launch_ide')` (which would re-enter the
105
+ * registry). Byte-identical to the original case body.
106
+ */
107
+ launchIde: (args: any) => Promise<CommandRouterResult>;
108
+
109
+ /** Router's inline-mesh cache (read/write of resolved mesh records). */
110
+ inlineMeshCache: Map<string, any>;
111
+
112
+ /** Router's mesh git-probe cache (reused direct-truth probes for get_mesh). */
113
+ meshGitProbeCache: MeshGitProbeCache;
114
+ }
115
+
116
+ export type MedFamilyHandler = (ctx: MedFamilyContext, args: any) => Promise<CommandRouterResult | null>;
117
+
118
+ export type MedFamilyRegistry = Map<string, MedFamilyHandler>;
119
+
120
+ export type { WorktreeBootstrapState };