@adhdev/daemon-core 0.9.82-rc.34 → 0.9.82-rc.340

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 (318) hide show
  1. package/dist/boot/daemon-lifecycle.d.ts +8 -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 +46 -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 +116 -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 +53 -0
  14. package/dist/cli-adapters/raw-terminal-io.d.ts +37 -0
  15. package/dist/cli-adapters/resolve-executable.d.ts +14 -0
  16. package/dist/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +6 -3
  17. package/dist/cli-adapters/terminal-backends/types.d.ts +10 -2
  18. package/dist/cli-adapters/terminal-screen.d.ts +4 -11
  19. package/dist/commands/cli-manager.d.ts +2 -1
  20. package/dist/commands/handler.d.ts +110 -0
  21. package/dist/commands/mesh-coordinator.d.ts +85 -1
  22. package/dist/commands/router.d.ts +308 -1
  23. package/dist/commands/upgrade-helper.d.ts +12 -0
  24. package/dist/config/chat-history.d.ts +9 -0
  25. package/dist/config/config.d.ts +5 -0
  26. package/dist/config/mesh-config.d.ts +77 -1
  27. package/dist/detection/ide-detector.d.ts +13 -0
  28. package/dist/detection/win32-ide-version.d.ts +37 -0
  29. package/dist/git/change-impact-config.d.ts +159 -0
  30. package/dist/git/git-commands.d.ts +11 -1
  31. package/dist/git/git-diff.d.ts +6 -0
  32. package/dist/git/git-executor.d.ts +11 -0
  33. package/dist/git/git-status.d.ts +23 -0
  34. package/dist/git/git-types.d.ts +2 -50
  35. package/dist/git/index.d.ts +2 -0
  36. package/dist/index.d.ts +52 -13
  37. package/dist/index.js +39439 -14533
  38. package/dist/index.js.map +1 -1
  39. package/dist/index.mjs +39000 -14215
  40. package/dist/index.mjs.map +1 -1
  41. package/dist/installer.d.ts +1 -4
  42. package/dist/ipc/local-ipc-server.d.ts +91 -0
  43. package/dist/launch.d.ts +1 -1
  44. package/dist/logging/async-batch-writer.d.ts +10 -0
  45. package/dist/logging/log-redactor.d.ts +24 -0
  46. package/dist/logging/log-tail-reader.d.ts +46 -0
  47. package/dist/mesh/contracts.d.ts +164 -0
  48. package/dist/mesh/coordinator-prompt.d.ts +36 -0
  49. package/dist/mesh/coordinator-registry.d.ts +59 -0
  50. package/dist/mesh/mesh-active-work.d.ts +174 -0
  51. package/dist/mesh/mesh-delivery-policy.d.ts +131 -0
  52. package/dist/mesh/mesh-events-coordinator.d.ts +169 -0
  53. package/dist/mesh/mesh-events-pending.d.ts +45 -0
  54. package/dist/mesh/mesh-events-stale.d.ts +40 -0
  55. package/dist/mesh/mesh-events-utils.d.ts +66 -0
  56. package/dist/mesh/mesh-events.d.ts +6 -49
  57. package/dist/mesh/mesh-fast-forward.d.ts +81 -0
  58. package/dist/mesh/mesh-host-ownership.d.ts +9 -0
  59. package/dist/mesh/mesh-init.d.ts +86 -0
  60. package/dist/mesh/mesh-ledger-reconciliation.d.ts +23 -3
  61. package/dist/mesh/mesh-ledger.d.ts +77 -1
  62. package/dist/mesh/mesh-missions.d.ts +116 -0
  63. package/dist/mesh/mesh-reconcile-loop.d.ts +7 -0
  64. package/dist/mesh/mesh-refine-batch.d.ts +68 -0
  65. package/dist/mesh/mesh-refine-status.d.ts +62 -0
  66. package/dist/mesh/mesh-review-inbox.d.ts +90 -0
  67. package/dist/mesh/mesh-routing.d.ts +70 -0
  68. package/dist/mesh/mesh-runtime-store.d.ts +418 -0
  69. package/dist/mesh/mesh-task-stats.d.ts +49 -0
  70. package/dist/mesh/mesh-unresolved-forward-outbox.d.ts +30 -0
  71. package/dist/mesh/mesh-work-queue.d.ts +208 -5
  72. package/dist/mesh/preview-freshness.d.ts +18 -0
  73. package/dist/mesh/refine-config.d.ts +216 -0
  74. package/dist/mesh/worktree-bootstrap-config.d.ts +135 -0
  75. package/dist/providers/acp-provider-instance.d.ts +2 -0
  76. package/dist/providers/approval-utils.d.ts +13 -0
  77. package/dist/providers/chat-message-normalization.d.ts +12 -0
  78. package/dist/providers/cli-provider-instance.d.ts +76 -3
  79. package/dist/providers/contracts.d.ts +139 -6
  80. package/dist/providers/external-sources.d.ts +71 -0
  81. package/dist/providers/native-history/antigravity-cli-transcript.d.ts +100 -0
  82. package/dist/providers/native-history/claude-cli-transcript.d.ts +70 -0
  83. package/dist/providers/native-history/codex-cli-transcript.d.ts +73 -0
  84. package/dist/providers/native-history/dispatcher.d.ts +27 -0
  85. package/dist/providers/native-history/hermes-cli-transcript.d.ts +30 -0
  86. package/dist/providers/native-history/index.d.ts +13 -0
  87. package/dist/providers/provider-instance-manager.d.ts +13 -0
  88. package/dist/providers/provider-instance.d.ts +13 -1
  89. package/dist/providers/provider-loader.d.ts +26 -4
  90. package/dist/providers/provider-trust.d.ts +31 -0
  91. package/dist/providers/read-chat-contract.d.ts +29 -0
  92. package/dist/providers/sdk/v1/builders/acp/detect-status.d.ts +68 -0
  93. package/dist/providers/sdk/v1/builders/cli/detect-status.d.ts +85 -0
  94. package/dist/providers/sdk/v1/builders/cli/parse-approval-squash.d.ts +59 -0
  95. package/dist/providers/sdk/v1/builders/cli/parse-approval.d.ts +65 -0
  96. package/dist/providers/sdk/v1/builders/cli/parse-session.d.ts +91 -0
  97. package/dist/providers/sdk/v1/builders/cli/visible-region.d.ts +42 -0
  98. package/dist/providers/sdk/v1/fixture-tooling/format.d.ts +126 -0
  99. package/dist/providers/sdk/v1/fixture-tooling/index.d.ts +8 -0
  100. package/dist/providers/sdk/v1/fixture-tooling/replay.d.ts +38 -0
  101. package/dist/providers/sdk/v1/index.d.ts +30 -0
  102. package/dist/providers/sdk/v1/sandbox/README-design.d.ts +193 -0
  103. package/dist/providers/sdk/v1/sandbox/require-whitelist.d.ts +74 -0
  104. package/dist/providers/sdk/v1/sandbox/script-runner.d.ts +98 -0
  105. package/dist/providers/sdk/v1/types/cli/index.d.ts +277 -0
  106. package/dist/providers/sdk/v1/types/common/index.d.ts +203 -0
  107. package/dist/providers/sdk/v1/validators/index.d.ts +5 -0
  108. package/dist/providers/sdk/v1/validators/manifest.d.ts +40 -0
  109. package/dist/providers/sdk/v1/validators/taint.d.ts +52 -0
  110. package/dist/providers/spec/adapter.d.ts +69 -0
  111. package/dist/providers/spec/cli-adapter.d.ts +217 -0
  112. package/dist/providers/spec/evaluator.d.ts +23 -0
  113. package/dist/providers/spec/fsm-driver.d.ts +306 -0
  114. package/dist/providers/spec/fsm-evaluator.d.ts +72 -0
  115. package/dist/providers/spec/fsm-loader.d.ts +14 -0
  116. package/dist/providers/spec/fsm-types.d.ts +144 -0
  117. package/dist/providers/spec/native-history-executor.d.ts +41 -0
  118. package/dist/providers/spec/pre-launch-trust.d.ts +16 -0
  119. package/dist/providers/spec/route.d.ts +4 -0
  120. package/dist/providers/spec/types.d.ts +180 -0
  121. package/dist/providers/status-monitor.d.ts +7 -7
  122. package/dist/providers/transcript-v2.d.ts +176 -0
  123. package/dist/providers/types/interactive-prompt.d.ts +84 -0
  124. package/dist/providers/working-dir.d.ts +17 -0
  125. package/dist/repo-mesh-types.d.ts +295 -13
  126. package/dist/sessions/registry.d.ts +6 -0
  127. package/dist/shared-types-extra.d.ts +2 -4
  128. package/dist/shared-types.d.ts +59 -2
  129. package/dist/status/normalize.d.ts +1 -1
  130. package/dist/status/normalize.js +1 -0
  131. package/dist/status/normalize.js.map +1 -1
  132. package/dist/status/normalize.mjs +1 -0
  133. package/dist/status/normalize.mjs.map +1 -1
  134. package/dist/status/reporter.d.ts +2 -0
  135. package/dist/status/snapshot.d.ts +26 -0
  136. package/dist/system/load-better-sqlite3.d.ts +21 -0
  137. package/dist/types.d.ts +5 -0
  138. package/package.json +7 -3
  139. package/src/agent-stream/poller.ts +2 -3
  140. package/src/agent-stream/provider-adapter.ts +1 -1
  141. package/src/boot/daemon-lifecycle.ts +55 -12
  142. package/src/boot/process-hardening.ts +89 -0
  143. package/src/build-info.ts +73 -0
  144. package/src/chat/source-machine.ts +534 -0
  145. package/src/chat/source-resolver.ts +0 -0
  146. package/src/chat/subscription-updates.ts +20 -1
  147. package/src/cli-adapter-types.d.ts +1 -0
  148. package/src/cli-adapter-types.ts +47 -2
  149. package/src/cli-adapters/cli-script-runner.ts +421 -0
  150. package/src/cli-adapters/cli-state-engine.ts +1215 -0
  151. package/src/cli-adapters/provider-cli-adapter.d.ts +1 -1
  152. package/src/cli-adapters/provider-cli-adapter.ts +774 -1141
  153. package/src/cli-adapters/provider-cli-parse.d.ts +1 -0
  154. package/src/cli-adapters/provider-cli-parse.ts +13 -0
  155. package/src/cli-adapters/provider-cli-runtime.ts +56 -7
  156. package/src/cli-adapters/provider-cli-shared.d.ts +4 -0
  157. package/src/cli-adapters/provider-cli-shared.ts +100 -11
  158. package/src/cli-adapters/pty-transport.ts +2 -1
  159. package/src/cli-adapters/raw-terminal-io.ts +252 -0
  160. package/src/cli-adapters/resolve-executable.ts +90 -0
  161. package/src/cli-adapters/session-host-transport.ts +2 -1
  162. package/src/cli-adapters/terminal-backends/ghostty-vt-backend.ts +53 -29
  163. package/src/cli-adapters/terminal-backends/types.ts +10 -3
  164. package/src/cli-adapters/terminal-screen.ts +16 -81
  165. package/src/commands/chat-commands.ts +1823 -62
  166. package/src/commands/cli-manager.ts +286 -14
  167. package/src/commands/handler.ts +809 -2
  168. package/src/commands/mesh-coordinator.ts +332 -122
  169. package/src/commands/router.ts +7433 -1317
  170. package/src/commands/stream-commands.ts +8 -0
  171. package/src/commands/upgrade-helper.ts +81 -30
  172. package/src/config/chat-history.ts +483 -24
  173. package/src/config/config.ts +12 -0
  174. package/src/config/mesh-config.ts +388 -6
  175. package/src/config/recent-activity.ts +8 -2
  176. package/src/daemon/dev-auto-implement.ts +3 -2
  177. package/src/daemon/dev-cli-debug.ts +10 -1
  178. package/src/detection/cli-detector.ts +28 -9
  179. package/src/detection/ide-detector.ts +55 -16
  180. package/src/detection/win32-ide-version.ts +106 -0
  181. package/src/git/change-impact-config.ts +354 -0
  182. package/src/git/git-commands.ts +55 -14
  183. package/src/git/git-diff.ts +53 -0
  184. package/src/git/git-executor.ts +12 -0
  185. package/src/git/git-status.ts +574 -43
  186. package/src/git/git-types.ts +14 -62
  187. package/src/git/git-worktree.ts +8 -1
  188. package/src/git/index.ts +16 -0
  189. package/src/index.ts +146 -12
  190. package/src/installer.d.ts +1 -1
  191. package/src/installer.ts +8 -6
  192. package/src/ipc/local-ipc-server.ts +278 -0
  193. package/src/launch.d.ts +1 -1
  194. package/src/launch.ts +37 -28
  195. package/src/logging/async-batch-writer.ts +55 -0
  196. package/src/logging/log-redactor.ts +100 -0
  197. package/src/logging/log-tail-reader.ts +220 -0
  198. package/src/logging/logger.ts +2 -1
  199. package/src/mesh/contracts.ts +329 -0
  200. package/src/mesh/coordinator-prompt.ts +234 -31
  201. package/src/mesh/coordinator-registry.ts +121 -0
  202. package/src/mesh/mesh-active-work.ts +623 -0
  203. package/src/mesh/mesh-delivery-policy.ts +315 -0
  204. package/src/mesh/mesh-events-coordinator.ts +2144 -0
  205. package/src/mesh/mesh-events-pending.ts +508 -0
  206. package/src/mesh/mesh-events-stale.ts +290 -0
  207. package/src/mesh/mesh-events-utils.ts +300 -0
  208. package/src/mesh/mesh-events.ts +30 -1035
  209. package/src/mesh/mesh-fast-forward.ts +839 -0
  210. package/src/mesh/mesh-host-ownership.ts +73 -0
  211. package/src/mesh/mesh-init.ts +260 -0
  212. package/src/mesh/mesh-ledger-reconciliation.ts +12 -5
  213. package/src/mesh/mesh-ledger.ts +589 -102
  214. package/src/mesh/mesh-missions.ts +248 -0
  215. package/src/mesh/mesh-reconcile-loop.ts +822 -0
  216. package/src/mesh/mesh-refine-batch.ts +197 -0
  217. package/src/mesh/mesh-refine-status.ts +231 -0
  218. package/src/mesh/mesh-review-inbox.ts +307 -0
  219. package/src/mesh/mesh-routing.ts +291 -0
  220. package/src/mesh/mesh-runtime-store.ts +1626 -0
  221. package/src/mesh/mesh-task-stats.ts +154 -0
  222. package/src/mesh/mesh-unresolved-forward-outbox.ts +185 -0
  223. package/src/mesh/mesh-work-queue.ts +888 -141
  224. package/src/mesh/preview-freshness.ts +118 -0
  225. package/src/mesh/refine-config.ts +423 -0
  226. package/src/mesh/worktree-bootstrap-config.ts +331 -0
  227. package/src/providers/acp-provider-instance.ts +25 -9
  228. package/src/providers/approval-utils.d.ts +4 -0
  229. package/src/providers/approval-utils.ts +47 -5
  230. package/src/providers/chat-message-normalization.ts +45 -5
  231. package/src/providers/cli-provider-instance.ts +1038 -99
  232. package/src/providers/contracts.d.ts +55 -0
  233. package/src/providers/contracts.ts +150 -6
  234. package/src/providers/extension-provider-instance.ts +12 -7
  235. package/src/providers/external-sources.ts +218 -0
  236. package/src/providers/ide-provider-instance.ts +35 -12
  237. package/src/providers/native-history/antigravity-cli-transcript.ts +643 -0
  238. package/src/providers/native-history/claude-cli-transcript.ts +396 -0
  239. package/src/providers/native-history/codex-cli-transcript.ts +479 -0
  240. package/src/providers/native-history/dispatcher.ts +340 -0
  241. package/src/providers/native-history/hermes-cli-transcript.ts +230 -0
  242. package/src/providers/native-history/index.ts +30 -0
  243. package/src/providers/provider-instance-manager.ts +30 -0
  244. package/src/providers/provider-instance.ts +10 -1
  245. package/src/providers/provider-loader.ts +670 -50
  246. package/src/providers/provider-schema.ts +87 -14
  247. package/src/providers/provider-trust.ts +114 -0
  248. package/src/providers/read-chat-contract.ts +76 -16
  249. package/src/providers/sdk/README.md +49 -0
  250. package/src/providers/sdk/v1/builders/acp/detect-status.ts +144 -0
  251. package/src/providers/sdk/v1/builders/cli/detect-status.ts +262 -0
  252. package/src/providers/sdk/v1/builders/cli/parse-approval-squash.ts +158 -0
  253. package/src/providers/sdk/v1/builders/cli/parse-approval.ts +250 -0
  254. package/src/providers/sdk/v1/builders/cli/parse-session.ts +276 -0
  255. package/src/providers/sdk/v1/builders/cli/visible-region.ts +143 -0
  256. package/src/providers/sdk/v1/fixture-tooling/format.ts +130 -0
  257. package/src/providers/sdk/v1/fixture-tooling/index.ts +22 -0
  258. package/src/providers/sdk/v1/fixture-tooling/replay.ts +352 -0
  259. package/src/providers/sdk/v1/index.ts +152 -0
  260. package/src/providers/sdk/v1/sandbox/README-design.ts +195 -0
  261. package/src/providers/sdk/v1/sandbox/require-whitelist.ts +472 -0
  262. package/src/providers/sdk/v1/sandbox/script-runner.ts +150 -0
  263. package/src/providers/sdk/v1/schemas/cli/provider.schema.json +504 -0
  264. package/src/providers/sdk/v1/schemas/primitives/acp-session-protocol-v1.json +131 -0
  265. package/src/providers/sdk/v1/schemas/primitives/native-history-codex-rollout-v1.json +66 -0
  266. package/src/providers/sdk/v1/schemas/primitives/tui-approval-squash-v1.json +91 -0
  267. package/src/providers/sdk/v1/schemas/primitives/tui-assistant-block-v1.json +91 -0
  268. package/src/providers/sdk/v1/schemas/primitives/tui-cue-ordering-v1.json +47 -0
  269. package/src/providers/sdk/v1/schemas/primitives/tui-dispatch-order-v1.json +32 -0
  270. package/src/providers/sdk/v1/schemas/primitives/tui-footer-chrome-v1.json +42 -0
  271. package/src/providers/sdk/v1/schemas/primitives/tui-index-finder-v1.json +27 -0
  272. package/src/providers/sdk/v1/schemas/primitives/tui-modal-v1.json +125 -0
  273. package/src/providers/sdk/v1/schemas/primitives/tui-prompt-marker-v1.json +45 -0
  274. package/src/providers/sdk/v1/schemas/primitives/tui-session-id-extraction-v1.json +46 -0
  275. package/src/providers/sdk/v1/schemas/primitives/tui-settled-prompt-v1.json +71 -0
  276. package/src/providers/sdk/v1/schemas/primitives/tui-spinner-v1.json +83 -0
  277. package/src/providers/sdk/v1/schemas/primitives/tui-transcript-pty-v1.json +83 -0
  278. package/src/providers/sdk/v1/schemas/primitives/tui-visible-region-v1.json +57 -0
  279. package/src/providers/sdk/v1/schemas/primitives/tui-welcome-screen-v1.json +35 -0
  280. package/src/providers/sdk/v1/types/cli/index.ts +365 -0
  281. package/src/providers/sdk/v1/types/common/index.ts +229 -0
  282. package/src/providers/sdk/v1/validators/index.ts +19 -0
  283. package/src/providers/sdk/v1/validators/manifest.ts +110 -0
  284. package/src/providers/sdk/v1/validators/taint.ts +309 -0
  285. package/src/providers/spec/adapter.ts +168 -0
  286. package/src/providers/spec/cli-adapter.ts +986 -0
  287. package/src/providers/spec/evaluator.ts +345 -0
  288. package/src/providers/spec/fsm-driver.ts +993 -0
  289. package/src/providers/spec/fsm-evaluator.ts +255 -0
  290. package/src/providers/spec/fsm-loader.ts +120 -0
  291. package/src/providers/spec/fsm-types.ts +238 -0
  292. package/src/providers/spec/native-history-executor.ts +1136 -0
  293. package/src/providers/spec/pre-launch-trust.ts +104 -0
  294. package/src/providers/spec/route.ts +51 -0
  295. package/src/providers/spec/types.ts +226 -0
  296. package/src/providers/status-monitor.d.ts +7 -7
  297. package/src/providers/status-monitor.ts +37 -22
  298. package/src/providers/transcript-v2.ts +567 -0
  299. package/src/providers/types/interactive-prompt.ts +536 -0
  300. package/src/providers/version-archive.ts +64 -24
  301. package/src/providers/working-dir.ts +23 -0
  302. package/src/repo-mesh-types.ts +378 -14
  303. package/src/sessions/registry.ts +6 -0
  304. package/src/shared-types-extra.ts +2 -4
  305. package/src/shared-types.d.ts +8 -0
  306. package/src/shared-types.ts +64 -1
  307. package/src/status/builders.ts +26 -6
  308. package/src/status/normalize.ts +2 -0
  309. package/src/status/reporter.ts +19 -1
  310. package/src/status/snapshot.ts +95 -26
  311. package/src/system/host-memory.ts +29 -12
  312. package/src/system/load-better-sqlite3.ts +68 -0
  313. package/src/types.ts +5 -0
  314. package/dist/cli-adapters/terminal-backends/xterm-backend.d.ts +0 -17
  315. package/dist/mesh/mesh-sync.d.ts +0 -53
  316. package/src/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +0 -16
  317. package/src/cli-adapters/terminal-backends/xterm-backend.ts +0 -97
  318. package/src/mesh/mesh-sync.ts +0 -111
@@ -28,10 +28,7 @@ export interface InstallResult {
28
28
  alreadyInstalled: boolean;
29
29
  error?: string;
30
30
  }
31
- /**
32
- * Check if an extension is already installed
33
- */
34
- export declare function isExtensionInstalled(ide: IDEInfo, marketplaceId: string): boolean;
31
+ export declare function isExtensionInstalled(ide: IDEInfo, marketplaceId: string): Promise<boolean>;
35
32
  /**
36
33
  * Install a single extension
37
34
  */
@@ -0,0 +1,91 @@
1
+ /**
2
+ * LocalIpcServer — generic HTTP + WebSocket IPC endpoint for daemon processes.
3
+ *
4
+ * Both daemon-cloud and daemon-standalone need a local IPC surface so
5
+ * external tools — the `adhdev mcp --mode ipc` MCP server and anything
6
+ * else that wants to issue commands without going through the cloud
7
+ * Worker — can connect over `ws://127.0.0.1:<port>/ipc`.
8
+ *
9
+ * Until now the implementation lived only in daemon-cloud. Standalone
10
+ * sessions therefore couldn't host MCP mesh tools — codex/claude config
11
+ * pointing at `--mode ipc` got `Cannot reach ipc daemon`. This module
12
+ * moves the transport into daemon-core so both daemons can mount it.
13
+ *
14
+ * The transport itself is daemon-agnostic. Cloud-specific behaviors
15
+ * (mesh relay, mandatory update gates) are injected via the caller's
16
+ * `handleCommand` hook; the IPC layer just frames/unframes JSON and
17
+ * routes messages.
18
+ */
19
+ import { WebSocket } from 'ws';
20
+ /** Parameters passed to `handleCommand` for each incoming ext:command frame. */
21
+ export interface IpcCommandContext {
22
+ /** The raw `command` field from the message — caller decides routing. */
23
+ command: string;
24
+ /** Args provided by the client; may have been normalized by the caller. */
25
+ args: Record<string, unknown>;
26
+ /** Stable id correlating the request and the eventual ext:command_result. */
27
+ requestId: string;
28
+ /** The connected WebSocket — only needed if the caller wants to send extra events. */
29
+ ws: WebSocket;
30
+ }
31
+ /** Result reported back to the client. `result` is optional context for success. */
32
+ export interface IpcCommandResult {
33
+ success: boolean;
34
+ result?: unknown;
35
+ error?: string;
36
+ /**
37
+ * Additional fields the caller wants merged into the response payload
38
+ * (e.g. the cloud daemon's mandatory-update-block fields). Reserved.
39
+ */
40
+ extra?: Record<string, unknown>;
41
+ }
42
+ /** Status payload returned from GET / on the IPC HTTP port. */
43
+ export interface IpcStatusPayload {
44
+ ok: true;
45
+ pid: number;
46
+ wsPath: string;
47
+ port: number;
48
+ /** Arbitrary daemon-specific summary. Cloud daemon includes mesh state, etc. */
49
+ status: Record<string, unknown> | null;
50
+ }
51
+ export interface LocalIpcServerOptions {
52
+ /** TCP port to listen on. 19222 is the conventional default. */
53
+ port: number;
54
+ /** Build the GET / status payload. Called on every health probe. */
55
+ buildStatusPayload: () => Record<string, unknown> | null;
56
+ /** Build the welcome message sent to a freshly-connected client. */
57
+ buildWelcomePayload: () => Record<string, unknown>;
58
+ /** Handle a single ext:command frame. Caller decides routing and returns the result. */
59
+ handleCommand: (ctx: IpcCommandContext) => Promise<IpcCommandResult>;
60
+ /** Optional notification when a new client connects (lets daemon track them for broadcasts). */
61
+ onClientConnected?: (ws: WebSocket) => void;
62
+ /** Optional notification when a client disconnects. */
63
+ onClientDisconnected?: (ws: WebSocket) => void;
64
+ /** Optional logger label (defaults to "IPC"). */
65
+ logCategory?: string;
66
+ }
67
+ /**
68
+ * Returned controller for stopping the server and broadcasting to clients.
69
+ * Stored by the daemon and torn down at shutdown.
70
+ */
71
+ export interface LocalIpcServerHandle {
72
+ /** True once `listen()` succeeded. */
73
+ isListening(): boolean;
74
+ /** Push a message to every connected client. */
75
+ broadcast(type: string, payload: unknown): void;
76
+ /** Close all client sockets + the HTTP server. */
77
+ close(): Promise<void>;
78
+ }
79
+ /**
80
+ * Build a JSON HTTP response describing the IPC endpoint. Exposed so caller
81
+ * code (and tests) can build the same shape without spinning a real server.
82
+ */
83
+ export declare function buildIpcStatusHttpResponse(method: string | undefined, url: string | undefined, payload: IpcStatusPayload): {
84
+ statusCode: number;
85
+ body: Record<string, unknown>;
86
+ };
87
+ /**
88
+ * Start the local IPC server. Returns a handle the caller can use to broadcast
89
+ * events and tear down at shutdown.
90
+ */
91
+ export declare function startLocalIpcServer(opts: LocalIpcServerOptions): Promise<LocalIpcServerHandle>;
package/dist/launch.d.ts CHANGED
@@ -18,7 +18,7 @@
18
18
  /** Kill IDE process (graceful → force) */
19
19
  export declare function killIdeProcess(ideId: string): Promise<boolean>;
20
20
  /** Check if IDE process is running */
21
- export declare function isIdeRunning(ideId: string): boolean;
21
+ export declare function isIdeRunning(ideId: string): Promise<boolean>;
22
22
  export interface LaunchOptions {
23
23
  ideId?: string;
24
24
  workspace?: string;
@@ -0,0 +1,10 @@
1
+ export declare class AsyncBatchWriter {
2
+ private static buffers;
3
+ private static writePromises;
4
+ private static flushTimer;
5
+ /**
6
+ * Queues data to be written to a file asynchronously in a batch.
7
+ */
8
+ static write(filePath: string, data: string): void;
9
+ private static flushAll;
10
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Log redactor — mask secrets before a raw daemon log line leaves the machine.
3
+ *
4
+ * Daemon logs can incidentally contain credentials: ADHDev API keys (adk_*),
5
+ * machine secrets (adm_*), provider keys (adp_*), bearer tokens, JWTs, TURN
6
+ * `username:credential` pairs, and `SECRET=...` style env dumps. The mesh
7
+ * `get_mesh_node_logs` command ships a log tail over P2P to the coordinator, so
8
+ * every line MUST pass through redactLogLine() first — otherwise a secret in a
9
+ * remote daemon's log is exfiltrated to whoever is driving the coordinator.
10
+ *
11
+ * Patterns are intentionally conservative: each masks the secret material while
12
+ * preserving enough surrounding shape that the line stays useful for debugging
13
+ * (e.g. `adk_••••1234`, `Bearer ••••redacted`). When in doubt, mask.
14
+ */
15
+ /**
16
+ * Mask secrets in a single log line. Idempotent-ish: re-running over an
17
+ * already-masked line leaves the MASK token in place (it contains no secret
18
+ * shape). Never throws — a redaction failure must not crash the log path.
19
+ */
20
+ export declare function redactLogLine(line: string): string;
21
+ /** Redact an array of log lines in place-safe fashion (returns a new array). */
22
+ export declare function redactLogLines(lines: string[]): string[];
23
+ /** Exposed for tests/introspection: the rule names applied, in order. */
24
+ export declare const LOG_REDACTION_RULE_NAMES: readonly string[];
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Daemon log tail reader — read the last N bytes of a daemon log file, newest
3
+ * bytes first, bounded so the result is safe to ship over a mesh P2P channel.
4
+ *
5
+ * Used by the mesh `get_mesh_node_logs` command: the coordinator asks a (possibly
6
+ * remote) daemon for its recent log tail instead of having to open a session and
7
+ * grep the file by hand. Because the mesh RPC envelope is sent as a single
8
+ * datachannel message (~256KB SCTP ceiling, no chunking), the returned tail is
9
+ * HARD-bounded by `tailBytes` (default 64KB, capped at MAX_TAIL_BYTES=128KB) and
10
+ * flags `truncated:true` when the file was larger.
11
+ *
12
+ * Boundary-safe: lines are cut on the newline byte (0x0A) only, which never
13
+ * appears inside a multibyte UTF-8 sequence, so decoding each complete byte
14
+ * segment never splits a multibyte char.
15
+ */
16
+ export declare const DEFAULT_TAIL_BYTES: number;
17
+ export declare const MAX_TAIL_BYTES: number;
18
+ export interface ReadDaemonLogTailArgs {
19
+ /** Date of the log file to read (defaults to today). YYYY-MM-DD string or Date. */
20
+ date?: string | Date;
21
+ /** Max bytes of tail to return. Clamped to (0, MAX_TAIL_BYTES]. Default 64KB. */
22
+ tailBytes?: number;
23
+ /** Optional regex source string; only lines matching (case-insensitive) are kept. */
24
+ grep?: string;
25
+ /** Optional epoch-ms floor; only lines whose leading [HH:MM:SS...] / ISO ts >= this are kept. */
26
+ sinceMs?: number;
27
+ }
28
+ export interface DaemonLogTailResult {
29
+ success: boolean;
30
+ error?: string;
31
+ lines: string[];
32
+ truncated: boolean;
33
+ logPath: string;
34
+ platform: NodeJS.Platform;
35
+ bytesReturned: number;
36
+ /** True when a grep/since filter dropped lines from the raw tail window. */
37
+ filtered: boolean;
38
+ /** The grep source actually applied (echoed back for clarity). */
39
+ grep?: string;
40
+ }
41
+ /**
42
+ * Read the daemon log tail for `date` (default today), bounded to `tailBytes`,
43
+ * with optional grep (regex source) and sinceMs filters. Falls back to the
44
+ * size-rotation backup (`*.1.log`) when the primary file does not exist.
45
+ */
46
+ export declare function readDaemonLogTail(args?: ReadDaemonLogTailArgs): DaemonLogTailResult;
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Mesh contract v2 — first-class identity, scopes, and protocol version.
3
+ *
4
+ * Replaces the implicit conventions that grew across mesh-events.ts,
5
+ * mesh-work-queue.ts, mesh-ledger.ts, and mesh-tools.ts where the same
6
+ * concept (a coordinator, a session, a task status) appeared in different
7
+ * shapes per file. The audit found:
8
+ *
9
+ * - PendingMeshCoordinatorEvent had no targetCoordinatorDaemonId. All
10
+ * events were broadcast to every coordinator that drained them. Two
11
+ * coordinators sharing a mesh would each receive every event,
12
+ * leading to duplicate completion handling and missed targeting.
13
+ * - drainPendingMeshCoordinatorEvents accepted only meshId. The caller's
14
+ * coordinator identity was never available, so per-coordinator
15
+ * routing was impossible by construction.
16
+ * - Session identifier keys diverged across stores: targetSessionId /
17
+ * assignedSessionId / instanceId / runtimeSessionId / providerSessionId.
18
+ * resolveEventSessionId() tried four fallbacks per call.
19
+ * - No protocol version on the JSONL ledger or MeshRuntimeStore. Schema
20
+ * evolutions had no guard rail.
21
+ * - mesh_reconcile_ledger existed as a routine recovery tool, not as
22
+ * an incident-response escape hatch. That itself signals the routing
23
+ * layer cannot be trusted.
24
+ *
25
+ * This module introduces the types; the actual wiring lands in B2 (data
26
+ * model + 3-way transactional store), B3 (MCP layer enforcement), and B4
27
+ * (frontend consumption). B1 is intentionally non-breaking — it adds the
28
+ * types and leaves runtime behaviour unchanged.
29
+ */
30
+ /** Provider type identifier (e.g. 'claude-cli', 'codex-cli', 'roo-code').
31
+ * Free-form string; no shared enum exists in daemon-core yet. */
32
+ type ProviderType = string;
33
+ export declare const MESH_PROTOCOL_VERSION_V1: "1.0";
34
+ export declare const MESH_PROTOCOL_VERSION_V2: "2.0";
35
+ export type MeshProtocolVersion = typeof MESH_PROTOCOL_VERSION_V1 | typeof MESH_PROTOCOL_VERSION_V2;
36
+ export declare const SUPPORTED_MESH_PROTOCOL_VERSIONS: readonly MeshProtocolVersion[];
37
+ export declare function isSupportedMeshProtocolVersion(value: unknown): value is MeshProtocolVersion;
38
+ /**
39
+ * Identity of a mesh coordinator. Required (non-optional) on every dispatch
40
+ * and drain operation in v2 — opaque/missing identity is the audit's
41
+ * smoking gun for routing failures and is structurally banned by the v2
42
+ * types.
43
+ *
44
+ * - daemonId: the machineId of the daemon hosting the coordinator. Stable
45
+ * across coordinator restarts on the same machine.
46
+ * - coordinatorRunId: a UUID generated when the coordinator process starts.
47
+ * Stable for the coordinator's lifetime, fresh on restart. Required so
48
+ * two coordinators on the same daemon (one CLI, one MCP) can be told
49
+ * apart without conflating their drains.
50
+ * - sessionId: optional CLI coordinator session identifier (instanceId).
51
+ * Present when the coordinator is itself a CLI session, absent for
52
+ * pure MCP coordinators.
53
+ */
54
+ export interface CoordinatorIdentity {
55
+ readonly daemonId: string;
56
+ readonly coordinatorRunId: string;
57
+ readonly sessionId?: string;
58
+ }
59
+ export declare function coordinatorIdentityEquals(a: CoordinatorIdentity, b: CoordinatorIdentity): boolean;
60
+ export declare function coordinatorIdentityKey(identity: CoordinatorIdentity): string;
61
+ /**
62
+ * Unified mesh session identifier. v1 referred to "the session" with five
63
+ * different field names depending on which store you were reading; v2
64
+ * collapses them into one explicit handle that carries every disambiguator
65
+ * a consumer might need.
66
+ *
67
+ * - nodeId: the mesh node this session belongs to (FK into mesh node table).
68
+ * - sessionId: provider-instance identifier (the runtime session id).
69
+ * - providerType: which provider category/type the session runs (e.g.
70
+ * 'claude-cli', 'codex-cli', 'roo-code').
71
+ * - coordinatorDaemonId: which coordinator dispatched the work that
72
+ * spawned this session. Used for completion event routing.
73
+ * - assignedAt: ms epoch when the session was bound to its current task.
74
+ */
75
+ export interface MeshSessionHandle {
76
+ readonly nodeId: string;
77
+ readonly sessionId: string;
78
+ readonly providerType: ProviderType;
79
+ readonly coordinatorDaemonId: string;
80
+ readonly assignedAt: number;
81
+ }
82
+ export declare function meshSessionHandleKey(handle: MeshSessionHandle): string;
83
+ /**
84
+ * Single canonical task status enum. v1 had at least three overlapping
85
+ * sets (queue / ledger / direct-dispatch). v2 consumers import from here.
86
+ */
87
+ export declare const MESH_TASK_STATUSES: readonly ["pending", "assigned", "in_progress", "completed", "failed", "cancelled"];
88
+ export type MeshTaskStatus = typeof MESH_TASK_STATUSES[number];
89
+ export declare function isMeshTaskStatus(value: unknown): value is MeshTaskStatus;
90
+ /**
91
+ * Explicit scope for pending coordinator events. v1 had no scope: every
92
+ * event was broadcast to every drainer. v2 forces producers to declare
93
+ * intent.
94
+ *
95
+ * - 'unicast': delivered to exactly one coordinator (intendedFor). Other
96
+ * coordinators' drains skip it.
97
+ * - 'broadcast': delivered to every coordinator on the mesh. Used for
98
+ * system-wide signals (e.g. mesh-wide policy changes). The v1 default
99
+ * becomes explicit here so audit tools can flag unintended broadcasts.
100
+ * - 'system': delivered to the daemon-level handler, not coordinators.
101
+ * Reserved for infrastructure events that no coordinator should see
102
+ * (e.g. ledger reconciliation outcomes).
103
+ */
104
+ export declare const MESH_EVENT_SCOPES: readonly ["unicast", "broadcast", "system"];
105
+ export type MeshEventScope = typeof MESH_EVENT_SCOPES[number];
106
+ export declare function isMeshEventScope(value: unknown): value is MeshEventScope;
107
+ /**
108
+ * v2 shape of a pending coordinator event. Strict supersets of the v1
109
+ * shape — every v1 field is preserved so existing readers do not break;
110
+ * v2 fields (scope, dispatchedBy, intendedFor, protocolVersion) are
111
+ * additive and consulted by v2-aware drainers only.
112
+ *
113
+ * Mixed v1/v2 events coexist during the rollout window. B2 fully cuts
114
+ * over once every coordinator drain is v2-aware.
115
+ */
116
+ export interface PendingMeshCoordinatorEventV2 {
117
+ readonly event: string;
118
+ readonly meshId: string;
119
+ readonly nodeLabel: string;
120
+ readonly nodeId?: string;
121
+ readonly workspace?: string;
122
+ readonly metadataEvent: Record<string, unknown>;
123
+ readonly coordinatorMessage?: string;
124
+ readonly queuedAt: number;
125
+ readonly protocolVersion: MeshProtocolVersion;
126
+ readonly scope: MeshEventScope;
127
+ readonly dispatchedBy: CoordinatorIdentity;
128
+ /**
129
+ * Required when scope === 'unicast', forbidden otherwise. Drainers MUST
130
+ * skip unicast events whose intendedFor does not equal their own identity.
131
+ */
132
+ readonly intendedFor?: CoordinatorIdentity;
133
+ }
134
+ /**
135
+ * v2 ledger entry additions. The originatingCoordinator field is the
136
+ * source of truth that lets completion events route back to the
137
+ * coordinator that dispatched the task. v1's "worker settings carried it
138
+ * if it happened to be set" approach is replaced.
139
+ */
140
+ export interface MeshLedgerOriginatingCoordinatorV2 {
141
+ readonly originatingCoordinator: CoordinatorIdentity;
142
+ readonly protocolVersion: MeshProtocolVersion;
143
+ }
144
+ export declare class MeshContractViolationError extends Error {
145
+ readonly violationPath: string;
146
+ readonly protocolVersion: MeshProtocolVersion;
147
+ constructor(protocolVersion: MeshProtocolVersion, violationPath: string, detail: string);
148
+ }
149
+ export declare function assertCoordinatorIdentity(raw: unknown, path: string): CoordinatorIdentity;
150
+ export declare function assertPendingMeshCoordinatorEventV2(raw: unknown, path?: string): PendingMeshCoordinatorEventV2;
151
+ /**
152
+ * Decide whether a v2 pending event should be delivered to the given drainer.
153
+ * Centralised so every drain implementation uses the same rule.
154
+ *
155
+ * - 'broadcast': always delivered.
156
+ * - 'system': never delivered to coordinators (system handler only).
157
+ * - 'unicast': delivered iff intendedFor matches drainer identity.
158
+ *
159
+ * v1 events (no scope / no protocolVersion) are treated as broadcast for
160
+ * backward compatibility during rollout; B3 tightens this so v1 events
161
+ * are quarantined to a dedicated drain endpoint instead.
162
+ */
163
+ export declare function shouldDeliverPendingEventToCoordinator(event: PendingMeshCoordinatorEventV2, drainer: CoordinatorIdentity): boolean;
164
+ export {};
@@ -8,6 +8,17 @@
8
8
  * 3. How to orchestrate work across nodes
9
9
  *
10
10
  * The prompt is generated dynamically from the current mesh state.
11
+ *
12
+ * User customization:
13
+ * ~/.adhdev/coordinator-prompts/<cliType>.md — full override
14
+ * ~/.adhdev/coordinator-prompts/<cliType>.append.md — appended to default
15
+ * ~/.adhdev/coordinator-prompts/default.md — full override (any CLI)
16
+ * ~/.adhdev/coordinator-prompts/default.append.md — appended to default (any CLI)
17
+ *
18
+ * CLI-specific files take precedence over default.* files. The override file
19
+ * still gets the node/policy facts substituted via the same {{placeholders}}
20
+ * the daemon understands; an override that doesn't reference them just gets
21
+ * a static prompt, which is also fine.
11
22
  */
12
23
  import type { LocalMeshEntry, RepoMeshStatus } from '../repo-mesh-types.js';
13
24
  export interface CoordinatorPromptContext {
@@ -15,5 +26,30 @@ export interface CoordinatorPromptContext {
15
26
  status?: RepoMeshStatus;
16
27
  userInstruction?: string;
17
28
  coordinatorCliType?: string;
29
+ /**
30
+ * M3: pre-rendered active mission section (from buildMissionPromptSection).
31
+ * Empty/undefined when the mesh has no active mission — the prompt output
32
+ * stays identical to the pre-M3 form in that case.
33
+ */
34
+ missionSection?: string;
18
35
  }
36
+ /**
37
+ * Compose the final coordinator prompt from four layers, in this precedence:
38
+ *
39
+ * 1. Per-launch `extraSystemPrompt` (always appended, as "## Additional
40
+ * Context"). Never wins as a base — it's launch-scope context.
41
+ * 2. Mesh-level append (`mesh.coordinator.systemPromptAppend` or the legacy
42
+ * `systemPromptSuffix`). Stacks after whichever base won.
43
+ * 3. User-file append (`~/.adhdev/coordinator-prompts/<cli>.append.md` or
44
+ * `default.append.md`). Also stacks; same placeholder expansion as the
45
+ * override path.
46
+ * 4. Base prompt, picked in this order:
47
+ * a. `mesh.coordinator.systemPromptOverride` (mesh-level override)
48
+ * b. user-file override (`~/.adhdev/coordinator-prompts/<cli>.md` or
49
+ * `default.md`)
50
+ * c. daemon default (assembled from identity/nodes/policy/tools/…)
51
+ *
52
+ * That layering lets a user customize prompts at three increasing scopes
53
+ * (machine, mesh, single launch) without losing the daemon's stock rules.
54
+ */
19
55
  export declare function buildCoordinatorSystemPrompt(ctx: CoordinatorPromptContext): string;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * MeshCoordinatorRegistry — Persisted record of active mesh coordinator sessions.
3
+ *
4
+ * Survives daemon restarts: when a CLI coordinator session is re-attached after
5
+ * a daemon restart the in-memory `settings.meshCoordinatorFor` on the provider
6
+ * instance is gone, so the registry file fills the gap.
7
+ *
8
+ * Keyed by sessionId (the CLI instance key / runtimeKey).
9
+ */
10
+ export interface CoordinatorRegistryEntry {
11
+ meshId: string;
12
+ sessionId: string;
13
+ workspace?: string;
14
+ startedAt: number;
15
+ /** CLI type used to launch the coordinator (claude-cli / codex-cli / …). */
16
+ cliType?: string;
17
+ /** Final system prompt sent to the coordinator after all overrides, appends,
18
+ * and extraSystemPrompt have been applied. Surfaced via the session-info
19
+ * endpoint so users can audit exactly what prompt the agent saw. */
20
+ systemPrompt?: string;
21
+ /** Per-launch extraSystemPrompt the caller passed in, if any. Stored
22
+ * separately from `systemPrompt` so the UI can show what the user
23
+ * added vs. what the daemon's default template produced. */
24
+ extraSystemPrompt?: string;
25
+ /** How the prompt was actually injected (cli_arg / context_file / …). */
26
+ injection?: {
27
+ mode: string;
28
+ target?: string;
29
+ };
30
+ /** Path of the MCP config file the daemon wrote for this session. */
31
+ mcpConfigPath?: string;
32
+ }
33
+ /** Load persisted coordinator registry from disk into in-memory map. Called once on daemon boot. */
34
+ export declare function loadMeshCoordinatorRegistry(): void;
35
+ /** Register a coordinator session. Persists to disk immediately. */
36
+ export declare function registerMeshCoordinator(entry: CoordinatorRegistryEntry): void;
37
+ /** Remove a coordinator session by sessionId. Persists to disk.
38
+ *
39
+ * Also best-effort strips any context_file wrapper block we wrote into
40
+ * the workspace at launch time (AGENTS.md / GEMINI.md), because those
41
+ * files are auto-loaded by their CLIs on every subsequent launch — and
42
+ * a wrapper block surviving the coordinator session would silently
43
+ * inject the coordinator system prompt into ordinary non-coordinator
44
+ * sessions in the same workspace, which is exactly the bug we're
45
+ * fixing here.
46
+ *
47
+ * Stripping rules:
48
+ * - Look for the start sentinel anywhere in the file; if absent,
49
+ * leave the file alone (user-authored content).
50
+ * - If the wrapper block was the only thing in the file, delete the
51
+ * file outright so we don't leave behind an empty AGENTS.md.
52
+ * - Otherwise drop only the block between the sentinels and trim a
53
+ * leading/trailing blank line so we don't leave dangling separators.
54
+ */
55
+ export declare function unregisterMeshCoordinator(sessionId: string): void;
56
+ /** Look up a coordinator entry by session ID. Returns undefined if not registered. */
57
+ export declare function getCoordinatorForSession(sessionId: string): CoordinatorRegistryEntry | undefined;
58
+ /** List all coordinator entries for a given workspace path. */
59
+ export declare function listCoordinatorsForWorkspace(workspace: string): CoordinatorRegistryEntry[];
@@ -0,0 +1,174 @@
1
+ import type { MeshLedgerEntry } from './mesh-ledger.js';
2
+ import type { MeshWorkQueueEntry, DirectDispatchRecord } from './mesh-work-queue.js';
3
+ export type MeshActiveWorkSource = 'queue' | 'direct';
4
+ export type MeshActiveWorkStatus = 'pending' | 'assigned' | 'generating' | 'idle' | 'failed' | 'awaiting_approval';
5
+ export interface MeshActiveWorkRecord {
6
+ taskId: string;
7
+ source: MeshActiveWorkSource;
8
+ status: MeshActiveWorkStatus;
9
+ nodeId?: string;
10
+ sessionId?: string;
11
+ providerType?: string;
12
+ taskTitle: string;
13
+ taskSummary: string;
14
+ message?: string;
15
+ taskMode?: string;
16
+ createdAt: string;
17
+ updatedAt: string;
18
+ dispatchedAt?: string;
19
+ elapsedMs: number;
20
+ terminal?: boolean;
21
+ terminalKind?: string;
22
+ terminalAt?: string;
23
+ staleReason?: string;
24
+ /**
25
+ * When true, the session targeted by this direct dispatch still exists in the live mesh
26
+ * but did not transition to generating — the dispatch was not acknowledged by the provider.
27
+ * Distinct from historical/orphaned stale entries where the node/session is gone.
28
+ */
29
+ staleDispatchUnacknowledged?: boolean;
30
+ }
31
+ export interface MeshActiveWorkSummary {
32
+ totalActiveCount: number;
33
+ queueActiveCount: number;
34
+ directActiveCount: number;
35
+ awaitingApprovalCount: number;
36
+ generatingCount: number;
37
+ failedCount: number;
38
+ idleCount: number;
39
+ sourceCounts: Record<MeshActiveWorkSource, number>;
40
+ statusCounts: Record<MeshActiveWorkStatus, number>;
41
+ staleDirectCount: number;
42
+ /**
43
+ * Count of stale direct entries where the target session still exists in the live mesh
44
+ * but never transitioned to generating — these are fresh dispatch failures, not historical orphans.
45
+ * Requires immediate recovery: launch a fresh session and retry the task.
46
+ */
47
+ staleDirectUnacknowledgedCount?: number;
48
+ /**
49
+ * When staleDirectCount > 0, this note clarifies what kind of stale records exist.
50
+ * Fresh unacknowledged dispatches carry an actionable recovery note; orphaned historical
51
+ * entries carry the "historical evidence only" note. Both may coexist.
52
+ */
53
+ staleDirectNote?: string;
54
+ }
55
+ export interface MeshStaleDirectWorkSummary {
56
+ count: number;
57
+ sampleLimit: number;
58
+ sample: Array<Pick<MeshActiveWorkRecord, 'taskId' | 'status' | 'nodeId' | 'sessionId' | 'taskTitle' | 'createdAt' | 'staleReason'>>;
59
+ reasonCounts: Record<string, number>;
60
+ detailHint: string;
61
+ note?: string;
62
+ }
63
+ export interface BuildMeshActiveWorkOptions {
64
+ meshId: string;
65
+ queue?: MeshWorkQueueEntry[];
66
+ ledgerEntries?: MeshLedgerEntry[];
67
+ /**
68
+ * Active direct dispatches from MeshRuntimeStore. When provided, these are used instead of
69
+ * scanning ledger entries for direct dispatches — eliminates the O(n_ledger) scan.
70
+ * Falls back to ledger scanning when not provided.
71
+ */
72
+ directDispatches?: DirectDispatchRecord[];
73
+ nodes?: any[];
74
+ now?: number;
75
+ /** Include terminal direct rows (idle/failed) for handoff/recent-work surfaces. Defaults false. */
76
+ includeTerminalDirect?: boolean;
77
+ }
78
+ export declare function buildMeshActiveWorkSummary(activeWork: MeshActiveWorkRecord[]): MeshActiveWorkSummary;
79
+ export declare function buildMeshActiveWork(opts: BuildMeshActiveWorkOptions): {
80
+ activeWork: MeshActiveWorkRecord[];
81
+ staleDirectWork: MeshActiveWorkRecord[];
82
+ staleDirectWorkNote?: string;
83
+ terminalDirectWork: MeshActiveWorkRecord[];
84
+ summary: MeshActiveWorkSummary;
85
+ };
86
+ /**
87
+ * staleReason strings (produced by sessionStatusFromNodes above) that indicate the original
88
+ * node/session is GONE from the live mesh — i.e. the staleDirect record is an orphaned ledger
89
+ * artifact, not active or recoverable work. These are the only reasons safe to prune from the
90
+ * active staleDirect surface. The "no provider acknowledgement" reason is deliberately excluded:
91
+ * those entries have a still-live node/session (staleDispatchUnacknowledged) and represent
92
+ * recoverable dispatch failures, never orphans.
93
+ */
94
+ export declare const PRUNABLE_ORPHAN_STALE_REASONS: ReadonlySet<string>;
95
+ export type StaleDirectPruneClassification = 'prunable_orphan' | 'prunable_terminal' | 'preserve_unacknowledged' | 'preserve_active';
96
+ /**
97
+ * Classify a direct-work record for the staleDirect prune path. Pure function — the prune tool
98
+ * uses this so the safety rules (never touch active work or recoverable unacknowledged dispatches)
99
+ * live next to the staleReason producers and are independently testable.
100
+ */
101
+ export declare function classifyStaleDirectForPrune(record: Pick<MeshActiveWorkRecord, 'staleReason' | 'staleDispatchUnacknowledged' | 'terminal'>, opts?: {
102
+ includeTerminal?: boolean;
103
+ }): StaleDirectPruneClassification;
104
+ /**
105
+ * Outcome of one staleDirect prune pass. Pure data — callers (the MCP tool, the
106
+ * daemon reconcile loop) format/log this however they need. The MCP tool wraps it in
107
+ * its JSON response; the reconcile loop logs prunedCount when > 0.
108
+ */
109
+ export interface StaleDirectPruneResult {
110
+ mode: 'execute' | 'dry_run';
111
+ includeTerminal: boolean;
112
+ /** Total staleDirect (+terminal when included) candidates surfaced this pass. */
113
+ candidateCount: number;
114
+ /** Records classified prunable AND (when minAgeMs > 0) old enough to auto-prune. */
115
+ prunable: MeshActiveWorkRecord[];
116
+ prunedCount: number;
117
+ /** Prunable by classification but younger than the age gate — only populated when minAgeMs > 0. */
118
+ skippedTooYoung: MeshActiveWorkRecord[];
119
+ preservedUnacknowledged: MeshActiveWorkRecord[];
120
+ /** Prunable orphans/terminals with no store-backed row to delete (ledger-only audit). */
121
+ preservedLedgerOnly: MeshActiveWorkRecord[];
122
+ preservedNotOrphan: MeshActiveWorkRecord[];
123
+ }
124
+ export interface PruneStaleDirectDispatchesOptions {
125
+ meshId: string;
126
+ /** Active direct dispatches from MeshRuntimeStore (getActiveDirectDispatches). */
127
+ directDispatches: DirectDispatchRecord[];
128
+ /** Ledger tail used to attribute remote/terminal dispatches (readLedgerEntries). */
129
+ ledgerEntries?: MeshLedgerEntry[];
130
+ queue?: MeshWorkQueueEntry[];
131
+ /** Live mesh nodes (decorated with live session details) — drives orphan detection. */
132
+ nodes?: any[];
133
+ /** When true, actually delete + append the audit ledger entry. Default false (dry run). */
134
+ execute?: boolean;
135
+ /** Include terminal (idle/failed) direct rows as prune candidates. Default false. */
136
+ includeTerminal?: boolean;
137
+ /**
138
+ * Minimum age (ms, measured from createdAt/dispatchedAt) before a prunable orphan is
139
+ * eligible. 0 (default) prunes immediately regardless of age — the manual prune behavior.
140
+ * The daemon auto-prune passes a conservative threshold so a node/session that is only
141
+ * transiently invisible is never pruned on the spot.
142
+ */
143
+ minAgeMs?: number;
144
+ /** Audit source string written into the direct_dispatch_pruned ledger payload. */
145
+ source?: string;
146
+ now?: number;
147
+ }
148
+ /**
149
+ * Shared staleDirect prune core. Single source of truth for the prune decision + the
150
+ * mutation (store-row delete + audit-ledger append) used by BOTH the manual MCP tool
151
+ * (mesh_prune_stale_direct, minAgeMs=0) and the daemon reconcile loop's auto-prune
152
+ * PHASE (minAgeMs > 0). Pure decision logic via buildMeshActiveWork + classifyStaleDirectForPrune;
153
+ * the only side effects (on execute) are deleteDirectDispatchesByTaskId and a single
154
+ * direct_dispatch_pruned ledger entry — never touching the append-only audit history of the
155
+ * pruned dispatches themselves.
156
+ *
157
+ * Safety rules (identical for manual + auto):
158
+ * - Only records classified as staleDirectWork against the CURRENT live mesh are eligible.
159
+ * - Of those, only orphans (node/session gone) — and terminals when includeTerminal — are prunable.
160
+ * Fresh unacknowledged dispatch failures (node/session still live) are always preserved.
161
+ * - Only store-backed rows (taskId present in MeshRuntimeStore) are deleted; ledger-only remote
162
+ * entries are preserved.
163
+ * - When minAgeMs > 0, a prunable orphan younger than the gate is held back (skippedTooYoung).
164
+ * This applies ONLY to the auto path; the manual path passes minAgeMs=0 (immediate).
165
+ *
166
+ * Idempotent: a deleted row no longer appears in getActiveDirectDispatches, so a second pass
167
+ * over the same orphan finds nothing to prune.
168
+ */
169
+ export declare function pruneStaleDirectDispatches(opts: PruneStaleDirectDispatchesOptions): StaleDirectPruneResult;
170
+ export declare function buildCompactStaleDirectWorkSummary(staleDirectWork: MeshActiveWorkRecord[], opts?: {
171
+ sampleLimit?: number;
172
+ detailHint?: string;
173
+ note?: string;
174
+ }): MeshStaleDirectWorkSummary;