@adhdev/daemon-core 0.9.82-rc.26 → 0.9.82-rc.260

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 (274) hide show
  1. package/dist/boot/daemon-lifecycle.d.ts +4 -0
  2. package/dist/boot/process-hardening.d.ts +50 -0
  3. package/dist/chat/source-machine.d.ts +166 -0
  4. package/dist/chat/source-resolver.d.ts +104 -0
  5. package/dist/chat/subscription-updates.d.ts +1 -0
  6. package/dist/cli-adapter-types.d.ts +23 -2
  7. package/dist/cli-adapters/cli-script-runner.d.ts +117 -0
  8. package/dist/cli-adapters/cli-state-engine.d.ts +198 -0
  9. package/dist/cli-adapters/provider-cli-adapter.d.ts +106 -63
  10. package/dist/cli-adapters/provider-cli-parse.d.ts +4 -0
  11. package/dist/cli-adapters/provider-cli-shared.d.ts +38 -0
  12. package/dist/cli-adapters/raw-terminal-io.d.ts +37 -0
  13. package/dist/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +3 -3
  14. package/dist/cli-adapters/terminal-backends/types.d.ts +1 -2
  15. package/dist/cli-adapters/terminal-screen.d.ts +2 -11
  16. package/dist/commands/cli-manager.d.ts +2 -1
  17. package/dist/commands/handler.d.ts +110 -0
  18. package/dist/commands/mesh-coordinator.d.ts +85 -1
  19. package/dist/commands/router.d.ts +44 -1
  20. package/dist/config/chat-history.d.ts +9 -0
  21. package/dist/config/config.d.ts +5 -0
  22. package/dist/config/mesh-config.d.ts +72 -1
  23. package/dist/git/git-commands.d.ts +9 -1
  24. package/dist/git/git-diff.d.ts +6 -0
  25. package/dist/git/git-types.d.ts +2 -0
  26. package/dist/index.d.ts +47 -11
  27. package/dist/index.js +31689 -11929
  28. package/dist/index.js.map +1 -1
  29. package/dist/index.mjs +30983 -11319
  30. package/dist/index.mjs.map +1 -1
  31. package/dist/installer.d.ts +1 -4
  32. package/dist/ipc/local-ipc-server.d.ts +91 -0
  33. package/dist/launch.d.ts +1 -1
  34. package/dist/logging/async-batch-writer.d.ts +10 -0
  35. package/dist/mesh/contracts.d.ts +164 -0
  36. package/dist/mesh/coordinator-prompt.d.ts +36 -0
  37. package/dist/mesh/coordinator-registry.d.ts +59 -0
  38. package/dist/mesh/mesh-active-work.d.ts +90 -0
  39. package/dist/mesh/mesh-delivery-policy.d.ts +131 -0
  40. package/dist/mesh/mesh-events-coordinator.d.ts +152 -0
  41. package/dist/mesh/mesh-events-pending.d.ts +40 -0
  42. package/dist/mesh/mesh-events-stale.d.ts +40 -0
  43. package/dist/mesh/mesh-events-utils.d.ts +16 -0
  44. package/dist/mesh/mesh-events.d.ts +5 -49
  45. package/dist/mesh/mesh-fast-forward.d.ts +41 -0
  46. package/dist/mesh/mesh-host-ownership.d.ts +9 -0
  47. package/dist/mesh/mesh-ledger-reconciliation.d.ts +23 -3
  48. package/dist/mesh/mesh-ledger.d.ts +77 -1
  49. package/dist/mesh/mesh-missions.d.ts +58 -0
  50. package/dist/mesh/mesh-refine-batch.d.ts +68 -0
  51. package/dist/mesh/mesh-refine-status.d.ts +62 -0
  52. package/dist/mesh/mesh-review-inbox.d.ts +90 -0
  53. package/dist/mesh/mesh-routing.d.ts +70 -0
  54. package/dist/mesh/mesh-runtime-store.d.ts +327 -0
  55. package/dist/mesh/mesh-task-stats.d.ts +49 -0
  56. package/dist/mesh/mesh-work-queue.d.ts +160 -5
  57. package/dist/mesh/preview-freshness.d.ts +18 -0
  58. package/dist/mesh/refine-config.d.ts +215 -0
  59. package/dist/mesh/worktree-bootstrap-config.d.ts +135 -0
  60. package/dist/providers/acp-provider-instance.d.ts +2 -0
  61. package/dist/providers/approval-utils.d.ts +13 -0
  62. package/dist/providers/cli-provider-instance.d.ts +37 -3
  63. package/dist/providers/contracts.d.ts +130 -6
  64. package/dist/providers/external-sources.d.ts +71 -0
  65. package/dist/providers/native-history/antigravity-cli-transcript.d.ts +100 -0
  66. package/dist/providers/native-history/claude-cli-transcript.d.ts +70 -0
  67. package/dist/providers/native-history/codex-cli-transcript.d.ts +73 -0
  68. package/dist/providers/native-history/dispatcher.d.ts +27 -0
  69. package/dist/providers/native-history/hermes-cli-transcript.d.ts +30 -0
  70. package/dist/providers/native-history/index.d.ts +13 -0
  71. package/dist/providers/provider-instance-manager.d.ts +13 -0
  72. package/dist/providers/provider-instance.d.ts +13 -1
  73. package/dist/providers/provider-loader.d.ts +26 -4
  74. package/dist/providers/provider-trust.d.ts +31 -0
  75. package/dist/providers/read-chat-contract.d.ts +29 -0
  76. package/dist/providers/sdk/v1/builders/acp/detect-status.d.ts +68 -0
  77. package/dist/providers/sdk/v1/builders/cli/detect-status.d.ts +85 -0
  78. package/dist/providers/sdk/v1/builders/cli/parse-approval-squash.d.ts +59 -0
  79. package/dist/providers/sdk/v1/builders/cli/parse-approval.d.ts +65 -0
  80. package/dist/providers/sdk/v1/builders/cli/parse-session.d.ts +91 -0
  81. package/dist/providers/sdk/v1/builders/cli/visible-region.d.ts +42 -0
  82. package/dist/providers/sdk/v1/fixture-tooling/format.d.ts +126 -0
  83. package/dist/providers/sdk/v1/fixture-tooling/index.d.ts +8 -0
  84. package/dist/providers/sdk/v1/fixture-tooling/replay.d.ts +38 -0
  85. package/dist/providers/sdk/v1/index.d.ts +30 -0
  86. package/dist/providers/sdk/v1/sandbox/README-design.d.ts +193 -0
  87. package/dist/providers/sdk/v1/sandbox/require-whitelist.d.ts +74 -0
  88. package/dist/providers/sdk/v1/sandbox/script-runner.d.ts +98 -0
  89. package/dist/providers/sdk/v1/types/cli/index.d.ts +277 -0
  90. package/dist/providers/sdk/v1/types/common/index.d.ts +203 -0
  91. package/dist/providers/sdk/v1/validators/index.d.ts +5 -0
  92. package/dist/providers/sdk/v1/validators/manifest.d.ts +40 -0
  93. package/dist/providers/sdk/v1/validators/taint.d.ts +52 -0
  94. package/dist/providers/spec/adapter.d.ts +52 -0
  95. package/dist/providers/spec/cli-adapter.d.ts +102 -0
  96. package/dist/providers/spec/evaluator.d.ts +23 -0
  97. package/dist/providers/spec/fsm-driver.d.ts +232 -0
  98. package/dist/providers/spec/fsm-evaluator.d.ts +72 -0
  99. package/dist/providers/spec/fsm-loader.d.ts +14 -0
  100. package/dist/providers/spec/fsm-types.d.ts +91 -0
  101. package/dist/providers/spec/native-history-executor.d.ts +41 -0
  102. package/dist/providers/spec/route.d.ts +4 -0
  103. package/dist/providers/spec/types.d.ts +129 -0
  104. package/dist/providers/transcript-v2.d.ts +176 -0
  105. package/dist/providers/types/interactive-prompt.d.ts +48 -0
  106. package/dist/repo-mesh-types.d.ts +126 -1
  107. package/dist/sessions/registry.d.ts +6 -0
  108. package/dist/shared-types-extra.d.ts +2 -4
  109. package/dist/shared-types.d.ts +42 -1
  110. package/dist/status/normalize.d.ts +1 -1
  111. package/dist/status/normalize.js +1 -0
  112. package/dist/status/normalize.js.map +1 -1
  113. package/dist/status/normalize.mjs +1 -0
  114. package/dist/status/normalize.mjs.map +1 -1
  115. package/dist/status/reporter.d.ts +2 -0
  116. package/dist/status/snapshot.d.ts +1 -0
  117. package/dist/types.d.ts +5 -0
  118. package/package.json +6 -3
  119. package/src/agent-stream/poller.ts +2 -3
  120. package/src/boot/daemon-lifecycle.ts +30 -10
  121. package/src/boot/process-hardening.ts +89 -0
  122. package/src/chat/source-machine.ts +534 -0
  123. package/src/chat/source-resolver.ts +0 -0
  124. package/src/chat/subscription-updates.ts +20 -1
  125. package/src/cli-adapter-types.d.ts +1 -0
  126. package/src/cli-adapter-types.ts +22 -2
  127. package/src/cli-adapters/cli-script-runner.ts +421 -0
  128. package/src/cli-adapters/cli-state-engine.ts +1215 -0
  129. package/src/cli-adapters/provider-cli-adapter.d.ts +1 -1
  130. package/src/cli-adapters/provider-cli-adapter.ts +674 -1139
  131. package/src/cli-adapters/provider-cli-parse.d.ts +1 -0
  132. package/src/cli-adapters/provider-cli-parse.ts +13 -0
  133. package/src/cli-adapters/provider-cli-runtime.ts +3 -1
  134. package/src/cli-adapters/provider-cli-shared.d.ts +2 -0
  135. package/src/cli-adapters/provider-cli-shared.ts +68 -11
  136. package/src/cli-adapters/raw-terminal-io.ts +252 -0
  137. package/src/cli-adapters/terminal-backends/ghostty-vt-backend.ts +35 -29
  138. package/src/cli-adapters/terminal-backends/types.ts +1 -3
  139. package/src/cli-adapters/terminal-screen.ts +11 -81
  140. package/src/commands/chat-commands.ts +1806 -60
  141. package/src/commands/cli-manager.ts +286 -14
  142. package/src/commands/handler.ts +809 -2
  143. package/src/commands/mesh-coordinator.ts +332 -122
  144. package/src/commands/router.ts +4890 -489
  145. package/src/config/chat-history.ts +95 -24
  146. package/src/config/config.ts +12 -0
  147. package/src/config/mesh-config.ts +303 -3
  148. package/src/config/recent-activity.ts +8 -2
  149. package/src/daemon/dev-auto-implement.ts +3 -2
  150. package/src/daemon/dev-cli-debug.ts +10 -1
  151. package/src/detection/ide-detector.ts +26 -16
  152. package/src/git/git-commands.ts +42 -12
  153. package/src/git/git-diff.ts +53 -0
  154. package/src/git/git-status.ts +35 -6
  155. package/src/git/git-types.ts +2 -0
  156. package/src/git/git-worktree.ts +8 -1
  157. package/src/index.ts +127 -10
  158. package/src/installer.d.ts +1 -1
  159. package/src/installer.ts +8 -6
  160. package/src/ipc/local-ipc-server.ts +278 -0
  161. package/src/launch.d.ts +1 -1
  162. package/src/launch.ts +37 -28
  163. package/src/logging/async-batch-writer.ts +55 -0
  164. package/src/logging/logger.ts +2 -1
  165. package/src/mesh/contracts.ts +329 -0
  166. package/src/mesh/coordinator-prompt.ts +219 -31
  167. package/src/mesh/coordinator-registry.ts +121 -0
  168. package/src/mesh/mesh-active-work.ts +437 -0
  169. package/src/mesh/mesh-delivery-policy.ts +315 -0
  170. package/src/mesh/mesh-events-coordinator.ts +1625 -0
  171. package/src/mesh/mesh-events-pending.ts +439 -0
  172. package/src/mesh/mesh-events-stale.ts +283 -0
  173. package/src/mesh/mesh-events-utils.ts +195 -0
  174. package/src/mesh/mesh-events.ts +26 -1035
  175. package/src/mesh/mesh-fast-forward.ts +438 -0
  176. package/src/mesh/mesh-host-ownership.ts +73 -0
  177. package/src/mesh/mesh-ledger-reconciliation.ts +12 -5
  178. package/src/mesh/mesh-ledger.ts +588 -102
  179. package/src/mesh/mesh-missions.ts +151 -0
  180. package/src/mesh/mesh-refine-batch.ts +197 -0
  181. package/src/mesh/mesh-refine-status.ts +231 -0
  182. package/src/mesh/mesh-review-inbox.ts +307 -0
  183. package/src/mesh/mesh-routing.ts +272 -0
  184. package/src/mesh/mesh-runtime-store.ts +1342 -0
  185. package/src/mesh/mesh-task-stats.ts +154 -0
  186. package/src/mesh/mesh-work-queue.ts +573 -145
  187. package/src/mesh/preview-freshness.ts +118 -0
  188. package/src/mesh/refine-config.ts +403 -0
  189. package/src/mesh/worktree-bootstrap-config.ts +326 -0
  190. package/src/providers/acp-provider-instance.ts +15 -1
  191. package/src/providers/approval-utils.d.ts +4 -0
  192. package/src/providers/approval-utils.ts +47 -5
  193. package/src/providers/chat-message-normalization.ts +4 -11
  194. package/src/providers/cli-provider-instance.ts +806 -72
  195. package/src/providers/contracts.d.ts +55 -0
  196. package/src/providers/contracts.ts +141 -6
  197. package/src/providers/external-sources.ts +218 -0
  198. package/src/providers/ide-provider-instance.ts +19 -5
  199. package/src/providers/native-history/antigravity-cli-transcript.ts +643 -0
  200. package/src/providers/native-history/claude-cli-transcript.ts +396 -0
  201. package/src/providers/native-history/codex-cli-transcript.ts +479 -0
  202. package/src/providers/native-history/dispatcher.ts +340 -0
  203. package/src/providers/native-history/hermes-cli-transcript.ts +230 -0
  204. package/src/providers/native-history/index.ts +30 -0
  205. package/src/providers/provider-instance-manager.ts +30 -0
  206. package/src/providers/provider-instance.ts +10 -1
  207. package/src/providers/provider-loader.ts +584 -50
  208. package/src/providers/provider-schema.ts +87 -14
  209. package/src/providers/provider-trust.ts +114 -0
  210. package/src/providers/read-chat-contract.ts +76 -16
  211. package/src/providers/sdk/README.md +49 -0
  212. package/src/providers/sdk/v1/builders/acp/detect-status.ts +144 -0
  213. package/src/providers/sdk/v1/builders/cli/detect-status.ts +262 -0
  214. package/src/providers/sdk/v1/builders/cli/parse-approval-squash.ts +158 -0
  215. package/src/providers/sdk/v1/builders/cli/parse-approval.ts +250 -0
  216. package/src/providers/sdk/v1/builders/cli/parse-session.ts +276 -0
  217. package/src/providers/sdk/v1/builders/cli/visible-region.ts +143 -0
  218. package/src/providers/sdk/v1/fixture-tooling/format.ts +130 -0
  219. package/src/providers/sdk/v1/fixture-tooling/index.ts +22 -0
  220. package/src/providers/sdk/v1/fixture-tooling/replay.ts +352 -0
  221. package/src/providers/sdk/v1/index.ts +152 -0
  222. package/src/providers/sdk/v1/sandbox/README-design.ts +195 -0
  223. package/src/providers/sdk/v1/sandbox/require-whitelist.ts +472 -0
  224. package/src/providers/sdk/v1/sandbox/script-runner.ts +150 -0
  225. package/src/providers/sdk/v1/schemas/cli/provider.schema.json +504 -0
  226. package/src/providers/sdk/v1/schemas/primitives/acp-session-protocol-v1.json +131 -0
  227. package/src/providers/sdk/v1/schemas/primitives/native-history-codex-rollout-v1.json +66 -0
  228. package/src/providers/sdk/v1/schemas/primitives/tui-approval-squash-v1.json +91 -0
  229. package/src/providers/sdk/v1/schemas/primitives/tui-assistant-block-v1.json +91 -0
  230. package/src/providers/sdk/v1/schemas/primitives/tui-cue-ordering-v1.json +47 -0
  231. package/src/providers/sdk/v1/schemas/primitives/tui-dispatch-order-v1.json +32 -0
  232. package/src/providers/sdk/v1/schemas/primitives/tui-footer-chrome-v1.json +42 -0
  233. package/src/providers/sdk/v1/schemas/primitives/tui-index-finder-v1.json +27 -0
  234. package/src/providers/sdk/v1/schemas/primitives/tui-modal-v1.json +125 -0
  235. package/src/providers/sdk/v1/schemas/primitives/tui-prompt-marker-v1.json +45 -0
  236. package/src/providers/sdk/v1/schemas/primitives/tui-session-id-extraction-v1.json +46 -0
  237. package/src/providers/sdk/v1/schemas/primitives/tui-settled-prompt-v1.json +71 -0
  238. package/src/providers/sdk/v1/schemas/primitives/tui-spinner-v1.json +83 -0
  239. package/src/providers/sdk/v1/schemas/primitives/tui-transcript-pty-v1.json +83 -0
  240. package/src/providers/sdk/v1/schemas/primitives/tui-visible-region-v1.json +57 -0
  241. package/src/providers/sdk/v1/schemas/primitives/tui-welcome-screen-v1.json +35 -0
  242. package/src/providers/sdk/v1/types/cli/index.ts +365 -0
  243. package/src/providers/sdk/v1/types/common/index.ts +229 -0
  244. package/src/providers/sdk/v1/validators/index.ts +19 -0
  245. package/src/providers/sdk/v1/validators/manifest.ts +110 -0
  246. package/src/providers/sdk/v1/validators/taint.ts +309 -0
  247. package/src/providers/spec/adapter.ts +138 -0
  248. package/src/providers/spec/cli-adapter.ts +650 -0
  249. package/src/providers/spec/evaluator.ts +321 -0
  250. package/src/providers/spec/fsm-driver.ts +754 -0
  251. package/src/providers/spec/fsm-evaluator.ts +255 -0
  252. package/src/providers/spec/fsm-loader.ts +102 -0
  253. package/src/providers/spec/fsm-types.ts +184 -0
  254. package/src/providers/spec/native-history-executor.ts +943 -0
  255. package/src/providers/spec/route.ts +51 -0
  256. package/src/providers/spec/types.ts +173 -0
  257. package/src/providers/transcript-v2.ts +567 -0
  258. package/src/providers/types/interactive-prompt.ts +425 -0
  259. package/src/providers/version-archive.ts +38 -20
  260. package/src/repo-mesh-types.ts +138 -1
  261. package/src/sessions/registry.ts +6 -0
  262. package/src/shared-types-extra.ts +2 -4
  263. package/src/shared-types.ts +45 -1
  264. package/src/status/builders.ts +26 -6
  265. package/src/status/normalize.ts +2 -0
  266. package/src/status/reporter.ts +15 -0
  267. package/src/status/snapshot.ts +84 -25
  268. package/src/system/host-memory.ts +29 -12
  269. package/src/types.ts +5 -0
  270. package/dist/cli-adapters/terminal-backends/xterm-backend.d.ts +0 -17
  271. package/dist/mesh/mesh-sync.d.ts +0 -53
  272. package/src/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +0 -16
  273. package/src/cli-adapters/terminal-backends/xterm-backend.ts +0 -97
  274. package/src/mesh/mesh-sync.ts +0 -111
@@ -0,0 +1,102 @@
1
+ import type { CliAdapter, CliAdapterStatus } from '../../cli-adapter-types.js';
2
+ import type { PtyTransportFactory } from '../../cli-adapters/pty-transport.js';
3
+ import { type InteractivePromptResponse } from '../types/interactive-prompt.js';
4
+ export declare class SpecCliAdapter implements CliAdapter {
5
+ readonly cliType: string;
6
+ readonly cliName: string;
7
+ readonly workingDir: string;
8
+ /**
9
+ * Marker the daemon's finalization gate checks: `getStatus()` returns
10
+ * `messages: []` by design here (chat history lives in the daemon's
11
+ * native-history pipeline, not the adapter). Without this flag,
12
+ * cli-provider-instance's `missing_final_assistant` gate would stall
13
+ * every turn until the 30s safety timeout because it expects the
14
+ * adapter to surface the final assistant message.
15
+ */
16
+ readonly chatMessagesOwnedExternally: true;
17
+ private driver;
18
+ /** Common spec fields the adapter reads, present in both v3 and v4. */
19
+ private spec;
20
+ private lastEvent;
21
+ private latestState;
22
+ private latestModal;
23
+ private statusCallback;
24
+ private ptyDataCallback;
25
+ private partialResponse;
26
+ private activeInteractivePrompt;
27
+ private interactivePromptTransport;
28
+ private claudeTuiPromptCaptureInFlight;
29
+ private jsonLineTail;
30
+ private exited;
31
+ private spawned;
32
+ private providerSessionId;
33
+ /** Wall clock at the moment spawn() ran. Used as the cutoff for
34
+ * native-history file selection so a prior session's transcript
35
+ * can't leak into this session before the agent has written its
36
+ * own records. */
37
+ private spawnedAtMs;
38
+ /** Env vars the daemon set on the spawned child. Mesh coordinator
39
+ * points hermes at a per-coordinator HERMES_HOME so the dashboard's
40
+ * native-history reader needs that override to find the right
41
+ * state.db; without it the reader sees ~/.hermes/state.db which
42
+ * the coordinator-launched hermes never writes to. The choice to
43
+ * redirect HERMES_HOME is a workaround for an unresolved hermes
44
+ * upstream feature gap (see hermes-agent#23130 — runtime-supplied
45
+ * MCP config), so this routing keeps the dashboard honest until
46
+ * hermes ships a runtime MCP override. */
47
+ private spawnedEnv;
48
+ constructor(specPath: string, workingDir: string, cliArgs: string[], extraEnv: Record<string, string>, transportFactory?: PtyTransportFactory);
49
+ spawn(): Promise<void>;
50
+ sendMessage(text: string): Promise<void>;
51
+ getStatus(): CliAdapterStatus;
52
+ private maybeRefreshNativeHistory;
53
+ getScriptParsedStatus(): unknown;
54
+ getPartialResponse(): string;
55
+ shutdown(): void;
56
+ cancel(): void;
57
+ isProcessing(): boolean;
58
+ isReady(): boolean;
59
+ setOnStatusChange(cb: () => void): void;
60
+ setOnPtyData(cb: (data: string) => void): void;
61
+ writeRaw(data: string): void;
62
+ resize(cols: number, rows: number): void;
63
+ resolveModal(buttonIndex: number): void;
64
+ resolveAction(data: unknown): Promise<void>;
65
+ setInteractivePromptResponse(response: InteractivePromptResponse): Promise<void>;
66
+ isApprovalRecentlyResolved(): boolean;
67
+ clearHistory(): void;
68
+ updateRuntimeSettings(): void;
69
+ setServerConn(): void;
70
+ /**
71
+ * Map an invokeScript(name, args) call onto a control_bar entry.
72
+ *
73
+ * scriptName is matched against control.id. The control's action.type
74
+ * drives the dispatch:
75
+ *
76
+ * send_keys → click_control (e.g. stop)
77
+ * open_picker → click_control then resolve when extract_choices
78
+ * surface; choice index comes from args.choiceIndex
79
+ * or args.choice (string label match), defaulting to 0
80
+ * attach_image → attach_image dispatch; expects args.blob (data url
81
+ * or base64) and args.mime
82
+ *
83
+ * Callers that pass an unknown control id get a { not_found } response.
84
+ * No control matched, no driver call — keeps the surface honest.
85
+ */
86
+ invokeScript(scriptName: string, args?: Record<string, unknown>): Promise<unknown>;
87
+ getDebugSnapshot(): unknown;
88
+ getRuntimeMetadata(): unknown;
89
+ updateRuntimeMeta(meta?: Record<string, unknown>): void;
90
+ refreshProviderDefinition(): void;
91
+ private handleEvent;
92
+ private detectInteractivePromptFromPtyChunk;
93
+ private readCurrentScreenSections;
94
+ private extractProviderSessionIdFromScreen;
95
+ private readClaudeScreenAssistantMessages;
96
+ private maybeCaptureClaudeTuiPrompt;
97
+ private readClaudeTuiHeaders;
98
+ private captureClaudeTuiPrompt;
99
+ getDebugState(): Record<string, any>;
100
+ getTraceState(limit?: number): Record<string, any>;
101
+ getProviderResolutionMeta(): Record<string, any>;
102
+ }
@@ -0,0 +1,23 @@
1
+ import type { SectionDef, Condition, ExtractTitle, ExtractButtons } from './types.js';
2
+ export interface ResolvedSection {
3
+ id: string;
4
+ fromLine: number;
5
+ toLine: number;
6
+ text: string;
7
+ }
8
+ export interface TraceEntry {
9
+ kind: 'section' | 'state_match' | 'state_skip' | 'modal' | 'control' | 'notification' | 'delegate';
10
+ text: string;
11
+ }
12
+ export declare function resolveSections(sectionsObj: Record<string, SectionDef>, lines: string[]): ResolvedSection[];
13
+ export declare function sectionText(sections: ResolvedSection[], sectionId: string | undefined, fullScreen: string): string;
14
+ export declare function evaluateCondition(cond: Condition, sections: ResolvedSection[], fullScreen: string, cursor: {
15
+ row: number;
16
+ col: number;
17
+ } | undefined, prevLines: string[] | undefined, trace: TraceEntry[], stateId: string): boolean;
18
+ export declare function extractTitle(rule: ExtractTitle, sections: ResolvedSection[], fullScreen: string): string | null;
19
+ export declare function extractButtonsFromRule(rule: ExtractButtons, hay: string): {
20
+ index: number;
21
+ label: string;
22
+ key: string;
23
+ }[];
@@ -0,0 +1,232 @@
1
+ import type { PtyTransportFactory } from '../../cli-adapters/pty-transport.js';
2
+ import { type TraceEntry } from './evaluator.js';
3
+ import { type TransitionEval } from './fsm-evaluator.js';
4
+ export type DashboardEvent = {
5
+ kind: 'pty_data';
6
+ chunk: string;
7
+ } | {
8
+ kind: 'state_changed';
9
+ state: {
10
+ id: string;
11
+ label: string;
12
+ title: string | null;
13
+ status: 'idle' | 'generating' | 'approval';
14
+ };
15
+ modal: {
16
+ title: string | null;
17
+ buttons: {
18
+ index: number;
19
+ label: string;
20
+ }[];
21
+ } | null;
22
+ controls: {
23
+ id: string;
24
+ label: string;
25
+ action_type: string;
26
+ }[];
27
+ } | {
28
+ kind: 'notification';
29
+ id: string;
30
+ title: string;
31
+ body: string;
32
+ } | {
33
+ kind: 'delegate';
34
+ id: string;
35
+ task: string;
36
+ } | {
37
+ kind: 'spec_trace';
38
+ entries: TraceEntry[];
39
+ } | {
40
+ kind: 'exit';
41
+ exit_code: number;
42
+ } | {
43
+ kind: 'spec_error';
44
+ errors: string[];
45
+ };
46
+ export type DashboardCommand = {
47
+ kind: 'send_message';
48
+ text: string;
49
+ } | {
50
+ kind: 'pty_write';
51
+ data: string;
52
+ } | {
53
+ kind: 'click_control';
54
+ control_id: string;
55
+ payload?: unknown;
56
+ } | {
57
+ kind: 'click_modal_button';
58
+ index: number;
59
+ } | {
60
+ kind: 'attach_image';
61
+ blob: string;
62
+ mime: string;
63
+ } | {
64
+ kind: 'resize';
65
+ cols: number;
66
+ rows: number;
67
+ } | {
68
+ kind: 'cancel';
69
+ } | {
70
+ kind: 'shutdown';
71
+ };
72
+ export interface DriverHistoryEntry {
73
+ stateId: string;
74
+ label: string;
75
+ at: number;
76
+ durationMs: number;
77
+ reason: string;
78
+ matchedStateId?: string;
79
+ matchedRules?: string[];
80
+ debounceKind?: string;
81
+ idleHoldMs?: number;
82
+ busyHoldMs?: number;
83
+ via?: string;
84
+ }
85
+ export interface ISpecDriver {
86
+ subscribe(listener: (ev: DashboardEvent) => void): () => void;
87
+ start(): void;
88
+ dispatch(cmd: DashboardCommand): void;
89
+ snapshot(): string;
90
+ getCursorPosition(): {
91
+ row: number;
92
+ col: number;
93
+ };
94
+ getScreen(): string;
95
+ getSpecPath(): string;
96
+ shutdown(): void;
97
+ getStateHistory(): ReadonlyArray<DriverHistoryEntry>;
98
+ getSections(): Array<{
99
+ id: string;
100
+ text: string;
101
+ }> | null;
102
+ getLastBusyAt(): number;
103
+ hasIdleHoldPending(): boolean;
104
+ getCompletionIdleDebounceState(): {
105
+ active: boolean;
106
+ ageMs: number;
107
+ holdMs: number;
108
+ forceAfterMs: number;
109
+ } | null;
110
+ getFsmDebug?(): unknown;
111
+ }
112
+ export interface SpecDriverOpts {
113
+ specPath: string;
114
+ workingDir: string;
115
+ extraEnv?: Record<string, string>;
116
+ cols?: number;
117
+ rows?: number;
118
+ hotReload?: boolean;
119
+ emitTrace?: boolean;
120
+ transportFactory?: PtyTransportFactory;
121
+ extraCliArgs?: string[];
122
+ }
123
+ export declare function resolveSubmitDelayMs(specBeforeSubmit: number | undefined, text: string): number;
124
+ export declare function guessExt(mime: string): string;
125
+ type HistoryEntry = DriverHistoryEntry;
126
+ export declare class FsmDriver implements ISpecDriver {
127
+ private readonly opts;
128
+ private spec;
129
+ private adapter;
130
+ private listeners;
131
+ private currentStateId;
132
+ private stateEnteredAt;
133
+ private startedAtMs;
134
+ private prevScreenLines;
135
+ /** Per cursor_above region (key: cursor_above, -1 = whole screen) → last
136
+ * time that region's content changed. Drives stable_ms conditions. */
137
+ private regionLastChangedAt;
138
+ /** Timer that re-runs evaluate() when a time-condition would flip true
139
+ * with no PTY frame to trigger it. */
140
+ private wakeTimer;
141
+ private currentEval;
142
+ private stateHistory;
143
+ private prevStateAt;
144
+ private readySeenOnce;
145
+ private pendingSends;
146
+ private pickerInProgress;
147
+ private delegateTimers;
148
+ private specWatcher;
149
+ /** Last full FSM evaluation, kept for the debugger. */
150
+ private lastFsmEval;
151
+ constructor(opts: SpecDriverOpts);
152
+ subscribe(listener: (ev: DashboardEvent) => void): () => void;
153
+ start(): void;
154
+ dispatch(cmd: DashboardCommand): void;
155
+ snapshot(): string;
156
+ getCursorPosition(): {
157
+ row: number;
158
+ col: number;
159
+ };
160
+ getScreen(): string;
161
+ getSpecPath(): string;
162
+ shutdown(): void;
163
+ getFsmDebug(): {
164
+ currentState: string;
165
+ label: string;
166
+ stateAgeMs: number;
167
+ status: string;
168
+ cursor: {
169
+ row: number;
170
+ col: number;
171
+ };
172
+ transitions: TransitionEval[];
173
+ };
174
+ getStateHistory(): ReadonlyArray<HistoryEntry>;
175
+ getSections(): Array<{
176
+ id: string;
177
+ text: string;
178
+ }> | null;
179
+ /** v3-compat shims so the cli-adapter's existing debug snapshot keeps
180
+ * working without branching on driver type. */
181
+ getLastBusyAt(): number;
182
+ hasIdleHoldPending(): boolean;
183
+ getCompletionIdleDebounceState(): {
184
+ active: boolean;
185
+ ageMs: number;
186
+ holdMs: number;
187
+ forceAfterMs: number;
188
+ } | null;
189
+ private loadSpecOrThrow;
190
+ private buildAdapterOpts;
191
+ private armSpecWatcher;
192
+ private emitInitialState;
193
+ private buildClock;
194
+ private evalFsmNow;
195
+ private reevaluate;
196
+ private commitTransition;
197
+ /** Re-derive the visible modal + controls for the current state and emit a
198
+ * state_changed if anything differs from the last emit. */
199
+ private emitStateChanged;
200
+ private deriveModal;
201
+ private deriveTitle;
202
+ private deriveControls;
203
+ /** Track which cursor_above regions changed since the previous frame so
204
+ * stable_ms conditions can measure quiet time. We record every region
205
+ * size referenced by a stable_ms condition in the spec, plus the whole
206
+ * screen (-1). */
207
+ private trackRegionChanges;
208
+ /** All cursor_above region sizes referenced by stable_ms conditions in the
209
+ * current state's outgoing transitions, plus whole-screen. Cached lazily
210
+ * per spec load would be nicer but the set is tiny. */
211
+ private stableRegionSizes;
212
+ /** Schedule a re-evaluation for the soonest pending time-condition on any
213
+ * outgoing transition (elapsed_ms / stable_ms / min_hold_ms). Without
214
+ * this, a state whose only exit is time-based would never leave once the
215
+ * PTY goes quiet. */
216
+ private scheduleWakeForState;
217
+ private maybeMarkReady;
218
+ private fireNotifications;
219
+ private armOrCancelDelegateTimers;
220
+ private fireDelegate;
221
+ private handleSendMessage;
222
+ private actuallySendMessage;
223
+ private handleClickControl;
224
+ private handleClickModalButton;
225
+ private handleAttachImage;
226
+ private tryAdvancePicker;
227
+ private handleExit;
228
+ private pushHistory;
229
+ private specTag;
230
+ private emit;
231
+ }
232
+ export {};
@@ -0,0 +1,72 @@
1
+ import type { SectionDef } from './types.js';
2
+ import { type ResolvedSection, type TraceEntry } from './evaluator.js';
3
+ import { type CliSpecV4, type FsmCondition } from './fsm-types.js';
4
+ export interface FsmClock {
5
+ /** Wall-clock now (ms). Passed in so the evaluator stays pure. */
6
+ now: number;
7
+ /** When the current state was entered (ms). */
8
+ stateEnteredAt: number;
9
+ /** Last-changed timestamp per cursor_above region. Key = cursor_above
10
+ * value (0 / undefined → whole-screen, keyed as -1). Missing key means
11
+ * "never observed changing" → treated as stable since stateEnteredAt. */
12
+ regionLastChangedAt: Map<number, number>;
13
+ }
14
+ /** Per-condition evaluation detail — the debugging payload. */
15
+ export interface CondResult {
16
+ kind: 'regex' | 'changed' | 'elapsed' | 'stable' | 'all' | 'any' | 'not';
17
+ result: boolean;
18
+ detail: string;
19
+ /** Remaining ms until a time-based condition would flip to true. 0 if
20
+ * already true or not applicable. Lets the UI show a countdown. */
21
+ remainingMs?: number;
22
+ children?: CondResult[];
23
+ }
24
+ /** One evaluated transition with its full reasoning. */
25
+ export interface TransitionEval {
26
+ to: string;
27
+ label: string;
28
+ /** Did the `from` clause include the current state? (Always true for the
29
+ * transitions we return — kept for completeness.) */
30
+ eligible: boolean;
31
+ /** min_hold_ms guard satisfied? */
32
+ holdSatisfied: boolean;
33
+ holdRemainingMs: number;
34
+ /** Guard condition result (true if no `when`). */
35
+ condResult: boolean;
36
+ cond?: CondResult;
37
+ /** Overall: would this transition fire? */
38
+ fires: boolean;
39
+ priority: number;
40
+ }
41
+ export interface FsmEvaluation {
42
+ /** Sections resolved from the screen (shared with v3 shape). */
43
+ sections: ResolvedSection[];
44
+ /** Every outgoing transition from the current state, priority-ordered,
45
+ * each annotated with why it fired or didn't. */
46
+ transitions: TransitionEval[];
47
+ /** The transition that fires (first in priority order with fires===true),
48
+ * or null to stay in the current state. */
49
+ fired: TransitionEval | null;
50
+ /** v3-compatible trace lines for the legacy inspector. */
51
+ trace: TraceEntry[];
52
+ }
53
+ /**
54
+ * Evaluate the FSM: given the current state id and screen, return every
55
+ * outgoing transition annotated with why it fires/doesn't, plus the one that
56
+ * fires (if any).
57
+ */
58
+ export declare function evaluateFsm(spec: CliSpecV4, currentStateId: string, screenText: string, cursor: {
59
+ row: number;
60
+ col: number;
61
+ } | undefined, prevLines: string[] | undefined, clock: FsmClock): FsmEvaluation;
62
+ /**
63
+ * Evaluate a single condition against a screen + section map — for the spec
64
+ * editor's live preview ("does this regex match the current screen right
65
+ * now?"). Time leaves (elapsed_ms/stable_ms) are evaluated against a synthetic
66
+ * clock where the state was just entered, so they report their countdown
67
+ * rather than firing; the preview is about screen-content match, not timing.
68
+ */
69
+ export declare function evaluateConditionPreview(cond: FsmCondition, sections: Record<string, SectionDef> | undefined, screenText: string, cursor?: {
70
+ row: number;
71
+ col: number;
72
+ }): CondResult;
@@ -0,0 +1,14 @@
1
+ import { type CliSpecV4 } from './fsm-types.js';
2
+ export interface FsmLoadOk {
3
+ ok: true;
4
+ spec: CliSpecV4;
5
+ sourcePath: string;
6
+ }
7
+ export interface FsmLoadErr {
8
+ ok: false;
9
+ errors: string[];
10
+ sourcePath: string;
11
+ }
12
+ export declare function loadFsmSpec(sourcePath: string): FsmLoadOk | FsmLoadErr;
13
+ /** Pure validator — usable from a "validate before save" API in the panel. */
14
+ export declare function validateFsmSpec(raw: unknown): string[];
@@ -0,0 +1,91 @@
1
+ import type { RegexCondition, ChangedCondition, Control, NotificationRule, DelegateTrigger, NativeHistoryConfig, SectionDef, ExtractTitle, ExtractButtons } from './types.js';
2
+ /** True once `ms` have elapsed since the current state was entered. */
3
+ export interface ElapsedCondition {
4
+ elapsed_ms: number;
5
+ }
6
+ /** True once the region `cursor_above` lines above the cursor has been
7
+ * unchanged for `ms`. A stability gate — the inverse of a busy signal. */
8
+ export interface StableCondition {
9
+ stable_ms: number;
10
+ /** Lines above the cursor that must be stable. Default: whole screen. */
11
+ cursor_above?: number;
12
+ }
13
+ export interface FsmAllCondition {
14
+ all: FsmCondition[];
15
+ }
16
+ export interface FsmAnyCondition {
17
+ any: FsmCondition[];
18
+ }
19
+ /** Negation — true when the inner condition is false. Lets a transition say
20
+ * "go busy unless the completion marker is present", etc. */
21
+ export interface FsmNotCondition {
22
+ not: FsmCondition;
23
+ }
24
+ export type FsmCondition = RegexCondition | ChangedCondition | ElapsedCondition | StableCondition | FsmAllCondition | FsmAnyCondition | FsmNotCondition;
25
+ export interface FsmState {
26
+ id: string;
27
+ label: string;
28
+ /** Exactly one state must be `initial: true` — the state at spawn. */
29
+ initial?: boolean;
30
+ /** Modal states (approval/picker) expose modal buttons in the UI and are
31
+ * treated as "interesting" — the dashboard surfaces them distinctly. */
32
+ modal?: boolean;
33
+ /** Status this state maps to for the dashboard/cli-adapter status field.
34
+ * One of: idle | generating | approval. Defaults: modal→approval,
35
+ * initial→idle, id==='busy'→generating, else idle. Explicit wins. */
36
+ status?: 'idle' | 'generating' | 'approval';
37
+ /** Optional extraction run whenever this state is the committed state —
38
+ * used by modal states to surface a title + buttons. */
39
+ extract?: {
40
+ title?: ExtractTitle;
41
+ buttons?: ExtractButtons;
42
+ };
43
+ }
44
+ export interface FsmTransition {
45
+ /** Source state id, or list of source ids, or "*" for any state. */
46
+ from: string | string[];
47
+ /** Destination state id. */
48
+ to: string;
49
+ /** Guard condition. Omitted → always eligible (only gated by `from` +
50
+ * min_hold_ms). Evaluated against the current screen + clock. */
51
+ when?: FsmCondition;
52
+ /** Minimum time the machine must have been in `from` before this edge can
53
+ * fire. Replaces busy_hold_ms / idle_hold_ms (per-edge, not global). */
54
+ min_hold_ms?: number;
55
+ /** Higher priority transitions are evaluated first. Default 0. Ties broken
56
+ * by declaration order. */
57
+ priority?: number;
58
+ /** Human label for the debugger. */
59
+ label?: string;
60
+ }
61
+ export interface CliSpecV4 {
62
+ $schema: 'adhdev:cli/spec@4';
63
+ id: string;
64
+ name: string;
65
+ binary: string;
66
+ spawn_args?: string[];
67
+ env?: Record<string, string>;
68
+ cli_version_range?: string;
69
+ send_message: {
70
+ submit_key: string;
71
+ delay_ms_before_submit?: number;
72
+ delay_ms_per_char?: number;
73
+ };
74
+ sections: Record<string, SectionDef>;
75
+ states: FsmState[];
76
+ transitions: FsmTransition[];
77
+ control_bar?: Control[];
78
+ notifications?: NotificationRule[];
79
+ delegate?: DelegateTrigger[];
80
+ native_history?: NativeHistoryConfig;
81
+ requiresFinalAssistantBeforeIdle?: boolean;
82
+ }
83
+ export declare function isV4Spec(raw: unknown): raw is CliSpecV4;
84
+ export declare function initialState(spec: CliSpecV4): FsmState;
85
+ export declare function stateById(spec: CliSpecV4, id: string): FsmState | undefined;
86
+ /** Outgoing transitions from `stateId`, highest priority first, declaration
87
+ * order as tiebreak. Includes wildcard ("*") and list-membership sources. */
88
+ export declare function outgoingTransitions(spec: CliSpecV4, stateId: string): FsmTransition[];
89
+ /** Map a state to the dashboard status string, applying the documented
90
+ * defaults when `status` is not explicit. */
91
+ export declare function statusForState(state: FsmState): 'idle' | 'generating' | 'approval';
@@ -0,0 +1,41 @@
1
+ import type { NativeHistoryConfig } from './types.js';
2
+ export interface NativeHistoryInput {
3
+ agentType?: string;
4
+ sessionId?: string;
5
+ providerSessionId?: string;
6
+ historySessionId?: string;
7
+ workspace?: string;
8
+ /** Daemon-side wall clock at the moment the session was registered.
9
+ * Native-history file lookups use this as the lower bound: any file
10
+ * whose mtime is before the current session started can't be from
11
+ * this session, so it's excluded from newest-recent matching. The
12
+ * caller (chat-history pipeline) populates this from the session
13
+ * registry; specs/executor never need to know how it's sourced. */
14
+ sessionStartedAtMs?: number;
15
+ /** Env overrides the daemon set on the spawned CLI. The mesh
16
+ * coordinator points hermes at a per-coordinator HERMES_HOME so
17
+ * the hermes process writes its state.db into a tmp directory
18
+ * instead of ~/.hermes. expandPath consults this map before
19
+ * process.env so the native-history reader follows the spawned
20
+ * child's view of HERMES_HOME / similar overrides; without it
21
+ * the reader would always look at ~/.hermes and miss every
22
+ * coordinator-session transcript. */
23
+ envOverrides?: Record<string, string>;
24
+ args?: Record<string, unknown>;
25
+ }
26
+ export interface NativeHistoryMessage {
27
+ role: 'user' | 'assistant' | 'system';
28
+ content: string;
29
+ receivedAt: number;
30
+ kind?: string;
31
+ workspace?: string;
32
+ }
33
+ export interface NativeHistoryResult {
34
+ messages: NativeHistoryMessage[];
35
+ providerSessionId?: string;
36
+ sourcePath: string;
37
+ sourceMtimeMs: number;
38
+ nativeHistoryCoverage?: 'full' | 'partial' | 'best-effort';
39
+ workspace?: string;
40
+ }
41
+ export declare function executeNativeHistory(cfg: NativeHistoryConfig, input: NativeHistoryInput): NativeHistoryResult | null;
@@ -0,0 +1,4 @@
1
+ import type { CliProviderModule } from '../../cli-adapters/provider-cli-adapter.js';
2
+ import type { PtyTransportFactory } from '../../cli-adapters/pty-transport.js';
3
+ import type { CliAdapter } from '../../cli-adapter-types.js';
4
+ export declare function createCliAdapter(provider: CliProviderModule, workingDir: string, cliArgs: string[], extraEnv: Record<string, string>, transportFactory?: PtyTransportFactory): CliAdapter;