@adhdev/daemon-core 0.9.82-rc.36 → 0.9.82-rc.360

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 (325) 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 +55 -2
  8. package/dist/cli-adapters/cli-script-runner.d.ts +117 -0
  9. package/dist/cli-adapters/cli-state-engine.d.ts +198 -0
  10. package/dist/cli-adapters/provider-cli-adapter.d.ts +116 -64
  11. package/dist/cli-adapters/provider-cli-parse.d.ts +4 -0
  12. package/dist/cli-adapters/provider-cli-runtime.d.ts +34 -0
  13. package/dist/cli-adapters/provider-cli-shared.d.ts +53 -0
  14. package/dist/cli-adapters/raw-terminal-io.d.ts +37 -0
  15. package/dist/cli-adapters/resolve-executable.d.ts +14 -0
  16. package/dist/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +6 -3
  17. package/dist/cli-adapters/terminal-backends/types.d.ts +10 -2
  18. package/dist/cli-adapters/terminal-screen.d.ts +4 -11
  19. package/dist/commands/cli-manager.d.ts +2 -1
  20. package/dist/commands/handler.d.ts +125 -0
  21. package/dist/commands/mesh-coordinator.d.ts +85 -1
  22. package/dist/commands/router.d.ts +336 -1
  23. package/dist/commands/upgrade-helper.d.ts +41 -1
  24. package/dist/config/chat-history.d.ts +9 -0
  25. package/dist/config/config.d.ts +5 -0
  26. package/dist/config/mesh-config.d.ts +77 -1
  27. package/dist/detection/ide-detector.d.ts +13 -0
  28. package/dist/detection/win32-ide-version.d.ts +37 -0
  29. package/dist/git/change-impact-config.d.ts +159 -0
  30. package/dist/git/git-commands.d.ts +11 -1
  31. package/dist/git/git-diff.d.ts +6 -0
  32. package/dist/git/git-executor.d.ts +11 -0
  33. package/dist/git/git-status.d.ts +23 -0
  34. package/dist/git/git-types.d.ts +2 -50
  35. package/dist/git/index.d.ts +2 -0
  36. package/dist/index.d.ts +54 -13
  37. package/dist/index.js +44143 -17595
  38. package/dist/index.js.map +1 -1
  39. package/dist/index.mjs +43858 -17438
  40. package/dist/index.mjs.map +1 -1
  41. package/dist/installer.d.ts +1 -4
  42. package/dist/ipc/local-ipc-server.d.ts +91 -0
  43. package/dist/launch.d.ts +1 -1
  44. package/dist/logging/async-batch-writer.d.ts +10 -0
  45. package/dist/logging/log-redactor.d.ts +24 -0
  46. package/dist/logging/log-tail-reader.d.ts +46 -0
  47. package/dist/logging/logger.d.ts +1 -1
  48. package/dist/mesh/contracts.d.ts +164 -0
  49. package/dist/mesh/coordinator-prompt.d.ts +36 -0
  50. package/dist/mesh/coordinator-registry.d.ts +59 -0
  51. package/dist/mesh/mesh-active-work.d.ts +174 -0
  52. package/dist/mesh/mesh-delivery-policy.d.ts +131 -0
  53. package/dist/mesh/mesh-event-trace.d.ts +21 -0
  54. package/dist/mesh/mesh-events-coordinator.d.ts +170 -0
  55. package/dist/mesh/mesh-events-pending.d.ts +55 -0
  56. package/dist/mesh/mesh-events-stale.d.ts +40 -0
  57. package/dist/mesh/mesh-events-utils.d.ts +62 -0
  58. package/dist/mesh/mesh-events.d.ts +6 -49
  59. package/dist/mesh/mesh-fast-forward.d.ts +81 -0
  60. package/dist/mesh/mesh-host-ownership.d.ts +9 -0
  61. package/dist/mesh/mesh-init.d.ts +86 -0
  62. package/dist/mesh/mesh-ledger-reconciliation.d.ts +23 -3
  63. package/dist/mesh/mesh-ledger.d.ts +77 -1
  64. package/dist/mesh/mesh-missions.d.ts +164 -0
  65. package/dist/mesh/mesh-reconcile-loop.d.ts +7 -0
  66. package/dist/mesh/mesh-refine-batch.d.ts +68 -0
  67. package/dist/mesh/mesh-refine-status.d.ts +62 -0
  68. package/dist/mesh/mesh-review-inbox.d.ts +90 -0
  69. package/dist/mesh/mesh-routing.d.ts +70 -0
  70. package/dist/mesh/mesh-runtime-store.d.ts +429 -0
  71. package/dist/mesh/mesh-task-stats.d.ts +49 -0
  72. package/dist/mesh/mesh-unresolved-forward-outbox.d.ts +30 -0
  73. package/dist/mesh/mesh-work-queue.d.ts +246 -5
  74. package/dist/mesh/preview-freshness.d.ts +18 -0
  75. package/dist/mesh/refine-config.d.ts +216 -0
  76. package/dist/mesh/worktree-bootstrap-config.d.ts +135 -0
  77. package/dist/providers/acp-provider-instance.d.ts +5 -0
  78. package/dist/providers/approval-utils.d.ts +20 -0
  79. package/dist/providers/chat-message-normalization.d.ts +12 -0
  80. package/dist/providers/cli-provider-instance.d.ts +106 -3
  81. package/dist/providers/contracts.d.ts +139 -6
  82. package/dist/providers/external-sources.d.ts +71 -0
  83. package/dist/providers/manual-attendance.d.ts +63 -0
  84. package/dist/providers/native-history/antigravity-cli-transcript.d.ts +100 -0
  85. package/dist/providers/native-history/claude-cli-transcript.d.ts +70 -0
  86. package/dist/providers/native-history/codex-cli-transcript.d.ts +73 -0
  87. package/dist/providers/native-history/dispatcher.d.ts +27 -0
  88. package/dist/providers/native-history/hermes-cli-transcript.d.ts +30 -0
  89. package/dist/providers/native-history/index.d.ts +13 -0
  90. package/dist/providers/provider-instance-manager.d.ts +14 -0
  91. package/dist/providers/provider-instance.d.ts +23 -1
  92. package/dist/providers/provider-loader.d.ts +26 -4
  93. package/dist/providers/provider-trust.d.ts +31 -0
  94. package/dist/providers/read-chat-contract.d.ts +29 -0
  95. package/dist/providers/sdk/v1/builders/acp/detect-status.d.ts +68 -0
  96. package/dist/providers/sdk/v1/builders/cli/detect-status.d.ts +86 -0
  97. package/dist/providers/sdk/v1/builders/cli/parse-approval-squash.d.ts +59 -0
  98. package/dist/providers/sdk/v1/builders/cli/parse-approval.d.ts +65 -0
  99. package/dist/providers/sdk/v1/builders/cli/parse-session.d.ts +91 -0
  100. package/dist/providers/sdk/v1/builders/cli/visible-region.d.ts +42 -0
  101. package/dist/providers/sdk/v1/fixture-tooling/format.d.ts +126 -0
  102. package/dist/providers/sdk/v1/fixture-tooling/index.d.ts +8 -0
  103. package/dist/providers/sdk/v1/fixture-tooling/replay.d.ts +38 -0
  104. package/dist/providers/sdk/v1/index.d.ts +30 -0
  105. package/dist/providers/sdk/v1/sandbox/README-design.d.ts +193 -0
  106. package/dist/providers/sdk/v1/sandbox/require-whitelist.d.ts +74 -0
  107. package/dist/providers/sdk/v1/sandbox/script-runner.d.ts +98 -0
  108. package/dist/providers/sdk/v1/types/cli/index.d.ts +277 -0
  109. package/dist/providers/sdk/v1/types/common/index.d.ts +203 -0
  110. package/dist/providers/sdk/v1/validators/index.d.ts +5 -0
  111. package/dist/providers/sdk/v1/validators/manifest.d.ts +40 -0
  112. package/dist/providers/sdk/v1/validators/taint.d.ts +52 -0
  113. package/dist/providers/spec/adapter.d.ts +91 -0
  114. package/dist/providers/spec/cli-adapter.d.ts +223 -0
  115. package/dist/providers/spec/evaluator.d.ts +45 -0
  116. package/dist/providers/spec/fsm-driver.d.ts +368 -0
  117. package/dist/providers/spec/fsm-evaluator.d.ts +76 -0
  118. package/dist/providers/spec/fsm-loader.d.ts +14 -0
  119. package/dist/providers/spec/fsm-types.d.ts +174 -0
  120. package/dist/providers/spec/native-history-executor.d.ts +41 -0
  121. package/dist/providers/spec/pre-launch-trust.d.ts +16 -0
  122. package/dist/providers/spec/route.d.ts +4 -0
  123. package/dist/providers/spec/types.d.ts +222 -0
  124. package/dist/providers/status-monitor.d.ts +7 -7
  125. package/dist/providers/transcript-v2.d.ts +176 -0
  126. package/dist/providers/types/interactive-prompt.d.ts +84 -0
  127. package/dist/providers/working-dir.d.ts +17 -0
  128. package/dist/repo-mesh-types.d.ts +295 -13
  129. package/dist/sessions/registry.d.ts +6 -0
  130. package/dist/shared-types-extra.d.ts +2 -4
  131. package/dist/shared-types.d.ts +59 -2
  132. package/dist/status/normalize.d.ts +1 -1
  133. package/dist/status/normalize.js +1 -0
  134. package/dist/status/normalize.js.map +1 -1
  135. package/dist/status/normalize.mjs +1 -0
  136. package/dist/status/normalize.mjs.map +1 -1
  137. package/dist/status/reporter.d.ts +2 -0
  138. package/dist/status/snapshot.d.ts +26 -0
  139. package/dist/system/load-better-sqlite3.d.ts +21 -0
  140. package/dist/types.d.ts +5 -0
  141. package/package.json +7 -3
  142. package/src/agent-stream/poller.ts +2 -3
  143. package/src/agent-stream/provider-adapter.ts +1 -1
  144. package/src/boot/daemon-lifecycle.ts +55 -12
  145. package/src/boot/process-hardening.ts +89 -0
  146. package/src/build-info.ts +73 -0
  147. package/src/chat/source-machine.ts +534 -0
  148. package/src/chat/source-resolver.ts +0 -0
  149. package/src/chat/subscription-updates.ts +20 -1
  150. package/src/cli-adapter-types.d.ts +1 -0
  151. package/src/cli-adapter-types.ts +56 -2
  152. package/src/cli-adapters/cli-script-runner.ts +421 -0
  153. package/src/cli-adapters/cli-state-engine.ts +1215 -0
  154. package/src/cli-adapters/provider-cli-adapter.d.ts +1 -1
  155. package/src/cli-adapters/provider-cli-adapter.ts +774 -1141
  156. package/src/cli-adapters/provider-cli-parse.d.ts +1 -0
  157. package/src/cli-adapters/provider-cli-parse.ts +13 -0
  158. package/src/cli-adapters/provider-cli-runtime.ts +56 -7
  159. package/src/cli-adapters/provider-cli-shared.d.ts +4 -0
  160. package/src/cli-adapters/provider-cli-shared.ts +100 -11
  161. package/src/cli-adapters/pty-transport.ts +2 -1
  162. package/src/cli-adapters/raw-terminal-io.ts +252 -0
  163. package/src/cli-adapters/resolve-executable.ts +90 -0
  164. package/src/cli-adapters/session-host-transport.ts +2 -1
  165. package/src/cli-adapters/terminal-backends/ghostty-vt-backend.ts +53 -29
  166. package/src/cli-adapters/terminal-backends/types.ts +10 -3
  167. package/src/cli-adapters/terminal-screen.ts +16 -81
  168. package/src/commands/WINDOWS-UPGRADE-LOCK-FAILURE.md +198 -0
  169. package/src/commands/chat-commands.ts +1823 -62
  170. package/src/commands/cli-manager.ts +336 -19
  171. package/src/commands/handler.ts +841 -2
  172. package/src/commands/mesh-coordinator.ts +332 -122
  173. package/src/commands/router.ts +7624 -1312
  174. package/src/commands/stream-commands.ts +8 -0
  175. package/src/commands/upgrade-helper.ts +310 -45
  176. package/src/config/chat-history.ts +483 -24
  177. package/src/config/config.ts +12 -0
  178. package/src/config/mesh-config.ts +388 -6
  179. package/src/config/recent-activity.ts +8 -2
  180. package/src/daemon/dev-auto-implement.ts +3 -2
  181. package/src/daemon/dev-cli-debug.ts +10 -1
  182. package/src/detection/cli-detector.ts +28 -9
  183. package/src/detection/ide-detector.ts +55 -16
  184. package/src/detection/win32-ide-version.ts +106 -0
  185. package/src/git/change-impact-config.ts +354 -0
  186. package/src/git/git-commands.ts +55 -14
  187. package/src/git/git-diff.ts +81 -11
  188. package/src/git/git-executor.ts +12 -0
  189. package/src/git/git-status.ts +574 -43
  190. package/src/git/git-types.ts +14 -62
  191. package/src/git/git-worktree.ts +8 -1
  192. package/src/git/index.ts +16 -0
  193. package/src/index.ts +156 -12
  194. package/src/installer.d.ts +1 -1
  195. package/src/installer.ts +8 -6
  196. package/src/ipc/local-ipc-server.ts +278 -0
  197. package/src/launch.d.ts +1 -1
  198. package/src/launch.ts +37 -28
  199. package/src/logging/async-batch-writer.ts +55 -0
  200. package/src/logging/command-log.ts +7 -5
  201. package/src/logging/log-redactor.ts +100 -0
  202. package/src/logging/log-tail-reader.ts +220 -0
  203. package/src/logging/logger.ts +14 -7
  204. package/src/mesh/contracts.ts +329 -0
  205. package/src/mesh/coordinator-prompt.ts +234 -31
  206. package/src/mesh/coordinator-registry.ts +121 -0
  207. package/src/mesh/mesh-active-work.ts +667 -0
  208. package/src/mesh/mesh-delivery-policy.ts +315 -0
  209. package/src/mesh/mesh-event-trace.ts +67 -0
  210. package/src/mesh/mesh-events-coordinator.ts +2572 -0
  211. package/src/mesh/mesh-events-pending.ts +599 -0
  212. package/src/mesh/mesh-events-stale.ts +309 -0
  213. package/src/mesh/mesh-events-utils.ts +381 -0
  214. package/src/mesh/mesh-events.ts +30 -1035
  215. package/src/mesh/mesh-fast-forward.ts +839 -0
  216. package/src/mesh/mesh-host-ownership.ts +73 -0
  217. package/src/mesh/mesh-init.ts +260 -0
  218. package/src/mesh/mesh-ledger-reconciliation.ts +12 -5
  219. package/src/mesh/mesh-ledger.ts +591 -102
  220. package/src/mesh/mesh-missions.ts +322 -0
  221. package/src/mesh/mesh-reconcile-loop.ts +1096 -0
  222. package/src/mesh/mesh-refine-batch.ts +197 -0
  223. package/src/mesh/mesh-refine-status.ts +231 -0
  224. package/src/mesh/mesh-review-inbox.ts +307 -0
  225. package/src/mesh/mesh-routing.ts +291 -0
  226. package/src/mesh/mesh-runtime-store.ts +1697 -0
  227. package/src/mesh/mesh-task-stats.ts +161 -0
  228. package/src/mesh/mesh-unresolved-forward-outbox.ts +185 -0
  229. package/src/mesh/mesh-work-queue.ts +997 -141
  230. package/src/mesh/preview-freshness.ts +118 -0
  231. package/src/mesh/refine-config.ts +423 -0
  232. package/src/mesh/worktree-bootstrap-config.ts +331 -0
  233. package/src/providers/acp-provider-instance.ts +43 -10
  234. package/src/providers/approval-utils.d.ts +5 -0
  235. package/src/providers/approval-utils.ts +57 -5
  236. package/src/providers/chat-message-normalization.ts +45 -5
  237. package/src/providers/cli-provider-instance.ts +1254 -101
  238. package/src/providers/contracts.d.ts +55 -0
  239. package/src/providers/contracts.ts +150 -6
  240. package/src/providers/extension-provider-instance.ts +12 -7
  241. package/src/providers/external-sources.ts +218 -0
  242. package/src/providers/ide-provider-instance.ts +35 -12
  243. package/src/providers/manual-attendance.ts +85 -0
  244. package/src/providers/native-history/antigravity-cli-transcript.ts +643 -0
  245. package/src/providers/native-history/claude-cli-transcript.ts +396 -0
  246. package/src/providers/native-history/codex-cli-transcript.ts +479 -0
  247. package/src/providers/native-history/dispatcher.ts +340 -0
  248. package/src/providers/native-history/hermes-cli-transcript.ts +230 -0
  249. package/src/providers/native-history/index.ts +30 -0
  250. package/src/providers/provider-instance-manager.ts +30 -0
  251. package/src/providers/provider-instance.ts +19 -1
  252. package/src/providers/provider-loader.ts +670 -50
  253. package/src/providers/provider-schema.ts +87 -14
  254. package/src/providers/provider-trust.ts +114 -0
  255. package/src/providers/read-chat-contract.ts +76 -16
  256. package/src/providers/sdk/README.md +49 -0
  257. package/src/providers/sdk/v1/builders/acp/detect-status.ts +144 -0
  258. package/src/providers/sdk/v1/builders/cli/detect-status.ts +313 -0
  259. package/src/providers/sdk/v1/builders/cli/parse-approval-squash.ts +158 -0
  260. package/src/providers/sdk/v1/builders/cli/parse-approval.ts +250 -0
  261. package/src/providers/sdk/v1/builders/cli/parse-session.ts +276 -0
  262. package/src/providers/sdk/v1/builders/cli/visible-region.ts +143 -0
  263. package/src/providers/sdk/v1/fixture-tooling/format.ts +130 -0
  264. package/src/providers/sdk/v1/fixture-tooling/index.ts +22 -0
  265. package/src/providers/sdk/v1/fixture-tooling/replay.ts +352 -0
  266. package/src/providers/sdk/v1/index.ts +152 -0
  267. package/src/providers/sdk/v1/sandbox/README-design.ts +195 -0
  268. package/src/providers/sdk/v1/sandbox/require-whitelist.ts +472 -0
  269. package/src/providers/sdk/v1/sandbox/script-runner.ts +150 -0
  270. package/src/providers/sdk/v1/schemas/cli/provider.schema.json +504 -0
  271. package/src/providers/sdk/v1/schemas/primitives/acp-session-protocol-v1.json +131 -0
  272. package/src/providers/sdk/v1/schemas/primitives/native-history-codex-rollout-v1.json +66 -0
  273. package/src/providers/sdk/v1/schemas/primitives/tui-approval-squash-v1.json +91 -0
  274. package/src/providers/sdk/v1/schemas/primitives/tui-assistant-block-v1.json +91 -0
  275. package/src/providers/sdk/v1/schemas/primitives/tui-cue-ordering-v1.json +47 -0
  276. package/src/providers/sdk/v1/schemas/primitives/tui-dispatch-order-v1.json +32 -0
  277. package/src/providers/sdk/v1/schemas/primitives/tui-footer-chrome-v1.json +42 -0
  278. package/src/providers/sdk/v1/schemas/primitives/tui-index-finder-v1.json +27 -0
  279. package/src/providers/sdk/v1/schemas/primitives/tui-modal-v1.json +125 -0
  280. package/src/providers/sdk/v1/schemas/primitives/tui-prompt-marker-v1.json +45 -0
  281. package/src/providers/sdk/v1/schemas/primitives/tui-session-id-extraction-v1.json +46 -0
  282. package/src/providers/sdk/v1/schemas/primitives/tui-settled-prompt-v1.json +71 -0
  283. package/src/providers/sdk/v1/schemas/primitives/tui-spinner-v1.json +83 -0
  284. package/src/providers/sdk/v1/schemas/primitives/tui-transcript-pty-v1.json +83 -0
  285. package/src/providers/sdk/v1/schemas/primitives/tui-visible-region-v1.json +57 -0
  286. package/src/providers/sdk/v1/schemas/primitives/tui-welcome-screen-v1.json +35 -0
  287. package/src/providers/sdk/v1/types/cli/index.ts +365 -0
  288. package/src/providers/sdk/v1/types/common/index.ts +229 -0
  289. package/src/providers/sdk/v1/validators/index.ts +19 -0
  290. package/src/providers/sdk/v1/validators/manifest.ts +110 -0
  291. package/src/providers/sdk/v1/validators/taint.ts +309 -0
  292. package/src/providers/spec/adapter.ts +235 -0
  293. package/src/providers/spec/cli-adapter.ts +1051 -0
  294. package/src/providers/spec/evaluator.ts +407 -0
  295. package/src/providers/spec/fsm-driver.ts +1251 -0
  296. package/src/providers/spec/fsm-evaluator.ts +272 -0
  297. package/src/providers/spec/fsm-loader.ts +120 -0
  298. package/src/providers/spec/fsm-types.ts +273 -0
  299. package/src/providers/spec/native-history-executor.ts +1136 -0
  300. package/src/providers/spec/pre-launch-trust.ts +104 -0
  301. package/src/providers/spec/route.ts +51 -0
  302. package/src/providers/spec/types.ts +262 -0
  303. package/src/providers/status-monitor.d.ts +7 -7
  304. package/src/providers/status-monitor.ts +37 -22
  305. package/src/providers/transcript-v2.ts +567 -0
  306. package/src/providers/types/interactive-prompt.ts +536 -0
  307. package/src/providers/version-archive.ts +64 -24
  308. package/src/providers/working-dir.ts +23 -0
  309. package/src/repo-mesh-types.ts +378 -14
  310. package/src/sessions/registry.ts +6 -0
  311. package/src/shared-types-extra.ts +2 -4
  312. package/src/shared-types.d.ts +8 -0
  313. package/src/shared-types.ts +64 -1
  314. package/src/status/builders.ts +26 -6
  315. package/src/status/normalize.ts +2 -0
  316. package/src/status/reporter.ts +19 -1
  317. package/src/status/snapshot.ts +95 -26
  318. package/src/system/host-memory.ts +29 -12
  319. package/src/system/load-better-sqlite3.ts +68 -0
  320. package/src/types.ts +5 -0
  321. package/dist/cli-adapters/terminal-backends/xterm-backend.d.ts +0 -17
  322. package/dist/mesh/mesh-sync.d.ts +0 -53
  323. package/src/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +0 -16
  324. package/src/cli-adapters/terminal-backends/xterm-backend.ts +0 -97
  325. package/src/mesh/mesh-sync.ts +0 -111
@@ -0,0 +1,368 @@
1
+ import { type SpecPtyEvent } from './adapter.js';
2
+ import type { PtyTransportFactory } from '../../cli-adapters/pty-transport.js';
3
+ import { type TraceEntry } from './evaluator.js';
4
+ import { type TransitionEval } from './fsm-evaluator.js';
5
+ export type DashboardEvent = {
6
+ kind: 'pty_data';
7
+ chunk: string;
8
+ } | {
9
+ kind: 'state_changed';
10
+ state: {
11
+ id: string;
12
+ label: string;
13
+ title: string | null;
14
+ status: 'idle' | 'generating' | 'approval';
15
+ };
16
+ modal: {
17
+ title: string | null;
18
+ buttons: {
19
+ index: number;
20
+ label: string;
21
+ }[];
22
+ kind: 'approval' | 'picker' | 'confirm' | null;
23
+ } | null;
24
+ controls: {
25
+ id: string;
26
+ label: string;
27
+ action_type: string;
28
+ }[];
29
+ } | {
30
+ kind: 'notification';
31
+ id: string;
32
+ title: string;
33
+ body: string;
34
+ } | {
35
+ kind: 'delegate';
36
+ id: string;
37
+ task: string;
38
+ } | {
39
+ kind: 'spec_trace';
40
+ entries: TraceEntry[];
41
+ } | {
42
+ kind: 'exit';
43
+ exit_code: number;
44
+ } | {
45
+ kind: 'spec_error';
46
+ errors: string[];
47
+ };
48
+ export type DashboardCommand = {
49
+ kind: 'send_message';
50
+ text: string;
51
+ } | {
52
+ kind: 'pty_write';
53
+ data: string;
54
+ } | {
55
+ kind: 'click_control';
56
+ control_id: string;
57
+ payload?: unknown;
58
+ } | {
59
+ kind: 'click_modal_button';
60
+ index: number;
61
+ } | {
62
+ kind: 'attach_image';
63
+ blob: string;
64
+ mime: string;
65
+ } | {
66
+ kind: 'resize';
67
+ cols: number;
68
+ rows: number;
69
+ } | {
70
+ kind: 'cancel';
71
+ } | {
72
+ kind: 'shutdown';
73
+ };
74
+ export interface DriverHistoryEntry {
75
+ stateId: string;
76
+ label: string;
77
+ at: number;
78
+ durationMs: number;
79
+ reason: string;
80
+ matchedStateId?: string;
81
+ matchedRules?: string[];
82
+ debounceKind?: string;
83
+ idleHoldMs?: number;
84
+ busyHoldMs?: number;
85
+ via?: string;
86
+ }
87
+ /**
88
+ * A frozen snapshot of the FULL FSM evaluation captured at the instant a
89
+ * transition fired — the rich `transitions[]` table (per-transition eligible /
90
+ * hold countdown / per-condition CondResult + remainingMs) that `getFsmDebug()`
91
+ * otherwise only computes live for the current instant. Kept in a separate ring
92
+ * buffer from `stateHistory` (which stays intentionally lightweight) so the
93
+ * "why did this rule fire just before the transition" question is answerable
94
+ * after the fact. before-only: this is the evaluation that PRODUCED the
95
+ * transition, not the post-transition state.
96
+ */
97
+ export interface FsmSnapshotEntry {
98
+ /** State we transitioned out of. */
99
+ stateFrom: string;
100
+ /** State we transitioned into (the fired transition's destination). */
101
+ stateTo: string;
102
+ /** Wall-clock time the transition committed (ms). */
103
+ at: number;
104
+ /** The fired transition's destination state id (== stateTo; kept explicit
105
+ * to mirror the rule that fired). */
106
+ firedTo: string;
107
+ /** Human label of the fired transition (e.g. "approval→busy"). */
108
+ firedLabel: string;
109
+ /** Why-it-fired summary, same shape produced for stateHistory.matchedRules. */
110
+ reason: string[];
111
+ /** Every outgoing transition from `stateFrom` as evaluated at `at`, each
112
+ * with its eligible / hold / per-condition CondResult + remainingMs. This
113
+ * is the full pre-transition evaluation table — the whole point of the
114
+ * snapshot. */
115
+ transitions: TransitionEval[];
116
+ }
117
+ export interface ISpecDriver {
118
+ subscribe(listener: (ev: DashboardEvent) => void): () => void;
119
+ start(): void;
120
+ dispatch(cmd: DashboardCommand): void;
121
+ snapshot(): string;
122
+ getCursorPosition(): {
123
+ row: number;
124
+ col: number;
125
+ };
126
+ getScreen(): string;
127
+ getSpecPath(): string;
128
+ shutdown(): void;
129
+ getStateHistory(): ReadonlyArray<DriverHistoryEntry>;
130
+ getSections(): Array<{
131
+ id: string;
132
+ text: string;
133
+ }> | null;
134
+ getLastBusyAt(): number;
135
+ hasIdleHoldPending(): boolean;
136
+ getCompletionIdleDebounceState(): {
137
+ active: boolean;
138
+ ageMs: number;
139
+ holdMs: number;
140
+ forceAfterMs: number;
141
+ } | null;
142
+ getFsmDebug?(): unknown;
143
+ getFsmSnapshotHistory?(): ReadonlyArray<FsmSnapshotEntry>;
144
+ getEventTimeline?(limit?: number): ReadonlyArray<SpecPtyEvent>;
145
+ }
146
+ export interface SpecDriverOpts {
147
+ specPath: string;
148
+ workingDir: string;
149
+ extraEnv?: Record<string, string>;
150
+ cols?: number;
151
+ rows?: number;
152
+ hotReload?: boolean;
153
+ emitTrace?: boolean;
154
+ transportFactory?: PtyTransportFactory;
155
+ extraCliArgs?: string[];
156
+ }
157
+ export declare function resolveSubmitDelayMs(specBeforeSubmit: number | undefined, text: string): number;
158
+ /** Split `text` into chunks of at most `size` UTF-16 units without ever cutting
159
+ * between a high and low surrogate (which would corrupt an astral char — emoji,
160
+ * etc. — on the UTF-8 PTY write). */
161
+ export declare function chunkPreservingSurrogates(text: string, size: number): string[];
162
+ export declare function guessExt(mime: string): string;
163
+ type HistoryEntry = DriverHistoryEntry;
164
+ export declare class FsmDriver implements ISpecDriver {
165
+ private readonly opts;
166
+ private spec;
167
+ private adapter;
168
+ private listeners;
169
+ private currentStateId;
170
+ private stateEnteredAt;
171
+ private startedAtMs;
172
+ private prevScreenLines;
173
+ /** Per cursor_above region (key: cursor_above, -1 = whole screen) → last
174
+ * time that region's content changed. Drives stable_ms conditions. */
175
+ private regionLastChangedAt;
176
+ /** Timer that re-runs evaluate() when a time-condition would flip true
177
+ * with no PTY frame to trigger it. */
178
+ private wakeTimer;
179
+ /** Timer driving the focus-gated stall watchdog (refocus_when_stalled_ms).
180
+ * Re-arms itself while the machine is generating so a re-prime can fire
181
+ * even when the PTY has gone completely quiet. */
182
+ private stallTimer;
183
+ /** Wall-clock time the last stall re-prime was injected. The cooldown gate:
184
+ * after a re-prime we don't re-inject until the screen changes (which
185
+ * resets the stall reference) or another full stall window lapses. */
186
+ private lastRefocusAt;
187
+ /** Timer driving the win32 verification-based submit resend loop (see
188
+ * WIN32_SUBMIT_* and scheduleWin32Submit). Re-arms itself until the FSM
189
+ * leaves idle (submitted) or the resend budget is spent. */
190
+ private win32SubmitTimer;
191
+ /** Wall-clock (ms) of the most recent raw PTY output chunk. Advances on every
192
+ * on_pty_data — including the echo of text written into the composer — so the
193
+ * win32 submit settle-gate can tell when input has finished landing. */
194
+ private lastPtyDataAt;
195
+ /** Wall-clock (ms) of the most recent win32 message-body input write. Bridges
196
+ * the gap between writing a chunk and its echo so the settle-gate does not
197
+ * declare "quiet" mid-write. */
198
+ private lastWin32WriteAt;
199
+ /** Pending paced chunk-write timer for a large win32 body (see writeWin32Body). */
200
+ private win32WriteTimer;
201
+ private currentEval;
202
+ private stateHistory;
203
+ private prevStateAt;
204
+ private readySeenOnce;
205
+ private pendingSends;
206
+ private pickerInProgress;
207
+ private delegateTimers;
208
+ private specWatcher;
209
+ /** Last full FSM evaluation, kept for the debugger. */
210
+ private lastFsmEval;
211
+ /** Ring buffer (max 20) of the full FSM evaluation captured at each
212
+ * transition — the rich pre-transition table that lastFsmEval only keeps
213
+ * for the single most recent evaluation. Separate from stateHistory. */
214
+ private fsmSnapshotHistory;
215
+ constructor(opts: SpecDriverOpts);
216
+ subscribe(listener: (ev: DashboardEvent) => void): () => void;
217
+ start(): void;
218
+ private scheduleSpawnPrime;
219
+ /** Write the declared `send_on_spawn` sequences to the PTY once. Used both
220
+ * at spawn (scheduleSpawnPrime) and, for focus-gated TUIs, by the stall
221
+ * watchdog to re-inject the focus-in wake mid-turn. No-op when the spec
222
+ * declares no prime, so non-focus-gated CLIs are never poked. */
223
+ private sendSpawnPrime;
224
+ dispatch(cmd: DashboardCommand): void;
225
+ snapshot(): string;
226
+ getCursorPosition(): {
227
+ row: number;
228
+ col: number;
229
+ };
230
+ getScreen(): string;
231
+ /** Scrollback-inclusive screen as line array — used only for modal/button
232
+ * content extraction so a tall prompt's off-screen anchors stay matchable.
233
+ * Falls back to the viewport snapshot if scrollback read is unavailable. */
234
+ private scrollbackLines;
235
+ getSpecPath(): string;
236
+ shutdown(): void;
237
+ getFsmDebug(): {
238
+ currentState: string;
239
+ label: string;
240
+ stateAgeMs: number;
241
+ status: string;
242
+ cursor: {
243
+ row: number;
244
+ col: number;
245
+ };
246
+ transitions: TransitionEval[];
247
+ };
248
+ getStateHistory(): ReadonlyArray<HistoryEntry>;
249
+ getFsmSnapshotHistory(): ReadonlyArray<FsmSnapshotEntry>;
250
+ /** Debug-only PTY input/output/resize/cursor timeline from the adapter. */
251
+ getEventTimeline(limit?: number): ReadonlyArray<SpecPtyEvent>;
252
+ getSections(): Array<{
253
+ id: string;
254
+ text: string;
255
+ }> | null;
256
+ /** v3-compat shims so the cli-adapter's existing debug snapshot keeps
257
+ * working without branching on driver type. */
258
+ getLastBusyAt(): number;
259
+ hasIdleHoldPending(): boolean;
260
+ getCompletionIdleDebounceState(): {
261
+ active: boolean;
262
+ ageMs: number;
263
+ holdMs: number;
264
+ forceAfterMs: number;
265
+ } | null;
266
+ private loadSpecOrThrow;
267
+ private buildAdapterOpts;
268
+ private armSpecWatcher;
269
+ private emitInitialState;
270
+ private buildClock;
271
+ private evalFsmNow;
272
+ private reevaluate;
273
+ private commitTransition;
274
+ /** Snapshot the full FSM evaluation that produced a transition into the
275
+ * separate fsmSnapshotHistory ring buffer (max 20). The transitions[]
276
+ * table is captured by reference — it is freshly built per evaluation in
277
+ * evaluateFsm and never mutated after, so no clone is needed. */
278
+ private pushFsmSnapshot;
279
+ /** Re-derive the visible modal + controls for the current state and emit a
280
+ * state_changed if anything differs from the last emit. */
281
+ private emitStateChanged;
282
+ private deriveModal;
283
+ private deriveTitle;
284
+ private deriveControls;
285
+ /** Track which cursor_above regions changed since the previous frame so
286
+ * stable_ms conditions can measure quiet time. We record every region
287
+ * size referenced by a stable_ms condition in the spec, plus the whole
288
+ * screen (-1). */
289
+ private trackRegionChanges;
290
+ /** All cursor_above region sizes referenced by stable_ms conditions in the
291
+ * current state's outgoing transitions, plus whole-screen. Cached lazily
292
+ * per spec load would be nicer but the set is tiny. */
293
+ private stableRegionSizes;
294
+ /** Schedule a re-evaluation for the soonest pending time-condition on any
295
+ * outgoing transition (elapsed_ms / stable_ms / min_hold_ms). Without
296
+ * this, a state whose only exit is time-based would never leave once the
297
+ * PTY goes quiet. */
298
+ private scheduleWakeForState;
299
+ /** True when this spec opts into stall recovery (declares a positive
300
+ * refocus window AND a wake sequence to re-inject). */
301
+ private stallRecoveryEnabled;
302
+ /** Wall-clock time the screen last changed in the current state, falling
303
+ * back to state entry when it has not changed since (i.e. fully stalled
304
+ * from the start of the state). */
305
+ private lastScreenChangeAt;
306
+ /** Arm a timer to re-inject the focus-in prime if the screen stays frozen
307
+ * through a `generating` state. Only active for opted-in focus-gated specs;
308
+ * a no-op (and cleared) for every other CLI and every non-generating state.
309
+ * Re-arms itself so it keeps watching while the PTY is quiet. */
310
+ private scheduleStallWatchdog;
311
+ /** Fire when the stall window elapses: if the screen is still frozen and we
312
+ * are still generating, re-inject the focus-in wake once, then re-arm. */
313
+ private onStallTick;
314
+ private maybeMarkReady;
315
+ private fireNotifications;
316
+ private armOrCancelDelegateTimers;
317
+ private fireDelegate;
318
+ private handleSendMessage;
319
+ private actuallySendMessage;
320
+ /** The agent's current coarse status, derived from the FSM node we're in. */
321
+ private currentStatus;
322
+ /** Record a win32 body write so the settle-gate counts it as input activity
323
+ * even before the echo arrives. */
324
+ private markWin32Write;
325
+ /** Most recent win32 input activity — a write we issued OR a PTY output chunk
326
+ * (echo). The submit settle-gate waits for this to go quiet. */
327
+ private lastWin32InputActivityAt;
328
+ /**
329
+ * Write the message body to the PTY for win32, paced into bounded chunks. A
330
+ * single unbounded ConPTY write can overflow the input pipe and drop leading
331
+ * bytes; splitting it with a short inter-chunk gap keeps the console input
332
+ * buffer from overflowing. Small bodies still go out in a single write. Each
333
+ * chunk advances lastWin32WriteAt so the submit settle-gate keeps waiting until
334
+ * the final chunk is out and echoed.
335
+ */
336
+ private writeWin32Body;
337
+ /**
338
+ * win32 submit. Two phases:
339
+ *
340
+ * Phase 1 (echo-gate): hold the first CR until the body text is CONFIRMED in the
341
+ * composer (its whitespace-collapsed tail appears in the rendered screen) AND the
342
+ * PTY output is then quiet for WIN32_SUBMIT_SETTLE_MS (the full, possibly multi-KB
343
+ * / multiline body has finished arriving). This replaces a bare output-quiet
344
+ * settle: an early write that races claude's boot is buffered, not dropped, so the
345
+ * screen can go quiet with the body NOT YET in the composer — a quiet-only gate
346
+ * would then fire a CR into an empty composer (no submit). Waiting on the echo
347
+ * closes that. Honors an initial minimum delay and a generous WIN32_ECHO_MAX_WAIT_MS
348
+ * last-resort blind fire so a body that truly never confirms still submits (carried
349
+ * by phase 2) rather than hanging. A settled session echoes immediately → no delay.
350
+ *
351
+ * Phase 2 (verified resend — unchanged): send the submit key, wait a gap, and
352
+ * if the FSM is still 'idle' (the CR was absorbed as a multiline-paste
353
+ * newline) resend, up to WIN32_SUBMIT_MAX_RESENDS. The first CR always fires
354
+ * (a stale/edge status never suppresses it); resends are gated on still being
355
+ * idle and stop the instant the agent leaves idle (submitted → generating /
356
+ * approval). This preserves the win32 lone-CR-swallow handling.
357
+ */
358
+ private scheduleWin32Submit;
359
+ private handleClickControl;
360
+ private handleClickModalButton;
361
+ private handleAttachImage;
362
+ private tryAdvancePicker;
363
+ private handleExit;
364
+ private pushHistory;
365
+ private specTag;
366
+ private emit;
367
+ }
368
+ export {};
@@ -0,0 +1,76 @@
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
+ /** Debug-only: the actual substring a TRUE regex condition matched, so the
23
+ * snapshot shows WHAT text the rule fired on — not just which regex. Never
24
+ * read by the FSM; purely for the Spec Debug Snapshot. */
25
+ matchedText?: string;
26
+ children?: CondResult[];
27
+ }
28
+ /** One evaluated transition with its full reasoning. */
29
+ export interface TransitionEval {
30
+ to: string;
31
+ label: string;
32
+ /** Did the `from` clause include the current state? (Always true for the
33
+ * transitions we return — kept for completeness.) */
34
+ eligible: boolean;
35
+ /** min_hold_ms guard satisfied? */
36
+ holdSatisfied: boolean;
37
+ holdRemainingMs: number;
38
+ /** Guard condition result (true if no `when`). */
39
+ condResult: boolean;
40
+ cond?: CondResult;
41
+ /** Overall: would this transition fire? */
42
+ fires: boolean;
43
+ priority: number;
44
+ }
45
+ export interface FsmEvaluation {
46
+ /** Sections resolved from the screen (shared with v3 shape). */
47
+ sections: ResolvedSection[];
48
+ /** Every outgoing transition from the current state, priority-ordered,
49
+ * each annotated with why it fired or didn't. */
50
+ transitions: TransitionEval[];
51
+ /** The transition that fires (first in priority order with fires===true),
52
+ * or null to stay in the current state. */
53
+ fired: TransitionEval | null;
54
+ /** v3-compatible trace lines for the legacy inspector. */
55
+ trace: TraceEntry[];
56
+ }
57
+ /**
58
+ * Evaluate the FSM: given the current state id and screen, return every
59
+ * outgoing transition annotated with why it fires/doesn't, plus the one that
60
+ * fires (if any).
61
+ */
62
+ export declare function evaluateFsm(spec: CliSpecV4, currentStateId: string, screenText: string, cursor: {
63
+ row: number;
64
+ col: number;
65
+ } | undefined, prevLines: string[] | undefined, clock: FsmClock): FsmEvaluation;
66
+ /**
67
+ * Evaluate a single condition against a screen + section map — for the spec
68
+ * editor's live preview ("does this regex match the current screen right
69
+ * now?"). Time leaves (elapsed_ms/stable_ms) are evaluated against a synthetic
70
+ * clock where the state was just entered, so they report their countdown
71
+ * rather than firing; the preview is about screen-content match, not timing.
72
+ */
73
+ export declare function evaluateConditionPreview(cond: FsmCondition, sections: Record<string, SectionDef> | undefined, screenText: string, cursor?: {
74
+ row: number;
75
+ col: number;
76
+ }): 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,174 @@
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
+ /**
34
+ * For a modal state, what KIND of modal it is — the semantic distinction the
35
+ * status field (always 'approval' for any modal, so the dashboard surfaces it)
36
+ * deliberately loses. The auto-approve worker uses this to decide whether it
37
+ * may answer the modal on the user's behalf:
38
+ *
39
+ * - 'approval' — a tool/command/trust consent prompt ("Allow Bash?",
40
+ * "Trust this folder?"). Auto-approve MAY fire (a background mesh worker
41
+ * should not stall on these).
42
+ * - 'picker' — a selection menu the user opened (/model, /mode, …). There
43
+ * is no "correct" answer to auto-pick; blindly selecting the first option
44
+ * silently changes the model/mode. Auto-approve must NOT fire — the user
45
+ * chooses.
46
+ * - 'confirm' — a non-consent yes/no the user must decide. Left to the user.
47
+ *
48
+ * Defaults to 'approval' for a modal state that omits it (preserves the
49
+ * pre-existing "auto-approve any modal" behaviour for un-migrated specs;
50
+ * picker/confirm states declare their kind explicitly). Non-modal states
51
+ * have no modal_kind.
52
+ */
53
+ modal_kind?: 'approval' | 'picker' | 'confirm';
54
+ /** Status this state maps to for the dashboard/cli-adapter status field.
55
+ * One of: idle | generating | approval. Defaults: modal→approval,
56
+ * initial→idle, id==='busy'→generating, else idle. Explicit wins. */
57
+ status?: 'idle' | 'generating' | 'approval';
58
+ /** Optional extraction run whenever this state is the committed state —
59
+ * used by modal states to surface a title + buttons. */
60
+ extract?: {
61
+ title?: ExtractTitle;
62
+ buttons?: ExtractButtons;
63
+ };
64
+ }
65
+ export interface FsmTransition {
66
+ /** Source state id, or list of source ids, or "*" for any state. */
67
+ from: string | string[];
68
+ /** Destination state id. */
69
+ to: string;
70
+ /** Guard condition. Omitted → always eligible (only gated by `from` +
71
+ * min_hold_ms). Evaluated against the current screen + clock. */
72
+ when?: FsmCondition;
73
+ /** Minimum time the machine must have been in `from` before this edge can
74
+ * fire. Replaces busy_hold_ms / idle_hold_ms (per-edge, not global). */
75
+ min_hold_ms?: number;
76
+ /** Higher priority transitions are evaluated first. Default 0. Ties broken
77
+ * by declaration order. */
78
+ priority?: number;
79
+ /** Human label for the debugger. */
80
+ label?: string;
81
+ }
82
+ /**
83
+ * Declarative "trust this folder before spawn" config. Some agent CLIs gate the
84
+ * first run in a new folder behind an interactive trust prompt and persist the
85
+ * answer as a string array in a JSON settings file. Declaring this lets the
86
+ * engine add the workspace path to that array before spawn so the prompt never
87
+ * appears — the robust alternative to detecting and auto-clicking the modal.
88
+ * CLIs without such a gate omit this field and the engine does nothing.
89
+ */
90
+ export interface PreLaunchTrust {
91
+ /** Path to the CLI's JSON settings file. A leading `~` expands to $HOME. */
92
+ settings_path: string;
93
+ /** Key of the string-array of trusted folder paths within that file. */
94
+ key: string;
95
+ }
96
+ export interface CliSpecV4 {
97
+ $schema: 'adhdev:cli/spec@4';
98
+ id: string;
99
+ name: string;
100
+ binary: string;
101
+ spawn_args?: string[];
102
+ env?: Record<string, string>;
103
+ cli_version_range?: string;
104
+ /**
105
+ * Optional raw byte sequences written to the PTY once, shortly after spawn,
106
+ * to prime a TUI that gates its input handling on a terminal event the
107
+ * daemon would otherwise never emit. The canonical case is a focus-event
108
+ * TUI (Ink `useStdin`/`useFocus`, e.g. antigravity's `agy`) that enables
109
+ * focus reporting (`CSI ?1004h`) and treats its input box as unfocused —
110
+ * silently dropping the first programmatic write — until it receives a
111
+ * focus-in event (`ESC [ I`). Declaring `[""]` here wakes the input
112
+ * stream on spawn so the first delegated message lands without a manual
113
+ * keystroke. CLIs that do not focus-gate input simply omit this field; the
114
+ * engine writes nothing extra for them, so it stays CLI-agnostic.
115
+ */
116
+ send_on_spawn?: string[];
117
+ /** Delay (ms) after spawn before writing `send_on_spawn`. Default 250. */
118
+ send_on_spawn_delay_ms?: number;
119
+ /**
120
+ * Opt-in stall recovery for focus-gated TUIs. The same CLIs that need
121
+ * `send_on_spawn` (focus-event TUIs like antigravity's `agy`) also stop
122
+ * rendering / flushing output the moment they believe they have lost focus
123
+ * MID-TURN — the screen freezes and only repaints once the user presses a
124
+ * key, which the daemon never does on its own. When this field is set and
125
+ * the machine is in a `generating`-status state whose screen has not changed
126
+ * for `refocus_when_stalled_ms`, the engine re-injects the `send_on_spawn`
127
+ * prime (the focus-in event) once to wake the render loop, then waits for the
128
+ * screen to change or for the stall window to lapse again before re-priming
129
+ * (a cooldown that prevents a tight re-prime loop). Requires `send_on_spawn`
130
+ * to carry the wake sequence; with no `send_on_spawn` there is nothing to
131
+ * re-inject and the engine does nothing. Omitted by every non-focus-gated
132
+ * CLI spec, so the engine stays CLI-agnostic.
133
+ */
134
+ refocus_when_stalled_ms?: number;
135
+ /**
136
+ * Optional pre-spawn folder-trust step. When present, the engine adds the
137
+ * launch workspace path to the declared trusted-folders array before
138
+ * spawning, so a CLI that gates first run on a "trust this folder?" prompt
139
+ * (e.g. antigravity's `agy`) starts trusted and never blocks. Omitted for
140
+ * CLIs without such a gate. See pre-launch-trust.ts.
141
+ */
142
+ pre_launch_trust?: PreLaunchTrust;
143
+ send_message: {
144
+ submit_key: string;
145
+ delay_ms_before_submit?: number;
146
+ delay_ms_per_char?: number;
147
+ };
148
+ sections: Record<string, SectionDef>;
149
+ states: FsmState[];
150
+ transitions: FsmTransition[];
151
+ control_bar?: Control[];
152
+ notifications?: NotificationRule[];
153
+ delegate?: DelegateTrigger[];
154
+ native_history?: NativeHistoryConfig;
155
+ requiresFinalAssistantBeforeIdle?: boolean;
156
+ }
157
+ export declare function isV4Spec(raw: unknown): raw is CliSpecV4;
158
+ export declare function initialState(spec: CliSpecV4): FsmState;
159
+ export declare function stateById(spec: CliSpecV4, id: string): FsmState | undefined;
160
+ /** Outgoing transitions from `stateId`, highest priority first, declaration
161
+ * order as tiebreak. Includes wildcard ("*") and list-membership sources. */
162
+ export declare function outgoingTransitions(spec: CliSpecV4, stateId: string): FsmTransition[];
163
+ /** Map a state to the dashboard status string, applying the documented
164
+ * defaults when `status` is not explicit. */
165
+ export declare function statusForState(state: FsmState): 'idle' | 'generating' | 'approval';
166
+ /**
167
+ * The modal kind for a state, or null when the state is not modal. A modal state
168
+ * that omits `modal_kind` defaults to 'approval' so the established
169
+ * auto-approve-any-modal behaviour is preserved for specs that have not yet
170
+ * declared a kind; picker/confirm states must opt out by declaring their kind.
171
+ * This is the value the cli-adapter carries on `activeModal.kind` and the
172
+ * auto-approve gate reads — see cli-provider-instance.maybeAutoApproveStatus.
173
+ */
174
+ export declare function modalKindForState(state: FsmState): 'approval' | 'picker' | 'confirm' | null;
@@ -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;