@benjamolina/pi-antigravity-guard 0.5.1 → 0.6.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/README.md CHANGED
@@ -1,26 +1,36 @@
1
1
  # Pi Antigravity Guard
2
2
 
3
- `@benjamolina/pi-antigravity-guard` is a static Pi extension that registers the text-only `antigravity-guard` provider. It uses Pi-managed OAuth credentials and the existing Antigravity OAuth endpoint and quota path; it does not provide alternate credential routes, quota pools, fallback, or model substitution.
3
+ `@benjamolina/pi-antigravity-guard` is the Pi extension for Antigravity Guard (`antigravity-guard`), powered by `@benjamolina/antigravity-guard-core`. It shares the exact runtime protections and credentials pool used by `@benjamolina/opencode-antigravity-guard`:
4
+
5
+ - **Shared Multi-Account Pool & Cascade Fallback**: Resolves `antigravity-accounts.json` (`AccountStorageV4` with lockfile coordination) and `antigravity.json` across `OPENCODE_CONFIG_DIR`, `~/.config/opencode`, and `~/.pi/agent` (with non-destructive standalone `auth.json` fallback), supporting `hybrid`, `sticky`, and `round-robin` rotation.
6
+ - **Strict Quota Guard & Endpoint Failover**: Enforces soft-quota thresholds with strict reset-time locking, `daily -> autopush -> prod` pre-stream endpoint failover, and `RetryInfo`-aware `429/503/529` backoff retries.
7
+ - **Permissive Tool Schemas & Signature Continuity**: Normalizes rich JSON Schemas (`$ref`, `anyOf`/`oneOf`/`allOf`, `const`, constraints, empty-object placeholders) and persists thinking signatures via `SignatureCache` with `skip_thought_signature_validator` recovery.
8
+ - **Multimodal Inputs & Grounded Search**: Supports images (`image/*`) and PDF documents (`application/pdf`) on Gemini and Claude models, registers the `google_search` grounding tool, auto-injects native Google Search grounding on `-sonar` text turns, and supports opt-in dynamic `model_discovery`.
4
9
 
5
10
  ## Use
6
11
 
7
- Install the package in Pi, then run:
12
+ Install the package in Pi, then authenticate or inspect your pool:
8
13
 
9
14
  ```text
10
15
  /login antigravity-guard
16
+ /antigravity-accounts
17
+ /antigravity-quota
11
18
  ```
12
19
 
13
20
  Choose browser login, or choose manual login and paste the complete callback URL. The loopback callback uses fixed port `51121`; browser callback failures, remote shells, and port conflicts can use the manual callback-URL flow.
14
21
 
15
- ## Text registration is not tool enablement
22
+ ## Catalog and tool admission
16
23
 
17
- All twelve rows below are registered for text. The exact `antigravity-gemini-3.8-flash` `off` route is enabled for tools from recorded direct evidence; every other production route is **not enabled for tools**, so its context with a declaration, assistant tool call, or tool result fails locally before any network request. Text-only requests retain their released behavior.
24
+ All seventeen static catalog rows below are registered with verified routes and tool schemas:
18
25
 
19
26
  | Public ID | Exposed Pi levels | Tool state | Admission |
20
27
  |---|---|---|---|
21
28
  | `antigravity-gemini-3.8-flash` | off, low, medium, high | Enabled (off, low, medium, high) | pi-json-tool-loop/gemini-3.8-flash-off-v1 |
29
+ | `antigravity-gemini-3.8-flash-tiered` | off, low, medium, high | Enabled (off, low, medium, high) | pi-json-tool-loop/gemini-3.8-flash-tiered-off-v1 |
22
30
  | `antigravity-gemini-3.7-flash` | off, low, medium, high | Enabled (off, low, medium, high) | pi-json-tool-loop/gemini-3.7-flash-off-v1 |
31
+ | `antigravity-gemini-3.7-flash-tiered` | off, low, medium, high | Enabled (off, low, medium, high) | pi-json-tool-loop/gemini-3.7-flash-tiered-off-v1 |
23
32
  | `antigravity-gemini-3.6-flash` | off, low, medium, high | Enabled (off, low, medium, high) | pi-json-tool-loop/gemini-3.6-flash-off-v1 |
33
+ | `antigravity-gemini-3.6-flash-tiered` | off, low, medium, high | Enabled (off, low, medium, high) | pi-json-tool-loop/gemini-3.6-flash-tiered-off-v1 |
24
34
  | `antigravity-gemini-3.1-pro` | off, low, high | Enabled (off, low, high) | pi-json-tool-loop/gemini-3.1-pro-off-v1 |
25
35
  | `antigravity-claude-sonnet-4.6` | off, high | Enabled (off, high) | pi-json-tool-loop/claude-sonnet-4.6-off-v1 |
26
36
  | `antigravity-claude-opus-4.6-thinking` | off, high | Enabled (off, high) | pi-json-tool-loop/claude-opus-4.6-thinking-off-v1 |
@@ -29,29 +39,34 @@ All twelve rows below are registered for text. The exact `antigravity-gemini-3.8
29
39
  | `antigravity-gemini-4-carbon` | off, low, medium, high | Enabled (off, low, medium, high) | pi-json-tool-loop/gemini-4-carbon-off-v1 |
30
40
  | `antigravity-gemini-4-neon` | off, low, medium, high, xhigh | Enabled (off, low, medium, high, xhigh) | pi-json-tool-loop/gemini-4-neon-off-v1 |
31
41
  | `antigravity-gemini-4-hydrogen` | off, low, medium, high, xhigh | Enabled (off, low, medium, high, xhigh) | pi-json-tool-loop/gemini-4-hydrogen-off-v1 |
42
+ | `antigravity-gemini-4-hydrogen-tiered` | off, high, xhigh | Enabled (off, high, xhigh) | pi-json-tool-loop/gemini-4-hydrogen-tiered-off-v1 |
43
+ | `antigravity-gemini-4-hydrogen-sonar` | off, high | Enabled (off, high) | pi-json-tool-loop/gemini-4-hydrogen-sonar-off-v1 |
32
44
  | `antigravity-gemini-3.5-flash-lite` | off, low | Enabled (off, low) | pi-json-tool-loop/gemini-3.5-flash-lite-off-v1 |
33
45
 
34
46
  `off` is available for every row even though it is omitted from Pi's level map; omitted reasoning also selects that row's `off` route. Unsupported levels are not advertised and are rejected before transport. `antigravity-gemini-3.5-flash` is not registered or advertised as supported because its recorded HTTP-200 response lacks the strict terminal metadata required for admission. A future `fixture-qualified` route remains disabled for ordinary tool use; only separately authorized direct validation for the exact route may make it enabled.
35
47
 
36
- Claude Sonnet and Claude Opus remain disabled until declaration, call, result replay, thinking-signature, resume, interruption, and continuation evidence is recorded for each exact route. Only Gemini 3.8 Flash `off` is enabled by this package release.
37
-
38
48
  ## Opt-in direct tool-loop validation
39
49
 
40
- Maintainers can run `npm run build:pi` followed by `npx tsx scripts/pi-tool-loop-probe.ts --live --expect-enabled` to verify the directly admitted Gemini 3.8 Flash `off` route. The isolated runner invokes Pi in `--mode json`, passes the deterministic non-terminating `pi_evidence_echo` prompt positionally, drains its event stream, and completes after Pi emits `agent_end` and the child exits. It stores only the passing route and sanitized assertions; it never stores message contents, tool details, names, IDs, arguments, credentials, headers, or raw provider output. Other routes remain fail-closed.
50
+ Maintainers can run `npm run build:pi` followed by `npx tsx scripts/pi-tool-loop-probe.ts --live --expect-enabled` to verify the directly admitted Gemini 3.8 Flash `off` route. The isolated runner invokes Pi in `--mode json`, passes the deterministic non-terminating `pi_evidence_echo` prompt positionally, drains its event stream, and completes after Pi emits `agent_end` and the child exits. It stores only the passing route and sanitized assertions; it never stores message contents, tool details, names, IDs, arguments, credentials, headers, or raw provider output.
51
+
52
+ ## Tool preflight, multimodal, and grounding boundaries
41
53
 
42
- ## Tool preflight boundaries
54
+ Tool-bearing requests are never silently downgraded to text. Declarations are retained in order and omitted or `auto` choice serializes as `AUTO`; explicit `none` serializes as `NONE`. Forced, required, named, unknown, and constrained-sampling choices are rejected before transport.
43
55
 
44
- Tool-bearing requests are never silently downgraded to text. When an exact route is eventually enabled, declarations are retained in order and omitted or `auto` choice serializes as `AUTO`; explicit `none` serializes as `NONE`. Forced, required, named, unknown, and constrained-sampling choices are rejected before transport.
56
+ Gemini routes use the `parametersJsonSchema` profile while Claude and GPT-OSS routes use `claude-custom-parameters`, backed by the shared permissive Antigravity JSON Schema cleaner (resolving local RFC 6901 `#` / `#/...` `$ref` pointers while failing closed on external, cyclic, or unresolved references). Tool results must match the exact call ID and name and are replayed in assistant source-call order; Gemini and Claude routes accept `text`, `image/*`, and `application/pdf` parts (`image`, `document`, or `file` blocks with base64/data-URI payloads), whereas `antigravity-gpt-oss-120b` remains text-only.
45
57
 
46
- Only the evidence-enabled Gemini 3.8 Flash `off` route uses the `parametersJsonSchema` profile. Its hermetically verified preflight preserves ordinary JSON Schema constraints and JSON values in canonical immutable output, including safe local RFC 6901 `$ref` expansion (`#` and `#/...`) with resolved definitions removed. External, malformed, unresolved, cyclic, or otherwise unsafe references fail closed before transport. This is local serialization and safety evidence, not direct live backend acceptance of constrained or reference-based schemas. Tool results must match the exact call ID and name, remain text-only, and are replayed in assistant source-call order; image-bearing or ambiguous results are rejected. A missing persisted result uses the documented failed response only during context reconstruction.
58
+ For live web grounding alongside function declarations, invoke the registered `google_search` tool (which runs a dedicated grounded `v1internal:generateContent` request with `googleSearch` + `urlContext` across the shared account pool and endpoint fallback chain). On `antigravity-gemini-4-hydrogen-sonar` turns without function declarations (and `toolChoice !== "none"`), `{ googleSearch: {} }` is injected automatically and response `groundingMetadata` / `urlContextMetadata` citations are appended to the assistant output.
47
59
 
48
- ## Text catalog limits and safety
60
+ ## Catalog limits and dynamic discovery
49
61
 
50
62
  | Public ID | Exposed Pi levels | Context / output |
51
63
  |---|---|---:|
52
64
  | `antigravity-gemini-3.8-flash` | off, low, medium, high | 1,048,576 / 65,536 |
65
+ | `antigravity-gemini-3.8-flash-tiered` | off, low, medium, high | 1,048,576 / 65,536 |
53
66
  | `antigravity-gemini-3.7-flash` | off, low, medium, high | 1,048,576 / 65,536 |
67
+ | `antigravity-gemini-3.7-flash-tiered` | off, low, medium, high | 1,048,576 / 65,536 |
54
68
  | `antigravity-gemini-3.6-flash` | off, low, medium, high | 1,048,576 / 65,536 |
69
+ | `antigravity-gemini-3.6-flash-tiered` | off, low, medium, high | 1,048,576 / 65,536 |
55
70
  | `antigravity-gemini-3.1-pro` | off, low, high | 1,048,576 / 65,535 |
56
71
  | `antigravity-claude-sonnet-4.6` | off, high | 250,000 / 64,000 |
57
72
  | `antigravity-claude-opus-4.6-thinking` | off, high | 250,000 / 64,000 |
@@ -60,12 +75,13 @@ Only the evidence-enabled Gemini 3.8 Flash `off` route uses the `parametersJsonS
60
75
  | `antigravity-gemini-4-carbon` | off, low, medium, high | 1,048,576 / 262,144 |
61
76
  | `antigravity-gemini-4-neon` | off, low, medium, high, xhigh | 1,048,576 / 262,144 |
62
77
  | `antigravity-gemini-4-hydrogen` | off, low, medium, high, xhigh | 1,048,576 / 262,144 |
78
+ | `antigravity-gemini-4-hydrogen-tiered` | off, high, xhigh | 1,048,576 / 262,144 |
79
+ | `antigravity-gemini-4-hydrogen-sonar` | off, high | 1,048,576 / 262,144 |
63
80
  | `antigravity-gemini-3.5-flash-lite` | off, low | 1,048,576 / 65,535 |
64
81
 
65
82
  An explicit `maxTokens` must be a positive integer no greater than the row's output limit. For a route with a positive finite thinking budget, it must also be greater than that budget. When `maxTokens` is omitted, the provider uses 4,096 unless a larger finite thinking budget needs a 1,024-token answer reserve, always bounded by the row's output limit. Custom `thinkingBudgets` are unsupported and rejected.
66
83
 
67
84
  - Costs are reported as zero because subscription usage is unpriced, not because access is free.
68
- - The catalog is static: it performs no startup or runtime model discovery, catalog synchronization, or dynamic registration.
69
- - It has no account rotation, quota fallback, model substitution, image support, or enabled tools beyond the directly admitted Gemini 3.8 Flash `off` route.
85
+ - Dynamic model discovery via `ProviderConfig.refreshModels` is opt-in in Pi (`"model_discovery": { "enabled": true, "antigravity": true }` in `antigravity.json`), falling back cleanly to the static catalog when disabled, offline (`PI_OFFLINE=1`), or unreachable.
70
86
 
71
- To remove it, disable or uninstall `@benjamolina/pi-antigravity-guard` and reload Pi. Removal does not delete Pi-managed credentials or revoke tokens.
87
+ To remove it, disable or uninstall `@benjamolina/pi-antigravity-guard` and reload Pi. Removal does not delete shared or Pi-managed credentials or revoke tokens.
@@ -0,0 +1,94 @@
1
+ import { AccountManager, type AccountQuotaResult, type ManagedAccount, type ModelFamily, type ResolveSharedGuardPathsOptions, type SharedGuardConfig } from "@benjamolina/antigravity-guard-core";
2
+ import { type StreamTransportError } from "./stream.ts";
3
+ export declare const SHARED_POOL_PLACEHOLDER_ACCESS = "shared-pool-pending-refresh";
4
+ export interface PiAuthJsonEntry {
5
+ type: "oauth";
6
+ refresh: string;
7
+ access: string;
8
+ expires: number;
9
+ projectId?: string;
10
+ email?: string;
11
+ poolSynced?: boolean;
12
+ }
13
+ export declare function resolvePiAuthJsonPath(options?: ResolveSharedGuardPathsOptions): string;
14
+ export declare function readPiAuthEntry(authJsonPath: string): PiAuthJsonEntry | null;
15
+ export declare function seedPiAuthJsonIfMissing(authJsonPath: string, account: ManagedAccount, nowMs?: number): boolean;
16
+ export declare function syncPiAuthJsonWithPool(authJsonPath: string, activeManager: AccountManager): boolean;
17
+ export interface PiAccountPoolOptions extends ResolveSharedGuardPathsOptions {
18
+ fetch?: typeof globalThis.fetch;
19
+ now?: () => number;
20
+ getVersion: () => string;
21
+ getConfig: () => SharedGuardConfig;
22
+ }
23
+ export interface SelectedPoolCredentials {
24
+ account: ManagedAccount;
25
+ accessToken: string;
26
+ projectId: string;
27
+ userAgent: string;
28
+ tokenConsumed?: boolean;
29
+ }
30
+ export interface PiAccountPool {
31
+ getManager(): AccountManager | null;
32
+ hasManagedPoolHistory(): boolean;
33
+ getAccountsPath(): string;
34
+ loadOrRefresh(cwd?: string): Promise<AccountManager>;
35
+ recordLoginAccount(input: {
36
+ refreshToken: string;
37
+ access: string;
38
+ expires: number;
39
+ projectId?: string;
40
+ email?: string;
41
+ }): Promise<void>;
42
+ removeAccountByIndex(index: number, cwd?: string): Promise<{
43
+ manager: AccountManager;
44
+ removed: boolean;
45
+ }>;
46
+ syncAuthAfterAccountToggle(activeManager?: AccountManager): void;
47
+ refreshQuotasLive(input?: {
48
+ cwd?: string;
49
+ fetch?: typeof globalThis.fetch;
50
+ signal?: AbortSignal;
51
+ }): Promise<{
52
+ manager: AccountManager;
53
+ results: AccountQuotaResult[] | null;
54
+ }>;
55
+ resolvePoolUnavailableOutcome(input: {
56
+ modelId: string;
57
+ fetch: typeof globalThis.fetch;
58
+ signal: AbortSignal;
59
+ alreadyWaitedForSoftQuota?: boolean;
60
+ alreadyWaitedForRateLimit?: boolean;
61
+ }): Promise<{
62
+ action: "wait-and-retry";
63
+ waitMs: number;
64
+ kind: "soft-quota" | "rate-limit";
65
+ } | {
66
+ action: "error";
67
+ error: StreamTransportError;
68
+ }>;
69
+ acquireCredentials(input: {
70
+ modelId: string;
71
+ fetch: typeof globalThis.fetch;
72
+ signal: AbortSignal;
73
+ excludeIndices?: ReadonlySet<number>;
74
+ excludeRefreshTokens?: ReadonlySet<string>;
75
+ }): Promise<SelectedPoolCredentials | null>;
76
+ recordSuccess(account: ManagedAccount, fetch?: typeof globalThis.fetch): Promise<void>;
77
+ recordHttpFailure(input: {
78
+ account: ManagedAccount;
79
+ modelId: string;
80
+ status?: number;
81
+ body?: string;
82
+ headers?: Record<string, string>;
83
+ message?: string;
84
+ tokenConsumed?: boolean;
85
+ }): Promise<{
86
+ rotated: boolean;
87
+ quarantined: boolean;
88
+ }>;
89
+ stopBackgroundRefresh(): void;
90
+ }
91
+ export declare function resolvePiModelFamily(modelId: string): ModelFamily;
92
+ export declare function createPiAccountPool(options: PiAccountPoolOptions): PiAccountPool;
93
+ export declare function formatPoolAccountSummary(accounts: readonly ManagedAccount[], accountsPath: string, strategy: string, nowMs?: number): string;
94
+ export declare function formatPoolQuotaSummary(accounts: readonly ManagedAccount[], softThresholdPercent: number, liveResults?: readonly AccountQuotaResult[] | null, nowMs?: number): string;