@koalaauto/agentchannel 3.53.4 → 3.55.0

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.
Files changed (48) hide show
  1. package/README.md +5 -2
  2. package/dist/src/adapters/antigravity.d.ts +154 -0
  3. package/dist/src/adapters/antigravity.js +345 -0
  4. package/dist/src/adapters/claude.d.ts +24 -0
  5. package/dist/src/adapters/claude.js +2 -0
  6. package/dist/src/adapters/codex.d.ts +24 -1
  7. package/dist/src/adapters/codex.js +2 -1
  8. package/dist/src/adapters/fake.d.ts +6 -3
  9. package/dist/src/adapters/fake.js +21 -5
  10. package/dist/src/adapters/index.d.ts +2 -0
  11. package/dist/src/adapters/index.js +7 -1
  12. package/dist/src/adapters/kiro.d.ts +20 -2
  13. package/dist/src/adapters/kiro.js +2 -2
  14. package/dist/src/adapters/spec.d.ts +164 -0
  15. package/dist/src/adapters/spec.js +104 -0
  16. package/dist/src/adapters/types.d.ts +4 -7
  17. package/dist/src/agycheck.d.ts +21 -0
  18. package/dist/src/agycheck.js +58 -0
  19. package/dist/src/appinstall.d.ts +54 -0
  20. package/dist/src/appinstall.js +216 -0
  21. package/dist/src/args.d.ts +1 -1
  22. package/dist/src/args.js +3 -2
  23. package/dist/src/cli-run.js +93 -26
  24. package/dist/src/client.d.ts +19 -0
  25. package/dist/src/doctor.d.ts +3 -3
  26. package/dist/src/doctor.js +13 -7
  27. package/dist/src/invite.js +6 -2
  28. package/dist/src/onboard.d.ts +21 -2
  29. package/dist/src/onboard.js +56 -3
  30. package/dist/src/prompts.d.ts +9 -2
  31. package/dist/src/prompts.js +57 -5
  32. package/dist/src/runner/context.d.ts +2 -2
  33. package/dist/src/runner/context.js +3 -3
  34. package/dist/src/runner/runner.d.ts +4 -0
  35. package/dist/src/runner/runner.js +49 -24
  36. package/dist/src/runtimecheck.d.ts +26 -0
  37. package/dist/src/runtimecheck.js +20 -0
  38. package/dist/src/sandboxcheck.d.ts +2 -1
  39. package/dist/src/sandboxcheck.js +10 -5
  40. package/dist/src/selfupdate.d.ts +10 -1
  41. package/dist/src/selfupdate.js +28 -5
  42. package/dist/src/service.d.ts +5 -4
  43. package/dist/src/service.js +2 -0
  44. package/dist/src/servicefix.d.ts +4 -4
  45. package/dist/src/servicefix.js +10 -8
  46. package/dist/src/version.d.ts +1 -1
  47. package/dist/src/version.js +1 -1
  48. package/package.json +1 -1
package/README.md CHANGED
@@ -40,8 +40,11 @@ installed or changed.
40
40
  pasting the line was the consent, so it does the same and says what it ran.
41
41
  - `--service` also installs the background helper (`ach run --install-service
42
42
  --interactive-first` for the current directory, without desktop
43
- notifications), and starts it. Through npx the service runs the same pinned
44
- npx spec as the MCP entry, so nothing is installed globally.
43
+ notifications), and starts it.
44
+ - Run through npx, join copies this release into `~/.config/agentchannel/app`
45
+ (one dir per release, no root needed) and the MCP entry and the service start
46
+ its launcher, `node ~/.config/agentchannel/app/ach.mjs`. Nothing waits on npm
47
+ when a session starts; the runner installs new releases there.
45
48
  - When the agent tool's sandbox does not work on this machine (on Linux: bubblewrap and
46
49
  socat missing, or Ubuntu's AppArmor rule), it shows the commands that fix it and runs
47
50
  them only after you say yes in a terminal (they use sudo). Without a terminal it only
@@ -0,0 +1,154 @@
1
+ import type { RuntimeModels } from './models.js';
2
+ import { type AdapterEvent, type AdapterResult, type AdapterRunOptions, type RuntimeAdapter } from './types.js';
3
+ import type { Perm } from '../perm.js';
4
+ /**
5
+ * Antigravity runtime: each run is one headless `agy -p <prompt> --output-format stream-json` on this machine, logged in
6
+ * with the owner's Google account (the login is a file under the real ~/.gemini, so the run keeps the real HOME).
7
+ *
8
+ * The run gets no `ach` and no hub credentials: a sandboxed command has no network, so it could not reach the hub anyway.
9
+ * The runner completes or fails the task and posts answers from the run's final text.
10
+ *
11
+ * Permission levels, as tried by hand with agy 1.5.13 on Linux (2026-11-20; recordings in test/fixtures/antigravity):
12
+ * - read: no commands at all (one allowed command reads any file), no writes, no URL tools, no MCP; file reads only.
13
+ * - workdir: `--sandbox`, commands run inside agy's own sandbox without asking: they write the work dir and /tmp, have no
14
+ * network, and see a filtered HOME (no runner config, no tokens). The file tools run outside it, held by deny rules.
15
+ * - full: `--dangerously-skip-permissions`.
16
+ * What it does not hold: files outside HOME are readable (other checkouts on the machine, /tmp), and its web search tool
17
+ * cannot be turned off by any rule (spec: `reads: 'machine'`, `limits.net: false`).
18
+ *
19
+ * An action nobody could approve is auto-denied and agy then reports status SUCCESS, exit 0, with an empty response and
20
+ * `denied_actions`: that is a failed run here. A rule that denies an action outright is only a tool error to the model, and
21
+ * the run goes on, so every profile denies by rule what it does not allow.
22
+ */
23
+ export declare const AGY_INSTALL = "curl -fsSL https://antigravity.google/cli/install.sh | bash";
24
+ /** Ubuntu stops unprivileged user namespaces through AppArmor; agy builds its sandbox from them (not bwrap), so it needs its own profile. */
25
+ export declare const AGY_APPARMOR: string;
26
+ /** The paths of `paths` a sandboxed command could read: the sandbox hides the home directory and nothing else. Pure. */
27
+ export declare function agyExposed(paths: string[], realHome?: string): string[];
28
+ /** The settings of one run (`--settings`, never saved): its permission rules. Pure. */
29
+ export declare function agySettings(o: {
30
+ perm: Perm;
31
+ denyReadPaths?: string[];
32
+ }): Record<string, unknown> | undefined;
33
+ /** The level a run really gets: only a work run writes; every other run (answer, mention, read-ahead) reads. */
34
+ export declare function agyPerm(perm: Perm, mode: AdapterRunOptions['mode']): Perm;
35
+ export declare function agyArgs(o: {
36
+ prompt: string;
37
+ perm: Perm;
38
+ model?: string;
39
+ effort?: string;
40
+ resume?: string;
41
+ denyReadPaths?: string[];
42
+ readRoots?: string[];
43
+ outputSchema?: unknown;
44
+ }): string[];
45
+ /** The environment agy runs with: the agent env without the hub's run variables, and the runner's real HOME (its login is there). */
46
+ export declare function agyEnv(agentEnv: Record<string, string>, o: {
47
+ realHome?: string;
48
+ }): Record<string, string>;
49
+ /** agy as the runner starts it: ACH_ANTIGRAVITY_BIN, else `agy` (on PATH, or where its installer puts it). */
50
+ export declare function agyBin(env: Record<string, string | undefined>): string;
51
+ /** PATH with the installer's directory (~/.local/bin) added: a service's PATH often lacks it. */
52
+ export declare function agyPath(env: Record<string, string | undefined>, realHome?: string): string;
53
+ /**
54
+ * Turns `--output-format stream-json` (one JSON object per line: `init`, `step_update`, `result`) into adapter events and the
55
+ * run's outcome. A tool step comes ACTIVE, then DONE or ERROR: one tool_start and one tool_end (a step seen only when it is
56
+ * over gets both). Text comes as deltas of an `agent_response` step: one text event per step. There are no thinking events.
57
+ */
58
+ export declare class AgyOutput {
59
+ private onEvent;
60
+ sessionId?: string;
61
+ model?: string;
62
+ status?: string;
63
+ runError?: string;
64
+ denied: string[];
65
+ /** usage of the conversation so far (a resumed one counts its earlier turns too) */
66
+ tokens?: {
67
+ input: number;
68
+ output: number;
69
+ };
70
+ private buf;
71
+ private response;
72
+ private structured;
73
+ private texts;
74
+ private lastText;
75
+ private open;
76
+ constructor(onEvent: (e: AdapterEvent) => void);
77
+ push(chunk: string): void;
78
+ end(): void;
79
+ /**
80
+ * The agent's final message: the structured output when a schema was asked for (the response can carry prose around
81
+ * it), else the result's response, else what it last said.
82
+ */
83
+ finalText(): string;
84
+ private line;
85
+ private session;
86
+ private step;
87
+ private flushText;
88
+ private result;
89
+ }
90
+ /**
91
+ * The outcome of a finished agy process. A run is good only when the process, the status and the final message all say so:
92
+ * agy reports SUCCESS with nothing in it when an action was auto-denied, and exits 0 then. Pure.
93
+ */
94
+ export declare function agyOutcome(o: {
95
+ code: number | null;
96
+ out: Pick<AgyOutput, 'status' | 'runError' | 'denied'>;
97
+ finalText: string;
98
+ stderr: string;
99
+ aborted?: boolean;
100
+ spawnError?: string;
101
+ }): {
102
+ ok: boolean;
103
+ error?: string;
104
+ };
105
+ /** How often a run that was refused an action is resumed to finish without it. */
106
+ export declare const AGY_DENIED_RETRIES = 2;
107
+ /** What a resumed run is told after an action was refused: what it was, and what this run may do. Pure. */
108
+ export declare function agyRefusedPrompt(refused: string[], perm: Perm, cwd: string): string;
109
+ /** `agy models` prints "<slug>\t<label>" per line (after a "Fetching..." line). Pure. */
110
+ export declare function agyModels(out: string): RuntimeModels | undefined;
111
+ export interface AntigravityAdapterOptions {
112
+ model?: string;
113
+ env?: Record<string, string | undefined>;
114
+ /** Tests: the program to start instead of agy. */
115
+ bin?: string;
116
+ }
117
+ export declare class AntigravityAdapter implements RuntimeAdapter {
118
+ private o;
119
+ readonly name = "antigravity";
120
+ readonly spec: {
121
+ readonly name: "antigravity";
122
+ readonly label: "Antigravity";
123
+ readonly where: "local";
124
+ readonly ach: false;
125
+ readonly structuredAnswers: true;
126
+ readonly perms: readonly Perm[];
127
+ readonly limits: {
128
+ readonly net: false;
129
+ readonly denyRead: true;
130
+ };
131
+ readonly reads: "machine";
132
+ readonly budget: false;
133
+ readonly ownerMemory: "prompt";
134
+ readonly ownFiles: readonly [];
135
+ readonly login: {
136
+ readonly command: "agy";
137
+ };
138
+ readonly check: "tool";
139
+ };
140
+ constructor(o?: AntigravityAdapterOptions);
141
+ listModels(o: {
142
+ env: Record<string, string>;
143
+ cwd: string;
144
+ realHome?: string;
145
+ }): Promise<RuntimeModels>;
146
+ private bin;
147
+ /**
148
+ * One run. An action nobody could approve blanks agy's answer (see the header): the conversation is then resumed, at most
149
+ * twice, told what was refused and what this run may do, so one stray attempt does not cost the whole run. The action
150
+ * stays refused; a run that still ends without an answer fails.
151
+ */
152
+ run(opts: AdapterRunOptions): Promise<AdapterResult>;
153
+ private once;
154
+ }
@@ -0,0 +1,345 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { join, relative, isAbsolute } from 'node:path';
3
+ import { RUNTIME_SPECS } from './spec.js';
4
+ import { spawnGroup } from './procgroup.js';
5
+ import { modelId } from './types.js';
6
+ /**
7
+ * Antigravity runtime: each run is one headless `agy -p <prompt> --output-format stream-json` on this machine, logged in
8
+ * with the owner's Google account (the login is a file under the real ~/.gemini, so the run keeps the real HOME).
9
+ *
10
+ * The run gets no `ach` and no hub credentials: a sandboxed command has no network, so it could not reach the hub anyway.
11
+ * The runner completes or fails the task and posts answers from the run's final text.
12
+ *
13
+ * Permission levels, as tried by hand with agy 1.5.13 on Linux (2026-11-20; recordings in test/fixtures/antigravity):
14
+ * - read: no commands at all (one allowed command reads any file), no writes, no URL tools, no MCP; file reads only.
15
+ * - workdir: `--sandbox`, commands run inside agy's own sandbox without asking: they write the work dir and /tmp, have no
16
+ * network, and see a filtered HOME (no runner config, no tokens). The file tools run outside it, held by deny rules.
17
+ * - full: `--dangerously-skip-permissions`.
18
+ * What it does not hold: files outside HOME are readable (other checkouts on the machine, /tmp), and its web search tool
19
+ * cannot be turned off by any rule (spec: `reads: 'machine'`, `limits.net: false`).
20
+ *
21
+ * An action nobody could approve is auto-denied and agy then reports status SUCCESS, exit 0, with an empty response and
22
+ * `denied_actions`: that is a failed run here. A rule that denies an action outright is only a tool error to the model, and
23
+ * the run goes on, so every profile denies by rule what it does not allow.
24
+ */
25
+ export const AGY_INSTALL = 'curl -fsSL https://antigravity.google/cli/install.sh | bash';
26
+ /** Ubuntu stops unprivileged user namespaces through AppArmor; agy builds its sandbox from them (not bwrap), so it needs its own profile. */
27
+ export const AGY_APPARMOR = `printf '%s\\n' 'abi <abi/4.0>,' 'include <tunables/global>' 'profile agy /home/*/.local/bin/agy flags=(unconfined) {' ' userns,' ' include if exists <local/agy>' '}' ` +
28
+ `| sudo tee /etc/apparmor.d/agy >/dev/null && sudo apparmor_parser -r /etc/apparmor.d/agy`;
29
+ const AGY_SANDBOX_HINT = 'on Ubuntu, AppArmor must let agy create user namespaces: see `ach doctor`';
30
+ /** The paths of `paths` a sandboxed command could read: the sandbox hides the home directory and nothing else. Pure. */
31
+ export function agyExposed(paths, realHome) {
32
+ const inside = (p) => {
33
+ if (!realHome)
34
+ return false;
35
+ const r = relative(realHome, p);
36
+ return !!r && !r.startsWith('..') && !isAbsolute(r);
37
+ };
38
+ return paths.filter((p) => !inside(p));
39
+ }
40
+ /** The settings of one run (`--settings`, never saved): its permission rules. Pure. */
41
+ export function agySettings(o) {
42
+ if (o.perm === 'full')
43
+ return undefined;
44
+ const secrets = (o.denyReadPaths ?? []).flatMap((p) => [`read_file(${p})`, `write_file(${p})`]);
45
+ const net = ['read_url(*)', 'execute_url(*)', 'download_url(*)', 'mcp(*)'];
46
+ if (o.perm === 'read')
47
+ return { permissions: { deny: ['command(*)', 'unsandboxed(*)', 'write_file(*)', ...net, ...secrets] } };
48
+ return { toolPermission: 'proceed-in-sandbox', enableTerminalSandbox: true, permissions: { deny: ['unsandboxed(*)', ...net, ...secrets] } };
49
+ }
50
+ /** The level a run really gets: only a work run writes; every other run (answer, mention, read-ahead) reads. */
51
+ export function agyPerm(perm, mode) {
52
+ return mode && mode !== 'work' ? 'read' : perm;
53
+ }
54
+ export function agyArgs(o) {
55
+ const settings = agySettings(o);
56
+ return [
57
+ '--print',
58
+ o.prompt,
59
+ '--output-format',
60
+ 'stream-json',
61
+ ...(o.resume ? ['--conversation', o.resume] : []),
62
+ ...(o.model ? ['--model', o.model] : []),
63
+ ...(o.effort && /^[a-z]{2,12}$/.test(o.effort) ? ['--effort', o.effort] : []),
64
+ ...(o.perm === 'full' ? ['--dangerously-skip-permissions'] : []),
65
+ ...(o.perm === 'workdir' ? ['--sandbox'] : []),
66
+ ...(settings ? ['--settings', JSON.stringify(settings)] : []),
67
+ ...(o.readRoots ?? []).flatMap((d) => ['--add-dir', d]),
68
+ ...(o.outputSchema ? ['--json-schema', JSON.stringify(o.outputSchema)] : []),
69
+ ];
70
+ }
71
+ /** The environment agy runs with: the agent env without the hub's run variables, and the runner's real HOME (its login is there). */
72
+ export function agyEnv(agentEnv, o) {
73
+ const env = {};
74
+ for (const [k, v] of Object.entries(agentEnv))
75
+ if (!/^ACH_/.test(k))
76
+ env[k] = v;
77
+ if (o.realHome)
78
+ env.HOME = o.realHome;
79
+ return env;
80
+ }
81
+ /** agy as the runner starts it: ACH_ANTIGRAVITY_BIN, else `agy` (on PATH, or where its installer puts it). */
82
+ export function agyBin(env) {
83
+ return env.ACH_ANTIGRAVITY_BIN?.trim() || 'agy';
84
+ }
85
+ /** PATH with the installer's directory (~/.local/bin) added: a service's PATH often lacks it. */
86
+ export function agyPath(env, realHome) {
87
+ const local = realHome ? join(realHome, '.local', 'bin') : '';
88
+ const path = env.PATH ?? '';
89
+ return local && !path.split(':').includes(local) ? [path, local].filter(Boolean).join(':') : path;
90
+ }
91
+ /**
92
+ * Turns `--output-format stream-json` (one JSON object per line: `init`, `step_update`, `result`) into adapter events and the
93
+ * run's outcome. A tool step comes ACTIVE, then DONE or ERROR: one tool_start and one tool_end (a step seen only when it is
94
+ * over gets both). Text comes as deltas of an `agent_response` step: one text event per step. There are no thinking events.
95
+ */
96
+ export class AgyOutput {
97
+ onEvent;
98
+ sessionId;
99
+ model;
100
+ status;
101
+ runError;
102
+ denied = [];
103
+ /** usage of the conversation so far (a resumed one counts its earlier turns too) */
104
+ tokens;
105
+ buf = '';
106
+ response = '';
107
+ structured = '';
108
+ texts = new Map();
109
+ lastText = '';
110
+ open = new Set();
111
+ constructor(onEvent) {
112
+ this.onEvent = onEvent;
113
+ }
114
+ push(chunk) {
115
+ this.buf += chunk;
116
+ let i;
117
+ while ((i = this.buf.indexOf('\n')) >= 0) {
118
+ this.line(this.buf.slice(0, i));
119
+ this.buf = this.buf.slice(i + 1);
120
+ }
121
+ }
122
+ end() {
123
+ if (this.buf.trim())
124
+ this.line(this.buf);
125
+ this.buf = '';
126
+ for (const [i] of this.texts)
127
+ this.flushText(i);
128
+ }
129
+ /**
130
+ * The agent's final message: the structured output when a schema was asked for (the response can carry prose around
131
+ * it), else the result's response, else what it last said.
132
+ */
133
+ finalText() {
134
+ return (this.structured || this.response || this.lastText).trim();
135
+ }
136
+ line(raw) {
137
+ const s = raw.trim();
138
+ if (!s)
139
+ return;
140
+ let d;
141
+ try {
142
+ d = JSON.parse(s);
143
+ }
144
+ catch {
145
+ return; // not an event (a notice on stdout): stderr carries what matters
146
+ }
147
+ if (!d || typeof d !== 'object')
148
+ return;
149
+ if (d.event === 'init')
150
+ return this.session(d.conversation_id, d.init?.model);
151
+ if (d.event === 'step_update' && d.step_update)
152
+ return this.step(d.step_update);
153
+ if (d.event === 'result' && d.result)
154
+ return this.result(d.result);
155
+ }
156
+ session(id, model) {
157
+ if (modelId(model))
158
+ this.model = String(model);
159
+ if (typeof id !== 'string' || !id || this.sessionId === id)
160
+ return;
161
+ this.sessionId = id;
162
+ this.onEvent({ type: 'session', data: id });
163
+ }
164
+ step(s) {
165
+ this.session(s.conversation_id);
166
+ const i = Number(s.step_index);
167
+ if (s.step_type === 'agent_response') {
168
+ if (typeof s.text_delta === 'string')
169
+ this.texts.set(i, (this.texts.get(i) ?? '') + s.text_delta);
170
+ if (s.state !== 'ACTIVE')
171
+ this.flushText(i);
172
+ return;
173
+ }
174
+ if (s.step_type !== 'tool')
175
+ return;
176
+ const info = s.tool_info ?? {};
177
+ const id = `step-${i}`;
178
+ if (!this.open.has(i)) {
179
+ this.open.add(i);
180
+ this.onEvent({ type: 'tool_start', data: { id, name: String(info.name ?? s.tool_name ?? 'tool'), input: info.parameters ?? {} } });
181
+ }
182
+ if (s.state === 'ACTIVE')
183
+ return;
184
+ this.open.delete(i);
185
+ const err = info.error ? String(info.error.message ?? info.error.type ?? 'error') : undefined;
186
+ this.onEvent({ type: 'tool_end', data: { id, ...(err || s.state === 'ERROR' ? { is_error: true } : {}), output: String(err ?? info.output ?? '').slice(0, 20_000) } });
187
+ }
188
+ flushText(i) {
189
+ const t = (this.texts.get(i) ?? '').trim();
190
+ this.texts.delete(i);
191
+ if (!t)
192
+ return;
193
+ this.lastText = t;
194
+ this.onEvent({ type: 'text', data: t });
195
+ }
196
+ result(r) {
197
+ this.session(r.conversation_id);
198
+ this.status = typeof r.status === 'string' ? r.status : undefined;
199
+ if (typeof r.response === 'string')
200
+ this.response = r.response;
201
+ if (r.structured_output && typeof r.structured_output === 'object')
202
+ this.structured = JSON.stringify(r.structured_output);
203
+ if (typeof r.error === 'string' && r.error)
204
+ this.runError = r.error;
205
+ if (Array.isArray(r.denied_actions))
206
+ this.denied = r.denied_actions.map((a) => String(a?.action ?? a?.display_name ?? 'action'));
207
+ const u = r.usage;
208
+ if (u && typeof u === 'object') {
209
+ this.tokens = { input: Number(u.input_tokens ?? 0) + Number(u.cache_read_tokens ?? 0), output: Number(u.output_tokens ?? 0) };
210
+ this.onEvent({ type: 'usage', data: { input_tokens: this.tokens.input, output_tokens: this.tokens.output } });
211
+ }
212
+ }
213
+ }
214
+ /**
215
+ * The outcome of a finished agy process. A run is good only when the process, the status and the final message all say so:
216
+ * agy reports SUCCESS with nothing in it when an action was auto-denied, and exits 0 then. Pure.
217
+ */
218
+ export function agyOutcome(o) {
219
+ if (o.aborted)
220
+ return { ok: false, error: 'aborted' };
221
+ if (o.spawnError)
222
+ return { ok: false, error: o.spawnError };
223
+ if (/sandbox is not available/i.test(o.stderr)) {
224
+ return { ok: false, error: `Antigravity's sandbox is not available on this machine, so this run was not allowed to run commands (${AGY_SANDBOX_HINT})` };
225
+ }
226
+ if (o.out.denied.length) {
227
+ return { ok: false, error: `Antigravity stopped: it needed a permission this run does not have and nobody could approve (${[...new Set(o.out.denied)].join(', ')})` };
228
+ }
229
+ const tail = o.stderr.split('\n').map((l) => l.trim()).filter(Boolean).slice(-3).join(' | ');
230
+ if (o.out.runError)
231
+ return { ok: false, error: /authentication/i.test(o.out.runError) ? `Antigravity is not logged in on this machine (authentication required): ${o.out.runError}` : `agy: ${o.out.runError}` };
232
+ if (o.code !== 0 || (o.out.status && o.out.status !== 'SUCCESS'))
233
+ return { ok: false, error: `agy ended with ${o.out.status ?? `exit ${o.code}`}${tail ? `: ${tail}` : ''}`.slice(0, 2000) };
234
+ if (!o.finalText)
235
+ return { ok: false, error: `agy reported ${o.out.status ?? 'success'} with no final message${tail ? `: ${tail}` : ''}`.slice(0, 2000) };
236
+ return { ok: true };
237
+ }
238
+ /** How often a run that was refused an action is resumed to finish without it. */
239
+ export const AGY_DENIED_RETRIES = 2;
240
+ /** What a resumed run is told after an action was refused: what it was, and what this run may do. Pure. */
241
+ export function agyRefusedPrompt(refused, perm, cwd) {
242
+ const may = perm === 'read' ? `Here you may only read files (no commands, no writes, no URLs).` : `Here you may run commands, and read and write files inside ${cwd} only.`;
243
+ return `An action you tried was refused and cannot be approved in this run: ${refused.join(', ')}. ${may} Do not try a refused action again, and do not look outside ${cwd} unless the task says to. Go on with the task and end with your final message, as the rules of the task say; say there what you could not do.`;
244
+ }
245
+ /** `agy models` prints "<slug>\t<label>" per line (after a "Fetching..." line). Pure. */
246
+ export function agyModels(out) {
247
+ const models = out
248
+ .split('\n')
249
+ .map((l) => l.trim().split('\t'))
250
+ .filter((p) => p.length >= 2 && modelId(p[0]))
251
+ .map(([id, label]) => ({ id, ...(label && label !== id ? { label: label.slice(0, 80) } : {}) }));
252
+ return models.length ? { models } : undefined;
253
+ }
254
+ export class AntigravityAdapter {
255
+ o;
256
+ name = 'antigravity';
257
+ spec = RUNTIME_SPECS.antigravity;
258
+ constructor(o = {}) {
259
+ this.o = o;
260
+ }
261
+ async listModels(o) {
262
+ const env = { ...agyEnv(o.env, { realHome: o.realHome }) };
263
+ env.PATH = agyPath(env, o.realHome);
264
+ return new Promise((resolve, reject) => {
265
+ execFile(this.bin(), ['models'], { env, cwd: o.cwd, timeout: 30_000, maxBuffer: 1 << 20 }, (err, stdout, stderr) => {
266
+ const list = agyModels(String(stdout));
267
+ if (list)
268
+ resolve(list);
269
+ else
270
+ reject(new Error(`agy models: ${err?.message ?? String(stderr).trim().split('\n').slice(-2).join(' ') ?? 'no models listed'}`));
271
+ });
272
+ });
273
+ }
274
+ bin() {
275
+ return this.o.bin ?? agyBin(this.o.env ?? process.env);
276
+ }
277
+ /**
278
+ * One run. An action nobody could approve blanks agy's answer (see the header): the conversation is then resumed, at most
279
+ * twice, told what was refused and what this run may do, so one stray attempt does not cost the whole run. The action
280
+ * stays refused; a run that still ends without an answer fails.
281
+ */
282
+ async run(opts) {
283
+ const model = opts.model ?? this.o.model;
284
+ const perm = agyPerm(opts.perm, opts.mode);
285
+ // a sandboxed command sees every file outside the home directory: the runner's secrets must not be among them
286
+ const exposed = perm === 'workdir' ? agyExposed(opts.denyReadPaths ?? [], opts.realHome) : [];
287
+ if (exposed.length) {
288
+ const error = `not run: Antigravity's sandbox hides only the home directory, and the runner keeps its key outside it (${exposed[0]}); keep the agent home under the home directory, or run with full access`;
289
+ opts.onEvent({ type: 'error', data: error });
290
+ return { finalText: '', ok: false, error };
291
+ }
292
+ let prompt = opts.prompt;
293
+ let resume = opts.resume;
294
+ for (let attempt = 0;; attempt++) {
295
+ const r = await this.once(opts, { prompt, resume, perm, model });
296
+ const finalText = r.out.finalText();
297
+ const { ok, error } = agyOutcome({ code: r.code, out: r.out, finalText, stderr: r.stderr, aborted: opts.signal.aborted, spawnError: r.spawnError });
298
+ const used = r.out.model ?? (modelId(model) ? model : undefined);
299
+ const result = { finalText, sessionId: r.out.sessionId ?? resume, ok, ...(error ? { error } : {}), ...(used ? { model: used } : {}) };
300
+ const refused = [...new Set(r.out.denied)];
301
+ if (ok || !refused.length || !r.out.sessionId || attempt >= AGY_DENIED_RETRIES || opts.signal.aborted || r.spawnError)
302
+ return result;
303
+ opts.onEvent({ type: 'error', data: `Antigravity was refused ${refused.join(', ')} and gave no answer; resuming the conversation to finish without it` });
304
+ prompt = agyRefusedPrompt(refused, perm, opts.cwd);
305
+ resume = r.out.sessionId;
306
+ }
307
+ }
308
+ once(opts, o) {
309
+ const out = new AgyOutput(opts.onEvent);
310
+ let stderr = '';
311
+ return new Promise((resolve) => {
312
+ const env = agyEnv(opts.env, { realHome: opts.realHome });
313
+ env.PATH = agyPath(env, opts.realHome);
314
+ let done = false;
315
+ const finish = (code, spawnError) => {
316
+ if (done)
317
+ return;
318
+ done = true;
319
+ out.end();
320
+ resolve({ out, code, stderr, ...(spawnError ? { spawnError } : {}) });
321
+ };
322
+ let child;
323
+ try {
324
+ child = spawnGroup(this.bin(), agyArgs({ prompt: o.prompt, perm: o.perm, model: o.model, effort: opts.effort, resume: o.resume, denyReadPaths: opts.denyReadPaths, readRoots: opts.readRoots, outputSchema: opts.outputSchema }), {
325
+ cwd: opts.cwd,
326
+ env,
327
+ signal: opts.signal,
328
+ onStderr: (t) => {
329
+ stderr = (stderr + t).slice(-4000);
330
+ opts.onEvent({ type: 'error', data: t });
331
+ },
332
+ });
333
+ }
334
+ catch (e) {
335
+ finish(null, `agy: ${e?.message ?? e}`);
336
+ return;
337
+ }
338
+ child.stdin?.end();
339
+ child.stdout?.setEncoding('utf8');
340
+ child.stdout?.on('data', (d) => out.push(d));
341
+ child.on('error', (e) => finish(null, e?.code === 'ENOENT' ? `agy not found (${this.bin()}): install it (${AGY_INSTALL}) or set ACH_ANTIGRAVITY_BIN` : String(e?.message ?? e)));
342
+ child.on('close', (code) => finish(code));
343
+ });
344
+ }
345
+ }
@@ -143,6 +143,30 @@ export interface ClaudeAdapterOptions {
143
143
  export declare class ClaudeAdapter implements RuntimeAdapter {
144
144
  private o;
145
145
  readonly name = "claude";
146
+ readonly spec: {
147
+ readonly name: "claude";
148
+ readonly label: "Claude Code";
149
+ readonly where: "local";
150
+ readonly ach: true;
151
+ readonly structuredAnswers: false;
152
+ readonly perms: readonly Perm[];
153
+ readonly limits: {
154
+ readonly net: true;
155
+ readonly denyRead: true;
156
+ };
157
+ readonly reads: "scoped";
158
+ readonly budget: true;
159
+ readonly ownerMemory: "native";
160
+ readonly ownFiles: readonly [];
161
+ readonly lightModel: {
162
+ readonly model: "claude-haiku-5-5";
163
+ readonly effort: "low";
164
+ };
165
+ readonly login: {
166
+ readonly command: "claude auth login";
167
+ };
168
+ readonly check: "sandbox";
169
+ };
146
170
  constructor(o?: ClaudeAdapterOptions);
147
171
  /**
148
172
  * Run, asking for the thinking summary. The default model cannot be seen from here (Claude Code settings may select an older
@@ -1,4 +1,5 @@
1
1
  import { mkdtempSync, realpathSync, rmSync } from 'node:fs';
2
+ import { RUNTIME_SPECS } from './spec.js';
2
3
  import { homedir, tmpdir } from 'node:os';
3
4
  import { join } from 'node:path';
4
5
  import { CAPS_SERVER } from '../caps.js';
@@ -377,6 +378,7 @@ export function effortOf(input) {
377
378
  export class ClaudeAdapter {
378
379
  o;
379
380
  name = 'claude';
381
+ spec = RUNTIME_SPECS.claude;
380
382
  constructor(o = {}) {
381
383
  this.o = o;
382
384
  }
@@ -118,7 +118,30 @@ export declare function codexSessionModel(codexHome: string | undefined, threadI
118
118
  export declare class CodexAdapter implements RuntimeAdapter {
119
119
  private o;
120
120
  readonly name = "codex";
121
- readonly structuredAnswers = true;
121
+ readonly spec: {
122
+ readonly name: "codex";
123
+ readonly label: "Codex";
124
+ readonly where: "local";
125
+ readonly ach: true;
126
+ readonly structuredAnswers: true;
127
+ readonly perms: readonly Perm[];
128
+ readonly limits: {
129
+ readonly net: true;
130
+ readonly denyRead: true;
131
+ };
132
+ readonly reads: "scoped";
133
+ readonly budget: false;
134
+ readonly ownerMemory: "prompt";
135
+ readonly ownFiles: readonly ["AGENTS.md"];
136
+ readonly lightModel: {
137
+ readonly model: "gpt-6.1-sol";
138
+ readonly effort: "medium";
139
+ };
140
+ readonly login: {
141
+ readonly command: "codex login";
142
+ };
143
+ readonly check: "sandbox";
144
+ };
122
145
  constructor(o?: {
123
146
  model?: string;
124
147
  price?: PriceTable;
@@ -1,4 +1,5 @@
1
1
  import { execFileSync } from 'node:child_process';
2
+ import { RUNTIME_SPECS } from './spec.js';
2
3
  import { closeSync, existsSync, openSync, readdirSync, readSync, statSync } from 'node:fs';
3
4
  import { join } from 'node:path';
4
5
  import { readable, systemPaths } from './scope.js';
@@ -313,7 +314,7 @@ export function codexSessionModel(codexHome, threadId) {
313
314
  export class CodexAdapter {
314
315
  o;
315
316
  name = 'codex';
316
- structuredAnswers = true;
317
+ spec = RUNTIME_SPECS.codex;
317
318
  constructor(o = {}) {
318
319
  this.o = o;
319
320
  }
@@ -1,3 +1,4 @@
1
+ import type { RuntimeSpec } from './spec.js';
1
2
  import type { AdapterResult, AdapterRunOptions, RuntimeAdapter } from './types.js';
2
3
  export interface AchCallResult {
3
4
  code: number;
@@ -69,15 +70,17 @@ export interface FakeAdapterOptions {
69
70
  models?: import('./models.js').RuntimeModels;
70
71
  /** Behave like kiro: no `ach` in the run; the runner reports the final text (implies structuredAnswers). */
71
72
  remote?: boolean;
73
+ /** Any other part of the runtime's spec (a tool that cannot limit the network, one that enforces `read` only, ...). */
74
+ spec?: Partial<RuntimeSpec>;
72
75
  }
73
76
  /** Default: spawn this package's CLI with node. */
74
77
  export declare const spawnAch: AchCall;
75
78
  /** Scripted runtime for tests. Never calls a model. */
76
79
  export declare class FakeAdapter implements RuntimeAdapter {
77
80
  private o;
78
- readonly name = "fake";
79
- readonly structuredAnswers: boolean;
80
- readonly remote: boolean;
81
+ /** `fake`, or the runtime it stands in for (`spec.name`). */
82
+ readonly name: string;
83
+ readonly spec: RuntimeSpec;
81
84
  runs: FakeRunInfo[];
82
85
  achCalls: {
83
86
  args: string[];