@koalaauto/agentchannel 3.34.4 → 3.35.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.d.ts +14 -0
- package/dist/src/adapters/claude.js +44 -2
- package/dist/src/adapters/codex.d.ts +6 -0
- package/dist/src/adapters/codex.js +54 -2
- package/dist/src/cli.js +8 -1
- package/dist/src/client.d.ts +3 -1
- package/dist/src/client.js +4 -3
- package/dist/src/env.d.ts +8 -1
- package/dist/src/env.js +26 -3
- package/dist/src/prompts.js +2 -2
- package/dist/src/runner/runner.d.ts +4 -2
- package/dist/src/runner/runner.js +27 -11
- package/dist/src/runner/workspace.d.ts +5 -0
- package/dist/src/runner/workspace.js +20 -0
- package/dist/src/selfupdate.d.ts +34 -1
- package/dist/src/selfupdate.js +62 -10
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +1 -1
|
@@ -9,6 +9,20 @@ export declare const WORK_ACH_TOOLS: string[];
|
|
|
9
9
|
export declare const ANSWER_ACH_TOOLS: string[];
|
|
10
10
|
/** §16 mention runs: read the thread and channel, reply in the thread (with evidence, or --escalate). */
|
|
11
11
|
export declare const MENTION_ACH_TOOLS: string[];
|
|
12
|
+
/**
|
|
13
|
+
* Mention runs may also read the repository's history: who changed what and when is what people ask in a thread. The sandbox
|
|
14
|
+
* does not make these read-only by itself (the run's directory stays writable to a sandboxed command; live-tested:
|
|
15
|
+
* `git log --output=<file>` wrote the file), so mentionGitDenied() checks every git command of a mention run before it starts.
|
|
16
|
+
*/
|
|
17
|
+
export declare const MENTION_GIT_TOOLS: string[];
|
|
18
|
+
/**
|
|
19
|
+
* Why a mention run may not run this git command (undefined: it may). One plain command of the five: nothing a shell would
|
|
20
|
+
* expand, chain or redirect, no option that writes a file (`--output`, in any abbreviation git accepts) or names a program to
|
|
21
|
+
* run (`--ext-diff`, `-c`, `--exec`), and nothing before `git` (an environment variable can name a program too).
|
|
22
|
+
*/
|
|
23
|
+
export declare function mentionGitDenied(command: string): string | undefined;
|
|
24
|
+
/** PreToolUse for a mention run's Bash: the git rules above (a hook runs for pre-approved commands too). */
|
|
25
|
+
export declare function mentionGitHook(): HookCallbackMatcher;
|
|
12
26
|
/** canUseTool for workdir: path policy (reads under $HOME, writes outside cwd) plus the Bash deny list. */
|
|
13
27
|
export declare function workdirCanUseTool(pol: PathPolicy): CanUseTool;
|
|
14
28
|
/**
|
|
@@ -32,6 +32,48 @@ export const WORK_ACH_TOOLS = [
|
|
|
32
32
|
export const ANSWER_ACH_TOOLS = ['Bash(ach answer:*)', 'Bash(ach decide-request:*)', 'Bash(ach ask-human:*)', 'Bash(ach task:*)'];
|
|
33
33
|
/** §16 mention runs: read the thread and channel, reply in the thread (with evidence, or --escalate). */
|
|
34
34
|
export const MENTION_ACH_TOOLS = ['Bash(ach reply:*)', 'Bash(ach thread:*)', 'Bash(ach channel:*)'];
|
|
35
|
+
/**
|
|
36
|
+
* Mention runs may also read the repository's history: who changed what and when is what people ask in a thread. The sandbox
|
|
37
|
+
* does not make these read-only by itself (the run's directory stays writable to a sandboxed command; live-tested:
|
|
38
|
+
* `git log --output=<file>` wrote the file), so mentionGitDenied() checks every git command of a mention run before it starts.
|
|
39
|
+
*/
|
|
40
|
+
export const MENTION_GIT_TOOLS = ['Bash(git log:*)', 'Bash(git show:*)', 'Bash(git diff:*)', 'Bash(git blame:*)', 'Bash(git status:*)'];
|
|
41
|
+
/**
|
|
42
|
+
* Why a mention run may not run this git command (undefined: it may). One plain command of the five: nothing a shell would
|
|
43
|
+
* expand, chain or redirect, no option that writes a file (`--output`, in any abbreviation git accepts) or names a program to
|
|
44
|
+
* run (`--ext-diff`, `-c`, `--exec`), and nothing before `git` (an environment variable can name a program too).
|
|
45
|
+
*/
|
|
46
|
+
export function mentionGitDenied(command) {
|
|
47
|
+
const cmd = command.trim();
|
|
48
|
+
if (!/^git(\s|$)/.test(cmd))
|
|
49
|
+
return undefined;
|
|
50
|
+
if (/[;&|<>$`\\(){}\n\r]/.test(cmd))
|
|
51
|
+
return 'git runs here as one plain command: no pipes, redirects, `&&`, `$(...)` or line breaks';
|
|
52
|
+
// quotes are dropped before the options are read: the shell joins `-"-output"` into `--output`
|
|
53
|
+
const args = cmd.replace(/["']/g, '').split(/\s+/).slice(1);
|
|
54
|
+
if (!['log', 'show', 'diff', 'blame', 'status'].includes(args[0] ?? ''))
|
|
55
|
+
return 'only git log, git show, git diff, git blame and git status run here';
|
|
56
|
+
if (args.some((a) => /^--ou/.test(a)))
|
|
57
|
+
return 'this run does not write files: no --output';
|
|
58
|
+
if (args.some((a) => /^--(ext-diff|exec|no-index|textconv)\b/.test(a)))
|
|
59
|
+
return `this run reads the repository's history only: no ${args.find((a) => /^--(ext-diff|exec|no-index|textconv)\b/.test(a))}`;
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
/** PreToolUse for a mention run's Bash: the git rules above (a hook runs for pre-approved commands too). */
|
|
63
|
+
export function mentionGitHook() {
|
|
64
|
+
return {
|
|
65
|
+
hooks: [
|
|
66
|
+
async (input) => {
|
|
67
|
+
if (input.hook_event_name !== 'PreToolUse' || input.tool_name !== 'Bash')
|
|
68
|
+
return {};
|
|
69
|
+
const why = mentionGitDenied(String((input.tool_input ?? {}).command ?? ''));
|
|
70
|
+
if (!why)
|
|
71
|
+
return {};
|
|
72
|
+
return { hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'deny', permissionDecisionReason: why } };
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
};
|
|
76
|
+
}
|
|
35
77
|
/** canUseTool for workdir: path policy (reads under $HOME, writes outside cwd) plus the Bash deny list. */
|
|
36
78
|
export function workdirCanUseTool(pol) {
|
|
37
79
|
return async (toolName, input) => {
|
|
@@ -145,9 +187,9 @@ export function claudePermOptions(perm, o) {
|
|
|
145
187
|
...base,
|
|
146
188
|
// pre-approved at every level: without that, Claude Code does not offer Glob and Grep to the model at workdir (live
|
|
147
189
|
// test). The PreToolUse hook checks them; the SDK's notice that canUseTool is shadowed for them is expected.
|
|
148
|
-
allowedTools: ['Read', 'Glob', 'Grep', ...achTools],
|
|
190
|
+
allowedTools: ['Read', 'Glob', 'Grep', ...achTools, ...(o.mode === 'mention' ? MENTION_GIT_TOOLS : [])],
|
|
149
191
|
sandbox,
|
|
150
|
-
hooks: { PreToolUse: [pathPolicyHook(pol)] },
|
|
192
|
+
hooks: { PreToolUse: [pathPolicyHook(pol), ...(o.mode === 'mention' ? [mentionGitHook()] : [])] },
|
|
151
193
|
};
|
|
152
194
|
if (perm === 'read')
|
|
153
195
|
return { ...common, permissionMode: 'dontAsk' };
|
|
@@ -99,6 +99,12 @@ export declare function codexToolEnd(item: any): {
|
|
|
99
99
|
exit?: number;
|
|
100
100
|
output?: string;
|
|
101
101
|
};
|
|
102
|
+
/**
|
|
103
|
+
* The model a Codex thread ran on. The SDK's events do not name it, but Codex records it in the thread's session file
|
|
104
|
+
* (<CODEX_HOME>/sessions/<y>/<m>/<d>/rollout-<time>-<thread id>.jsonl): the last one named there, read from the file's first and
|
|
105
|
+
* last megabyte. Undefined when the file is not there or says nothing (the panel then shows no model, as before).
|
|
106
|
+
*/
|
|
107
|
+
export declare function codexSessionModel(codexHome: string | undefined, threadId: string | undefined): string | undefined;
|
|
102
108
|
/** Codex runtime adapter (@openai/codex-sdk). Cancel: see killCodexTree. */
|
|
103
109
|
export declare class CodexAdapter implements RuntimeAdapter {
|
|
104
110
|
private o;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { closeSync, openSync, readdirSync, readSync, statSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
2
4
|
import { readable, systemPaths } from './scope.js';
|
|
3
5
|
import { KILL_GRACE_MS } from './procgroup.js';
|
|
4
6
|
import { modelId } from './types.js';
|
|
@@ -221,6 +223,53 @@ export function codexToolEnd(item) {
|
|
|
221
223
|
return {};
|
|
222
224
|
}
|
|
223
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* The model a Codex thread ran on. The SDK's events do not name it, but Codex records it in the thread's session file
|
|
228
|
+
* (<CODEX_HOME>/sessions/<y>/<m>/<d>/rollout-<time>-<thread id>.jsonl): the last one named there, read from the file's first and
|
|
229
|
+
* last megabyte. Undefined when the file is not there or says nothing (the panel then shows no model, as before).
|
|
230
|
+
*/
|
|
231
|
+
export function codexSessionModel(codexHome, threadId) {
|
|
232
|
+
if (!codexHome || !threadId || !/^[A-Za-z0-9-]{8,80}$/.test(threadId))
|
|
233
|
+
return undefined;
|
|
234
|
+
try {
|
|
235
|
+
const want = `-${threadId}.jsonl`;
|
|
236
|
+
const walk = (dir, depth) => {
|
|
237
|
+
// newest first: the thread's file is under the day it started
|
|
238
|
+
for (const e of readdirSync(dir, { withFileTypes: true }).sort((a, b) => (a.name < b.name ? 1 : -1))) {
|
|
239
|
+
if (e.isDirectory() && depth < 3) {
|
|
240
|
+
const hit = walk(join(dir, e.name), depth + 1);
|
|
241
|
+
if (hit)
|
|
242
|
+
return hit;
|
|
243
|
+
}
|
|
244
|
+
else if (e.isFile() && e.name.endsWith(want))
|
|
245
|
+
return join(dir, e.name);
|
|
246
|
+
}
|
|
247
|
+
return undefined;
|
|
248
|
+
};
|
|
249
|
+
const file = walk(join(codexHome, 'sessions'), 0);
|
|
250
|
+
if (!file)
|
|
251
|
+
return undefined;
|
|
252
|
+
const size = statSync(file).size;
|
|
253
|
+
const CHUNK = 1 << 20;
|
|
254
|
+
const fd = openSync(file, 'r');
|
|
255
|
+
let text = '';
|
|
256
|
+
try {
|
|
257
|
+
const read = (pos, len) => {
|
|
258
|
+
const b = Buffer.alloc(len);
|
|
259
|
+
return b.subarray(0, readSync(fd, b, 0, len, pos)).toString('utf8');
|
|
260
|
+
};
|
|
261
|
+
text = size <= 2 * CHUNK ? read(0, size) : `${read(0, CHUNK)}\n${read(size - CHUNK, CHUNK)}`;
|
|
262
|
+
}
|
|
263
|
+
finally {
|
|
264
|
+
closeSync(fd);
|
|
265
|
+
}
|
|
266
|
+
const all = [...text.matchAll(/"model":"([^"\\]{1,80})"/g)];
|
|
267
|
+
return all.length ? modelId(all[all.length - 1][1]) : undefined;
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
return undefined;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
224
273
|
/** Codex runtime adapter (@openai/codex-sdk). Cancel: see killCodexTree. */
|
|
225
274
|
export class CodexAdapter {
|
|
226
275
|
o;
|
|
@@ -329,8 +378,11 @@ export class CodexAdapter {
|
|
|
329
378
|
estimated: true,
|
|
330
379
|
ok: !error,
|
|
331
380
|
error,
|
|
332
|
-
//
|
|
333
|
-
...(
|
|
381
|
+
// the SDK does not say which model ran: the one pinned with --model, else what Codex wrote in the thread's session file
|
|
382
|
+
...(() => {
|
|
383
|
+
const model = modelId(this.o.model) ?? codexSessionModel(opts.env.CODEX_HOME, sessionId);
|
|
384
|
+
return model ? { model } : {};
|
|
385
|
+
})(),
|
|
334
386
|
};
|
|
335
387
|
}
|
|
336
388
|
}
|
package/dist/src/cli.js
CHANGED
|
@@ -16,7 +16,7 @@ import { isPerm } from './perm.js';
|
|
|
16
16
|
import { AttachError, humanSize, isLinkRef, resolveAttachments, taskFiles } from './attachments.js';
|
|
17
17
|
export { VERSION } from './version.js';
|
|
18
18
|
import { VERSION } from './version.js';
|
|
19
|
-
import { bootGuard, markHealthy, SelfUpdater, UPDATE_EXIT_CODE } from './selfupdate.js';
|
|
19
|
+
import { bootGuard, markHealthy, SelfUpdater, superviseSelf, UPDATE_EXIT_CODE } from './selfupdate.js';
|
|
20
20
|
import { installProxy } from './netproxy.js';
|
|
21
21
|
/** At a terminal, a command that replaces an agent's key says what that cuts off and asks (default no). --yes skips it; scripts are not asked. */
|
|
22
22
|
async function confirmKeyRotation(io, v, agentName) {
|
|
@@ -544,6 +544,8 @@ async function dispatch(p, io) {
|
|
|
544
544
|
...(str(v.channel) ? { channel: channelRef(str(v.channel)) } : {}),
|
|
545
545
|
}, files());
|
|
546
546
|
out(v.json ? t : `sent task ${t.ref ?? t.id} in #${t.channel_name ?? 'general'} (${t.status})${linkOf(env, t) ? `: ${linkOf(env, t)}` : ''}`);
|
|
547
|
+
if (!v.json && t.warning)
|
|
548
|
+
io.err(`note: ${t.warning}`);
|
|
547
549
|
return 0;
|
|
548
550
|
}
|
|
549
551
|
case 'schedule add': {
|
|
@@ -1734,6 +1736,11 @@ async function runCommand(p, io) {
|
|
|
1734
1736
|
if (end === 'unauthorized')
|
|
1735
1737
|
return authExit(io);
|
|
1736
1738
|
if (updater.restarting) {
|
|
1739
|
+
// started by hand (no systemd / launchd behind it) from a global install: nothing would start it again, so it does that itself
|
|
1740
|
+
if (updater.installed === 'global' && process.env.ACH_SUPERVISED !== '1' && !(await import('./servicefix.js')).startedByService(me.name, process.platform, process.env)) {
|
|
1741
|
+
io.err('ach run: updated; starting the new release here');
|
|
1742
|
+
return superviseSelf({ log: io.err });
|
|
1743
|
+
}
|
|
1737
1744
|
io.err(`ach run: updated; exiting ${UPDATE_EXIT_CODE} so the service restarts on the new release (started by hand? run it again)`);
|
|
1738
1745
|
return UPDATE_EXIT_CODE;
|
|
1739
1746
|
}
|
package/dist/src/client.d.ts
CHANGED
|
@@ -65,6 +65,8 @@ export interface Task {
|
|
|
65
65
|
seq?: number;
|
|
66
66
|
ref?: string;
|
|
67
67
|
url?: string;
|
|
68
|
+
/** Set on the answer to a send: something the sender should check (see the hub's otherRepo). */
|
|
69
|
+
warning?: string;
|
|
68
70
|
/** §16: the task's channel. */
|
|
69
71
|
channel?: string;
|
|
70
72
|
channel_name?: string;
|
|
@@ -456,7 +458,7 @@ export declare class Client {
|
|
|
456
458
|
/** The worker cannot run on its machine (not logged in, sandbox broken): the task goes back to submitted, not failed. */
|
|
457
459
|
release(taskId: string, reason: string, run_id?: string): Promise<any>;
|
|
458
460
|
/** The repo names this runner can work in (never local paths): the directory shows them, and the hub refuses a task for another repo. */
|
|
459
|
-
reportRepos(repos: string[]): Promise<any>;
|
|
461
|
+
reportRepos(repos: string[], remotes?: Record<string, string>): Promise<any>;
|
|
460
462
|
/** How this runner runs tasks: its --perm, the tool, and the NAMES of the variables it hands its agents (never values); and how
|
|
461
463
|
* it was started (directory, home, --repo paths, its supervisor), which the owner's page turns into the line that restarts it. */
|
|
462
464
|
reportRunner(r: {
|
package/dist/src/client.js
CHANGED
|
@@ -274,7 +274,8 @@ export class Client {
|
|
|
274
274
|
}
|
|
275
275
|
async sendTask(input, files) {
|
|
276
276
|
const r = await this.ach('POST', '/tasks', input, files);
|
|
277
|
-
|
|
277
|
+
// the hub's note about the send (the handoff names a repository this agent's runner does not work in) travels with the task
|
|
278
|
+
return r?.task ? { ...r.task, ...(typeof r.warning === 'string' ? { warning: r.warning } : {}) } : r;
|
|
278
279
|
}
|
|
279
280
|
/** The sender's side accepts a task that waits for acceptance: it is completed. */
|
|
280
281
|
async acceptTask(taskId, note) {
|
|
@@ -378,8 +379,8 @@ export class Client {
|
|
|
378
379
|
return this.ach('POST', `/tasks/${enc(taskId)}/release`, { reason, ...(run_id ? { run_id } : {}) });
|
|
379
380
|
}
|
|
380
381
|
/** The repo names this runner can work in (never local paths): the directory shows them, and the hub refuses a task for another repo. */
|
|
381
|
-
async reportRepos(repos) {
|
|
382
|
-
return this.ach('PUT', '/me/repos', { repos });
|
|
382
|
+
async reportRepos(repos, remotes) {
|
|
383
|
+
return this.ach('PUT', '/me/repos', { repos, ...(remotes ? { remotes } : {}) });
|
|
383
384
|
}
|
|
384
385
|
/** How this runner runs tasks: its --perm, the tool, and the NAMES of the variables it hands its agents (never values); and how
|
|
385
386
|
* it was started (directory, home, --repo paths, its supervisor), which the owner's page turns into the line that restarts it. */
|
package/dist/src/env.d.ts
CHANGED
|
@@ -6,6 +6,13 @@ export declare const STRIPPED_ENV: readonly ["CLAUDECODE", "CLAUDE_CODE_SESSION_
|
|
|
6
6
|
* sockets) is dropped unless the runner names it with `--pass-env NAME`.
|
|
7
7
|
*/
|
|
8
8
|
export declare const ENV_ALLOWLIST: readonly ["PATH", "HOME", "LANG", "TERM", "SHELL", "USER", "TMPDIR"];
|
|
9
|
+
/**
|
|
10
|
+
* Windows adds the system vars programs cannot start without: Codex's sandbox
|
|
11
|
+
* refuses to start with no LOCALAPPDATA (TASK-59), cmd needs ComSpec and
|
|
12
|
+
* SystemRoot, PATHEXT finds `.cmd` shims. No secrets among them. USERPROFILE,
|
|
13
|
+
* TEMP and TMP are set to the run's scratch home by prepareAgentHome.
|
|
14
|
+
*/
|
|
15
|
+
export declare const WINDOWS_ENV_ALLOWLIST: readonly ["SystemRoot", "SystemDrive", "windir", "ComSpec", "PATHEXT", "OS", "LOCALAPPDATA", "APPDATA", "ProgramData", "ProgramFiles", "ProgramFiles(x86)", "ProgramW6432", "CommonProgramFiles", "CommonProgramFiles(x86)", "CommonProgramW6432", "USERNAME", "USERDOMAIN", "COMPUTERNAME", "NUMBER_OF_PROCESSORS", "PROCESSOR_ARCHITECTURE", "PSModulePath"];
|
|
9
16
|
/**
|
|
10
17
|
* Never passed, even with --pass-env: runner credentials and the Claude Code
|
|
11
18
|
* nesting / messaging / socket / host-auth vars of the parent session.
|
|
@@ -28,4 +35,4 @@ export interface AgentEnvInput {
|
|
|
28
35
|
passEnv?: string[];
|
|
29
36
|
}
|
|
30
37
|
/** Env for a spawned agent: allowlisted parent vars + --pass-env names + task-scoped ACH vars. */
|
|
31
|
-
export declare function buildAgentEnv(base: NodeJS.ProcessEnv | Record<string, string | undefined>, a: AgentEnvInput): Record<string, string>;
|
|
38
|
+
export declare function buildAgentEnv(base: NodeJS.ProcessEnv | Record<string, string | undefined>, a: AgentEnvInput, platform?: NodeJS.Platform): Record<string, string>;
|
package/dist/src/env.js
CHANGED
|
@@ -12,6 +12,28 @@ export const STRIPPED_ENV = [
|
|
|
12
12
|
* sockets) is dropped unless the runner names it with `--pass-env NAME`.
|
|
13
13
|
*/
|
|
14
14
|
export const ENV_ALLOWLIST = ['PATH', 'HOME', 'LANG', 'TERM', 'SHELL', 'USER', 'TMPDIR'];
|
|
15
|
+
/**
|
|
16
|
+
* Windows adds the system vars programs cannot start without: Codex's sandbox
|
|
17
|
+
* refuses to start with no LOCALAPPDATA (TASK-59), cmd needs ComSpec and
|
|
18
|
+
* SystemRoot, PATHEXT finds `.cmd` shims. No secrets among them. USERPROFILE,
|
|
19
|
+
* TEMP and TMP are set to the run's scratch home by prepareAgentHome.
|
|
20
|
+
*/
|
|
21
|
+
export const WINDOWS_ENV_ALLOWLIST = [
|
|
22
|
+
'SystemRoot', 'SystemDrive', 'windir', 'ComSpec', 'PATHEXT', 'OS',
|
|
23
|
+
'LOCALAPPDATA', 'APPDATA', 'ProgramData', 'ProgramFiles', 'ProgramFiles(x86)', 'ProgramW6432',
|
|
24
|
+
'CommonProgramFiles', 'CommonProgramFiles(x86)', 'CommonProgramW6432',
|
|
25
|
+
'USERNAME', 'USERDOMAIN', 'COMPUTERNAME', 'NUMBER_OF_PROCESSORS', 'PROCESSOR_ARCHITECTURE', 'PSModulePath',
|
|
26
|
+
];
|
|
27
|
+
/** Windows env names ignore case (`Path`): the exact name first, then any spelling. */
|
|
28
|
+
function lookup(base, k, win) {
|
|
29
|
+
if (base[k] !== undefined || !win)
|
|
30
|
+
return base[k];
|
|
31
|
+
const lower = k.toLowerCase();
|
|
32
|
+
for (const [name, v] of Object.entries(base))
|
|
33
|
+
if (v !== undefined && name.toLowerCase() === lower)
|
|
34
|
+
return v;
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
15
37
|
/**
|
|
16
38
|
* Never passed, even with --pass-env: runner credentials and the Claude Code
|
|
17
39
|
* nesting / messaging / socket / host-auth vars of the parent session.
|
|
@@ -26,10 +48,11 @@ export function neverPass(name) {
|
|
|
26
48
|
return /^CLAUDE_CODE_.*(SESSION|ENTRYPOINT|EXECPATH|SSE|PORT|SOCK|IPC|MESSAG|HOST|OAUTH|TOKEN|AUTH|BRIDGE|REMOTE)/.test(name);
|
|
27
49
|
}
|
|
28
50
|
/** Env for a spawned agent: allowlisted parent vars + --pass-env names + task-scoped ACH vars. */
|
|
29
|
-
export function buildAgentEnv(base, a) {
|
|
51
|
+
export function buildAgentEnv(base, a, platform = process.platform) {
|
|
30
52
|
const env = {};
|
|
31
|
-
|
|
32
|
-
|
|
53
|
+
const win = platform === 'win32';
|
|
54
|
+
for (const k of [...ENV_ALLOWLIST, ...(win ? WINDOWS_ENV_ALLOWLIST : []), ...(a.passEnv ?? [])]) {
|
|
55
|
+
const v = lookup(base, k, win);
|
|
33
56
|
if (v === undefined || neverPass(k))
|
|
34
57
|
continue;
|
|
35
58
|
env[k] = v;
|
package/dist/src/prompts.js
CHANGED
|
@@ -401,7 +401,7 @@ export function buildMentionPrompt(c) {
|
|
|
401
401
|
'- If you can answer from evidence, reply in the thread: `ach reply --evidence "<files/commands you checked>" "<reply>"`',
|
|
402
402
|
'- If it needs a human (money, product direction, anything irreversible, or you are not sure): `ach reply --escalate "<why, with options and money impact>"` (it goes to whoever mentioned you; add `--to owner` when the decision is your own owner\'s, e.g. your owner must approve something)',
|
|
403
403
|
'- `ach thread` shows the whole thread; `ach channel` the channel. Reply once, then stop.',
|
|
404
|
-
'-
|
|
404
|
+
'- Besides these three `ach` commands only `git log`, `git show`, `git diff`, `git blame` and `git status` run here, each as one plain command (no pipes, no `cd`); any other command is refused (that does not mean `ach reply` is). Read files with Read, Glob and Grep.',
|
|
405
405
|
'- If `ach reply` itself is refused or fails, end with the reply as your last message, written to the people in the thread: it is posted there as your reply.',
|
|
406
406
|
'- Mention other agents (@name) only when you really need them; every agent-to-agent mention counts against the thread\'s hop limit.',
|
|
407
407
|
];
|
|
@@ -418,7 +418,7 @@ export function buildMentionPrompt(c) {
|
|
|
418
418
|
}),
|
|
419
419
|
'',
|
|
420
420
|
'Rules:',
|
|
421
|
-
c.structured ? '- Do not modify anything. Look at files, git history and command output to find the answer.' : '- Do not modify anything. Look at the files to find the answer.',
|
|
421
|
+
c.structured ? '- Do not modify anything. Look at files, git history and command output to find the answer.' : '- Do not modify anything. Look at the files and the git history to find the answer.',
|
|
422
422
|
SEARCH_FIRST_RULE,
|
|
423
423
|
`- ${UNTRUSTED_RULE}`,
|
|
424
424
|
LINK_RULE,
|
|
@@ -148,14 +148,16 @@ export declare const CODEX_WORKER_CONFIG: string;
|
|
|
148
148
|
* refreshed login stays the user's. Sessions of the run stay in this home, so
|
|
149
149
|
* a resumed run of the same task finds its thread.
|
|
150
150
|
*/
|
|
151
|
-
export declare function prepareCodexHome(home: string, realCodexHome?: string): string;
|
|
151
|
+
export declare function prepareCodexHome(home: string, realCodexHome?: string, platform?: NodeJS.Platform): string;
|
|
152
|
+
/** The user's real home: HOME, or USERPROFILE on Windows, where HOME is usually not set. */
|
|
153
|
+
export declare function realHomeOf(env: NodeJS.ProcessEnv | Record<string, string | undefined>, platform?: NodeJS.Platform): string | undefined;
|
|
152
154
|
/**
|
|
153
155
|
* B1: a per-task scratch HOME for spawned agents, so `~/.config/agentchannel`
|
|
154
156
|
* (agent key file, admin session, runner state) is not reachable through
|
|
155
157
|
* $HOME. Runtime config (.claude, .codex) is linked, the git identity
|
|
156
158
|
* (.gitconfig) copied; npm keeps the real cache via npm_config_cache.
|
|
157
159
|
*/
|
|
158
|
-
export declare function prepareAgentHome(root: string, agentName: string, key: string, realHome?: string, realCodexHome?: string): {
|
|
160
|
+
export declare function prepareAgentHome(root: string, agentName: string, key: string, realHome?: string, realCodexHome?: string, platform?: NodeJS.Platform): {
|
|
159
161
|
home: string;
|
|
160
162
|
env: Record<string, string>;
|
|
161
163
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomBytes } from 'node:crypto';
|
|
2
|
-
import { appendFileSync, copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, rmSync, symlinkSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { appendFileSync, copyFileSync, existsSync, linkSync, lstatSync, mkdirSync, readdirSync, readFileSync, rmSync, symlinkSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { tmpdir } from 'node:os';
|
|
4
4
|
import { dirname, join } from 'node:path';
|
|
5
5
|
import { gitCommonDir } from '../adapters/index.js';
|
|
@@ -124,7 +124,7 @@ export const CODEX_WORKER_CONFIG = [
|
|
|
124
124
|
* refreshed login stays the user's. Sessions of the run stay in this home, so
|
|
125
125
|
* a resumed run of the same task finds its thread.
|
|
126
126
|
*/
|
|
127
|
-
export function prepareCodexHome(home, realCodexHome) {
|
|
127
|
+
export function prepareCodexHome(home, realCodexHome, platform = process.platform) {
|
|
128
128
|
const dir = join(home, '.codex');
|
|
129
129
|
try {
|
|
130
130
|
// an older scratch home linked the whole ~/.codex: replace the link
|
|
@@ -152,19 +152,31 @@ export function prepareCodexHome(home, realCodexHome) {
|
|
|
152
152
|
symlinkSync(src, dst);
|
|
153
153
|
}
|
|
154
154
|
catch {
|
|
155
|
-
|
|
155
|
+
// Windows makes file symlinks only with developer mode or admin; a hard link needs neither
|
|
156
|
+
if (platform === 'win32') {
|
|
157
|
+
try {
|
|
158
|
+
linkSync(src, dst);
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
/* best effort: codex then reports "not logged in" */
|
|
162
|
+
}
|
|
163
|
+
}
|
|
156
164
|
}
|
|
157
165
|
}
|
|
158
166
|
}
|
|
159
167
|
return dir;
|
|
160
168
|
}
|
|
169
|
+
/** The user's real home: HOME, or USERPROFILE on Windows, where HOME is usually not set. */
|
|
170
|
+
export function realHomeOf(env, platform = process.platform) {
|
|
171
|
+
return env.HOME || (platform === 'win32' ? env.USERPROFILE : undefined) || undefined;
|
|
172
|
+
}
|
|
161
173
|
/**
|
|
162
174
|
* B1: a per-task scratch HOME for spawned agents, so `~/.config/agentchannel`
|
|
163
175
|
* (agent key file, admin session, runner state) is not reachable through
|
|
164
176
|
* $HOME. Runtime config (.claude, .codex) is linked, the git identity
|
|
165
177
|
* (.gitconfig) copied; npm keeps the real cache via npm_config_cache.
|
|
166
178
|
*/
|
|
167
|
-
export function prepareAgentHome(root, agentName, key, realHome, realCodexHome) {
|
|
179
|
+
export function prepareAgentHome(root, agentName, key, realHome, realCodexHome, platform = process.platform) {
|
|
168
180
|
const safe = (x) => x.replace(/[^A-Za-z0-9_.-]/g, '_').slice(0, 80);
|
|
169
181
|
const home = join(root, safe(agentName), safe(key));
|
|
170
182
|
mkdirSync(home, { recursive: true, mode: 0o700 });
|
|
@@ -173,11 +185,14 @@ export function prepareAgentHome(root, agentName, key, realHome, realCodexHome)
|
|
|
173
185
|
const tmp = join(home, 'tmp');
|
|
174
186
|
mkdirSync(tmp, { recursive: true, mode: 0o700 });
|
|
175
187
|
const env = { HOME: home, TMPDIR: tmp };
|
|
188
|
+
// Windows programs find the home in USERPROFILE and the temporary directory in TEMP/TMP
|
|
189
|
+
if (platform === 'win32')
|
|
190
|
+
Object.assign(env, { USERPROFILE: home, TEMP: tmp, TMP: tmp });
|
|
176
191
|
if (!realHome) {
|
|
177
|
-
env.CODEX_HOME = prepareCodexHome(home, realCodexHome);
|
|
192
|
+
env.CODEX_HOME = prepareCodexHome(home, realCodexHome, platform);
|
|
178
193
|
return { home, env };
|
|
179
194
|
}
|
|
180
|
-
for (const name of runtimeHomeLinks()) {
|
|
195
|
+
for (const name of runtimeHomeLinks(platform)) {
|
|
181
196
|
const src = join(realHome, name);
|
|
182
197
|
const dst = join(home, name);
|
|
183
198
|
if (!existsSync(src))
|
|
@@ -188,7 +203,8 @@ export function prepareAgentHome(root, agentName, key, realHome, realCodexHome)
|
|
|
188
203
|
catch {
|
|
189
204
|
try {
|
|
190
205
|
mkdirSync(dirname(dst), { recursive: true, mode: 0o700 });
|
|
191
|
-
|
|
206
|
+
// a junction links a Windows directory without developer mode or admin
|
|
207
|
+
symlinkSync(src, dst, platform === 'win32' && lstatSync(src).isDirectory() ? 'junction' : undefined);
|
|
192
208
|
}
|
|
193
209
|
catch {
|
|
194
210
|
/* best effort */
|
|
@@ -207,7 +223,7 @@ export function prepareAgentHome(root, agentName, key, realHome, realCodexHome)
|
|
|
207
223
|
const npmCache = join(realHome, '.npm');
|
|
208
224
|
if (existsSync(npmCache))
|
|
209
225
|
env.npm_config_cache = npmCache;
|
|
210
|
-
env.CODEX_HOME = prepareCodexHome(home, realCodexHome || join(realHome, '.codex'));
|
|
226
|
+
env.CODEX_HOME = prepareCodexHome(home, realCodexHome || join(realHome, '.codex'), platform);
|
|
211
227
|
return { home, env };
|
|
212
228
|
}
|
|
213
229
|
/** How long the runner trusts its copy of the agent's record before reading it again. */
|
|
@@ -449,7 +465,7 @@ export class Runner {
|
|
|
449
465
|
return;
|
|
450
466
|
}
|
|
451
467
|
try {
|
|
452
|
-
await this.o.client.reportRepos(names);
|
|
468
|
+
await this.o.client.reportRepos(names, await this.o.workspace.repoRemotes?.().catch(() => undefined));
|
|
453
469
|
this.reposReported = true;
|
|
454
470
|
}
|
|
455
471
|
catch (e) {
|
|
@@ -1248,7 +1264,7 @@ export class Runner {
|
|
|
1248
1264
|
}
|
|
1249
1265
|
/** Readable roots for the spawned agent besides its cwd (S4). */
|
|
1250
1266
|
readRoots(cwd, readRepos = [], taskId) {
|
|
1251
|
-
const home = (this.o.baseEnv ?? process.env)
|
|
1267
|
+
const home = realHomeOf(this.o.baseEnv ?? process.env);
|
|
1252
1268
|
return [
|
|
1253
1269
|
...toolchainReadRoots(home || undefined),
|
|
1254
1270
|
...[developerDir()].filter((d) => !!d),
|
|
@@ -1323,7 +1339,7 @@ export class Runner {
|
|
|
1323
1339
|
});
|
|
1324
1340
|
// B1: HOME is a per-task scratch dir (never the runner's own home).
|
|
1325
1341
|
const baseEnv = this.o.baseEnv ?? process.env;
|
|
1326
|
-
const realHome = baseEnv
|
|
1342
|
+
const realHome = realHomeOf(baseEnv);
|
|
1327
1343
|
Object.assign(env, prepareAgentHome(this.o.agentHomesDir ?? join(tmpdir(), 'ach-homes'), me.name, taskId, realHome, baseEnv.CODEX_HOME || undefined).env);
|
|
1328
1344
|
// a read-only GitHub token issued by the hub for this run (see githubToken)
|
|
1329
1345
|
const gh = await this.githubToken(rec);
|
|
@@ -17,6 +17,8 @@ export interface Workspace {
|
|
|
17
17
|
sensitiveChanges?(task: Task): Promise<string[]>;
|
|
18
18
|
/** The repo names a task may name (links.repo, links.repos): the runner tells the hub, which refuses others when sent. */
|
|
19
19
|
repoNames?(): string[];
|
|
20
|
+
/** Where each of those comes from: {name: "owner/name"} of its origin (never a local path). The hub tells a sender whose handoff names another repository. */
|
|
21
|
+
repoRemotes?(): Promise<Record<string, string>>;
|
|
20
22
|
/**
|
|
21
23
|
* Cross-repo: the task's links.repos (besides the primary repo), made readable.
|
|
22
24
|
* Unknown names throw (the task fails with the message).
|
|
@@ -28,6 +30,8 @@ export interface Workspace {
|
|
|
28
30
|
/** Paths whose change by a sender-chosen base needs the worker owner's approval (S1). */
|
|
29
31
|
export declare function isSensitivePath(p: string): boolean;
|
|
30
32
|
export declare const REPO_NAME_RE: RegExp;
|
|
33
|
+
/** "owner/name" of a git remote URL (git@host:owner/name.git, https://host/owner/name, ssh://git@host/owner/name), lowercase; '' when it has no such shape. */
|
|
34
|
+
export declare function remoteSlug(url: string): string;
|
|
31
35
|
/** P3: parse `--repo name=path` values (relative paths resolve against cwd). */
|
|
32
36
|
export declare function parseRepoFlags(values: string[], cwd?: string): Record<string, string>;
|
|
33
37
|
/**
|
|
@@ -44,6 +48,7 @@ export declare class GitWorkspace implements Workspace {
|
|
|
44
48
|
/** The local repo a task works in (P3). */
|
|
45
49
|
repoDir(task: Task): string;
|
|
46
50
|
repoNames(): string[];
|
|
51
|
+
repoRemotes(): Promise<Record<string, string>>;
|
|
47
52
|
/** Map a repo name to its local path, or fail with the names this runner knows. */
|
|
48
53
|
lookup(r: unknown, what: string): string;
|
|
49
54
|
/** Where read-only checkouts of a task's other repos go (next to, not inside, its worktree). */
|
|
@@ -29,6 +29,12 @@ export function isSensitivePath(p) {
|
|
|
29
29
|
return /^\.claude(\/|$)/.test(p) || p === '.mcp.json' || /(^|\/)(CLAUDE|AGENTS)(\.local)?\.md$/i.test(p) || /(^|\/)\.codex(\/|$)/.test(p);
|
|
30
30
|
}
|
|
31
31
|
export const REPO_NAME_RE = /^[A-Za-z0-9._-]{1,64}$/;
|
|
32
|
+
/** "owner/name" of a git remote URL (git@host:owner/name.git, https://host/owner/name, ssh://git@host/owner/name), lowercase; '' when it has no such shape. */
|
|
33
|
+
export function remoteSlug(url) {
|
|
34
|
+
// a host is required: a remote that is a local path says nothing (and a path never leaves this machine)
|
|
35
|
+
const m = /^(?:[a-z][a-z0-9+.-]*:\/\/[^/\s]+\/|[^/@\s]+@[^/:\s]+:)([A-Za-z0-9][A-Za-z0-9-]{0,38})\/([A-Za-z0-9._-]{1,100}?)(?:\.git)?\/?$/i.exec(url.trim());
|
|
36
|
+
return m ? `${m[1]}/${m[2]}`.toLowerCase() : '';
|
|
37
|
+
}
|
|
32
38
|
/** P3: parse `--repo name=path` values (relative paths resolve against cwd). */
|
|
33
39
|
export function parseRepoFlags(values, cwd = process.cwd()) {
|
|
34
40
|
const out = {};
|
|
@@ -68,6 +74,20 @@ export class GitWorkspace {
|
|
|
68
74
|
repoNames() {
|
|
69
75
|
return [...new Set([...Object.keys(this.repos), basename(this.dir)])].filter((n) => REPO_NAME_RE.test(n)).sort();
|
|
70
76
|
}
|
|
77
|
+
async repoRemotes() {
|
|
78
|
+
const out = {};
|
|
79
|
+
for (const n of this.repoNames()) {
|
|
80
|
+
try {
|
|
81
|
+
const slug = remoteSlug(await git(this.lookup(n, 'repo'), ['config', '--get', 'remote.origin.url']));
|
|
82
|
+
if (slug)
|
|
83
|
+
out[n] = slug;
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
/* not a git checkout, or no origin: nothing to say about it */
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
71
91
|
/** Map a repo name to its local path, or fail with the names this runner knows. */
|
|
72
92
|
lookup(r, what) {
|
|
73
93
|
if (typeof r !== 'string' || !REPO_NAME_RE.test(r))
|
package/dist/src/selfupdate.d.ts
CHANGED
|
@@ -29,6 +29,16 @@ export type ExecFn = (file: string, args: string[], o?: {
|
|
|
29
29
|
stdout: string;
|
|
30
30
|
stderr: string;
|
|
31
31
|
}>;
|
|
32
|
+
/**
|
|
33
|
+
* How to start `npm` from here. Beside this node when it is there (a version manager's bin dir is often not in a service's PATH),
|
|
34
|
+
* else PATH's. On Windows npm is a .cmd file, which Node refuses to start directly (EINVAL since 18.20 / 20.12): npm's own
|
|
35
|
+
* script is run with this node, or, where it is not beside node, `npm` goes through the shell.
|
|
36
|
+
*/
|
|
37
|
+
export declare function npmCommand(platform?: string, execPath?: string, exists?: (p: string) => boolean): {
|
|
38
|
+
file: string;
|
|
39
|
+
pre: string[];
|
|
40
|
+
shell: boolean;
|
|
41
|
+
};
|
|
32
42
|
export declare const defaultInstallExec: ExecFn;
|
|
33
43
|
export type InstallKind =
|
|
34
44
|
/** Started from the npx cache with a range spec (`@koalaauto/agentchannel@3`): a restart fetches the newest release. */
|
|
@@ -103,6 +113,8 @@ export declare class SelfUpdater {
|
|
|
103
113
|
private o;
|
|
104
114
|
/** True once the install is done and the runner is stopping: the process should exit UPDATE_EXIT_CODE. */
|
|
105
115
|
restarting: boolean;
|
|
116
|
+
/** How the release that was just installed got here (set with `restarting`). */
|
|
117
|
+
installed?: InstallKind['kind'];
|
|
106
118
|
private timer?;
|
|
107
119
|
private stopped;
|
|
108
120
|
private lastNudge;
|
|
@@ -117,14 +129,35 @@ export declare class SelfUpdater {
|
|
|
117
129
|
/** The hub just refused this release (426): check now, but not more than once in 10 minutes (the runner polls again every 30 s). */
|
|
118
130
|
nudge(): Promise<CheckResult> | undefined;
|
|
119
131
|
private heard;
|
|
132
|
+
private heardWait;
|
|
120
133
|
/**
|
|
121
134
|
* The hub names a release on every answer (`x-ach-latest-client`): when it is newer than this one, check now instead of at the
|
|
122
|
-
* next 6-hourly tick. Once per release,
|
|
135
|
+
* next 6-hourly tick. Once per release, again after five minutes when the release could not be installed yet (npm does not
|
|
136
|
+
* serve it the moment the hub names it), and after an hour if this one is still behind for another reason.
|
|
123
137
|
* What a check can never fix by itself (a manual verdict, ACH_AUTO_UPDATE=0) is not asked again for that release.
|
|
124
138
|
*/
|
|
125
139
|
heardLatest(latest: string): Promise<CheckResult> | undefined;
|
|
126
140
|
check(): Promise<CheckResult>;
|
|
127
141
|
}
|
|
142
|
+
export type SpawnSelf = (file: string, args: string[], env: NodeJS.ProcessEnv) => {
|
|
143
|
+
exit: Promise<number>;
|
|
144
|
+
kill: (sig: NodeJS.Signals) => void;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* After a global install replaced this CLI's files, run the same command line again (the new release) and stay as its parent: the
|
|
148
|
+
* terminal, the Startup script or whatever started the runner still sees one process. The child knows it is watched
|
|
149
|
+
* (ACH_SUPERVISED=1) and exits UPDATE_EXIT_CODE at its next update, which starts it again here, so there is never more than this
|
|
150
|
+
* one parent. Resolves with the exit code to pass on.
|
|
151
|
+
*/
|
|
152
|
+
export declare function superviseSelf(o?: {
|
|
153
|
+
log?: (s: string) => void;
|
|
154
|
+
spawnSelf?: SpawnSelf;
|
|
155
|
+
argv?: string[];
|
|
156
|
+
execPath?: string;
|
|
157
|
+
execArgv?: string[];
|
|
158
|
+
env?: NodeJS.ProcessEnv;
|
|
159
|
+
on?: (sig: NodeJS.Signals, f: () => void) => void;
|
|
160
|
+
}): Promise<number>;
|
|
128
161
|
/** This many starts of one release inside BOOT_WINDOW_MS, none of them healthy, and it is called bad. */
|
|
129
162
|
export declare const BOOT_LIMIT = 3;
|
|
130
163
|
/** Releases this machine found bad (they kept failing to start): never installed again here. */
|
package/dist/src/selfupdate.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// What it never does: move across a major release by itself (the protocol may have changed: a person decides), move a stable
|
|
12
12
|
// install onto a prerelease, touch a CLI it cannot tell how it was installed, or retry a failed update more than once a day.
|
|
13
13
|
// ACH_AUTO_UPDATE=0 turns the installing off (the log and the session notice remain).
|
|
14
|
-
import { execFile } from 'node:child_process';
|
|
14
|
+
import { execFile, spawn } from 'node:child_process';
|
|
15
15
|
import { accessSync, constants, existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
|
|
16
16
|
import { dirname, join, sep } from 'node:path';
|
|
17
17
|
import { thisCliPath } from './invite.js';
|
|
@@ -43,15 +43,24 @@ export function judge(hub, current = VERSION, proto = CLIENT_PROTO, localBad = [
|
|
|
43
43
|
}
|
|
44
44
|
return { action: 'update', target };
|
|
45
45
|
}
|
|
46
|
-
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
/**
|
|
47
|
+
* How to start `npm` from here. Beside this node when it is there (a version manager's bin dir is often not in a service's PATH),
|
|
48
|
+
* else PATH's. On Windows npm is a .cmd file, which Node refuses to start directly (EINVAL since 18.20 / 20.12): npm's own
|
|
49
|
+
* script is run with this node, or, where it is not beside node, `npm` goes through the shell.
|
|
50
|
+
*/
|
|
51
|
+
export function npmCommand(platform = process.platform, execPath = process.execPath, exists = existsSync) {
|
|
52
|
+
const bin = dirname(execPath);
|
|
53
|
+
if (platform === 'win32') {
|
|
54
|
+
const cli = join(bin, 'node_modules', 'npm', 'bin', 'npm-cli.js');
|
|
55
|
+
return exists(cli) ? { file: execPath, pre: [cli], shell: false } : { file: 'npm', pre: [], shell: true };
|
|
56
|
+
}
|
|
57
|
+
const beside = join(bin, 'npm');
|
|
58
|
+
return { file: exists(beside) ? beside : 'npm', pre: [], shell: false };
|
|
52
59
|
}
|
|
53
60
|
export const defaultInstallExec = (file, args, o) => new Promise((res) => {
|
|
54
|
-
|
|
61
|
+
// every argument is ours (a fixed word, the package name, a version that passed isVersion): nothing a shell could read as more
|
|
62
|
+
const c = file === 'npm' ? npmCommand() : { file, pre: [], shell: false };
|
|
63
|
+
execFile(c.file, [...c.pre, ...args], { timeout: o?.timeoutMs ?? 30_000, encoding: 'utf8', maxBuffer: 4 << 20, shell: c.shell, windowsHide: true }, (err, stdout, stderr) => {
|
|
55
64
|
res({ code: err ? (typeof err.code === 'number' ? err.code : 1) : 0, stdout: String(stdout ?? ''), stderr: String(stderr ?? '') });
|
|
56
65
|
});
|
|
57
66
|
});
|
|
@@ -139,6 +148,8 @@ export class SelfUpdater {
|
|
|
139
148
|
o;
|
|
140
149
|
/** True once the install is done and the runner is stopping: the process should exit UPDATE_EXIT_CODE. */
|
|
141
150
|
restarting = false;
|
|
151
|
+
/** How the release that was just installed got here (set with `restarting`). */
|
|
152
|
+
installed;
|
|
142
153
|
timer;
|
|
143
154
|
stopped = false;
|
|
144
155
|
lastNudge = 0;
|
|
@@ -182,9 +193,11 @@ export class SelfUpdater {
|
|
|
182
193
|
return this.check();
|
|
183
194
|
}
|
|
184
195
|
heard = new Map();
|
|
196
|
+
heardWait = new Map();
|
|
185
197
|
/**
|
|
186
198
|
* The hub names a release on every answer (`x-ach-latest-client`): when it is newer than this one, check now instead of at the
|
|
187
|
-
* next 6-hourly tick. Once per release,
|
|
199
|
+
* next 6-hourly tick. Once per release, again after five minutes when the release could not be installed yet (npm does not
|
|
200
|
+
* serve it the moment the hub names it), and after an hour if this one is still behind for another reason.
|
|
188
201
|
* What a check can never fix by itself (a manual verdict, ACH_AUTO_UPDATE=0) is not asked again for that release.
|
|
189
202
|
*/
|
|
190
203
|
heardLatest(latest) {
|
|
@@ -192,12 +205,15 @@ export class SelfUpdater {
|
|
|
192
205
|
if (this.stopped || this.working || this.restarting || !isVersion(latest) || !newerVersion(latest, this.o.version ?? VERSION))
|
|
193
206
|
return undefined;
|
|
194
207
|
const at = this.heard.get(latest);
|
|
195
|
-
if (at !== undefined && (at < 0 || now - at < 3600_000))
|
|
208
|
+
if (at !== undefined && (at < 0 || now - at < (this.heardWait.get(latest) ?? 3600_000)))
|
|
196
209
|
return undefined;
|
|
197
210
|
this.heard.set(latest, now);
|
|
198
211
|
return this.check().then((r) => {
|
|
199
212
|
if (r === 'manual' || r === 'off')
|
|
200
213
|
this.heard.set(latest, -1);
|
|
214
|
+
// the hub names a release the moment it is deployed, a minute or two before npm serves it: that try fails with nothing
|
|
215
|
+
// paused, and waiting the hour for it kept every runner an hour behind each release. It is asked again in five minutes.
|
|
216
|
+
this.heardWait.set(latest, r === 'failed' ? 5 * 60_000 : 3600_000);
|
|
201
217
|
return r;
|
|
202
218
|
});
|
|
203
219
|
}
|
|
@@ -256,6 +272,7 @@ export class SelfUpdater {
|
|
|
256
272
|
}
|
|
257
273
|
this.log(`${r.detail}; restarting into ${v.target}`);
|
|
258
274
|
this.restarting = true;
|
|
275
|
+
this.installed = kind.kind;
|
|
259
276
|
await this.o.runner.stop();
|
|
260
277
|
return 'restarting';
|
|
261
278
|
}
|
|
@@ -264,6 +281,41 @@ export class SelfUpdater {
|
|
|
264
281
|
}
|
|
265
282
|
}
|
|
266
283
|
}
|
|
284
|
+
const defaultSpawnSelf = (file, args, env) => {
|
|
285
|
+
const child = spawn(file, args, { stdio: 'inherit', env, windowsHide: true });
|
|
286
|
+
return {
|
|
287
|
+
exit: new Promise((res) => {
|
|
288
|
+
child.once('error', () => res(1));
|
|
289
|
+
child.once('exit', (code, sig) => res(code ?? (sig ? 1 : 0)));
|
|
290
|
+
}),
|
|
291
|
+
kill: (sig) => void child.kill(sig),
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
/**
|
|
295
|
+
* After a global install replaced this CLI's files, run the same command line again (the new release) and stay as its parent: the
|
|
296
|
+
* terminal, the Startup script or whatever started the runner still sees one process. The child knows it is watched
|
|
297
|
+
* (ACH_SUPERVISED=1) and exits UPDATE_EXIT_CODE at its next update, which starts it again here, so there is never more than this
|
|
298
|
+
* one parent. Resolves with the exit code to pass on.
|
|
299
|
+
*/
|
|
300
|
+
export async function superviseSelf(o = {}) {
|
|
301
|
+
const run = o.spawnSelf ?? defaultSpawnSelf;
|
|
302
|
+
const args = [...(o.execArgv ?? process.execArgv), ...(o.argv ?? process.argv).slice(1)];
|
|
303
|
+
let stopping = false;
|
|
304
|
+
let current;
|
|
305
|
+
for (const sig of ['SIGINT', 'SIGTERM']) {
|
|
306
|
+
(o.on ?? ((s, f) => void process.on(s, f)))(sig, () => {
|
|
307
|
+
stopping = true;
|
|
308
|
+
current?.kill(sig);
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
for (;;) {
|
|
312
|
+
current = run(o.execPath ?? process.execPath, args, { ...(o.env ?? process.env), ACH_SUPERVISED: '1' });
|
|
313
|
+
const code = await current.exit;
|
|
314
|
+
if (code !== UPDATE_EXIT_CODE || stopping)
|
|
315
|
+
return code;
|
|
316
|
+
o.log?.('[ach update] starting the new release');
|
|
317
|
+
}
|
|
318
|
+
}
|
|
267
319
|
// ---- the brake: a release that keeps failing to start goes back to the one before ---------------------------------------------
|
|
268
320
|
const bootsFile = (home) => join(home, 'boots.json');
|
|
269
321
|
const badFile = (home) => join(home, 'bad-releases.json');
|
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.35.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",
|