@juanbenjumea/pi-agy 0.6.11 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +59 -2
- package/extensions/commands.ts +66 -105
- package/extensions/index.ts +164 -47
- package/extensions/lib/args.ts +125 -0
- package/extensions/lib/cli.ts +31 -1223
- package/extensions/lib/command-args.ts +101 -0
- package/extensions/lib/config.ts +36 -1
- package/extensions/lib/confirm.ts +43 -0
- package/extensions/lib/doctor.ts +37 -1
- package/extensions/lib/inspect.ts +254 -0
- package/extensions/lib/lock.ts +1 -1
- package/extensions/lib/model-sort.ts +46 -0
- package/extensions/lib/provider-driver.ts +728 -0
- package/extensions/lib/provider-mcp.ts +580 -0
- package/extensions/lib/provider-models.ts +251 -0
- package/extensions/lib/provider.ts +1148 -0
- package/extensions/lib/retry.ts +34 -0
- package/extensions/lib/spawn.ts +411 -0
- package/extensions/lib/usage.ts +398 -0
- package/extensions/lib/verify.ts +11 -0
- package/package.json +6 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.1
|
|
4
|
+
|
|
5
|
+
- Report provider runtime state in `/agy doctor` (driver turns/reuses/recycles, bridge tool count, suspended turns awaiting Pi tools, live image staging) via a never-throwing status snapshot.
|
|
6
|
+
- Add `/agy bridge [on|off|status]`: inspect or toggle the provider MCP bridge at runtime, persisted to `agy-config.json` with memoized servers invalidated so the next turn picks it up.
|
|
7
|
+
- Full 277-test gate plus typecheck and package checks pass.
|
|
8
|
+
|
|
9
|
+
## 0.7.0
|
|
10
|
+
|
|
11
|
+
- Register an `antigravity` provider so agy-backed models appear in Pi's global `/model` picker as `antigravity/*`, discovered from live `agy models` with a fallback catalog (background refresh, no `/reload`). Gemini bases expose Pi's thinking toggle as agy `--effort` clamped to supported tiers; fixed-thinking families keep agy's exact slug.
|
|
12
|
+
- Run provider turns on a persistent `agy --input-format stream-json` driver process per directory: serialized queue, reuse on matching profile and conversation, recycle with recorded reasons on drift, abort/timeout as kill-and-respawn with flagged partial text, idle reaping, and session-shutdown disposal.
|
|
13
|
+
- Bridge Pi tools into agy turns over a localhost MCP server injected via an extra `--add-dir` (per-process secret, no global config changes): read-only context tools (sessions, quota, model catalog) plus mutating Pi tools through parked calls and real shadow `toolCall` turns, so Pi permissions, approvals, and diff review engage. `providerBridge: false` opts out.
|
|
14
|
+
- Stage attached images as 0700 files agy opens by path (newest 8, 8 MiB each, strict base64); models advertise image input. Staging is owned per turn, carried across parks, and reclaimed on settle, cancel, abandonment, or teardown.
|
|
15
|
+
- Serialize provider turns on the existing per-directory lock, record them in the shared session store (preserving delegation agents), surface driver/bridge/suspension/staging state in `/agy doctor`, and live-verify discovery, tool calls, and park round-trips against real agy. Do not install `@estebanforge/pi-antigravity-bridge` alongside this package (shared provider id and `/agy` command).
|
|
16
|
+
- Independent reviews per milestone with zero open blockers; the full 273-test gate plus typecheck and package checks pass.
|
|
17
|
+
|
|
3
18
|
## 0.6.11
|
|
4
19
|
|
|
5
20
|
- Parse agy 1.1.27+ `denied_actions` from nested stream results and top-level JSON envelopes, sanitizing, deduplicating, and bounding the untrusted action metadata.
|
package/README.md
CHANGED
|
@@ -37,6 +37,60 @@ Requires Node.js >= 20.3.
|
|
|
37
37
|
|
|
38
38
|
Auth is unchanged: existing `agy` OAuth (`~/.gemini/oauth_creds.json`).
|
|
39
39
|
|
|
40
|
+
## Antigravity provider (`/model` picker)
|
|
41
|
+
|
|
42
|
+
This package also registers an `antigravity` provider, so agy-backed models
|
|
43
|
+
appear in Pi's global `/model` picker as `antigravity/<id>` (for example
|
|
44
|
+
`antigravity/gemini-3-8-flash`). Model entries are discovered from live
|
|
45
|
+
`agy models` output at startup (refreshed in the background, no `/reload`
|
|
46
|
+
needed); when discovery fails, a fallback catalog keeps the picker populated
|
|
47
|
+
and selection yields a clear runtime error instead of an empty list.
|
|
48
|
+
|
|
49
|
+
Gemini bases with multiple effort tiers expose Pi's thinking-level toggle,
|
|
50
|
+
which is sent as agy `--effort` (clamped to tiers the base accepts — Pro has
|
|
51
|
+
no medium). Fixed-thinking families (Claude, GPT-OSS) keep agy's exact slug
|
|
52
|
+
and never receive `--effort`.
|
|
53
|
+
|
|
54
|
+
Attached images are staged as files under a process-stable 0700 root
|
|
55
|
+
(passed as `--add-dir` so sandboxed turns can open them) and referenced by
|
|
56
|
+
path in the turn prompt, so agy opens them with its file tools; images on
|
|
57
|
+
tool results ride the delivery the same way. Capped at the 8 newest images /
|
|
58
|
+
8 MiB each with strict base64 validation — failures degrade to omitted notes.
|
|
59
|
+
Each staging has a dispose handle owned by its turn (suspensions carry
|
|
60
|
+
theirs forward); terminal settle, stale-cancel, abandonment, and session
|
|
61
|
+
shutdown all reclaim.
|
|
62
|
+
|
|
63
|
+
Each turn runs on a persistent `agy --input-format stream-json` driver
|
|
64
|
+
process (one per working directory) with the transcript rendered as text.
|
|
65
|
+
The process is reused across turns — follow-ups skip cold start and re-auth —
|
|
66
|
+
and recycled when the model, effort, permissions, or conversation drifts; idle
|
|
67
|
+
processes are reaped after five minutes and everything is disposed on session
|
|
68
|
+
shutdown. Completed turns are recorded to the same session store as
|
|
69
|
+
delegation runs, so `/agy sessions` can resume them. Provider turns take the
|
|
70
|
+
same per-directory lock as delegation runs (lock waits count against the turn
|
|
71
|
+
timeout), so a provider turn never races `agy_execute` in the same directory.
|
|
72
|
+
|
|
73
|
+
Read-only tool bridge: provider turns also get an extra `--add-dir`
|
|
74
|
+
carrying a localhost MCP server (`pi-agy-tools`) that exposes Pi-side
|
|
75
|
+
context agy cannot see otherwise — `agy_sessions_list`, `agy_quota_report`,
|
|
76
|
+
and `agy_model_catalog`. The server binds 127.0.0.1 with a per-process
|
|
77
|
+
shared secret, serves only reads, and never touches your global agy config.
|
|
78
|
+
Set `"providerBridge": false` in `agy-config.json` to run provider turns
|
|
79
|
+
plain.
|
|
80
|
+
|
|
81
|
+
Mutating tool bridge: agy turns can also call Pi tools directly. The bridge
|
|
82
|
+
parks the MCP call, the provider emits a real shadow `toolCall`, and Pi
|
|
83
|
+
executes it with normal permissions, approvals, and diff review; the next
|
|
84
|
+
turn's `toolResult` completes the parked call and agy continues. Only active
|
|
85
|
+
non-builtin tools are exposed (`agy_*` and `AskAntigravity` excluded — no
|
|
86
|
+
recursive delegation); the catalog refreshes per turn and the driver recycles
|
|
87
|
+
when it changes so agy always sees a fresh tool list. Suspended turns hold
|
|
88
|
+
the agy child with timers off, re-arm on resume, and are abandoned loudly on
|
|
89
|
+
cancel, teardown, or a 30-minute stall cap.
|
|
90
|
+
|
|
91
|
+
Do not install `@estebanforge/pi-antigravity-bridge` alongside this package:
|
|
92
|
+
both register the `antigravity` provider id and an `/agy` command.
|
|
93
|
+
|
|
40
94
|
## Timeouts & cancellation
|
|
41
95
|
|
|
42
96
|
`timeout_ms` (default 5m, max 10m) is a hard parent-side deadline — lock
|
|
@@ -138,8 +192,9 @@ Run agy directly from the Pi TUI — fast path when fully specified, wizard othe
|
|
|
138
192
|
/agy continue fix the tests # continue this directory's last conversation
|
|
139
193
|
/agy timeout=10m sonnet big task # raise the run cap (also 90s / 1500ms; bare = minutes)
|
|
140
194
|
/agy sessions # pick a recorded conversation to resume
|
|
141
|
-
/agy doctor # diagnose CLI, models, agents, quota, config, sessions, lock, and repo gate
|
|
195
|
+
/agy doctor # diagnose CLI, models, agents, quota, config, sessions, lock, provider, and repo gate
|
|
142
196
|
/agy usage # inspect model quotas and reset times
|
|
197
|
+
/agy bridge [on|off] # inspect or toggle the provider MCP bridge (takes effect next turn)
|
|
143
198
|
```
|
|
144
199
|
|
|
145
200
|
Leading option tokens (`plan`, a model alias, `agent=name`, `continue`,
|
|
@@ -156,7 +211,9 @@ exploration/review. Sandbox runs do not bypass agy permission checks.
|
|
|
156
211
|
`/agy doctor` performs no inference and spends no model tokens. It reports the
|
|
157
212
|
installed CLI version, discoverable stable model aliases, optional custom-agent
|
|
158
213
|
discovery, quota support, active config, recorded sessions, workspace lock state,
|
|
159
|
-
|
|
214
|
+
provider runtime state (driver turns/reuses/recycles, bridge tool count,
|
|
215
|
+
suspended turns awaiting Pi tools, live image staging), and detected
|
|
216
|
+
verification gate.
|
|
160
217
|
|
|
161
218
|
Missing pieces open interactive dialogs (mode select, model select with
|
|
162
219
|
descriptions, multi-line task editor). `accept-edits` asks for confirmation
|
package/extensions/commands.ts
CHANGED
|
@@ -21,20 +21,10 @@ import {
|
|
|
21
21
|
} from "./lib/render.js";
|
|
22
22
|
import { getHistory, getSession } from "./lib/sessions.js";
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"flash-high": "flash-high",
|
|
29
|
-
pro: "pro-high",
|
|
30
|
-
"pro-low": "pro-low",
|
|
31
|
-
"pro-high": "pro-high",
|
|
32
|
-
sonnet: "sonnet",
|
|
33
|
-
opus: "opus",
|
|
34
|
-
"gpt-oss": "gpt-oss",
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const MODEL_KEYS = Object.keys(MODEL_ALIASES);
|
|
24
|
+
import { DEFAULT_TIMEOUT_MS, MODEL_ALIASES, MODEL_KEYS, MODE_KEYS, parseAgyCommandArgs } from "./lib/command-args.js";
|
|
25
|
+
import { buildAcceptEditsConfirm } from "./lib/confirm.js";
|
|
26
|
+
import { loadAgyConfig, saveAgyConfig } from "./lib/config.js";
|
|
27
|
+
import { describeProviderBridges, resetProviderBridges } from "./lib/provider.js";
|
|
38
28
|
|
|
39
29
|
const MODEL_OPTIONS = [
|
|
40
30
|
"flash — fast, cheap (Gemini Flash medium)",
|
|
@@ -54,81 +44,7 @@ const MODE_OPTIONS = [
|
|
|
54
44
|
"sandbox — isolated preview",
|
|
55
45
|
];
|
|
56
46
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const DEFAULT_TIMEOUT_MS = 300_000;
|
|
60
|
-
const MAX_TIMEOUT_MS = 600_000;
|
|
61
|
-
|
|
62
|
-
export interface AgyCommandArgs {
|
|
63
|
-
mode?: "plan" | "accept-edits" | "sandbox";
|
|
64
|
-
model?: AgyModel;
|
|
65
|
-
agent?: string;
|
|
66
|
-
prompt?: string;
|
|
67
|
-
continue?: boolean;
|
|
68
|
-
timeout_ms?: number;
|
|
69
|
-
context?: AgyContextMode;
|
|
70
|
-
error?: string;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Parse `/agy [mode] [model] [agent=name] [continue] [timeout=10m] <prompt>` — leading
|
|
75
|
-
* option tokens are consumed in any order; the remainder is the prompt.
|
|
76
|
-
*/
|
|
77
|
-
export function parseAgyCommandArgs(args: string): AgyCommandArgs {
|
|
78
|
-
let rest = args.trim();
|
|
79
|
-
const parsed: AgyCommandArgs = {};
|
|
80
|
-
|
|
81
|
-
while (rest) {
|
|
82
|
-
const token = readToken(rest);
|
|
83
|
-
if (!token) break;
|
|
84
|
-
const value = token.value.toLowerCase();
|
|
85
|
-
|
|
86
|
-
const timeout = parseTimeoutToken(token.value);
|
|
87
|
-
if (MODE_KEYS.includes(value as (typeof MODE_KEYS)[number])) {
|
|
88
|
-
parsed.mode = value as AgyCommandArgs["mode"];
|
|
89
|
-
} else if (MODEL_ALIASES[value]) {
|
|
90
|
-
parsed.model = MODEL_ALIASES[value];
|
|
91
|
-
} else if (value === "continue") {
|
|
92
|
-
parsed.continue = true;
|
|
93
|
-
} else if (value.startsWith("agent=")) {
|
|
94
|
-
try {
|
|
95
|
-
parsed.agent = normalizeAgyAgentName(token.value.slice("agent=".length));
|
|
96
|
-
} catch (error) {
|
|
97
|
-
parsed.error = error instanceof Error ? error.message : String(error);
|
|
98
|
-
}
|
|
99
|
-
} else if (value.startsWith("context=")) {
|
|
100
|
-
const context = value.slice("context=".length);
|
|
101
|
-
if (context === "none" || context === "summary" || context === "recent") {
|
|
102
|
-
parsed.context = context;
|
|
103
|
-
} else {
|
|
104
|
-
parsed.error = `unknown context mode '${context || "(empty)"}'`;
|
|
105
|
-
}
|
|
106
|
-
} else if (timeout !== undefined) {
|
|
107
|
-
parsed.timeout_ms = timeout;
|
|
108
|
-
} else {
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
rest = rest.slice(token.end).trimStart();
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (rest) parsed.prompt = rest;
|
|
115
|
-
return parsed;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/** `timeout=10m`, `timeout=90s`, `timeout=1500ms`; a bare number means minutes. */
|
|
119
|
-
function parseTimeoutToken(token: string): number | undefined {
|
|
120
|
-
const match = /^timeout=(\d+(?:\.\d+)?)(ms|s|m)?$/i.exec(token);
|
|
121
|
-
if (!match) return undefined;
|
|
122
|
-
const amount = Number.parseFloat(match[1]);
|
|
123
|
-
const unit = (match[2] ?? "m").toLowerCase();
|
|
124
|
-
const ms = unit === "ms" ? amount : unit === "s" ? amount * 1_000 : amount * 60_000;
|
|
125
|
-
return Math.min(Math.max(Math.round(ms), 1_000), MAX_TIMEOUT_MS);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function readToken(value: string): { value: string; end: number } | undefined {
|
|
129
|
-
const match = /^\S+/.exec(value);
|
|
130
|
-
return match ? { value: match[0], end: match[0].length } : undefined;
|
|
131
|
-
}
|
|
47
|
+
export { parseAgyCommandArgs, type AgyCommandArgs } from "./lib/command-args.js";
|
|
132
48
|
|
|
133
49
|
interface InteractiveRun {
|
|
134
50
|
mode: "plan" | "accept-edits" | "sandbox";
|
|
@@ -196,6 +112,7 @@ export function registerAgyCommand(pi: ExtensionAPI): void {
|
|
|
196
112
|
"doctor",
|
|
197
113
|
"usage",
|
|
198
114
|
"quota",
|
|
115
|
+
"bridge",
|
|
199
116
|
"context=summary",
|
|
200
117
|
"context=recent",
|
|
201
118
|
"timeout=10m",
|
|
@@ -247,6 +164,11 @@ export function registerAgyCommand(pi: ExtensionAPI): void {
|
|
|
247
164
|
await showUsage(ctx, requestedModel);
|
|
248
165
|
return;
|
|
249
166
|
}
|
|
167
|
+
const bridgeMatch = /^bridge(?:\s+(\S+))?$/.exec(command);
|
|
168
|
+
if (bridgeMatch) {
|
|
169
|
+
await showBridge(ctx, bridgeMatch[1]);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
250
172
|
|
|
251
173
|
const parsed = parseAgyCommandArgs(args);
|
|
252
174
|
if (parsed.error) {
|
|
@@ -366,6 +288,51 @@ async function showUsage(
|
|
|
366
288
|
}
|
|
367
289
|
}
|
|
368
290
|
|
|
291
|
+
/** `/agy bridge [on|off|status]` — inspect or toggle the provider MCP bridge. */
|
|
292
|
+
async function showBridge(ctx: ExtensionCommandContext, arg?: string): Promise<void> {
|
|
293
|
+
const sub = (arg ?? "status").toLowerCase();
|
|
294
|
+
if (sub !== "on" && sub !== "off" && sub !== "status") {
|
|
295
|
+
ctx.ui.notify("agy: bridge takes on, off, or no argument (status)", "error");
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
try {
|
|
299
|
+
await ctx.waitForIdle();
|
|
300
|
+
if (sub === "on" || sub === "off") {
|
|
301
|
+
ctx.ui.setStatus("agy", `agy: turning the provider bridge ${sub}…`);
|
|
302
|
+
await saveAgyConfig({ providerBridge: sub === "on" });
|
|
303
|
+
// Drop memoized servers so the next provider turn re-resolves;
|
|
304
|
+
// drivers recycle on the bridge-dir change by themselves.
|
|
305
|
+
await resetProviderBridges();
|
|
306
|
+
ctx.ui.notify(
|
|
307
|
+
sub === "on"
|
|
308
|
+
? "Provider bridge on: agy turns get Pi tools via localhost MCP (takes effect on the next turn)."
|
|
309
|
+
: "Provider bridge off: agy turns run plain (takes effect on the next turn).",
|
|
310
|
+
"info",
|
|
311
|
+
);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const config = await loadAgyConfig().catch(() => ({ providerBridge: true as const }));
|
|
315
|
+
const enabled = config.providerBridge !== false;
|
|
316
|
+
const bridges = describeProviderBridges();
|
|
317
|
+
const running = bridges.filter((bridge) => bridge.running);
|
|
318
|
+
const lines = [
|
|
319
|
+
`Provider bridge: ${enabled ? "on" : "off"} (agy-config.json${enabled ? "" : " — set providerBridge or run /agy bridge on"})`,
|
|
320
|
+
running.length > 0
|
|
321
|
+
? `running servers (${running.length}):\n${running.map((bridge) => `- ${bridge.dir} · ${bridge.toolCount ?? 0} tools`).join("\n")}`
|
|
322
|
+
: "no bridge servers running (one starts on the next provider turn)",
|
|
323
|
+
];
|
|
324
|
+
ctx.ui.notify(lines.join("\n"), "info");
|
|
325
|
+
} catch (error) {
|
|
326
|
+
if (ctx.signal?.aborted) ctx.ui.notify("agy: bridge check cancelled", "info");
|
|
327
|
+
else {
|
|
328
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
329
|
+
ctx.ui.notify(`agy bridge failed: ${message}`, "error");
|
|
330
|
+
}
|
|
331
|
+
} finally {
|
|
332
|
+
ctx.ui.setStatus("agy", undefined);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
369
336
|
/** `/agy sessions` — pick a recorded conversation and resume it with a follow-up. */
|
|
370
337
|
async function runSessionsPicker(
|
|
371
338
|
pi: ExtensionAPI,
|
|
@@ -432,22 +399,16 @@ async function executeConfirmedRun(
|
|
|
432
399
|
|
|
433
400
|
if (run.mode === "accept-edits") {
|
|
434
401
|
const dirt = await describePreRunDirt(cwd, ctx.signal).catch(() => null);
|
|
435
|
-
const
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
? `\n\nWarning: uncommitted changes already exist — the result summary only attributes newly-dirty files to agy.`
|
|
446
|
-
: "";
|
|
447
|
-
const ok = await ctx.ui.confirm(
|
|
448
|
-
"Run agy (accept-edits)?",
|
|
449
|
-
`model: ${run.model} (${resolveAgyModelId(run.model)})${agentLine}\ndir: ${cwd}${dirtLine}${contextLine}\n\ntask: ${run.prompt.slice(0, 200)}${run.prompt.length > 200 ? "…" : ""}\n\nThis grants agy permission to modify files and run commands.${warning}`,
|
|
450
|
-
);
|
|
402
|
+
const { title, body } = buildAcceptEditsConfirm({
|
|
403
|
+
modelLabel: `${run.model} (${resolveAgyModelId(run.model)})`,
|
|
404
|
+
agent: run.agent,
|
|
405
|
+
cwd,
|
|
406
|
+
prompt: run.prompt,
|
|
407
|
+
contextMode,
|
|
408
|
+
contextText,
|
|
409
|
+
dirt,
|
|
410
|
+
});
|
|
411
|
+
const ok = await ctx.ui.confirm(title, body);
|
|
451
412
|
if (!ok) {
|
|
452
413
|
ctx.ui.notify("agy: cancelled", "info");
|
|
453
414
|
return;
|
package/extensions/index.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import {
|
|
3
|
+
createAssistantMessageEventStream,
|
|
4
|
+
getCurrentSystemPrompt,
|
|
5
|
+
getCurrentTools,
|
|
6
|
+
type AssistantMessageEvent,
|
|
7
|
+
type AssistantMessageEventStream,
|
|
8
|
+
type Model,
|
|
9
|
+
type SimpleStreamOptions,
|
|
10
|
+
type TranscriptContext,
|
|
11
|
+
} from "@earendil-works/pi-ai";
|
|
2
12
|
import { Type } from "@sinclair/typebox";
|
|
3
13
|
import { stat } from "node:fs/promises";
|
|
4
14
|
import * as path from "node:path";
|
|
@@ -17,26 +27,165 @@ import {
|
|
|
17
27
|
import { buildAgyContextFromEntries, type AgyContextMode } from "./lib/context.js";
|
|
18
28
|
import { describePreRunDirt } from "./lib/postflight.js";
|
|
19
29
|
import { registerAgyCommand } from "./commands.js";
|
|
30
|
+
import { buildAcceptEditsConfirm } from "./lib/confirm.js";
|
|
31
|
+
import { DEFAULT_TIMEOUT_MS, MAX_TIMEOUT_MS } from "./lib/command-args.js";
|
|
20
32
|
import {
|
|
21
33
|
executeAgyTask,
|
|
22
34
|
validateAgyExecutionOptions,
|
|
23
35
|
type AgyMode,
|
|
24
36
|
} from "./lib/execute.js";
|
|
25
37
|
import { describeWhen, truncate } from "./lib/output.js";
|
|
38
|
+
import {
|
|
39
|
+
AGY_PROVIDER_API,
|
|
40
|
+
AGY_PROVIDER_ID,
|
|
41
|
+
closeProviderDrivers,
|
|
42
|
+
createAgyStreamSimple,
|
|
43
|
+
type ProviderToolSource,
|
|
44
|
+
type ProviderTranscriptMessage,
|
|
45
|
+
} from "./lib/provider.js";
|
|
46
|
+
import {
|
|
47
|
+
areProviderCatalogsEqual,
|
|
48
|
+
FALLBACK_PROVIDER_MODELS,
|
|
49
|
+
parseProviderCatalog,
|
|
50
|
+
toProviderModelDef,
|
|
51
|
+
type AgyProviderModelEntry,
|
|
52
|
+
} from "./lib/provider-models.js";
|
|
26
53
|
import { renderAgyCall, renderAgyResult } from "./lib/render.js";
|
|
27
54
|
import { getHistory, getSession } from "./lib/sessions.js";
|
|
28
|
-
|
|
29
|
-
const DEFAULT_TIMEOUT_MS = 300_000;
|
|
30
|
-
const MAX_TIMEOUT_MS = 600_000;
|
|
55
|
+
import { runPreflightCommand } from "./lib/spawn.js";
|
|
31
56
|
|
|
32
57
|
export { truncate } from "./lib/output.js";
|
|
33
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Resolve a tool `dir` override against the session cwd, validating it
|
|
61
|
+
* up front so a bad dir is not misreported downstream (e.g. as a missing
|
|
62
|
+
* Antigravity CLI installation).
|
|
63
|
+
*/
|
|
64
|
+
async function resolveToolDir(cwd: string, dir?: string): Promise<string> {
|
|
65
|
+
const resolved = dir ? path.resolve(cwd, dir) : cwd;
|
|
66
|
+
if (dir) {
|
|
67
|
+
try {
|
|
68
|
+
const info = await stat(resolved);
|
|
69
|
+
if (!info.isDirectory()) throw new Error(`Working directory is not a directory: ${resolved}`);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
|
|
72
|
+
throw new Error(`Working directory does not exist: ${resolved}`);
|
|
73
|
+
}
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return resolved;
|
|
78
|
+
}
|
|
79
|
+
|
|
34
80
|
export function resolveAgyMode(mode?: AgyMode): AgyMode {
|
|
35
81
|
return mode ?? "accept-edits";
|
|
36
82
|
}
|
|
37
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Register agy-backed models in Pi's global `/model` picker as
|
|
86
|
+
* `antigravity/*`.
|
|
87
|
+
*
|
|
88
|
+
* Registers synchronously with the fallback catalog so provider setup can
|
|
89
|
+
* never break extension load (or the delegation tools below); then refreshes
|
|
90
|
+
* from live `agy models` in the background and re-registers when the catalog
|
|
91
|
+
* changed — applied immediately, no `/reload` required. Refresh failures keep
|
|
92
|
+
* the fallback. Do not install `@estebanforge/pi-antigravity-bridge`
|
|
93
|
+
* alongside this package: both register the `antigravity` provider id and an
|
|
94
|
+
* `/agy` command.
|
|
95
|
+
*/
|
|
96
|
+
function registerAgyProvider(pi: ExtensionAPI): void {
|
|
97
|
+
if (typeof pi.registerProvider !== "function") return;
|
|
98
|
+
// Shared mutable catalog: the turn handler closes over this array, so a
|
|
99
|
+
// background refresh updates picker models without losing conversation
|
|
100
|
+
// continuity or re-creating the handler.
|
|
101
|
+
const entries: AgyProviderModelEntry[] = [...FALLBACK_PROVIDER_MODELS];
|
|
102
|
+
const streamSimple = createAgyStreamSimple(
|
|
103
|
+
{
|
|
104
|
+
createStream: () => {
|
|
105
|
+
const real = createAssistantMessageEventStream();
|
|
106
|
+
// Keep the real stream object (async iteration, result()) and only
|
|
107
|
+
// widen push: provider.ts emits protocol-shaped plain objects.
|
|
108
|
+
// Bind first: after assign, real.push is the override itself.
|
|
109
|
+
const push = real.push.bind(real);
|
|
110
|
+
return Object.assign(real, {
|
|
111
|
+
push: (event: Record<string, unknown>) =>
|
|
112
|
+
push(event as unknown as AssistantMessageEvent),
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
getSystemPrompt: (messages) =>
|
|
116
|
+
getCurrentSystemPrompt(messages as unknown as Parameters<typeof getCurrentSystemPrompt>[0]),
|
|
117
|
+
},
|
|
118
|
+
{ entries },
|
|
119
|
+
);
|
|
120
|
+
const register = (): void => {
|
|
121
|
+
pi.registerProvider(AGY_PROVIDER_ID, {
|
|
122
|
+
name: "Antigravity (agy)",
|
|
123
|
+
baseUrl: "agy-provider://antigravity",
|
|
124
|
+
apiKey: "not-used",
|
|
125
|
+
api: AGY_PROVIDER_API,
|
|
126
|
+
models: entries.map((entry) => ({
|
|
127
|
+
...toProviderModelDef(entry),
|
|
128
|
+
api: AGY_PROVIDER_API,
|
|
129
|
+
})),
|
|
130
|
+
streamSimple: (
|
|
131
|
+
model: Model<any>,
|
|
132
|
+
context: TranscriptContext,
|
|
133
|
+
options?: SimpleStreamOptions,
|
|
134
|
+
): AssistantMessageEventStream =>
|
|
135
|
+
streamSimple(
|
|
136
|
+
{ id: model.id },
|
|
137
|
+
context.messages as unknown as ProviderTranscriptMessage[],
|
|
138
|
+
options
|
|
139
|
+
? {
|
|
140
|
+
signal: options.signal,
|
|
141
|
+
reasoning: options.reasoning,
|
|
142
|
+
tools: getCurrentTools(context.messages) as unknown as ProviderToolSource[],
|
|
143
|
+
}
|
|
144
|
+
: undefined,
|
|
145
|
+
) as unknown as AssistantMessageEventStream,
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
try {
|
|
149
|
+
register();
|
|
150
|
+
} catch {
|
|
151
|
+
// Provider setup is additive; delegation tools must survive it.
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
void (async () => {
|
|
155
|
+
try {
|
|
156
|
+
const raw = await runPreflightCommand(
|
|
157
|
+
["models"],
|
|
158
|
+
process.cwd(),
|
|
159
|
+
undefined,
|
|
160
|
+
"agy provider model discovery",
|
|
161
|
+
true,
|
|
162
|
+
);
|
|
163
|
+
const live = parseProviderCatalog(raw);
|
|
164
|
+
if (live.length === 0) return;
|
|
165
|
+
if (areProviderCatalogsEqual(entries, live)) return;
|
|
166
|
+
entries.splice(0, entries.length, ...live);
|
|
167
|
+
register();
|
|
168
|
+
} catch {
|
|
169
|
+
// Refresh failures keep the fallback catalog.
|
|
170
|
+
}
|
|
171
|
+
})();
|
|
172
|
+
}
|
|
173
|
+
|
|
38
174
|
export default function piAgyExtension(pi: ExtensionAPI) {
|
|
39
175
|
registerAgyCommand(pi);
|
|
176
|
+
registerAgyProvider(pi);
|
|
177
|
+
// Persistent driver processes must not outlive the session.
|
|
178
|
+
try {
|
|
179
|
+
pi.on?.("session_shutdown", async () => {
|
|
180
|
+
try {
|
|
181
|
+
await closeProviderDrivers();
|
|
182
|
+
} catch {
|
|
183
|
+
// Shutdown disposal is best effort; turns still work without it.
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
} catch {
|
|
187
|
+
// Shutdown disposal is best effort; turns still work without it.
|
|
188
|
+
}
|
|
40
189
|
|
|
41
190
|
pi.registerTool({
|
|
42
191
|
name: "agy_execute",
|
|
@@ -211,24 +360,16 @@ export default function piAgyExtension(pi: ExtensionAPI) {
|
|
|
211
360
|
? `${requestedModel} (${resolveAgyModelId(model, params.tier)})`
|
|
212
361
|
: "configured default (fallback flash-medium)";
|
|
213
362
|
const dirt = await describePreRunDirt(cwd, abortSignal).catch(() => null);
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
contextMode
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
const warning =
|
|
225
|
-
dirt && dirt !== "clean"
|
|
226
|
-
? `\n\nWarning: uncommitted changes already exist — the result summary only attributes newly-dirty files to agy.`
|
|
227
|
-
: "";
|
|
228
|
-
const approved = await ctx.ui.confirm(
|
|
229
|
-
"Run agy (accept-edits)?",
|
|
230
|
-
`model: ${modelLabel}${agentLine}\ndir: ${cwd}${dirtLine}${contextLine}\n\ntask: ${excerpt}\n\nThis grants agy permission to modify files and run commands.${warning}`,
|
|
231
|
-
);
|
|
363
|
+
const { title, body } = buildAcceptEditsConfirm({
|
|
364
|
+
modelLabel,
|
|
365
|
+
agent,
|
|
366
|
+
cwd,
|
|
367
|
+
prompt: params.prompt,
|
|
368
|
+
contextMode,
|
|
369
|
+
contextText,
|
|
370
|
+
dirt,
|
|
371
|
+
});
|
|
372
|
+
const approved = await ctx.ui.confirm(title, body);
|
|
232
373
|
if (!approved) throw new Error("agy accept-edits cancelled by user");
|
|
233
374
|
}
|
|
234
375
|
|
|
@@ -270,18 +411,7 @@ export default function piAgyExtension(pi: ExtensionAPI) {
|
|
|
270
411
|
}),
|
|
271
412
|
|
|
272
413
|
async execute(_toolCallId, params, signal, _onUpdate, ctx) {
|
|
273
|
-
const cwd =
|
|
274
|
-
if (params.dir) {
|
|
275
|
-
try {
|
|
276
|
-
const info = await stat(cwd);
|
|
277
|
-
if (!info.isDirectory()) throw new Error(`Working directory is not a directory: ${cwd}`);
|
|
278
|
-
} catch (error) {
|
|
279
|
-
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
|
|
280
|
-
throw new Error(`Working directory does not exist: ${cwd}`);
|
|
281
|
-
}
|
|
282
|
-
throw error;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
414
|
+
const cwd = await resolveToolDir(ctx.cwd, params.dir);
|
|
285
415
|
const agents = await inspectAgyAgents(cwd, signal);
|
|
286
416
|
const text = agents.length
|
|
287
417
|
? `configured agy agents:\n${agents.map((agent) => `- ${agent}`).join("\n")}`
|
|
@@ -374,20 +504,7 @@ export default function piAgyExtension(pi: ExtensionAPI) {
|
|
|
374
504
|
}),
|
|
375
505
|
|
|
376
506
|
async execute(_toolCallId, params, signal, _onUpdate, ctx) {
|
|
377
|
-
const cwd =
|
|
378
|
-
if (params.dir) {
|
|
379
|
-
// Validate the override before spawning so a bad dir is not
|
|
380
|
-
// misreported as a missing Antigravity CLI installation.
|
|
381
|
-
try {
|
|
382
|
-
const info = await stat(cwd);
|
|
383
|
-
if (!info.isDirectory()) throw new Error(`Working directory is not a directory: ${cwd}`);
|
|
384
|
-
} catch (error) {
|
|
385
|
-
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
|
|
386
|
-
throw new Error(`Working directory does not exist: ${cwd}`);
|
|
387
|
-
}
|
|
388
|
-
throw error;
|
|
389
|
-
}
|
|
390
|
-
}
|
|
507
|
+
const cwd = await resolveToolDir(ctx.cwd, params.dir);
|
|
391
508
|
const quota = await checkAgyUsage(cwd, signal);
|
|
392
509
|
const selectedModel = params.model ? resolveAgyModelId(params.model) : undefined;
|
|
393
510
|
const selectedEntries = selectedModel ? findAgyQuotaEntries(quota, selectedModel) : [];
|