@adhdev/daemon-core 0.9.82-rc.4 → 0.9.82-rc.400

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 (418) hide show
  1. package/dist/boot/daemon-lifecycle.d.ts +11 -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 +123 -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 +267 -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 +12 -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 +28 -0
  69. package/dist/git/git-types.d.ts +5 -43
  70. package/dist/git/git-worktree.d.ts +22 -0
  71. package/dist/git/index.d.ts +2 -0
  72. package/dist/index.d.ts +57 -13
  73. package/dist/index.js +48373 -18578
  74. package/dist/index.js.map +1 -1
  75. package/dist/index.mjs +47576 -17923
  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 -37
  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 +250 -6
  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 +13 -0
  124. package/dist/providers/cli-provider-instance.d.ts +157 -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 +536 -1
  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 +66 -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 +1 -0
  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 +1221 -0
  201. package/src/cli-adapters/provider-cli-adapter.d.ts +1 -1
  202. package/src/cli-adapters/provider-cli-adapter.ts +888 -1144
  203. package/src/cli-adapters/provider-cli-parse.d.ts +1 -0
  204. package/src/cli-adapters/provider-cli-parse.ts +13 -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 +53 -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 +880 -0
  222. package/src/commands/chat-commands.ts +19 -1841
  223. package/src/commands/cli-manager.ts +513 -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 +865 -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 +2636 -2310
  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 +56 -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 +670 -48
  271. package/src/git/git-summary.ts +3 -0
  272. package/src/git/git-types.ts +17 -54
  273. package/src/git/git-worktree.ts +76 -1
  274. package/src/git/index.ts +16 -0
  275. package/src/index.ts +179 -12
  276. package/src/installer.d.ts +1 -1
  277. package/src/installer.ts +8 -6
  278. package/src/ipc/local-ipc-server.ts +278 -0
  279. package/src/launch.d.ts +1 -1
  280. package/src/launch.ts +37 -28
  281. package/src/logging/async-batch-writer.ts +55 -0
  282. package/src/logging/command-log.ts +7 -5
  283. package/src/logging/log-redactor.ts +100 -0
  284. package/src/logging/log-tail-reader.ts +341 -0
  285. package/src/logging/logger.ts +14 -7
  286. package/src/mesh/contracts.ts +338 -0
  287. package/src/mesh/coordinator-prompt.ts +381 -33
  288. package/src/mesh/coordinator-registry.ts +121 -0
  289. package/src/mesh/mesh-active-work.ts +645 -0
  290. package/src/mesh/mesh-coordinator-config.ts +97 -0
  291. package/src/mesh/mesh-delivery-policy.ts +315 -0
  292. package/src/mesh/mesh-event-classify.ts +51 -0
  293. package/src/mesh/mesh-event-forwarding.ts +1762 -0
  294. package/src/mesh/mesh-event-trace.ts +67 -0
  295. package/src/mesh/mesh-events-coordinator.ts +31 -0
  296. package/src/mesh/mesh-events-pending.ts +590 -0
  297. package/src/mesh/mesh-events-stale.ts +389 -0
  298. package/src/mesh/mesh-events-utils.ts +443 -0
  299. package/src/mesh/mesh-events.ts +32 -897
  300. package/src/mesh/mesh-fast-forward.ts +839 -0
  301. package/src/mesh/mesh-host-ownership.ts +73 -0
  302. package/src/mesh/mesh-init.ts +260 -0
  303. package/src/mesh/mesh-ledger-reconciliation.ts +12 -7
  304. package/src/mesh/mesh-ledger.ts +596 -102
  305. package/src/mesh/mesh-missions.ts +322 -0
  306. package/src/mesh/mesh-node-identity.ts +1887 -0
  307. package/src/mesh/mesh-queue-assignment.ts +1726 -0
  308. package/src/mesh/mesh-reconcile-loop.ts +1550 -0
  309. package/src/mesh/mesh-refine-batch.ts +205 -0
  310. package/src/mesh/mesh-refine-gates.ts +1660 -0
  311. package/src/mesh/mesh-refine-status.ts +231 -0
  312. package/src/mesh/mesh-review-inbox.ts +307 -0
  313. package/src/mesh/mesh-routing.ts +291 -0
  314. package/src/mesh/mesh-runtime-store.ts +1817 -0
  315. package/src/mesh/mesh-scheduling-runtime.ts +201 -0
  316. package/src/mesh/mesh-task-stats.ts +161 -0
  317. package/src/mesh/mesh-unresolved-forward-outbox.ts +185 -0
  318. package/src/mesh/mesh-warmup-deadline.ts +152 -0
  319. package/src/mesh/mesh-work-queue.ts +1178 -162
  320. package/src/mesh/preview-freshness.ts +118 -0
  321. package/src/mesh/refine-config.ts +423 -0
  322. package/src/mesh/worktree-bootstrap-config.ts +369 -0
  323. package/src/providers/acp-provider-instance.ts +43 -10
  324. package/src/providers/approval-utils.d.ts +5 -0
  325. package/src/providers/approval-utils.ts +57 -5
  326. package/src/providers/chat-message-normalization.ts +48 -6
  327. package/src/providers/cli-provider-instance.ts +1580 -103
  328. package/src/providers/contracts.d.ts +55 -0
  329. package/src/providers/contracts.ts +150 -6
  330. package/src/providers/extension-provider-instance.ts +12 -7
  331. package/src/providers/external-sources.ts +218 -0
  332. package/src/providers/ide-provider-instance.ts +35 -12
  333. package/src/providers/manual-attendance.ts +85 -0
  334. package/src/providers/native-history/antigravity-cli-transcript.ts +643 -0
  335. package/src/providers/native-history/claude-cli-transcript.ts +396 -0
  336. package/src/providers/native-history/codex-cli-transcript.ts +479 -0
  337. package/src/providers/native-history/constants.ts +19 -0
  338. package/src/providers/native-history/dispatcher.ts +339 -0
  339. package/src/providers/native-history/hermes-cli-transcript.ts +230 -0
  340. package/src/providers/native-history/index.ts +30 -0
  341. package/src/providers/provider-instance-manager.ts +30 -0
  342. package/src/providers/provider-instance.ts +19 -1
  343. package/src/providers/provider-loader.ts +668 -50
  344. package/src/providers/provider-schema.ts +87 -14
  345. package/src/providers/provider-trust.ts +114 -0
  346. package/src/providers/read-chat-contract.ts +76 -16
  347. package/src/providers/sdk/README.md +49 -0
  348. package/src/providers/sdk/v1/builders/acp/detect-status.ts +144 -0
  349. package/src/providers/sdk/v1/builders/cli/detect-status.ts +313 -0
  350. package/src/providers/sdk/v1/builders/cli/parse-approval-squash.ts +158 -0
  351. package/src/providers/sdk/v1/builders/cli/parse-approval.ts +250 -0
  352. package/src/providers/sdk/v1/builders/cli/parse-session.ts +276 -0
  353. package/src/providers/sdk/v1/builders/cli/visible-region.ts +143 -0
  354. package/src/providers/sdk/v1/fixture-tooling/format.ts +130 -0
  355. package/src/providers/sdk/v1/fixture-tooling/index.ts +22 -0
  356. package/src/providers/sdk/v1/fixture-tooling/replay.ts +352 -0
  357. package/src/providers/sdk/v1/index.ts +152 -0
  358. package/src/providers/sdk/v1/sandbox/README-design.ts +195 -0
  359. package/src/providers/sdk/v1/sandbox/require-whitelist.ts +472 -0
  360. package/src/providers/sdk/v1/sandbox/script-runner.ts +150 -0
  361. package/src/providers/sdk/v1/schemas/cli/provider.schema.json +504 -0
  362. package/src/providers/sdk/v1/schemas/primitives/acp-session-protocol-v1.json +131 -0
  363. package/src/providers/sdk/v1/schemas/primitives/native-history-codex-rollout-v1.json +66 -0
  364. package/src/providers/sdk/v1/schemas/primitives/tui-approval-squash-v1.json +91 -0
  365. package/src/providers/sdk/v1/schemas/primitives/tui-assistant-block-v1.json +91 -0
  366. package/src/providers/sdk/v1/schemas/primitives/tui-cue-ordering-v1.json +47 -0
  367. package/src/providers/sdk/v1/schemas/primitives/tui-dispatch-order-v1.json +32 -0
  368. package/src/providers/sdk/v1/schemas/primitives/tui-footer-chrome-v1.json +42 -0
  369. package/src/providers/sdk/v1/schemas/primitives/tui-index-finder-v1.json +27 -0
  370. package/src/providers/sdk/v1/schemas/primitives/tui-modal-v1.json +125 -0
  371. package/src/providers/sdk/v1/schemas/primitives/tui-prompt-marker-v1.json +45 -0
  372. package/src/providers/sdk/v1/schemas/primitives/tui-session-id-extraction-v1.json +46 -0
  373. package/src/providers/sdk/v1/schemas/primitives/tui-settled-prompt-v1.json +71 -0
  374. package/src/providers/sdk/v1/schemas/primitives/tui-spinner-v1.json +83 -0
  375. package/src/providers/sdk/v1/schemas/primitives/tui-transcript-pty-v1.json +83 -0
  376. package/src/providers/sdk/v1/schemas/primitives/tui-visible-region-v1.json +57 -0
  377. package/src/providers/sdk/v1/schemas/primitives/tui-welcome-screen-v1.json +35 -0
  378. package/src/providers/sdk/v1/types/cli/index.ts +365 -0
  379. package/src/providers/sdk/v1/types/common/index.ts +229 -0
  380. package/src/providers/sdk/v1/validators/index.ts +19 -0
  381. package/src/providers/sdk/v1/validators/manifest.ts +110 -0
  382. package/src/providers/sdk/v1/validators/taint.ts +309 -0
  383. package/src/providers/spec/adapter.ts +235 -0
  384. package/src/providers/spec/cli-adapter.ts +1056 -0
  385. package/src/providers/spec/evaluator.ts +407 -0
  386. package/src/providers/spec/fsm-driver.ts +1304 -0
  387. package/src/providers/spec/fsm-evaluator.ts +272 -0
  388. package/src/providers/spec/fsm-loader.ts +120 -0
  389. package/src/providers/spec/fsm-types.ts +273 -0
  390. package/src/providers/spec/native-history-executor.ts +1128 -0
  391. package/src/providers/spec/pre-launch-trust.ts +104 -0
  392. package/src/providers/spec/route.ts +51 -0
  393. package/src/providers/spec/types.ts +262 -0
  394. package/src/providers/status-monitor.d.ts +7 -7
  395. package/src/providers/status-monitor.ts +37 -22
  396. package/src/providers/transcript-v2.ts +567 -0
  397. package/src/providers/types/interactive-prompt.ts +536 -0
  398. package/src/providers/version-archive.ts +64 -24
  399. package/src/providers/working-dir.ts +23 -0
  400. package/src/repo-mesh-types.ts +755 -2
  401. package/src/runtime-defaults.ts +39 -0
  402. package/src/sessions/registry.ts +6 -0
  403. package/src/shared-types-extra.ts +2 -4
  404. package/src/shared-types.d.ts +8 -0
  405. package/src/shared-types.ts +64 -1
  406. package/src/status/builders.ts +26 -6
  407. package/src/status/normalize.ts +2 -0
  408. package/src/status/reporter.ts +19 -1
  409. package/src/status/snapshot.ts +95 -26
  410. package/src/system/hash.ts +23 -0
  411. package/src/system/host-memory.ts +29 -12
  412. package/src/system/load-better-sqlite3.ts +68 -0
  413. package/src/types.ts +5 -0
  414. package/dist/cli-adapters/terminal-backends/xterm-backend.d.ts +0 -17
  415. package/dist/mesh/mesh-sync.d.ts +0 -53
  416. package/src/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +0 -16
  417. package/src/cli-adapters/terminal-backends/xterm-backend.ts +0 -97
  418. package/src/mesh/mesh-sync.ts +0 -111
@@ -0,0 +1,617 @@
1
+ /**
2
+ * Repo-shared declarative mesh config — `.adhdev/mesh.json`
3
+ *
4
+ * A repo-committed, machine-independent BASE for mesh declarative settings
5
+ * (policy + coordinator prompt override/append + operating notes). It is the
6
+ * lowest layer of a LOCAL-WINS merge chain:
7
+ *
8
+ * DEFAULT_MESH_POLICY → .adhdev/mesh.json (repo base) → machine-local
9
+ * meshes.json / coordinator-prompt files (always win)
10
+ *
11
+ * The merge is **in-memory only**. The on-disk machine-local `meshes.json` is
12
+ * NEVER mutated by this module — local config keeps winning and the merge is
13
+ * applied transiently on the coordinator launch + display paths. This keeps the
14
+ * repo file a shared default that a machine can always override without the
15
+ * override being silently rewritten back to the repo shape.
16
+ *
17
+ * Three zones (scope = mesh-global in v1; per-node scope is not introduced):
18
+ * - policy — RepoMeshPolicy fields; local fields that differ from
19
+ * DEFAULT_MESH_POLICY win, otherwise the repo base shows
20
+ * through (true per-field LOCAL-WINS).
21
+ * - coordinator — systemPromptOverride (local wins, else repo) and
22
+ * systemPromptAppend (repo append + local append BOTH
23
+ * stack, repo first).
24
+ * - operatingNotes — repo-declared baseline notes merged with the runtime
25
+ * ledger notes; on duplicate text the ledger note wins.
26
+ *
27
+ * Advisory-only fields (`coordinator.maxPromptChars`, `limits.maxNoteChars`,
28
+ * `limits.maxNotes`) are accepted and preserved in the schema but NOT enforced
29
+ * in v1 — they document operator intent only.
30
+ *
31
+ * SCHEDULING OVERLAY — this same `.adhdev/mesh.json` also carries the in-tree
32
+ * scheduling product surface (`policy.scheduling`). Instead of the scattered
33
+ * `schedulingStrategy` / `maxParallelTasks` knobs (each with its own default +
34
+ * clamp), an operator declares one `policy.scheduling` block checked into the
35
+ * repo. It layers ON TOP of the stored meshes.json policy with LOCAL-WINS — a
36
+ * value present in the repo file overrides the persisted mesh policy, so the
37
+ * repo is the source of truth for how its own work distributes. Absent keys
38
+ * leave the stored policy untouched (a partial overlay, not a replacement).
39
+ *
40
+ * .adhdev/mesh.json
41
+ * { "policy": { "scheduling": {
42
+ * "distribution": "spread" | "in_order", // → schedulingStrategy
43
+ * "maxParallel": 1..8, // → maxParallelTasks (clamped)
44
+ * "readonlyMultiplier": 2 // read-only cap multiplier (default 2)
45
+ * } } }
46
+ *
47
+ * The raw 4-union schedulingStrategy escape hatch is preserved elsewhere: a
48
+ * hand-edited meshes.json may still write any of the four raw strategies and the
49
+ * scheduler honors it. The scheduling overlay exposes only the 2-mode
50
+ * `distribution` façade, mapped through distributionToStrategy.
51
+ *
52
+ * The declarative-config loader (`loadRepoMeshJsonConfig`) and the scheduling
53
+ * overlay loader (`loadMeshJsonConfig`) read the SAME file but resolve different
54
+ * zones; they coexist intentionally — coordinator launch/display consume the
55
+ * declarative zones, the scheduler consumes the scheduling overlay.
56
+ *
57
+ * SECURITY: declarative only. JSON/YAML is parsed; arbitrary JS (.js) is NOT
58
+ * supported, so loading a config can never execute code.
59
+ */
60
+
61
+ import { existsSync, readFileSync, statSync } from 'fs';
62
+ import { join } from 'path';
63
+ import * as yaml from 'js-yaml';
64
+ import {
65
+ mergeAndNormalizePolicy,
66
+ type RepoMeshPolicy,
67
+ type RepoMeshCoordinatorConfig,
68
+ type LocalMeshEntry,
69
+ type RepoMeshDistribution,
70
+ distributionToStrategy,
71
+ normalizeMeshDistribution,
72
+ resolveMaxParallelTasks,
73
+ MESH_MAX_PARALLEL_TASKS_MIN,
74
+ MESH_MAX_PARALLEL_TASKS_MAX,
75
+ } from '../repo-mesh-types.js';
76
+ import type { CoordinatorOperatingNote } from '../mesh/coordinator-prompt.js';
77
+
78
+ // ─── Types (declarative config zones) ───────────
79
+
80
+ export interface RepoMeshDeclarativeCoordinatorConfig {
81
+ /** Full mesh-level system prompt override. Same semantics as
82
+ * RepoMeshCoordinatorConfig.systemPromptOverride; LOCAL-WINS. */
83
+ systemPromptOverride?: string;
84
+ /** Mesh-level append stacked after the base prompt. Both the repo append
85
+ * and the machine-local append apply; the repo append comes first. */
86
+ systemPromptAppend?: string;
87
+ /** Advisory only in v1 — recorded but never enforced. */
88
+ maxPromptChars?: number;
89
+ }
90
+
91
+ export interface RepoMeshDeclarativeLimits {
92
+ /** Advisory only in v1 — recorded but never enforced. */
93
+ maxNoteChars?: number;
94
+ /** Advisory only in v1 — recorded but never enforced. */
95
+ maxNotes?: number;
96
+ }
97
+
98
+ /**
99
+ * Parsed + normalized `.adhdev/mesh.json` shape. Every field is optional except
100
+ * version so a repo can declare only the zone(s) it cares about.
101
+ */
102
+ export interface RepoMeshDeclarativeConfig {
103
+ version: 1;
104
+ policy?: Partial<RepoMeshPolicy>;
105
+ coordinator?: RepoMeshDeclarativeCoordinatorConfig;
106
+ operatingNotes?: CoordinatorOperatingNote[];
107
+ limits?: RepoMeshDeclarativeLimits;
108
+ }
109
+
110
+ export interface RepoMeshJsonConfigLoadResult {
111
+ config?: RepoMeshDeclarativeConfig;
112
+ /** Relative location matched, or 'unavailable'/'invalid' marker. */
113
+ source: string;
114
+ sourceType: 'repo_file' | 'unavailable' | 'invalid';
115
+ /** Absolute path of the matched file, when one was read. */
116
+ path?: string;
117
+ error?: string;
118
+ }
119
+
120
+ // ─── Types (scheduling overlay) ─────────────────
121
+
122
+ export interface MeshJsonSchedulingConfig {
123
+ /** User-facing distribution mode; mapped to schedulingStrategy on apply. */
124
+ distribution?: RepoMeshDistribution;
125
+ /** Global write-task parallel cap (clamped to [1, 8] on apply). */
126
+ maxParallel?: number;
127
+ /** Read-only diagnosis cap multiplier. Missing → 2. */
128
+ readonlyMultiplier?: number;
129
+ }
130
+
131
+ export interface MeshJsonConfig {
132
+ scheduling?: MeshJsonSchedulingConfig;
133
+ }
134
+
135
+ export interface MeshJsonConfigLoadResult {
136
+ config?: MeshJsonConfig;
137
+ source: string;
138
+ sourceType: 'repo_file' | 'unavailable' | 'invalid';
139
+ path?: string;
140
+ error?: string;
141
+ /** Cache key: path + mtime, or a sentinel for the missing/invalid case. */
142
+ sourceKey: string;
143
+ }
144
+
145
+ export const MESH_JSON_CONFIG_LOCATIONS = [
146
+ '.adhdev/mesh.json',
147
+ '.adhdev/mesh.yaml',
148
+ '.adhdev/mesh.yml',
149
+ ];
150
+
151
+ export const MESH_JSON_CONFIG_SCHEMA = {
152
+ $schema: 'https://json-schema.org/draft/2020-12/schema',
153
+ title: 'ADHDev Repo Mesh Declarative Config',
154
+ type: 'object',
155
+ additionalProperties: false,
156
+ required: ['version'],
157
+ properties: {
158
+ version: { const: 1 },
159
+ // policy is validated/normalized through mergeAndNormalizePolicy at merge
160
+ // time; the schema here only asserts it is an object.
161
+ policy: { type: 'object' },
162
+ coordinator: {
163
+ type: 'object',
164
+ additionalProperties: false,
165
+ properties: {
166
+ systemPromptOverride: { type: 'string' },
167
+ systemPromptAppend: { type: 'string' },
168
+ maxPromptChars: { type: 'number', minimum: 1 },
169
+ },
170
+ },
171
+ operatingNotes: {
172
+ type: 'array',
173
+ maxItems: 200,
174
+ items: {
175
+ type: 'object',
176
+ additionalProperties: false,
177
+ required: ['text'],
178
+ properties: {
179
+ text: { type: 'string', minLength: 1 },
180
+ category: { enum: ['provider_quirk', 'pattern_to_avoid', 'recovery_lesson'] },
181
+ createdAt: { type: 'string' },
182
+ sourceCoordinator: { type: 'string' },
183
+ },
184
+ },
185
+ },
186
+ limits: {
187
+ type: 'object',
188
+ additionalProperties: false,
189
+ properties: {
190
+ maxNoteChars: { type: 'number', minimum: 1 },
191
+ maxNotes: { type: 'number', minimum: 1 },
192
+ },
193
+ },
194
+ },
195
+ } as const;
196
+
197
+ // ─── Shared helpers ─────────────────────────────
198
+
199
+ function isRecord(value: unknown): value is Record<string, unknown> {
200
+ return !!value && typeof value === 'object' && !Array.isArray(value);
201
+ }
202
+
203
+ function parseConfigText(path: string, text: string): unknown {
204
+ if (/\.json$/i.test(path)) return JSON.parse(text);
205
+ return yaml.load(text);
206
+ }
207
+
208
+ // ─── Declarative config: Parse / Normalize ──────
209
+
210
+ function normalizeOperatingNote(value: unknown): CoordinatorOperatingNote | null {
211
+ if (!isRecord(value)) return null;
212
+ const text = typeof value.text === 'string' ? value.text.trim() : '';
213
+ if (!text) return null;
214
+ const category = value.category === 'provider_quirk' || value.category === 'pattern_to_avoid' || value.category === 'recovery_lesson'
215
+ ? value.category
216
+ : undefined;
217
+ return {
218
+ text,
219
+ ...(category ? { category } : {}),
220
+ ...(typeof value.createdAt === 'string' ? { createdAt: value.createdAt } : {}),
221
+ ...(typeof value.sourceCoordinator === 'string' ? { sourceCoordinator: value.sourceCoordinator } : {}),
222
+ };
223
+ }
224
+
225
+ /**
226
+ * Validate + normalize a parsed `.adhdev/mesh.json` object into a typed
227
+ * RepoMeshDeclarativeConfig. Returns the config plus any non-fatal warnings;
228
+ * `valid` is false only when the document is structurally unusable (not an
229
+ * object / wrong version). Unknown top-level keys are tolerated (dropped) so a
230
+ * newer repo file authored against a future schema still loads its known zones.
231
+ */
232
+ export function normalizeRepoMeshDeclarativeConfig(parsed: unknown): {
233
+ valid: boolean;
234
+ config?: RepoMeshDeclarativeConfig;
235
+ errors: string[];
236
+ } {
237
+ const errors: string[] = [];
238
+ if (!isRecord(parsed)) return { valid: false, errors: ['config must be an object'] };
239
+ if (parsed.version !== 1) {
240
+ return { valid: false, errors: [`version must be 1 (got ${JSON.stringify(parsed.version)})`] };
241
+ }
242
+
243
+ const config: RepoMeshDeclarativeConfig = { version: 1 };
244
+
245
+ if (parsed.policy !== undefined) {
246
+ if (isRecord(parsed.policy)) {
247
+ config.policy = parsed.policy as Partial<RepoMeshPolicy>;
248
+ } else {
249
+ errors.push('policy must be an object when provided');
250
+ }
251
+ }
252
+
253
+ if (parsed.coordinator !== undefined) {
254
+ if (isRecord(parsed.coordinator)) {
255
+ const coord: RepoMeshDeclarativeCoordinatorConfig = {};
256
+ const c = parsed.coordinator;
257
+ if (typeof c.systemPromptOverride === 'string') coord.systemPromptOverride = c.systemPromptOverride;
258
+ if (typeof c.systemPromptAppend === 'string') coord.systemPromptAppend = c.systemPromptAppend;
259
+ if (Number.isFinite(Number(c.maxPromptChars))) coord.maxPromptChars = Number(c.maxPromptChars);
260
+ config.coordinator = coord;
261
+ } else {
262
+ errors.push('coordinator must be an object when provided');
263
+ }
264
+ }
265
+
266
+ if (parsed.operatingNotes !== undefined) {
267
+ if (Array.isArray(parsed.operatingNotes)) {
268
+ const notes = parsed.operatingNotes
269
+ .map(normalizeOperatingNote)
270
+ .filter((n): n is CoordinatorOperatingNote => n !== null);
271
+ if (notes.length) config.operatingNotes = notes;
272
+ } else {
273
+ errors.push('operatingNotes must be an array when provided');
274
+ }
275
+ }
276
+
277
+ if (parsed.limits !== undefined) {
278
+ if (isRecord(parsed.limits)) {
279
+ const limits: RepoMeshDeclarativeLimits = {};
280
+ if (Number.isFinite(Number(parsed.limits.maxNoteChars))) limits.maxNoteChars = Number(parsed.limits.maxNoteChars);
281
+ if (Number.isFinite(Number(parsed.limits.maxNotes))) limits.maxNotes = Number(parsed.limits.maxNotes);
282
+ if (Object.keys(limits).length) config.limits = limits;
283
+ } else {
284
+ errors.push('limits must be an object when provided');
285
+ }
286
+ }
287
+
288
+ return { valid: true, config, errors };
289
+ }
290
+
291
+ // ─── Declarative config: Loader ─────────────────
292
+
293
+ /**
294
+ * Load the repo-shared declarative mesh config for a coordinator workspace.
295
+ *
296
+ * Resolution: the coordinator node workspace is checked first; if it carries no
297
+ * `.adhdev/mesh.json`, the calling process cwd is tried as a fallback (per the
298
+ * design: "workspace path = coordinator node workspace's .adhdev/mesh.json,
299
+ * else calling cwd"). The first existing file across both bases (and the
300
+ * json/yaml/yml variants) wins.
301
+ *
302
+ * Read/parse errors never throw — they resolve to a sourceType:'invalid'
303
+ * result so a broken repo file degrades to "no repo base" instead of blocking
304
+ * coordinator launch.
305
+ */
306
+ export function loadRepoMeshJsonConfig(workspace?: string): RepoMeshJsonConfigLoadResult {
307
+ const bases: string[] = [];
308
+ const ws = typeof workspace === 'string' ? workspace.trim() : '';
309
+ if (ws) bases.push(ws);
310
+ let cwd = '';
311
+ try { cwd = process.cwd(); } catch { /* cwd unavailable in some sandboxes */ }
312
+ if (cwd && cwd !== ws) bases.push(cwd);
313
+
314
+ for (const base of bases) {
315
+ for (const relative of MESH_JSON_CONFIG_LOCATIONS) {
316
+ const configPath = join(base, relative);
317
+ if (!existsSync(configPath)) continue;
318
+ try {
319
+ const parsed = parseConfigText(configPath, readFileSync(configPath, 'utf-8'));
320
+ const result = normalizeRepoMeshDeclarativeConfig(parsed);
321
+ if (!result.valid || !result.config) {
322
+ return { source: relative, sourceType: 'invalid', path: configPath, error: result.errors.join('; ') };
323
+ }
324
+ return { config: result.config, source: relative, sourceType: 'repo_file', path: configPath };
325
+ } catch (error: any) {
326
+ return { source: relative, sourceType: 'invalid', path: configPath, error: error?.message || String(error) };
327
+ }
328
+ }
329
+ }
330
+ return {
331
+ source: 'unavailable',
332
+ sourceType: 'unavailable',
333
+ error: `No repo mesh config found. Checked: ${MESH_JSON_CONFIG_LOCATIONS.join(', ')}`,
334
+ };
335
+ }
336
+
337
+ // ─── Declarative config: Merge (LOCAL-WINS) ─────
338
+
339
+ function deepEqual(a: unknown, b: unknown): boolean {
340
+ if (a === b) return true;
341
+ try { return JSON.stringify(a) === JSON.stringify(b); } catch { return false; }
342
+ }
343
+
344
+ /**
345
+ * Reduce a (fully-normalized) machine-local policy to ONLY the fields that
346
+ * genuinely differ from DEFAULT_MESH_POLICY. A meshes.json policy is always
347
+ * stored fully-defaulted, so a naive merge would let it shadow every repo-base
348
+ * field — defeating the repo default. By keeping only the truly-overridden
349
+ * fields, an untouched local field falls through to the repo base while a local
350
+ * field the operator actually changed still wins. Optional fields absent from
351
+ * DEFAULT_MESH_POLICY (e.g. allowedProviders, schedulingStrategy) count as an
352
+ * override whenever present.
353
+ */
354
+ export function diffPolicyFromDefault(local: Partial<RepoMeshPolicy> | undefined): Partial<RepoMeshPolicy> {
355
+ if (!local || typeof local !== 'object') return {};
356
+ const out: Record<string, unknown> = {};
357
+ // Compare against the NORMALIZED default (not the raw DEFAULT_MESH_POLICY) so a
358
+ // fully-normalized local policy — whose nested autoFastForward is filled out by
359
+ // normalizeAutoFastForwardPolicy — does not spuriously read as an override.
360
+ const def = mergeAndNormalizePolicy(undefined, undefined) as unknown as Record<string, unknown>;
361
+ for (const [key, value] of Object.entries(local)) {
362
+ if (value === undefined) continue;
363
+ if (!deepEqual(value, def[key])) out[key] = value;
364
+ }
365
+ return out as Partial<RepoMeshPolicy>;
366
+ }
367
+
368
+ /**
369
+ * Effective mesh policy = DEFAULT → repo base → local overrides (per-field
370
+ * LOCAL-WINS). When `local` is all-default the repo base shows through entirely
371
+ * (case i); when `local` overrides a field that field wins (case ii). Nested
372
+ * objects (autoFastForward) are still merged per-field by mergeAndNormalizePolicy.
373
+ */
374
+ export function mergeEffectiveMeshPolicy(
375
+ repoPolicy: Partial<RepoMeshPolicy> | undefined,
376
+ localPolicy: RepoMeshPolicy | Partial<RepoMeshPolicy> | undefined,
377
+ ): RepoMeshPolicy {
378
+ const repoMerged = mergeAndNormalizePolicy(undefined, repoPolicy);
379
+ const localOverrides = diffPolicyFromDefault(localPolicy);
380
+ return mergeAndNormalizePolicy(repoMerged, localOverrides);
381
+ }
382
+
383
+ /**
384
+ * Effective coordinator config. systemPromptOverride: local wins, else repo.
385
+ * systemPromptAppend: repo append + local append BOTH stack (repo first). Other
386
+ * coordinator fields (providerType, preferredNodeId, …) are carried from the
387
+ * machine-local config unchanged.
388
+ */
389
+ export function mergeEffectiveCoordinatorConfig(
390
+ repoCoord: RepoMeshDeclarativeCoordinatorConfig | undefined,
391
+ localCoord: RepoMeshCoordinatorConfig | undefined,
392
+ ): RepoMeshCoordinatorConfig {
393
+ const out: RepoMeshCoordinatorConfig = { ...(localCoord || {}) };
394
+
395
+ const localOverride = localCoord?.systemPromptOverride?.trim();
396
+ const repoOverride = repoCoord?.systemPromptOverride?.trim();
397
+ if (localOverride) {
398
+ out.systemPromptOverride = localCoord!.systemPromptOverride;
399
+ } else if (repoOverride) {
400
+ out.systemPromptOverride = repoCoord!.systemPromptOverride;
401
+ } else {
402
+ delete out.systemPromptOverride;
403
+ }
404
+
405
+ const repoAppend = repoCoord?.systemPromptAppend?.trim() ? repoCoord!.systemPromptAppend!.trim() : '';
406
+ // The machine-local append may live on the new field or the legacy alias.
407
+ const localAppendRaw = (localCoord?.systemPromptAppend ?? localCoord?.systemPromptSuffix);
408
+ const localAppend = localAppendRaw?.trim() ? localAppendRaw.trim() : '';
409
+ const stacked = [repoAppend, localAppend].filter(Boolean).join('\n\n');
410
+ if (stacked) {
411
+ out.systemPromptAppend = stacked;
412
+ // The stacked value already folds in any legacy suffix; drop the alias so
413
+ // buildCoordinatorSystemPrompt doesn't risk double-applying it.
414
+ delete out.systemPromptSuffix;
415
+ }
416
+
417
+ return out;
418
+ }
419
+
420
+ /**
421
+ * Effective operating notes = repo-declared baseline ⊕ runtime ledger notes.
422
+ * Dedup by trimmed text with the LEDGER note winning (repo duplicates dropped),
423
+ * so a runtime note's freshest wording/category survives. Order: repo baseline
424
+ * first, then ledger notes. Returns undefined when nothing usable remains so the
425
+ * prompt's "## Operating Notes" section is omitted exactly as before.
426
+ */
427
+ export function mergeEffectiveOperatingNotes(
428
+ repoNotes: CoordinatorOperatingNote[] | undefined,
429
+ ledgerNotes: CoordinatorOperatingNote[] | undefined,
430
+ ): CoordinatorOperatingNote[] | undefined {
431
+ const usable = (notes: CoordinatorOperatingNote[] | undefined): CoordinatorOperatingNote[] =>
432
+ Array.isArray(notes) ? notes.filter(n => n && typeof n.text === 'string' && n.text.trim()) : [];
433
+ const repo = usable(repoNotes);
434
+ const ledger = usable(ledgerNotes);
435
+ const ledgerTexts = new Set(ledger.map(n => n.text.trim()));
436
+ const repoKept = repo.filter(n => !ledgerTexts.has(n.text.trim()));
437
+ const merged = [...repoKept, ...ledger];
438
+ return merged.length ? merged : undefined;
439
+ }
440
+
441
+ /**
442
+ * Produce an in-memory effective mesh by layering the repo declarative config
443
+ * UNDER the machine-local mesh entry (policy + coordinator zones). Returns a new
444
+ * object; the input mesh and on-disk meshes.json are never mutated. operatingNotes
445
+ * are merged separately at launch (they ride the prompt context, not the mesh).
446
+ */
447
+ export function applyRepoMeshConfig<T extends Pick<LocalMeshEntry, 'policy' | 'coordinator'>>(
448
+ mesh: T,
449
+ repoConfig: RepoMeshDeclarativeConfig | null | undefined,
450
+ ): T {
451
+ if (!repoConfig) return mesh;
452
+ return {
453
+ ...mesh,
454
+ policy: mergeEffectiveMeshPolicy(repoConfig.policy, mesh.policy),
455
+ coordinator: mergeEffectiveCoordinatorConfig(repoConfig.coordinator, mesh.coordinator),
456
+ };
457
+ }
458
+
459
+ // ─── Declarative config: Export scaffold ────────
460
+
461
+ /**
462
+ * Build a `.adhdev/mesh.json` DRAFT from a machine-local mesh entry. This is a
463
+ * scaffold for the operator to review and commit — NOT an automatic migration.
464
+ * It captures the local policy (fully normalized) plus any coordinator prompt
465
+ * override/append so a repo can adopt the current machine's settings as the
466
+ * shared base. Operating notes are intentionally NOT exported: those are runtime
467
+ * ledger lessons, and a repo should declare baseline notes deliberately.
468
+ */
469
+ export function buildMeshJsonConfigScaffold(
470
+ mesh: Pick<LocalMeshEntry, 'policy' | 'coordinator'>,
471
+ ): RepoMeshDeclarativeConfig {
472
+ const scaffold: RepoMeshDeclarativeConfig = {
473
+ version: 1,
474
+ policy: mergeAndNormalizePolicy(undefined, mesh.policy),
475
+ };
476
+ const coord: RepoMeshDeclarativeCoordinatorConfig = {};
477
+ const override = mesh.coordinator?.systemPromptOverride;
478
+ if (typeof override === 'string' && override.trim()) coord.systemPromptOverride = override;
479
+ const append = mesh.coordinator?.systemPromptAppend ?? mesh.coordinator?.systemPromptSuffix;
480
+ if (typeof append === 'string' && append.trim()) coord.systemPromptAppend = append;
481
+ if (Object.keys(coord).length) scaffold.coordinator = coord;
482
+ return scaffold;
483
+ }
484
+
485
+ /** Serialize a scaffold to the canonical 2-space JSON draft text. */
486
+ export function serializeMeshJsonConfigScaffold(config: RepoMeshDeclarativeConfig): string {
487
+ return JSON.stringify(config, null, 2);
488
+ }
489
+
490
+ // ─── Scheduling overlay: validate / load ────────
491
+
492
+ /**
493
+ * Validate a parsed `.adhdev/mesh.*` document into a MeshJsonConfig (scheduling
494
+ * overlay). Tolerant of an empty/partial file (an empty object is valid and
495
+ * yields no overlay); strict about malformed values so a typo surfaces as
496
+ * `invalid` rather than silently no-op'ing.
497
+ */
498
+ export function validateMeshJsonConfig(raw: unknown, source = 'inline'): { valid: boolean; errors: string[]; config?: MeshJsonConfig } {
499
+ const errors: string[] = [];
500
+ if (!isRecord(raw)) {
501
+ return { valid: false, errors: [`${source}: config must be an object`] };
502
+ }
503
+ const config: MeshJsonConfig = {};
504
+
505
+ const policy = raw.policy;
506
+ const schedulingRaw = isRecord(policy) ? policy.scheduling : undefined;
507
+ if (schedulingRaw !== undefined) {
508
+ if (!isRecord(schedulingRaw)) {
509
+ errors.push('policy.scheduling must be an object');
510
+ } else {
511
+ const scheduling: MeshJsonSchedulingConfig = {};
512
+ if (schedulingRaw.distribution !== undefined) {
513
+ if (typeof schedulingRaw.distribution !== 'string'
514
+ || !['spread', 'in_order'].includes(schedulingRaw.distribution.trim())) {
515
+ errors.push("policy.scheduling.distribution must be 'spread' or 'in_order'");
516
+ } else {
517
+ scheduling.distribution = normalizeMeshDistribution(schedulingRaw.distribution);
518
+ }
519
+ }
520
+ if (schedulingRaw.maxParallel !== undefined) {
521
+ const n = Number(schedulingRaw.maxParallel);
522
+ if (!Number.isFinite(n) || n < MESH_MAX_PARALLEL_TASKS_MIN || n > MESH_MAX_PARALLEL_TASKS_MAX) {
523
+ errors.push(`policy.scheduling.maxParallel must be a number in [${MESH_MAX_PARALLEL_TASKS_MIN}, ${MESH_MAX_PARALLEL_TASKS_MAX}]`);
524
+ } else {
525
+ scheduling.maxParallel = Math.floor(n);
526
+ }
527
+ }
528
+ if (schedulingRaw.readonlyMultiplier !== undefined) {
529
+ const n = Number(schedulingRaw.readonlyMultiplier);
530
+ if (!Number.isFinite(n) || n < 1) {
531
+ errors.push('policy.scheduling.readonlyMultiplier must be a number >= 1');
532
+ } else {
533
+ scheduling.readonlyMultiplier = Math.floor(n);
534
+ }
535
+ }
536
+ // Reject unknown keys inside the scheduling block to catch typos early.
537
+ for (const key of Object.keys(schedulingRaw)) {
538
+ if (!['distribution', 'maxParallel', 'readonlyMultiplier'].includes(key)) {
539
+ errors.push(`policy.scheduling.${key} is not a recognized field`);
540
+ }
541
+ }
542
+ if (Object.keys(scheduling).length) config.scheduling = scheduling;
543
+ }
544
+ }
545
+
546
+ return { valid: errors.length === 0, errors, config: errors.length === 0 ? config : undefined };
547
+ }
548
+
549
+ // mtime-keyed cache: the scheduler re-reads on every reconcile tick (~4s), so cache
550
+ // the parse result and only re-read when the file's mtime (or its presence) changes.
551
+ const cache = new Map<string, { sourceKey: string; result: MeshJsonConfigLoadResult }>();
552
+
553
+ /**
554
+ * Locate and load the `.adhdev/mesh.json` scheduling overlay for a repo root.
555
+ * Declarative only — never executes config. Cached by path + mtime so repeated
556
+ * scheduler reads are cheap.
557
+ */
558
+ export function loadMeshJsonConfig(repoRoot: string): MeshJsonConfigLoadResult {
559
+ if (!repoRoot) {
560
+ return { source: 'unavailable', sourceType: 'unavailable', error: 'no repo root', sourceKey: 'unavailable' };
561
+ }
562
+ for (const relative of MESH_JSON_CONFIG_LOCATIONS) {
563
+ const configPath = join(repoRoot, relative);
564
+ if (!existsSync(configPath)) continue;
565
+ let mtimeMs = 0;
566
+ try {
567
+ mtimeMs = statSync(configPath).mtimeMs;
568
+ } catch {
569
+ mtimeMs = 0;
570
+ }
571
+ const cacheKey = configPath;
572
+ const sourceKey = `file:${configPath}:${mtimeMs}`;
573
+ const cached = cache.get(cacheKey);
574
+ if (cached && cached.sourceKey === sourceKey) return cached.result;
575
+ let result: MeshJsonConfigLoadResult;
576
+ try {
577
+ const text = readFileSync(configPath, 'utf-8');
578
+ const parsed = parseConfigText(configPath, text);
579
+ const validation = validateMeshJsonConfig(parsed, relative);
580
+ result = validation.valid
581
+ ? { config: validation.config, source: relative, sourceType: 'repo_file', path: configPath, sourceKey }
582
+ : { source: relative, sourceType: 'invalid', path: configPath, error: validation.errors.join('; '), sourceKey: `invalid:${configPath}:${mtimeMs}` };
583
+ } catch (error: any) {
584
+ result = { source: relative, sourceType: 'invalid', path: configPath, error: error?.message || String(error), sourceKey: `error:${configPath}` };
585
+ }
586
+ cache.set(cacheKey, { sourceKey: result.sourceKey, result });
587
+ return result;
588
+ }
589
+ return {
590
+ source: 'unavailable',
591
+ sourceType: 'unavailable',
592
+ error: `No .adhdev/mesh config found. Checked: ${MESH_JSON_CONFIG_LOCATIONS.join(', ')}`,
593
+ sourceKey: 'unavailable',
594
+ };
595
+ }
596
+
597
+ /** Test-only: drop the mtime cache so a per-run temp file is re-read. */
598
+ export function __resetMeshJsonConfigCacheForTests(): void {
599
+ cache.clear();
600
+ }
601
+
602
+ /**
603
+ * The effective scheduling knobs after layering the repo-local `.adhdev/mesh.json`
604
+ * overlay on top of a stored mesh policy (LOCAL-WINS). This is the single resolution
605
+ * point the scheduler reads, so the strategy/caps it acts on always reflect the
606
+ * in-tree override when present and fall back to the persisted policy otherwise.
607
+ */
608
+ export interface EffectiveMeshScheduling {
609
+ /** Resolved raw strategy (override distribution → strategy, else stored policy). */
610
+ strategy: ReturnType<typeof distributionToStrategy> | RepoMeshPolicy['schedulingStrategy'];
611
+ /** Effective, clamped global write cap. */
612
+ maxParallelTasks: number;
613
+ /** Read-only cap multiplier (override, else default 2). */
614
+ readonlyMultiplier?: number;
615
+ /** True when an `.adhdev/mesh.json` overlay actually contributed a value. */
616
+ overrideApplied: boolean;
617
+ }
@@ -92,12 +92,18 @@ export function buildSessionReadStateKey(sessionId: string, providerSessionId?:
92
92
 
93
93
  export function getSessionSeenAt(state: DaemonState, sessionId: string, providerSessionId?: string | null): number {
94
94
  const providerKey = buildSessionReadStateKey(sessionId, providerSessionId);
95
- return state.sessionReads?.[providerKey] || state.sessionReads?.[sessionId] || 0;
95
+ return Math.max(state.sessionReads?.[providerKey] || 0, state.sessionReads?.[sessionId] || 0);
96
96
  }
97
97
 
98
98
  export function getSessionSeenMarker(state: DaemonState, sessionId: string, providerSessionId?: string | null): string {
99
99
  const providerKey = buildSessionReadStateKey(sessionId, providerSessionId);
100
- return state.sessionReadMarkers?.[providerKey] || state.sessionReadMarkers?.[sessionId] || '';
100
+ const providerSeenAt = state.sessionReads?.[providerKey] || 0;
101
+ const sessionSeenAt = state.sessionReads?.[sessionId] || 0;
102
+ const providerMarker = state.sessionReadMarkers?.[providerKey] || '';
103
+ const sessionMarker = state.sessionReadMarkers?.[sessionId] || '';
104
+ if (sessionSeenAt > providerSeenAt && sessionMarker) return sessionMarker;
105
+ if (providerSeenAt > sessionSeenAt && providerMarker) return providerMarker;
106
+ return providerMarker || sessionMarker;
101
107
  }
102
108
 
103
109
  export function getSessionNotificationDismissal(state: DaemonState, sessionId: string, providerSessionId?: string | null): string {
@@ -9,6 +9,7 @@
9
9
  import * as fs from 'fs';
10
10
  import * as path from 'path';
11
11
  import * as os from 'os';
12
+ import { DEFAULT_SESSION_HOST_COLS, DEFAULT_SESSION_HOST_ROWS } from '@adhdev/session-host-core';
12
13
  import type * as http from 'http';
13
14
  import type { ChildProcess } from 'child_process';
14
15
  import type { DevServerContext, ProviderCategory } from './dev-server-types.js';
@@ -482,8 +483,8 @@ export async function handleAutoImplement(ctx: DevServerContext, type: string, r
482
483
  const isWin = os.platform() === 'win32';
483
484
  child = pty.spawn(isWin ? 'cmd.exe' : (process.env.SHELL || '/bin/zsh'), [isWin ? '/c' : '-c', shellCmd], {
484
485
  name: 'xterm-256color',
485
- cols: 120,
486
- rows: 40,
486
+ cols: DEFAULT_SESSION_HOST_COLS,
487
+ rows: DEFAULT_SESSION_HOST_ROWS,
487
488
  cwd: providerDir,
488
489
  env: { ...process.env, ...(spawn.env || {}) },
489
490
  });
@@ -802,7 +802,16 @@ export async function handleCliSend(ctx: DevServerContext, req: http.IncomingMes
802
802
  }
803
803
 
804
804
  try {
805
- ctx.instanceManager!.sendEvent(target.instanceId, 'send_message', { text });
805
+ if (target.category === 'cli') {
806
+ const bundle = getCliTargetBundle(ctx, type, instanceId);
807
+ if (!bundle) {
808
+ ctx.json(res, 404, { error: `No running CLI adapter found for: ${type || instanceId}` });
809
+ return;
810
+ }
811
+ await bundle.adapter.sendMessage(text);
812
+ } else {
813
+ ctx.instanceManager!.sendEvent(target.instanceId, 'send_message', { text });
814
+ }
806
815
  ctx.json(res, 200, { sent: true, type: target.type, instanceId: target.instanceId });
807
816
  } catch (e: any) {
808
817
  ctx.json(res, 500, { error: `Send failed: ${e.message}` });