omp-antigravity-acp-provider 0.1.33 → 0.1.34

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.
@@ -167,6 +167,7 @@ export interface AuthCoordinatorDeps {
167
167
  // this adapter finish the Antigravity-side logout when OMP reports removal.
168
168
  export class OmpAuthCoordinator {
169
169
  private watchingCredentials = false;
170
+ private activeContext: OmpCommandContext | undefined;
170
171
  private markerPresent: boolean | undefined;
171
172
  private suppressFollow = false;
172
173
  private selfLogout = false;
@@ -268,12 +269,14 @@ export class OmpAuthCoordinator {
268
269
  }
269
270
 
270
271
  private async finishFollowedLogout(ctx: OmpCommandContext): Promise<void> {
272
+ const activeCtx = this.activeContext ?? ctx;
271
273
  if (this.deps.isPoolBusy()) {
272
274
  // Never interrupt an in-flight Antigravity request; retry once idle.
273
275
  clearTimeout(this.followRetry);
274
276
  this.followRetry = setTimeout(() => {
275
277
  this.followRetry = undefined;
276
- if (this.ompMarkerStored(ctx) === false) this.runFollowedLogout(ctx);
278
+ const currentCtx = this.activeContext ?? activeCtx;
279
+ if (this.ompMarkerStored(currentCtx) === false) this.runFollowedLogout(currentCtx);
277
280
  }, logoutFollow.retryMs);
278
281
  this.followRetry.unref?.();
279
282
  return;
@@ -282,27 +285,30 @@ export class OmpAuthCoordinator {
282
285
  await this.deps.closeAllRuntimes();
283
286
  // A quick re-login can restore the marker while the steps above await;
284
287
  // a restored or unknown marker keeps the new keychain entry untouched.
285
- if (this.ompMarkerStored(ctx) !== false) return;
288
+ if (this.ompMarkerStored(this.activeContext ?? activeCtx) !== false) return;
286
289
  const keychainRemoved = await this.removeKeychainCredentialDurably();
287
290
  // Keep the confirmation terse; /antigravity-acp account shows the details.
288
291
  try {
289
- ctx?.ui?.notify?.(formatLogoutSummary({ keychainRemoved, followed: true }), "info");
292
+ (this.activeContext ?? activeCtx)?.ui?.notify?.(formatLogoutSummary({ keychainRemoved, followed: true }), "info");
290
293
  } catch { /* the host UI may already be gone */ }
291
294
  }
292
295
 
293
296
  // The follow-up runs detached from timer callbacks; a failure must not
294
297
  // become an unhandled rejection, and the notice stays credential-free.
295
298
  private runFollowedLogout(ctx: OmpCommandContext): void {
296
- void this.finishFollowedLogout(ctx).catch(() => {
299
+ const activeCtx = this.activeContext ?? ctx;
300
+ void this.finishFollowedLogout(activeCtx).catch(() => {
297
301
  try {
298
- ctx?.ui?.notify?.("Antigravity ACP: the logout OMP started could not be finished. Run /antigravity-acp logout to retry.", "error");
302
+ (this.activeContext ?? activeCtx)?.ui?.notify?.("Antigravity ACP: the logout OMP started could not be finished. Run /antigravity-acp logout to retry.", "error");
299
303
  } catch { /* the host UI may already be gone */ }
300
304
  });
301
305
  }
302
306
 
303
307
  watchOmpCredentials(ctx: OmpCommandContext | undefined): void {
304
- if (this.watchingCredentials || !ctx) return;
308
+ if (!ctx) return;
305
309
  const credentials = ctx.modelRegistry?.authStorage?.credentials;
310
+ if (credentials?.getOAuth && credentials.onGeneration) this.activeContext = ctx;
311
+ if (this.watchingCredentials) return;
306
312
  if (!credentials?.getOAuth || !credentials.onGeneration) return;
307
313
  const initial = this.ompMarkerStored(ctx);
308
314
  if (initial === undefined) return;
@@ -317,7 +323,8 @@ export class OmpAuthCoordinator {
317
323
  }
318
324
  });
319
325
  credentials.onGeneration(() => {
320
- const current = this.ompMarkerStored(ctx);
326
+ const activeCtx = this.activeContext ?? ctx;
327
+ const current = this.ompMarkerStored(activeCtx);
321
328
  if (current === undefined) return;
322
329
  const wasPresent = this.markerPresent === true;
323
330
  this.markerPresent = current;
@@ -342,12 +349,13 @@ export class OmpAuthCoordinator {
342
349
  return;
343
350
  }
344
351
  // A quick re-login after the removal cancels the cleanup.
345
- if (this.ompMarkerStored(ctx) !== false) {
352
+ const currentCtx = this.activeContext ?? activeCtx;
353
+ if (this.ompMarkerStored(currentCtx) !== false) {
346
354
  this.apiKeyFallback = true;
347
355
  this.deps.onSyncProvider();
348
356
  return;
349
357
  }
350
- this.runFollowedLogout(ctx);
358
+ this.runFollowedLogout(currentCtx);
351
359
  }, logoutFollow.delayMs);
352
360
  this.followTimer.unref?.();
353
361
  });
@@ -26,6 +26,8 @@ export class CatalogStore {
26
26
  private readonly prepareRuntime: () => Promise<void>,
27
27
  private readonly fallbackModels: () => PublicCatalogModel[],
28
28
  private readonly requireAuth: () => Promise<void> = async () => {},
29
+ private readonly createConnection: (options: ConstructorParameters<typeof TierConnection>[0]) => TierConnection =
30
+ options => new TierConnection(options),
29
31
  ) {}
30
32
 
31
33
  projectWithSettings(models: PublicCatalogModel[], settings: ContextSettings): ConfiguredCatalogModel[] {
@@ -111,7 +113,7 @@ export class CatalogStore {
111
113
  private async discoverOnce(): Promise<AdvertisedModel[]> {
112
114
  await this.requireAuth();
113
115
  await this.prepareRuntime();
114
- const connection = new TierConnection({ cwd: process.cwd(), ompCleanup: this.cleanup });
116
+ const connection = this.createConnection({ cwd: process.cwd(), ompCleanup: this.cleanup });
115
117
  let discoveredSession: string | undefined;
116
118
  try {
117
119
  await connection.initialize();
@@ -123,9 +125,15 @@ export class CatalogStore {
123
125
  for (const option of modern) {
124
126
  // Model changes can alter reasoning choices; inspect each model's
125
127
  // confirmed configuration rather than sharing one global tier list.
126
- await connection.setModel(session.sessionId, option.value);
127
- models.push(advertisedRecord(connection.getSessionState(session.sessionId), option.value, option.name));
128
+ try {
129
+ await connection.setModel(session.sessionId, option.value);
130
+ models.push(advertisedRecord(connection.getSessionState(session.sessionId), option.value, option.name));
131
+ } catch {
132
+ // An advertised preview/retired model can reject selection without
133
+ // making the remaining models unusable.
134
+ }
128
135
  }
136
+ if (!models.length) throw new Error("Antigravity advertised models but none could be selected");
129
137
  return models;
130
138
  }
131
139
  const models = readModels(session.models?.availableModels);
@@ -297,17 +297,23 @@ export function createAntigravityCommandHandler(deps: CommandControllerDeps) {
297
297
 
298
298
  // Only the tools inspection and the status display below need a live
299
299
  // runtime; every earlier command runs without one.
300
- const { runtime } = deps.getRuntimeForSession(sessionIdOf(ctx));
301
- const snapshot = await runtime.snapshot();
302
- if (command === "tools") {
303
- const lastToolAudit = deps.getLastToolAudit();
304
- ctx.ui.notify(lastToolAudit
305
- ? `OMP ACP tool bridge\nAvailable: ${lastToolAudit.available.join(", ")}\nOmitted: ${JSON.stringify(lastToolAudit.omitted)}\nLive ACP checks: ${JSON.stringify(snapshot.processes.map(item => ({ mcpHttp: item.mcpHttp, omittedTools: item.omittedTools })))}`
306
- : "No model request yet. Send a message with this ACP model to inspect its offered OMP tools.", "info");
307
- return;
308
- }
300
+ const lease = deps.acquireRuntimeForSession
301
+ ? deps.acquireRuntimeForSession(sessionIdOf(ctx))
302
+ : { value: deps.getRuntimeForSession(sessionIdOf(ctx)), release: () => {} };
303
+ try {
304
+ const snapshot = await lease.value.runtime.snapshot();
305
+ if (command === "tools") {
306
+ const lastToolAudit = deps.getLastToolAudit();
307
+ ctx.ui.notify(lastToolAudit
308
+ ? `OMP ACP tool bridge\nAvailable: ${lastToolAudit.available.join(", ")}\nOmitted: ${JSON.stringify(lastToolAudit.omitted)}\nLive ACP checks: ${JSON.stringify(snapshot.processes.map(item => ({ mcpHttp: item.mcpHttp, omittedTools: item.omittedTools })))}`
309
+ : "No model request yet. Send a message with this ACP model to inspect its offered OMP tools.", "info");
310
+ return;
311
+ }
309
312
 
310
- const policy = deps.getToolPolicy();
311
- ctx.ui.notify(`Antigravity ACP (OMP adapter)\nAuth storage: ${(await authReady()) ? "configured (ACP-owned token file or macOS keychain)" : inspectAntigravityAuth().status}\nPermissions: ${snapshot.permissionMode}\nNative tools: ${policy.nativeTools}\nDebug tool updates: ${policy.debugToolUpdates ? "on" : "off"}\nTool routing: ${JSON.stringify([...deps.connections].map(connection => connection.toolRouting).filter(Boolean))}\nActive sessions: ${snapshot.bindings}\nConfirmed thinking: ${JSON.stringify([...deps.connections].map(connection => connection.confirmedThinking).filter(Boolean))}\nUsage: ${JSON.stringify(snapshot.metrics)}\n${JSON.stringify(snapshot.processes)}`, "info");
313
+ const policy = deps.getToolPolicy();
314
+ ctx.ui.notify(`Antigravity ACP (OMP adapter)\nAuth storage: ${(await authReady()) ? "configured (ACP-owned token file or macOS keychain)" : inspectAntigravityAuth().status}\nPermissions: ${snapshot.permissionMode}\nNative tools: ${policy.nativeTools}\nDebug tool updates: ${policy.debugToolUpdates ? "on" : "off"}\nTool routing: ${JSON.stringify([...deps.connections].map(connection => connection.toolRouting).filter(Boolean))}\nActive sessions: ${snapshot.bindings}\nConfirmed thinking: ${JSON.stringify([...deps.connections].map(connection => connection.confirmedThinking).filter(Boolean))}\nUsage: ${JSON.stringify(snapshot.metrics)}\n${JSON.stringify(snapshot.processes)}`, "info");
315
+ } finally {
316
+ lease.release();
317
+ }
312
318
  };
313
319
  }
@@ -148,7 +148,6 @@ export function stableSystemContent(text: string): string {
148
148
  .replace(DATE_CWD_REMINDER, "")
149
149
  .replace(SYSTEM_REMINDER_TAG, (match, body: string) => isVolatileReminder(body) ? "" : match)
150
150
  .replace(OMP_TOOL_NAMES_LINE, "")
151
- .replace(TOOL_ROUTING.trim(), "")
152
151
  .replace(/\n{3,}/g, "\n\n")
153
152
  .trim();
154
153
  }
@@ -542,9 +541,17 @@ export function buildPromptParts(context: TransferContext, fresh: boolean, unsee
542
541
  if (promptTextBytes(prompt) > ACP_STEP_TEXT_BYTES) {
543
542
  const seedTail: TransferBlock[] = [{ type: "text", text: SEED_ACK_TEXT }];
544
543
  let pendingInstructions = instructionsBlock;
544
+ let finalInstructions: TransferBlock | undefined;
545
+ if (pendingInstructions && promptTextBytes(assembleStep(pendingInstructions, [], seedTail)) > ACP_STEP_TEXT_BYTES) {
546
+ // Instructions that cannot fit beside a seed acknowledgement stay in
547
+ // the final prompt; history seed steps can still be sent without them.
548
+ finalInstructions = pendingInstructions;
549
+ pendingInstructions = undefined;
550
+ }
545
551
  let cursor = 0;
546
552
  while (cursor < recordItems.length || pendingInstructions) {
547
- const remaining = assembleStep(pendingInstructions, recordItems.slice(cursor), tailBlocks);
553
+ const remainingInstructions = finalInstructions ?? pendingInstructions;
554
+ const remaining = assembleStep(remainingInstructions, recordItems.slice(cursor), tailBlocks);
548
555
  if (promptTextBytes(remaining) <= ACP_STEP_TEXT_BYTES) break;
549
556
  const chunkItems: RecordItem[] = [];
550
557
  const chunkInst = pendingInstructions;
@@ -565,7 +572,7 @@ export function buildPromptParts(context: TransferContext, fresh: boolean, unsee
565
572
  historySeedSteps.push(seedStep);
566
573
  pendingInstructions = undefined;
567
574
  }
568
- prompt = assembleStep(pendingInstructions, recordItems.slice(cursor), tailBlocks);
575
+ prompt = assembleStep(finalInstructions ?? pendingInstructions, recordItems.slice(cursor), tailBlocks);
569
576
  checkStepTextBytes(promptTextBytes(prompt));
570
577
  }
571
578
  const seedSteps = historySeedSteps.length || requestSeedSteps.length
@@ -252,6 +252,7 @@ export async function registerOmpAdapter(pi: OmpHostApi, stateDir: string,
252
252
  prepareRuntime,
253
253
  () => [...(FALLBACK_MODELS as PublicCatalogModel[])],
254
254
  requireAcpAuth,
255
+ createConnection,
255
256
  );
256
257
  let initialModels = catalogStore.loadInitialOrCached(contextSettings);
257
258
 
@@ -19338,9 +19338,10 @@ async function drainCancelledTurn(binding, abort, signal, timeoutMs = 1500, timi
19338
19338
  if (!completion || signal?.aborted) return false;
19339
19339
  const deadline = Promise.withResolvers();
19340
19340
  const cancelled = () => deadline.resolve(false);
19341
- let timer = setTimeout(cancelled, timeoutMs);
19341
+ let timer;
19342
19342
  let giveup;
19343
19343
  let finished = false;
19344
+ let cancelSettled = false;
19344
19345
  signal?.addEventListener("abort", cancelled, { once: true });
19345
19346
  const extendForNaturalCompletion = () => {
19346
19347
  if (finished || giveup) return;
@@ -19348,14 +19349,20 @@ async function drainCancelledTurn(binding, abort, signal, timeoutMs = 1500, timi
19348
19349
  clearTimeout(timer);
19349
19350
  giveup = armSteerGiveup(binding.connection, binding.session.sessionId, timings, cancelled);
19350
19351
  };
19352
+ timer = setTimeout(() => {
19353
+ if (!cancelSettled && timings.idleMs > 0) extendForNaturalCompletion();
19354
+ else cancelled();
19355
+ }, timeoutMs);
19351
19356
  try {
19352
19357
  abort();
19353
19358
  void (async () => {
19354
19359
  try {
19355
19360
  await binding.connection.cancel(binding.session.sessionId);
19361
+ cancelSettled = true;
19356
19362
  if (timings.idleMs > 0) extendForNaturalCompletion();
19357
19363
  else deadline.resolve(false);
19358
19364
  } catch (error62) {
19365
+ cancelSettled = true;
19359
19366
  if (timings.idleMs > 0 && isCancelUnsupported(error62)) extendForNaturalCompletion();
19360
19367
  else deadline.resolve(false);
19361
19368
  }
@@ -59613,7 +59620,7 @@ function isVolatileReminder(body) {
59613
59620
  return lines.length > 0 && lines.every((line) => /^Today: .*$/u.test(line) || /^OMP tool names: .*$/u.test(line));
59614
59621
  }
59615
59622
  function stableSystemContent(text) {
59616
- return text.replace(DATE_CWD_REMINDER, "").replace(SYSTEM_REMINDER_TAG, (match, body) => isVolatileReminder(body) ? "" : match).replace(OMP_TOOL_NAMES_LINE, "").replace(TOOL_ROUTING.trim(), "").replace(/\n{3,}/g, "\n\n").trim();
59623
+ return text.replace(DATE_CWD_REMINDER, "").replace(SYSTEM_REMINDER_TAG, (match, body) => isVolatileReminder(body) ? "" : match).replace(OMP_TOOL_NAMES_LINE, "").replace(/\n{3,}/g, "\n\n").trim();
59617
59624
  }
59618
59625
  function stableSystemInstructions(context) {
59619
59626
  return stableSystemContent(currentSystemInstructions(context));
@@ -59937,9 +59944,15 @@ ${instructions}` : "";
59937
59944
  if (promptTextBytes(prompt) > ACP_STEP_TEXT_BYTES) {
59938
59945
  const seedTail = [{ type: "text", text: SEED_ACK_TEXT }];
59939
59946
  let pendingInstructions = instructionsBlock;
59947
+ let finalInstructions;
59948
+ if (pendingInstructions && promptTextBytes(assembleStep(pendingInstructions, [], seedTail)) > ACP_STEP_TEXT_BYTES) {
59949
+ finalInstructions = pendingInstructions;
59950
+ pendingInstructions = void 0;
59951
+ }
59940
59952
  let cursor = 0;
59941
59953
  while (cursor < recordItems.length || pendingInstructions) {
59942
- const remaining = assembleStep(pendingInstructions, recordItems.slice(cursor), tailBlocks);
59954
+ const remainingInstructions = finalInstructions ?? pendingInstructions;
59955
+ const remaining = assembleStep(remainingInstructions, recordItems.slice(cursor), tailBlocks);
59943
59956
  if (promptTextBytes(remaining) <= ACP_STEP_TEXT_BYTES) break;
59944
59957
  const chunkItems = [];
59945
59958
  const chunkInst = pendingInstructions;
@@ -59960,7 +59973,7 @@ ${instructions}` : "";
59960
59973
  historySeedSteps.push(seedStep);
59961
59974
  pendingInstructions = void 0;
59962
59975
  }
59963
- prompt = assembleStep(pendingInstructions, recordItems.slice(cursor), tailBlocks);
59976
+ prompt = assembleStep(finalInstructions ?? pendingInstructions, recordItems.slice(cursor), tailBlocks);
59964
59977
  checkStepTextBytes(promptTextBytes(prompt));
59965
59978
  }
59966
59979
  const seedSteps = historySeedSteps.length || requestSeedSteps.length ? [...historySeedSteps, ...requestSeedSteps] : void 0;
@@ -61552,6 +61565,12 @@ function resolveSelection(state, requested) {
61552
61565
  return { modelId: requested };
61553
61566
  }
61554
61567
 
61568
+ // extension/activity-presentation.ts
61569
+ function showAcpUpdate(notification, debugToolUpdates) {
61570
+ const kind = notification.update?.sessionUpdate;
61571
+ return debugToolUpdates || kind !== "tool_call" && kind !== "tool_call_update";
61572
+ }
61573
+
61555
61574
  // extension/acp-compaction.ts
61556
61575
  function isTerminalCompaction(status) {
61557
61576
  return status === "completed" || status === "failed" || status === "cancelled";
@@ -61620,7 +61639,7 @@ function parseSessionUsage(text) {
61620
61639
  if (!Object.keys(counts).length && total > 0) return;
61621
61640
  const usage = { input: counts.prompt ?? 0, completion: counts.completion ?? 0, thinking: counts.thinking ?? 0, cached: counts.cached, total };
61622
61641
  if (usage.cached !== void 0 && usage.cached > usage.input) return;
61623
- if (usage.input + usage.completion + usage.thinking !== usage.total) return;
61642
+ if (usage.input + usage.completion + usage.thinking > usage.total) return;
61624
61643
  return usage;
61625
61644
  }
61626
61645
  function usageDelta(before, after) {
@@ -3,6 +3,7 @@
3
3
  import { AntigravityAcpConnection } from "./vendor/pi-antigravity-acp-provider/src/acp/connection.ts";
4
4
  import { choices, resolveSelection, selector } from "./selectors.ts";
5
5
  import { installSessionRouting, type NativeToolMode } from "./tool-routing.ts";
6
+ import { showAcpUpdate } from "./activity-presentation.ts";
6
7
  import { alignContextTokens, applyCompactionChunk, applyCompactionUpdate, isTerminalCompaction, type AcpCompactionNotice, type AcpCompactionRecord } from "./acp-compaction.ts";
7
8
  import { parseSessionUsage, usageDelta, type SessionUsage } from "./usage-accounting.ts";
8
9
  import type { SessionCleanup } from "./session-cleanup.ts";
@@ -23,6 +23,7 @@ export class TranscriptRouting {
23
23
  if (transcriptId.includes(":side:")) return transcriptId;
24
24
  if (this.pending.delete(transcriptId)) {
25
25
  this.byTranscript.set(transcriptId, transcriptId);
26
+ if (!this.pending.size) this.ambiguous = false;
26
27
  return transcriptId;
27
28
  }
28
29
  if (!this.ambiguous && this.pending.size === 1) {
@@ -143,9 +143,10 @@ export async function drainCancelledTurn(
143
143
  if (!completion || signal?.aborted) return false;
144
144
  const deadline = Promise.withResolvers<boolean>();
145
145
  const cancelled = () => deadline.resolve(false);
146
- let timer = setTimeout(cancelled, timeoutMs);
146
+ let timer: ReturnType<typeof setTimeout> | undefined;
147
147
  let giveup: { dispose: () => void } | undefined;
148
148
  let finished = false;
149
+ let cancelSettled = false;
149
150
  signal?.addEventListener("abort", cancelled, { once: true });
150
151
  // session/cancel is an ACP notification: a successful send only means the
151
152
  // server received it, not that the prompt already stopped. Freeze retained
@@ -157,15 +158,24 @@ export async function drainCancelledTurn(
157
158
  clearTimeout(timer);
158
159
  giveup = armSteerGiveup(binding.connection, binding.session.sessionId, timings, cancelled);
159
160
  };
161
+ timer = setTimeout(() => {
162
+ // A slow cancel RPC is not the same as a transport that never sent the
163
+ // notification. Give an unacknowledged-but-pending cancel the same grace
164
+ // as an acknowledged one before deciding to rebuild.
165
+ if (!cancelSettled && timings.idleMs > 0) extendForNaturalCompletion();
166
+ else cancelled();
167
+ }, timeoutMs);
160
168
  try {
161
169
  abort();
162
170
  // A blocked cancel transport must not block the fallback deadline.
163
171
  void (async () => {
164
172
  try {
165
173
  await binding.connection.cancel(binding.session.sessionId);
174
+ cancelSettled = true;
166
175
  if (timings.idleMs > 0) extendForNaturalCompletion();
167
176
  else deadline.resolve(false);
168
177
  } catch (error) {
178
+ cancelSettled = true;
169
179
  if (timings.idleMs > 0 && isCancelUnsupported(error)) extendForNaturalCompletion();
170
180
  else deadline.resolve(false);
171
181
  }
@@ -12,7 +12,7 @@ export function parseSessionUsage(text: string): SessionUsage | undefined {
12
12
  if (!Object.keys(counts).length && total > 0) return;
13
13
  const usage = { input: counts.prompt ?? 0, completion: counts.completion ?? 0, thinking: counts.thinking ?? 0, cached: counts.cached, total };
14
14
  if (usage.cached !== undefined && usage.cached > usage.input) return;
15
- if (usage.input + usage.completion + usage.thinking !== usage.total) return;
15
+ if (usage.input + usage.completion + usage.thinking > usage.total) return;
16
16
  return usage;
17
17
  }
18
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omp-antigravity-acp-provider",
3
- "version": "0.1.33",
3
+ "version": "0.1.34",
4
4
  "ompAcpBundle": 1,
5
5
  "description": "Google Antigravity ACP provider for Oh My Pi (OMP), with tool bridging and per-model thinking; derived from zacbemis/pi-antigravity-acp-provider",
6
6
  "type": "module",