@adhdev/daemon-core 0.9.82-rc.28 → 0.9.82-rc.281

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 (279) 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 +23 -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 +106 -63
  11. package/dist/cli-adapters/provider-cli-parse.d.ts +4 -0
  12. package/dist/cli-adapters/provider-cli-shared.d.ts +38 -0
  13. package/dist/cli-adapters/raw-terminal-io.d.ts +37 -0
  14. package/dist/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +6 -3
  15. package/dist/cli-adapters/terminal-backends/types.d.ts +10 -2
  16. package/dist/cli-adapters/terminal-screen.d.ts +4 -11
  17. package/dist/commands/cli-manager.d.ts +2 -1
  18. package/dist/commands/handler.d.ts +110 -0
  19. package/dist/commands/mesh-coordinator.d.ts +85 -1
  20. package/dist/commands/router.d.ts +160 -1
  21. package/dist/config/chat-history.d.ts +9 -0
  22. package/dist/config/config.d.ts +5 -0
  23. package/dist/config/mesh-config.d.ts +72 -1
  24. package/dist/git/git-commands.d.ts +9 -1
  25. package/dist/git/git-diff.d.ts +6 -0
  26. package/dist/git/git-status.d.ts +7 -0
  27. package/dist/git/git-types.d.ts +2 -50
  28. package/dist/index.d.ts +51 -12
  29. package/dist/index.js +34388 -12966
  30. package/dist/index.js.map +1 -1
  31. package/dist/index.mjs +38052 -16731
  32. package/dist/index.mjs.map +1 -1
  33. package/dist/installer.d.ts +1 -4
  34. package/dist/ipc/local-ipc-server.d.ts +91 -0
  35. package/dist/launch.d.ts +1 -1
  36. package/dist/logging/async-batch-writer.d.ts +10 -0
  37. package/dist/mesh/contracts.d.ts +164 -0
  38. package/dist/mesh/coordinator-prompt.d.ts +36 -0
  39. package/dist/mesh/coordinator-registry.d.ts +59 -0
  40. package/dist/mesh/mesh-active-work.d.ts +108 -0
  41. package/dist/mesh/mesh-delivery-policy.d.ts +131 -0
  42. package/dist/mesh/mesh-events-coordinator.d.ts +133 -0
  43. package/dist/mesh/mesh-events-pending.d.ts +45 -0
  44. package/dist/mesh/mesh-events-stale.d.ts +40 -0
  45. package/dist/mesh/mesh-events-utils.d.ts +47 -0
  46. package/dist/mesh/mesh-events.d.ts +6 -49
  47. package/dist/mesh/mesh-fast-forward.d.ts +81 -0
  48. package/dist/mesh/mesh-host-ownership.d.ts +9 -0
  49. package/dist/mesh/mesh-ledger-reconciliation.d.ts +23 -3
  50. package/dist/mesh/mesh-ledger.d.ts +77 -1
  51. package/dist/mesh/mesh-missions.d.ts +68 -0
  52. package/dist/mesh/mesh-reconcile-loop.d.ts +7 -0
  53. package/dist/mesh/mesh-refine-batch.d.ts +68 -0
  54. package/dist/mesh/mesh-refine-status.d.ts +62 -0
  55. package/dist/mesh/mesh-review-inbox.d.ts +90 -0
  56. package/dist/mesh/mesh-routing.d.ts +70 -0
  57. package/dist/mesh/mesh-runtime-store.d.ts +345 -0
  58. package/dist/mesh/mesh-task-stats.d.ts +49 -0
  59. package/dist/mesh/mesh-work-queue.d.ts +166 -5
  60. package/dist/mesh/preview-freshness.d.ts +18 -0
  61. package/dist/mesh/refine-config.d.ts +215 -0
  62. package/dist/mesh/worktree-bootstrap-config.d.ts +135 -0
  63. package/dist/providers/acp-provider-instance.d.ts +2 -0
  64. package/dist/providers/approval-utils.d.ts +13 -0
  65. package/dist/providers/cli-provider-instance.d.ts +61 -3
  66. package/dist/providers/contracts.d.ts +130 -6
  67. package/dist/providers/external-sources.d.ts +71 -0
  68. package/dist/providers/native-history/antigravity-cli-transcript.d.ts +100 -0
  69. package/dist/providers/native-history/claude-cli-transcript.d.ts +70 -0
  70. package/dist/providers/native-history/codex-cli-transcript.d.ts +73 -0
  71. package/dist/providers/native-history/dispatcher.d.ts +27 -0
  72. package/dist/providers/native-history/hermes-cli-transcript.d.ts +30 -0
  73. package/dist/providers/native-history/index.d.ts +13 -0
  74. package/dist/providers/provider-instance-manager.d.ts +13 -0
  75. package/dist/providers/provider-instance.d.ts +13 -1
  76. package/dist/providers/provider-loader.d.ts +26 -4
  77. package/dist/providers/provider-trust.d.ts +31 -0
  78. package/dist/providers/read-chat-contract.d.ts +29 -0
  79. package/dist/providers/sdk/v1/builders/acp/detect-status.d.ts +68 -0
  80. package/dist/providers/sdk/v1/builders/cli/detect-status.d.ts +85 -0
  81. package/dist/providers/sdk/v1/builders/cli/parse-approval-squash.d.ts +59 -0
  82. package/dist/providers/sdk/v1/builders/cli/parse-approval.d.ts +65 -0
  83. package/dist/providers/sdk/v1/builders/cli/parse-session.d.ts +91 -0
  84. package/dist/providers/sdk/v1/builders/cli/visible-region.d.ts +42 -0
  85. package/dist/providers/sdk/v1/fixture-tooling/format.d.ts +126 -0
  86. package/dist/providers/sdk/v1/fixture-tooling/index.d.ts +8 -0
  87. package/dist/providers/sdk/v1/fixture-tooling/replay.d.ts +38 -0
  88. package/dist/providers/sdk/v1/index.d.ts +30 -0
  89. package/dist/providers/sdk/v1/sandbox/README-design.d.ts +193 -0
  90. package/dist/providers/sdk/v1/sandbox/require-whitelist.d.ts +74 -0
  91. package/dist/providers/sdk/v1/sandbox/script-runner.d.ts +98 -0
  92. package/dist/providers/sdk/v1/types/cli/index.d.ts +277 -0
  93. package/dist/providers/sdk/v1/types/common/index.d.ts +203 -0
  94. package/dist/providers/sdk/v1/validators/index.d.ts +5 -0
  95. package/dist/providers/sdk/v1/validators/manifest.d.ts +40 -0
  96. package/dist/providers/sdk/v1/validators/taint.d.ts +52 -0
  97. package/dist/providers/spec/adapter.d.ts +59 -0
  98. package/dist/providers/spec/cli-adapter.d.ts +140 -0
  99. package/dist/providers/spec/evaluator.d.ts +23 -0
  100. package/dist/providers/spec/fsm-driver.d.ts +278 -0
  101. package/dist/providers/spec/fsm-evaluator.d.ts +72 -0
  102. package/dist/providers/spec/fsm-loader.d.ts +14 -0
  103. package/dist/providers/spec/fsm-types.d.ts +106 -0
  104. package/dist/providers/spec/native-history-executor.d.ts +41 -0
  105. package/dist/providers/spec/route.d.ts +4 -0
  106. package/dist/providers/spec/types.d.ts +144 -0
  107. package/dist/providers/transcript-v2.d.ts +176 -0
  108. package/dist/providers/types/interactive-prompt.d.ts +48 -0
  109. package/dist/repo-mesh-types.d.ts +154 -13
  110. package/dist/sessions/registry.d.ts +6 -0
  111. package/dist/shared-types-extra.d.ts +2 -4
  112. package/dist/shared-types.d.ts +42 -1
  113. package/dist/status/normalize.d.ts +1 -1
  114. package/dist/status/normalize.js +1 -0
  115. package/dist/status/normalize.js.map +1 -1
  116. package/dist/status/normalize.mjs +1 -0
  117. package/dist/status/normalize.mjs.map +1 -1
  118. package/dist/status/reporter.d.ts +2 -0
  119. package/dist/status/snapshot.d.ts +1 -0
  120. package/dist/types.d.ts +5 -0
  121. package/package.json +7 -3
  122. package/src/agent-stream/poller.ts +2 -3
  123. package/src/boot/daemon-lifecycle.ts +55 -12
  124. package/src/boot/process-hardening.ts +89 -0
  125. package/src/build-info.ts +73 -0
  126. package/src/chat/source-machine.ts +534 -0
  127. package/src/chat/source-resolver.ts +0 -0
  128. package/src/chat/subscription-updates.ts +20 -1
  129. package/src/cli-adapter-types.d.ts +1 -0
  130. package/src/cli-adapter-types.ts +22 -2
  131. package/src/cli-adapters/cli-script-runner.ts +421 -0
  132. package/src/cli-adapters/cli-state-engine.ts +1215 -0
  133. package/src/cli-adapters/provider-cli-adapter.d.ts +1 -1
  134. package/src/cli-adapters/provider-cli-adapter.ts +674 -1139
  135. package/src/cli-adapters/provider-cli-parse.d.ts +1 -0
  136. package/src/cli-adapters/provider-cli-parse.ts +13 -0
  137. package/src/cli-adapters/provider-cli-runtime.ts +3 -1
  138. package/src/cli-adapters/provider-cli-shared.d.ts +2 -0
  139. package/src/cli-adapters/provider-cli-shared.ts +68 -11
  140. package/src/cli-adapters/raw-terminal-io.ts +252 -0
  141. package/src/cli-adapters/terminal-backends/ghostty-vt-backend.ts +53 -29
  142. package/src/cli-adapters/terminal-backends/types.ts +10 -3
  143. package/src/cli-adapters/terminal-screen.ts +16 -81
  144. package/src/commands/chat-commands.ts +1813 -60
  145. package/src/commands/cli-manager.ts +286 -14
  146. package/src/commands/handler.ts +809 -2
  147. package/src/commands/mesh-coordinator.ts +332 -122
  148. package/src/commands/router.ts +5739 -566
  149. package/src/config/chat-history.ts +229 -24
  150. package/src/config/config.ts +12 -0
  151. package/src/config/mesh-config.ts +303 -3
  152. package/src/config/recent-activity.ts +8 -2
  153. package/src/daemon/dev-auto-implement.ts +3 -2
  154. package/src/daemon/dev-cli-debug.ts +10 -1
  155. package/src/detection/ide-detector.ts +26 -16
  156. package/src/git/git-commands.ts +42 -12
  157. package/src/git/git-diff.ts +53 -0
  158. package/src/git/git-status.ts +198 -7
  159. package/src/git/git-types.ts +14 -62
  160. package/src/git/git-worktree.ts +8 -1
  161. package/src/index.ts +131 -11
  162. package/src/installer.d.ts +1 -1
  163. package/src/installer.ts +8 -6
  164. package/src/ipc/local-ipc-server.ts +278 -0
  165. package/src/launch.d.ts +1 -1
  166. package/src/launch.ts +37 -28
  167. package/src/logging/async-batch-writer.ts +55 -0
  168. package/src/logging/logger.ts +2 -1
  169. package/src/mesh/contracts.ts +329 -0
  170. package/src/mesh/coordinator-prompt.ts +219 -31
  171. package/src/mesh/coordinator-registry.ts +121 -0
  172. package/src/mesh/mesh-active-work.ts +468 -0
  173. package/src/mesh/mesh-delivery-policy.ts +315 -0
  174. package/src/mesh/mesh-events-coordinator.ts +1592 -0
  175. package/src/mesh/mesh-events-pending.ts +508 -0
  176. package/src/mesh/mesh-events-stale.ts +283 -0
  177. package/src/mesh/mesh-events-utils.ts +254 -0
  178. package/src/mesh/mesh-events.ts +30 -1035
  179. package/src/mesh/mesh-fast-forward.ts +839 -0
  180. package/src/mesh/mesh-host-ownership.ts +73 -0
  181. package/src/mesh/mesh-ledger-reconciliation.ts +12 -5
  182. package/src/mesh/mesh-ledger.ts +589 -102
  183. package/src/mesh/mesh-missions.ts +172 -0
  184. package/src/mesh/mesh-reconcile-loop.ts +298 -0
  185. package/src/mesh/mesh-refine-batch.ts +197 -0
  186. package/src/mesh/mesh-refine-status.ts +231 -0
  187. package/src/mesh/mesh-review-inbox.ts +307 -0
  188. package/src/mesh/mesh-routing.ts +272 -0
  189. package/src/mesh/mesh-runtime-store.ts +1399 -0
  190. package/src/mesh/mesh-task-stats.ts +154 -0
  191. package/src/mesh/mesh-work-queue.ts +586 -145
  192. package/src/mesh/preview-freshness.ts +118 -0
  193. package/src/mesh/refine-config.ts +403 -0
  194. package/src/mesh/worktree-bootstrap-config.ts +326 -0
  195. package/src/providers/acp-provider-instance.ts +15 -1
  196. package/src/providers/approval-utils.d.ts +4 -0
  197. package/src/providers/approval-utils.ts +47 -5
  198. package/src/providers/chat-message-normalization.ts +4 -11
  199. package/src/providers/cli-provider-instance.ts +920 -81
  200. package/src/providers/contracts.d.ts +55 -0
  201. package/src/providers/contracts.ts +141 -6
  202. package/src/providers/external-sources.ts +218 -0
  203. package/src/providers/ide-provider-instance.ts +19 -5
  204. package/src/providers/native-history/antigravity-cli-transcript.ts +643 -0
  205. package/src/providers/native-history/claude-cli-transcript.ts +396 -0
  206. package/src/providers/native-history/codex-cli-transcript.ts +479 -0
  207. package/src/providers/native-history/dispatcher.ts +340 -0
  208. package/src/providers/native-history/hermes-cli-transcript.ts +230 -0
  209. package/src/providers/native-history/index.ts +30 -0
  210. package/src/providers/provider-instance-manager.ts +30 -0
  211. package/src/providers/provider-instance.ts +10 -1
  212. package/src/providers/provider-loader.ts +584 -50
  213. package/src/providers/provider-schema.ts +87 -14
  214. package/src/providers/provider-trust.ts +114 -0
  215. package/src/providers/read-chat-contract.ts +76 -16
  216. package/src/providers/sdk/README.md +49 -0
  217. package/src/providers/sdk/v1/builders/acp/detect-status.ts +144 -0
  218. package/src/providers/sdk/v1/builders/cli/detect-status.ts +262 -0
  219. package/src/providers/sdk/v1/builders/cli/parse-approval-squash.ts +158 -0
  220. package/src/providers/sdk/v1/builders/cli/parse-approval.ts +250 -0
  221. package/src/providers/sdk/v1/builders/cli/parse-session.ts +276 -0
  222. package/src/providers/sdk/v1/builders/cli/visible-region.ts +143 -0
  223. package/src/providers/sdk/v1/fixture-tooling/format.ts +130 -0
  224. package/src/providers/sdk/v1/fixture-tooling/index.ts +22 -0
  225. package/src/providers/sdk/v1/fixture-tooling/replay.ts +352 -0
  226. package/src/providers/sdk/v1/index.ts +152 -0
  227. package/src/providers/sdk/v1/sandbox/README-design.ts +195 -0
  228. package/src/providers/sdk/v1/sandbox/require-whitelist.ts +472 -0
  229. package/src/providers/sdk/v1/sandbox/script-runner.ts +150 -0
  230. package/src/providers/sdk/v1/schemas/cli/provider.schema.json +504 -0
  231. package/src/providers/sdk/v1/schemas/primitives/acp-session-protocol-v1.json +131 -0
  232. package/src/providers/sdk/v1/schemas/primitives/native-history-codex-rollout-v1.json +66 -0
  233. package/src/providers/sdk/v1/schemas/primitives/tui-approval-squash-v1.json +91 -0
  234. package/src/providers/sdk/v1/schemas/primitives/tui-assistant-block-v1.json +91 -0
  235. package/src/providers/sdk/v1/schemas/primitives/tui-cue-ordering-v1.json +47 -0
  236. package/src/providers/sdk/v1/schemas/primitives/tui-dispatch-order-v1.json +32 -0
  237. package/src/providers/sdk/v1/schemas/primitives/tui-footer-chrome-v1.json +42 -0
  238. package/src/providers/sdk/v1/schemas/primitives/tui-index-finder-v1.json +27 -0
  239. package/src/providers/sdk/v1/schemas/primitives/tui-modal-v1.json +125 -0
  240. package/src/providers/sdk/v1/schemas/primitives/tui-prompt-marker-v1.json +45 -0
  241. package/src/providers/sdk/v1/schemas/primitives/tui-session-id-extraction-v1.json +46 -0
  242. package/src/providers/sdk/v1/schemas/primitives/tui-settled-prompt-v1.json +71 -0
  243. package/src/providers/sdk/v1/schemas/primitives/tui-spinner-v1.json +83 -0
  244. package/src/providers/sdk/v1/schemas/primitives/tui-transcript-pty-v1.json +83 -0
  245. package/src/providers/sdk/v1/schemas/primitives/tui-visible-region-v1.json +57 -0
  246. package/src/providers/sdk/v1/schemas/primitives/tui-welcome-screen-v1.json +35 -0
  247. package/src/providers/sdk/v1/types/cli/index.ts +365 -0
  248. package/src/providers/sdk/v1/types/common/index.ts +229 -0
  249. package/src/providers/sdk/v1/validators/index.ts +19 -0
  250. package/src/providers/sdk/v1/validators/manifest.ts +110 -0
  251. package/src/providers/sdk/v1/validators/taint.ts +309 -0
  252. package/src/providers/spec/adapter.ts +155 -0
  253. package/src/providers/spec/cli-adapter.ts +730 -0
  254. package/src/providers/spec/evaluator.ts +345 -0
  255. package/src/providers/spec/fsm-driver.ts +868 -0
  256. package/src/providers/spec/fsm-evaluator.ts +255 -0
  257. package/src/providers/spec/fsm-loader.ts +102 -0
  258. package/src/providers/spec/fsm-types.ts +199 -0
  259. package/src/providers/spec/native-history-executor.ts +943 -0
  260. package/src/providers/spec/route.ts +51 -0
  261. package/src/providers/spec/types.ts +189 -0
  262. package/src/providers/transcript-v2.ts +567 -0
  263. package/src/providers/types/interactive-prompt.ts +446 -0
  264. package/src/providers/version-archive.ts +38 -20
  265. package/src/repo-mesh-types.ts +183 -13
  266. package/src/sessions/registry.ts +6 -0
  267. package/src/shared-types-extra.ts +2 -4
  268. package/src/shared-types.ts +45 -1
  269. package/src/status/builders.ts +26 -6
  270. package/src/status/normalize.ts +2 -0
  271. package/src/status/reporter.ts +15 -0
  272. package/src/status/snapshot.ts +84 -25
  273. package/src/system/host-memory.ts +29 -12
  274. package/src/types.ts +5 -0
  275. package/dist/cli-adapters/terminal-backends/xterm-backend.d.ts +0 -17
  276. package/dist/mesh/mesh-sync.d.ts +0 -53
  277. package/src/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +0 -16
  278. package/src/cli-adapters/terminal-backends/xterm-backend.ts +0 -97
  279. package/src/mesh/mesh-sync.ts +0 -111
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Change-area analysis for one worktree node, used to order sibling nodes for
3
+ * batch refinement so that nodes least likely to conflict merge first.
4
+ *
5
+ * The heuristic is deliberately git-only and side-effect-free: it inspects the
6
+ * commits the node's branch adds on top of the base (`base..branch`) and records
7
+ * - whether any submodule gitlink path is touched (high-conflict signal: the
8
+ * batch must rebase later siblings onto the advanced submodule main), and
9
+ * - the set of changed top-level paths (so siblings touching disjoint trees can
10
+ * be ordered ahead of ones that overlap).
11
+ */
12
+ export interface MeshRefineBatchNodeChangeArea {
13
+ nodeId: string;
14
+ workspace: string;
15
+ branch: string;
16
+ /** Top-level path segments changed by the branch vs. base (e.g. 'oss', 'packages'). */
17
+ changedTopLevelPaths: string[];
18
+ /** Full changed file list (bounded) for overlap detection. */
19
+ changedFiles: string[];
20
+ /** Submodule gitlink paths touched by the branch (subset of changedTopLevelPaths). */
21
+ touchedSubmodulePaths: string[];
22
+ /** True when the branch touches at least one submodule gitlink. */
23
+ touchesSubmodule: boolean;
24
+ /** Number of commits the branch is ahead of base; 0 means nothing to merge. */
25
+ aheadCount: number;
26
+ /** Non-fatal analysis error (e.g. base/branch unresolved); ordering falls back to neutral. */
27
+ error?: string;
28
+ }
29
+ export interface MeshRefineBatchOrderingResult {
30
+ /** Node IDs in the order they should be refined. */
31
+ order: string[];
32
+ /** Per-node change areas, keyed by node id, for plan transparency. */
33
+ changeAreas: Record<string, MeshRefineBatchNodeChangeArea>;
34
+ /** Human-readable explanation of why the order was chosen. */
35
+ rationale: string[];
36
+ }
37
+ /**
38
+ * Analyze one worktree node's change area against its merge base.
39
+ *
40
+ * @param baseRef ref that the node will merge into (e.g. 'origin/main' or a SHA)
41
+ * @param branchRef the node's branch tip
42
+ * @param diffCwd repo to run the diff in (the worktree itself is authoritative for
43
+ * `branch` resolution, but the diff `base..branch` is symmetric, so
44
+ * the worktree cwd works for both refs once base is a reachable SHA).
45
+ */
46
+ export declare function analyzeMeshRefineNodeChangeArea(args: {
47
+ nodeId: string;
48
+ workspace: string;
49
+ branch: string;
50
+ baseRef: string;
51
+ branchRef: string;
52
+ diffCwd: string;
53
+ submodulePaths: Set<string>;
54
+ }): Promise<MeshRefineBatchNodeChangeArea>;
55
+ /**
56
+ * Order nodes for batch refinement to minimize cross-sibling conflicts.
57
+ *
58
+ * Heuristic (deterministic, stable):
59
+ * 1. Nodes that do NOT touch any submodule come first — they cannot advance the
60
+ * submodule main, so they never force a later submodule rebase.
61
+ * 2. Within each group, fewer touched top-level paths first (smaller blast radius).
62
+ * 3. Tie-break by node id for determinism.
63
+ *
64
+ * Submodule-touching siblings are intrinsically serial: each one that merges
65
+ * advances oss main, so the next must rebase. Ordering them last keeps the
66
+ * non-submodule merges (which never need a submodule rebase) clean and up front.
67
+ */
68
+ export declare function orderMeshRefineBatchNodes(changeAreas: MeshRefineBatchNodeChangeArea[]): MeshRefineBatchOrderingResult;
@@ -0,0 +1,62 @@
1
+ import type { MeshLedgerEntry } from './mesh-ledger.js';
2
+ import type { PendingMeshCoordinatorEvent } from './mesh-events.js';
3
+ import type { MeshAsyncJobLifecycle } from '../repo-mesh-types.js';
4
+ export type MeshAsyncRefineJobStatus = 'accepted' | 'running' | 'completed' | 'failed';
5
+ export interface MeshAsyncRefineJobSummary extends MeshAsyncJobLifecycle {
6
+ jobId: string;
7
+ interactionId?: string;
8
+ status: MeshAsyncRefineJobStatus;
9
+ meshId?: string;
10
+ nodeId?: string;
11
+ targetNodeId?: string;
12
+ targetDaemonId?: string;
13
+ workspace?: string;
14
+ branch?: string;
15
+ into?: string;
16
+ retryOfJobId?: string;
17
+ lastEvent?: string;
18
+ lastLedgerKind?: string;
19
+ lastUpdatedAt?: string;
20
+ instruction: string;
21
+ }
22
+ export declare function buildMeshAsyncRefineJobs(args: {
23
+ meshId?: string;
24
+ ledgerEntries?: MeshLedgerEntry[];
25
+ pendingEvents?: PendingMeshCoordinatorEvent[];
26
+ }): MeshAsyncRefineJobSummary[];
27
+ /** Terminal refine jobs older than this (relative to the newest job in the set) are
28
+ * "stale" — already-resolved historical refinery rejections/successes that should not
29
+ * keep inflating the status counts in mesh_status. 6h covers a long working session
30
+ * while still folding multi-day-old residue. */
31
+ export declare const STALE_TERMINAL_REFINE_WINDOW_MS: number;
32
+ /** Cap on how many recent terminal jobs are counted even if all fall inside the freshness
33
+ * window — prevents a burst of refines from dominating the summary. */
34
+ export declare const RECENT_TERMINAL_REFINE_CAP = 8;
35
+ export interface MeshAsyncRefineJobsSummary {
36
+ /** Count of jobs reflected in `byStatus` (active jobs + recent terminal jobs). */
37
+ total: number;
38
+ byStatus: Record<string, number>;
39
+ /** Terminal jobs dropped from the counts because they are stale residue. */
40
+ staleTerminal: number;
41
+ /** Non-terminal (accepted/running) jobs still in flight. */
42
+ activeJobs: MeshAsyncRefineJobSummary[];
43
+ }
44
+ /**
45
+ * Build a compact summary of refine jobs that folds stale terminal jobs.
46
+ *
47
+ * The full job list (from `buildMeshAsyncRefineJobs`) is derived from a recent ledger
48
+ * window and deduped by jobId, but it still includes every terminal (completed/failed)
49
+ * job that happens to fall in that window — including multi-day-old refinery rejections
50
+ * that have long since been resolved. Those stale terminals inflate `byStatus.failed`
51
+ * and read as "current breakage" when they are historical noise.
52
+ *
53
+ * Active (accepted/running) jobs are always counted. Terminal jobs are counted only when
54
+ * they are recent: within `STALE_TERMINAL_REFINE_WINDOW_MS` of the newest job's activity
55
+ * time AND among the `RECENT_TERMINAL_REFINE_CAP` most-recent terminals. Everything else
56
+ * is folded into `staleTerminal` and excluded from `byStatus`.
57
+ *
58
+ * Freshness is measured relative to the newest job in the set (not wall-clock), so the
59
+ * result is deterministic for a given input — important for tests and for stale-clock
60
+ * environments.
61
+ */
62
+ export declare function summarizeMeshAsyncRefineJobs(jobs: MeshAsyncRefineJobSummary[]): MeshAsyncRefineJobsSummary;
@@ -0,0 +1,90 @@
1
+ /**
2
+ * M4.0: Review inbox — derive review items from existing truth.
3
+ *
4
+ * No new store: review items are a query-time projection of
5
+ * - mesh_status node statuses (daemon-owned branchConvergence), and
6
+ * - the task ledger (completion evidence envelopes + refine job results).
7
+ *
8
+ * Scope (M4.0): host-daemon-local nodes only. Remote nodes are excluded and
9
+ * surfaced via remoteNodesExcluded/excludedRemoteNodeIds until the
10
+ * daemon↔daemon P2P relay path is live-verified (M4.2).
11
+ */
12
+ import type { MeshLedgerEntry } from './mesh-ledger.js';
13
+ export type MeshReviewInboxReason = 'merge_candidate' | 'refine_blocked_review';
14
+ export interface MeshReviewInboxConvergence {
15
+ status: string;
16
+ reason: string | null;
17
+ nextStep: string | null;
18
+ needsConvergence: boolean;
19
+ }
20
+ export interface MeshReviewInboxEvidence {
21
+ available: boolean;
22
+ /** Ledger kind of the entry the evidence came from. */
23
+ kind?: 'task_completed' | 'task_failed';
24
+ /** 'task_completion' = ordinary worker completion envelope; 'refine_job' = Refinery result. */
25
+ source?: 'task_completion' | 'refine_job';
26
+ timestamp?: string;
27
+ taskId?: string;
28
+ sessionId?: string;
29
+ /** M2-3 bootstrap stage from the refine validation gate: cached|ran|failed|skipped|legacy|not_configured. */
30
+ bootstrap?: Record<string, unknown> | null;
31
+ validation?: Record<string, unknown> | null;
32
+ checkpoint?: Record<string, unknown> | null;
33
+ worker?: {
34
+ status: string;
35
+ classification?: string;
36
+ changedFiles: string[];
37
+ changedFilesTruncated?: true;
38
+ validationResults: Array<Record<string, unknown>>;
39
+ errors: string[];
40
+ requiresUserAction: boolean;
41
+ } | null;
42
+ finalBranchConvergenceState?: Record<string, unknown>;
43
+ refineJob?: Record<string, unknown>;
44
+ }
45
+ export interface MeshReviewInboxDiffFile {
46
+ path: string;
47
+ status?: string;
48
+ insertions?: number;
49
+ deletions?: number;
50
+ binary?: boolean;
51
+ oldPath?: string;
52
+ }
53
+ export interface MeshReviewInboxDiffSummary {
54
+ baseRef: string;
55
+ files: MeshReviewInboxDiffFile[];
56
+ totalFiles: number;
57
+ totalInsertions: number;
58
+ totalDeletions: number;
59
+ truncated: boolean;
60
+ error?: string;
61
+ }
62
+ export interface MeshReviewInboxItem {
63
+ nodeId: string;
64
+ workspace: string | null;
65
+ branch: string | null;
66
+ defaultBranch: string | null;
67
+ isLocalWorktree: boolean;
68
+ reviewReason: MeshReviewInboxReason;
69
+ convergence: MeshReviewInboxConvergence;
70
+ evidence: MeshReviewInboxEvidence;
71
+ transcriptHandle: Record<string, unknown> | null;
72
+ /** Latest non-terminal Refinery job for this node (accepted/running), if any. */
73
+ activeRefineJob: Record<string, unknown> | null;
74
+ lastActivityAt: string | null;
75
+ /** Filled by the daemon command with a bounded base-branch diff probe; null when the workspace is not locally readable. */
76
+ diffSummary?: MeshReviewInboxDiffSummary | null;
77
+ }
78
+ export interface MeshReviewInboxDerivation {
79
+ items: MeshReviewInboxItem[];
80
+ remoteNodesExcluded: boolean;
81
+ excludedRemoteNodeIds: string[];
82
+ }
83
+ /**
84
+ * Derive review inbox items from mesh_status node statuses and a bounded
85
+ * ledger tail. Pure and read-only; the caller attaches diffSummary separately.
86
+ */
87
+ export declare function deriveMeshReviewInboxItems(args: {
88
+ nodes: Array<Record<string, unknown>>;
89
+ ledgerEntries: MeshLedgerEntry[];
90
+ }): MeshReviewInboxDerivation;
@@ -0,0 +1,70 @@
1
+ import type { DaemonComponents } from '../boot/daemon-lifecycle.js';
2
+ export type WorkerDelegateRejectionReason = 'not_cli' | 'no_workspace' | 'no_worker_envelope' | 'coordinator_not_dispatch_target' | 'mesh_unresolved';
3
+ export interface WorkerDelegateRouting {
4
+ /** True when the source session is a mesh worker whose events must route to a coordinator. */
5
+ isDelegate: boolean;
6
+ /** Resolved mesh id (runtime stamp, direct-dispatch recovery, or workspace lookup). */
7
+ meshId: string;
8
+ /** Resolved node id within the mesh, or '' when it cannot be determined. */
9
+ nodeId: string;
10
+ /** Human-readable node label for the coordinator system message. */
11
+ nodeLabel: string;
12
+ /** Coordinator daemon anchor (prefixed id) when the worker carries one; '' otherwise. */
13
+ coordinatorDaemonId: string;
14
+ /** Source session workspace (best-effort; '' when the session/workspace is missing). */
15
+ workspace: string;
16
+ /** Source session id echoed back, so diagnostics can name the dropped event's origin. */
17
+ sessionId: string;
18
+ /** Why routing was rejected (isDelegate=false), for fail-loud diagnostics (R4). */
19
+ rejectionReason?: WorkerDelegateRejectionReason;
20
+ }
21
+ interface ResolveDeps {
22
+ /** Resolve a mesh by id (local config + inline cache). */
23
+ getMeshById: (meshId: string) => any | undefined;
24
+ /** Resolve a mesh by workspace path (cached repo lookup). */
25
+ getMeshByWorkspace: (workspace: string) => any | undefined;
26
+ }
27
+ /**
28
+ * Resolve how a source CLI session's mesh events should route to a coordinator.
29
+ *
30
+ * This is the single authoritative interpretation of the worker envelope. It folds
31
+ * together every signal that previously lived in inline branches:
32
+ * - runtime stamps (meshNodeFor / meshNodeId)
33
+ * - the coordinator anchor (meshCoordinatorDaemonId) and launch marker (launchedByCoordinator,
34
+ * meshCoordinatorNodeId) — any one proves delegation even if the node/mesh stamp was dropped
35
+ * - direct-dispatch recovery: a coordinator session that is itself a dispatch target
36
+ * - workspace→mesh fallback when no runtime mesh id survived
37
+ *
38
+ * Returns isDelegate=false (with a rejectionReason) instead of throwing, so the caller
39
+ * can either ignore non-delegate events or surface a diagnostic.
40
+ */
41
+ export declare function resolveWorkerDelegateRouting(components: DaemonComponents, instanceId: string, deps: ResolveDeps): WorkerDelegateRouting;
42
+ /** Ledger stream that collects delivery_unroutable diagnostics (no real mesh id exists for them). */
43
+ export declare const UNROUTABLE_DIAGNOSTIC_STREAM = "__unroutable__";
44
+ export declare function __resetUnroutableDiagnosticsForTests(): void;
45
+ /** True only for rejections that represent a silently-dropped delegate event worth a diagnostic. */
46
+ export declare function isUnroutableDelegateRejection(routing: WorkerDelegateRouting): boolean;
47
+ /**
48
+ * R4: record that a worker event with a valid envelope could not be routed to a coordinator.
49
+ * Writes a `delivery_unroutable` ledger entry (deduped within a short window) so operators see
50
+ * WHY a completion never arrived instead of it vanishing. No-op for non-diagnostic rejections.
51
+ */
52
+ export declare function recordUnroutableDelegateEvent(routing: WorkerDelegateRouting, eventName: string): boolean;
53
+ export interface UnroutableDeliveryDiagnostic {
54
+ timestamp: string;
55
+ event: string;
56
+ sessionId?: string;
57
+ workspace?: string;
58
+ coordinatorDaemonId?: string;
59
+ }
60
+ /**
61
+ * R4 visibility: recent delivery_unroutable diagnostics, newest first. Surfaced in mesh_status
62
+ * so an operator/coordinator can see that completions were dropped (envelope present, mesh
63
+ * unresolved) rather than the drops being invisible in a ledger nobody reads. The diagnostics
64
+ * live in a single shared stream because an unroutable event has no resolvable mesh.
65
+ */
66
+ export declare function getRecentUnroutableDeliveries(opts?: {
67
+ sinceMs?: number;
68
+ limit?: number;
69
+ }): UnroutableDeliveryDiagnostic[];
70
+ export {};
@@ -0,0 +1,345 @@
1
+ import type { MeshTaskStatus, MeshWorkQueueEntry } from './mesh-work-queue.js';
2
+ export declare class MeshRuntimeStore {
3
+ private static instance;
4
+ private readonly db;
5
+ private readonly dbPath;
6
+ private readonly migratedMeshIds;
7
+ private fingerprintSweepCounter;
8
+ private walWriteCounter;
9
+ private static readonly WAL_CHECK_INTERVAL;
10
+ private static readonly WAL_MAX_BYTES;
11
+ private constructor();
12
+ static getInstance(): MeshRuntimeStore;
13
+ static resetForTests(): void;
14
+ close(): void;
15
+ transaction<T>(fn: () => T): T;
16
+ private migrate;
17
+ hasCompletionFingerprint(fingerprint: string): boolean;
18
+ recordCompletionFingerprint(fingerprint: string, ttlMs: number): void;
19
+ sweepExpiredFingerprints(): void;
20
+ recordDirectDelivered(coordinatorDaemonId: string, fingerprint: string, ttlMs: number): void;
21
+ wasDirectDelivered(coordinatorDaemonId: string, fingerprint: string): boolean;
22
+ sweepExpiredDirectDelivered(): void;
23
+ private maybeCheckpointWal;
24
+ private ensureLegacyQueueMigrated;
25
+ getQueueEntries(meshId: string, statuses?: MeshTaskStatus[]): MeshWorkQueueEntry[];
26
+ getQueueRevision(meshId: string): string;
27
+ replaceQueue(meshId: string, queue: MeshWorkQueueEntry[]): void;
28
+ deleteQueue(meshId: string): void;
29
+ insertQueueEntry(entry: MeshWorkQueueEntry): void;
30
+ updateQueueEntry(entry: MeshWorkQueueEntry): void;
31
+ findQueueEntryById(meshId: string, id: string): MeshWorkQueueEntry | null;
32
+ hasActiveAssignment(meshId: string, sessionId: string, nodeId: string): boolean;
33
+ claimNextQueueTask(meshId: string, nodeId: string, sessionId: string, capabilityTags?: string[]): MeshWorkQueueEntry | null;
34
+ getQueueStatsByStatus(meshId: string): {
35
+ status: string;
36
+ count: number;
37
+ }[];
38
+ getActiveAssignmentDetails(meshId: string): Array<{
39
+ id: string;
40
+ nodeId?: string;
41
+ sessionId?: string;
42
+ message: string;
43
+ }>;
44
+ findAssignedBySession(meshId: string, sessionId: string, occurredAtIso?: string): MeshWorkQueueEntry | null;
45
+ private toRow;
46
+ insertDirectDispatch(entry: {
47
+ taskId: string;
48
+ meshId: string;
49
+ nodeId?: string;
50
+ sessionId?: string;
51
+ providerType?: string;
52
+ message: string;
53
+ taskMode?: string;
54
+ via: string;
55
+ dispatchedToIdleSession?: boolean;
56
+ dispatchedAt: string;
57
+ }): void;
58
+ getActiveDirectDispatches(meshId: string): Array<{
59
+ taskId: string;
60
+ meshId: string;
61
+ nodeId: string | null;
62
+ sessionId: string | null;
63
+ providerType: string | null;
64
+ message: string;
65
+ taskMode: string | null;
66
+ via: string;
67
+ status: string;
68
+ dispatchedToIdleSession: boolean;
69
+ dispatchedAt: string;
70
+ updatedAt: string;
71
+ }>;
72
+ updateDirectDispatchStatus(meshId: string, sessionId: string, status: 'acked' | 'completed' | 'failed' | 'stale'): void;
73
+ cleanupTerminalDirectDispatches(olderThanMs: number): void;
74
+ deleteDirectDispatches(meshId: string): void;
75
+ /**
76
+ * Delete specific direct dispatch rows by taskId for a mesh. Used by the staleDirect prune
77
+ * path to remove orphaned/terminal dispatch records whose node/session is no longer in the
78
+ * live mesh. Returns the number of rows actually deleted. No-op for an empty taskId list.
79
+ */
80
+ deleteDirectDispatchesByTaskId(meshId: string, taskIds: string[]): number;
81
+ markStaleDirectDispatches(meshId: string, olderThanMs: number): void;
82
+ setRemoteIdleSession(nodeId: string, sessionId: string, providerType: string, expiresAt: number, metadata?: any): void;
83
+ getRemoteIdleSessions(): Array<{
84
+ nodeId: string;
85
+ sessionId: string;
86
+ providerType: string;
87
+ expiresAt: number;
88
+ metadata?: any;
89
+ }>;
90
+ deleteRemoteIdleSession(nodeId: string, sessionId: string): void;
91
+ pruneExpiredRemoteIdleSessions(): void;
92
+ insertSessionDelivery(entry: {
93
+ id: string;
94
+ meshId: string;
95
+ nodeId?: string;
96
+ sessionId?: string;
97
+ providerType?: string;
98
+ taskId?: string;
99
+ kind: string;
100
+ priority?: number;
101
+ message: string;
102
+ status: string;
103
+ deliverAfter?: string;
104
+ expiresAt?: string;
105
+ sourceCoordinatorSessionId?: string;
106
+ sourceCoordinatorDaemonId?: string;
107
+ createdAt: string;
108
+ updatedAt: string;
109
+ }): void;
110
+ updateSessionDeliveryStatus(id: string, status: string, opts?: {
111
+ lastError?: string;
112
+ incrementAttempt?: boolean;
113
+ }): void;
114
+ getActiveSessionDeliveries(meshId: string, sessionId?: string): Array<{
115
+ id: string;
116
+ meshId: string;
117
+ nodeId: string | null;
118
+ sessionId: string | null;
119
+ providerType: string | null;
120
+ taskId: string | null;
121
+ kind: string;
122
+ priority: number;
123
+ message: string;
124
+ status: string;
125
+ deliverAfter: string | null;
126
+ expiresAt: string | null;
127
+ attemptCount: number;
128
+ sourceCoordinatorSessionId: string | null;
129
+ sourceCoordinatorDaemonId: string | null;
130
+ lastError: string | null;
131
+ createdAt: string;
132
+ updatedAt: string;
133
+ }>;
134
+ expireStaleSessionDeliveries(meshId: string): void;
135
+ deleteSessionDeliveries(meshId: string): void;
136
+ recordCompletionConflict(entry: {
137
+ id: string;
138
+ meshId: string;
139
+ fingerprint: string;
140
+ conflictingTaskId?: string;
141
+ conflictingSessionId?: string;
142
+ originalTaskId?: string;
143
+ originalSessionId?: string;
144
+ event: string;
145
+ createdAt: string;
146
+ }): void;
147
+ getRecentCompletionConflicts(meshId: string, limitMs?: number): Array<{
148
+ id: string;
149
+ meshId: string;
150
+ fingerprint: string;
151
+ conflictingTaskId: string | null;
152
+ conflictingSessionId: string | null;
153
+ originalTaskId: string | null;
154
+ originalSessionId: string | null;
155
+ event: string;
156
+ createdAt: string;
157
+ }>;
158
+ /**
159
+ * Record a mesh tool call and check whether this mesh+tool combination is
160
+ * being called too rapidly (sliding window rate guard).
161
+ *
162
+ * Returns a rate-limit advisory string when the call rate is too high, null otherwise.
163
+ * windowMs: sliding window size in ms (default 10s)
164
+ * maxCalls: max allowed calls within the window (default 5)
165
+ */
166
+ recordMeshToolCall(opts: {
167
+ meshId: string;
168
+ tool: string;
169
+ sessionId?: string | null;
170
+ windowMs?: number;
171
+ maxCalls?: number;
172
+ }): {
173
+ rateLimitExceeded: boolean;
174
+ callsInWindow: number;
175
+ advisory: string | null;
176
+ };
177
+ /**
178
+ * Prune tool call log entries older than the given age in ms.
179
+ * Exposed for testing.
180
+ */
181
+ pruneToolCallLog(olderThanMs: number): void;
182
+ appendLedgerEntry(entry: {
183
+ id: string;
184
+ meshId: string;
185
+ timestamp: string;
186
+ kind: string;
187
+ nodeId?: string | null;
188
+ sessionId?: string | null;
189
+ providerType?: string | null;
190
+ payload?: unknown;
191
+ }): void;
192
+ readLedgerEntries(meshId: string, opts?: {
193
+ tail?: number;
194
+ since?: string;
195
+ kind?: string;
196
+ limit?: number;
197
+ }): Array<{
198
+ id: string;
199
+ meshId: string;
200
+ timestamp: string;
201
+ kind: string;
202
+ nodeId: string | null;
203
+ sessionId: string | null;
204
+ providerType: string | null;
205
+ payload: unknown;
206
+ }>;
207
+ /**
208
+ * G2 read cutover: read ledger entries in append order (oldest first),
209
+ * matching legacy JSONL file-order semantics. Ties on the same timestamp
210
+ * are broken by rowid (insertion order), preserving the positional
211
+ * guarantee that mesh-events relies on for same-millisecond entries.
212
+ */
213
+ readLedgerEntriesOrdered(meshId: string, opts?: {
214
+ since?: string;
215
+ kinds?: string[];
216
+ tail?: number;
217
+ }): Array<{
218
+ id: string;
219
+ meshId: string;
220
+ timestamp: string;
221
+ kind: string;
222
+ nodeId: string | null;
223
+ sessionId: string | null;
224
+ providerType: string | null;
225
+ payload: unknown;
226
+ }>;
227
+ /** Remove all ledger entries for a mesh (mesh deletion / test cleanup). */
228
+ clearLedgerForMesh(meshId: string): number;
229
+ /** G2: remove entries moved to the JSONL archive so the SQLite runtime set mirrors the active ledger. */
230
+ deleteLedgerEntries(meshId: string, ids: string[]): number;
231
+ hasLedgerEntry(meshId: string, id: string): boolean;
232
+ ledgerEntryCount(meshId: string): number;
233
+ importLedgerEntries(entries: Array<{
234
+ id: string;
235
+ meshId: string;
236
+ timestamp: string;
237
+ kind: string;
238
+ nodeId?: string | null;
239
+ sessionId?: string | null;
240
+ providerType?: string | null;
241
+ payload?: unknown;
242
+ }>): number;
243
+ /**
244
+ * G4: Read a bounded, cursor-addressable ledger slice directly from the SQLite
245
+ * mesh_event_ledger table. This is the P2P reconcile read path; JSONL files are
246
+ * retained as export/import/debug/legacy artifacts only.
247
+ *
248
+ * The return shape is structurally compatible with MeshLedgerSlice so callers
249
+ * in mesh-tools.ts can pass it directly to buildMeshLedgerReplicaEvidence.
250
+ */
251
+ readLedgerSlice(meshId: string, opts?: {
252
+ afterId?: string;
253
+ since?: string;
254
+ kind?: string;
255
+ limit?: number;
256
+ }): {
257
+ protocol: 'adhdev.mesh.ledger.slice.v1';
258
+ meshId: string;
259
+ entries: Array<{
260
+ id: string;
261
+ meshId: string;
262
+ timestamp: string;
263
+ kind: string;
264
+ nodeId: string | null;
265
+ sessionId: string | null;
266
+ providerType: string | null;
267
+ payload: unknown;
268
+ }>;
269
+ cursor: {
270
+ afterId: string | null;
271
+ nextAfterId: string | null;
272
+ limit: number;
273
+ hasMore: boolean;
274
+ };
275
+ sourceOfTruth: {
276
+ kind: 'local_sqlite';
277
+ table: 'mesh_event_ledger';
278
+ bounded: true;
279
+ maxLimit: number;
280
+ };
281
+ };
282
+ insertPendingEvent(event: {
283
+ id: string;
284
+ meshId: string;
285
+ coordinatorDaemonId?: string | null;
286
+ event: string;
287
+ payload?: unknown;
288
+ fingerprint?: string | null;
289
+ queuedAt: number;
290
+ }): boolean;
291
+ /**
292
+ * Drain undrained pending events for a mesh, atomically marking them drained.
293
+ * When `opts.onlyEvents` is supplied, ONLY rows whose `event` is in that set are
294
+ * drained — the rest stay queued (drained=0) for a later drain. This is how the
295
+ * reconcile loop force-drains terminal/force-inject events into a *generating*
296
+ * coordinator while leaving non-force progress events for the coordinator's next
297
+ * idle transition. Filtering happens inside the same transaction as the
298
+ * drained=1 marking, so force-drain + a concurrent full drain can never both
299
+ * consume the same row.
300
+ */
301
+ drainPendingEvents(meshId: string, coordinatorDaemonId?: string | null | ReadonlyArray<string>, opts?: {
302
+ onlyEvents?: ReadonlySet<string>;
303
+ }): Array<{
304
+ id: string;
305
+ event: string;
306
+ payload: unknown;
307
+ }>;
308
+ /** Non-destructive peek — returns undrained events without marking them drained. */
309
+ peekPendingEvents(meshId: string, coordinatorDaemonId?: string | null | ReadonlyArray<string>): Array<{
310
+ id: string;
311
+ event: string;
312
+ payload: unknown;
313
+ }>;
314
+ hasPendingEventFingerprint(meshId: string, fingerprint: string): boolean;
315
+ upsertMission(mission: {
316
+ id: string;
317
+ meshId: string;
318
+ title: string;
319
+ goal?: string;
320
+ status?: string;
321
+ }): void;
322
+ getMission(meshId: string, missionId: string): {
323
+ id: string;
324
+ meshId: string;
325
+ title: string;
326
+ goal: string;
327
+ status: string;
328
+ createdAt: string;
329
+ updatedAt: string;
330
+ } | null;
331
+ getMissions(meshId: string, statuses?: string[]): Array<{
332
+ id: string;
333
+ meshId: string;
334
+ title: string;
335
+ goal: string;
336
+ status: string;
337
+ createdAt: string;
338
+ updatedAt: string;
339
+ }>;
340
+ /** Remove all missions for a mesh — mesh deletion / test cleanup. */
341
+ clearMissionsForMesh(meshId: string): number;
342
+ /** Remove all pending-event rows (drained included) for a mesh — mesh deletion / test cleanup. */
343
+ clearPendingEventsForMesh(meshId: string): number;
344
+ pendingEventCount(meshId: string): number;
345
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * M7: Operational stats (time/attempts) derived from existing truth.
3
+ *
4
+ * No cost/token accounting — ADHDev observes PTY/CDP and cannot see API
5
+ * tokens (explicit non-goal). Everything here is derived at query time from
6
+ * the SQLite ledger and queue rows; there is no separate aggregate table.
7
+ * Tasks with missing ledger evidence report incompleteEvidence instead of
8
+ * estimated numbers.
9
+ */
10
+ export interface MeshTaskStats {
11
+ taskId: string;
12
+ status: string;
13
+ dispatchedAt: string | null;
14
+ terminalAt: string | null;
15
+ terminalKind: 'task_completed' | 'task_failed' | null;
16
+ /** dispatched → terminal wall clock; null when evidence is incomplete. */
17
+ durationMs: number | null;
18
+ /** Number of task_dispatched ledger entries observed for this task. */
19
+ dispatchCount: number;
20
+ /** Queue requeueCount (0 when the row is gone or never requeued). */
21
+ requeueCount: number;
22
+ /** True when dispatch or terminal ledger evidence is missing — numbers are withheld, never estimated. */
23
+ incompleteEvidence?: true;
24
+ }
25
+ export interface MeshMissionStats {
26
+ missionId: string;
27
+ taskCount: number;
28
+ completed: number;
29
+ failed: number;
30
+ /** Sum of per-task durations with complete evidence. */
31
+ totalDurationMs: number;
32
+ /** First dispatch → last terminal across the mission's tasks; null without complete endpoints. */
33
+ wallClockMs: number | null;
34
+ /** Total requeue attempts across the mission's tasks. */
35
+ retries: number;
36
+ /** Task ids whose ledger evidence was incomplete (excluded from sums). */
37
+ incompleteTaskIds: string[];
38
+ }
39
+ /**
40
+ * Compute per-task stats from ledger entries. Scans a bounded tail window —
41
+ * stats are an operational view of recent work, not a full historical report.
42
+ */
43
+ export declare function computeMeshTaskStats(meshId: string, opts?: {
44
+ taskIds?: string[];
45
+ missionId?: string;
46
+ tail?: number;
47
+ }): MeshTaskStats[];
48
+ /** Mission rollup — derived from per-task stats, no stored aggregates. */
49
+ export declare function computeMeshMissionStats(meshId: string, missionId: string): MeshMissionStats;