@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,650 @@
1
+ /**
2
+ * SpecCliAdapter — bridges SpecDriver into the daemon's CliAdapter
3
+ * interface so an existing CliProviderInstance can drive a spec-backed
4
+ * provider without rewriting the surrounding session machinery.
5
+ *
6
+ * Translation:
7
+ * spec state.id 'approval' (with modal_buttons that produced a modal)
8
+ * → CliAdapterStatus.status='waiting_approval', activeModal={...}
9
+ * spec state.id 'busy' / any non-decision state with a 'busy' label
10
+ * → status='generating'
11
+ * spec state.id 'idle' or default
12
+ * → status='idle'
13
+ *
14
+ * Methods that the round-3 spec model doesn't have an opinion on
15
+ * (transcript reading, slash commands, history, runtime metadata
16
+ * surfacing) are minimal stubs. They satisfy the daemon's call sites
17
+ * without pretending to implement anything.
18
+ */
19
+ 'use strict';
20
+
21
+ import { FsmDriver, type DashboardEvent, type ISpecDriver } from './fsm-driver.js';
22
+ import { executeNativeHistory } from './native-history-executor.js';
23
+ import * as fs from 'node:fs';
24
+ import type { NativeHistoryConfig, Control } from './types.js';
25
+ import type { CliAdapter, CliAdapterStatus } from '../../cli-adapter-types.js';
26
+ import type { ChatMessage } from '../../types.js';
27
+ import type { PtyTransportFactory } from '../../cli-adapters/pty-transport.js';
28
+ import { LOG } from '../../logging/logger.js';
29
+ import {
30
+ buildClaudeInteractiveTuiAnswerSteps,
31
+ buildClaudeInteractiveToolResult,
32
+ detectClaudeAskUserQuestionPromptFromJson,
33
+ detectClaudeAskUserQuestionPromptFromTuiPages,
34
+ type ClaudeInteractiveTuiPage,
35
+ type InteractivePrompt,
36
+ type InteractivePromptResponse,
37
+ } from '../types/interactive-prompt.js';
38
+
39
+
40
+ function stripAnsi(text: string): string {
41
+ // eslint-disable-next-line no-control-regex
42
+ return String(text || '')
43
+ .replace(/\x1B\][^\x07]*(?:\x07|\x1B\\)/g, '')
44
+ .replace(/\x1B[P^_X][\s\S]*?(?:\x07|\x1B\\)/g, '')
45
+ .replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, '');
46
+ }
47
+
48
+ export class SpecCliAdapter implements CliAdapter {
49
+ readonly cliType: string;
50
+ readonly cliName: string;
51
+ readonly workingDir: string;
52
+ /**
53
+ * Marker the daemon's finalization gate checks: `getStatus()` returns
54
+ * `messages: []` by design here (chat history lives in the daemon's
55
+ * native-history pipeline, not the adapter). Without this flag,
56
+ * cli-provider-instance's `missing_final_assistant` gate would stall
57
+ * every turn until the 30s safety timeout because it expects the
58
+ * adapter to surface the final assistant message.
59
+ */
60
+ readonly chatMessagesOwnedExternally = true as const;
61
+
62
+ private driver: ISpecDriver;
63
+ /** Common spec fields the adapter reads, present in both v3 and v4. */
64
+ private spec: {
65
+ id: string;
66
+ name: string;
67
+ control_bar?: Control[];
68
+ native_history?: NativeHistoryConfig;
69
+ };
70
+ private lastEvent: DashboardEvent | null = null;
71
+ private latestState: { id: string; label: string; title: string | null; status: 'idle' | 'generating' | 'approval' } | null = null;
72
+ private latestModal: { title: string | null; buttons: { index: number; label: string }[] } | null = null;
73
+ private statusCallback: (() => void) | null = null;
74
+ private ptyDataCallback: ((data: string) => void) | null = null;
75
+ private partialResponse = '';
76
+ private activeInteractivePrompt: InteractivePrompt | null = null;
77
+ private interactivePromptTransport: 'stream-json' | 'tui' | null = null;
78
+ private claudeTuiPromptCaptureInFlight = false;
79
+ private jsonLineTail = '';
80
+ private exited = false;
81
+ private spawned = false;
82
+ private providerSessionId: string | undefined;
83
+ /** Wall clock at the moment spawn() ran. Used as the cutoff for
84
+ * native-history file selection so a prior session's transcript
85
+ * can't leak into this session before the agent has written its
86
+ * own records. */
87
+ private spawnedAtMs = 0;
88
+ /** Env vars the daemon set on the spawned child. Mesh coordinator
89
+ * points hermes at a per-coordinator HERMES_HOME so the dashboard's
90
+ * native-history reader needs that override to find the right
91
+ * state.db; without it the reader sees ~/.hermes/state.db which
92
+ * the coordinator-launched hermes never writes to. The choice to
93
+ * redirect HERMES_HOME is a workaround for an unresolved hermes
94
+ * upstream feature gap (see hermes-agent#23130 — runtime-supplied
95
+ * MCP config), so this routing keeps the dashboard honest until
96
+ * hermes ships a runtime MCP override. */
97
+ private spawnedEnv: Record<string, string> = {};
98
+
99
+ constructor(
100
+ specPath: string,
101
+ workingDir: string,
102
+ cliArgs: string[],
103
+ extraEnv: Record<string, string>,
104
+ transportFactory?: PtyTransportFactory,
105
+ ) {
106
+ const raw = JSON.parse(fs.readFileSync(specPath, 'utf8'));
107
+ this.spec = {
108
+ id: raw.id,
109
+ name: raw.name,
110
+ control_bar: raw.control_bar,
111
+ native_history: raw.native_history,
112
+ };
113
+ this.cliType = this.spec.id;
114
+ this.cliName = this.spec.name;
115
+ this.workingDir = workingDir;
116
+ this.spawnedEnv = { ...extraEnv };
117
+
118
+ // cli-manager.ts allocates providerSessionId per launch and threads
119
+ // it through resume.newSessionArgs as additional cliArgs (e.g.
120
+ // ["--session-id", "<uuid>"]). We must hand those to the driver
121
+ // so the agent uses the daemon's id, otherwise (claude case) the
122
+ // agent generates its own id and the chat-history pipeline can't
123
+ // pair the on-disk transcript with the live session.
124
+ this.driver = new FsmDriver({
125
+ specPath,
126
+ workingDir,
127
+ extraEnv,
128
+ hotReload: true,
129
+ emitTrace: false,
130
+ transportFactory,
131
+ extraCliArgs: cliArgs,
132
+ });
133
+ this.driver.subscribe((ev) => this.handleEvent(ev));
134
+ }
135
+
136
+ async spawn(): Promise<void> {
137
+ if (this.spawned) return;
138
+ this.driver.start();
139
+ this.spawned = true;
140
+ this.spawnedAtMs = Date.now();
141
+ }
142
+
143
+ async sendMessage(text: string): Promise<void> {
144
+ // Content-free at info — the prompt body is user data.
145
+ LOG.info('SpecAdapter', `[${this.cliType}] sendMessage(len=${text.length})`);
146
+ LOG.debug('SpecAdapter', `[${this.cliType}] sendMessage body=${JSON.stringify(text.slice(0, 80))}${text.length > 80 ? '…' : ''}`);
147
+ this.driver.dispatch({ kind: 'send_message', text });
148
+ }
149
+
150
+ getStatus(): CliAdapterStatus {
151
+ const sessionFields = this.providerSessionId ? { providerSessionId: this.providerSessionId } : {};
152
+ if (this.exited) return { status: 'stopped', messages: [], activeModal: null, activeInteractivePrompt: this.activeInteractivePrompt, ...sessionFields };
153
+ if (!this.spawned) return { status: 'starting', messages: [], activeModal: null, activeInteractivePrompt: this.activeInteractivePrompt, ...sessionFields };
154
+
155
+ // Refresh native history lazily — the watch_path is cheap to stat,
156
+ // but parsing a full session.jsonl every call would be wasteful.
157
+ this.maybeRefreshNativeHistory();
158
+
159
+ const state = this.latestState;
160
+ if (!state) return { status: 'starting', messages: [], activeModal: null, activeInteractivePrompt: this.activeInteractivePrompt, ...sessionFields };
161
+
162
+ // The FSM state is authoritative for status. We do NOT infer status from whether
163
+ // a modal was parsed this frame: a modal/approval state whose buttons briefly fail
164
+ // to parse (PTY repaint) must still report waiting_approval, not collapse to idle —
165
+ // that collapse fired false completions while a session sat at an approval prompt.
166
+ const modal = this.latestModal;
167
+ if (state.status === 'approval') {
168
+ return {
169
+ status: 'waiting_approval',
170
+ messages: [],
171
+ // Surface buttons when we have them; an approval state with no parsed
172
+ // modal this frame still stays waiting_approval (no activeModal yet).
173
+ activeModal: modal
174
+ ? { message: modal.title ?? state.label, buttons: modal.buttons.map(b => b.label) }
175
+ : null,
176
+ activeInteractivePrompt: this.activeInteractivePrompt,
177
+ ...sessionFields,
178
+ };
179
+ }
180
+ if (state.status === 'generating') {
181
+ return { status: 'generating', messages: [], activeModal: null, activeInteractivePrompt: this.activeInteractivePrompt, ...sessionFields };
182
+ }
183
+ return { status: 'idle', messages: [], activeModal: null, activeInteractivePrompt: this.activeInteractivePrompt, ...sessionFields };
184
+ }
185
+
186
+ private maybeRefreshNativeHistory(): void {
187
+ // Native history is now sourced by daemon's chat-history pipeline
188
+ // (which calls provider.scripts.readNativeHistory wired by
189
+ // provider-loader). SpecCliAdapter no longer polls or caches.
190
+ }
191
+
192
+ getScriptParsedStatus(): unknown {
193
+ const providerSessionId = this.extractProviderSessionIdFromScreen();
194
+ if (providerSessionId) this.providerSessionId = providerSessionId;
195
+ const status = this.getStatus();
196
+ return {
197
+ ...status,
198
+ messages: this.readClaudeScreenAssistantMessages(),
199
+ ...(this.providerSessionId ? { providerSessionId: this.providerSessionId } : {}),
200
+ };
201
+ }
202
+
203
+ getPartialResponse(): string {
204
+ return this.partialResponse;
205
+ }
206
+
207
+ shutdown(): void {
208
+ try { this.driver.dispatch({ kind: 'shutdown' }); } catch { /* ignore */ }
209
+ }
210
+
211
+ cancel(): void {
212
+ try { this.driver.dispatch({ kind: 'cancel' }); } catch { /* ignore */ }
213
+ }
214
+
215
+ isProcessing(): boolean {
216
+ return this.getStatus().status === 'generating';
217
+ }
218
+
219
+ isReady(): boolean {
220
+ return this.spawned && !this.exited;
221
+ }
222
+
223
+ setOnStatusChange(cb: () => void): void {
224
+ this.statusCallback = cb;
225
+ }
226
+
227
+ setOnPtyData(cb: (data: string) => void): void {
228
+ this.ptyDataCallback = cb;
229
+ }
230
+
231
+ writeRaw(data: string): void {
232
+ // Raw pty input — typed characters, escape codes, arrow keys —
233
+ // goes straight to the underlying terminal. send_message would
234
+ // append submit_key after every chunk, which is why typing in
235
+ // the dashboard terminal felt like "enter on every keystroke".
236
+ this.driver.dispatch({ kind: 'pty_write', data });
237
+ }
238
+
239
+ resize(cols: number, rows: number): void {
240
+ this.driver.dispatch({ kind: 'resize', cols, rows });
241
+ }
242
+
243
+ resolveModal(buttonIndex: number): void {
244
+ // CliAdapter buttonIndex is 0-based; spec buttons are 1-based.
245
+ this.driver.dispatch({ kind: 'click_modal_button', index: buttonIndex + 1 });
246
+ }
247
+
248
+ async resolveAction(data: unknown): Promise<void> {
249
+ const args = (data && typeof data === 'object') ? (data as any) : {};
250
+ const explicitIndex = typeof args.buttonIndex === 'number' ? args.buttonIndex : -1;
251
+ if (explicitIndex >= 0) { this.resolveModal(explicitIndex); return; }
252
+ const action = typeof args.action === 'string' ? args.action : 'approve';
253
+ const buttons = this.latestModal?.buttons ?? [];
254
+ if (buttons.length === 0) return;
255
+ let target = -1;
256
+ if (action === 'reject' || action === 'deny') {
257
+ target = buttons.findIndex(b => /^(no|deny|reject|cancel)\b/i.test(b.label));
258
+ if (target < 0) target = buttons.length - 1;
259
+ } else {
260
+ target = buttons.findIndex(b => /^(yes|allow|approve|accept|continue|proceed|update)\b/i.test(b.label));
261
+ if (target < 0) target = 0;
262
+ }
263
+ this.resolveModal(target);
264
+ }
265
+
266
+ async setInteractivePromptResponse(response: InteractivePromptResponse): Promise<void> {
267
+ const prompt = this.activeInteractivePrompt;
268
+ if (!prompt || prompt.promptId !== response.promptId) throw new Error('Interactive prompt response does not match active prompt');
269
+ if (this.cliType !== 'claude-cli') return;
270
+ if (this.interactivePromptTransport === 'tui') {
271
+ const steps = buildClaudeInteractiveTuiAnswerSteps(prompt, response);
272
+ for (const step of steps) {
273
+ this.driver.dispatch({ kind: 'pty_write', data: step });
274
+ await new Promise(resolve => setTimeout(resolve, 180));
275
+ }
276
+ } else {
277
+ this.driver.dispatch({ kind: 'pty_write', data: `${buildClaudeInteractiveToolResult(response)}\n` });
278
+ }
279
+ this.activeInteractivePrompt = null;
280
+ this.interactivePromptTransport = null;
281
+ this.statusCallback?.();
282
+ }
283
+
284
+ isApprovalRecentlyResolved(): boolean { return false; }
285
+ clearHistory(): void { /* no transcript buffer yet */ }
286
+ updateRuntimeSettings(): void { /* no runtime settings in spec model yet */ }
287
+ setServerConn(): void { /* server conn unused by SpecDriver */ }
288
+ /**
289
+ * Map an invokeScript(name, args) call onto a control_bar entry.
290
+ *
291
+ * scriptName is matched against control.id. The control's action.type
292
+ * drives the dispatch:
293
+ *
294
+ * send_keys → click_control (e.g. stop)
295
+ * open_picker → click_control then resolve when extract_choices
296
+ * surface; choice index comes from args.choiceIndex
297
+ * or args.choice (string label match), defaulting to 0
298
+ * attach_image → attach_image dispatch; expects args.blob (data url
299
+ * or base64) and args.mime
300
+ *
301
+ * Callers that pass an unknown control id get a { not_found } response.
302
+ * No control matched, no driver call — keeps the surface honest.
303
+ */
304
+ invokeScript(scriptName: string, args?: Record<string, unknown>): Promise<unknown> {
305
+ const controls = this.spec.control_bar ?? [];
306
+ const ctl = controls.find(c => c.id === scriptName);
307
+ if (!ctl) {
308
+ return Promise.resolve({ ok: false, error: `unknown control: ${scriptName}` });
309
+ }
310
+ // Args may arrive as either { blob, mime } (direct invocation) or
311
+ // { params: { blob, mime } } (when the dashboard wraps script args
312
+ // in a params bag). Look at both.
313
+ const flat: Record<string, unknown> = { ...(args || {}) };
314
+ if (args && typeof args.params === 'object' && args.params) {
315
+ Object.assign(flat, args.params as Record<string, unknown>);
316
+ }
317
+ const action = ctl.action;
318
+ if (action.type === 'attach_image') {
319
+ const blob = typeof flat.blob === 'string' ? flat.blob : '';
320
+ const mime = typeof flat.mime === 'string' ? flat.mime : 'image/png';
321
+ if (!blob) return Promise.resolve({ ok: false, error: 'attach_image requires args.blob (base64 or data URL)' });
322
+ this.driver.dispatch({ kind: 'attach_image', blob, mime });
323
+ return Promise.resolve({ ok: true, effects: [{ type: 'attached_image', controlId: ctl.id }] });
324
+ }
325
+ // send_keys + open_picker both route through click_control. For
326
+ // open_picker the dashboard sees the picker modal arrive via a
327
+ // state_changed event, then submits the choice using
328
+ // resolveModal/click_modal_button. invokeScript's synchronous
329
+ // return is just an acknowledgement that the trigger fired.
330
+ this.driver.dispatch({ kind: 'click_control', control_id: ctl.id, payload: flat });
331
+ const effects: { type: string; controlId: string }[] = [];
332
+ if (action.type === 'open_picker') effects.push({ type: 'opened_picker', controlId: ctl.id });
333
+ else if (action.type === 'send_keys') effects.push({ type: 'sent_keys', controlId: ctl.id });
334
+ return Promise.resolve({ ok: true, effects });
335
+ }
336
+ getDebugSnapshot(): unknown {
337
+ let screen = '';
338
+ let sections: Record<string, string> | undefined;
339
+ try {
340
+ screen = this.driver.snapshot();
341
+ const driverSections = this.driver.getSections?.();
342
+ if (driverSections) {
343
+ sections = Object.fromEntries(driverSections.map(s => [s.id, s.text]));
344
+ } else {
345
+ sections = this.readCurrentScreenSections(screen);
346
+ }
347
+ } catch { /* best-effort */ }
348
+ // Read native transcript messages for the debug snapshot
349
+ let messages: any[] = [];
350
+ if (this.spec.native_history?.source) {
351
+ try {
352
+ const nhResult = executeNativeHistory(this.spec.native_history, {
353
+ agentType: this.cliType,
354
+ providerSessionId: this.providerSessionId,
355
+ sessionStartedAtMs: this.spawnedAtMs,
356
+ envOverrides: this.spawnedEnv,
357
+ workspace: this.workingDir,
358
+ });
359
+ if (nhResult && Array.isArray(nhResult.messages)) messages = nhResult.messages;
360
+ } catch { /* best-effort */ }
361
+ } else {
362
+ messages = this.readClaudeScreenAssistantMessages();
363
+ }
364
+ return {
365
+ cliType: this.cliType,
366
+ spec_id: this.spec.id,
367
+ current_state: this.latestState,
368
+ current_modal: this.latestModal,
369
+ activeInteractivePrompt: this.activeInteractivePrompt,
370
+ exited: this.exited,
371
+ screen,
372
+ sections,
373
+ stateHistory: this.driver.getStateHistory(),
374
+ idleHoldPending: this.driver.hasIdleHoldPending(),
375
+ lastBusyAt: this.driver.getLastBusyAt(),
376
+ specPath: this.driver.getSpecPath(),
377
+ cursorPosition: this.driver.getCursorPosition(),
378
+ completionIdleDebounce: this.driver.getCompletionIdleDebounceState(),
379
+ // v4 FSM live transition table (null for v3 specs). Every outgoing
380
+ // transition from the current state with its per-condition match
381
+ // result + countdown — the canonical "why isn't it moving" answer.
382
+ fsm: this.driver.getFsmDebug?.() ?? null,
383
+ // Extended fields
384
+ name: this.cliName,
385
+ status: this.getStatus().status,
386
+ workingDir: this.workingDir,
387
+ spawnedAtMs: this.spawnedAtMs,
388
+ providerSessionId: this.providerSessionId ?? null,
389
+ messages,
390
+ committedMessages: messages,
391
+ };
392
+ }
393
+ getRuntimeMetadata(): unknown {
394
+ return {
395
+ runtimeId: this.spec.id,
396
+ runtimeKey: this.spec.id,
397
+ displayName: this.spec.name,
398
+ spawnedAtMs: this.spawnedAtMs,
399
+ spawnedEnv: this.spawnedEnv,
400
+ ...(this.providerSessionId ? { providerSessionId: this.providerSessionId } : {}),
401
+ };
402
+ }
403
+ updateRuntimeMeta(meta?: Record<string, unknown>): void {
404
+ if (meta && typeof meta.providerSessionId === 'string') {
405
+ this.providerSessionId = meta.providerSessionId;
406
+ }
407
+ }
408
+ refreshProviderDefinition(): void { /* hot reload handled by SpecDriver fs.watch */ }
409
+
410
+ private handleEvent(ev: DashboardEvent): void {
411
+ this.lastEvent = ev;
412
+ switch (ev.kind) {
413
+ case 'state_changed':
414
+ this.latestState = ev.state;
415
+ this.latestModal = ev.modal;
416
+ // info-level keeps only spec-defined identifiers (state.id /
417
+ // state.label / button count). The extracted title can carry
418
+ // user data — file paths, command text, ticket titles — so
419
+ // it stays at debug.
420
+ LOG.info('SpecAdapter', `[${this.cliType}] state=${ev.state.id} (${ev.state.label}) modal=${ev.modal ? `${ev.modal.buttons.length}-buttons` : 'none'}`);
421
+ if (ev.state.title) {
422
+ LOG.debug('SpecAdapter', `[${this.cliType}] state.title=${JSON.stringify(ev.state.title)}`);
423
+ }
424
+ this.maybeCaptureClaudeTuiPrompt();
425
+ this.statusCallback?.();
426
+ return;
427
+ case 'pty_data':
428
+ this.detectInteractivePromptFromPtyChunk(ev.chunk);
429
+ this.maybeCaptureClaudeTuiPrompt();
430
+ try { this.ptyDataCallback?.(ev.chunk); } catch { /* ignore */ }
431
+ return;
432
+ case 'exit':
433
+ this.exited = true;
434
+ this.statusCallback?.();
435
+ return;
436
+ case 'spec_error':
437
+ LOG.warn('SpecAdapter', `[${this.cliType}] spec reload error: ${ev.errors.join('; ')}`);
438
+ return;
439
+ default:
440
+ return;
441
+ }
442
+ }
443
+
444
+ private detectInteractivePromptFromPtyChunk(chunk: string): void {
445
+ if (this.cliType !== 'claude-cli' || !chunk) return;
446
+ this.jsonLineTail += chunk;
447
+ if (this.jsonLineTail.length > 64 * 1024) this.jsonLineTail = this.jsonLineTail.slice(-64 * 1024);
448
+ const lines = this.jsonLineTail.split(/\r?\n/);
449
+ this.jsonLineTail = lines.pop() || '';
450
+ for (const line of lines) {
451
+ const trimmed = line.trim();
452
+ if (!trimmed.startsWith('{') || !trimmed.includes('AskUserQuestion')) continue;
453
+ try {
454
+ const parsed = JSON.parse(trimmed);
455
+ const prompt = detectClaudeAskUserQuestionPromptFromJson(parsed, this.cliType);
456
+ if (!prompt) continue;
457
+ this.activeInteractivePrompt = prompt;
458
+ this.interactivePromptTransport = 'stream-json';
459
+ this.statusCallback?.();
460
+ } catch {
461
+ // PTY output is not guaranteed to be machine JSON.
462
+ }
463
+ }
464
+ }
465
+
466
+ private readCurrentScreenSections(_screenText: string): Record<string, string> {
467
+ try {
468
+ const sections = this.driver.getSections() ?? [];
469
+ return Object.fromEntries(sections.map(section => [section.id, section.text]));
470
+ } catch {
471
+ return {};
472
+ }
473
+ }
474
+
475
+ private extractProviderSessionIdFromScreen(): string | undefined {
476
+ if (this.cliType !== 'codex-cli') return this.providerSessionId;
477
+ let screenText = '';
478
+ try {
479
+ screenText = this.driver.snapshot();
480
+ } catch {
481
+ return this.providerSessionId;
482
+ }
483
+ const clean = stripAnsi(screenText);
484
+ const match = clean.match(/(?:gpt-|o\d|codex-)[^\n·]*·[^\n·]*·\s*([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/i);
485
+ return match?.[1] || this.providerSessionId;
486
+ }
487
+
488
+ private readClaudeScreenAssistantMessages(): ChatMessage[] {
489
+ if (this.cliType !== 'claude-cli') return [];
490
+ let screenText = '';
491
+ try {
492
+ screenText = this.driver.snapshot();
493
+ } catch {
494
+ return [];
495
+ }
496
+ const sections = this.readCurrentScreenSections(screenText);
497
+ const body = sections.body || screenText;
498
+ const messages: ChatMessage[] = [];
499
+ const seen = new Set<string>();
500
+ for (const line of body.split(/\r?\n/)) {
501
+ const match = line.match(/^\s*⏺\s+(.+?)\s*$/);
502
+ const content = match?.[1]?.trim();
503
+ if (!content || seen.has(content)) continue;
504
+ seen.add(content);
505
+ messages.push({
506
+ role: 'assistant',
507
+ kind: 'standard',
508
+ content,
509
+ source: 'assistant_text',
510
+ userFacing: true,
511
+ bubbleState: 'final',
512
+ });
513
+ }
514
+ return messages;
515
+ }
516
+
517
+ private maybeCaptureClaudeTuiPrompt(): void {
518
+ if (this.cliType !== 'claude-cli'
519
+ || this.activeInteractivePrompt
520
+ || this.claudeTuiPromptCaptureInFlight) return;
521
+ const screenText = this.driver.snapshot();
522
+ const headers = this.readClaudeTuiHeaders(screenText);
523
+ if (!screenText.includes('Enter to select')) return;
524
+ if (headers.length === 0) {
525
+ const prompt = detectClaudeAskUserQuestionPromptFromTuiPages([{ screenText }], {
526
+ promptId: `ask-user-${this.providerSessionId || 'claude'}-${Date.now()}`,
527
+ providerType: this.cliType,
528
+ });
529
+ if (!prompt) return;
530
+ this.activeInteractivePrompt = prompt;
531
+ this.interactivePromptTransport = 'tui';
532
+ this.statusCallback?.();
533
+ return;
534
+ }
535
+ this.claudeTuiPromptCaptureInFlight = true;
536
+ void this.captureClaudeTuiPrompt(screenText, headers).finally(() => {
537
+ this.claudeTuiPromptCaptureInFlight = false;
538
+ });
539
+ }
540
+
541
+ private readClaudeTuiHeaders(screenText: string): string[] {
542
+ const navLine = screenText.split(/\r?\n/).find(line => line.includes('✔ Submit') && /[☐☒]/.test(line));
543
+ if (!navLine) return [];
544
+ const headers: string[] = [];
545
+ for (const match of navLine.matchAll(/[☐☒]\s+(.+?)(?=\s+[☐☒]|\s+✔\s+Submit)/g)) {
546
+ const header = match[1]?.trim();
547
+ if (header) headers.push(header);
548
+ }
549
+ return headers;
550
+ }
551
+
552
+ private async captureClaudeTuiPrompt(firstScreen: string, headers: string[]): Promise<void> {
553
+ const pages: ClaudeInteractiveTuiPage[] = [{ screenText: firstScreen, header: headers[0] }];
554
+ for (let index = 1; index < headers.length; index += 1) {
555
+ this.driver.dispatch({ kind: 'pty_write', data: '\t' });
556
+ await new Promise(resolve => setTimeout(resolve, 120));
557
+ pages.push({ screenText: this.driver.snapshot(), header: headers[index] });
558
+ }
559
+ for (let index = headers.length - 1; index > 0; index -= 1) {
560
+ this.driver.dispatch({ kind: 'pty_write', data: '\x1b[Z' });
561
+ await new Promise(resolve => setTimeout(resolve, 80));
562
+ }
563
+
564
+ const prompt = detectClaudeAskUserQuestionPromptFromTuiPages(pages, {
565
+ promptId: `ask-user-${this.providerSessionId || 'claude'}-${Date.now()}`,
566
+ providerType: this.cliType,
567
+ });
568
+ if (!prompt) return;
569
+ this.activeInteractivePrompt = prompt;
570
+ this.interactivePromptTransport = 'tui';
571
+ this.statusCallback?.();
572
+ }
573
+
574
+ getDebugState(): Record<string, any> {
575
+ const screen = this.driver.getScreen?.() ?? '';
576
+ const history = this.driver.getStateHistory();
577
+ const status = this.getStatus();
578
+
579
+ let messages: any[] = [];
580
+ if (this.spec.native_history?.source) {
581
+ try {
582
+ const result = executeNativeHistory(this.spec.native_history, {
583
+ agentType: this.cliType,
584
+ providerSessionId: this.providerSessionId,
585
+ sessionStartedAtMs: this.spawnedAtMs,
586
+ envOverrides: this.spawnedEnv,
587
+ workspace: this.workingDir,
588
+ });
589
+ if (result && Array.isArray(result.messages)) {
590
+ messages = result.messages;
591
+ }
592
+ } catch (e) {
593
+ // Ignore native history read errors in debug state
594
+ }
595
+ } else {
596
+ messages = this.readClaudeScreenAssistantMessages();
597
+ }
598
+
599
+ const latestState = this.latestState;
600
+ const latestModal = this.latestModal;
601
+ return {
602
+ type: this.cliType,
603
+ name: this.cliName,
604
+ status: status.status,
605
+ rawStatus: status.status,
606
+ projectedStatus: status.status,
607
+ ready: this.spawned,
608
+ // Legacy snapshot-style fields for panels that read getDebugSnapshot shape
609
+ spec_id: this.spec.id,
610
+ current_state: latestState ?? null,
611
+ current_modal: latestModal ?? null,
612
+ exited: this.exited,
613
+ idleHoldPending: this.driver.hasIdleHoldPending?.() ?? false,
614
+ lastBusyAt: this.driver.getLastBusyAt?.() ?? 0,
615
+ screen: screen,
616
+ screenText: screen,
617
+ workingDir: this.workingDir,
618
+ spawnedAtMs: this.spawnedAtMs,
619
+ providerSessionId: this.providerSessionId ?? null,
620
+ sections: this.driver.getSections?.() ?? null,
621
+ stateHistory: history,
622
+ specPath: this.driver.getSpecPath?.() ?? null,
623
+ // v4 FSM live transition table — present only for FsmDriver. Lets
624
+ // the panel (and the daemon API) show, for the current instant,
625
+ // every outgoing transition with its per-condition match result
626
+ // and countdown. This is the canonical "why isn't it transitioning"
627
+ // answer — no screenshots needed.
628
+ fsm: this.driver.getFsmDebug?.() ?? null,
629
+ messages,
630
+ committedMessages: messages,
631
+ };
632
+ }
633
+
634
+ getTraceState(limit = 120): Record<string, any> {
635
+ const history = this.driver.getStateHistory();
636
+ return {
637
+ status: this.getStatus().status,
638
+ stateHistory: history.slice(-limit),
639
+ screenText: this.driver.getScreen?.() ?? '',
640
+ };
641
+ }
642
+
643
+ getProviderResolutionMeta(): Record<string, any> {
644
+ return {
645
+ type: this.cliType,
646
+ providerDir: null,
647
+ resolvedVersion: null,
648
+ };
649
+ }
650
+ }