@karlorz/codexhost-cli-darwin-x64 0.20.0-0 → 0.21.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/app/codexhost-distribution.json +1 -1
- package/app/console-server.mjs +62 -14
- package/app/console-web.js +34 -7
- package/app/cpa-live-voice-hook.js +26 -6
- package/app/desktop-controller.mjs +164 -51
- package/app/host-runtime.mjs +21746 -15276
- package/app/plugins/antigravity/assets/icon.svg +1 -1
- package/app/plugins/antigravity/plugin.mjs +1112 -822
- package/app/plugins/claude-code/plugin.mjs +152 -28
- package/app/plugins/codebuddy/plugin.mjs +35 -6
- package/app/plugins/codex-usage/plugin.mjs +35 -6
- package/app/plugins/copilot/plugin.mjs +27 -6
- package/app/plugins/cursor-cli/plugin.mjs +27 -6
- package/app/plugins/deepseek-harness/plugin.mjs +52 -11
- package/app/plugins/devin/plugin.mjs +27 -6
- package/app/plugins/grok/plugin.mjs +63 -15
- package/app/plugins/hermes/plugin.mjs +27 -6
- package/app/plugins/kimi-code/plugin.mjs +52 -16
- package/app/plugins/kiro-cli/plugin.mjs +27 -6
- package/app/plugins/omp/plugin.mjs +35 -6
- package/app/plugins/opencode/plugin.mjs +53 -15
- package/app/plugins/pi/plugin.mjs +35 -6
- package/app/plugins/qoder/plugin.mjs +42 -6
- package/app/plugins/qoder-cn/plugin.mjs +42 -6
- package/app/plugins/qwen-code/plugin.mjs +27 -6
- package/app/plugins/workbuddy/plugin.mjs +35 -6
- package/app/plugins/zcode/plugin.mjs +35 -6
- package/app/renderer-extension.js +26 -6
- package/app/web/assets/{index-D6-hvggd.css → index-DJW4bmyx.css} +1 -1
- package/app/web/assets/{index-B5OfOGb8.js → index-DLXdvkWR.js} +63 -63
- package/app/web/codexhost-settings.js +34 -7
- package/app/web/index.html +2 -2
- package/app/web/plugins/deepseek-ai__dsh-api-remotes/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-api-session-controller/client.js +57 -57
- package/app/web/plugins/deepseek-ai__dsh-client-ui-chat/client.js +68 -68
- package/app/web/plugins/deepseek-ai__dsh-client-ui-codexhost/client.js +6 -6
- package/app/web/plugins/deepseek-ai__dsh-client-ui-conversation/client.js +22 -22
- package/app/web/plugins/deepseek-ai__dsh-client-ui-input-trigger/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-layout/client.js +2 -2
- package/app/web/plugins/deepseek-ai__dsh-client-ui-model-selection/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-settings-general/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar-documentpreview/client.js +9 -9
- package/app/web/plugins/deepseek-ai__dsh-client-ui-tool/client.js +16 -16
- package/app/web/plugins/deepseek-ai__dsh-client-ui-workspace/client.js +2 -2
- package/app/web-modules/server.mjs +1017 -672
- package/bin/codexhost +0 -0
- package/libexec/codexhost-shim +0 -0
- package/libexec/codexhost-updater +0 -0
- package/package.json +1 -1
|
@@ -15436,7 +15436,7 @@ var nonNegativeSafeIntegerSchema = external_exports.number().int().safe().nonneg
|
|
|
15436
15436
|
var finiteNonNegativeNumberSchema = external_exports.number().finite().nonnegative();
|
|
15437
15437
|
var cacheHitRatePercentSchema = external_exports.number().finite().min(0).max(100);
|
|
15438
15438
|
var usageOutputTimingSchema = external_exports.object({
|
|
15439
|
-
version: external_exports.literal(3).optional(),
|
|
15439
|
+
version: external_exports.union([external_exports.literal(3), external_exports.literal(4)]).optional(),
|
|
15440
15440
|
requestId: external_exports.string().min(1),
|
|
15441
15441
|
turnId: external_exports.string().min(1).max(1024),
|
|
15442
15442
|
outputTokens: nonNegativeSafeIntegerSchema,
|
|
@@ -15444,16 +15444,16 @@ var usageOutputTimingSchema = external_exports.object({
|
|
|
15444
15444
|
completedAtMs: nonNegativeSafeIntegerSchema
|
|
15445
15445
|
}).strict().refine((value) => value.completedAtMs > value.startedAtMs);
|
|
15446
15446
|
var usageMeasurementSchema = external_exports.object({
|
|
15447
|
-
version: external_exports.union([external_exports.literal(2), external_exports.literal(3)]).optional(),
|
|
15447
|
+
version: external_exports.union([external_exports.literal(2), external_exports.literal(3), external_exports.literal(4)]).optional(),
|
|
15448
15448
|
value: finiteNonNegativeNumberSchema,
|
|
15449
15449
|
turnId: external_exports.string().min(1).max(1024),
|
|
15450
15450
|
at: nonNegativeSafeIntegerSchema
|
|
15451
15451
|
}).strict();
|
|
15452
15452
|
var usageMeasurementsSchema = external_exports.object({
|
|
15453
|
-
//
|
|
15454
|
-
outputTimings: external_exports.array(usageOutputTimingSchema).transform((values) => values.filter((value) => value.version ===
|
|
15453
|
+
// Older intervals can omit hidden thinking time; do not restore them into averages.
|
|
15454
|
+
outputTimings: external_exports.array(usageOutputTimingSchema).transform((values) => values.filter((value) => value.version === 4)).optional(),
|
|
15455
15455
|
// Retain independent TTFT facts when dropping incompatible speed measurements.
|
|
15456
|
-
outputTokensPerSecond: usageMeasurementSchema.refine((value) => value.version ===
|
|
15456
|
+
outputTokensPerSecond: usageMeasurementSchema.refine((value) => value.version === 4).optional().catch(void 0),
|
|
15457
15457
|
timeToFirstOutputMs: usageMeasurementSchema.extend({ value: nonNegativeSafeIntegerSchema }).optional()
|
|
15458
15458
|
}).strict();
|
|
15459
15459
|
var indicatorTextSchema = (maximum) => harnessLocalizedTextSchema.refine((entries) => Object.values(entries).every((text2) => text2.length <= maximum));
|
|
@@ -15967,6 +15967,11 @@ var clientChannelEventSchema = external_exports.discriminatedUnion("type", [
|
|
|
15967
15967
|
cursor: clientChannelCursorSchema,
|
|
15968
15968
|
cwd: external_exports.string().optional()
|
|
15969
15969
|
}),
|
|
15970
|
+
external_exports.object({
|
|
15971
|
+
type: external_exports.literal("harness-inspection-changed"),
|
|
15972
|
+
cursor: clientChannelCursorSchema,
|
|
15973
|
+
harnessId: external_exports.string().min(1)
|
|
15974
|
+
}),
|
|
15970
15975
|
external_exports.object({ type: external_exports.literal("display-settings-changed"), cursor: clientChannelCursorSchema }),
|
|
15971
15976
|
external_exports.object({
|
|
15972
15977
|
type: external_exports.literal("preferences-changed"),
|
|
@@ -16038,6 +16043,8 @@ var clientItemTruncationSchema = external_exports.object({
|
|
|
16038
16043
|
var clientTurnSchema = external_exports.object({
|
|
16039
16044
|
id: external_exports.string().min(1),
|
|
16040
16045
|
status: external_exports.string().min(1),
|
|
16046
|
+
/** Native history has no terminal evidence; Desktop's status vocabulary cannot express this. */
|
|
16047
|
+
codexhostTurnOutcome: external_exports.object({ status: external_exports.literal("unknown"), reason: external_exports.string() }).optional(),
|
|
16041
16048
|
items: external_exports.array(external_exports.object({ id: external_exports.string().min(1), type: external_exports.string().min(1) }).passthrough()),
|
|
16042
16049
|
/** Original file operations, independent of the cumulative Desktop fileChange card.
|
|
16043
16050
|
* Insert before the named non-file Item; null appends at the end of the Turn.
|
|
@@ -17303,6 +17310,7 @@ var THREAD_WATCH_NOTICE_OUTCOMES = [
|
|
|
17303
17310
|
"completed",
|
|
17304
17311
|
"failed",
|
|
17305
17312
|
"interrupted",
|
|
17313
|
+
"needsInput",
|
|
17306
17314
|
"timedOut",
|
|
17307
17315
|
"unreadable",
|
|
17308
17316
|
"notFound"
|
|
@@ -17349,13 +17357,25 @@ var target = { hostId: identity.regex(/^remote-(?:ssh(?:-|:)|control:)/u) };
|
|
|
17349
17357
|
var thread = { ...target, threadId: identity };
|
|
17350
17358
|
var remoteSessionOperationSchema = external_exports.discriminatedUnion("kind", [
|
|
17351
17359
|
external_exports.strictObject({ kind: external_exports.literal("hosts") }),
|
|
17360
|
+
external_exports.strictObject({ kind: external_exports.literal("status"), ...thread }),
|
|
17352
17361
|
external_exports.strictObject({
|
|
17353
17362
|
kind: external_exports.literal("list"),
|
|
17354
17363
|
...target,
|
|
17355
17364
|
cursor: external_exports.string().nullable(),
|
|
17356
17365
|
archived: external_exports.boolean()
|
|
17357
17366
|
}),
|
|
17358
|
-
external_exports.strictObject({
|
|
17367
|
+
external_exports.strictObject({
|
|
17368
|
+
kind: external_exports.literal("read"),
|
|
17369
|
+
...thread,
|
|
17370
|
+
page: external_exports.strictObject({
|
|
17371
|
+
cursor: external_exports.string().min(1).max(8192).nullable(),
|
|
17372
|
+
epoch: identity.optional(),
|
|
17373
|
+
sortDirection: external_exports.enum(["asc", "desc"]).optional(),
|
|
17374
|
+
limit: external_exports.number().int().min(1).max(20).optional()
|
|
17375
|
+
}).refine((page) => page.cursor === null || page.epoch !== void 0, {
|
|
17376
|
+
message: "A history continuation requires its connection epoch"
|
|
17377
|
+
}).optional()
|
|
17378
|
+
}),
|
|
17359
17379
|
external_exports.strictObject({
|
|
17360
17380
|
kind: external_exports.literal("configure"),
|
|
17361
17381
|
...thread,
|
|
@@ -17768,6 +17788,7 @@ var requestTokenFields = [
|
|
|
17768
17788
|
"cacheWrite1hInputTokens",
|
|
17769
17789
|
"outputTokens",
|
|
17770
17790
|
"reasoningOutputTokens",
|
|
17791
|
+
"timedOutputTokens",
|
|
17771
17792
|
"startedAtMs",
|
|
17772
17793
|
"completedAtMs"
|
|
17773
17794
|
];
|
|
@@ -17820,6 +17841,14 @@ function parseHostUsageRequest(value) {
|
|
|
17820
17841
|
if (request.startedAtMs === void 0 !== (request.completedAtMs === void 0)) {
|
|
17821
17842
|
throw new Error("Harness Usage request timing fields must be provided together");
|
|
17822
17843
|
}
|
|
17844
|
+
if (request.timedOutputTokens !== void 0) {
|
|
17845
|
+
if (request.startedAtMs === void 0) {
|
|
17846
|
+
throw new Error("Harness Usage request 'timedOutputTokens' requires timing fields");
|
|
17847
|
+
}
|
|
17848
|
+
if (request.timedOutputTokens > request.outputTokens) {
|
|
17849
|
+
throw new Error("Harness Usage request 'timedOutputTokens' must not exceed 'outputTokens'");
|
|
17850
|
+
}
|
|
17851
|
+
}
|
|
17823
17852
|
if (request.startedAtMs !== void 0 && request.completedAtMs !== void 0 && request.completedAtMs < request.startedAtMs) {
|
|
17824
17853
|
throw new Error("Harness Usage request 'completedAtMs' must not precede 'startedAtMs'");
|
|
17825
17854
|
}
|
|
@@ -23346,390 +23375,264 @@ var AntigravityTransportError = class extends Error {
|
|
|
23346
23375
|
}
|
|
23347
23376
|
};
|
|
23348
23377
|
|
|
23349
|
-
// dist/
|
|
23350
|
-
|
|
23351
|
-
|
|
23352
|
-
|
|
23353
|
-
|
|
23354
|
-
|
|
23355
|
-
|
|
23356
|
-
|
|
23357
|
-
|
|
23358
|
-
|
|
23359
|
-
|
|
23360
|
-
|
|
23361
|
-
|
|
23362
|
-
|
|
23363
|
-
|
|
23364
|
-
|
|
23365
|
-
#closing = null;
|
|
23366
|
-
#stderrRaw = "";
|
|
23367
|
-
get #stderr() {
|
|
23368
|
-
return sanitizeDiagnosticTail(this.#stderrRaw);
|
|
23369
|
-
}
|
|
23370
|
-
#faultSignal = new AbortController();
|
|
23371
|
-
constructor(options) {
|
|
23372
|
-
this.options = options;
|
|
23373
|
-
this.skipPermissions = options.skipPermissions === true;
|
|
23374
|
-
}
|
|
23375
|
-
get sessionId() {
|
|
23376
|
-
return this.#sessionId;
|
|
23377
|
-
}
|
|
23378
|
-
get isClosed() {
|
|
23379
|
-
return this.#closed;
|
|
23378
|
+
// dist/fork.js
|
|
23379
|
+
import { randomUUID } from "node:crypto";
|
|
23380
|
+
import { access as access2, cp, mkdir, open, rm as rm2 } from "node:fs/promises";
|
|
23381
|
+
import os3 from "node:os";
|
|
23382
|
+
import path9 from "node:path";
|
|
23383
|
+
|
|
23384
|
+
// dist/native-protobuf.js
|
|
23385
|
+
function decodeVarint(buffer, start) {
|
|
23386
|
+
let value = 0n;
|
|
23387
|
+
for (let index = 0; index < 10; index++) {
|
|
23388
|
+
const byte = buffer[start + index];
|
|
23389
|
+
if (byte === void 0 || index === 9 && byte > 1)
|
|
23390
|
+
return null;
|
|
23391
|
+
value |= BigInt(byte & 127) << BigInt(index * 7);
|
|
23392
|
+
if ((byte & 128) === 0)
|
|
23393
|
+
return [value, start + index + 1];
|
|
23380
23394
|
}
|
|
23381
|
-
|
|
23382
|
-
|
|
23383
|
-
|
|
23384
|
-
|
|
23385
|
-
|
|
23395
|
+
return null;
|
|
23396
|
+
}
|
|
23397
|
+
function readProtoFields(blob) {
|
|
23398
|
+
const fields = [];
|
|
23399
|
+
let offset = 0;
|
|
23400
|
+
while (offset < blob.length) {
|
|
23401
|
+
if (fields.length >= 1e4)
|
|
23402
|
+
return null;
|
|
23403
|
+
const tag = decodeVarint(blob, offset);
|
|
23404
|
+
if (!tag || tag[0] < 8n || tag[0] > 0xffffffffn)
|
|
23405
|
+
return null;
|
|
23406
|
+
offset = tag[1];
|
|
23407
|
+
const number4 = Number(tag[0] >> 3n);
|
|
23408
|
+
const wire = Number(tag[0] & 7n);
|
|
23409
|
+
if (wire === 0) {
|
|
23410
|
+
const value = decodeVarint(blob, offset);
|
|
23411
|
+
if (!value)
|
|
23412
|
+
return null;
|
|
23413
|
+
fields.push({ number: number4, wire, value: value[0] });
|
|
23414
|
+
offset = value[1];
|
|
23415
|
+
} else if (wire === 1 || wire === 5) {
|
|
23416
|
+
const length = wire === 1 ? 8 : 4;
|
|
23417
|
+
if (offset + length > blob.length)
|
|
23418
|
+
return null;
|
|
23419
|
+
fields.push({ number: number4, wire, value: blob.subarray(offset, offset + length) });
|
|
23420
|
+
offset += length;
|
|
23421
|
+
} else if (wire === 2) {
|
|
23422
|
+
const length = decodeVarint(blob, offset);
|
|
23423
|
+
if (!length || length[0] > BigInt(blob.length - length[1]))
|
|
23424
|
+
return null;
|
|
23425
|
+
offset = length[1];
|
|
23426
|
+
const end = offset + Number(length[0]);
|
|
23427
|
+
fields.push({ number: number4, wire, value: blob.subarray(offset, end) });
|
|
23428
|
+
offset = end;
|
|
23429
|
+
} else
|
|
23430
|
+
return null;
|
|
23386
23431
|
}
|
|
23387
|
-
|
|
23388
|
-
|
|
23389
|
-
|
|
23390
|
-
|
|
23432
|
+
return fields;
|
|
23433
|
+
}
|
|
23434
|
+
|
|
23435
|
+
// dist/native-trajectory-metadata.js
|
|
23436
|
+
var DEFAULT_CLI_PROJECT_ID = "default-cli-project";
|
|
23437
|
+
function encodeVarint(value) {
|
|
23438
|
+
const bytes = [];
|
|
23439
|
+
let remaining = value >>> 0;
|
|
23440
|
+
while (remaining >= 128) {
|
|
23441
|
+
bytes.push(remaining & 127 | 128);
|
|
23442
|
+
remaining >>>= 7;
|
|
23391
23443
|
}
|
|
23392
|
-
|
|
23393
|
-
|
|
23394
|
-
|
|
23395
|
-
|
|
23396
|
-
|
|
23397
|
-
|
|
23398
|
-
|
|
23399
|
-
|
|
23400
|
-
|
|
23401
|
-
|
|
23402
|
-
|
|
23403
|
-
|
|
23404
|
-
|
|
23405
|
-
|
|
23406
|
-
|
|
23407
|
-
|
|
23408
|
-
|
|
23409
|
-
|
|
23410
|
-
|
|
23411
|
-
|
|
23412
|
-
|
|
23413
|
-
|
|
23414
|
-
|
|
23415
|
-
|
|
23416
|
-
|
|
23417
|
-
|
|
23418
|
-
|
|
23419
|
-
|
|
23420
|
-
|
|
23421
|
-
|
|
23422
|
-
|
|
23423
|
-
|
|
23424
|
-
|
|
23425
|
-
|
|
23426
|
-
|
|
23427
|
-
|
|
23428
|
-
|
|
23429
|
-
|
|
23430
|
-
|
|
23431
|
-
|
|
23432
|
-
|
|
23433
|
-
|
|
23434
|
-
|
|
23435
|
-
|
|
23436
|
-
|
|
23437
|
-
|
|
23438
|
-
|
|
23444
|
+
bytes.push(remaining);
|
|
23445
|
+
return Buffer.from(bytes);
|
|
23446
|
+
}
|
|
23447
|
+
function encodeLengthDelimited(fieldNumber, payload) {
|
|
23448
|
+
return Buffer.concat([
|
|
23449
|
+
encodeVarint(fieldNumber << 3 | 2),
|
|
23450
|
+
encodeVarint(payload.length),
|
|
23451
|
+
Buffer.from(payload)
|
|
23452
|
+
]);
|
|
23453
|
+
}
|
|
23454
|
+
function minimalTrajectoryMetadataBlob(cascadeId, projectId = DEFAULT_CLI_PROJECT_ID) {
|
|
23455
|
+
return Buffer.concat([
|
|
23456
|
+
encodeLengthDelimited(6, Buffer.from(cascadeId, "utf8")),
|
|
23457
|
+
encodeLengthDelimited(18, Buffer.from(projectId, "utf8"))
|
|
23458
|
+
]);
|
|
23459
|
+
}
|
|
23460
|
+
function minimalRawSummaryBlob(trajectoryId, metadataBlob) {
|
|
23461
|
+
return Buffer.concat([
|
|
23462
|
+
encodeLengthDelimited(4, Buffer.from(trajectoryId, "utf8")),
|
|
23463
|
+
Buffer.from([40, 1]),
|
|
23464
|
+
encodeLengthDelimited(17, metadataBlob),
|
|
23465
|
+
Buffer.from([176, 1, 4])
|
|
23466
|
+
]);
|
|
23467
|
+
}
|
|
23468
|
+
function rewriteTrajectoryMetadataCascadeId(blob, cascadeId) {
|
|
23469
|
+
const chunks = [];
|
|
23470
|
+
let offset = 0;
|
|
23471
|
+
let wroteCascadeId = false;
|
|
23472
|
+
let hasProjectId = false;
|
|
23473
|
+
while (offset < blob.length) {
|
|
23474
|
+
const fieldStart = offset;
|
|
23475
|
+
const tagParsed = decodeVarint(blob, offset);
|
|
23476
|
+
if (!tagParsed)
|
|
23477
|
+
return null;
|
|
23478
|
+
const [tag, afterTag] = tagParsed;
|
|
23479
|
+
if (tag < 8n || tag > 0xffffffffn)
|
|
23480
|
+
return null;
|
|
23481
|
+
const fieldNumber = Number(tag >> 3n);
|
|
23482
|
+
const wireType = Number(tag & 7n);
|
|
23483
|
+
if (fieldNumber === 6 && wireType !== 2)
|
|
23484
|
+
return null;
|
|
23485
|
+
offset = afterTag;
|
|
23486
|
+
if (wireType === 0) {
|
|
23487
|
+
const valParsed = decodeVarint(blob, offset);
|
|
23488
|
+
if (!valParsed)
|
|
23489
|
+
return null;
|
|
23490
|
+
offset = valParsed[1];
|
|
23491
|
+
} else if (wireType === 1) {
|
|
23492
|
+
if (offset + 8 > blob.length)
|
|
23493
|
+
return null;
|
|
23494
|
+
offset += 8;
|
|
23495
|
+
} else if (wireType === 2) {
|
|
23496
|
+
const lenParsed = decodeVarint(blob, offset);
|
|
23497
|
+
if (!lenParsed)
|
|
23498
|
+
return null;
|
|
23499
|
+
const [length, afterLen] = lenParsed;
|
|
23500
|
+
if (length > BigInt(blob.length - afterLen))
|
|
23501
|
+
return null;
|
|
23502
|
+
offset = afterLen + Number(length);
|
|
23503
|
+
if (fieldNumber === 6) {
|
|
23504
|
+
if (!wroteCascadeId) {
|
|
23505
|
+
chunks.push(encodeLengthDelimited(6, Buffer.from(cascadeId, "utf8")));
|
|
23506
|
+
wroteCascadeId = true;
|
|
23439
23507
|
}
|
|
23440
|
-
|
|
23441
|
-
|
|
23442
|
-
|
|
23443
|
-
|
|
23444
|
-
|
|
23445
|
-
|
|
23446
|
-
|
|
23447
|
-
|
|
23448
|
-
|
|
23449
|
-
|
|
23450
|
-
if (response.protocolVersion !== 1)
|
|
23451
|
-
throw new AntigravityTransportError("protocolError", `Unsupported ACP version ${response.protocolVersion}`);
|
|
23452
|
-
return response;
|
|
23453
|
-
} catch (error51) {
|
|
23454
|
-
await this.close();
|
|
23455
|
-
throw this.#error(error51);
|
|
23508
|
+
continue;
|
|
23509
|
+
}
|
|
23510
|
+
if (fieldNumber === 18)
|
|
23511
|
+
hasProjectId = true;
|
|
23512
|
+
} else if (wireType === 5) {
|
|
23513
|
+
if (offset + 4 > blob.length)
|
|
23514
|
+
return null;
|
|
23515
|
+
offset += 4;
|
|
23516
|
+
} else {
|
|
23517
|
+
return null;
|
|
23456
23518
|
}
|
|
23519
|
+
chunks.push(Buffer.from(blob.subarray(fieldStart, offset)));
|
|
23457
23520
|
}
|
|
23458
|
-
|
|
23459
|
-
|
|
23460
|
-
if (this.#closed || !this.#connection || this.#active || this.#opening || this.#sessionId)
|
|
23461
|
-
throw new AntigravityTransportError("unavailable", "Close the current ACP session before opening another");
|
|
23462
|
-
const connection = this.#connection;
|
|
23463
|
-
const buffered = [];
|
|
23464
|
-
this.#opening = buffered;
|
|
23465
|
-
this.#pendingEvents = [];
|
|
23466
|
-
const params = {
|
|
23467
|
-
cwd: input.cwd,
|
|
23468
|
-
mcpServers: [],
|
|
23469
|
-
...input.additionalDirectories?.length ? { additionalDirectories: input.additionalDirectories } : {},
|
|
23470
|
-
...input.systemPromptAppend ? { _meta: { antigravity: { systemPrompt: { append: input.systemPromptAppend } } } } : {}
|
|
23471
|
-
};
|
|
23472
|
-
try {
|
|
23473
|
-
let request;
|
|
23474
|
-
if (input.kind === "create")
|
|
23475
|
-
request = connection.newSession(params);
|
|
23476
|
-
else {
|
|
23477
|
-
if (!input.sessionId)
|
|
23478
|
-
throw new AntigravityTransportError("protocolError", "Session ID required for resume/load");
|
|
23479
|
-
const target2 = { ...params, sessionId: input.sessionId };
|
|
23480
|
-
request = input.kind === "resume" ? connection.resumeSession(target2) : connection.loadSession(target2);
|
|
23481
|
-
}
|
|
23482
|
-
const result = await this.#request(request, `session/${input.kind === "create" ? "new" : input.kind}`);
|
|
23483
|
-
const raw = result;
|
|
23484
|
-
const sessionId = raw.sessionId ?? input.sessionId;
|
|
23485
|
-
if (!sessionId)
|
|
23486
|
-
throw new AntigravityTransportError("protocolError", "Antigravity session/new returned no sessionId");
|
|
23487
|
-
this.#sessionId = sessionId;
|
|
23488
|
-
const events = buffered.filter((entry) => entry.sessionId === sessionId).map(({ event }) => event);
|
|
23489
|
-
if (input.kind !== "load")
|
|
23490
|
-
for (const event of events)
|
|
23491
|
-
this.#dispatch(event);
|
|
23492
|
-
return {
|
|
23493
|
-
opened: {
|
|
23494
|
-
sessionId,
|
|
23495
|
-
...raw.models ? { models: raw.models } : {},
|
|
23496
|
-
...raw.modes ? { modes: raw.modes } : {},
|
|
23497
|
-
...raw.configOptions ? { configOptions: raw.configOptions } : {},
|
|
23498
|
-
...raw._meta?.antigravity?.tier ? { tier: raw._meta.antigravity.tier } : {}
|
|
23499
|
-
},
|
|
23500
|
-
replayedEvents: input.kind === "load" ? events : []
|
|
23501
|
-
};
|
|
23502
|
-
} finally {
|
|
23503
|
-
this.#opening = null;
|
|
23504
|
-
}
|
|
23505
|
-
}
|
|
23506
|
-
async setMode(modeId) {
|
|
23507
|
-
const { connection, sessionId } = this.#session();
|
|
23508
|
-
await this.#request(connection.setSessionMode({ sessionId, modeId }), "session/set_mode");
|
|
23509
|
-
}
|
|
23510
|
-
async setConfigOption(configId, value) {
|
|
23511
|
-
const { connection, sessionId } = this.#session();
|
|
23512
|
-
const response = await this.#request(connection.setSessionConfigOption({ sessionId, configId, value }), "session/set_config_option");
|
|
23513
|
-
return response.configOptions;
|
|
23514
|
-
}
|
|
23515
|
-
async prompt(parts, handler) {
|
|
23516
|
-
const { connection, sessionId } = this.#session();
|
|
23517
|
-
if (this.#active)
|
|
23518
|
-
throw new AntigravityTransportError("unavailable", "An ACP prompt is already active");
|
|
23519
|
-
this.#active = handler;
|
|
23520
|
-
this.#acceptCallbacks = true;
|
|
23521
|
-
const interrupted = new AbortController();
|
|
23522
|
-
this.#promptInterrupted = interrupted;
|
|
23523
|
-
try {
|
|
23524
|
-
return await this.#request(connection.prompt({ sessionId, prompt: [...parts] }), "session/prompt", null, interrupted.signal);
|
|
23525
|
-
} finally {
|
|
23526
|
-
this.#clearCallbacks();
|
|
23527
|
-
this.#acceptCallbacks = false;
|
|
23528
|
-
this.#active = null;
|
|
23529
|
-
this.#promptInterrupted = null;
|
|
23530
|
-
}
|
|
23531
|
-
}
|
|
23532
|
-
async cancel() {
|
|
23533
|
-
const { connection, sessionId } = this.#session();
|
|
23534
|
-
this.#acceptCallbacks = false;
|
|
23535
|
-
this.#clearCallbacks();
|
|
23536
|
-
await this.#request(connection.cancel({ sessionId }), "session/cancel");
|
|
23537
|
-
}
|
|
23538
|
-
async closeSession() {
|
|
23539
|
-
const sessionId = this.#sessionId;
|
|
23540
|
-
this.#sessionId = null;
|
|
23541
|
-
this.#acceptCallbacks = false;
|
|
23542
|
-
this.#promptInterrupted?.abort(new AntigravityTransportError("unavailable", "ACP session closed"));
|
|
23543
|
-
this.#active = null;
|
|
23544
|
-
this.#pendingEvents = [];
|
|
23545
|
-
this.#clearCallbacks();
|
|
23546
|
-
if (sessionId && this.#connection)
|
|
23547
|
-
await this.#request(this.#connection.closeSession({ sessionId }), "session/close", this.options.closeTimeoutMs ?? 2e3);
|
|
23548
|
-
}
|
|
23549
|
-
close() {
|
|
23550
|
-
if (this.#closing)
|
|
23551
|
-
return this.#closing;
|
|
23552
|
-
this.#closed = true;
|
|
23553
|
-
return this.#closing = this.#shutdown();
|
|
23554
|
-
}
|
|
23555
|
-
async #shutdown() {
|
|
23556
|
-
try {
|
|
23557
|
-
await this.closeSession();
|
|
23558
|
-
} catch (error51) {
|
|
23559
|
-
this.#stderrRaw = `${this.#stderrRaw}
|
|
23560
|
-
${this.#error(error51).message}`.slice(-32e3);
|
|
23561
|
-
}
|
|
23562
|
-
this.#faultSignal.abort(new AntigravityTransportError("unavailable", "Antigravity ACP closed"));
|
|
23563
|
-
this.#opening = null;
|
|
23564
|
-
this.#sessionHandler = null;
|
|
23565
|
-
const child = this.#child;
|
|
23566
|
-
if (child && child.exitCode === null && child.signalCode === null && child.pid) {
|
|
23567
|
-
const exited = new Promise((resolve) => child.once("exit", () => resolve()));
|
|
23568
|
-
const timeout = this.options.closeTimeoutMs ?? 2e3;
|
|
23569
|
-
const term = setTimeout(() => child.kill("SIGTERM"), Math.max(1, timeout / 2));
|
|
23570
|
-
const kill = setTimeout(() => child.kill("SIGKILL"), Math.max(2, timeout));
|
|
23571
|
-
child.stdin.end();
|
|
23572
|
-
try {
|
|
23573
|
-
await exited;
|
|
23574
|
-
} finally {
|
|
23575
|
-
clearTimeout(term);
|
|
23576
|
-
clearTimeout(kill);
|
|
23577
|
-
}
|
|
23578
|
-
}
|
|
23579
|
-
this.#connection = null;
|
|
23580
|
-
this.#child = null;
|
|
23581
|
-
}
|
|
23582
|
-
#session() {
|
|
23583
|
-
if (this.#closed || !this.#connection || !this.#sessionId)
|
|
23584
|
-
throw new AntigravityTransportError("unavailable", "Antigravity ACP session is unavailable");
|
|
23585
|
-
return { connection: this.#connection, sessionId: this.#sessionId };
|
|
23586
|
-
}
|
|
23587
|
-
#update(sessionId, raw) {
|
|
23588
|
-
if (this.#closed)
|
|
23589
|
-
return;
|
|
23590
|
-
const event = projectAcpSessionUpdate(raw);
|
|
23591
|
-
if (!event)
|
|
23592
|
-
return;
|
|
23593
|
-
if (this.#opening) {
|
|
23594
|
-
this.#opening.push({ sessionId, event });
|
|
23595
|
-
return;
|
|
23596
|
-
}
|
|
23597
|
-
if (sessionId === this.#sessionId)
|
|
23598
|
-
this.#dispatch(event);
|
|
23599
|
-
}
|
|
23600
|
-
#dispatch(event) {
|
|
23601
|
-
if (["config.update", "mode.update", "commands.update", "session.info", "usage.context"].includes(event.type)) {
|
|
23602
|
-
if (this.#sessionHandler)
|
|
23603
|
-
this.#sessionHandler(event);
|
|
23604
|
-
else
|
|
23605
|
-
this.#pendingEvents.push(event);
|
|
23606
|
-
} else
|
|
23607
|
-
this.#active?.onEvent(event);
|
|
23608
|
-
}
|
|
23609
|
-
async #callback(sessionId, invoke, cancelled) {
|
|
23610
|
-
const active = this.#active;
|
|
23611
|
-
if (!active || !this.#acceptCallbacks || sessionId !== this.#sessionId || this.#closed)
|
|
23612
|
-
return cancelled;
|
|
23613
|
-
let cancel;
|
|
23614
|
-
const cancellation = new Promise((resolve) => {
|
|
23615
|
-
cancel = () => resolve(cancelled);
|
|
23616
|
-
});
|
|
23617
|
-
this.#callbacks.add(cancel);
|
|
23618
|
-
try {
|
|
23619
|
-
return await Promise.race([invoke(active), cancellation]);
|
|
23620
|
-
} finally {
|
|
23621
|
-
this.#callbacks.delete(cancel);
|
|
23622
|
-
}
|
|
23623
|
-
}
|
|
23624
|
-
#clearCallbacks() {
|
|
23625
|
-
for (const cancel of this.#callbacks)
|
|
23626
|
-
cancel();
|
|
23627
|
-
this.#callbacks.clear();
|
|
23628
|
-
}
|
|
23629
|
-
async #request(promise2, operation, timeoutMs = this.options.commandTimeoutMs ?? 3e4, signal) {
|
|
23630
|
-
let timer;
|
|
23631
|
-
let abort;
|
|
23632
|
-
const signals = [this.#faultSignal.signal, ...signal ? [signal] : []];
|
|
23633
|
-
const interrupted = new Promise((_, reject) => {
|
|
23634
|
-
abort = () => reject(signal?.aborted ? signal.reason : this.#faultSignal.signal.reason);
|
|
23635
|
-
if (signals.some((candidate) => candidate.aborted))
|
|
23636
|
-
abort();
|
|
23637
|
-
else
|
|
23638
|
-
for (const candidate of signals)
|
|
23639
|
-
candidate.addEventListener("abort", abort, { once: true });
|
|
23640
|
-
if (timeoutMs !== null)
|
|
23641
|
-
timer = setTimeout(() => reject(new AntigravityTransportError("unavailable", `${operation} timed out after ${timeoutMs}ms`, { diagnostic: this.#stderr })), timeoutMs);
|
|
23642
|
-
});
|
|
23643
|
-
try {
|
|
23644
|
-
return await Promise.race([promise2, interrupted]);
|
|
23645
|
-
} catch (error51) {
|
|
23646
|
-
const normalized = this.#error(error51);
|
|
23647
|
-
if (normalized.kind === "unavailable" && normalized.message.includes("timed out"))
|
|
23648
|
-
void this.close();
|
|
23649
|
-
throw normalized;
|
|
23650
|
-
} finally {
|
|
23651
|
-
clearTimeout(timer);
|
|
23652
|
-
for (const candidate of signals)
|
|
23653
|
-
candidate.removeEventListener("abort", abort);
|
|
23654
|
-
}
|
|
23521
|
+
if (!wroteCascadeId) {
|
|
23522
|
+
chunks.push(encodeLengthDelimited(6, Buffer.from(cascadeId, "utf8")));
|
|
23655
23523
|
}
|
|
23656
|
-
|
|
23657
|
-
|
|
23658
|
-
return error51;
|
|
23659
|
-
const message2 = sanitizeDiagnosticTail(error51 instanceof Error ? error51.message : String(error51));
|
|
23660
|
-
const code = error51?.code;
|
|
23661
|
-
return new AntigravityTransportError(code === -32e3 || /auth|login|sign[ -]?in|unauthenticated/iu.test(message2) ? "authenticationRequired" : "unavailable", message2, { cause: error51, diagnostic: this.#stderr });
|
|
23524
|
+
if (!hasProjectId) {
|
|
23525
|
+
chunks.push(encodeLengthDelimited(18, Buffer.from(DEFAULT_CLI_PROJECT_ID, "utf8")));
|
|
23662
23526
|
}
|
|
23663
|
-
|
|
23664
|
-
|
|
23665
|
-
|
|
23666
|
-
|
|
23667
|
-
|
|
23668
|
-
|
|
23669
|
-
|
|
23527
|
+
return Buffer.concat(chunks);
|
|
23528
|
+
}
|
|
23529
|
+
|
|
23530
|
+
// dist/native-turn-boundaries.js
|
|
23531
|
+
import { access } from "node:fs/promises";
|
|
23532
|
+
async function readNativeTurnCount(dbPath) {
|
|
23533
|
+
await access(dbPath);
|
|
23534
|
+
const { DatabaseSync } = await import("node:sqlite");
|
|
23535
|
+
const db = new DatabaseSync(dbPath, { readOnly: true });
|
|
23536
|
+
try {
|
|
23537
|
+
const row = db.prepare("SELECT count(*) AS n FROM steps WHERE step_type = 14").get();
|
|
23538
|
+
return Number(row?.n ?? 0);
|
|
23539
|
+
} finally {
|
|
23540
|
+
db.close();
|
|
23670
23541
|
}
|
|
23671
|
-
}
|
|
23542
|
+
}
|
|
23543
|
+
function nativeHistoryError(error51) {
|
|
23544
|
+
const missing = error51?.code === "ENOENT";
|
|
23545
|
+
return {
|
|
23546
|
+
code: missing ? "sessionNotFound" : "nativeFailure",
|
|
23547
|
+
message: missing ? "Antigravity native conversation database was not found" : "Cannot read or derive Antigravity native history",
|
|
23548
|
+
retryable: false
|
|
23549
|
+
};
|
|
23550
|
+
}
|
|
23672
23551
|
|
|
23673
|
-
// dist/
|
|
23552
|
+
// dist/usage-statistics.js
|
|
23553
|
+
import { lstat, opendir } from "node:fs/promises";
|
|
23554
|
+
import os2 from "node:os";
|
|
23555
|
+
import path8 from "node:path";
|
|
23556
|
+
|
|
23557
|
+
// ../../harness-adapter/dist/usage-statistics.js
|
|
23674
23558
|
import { createReadStream } from "node:fs";
|
|
23675
|
-
import path7 from "node:path";
|
|
23676
23559
|
import { createInterface } from "node:readline";
|
|
23677
|
-
|
|
23678
|
-
|
|
23679
|
-
|
|
23680
|
-
|
|
23681
|
-
|
|
23682
|
-
function decodeVarint(buffer, start) {
|
|
23683
|
-
let value = 0n;
|
|
23684
|
-
for (let index = 0; index < 10; index++) {
|
|
23685
|
-
const byte = buffer[start + index];
|
|
23686
|
-
if (byte === void 0 || index === 9 && byte > 1)
|
|
23687
|
-
return null;
|
|
23688
|
-
value |= BigInt(byte & 127) << BigInt(index * 7);
|
|
23689
|
-
if ((byte & 128) === 0)
|
|
23690
|
-
return [value, start + index + 1];
|
|
23560
|
+
var HarnessUsageSourceChangedError = class extends Error {
|
|
23561
|
+
code = "HARNESS_USAGE_SOURCE_CHANGED";
|
|
23562
|
+
/** Plugins may bundle their own copy of this contract, so instanceof is insufficient. */
|
|
23563
|
+
static is(error51) {
|
|
23564
|
+
return typeof error51 === "object" && error51 !== null && "code" in error51 && error51.code === "HARNESS_USAGE_SOURCE_CHANGED";
|
|
23691
23565
|
}
|
|
23692
|
-
|
|
23566
|
+
};
|
|
23567
|
+
var MAX_SESSION_ID_LENGTH = 512;
|
|
23568
|
+
var MAX_CWD_LENGTH = 4096;
|
|
23569
|
+
var MAX_SESSION_TITLE_LENGTH = 200;
|
|
23570
|
+
function usageSessionTitle(value) {
|
|
23571
|
+
if (typeof value !== "string")
|
|
23572
|
+
return void 0;
|
|
23573
|
+
const normalized = value.replaceAll("\0", "").replaceAll(/\s+/gu, " ").trim();
|
|
23574
|
+
if (!normalized)
|
|
23575
|
+
return void 0;
|
|
23576
|
+
if (normalized.length <= MAX_SESSION_TITLE_LENGTH)
|
|
23577
|
+
return normalized;
|
|
23578
|
+
let title = "";
|
|
23579
|
+
for (const character of normalized) {
|
|
23580
|
+
if (title.length + character.length >= MAX_SESSION_TITLE_LENGTH)
|
|
23581
|
+
break;
|
|
23582
|
+
title += character;
|
|
23583
|
+
}
|
|
23584
|
+
return `${title.trimEnd()}…`;
|
|
23693
23585
|
}
|
|
23694
|
-
function
|
|
23695
|
-
|
|
23696
|
-
|
|
23697
|
-
|
|
23698
|
-
|
|
23699
|
-
|
|
23700
|
-
|
|
23701
|
-
|
|
23702
|
-
|
|
23703
|
-
|
|
23704
|
-
|
|
23705
|
-
|
|
23706
|
-
|
|
23707
|
-
|
|
23708
|
-
|
|
23709
|
-
|
|
23710
|
-
|
|
23711
|
-
|
|
23712
|
-
|
|
23713
|
-
|
|
23714
|
-
|
|
23715
|
-
|
|
23716
|
-
|
|
23717
|
-
|
|
23718
|
-
|
|
23719
|
-
|
|
23720
|
-
|
|
23721
|
-
|
|
23722
|
-
|
|
23723
|
-
|
|
23724
|
-
|
|
23725
|
-
|
|
23726
|
-
}
|
|
23727
|
-
|
|
23586
|
+
function sessionIdOk(value) {
|
|
23587
|
+
return typeof value === "string" && value.length > 0 && value.length <= MAX_SESSION_ID_LENGTH;
|
|
23588
|
+
}
|
|
23589
|
+
function cwdOk(value) {
|
|
23590
|
+
return typeof value === "string" && value.length > 0 && value.length <= MAX_CWD_LENGTH && !value.includes("\0") && (value.startsWith("/") || /^[A-Za-z]:[\\/]/u.test(value) || value.startsWith("\\\\"));
|
|
23591
|
+
}
|
|
23592
|
+
function withUsageSession(entry, session) {
|
|
23593
|
+
const sessionId = sessionIdOk(session.sessionId) ? session.sessionId : void 0;
|
|
23594
|
+
const cwd = cwdOk(session.cwd) ? session.cwd : void 0;
|
|
23595
|
+
const sessionTitle = sessionId !== void 0 ? usageSessionTitle(session.title) : void 0;
|
|
23596
|
+
if (sessionId === void 0 && cwd === void 0)
|
|
23597
|
+
return entry;
|
|
23598
|
+
return {
|
|
23599
|
+
...entry,
|
|
23600
|
+
...sessionId !== void 0 ? { sessionId } : {},
|
|
23601
|
+
...cwd !== void 0 ? { cwd } : {},
|
|
23602
|
+
...sessionTitle !== void 0 ? { sessionTitle } : {}
|
|
23603
|
+
};
|
|
23604
|
+
}
|
|
23605
|
+
async function* jsonlRecords(file2, marker, signal) {
|
|
23606
|
+
const lines = createInterface({
|
|
23607
|
+
input: createReadStream(file2, { encoding: "utf8", signal }),
|
|
23608
|
+
crlfDelay: Infinity
|
|
23609
|
+
});
|
|
23610
|
+
for await (const line of lines) {
|
|
23611
|
+
if (!line.includes(marker))
|
|
23612
|
+
continue;
|
|
23613
|
+
let value;
|
|
23614
|
+
try {
|
|
23615
|
+
value = JSON.parse(line);
|
|
23616
|
+
} catch {
|
|
23617
|
+
continue;
|
|
23618
|
+
}
|
|
23619
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
23620
|
+
yield value;
|
|
23621
|
+
}
|
|
23728
23622
|
}
|
|
23729
|
-
return fields;
|
|
23730
23623
|
}
|
|
23624
|
+
function nativeTimeMs(value) {
|
|
23625
|
+
const time3 = typeof value === "number" ? value : typeof value === "string" ? Date.parse(value) : Number.NaN;
|
|
23626
|
+
return Number.isFinite(time3) && time3 > 0 ? Math.floor(time3) : null;
|
|
23627
|
+
}
|
|
23628
|
+
|
|
23629
|
+
// dist/acp-usage.js
|
|
23630
|
+
import { createReadStream as createReadStream2 } from "node:fs";
|
|
23631
|
+
import path7 from "node:path";
|
|
23632
|
+
import { createInterface as createInterface2 } from "node:readline";
|
|
23731
23633
|
|
|
23732
23634
|
// dist/native-request-timing.js
|
|
23635
|
+
import path6 from "node:path";
|
|
23733
23636
|
var MAX_METADATA_BYTES = 8 * 1024 * 1024;
|
|
23734
23637
|
var NANOSECONDS_PER_MS = 1000000n;
|
|
23735
23638
|
var MAX_MS = BigInt(Number.MAX_SAFE_INTEGER);
|
|
@@ -23780,31 +23683,40 @@ function stepIndices(fields) {
|
|
|
23780
23683
|
function matchesUsage(fields, request) {
|
|
23781
23684
|
if (!fields)
|
|
23782
23685
|
return false;
|
|
23783
|
-
const input = unsigned(fields, 2), output = unsigned(fields, 3), cached2 = unsigned(fields, 5);
|
|
23784
|
-
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));
|
|
23686
|
+
const input = unsigned(fields, 2), output = unsigned(fields, 3), cached2 = unsigned(fields, 5), thought = unsigned(fields, 9);
|
|
23687
|
+
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));
|
|
23785
23688
|
}
|
|
23786
23689
|
function closeTo(left, right) {
|
|
23787
23690
|
const difference = left - right;
|
|
23788
23691
|
return difference >= -NANOSECONDS_PER_MS && difference <= NANOSECONDS_PER_MS;
|
|
23789
23692
|
}
|
|
23790
|
-
function
|
|
23693
|
+
function requestMetadata(metadata, generator, request) {
|
|
23791
23694
|
const chat = message(generator, 1);
|
|
23792
|
-
|
|
23695
|
+
const stepUsage = message(metadata, 9);
|
|
23696
|
+
const chatUsage = chat && message(chat, 4);
|
|
23697
|
+
if (!chat || !stepUsage || !chatUsage || !matchesUsage(stepUsage, request) || !matchesUsage(chatUsage, request))
|
|
23793
23698
|
return null;
|
|
23794
|
-
|
|
23699
|
+
const thought = unsigned(stepUsage, 9);
|
|
23700
|
+
if (thought === null || thought !== unsigned(chatUsage, 9))
|
|
23795
23701
|
return null;
|
|
23702
|
+
const facts = { reasoningOutputTokens: Number(thought) };
|
|
23703
|
+
if (unsigned(chat, 14) !== 0n || chat.filter((value) => value.number === 17).length > 1)
|
|
23704
|
+
return facts;
|
|
23796
23705
|
const created = nanoseconds(message(metadata, 1));
|
|
23797
23706
|
const started = nanoseconds(message(metadata, 6));
|
|
23798
23707
|
const completed = nanoseconds(message(metadata, 7));
|
|
23799
23708
|
const ttft = nanoseconds(message(chat, 11));
|
|
23800
23709
|
const streamed = nanoseconds(message(chat, 12));
|
|
23801
23710
|
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))
|
|
23802
|
-
return
|
|
23711
|
+
return facts;
|
|
23803
23712
|
const startedAtMs = Number(started / NANOSECONDS_PER_MS);
|
|
23804
23713
|
const completedAtMs = Number(completed / NANOSECONDS_PER_MS);
|
|
23805
|
-
return
|
|
23714
|
+
return {
|
|
23715
|
+
...facts,
|
|
23716
|
+
...completedAtMs > startedAtMs ? { timing: { startedAtMs, completedAtMs } } : {}
|
|
23717
|
+
};
|
|
23806
23718
|
}
|
|
23807
|
-
async function
|
|
23719
|
+
async function readAntigravityRequestMetadata(nativeSessionId, home, requests, neededSteps = new Set(requests.keys())) {
|
|
23808
23720
|
if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/u.test(nativeSessionId))
|
|
23809
23721
|
return null;
|
|
23810
23722
|
let database;
|
|
@@ -23828,6 +23740,10 @@ async function readAntigravityRequestTimings(nativeSessionId, home, requests, ne
|
|
|
23828
23740
|
const cascade = source && field2(source, 4);
|
|
23829
23741
|
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))
|
|
23830
23742
|
continue;
|
|
23743
|
+
const usage = message(metadata, 9);
|
|
23744
|
+
if (!usage || !matchesUsage(usage, request))
|
|
23745
|
+
continue;
|
|
23746
|
+
result.set(index, { reasoningOutputTokens: Number(unsigned(usage, 9)) });
|
|
23831
23747
|
const generated = generatorQuery.get(Number(generatorIndex));
|
|
23832
23748
|
if (!(generated?.data instanceof Uint8Array))
|
|
23833
23749
|
continue;
|
|
@@ -23838,9 +23754,11 @@ async function readAntigravityRequestTimings(nativeSessionId, home, requests, ne
|
|
|
23838
23754
|
const plannerSteps = [...new Set(indices.filter((step) => requests.get(step)))];
|
|
23839
23755
|
if (plannerSteps.length !== 1 || plannerSteps[0] !== index)
|
|
23840
23756
|
continue;
|
|
23841
|
-
const
|
|
23842
|
-
if (
|
|
23843
|
-
result.set(index,
|
|
23757
|
+
const facts = requestMetadata(metadata, fields, request);
|
|
23758
|
+
if (facts)
|
|
23759
|
+
result.set(index, facts);
|
|
23760
|
+
else
|
|
23761
|
+
result.delete(index);
|
|
23844
23762
|
}
|
|
23845
23763
|
return result;
|
|
23846
23764
|
} catch {
|
|
@@ -23903,7 +23821,7 @@ function promptUsage(raw) {
|
|
|
23903
23821
|
return null;
|
|
23904
23822
|
}
|
|
23905
23823
|
}
|
|
23906
|
-
function
|
|
23824
|
+
function timing(input) {
|
|
23907
23825
|
const { firstOutputAtMs, completedAtMs } = input;
|
|
23908
23826
|
return count3(firstOutputAtMs) && count3(completedAtMs) && completedAtMs >= firstOutputAtMs ? { startedAtMs: firstOutputAtMs, completedAtMs } : {};
|
|
23909
23827
|
}
|
|
@@ -24014,7 +23932,7 @@ var AntigravitySessionUsageTracker = class {
|
|
|
24014
23932
|
this.#turnActive = false;
|
|
24015
23933
|
}
|
|
24016
23934
|
#historyComplete() {
|
|
24017
|
-
return this.#complete && !this.#invalidated && !this.#
|
|
23935
|
+
return this.#complete && !this.#invalidated && !this.#pending;
|
|
24018
23936
|
}
|
|
24019
23937
|
#reconcile() {
|
|
24020
23938
|
if (this.#pending && usageMatches(requestUsage([...this.#requests.values()]), addUsage(this.#pending.base, this.#pending.usage), false))
|
|
@@ -24057,8 +23975,8 @@ var AntigravitySessionUsageTracker = class {
|
|
|
24057
23975
|
const requests = this.#consume(transcript, false, cacheUsage, input.completedAtMs !== void 0);
|
|
24058
23976
|
const single = requests[0];
|
|
24059
23977
|
const step = [...this.#turnCollectionSteps][0];
|
|
24060
|
-
if (!hadPending && !input.hasToolCalls && transcript.
|
|
24061
|
-
const updated = parseHostUsageRequest({ ...single, ...
|
|
23978
|
+
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)) {
|
|
23979
|
+
const updated = parseHostUsageRequest({ ...single, ...timing(input) });
|
|
24062
23980
|
requests[0] = updated;
|
|
24063
23981
|
this.#requests.set(step, updated);
|
|
24064
23982
|
}
|
|
@@ -24073,7 +23991,7 @@ var AntigravitySessionUsageTracker = class {
|
|
|
24073
23991
|
const request = this.#requests.get(step);
|
|
24074
23992
|
if (request?.startedAtMs === void 0 || request.completedAtMs === void 0 || request.completedAtMs <= request.startedAtMs || request.outputTokens <= 0)
|
|
24075
23993
|
continue;
|
|
24076
|
-
tokens += request.outputTokens;
|
|
23994
|
+
tokens += request.timedOutputTokens ?? request.outputTokens;
|
|
24077
23995
|
milliseconds += request.completedAtMs - request.startedAtMs;
|
|
24078
23996
|
}
|
|
24079
23997
|
if (milliseconds > 0)
|
|
@@ -24100,13 +24018,18 @@ var AntigravitySessionUsageTracker = class {
|
|
|
24100
24018
|
this.#invalidated = true;
|
|
24101
24019
|
continue;
|
|
24102
24020
|
}
|
|
24103
|
-
|
|
24021
|
+
const write = cacheUsage?.cacheWriteInputTokens;
|
|
24022
|
+
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);
|
|
24023
|
+
const native = transcript.metadata?.get(step);
|
|
24024
|
+
const thought = !historical && singleMatches && transcript.complete ? cacheUsage?.reasoningOutputTokens ?? native?.reasoningOutputTokens : native?.reasoningOutputTokens;
|
|
24025
|
+
let parsed = parseHostUsageRequest({
|
|
24026
|
+
...request,
|
|
24027
|
+
...thought !== void 0 && thought <= request.outputTokens ? { reasoningOutputTokens: thought } : {}
|
|
24028
|
+
});
|
|
24104
24029
|
if (!historical && request.cachedInputTokens !== void 0 && request.cacheWriteInputTokens === void 0) {
|
|
24105
|
-
const write = cacheUsage?.cacheWriteInputTokens;
|
|
24106
|
-
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);
|
|
24107
24030
|
if (write === 0 || write !== void 0 && singleMatches && transcript.complete)
|
|
24108
24031
|
parsed = parseHostUsageRequest({
|
|
24109
|
-
...
|
|
24032
|
+
...parsed,
|
|
24110
24033
|
inputTokens: request.inputTokens + (write ?? 0),
|
|
24111
24034
|
cacheWriteInputTokens: write
|
|
24112
24035
|
});
|
|
@@ -24115,9 +24038,13 @@ var AntigravitySessionUsageTracker = class {
|
|
|
24115
24038
|
this.#complete = false;
|
|
24116
24039
|
continue;
|
|
24117
24040
|
}
|
|
24118
|
-
const candidate =
|
|
24119
|
-
const clock =
|
|
24120
|
-
|
|
24041
|
+
const candidate = native?.timing;
|
|
24042
|
+
const clock = parsed.reasoningOutputTokens !== void 0 && parsed.reasoningOutputTokens === native?.reasoningOutputTokens && // A thinking-only request has no output inside the visible window to time.
|
|
24043
|
+
parsed.reasoningOutputTokens < parsed.outputTokens && !transcript.toolCallSteps.has(step) && candidate && (historical || candidate.startedAtMs >= this.#turnStartedAtMs) && candidate.completedAtMs <= Date.now() ? {
|
|
24044
|
+
...candidate,
|
|
24045
|
+
timedOutputTokens: parsed.outputTokens - parsed.reasoningOutputTokens
|
|
24046
|
+
} : void 0;
|
|
24047
|
+
if (!historical && this.#turnActive && !finalizing && transcript.metadata !== null && !clock && !transcript.toolCallSteps.has(step))
|
|
24121
24048
|
continue;
|
|
24122
24049
|
parsed = parseHostUsageRequest({
|
|
24123
24050
|
...parsed,
|
|
@@ -24132,13 +24059,13 @@ var AntigravitySessionUsageTracker = class {
|
|
|
24132
24059
|
}
|
|
24133
24060
|
async #read(signal, withTimings = true) {
|
|
24134
24061
|
signal?.throwIfAborted();
|
|
24135
|
-
const stream =
|
|
24136
|
-
const lines =
|
|
24062
|
+
const stream = createReadStream2(this.#file, { encoding: "utf8", signal });
|
|
24063
|
+
const lines = createInterface2({ input: stream, crlfDelay: Infinity });
|
|
24137
24064
|
const result = {
|
|
24138
24065
|
steps: /* @__PURE__ */ new Map(),
|
|
24139
24066
|
toolCallSteps: /* @__PURE__ */ new Set(),
|
|
24140
24067
|
complete: true,
|
|
24141
|
-
|
|
24068
|
+
metadata: null
|
|
24142
24069
|
};
|
|
24143
24070
|
try {
|
|
24144
24071
|
for await (const line of lines) {
|
|
@@ -24192,227 +24119,14 @@ var AntigravitySessionUsageTracker = class {
|
|
|
24192
24119
|
stream.destroy();
|
|
24193
24120
|
}
|
|
24194
24121
|
result.complete &&= [...result.steps.values()].every((request) => request !== null) && [...this.#consumed.keys()].every((step) => result.steps.has(step));
|
|
24195
|
-
const unseen = new Set([...result.steps.keys()].filter((step) => !this.#consumed.has(step)
|
|
24122
|
+
const unseen = new Set([...result.steps.keys()].filter((step) => !this.#consumed.has(step)));
|
|
24196
24123
|
if (withTimings && unseen.size > 0)
|
|
24197
|
-
result.
|
|
24124
|
+
result.metadata = await readAntigravityRequestMetadata(this.#nativeSessionId, this.#home, result.steps, unseen);
|
|
24198
24125
|
signal?.throwIfAborted();
|
|
24199
24126
|
return result;
|
|
24200
24127
|
}
|
|
24201
24128
|
};
|
|
24202
24129
|
|
|
24203
|
-
// dist/delegation.js
|
|
24204
|
-
var DELEGATION_ENVIRONMENT_KEYS = [
|
|
24205
|
-
"CODEXHOST_CLI_PATH",
|
|
24206
|
-
"CODEXHOST_RUNTIME_ENDPOINT",
|
|
24207
|
-
"CODEXHOST_RUNTIME_TOKEN",
|
|
24208
|
-
"CODEXHOST_THREAD_ID"
|
|
24209
|
-
];
|
|
24210
|
-
var ANTIGRAVITY_DELEGATION_INSTRUCTIONS = `This Antigravity Session runs inside codexhost.
|
|
24211
|
-
When the user requests cross-Harness delegation, use the executable specified by the CODEXHOST_CLI_PATH environment variable through your native shell tool. Start with --help and harness list, then use delegate start and thread send/read/wait/cancel as documented. Use --format compact for results. Keep the inherited CODEXHOST_RUNTIME_ENDPOINT, CODEXHOST_RUNTIME_TOKEN and CODEXHOST_THREAD_ID environment variables for every call; they identify this Runtime and parent Thread. Never print their values, substitute another executable, or delegate without user authorization. Native Antigravity subagents are separate from cross-Harness delegation.`;
|
|
24212
|
-
function antigravityDelegationInstructions(environment) {
|
|
24213
|
-
return DELEGATION_ENVIRONMENT_KEYS.every((key) => environment[key]) ? ANTIGRAVITY_DELEGATION_INSTRUCTIONS : void 0;
|
|
24214
|
-
}
|
|
24215
|
-
|
|
24216
|
-
// dist/fork.js
|
|
24217
|
-
import { randomUUID } from "node:crypto";
|
|
24218
|
-
import { access as access2, cp, mkdir, open, rm as rm2 } from "node:fs/promises";
|
|
24219
|
-
import os3 from "node:os";
|
|
24220
|
-
import path9 from "node:path";
|
|
24221
|
-
|
|
24222
|
-
// dist/native-trajectory-metadata.js
|
|
24223
|
-
var DEFAULT_CLI_PROJECT_ID = "default-cli-project";
|
|
24224
|
-
function encodeVarint(value) {
|
|
24225
|
-
const bytes = [];
|
|
24226
|
-
let remaining = value >>> 0;
|
|
24227
|
-
while (remaining >= 128) {
|
|
24228
|
-
bytes.push(remaining & 127 | 128);
|
|
24229
|
-
remaining >>>= 7;
|
|
24230
|
-
}
|
|
24231
|
-
bytes.push(remaining);
|
|
24232
|
-
return Buffer.from(bytes);
|
|
24233
|
-
}
|
|
24234
|
-
function encodeLengthDelimited(fieldNumber, payload) {
|
|
24235
|
-
return Buffer.concat([
|
|
24236
|
-
encodeVarint(fieldNumber << 3 | 2),
|
|
24237
|
-
encodeVarint(payload.length),
|
|
24238
|
-
Buffer.from(payload)
|
|
24239
|
-
]);
|
|
24240
|
-
}
|
|
24241
|
-
function minimalTrajectoryMetadataBlob(cascadeId, projectId = DEFAULT_CLI_PROJECT_ID) {
|
|
24242
|
-
return Buffer.concat([
|
|
24243
|
-
encodeLengthDelimited(6, Buffer.from(cascadeId, "utf8")),
|
|
24244
|
-
encodeLengthDelimited(18, Buffer.from(projectId, "utf8"))
|
|
24245
|
-
]);
|
|
24246
|
-
}
|
|
24247
|
-
function minimalRawSummaryBlob(trajectoryId, metadataBlob) {
|
|
24248
|
-
return Buffer.concat([
|
|
24249
|
-
encodeLengthDelimited(4, Buffer.from(trajectoryId, "utf8")),
|
|
24250
|
-
Buffer.from([40, 1]),
|
|
24251
|
-
encodeLengthDelimited(17, metadataBlob),
|
|
24252
|
-
Buffer.from([176, 1, 4])
|
|
24253
|
-
]);
|
|
24254
|
-
}
|
|
24255
|
-
function rewriteTrajectoryMetadataCascadeId(blob, cascadeId) {
|
|
24256
|
-
const chunks = [];
|
|
24257
|
-
let offset = 0;
|
|
24258
|
-
let wroteCascadeId = false;
|
|
24259
|
-
let hasProjectId = false;
|
|
24260
|
-
while (offset < blob.length) {
|
|
24261
|
-
const fieldStart = offset;
|
|
24262
|
-
const tagParsed = decodeVarint(blob, offset);
|
|
24263
|
-
if (!tagParsed)
|
|
24264
|
-
return null;
|
|
24265
|
-
const [tag, afterTag] = tagParsed;
|
|
24266
|
-
if (tag < 8n || tag > 0xffffffffn)
|
|
24267
|
-
return null;
|
|
24268
|
-
const fieldNumber = Number(tag >> 3n);
|
|
24269
|
-
const wireType = Number(tag & 7n);
|
|
24270
|
-
if (fieldNumber === 6 && wireType !== 2)
|
|
24271
|
-
return null;
|
|
24272
|
-
offset = afterTag;
|
|
24273
|
-
if (wireType === 0) {
|
|
24274
|
-
const valParsed = decodeVarint(blob, offset);
|
|
24275
|
-
if (!valParsed)
|
|
24276
|
-
return null;
|
|
24277
|
-
offset = valParsed[1];
|
|
24278
|
-
} else if (wireType === 1) {
|
|
24279
|
-
if (offset + 8 > blob.length)
|
|
24280
|
-
return null;
|
|
24281
|
-
offset += 8;
|
|
24282
|
-
} else if (wireType === 2) {
|
|
24283
|
-
const lenParsed = decodeVarint(blob, offset);
|
|
24284
|
-
if (!lenParsed)
|
|
24285
|
-
return null;
|
|
24286
|
-
const [length, afterLen] = lenParsed;
|
|
24287
|
-
if (length > BigInt(blob.length - afterLen))
|
|
24288
|
-
return null;
|
|
24289
|
-
offset = afterLen + Number(length);
|
|
24290
|
-
if (fieldNumber === 6) {
|
|
24291
|
-
if (!wroteCascadeId) {
|
|
24292
|
-
chunks.push(encodeLengthDelimited(6, Buffer.from(cascadeId, "utf8")));
|
|
24293
|
-
wroteCascadeId = true;
|
|
24294
|
-
}
|
|
24295
|
-
continue;
|
|
24296
|
-
}
|
|
24297
|
-
if (fieldNumber === 18)
|
|
24298
|
-
hasProjectId = true;
|
|
24299
|
-
} else if (wireType === 5) {
|
|
24300
|
-
if (offset + 4 > blob.length)
|
|
24301
|
-
return null;
|
|
24302
|
-
offset += 4;
|
|
24303
|
-
} else {
|
|
24304
|
-
return null;
|
|
24305
|
-
}
|
|
24306
|
-
chunks.push(Buffer.from(blob.subarray(fieldStart, offset)));
|
|
24307
|
-
}
|
|
24308
|
-
if (!wroteCascadeId) {
|
|
24309
|
-
chunks.push(encodeLengthDelimited(6, Buffer.from(cascadeId, "utf8")));
|
|
24310
|
-
}
|
|
24311
|
-
if (!hasProjectId) {
|
|
24312
|
-
chunks.push(encodeLengthDelimited(18, Buffer.from(DEFAULT_CLI_PROJECT_ID, "utf8")));
|
|
24313
|
-
}
|
|
24314
|
-
return Buffer.concat(chunks);
|
|
24315
|
-
}
|
|
24316
|
-
|
|
24317
|
-
// dist/native-turn-boundaries.js
|
|
24318
|
-
import { access } from "node:fs/promises";
|
|
24319
|
-
async function readNativeTurnCount(dbPath) {
|
|
24320
|
-
await access(dbPath);
|
|
24321
|
-
const { DatabaseSync } = await import("node:sqlite");
|
|
24322
|
-
const db = new DatabaseSync(dbPath, { readOnly: true });
|
|
24323
|
-
try {
|
|
24324
|
-
const row = db.prepare("SELECT count(*) AS n FROM steps WHERE step_type = 14").get();
|
|
24325
|
-
return Number(row?.n ?? 0);
|
|
24326
|
-
} finally {
|
|
24327
|
-
db.close();
|
|
24328
|
-
}
|
|
24329
|
-
}
|
|
24330
|
-
function nativeHistoryError(error51) {
|
|
24331
|
-
const missing = error51?.code === "ENOENT";
|
|
24332
|
-
return {
|
|
24333
|
-
code: missing ? "sessionNotFound" : "nativeFailure",
|
|
24334
|
-
message: missing ? "Antigravity native conversation database was not found" : "Cannot read or derive Antigravity native history",
|
|
24335
|
-
retryable: false
|
|
24336
|
-
};
|
|
24337
|
-
}
|
|
24338
|
-
|
|
24339
|
-
// dist/usage-statistics.js
|
|
24340
|
-
import { lstat, opendir } from "node:fs/promises";
|
|
24341
|
-
import os2 from "node:os";
|
|
24342
|
-
import path8 from "node:path";
|
|
24343
|
-
|
|
24344
|
-
// ../../harness-adapter/dist/usage-statistics.js
|
|
24345
|
-
import { createReadStream as createReadStream2 } from "node:fs";
|
|
24346
|
-
import { createInterface as createInterface2 } from "node:readline";
|
|
24347
|
-
var HarnessUsageSourceChangedError = class extends Error {
|
|
24348
|
-
code = "HARNESS_USAGE_SOURCE_CHANGED";
|
|
24349
|
-
/** Plugins may bundle their own copy of this contract, so instanceof is insufficient. */
|
|
24350
|
-
static is(error51) {
|
|
24351
|
-
return typeof error51 === "object" && error51 !== null && "code" in error51 && error51.code === "HARNESS_USAGE_SOURCE_CHANGED";
|
|
24352
|
-
}
|
|
24353
|
-
};
|
|
24354
|
-
var MAX_SESSION_ID_LENGTH = 512;
|
|
24355
|
-
var MAX_CWD_LENGTH = 4096;
|
|
24356
|
-
var MAX_SESSION_TITLE_LENGTH = 200;
|
|
24357
|
-
function usageSessionTitle(value) {
|
|
24358
|
-
if (typeof value !== "string")
|
|
24359
|
-
return void 0;
|
|
24360
|
-
const normalized = value.replaceAll("\0", "").replaceAll(/\s+/gu, " ").trim();
|
|
24361
|
-
if (!normalized)
|
|
24362
|
-
return void 0;
|
|
24363
|
-
if (normalized.length <= MAX_SESSION_TITLE_LENGTH)
|
|
24364
|
-
return normalized;
|
|
24365
|
-
let title = "";
|
|
24366
|
-
for (const character of normalized) {
|
|
24367
|
-
if (title.length + character.length >= MAX_SESSION_TITLE_LENGTH)
|
|
24368
|
-
break;
|
|
24369
|
-
title += character;
|
|
24370
|
-
}
|
|
24371
|
-
return `${title.trimEnd()}…`;
|
|
24372
|
-
}
|
|
24373
|
-
function sessionIdOk(value) {
|
|
24374
|
-
return typeof value === "string" && value.length > 0 && value.length <= MAX_SESSION_ID_LENGTH;
|
|
24375
|
-
}
|
|
24376
|
-
function cwdOk(value) {
|
|
24377
|
-
return typeof value === "string" && value.length > 0 && value.length <= MAX_CWD_LENGTH && !value.includes("\0") && (value.startsWith("/") || /^[A-Za-z]:[\\/]/u.test(value) || value.startsWith("\\\\"));
|
|
24378
|
-
}
|
|
24379
|
-
function withUsageSession(entry, session) {
|
|
24380
|
-
const sessionId = sessionIdOk(session.sessionId) ? session.sessionId : void 0;
|
|
24381
|
-
const cwd = cwdOk(session.cwd) ? session.cwd : void 0;
|
|
24382
|
-
const sessionTitle = sessionId !== void 0 ? usageSessionTitle(session.title) : void 0;
|
|
24383
|
-
if (sessionId === void 0 && cwd === void 0)
|
|
24384
|
-
return entry;
|
|
24385
|
-
return {
|
|
24386
|
-
...entry,
|
|
24387
|
-
...sessionId !== void 0 ? { sessionId } : {},
|
|
24388
|
-
...cwd !== void 0 ? { cwd } : {},
|
|
24389
|
-
...sessionTitle !== void 0 ? { sessionTitle } : {}
|
|
24390
|
-
};
|
|
24391
|
-
}
|
|
24392
|
-
async function* jsonlRecords(file2, marker, signal) {
|
|
24393
|
-
const lines = createInterface2({
|
|
24394
|
-
input: createReadStream2(file2, { encoding: "utf8", signal }),
|
|
24395
|
-
crlfDelay: Infinity
|
|
24396
|
-
});
|
|
24397
|
-
for await (const line of lines) {
|
|
24398
|
-
if (!line.includes(marker))
|
|
24399
|
-
continue;
|
|
24400
|
-
let value;
|
|
24401
|
-
try {
|
|
24402
|
-
value = JSON.parse(line);
|
|
24403
|
-
} catch {
|
|
24404
|
-
continue;
|
|
24405
|
-
}
|
|
24406
|
-
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
24407
|
-
yield value;
|
|
24408
|
-
}
|
|
24409
|
-
}
|
|
24410
|
-
}
|
|
24411
|
-
function nativeTimeMs(value) {
|
|
24412
|
-
const time3 = typeof value === "number" ? value : typeof value === "string" ? Date.parse(value) : Number.NaN;
|
|
24413
|
-
return Number.isFinite(time3) && time3 > 0 ? Math.floor(time3) : null;
|
|
24414
|
-
}
|
|
24415
|
-
|
|
24416
24130
|
// dist/usage-statistics.js
|
|
24417
24131
|
function count4(value) {
|
|
24418
24132
|
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
@@ -24582,184 +24296,602 @@ async function cloneNativeConversationDb(sourceId, derivedId, retainedTurnsCount
|
|
|
24582
24296
|
target2.prepare(`DELETE FROM ${table} WHERE idx >= ?`).run(cutoff);
|
|
24583
24297
|
}
|
|
24584
24298
|
}
|
|
24585
|
-
target2.exec("COMMIT");
|
|
24299
|
+
target2.exec("COMMIT");
|
|
24300
|
+
} finally {
|
|
24301
|
+
target2.close();
|
|
24302
|
+
}
|
|
24303
|
+
await registerDerivedSummary(sourceId, derivedId, home);
|
|
24304
|
+
return true;
|
|
24305
|
+
} catch (error51) {
|
|
24306
|
+
if (owned)
|
|
24307
|
+
await removeDerivedDb(derivedId, home);
|
|
24308
|
+
throw error51;
|
|
24309
|
+
} finally {
|
|
24310
|
+
source.close();
|
|
24311
|
+
}
|
|
24312
|
+
}
|
|
24313
|
+
async function registerDerivedSummary(sourceId, derivedId, home) {
|
|
24314
|
+
const summaryPath = nativeConversationSummariesDbPath(home);
|
|
24315
|
+
try {
|
|
24316
|
+
await access2(summaryPath);
|
|
24317
|
+
} catch (error51) {
|
|
24318
|
+
if (error51.code === "ENOENT")
|
|
24319
|
+
return;
|
|
24320
|
+
throw error51;
|
|
24321
|
+
}
|
|
24322
|
+
const { DatabaseSync } = await import("node:sqlite");
|
|
24323
|
+
const summaries = new DatabaseSync(summaryPath);
|
|
24324
|
+
try {
|
|
24325
|
+
const template = summaries.prepare("SELECT * FROM conversation_summaries WHERE conversation_id = ?").get(sourceId);
|
|
24326
|
+
if (!template)
|
|
24327
|
+
return;
|
|
24328
|
+
const derived = new DatabaseSync(nativeConversationDbPath(derivedId, home), { readOnly: true });
|
|
24329
|
+
let row;
|
|
24330
|
+
try {
|
|
24331
|
+
const metadata = derived.prepare("SELECT data FROM trajectory_metadata_blob WHERE id = 'main'").get()?.data;
|
|
24332
|
+
const trajectoryId = derived.prepare("SELECT trajectory_id FROM trajectory_meta LIMIT 1").get()?.trajectory_id;
|
|
24333
|
+
row = {
|
|
24334
|
+
...template,
|
|
24335
|
+
conversation_id: derivedId,
|
|
24336
|
+
status: "CASCADE_RUN_STATUS_IDLE",
|
|
24337
|
+
step_count: Number(derived.prepare("SELECT count(*) AS n FROM steps").get()?.n),
|
|
24338
|
+
last_user_input_step_index: Number(derived.prepare("SELECT max(idx) AS idx FROM steps WHERE step_type = 14").get()?.idx ?? -1),
|
|
24339
|
+
not_fully_idle: 0,
|
|
24340
|
+
killed: 0,
|
|
24341
|
+
last_modified_time: (/* @__PURE__ */ new Date()).toISOString(),
|
|
24342
|
+
raw_summary: minimalRawSummaryBlob(String(trajectoryId), Buffer.from(metadata))
|
|
24343
|
+
};
|
|
24344
|
+
} finally {
|
|
24345
|
+
derived.close();
|
|
24346
|
+
}
|
|
24347
|
+
const columns = Object.keys(template);
|
|
24348
|
+
summaries.prepare(`INSERT INTO conversation_summaries (${columns.map((name) => `"${name.replaceAll('"', '""')}"`).join(",")}) VALUES (${columns.map(() => "?").join(",")})`).run(...columns.map((name) => row[name] ?? null));
|
|
24349
|
+
} finally {
|
|
24350
|
+
summaries.close();
|
|
24351
|
+
}
|
|
24352
|
+
}
|
|
24353
|
+
async function removeDerivedSummary(id, home) {
|
|
24354
|
+
try {
|
|
24355
|
+
await access2(nativeConversationSummariesDbPath(home));
|
|
24356
|
+
} catch (error51) {
|
|
24357
|
+
if (error51.code === "ENOENT")
|
|
24358
|
+
return;
|
|
24359
|
+
throw error51;
|
|
24360
|
+
}
|
|
24361
|
+
const { DatabaseSync } = await import("node:sqlite");
|
|
24362
|
+
const db = new DatabaseSync(nativeConversationSummariesDbPath(home));
|
|
24363
|
+
try {
|
|
24364
|
+
db.prepare("DELETE FROM conversation_summaries WHERE conversation_id = ?").run(id);
|
|
24365
|
+
} finally {
|
|
24366
|
+
db.close();
|
|
24367
|
+
}
|
|
24368
|
+
}
|
|
24369
|
+
async function removeDerivedDb(id, home) {
|
|
24370
|
+
const file2 = nativeConversationDbPath(id, home);
|
|
24371
|
+
await Promise.all([file2, `${file2}-wal`, `${file2}-shm`].map((target2) => rm2(target2, { force: true })));
|
|
24372
|
+
}
|
|
24373
|
+
async function copyNativeBrainDirIfExists(sourceId, derivedId, home = os3.homedir()) {
|
|
24374
|
+
try {
|
|
24375
|
+
await access2(nativeBrainDirPath(sourceId, home));
|
|
24376
|
+
} catch (error51) {
|
|
24377
|
+
if (error51.code === "ENOENT")
|
|
24378
|
+
return false;
|
|
24379
|
+
throw error51;
|
|
24380
|
+
}
|
|
24381
|
+
await cp(nativeBrainDirPath(sourceId, home), nativeBrainDirPath(derivedId, home), {
|
|
24382
|
+
recursive: true,
|
|
24383
|
+
errorOnExist: true,
|
|
24384
|
+
force: false,
|
|
24385
|
+
filter: (source) => path9.basename(source) !== ".system_generated"
|
|
24386
|
+
});
|
|
24387
|
+
return true;
|
|
24388
|
+
}
|
|
24389
|
+
async function openDerivedAntigravitySession(options, input, sourceRef, retained) {
|
|
24390
|
+
const environment = { ...options.adapterEnvironment, ...input.environment };
|
|
24391
|
+
const home = antigravityHome(environment);
|
|
24392
|
+
const derivedId = randomUUID();
|
|
24393
|
+
let cloned = false;
|
|
24394
|
+
try {
|
|
24395
|
+
await cloneNativeConversationDb(sourceRef.nativeSessionId, derivedId, retained, home);
|
|
24396
|
+
cloned = true;
|
|
24397
|
+
await copyNativeBrainDirIfExists(sourceRef.nativeSessionId, derivedId, home);
|
|
24398
|
+
const result = await options.openSession({
|
|
24399
|
+
...input,
|
|
24400
|
+
environment,
|
|
24401
|
+
nativeRef: { ...sourceRef, nativeSessionId: derivedId }
|
|
24402
|
+
});
|
|
24403
|
+
if (result.ok)
|
|
24404
|
+
return result;
|
|
24405
|
+
const cleanupFailure = await cleanup().then(() => void 0, () => "Derived native history cleanup failed");
|
|
24406
|
+
return cleanupFailure ? { ok: false, error: { ...result.error, diagnostic: cleanupFailure } } : result;
|
|
24407
|
+
} catch (error51) {
|
|
24408
|
+
const cleanupFailure = await cleanup().then(() => void 0, () => "Derived native history cleanup failed");
|
|
24409
|
+
return {
|
|
24410
|
+
ok: false,
|
|
24411
|
+
error: {
|
|
24412
|
+
...nativeHistoryError(error51),
|
|
24413
|
+
...cleanupFailure ? { diagnostic: cleanupFailure } : {}
|
|
24414
|
+
}
|
|
24415
|
+
};
|
|
24416
|
+
}
|
|
24417
|
+
async function cleanup() {
|
|
24418
|
+
if (!cloned)
|
|
24419
|
+
return;
|
|
24420
|
+
await Promise.all([
|
|
24421
|
+
removeDerivedDb(derivedId, home),
|
|
24422
|
+
rm2(nativeBrainDirPath(derivedId, home), { recursive: true, force: true }),
|
|
24423
|
+
removeDerivedSummary(derivedId, home)
|
|
24424
|
+
]);
|
|
24425
|
+
}
|
|
24426
|
+
}
|
|
24427
|
+
async function forkAntigravitySession(options) {
|
|
24428
|
+
const { input, harnessId: harnessId2 } = options;
|
|
24429
|
+
if (!validNativeSessionRef(input.sourceRef, harnessId2))
|
|
24430
|
+
return {
|
|
24431
|
+
ok: false,
|
|
24432
|
+
error: {
|
|
24433
|
+
code: "invalidRequest",
|
|
24434
|
+
message: "Invalid Antigravity source Native Session",
|
|
24435
|
+
retryable: false
|
|
24436
|
+
}
|
|
24437
|
+
};
|
|
24438
|
+
const checkpoint = nativeCheckpointRefSchema.safeParse(input.checkpoint);
|
|
24439
|
+
if (!checkpoint.success || checkpoint.data.harnessId !== harnessId2 || checkpoint.data.nativeSessionId !== input.sourceRef.nativeSessionId)
|
|
24440
|
+
return checkpointError();
|
|
24441
|
+
if (options.sourceSession?.isActive)
|
|
24442
|
+
return {
|
|
24443
|
+
ok: false,
|
|
24444
|
+
error: {
|
|
24445
|
+
code: "sessionBusy",
|
|
24446
|
+
message: "Source Session is busy",
|
|
24447
|
+
retryable: true
|
|
24448
|
+
}
|
|
24449
|
+
};
|
|
24450
|
+
const match = /^turn-(0|[1-9]\d*)$/u.exec(checkpoint.data.checkpointId);
|
|
24451
|
+
if (!match)
|
|
24452
|
+
return checkpointError();
|
|
24453
|
+
try {
|
|
24454
|
+
const count5 = await readNativeTurnCount(nativeConversationDbPath(input.sourceRef.nativeSessionId, antigravityHome({ ...options.adapterEnvironment, ...input.environment })));
|
|
24455
|
+
const index = Number(match[1]);
|
|
24456
|
+
if (!Number.isSafeInteger(index) || index >= count5)
|
|
24457
|
+
return checkpointError();
|
|
24458
|
+
return openDerivedAntigravitySession(options, {
|
|
24459
|
+
kind: "resume",
|
|
24460
|
+
nativeRef: input.sourceRef,
|
|
24461
|
+
cwd: input.cwd,
|
|
24462
|
+
...input.environment ? { environment: input.environment } : {}
|
|
24463
|
+
}, input.sourceRef, index + 1);
|
|
24464
|
+
} catch (error51) {
|
|
24465
|
+
return { ok: false, error: nativeHistoryError(error51) };
|
|
24466
|
+
}
|
|
24467
|
+
}
|
|
24468
|
+
function checkpointError() {
|
|
24469
|
+
return {
|
|
24470
|
+
ok: false,
|
|
24471
|
+
error: {
|
|
24472
|
+
code: "checkpointNotFound",
|
|
24473
|
+
message: "Antigravity native Turn checkpoint not found",
|
|
24474
|
+
retryable: false
|
|
24475
|
+
}
|
|
24476
|
+
};
|
|
24477
|
+
}
|
|
24478
|
+
|
|
24479
|
+
// dist/native-replay.js
|
|
24480
|
+
async function readNativeReplaySize(sessionId, home) {
|
|
24481
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/u.test(sessionId))
|
|
24482
|
+
throw new AntigravityTransportError("protocolError", "Invalid native Session ID");
|
|
24483
|
+
const { DatabaseSync } = await import("node:sqlite");
|
|
24484
|
+
const db = new DatabaseSync(nativeConversationDbPath(sessionId, home), { readOnly: true });
|
|
24485
|
+
const size = { users: 0, text: 0, thought: 0, tools: 0 };
|
|
24486
|
+
try {
|
|
24487
|
+
for (const row of db.prepare("SELECT step_type, step_payload FROM steps WHERE step_type IN (14, 15) ORDER BY idx").iterate()) {
|
|
24488
|
+
if (row.step_type === 14) {
|
|
24489
|
+
size.users++;
|
|
24490
|
+
continue;
|
|
24491
|
+
}
|
|
24492
|
+
const planner = row.step_payload instanceof Uint8Array ? readProtoFields(row.step_payload)?.find((field3) => field3.number === 20)?.value : void 0;
|
|
24493
|
+
const fields = planner instanceof Uint8Array ? readProtoFields(planner) : null;
|
|
24494
|
+
if (!fields)
|
|
24495
|
+
throw new AntigravityTransportError("protocolError", "Cannot verify Antigravity history replay");
|
|
24496
|
+
for (const field3 of fields) {
|
|
24497
|
+
if (!(field3.value instanceof Uint8Array))
|
|
24498
|
+
continue;
|
|
24499
|
+
if (field3.number === 1)
|
|
24500
|
+
size.text += Buffer.from(field3.value).toString("utf8").length;
|
|
24501
|
+
if (field3.number === 3)
|
|
24502
|
+
size.thought += Buffer.from(field3.value).toString("utf8").length;
|
|
24503
|
+
if (field3.number === 7)
|
|
24504
|
+
size.tools++;
|
|
24505
|
+
}
|
|
24506
|
+
}
|
|
24507
|
+
return size;
|
|
24508
|
+
} finally {
|
|
24509
|
+
db.close();
|
|
24510
|
+
}
|
|
24511
|
+
}
|
|
24512
|
+
function nativeReplayCompletion(expected) {
|
|
24513
|
+
const received = {
|
|
24514
|
+
users: 0,
|
|
24515
|
+
text: 0,
|
|
24516
|
+
thought: 0,
|
|
24517
|
+
tools: 0,
|
|
24518
|
+
usage: false,
|
|
24519
|
+
sessionInfo: false
|
|
24520
|
+
};
|
|
24521
|
+
let resolve;
|
|
24522
|
+
const complete = new Promise((done) => {
|
|
24523
|
+
resolve = done;
|
|
24524
|
+
});
|
|
24525
|
+
const check2 = () => {
|
|
24526
|
+
if (received.users === expected.users && received.text === expected.text && received.thought === expected.thought && received.tools === expected.tools && received.usage && received.sessionInfo)
|
|
24527
|
+
resolve();
|
|
24528
|
+
};
|
|
24529
|
+
check2();
|
|
24530
|
+
return {
|
|
24531
|
+
complete,
|
|
24532
|
+
observe(event) {
|
|
24533
|
+
if (event.type === "user.text")
|
|
24534
|
+
received.users++;
|
|
24535
|
+
if (event.type === "agent.text")
|
|
24536
|
+
received.text += event.text.length;
|
|
24537
|
+
if (event.type === "agent.thought")
|
|
24538
|
+
received.thought += event.text.length;
|
|
24539
|
+
if (event.type === "tool.call")
|
|
24540
|
+
received.tools++;
|
|
24541
|
+
if (event.type === "usage.context")
|
|
24542
|
+
received.usage = true;
|
|
24543
|
+
if (event.type === "session.info")
|
|
24544
|
+
received.sessionInfo = true;
|
|
24545
|
+
check2();
|
|
24546
|
+
}
|
|
24547
|
+
};
|
|
24548
|
+
}
|
|
24549
|
+
|
|
24550
|
+
// dist/acp-transport.js
|
|
24551
|
+
var AntigravityAcpTransport = class {
|
|
24552
|
+
options;
|
|
24553
|
+
skipPermissions;
|
|
24554
|
+
#child = null;
|
|
24555
|
+
#connection = null;
|
|
24556
|
+
#initializing = null;
|
|
24557
|
+
#sessionId = null;
|
|
24558
|
+
#sessionHandler = null;
|
|
24559
|
+
#active = null;
|
|
24560
|
+
#callbacks = /* @__PURE__ */ new Set();
|
|
24561
|
+
#acceptCallbacks = false;
|
|
24562
|
+
#promptInterrupted = null;
|
|
24563
|
+
#opening = null;
|
|
24564
|
+
#observeReplay = null;
|
|
24565
|
+
#pendingEvents = [];
|
|
24566
|
+
#closed = false;
|
|
24567
|
+
#closing = null;
|
|
24568
|
+
#stderrRaw = "";
|
|
24569
|
+
get #stderr() {
|
|
24570
|
+
return sanitizeDiagnosticTail(this.#stderrRaw);
|
|
24571
|
+
}
|
|
24572
|
+
#faultSignal = new AbortController();
|
|
24573
|
+
constructor(options) {
|
|
24574
|
+
this.options = options;
|
|
24575
|
+
this.skipPermissions = options.skipPermissions === true;
|
|
24576
|
+
}
|
|
24577
|
+
get sessionId() {
|
|
24578
|
+
return this.#sessionId;
|
|
24579
|
+
}
|
|
24580
|
+
get isClosed() {
|
|
24581
|
+
return this.#closed;
|
|
24582
|
+
}
|
|
24583
|
+
setSessionEventHandler(handler) {
|
|
24584
|
+
this.#sessionHandler = handler;
|
|
24585
|
+
if (handler)
|
|
24586
|
+
for (const event of this.#pendingEvents.splice(0))
|
|
24587
|
+
handler(event);
|
|
24588
|
+
}
|
|
24589
|
+
initialize() {
|
|
24590
|
+
if (this.#closed)
|
|
24591
|
+
return Promise.reject(new AntigravityTransportError("unavailable", "Antigravity ACP is closed"));
|
|
24592
|
+
return this.#initializing ??= this.#start();
|
|
24593
|
+
}
|
|
24594
|
+
async #start() {
|
|
24595
|
+
try {
|
|
24596
|
+
const executable = resolveAntigravityExecutable(this.options);
|
|
24597
|
+
if (!executable)
|
|
24598
|
+
throw new AntigravityTransportError("notInstalled", "Antigravity CLI was not found");
|
|
24599
|
+
const invocation = commandInvocation(executable, this.skipPermissions ? ["acp", "--dangerously-skip-permissions"] : ["acp"], this.options.environment ?? process.env);
|
|
24600
|
+
const child = spawn(invocation.command, invocation.arguments, {
|
|
24601
|
+
cwd: this.options.cwd,
|
|
24602
|
+
env: this.options.environment ?? process.env,
|
|
24603
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
24604
|
+
windowsHide: true,
|
|
24605
|
+
windowsVerbatimArguments: invocation.windowsVerbatimArguments
|
|
24606
|
+
});
|
|
24607
|
+
this.#child = child;
|
|
24608
|
+
child.stderr.on("data", (chunk) => {
|
|
24609
|
+
this.#stderrRaw = (this.#stderrRaw + chunk.toString()).slice(-32e3);
|
|
24610
|
+
});
|
|
24611
|
+
child.on("error", (error51) => this.#fault(new AntigravityTransportError(error51.code === "ENOENT" ? "notInstalled" : "unavailable", error51.message, { diagnostic: this.#stderr })));
|
|
24612
|
+
child.on("exit", (code, signal) => this.#fault(new AntigravityTransportError("processExited", `Antigravity ACP exited (code ${code}, signal ${signal})`, { diagnostic: this.#stderr })));
|
|
24613
|
+
child.stdin.on("error", (error51) => this.#fault(this.#error(error51)));
|
|
24614
|
+
const stream = ndJsonStream2(Writable.toWeb(child.stdin), Readable.toWeb(child.stdout));
|
|
24615
|
+
const nativeMethods = /* @__PURE__ */ new Set(["session/request_permission", "elicitation/create"]);
|
|
24616
|
+
stream.readable = stream.readable.pipeThrough(new TransformStream({
|
|
24617
|
+
transform: (message2, controller) => {
|
|
24618
|
+
if ("method" in message2 && message2.method === "session/update") {
|
|
24619
|
+
const params = message2.params;
|
|
24620
|
+
this.#update(params.sessionId, params.update);
|
|
24621
|
+
return;
|
|
24622
|
+
}
|
|
24623
|
+
if ("method" in message2 && nativeMethods.has(message2.method))
|
|
24624
|
+
message2.method = `_antigravity/${message2.method}`;
|
|
24625
|
+
controller.enqueue(message2);
|
|
24626
|
+
}
|
|
24627
|
+
}));
|
|
24628
|
+
const onElicitation = (request) => this.#callback("sessionId" in request ? request.sessionId : void 0, (handler) => handler.onElicitation(request), { action: "cancel" });
|
|
24629
|
+
const client2 = {
|
|
24630
|
+
sessionUpdate: ({ sessionId, update }) => this.#update(sessionId, update),
|
|
24631
|
+
requestPermission: (request) => this.#callback(request.sessionId, (handler) => handler.onPermission(request), {
|
|
24632
|
+
outcome: { outcome: "cancelled" }
|
|
24633
|
+
}),
|
|
24634
|
+
unstable_createElicitation: onElicitation,
|
|
24635
|
+
extMethod: async (method, params) => {
|
|
24636
|
+
if (method === "_antigravity/session/request_permission")
|
|
24637
|
+
return await client2.requestPermission(params);
|
|
24638
|
+
if (method === "_antigravity/elicitation/create")
|
|
24639
|
+
return await onElicitation(params);
|
|
24640
|
+
throw new AntigravityTransportError("unsupported", `Unsupported ACP client method: ${method}`);
|
|
24641
|
+
}
|
|
24642
|
+
};
|
|
24643
|
+
const connection = new ClientSideConnection(() => client2, stream);
|
|
24644
|
+
this.#connection = connection;
|
|
24645
|
+
connection.signal.addEventListener("abort", () => this.#fault(new AntigravityTransportError("processExited", "Antigravity ACP connection closed", {
|
|
24646
|
+
diagnostic: this.#stderr
|
|
24647
|
+
})), { once: true });
|
|
24648
|
+
const response = await this.#request(connection.initialize({
|
|
24649
|
+
protocolVersion: 1,
|
|
24650
|
+
clientCapabilities: { elicitation: { form: {} } }
|
|
24651
|
+
}), "initialize");
|
|
24652
|
+
if (response.protocolVersion !== 1)
|
|
24653
|
+
throw new AntigravityTransportError("protocolError", `Unsupported ACP version ${response.protocolVersion}`);
|
|
24654
|
+
return response;
|
|
24655
|
+
} catch (error51) {
|
|
24656
|
+
await this.close();
|
|
24657
|
+
throw this.#error(error51);
|
|
24658
|
+
}
|
|
24659
|
+
}
|
|
24660
|
+
async openSession(input) {
|
|
24661
|
+
await this.initialize();
|
|
24662
|
+
if (this.#closed || !this.#connection || this.#active || this.#opening || this.#sessionId)
|
|
24663
|
+
throw new AntigravityTransportError("unavailable", "Close the current ACP session before opening another");
|
|
24664
|
+
const connection = this.#connection;
|
|
24665
|
+
const buffered = [];
|
|
24666
|
+
this.#opening = buffered;
|
|
24667
|
+
this.#pendingEvents = [];
|
|
24668
|
+
const params = {
|
|
24669
|
+
cwd: input.cwd,
|
|
24670
|
+
mcpServers: [],
|
|
24671
|
+
...input.additionalDirectories?.length ? { additionalDirectories: input.additionalDirectories } : {},
|
|
24672
|
+
...input.systemPromptAppend ? { _meta: { antigravity: { systemPrompt: { append: input.systemPromptAppend } } } } : {}
|
|
24673
|
+
};
|
|
24674
|
+
try {
|
|
24675
|
+
const replay = input.kind === "load" && input.sessionId ? nativeReplayCompletion(await readNativeReplaySize(input.sessionId, antigravityHome(this.options.environment ?? process.env))) : void 0;
|
|
24676
|
+
this.#observeReplay = replay ? (sessionId2, event) => {
|
|
24677
|
+
if (sessionId2 === input.sessionId)
|
|
24678
|
+
replay.observe(event);
|
|
24679
|
+
} : null;
|
|
24680
|
+
let request;
|
|
24681
|
+
if (input.kind === "create")
|
|
24682
|
+
request = connection.newSession(params);
|
|
24683
|
+
else {
|
|
24684
|
+
if (!input.sessionId)
|
|
24685
|
+
throw new AntigravityTransportError("protocolError", "Session ID required for resume/load");
|
|
24686
|
+
const target2 = { ...params, sessionId: input.sessionId };
|
|
24687
|
+
request = input.kind === "resume" ? connection.resumeSession(target2) : connection.loadSession(target2);
|
|
24688
|
+
}
|
|
24689
|
+
const result = await this.#request(request, `session/${input.kind === "create" ? "new" : input.kind}`);
|
|
24690
|
+
const raw = result;
|
|
24691
|
+
const sessionId = raw.sessionId ?? input.sessionId;
|
|
24692
|
+
if (!sessionId)
|
|
24693
|
+
throw new AntigravityTransportError("protocolError", "Antigravity session/new returned no sessionId");
|
|
24694
|
+
this.#sessionId = sessionId;
|
|
24695
|
+
if (replay)
|
|
24696
|
+
await this.#request(replay.complete, "session/load replay");
|
|
24697
|
+
const events = buffered.filter((entry) => entry.sessionId === sessionId).map(({ event }) => event);
|
|
24698
|
+
if (input.kind !== "load")
|
|
24699
|
+
for (const event of events)
|
|
24700
|
+
this.#dispatch(event);
|
|
24701
|
+
return {
|
|
24702
|
+
opened: {
|
|
24703
|
+
sessionId,
|
|
24704
|
+
...raw.models ? { models: raw.models } : {},
|
|
24705
|
+
...raw.modes ? { modes: raw.modes } : {},
|
|
24706
|
+
...raw.configOptions ? { configOptions: raw.configOptions } : {},
|
|
24707
|
+
...raw._meta?.antigravity?.tier ? { tier: raw._meta.antigravity.tier } : {}
|
|
24708
|
+
},
|
|
24709
|
+
replayedEvents: input.kind === "load" ? events : []
|
|
24710
|
+
};
|
|
24586
24711
|
} finally {
|
|
24587
|
-
|
|
24712
|
+
this.#opening = null;
|
|
24713
|
+
this.#observeReplay = null;
|
|
24588
24714
|
}
|
|
24589
|
-
await registerDerivedSummary(sourceId, derivedId, home);
|
|
24590
|
-
return true;
|
|
24591
|
-
} catch (error51) {
|
|
24592
|
-
if (owned)
|
|
24593
|
-
await removeDerivedDb(derivedId, home);
|
|
24594
|
-
throw error51;
|
|
24595
|
-
} finally {
|
|
24596
|
-
source.close();
|
|
24597
24715
|
}
|
|
24598
|
-
|
|
24599
|
-
|
|
24600
|
-
|
|
24601
|
-
try {
|
|
24602
|
-
await access2(summaryPath);
|
|
24603
|
-
} catch (error51) {
|
|
24604
|
-
if (error51.code === "ENOENT")
|
|
24605
|
-
return;
|
|
24606
|
-
throw error51;
|
|
24716
|
+
async setMode(modeId) {
|
|
24717
|
+
const { connection, sessionId } = this.#session();
|
|
24718
|
+
await this.#request(connection.setSessionMode({ sessionId, modeId }), "session/set_mode");
|
|
24607
24719
|
}
|
|
24608
|
-
|
|
24609
|
-
|
|
24610
|
-
|
|
24611
|
-
|
|
24612
|
-
|
|
24613
|
-
|
|
24614
|
-
const
|
|
24615
|
-
|
|
24720
|
+
async setConfigOption(configId, value) {
|
|
24721
|
+
const { connection, sessionId } = this.#session();
|
|
24722
|
+
const response = await this.#request(connection.setSessionConfigOption({ sessionId, configId, value }), "session/set_config_option");
|
|
24723
|
+
return response.configOptions;
|
|
24724
|
+
}
|
|
24725
|
+
async prompt(parts, handler) {
|
|
24726
|
+
const { connection, sessionId } = this.#session();
|
|
24727
|
+
if (this.#active)
|
|
24728
|
+
throw new AntigravityTransportError("unavailable", "An ACP prompt is already active");
|
|
24729
|
+
this.#active = handler;
|
|
24730
|
+
this.#acceptCallbacks = true;
|
|
24731
|
+
const interrupted = new AbortController();
|
|
24732
|
+
this.#promptInterrupted = interrupted;
|
|
24616
24733
|
try {
|
|
24617
|
-
|
|
24618
|
-
const trajectoryId = derived.prepare("SELECT trajectory_id FROM trajectory_meta LIMIT 1").get()?.trajectory_id;
|
|
24619
|
-
row = {
|
|
24620
|
-
...template,
|
|
24621
|
-
conversation_id: derivedId,
|
|
24622
|
-
status: "CASCADE_RUN_STATUS_IDLE",
|
|
24623
|
-
step_count: Number(derived.prepare("SELECT count(*) AS n FROM steps").get()?.n),
|
|
24624
|
-
last_user_input_step_index: Number(derived.prepare("SELECT max(idx) AS idx FROM steps WHERE step_type = 14").get()?.idx ?? -1),
|
|
24625
|
-
not_fully_idle: 0,
|
|
24626
|
-
killed: 0,
|
|
24627
|
-
last_modified_time: (/* @__PURE__ */ new Date()).toISOString(),
|
|
24628
|
-
raw_summary: minimalRawSummaryBlob(String(trajectoryId), Buffer.from(metadata))
|
|
24629
|
-
};
|
|
24734
|
+
return await this.#request(connection.prompt({ sessionId, prompt: [...parts] }), "session/prompt", null, interrupted.signal);
|
|
24630
24735
|
} finally {
|
|
24631
|
-
|
|
24736
|
+
this.#clearCallbacks();
|
|
24737
|
+
this.#acceptCallbacks = false;
|
|
24738
|
+
this.#active = null;
|
|
24739
|
+
this.#promptInterrupted = null;
|
|
24632
24740
|
}
|
|
24633
|
-
const columns = Object.keys(template);
|
|
24634
|
-
summaries.prepare(`INSERT INTO conversation_summaries (${columns.map((name) => `"${name.replaceAll('"', '""')}"`).join(",")}) VALUES (${columns.map(() => "?").join(",")})`).run(...columns.map((name) => row[name] ?? null));
|
|
24635
|
-
} finally {
|
|
24636
|
-
summaries.close();
|
|
24637
24741
|
}
|
|
24638
|
-
|
|
24639
|
-
|
|
24640
|
-
|
|
24641
|
-
|
|
24642
|
-
|
|
24643
|
-
if (error51.code === "ENOENT")
|
|
24644
|
-
return;
|
|
24645
|
-
throw error51;
|
|
24742
|
+
async cancel() {
|
|
24743
|
+
const { connection, sessionId } = this.#session();
|
|
24744
|
+
this.#acceptCallbacks = false;
|
|
24745
|
+
this.#clearCallbacks();
|
|
24746
|
+
await this.#request(connection.cancel({ sessionId }), "session/cancel");
|
|
24646
24747
|
}
|
|
24647
|
-
|
|
24648
|
-
|
|
24649
|
-
|
|
24650
|
-
|
|
24651
|
-
|
|
24652
|
-
|
|
24748
|
+
async closeSession() {
|
|
24749
|
+
const sessionId = this.#sessionId;
|
|
24750
|
+
this.#sessionId = null;
|
|
24751
|
+
this.#acceptCallbacks = false;
|
|
24752
|
+
this.#promptInterrupted?.abort(new AntigravityTransportError("unavailable", "ACP session closed"));
|
|
24753
|
+
this.#active = null;
|
|
24754
|
+
this.#pendingEvents = [];
|
|
24755
|
+
this.#clearCallbacks();
|
|
24756
|
+
if (sessionId && this.#connection)
|
|
24757
|
+
await this.#request(this.#connection.closeSession({ sessionId }), "session/close", this.options.closeTimeoutMs ?? 2e3);
|
|
24653
24758
|
}
|
|
24654
|
-
|
|
24655
|
-
|
|
24656
|
-
|
|
24657
|
-
|
|
24658
|
-
|
|
24659
|
-
async function copyNativeBrainDirIfExists(sourceId, derivedId, home = os3.homedir()) {
|
|
24660
|
-
try {
|
|
24661
|
-
await access2(nativeBrainDirPath(sourceId, home));
|
|
24662
|
-
} catch (error51) {
|
|
24663
|
-
if (error51.code === "ENOENT")
|
|
24664
|
-
return false;
|
|
24665
|
-
throw error51;
|
|
24759
|
+
close() {
|
|
24760
|
+
if (this.#closing)
|
|
24761
|
+
return this.#closing;
|
|
24762
|
+
this.#closed = true;
|
|
24763
|
+
return this.#closing = this.#shutdown();
|
|
24666
24764
|
}
|
|
24667
|
-
|
|
24668
|
-
|
|
24669
|
-
|
|
24670
|
-
|
|
24671
|
-
|
|
24672
|
-
|
|
24673
|
-
|
|
24674
|
-
|
|
24675
|
-
|
|
24676
|
-
|
|
24677
|
-
|
|
24678
|
-
|
|
24679
|
-
|
|
24680
|
-
|
|
24681
|
-
|
|
24682
|
-
|
|
24683
|
-
|
|
24684
|
-
|
|
24685
|
-
|
|
24686
|
-
|
|
24687
|
-
|
|
24688
|
-
|
|
24689
|
-
if (result.ok)
|
|
24690
|
-
return result;
|
|
24691
|
-
const cleanupFailure = await cleanup().then(() => void 0, () => "Derived native history cleanup failed");
|
|
24692
|
-
return cleanupFailure ? { ok: false, error: { ...result.error, diagnostic: cleanupFailure } } : result;
|
|
24693
|
-
} catch (error51) {
|
|
24694
|
-
const cleanupFailure = await cleanup().then(() => void 0, () => "Derived native history cleanup failed");
|
|
24695
|
-
return {
|
|
24696
|
-
ok: false,
|
|
24697
|
-
error: {
|
|
24698
|
-
...nativeHistoryError(error51),
|
|
24699
|
-
...cleanupFailure ? { diagnostic: cleanupFailure } : {}
|
|
24765
|
+
async #shutdown() {
|
|
24766
|
+
try {
|
|
24767
|
+
await this.closeSession();
|
|
24768
|
+
} catch (error51) {
|
|
24769
|
+
this.#stderrRaw = `${this.#stderrRaw}
|
|
24770
|
+
${this.#error(error51).message}`.slice(-32e3);
|
|
24771
|
+
}
|
|
24772
|
+
this.#faultSignal.abort(new AntigravityTransportError("unavailable", "Antigravity ACP closed"));
|
|
24773
|
+
this.#opening = null;
|
|
24774
|
+
this.#sessionHandler = null;
|
|
24775
|
+
const child = this.#child;
|
|
24776
|
+
if (child && child.exitCode === null && child.signalCode === null && child.pid) {
|
|
24777
|
+
const exited = new Promise((resolve) => child.once("exit", () => resolve()));
|
|
24778
|
+
const timeout = this.options.closeTimeoutMs ?? 2e3;
|
|
24779
|
+
const term = setTimeout(() => child.kill("SIGTERM"), Math.max(1, timeout / 2));
|
|
24780
|
+
const kill = setTimeout(() => child.kill("SIGKILL"), Math.max(2, timeout));
|
|
24781
|
+
child.stdin.end();
|
|
24782
|
+
try {
|
|
24783
|
+
await exited;
|
|
24784
|
+
} finally {
|
|
24785
|
+
clearTimeout(term);
|
|
24786
|
+
clearTimeout(kill);
|
|
24700
24787
|
}
|
|
24701
|
-
}
|
|
24788
|
+
}
|
|
24789
|
+
this.#connection = null;
|
|
24790
|
+
this.#child = null;
|
|
24702
24791
|
}
|
|
24703
|
-
|
|
24704
|
-
if (!
|
|
24792
|
+
#session() {
|
|
24793
|
+
if (this.#closed || !this.#connection || !this.#sessionId)
|
|
24794
|
+
throw new AntigravityTransportError("unavailable", "Antigravity ACP session is unavailable");
|
|
24795
|
+
return { connection: this.#connection, sessionId: this.#sessionId };
|
|
24796
|
+
}
|
|
24797
|
+
#update(sessionId, raw) {
|
|
24798
|
+
if (this.#closed)
|
|
24705
24799
|
return;
|
|
24706
|
-
|
|
24707
|
-
|
|
24708
|
-
|
|
24709
|
-
|
|
24710
|
-
|
|
24800
|
+
const event = projectAcpSessionUpdate(raw);
|
|
24801
|
+
if (!event)
|
|
24802
|
+
return;
|
|
24803
|
+
if (this.#opening) {
|
|
24804
|
+
this.#opening.push({ sessionId, event });
|
|
24805
|
+
this.#observeReplay?.(sessionId, event);
|
|
24806
|
+
return;
|
|
24807
|
+
}
|
|
24808
|
+
if (sessionId === this.#sessionId)
|
|
24809
|
+
this.#dispatch(event);
|
|
24711
24810
|
}
|
|
24712
|
-
|
|
24713
|
-
|
|
24714
|
-
|
|
24715
|
-
|
|
24716
|
-
|
|
24717
|
-
|
|
24718
|
-
|
|
24719
|
-
|
|
24720
|
-
message: "Invalid Antigravity source Native Session",
|
|
24721
|
-
retryable: false
|
|
24722
|
-
}
|
|
24723
|
-
};
|
|
24724
|
-
const checkpoint = nativeCheckpointRefSchema.safeParse(input.checkpoint);
|
|
24725
|
-
if (!checkpoint.success || checkpoint.data.harnessId !== harnessId2 || checkpoint.data.nativeSessionId !== input.sourceRef.nativeSessionId)
|
|
24726
|
-
return checkpointError();
|
|
24727
|
-
if (options.sourceSession?.isActive)
|
|
24728
|
-
return {
|
|
24729
|
-
ok: false,
|
|
24730
|
-
error: {
|
|
24731
|
-
code: "sessionBusy",
|
|
24732
|
-
message: "Source Session is busy",
|
|
24733
|
-
retryable: true
|
|
24734
|
-
}
|
|
24735
|
-
};
|
|
24736
|
-
const match = /^turn-(0|[1-9]\d*)$/u.exec(checkpoint.data.checkpointId);
|
|
24737
|
-
if (!match)
|
|
24738
|
-
return checkpointError();
|
|
24739
|
-
try {
|
|
24740
|
-
const count5 = await readNativeTurnCount(nativeConversationDbPath(input.sourceRef.nativeSessionId, antigravityHome({ ...options.adapterEnvironment, ...input.environment })));
|
|
24741
|
-
const index = Number(match[1]);
|
|
24742
|
-
if (!Number.isSafeInteger(index) || index >= count5)
|
|
24743
|
-
return checkpointError();
|
|
24744
|
-
return openDerivedAntigravitySession(options, {
|
|
24745
|
-
kind: "resume",
|
|
24746
|
-
nativeRef: input.sourceRef,
|
|
24747
|
-
cwd: input.cwd,
|
|
24748
|
-
...input.environment ? { environment: input.environment } : {}
|
|
24749
|
-
}, input.sourceRef, index + 1);
|
|
24750
|
-
} catch (error51) {
|
|
24751
|
-
return { ok: false, error: nativeHistoryError(error51) };
|
|
24811
|
+
#dispatch(event) {
|
|
24812
|
+
if (["config.update", "mode.update", "commands.update", "session.info", "usage.context"].includes(event.type)) {
|
|
24813
|
+
if (this.#sessionHandler)
|
|
24814
|
+
this.#sessionHandler(event);
|
|
24815
|
+
else
|
|
24816
|
+
this.#pendingEvents.push(event);
|
|
24817
|
+
} else
|
|
24818
|
+
this.#active?.onEvent(event);
|
|
24752
24819
|
}
|
|
24753
|
-
|
|
24754
|
-
|
|
24755
|
-
|
|
24756
|
-
|
|
24757
|
-
|
|
24758
|
-
|
|
24759
|
-
|
|
24760
|
-
|
|
24820
|
+
async #callback(sessionId, invoke, cancelled) {
|
|
24821
|
+
const active = this.#active;
|
|
24822
|
+
if (!active || !this.#acceptCallbacks || sessionId !== this.#sessionId || this.#closed)
|
|
24823
|
+
return cancelled;
|
|
24824
|
+
let cancel;
|
|
24825
|
+
const cancellation = new Promise((resolve) => {
|
|
24826
|
+
cancel = () => resolve(cancelled);
|
|
24827
|
+
});
|
|
24828
|
+
this.#callbacks.add(cancel);
|
|
24829
|
+
try {
|
|
24830
|
+
return await Promise.race([invoke(active), cancellation]);
|
|
24831
|
+
} finally {
|
|
24832
|
+
this.#callbacks.delete(cancel);
|
|
24761
24833
|
}
|
|
24762
|
-
}
|
|
24834
|
+
}
|
|
24835
|
+
#clearCallbacks() {
|
|
24836
|
+
for (const cancel of this.#callbacks)
|
|
24837
|
+
cancel();
|
|
24838
|
+
this.#callbacks.clear();
|
|
24839
|
+
}
|
|
24840
|
+
async #request(promise2, operation, timeoutMs = this.options.commandTimeoutMs ?? 3e4, signal) {
|
|
24841
|
+
let timer;
|
|
24842
|
+
let abort;
|
|
24843
|
+
const signals = [this.#faultSignal.signal, ...signal ? [signal] : []];
|
|
24844
|
+
const interrupted = new Promise((_, reject) => {
|
|
24845
|
+
abort = () => reject(signal?.aborted ? signal.reason : this.#faultSignal.signal.reason);
|
|
24846
|
+
if (signals.some((candidate) => candidate.aborted))
|
|
24847
|
+
abort();
|
|
24848
|
+
else
|
|
24849
|
+
for (const candidate of signals)
|
|
24850
|
+
candidate.addEventListener("abort", abort, { once: true });
|
|
24851
|
+
if (timeoutMs !== null)
|
|
24852
|
+
timer = setTimeout(() => reject(new AntigravityTransportError("unavailable", `${operation} timed out after ${timeoutMs}ms`, { diagnostic: this.#stderr })), timeoutMs);
|
|
24853
|
+
});
|
|
24854
|
+
try {
|
|
24855
|
+
return await Promise.race([promise2, interrupted]);
|
|
24856
|
+
} catch (error51) {
|
|
24857
|
+
const normalized = this.#error(error51);
|
|
24858
|
+
if (normalized.kind === "unavailable" && normalized.message.includes("timed out"))
|
|
24859
|
+
void this.close();
|
|
24860
|
+
throw normalized;
|
|
24861
|
+
} finally {
|
|
24862
|
+
clearTimeout(timer);
|
|
24863
|
+
for (const candidate of signals)
|
|
24864
|
+
candidate.removeEventListener("abort", abort);
|
|
24865
|
+
}
|
|
24866
|
+
}
|
|
24867
|
+
#error(error51) {
|
|
24868
|
+
if (error51 instanceof AntigravityTransportError)
|
|
24869
|
+
return error51;
|
|
24870
|
+
const message2 = sanitizeDiagnosticTail(error51 instanceof Error ? error51.message : String(error51));
|
|
24871
|
+
const code = error51?.code;
|
|
24872
|
+
return new AntigravityTransportError(code === -32e3 || /auth|login|sign[ -]?in|unauthenticated/iu.test(message2) ? "authenticationRequired" : "unavailable", message2, { cause: error51, diagnostic: this.#stderr });
|
|
24873
|
+
}
|
|
24874
|
+
#fault(error51) {
|
|
24875
|
+
if (this.#closed || this.#faultSignal.signal.aborted)
|
|
24876
|
+
return;
|
|
24877
|
+
this.#faultSignal.abort(error51);
|
|
24878
|
+
this.#clearCallbacks();
|
|
24879
|
+
void this.close();
|
|
24880
|
+
this.options.onFault?.(error51);
|
|
24881
|
+
}
|
|
24882
|
+
};
|
|
24883
|
+
|
|
24884
|
+
// dist/delegation.js
|
|
24885
|
+
var DELEGATION_ENVIRONMENT_KEYS = [
|
|
24886
|
+
"CODEXHOST_CLI_PATH",
|
|
24887
|
+
"CODEXHOST_RUNTIME_ENDPOINT",
|
|
24888
|
+
"CODEXHOST_RUNTIME_TOKEN",
|
|
24889
|
+
"CODEXHOST_THREAD_ID"
|
|
24890
|
+
];
|
|
24891
|
+
var ANTIGRAVITY_DELEGATION_INSTRUCTIONS = `This Antigravity Session runs inside codexhost.
|
|
24892
|
+
When the user requests cross-Harness delegation, use the executable specified by the CODEXHOST_CLI_PATH environment variable through your native shell tool. Start with --help and harness list, then use delegate start and thread send/read/wait/cancel as documented. Use --format compact for results. Keep the inherited CODEXHOST_RUNTIME_ENDPOINT, CODEXHOST_RUNTIME_TOKEN and CODEXHOST_THREAD_ID environment variables for every call; they identify this Runtime and parent Thread. Never print their values, substitute another executable, or delegate without user authorization. Native Antigravity subagents are separate from cross-Harness delegation.`;
|
|
24893
|
+
function antigravityDelegationInstructions(environment) {
|
|
24894
|
+
return DELEGATION_ENVIRONMENT_KEYS.every((key) => environment[key]) ? ANTIGRAVITY_DELEGATION_INSTRUCTIONS : void 0;
|
|
24763
24895
|
}
|
|
24764
24896
|
|
|
24765
24897
|
// dist/model-catalog.js
|
|
@@ -25501,6 +25633,144 @@ var AntigravitySessionImport = class {
|
|
|
25501
25633
|
}
|
|
25502
25634
|
};
|
|
25503
25635
|
|
|
25636
|
+
// dist/snapshot-reader-pool.js
|
|
25637
|
+
var THREAD_SCOPED_ENV_KEYS = /* @__PURE__ */ new Set(["CODEXHOST_THREAD_ID"]);
|
|
25638
|
+
function sanitizeReaderEnvironment(environment) {
|
|
25639
|
+
const sanitized = {};
|
|
25640
|
+
for (const [key, value] of Object.entries(environment)) {
|
|
25641
|
+
if (value !== void 0 && !THREAD_SCOPED_ENV_KEYS.has(key)) {
|
|
25642
|
+
sanitized[key] = value;
|
|
25643
|
+
}
|
|
25644
|
+
}
|
|
25645
|
+
return sanitized;
|
|
25646
|
+
}
|
|
25647
|
+
function readerScopeKey(command, skipPermissions, environment) {
|
|
25648
|
+
const entries = Object.entries(environment).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0);
|
|
25649
|
+
return JSON.stringify([command ?? "", skipPermissions, entries]);
|
|
25650
|
+
}
|
|
25651
|
+
var AntigravitySnapshotReaderPool = class {
|
|
25652
|
+
adapterOptions;
|
|
25653
|
+
#lanes = /* @__PURE__ */ new Map();
|
|
25654
|
+
#retiring = /* @__PURE__ */ new Set();
|
|
25655
|
+
#retired = /* @__PURE__ */ new WeakSet();
|
|
25656
|
+
#closed = false;
|
|
25657
|
+
#closing;
|
|
25658
|
+
constructor(adapterOptions) {
|
|
25659
|
+
this.adapterOptions = adapterOptions;
|
|
25660
|
+
}
|
|
25661
|
+
loadSession(input) {
|
|
25662
|
+
if (this.#closed || input.signal?.aborted) {
|
|
25663
|
+
return Promise.reject(new AntigravityTransportError("unavailable", "Snapshot reader is closed"));
|
|
25664
|
+
}
|
|
25665
|
+
const environment = sanitizeReaderEnvironment(input.environment);
|
|
25666
|
+
const key = readerScopeKey(this.adapterOptions.command, input.skipPermissions, environment);
|
|
25667
|
+
let lane = this.#lanes.get(key);
|
|
25668
|
+
if (!lane) {
|
|
25669
|
+
lane = { transport: void 0, initialized: false, tail: Promise.resolve() };
|
|
25670
|
+
this.#lanes.set(key, lane);
|
|
25671
|
+
}
|
|
25672
|
+
const currentLane = lane;
|
|
25673
|
+
const run = currentLane.tail.then(() => this.#loadInLane(currentLane, input, environment));
|
|
25674
|
+
currentLane.tail = run.then(() => void 0, () => void 0);
|
|
25675
|
+
return run;
|
|
25676
|
+
}
|
|
25677
|
+
close() {
|
|
25678
|
+
return this.#closing ??= this.#close().catch((error51) => {
|
|
25679
|
+
this.#closing = void 0;
|
|
25680
|
+
throw error51;
|
|
25681
|
+
});
|
|
25682
|
+
}
|
|
25683
|
+
async #close() {
|
|
25684
|
+
this.#closed = true;
|
|
25685
|
+
for (const lane of this.#lanes.values()) {
|
|
25686
|
+
if (lane.transport)
|
|
25687
|
+
this.#retire(lane, lane.transport);
|
|
25688
|
+
}
|
|
25689
|
+
this.#lanes.clear();
|
|
25690
|
+
await Promise.all(this.#retiring);
|
|
25691
|
+
}
|
|
25692
|
+
async #loadInLane(lane, input, environment) {
|
|
25693
|
+
if (this.#closed || input.signal?.aborted) {
|
|
25694
|
+
throw new AntigravityTransportError("unavailable", "Snapshot reader is closed");
|
|
25695
|
+
}
|
|
25696
|
+
let transport = lane.transport;
|
|
25697
|
+
if (!transport || transport.isClosed) {
|
|
25698
|
+
transport = this.#createTransport(lane, input.cwd, environment, input.skipPermissions);
|
|
25699
|
+
lane.transport = transport;
|
|
25700
|
+
lane.initialized = false;
|
|
25701
|
+
}
|
|
25702
|
+
if (!lane.initialized) {
|
|
25703
|
+
try {
|
|
25704
|
+
await transport.initialize();
|
|
25705
|
+
lane.initialized = true;
|
|
25706
|
+
} catch (error51) {
|
|
25707
|
+
this.#retire(lane, transport);
|
|
25708
|
+
throw error51;
|
|
25709
|
+
}
|
|
25710
|
+
}
|
|
25711
|
+
if (this.#closed || transport.isClosed) {
|
|
25712
|
+
this.#retire(lane, transport);
|
|
25713
|
+
throw new AntigravityTransportError("unavailable", "Snapshot reader is closed");
|
|
25714
|
+
}
|
|
25715
|
+
if (input.signal?.aborted) {
|
|
25716
|
+
throw new AntigravityTransportError("unavailable", "Snapshot read aborted");
|
|
25717
|
+
}
|
|
25718
|
+
try {
|
|
25719
|
+
const { opened, replayedEvents } = await transport.openSession({
|
|
25720
|
+
kind: "load",
|
|
25721
|
+
sessionId: input.sessionId,
|
|
25722
|
+
cwd: input.cwd
|
|
25723
|
+
});
|
|
25724
|
+
if (opened.sessionId !== input.sessionId) {
|
|
25725
|
+
throw new AntigravityTransportError("protocolError", "Snapshot loaded a different Session");
|
|
25726
|
+
}
|
|
25727
|
+
await transport.closeSession();
|
|
25728
|
+
if (this.#closed || transport.isClosed) {
|
|
25729
|
+
this.#retire(lane, transport);
|
|
25730
|
+
}
|
|
25731
|
+
return { opened, replayedEvents };
|
|
25732
|
+
} catch (error51) {
|
|
25733
|
+
this.#retire(lane, transport);
|
|
25734
|
+
throw error51;
|
|
25735
|
+
}
|
|
25736
|
+
}
|
|
25737
|
+
#createTransport(lane, cwd, environment, skipPermissions) {
|
|
25738
|
+
const options = {
|
|
25739
|
+
cwd,
|
|
25740
|
+
...this.adapterOptions.command ? { command: this.adapterOptions.command } : {},
|
|
25741
|
+
environment,
|
|
25742
|
+
skipPermissions,
|
|
25743
|
+
...this.adapterOptions.commandTimeoutMs !== void 0 ? { commandTimeoutMs: this.adapterOptions.commandTimeoutMs } : {},
|
|
25744
|
+
...this.adapterOptions.closeTimeoutMs !== void 0 ? { closeTimeoutMs: this.adapterOptions.closeTimeoutMs } : {},
|
|
25745
|
+
onFault: () => {
|
|
25746
|
+
this.#retire(lane, transport);
|
|
25747
|
+
}
|
|
25748
|
+
};
|
|
25749
|
+
const transport = this.adapterOptions.createTransport?.(options) ?? new AntigravityAcpTransport(options);
|
|
25750
|
+
return transport;
|
|
25751
|
+
}
|
|
25752
|
+
#retire(lane, transport) {
|
|
25753
|
+
if (lane.transport === transport) {
|
|
25754
|
+
lane.transport = void 0;
|
|
25755
|
+
lane.initialized = false;
|
|
25756
|
+
}
|
|
25757
|
+
if (this.#retired.has(transport))
|
|
25758
|
+
return;
|
|
25759
|
+
this.#retired.add(transport);
|
|
25760
|
+
let raw;
|
|
25761
|
+
try {
|
|
25762
|
+
raw = transport.close();
|
|
25763
|
+
} catch (error51) {
|
|
25764
|
+
raw = Promise.reject(error51);
|
|
25765
|
+
}
|
|
25766
|
+
const tracked = raw.then(() => {
|
|
25767
|
+
this.#retiring.delete(tracked);
|
|
25768
|
+
});
|
|
25769
|
+
this.#retiring.add(tracked);
|
|
25770
|
+
void tracked.catch(() => void 0);
|
|
25771
|
+
}
|
|
25772
|
+
};
|
|
25773
|
+
|
|
25504
25774
|
// dist/subagent-transcript.js
|
|
25505
25775
|
import { open as open2, realpath } from "node:fs/promises";
|
|
25506
25776
|
import path11 from "node:path";
|
|
@@ -25965,7 +26235,6 @@ var AntigravitySession = class {
|
|
|
25965
26235
|
#state = {};
|
|
25966
26236
|
#requested;
|
|
25967
26237
|
#transport;
|
|
25968
|
-
#readers = /* @__PURE__ */ new Set();
|
|
25969
26238
|
#opening;
|
|
25970
26239
|
#availableModels = [];
|
|
25971
26240
|
#configOptions = [];
|
|
@@ -25984,6 +26253,8 @@ var AntigravitySession = class {
|
|
|
25984
26253
|
#historyOperation = false;
|
|
25985
26254
|
constructor(options) {
|
|
25986
26255
|
this.#options = options;
|
|
26256
|
+
if (options.nativeRef)
|
|
26257
|
+
this.#state = { nativeRef: options.nativeRef };
|
|
25987
26258
|
this.#requested = {
|
|
25988
26259
|
model: options.model,
|
|
25989
26260
|
thinkingOptionId: options.thinkingOptionId,
|
|
@@ -26086,23 +26357,14 @@ var AntigravitySession = class {
|
|
|
26086
26357
|
try {
|
|
26087
26358
|
this.#turnCount = await readNativeTurnCount(nativeConversationDbPath(opened.sessionId, antigravityHome(this.#options.environment)));
|
|
26088
26359
|
} catch {
|
|
26089
|
-
this.#turnCount = projectReplayedEventsToTurns({
|
|
26360
|
+
this.#turnCount = Math.max(this.#turnCount, projectReplayedEventsToTurns({
|
|
26090
26361
|
nativeSessionId: opened.sessionId,
|
|
26091
26362
|
cwd: this.#options.cwd,
|
|
26092
26363
|
events: replayedEvents,
|
|
26093
26364
|
...this.#options.knownTurnRefs ? { knownTurnRefs: this.#options.knownTurnRefs } : {}
|
|
26094
|
-
}).length;
|
|
26095
|
-
}
|
|
26096
|
-
if (!this.#usage) {
|
|
26097
|
-
const context = replayedEvents.findLast((event) => event.type === "usage.context");
|
|
26098
|
-
this.#usage = new AntigravitySessionUsageTracker({
|
|
26099
|
-
nativeSessionId: opened.sessionId,
|
|
26100
|
-
homedir: antigravityHome(this.#options.environment),
|
|
26101
|
-
expectedInitialTurns: this.#turnCount,
|
|
26102
|
-
...context ? { initialContextUsedTokens: context.used, initialContextWindowTokens: context.size } : {}
|
|
26103
|
-
});
|
|
26104
|
-
this.#usageWork = this.#replayUsage();
|
|
26365
|
+
}).length);
|
|
26105
26366
|
}
|
|
26367
|
+
this.#initializeUsage(opened.sessionId, replayedEvents);
|
|
26106
26368
|
transport.setSessionEventHandler((event) => {
|
|
26107
26369
|
if (this.#transport === transport && !this.#closed && !this.#faulted)
|
|
26108
26370
|
this.#sessionEvent(event);
|
|
@@ -26132,6 +26394,18 @@ var AntigravitySession = class {
|
|
|
26132
26394
|
throw error51;
|
|
26133
26395
|
}
|
|
26134
26396
|
}
|
|
26397
|
+
#initializeUsage(nativeSessionId, events) {
|
|
26398
|
+
if (this.#usage)
|
|
26399
|
+
return;
|
|
26400
|
+
const context = events.findLast((event) => event.type === "usage.context");
|
|
26401
|
+
this.#usage = new AntigravitySessionUsageTracker({
|
|
26402
|
+
nativeSessionId,
|
|
26403
|
+
homedir: antigravityHome(this.#options.environment),
|
|
26404
|
+
expectedInitialTurns: this.#turnCount,
|
|
26405
|
+
...context ? { initialContextUsedTokens: context.used, initialContextWindowTokens: context.size } : {}
|
|
26406
|
+
});
|
|
26407
|
+
this.#usageWork = this.#replayUsage();
|
|
26408
|
+
}
|
|
26135
26409
|
#setLocatorPermissionMode(permissionModeId) {
|
|
26136
26410
|
const ref = this.#state.nativeRef;
|
|
26137
26411
|
if (!ref)
|
|
@@ -26322,33 +26596,35 @@ var AntigravitySession = class {
|
|
|
26322
26596
|
return err("invalidState", "Session is closed");
|
|
26323
26597
|
if (!this.nativeRef)
|
|
26324
26598
|
return ok({ turns: [], state: { ...this.#state } });
|
|
26325
|
-
const
|
|
26326
|
-
this.#readers.add(transport);
|
|
26599
|
+
const skip = this.#transport?.skipPermissions ?? (this.#options.unattended || this.#requested.permissionModeId === SKIP);
|
|
26327
26600
|
try {
|
|
26328
|
-
await
|
|
26329
|
-
const { opened, replayedEvents } = await transport.openSession({
|
|
26330
|
-
kind: "load",
|
|
26601
|
+
const { opened, replayedEvents } = await this.#options.readerPool.loadSession({
|
|
26331
26602
|
sessionId: this.nativeRef.nativeSessionId,
|
|
26332
26603
|
cwd: this.#options.cwd,
|
|
26333
|
-
|
|
26604
|
+
environment: this.#options.environment,
|
|
26605
|
+
skipPermissions: skip,
|
|
26606
|
+
signal: this.#abort.signal
|
|
26334
26607
|
});
|
|
26335
|
-
if (
|
|
26336
|
-
|
|
26337
|
-
const
|
|
26338
|
-
|
|
26339
|
-
|
|
26340
|
-
|
|
26341
|
-
|
|
26342
|
-
|
|
26343
|
-
|
|
26344
|
-
|
|
26345
|
-
|
|
26346
|
-
|
|
26347
|
-
|
|
26348
|
-
|
|
26349
|
-
|
|
26608
|
+
if (this.#closed || this.#faulted)
|
|
26609
|
+
return err("invalidState", "Session is closed");
|
|
26610
|
+
const turns = projectReplayedEventsToTurns({
|
|
26611
|
+
nativeSessionId: opened.sessionId,
|
|
26612
|
+
cwd: this.#options.cwd,
|
|
26613
|
+
events: replayedEvents,
|
|
26614
|
+
...this.#options.knownTurnRefs ? { knownTurnRefs: this.#options.knownTurnRefs } : {},
|
|
26615
|
+
...this.#options.adapter.toolOutputLimit !== void 0 ? { outputLimit: this.#options.adapter.toolOutputLimit } : {}
|
|
26616
|
+
});
|
|
26617
|
+
const turnCount = this.#transport ? this.#turnCount : await readNativeTurnCount(nativeConversationDbPath(opened.sessionId, antigravityHome(this.#options.environment))).catch(() => turns.length);
|
|
26618
|
+
if (this.#closed || this.#faulted)
|
|
26619
|
+
return err("invalidState", "Session is closed");
|
|
26620
|
+
if (!this.#transport) {
|
|
26621
|
+
this.#turnCount = turnCount;
|
|
26622
|
+
this.#initializeUsage(opened.sessionId, replayedEvents);
|
|
26623
|
+
}
|
|
26624
|
+
return ok({ turns, ...this.#transport ? { state: { ...this.#state } } : {} });
|
|
26350
26625
|
} catch (error51) {
|
|
26351
|
-
|
|
26626
|
+
if (this.#closed || this.#faulted)
|
|
26627
|
+
return err("invalidState", "Session is closed");
|
|
26352
26628
|
return { ok: false, error: normalizeAntigravityError(error51) };
|
|
26353
26629
|
}
|
|
26354
26630
|
}
|
|
@@ -26567,19 +26843,19 @@ var AntigravitySession = class {
|
|
|
26567
26843
|
await this.#usageWork;
|
|
26568
26844
|
if (this.#usage && this.#isCurrent(turn)) {
|
|
26569
26845
|
try {
|
|
26570
|
-
const
|
|
26846
|
+
const timing2 = {
|
|
26571
26847
|
...turn.firstOutputAtMs !== void 0 ? { firstOutputAtMs: turn.firstOutputAtMs } : {},
|
|
26572
26848
|
completedAtMs
|
|
26573
26849
|
};
|
|
26574
26850
|
const update = await this.#usage.collectNewTranscriptRequests({
|
|
26575
|
-
...
|
|
26851
|
+
...timing2,
|
|
26576
26852
|
...turn.hasToolCalls ? { hasToolCalls: true } : {},
|
|
26577
26853
|
...result.usage ? { promptUsage: result.usage } : {},
|
|
26578
26854
|
signal: this.#abort.signal
|
|
26579
26855
|
});
|
|
26580
26856
|
const recorded = this.#usage.recordTurnPromptUsage({
|
|
26581
26857
|
...result.usage ? { usage: result.usage } : {},
|
|
26582
|
-
...
|
|
26858
|
+
...timing2
|
|
26583
26859
|
});
|
|
26584
26860
|
if (!this.#isCurrent(turn))
|
|
26585
26861
|
return;
|
|
@@ -26782,12 +27058,7 @@ var AntigravitySession = class {
|
|
|
26782
27058
|
this.#transport?.setSessionEventHandler(null);
|
|
26783
27059
|
if (active)
|
|
26784
27060
|
await this.#transport?.cancel().catch(() => void 0);
|
|
26785
|
-
await Promise.all([
|
|
26786
|
-
this.#transport?.close(),
|
|
26787
|
-
this.#subagents.close(),
|
|
26788
|
-
...[...this.#readers].map((reader) => reader.close())
|
|
26789
|
-
]);
|
|
26790
|
-
this.#readers.clear();
|
|
27061
|
+
await Promise.all([this.#transport?.close(), this.#subagents.close()]);
|
|
26791
27062
|
this.#options.onClosed(this);
|
|
26792
27063
|
}
|
|
26793
27064
|
};
|
|
@@ -26812,6 +27083,7 @@ var AntigravityAdapter = class {
|
|
|
26812
27083
|
usageStatistics;
|
|
26813
27084
|
#environment;
|
|
26814
27085
|
#sessions = /* @__PURE__ */ new Set();
|
|
27086
|
+
#readerPool;
|
|
26815
27087
|
#cache = /* @__PURE__ */ new Map();
|
|
26816
27088
|
#inflight = /* @__PURE__ */ new Map();
|
|
26817
27089
|
#abort = new AbortController();
|
|
@@ -26822,6 +27094,7 @@ var AntigravityAdapter = class {
|
|
|
26822
27094
|
constructor(options = {}) {
|
|
26823
27095
|
this.options = options;
|
|
26824
27096
|
this.#environment = options.environment ?? process.env;
|
|
27097
|
+
this.#readerPool = new AntigravitySnapshotReaderPool(this.options);
|
|
26825
27098
|
this.sessionImport = new AntigravitySessionImport(this.#environment);
|
|
26826
27099
|
this.usageStatistics = createAntigravityUsageStatistics(this.#environment);
|
|
26827
27100
|
}
|
|
@@ -26919,7 +27192,22 @@ var AntigravityAdapter = class {
|
|
|
26919
27192
|
const common = {
|
|
26920
27193
|
harnessId,
|
|
26921
27194
|
adapterEnvironment: this.#environment,
|
|
26922
|
-
openSession: (resume) =>
|
|
27195
|
+
openSession: async (resume) => {
|
|
27196
|
+
const result = await this.open(resume);
|
|
27197
|
+
if (!result.ok || !(result.value instanceof AntigravitySession))
|
|
27198
|
+
return result;
|
|
27199
|
+
try {
|
|
27200
|
+
await result.value.initialize();
|
|
27201
|
+
if (this.#closed) {
|
|
27202
|
+
await result.value.close();
|
|
27203
|
+
return err("invalidState", "Adapter is closed");
|
|
27204
|
+
}
|
|
27205
|
+
return result;
|
|
27206
|
+
} catch (error51) {
|
|
27207
|
+
await result.value.close().catch(() => void 0);
|
|
27208
|
+
return { ok: false, error: normalizeAntigravityError(error51) };
|
|
27209
|
+
}
|
|
27210
|
+
}
|
|
26923
27211
|
};
|
|
26924
27212
|
try {
|
|
26925
27213
|
return await (input.kind === "fork" ? forkAntigravitySession({ ...common, input }) : rollbackAntigravityLastTurn({ ...common, input }));
|
|
@@ -26949,12 +27237,11 @@ var AntigravityAdapter = class {
|
|
|
26949
27237
|
...input.kind === "resume" ? { nativeRef: input.nativeRef, knownTurnRefs: input.knownTurnRefs } : {},
|
|
26950
27238
|
unattended,
|
|
26951
27239
|
adapter: this.options,
|
|
27240
|
+
readerPool: this.#readerPool,
|
|
26952
27241
|
onClosed: (closed) => this.#sessions.delete(closed)
|
|
26953
27242
|
});
|
|
26954
27243
|
this.#sessions.add(session);
|
|
26955
27244
|
try {
|
|
26956
|
-
if (input.kind === "resume")
|
|
26957
|
-
await session.initialize();
|
|
26958
27245
|
if (this.#closed) {
|
|
26959
27246
|
await session.close();
|
|
26960
27247
|
return err("invalidState", "Adapter is closed");
|
|
@@ -27025,7 +27312,10 @@ var AntigravityAdapter = class {
|
|
|
27025
27312
|
this.#cache.clear();
|
|
27026
27313
|
this.#inflight.clear();
|
|
27027
27314
|
this.#quota = null;
|
|
27028
|
-
await Promise.all([
|
|
27315
|
+
await Promise.all([
|
|
27316
|
+
...[...this.#sessions].map((session) => session.close()),
|
|
27317
|
+
this.#readerPool.close()
|
|
27318
|
+
]);
|
|
27029
27319
|
this.#sessions.clear();
|
|
27030
27320
|
}
|
|
27031
27321
|
};
|