@adhdev/daemon-core 0.9.82-rc.20 → 0.9.82-rc.201

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 (241) hide show
  1. package/dist/boot/daemon-lifecycle.d.ts +1 -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 +178 -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 +29 -0
  12. package/dist/cli-adapters/raw-terminal-io.d.ts +37 -0
  13. package/dist/commands/cli-manager.d.ts +2 -1
  14. package/dist/commands/handler.d.ts +110 -0
  15. package/dist/commands/mesh-coordinator.d.ts +85 -1
  16. package/dist/commands/router.d.ts +26 -1
  17. package/dist/config/chat-history.d.ts +9 -0
  18. package/dist/config/config.d.ts +5 -0
  19. package/dist/config/mesh-config.d.ts +72 -1
  20. package/dist/git/git-commands.d.ts +7 -1
  21. package/dist/git/git-types.d.ts +2 -0
  22. package/dist/index.d.ts +39 -10
  23. package/dist/index.js +25488 -8333
  24. package/dist/index.js.map +1 -1
  25. package/dist/index.mjs +29124 -12045
  26. package/dist/index.mjs.map +1 -1
  27. package/dist/installer.d.ts +1 -4
  28. package/dist/ipc/local-ipc-server.d.ts +91 -0
  29. package/dist/launch.d.ts +1 -1
  30. package/dist/logging/async-batch-writer.d.ts +10 -0
  31. package/dist/mesh/contracts.d.ts +164 -0
  32. package/dist/mesh/coordinator-prompt.d.ts +30 -0
  33. package/dist/mesh/coordinator-registry.d.ts +59 -0
  34. package/dist/mesh/mesh-active-work.d.ts +90 -0
  35. package/dist/mesh/mesh-delivery-policy.d.ts +126 -0
  36. package/dist/mesh/mesh-events.d.ts +164 -6
  37. package/dist/mesh/mesh-fast-forward.d.ts +41 -0
  38. package/dist/mesh/mesh-host-ownership.d.ts +9 -0
  39. package/dist/mesh/mesh-ledger.d.ts +58 -1
  40. package/dist/mesh/mesh-refine-status.d.ts +26 -0
  41. package/dist/mesh/mesh-runtime-store.d.ts +149 -0
  42. package/dist/mesh/mesh-work-queue.d.ts +55 -6
  43. package/dist/mesh/preview-freshness.d.ts +18 -0
  44. package/dist/mesh/refine-config.d.ts +193 -0
  45. package/dist/mesh/worktree-bootstrap-config.d.ts +113 -0
  46. package/dist/providers/approval-utils.d.ts +13 -0
  47. package/dist/providers/cli-provider-instance.d.ts +39 -3
  48. package/dist/providers/contracts.d.ts +130 -6
  49. package/dist/providers/external-sources.d.ts +71 -0
  50. package/dist/providers/native-history/antigravity-cli-transcript.d.ts +100 -0
  51. package/dist/providers/native-history/claude-cli-transcript.d.ts +70 -0
  52. package/dist/providers/native-history/codex-cli-transcript.d.ts +73 -0
  53. package/dist/providers/native-history/dispatcher.d.ts +27 -0
  54. package/dist/providers/native-history/hermes-cli-transcript.d.ts +30 -0
  55. package/dist/providers/native-history/index.d.ts +13 -0
  56. package/dist/providers/provider-instance-manager.d.ts +12 -0
  57. package/dist/providers/provider-instance.d.ts +13 -1
  58. package/dist/providers/provider-loader.d.ts +26 -4
  59. package/dist/providers/provider-trust.d.ts +31 -0
  60. package/dist/providers/read-chat-contract.d.ts +29 -0
  61. package/dist/providers/sdk/v1/builders/acp/detect-status.d.ts +68 -0
  62. package/dist/providers/sdk/v1/builders/cli/detect-status.d.ts +85 -0
  63. package/dist/providers/sdk/v1/builders/cli/parse-approval-squash.d.ts +59 -0
  64. package/dist/providers/sdk/v1/builders/cli/parse-approval.d.ts +65 -0
  65. package/dist/providers/sdk/v1/builders/cli/parse-session.d.ts +91 -0
  66. package/dist/providers/sdk/v1/builders/cli/visible-region.d.ts +42 -0
  67. package/dist/providers/sdk/v1/fixture-tooling/format.d.ts +126 -0
  68. package/dist/providers/sdk/v1/fixture-tooling/index.d.ts +8 -0
  69. package/dist/providers/sdk/v1/fixture-tooling/replay.d.ts +38 -0
  70. package/dist/providers/sdk/v1/index.d.ts +30 -0
  71. package/dist/providers/sdk/v1/sandbox/README-design.d.ts +193 -0
  72. package/dist/providers/sdk/v1/sandbox/require-whitelist.d.ts +74 -0
  73. package/dist/providers/sdk/v1/sandbox/script-runner.d.ts +98 -0
  74. package/dist/providers/sdk/v1/types/cli/index.d.ts +277 -0
  75. package/dist/providers/sdk/v1/types/common/index.d.ts +203 -0
  76. package/dist/providers/sdk/v1/validators/index.d.ts +5 -0
  77. package/dist/providers/sdk/v1/validators/manifest.d.ts +40 -0
  78. package/dist/providers/sdk/v1/validators/taint.d.ts +52 -0
  79. package/dist/providers/spec/adapter.d.ts +60 -0
  80. package/dist/providers/spec/cli-adapter.d.ts +101 -0
  81. package/dist/providers/spec/driver.d.ts +195 -0
  82. package/dist/providers/spec/evaluator.d.ts +55 -0
  83. package/dist/providers/spec/loader.d.ts +14 -0
  84. package/dist/providers/spec/native-history-executor.d.ts +41 -0
  85. package/dist/providers/spec/route.d.ts +4 -0
  86. package/dist/providers/spec/schema.gen.d.ts +599 -0
  87. package/dist/providers/spec/types.d.ts +282 -0
  88. package/dist/providers/transcript-v2.d.ts +176 -0
  89. package/dist/providers/types/interactive-prompt.d.ts +48 -0
  90. package/dist/repo-mesh-types.d.ts +108 -1
  91. package/dist/sessions/registry.d.ts +3 -0
  92. package/dist/shared-types-extra.d.ts +1 -1
  93. package/dist/shared-types.d.ts +42 -1
  94. package/dist/status/normalize.d.ts +1 -1
  95. package/dist/status/normalize.js +1 -0
  96. package/dist/status/normalize.js.map +1 -1
  97. package/dist/status/normalize.mjs +1 -0
  98. package/dist/status/normalize.mjs.map +1 -1
  99. package/dist/status/reporter.d.ts +2 -0
  100. package/dist/status/snapshot.d.ts +1 -0
  101. package/dist/types.d.ts +5 -0
  102. package/package.json +7 -2
  103. package/src/agent-stream/poller.ts +2 -3
  104. package/src/boot/daemon-lifecycle.ts +19 -10
  105. package/src/boot/process-hardening.ts +89 -0
  106. package/src/chat/source-machine.ts +534 -0
  107. package/src/chat/source-resolver.ts +0 -0
  108. package/src/chat/subscription-updates.ts +20 -1
  109. package/src/cli-adapter-types.d.ts +1 -0
  110. package/src/cli-adapter-types.ts +22 -2
  111. package/src/cli-adapters/cli-script-runner.ts +421 -0
  112. package/src/cli-adapters/cli-state-engine.ts +1138 -0
  113. package/src/cli-adapters/provider-cli-adapter.d.ts +1 -1
  114. package/src/cli-adapters/provider-cli-adapter.ts +670 -1137
  115. package/src/cli-adapters/provider-cli-parse.d.ts +1 -0
  116. package/src/cli-adapters/provider-cli-parse.ts +13 -0
  117. package/src/cli-adapters/provider-cli-runtime.ts +3 -1
  118. package/src/cli-adapters/provider-cli-shared.d.ts +2 -0
  119. package/src/cli-adapters/provider-cli-shared.ts +59 -11
  120. package/src/cli-adapters/raw-terminal-io.ts +252 -0
  121. package/src/cli-adapters/terminal-backends/ghostty-vt-backend.ts +17 -1
  122. package/src/cli-adapters/terminal-backends/xterm-backend.ts +8 -1
  123. package/src/commands/chat-commands.ts +1787 -60
  124. package/src/commands/cli-manager.ts +283 -14
  125. package/src/commands/handler.ts +809 -2
  126. package/src/commands/mesh-coordinator.ts +331 -122
  127. package/src/commands/router.ts +3628 -515
  128. package/src/config/chat-history.ts +95 -24
  129. package/src/config/config.ts +12 -0
  130. package/src/config/mesh-config.ts +280 -2
  131. package/src/config/recent-activity.ts +8 -2
  132. package/src/daemon/dev-cli-debug.ts +10 -1
  133. package/src/detection/ide-detector.ts +26 -16
  134. package/src/git/git-commands.ts +37 -7
  135. package/src/git/git-status.ts +35 -6
  136. package/src/git/git-types.ts +2 -0
  137. package/src/git/git-worktree.ts +8 -1
  138. package/src/index.ts +119 -9
  139. package/src/installer.d.ts +1 -1
  140. package/src/installer.ts +8 -6
  141. package/src/ipc/local-ipc-server.ts +278 -0
  142. package/src/launch.d.ts +1 -1
  143. package/src/launch.ts +37 -28
  144. package/src/logging/async-batch-writer.ts +55 -0
  145. package/src/logging/logger.ts +2 -1
  146. package/src/mesh/contracts.ts +329 -0
  147. package/src/mesh/coordinator-prompt.ts +204 -30
  148. package/src/mesh/coordinator-registry.ts +121 -0
  149. package/src/mesh/mesh-active-work.ts +437 -0
  150. package/src/mesh/mesh-delivery-policy.ts +298 -0
  151. package/src/mesh/mesh-events.ts +1341 -109
  152. package/src/mesh/mesh-fast-forward.ts +438 -0
  153. package/src/mesh/mesh-host-ownership.ts +73 -0
  154. package/src/mesh/mesh-ledger.ts +457 -104
  155. package/src/mesh/mesh-refine-status.ts +144 -0
  156. package/src/mesh/mesh-runtime-store.ts +769 -0
  157. package/src/mesh/mesh-work-queue.ts +267 -159
  158. package/src/mesh/preview-freshness.ts +118 -0
  159. package/src/mesh/refine-config.ts +366 -0
  160. package/src/mesh/worktree-bootstrap-config.ts +247 -0
  161. package/src/providers/approval-utils.d.ts +4 -0
  162. package/src/providers/approval-utils.ts +47 -5
  163. package/src/providers/chat-message-normalization.ts +4 -11
  164. package/src/providers/cli-provider-instance.ts +806 -64
  165. package/src/providers/contracts.d.ts +55 -0
  166. package/src/providers/contracts.ts +141 -6
  167. package/src/providers/external-sources.ts +218 -0
  168. package/src/providers/ide-provider-instance.ts +19 -5
  169. package/src/providers/native-history/antigravity-cli-transcript.ts +643 -0
  170. package/src/providers/native-history/claude-cli-transcript.ts +396 -0
  171. package/src/providers/native-history/codex-cli-transcript.ts +419 -0
  172. package/src/providers/native-history/dispatcher.ts +340 -0
  173. package/src/providers/native-history/hermes-cli-transcript.ts +230 -0
  174. package/src/providers/native-history/index.ts +30 -0
  175. package/src/providers/provider-instance-manager.ts +30 -0
  176. package/src/providers/provider-instance.ts +10 -1
  177. package/src/providers/provider-loader.ts +582 -50
  178. package/src/providers/provider-schema.ts +87 -14
  179. package/src/providers/provider-trust.ts +114 -0
  180. package/src/providers/read-chat-contract.ts +76 -16
  181. package/src/providers/sdk/README.md +49 -0
  182. package/src/providers/sdk/v1/builders/acp/detect-status.ts +144 -0
  183. package/src/providers/sdk/v1/builders/cli/detect-status.ts +262 -0
  184. package/src/providers/sdk/v1/builders/cli/parse-approval-squash.ts +158 -0
  185. package/src/providers/sdk/v1/builders/cli/parse-approval.ts +250 -0
  186. package/src/providers/sdk/v1/builders/cli/parse-session.ts +276 -0
  187. package/src/providers/sdk/v1/builders/cli/visible-region.ts +143 -0
  188. package/src/providers/sdk/v1/fixture-tooling/format.ts +130 -0
  189. package/src/providers/sdk/v1/fixture-tooling/index.ts +22 -0
  190. package/src/providers/sdk/v1/fixture-tooling/replay.ts +352 -0
  191. package/src/providers/sdk/v1/index.ts +152 -0
  192. package/src/providers/sdk/v1/sandbox/README-design.ts +195 -0
  193. package/src/providers/sdk/v1/sandbox/require-whitelist.ts +472 -0
  194. package/src/providers/sdk/v1/sandbox/script-runner.ts +150 -0
  195. package/src/providers/sdk/v1/schemas/cli/provider.schema.json +504 -0
  196. package/src/providers/sdk/v1/schemas/primitives/acp-session-protocol-v1.json +131 -0
  197. package/src/providers/sdk/v1/schemas/primitives/native-history-codex-rollout-v1.json +66 -0
  198. package/src/providers/sdk/v1/schemas/primitives/tui-approval-squash-v1.json +91 -0
  199. package/src/providers/sdk/v1/schemas/primitives/tui-assistant-block-v1.json +91 -0
  200. package/src/providers/sdk/v1/schemas/primitives/tui-cue-ordering-v1.json +47 -0
  201. package/src/providers/sdk/v1/schemas/primitives/tui-dispatch-order-v1.json +32 -0
  202. package/src/providers/sdk/v1/schemas/primitives/tui-footer-chrome-v1.json +42 -0
  203. package/src/providers/sdk/v1/schemas/primitives/tui-index-finder-v1.json +27 -0
  204. package/src/providers/sdk/v1/schemas/primitives/tui-modal-v1.json +125 -0
  205. package/src/providers/sdk/v1/schemas/primitives/tui-prompt-marker-v1.json +45 -0
  206. package/src/providers/sdk/v1/schemas/primitives/tui-session-id-extraction-v1.json +46 -0
  207. package/src/providers/sdk/v1/schemas/primitives/tui-settled-prompt-v1.json +71 -0
  208. package/src/providers/sdk/v1/schemas/primitives/tui-spinner-v1.json +83 -0
  209. package/src/providers/sdk/v1/schemas/primitives/tui-transcript-pty-v1.json +83 -0
  210. package/src/providers/sdk/v1/schemas/primitives/tui-visible-region-v1.json +57 -0
  211. package/src/providers/sdk/v1/schemas/primitives/tui-welcome-screen-v1.json +35 -0
  212. package/src/providers/sdk/v1/types/cli/index.ts +365 -0
  213. package/src/providers/sdk/v1/types/common/index.ts +229 -0
  214. package/src/providers/sdk/v1/validators/index.ts +19 -0
  215. package/src/providers/sdk/v1/validators/manifest.ts +110 -0
  216. package/src/providers/sdk/v1/validators/taint.ts +309 -0
  217. package/src/providers/spec/adapter.ts +176 -0
  218. package/src/providers/spec/cli-adapter.ts +573 -0
  219. package/src/providers/spec/driver.ts +733 -0
  220. package/src/providers/spec/evaluator.ts +373 -0
  221. package/src/providers/spec/loader.ts +130 -0
  222. package/src/providers/spec/native-history-executor.ts +939 -0
  223. package/src/providers/spec/route.ts +51 -0
  224. package/src/providers/spec/schema.gen.ts +559 -0
  225. package/src/providers/spec/schema.json +237 -0
  226. package/src/providers/spec/types.ts +301 -0
  227. package/src/providers/transcript-v2.ts +567 -0
  228. package/src/providers/types/interactive-prompt.ts +425 -0
  229. package/src/providers/version-archive.ts +38 -20
  230. package/src/repo-mesh-types.ts +118 -1
  231. package/src/sessions/registry.ts +3 -0
  232. package/src/shared-types-extra.ts +1 -1
  233. package/src/shared-types.ts +45 -1
  234. package/src/status/builders.ts +24 -6
  235. package/src/status/normalize.ts +2 -0
  236. package/src/status/reporter.ts +15 -0
  237. package/src/status/snapshot.ts +84 -25
  238. package/src/system/host-memory.ts +29 -12
  239. package/src/types.ts +5 -0
  240. package/dist/mesh/mesh-sync.d.ts +0 -53
  241. package/src/mesh/mesh-sync.ts +0 -111
@@ -0,0 +1,282 @@
1
+ export type Size = number | string;
2
+ export interface Section {
3
+ id: string;
4
+ from_top?: Size;
5
+ from_bottom?: Size;
6
+ until?: {
7
+ section: string;
8
+ };
9
+ /** Scan the screen for the first (or last, if anchor_last=true) line
10
+ * matching this regex and use that line as the section start.
11
+ * Combine with `lines`, `until_regex`, or leave alone (defaults to
12
+ * end-of-screen) to control how far it extends. */
13
+ anchor_regex?: string;
14
+ anchor_flags?: string;
15
+ /** If true, use the LAST matching line instead of the first. Useful
16
+ * when the anchor pattern appears multiple times (e.g. separator
17
+ * lines) and you want the one closest to the bottom. */
18
+ anchor_last?: boolean;
19
+ /** Optional neighbouring-line guards that must also match for the
20
+ * anchor to be accepted. Reduces false positives when the anchor
21
+ * pattern could appear elsewhere on screen (e.g. `>` in body text).
22
+ * `prev` checks the line immediately above; `next` the line below. */
23
+ anchor_context?: {
24
+ prev?: string;
25
+ prev_flags?: string;
26
+ next?: string;
27
+ next_flags?: string;
28
+ };
29
+ /** When used with anchor_regex: take at most this many lines from the
30
+ * anchor point. */
31
+ lines?: number;
32
+ /** When used with anchor_regex: extend until the first line matching
33
+ * this regex (exclusive). Takes precedence over `lines`. */
34
+ until_regex?: string;
35
+ until_regex_flags?: string;
36
+ }
37
+ export interface SectionRegex {
38
+ section?: string;
39
+ regex: string;
40
+ flags?: string;
41
+ /**
42
+ * Optional cursor-position guards. When present, the state is only
43
+ * considered matched if the terminal cursor row/column satisfies the
44
+ * bounds (0-based, inclusive). Missing or undefined means "no constraint".
45
+ *
46
+ * Use case: distinguish modal zone from body zone for TUIs that use
47
+ * cursor position rather than distinct text to locate the active prompt
48
+ * (e.g. Antigravity cursor lands in modal_zone rows 8-31 when approval
49
+ * is visible, never in body rows 0-7). Without this guard, body text
50
+ * containing "Do you want to proceed?" could false-positive a modal match.
51
+ */
52
+ cursor_row_min?: number;
53
+ cursor_row_max?: number;
54
+ cursor_col_min?: number;
55
+ cursor_col_max?: number;
56
+ }
57
+ export interface SectionPattern {
58
+ section?: string;
59
+ pattern: string;
60
+ flags?: string;
61
+ }
62
+ export interface ModalButtonsRule {
63
+ section?: string;
64
+ pattern: string;
65
+ flags?: string;
66
+ key_for_index: string;
67
+ min_count?: number;
68
+ continuation_lines?: boolean;
69
+ }
70
+ export interface SpecState {
71
+ id: string;
72
+ label: string;
73
+ when: SectionRegex;
74
+ extract_title?: SectionRegex;
75
+ modal_buttons?: ModalButtonsRule;
76
+ }
77
+ export type ControlAction = {
78
+ type: 'send_keys';
79
+ keys: string;
80
+ } | {
81
+ type: 'open_picker';
82
+ trigger_keys: string;
83
+ wait_for: SectionRegex;
84
+ extract_choices: SectionPattern;
85
+ submit_key: string;
86
+ } | {
87
+ type: 'attach_image';
88
+ method: 'tempfile_then_keys';
89
+ keys_template: string;
90
+ };
91
+ export interface Control {
92
+ id: string;
93
+ label: string;
94
+ visible_when_state?: string[];
95
+ action: ControlAction;
96
+ }
97
+ export interface NotificationRule {
98
+ id: string;
99
+ when_state: string;
100
+ title: string;
101
+ body?: string;
102
+ }
103
+ export interface DelegateTrigger {
104
+ id: string;
105
+ when_state: string;
106
+ after_duration_ms?: number;
107
+ task_template: string;
108
+ }
109
+ /**
110
+ * Native history config — three modes, picked by which fields are present:
111
+ *
112
+ * 1. `reader`: built-in reader id (claude-cli / codex-cli / antigravity-cli / hermes-cli).
113
+ * Backwards-compatible path used by the four shipped providers.
114
+ *
115
+ * 2. `source`: declarative source descriptor. The daemon's spec native-history
116
+ * executor reads the on-disk store (jsonl file / sqlite db) directly using
117
+ * paths + jsonpath maps from this block. New providers should prefer this
118
+ * mode — no daemon changes required.
119
+ *
120
+ * 3. `override_path`: relative path to a provider-supplied reader module
121
+ * (e.g. "./native_history/index.js"). Escape hatch for formats too
122
+ * exotic for the declarative executor. The module must default-export
123
+ * a function with the signature
124
+ * (input: NativeHistoryInput) => NativeHistoryResult | null
125
+ * and runs under provider-script-root sandboxing (same gate as
126
+ * scripts.js).
127
+ *
128
+ * The three modes are mutually exclusive — set exactly one. Loader rejects
129
+ * specs that set zero or more than one.
130
+ */
131
+ export interface NativeHistoryConfig {
132
+ reader?: 'claude-cli' | 'codex-cli' | 'antigravity-cli' | 'hermes-cli';
133
+ source?: NativeHistorySource;
134
+ override_path?: string;
135
+ }
136
+ export type NativeHistorySource = NativeHistoryJsonlSource | NativeHistorySqliteSource;
137
+ /**
138
+ * JSONL source — each line in the resolved file is one record.
139
+ *
140
+ * `path` accepts ~/, environment variables (${HOME}), and a small set of
141
+ * runtime variables:
142
+ * {cwd} — the session's working directory, raw
143
+ * {cwd_dashed} — cwd with `/` replaced by `-` (claude's per-project key)
144
+ * {session_id} — providerSessionId, when known
145
+ * {yyyy} {mm} {dd} — UTC date components
146
+ *
147
+ * When `path` resolves to a directory, the daemon picks the newest file
148
+ * matching `file_pattern` whose mtime is inside `recent_window_ms` (default
149
+ * 5min) — prevents the wrong session's transcript from leaking through.
150
+ */
151
+ export interface NativeHistoryJsonlSource {
152
+ kind: 'jsonl';
153
+ path: string;
154
+ file_pattern?: string;
155
+ recent_window_ms?: number;
156
+ session_id_from?: 'filename_uuid' | 'first_record';
157
+ session_id_path?: string;
158
+ message_filter?: {
159
+ where: string;
160
+ };
161
+ message_map: NativeHistoryMessageMap;
162
+ }
163
+ /**
164
+ * SQLite source — provider runs two queries on a read-only handle: one to
165
+ * pick the session row (`session_query` — first row's first column is the
166
+ * sessionId), then one to fetch messages (`message_query` — `?` is bound
167
+ * to the sessionId). Output rows are projected through `message_map`.
168
+ */
169
+ export interface NativeHistorySqliteSource {
170
+ kind: 'sqlite';
171
+ path: string;
172
+ session_query: string;
173
+ message_query: string;
174
+ message_map: NativeHistoryMessageMap;
175
+ }
176
+ /**
177
+ * Maps a source record (jsonl line object / sqlite row) to a daemon
178
+ * native-history message. Values are jsonpath-lite strings: `$.foo.bar`
179
+ * or `$.items[0].text`. Literal strings (no leading `$`) pass through.
180
+ *
181
+ * `content_strip` lets a spec drop wrapper tags that the agent injects
182
+ * into its own transcript (claude's `<local-command-caveat>`, agy's
183
+ * `<USER_REQUEST>` / `<ADDITIONAL_METADATA>` / `<USER_SETTINGS_CHANGE>`).
184
+ * Each entry is a tag name; the executor removes `<tag>…</tag>` segments
185
+ * non-greedily before the value is handed to the dashboard. After all
186
+ * strips, leading/trailing whitespace is trimmed. If the result is empty
187
+ * the message is dropped.
188
+ */
189
+ export interface NativeHistoryMessageMap {
190
+ role: string;
191
+ content: string;
192
+ /**
193
+ * Tags whose entire `<tag>…</tag>` segment is removed from content.
194
+ * Use for noise wrappers the agent ships alongside the real message
195
+ * (claude's `<local-command-caveat>`, agy's `<ADDITIONAL_METADATA>`).
196
+ */
197
+ content_strip?: string[];
198
+ /**
199
+ * Tags whose open/close markers are removed but inner content is kept.
200
+ * Use when the *real* user/assistant message is wrapped in a tag
201
+ * the agent uses for routing (agy wraps user input in `<USER_REQUEST>`).
202
+ */
203
+ content_unwrap?: string[];
204
+ timestamp_ms?: string;
205
+ kind?: string;
206
+ }
207
+ export interface CliSpec {
208
+ $schema: 'adhdev:cli/spec@1';
209
+ id: string;
210
+ name: string;
211
+ binary: string;
212
+ spawn_args?: string[];
213
+ env?: Record<string, string>;
214
+ /**
215
+ * Optional version constraint this spec is authored for, e.g. ">=2.1.0".
216
+ * Pure metadata used by tooling/UI — the actual version-to-spec match
217
+ * happens in provider-loader via the manifest's compatibility array.
218
+ * Spec authors include this so a misrouted spec is easy to spot.
219
+ */
220
+ cli_version_range?: string;
221
+ send_message: {
222
+ submit_key: string;
223
+ delay_ms_before_submit?: number;
224
+ delay_ms_per_char?: number;
225
+ };
226
+ layout: {
227
+ sections: Section[];
228
+ };
229
+ states: SpecState[];
230
+ default_state: string;
231
+ control_bar?: Control[];
232
+ notifications?: NotificationRule[];
233
+ delegate?: DelegateTrigger[];
234
+ native_history?: NativeHistoryConfig;
235
+ /**
236
+ * When true, the daemon's completed-finalization gate will not emit
237
+ * `generating_completed` until native history confirms the last message
238
+ * role is `assistant`. Prevents PTY quiet-period from triggering idle
239
+ * before the CLI has finished writing its response to disk.
240
+ */
241
+ requiresFinalAssistantBeforeIdle?: boolean;
242
+ /**
243
+ * Per-spec debounce knobs. Defaults are conservative (busy_hold_ms
244
+ * 6000) and live in SpecDriver. Spec authors override here when a
245
+ * particular CLI flickers slower/faster than the default.
246
+ */
247
+ debounce?: {
248
+ /** Min time to stay in busy after the evaluator last reported it.
249
+ * Absorbs per-frame flicker in TUIs that stream output through
250
+ * the same region as the spinner. */
251
+ busy_hold_ms?: number;
252
+ /** Min time the idle state must remain matched before it is
253
+ * committed. Filters transient idle flickers that appear during
254
+ * approval dismissals, layout reflows, or brief spinner gaps.
255
+ * Any non-idle reading within the window cancels the transition.
256
+ * When omitted the idle transition is immediate (legacy behaviour). */
257
+ idle_hold_ms?: number;
258
+ /** Min time after start() before a send_message is allowed to
259
+ * reach the PTY. Banner paints + auth flows + skill listings
260
+ * can keep the agent unable to accept input for several seconds
261
+ * even though the idle regex matches a transient empty prompt.
262
+ * Send_messages issued before this window are queued and drained
263
+ * once the window passes and an idle state has actually been
264
+ * observed. */
265
+ startup_grace_ms?: number;
266
+ /** Treat a provider-specific completion marker as idle after it has
267
+ * remained visible for hold_ms. This handles TUIs that leave their
268
+ * last spinner glyph next to a completed timer, causing the normal
269
+ * busy regex to keep matching after the turn is done. */
270
+ completion_idle_after?: {
271
+ section?: string;
272
+ regex: string;
273
+ flags?: string;
274
+ hold_ms: number;
275
+ /** If the target-state check still fails this many ms after hold_ms
276
+ * expired, force an idle transition anyway. Guards against TUIs that
277
+ * show transient UI (pickers, option lists) after the completion
278
+ * marker appears, keeping the target-state regex from matching. */
279
+ force_after_ms?: number;
280
+ };
281
+ };
282
+ }
@@ -0,0 +1,176 @@
1
+ /**
2
+ * Chat Transcript Contract v2
3
+ *
4
+ * First-class message identity, monotonic sequence, strict enums. Designed to
5
+ * replace the v1 contract (contracts.ts ReadChatResult + types.ts ChatMessage)
6
+ * during the A2 big-bang. This module defines the contract; it does not yet
7
+ * change runtime behaviour. v1 keeps working until A2 flips the switch.
8
+ *
9
+ * Invariants v2 enforces (and v1 does not):
10
+ * 1. Every ChatMessageV2 has providerUnitKey, bubbleId, sequence — none optional.
11
+ * 2. sequence is a monotonic integer per (sessionId, source) tuple. Producers
12
+ * never reuse it; consumers MAY assume strict ordering.
13
+ * 3. providerUnitKey is stable across re-reads: the same logical message
14
+ * always yields the same key even if its index shifts or content is
15
+ * edited mid-stream. Producers derive it from provider-owned identifiers
16
+ * (turn id, native message id), not from content hashes or array index.
17
+ * 4. timestamp is producer-asserted wall-clock; orderingTimestamp is monotonic
18
+ * and used for snapshot diffs. 1ms fallback increments are forbidden — if
19
+ * a producer cannot supply a stable monotonic value, the daemon assigns
20
+ * sequence at ingest and orderingTimestamp = ingestedAt.
21
+ * 5. visibility / source / role / kind are strict unions. No `(string & {})`
22
+ * escape hatches.
23
+ * 6. Coverage is exactly one of full/tail/current-turn. Mixing it with
24
+ * partialReason or unavailableReason is a contract violation.
25
+ * 7. workspace / sessionId are explicit on every ReadChatResultV2; the daemon
26
+ * no longer infers them from message bodies.
27
+ */
28
+ import type { MessagePart, ToolCallInfo } from './contracts.js';
29
+ export declare const CHAT_CONTRACT_VERSION_V1: "1.0";
30
+ export declare const CHAT_CONTRACT_VERSION_V2: "2.0";
31
+ export type ChatContractVersion = typeof CHAT_CONTRACT_VERSION_V1 | typeof CHAT_CONTRACT_VERSION_V2;
32
+ export declare const SUPPORTED_CHAT_CONTRACT_VERSIONS: readonly ChatContractVersion[];
33
+ export declare const CHAT_ROLES_V2: readonly ["user", "assistant", "system"];
34
+ export type ChatRoleV2 = typeof CHAT_ROLES_V2[number];
35
+ export declare const CHAT_MESSAGE_KINDS_V2: readonly ["standard", "thought", "tool", "terminal", "system"];
36
+ export type ChatMessageKindV2 = typeof CHAT_MESSAGE_KINDS_V2[number];
37
+ export declare const CHAT_VISIBILITIES_V2: readonly ["user", "debug", "internal", "hidden"];
38
+ export type ChatVisibilityV2 = typeof CHAT_VISIBILITIES_V2[number];
39
+ export declare const CHAT_AUDIENCES_V2: readonly ["chat", "debug", "trace", "internal"];
40
+ export type ChatAudienceV2 = typeof CHAT_AUDIENCES_V2[number];
41
+ export declare const CHAT_SOURCES_V2: readonly ["assistant_text", "tool_call", "terminal_command", "runtime_activity", "runtime_status", "provider_chrome", "control"];
42
+ export type ChatSourceV2 = typeof CHAT_SOURCES_V2[number];
43
+ export declare const CHAT_BUBBLE_STATES_V2: readonly ["draft", "streaming", "final", "removed"];
44
+ export type ChatBubbleStateV2 = typeof CHAT_BUBBLE_STATES_V2[number];
45
+ /**
46
+ * Stable identity of a single chat message. All fields are required in v2.
47
+ *
48
+ * - providerUnitKey: provider-owned canonical id. Must be derivable from
49
+ * provider primitives (native message id, turn id, bubble id), NOT from
50
+ * array index or content hash. Stable across re-reads of the same logical
51
+ * message even if neighbours change.
52
+ * - bubbleId: dashboard-owned bubble identity. May equal providerUnitKey when
53
+ * the provider already exposes a bubble-grained id; otherwise daemon
54
+ * derives it deterministically from providerUnitKey (e.g. `bubble:${key}`).
55
+ * - sequence: monotonic integer per (sessionId, source). Strictly increasing
56
+ * over the lifetime of the session. Used for snapshot diffs and dedup.
57
+ * - turnKey: stable identifier for the conversation turn this message belongs
58
+ * to. Required so consumers can group messages without re-deriving turns.
59
+ */
60
+ export interface MessageIdentityV2 {
61
+ providerUnitKey: string;
62
+ bubbleId: string;
63
+ sequence: number;
64
+ turnKey: string;
65
+ }
66
+ /**
67
+ * Producer-asserted wall-clock time (ms since epoch). Forward jumps are
68
+ * permitted; consumers MUST NOT rely on this for ordering.
69
+ */
70
+ export type ChatTimestampMs = number;
71
+ /**
72
+ * Monotonic ordering value (ms since epoch, but assigned by the daemon at
73
+ * ingest to guarantee monotonicity even if the producer's wall clock skews).
74
+ * Used by snapshot diffs in place of timestamp.
75
+ */
76
+ export type ChatOrderingTimestampMs = number;
77
+ export interface ChatMessageV2 extends MessageIdentityV2 {
78
+ role: ChatRoleV2;
79
+ kind: ChatMessageKindV2;
80
+ content: string | MessagePart[];
81
+ bubbleState: ChatBubbleStateV2;
82
+ timestamp: ChatTimestampMs;
83
+ orderingTimestamp: ChatOrderingTimestampMs;
84
+ visibility: ChatVisibilityV2;
85
+ audience: ChatAudienceV2;
86
+ source: ChatSourceV2;
87
+ /** Sender display name (for shared sessions). Empty string when unused. */
88
+ senderName: string;
89
+ /** Tool calls associated with this message. Empty array when none. */
90
+ toolCalls: ToolCallInfo[];
91
+ /** Producer-defined metadata. Daemon never inspects this except for passthrough. */
92
+ meta: Readonly<Record<string, unknown>>;
93
+ }
94
+ export interface WorkspaceContextV2 {
95
+ /** Absolute realpath of the workspace the session is reading from. */
96
+ workspacePath: string;
97
+ /** Workspace the session was intended to operate on (may differ during cross-workspace ops). */
98
+ intendedWorkspacePath: string;
99
+ }
100
+ export interface SessionContextV2 {
101
+ /** Provider-owned session id (e.g. claude.jsonl uuid, codex session_meta.id). */
102
+ providerSessionId: string;
103
+ /** Optional daemon-side history alias used to disambiguate within a workspace. */
104
+ historySessionId?: string;
105
+ }
106
+ /**
107
+ * v1 allowed `coverage='full'` to coexist with `partialReason`/`unavailableReason`,
108
+ * which is a contract lie. v2 makes the three states mutually exclusive.
109
+ */
110
+ export type CoverageHintV2 = {
111
+ kind: 'full';
112
+ } | {
113
+ kind: 'tail';
114
+ tailMessageCount: number;
115
+ } | {
116
+ kind: 'current-turn';
117
+ turnKey: string;
118
+ } | {
119
+ kind: 'partial';
120
+ partialReason: string;
121
+ } | {
122
+ kind: 'unavailable';
123
+ unavailableReason: string;
124
+ };
125
+ export type CanonicalHistoryModeV2 = 'native-source' | 'disabled' | 'materialized-mirror';
126
+ export interface CanonicalHistoryDeclarationV2 {
127
+ contractVersion: ChatContractVersion;
128
+ format: string;
129
+ mode: CanonicalHistoryModeV2;
130
+ watchPath?: string;
131
+ scripts: {
132
+ readSession: string;
133
+ listSessions: string;
134
+ };
135
+ }
136
+ export type ReadChatStatusV2 = 'idle' | 'generating' | 'waiting_approval' | 'error' | 'panel_hidden' | 'streaming';
137
+ export type ReadChatTurnStatusV2 = 'open' | 'waiting_approval' | 'complete' | 'error';
138
+ export interface ReadChatResultV2 {
139
+ contractVersion: typeof CHAT_CONTRACT_VERSION_V2;
140
+ workspace: WorkspaceContextV2;
141
+ session: SessionContextV2;
142
+ coverage: CoverageHintV2;
143
+ status: ReadChatStatusV2;
144
+ messages: ChatMessageV2[];
145
+ currentTurnId: string;
146
+ turnStatus: ReadChatTurnStatusV2;
147
+ transcriptAuthority: 'provider' | 'daemon';
148
+ }
149
+ export declare class ChatContractViolationError extends Error {
150
+ readonly violationPath: string;
151
+ readonly contractVersion: ChatContractVersion;
152
+ constructor(contractVersion: ChatContractVersion, violationPath: string, detail: string);
153
+ }
154
+ /**
155
+ * Validate a v2 read_chat payload. Throws ChatContractViolationError on the
156
+ * first violation. v2 invariants beyond per-field checks:
157
+ * - messages[*].sequence strictly increasing
158
+ * - messages[*].orderingTimestamp monotonic non-decreasing
159
+ * - coverage union is well-formed
160
+ */
161
+ export declare function assertReadChatResultV2Payload(raw: unknown): ReadChatResultV2;
162
+ export declare function isSupportedChatContractVersion(value: unknown): value is ChatContractVersion;
163
+ /**
164
+ * Read a provider's declared chat contract version from its parsed
165
+ * provider.json `canonicalHistory.contractVersion` field.
166
+ *
167
+ * - Absent or unrecognized → treated as v1 (legacy behaviour preserved during
168
+ * the A1 transition). A2 will tighten this to reject unsupported versions
169
+ * at provider load time.
170
+ * - Present and supported → returned as-is.
171
+ *
172
+ * The returned version drives which validator (assertReadChatResultV2Payload
173
+ * vs the legacy validateReadChatResultPayload) processes the provider's
174
+ * read_chat output.
175
+ */
176
+ export declare function readDeclaredChatContractVersion(canonicalHistory: unknown): ChatContractVersion;
@@ -0,0 +1,48 @@
1
+ export interface InteractivePrompt {
2
+ promptId: string;
3
+ origin: 'cli' | 'mcp' | 'agent';
4
+ providerType: string;
5
+ createdAt: number;
6
+ questions: InteractiveQuestion[];
7
+ }
8
+ export interface InteractiveQuestion {
9
+ questionId: string;
10
+ question: string;
11
+ header?: string;
12
+ multiSelect: boolean;
13
+ options: InteractiveOption[];
14
+ allowFreeform?: boolean;
15
+ }
16
+ export interface InteractiveOption {
17
+ label: string;
18
+ description?: string;
19
+ preview?: string;
20
+ }
21
+ export interface InteractivePromptResponse {
22
+ promptId: string;
23
+ answers: Record<string, InteractiveAnswer>;
24
+ }
25
+ export interface InteractiveAnswer {
26
+ selectedLabels: string[];
27
+ freeformText?: string;
28
+ }
29
+ export declare function normalizeInteractivePrompt(raw: unknown): InteractivePrompt | null;
30
+ export declare function normalizeInteractivePromptResponse(raw: unknown): InteractivePromptResponse;
31
+ export declare function buildClaudeInteractiveToolResult(response: InteractivePromptResponse): string;
32
+ export interface ClaudeInteractiveTuiPage {
33
+ screenText: string;
34
+ header?: string;
35
+ }
36
+ export declare function detectClaudeAskUserQuestionPromptFromTuiPages(pages: ClaudeInteractiveTuiPage[], options: {
37
+ promptId: string;
38
+ providerType?: string;
39
+ createdAt?: number;
40
+ }): InteractivePrompt | null;
41
+ export declare function buildClaudeInteractiveTuiAnswerSteps(prompt: InteractivePrompt, response: InteractivePromptResponse): string[];
42
+ export declare function interactivePromptFromClaudeAskUserQuestion(input: unknown, options: {
43
+ promptId: string;
44
+ providerType: string;
45
+ createdAt?: number;
46
+ origin?: InteractivePrompt['origin'];
47
+ }): InteractivePrompt | null;
48
+ export declare function detectClaudeAskUserQuestionPromptFromJson(value: unknown, providerType?: string): InteractivePrompt | null;