@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
@@ -1,4 +1,5 @@
1
1
  import { spawn } from 'node:child_process';
2
+ import { PERMS } from '../perm.js';
2
3
  import { fileURLToPath } from 'node:url';
3
4
  /** Default: spawn this package's CLI with node. */
4
5
  export const spawnAch = (args, env, cwd) => new Promise((res) => {
@@ -28,15 +29,30 @@ function sleep(ms, signal) {
28
29
  /** Scripted runtime for tests. Never calls a model. */
29
30
  export class FakeAdapter {
30
31
  o;
31
- name = 'fake';
32
- structuredAnswers;
33
- remote;
32
+ /** `fake`, or the runtime it stands in for (`spec.name`). */
33
+ name;
34
+ spec;
34
35
  runs = [];
35
36
  achCalls = [];
36
37
  constructor(o) {
37
38
  this.o = o;
38
- this.structuredAnswers = !!o.structuredAnswers || !!o.remote;
39
- this.remote = !!o.remote;
39
+ this.spec = {
40
+ name: 'fake',
41
+ label: 'Fake',
42
+ where: o.remote ? 'cloud' : 'local',
43
+ ach: !o.remote,
44
+ structuredAnswers: !!o.structuredAnswers || !!o.remote,
45
+ perms: PERMS,
46
+ limits: { net: true, denyRead: true },
47
+ reads: 'scoped',
48
+ budget: false,
49
+ ownerMemory: 'prompt',
50
+ ownFiles: [],
51
+ login: { key: 'FAKE_KEY' },
52
+ check: 'tool',
53
+ ...o.spec,
54
+ };
55
+ this.name = this.spec.name;
40
56
  }
41
57
  modelListings = 0;
42
58
  get listModels() {
@@ -1,8 +1,10 @@
1
1
  import type { RuntimeAdapter } from './types.js';
2
2
  export * from './types.js';
3
+ export * from './spec.js';
3
4
  export { ClaudeAdapter } from './claude.js';
4
5
  export { CodexAdapter } from './codex.js';
5
6
  export { KiroAdapter } from './kiro.js';
7
+ export { AntigravityAdapter } from './antigravity.js';
6
8
  export { FakeAdapter } from './fake.js';
7
9
  export * from './paths.js';
8
10
  /** The git common dir of a worktree (readable for git log/diff; never writable, S10). */
@@ -3,10 +3,14 @@ import { resolve } from 'node:path';
3
3
  import { ClaudeAdapter } from './claude.js';
4
4
  import { CodexAdapter } from './codex.js';
5
5
  import { KiroAdapter } from './kiro.js';
6
+ import { AntigravityAdapter } from './antigravity.js';
7
+ import { runtimeList } from './spec.js';
6
8
  export * from './types.js';
9
+ export * from './spec.js';
7
10
  export { ClaudeAdapter } from './claude.js';
8
11
  export { CodexAdapter } from './codex.js';
9
12
  export { KiroAdapter } from './kiro.js';
13
+ export { AntigravityAdapter } from './antigravity.js';
10
14
  export { FakeAdapter } from './fake.js';
11
15
  export * from './paths.js';
12
16
  /** The git common dir of a worktree (readable for git log/diff; never writable, S10). */
@@ -26,5 +30,7 @@ export function makeAdapter(runtime, o = {}) {
26
30
  return new CodexAdapter({ model: o.model });
27
31
  if (runtime === 'kiro')
28
32
  return new KiroAdapter({ model: o.model, env: o.env });
29
- throw new Error(`Unknown runtime "${runtime}" (use claude, codex or kiro)`);
33
+ if (runtime === 'antigravity')
34
+ return new AntigravityAdapter({ model: o.model, env: o.env });
35
+ throw new Error(`Unknown runtime "${runtime}" (use ${runtimeList()})`);
30
36
  }
@@ -83,8 +83,26 @@ export interface KiroAdapterOptions {
83
83
  export declare class KiroAdapter implements RuntimeAdapter {
84
84
  private o;
85
85
  readonly name = "kiro";
86
- readonly structuredAnswers = true;
87
- readonly remote = true;
86
+ readonly spec: {
87
+ readonly name: "kiro";
88
+ readonly label: "Kiro";
89
+ readonly where: "cloud";
90
+ readonly ach: false;
91
+ readonly structuredAnswers: true;
92
+ readonly perms: readonly import("../perm.js").Perm[];
93
+ readonly limits: {
94
+ readonly net: false;
95
+ readonly denyRead: false;
96
+ };
97
+ readonly reads: "scoped";
98
+ readonly budget: false;
99
+ readonly ownerMemory: "prompt";
100
+ readonly ownFiles: readonly [];
101
+ readonly login: {
102
+ readonly key: "KIRO_API_KEY";
103
+ };
104
+ readonly check: "tool";
105
+ };
88
106
  constructor(o?: KiroAdapterOptions);
89
107
  run(opts: AdapterRunOptions): Promise<AdapterResult>;
90
108
  /** the models this key may use, their credit rate, the effort levels each takes and the default: from an ACP session (`kiro-cli acp`), else `kiro-cli chat --list-models --format json`. */
@@ -1,4 +1,5 @@
1
1
  import { execFileSync } from 'node:child_process';
2
+ import { RUNTIME_SPECS } from './spec.js';
2
3
  import { spawnGroup } from './procgroup.js';
3
4
  import { ask, KIRO_ACP_INPUT, kiroAcpModels, kiroModels } from './models.js';
4
5
  import { modelId } from './types.js';
@@ -266,8 +267,7 @@ const FORMAT_REFUSED = /output[- ]format|stream-json|unexpected argument|not sup
266
267
  export class KiroAdapter {
267
268
  o;
268
269
  name = 'kiro';
269
- structuredAnswers = true;
270
- remote = true;
270
+ spec = RUNTIME_SPECS.kiro;
271
271
  constructor(o = {}) {
272
272
  this.o = o;
273
273
  }
@@ -0,0 +1,164 @@
1
+ import { type Perm } from '../perm.js';
2
+ /**
3
+ * What a runtime (the agent tool a runner drives) can and cannot do: docs/specs/runtimes.md. Data only, so the CLI, the
4
+ * checks and the tests read it without loading a tool's SDK. Nothing outside adapters/ and the checks branches on a
5
+ * runtime's name: it reads these fields. A field exists only when something reads it.
6
+ */
7
+ export interface RuntimeSpec {
8
+ /** The id the hub stores. */
9
+ name: string;
10
+ /** The name people read. */
11
+ label: string;
12
+ /** local: the run works on this machine's files. cloud: elsewhere, on its own clone (no local paths, memory, capabilities). */
13
+ where: 'local' | 'cloud';
14
+ /** The run can call `ach` itself. false: it gets no hub credentials; the runner reports the task from the run's final text. */
15
+ ach: boolean;
16
+ /** Short runs (answer, mention, description) return JSON by a schema and the runner posts it. Implied by `ach: false`. */
17
+ structuredAnswers: boolean;
18
+ /** The permission levels the tool can enforce. */
19
+ perms: readonly Perm[];
20
+ /** What a sandboxed (below `full`) local run can be held to. */
21
+ limits: {
22
+ /** the agent's `net_allow` */
23
+ net: boolean;
24
+ /** not reading the runner's secrets, by any route (commands included) */
25
+ denyRead: boolean;
26
+ };
27
+ /**
28
+ * What a sandboxed local run can read besides its work dir. scoped: only the read roots the runner names. machine: other
29
+ * files on the machine too (other checkouts, /tmp); said when the runner starts, because the owner chooses it knowingly.
30
+ */
31
+ reads: 'scoped' | 'machine';
32
+ /** A run can be stopped at a USD cap. */
33
+ budget: boolean;
34
+ /** native: the tool shows the owner's memory index itself. prompt: the runner puts it in the prompt. */
35
+ ownerMemory: 'native' | 'prompt';
36
+ /** Project instruction files the tool loads by itself; the runner puts the others in the prompt. */
37
+ ownFiles: readonly string[];
38
+ /** The cheap model for housekeeping runs (the agent's description); none: the runtime's default. */
39
+ lightModel?: {
40
+ model: string;
41
+ effort: string;
42
+ };
43
+ /** How the tool is logged in on a machine: the command a person runs, or the environment variable that holds its key. */
44
+ login: {
45
+ command: string;
46
+ } | {
47
+ key: string;
48
+ };
49
+ /** sandbox: login + a real sandbox probe (envcheck.ts). tool: the runtime's own probe (runtimecheck.ts). */
50
+ check: 'sandbox' | 'tool';
51
+ }
52
+ export declare const RUNTIME_SPECS: {
53
+ readonly claude: {
54
+ readonly name: "claude";
55
+ readonly label: "Claude Code";
56
+ readonly where: "local";
57
+ readonly ach: true;
58
+ readonly structuredAnswers: false;
59
+ readonly perms: readonly Perm[];
60
+ readonly limits: {
61
+ readonly net: true;
62
+ readonly denyRead: true;
63
+ };
64
+ readonly reads: "scoped";
65
+ readonly budget: true;
66
+ readonly ownerMemory: "native";
67
+ readonly ownFiles: readonly [];
68
+ readonly lightModel: {
69
+ readonly model: "claude-haiku-5-5";
70
+ readonly effort: "low";
71
+ };
72
+ readonly login: {
73
+ readonly command: "claude auth login";
74
+ };
75
+ readonly check: "sandbox";
76
+ };
77
+ readonly codex: {
78
+ readonly name: "codex";
79
+ readonly label: "Codex";
80
+ readonly where: "local";
81
+ readonly ach: true;
82
+ readonly structuredAnswers: true;
83
+ readonly perms: readonly Perm[];
84
+ readonly limits: {
85
+ readonly net: true;
86
+ readonly denyRead: true;
87
+ };
88
+ readonly reads: "scoped";
89
+ readonly budget: false;
90
+ readonly ownerMemory: "prompt";
91
+ readonly ownFiles: readonly ["AGENTS.md"];
92
+ readonly lightModel: {
93
+ readonly model: "gpt-6.1-sol";
94
+ readonly effort: "medium";
95
+ };
96
+ readonly login: {
97
+ readonly command: "codex login";
98
+ };
99
+ readonly check: "sandbox";
100
+ };
101
+ readonly kiro: {
102
+ readonly name: "kiro";
103
+ readonly label: "Kiro";
104
+ readonly where: "cloud";
105
+ readonly ach: false;
106
+ readonly structuredAnswers: true;
107
+ readonly perms: readonly Perm[];
108
+ readonly limits: {
109
+ readonly net: false;
110
+ readonly denyRead: false;
111
+ };
112
+ readonly reads: "scoped";
113
+ readonly budget: false;
114
+ readonly ownerMemory: "prompt";
115
+ readonly ownFiles: readonly [];
116
+ readonly login: {
117
+ readonly key: "KIRO_API_KEY";
118
+ };
119
+ readonly check: "tool";
120
+ };
121
+ readonly antigravity: {
122
+ readonly name: "antigravity";
123
+ readonly label: "Antigravity";
124
+ readonly where: "local";
125
+ readonly ach: false;
126
+ readonly structuredAnswers: true;
127
+ readonly perms: readonly Perm[];
128
+ readonly limits: {
129
+ readonly net: false;
130
+ readonly denyRead: true;
131
+ };
132
+ readonly reads: "machine";
133
+ readonly budget: false;
134
+ readonly ownerMemory: "prompt";
135
+ readonly ownFiles: readonly [];
136
+ readonly login: {
137
+ readonly command: "agy";
138
+ };
139
+ readonly check: "tool";
140
+ };
141
+ };
142
+ export type RuntimeName = keyof typeof RUNTIME_SPECS;
143
+ export declare const RUNTIME_NAMES: RuntimeName[];
144
+ /** "claude, codex or kiro": the names as a sentence part, for messages. */
145
+ export declare const runtimeList: () => string;
146
+ export declare function isRuntime(v: unknown): v is RuntimeName;
147
+ /** The spec of a runtime `ach run` drives; undefined for any other name (the hub's `other`, a test's fake). */
148
+ export declare function runtimeSpec(name: unknown): RuntimeSpec | undefined;
149
+ /** How people call a runtime: its label, else the name as it is. */
150
+ export declare const runtimeLabel: (name: string) => string;
151
+ /**
152
+ * The level a run gets on this runtime: the highest it can enforce that is not above `perm` (never raised). undefined:
153
+ * it can enforce none at or below it, so the runner must not start.
154
+ */
155
+ export declare function runtimePerm(spec: Pick<RuntimeSpec, 'perms'>, perm: Perm): Perm | undefined;
156
+ /**
157
+ * Why this run must not start on this runtime (fail closed), or undefined. A local run below `full` needs the tool to keep
158
+ * it from the runner's secrets, and to keep the network limit the hub promises unless the agent's `net_allow` is `*`.
159
+ * `full` is both sides' choice of no limits; a cloud run is not on this machine.
160
+ */
161
+ export declare function runRefusal(spec: Pick<RuntimeSpec, 'label' | 'where' | 'perms' | 'limits'>, run: {
162
+ perm: Perm;
163
+ netAllow?: readonly string[];
164
+ }): string | undefined;
@@ -0,0 +1,104 @@
1
+ import { PERMS, permRank } from '../perm.js';
2
+ const ALL = PERMS;
3
+ export const RUNTIME_SPECS = {
4
+ claude: {
5
+ name: 'claude',
6
+ label: 'Claude Code',
7
+ where: 'local',
8
+ ach: true,
9
+ structuredAnswers: false,
10
+ perms: ALL,
11
+ limits: { net: true, denyRead: true },
12
+ reads: 'scoped',
13
+ budget: true,
14
+ ownerMemory: 'native',
15
+ ownFiles: [],
16
+ lightModel: { model: 'claude-haiku-5-5', effort: 'low' },
17
+ login: { command: 'claude auth login' },
18
+ check: 'sandbox',
19
+ },
20
+ codex: {
21
+ name: 'codex',
22
+ label: 'Codex',
23
+ where: 'local',
24
+ ach: true,
25
+ structuredAnswers: true,
26
+ perms: ALL,
27
+ limits: { net: true, denyRead: true },
28
+ reads: 'scoped',
29
+ budget: false,
30
+ ownerMemory: 'prompt',
31
+ ownFiles: ['AGENTS.md'],
32
+ lightModel: { model: 'gpt-6.1-sol', effort: 'medium' },
33
+ login: { command: 'codex login' },
34
+ check: 'sandbox',
35
+ },
36
+ // each run is a Kiro cloud session: the permission level and the limits are the cloud sandbox's, not this machine's
37
+ kiro: {
38
+ name: 'kiro',
39
+ label: 'Kiro',
40
+ where: 'cloud',
41
+ ach: false,
42
+ structuredAnswers: true,
43
+ perms: ALL,
44
+ limits: { net: false, denyRead: false },
45
+ reads: 'scoped',
46
+ budget: false,
47
+ ownerMemory: 'prompt',
48
+ ownFiles: [],
49
+ login: { key: 'KIRO_API_KEY' },
50
+ check: 'tool',
51
+ },
52
+ // one headless `agy` per run on this machine, with its own sandbox (adapters/antigravity.ts says what was tried by hand): no
53
+ // `ach` in the run (a sandboxed command has no network), its web search cannot be turned off, and it reads outside HOME
54
+ antigravity: {
55
+ name: 'antigravity',
56
+ label: 'Antigravity',
57
+ where: 'local',
58
+ ach: false,
59
+ structuredAnswers: true,
60
+ perms: ALL,
61
+ limits: { net: false, denyRead: true },
62
+ reads: 'machine',
63
+ budget: false,
64
+ ownerMemory: 'prompt',
65
+ ownFiles: [],
66
+ login: { command: 'agy' },
67
+ check: 'tool',
68
+ },
69
+ };
70
+ export const RUNTIME_NAMES = Object.keys(RUNTIME_SPECS);
71
+ /** "claude, codex or kiro": the names as a sentence part, for messages. */
72
+ export const runtimeList = () => RUNTIME_NAMES.join(', ').replace(/, ([^,]*)$/, ' or $1');
73
+ export function isRuntime(v) {
74
+ return typeof v === 'string' && Object.hasOwn(RUNTIME_SPECS, v);
75
+ }
76
+ /** The spec of a runtime `ach run` drives; undefined for any other name (the hub's `other`, a test's fake). */
77
+ export function runtimeSpec(name) {
78
+ return isRuntime(name) ? RUNTIME_SPECS[name] : undefined;
79
+ }
80
+ /** How people call a runtime: its label, else the name as it is. */
81
+ export const runtimeLabel = (name) => runtimeSpec(name)?.label ?? name;
82
+ /**
83
+ * The level a run gets on this runtime: the highest it can enforce that is not above `perm` (never raised). undefined:
84
+ * it can enforce none at or below it, so the runner must not start.
85
+ */
86
+ export function runtimePerm(spec, perm) {
87
+ return [...spec.perms].filter((p) => permRank(p) <= permRank(perm)).sort((a, b) => permRank(b) - permRank(a))[0];
88
+ }
89
+ /**
90
+ * Why this run must not start on this runtime (fail closed), or undefined. A local run below `full` needs the tool to keep
91
+ * it from the runner's secrets, and to keep the network limit the hub promises unless the agent's `net_allow` is `*`.
92
+ * `full` is both sides' choice of no limits; a cloud run is not on this machine.
93
+ */
94
+ export function runRefusal(spec, run) {
95
+ if (!spec.perms.includes(run.perm))
96
+ return `${spec.label} cannot enforce the permission level "${run.perm}"`;
97
+ if (spec.where === 'cloud' || run.perm === 'full')
98
+ return undefined;
99
+ if (!spec.limits.denyRead)
100
+ return `${spec.label} cannot keep a run from reading the runner's secrets on this machine; it runs only with full access (the agent's permission level and the runner's --perm both full)`;
101
+ if (!spec.limits.net && !run.netAllow?.includes('*'))
102
+ return `${spec.label} cannot limit a run's network; it runs only for an agent whose network list allows any host (*)`;
103
+ return undefined;
104
+ }
@@ -1,5 +1,6 @@
1
1
  import type { Perm } from '../perm.js';
2
2
  import type { CapsServerSpec } from '../caps.js';
3
+ import type { RuntimeSpec } from './spec.js';
3
4
  /**
4
5
  * `tool_start` / `tool_end` (data: {id}) bracket one tool call; the runner's
5
6
  * idle watchdog is suspended while any call is in flight (C6). `tool_start` data: {id, name, input}; `tool_end` data: {id, is_error?,
@@ -71,14 +72,10 @@ export interface AdapterResult {
71
72
  error?: string;
72
73
  }
73
74
  export interface RuntimeAdapter {
75
+ /** The same as `spec.name`. */
74
76
  readonly name: string;
75
- /** True when answer runs return JSON (ANSWER_SCHEMA) and the runner posts it (codex). */
76
- readonly structuredAnswers?: boolean;
77
- /**
78
- * True when the agent runs somewhere else (a Kiro cloud sandbox) with no `ach` CLI and no hub credentials: the prompt
79
- * says so, and the runner completes or fails the task with the run's final text (it implies structuredAnswers).
80
- */
81
- readonly remote?: boolean;
77
+ /** What this runtime can and cannot do (docs/specs/runtimes.md): the runner reads this, never the name. */
78
+ readonly spec: RuntimeSpec;
82
79
  run(opts: AdapterRunOptions): Promise<AdapterResult>;
83
80
  /**
84
81
  * The models it offers with the environment a run gets (its login decides which), and the one a run uses when none is picked.
@@ -0,0 +1,21 @@
1
+ import { type Run, type SandboxStatus } from './sandboxcheck.js';
2
+ /** The release the adapter was written against (headless stream-json with tool start/end, `--settings`, `denied_actions`). */
3
+ export declare const AGY_MIN_VERSION = "1.5.13";
4
+ /** agy as the runner will start it: ACH_ANTIGRAVITY_BIN, else `agy` on PATH, else where its installer puts it (~/.local/bin). */
5
+ export declare function agyPathOf(env: NodeJS.ProcessEnv): string | undefined;
6
+ /** Linux: AppArmor stops unprivileged user namespaces and no profile lets agy make them (its sandbox then silently does not start). */
7
+ export declare function agySandboxBlocked(o?: {
8
+ platform?: NodeJS.Platform;
9
+ read?: (p: string) => string | undefined;
10
+ }): boolean;
11
+ /**
12
+ * What the antigravity runtime needs on this machine: agy new enough, logged in (its login file exists; never read), and a
13
+ * sandbox that can start (the default permission level runs commands in it).
14
+ */
15
+ export declare function probeAgy(o?: {
16
+ env?: NodeJS.ProcessEnv;
17
+ run?: Run;
18
+ platform?: NodeJS.Platform;
19
+ exists?: (p: string) => boolean;
20
+ read?: (p: string) => string | undefined;
21
+ }): Promise<SandboxStatus>;
@@ -0,0 +1,58 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { isAbsolute, join } from 'node:path';
3
+ import { AGY_APPARMOR, AGY_INSTALL, agyBin } from './adapters/antigravity.js';
4
+ import { parseKiroVersion as parseVersion, versionAtLeast } from './adapters/kiro.js';
5
+ import { defaultRun, onPath } from './sandboxcheck.js';
6
+ /** The release the adapter was written against (headless stream-json with tool start/end, `--settings`, `denied_actions`). */
7
+ export const AGY_MIN_VERSION = '1.5.13';
8
+ const home = (env) => env.HOME || '';
9
+ /** agy as the runner will start it: ACH_ANTIGRAVITY_BIN, else `agy` on PATH, else where its installer puts it (~/.local/bin). */
10
+ export function agyPathOf(env) {
11
+ const b = agyBin(env);
12
+ if (isAbsolute(b))
13
+ return existsSync(b) ? b : undefined;
14
+ const local = home(env) ? join(home(env), '.local', 'bin', b) : '';
15
+ return onPath(b, env) ?? (local && existsSync(local) ? local : undefined);
16
+ }
17
+ /** Linux: AppArmor stops unprivileged user namespaces and no profile lets agy make them (its sandbox then silently does not start). */
18
+ export function agySandboxBlocked(o = {}) {
19
+ if ((o.platform ?? process.platform) !== 'linux')
20
+ return false;
21
+ const read = o.read ??
22
+ ((p) => {
23
+ try {
24
+ return readFileSync(p, 'utf8');
25
+ }
26
+ catch {
27
+ return undefined;
28
+ }
29
+ });
30
+ if (read('/proc/sys/kernel/apparmor_restrict_unprivileged_userns')?.trim() !== '1')
31
+ return false;
32
+ return read('/etc/apparmor.d/agy') === undefined;
33
+ }
34
+ /**
35
+ * What the antigravity runtime needs on this machine: agy new enough, logged in (its login file exists; never read), and a
36
+ * sandbox that can start (the default permission level runs commands in it).
37
+ */
38
+ export async function probeAgy(o = {}) {
39
+ const env = o.env ?? process.env;
40
+ const tool = 'antigravity';
41
+ const bin = agyPathOf(env);
42
+ if (!bin) {
43
+ return { tool, ok: false, problem: 'missing', missing: ['agy'], detail: 'agy not found', fix: { en: `Install the Antigravity CLI (${AGY_INSTALL}), or set ACH_ANTIGRAVITY_BIN to its path.`, zh: `安装 Antigravity CLI(${AGY_INSTALL}),或用 ACH_ANTIGRAVITY_BIN 指定它的路径。`, commands: [AGY_INSTALL] } };
44
+ }
45
+ const r = await (o.run ?? defaultRun)(bin, ['--version'], { env });
46
+ const version = parseVersion(r.stdout || r.stderr);
47
+ if (!version || !versionAtLeast(version, AGY_MIN_VERSION)) {
48
+ return { tool, ok: false, problem: 'failed', detail: `agy ${version ?? '(unknown version)'}: needs ${AGY_MIN_VERSION} or later`, fix: { en: `Update agy to ${AGY_MIN_VERSION} or later.`, zh: `把 agy 升级到 ${AGY_MIN_VERSION} 或更新。`, commands: [`${bin} update`] } };
49
+ }
50
+ const token = join(home(env), '.gemini', 'antigravity-cli', 'antigravity-oauth-token');
51
+ if (!(o.exists ?? existsSync)(token)) {
52
+ return { tool, ok: false, problem: 'not-logged-in', detail: `agy ${version}; not logged in`, fix: { en: 'Antigravity is not logged in on this machine: run `agy` once as the user that runs this agent and sign in.', zh: 'Antigravity 在这台机器上没有登录:以运行这个智能体的用户身份执行一次 `agy` 并登录。', commands: ['agy'] } };
53
+ }
54
+ if (agySandboxBlocked({ platform: o.platform, read: o.read })) {
55
+ return { tool, ok: false, problem: 'userns-blocked', detail: `agy ${version}; its sandbox cannot start (AppArmor restricts unprivileged user namespaces)`, fix: { en: "AppArmor stops agy from creating the user namespaces its sandbox is made of: add a profile that lets it.", zh: 'AppArmor 不让 agy 创建沙箱需要的用户命名空间:加一条放行它的规则。', commands: [AGY_APPARMOR] } };
56
+ }
57
+ return { tool, ok: true, detail: `agy ${version}, logged in` };
58
+ }
@@ -0,0 +1,54 @@
1
+ /** Where the install lives: one per user, shared by every agent home on the machine (they run the same CLI). */
2
+ export declare function appDir(env?: NodeJS.ProcessEnv): string;
3
+ export declare const launcherPath: (app: string) => string;
4
+ /** The CLI file of one release in the install. */
5
+ export declare const cliOf: (app: string, version: string) => string;
6
+ /** Plain JS, run by node: starts the release named in ./current. The CLI checks that it is the entry by process.argv[1]. */
7
+ export declare const LAUNCHER_SCRIPT: string;
8
+ /** The release `current` names, when its files are there. */
9
+ export declare function currentVersion(app?: string): string | undefined;
10
+ /** Is this CLI file inside the install? */
11
+ export declare function inApp(self: string, app?: string): boolean;
12
+ /** The release of the install this CLI file belongs to (from its dir name). */
13
+ export declare function appVersionOf(self: string, app?: string): string | undefined;
14
+ /**
15
+ * The node to start the launcher with: the first `node` on PATH as PATH names it (a version manager's or Homebrew's stable link, not
16
+ * the versioned file behind it, which an upgrade removes), else this one.
17
+ */
18
+ export declare function nodeCommand(env?: NodeJS.ProcessEnv, execPath?: string): string;
19
+ /** How an MCP entry or a service starts the install. */
20
+ export declare function appAch(env?: NodeJS.ProcessEnv, app?: string): string[];
21
+ /** Point the launcher at `version` (its files must be there). Writes the launcher too, so an install that lost it gets it back. */
22
+ export declare function setCurrent(app: string, version: string): void;
23
+ /** The node_modules dir an npx cache run of this CLI lives in, or undefined when it is not one. */
24
+ export declare function npxModulesOf(self: string): string | undefined;
25
+ /**
26
+ * Put the release this CLI is into the install by copying its npx cache dir (nothing is downloaded, so nothing waits on npm), and point
27
+ * `current` at it unless `current` already names a newer release. Returns the install's command, or undefined when this is not an npx
28
+ * run or the copy failed (the caller keeps using npx then).
29
+ */
30
+ export declare function adoptFromNpx(o: {
31
+ self: string;
32
+ env?: NodeJS.ProcessEnv;
33
+ version?: string;
34
+ log?: (s: string) => void;
35
+ }): string[] | undefined;
36
+ export type InstallExec = (file: string, args: string[], o?: {
37
+ timeoutMs?: number;
38
+ }) => Promise<{
39
+ code: number;
40
+ stdout: string;
41
+ stderr: string;
42
+ }>;
43
+ /** Can the install be written (the updater asks before it stops taking work)? */
44
+ export declare function appWritable(app: string): boolean;
45
+ /** Install `version` from npm into a dir of its own (`npm install --prefix`, scripts off), read it back, point `current` at it, prune. */
46
+ export declare function installIntoApp(app: string, version: string, exec: InstallExec): Promise<{
47
+ ok: boolean;
48
+ detail: string;
49
+ }>;
50
+ /**
51
+ * Remove releases nothing should still run: not `current`, not among the three newest, and untouched for three days (an MCP session
52
+ * started on an old release keeps reading its files until it is restarted).
53
+ */
54
+ export declare function pruneApp(app: string, now?: number, keep?: number, minAgeMs?: number): string[];