omp-antigravity-acp-provider 0.1.7 → 0.1.8
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/README.md +48 -9
- package/extension/context-settings.ts +82 -0
- package/extension/context-transfer.ts +19 -13
- package/extension/index.ts +40 -6
- package/extension/runtime.mjs +52 -14
- package/extension/tier-connection.ts +10 -3
- package/package.json +1 -1
- package/scripts/build.mjs +1 -1
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ The repository keeps the OMP adapter sources separately and installs upstream ve
|
|
|
19
19
|
|
|
20
20
|
## Status
|
|
21
21
|
|
|
22
|
-
Version 0.1.
|
|
22
|
+
Version 0.1.8 supports all models advertised by the official ACP server. Tested with macOS, OMP 18.12.3, upstream provider 0.1.15 and official ACP runtime 1.4.1. Other platforms and OMP versions are not yet verified.
|
|
23
23
|
|
|
24
24
|
Google's consumer-plan policies can restrict third-party agent access even through the official CLI or ACP executable. An official transport does not establish permission to use a subscription in OMP. Check the current [Antigravity FAQ](https://www.antigravity.google/docs/faq/) and [terms](https://antigravity.google/terms) for your account.
|
|
25
25
|
|
|
@@ -56,7 +56,7 @@ Or, inside OMP:
|
|
|
56
56
|
|
|
57
57
|
Select **omp-antigravity-acp-provider** in the browser, install it, and restart OMP to load the provider.
|
|
58
58
|
|
|
59
|
-
OMP's marketplace installer currently copies Git content without installing npm dependencies. This marketplace therefore ships a small source launcher that retrieves the exact published **0.1.
|
|
59
|
+
OMP's marketplace installer currently copies Git content without installing npm dependencies. This marketplace therefore ships a small source launcher that retrieves the exact published **0.1.8** prebuilt npm adapter and production dependencies on first load. It disables npm install scripts, skips Pi CLI peer installation, and performs no local compilation. Node.js 22.19+ and npm must be on PATH. First preparation needs internet access and roughly **150 MiB** of disk space; later loads reuse the installed cache without npm network access.
|
|
60
60
|
|
|
61
61
|
The launcher stores its versioned dependencies in `.runtime/` inside the installed marketplace plugin's cache directory. Uninstalling the marketplace plugin removes that cache when it is no longer referenced by another scope. Google credentials and the separately downloaded official ACP runtime are unaffected.
|
|
62
62
|
|
|
@@ -80,7 +80,7 @@ omp plugin install npm:omp-antigravity-acp-provider
|
|
|
80
80
|
To pin a specific release:
|
|
81
81
|
|
|
82
82
|
```sh
|
|
83
|
-
omp plugin install npm:omp-antigravity-acp-provider@0.1.
|
|
83
|
+
omp plugin install npm:omp-antigravity-acp-provider@0.1.8
|
|
84
84
|
```
|
|
85
85
|
|
|
86
86
|
Restart OMP after installation. The npm package includes the built adapter; users do not need esbuild or a manual build step. Disable any older ACP adapter for the same provider before loading this package.
|
|
@@ -149,6 +149,11 @@ After upgrading from an older adapter, run `/antigravity-acp refresh` once to re
|
|
|
149
149
|
| --- | --- |
|
|
150
150
|
| `/antigravity-acp status` | Runtime, confirmed thinking and usage information |
|
|
151
151
|
| `/antigravity-acp usage` | Current ACP context occupancy, accounting source and cache-data availability |
|
|
152
|
+
| `/antigravity-acp usage auto` | Enable supplemental usage queries |
|
|
153
|
+
| `/antigravity-acp usage off` | Skip supplemental queries; preserve context occupancy updates |
|
|
154
|
+
| `/antigravity-acp context` | Show saved settings and effective per-model budgets |
|
|
155
|
+
| `/antigravity-acp context set default KEY NUMBER` | Set a default token or payload setting |
|
|
156
|
+
| `/antigravity-acp context set MODEL KEY NUMBER` | Override one advertised model ID |
|
|
152
157
|
| `/antigravity-acp tools` | Available and omitted OMP tool schemas after a request |
|
|
153
158
|
| `/antigravity-acp refresh` | Explicit network discovery and local catalog refresh |
|
|
154
159
|
| `/antigravity-acp native-tools prefer` | Prefer OMP tools; retain native built-ins (default) |
|
|
@@ -191,7 +196,41 @@ Never include those user data directories, OAuth callback URLs, account identifi
|
|
|
191
196
|
|
|
192
197
|
The adapter now transfers complete replay history within a bounded budget, including historical image attachments. It no longer silently keeps only a 32,000-character history tail. If a transfer does not fit, it stops with an explicit error requesting OMP `/compact` or smaller attachments. This is a local transfer limit, not Antigravity's model context window or its internal compaction threshold. Active requests, history text and system instructions share the text budget; images have a conservative allowance and a separate total payload ceiling of 8 MiB. No automatic summarization or extra inference is added by the transfer layer.
|
|
193
198
|
|
|
194
|
-
The default
|
|
199
|
+
Token budgets and wire payload size are independent; the former 500,000-byte clamp is removed. The default wire payload limit is 16 MiB, configurable up to 128 MiB. Image data additionally defaults to an 8 MiB decoded payload limit. The automatic input-token budget is `contextWindow - maxTokens - reserveTokens`, where reserve defaults to the smaller of 16,384 and 5% of the window. A lightweight Unicode-aware estimate checks serialized text plus approximately 4,096 tokens per image. This is not a Gemini tokenizer, cannot guarantee exact token counts and does not include every hidden server instruction.
|
|
200
|
+
|
|
201
|
+
Persist settings in `~/.omp/agent/antigravity-acp-provider/context.json`, or use the commands below. Defaults apply to every ACP model; entries under `models` override one advertised model ID. Model limits are client metadata and transfer budgets: they do not expand Google's server window or set an unsupported ACP generation-output parameter.
|
|
202
|
+
|
|
203
|
+
```json
|
|
204
|
+
{
|
|
205
|
+
"defaults": {
|
|
206
|
+
"contextWindow": 524288,
|
|
207
|
+
"maxTokens": 32000,
|
|
208
|
+
"reserveTokens": 16384,
|
|
209
|
+
"maxTransferBytes": 16777216,
|
|
210
|
+
"maxImageBytes": 8388608,
|
|
211
|
+
"usageMode": "off"
|
|
212
|
+
},
|
|
213
|
+
"models": {}
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Numeric keys: `contextWindow`, `maxTokens`, `reserveTokens`, `inputTokenBudget`, `maxTransferBytes`, `maxImageBytes`. Omit `inputTokenBudget` to calculate it automatically. A custom input budget must fit alongside output and reserve. Settings load once per process, without disk reads on every streamed chunk. Direct file edits require a restart; commands persist settings and refresh registration in the current process. Restart OMP or reselect the model to refresh displayed metadata. Other OMP processes must restart.
|
|
218
|
+
|
|
219
|
+
```text
|
|
220
|
+
/antigravity-acp context
|
|
221
|
+
/antigravity-acp context set default maxTransferBytes 33554432
|
|
222
|
+
/antigravity-acp context set gemini-4-argon contextWindow 1000000
|
|
223
|
+
/antigravity-acp usage off
|
|
224
|
+
/antigravity-acp usage auto
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
For OMP-managed automatic compaction, keep `compaction.enabled`, `compaction.midTurnEnabled` and `compaction.autoContinue` enabled with a working method such as `soft`. A provider-specific threshold can be set without changing other providers:
|
|
228
|
+
|
|
229
|
+
```sh
|
|
230
|
+
omp config set compaction.modelThresholds '{"antigravity-acp/*":"85%"}'
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Merge that map with existing model-specific entries before running the command. At the example 524,288-token window, 85% triggers at 445,644 tokens, below the automatic transfer estimate budget of 475,904 tokens. OMP can also recover from local context/payload overflow errors. Google independently controls its internal agent summaries. Plugin installation does not automatically change OMP's global compaction configuration.
|
|
195
234
|
|
|
196
235
|
Active sessions are reused. After five idle minutes, the adapter closes its ACP runtime, bridge and child processes; the next request tries to restore the saved server session. Active streams, outstanding ACP prompts, tools and permission waits prevent eviction. No background model prewarming, quota polling or tokenizer model download is performed.
|
|
197
236
|
|
|
@@ -199,21 +238,21 @@ Optional environment settings, applied when OMP starts:
|
|
|
199
238
|
|
|
200
239
|
| Setting | Default | Effect |
|
|
201
240
|
| --- | --- | --- |
|
|
202
|
-
| `OMP_ACP_HISTORY_BYTES` |
|
|
241
|
+
| `OMP_ACP_HISTORY_BYTES` | context.json or 16 MiB | Optional byte-limit override, 64 KiB–128 MiB; independent of token window |
|
|
203
242
|
| `OMP_ACP_IDLE_TIMEOUT_MS` | `300000` | Idle runtime reclamation; `0` disables it, positive values must be at least `1000` |
|
|
204
|
-
| `OMP_ACP_USAGE` |
|
|
243
|
+
| `OMP_ACP_USAGE` | context.json or auto | `off` forces supplemental queries off, including when the saved option is auto |
|
|
205
244
|
|
|
206
|
-
When `/usage` is advertised by the official server, the adapter queries it after each completed ACP prompt and computes a difference from the previous cumulative snapshot. A restored session first establishes a baseline so its old tokens are not charged again. These are main-agent totals and can include multiple internal model calls. Thinking tokens count toward estimated output cost. Queries are bounded by a five-second deadline; unavailable/malformed usage or a counter reset does not turn a successful model answer into a billing claim. Native ACP response usage takes priority when supplied. Query failures can cancel/retire the connection; subsequent work can restore the server session.
|
|
245
|
+
When automatic usage is enabled and `/usage` is advertised by the official server, the adapter queries it after each completed ACP prompt and computes a difference from the previous cumulative snapshot. A restored session first establishes a baseline so its old tokens are not charged again. These are main-agent totals and can include multiple internal model calls. Thinking tokens count toward estimated output cost. Queries are bounded by a five-second deadline; unavailable/malformed usage or a counter reset does not turn a successful model answer into a billing claim. Native ACP response usage takes priority when supplied. Query failures can cancel/retire the connection; subsequent work can restore the server session.
|
|
207
246
|
|
|
208
247
|
ACP `usage_update.used` is passed to OMP separately as `usage.contextTokens`, rather than treating aggregate billable consumption as context occupancy. OMP 18.12.3 recognizes this field; it can still use a local stored-history estimate when deciding whether to compact. Google continues to control its own internal summaries.
|
|
209
248
|
|
|
210
249
|
Stable tool ordering and stable context-resource identifiers avoid unnecessary client-side prefix changes. They do not guarantee implicit cache hits. `/antigravity-acp usage` marks cache information as `unknown` when Google omits it; zero cache fields in OMP's numeric usage structure must not be read as proof of zero backend caching. If cache counts are missing, the API-equivalent estimate prices input as uncached and cannot reflect any unreported cache discount. This is not a subscription bill or a measurement of quota deduction.
|
|
211
250
|
|
|
212
|
-
See the [
|
|
251
|
+
See the [0.1.8 context/compaction and usage benchmark](docs/context-compaction-0.1.8.md) for current settings and measurements. The [0.1.7 report](docs/continuity-performance-0.1.7.md) documents the previous implementation.
|
|
213
252
|
|
|
214
253
|
## Limitations
|
|
215
254
|
|
|
216
|
-
- Argon/Flash
|
|
255
|
+
- Argon/Flash default to client metadata of 1,000,000 context tokens and 65,536 output tokens. These can be overridden in context.json. Other models use conservative defaults of 32,768 context tokens and 8,192 output tokens because the model selector does not supply these limits. These are client metadata, not verified server limits or controls over Antigravity's internal compaction.
|
|
217
256
|
- API background execution and long decode controls are not exposed.
|
|
218
257
|
- The bridge advertises text and image input, not the full Gemini API media surface.
|
|
219
258
|
- Thought summaries appear only if the ACP server emits them. A verified Argon High request returned no `agent_thought_chunk`; plan progress and optional debug tool-status lines can appear in OMP's thinking area.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
export interface ContextOptions {
|
|
5
|
+
contextWindow?: number;
|
|
6
|
+
maxTokens?: number;
|
|
7
|
+
inputTokenBudget?: number;
|
|
8
|
+
reserveTokens?: number;
|
|
9
|
+
maxTransferBytes?: number;
|
|
10
|
+
maxImageBytes?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface ContextSettings {
|
|
13
|
+
defaults: ContextOptions & { usageMode?: "auto" | "off" };
|
|
14
|
+
models: Record<string, ContextOptions>;
|
|
15
|
+
}
|
|
16
|
+
const ranges: Record<keyof ContextOptions, [number, number]> = {
|
|
17
|
+
contextWindow: [4096, 16_777_216], maxTokens: [1, 1_048_576], inputTokenBudget: [1, 16_777_216],
|
|
18
|
+
reserveTokens: [0, 1_048_576], maxTransferBytes: [65_536, 134_217_728], maxImageBytes: [0, 100_663_296],
|
|
19
|
+
};
|
|
20
|
+
function validate(options: any, allowUsage: boolean): void {
|
|
21
|
+
if (!options || typeof options !== "object" || Array.isArray(options)) throw new Error("Context settings must be an object");
|
|
22
|
+
for (const [key, value] of Object.entries(options)) {
|
|
23
|
+
if (key === "usageMode" && allowUsage) {
|
|
24
|
+
if (value !== "auto" && value !== "off") throw new Error("usageMode must be auto or off");
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const range = ranges[key as keyof ContextOptions];
|
|
28
|
+
if (!range || !Number.isSafeInteger(value) || (value as number) < range[0] || (value as number) > range[1]) {
|
|
29
|
+
throw new Error(`Invalid context setting ${key}${range ? `; expected ${range[0]}..${range[1]}` : ""}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function loadContextSettings(file: string): ContextSettings {
|
|
34
|
+
let settings: any;
|
|
35
|
+
try { settings = JSON.parse(fs.readFileSync(file, "utf8")); }
|
|
36
|
+
catch (error: any) { if (error.code === "ENOENT") return { defaults: {}, models: {} }; throw error; }
|
|
37
|
+
if (!settings || Object.keys(settings).some(key => !["defaults", "models"].includes(key))) throw new Error("Invalid context settings file");
|
|
38
|
+
const defaults = settings.defaults ?? {}, models = settings.models ?? {};
|
|
39
|
+
validate(defaults, true);
|
|
40
|
+
if (!models || typeof models !== "object" || Array.isArray(models)) throw new Error("models must be an object");
|
|
41
|
+
for (const [id, options] of Object.entries(models)) {
|
|
42
|
+
if (!id || ["__proto__", "constructor", "prototype"].includes(id)) throw new Error("Invalid model ID");
|
|
43
|
+
validate(options, false);
|
|
44
|
+
}
|
|
45
|
+
return { defaults, models };
|
|
46
|
+
}
|
|
47
|
+
export function saveContextSettings(file: string, settings: ContextSettings) {
|
|
48
|
+
validate(settings.defaults, true);
|
|
49
|
+
for (const options of Object.values(settings.models)) validate(options, false);
|
|
50
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
51
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
52
|
+
fs.writeFileSync(temporary, JSON.stringify(settings, null, 2) + "\n", { mode: 0o600 });
|
|
53
|
+
fs.renameSync(temporary, file);
|
|
54
|
+
}
|
|
55
|
+
export function updateContextSettings(settings: ContextSettings, target: string, key: string, value: number | string): ContextSettings {
|
|
56
|
+
if (["__proto__", "constructor", "prototype"].includes(target)) throw new Error("Invalid model ID");
|
|
57
|
+
const next = structuredClone(settings);
|
|
58
|
+
const options: any = target === "default" ? next.defaults : (next.models[target] ??= {});
|
|
59
|
+
options[key] = value;
|
|
60
|
+
validate(options, target === "default");
|
|
61
|
+
return next;
|
|
62
|
+
}
|
|
63
|
+
export function resolveContextOptions(model: { id: string; contextWindow: number; maxTokens: number }, settings: ContextSettings) {
|
|
64
|
+
const options = { ...settings.defaults, ...settings.models[model.id] };
|
|
65
|
+
const contextWindow = options.contextWindow ?? model.contextWindow;
|
|
66
|
+
const maxTokens = options.maxTokens ?? model.maxTokens;
|
|
67
|
+
const reserveTokens = options.reserveTokens ?? Math.min(16_384, Math.floor(contextWindow * 0.05));
|
|
68
|
+
const automatic = contextWindow - maxTokens - reserveTokens;
|
|
69
|
+
const inputTokenBudget = options.inputTokenBudget ?? automatic;
|
|
70
|
+
if (automatic <= 0 || inputTokenBudget > automatic) throw new Error(`Invalid token budgets for ${model.id}: input + output + reserve must fit contextWindow`);
|
|
71
|
+
return { contextWindow, maxTokens, reserveTokens, inputTokenBudget,
|
|
72
|
+
maxTransferBytes: options.maxTransferBytes ?? 16_777_216,
|
|
73
|
+
maxImageBytes: options.maxImageBytes ?? 8_388_608 };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Lightweight estimate, not a Gemini tokenizer. Do not download tokenizers or
|
|
77
|
+
// confuse payload bytes with tokens. Non-ASCII receives a larger allowance.
|
|
78
|
+
export function estimateTransferTokens(text: string, images = 0) {
|
|
79
|
+
let nonAscii = 0;
|
|
80
|
+
for (let i = 0; i < text.length; i++) if (text.charCodeAt(i) > 127) nonAscii++;
|
|
81
|
+
return Math.ceil((text.length - nonAscii) / 3 + nonAscii * 1.5) + images * 4096;
|
|
82
|
+
}
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
// Adapter-owned context transfer. The pinned upstream dependency stays intact.
|
|
2
2
|
import { getCurrentSystemPrompt } from "@earendil-works/pi-ai/utils/transcript";
|
|
3
|
+
import { estimateTransferTokens, resolveContextOptions, type ContextOptions } from "./context-settings.ts";
|
|
3
4
|
export function currentSystemInstructions(context: any): string {
|
|
4
5
|
const prompt = getCurrentSystemPrompt(context.messages) || context.systemPrompt || "";
|
|
5
|
-
if (Buffer.byteLength(prompt, "utf8") >
|
|
6
|
+
if (Buffer.byteLength(prompt, "utf8") > 134_217_728) throw new Error("OMP system instructions exceed the 128 MiB hard transfer ceiling; reduce them rather than truncating instructions");
|
|
6
7
|
return prompt;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
export function historyBudget(
|
|
10
|
-
const
|
|
11
|
-
if (!Number.isSafeInteger(
|
|
12
|
-
throw new Error("OMP_ACP_HISTORY_BYTES must be an integer between
|
|
10
|
+
export function historyBudget(_contextWindow = 32_768, env = process.env, configured = 16_777_216): number {
|
|
11
|
+
const bytes = Number(env.OMP_ACP_HISTORY_BYTES ?? configured);
|
|
12
|
+
if (!Number.isSafeInteger(bytes) || bytes < 65_536 || bytes > 134_217_728) {
|
|
13
|
+
throw new Error("OMP_ACP_HISTORY_BYTES must be an integer between 65536 and 134217728");
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
const modelBudget = Number.isFinite(contextWindow) && contextWindow > 0 ? Math.floor(contextWindow / 2) : 16_384;
|
|
16
|
-
return Math.min(configured, Math.max(4096, modelBudget));
|
|
15
|
+
return bytes;
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
export function buildPromptParts(context: any, fresh: boolean, unseenStart?: number,
|
|
20
|
-
limits: { contextWindow?: number } = {}) {
|
|
19
|
+
limits: { contextWindow?: number; maxTokens?: number; policy?: ContextOptions } = {}) {
|
|
20
|
+
const options = resolveContextOptions({ id: "transfer", contextWindow: limits.contextWindow ?? 32_768, maxTokens: limits.maxTokens ?? 8192 },
|
|
21
|
+
{ defaults: limits.policy ?? {}, models: {} });
|
|
21
22
|
const messages = context.messages;
|
|
22
23
|
let latest = messages.length - 1;
|
|
23
24
|
while (latest >= 0 && messages[latest].role !== "user") latest--;
|
|
@@ -68,15 +69,20 @@ export function buildPromptParts(context: any, fresh: boolean, unseenStart?: num
|
|
|
68
69
|
// footprint separately, and reserve a conservative text-equivalent allowance.
|
|
69
70
|
let imageBytes = 0;
|
|
70
71
|
let imageCount = 0;
|
|
72
|
+
let imageWireChars = 0;
|
|
71
73
|
const textOnly = prompt.map(block => {
|
|
72
74
|
if (block.type !== "image") return block;
|
|
73
75
|
imageBytes += Math.ceil((block.data?.length ?? 0) * 3 / 4);
|
|
76
|
+
imageWireChars += block.data?.length ?? 0;
|
|
74
77
|
imageCount++;
|
|
75
78
|
return { type: "image", mimeType: block.mimeType };
|
|
76
79
|
});
|
|
77
|
-
if (imageBytes >
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
|
|
80
|
+
if (imageBytes > options.maxImageBytes) throw new Error(`Request payload too large (413): local ACP image budget is ${options.maxImageBytes} bytes; reduce attachments. No images were silently omitted.`);
|
|
81
|
+
const serialized = JSON.stringify(textOnly);
|
|
82
|
+
const bytes = Buffer.byteLength(serialized, "utf8") + imageWireChars + imageCount * 10;
|
|
83
|
+
const budget = historyBudget(undefined, process.env, options.maxTransferBytes);
|
|
84
|
+
if (bytes > budget) throw new Error(`Request payload too large (413): local ACP transfer needs ${bytes} bytes; budget is ${budget}. Use OMP /compact or raise maxTransferBytes. No history was silently truncated.`);
|
|
85
|
+
const estimatedTokens = estimateTransferTokens(serialized, imageCount);
|
|
86
|
+
if (estimatedTokens > options.inputTokenBudget) throw new Error(`Maximum context length exceeded: local ACP estimate is ${estimatedTokens} tokens; input budget is ${options.inputTokenBudget}. Use OMP /compact. This is a heuristic estimate, not a server token count. No history was silently truncated.`);
|
|
81
87
|
return { prompt, messageCount: messages.length };
|
|
82
88
|
}
|
package/extension/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import fs from "node:fs";
|
|
|
7
7
|
import { officialApiCost, applyApiCostEstimate } from "./pricing.ts";
|
|
8
8
|
import { SessionRuntimePool } from "./runtime-pool.ts";
|
|
9
9
|
import { stableTools } from "./tool-order.ts";
|
|
10
|
+
import { loadContextSettings, saveContextSettings, resolveContextOptions, updateContextSettings } from "./context-settings.ts";
|
|
10
11
|
import { EFFORTS, projectCatalog, readModels, selectRuntimeModel } from "./model-catalog.ts";
|
|
11
12
|
import { advertisedRecord, choices, selector } from "./selectors.ts";
|
|
12
13
|
import { TOOL_ROUTING, parseNativeToolMode } from "./tool-routing.ts";
|
|
@@ -34,6 +35,8 @@ export async function registerOmpAdapter(pi: any, stateDir: string) {
|
|
|
34
35
|
const configPath = path.join(stateDir, "config.json");
|
|
35
36
|
const cachePath = path.join(stateDir, "models-cache.json");
|
|
36
37
|
const toolPolicyPath = path.join(stateDir, "omp-tools.json");
|
|
38
|
+
const contextPath = path.join(stateDir, "context.json");
|
|
39
|
+
let contextSettings = loadContextSettings(contextPath);
|
|
37
40
|
// Loading this global extension must not start ACP or query Google.
|
|
38
41
|
let readiness: Promise<void> | undefined;
|
|
39
42
|
function prepareRuntime() {
|
|
@@ -53,7 +56,8 @@ export async function registerOmpAdapter(pi: any, stateDir: string) {
|
|
|
53
56
|
const ownedConnections = new Set<any>();
|
|
54
57
|
const runtime = new AntigravityRuntime((options: any) => {
|
|
55
58
|
const policy = loadToolPolicy(toolPolicyPath);
|
|
56
|
-
const connection = new TierConnection({ ...options, ompNativeTools: policy.nativeTools, ompDebugToolUpdates: policy.debugToolUpdates
|
|
59
|
+
const connection = new TierConnection({ ...options, ompNativeTools: policy.nativeTools, ompDebugToolUpdates: policy.debugToolUpdates,
|
|
60
|
+
ompUsageMode: contextSettings.defaults.usageMode ?? "auto" });
|
|
57
61
|
connections.add(connection);
|
|
58
62
|
ownedConnections.add(connection);
|
|
59
63
|
void connection.process.exited.finally(() => connections.delete(connection));
|
|
@@ -90,9 +94,35 @@ export async function registerOmpAdapter(pi: any, stateDir: string) {
|
|
|
90
94
|
},
|
|
91
95
|
});
|
|
92
96
|
pi.registerCommand("antigravity-acp", {
|
|
93
|
-
description: "Inspect ACP status/tools/usage, toggle debug
|
|
97
|
+
description: "Inspect ACP status/tools/usage/context, configure budgets, toggle debug, refresh models or set tool policies",
|
|
94
98
|
async handler(args: string, ctx: any) {
|
|
95
|
-
const
|
|
99
|
+
const parts = args.trim().split(/\s+/);
|
|
100
|
+
const [command, value] = parts;
|
|
101
|
+
if (command === "context") {
|
|
102
|
+
if (value === "set") {
|
|
103
|
+
const [, , target, key, raw] = parts;
|
|
104
|
+
if (parts.length !== 5) throw new Error("Usage: /antigravity-acp context set default|MODEL KEY NUMBER");
|
|
105
|
+
const next = updateContextSettings(contextSettings, target, key, key === "usageMode" ? raw : Number(raw));
|
|
106
|
+
for (const model of initialModels) resolveContextOptions(model, next);
|
|
107
|
+
saveContextSettings(contextPath, next);
|
|
108
|
+
contextSettings = next;
|
|
109
|
+
if (key === "usageMode") for (const connection of connections) connection.configureUsage(raw as "auto" | "off");
|
|
110
|
+
initialModels = catalog(initialModels);
|
|
111
|
+
adapted.registerProvider();
|
|
112
|
+
ctx.ui.notify("ACP context settings saved. Restart OMP or reselect the model to refresh its displayed limits.", "info");
|
|
113
|
+
} else if (value) throw new Error("Usage: /antigravity-acp context [set default|MODEL KEY NUMBER]");
|
|
114
|
+
else ctx.ui.notify(JSON.stringify({ file: contextPath, settings: contextSettings,
|
|
115
|
+
effective: initialModels.map((model: any) => ({ id: model.id, ...resolveContextOptions(model, contextSettings) })) }, null, 2), "info");
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (command === "usage" && value) {
|
|
119
|
+
if (value !== "auto" && value !== "off") throw new Error("Usage: /antigravity-acp usage [auto|off]");
|
|
120
|
+
contextSettings = updateContextSettings(contextSettings, "default", "usageMode", value);
|
|
121
|
+
saveContextSettings(contextPath, contextSettings);
|
|
122
|
+
for (const connection of connections) connection.configureUsage(value);
|
|
123
|
+
ctx.ui.notify(`Supplemental ACP usage queries: ${value}${process.env.OMP_ACP_USAGE === "off" ? " (environment override keeps queries off)" : ""}. Context occupancy updates remain enabled.`, "info");
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
96
126
|
if (command === "debug") {
|
|
97
127
|
if (value !== "on" && value !== "off") throw new Error("Usage: /antigravity-acp debug on|off");
|
|
98
128
|
const enabled = value === "on";
|
|
@@ -110,11 +140,13 @@ export async function registerOmpAdapter(pi: any, stateDir: string) {
|
|
|
110
140
|
}
|
|
111
141
|
const { runtime } = runtimes.get(sessionIdOf(ctx));
|
|
112
142
|
if (command === "usage") {
|
|
113
|
-
ctx.ui.notify(JSON.stringify(
|
|
143
|
+
ctx.ui.notify(JSON.stringify({ configured: contextSettings.defaults.usageMode ?? "auto",
|
|
144
|
+
effective: process.env.OMP_ACP_USAGE === "off" ? "off" : contextSettings.defaults.usageMode ?? "auto",
|
|
145
|
+
connections: [...connections].map(connection => ({
|
|
114
146
|
context: [...connection.contextUsage.values()],
|
|
115
147
|
accounting: [...connection.usageStatus.values()],
|
|
116
148
|
activePrompts: connection.activePrompts,
|
|
117
|
-
})), null, 2), "info");
|
|
149
|
+
})) }, null, 2), "info");
|
|
118
150
|
return;
|
|
119
151
|
}
|
|
120
152
|
if (command === "refresh") {
|
|
@@ -141,7 +173,9 @@ export async function registerOmpAdapter(pi: any, stateDir: string) {
|
|
|
141
173
|
const upstreamModels = new Map<string, any>();
|
|
142
174
|
function catalog(models: any[]) {
|
|
143
175
|
return models.map(source => {
|
|
144
|
-
const
|
|
176
|
+
const limits = resolveContextOptions(source, contextSettings);
|
|
177
|
+
const model = { ...source, contextWindow: limits.contextWindow, maxTokens: limits.maxTokens,
|
|
178
|
+
ompContextPolicy: limits, cost: officialApiCost(source.id) ?? source.cost };
|
|
145
179
|
const efforts = EFFORTS.filter(effort => model.thinkingLevelMap?.[effort]);
|
|
146
180
|
if (efforts.length && !model.thinking) {
|
|
147
181
|
model.thinking = { mode: "effort", efforts, defaultLevel: efforts.includes("high") ? "high" : efforts[0] };
|
package/extension/runtime.mjs
CHANGED
|
@@ -59055,21 +59055,48 @@ function toolError(text) {
|
|
|
59055
59055
|
return { content: [{ type: "text", text }], isError: true };
|
|
59056
59056
|
}
|
|
59057
59057
|
|
|
59058
|
+
// extension/context-settings.ts
|
|
59059
|
+
function resolveContextOptions(model, settings2) {
|
|
59060
|
+
const options = { ...settings2.defaults, ...settings2.models[model.id] };
|
|
59061
|
+
const contextWindow = options.contextWindow ?? model.contextWindow;
|
|
59062
|
+
const maxTokens = options.maxTokens ?? model.maxTokens;
|
|
59063
|
+
const reserveTokens = options.reserveTokens ?? Math.min(16384, Math.floor(contextWindow * 0.05));
|
|
59064
|
+
const automatic = contextWindow - maxTokens - reserveTokens;
|
|
59065
|
+
const inputTokenBudget = options.inputTokenBudget ?? automatic;
|
|
59066
|
+
if (automatic <= 0 || inputTokenBudget > automatic) throw new Error(`Invalid token budgets for ${model.id}: input + output + reserve must fit contextWindow`);
|
|
59067
|
+
return {
|
|
59068
|
+
contextWindow,
|
|
59069
|
+
maxTokens,
|
|
59070
|
+
reserveTokens,
|
|
59071
|
+
inputTokenBudget,
|
|
59072
|
+
maxTransferBytes: options.maxTransferBytes ?? 16777216,
|
|
59073
|
+
maxImageBytes: options.maxImageBytes ?? 8388608
|
|
59074
|
+
};
|
|
59075
|
+
}
|
|
59076
|
+
function estimateTransferTokens(text, images = 0) {
|
|
59077
|
+
let nonAscii = 0;
|
|
59078
|
+
for (let i = 0; i < text.length; i++) if (text.charCodeAt(i) > 127) nonAscii++;
|
|
59079
|
+
return Math.ceil((text.length - nonAscii) / 3 + nonAscii * 1.5) + images * 4096;
|
|
59080
|
+
}
|
|
59081
|
+
|
|
59058
59082
|
// extension/context-transfer.ts
|
|
59059
59083
|
function currentSystemInstructions(context) {
|
|
59060
59084
|
const prompt = getCurrentSystemPrompt(context.messages) || context.systemPrompt || "";
|
|
59061
|
-
if (Buffer.byteLength(prompt, "utf8") >
|
|
59085
|
+
if (Buffer.byteLength(prompt, "utf8") > 134217728) throw new Error("OMP system instructions exceed the 128 MiB hard transfer ceiling; reduce them rather than truncating instructions");
|
|
59062
59086
|
return prompt;
|
|
59063
59087
|
}
|
|
59064
|
-
function historyBudget(
|
|
59065
|
-
const
|
|
59066
|
-
if (!Number.isSafeInteger(
|
|
59067
|
-
throw new Error("OMP_ACP_HISTORY_BYTES must be an integer between
|
|
59088
|
+
function historyBudget(_contextWindow = 32768, env2 = process.env, configured = 16777216) {
|
|
59089
|
+
const bytes = Number(env2.OMP_ACP_HISTORY_BYTES ?? configured);
|
|
59090
|
+
if (!Number.isSafeInteger(bytes) || bytes < 65536 || bytes > 134217728) {
|
|
59091
|
+
throw new Error("OMP_ACP_HISTORY_BYTES must be an integer between 65536 and 134217728");
|
|
59068
59092
|
}
|
|
59069
|
-
|
|
59070
|
-
return Math.min(configured, Math.max(4096, modelBudget));
|
|
59093
|
+
return bytes;
|
|
59071
59094
|
}
|
|
59072
59095
|
function buildPromptParts(context, fresh, unseenStart, limits = {}) {
|
|
59096
|
+
const options = resolveContextOptions(
|
|
59097
|
+
{ id: "transfer", contextWindow: limits.contextWindow ?? 32768, maxTokens: limits.maxTokens ?? 8192 },
|
|
59098
|
+
{ defaults: limits.policy ?? {}, models: {} }
|
|
59099
|
+
);
|
|
59073
59100
|
const messages = context.messages;
|
|
59074
59101
|
let latest = messages.length - 1;
|
|
59075
59102
|
while (latest >= 0 && messages[latest].role !== "user") latest--;
|
|
@@ -59120,16 +59147,21 @@ ${instructions}`
|
|
|
59120
59147
|
}
|
|
59121
59148
|
let imageBytes = 0;
|
|
59122
59149
|
let imageCount = 0;
|
|
59150
|
+
let imageWireChars = 0;
|
|
59123
59151
|
const textOnly = prompt.map((block) => {
|
|
59124
59152
|
if (block.type !== "image") return block;
|
|
59125
59153
|
imageBytes += Math.ceil((block.data?.length ?? 0) * 3 / 4);
|
|
59154
|
+
imageWireChars += block.data?.length ?? 0;
|
|
59126
59155
|
imageCount++;
|
|
59127
59156
|
return { type: "image", mimeType: block.mimeType };
|
|
59128
59157
|
});
|
|
59129
|
-
if (imageBytes >
|
|
59130
|
-
const
|
|
59131
|
-
const
|
|
59132
|
-
|
|
59158
|
+
if (imageBytes > options.maxImageBytes) throw new Error(`Request payload too large (413): local ACP image budget is ${options.maxImageBytes} bytes; reduce attachments. No images were silently omitted.`);
|
|
59159
|
+
const serialized = JSON.stringify(textOnly);
|
|
59160
|
+
const bytes = Buffer.byteLength(serialized, "utf8") + imageWireChars + imageCount * 10;
|
|
59161
|
+
const budget = historyBudget(void 0, process.env, options.maxTransferBytes);
|
|
59162
|
+
if (bytes > budget) throw new Error(`Request payload too large (413): local ACP transfer needs ${bytes} bytes; budget is ${budget}. Use OMP /compact or raise maxTransferBytes. No history was silently truncated.`);
|
|
59163
|
+
const estimatedTokens = estimateTransferTokens(serialized, imageCount);
|
|
59164
|
+
if (estimatedTokens > options.inputTokenBudget) throw new Error(`Maximum context length exceeded: local ACP estimate is ${estimatedTokens} tokens; input budget is ${options.inputTokenBudget}. Use OMP /compact. This is a heuristic estimate, not a server token count. No history was silently truncated.`);
|
|
59133
59165
|
return { prompt, messageCount: messages.length };
|
|
59134
59166
|
}
|
|
59135
59167
|
|
|
@@ -59687,7 +59719,7 @@ var AntigravityRuntime = class {
|
|
|
59687
59719
|
unseenStart += 1;
|
|
59688
59720
|
}
|
|
59689
59721
|
const parts = adaptPromptToCapabilities(
|
|
59690
|
-
buildPromptParts(context, fresh, unseenStart, { contextWindow: model.contextWindow }),
|
|
59722
|
+
buildPromptParts(context, fresh, unseenStart, { contextWindow: model.contextWindow, maxTokens: model.maxTokens, policy: model.ompContextPolicy }),
|
|
59691
59723
|
binding.initialize
|
|
59692
59724
|
);
|
|
59693
59725
|
await this.modeChanges;
|
|
@@ -60438,6 +60470,7 @@ var TierConnection = class extends AntigravityAcpConnection {
|
|
|
60438
60470
|
activePrompts = 0;
|
|
60439
60471
|
usageQueryCount = 0;
|
|
60440
60472
|
usageQueryMs = 0;
|
|
60473
|
+
usageMode = "auto";
|
|
60441
60474
|
contextUsage = /* @__PURE__ */ new Map();
|
|
60442
60475
|
usageStatus = /* @__PURE__ */ new Map();
|
|
60443
60476
|
usageBaselines = /* @__PURE__ */ new Map();
|
|
@@ -60447,6 +60480,7 @@ var TierConnection = class extends AntigravityAcpConnection {
|
|
|
60447
60480
|
constructor(options) {
|
|
60448
60481
|
super(options);
|
|
60449
60482
|
this.debugToolUpdates = options.ompDebugToolUpdates ?? false;
|
|
60483
|
+
this.usageMode = options.ompUsageMode ?? "auto";
|
|
60450
60484
|
this.setHandlers({ ...options.handlers, onUpdate: async (notification) => {
|
|
60451
60485
|
const update = notification.update;
|
|
60452
60486
|
if (update.sessionUpdate === "available_commands_update") {
|
|
@@ -60469,6 +60503,10 @@ var TierConnection = class extends AntigravityAcpConnection {
|
|
|
60469
60503
|
});
|
|
60470
60504
|
}
|
|
60471
60505
|
}
|
|
60506
|
+
configureUsage(mode) {
|
|
60507
|
+
this.usageMode = mode;
|
|
60508
|
+
this.usageBaselines.clear();
|
|
60509
|
+
}
|
|
60472
60510
|
async newSession(...args) {
|
|
60473
60511
|
const session = await super.newSession(...args);
|
|
60474
60512
|
this.usageBaselines.set(session.sessionId, { input: 0, completion: 0, thinking: 0, cached: 0, total: 0 });
|
|
@@ -60495,7 +60533,7 @@ var TierConnection = class extends AntigravityAcpConnection {
|
|
|
60495
60533
|
this.activePrompts++;
|
|
60496
60534
|
const id = request.sessionId;
|
|
60497
60535
|
try {
|
|
60498
|
-
const queryUsage = process.env.OMP_ACP_USAGE !== "off" && this.usageCommands.has(id);
|
|
60536
|
+
const queryUsage = process.env.OMP_ACP_USAGE !== "off" && this.usageMode !== "off" && this.usageCommands.has(id);
|
|
60499
60537
|
if (queryUsage && !this.usageBaselines.has(id)) {
|
|
60500
60538
|
try {
|
|
60501
60539
|
const baseline = await this.readUsage(id, signal);
|
|
@@ -60508,7 +60546,7 @@ var TierConnection = class extends AntigravityAcpConnection {
|
|
|
60508
60546
|
const context = this.contextUsage.get(id);
|
|
60509
60547
|
return context ? { ...value, _meta: { ...value._meta, ompContextTokens: context.used } } : value;
|
|
60510
60548
|
};
|
|
60511
|
-
if (response.usage || process.env.OMP_ACP_USAGE === "off" || !this.usageCommands.has(id) || signal?.aborted) {
|
|
60549
|
+
if (response.usage || process.env.OMP_ACP_USAGE === "off" || this.usageMode === "off" || !this.usageCommands.has(id) || signal?.aborted) {
|
|
60512
60550
|
this.usageBaselines.delete(id);
|
|
60513
60551
|
this.usageStatus.set(id, { source: response.usage ? "ACP response" : "unavailable", cache: "unknown" });
|
|
60514
60552
|
return withContext(response);
|
|
@@ -12,6 +12,7 @@ export class TierConnection extends AntigravityAcpConnection {
|
|
|
12
12
|
activePrompts = 0;
|
|
13
13
|
usageQueryCount = 0;
|
|
14
14
|
usageQueryMs = 0;
|
|
15
|
+
usageMode: "auto" | "off" = "auto";
|
|
15
16
|
readonly contextUsage = new Map<string, { used: number; size: number }>();
|
|
16
17
|
readonly usageStatus = new Map<string, { source: string; cache: string; error?: string }>();
|
|
17
18
|
private readonly usageBaselines = new Map<string, SessionUsage>();
|
|
@@ -19,9 +20,10 @@ export class TierConnection extends AntigravityAcpConnection {
|
|
|
19
20
|
private readonly usageCommands = new Set<string>();
|
|
20
21
|
toolRouting: { nativeTools: NativeToolMode; channel: "pending" | "system-append" | "legacy-prompt" } | undefined;
|
|
21
22
|
|
|
22
|
-
constructor(options: ConstructorParameters<typeof AntigravityAcpConnection>[0] & { ompNativeTools?: NativeToolMode; ompDebugToolUpdates?: boolean }) {
|
|
23
|
+
constructor(options: ConstructorParameters<typeof AntigravityAcpConnection>[0] & { ompNativeTools?: NativeToolMode; ompDebugToolUpdates?: boolean; ompUsageMode?: "auto" | "off" }) {
|
|
23
24
|
super(options);
|
|
24
25
|
this.debugToolUpdates = options.ompDebugToolUpdates ?? false;
|
|
26
|
+
this.usageMode = options.ompUsageMode ?? "auto";
|
|
25
27
|
this.setHandlers({ ...options.handlers, onUpdate: async notification => {
|
|
26
28
|
const update: any = notification.update;
|
|
27
29
|
if (update.sessionUpdate === "available_commands_update") {
|
|
@@ -45,6 +47,11 @@ export class TierConnection extends AntigravityAcpConnection {
|
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
|
|
50
|
+
configureUsage(mode: "auto" | "off") {
|
|
51
|
+
this.usageMode = mode;
|
|
52
|
+
this.usageBaselines.clear();
|
|
53
|
+
}
|
|
54
|
+
|
|
48
55
|
override async newSession(...args: Parameters<AntigravityAcpConnection["newSession"]>) {
|
|
49
56
|
const session = await super.newSession(...args);
|
|
50
57
|
this.usageBaselines.set(session.sessionId, { input: 0, completion: 0, thinking: 0, cached: 0, total: 0 });
|
|
@@ -68,7 +75,7 @@ export class TierConnection extends AntigravityAcpConnection {
|
|
|
68
75
|
this.activePrompts++;
|
|
69
76
|
const id = request.sessionId;
|
|
70
77
|
try {
|
|
71
|
-
const queryUsage = process.env.OMP_ACP_USAGE !== "off" && this.usageCommands.has(id);
|
|
78
|
+
const queryUsage = process.env.OMP_ACP_USAGE !== "off" && this.usageMode !== "off" && this.usageCommands.has(id);
|
|
72
79
|
if (queryUsage && !this.usageBaselines.has(id)) {
|
|
73
80
|
try {
|
|
74
81
|
const baseline = await this.readUsage(id, signal);
|
|
@@ -80,7 +87,7 @@ export class TierConnection extends AntigravityAcpConnection {
|
|
|
80
87
|
const context = this.contextUsage.get(id);
|
|
81
88
|
return context ? { ...value, _meta: { ...value._meta, ompContextTokens: context.used } } : value;
|
|
82
89
|
};
|
|
83
|
-
if (response.usage || process.env.OMP_ACP_USAGE === "off" || !this.usageCommands.has(id) || signal?.aborted) {
|
|
90
|
+
if (response.usage || process.env.OMP_ACP_USAGE === "off" || this.usageMode === "off" || !this.usageCommands.has(id) || signal?.aborted) {
|
|
84
91
|
this.usageBaselines.delete(id);
|
|
85
92
|
this.usageStatus.set(id, { source: response.usage ? "ACP response" : "unavailable", cache: "unknown" });
|
|
86
93
|
return withContext(response);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omp-antigravity-acp-provider",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Google Antigravity ACP provider for Oh My Pi (OMP), with tool bridging and per-model thinking; derived from zacbemis/pi-antigravity-acp-provider",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/scripts/build.mjs
CHANGED
|
@@ -59,7 +59,7 @@ const result = await build({
|
|
|
59
59
|
if (source.split(marker).length !== 2) throw new Error("Pinned upstream context seam changed; review compatibility");
|
|
60
60
|
const retirement = "if (!persistent) await this.dropBinding(key, binding);";
|
|
61
61
|
if (source.split(retirement).length !== 2) throw new Error("Pinned upstream connection retirement seam changed; review compatibility");
|
|
62
|
-
return { contents: source.replace(marker, "buildPromptParts(context, fresh, unseenStart, { contextWindow: model.contextWindow })")
|
|
62
|
+
return { contents: source.replace(marker, "buildPromptParts(context, fresh, unseenStart, { contextWindow: model.contextWindow, maxTokens: model.maxTokens, policy: model.ompContextPolicy })")
|
|
63
63
|
.replace(retirement, "if (!persistent || !binding.connection.process.alive) await this.dropBinding(key, binding);"), loader: "ts" };
|
|
64
64
|
});
|
|
65
65
|
builder.onLoad({ filter: /\/(?:process|runtime-manifest)\.ts$/ }, async ({ path: file }) => {
|