pi-agy-acp 0.1.4 → 0.2.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 CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.2.1](https://github.com/fdkevin0/pi-agy-acp/compare/v0.2.0...v0.2.1) (2026-11-22)
4
+
5
+
6
+ ### Features
7
+
8
+ * sync agy 1.5.10+ features, dynamic catalog, and process hardening ([#34](https://github.com/fdkevin0/pi-agy-acp/issues/34)) ([44d2d36](https://github.com/fdkevin0/pi-agy-acp/commit/44d2d3690f927adacda8c37ae281714992736844)), closes [#28](https://github.com/fdkevin0/pi-agy-acp/issues/28) [#31](https://github.com/fdkevin0/pi-agy-acp/issues/31) [#32](https://github.com/fdkevin0/pi-agy-acp/issues/32)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * encapsulate turn prompt liveness and relay lifecycle ([#33](https://github.com/fdkevin0/pi-agy-acp/issues/33)) ([#36](https://github.com/fdkevin0/pi-agy-acp/issues/36)) ([f661d8d](https://github.com/fdkevin0/pi-agy-acp/commit/f661d8d49564a83aada3617936e564f9b352eb44))
14
+
15
+
16
+ ### Miscellaneous Chores
17
+
18
+ * **release:** prepare 0.2.1 ([#37](https://github.com/fdkevin0/pi-agy-acp/issues/37)) ([5ca8a16](https://github.com/fdkevin0/pi-agy-acp/commit/5ca8a164e0b40e4040401ff7455cb34c54d0b9c9))
19
+
20
+ ## [0.2.0](https://github.com/fdkevin0/pi-agy-acp/compare/v0.1.4...v0.2.0) (2026-11-17)
21
+
22
+
23
+ ### Features
24
+
25
+ * discover model context windows dynamically from session metadata ([#29](https://github.com/fdkevin0/pi-agy-acp/issues/29)) ([c29277f](https://github.com/fdkevin0/pi-agy-acp/commit/c29277ff3e8c64b9549444b14177bcfd283ef50a))
26
+
3
27
  ## [0.1.4](https://github.com/fdkevin0/pi-agy-acp/compare/v0.1.3...v0.1.4) (2026-11-15)
4
28
 
5
29
 
package/README.md CHANGED
@@ -12,7 +12,7 @@ parallel tool calls.
12
12
 
13
13
  - Node.js >= 22.19.0.
14
14
  - Pi (`@earendil-works/pi-coding-agent`) 1.5.x.
15
- - The official `agy` CLI >= 1.4.12, signed in with your Google account.
15
+ - The official `agy` CLI >= 1.5.10, signed in with your Google account.
16
16
  Run `agy` in your terminal to complete sign-in before using the extension.
17
17
 
18
18
  ## Install
@@ -39,10 +39,9 @@ installation. See [development setup](docs/development.md) for local testing.
39
39
 
40
40
  ## Usage
41
41
 
42
- Start `pi`, then use `/model` to select a model under `antigravity-acp`.
43
- Examples include `gemini-4-argon`, `gemini-3.8-flash`, `claude-opus-5-5`,
44
- `claude-sonnet-5-5`, and `gpt-oss-120b-medium`. The available list refreshes
45
- automatically from your account.
42
+ Start `pi`, then use `/model` to refresh and select a model under `antigravity-acp`.
43
+ The available models and reasoning levels are discovered dynamically from your
44
+ Antigravity account and cached locally in `catalog.json`.
46
45
 
47
46
  | Command | Purpose |
48
47
  | --- | --- |
@@ -24,18 +24,38 @@ pi -e ./index.ts
24
24
  3. Model tool calls reach the bridge and remain pending while Pi executes them.
25
25
  Pi receives a `toolUse` result, then supplies tool results on its next request.
26
26
  4. Those results resolve the pending MCP requests, allowing the same ACP turn to
27
- continue. Long-running tools use a relay to keep the agent waiting.
27
+ continue (or, if the ACP prompt already settled while Pi was running tools,
28
+ starting a fresh continuation prompt with those results and any deferred
29
+ suffixes without executing zombie queued calls). Long-running tools use a
30
+ relay (`pi_await_result`) to keep the agent waiting; if the agent instead
31
+ moves on to a new tool call or another awaited result, buffered output
32
+ flushes in order so later steps stream live, deferred tool/steering suffixes
33
+ and a one-time `<harness_relay_update>` hint carry onto the next delivered
34
+ tool result, and `end_turn`/`max_tokens` finishes with a note if any relayed
35
+ call remained unretrieved (while immediate premature completion with no
36
+ further tool progress still fails with `PROVIDER_ERROR`).
28
37
  5. The adapter drains the runtime's generator before publishing completion, so
29
38
  session cleanup finishes before Pi can start its next step.
30
39
 
31
40
  - **Model discovery:** Registration and cache-only refresh start no processes,
32
- sockets, or timers. Concurrent refreshes share a discovery session; after a live
41
+ sockets, or timers; before the first ACP discovery (`catalog.json` absent),
42
+ the catalog starts empty with no hardcoded model list. `catalog.json` is
43
+ written atomically and persists models, per-model efforts, `promptCapabilities.image`,
44
+ tier, `contextWindows`, and a subprocess-free `agy` binary fingerprint
45
+ (`realpath`, `dev`, `ino`, `size`, `mtimeNs`); a changed binary invalidates
46
+ cached `contextWindows` and `observed` so the next refresh or session re-probes.
47
+ The ACP `initialize` handshake also validates `agentInfo.version` against
48
+ `MIN_AGY_VERSION`. Concurrent refreshes share a discovery session; after a live
33
49
  catalog is observed, later refreshes reuse it unless forced. Refresh suppresses
34
50
  provider re-registration so it cannot cancel itself. Cancellation ends the
35
51
  caller's wait; shared discovery still closes its session and cleans its files.
36
52
  - **Session lifecycle:** The bridge binds to `127.0.0.1`, uses per-session bearer
37
53
  credentials, and validates structured tool identity before granting permissions.
38
- Live `agy 1.5.9` sessions issue `session/request_permission` only inside an
54
+ On Unix, `agy acp` and helper commands run in detached process groups so
55
+ termination and timeouts signal `-pid` (`SIGTERM`, then `SIGKILL`) without
56
+ orphaning `--process-per-session` workers. Session SQLite reads reject
57
+ symlinked or non-regular `.db`, `.db-wal`, and `.db-shm` files.
58
+ Live `agy 1.5.10+` sessions issue `session/request_permission` only inside an
39
59
  active `session/prompt` turn (never during `session/new` or
40
60
  `session/set_config_option`), so session creation and idle pre-/post-turn
41
61
  windows remain fail-closed (`cancelled` before `session/new` completes;
@@ -52,13 +72,16 @@ pi -e ./index.ts
52
72
  First interruption wins (`abandon` vs. `fail`), cancellation takes priority
53
73
  over buffered output, and turn/tenant identities guard all async callbacks.
54
74
  - **Quota and TUI:** Settled checks share the reader's TTL and in-flight request
55
- without blocking Pi. Model selection reads memory only. UI generation checks
56
- discard stale background results; warning keys include group, bucket, reset
57
- time, and threshold. An explicit quota query can discover uncached account tiers through
58
- one tool-less ACP session per runtime, persisting the tier in `catalog.json`.
59
- Email lookup reads at most the last 64 KiB of each candidate login log and uses
60
- the last match in the first matching file. Runtime warnings stay off stderr to
61
- preserve TUI rendering; diagnostics use status and agy's logs.
75
+ without blocking Pi. `/usage` commands close stdin, cap stdout at 1 MiB, and
76
+ abort early if stderr matches `Authentication required`. Model selection reads
77
+ memory only. UI generation checks discard stale background results; warning
78
+ keys include group, bucket, reset time, and threshold. An explicit quota query
79
+ can discover uncached account tiers through one tool-less ACP session per
80
+ runtime, persisting the tier in `catalog.json`. Email lookup scans `cli.log`
81
+ and the newest 10 contained `log/cli-*.log` and `log/acp-server-*.log` files
82
+ (newest first, deduplicated), checking the tail 64 KiB first and falling back
83
+ to the head 64 KiB when larger. Runtime warnings stay off stderr to preserve
84
+ TUI rendering; diagnostics use status and agy's logs.
62
85
  - **Pi stream and error contracts:** `onPayload` can replace the request, and
63
86
  `onProviderStreamEvent` observes events before conversion. At the first stream
64
87
  event, `onResponse` receives synthetic status `200` and empty headers before
package/docs/reference.md CHANGED
@@ -71,8 +71,11 @@ it. This may start ACP but sends no model prompt; failure does not prevent quota
71
71
  from appearing. Use `/agy-acp reset` to retry discovery. Viewing status never starts it.
72
72
 
73
73
  The email comes from login logs. With the default home only, the extension also
74
- checks `~/.gemini/antigravity-cli/cli.log` if needed; a custom `PI_AGY_HOME` stays
75
- isolated. Cached plans and login logs can be stale after an account change.
74
+ checks `ANTIGRAVITY_CLI_HOME`, `AGY_HOME`, and `~/.gemini/antigravity-cli`
75
+ (`cli.log` plus the newest 10 `log/cli-*.log` and `log/acp-server-*.log` files,
76
+ scanning each log's tail 64 KiB and falling back to its head 64 KiB when larger);
77
+ a custom `PI_AGY_HOME` stays isolated. Cached plans and login logs can be stale
78
+ after an account change.
76
79
 
77
80
  ### Quota status and warnings
78
81
 
@@ -125,35 +128,37 @@ for each concurrently running Pi instance, since startup cleanup assumes exclusi
125
128
  use of the directory.
126
129
 
127
130
  With file-backed authentication, the extension copies the existing OAuth token
128
- from your normal agy directory and sets its permissions to `0600`. Do not commit
131
+ from your normal agy directory (`ANTIGRAVITY_CLI_HOME`, `AGY_HOME`, or
132
+ `~/.gemini/antigravity-cli`) and sets its permissions to `0600`. Do not commit
129
133
  or share this directory. Authentication and token refresh remain agy's responsibility.
130
134
 
131
135
  ## Models and context
132
136
 
133
- Loading the extension uses the cached catalog, or five fallback model families,
134
- without starting agy. Model refresh or the first request updates available models
135
- and reasoning levels from ACP. A forced refresh queries again; refreshes can be
136
- cancelled. The selector exposes only the reasoning levels offered for each model.
137
- Direct requests map `minimal` to `low` and `xhigh` or `max` to `high`; `off` uses
138
- the runtime default.
139
-
140
- The fallback families are:
141
-
142
- - `gemini-4-argon`
143
- - `gemini-3.8-flash`
144
- - `claude-opus-5-5`
145
- - `claude-sonnet-5-5`
146
- - `gpt-oss-120b-medium`
147
-
148
- These entries are defaults, not a guarantee of account access. Context declarations
149
- are 256,000 tokens, or 131,072 for GPT-OSS. The history replay budget is 160,000 bytes;
150
- older history can be omitted to fit, and historical images become text placeholders.
137
+ Loading the extension restores the cached catalog from `catalog.json` (or starts
138
+ empty on a fresh install) without starting agy. Model refresh (such as opening
139
+ `/model`) or the first request discovers available models, reasoning levels
140
+ (including grouped select options and `-effort` suffix variants), and image input
141
+ capability (`promptCapabilities.image`) dynamically from ACP. A forced refresh
142
+ queries again; refreshes can be cancelled. The selector exposes only the
143
+ reasoning levels offered for each model (`low`, `medium`, `high`, `xhigh`, `max`).
144
+ Direct requests map `minimal` to `low` and forward `xhigh` and `max` (clamping to
145
+ the nearest effort offered by that model); `off` uses the runtime default.
146
+
147
+ Model context windows start at `0` until learned dynamically from the
148
+ server-issued `max_context_tokens` metadata in the session database and cached
149
+ per model in `catalog.json` alongside the `agy` binary fingerprint; updating the
150
+ `agy` binary invalidates cached context windows and triggers re-discovery on the
151
+ next refresh or session. The history replay budget is 160,000 bytes; older
152
+ history can be omitted to fit, and historical images become text placeholders.
151
153
 
152
154
  ## Usage and costs
153
155
 
154
156
  Usage comes from the ACP session rather than per-step API headers. Parked `toolUse`
155
157
  steps emit zero usage; statistics arrive on the final step when the full ACP turn
156
- finishes (accumulated across any automatic `max_tokens` continuations).
158
+ finishes (accumulated across any automatic `max_tokens` continuations). `max_context_tokens`
159
+ recorded in the session SQLite metadata supplies the model's context window, while
160
+ `usage_update` (and same-turn `estimated_tokens_used` metadata when `usage_update`
161
+ is absent) supplies live token occupancy.
157
162
 
158
163
  The extension separates cumulative token consumption from final-call context
159
164
  occupancy:
@@ -163,10 +168,11 @@ occupancy:
163
168
  overrides reflect full multi-step consumption.
164
169
  - `totalTokens` (which feeds Pi's context meter and auto-compaction threshold via
165
170
  `calculateContextTokens`) uses the final model call's live `usage_update.used`
166
- count when `agy` provides it. When `usage_update` is absent, it falls back to
167
- averaging the final `session/prompt` segment's prompt tokens across that
168
- segment's model calls plus final-segment output tokens; this fallback is an
169
- estimate rather than an exact per-step measurement.
171
+ count when `agy` provides it. When `usage_update` is absent, it prefers the
172
+ same turn's `estimated_tokens_used` from `gen_metadata`, and otherwise falls
173
+ back to averaging the final `session/prompt` segment's prompt tokens across
174
+ that segment's model calls plus final-segment output tokens; this fallback is
175
+ an estimate rather than an exact per-step measurement.
170
176
 
171
177
  Default model prices are zero because pricing is unavailable. If you configure
172
178
  Pi model pricing overrides, flat per-million rates price the cumulative turn
@@ -174,12 +180,14 @@ buckets accurately; tiered `inputTokensAbove` rules evaluate against cumulative
174
180
  turn prompt tokens rather than per-call prompt sizes. These estimates are not
175
181
  an invoice amount or a promise of free access.
176
182
 
177
- The extension does not inspect agy's private databases or invoke or distribute
178
- binary patch scripts.
183
+ The extension reads only session-scoped `max_context_tokens` metadata inside `PI_AGY_HOME`;
184
+ it never inspects your global `agy` databases or invokes or distributes binary patch
185
+ scripts.
179
186
 
180
187
  ## Compatibility limits
181
188
 
182
- This version targets the `@earendil-works/*` Pi packages at version 1.5.x.
189
+ This version requires `agy` CLI >= 1.5.10 and targets the `@earendil-works/*`
190
+ Pi packages at version 1.5.x.
183
191
  Host `peerDependencies` use `*` as required by Pi package conventions;
184
192
  `devDependencies` pin a reproducible CI baseline (`1.5.2`), and CI validates
185
193
  both that baseline (on Node.js 22.19.0 and 24) and the `1.5.x` host range
package/index.ts CHANGED
@@ -26,7 +26,7 @@ import type { QuotaSnapshot } from './src/quota.ts'
26
26
 
27
27
  export default function (
28
28
  pi: ExtensionAPI,
29
- host: Partial<Pick<RuntimeHost, 'runCommand'>> = {},
29
+ host: Partial<Pick<RuntimeHost, 'runCommand' | 'spawnAcp'>> = {},
30
30
  ) {
31
31
  const envQuotaDisplay = asQuotaDisplay(process.env.PI_AGY_QUOTA_DISPLAY)
32
32
  const config = {
@@ -38,7 +38,7 @@ export default function (
38
38
  const createRuntime = () =>
39
39
  new AntigravityRuntime({
40
40
  config,
41
- spawnAcp,
41
+ spawnAcp: host.spawnAcp ?? spawnAcp,
42
42
  runCommand: host.runCommand ?? runCommand,
43
43
  log: { info: () => {}, warn: () => {} },
44
44
  onModelsChanged: () => {
@@ -51,13 +51,14 @@ export default function (
51
51
  envQuotaDisplay ??
52
52
  readQuotaDisplayPreference(home) ??
53
53
  DEFAULT_QUOTA_DISPLAY
54
- const models = (): ProviderModelConfig[] =>
55
- runtime.catalog.list().map((m) => {
54
+ const models = (): ProviderModelConfig[] => {
55
+ const input = runtime.catalog.inputModalities()
56
+ return runtime.catalog.list().map((m) => {
56
57
  const efforts = runtime.catalog.effortsFor(m.id)
57
58
  return {
58
59
  id: m.id,
59
60
  name: m.name,
60
- input: ['text', 'image'],
61
+ input,
61
62
  reasoning: efforts.length > 0,
62
63
  thinkingLevelMap:
63
64
  efforts.length > 0
@@ -67,8 +68,8 @@ export default function (
67
68
  low: efforts.includes('low') ? 'low' : null,
68
69
  medium: efforts.includes('medium') ? 'medium' : null,
69
70
  high: efforts.includes('high') ? 'high' : null,
70
- xhigh: null,
71
- max: null,
71
+ xhigh: efforts.includes('xhigh') ? 'xhigh' : null,
72
+ max: efforts.includes('max') ? 'max' : null,
72
73
  }
73
74
  : undefined,
74
75
  cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
@@ -76,6 +77,7 @@ export default function (
76
77
  maxTokens: 65536,
77
78
  }
78
79
  })
80
+ }
79
81
  const register = () =>
80
82
  pi.registerProvider(config.provider, {
81
83
  name: config.displayName,
@@ -172,6 +174,13 @@ export default function (
172
174
  pi.on('cache_warming_decision', (_event, ctx) =>
173
175
  ctx.model?.provider === config.provider ? { action: 'stop' } : undefined,
174
176
  )
177
+ pi.on('session_before_compact', (event, ctx) =>
178
+ ctx.model?.provider === config.provider &&
179
+ event.reason === 'threshold' &&
180
+ (ctx.model.contextWindow ?? 0) <= 0
181
+ ? { cancel: true }
182
+ : undefined,
183
+ )
175
184
  pi.on('model_select', (event, ctx) => {
176
185
  const retarget =
177
186
  pendingSettle &&
@@ -342,7 +351,13 @@ export default function (
342
351
  }
343
352
  const notice = snapshot
344
353
  ? formatQuota(snapshot, undefined, quotaDisplay)
345
- : formatStatus(runtime.status())
354
+ : formatStatus(
355
+ runtime.status(
356
+ ctx.model?.provider === config.provider
357
+ ? ctx.model.id
358
+ : undefined,
359
+ ),
360
+ )
346
361
  if (epoch === uiEpoch)
347
362
  updateStatus(ctx, snapshot ?? activeRuntime?.quota.peek())
348
363
  ctx.ui.notify(notice.text, notice.level)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-agy-acp",
3
- "version": "0.1.4",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Google Antigravity ACP provider extension for Pi Coding Agent",
@@ -60,6 +60,20 @@ export interface AcpToolCallMeta {
60
60
  [key: string]: unknown
61
61
  }
62
62
 
63
+ /** One selectable option entry inside an ACP select config option. */
64
+ export interface AcpConfigOptionValue {
65
+ value: string
66
+ name?: string
67
+ description?: string
68
+ }
69
+
70
+ /** One grouped list of selectable option entries inside an ACP select config option. */
71
+ export interface AcpConfigOptionGroup {
72
+ group: string
73
+ name?: string
74
+ options: AcpConfigOptionValue[]
75
+ }
76
+
63
77
  /** One select-type session configuration option. */
64
78
  export interface AcpConfigOption {
65
79
  id: string
@@ -67,7 +81,23 @@ export interface AcpConfigOption {
67
81
  category?: string
68
82
  type?: string
69
83
  currentValue?: string
70
- options?: { value: string; name?: string; description?: string }[]
84
+ options?: (AcpConfigOptionValue | AcpConfigOptionGroup)[]
85
+ }
86
+
87
+ /** `initialize` result. */
88
+ export interface AcpInitializeResult {
89
+ protocolVersion?: number
90
+ agentInfo?: {
91
+ name?: string
92
+ version?: string
93
+ }
94
+ agentCapabilities?: {
95
+ promptCapabilities?: {
96
+ image?: boolean
97
+ audio?: boolean
98
+ embeddedContext?: boolean
99
+ }
100
+ }
71
101
  }
72
102
 
73
103
  /** `session/request_permission` parameters. */
@@ -169,7 +199,7 @@ export class AcpProcess {
169
199
  * Spawn the process and complete the ACP `initialize` handshake.
170
200
  * @param timeoutMs - handshake deadline.
171
201
  */
172
- async start(timeoutMs: number): Promise<void> {
202
+ async start(timeoutMs: number): Promise<AcpInitializeResult | undefined> {
173
203
  const child = this.options.spawn(this.options.argv, this.options.cwd)
174
204
  this.child = child
175
205
  const peer = new JsonRpcPeer(child.stdout, child.stdin, {
@@ -188,7 +218,7 @@ export class AcpProcess {
188
218
  peer.close(error)
189
219
  this.fail(error)
190
220
  })
191
- await peer.request(
221
+ return peer.request<AcpInitializeResult | undefined>(
192
222
  'initialize',
193
223
  {
194
224
  protocolVersion: 1,