@koalaauto/agentchannel 3.99.0 → 3.99.2
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/src/attention.d.ts +27 -0
- package/dist/src/attention.js +51 -0
- package/dist/src/cli.js +1 -1
- package/dist/src/client.d.ts +1 -0
- package/dist/src/client.js +1 -1
- package/dist/src/mcp.d.ts +10 -7
- package/dist/src/mcp.js +42 -15
- package/dist/src/pool.d.ts +8 -7
- package/dist/src/pool.js +36 -25
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +1 -1
package/dist/src/attention.d.ts
CHANGED
|
@@ -35,6 +35,33 @@ export declare function noticeText(a: Attention, lang?: 'en' | 'zh'): string;
|
|
|
35
35
|
/** One confirmation, for the person and for the session that answers for them (`decide` with the request id and the answer). Pure. */
|
|
36
36
|
export declare function confirmationText(c: Confirmation, lang?: 'en' | 'zh'): string;
|
|
37
37
|
export declare const NOTICE_GAP_MS: number;
|
|
38
|
+
/**
|
|
39
|
+
* A reminder that waits for the session's next tool result (docs/specs/mcp-client.md §7). The other ways into a session
|
|
40
|
+
* depend on the client (a Claude Code channel needs a start flag, `codex queue` the session's id, which Codex does not give
|
|
41
|
+
* its MCP servers) and fail without a sound; a tool result is what every client hands its model. One line per kind, the
|
|
42
|
+
* newest; taken once. A count of what waits that is older than `staleMs` is counted again before it is said (`fresh`),
|
|
43
|
+
* so a session that was idle for hours does not announce what has been answered since.
|
|
44
|
+
*/
|
|
45
|
+
export declare class PendingNotice {
|
|
46
|
+
private o;
|
|
47
|
+
private held;
|
|
48
|
+
/** What waits now, as the line to say, or null when nothing does. Set by the session's notifier. */
|
|
49
|
+
fresh?: () => Promise<string | null>;
|
|
50
|
+
constructor(o?: {
|
|
51
|
+
staleMs?: number;
|
|
52
|
+
now?: () => number;
|
|
53
|
+
});
|
|
54
|
+
private now;
|
|
55
|
+
put(kind: string, text: string): void;
|
|
56
|
+
/** The person is reading what waits themselves: nothing to tell them about it. */
|
|
57
|
+
drop(kind: string): void;
|
|
58
|
+
get waiting(): boolean;
|
|
59
|
+
/** Everything held, once: the lines for the next tool result ([] when nothing). */
|
|
60
|
+
take(): Promise<string[]>;
|
|
61
|
+
}
|
|
62
|
+
/** The kinds of reminder a session holds: what waits for the person, and that a newer `ach` is out. */
|
|
63
|
+
export declare const ATTENTION_NOTICE = "attention";
|
|
64
|
+
export declare const STALE_NOTICE = "stale";
|
|
38
65
|
export interface AttentionNotifierOptions {
|
|
39
66
|
fetch: () => Promise<Attention>;
|
|
40
67
|
/** Shows the line; resolves false when it could not (unsupported: stays silent). */
|
package/dist/src/attention.js
CHANGED
|
@@ -110,6 +110,57 @@ export function confirmationText(c, lang = 'en') {
|
|
|
110
110
|
return `${c.task} waits for your confirmation: ${c.runs}${c.money ? ` · cost ${c.money}` : ''}. Once you say yes or no, answer with decide (task_id ${c.task}, message_id ${c.id}, reply "${c.confirm}" or "${c.decline}").`;
|
|
111
111
|
}
|
|
112
112
|
export const NOTICE_GAP_MS = 10 * 60_000;
|
|
113
|
+
/**
|
|
114
|
+
* A reminder that waits for the session's next tool result (docs/specs/mcp-client.md §7). The other ways into a session
|
|
115
|
+
* depend on the client (a Claude Code channel needs a start flag, `codex queue` the session's id, which Codex does not give
|
|
116
|
+
* its MCP servers) and fail without a sound; a tool result is what every client hands its model. One line per kind, the
|
|
117
|
+
* newest; taken once. A count of what waits that is older than `staleMs` is counted again before it is said (`fresh`),
|
|
118
|
+
* so a session that was idle for hours does not announce what has been answered since.
|
|
119
|
+
*/
|
|
120
|
+
export class PendingNotice {
|
|
121
|
+
o;
|
|
122
|
+
held = new Map();
|
|
123
|
+
/** What waits now, as the line to say, or null when nothing does. Set by the session's notifier. */
|
|
124
|
+
fresh;
|
|
125
|
+
constructor(o = {}) {
|
|
126
|
+
this.o = o;
|
|
127
|
+
}
|
|
128
|
+
now() {
|
|
129
|
+
return (this.o.now ?? Date.now)();
|
|
130
|
+
}
|
|
131
|
+
put(kind, text) {
|
|
132
|
+
if (text)
|
|
133
|
+
this.held.set(kind, { text, at: this.now() });
|
|
134
|
+
}
|
|
135
|
+
/** The person is reading what waits themselves: nothing to tell them about it. */
|
|
136
|
+
drop(kind) {
|
|
137
|
+
this.held.delete(kind);
|
|
138
|
+
}
|
|
139
|
+
get waiting() {
|
|
140
|
+
return this.held.size > 0;
|
|
141
|
+
}
|
|
142
|
+
/** Everything held, once: the lines for the next tool result ([] when nothing). */
|
|
143
|
+
async take() {
|
|
144
|
+
if (!this.held.size)
|
|
145
|
+
return [];
|
|
146
|
+
const all = [...this.held];
|
|
147
|
+
this.held.clear();
|
|
148
|
+
const out = [];
|
|
149
|
+
for (const [kind, n] of all) {
|
|
150
|
+
if (kind !== ATTENTION_NOTICE || !this.fresh || this.now() - n.at <= (this.o.staleMs ?? NOTICE_GAP_MS))
|
|
151
|
+
out.push(n.text);
|
|
152
|
+
else {
|
|
153
|
+
const now = await this.fresh().catch(() => n.text);
|
|
154
|
+
if (now)
|
|
155
|
+
out.push(now);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return out;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/** The kinds of reminder a session holds: what waits for the person, and that a newer `ach` is out. */
|
|
162
|
+
export const ATTENTION_NOTICE = 'attention';
|
|
163
|
+
export const STALE_NOTICE = 'stale';
|
|
113
164
|
export class AttentionNotifier {
|
|
114
165
|
o;
|
|
115
166
|
noticed = new Set();
|
package/dist/src/cli.js
CHANGED
|
@@ -1109,7 +1109,7 @@ async function dispatch(p, io) {
|
|
|
1109
1109
|
if (r.started.length || r.stopped.length)
|
|
1110
1110
|
io.err(`pool ${name}: started ${r.started.join(', ') || 'none'}; stopped ${r.stopped.join(', ') || 'none'}; running ${pool.running.size}`);
|
|
1111
1111
|
if (pool.restartDue) {
|
|
1112
|
-
io.err(`pool ${name}:
|
|
1112
|
+
io.err(`pool ${name}: no run is going; restarting on ${pool.restartDue}`);
|
|
1113
1113
|
return (await import('./selfupdate.js')).UPDATE_EXIT_CODE;
|
|
1114
1114
|
}
|
|
1115
1115
|
}
|
package/dist/src/client.d.ts
CHANGED
|
@@ -714,6 +714,7 @@ export declare class Client {
|
|
|
714
714
|
id: string;
|
|
715
715
|
name: string;
|
|
716
716
|
repos: string[];
|
|
717
|
+
busy: boolean;
|
|
717
718
|
}[]>;
|
|
718
719
|
/** A fresh key for one of the pool's agents (its old one stops working). */
|
|
719
720
|
poolAgentKey(name: string, agentId: string): Promise<string>;
|
package/dist/src/client.js
CHANGED
|
@@ -481,7 +481,7 @@ export class Client {
|
|
|
481
481
|
/** `ach pool`: the agents of a pool (this client's token is the pool's key). */
|
|
482
482
|
async poolAgents(name) {
|
|
483
483
|
const r = await this.ach('GET', `/pool/${encodeURIComponent(name)}/agents`);
|
|
484
|
-
return arr(r?.agents).map((a) => ({ id: String(a.id), name: String(a.name), repos: arr(a.repos).map(String) }));
|
|
484
|
+
return arr(r?.agents).map((a) => ({ id: String(a.id), name: String(a.name), repos: arr(a.repos).map(String), busy: a.busy === true }));
|
|
485
485
|
}
|
|
486
486
|
/** A fresh key for one of the pool's agents (its old one stops working). */
|
|
487
487
|
async poolAgentKey(name, agentId) {
|
package/dist/src/mcp.d.ts
CHANGED
|
@@ -71,6 +71,8 @@ export declare const toolHints: (name: string) => {
|
|
|
71
71
|
readOnlyHint: boolean;
|
|
72
72
|
destructiveHint: boolean;
|
|
73
73
|
};
|
|
74
|
+
/** A held reminder as the last text item of a tool result: said to be the hub's own word, apart from what the tool returned. */
|
|
75
|
+
export declare const noticeInResult: (lines: string[]) => string;
|
|
74
76
|
/**
|
|
75
77
|
* Ask the person, in their client's own question box (MCP elicitation), whether something waiting on a card goes out
|
|
76
78
|
* (docs/specs/mcp-client.md §4.2). One step: the box has no field, so the client's own two buttons are the answer: accept
|
|
@@ -100,14 +102,15 @@ export declare function buildMcpServer(client: Client, o?: {
|
|
|
100
102
|
}): McpServer;
|
|
101
103
|
/**
|
|
102
104
|
* Where the one-line reminder goes in the session that runs this server.
|
|
103
|
-
* -
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
105
|
+
* - Always: held for the session's next tool result (PendingNotice): the one way every client is known to pass on. Tested
|
|
106
|
+
* in Claude Code, Codex, Kiro and Antigravity (docs/specs/mcp-client.md §7).
|
|
107
|
+
* - Codex (client name "codex..."): also `codex queue --thread <id>` when the session id is known (CODEX_THREAD_ID /
|
|
108
|
+
* ACH_CODEX_THREAD_ID); when that worked the person has it already and nothing is held. Codex 0.163 gives its MCP servers
|
|
109
|
+
* no such id.
|
|
110
|
+
* - Anything else: also a Claude Code channel notification. Claude Code shows it only when started with channels enabled for
|
|
111
|
+
* this server and says nothing when it drops it, so it never counts as delivered.
|
|
109
112
|
*/
|
|
110
|
-
export declare function sessionDeliverer(server: McpServer, env?: NodeJS.ProcessEnv, exec?: Exec): (text: string) => Promise<boolean>;
|
|
113
|
+
export declare function sessionDeliverer(server: McpServer, env?: NodeJS.ProcessEnv, exec?: Exec, kind?: string): (text: string) => Promise<boolean>;
|
|
111
114
|
/**
|
|
112
115
|
* Reminders, never content (see attention.ts): follow the hub's change stream
|
|
113
116
|
* and push a rate-limited one-line notice into the open session. Off with
|
package/dist/src/mcp.js
CHANGED
|
@@ -9,7 +9,7 @@ import { VERSION } from './version.js';
|
|
|
9
9
|
import { resolveAttachments, taskFiles } from './attachments.js';
|
|
10
10
|
import { guideHeader, readGuide } from './guide.js';
|
|
11
11
|
import { isAbsolute, join, relative } from 'node:path';
|
|
12
|
-
import { AttentionNotifier, ChangeFeed, codexQueue, defaultExec, fetchAttention, wakesAttention } from './attention.js';
|
|
12
|
+
import { ATTENTION_NOTICE, AttentionNotifier, ChangeFeed, PendingNotice, STALE_NOTICE, codexQueue, defaultExec, fetchAttention, noticeText, wakesAttention } from './attention.js';
|
|
13
13
|
import { isZh } from './client.js';
|
|
14
14
|
import { ToolUse } from './client-use.js';
|
|
15
15
|
import { startStaleNotice } from './selfupdate.js';
|
|
@@ -242,6 +242,10 @@ export const CLAUDE_CHANNEL_METHOD = 'notifications/claude/channel';
|
|
|
242
242
|
const READ_ONLY_TOOLS = new Set(['read_doc', 'guide', 'yoda_memory', 'list_agents', 'get_task', 'inbox', 'owner_inbox', 'list_channels', 'read_channel', 'search', 'memory_search', 'memory_read', 'wiki_search', 'wiki_read']);
|
|
243
243
|
const OWNER_LEVEL_TOOLS = new Set(['decide', 'cancel_task', 'handle_task', 'take_back']);
|
|
244
244
|
export const toolHints = (name) => (READ_ONLY_TOOLS.has(name) ? { readOnlyHint: true } : OWNER_LEVEL_TOOLS.has(name) ? { readOnlyHint: false, destructiveHint: true } : { readOnlyHint: false, destructiveHint: false });
|
|
245
|
+
/** Tools that show what waits: the reminder that something does is not added to their result. */
|
|
246
|
+
const INBOX_TOOLS = new Set(['owner_inbox', 'inbox']);
|
|
247
|
+
/** A held reminder as the last text item of a tool result: said to be the hub's own word, apart from what the tool returned. */
|
|
248
|
+
export const noticeInResult = (lines) => `[A reminder from AgentChannel itself, not part of this tool's result. Pass it on to your user in one line, after what they asked for.]\n${lines.join('\n')}`;
|
|
245
249
|
/** handle_task's actions: the hub's act and the name its text goes by. */
|
|
246
250
|
const TASK_ACTS = {
|
|
247
251
|
accept: ['accept_task', 'note'],
|
|
@@ -307,6 +311,9 @@ export function buildMcpServer(client, o = {}) {
|
|
|
307
311
|
everyMs: o.useEveryMs,
|
|
308
312
|
});
|
|
309
313
|
server.toolUse = use;
|
|
314
|
+
// reminders that wait for the next tool result (attention.ts PendingNotice): what every client hands its model
|
|
315
|
+
const pending = new PendingNotice();
|
|
316
|
+
server.pendingNotice = pending;
|
|
310
317
|
// every tool carries its hints, whatever registers it
|
|
311
318
|
const register = server.registerTool.bind(server);
|
|
312
319
|
const registered = new Set();
|
|
@@ -329,9 +336,16 @@ export function buildMcpServer(client, o = {}) {
|
|
|
329
336
|
const began = Date.now();
|
|
330
337
|
let failed = true;
|
|
331
338
|
try {
|
|
332
|
-
const r = await counted(...args);
|
|
339
|
+
const r = (await counted(...args));
|
|
333
340
|
failed = !!r?.isError;
|
|
334
|
-
|
|
341
|
+
// asking what waits is the answer to "something waits": that reminder is not said on top of it
|
|
342
|
+
if (!failed && INBOX_TOOLS.has(name))
|
|
343
|
+
pending.drop(ATTENTION_NOTICE);
|
|
344
|
+
if (failed || !pending.waiting || !Array.isArray(r?.content))
|
|
345
|
+
return r;
|
|
346
|
+
const lines = await pending.take();
|
|
347
|
+
// its own text item after the tool's: the result itself stays what the tool gave
|
|
348
|
+
return lines.length ? { ...r, content: [...r.content, { type: 'text', text: noticeInResult(lines) }] } : r;
|
|
335
349
|
}
|
|
336
350
|
finally {
|
|
337
351
|
use.count(name, failed, Date.now() - began);
|
|
@@ -831,25 +845,34 @@ export function buildMcpServer(client, o = {}) {
|
|
|
831
845
|
}
|
|
832
846
|
/**
|
|
833
847
|
* Where the one-line reminder goes in the session that runs this server.
|
|
834
|
-
* -
|
|
835
|
-
*
|
|
836
|
-
*
|
|
837
|
-
*
|
|
838
|
-
*
|
|
839
|
-
*
|
|
848
|
+
* - Always: held for the session's next tool result (PendingNotice): the one way every client is known to pass on. Tested
|
|
849
|
+
* in Claude Code, Codex, Kiro and Antigravity (docs/specs/mcp-client.md §7).
|
|
850
|
+
* - Codex (client name "codex..."): also `codex queue --thread <id>` when the session id is known (CODEX_THREAD_ID /
|
|
851
|
+
* ACH_CODEX_THREAD_ID); when that worked the person has it already and nothing is held. Codex 0.163 gives its MCP servers
|
|
852
|
+
* no such id.
|
|
853
|
+
* - Anything else: also a Claude Code channel notification. Claude Code shows it only when started with channels enabled for
|
|
854
|
+
* this server and says nothing when it drops it, so it never counts as delivered.
|
|
840
855
|
*/
|
|
841
|
-
export function sessionDeliverer(server, env = process.env, exec = defaultExec) {
|
|
856
|
+
export function sessionDeliverer(server, env = process.env, exec = defaultExec, kind = ATTENTION_NOTICE) {
|
|
842
857
|
return async (text) => {
|
|
858
|
+
const pending = server.pendingNotice;
|
|
843
859
|
const name = String(server.server.getClientVersion()?.name ?? '');
|
|
844
|
-
if (/codex/i.test(name))
|
|
845
|
-
|
|
860
|
+
if (/codex/i.test(name)) {
|
|
861
|
+
if (await codexQueue(text, env, exec))
|
|
862
|
+
return true;
|
|
863
|
+
pending?.put(kind, text);
|
|
864
|
+
return !!pending;
|
|
865
|
+
}
|
|
866
|
+
let sent = false;
|
|
846
867
|
try {
|
|
847
868
|
await server.server.notification({ method: CLAUDE_CHANNEL_METHOD, params: { content: text, meta: { source: 'agentchannel', kind: 'reminder' } } });
|
|
848
|
-
|
|
869
|
+
sent = true;
|
|
849
870
|
}
|
|
850
871
|
catch {
|
|
851
|
-
|
|
872
|
+
sent = false;
|
|
852
873
|
}
|
|
874
|
+
pending?.put(kind, text);
|
|
875
|
+
return sent || !!pending;
|
|
853
876
|
};
|
|
854
877
|
}
|
|
855
878
|
/**
|
|
@@ -872,12 +895,16 @@ export function startSessionNotices(server, client, o = {}) {
|
|
|
872
895
|
// (only what is addressed to this person: counting again for every event of the team made this the hub's most asked question)
|
|
873
896
|
// (and not in the same instant as the person's other sessions: 2026-11-24, six of them counted together two seconds after one
|
|
874
897
|
// reply, and D1 refused them all as overloaded)
|
|
898
|
+
// a held count that grew old is counted again before it is said (PendingNotice.fresh)
|
|
899
|
+
const held = server.pendingNotice;
|
|
900
|
+
if (held)
|
|
901
|
+
held.fresh = async () => { const a = await fetchAttention(request); return a.total > 0 ? noticeText(a, isZh(env) ? 'zh' : 'en') : null; };
|
|
875
902
|
const feed = new ChangeFeed({ socket: () => client.eventsSocket(), onChange: () => notifier.check(), relevant: wakesAttention, spreadMs: 3000, log: o.log, ...o.feed });
|
|
876
903
|
const done = feed.run();
|
|
877
904
|
// a session cannot be restarted from outside: when the hub names a newer ach, say so once (see selfupdate.ts)
|
|
878
905
|
const stale = startStaleNotice({
|
|
879
906
|
fetchVersions: () => client.request('GET', '/api/ach/auth/config'),
|
|
880
|
-
deliver: sessionDeliverer(server, env, o.exec),
|
|
907
|
+
deliver: sessionDeliverer(server, env, o.exec, STALE_NOTICE),
|
|
881
908
|
lang: isZh(env) ? 'zh' : 'en',
|
|
882
909
|
firstMs: o.staleFirstMs,
|
|
883
910
|
log: o.log,
|
package/dist/src/pool.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export interface PoolAgent {
|
|
|
3
3
|
name: string;
|
|
4
4
|
/** owner/name GitHub repositories its cloud session opens */
|
|
5
5
|
repos: string[];
|
|
6
|
+
/** it has a run going now, as the hub knows it */
|
|
7
|
+
busy?: boolean;
|
|
6
8
|
}
|
|
7
9
|
export interface PoolHub {
|
|
8
10
|
agents(): Promise<PoolAgent[]>;
|
|
@@ -27,7 +29,7 @@ export interface PoolOptions {
|
|
|
27
29
|
};
|
|
28
30
|
now?: () => number;
|
|
29
31
|
}
|
|
30
|
-
/** How long a pool on an old release waits for
|
|
32
|
+
/** How long a pool on an old release waits for the runs that are going before it restarts anyway. */
|
|
31
33
|
export declare const MOVE_WAIT_MS: number;
|
|
32
34
|
export interface PoolChild {
|
|
33
35
|
/** set once it has exited */
|
|
@@ -57,7 +59,7 @@ export declare class Pool {
|
|
|
57
59
|
readonly running: Map<string, Running>;
|
|
58
60
|
/** when a runner that exited may be started again, and how often it has in a row */
|
|
59
61
|
private retry;
|
|
60
|
-
/** set once the install names another release and no
|
|
62
|
+
/** set once the install names another release and no run is going: the pool should exit so that its service restarts it */
|
|
61
63
|
restartDue?: string;
|
|
62
64
|
/** when the pool saw that the install names another release than its own */
|
|
63
65
|
private movedAt?;
|
|
@@ -71,11 +73,10 @@ export declare class Pool {
|
|
|
71
73
|
stopped: string[];
|
|
72
74
|
failed: string[];
|
|
73
75
|
}>;
|
|
74
|
-
/**
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
private moving;
|
|
76
|
+
/** The release the install names when it is not the pool's own (the pool is then due to move to it), said once. */
|
|
77
|
+
private moveTo;
|
|
78
|
+
/** Stop the runners and say that the pool should restart: its service starts it, and them, on `release`. */
|
|
79
|
+
private leave;
|
|
79
80
|
stop(): void;
|
|
80
81
|
}
|
|
81
82
|
export {};
|
package/dist/src/pool.js
CHANGED
|
@@ -6,18 +6,22 @@
|
|
|
6
6
|
// that leaves the pool has its runner stopped; one whose repositories changed has it restarted.
|
|
7
7
|
//
|
|
8
8
|
// Releases (2026-11-24: every cloud workspace sat on 3.67.0 for a day while 17 releases went by): the runners are started through
|
|
9
|
-
// the install's launcher, so a runner that updated itself (it installs, sets `current`, exits) comes back on the new release
|
|
10
|
-
// pool itself moves
|
|
11
|
-
//
|
|
9
|
+
// the install's launcher, so a runner that updated itself (it installs, sets `current`, exits) comes back on the new release: the
|
|
10
|
+
// pool starts it again at once. The pool itself moves when nobody is at work: once `current` names another release than its own
|
|
11
|
+
// and the hub says none of its agents has a run going, it stops its runners and exits, so that its service starts it and them
|
|
12
|
+
// on the new release (a second or two). While a run is going it waits, and the runners that are free keep taking work.
|
|
13
|
+
// (Until 2026-11-26 it started no runner again and waited for every one to exit: one runner that did not update, or one long
|
|
14
|
+
// run, kept all the others offline, up to the half hour below. Three times in two days.)
|
|
12
15
|
import { spawn } from 'node:child_process';
|
|
13
16
|
import { chmodSync, existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
14
17
|
import { dirname, join } from 'node:path';
|
|
15
18
|
import { fileURLToPath } from 'node:url';
|
|
16
19
|
import { appDir, appVersionOf, currentVersion, inApp, launcherPath } from './appinstall.js';
|
|
17
20
|
import { cfSecretPath, keyFilePath } from './keystore.js';
|
|
21
|
+
import { UPDATE_EXIT_CODE } from './selfupdate.js';
|
|
18
22
|
/** The CLI's entry (dist/src/cli.js, next to this file). */
|
|
19
23
|
const CLI_JS = join(dirname(fileURLToPath(import.meta.url)), 'cli.js');
|
|
20
|
-
/** How long a pool on an old release waits for
|
|
24
|
+
/** How long a pool on an old release waits for the runs that are going before it restarts anyway. */
|
|
21
25
|
export const MOVE_WAIT_MS = 30 * 60_000;
|
|
22
26
|
const safe = (name) => name.replace(/[^A-Za-z0-9-]/g, '-');
|
|
23
27
|
export const agentHomeIn = (base, a) => join(base, 'homes', safe(a.name));
|
|
@@ -78,7 +82,7 @@ export class Pool {
|
|
|
78
82
|
running = new Map();
|
|
79
83
|
/** when a runner that exited may be started again, and how often it has in a row */
|
|
80
84
|
retry = new Map();
|
|
81
|
-
/** set once the install names another release and no
|
|
85
|
+
/** set once the install names another release and no run is going: the pool should exit so that its service restarts it */
|
|
82
86
|
restartDue;
|
|
83
87
|
/** when the pool saw that the install names another release than its own */
|
|
84
88
|
movedAt;
|
|
@@ -95,9 +99,13 @@ export class Pool {
|
|
|
95
99
|
/** One round: what the hub says is in the pool is what runs. Returns what changed (for the log, and the tests). */
|
|
96
100
|
async tick() {
|
|
97
101
|
const out = { started: [], stopped: [], failed: [] };
|
|
98
|
-
|
|
99
|
-
|
|
102
|
+
const move = this.moveTo();
|
|
103
|
+
// (the limit does not need the hub: a hub that does not answer never holds the pool on an old release)
|
|
104
|
+
if (move && this.now() - this.movedAt > MOVE_WAIT_MS)
|
|
105
|
+
return this.leave(move, out);
|
|
100
106
|
const agents = await this.hub.agents();
|
|
107
|
+
if (move && !agents.some((a) => a.busy))
|
|
108
|
+
return this.leave(move, out);
|
|
101
109
|
const want = new Map(agents.map((a) => [a.id, a]));
|
|
102
110
|
for (const [id, r] of this.running) {
|
|
103
111
|
const a = want.get(id);
|
|
@@ -108,6 +116,12 @@ export class Pool {
|
|
|
108
116
|
this.retry.delete(id);
|
|
109
117
|
out.stopped.push(r.agent.name);
|
|
110
118
|
}
|
|
119
|
+
else if (r.child.exited?.code === UPDATE_EXIT_CODE) {
|
|
120
|
+
// it updated itself and left for that: back at once, on the release it installed
|
|
121
|
+
this.running.delete(id);
|
|
122
|
+
this.retry.delete(id);
|
|
123
|
+
this.o.log(`[${r.agent.name}] its runner updated itself; starting it again`);
|
|
124
|
+
}
|
|
111
125
|
else if (r.child.exited) {
|
|
112
126
|
this.running.delete(id);
|
|
113
127
|
const n = (this.retry.get(id)?.n ?? 0) + 1;
|
|
@@ -140,33 +154,30 @@ export class Pool {
|
|
|
140
154
|
this.retry.delete(id);
|
|
141
155
|
return out;
|
|
142
156
|
}
|
|
143
|
-
/**
|
|
144
|
-
|
|
145
|
-
* runs first), and once none is left say that the pool should restart. One that has not exited after MOVE_WAIT_MS is stopped.
|
|
146
|
-
*/
|
|
147
|
-
moving(out) {
|
|
157
|
+
/** The release the install names when it is not the pool's own (the pool is then due to move to it), said once. */
|
|
158
|
+
moveTo() {
|
|
148
159
|
const { mine, current } = this.releases();
|
|
149
160
|
if (!mine || !current || mine === current) {
|
|
150
161
|
this.movedAt = undefined;
|
|
151
|
-
return
|
|
162
|
+
return undefined;
|
|
152
163
|
}
|
|
153
164
|
if (this.movedAt === undefined) {
|
|
154
165
|
this.movedAt = this.now();
|
|
155
|
-
this.o.log(`the install starts ${current} now (this pool is ${mine}): no
|
|
166
|
+
this.o.log(`the install starts ${current} now (this pool is ${mine}): the pool restarts on it once no run is going; runners that update themselves are started again meanwhile`);
|
|
156
167
|
}
|
|
157
|
-
|
|
158
|
-
|
|
168
|
+
return current;
|
|
169
|
+
}
|
|
170
|
+
/** Stop the runners and say that the pool should restart: its service starts it, and them, on `release`. */
|
|
171
|
+
leave(release, out) {
|
|
172
|
+
for (const r of this.running.values()) {
|
|
159
173
|
if (r.child.exited)
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
this.running.delete(id);
|
|
164
|
-
out.stopped.push(r.agent.name);
|
|
165
|
-
}
|
|
174
|
+
continue;
|
|
175
|
+
r.child.stop();
|
|
176
|
+
out.stopped.push(r.agent.name);
|
|
166
177
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return
|
|
178
|
+
this.running.clear();
|
|
179
|
+
this.restartDue = release;
|
|
180
|
+
return out;
|
|
170
181
|
}
|
|
171
182
|
stop() {
|
|
172
183
|
for (const r of this.running.values())
|
package/dist/src/version.d.ts
CHANGED
package/dist/src/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koalaauto/agentchannel",
|
|
3
|
-
"version": "3.99.
|
|
3
|
+
"version": "3.99.2",
|
|
4
4
|
"description": "Hand work between your team's agents (Claude Code, Codex) and follow it in one panel: the ach CLI, MCP server and runner for AgentChannel v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentchannel",
|