@codexhost/cli-linux-arm64 0.20.0 → 0.22.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.
Files changed (51) hide show
  1. package/README.md +1 -1
  2. package/app/codexhost-distribution.json +1 -1
  3. package/app/console-server.mjs +27 -6
  4. package/app/console-web.js +35 -7
  5. package/app/desktop-controller.mjs +166 -52
  6. package/app/host-runtime.mjs +35350 -28799
  7. package/app/plugins/antigravity/assets/icon.svg +1 -1
  8. package/app/plugins/antigravity/plugin.mjs +411 -231
  9. package/app/plugins/claude-code/plugin.mjs +538 -109
  10. package/app/plugins/codebuddy/plugin.mjs +36 -6
  11. package/app/plugins/codex-usage/plugin.mjs +36 -6
  12. package/app/plugins/copilot/plugin.mjs +28 -6
  13. package/app/plugins/cursor-cli/plugin.mjs +28 -6
  14. package/app/plugins/deepseek-harness/plugin.mjs +53 -11
  15. package/app/plugins/devin/plugin.mjs +28 -6
  16. package/app/plugins/grok/plugin.mjs +255 -192
  17. package/app/plugins/hermes/plugin.mjs +28 -6
  18. package/app/plugins/kimi-code/plugin.mjs +53 -16
  19. package/app/plugins/kiro-cli/plugin.mjs +28 -6
  20. package/app/plugins/omp/plugin.mjs +143 -28
  21. package/app/plugins/opencode/plugin.mjs +54 -15
  22. package/app/plugins/pi/plugin.mjs +154 -29
  23. package/app/plugins/qoder/plugin.mjs +43 -6
  24. package/app/plugins/qoder-cn/plugin.mjs +43 -6
  25. package/app/plugins/qwen-code/plugin.mjs +28 -6
  26. package/app/plugins/workbuddy/plugin.mjs +36 -6
  27. package/app/plugins/zcode/plugin.mjs +36 -6
  28. package/app/renderer-extension.js +27 -6
  29. package/app/web/assets/index-CN4a4sj0.js +201 -0
  30. package/app/web/assets/{index-D6-hvggd.css → index-DJW4bmyx.css} +1 -1
  31. package/app/web/codexhost-settings.js +35 -7
  32. package/app/web/index.html +2 -2
  33. package/app/web/plugins/deepseek-ai__dsh-api-remotes/client.js +1 -1
  34. package/app/web/plugins/deepseek-ai__dsh-api-session-controller/client.js +7 -7
  35. package/app/web/plugins/deepseek-ai__dsh-client-ui-chat/client.js +9 -9
  36. package/app/web/plugins/deepseek-ai__dsh-client-ui-codexhost/client.js +6 -6
  37. package/app/web/plugins/deepseek-ai__dsh-client-ui-conversation/client.js +22 -22
  38. package/app/web/plugins/deepseek-ai__dsh-client-ui-input-trigger/client.js +1 -1
  39. package/app/web/plugins/deepseek-ai__dsh-client-ui-layout/client.js +2 -2
  40. package/app/web/plugins/deepseek-ai__dsh-client-ui-model-selection/client.js +1 -1
  41. package/app/web/plugins/deepseek-ai__dsh-client-ui-settings-general/client.js +1 -1
  42. package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar/client.js +1 -1
  43. package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar-documentpreview/client.js +9 -9
  44. package/app/web/plugins/deepseek-ai__dsh-client-ui-tool/client.js +1 -1
  45. package/app/web/plugins/deepseek-ai__dsh-client-ui-workspace/client.js +2 -2
  46. package/app/web-modules/server.mjs +1123 -722
  47. package/bin/codexhost +0 -0
  48. package/libexec/codexhost-shim +0 -0
  49. package/libexec/codexhost-updater +0 -0
  50. package/package.json +1 -1
  51. package/app/web/assets/index-D85gPBbQ.js +0 -201
@@ -1600,14 +1600,14 @@ function prefixIssues(path13, issues) {
1600
1600
  return iss;
1601
1601
  });
1602
1602
  }
1603
- function unwrapMessage(message2) {
1604
- return typeof message2 === "string" ? message2 : message2?.message;
1603
+ function unwrapMessage(message3) {
1604
+ return typeof message3 === "string" ? message3 : message3?.message;
1605
1605
  }
1606
1606
  function finalizeIssue(iss, ctx, config2) {
1607
- const message2 = iss.message ? iss.message : unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config2.customError?.(iss)) ?? unwrapMessage(config2.localeError?.(iss)) ?? "Invalid input";
1607
+ const message3 = iss.message ? iss.message : unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config2.customError?.(iss)) ?? unwrapMessage(config2.localeError?.(iss)) ?? "Invalid input";
1608
1608
  const { inst: _inst, continue: _continue, input: _input, ...rest } = iss;
1609
1609
  rest.path ?? (rest.path = []);
1610
- rest.message = message2;
1610
+ rest.message = message3;
1611
1611
  if (ctx?.reportInput) {
1612
1612
  rest.input = _input;
1613
1613
  }
@@ -15066,7 +15066,7 @@ var nonNegativeSafeIntegerSchema = external_exports.number().int().safe().nonneg
15066
15066
  var finiteNonNegativeNumberSchema = external_exports.number().finite().nonnegative();
15067
15067
  var cacheHitRatePercentSchema = external_exports.number().finite().min(0).max(100);
15068
15068
  var usageOutputTimingSchema = external_exports.object({
15069
- version: external_exports.literal(3).optional(),
15069
+ version: external_exports.union([external_exports.literal(3), external_exports.literal(4)]).optional(),
15070
15070
  requestId: external_exports.string().min(1),
15071
15071
  turnId: external_exports.string().min(1).max(1024),
15072
15072
  outputTokens: nonNegativeSafeIntegerSchema,
@@ -15074,16 +15074,16 @@ var usageOutputTimingSchema = external_exports.object({
15074
15074
  completedAtMs: nonNegativeSafeIntegerSchema
15075
15075
  }).strict().refine((value) => value.completedAtMs > value.startedAtMs);
15076
15076
  var usageMeasurementSchema = external_exports.object({
15077
- version: external_exports.union([external_exports.literal(2), external_exports.literal(3)]).optional(),
15077
+ version: external_exports.union([external_exports.literal(2), external_exports.literal(3), external_exports.literal(4)]).optional(),
15078
15078
  value: finiteNonNegativeNumberSchema,
15079
15079
  turnId: external_exports.string().min(1).max(1024),
15080
15080
  at: nonNegativeSafeIntegerSchema
15081
15081
  }).strict();
15082
15082
  var usageMeasurementsSchema = external_exports.object({
15083
- // Unversioned intervals can omit hidden thinking time; do not restore them into averages.
15084
- outputTimings: external_exports.array(usageOutputTimingSchema).transform((values) => values.filter((value) => value.version === 3)).optional(),
15083
+ // Older intervals can omit hidden thinking time; do not restore them into averages.
15084
+ outputTimings: external_exports.array(usageOutputTimingSchema).transform((values) => values.filter((value) => value.version === 4)).optional(),
15085
15085
  // Retain independent TTFT facts when dropping incompatible speed measurements.
15086
- outputTokensPerSecond: usageMeasurementSchema.refine((value) => value.version === 3).optional().catch(void 0),
15086
+ outputTokensPerSecond: usageMeasurementSchema.refine((value) => value.version === 4).optional().catch(void 0),
15087
15087
  timeToFirstOutputMs: usageMeasurementSchema.extend({ value: nonNegativeSafeIntegerSchema }).optional()
15088
15088
  }).strict();
15089
15089
  var indicatorTextSchema = (maximum) => harnessLocalizedTextSchema.refine((entries) => Object.values(entries).every((text2) => text2.length <= maximum));
@@ -15549,6 +15549,11 @@ var clientChannelEventSchema = external_exports.discriminatedUnion("type", [
15549
15549
  cursor: clientChannelCursorSchema,
15550
15550
  cwd: external_exports.string().optional()
15551
15551
  }),
15552
+ external_exports.object({
15553
+ type: external_exports.literal("harness-inspection-changed"),
15554
+ cursor: clientChannelCursorSchema,
15555
+ harnessId: external_exports.string().min(1)
15556
+ }),
15552
15557
  external_exports.object({ type: external_exports.literal("display-settings-changed"), cursor: clientChannelCursorSchema }),
15553
15558
  external_exports.object({
15554
15559
  type: external_exports.literal("preferences-changed"),
@@ -15620,6 +15625,8 @@ var clientItemTruncationSchema = external_exports.object({
15620
15625
  var clientTurnSchema = external_exports.object({
15621
15626
  id: external_exports.string().min(1),
15622
15627
  status: external_exports.string().min(1),
15628
+ /** Native history has no terminal evidence; Desktop's status vocabulary cannot express this. */
15629
+ codexhostTurnOutcome: external_exports.object({ status: external_exports.literal("unknown"), reason: external_exports.string() }).optional(),
15623
15630
  items: external_exports.array(external_exports.object({ id: external_exports.string().min(1), type: external_exports.string().min(1) }).passthrough()),
15624
15631
  /** Original file operations, independent of the cumulative Desktop fileChange card.
15625
15632
  * Insert before the named non-file Item; null appends at the end of the Turn.
@@ -16836,6 +16843,7 @@ var THREAD_WATCH_NOTICE_OUTCOMES = [
16836
16843
  "completed",
16837
16844
  "failed",
16838
16845
  "interrupted",
16846
+ "needsInput",
16839
16847
  "timedOut",
16840
16848
  "unreadable",
16841
16849
  "notFound"
@@ -16882,13 +16890,26 @@ var target = { hostId: identity.regex(/^remote-(?:ssh(?:-|:)|control:)/u) };
16882
16890
  var thread = { ...target, threadId: identity };
16883
16891
  var remoteSessionOperationSchema = external_exports.discriminatedUnion("kind", [
16884
16892
  external_exports.strictObject({ kind: external_exports.literal("hosts") }),
16893
+ external_exports.strictObject({ kind: external_exports.literal("status"), ...thread }),
16885
16894
  external_exports.strictObject({
16886
16895
  kind: external_exports.literal("list"),
16887
16896
  ...target,
16888
16897
  cursor: external_exports.string().nullable(),
16889
16898
  archived: external_exports.boolean()
16890
16899
  }),
16891
- external_exports.strictObject({ kind: external_exports.literal("read"), ...thread }),
16900
+ external_exports.strictObject({
16901
+ kind: external_exports.literal("read"),
16902
+ ...thread,
16903
+ page: external_exports.strictObject({
16904
+ cursor: external_exports.string().min(1).max(8192).nullable(),
16905
+ epoch: identity.optional(),
16906
+ sortDirection: external_exports.enum(["asc", "desc"]).optional(),
16907
+ limit: external_exports.number().int().min(1).max(20).optional()
16908
+ }).refine((page) => page.cursor === null || page.epoch !== void 0, {
16909
+ message: "A history continuation requires its connection epoch"
16910
+ }).optional()
16911
+ }),
16912
+ external_exports.strictObject({ kind: external_exports.literal("usage"), ...thread, epoch: identity }),
16892
16913
  external_exports.strictObject({
16893
16914
  kind: external_exports.literal("configure"),
16894
16915
  ...thread,
@@ -17020,16 +17041,16 @@ var webUiExtensionRemoveSchema = external_exports.object({ id: webUiExtensionIdS
17020
17041
  var workspaceContractVersionSchema = external_exports.literal(WORKSPACE_CONTRACT_VERSION);
17021
17042
 
17022
17043
  // ../../harness-adapter/dist/approval.js
17023
- function invalidRequest(message2) {
17024
- return { code: "invalidRequest", message: message2, retryable: false };
17044
+ function invalidRequest(message3) {
17045
+ return { code: "invalidRequest", message: message3, retryable: false };
17025
17046
  }
17026
17047
  function validateHostApprovalResponse(interaction, response) {
17027
17048
  return interaction.actions.some(({ id }) => id === response.actionId) ? null : invalidRequest("Approval Response contains an undeclared action ID");
17028
17049
  }
17029
17050
 
17030
17051
  // ../../harness-adapter/dist/question.js
17031
- function invalidRequest2(message2) {
17032
- return { code: "invalidRequest", message: message2, retryable: false };
17052
+ function invalidRequest2(message3) {
17053
+ return { code: "invalidRequest", message: message3, retryable: false };
17033
17054
  }
17034
17055
  function validateHostQuestionResponse(interaction, response) {
17035
17056
  const questionIds = new Set(interaction.questions.map(({ id }) => id));
@@ -17267,6 +17288,7 @@ var requestTokenFields = [
17267
17288
  "cacheWrite1hInputTokens",
17268
17289
  "outputTokens",
17269
17290
  "reasoningOutputTokens",
17291
+ "timedOutputTokens",
17270
17292
  "startedAtMs",
17271
17293
  "completedAtMs"
17272
17294
  ];
@@ -17319,6 +17341,14 @@ function parseHostUsageRequest(value) {
17319
17341
  if (request.startedAtMs === void 0 !== (request.completedAtMs === void 0)) {
17320
17342
  throw new Error("Harness Usage request timing fields must be provided together");
17321
17343
  }
17344
+ if (request.timedOutputTokens !== void 0) {
17345
+ if (request.startedAtMs === void 0) {
17346
+ throw new Error("Harness Usage request 'timedOutputTokens' requires timing fields");
17347
+ }
17348
+ if (request.timedOutputTokens > request.outputTokens) {
17349
+ throw new Error("Harness Usage request 'timedOutputTokens' must not exceed 'outputTokens'");
17350
+ }
17351
+ }
17322
17352
  if (request.startedAtMs !== void 0 && request.completedAtMs !== void 0 && request.completedAtMs < request.startedAtMs) {
17323
17353
  throw new Error("Harness Usage request 'completedAtMs' must not precede 'startedAtMs'");
17324
17354
  }
@@ -19233,8 +19263,8 @@ var Handled = {
19233
19263
  /**
19234
19264
  * Leaves a message unhandled so later handlers can process it.
19235
19265
  */
19236
- no(message2, retry = false) {
19237
- return { handled: false, message: message2, retry };
19266
+ no(message3, retry = false) {
19267
+ return { handled: false, message: message3, retry };
19238
19268
  }
19239
19269
  };
19240
19270
  function rejectedPromise(error51) {
@@ -19481,8 +19511,8 @@ var Connection = class {
19481
19511
  addDynamicHandler(handler) {
19482
19512
  this.dynamicHandlers.add(handler);
19483
19513
  if (this.retryQueue.length > 0) {
19484
- for (const message2 of this.retryQueue.splice(0)) {
19485
- void this.processIncomingMessage(message2).catch((error51) => this.close(error51));
19514
+ for (const message3 of this.retryQueue.splice(0)) {
19515
+ void this.processIncomingMessage(message3).catch((error51) => this.close(error51));
19486
19516
  }
19487
19517
  }
19488
19518
  return new HandlerRegistration(() => {
@@ -19661,12 +19691,12 @@ var Connection = class {
19661
19691
  }
19662
19692
  legacyHandler(requestHandler, notificationHandler) {
19663
19693
  return {
19664
- handleMessage: async (message2, cx) => {
19665
- if (message2.kind === "request") {
19666
- const result = await requestHandler(message2.method, message2.params, cx);
19667
- await message2.responder.respond(result);
19694
+ handleMessage: async (message3, cx) => {
19695
+ if (message3.kind === "request") {
19696
+ const result = await requestHandler(message3.method, message3.params, cx);
19697
+ await message3.responder.respond(result);
19668
19698
  } else {
19669
- await notificationHandler(message2.method, message2.params, cx);
19699
+ await notificationHandler(message3.method, message3.params, cx);
19670
19700
  }
19671
19701
  return Handled.yes();
19672
19702
  }
@@ -19679,17 +19709,17 @@ var Connection = class {
19679
19709
  this.receiveReader = reader;
19680
19710
  try {
19681
19711
  while (!this.abortController.signal.aborted) {
19682
- const { value: message2, done } = await reader.read();
19712
+ const { value: message3, done } = await reader.read();
19683
19713
  if (this.abortController.signal.aborted) {
19684
19714
  break;
19685
19715
  }
19686
19716
  if (done) {
19687
19717
  break;
19688
19718
  }
19689
- if (!message2) {
19719
+ if (!message3) {
19690
19720
  continue;
19691
19721
  }
19692
- this.receiveWireMessage(message2);
19722
+ this.receiveWireMessage(message3);
19693
19723
  }
19694
19724
  } finally {
19695
19725
  if (this.receiveReader === reader) {
@@ -19703,20 +19733,20 @@ var Connection = class {
19703
19733
  this.close(closeError);
19704
19734
  }
19705
19735
  }
19706
- receiveWireMessage(message2) {
19707
- if (Array.isArray(message2)) {
19736
+ receiveWireMessage(message3) {
19737
+ if (Array.isArray(message3)) {
19708
19738
  if (!this.allowBatches) {
19709
19739
  this.close(new TypeError("JSON-RPC batches are not supported on this connection"));
19710
19740
  return;
19711
19741
  }
19712
- this.receiveBatch(message2);
19742
+ this.receiveBatch(message3);
19713
19743
  return;
19714
19744
  }
19715
- if (!isRecord2(message2)) {
19716
- console.error("Invalid message", { message: message2 });
19745
+ if (!isRecord2(message3)) {
19746
+ console.error("Invalid message", { message: message3 });
19717
19747
  return;
19718
19748
  }
19719
- this.receiveMessage(message2);
19749
+ this.receiveMessage(message3);
19720
19750
  }
19721
19751
  receiveBatch(batch) {
19722
19752
  if (batch.length === 0) {
@@ -19729,9 +19759,9 @@ var Connection = class {
19729
19759
  return;
19730
19760
  }
19731
19761
  const responseBatch = isResponseBatch(batch);
19732
- const responseCount = responseBatch ? 0 : batch.reduce((count4, message2) => count4 + (isNotificationMessage(message2) ? 0 : 1), 0);
19762
+ const responseCount = responseBatch ? 0 : batch.reduce((count4, message3) => count4 + (isNotificationMessage(message3) ? 0 : 1), 0);
19733
19763
  let remaining = responseCount;
19734
- let remainingNotifications = batch.reduce((count4, message2) => count4 + (isNotificationMessage(message2) ? 1 : 0), 0);
19764
+ let remainingNotifications = batch.reduce((count4, message3) => count4 + (isNotificationMessage(message3) ? 1 : 0), 0);
19735
19765
  let responseSent = false;
19736
19766
  const responses = [];
19737
19767
  const sendResponsesIfReady = async () => {
@@ -19746,24 +19776,24 @@ var Connection = class {
19746
19776
  remaining -= 1;
19747
19777
  await sendResponsesIfReady();
19748
19778
  };
19749
- for (const message2 of batch) {
19779
+ for (const message3 of batch) {
19750
19780
  if (responseBatch) {
19751
- if (isResponseShapedMessage(message2)) {
19752
- this.receiveMessage(message2);
19781
+ if (isResponseShapedMessage(message3)) {
19782
+ this.receiveMessage(message3);
19753
19783
  }
19754
19784
  continue;
19755
19785
  }
19756
- if (!isRequestMessage(message2) && !isNotificationMessage(message2)) {
19786
+ if (!isRequestMessage(message3) && !isNotificationMessage(message3)) {
19757
19787
  void collectResponse({
19758
19788
  jsonrpc: "2.0",
19759
19789
  id: null,
19760
- error: RequestError.invalidRequest(message2).toErrorResponse()
19790
+ error: RequestError.invalidRequest(message3).toErrorResponse()
19761
19791
  }).catch(() => {
19762
19792
  });
19763
19793
  continue;
19764
19794
  }
19765
- const processing = this.receiveMessage(message2, isRequestMessage(message2) ? collectResponse : void 0);
19766
- if (isNotificationMessage(message2)) {
19795
+ const processing = this.receiveMessage(message3, isRequestMessage(message3) ? collectResponse : void 0);
19796
+ if (isNotificationMessage(message3)) {
19767
19797
  void processing.finally(() => {
19768
19798
  remainingNotifications -= 1;
19769
19799
  void sendResponsesIfReady().catch((error51) => this.close(error51));
@@ -19771,31 +19801,31 @@ var Connection = class {
19771
19801
  }
19772
19802
  }
19773
19803
  }
19774
- receiveMessage(message2, sendResponse) {
19804
+ receiveMessage(message3, sendResponse) {
19775
19805
  if (this.abortController.signal.aborted) {
19776
19806
  return Promise.resolve();
19777
19807
  }
19778
- if (!isRecord2(message2)) {
19779
- console.error("Invalid message", { message: message2 });
19808
+ if (!isRecord2(message3)) {
19809
+ console.error("Invalid message", { message: message3 });
19780
19810
  return Promise.resolve();
19781
19811
  }
19782
- if ("method" in message2) {
19783
- if (!("id" in message2)) {
19784
- this.handleProtocolNotification(message2);
19812
+ if ("method" in message3) {
19813
+ if (!("id" in message3)) {
19814
+ this.handleProtocolNotification(message3);
19785
19815
  }
19786
- return this.processIncomingMessage(this.toIncomingMessage(message2, sendResponse)).catch((error51) => this.close(error51));
19787
- } else if ("id" in message2) {
19788
- this.handleResponse(message2);
19816
+ return this.processIncomingMessage(this.toIncomingMessage(message3, sendResponse)).catch((error51) => this.close(error51));
19817
+ } else if ("id" in message3) {
19818
+ this.handleResponse(message3);
19789
19819
  } else {
19790
- console.error("Invalid message", { message: message2 });
19820
+ console.error("Invalid message", { message: message3 });
19791
19821
  }
19792
19822
  return Promise.resolve();
19793
19823
  }
19794
- async processIncomingMessage(message2) {
19824
+ async processIncomingMessage(message3) {
19795
19825
  if (this.abortController.signal.aborted) {
19796
19826
  return;
19797
19827
  }
19798
- let current = message2;
19828
+ let current = message3;
19799
19829
  let retry = false;
19800
19830
  try {
19801
19831
  for (const handler of [
@@ -19828,30 +19858,30 @@ var Connection = class {
19828
19858
  } else {
19829
19859
  const response = errorToResult(error51);
19830
19860
  if ("error" in response) {
19831
- console.error("Error handling notification", message2.raw, response.error);
19861
+ console.error("Error handling notification", message3.raw, response.error);
19832
19862
  }
19833
19863
  }
19834
19864
  }
19835
19865
  }
19836
- toIncomingMessage(message2, sendResponse) {
19837
- if ("id" in message2) {
19866
+ toIncomingMessage(message3, sendResponse) {
19867
+ if ("id" in message3) {
19838
19868
  const abortController = new AbortController();
19839
- this.incomingRequests.set(message2.id, abortController);
19869
+ this.incomingRequests.set(message3.id, abortController);
19840
19870
  const finishRequest = () => {
19841
- if (this.incomingRequests.get(message2.id) === abortController) {
19842
- this.incomingRequests.delete(message2.id);
19871
+ if (this.incomingRequests.get(message3.id) === abortController) {
19872
+ this.incomingRequests.delete(message3.id);
19843
19873
  }
19844
19874
  };
19845
19875
  return {
19846
19876
  kind: "request",
19847
- method: message2.method,
19848
- params: message2.params,
19849
- raw: message2,
19877
+ method: message3.method,
19878
+ params: message3.params,
19879
+ raw: message3,
19850
19880
  signal: abortController.signal,
19851
- responder: new RequestResponder(message2.id, (result) => {
19881
+ responder: new RequestResponder(message3.id, (result) => {
19852
19882
  const response = {
19853
19883
  jsonrpc: "2.0",
19854
- id: message2.id,
19884
+ id: message3.id,
19855
19885
  ...result
19856
19886
  };
19857
19887
  return sendResponse ? sendResponse(response) : this.sendWireMessage(response);
@@ -19860,9 +19890,9 @@ var Connection = class {
19860
19890
  }
19861
19891
  return {
19862
19892
  kind: "notification",
19863
- method: message2.method,
19864
- params: message2.params,
19865
- raw: message2
19893
+ method: message3.method,
19894
+ params: message3.params,
19895
+ raw: message3
19866
19896
  };
19867
19897
  }
19868
19898
  handleResponse(response) {
@@ -19875,18 +19905,18 @@ var Connection = class {
19875
19905
  } else if ("result" in response) {
19876
19906
  pendingResponse.resolve(response.result);
19877
19907
  } else {
19878
- const { code, message: message2, data } = response.error;
19879
- pendingResponse.reject(new RequestError(code, message2, data));
19908
+ const { code, message: message3, data } = response.error;
19909
+ pendingResponse.reject(new RequestError(code, message3, data));
19880
19910
  }
19881
19911
  } else {
19882
19912
  console.error("Got response to unknown request", response.id);
19883
19913
  }
19884
19914
  }
19885
- handleProtocolNotification(message2) {
19886
- if (message2.method !== CANCEL_REQUEST_METHOD) {
19915
+ handleProtocolNotification(message3) {
19916
+ if (message3.method !== CANCEL_REQUEST_METHOD) {
19887
19917
  return;
19888
19918
  }
19889
- const requestId = cancelRequestId(message2.params);
19919
+ const requestId = cancelRequestId(message3.params);
19890
19920
  if (requestId === void 0) {
19891
19921
  return;
19892
19922
  }
@@ -19899,7 +19929,7 @@ var Connection = class {
19899
19929
  closedReason() {
19900
19930
  return this.abortController.signal.reason ?? new Error("ACP connection closed");
19901
19931
  }
19902
- async sendWireMessage(message2) {
19932
+ async sendWireMessage(message3) {
19903
19933
  if (this.abortController.signal.aborted) {
19904
19934
  return rejectedPromise(this.closedReason());
19905
19935
  }
@@ -19909,7 +19939,7 @@ var Connection = class {
19909
19939
  }
19910
19940
  const writer = this.stream.writable.getWriter();
19911
19941
  try {
19912
- await writer.write(message2);
19942
+ await writer.write(message3);
19913
19943
  } finally {
19914
19944
  writer.releaseLock();
19915
19945
  }
@@ -19945,7 +19975,7 @@ var ConnectionBuilder = class {
19945
19975
  */
19946
19976
  onReceiveMessage(handler) {
19947
19977
  return this.withHandler({
19948
- handleMessage: async (message2, cx) => await handler(message2, cx) ?? Handled.no(message2),
19978
+ handleMessage: async (message3, cx) => await handler(message3, cx) ?? Handled.no(message3),
19949
19979
  describe: () => this.connectionName ?? "onReceiveMessage"
19950
19980
  });
19951
19981
  }
@@ -19954,12 +19984,12 @@ var ConnectionBuilder = class {
19954
19984
  */
19955
19985
  onReceiveRequest(method, parse3, handler) {
19956
19986
  return this.withHandler({
19957
- handleMessage: async (message2, cx) => {
19958
- if (message2.kind !== "request" || message2.method !== method) {
19959
- return Handled.no(message2);
19987
+ handleMessage: async (message3, cx) => {
19988
+ if (message3.kind !== "request" || message3.method !== method) {
19989
+ return Handled.no(message3);
19960
19990
  }
19961
- const request = parse3(message2.params);
19962
- return await handler(request, message2.responder, cx) ?? Handled.yes();
19991
+ const request = parse3(message3.params);
19992
+ return await handler(request, message3.responder, cx) ?? Handled.yes();
19963
19993
  },
19964
19994
  describe: () => `${this.connectionName ?? "request"}:${method}`
19965
19995
  });
@@ -19969,11 +19999,11 @@ var ConnectionBuilder = class {
19969
19999
  */
19970
20000
  onReceiveNotification(method, parse3, handler) {
19971
20001
  return this.withHandler({
19972
- handleMessage: async (message2, cx) => {
19973
- if (message2.kind !== "notification" || message2.method !== method) {
19974
- return Handled.no(message2);
20002
+ handleMessage: async (message3, cx) => {
20003
+ if (message3.kind !== "notification" || message3.method !== method) {
20004
+ return Handled.no(message3);
19975
20005
  }
19976
- const notification = parse3(message2.params);
20006
+ const notification = parse3(message3.params);
19977
20007
  return await handler(notification, cx) ?? Handled.yes();
19978
20008
  },
19979
20009
  describe: () => `${this.connectionName ?? "notification"}:${method}`
@@ -19998,8 +20028,8 @@ var RequestError = class _RequestError extends Error {
19998
20028
  * Additional JSON-RPC error data.
19999
20029
  */
20000
20030
  data;
20001
- constructor(code, message2, data) {
20002
- super(message2);
20031
+ constructor(code, message3, data) {
20032
+ super(message3);
20003
20033
  this.code = code;
20004
20034
  this.name = "RequestError";
20005
20035
  this.data = data;
@@ -20144,9 +20174,9 @@ function ndJsonStream(output, input) {
20144
20174
  const trimmedLine = textDecoder.decode(lineBytes).trim();
20145
20175
  if (trimmedLine) {
20146
20176
  try {
20147
- const message2 = JSON.parse(trimmedLine);
20148
- if (isRecord2(message2) || Array.isArray(message2)) {
20149
- controller.enqueue(message2);
20177
+ const message3 = JSON.parse(trimmedLine);
20178
+ if (isRecord2(message3) || Array.isArray(message3)) {
20179
+ controller.enqueue(message3);
20150
20180
  } else {
20151
20181
  console.warn("Skipping JSON line that is not an object:", trimmedLine);
20152
20182
  }
@@ -20206,8 +20236,8 @@ function ndJsonStream(output, input) {
20206
20236
  }
20207
20237
  });
20208
20238
  const writable = new WritableStream({
20209
- async write(message2) {
20210
- const content = JSON.stringify(message2) + "\n";
20239
+ async write(message3) {
20240
+ const content = JSON.stringify(message3) + "\n";
20211
20241
  const writer = output.getWriter();
20212
20242
  try {
20213
20243
  await writer.write(textEncoder.encode(content));
@@ -20694,11 +20724,11 @@ var ActiveSession = class _ActiveSession {
20694
20724
  async readText() {
20695
20725
  let output = "";
20696
20726
  for (; ; ) {
20697
- const message2 = await this.nextUpdate();
20698
- if (message2.kind === "stop") {
20727
+ const message3 = await this.nextUpdate();
20728
+ if (message3.kind === "stop") {
20699
20729
  return output;
20700
20730
  }
20701
- const { update } = message2;
20731
+ const { update } = message3;
20702
20732
  if (update.sessionUpdate === "agent_message_chunk" && update.content.type === "text") {
20703
20733
  output += update.content.text;
20704
20734
  }
@@ -20846,11 +20876,11 @@ function clientNotificationContext(params, agent, signal) {
20846
20876
  }
20847
20877
  var SessionUpdateRouter = class {
20848
20878
  activeSessions = /* @__PURE__ */ new Map();
20849
- handleMessage(message2) {
20850
- if (message2.kind !== "notification" || message2.method !== CLIENT_METHODS.session_update) {
20851
- return Handled.no(message2);
20879
+ handleMessage(message3) {
20880
+ if (message3.kind !== "notification" || message3.method !== CLIENT_METHODS.session_update) {
20881
+ return Handled.no(message3);
20852
20882
  }
20853
- const notification = zSessionNotification.parse(message2.params);
20883
+ const notification = zSessionNotification.parse(message3.params);
20854
20884
  const update = {
20855
20885
  kind: "session_update",
20856
20886
  notification,
@@ -20862,7 +20892,7 @@ var SessionUpdateRouter = class {
20862
20892
  session.enqueue(update);
20863
20893
  }
20864
20894
  }
20865
- return Handled.no(message2);
20895
+ return Handled.no(message3);
20866
20896
  }
20867
20897
  attach(response, updates) {
20868
20898
  const sessions = this.activeSessions.get(response.sessionId) ?? /* @__PURE__ */ new Set();
@@ -21007,7 +21037,7 @@ var ClientApp = class {
21007
21037
  this.builder.name(options.name);
21008
21038
  }
21009
21039
  this.builder.withHandler({
21010
- handleMessage: (message2, cx) => sessionUpdateRouter(cx).handleMessage(message2),
21040
+ handleMessage: (message3, cx) => sessionUpdateRouter(cx).handleMessage(message3),
21011
21041
  describe: () => "client-session-update-router"
21012
21042
  });
21013
21043
  }
@@ -21150,11 +21180,11 @@ function legacyClientApp(implementation) {
21150
21180
  }
21151
21181
  if (implementation.extMethod) {
21152
21182
  app[appBuilder]().withHandler({
21153
- handleMessage: async (message2) => {
21154
- if (message2.kind !== "request" || legacyClientRequestMethods.has(message2.method)) {
21155
- return Handled.no(message2);
21183
+ handleMessage: async (message3) => {
21184
+ if (message3.kind !== "request" || legacyClientRequestMethods.has(message3.method)) {
21185
+ return Handled.no(message3);
21156
21186
  }
21157
- await message2.responder.respond(await implementation.extMethod(message2.method, message2.params));
21187
+ await message3.responder.respond(await implementation.extMethod(message3.method, message3.params));
21158
21188
  return Handled.yes();
21159
21189
  },
21160
21190
  describe: () => "legacy-client-extension-request"
@@ -21162,11 +21192,11 @@ function legacyClientApp(implementation) {
21162
21192
  }
21163
21193
  if (implementation.extNotification) {
21164
21194
  app[appBuilder]().withHandler({
21165
- handleMessage: async (message2) => {
21166
- if (message2.kind !== "notification" || legacyClientNotificationMethods.has(message2.method)) {
21167
- return Handled.no(message2);
21195
+ handleMessage: async (message3) => {
21196
+ if (message3.kind !== "notification" || legacyClientNotificationMethods.has(message3.method)) {
21197
+ return Handled.no(message3);
21168
21198
  }
21169
- await implementation.extNotification(message2.method, message2.params);
21199
+ await implementation.extNotification(message3.method, message3.params);
21170
21200
  return Handled.yes();
21171
21201
  },
21172
21202
  describe: () => "legacy-client-extension-notification"
@@ -22221,9 +22251,9 @@ function extractString(record4, keys) {
22221
22251
  }
22222
22252
  for (const wrapper of ["input", "arguments", "params", "parameters"]) {
22223
22253
  if (isRecord3(record4[wrapper])) {
22224
- const nested = extractString(record4[wrapper], keys);
22225
- if (nested !== void 0)
22226
- return nested;
22254
+ const nested2 = extractString(record4[wrapper], keys);
22255
+ if (nested2 !== void 0)
22256
+ return nested2;
22227
22257
  }
22228
22258
  }
22229
22259
  return void 0;
@@ -22696,6 +22726,7 @@ var AntigravityToolTracker = class {
22696
22726
  };
22697
22727
  function projectReplayedEventsToTurns(params) {
22698
22728
  const turns = [];
22729
+ const usedTurnKeys = new Set(params.knownTurnRefs?.map(({ nativeTurnKey }) => nativeTurnKey));
22699
22730
  let active;
22700
22731
  let userRun = false;
22701
22732
  let textItem;
@@ -22703,15 +22734,23 @@ function projectReplayedEventsToTurns(params) {
22703
22734
  const begin = () => {
22704
22735
  active?.tracker.finishPending({
22705
22736
  status: "cancelled",
22706
- reason: "No terminal tool status in ACP replay"
22737
+ reason: "No terminal tool status in native history"
22707
22738
  });
22708
22739
  const index = turns.length;
22709
22740
  const turnId = hostTurnIdSchema.parse(`turn-${index}`);
22741
+ let nativeTurnKey = params.knownTurnRefs?.[index]?.nativeTurnKey;
22742
+ if (nativeTurnKey === void 0) {
22743
+ let n = index;
22744
+ nativeTurnKey = `turn-${n}`;
22745
+ while (usedTurnKeys.has(nativeTurnKey))
22746
+ nativeTurnKey = `turn-${++n}`;
22747
+ usedTurnKeys.add(nativeTurnKey);
22748
+ }
22710
22749
  const turn = {
22711
22750
  nativeTurnRef: nativeTurnRefSchema.parse({
22712
22751
  harnessId: "antigravity",
22713
22752
  nativeSessionId: params.nativeSessionId,
22714
- nativeTurnKey: params.knownTurnRefs?.[index]?.nativeTurnKey ?? `turn-${index}`,
22753
+ nativeTurnKey,
22715
22754
  formatVersion: 1
22716
22755
  }),
22717
22756
  checkpoint: nativeCheckpointRefSchema.parse({
@@ -22722,7 +22761,7 @@ function projectReplayedEventsToTurns(params) {
22722
22761
  }),
22723
22762
  input: [],
22724
22763
  items: [],
22725
- outcome: { status: "unknown", reason: "ACP replay does not include prompt stop reasons" }
22764
+ outcome: { status: "unknown", reason: "Native history does not include prompt stop reasons" }
22726
22765
  };
22727
22766
  turns.push(turn);
22728
22767
  sequence = 0;
@@ -22782,7 +22821,7 @@ function projectReplayedEventsToTurns(params) {
22782
22821
  }
22783
22822
  active?.tracker.finishPending({
22784
22823
  status: "cancelled",
22785
- reason: "No terminal tool status in ACP replay"
22824
+ reason: "No terminal tool status in native history"
22786
22825
  });
22787
22826
  return turns;
22788
22827
  }
@@ -22820,8 +22859,8 @@ var AntigravityTransportError = class extends Error {
22820
22859
  kind;
22821
22860
  diagnostic;
22822
22861
  retryable;
22823
- constructor(kind, message2, options) {
22824
- super(message2, options);
22862
+ constructor(kind, message3, options) {
22863
+ super(message3, options);
22825
22864
  this.kind = kind;
22826
22865
  this.name = "AntigravityTransportError";
22827
22866
  this.diagnostic = options?.diagnostic;
@@ -22908,18 +22947,24 @@ var AntigravityAcpTransport = class {
22908
22947
  child.on("error", (error51) => this.#fault(new AntigravityTransportError(error51.code === "ENOENT" ? "notInstalled" : "unavailable", error51.message, { diagnostic: this.#stderr })));
22909
22948
  child.on("exit", (code, signal) => this.#fault(new AntigravityTransportError("processExited", `Antigravity ACP exited (code ${code}, signal ${signal})`, { diagnostic: this.#stderr })));
22910
22949
  child.stdin.on("error", (error51) => this.#fault(this.#error(error51)));
22911
- const stream = ndJsonStream2(Writable.toWeb(child.stdin), Readable.toWeb(child.stdout));
22950
+ const stream = ndJsonStream2(
22951
+ Writable.toWeb(child.stdin),
22952
+ // Keep draining ACP stdout even when the consumer is slow.
22953
+ Readable.toWeb(child.stdout, {
22954
+ strategy: { highWaterMark: Infinity }
22955
+ })
22956
+ );
22912
22957
  const nativeMethods = /* @__PURE__ */ new Set(["session/request_permission", "elicitation/create"]);
22913
22958
  stream.readable = stream.readable.pipeThrough(new TransformStream({
22914
- transform: (message2, controller) => {
22915
- if ("method" in message2 && message2.method === "session/update") {
22916
- const params = message2.params;
22959
+ transform: (message3, controller) => {
22960
+ if ("method" in message3 && message3.method === "session/update") {
22961
+ const params = message3.params;
22917
22962
  this.#update(params.sessionId, params.update);
22918
22963
  return;
22919
22964
  }
22920
- if ("method" in message2 && nativeMethods.has(message2.method))
22921
- message2.method = `_antigravity/${message2.method}`;
22922
- controller.enqueue(message2);
22965
+ if ("method" in message3 && nativeMethods.has(message3.method))
22966
+ message3.method = `_antigravity/${message3.method}`;
22967
+ controller.enqueue(message3);
22923
22968
  }
22924
22969
  }));
22925
22970
  const onElicitation = (request) => this.#callback("sessionId" in request ? request.sessionId : void 0, (handler) => handler.onElicitation(request), { action: "cancel" });
@@ -22974,9 +23019,8 @@ var AntigravityAcpTransport = class {
22974
23019
  request = connection.newSession(params);
22975
23020
  else {
22976
23021
  if (!input.sessionId)
22977
- throw new AntigravityTransportError("protocolError", "Session ID required for resume/load");
22978
- const target2 = { ...params, sessionId: input.sessionId };
22979
- request = input.kind === "resume" ? connection.resumeSession(target2) : connection.loadSession(target2);
23022
+ throw new AntigravityTransportError("protocolError", "Session ID required for resume");
23023
+ request = connection.resumeSession({ ...params, sessionId: input.sessionId });
22980
23024
  }
22981
23025
  const result = await this.#request(request, `session/${input.kind === "create" ? "new" : input.kind}`);
22982
23026
  const raw = result;
@@ -22984,10 +23028,9 @@ var AntigravityAcpTransport = class {
22984
23028
  if (!sessionId)
22985
23029
  throw new AntigravityTransportError("protocolError", "Antigravity session/new returned no sessionId");
22986
23030
  this.#sessionId = sessionId;
22987
- const events = buffered.filter((entry) => entry.sessionId === sessionId).map(({ event }) => event);
22988
- if (input.kind !== "load")
22989
- for (const event of events)
22990
- this.#dispatch(event);
23031
+ for (const entry of buffered)
23032
+ if (entry.sessionId === sessionId)
23033
+ this.#dispatch(entry.event);
22991
23034
  return {
22992
23035
  opened: {
22993
23036
  sessionId,
@@ -22995,8 +23038,7 @@ var AntigravityAcpTransport = class {
22995
23038
  ...raw.modes ? { modes: raw.modes } : {},
22996
23039
  ...raw.configOptions ? { configOptions: raw.configOptions } : {},
22997
23040
  ...raw._meta?.antigravity?.tier ? { tier: raw._meta.antigravity.tier } : {}
22998
- },
22999
- replayedEvents: input.kind === "load" ? events : []
23041
+ }
23000
23042
  };
23001
23043
  } finally {
23002
23044
  this.#opening = null;
@@ -23155,9 +23197,9 @@ ${this.#error(error51).message}`.slice(-32e3);
23155
23197
  #error(error51) {
23156
23198
  if (error51 instanceof AntigravityTransportError)
23157
23199
  return error51;
23158
- const message2 = sanitizeDiagnosticTail(error51 instanceof Error ? error51.message : String(error51));
23200
+ const message3 = sanitizeDiagnosticTail(error51 instanceof Error ? error51.message : String(error51));
23159
23201
  const code = error51?.code;
23160
- return new AntigravityTransportError(code === -32e3 || /auth|login|sign[ -]?in|unauthenticated/iu.test(message2) ? "authenticationRequired" : "unavailable", message2, { cause: error51, diagnostic: this.#stderr });
23202
+ return new AntigravityTransportError(code === -32e3 || /auth|login|sign[ -]?in|unauthenticated/iu.test(message3) ? "authenticationRequired" : "unavailable", message3, { cause: error51, diagnostic: this.#stderr });
23161
23203
  }
23162
23204
  #fault(error51) {
23163
23205
  if (this.#closed || this.#faultSignal.signal.aborted)
@@ -23279,31 +23321,40 @@ function stepIndices(fields) {
23279
23321
  function matchesUsage(fields, request) {
23280
23322
  if (!fields)
23281
23323
  return false;
23282
- const input = unsigned(fields, 2), output = unsigned(fields, 3), cached2 = unsigned(fields, 5);
23283
- return input !== null && output !== null && cached2 !== null && input + cached2 + BigInt(request.cacheWriteInputTokens ?? 0) === BigInt(request.inputTokens) && output === BigInt(request.outputTokens) && (request.cachedInputTokens === void 0 || cached2 === BigInt(request.cachedInputTokens));
23324
+ const input = unsigned(fields, 2), output = unsigned(fields, 3), cached2 = unsigned(fields, 5), thought = unsigned(fields, 9);
23325
+ return input !== null && output !== null && cached2 !== null && thought !== null && output >= thought && (request.reasoningOutputTokens === void 0 || thought === BigInt(request.reasoningOutputTokens)) && input + cached2 + BigInt(request.cacheWriteInputTokens ?? 0) === BigInt(request.inputTokens) && output === BigInt(request.outputTokens) && (request.cachedInputTokens === void 0 || cached2 === BigInt(request.cachedInputTokens));
23284
23326
  }
23285
23327
  function closeTo(left, right) {
23286
23328
  const difference = left - right;
23287
23329
  return difference >= -NANOSECONDS_PER_MS && difference <= NANOSECONDS_PER_MS;
23288
23330
  }
23289
- function timing(metadata, generator, request) {
23331
+ function requestMetadata(metadata, generator, request) {
23290
23332
  const chat = message(generator, 1);
23291
- if (!chat || !matchesUsage(message(metadata, 9), request) || !matchesUsage(message(chat, 4), request))
23333
+ const stepUsage = message(metadata, 9);
23334
+ const chatUsage = chat && message(chat, 4);
23335
+ if (!chat || !stepUsage || !chatUsage || !matchesUsage(stepUsage, request) || !matchesUsage(chatUsage, request))
23292
23336
  return null;
23293
- if (unsigned(chat, 14) !== 0n || chat.filter((value) => value.number === 17).length > 1)
23337
+ const thought = unsigned(stepUsage, 9);
23338
+ if (thought === null || thought !== unsigned(chatUsage, 9))
23294
23339
  return null;
23340
+ const facts = { reasoningOutputTokens: Number(thought) };
23341
+ if (unsigned(chat, 14) !== 0n || chat.filter((value) => value.number === 17).length > 1)
23342
+ return facts;
23295
23343
  const created = nanoseconds(message(metadata, 1));
23296
23344
  const started = nanoseconds(message(metadata, 6));
23297
23345
  const completed = nanoseconds(message(metadata, 7));
23298
23346
  const ttft = nanoseconds(message(chat, 11));
23299
23347
  const streamed = nanoseconds(message(chat, 12));
23300
23348
  if (created === null || started === null || completed === null || ttft === null || streamed === null || started < created || completed <= started || streamed <= 0n || !closeTo(started - created, ttft) || !closeTo(completed - started, streamed))
23301
- return null;
23349
+ return facts;
23302
23350
  const startedAtMs = Number(started / NANOSECONDS_PER_MS);
23303
23351
  const completedAtMs = Number(completed / NANOSECONDS_PER_MS);
23304
- return completedAtMs > startedAtMs ? { startedAtMs, completedAtMs } : null;
23352
+ return {
23353
+ ...facts,
23354
+ ...completedAtMs > startedAtMs ? { timing: { startedAtMs, completedAtMs } } : {}
23355
+ };
23305
23356
  }
23306
- async function readAntigravityRequestTimings(nativeSessionId, home, requests, neededSteps = new Set(requests.keys())) {
23357
+ async function readAntigravityRequestMetadata(nativeSessionId, home, requests, neededSteps = new Set(requests.keys())) {
23307
23358
  if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/u.test(nativeSessionId))
23308
23359
  return null;
23309
23360
  let database;
@@ -23327,6 +23378,10 @@ async function readAntigravityRequestTimings(nativeSessionId, home, requests, ne
23327
23378
  const cascade = source && field2(source, 4);
23328
23379
  if (!metadata || !source || cascade?.wire !== 2 || !(cascade.value instanceof Uint8Array) || Buffer.from(cascade.value).toString("utf8") !== nativeSessionId || unsigned(source, 2) !== BigInt(index) || generatorIndex === null || generatorIndex > BigInt(Number.MAX_SAFE_INTEGER))
23329
23380
  continue;
23381
+ const usage = message(metadata, 9);
23382
+ if (!usage || !matchesUsage(usage, request))
23383
+ continue;
23384
+ result.set(index, { reasoningOutputTokens: Number(unsigned(usage, 9)) });
23330
23385
  const generated = generatorQuery.get(Number(generatorIndex));
23331
23386
  if (!(generated?.data instanceof Uint8Array))
23332
23387
  continue;
@@ -23337,9 +23392,11 @@ async function readAntigravityRequestTimings(nativeSessionId, home, requests, ne
23337
23392
  const plannerSteps = [...new Set(indices.filter((step) => requests.get(step)))];
23338
23393
  if (plannerSteps.length !== 1 || plannerSteps[0] !== index)
23339
23394
  continue;
23340
- const clock = timing(metadata, fields, request);
23341
- if (clock)
23342
- result.set(index, clock);
23395
+ const facts = requestMetadata(metadata, fields, request);
23396
+ if (facts)
23397
+ result.set(index, facts);
23398
+ else
23399
+ result.delete(index);
23343
23400
  }
23344
23401
  return result;
23345
23402
  } catch {
@@ -23402,7 +23459,7 @@ function promptUsage(raw) {
23402
23459
  return null;
23403
23460
  }
23404
23461
  }
23405
- function timing2(input) {
23462
+ function timing(input) {
23406
23463
  const { firstOutputAtMs, completedAtMs } = input;
23407
23464
  return count2(firstOutputAtMs) && count2(completedAtMs) && completedAtMs >= firstOutputAtMs ? { startedAtMs: firstOutputAtMs, completedAtMs } : {};
23408
23465
  }
@@ -23470,9 +23527,6 @@ var AntigravitySessionUsageTracker = class {
23470
23527
  this.#home = options.homedir;
23471
23528
  this.#expectedInitialTurns = options.expectedInitialTurns ?? 0;
23472
23529
  this.#file = path7.join(options.homedir, ".gemini", "antigravity-cli", "brain", options.nativeSessionId, ".system_generated", "logs", "transcript.jsonl");
23473
- if (options.initialContextUsedTokens !== void 0 && options.initialContextWindowTokens !== void 0) {
23474
- this.recordContextWindow(options.initialContextUsedTokens, options.initialContextWindowTokens);
23475
- }
23476
23530
  }
23477
23531
  currentUsage() {
23478
23532
  const recorded = [...this.#requests].sort(([left], [right]) => left - right).map(([, request]) => request);
@@ -23513,7 +23567,7 @@ var AntigravitySessionUsageTracker = class {
23513
23567
  this.#turnActive = false;
23514
23568
  }
23515
23569
  #historyComplete() {
23516
- return this.#complete && !this.#invalidated && !this.#turnActive && !this.#pending;
23570
+ return this.#complete && !this.#invalidated && !this.#pending;
23517
23571
  }
23518
23572
  #reconcile() {
23519
23573
  if (this.#pending && usageMatches(requestUsage([...this.#requests.values()]), addUsage(this.#pending.base, this.#pending.usage), false))
@@ -23556,8 +23610,8 @@ var AntigravitySessionUsageTracker = class {
23556
23610
  const requests = this.#consume(transcript, false, cacheUsage, input.completedAtMs !== void 0);
23557
23611
  const single = requests[0];
23558
23612
  const step = [...this.#turnCollectionSteps][0];
23559
- if (!hadPending && !input.hasToolCalls && transcript.timings === null && usage?.inputTokens !== void 0 && usage.outputTokens !== void 0 && requests.length === 1 && single && step !== void 0 && !transcript.toolCallSteps.has(step) && this.#turnCollectionSteps.size === 1 && transcript.complete && !this.#invalidated && usageMatches(requestUsage([single]), usage, true)) {
23560
- const updated = parseHostUsageRequest({ ...single, ...timing2(input) });
23613
+ if (!hadPending && !input.hasToolCalls && transcript.metadata === null && single?.reasoningOutputTokens === 0 && usage?.inputTokens !== void 0 && usage.outputTokens !== void 0 && requests.length === 1 && single && step !== void 0 && !transcript.toolCallSteps.has(step) && this.#turnCollectionSteps.size === 1 && transcript.complete && !this.#invalidated && usageMatches(requestUsage([single]), usage, true)) {
23614
+ const updated = parseHostUsageRequest({ ...single, ...timing(input) });
23561
23615
  requests[0] = updated;
23562
23616
  this.#requests.set(step, updated);
23563
23617
  }
@@ -23572,7 +23626,7 @@ var AntigravitySessionUsageTracker = class {
23572
23626
  const request = this.#requests.get(step);
23573
23627
  if (request?.startedAtMs === void 0 || request.completedAtMs === void 0 || request.completedAtMs <= request.startedAtMs || request.outputTokens <= 0)
23574
23628
  continue;
23575
- tokens += request.outputTokens;
23629
+ tokens += request.timedOutputTokens ?? request.outputTokens;
23576
23630
  milliseconds += request.completedAtMs - request.startedAtMs;
23577
23631
  }
23578
23632
  if (milliseconds > 0)
@@ -23599,13 +23653,18 @@ var AntigravitySessionUsageTracker = class {
23599
23653
  this.#invalidated = true;
23600
23654
  continue;
23601
23655
  }
23602
- let parsed = request;
23656
+ const write = cacheUsage?.cacheWriteInputTokens;
23657
+ const singleMatches = steps.size === 1 && cacheUsage?.inputTokens !== void 0 && request.inputTokens - (request.cacheWriteInputTokens ?? 0) === cacheUsage.inputTokens - (write ?? 0) && request.outputTokens === cacheUsage.outputTokens && (cacheUsage.cachedInputTokens === void 0 || request.cachedInputTokens === cacheUsage.cachedInputTokens);
23658
+ const native = transcript.metadata?.get(step);
23659
+ const thought = !historical && singleMatches && transcript.complete ? cacheUsage?.reasoningOutputTokens ?? native?.reasoningOutputTokens : native?.reasoningOutputTokens;
23660
+ let parsed = parseHostUsageRequest({
23661
+ ...request,
23662
+ ...thought !== void 0 && thought <= request.outputTokens ? { reasoningOutputTokens: thought } : {}
23663
+ });
23603
23664
  if (!historical && request.cachedInputTokens !== void 0 && request.cacheWriteInputTokens === void 0) {
23604
- const write = cacheUsage?.cacheWriteInputTokens;
23605
- const singleMatches = steps.size === 1 && cacheUsage?.inputTokens !== void 0 && request.inputTokens === cacheUsage.inputTokens - (write ?? 0) && request.outputTokens === cacheUsage.outputTokens && (cacheUsage.cachedInputTokens === void 0 || request.cachedInputTokens === cacheUsage.cachedInputTokens);
23606
23665
  if (write === 0 || write !== void 0 && singleMatches && transcript.complete)
23607
23666
  parsed = parseHostUsageRequest({
23608
- ...request,
23667
+ ...parsed,
23609
23668
  inputTokens: request.inputTokens + (write ?? 0),
23610
23669
  cacheWriteInputTokens: write
23611
23670
  });
@@ -23614,9 +23673,13 @@ var AntigravitySessionUsageTracker = class {
23614
23673
  this.#complete = false;
23615
23674
  continue;
23616
23675
  }
23617
- const candidate = transcript.timings?.get(step);
23618
- const clock = candidate && (historical || candidate.startedAtMs >= this.#turnStartedAtMs) && candidate.completedAtMs <= Date.now() ? candidate : void 0;
23619
- if (!historical && this.#turnActive && !finalizing && transcript.timings !== null && !clock && !transcript.toolCallSteps.has(step))
23676
+ const candidate = native?.timing;
23677
+ const clock = parsed.reasoningOutputTokens !== void 0 && parsed.reasoningOutputTokens === native?.reasoningOutputTokens && // A thinking-only request has no output inside the visible window to time.
23678
+ parsed.reasoningOutputTokens < parsed.outputTokens && !transcript.toolCallSteps.has(step) && candidate && (historical || candidate.startedAtMs >= this.#turnStartedAtMs) && candidate.completedAtMs <= Date.now() ? {
23679
+ ...candidate,
23680
+ timedOutputTokens: parsed.outputTokens - parsed.reasoningOutputTokens
23681
+ } : void 0;
23682
+ if (!historical && this.#turnActive && !finalizing && transcript.metadata !== null && !clock && !transcript.toolCallSteps.has(step))
23620
23683
  continue;
23621
23684
  parsed = parseHostUsageRequest({
23622
23685
  ...parsed,
@@ -23637,7 +23700,7 @@ var AntigravitySessionUsageTracker = class {
23637
23700
  steps: /* @__PURE__ */ new Map(),
23638
23701
  toolCallSteps: /* @__PURE__ */ new Set(),
23639
23702
  complete: true,
23640
- timings: null
23703
+ metadata: null
23641
23704
  };
23642
23705
  try {
23643
23706
  for await (const line of lines) {
@@ -23691,9 +23754,9 @@ var AntigravitySessionUsageTracker = class {
23691
23754
  stream.destroy();
23692
23755
  }
23693
23756
  result.complete &&= [...result.steps.values()].every((request) => request !== null) && [...this.#consumed.keys()].every((step) => result.steps.has(step));
23694
- const unseen = new Set([...result.steps.keys()].filter((step) => !this.#consumed.has(step) && !result.toolCallSteps.has(step)));
23757
+ const unseen = new Set([...result.steps.keys()].filter((step) => !this.#consumed.has(step)));
23695
23758
  if (withTimings && unseen.size > 0)
23696
- result.timings = await readAntigravityRequestTimings(this.#nativeSessionId, this.#home, result.steps, unseen);
23759
+ result.metadata = await readAntigravityRequestMetadata(this.#nativeSessionId, this.#home, result.steps, unseen);
23697
23760
  signal?.throwIfAborted();
23698
23761
  return result;
23699
23762
  }
@@ -24417,6 +24480,128 @@ function splitAntigravityModelAndEffort(rawModelId) {
24417
24480
  return { modelRef: harnessModelRefSchema.parse({ id: rawModelId.trim() }) };
24418
24481
  }
24419
24482
 
24483
+ // dist/native-replay.js
24484
+ var USER_INPUT = 14;
24485
+ var PLANNER_RESPONSE = 15;
24486
+ var ERROR_MESSAGE = 17;
24487
+ var GENERIC_TOOL = 132;
24488
+ var DONE = 3;
24489
+ var ERROR = 7;
24490
+ var IN_FLIGHT = /* @__PURE__ */ new Set([1, 2, 8, 9, 11]);
24491
+ function message2(payload) {
24492
+ const fields = payload instanceof Uint8Array ? readProtoFields(payload) : null;
24493
+ if (!fields)
24494
+ throw new Error("Invalid Antigravity history protobuf");
24495
+ return fields;
24496
+ }
24497
+ function messageField(fields, number4) {
24498
+ const field3 = fields.find((entry) => entry.number === number4 && entry.wire === 2);
24499
+ return field3?.value instanceof Uint8Array ? field3.value : void 0;
24500
+ }
24501
+ function nested(fields, number4) {
24502
+ const payload = messageField(fields, number4);
24503
+ return payload ? message2(payload) : [];
24504
+ }
24505
+ function textField(fields, number4) {
24506
+ const bytes = messageField(fields, number4);
24507
+ return bytes ? Buffer.from(bytes).toString("utf8") : "";
24508
+ }
24509
+ function argsValue(raw) {
24510
+ if (!raw)
24511
+ return void 0;
24512
+ try {
24513
+ return JSON.parse(raw);
24514
+ } catch {
24515
+ return raw;
24516
+ }
24517
+ }
24518
+ async function readNativeHistory(sessionId, home) {
24519
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/u.test(sessionId))
24520
+ throw new Error("Invalid native Session ID");
24521
+ const { DatabaseSync } = await import("node:sqlite");
24522
+ const db = new DatabaseSync(nativeConversationDbPath(sessionId, home), { readOnly: true });
24523
+ const events = [];
24524
+ const pendingCalls = /* @__PURE__ */ new Set();
24525
+ let turnCount = 0;
24526
+ const append = (type, text2) => {
24527
+ if (text2)
24528
+ events.push({ type, text: events.at(-1)?.type === type ? `
24529
+
24530
+ ${text2}` : text2 });
24531
+ };
24532
+ try {
24533
+ db.exec("BEGIN");
24534
+ if (db.prepare("PRAGMA user_version").get()?.user_version !== 1)
24535
+ throw new Error("Unsupported Antigravity history database version");
24536
+ for (const row of db.prepare(`SELECT step_type, status, step_payload FROM steps
24537
+ WHERE step_type IN (${USER_INPUT}, ${PLANNER_RESPONSE}, ${ERROR_MESSAGE}, ${GENERIC_TOOL})
24538
+ ORDER BY idx`).iterate()) {
24539
+ if (row.step_type === USER_INPUT)
24540
+ turnCount++;
24541
+ if (IN_FLIGHT.has(Number(row.status)))
24542
+ continue;
24543
+ const step = message2(row.step_payload);
24544
+ const number4 = row.step_type === USER_INPUT ? 19 : row.step_type === PLANNER_RESPONSE ? 20 : row.step_type === ERROR_MESSAGE ? 24 : 140;
24545
+ const body = message2(messageField(step, number4));
24546
+ switch (row.step_type) {
24547
+ case USER_INPUT: {
24548
+ const items = body.flatMap((field3) => field3.number === 3 && field3.wire === 2 ? [textField(message2(field3.value), 1)] : []);
24549
+ const text2 = items.join("") || textField(body, 2) || textField(body, 1);
24550
+ pendingCalls.clear();
24551
+ if (text2)
24552
+ events.push({ type: "user.text", text: text2 });
24553
+ break;
24554
+ }
24555
+ case PLANNER_RESPONSE: {
24556
+ append("agent.thought", textField(body, 3));
24557
+ append("agent.text", textField(body, 1));
24558
+ for (const field3 of body) {
24559
+ if (field3.number !== 7 || field3.wire !== 2)
24560
+ continue;
24561
+ const call = message2(field3.value);
24562
+ const toolCallId = textField(call, 1);
24563
+ const name = textField(call, 2);
24564
+ if (!toolCallId || !name)
24565
+ continue;
24566
+ pendingCalls.add(toolCallId);
24567
+ events.push({
24568
+ type: "tool.call",
24569
+ toolCallId,
24570
+ name,
24571
+ args: argsValue(textField(call, 3))
24572
+ });
24573
+ }
24574
+ break;
24575
+ }
24576
+ case ERROR_MESSAGE: {
24577
+ const warning = textField(nested(body, 3), 2);
24578
+ if (warning)
24579
+ append("agent.text", `⚠ ${warning}`);
24580
+ break;
24581
+ }
24582
+ case GENERIC_TOOL: {
24583
+ const toolCallId = textField(nested(nested(step, 5), 4), 1);
24584
+ if (!pendingCalls.delete(toolCallId))
24585
+ break;
24586
+ const error51 = nested(step, 31);
24587
+ const output = textField(nested(body, 2), 1) || textField(error51, 3) || textField(error51, 2) || textField(error51, 1);
24588
+ const status = row.status === DONE ? "completed" : row.status === ERROR ? "failed" : "cancelled";
24589
+ events.push({
24590
+ type: "tool.update",
24591
+ toolCallId,
24592
+ status,
24593
+ ...output ? { rawOutput: output } : {}
24594
+ });
24595
+ break;
24596
+ }
24597
+ }
24598
+ }
24599
+ return { events, turnCount };
24600
+ } finally {
24601
+ db.close();
24602
+ }
24603
+ }
24604
+
24420
24605
  // dist/permission-modes.js
24421
24606
  var ANTIGRAVITY_ACP_SESSION_MODES = ["default", "accept-edits", "auto", "plan"];
24422
24607
  var ANTIGRAVITY_DEFAULT_PERMISSION_MODE_ID = harnessPermissionModeIdSchema.parse("default");
@@ -24726,8 +24911,8 @@ import { fileURLToPath } from "node:url";
24726
24911
  // ../../harness-adapter/dist/session-import.js
24727
24912
  import { lstat as lstat2 } from "node:fs/promises";
24728
24913
  var SessionImportChangedError = class extends Error {
24729
- constructor(message2 = "Native Session changed during discovery; refresh and retry") {
24730
- super(message2);
24914
+ constructor(message3 = "Native Session changed during discovery; refresh and retry") {
24915
+ super(message3);
24731
24916
  this.name = "SessionImportChangedError";
24732
24917
  }
24733
24918
  };
@@ -25352,8 +25537,8 @@ var antigravitySessionCapabilities = {
25352
25537
  function ok(value) {
25353
25538
  return { ok: true, value };
25354
25539
  }
25355
- function err(code, message2, retryable = false) {
25356
- return { ok: false, error: { code, message: message2, retryable } };
25540
+ function err(code, message3, retryable = false) {
25541
+ return { ok: false, error: { code, message: message3, retryable } };
25357
25542
  }
25358
25543
  function normalizeAntigravityError(error51) {
25359
25544
  if (error51 instanceof AntigravityTransportError)
@@ -25363,11 +25548,11 @@ function normalizeAntigravityError(error51) {
25363
25548
  retryable: error51.retryable,
25364
25549
  ...error51.diagnostic ? { diagnostic: sanitizeDiagnosticTail(error51.diagnostic) } : {}
25365
25550
  };
25366
- const message2 = sanitizeDiagnosticTail(error51 instanceof Error ? error51.message : String(error51));
25551
+ const message3 = sanitizeDiagnosticTail(error51 instanceof Error ? error51.message : String(error51));
25367
25552
  const code = error51?.code;
25368
25553
  return {
25369
- code: code === "ENOENT" ? "notInstalled" : /authenticat|sign.?in|login|credential/iu.test(message2) ? "authenticationRequired" : "nativeFailure",
25370
- message: message2,
25554
+ code: code === "ENOENT" ? "notInstalled" : /authenticat|sign.?in|login|credential/iu.test(message3) ? "authenticationRequired" : "nativeFailure",
25555
+ message: message3,
25371
25556
  retryable: false
25372
25557
  };
25373
25558
  }
@@ -25464,7 +25649,6 @@ var AntigravitySession = class {
25464
25649
  #state = {};
25465
25650
  #requested;
25466
25651
  #transport;
25467
- #readers = /* @__PURE__ */ new Set();
25468
25652
  #opening;
25469
25653
  #availableModels = [];
25470
25654
  #configOptions = [];
@@ -25483,6 +25667,8 @@ var AntigravitySession = class {
25483
25667
  #historyOperation = false;
25484
25668
  constructor(options) {
25485
25669
  this.#options = options;
25670
+ if (options.nativeRef)
25671
+ this.#state = { nativeRef: options.nativeRef };
25486
25672
  this.#requested = {
25487
25673
  model: options.model,
25488
25674
  thinkingOptionId: options.thinkingOptionId,
@@ -25567,7 +25753,7 @@ var AntigravitySession = class {
25567
25753
  return;
25568
25754
  }
25569
25755
  const ref = this.nativeRef ?? this.#options.nativeRef;
25570
- const { opened, replayedEvents } = await transport.openSession({
25756
+ const { opened } = await transport.openSession({
25571
25757
  kind: ref ? "resume" : "create",
25572
25758
  ...ref ? { sessionId: ref.nativeSessionId } : {},
25573
25759
  cwd: this.#options.cwd,
@@ -25582,26 +25768,8 @@ var AntigravitySession = class {
25582
25768
  if (!validNativeSessionRef({ harnessId, nativeSessionId: opened.sessionId, formatVersion: 1 }, harnessId))
25583
25769
  throw new AntigravityTransportError("protocolError", "Antigravity returned an invalid native Session ID");
25584
25770
  this.#applyOpened(opened, skip);
25585
- try {
25586
- this.#turnCount = await readNativeTurnCount(nativeConversationDbPath(opened.sessionId, antigravityHome(this.#options.environment)));
25587
- } catch {
25588
- this.#turnCount = projectReplayedEventsToTurns({
25589
- nativeSessionId: opened.sessionId,
25590
- cwd: this.#options.cwd,
25591
- events: replayedEvents,
25592
- ...this.#options.knownTurnRefs ? { knownTurnRefs: this.#options.knownTurnRefs } : {}
25593
- }).length;
25594
- }
25595
- if (!this.#usage) {
25596
- const context = replayedEvents.findLast((event) => event.type === "usage.context");
25597
- this.#usage = new AntigravitySessionUsageTracker({
25598
- nativeSessionId: opened.sessionId,
25599
- homedir: antigravityHome(this.#options.environment),
25600
- expectedInitialTurns: this.#turnCount,
25601
- ...context ? { initialContextUsedTokens: context.used, initialContextWindowTokens: context.size } : {}
25602
- });
25603
- this.#usageWork = this.#replayUsage();
25604
- }
25771
+ this.#turnCount = await readNativeTurnCount(nativeConversationDbPath(opened.sessionId, antigravityHome(this.#options.environment))).catch(() => this.#turnCount);
25772
+ this.#initializeUsage(opened.sessionId);
25605
25773
  transport.setSessionEventHandler((event) => {
25606
25774
  if (this.#transport === transport && !this.#closed && !this.#faulted)
25607
25775
  this.#sessionEvent(event);
@@ -25631,6 +25799,16 @@ var AntigravitySession = class {
25631
25799
  throw error51;
25632
25800
  }
25633
25801
  }
25802
+ #initializeUsage(nativeSessionId) {
25803
+ if (this.#usage)
25804
+ return;
25805
+ this.#usage = new AntigravitySessionUsageTracker({
25806
+ nativeSessionId,
25807
+ homedir: antigravityHome(this.#options.environment),
25808
+ expectedInitialTurns: this.#turnCount
25809
+ });
25810
+ this.#usageWork = this.#replayUsage();
25811
+ }
25634
25812
  #setLocatorPermissionMode(permissionModeId) {
25635
25813
  const ref = this.#state.nativeRef;
25636
25814
  if (!ref)
@@ -25819,36 +25997,30 @@ var AntigravitySession = class {
25819
25997
  async readSnapshot() {
25820
25998
  if (this.#closed || this.#faulted)
25821
25999
  return err("invalidState", "Session is closed");
25822
- if (!this.nativeRef)
26000
+ const nativeRef = this.nativeRef;
26001
+ if (!nativeRef)
25823
26002
  return ok({ turns: [], state: { ...this.#state } });
25824
- const transport = this.#newTransport(this.#transport?.skipPermissions ?? this.#options.unattended);
25825
- this.#readers.add(transport);
26003
+ const { nativeSessionId } = nativeRef;
25826
26004
  try {
25827
- await transport.initialize();
25828
- const { opened, replayedEvents } = await transport.openSession({
25829
- kind: "load",
25830
- sessionId: this.nativeRef.nativeSessionId,
26005
+ const { events, turnCount } = await readNativeHistory(nativeSessionId, antigravityHome(this.#options.environment));
26006
+ if (this.#closed || this.#faulted)
26007
+ return err("invalidState", "Session is closed");
26008
+ const turns = projectReplayedEventsToTurns({
26009
+ nativeSessionId,
25831
26010
  cwd: this.#options.cwd,
25832
- ...this.#delegationPrompt()
26011
+ events,
26012
+ ...this.#options.knownTurnRefs ? { knownTurnRefs: this.#options.knownTurnRefs } : {},
26013
+ ...this.#options.adapter.toolOutputLimit !== void 0 ? { outputLimit: this.#options.adapter.toolOutputLimit } : {}
25833
26014
  });
25834
- if (opened.sessionId !== this.nativeRef.nativeSessionId)
25835
- throw new AntigravityTransportError("protocolError", "Snapshot loaded a different Session");
25836
- const snapshot = {
25837
- turns: projectReplayedEventsToTurns({
25838
- nativeSessionId: opened.sessionId,
25839
- cwd: this.#options.cwd,
25840
- events: replayedEvents,
25841
- ...this.#options.knownTurnRefs ? { knownTurnRefs: this.#options.knownTurnRefs } : {},
25842
- ...this.#options.adapter.toolOutputLimit !== void 0 ? { outputLimit: this.#options.adapter.toolOutputLimit } : {}
25843
- }),
25844
- state: { ...this.#state }
25845
- };
25846
- await transport.close();
25847
- this.#readers.delete(transport);
25848
- return this.#closed || this.#faulted ? err("invalidState", "Session is closed") : ok(snapshot);
25849
- } catch (error51) {
25850
- await transport.close().then(() => this.#readers.delete(transport)).catch(() => void 0);
25851
- return { ok: false, error: normalizeAntigravityError(error51) };
26015
+ if (!this.#transport) {
26016
+ this.#turnCount = turnCount;
26017
+ this.#initializeUsage(nativeSessionId);
26018
+ }
26019
+ return ok({ turns, ...this.#transport ? { state: { ...this.#state } } : {} });
26020
+ } catch {
26021
+ if (this.#closed || this.#faulted)
26022
+ return err("invalidState", "Session is closed");
26023
+ return err("nativeFailure", "Antigravity history unavailable");
25852
26024
  }
25853
26025
  }
25854
26026
  async execute(command) {
@@ -26066,19 +26238,19 @@ var AntigravitySession = class {
26066
26238
  await this.#usageWork;
26067
26239
  if (this.#usage && this.#isCurrent(turn)) {
26068
26240
  try {
26069
- const timing3 = {
26241
+ const timing2 = {
26070
26242
  ...turn.firstOutputAtMs !== void 0 ? { firstOutputAtMs: turn.firstOutputAtMs } : {},
26071
26243
  completedAtMs
26072
26244
  };
26073
26245
  const update = await this.#usage.collectNewTranscriptRequests({
26074
- ...timing3,
26246
+ ...timing2,
26075
26247
  ...turn.hasToolCalls ? { hasToolCalls: true } : {},
26076
26248
  ...result.usage ? { promptUsage: result.usage } : {},
26077
26249
  signal: this.#abort.signal
26078
26250
  });
26079
26251
  const recorded = this.#usage.recordTurnPromptUsage({
26080
26252
  ...result.usage ? { usage: result.usage } : {},
26081
- ...timing3
26253
+ ...timing2
26082
26254
  });
26083
26255
  if (!this.#isCurrent(turn))
26084
26256
  return;
@@ -26281,12 +26453,7 @@ var AntigravitySession = class {
26281
26453
  this.#transport?.setSessionEventHandler(null);
26282
26454
  if (active)
26283
26455
  await this.#transport?.cancel().catch(() => void 0);
26284
- await Promise.all([
26285
- this.#transport?.close(),
26286
- this.#subagents.close(),
26287
- ...[...this.#readers].map((reader) => reader.close())
26288
- ]);
26289
- this.#readers.clear();
26456
+ await Promise.all([this.#transport?.close(), this.#subagents.close()]);
26290
26457
  this.#options.onClosed(this);
26291
26458
  }
26292
26459
  };
@@ -26416,7 +26583,22 @@ var AntigravityAdapter = class {
26416
26583
  const common = {
26417
26584
  harnessId,
26418
26585
  adapterEnvironment: this.#environment,
26419
- openSession: (resume) => this.open(resume)
26586
+ openSession: async (resume) => {
26587
+ const result = await this.open(resume);
26588
+ if (!result.ok || !(result.value instanceof AntigravitySession))
26589
+ return result;
26590
+ try {
26591
+ await result.value.initialize();
26592
+ if (this.#closed) {
26593
+ await result.value.close();
26594
+ return err("invalidState", "Adapter is closed");
26595
+ }
26596
+ return result;
26597
+ } catch (error51) {
26598
+ await result.value.close().catch(() => void 0);
26599
+ return { ok: false, error: normalizeAntigravityError(error51) };
26600
+ }
26601
+ }
26420
26602
  };
26421
26603
  try {
26422
26604
  return await (input.kind === "fork" ? forkAntigravitySession({ ...common, input }) : rollbackAntigravityLastTurn({ ...common, input }));
@@ -26450,8 +26632,6 @@ var AntigravityAdapter = class {
26450
26632
  });
26451
26633
  this.#sessions.add(session);
26452
26634
  try {
26453
- if (input.kind === "resume")
26454
- await session.initialize();
26455
26635
  if (this.#closed) {
26456
26636
  await session.close();
26457
26637
  return err("invalidState", "Adapter is closed");