@koalaauto/agentchannel 3.35.1 → 3.35.3
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/kiro.d.ts +2 -0
- package/dist/src/adapters/kiro.js +18 -1
- package/dist/src/cli.js +17 -10
- package/dist/src/env.d.ts +5 -0
- package/dist/src/env.js +10 -2
- package/dist/src/sandboxcheck.d.ts +2 -0
- package/dist/src/sandboxcheck.js +11 -6
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +1 -1
|
@@ -50,6 +50,8 @@ export declare class KiroOutput {
|
|
|
50
50
|
private buf;
|
|
51
51
|
private message;
|
|
52
52
|
private messages;
|
|
53
|
+
/** kiro-cli 3.x ends a run with `runFinished` carrying the run's final text: it wins over the streamed messages. */
|
|
54
|
+
private runFinal;
|
|
53
55
|
private text;
|
|
54
56
|
constructor(onEvent: (e: AdapterEvent) => void);
|
|
55
57
|
push(chunk: string): void;
|
|
@@ -96,6 +96,8 @@ export class KiroOutput {
|
|
|
96
96
|
buf = '';
|
|
97
97
|
message = '';
|
|
98
98
|
messages = [];
|
|
99
|
+
/** kiro-cli 3.x ends a run with `runFinished` carrying the run's final text: it wins over the streamed messages. */
|
|
100
|
+
runFinal = '';
|
|
99
101
|
text = [];
|
|
100
102
|
constructor(onEvent) {
|
|
101
103
|
this.onEvent = onEvent;
|
|
@@ -116,6 +118,8 @@ export class KiroOutput {
|
|
|
116
118
|
}
|
|
117
119
|
/** The agent's last message (stream-json), else the text transcript's tail. */
|
|
118
120
|
finalText() {
|
|
121
|
+
if (this.runFinal.trim())
|
|
122
|
+
return this.runFinal.trim();
|
|
119
123
|
const last = [...this.messages].reverse().find((m) => m.trim());
|
|
120
124
|
if (last)
|
|
121
125
|
return last.trim();
|
|
@@ -156,7 +160,8 @@ export class KiroOutput {
|
|
|
156
160
|
return;
|
|
157
161
|
}
|
|
158
162
|
this.jsonLines++;
|
|
159
|
-
|
|
163
|
+
// kiro-cli 2.x: JSON-RPC `{method, params: {sessionId, update}}`; 3.x: `{type, data: {sessionId, update}}`
|
|
164
|
+
const p = j.params ?? (j.data && typeof j.data === 'object' ? j.data : undefined) ?? j;
|
|
160
165
|
this.setSession(p.sessionId ?? p.session_id ?? j.sessionId ?? j.session_id);
|
|
161
166
|
const credits = findCredits(j);
|
|
162
167
|
if (credits !== undefined) {
|
|
@@ -181,6 +186,15 @@ export class KiroOutput {
|
|
|
181
186
|
if (u.status === 'completed' || u.status === 'failed')
|
|
182
187
|
this.onEvent({ type: 'tool_end', data: { id: String(u.toolCallId ?? u.id ?? ''), is_error: u.status === 'failed' } });
|
|
183
188
|
break;
|
|
189
|
+
case 'runFinished':
|
|
190
|
+
this.flushMessage();
|
|
191
|
+
if (typeof p.finalText === 'string')
|
|
192
|
+
this.runFinal = p.finalText;
|
|
193
|
+
if (p.status && p.status !== 'success')
|
|
194
|
+
this.onEvent({ type: 'error', data: `kiro run ${String(p.status)}${p.stopReason ? ` (${String(p.stopReason)})` : ''}` });
|
|
195
|
+
else
|
|
196
|
+
this.onEvent({ type: 'tool', data: { type: kind } });
|
|
197
|
+
break;
|
|
184
198
|
case 'tool_call_update':
|
|
185
199
|
if (u.status === 'completed' || u.status === 'failed') {
|
|
186
200
|
this.onEvent({ type: 'tool_end', data: { id: String(u.toolCallId ?? u.id ?? ''), is_error: u.status === 'failed', output: contentText(u.content) || (u.rawOutput ? JSON.stringify(u.rawOutput) : '') } });
|
|
@@ -217,6 +231,9 @@ function findCredits(o, depth = 0) {
|
|
|
217
231
|
for (const [k, v] of Object.entries(o)) {
|
|
218
232
|
if (/^credits?(_?used)?$/i.test(k) && typeof v === 'number' && Number.isFinite(v))
|
|
219
233
|
return v;
|
|
234
|
+
// kiro-cli 3.x: `_meta.kiro.credits: [{usage, unit: "credit"}]`
|
|
235
|
+
if (/^credits?$/i.test(k) && Array.isArray(v) && v.length && v.every((x) => x && typeof x.usage === 'number' && Number.isFinite(x.usage)))
|
|
236
|
+
return v.reduce((a, x) => a + x.usage, 0);
|
|
220
237
|
const inner = findCredits(v, depth + 1);
|
|
221
238
|
if (inner !== undefined)
|
|
222
239
|
return inner;
|
package/dist/src/cli.js
CHANGED
|
@@ -4,6 +4,7 @@ import { randomBytes } from 'node:crypto';
|
|
|
4
4
|
import { chmodSync, existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
|
|
5
5
|
import { basename, delimiter, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { tmpdir } from 'node:os';
|
|
7
8
|
import { developerDir } from './adapters/scope.js';
|
|
8
9
|
import { acquireRunnerLock, RunnerLockedError } from './runner/lock.js';
|
|
9
10
|
import { helpFor, HELP, parseCli, UsageError } from './args.js';
|
|
@@ -18,6 +19,7 @@ export { VERSION } from './version.js';
|
|
|
18
19
|
import { VERSION } from './version.js';
|
|
19
20
|
import { bootGuard, markHealthy, SelfUpdater, superviseSelf, UPDATE_EXIT_CODE } from './selfupdate.js';
|
|
20
21
|
import { installProxy } from './netproxy.js';
|
|
22
|
+
import { inheritedEnv } from './env.js';
|
|
21
23
|
/** 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
24
|
async function confirmKeyRotation(io, v, agentName) {
|
|
23
25
|
if (!io.ask || v.yes || v.json)
|
|
@@ -1578,7 +1580,7 @@ async function runCommand(p, io) {
|
|
|
1578
1580
|
const home = achHome(env);
|
|
1579
1581
|
const dir = resolve(io.cwd ?? process.cwd(), str(v.dir) ?? '.');
|
|
1580
1582
|
const { GitWorkspace, parseRepoFlags } = await import('./runner/workspace.js');
|
|
1581
|
-
const { Runner, gcWorktrees } = await import('./runner/runner.js');
|
|
1583
|
+
const { Runner, gcWorktrees, prepareAgentHome, realHomeOf } = await import('./runner/runner.js');
|
|
1582
1584
|
let repoFlags;
|
|
1583
1585
|
try {
|
|
1584
1586
|
repoFlags = parseRepoFlags(Array.isArray(v.repo) ? v.repo : [], io.cwd ?? process.cwd());
|
|
@@ -1630,6 +1632,14 @@ async function runCommand(p, io) {
|
|
|
1630
1632
|
throw new UsageError(`run: ${e.message}`);
|
|
1631
1633
|
}
|
|
1632
1634
|
// keeps this runner on the hub's release: waits for the runs in flight, installs, exits UPDATE_EXIT_CODE so the service restarts
|
|
1635
|
+
const passEnv = (Array.isArray(v['pass-env']) ? v['pass-env'] : []).flatMap(splitList);
|
|
1636
|
+
const baseEnv = (() => {
|
|
1637
|
+
const shim = writeAchShim(home);
|
|
1638
|
+
// macOS: the real git and python3 of the developer tools before the /usr/bin shims (scope.ts developerDir)
|
|
1639
|
+
const dev = developerDir();
|
|
1640
|
+
const path = [shim, dev ? `${dev}/usr/bin` : undefined, env.PATH].filter(Boolean).join(delimiter);
|
|
1641
|
+
return shim || dev ? { ...env, PATH: path } : env;
|
|
1642
|
+
})();
|
|
1633
1643
|
const runner = new Runner({
|
|
1634
1644
|
client: c,
|
|
1635
1645
|
adapter,
|
|
@@ -1647,7 +1657,7 @@ async function runCommand(p, io) {
|
|
|
1647
1657
|
secrets: [cfg.key ?? ''].filter(Boolean),
|
|
1648
1658
|
publicUrl: env.ACH_PUBLIC_URL || undefined,
|
|
1649
1659
|
onClientTooOld: () => void updater?.nudge(),
|
|
1650
|
-
passEnv
|
|
1660
|
+
passEnv,
|
|
1651
1661
|
startInfo: await (async () => {
|
|
1652
1662
|
const { startedByService } = await import('./servicefix.js');
|
|
1653
1663
|
const service = !startedByService(me.name, process.platform, env) ? '' : process.platform === 'darwin' ? 'launchd' : 'systemd';
|
|
@@ -1660,20 +1670,17 @@ async function runCommand(p, io) {
|
|
|
1660
1670
|
...(service === 'systemd' ? { linger: lingers(env) } : {}),
|
|
1661
1671
|
};
|
|
1662
1672
|
})(),
|
|
1663
|
-
baseEnv
|
|
1664
|
-
const shim = writeAchShim(home);
|
|
1665
|
-
// macOS: the real git and python3 of the developer tools before the /usr/bin shims (scope.ts developerDir)
|
|
1666
|
-
const dev = developerDir();
|
|
1667
|
-
const path = [shim, dev ? `${dev}/usr/bin` : undefined, env.PATH].filter(Boolean).join(delimiter);
|
|
1668
|
-
return shim || dev ? { ...env, PATH: path } : env;
|
|
1669
|
-
})(),
|
|
1673
|
+
baseEnv,
|
|
1670
1674
|
log: io.err,
|
|
1671
1675
|
sandboxCheck: async () => {
|
|
1672
1676
|
// kiro runs in Kiro's cloud sandbox: what this machine needs is kiro-cli and its key
|
|
1673
1677
|
if (runtime === 'kiro')
|
|
1674
1678
|
return (await import('./kirocheck.js')).probeKiro({ env });
|
|
1675
1679
|
const { probeEnvironment } = await import('./envcheck.js');
|
|
1676
|
-
|
|
1680
|
+
// the sandboxed command gets the env a run gets (inherited vars and a scratch home like a task's), so what a run cannot start
|
|
1681
|
+
// without shows here, not in the first task (TASK-59)
|
|
1682
|
+
const { env: homeEnv } = prepareAgentHome(join(tmpdir(), 'ach-homes'), me.name, 'startup-check', realHomeOf(baseEnv), baseEnv.CODEX_HOME || undefined);
|
|
1683
|
+
return probeEnvironment(runtime === 'codex' ? 'codex' : 'claude', { env, hub: cfg.hub, runEnv: { ...inheritedEnv(baseEnv, passEnv), ...homeEnv } });
|
|
1677
1684
|
},
|
|
1678
1685
|
});
|
|
1679
1686
|
io.err(`ach run: agent ${me.name}, runtime ${runtime}, perm min(${me.perm_level}, ${perm}), dir ${dir}` +
|
package/dist/src/env.d.ts
CHANGED
|
@@ -35,4 +35,9 @@ export interface AgentEnvInput {
|
|
|
35
35
|
passEnv?: string[];
|
|
36
36
|
}
|
|
37
37
|
/** Env for a spawned agent: allowlisted parent vars + --pass-env names + task-scoped ACH vars. */
|
|
38
|
+
/**
|
|
39
|
+
* The parent vars a spawned agent inherits: the allowlist, the platform's system vars and the --pass-env names. The runner's
|
|
40
|
+
* startup check runs the runtime with these too, so a var a run cannot do without fails there, not in the first task (TASK-59).
|
|
41
|
+
*/
|
|
42
|
+
export declare function inheritedEnv(base: NodeJS.ProcessEnv | Record<string, string | undefined>, passEnv?: string[], platform?: NodeJS.Platform): Record<string, string>;
|
|
38
43
|
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
|
@@ -48,15 +48,23 @@ export function neverPass(name) {
|
|
|
48
48
|
return /^CLAUDE_CODE_.*(SESSION|ENTRYPOINT|EXECPATH|SSE|PORT|SOCK|IPC|MESSAG|HOST|OAUTH|TOKEN|AUTH|BRIDGE|REMOTE)/.test(name);
|
|
49
49
|
}
|
|
50
50
|
/** Env for a spawned agent: allowlisted parent vars + --pass-env names + task-scoped ACH vars. */
|
|
51
|
-
|
|
51
|
+
/**
|
|
52
|
+
* The parent vars a spawned agent inherits: the allowlist, the platform's system vars and the --pass-env names. The runner's
|
|
53
|
+
* startup check runs the runtime with these too, so a var a run cannot do without fails there, not in the first task (TASK-59).
|
|
54
|
+
*/
|
|
55
|
+
export function inheritedEnv(base, passEnv = [], platform = process.platform) {
|
|
52
56
|
const env = {};
|
|
53
57
|
const win = platform === 'win32';
|
|
54
|
-
for (const k of [...ENV_ALLOWLIST, ...(win ? WINDOWS_ENV_ALLOWLIST : []), ...
|
|
58
|
+
for (const k of [...ENV_ALLOWLIST, ...(win ? WINDOWS_ENV_ALLOWLIST : []), ...passEnv]) {
|
|
55
59
|
const v = lookup(base, k, win);
|
|
56
60
|
if (v === undefined || neverPass(k))
|
|
57
61
|
continue;
|
|
58
62
|
env[k] = v;
|
|
59
63
|
}
|
|
64
|
+
return env;
|
|
65
|
+
}
|
|
66
|
+
export function buildAgentEnv(base, a, platform = process.platform) {
|
|
67
|
+
const env = inheritedEnv(base, a.passEnv, platform);
|
|
60
68
|
env.ACH_HUB = a.hub;
|
|
61
69
|
env.ACH_RUN_TOKEN = a.runToken;
|
|
62
70
|
env.ACH_TASK_ID = a.taskId;
|
|
@@ -90,6 +90,8 @@ export interface ProbeOptions {
|
|
|
90
90
|
codex?: string[];
|
|
91
91
|
/** the hub URL: when set, a Codex probe also checks that a sandboxed command reaches it (work runs call `ach` from there) */
|
|
92
92
|
hub?: string;
|
|
93
|
+
/** the env a run's runtime gets (inheritedEnv); the sandboxed commands run with it. Default: env */
|
|
94
|
+
runEnv?: NodeJS.ProcessEnv;
|
|
93
95
|
}
|
|
94
96
|
/** Probe `tool`'s sandbox on this machine. Never throws. */
|
|
95
97
|
export declare function probeSandbox(tool: SandboxTool, o?: ProbeOptions): Promise<SandboxStatus>;
|
package/dist/src/sandboxcheck.js
CHANGED
|
@@ -86,8 +86,13 @@ export function classify(stderr, host) {
|
|
|
86
86
|
return 'userns-blocked';
|
|
87
87
|
return 'failed';
|
|
88
88
|
}
|
|
89
|
+
/** Warnings a tool prints before it fails (Codex on Windows: "proceeding, even though we could not create PATH aliases"). */
|
|
90
|
+
const PROBE_NOISE = /^warning\b|proceeding, even though/i;
|
|
91
|
+
/** The line that says why: the first error-looking line that is not a warning, else the first line that is not one, else the first. */
|
|
89
92
|
function firstLine(s) {
|
|
90
|
-
|
|
93
|
+
const lines = s.split('\n').map((l) => l.trim()).filter(Boolean);
|
|
94
|
+
const real = lines.filter((l) => !PROBE_NOISE.test(l));
|
|
95
|
+
return (real.find((l) => /error|fail|denied|refus|cannot|not (found|permitted|allowed)|requires/i.test(l)) ?? real[0] ?? lines[0] ?? '').slice(0, 300);
|
|
91
96
|
}
|
|
92
97
|
/**
|
|
93
98
|
* The two writes: inside the sandbox's directory (must work) and in the home directory (must be refused). With a third
|
|
@@ -113,13 +118,13 @@ export async function probeSandbox(tool, o = {}) {
|
|
|
113
118
|
const platform = o.platform ?? process.platform;
|
|
114
119
|
const host = o.host ?? detectHost(env, platform);
|
|
115
120
|
const run = o.run ?? defaultRun;
|
|
116
|
-
const st = await probe(tool, { env, platform, host, run, home: o.home ?? homedir(), codex: o.codex, hub: o.hub });
|
|
121
|
+
const st = await probe(tool, { env, platform, host, run, home: o.home ?? homedir(), codex: o.codex, hub: o.hub, runEnv: o.runEnv ?? env });
|
|
117
122
|
if (!st.ok)
|
|
118
123
|
st.fix = sandboxFix(st, host);
|
|
119
124
|
return st;
|
|
120
125
|
}
|
|
121
126
|
async function probe(tool, o) {
|
|
122
|
-
const { platform, host, run, env } = o;
|
|
127
|
+
const { platform, host, run, env, runEnv } = o;
|
|
123
128
|
if (platform === 'win32') {
|
|
124
129
|
if (tool === 'claude')
|
|
125
130
|
return { tool, ok: false, problem: 'windows-native' };
|
|
@@ -152,12 +157,12 @@ async function probe(tool, o) {
|
|
|
152
157
|
let codex;
|
|
153
158
|
if (tool === 'claude' && platform === 'linux') {
|
|
154
159
|
// what Claude Code's sandbox does: a new session, no network, the filesystem read-only except the work directory
|
|
155
|
-
r = await run(host.bwrap, ['--new-session', '--die-with-parent', '--unshare-net', '--ro-bind', '/', '/', '--dev', '/dev', '--proc', '/proc', '--bind', dir, dir, '--', ...sh], { env });
|
|
160
|
+
r = await run(host.bwrap, ['--new-session', '--die-with-parent', '--unshare-net', '--ro-bind', '/', '/', '--dev', '/dev', '--proc', '/proc', '--bind', dir, dir, '--', ...sh], { env: runEnv });
|
|
156
161
|
}
|
|
157
162
|
else if (tool === 'claude') {
|
|
158
163
|
const q = (p) => JSON.stringify(p);
|
|
159
164
|
const profile = `(version 1)(allow default)(deny file-write* (subpath ${q(o.home)}))(allow file-write* (subpath ${q(dir)}))`;
|
|
160
|
-
r = await run('/usr/bin/sandbox-exec', ['-p', profile, ...sh], { env });
|
|
165
|
+
r = await run('/usr/bin/sandbox-exec', ['-p', profile, ...sh], { env: runEnv });
|
|
161
166
|
}
|
|
162
167
|
else {
|
|
163
168
|
codex = o.codex ?? codexCommand(env);
|
|
@@ -167,7 +172,7 @@ async function probe(tool, o) {
|
|
|
167
172
|
if (canary)
|
|
168
173
|
writeFileSync(canary, 'probe\n', { mode: 0o600 });
|
|
169
174
|
codexHome = probeCodexHome();
|
|
170
|
-
const cenv = { ...
|
|
175
|
+
const cenv = { ...runEnv, CODEX_HOME: codexHome };
|
|
171
176
|
// the work directory is the cwd; the sandbox is the one a work run gets (codexSandboxOverrides)
|
|
172
177
|
r = await run(codex[0], [...codex.slice(1), 'sandbox', ...codexProbeConfig(dir, o.home, o.hub), '--', ...cmd], { env: cenv, cwd: dir });
|
|
173
178
|
if (r.code !== 0 && /unrecognized subcommand|unexpected argument|Usage: codex \[OPTIONS\]/i.test(r.stderr)) {
|
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.35.
|
|
3
|
+
"version": "3.35.3",
|
|
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",
|