pi-agy-acp 0.1.3 → 0.2.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.
- package/CHANGELOG.md +17 -0
- package/docs/development.md +40 -15
- package/docs/reference.md +54 -30
- package/index.ts +141 -44
- package/package.json +6 -6
- package/src/acp-process.ts +2 -0
- package/src/catalog.ts +51 -1
- package/src/conversation.ts +173 -41
- package/src/format.ts +321 -19
- package/src/history.ts +61 -33
- package/src/mcp-bridge.ts +3 -2
- package/src/preflight.ts +242 -13
- package/src/runtime.ts +89 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.2.0](https://github.com/fdkevin0/pi-agy-acp/compare/v0.1.4...v0.2.0) (2026-11-17)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* 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))
|
|
9
|
+
|
|
10
|
+
## [0.1.4](https://github.com/fdkevin0/pi-agy-acp/compare/v0.1.3...v0.1.4) (2026-11-15)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* accept the flat mcp_pi_<tool> name agy 1.5.8 reports for Pi tools ([#23](https://github.com/fdkevin0/pi-agy-acp/issues/23)) ([d202134](https://github.com/fdkevin0/pi-agy-acp/commit/d2021349a4886ae34c5d4de7510da102f0e0c655))
|
|
16
|
+
* deliver harness system prompt in opening ACP prompt ([#24](https://github.com/fdkevin0/pi-agy-acp/issues/24)) ([#26](https://github.com/fdkevin0/pi-agy-acp/issues/26)) ([b8679b0](https://github.com/fdkevin0/pi-agy-acp/commit/b8679b0baa171d6447a1cb11195d82a949bb2adf))
|
|
17
|
+
* match quota groups to specific models and scope cache-warming veto ([#21](https://github.com/fdkevin0/pi-agy-acp/issues/21)) ([4f5bc7b](https://github.com/fdkevin0/pi-agy-acp/commit/4f5bc7b82f4e232ba36e2fcd3aa1e9ea5483e88b))
|
|
18
|
+
* preserve turn usage totals, pin CI baseline, and test permission probe timing ([#10](https://github.com/fdkevin0/pi-agy-acp/issues/10)) ([#27](https://github.com/fdkevin0/pi-agy-acp/issues/27)) ([148fb6a](https://github.com/fdkevin0/pi-agy-acp/commit/148fb6a2f9bf12b31cac4e854d22a652a72c4f3b))
|
|
19
|
+
|
|
3
20
|
## [0.1.3]
|
|
4
21
|
|
|
5
22
|
- Default quota display to `used` across the status bar, quota panel, and warnings, with `/agy-acp quota [used|remaining]` persistence in `settings.json` and `PI_AGY_QUOTA_DISPLAY` startup override.
|
package/docs/development.md
CHANGED
|
@@ -16,9 +16,11 @@ pi -e ./index.ts
|
|
|
16
16
|
|
|
17
17
|
1. The extension registers `antigravity-acp` with Pi. The first request starts
|
|
18
18
|
`agy acp --process-per-session` and a loopback MCP bridge.
|
|
19
|
-
2.
|
|
20
|
-
|
|
21
|
-
the
|
|
19
|
+
2. Session creation appends only a static MCP tool-routing preamble to `agy`'s
|
|
20
|
+
system prompt; Pi's system prompt, compacted initial tool schemas, and any
|
|
21
|
+
replayed history travel in the session's opening prompt within the 160 KB
|
|
22
|
+
replay budget. Later turns on an intact history prefix reuse the session and
|
|
23
|
+
send only new input (plus any dynamic tool deltas).
|
|
22
24
|
3. Model tool calls reach the bridge and remain pending while Pi executes them.
|
|
23
25
|
Pi receives a `toolUse` result, then supplies tool results on its next request.
|
|
24
26
|
4. Those results resolve the pending MCP requests, allowing the same ACP turn to
|
|
@@ -33,6 +35,11 @@ pi -e ./index.ts
|
|
|
33
35
|
caller's wait; shared discovery still closes its session and cleans its files.
|
|
34
36
|
- **Session lifecycle:** The bridge binds to `127.0.0.1`, uses per-session bearer
|
|
35
37
|
credentials, and validates structured tool identity before granting permissions.
|
|
38
|
+
Live `agy 1.5.9` sessions issue `session/request_permission` only inside an
|
|
39
|
+
active `session/prompt` turn (never during `session/new` or
|
|
40
|
+
`session/set_config_option`), so session creation and idle pre-/post-turn
|
|
41
|
+
windows remain fail-closed (`cancelled` before `session/new` completes;
|
|
42
|
+
`reject_once` when no live turn owns the session, even after MCP handshake).
|
|
36
43
|
Tree navigation and compaction close conversation sessions and their files,
|
|
37
44
|
retaining the process, bridge, and caches. `session_start` (`new`, `resume`, or
|
|
38
45
|
`fork`) uses the same light reset if the runtime survives; `session_shutdown`
|
|
@@ -46,8 +53,8 @@ pi -e ./index.ts
|
|
|
46
53
|
over buffered output, and turn/tenant identities guard all async callbacks.
|
|
47
54
|
- **Quota and TUI:** Settled checks share the reader's TTL and in-flight request
|
|
48
55
|
without blocking Pi. Model selection reads memory only. UI generation checks
|
|
49
|
-
discard stale background results; warning keys include bucket, reset
|
|
50
|
-
threshold. An explicit quota query can discover uncached account tiers through
|
|
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
|
|
51
58
|
one tool-less ACP session per runtime, persisting the tier in `catalog.json`.
|
|
52
59
|
Email lookup reads at most the last 64 KiB of each candidate login log and uses
|
|
53
60
|
the last match in the first matching file. Runtime warnings stay off stderr to
|
|
@@ -114,21 +121,39 @@ npm pack --dry-run
|
|
|
114
121
|
|
|
115
122
|
## CI and releases
|
|
116
123
|
|
|
117
|
-
`ci.yml` checks pull requests and pushes to `main`. `release.yml` runs
|
|
118
|
-
version-tag pushes or manual runs on an
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
124
|
+
`ci.yml` checks pull requests and pushes to `main`. `release.yml` runs on pushes
|
|
125
|
+
to `main` (to run `release-please`), version-tag pushes, or manual runs on an
|
|
126
|
+
existing tag, so ordinary commits do not trigger the `publish` job. CI tests the
|
|
127
|
+
pinned `devDependencies` baseline on Node.js 22.19.0 and 24, plus a `pi-compat`
|
|
128
|
+
matrix across `@earendil-works/pi-*` `1.5.0` and latest `1.5`; releases use
|
|
129
|
+
Node.js 24. `.npmrc` sets `package-lock=false` so dependency installation stays
|
|
130
|
+
lockfile-free via `npm install`.
|
|
122
131
|
|
|
123
132
|
All changes to `main` require a pull request, passing CI on both Node versions,
|
|
124
133
|
and resolved review discussions. Squash merge after CI passes; no second-person
|
|
125
134
|
approval is required.
|
|
126
135
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
136
|
+
Releases are automated with `release-please` (`release-please-config.json` and
|
|
137
|
+
`.release-please-manifest.json`):
|
|
138
|
+
- Merging Conventional Commits (`feat:`, `fix:`, etc.) to `main` opens or updates
|
|
139
|
+
a release PR that bumps `package.json` and updates `CHANGELOG.md` and
|
|
140
|
+
`.release-please-manifest.json`.
|
|
141
|
+
- Squash-merging that release PR (preserving its `chore(main): release X.Y.Z`
|
|
142
|
+
title) creates the `vX.Y.Z` tag and GitHub Release, then triggers the
|
|
143
|
+
`publish` job in `release.yml` to check, test, pack, and publish to npm.
|
|
144
|
+
- Enable **Allow GitHub Actions to create and approve pull requests** in
|
|
145
|
+
repository Settings → Actions → General. Without a `RELEASE_PLEASE_TOKEN` PAT
|
|
146
|
+
(with `contents: write` and `pull-requests: write`) in repository secrets,
|
|
147
|
+
`GITHUB_TOKEN` is used; in that case, close and reopen the release PR after
|
|
148
|
+
its final update to trigger `ci.yml` when branch protection requires it.
|
|
149
|
+
- To recover a failed `publish` job, choose **Re-run failed jobs** on that
|
|
150
|
+
workflow run (re-running all jobs on a `main` run skips `publish` once the tag
|
|
151
|
+
exists) or run `gh workflow run release.yml --ref vX.Y.Z`. Manual tag pushes
|
|
152
|
+
(`vX.Y.Z`) also trigger `publish` but bypass `release-please`, leaving
|
|
153
|
+
`CHANGELOG.md` and `.release-please-manifest.json` out of sync.
|
|
154
|
+
- The workflow accepts stable versions only, publishes one version at a time,
|
|
155
|
+
and never moves a published tag. Only a registry 404 means the version is
|
|
156
|
+
absent; network, authentication, and server errors stop the job.
|
|
132
157
|
|
|
133
158
|
Configure npm [Trusted Publishing](https://docs.npmjs.com/trusted-publishers/)
|
|
134
159
|
for owner `fdkevin0`, repository `pi-agy-acp`, and workflow filename `release.yml`.
|
package/docs/reference.md
CHANGED
|
@@ -77,22 +77,25 @@ isolated. Cached plans and login logs can be stale after an account change.
|
|
|
77
77
|
### Quota status and warnings
|
|
78
78
|
|
|
79
79
|
When a run using `antigravity-acp` fully settles, the extension checks `/usage`
|
|
80
|
-
in the background and shows a compact status such as `AGY 20%` (or
|
|
81
|
-
in `remaining` mode). It uses the lowest remaining window
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
80
|
+
in the background and shows a compact status indicator such as `AGY 20%` (or
|
|
81
|
+
`AGY 80%` in `remaining` mode). It uses the lowest known remaining window across
|
|
82
|
+
the selected model's matching quota group(s) (or an unambiguous generic family
|
|
83
|
+
group), and omits the status indicator and low-quota warning when group ownership is
|
|
84
|
+
unknown or ambiguous. Failed background checks stay silent. Successful results
|
|
85
|
+
and failures both respect the two-minute quota TTL, and concurrent background
|
|
86
|
+
checks share the in-flight query.
|
|
87
|
+
|
|
88
|
+
At or below 20% and 5% remaining (≥80% and ≥95% used), a warning appears once
|
|
89
|
+
per group, quota window, reset time, and threshold. `/agy-acp quota` explicitly
|
|
90
|
+
refreshes quota and updates the status indicator; `/agy-acp status` uses fresh
|
|
91
|
+
cached quota only. Neither session start nor model selection launches a quota
|
|
92
|
+
command. Selecting another provider hides the status indicator; returning to
|
|
93
|
+
Antigravity uses only a fresh in-memory snapshot. `/agy-acp reset` clears the
|
|
94
|
+
status indicator and warning history; shutdown clears the status indicator.
|
|
95
|
+
|
|
96
|
+
When the active model belongs to `antigravity-acp`, this extension vetoes Pi's
|
|
97
|
+
automatic prompt-cache warming to avoid background warming requests consuming
|
|
98
|
+
quota. Other providers' warming decisions are left unchanged.
|
|
96
99
|
|
|
97
100
|
## Configuration
|
|
98
101
|
|
|
@@ -142,30 +145,51 @@ The fallback families are:
|
|
|
142
145
|
- `claude-sonnet-5-5`
|
|
143
146
|
- `gpt-oss-120b-medium`
|
|
144
147
|
|
|
145
|
-
These entries are defaults, not a guarantee of account access.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
+
These entries are defaults, not a guarantee of account access. Model context windows
|
|
149
|
+
start at `0` until learned dynamically from the server-issued `max_context_tokens`
|
|
150
|
+
metadata in the session database and cached per model in `catalog.json`. The history
|
|
151
|
+
replay budget is 160,000 bytes; older history can be omitted to fit, and historical
|
|
152
|
+
images become text placeholders.
|
|
148
153
|
|
|
149
154
|
## Usage and costs
|
|
150
155
|
|
|
151
|
-
Usage comes
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
156
|
+
Usage comes from the ACP session rather than per-step API headers. Parked `toolUse`
|
|
157
|
+
steps emit zero usage; statistics arrive on the final step when the full ACP turn
|
|
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` supplies live token occupancy.
|
|
161
|
+
|
|
162
|
+
The extension separates cumulative token consumption from final-call context
|
|
163
|
+
occupancy:
|
|
164
|
+
|
|
165
|
+
- `input`, `output`, `cacheRead`, and `cacheWrite` preserve unscaled cumulative
|
|
166
|
+
turn totals from `session/prompt`, so Pi's session totals and flat pricing
|
|
167
|
+
overrides reflect full multi-step consumption.
|
|
168
|
+
- `totalTokens` (which feeds Pi's context meter and auto-compaction threshold via
|
|
169
|
+
`calculateContextTokens`) uses the final model call's live `usage_update.used`
|
|
170
|
+
count when `agy` provides it. When `usage_update` is absent, it falls back to
|
|
171
|
+
averaging the final `session/prompt` segment's prompt tokens across that
|
|
172
|
+
segment's model calls plus final-segment output tokens; this fallback is an
|
|
173
|
+
estimate rather than an exact per-step measurement.
|
|
155
174
|
|
|
156
175
|
Default model prices are zero because pricing is unavailable. If you configure
|
|
157
|
-
Pi model pricing overrides,
|
|
158
|
-
|
|
176
|
+
Pi model pricing overrides, flat per-million rates price the cumulative turn
|
|
177
|
+
buckets accurately; tiered `inputTokensAbove` rules evaluate against cumulative
|
|
178
|
+
turn prompt tokens rather than per-call prompt sizes. These estimates are not
|
|
179
|
+
an invoice amount or a promise of free access.
|
|
159
180
|
|
|
160
|
-
The extension
|
|
161
|
-
binary patch
|
|
181
|
+
The extension reads only session-scoped `max_context_tokens` metadata inside `PI_AGY_HOME`;
|
|
182
|
+
it never inspects your global `agy` databases or invokes or distributes binary patch
|
|
183
|
+
scripts.
|
|
162
184
|
|
|
163
185
|
## Compatibility limits
|
|
164
186
|
|
|
165
187
|
This version targets the `@earendil-works/*` Pi packages at version 1.5.x.
|
|
166
|
-
Host
|
|
167
|
-
|
|
168
|
-
|
|
188
|
+
Host `peerDependencies` use `*` as required by Pi package conventions;
|
|
189
|
+
`devDependencies` pin a reproducible CI baseline (`1.5.2`), and CI validates
|
|
190
|
+
both that baseline (on Node.js 22.19.0 and 24) and the `1.5.x` host range
|
|
191
|
+
(`1.5.0` and latest `1.5`), which requires Node.js >= 22.19.0. Compatibility
|
|
192
|
+
with older `@mariozechner/*` interfaces is not claimed.
|
|
169
193
|
|
|
170
194
|
Sampling parameters, output limits, forced `toolChoice`, and provider-scoped
|
|
171
195
|
environment overrides are not mapped to ACP. See
|
package/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
type ProviderModelConfig,
|
|
5
5
|
type ExtensionContext,
|
|
6
6
|
} from '@earendil-works/pi-coding-agent'
|
|
7
|
-
import { AntigravityRuntime } from './src/runtime.ts'
|
|
7
|
+
import { AntigravityRuntime, type RuntimeHost } from './src/runtime.ts'
|
|
8
8
|
import {
|
|
9
9
|
asQuotaDisplay,
|
|
10
10
|
DEFAULT_QUOTA_DISPLAY,
|
|
@@ -24,7 +24,10 @@ import {
|
|
|
24
24
|
} from './src/format.ts'
|
|
25
25
|
import type { QuotaSnapshot } from './src/quota.ts'
|
|
26
26
|
|
|
27
|
-
export default function (
|
|
27
|
+
export default function (
|
|
28
|
+
pi: ExtensionAPI,
|
|
29
|
+
host: Partial<Pick<RuntimeHost, 'runCommand'>> = {},
|
|
30
|
+
) {
|
|
28
31
|
const envQuotaDisplay = asQuotaDisplay(process.env.PI_AGY_QUOTA_DISPLAY)
|
|
29
32
|
const config = {
|
|
30
33
|
...defaults,
|
|
@@ -36,16 +39,17 @@ export default function (pi: ExtensionAPI) {
|
|
|
36
39
|
new AntigravityRuntime({
|
|
37
40
|
config,
|
|
38
41
|
spawnAcp,
|
|
39
|
-
runCommand,
|
|
42
|
+
runCommand: host.runCommand ?? runCommand,
|
|
40
43
|
log: { info: () => {}, warn: () => {} },
|
|
41
44
|
onModelsChanged: () => {
|
|
42
45
|
if (refreshDepth === 0) register()
|
|
43
46
|
},
|
|
44
47
|
})
|
|
45
48
|
let runtime = createRuntime()
|
|
49
|
+
const home = runtime.status().home
|
|
46
50
|
let quotaDisplay: QuotaDisplay =
|
|
47
51
|
envQuotaDisplay ??
|
|
48
|
-
readQuotaDisplayPreference(
|
|
52
|
+
readQuotaDisplayPreference(home) ??
|
|
49
53
|
DEFAULT_QUOTA_DISPLAY
|
|
50
54
|
const models = (): ProviderModelConfig[] =>
|
|
51
55
|
runtime.catalog.list().map((m) => {
|
|
@@ -98,92 +102,178 @@ export default function (pi: ExtensionAPI) {
|
|
|
98
102
|
})
|
|
99
103
|
register()
|
|
100
104
|
let uiEpoch = 0
|
|
101
|
-
let
|
|
105
|
+
let shutDown = false
|
|
106
|
+
let activeRuntime: AntigravityRuntime | undefined = runtime
|
|
107
|
+
let resetting: Promise<void> | undefined
|
|
108
|
+
interface PendingSettle {
|
|
109
|
+
runtime: AntigravityRuntime
|
|
110
|
+
epoch: number
|
|
111
|
+
ctx: ExtensionContext
|
|
112
|
+
model: ExtensionContext['model']
|
|
113
|
+
}
|
|
114
|
+
let pendingSettle: PendingSettle | undefined
|
|
102
115
|
const warned = new Set<string>()
|
|
103
116
|
const clearStatus = (ctx?: ExtensionContext) => {
|
|
104
117
|
uiEpoch++
|
|
105
|
-
|
|
118
|
+
pendingSettle = undefined
|
|
119
|
+
if (!shutDown && ctx?.hasUI) ctx.ui.setStatus(config.provider, undefined)
|
|
106
120
|
}
|
|
107
121
|
const updateStatus = (
|
|
108
122
|
ctx: ExtensionContext,
|
|
109
123
|
snapshot?: QuotaSnapshot,
|
|
110
|
-
explicit = false,
|
|
111
124
|
model = ctx.model,
|
|
112
125
|
) => {
|
|
113
|
-
if (ctx.hasUI &&
|
|
126
|
+
if (!shutDown && activeRuntime && ctx.hasUI && model?.provider === config.provider)
|
|
114
127
|
ctx.ui.setStatus(
|
|
115
128
|
config.provider,
|
|
116
129
|
snapshot
|
|
117
|
-
? formatQuotaStatus(snapshot, model
|
|
130
|
+
? formatQuotaStatus(snapshot, model, quotaDisplay)
|
|
118
131
|
: undefined,
|
|
119
132
|
)
|
|
120
133
|
}
|
|
121
|
-
const reset =
|
|
134
|
+
const reset = () => {
|
|
122
135
|
uiEpoch++
|
|
123
136
|
warned.clear()
|
|
124
|
-
|
|
125
|
-
|
|
137
|
+
pendingSettle = undefined
|
|
138
|
+
activeRuntime = undefined
|
|
139
|
+
if (resetting) return resetting
|
|
140
|
+
const previous = runtime
|
|
141
|
+
resetting = (async () => {
|
|
142
|
+
try {
|
|
143
|
+
await previous.dispose()
|
|
144
|
+
if (shutDown) return
|
|
145
|
+
runtime = activeRuntime = createRuntime()
|
|
146
|
+
} finally {
|
|
147
|
+
resetting = undefined
|
|
148
|
+
}
|
|
149
|
+
})()
|
|
150
|
+
return resetting
|
|
126
151
|
}
|
|
127
|
-
pi.on('session_tree', () =>
|
|
128
|
-
pi.on('session_compact', () =>
|
|
152
|
+
pi.on('session_tree', () => activeRuntime?.resetConversations())
|
|
153
|
+
pi.on('session_compact', () => activeRuntime?.resetConversations())
|
|
129
154
|
pi.on('session_start', async (event, ctx) => {
|
|
130
155
|
clearStatus(ctx)
|
|
156
|
+
const epoch = uiEpoch
|
|
157
|
+
if (resetting) await resetting.catch(() => {})
|
|
158
|
+
if (shutDown) return
|
|
131
159
|
if (['new', 'resume', 'fork'].includes(event.reason))
|
|
132
|
-
await
|
|
133
|
-
|
|
160
|
+
await activeRuntime?.resetConversations()
|
|
161
|
+
if (!shutDown && epoch === uiEpoch)
|
|
162
|
+
updateStatus(ctx, activeRuntime?.quota.peek())
|
|
134
163
|
})
|
|
135
164
|
pi.on('session_shutdown', async (_event, ctx) => {
|
|
136
165
|
clearStatus(ctx)
|
|
166
|
+
shutDown = true
|
|
167
|
+
activeRuntime = undefined
|
|
168
|
+
pendingSettle = undefined
|
|
169
|
+
if (resetting) await resetting.catch(() => {})
|
|
137
170
|
await runtime.dispose()
|
|
138
171
|
})
|
|
139
|
-
pi.on('cache_warming_decision', () =>
|
|
172
|
+
pi.on('cache_warming_decision', (_event, ctx) =>
|
|
173
|
+
ctx.model?.provider === config.provider ? { action: 'stop' } : undefined,
|
|
174
|
+
)
|
|
175
|
+
pi.on('session_before_compact', (event, ctx) =>
|
|
176
|
+
ctx.model?.provider === config.provider &&
|
|
177
|
+
event.reason === 'threshold' &&
|
|
178
|
+
(ctx.model.contextWindow ?? 0) <= 0
|
|
179
|
+
? { cancel: true }
|
|
180
|
+
: undefined,
|
|
181
|
+
)
|
|
140
182
|
pi.on('model_select', (event, ctx) => {
|
|
183
|
+
const retarget =
|
|
184
|
+
pendingSettle &&
|
|
185
|
+
pendingSettle.runtime === activeRuntime &&
|
|
186
|
+
pendingSettle.epoch === uiEpoch &&
|
|
187
|
+
event.model?.provider === config.provider
|
|
188
|
+
? pendingSettle
|
|
189
|
+
: undefined
|
|
141
190
|
clearStatus(ctx)
|
|
142
|
-
|
|
191
|
+
if (retarget) {
|
|
192
|
+
retarget.epoch = uiEpoch
|
|
193
|
+
retarget.ctx = ctx
|
|
194
|
+
retarget.model = event.model
|
|
195
|
+
pendingSettle = retarget
|
|
196
|
+
}
|
|
197
|
+
updateStatus(ctx, activeRuntime?.quota.peek(), event.model)
|
|
143
198
|
})
|
|
144
199
|
pi.on('agent_settled', (_event, ctx) => {
|
|
145
200
|
// Pi 1.5.2 AgentSession._emitAgentSettled runs after tools and the run finish.
|
|
146
201
|
runtime.settleSession(ctx.sessionManager.getSessionId())
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
202
|
+
const current = activeRuntime
|
|
203
|
+
if (!current || !ctx.hasUI || ctx.model?.provider !== config.provider) return
|
|
204
|
+
if (pendingSettle?.runtime === current) {
|
|
205
|
+
pendingSettle.epoch = uiEpoch
|
|
206
|
+
pendingSettle.ctx = ctx
|
|
207
|
+
pendingSettle.model = ctx.model
|
|
152
208
|
return
|
|
153
|
-
|
|
154
|
-
const
|
|
155
|
-
|
|
209
|
+
}
|
|
210
|
+
const state: PendingSettle = {
|
|
211
|
+
runtime: current,
|
|
212
|
+
epoch: uiEpoch,
|
|
213
|
+
ctx,
|
|
214
|
+
model: ctx.model,
|
|
215
|
+
}
|
|
216
|
+
pendingSettle = state
|
|
156
217
|
void current.quota
|
|
157
218
|
.read(false)
|
|
158
219
|
.then((snapshot) => {
|
|
159
220
|
if (
|
|
160
|
-
|
|
161
|
-
|
|
221
|
+
shutDown ||
|
|
222
|
+
pendingSettle !== state ||
|
|
223
|
+
state.runtime !== activeRuntime ||
|
|
224
|
+
state.epoch !== uiEpoch ||
|
|
162
225
|
snapshot.status !== 'ok'
|
|
163
226
|
)
|
|
164
227
|
return
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
228
|
+
const targetCtx = state.ctx
|
|
229
|
+
const model = state.model
|
|
230
|
+
if (!targetCtx.hasUI || model?.provider !== config.provider) return
|
|
231
|
+
updateStatus(targetCtx, snapshot, model)
|
|
232
|
+
const quota = quotaForModel(snapshot, model)
|
|
168
233
|
if (!quota || quota.fraction > 0.2) return
|
|
169
234
|
const threshold = quota.fraction <= 0.05 ? 5 : 20
|
|
170
|
-
const
|
|
235
|
+
const groupName = quota.group.name || 'Unnamed model group'
|
|
236
|
+
const windowLabel =
|
|
237
|
+
quota.bucket.window ||
|
|
238
|
+
quota.bucket.name ||
|
|
239
|
+
quota.bucket.id ||
|
|
240
|
+
'quota'
|
|
241
|
+
const key = `${groupName}:${quota.bucket.id}:${windowLabel}:${quota.bucket.resetTime || 'none'}:${threshold}`
|
|
171
242
|
if (warned.has(key)) return
|
|
172
243
|
warned.add(key)
|
|
173
244
|
const percent = Math.round(
|
|
174
245
|
displayFraction(quota.fraction, quotaDisplay) * 100,
|
|
175
246
|
)
|
|
176
247
|
const metric = `${percent}% ${quotaDisplay}`
|
|
177
|
-
|
|
178
|
-
`Antigravity quota low: ${metric} (${
|
|
248
|
+
targetCtx.ui.notify(
|
|
249
|
+
`Antigravity quota low: ${metric} (${groupName}, ${windowLabel}).`,
|
|
179
250
|
'warning',
|
|
180
251
|
)
|
|
181
252
|
})
|
|
182
253
|
.catch(() => {})
|
|
183
254
|
.finally(() => {
|
|
184
|
-
|
|
255
|
+
if (pendingSettle === state) pendingSettle = undefined
|
|
185
256
|
})
|
|
186
257
|
})
|
|
258
|
+
const readQuotaSafe = async (): Promise<QuotaSnapshot> => {
|
|
259
|
+
if (!activeRuntime)
|
|
260
|
+
return {
|
|
261
|
+
status: 'error',
|
|
262
|
+
updatedAt: new Date().toISOString(),
|
|
263
|
+
groups: [],
|
|
264
|
+
error: 'Antigravity ACP runtime is disposed.',
|
|
265
|
+
}
|
|
266
|
+
try {
|
|
267
|
+
return await activeRuntime.readQuota(true)
|
|
268
|
+
} catch (err) {
|
|
269
|
+
return {
|
|
270
|
+
status: 'error',
|
|
271
|
+
updatedAt: new Date().toISOString(),
|
|
272
|
+
groups: [],
|
|
273
|
+
error: err instanceof Error ? err.message : String(err),
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
187
277
|
pi.registerCommand('agy-acp', {
|
|
188
278
|
description: 'Antigravity ACP status, quota, or reset',
|
|
189
279
|
getArgumentCompletions: (prefix) => {
|
|
@@ -200,6 +290,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
200
290
|
return items.length > 0 ? items : null
|
|
201
291
|
},
|
|
202
292
|
handler: async (args, ctx) => {
|
|
293
|
+
if (shutDown) return
|
|
203
294
|
const tokens = args.trim().split(/\s+/).filter(Boolean)
|
|
204
295
|
const command = tokens[0] ?? ''
|
|
205
296
|
const requestedDisplay =
|
|
@@ -209,7 +300,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
209
300
|
if (command === 'reset' && tokens.length === 1) {
|
|
210
301
|
clearStatus(ctx)
|
|
211
302
|
await reset()
|
|
212
|
-
ctx.ui.notify('Antigravity ACP sessions reset', 'info')
|
|
303
|
+
if (!shutDown) ctx.ui.notify('Antigravity ACP sessions reset', 'info')
|
|
213
304
|
return
|
|
214
305
|
}
|
|
215
306
|
const isStatus =
|
|
@@ -226,7 +317,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
226
317
|
}
|
|
227
318
|
if (requestedDisplay !== undefined) {
|
|
228
319
|
quotaDisplay = requestedDisplay
|
|
229
|
-
writeQuotaDisplayPreference(
|
|
320
|
+
writeQuotaDisplayPreference(home, quotaDisplay)
|
|
230
321
|
}
|
|
231
322
|
let snapshot: QuotaSnapshot | null = null
|
|
232
323
|
const epoch = uiEpoch
|
|
@@ -241,26 +332,32 @@ export default function (pi: ExtensionAPI) {
|
|
|
241
332
|
'Fetching Antigravity quota...',
|
|
242
333
|
)
|
|
243
334
|
loader.onAbort = () => done(null)
|
|
244
|
-
//
|
|
245
|
-
void
|
|
335
|
+
// readQuotaSafe converts runtime errors into snapshots so loaders always close cleanly.
|
|
336
|
+
void readQuotaSafe().then((result) => {
|
|
246
337
|
if (!loader.signal.aborted) done(result)
|
|
247
338
|
})
|
|
248
339
|
return loader
|
|
249
340
|
},
|
|
250
341
|
)
|
|
251
|
-
: await
|
|
342
|
+
: await readQuotaSafe()
|
|
343
|
+
if (shutDown) return
|
|
252
344
|
if (snapshot === null) {
|
|
253
|
-
if (epoch === uiEpoch)
|
|
254
|
-
updateStatus(ctx, runtime.quota.peek(), true)
|
|
345
|
+
if (epoch === uiEpoch) updateStatus(ctx, activeRuntime?.quota.peek())
|
|
255
346
|
ctx.ui.notify('Quota check cancelled', 'info')
|
|
256
347
|
return
|
|
257
348
|
}
|
|
258
349
|
}
|
|
259
350
|
const notice = snapshot
|
|
260
351
|
? formatQuota(snapshot, undefined, quotaDisplay)
|
|
261
|
-
: formatStatus(
|
|
352
|
+
: formatStatus(
|
|
353
|
+
runtime.status(
|
|
354
|
+
ctx.model?.provider === config.provider
|
|
355
|
+
? ctx.model.id
|
|
356
|
+
: undefined,
|
|
357
|
+
),
|
|
358
|
+
)
|
|
262
359
|
if (epoch === uiEpoch)
|
|
263
|
-
updateStatus(ctx, snapshot ??
|
|
360
|
+
updateStatus(ctx, snapshot ?? activeRuntime?.quota.peek())
|
|
264
361
|
ctx.ui.notify(notice.text, notice.level)
|
|
265
362
|
},
|
|
266
363
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-agy-acp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Google Antigravity ACP provider extension for Pi Coding Agent",
|
|
@@ -39,11 +39,11 @@
|
|
|
39
39
|
"check": "tsc --noEmit"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"typescript": "
|
|
43
|
-
"@types/node": "
|
|
44
|
-
"@earendil-works/pi-ai": "
|
|
45
|
-
"@earendil-works/pi-coding-agent": "
|
|
46
|
-
"@earendil-works/pi-tui": "
|
|
42
|
+
"typescript": "7.0.2",
|
|
43
|
+
"@types/node": "22.20.5",
|
|
44
|
+
"@earendil-works/pi-ai": "1.5.2",
|
|
45
|
+
"@earendil-works/pi-coding-agent": "1.5.2",
|
|
46
|
+
"@earendil-works/pi-tui": "1.5.2"
|
|
47
47
|
},
|
|
48
48
|
"keywords": [
|
|
49
49
|
"pi-package",
|
package/src/acp-process.ts
CHANGED
|
@@ -36,6 +36,7 @@ export interface AcpSessionUpdate {
|
|
|
36
36
|
sessionUpdate: string
|
|
37
37
|
content?: { type: string; text?: string }
|
|
38
38
|
toolCallId?: string
|
|
39
|
+
name?: string
|
|
39
40
|
title?: string
|
|
40
41
|
status?: string
|
|
41
42
|
kind?: string
|
|
@@ -74,6 +75,7 @@ export interface AcpPermissionRequest {
|
|
|
74
75
|
sessionId: string
|
|
75
76
|
toolCall?: {
|
|
76
77
|
toolCallId?: string
|
|
78
|
+
name?: string
|
|
77
79
|
title?: string
|
|
78
80
|
kind?: string
|
|
79
81
|
rawInput?: unknown
|