@songsid/agend 2.1.2-beta.2 → 2.1.2-beta.21
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.
- package/dist/access-path.js +15 -6
- package/dist/access-path.js.map +1 -1
- package/dist/agent-endpoint.d.ts +2 -0
- package/dist/agent-endpoint.js +17 -1
- package/dist/agent-endpoint.js.map +1 -1
- package/dist/backend/antigravity.d.ts +18 -0
- package/dist/backend/antigravity.js +32 -3
- package/dist/backend/antigravity.js.map +1 -1
- package/dist/backend/claude-code.d.ts +37 -0
- package/dist/backend/claude-code.js +43 -1
- package/dist/backend/claude-code.js.map +1 -1
- package/dist/backend/codex.d.ts +1 -0
- package/dist/backend/codex.js +25 -0
- package/dist/backend/codex.js.map +1 -1
- package/dist/backend/grok.d.ts +23 -0
- package/dist/backend/grok.js +45 -0
- package/dist/backend/grok.js.map +1 -1
- package/dist/backend/kiro.d.ts +20 -0
- package/dist/backend/kiro.js +77 -2
- package/dist/backend/kiro.js.map +1 -1
- package/dist/backend/types.d.ts +34 -0
- package/dist/backend/types.js +1 -1
- package/dist/backend/types.js.map +1 -1
- package/dist/channel/adapters/discord.d.ts +15 -0
- package/dist/channel/adapters/discord.js +91 -2
- package/dist/channel/adapters/discord.js.map +1 -1
- package/dist/channel/adapters/telegram.d.ts +21 -0
- package/dist/channel/adapters/telegram.js +82 -0
- package/dist/channel/adapters/telegram.js.map +1 -1
- package/dist/channel/ipc-bridge.d.ts +17 -1
- package/dist/channel/ipc-bridge.js +53 -17
- package/dist/channel/ipc-bridge.js.map +1 -1
- package/dist/channel/ipc-timeouts.d.ts +46 -0
- package/dist/channel/ipc-timeouts.js +65 -0
- package/dist/channel/ipc-timeouts.js.map +1 -0
- package/dist/channel/mcp-server.js +30 -14
- package/dist/channel/mcp-server.js.map +1 -1
- package/dist/channel/mcp-tools.js +28 -1
- package/dist/channel/mcp-tools.js.map +1 -1
- package/dist/channel/reconnect-backoff.d.ts +17 -0
- package/dist/channel/reconnect-backoff.js +21 -0
- package/dist/channel/reconnect-backoff.js.map +1 -0
- package/dist/channel/types.d.ts +29 -0
- package/dist/classic-channel-manager.js +1 -5
- package/dist/classic-channel-manager.js.map +1 -1
- package/dist/cli.js +132 -52
- package/dist/cli.js.map +1 -1
- package/dist/completion.d.ts +27 -0
- package/dist/completion.js +121 -0
- package/dist/completion.js.map +1 -0
- package/dist/config-validator.js +9 -0
- package/dist/config-validator.js.map +1 -1
- package/dist/config.js +1 -0
- package/dist/config.js.map +1 -1
- package/dist/cost-guard.d.ts +3 -1
- package/dist/cost-guard.js +3 -1
- package/dist/cost-guard.js.map +1 -1
- package/dist/daemon.d.ts +219 -13
- package/dist/daemon.js +919 -303
- package/dist/daemon.js.map +1 -1
- package/dist/event-log.d.ts +31 -0
- package/dist/event-log.js +96 -0
- package/dist/event-log.js.map +1 -1
- package/dist/fleet-manager.d.ts +238 -2
- package/dist/fleet-manager.js +1008 -90
- package/dist/fleet-manager.js.map +1 -1
- package/dist/general-knowledge/skills/cross-instance-messaging/SKILL.md +22 -0
- package/dist/general-knowledge/skills/model-discovery/SKILL.md +14 -23
- package/dist/general-knowledge/skills/session-management/SKILL.md +15 -34
- package/dist/hang-detector.d.ts +19 -13
- package/dist/hang-detector.js +19 -49
- package/dist/hang-detector.js.map +1 -1
- package/dist/instance-lifecycle.d.ts +13 -1
- package/dist/instance-lifecycle.js +84 -3
- package/dist/instance-lifecycle.js.map +1 -1
- package/dist/instructions.d.ts +5 -0
- package/dist/instructions.js +9 -11
- package/dist/instructions.js.map +1 -1
- package/dist/locale.js +2 -1
- package/dist/locale.js.map +1 -1
- package/dist/logger.js +14 -0
- package/dist/logger.js.map +1 -1
- package/dist/mcp-liveness.d.ts +21 -0
- package/dist/mcp-liveness.js +27 -0
- package/dist/mcp-liveness.js.map +1 -0
- package/dist/outbound-handlers.d.ts +16 -0
- package/dist/outbound-handlers.js +121 -27
- package/dist/outbound-handlers.js.map +1 -1
- package/dist/outbound-schemas.d.ts +8 -3
- package/dist/outbound-schemas.js +13 -2
- package/dist/outbound-schemas.js.map +1 -1
- package/dist/pane-write-lock.d.ts +48 -0
- package/dist/pane-write-lock.js +73 -0
- package/dist/pane-write-lock.js.map +1 -0
- package/dist/process-memory.d.ts +31 -0
- package/dist/process-memory.js +79 -0
- package/dist/process-memory.js.map +1 -0
- package/dist/quickstart.js +17 -16
- package/dist/quickstart.js.map +1 -1
- package/dist/reply-dedup.d.ts +41 -0
- package/dist/reply-dedup.js +0 -0
- package/dist/reply-dedup.js.map +1 -0
- package/dist/scheduler/db.js +3 -0
- package/dist/scheduler/db.js.map +1 -1
- package/dist/sd-notify.d.ts +27 -0
- package/dist/sd-notify.js +33 -1
- package/dist/sd-notify.js.map +1 -1
- package/dist/secret-file.d.ts +33 -0
- package/dist/secret-file.js +36 -0
- package/dist/secret-file.js.map +1 -0
- package/dist/setup-wizard.js +9 -7
- package/dist/setup-wizard.js.map +1 -1
- package/dist/tmux-control.d.ts +58 -5
- package/dist/tmux-control.js +102 -14
- package/dist/tmux-control.js.map +1 -1
- package/dist/tmux-manager.d.ts +31 -1
- package/dist/tmux-manager.js +40 -11
- package/dist/tmux-manager.js.map +1 -1
- package/dist/topic-commands.d.ts +50 -10
- package/dist/topic-commands.js +242 -106
- package/dist/topic-commands.js.map +1 -1
- package/dist/tui-glyphs.d.ts +25 -0
- package/dist/tui-glyphs.js +26 -0
- package/dist/tui-glyphs.js.map +1 -0
- package/dist/types.d.ts +6 -0
- package/dist/ui/view.html +123 -2
- package/dist/usage/format-rich.d.ts +11 -0
- package/dist/usage/format-rich.js +108 -0
- package/dist/usage/format-rich.js.map +1 -0
- package/dist/usage/providers.d.ts +97 -0
- package/dist/usage/providers.js +834 -0
- package/dist/usage/providers.js.map +1 -0
- package/dist/usage/usage-api.d.ts +50 -0
- package/dist/usage/usage-api.js +111 -0
- package/dist/usage/usage-api.js.map +1 -0
- package/dist/view-api.d.ts +3 -0
- package/dist/view-api.js +11 -2
- package/dist/view-api.js.map +1 -1
- package/dist/web-api.js +5 -2
- package/dist/web-api.js.map +1 -1
- package/package.json +4 -1
- package/dist/channel/tool-tracker.d.ts +0 -13
- package/dist/channel/tool-tracker.js +0 -58
- package/dist/channel/tool-tracker.js.map +0 -1
- package/dist/daemon-entry.d.ts +0 -1
- package/dist/daemon-entry.js +0 -30
- package/dist/daemon-entry.js.map +0 -1
package/dist/event-log.js
CHANGED
|
@@ -13,6 +13,10 @@ export class EventLog {
|
|
|
13
13
|
constructor(dbPath) {
|
|
14
14
|
this.db = new Database(dbPath);
|
|
15
15
|
this.db.pragma("journal_mode = WAL");
|
|
16
|
+
// The fleet writes this file while `agend events` / `agend activity` read it
|
|
17
|
+
// from a separate process. Without a busy timeout, either side raises
|
|
18
|
+
// SQLITE_BUSY immediately instead of waiting for the other's write to finish.
|
|
19
|
+
this.db.pragma("busy_timeout = 5000");
|
|
16
20
|
this.db.exec(`
|
|
17
21
|
CREATE TABLE IF NOT EXISTS events (
|
|
18
22
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -25,6 +29,24 @@ export class EventLog {
|
|
|
25
29
|
CREATE INDEX IF NOT EXISTS idx_events_type ON events(event_type, created_at);
|
|
26
30
|
`);
|
|
27
31
|
this.insertStmt = this.db.prepare("INSERT INTO events (instance_name, event_type, payload) VALUES (?, ?, ?)");
|
|
32
|
+
// Reaction queue (#432 rework of #408/#413). A reaction is context, not a
|
|
33
|
+
// message: it no longer triggers an agent turn. It waits here until the next
|
|
34
|
+
// REAL message to the same instance, rides in as one compact context line,
|
|
35
|
+
// and is then marked consumed. consumed_at stays (rather than DELETE) so a
|
|
36
|
+
// delivery that fails after summarising does not lose the reactions — they
|
|
37
|
+
// are only marked once the message actually went out.
|
|
38
|
+
this.db.exec(`
|
|
39
|
+
CREATE TABLE IF NOT EXISTS reactions (
|
|
40
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
41
|
+
instance_name TEXT NOT NULL,
|
|
42
|
+
message_id TEXT NOT NULL,
|
|
43
|
+
username TEXT NOT NULL,
|
|
44
|
+
emoji TEXT NOT NULL,
|
|
45
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
46
|
+
consumed_at TEXT
|
|
47
|
+
);
|
|
48
|
+
CREATE INDEX IF NOT EXISTS idx_reactions_pending ON reactions(instance_name, consumed_at);
|
|
49
|
+
`);
|
|
28
50
|
// Activity log for visualization
|
|
29
51
|
this.db.exec(`
|
|
30
52
|
CREATE TABLE IF NOT EXISTS activity (
|
|
@@ -92,6 +114,80 @@ export class EventLog {
|
|
|
92
114
|
this.db
|
|
93
115
|
.prepare("DELETE FROM activity WHERE timestamp < datetime('now', ?)")
|
|
94
116
|
.run(`-${days} days`);
|
|
117
|
+
// Reactions have their own, shorter horizon: after REACTION_RETENTION_DAYS a
|
|
118
|
+
// pending reaction is stale context nobody should be shown, consumed or not.
|
|
119
|
+
this.db
|
|
120
|
+
.prepare("DELETE FROM reactions WHERE created_at < datetime('now', ?)")
|
|
121
|
+
.run(`-${EventLog.REACTION_RETENTION_DAYS} days`);
|
|
122
|
+
}
|
|
123
|
+
static REACTION_RETENTION_DAYS = 7;
|
|
124
|
+
/** Queue a reaction for the instance's next real message. */
|
|
125
|
+
addReaction(instance, messageId, username, emoji) {
|
|
126
|
+
this.db
|
|
127
|
+
.prepare("INSERT INTO reactions (instance_name, message_id, username, emoji) VALUES (?, ?, ?, ?)")
|
|
128
|
+
.run(instance, messageId, username, emoji);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* A withdrawn reaction is withdrawn context. Deleting the matching pending row
|
|
132
|
+
* (newest first, one per removal) means an add-then-remove nets out to nothing,
|
|
133
|
+
* instead of reporting a 👍 the user visibly took back. Already-consumed rows
|
|
134
|
+
* are left alone — the agent has seen those; history does not un-happen.
|
|
135
|
+
*/
|
|
136
|
+
removeReaction(instance, messageId, username, emoji) {
|
|
137
|
+
this.db
|
|
138
|
+
.prepare(`DELETE FROM reactions WHERE id = (
|
|
139
|
+
SELECT id FROM reactions
|
|
140
|
+
WHERE instance_name = ? AND message_id = ? AND username = ? AND emoji = ? AND consumed_at IS NULL
|
|
141
|
+
ORDER BY id DESC LIMIT 1
|
|
142
|
+
)`)
|
|
143
|
+
.run(instance, messageId, username, emoji);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Pending reactions as compact context, grouped by the message they landed on:
|
|
147
|
+
*
|
|
148
|
+
* msg 1532964272244523028: 👍×2 from hanhanv, ❓ from user2 | msg 1532965…: 👍 from hanhanv
|
|
149
|
+
*
|
|
150
|
+
* The message id is the point (#433): the agent's inbound blocks render each of
|
|
151
|
+
* its own messages' ids, so carrying the id is what lets it tell WHICH of its
|
|
152
|
+
* messages was reacted to. Within a message, duplicates of the same emoji from
|
|
153
|
+
* the same user collapse to ×N (a re-added reaction is not new information).
|
|
154
|
+
*
|
|
155
|
+
* Returns null (not an empty string) when there is nothing pending, so callers
|
|
156
|
+
* add zero context in the common case. `maxId` is what the caller hands back to
|
|
157
|
+
* markReactionsConsumed — bounding by id keeps a reaction that arrives DURING
|
|
158
|
+
* delivery pending for the next message instead of being silently eaten.
|
|
159
|
+
*/
|
|
160
|
+
pendingReactions(instance) {
|
|
161
|
+
const rows = this.db
|
|
162
|
+
.prepare("SELECT id, message_id, username, emoji FROM reactions WHERE instance_name = ? AND consumed_at IS NULL ORDER BY id")
|
|
163
|
+
.all(instance);
|
|
164
|
+
if (rows.length === 0)
|
|
165
|
+
return null;
|
|
166
|
+
// message_id → (emoji+user → count), both insertion-ordered so the summary
|
|
167
|
+
// reads in arrival order.
|
|
168
|
+
const byMessage = new Map();
|
|
169
|
+
for (const row of rows) {
|
|
170
|
+
const counts = byMessage.get(row.message_id) ?? new Map();
|
|
171
|
+
const key = `${row.emoji}\u0000${row.username}`;
|
|
172
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
173
|
+
byMessage.set(row.message_id, counts);
|
|
174
|
+
}
|
|
175
|
+
const groups = [];
|
|
176
|
+
for (const [messageId, counts] of byMessage) {
|
|
177
|
+
const parts = [];
|
|
178
|
+
for (const [key, count] of counts) {
|
|
179
|
+
const [emoji, username] = key.split("\u0000");
|
|
180
|
+
parts.push(count > 1 ? `${emoji}×${count} from ${username}` : `${emoji} from ${username}`);
|
|
181
|
+
}
|
|
182
|
+
groups.push(`msg ${messageId}: ${parts.join(", ")}`);
|
|
183
|
+
}
|
|
184
|
+
return { summary: groups.join(" | "), maxId: rows[rows.length - 1].id };
|
|
185
|
+
}
|
|
186
|
+
/** Mark reactions up to `maxId` as shown. Call only after the delivery succeeded. */
|
|
187
|
+
markReactionsConsumed(instance, maxId) {
|
|
188
|
+
this.db
|
|
189
|
+
.prepare("UPDATE reactions SET consumed_at = datetime('now') WHERE instance_name = ? AND id <= ? AND consumed_at IS NULL")
|
|
190
|
+
.run(instance, maxId);
|
|
95
191
|
}
|
|
96
192
|
close() {
|
|
97
193
|
this.db.close();
|
package/dist/event-log.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-log.js","sourceRoot":"","sources":["../src/event-log.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAmCtC,SAAS,aAAa,CAAC,CAAS;IAC9B,IAAI,CAAC;QAAC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAA4B,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC;QAAC,OAAO,IAAI,CAAC;IAAC,CAAC;AACjF,CAAC;AAED,MAAM,OAAO,QAAQ;IACX,EAAE,CAAoB;IACtB,UAAU,CAAqB;IAEvC,YAAY,MAAc;QACxB,IAAI,CAAC,EAAE,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC/B,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;QACrC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC;;;;;;;;;;KAUZ,CAAC,CAAC;QACH,IAAI,CAAC,UAA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IACrF,qBAAqB,CAAC,QAAgB,EAAE,KAAa;QACnD,IAAI,CAAC,EAAE;aACJ,OAAO,CAAC,gHAAgH,CAAC;aACzH,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC1B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC"}
|
package/dist/fleet-manager.d.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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,6 +100,12 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
|
|
|
98
100
|
private instanceIdleWaiters;
|
|
99
101
|
private lastInboundUser;
|
|
100
102
|
private cancelButtons;
|
|
103
|
+
/** Duplicate-reply suppression across both the MCP and HTTP reply paths. */
|
|
104
|
+
readonly replyDeduper: ReplyDeduper;
|
|
105
|
+
/** instanceName → what it is doing right now, when the backend can tell us. */
|
|
106
|
+
private instanceActivity;
|
|
107
|
+
/** instanceName → tail of deliveries waiting for its IPC to come back. */
|
|
108
|
+
private ipcWaitTails;
|
|
101
109
|
private lastInboundMsg;
|
|
102
110
|
private topicArchiver;
|
|
103
111
|
controlClient: TmuxControlClient | null;
|
|
@@ -107,12 +115,20 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
|
|
|
107
115
|
private pendingModelSelects;
|
|
108
116
|
private failoverActive;
|
|
109
117
|
readonly ipcStoppingInstances: Set<string>;
|
|
118
|
+
/** Coalesce concurrent connection attempts for the same daemon socket. */
|
|
119
|
+
private ipcConnectInFlight;
|
|
120
|
+
/** At most one reconnect/backoff loop may exist per instance. */
|
|
121
|
+
private ipcReconnectInFlight;
|
|
110
122
|
private adapterRestarting;
|
|
111
123
|
private adapterState;
|
|
112
124
|
private collabInstances;
|
|
113
125
|
private healthServer;
|
|
114
126
|
private healthPortRetried;
|
|
115
127
|
private updateCheckTimer;
|
|
128
|
+
private eventLogPruneTimer;
|
|
129
|
+
private logRotateTimer;
|
|
130
|
+
/** Days of event/activity history to keep. */
|
|
131
|
+
private static readonly EVENT_LOG_RETENTION_DAYS;
|
|
116
132
|
private watchdogTimer;
|
|
117
133
|
private startedAt;
|
|
118
134
|
private mirrorBuffer;
|
|
@@ -125,7 +141,26 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
|
|
|
125
141
|
private scheduleReconcile;
|
|
126
142
|
private finishStartup;
|
|
127
143
|
lastActivityMs(name: string): number;
|
|
144
|
+
/**
|
|
145
|
+
* Is the instance between turns?
|
|
146
|
+
*
|
|
147
|
+
* Prefers the daemon's pane state machine (debounced, busy-pattern aware) over
|
|
148
|
+
* the control client's raw 2-second output-silence heuristic. The raw heuristic
|
|
149
|
+
* reads every >2s output lull as idle — and long silent tools (a build, a test
|
|
150
|
+
* run) or an LLM pause produce those constantly mid-turn. That misreading is
|
|
151
|
+
* what retired cancel buttons in the middle of long work (the 5-minute backstop
|
|
152
|
+
* fired during a lull) and froze their progress text (ticker skipped "idle"
|
|
153
|
+
* ticks). The silence heuristic remains only as the fallback for instances
|
|
154
|
+
* whose daemon has not reported a state yet.
|
|
155
|
+
*/
|
|
128
156
|
private getInstanceIdle;
|
|
157
|
+
/**
|
|
158
|
+
* True when the instance claims working/stuck but nothing has refreshed that
|
|
159
|
+
* claim for STATE_REPORT_STALE_MS despite the backstop's per-tick queries.
|
|
160
|
+
* Measures the CACHE's age, not the button's — a healthy multi-hour run
|
|
161
|
+
* answers every query and never trips this.
|
|
162
|
+
*/
|
|
163
|
+
private stateReportDead;
|
|
129
164
|
webhookEmit(event: string, name: string, data?: Record<string, unknown>): void;
|
|
130
165
|
getSysInfo(): import("./fleet-context.js").SysInfo;
|
|
131
166
|
/** Load fleet.yaml and build routing table */
|
|
@@ -193,6 +228,25 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
|
|
|
193
228
|
private enforceWarmCap;
|
|
194
229
|
private waitForInstanceIdle;
|
|
195
230
|
private deliverWithIdleGate;
|
|
231
|
+
/**
|
|
232
|
+
* Hand a payload to an instance's IPC, waiting out a *transient* disconnect.
|
|
233
|
+
*
|
|
234
|
+
* A daemon that is restarting — `/restart`, crash recovery, a model switch —
|
|
235
|
+
* drops its socket for a few seconds. Any message arriving in that window used
|
|
236
|
+
* to fail instantly: the caller logged a warning, put ❌ on the user's message,
|
|
237
|
+
* and the message was gone. The user had to notice the ❌ and retype it. That is
|
|
238
|
+
* the "instance 訊息不容易掉" goal failing on the most predictable event there is.
|
|
239
|
+
*
|
|
240
|
+
* The wait is bounded. If the instance is genuinely down, this still throws and
|
|
241
|
+
* the ❌ still appears — just for a real failure rather than a restart.
|
|
242
|
+
*
|
|
243
|
+
* Ordering is preserved by serialising behind any waiter already queued for this
|
|
244
|
+
* instance, *including* when the socket happens to be up: otherwise a message
|
|
245
|
+
* arriving after the reconnect could overtake one that has been waiting for it.
|
|
246
|
+
*/
|
|
247
|
+
private sendWhenConnected;
|
|
248
|
+
/** Poll for the instance's IPC to come back, then send. Throws if it does not. */
|
|
249
|
+
private sendAfterIpcReturns;
|
|
196
250
|
/** Single delivery facade: wake paused CLIs and serialize non-user work behind idle. */
|
|
197
251
|
deliverToInstance(instanceName: string, payload: Record<string, unknown>, options?: DeliveryOptions): Promise<void>;
|
|
198
252
|
/** Fleet admin is an explicit config allowlist entry, not merely an open/paired user. */
|
|
@@ -200,7 +254,7 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
|
|
|
200
254
|
changeInstancePauseState(name: string, action: "pause" | "wake"): Promise<"paused" | "awake" | "not_idle">;
|
|
201
255
|
/** Apply a Settings edit to a ClassicBot channel without waiting for the poller. */
|
|
202
256
|
restartClassicInstanceFromSettings(instanceName: string): Promise<void>;
|
|
203
|
-
startInstance(name: string, config: InstanceConfig, topicMode: boolean): Promise<void>;
|
|
257
|
+
startInstance(name: string, config: InstanceConfig, topicMode: boolean, kind?: "fleet-topic" | "classic"): Promise<void>;
|
|
204
258
|
/** Recreate a daemon for a marker-only paused instance after an explicit wake/delivery. */
|
|
205
259
|
startPersistedPausedInstance(name: string): Promise<void>;
|
|
206
260
|
/**
|
|
@@ -247,18 +301,73 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
|
|
|
247
301
|
retryCount: number;
|
|
248
302
|
lastError?: string;
|
|
249
303
|
}>;
|
|
304
|
+
/**
|
|
305
|
+
* Real, checkable fleet health for `/health` and the operator.
|
|
306
|
+
*
|
|
307
|
+
* `status` is:
|
|
308
|
+
* - `ok` — at least one adapter connected and every configured instance
|
|
309
|
+
* that should be running is running
|
|
310
|
+
* - `degraded` — reachable, but something the operator should look at (an
|
|
311
|
+
* adapter retrying, an instance crashed or stopped)
|
|
312
|
+
* - `down` — the fleet cannot do its job: no adapter is connected, so no
|
|
313
|
+
* message can arrive or be answered
|
|
314
|
+
*
|
|
315
|
+
* Deliberately does NOT gate the systemd watchdog — see the comment at the
|
|
316
|
+
* WATCHDOG timer for why.
|
|
317
|
+
*/
|
|
318
|
+
getFleetHealth(): {
|
|
319
|
+
status: "ok" | "degraded" | "down";
|
|
320
|
+
uptime: number;
|
|
321
|
+
instances: {
|
|
322
|
+
configured: number;
|
|
323
|
+
running: number;
|
|
324
|
+
crashed: number;
|
|
325
|
+
paused: number;
|
|
326
|
+
stopped: number;
|
|
327
|
+
};
|
|
328
|
+
adapters: {
|
|
329
|
+
total: number;
|
|
330
|
+
connected: number;
|
|
331
|
+
states: Record<string, string>;
|
|
332
|
+
};
|
|
333
|
+
startupComplete: boolean;
|
|
334
|
+
/** See process-memory.ts: the fleet process and the whole service cgroup are
|
|
335
|
+
* reported separately because they differ by ~60x and only one of them can
|
|
336
|
+
* show a fleet-manager leak. */
|
|
337
|
+
memory: FleetMemory;
|
|
338
|
+
problems: string[];
|
|
339
|
+
};
|
|
250
340
|
/** Start the primary adapter (backward-compatible, sets this.adapter) */
|
|
251
341
|
private startSingleAdapter;
|
|
252
342
|
/** Start an additional (non-primary) adapter */
|
|
253
343
|
private startAdditionalAdapter;
|
|
254
344
|
/** Connect IPC to a single instance with all handlers */
|
|
255
345
|
connectIpcToInstance(name: string): Promise<void>;
|
|
346
|
+
private connectIpcToInstanceInternal;
|
|
256
347
|
/** Attempt IPC reconnection with exponential backoff */
|
|
257
348
|
private ipcReconnect;
|
|
349
|
+
private runIpcReconnect;
|
|
258
350
|
/** Restart a channel adapter after fatal error with infinite retry + 60s cap */
|
|
259
351
|
private restartAdapter;
|
|
260
352
|
/** Handle inbound message — transcribe voice if present, then route */
|
|
261
353
|
private findGeneralInstance;
|
|
354
|
+
/**
|
|
355
|
+
* A user reacted to one of the bot's messages (#408).
|
|
356
|
+
*
|
|
357
|
+
* A reaction is context, not a message (#432, reworking #413): it never triggers
|
|
358
|
+
* an agent turn and never wakes anything. It is queued in the event log and rides
|
|
359
|
+
* into the instance's NEXT real message as one compact leading line —
|
|
360
|
+
* `[Recent reactions: 👍×2 from hanhanv]` — after which it is marked consumed.
|
|
361
|
+
* No pending reactions → no line → zero context spent, which is the common case.
|
|
362
|
+
*/
|
|
363
|
+
private handleInboundReaction;
|
|
364
|
+
/**
|
|
365
|
+
* The queued-reaction summary for an instance's next real message, or {} when
|
|
366
|
+
* nothing is pending (the common case must add zero context). The consume
|
|
367
|
+
* callback is separate from the fetch so reactions are only marked once the
|
|
368
|
+
* message actually went out — a failed delivery keeps them queued.
|
|
369
|
+
*/
|
|
370
|
+
private pendingReactionsMeta;
|
|
262
371
|
private handleInboundMessage;
|
|
263
372
|
/** Handle outbound tool calls from a daemon instance */
|
|
264
373
|
/** Warn (but don't block) when rate limits are high. 30-min debounce per instance. */
|
|
@@ -266,6 +375,8 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
|
|
|
266
375
|
private warnIfRateLimited;
|
|
267
376
|
/** Handle outbound tool calls from a daemon instance */
|
|
268
377
|
private handleOutboundFromInstance;
|
|
378
|
+
/** Side effects of a routed reply: cancel-button lifecycle, logs, SSE, chat log. */
|
|
379
|
+
private afterReplyRouted;
|
|
269
380
|
/** Handle tool status update from a daemon instance */
|
|
270
381
|
private handleToolStatusFromInstance;
|
|
271
382
|
private handleScheduleTrigger;
|
|
@@ -307,6 +418,68 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
|
|
|
307
418
|
private static FAILOVER_RECOVER_PCT;
|
|
308
419
|
checkModelFailover(name: string, fiveHourPct: number): void;
|
|
309
420
|
toggleFleetCollab(instanceName: string): boolean;
|
|
421
|
+
/**
|
|
422
|
+
* Open the event log, tolerating a corrupt file.
|
|
423
|
+
*
|
|
424
|
+
* `events.db` holds history only — event rows and the activity feed. Nothing the
|
|
425
|
+
* fleet needs to run depends on it, and every consumer already uses
|
|
426
|
+
* `this.eventLog?.`. An unguarded `new EventLog(...)` here meant a corrupt or
|
|
427
|
+
* unreadable history file (a truncated WAL after a hard kill, a full disk)
|
|
428
|
+
* threw during startAll and the WHOLE FLEET FAILED TO BOOT — trading every
|
|
429
|
+
* running agent for a file whose only job is reporting.
|
|
430
|
+
*
|
|
431
|
+
* So: try, move a bad file aside and retry once with a fresh one, and if even
|
|
432
|
+
* that fails carry on without an event log.
|
|
433
|
+
*/
|
|
434
|
+
/**
|
|
435
|
+
* Run `agend backend doctor` for the fleet's default backend and return its
|
|
436
|
+
* cleaned output.
|
|
437
|
+
*
|
|
438
|
+
* Async on purpose: this was `execSync` with a 30s timeout, reachable by any
|
|
439
|
+
* allowlisted user through `/doctor`. While it ran, the entire fleet event loop
|
|
440
|
+
* was frozen — no IPC, no adapter, no message delivery, no health responses,
|
|
441
|
+
* and critically no WATCHDOG ping, so a slow doctor could push past
|
|
442
|
+
* WatchdogSec and have systemd SIGABRT the fleet.
|
|
443
|
+
*/
|
|
444
|
+
private runBackendDoctor;
|
|
445
|
+
/** Drop event/activity rows older than the retention window. Best-effort. */
|
|
446
|
+
/**
|
|
447
|
+
* Cap every instance's pipe-pane log, walking the instances **directory** rather
|
|
448
|
+
* than the config.
|
|
449
|
+
*
|
|
450
|
+
* A running instance rotates its own log on each health tick, so the ones that
|
|
451
|
+
* need this are the ones nothing else looks at:
|
|
452
|
+
*
|
|
453
|
+
* - deleted instances, whose directory outlives the config entry. Nothing ever
|
|
454
|
+
* touched these again. On the machine this was found on, one held 122 MB and
|
|
455
|
+
* another 74 MB, out of 622 MB of pipe-pane logs in total.
|
|
456
|
+
* - classic instances, which live in classicChannels, not fleetConfig.instances,
|
|
457
|
+
* and so were never in the old config-driven loop at all.
|
|
458
|
+
* - stopped instances, which have no health tick running.
|
|
459
|
+
*
|
|
460
|
+
* pipe-pane writes raw TUI output, so a wedged splash screen can emit ANSI frames
|
|
461
|
+
* at animation rate. Unbounded growth here fills the disk, which takes the whole
|
|
462
|
+
* fleet down rather than one instance.
|
|
463
|
+
*/
|
|
464
|
+
private rotateAllInstanceLogs;
|
|
465
|
+
private pruneEventLog;
|
|
466
|
+
private openEventLog;
|
|
467
|
+
/**
|
|
468
|
+
* Report a fleet-level fault (not attributable to one instance) to the General
|
|
469
|
+
* topic, so the operator learns about it without reading daemon.log.
|
|
470
|
+
*
|
|
471
|
+
* Throttled per distinct message: an unhandled rejection typically comes from a
|
|
472
|
+
* loop (a poller, a repeating timer), and one channel message per occurrence
|
|
473
|
+
* would bury the topic — which is worse than silence. First occurrence goes out
|
|
474
|
+
* immediately, repeats are suppressed for THROTTLE_MS and then re-sent with a
|
|
475
|
+
* count.
|
|
476
|
+
*
|
|
477
|
+
* The log line is written by the caller regardless: if every adapter is down,
|
|
478
|
+
* the only notification path is the one that is broken.
|
|
479
|
+
*/
|
|
480
|
+
notifyFleetError(text: string): void;
|
|
481
|
+
private static readonly FLEET_ERROR_THROTTLE_MS;
|
|
482
|
+
private fleetErrorNotices;
|
|
310
483
|
notifyInstanceTopic(instanceName: string, text: string, extraOpts?: import("./channel/types.js").SendOpts): void;
|
|
311
484
|
/** Send a "🛑 Cancel" button to the instance's topic/channel after delivery. */
|
|
312
485
|
/**
|
|
@@ -318,6 +491,46 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
|
|
|
318
491
|
/** Whether the instance currently has at least one live cancel button. */
|
|
319
492
|
private hasCancelButton;
|
|
320
493
|
sendCancelButton(instanceName: string, correlationId?: string): Promise<void>;
|
|
494
|
+
/**
|
|
495
|
+
* The cancel button's text for a given elapsed time.
|
|
496
|
+
*
|
|
497
|
+
* Below the threshold it keeps the original wording, so a normal quick answer
|
|
498
|
+
* looks exactly as it did before. Past it, the button doubles as the live
|
|
499
|
+
* progress indicator (#409) — the channel showed nothing at all during long work,
|
|
500
|
+
* and once the agent had replied once there was no sign it was still going.
|
|
501
|
+
*/
|
|
502
|
+
static progressText(elapsedMs: number, activity?: string | null): string;
|
|
503
|
+
/**
|
|
504
|
+
* Make a tool summary safe to paste into a channel message.
|
|
505
|
+
*
|
|
506
|
+
* The text is agent-controlled (it is built from tool inputs — file paths,
|
|
507
|
+
* shell commands), so it gets flattened to one line, capped, and stripped of
|
|
508
|
+
* the two Discord mass-mention triggers. Neither channel renders it with a
|
|
509
|
+
* parse mode, so no markup escaping is needed beyond that.
|
|
510
|
+
*/
|
|
511
|
+
private static sanitizeActivity;
|
|
512
|
+
/**
|
|
513
|
+
* Remember what an instance is currently doing, for the progress line.
|
|
514
|
+
*
|
|
515
|
+
* Best-effort by design: only backends that expose a live activity feed report
|
|
516
|
+
* anything, and the progress line simply omits the detail for the rest. It is
|
|
517
|
+
* never used to decide anything — purely what the user is shown.
|
|
518
|
+
*/
|
|
519
|
+
private cacheInstanceActivity;
|
|
520
|
+
/**
|
|
521
|
+
* Refresh the button's text in place while the instance keeps working.
|
|
522
|
+
*
|
|
523
|
+
* Uses `editAlert`, NOT `editMessage`: on Telegram the latter omits reply_markup,
|
|
524
|
+
* and the Bot API treats that as "clear the keyboard" — so editing with it would
|
|
525
|
+
* delete the very cancel button this is trying to keep alive.
|
|
526
|
+
*/
|
|
527
|
+
private startProgressTicker;
|
|
528
|
+
/**
|
|
529
|
+
* After a reply: give the instance REPLY_RETIRE_GRACE_MS to resume working; if
|
|
530
|
+
* it has not, retire its button. Re-arming replaces the previous timer, so a
|
|
531
|
+
* burst of replies ends with exactly one pending check.
|
|
532
|
+
*/
|
|
533
|
+
private armReplyGrace;
|
|
321
534
|
/** Retire (delete) every cancel button belonging to an instance. */
|
|
322
535
|
private retireInstanceButtons;
|
|
323
536
|
/** Begin retiring one button (delete + bounded retry on failure). Idempotent:
|
|
@@ -327,6 +540,19 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
|
|
|
327
540
|
private attemptButtonDelete;
|
|
328
541
|
/** Clear an entry's timers (retry + idle-check) and drop it from the map. */
|
|
329
542
|
private discardButton;
|
|
543
|
+
/**
|
|
544
|
+
* Mirror the live buttons to disk. The map is memory-only, so before this a
|
|
545
|
+
* fleet restart orphaned every button on screen: frozen "處理中…" text and a
|
|
546
|
+
* click that did nothing, forever. The ledger is tiny (a handful of rows) and
|
|
547
|
+
* written on every add/remove — no debounce needed at that rate.
|
|
548
|
+
*/
|
|
549
|
+
private persistCancelButtons;
|
|
550
|
+
/**
|
|
551
|
+
* Delete the previous process's buttons. Runs once adapters are up: nothing
|
|
552
|
+
* from a previous fleet process can still be mid-turn from this process's
|
|
553
|
+
* point of view, so every ledger row is an orphan by definition.
|
|
554
|
+
*/
|
|
555
|
+
private sweepOrphanedCancelButtons;
|
|
330
556
|
/** Re-attempt a failed button delete up to CANCEL_BTN_MAX_RETRIES times. */
|
|
331
557
|
private scheduleButtonRetry;
|
|
332
558
|
/** Delete one button's message via its own adapter. Resolves on success,
|
|
@@ -441,7 +667,17 @@ export declare class FleetManager implements FleetContext, LifecycleContext, Arc
|
|
|
441
667
|
handleClassicStart(channelId: string, channelName: string, userId: string, guildId?: string, adapterId?: string, backend?: string): Promise<string>;
|
|
442
668
|
/** Handle /stop slash command — unregister classic channel */
|
|
443
669
|
handleClassicStop(channelId: string, adapterId?: string): Promise<string>;
|
|
670
|
+
/**
|
|
671
|
+
* Idempotent while in flight: SIGINT and SIGTERM share one handler and the
|
|
672
|
+
* uncaughtException path calls this too, so overlapping runs were possible —
|
|
673
|
+
* each snapshotting the daemon map and calling stop() on the same daemons
|
|
674
|
+
* concurrently. Deliberately NOT `async`, so callers receive the same promise
|
|
675
|
+
* object rather than a fresh wrapper around it. The latch clears when the run
|
|
676
|
+
* settles, so a later genuine stop (after a restart) still does the work.
|
|
677
|
+
*/
|
|
444
678
|
stopAll(): Promise<void>;
|
|
679
|
+
private stopAllInFlight;
|
|
680
|
+
private doStopAll;
|
|
445
681
|
/**
|
|
446
682
|
* Prune stale external sessions by re-querying each daemon for live sessions.
|
|
447
683
|
* Sessions in the registry that are no longer reported by any daemon are removed.
|