@koalaauto/agentchannel 3.25.0 → 3.26.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/adapters/claude.js +7 -1
- package/dist/src/adapters/paths.d.ts +2 -0
- package/dist/src/adapters/paths.js +3 -0
- package/dist/src/adapters/types.d.ts +4 -0
- package/dist/src/args.d.ts +7 -1
- package/dist/src/args.js +44 -15
- package/dist/src/cli.d.ts +6 -0
- package/dist/src/cli.js +114 -72
- package/dist/src/client.d.ts +3 -0
- package/dist/src/client.js +24 -5
- package/dist/src/envcheck.d.ts +7 -0
- package/dist/src/envcheck.js +11 -0
- package/dist/src/import.js +12 -13
- package/dist/src/invite.js +1 -1
- package/dist/src/mcp.d.ts +7 -0
- package/dist/src/mcp.js +45 -7
- package/dist/src/redact.js +3 -0
- package/dist/src/runner/lock.d.ts +4 -0
- package/dist/src/runner/lock.js +69 -0
- package/dist/src/runner/runner.d.ts +19 -0
- package/dist/src/runner/runner.js +100 -11
- package/dist/src/runner/state.d.ts +2 -0
- package/dist/src/runner/state.js +4 -2
- package/dist/src/runner/workspace.js +8 -2
- package/dist/src/selfupdate.d.ts +23 -1
- package/dist/src/selfupdate.js +71 -5
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +1 -1
|
@@ -39,6 +39,8 @@ export interface RunsFile {
|
|
|
39
39
|
export interface SessionRef {
|
|
40
40
|
id: string;
|
|
41
41
|
cwd: string;
|
|
42
|
+
/** The running cost total the runtime last reported for this task's session (Claude reports a total, the hub adds up increments). */
|
|
43
|
+
costTotal?: number;
|
|
42
44
|
}
|
|
43
45
|
export interface SessionsFile {
|
|
44
46
|
[taskId: string]: {
|
package/dist/src/runner/state.js
CHANGED
|
@@ -68,9 +68,11 @@ export class RunnerState {
|
|
|
68
68
|
}
|
|
69
69
|
setSession(taskId, kind, ref) {
|
|
70
70
|
const cur = this.sessions[taskId] ?? {};
|
|
71
|
-
|
|
71
|
+
// the cost baseline survives a new session id (a resumed run may start a new one that still carries the earlier cost)
|
|
72
|
+
const keep = ref.costTotal !== undefined ? ref : { ...ref, ...(cur[kind]?.costTotal !== undefined ? { costTotal: cur[kind].costTotal } : {}) };
|
|
73
|
+
if (cur[kind]?.id === keep.id && cur[kind]?.cwd === keep.cwd && cur[kind]?.costTotal === keep.costTotal)
|
|
72
74
|
return;
|
|
73
|
-
cur[kind] =
|
|
75
|
+
cur[kind] = keep;
|
|
74
76
|
this.sessions[taskId] = cur;
|
|
75
77
|
this.saveSessions();
|
|
76
78
|
}
|
|
@@ -3,8 +3,14 @@ import { existsSync, mkdirSync, readdirSync, rmSync, statSync } from 'node:fs';
|
|
|
3
3
|
import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
|
|
4
4
|
import { promisify } from 'node:util';
|
|
5
5
|
const pexec = promisify(execFile);
|
|
6
|
+
/**
|
|
7
|
+
* The runner runs git on a work dir the agent can write to, outside the sandbox. A repository the agent edited can name programs
|
|
8
|
+
* to run in its own config (a file system monitor, an external diff, an ssh command): these are switched off for every git call
|
|
9
|
+
* the runner makes on such a directory.
|
|
10
|
+
*/
|
|
11
|
+
const HARDEN = ['-c', 'core.fsmonitor=false', '-c', 'core.hooksPath=/dev/null', '-c', 'diff.external=', '-c', 'core.pager=cat', '-c', 'protocol.ext.allow=never'];
|
|
6
12
|
async function git(cwd, args) {
|
|
7
|
-
const { stdout } = await pexec('git', args, { cwd, encoding: 'utf8' });
|
|
13
|
+
const { stdout } = await pexec('git', [...HARDEN, ...args], { cwd, encoding: 'utf8' });
|
|
8
14
|
return stdout.trim();
|
|
9
15
|
}
|
|
10
16
|
export async function isGitRepo(dir) {
|
|
@@ -241,7 +247,7 @@ export class GitWorkspace {
|
|
|
241
247
|
catch {
|
|
242
248
|
ident.push('-c', 'user.name=AgentChannel runner', '-c', 'user.email=runner@agentchannel.invalid');
|
|
243
249
|
}
|
|
244
|
-
const safe = [
|
|
250
|
+
const safe = [...ident];
|
|
245
251
|
await git(p, [...safe, 'add', '-A']);
|
|
246
252
|
await git(p, [...safe, 'commit', '--no-verify', '-q', '-m', message]);
|
|
247
253
|
return git(p, ['rev-parse', 'HEAD']);
|
package/dist/src/selfupdate.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export declare const UPDATE_EXIT_CODE = 75;
|
|
|
3
3
|
export interface HubVersions {
|
|
4
4
|
latest_client?: string;
|
|
5
5
|
min_client_proto?: number;
|
|
6
|
+
/** Releases the hub's admin marked bad (ACH_BAD_CLIENTS): never installed, and a runner on one moves to latest_client even if it is older. */
|
|
7
|
+
bad_clients?: string[];
|
|
6
8
|
}
|
|
7
9
|
export type Verdict = {
|
|
8
10
|
action: 'none';
|
|
@@ -19,7 +21,7 @@ export type Verdict = {
|
|
|
19
21
|
why: string;
|
|
20
22
|
};
|
|
21
23
|
/** What to do about the release the hub names. Pure: no I/O. */
|
|
22
|
-
export declare function judge(hub: HubVersions | null | undefined, current?: string, proto?: number): Verdict;
|
|
24
|
+
export declare function judge(hub: HubVersions | null | undefined, current?: string, proto?: number, localBad?: string[]): Verdict;
|
|
23
25
|
export type ExecFn = (file: string, args: string[], o?: {
|
|
24
26
|
timeoutMs?: number;
|
|
25
27
|
}) => Promise<{
|
|
@@ -67,6 +69,8 @@ interface UpdateState {
|
|
|
67
69
|
/** ms since epoch of the last attempt. */
|
|
68
70
|
at: number;
|
|
69
71
|
attempts: number;
|
|
72
|
+
/** The release that ran before this update: where a release that keeps failing to start goes back to. */
|
|
73
|
+
previous?: string;
|
|
70
74
|
}
|
|
71
75
|
export declare function loadUpdateState(home: string): UpdateState | null;
|
|
72
76
|
/** The runner as the updater needs it. */
|
|
@@ -121,6 +125,24 @@ export declare class SelfUpdater {
|
|
|
121
125
|
heardLatest(latest: string): Promise<CheckResult> | undefined;
|
|
122
126
|
check(): Promise<CheckResult>;
|
|
123
127
|
}
|
|
128
|
+
/** This many starts of one release inside BOOT_WINDOW_MS, none of them healthy, and it is called bad. */
|
|
129
|
+
export declare const BOOT_LIMIT = 3;
|
|
130
|
+
/** Releases this machine found bad (they kept failing to start): never installed again here. */
|
|
131
|
+
export declare const localBad: (home: string) => string[];
|
|
132
|
+
/** The runner has worked for a while on this release (it reached the hub and kept going): the release is good. */
|
|
133
|
+
export declare function markHealthy(home: string, version?: string): void;
|
|
134
|
+
/**
|
|
135
|
+
* Called first thing when `ach run` starts. A release this runner updated itself to, that has started BOOT_LIMIT times within
|
|
136
|
+
* ten minutes without once becoming healthy, is marked bad here and the release before it is installed again (a global install;
|
|
137
|
+
* an npx install has nothing to go back to and only marks it). Returns what it did; 'rolledback' means: exit UPDATE_EXIT_CODE.
|
|
138
|
+
*/
|
|
139
|
+
export declare function bootGuard(home: string, o?: {
|
|
140
|
+
version?: string;
|
|
141
|
+
exec?: ExecFn;
|
|
142
|
+
self?: string;
|
|
143
|
+
now?: () => number;
|
|
144
|
+
log?: (s: string) => void;
|
|
145
|
+
}): Promise<'ok' | 'rolledback' | 'marked'>;
|
|
124
146
|
export declare function staleText(latest: string, lang?: 'en' | 'zh', current?: string): string;
|
|
125
147
|
/**
|
|
126
148
|
* One line into the open session when the hub names a newer CLI (once per release per process, checked every 6 h). A session
|
package/dist/src/selfupdate.js
CHANGED
|
@@ -23,9 +23,15 @@ const CHECK_EVERY_MS = 6 * 3600_000;
|
|
|
23
23
|
const isVersion = (v) => typeof v === 'string' && /^\d+\.\d+\.\d+(-[0-9A-Za-z.]+)?$/.test(v);
|
|
24
24
|
const major = (v) => Number(v.split('.')[0]);
|
|
25
25
|
/** What to do about the release the hub names. Pure: no I/O. */
|
|
26
|
-
export function judge(hub, current = VERSION, proto = CLIENT_PROTO) {
|
|
26
|
+
export function judge(hub, current = VERSION, proto = CLIENT_PROTO, localBad = []) {
|
|
27
27
|
const target = hub?.latest_client;
|
|
28
28
|
const needs = Number(hub?.min_client_proto) > proto;
|
|
29
|
+
const bad = new Set([...(Array.isArray(hub?.bad_clients) ? hub.bad_clients : []), ...localBad].filter(isVersion));
|
|
30
|
+
// a release marked bad is never installed; one that IS bad is left for the named release, older or not (same major only)
|
|
31
|
+
if (isVersion(target) && bad.has(target))
|
|
32
|
+
return { action: 'none' };
|
|
33
|
+
if (bad.has(current) && isVersion(target) && target !== current && major(target) === major(current))
|
|
34
|
+
return { action: 'update', target };
|
|
29
35
|
if (!isVersion(target) || !newerVersion(target, current)) {
|
|
30
36
|
return needs ? { action: 'manual', target: '', why: `the hub needs protocol ${hub.min_client_proto} or newer, but names no newer release: ask the hub's admin` } : { action: 'none' };
|
|
31
37
|
}
|
|
@@ -113,7 +119,7 @@ const stateFile = (home) => join(home, 'update.json');
|
|
|
113
119
|
export function loadUpdateState(home) {
|
|
114
120
|
try {
|
|
115
121
|
const s = JSON.parse(readFileSync(stateFile(home), 'utf8'));
|
|
116
|
-
return isVersion(s?.target) && Number.isFinite(s?.at) ? { target: s.target, at: s.at, attempts: Number(s.attempts) || 1 } : null;
|
|
122
|
+
return isVersion(s?.target) && Number.isFinite(s?.at) ? { target: s.target, at: s.at, attempts: Number(s.attempts) || 1, ...(isVersion(s?.previous) ? { previous: s.previous } : {}) } : null;
|
|
117
123
|
}
|
|
118
124
|
catch {
|
|
119
125
|
return null;
|
|
@@ -208,9 +214,9 @@ export class SelfUpdater {
|
|
|
208
214
|
return 'none'; // offline or an old hub: nothing to act on
|
|
209
215
|
}
|
|
210
216
|
const prior = loadUpdateState(this.o.home);
|
|
211
|
-
if (prior && prior.target === version)
|
|
217
|
+
if (prior && prior.target === version && isHealthy(this.o.home, version))
|
|
212
218
|
saveUpdateState(this.o.home, null); // it worked: forget the back-off
|
|
213
|
-
const v = judge(hub, version, this.o.proto);
|
|
219
|
+
const v = judge(hub, version, this.o.proto, localBad(this.o.home));
|
|
214
220
|
if (v.action === 'none')
|
|
215
221
|
return 'none';
|
|
216
222
|
if (v.action === 'manual') {
|
|
@@ -241,7 +247,7 @@ export class SelfUpdater {
|
|
|
241
247
|
try {
|
|
242
248
|
this.log(`ach ${v.target} is out (this is ${version}): taking no new work, ${this.o.runner.busy()} run(s) to finish first`);
|
|
243
249
|
await this.o.runner.quiesce();
|
|
244
|
-
saveUpdateState(this.o.home, { target: v.target, at: now, attempts: (last?.attempts ?? 0) + 1 });
|
|
250
|
+
saveUpdateState(this.o.home, { target: v.target, at: now, attempts: (last?.attempts ?? 0) + 1, previous: version });
|
|
245
251
|
const r = await installRelease(kind, v.target, this.o.exec);
|
|
246
252
|
if (!r.ok) {
|
|
247
253
|
this.log(`update to ${v.target} failed: ${r.detail}; staying on ${version}`);
|
|
@@ -258,6 +264,66 @@ export class SelfUpdater {
|
|
|
258
264
|
}
|
|
259
265
|
}
|
|
260
266
|
}
|
|
267
|
+
// ---- the brake: a release that keeps failing to start goes back to the one before ---------------------------------------------
|
|
268
|
+
const bootsFile = (home) => join(home, 'boots.json');
|
|
269
|
+
const badFile = (home) => join(home, 'bad-releases.json');
|
|
270
|
+
/** This many starts of one release inside BOOT_WINDOW_MS, none of them healthy, and it is called bad. */
|
|
271
|
+
export const BOOT_LIMIT = 3;
|
|
272
|
+
const BOOT_WINDOW_MS = 10 * 60_000;
|
|
273
|
+
const readJson = (f, d) => { try {
|
|
274
|
+
return JSON.parse(readFileSync(f, 'utf8'));
|
|
275
|
+
}
|
|
276
|
+
catch {
|
|
277
|
+
return d;
|
|
278
|
+
} };
|
|
279
|
+
const writeJson = (home, f, v) => {
|
|
280
|
+
try {
|
|
281
|
+
if (!existsSync(home))
|
|
282
|
+
mkdirSync(home, { recursive: true, mode: 0o700 });
|
|
283
|
+
writeFileSync(f, JSON.stringify(v), { mode: 0o600 });
|
|
284
|
+
}
|
|
285
|
+
catch { /* best effort */ }
|
|
286
|
+
};
|
|
287
|
+
/** Releases this machine found bad (they kept failing to start): never installed again here. */
|
|
288
|
+
export const localBad = (home) => readJson(badFile(home), []).filter(isVersion);
|
|
289
|
+
const isHealthy = (home, version) => { const b = readJson(bootsFile(home), null); return !!b && b.version === version && b.healthy; };
|
|
290
|
+
/** The runner has worked for a while on this release (it reached the hub and kept going): the release is good. */
|
|
291
|
+
export function markHealthy(home, version = VERSION) {
|
|
292
|
+
const b = readJson(bootsFile(home), null);
|
|
293
|
+
if (b && b.version === version && b.healthy)
|
|
294
|
+
return;
|
|
295
|
+
writeJson(home, bootsFile(home), { version, starts: [], healthy: true });
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Called first thing when `ach run` starts. A release this runner updated itself to, that has started BOOT_LIMIT times within
|
|
299
|
+
* ten minutes without once becoming healthy, is marked bad here and the release before it is installed again (a global install;
|
|
300
|
+
* an npx install has nothing to go back to and only marks it). Returns what it did; 'rolledback' means: exit UPDATE_EXIT_CODE.
|
|
301
|
+
*/
|
|
302
|
+
export async function bootGuard(home, o = {}) {
|
|
303
|
+
const version = o.version ?? VERSION;
|
|
304
|
+
const now = (o.now ?? Date.now)();
|
|
305
|
+
const prev = readJson(bootsFile(home), null);
|
|
306
|
+
const b = prev && prev.version === version ? { ...prev, starts: prev.starts.filter((t) => now - t < BOOT_WINDOW_MS) } : { version, starts: [], healthy: false };
|
|
307
|
+
if (b.healthy)
|
|
308
|
+
return 'ok';
|
|
309
|
+
b.starts.push(now);
|
|
310
|
+
writeJson(home, bootsFile(home), b);
|
|
311
|
+
const upd = loadUpdateState(home);
|
|
312
|
+
if (b.starts.length < BOOT_LIMIT || !upd?.previous || upd.target !== version || upd.previous === version)
|
|
313
|
+
return 'ok';
|
|
314
|
+
const log = o.log ?? ((s) => console.error(s));
|
|
315
|
+
writeJson(home, badFile(home), [...new Set([...localBad(home), version])]);
|
|
316
|
+
log(`[ach update] ${version} started ${b.starts.length} times in ten minutes without working: marked bad here, going back to ${upd.previous}`);
|
|
317
|
+
const kind = await detectInstall({ self: o.self, exec: o.exec, version });
|
|
318
|
+
if (kind.kind !== 'global') {
|
|
319
|
+
log(`[ach update] cannot go back by itself (${kind.kind === 'npx' ? 'an npx install fetches the newest release on every start' : kind.why}): ask the hub's admin to mark ${version} bad (ACH_BAD_CLIENTS)`);
|
|
320
|
+
return 'marked';
|
|
321
|
+
}
|
|
322
|
+
const r = await installRelease(kind, upd.previous, o.exec);
|
|
323
|
+
log(`[ach update] ${r.ok ? `back on ${upd.previous}` : `going back failed: ${r.detail}`}`);
|
|
324
|
+
writeJson(home, bootsFile(home), { version: upd.previous, starts: [], healthy: false });
|
|
325
|
+
return r.ok ? 'rolledback' : 'marked';
|
|
326
|
+
}
|
|
261
327
|
// ---- the MCP session -------------------------------------------------------------------------------------------------------
|
|
262
328
|
export function staleText(latest, lang = 'en', current = VERSION) {
|
|
263
329
|
return lang === 'zh'
|
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.
|
|
3
|
+
"version": "3.26.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",
|