@juanbenjumea/pi-agy 0.7.11 → 0.7.12

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.12
4
+
5
+ - Refresh the full Antigravity model catalog automatically at session startup and whenever Pi opens `/model`, using Pi's native refresh lifecycle instead of a one-time discovery probe.
6
+ - Discover nonhyphen IDs such as `argon` and new model generations without hardcoded catalog updates; preserve exact CLI names and existing Gemini effort grouping.
7
+ - Retain the last good catalog on discovery failures and retry on the next picker opening; reject canceled, superseded, and shutdown refresh results.
8
+ - Add real Pi runtime and model-picker integration regressions. Full 465-test gate, typecheck, and package checks pass; live discovery still requires an authenticated agy CLI.
9
+
3
10
  ## 0.7.11
4
11
 
5
12
  - Preserve exclusive provider-turn ownership across tool suspension, resumption, and terminal delivery; reject competing turns before they alter bridge tools.
package/README.md CHANGED
@@ -37,7 +37,7 @@ In `accept-edits` mode, Pi confirms before writes. agy's own permission behavior
37
37
 
38
38
  ## Use agy as a Pi model
39
39
 
40
- The package registers an `antigravity` provider. Select discovered models as `antigravity/<model>` in Pi's `/model` picker. Models are discovered from `agy models`, with a fallback catalog if discovery fails. Gemini thinking levels map to agy's supported effort tiers.
40
+ The package registers an `antigravity` provider. Select discovered models as `antigravity/<model>` in Pi's `/model` picker. Models refresh automatically from `agy models` at session startup and whenever Pi opens the model picker (Pi 1.5.2 native refresh). New model names need no package update. Failed discovery keeps the last good catalog, or the synchronous fallback before the first success; reopen `/model` after signing in to retry. Cache-only refreshes never run the CLI. Gemini thinking levels map to agy's supported effort tiers.
41
41
 
42
42
  Provider turns use a persistent agy process per working directory and can stage attached images for agy to read. By default, an MCP bridge gives agy read-only Pi context and lets it call active Pi tools through Pi's normal permission and approval flow. Set `"providerBridge": false` in `agy-config.json` to disable the bridge.
43
43
 
@@ -6,8 +6,8 @@ import {
6
6
  type AssistantMessageEvent,
7
7
  type AssistantMessageEventStream,
8
8
  type Model,
9
+ type Provider,
9
10
  type SimpleStreamOptions,
10
- type TranscriptContext,
11
11
  } from "@earendil-works/pi-ai";
12
12
  import { registerAgyCommand } from "./commands.js";
13
13
  import { closeProviderDrivers } from "./lib/provider.js";
@@ -36,20 +36,19 @@ export { truncate } from "./lib/output.js";
36
36
  * Register agy-backed models in Pi's global `/model` picker as
37
37
  * `antigravity/*`.
38
38
  *
39
- * Registers synchronously with the fallback catalog so provider setup can
40
- * never break extension load (or the delegation tools below); then refreshes
41
- * from live `agy models` in the background and re-registers when the catalog
42
- * changed — applied immediately, no `/reload` required. Refresh failures keep
43
- * the fallback. Do not install `@estebanforge/pi-antigravity-bridge`
44
- * alongside this package: both register the `antigravity` provider id and an
45
- * `/agy` command.
39
+ * Registers a synchronous fallback and lets Pi refresh the catalog whenever
40
+ * its model picker opens. Both picker definitions and turn resolution are
41
+ * published atomically through Pi's generation-checked native refresh API.
42
+ * Do not install `@estebanforge/pi-antigravity-bridge` alongside this package:
43
+ * both register the `antigravity` provider id and an `/agy` command.
46
44
  */
47
45
  function registerAgyProvider(pi: ExtensionAPI): void {
48
46
  if (typeof pi.registerProvider !== "function") return;
49
- // Shared mutable catalog: the turn handler closes over this array, so a
50
- // background refresh updates picker models without losing conversation
51
- // continuity or re-creating the handler.
47
+ // Keep one handler and catalog array for conversation/driver continuity.
48
+ // Only a generation-checked publication may mutate these entries.
52
49
  const entries: AgyProviderModelEntry[] = [...FALLBACK_PROVIDER_MODELS];
50
+ const shutdown = new AbortController();
51
+ pi.on?.("session_shutdown", () => { shutdown.abort(); });
53
52
  const streamSimple = createAgyStreamSimple(
54
53
  {
55
54
  createStream: () => {
@@ -68,56 +67,76 @@ function registerAgyProvider(pi: ExtensionAPI): void {
68
67
  },
69
68
  { entries },
70
69
  );
71
- const register = (): void => {
72
- pi.registerProvider(AGY_PROVIDER_ID, {
73
- name: "Antigravity (agy)",
74
- baseUrl: "agy-provider://antigravity",
75
- apiKey: "not-used",
70
+ const baseUrl = "agy-provider://antigravity";
71
+ const modelDefinitions = (catalog: readonly AgyProviderModelEntry[]): Model<any>[] =>
72
+ catalog.map((entry) => ({
73
+ ...toProviderModelDef(entry),
76
74
  api: AGY_PROVIDER_API,
77
- models: entries.map((entry) => ({
78
- ...toProviderModelDef(entry),
79
- api: AGY_PROVIDER_API,
80
- })),
81
- streamSimple: (
82
- model: Model<any>,
83
- context: TranscriptContext,
84
- options?: SimpleStreamOptions,
85
- ): AssistantMessageEventStream =>
86
- streamSimple(
87
- { id: model.id },
88
- context.messages as unknown as ProviderTranscriptMessage[],
89
- {
90
- signal: options?.signal,
91
- reasoning: options?.reasoning,
92
- tools: getCurrentTools(context.messages) as unknown as ProviderToolSource[],
93
- },
94
- ) as unknown as AssistantMessageEventStream,
95
- });
75
+ provider: AGY_PROVIDER_ID,
76
+ baseUrl,
77
+ }));
78
+ let models = modelDefinitions(entries);
79
+ const stream: Provider["streamSimple"] = (model, context, options) =>
80
+ streamSimple(
81
+ { id: model.id },
82
+ context.messages as unknown as ProviderTranscriptMessage[],
83
+ {
84
+ signal: options?.signal,
85
+ reasoning: options?.reasoning,
86
+ tools: getCurrentTools(context.messages) as unknown as ProviderToolSource[],
87
+ },
88
+ ) as unknown as AssistantMessageEventStream;
89
+ const provider: Provider = {
90
+ id: AGY_PROVIDER_ID,
91
+ name: "Antigravity (agy)",
92
+ baseUrl,
93
+ // agy owns authentication. Pi must regard this ambient CLI provider as
94
+ // configured so refresh can recover after the user signs in to agy.
95
+ auth: { apiKey: { name: "Antigravity CLI", resolve: async () => ({ auth: { apiKey: "not-used" } }) } },
96
+ getModels: () => models,
97
+ async refreshModels(context) {
98
+ const signal = AbortSignal.any([context.signal, shutdown.signal]);
99
+ signal.throwIfAborted();
100
+ // Native refresh first calls a cache-only phase, even for network
101
+ // refreshes. Never launch agy (which can contact its server) there.
102
+ if (!context.allowNetwork) return;
103
+ const raw = await runPreflightCommand(
104
+ ["models"], process.cwd(), signal, "agy provider model discovery", true,
105
+ );
106
+ signal.throwIfAborted();
107
+ const live = parseProviderCatalog(raw);
108
+ if (live.length === 0) throw new Error("agy models returned no usable models");
109
+ if (areProviderCatalogsEqual(entries, live)) return;
110
+ const definitions = modelDefinitions(live);
111
+ await context.publish({
112
+ update: () => {
113
+ // Pi checks its generation/signal immediately before this callback;
114
+ // session shutdown also invalidates a still-live runtime's refresh.
115
+ signal.throwIfAborted();
116
+ entries.splice(0, entries.length, ...live);
117
+ models = definitions;
118
+ },
119
+ });
120
+ },
121
+ stream: (model, context, options) => stream(model, context, options as SimpleStreamOptions),
122
+ streamSimple: stream,
96
123
  };
97
124
  try {
98
- register();
125
+ pi.registerProvider(provider);
99
126
  } catch {
100
127
  // Provider setup is additive; delegation tools must survive it.
128
+ shutdown.abort();
101
129
  return;
102
130
  }
103
- void (async () => {
104
- try {
105
- const raw = await runPreflightCommand(
106
- ["models"],
107
- process.cwd(),
108
- undefined,
109
- "agy provider model discovery",
110
- true,
111
- );
112
- const live = parseProviderCatalog(raw);
113
- if (live.length === 0) return;
114
- if (areProviderCatalogsEqual(entries, live)) return;
115
- entries.splice(0, entries.length, ...live);
116
- register();
117
- } catch {
118
- // Refresh failures keep the fallback catalog.
131
+ pi.on?.("session_start", async (_event, ctx) => {
132
+ const signal = AbortSignal.any([shutdown.signal, AbortSignal.timeout(10_000)]);
133
+ const result = await ctx.modelRegistry.refresh({
134
+ providers: [AGY_PROVIDER_ID], allowNetwork: true, signal,
135
+ });
136
+ if (!signal.aborted && result.errors.has(AGY_PROVIDER_ID)) {
137
+ ctx.ui.notify("Could not refresh Antigravity models; showing cached models. Reopen /model to retry.", "warning");
119
138
  }
120
- })();
139
+ });
121
140
  }
122
141
 
123
142
  export default function piAgyExtension(pi: ExtensionAPI) {
@@ -36,12 +36,19 @@ const EFFORT_ORDER: readonly AgyProviderEffort[] = ["low", "medium", "high"];
36
36
  const TIER_RE = /^(.+)-(high|medium|low)$/;
37
37
 
38
38
  /**
39
- * Validate the first column of an `agy models` line so banners, auth
40
- * prompts, or progress chatter ("Fetching models…") can never register as a
41
- * model, and a leading-dash token cannot reach agy's flag parser as `--model`.
39
+ * Preserve the established hyphenated first-column format. A leading-dash
40
+ * token must never reach agy's flag parser as `--model`.
42
41
  */
43
42
  const MODEL_LINE_RE = /^[A-Za-z0-9][A-Za-z0-9._]*-[A-Za-z0-9._-]*$/;
44
43
 
44
+ // Nonhyphen ids also occur (e.g. `argon`). Be conservative about ambiguous
45
+ // human text: require lowercase slug syntax with no trailing dot. Common
46
+ // header and diagnostic first tokens are not models. Other lowercase words
47
+ // (bare or followed by whitespace) are inherently indistinguishable from ids
48
+ // in this unstructured CLI format.
49
+ const NONHYPHEN_MODEL_ID_RE = /^[a-z0-9](?:[a-z0-9._]*[a-z0-9_])?$/;
50
+ const NON_MODEL_TOKEN_RE = /^(?:id|model|models|name|label|status|available|fetching|loading|error|warning|info|auth|authentication|unauthorized|forbidden|login|success)$/;
51
+
45
52
  /**
46
53
  * Families verified to accept base-slug + `--effort`. Only these collapse to
47
54
  * a base entry with a thinking toggle; every other family keeps agy's exact
@@ -141,7 +148,10 @@ export function parseProviderCatalog(raw: string): AgyProviderModelEntry[] {
141
148
  const groups = new Map<string, { lines: string[]; tiers: Set<AgyProviderEffort> }>();
142
149
  for (const line of raw.split("\n")) {
143
150
  const slug = line.trim().split(/\s+/)[0] ?? "";
144
- if (!slug || !MODEL_LINE_RE.test(slug)) continue;
151
+ if (
152
+ !MODEL_LINE_RE.test(slug) &&
153
+ (!NONHYPHEN_MODEL_ID_RE.test(slug) || NON_MODEL_TOKEN_RE.test(slug))
154
+ ) continue;
145
155
  const match = TIER_RE.exec(slug);
146
156
  const base = match ? match[1] : slug;
147
157
  const tier = match ? (match[2] as AgyProviderEffort) : null;
@@ -461,7 +461,7 @@ export function resolveProviderTurnModel(
461
461
  const entry = entries.find((candidate) => candidate.id === modelId);
462
462
  if (!entry) {
463
463
  throw new Error(
464
- `Unknown ${AGY_PROVIDER_ID} model '${modelId}'; pick another via /model (the agy catalog may have changed — restart Pi to refresh).`,
464
+ `Unknown ${AGY_PROVIDER_ID} model '${modelId}'; pick another via /model (the agy catalog may have changed — reopen /model to refresh).`,
465
465
  );
466
466
  }
467
467
  const effort =
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juanbenjumea/pi-agy",
3
- "version": "0.7.11",
3
+ "version": "0.7.12",
4
4
  "description": "Antigravity (agy) provider and delegation for Pi — /model picker, background tasks, loopback MCP tool bridge, quota awareness, and repo verification.",
5
5
  "type": "module",
6
6
  "license": "MIT",