@adhdev/daemon-core 0.9.82-rc.41 → 0.9.82-rc.411

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 (417) 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 +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 +256 -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/config/mesh-json-config.d.ts +299 -0
  61. package/dist/daemon/dev-server.d.ts +0 -2
  62. package/dist/detection/ide-detector.d.ts +13 -0
  63. package/dist/detection/win32-ide-version.d.ts +37 -0
  64. package/dist/git/change-impact-config.d.ts +159 -0
  65. package/dist/git/git-commands.d.ts +11 -1
  66. package/dist/git/git-diff.d.ts +6 -0
  67. package/dist/git/git-executor.d.ts +11 -0
  68. package/dist/git/git-status.d.ts +57 -0
  69. package/dist/git/git-types.d.ts +2 -50
  70. package/dist/git/git-worktree.d.ts +71 -1
  71. package/dist/git/index.d.ts +3 -1
  72. package/dist/index.d.ts +57 -13
  73. package/dist/index.js +46445 -17229
  74. package/dist/index.js.map +1 -1
  75. package/dist/index.mjs +46052 -16978
  76. package/dist/index.mjs.map +1 -1
  77. package/dist/installer.d.ts +1 -4
  78. package/dist/ipc/local-ipc-server.d.ts +91 -0
  79. package/dist/launch.d.ts +1 -1
  80. package/dist/logging/async-batch-writer.d.ts +10 -0
  81. package/dist/logging/log-redactor.d.ts +24 -0
  82. package/dist/logging/log-tail-reader.d.ts +81 -0
  83. package/dist/logging/logger.d.ts +1 -1
  84. package/dist/mesh/contracts.d.ts +164 -0
  85. package/dist/mesh/coordinator-prompt.d.ts +89 -0
  86. package/dist/mesh/coordinator-registry.d.ts +59 -0
  87. package/dist/mesh/mesh-active-work.d.ts +174 -0
  88. package/dist/mesh/mesh-coordinator-config.d.ts +21 -0
  89. package/dist/mesh/mesh-delivery-policy.d.ts +131 -0
  90. package/dist/mesh/mesh-event-classify.d.ts +5 -0
  91. package/dist/mesh/mesh-event-forwarding.d.ts +19 -0
  92. package/dist/mesh/mesh-event-trace.d.ts +21 -0
  93. package/dist/mesh/mesh-events-coordinator.d.ts +4 -0
  94. package/dist/mesh/mesh-events-pending.d.ts +55 -0
  95. package/dist/mesh/mesh-events-stale.d.ts +61 -0
  96. package/dist/mesh/mesh-events-utils.d.ts +75 -0
  97. package/dist/mesh/mesh-events.d.ts +6 -49
  98. package/dist/mesh/mesh-fast-forward.d.ts +81 -0
  99. package/dist/mesh/mesh-host-ownership.d.ts +9 -0
  100. package/dist/mesh/mesh-init.d.ts +86 -0
  101. package/dist/mesh/mesh-ledger-reconciliation.d.ts +23 -4
  102. package/dist/mesh/mesh-ledger.d.ts +77 -1
  103. package/dist/mesh/mesh-missions.d.ts +164 -0
  104. package/dist/mesh/mesh-node-identity.d.ts +289 -0
  105. package/dist/mesh/mesh-queue-assignment.d.ts +95 -0
  106. package/dist/mesh/mesh-reconcile-loop.d.ts +65 -0
  107. package/dist/mesh/mesh-refine-batch.d.ts +68 -0
  108. package/dist/mesh/mesh-refine-gates.d.ts +428 -0
  109. package/dist/mesh/mesh-refine-status.d.ts +62 -0
  110. package/dist/mesh/mesh-review-inbox.d.ts +90 -0
  111. package/dist/mesh/mesh-routing.d.ts +70 -0
  112. package/dist/mesh/mesh-runtime-store.d.ts +447 -0
  113. package/dist/mesh/mesh-scheduling-runtime.d.ts +78 -0
  114. package/dist/mesh/mesh-task-stats.d.ts +49 -0
  115. package/dist/mesh/mesh-unresolved-forward-outbox.d.ts +30 -0
  116. package/dist/mesh/mesh-warmup-deadline.d.ts +68 -0
  117. package/dist/mesh/mesh-work-queue.d.ts +281 -5
  118. package/dist/mesh/preview-freshness.d.ts +18 -0
  119. package/dist/mesh/refine-config.d.ts +216 -0
  120. package/dist/mesh/worktree-bootstrap-config.d.ts +145 -0
  121. package/dist/providers/acp-provider-instance.d.ts +5 -0
  122. package/dist/providers/approval-utils.d.ts +20 -0
  123. package/dist/providers/chat-message-normalization.d.ts +31 -1
  124. package/dist/providers/cli-provider-instance.d.ts +197 -3
  125. package/dist/providers/contracts.d.ts +139 -6
  126. package/dist/providers/external-sources.d.ts +71 -0
  127. package/dist/providers/manual-attendance.d.ts +63 -0
  128. package/dist/providers/native-history/antigravity-cli-transcript.d.ts +100 -0
  129. package/dist/providers/native-history/claude-cli-transcript.d.ts +70 -0
  130. package/dist/providers/native-history/codex-cli-transcript.d.ts +73 -0
  131. package/dist/providers/native-history/constants.d.ts +12 -0
  132. package/dist/providers/native-history/dispatcher.d.ts +27 -0
  133. package/dist/providers/native-history/hermes-cli-transcript.d.ts +30 -0
  134. package/dist/providers/native-history/index.d.ts +13 -0
  135. package/dist/providers/provider-instance-manager.d.ts +14 -0
  136. package/dist/providers/provider-instance.d.ts +23 -1
  137. package/dist/providers/provider-loader.d.ts +26 -4
  138. package/dist/providers/provider-trust.d.ts +31 -0
  139. package/dist/providers/read-chat-contract.d.ts +29 -0
  140. package/dist/providers/sdk/v1/builders/acp/detect-status.d.ts +68 -0
  141. package/dist/providers/sdk/v1/builders/cli/detect-status.d.ts +86 -0
  142. package/dist/providers/sdk/v1/builders/cli/parse-approval-squash.d.ts +59 -0
  143. package/dist/providers/sdk/v1/builders/cli/parse-approval.d.ts +65 -0
  144. package/dist/providers/sdk/v1/builders/cli/parse-session.d.ts +91 -0
  145. package/dist/providers/sdk/v1/builders/cli/visible-region.d.ts +42 -0
  146. package/dist/providers/sdk/v1/fixture-tooling/format.d.ts +126 -0
  147. package/dist/providers/sdk/v1/fixture-tooling/index.d.ts +8 -0
  148. package/dist/providers/sdk/v1/fixture-tooling/replay.d.ts +38 -0
  149. package/dist/providers/sdk/v1/index.d.ts +30 -0
  150. package/dist/providers/sdk/v1/sandbox/README-design.d.ts +193 -0
  151. package/dist/providers/sdk/v1/sandbox/require-whitelist.d.ts +74 -0
  152. package/dist/providers/sdk/v1/sandbox/script-runner.d.ts +98 -0
  153. package/dist/providers/sdk/v1/types/cli/index.d.ts +277 -0
  154. package/dist/providers/sdk/v1/types/common/index.d.ts +203 -0
  155. package/dist/providers/sdk/v1/validators/index.d.ts +5 -0
  156. package/dist/providers/sdk/v1/validators/manifest.d.ts +40 -0
  157. package/dist/providers/sdk/v1/validators/taint.d.ts +52 -0
  158. package/dist/providers/spec/adapter.d.ts +91 -0
  159. package/dist/providers/spec/cli-adapter.d.ts +223 -0
  160. package/dist/providers/spec/evaluator.d.ts +45 -0
  161. package/dist/providers/spec/fsm-driver.d.ts +407 -0
  162. package/dist/providers/spec/fsm-evaluator.d.ts +76 -0
  163. package/dist/providers/spec/fsm-loader.d.ts +14 -0
  164. package/dist/providers/spec/fsm-types.d.ts +174 -0
  165. package/dist/providers/spec/native-history-executor.d.ts +41 -0
  166. package/dist/providers/spec/pre-launch-trust.d.ts +16 -0
  167. package/dist/providers/spec/route.d.ts +4 -0
  168. package/dist/providers/spec/types.d.ts +222 -0
  169. package/dist/providers/status-monitor.d.ts +7 -7
  170. package/dist/providers/transcript-v2.d.ts +176 -0
  171. package/dist/providers/types/interactive-prompt.d.ts +84 -0
  172. package/dist/providers/working-dir.d.ts +17 -0
  173. package/dist/repo-mesh-types.d.ts +420 -13
  174. package/dist/runtime-defaults.d.ts +2 -0
  175. package/dist/sessions/registry.d.ts +6 -0
  176. package/dist/shared-types-extra.d.ts +2 -4
  177. package/dist/shared-types.d.ts +59 -2
  178. package/dist/status/normalize.d.ts +1 -1
  179. package/dist/status/normalize.js +1 -0
  180. package/dist/status/normalize.js.map +1 -1
  181. package/dist/status/normalize.mjs +1 -0
  182. package/dist/status/normalize.mjs.map +1 -1
  183. package/dist/status/reporter.d.ts +2 -0
  184. package/dist/status/snapshot.d.ts +26 -0
  185. package/dist/system/hash.d.ts +8 -0
  186. package/dist/system/load-better-sqlite3.d.ts +21 -0
  187. package/dist/types.d.ts +5 -0
  188. package/package.json +7 -3
  189. package/src/agent-stream/poller.ts +2 -3
  190. package/src/agent-stream/provider-adapter.ts +1 -1
  191. package/src/boot/daemon-lifecycle.ts +63 -12
  192. package/src/boot/process-hardening.ts +89 -0
  193. package/src/build-info.ts +73 -0
  194. package/src/chat/source-machine.ts +534 -0
  195. package/src/chat/source-resolver.ts +0 -0
  196. package/src/chat/subscription-updates.ts +20 -1
  197. package/src/cli-adapter-types.d.ts +3 -1
  198. package/src/cli-adapter-types.ts +68 -2
  199. package/src/cli-adapters/cli-script-runner.ts +421 -0
  200. package/src/cli-adapters/cli-state-engine.ts +1246 -0
  201. package/src/cli-adapters/provider-cli-adapter.d.ts +1 -1
  202. package/src/cli-adapters/provider-cli-adapter.ts +914 -1144
  203. package/src/cli-adapters/provider-cli-parse.d.ts +2 -0
  204. package/src/cli-adapters/provider-cli-parse.ts +19 -0
  205. package/src/cli-adapters/provider-cli-runtime.ts +56 -7
  206. package/src/cli-adapters/provider-cli-shared.d.ts +4 -0
  207. package/src/cli-adapters/provider-cli-shared.ts +121 -11
  208. package/src/cli-adapters/pty-transport.ts +2 -1
  209. package/src/cli-adapters/pty-write-chunking.ts +106 -0
  210. package/src/cli-adapters/raw-terminal-io.ts +252 -0
  211. package/src/cli-adapters/resolve-executable.ts +90 -0
  212. package/src/cli-adapters/session-host-transport.ts +2 -1
  213. package/src/cli-adapters/terminal-backends/ghostty-vt-backend.ts +63 -29
  214. package/src/cli-adapters/terminal-backends/types.ts +10 -3
  215. package/src/cli-adapters/terminal-screen.ts +16 -81
  216. package/src/commands/WINDOWS-UPGRADE-LOCK-FAILURE.md +198 -0
  217. package/src/commands/chat-commands-debug-bundle.ts +398 -0
  218. package/src/commands/chat-commands-read.ts +2327 -0
  219. package/src/commands/chat-commands-scope.ts +54 -0
  220. package/src/commands/chat-commands-shared.ts +114 -0
  221. package/src/commands/chat-commands-write.ts +891 -0
  222. package/src/commands/chat-commands.ts +19 -1841
  223. package/src/commands/cli-manager.ts +527 -26
  224. package/src/commands/handler.ts +841 -2
  225. package/src/commands/high-family/index.ts +28 -0
  226. package/src/commands/high-family/mesh-coordinator-launch.ts +673 -0
  227. package/src/commands/high-family/mesh-events.ts +80 -0
  228. package/src/commands/high-family/mesh-status.ts +678 -0
  229. package/src/commands/high-family/types.ts +76 -0
  230. package/src/commands/low-family/coordinator-prompt.ts +72 -0
  231. package/src/commands/low-family/daemon-lifecycle.ts +107 -0
  232. package/src/commands/low-family/diagnostics.ts +57 -0
  233. package/src/commands/low-family/index.ts +37 -0
  234. package/src/commands/low-family/mesh-ledger.ts +62 -0
  235. package/src/commands/low-family/mesh-node-logs.ts +87 -0
  236. package/src/commands/low-family/notification.ts +116 -0
  237. package/src/commands/low-family/refine-config.ts +106 -0
  238. package/src/commands/low-family/session-host.ts +274 -0
  239. package/src/commands/low-family/spec-providerdev.ts +217 -0
  240. package/src/commands/low-family/status-meta.ts +112 -0
  241. package/src/commands/low-family/types.ts +39 -0
  242. package/src/commands/med-family/cli-agent.ts +238 -0
  243. package/src/commands/med-family/fast-forward.ts +230 -0
  244. package/src/commands/med-family/ide.ts +163 -0
  245. package/src/commands/med-family/index.ts +37 -0
  246. package/src/commands/med-family/mesh-crud.ts +874 -0
  247. package/src/commands/med-family/mesh-host-pairing.ts +234 -0
  248. package/src/commands/med-family/mesh-queue.ts +131 -0
  249. package/src/commands/med-family/mesh-restart.ts +92 -0
  250. package/src/commands/med-family/types.ts +120 -0
  251. package/src/commands/mesh-coordinator.ts +334 -124
  252. package/src/commands/router.ts +2516 -3221
  253. package/src/commands/stream-commands.ts +8 -0
  254. package/src/commands/upgrade-helper.ts +310 -45
  255. package/src/config/chat-history.ts +483 -24
  256. package/src/config/config.ts +12 -0
  257. package/src/config/mesh-config.ts +353 -22
  258. package/src/config/mesh-json-config.ts +617 -0
  259. package/src/config/recent-activity.ts +8 -2
  260. package/src/daemon/dev-auto-implement.ts +3 -2
  261. package/src/daemon/dev-cli-debug.ts +10 -1
  262. package/src/daemon/dev-server.ts +0 -541
  263. package/src/detection/cli-detector.ts +28 -9
  264. package/src/detection/ide-detector.ts +55 -16
  265. package/src/detection/win32-ide-version.ts +106 -0
  266. package/src/git/change-impact-config.ts +354 -0
  267. package/src/git/git-commands.ts +59 -15
  268. package/src/git/git-diff.ts +81 -11
  269. package/src/git/git-executor.ts +12 -0
  270. package/src/git/git-status.ts +767 -48
  271. package/src/git/git-types.ts +14 -62
  272. package/src/git/git-worktree.ts +261 -4
  273. package/src/git/index.ts +17 -0
  274. package/src/index.ts +171 -12
  275. package/src/installer.d.ts +1 -1
  276. package/src/installer.ts +8 -6
  277. package/src/ipc/local-ipc-server.ts +278 -0
  278. package/src/launch.d.ts +1 -1
  279. package/src/launch.ts +37 -28
  280. package/src/logging/async-batch-writer.ts +55 -0
  281. package/src/logging/command-log.ts +7 -5
  282. package/src/logging/log-redactor.ts +100 -0
  283. package/src/logging/log-tail-reader.ts +341 -0
  284. package/src/logging/logger.ts +14 -7
  285. package/src/mesh/contracts.ts +338 -0
  286. package/src/mesh/coordinator-prompt.ts +381 -33
  287. package/src/mesh/coordinator-registry.ts +121 -0
  288. package/src/mesh/mesh-active-work.ts +645 -0
  289. package/src/mesh/mesh-coordinator-config.ts +97 -0
  290. package/src/mesh/mesh-delivery-policy.ts +315 -0
  291. package/src/mesh/mesh-event-classify.ts +51 -0
  292. package/src/mesh/mesh-event-forwarding.ts +1773 -0
  293. package/src/mesh/mesh-event-trace.ts +67 -0
  294. package/src/mesh/mesh-events-coordinator.ts +31 -0
  295. package/src/mesh/mesh-events-pending.ts +590 -0
  296. package/src/mesh/mesh-events-stale.ts +389 -0
  297. package/src/mesh/mesh-events-utils.ts +443 -0
  298. package/src/mesh/mesh-events.ts +32 -1035
  299. package/src/mesh/mesh-fast-forward.ts +843 -0
  300. package/src/mesh/mesh-host-ownership.ts +73 -0
  301. package/src/mesh/mesh-init.ts +260 -0
  302. package/src/mesh/mesh-ledger-reconciliation.ts +12 -7
  303. package/src/mesh/mesh-ledger.ts +596 -102
  304. package/src/mesh/mesh-missions.ts +322 -0
  305. package/src/mesh/mesh-node-identity.ts +1887 -0
  306. package/src/mesh/mesh-queue-assignment.ts +1738 -0
  307. package/src/mesh/mesh-reconcile-loop.ts +1726 -0
  308. package/src/mesh/mesh-refine-batch.ts +205 -0
  309. package/src/mesh/mesh-refine-gates.ts +1666 -0
  310. package/src/mesh/mesh-refine-status.ts +231 -0
  311. package/src/mesh/mesh-review-inbox.ts +307 -0
  312. package/src/mesh/mesh-routing.ts +291 -0
  313. package/src/mesh/mesh-runtime-store.ts +1836 -0
  314. package/src/mesh/mesh-scheduling-runtime.ts +198 -0
  315. package/src/mesh/mesh-task-stats.ts +161 -0
  316. package/src/mesh/mesh-unresolved-forward-outbox.ts +185 -0
  317. package/src/mesh/mesh-warmup-deadline.ts +152 -0
  318. package/src/mesh/mesh-work-queue.ts +1205 -141
  319. package/src/mesh/preview-freshness.ts +118 -0
  320. package/src/mesh/refine-config.ts +423 -0
  321. package/src/mesh/worktree-bootstrap-config.ts +369 -0
  322. package/src/providers/acp-provider-instance.ts +43 -10
  323. package/src/providers/approval-utils.d.ts +5 -0
  324. package/src/providers/approval-utils.ts +57 -5
  325. package/src/providers/chat-message-normalization.ts +92 -4
  326. package/src/providers/cli-provider-instance.ts +1865 -104
  327. package/src/providers/contracts.d.ts +55 -0
  328. package/src/providers/contracts.ts +150 -6
  329. package/src/providers/extension-provider-instance.ts +12 -7
  330. package/src/providers/external-sources.ts +218 -0
  331. package/src/providers/ide-provider-instance.ts +35 -12
  332. package/src/providers/manual-attendance.ts +85 -0
  333. package/src/providers/native-history/antigravity-cli-transcript.ts +643 -0
  334. package/src/providers/native-history/claude-cli-transcript.ts +396 -0
  335. package/src/providers/native-history/codex-cli-transcript.ts +479 -0
  336. package/src/providers/native-history/constants.ts +19 -0
  337. package/src/providers/native-history/dispatcher.ts +339 -0
  338. package/src/providers/native-history/hermes-cli-transcript.ts +230 -0
  339. package/src/providers/native-history/index.ts +30 -0
  340. package/src/providers/provider-instance-manager.ts +30 -0
  341. package/src/providers/provider-instance.ts +19 -1
  342. package/src/providers/provider-loader.ts +668 -50
  343. package/src/providers/provider-schema.ts +87 -14
  344. package/src/providers/provider-trust.ts +114 -0
  345. package/src/providers/read-chat-contract.ts +76 -16
  346. package/src/providers/sdk/README.md +49 -0
  347. package/src/providers/sdk/v1/builders/acp/detect-status.ts +144 -0
  348. package/src/providers/sdk/v1/builders/cli/detect-status.ts +313 -0
  349. package/src/providers/sdk/v1/builders/cli/parse-approval-squash.ts +158 -0
  350. package/src/providers/sdk/v1/builders/cli/parse-approval.ts +250 -0
  351. package/src/providers/sdk/v1/builders/cli/parse-session.ts +276 -0
  352. package/src/providers/sdk/v1/builders/cli/visible-region.ts +143 -0
  353. package/src/providers/sdk/v1/fixture-tooling/format.ts +130 -0
  354. package/src/providers/sdk/v1/fixture-tooling/index.ts +22 -0
  355. package/src/providers/sdk/v1/fixture-tooling/replay.ts +352 -0
  356. package/src/providers/sdk/v1/index.ts +152 -0
  357. package/src/providers/sdk/v1/sandbox/README-design.ts +195 -0
  358. package/src/providers/sdk/v1/sandbox/require-whitelist.ts +472 -0
  359. package/src/providers/sdk/v1/sandbox/script-runner.ts +150 -0
  360. package/src/providers/sdk/v1/schemas/cli/provider.schema.json +504 -0
  361. package/src/providers/sdk/v1/schemas/primitives/acp-session-protocol-v1.json +131 -0
  362. package/src/providers/sdk/v1/schemas/primitives/native-history-codex-rollout-v1.json +66 -0
  363. package/src/providers/sdk/v1/schemas/primitives/tui-approval-squash-v1.json +91 -0
  364. package/src/providers/sdk/v1/schemas/primitives/tui-assistant-block-v1.json +91 -0
  365. package/src/providers/sdk/v1/schemas/primitives/tui-cue-ordering-v1.json +47 -0
  366. package/src/providers/sdk/v1/schemas/primitives/tui-dispatch-order-v1.json +32 -0
  367. package/src/providers/sdk/v1/schemas/primitives/tui-footer-chrome-v1.json +42 -0
  368. package/src/providers/sdk/v1/schemas/primitives/tui-index-finder-v1.json +27 -0
  369. package/src/providers/sdk/v1/schemas/primitives/tui-modal-v1.json +125 -0
  370. package/src/providers/sdk/v1/schemas/primitives/tui-prompt-marker-v1.json +45 -0
  371. package/src/providers/sdk/v1/schemas/primitives/tui-session-id-extraction-v1.json +46 -0
  372. package/src/providers/sdk/v1/schemas/primitives/tui-settled-prompt-v1.json +71 -0
  373. package/src/providers/sdk/v1/schemas/primitives/tui-spinner-v1.json +83 -0
  374. package/src/providers/sdk/v1/schemas/primitives/tui-transcript-pty-v1.json +83 -0
  375. package/src/providers/sdk/v1/schemas/primitives/tui-visible-region-v1.json +57 -0
  376. package/src/providers/sdk/v1/schemas/primitives/tui-welcome-screen-v1.json +35 -0
  377. package/src/providers/sdk/v1/types/cli/index.ts +365 -0
  378. package/src/providers/sdk/v1/types/common/index.ts +229 -0
  379. package/src/providers/sdk/v1/validators/index.ts +19 -0
  380. package/src/providers/sdk/v1/validators/manifest.ts +110 -0
  381. package/src/providers/sdk/v1/validators/taint.ts +309 -0
  382. package/src/providers/spec/adapter.ts +235 -0
  383. package/src/providers/spec/cli-adapter.ts +1056 -0
  384. package/src/providers/spec/evaluator.ts +407 -0
  385. package/src/providers/spec/fsm-driver.ts +1304 -0
  386. package/src/providers/spec/fsm-evaluator.ts +272 -0
  387. package/src/providers/spec/fsm-loader.ts +120 -0
  388. package/src/providers/spec/fsm-types.ts +273 -0
  389. package/src/providers/spec/native-history-executor.ts +1128 -0
  390. package/src/providers/spec/pre-launch-trust.ts +104 -0
  391. package/src/providers/spec/route.ts +51 -0
  392. package/src/providers/spec/types.ts +262 -0
  393. package/src/providers/status-monitor.d.ts +7 -7
  394. package/src/providers/status-monitor.ts +37 -22
  395. package/src/providers/transcript-v2.ts +567 -0
  396. package/src/providers/types/interactive-prompt.ts +536 -0
  397. package/src/providers/version-archive.ts +64 -24
  398. package/src/providers/working-dir.ts +23 -0
  399. package/src/repo-mesh-types.ts +629 -14
  400. package/src/runtime-defaults.ts +39 -0
  401. package/src/sessions/registry.ts +6 -0
  402. package/src/shared-types-extra.ts +2 -4
  403. package/src/shared-types.d.ts +8 -0
  404. package/src/shared-types.ts +64 -1
  405. package/src/status/builders.ts +26 -6
  406. package/src/status/normalize.ts +2 -0
  407. package/src/status/reporter.ts +19 -1
  408. package/src/status/snapshot.ts +95 -26
  409. package/src/system/hash.ts +23 -0
  410. package/src/system/host-memory.ts +29 -12
  411. package/src/system/load-better-sqlite3.ts +68 -0
  412. package/src/types.ts +5 -0
  413. package/dist/cli-adapters/terminal-backends/xterm-backend.d.ts +0 -17
  414. package/dist/mesh/mesh-sync.d.ts +0 -53
  415. package/src/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +0 -16
  416. package/src/cli-adapters/terminal-backends/xterm-backend.ts +0 -97
  417. package/src/mesh/mesh-sync.ts +0 -111
@@ -18,13 +18,15 @@ import { loadConfig } from '../config/config.js';
18
18
  import { loadState, saveState } from '../config/state-store.js';
19
19
  import { getWorkspaceState, resolveLaunchDirectory } from '../config/workspaces.js';
20
20
  import { appendRecentActivity } from '../config/recent-activity.js';
21
+ import { shortHash } from '../system/hash.js';
22
+ import { unregisterMeshCoordinator, getCoordinatorForSession, listCoordinatorsForWorkspace } from '../mesh/coordinator-registry.js';
21
23
  import { upsertSavedProviderSession } from '../config/saved-sessions.js';
22
24
  import { buildLegacyModelModeSummaryMetadata, normalizeProviderSummaryMetadata } from '../providers/summary-metadata.js';
23
25
  import { CliProviderInstance } from '../providers/cli-provider-instance.js';
24
26
  import { AcpProviderInstance } from '../providers/acp-provider-instance.js';
25
27
  import type { ProviderInstanceManager } from '../providers/provider-instance-manager.js';
26
28
  import { ProviderLoader } from '../providers/provider-loader.js';
27
- import { normalizeInputEnvelope, type ProviderModule, type ProviderResumeCapability } from '../providers/contracts.js';
29
+ import { normalizeInputEnvelope, type MeshCoordinatorDelegatedWorkerIsolation, type ProviderModule, type ProviderResumeCapability } from '../providers/contracts.js';
28
30
  import { assertProviderSupportsDeclaredInput, assertTextOnlyInput } from '../providers/provider-input-support.js';
29
31
  import type { CliAdapter } from '../cli-adapter-types.js';
30
32
  import type { PtyTransportFactory } from '../cli-adapters/pty-transport.js';
@@ -80,6 +82,126 @@ export interface CliManagerDeps {
80
82
 
81
83
  type CommandResult = { success: boolean;[key: string]: unknown };
82
84
 
85
+ const BUSY_AGENT_STATUSES = new Set(['generating', 'running', 'streaming', 'starting', 'busy', 'waiting', 'waiting_approval', 'no_progress', 'long_generating']);
86
+ const ZERO_MESSAGE_STARTING_SEND_WAIT_MS = 2_000;
87
+
88
+ function normalizeAgentStatus(value: unknown): string {
89
+ return typeof value === 'string' ? value.trim().toLowerCase() : '';
90
+ }
91
+
92
+ function hasNonEmptyModalButtons(activeModal: unknown): boolean {
93
+ const buttons = (activeModal as any)?.buttons;
94
+ return Array.isArray(buttons) && buttons.some((button) => String(button || '').trim().length > 0);
95
+ }
96
+
97
+ function hasAdapterPendingResponse(adapter: any): boolean {
98
+ if (adapter?.isWaitingForResponse === true) return true;
99
+ if (adapter?.currentTurnScope) return true;
100
+ try {
101
+ if (typeof adapter?.isProcessing === 'function' && adapter.isProcessing()) return true;
102
+ } catch { /* defensive: send guard should not fail on diagnostics */ }
103
+ try {
104
+ const partial = typeof adapter?.getPartialResponse === 'function' ? adapter.getPartialResponse() : '';
105
+ if (typeof partial === 'string' && partial.trim()) return true;
106
+ } catch { /* defensive: missing partial means no pending evidence */ }
107
+ return false;
108
+ }
109
+
110
+ function countMessages(value: unknown): number {
111
+ return Array.isArray(value) ? value.length : 0;
112
+ }
113
+
114
+ function hasFinalAssistantMessage(value: unknown): boolean {
115
+ const messages = Array.isArray(value) ? value : [];
116
+ const last = messages[messages.length - 1] as any;
117
+ if (!last || last.role !== 'assistant') return false;
118
+ if (last.bubbleState === 'streaming') return false;
119
+ if (last.meta?.streaming === true) return false;
120
+ return typeof last.content === 'string' && last.content.trim().length > 0;
121
+ }
122
+
123
+ function hasZeroMessageStartingLaunch(adapter: any): boolean {
124
+ const adapterStatus = adapter?.getStatus?.({ allowParse: false }) ?? adapter?.getStatus?.() ?? {};
125
+ const parsedStatus = typeof adapter?.getScriptParsedStatus === 'function'
126
+ ? adapter.getScriptParsedStatus()
127
+ : {};
128
+ const adapterRawStatus = normalizeAgentStatus(adapterStatus?.status);
129
+ const parsedRawStatus = normalizeAgentStatus(parsedStatus?.status);
130
+ if (adapterRawStatus !== 'starting') return false;
131
+ if (parsedRawStatus && parsedRawStatus !== 'starting' && parsedRawStatus !== 'generating') return false;
132
+ if (hasNonEmptyModalButtons(adapterStatus?.activeModal ?? adapterStatus?.modal ?? parsedStatus?.activeModal ?? parsedStatus?.modal)) return false;
133
+ if (countMessages(adapterStatus?.messages) > 0 || countMessages(parsedStatus?.messages) > 0) return false;
134
+ return !hasAdapterPendingResponse(adapter);
135
+ }
136
+
137
+ function hasCompletedStartingLaunch(adapter: any): boolean {
138
+ const adapterStatus = adapter?.getStatus?.({ allowParse: false }) ?? adapter?.getStatus?.() ?? {};
139
+ const adapterRawStatus = normalizeAgentStatus(adapterStatus?.status);
140
+ if (adapterRawStatus !== 'starting') return false;
141
+ if (hasAdapterPendingResponse(adapter)) return false;
142
+
143
+ const parsedStatus = typeof adapter?.getScriptParsedStatus === 'function'
144
+ ? adapter.getScriptParsedStatus()
145
+ : {};
146
+ const parsedRawStatus = normalizeAgentStatus(parsedStatus?.status);
147
+ if (parsedRawStatus !== 'idle') return false;
148
+ if (hasNonEmptyModalButtons(adapterStatus?.activeModal ?? adapterStatus?.modal ?? parsedStatus?.activeModal ?? parsedStatus?.modal)) return false;
149
+ return hasFinalAssistantMessage(parsedStatus?.messages);
150
+ }
151
+
152
+ /**
153
+ * WTCLAIM (B): compare two workspace paths for node scoping. Normalizes separator
154
+ * style, trailing slashes, and case (Windows paths are case-insensitive; the
155
+ * coordinator-supplied node.workspace and the adapter's launch workingDir can
156
+ * differ only in those) so a base node and a worktree clone are still told apart
157
+ * by their distinct workspace roots.
158
+ */
159
+ function normalizeDirForCompare(dir?: string): string {
160
+ if (typeof dir !== 'string') return '';
161
+ return dir.trim().replace(/[\\/]+/g, '/').replace(/\/+$/, '').toLowerCase();
162
+ }
163
+
164
+ function shouldSuppressStaleParsedBusyStatus(adapterStatus: string, parsedStatus: any, adapter: any): boolean {
165
+ const parsedRawStatus = normalizeAgentStatus(parsedStatus?.status);
166
+ if (!BUSY_AGENT_STATUSES.has(parsedRawStatus)) return false;
167
+ if (adapterStatus !== 'idle') return false;
168
+ if (hasNonEmptyModalButtons(parsedStatus?.activeModal ?? parsedStatus?.modal)) return false;
169
+ return !hasAdapterPendingResponse(adapter);
170
+ }
171
+
172
+ function getEffectiveAgentSendStatus(adapter: any): string {
173
+ const adapterStatus = normalizeAgentStatus(adapter?.getStatus?.({ allowParse: false })?.status ?? adapter?.getStatus?.()?.status);
174
+ if (adapterStatus === 'starting' && hasCompletedStartingLaunch(adapter)) return 'idle';
175
+ if (adapterStatus && adapterStatus !== 'idle') return adapterStatus;
176
+ if (adapterStatus !== 'idle') return adapterStatus;
177
+
178
+ if (typeof adapter?.getScriptParsedStatus !== 'function') return adapterStatus;
179
+ try {
180
+ const parsedStatus = adapter.getScriptParsedStatus();
181
+ const parsedRawStatus = normalizeAgentStatus(parsedStatus?.status);
182
+ if (BUSY_AGENT_STATUSES.has(parsedRawStatus) && !shouldSuppressStaleParsedBusyStatus(adapterStatus, parsedStatus, adapter)) {
183
+ return parsedRawStatus;
184
+ }
185
+ } catch {
186
+ return adapterStatus;
187
+ }
188
+ return adapterStatus;
189
+ }
190
+
191
+ async function waitForZeroMessageStartingLaunch(adapter: any): Promise<boolean> {
192
+ try {
193
+ if (!hasZeroMessageStartingLaunch(adapter)) return false;
194
+ } catch {
195
+ return false;
196
+ }
197
+ await new Promise(resolve => setTimeout(resolve, ZERO_MESSAGE_STARTING_SEND_WAIT_MS));
198
+ try {
199
+ return hasZeroMessageStartingLaunch(adapter);
200
+ } catch {
201
+ return false;
202
+ }
203
+ }
204
+
83
205
  export interface CliTransportFactoryParams {
84
206
  runtimeId: string;
85
207
  providerType: string;
@@ -138,18 +260,19 @@ type CliStartOptions = {
138
260
  extraEnv?: Record<string, string>;
139
261
  };
140
262
 
141
- const COORDINATOR_DELEGATED_ENV_UNSETS: Record<string, string> = {
142
- ADHDEV_INLINE_MESH: '',
143
- ADHDEV_MCP_TRANSPORT: '',
144
- ADHDEV_MESH_ID: '',
145
- HERMES_EPHEMERAL_SYSTEM_PROMPT: '',
146
- };
263
+ const DEFAULT_COORDINATOR_DELEGATED_ENV_UNSETS = [
264
+ 'ADHDEV_INLINE_MESH',
265
+ 'ADHDEV_MCP_TRANSPORT',
266
+ 'ADHDEV_MESH_ID',
267
+ 'HERMES_EPHEMERAL_SYSTEM_PROMPT',
268
+ ] as const;
147
269
 
148
270
  export interface CoordinatorDelegatedCliLaunchOptionsInput {
149
271
  cliType: string;
150
272
  workspace: string;
151
273
  cliArgs?: string[];
152
274
  env?: Record<string, string>;
275
+ isolation?: MeshCoordinatorDelegatedWorkerIsolation;
153
276
  }
154
277
 
155
278
  export interface CoordinatorDelegatedCliLaunchOptions {
@@ -161,10 +284,25 @@ function hasCliArg(args: string[], flag: string): boolean {
161
284
  return args.some((arg) => arg === flag || arg.startsWith(`${flag}=`));
162
285
  }
163
286
 
287
+ function hasConfigOverride(args: string[], key: string): boolean {
288
+ for (let index = 0; index < args.length; index += 1) {
289
+ const arg = args[index];
290
+ const next = args[index + 1];
291
+ if ((arg === '-c' || arg === '--config') && typeof next === 'string') {
292
+ if (next === key || next.startsWith(`${key}=`) || next.startsWith(`${key}.`)) return true;
293
+ }
294
+ if (arg.startsWith('--config=')) {
295
+ const value = arg.slice('--config='.length);
296
+ if (value === key || value.startsWith(`${key}=`) || value.startsWith(`${key}.`)) return true;
297
+ }
298
+ }
299
+ return false;
300
+ }
301
+
164
302
  function ensureEmptyDelegatedMcpConfig(workspace: string): string {
165
303
  const baseDir = path.join(os.tmpdir(), 'adhdev-delegated-agent-empty-mcp');
166
304
  mkdirSync(baseDir, { recursive: true });
167
- const workspaceHash = crypto.createHash('sha256').update(path.resolve(workspace || os.tmpdir())).digest('hex').slice(0, 16);
305
+ const workspaceHash = shortHash(path.resolve(workspace || os.tmpdir()));
168
306
  const filePath = path.join(baseDir, `${workspaceHash}.json`);
169
307
  writeFileSync(filePath, JSON.stringify({ mcpServers: {} }, null, 2), 'utf-8');
170
308
  return filePath;
@@ -173,12 +311,31 @@ function ensureEmptyDelegatedMcpConfig(workspace: string): string {
173
311
  export function buildCoordinatorDelegatedCliLaunchOptions(
174
312
  input: CoordinatorDelegatedCliLaunchOptionsInput,
175
313
  ): CoordinatorDelegatedCliLaunchOptions {
176
- const cliType = String(input.cliType || '').trim();
177
314
  const cliArgs = Array.isArray(input.cliArgs) ? [...input.cliArgs] : [];
178
- const env: Record<string, string> = { ...(input.env || {}), ...COORDINATOR_DELEGATED_ENV_UNSETS };
315
+ const env: Record<string, string> = { ...(input.env || {}) };
316
+ const envUnsets = new Set<string>(DEFAULT_COORDINATOR_DELEGATED_ENV_UNSETS);
317
+ for (const key of input.isolation?.env?.unset || []) {
318
+ if (typeof key === 'string' && key.trim()) envUnsets.add(key.trim());
319
+ }
320
+ for (const key of envUnsets) env[key] = '';
179
321
 
180
- if (cliType === 'claude-cli' && !hasCliArg(cliArgs, '--mcp-config')) {
181
- cliArgs.unshift('--mcp-config', ensureEmptyDelegatedMcpConfig(input.workspace));
322
+ for (const rule of input.isolation?.args || []) {
323
+ if (!rule || typeof rule !== 'object') continue;
324
+ if (rule.mode === 'empty_mcp_config') {
325
+ if (rule.flag && !hasCliArg(cliArgs, rule.flag)) {
326
+ cliArgs.unshift(rule.flag, ensureEmptyDelegatedMcpConfig(input.workspace));
327
+ }
328
+ if (rule.strictFlag && !hasCliArg(cliArgs, rule.strictFlag)) {
329
+ cliArgs.unshift(rule.strictFlag);
330
+ }
331
+ continue;
332
+ }
333
+ if (rule.mode === 'config_override') {
334
+ const key = String(rule.dedupeKey || rule.key || '').trim();
335
+ const flag = String(rule.flag || '').trim();
336
+ if (!key || !flag || hasConfigOverride(cliArgs, key)) continue;
337
+ cliArgs.unshift(flag, `${rule.key}=${rule.value}`);
338
+ }
182
339
  }
183
340
 
184
341
  return { cliArgs, env };
@@ -255,10 +412,14 @@ function detectExplicitProviderSessionId(
255
412
 
256
413
  const subcommands = resume?.sessionIdFromSubcommand;
257
414
  if (Array.isArray(subcommands) && subcommands.length > 0) {
415
+ const hasResumeSubcommand = args.some((arg) => subcommands.includes(arg));
258
416
  const subcommandSessionId = readSubcommandSessionId(args, subcommands);
259
417
  if (subcommandSessionId) {
260
418
  return { providerSessionId: subcommandSessionId, launchMode: 'resume' };
261
419
  }
420
+ if (hasResumeSubcommand) {
421
+ return { launchMode: 'resume' };
422
+ }
262
423
  }
263
424
 
264
425
  return { launchMode: 'manual' };
@@ -292,6 +453,12 @@ export function resolveCliSessionBinding(
292
453
  launchMode: explicit.launchMode,
293
454
  };
294
455
  }
456
+ if (explicit.launchMode === 'resume') {
457
+ return {
458
+ cliArgs: baseArgs,
459
+ launchMode: 'resume',
460
+ };
461
+ }
295
462
  if (explicit.launchMode === 'manual' && hasArg(baseArgs || [], ['--session-id'])) {
296
463
  return {
297
464
  cliArgs: baseArgs,
@@ -435,7 +602,9 @@ export class DaemonCliManager {
435
602
  providerSessionId,
436
603
  attachExisting,
437
604
  );
438
- return new ProviderCliAdapter(resolvedProvider as CliProviderModule, workingDir, cliArgs, extraEnv || {}, transportFactory);
605
+ const adapter = new ProviderCliAdapter(resolvedProvider as CliProviderModule, workingDir, cliArgs, extraEnv || {}, transportFactory);
606
+ if (providerSessionId) adapter.updateRuntimeMeta({ providerSessionId });
607
+ return adapter;
439
608
  }
440
609
 
441
610
  throw new Error(`No CLI provider found for '${cliType}'. Create a provider.js in providers/cli/${cliType}/`);
@@ -457,6 +626,7 @@ export class DaemonCliManager {
457
626
  this.deps.removeAgentTracking(key);
458
627
  sessionRegistry?.unregisterByInstanceKey(key);
459
628
  instanceManager?.removeInstance(key);
629
+ unregisterMeshCoordinator(key);
460
630
  LOG.info('CLI', `🧹 Auto-cleaned ${status.status} CLI: ${cliType}`);
461
631
  this.deps.onStatusChange();
462
632
  }
@@ -516,6 +686,18 @@ export class DaemonCliManager {
516
686
  transport: 'pty',
517
687
  adapterKey: key,
518
688
  instanceKey: key,
689
+ workspace: resolvedDir,
690
+ // attachExisting === true means we're restoring an already-spawned
691
+ // hosted runtime after a daemon restart, not starting a fresh PTY.
692
+ // The real spawn time is in the past and we don't have it on the
693
+ // restored descriptor; pinning spawnedAtMs to Date.now() in that
694
+ // case would push the native-history session-floor cutoff past
695
+ // every existing transcript file, so the agy/hermes/claude reader
696
+ // would return null even though the transcript on disk is fresh.
697
+ // 0 disables the floor for this session — recent_window_ms in the
698
+ // spec still bounds how far back we look. Fresh launches still
699
+ // get a proper floor so prior-session leak protection holds.
700
+ spawnedAtMs: attachExisting ? 0 : Date.now(),
519
701
  });
520
702
  } catch (spawnErr: any) {
521
703
  LOG.error('CLI', `[${cliType}] Spawn failed: ${spawnErr?.message}`);
@@ -524,6 +706,28 @@ export class DaemonCliManager {
524
706
  }
525
707
 
526
708
  this.adapters.set(key, cliInstance.getAdapter());
709
+
710
+ // WTDISPATCH (no_node_binding): a coordinator-launched worker carries its mesh node
711
+ // binding on the CLI-instance settings, but the session-host RECORD meta was never
712
+ // stamped with it — `updateRuntimeSettings` only mutates in-memory runtime settings and
713
+ // `updateRuntimeMeta` was only ever called with providerSessionId. So mesh_cleanup_sessions
714
+ // matched these worker sessions to a node by workspace ALONE
715
+ // (`live_session_matched_by_workspace_only_no_node_binding`), which on a daemon hosting
716
+ // sibling worktree nodes cannot tell two co-located clones apart. Push the launch-time node
717
+ // binding to the record meta so the record is 1:1 bound to its node (the spawned pty exists
718
+ // by now, so updateMeta reaches the session-host store). Best-effort; guarded.
719
+ const launchMeshNodeId = typeof settings?.meshNodeId === 'string' ? settings.meshNodeId.trim() : '';
720
+ const launchMeshNodeFor = typeof settings?.meshNodeFor === 'string' ? settings.meshNodeFor.trim() : '';
721
+ if (launchMeshNodeId || launchMeshNodeFor) {
722
+ try {
723
+ cliInstance.getAdapter().updateRuntimeMeta?.({
724
+ ...(launchMeshNodeId ? { meshNodeId: launchMeshNodeId } : {}),
725
+ ...(launchMeshNodeFor ? { meshNodeFor: launchMeshNodeFor } : {}),
726
+ ...(settings?.launchedByCoordinator === true ? { launchedByCoordinator: true } : {}),
727
+ });
728
+ } catch { /* best-effort — record-meta stamp is cleanup hygiene, not on the dispatch path */ }
729
+ }
730
+
527
731
  this.startCliExitMonitor(key, cliType);
528
732
  }
529
733
 
@@ -556,6 +760,24 @@ export class DaemonCliManager {
556
760
 
557
761
  // Create UUID-based key (allows separate instances even for same type+dir)
558
762
  const key = crypto.randomUUID();
763
+
764
+ // (3) Session-anchored mesh routing: when launching a mesh COORDINATOR session
765
+ // (settings.meshCoordinatorFor set), expose this session's OWN runtime id to its MCP
766
+ // server via env. The MCP server is spawned by the CLI as a child and inherits this
767
+ // env, so the MCP layer can stamp ADHDEV_COORDINATOR_SESSION_ID as the originating
768
+ // coordinator on every dispatch (→ MeshContext.coordinatorSessionId → worker
769
+ // meshCoordinatorSessionId → completion targetCoordinatorSessionId → strict route).
770
+ // `key` IS the instance id findLiveCoordinators matches on, so the stamp and the live
771
+ // session agree. Re-applied on every (re)launch, so it always reflects the current id;
772
+ // a stale value only survives if the CLI process outlives a daemon restart, in which
773
+ // case routing falls back to the daemon level (no wedge — see mesh-reconcile-loop).
774
+ {
775
+ const coordinatorMeshId = (options?.settingsOverride as Record<string, unknown> | undefined)?.meshCoordinatorFor;
776
+ if (typeof coordinatorMeshId === 'string' && coordinatorMeshId.trim()) {
777
+ options = { ...options, extraEnv: { ...(options?.extraEnv || {}), ADHDEV_COORDINATOR_SESSION_ID: key } };
778
+ }
779
+ }
780
+
559
781
  const sessionRegistry = this.deps.getSessionRegistry?.() || null;
560
782
 
561
783
  // ─── ACP category handle ───
@@ -589,6 +811,7 @@ export class DaemonCliManager {
589
811
  transport: 'acp',
590
812
  adapterKey: key,
591
813
  instanceKey: key,
814
+ workspace: resolvedDir,
592
815
  });
593
816
 
594
817
  // Register ACP entry in adapter map (getStatus queries from acpInstance in real-time)
@@ -783,6 +1006,7 @@ export class DaemonCliManager {
783
1006
  this.deps.removeAgentTracking(key);
784
1007
  this.deps.getSessionRegistry?.()?.unregisterByInstanceKey(key);
785
1008
  this.deps.getInstanceManager()?.removeInstance(key);
1009
+ unregisterMeshCoordinator(key);
786
1010
  LOG.info('CLI', `🛑 Agent stopped: ${adapter.cliType} in ${adapter.workingDir}`);
787
1011
  this.deps.onStatusChange();
788
1012
  } else {
@@ -792,6 +1016,7 @@ export class DaemonCliManager {
792
1016
  this.deps.getSessionRegistry?.()?.unregisterByInstanceKey(key);
793
1017
  im.removeInstance(key);
794
1018
  this.deps.removeAgentTracking(key);
1019
+ unregisterMeshCoordinator(key);
795
1020
  LOG.warn('CLI', `🧹 Force-removed orphan entry: ${key}`);
796
1021
  this.deps.onStatusChange();
797
1022
  }
@@ -819,6 +1044,29 @@ export class DaemonCliManager {
819
1044
  const restoredBindings = new Set<string>();
820
1045
  const managerTag = this.deps.hostedRuntimeManagerTag;
821
1046
 
1047
+ // CORDBADGE worker-overbind guard pre-pass: the workspace-scoped coordinator
1048
+ // rebind fallback (below) recovers a coordinator's mark when its runtimeId
1049
+ // changed across restart. But a delegated WORKER session that shares the
1050
+ // coordinator's workspace+cliType ALSO misses the exact by-id lookup, so the
1051
+ // fallback would wrongly stamp it with the lone registered coordinator's mesh
1052
+ // mark (the reported bug: a worker shown with role:coordinator after restart).
1053
+ // Two batch-level signals let the fallback refuse to mark a worker:
1054
+ // - restoredRuntimeIds: every runtimeId in this restore batch. If a
1055
+ // registered coordinator's own sessionId appears here, that coordinator is
1056
+ // being restored under its known id (the exact match binds it), so ANY
1057
+ // other same-workspace session is a worker — not the renamed coordinator.
1058
+ // - workspaceTypeCounts: how many sessions in the batch share a
1059
+ // workspace+cliType. >1 means we cannot tell the coordinator from a worker
1060
+ // even if the coordinator's id changed, so we stay unbound (ambiguous).
1061
+ const restoredRuntimeIds = new Set<string>();
1062
+ const workspaceTypeCounts = new Map<string, number>();
1063
+ for (const r of sessions) {
1064
+ if (!r?.runtimeId || !r?.cliType || !r?.workspace) continue;
1065
+ restoredRuntimeIds.add(r.runtimeId);
1066
+ const key = `${r.workspace}::${r.cliType}`;
1067
+ workspaceTypeCounts.set(key, (workspaceTypeCounts.get(key) || 0) + 1);
1068
+ }
1069
+
822
1070
  for (const record of sessions) {
823
1071
  if (!record?.runtimeId || !record?.cliType || !record?.workspace) continue;
824
1072
  if (!shouldRestoreHostedRuntime(record, managerTag)) {
@@ -852,6 +1100,74 @@ export class DaemonCliManager {
852
1100
  );
853
1101
  continue;
854
1102
  }
1103
+ // Re-establish the launch-time settings a fresh launch applies. startSession
1104
+ // seeds every new instance with { ...providerLoader.getSettings(type), ...override };
1105
+ // passing a bare {} here on restart silently dropped TWO launch settings, so a
1106
+ // restored session diverged from a freshly-launched one:
1107
+ // - autoApprove (a provider/machine setting from getSettings) → a restored
1108
+ // coordinator self-session lost auto-approve and re-prompted on every tool call.
1109
+ // - meshCoordinatorFor (the coordinator launch's settingsOverride) → the restored
1110
+ // session was no longer recognized as this daemon's live CLI coordinator by
1111
+ // findLiveCoordinators (so pending mesh events stopped draining into its PTY) nor
1112
+ // surfaced with the coordinator badge via settings. The persisted coordinator
1113
+ // registry (loaded on boot) is the source of truth to rebuild that mark.
1114
+ // Both restores are provider-agnostic — getSettings is keyed by provider type and the
1115
+ // registry mark is type-independent.
1116
+ const restoredSettings: Record<string, any> = { ...this.providerLoader.getSettings(normalizedType) };
1117
+ // Primary rebind: exact persisted-registry match by runtimeId (stable across
1118
+ // restart, see session-host runtimeId = runtimeRecord.sessionId).
1119
+ let coordinatorEntry = getCoordinatorForSession(record.runtimeId);
1120
+ // CORDBADGE fallback: the by-id match misses when a coordinator's runtime
1121
+ // re-attaches under a different runtimeId than the one it was registered with
1122
+ // (the registry survived, but its key no longer lines up). Without a rebind the
1123
+ // restored session silently loses meshCoordinatorFor → the coordinator badge and
1124
+ // selfIdentification block vanish and pending mesh events stop draining into its
1125
+ // PTY, and the only recovery is a manual coordinator restart. Recover the mark
1126
+ // from the persisted registry scoped to this exact workspace, but ONLY when it is
1127
+ // UNAMBIGUOUS: exactly one registered coordinator for this workspace AND its
1128
+ // cliType matches the restored session's type.
1129
+ //
1130
+ // WORKER-OVERBIND guard: "exactly one registered coordinator" is NOT enough —
1131
+ // a delegated worker session sharing the coordinator's workspace+cliType also
1132
+ // misses the by-id lookup, and the registry holding only the (single) real
1133
+ // coordinator does NOT stop the fallback from projecting that coordinator's
1134
+ // mark onto the worker record. So before adopting the mark we positively rule
1135
+ // the worker out:
1136
+ // (a) coordinatorPresentById — the registered coordinator's own sessionId is
1137
+ // in this restore batch, i.e. it is being restored under its known id and
1138
+ // the exact match already binds it. Then THIS record (which missed) is a
1139
+ // worker, not the renamed coordinator → do not rebind.
1140
+ // (b) siblingCount > 1 — more than one session shares this workspace+cliType,
1141
+ // so even if the coordinator's id changed we cannot tell it from a worker
1142
+ // → stay unbound (ambiguous).
1143
+ // Anything ambiguous stays unbound (we would rather miss a badge than
1144
+ // mis-attribute one).
1145
+ if (!coordinatorEntry?.meshId && record.workspace) {
1146
+ const workspaceCoordinators = listCoordinatorsForWorkspace(record.workspace)
1147
+ .filter(e => e.meshId && (!e.cliType || e.cliType === record.cliType));
1148
+ if (workspaceCoordinators.length === 1) {
1149
+ const candidate = workspaceCoordinators[0];
1150
+ const coordinatorPresentById = !!candidate.sessionId && restoredRuntimeIds.has(candidate.sessionId);
1151
+ const siblingCount = workspaceTypeCounts.get(`${record.workspace}::${record.cliType}`) || 1;
1152
+ if (!coordinatorPresentById && siblingCount === 1) {
1153
+ coordinatorEntry = candidate;
1154
+ LOG.info(
1155
+ 'CLI',
1156
+ `↻ Rebound coordinator mark by workspace for ${record.runtimeKey || record.runtimeId} (mesh ${candidate.meshId} @ ${record.workspace}); registry key did not match runtimeId`
1157
+ );
1158
+ } else {
1159
+ LOG.info(
1160
+ 'CLI',
1161
+ `↷ Skipping workspace coordinator rebind for ${record.runtimeKey || record.runtimeId} (${record.cliType} @ ${record.workspace}): ${coordinatorPresentById
1162
+ ? 'registered coordinator is restoring under its own id — this is a delegated worker'
1163
+ : `ambiguous (${siblingCount} sessions share this workspace+cliType)`}`
1164
+ );
1165
+ }
1166
+ }
1167
+ }
1168
+ if (coordinatorEntry?.meshId) {
1169
+ restoredSettings.meshCoordinatorFor = coordinatorEntry.meshId;
1170
+ }
855
1171
  try {
856
1172
  await this.registerCliInstance(
857
1173
  record.runtimeId,
@@ -860,7 +1176,7 @@ export class DaemonCliManager {
860
1176
  record.workspace,
861
1177
  record.cliArgs,
862
1178
  resolvedProvider,
863
- {},
1179
+ restoredSettings,
864
1180
  true,
865
1181
  {
866
1182
  providerSessionId: sessionBinding.providerSessionId,
@@ -899,18 +1215,36 @@ export class DaemonCliManager {
899
1215
  const adapter = this.adapters.get(ik);
900
1216
  if (adapter) return { adapter, key: ik };
901
1217
  }
902
- // 1. agentType + dir match
903
- if (opts?.dir) {
1218
+ // 1. agentType + dir match.
1219
+ // FAIL-CLOSED when an explicit instanceKey/targetSessionId was named (step 0) but
1220
+ // did not resolve: the caller pinned a SPECIFIC session, so healing by workspace must
1221
+ // not silently redirect the command into a co-located SIBLING worktree session. The
1222
+ // remote mesh relay (ipcDispatchToRemoteAgent) carries `dir: node.workspace` alongside
1223
+ // targetSessionId for the sessionless-scope case; when a session WAS named, that dir
1224
+ // fallback is the WTDISPATCH-FANOUT (a) leak — a stale/relaunched session_id would
1225
+ // dir-match whatever session lives in that workspace instead of failing. The sessionless
1226
+ // node-scoped path uses findMeshNodeAdapter, not this fallback, so gating dir on
1227
+ // !instanceKey loses no legitimate routing. Mirror step 2's fail-closed rule.
1228
+ if (opts?.dir && !opts?.instanceKey) {
904
1229
  for (const [k, a] of this.adapters) {
905
1230
  if (a.cliType === agentType && a.workingDir === opts.dir) {
906
1231
  return { adapter: a, key: k };
907
1232
  }
908
1233
  }
909
1234
  }
910
- // 2. Fuzzy match (returns first of multiple sessions — may be inaccurate)
911
- for (const [k, a] of this.adapters) {
912
- if (a.cliType === agentType) {
913
- return { adapter: a, key: k };
1235
+ // 2. Fuzzy match (returns first of multiple sessions — may be inaccurate).
1236
+ // FAIL-CLOSED: only when NO explicit instanceKey/targetSessionId was requested.
1237
+ // When a specific session WAS named (step 0) but is not hosted on this daemon,
1238
+ // falling back to the first same-cliType adapter silently redirects the command
1239
+ // into an UNRELATED session — e.g. a relayed/misrouted mesh send_chat lands in the
1240
+ // coordinator's own CLI session, echoing the dispatched task body back to the
1241
+ // coordinator (TASKECHO self-inject). Returning null instead makes the caller
1242
+ // surface an explicit "not running" error rather than mis-delivering the message.
1243
+ if (!opts?.instanceKey) {
1244
+ for (const [k, a] of this.adapters) {
1245
+ if (a.cliType === agentType) {
1246
+ return { adapter: a, key: k };
1247
+ }
914
1248
  }
915
1249
  }
916
1250
  return null;
@@ -925,6 +1259,40 @@ export class DaemonCliManager {
925
1259
  return adapter ? { adapter, key: ik } : null;
926
1260
  }
927
1261
 
1262
+ /**
1263
+ * WTCLAIM (B): resolve the adapter for a mesh dispatch that named a node
1264
+ * (meshContext.nodeId) but carried no explicit session. Matches by the
1265
+ * instance's bound mesh node id (settings.meshNodeId, falling back to the
1266
+ * sticky meshLastNodeId) first, then by the node workspace (workingDir).
1267
+ *
1268
+ * Unlike findAdapter's step-2 fuzzy fallback, this NEVER degrades to a
1269
+ * provider-only first-match: on a daemon hosting BOTH a base node and a
1270
+ * cloned worktree node (same daemonId), that fuzzy match could land a
1271
+ * worktree-targeted task on the base session. Returns null when no session
1272
+ * is bound to this node so the caller fails closed.
1273
+ */
1274
+ private findMeshNodeAdapter(agentType: string, nodeId: string, dir?: string): { adapter: CliAdapter; key: string } | null {
1275
+ const instanceManager = this.deps.getInstanceManager();
1276
+ const targetDir = normalizeDirForCompare(dir);
1277
+ let workspaceMatch: { adapter: CliAdapter; key: string } | null = null;
1278
+ for (const [k, a] of this.adapters) {
1279
+ if (a.cliType !== agentType) continue;
1280
+ const settings = (instanceManager?.getInstance(k) as any)?.getState?.()?.settings as Record<string, unknown> | undefined;
1281
+ const boundNodeId = (typeof settings?.meshNodeId === 'string' && settings.meshNodeId.trim())
1282
+ ? settings.meshNodeId.trim()
1283
+ : (typeof settings?.meshLastNodeId === 'string' ? settings.meshLastNodeId.trim() : '');
1284
+ // Exact node binding wins immediately (most precise).
1285
+ if (boundNodeId && boundNodeId === nodeId) return { adapter: a, key: k };
1286
+ // Workspace identity is the secondary signal for a session not (yet)
1287
+ // stamped with a node id — a base node and a worktree clone always have
1288
+ // distinct workspaces, so this still separates them.
1289
+ if (!workspaceMatch && targetDir && normalizeDirForCompare(a.workingDir) === targetDir) {
1290
+ workspaceMatch = { adapter: a, key: k };
1291
+ }
1292
+ }
1293
+ return workspaceMatch;
1294
+ }
1295
+
928
1296
  // ─── CLI command handling ────────────────────────────
929
1297
 
930
1298
  async handleCliCommand(cmd: string, args: any): Promise<CommandResult | null> {
@@ -955,6 +1323,8 @@ export class DaemonCliManager {
955
1323
  const launchSource = resolved.source;
956
1324
  if (!cliType) throw new Error('cliType required');
957
1325
 
1326
+ const providerType = this.providerLoader.resolveAlias(cliType);
1327
+ const provLookup = this.providerLoader.getMeta(providerType) as ProviderModule | undefined;
958
1328
  const settingsOverride = args?.settings && typeof args.settings === 'object' ? args.settings : undefined;
959
1329
  const delegatedLaunch = settingsOverride?.launchedByCoordinator === true
960
1330
  ? buildCoordinatorDelegatedCliLaunchOptions({
@@ -962,8 +1332,28 @@ export class DaemonCliManager {
962
1332
  workspace: dir,
963
1333
  cliArgs: args?.cliArgs,
964
1334
  env: args?.env,
1335
+ isolation: provLookup?.meshCoordinator?.delegatedWorkerIsolation,
965
1336
  })
966
1337
  : null;
1338
+ // Untrusted-provider gate: an external source that ships JS
1339
+ // hooks needs explicit user confirmation before its first
1340
+ // launch. Dashboards add `confirmExternalUntrusted: true` to
1341
+ // the launch args after showing the trust modal. Without
1342
+ // that ack we refuse to spawn and tell the caller why.
1343
+ const provMeta = provLookup as any;
1344
+ const provTrust = provMeta?._sourceTrust;
1345
+ if (provTrust === 'external-untrusted' && args?.confirmExternalUntrusted !== true) {
1346
+ return {
1347
+ success: false,
1348
+ error: 'untrusted_external_provider',
1349
+ provider: {
1350
+ type: provLookup?.type ?? cliType,
1351
+ sourceName: provMeta?._sourceName ?? null,
1352
+ trust: provTrust,
1353
+ },
1354
+ hint: 'Resend launch_cli with confirmExternalUntrusted=true after the user explicitly approves running JavaScript from this 3rd-party source.',
1355
+ };
1356
+ }
967
1357
  const started = await this.startSession(
968
1358
  cliType,
969
1359
  dir,
@@ -1030,6 +1420,45 @@ export class DaemonCliManager {
1030
1420
  this.deps.onStatusChange();
1031
1421
  return { success: true, id: found.key, mode };
1032
1422
  }
1423
+ case 'record_provider_pty': {
1424
+ const cliType = args?.type || args?.cliType;
1425
+ if (!cliType) {
1426
+ return { success: false, error: '`type` (provider type) is required', code: 'MISSING_TYPE' };
1427
+ }
1428
+ const targetSessionId = typeof args?.targetSessionId === 'string' ? args.targetSessionId : '';
1429
+ const dir = args?.dir || '';
1430
+ const found = (targetSessionId ? this.findAdapterBySessionId(targetSessionId) : null)
1431
+ || this.findAdapter(cliType, { instanceKey: targetSessionId, dir });
1432
+ if (!found) {
1433
+ return {
1434
+ success: false,
1435
+ error: `No running ${cliType} session. Launch one first (adhdev launch ${cliType}) or pass --target-session-id.`,
1436
+ code: 'NO_RUNNING_SESSION',
1437
+ };
1438
+ }
1439
+ const instance = this.deps.getInstanceManager()?.getInstance(found.key);
1440
+ if (!(instance instanceof CliProviderInstance)) {
1441
+ return { success: false, error: 'CLI instance not available', code: 'CLI_INSTANCE_NOT_FOUND' };
1442
+ }
1443
+ const adapter = instance.getAdapter();
1444
+ if (!adapter || typeof (adapter as any).getAccumulatedRawBuffer !== 'function') {
1445
+ return { success: false, error: 'Adapter does not expose PTY buffer', code: 'ADAPTER_NOT_RECORDABLE' };
1446
+ }
1447
+ const buffer = (adapter as any).getAccumulatedRawBuffer() as { text: string; droppedChars: number };
1448
+ const maxBytes = Number(args?.maxBytes) > 0 ? Number(args.maxBytes) : 262144;
1449
+ const truncated = buffer.text.length > maxBytes;
1450
+ const ptyBytes = truncated ? buffer.text.slice(-maxBytes) : buffer.text;
1451
+ return {
1452
+ success: true,
1453
+ cliType,
1454
+ sessionId: found.key,
1455
+ ptyBytes,
1456
+ bytes: ptyBytes.length,
1457
+ truncated,
1458
+ droppedChars: buffer.droppedChars,
1459
+ capturedAt: Date.now(),
1460
+ };
1461
+ }
1033
1462
  case 'restart_session': {
1034
1463
  const cliType = args?.cliType || args?.agentType || args?.ideType;
1035
1464
  const cfg = loadConfig();
@@ -1065,14 +1494,56 @@ export class DaemonCliManager {
1065
1494
  const action = args?.action;
1066
1495
  if (!agentType || !action) throw new Error('agentType and action required');
1067
1496
 
1068
- const found = this.findAdapter(agentType, {
1069
- dir: args?.dir,
1070
- instanceKey: args?.targetSessionId,
1071
- });
1497
+ // WTCLAIM (B): a mesh dispatch that named a node (meshContext.nodeId)
1498
+ // but resolved no explicit session must be scoped to THAT node's
1499
+ // session — never routed by findAdapter's provider-only fuzzy fallback,
1500
+ // which on a daemon hosting both a base node and a cloned worktree node
1501
+ // (same daemonId) could land a worktree task on the base session. Fail
1502
+ // closed when no session is bound to the node so the coordinator
1503
+ // launches/retries instead of mis-landing the work.
1504
+ const meshScopeNodeId = (() => {
1505
+ const mc = (args as any)?.meshContext;
1506
+ return mc && typeof mc === 'object' && typeof mc.nodeId === 'string' ? mc.nodeId.trim() : '';
1507
+ })();
1508
+ let found: { adapter: CliAdapter; key: string } | null;
1509
+ if (meshScopeNodeId && !args?.targetSessionId) {
1510
+ found = this.findMeshNodeAdapter(agentType, meshScopeNodeId, args?.dir);
1511
+ if (!found) {
1512
+ throw new Error(`No mesh worker session bound to node '${meshScopeNodeId}' for agent '${agentType}' on this daemon; refusing provider-only fuzzy match to avoid cross-node dispatch`);
1513
+ }
1514
+ } else {
1515
+ found = this.findAdapter(agentType, {
1516
+ dir: args?.dir,
1517
+ instanceKey: args?.targetSessionId,
1518
+ });
1519
+ }
1072
1520
  if (!found) throw new Error(`CLI agent not running: ${agentType}`);
1073
1521
  const { adapter, key } = found;
1074
1522
 
1075
1523
  if (action === 'send_chat') {
1524
+ let currentStatus = getEffectiveAgentSendStatus(adapter);
1525
+ if (currentStatus === 'starting' && await waitForZeroMessageStartingLaunch(adapter)) {
1526
+ currentStatus = 'idle';
1527
+ } else if (currentStatus === 'starting') {
1528
+ currentStatus = getEffectiveAgentSendStatus(adapter);
1529
+ }
1530
+ // Stamp mesh direct-dispatch assignment on the target
1531
+ // instance BEFORE sending the prompt so the completion
1532
+ // event has a routing marker by the time it fires.
1533
+ // mesh_send_task --direct ships meshContext for plain CLI
1534
+ // sessions that were never launched as mesh delegates.
1535
+ const meshContext = (args as any)?.meshContext;
1536
+ if (meshContext && typeof meshContext === 'object' && typeof meshContext.meshId === 'string' && meshContext.meshId) {
1537
+ const targetInstanceId = key;
1538
+ try {
1539
+ this.deps.getInstanceManager()?.attachMeshAssignmentToInstance(targetInstanceId, {
1540
+ meshId: meshContext.meshId,
1541
+ ...(typeof meshContext.nodeId === 'string' && meshContext.nodeId ? { nodeId: meshContext.nodeId } : {}),
1542
+ ...(typeof meshContext.taskId === 'string' && meshContext.taskId ? { taskId: meshContext.taskId } : {}),
1543
+ ...(typeof meshContext.coordinatorDaemonId === 'string' && meshContext.coordinatorDaemonId ? { coordinatorDaemonId: meshContext.coordinatorDaemonId } : {}),
1544
+ });
1545
+ } catch { /* best-effort */ }
1546
+ }
1076
1547
  const input = normalizeInputEnvelope(args?.input ? { input: args.input } : args);
1077
1548
  const provider = this.providerLoader.resolve(agentType) || this.providerLoader.getMeta(agentType);
1078
1549
  if (provider?.category === 'acp') {
@@ -1082,8 +1553,38 @@ export class DaemonCliManager {
1082
1553
  }
1083
1554
  const message = input.textFallback;
1084
1555
  if (!message) throw new Error('message required for send_chat');
1085
- await adapter.sendMessage(message);
1086
- return { success: true, status: 'generating' };
1556
+ // ARCH-REFACTOR R1: thread the dispatched task's id into the turn so the
1557
+ // worker's completion event is bound to THIS task (per-turn identity),
1558
+ // not the last-write-wins session scalar. Carried for both local and
1559
+ // remote (P2P-echoed meshContext) dispatch; absent for plain ad-hoc chat.
1560
+ const meshTaskId = (meshContext && typeof meshContext === 'object'
1561
+ && typeof (meshContext as any).taskId === 'string' && (meshContext as any).taskId.trim())
1562
+ ? (meshContext as any).taskId as string
1563
+ : undefined;
1564
+ const forceSend = args?.force === true || args?.forceSend === true;
1565
+ // Preserve the exact prior call shape when there is no taskId (plain
1566
+ // ad-hoc chat / non-mesh dispatch); only thread the per-turn taskId when
1567
+ // present, so existing non-mesh callers and their contracts are unchanged.
1568
+ if (forceSend && typeof (adapter as any).forceSendMessage === 'function') {
1569
+ if (meshTaskId) await (adapter as any).forceSendMessage(message, meshTaskId);
1570
+ else await (adapter as any).forceSendMessage(message);
1571
+ } else if (forceSend) {
1572
+ await adapter.sendMessage(message, meshTaskId ? { force: true, meshTaskId } : { force: true });
1573
+ } else if (meshTaskId) {
1574
+ await adapter.sendMessage(message, { meshTaskId });
1575
+ } else {
1576
+ await adapter.sendMessage(message);
1577
+ }
1578
+ const targetInstance = this.deps.getInstanceManager()?.getInstance(key) as
1579
+ | { recordAcknowledgedUserInput?: (input: unknown) => void }
1580
+ | undefined;
1581
+ targetInstance?.recordAcknowledgedUserInput?.(input);
1582
+ return {
1583
+ success: true,
1584
+ status: BUSY_AGENT_STATUSES.has(currentStatus) ? currentStatus : 'generating',
1585
+ ...(BUSY_AGENT_STATUSES.has(currentStatus) ? { queued: true, queuedReason: 'agent_runtime_busy' } : {}),
1586
+ ...(forceSend ? { forceSent: true, queued: false } : {}),
1587
+ };
1087
1588
  } else if (action === 'clear_history') {
1088
1589
  if (typeof adapter.clearHistory === 'function') adapter.clearHistory();
1089
1590
  return { success: true, cleared: true };