omp-antigravity-acp-provider 0.3.1 → 0.3.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/README.md CHANGED
@@ -14,6 +14,8 @@ Google Antigravity's official ACP server, adapted for **Oh My Pi (OMP)**.
14
14
 
15
15
  This is an independent adaptation, **NOT** an official Google or OMP integration. It uses ACP over stdio. The local HTTP MCP bridge carries tool calls; it is not a model API reverse proxy.
16
16
 
17
+ > **Warning.** Use this adapter at your own risk. It is an independent, unofficial integration, not affiliated with or endorsed by Google or OMP. It can change or lose data, consume account quota, and break when upstream services change. Review the code and your account policies before using it in production.
18
+
17
19
  This plugin registers the OMP provider and API name `antigravity-acp-provider`. OMP 18.20+ reserves `antigravity-acp` for its built-in Antigravity provider, so the two can be installed side by side. Select this adapter's models as `antigravity-acp-provider/<model-id>`.
18
20
 
19
21
  ## Features
@@ -21,12 +23,12 @@ This plugin registers the OMP provider and API name `antigravity-acp-provider`.
21
23
  - All server-advertised models, including Claude, GPT-OSS and future IDs when the ACP endpoint advertises them.
22
24
  - CLI-first selection. When a usable `agy` CLI is on `PATH`, the adapter launches it through a generated `AGY_ACP_BIN` wrapper. The managed runtime is the fallback. An explicit `AGY_ACP_BIN` always wins.
23
25
  - Per-model thinking levels, exposed only when the server confirms them. The offline catalog includes Gemini 4 Hydrogen through `xhigh` and known partner models; the first inference after an empty cache attempts real server discovery.
24
- - OMP tools through an authenticated loopback MCP bridge.
26
+ - OMP tools through an authenticated loopback MCP bridge, exposed to ACP as `omp_*` names.
25
27
  - ACP-native tools are disabled by default for strict OMP-only sessions; `/antigravity-acp native-tools prefer` restores them.
26
28
  - Standby ACP initialization coordinated with discovery, plus warm session reuse and guarded oldest-image history continuity.
27
29
  - `/login` plus `/antigravity-acp` account, usage and cleanup commands.
28
30
  - API-equivalent cost estimates from a model-ID rate table, not subscription billing. Native response usage takes precedence, with a read-only SQLite fallback for completed model steps when no supplemental usage query runs.
29
- - Long-running OMP tools survive the MCP request window through a relay. The model resumes the same result with `pi_omp_await_result`; the control tool is a separate MCP server and never appears in OMP's tool list.
31
+ - Long-running OMP tools survive the MCP request window through a relay. The model resumes the same result with `omp_await_result`; the control tool is a separate MCP server and never appears in OMP's tool list.
30
32
  - Permission requests are tied to the originating session, turn and tool call. Forged, conflicting or previous-turn identities fail closed, while normal requests still use OMP's human review.
31
33
  - The MCP `tools/list` reflects the current OMP tool set. The offline wire test covers add, remove and restore on one warm ACP session.
32
34
  - Tool-argument hardening on the MCP bridge. Habitual alias mistakes such as `path` for `file_path` are corrected only when the tool schema makes the mapping unambiguous, and rejected calls return the missing required keys plus the tool's expected signature instead of a bare schema failure.
@@ -99,7 +101,7 @@ Run `/login`, choose **Google Antigravity (ACP)**, and complete Google's consent
99
101
  /model
100
102
  ```
101
103
 
102
- `refresh` asks the ACP server which models the account can use; `/model` lists them. Set an effort with OMP's thinking control when the model advertises levels. If OMP's `enabledModels` whitelist is configured, add `antigravity-acp-provider/*` to it.
104
+ `refresh` asks the ACP server which models the account can use; `/model` lists them. Set an effort with OMP's thinking control when the model advertises levels. When OMP already has a non-empty `enabledModels` whitelist, `refresh` adds `antigravity-acp-provider/*` to it automatically, so restart OMP or reopen `/model` if the picker was already open. No whitelist is created when none exists.
103
105
 
104
106
  ### 6. Verify
105
107
 
@@ -122,12 +124,12 @@ To remove the installed plugin, use `omp plugin uninstall omp-antigravity-acp-pr
122
124
  | Symptom | Check |
123
125
  | --- | --- |
124
126
  | `omp: command not found` | This is an OMP plugin. Install OMP first; there is no standalone CLI. |
125
- | No models after `/antigravity-acp refresh` | Run `/antigravity-acp account` to confirm both sides are signed in, then retry with internet access. ACP can advertise fewer models than the Antigravity app. |
127
+ | No models after `/antigravity-acp refresh` | Run `/antigravity-acp account` to confirm both sides are signed in, then retry with internet access. ACP can advertise fewer models than the Antigravity app. If OMP has an `enabledModels` whitelist, refresh adds `antigravity-acp-provider/*` to it; restart OMP or reopen `/model` when the picker was already open. |
126
128
  | Two Antigravity providers appear | That is expected on OMP 18.20+: the built-in `antigravity-acp` provider and this plugin's `antigravity-acp-provider` coexist. Remove only a second copy of this adapter (`antigravity-acp-omp`, the upstream Pi extension, or a duplicate npm install), then restart OMP. |
127
129
  | Login opens the wrong Google account | Both login paths always start a fresh sign-in. Choose the intended account (or "Use another account") on Google's consent screen. |
128
130
  | Default `disabled` native-tool mode rejects the session | The official runtime must advertise system-append support (1.4.1+). Upgrade the runtime or run `/antigravity-acp native-tools prefer`. |
129
131
  | The first request is slow | Runtime download and cold ACP start happen once; later turns reuse the warm session. |
130
- | A tool call returns a relay notice | The model should call `pi_omp_await_result` with the notice's `call_id`. Lower `OMP_ACP_TOOL_RELAY_MS` or set it to `0` to disable relay. |
132
+ | A tool call returns a relay notice | The model should call `omp_await_result` with the notice's `call_id`. Lower `OMP_ACP_TOOL_RELAY_MS` or set it to `0` to disable relay. |
131
133
 
132
134
  ## Install: for agents
133
135
 
@@ -182,7 +184,7 @@ Create or edit `~/.omp/agent/antigravity-acp-provider/config.json`:
182
184
 
183
185
  A pinned source never falls back to the other channel and never downloads it. An explicit non-wrapper `AGY_ACP_BIN` still wins over this setting. If `PI_CODING_AGENT_DIR` is set, use its actual path for `config.json`. Other `runtimeSource` values fail provider startup.
184
186
 
185
- Session storage follows the server's own `--app_data_dir`. The generated wrapper pins `antigravity-acp` — the managed runtime's own default — so CLI-launched ACP sessions land in `~/.gemini/antigravity-acp/`, where `/antigravity-acp cleanup` and session ownership tracking operate. Personal `agy` CLI chats stay in `~/.gemini/antigravity-cli/` and are never read or deleted by the adapter. `GEMINI_HOME` relocates the managed runtime's tree (upstream behavior); the `agy` CLI stores under `~/.gemini` regardless.
187
+ Session storage follows the server's own `--app_data_dir`. The generated wrapper pins `antigravity-acp` — the managed runtime's own default — so CLI-launched ACP sessions land in `~/.gemini/antigravity-acp/`, where `/antigravity-acp cleanup` and session ownership tracking operate. Personal `agy` CLI chats stay in `~/.gemini/antigravity-cli/` and are never read or deleted by the adapter. `GEMINI_HOME` relocates the adapter's ACP tree and the token-sync source; the personal `agy` CLI store remains under `~/.gemini` and its token is never copied into an isolated tree. A logout marker blocks later CLI-token sync until a fresh sign-in.
186
188
 
187
189
  The active channel and its versions are recorded in `~/.omp/agent/antigravity-acp-provider/acp-runtime-source.json` whenever the CLI is chosen.
188
190
 
@@ -270,7 +272,7 @@ Inference and `/antigravity-acp refresh` refuse to start ACP when no local Googl
270
272
 
271
273
  ## Long tools and relay
272
274
 
273
- A tool call that outlives `OMP_ACP_TOOL_RELAY_MS` (default 85000, `0` disables, otherwise 5000 through 165000) returns a relay notice instead of holding the MCP request open. The model calls `pi_omp_await_result` with the notice's `call_id`; the adapter returns the same original result, not a second execution. The control tool is a separate MCP server and is not added to OMP's tool list. If the ACP turn ends before the result arrives, the adapter retries the same result in a fresh ACP turn; it never delivers a stale result to a new writer.
275
+ A tool call that outlives `OMP_ACP_TOOL_RELAY_MS` (default 85000, `0` disables, otherwise 5000 through 165000) returns a relay notice instead of holding the MCP request open. The model calls `omp_await_result` with the notice's `call_id`; the adapter returns the same original result, not a second execution. The control tool is a separate MCP server and is not added to OMP's tool list. If the ACP turn ends before the result arrives, the adapter retries the same result in a fresh ACP turn; it never delivers a stale result to a new writer. If the model never calls the control tool, the next OMP turn carries the completed result as history or a bounded `<tool_result>` envelope; the adapter never re-executes the tool.
274
276
 
275
277
  Permission requests are correlated by session, turn and `toolCallId` with structured `mcpServerName`/`mcpToolName` metadata. A conflicting update, a previous-turn id, or a permission-before-update that claims MCP identity is rejected with `reject_once` when available, otherwise `cancelled`. Normal requests still go through OMP's human review.
276
278
 
@@ -14,6 +14,7 @@ The following community work was adapted into the owned adapter architecture rat
14
14
  - [ldfhhc/omp-antigravity-acp-provider](https://github.com/ldfhhc/omp-antigravity-acp-provider) (`@ldfhhc`): oldest-image history continuity and hidden history/request seed guards. The independently guarded implementation lives in `extension/runtime/image-history.ts` and `extension/runtime/history-seed.ts`.
15
15
  - [00lllooolll00/omp-antigravity-acp-provider](https://github.com/00lllooolll00/omp-antigravity-acp-provider) (`@00lllooolll00`): fresh-login watcher protection, Hydrogen/offline catalog discovery, Bun SQLite usage, CLI stat caching, quota refresh grace, standby warmup and release helper ideas, adapted and additionally hardened in this repository.
16
16
  - [masred/omp-antigravity-acp-provider](https://github.com/masred/omp-antigravity-acp-provider) (`@masred`): standard Google OAuth endpoints and AccountChooser handling for headless login, adapted into `extension/runtime/acp/headless-oauth.ts`.
17
+ - A community Antigravity bridge plugin by DylanLIiii, gitxm, yce (itself adapting magpie-community/plugins `agy-cli`), MIT: the CloudCode-observed per-model context/output limits (`extension/runtime/models.ts`), RE2-safe tool-schema pattern handling and the MCP tool token budget with `antigravity/alwaysLoad` (`extension/runtime/tools/`), the agy diagnostic notice taxonomy (`extension/agent-notices.ts`), and the system-prompt fingerprint rewording list (`extension/prompt-cloak.ts`), each adapted into this repository's owned sources.
17
18
 
18
19
  Each contribution remains distinguishable in the owned source and its feature commit where applicable. The adapter does not copy fork-specific package names, publishing identities or personal skill files.
19
20
 
@@ -6,6 +6,7 @@ import { redactSensitiveText } from "./redact.ts";
6
6
  export type AcpFailureCode =
7
7
  | "auth"
8
8
  | "quota"
9
+ | "prompt_rejected"
9
10
  | "rate_limit"
10
11
  | "context"
11
12
  | "timeout"
@@ -16,6 +17,11 @@ export type AcpFailureCode =
16
17
  | "refusal"
17
18
  | "aborted";
18
19
 
20
+ export interface AcpFailureContext {
21
+ /** The session's instructions contained a phrase agy refuses regardless of quota. */
22
+ promptFingerprinted?: boolean;
23
+ }
24
+
19
25
  export class AcpFailure extends Error {
20
26
  constructor(readonly code: AcpFailureCode, message: string, options?: ErrorOptions) {
21
27
  super(message, options);
@@ -42,6 +48,17 @@ const QUOTA_RULE: FailureRule = {
42
48
  ensure: /quota exceeded|insufficient_quota|billing/i,
43
49
  append: "quota exceeded",
44
50
  };
51
+
52
+ // agy answers known third-party harness prompt lines with 429s whatever quota
53
+ // is left. When the session's instructions carried such a phrase, quota is the
54
+ // wrong explanation. Explicit metered-quota wording still wins, because the
55
+ // same 429 text also appears for genuine throttling and rate limits.
56
+ const PROMPT_REJECTED_RULE: FailureRule = {
57
+ code: "prompt_rejected",
58
+ match: /resource.?exhausted|code\s*[:=]?\s*429|http\s*429|too many requests/i,
59
+ ensure: /fingerprint/i,
60
+ append: "prompt fingerprint refused by Antigravity despite remaining quota",
61
+ };
45
62
  const RATE_LIMIT_RULE: FailureRule = {
46
63
  code: "rate_limit",
47
64
  match: /rate.?limit|429|too many requests|overloaded|capacity|server_busy|high demand/i,
@@ -126,12 +143,17 @@ function sanitizedError(error: unknown): Error {
126
143
  return sanitized;
127
144
  }
128
145
 
129
- export function classifyAcpFailure(error: unknown): Error {
146
+ export function classifyAcpFailure(error: unknown, context: AcpFailureContext = {}): Error {
130
147
  if (isAntigravityAcpError(error)) {
131
148
  if (error.code === "aborted") return error;
132
149
  const cause = { cause: sanitizedCause(error) };
133
150
  if (error.code === "auth") return new AcpFailure("auth", redactSensitiveText(appendHint(error.message, AUTH_RULE)), cause);
134
- if (error.code === "quota") return new AcpFailure("quota", redactSensitiveText(appendHint(error.message, QUOTA_RULE)), cause);
151
+ if (error.code === "quota") {
152
+ if (context.promptFingerprinted && !QUOTA_RULE.ensure.test(error.message) && PROMPT_REJECTED_RULE.match.test(error.message)) {
153
+ return new AcpFailure("prompt_rejected", redactSensitiveText(appendHint(error.message, PROMPT_REJECTED_RULE)), cause);
154
+ }
155
+ return new AcpFailure("quota", redactSensitiveText(appendHint(error.message, QUOTA_RULE)), cause);
156
+ }
135
157
  if (error.code === "timeout") return new AcpFailure("timeout", redactSensitiveText(appendHint(error.message, TIMEOUT_RULE)), cause);
136
158
  if (error.code === "spawn" || error.code === "process_exit") return new AcpFailure("transport", redactSensitiveText(appendHint(error.message, TRANSPORT_RULE)), cause);
137
159
  if ((error.code === "protocol" || error.code === "invalid_input")
@@ -146,6 +168,9 @@ export function classifyAcpFailure(error: unknown): Error {
146
168
  if (OAUTH_NETWORK_REFRESH.test(message) && !/invalid_grant/i.test(message)) {
147
169
  return new AcpFailure("transport", redactSensitiveText(appendHint(message, TRANSPORT_RULE)), { cause: sanitizedCause(error) });
148
170
  }
171
+ if (context.promptFingerprinted && !QUOTA_RULE.ensure.test(message) && PROMPT_REJECTED_RULE.match.test(message)) {
172
+ return new AcpFailure("prompt_rejected", redactSensitiveText(appendHint(message, PROMPT_REJECTED_RULE)), { cause: sanitizedCause(error) });
173
+ }
149
174
  for (const rule of RULES) {
150
175
  if (rule.match.test(message)) {
151
176
  return new AcpFailure(rule.code, redactSensitiveText(appendHint(message, rule)), { cause: sanitizedCause(error) });
@@ -1,10 +1,35 @@
1
- // agy streams transport retries and its own output-cap continuation notice as
2
- // assistant text. They are diagnostics, not model output, so keep them out of
3
- // OMP's transcript without dropping a chunk that only looks like a prefix.
1
+ // agy streams transport retries, its output-cap continuation notice and its
2
+ // own ⚠ diagnostics as ordinary assistant text. They are agy's, not the
3
+ // model's, so they are only recognised as standalone complete lines at line
4
+ // boundaries and kept out of OMP's transcript without dropping a chunk that
5
+ // only looks like a prefix. The same words inside prose or a fenced code
6
+ // block are model text and pass through untouched. Terminal notices and
7
+ // RESOURCE_EXHAUSTED refusals are failure evidence without a log, so their
8
+ // text is captured for the connection to read once the stream ends
9
+ // (taxonomy adapted from a community Antigravity bridge plugin, MIT, issue #49).
4
10
  const AGENT_RETRY_NOTICE = /^\s*⚠\s*API error \(attempt \d+\)/i;
5
11
  const OUTPUT_LIMIT_HEAD = "your previous response was cut off because it exceeded the output token limit";
6
12
  const OUTPUT_LIMIT_TAIL = "please continue from where you left off, keeping your response shorter";
7
13
 
14
+ // agy's own ⚠ diagnostics arrive as plain assistant lines. The terminal
15
+ // notices mean the turn failed; the others describe internal retries, and a
16
+ // RESOURCE_EXHAUSTED banner is agy 1.5.9's refusal as an attempt-1 error.
17
+ const ERROR_LINE = "⚠ Agent execution terminated due to error.";
18
+ const NETWORK_LINE = "⚠ There was a network issue connecting to the server, please try again.";
19
+ const CREDITS_LINE = "⚠ Your AI credits balance is too low to continue.";
20
+ const INVALID_LINE = "⚠ Model produced invalid output.";
21
+ const INTERRUPT_LINE = "⚠ The stream was interrupted. Please continue the task you were working on.";
22
+ const API_HEAD = "⚠ API error (attempt ";
23
+ const EXHAUSTED_HEAD = "⚠ RESOURCE_EXHAUSTED (code ";
24
+ const API_FULL = /^⚠ API error \(attempt \d+\): /;
25
+ const EXHAUSTED_FULL = /^⚠ RESOURCE_EXHAUSTED \(code \d+\): /;
26
+ // The digits and closing punctuation that can still grow into a full head.
27
+ const API_PARTIAL = /^\d*(?:\)(?::(?: )?)?)?$/;
28
+ const FENCE_OPENER = /^\s*(?:```|~~~)/;
29
+ // A short backtick or tilde run may still grow into a fence opener.
30
+ const PARTIAL_FENCE = /^ {0,3}(?:`{1,2}|~{1,2})$/;
31
+ const DETAIL_LIMIT = 2000;
32
+
8
33
  export type NoticeVerdict = "drop" | "hold" | "emit";
9
34
 
10
35
  function noticeText(raw: string): string {
@@ -16,7 +41,7 @@ export function classifyOutputLimitNotice(raw: string): NoticeVerdict {
16
41
  if (text.length === 0) return "emit";
17
42
  const stripped = text.replace(/\s*retries remaining:\s*\d*\s*$/i, "").trim();
18
43
  const retry = text.slice(stripped.length).trim();
19
- if (retry.length > 0 && !/^retries remaining:\s*\d*$/i.test(retry)) return "emit";
44
+ if (retry.length > 0 && !/^retries remaining:\s*\d+$/i.test(retry)) return "emit";
20
45
  if (stripped.length === 0) return /^retries remaining:\s*\d+$/i.test(text) ? "drop" : "emit";
21
46
  const full = `${OUTPUT_LIMIT_HEAD} ${OUTPUT_LIMIT_TAIL}`;
22
47
  if (stripped === full || stripped === OUTPUT_LIMIT_HEAD || stripped === OUTPUT_LIMIT_TAIL) return "drop";
@@ -26,42 +51,125 @@ export function classifyOutputLimitNotice(raw: string): NoticeVerdict {
26
51
  return "emit";
27
52
  }
28
53
 
54
+ // A 429 RESOURCE_EXHAUSTED detail is a quota refusal, not a retry.
55
+ export function isRefused429(detail: string | undefined): boolean {
56
+ const text = String(detail ?? "");
57
+ return /code 429\b/i.test(text) && /resource has been exhausted/i.test(text);
58
+ }
59
+
60
+ // Failure evidence the connection reads once the stream has ended: the first
61
+ // terminal banner, the latest API detail and the first 429 refusal detail.
62
+ export interface AgentNoticeCapture {
63
+ readonly terminal: string | undefined;
64
+ readonly apiDetail: string | undefined;
65
+ readonly refusedDetail: string | undefined;
66
+ }
67
+
68
+ type LineKind = "emit" | "hold" | "fence" | "terminal" | "notice" | "api" | "limit";
69
+
70
+ interface LineState {
71
+ // Trailing line that may still grow into a notice.
72
+ pending: string;
73
+ // The open line already reached the transcript as model text.
74
+ midLine: boolean;
75
+ // Inside a ``` / ~~~ fenced code block.
76
+ fence: boolean;
77
+ }
78
+
79
+ interface SessionCapture {
80
+ terminal?: string;
81
+ apiDetail?: string;
82
+ refusedDetail?: string;
83
+ }
84
+
85
+ // An incomplete line only counts as a notice candidate while it can still
86
+ // grow into one, allowing for trailing spaces before the line ends.
87
+ function couldBecome(line: string, notice: string): boolean {
88
+ return notice.startsWith(line) || (line.trimEnd() === notice && line.length <= notice.length + 16);
89
+ }
90
+
29
91
  // ACP notifications from several sessions share one connection callback, so
30
- // the hold state is keyed by session and never leaks across streams.
92
+ // the line state is keyed by session and never leaks across streams.
31
93
  export class AgentNoticeFilter {
32
- private readonly holds = new Map<string, string>();
94
+ private readonly lines = new Map<string, LineState>();
33
95
  private readonly limitNotices = new Set<string>();
96
+ private readonly captures = new Map<string, SessionCapture>();
34
97
  dropped = 0;
35
98
 
36
99
  accept(sessionId: string, text: string): string | undefined {
37
- const combined = (this.holds.get(sessionId) ?? "") + text;
38
- const verdict = classifyOutputLimitNotice(combined);
39
- if (verdict === "hold") {
40
- this.holds.set(sessionId, combined);
41
- return undefined;
42
- }
43
- this.holds.delete(sessionId);
44
- if (verdict === "drop") {
100
+ const state = this.lineState(sessionId);
101
+ let rest = state.pending + text;
102
+ state.pending = "";
103
+ let out = "";
104
+ let consumed = false;
105
+ while (rest.length > 0) {
106
+ if (state.midLine) {
107
+ // The open line was already emitted as model text, so nothing in it
108
+ // can start a standalone notice; only its end begins a new line.
109
+ const end = rest.indexOf("\n");
110
+ if (end < 0) {
111
+ out += rest;
112
+ break;
113
+ }
114
+ out += rest.slice(0, end);
115
+ rest = rest.slice(end);
116
+ state.midLine = false;
117
+ continue;
118
+ }
119
+ const lead = rest[0] === "\n" ? "\n" : "";
120
+ const body = rest.slice(lead.length);
121
+ if (body.length === 0) {
122
+ out += lead;
123
+ break;
124
+ }
125
+ const end = body.indexOf("\n");
126
+ const line = end < 0 ? body : body.slice(0, end);
127
+ const kind = this.classify(state, line, end >= 0);
128
+ if (kind === "hold") {
129
+ state.pending = rest;
130
+ consumed = true;
131
+ break;
132
+ }
133
+ if (kind === "emit" || kind === "fence") {
134
+ if (kind === "fence") state.fence = !state.fence;
135
+ out += lead + line;
136
+ if (end < 0) {
137
+ state.midLine = true;
138
+ break;
139
+ }
140
+ rest = body.slice(end);
141
+ continue;
142
+ }
143
+ // A notice line is dropped together with its terminating newline; the
144
+ // newline before it stays so surrounding model text keeps its shape.
145
+ consumed = true;
45
146
  this.dropped++;
46
- this.limitNotices.add(sessionId);
47
- return undefined;
147
+ if (kind === "terminal") this.recordTerminal(sessionId, line);
148
+ else if (kind === "api") this.recordApiDetail(sessionId, line);
149
+ else if (kind === "limit") this.limitNotices.add(sessionId);
150
+ out += lead;
151
+ if (end < 0) break;
152
+ rest = body.slice(end + 1);
48
153
  }
49
- if (AGENT_RETRY_NOTICE.test(combined)) {
50
- this.dropped++;
51
- return undefined;
52
- }
53
- return combined;
154
+ if (out.length > 0) return out;
155
+ return consumed ? undefined : "";
54
156
  }
55
157
 
56
- // A thought chunk proves the held text was model output rather than the
57
- // start of agy's notice. A finished notice is counted and discarded.
158
+ // Releases held text at the end of a model step. A held line that finished
159
+ // as a notice is counted and discarded; anything else is model text.
58
160
  flush(sessionId: string): string | undefined {
59
- const held = this.holds.get(sessionId);
60
- if (held === undefined) return undefined;
61
- this.holds.delete(sessionId);
62
- if (classifyOutputLimitNotice(held) === "drop") {
161
+ const state = this.lines.get(sessionId);
162
+ if (state === undefined) return undefined;
163
+ const held = state.pending;
164
+ if (held === "") return undefined;
165
+ state.pending = "";
166
+ const line = held[0] === "\n" ? held.slice(1) : held;
167
+ const kind = this.classify(state, line, true);
168
+ if (kind === "terminal" || kind === "notice" || kind === "api" || kind === "limit") {
63
169
  this.dropped++;
64
- this.limitNotices.add(sessionId);
170
+ if (kind === "terminal") this.recordTerminal(sessionId, line);
171
+ else if (kind === "api") this.recordApiDetail(sessionId, line);
172
+ else if (kind === "limit") this.limitNotices.add(sessionId);
65
173
  return undefined;
66
174
  }
67
175
  return held;
@@ -71,13 +179,91 @@ export class AgentNoticeFilter {
71
179
  return this.limitNotices.delete(sessionId);
72
180
  }
73
181
 
182
+ terminalNotice(sessionId: string): string | undefined {
183
+ return this.captures.get(sessionId)?.terminal;
184
+ }
185
+
186
+ captured(sessionId: string): AgentNoticeCapture {
187
+ const capture = this.captures.get(sessionId);
188
+ return { terminal: capture?.terminal, apiDetail: capture?.apiDetail, refusedDetail: capture?.refusedDetail };
189
+ }
190
+
191
+ // Captures outlive forget(): a turn's banner is often only settled by the
192
+ // final flush, after the per-turn forget has already run, so the finished
193
+ // turn stays inspectable until the failure is reported.
194
+ consumeCaptured(sessionId: string): AgentNoticeCapture {
195
+ const record = this.captured(sessionId);
196
+ this.captures.delete(sessionId);
197
+ return record;
198
+ }
199
+
74
200
  forget(sessionId: string): void {
75
- this.holds.delete(sessionId);
201
+ this.lines.delete(sessionId);
76
202
  this.limitNotices.delete(sessionId);
77
203
  }
78
204
 
79
205
  clear(): void {
80
- this.holds.clear();
206
+ this.lines.clear();
81
207
  this.limitNotices.clear();
208
+ this.captures.clear();
209
+ }
210
+
211
+ private lineState(sessionId: string): LineState {
212
+ let state = this.lines.get(sessionId);
213
+ if (state === undefined) {
214
+ state = { pending: "", midLine: false, fence: false };
215
+ this.lines.set(sessionId, state);
216
+ }
217
+ return state;
218
+ }
219
+
220
+ private sessionCapture(sessionId: string): SessionCapture {
221
+ let capture = this.captures.get(sessionId);
222
+ if (capture === undefined) {
223
+ capture = {};
224
+ this.captures.set(sessionId, capture);
225
+ }
226
+ return capture;
227
+ }
228
+
229
+ private recordTerminal(sessionId: string, line: string): void {
230
+ const capture = this.sessionCapture(sessionId);
231
+ if (capture.terminal === undefined) capture.terminal = line.trimEnd();
232
+ }
233
+
234
+ private recordApiDetail(sessionId: string, line: string): void {
235
+ const capture = this.sessionCapture(sessionId);
236
+ const detail = line.slice(0, DETAIL_LIMIT);
237
+ capture.apiDetail = detail;
238
+ if (capture.refusedDetail === undefined && isRefused429(detail)) capture.refusedDetail = detail;
239
+ }
240
+
241
+ private classify(state: LineState, line: string, complete: boolean): LineKind {
242
+ if (FENCE_OPENER.test(line)) return "fence";
243
+ // Everything inside a fence is model text and passes through untouched.
244
+ if (state.fence) return "emit";
245
+ if (complete && line.trimEnd() === ERROR_LINE) return "terminal";
246
+ if (!complete && couldBecome(line, ERROR_LINE)) return "hold";
247
+ if (complete && (line.trimEnd() === NETWORK_LINE || line.trimEnd() === CREDITS_LINE)) return "terminal";
248
+ if (!complete && (couldBecome(line, NETWORK_LINE) || couldBecome(line, CREDITS_LINE))) return "hold";
249
+ if (line.startsWith("⚠")) {
250
+ // An invalid-output banner means the turn produced nothing usable, so it
251
+ // is terminal evidence; a stream interruption invites a continuation.
252
+ if (complete && line.trimEnd() === INVALID_LINE) return "terminal";
253
+ if (complete && line.trimEnd() === INTERRUPT_LINE) return "notice";
254
+ if (API_FULL.test(line) || EXHAUSTED_FULL.test(line) || AGENT_RETRY_NOTICE.test(line)) return "api";
255
+ if (!complete) {
256
+ if (couldBecome(line, INTERRUPT_LINE) || couldBecome(line, INVALID_LINE)) return "hold";
257
+ if (API_HEAD.startsWith(line) || EXHAUSTED_HEAD.startsWith(line)) return "hold";
258
+ if (line.startsWith(API_HEAD) && line.length <= API_HEAD.length + 16 && API_PARTIAL.test(line.slice(API_HEAD.length))) return "hold";
259
+ if (line.startsWith(EXHAUSTED_HEAD) && line.length <= EXHAUSTED_HEAD.length + 16 && API_PARTIAL.test(line.slice(EXHAUSTED_HEAD.length))) return "hold";
260
+ }
261
+ } else if (!complete && PARTIAL_FENCE.test(line)) {
262
+ return "hold";
263
+ }
264
+ const verdict = classifyOutputLimitNotice(line);
265
+ if (verdict === "drop") return "limit";
266
+ if (verdict === "hold" && !complete) return "hold";
267
+ return "emit";
82
268
  }
83
269
  }
@@ -4,7 +4,12 @@ import { promisify } from "node:util";
4
4
  import fs from "node:fs";
5
5
  import path from "node:path";
6
6
  import { randomUUID } from "node:crypto";
7
- import { clearAntigravityCredentials, inspectAntigravityAuth, resolveAntigravityAcpDirectory } from "./runtime.mjs";
7
+ import {
8
+ clearAntigravityCredentials,
9
+ clearAntigravityLogoutMarker,
10
+ inspectAntigravityAuth,
11
+ resolveAntigravityAcpDirectory,
12
+ } from "./runtime.mjs";
8
13
  import type { AntigravityAuthHealth } from "./runtime/acp/antigravity.ts";
9
14
  import { createSecretService, runSecretTool } from "./secret-service.ts";
10
15
  import type { TierConnection } from "./tier-connection.ts";
@@ -411,6 +416,9 @@ export class OmpAuthCoordinator {
411
416
  // saved login and keep the previous account.
412
417
  noteLoginSucceeded(attempt: FreshGoogleLoginAttempt): void {
413
418
  if (!this.activeLogins.delete(attempt)) return;
419
+ // A completed sign-in ends the durable logout state; a failed or cancelled
420
+ // one keeps the marker so the next token sync cannot restore the old login.
421
+ try { clearAntigravityLogoutMarker(); } catch { /* Best effort: the login itself succeeded. */ }
414
422
  if (this.activeLogins.size > 0) {
415
423
  this.baseSuppressFollow = false;
416
424
  this.disabledUntil = 0;
@@ -4,6 +4,8 @@ import { antigravityAccountEmail, authReady, formatLogoutSummary, inspectAcpAuth
4
4
  import { parseNativeToolMode, type NativeToolMode } from "./tool-routing.ts";
5
5
  import { saveToolPolicy, type ToolPolicy } from "./tool-policy.ts";
6
6
  import { DEFAULT_USAGE_MODE, updateContextSettings, resolveContextOptions, saveContextSettings, type ContextSettings } from "./context-settings.ts";
7
+ import { ensureProviderModelsEnabled, PROVIDER_MODEL_SELECTOR, resolveOmpConfigPath } from "./omp-model-whitelist.ts";
8
+ import { errorMessageOf } from "./fs-atomic.ts";
7
9
  import type { CatalogStore, ConfiguredCatalogModel } from "./catalog-store.ts";
8
10
  import type { SessionCleanup, CleanupMode } from "./session-cleanup.ts";
9
11
  import type { TierConnection } from "./tier-connection.ts";
@@ -67,6 +69,9 @@ export interface CommandControllerDeps {
67
69
  configPath: string;
68
70
  contextPath: string;
69
71
  toolPolicyPath: string;
72
+ // OMP's agent directory. Refresh resolves the config file at use time so a
73
+ // config created after startup is still found.
74
+ ompAgentDir?: string;
70
75
  cleanup: SessionCleanup;
71
76
  connections: Set<TierConnection>;
72
77
  auth: OmpAuthCoordinator;
@@ -528,7 +533,25 @@ export function createAntigravityCommandHandler(deps: CommandControllerDeps) {
528
533
  if (value !== undefined) throw new Error("Usage: /antigravity-acp refresh");
529
534
  const refreshed = await deps.catalog.refresh(deps.getContextSettings());
530
535
  deps.onModelsUpdated(refreshed);
531
- ctx.ui.notify(section("ACP model cache refreshed", [["Models", refreshed.length ? refreshed.map(model => model.id).join(", ") : "none advertised"]]), "info");
536
+ const fields: DisplayField[] = [["Models", refreshed.length ? refreshed.map(model => model.id).join(", ") : "none advertised"]];
537
+ // Only a successful catalog makes the selector meaningful; a config
538
+ // write must never turn a refresh into a failure.
539
+ if (refreshed.length > 0 && deps.ompAgentDir) {
540
+ try {
541
+ const ompConfigPath = resolveOmpConfigPath(deps.ompAgentDir);
542
+ if (ompConfigPath) {
543
+ const whitelist = await ensureProviderModelsEnabled(ompConfigPath);
544
+ if (whitelist.changed) {
545
+ fields.push(["OMP whitelist", `${PROVIDER_MODEL_SELECTOR} added to ${whitelist.path}. Restart OMP or reopen /model to list the models.`]);
546
+ } else if (whitelist.reason === "unsupported") {
547
+ fields.push(["OMP whitelist warning", `${whitelist.path}: enabledModels is not a supported YAML shape; add ${PROVIDER_MODEL_SELECTOR} manually.`]);
548
+ }
549
+ }
550
+ } catch (error) {
551
+ fields.push(["OMP whitelist warning", `OMP config in ${deps.ompAgentDir}: ${errorMessageOf(error)}`]);
552
+ }
553
+ }
554
+ ctx.ui.notify(section("ACP model cache refreshed", fields), "info");
532
555
  return;
533
556
  }
534
557