@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
@@ -1,3 +1,5 @@
1
+ import { type FleetMemory } from "./process-memory.js";
2
+ import { ReplyDeduper } from "./reply-dedup.js";
1
3
  import type { FleetConfig, RawFleetConfig, InstanceConfig } from "./types.js";
2
4
  import { type RouteTarget } from "./fleet-context.js";
3
5
  import { EventLog } from "./event-log.js";
@@ -48,7 +50,7 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
48
50
  private static sighupHandlerInstalled;
49
51
  private children;
50
52
  readonly lifecycle: InstanceLifecycle;
51
- /** @deprecated Use lifecycle.daemons — kept for backward compat */
53
+ /** Live view of lifecycle.daemons — used throughout; not deprecated. */
52
54
  get daemons(): Map<string, import("./daemon.js").Daemon>;
53
55
  fleetConfig: FleetConfig | null;
54
56
  private rawFleetConfig;
@@ -98,15 +100,29 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
98
100
  private instanceIdleWaiters;
99
101
  private lastInboundUser;
100
102
  private cancelButtons;
103
+ /** Pending idle-edge retirement, one timer per instance. */
104
+ private cancelButtonIdleRetireTimers;
105
+ /** Duplicate-reply suppression across both the MCP and HTTP reply paths. */
106
+ readonly replyDeduper: ReplyDeduper;
107
+ /** instanceName → what it is doing right now, when the backend can tell us. */
108
+ private instanceActivity;
109
+ /** instanceName → tail of deliveries waiting for its IPC to come back. */
110
+ private ipcWaitTails;
101
111
  private lastInboundMsg;
102
112
  private topicArchiver;
103
113
  controlClient: TmuxControlClient | null;
104
114
  classicChannels: ClassicChannelManager | null;
105
115
  private pendingClassicStarts;
106
116
  /** In-flight /model selections, keyed by nonce (see handleModelSelection). */
117
+ /** In-flight /effort selections, same coordinator shape as pendingModelSelects. */
118
+ private pendingEffortSelects;
107
119
  private pendingModelSelects;
108
120
  private failoverActive;
121
+ /** instance → when a click with no live button entry last fired a cancel. */
122
+ private staleCancelClickAt;
109
123
  readonly ipcStoppingInstances: Set<string>;
124
+ /** Set the moment a graceful stop begins — see isPlannedRestart(). */
125
+ private shuttingDown;
110
126
  /** Coalesce concurrent connection attempts for the same daemon socket. */
111
127
  private ipcConnectInFlight;
112
128
  /** At most one reconnect/backoff loop may exist per instance. */
@@ -117,6 +133,10 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
117
133
  private healthServer;
118
134
  private healthPortRetried;
119
135
  private updateCheckTimer;
136
+ private eventLogPruneTimer;
137
+ private logRotateTimer;
138
+ /** Days of event/activity history to keep. */
139
+ private static readonly EVENT_LOG_RETENTION_DAYS;
120
140
  private watchdogTimer;
121
141
  private startedAt;
122
142
  private mirrorBuffer;
@@ -127,9 +147,38 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
127
147
  constructor(dataDir: string);
128
148
  private handleSighup;
129
149
  private scheduleReconcile;
150
+ /**
151
+ * Is the fleet going down (or coming back up) on purpose?
152
+ *
153
+ * Instances dying during a planned restart is the restart working, not an
154
+ * incident — but the code that notices a dead pane or a dead MCP server
155
+ * cannot tell the difference on its own. Two sources, because the noise
156
+ * starts before this process is even told to stop: `agend update` replaces
157
+ * the package on disk while this daemon is still running and still watching.
158
+ */
159
+ isPlannedRestart(): boolean;
130
160
  private finishStartup;
131
161
  lastActivityMs(name: string): number;
162
+ /**
163
+ * Is the instance between turns?
164
+ *
165
+ * Prefers the daemon's pane state machine (debounced, busy-pattern aware) over
166
+ * the control client's raw 2-second output-silence heuristic. The raw heuristic
167
+ * reads every >2s output lull as idle — and long silent tools (a build, a test
168
+ * run) or an LLM pause produce those constantly mid-turn. That misreading is
169
+ * what retired cancel buttons in the middle of long work (the 5-minute backstop
170
+ * fired during a lull) and froze their progress text (ticker skipped "idle"
171
+ * ticks). The silence heuristic remains only as the fallback for instances
172
+ * whose daemon has not reported a state yet.
173
+ */
132
174
  private getInstanceIdle;
175
+ /**
176
+ * True when the instance claims working/stuck but nothing has refreshed that
177
+ * claim for STATE_REPORT_STALE_MS despite the backstop's per-tick queries.
178
+ * Measures the CACHE's age, not the button's — a healthy multi-hour run
179
+ * answers every query and never trips this.
180
+ */
181
+ private stateReportDead;
133
182
  webhookEmit(event: string, name: string, data?: Record<string, unknown>): void;
134
183
  getSysInfo(): import("./fleet-context.js").SysInfo;
135
184
  /** Load fleet.yaml and build routing table */
@@ -184,6 +233,8 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
184
233
  getInstanceExecutionState(name: string): InstanceState | null;
185
234
  isClassicInstance(name: string): boolean;
186
235
  private cacheInstanceExecutionState;
236
+ private cancelIdleButtonRetirement;
237
+ private scheduleIdleButtonRetirement;
187
238
  private cacheInstanceProcessStatus;
188
239
  /**
189
240
  * Fleet-wide warm cap: if more than `defaults.warm_cap` instances are running,
@@ -197,6 +248,25 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
197
248
  private enforceWarmCap;
198
249
  private waitForInstanceIdle;
199
250
  private deliverWithIdleGate;
251
+ /**
252
+ * Hand a payload to an instance's IPC, waiting out a *transient* disconnect.
253
+ *
254
+ * A daemon that is restarting — `/restart`, crash recovery, a model switch —
255
+ * drops its socket for a few seconds. Any message arriving in that window used
256
+ * to fail instantly: the caller logged a warning, put ❌ on the user's message,
257
+ * and the message was gone. The user had to notice the ❌ and retype it. That is
258
+ * the "instance 訊息不容易掉" goal failing on the most predictable event there is.
259
+ *
260
+ * The wait is bounded. If the instance is genuinely down, this still throws and
261
+ * the ❌ still appears — just for a real failure rather than a restart.
262
+ *
263
+ * Ordering is preserved by serialising behind any waiter already queued for this
264
+ * instance, *including* when the socket happens to be up: otherwise a message
265
+ * arriving after the reconnect could overtake one that has been waiting for it.
266
+ */
267
+ private sendWhenConnected;
268
+ /** Poll for the instance's IPC to come back, then send. Throws if it does not. */
269
+ private sendAfterIpcReturns;
200
270
  /** Single delivery facade: wake paused CLIs and serialize non-user work behind idle. */
201
271
  deliverToInstance(instanceName: string, payload: Record<string, unknown>, options?: DeliveryOptions): Promise<void>;
202
272
  /** Fleet admin is an explicit config allowlist entry, not merely an open/paired user. */
@@ -204,7 +274,7 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
204
274
  changeInstancePauseState(name: string, action: "pause" | "wake"): Promise<"paused" | "awake" | "not_idle">;
205
275
  /** Apply a Settings edit to a ClassicBot channel without waiting for the poller. */
206
276
  restartClassicInstanceFromSettings(instanceName: string): Promise<void>;
207
- startInstance(name: string, config: InstanceConfig, topicMode: boolean): Promise<void>;
277
+ startInstance(name: string, config: InstanceConfig, topicMode: boolean, kind?: "fleet-topic" | "classic"): Promise<void>;
208
278
  /** Recreate a daemon for a marker-only paused instance after an explicit wake/delivery. */
209
279
  startPersistedPausedInstance(name: string): Promise<void>;
210
280
  /**
@@ -251,6 +321,42 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
251
321
  retryCount: number;
252
322
  lastError?: string;
253
323
  }>;
324
+ /**
325
+ * Real, checkable fleet health for `/health` and the operator.
326
+ *
327
+ * `status` is:
328
+ * - `ok` — at least one adapter connected and every configured instance
329
+ * that should be running is running
330
+ * - `degraded` — reachable, but something the operator should look at (an
331
+ * adapter retrying, an instance crashed or stopped)
332
+ * - `down` — the fleet cannot do its job: no adapter is connected, so no
333
+ * message can arrive or be answered
334
+ *
335
+ * Deliberately does NOT gate the systemd watchdog — see the comment at the
336
+ * WATCHDOG timer for why.
337
+ */
338
+ getFleetHealth(): {
339
+ status: "ok" | "degraded" | "down";
340
+ uptime: number;
341
+ instances: {
342
+ configured: number;
343
+ running: number;
344
+ crashed: number;
345
+ paused: number;
346
+ stopped: number;
347
+ };
348
+ adapters: {
349
+ total: number;
350
+ connected: number;
351
+ states: Record<string, string>;
352
+ };
353
+ startupComplete: boolean;
354
+ /** See process-memory.ts: the fleet process and the whole service cgroup are
355
+ * reported separately because they differ by ~60x and only one of them can
356
+ * show a fleet-manager leak. */
357
+ memory: FleetMemory;
358
+ problems: string[];
359
+ };
254
360
  /** Start the primary adapter (backward-compatible, sets this.adapter) */
255
361
  private startSingleAdapter;
256
362
  /** Start an additional (non-primary) adapter */
@@ -265,6 +371,23 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
265
371
  private restartAdapter;
266
372
  /** Handle inbound message — transcribe voice if present, then route */
267
373
  private findGeneralInstance;
374
+ /**
375
+ * A user reacted to one of the bot's messages (#408).
376
+ *
377
+ * A reaction is context, not a message (#432, reworking #413): it never triggers
378
+ * an agent turn and never wakes anything. It is queued in the event log and rides
379
+ * into the instance's NEXT real message as one compact leading line —
380
+ * `[Recent reactions: 👍×2 from hanhanv]` — after which it is marked consumed.
381
+ * No pending reactions → no line → zero context spent, which is the common case.
382
+ */
383
+ private handleInboundReaction;
384
+ /**
385
+ * The queued-reaction summary for an instance's next real message, or {} when
386
+ * nothing is pending (the common case must add zero context). The consume
387
+ * callback is separate from the fetch so reactions are only marked once the
388
+ * message actually went out — a failed delivery keeps them queued.
389
+ */
390
+ private pendingReactionsMeta;
268
391
  private handleInboundMessage;
269
392
  /** Handle outbound tool calls from a daemon instance */
270
393
  /** Warn (but don't block) when rate limits are high. 30-min debounce per instance. */
@@ -272,6 +395,8 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
272
395
  private warnIfRateLimited;
273
396
  /** Handle outbound tool calls from a daemon instance */
274
397
  private handleOutboundFromInstance;
398
+ /** Side effects of a routed reply: cancel-button lifecycle, logs, SSE, chat log. */
399
+ private afterReplyRouted;
275
400
  /** Handle tool status update from a daemon instance */
276
401
  private handleToolStatusFromInstance;
277
402
  private handleScheduleTrigger;
@@ -313,6 +438,68 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
313
438
  private static FAILOVER_RECOVER_PCT;
314
439
  checkModelFailover(name: string, fiveHourPct: number): void;
315
440
  toggleFleetCollab(instanceName: string): boolean;
441
+ /**
442
+ * Open the event log, tolerating a corrupt file.
443
+ *
444
+ * `events.db` holds history only — event rows and the activity feed. Nothing the
445
+ * fleet needs to run depends on it, and every consumer already uses
446
+ * `this.eventLog?.`. An unguarded `new EventLog(...)` here meant a corrupt or
447
+ * unreadable history file (a truncated WAL after a hard kill, a full disk)
448
+ * threw during startAll and the WHOLE FLEET FAILED TO BOOT — trading every
449
+ * running agent for a file whose only job is reporting.
450
+ *
451
+ * So: try, move a bad file aside and retry once with a fresh one, and if even
452
+ * that fails carry on without an event log.
453
+ */
454
+ /**
455
+ * Run `agend backend doctor` for the fleet's default backend and return its
456
+ * cleaned output.
457
+ *
458
+ * Async on purpose: this was `execSync` with a 30s timeout, reachable by any
459
+ * allowlisted user through `/doctor`. While it ran, the entire fleet event loop
460
+ * was frozen — no IPC, no adapter, no message delivery, no health responses,
461
+ * and critically no WATCHDOG ping, so a slow doctor could push past
462
+ * WatchdogSec and have systemd SIGABRT the fleet.
463
+ */
464
+ private runBackendDoctor;
465
+ /** Drop event/activity rows older than the retention window. Best-effort. */
466
+ /**
467
+ * Cap every instance's pipe-pane log, walking the instances **directory** rather
468
+ * than the config.
469
+ *
470
+ * A running instance rotates its own log on each health tick, so the ones that
471
+ * need this are the ones nothing else looks at:
472
+ *
473
+ * - deleted instances, whose directory outlives the config entry. Nothing ever
474
+ * touched these again. On the machine this was found on, one held 122 MB and
475
+ * another 74 MB, out of 622 MB of pipe-pane logs in total.
476
+ * - classic instances, which live in classicChannels, not fleetConfig.instances,
477
+ * and so were never in the old config-driven loop at all.
478
+ * - stopped instances, which have no health tick running.
479
+ *
480
+ * pipe-pane writes raw TUI output, so a wedged splash screen can emit ANSI frames
481
+ * at animation rate. Unbounded growth here fills the disk, which takes the whole
482
+ * fleet down rather than one instance.
483
+ */
484
+ private rotateAllInstanceLogs;
485
+ private pruneEventLog;
486
+ private openEventLog;
487
+ /**
488
+ * Report a fleet-level fault (not attributable to one instance) to the General
489
+ * topic, so the operator learns about it without reading daemon.log.
490
+ *
491
+ * Throttled per distinct message: an unhandled rejection typically comes from a
492
+ * loop (a poller, a repeating timer), and one channel message per occurrence
493
+ * would bury the topic — which is worse than silence. First occurrence goes out
494
+ * immediately, repeats are suppressed for THROTTLE_MS and then re-sent with a
495
+ * count.
496
+ *
497
+ * The log line is written by the caller regardless: if every adapter is down,
498
+ * the only notification path is the one that is broken.
499
+ */
500
+ notifyFleetError(text: string): void;
501
+ private static readonly FLEET_ERROR_THROTTLE_MS;
502
+ private fleetErrorNotices;
316
503
  notifyInstanceTopic(instanceName: string, text: string, extraOpts?: import("./channel/types.js").SendOpts): void;
317
504
  /** Send a "🛑 Cancel" button to the instance's topic/channel after delivery. */
318
505
  /**
@@ -322,8 +509,66 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
322
509
  */
323
510
  private handleSlashSave;
324
511
  /** Whether the instance currently has at least one live cancel button. */
512
+ /**
513
+ * A click on a cancel button, whether or not the fleet still tracks it.
514
+ *
515
+ * The old rule was "act only while an entry is live", which made a click on a
516
+ * button the fleet had forgotten a silent no-op — no cancel, no message, not
517
+ * even a log line. That is indistinguishable from a broken button, and it is
518
+ * what the "按鈕點了沒反應" reports were: the entry is briefly absent while a
519
+ * button is being replaced, and a delete that fails leaves the message on
520
+ * screen with no entry at all.
521
+ *
522
+ * So: honour the click if the instance is actually running, and say so plainly
523
+ * if it is not. The stale-click path is rate-limited because the original
524
+ * concern was real — a second click must not fire a second interrupt key at an
525
+ * instance that has already started a new turn.
526
+ */
527
+ private handleCancelClick;
325
528
  private hasCancelButton;
326
529
  sendCancelButton(instanceName: string, correlationId?: string): Promise<void>;
530
+ /**
531
+ * The cancel button's text for a given elapsed time.
532
+ *
533
+ * Below the threshold it keeps the original wording, so a normal quick answer
534
+ * looks exactly as it did before. Past it, the button doubles as the live
535
+ * progress indicator (#409) — the channel showed nothing at all during long work,
536
+ * and once the agent had replied once there was no sign it was still going.
537
+ */
538
+ static progressText(elapsedMs: number, activity?: string | null, minElapsedMs?: number): string;
539
+ /**
540
+ * Make a tool summary safe to paste into a channel message.
541
+ *
542
+ * The text is agent-controlled (it is built from tool inputs — file paths,
543
+ * shell commands), so it gets flattened to one line, capped, and stripped of
544
+ * the two Discord mass-mention triggers. Neither channel renders it with a
545
+ * parse mode, so no markup escaping is needed beyond that.
546
+ */
547
+ private static sanitizeActivity;
548
+ /**
549
+ * Remember what an instance is currently doing, for the progress line.
550
+ *
551
+ * Best-effort by design: only backends that expose a live activity feed report
552
+ * anything, and the progress line simply omits the detail for the rest. It is
553
+ * never used to decide anything — purely what the user is shown.
554
+ */
555
+ private cacheInstanceActivity;
556
+ /**
557
+ * Refresh the button's text in place while the instance keeps working.
558
+ *
559
+ * Uses `editAlert`, NOT `editMessage`: on Telegram the latter omits reply_markup,
560
+ * and the Bot API treats that as "clear the keyboard" — so editing with it would
561
+ * delete the very cancel button this is trying to keep alive.
562
+ */
563
+ /** Configured threshold before elapsed time appears, in ms. */
564
+ progressMinElapsedMs(): number;
565
+ private startProgressTicker;
566
+ /**
567
+ * After a reply: give the instance REPLY_RETIRE_GRACE_MS to resume working; if
568
+ * it has not, retire its button. Re-arming replaces the previous timer, so a
569
+ * burst of replies ends with exactly one pending check.
570
+ */
571
+ private armReplyGrace;
327
572
  /** Retire (delete) every cancel button belonging to an instance. */
328
573
  private retireInstanceButtons;
329
574
  /** Begin retiring one button (delete + bounded retry on failure). Idempotent:
@@ -333,6 +578,19 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
333
578
  private attemptButtonDelete;
334
579
  /** Clear an entry's timers (retry + idle-check) and drop it from the map. */
335
580
  private discardButton;
581
+ /**
582
+ * Mirror the live buttons to disk. The map is memory-only, so before this a
583
+ * fleet restart orphaned every button on screen: frozen "處理中…" text and a
584
+ * click that did nothing, forever. The ledger is tiny (a handful of rows) and
585
+ * written on every add/remove — no debounce needed at that rate.
586
+ */
587
+ private persistCancelButtons;
588
+ /**
589
+ * Delete the previous process's buttons. Runs once adapters are up: nothing
590
+ * from a previous fleet process can still be mid-turn from this process's
591
+ * point of view, so every ledger row is an orphan by definition.
592
+ */
593
+ private sweepOrphanedCancelButtons;
336
594
  /** Re-attempt a failed button delete up to CANCEL_BTN_MAX_RETRIES times. */
337
595
  private scheduleButtonRetry;
338
596
  /** Delete one button's message via its own adapter. Resolves on success,
@@ -416,6 +674,15 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
416
674
  /** Best-effort model list for `/model`: cached CLI env first, else live probe. Never throws. */
417
675
  private getModelOptions;
418
676
  /** `/model` slash handler (admin only). No arg → DC menu; `/model <name>` → apply directly. */
677
+ /** Label an effort choice, marking the one currently configured. */
678
+ private effortChoiceLabel;
679
+ private effortMenuHeader;
680
+ /** `/effort` — DC Select Menu, or apply directly when a level is given. */
681
+ private handleEffortSlash;
682
+ /** TG inline-keyboard effort menu. Returns null on success, else a fallback string. */
683
+ promptEffortMenu(instanceName: string, userId: string, channelId: string, adapter: ChannelAdapter, chatId: string, threadId?: string): Promise<string | null>;
684
+ /** Consume an `/effort` selection callback. Mirrors handleModelSelection. */
685
+ private handleEffortSelection;
419
686
  private handleModelSlash;
420
687
  /**
421
688
  * Show a TG inline-keyboard model-selection menu. Reuses the same
@@ -426,7 +693,43 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
426
693
  /** Consume a `/model` selection callback. Returns true for all model-select ids (incl. stale). */
427
694
  private handleModelSelection;
428
695
  /** Apply a model to an instance: runtime paste (claude-code) or persist + restart (others). */
696
+ /** AgEnD's canonical effort ladder, low → max. Backends expose a subset. */
697
+ static readonly EFFORT_LEVELS: readonly ["low", "medium", "high", "xhigh", "max"];
698
+ /** How this instance's backend applies an effort change. */
699
+ effortStrategyFor(instanceName: string): "runtime" | "restart" | "unsupported";
700
+ /** Effort levels this instance's backend actually accepts (empty = unsupported). */
701
+ effortLevelsFor(instanceName: string): string[];
702
+ /** Configured effort for an instance: per-instance, else fleet default, else none. */
703
+ resolveInstanceEffort(instanceName: string): {
704
+ effort: string | null;
705
+ source: "instance" | "fleet-default" | "unset";
706
+ };
707
+ /**
708
+ * Clamp a canonical level to the nearest one this backend supports.
709
+ *
710
+ * Clamping DOWN the ladder, never up: asking for `max` on a CLI that stops at
711
+ * `high` should get high, not silently fall to low. The caller reports the
712
+ * clamp — a user who asks for max and quietly receives high has been told the
713
+ * request succeeded when it did not.
714
+ */
715
+ static clampEffort(level: string, supported: string[]): string | null;
716
+ /**
717
+ * Apply a reasoning-effort level, mirroring applyModel's shape.
718
+ *
719
+ * runtime backends take `/effort <level>` in the pane and keep working;
720
+ * restart backends only read it at launch, so it is persisted and the
721
+ * instance respawns.
722
+ */
723
+ applyEffort(instanceName: string, requested: string): Promise<string>;
429
724
  applyModel(instanceName: string, model: string): Promise<string>;
725
+ /**
726
+ * The trailing "Current effort: …" line for a /model reply.
727
+ *
728
+ * Model and effort interact (a cheaper model at max effort is a different
729
+ * trade than a bigger one at low), so showing the effort in force right after
730
+ * a switch saves the round trip of asking. Empty when the backend has none.
731
+ */
732
+ private effortSuffix;
430
733
  /** Read recent chat log for agent context */
431
734
  private getRecentChatLog;
432
735
  /** Return a user-facing blocker without mutating ClassicBot state. */
@@ -447,7 +750,17 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
447
750
  handleClassicStart(channelId: string, channelName: string, userId: string, guildId?: string, adapterId?: string, backend?: string): Promise<string>;
448
751
  /** Handle /stop slash command — unregister classic channel */
449
752
  handleClassicStop(channelId: string, adapterId?: string): Promise<string>;
753
+ /**
754
+ * Idempotent while in flight: SIGINT and SIGTERM share one handler and the
755
+ * uncaughtException path calls this too, so overlapping runs were possible —
756
+ * each snapshotting the daemon map and calling stop() on the same daemons
757
+ * concurrently. Deliberately NOT `async`, so callers receive the same promise
758
+ * object rather than a fresh wrapper around it. The latch clears when the run
759
+ * settles, so a later genuine stop (after a restart) still does the work.
760
+ */
450
761
  stopAll(): Promise<void>;
762
+ private stopAllInFlight;
763
+ private doStopAll;
451
764
  /**
452
765
  * Prune stale external sessions by re-querying each daemon for live sessions.
453
766
  * Sessions in the registry that are no longer reported by any daemon are removed.