pi-agy-acp 0.1.2 → 0.1.3
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 +7 -0
- package/README.md +9 -4
- package/docs/development.md +34 -10
- package/docs/reference.md +31 -27
- package/index.ts +57 -10
- package/package.json +6 -3
- package/src/acp-process.ts +6 -2
- package/src/config.ts +75 -0
- package/src/conversation.ts +154 -30
- package/src/format.ts +17 -3
- package/src/history.ts +30 -7
- package/src/jsonrpc.ts +16 -0
- package/src/mcp-bridge.ts +119 -42
- package/src/pi-stream.ts +43 -2
- package/src/preflight.ts +1 -14
- package/src/runtime.ts +318 -133
- package/src/util.ts +12 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.1.3]
|
|
4
|
+
|
|
5
|
+
- 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.
|
|
6
|
+
- Harden MCP HTTP request boundaries, runtime disposal, conversation turn ownership, and tool continuation/cancellation handling.
|
|
7
|
+
- Correct the minimum Node.js version to 22.19.0 to match Pi 1.5.x requirements.
|
|
8
|
+
- Add contribution and security policies, issue templates, dependency updates, and CI coverage for Node.js 22.19.0 and 24.
|
|
9
|
+
|
|
3
10
|
## [0.1.2]
|
|
4
11
|
|
|
5
12
|
- Fix model refresh self-cancellation and support forced or cancelled refreshes.
|
package/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# pi-agy-acp
|
|
2
2
|
|
|
3
|
+
[](https://github.com/fdkevin0/pi-agy-acp/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/pi-agy-acp)
|
|
5
|
+
|
|
3
6
|
Use Google Antigravity in Pi through the official, locally installed `agy` CLI.
|
|
4
7
|
This extension registers the `antigravity-acp` provider and lets Pi execute the
|
|
5
8
|
model's tool calls. It supports streaming text and reasoning, images, and
|
|
@@ -7,7 +10,7 @@ parallel tool calls.
|
|
|
7
10
|
|
|
8
11
|
## Prerequisites
|
|
9
12
|
|
|
10
|
-
- Node.js >= 22.
|
|
13
|
+
- Node.js >= 22.19.0.
|
|
11
14
|
- Pi (`@earendil-works/pi-coding-agent`) 1.5.x.
|
|
12
15
|
- The official `agy` CLI >= 1.4.12, signed in with your Google account.
|
|
13
16
|
Run `agy` in your terminal to complete sign-in before using the extension.
|
|
@@ -44,11 +47,11 @@ automatically from your account.
|
|
|
44
47
|
| Command | Purpose |
|
|
45
48
|
| --- | --- |
|
|
46
49
|
| `/agy-acp` or `/agy-acp status` | Show runtime state, account details, models, sessions, and the last turn. |
|
|
47
|
-
| `/agy-acp quota` | Show account details, grouped quota bars, and reset countdowns. |
|
|
50
|
+
| `/agy-acp quota [used\|remaining]` | Show account details, grouped quota bars, and reset countdowns (remembers the last selected mode). |
|
|
48
51
|
| `/agy-acp reset` | Close ACP sessions; the next request rebuilds the connection. |
|
|
49
52
|
|
|
50
|
-
After an Antigravity turn settles, the status bar shows
|
|
51
|
-
`AGY 80%`) and warns when quota is low; see [quota status](docs/reference.md#quota-status-and-warnings).
|
|
53
|
+
After an Antigravity turn settles, the status bar shows quota usage (for example,
|
|
54
|
+
`AGY 20%`, or `AGY 80%` in `remaining` mode) and warns when quota is low; see [quota status](docs/reference.md#quota-status-and-warnings).
|
|
52
55
|
|
|
53
56
|
Default prices are zero, not a promise of free calls. Pi pricing overrides are
|
|
54
57
|
used when configured.
|
|
@@ -59,3 +62,5 @@ used when configured.
|
|
|
59
62
|
- [Development](docs/development.md): setup, request flow, source layout, and verification.
|
|
60
63
|
- [Changelog](CHANGELOG.md): release history and upcoming changes.
|
|
61
64
|
- [Attribution](NOTICE) and [MIT license](LICENSE).
|
|
65
|
+
|
|
66
|
+
For contributions, see [CONTRIBUTING.md](https://github.com/fdkevin0/pi-agy-acp/blob/main/CONTRIBUTING.md). Report vulnerabilities through the [security policy](https://github.com/fdkevin0/pi-agy-acp/blob/main/SECURITY.md).
|
package/docs/development.md
CHANGED
|
@@ -34,11 +34,16 @@ pi -e ./index.ts
|
|
|
34
34
|
- **Session lifecycle:** The bridge binds to `127.0.0.1`, uses per-session bearer
|
|
35
35
|
credentials, and validates structured tool identity before granting permissions.
|
|
36
36
|
Tree navigation and compaction close conversation sessions and their files,
|
|
37
|
-
retaining the process, bridge, and caches.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
retaining the process, bridge, and caches. `session_start` (`new`, `resume`, or
|
|
38
|
+
`fork`) uses the same light reset if the runtime survives; `session_shutdown`
|
|
39
|
+
and `/agy-acp reset` dispose the runtime.
|
|
40
|
+
Disposal is idempotent, drains in-flight startup and bridge binding, cancels
|
|
41
|
+
waiters, and rolls back late session replies from obsolete processes or
|
|
42
|
+
conversations. A turn owns cancellation through streaming and parked tool
|
|
43
|
+
execution until its step drains, `agent_settled` runs, or the process exits;
|
|
44
|
+
only a fully drained `tool-calls` handoff preserves parked tool calls.
|
|
45
|
+
First interruption wins (`abandon` vs. `fail`), cancellation takes priority
|
|
46
|
+
over buffered output, and turn/tenant identities guard all async callbacks.
|
|
42
47
|
- **Quota and TUI:** Settled checks share the reader's TTL and in-flight request
|
|
43
48
|
without blocking Pi. Model selection reads memory only. UI generation checks
|
|
44
49
|
discard stale background results; warning keys include bucket, reset time, and
|
|
@@ -55,6 +60,20 @@ pi -e ./index.ts
|
|
|
55
60
|
receive `context_length_exceeded` and `quota exceeded` markers for Pi's
|
|
56
61
|
compaction and retry decisions; transport timeouts remain distinct.
|
|
57
62
|
|
|
63
|
+
## MCP HTTP boundary
|
|
64
|
+
|
|
65
|
+
The loopback bridge returns 400 for invalid URLs and 413 for authenticated POST
|
|
66
|
+
bodies exceeding 1 MiB (1,048,576 bytes), including chunked uploads. Rejected
|
|
67
|
+
oversized uploads close their connection after the error response. JSON parse
|
|
68
|
+
errors retain the MCP parse-error response. Unexpected handler failures return
|
|
69
|
+
500 before headers or destroy an already-started response; listener errors go to
|
|
70
|
+
the diagnostic sink.
|
|
71
|
+
|
|
72
|
+
Node's HTTP parser enforces a 10-second header reception deadline and a 30-second
|
|
73
|
+
whole-request reception deadline, checked every second. These are reception limits
|
|
74
|
+
only and do not cap completed SSE tool streams. Shutdown stops accepting
|
|
75
|
+
connections and destroys all tracked sockets without waiting for tool promises.
|
|
76
|
+
|
|
58
77
|
## Source layout
|
|
59
78
|
|
|
60
79
|
| File or group | Responsibility |
|
|
@@ -97,12 +116,17 @@ npm pack --dry-run
|
|
|
97
116
|
|
|
98
117
|
`ci.yml` checks pull requests and pushes to `main`. `release.yml` runs only for
|
|
99
118
|
version-tag pushes or manual runs on an existing tag, so ordinary commits do not
|
|
100
|
-
run a second test suite or trigger publication.
|
|
101
|
-
committed lockfile, so dependency
|
|
119
|
+
run a second test suite or trigger publication. CI tests Node.js 22.19.0 and 24;
|
|
120
|
+
releases use Node.js 24. There is no committed lockfile, so dependency
|
|
121
|
+
installation uses `npm install`.
|
|
122
|
+
|
|
123
|
+
All changes to `main` require a pull request, passing CI on both Node versions,
|
|
124
|
+
and resolved review discussions. Squash merge after CI passes; no second-person
|
|
125
|
+
approval is required.
|
|
102
126
|
|
|
103
|
-
To release, bump `package.json
|
|
104
|
-
`vX.Y.Z` tag
|
|
105
|
-
a time and never move a published tag. It validates the tag and version, then
|
|
127
|
+
To release, bump `package.json` through a pull request, merge it, and tag the
|
|
128
|
+
merged commit with its matching `vX.Y.Z` tag, then push the tag. The workflow
|
|
129
|
+
accepts stable versions only; publish one version at a time and never move a published tag. It validates the tag and version, then
|
|
106
130
|
checks, tests, and packs before publishing. Only a registry 404 means the version
|
|
107
131
|
is absent; network, authentication, and server errors stop the job.
|
|
108
132
|
|
package/docs/reference.md
CHANGED
|
@@ -7,11 +7,11 @@ For installation and your first request, start with the [installation guide](../
|
|
|
7
7
|
| Command | Behavior |
|
|
8
8
|
| --- | --- |
|
|
9
9
|
| `/agy-acp` or `/agy-acp status` | Show a status panel with runtime state, paths, sessions, model reasoning levels, and the last turn. |
|
|
10
|
-
| `/agy-acp quota` | Show account details, grouped quota bars, and reset countdowns. |
|
|
10
|
+
| `/agy-acp quota [used\|remaining]` | Show account details, grouped quota bars, and reset countdowns, optionally switching and remembering the display mode. |
|
|
11
11
|
| `/agy-acp reset` | Close ACP sessions; the next request rebuilds a session from Pi's history. |
|
|
12
12
|
|
|
13
13
|
Subcommands support completion with Tab. Unknown arguments display
|
|
14
|
-
`Usage: /agy-acp [status|quota|reset]` as a warning.
|
|
14
|
+
`Usage: /agy-acp [status|quota [used|remaining]|reset]` as a warning.
|
|
15
15
|
|
|
16
16
|
### Status panel
|
|
17
17
|
|
|
@@ -35,8 +35,10 @@ editor. The underlying quota query may finish and update the cache, but its resu
|
|
|
35
35
|
will not appear after cancellation. Non-TUI modes query directly without a loader.
|
|
36
36
|
|
|
37
37
|
Quota is read through `agy -p /usage --output-format json`. Each model group has
|
|
38
|
-
one row per quota window, with a 12-cell bar
|
|
39
|
-
|
|
38
|
+
one row per quota window, with a 12-cell bar, a rounded percentage, and a relative
|
|
39
|
+
reset time. By default (`used` mode), bars and percentages count up from `0%`; pass
|
|
40
|
+
`remaining` (`/agy-acp quota remaining`) to count down from `100%`. The last
|
|
41
|
+
selected mode is saved in `settings.json` inside `PI_AGY_HOME`. For example:
|
|
40
42
|
|
|
41
43
|
```text
|
|
42
44
|
Antigravity Quota
|
|
@@ -44,8 +46,8 @@ Antigravity Quota
|
|
|
44
46
|
|
|
45
47
|
Gemini Models
|
|
46
48
|
Gemini Flash, Gemini Pro
|
|
47
|
-
5h [
|
|
48
|
-
weekly [
|
|
49
|
+
5h [░░░░░░░░░░░░] 0% · resets in 4h 59m
|
|
50
|
+
weekly [█░░░░░░░░░░░] 9% · resets in 6d 7h
|
|
49
51
|
```
|
|
50
52
|
|
|
51
53
|
Missing values display `n/a`; an elapsed reset time displays `resetting soon`.
|
|
@@ -53,13 +55,13 @@ Severity uses the actual remaining fraction rather than the rounded percentage:
|
|
|
53
55
|
|
|
54
56
|
| Condition | Notification |
|
|
55
57
|
| --- | --- |
|
|
56
|
-
| All known windows above 20% | Info |
|
|
57
|
-
| Any window at or below 20
|
|
58
|
-
| Any window at or below 5
|
|
58
|
+
| All known windows above 20% remaining (<80% used) | Info |
|
|
59
|
+
| Any window at or below 20% remaining (≥80% used), with none at or below 5% remaining | Warning |
|
|
60
|
+
| Any window at or below 5% remaining (≥95% used), or a failed quota query | Error |
|
|
59
61
|
|
|
60
62
|
Errors include the reason. If cached groups are available after a failed query,
|
|
61
|
-
the title marks them as `(stale)` and still displays their bars. An empty
|
|
62
|
-
response displays `No quota data available.`.
|
|
63
|
+
the title marks them as `(stale)` and still displays their bars. An empty
|
|
64
|
+
successful response displays `No quota data available.`.
|
|
63
65
|
|
|
64
66
|
### Account details
|
|
65
67
|
|
|
@@ -75,18 +77,19 @@ isolated. Cached plans and login logs can be stale after an account change.
|
|
|
75
77
|
### Quota status and warnings
|
|
76
78
|
|
|
77
79
|
When a run using `antigravity-acp` fully settles, the extension checks `/usage`
|
|
78
|
-
in the background and shows a compact status such as `AGY
|
|
79
|
-
lowest
|
|
80
|
-
|
|
81
|
-
checks stay silent. Successful results and
|
|
82
|
-
quota TTL, and overlapping background
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
`/agy-acp
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
80
|
+
in the background and shows a compact status such as `AGY 20%` (or `AGY 80%`
|
|
81
|
+
in `remaining` mode). It uses the lowest remaining window in the selected model
|
|
82
|
+
family's group, falling back to the lowest remaining quota across groups when
|
|
83
|
+
the family cannot be matched. Failed checks stay silent. Successful results and
|
|
84
|
+
failures both respect the two-minute quota TTL, and overlapping background
|
|
85
|
+
checks are skipped.
|
|
86
|
+
|
|
87
|
+
At 20% and 5% remaining (80% and 95% used), a warning appears once per bucket,
|
|
88
|
+
reset time, and threshold. `/agy-acp quota` explicitly refreshes quota and updates
|
|
89
|
+
the status; `/agy-acp status` uses fresh cached quota only. Neither session start
|
|
90
|
+
nor model selection launches a quota command. Selecting another provider hides the
|
|
91
|
+
status; returning to Antigravity uses only a fresh in-memory snapshot. Reset and
|
|
92
|
+
shutdown clear the status.
|
|
90
93
|
|
|
91
94
|
While loaded, this extension vetoes Pi's automatic prompt-cache warming to avoid
|
|
92
95
|
idle requests consuming quota. It does not alter explicit model requests.
|
|
@@ -99,6 +102,7 @@ Set these environment variables before starting Pi:
|
|
|
99
102
|
| --- | --- | --- |
|
|
100
103
|
| `PI_AGY_COMMAND` | Absolute path to the `agy` executable. | Automatic discovery. |
|
|
101
104
|
| `PI_AGY_HOME` | Dedicated directory for this extension's agy state. | `~/.pi/agent/cache/antigravity-acp` |
|
|
105
|
+
| `PI_AGY_QUOTA_DISPLAY` | Startup quota display mode (`used` or `remaining`), overriding `settings.json` for startup. Invalid values are ignored; `/agy-acp quota <mode>` overrides it for the active session. | `settings.json`, then `used` |
|
|
102
106
|
|
|
103
107
|
For example:
|
|
104
108
|
|
|
@@ -112,8 +116,8 @@ The dedicated directory isolates the bridge agent from your normal agy tools and
|
|
|
112
116
|
plugins. It contains agy-managed session data, logs, and the extension's model cache.
|
|
113
117
|
|
|
114
118
|
Temporary session data and old logs are removed automatically. The current log,
|
|
115
|
-
model cache,
|
|
116
|
-
history. Cleanup is best-effort if files are locked. Use a different `PI_AGY_HOME`
|
|
119
|
+
model cache, `settings.json` (quota display preference), and authentication files
|
|
120
|
+
are retained; sessions rebuild from Pi's history. Cleanup is best-effort if files are locked. Use a different `PI_AGY_HOME`
|
|
117
121
|
for each concurrently running Pi instance, since startup cleanup assumes exclusive
|
|
118
122
|
use of the directory.
|
|
119
123
|
|
|
@@ -159,8 +163,8 @@ binary patch scripts.
|
|
|
159
163
|
## Compatibility limits
|
|
160
164
|
|
|
161
165
|
This version targets the `@earendil-works/*` Pi packages at version 1.5.x.
|
|
162
|
-
Host peer dependencies use `*` as required by Pi package conventions;
|
|
163
|
-
|
|
166
|
+
Host peer dependencies use `*` as required by Pi package conventions; development
|
|
167
|
+
dependencies constrain CI to Pi 1.5.x, which requires Node.js >= 22.19.0. Compatibility with older
|
|
164
168
|
`@mariozechner/*` interfaces is not claimed.
|
|
165
169
|
|
|
166
170
|
Sampling parameters, output limits, forced `toolChoice`, and provider-scoped
|
package/index.ts
CHANGED
|
@@ -5,10 +5,18 @@ import {
|
|
|
5
5
|
type ExtensionContext,
|
|
6
6
|
} from '@earendil-works/pi-coding-agent'
|
|
7
7
|
import { AntigravityRuntime } from './src/runtime.ts'
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
asQuotaDisplay,
|
|
10
|
+
DEFAULT_QUOTA_DISPLAY,
|
|
11
|
+
defaults,
|
|
12
|
+
readQuotaDisplayPreference,
|
|
13
|
+
writeQuotaDisplayPreference,
|
|
14
|
+
type QuotaDisplay,
|
|
15
|
+
} from './src/config.ts'
|
|
9
16
|
import { spawnAcp, runCommand } from './src/host.ts'
|
|
10
17
|
import { streamPi } from './src/pi-stream.ts'
|
|
11
18
|
import {
|
|
19
|
+
displayFraction,
|
|
12
20
|
formatQuota,
|
|
13
21
|
formatStatus,
|
|
14
22
|
formatQuotaStatus,
|
|
@@ -17,6 +25,7 @@ import {
|
|
|
17
25
|
import type { QuotaSnapshot } from './src/quota.ts'
|
|
18
26
|
|
|
19
27
|
export default function (pi: ExtensionAPI) {
|
|
28
|
+
const envQuotaDisplay = asQuotaDisplay(process.env.PI_AGY_QUOTA_DISPLAY)
|
|
20
29
|
const config = {
|
|
21
30
|
...defaults,
|
|
22
31
|
command: process.env.PI_AGY_COMMAND || '',
|
|
@@ -34,6 +43,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
34
43
|
},
|
|
35
44
|
})
|
|
36
45
|
let runtime = createRuntime()
|
|
46
|
+
let quotaDisplay: QuotaDisplay =
|
|
47
|
+
envQuotaDisplay ??
|
|
48
|
+
readQuotaDisplayPreference(runtime.status().home) ??
|
|
49
|
+
DEFAULT_QUOTA_DISPLAY
|
|
37
50
|
const models = (): ProviderModelConfig[] =>
|
|
38
51
|
runtime.catalog.list().map((m) => {
|
|
39
52
|
const efforts = runtime.catalog.effortsFor(m.id)
|
|
@@ -100,7 +113,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
100
113
|
if (ctx.hasUI && (explicit || model?.provider === config.provider))
|
|
101
114
|
ctx.ui.setStatus(
|
|
102
115
|
config.provider,
|
|
103
|
-
snapshot
|
|
116
|
+
snapshot
|
|
117
|
+
? formatQuotaStatus(snapshot, model?.id, quotaDisplay)
|
|
118
|
+
: undefined,
|
|
104
119
|
)
|
|
105
120
|
}
|
|
106
121
|
const reset = async () => {
|
|
@@ -127,6 +142,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
127
142
|
updateStatus(ctx, runtime.quota.peek(), false, event.model)
|
|
128
143
|
})
|
|
129
144
|
pi.on('agent_settled', (_event, ctx) => {
|
|
145
|
+
// Pi 1.5.2 AgentSession._emitAgentSettled runs after tools and the run finish.
|
|
146
|
+
runtime.settleSession(ctx.sessionManager.getSessionId())
|
|
130
147
|
if (
|
|
131
148
|
ctx.model?.provider !== config.provider ||
|
|
132
149
|
checkingQuota ||
|
|
@@ -153,8 +170,12 @@ export default function (pi: ExtensionAPI) {
|
|
|
153
170
|
const key = `${quota.group.name}:${quota.bucket.id}:${quota.bucket.window}:${quota.bucket.resetTime || 'none'}:${threshold}`
|
|
154
171
|
if (warned.has(key)) return
|
|
155
172
|
warned.add(key)
|
|
173
|
+
const percent = Math.round(
|
|
174
|
+
displayFraction(quota.fraction, quotaDisplay) * 100,
|
|
175
|
+
)
|
|
176
|
+
const metric = `${percent}% ${quotaDisplay}`
|
|
156
177
|
ctx.ui.notify(
|
|
157
|
-
`Antigravity quota low: ${
|
|
178
|
+
`Antigravity quota low: ${metric} (${quota.group.name}, ${quota.bucket.window}).`,
|
|
158
179
|
'warning',
|
|
159
180
|
)
|
|
160
181
|
})
|
|
@@ -166,23 +187,47 @@ export default function (pi: ExtensionAPI) {
|
|
|
166
187
|
pi.registerCommand('agy-acp', {
|
|
167
188
|
description: 'Antigravity ACP status, quota, or reset',
|
|
168
189
|
getArgumentCompletions: (prefix) => {
|
|
169
|
-
const
|
|
170
|
-
|
|
190
|
+
const normalized = prefix.trimStart()
|
|
191
|
+
const items = [
|
|
192
|
+
'status',
|
|
193
|
+
'quota',
|
|
194
|
+
'quota used',
|
|
195
|
+
'quota remaining',
|
|
196
|
+
'reset',
|
|
197
|
+
]
|
|
198
|
+
.filter((command) => command.startsWith(normalized))
|
|
171
199
|
.map((value) => ({ value, label: value }))
|
|
172
200
|
return items.length > 0 ? items : null
|
|
173
201
|
},
|
|
174
202
|
handler: async (args, ctx) => {
|
|
175
|
-
const
|
|
176
|
-
|
|
203
|
+
const tokens = args.trim().split(/\s+/).filter(Boolean)
|
|
204
|
+
const command = tokens[0] ?? ''
|
|
205
|
+
const requestedDisplay =
|
|
206
|
+
command === 'quota' && tokens.length === 2
|
|
207
|
+
? asQuotaDisplay(tokens[1])
|
|
208
|
+
: undefined
|
|
209
|
+
if (command === 'reset' && tokens.length === 1) {
|
|
177
210
|
clearStatus(ctx)
|
|
178
211
|
await reset()
|
|
179
212
|
ctx.ui.notify('Antigravity ACP sessions reset', 'info')
|
|
180
213
|
return
|
|
181
214
|
}
|
|
182
|
-
|
|
183
|
-
|
|
215
|
+
const isStatus =
|
|
216
|
+
(command === '' || command === 'status') && tokens.length <= 1
|
|
217
|
+
const isQuota =
|
|
218
|
+
command === 'quota' &&
|
|
219
|
+
(tokens.length === 1 || requestedDisplay !== undefined)
|
|
220
|
+
if (!isStatus && !isQuota) {
|
|
221
|
+
ctx.ui.notify(
|
|
222
|
+
'Usage: /agy-acp [status|quota [used|remaining]|reset]',
|
|
223
|
+
'warning',
|
|
224
|
+
)
|
|
184
225
|
return
|
|
185
226
|
}
|
|
227
|
+
if (requestedDisplay !== undefined) {
|
|
228
|
+
quotaDisplay = requestedDisplay
|
|
229
|
+
writeQuotaDisplayPreference(runtime.status().home, quotaDisplay)
|
|
230
|
+
}
|
|
186
231
|
let snapshot: QuotaSnapshot | null = null
|
|
187
232
|
const epoch = uiEpoch
|
|
188
233
|
if (command === 'quota') {
|
|
@@ -205,12 +250,14 @@ export default function (pi: ExtensionAPI) {
|
|
|
205
250
|
)
|
|
206
251
|
: await runtime.readQuota(true)
|
|
207
252
|
if (snapshot === null) {
|
|
253
|
+
if (epoch === uiEpoch)
|
|
254
|
+
updateStatus(ctx, runtime.quota.peek(), true)
|
|
208
255
|
ctx.ui.notify('Quota check cancelled', 'info')
|
|
209
256
|
return
|
|
210
257
|
}
|
|
211
258
|
}
|
|
212
259
|
const notice = snapshot
|
|
213
|
-
? formatQuota(snapshot)
|
|
260
|
+
? formatQuota(snapshot, undefined, quotaDisplay)
|
|
214
261
|
: formatStatus(runtime.status())
|
|
215
262
|
if (epoch === uiEpoch)
|
|
216
263
|
updateStatus(ctx, snapshot ?? runtime.quota.peek(), true)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-agy-acp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Google Antigravity ACP provider extension for Pi Coding Agent",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"NOTICE"
|
|
28
28
|
],
|
|
29
29
|
"engines": {
|
|
30
|
-
"node": ">=22.
|
|
30
|
+
"node": ">=22.19.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@earendil-works/pi-ai": "*",
|
|
@@ -40,7 +40,10 @@
|
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"typescript": "^5.9.0",
|
|
43
|
-
"@types/node": "^22.0.0"
|
|
43
|
+
"@types/node": "^22.0.0",
|
|
44
|
+
"@earendil-works/pi-ai": "~1.5.0",
|
|
45
|
+
"@earendil-works/pi-coding-agent": "~1.5.0",
|
|
46
|
+
"@earendil-works/pi-tui": "~1.5.0"
|
|
44
47
|
},
|
|
45
48
|
"keywords": [
|
|
46
49
|
"pi-package",
|
package/src/acp-process.ts
CHANGED
|
@@ -202,7 +202,9 @@ export class AcpProcess {
|
|
|
202
202
|
|
|
203
203
|
/** Terminate the process. */
|
|
204
204
|
stop(): void {
|
|
205
|
-
|
|
205
|
+
const error = new Error('ACP process stopped')
|
|
206
|
+
this.fail(error)
|
|
207
|
+
this.peer?.close(error)
|
|
206
208
|
this.child?.terminate()
|
|
207
209
|
}
|
|
208
210
|
|
|
@@ -223,7 +225,8 @@ export class AcpProcess {
|
|
|
223
225
|
params,
|
|
224
226
|
{ timeoutMs },
|
|
225
227
|
)
|
|
226
|
-
|
|
228
|
+
// JsonRpcPeer can resolve a buffered reply before stop; leave its rollback to the owner.
|
|
229
|
+
if (this.alive) this.listeners.set(result.sessionId, listener)
|
|
227
230
|
return result
|
|
228
231
|
}
|
|
229
232
|
|
|
@@ -307,6 +310,7 @@ export class AcpProcess {
|
|
|
307
310
|
private fail(error: Error): void {
|
|
308
311
|
if (this.exitError !== undefined) return
|
|
309
312
|
this.exitError = error
|
|
313
|
+
this.listeners.clear()
|
|
310
314
|
for (const listener of this.exitListeners) listener(error)
|
|
311
315
|
}
|
|
312
316
|
|
package/src/config.ts
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mkdirSync,
|
|
3
|
+
readFileSync,
|
|
4
|
+
renameSync,
|
|
5
|
+
unlinkSync,
|
|
6
|
+
writeFileSync,
|
|
7
|
+
} from 'node:fs'
|
|
8
|
+
import { join } from 'node:path'
|
|
9
|
+
|
|
1
10
|
/** Reasoning effort ids accepted by the Antigravity ACP `thought_level` option. */
|
|
2
11
|
export const EFFORTS = ['low', 'medium', 'high'] as const
|
|
3
12
|
/** One Antigravity reasoning effort. */
|
|
4
13
|
export type Effort = (typeof EFFORTS)[number]
|
|
5
14
|
|
|
15
|
+
/** Supported quota percentage display conventions. */
|
|
16
|
+
export const QUOTA_DISPLAY_MODES = ['used', 'remaining'] as const
|
|
17
|
+
/** Quota percentage display convention (`used` counts up from 0%, `remaining` counts down from 100%). */
|
|
18
|
+
export type QuotaDisplay = (typeof QUOTA_DISPLAY_MODES)[number]
|
|
19
|
+
/** Default quota percentage display convention when no env var or saved preference is set. */
|
|
20
|
+
export const DEFAULT_QUOTA_DISPLAY: QuotaDisplay = 'used'
|
|
21
|
+
|
|
6
22
|
/** Validated plugin configuration. */
|
|
7
23
|
export interface Config {
|
|
8
24
|
/** Provider route id shown in the model picker. */
|
|
@@ -45,6 +61,65 @@ export const defaults: Config = {
|
|
|
45
61
|
longDecodeContinuations: 3,
|
|
46
62
|
quotaTtlMs: 120000,
|
|
47
63
|
}
|
|
64
|
+
|
|
48
65
|
export function asEffort(value: string | undefined): Effort | undefined {
|
|
49
66
|
return EFFORTS.includes(value as Effort) ? (value as Effort) : undefined
|
|
50
67
|
}
|
|
68
|
+
|
|
69
|
+
export function asQuotaDisplay(
|
|
70
|
+
value: string | undefined,
|
|
71
|
+
): QuotaDisplay | undefined {
|
|
72
|
+
const normalized = value?.trim().toLowerCase()
|
|
73
|
+
return QUOTA_DISPLAY_MODES.includes(normalized as QuotaDisplay)
|
|
74
|
+
? (normalized as QuotaDisplay)
|
|
75
|
+
: undefined
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const SETTINGS_FILE = 'settings.json'
|
|
79
|
+
|
|
80
|
+
/** Read a JSON file as a plain object, returning `{}` when missing or invalid. */
|
|
81
|
+
export function readJson(path: string): Record<string, unknown> {
|
|
82
|
+
try {
|
|
83
|
+
const parsed: unknown = JSON.parse(readFileSync(path, 'utf8'))
|
|
84
|
+
return parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
85
|
+
? (parsed as Record<string, unknown>)
|
|
86
|
+
: {}
|
|
87
|
+
} catch {
|
|
88
|
+
return {}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Read the last remembered quota display preference from `home/settings.json`. */
|
|
93
|
+
export function readQuotaDisplayPreference(
|
|
94
|
+
home: string,
|
|
95
|
+
): QuotaDisplay | undefined {
|
|
96
|
+
const settings = readJson(join(home, SETTINGS_FILE))
|
|
97
|
+
return typeof settings.quotaDisplay === 'string'
|
|
98
|
+
? asQuotaDisplay(settings.quotaDisplay)
|
|
99
|
+
: undefined
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Persist the user's quota display preference in `home/settings.json`. */
|
|
103
|
+
export function writeQuotaDisplayPreference(
|
|
104
|
+
home: string,
|
|
105
|
+
quotaDisplay: QuotaDisplay,
|
|
106
|
+
): void {
|
|
107
|
+
const path = join(home, SETTINGS_FILE)
|
|
108
|
+
const tempPath = join(
|
|
109
|
+
home,
|
|
110
|
+
`.${SETTINGS_FILE}.${process.pid}.${Date.now()}.tmp`,
|
|
111
|
+
)
|
|
112
|
+
try {
|
|
113
|
+
mkdirSync(home, { recursive: true })
|
|
114
|
+
const existing = readJson(path)
|
|
115
|
+
const content = `${JSON.stringify({ ...existing, quotaDisplay }, null, 2)}\n`
|
|
116
|
+
writeFileSync(tempPath, content)
|
|
117
|
+
renameSync(tempPath, path)
|
|
118
|
+
} catch {
|
|
119
|
+
try {
|
|
120
|
+
unlinkSync(tempPath)
|
|
121
|
+
} catch {
|
|
122
|
+
// Best-effort cleanup.
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|