@adhdev/daemon-core 0.9.82-rc.17 → 0.9.82-rc.170

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 (221) hide show
  1. package/dist/boot/process-hardening.d.ts +50 -0
  2. package/dist/chat/source-machine.d.ts +166 -0
  3. package/dist/chat/source-resolver.d.ts +104 -0
  4. package/dist/chat/subscription-updates.d.ts +1 -0
  5. package/dist/cli-adapter-types.d.ts +22 -2
  6. package/dist/cli-adapters/cli-script-runner.d.ts +117 -0
  7. package/dist/cli-adapters/cli-state-engine.d.ts +178 -0
  8. package/dist/cli-adapters/provider-cli-adapter.d.ts +106 -63
  9. package/dist/cli-adapters/provider-cli-parse.d.ts +4 -0
  10. package/dist/cli-adapters/provider-cli-shared.d.ts +29 -0
  11. package/dist/cli-adapters/raw-terminal-io.d.ts +37 -0
  12. package/dist/commands/handler.d.ts +110 -0
  13. package/dist/commands/mesh-coordinator.d.ts +72 -1
  14. package/dist/commands/router.d.ts +22 -0
  15. package/dist/config/chat-history.d.ts +7 -0
  16. package/dist/config/config.d.ts +5 -0
  17. package/dist/config/mesh-config.d.ts +71 -1
  18. package/dist/git/git-commands.d.ts +5 -1
  19. package/dist/index.d.ts +35 -6
  20. package/dist/index.js +18621 -3760
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.mjs +18525 -3732
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/installer.d.ts +1 -4
  25. package/dist/ipc/local-ipc-server.d.ts +91 -0
  26. package/dist/launch.d.ts +1 -1
  27. package/dist/logging/async-batch-writer.d.ts +10 -0
  28. package/dist/mesh/beads-db.d.ts +72 -0
  29. package/dist/mesh/contracts.d.ts +164 -0
  30. package/dist/mesh/coordinator-prompt.d.ts +30 -0
  31. package/dist/mesh/coordinator-registry.d.ts +59 -0
  32. package/dist/mesh/mesh-active-work.d.ts +90 -0
  33. package/dist/mesh/mesh-events.d.ts +96 -5
  34. package/dist/mesh/mesh-fast-forward.d.ts +39 -0
  35. package/dist/mesh/mesh-host-ownership.d.ts +9 -0
  36. package/dist/mesh/mesh-ledger.d.ts +58 -1
  37. package/dist/mesh/mesh-refine-status.d.ts +26 -0
  38. package/dist/mesh/mesh-work-queue.d.ts +44 -5
  39. package/dist/mesh/preview-freshness.d.ts +18 -0
  40. package/dist/mesh/refine-config.d.ts +193 -0
  41. package/dist/mesh/worktree-bootstrap-config.d.ts +113 -0
  42. package/dist/providers/approval-utils.d.ts +13 -0
  43. package/dist/providers/cli-provider-instance.d.ts +9 -3
  44. package/dist/providers/contracts.d.ts +98 -5
  45. package/dist/providers/external-sources.d.ts +71 -0
  46. package/dist/providers/native-history/antigravity-cli-transcript.d.ts +100 -0
  47. package/dist/providers/native-history/claude-cli-transcript.d.ts +70 -0
  48. package/dist/providers/native-history/codex-cli-transcript.d.ts +73 -0
  49. package/dist/providers/native-history/dispatcher.d.ts +24 -0
  50. package/dist/providers/native-history/hermes-cli-transcript.d.ts +30 -0
  51. package/dist/providers/native-history/index.d.ts +13 -0
  52. package/dist/providers/provider-instance.d.ts +3 -0
  53. package/dist/providers/provider-loader.d.ts +26 -4
  54. package/dist/providers/provider-trust.d.ts +31 -0
  55. package/dist/providers/read-chat-contract.d.ts +29 -0
  56. package/dist/providers/sdk/v1/builders/acp/detect-status.d.ts +68 -0
  57. package/dist/providers/sdk/v1/builders/cli/detect-status.d.ts +85 -0
  58. package/dist/providers/sdk/v1/builders/cli/parse-approval-squash.d.ts +59 -0
  59. package/dist/providers/sdk/v1/builders/cli/parse-approval.d.ts +65 -0
  60. package/dist/providers/sdk/v1/builders/cli/parse-session.d.ts +91 -0
  61. package/dist/providers/sdk/v1/builders/cli/visible-region.d.ts +42 -0
  62. package/dist/providers/sdk/v1/fixture-tooling/format.d.ts +126 -0
  63. package/dist/providers/sdk/v1/fixture-tooling/index.d.ts +8 -0
  64. package/dist/providers/sdk/v1/fixture-tooling/replay.d.ts +38 -0
  65. package/dist/providers/sdk/v1/index.d.ts +30 -0
  66. package/dist/providers/sdk/v1/sandbox/README-design.d.ts +193 -0
  67. package/dist/providers/sdk/v1/sandbox/require-whitelist.d.ts +74 -0
  68. package/dist/providers/sdk/v1/sandbox/script-runner.d.ts +98 -0
  69. package/dist/providers/sdk/v1/types/cli/index.d.ts +277 -0
  70. package/dist/providers/sdk/v1/types/common/index.d.ts +169 -0
  71. package/dist/providers/sdk/v1/validators/index.d.ts +5 -0
  72. package/dist/providers/sdk/v1/validators/manifest.d.ts +40 -0
  73. package/dist/providers/sdk/v1/validators/taint.d.ts +52 -0
  74. package/dist/providers/spec/adapter.d.ts +56 -0
  75. package/dist/providers/spec/cli-adapter.d.ts +95 -0
  76. package/dist/providers/spec/driver.d.ts +149 -0
  77. package/dist/providers/spec/evaluator.d.ts +47 -0
  78. package/dist/providers/spec/loader.d.ts +14 -0
  79. package/dist/providers/spec/native-history-executor.d.ts +39 -0
  80. package/dist/providers/spec/route.d.ts +4 -0
  81. package/dist/providers/spec/schema.gen.d.ts +511 -0
  82. package/dist/providers/spec/types.d.ts +212 -0
  83. package/dist/providers/transcript-v2.d.ts +176 -0
  84. package/dist/providers/types/interactive-prompt.d.ts +48 -0
  85. package/dist/repo-mesh-types.d.ts +100 -1
  86. package/dist/sessions/registry.d.ts +3 -0
  87. package/dist/shared-types.d.ts +42 -1
  88. package/dist/status/reporter.d.ts +2 -0
  89. package/dist/status/snapshot.d.ts +1 -0
  90. package/dist/types.d.ts +5 -0
  91. package/package.json +7 -2
  92. package/src/agent-stream/poller.ts +2 -3
  93. package/src/boot/daemon-lifecycle.ts +17 -10
  94. package/src/boot/process-hardening.ts +89 -0
  95. package/src/chat/source-machine.ts +534 -0
  96. package/src/chat/source-resolver.ts +0 -0
  97. package/src/chat/subscription-updates.ts +14 -1
  98. package/src/cli-adapter-types.d.ts +1 -0
  99. package/src/cli-adapter-types.ts +21 -2
  100. package/src/cli-adapters/cli-script-runner.ts +421 -0
  101. package/src/cli-adapters/cli-state-engine.ts +1086 -0
  102. package/src/cli-adapters/provider-cli-adapter.d.ts +1 -1
  103. package/src/cli-adapters/provider-cli-adapter.ts +670 -1137
  104. package/src/cli-adapters/provider-cli-parse.d.ts +1 -0
  105. package/src/cli-adapters/provider-cli-parse.ts +13 -0
  106. package/src/cli-adapters/provider-cli-runtime.ts +3 -1
  107. package/src/cli-adapters/provider-cli-shared.d.ts +2 -0
  108. package/src/cli-adapters/provider-cli-shared.ts +59 -11
  109. package/src/cli-adapters/raw-terminal-io.ts +252 -0
  110. package/src/cli-adapters/terminal-backends/ghostty-vt-backend.ts +17 -1
  111. package/src/cli-adapters/terminal-backends/xterm-backend.ts +8 -1
  112. package/src/commands/chat-commands.ts +1597 -60
  113. package/src/commands/cli-manager.ts +214 -3
  114. package/src/commands/handler.ts +809 -2
  115. package/src/commands/mesh-coordinator.ts +231 -127
  116. package/src/commands/router.ts +3559 -502
  117. package/src/config/chat-history.ts +87 -24
  118. package/src/config/config.ts +12 -0
  119. package/src/config/mesh-config.ts +264 -2
  120. package/src/config/recent-activity.ts +8 -2
  121. package/src/daemon/dev-cli-debug.ts +10 -1
  122. package/src/detection/ide-detector.ts +26 -16
  123. package/src/git/git-commands.ts +17 -5
  124. package/src/git/git-worktree.ts +8 -1
  125. package/src/index.ts +113 -5
  126. package/src/installer.d.ts +1 -1
  127. package/src/installer.ts +8 -6
  128. package/src/ipc/local-ipc-server.ts +278 -0
  129. package/src/launch.d.ts +1 -1
  130. package/src/launch.ts +37 -28
  131. package/src/logging/async-batch-writer.ts +55 -0
  132. package/src/logging/logger.ts +2 -1
  133. package/src/mesh/beads-db.ts +479 -0
  134. package/src/mesh/contracts.ts +329 -0
  135. package/src/mesh/coordinator-prompt.ts +204 -30
  136. package/src/mesh/coordinator-registry.ts +121 -0
  137. package/src/mesh/mesh-active-work.ts +437 -0
  138. package/src/mesh/mesh-events.ts +879 -61
  139. package/src/mesh/mesh-fast-forward.ts +430 -0
  140. package/src/mesh/mesh-host-ownership.ts +73 -0
  141. package/src/mesh/mesh-ledger.ts +457 -104
  142. package/src/mesh/mesh-refine-status.ts +144 -0
  143. package/src/mesh/mesh-work-queue.ts +216 -158
  144. package/src/mesh/preview-freshness.ts +118 -0
  145. package/src/mesh/refine-config.ts +366 -0
  146. package/src/mesh/worktree-bootstrap-config.ts +247 -0
  147. package/src/providers/approval-utils.d.ts +4 -0
  148. package/src/providers/approval-utils.ts +47 -5
  149. package/src/providers/chat-message-normalization.ts +4 -11
  150. package/src/providers/cli-provider-instance.ts +452 -54
  151. package/src/providers/contracts.ts +105 -5
  152. package/src/providers/external-sources.ts +218 -0
  153. package/src/providers/ide-provider-instance.ts +19 -5
  154. package/src/providers/native-history/antigravity-cli-transcript.ts +643 -0
  155. package/src/providers/native-history/claude-cli-transcript.ts +396 -0
  156. package/src/providers/native-history/codex-cli-transcript.ts +419 -0
  157. package/src/providers/native-history/dispatcher.ts +227 -0
  158. package/src/providers/native-history/hermes-cli-transcript.ts +230 -0
  159. package/src/providers/native-history/index.ts +30 -0
  160. package/src/providers/provider-instance.ts +3 -0
  161. package/src/providers/provider-loader.ts +585 -50
  162. package/src/providers/provider-schema.ts +31 -13
  163. package/src/providers/provider-trust.ts +114 -0
  164. package/src/providers/read-chat-contract.ts +76 -16
  165. package/src/providers/sdk/README.md +49 -0
  166. package/src/providers/sdk/v1/builders/acp/detect-status.ts +144 -0
  167. package/src/providers/sdk/v1/builders/cli/detect-status.ts +262 -0
  168. package/src/providers/sdk/v1/builders/cli/parse-approval-squash.ts +158 -0
  169. package/src/providers/sdk/v1/builders/cli/parse-approval.ts +250 -0
  170. package/src/providers/sdk/v1/builders/cli/parse-session.ts +276 -0
  171. package/src/providers/sdk/v1/builders/cli/visible-region.ts +143 -0
  172. package/src/providers/sdk/v1/fixture-tooling/format.ts +130 -0
  173. package/src/providers/sdk/v1/fixture-tooling/index.ts +22 -0
  174. package/src/providers/sdk/v1/fixture-tooling/replay.ts +352 -0
  175. package/src/providers/sdk/v1/index.ts +152 -0
  176. package/src/providers/sdk/v1/sandbox/README-design.ts +195 -0
  177. package/src/providers/sdk/v1/sandbox/require-whitelist.ts +472 -0
  178. package/src/providers/sdk/v1/sandbox/script-runner.ts +150 -0
  179. package/src/providers/sdk/v1/schemas/cli/provider.schema.json +458 -0
  180. package/src/providers/sdk/v1/schemas/primitives/acp-session-protocol-v1.json +131 -0
  181. package/src/providers/sdk/v1/schemas/primitives/native-history-codex-rollout-v1.json +66 -0
  182. package/src/providers/sdk/v1/schemas/primitives/tui-approval-squash-v1.json +91 -0
  183. package/src/providers/sdk/v1/schemas/primitives/tui-assistant-block-v1.json +91 -0
  184. package/src/providers/sdk/v1/schemas/primitives/tui-cue-ordering-v1.json +47 -0
  185. package/src/providers/sdk/v1/schemas/primitives/tui-dispatch-order-v1.json +32 -0
  186. package/src/providers/sdk/v1/schemas/primitives/tui-footer-chrome-v1.json +42 -0
  187. package/src/providers/sdk/v1/schemas/primitives/tui-index-finder-v1.json +27 -0
  188. package/src/providers/sdk/v1/schemas/primitives/tui-modal-v1.json +125 -0
  189. package/src/providers/sdk/v1/schemas/primitives/tui-prompt-marker-v1.json +45 -0
  190. package/src/providers/sdk/v1/schemas/primitives/tui-session-id-extraction-v1.json +46 -0
  191. package/src/providers/sdk/v1/schemas/primitives/tui-settled-prompt-v1.json +71 -0
  192. package/src/providers/sdk/v1/schemas/primitives/tui-spinner-v1.json +83 -0
  193. package/src/providers/sdk/v1/schemas/primitives/tui-transcript-pty-v1.json +83 -0
  194. package/src/providers/sdk/v1/schemas/primitives/tui-visible-region-v1.json +57 -0
  195. package/src/providers/sdk/v1/schemas/primitives/tui-welcome-screen-v1.json +35 -0
  196. package/src/providers/sdk/v1/types/cli/index.ts +365 -0
  197. package/src/providers/sdk/v1/types/common/index.ts +210 -0
  198. package/src/providers/sdk/v1/validators/index.ts +19 -0
  199. package/src/providers/sdk/v1/validators/manifest.ts +110 -0
  200. package/src/providers/sdk/v1/validators/taint.ts +309 -0
  201. package/src/providers/spec/adapter.ts +168 -0
  202. package/src/providers/spec/cli-adapter.ts +430 -0
  203. package/src/providers/spec/driver.ts +502 -0
  204. package/src/providers/spec/evaluator.ts +298 -0
  205. package/src/providers/spec/loader.ts +130 -0
  206. package/src/providers/spec/native-history-executor.ts +623 -0
  207. package/src/providers/spec/route.ts +51 -0
  208. package/src/providers/spec/schema.gen.ts +511 -0
  209. package/src/providers/spec/schema.json +211 -0
  210. package/src/providers/spec/types.ts +231 -0
  211. package/src/providers/transcript-v2.ts +567 -0
  212. package/src/providers/types/interactive-prompt.ts +297 -0
  213. package/src/providers/version-archive.ts +38 -20
  214. package/src/repo-mesh-types.ts +110 -1
  215. package/src/sessions/registry.ts +3 -0
  216. package/src/shared-types.ts +45 -1
  217. package/src/status/builders.ts +24 -6
  218. package/src/status/reporter.ts +15 -0
  219. package/src/status/snapshot.ts +84 -25
  220. package/src/system/host-memory.ts +29 -12
  221. package/src/types.ts +5 -0
@@ -0,0 +1,212 @@
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
+ }
10
+ export interface SectionRegex {
11
+ section?: string;
12
+ regex: string;
13
+ flags?: string;
14
+ }
15
+ export interface SectionPattern {
16
+ section?: string;
17
+ pattern: string;
18
+ flags?: string;
19
+ }
20
+ export interface ModalButtonsRule {
21
+ section?: string;
22
+ pattern: string;
23
+ flags?: string;
24
+ key_for_index: string;
25
+ min_count?: number;
26
+ continuation_lines?: boolean;
27
+ }
28
+ export interface SpecState {
29
+ id: string;
30
+ label: string;
31
+ when: SectionRegex;
32
+ extract_title?: SectionRegex;
33
+ modal_buttons?: ModalButtonsRule;
34
+ }
35
+ export type ControlAction = {
36
+ type: 'send_keys';
37
+ keys: string;
38
+ } | {
39
+ type: 'open_picker';
40
+ trigger_keys: string;
41
+ wait_for: SectionRegex;
42
+ extract_choices: SectionPattern;
43
+ submit_key: string;
44
+ } | {
45
+ type: 'attach_image';
46
+ method: 'tempfile_then_keys';
47
+ keys_template: string;
48
+ };
49
+ export interface Control {
50
+ id: string;
51
+ label: string;
52
+ visible_when_state?: string[];
53
+ action: ControlAction;
54
+ }
55
+ export interface NotificationRule {
56
+ id: string;
57
+ when_state: string;
58
+ title: string;
59
+ body?: string;
60
+ }
61
+ export interface DelegateTrigger {
62
+ id: string;
63
+ when_state: string;
64
+ after_duration_ms?: number;
65
+ task_template: string;
66
+ }
67
+ /**
68
+ * Native history config — three modes, picked by which fields are present:
69
+ *
70
+ * 1. `reader`: built-in reader id (claude-cli / codex-cli / antigravity-cli / hermes-cli).
71
+ * Backwards-compatible path used by the four shipped providers.
72
+ *
73
+ * 2. `source`: declarative source descriptor. The daemon's spec native-history
74
+ * executor reads the on-disk store (jsonl file / sqlite db) directly using
75
+ * paths + jsonpath maps from this block. New providers should prefer this
76
+ * mode — no daemon changes required.
77
+ *
78
+ * 3. `override_path`: relative path to a provider-supplied reader module
79
+ * (e.g. "./native_history/index.js"). Escape hatch for formats too
80
+ * exotic for the declarative executor. The module must default-export
81
+ * a function with the signature
82
+ * (input: NativeHistoryInput) => NativeHistoryResult | null
83
+ * and runs under provider-script-root sandboxing (same gate as
84
+ * scripts.js).
85
+ *
86
+ * The three modes are mutually exclusive — set exactly one. Loader rejects
87
+ * specs that set zero or more than one.
88
+ */
89
+ export interface NativeHistoryConfig {
90
+ reader?: 'claude-cli' | 'codex-cli' | 'antigravity-cli' | 'hermes-cli';
91
+ source?: NativeHistorySource;
92
+ override_path?: string;
93
+ }
94
+ export type NativeHistorySource = NativeHistoryJsonlSource | NativeHistorySqliteSource;
95
+ /**
96
+ * JSONL source — each line in the resolved file is one record.
97
+ *
98
+ * `path` accepts ~/, environment variables (${HOME}), and a small set of
99
+ * runtime variables:
100
+ * {cwd} — the session's working directory, raw
101
+ * {cwd_dashed} — cwd with `/` replaced by `-` (claude's per-project key)
102
+ * {session_id} — providerSessionId, when known
103
+ * {yyyy} {mm} {dd} — UTC date components
104
+ *
105
+ * When `path` resolves to a directory, the daemon picks the newest file
106
+ * matching `file_pattern` whose mtime is inside `recent_window_ms` (default
107
+ * 5min) — prevents the wrong session's transcript from leaking through.
108
+ */
109
+ export interface NativeHistoryJsonlSource {
110
+ kind: 'jsonl';
111
+ path: string;
112
+ file_pattern?: string;
113
+ recent_window_ms?: number;
114
+ session_id_from?: 'filename_uuid' | 'first_record';
115
+ session_id_path?: string;
116
+ message_filter?: {
117
+ where: string;
118
+ };
119
+ message_map: NativeHistoryMessageMap;
120
+ }
121
+ /**
122
+ * SQLite source — provider runs two queries on a read-only handle: one to
123
+ * pick the session row (`session_query` — first row's first column is the
124
+ * sessionId), then one to fetch messages (`message_query` — `?` is bound
125
+ * to the sessionId). Output rows are projected through `message_map`.
126
+ */
127
+ export interface NativeHistorySqliteSource {
128
+ kind: 'sqlite';
129
+ path: string;
130
+ session_query: string;
131
+ message_query: string;
132
+ message_map: NativeHistoryMessageMap;
133
+ }
134
+ /**
135
+ * Maps a source record (jsonl line object / sqlite row) to a daemon
136
+ * native-history message. Values are jsonpath-lite strings: `$.foo.bar`
137
+ * or `$.items[0].text`. Literal strings (no leading `$`) pass through.
138
+ *
139
+ * `content_strip` lets a spec drop wrapper tags that the agent injects
140
+ * into its own transcript (claude's `<local-command-caveat>`, agy's
141
+ * `<USER_REQUEST>` / `<ADDITIONAL_METADATA>` / `<USER_SETTINGS_CHANGE>`).
142
+ * Each entry is a tag name; the executor removes `<tag>…</tag>` segments
143
+ * non-greedily before the value is handed to the dashboard. After all
144
+ * strips, leading/trailing whitespace is trimmed. If the result is empty
145
+ * the message is dropped.
146
+ */
147
+ export interface NativeHistoryMessageMap {
148
+ role: string;
149
+ content: string;
150
+ /**
151
+ * Tags whose entire `<tag>…</tag>` segment is removed from content.
152
+ * Use for noise wrappers the agent ships alongside the real message
153
+ * (claude's `<local-command-caveat>`, agy's `<ADDITIONAL_METADATA>`).
154
+ */
155
+ content_strip?: string[];
156
+ /**
157
+ * Tags whose open/close markers are removed but inner content is kept.
158
+ * Use when the *real* user/assistant message is wrapped in a tag
159
+ * the agent uses for routing (agy wraps user input in `<USER_REQUEST>`).
160
+ */
161
+ content_unwrap?: string[];
162
+ timestamp_ms?: string;
163
+ kind?: string;
164
+ }
165
+ export interface CliSpec {
166
+ $schema: 'adhdev:cli/spec@1';
167
+ id: string;
168
+ name: string;
169
+ binary: string;
170
+ spawn_args?: string[];
171
+ env?: Record<string, string>;
172
+ /**
173
+ * Optional version constraint this spec is authored for, e.g. ">=2.1.0".
174
+ * Pure metadata used by tooling/UI — the actual version-to-spec match
175
+ * happens in provider-loader via the manifest's compatibility array.
176
+ * Spec authors include this so a misrouted spec is easy to spot.
177
+ */
178
+ cli_version_range?: string;
179
+ send_message: {
180
+ submit_key: string;
181
+ delay_ms_before_submit?: number;
182
+ delay_ms_per_char?: number;
183
+ };
184
+ layout: {
185
+ sections: Section[];
186
+ };
187
+ states: SpecState[];
188
+ default_state: string;
189
+ control_bar?: Control[];
190
+ notifications?: NotificationRule[];
191
+ delegate?: DelegateTrigger[];
192
+ native_history?: NativeHistoryConfig;
193
+ /**
194
+ * Per-spec debounce knobs. Defaults are conservative (busy_hold_ms
195
+ * 6000) and live in SpecDriver. Spec authors override here when a
196
+ * particular CLI flickers slower/faster than the default.
197
+ */
198
+ debounce?: {
199
+ /** Min time to stay in busy after the evaluator last reported it.
200
+ * Absorbs per-frame flicker in TUIs that stream output through
201
+ * the same region as the spinner. */
202
+ busy_hold_ms?: number;
203
+ /** Min time after start() before a send_message is allowed to
204
+ * reach the PTY. Banner paints + auth flows + skill listings
205
+ * can keep the agent unable to accept input for several seconds
206
+ * even though the idle regex matches a transient empty prompt.
207
+ * Send_messages issued before this window are queued and drained
208
+ * once the window passes and an idle state has actually been
209
+ * observed. */
210
+ startup_grace_ms?: number;
211
+ };
212
+ }
@@ -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;
@@ -19,10 +19,37 @@ export interface RepoMesh {
19
19
  defaultBranch?: string;
20
20
  policy: RepoMeshPolicy;
21
21
  coordinator: RepoMeshCoordinatorConfig;
22
+ meshHost?: RepoMeshHostMetadata;
22
23
  projectContext: ProjectContextSnapshot;
23
24
  nodes: RepoMeshNode[];
24
25
  status: 'active' | 'archived' | 'deleted';
25
26
  }
27
+ export type RepoMeshDaemonRole = 'host' | 'member';
28
+ export interface RepoMeshHostPairingMetadata {
29
+ status: 'not_configured' | 'pairing' | 'paired' | 'rejected' | 'revoked';
30
+ tokenId?: string;
31
+ joinedAt?: string;
32
+ lastPairedAt?: string;
33
+ lastRejectedAt?: string;
34
+ expiresAt?: string;
35
+ }
36
+ export interface RepoMeshHostMetadata {
37
+ /** Local daemon role for this mesh. Missing metadata defaults to host for standalone compatibility. */
38
+ role: RepoMeshDaemonRole;
39
+ /** Daemon that owns mesh truth/status/git/queue/session/ledger/coordinator ownership. */
40
+ hostDaemonId?: string;
41
+ /** Mesh node that represents the host daemon, when known. */
42
+ hostNodeId?: string;
43
+ /** Future standalone manual pairing endpoint entered by member daemons. */
44
+ hostAddress?: string;
45
+ /** Redacted pairing state only; raw join tokens must not be persisted here. */
46
+ pairing?: RepoMeshHostPairingMetadata;
47
+ }
48
+ export interface RepoMeshHostStatus extends RepoMeshHostMetadata {
49
+ canOwnCoordinator: boolean;
50
+ canOwnQueue: boolean;
51
+ defaulted: boolean;
52
+ }
26
53
  export interface RepoMeshNode {
27
54
  id: string;
28
55
  daemonId: string;
@@ -37,6 +64,7 @@ export interface RepoMeshNode {
37
64
  effectiveCapabilities: RepoMeshNodeCapabilities;
38
65
  policy: RepoMeshNodePolicy;
39
66
  health: RepoMeshNodeHealth;
67
+ role?: RepoMeshDaemonRole;
40
68
  status: 'enabled' | 'disabled' | 'removed';
41
69
  }
42
70
  export type RepoMeshNodeHealth = 'online' | 'offline' | 'degraded' | 'dirty' | 'wrong_branch' | 'unknown';
@@ -46,6 +74,13 @@ export interface RepoMeshPolicy {
46
74
  requirePreTaskCheckpoint: boolean;
47
75
  requirePostTaskCheckpoint: boolean;
48
76
  requireApprovalForPush: boolean;
77
+ /**
78
+ * Narrow Refinery opt-in: when validation and patch-equivalence have passed,
79
+ * allow Refinery to publish submodule gitlink commits to each submodule's
80
+ * configured remote main branch with a non-force push, then verify reachability.
81
+ * Defaults to false; root branch pushes/merges are not affected.
82
+ */
83
+ allowAutoPublishSubmoduleMainCommits?: boolean;
49
84
  requireApprovalForDestructiveGit: boolean;
50
85
  dirtyWorkspaceBehavior: 'block' | 'warn' | 'checkpoint_then_continue';
51
86
  maxParallelTasks: number;
@@ -167,7 +202,28 @@ export interface RepoMeshCoordinatorConfig {
167
202
  providerType?: string;
168
203
  /** Preferred node to run coordinator on (null = auto) */
169
204
  preferredNodeId?: string;
170
- /** Additional system prompt context for coordinator */
205
+ /**
206
+ * Full mesh-level override for the coordinator system prompt. When set,
207
+ * replaces the daemon's rendered default and any user-file override
208
+ * (~/.adhdev/coordinator-prompts/<cli>.md). The per-launch
209
+ * extraSystemPrompt still composes on top — it always lands last as
210
+ * Additional Context. Supports the same {{placeholders}} the daemon's
211
+ * default template uses ({{meshName}}, {{repo}}, {{nodes}}, …).
212
+ */
213
+ systemPromptOverride?: string;
214
+ /**
215
+ * Mesh-level append. Composes after whichever base prompt won
216
+ * (override → user-file override → daemon default). Use this when you
217
+ * want extra rules for THIS mesh but otherwise the standard prompt is
218
+ * fine. Stacks with the user-file append (`<cli>.append.md`) — both
219
+ * apply if both are set.
220
+ */
221
+ systemPromptAppend?: string;
222
+ /**
223
+ * @deprecated Use systemPromptAppend. Kept as a fallback alias so
224
+ * existing meshes.json files keep working without a migration step;
225
+ * the daemon prefers systemPromptAppend when both are present.
226
+ */
171
227
  systemPromptSuffix?: string;
172
228
  }
173
229
  /**
@@ -185,6 +241,7 @@ export interface LocalMeshEntry {
185
241
  defaultBranch?: string;
186
242
  policy: RepoMeshPolicy;
187
243
  coordinator: RepoMeshCoordinatorConfig;
244
+ meshHost?: RepoMeshHostMetadata;
188
245
  nodes: LocalMeshNodeEntry[];
189
246
  createdAt: string;
190
247
  updatedAt: string;
@@ -198,14 +255,38 @@ export interface LocalMeshNodeEntry {
198
255
  machineId?: string;
199
256
  userOverrides: Partial<RepoMeshNodeCapabilities>;
200
257
  policy: RepoMeshNodePolicy;
258
+ /**
259
+ * Per-node instruction surfaced in the coordinator prompt so the LLM
260
+ * knows what each node is for (e.g. "this is the staging mirror — run
261
+ * only smoke tests here", or "use opus on this node, sonnet elsewhere").
262
+ * Empty/missing: omitted silently from the rendered prompt, no rule
263
+ * line about it gets added. The coordinator forwards/honors it when
264
+ * delegating; we don't enforce it at the daemon level.
265
+ */
266
+ systemPrompt?: string;
201
267
  /** For single-machine mesh: same daemon, different worktree */
202
268
  isLocalWorktree?: boolean;
203
269
  /** Branch this worktree tracks (set when created via clone_mesh_node) */
204
270
  worktreeBranch?: string;
205
271
  /** Node ID this worktree was cloned from */
206
272
  clonedFromNodeId?: string;
273
+ /** Repo-local preparation result for ADHDev-created worktree nodes. */
274
+ worktreeBootstrap?: {
275
+ status: 'ready' | 'running' | 'failed' | 'not_configured' | 'disabled' | 'stale';
276
+ required?: boolean;
277
+ configSource?: string;
278
+ configSourceType?: string;
279
+ startedAt?: string;
280
+ completedAt?: string;
281
+ lastCommand?: string;
282
+ exitCode?: number | null;
283
+ error?: string;
284
+ commandsRun?: Array<Record<string, unknown>>;
285
+ staleInputs?: string[];
286
+ };
207
287
  /** Optional associated/external repos configured as node metadata. */
208
288
  relatedRepos?: RepoMeshRelatedRepo[];
289
+ role?: RepoMeshDaemonRole;
209
290
  }
210
291
  export interface RepoMeshStatus {
211
292
  meshId: string;
@@ -213,6 +294,7 @@ export interface RepoMeshStatus {
213
294
  repoIdentity: string;
214
295
  defaultBranch?: string;
215
296
  refreshedAt: string;
297
+ meshHost?: RepoMeshHostStatus;
216
298
  nodes: RepoMeshNodeStatus[];
217
299
  queue?: RepoMeshQueueStatus;
218
300
  ledger?: RepoMeshLedgerStatus;
@@ -249,16 +331,28 @@ export interface RepoMeshNodeStatus {
249
331
  repoRoot?: string;
250
332
  daemonId?: string;
251
333
  machineId?: string;
334
+ role?: RepoMeshDaemonRole;
252
335
  machineStatus?: string;
253
336
  isLocalWorktree?: boolean;
254
337
  worktreeBranch?: string;
338
+ /** Mirrored from LocalMeshNodeEntry.systemPrompt for coordinator-prompt rendering. */
339
+ systemPrompt?: string;
255
340
  health: RepoMeshNodeHealth;
256
341
  git?: GitRepoStatus;
342
+ /**
343
+ * True when the selected coordinator has evidence that a peer git probe is still
344
+ * in flight or just timed out during initial mesh handshake, so callers should
345
+ * treat missing git data as pending instead of authoritative absence.
346
+ */
347
+ gitProbePending?: boolean;
257
348
  providers: string[];
258
349
  activeSessions: string[];
259
350
  activeSessionDetails?: RepoMeshSessionStatus[];
260
351
  providerPriority?: string[];
261
352
  launchReady?: boolean;
353
+ worktreeBootstrap?: LocalMeshNodeEntry['worktreeBootstrap'];
354
+ launchBlockedReason?: string;
355
+ launchBlockedMessage?: string;
262
356
  lastSeenAt?: string;
263
357
  updatedAt?: string;
264
358
  connection?: RepoMeshPeerConnectionStatus;
@@ -346,3 +440,8 @@ export interface RepoMeshLedgerStatus {
346
440
  entries: RepoMeshLedgerEntryStatus[];
347
441
  summary: RepoMeshLedgerSummaryStatus;
348
442
  }
443
+ export interface MeshAsyncJobLifecycle {
444
+ startedAt?: string;
445
+ completedAt?: string;
446
+ error?: string;
447
+ }
@@ -7,6 +7,9 @@ export interface SessionRuntimeTarget {
7
7
  cdpManagerKey?: string;
8
8
  adapterKey?: string;
9
9
  instanceKey?: string;
10
+ /** Wall clock at register time. native-history readers use it as a
11
+ * cutoff so a fresh session can't show records from a prior one. */
12
+ spawnedAtMs?: number;
10
13
  }
11
14
  export declare class SessionRegistry {
12
15
  private readonly bySessionId;