@adhdev/daemon-core 0.9.82-rc.16 → 0.9.82-rc.161

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 (209) 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 +19 -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 +104 -63
  9. package/dist/cli-adapters/provider-cli-parse.d.ts +4 -0
  10. package/dist/cli-adapters/provider-cli-shared.d.ts +27 -0
  11. package/dist/commands/handler.d.ts +66 -0
  12. package/dist/commands/mesh-coordinator.d.ts +72 -1
  13. package/dist/commands/router.d.ts +22 -0
  14. package/dist/config/chat-history.d.ts +7 -0
  15. package/dist/config/config.d.ts +5 -0
  16. package/dist/config/mesh-config.d.ts +71 -1
  17. package/dist/git/git-commands.d.ts +5 -1
  18. package/dist/index.d.ts +31 -6
  19. package/dist/index.js +17210 -3575
  20. package/dist/index.js.map +1 -1
  21. package/dist/index.mjs +17127 -3551
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/installer.d.ts +1 -4
  24. package/dist/ipc/local-ipc-server.d.ts +91 -0
  25. package/dist/launch.d.ts +1 -1
  26. package/dist/logging/async-batch-writer.d.ts +10 -0
  27. package/dist/mesh/beads-db.d.ts +72 -0
  28. package/dist/mesh/contracts.d.ts +164 -0
  29. package/dist/mesh/coordinator-prompt.d.ts +30 -0
  30. package/dist/mesh/coordinator-registry.d.ts +59 -0
  31. package/dist/mesh/mesh-active-work.d.ts +90 -0
  32. package/dist/mesh/mesh-events.d.ts +77 -5
  33. package/dist/mesh/mesh-fast-forward.d.ts +39 -0
  34. package/dist/mesh/mesh-host-ownership.d.ts +9 -0
  35. package/dist/mesh/mesh-ledger.d.ts +58 -1
  36. package/dist/mesh/mesh-refine-status.d.ts +26 -0
  37. package/dist/mesh/mesh-work-queue.d.ts +44 -5
  38. package/dist/mesh/preview-freshness.d.ts +18 -0
  39. package/dist/mesh/refine-config.d.ts +193 -0
  40. package/dist/mesh/worktree-bootstrap-config.d.ts +113 -0
  41. package/dist/providers/approval-utils.d.ts +9 -0
  42. package/dist/providers/cli-provider-instance.d.ts +7 -2
  43. package/dist/providers/contracts.d.ts +98 -5
  44. package/dist/providers/native-history/antigravity-cli-transcript.d.ts +100 -0
  45. package/dist/providers/native-history/claude-cli-transcript.d.ts +70 -0
  46. package/dist/providers/native-history/codex-cli-transcript.d.ts +73 -0
  47. package/dist/providers/native-history/dispatcher.d.ts +24 -0
  48. package/dist/providers/native-history/hermes-cli-transcript.d.ts +30 -0
  49. package/dist/providers/native-history/index.d.ts +13 -0
  50. package/dist/providers/provider-loader.d.ts +19 -1
  51. package/dist/providers/read-chat-contract.d.ts +29 -0
  52. package/dist/providers/sdk/v1/builders/acp/detect-status.d.ts +68 -0
  53. package/dist/providers/sdk/v1/builders/cli/detect-status.d.ts +85 -0
  54. package/dist/providers/sdk/v1/builders/cli/parse-approval-squash.d.ts +59 -0
  55. package/dist/providers/sdk/v1/builders/cli/parse-approval.d.ts +64 -0
  56. package/dist/providers/sdk/v1/builders/cli/parse-session.d.ts +91 -0
  57. package/dist/providers/sdk/v1/builders/cli/visible-region.d.ts +42 -0
  58. package/dist/providers/sdk/v1/fixture-tooling/format.d.ts +126 -0
  59. package/dist/providers/sdk/v1/fixture-tooling/index.d.ts +8 -0
  60. package/dist/providers/sdk/v1/fixture-tooling/replay.d.ts +38 -0
  61. package/dist/providers/sdk/v1/index.d.ts +30 -0
  62. package/dist/providers/sdk/v1/sandbox/README-design.d.ts +193 -0
  63. package/dist/providers/sdk/v1/sandbox/require-whitelist.d.ts +74 -0
  64. package/dist/providers/sdk/v1/sandbox/script-runner.d.ts +98 -0
  65. package/dist/providers/sdk/v1/types/cli/index.d.ts +277 -0
  66. package/dist/providers/sdk/v1/types/common/index.d.ts +169 -0
  67. package/dist/providers/sdk/v1/validators/index.d.ts +5 -0
  68. package/dist/providers/sdk/v1/validators/manifest.d.ts +40 -0
  69. package/dist/providers/sdk/v1/validators/taint.d.ts +52 -0
  70. package/dist/providers/spec/adapter.d.ts +56 -0
  71. package/dist/providers/spec/cli-adapter.d.ts +76 -0
  72. package/dist/providers/spec/driver.d.ts +148 -0
  73. package/dist/providers/spec/evaluator.d.ts +47 -0
  74. package/dist/providers/spec/loader.d.ts +14 -0
  75. package/dist/providers/spec/native-history-executor.d.ts +39 -0
  76. package/dist/providers/spec/route.d.ts +4 -0
  77. package/dist/providers/spec/schema.gen.d.ts +507 -0
  78. package/dist/providers/spec/types.d.ts +211 -0
  79. package/dist/providers/transcript-v2.d.ts +176 -0
  80. package/dist/repo-mesh-types.d.ts +100 -1
  81. package/dist/sessions/registry.d.ts +3 -0
  82. package/dist/shared-types.d.ts +12 -0
  83. package/dist/status/reporter.d.ts +2 -0
  84. package/dist/status/snapshot.d.ts +1 -0
  85. package/dist/types.d.ts +5 -0
  86. package/package.json +7 -2
  87. package/src/boot/daemon-lifecycle.ts +17 -10
  88. package/src/boot/process-hardening.ts +89 -0
  89. package/src/chat/source-machine.ts +534 -0
  90. package/src/chat/source-resolver.ts +0 -0
  91. package/src/chat/subscription-updates.ts +14 -1
  92. package/src/cli-adapter-types.d.ts +1 -0
  93. package/src/cli-adapter-types.ts +18 -2
  94. package/src/cli-adapters/cli-script-runner.ts +421 -0
  95. package/src/cli-adapters/cli-state-engine.ts +1086 -0
  96. package/src/cli-adapters/provider-cli-adapter.d.ts +1 -1
  97. package/src/cli-adapters/provider-cli-adapter.ts +664 -1137
  98. package/src/cli-adapters/provider-cli-parse.d.ts +1 -0
  99. package/src/cli-adapters/provider-cli-parse.ts +13 -0
  100. package/src/cli-adapters/provider-cli-runtime.ts +3 -1
  101. package/src/cli-adapters/provider-cli-shared.d.ts +2 -0
  102. package/src/cli-adapters/provider-cli-shared.ts +57 -11
  103. package/src/cli-adapters/terminal-backends/ghostty-vt-backend.ts +17 -1
  104. package/src/cli-adapters/terminal-backends/xterm-backend.ts +8 -1
  105. package/src/commands/chat-commands.ts +1597 -60
  106. package/src/commands/cli-manager.ts +195 -3
  107. package/src/commands/handler.ts +547 -2
  108. package/src/commands/mesh-coordinator.ts +231 -127
  109. package/src/commands/router.ts +3547 -502
  110. package/src/config/chat-history.ts +87 -24
  111. package/src/config/config.ts +12 -0
  112. package/src/config/mesh-config.ts +264 -2
  113. package/src/config/recent-activity.ts +8 -2
  114. package/src/daemon/dev-cli-debug.ts +10 -1
  115. package/src/detection/ide-detector.ts +26 -16
  116. package/src/git/git-commands.ts +17 -5
  117. package/src/git/git-worktree.ts +8 -1
  118. package/src/index.ts +91 -5
  119. package/src/installer.d.ts +1 -1
  120. package/src/installer.ts +8 -6
  121. package/src/ipc/local-ipc-server.ts +278 -0
  122. package/src/launch.d.ts +1 -1
  123. package/src/launch.ts +37 -28
  124. package/src/logging/async-batch-writer.ts +55 -0
  125. package/src/logging/logger.ts +2 -1
  126. package/src/mesh/beads-db.ts +479 -0
  127. package/src/mesh/contracts.ts +329 -0
  128. package/src/mesh/coordinator-prompt.ts +204 -30
  129. package/src/mesh/coordinator-registry.ts +121 -0
  130. package/src/mesh/mesh-active-work.ts +437 -0
  131. package/src/mesh/mesh-events.ts +820 -61
  132. package/src/mesh/mesh-fast-forward.ts +430 -0
  133. package/src/mesh/mesh-host-ownership.ts +73 -0
  134. package/src/mesh/mesh-ledger.ts +457 -104
  135. package/src/mesh/mesh-refine-status.ts +144 -0
  136. package/src/mesh/mesh-work-queue.ts +216 -158
  137. package/src/mesh/preview-freshness.ts +118 -0
  138. package/src/mesh/refine-config.ts +366 -0
  139. package/src/mesh/worktree-bootstrap-config.ts +247 -0
  140. package/src/providers/approval-utils.ts +39 -5
  141. package/src/providers/chat-message-normalization.ts +4 -11
  142. package/src/providers/cli-provider-instance.ts +388 -47
  143. package/src/providers/contracts.ts +105 -5
  144. package/src/providers/ide-provider-instance.ts +17 -3
  145. package/src/providers/native-history/antigravity-cli-transcript.ts +643 -0
  146. package/src/providers/native-history/claude-cli-transcript.ts +396 -0
  147. package/src/providers/native-history/codex-cli-transcript.ts +419 -0
  148. package/src/providers/native-history/dispatcher.ts +227 -0
  149. package/src/providers/native-history/hermes-cli-transcript.ts +230 -0
  150. package/src/providers/native-history/index.ts +30 -0
  151. package/src/providers/provider-loader.ts +420 -31
  152. package/src/providers/provider-schema.ts +31 -13
  153. package/src/providers/read-chat-contract.ts +76 -16
  154. package/src/providers/sdk/README.md +49 -0
  155. package/src/providers/sdk/v1/builders/acp/detect-status.ts +144 -0
  156. package/src/providers/sdk/v1/builders/cli/detect-status.ts +262 -0
  157. package/src/providers/sdk/v1/builders/cli/parse-approval-squash.ts +158 -0
  158. package/src/providers/sdk/v1/builders/cli/parse-approval.ts +245 -0
  159. package/src/providers/sdk/v1/builders/cli/parse-session.ts +276 -0
  160. package/src/providers/sdk/v1/builders/cli/visible-region.ts +143 -0
  161. package/src/providers/sdk/v1/fixture-tooling/format.ts +130 -0
  162. package/src/providers/sdk/v1/fixture-tooling/index.ts +22 -0
  163. package/src/providers/sdk/v1/fixture-tooling/replay.ts +352 -0
  164. package/src/providers/sdk/v1/index.ts +152 -0
  165. package/src/providers/sdk/v1/sandbox/README-design.ts +195 -0
  166. package/src/providers/sdk/v1/sandbox/require-whitelist.ts +472 -0
  167. package/src/providers/sdk/v1/sandbox/script-runner.ts +150 -0
  168. package/src/providers/sdk/v1/schemas/cli/provider.schema.json +457 -0
  169. package/src/providers/sdk/v1/schemas/primitives/acp-session-protocol-v1.json +131 -0
  170. package/src/providers/sdk/v1/schemas/primitives/native-history-codex-rollout-v1.json +66 -0
  171. package/src/providers/sdk/v1/schemas/primitives/tui-approval-squash-v1.json +91 -0
  172. package/src/providers/sdk/v1/schemas/primitives/tui-assistant-block-v1.json +91 -0
  173. package/src/providers/sdk/v1/schemas/primitives/tui-cue-ordering-v1.json +47 -0
  174. package/src/providers/sdk/v1/schemas/primitives/tui-dispatch-order-v1.json +32 -0
  175. package/src/providers/sdk/v1/schemas/primitives/tui-footer-chrome-v1.json +42 -0
  176. package/src/providers/sdk/v1/schemas/primitives/tui-index-finder-v1.json +27 -0
  177. package/src/providers/sdk/v1/schemas/primitives/tui-modal-v1.json +119 -0
  178. package/src/providers/sdk/v1/schemas/primitives/tui-prompt-marker-v1.json +45 -0
  179. package/src/providers/sdk/v1/schemas/primitives/tui-session-id-extraction-v1.json +46 -0
  180. package/src/providers/sdk/v1/schemas/primitives/tui-settled-prompt-v1.json +71 -0
  181. package/src/providers/sdk/v1/schemas/primitives/tui-spinner-v1.json +83 -0
  182. package/src/providers/sdk/v1/schemas/primitives/tui-transcript-pty-v1.json +83 -0
  183. package/src/providers/sdk/v1/schemas/primitives/tui-visible-region-v1.json +57 -0
  184. package/src/providers/sdk/v1/schemas/primitives/tui-welcome-screen-v1.json +35 -0
  185. package/src/providers/sdk/v1/types/cli/index.ts +365 -0
  186. package/src/providers/sdk/v1/types/common/index.ts +210 -0
  187. package/src/providers/sdk/v1/validators/index.ts +19 -0
  188. package/src/providers/sdk/v1/validators/manifest.ts +110 -0
  189. package/src/providers/sdk/v1/validators/taint.ts +309 -0
  190. package/src/providers/spec/adapter.ts +153 -0
  191. package/src/providers/spec/cli-adapter.ts +318 -0
  192. package/src/providers/spec/driver.ts +498 -0
  193. package/src/providers/spec/evaluator.ts +268 -0
  194. package/src/providers/spec/loader.ts +130 -0
  195. package/src/providers/spec/native-history-executor.ts +612 -0
  196. package/src/providers/spec/route.ts +51 -0
  197. package/src/providers/spec/schema.gen.ts +507 -0
  198. package/src/providers/spec/schema.json +210 -0
  199. package/src/providers/spec/types.ts +230 -0
  200. package/src/providers/transcript-v2.ts +567 -0
  201. package/src/providers/version-archive.ts +38 -20
  202. package/src/repo-mesh-types.ts +110 -1
  203. package/src/sessions/registry.ts +3 -0
  204. package/src/shared-types.ts +9 -0
  205. package/src/status/builders.ts +23 -6
  206. package/src/status/reporter.ts +15 -0
  207. package/src/status/snapshot.ts +35 -11
  208. package/src/system/host-memory.ts +29 -12
  209. package/src/types.ts +5 -0
@@ -0,0 +1,211 @@
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
+ }
27
+ export interface SpecState {
28
+ id: string;
29
+ label: string;
30
+ when: SectionRegex;
31
+ extract_title?: SectionRegex;
32
+ modal_buttons?: ModalButtonsRule;
33
+ }
34
+ export type ControlAction = {
35
+ type: 'send_keys';
36
+ keys: string;
37
+ } | {
38
+ type: 'open_picker';
39
+ trigger_keys: string;
40
+ wait_for: SectionRegex;
41
+ extract_choices: SectionPattern;
42
+ submit_key: string;
43
+ } | {
44
+ type: 'attach_image';
45
+ method: 'tempfile_then_keys';
46
+ keys_template: string;
47
+ };
48
+ export interface Control {
49
+ id: string;
50
+ label: string;
51
+ visible_when_state?: string[];
52
+ action: ControlAction;
53
+ }
54
+ export interface NotificationRule {
55
+ id: string;
56
+ when_state: string;
57
+ title: string;
58
+ body?: string;
59
+ }
60
+ export interface DelegateTrigger {
61
+ id: string;
62
+ when_state: string;
63
+ after_duration_ms?: number;
64
+ task_template: string;
65
+ }
66
+ /**
67
+ * Native history config — three modes, picked by which fields are present:
68
+ *
69
+ * 1. `reader`: built-in reader id (claude-cli / codex-cli / antigravity-cli / hermes-cli).
70
+ * Backwards-compatible path used by the four shipped providers.
71
+ *
72
+ * 2. `source`: declarative source descriptor. The daemon's spec native-history
73
+ * executor reads the on-disk store (jsonl file / sqlite db) directly using
74
+ * paths + jsonpath maps from this block. New providers should prefer this
75
+ * mode — no daemon changes required.
76
+ *
77
+ * 3. `override_path`: relative path to a provider-supplied reader module
78
+ * (e.g. "./native_history/index.js"). Escape hatch for formats too
79
+ * exotic for the declarative executor. The module must default-export
80
+ * a function with the signature
81
+ * (input: NativeHistoryInput) => NativeHistoryResult | null
82
+ * and runs under provider-script-root sandboxing (same gate as
83
+ * scripts.js).
84
+ *
85
+ * The three modes are mutually exclusive — set exactly one. Loader rejects
86
+ * specs that set zero or more than one.
87
+ */
88
+ export interface NativeHistoryConfig {
89
+ reader?: 'claude-cli' | 'codex-cli' | 'antigravity-cli' | 'hermes-cli';
90
+ source?: NativeHistorySource;
91
+ override_path?: string;
92
+ }
93
+ export type NativeHistorySource = NativeHistoryJsonlSource | NativeHistorySqliteSource;
94
+ /**
95
+ * JSONL source — each line in the resolved file is one record.
96
+ *
97
+ * `path` accepts ~/, environment variables (${HOME}), and a small set of
98
+ * runtime variables:
99
+ * {cwd} — the session's working directory, raw
100
+ * {cwd_dashed} — cwd with `/` replaced by `-` (claude's per-project key)
101
+ * {session_id} — providerSessionId, when known
102
+ * {yyyy} {mm} {dd} — UTC date components
103
+ *
104
+ * When `path` resolves to a directory, the daemon picks the newest file
105
+ * matching `file_pattern` whose mtime is inside `recent_window_ms` (default
106
+ * 5min) — prevents the wrong session's transcript from leaking through.
107
+ */
108
+ export interface NativeHistoryJsonlSource {
109
+ kind: 'jsonl';
110
+ path: string;
111
+ file_pattern?: string;
112
+ recent_window_ms?: number;
113
+ session_id_from?: 'filename_uuid' | 'first_record';
114
+ session_id_path?: string;
115
+ message_filter?: {
116
+ where: string;
117
+ };
118
+ message_map: NativeHistoryMessageMap;
119
+ }
120
+ /**
121
+ * SQLite source — provider runs two queries on a read-only handle: one to
122
+ * pick the session row (`session_query` — first row's first column is the
123
+ * sessionId), then one to fetch messages (`message_query` — `?` is bound
124
+ * to the sessionId). Output rows are projected through `message_map`.
125
+ */
126
+ export interface NativeHistorySqliteSource {
127
+ kind: 'sqlite';
128
+ path: string;
129
+ session_query: string;
130
+ message_query: string;
131
+ message_map: NativeHistoryMessageMap;
132
+ }
133
+ /**
134
+ * Maps a source record (jsonl line object / sqlite row) to a daemon
135
+ * native-history message. Values are jsonpath-lite strings: `$.foo.bar`
136
+ * or `$.items[0].text`. Literal strings (no leading `$`) pass through.
137
+ *
138
+ * `content_strip` lets a spec drop wrapper tags that the agent injects
139
+ * into its own transcript (claude's `<local-command-caveat>`, agy's
140
+ * `<USER_REQUEST>` / `<ADDITIONAL_METADATA>` / `<USER_SETTINGS_CHANGE>`).
141
+ * Each entry is a tag name; the executor removes `<tag>…</tag>` segments
142
+ * non-greedily before the value is handed to the dashboard. After all
143
+ * strips, leading/trailing whitespace is trimmed. If the result is empty
144
+ * the message is dropped.
145
+ */
146
+ export interface NativeHistoryMessageMap {
147
+ role: string;
148
+ content: string;
149
+ /**
150
+ * Tags whose entire `<tag>…</tag>` segment is removed from content.
151
+ * Use for noise wrappers the agent ships alongside the real message
152
+ * (claude's `<local-command-caveat>`, agy's `<ADDITIONAL_METADATA>`).
153
+ */
154
+ content_strip?: string[];
155
+ /**
156
+ * Tags whose open/close markers are removed but inner content is kept.
157
+ * Use when the *real* user/assistant message is wrapped in a tag
158
+ * the agent uses for routing (agy wraps user input in `<USER_REQUEST>`).
159
+ */
160
+ content_unwrap?: string[];
161
+ timestamp_ms?: string;
162
+ kind?: string;
163
+ }
164
+ export interface CliSpec {
165
+ $schema: 'adhdev:cli/spec@1';
166
+ id: string;
167
+ name: string;
168
+ binary: string;
169
+ spawn_args?: string[];
170
+ env?: Record<string, string>;
171
+ /**
172
+ * Optional version constraint this spec is authored for, e.g. ">=2.1.0".
173
+ * Pure metadata used by tooling/UI — the actual version-to-spec match
174
+ * happens in provider-loader via the manifest's compatibility array.
175
+ * Spec authors include this so a misrouted spec is easy to spot.
176
+ */
177
+ cli_version_range?: string;
178
+ send_message: {
179
+ submit_key: string;
180
+ delay_ms_before_submit?: number;
181
+ delay_ms_per_char?: number;
182
+ };
183
+ layout: {
184
+ sections: Section[];
185
+ };
186
+ states: SpecState[];
187
+ default_state: string;
188
+ control_bar?: Control[];
189
+ notifications?: NotificationRule[];
190
+ delegate?: DelegateTrigger[];
191
+ native_history?: NativeHistoryConfig;
192
+ /**
193
+ * Per-spec debounce knobs. Defaults are conservative (busy_hold_ms
194
+ * 6000) and live in SpecDriver. Spec authors override here when a
195
+ * particular CLI flickers slower/faster than the default.
196
+ */
197
+ debounce?: {
198
+ /** Min time to stay in busy after the evaluator last reported it.
199
+ * Absorbs per-frame flicker in TUIs that stream output through
200
+ * the same region as the spinner. */
201
+ busy_hold_ms?: number;
202
+ /** Min time after start() before a send_message is allowed to
203
+ * reach the PTY. Banner paints + auth flows + skill listings
204
+ * can keep the agent unable to accept input for several seconds
205
+ * even though the idle regex matches a transient empty prompt.
206
+ * Send_messages issued before this window are queued and drained
207
+ * once the window passes and an idle state has actually been
208
+ * observed. */
209
+ startup_grace_ms?: number;
210
+ };
211
+ }
@@ -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;
@@ -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;
@@ -49,6 +49,13 @@ export interface ReadChatSyncResult {
49
49
  message: string;
50
50
  buttons: string[];
51
51
  } | null;
52
+ /**
53
+ * Chat source provenance from ChatSourceMachine (A2). Carries the
54
+ * selected source, transition cause, lock state, and legacy
55
+ * fallbackReason — opaque to the daemon-core, consumed by web-core
56
+ * for the source debug badge and SourceTimeline (A3).
57
+ */
58
+ messageSource?: Record<string, unknown>;
52
59
  }
53
60
  export interface ProviderSummaryItem {
54
61
  id: string;
@@ -292,6 +299,11 @@ export interface SessionEntry {
292
299
  seenCompletionMarker?: string;
293
300
  surfaceHidden?: boolean;
294
301
  settings?: Record<string, any>;
302
+ /** Set when this session is acting as a mesh coordinator for the given mesh. */
303
+ coordinator?: {
304
+ meshId: string;
305
+ role: 'coordinator';
306
+ };
295
307
  meshQueueStats?: {
296
308
  total?: number;
297
309
  active?: number;
@@ -46,6 +46,8 @@ export declare class DaemonStatusReporter {
46
46
  private lastStatusSentAt;
47
47
  private statusPendingThrottle;
48
48
  private lastP2PStatusHash;
49
+ private lastP2PStatusSentAt;
50
+ private p2pDebounceTimer;
49
51
  private lastServerStatusHash;
50
52
  private lastStatusSummary;
51
53
  private statusTimer;
@@ -75,6 +75,7 @@ export declare function getSessionCompletionMarker(session: {
75
75
  receivedAt?: number | string;
76
76
  timestamp?: number | string;
77
77
  _turnKey?: string;
78
+ kind?: string;
78
79
  }> | null;
79
80
  } | null;
80
81
  }): string;
package/dist/types.d.ts CHANGED
@@ -36,6 +36,11 @@ export interface ChatMessage {
36
36
  index?: number;
37
37
  timestamp?: number;
38
38
  receivedAt?: number;
39
+ /** (A2.3) Monotonic sequence number per (session, source). Producer-asserted
40
+ * when emitted by v2-aware providers (transcript v2 schema); otherwise
41
+ * derived by the daemon from receivedAt/timestamp/index. ChatSourceMachine
42
+ * uses this as the native peak watermark for regression detection. */
43
+ sequence?: number;
39
44
  _turnKey?: string;
40
45
  /** Tool calls associated with this message */
41
46
  toolCalls?: ToolCallInfo[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhdev/daemon-core",
3
- "version": "0.9.82-rc.16",
3
+ "version": "0.9.82-rc.161",
4
4
  "description": "ADHDev daemon core — CDP, IDE detection, providers, command execution",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -27,7 +27,7 @@
27
27
  "scripts": {
28
28
  "build": "tsup && npm run build:types",
29
29
  "build:types": "tsc -p tsconfig.json --emitDeclarationOnly --declaration --declarationMap false",
30
- "dev": "tsup --watch",
30
+ "dev": "tsup --watch --no-clean",
31
31
  "test": "vitest run",
32
32
  "test:watch": "vitest",
33
33
  "typecheck": "tsc --noEmit -p tsconfig.json"
@@ -48,7 +48,11 @@
48
48
  "dependencies": {
49
49
  "@adhdev/session-host-core": "*",
50
50
  "@agentclientprotocol/sdk": "^0.16.1",
51
+ "@xterm/headless": "^6.0.0",
51
52
  "@xterm/xterm": "^6.0.0",
53
+ "ajv": "^8.20.0",
54
+ "ajv-formats": "^3.0.1",
55
+ "better-sqlite3": "^12.10.0",
52
56
  "chalk": "^5.3.0",
53
57
  "chokidar": "^4.0.3",
54
58
  "conf": "^13.0.0",
@@ -60,6 +64,7 @@
60
64
  "@adhdev/ghostty-vt-node": "*"
61
65
  },
62
66
  "devDependencies": {
67
+ "@types/better-sqlite3": "^7.6.13",
63
68
  "@types/js-yaml": "^4.0.9",
64
69
  "@types/node": "^22.0.0",
65
70
  "@types/ws": "^8.18.1",