@netnodeag/kraftwerk 0.95.0 → 0.96.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 (44) hide show
  1. package/README.md +17 -7
  2. package/dist/acp.d.ts +31 -3
  3. package/dist/acp.js +63 -2
  4. package/dist/cli/create-brief.js +2 -2
  5. package/dist/cli/daemon-login.d.ts +1 -1
  6. package/dist/cli/daemon-login.js +1 -1
  7. package/dist/cli/doctor.js +6 -3
  8. package/dist/cli/projects.js +2 -2
  9. package/dist/client/routes.d.ts +1 -0
  10. package/dist/client/routes.js +1 -0
  11. package/dist/core/agents.js +1 -1
  12. package/dist/core/board-wake.d.ts +1 -1
  13. package/dist/core/chat/acp.d.ts +6 -0
  14. package/dist/core/chat/acp.js +33 -7
  15. package/dist/core/chat/permissions.d.ts +2 -2
  16. package/dist/core/chat/permissions.js +4 -1
  17. package/dist/core/chat/pi.d.ts +12 -0
  18. package/dist/core/chat/pi.js +56 -5
  19. package/dist/core/chat/sessions.d.ts +10 -2
  20. package/dist/core/chat/sessions.js +28 -4
  21. package/dist/core/chat/types.d.ts +1 -1
  22. package/dist/harness.d.ts +3 -2
  23. package/dist/harnesses/acp.js +3 -1
  24. package/dist/harnesses/registry.js +2 -1
  25. package/dist/server/api/chats.d.ts +4 -1
  26. package/dist/server/api/chats.js +20 -6
  27. package/dist/server/api/index.d.ts +4 -1
  28. package/package.json +1 -1
  29. package/schema/workflow.schema.json +4 -3
  30. package/web/dist/assets/{dist-SHAE_oEQ.js → dist-14HFV7uD.js} +1 -1
  31. package/web/dist/assets/{dist-BlxwNXF3.js → dist-BYgXVWBg.js} +1 -1
  32. package/web/dist/assets/{dist--oB2_FQJ.js → dist-BiyjchCb.js} +1 -1
  33. package/web/dist/assets/dist-CCZcAg77.js +1 -0
  34. package/web/dist/assets/{dist-Ys1tb91R.js → dist-DKQkCBo9.js} +1 -1
  35. package/web/dist/assets/{dist-SL9iU_p4.js → dist-DO04nOS3.js} +1 -1
  36. package/web/dist/assets/{dist-DB33yOhN.js → dist-DOW1X_nG.js} +1 -1
  37. package/web/dist/assets/{dist-Tdda9sK7.js → dist-DbBrc07-.js} +1 -1
  38. package/web/dist/assets/{dist-CRqkyR9b.js → dist-DkDmdJNX.js} +1 -1
  39. package/web/dist/assets/{dist-WA1PTY07.js → dist-qkoQQWNK.js} +1 -1
  40. package/web/dist/assets/{dist-FlDPUw_l.js → dist-wkkpVezb.js} +1 -1
  41. package/web/dist/assets/{editor-Clx4xAh9.js → editor-DvkpSp7h.js} +3 -3
  42. package/web/dist/assets/{index-BJml45iw.js → index-B5PLhJ-C.js} +16 -16
  43. package/web/dist/index.html +1 -1
  44. package/web/dist/assets/dist-C3zyJ_nA.js +0 -1
package/README.md CHANGED
@@ -486,7 +486,7 @@ For a client of your own, `@netnodeag/kraftwerk/client` takes the token:
486
486
 
487
487
  The repo root ships [`deploy-starter/`](../deploy-starter/). Copy it into your
488
488
  consumer repo as `deploy/` and it builds a small image, this package from npm
489
- plus the claude, codex and pi CLIs, that serves `kraftwerk ui` for that repo
489
+ plus the claude, codex, pi and agy CLIs, that serves `kraftwerk ui` for that repo
490
490
  bind-mounted at `/work`. `compose.yml` is localhost-only, reachable over an
491
491
  SSH tunnel. `compose.traefik.yml` layers traefik routing and mandatory
492
492
  basic-auth on top. Treat that auth as load-bearing. In a container the UI
@@ -569,7 +569,7 @@ record** and the **links**:
569
569
  title: Relaunch netnode.ch
570
570
  status: active
571
571
  goal: Ship the new site on NodeHive by 2026-11-30
572
- harness: claude # claude | codex | pi — every chat in the project runs on it
572
+ harness: claude # claude | codex | pi | antigravity — every chat in the project runs on it
573
573
  model: sonnet # optional, like an agent's
574
574
  effort: high # optional: low | medium | high | xhigh | max
575
575
  records:
@@ -1027,7 +1027,7 @@ agents/max/
1027
1027
  name: Max
1028
1028
  emoji: 🛠️
1029
1029
  description: Runs and explains this project's workflows
1030
- harness: claude # claude | codex | pi (which chat backend runs it)
1030
+ harness: claude # claude | codex | pi | antigravity (which chat backend runs it)
1031
1031
  model: sonnet # optional; harness default when omitted
1032
1032
  effort: medium # optional: low | medium | high | xhigh | max
1033
1033
  workflows: [tagline, website-check]
@@ -1395,7 +1395,7 @@ agents:
1395
1395
  export const desloper = defineAgent({
1396
1396
  id: "desloper",
1397
1397
  name: "Lektorat",
1398
- harness: "codex", // WHERE it runs: claude (default) | codex | pi
1398
+ harness: "codex", // WHERE it runs: claude (default) | codex | pi | antigravity
1399
1399
  model: "gpt-5.6-sol", // WHAT thinks, in the harness's naming
1400
1400
  effort: "high", // optional: low | medium | high | xhigh | max
1401
1401
  tools: ["Read", "Write", "Edit"], // governance: capability boundary
@@ -1450,19 +1450,29 @@ Prerequisites per harness:
1450
1450
  - **pi** needs `npm install -g @earendil-works/pi-coding-agent`. Anthropic
1451
1451
  models reuse the Claude subscription OAuth, other vendors need their key in
1452
1452
  the env (check with `pi auth check --provider deepseek`).
1453
+ - **antigravity** needs Google's Antigravity CLI (`agy`) on the PATH and
1454
+ logged in (`agy acp --login`). It has no headless CLI mode kraftwerk
1455
+ drives: its CLI *is* an ACP server (`agy acp`), so `runs-on: antigravity`
1456
+ always runs over the agent protocol, whatever `protocol` says. `model`
1457
+ picks one of the models `agy models` lists; `effort` becomes its
1458
+ thinking level (low / medium / high; xhigh and max are high) where the
1459
+ model has one. MCP servers reach it the protocol's way (session
1460
+ `mcpServers`). Chats on it cannot be forked.
1453
1461
 
1454
1462
  ### Agent protocol
1455
1463
 
1456
1464
  Phases can also run over the [Agent Client Protocol](https://agentclientprotocol.com)
1457
1465
  — the same adapters the inspector's chats use (`claude-agent-acp`,
1458
- `codex-acp`), bundled with kraftwerk, so nothing needs to be on the PATH.
1466
+ `codex-acp`), bundled with kraftwerk, so nothing needs to be on the PATH —
1467
+ except for antigravity, whose own CLI is the adapter (`agy acp`).
1459
1468
  Set `protocol: acp` at the top of a workflow (every agent) or on one agent;
1460
1469
  `runs-on` still picks the harness (pi has no adapter). The adapter process
1461
1470
  stays alive for the whole run, so phases on one harness share a session
1462
1471
  like `--resume` does on the CLI. Persona and workspace context travel inside
1463
1472
  each phase prompt. On claude the agent's `tools`, CLI grants and MCP servers
1464
1473
  become the session's allowlist (settings sources off) and the session is
1465
- switched to `acceptEdits`; codex runs in its workspace-write mode. A permission request the harness
1474
+ switched to `acceptEdits`; codex runs in its workspace-write mode,
1475
+ antigravity in `accept-edits`. A permission request the harness
1466
1476
  still raises is declined — nobody watches a workflow run, and kraftwerk
1467
1477
  never answers for a human. A programmatic `Run` ends its adapters with
1468
1478
  `disposeAcpSessions(runDir)` (the YAML runner does this itself).
@@ -1500,7 +1510,7 @@ workspace: |
1500
1510
  Dateien: brand.md, tagline.md
1501
1511
  agents:
1502
1512
  analyst:
1503
- runs-on: claude # claude (default) | codex | pi
1513
+ runs-on: claude # claude (default) | codex | pi | antigravity
1504
1514
  model: haiku # effort: low..max optional
1505
1515
  tools: [Read, Write, Edit, WebFetch]
1506
1516
  persona: |
package/dist/acp.d.ts CHANGED
@@ -7,10 +7,14 @@ import type { McpServerConfig } from "./harness.js";
7
7
  * CLI on the PATH is needed), model/effort tuning, and spawning one adapter
8
8
  * as a subprocess speaking ACP over its stdio.
9
9
  *
10
- * Auth rides on the local CLI logins (Claude Code / Codex) via the
11
- * inherited environment — same story as the CLI harnesses.
10
+ * Auth rides on the local CLI logins (Claude Code / Codex / Antigravity)
11
+ * via the inherited environment — same story as the CLI harnesses.
12
+ *
13
+ * Antigravity is the exception to "bundled": Google ships no npm adapter,
14
+ * its own CLI speaks ACP natively (`agy acp`), so that one is spawned from
15
+ * the PATH and needs `agy` installed and logged in.
12
16
  */
13
- export type AcpAgent = "claude" | "codex";
17
+ export type AcpAgent = "claude" | "codex" | "antigravity";
14
18
  /**
15
19
  * Model/effort overrides ride on adapter-specific channels: the claude
16
20
  * adapter takes the model via session `_meta.claudeCode.options` and the
@@ -21,6 +25,19 @@ export declare function adapterEnv(agent: AcpAgent, tuning: {
21
25
  model?: string;
22
26
  effort?: string;
23
27
  }): NodeJS.ProcessEnv;
28
+ /**
29
+ * Model/effort for an adapter that takes them as session config options
30
+ * (Antigravity: `model`, `thought_level`) instead of env or `_meta`: the
31
+ * values to set once the session is open. Only choices the session offers
32
+ * are set; anything else keeps the agent's default.
33
+ */
34
+ export declare function tuningConfig(agent: AcpAgent, tuning: {
35
+ model?: string;
36
+ effort?: string;
37
+ }, options: SessionConfigOption[] | null | undefined): Array<{
38
+ configId: string;
39
+ value: string;
40
+ }>;
24
41
  /** Kraftwerk's MCP config (stdio or url) -> the protocol's session mcpServers entries. */
25
42
  export declare function acpMcpServers(servers?: Record<string, McpServerConfig>): McpServer[];
26
43
  /**
@@ -175,6 +192,17 @@ export declare function connectAcp(agent: AcpAgent, opts: {
175
192
  * `fn` settles.
176
193
  */
177
194
  export declare function withAdapter<T>(agent: AcpAgent, cwd: string, fn: (conn: AcpConnection) => Promise<T>): Promise<T>;
195
+ /**
196
+ * Set the model and thinking depth an adapter takes as session settings
197
+ * (see tuningConfig), the model first: what the thinking depth offers
198
+ * depends on it (agy drops thought_level for a model without levels). A
199
+ * refused setting is reported through `warn` and the agent's default
200
+ * stays. Returns the session's settings as they are afterwards.
201
+ */
202
+ export declare function applyTuningConfig(agent: AcpAgent, conn: Pick<AcpConnection, "setSessionConfigOption">, sessionId: string, tuning: {
203
+ model?: string;
204
+ effort?: string;
205
+ }, options: SessionConfigOption[] | null | undefined, warn: (message: string) => void): Promise<SessionConfigOption[] | null | undefined>;
178
206
  /** The subset of the connection a session open needs (a test can stand in for it). */
179
207
  export type SessionOpener = Pick<AcpConnection, "newSession" | "resumeSession">;
180
208
  export interface OpenedSession {
package/dist/acp.js CHANGED
@@ -9,6 +9,10 @@ const ADAPTERS = {
9
9
  claude: "@agentclientprotocol/claude-agent-acp",
10
10
  codex: "@agentclientprotocol/codex-acp",
11
11
  };
12
+ /** Agents whose own CLI is the ACP server: command + args, spawned from the PATH. */
13
+ const NATIVE = {
14
+ antigravity: ["agy", ["acp"]],
15
+ };
12
16
  /**
13
17
  * The adapter's executable: its package's `bin` (the packages' `exports`
14
18
  * may hide dist/, and claude-agent-acp's main is a library, not the CLI).
@@ -49,6 +53,35 @@ export function adapterEnv(agent, tuning) {
49
53
  }
50
54
  return env;
51
55
  }
56
+ /** Effort tier -> Antigravity's thought_level choices (low | medium | high). */
57
+ const ANTIGRAVITY_THOUGHT = { low: "low", medium: "medium", high: "high", xhigh: "high", max: "high" };
58
+ /**
59
+ * Model/effort for an adapter that takes them as session config options
60
+ * (Antigravity: `model`, `thought_level`) instead of env or `_meta`: the
61
+ * values to set once the session is open. Only choices the session offers
62
+ * are set; anything else keeps the agent's default.
63
+ */
64
+ export function tuningConfig(agent, tuning, options) {
65
+ if (agent !== "antigravity" || !options?.length)
66
+ return [];
67
+ const offers = (id, value) => {
68
+ const o = options.find((x) => x.id === id);
69
+ return !!value && !!o && o.type === "select" && flatChoices(o).includes(value);
70
+ };
71
+ const out = [];
72
+ if (offers("model", tuning.model))
73
+ out.push({ configId: "model", value: tuning.model });
74
+ const level = tuning.effort ? ANTIGRAVITY_THOUGHT[tuning.effort] : undefined;
75
+ if (offers("thought_level", level))
76
+ out.push({ configId: "thought_level", value: level });
77
+ return out;
78
+ }
79
+ /** The values of a select option, its groups flattened. */
80
+ function flatChoices(o) {
81
+ if (o.type !== "select")
82
+ return [];
83
+ return o.options.flatMap((c) => (c.options ? c.options.map((x) => x.value) : c.value ? [c.value] : []));
84
+ }
52
85
  /** Kraftwerk's MCP config (stdio or url) -> the protocol's session mcpServers entries. */
53
86
  export function acpMcpServers(servers = {}) {
54
87
  return Object.entries(servers).map(([name, cfg]) => "url" in cfg
@@ -193,8 +226,12 @@ function agentCalls(ctx) {
193
226
  */
194
227
  export async function connectAcp(agent, opts) {
195
228
  // KRAFTWERK_ACP_ADAPTER: a script standing in for the adapter (the tests' scripted fake agent).
196
- const entry = process.env.KRAFTWERK_ACP_ADAPTER || adapterEntry(agent);
197
- const child = spawn(process.execPath, [entry], {
229
+ const fake = process.env.KRAFTWERK_ACP_ADAPTER;
230
+ const native = NATIVE[agent];
231
+ const [command, args] = fake
232
+ ? [process.execPath, [fake]]
233
+ : native ?? [process.execPath, [adapterEntry(agent)]];
234
+ const child = spawn(command, args, {
198
235
  cwd: opts.cwd,
199
236
  stdio: ["pipe", "pipe", "pipe"],
200
237
  env: opts.env,
@@ -258,6 +295,30 @@ export async function withAdapter(agent, cwd, fn) {
258
295
  child.kill("SIGTERM");
259
296
  }
260
297
  }
298
+ /**
299
+ * Set the model and thinking depth an adapter takes as session settings
300
+ * (see tuningConfig), the model first: what the thinking depth offers
301
+ * depends on it (agy drops thought_level for a model without levels). A
302
+ * refused setting is reported through `warn` and the agent's default
303
+ * stays. Returns the session's settings as they are afterwards.
304
+ */
305
+ export async function applyTuningConfig(agent, conn, sessionId, tuning, options, warn) {
306
+ let current = options;
307
+ for (const configId of ["model", "thought_level"]) {
308
+ const c = tuningConfig(agent, tuning, current).find((x) => x.configId === configId);
309
+ if (!c)
310
+ continue;
311
+ try {
312
+ const res = await conn.setSessionConfigOption({ sessionId, ...c });
313
+ if (res.configOptions)
314
+ current = res.configOptions;
315
+ }
316
+ catch (err) {
317
+ warn(`could not set ${c.configId} to ${c.value} (${err.message})`);
318
+ }
319
+ }
320
+ return current;
321
+ }
261
322
  /**
262
323
  * Open a session: continue `resume` when given (session/resume — the
263
324
  * agent's own transcript carries the history, no replay), else a new one.
@@ -32,7 +32,7 @@ nothing to register.
32
32
  sequences fit YAML; if the requirements demand loops or human approval
33
33
  gates, STOP and tell the user this needs a TypeScript workflow instead.
34
34
  - **Agents**: one per role — persona (WHO), model + optional effort (WHAT
35
- thinks), tools (governance), \`runs-on\` (WHERE: claude | codex | pi).
35
+ thinks), tools (governance), \`runs-on\` (WHERE: claude | codex | pi | antigravity).
36
36
  - **Gates** per step: what file evidence proves the step worked?
37
37
  3. Write \`${root}/<name>/workflow.yml\`. Complete example of every feature:
38
38
 
@@ -59,7 +59,7 @@ nothing to register.
59
59
  persona: |
60
60
  You analyze brands based on their website ...
61
61
  writer:
62
- runs-on: codex # optional: claude (default) | codex | pi
62
+ runs-on: codex # optional: claude (default) | codex | pi | antigravity
63
63
  model: gpt-5.6-sol
64
64
  effort: high # optional: low | medium | high | xhigh | max
65
65
  tools: [Read, Write, Edit]
@@ -3,7 +3,7 @@
3
3
  * (a LaunchAgent), so it runs after a reboot without a terminal or the
4
4
  * desktop app. launchd starts the same `kraftwerk daemon` a terminal would —
5
5
  * this node, this install — with the PATH of the shell that installed it,
6
- * because launchd's own PATH would not find the agents (claude, codex, pi).
6
+ * because launchd's own PATH would not find the agents (claude, codex, pi, agy).
7
7
  * The daemon's supervisor restarts it after a self-update; launchd only
8
8
  * starts it at login.
9
9
  */
@@ -11,7 +11,7 @@ import { tildify } from "../core/instances.js";
11
11
  * (a LaunchAgent), so it runs after a reboot without a terminal or the
12
12
  * desktop app. launchd starts the same `kraftwerk daemon` a terminal would —
13
13
  * this node, this install — with the PATH of the shell that installed it,
14
- * because launchd's own PATH would not find the agents (claude, codex, pi).
14
+ * because launchd's own PATH would not find the agents (claude, codex, pi, agy).
15
15
  * The daemon's supervisor restarts it after a self-update; launchd only
16
16
  * starts it at login.
17
17
  */
@@ -214,7 +214,9 @@ export async function runDoctor(cwd, opts = {}) {
214
214
  let acp = false;
215
215
  for (const e of found) {
216
216
  for (const a of e.workflow?.meta.agents ?? []) {
217
- if (a.protocol === "acp")
217
+ if (a.harness === "antigravity")
218
+ needed.add("antigravity");
219
+ else if (a.protocol === "acp")
218
220
  acp = true;
219
221
  else
220
222
  needed.add(a.harness ?? "claude");
@@ -222,8 +224,9 @@ export async function runDoctor(cwd, opts = {}) {
222
224
  }
223
225
  if (acp)
224
226
  report("ok", "agent protocol adapters", "claude-agent-acp + codex-acp bundled with kraftwerk");
225
- for (const harness of ["claude", "codex", "pi"]) {
226
- const version = cliVersion(harness);
227
+ // Antigravity has no bundled adapter: its own CLI (agy) is the ACP server, needed on either protocol.
228
+ for (const harness of ["claude", "codex", "pi", "antigravity"]) {
229
+ const version = cliVersion(harness === "antigravity" ? "agy" : harness);
227
230
  const isNeeded = needed.has(harness);
228
231
  if (version) {
229
232
  report("ok", `${harness} CLI`, version);
@@ -100,7 +100,7 @@ export function registerProjectCommands(program) {
100
100
  .argument("<title>", "Display title; the folder name is derived from it unless --slug is given")
101
101
  .option("--goal <text>", "One-line goal")
102
102
  .option("--slug <slug>", "Folder name under the root (lowercase, digits, dashes)")
103
- .option("--harness <harness>", "Harness every chat in the project runs on: claude | codex | pi (default: claude)")
103
+ .option("--harness <harness>", "Harness every chat in the project runs on: claude | codex | pi | antigravity (default: claude)")
104
104
  .option("--model <model>", "Model for that harness (default: the harness default)")
105
105
  .option("--effort <effort>", "Reasoning effort: low | medium | high | xhigh | max")
106
106
  .option("--json", "Print the new project as JSON")
@@ -141,7 +141,7 @@ export function registerProjectCommands(program) {
141
141
  .command("set")
142
142
  .description("Change the project's harness, model, effort, status or goal (like an agent's settings)")
143
143
  .argument("<slug>", "Project folder name")
144
- .option("--harness <harness>", "claude | codex | pi")
144
+ .option("--harness <harness>", "claude | codex | pi | antigravity")
145
145
  .option("--model <model>", 'Model for the harness; "" for the default')
146
146
  .option("--effort <effort>", 'low | medium | high | xhigh | max; "" for the default')
147
147
  .option("--status <status>", "active | paused | done | archived")
@@ -10,6 +10,7 @@ export declare const ROUTES: {
10
10
  readonly "agents.get": readonly ["GET", "/api/agents/:slug"];
11
11
  readonly "agents.journal": readonly ["GET", "/api/agents/:slug/journal"];
12
12
  readonly "agents.list": readonly ["GET", "/api/agents"];
13
+ readonly "agents.options": readonly ["GET", "/api/agent-options"];
13
14
  readonly "agents.routines": readonly ["GET", "/api/agents/:slug/routines"];
14
15
  readonly "agents.runRoutine": readonly ["POST", "/api/agents/:slug/routines/:id/run"];
15
16
  readonly "agents.save": readonly ["PUT", "/api/agents/:slug"];
@@ -11,6 +11,7 @@ export const ROUTES = {
11
11
  "agents.get": ["GET", "/api/agents/:slug"],
12
12
  "agents.journal": ["GET", "/api/agents/:slug/journal"],
13
13
  "agents.list": ["GET", "/api/agents"],
14
+ "agents.options": ["GET", "/api/agent-options"],
14
15
  "agents.routines": ["GET", "/api/agents/:slug/routines"],
15
16
  "agents.runRoutine": ["POST", "/api/agents/:slug/routines/:id/run"],
16
17
  "agents.save": ["PUT", "/api/agents/:slug"],
@@ -15,7 +15,7 @@ import { moveToTrash } from "./trash.js";
15
15
  * Definitions are git-tracked project config (like workflows/), not run
16
16
  * state — sessions with a member are ordinary chats scoped to it.
17
17
  */
18
- export const HARNESSES = ["claude", "codex", "pi"];
18
+ export const HARNESSES = ["claude", "codex", "pi", "antigravity"];
19
19
  export const EFFORTS = ["low", "medium", "high", "xhigh", "max"];
20
20
  export const toSummary = (a) => ({
21
21
  slug: a.slug,
@@ -1,7 +1,7 @@
1
1
  /** A chat on the task page: the agent's task session (scope.task) or a chat tagged with the task (meta.task, "work on this"). */
2
2
  export interface TaskSession {
3
3
  id: string;
4
- /** The agent slug of a task session; "claude" | "codex" | "pi" for a plain chat tagged with the task. */
4
+ /** The agent slug of a task session; "claude" | "codex" | "pi" | "antigravity" for a plain chat tagged with the task. */
5
5
  agent: string;
6
6
  /** The agent's display name and emoji when it is one of the workspace's agents. */
7
7
  name?: string;
@@ -43,6 +43,12 @@ export declare function listAgentSessions(agent: AcpAgent, cwd: string): Promise
43
43
  updatedAt?: string;
44
44
  cwd: string;
45
45
  }>>;
46
+ /**
47
+ * The settings a fresh session of the agent offers (model, thinking depth,
48
+ * ... as the agent announces them for this login), from a short-lived
49
+ * adapter that opens one session and closes it without a prompt.
50
+ */
51
+ export declare function announcedOptions(agent: AcpAgent, cwd: string): Promise<ConfigOption[]>;
46
52
  /** Remove one of the agent's sessions for good (its transcript on disk), from a short-lived adapter. */
47
53
  export declare function deleteAgentSession(agent: AcpAgent, cwd: string, sessionId: string): Promise<void>;
48
54
  export declare function startAcpBackend(agent: AcpAgent, cwd: string, hooks: BackendHooks, tuning?: BackendTuning): Promise<ChatBackend>;
@@ -2,12 +2,12 @@ import { randomUUID } from "node:crypto";
2
2
  import { promises as fs } from "node:fs";
3
3
  import { pathToFileURL } from "node:url";
4
4
  import { RequestError, } from "@agentclientprotocol/sdk/unstable";
5
- import { adapterEnv, airMeta, connectAcp, EXT_METHODS, EXT_NOTIFICATIONS, fileChangeReportMeta, openSession, withAdapter, } from "../../acp.js";
5
+ import { adapterEnv, applyTuningConfig, airMeta, connectAcp, EXT_METHODS, EXT_NOTIFICATIONS, fileChangeReportMeta, openSession, withAdapter, } from "../../acp.js";
6
6
  import { identityEnv } from "./backend.js";
7
7
  import { tempEnv } from "../temp.js";
8
8
  import { unattendedMode } from "./permissions.js";
9
9
  /**
10
- * ACP-backed chat: spawn an adapter (claude-agent-acp / codex-acp) as a
10
+ * ACP-backed chat: spawn an adapter (claude-agent-acp / codex-acp / agy acp) as a
11
11
  * subprocess, speak Agent Client Protocol over its stdio, and translate
12
12
  * session/update notifications into chat events. One subprocess lives for
13
13
  * the whole chat; the ACP session id carries the conversation and is
@@ -340,6 +340,18 @@ export async function listAgentSessions(agent, cwd) {
340
340
  .sort((a, b) => (b.updatedAt ?? "").localeCompare(a.updatedAt ?? ""));
341
341
  });
342
342
  }
343
+ /**
344
+ * The settings a fresh session of the agent offers (model, thinking depth,
345
+ * ... as the agent announces them for this login), from a short-lived
346
+ * adapter that opens one session and closes it without a prompt.
347
+ */
348
+ export async function announcedOptions(agent, cwd) {
349
+ return withAdapter(agent, cwd, async (conn) => {
350
+ const s = await conn.newSession({ cwd, mcpServers: [] });
351
+ await conn.closeSession({ sessionId: s.sessionId }).catch(() => { });
352
+ return configOptions(s.configOptions);
353
+ });
354
+ }
343
355
  /** Remove one of the agent's sessions for good (its transcript on disk), from a short-lived adapter. */
344
356
  export async function deleteAgentSession(agent, cwd, sessionId) {
345
357
  await withAdapter(agent, cwd, async (conn) => {
@@ -353,13 +365,23 @@ export async function startAcpBackend(agent, cwd, hooks, tuning = {}) {
353
365
  // Usage arrives after nearly every chunk; the thread keeps a step per
354
366
  // percent of the window and every cost total (turn ends), not each tick.
355
367
  let usagePercent = -1;
368
+ // The slash commands as last announced. An agent may announce them while
369
+ // the session is still opening (agy does, during session/new and while its
370
+ // settings are set) — before the backend object exists.
371
+ let commands;
372
+ let made;
356
373
  const client = {
357
374
  sessionUpdate(params) {
358
- const ev = translateUpdate(sessionId, params);
375
+ // Nothing but the session being opened can speak before its id is known.
376
+ const opening = !sessionId && params.update.sessionUpdate === "available_commands_update";
377
+ const ev = translateUpdate(opening ? params.sessionId : sessionId, params);
359
378
  if (!ev)
360
379
  return;
361
- if (ev.type === "commands")
362
- backend.commands = ev.commands;
380
+ if (ev.type === "commands") {
381
+ commands = ev.commands;
382
+ if (made)
383
+ made.commands = ev.commands;
384
+ }
363
385
  if (ev.type === "usage") {
364
386
  const pct = ev.size > 0 ? Math.floor((100 * ev.used) / ev.size) : 0;
365
387
  if (ev.costUsd == null && pct === usagePercent)
@@ -440,8 +462,10 @@ export async function startAcpBackend(agent, cwd, hooks, tuning = {}) {
440
462
  message: `could not resume the previous ${agent} session (${session.resumeError}) — starting a fresh one; the agent gets the conversation so far as context, not as memory`,
441
463
  });
442
464
  }
443
- if (session.configOptions?.length)
444
- hooks.emit({ type: "config", options: configOptions(session.configOptions) });
465
+ // Antigravity takes the agent's or project's model and thinking depth as session settings.
466
+ const opened = await applyTuningConfig(agent, conn, sessionId, tuning, session.configOptions, (message) => hooks.emit({ type: "error", message: `${message} — the ${agent} default applies` }));
467
+ if (opened?.length)
468
+ hooks.emit({ type: "config", options: configOptions(opened) });
445
469
  if (tuning.unattended) {
446
470
  // Nobody is watching: keep the harness's configured mode unless it is
447
471
  // one that never asks (see unattendedMode). The harness keeps deciding
@@ -467,6 +491,7 @@ export async function startAcpBackend(agent, cwd, hooks, tuning = {}) {
467
491
  const backend = {
468
492
  sessionId,
469
493
  resumed: session.resumed,
494
+ ...(commands ? { commands } : {}),
470
495
  async prompt(text, files) {
471
496
  if (dead)
472
497
  throw new Error(`${agent} agent process is gone — start a new chat`);
@@ -567,5 +592,6 @@ export async function startAcpBackend(agent, cwd, hooks, tuning = {}) {
567
592
  });
568
593
  },
569
594
  };
595
+ made = backend;
570
596
  return backend;
571
597
  }
@@ -29,8 +29,8 @@ export declare function unattendedTimeoutLabel(ms?: number): string;
29
29
  * to, or null to keep the current one. The harness stays the judge of what
30
30
  * needs a human; this only rules out the two presets that never ask —
31
31
  * claude bypassPermissions and codex agent-full-access — and lifts claude's
32
- * plain "default" (ask for every edit) to acceptEdits so a routine can write
32
+ * (and antigravity's) plain "default" (ask for every edit) to acceptEdits so a routine can write
33
33
  * inside the project without stalling. claude's "auto" mode (its own
34
34
  * classifier decides) and acceptEdits are kept as they are.
35
35
  */
36
- export declare function unattendedMode(agent: "claude" | "codex", current: string | undefined): string | null;
36
+ export declare function unattendedMode(agent: "claude" | "codex" | "antigravity", current: string | undefined): string | null;
@@ -31,12 +31,15 @@ export function unattendedTimeoutLabel(ms = UNATTENDED_PERMISSION_TIMEOUT_MS) {
31
31
  * to, or null to keep the current one. The harness stays the judge of what
32
32
  * needs a human; this only rules out the two presets that never ask —
33
33
  * claude bypassPermissions and codex agent-full-access — and lifts claude's
34
- * plain "default" (ask for every edit) to acceptEdits so a routine can write
34
+ * (and antigravity's) plain "default" (ask for every edit) to acceptEdits so a routine can write
35
35
  * inside the project without stalling. claude's "auto" mode (its own
36
36
  * classifier decides) and acceptEdits are kept as they are.
37
37
  */
38
38
  export function unattendedMode(agent, current) {
39
39
  if (agent === "codex")
40
40
  return current === "agent-full-access" || !current ? "agent" : null;
41
+ // antigravity: "default" asks for every edit; "auto" and "accept-edits" still ask before what matters.
42
+ if (agent === "antigravity")
43
+ return current === "auto" || current === "accept-edits" ? null : "accept-edits";
41
44
  return current === "auto" || current === "acceptEdits" ? null : "acceptEdits";
42
45
  }
@@ -1,2 +1,14 @@
1
1
  import { type BackendHooks, type BackendTuning, type ChatBackend } from "./backend.js";
2
+ import type { ConfigOption } from "./types.js";
3
+ /**
4
+ * The models pi can run (`pi --list-models`: its providers with a login or
5
+ * key), as `provider/id`. Empty when pi is missing.
6
+ */
7
+ export declare function listPiModels(): Promise<string[]>;
8
+ /**
9
+ * pi's model and thinking level in the shape ACP agents announce theirs
10
+ * (a select each, "default" = pi's own setting), so the chat's pickers and
11
+ * a new chat's start options treat pi like the others.
12
+ */
13
+ export declare function piOptions(models: string[], model?: string, effort?: string): ConfigOption[];
2
14
  export declare function startPiBackend(cwd: string, hooks: BackendHooks, tuning?: BackendTuning): ChatBackend;
@@ -1,8 +1,36 @@
1
- import { spawn } from "node:child_process";
1
+ import { execFile, spawn } from "node:child_process";
2
2
  import { randomUUID } from "node:crypto";
3
3
  import { identityEnv } from "./backend.js";
4
4
  import { workspaceEnv } from "../env.js";
5
5
  import { tempEnv } from "../temp.js";
6
+ /** pi's --thinking levels. */
7
+ const PI_THINKING = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
8
+ /**
9
+ * The models pi can run (`pi --list-models`: its providers with a login or
10
+ * key), as `provider/id`. Empty when pi is missing.
11
+ */
12
+ export function listPiModels() {
13
+ return new Promise((resolve) => {
14
+ execFile("pi", ["--list-models"], { env: workspaceEnv(), timeout: 20_000 }, (err, stdout) => {
15
+ if (err)
16
+ return resolve([]);
17
+ const rows = stdout.split("\n").slice(1).map((l) => l.trim().split(/\s+/));
18
+ resolve(rows.filter((r) => r.length >= 2 && r[0] && r[1]).map(([provider, id]) => `${provider}/${id}`));
19
+ });
20
+ });
21
+ }
22
+ /**
23
+ * pi's model and thinking level in the shape ACP agents announce theirs
24
+ * (a select each, "default" = pi's own setting), so the chat's pickers and
25
+ * a new chat's start options treat pi like the others.
26
+ */
27
+ export function piOptions(models, model, effort) {
28
+ const known = model && !models.includes(model) ? [model, ...models] : models;
29
+ return [
30
+ { id: "model", name: "Model", category: "model", type: "select", value: model ?? "default", choices: [{ value: "default", name: "pi's default" }, ...known.map((m) => ({ value: m, name: m }))] },
31
+ { id: "thinking", name: "Thinking", category: "thought_level", type: "select", value: effort ?? "default", choices: [{ value: "default", name: "pi's default" }, ...PI_THINKING.map((t) => ({ value: t, name: t }))] },
32
+ ];
33
+ }
6
34
  const clip = (raw) => {
7
35
  const oneLine = String(raw ?? "").replace(/\s+/g, " ").trim();
8
36
  return oneLine.length > 120 ? `${oneLine.slice(0, 120)}…` : oneLine;
@@ -11,11 +39,21 @@ export function startPiBackend(cwd, hooks, tuning = {}) {
11
39
  const sessionId = randomUUID();
12
40
  let child = null;
13
41
  let cancelled = false;
14
- const tuningArgs = [
15
- ...(tuning.model ? ["--model", tuning.model] : []),
16
- ...(tuning.effort ? ["--thinking", tuning.effort] : []),
42
+ // pi runs one process per message: a changed setting applies from the next one.
43
+ let model = tuning.model;
44
+ let effort = tuning.effort;
45
+ const args = () => [
46
+ ...(model ? ["--model", model] : []),
47
+ ...(effort ? ["--thinking", effort] : []),
17
48
  ...(tuning.skillDirs ?? []).flatMap((dir) => ["--skill", dir]),
18
49
  ];
50
+ const models = listPiModels();
51
+ const announce = async () => {
52
+ const options = piOptions(await models, model, effort);
53
+ hooks.emit({ type: "config", options });
54
+ return options;
55
+ };
56
+ void announce();
19
57
  return {
20
58
  prompt(text, files) {
21
59
  // pi takes text only: name the files, they are on disk for it to open.
@@ -23,7 +61,7 @@ export function startPiBackend(cwd, hooks, tuning = {}) {
23
61
  text += `\n\nAttached files:\n${files.map((f) => `- ${f.name} (${f.mimeType}, ${f.path})`).join("\n")}`;
24
62
  cancelled = false;
25
63
  return new Promise((resolve, reject) => {
26
- const proc = spawn("pi", ["-p", "--mode", "json", "--session-id", sessionId, ...tuningArgs], {
64
+ const proc = spawn("pi", ["-p", "--mode", "json", "--session-id", sessionId, ...args()], {
27
65
  cwd,
28
66
  stdio: ["pipe", "pipe", "pipe"],
29
67
  env: { ...workspaceEnv(), ...(tuning.temp ? tempEnv(tuning.temp) : {}), ...identityEnv("pi", tuning) },
@@ -101,6 +139,19 @@ export function startPiBackend(cwd, hooks, tuning = {}) {
101
139
  });
102
140
  });
103
141
  },
142
+ async setConfig(configId, value) {
143
+ const v = typeof value === "string" && value !== "default" ? value : undefined;
144
+ if (configId === "model")
145
+ model = v;
146
+ else if (configId === "thinking") {
147
+ if (v && !PI_THINKING.includes(v))
148
+ throw new Error(`pi has no thinking level "${v}"`);
149
+ effort = v;
150
+ }
151
+ else
152
+ throw new Error(`pi has no setting "${configId}"`);
153
+ return announce();
154
+ },
104
155
  cancel() {
105
156
  cancelled = true;
106
157
  child?.kill("SIGTERM");
@@ -1,4 +1,4 @@
1
- import type { Attachment, ChatAgentId, ChatMeta, ChatPerson, ChatScope, ElicitationAnswer, StoredChatEvent } from "./types.js";
1
+ import type { Attachment, ChatAgentId, ChatMeta, ConfigOption, ChatPerson, ChatScope, ElicitationAnswer, StoredChatEvent } from "./types.js";
2
2
  import { type Channel } from "../channels.js";
3
3
  export { agentFilesContext, agentJournalContext, agentVibeablesContext, vibeableContext } from "./context.js";
4
4
  export { disposeAllBackends, disposeWorkspaceBackends } from "./state.js";
@@ -36,6 +36,8 @@ export declare function createChat(opts: {
36
36
  author?: ChatPerson;
37
37
  /** A private routine's run: hidden from remote callers (meta.private). */
38
38
  private?: boolean;
39
+ /** Settings to start with (model, thinking depth, by config id): applied before the first prompt (meta.pendingConfig). */
40
+ config?: Record<string, string | boolean>;
39
41
  }): Promise<ChatMeta>;
40
42
  /** A permission request is waiting for a human in this chat (live state only — a restart drops it with the backend). */
41
43
  export declare function chatAwaitingApproval(id: string): boolean;
@@ -116,7 +118,7 @@ export declare function setChatVibeable(id: string, slug: string | null): Promis
116
118
  * Fork a chat: a new chat with the same transcript whose agent continues
117
119
  * from a copy of this session (session/fork) — try something without
118
120
  * losing the original thread. Needs a session to fork: an agent that keeps
119
- * one (claude, codex — pi has no ACP session) that has answered at least
121
+ * one (claude — codex and antigravity have no fork, pi has no ACP session) that has answered at least
120
122
  * once. The source's process is (re)spawned if needed; the fork's own
121
123
  * process starts with its first message and resumes the forked id.
122
124
  */
@@ -161,6 +163,12 @@ export declare function listAgentSessionsFor(agent: ChatAgentId): Promise<Array<
161
163
  updatedAt?: string;
162
164
  cwd: string;
163
165
  }>>;
166
+ /**
167
+ * The model and thinking depth a new chat on `agent` can start with — the
168
+ * choices the agent itself announces (they depend on its login and
169
+ * version, so there is no fixed list); pi's from `pi --list-models`.
170
+ */
171
+ export declare function startOptionsFor(agent: ChatAgentId): Promise<ConfigOption[]>;
164
172
  export declare function resolvePermission(id: string, requestId: string, optionId: string | null): Promise<{
165
173
  error?: string;
166
174
  }>;