@songsid/agend 2.1.2-beta.4 → 2.1.2-beta.40

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 (166) hide show
  1. package/dist/access-path.js +15 -6
  2. package/dist/access-path.js.map +1 -1
  3. package/dist/agent-cli-instructions.md +1 -0
  4. package/dist/agent-cli.js +14 -0
  5. package/dist/agent-cli.js.map +1 -1
  6. package/dist/agent-endpoint.d.ts +2 -0
  7. package/dist/agent-endpoint.js +25 -1
  8. package/dist/agent-endpoint.js.map +1 -1
  9. package/dist/backend/antigravity.d.ts +20 -0
  10. package/dist/backend/antigravity.js +51 -4
  11. package/dist/backend/antigravity.js.map +1 -1
  12. package/dist/backend/claude-code.d.ts +59 -0
  13. package/dist/backend/claude-code.js +67 -1
  14. package/dist/backend/claude-code.js.map +1 -1
  15. package/dist/backend/codex.d.ts +27 -0
  16. package/dist/backend/codex.js +93 -0
  17. package/dist/backend/codex.js.map +1 -1
  18. package/dist/backend/grok.d.ts +25 -0
  19. package/dist/backend/grok.js +51 -0
  20. package/dist/backend/grok.js.map +1 -1
  21. package/dist/backend/kiro.d.ts +22 -0
  22. package/dist/backend/kiro.js +79 -1
  23. package/dist/backend/kiro.js.map +1 -1
  24. package/dist/backend/types.d.ts +58 -0
  25. package/dist/backend/types.js +13 -1
  26. package/dist/backend/types.js.map +1 -1
  27. package/dist/channel/adapters/discord.d.ts +15 -0
  28. package/dist/channel/adapters/discord.js +100 -2
  29. package/dist/channel/adapters/discord.js.map +1 -1
  30. package/dist/channel/adapters/telegram.d.ts +21 -0
  31. package/dist/channel/adapters/telegram.js +86 -0
  32. package/dist/channel/adapters/telegram.js.map +1 -1
  33. package/dist/channel/ipc-bridge.d.ts +9 -1
  34. package/dist/channel/ipc-bridge.js +12 -3
  35. package/dist/channel/ipc-bridge.js.map +1 -1
  36. package/dist/channel/ipc-timeouts.d.ts +46 -0
  37. package/dist/channel/ipc-timeouts.js +65 -0
  38. package/dist/channel/ipc-timeouts.js.map +1 -0
  39. package/dist/channel/mcp-server.js +30 -14
  40. package/dist/channel/mcp-server.js.map +1 -1
  41. package/dist/channel/mcp-tools.js +30 -1
  42. package/dist/channel/mcp-tools.js.map +1 -1
  43. package/dist/channel/reconnect-backoff.d.ts +17 -0
  44. package/dist/channel/reconnect-backoff.js +21 -0
  45. package/dist/channel/reconnect-backoff.js.map +1 -0
  46. package/dist/channel/types.d.ts +29 -0
  47. package/dist/classic-channel-manager.js +1 -5
  48. package/dist/classic-channel-manager.js.map +1 -1
  49. package/dist/cli.js +204 -82
  50. package/dist/cli.js.map +1 -1
  51. package/dist/completion.d.ts +27 -0
  52. package/dist/completion.js +121 -0
  53. package/dist/completion.js.map +1 -0
  54. package/dist/config-validator.js +21 -0
  55. package/dist/config-validator.js.map +1 -1
  56. package/dist/config.js +1 -0
  57. package/dist/config.js.map +1 -1
  58. package/dist/cost-guard.d.ts +3 -1
  59. package/dist/cost-guard.js +3 -1
  60. package/dist/cost-guard.js.map +1 -1
  61. package/dist/daemon.d.ts +260 -14
  62. package/dist/daemon.js +991 -309
  63. package/dist/daemon.js.map +1 -1
  64. package/dist/event-log.d.ts +31 -0
  65. package/dist/event-log.js +96 -0
  66. package/dist/event-log.js.map +1 -1
  67. package/dist/fleet-context.d.ts +9 -0
  68. package/dist/fleet-lock.d.ts +28 -0
  69. package/dist/fleet-lock.js +130 -0
  70. package/dist/fleet-lock.js.map +1 -0
  71. package/dist/fleet-manager.d.ts +315 -2
  72. package/dist/fleet-manager.js +1410 -108
  73. package/dist/fleet-manager.js.map +1 -1
  74. package/dist/general-knowledge/skills/cross-instance-messaging/SKILL.md +22 -0
  75. package/dist/general-knowledge/skills/model-discovery/SKILL.md +14 -23
  76. package/dist/general-knowledge/skills/session-management/SKILL.md +15 -34
  77. package/dist/hang-detector.d.ts +19 -13
  78. package/dist/hang-detector.js +19 -49
  79. package/dist/hang-detector.js.map +1 -1
  80. package/dist/instance-lifecycle.d.ts +44 -3
  81. package/dist/instance-lifecycle.js +165 -48
  82. package/dist/instance-lifecycle.js.map +1 -1
  83. package/dist/instructions.d.ts +5 -0
  84. package/dist/instructions.js +9 -11
  85. package/dist/instructions.js.map +1 -1
  86. package/dist/locale.js +5 -1
  87. package/dist/locale.js.map +1 -1
  88. package/dist/logger.js +14 -0
  89. package/dist/logger.js.map +1 -1
  90. package/dist/mcp-liveness.d.ts +21 -0
  91. package/dist/mcp-liveness.js +27 -0
  92. package/dist/mcp-liveness.js.map +1 -0
  93. package/dist/outbound-handlers.d.ts +16 -0
  94. package/dist/outbound-handlers.js +151 -27
  95. package/dist/outbound-handlers.js.map +1 -1
  96. package/dist/outbound-schemas.d.ts +11 -3
  97. package/dist/outbound-schemas.js +16 -2
  98. package/dist/outbound-schemas.js.map +1 -1
  99. package/dist/pane-write-lock.d.ts +48 -0
  100. package/dist/pane-write-lock.js +73 -0
  101. package/dist/pane-write-lock.js.map +1 -0
  102. package/dist/process-memory.d.ts +31 -0
  103. package/dist/process-memory.js +79 -0
  104. package/dist/process-memory.js.map +1 -0
  105. package/dist/quickstart.js +17 -16
  106. package/dist/quickstart.js.map +1 -1
  107. package/dist/reply-dedup.d.ts +41 -0
  108. package/dist/reply-dedup.js +0 -0
  109. package/dist/reply-dedup.js.map +1 -0
  110. package/dist/scheduler/db.js +3 -0
  111. package/dist/scheduler/db.js.map +1 -1
  112. package/dist/sd-notify.d.ts +27 -0
  113. package/dist/sd-notify.js +33 -1
  114. package/dist/sd-notify.js.map +1 -1
  115. package/dist/secret-file.d.ts +33 -0
  116. package/dist/secret-file.js +36 -0
  117. package/dist/secret-file.js.map +1 -0
  118. package/dist/service-installer.d.ts +16 -0
  119. package/dist/service-installer.js +56 -1
  120. package/dist/service-installer.js.map +1 -1
  121. package/dist/setup-wizard.js +9 -7
  122. package/dist/setup-wizard.js.map +1 -1
  123. package/dist/tmux-control.d.ts +58 -5
  124. package/dist/tmux-control.js +102 -14
  125. package/dist/tmux-control.js.map +1 -1
  126. package/dist/tmux-manager.d.ts +31 -1
  127. package/dist/tmux-manager.js +40 -11
  128. package/dist/tmux-manager.js.map +1 -1
  129. package/dist/topic-commands.d.ts +49 -9
  130. package/dist/topic-commands.js +267 -105
  131. package/dist/topic-commands.js.map +1 -1
  132. package/dist/tui-glyphs.d.ts +5 -1
  133. package/dist/tui-glyphs.js +6 -2
  134. package/dist/tui-glyphs.js.map +1 -1
  135. package/dist/types.d.ts +12 -2
  136. package/dist/ui/view.html +123 -2
  137. package/dist/update-marker.d.ts +15 -0
  138. package/dist/update-marker.js +69 -0
  139. package/dist/update-marker.js.map +1 -0
  140. package/dist/usage/format-rich.d.ts +11 -0
  141. package/dist/usage/format-rich.js +121 -0
  142. package/dist/usage/format-rich.js.map +1 -0
  143. package/dist/usage/provider-alerts.d.ts +33 -0
  144. package/dist/usage/provider-alerts.js +57 -0
  145. package/dist/usage/provider-alerts.js.map +1 -0
  146. package/dist/usage/providers.d.ts +130 -0
  147. package/dist/usage/providers.js +1063 -0
  148. package/dist/usage/providers.js.map +1 -0
  149. package/dist/usage/statusline-usage.d.ts +20 -0
  150. package/dist/usage/statusline-usage.js +120 -0
  151. package/dist/usage/statusline-usage.js.map +1 -0
  152. package/dist/usage/usage-api.d.ts +50 -0
  153. package/dist/usage/usage-api.js +197 -0
  154. package/dist/usage/usage-api.js.map +1 -0
  155. package/dist/view-api.d.ts +3 -0
  156. package/dist/view-api.js +11 -2
  157. package/dist/view-api.js.map +1 -1
  158. package/dist/web-api.js +5 -2
  159. package/dist/web-api.js.map +1 -1
  160. package/package.json +4 -1
  161. package/dist/channel/tool-tracker.d.ts +0 -13
  162. package/dist/channel/tool-tracker.js +0 -58
  163. package/dist/channel/tool-tracker.js.map +0 -1
  164. package/dist/daemon-entry.d.ts +0 -1
  165. package/dist/daemon-entry.js +0 -30
  166. package/dist/daemon-entry.js.map +0 -1
package/dist/daemon.d.ts CHANGED
@@ -1,21 +1,65 @@
1
1
  import { EventEmitter } from "node:events";
2
2
  import type { InstanceConfig, RotationSnapshot } from "./types.js";
3
- import type { Logger } from "./logger.js";
3
+ import { type Logger } from "./logger.js";
4
4
  import { MessageBus } from "./channel/message-bus.js";
5
5
  import type { CliBackend, InstanceState, InstanceStateSnapshot } from "./backend/types.js";
6
6
  import { HangDetector } from "./hang-detector.js";
7
7
  import type { TmuxControlClient } from "./tmux-control.js";
8
+ import type { FleetInstructionsParams } from "./instructions.js";
8
9
  /** Point a resumed CLI at its one backend-native instruction source. */
9
10
  export declare function buildInstructionReloadNotice(binaryName: string, instanceName: string, instanceDir: string): string;
10
11
  export declare const DEFAULT_STUCK_TIMEOUT_MS: number;
11
12
  export declare const DEFAULT_STATE_IDLE_DEBOUNCE_MS = 2000;
12
13
  export declare const DEFAULT_STATE_SAFETY_SWEEP_MS = 60000;
13
- /** @deprecated State detection is event-driven; this now aliases the safety sweep. */
14
- export declare const DEFAULT_STATE_POLL_INTERVAL_MS = 60000;
14
+ /**
15
+ * Whether two working directories belong to the same project, so a fleet-scoped
16
+ * decision recorded in one reaches the other. Covers the worktree/checkout
17
+ * layout AgEnD fleets actually use — `AgEnD`, `AgEnD-dev1`, `AgEnD-dev2`,
18
+ * `AgEnD-reviewer`, `AgEnD-main` are one project; `DouPo_Server` is not.
19
+ * Nesting counts too (a subdirectory of a project belongs to it).
20
+ */
21
+ export declare function sameProjectFamily(a: string, b: string): boolean;
22
+ /**
23
+ * Pick the decisions worth injecting into one instance's system prompt.
24
+ *
25
+ * `scope: "fleet"` previously bypassed the project check outright, so every
26
+ * instance carried every other project's playbook — measured at 8 of 14 here,
27
+ * resent on every API call. A fleet decision must now also be relevant: global
28
+ * (no project_root), the same project, or the same project family.
29
+ *
30
+ * `isDispatcher` (a general) opts out of that narrowing on purpose: it routes
31
+ * work across all projects, so cross-project rules ("X 文件操作由 Y 負責") are
32
+ * precisely what it must know. Narrowing a general would cause misrouting.
33
+ */
34
+ export declare function selectRelevantDecisions<T extends {
35
+ scope?: string;
36
+ project_root?: string;
37
+ title: string;
38
+ }>(all: T[], workDir: string, isDispatcher?: boolean): T[];
15
39
  /** Read the last real channel inbound timestamp persisted across daemon restarts. */
16
40
  export declare function readLastInboundAt(instanceDir: string, now?: number): number | null;
17
41
  /** Atomically persist the last real channel inbound timestamp. */
18
42
  export declare function writeLastInboundAt(instanceDir: string, timestamp: number): void;
43
+ /**
44
+ * Render the handoff/routing metadata that rides along with an inbound message
45
+ * into the block actually pasted into the agent's pane.
46
+ *
47
+ * These fields were all populated by the sender (outbound-handlers builds them
48
+ * into `ipcMeta`) and delivered over IPC, but never rendered — so the receiving
49
+ * agent could not see them, and several documented flows could not work:
50
+ *
51
+ * - `report_result` requires a `correlation_id` the agent had no way to know, so
52
+ * the "correlation_id not recognized" warning fired on essentially every call.
53
+ * - Delegation cancel buttons are retired by correlation id, so they never retired.
54
+ * - `react`, `edit_message` and `reply.reply_to` need `message_id`, which the tool
55
+ * descriptions tell the agent to take "from the inbound block".
56
+ * - `download_attachment` needs `attachment_file_id`.
57
+ * - `requires_reply` was invisible, so a delegated task looked like an FYI.
58
+ *
59
+ * Only non-empty fields are emitted, so a plain user message gains at most a
60
+ * message_id line.
61
+ */
62
+ export declare function renderHandoffMetadata(meta: Record<string, string>): string;
19
63
  /** Headless inactivity timer used by the daemon and unit tests. */
20
64
  export declare class AutoPauseController {
21
65
  private readonly thresholdMs;
@@ -36,17 +80,73 @@ export declare class AutoPauseController {
36
80
  * Pane motion wins over a ready match because several backends keep their ready
37
81
  * marker in a persistent header/footer while generating. A stable ready pane is
38
82
  * idle; changing content is working; stable non-ready content eventually sticks.
83
+ *
84
+ * ## Why an optional busy pattern exists
85
+ *
86
+ * "Motion wins" degrades badly when a backend's ready marker is *always* on
87
+ * screen. `stuck` requires `!ready`, so for such a backend the state can only ever
88
+ * be idle or working — the stuck edge, and with it `handleStuckTransition` and the
89
+ * hang notification, is unreachable. A frozen CLI is then reported as idle, which
90
+ * also clears pending work: the message the user sent is quietly booked as done.
91
+ *
92
+ * claude-code was exactly this case (see ClaudeCodeBackend.getReadyPattern). A
93
+ * backend that can point at a marker meaning "generating right now" supplies
94
+ * `getBusyPattern()`, and that match vetoes ready regardless of what the ready
95
+ * pattern says.
39
96
  */
97
+ /**
98
+ * A shell command reduced to the part that is safe to show: the program, and a
99
+ * subcommand when there is one.
100
+ *
101
+ * curl -H "Bearer sk-ant-…" https://api.com → curl
102
+ * npm test --env=API_KEY=xxx → npm test
103
+ * git push origin main → git push
104
+ *
105
+ * Arguments are dropped wholesale rather than filtered, because there is no
106
+ * reliable way to tell a secret from an ordinary argument: tokens, bearer
107
+ * headers, connection strings and `--password=` values all look like text. The
108
+ * progress line is posted to a chat channel and, for a public one, so is
109
+ * anything in it — so the rule is "never the arguments", not "not the arguments
110
+ * that look dangerous".
111
+ *
112
+ * A second token is kept only when it is a bare word (`push`, `test`), which is
113
+ * what a subcommand looks like and what a flag, path, URL, assignment or quoted
114
+ * string does not. Everything after it goes, including `git push ORIGIN MAIN`.
115
+ */
116
+ export declare function shellCommandLabel(command: string): string;
40
117
  export declare class PaneStateMachine {
41
118
  private readonly stuckTimeoutMs;
42
119
  private readonly readyPattern;
120
+ private readonly busyPattern;
43
121
  private lastPaneHash;
44
122
  private lastPaneChangeAt;
45
123
  private lastObservedAt;
46
124
  private stateChangedAt;
47
125
  private currentState;
48
- constructor(readyPattern: RegExp, stuckTimeoutMs?: number, now?: number);
49
- observe(pane: string, now?: number): InstanceStateSnapshot;
126
+ constructor(readyPattern: RegExp, stuckTimeoutMs?: number, now?: number, busyPattern?: RegExp | null);
127
+ /** Ready, unless the backend can positively see that it is still generating. */
128
+ private isReady;
129
+ /**
130
+ * @param now when this observation is being evaluated — drives the idle and
131
+ * stuck decisions.
132
+ * @param opts.changeAt when the content is believed to have changed, if that
133
+ * is earlier than `now` (the tmux output timestamp). Only the elapsed-time
134
+ * clock uses it; defaults to `now`.
135
+ * @param opts.settled the caller knows no output has arrived for the debounce
136
+ * window, so "the content differs from the last capture" says nothing about
137
+ * whether the CLI is still generating — decide on the patterns instead.
138
+ *
139
+ * Captures are event-driven, not periodic: the one taken 2s after output
140
+ * stops is compared against a capture that may be a minute old, so it
141
+ * *always* differs. Without this flag that difference reads as "still
142
+ * working" and a finished turn would not be seen as idle until the next 60s
143
+ * safety sweep. Output timestamps are the honest liveness signal here, and
144
+ * the caller has them.
145
+ */
146
+ observe(pane: string, now?: number, opts?: {
147
+ settled?: boolean;
148
+ changeAt?: number;
149
+ }): InstanceStateSnapshot;
50
150
  /** Record pane motion from tmux control mode without capturing pane content. */
51
151
  recordOutput(now?: number): InstanceStateSnapshot;
52
152
  snapshot(now?: number): InstanceStateSnapshot;
@@ -83,13 +183,13 @@ export declare class Daemon extends EventEmitter {
83
183
  private topicMode;
84
184
  private backend?;
85
185
  private controlClient?;
186
+ private runtimeIdentity?;
86
187
  private logger;
87
188
  private tmuxSessionName;
88
189
  private tmux;
89
190
  private ipcServer;
90
191
  private messageBus;
91
192
  private transcriptMonitor;
92
- private toolTracker;
93
193
  private guardian;
94
194
  private adapter;
95
195
  private pendingIpcRequests;
@@ -97,6 +197,8 @@ export declare class Daemon extends EventEmitter {
97
197
  private lastThreadId;
98
198
  private lastAdapterId;
99
199
  private pendingAckMessage;
200
+ /** Last activity published to the fleet manager; null when nothing is running. */
201
+ private currentActivity;
100
202
  private toolStatusMessageId;
101
203
  private toolStatusLines;
102
204
  private toolStatusDebounce;
@@ -110,9 +212,19 @@ export declare class Daemon extends EventEmitter {
110
212
  private lastSpawnAt;
111
213
  private crashTimestamps;
112
214
  private healthCheckPaused;
215
+ private lastHealthErrorNotifyAt;
113
216
  /** CLI pane availability, independent from the daemon process and tri-state. */
114
217
  private processStatus;
115
218
  private spawning;
219
+ /**
220
+ * Resolves when the in-flight spawn finishes; null when none is running.
221
+ *
222
+ * `spawning` alone can only be polled. Delivery needs to *wait*, and a boolean
223
+ * poll would either busy-loop or race the flag being cleared.
224
+ */
225
+ private spawnSettled;
226
+ private resolveSpawnSettled;
227
+ private spawnDepth;
116
228
  private skipResume;
117
229
  private backgroundSessionRecoveryAttempted;
118
230
  /** Whether the last spawn started a fresh session (not resumed). */
@@ -134,10 +246,18 @@ export declare class Daemon extends EventEmitter {
134
246
  private instanceStateIdleDebounceMs;
135
247
  private instanceStateStuckTimeoutMs;
136
248
  private instanceStateReadyPattern;
249
+ private instanceStateBusyPattern;
137
250
  private instanceStateMonitorActive;
138
251
  private statePollInFlight;
139
252
  private autoPauseController;
140
253
  private pauseRequested;
254
+ /**
255
+ * Sticky "pause as soon as possible" (auth failure). Unlike pauseRequested —
256
+ * which the state monitor clears whenever the pane is not idle — this survives
257
+ * busy/stuck states, because an auth error fires mid-turn and a plain pause()
258
+ * would silently no-op exactly when we most need to stop feeding the CLI.
259
+ */
260
+ private pausePending;
141
261
  private pauseWakeState;
142
262
  private pauseWakeTransition;
143
263
  private modelOverride;
@@ -145,7 +265,13 @@ export declare class Daemon extends EventEmitter {
145
265
  private recentEvents;
146
266
  private recentToolActivity;
147
267
  private snapshotConsumed;
268
+ /** Orders inbound channel messages against each other (queue-depth accounting
269
+ * and ⏳/👀/✅ reactions live here). It does NOT cover the other writers that
270
+ * reach the pane — {@link paneWriteLock} does. */
148
271
  private pasteLock;
272
+ /** Mutual exclusion for *every* write into the pane, whichever subsystem it
273
+ * comes from. See PaneWriteLock for why interleaving is destructive. */
274
+ private readonly paneWriteLock;
149
275
  private pendingInstructionsUpdate;
150
276
  private pendingInstructionsNotice;
151
277
  private warmupNeeded;
@@ -153,6 +279,10 @@ export declare class Daemon extends EventEmitter {
153
279
  private pasteQueueDepth;
154
280
  private firstDeliveryDelay;
155
281
  private errorMonitorTimer;
282
+ /** Same 5-min gate the error monitor uses, so a dead MCP server alerts once. */
283
+ private static readonly MCP_DEATH_COOLDOWN_MS;
284
+ private lastMcpDeathNotifiedAt;
285
+ private mcpDeathNotifiedForPid;
156
286
  /** Prevent in-flight monitor callbacks from re-arming after a pause. */
157
287
  private runtimeMonitorsFrozen;
158
288
  private errorWaitingForRecovery;
@@ -177,14 +307,42 @@ export declare class Daemon extends EventEmitter {
177
307
  private lastDetectedErrorType;
178
308
  private static errorPatternKey;
179
309
  private clearErrorRecoveryGate;
180
- constructor(name: string, config: InstanceConfig, instanceDir: string, topicMode?: boolean, backend?: CliBackend | undefined, controlClient?: TmuxControlClient | undefined, rootLogger?: Logger);
310
+ constructor(name: string, config: InstanceConfig, instanceDir: string, topicMode?: boolean, backend?: CliBackend | undefined, controlClient?: TmuxControlClient | undefined, rootLogger?: Logger, runtimeIdentity?: FleetInstructionsParams["runtimeIdentity"]);
181
311
  start(): Promise<void>;
312
+ /**
313
+ * Detect a CRASHED MCP server and report it once.
314
+ *
315
+ * The MCP server writes its pid to channel.mcp.pid at startup and unlinks it on
316
+ * a clean exit, so "file present + pid dead" specifically means it died without
317
+ * cleaning up (crash / OOM / SIGKILL). A missing file is either "not started
318
+ * yet" or "exited cleanly" — neither is an incident, and an orphan exit implies
319
+ * the CLI itself died, which the crash detector already covers.
320
+ *
321
+ * The daemon deliberately does NOT try to respawn it: MCP is a stdio protocol
322
+ * where the CLI spawns the server and owns its pipes, so a daemon-spawned
323
+ * process would have no client reading it. Only the CLI can restore its own
324
+ * tools — hence notify, and let the operator decide about restarting.
325
+ */
326
+ private checkMcpServerAlive;
182
327
  private startHealthCheck;
183
328
  /**
184
329
  * Publish pane-process availability separately from idle/working/stuck.
185
330
  * A dead remain-on-exit pane still contains the old ready prompt, so allowing
186
331
  * the pane monitor to capture it would re-create a false idle state.
187
332
  */
333
+ /**
334
+ * Announce that this instance is no longer being supervised.
335
+ *
336
+ * Four health-check exits set `healthCheckPaused = true` and returned without
337
+ * telling anyone: a clean CLI exit, `max_retries <= 0`, crash retries exhausted,
338
+ * and the instance directory being deleted. Only the crash-LOOP case emitted an
339
+ * event, so a fleet could quietly contain a dead instance that still looked fine
340
+ * on the dashboard — while messages routed to it queued or failed with a bare ❌.
341
+ *
342
+ * `crash_loop` already had this treatment; this is the same bridge for the other
343
+ * four, carrying a human-readable cause and the operator's next step.
344
+ */
345
+ private emitSupervisionEnded;
188
346
  private setProcessStatus;
189
347
  /**
190
348
  * Periodically scan PTY output for backend-defined error patterns.
@@ -211,6 +369,12 @@ export declare class Daemon extends EventEmitter {
211
369
  * Interrupt the CLI's current generation (cancel button / `/cancel`).
212
370
  * Direct tmux key event (not a paste) so it registers as the interrupt key.
213
371
  * kiro-cli interrupts on Ctrl+C; the others (claude-code, codex, …) on Escape.
372
+ *
373
+ * Deliberately NOT taken through `paneWriteLock`. Cancel is the user's way out
374
+ * of a pane that is busy or wedged — queueing it behind the very delivery chain
375
+ * it exists to unblock would make the button useless exactly when it is needed.
376
+ * The cost is accepted: an Escape landing between a paste and its Enter discards
377
+ * that message, which is what the user asked for anyway.
214
378
  */
215
379
  sendEscape(): Promise<void>;
216
380
  /** Send the backend-specific graceful quit command/key sequence. */
@@ -220,6 +384,12 @@ export declare class Daemon extends EventEmitter {
220
384
  getInstanceState(): InstanceState | "paused";
221
385
  getInstanceStateSnapshot(): InstanceStateSnapshot;
222
386
  /** Gracefully stop the CLI while keeping its remain-on-exit tmux window. */
387
+ /**
388
+ * Mark the instance to pause as soon as its pane is idle. Used for auth
389
+ * failures: pause() alone no-ops while the CLI is busy/stuck, which is the
390
+ * usual state when the error surfaces. Cleared by a successful pause or wake.
391
+ */
392
+ requestPauseWhenIdle(): void;
223
393
  pause(): Promise<void>;
224
394
  /** Respawn the CLI in the preserved window and block until its prompt is ready. */
225
395
  wake(timeoutMs?: number): Promise<void>;
@@ -239,6 +409,28 @@ export declare class Daemon extends EventEmitter {
239
409
  /** Restore the same monitor objects after wake without adding event listeners. */
240
410
  private resumeRuntimeMonitors;
241
411
  getMessageBus(): MessageBus;
412
+ /**
413
+ * Tell the fleet manager what this instance is doing right now, for the live
414
+ * progress line on the cancel button.
415
+ *
416
+ * Purely cosmetic — nothing decides anything from it, so it is fine that only
417
+ * backends with a transcript feed report at all (claude-code today). For the
418
+ * rest the progress line keeps showing just elapsed time.
419
+ *
420
+ * Repeats are dropped: the ticker only edits the channel message when the text
421
+ * changes, and a stream of identical broadcasts would defeat that.
422
+ */
423
+ private publishActivity;
424
+ /**
425
+ * Options for every system-initiated paste (startup notice, session snapshot,
426
+ * runtime-dialog keys).
427
+ *
428
+ * One place, so the three call sites cannot drift apart on it. Backends with a
429
+ * native input queue do not get the retry Enter: on those, a second bare Enter
430
+ * is not the no-op the retry assumed but a queue mutation — the same reason
431
+ * `deliverMessage` refuses to probe for busy with one.
432
+ */
433
+ private systemPasteOptions;
242
434
  private summarizeTool;
243
435
  private addToolStatus;
244
436
  /** Debounce tool status updates to avoid channel rate limits */
@@ -254,23 +446,52 @@ export declare class Daemon extends EventEmitter {
254
446
  pushChannelMessage(content: string, meta: Record<string, string>, _targetSession?: string): void;
255
447
  /**
256
448
  * Deliver a single message and drive its status reactions:
257
- * ⏳ message_queued — CLI busy; queued, waiting for idle
449
+ * ⏳ message_queued — CLI busy; queued locally or by the backend
258
450
  * 👀 message_delivered — pasted + Enter sent; agent now has it
259
- * ✅ message_confirmed — idle→busy transition observed; agent is processing
451
+ * ✅ message_confirmed — processing observed, or native queue handoff succeeded
260
452
  * ❌ message_failed — tmux window gone, paste retries exhausted
261
453
  * Returns true once the message is in the CLI, false only on real delivery failure.
262
454
  *
263
455
  * Bug A (silent message loss): paste failures retry with backoff (window recovery)
264
456
  * and emit `message_failed` if all attempts fail.
265
- * Busy handling (UX): we never force-paste into a busy CLI and never give up on a
266
- * busy one — we show ⏳ and wait for idle indefinitely (a genuinely hung CLI is the
267
- * hang detector's job; a user who can't wait presses Cancel → Escape → idle). The
268
- * pasteLock is serial, so later messages naturally queue behind this wait.
457
+ * Busy handling (UX): backends without a native input queue show and wait for
458
+ * idle indefinitely (a genuinely hung CLI is the hang detector's job). Backends
459
+ * that explicitly support queued input receive one complete paste+Enter transaction
460
+ * immediately and own the application-level queue themselves. The pasteLock remains
461
+ * serial in both cases so separate PTY writes can never overlap.
269
462
  */
270
463
  private deliverMessage;
464
+ /**
465
+ * The write half of a delivery: paste → Enter → confirm, with retries.
466
+ *
467
+ * Always called under {@link paneWriteLock}. Split out from `deliverMessage`
468
+ * precisely so the lock's scope is visible at the call site rather than being
469
+ * an invariant maintained by comments.
470
+ */
471
+ private writeMessageToPane;
472
+ /**
473
+ * True when a busy native-queue paste appears to have landed: Codex shows a
474
+ * `↳` queue marker, or a distinctive slice of the pasted text is on screen.
475
+ * Used only to detect silent paste loss — not as a general ready check.
476
+ */
477
+ private nativeQueuePasteVisible;
271
478
  /** Re-resolve this instance's tmux window by name (stale id after crash/respawn). */
272
479
  private recoverWindow;
273
- /** Poll up to ~2s (200ms × 10) for the pane to emit output after `since`. */
480
+ /**
481
+ * Poll up to ~2s (200ms × 10) for the pane to emit output after `since`.
482
+ *
483
+ * A `false` here is not "no output" — it is read as **"the message was pasted but
484
+ * never submitted"**, which re-sends Enter and then reports ❌ to the user. So a
485
+ * false negative costs a possible double submit and a failure notice for a
486
+ * message that actually arrived.
487
+ *
488
+ * That is exactly what a control-mode reconnect used to produce. `connect()`
489
+ * drops every output timestamp, so `hasOutputSince` answers `false` for a pane
490
+ * that did react — the evidence was thrown away, not absent. Blind time is
491
+ * therefore not counted against the budget: after a reset the poll restarts from
492
+ * the moment observation resumed. A hard wall-clock cap keeps a reconnect loop
493
+ * from extending this forever.
494
+ */
274
495
  private confirmBusyAfterEnter;
275
496
  private getWindowId;
276
497
  /** Find the IPC socket for a given sessionName */
@@ -288,6 +509,31 @@ export declare class Daemon extends EventEmitter {
288
509
  * This replaces the old system-prompt injection approach.
289
510
  */
290
511
  private injectSnapshotMessage;
512
+ /**
513
+ * Depth, not a flag: the wake path marks a spawn and then calls trySpawn, which
514
+ * marks another. With a plain boolean the inner one's completion would clear the
515
+ * latch while the outer spawn was still dismissing dialogs, releasing delivery
516
+ * into exactly the window this exists to close.
517
+ */
518
+ private beginSpawn;
519
+ private endSpawn;
520
+ /**
521
+ * Hold until the CLI has finished starting up.
522
+ *
523
+ * Startup is not a quiet period: `dismissDialogsUntilReady` is clicking through
524
+ * trust prompts and session pickers. A pane showing a modal dialog produces no
525
+ * output, so `waitUntilIdle` reports it idle and a queued message gets pasted
526
+ * *into the dialog* — where the text is discarded and the Enter picks a menu
527
+ * item. The paste and the Enter both "succeed", so this loses the message
528
+ * without even a ❌.
529
+ *
530
+ * The pane write lock (#414) does not cover this: it serialises each key
531
+ * sequence, but it is released between one dialog and the next.
532
+ *
533
+ * Bounded, and called BEFORE the pane lock is taken — waiting on the spawn while
534
+ * holding the lock the spawn itself needs would deadlock.
535
+ */
536
+ private waitForSpawnToSettle;
291
537
  /** Spawn a CLI window. Returns true if --resume was used successfully. */
292
538
  private spawnClaudeWindow;
293
539
  /** Kill the entire process tree of the current tmux pane (CLI + MCP server). */