@koalaauto/agentchannel 3.98.3 → 3.99.1

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/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}: every runner has exited; restarting on ${pool.restartDue}`);
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
  }
@@ -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>;
@@ -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
@@ -95,6 +95,8 @@ export declare function buildMcpServer(client: Client, o?: {
95
95
  };
96
96
  /** how often tool-call counts are reported (default: once a minute) */
97
97
  useEveryMs?: number;
98
+ /** connected as a person who gets no notifications on any device: where they turn them on (the hub's /me `notify`) */
99
+ notifyOff?: string;
98
100
  }): McpServer;
99
101
  /**
100
102
  * Where the one-line reminder goes in the session that runs this server.
package/dist/src/mcp.js CHANGED
@@ -543,7 +543,9 @@ export function buildMcpServer(client, o = {}) {
543
543
  // a session that is the person: each waiting item says which tool settles it, and the cards waiting for their word come along
544
544
  const items = Array.isArray(inbox.items) ? inbox.items.map((i) => { const h = i.pending ? inboxHandle(i) : ''; return h ? { ...i, handle: h } : i; }) : inbox.items;
545
545
  const cards = await client.yoda().then((y) => y.pending.filter((i) => i.kind === 'confirm' && i.act_id).map((i) => ({ act: i.act_id, what: i.body, handle: 'confirm_card {act}: asks your user here' })), () => []);
546
- return wrapUntrusted({ ...inbox, items, ...(cards.length ? { cards } : {}) });
546
+ // nothing reaches them outside a session: said with what waits, since that is when it matters
547
+ const notice = o.notifyOff ? { notice: `No browser of ${o.person}'s takes notifications: when no session is open, nothing tells them something waits. They turn them on once at ${o.notifyOff}` } : {};
548
+ return wrapUntrusted({ ...notice, ...inbox, items, ...(cards.length ? { cards } : {}) });
547
549
  }));
548
550
  server.registerTool('ask', {
549
551
  description: 'Ask a factual question on a task. It goes to the other party\'s agent by default (`to` takes an agent name, not a person); to reach a person, @ them by name in a post or reply. For money, product direction or irreversible actions use request_decision instead.',
@@ -924,7 +926,10 @@ export async function startMcp(client, where = { cwd: process.cwd() }) {
924
926
  client.yodaFrom = hand.name;
925
927
  if (viaKey && !hand)
926
928
  client.yodaOutside = true;
927
- const server = buildMcpServer(client, { brief, identity, memory, me: (hand ? handMe : me) ?? undefined, person, hand });
929
+ // (asked of the hub once, when the session starts: a person who turns notifications on mid-session hears it once more)
930
+ const notify = person ? me?.notify : undefined;
931
+ const notifyOff = notify && notify.devices === 0 && notify.url ? notify.url : undefined;
932
+ const server = buildMcpServer(client, { brief, identity, memory, me: (hand ? handMe : me) ?? undefined, person, hand, notifyOff });
928
933
  // reminders start once the session said hello (its name decides Claude channel vs codex queue)
929
934
  let notices = null;
930
935
  server.server.oninitialized = () => {
@@ -934,12 +939,21 @@ export async function startMcp(client, where = { cwd: process.cwd() }) {
934
939
  // this machine's runner, when it stopped and should not have (watchdog.ts): started again from here
935
940
  // (a session connected as a person has no runner to look after)
936
941
  const watchdog = linked && !hand ? { stop() { } } : startRunnerWatchdog({ me: () => (hand ? hand.client : client).me(), log: (s) => process.stderr.write(`[ach mcp] ${s}\n`) });
937
- // the client ends a session by closing the pipe and then killing the process: what was counted since the last report is
938
- // told first (a session shorter than a minute would otherwise leave no trace), within a second and a half
942
+ // A session ends when its client closes the pipe (and usually kills the process after). What was counted since the last
943
+ // report is told first, within a second and a half, and then the process goes: a server whose client is gone has nobody to
944
+ // answer, and until 3.98.2 it stayed, still following the hub's events (a client that was killed left one behind each time).
939
945
  const lastWord = () => Promise.race([server.toolUse?.flush(), new Promise((r) => setTimeout(r, 1500))]).catch(() => { });
940
- process.stdin.once('end', () => void lastWord());
946
+ let leaving = false;
947
+ const leave = () => {
948
+ if (leaving)
949
+ return;
950
+ leaving = true;
951
+ void lastWord().finally(() => process.exit(0));
952
+ };
953
+ process.stdin.once('end', leave);
954
+ process.stdin.once('close', leave);
941
955
  for (const sig of ['SIGTERM', 'SIGINT', 'SIGHUP'])
942
- process.once(sig, () => void lastWord().finally(() => process.exit(0)));
956
+ process.once(sig, leave);
943
957
  server.server.onclose = () => {
944
958
  void server.toolUse?.flush();
945
959
  notices?.stop();
@@ -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 its runners to exit by themselves before it stops the rest. */
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 runner is left: the pool should exit so that its service restarts it */
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
- * The install names another release than the pool's: start nothing, let each runner exit by itself (it updates, finishing its
76
- * runs first), and once none is left say that the pool should restart. One that has not exited after MOVE_WAIT_MS is stopped.
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. The
10
- // pool itself moves with them: once `current` names another release than its own, it starts no runner again, and when the last
11
- // one has exited (each finishes its runs first) it exits too, so that its service starts it on the new release.
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 its runners to exit by themselves before it stops the rest. */
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 runner is left: the pool should exit so that its service restarts it */
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
- if (this.moving(out))
99
- return out;
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
- * The install names another release than the pool's: start nothing, let each runner exit by itself (it updates, finishing its
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 false;
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 runner is started again; the pool restarts once they have exited`);
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
- const late = this.now() - this.movedAt > MOVE_WAIT_MS;
158
- for (const [id, r] of this.running) {
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
- this.running.delete(id);
161
- else if (late) {
162
- r.child.stop();
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
- if (!this.running.size)
168
- this.restartDue = current;
169
- return true;
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())
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "3.98.3";
1
+ export declare const VERSION = "3.99.1";
2
2
  /** The npm package (scripts/release.mjs keeps it and VERSION in step with package.json). */
3
3
  export declare const PKG_NAME = "@koalaauto/agentchannel";
4
4
  /**
@@ -1,4 +1,4 @@
1
- export const VERSION = '3.98.3';
1
+ export const VERSION = '3.99.1';
2
2
  /** The npm package (scripts/release.mjs keeps it and VERSION in step with package.json). */
3
3
  export const PKG_NAME = '@koalaauto/agentchannel';
4
4
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koalaauto/agentchannel",
3
- "version": "3.98.3",
3
+ "version": "3.99.1",
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",