@moxt-ai/mobius 0.0.471 → 0.0.473
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/dist/{chunk-7XY5VCQJ.js → chunk-MYBYMYDN.js} +1544 -142
- package/dist/{chunk-7XY5VCQJ.js.map → chunk-MYBYMYDN.js.map} +4 -4
- package/dist/{chunk-HPFAJPEN.js → chunk-ZNDBQ5XO.js} +2 -2
- package/dist/{chunk-HPFAJPEN.js.map → chunk-ZNDBQ5XO.js.map} +1 -1
- package/dist/{cli-6OLHX3IS.js → cli-52AEF4WX.js} +3 -3
- package/dist/cli.js +2 -2
- package/dist/engine/acp/adapter/antigravity/adapter.d.ts +1 -0
- package/dist/engine/acp/adapter/antigravity/adapter.d.ts.map +1 -1
- package/dist/engine/acp/adapter/antigravity/adapter.js +17 -5
- package/dist/engine/acp/adapter/antigravity/adapter.js.map +1 -1
- package/dist/engine/acp/adapter/antigravity/agent-connection.d.ts +12 -0
- package/dist/engine/acp/adapter/antigravity/agent-connection.d.ts.map +1 -1
- package/dist/engine/acp/adapter/antigravity/agent-connection.js +100 -0
- package/dist/engine/acp/adapter/antigravity/agent-connection.js.map +1 -1
- package/dist/engine/acp/adapter/antigravity/background-wakeup.d.ts +26 -0
- package/dist/engine/acp/adapter/antigravity/background-wakeup.d.ts.map +1 -1
- package/dist/engine/acp/adapter/antigravity/background-wakeup.js +592 -0
- package/dist/engine/acp/adapter/antigravity/background-wakeup.js.map +1 -1
- package/dist/engine/acp/adapter/antigravity/session-artifacts.d.ts +39 -0
- package/dist/engine/acp/adapter/antigravity/session-artifacts.d.ts.map +1 -0
- package/dist/engine/acp/adapter/antigravity/session-artifacts.js +409 -0
- package/dist/engine/acp/adapter/antigravity/session-artifacts.js.map +1 -0
- package/dist/engine/acp/adapter/claude/adapter.d.ts.map +1 -1
- package/dist/engine/acp/adapter/claude/adapter.js +3 -2
- package/dist/engine/acp/adapter/claude/adapter.js.map +1 -1
- package/dist/engine/acp/adapter/codex/adapter.d.ts.map +1 -1
- package/dist/engine/acp/adapter/codex/adapter.js +3 -2
- package/dist/engine/acp/adapter/codex/adapter.js.map +1 -1
- package/dist/engine/acp/adapter/lifecycle-output.d.ts +4 -1
- package/dist/engine/acp/adapter/lifecycle-output.d.ts.map +1 -1
- package/dist/engine/acp/adapter/lifecycle-output.js +5 -0
- package/dist/engine/acp/adapter/lifecycle-output.js.map +1 -1
- package/dist/engine/acp/harness/claude/turn-tokens.d.ts +8 -0
- package/dist/engine/acp/harness/claude/turn-tokens.d.ts.map +1 -0
- package/dist/engine/acp/harness/claude/turn-tokens.js +57 -0
- package/dist/engine/acp/harness/claude/turn-tokens.js.map +1 -0
- package/dist/engine/acp/harness/codex/app-server-protocol.d.ts +18 -0
- package/dist/engine/acp/harness/codex/app-server-protocol.d.ts.map +1 -1
- package/dist/engine/acp/harness/codex/app-server-protocol.js +18 -0
- package/dist/engine/acp/harness/codex/app-server-protocol.js.map +1 -1
- package/dist/engine/acp/harness/codex/owned-agent.d.ts.map +1 -1
- package/dist/engine/acp/harness/codex/owned-agent.js +41 -4
- package/dist/engine/acp/harness/codex/owned-agent.js.map +1 -1
- package/dist/engine/acp/harness/codex/turn-tokens.d.ts +8 -0
- package/dist/engine/acp/harness/codex/turn-tokens.d.ts.map +1 -0
- package/dist/engine/acp/harness/codex/turn-tokens.js +20 -0
- package/dist/engine/acp/harness/codex/turn-tokens.js.map +1 -0
- package/dist/engine/acp/native-history/preview-contract.d.ts +10 -1
- package/dist/engine/acp/native-history/preview-contract.d.ts.map +1 -1
- package/dist/engine/runtime/command/registry/prompt.d.ts.map +1 -1
- package/dist/engine/runtime/command/registry/prompt.js +1 -0
- package/dist/engine/runtime/command/registry/prompt.js.map +1 -1
- package/dist/engine/session/live/agent-session.d.ts +2 -0
- package/dist/engine/session/live/agent-session.d.ts.map +1 -1
- package/dist/engine/session/live/agent-session.js +34 -4
- package/dist/engine/session/live/agent-session.js.map +1 -1
- package/dist/engine/session/manager/session-manager.d.ts +5 -0
- package/dist/engine/session/manager/session-manager.d.ts.map +1 -1
- package/dist/engine/session/manager/session-manager.js +16 -2
- package/dist/engine/session/manager/session-manager.js.map +1 -1
- package/dist/engine/session/prompt/execute-prompt.d.ts +3 -1
- package/dist/engine/session/prompt/execute-prompt.d.ts.map +1 -1
- package/dist/engine/session/prompt/execute-prompt.js +57 -26
- package/dist/engine/session/prompt/execute-prompt.js.map +1 -1
- package/dist/engine/session/turn/active-turn.d.ts +5 -0
- package/dist/engine/session/turn/active-turn.d.ts.map +1 -1
- package/dist/engine/session/turn/active-turn.js +7 -0
- package/dist/engine/session/turn/active-turn.js.map +1 -1
- package/dist/engine/session/turn/session-execution.d.ts +5 -0
- package/dist/engine/session/turn/session-execution.d.ts.map +1 -1
- package/dist/engine/session/turn/session-execution.js +17 -0
- package/dist/engine/session/turn/session-execution.js.map +1 -1
- package/dist/engine/session/turn/session-turns.d.ts +1 -0
- package/dist/engine/session/turn/session-turns.d.ts.map +1 -1
- package/dist/engine/session/turn/session-turns.js +1 -0
- package/dist/engine/session/turn/session-turns.js.map +1 -1
- package/dist/engine/storage/files/local-files.d.ts +11 -0
- package/dist/engine/storage/files/local-files.d.ts.map +1 -1
- package/dist/engine/storage/files/local-files.js +141 -0
- package/dist/engine/storage/files/local-files.js.map +1 -1
- package/dist/engine.js +2 -2
- package/package.json +1 -1
- /package/dist/{cli-6OLHX3IS.js.map → cli-52AEF4WX.js.map} +0 -0
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
__toESM,
|
|
6
6
|
__using,
|
|
7
7
|
package_default
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-ZNDBQ5XO.js";
|
|
9
9
|
|
|
10
10
|
// ../../node_modules/.pnpm/ignore@7.0.9/node_modules/ignore/index.js
|
|
11
11
|
var require_ignore = __commonJS({
|
|
@@ -21476,6 +21476,7 @@ var turnTokenUsageSchema = external_exports.object({
|
|
|
21476
21476
|
}).readonly().refine(
|
|
21477
21477
|
(usage) => usage.cachedInputTokens + usage.cacheWriteTokens <= usage.inputTokens && (usage.reasoningTokens ?? 0) <= usage.outputTokens
|
|
21478
21478
|
);
|
|
21479
|
+
var isTurnTokenUsage = (value) => turnTokenUsageSchema.safeParse(value).success;
|
|
21479
21480
|
var agentPromptResponseSchema = external_exports.object({
|
|
21480
21481
|
_meta: promptMetadataSchema.nullish(),
|
|
21481
21482
|
stopReason: external_exports.enum(["end_turn", "max_tokens", "max_turn_requests", "refusal", "cancelled"]),
|
|
@@ -23277,6 +23278,7 @@ import { constants, createReadStream } from "node:fs";
|
|
|
23277
23278
|
import { mkdir, mkdtemp, open as open2, readdir, readFile, readlink, realpath, rm, stat } from "node:fs/promises";
|
|
23278
23279
|
import { tmpdir } from "node:os";
|
|
23279
23280
|
import { basename, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
23281
|
+
import { DatabaseSync } from "node:sqlite";
|
|
23280
23282
|
import { promisify } from "node:util";
|
|
23281
23283
|
function entryKind(entry) {
|
|
23282
23284
|
if (entry.isDirectory()) {
|
|
@@ -23369,6 +23371,131 @@ async function readScopedFileTail(baseDirectory, requestedRelativePath, maximumB
|
|
|
23369
23371
|
return null;
|
|
23370
23372
|
}
|
|
23371
23373
|
}
|
|
23374
|
+
async function readScopedFileBytes(baseDirectory, requestedRelativePath, maximumBytes) {
|
|
23375
|
+
if (requestedRelativePath.length === 0 || isAbsolute(requestedRelativePath) || maximumBytes <= 0) {
|
|
23376
|
+
return null;
|
|
23377
|
+
}
|
|
23378
|
+
try {
|
|
23379
|
+
const directory = await canonicalPath(resolve(baseDirectory));
|
|
23380
|
+
const candidate = resolve(directory, requestedRelativePath);
|
|
23381
|
+
if (!withinDirectory(directory, candidate)) {
|
|
23382
|
+
return null;
|
|
23383
|
+
}
|
|
23384
|
+
const target = await canonicalPath(candidate);
|
|
23385
|
+
if (!withinDirectory(directory, target)) {
|
|
23386
|
+
return null;
|
|
23387
|
+
}
|
|
23388
|
+
const handle = await open2(target, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
23389
|
+
try {
|
|
23390
|
+
const metadata = await handle.stat();
|
|
23391
|
+
if (!metadata.isFile() || metadata.size > maximumBytes) {
|
|
23392
|
+
return null;
|
|
23393
|
+
}
|
|
23394
|
+
if (metadata.size === 0) {
|
|
23395
|
+
return new Uint8Array(0);
|
|
23396
|
+
}
|
|
23397
|
+
const buffer = new Uint8Array(metadata.size);
|
|
23398
|
+
const { bytesRead } = await handle.read(buffer, 0, metadata.size, 0);
|
|
23399
|
+
return buffer.subarray(0, bytesRead);
|
|
23400
|
+
} finally {
|
|
23401
|
+
await handle.close();
|
|
23402
|
+
}
|
|
23403
|
+
} catch {
|
|
23404
|
+
return null;
|
|
23405
|
+
}
|
|
23406
|
+
}
|
|
23407
|
+
async function statScopedFile(baseDirectory, requestedRelativePath) {
|
|
23408
|
+
if (requestedRelativePath.length === 0 || isAbsolute(requestedRelativePath)) {
|
|
23409
|
+
return null;
|
|
23410
|
+
}
|
|
23411
|
+
try {
|
|
23412
|
+
const directory = await canonicalPath(resolve(baseDirectory));
|
|
23413
|
+
const candidate = resolve(directory, requestedRelativePath);
|
|
23414
|
+
if (!withinDirectory(directory, candidate)) {
|
|
23415
|
+
return null;
|
|
23416
|
+
}
|
|
23417
|
+
const target = await canonicalPath(candidate);
|
|
23418
|
+
if (!withinDirectory(directory, target)) {
|
|
23419
|
+
return null;
|
|
23420
|
+
}
|
|
23421
|
+
const handle = await open2(target, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
23422
|
+
try {
|
|
23423
|
+
const metadata = await handle.stat();
|
|
23424
|
+
if (!metadata.isFile()) {
|
|
23425
|
+
return null;
|
|
23426
|
+
}
|
|
23427
|
+
return { modifiedMilliseconds: metadata.mtimeMs, size: metadata.size };
|
|
23428
|
+
} finally {
|
|
23429
|
+
await handle.close();
|
|
23430
|
+
}
|
|
23431
|
+
} catch {
|
|
23432
|
+
return null;
|
|
23433
|
+
}
|
|
23434
|
+
}
|
|
23435
|
+
async function listScopedDirectory(baseDirectory, requestedRelativePath) {
|
|
23436
|
+
if (requestedRelativePath.length === 0 || isAbsolute(requestedRelativePath)) {
|
|
23437
|
+
return null;
|
|
23438
|
+
}
|
|
23439
|
+
try {
|
|
23440
|
+
const directory = await canonicalPath(resolve(baseDirectory));
|
|
23441
|
+
const candidate = resolve(directory, requestedRelativePath);
|
|
23442
|
+
if (!withinDirectory(directory, candidate)) {
|
|
23443
|
+
return null;
|
|
23444
|
+
}
|
|
23445
|
+
const target = await canonicalPath(candidate);
|
|
23446
|
+
if (!withinDirectory(directory, target)) {
|
|
23447
|
+
return null;
|
|
23448
|
+
}
|
|
23449
|
+
const metadata = await stat(target);
|
|
23450
|
+
if (!metadata.isDirectory()) {
|
|
23451
|
+
return null;
|
|
23452
|
+
}
|
|
23453
|
+
return await listDirectory(target);
|
|
23454
|
+
} catch {
|
|
23455
|
+
return null;
|
|
23456
|
+
}
|
|
23457
|
+
}
|
|
23458
|
+
async function queryScopedSqliteRow(baseDirectory, requestedRelativePath, sql2) {
|
|
23459
|
+
if (requestedRelativePath.length === 0 || isAbsolute(requestedRelativePath)) {
|
|
23460
|
+
return null;
|
|
23461
|
+
}
|
|
23462
|
+
let dbPath = null;
|
|
23463
|
+
try {
|
|
23464
|
+
const directory = await canonicalPath(resolve(baseDirectory));
|
|
23465
|
+
const candidate = resolve(directory, requestedRelativePath);
|
|
23466
|
+
if (!withinDirectory(directory, candidate)) {
|
|
23467
|
+
return null;
|
|
23468
|
+
}
|
|
23469
|
+
const target = await canonicalPath(candidate);
|
|
23470
|
+
if (!withinDirectory(directory, target)) {
|
|
23471
|
+
return null;
|
|
23472
|
+
}
|
|
23473
|
+
const handle = await open2(target, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
23474
|
+
try {
|
|
23475
|
+
const metadata = await handle.stat();
|
|
23476
|
+
dbPath = metadata.isFile() ? target : null;
|
|
23477
|
+
} finally {
|
|
23478
|
+
await handle.close();
|
|
23479
|
+
}
|
|
23480
|
+
} catch {
|
|
23481
|
+
return null;
|
|
23482
|
+
}
|
|
23483
|
+
if (dbPath === null) {
|
|
23484
|
+
return null;
|
|
23485
|
+
}
|
|
23486
|
+
let db2;
|
|
23487
|
+
try {
|
|
23488
|
+
db2 = new DatabaseSync(dbPath, { readOnly: true });
|
|
23489
|
+
return db2.prepare(sql2).get() ?? null;
|
|
23490
|
+
} catch {
|
|
23491
|
+
return null;
|
|
23492
|
+
} finally {
|
|
23493
|
+
try {
|
|
23494
|
+
db2?.close();
|
|
23495
|
+
} catch {
|
|
23496
|
+
}
|
|
23497
|
+
}
|
|
23498
|
+
}
|
|
23372
23499
|
async function readFileBytes(path6) {
|
|
23373
23500
|
return await readFile(path6);
|
|
23374
23501
|
}
|
|
@@ -29111,7 +29238,7 @@ function createWritableAcpStream(output2) {
|
|
|
29111
29238
|
|
|
29112
29239
|
// src/engine/acp/adapter/antigravity/background-wakeup.ts
|
|
29113
29240
|
import { homedir } from "node:os";
|
|
29114
|
-
import { join as
|
|
29241
|
+
import { join as join12 } from "node:path";
|
|
29115
29242
|
|
|
29116
29243
|
// src/engine/util/timer.ts
|
|
29117
29244
|
var SystemTimer = class {
|
|
@@ -29126,6 +29253,415 @@ var SystemTimer = class {
|
|
|
29126
29253
|
};
|
|
29127
29254
|
var systemTimer = new SystemTimer();
|
|
29128
29255
|
|
|
29256
|
+
// src/engine/acp/adapter/antigravity/session-artifacts.ts
|
|
29257
|
+
import { join as join11 } from "node:path";
|
|
29258
|
+
var SESSION_UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu;
|
|
29259
|
+
var TASK_ID_PATTERN = /^task-\d+$/u;
|
|
29260
|
+
var TASK_SENDER_PATTERN = /^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\/(task-\d+)$/iu;
|
|
29261
|
+
var MAXIMUM_JSON_BYTES = 65536;
|
|
29262
|
+
var MAXIMUM_SWARM_OR_READ_INDEX_BYTES = 262144;
|
|
29263
|
+
var MAXIMUM_SUBAGENT_FILES = 64;
|
|
29264
|
+
var MAXIMUM_MESSAGE_FILES = 256;
|
|
29265
|
+
var MAXIMUM_UNDELIVERED_FILES = 32;
|
|
29266
|
+
var MAXIMUM_TASK_LOG_FILES = 16;
|
|
29267
|
+
var MAXIMUM_ERROR_TEXT_CHARS = 500;
|
|
29268
|
+
var RESTART_SYSTEM_MESSAGE_MARKER = "All your subagents and background tasks have been stopped due to server restart";
|
|
29269
|
+
var subagentRecordSchema = external_exports.object({
|
|
29270
|
+
conversationId: external_exports.string().optional(),
|
|
29271
|
+
id: external_exports.string().optional(),
|
|
29272
|
+
state: external_exports.string().optional()
|
|
29273
|
+
});
|
|
29274
|
+
var swarmMemberSchema = external_exports.object({
|
|
29275
|
+
conversation_id: external_exports.string().optional(),
|
|
29276
|
+
conversationId: external_exports.string().optional(),
|
|
29277
|
+
desired_state: external_exports.string().optional(),
|
|
29278
|
+
desiredState: external_exports.string().optional(),
|
|
29279
|
+
phase: external_exports.string().optional(),
|
|
29280
|
+
wake_mode: external_exports.string().optional(),
|
|
29281
|
+
wakeMode: external_exports.string().optional()
|
|
29282
|
+
});
|
|
29283
|
+
var swarmMembersFileSchema = external_exports.object({
|
|
29284
|
+
members: external_exports.array(swarmMemberSchema).optional()
|
|
29285
|
+
});
|
|
29286
|
+
var messageRecordSchema = external_exports.object({
|
|
29287
|
+
id: external_exports.string().optional(),
|
|
29288
|
+
priority: external_exports.string().optional(),
|
|
29289
|
+
sender: external_exports.string().optional(),
|
|
29290
|
+
sourceMetadata: external_exports.object({
|
|
29291
|
+
tool: external_exports.object({
|
|
29292
|
+
toolCall: external_exports.object({
|
|
29293
|
+
id: external_exports.string().optional()
|
|
29294
|
+
}).optional()
|
|
29295
|
+
}).optional()
|
|
29296
|
+
}).optional(),
|
|
29297
|
+
timestamp: external_exports.string().optional()
|
|
29298
|
+
});
|
|
29299
|
+
var readIndexSchema = external_exports.record(external_exports.string(), external_exports.unknown());
|
|
29300
|
+
var conversationDbStepRowSchema = external_exports.object({
|
|
29301
|
+
error_details: external_exports.instanceof(Uint8Array).nullable().optional(),
|
|
29302
|
+
status: external_exports.number().int().optional()
|
|
29303
|
+
});
|
|
29304
|
+
var EMPTY_SUBAGENT_SNAPSHOT = {
|
|
29305
|
+
activeChildIds: /* @__PURE__ */ new Set(),
|
|
29306
|
+
available: false,
|
|
29307
|
+
conversationIdByToolCallId: /* @__PURE__ */ new Map(),
|
|
29308
|
+
deliveredNativeTaskIds: /* @__PURE__ */ new Set(),
|
|
29309
|
+
deliveredToolCallIds: /* @__PURE__ */ new Set(),
|
|
29310
|
+
resolvedChildIds: /* @__PURE__ */ new Set()
|
|
29311
|
+
};
|
|
29312
|
+
function parseTimestampMs(raw) {
|
|
29313
|
+
if (raw === void 0 || raw.length === 0) {
|
|
29314
|
+
return void 0;
|
|
29315
|
+
}
|
|
29316
|
+
const parsed = Date.parse(raw);
|
|
29317
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
29318
|
+
}
|
|
29319
|
+
function normalizeUuid(raw) {
|
|
29320
|
+
if (raw === void 0) {
|
|
29321
|
+
return void 0;
|
|
29322
|
+
}
|
|
29323
|
+
const trimmed = raw.trim().toLowerCase();
|
|
29324
|
+
return SESSION_UUID_PATTERN.test(trimmed) ? trimmed : void 0;
|
|
29325
|
+
}
|
|
29326
|
+
async function readScopedJson(baseDirectory, relativePath, maximumBytes, schema) {
|
|
29327
|
+
const bytes = await readScopedFileBytes(baseDirectory, relativePath, maximumBytes);
|
|
29328
|
+
if (bytes === null || bytes.byteLength === 0) {
|
|
29329
|
+
return null;
|
|
29330
|
+
}
|
|
29331
|
+
let decoded;
|
|
29332
|
+
try {
|
|
29333
|
+
decoded = JSON.parse(new TextDecoder().decode(bytes));
|
|
29334
|
+
} catch {
|
|
29335
|
+
return null;
|
|
29336
|
+
}
|
|
29337
|
+
const parsed = schema.safeParse(decoded);
|
|
29338
|
+
return parsed.success ? parsed.data : null;
|
|
29339
|
+
}
|
|
29340
|
+
function brainGeneratedPath(sessionId, ...segments) {
|
|
29341
|
+
return join11("antigravity-cli", "brain", sessionId, ".system_generated", ...segments);
|
|
29342
|
+
}
|
|
29343
|
+
async function readChildInboundInfo(geminiHome, parentSessionId, childId) {
|
|
29344
|
+
const toolCallIds = [];
|
|
29345
|
+
let latestInboundMs;
|
|
29346
|
+
let hasUndeliveredFromParent = false;
|
|
29347
|
+
const normalizedParent = parentSessionId.toLowerCase();
|
|
29348
|
+
const inspectDirectory = async (relativeDir, markUndelivered) => {
|
|
29349
|
+
const entries = await listScopedDirectory(geminiHome, relativeDir);
|
|
29350
|
+
if (entries === null) {
|
|
29351
|
+
return;
|
|
29352
|
+
}
|
|
29353
|
+
let inspected = 0;
|
|
29354
|
+
for (const entry of entries) {
|
|
29355
|
+
if (inspected >= MAXIMUM_UNDELIVERED_FILES) {
|
|
29356
|
+
break;
|
|
29357
|
+
}
|
|
29358
|
+
if (entry.kind !== "file" || !entry.name.endsWith(".json") || entry.name === "read.json") {
|
|
29359
|
+
continue;
|
|
29360
|
+
}
|
|
29361
|
+
inspected += 1;
|
|
29362
|
+
const record2 = await readScopedJson(
|
|
29363
|
+
geminiHome,
|
|
29364
|
+
join11(relativeDir, entry.name),
|
|
29365
|
+
MAXIMUM_JSON_BYTES,
|
|
29366
|
+
messageRecordSchema
|
|
29367
|
+
);
|
|
29368
|
+
if (record2 === null) {
|
|
29369
|
+
continue;
|
|
29370
|
+
}
|
|
29371
|
+
const sender = normalizeUuid(record2.sender);
|
|
29372
|
+
if (sender !== normalizedParent) {
|
|
29373
|
+
continue;
|
|
29374
|
+
}
|
|
29375
|
+
if (markUndelivered) {
|
|
29376
|
+
hasUndeliveredFromParent = true;
|
|
29377
|
+
}
|
|
29378
|
+
const ts2 = parseTimestampMs(record2.timestamp);
|
|
29379
|
+
if (ts2 !== void 0 && (latestInboundMs === void 0 || ts2 > latestInboundMs)) {
|
|
29380
|
+
latestInboundMs = ts2;
|
|
29381
|
+
}
|
|
29382
|
+
const toolCallId = record2.sourceMetadata?.tool?.toolCall?.id?.trim();
|
|
29383
|
+
if (toolCallId !== void 0 && toolCallId.length > 0) {
|
|
29384
|
+
toolCallIds.push(toolCallId);
|
|
29385
|
+
}
|
|
29386
|
+
}
|
|
29387
|
+
};
|
|
29388
|
+
await inspectDirectory(brainGeneratedPath(childId, "messages"), false);
|
|
29389
|
+
await inspectDirectory(brainGeneratedPath(childId, "messages", "undelivered"), true);
|
|
29390
|
+
return { hasUndeliveredFromParent, latestInboundMs, toolCallIds };
|
|
29391
|
+
}
|
|
29392
|
+
async function readAntigravitySubagentSnapshot(geminiHome, sessionId) {
|
|
29393
|
+
if (geminiHome === void 0 || !SESSION_UUID_PATTERN.test(sessionId)) {
|
|
29394
|
+
return EMPTY_SUBAGENT_SNAPSHOT;
|
|
29395
|
+
}
|
|
29396
|
+
const targetSessionId = sessionId.toLowerCase();
|
|
29397
|
+
const conversationIdByToolCallId = /* @__PURE__ */ new Map();
|
|
29398
|
+
const activeChildIds = /* @__PURE__ */ new Set();
|
|
29399
|
+
const resolvedChildIds = /* @__PURE__ */ new Set();
|
|
29400
|
+
const deliveredToolCallIds = /* @__PURE__ */ new Set();
|
|
29401
|
+
const deliveredNativeTaskIds = /* @__PURE__ */ new Set();
|
|
29402
|
+
const parentRepliedChildren = /* @__PURE__ */ new Set();
|
|
29403
|
+
const parentReplyMsByChild = /* @__PURE__ */ new Map();
|
|
29404
|
+
const parentMsgDir = brainGeneratedPath(sessionId, "messages");
|
|
29405
|
+
const parentMsgEntries = await listScopedDirectory(geminiHome, parentMsgDir);
|
|
29406
|
+
if (parentMsgEntries !== null) {
|
|
29407
|
+
let inspected = 0;
|
|
29408
|
+
for (const entry of parentMsgEntries) {
|
|
29409
|
+
if (inspected >= MAXIMUM_MESSAGE_FILES) {
|
|
29410
|
+
break;
|
|
29411
|
+
}
|
|
29412
|
+
if (entry.kind !== "file" || !entry.name.endsWith(".json") || entry.name === "read.json") {
|
|
29413
|
+
continue;
|
|
29414
|
+
}
|
|
29415
|
+
inspected += 1;
|
|
29416
|
+
const record2 = await readScopedJson(
|
|
29417
|
+
geminiHome,
|
|
29418
|
+
join11(parentMsgDir, entry.name),
|
|
29419
|
+
MAXIMUM_JSON_BYTES,
|
|
29420
|
+
messageRecordSchema
|
|
29421
|
+
);
|
|
29422
|
+
if (record2 === null || record2.sender === void 0) {
|
|
29423
|
+
continue;
|
|
29424
|
+
}
|
|
29425
|
+
const taskMatch = TASK_SENDER_PATTERN.exec(record2.sender.trim());
|
|
29426
|
+
if (taskMatch !== null) {
|
|
29427
|
+
if (taskMatch[1]?.toLowerCase() === targetSessionId && taskMatch[2] !== void 0) {
|
|
29428
|
+
deliveredNativeTaskIds.add(taskMatch[2]);
|
|
29429
|
+
const toolCallId = record2.sourceMetadata?.tool?.toolCall?.id?.trim();
|
|
29430
|
+
if (toolCallId !== void 0 && toolCallId.length > 0) {
|
|
29431
|
+
deliveredToolCallIds.add(toolCallId);
|
|
29432
|
+
}
|
|
29433
|
+
}
|
|
29434
|
+
continue;
|
|
29435
|
+
}
|
|
29436
|
+
const childSender = normalizeUuid(record2.sender);
|
|
29437
|
+
if (childSender !== void 0 && childSender !== targetSessionId) {
|
|
29438
|
+
parentRepliedChildren.add(childSender);
|
|
29439
|
+
const ts2 = parseTimestampMs(record2.timestamp);
|
|
29440
|
+
const existing = parentReplyMsByChild.get(childSender);
|
|
29441
|
+
if (ts2 !== void 0 && (existing === void 0 || ts2 > existing)) {
|
|
29442
|
+
parentReplyMsByChild.set(childSender, ts2);
|
|
29443
|
+
}
|
|
29444
|
+
}
|
|
29445
|
+
}
|
|
29446
|
+
}
|
|
29447
|
+
let available = false;
|
|
29448
|
+
const classifyAliveChild = async (childId) => {
|
|
29449
|
+
const inbound = await readChildInboundInfo(geminiHome, sessionId, childId);
|
|
29450
|
+
for (const toolCallId of inbound.toolCallIds) {
|
|
29451
|
+
conversationIdByToolCallId.set(toolCallId, childId);
|
|
29452
|
+
}
|
|
29453
|
+
const replied = parentRepliedChildren.has(childId);
|
|
29454
|
+
const replyMs = parentReplyMsByChild.get(childId);
|
|
29455
|
+
const replyCoversLatestInbound = replied && !inbound.hasUndeliveredFromParent && (inbound.latestInboundMs === void 0 || replyMs !== void 0 && replyMs >= inbound.latestInboundMs);
|
|
29456
|
+
if (replyCoversLatestInbound) {
|
|
29457
|
+
resolvedChildIds.add(childId);
|
|
29458
|
+
} else {
|
|
29459
|
+
activeChildIds.add(childId);
|
|
29460
|
+
}
|
|
29461
|
+
};
|
|
29462
|
+
const subagentsDir = brainGeneratedPath(sessionId, "subagents");
|
|
29463
|
+
const subagentEntries = await listScopedDirectory(geminiHome, subagentsDir);
|
|
29464
|
+
if (subagentEntries !== null) {
|
|
29465
|
+
available = true;
|
|
29466
|
+
let inspected = 0;
|
|
29467
|
+
for (const entry of subagentEntries) {
|
|
29468
|
+
if (inspected >= MAXIMUM_SUBAGENT_FILES) {
|
|
29469
|
+
break;
|
|
29470
|
+
}
|
|
29471
|
+
if (entry.kind !== "file" || !entry.name.endsWith(".json")) {
|
|
29472
|
+
continue;
|
|
29473
|
+
}
|
|
29474
|
+
inspected += 1;
|
|
29475
|
+
const record2 = await readScopedJson(
|
|
29476
|
+
geminiHome,
|
|
29477
|
+
join11(subagentsDir, entry.name),
|
|
29478
|
+
MAXIMUM_JSON_BYTES,
|
|
29479
|
+
subagentRecordSchema
|
|
29480
|
+
);
|
|
29481
|
+
if (record2 === null) {
|
|
29482
|
+
continue;
|
|
29483
|
+
}
|
|
29484
|
+
const childId = normalizeUuid(record2.conversationId) ?? normalizeUuid(record2.id) ?? normalizeUuid(entry.name.slice(0, -".json".length));
|
|
29485
|
+
if (childId === void 0) {
|
|
29486
|
+
continue;
|
|
29487
|
+
}
|
|
29488
|
+
if (record2.state === "SUBAGENT_STATE_KILLED") {
|
|
29489
|
+
resolvedChildIds.add(childId);
|
|
29490
|
+
const inbound = await readChildInboundInfo(geminiHome, sessionId, childId);
|
|
29491
|
+
for (const toolCallId of inbound.toolCallIds) {
|
|
29492
|
+
conversationIdByToolCallId.set(toolCallId, childId);
|
|
29493
|
+
}
|
|
29494
|
+
continue;
|
|
29495
|
+
}
|
|
29496
|
+
await classifyAliveChild(childId);
|
|
29497
|
+
}
|
|
29498
|
+
}
|
|
29499
|
+
const swarmFile = await readScopedJson(
|
|
29500
|
+
geminiHome,
|
|
29501
|
+
brainGeneratedPath(sessionId, "swarm", "members.json"),
|
|
29502
|
+
MAXIMUM_SWARM_OR_READ_INDEX_BYTES,
|
|
29503
|
+
swarmMembersFileSchema
|
|
29504
|
+
);
|
|
29505
|
+
if (swarmFile?.members !== void 0) {
|
|
29506
|
+
available = true;
|
|
29507
|
+
for (const member of swarmFile.members.slice(0, MAXIMUM_SUBAGENT_FILES)) {
|
|
29508
|
+
const childId = normalizeUuid(member.conversation_id ?? member.conversationId);
|
|
29509
|
+
if (childId === void 0) {
|
|
29510
|
+
continue;
|
|
29511
|
+
}
|
|
29512
|
+
const desiredState = (member.desired_state ?? member.desiredState ?? "").toUpperCase();
|
|
29513
|
+
const phase = (member.phase ?? "").toUpperCase();
|
|
29514
|
+
const wakeMode = (member.wake_mode ?? member.wakeMode ?? "").toLowerCase();
|
|
29515
|
+
if (desiredState.includes("KILLED") || phase.includes("KILLED") || (phase.includes("WAIT") || phase.includes("IDLE") || phase.includes("PARK")) && wakeMode === "mentions") {
|
|
29516
|
+
resolvedChildIds.add(childId);
|
|
29517
|
+
continue;
|
|
29518
|
+
}
|
|
29519
|
+
await classifyAliveChild(childId);
|
|
29520
|
+
}
|
|
29521
|
+
}
|
|
29522
|
+
return {
|
|
29523
|
+
activeChildIds,
|
|
29524
|
+
available,
|
|
29525
|
+
conversationIdByToolCallId,
|
|
29526
|
+
deliveredNativeTaskIds,
|
|
29527
|
+
deliveredToolCallIds,
|
|
29528
|
+
resolvedChildIds
|
|
29529
|
+
};
|
|
29530
|
+
}
|
|
29531
|
+
async function readAntigravityPendingReply(geminiHome, sessionId, lastTranscriptStep) {
|
|
29532
|
+
if (lastTranscriptStep !== void 0 && lastTranscriptStep.type === "SYSTEM_MESSAGE" && !(lastTranscriptStep.content?.includes(RESTART_SYSTEM_MESSAGE_MARKER) ?? false)) {
|
|
29533
|
+
return true;
|
|
29534
|
+
}
|
|
29535
|
+
if (geminiHome === void 0 || !SESSION_UUID_PATTERN.test(sessionId)) {
|
|
29536
|
+
return false;
|
|
29537
|
+
}
|
|
29538
|
+
const undeliveredDir = brainGeneratedPath(sessionId, "messages", "undelivered");
|
|
29539
|
+
const undeliveredEntries = await listScopedDirectory(geminiHome, undeliveredDir);
|
|
29540
|
+
if (undeliveredEntries !== null) {
|
|
29541
|
+
let inspected2 = 0;
|
|
29542
|
+
for (const entry of undeliveredEntries) {
|
|
29543
|
+
if (inspected2 >= MAXIMUM_UNDELIVERED_FILES) {
|
|
29544
|
+
break;
|
|
29545
|
+
}
|
|
29546
|
+
if (entry.kind !== "file" || !entry.name.endsWith(".json")) {
|
|
29547
|
+
continue;
|
|
29548
|
+
}
|
|
29549
|
+
inspected2 += 1;
|
|
29550
|
+
const record2 = await readScopedJson(
|
|
29551
|
+
geminiHome,
|
|
29552
|
+
join11(undeliveredDir, entry.name),
|
|
29553
|
+
MAXIMUM_JSON_BYTES,
|
|
29554
|
+
messageRecordSchema
|
|
29555
|
+
);
|
|
29556
|
+
if (record2 === null || record2.priority === void 0 || record2.priority === "MESSAGE_PRIORITY_HIGH") {
|
|
29557
|
+
return true;
|
|
29558
|
+
}
|
|
29559
|
+
}
|
|
29560
|
+
}
|
|
29561
|
+
const parentMsgDir = brainGeneratedPath(sessionId, "messages");
|
|
29562
|
+
const readIndex = await readScopedJson(
|
|
29563
|
+
geminiHome,
|
|
29564
|
+
join11(parentMsgDir, "read.json"),
|
|
29565
|
+
MAXIMUM_SWARM_OR_READ_INDEX_BYTES,
|
|
29566
|
+
readIndexSchema
|
|
29567
|
+
);
|
|
29568
|
+
if (readIndex === null) {
|
|
29569
|
+
return false;
|
|
29570
|
+
}
|
|
29571
|
+
const entries = await listScopedDirectory(geminiHome, parentMsgDir);
|
|
29572
|
+
if (entries === null) {
|
|
29573
|
+
return false;
|
|
29574
|
+
}
|
|
29575
|
+
let inspected = 0;
|
|
29576
|
+
for (const entry of entries) {
|
|
29577
|
+
if (inspected >= MAXIMUM_MESSAGE_FILES) {
|
|
29578
|
+
break;
|
|
29579
|
+
}
|
|
29580
|
+
if (entry.kind !== "file" || !entry.name.endsWith(".json") || entry.name === "read.json") {
|
|
29581
|
+
continue;
|
|
29582
|
+
}
|
|
29583
|
+
inspected += 1;
|
|
29584
|
+
const messageIdFromName = entry.name.slice(0, -".json".length);
|
|
29585
|
+
if (readIndex[messageIdFromName] === true) {
|
|
29586
|
+
continue;
|
|
29587
|
+
}
|
|
29588
|
+
const message = await readScopedJson(
|
|
29589
|
+
geminiHome,
|
|
29590
|
+
join11(parentMsgDir, entry.name),
|
|
29591
|
+
MAXIMUM_JSON_BYTES,
|
|
29592
|
+
messageRecordSchema
|
|
29593
|
+
);
|
|
29594
|
+
if (message === null) {
|
|
29595
|
+
continue;
|
|
29596
|
+
}
|
|
29597
|
+
const id = message.id ?? messageIdFromName;
|
|
29598
|
+
if (readIndex[id] !== true && message.priority === "MESSAGE_PRIORITY_HIGH") {
|
|
29599
|
+
return true;
|
|
29600
|
+
}
|
|
29601
|
+
}
|
|
29602
|
+
return false;
|
|
29603
|
+
}
|
|
29604
|
+
async function readAntigravityTaskLogSignature(geminiHome, sessionId, nativeTaskIds) {
|
|
29605
|
+
if (geminiHome === void 0 || !SESSION_UUID_PATTERN.test(sessionId)) {
|
|
29606
|
+
return "";
|
|
29607
|
+
}
|
|
29608
|
+
const tasksDir = brainGeneratedPath(sessionId, "tasks");
|
|
29609
|
+
const targets = [];
|
|
29610
|
+
for (const nativeTaskId of nativeTaskIds) {
|
|
29611
|
+
if (TASK_ID_PATTERN.test(nativeTaskId)) {
|
|
29612
|
+
targets.push(`${nativeTaskId}.log`);
|
|
29613
|
+
}
|
|
29614
|
+
}
|
|
29615
|
+
if (targets.length === 0) {
|
|
29616
|
+
const entries = await listScopedDirectory(geminiHome, tasksDir);
|
|
29617
|
+
if (entries === null) {
|
|
29618
|
+
return "";
|
|
29619
|
+
}
|
|
29620
|
+
for (const entry of entries) {
|
|
29621
|
+
if (entry.kind === "file" && /^task-\d+\.log$/u.test(entry.name)) {
|
|
29622
|
+
targets.push(entry.name);
|
|
29623
|
+
}
|
|
29624
|
+
}
|
|
29625
|
+
}
|
|
29626
|
+
targets.sort();
|
|
29627
|
+
const parts = [];
|
|
29628
|
+
for (const fileName of targets.slice(0, MAXIMUM_TASK_LOG_FILES)) {
|
|
29629
|
+
const stats = await statScopedFile(geminiHome, join11(tasksDir, fileName));
|
|
29630
|
+
if (stats !== null) {
|
|
29631
|
+
parts.push(`${fileName}:${String(stats.size)}:${String(Math.trunc(stats.modifiedMilliseconds))}`);
|
|
29632
|
+
}
|
|
29633
|
+
}
|
|
29634
|
+
return parts.join("|");
|
|
29635
|
+
}
|
|
29636
|
+
function extractReadableErrorFromBlob(blob2) {
|
|
29637
|
+
const decoded = new TextDecoder("utf-8", { fatal: false }).decode(blob2);
|
|
29638
|
+
const printableRuns = decoded.match(/[\x20-\x7e]{8,}/gu) ?? [];
|
|
29639
|
+
const informative = printableRuns.map((run) => run.trim()).filter((run) => /[a-zA-Z]{3,}/u.test(run)).sort((left, right) => right.length - left.length)[0];
|
|
29640
|
+
if (informative === void 0 || informative.length === 0) {
|
|
29641
|
+
return "Antigravity recorded an internal execution error";
|
|
29642
|
+
}
|
|
29643
|
+
return truncate(informative, MAXIMUM_ERROR_TEXT_CHARS);
|
|
29644
|
+
}
|
|
29645
|
+
async function readAntigravityConversationTerminalError(geminiHome, sessionId) {
|
|
29646
|
+
if (geminiHome === void 0 || !SESSION_UUID_PATTERN.test(sessionId)) {
|
|
29647
|
+
return null;
|
|
29648
|
+
}
|
|
29649
|
+
const row = await queryScopedSqliteRow(
|
|
29650
|
+
geminiHome,
|
|
29651
|
+
join11("antigravity-cli", "conversations", `${sessionId}.db`),
|
|
29652
|
+
"SELECT status, error_details FROM steps ORDER BY idx DESC LIMIT 1"
|
|
29653
|
+
);
|
|
29654
|
+
const parsed = conversationDbStepRowSchema.safeParse(row);
|
|
29655
|
+
if (!parsed.success) {
|
|
29656
|
+
return null;
|
|
29657
|
+
}
|
|
29658
|
+
const details = parsed.data.error_details;
|
|
29659
|
+
if (details === null || details === void 0 || details.byteLength === 0) {
|
|
29660
|
+
return null;
|
|
29661
|
+
}
|
|
29662
|
+
return extractReadableErrorFromBlob(details);
|
|
29663
|
+
}
|
|
29664
|
+
|
|
29129
29665
|
// src/engine/acp/adapter/antigravity/background-wakeup.ts
|
|
29130
29666
|
var TRANSCRIPT_TAIL_BYTES = 65536;
|
|
29131
29667
|
var SUBAGENT_RECONCILE_TAIL_BYTES = 1048576;
|
|
@@ -29133,7 +29669,11 @@ var TRANSCRIPT_INITIAL_DELAY_MS = 40;
|
|
|
29133
29669
|
var TRANSCRIPT_POLL_INTERVAL_MS = 150;
|
|
29134
29670
|
var MAX_PARTIAL_SETTLED_TEXT_DEFERRALS = 2;
|
|
29135
29671
|
var WAKEUP_INACTIVITY_TIMEOUT_MS = 3e5;
|
|
29136
|
-
var
|
|
29672
|
+
var WATCHDOG_SLICE_MS = 6e4;
|
|
29673
|
+
var ORPHAN_SHELL_SILENCE_SLICES = 5;
|
|
29674
|
+
var ORPHAN_SHELL_MAX_HOLD_SLICES = 30;
|
|
29675
|
+
var OPEN_PROMPT_INACTIVITY_SLICES = 15;
|
|
29676
|
+
var SESSION_UUID_PATTERN2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu;
|
|
29137
29677
|
var SUBAGENT_CONVERSATION_ID_PATTERN = /"conversationId"\s*:\s*"([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})"/giu;
|
|
29138
29678
|
var SUBAGENT_IDLE_ID_PATTERN = /\bSubagent ([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}) (?:has gone|went) idle\b/giu;
|
|
29139
29679
|
var SUBAGENT_MESSAGE_SENDER_PATTERN = /^\[Message\]\s+timestamp=\S+\s+sender=([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?!\/)\b/gimu;
|
|
@@ -29178,10 +29718,10 @@ function resolveGeminiHome(launchEnvironment) {
|
|
|
29178
29718
|
return configured;
|
|
29179
29719
|
}
|
|
29180
29720
|
const home = launchEnvironment["HOME"]?.trim() || launchEnvironment["USERPROFILE"]?.trim() || homedir();
|
|
29181
|
-
return home.length > 0 ?
|
|
29721
|
+
return home.length > 0 ? join12(home, ".gemini") : void 0;
|
|
29182
29722
|
}
|
|
29183
29723
|
async function readTranscriptTailState(launchEnvironment, sessionId, baselineStepIndex, maximumBytes = TRANSCRIPT_TAIL_BYTES) {
|
|
29184
|
-
if (!
|
|
29724
|
+
if (!SESSION_UUID_PATTERN2.test(sessionId)) {
|
|
29185
29725
|
return null;
|
|
29186
29726
|
}
|
|
29187
29727
|
const geminiHome = resolveGeminiHome(launchEnvironment);
|
|
@@ -29190,7 +29730,7 @@ async function readTranscriptTailState(launchEnvironment, sessionId, baselineSte
|
|
|
29190
29730
|
}
|
|
29191
29731
|
const tail = await readScopedFileTail(
|
|
29192
29732
|
geminiHome,
|
|
29193
|
-
|
|
29733
|
+
join12("antigravity-cli", "brain", sessionId, ".system_generated", "logs", "transcript.jsonl"),
|
|
29194
29734
|
maximumBytes
|
|
29195
29735
|
);
|
|
29196
29736
|
if (tail === null) {
|
|
@@ -29300,6 +29840,12 @@ function readToolCategory(update, inputs, previous) {
|
|
|
29300
29840
|
if (name2 === "manage_subagents") {
|
|
29301
29841
|
return "manage-subagents";
|
|
29302
29842
|
}
|
|
29843
|
+
if (name2 === "manage_task") {
|
|
29844
|
+
return "manage-task";
|
|
29845
|
+
}
|
|
29846
|
+
if (name2 === "swarm") {
|
|
29847
|
+
return "swarm";
|
|
29848
|
+
}
|
|
29303
29849
|
const title = readString3(update, "title");
|
|
29304
29850
|
if (title === "Run invoke_subagent" || title === "Running invoke_subagent" || title === "Run invoke_subagent?" || title === "Running start_subagent" || title === "Run start_subagent?") {
|
|
29305
29851
|
return "subagent";
|
|
@@ -29310,6 +29856,12 @@ function readToolCategory(update, inputs, previous) {
|
|
|
29310
29856
|
if (title === "Run manage_subagents") {
|
|
29311
29857
|
return "manage-subagents";
|
|
29312
29858
|
}
|
|
29859
|
+
if (title === "Run manage_task" || title === "Running manage_task") {
|
|
29860
|
+
return "manage-task";
|
|
29861
|
+
}
|
|
29862
|
+
if (title === "Run swarm" || title === "Running swarm") {
|
|
29863
|
+
return "swarm";
|
|
29864
|
+
}
|
|
29313
29865
|
if (previous?.category !== void 0 && previous.category !== null) {
|
|
29314
29866
|
return previous.category;
|
|
29315
29867
|
}
|
|
@@ -29318,12 +29870,25 @@ function readToolCategory(update, inputs, previous) {
|
|
|
29318
29870
|
}
|
|
29319
29871
|
return null;
|
|
29320
29872
|
}
|
|
29873
|
+
function normalizeManageTaskKillId(rawTaskId) {
|
|
29874
|
+
if (rawTaskId === void 0) {
|
|
29875
|
+
return void 0;
|
|
29876
|
+
}
|
|
29877
|
+
const trimmed = rawTaskId.trim();
|
|
29878
|
+
if (trimmed.length === 0) {
|
|
29879
|
+
return void 0;
|
|
29880
|
+
}
|
|
29881
|
+
const slashIndex = trimmed.lastIndexOf("/");
|
|
29882
|
+
return slashIndex === -1 ? trimmed : trimmed.slice(slashIndex + 1);
|
|
29883
|
+
}
|
|
29321
29884
|
function inspectToolMetadata(update, previous) {
|
|
29322
29885
|
const inputs = extractToolInputRecords(update);
|
|
29323
29886
|
const category = readToolCategory(update, inputs, previous);
|
|
29324
29887
|
let isDaemon = previous?.isDaemon ?? false;
|
|
29325
29888
|
const subagentKillIds = new Set(previous?.subagentKillIds ?? []);
|
|
29326
29889
|
let subagentKillAll = previous?.subagentKillAll ?? false;
|
|
29890
|
+
let killTaskId = previous?.killTaskId;
|
|
29891
|
+
let swarmAction = previous?.swarmAction;
|
|
29327
29892
|
for (const record2 of inputs) {
|
|
29328
29893
|
if (record2["IsDaemon"] === true) {
|
|
29329
29894
|
isDaemon = true;
|
|
@@ -29347,16 +29912,30 @@ function inspectToolMetadata(update, previous) {
|
|
|
29347
29912
|
}
|
|
29348
29913
|
}
|
|
29349
29914
|
}
|
|
29915
|
+
if (category === "manage-task") {
|
|
29916
|
+
const action = readString3(record2, "Action");
|
|
29917
|
+
if (action === "kill") {
|
|
29918
|
+
killTaskId = normalizeManageTaskKillId(readString3(record2, "TaskId")) ?? killTaskId;
|
|
29919
|
+
}
|
|
29920
|
+
}
|
|
29921
|
+
if (category === "swarm") {
|
|
29922
|
+
const action = readString3(record2, "action");
|
|
29923
|
+
if (action === "add" || action === "kill") {
|
|
29924
|
+
swarmAction = action;
|
|
29925
|
+
}
|
|
29926
|
+
}
|
|
29350
29927
|
}
|
|
29351
29928
|
const matchText = readInputString(inputs, "CommandLine") ?? readInputString(inputs, "Prompt") ?? readInputString(inputs, "Description") ?? previous?.matchText;
|
|
29352
|
-
const description = readInputString(inputs, "toolSummary") ?? readInputString(inputs, "Description") ?? readInputString(inputs, "Role") ?? readInputString(inputs, "CommandLine") ?? readInputString(inputs, "Prompt") ?? readString3(update, "title") ?? previous?.description;
|
|
29929
|
+
const description = readInputString(inputs, "toolSummary") ?? readInputString(inputs, "Description") ?? readInputString(inputs, "Role") ?? readInputString(inputs, "name") ?? readInputString(inputs, "CommandLine") ?? readInputString(inputs, "Prompt") ?? readString3(update, "title") ?? previous?.description;
|
|
29353
29930
|
return {
|
|
29354
29931
|
category,
|
|
29355
29932
|
description: description === void 0 ? void 0 : truncate(description, MAXIMUM_TOOL_DESCRIPTION_CHARS),
|
|
29356
29933
|
isDaemon,
|
|
29934
|
+
killTaskId,
|
|
29357
29935
|
matchText,
|
|
29358
29936
|
subagentKillAll,
|
|
29359
|
-
subagentKillIds: [...subagentKillIds]
|
|
29937
|
+
subagentKillIds: [...subagentKillIds],
|
|
29938
|
+
swarmAction
|
|
29360
29939
|
};
|
|
29361
29940
|
}
|
|
29362
29941
|
function isBackgroundableCategory(category) {
|
|
@@ -29450,6 +30029,28 @@ function extractTaskResultSenderIds(sessionId, steps, minStepExclusive, maxStepI
|
|
|
29450
30029
|
}
|
|
29451
30030
|
return received;
|
|
29452
30031
|
}
|
|
30032
|
+
var RESTART_SYSTEM_MESSAGE_MARKER2 = "All your subagents and background tasks have been stopped due to server restart";
|
|
30033
|
+
function findTrailingSettledReply(steps, minStepExclusive) {
|
|
30034
|
+
for (let index2 = steps.length - 1; index2 >= 0; index2 -= 1) {
|
|
30035
|
+
const step = steps[index2];
|
|
30036
|
+
if (step === void 0 || step.step_index <= minStepExclusive) {
|
|
30037
|
+
break;
|
|
30038
|
+
}
|
|
30039
|
+
if (step.type === "USER_INPUT") {
|
|
30040
|
+
return null;
|
|
30041
|
+
}
|
|
30042
|
+
if (step.type === "SYSTEM_MESSAGE" && !(step.content?.includes(RESTART_SYSTEM_MESSAGE_MARKER2) ?? false)) {
|
|
30043
|
+
return null;
|
|
30044
|
+
}
|
|
30045
|
+
if (step.type === "PLANNER_RESPONSE") {
|
|
30046
|
+
if (step.status === "DONE" && (step.tool_calls === void 0 || step.tool_calls.length === 0)) {
|
|
30047
|
+
return { content: step.content, stepIndex: step.step_index };
|
|
30048
|
+
}
|
|
30049
|
+
return null;
|
|
30050
|
+
}
|
|
30051
|
+
}
|
|
30052
|
+
return null;
|
|
30053
|
+
}
|
|
29453
30054
|
function backgroundKindFor(category) {
|
|
29454
30055
|
switch (category) {
|
|
29455
30056
|
case "command":
|
|
@@ -29460,6 +30061,8 @@ function backgroundKindFor(category) {
|
|
|
29460
30061
|
case "workflow":
|
|
29461
30062
|
return "other";
|
|
29462
30063
|
case "manage-subagents":
|
|
30064
|
+
case "manage-task":
|
|
30065
|
+
case "swarm":
|
|
29463
30066
|
case null:
|
|
29464
30067
|
return null;
|
|
29465
30068
|
}
|
|
@@ -29491,6 +30094,8 @@ function isWakeupChunkUpdateKind(updateKind) {
|
|
|
29491
30094
|
var AntigravityBackgroundWakeup = class {
|
|
29492
30095
|
#emitMetaUpdate;
|
|
29493
30096
|
#launchEnvironment;
|
|
30097
|
+
#onOpenPromptTimeout;
|
|
30098
|
+
#onOrphanShellPromptSettle;
|
|
29494
30099
|
#timer;
|
|
29495
30100
|
#sessions = /* @__PURE__ */ new Map();
|
|
29496
30101
|
#pendingRequests = /* @__PURE__ */ new Map();
|
|
@@ -29498,6 +30103,8 @@ var AntigravityBackgroundWakeup = class {
|
|
|
29498
30103
|
constructor(options) {
|
|
29499
30104
|
this.#emitMetaUpdate = options.emitMetaUpdate;
|
|
29500
30105
|
this.#launchEnvironment = options.launchEnvironment;
|
|
30106
|
+
this.#onOpenPromptTimeout = options.onOpenPromptTimeout;
|
|
30107
|
+
this.#onOrphanShellPromptSettle = options.onOrphanShellPromptSettle;
|
|
29501
30108
|
this.#timer = options.timer ?? systemTimer;
|
|
29502
30109
|
}
|
|
29503
30110
|
#ensureSession = (sessionId) => {
|
|
@@ -29518,6 +30125,7 @@ var AntigravityBackgroundWakeup = class {
|
|
|
29518
30125
|
backgroundTasks: /* @__PURE__ */ new Map(),
|
|
29519
30126
|
baselineStepIndex: -1,
|
|
29520
30127
|
lastEmittedBackgroundKey: "[]",
|
|
30128
|
+
openNonShellToolIds: /* @__PURE__ */ new Set(),
|
|
29521
30129
|
phase: { cancelRequested: false, kind: "idle" },
|
|
29522
30130
|
sessionOpenStepIndex: -1,
|
|
29523
30131
|
subagents: {
|
|
@@ -29533,11 +30141,362 @@ var AntigravityBackgroundWakeup = class {
|
|
|
29533
30141
|
wakeupOwedToolCallIds: /* @__PURE__ */ new Set(),
|
|
29534
30142
|
wakeupSettledStepIndex: null,
|
|
29535
30143
|
wakeupStageSeq: 0,
|
|
29536
|
-
wakeupStreamedMessageText: ""
|
|
30144
|
+
wakeupStreamedMessageText: "",
|
|
30145
|
+
watchdog: null,
|
|
30146
|
+
watchdogSeq: 0
|
|
29537
30147
|
};
|
|
29538
30148
|
this.#sessions.set(sessionId, created);
|
|
29539
30149
|
return created;
|
|
29540
30150
|
};
|
|
30151
|
+
#cancelWatchdog = (session) => {
|
|
30152
|
+
if (session.watchdog !== null) {
|
|
30153
|
+
session.watchdog.task.cancel();
|
|
30154
|
+
session.watchdog = null;
|
|
30155
|
+
}
|
|
30156
|
+
session.watchdogSeq += 1;
|
|
30157
|
+
};
|
|
30158
|
+
#isShellOnlyBackground = (session) => {
|
|
30159
|
+
if (session.backgroundTasks.size === 0) {
|
|
30160
|
+
return false;
|
|
30161
|
+
}
|
|
30162
|
+
for (const task of session.backgroundTasks.values()) {
|
|
30163
|
+
if (task.kind !== "shell" || task.state !== "running") {
|
|
30164
|
+
return false;
|
|
30165
|
+
}
|
|
30166
|
+
}
|
|
30167
|
+
return true;
|
|
30168
|
+
};
|
|
30169
|
+
#activeShellNativeTaskIds = (session) => {
|
|
30170
|
+
const ids = [];
|
|
30171
|
+
for (const [toolCallId, task] of session.backgroundTasks) {
|
|
30172
|
+
if (task.kind !== "shell") {
|
|
30173
|
+
continue;
|
|
30174
|
+
}
|
|
30175
|
+
const nativeTaskId = session.backgroundCorrelation.nativeTaskIdByToolCallId.get(toolCallId);
|
|
30176
|
+
if (nativeTaskId !== void 0) {
|
|
30177
|
+
ids.push(nativeTaskId);
|
|
30178
|
+
}
|
|
30179
|
+
}
|
|
30180
|
+
return ids;
|
|
30181
|
+
};
|
|
30182
|
+
#killBackgroundTaskByNativeId = (session, killTaskId) => {
|
|
30183
|
+
const mappedToolCallId = session.backgroundCorrelation.toolCallIdByNativeTaskId.get(killTaskId);
|
|
30184
|
+
if (mappedToolCallId !== void 0 && session.backgroundTasks.has(mappedToolCallId)) {
|
|
30185
|
+
this.#deleteBackgroundTask(session, mappedToolCallId);
|
|
30186
|
+
return true;
|
|
30187
|
+
}
|
|
30188
|
+
if (session.backgroundTasks.has(killTaskId)) {
|
|
30189
|
+
this.#deleteBackgroundTask(session, killTaskId);
|
|
30190
|
+
return true;
|
|
30191
|
+
}
|
|
30192
|
+
return false;
|
|
30193
|
+
};
|
|
30194
|
+
#reconcileStructuredArtifacts = async (sessionId, session, lastTranscriptStep, clearCompletedBackground) => {
|
|
30195
|
+
const geminiHome = resolveGeminiHome(this.#launchEnvironment);
|
|
30196
|
+
const snapshot = await readAntigravitySubagentSnapshot(geminiHome, sessionId);
|
|
30197
|
+
if (this.#disposed || this.#sessions.get(sessionId) !== session) {
|
|
30198
|
+
return false;
|
|
30199
|
+
}
|
|
30200
|
+
for (const [toolCallId, childId] of snapshot.conversationIdByToolCallId) {
|
|
30201
|
+
if (session.backgroundTasks.has(toolCallId)) {
|
|
30202
|
+
session.subagents.conversationIdByToolCallId.set(toolCallId, childId);
|
|
30203
|
+
const pendingIndex = session.subagents.pendingToolCallIds.indexOf(toolCallId);
|
|
30204
|
+
if (pendingIndex !== -1) {
|
|
30205
|
+
session.subagents.pendingToolCallIds.splice(pendingIndex, 1);
|
|
30206
|
+
}
|
|
30207
|
+
}
|
|
30208
|
+
}
|
|
30209
|
+
for (const nativeTaskId of snapshot.deliveredNativeTaskIds) {
|
|
30210
|
+
session.backgroundCorrelation.deliveredNativeTaskIds.add(nativeTaskId);
|
|
30211
|
+
}
|
|
30212
|
+
if (!clearCompletedBackground) {
|
|
30213
|
+
return true;
|
|
30214
|
+
}
|
|
30215
|
+
for (const [toolCallId, task] of [...session.backgroundTasks.entries()]) {
|
|
30216
|
+
if (task.kind === "subagent") {
|
|
30217
|
+
const childId = session.subagents.conversationIdByToolCallId.get(toolCallId);
|
|
30218
|
+
if (childId !== void 0 && snapshot.resolvedChildIds.has(childId)) {
|
|
30219
|
+
this.#deleteSubagentTask(session, toolCallId);
|
|
30220
|
+
}
|
|
30221
|
+
continue;
|
|
30222
|
+
}
|
|
30223
|
+
const nativeTaskId = session.backgroundCorrelation.nativeTaskIdByToolCallId.get(toolCallId);
|
|
30224
|
+
if (snapshot.deliveredToolCallIds.has(toolCallId) || nativeTaskId !== void 0 && snapshot.deliveredNativeTaskIds.has(nativeTaskId)) {
|
|
30225
|
+
this.#deleteBackgroundTask(session, toolCallId);
|
|
30226
|
+
}
|
|
30227
|
+
}
|
|
30228
|
+
if (snapshot.available && snapshot.activeChildIds.size === 0 && this.#hasSubagentTasks(session)) {
|
|
30229
|
+
const pendingReply = await readAntigravityPendingReply(geminiHome, sessionId, lastTranscriptStep);
|
|
30230
|
+
if (this.#disposed || this.#sessions.get(sessionId) !== session) {
|
|
30231
|
+
return false;
|
|
30232
|
+
}
|
|
30233
|
+
if (!pendingReply) {
|
|
30234
|
+
this.#deleteAllSubagentTasks(session);
|
|
30235
|
+
}
|
|
30236
|
+
}
|
|
30237
|
+
return true;
|
|
30238
|
+
};
|
|
30239
|
+
#inspectPostReplyShellState = async (sessionId, session) => {
|
|
30240
|
+
if (session.activeInteractions > 0 || session.openNonShellToolIds.size > 0 || !this.#isShellOnlyBackground(session)) {
|
|
30241
|
+
return { kind: "not-applicable" };
|
|
30242
|
+
}
|
|
30243
|
+
if (session.phase.kind === "client-prompt" && session.phase.cancelled) {
|
|
30244
|
+
return { kind: "not-applicable" };
|
|
30245
|
+
}
|
|
30246
|
+
if (session.phase.kind === "idle" && session.phase.cancelRequested) {
|
|
30247
|
+
return { kind: "not-applicable" };
|
|
30248
|
+
}
|
|
30249
|
+
if (session.phase.kind !== "client-prompt" && session.phase.kind !== "idle") {
|
|
30250
|
+
return { kind: "not-applicable" };
|
|
30251
|
+
}
|
|
30252
|
+
const prePromptStepIndex = session.phase.kind === "client-prompt" ? session.phase.prePromptStepIndex : session.baselineStepIndex;
|
|
30253
|
+
const tail = await readTranscriptTailState(this.#launchEnvironment, sessionId, prePromptStepIndex);
|
|
30254
|
+
if (this.#disposed || this.#sessions.get(sessionId) !== session) {
|
|
30255
|
+
return { kind: "not-applicable" };
|
|
30256
|
+
}
|
|
30257
|
+
if (tail !== null) {
|
|
30258
|
+
this.#syncBackgroundTaskCreations(sessionId, session, tail.steps);
|
|
30259
|
+
}
|
|
30260
|
+
if (session.phase.kind === "client-prompt") {
|
|
30261
|
+
if (tail === null || findTrailingSettledReply(tail.steps, session.phase.prePromptStepIndex) === null) {
|
|
30262
|
+
return { kind: "not-applicable" };
|
|
30263
|
+
}
|
|
30264
|
+
}
|
|
30265
|
+
const geminiHome = resolveGeminiHome(this.#launchEnvironment);
|
|
30266
|
+
const snapshot = await readAntigravitySubagentSnapshot(geminiHome, sessionId);
|
|
30267
|
+
if (this.#disposed || this.#sessions.get(sessionId) !== session || snapshot.activeChildIds.size > 0) {
|
|
30268
|
+
return { kind: "not-applicable" };
|
|
30269
|
+
}
|
|
30270
|
+
const pendingReply = await readAntigravityPendingReply(geminiHome, sessionId, tail?.steps.at(-1));
|
|
30271
|
+
if (this.#disposed || this.#sessions.get(sessionId) !== session || pendingReply) {
|
|
30272
|
+
return { kind: "not-applicable" };
|
|
30273
|
+
}
|
|
30274
|
+
const logSignature = await readAntigravityTaskLogSignature(
|
|
30275
|
+
geminiHome,
|
|
30276
|
+
sessionId,
|
|
30277
|
+
this.#activeShellNativeTaskIds(session)
|
|
30278
|
+
);
|
|
30279
|
+
if (this.#disposed || this.#sessions.get(sessionId) !== session) {
|
|
30280
|
+
return { kind: "not-applicable" };
|
|
30281
|
+
}
|
|
30282
|
+
return { kind: "shell-only-after-reply", logSignature };
|
|
30283
|
+
};
|
|
30284
|
+
#armClientPromptWatchdog = (sessionId, session) => {
|
|
30285
|
+
this.#cancelWatchdog(session);
|
|
30286
|
+
const epoch = session.watchdogSeq;
|
|
30287
|
+
const scheduleNext = () => this.#timer.schedule(() => {
|
|
30288
|
+
void this.#handleClientPromptWatchdogTick(sessionId, session, epoch);
|
|
30289
|
+
}, WATCHDOG_SLICE_MS);
|
|
30290
|
+
session.watchdog = {
|
|
30291
|
+
epoch,
|
|
30292
|
+
inactivitySlices: 0,
|
|
30293
|
+
kind: "client-prompt",
|
|
30294
|
+
lastLogSignature: null,
|
|
30295
|
+
sawAcpActivity: false,
|
|
30296
|
+
shellHoldSlices: 0,
|
|
30297
|
+
silentShellSlices: 0,
|
|
30298
|
+
task: scheduleNext()
|
|
30299
|
+
};
|
|
30300
|
+
};
|
|
30301
|
+
#syncIdleShellWatchdog = (sessionId, session) => {
|
|
30302
|
+
const shouldArm = session.phase.kind === "idle" && !session.phase.cancelRequested && session.activeInteractions === 0 && this.#isShellOnlyBackground(session);
|
|
30303
|
+
if (!shouldArm) {
|
|
30304
|
+
if (session.watchdog?.kind === "idle-shell") {
|
|
30305
|
+
this.#cancelWatchdog(session);
|
|
30306
|
+
}
|
|
30307
|
+
return;
|
|
30308
|
+
}
|
|
30309
|
+
if (session.watchdog?.kind === "idle-shell") {
|
|
30310
|
+
return;
|
|
30311
|
+
}
|
|
30312
|
+
this.#cancelWatchdog(session);
|
|
30313
|
+
const epoch = session.watchdogSeq;
|
|
30314
|
+
session.watchdog = {
|
|
30315
|
+
epoch,
|
|
30316
|
+
kind: "idle-shell",
|
|
30317
|
+
lastLogSignature: null,
|
|
30318
|
+
shellHoldSlices: 0,
|
|
30319
|
+
silentShellSlices: 0,
|
|
30320
|
+
task: this.#timer.schedule(() => {
|
|
30321
|
+
void this.#handleIdleShellWatchdogTick(sessionId, session, epoch);
|
|
30322
|
+
}, WATCHDOG_SLICE_MS)
|
|
30323
|
+
};
|
|
30324
|
+
};
|
|
30325
|
+
#handleClientPromptWatchdogTick = async (sessionId, session, epoch) => {
|
|
30326
|
+
if (this.#disposed || this.#sessions.get(sessionId) !== session) {
|
|
30327
|
+
return;
|
|
30328
|
+
}
|
|
30329
|
+
const handle = session.watchdog;
|
|
30330
|
+
if (handle === null || handle.kind !== "client-prompt" || handle.epoch !== epoch || session.phase.kind !== "client-prompt" || session.phase.cancelled) {
|
|
30331
|
+
return;
|
|
30332
|
+
}
|
|
30333
|
+
const reschedule = () => {
|
|
30334
|
+
if (this.#disposed || this.#sessions.get(sessionId) !== session || session.watchdog !== handle || handle.epoch !== epoch || session.phase.kind !== "client-prompt" || session.phase.cancelled) {
|
|
30335
|
+
return;
|
|
30336
|
+
}
|
|
30337
|
+
handle.task = this.#timer.schedule(() => {
|
|
30338
|
+
void this.#handleClientPromptWatchdogTick(sessionId, session, epoch);
|
|
30339
|
+
}, WATCHDOG_SLICE_MS);
|
|
30340
|
+
};
|
|
30341
|
+
const hadAcpActivity = handle.sawAcpActivity;
|
|
30342
|
+
handle.sawAcpActivity = false;
|
|
30343
|
+
if (session.activeInteractions > 0) {
|
|
30344
|
+
handle.inactivitySlices = 0;
|
|
30345
|
+
handle.silentShellSlices = 0;
|
|
30346
|
+
reschedule();
|
|
30347
|
+
return;
|
|
30348
|
+
}
|
|
30349
|
+
const shellState = await this.#inspectPostReplyShellState(sessionId, session);
|
|
30350
|
+
if (this.#disposed || this.#sessions.get(sessionId) !== session || session.watchdog !== handle || handle.epoch !== epoch || session.phase.kind !== "client-prompt" || session.phase.cancelled) {
|
|
30351
|
+
return;
|
|
30352
|
+
}
|
|
30353
|
+
if (shellState.kind === "shell-only-after-reply") {
|
|
30354
|
+
handle.inactivitySlices = 0;
|
|
30355
|
+
handle.shellHoldSlices += 1;
|
|
30356
|
+
const logChanged = handle.lastLogSignature !== null && shellState.logSignature !== handle.lastLogSignature;
|
|
30357
|
+
handle.lastLogSignature = shellState.logSignature;
|
|
30358
|
+
if (hadAcpActivity || logChanged) {
|
|
30359
|
+
handle.silentShellSlices = 0;
|
|
30360
|
+
} else {
|
|
30361
|
+
handle.silentShellSlices += 1;
|
|
30362
|
+
}
|
|
30363
|
+
if (handle.silentShellSlices >= ORPHAN_SHELL_SILENCE_SLICES || handle.shellHoldSlices >= ORPHAN_SHELL_MAX_HOLD_SLICES) {
|
|
30364
|
+
this.#cancelWatchdog(session);
|
|
30365
|
+
this.#onOrphanShellPromptSettle?.(sessionId);
|
|
30366
|
+
return;
|
|
30367
|
+
}
|
|
30368
|
+
reschedule();
|
|
30369
|
+
return;
|
|
30370
|
+
}
|
|
30371
|
+
handle.shellHoldSlices = 0;
|
|
30372
|
+
handle.silentShellSlices = 0;
|
|
30373
|
+
handle.lastLogSignature = null;
|
|
30374
|
+
if (!hadAcpActivity && session.openNonShellToolIds.size === 0 && session.backgroundTasks.size === 0 && session.activeInteractions === 0) {
|
|
30375
|
+
handle.inactivitySlices += 1;
|
|
30376
|
+
if (handle.inactivitySlices >= OPEN_PROMPT_INACTIVITY_SLICES) {
|
|
30377
|
+
const geminiHome = resolveGeminiHome(this.#launchEnvironment);
|
|
30378
|
+
const snapshot = await readAntigravitySubagentSnapshot(geminiHome, sessionId);
|
|
30379
|
+
if (this.#disposed || this.#sessions.get(sessionId) !== session || session.watchdog !== handle || handle.epoch !== epoch || session.phase.kind !== "client-prompt" || session.phase.cancelled) {
|
|
30380
|
+
return;
|
|
30381
|
+
}
|
|
30382
|
+
if (snapshot.activeChildIds.size > 0) {
|
|
30383
|
+
handle.inactivitySlices = 0;
|
|
30384
|
+
reschedule();
|
|
30385
|
+
return;
|
|
30386
|
+
}
|
|
30387
|
+
const prePromptStepIndex = session.phase.prePromptStepIndex;
|
|
30388
|
+
const tail = await readTranscriptTailState(this.#launchEnvironment, sessionId, prePromptStepIndex);
|
|
30389
|
+
const pendingReply = await readAntigravityPendingReply(geminiHome, sessionId, tail?.steps.at(-1));
|
|
30390
|
+
if (this.#disposed || this.#sessions.get(sessionId) !== session || session.watchdog !== handle || handle.epoch !== epoch || session.phase.kind !== "client-prompt" || session.phase.cancelled) {
|
|
30391
|
+
return;
|
|
30392
|
+
}
|
|
30393
|
+
if (tail !== null && findTrailingSettledReply(tail.steps, prePromptStepIndex) !== null && !pendingReply) {
|
|
30394
|
+
this.#cancelWatchdog(session);
|
|
30395
|
+
this.#onOpenPromptTimeout?.(sessionId, { kind: "settled" });
|
|
30396
|
+
return;
|
|
30397
|
+
}
|
|
30398
|
+
const recordedError = await readAntigravityConversationTerminalError(geminiHome, sessionId);
|
|
30399
|
+
if (this.#disposed || this.#sessions.get(sessionId) !== session || session.watchdog !== handle || handle.epoch !== epoch || session.phase.kind !== "client-prompt" || session.phase.cancelled) {
|
|
30400
|
+
return;
|
|
30401
|
+
}
|
|
30402
|
+
this.#cancelWatchdog(session);
|
|
30403
|
+
this.#onOpenPromptTimeout?.(sessionId, {
|
|
30404
|
+
kind: "failed",
|
|
30405
|
+
message: recordedError ?? "Antigravity stopped responding during the turn"
|
|
30406
|
+
});
|
|
30407
|
+
return;
|
|
30408
|
+
}
|
|
30409
|
+
} else {
|
|
30410
|
+
handle.inactivitySlices = 0;
|
|
30411
|
+
}
|
|
30412
|
+
reschedule();
|
|
30413
|
+
};
|
|
30414
|
+
#handleIdleShellWatchdogTick = async (sessionId, session, epoch) => {
|
|
30415
|
+
if (this.#disposed || this.#sessions.get(sessionId) !== session) {
|
|
30416
|
+
return;
|
|
30417
|
+
}
|
|
30418
|
+
const handle = session.watchdog;
|
|
30419
|
+
if (handle === null || handle.kind !== "idle-shell" || handle.epoch !== epoch || session.phase.kind !== "idle" || session.phase.cancelRequested) {
|
|
30420
|
+
return;
|
|
30421
|
+
}
|
|
30422
|
+
const reschedule = () => {
|
|
30423
|
+
if (this.#disposed || this.#sessions.get(sessionId) !== session || session.watchdog !== handle || handle.epoch !== epoch || session.phase.kind !== "idle" || session.phase.cancelRequested) {
|
|
30424
|
+
return;
|
|
30425
|
+
}
|
|
30426
|
+
handle.task = this.#timer.schedule(() => {
|
|
30427
|
+
void this.#handleIdleShellWatchdogTick(sessionId, session, epoch);
|
|
30428
|
+
}, WATCHDOG_SLICE_MS);
|
|
30429
|
+
};
|
|
30430
|
+
const shellState = await this.#inspectPostReplyShellState(sessionId, session);
|
|
30431
|
+
if (this.#disposed || this.#sessions.get(sessionId) !== session || session.watchdog !== handle || handle.epoch !== epoch || session.phase.kind !== "idle" || session.phase.cancelRequested) {
|
|
30432
|
+
return;
|
|
30433
|
+
}
|
|
30434
|
+
if (shellState.kind !== "shell-only-after-reply") {
|
|
30435
|
+
handle.silentShellSlices = 0;
|
|
30436
|
+
reschedule();
|
|
30437
|
+
return;
|
|
30438
|
+
}
|
|
30439
|
+
handle.shellHoldSlices += 1;
|
|
30440
|
+
const logChanged = handle.lastLogSignature !== null && shellState.logSignature !== handle.lastLogSignature;
|
|
30441
|
+
handle.lastLogSignature = shellState.logSignature;
|
|
30442
|
+
if (logChanged) {
|
|
30443
|
+
handle.silentShellSlices = 0;
|
|
30444
|
+
} else {
|
|
30445
|
+
handle.silentShellSlices += 1;
|
|
30446
|
+
}
|
|
30447
|
+
if (handle.silentShellSlices >= ORPHAN_SHELL_SILENCE_SLICES || handle.shellHoldSlices >= ORPHAN_SHELL_MAX_HOLD_SLICES) {
|
|
30448
|
+
this.#cancelWatchdog(session);
|
|
30449
|
+
for (const [toolCallId, task] of [...session.backgroundTasks.entries()]) {
|
|
30450
|
+
if (task.kind === "shell") {
|
|
30451
|
+
this.#deleteBackgroundTask(session, toolCallId);
|
|
30452
|
+
}
|
|
30453
|
+
}
|
|
30454
|
+
const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
|
|
30455
|
+
if (bg2 !== null) {
|
|
30456
|
+
this.#emitMetaUpdate(bg2);
|
|
30457
|
+
}
|
|
30458
|
+
return;
|
|
30459
|
+
}
|
|
30460
|
+
reschedule();
|
|
30461
|
+
};
|
|
30462
|
+
/**
|
|
30463
|
+
* Whether `sessionId` currently has an open client prompt whose final reply is already settled
|
|
30464
|
+
* in the native transcript and is only kept open by non-daemon background shell command(s).
|
|
30465
|
+
*/
|
|
30466
|
+
isReplyDoneWithOnlyShellTasks = async (sessionId) => {
|
|
30467
|
+
if (this.#disposed) {
|
|
30468
|
+
return false;
|
|
30469
|
+
}
|
|
30470
|
+
const session = this.#sessions.get(sessionId);
|
|
30471
|
+
if (session === void 0 || session.phase.kind !== "client-prompt" || session.phase.cancelled) {
|
|
30472
|
+
return false;
|
|
30473
|
+
}
|
|
30474
|
+
return (await this.#inspectPostReplyShellState(sessionId, session)).kind === "shell-only-after-reply";
|
|
30475
|
+
};
|
|
30476
|
+
/**
|
|
30477
|
+
* Transitions a client prompt that the proxy settled directly back to idle and clears its
|
|
30478
|
+
* background tasks before the proxy answers the client's `session/prompt` request.
|
|
30479
|
+
*/
|
|
30480
|
+
completeClientPromptByProxy = (sessionId) => {
|
|
30481
|
+
if (this.#disposed) {
|
|
30482
|
+
return null;
|
|
30483
|
+
}
|
|
30484
|
+
const session = this.#sessions.get(sessionId);
|
|
30485
|
+
if (session === void 0) {
|
|
30486
|
+
return null;
|
|
30487
|
+
}
|
|
30488
|
+
for (const [key, pending] of [...this.#pendingRequests.entries()]) {
|
|
30489
|
+
if (pending.sessionId === sessionId && pending.kind === "prompt") {
|
|
30490
|
+
this.#pendingRequests.delete(key);
|
|
30491
|
+
}
|
|
30492
|
+
}
|
|
30493
|
+
this.#cancelWatchdog(session);
|
|
30494
|
+
this.#cancelWakeupTimers(session.phase);
|
|
30495
|
+
session.openNonShellToolIds.clear();
|
|
30496
|
+
this.#clearAllBackgroundTasks(session);
|
|
30497
|
+
session.phase = { cancelRequested: false, kind: "idle" };
|
|
30498
|
+
return this.#takeBackgroundTasksUpdate(sessionId, session);
|
|
30499
|
+
};
|
|
29541
30500
|
#cancelWakeupTimers = (phase) => {
|
|
29542
30501
|
if (phase.kind !== "wakeup") {
|
|
29543
30502
|
return;
|
|
@@ -29950,6 +30909,7 @@ var AntigravityBackgroundWakeup = class {
|
|
|
29950
30909
|
};
|
|
29951
30910
|
};
|
|
29952
30911
|
#enterWakeup = (sessionId, session, taskIds) => {
|
|
30912
|
+
this.#cancelWatchdog(session);
|
|
29953
30913
|
const notifications = [];
|
|
29954
30914
|
const bgNotification = this.#takeBackgroundTasksUpdate(sessionId, session);
|
|
29955
30915
|
if (bgNotification !== null) {
|
|
@@ -29988,6 +30948,7 @@ var AntigravityBackgroundWakeup = class {
|
|
|
29988
30948
|
session.wakeupDeferredSettledStep = null;
|
|
29989
30949
|
session.wakeupStreamedMessageText = "";
|
|
29990
30950
|
this.#dropAwaitingResultTasks(session);
|
|
30951
|
+
this.#syncIdleShellWatchdog(sessionId, session);
|
|
29991
30952
|
const notifications = [];
|
|
29992
30953
|
const bgNotification = this.#takeBackgroundTasksUpdate(sessionId, session);
|
|
29993
30954
|
if (bgNotification !== null) {
|
|
@@ -30012,6 +30973,7 @@ var AntigravityBackgroundWakeup = class {
|
|
|
30012
30973
|
session.wakeupDeferredSettledStep = null;
|
|
30013
30974
|
session.wakeupStreamedMessageText = "";
|
|
30014
30975
|
this.#dropAwaitingResultTasks(session);
|
|
30976
|
+
this.#syncIdleShellWatchdog(sessionId, session);
|
|
30015
30977
|
const notifications = [];
|
|
30016
30978
|
const bgNotification = this.#takeBackgroundTasksUpdate(sessionId, session);
|
|
30017
30979
|
if (bgNotification !== null) {
|
|
@@ -30135,6 +31097,17 @@ var AntigravityBackgroundWakeup = class {
|
|
|
30135
31097
|
this.#consumeSubagentIdlesThrough(current, widerTail.steps, tail.settledStep.stepIndex);
|
|
30136
31098
|
}
|
|
30137
31099
|
}
|
|
31100
|
+
if (this.#hasSubagentTasks(current)) {
|
|
31101
|
+
const stillActive = await this.#reconcileStructuredArtifacts(
|
|
31102
|
+
sessionId,
|
|
31103
|
+
current,
|
|
31104
|
+
tail.steps.at(-1),
|
|
31105
|
+
true
|
|
31106
|
+
);
|
|
31107
|
+
if (!stillActive || current.phase.kind !== "wakeup" || current.phase.generation !== generation || current.phase.stage.stageEpoch !== stageEpoch || current.phase.stage.kind !== "streaming" && current.phase.stage.kind !== "awaiting-output") {
|
|
31108
|
+
return;
|
|
31109
|
+
}
|
|
31110
|
+
}
|
|
30138
31111
|
this.#consumeSettledReplyText(current, tail.settledStep);
|
|
30139
31112
|
if (this.#settleWakeupReply(sessionId, current, tail, tail.settledStep.stepIndex)) {
|
|
30140
31113
|
this.#emitNotifications(this.#finishWakeup(sessionId, current, "end_turn", false));
|
|
@@ -30320,13 +31293,35 @@ var AntigravityBackgroundWakeup = class {
|
|
|
30320
31293
|
const meta3 = inspectToolMetadata(update, session.toolMetadata.get(toolCallId));
|
|
30321
31294
|
session.toolMetadata.set(toolCallId, meta3);
|
|
30322
31295
|
if (meta3.isDaemon) {
|
|
31296
|
+
session.openNonShellToolIds.delete(toolCallId);
|
|
30323
31297
|
this.#deleteBackgroundTask(session, toolCallId);
|
|
30324
31298
|
return;
|
|
30325
31299
|
}
|
|
31300
|
+
const isShellTool = meta3.category === "command";
|
|
31301
|
+
if (!isShellTool) {
|
|
31302
|
+
if (status === "in_progress" || status === "pending") {
|
|
31303
|
+
session.openNonShellToolIds.add(toolCallId);
|
|
31304
|
+
} else if (status === "completed" || status === "failed" || status === "cancelled") {
|
|
31305
|
+
session.openNonShellToolIds.delete(toolCallId);
|
|
31306
|
+
}
|
|
31307
|
+
}
|
|
30326
31308
|
if (meta3.category === "manage-subagents" && status === "completed") {
|
|
30327
31309
|
await this.#killSubagentsByMetadata(sessionId, session, meta3);
|
|
30328
31310
|
return;
|
|
30329
31311
|
}
|
|
31312
|
+
if (meta3.category === "manage-task" && status === "completed" && meta3.killTaskId !== void 0) {
|
|
31313
|
+
this.#killBackgroundTaskByNativeId(session, meta3.killTaskId);
|
|
31314
|
+
return;
|
|
31315
|
+
}
|
|
31316
|
+
if (meta3.category === "swarm") {
|
|
31317
|
+
if (!cancelled && meta3.swarmAction === "add" && status === "completed") {
|
|
31318
|
+
this.#registerSubagentTask(session, toolCallId, meta3.description);
|
|
31319
|
+
await this.#reconcileStructuredArtifacts(sessionId, session, void 0, false);
|
|
31320
|
+
} else if (meta3.swarmAction === "kill" && status === "completed") {
|
|
31321
|
+
await this.#reconcileStructuredArtifacts(sessionId, session, void 0, true);
|
|
31322
|
+
}
|
|
31323
|
+
return;
|
|
31324
|
+
}
|
|
30330
31325
|
if (meta3.category === "subagent") {
|
|
30331
31326
|
if (!cancelled && status === "completed") {
|
|
30332
31327
|
this.#registerSubagentTask(session, toolCallId, meta3.description);
|
|
@@ -30456,6 +31451,34 @@ var AntigravityBackgroundWakeup = class {
|
|
|
30456
31451
|
if (bg2 !== null) {
|
|
30457
31452
|
notifications.push(bg2);
|
|
30458
31453
|
}
|
|
31454
|
+
} else if (meta3.category === "manage-task" && status === "completed" && meta3.killTaskId !== void 0) {
|
|
31455
|
+
if (this.#killBackgroundTaskByNativeId(session, meta3.killTaskId)) {
|
|
31456
|
+
const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
|
|
31457
|
+
if (bg2 !== null) {
|
|
31458
|
+
notifications.push(bg2);
|
|
31459
|
+
}
|
|
31460
|
+
}
|
|
31461
|
+
} else if (meta3.category === "swarm" && status === "completed") {
|
|
31462
|
+
if (meta3.swarmAction === "add") {
|
|
31463
|
+
this.#registerSubagentTask(session, toolCallId, meta3.description);
|
|
31464
|
+
const active = await this.#reconcileStructuredArtifacts(sessionId, session, void 0, false);
|
|
31465
|
+
if (!active) {
|
|
31466
|
+
return;
|
|
31467
|
+
}
|
|
31468
|
+
const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
|
|
31469
|
+
if (bg2 !== null) {
|
|
31470
|
+
notifications.push(bg2);
|
|
31471
|
+
}
|
|
31472
|
+
} else if (meta3.swarmAction === "kill") {
|
|
31473
|
+
const active = await this.#reconcileStructuredArtifacts(sessionId, session, void 0, true);
|
|
31474
|
+
if (!active) {
|
|
31475
|
+
return;
|
|
31476
|
+
}
|
|
31477
|
+
const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
|
|
31478
|
+
if (bg2 !== null) {
|
|
31479
|
+
notifications.push(bg2);
|
|
31480
|
+
}
|
|
31481
|
+
}
|
|
30459
31482
|
}
|
|
30460
31483
|
this.#pauseOrResumeWakeupTimers(sessionId, session);
|
|
30461
31484
|
}
|
|
@@ -30473,7 +31496,9 @@ var AntigravityBackgroundWakeup = class {
|
|
|
30473
31496
|
return;
|
|
30474
31497
|
}
|
|
30475
31498
|
const session = this.#ensureSession(sessionId);
|
|
31499
|
+
this.#cancelWatchdog(session);
|
|
30476
31500
|
this.#cancelWakeupTimers(session.phase);
|
|
31501
|
+
session.openNonShellToolIds.clear();
|
|
30477
31502
|
session.phase = { kind: "loading", requestKey: key };
|
|
30478
31503
|
if (key !== void 0) {
|
|
30479
31504
|
this.#pendingRequests.set(key, { kind: "load", sessionId });
|
|
@@ -30492,6 +31517,8 @@ var AntigravityBackgroundWakeup = class {
|
|
|
30492
31517
|
return;
|
|
30493
31518
|
}
|
|
30494
31519
|
const session = this.#ensureSession(sessionId);
|
|
31520
|
+
this.#cancelWatchdog(session);
|
|
31521
|
+
session.openNonShellToolIds.clear();
|
|
30495
31522
|
if (session.phase.kind === "wakeup") {
|
|
30496
31523
|
this.#emitNotifications(this.#finishWakeup(sessionId, session, "end_turn", false));
|
|
30497
31524
|
}
|
|
@@ -30508,6 +31535,7 @@ var AntigravityBackgroundWakeup = class {
|
|
|
30508
31535
|
prePromptStepIndex,
|
|
30509
31536
|
requestKey: key
|
|
30510
31537
|
};
|
|
31538
|
+
this.#armClientPromptWatchdog(sessionId, session);
|
|
30511
31539
|
if (key !== void 0) {
|
|
30512
31540
|
this.#pendingRequests.set(key, { kind: "prompt", sessionId });
|
|
30513
31541
|
}
|
|
@@ -30598,10 +31626,17 @@ var AntigravityBackgroundWakeup = class {
|
|
|
30598
31626
|
}
|
|
30599
31627
|
}
|
|
30600
31628
|
}
|
|
31629
|
+
this.#cancelWatchdog(session2);
|
|
31630
|
+
session2.openNonShellToolIds.clear();
|
|
31631
|
+
if (!promptCancelled && session2.backgroundTasks.size > 0) {
|
|
31632
|
+
await this.#reconcileStructuredArtifacts(tracked.sessionId, session2, tail?.steps.at(-1), true);
|
|
31633
|
+
promptCancelled = this.#disposed || session2.phase.kind === "client-prompt" && session2.phase.cancelled || session2.phase.kind === "idle" && session2.phase.cancelRequested || responseStopReason === "cancelled";
|
|
31634
|
+
}
|
|
30601
31635
|
if (promptCancelled) {
|
|
30602
31636
|
this.#clearAllBackgroundTasks(session2);
|
|
30603
31637
|
}
|
|
30604
31638
|
session2.phase = { cancelRequested: promptCancelled, kind: "idle" };
|
|
31639
|
+
this.#syncIdleShellWatchdog(tracked.sessionId, session2);
|
|
30605
31640
|
const bg2 = this.#takeBackgroundTasksUpdate(tracked.sessionId, session2);
|
|
30606
31641
|
const rewritePromptCancelled = promptCancelled && "result" in message && isRecord5(message.result) && responseStopReason !== "cancelled";
|
|
30607
31642
|
const beforeUpdates = bg2 === null ? [] : [bg2];
|
|
@@ -30632,6 +31667,9 @@ var AntigravityBackgroundWakeup = class {
|
|
|
30632
31667
|
case "loading":
|
|
30633
31668
|
return EMPTY_INCOMING_OUTCOME;
|
|
30634
31669
|
case "client-prompt": {
|
|
31670
|
+
if (session.watchdog?.kind === "client-prompt") {
|
|
31671
|
+
session.watchdog.sawAcpActivity = true;
|
|
31672
|
+
}
|
|
30635
31673
|
if (updateKind === "tool_call" || updateKind === "tool_call_update") {
|
|
30636
31674
|
await this.#applyClientPromptToolUpdate(sessionId, session, update, session.phase.cancelled);
|
|
30637
31675
|
}
|
|
@@ -30650,6 +31688,7 @@ var AntigravityBackgroundWakeup = class {
|
|
|
30650
31688
|
} else {
|
|
30651
31689
|
this.#deleteBackgroundTask(session, toolCallId);
|
|
30652
31690
|
}
|
|
31691
|
+
this.#syncIdleShellWatchdog(sessionId, session);
|
|
30653
31692
|
const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
|
|
30654
31693
|
return bg2 === null ? EMPTY_INCOMING_OUTCOME : { afterUpdates: [bg2], beforeUpdates: [] };
|
|
30655
31694
|
}
|
|
@@ -30660,6 +31699,7 @@ var AntigravityBackgroundWakeup = class {
|
|
|
30660
31699
|
} else {
|
|
30661
31700
|
this.#deleteBackgroundTask(session, toolCallId);
|
|
30662
31701
|
}
|
|
31702
|
+
this.#syncIdleShellWatchdog(sessionId, session);
|
|
30663
31703
|
const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
|
|
30664
31704
|
return bg2 === null ? EMPTY_INCOMING_OUTCOME : { afterUpdates: [bg2], beforeUpdates: [] };
|
|
30665
31705
|
}
|
|
@@ -30751,6 +31791,20 @@ var AntigravityBackgroundWakeup = class {
|
|
|
30751
31791
|
executorError
|
|
30752
31792
|
);
|
|
30753
31793
|
}
|
|
31794
|
+
return;
|
|
31795
|
+
}
|
|
31796
|
+
if (updateKind === "usage_update" && session.phase.openToolIds.size === 0 && session.activeInteractions === 0 && (session.phase.stage.kind === "streaming" || session.phase.stage.kind === "awaiting-output")) {
|
|
31797
|
+
session.phase.stage.transcriptCheck.cancel();
|
|
31798
|
+
const nextCheck = this.#scheduleTranscriptPoll(
|
|
31799
|
+
sessionId,
|
|
31800
|
+
session.phase.generation,
|
|
31801
|
+
session.phase.stage.stageEpoch,
|
|
31802
|
+
TRANSCRIPT_INITIAL_DELAY_MS
|
|
31803
|
+
);
|
|
31804
|
+
session.phase = {
|
|
31805
|
+
...session.phase,
|
|
31806
|
+
stage: { ...session.phase.stage, transcriptCheck: nextCheck }
|
|
31807
|
+
};
|
|
30754
31808
|
}
|
|
30755
31809
|
};
|
|
30756
31810
|
beginInteraction = (sessionId) => {
|
|
@@ -30759,6 +31813,9 @@ var AntigravityBackgroundWakeup = class {
|
|
|
30759
31813
|
}
|
|
30760
31814
|
const session = this.#ensureSession(sessionId);
|
|
30761
31815
|
session.activeInteractions += 1;
|
|
31816
|
+
if (session.watchdog?.kind === "idle-shell") {
|
|
31817
|
+
this.#cancelWatchdog(session);
|
|
31818
|
+
}
|
|
30762
31819
|
this.#pauseOrResumeWakeupTimers(sessionId, session);
|
|
30763
31820
|
};
|
|
30764
31821
|
endInteraction = (sessionId) => {
|
|
@@ -30770,6 +31827,7 @@ var AntigravityBackgroundWakeup = class {
|
|
|
30770
31827
|
return;
|
|
30771
31828
|
}
|
|
30772
31829
|
session.activeInteractions = Math.max(0, session.activeInteractions - 1);
|
|
31830
|
+
this.#syncIdleShellWatchdog(sessionId, session);
|
|
30773
31831
|
this.#pauseOrResumeWakeupTimers(sessionId, session);
|
|
30774
31832
|
};
|
|
30775
31833
|
cancelSession = (sessionId) => {
|
|
@@ -30777,6 +31835,7 @@ var AntigravityBackgroundWakeup = class {
|
|
|
30777
31835
|
return "retain";
|
|
30778
31836
|
}
|
|
30779
31837
|
const session = this.#ensureSession(sessionId);
|
|
31838
|
+
this.#cancelWatchdog(session);
|
|
30780
31839
|
const mustClose = session.phase.kind === "wakeup" || this.#hasSubagentTasks(session);
|
|
30781
31840
|
if (mustClose) {
|
|
30782
31841
|
this.#cancelWakeupTimers(session.phase);
|
|
@@ -30797,6 +31856,7 @@ var AntigravityBackgroundWakeup = class {
|
|
|
30797
31856
|
}
|
|
30798
31857
|
for (const [sessionId, session] of this.#sessions) {
|
|
30799
31858
|
const wasWakeup = session.phase.kind === "wakeup";
|
|
31859
|
+
this.#cancelWatchdog(session);
|
|
30800
31860
|
this.#cancelWakeupTimers(session.phase);
|
|
30801
31861
|
this.#clearAllBackgroundTasks(session);
|
|
30802
31862
|
if (wasWakeup) {
|
|
@@ -30822,6 +31882,7 @@ var AntigravityBackgroundWakeup = class {
|
|
|
30822
31882
|
}
|
|
30823
31883
|
this.#disposed = true;
|
|
30824
31884
|
for (const session of this.#sessions.values()) {
|
|
31885
|
+
this.#cancelWatchdog(session);
|
|
30825
31886
|
this.#cancelWakeupTimers(session.phase);
|
|
30826
31887
|
}
|
|
30827
31888
|
this.#sessions.clear();
|
|
@@ -30989,6 +32050,12 @@ async function prepareAntigravitySessionCancel(clientConnection2, sessionId) {
|
|
|
30989
32050
|
function takeAntigravityUnusableNativeSession(clientConnection2, sessionId) {
|
|
30990
32051
|
return activeConnectionsByClient.get(clientConnection2)?.takeUnusableNativeSession(sessionId) ?? false;
|
|
30991
32052
|
}
|
|
32053
|
+
function takeAntigravityProcessRecycleRequired(clientConnection2, sessionId) {
|
|
32054
|
+
return activeConnectionsByClient.get(clientConnection2)?.takeProcessRecycleRequired(sessionId) ?? false;
|
|
32055
|
+
}
|
|
32056
|
+
async function trySettleAntigravityIdlePrompt(clientConnection2, sessionId) {
|
|
32057
|
+
return await activeConnectionsByClient.get(clientConnection2)?.trySettleIdlePrompt(sessionId) ?? false;
|
|
32058
|
+
}
|
|
30992
32059
|
var AntigravityAgentConnection = class {
|
|
30993
32060
|
connection;
|
|
30994
32061
|
termination;
|
|
@@ -31004,6 +32071,10 @@ var AntigravityAgentConnection = class {
|
|
|
31004
32071
|
#pendingConfigEchoes = [];
|
|
31005
32072
|
/** Native sessions whose current prompt reported an unusable conversation. */
|
|
31006
32073
|
#unusableSessions = /* @__PURE__ */ new Set();
|
|
32074
|
+
/** Native sessions whose open prompt was settled by the proxy and whose child process must be recycled. */
|
|
32075
|
+
#recycleRequiredSessions = /* @__PURE__ */ new Set();
|
|
32076
|
+
/** Native sessions whose wedged prompt was settled by the proxy; drop late updates before teardown. */
|
|
32077
|
+
#proxySettledSessions = /* @__PURE__ */ new Set();
|
|
31007
32078
|
/** The client prompt each native session runs, while it runs. */
|
|
31008
32079
|
#runningPrompts = /* @__PURE__ */ new Map();
|
|
31009
32080
|
/** Every prompt sent to Antigravity whose answer has not arrived, by request id. */
|
|
@@ -31025,6 +32096,12 @@ var AntigravityAgentConnection = class {
|
|
|
31025
32096
|
this.#queueMetaUpdate(notification);
|
|
31026
32097
|
},
|
|
31027
32098
|
launchEnvironment,
|
|
32099
|
+
onOpenPromptTimeout: (sessionId, outcome) => {
|
|
32100
|
+
void this.#settlePromptByProxy(sessionId, outcome);
|
|
32101
|
+
},
|
|
32102
|
+
onOrphanShellPromptSettle: (sessionId) => {
|
|
32103
|
+
void this.#settlePromptByProxy(sessionId, { kind: "settled" });
|
|
32104
|
+
},
|
|
31028
32105
|
...options.timer === void 0 ? {} : { timer: options.timer }
|
|
31029
32106
|
});
|
|
31030
32107
|
const launch = executableLaunch2(options.command, ["acp"]);
|
|
@@ -31184,6 +32261,62 @@ var AntigravityAgentConnection = class {
|
|
|
31184
32261
|
return disposition;
|
|
31185
32262
|
};
|
|
31186
32263
|
takeUnusableNativeSession = (sessionId) => this.#unusableSessions.delete(sessionId);
|
|
32264
|
+
takeProcessRecycleRequired = (sessionId) => this.#recycleRequiredSessions.delete(sessionId);
|
|
32265
|
+
#settlePromptByProxy = async (sessionId, outcome) => {
|
|
32266
|
+
if (this.#closePromise !== null || this.#deliveryAbort.signal.aborted) {
|
|
32267
|
+
return false;
|
|
32268
|
+
}
|
|
32269
|
+
const running = this.#runningPrompts.get(sessionId);
|
|
32270
|
+
if (running === void 0 || running.cancelled) {
|
|
32271
|
+
return false;
|
|
32272
|
+
}
|
|
32273
|
+
this.#runningPrompts.delete(sessionId);
|
|
32274
|
+
this.#promptsByKey.delete(running.clientKey);
|
|
32275
|
+
this.#promptsByKey.delete(running.currentKey);
|
|
32276
|
+
if (running.pendingSteer !== void 0) {
|
|
32277
|
+
this.#promptsByKey.delete(running.pendingSteer.key);
|
|
32278
|
+
running.pendingSteer.settle(false);
|
|
32279
|
+
running.pendingSteer = void 0;
|
|
32280
|
+
}
|
|
32281
|
+
this.#proxySettledSessions.add(sessionId);
|
|
32282
|
+
this.#recycleRequiredSessions.add(sessionId);
|
|
32283
|
+
const bg2 = this.#backgroundWakeup.completeClientPromptByProxy(sessionId);
|
|
32284
|
+
if (bg2 !== null) {
|
|
32285
|
+
this.#queueMetaUpdate(bg2);
|
|
32286
|
+
}
|
|
32287
|
+
await this.#flushDeliveries();
|
|
32288
|
+
if (this.#closePromise !== null || this.#deliveryAbort.signal.aborted) {
|
|
32289
|
+
return false;
|
|
32290
|
+
}
|
|
32291
|
+
if (outcome.kind === "settled") {
|
|
32292
|
+
const usage = addUsage(running.supersededUsage, void 0);
|
|
32293
|
+
this.#answerClient?.({
|
|
32294
|
+
id: running.clientKey,
|
|
32295
|
+
jsonrpc: "2.0",
|
|
32296
|
+
result: { stopReason: "end_turn", ...usage === void 0 ? {} : { usage } }
|
|
32297
|
+
});
|
|
32298
|
+
return true;
|
|
32299
|
+
}
|
|
32300
|
+
this.#answerClient?.({
|
|
32301
|
+
error: { code: -32603, message: outcome.message },
|
|
32302
|
+
id: running.clientKey,
|
|
32303
|
+
jsonrpc: "2.0"
|
|
32304
|
+
});
|
|
32305
|
+
return true;
|
|
32306
|
+
};
|
|
32307
|
+
trySettleIdlePrompt = async (sessionId) => {
|
|
32308
|
+
if (this.#closePromise !== null || this.#deliveryAbort.signal.aborted) {
|
|
32309
|
+
return false;
|
|
32310
|
+
}
|
|
32311
|
+
const running = this.#runningPrompts.get(sessionId);
|
|
32312
|
+
if (running === void 0 || running.cancelled) {
|
|
32313
|
+
return false;
|
|
32314
|
+
}
|
|
32315
|
+
if (!await this.#backgroundWakeup.isReplyDoneWithOnlyShellTasks(sessionId)) {
|
|
32316
|
+
return false;
|
|
32317
|
+
}
|
|
32318
|
+
return await this.#settlePromptByProxy(sessionId, { kind: "settled" });
|
|
32319
|
+
};
|
|
31187
32320
|
initialize = async (signal) => {
|
|
31188
32321
|
signal.throwIfAborted();
|
|
31189
32322
|
};
|
|
@@ -31317,6 +32450,7 @@ var AntigravityAgentConnection = class {
|
|
|
31317
32450
|
if (sessionId !== void 0) {
|
|
31318
32451
|
this.#messageStreams.set(sessionId, { kind: "none" });
|
|
31319
32452
|
this.#unusableSessions.delete(sessionId);
|
|
32453
|
+
this.#proxySettledSessions.delete(sessionId);
|
|
31320
32454
|
if (key !== void 0) {
|
|
31321
32455
|
const prompt = {
|
|
31322
32456
|
cancelled: false,
|
|
@@ -31562,6 +32696,13 @@ var AntigravityAgentConnection = class {
|
|
|
31562
32696
|
try {
|
|
31563
32697
|
await previous;
|
|
31564
32698
|
await this.#flushDeliveries();
|
|
32699
|
+
if (joinable() === running && await this.#backgroundWakeup.isReplyDoneWithOnlyShellTasks(sessionId)) {
|
|
32700
|
+
if (joinable() === running) {
|
|
32701
|
+
await this.#settlePromptByProxy(sessionId, { kind: "settled" });
|
|
32702
|
+
}
|
|
32703
|
+
answer({ outcome: "promptRequired", reason: "noRunningTurn" });
|
|
32704
|
+
return;
|
|
32705
|
+
}
|
|
31565
32706
|
if (joinable() !== running) {
|
|
31566
32707
|
answer({ outcome: "promptRequired", reason: "noRunningTurn" });
|
|
31567
32708
|
return;
|
|
@@ -31610,6 +32751,12 @@ var AntigravityAgentConnection = class {
|
|
|
31610
32751
|
if (this.#closePromise !== null || this.#deliveryAbort.signal.aborted) {
|
|
31611
32752
|
return;
|
|
31612
32753
|
}
|
|
32754
|
+
if (this.#proxySettledSessions.size > 0 && isNotificationMessage3(chunk) && chunk.method === methods.client.session.update && isRecord5(chunk.params)) {
|
|
32755
|
+
const chunkSessionId = readStringProperty(chunk.params, "sessionId");
|
|
32756
|
+
if (chunkSessionId !== void 0 && this.#proxySettledSessions.has(chunkSessionId)) {
|
|
32757
|
+
return;
|
|
32758
|
+
}
|
|
32759
|
+
}
|
|
31613
32760
|
const routed = isResponseMessage3(chunk) ? this.#routePromptAnswer(chunk) : chunk;
|
|
31614
32761
|
if (routed === void 0) {
|
|
31615
32762
|
return;
|
|
@@ -77842,6 +78989,20 @@ var turnNotificationSchema = external_exports.object({
|
|
|
77842
78989
|
threadId: boundedText(256),
|
|
77843
78990
|
turn: turnSchema
|
|
77844
78991
|
});
|
|
78992
|
+
var tokenCount = external_exports.number().int().nonnegative().safe();
|
|
78993
|
+
var tokenUsageNotificationSchema = external_exports.object({
|
|
78994
|
+
threadId: boundedText(256),
|
|
78995
|
+
turnId: boundedText(256),
|
|
78996
|
+
tokenUsage: external_exports.object({
|
|
78997
|
+
last: external_exports.object({
|
|
78998
|
+
inputTokens: tokenCount,
|
|
78999
|
+
cachedInputTokens: tokenCount,
|
|
79000
|
+
cacheWriteInputTokens: tokenCount.optional(),
|
|
79001
|
+
outputTokens: tokenCount,
|
|
79002
|
+
reasoningOutputTokens: tokenCount
|
|
79003
|
+
})
|
|
79004
|
+
})
|
|
79005
|
+
});
|
|
77845
79006
|
var commandApprovalParamsSchema = external_exports.object({
|
|
77846
79007
|
command: external_exports.string().nullish(),
|
|
77847
79008
|
commandActions: external_exports.array(external_exports.unknown()).max(1e3).nullish(),
|
|
@@ -78526,6 +79687,7 @@ var THREAD_NOTIFICATIONS = /* @__PURE__ */ new Set([
|
|
|
78526
79687
|
"thread/compacted",
|
|
78527
79688
|
"thread/name/updated",
|
|
78528
79689
|
"thread/settings/updated",
|
|
79690
|
+
"thread/tokenUsage/updated",
|
|
78529
79691
|
"turn/completed",
|
|
78530
79692
|
"turn/plan/updated",
|
|
78531
79693
|
"turn/started"
|
|
@@ -78608,6 +79770,29 @@ function steeringPrompt(prompt) {
|
|
|
78608
79770
|
}
|
|
78609
79771
|
return blocks;
|
|
78610
79772
|
}
|
|
79773
|
+
function addResponseTokens(total, response) {
|
|
79774
|
+
return {
|
|
79775
|
+
inputTokens: (total?.inputTokens ?? 0) + response.inputTokens,
|
|
79776
|
+
cachedInputTokens: (total?.cachedInputTokens ?? 0) + response.cachedInputTokens,
|
|
79777
|
+
cacheWriteInputTokens: (total?.cacheWriteInputTokens ?? 0) + (response.cacheWriteInputTokens ?? 0),
|
|
79778
|
+
outputTokens: (total?.outputTokens ?? 0) + response.outputTokens,
|
|
79779
|
+
reasoningOutputTokens: (total?.reasoningOutputTokens ?? 0) + response.reasoningOutputTokens
|
|
79780
|
+
};
|
|
79781
|
+
}
|
|
79782
|
+
function turnQuota(tokens) {
|
|
79783
|
+
if (tokens === null) {
|
|
79784
|
+
return {};
|
|
79785
|
+
}
|
|
79786
|
+
const tokenCount2 = {
|
|
79787
|
+
totalTokens: tokens.inputTokens + tokens.outputTokens,
|
|
79788
|
+
inputTokens: tokens.inputTokens,
|
|
79789
|
+
cachedInputTokens: tokens.cachedInputTokens,
|
|
79790
|
+
cachedWriteTokens: tokens.cacheWriteInputTokens ?? 0,
|
|
79791
|
+
outputTokens: tokens.outputTokens,
|
|
79792
|
+
reasoningOutputTokens: tokens.reasoningOutputTokens
|
|
79793
|
+
};
|
|
79794
|
+
return { _meta: { quota: { token_count: tokenCount2, model_usage: [] } } };
|
|
79795
|
+
}
|
|
78611
79796
|
function agentMessageUpdate(messageId, text2, questions = []) {
|
|
78612
79797
|
return {
|
|
78613
79798
|
content: { text: text2, type: "text" },
|
|
@@ -78753,7 +79938,8 @@ var CodexOwnedAcpAgent = class {
|
|
|
78753
79938
|
steeringContent: /* @__PURE__ */ new Map(),
|
|
78754
79939
|
clientId: randomUUID8(),
|
|
78755
79940
|
input: { kind: "awaiting" },
|
|
78756
|
-
turn: { id: "" }
|
|
79941
|
+
turn: { id: "" },
|
|
79942
|
+
tokens: null
|
|
78757
79943
|
};
|
|
78758
79944
|
this.#turn = turn;
|
|
78759
79945
|
try {
|
|
@@ -78819,6 +80005,14 @@ var CodexOwnedAcpAgent = class {
|
|
|
78819
80005
|
if (!thread.success || thread.data.threadId !== this.#context.threadId()) {
|
|
78820
80006
|
return;
|
|
78821
80007
|
}
|
|
80008
|
+
if (method === "thread/tokenUsage/updated") {
|
|
80009
|
+
const decoded = tokenUsageNotificationSchema.safeParse(params);
|
|
80010
|
+
const active = this.#turn;
|
|
80011
|
+
if (decoded.success && active !== null && active.turn.id === decoded.data.turnId) {
|
|
80012
|
+
active.tokens = addResponseTokens(active.tokens, decoded.data.tokenUsage.last);
|
|
80013
|
+
}
|
|
80014
|
+
return;
|
|
80015
|
+
}
|
|
78822
80016
|
if (method === "turn/started") {
|
|
78823
80017
|
const decoded = turnNotificationSchema.safeParse(params);
|
|
78824
80018
|
if (decoded.success && this.#turn !== null && (this.#turn.turn.id === "" || this.#turn.turn.id === decoded.data.turn.id)) {
|
|
@@ -79167,7 +80361,8 @@ var CodexOwnedAcpAgent = class {
|
|
|
79167
80361
|
steeringContent: /* @__PURE__ */ new Map(),
|
|
79168
80362
|
clientId: randomUUID8(),
|
|
79169
80363
|
input: { kind: "awaiting" },
|
|
79170
|
-
turn: { id: "" }
|
|
80364
|
+
turn: { id: "" },
|
|
80365
|
+
tokens: null
|
|
79171
80366
|
};
|
|
79172
80367
|
this.#agentMessages.clear();
|
|
79173
80368
|
this.#streamedReasoningSources.clear();
|
|
@@ -79279,7 +80474,7 @@ var CodexOwnedAcpAgent = class {
|
|
|
79279
80474
|
}
|
|
79280
80475
|
}
|
|
79281
80476
|
this.#turnSettledCompaction = this.#settleCompaction("cancelled") !== null;
|
|
79282
|
-
turn.completion.resolve({ stopReason: "cancelled" });
|
|
80477
|
+
turn.completion.resolve({ stopReason: "cancelled", ...turnQuota(turn.tokens) });
|
|
79283
80478
|
};
|
|
79284
80479
|
#cancelSampling = () => {
|
|
79285
80480
|
this.#sampling?.abort();
|
|
@@ -79412,10 +80607,10 @@ var CodexOwnedAcpAgent = class {
|
|
|
79412
80607
|
}
|
|
79413
80608
|
if (turn.status === "interrupted") {
|
|
79414
80609
|
this.#turnSettledCompaction = this.#settleCompaction("cancelled") !== null;
|
|
79415
|
-
active.completion.resolve({ stopReason: "cancelled" });
|
|
80610
|
+
active.completion.resolve({ stopReason: "cancelled", ...turnQuota(active.tokens) });
|
|
79416
80611
|
return;
|
|
79417
80612
|
}
|
|
79418
|
-
active.completion.resolve({ stopReason: "end_turn" });
|
|
80613
|
+
active.completion.resolve({ stopReason: "end_turn", ...turnQuota(active.tokens) });
|
|
79419
80614
|
};
|
|
79420
80615
|
};
|
|
79421
80616
|
|
|
@@ -81247,13 +82442,13 @@ var CodexAgentSpecification = class extends InProcessAcpAgentSpecification {
|
|
|
81247
82442
|
|
|
81248
82443
|
// src/engine/agent/specification/vendors/pi-agent.ts
|
|
81249
82444
|
import { createHash as createHash3 } from "node:crypto";
|
|
81250
|
-
import { join as
|
|
82445
|
+
import { join as join24 } from "node:path";
|
|
81251
82446
|
|
|
81252
82447
|
// src/engine/acp/harness/pi/upstream/dist/acp/agent.js
|
|
81253
82448
|
import { spawnSync } from "node:child_process";
|
|
81254
82449
|
import { randomUUID as randomUUID12 } from "node:crypto";
|
|
81255
82450
|
import { existsSync as existsSync8, readdirSync as readdirSync6, readFileSync as readFileSync9, realpathSync as realpathSync3, statSync as statSync3, unlinkSync as unlinkSync2 } from "node:fs";
|
|
81256
|
-
import { basename as basename6, dirname as dirname8, isAbsolute as isAbsolute13, join as
|
|
82451
|
+
import { basename as basename6, dirname as dirname8, isAbsolute as isAbsolute13, join as join23 } from "node:path";
|
|
81257
82452
|
|
|
81258
82453
|
// src/engine/acp/harness/pi/upstream/dist/pi-rpc/process.js
|
|
81259
82454
|
import { spawn as spawn7 } from "node:child_process";
|
|
@@ -81709,7 +82904,7 @@ function maybeAuthRequiredError(err) {
|
|
|
81709
82904
|
}
|
|
81710
82905
|
|
|
81711
82906
|
// src/engine/acp/harness/pi/upstream/dist/acp/paths.js
|
|
81712
|
-
import { join as
|
|
82907
|
+
import { join as join19 } from "node:path";
|
|
81713
82908
|
|
|
81714
82909
|
// src/engine/acp/harness/pi/upstream/dist/acp/environment.js
|
|
81715
82910
|
import { homedir as homedir3 } from "node:os";
|
|
@@ -81719,10 +82914,10 @@ function environmentHome(environment) {
|
|
|
81719
82914
|
|
|
81720
82915
|
// src/engine/acp/harness/pi/upstream/dist/acp/paths.js
|
|
81721
82916
|
function getPiAcpDir(environment = process.env) {
|
|
81722
|
-
return
|
|
82917
|
+
return join19(environmentHome(environment), ".pi", "pi-acp");
|
|
81723
82918
|
}
|
|
81724
82919
|
function getPiAcpSessionMapPath(environment = process.env) {
|
|
81725
|
-
return
|
|
82920
|
+
return join19(getPiAcpDir(environment), "session-map.json");
|
|
81726
82921
|
}
|
|
81727
82922
|
|
|
81728
82923
|
// src/engine/acp/harness/pi/upstream/dist/acp/pi-commands.js
|
|
@@ -81844,15 +83039,15 @@ async function readPiLatestEntryId(sessionFile) {
|
|
|
81844
83039
|
|
|
81845
83040
|
// src/engine/acp/harness/pi/upstream/dist/acp/pi-sessions.js
|
|
81846
83041
|
import { closeSync as closeSync2, existsSync as existsSync5, openSync as openSync2, readdirSync as readdirSync4, readFileSync as readFileSync4, readSync as readSync2, statSync as statSync2 } from "node:fs";
|
|
81847
|
-
import { isAbsolute as isAbsolute11, join as
|
|
83042
|
+
import { isAbsolute as isAbsolute11, join as join20, resolve as resolve11 } from "node:path";
|
|
81848
83043
|
var DEFAULT_TAIL_BYTES = 256 * 1024;
|
|
81849
83044
|
var DEFAULT_HEAD_BYTES = 64 * 1024;
|
|
81850
83045
|
function getPiAgentDir(environment) {
|
|
81851
83046
|
const configured = environment["PI_CODING_AGENT_DIR"];
|
|
81852
|
-
return configured ? resolve11(configured) :
|
|
83047
|
+
return configured ? resolve11(configured) : join20(environmentHome(environment), ".pi", "agent");
|
|
81853
83048
|
}
|
|
81854
83049
|
function readSessionDirFromSettings(agentDir) {
|
|
81855
|
-
const settingsPath =
|
|
83050
|
+
const settingsPath = join20(agentDir, "settings.json");
|
|
81856
83051
|
try {
|
|
81857
83052
|
if (!existsSync5(settingsPath)) {
|
|
81858
83053
|
return null;
|
|
@@ -81873,7 +83068,7 @@ function readSessionDirFromSettings(agentDir) {
|
|
|
81873
83068
|
}
|
|
81874
83069
|
function getPiSessionsDir(environment = process.env) {
|
|
81875
83070
|
const agentDir = getPiAgentDir(environment);
|
|
81876
|
-
return readSessionDirFromSettings(agentDir) ??
|
|
83071
|
+
return readSessionDirFromSettings(agentDir) ?? join20(agentDir, "sessions");
|
|
81877
83072
|
}
|
|
81878
83073
|
function getPiSessionDiscoveryDirs(environment) {
|
|
81879
83074
|
const discoveryDirectories = [getPiSessionsDir(environment)];
|
|
@@ -81884,7 +83079,7 @@ function getPiSessionDiscoveryDirs(environment) {
|
|
|
81884
83079
|
if (!entry.isDirectory()) {
|
|
81885
83080
|
continue;
|
|
81886
83081
|
}
|
|
81887
|
-
const directory =
|
|
83082
|
+
const directory = join20(mobiusSessionsRoot, entry.name);
|
|
81888
83083
|
if (!discoveryDirectories.includes(directory)) {
|
|
81889
83084
|
discoveryDirectories.push(directory);
|
|
81890
83085
|
}
|
|
@@ -81901,7 +83096,7 @@ function walkJsonlFiles(dir, out2) {
|
|
|
81901
83096
|
}
|
|
81902
83097
|
for (const e of entries) {
|
|
81903
83098
|
const name2 = typeof e.name === "string" ? e.name : String(e.name);
|
|
81904
|
-
const p =
|
|
83099
|
+
const p = join20(dir, name2);
|
|
81905
83100
|
if (e.isDirectory()) {
|
|
81906
83101
|
walkJsonlFiles(p, out2);
|
|
81907
83102
|
} else if (e.isFile() && name2.endsWith(".jsonl")) {
|
|
@@ -82170,7 +83365,7 @@ function findPiSession(sessionId, environment = process.env) {
|
|
|
82170
83365
|
|
|
82171
83366
|
// src/engine/acp/harness/pi/upstream/dist/acp/pi-settings.js
|
|
82172
83367
|
import { existsSync as existsSync6, readFileSync as readFileSync5 } from "node:fs";
|
|
82173
|
-
import { join as
|
|
83368
|
+
import { join as join21, resolve as resolve12 } from "node:path";
|
|
82174
83369
|
function isObject2(x) {
|
|
82175
83370
|
return Boolean(x) && typeof x === "object" && !Array.isArray(x);
|
|
82176
83371
|
}
|
|
@@ -82199,7 +83394,7 @@ function readJsonFile2(path6) {
|
|
|
82199
83394
|
}
|
|
82200
83395
|
}
|
|
82201
83396
|
function getMergedSettings(cwd, environment) {
|
|
82202
|
-
const globalSettingsPath =
|
|
83397
|
+
const globalSettingsPath = join21(getAgentDir(environment), "settings.json");
|
|
82203
83398
|
const projectSettingsPath = resolve12(cwd, ".pi", "settings.json");
|
|
82204
83399
|
const global2 = readJsonFile2(globalSettingsPath);
|
|
82205
83400
|
const project = readJsonFile2(projectSettingsPath);
|
|
@@ -82207,7 +83402,7 @@ function getMergedSettings(cwd, environment) {
|
|
|
82207
83402
|
}
|
|
82208
83403
|
function getAgentDir(environment = process.env) {
|
|
82209
83404
|
const configured = environment["PI_CODING_AGENT_DIR"];
|
|
82210
|
-
return configured ? resolve12(configured) :
|
|
83405
|
+
return configured ? resolve12(configured) : join21(environmentHome(environment), ".pi", "agent");
|
|
82211
83406
|
}
|
|
82212
83407
|
function getEnableSkillCommands(cwd, environment = process.env) {
|
|
82213
83408
|
const merged = getMergedSettings(cwd, environment);
|
|
@@ -82461,7 +83656,7 @@ var SessionStore = class {
|
|
|
82461
83656
|
|
|
82462
83657
|
// src/engine/acp/harness/pi/upstream/dist/acp/slash-commands.js
|
|
82463
83658
|
import { existsSync as existsSync7, readdirSync as readdirSync5, readFileSync as readFileSync7 } from "node:fs";
|
|
82464
|
-
import { join as
|
|
83659
|
+
import { join as join22, resolve as resolve13 } from "node:path";
|
|
82465
83660
|
function parseFrontmatter(content) {
|
|
82466
83661
|
const frontmatter = {};
|
|
82467
83662
|
if (!content.startsWith("---")) {
|
|
@@ -82489,7 +83684,7 @@ function loadCommandsFromDir(dir, source, subdir = "") {
|
|
|
82489
83684
|
try {
|
|
82490
83685
|
const entries = readdirSync5(dir, { withFileTypes: true });
|
|
82491
83686
|
for (const entry of entries) {
|
|
82492
|
-
const fullPath =
|
|
83687
|
+
const fullPath = join22(dir, entry.name);
|
|
82493
83688
|
if (entry.isDirectory()) {
|
|
82494
83689
|
const newSubdir = subdir ? `${subdir}:${entry.name}` : entry.name;
|
|
82495
83690
|
commands.push(...loadCommandsFromDir(fullPath, source, newSubdir));
|
|
@@ -82529,7 +83724,7 @@ function loadCommandsFromDir(dir, source, subdir = "") {
|
|
|
82529
83724
|
}
|
|
82530
83725
|
function loadSlashCommands(cwd, environment = process.env) {
|
|
82531
83726
|
const commands = [];
|
|
82532
|
-
const userDir =
|
|
83727
|
+
const userDir = join22(environmentHome(environment), ".pi", "agent", "prompts");
|
|
82533
83728
|
const projectDir = resolve13(cwd, ".pi", "prompts");
|
|
82534
83729
|
commands.push(...loadCommandsFromDir(userDir, "user"));
|
|
82535
83730
|
commands.push(...loadCommandsFromDir(projectDir, "project"));
|
|
@@ -84198,7 +85393,7 @@ ${JSON.stringify(stats, null, 2)}`;
|
|
|
84198
85393
|
if (piPath) {
|
|
84199
85394
|
const resolved = realpathSync3(piPath);
|
|
84200
85395
|
const pkgRoot = dirname8(dirname8(resolved));
|
|
84201
|
-
const p =
|
|
85396
|
+
const p = join23(pkgRoot, "CHANGELOG.md");
|
|
84202
85397
|
if (existsSync8(p)) {
|
|
84203
85398
|
return p;
|
|
84204
85399
|
}
|
|
@@ -84209,7 +85404,7 @@ ${JSON.stringify(stats, null, 2)}`;
|
|
|
84209
85404
|
const npmRoot = spawnSync("npm", ["root", "-g"], { encoding: "utf-8" });
|
|
84210
85405
|
const root = String(npmRoot.stdout ?? "").trim();
|
|
84211
85406
|
if (root) {
|
|
84212
|
-
const p =
|
|
85407
|
+
const p = join23(root, "@earendil-works", "pi-coding-agent", "CHANGELOG.md");
|
|
84213
85408
|
if (existsSync8(p)) {
|
|
84214
85409
|
return p;
|
|
84215
85410
|
}
|
|
@@ -84303,7 +85498,7 @@ ${JSON.stringify(stats, null, 2)}`;
|
|
|
84303
85498
|
return { stopReason: "end_turn" };
|
|
84304
85499
|
}
|
|
84305
85500
|
const safeSessionId = session.sessionId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
84306
|
-
const outputPath =
|
|
85501
|
+
const outputPath = join23(session.cwd, `pi-session-${safeSessionId}.html`);
|
|
84307
85502
|
let resultPath = "";
|
|
84308
85503
|
try {
|
|
84309
85504
|
const result2 = await session.proc.exportHtml(outputPath);
|
|
@@ -85040,7 +86235,7 @@ function buildStartupInfo(opts) {
|
|
|
85040
86235
|
md.push("");
|
|
85041
86236
|
};
|
|
85042
86237
|
const contextItems = [];
|
|
85043
|
-
const contextPath =
|
|
86238
|
+
const contextPath = join23(opts.cwd, "AGENTS.md");
|
|
85044
86239
|
if (existsSync8(contextPath)) {
|
|
85045
86240
|
contextItems.push(contextPath);
|
|
85046
86241
|
}
|
|
@@ -85049,7 +86244,7 @@ function buildStartupInfo(opts) {
|
|
|
85049
86244
|
const pushSkillFromRoot = (root) => {
|
|
85050
86245
|
try {
|
|
85051
86246
|
for (const e of readdirSync6(root)) {
|
|
85052
|
-
const p =
|
|
86247
|
+
const p = join23(root, e);
|
|
85053
86248
|
try {
|
|
85054
86249
|
const st2 = statSync3(p);
|
|
85055
86250
|
if (st2.isFile() && e.toLowerCase().endsWith(".md")) {
|
|
@@ -85074,7 +86269,7 @@ function buildStartupInfo(opts) {
|
|
|
85074
86269
|
if (name2 === "node_modules" || name2 === ".git") {
|
|
85075
86270
|
continue;
|
|
85076
86271
|
}
|
|
85077
|
-
const p =
|
|
86272
|
+
const p = join23(dir, name2);
|
|
85078
86273
|
let st2;
|
|
85079
86274
|
try {
|
|
85080
86275
|
st2 = statSync3(p);
|
|
@@ -85091,16 +86286,16 @@ function buildStartupInfo(opts) {
|
|
|
85091
86286
|
} catch {
|
|
85092
86287
|
}
|
|
85093
86288
|
};
|
|
85094
|
-
const globalSkillsDir =
|
|
86289
|
+
const globalSkillsDir = join23(getAgentDir(opts.environment), "skills");
|
|
85095
86290
|
pushSkillFromRoot(globalSkillsDir);
|
|
85096
86291
|
const home = opts.environment["HOME"] ?? opts.environment["USERPROFILE"] ?? "";
|
|
85097
|
-
const legacyAgentsSkillsDir =
|
|
86292
|
+
const legacyAgentsSkillsDir = join23(home, ".agents", "skills");
|
|
85098
86293
|
pushSkillFromRoot(legacyAgentsSkillsDir);
|
|
85099
|
-
const projectSkillsDir =
|
|
86294
|
+
const projectSkillsDir = join23(opts.cwd, ".pi", "skills");
|
|
85100
86295
|
pushSkillFromRoot(projectSkillsDir);
|
|
85101
86296
|
addSection("Skills", skillsItems);
|
|
85102
86297
|
const promptsItems = [];
|
|
85103
|
-
const promptsDir =
|
|
86298
|
+
const promptsDir = join23(home, ".pi", "agent", "prompts");
|
|
85104
86299
|
try {
|
|
85105
86300
|
const prompts = readdirSync6(promptsDir).filter((f) => f.endsWith(".md"));
|
|
85106
86301
|
for (const f of prompts) {
|
|
@@ -85110,17 +86305,17 @@ function buildStartupInfo(opts) {
|
|
|
85110
86305
|
}
|
|
85111
86306
|
addSection("Prompts", promptsItems);
|
|
85112
86307
|
const extItems = [];
|
|
85113
|
-
const extDir =
|
|
86308
|
+
const extDir = join23(home, ".pi", "agent", "extensions");
|
|
85114
86309
|
try {
|
|
85115
86310
|
const exts = readdirSync6(extDir).filter((f) => f.endsWith(".ts") || f.endsWith(".js"));
|
|
85116
86311
|
for (const f of exts) {
|
|
85117
|
-
extItems.push(
|
|
86312
|
+
extItems.push(join23(extDir, f));
|
|
85118
86313
|
}
|
|
85119
86314
|
} catch {
|
|
85120
86315
|
}
|
|
85121
86316
|
const settingsPaths = [
|
|
85122
|
-
|
|
85123
|
-
|
|
86317
|
+
join23(getAgentDir(opts.environment), "settings.json"),
|
|
86318
|
+
join23(opts.cwd, ".pi", "settings.json")
|
|
85124
86319
|
];
|
|
85125
86320
|
for (const settingsPath of settingsPaths) {
|
|
85126
86321
|
try {
|
|
@@ -85311,7 +86506,7 @@ var PiAgentSpecification = class extends InProcessAcpAgentSpecification {
|
|
|
85311
86506
|
// keeps the adapter's opt-in capability flag enabled for every launch it owns.
|
|
85312
86507
|
createLaunchEnvironment = async (_agent, context) => {
|
|
85313
86508
|
const workspaceHash = createHash3("sha256").update(context.defaultWorkspace).digest("hex").slice(0, 24);
|
|
85314
|
-
const sessionDirectory =
|
|
86509
|
+
const sessionDirectory = join24(context.dataDirectory, "agents", "pi", "sessions", workspaceHash);
|
|
85315
86510
|
return Object.freeze({
|
|
85316
86511
|
PI_ACP_ENABLE_EMBEDDED_CONTEXT: "true",
|
|
85317
86512
|
MOBIUS_PI_SESSION_DIR: sessionDirectory
|
|
@@ -86028,7 +87223,7 @@ import { fetch as fetch2 } from "undici";
|
|
|
86028
87223
|
// src/engine/storage/antigravity-usage-credentials.ts
|
|
86029
87224
|
import { readFile as readFile7 } from "node:fs/promises";
|
|
86030
87225
|
import { homedir as homedir4 } from "node:os";
|
|
86031
|
-
import { join as
|
|
87226
|
+
import { join as join25, resolve as resolve14 } from "node:path";
|
|
86032
87227
|
var agyOAuthTokenFileSchema = external_exports.object({
|
|
86033
87228
|
auth_method: external_exports.string().optional(),
|
|
86034
87229
|
id_token_email: external_exports.string().optional(),
|
|
@@ -86062,7 +87257,7 @@ function resolveGeminiHome2(environment) {
|
|
|
86062
87257
|
return resolve14(configured);
|
|
86063
87258
|
}
|
|
86064
87259
|
const home = environment["HOME"]?.trim() || environment["USERPROFILE"]?.trim() || homedir4();
|
|
86065
|
-
return
|
|
87260
|
+
return join25(resolve14(home), ".gemini");
|
|
86066
87261
|
}
|
|
86067
87262
|
function classifyAuthMethod(raw) {
|
|
86068
87263
|
const normalized = raw?.trim().toLowerCase() ?? "";
|
|
@@ -86097,10 +87292,10 @@ async function readAntigravityStoredCredentials(environment) {
|
|
|
86097
87292
|
};
|
|
86098
87293
|
}
|
|
86099
87294
|
const geminiHome = resolveGeminiHome2(environment);
|
|
86100
|
-
const cliDir =
|
|
87295
|
+
const cliDir = join25(geminiHome, "antigravity-cli");
|
|
86101
87296
|
const [cliSettingsRaw, sharedConfigRaw] = await Promise.all([
|
|
86102
|
-
readTextIfPresent(
|
|
86103
|
-
readTextIfPresent(
|
|
87297
|
+
readTextIfPresent(join25(cliDir, "settings.json")),
|
|
87298
|
+
readTextIfPresent(join25(geminiHome, "config", "config.json"))
|
|
86104
87299
|
]);
|
|
86105
87300
|
if (hasGatewayEnabled(cliSettingsRaw) || hasGatewayEnabled(sharedConfigRaw)) {
|
|
86106
87301
|
return {
|
|
@@ -86109,9 +87304,9 @@ async function readAntigravityStoredCredentials(environment) {
|
|
|
86109
87304
|
};
|
|
86110
87305
|
}
|
|
86111
87306
|
const projectFromEnv = environment["ANTIGRAVITY_PROJECT_ID"]?.trim() || environment["AGY_ACP_CCPA_PROJECT"]?.trim() || environment["GOOGLE_CLOUD_PROJECT"]?.trim();
|
|
86112
|
-
const projectFromCache = (await readTextIfPresent(
|
|
87307
|
+
const projectFromCache = (await readTextIfPresent(join25(cliDir, "cache", "default_project_id.txt")))?.trim();
|
|
86113
87308
|
const fallbackProjectId = projectFromEnv !== void 0 && projectFromEnv.length > 0 ? projectFromEnv : projectFromCache !== void 0 && projectFromCache.length > 0 ? projectFromCache : void 0;
|
|
86114
|
-
const agyTokenRaw = await readTextIfPresent(
|
|
87309
|
+
const agyTokenRaw = await readTextIfPresent(join25(cliDir, "antigravity-oauth-token"));
|
|
86115
87310
|
if (agyTokenRaw !== null) {
|
|
86116
87311
|
try {
|
|
86117
87312
|
const parsed = agyOAuthTokenFileSchema.safeParse(JSON.parse(agyTokenRaw));
|
|
@@ -86130,7 +87325,7 @@ async function readAntigravityStoredCredentials(environment) {
|
|
|
86130
87325
|
} catch {
|
|
86131
87326
|
}
|
|
86132
87327
|
}
|
|
86133
|
-
const acpTokenRaw = await readTextIfPresent(
|
|
87328
|
+
const acpTokenRaw = await readTextIfPresent(join25(geminiHome, "antigravity-acp", "acp_token.json"));
|
|
86134
87329
|
if (acpTokenRaw !== null) {
|
|
86135
87330
|
try {
|
|
86136
87331
|
const parsed = acpTokenFileSchema.safeParse(JSON.parse(acpTokenRaw));
|
|
@@ -87973,6 +89168,10 @@ async function normalizeOpenedSession(session, nativeSessionId, response, signal
|
|
|
87973
89168
|
...session.connection.commitLifecycle(response)
|
|
87974
89169
|
};
|
|
87975
89170
|
}
|
|
89171
|
+
function withTurnTokens(result, convert) {
|
|
89172
|
+
const tokens = convert(result);
|
|
89173
|
+
return tokens === void 0 ? result : { ...result, tokens };
|
|
89174
|
+
}
|
|
87976
89175
|
|
|
87977
89176
|
// src/engine/session/process/retained-agent-processes.ts
|
|
87978
89177
|
var RetainedAgentProcesses = class {
|
|
@@ -88216,11 +89415,11 @@ var AgentQueryProcesses = class {
|
|
|
88216
89415
|
};
|
|
88217
89416
|
|
|
88218
89417
|
// src/engine/acp/adapter/antigravity/conversation-handoff.ts
|
|
88219
|
-
import { join as
|
|
89418
|
+
import { join as join26 } from "node:path";
|
|
88220
89419
|
var TRANSCRIPT_TAIL_BYTES2 = 1048576;
|
|
88221
89420
|
var MAXIMUM_HANDOFF_CHARACTERS = 32e3;
|
|
88222
89421
|
var MAXIMUM_MESSAGE_CHARACTERS = 4e3;
|
|
88223
|
-
var
|
|
89422
|
+
var SESSION_UUID_PATTERN3 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu;
|
|
88224
89423
|
var USER_REQUEST_PATTERN = /<USER_REQUEST>\n?([\s\S]*?)\n?<\/USER_REQUEST>/u;
|
|
88225
89424
|
var HANDOFF_TAG = "previous_conversation";
|
|
88226
89425
|
var transcriptStepSchema2 = external_exports.object({
|
|
@@ -88246,12 +89445,12 @@ function messageFromStep(step) {
|
|
|
88246
89445
|
}
|
|
88247
89446
|
async function readConversationMessages(launchEnvironment, nativeSessionId) {
|
|
88248
89447
|
const geminiHome = resolveGeminiHome(launchEnvironment);
|
|
88249
|
-
if (geminiHome === void 0 || !
|
|
89448
|
+
if (geminiHome === void 0 || !SESSION_UUID_PATTERN3.test(nativeSessionId)) {
|
|
88250
89449
|
return null;
|
|
88251
89450
|
}
|
|
88252
89451
|
const tail = await readScopedFileTail(
|
|
88253
89452
|
geminiHome,
|
|
88254
|
-
|
|
89453
|
+
join26("antigravity-cli", "brain", nativeSessionId, ".system_generated", "logs", "transcript.jsonl"),
|
|
88255
89454
|
TRANSCRIPT_TAIL_BYTES2
|
|
88256
89455
|
);
|
|
88257
89456
|
if (tail === null) {
|
|
@@ -88420,12 +89619,25 @@ var AntigravityAdapter = class {
|
|
|
88420
89619
|
prompt = async (params) => {
|
|
88421
89620
|
const result = await this.#executionConnections.prompt(params);
|
|
88422
89621
|
const connection = this.#executionConnections.connection(params);
|
|
88423
|
-
if (connection !== void 0
|
|
88424
|
-
|
|
89622
|
+
if (connection !== void 0) {
|
|
89623
|
+
const recycleProcess = takeAntigravityProcessRecycleRequired(connection.connection, params.nativeSessionId);
|
|
89624
|
+
if (takeAntigravityUnusableNativeSession(connection.connection, params.nativeSessionId) && result.stopReason !== "cancelled") {
|
|
89625
|
+
throw new AcpExecutionError(UNUSABLE_NATIVE_SESSION_MESSAGE, {}, NATIVE_SESSION_UNUSABLE_ERROR_CODE);
|
|
89626
|
+
}
|
|
89627
|
+
if (recycleProcess) {
|
|
89628
|
+
return { ...result, recycleProcess: true };
|
|
89629
|
+
}
|
|
88425
89630
|
}
|
|
88426
89631
|
return result;
|
|
88427
89632
|
};
|
|
88428
89633
|
steer = (...args) => this.#executionConnections.steer(...args);
|
|
89634
|
+
trySettleIdlePrompt = async (params) => {
|
|
89635
|
+
const connection = this.#executionConnections.connection(params);
|
|
89636
|
+
if (connection === void 0) {
|
|
89637
|
+
return false;
|
|
89638
|
+
}
|
|
89639
|
+
return await trySettleAntigravityIdlePrompt(connection.connection, params.nativeSessionId);
|
|
89640
|
+
};
|
|
88429
89641
|
renameSession = (...args) => this.#executionConnections.renameSession(...args);
|
|
88430
89642
|
configureSession = (...args) => this.#executionConnections.configureSession(...args);
|
|
88431
89643
|
// Antigravity reports `thought_level` options only for the currently selected model.
|
|
@@ -88461,6 +89673,58 @@ var AntigravityAdapter = class {
|
|
|
88461
89673
|
);
|
|
88462
89674
|
};
|
|
88463
89675
|
|
|
89676
|
+
// src/engine/acp/harness/claude/turn-tokens.ts
|
|
89677
|
+
function reportedTokens(result) {
|
|
89678
|
+
const quota = result._meta?.quota;
|
|
89679
|
+
if (quota !== void 0 && quota.model_usage.length > 0) {
|
|
89680
|
+
return quota.model_usage.map(({ token_count: count }) => ({
|
|
89681
|
+
input: count.inputTokens,
|
|
89682
|
+
cacheRead: count.cachedInputTokens ?? 0,
|
|
89683
|
+
cacheWrite: count.cachedWriteTokens ?? 0,
|
|
89684
|
+
output: count.outputTokens
|
|
89685
|
+
}));
|
|
89686
|
+
}
|
|
89687
|
+
if (quota?.token_count != null) {
|
|
89688
|
+
const count = quota.token_count;
|
|
89689
|
+
return [
|
|
89690
|
+
{
|
|
89691
|
+
input: count.inputTokens,
|
|
89692
|
+
cacheRead: count.cachedInputTokens ?? 0,
|
|
89693
|
+
cacheWrite: count.cachedWriteTokens ?? 0,
|
|
89694
|
+
output: count.outputTokens
|
|
89695
|
+
}
|
|
89696
|
+
];
|
|
89697
|
+
}
|
|
89698
|
+
const usage = result.usage;
|
|
89699
|
+
if (usage == null) {
|
|
89700
|
+
return [];
|
|
89701
|
+
}
|
|
89702
|
+
return [
|
|
89703
|
+
{
|
|
89704
|
+
input: usage.inputTokens,
|
|
89705
|
+
cacheRead: usage.cachedReadTokens ?? 0,
|
|
89706
|
+
cacheWrite: usage.cachedWriteTokens ?? 0,
|
|
89707
|
+
output: usage.outputTokens
|
|
89708
|
+
}
|
|
89709
|
+
];
|
|
89710
|
+
}
|
|
89711
|
+
function claudeTurnTokens(result) {
|
|
89712
|
+
const reported = reportedTokens(result);
|
|
89713
|
+
if (reported.length === 0) {
|
|
89714
|
+
return void 0;
|
|
89715
|
+
}
|
|
89716
|
+
const sum = (count) => reported.reduce((total, tokens) => total + count(tokens), 0);
|
|
89717
|
+
const cachedInputTokens = sum((tokens) => tokens.cacheRead);
|
|
89718
|
+
const cacheWriteTokens = sum((tokens) => tokens.cacheWrite);
|
|
89719
|
+
const usage = {
|
|
89720
|
+
inputTokens: sum((tokens) => tokens.input) + cachedInputTokens + cacheWriteTokens,
|
|
89721
|
+
cachedInputTokens,
|
|
89722
|
+
cacheWriteTokens,
|
|
89723
|
+
outputTokens: sum((tokens) => tokens.output)
|
|
89724
|
+
};
|
|
89725
|
+
return isTurnTokenUsage(usage) ? usage : void 0;
|
|
89726
|
+
}
|
|
89727
|
+
|
|
88464
89728
|
// src/engine/acp/adapter/claude/adapter.ts
|
|
88465
89729
|
function openingRequest(params, execution) {
|
|
88466
89730
|
return {
|
|
@@ -88534,7 +89798,7 @@ var ClaudeAdapter = class {
|
|
|
88534
89798
|
closeSession = (...args) => this.#executionConnections.closeSession(...args);
|
|
88535
89799
|
releaseSession = (params) => this.#executionConnections.releaseSession(params);
|
|
88536
89800
|
readNativeHistoryRevision = (params) => this.#executionConnections.readNativeHistoryRevision(params);
|
|
88537
|
-
prompt = (...args) => this.#executionConnections.prompt(...args);
|
|
89801
|
+
prompt = async (...args) => withTurnTokens(await this.#executionConnections.prompt(...args), claudeTurnTokens);
|
|
88538
89802
|
steer = (...args) => this.#executionConnections.steer(...args);
|
|
88539
89803
|
renameSession = (...args) => this.#executionConnections.renameSession(...args);
|
|
88540
89804
|
configureSession = (...args) => this.#executionConnections.configureSession(...args);
|
|
@@ -88551,6 +89815,22 @@ var ClaudeAdapter = class {
|
|
|
88551
89815
|
);
|
|
88552
89816
|
};
|
|
88553
89817
|
|
|
89818
|
+
// src/engine/acp/harness/codex/turn-tokens.ts
|
|
89819
|
+
function codexTurnTokens(result) {
|
|
89820
|
+
const count = result._meta?.quota?.token_count;
|
|
89821
|
+
if (count == null) {
|
|
89822
|
+
return void 0;
|
|
89823
|
+
}
|
|
89824
|
+
const usage = {
|
|
89825
|
+
inputTokens: count.inputTokens,
|
|
89826
|
+
cachedInputTokens: count.cachedInputTokens ?? 0,
|
|
89827
|
+
cacheWriteTokens: count.cachedWriteTokens ?? 0,
|
|
89828
|
+
outputTokens: count.outputTokens,
|
|
89829
|
+
...count.reasoningOutputTokens === void 0 ? {} : { reasoningTokens: count.reasoningOutputTokens }
|
|
89830
|
+
};
|
|
89831
|
+
return isTurnTokenUsage(usage) ? usage : void 0;
|
|
89832
|
+
}
|
|
89833
|
+
|
|
88554
89834
|
// src/engine/acp/adapter/codex/tool-event.ts
|
|
88555
89835
|
var toolEventSchema = external_exports.looseObject({
|
|
88556
89836
|
sessionUpdate: external_exports.enum(["tool_call", "tool_call_update"]),
|
|
@@ -88722,7 +90002,7 @@ var CodexAdapter = class {
|
|
|
88722
90002
|
signal.throwIfAborted();
|
|
88723
90003
|
return { kind: "untracked" };
|
|
88724
90004
|
};
|
|
88725
|
-
prompt = (...args) => this.#executionConnections.prompt(...args);
|
|
90005
|
+
prompt = async (...args) => withTurnTokens(await this.#executionConnections.prompt(...args), codexTurnTokens);
|
|
88726
90006
|
steer = (...args) => this.#executionConnections.steer(...args);
|
|
88727
90007
|
renameSession = (...args) => this.#executionConnections.renameSession(...args);
|
|
88728
90008
|
configureSession = (...args) => this.#executionConnections.configureSession(...args);
|
|
@@ -89146,11 +90426,11 @@ var RuntimeAgentDependencies = class {
|
|
|
89146
90426
|
};
|
|
89147
90427
|
|
|
89148
90428
|
// src/engine/runtime/observability/diagnostic-log.ts
|
|
89149
|
-
import { join as
|
|
90429
|
+
import { join as join29 } from "node:path";
|
|
89150
90430
|
|
|
89151
90431
|
// src/engine/storage/logs/bounded-log.ts
|
|
89152
90432
|
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync10, renameSync as renameSync2, statSync as statSync5, writeFileSync as writeFileSync2 } from "node:fs";
|
|
89153
|
-
import { join as
|
|
90433
|
+
import { join as join27 } from "node:path";
|
|
89154
90434
|
var BoundedLineLog = class {
|
|
89155
90435
|
#path;
|
|
89156
90436
|
#maximumBytes;
|
|
@@ -89159,7 +90439,7 @@ var BoundedLineLog = class {
|
|
|
89159
90439
|
#onWriteFailure;
|
|
89160
90440
|
constructor(directory, filename, maximumBytes, onWriteFailure = () => void 0) {
|
|
89161
90441
|
this.#directory = directory;
|
|
89162
|
-
this.#path =
|
|
90442
|
+
this.#path = join27(directory, filename);
|
|
89163
90443
|
this.#maximumBytes = maximumBytes;
|
|
89164
90444
|
this.#onWriteFailure = onWriteFailure;
|
|
89165
90445
|
}
|
|
@@ -89210,21 +90490,21 @@ var BoundedLineLog = class {
|
|
|
89210
90490
|
|
|
89211
90491
|
// src/engine/storage/logs/log-files.ts
|
|
89212
90492
|
import { readFileSync as readFileSync11 } from "node:fs";
|
|
89213
|
-
import { join as
|
|
90493
|
+
import { join as join28 } from "node:path";
|
|
89214
90494
|
var DAEMON_LOG_FILENAME = "daemon.log";
|
|
89215
90495
|
var WORKER_LIFECYCLE_LOG_FILENAME = "worker-lifecycle.log";
|
|
89216
90496
|
function unhandledRejectionLogFilename(role) {
|
|
89217
90497
|
return `unhandled-rejections-${role}.log`;
|
|
89218
90498
|
}
|
|
89219
90499
|
function logDirectory(dataDirectory) {
|
|
89220
|
-
return
|
|
90500
|
+
return join28(dataDirectory, "logs");
|
|
89221
90501
|
}
|
|
89222
90502
|
function processLogPaths(dataDirectory) {
|
|
89223
90503
|
return [
|
|
89224
90504
|
WORKER_LIFECYCLE_LOG_FILENAME,
|
|
89225
90505
|
unhandledRejectionLogFilename("manager"),
|
|
89226
90506
|
unhandledRejectionLogFilename("worker")
|
|
89227
|
-
].map((filename) =>
|
|
90507
|
+
].map((filename) => join28(logDirectory(dataDirectory), filename));
|
|
89228
90508
|
}
|
|
89229
90509
|
function readLogText(path6) {
|
|
89230
90510
|
try {
|
|
@@ -89302,7 +90582,7 @@ var RuntimeDiagnosticLog = class {
|
|
|
89302
90582
|
this.#maximumBytes = maximumBytes;
|
|
89303
90583
|
const processLogsDirectory = options.processLogsDirectory;
|
|
89304
90584
|
this.#sources = [
|
|
89305
|
-
{ maximumBytes, path:
|
|
90585
|
+
{ maximumBytes, path: join29(directory, DAEMON_LOG_FILENAME) },
|
|
89306
90586
|
// The process logs a Runtime does not own, but must read to explain its own deaths.
|
|
89307
90587
|
...processLogsDirectory === void 0 ? [] : processLogPaths(processLogsDirectory).map((path6) => ({ maximumBytes: null, path: path6 }))
|
|
89308
90588
|
];
|
|
@@ -90437,7 +91717,7 @@ function sql(strings, ...params) {
|
|
|
90437
91717
|
return new SQL([new StringChunk(str)]);
|
|
90438
91718
|
}
|
|
90439
91719
|
_sql.raw = raw;
|
|
90440
|
-
function
|
|
91720
|
+
function join37(chunks, separator) {
|
|
90441
91721
|
const result = [];
|
|
90442
91722
|
for (const [i, chunk] of chunks.entries()) {
|
|
90443
91723
|
if (i > 0 && separator !== void 0) result.push(separator);
|
|
@@ -90445,7 +91725,7 @@ function sql(strings, ...params) {
|
|
|
90445
91725
|
}
|
|
90446
91726
|
return new SQL(result);
|
|
90447
91727
|
}
|
|
90448
|
-
_sql.join =
|
|
91728
|
+
_sql.join = join37;
|
|
90449
91729
|
function identifier2(value) {
|
|
90450
91730
|
return new Name(value);
|
|
90451
91731
|
}
|
|
@@ -92590,7 +93870,7 @@ var SQLiteSelectBase = class extends TypedQueryBuilder {
|
|
|
92590
93870
|
const baseTableName = this.tableName;
|
|
92591
93871
|
const tableName = getTableLikeName(table);
|
|
92592
93872
|
for (const item of extractUsedTable(table)) this.usedTables.add(item);
|
|
92593
|
-
if (typeof tableName === "string" && this.config.joins?.some((
|
|
93873
|
+
if (typeof tableName === "string" && this.config.joins?.some((join37) => join37.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
92594
93874
|
if (!this.isPartialSelect) {
|
|
92595
93875
|
if (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === "string") this.config.fields = { [baseTableName]: this.config.fields };
|
|
92596
93876
|
if (typeof tableName === "string" && !is(table, SQL)) {
|
|
@@ -93429,7 +94709,7 @@ var SQLiteDialect = class {
|
|
|
93429
94709
|
if (!joins2) return;
|
|
93430
94710
|
const withEntries = Object.entries(joins2).filter(([_, v]) => v);
|
|
93431
94711
|
if (!withEntries.length) return;
|
|
93432
|
-
return sql.join(withEntries.map(([k2,
|
|
94712
|
+
return sql.join(withEntries.map(([k2, join37]) => {
|
|
93433
94713
|
const relation = tableConfig.relations[k2];
|
|
93434
94714
|
const isSingle2 = is(relation, One2);
|
|
93435
94715
|
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
|
@@ -93440,7 +94720,7 @@ var SQLiteDialect = class {
|
|
|
93440
94720
|
table: targetTable,
|
|
93441
94721
|
mode: isSingle2 ? "first" : "many",
|
|
93442
94722
|
schema,
|
|
93443
|
-
queryConfig:
|
|
94723
|
+
queryConfig: join37,
|
|
93444
94724
|
tableConfig: schema[relation.targetTableName],
|
|
93445
94725
|
relationWhere: filter,
|
|
93446
94726
|
isNested: true,
|
|
@@ -93454,7 +94734,7 @@ var SQLiteDialect = class {
|
|
|
93454
94734
|
key: k2,
|
|
93455
94735
|
selection: innerQuery.selection,
|
|
93456
94736
|
isArray: !isSingle2,
|
|
93457
|
-
isOptional: (relation.optional ?? false) ||
|
|
94737
|
+
isOptional: (relation.optional ?? false) || join37 !== true && !!join37.where
|
|
93458
94738
|
});
|
|
93459
94739
|
const jsonColumns = sql.join(innerQuery.selection.map((s) => {
|
|
93460
94740
|
return sql`${sql.raw(this.escapeString(s.key))}, ${s.selection ? sql`${jsonb}(${sql.identifier(s.key)})` : sql.identifier(s.key)}`;
|
|
@@ -94070,7 +95350,7 @@ var SQLiteUpdateBase = class {
|
|
|
94070
95350
|
createJoin(joinType) {
|
|
94071
95351
|
return ((table, on2) => {
|
|
94072
95352
|
const tableName = getTableLikeName(table);
|
|
94073
|
-
if (typeof tableName === "string" && this.config.joins.some((
|
|
95353
|
+
if (typeof tableName === "string" && this.config.joins.some((join37) => join37.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
94074
95354
|
if (typeof on2 === "function") {
|
|
94075
95355
|
const from = this.config.from ? is(table, SQLiteTable) ? table[Table.Symbol.Columns] : is(table, Subquery) ? table._.selectedFields : is(table, SQLiteViewBase) ? table[ViewBaseConfig].selectedFields : void 0 : void 0;
|
|
94076
95356
|
on2 = on2(new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
|
|
@@ -95024,8 +96304,8 @@ var SessionEventCacheTable = class {
|
|
|
95024
96304
|
// src/engine/storage/sqlite/local-databases.ts
|
|
95025
96305
|
import { createHash as createHash4 } from "node:crypto";
|
|
95026
96306
|
import { existsSync as existsSync9 } from "node:fs";
|
|
95027
|
-
import { join as
|
|
95028
|
-
import { DatabaseSync as
|
|
96307
|
+
import { join as join30 } from "node:path";
|
|
96308
|
+
import { DatabaseSync as DatabaseSync4 } from "node:sqlite";
|
|
95029
96309
|
|
|
95030
96310
|
// src/engine/generated/acp-session-store-migrations.ts
|
|
95031
96311
|
var acpSessionStoreMigrations = [
|
|
@@ -95110,7 +96390,7 @@ var sessionTitlePreferencesMigrations = [
|
|
|
95110
96390
|
// src/engine/storage/sqlite/local-sqlite-database.ts
|
|
95111
96391
|
import { chmodSync, mkdirSync as mkdirSync4 } from "node:fs";
|
|
95112
96392
|
import { dirname as dirname9 } from "node:path";
|
|
95113
|
-
import { DatabaseSync as
|
|
96393
|
+
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
95114
96394
|
|
|
95115
96395
|
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20261028.1_@types+better-sqlite3@7.6_12a6406e88a0f7753ae87b6d067c841c/node_modules/drizzle-orm/node-sqlite/session.js
|
|
95116
96396
|
var NodeSQLiteSession = class extends SQLiteAsyncSession {
|
|
@@ -95184,7 +96464,7 @@ var NodeSQLiteTransaction = class NodeSQLiteTransaction2 extends SQLiteAsyncTran
|
|
|
95184
96464
|
};
|
|
95185
96465
|
|
|
95186
96466
|
// ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20261028.1_@types+better-sqlite3@7.6_12a6406e88a0f7753ae87b6d067c841c/node_modules/drizzle-orm/node-sqlite/driver.js
|
|
95187
|
-
import { DatabaseSync } from "node:sqlite";
|
|
96467
|
+
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
95188
96468
|
var NodeSQLiteDatabase = class extends SQLiteAsyncDatabase {
|
|
95189
96469
|
static [entityKind] = "NodeSQLiteDatabase";
|
|
95190
96470
|
};
|
|
@@ -95199,14 +96479,14 @@ function construct(client2, config2 = {}) {
|
|
|
95199
96479
|
return db2;
|
|
95200
96480
|
}
|
|
95201
96481
|
function drizzle(...params) {
|
|
95202
|
-
if (params[0] === void 0 || typeof params[0] === "string") return construct(params[0] === void 0 ? new
|
|
96482
|
+
if (params[0] === void 0 || typeof params[0] === "string") return construct(params[0] === void 0 ? new DatabaseSync2(":memory:") : new DatabaseSync2(params[0]), params[1]);
|
|
95203
96483
|
const { connection, client: client2, ...config2 } = params[0];
|
|
95204
96484
|
if (client2) return construct(client2, config2);
|
|
95205
96485
|
if (typeof connection === "object") {
|
|
95206
96486
|
const { path: path6, ...options } = connection;
|
|
95207
|
-
return construct(new
|
|
96487
|
+
return construct(new DatabaseSync2(path6 ?? ":memory:", options), config2);
|
|
95208
96488
|
}
|
|
95209
|
-
return construct(new
|
|
96489
|
+
return construct(new DatabaseSync2(connection ?? ":memory:"), config2);
|
|
95210
96490
|
}
|
|
95211
96491
|
(function(_drizzle) {
|
|
95212
96492
|
function mock(config2) {
|
|
@@ -95223,7 +96503,7 @@ var LocalSqliteDatabase = class {
|
|
|
95223
96503
|
constructor(path6, label, migrations, pragmas = []) {
|
|
95224
96504
|
this.path = path6;
|
|
95225
96505
|
mkdirSync4(dirname9(path6), { mode: 448, recursive: true });
|
|
95226
|
-
this.#sqlite = new
|
|
96506
|
+
this.#sqlite = new DatabaseSync3(path6);
|
|
95227
96507
|
chmodSync(path6, 384);
|
|
95228
96508
|
try {
|
|
95229
96509
|
for (const pragma of pragmas) {
|
|
@@ -95277,16 +96557,16 @@ var LocalSqliteDatabase = class {
|
|
|
95277
96557
|
function channelSessionDatabasePaths(stateDirectory, channelId) {
|
|
95278
96558
|
const channelHash = createHash4("sha256").update(channelId).digest("hex");
|
|
95279
96559
|
return {
|
|
95280
|
-
cancellations:
|
|
95281
|
-
events:
|
|
95282
|
-
sessions:
|
|
96560
|
+
cancellations: join30(stateDirectory, "sessions", `${channelHash}.cancellations.sqlite`),
|
|
96561
|
+
events: join30(stateDirectory, "sessions", `${channelHash}.events.sqlite`),
|
|
96562
|
+
sessions: join30(stateDirectory, "sessions", `${channelHash}.sqlite`)
|
|
95283
96563
|
};
|
|
95284
96564
|
}
|
|
95285
96565
|
function recordAppliedAdmissionOrder(path6) {
|
|
95286
96566
|
if (!existsSync9(path6)) {
|
|
95287
96567
|
return;
|
|
95288
96568
|
}
|
|
95289
|
-
const database = new
|
|
96569
|
+
const database = new DatabaseSync4(path6);
|
|
95290
96570
|
try {
|
|
95291
96571
|
const version3 = database.prepare("PRAGMA user_version").get()?.["user_version"];
|
|
95292
96572
|
const column = database.prepare("SELECT name FROM pragma_table_info('execution_receipt') WHERE name = 'admission_order'").get();
|
|
@@ -97117,6 +98397,7 @@ var AgentSession = class _AgentSession {
|
|
|
97117
98397
|
agentTurnCommand = () => this.#agentTurn?.commandId;
|
|
97118
98398
|
/** The command whose prompt the Agent is running, which only the Agent can report as delegated. */
|
|
97119
98399
|
#delegableCommandId = null;
|
|
98400
|
+
#processRecycleRequired = false;
|
|
97120
98401
|
#modelEffort = null;
|
|
97121
98402
|
#scope;
|
|
97122
98403
|
#subscriber;
|
|
@@ -97672,10 +98953,17 @@ var AgentSession = class _AgentSession {
|
|
|
97672
98953
|
this.#delegableCommandId = null;
|
|
97673
98954
|
}
|
|
97674
98955
|
});
|
|
98956
|
+
if (result.recycleProcess === true) {
|
|
98957
|
+
this.#processRecycleRequired = true;
|
|
98958
|
+
}
|
|
97675
98959
|
this.writeStoredSession((/* @__PURE__ */ new Date()).toISOString());
|
|
97676
98960
|
if (lifecycle !== void 0) {
|
|
97677
98961
|
const messageId = result._meta?.messageId;
|
|
97678
|
-
const completion = {
|
|
98962
|
+
const completion = {
|
|
98963
|
+
...messageId === void 0 ? {} : { messageId },
|
|
98964
|
+
stopReason: result.stopReason,
|
|
98965
|
+
...result.tokens === void 0 ? {} : { usage: result.tokens }
|
|
98966
|
+
};
|
|
97679
98967
|
if (result.stopReason !== "cancelled" && this.#recordedBackground.length > 0) {
|
|
97680
98968
|
this.#hold(
|
|
97681
98969
|
options.commandId,
|
|
@@ -97734,7 +99022,10 @@ var AgentSession = class _AgentSession {
|
|
|
97734
99022
|
validatePromptContent(options, this.#capabilities);
|
|
97735
99023
|
options.signal.throwIfAborted();
|
|
97736
99024
|
const lifecycle = options.lifecycle;
|
|
97737
|
-
|
|
99025
|
+
const recordSteerStart = async () => {
|
|
99026
|
+
if (lifecycle === void 0) {
|
|
99027
|
+
return;
|
|
99028
|
+
}
|
|
97738
99029
|
await this.recordLifecycleEvent({
|
|
97739
99030
|
payload: {
|
|
97740
99031
|
commandId: options.commandId,
|
|
@@ -97755,9 +99046,10 @@ var AgentSession = class _AgentSession {
|
|
|
97755
99046
|
},
|
|
97756
99047
|
type: "lifecycle-metadata"
|
|
97757
99048
|
});
|
|
97758
|
-
}
|
|
99049
|
+
};
|
|
97759
99050
|
try {
|
|
97760
99051
|
const outcome = await this.#adapter.steer({ ...this.#target(), content: options, signal: options.signal });
|
|
99052
|
+
await recordSteerStart();
|
|
97761
99053
|
if (lifecycle !== void 0) {
|
|
97762
99054
|
await this.recordLifecycleEvent({
|
|
97763
99055
|
payload: {
|
|
@@ -97773,6 +99065,10 @@ var AgentSession = class _AgentSession {
|
|
|
97773
99065
|
return outcome.outcome;
|
|
97774
99066
|
} catch (error62) {
|
|
97775
99067
|
const failure2 = error62 instanceof AcpExecutionError ? error62 : new AcpExecutionError("ACP agent execution failed", { cause: error62 });
|
|
99068
|
+
if (failure2.code === "steering_target_unavailable") {
|
|
99069
|
+
throw failure2;
|
|
99070
|
+
}
|
|
99071
|
+
await recordSteerStart();
|
|
97776
99072
|
if (lifecycle !== void 0) {
|
|
97777
99073
|
await this.recordLifecycleEvent({
|
|
97778
99074
|
payload: {
|
|
@@ -97788,6 +99084,17 @@ var AgentSession = class _AgentSession {
|
|
|
97788
99084
|
throw failure2;
|
|
97789
99085
|
}
|
|
97790
99086
|
};
|
|
99087
|
+
trySettleIdlePrompt = async () => {
|
|
99088
|
+
if (this.#nativeIdentity.kind !== "bound" || this.#adapter.trySettleIdlePrompt === void 0) {
|
|
99089
|
+
return false;
|
|
99090
|
+
}
|
|
99091
|
+
return await this.#adapter.trySettleIdlePrompt(this.#target());
|
|
99092
|
+
};
|
|
99093
|
+
takeProcessRecycleRequired = () => {
|
|
99094
|
+
const required2 = this.#processRecycleRequired;
|
|
99095
|
+
this.#processRecycleRequired = false;
|
|
99096
|
+
return required2;
|
|
99097
|
+
};
|
|
97791
99098
|
cancel = async (signal) => {
|
|
97792
99099
|
signal.throwIfAborted();
|
|
97793
99100
|
await this.#interactions.cancelPendingInteractions();
|
|
@@ -98018,14 +99325,16 @@ var AgentSession = class _AgentSession {
|
|
|
98018
99325
|
if (this.#agentTurn?.held === true) {
|
|
98019
99326
|
this.#agentTurn = null;
|
|
98020
99327
|
}
|
|
99328
|
+
const usage = held.completion.usage === void 0 ? {} : { usage: held.completion.usage };
|
|
98021
99329
|
await this.recordLifecycleEvent({
|
|
98022
99330
|
payload: failure2 !== void 0 ? {
|
|
98023
99331
|
attemptId: held.attemptId,
|
|
98024
99332
|
code: failure2.code,
|
|
98025
99333
|
commandId: held.commandId,
|
|
98026
99334
|
kind: "prompt.failed",
|
|
98027
|
-
message: truncate(failure2.message, 500)
|
|
98028
|
-
|
|
99335
|
+
message: truncate(failure2.message, 500),
|
|
99336
|
+
...usage
|
|
99337
|
+
} : held.cancelled ? { commandId: held.commandId, kind: "prompt.completed", stopReason: "cancelled", ...usage } : { commandId: held.commandId, kind: "prompt.completed", ...held.completion },
|
|
98029
99338
|
type: "lifecycle-metadata"
|
|
98030
99339
|
});
|
|
98031
99340
|
this.#getObserver().onAgentTurn?.(this.#mobiusSessionId, this.#agentTurn?.commandId ?? null);
|
|
@@ -98484,9 +99793,9 @@ var SessionManager2 = class {
|
|
|
98484
99793
|
* Releases a closed or idle Session's process while keeping its title, settings and native
|
|
98485
99794
|
* identity available for the next preparation. This does not mark the Session closed.
|
|
98486
99795
|
*/
|
|
98487
|
-
async #stopSessionProcess(sessionId, runtime) {
|
|
99796
|
+
async #stopSessionProcess(sessionId, runtime, close = () => runtime.close()) {
|
|
98488
99797
|
this.#executionProcesses.detach(sessionId, runtime);
|
|
98489
|
-
const retirement = this.#processes.retire(runtime,
|
|
99798
|
+
const retirement = this.#processes.retire(runtime, close);
|
|
98490
99799
|
this.#sessionRetirements.set(sessionId, retirement);
|
|
98491
99800
|
try {
|
|
98492
99801
|
await retirement;
|
|
@@ -98952,6 +100261,17 @@ var SessionManager2 = class {
|
|
|
98952
100261
|
});
|
|
98953
100262
|
/** Whether a steering prompt can join the named execution: the one rule every steering check asks. */
|
|
98954
100263
|
acceptsSteering = (sessionId, targetCommandId) => this.#executions.acceptsSteering(sessionId, targetCommandId);
|
|
100264
|
+
/**
|
|
100265
|
+
* Asks an active session whose reply already finished while only an orphan background shell command
|
|
100266
|
+
* keeps its native prompt open to settle cleanly so a follow-up prompt can start at once.
|
|
100267
|
+
*/
|
|
100268
|
+
trySettleIdlePrompt = async (sessionId) => {
|
|
100269
|
+
const runtime = this.#executionProcesses.get(sessionId);
|
|
100270
|
+
if (runtime === void 0) {
|
|
100271
|
+
return false;
|
|
100272
|
+
}
|
|
100273
|
+
return await runtime.trySettleIdlePrompt();
|
|
100274
|
+
};
|
|
98955
100275
|
steerPrompt = async (options) => this.#operations.run(options, async (options2) => {
|
|
98956
100276
|
if (!this.acceptsSteering(options2.sessionId, options2.targetCommandId)) {
|
|
98957
100277
|
throw new AcpExecutionError("The target turn is no longer active", {}, "steering_target_unavailable");
|
|
@@ -99016,6 +100336,9 @@ var SessionManager2 = class {
|
|
|
99016
100336
|
...options2,
|
|
99017
100337
|
cancellationRequested: cancelled
|
|
99018
100338
|
});
|
|
100339
|
+
if (runtime.takeProcessRecycleRequired()) {
|
|
100340
|
+
await this.#stopSessionProcess(options2.sessionId, runtime, () => runtime.closeProcess());
|
|
100341
|
+
}
|
|
99019
100342
|
return cancelled() ? { stopReason: "cancelled" } : result;
|
|
99020
100343
|
} catch (error62) {
|
|
99021
100344
|
if (cancelled()) {
|
|
@@ -100180,6 +101503,13 @@ var ActiveRuntimeTurn = class {
|
|
|
100180
101503
|
this.#admission = { kind: "admitted", disposition };
|
|
100181
101504
|
return disposition;
|
|
100182
101505
|
};
|
|
101506
|
+
/**
|
|
101507
|
+
* Moves a steering prompt that could not join its finished target into normal FIFO execution
|
|
101508
|
+
* so it runs as a prompt of its own once the finished target releases the Session.
|
|
101509
|
+
*/
|
|
101510
|
+
fallbackSteerToQueue = () => {
|
|
101511
|
+
this.#admission = { kind: "admitted", disposition: SessionPromptDisposition.Queue };
|
|
101512
|
+
};
|
|
100183
101513
|
queuePromotion = () => {
|
|
100184
101514
|
if (this.#admission.kind === "queued") {
|
|
100185
101515
|
return this.#admission.promotion.promise;
|
|
@@ -100380,6 +101710,25 @@ var SessionExecutionState = class {
|
|
|
100380
101710
|
}
|
|
100381
101711
|
}
|
|
100382
101712
|
};
|
|
101713
|
+
/**
|
|
101714
|
+
* Claims the Session FIFO for a steering prompt whose target just finished before steering
|
|
101715
|
+
* could inject, waiting until any earlier non-steering execution releases the Session.
|
|
101716
|
+
*/
|
|
101717
|
+
fallbackSteerToPrompt = async (turn, waitSignal) => {
|
|
101718
|
+
waitSignal.throwIfAborted();
|
|
101719
|
+
turn.fallbackSteerToQueue();
|
|
101720
|
+
const head = () => [...this.#turnsByCommandId.values()].find(
|
|
101721
|
+
(candidate) => candidate.effectiveDisposition() !== SessionPromptDisposition.Steer
|
|
101722
|
+
);
|
|
101723
|
+
for (; ; ) {
|
|
101724
|
+
waitSignal.throwIfAborted();
|
|
101725
|
+
const first = head();
|
|
101726
|
+
if (first === void 0 || first === turn) {
|
|
101727
|
+
return;
|
|
101728
|
+
}
|
|
101729
|
+
await waitForTurnCompletion(first, waitSignal);
|
|
101730
|
+
}
|
|
101731
|
+
};
|
|
100383
101732
|
};
|
|
100384
101733
|
|
|
100385
101734
|
// src/engine/session/turn/session-turns.ts
|
|
@@ -100461,6 +101810,7 @@ var SessionTurns = class {
|
|
|
100461
101810
|
return { turn: null, queued: [] };
|
|
100462
101811
|
};
|
|
100463
101812
|
admitAndWait = async (turn, waitSignal, onQueued) => this.session(turn.command.sessionId).admitAndWait(turn, waitSignal, onQueued);
|
|
101813
|
+
fallbackSteerToPrompt = async (turn, waitSignal) => await this.session(turn.command.sessionId).fallbackSteerToPrompt(turn, waitSignal);
|
|
100464
101814
|
/** Discards empty session states so the index does not grow unboundedly. */
|
|
100465
101815
|
sweep = () => {
|
|
100466
101816
|
for (const [sessionId, session] of this.#bySessionId) {
|
|
@@ -100476,7 +101826,7 @@ var SessionTurns = class {
|
|
|
100476
101826
|
|
|
100477
101827
|
// src/engine/session/workspace/workspace-directory.ts
|
|
100478
101828
|
import { homedir as homedir5 } from "node:os";
|
|
100479
|
-
import { basename as basename8, dirname as dirname10, isAbsolute as isAbsolute16, join as
|
|
101829
|
+
import { basename as basename8, dirname as dirname10, isAbsolute as isAbsolute16, join as join31, normalize as normalize2, relative as relative3 } from "node:path";
|
|
100480
101830
|
|
|
100481
101831
|
// src/engine/session/workspace/local-authorization-error.ts
|
|
100482
101832
|
var LocalAuthorizationError = class extends OperationError {
|
|
@@ -100622,7 +101972,7 @@ var WorkspaceDirectoryService = class {
|
|
|
100622
101972
|
continue;
|
|
100623
101973
|
}
|
|
100624
101974
|
try {
|
|
100625
|
-
const path6 = await this.resolvePath(
|
|
101975
|
+
const path6 = await this.resolvePath(join31(target, child.name), signal);
|
|
100626
101976
|
entries.push({ directoryId: encodePath(path6), name: child.name });
|
|
100627
101977
|
} catch (cause) {
|
|
100628
101978
|
signal.throwIfAborted();
|
|
@@ -100807,13 +102157,13 @@ function buildSessionLayer(options) {
|
|
|
100807
102157
|
|
|
100808
102158
|
// src/engine/session/content/external-content-store.ts
|
|
100809
102159
|
import { createHash as createHash8 } from "node:crypto";
|
|
100810
|
-
import { extname as extname2, join as
|
|
102160
|
+
import { extname as extname2, join as join33 } from "node:path";
|
|
100811
102161
|
import { pathToFileURL as pathToFileURL3 } from "node:url";
|
|
100812
102162
|
|
|
100813
102163
|
// src/engine/storage/files/scratch-directory.ts
|
|
100814
102164
|
import { randomUUID as randomUUID18 } from "node:crypto";
|
|
100815
102165
|
import { lstat as lstat4, mkdir as mkdir5, readdir as readdir6, readFile as readFile8, realpath as realpath7, rename as rename4, rm as rm5, stat as stat6, utimes, writeFile as writeFile2 } from "node:fs/promises";
|
|
100816
|
-
import { dirname as dirname11, join as
|
|
102166
|
+
import { dirname as dirname11, join as join32 } from "node:path";
|
|
100817
102167
|
async function atomicWrite(path6, bytes, signal) {
|
|
100818
102168
|
const temporary = `${path6}.${randomUUID18()}.tmp`;
|
|
100819
102169
|
try {
|
|
@@ -100827,7 +102177,7 @@ async function atomicWrite(path6, bytes, signal) {
|
|
|
100827
102177
|
var ScratchDirectory = class {
|
|
100828
102178
|
#root;
|
|
100829
102179
|
constructor(parent) {
|
|
100830
|
-
this.#root =
|
|
102180
|
+
this.#root = join32(parent, randomUUID18());
|
|
100831
102181
|
}
|
|
100832
102182
|
/** Refreshes this directory's lease and removes sibling directories whose lease is older than `leaseMilliseconds`. */
|
|
100833
102183
|
refreshLease = async (leaseMilliseconds) => {
|
|
@@ -100838,7 +102188,7 @@ var ScratchDirectory = class {
|
|
|
100838
102188
|
if (!directory.isDirectory() || !/^[a-f0-9-]{36}$/u.test(directory.name)) {
|
|
100839
102189
|
continue;
|
|
100840
102190
|
}
|
|
100841
|
-
const path6 =
|
|
102191
|
+
const path6 = join32(dirname11(this.#root), directory.name);
|
|
100842
102192
|
if (path6 === this.#root) {
|
|
100843
102193
|
continue;
|
|
100844
102194
|
}
|
|
@@ -100853,10 +102203,10 @@ var ScratchDirectory = class {
|
|
|
100853
102203
|
};
|
|
100854
102204
|
/** Writes `bytes` atomically to `<group>/<name>` with owner-only permissions and returns the path. */
|
|
100855
102205
|
write = async (group, name2, bytes, signal) => {
|
|
100856
|
-
const directory =
|
|
102206
|
+
const directory = join32(this.#root, group);
|
|
100857
102207
|
await mkdir5(directory, { mode: 448, recursive: true });
|
|
100858
102208
|
signal.throwIfAborted();
|
|
100859
|
-
const path6 =
|
|
102209
|
+
const path6 = join32(directory, name2);
|
|
100860
102210
|
await atomicWrite(path6, bytes, signal);
|
|
100861
102211
|
return path6;
|
|
100862
102212
|
};
|
|
@@ -100907,7 +102257,7 @@ var LocalExternalContentStore = class {
|
|
|
100907
102257
|
#expirationTimer;
|
|
100908
102258
|
#cleanup = Promise.resolve();
|
|
100909
102259
|
constructor(stateDirectory) {
|
|
100910
|
-
this.#scratch = new ScratchDirectory(
|
|
102260
|
+
this.#scratch = new ScratchDirectory(join33(stateDirectory, "tmp", "session-content"));
|
|
100911
102261
|
this.#expirationTimer = setInterval(() => {
|
|
100912
102262
|
void this.#expire().catch(() => void 0);
|
|
100913
102263
|
}, 6e4);
|
|
@@ -101315,7 +102665,7 @@ var AgentProcessPool = class {
|
|
|
101315
102665
|
|
|
101316
102666
|
// src/engine/session/settings/agent-settings-cache.ts
|
|
101317
102667
|
import { createHash as createHash9, randomUUID as randomUUID19 } from "node:crypto";
|
|
101318
|
-
import { join as
|
|
102668
|
+
import { join as join34 } from "node:path";
|
|
101319
102669
|
var CACHE_FILE_LIMIT = 32 * 1024 * 1024;
|
|
101320
102670
|
var CACHE_FORMAT = 1;
|
|
101321
102671
|
var generationSchema = external_exports.union([external_exports.literal("initial"), external_exports.uuid()]);
|
|
@@ -101380,8 +102730,8 @@ var AgentSettingsCache = class {
|
|
|
101380
102730
|
#generationPath;
|
|
101381
102731
|
#generation = 0;
|
|
101382
102732
|
constructor(stateDirectory) {
|
|
101383
|
-
this.#directory =
|
|
101384
|
-
this.#generationPath =
|
|
102733
|
+
this.#directory = join34(stateDirectory, "agent-settings");
|
|
102734
|
+
this.#generationPath = join34(this.#directory, "generation");
|
|
101385
102735
|
}
|
|
101386
102736
|
get generation() {
|
|
101387
102737
|
return this.#generation;
|
|
@@ -101392,7 +102742,7 @@ var AgentSettingsCache = class {
|
|
|
101392
102742
|
};
|
|
101393
102743
|
open = async (agent2, signal) => {
|
|
101394
102744
|
const inspections = /* @__PURE__ */ new Map();
|
|
101395
|
-
const path6 =
|
|
102745
|
+
const path6 = join34(this.#directory, `${hash2(agent2.id)}.json`);
|
|
101396
102746
|
const fingerprint = hash2([
|
|
101397
102747
|
agent2.agentVersion,
|
|
101398
102748
|
agent2.adapterVersion,
|
|
@@ -102657,14 +104007,14 @@ function createContentWriteCommands(context) {
|
|
|
102657
104007
|
import { WebSocket as WebSocket5 } from "undici";
|
|
102658
104008
|
|
|
102659
104009
|
// src/engine/session/content/session-files.ts
|
|
102660
|
-
import { basename as basename9, extname as extname3, isAbsolute as isAbsolute18, join as
|
|
104010
|
+
import { basename as basename9, extname as extname3, isAbsolute as isAbsolute18, join as join36, normalize as normalize3, resolve as resolve18 } from "node:path";
|
|
102661
104011
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
102662
104012
|
|
|
102663
104013
|
// src/engine/storage/files/workspace-files.ts
|
|
102664
104014
|
var import_ignore = __toESM(require_ignore(), 1);
|
|
102665
104015
|
import { constants as constants6 } from "node:fs";
|
|
102666
104016
|
import { lstat as lstat5, open as open6, readdir as readdir7, realpath as realpath8 } from "node:fs/promises";
|
|
102667
|
-
import { dirname as dirname12, isAbsolute as isAbsolute17, join as
|
|
104017
|
+
import { dirname as dirname12, isAbsolute as isAbsolute17, join as join35, parse as parse5, relative as relative4, sep as sep6 } from "node:path";
|
|
102668
104018
|
var MAXIMUM_NAME_LENGTH = 255;
|
|
102669
104019
|
var MAXIMUM_PATH_LENGTH = 1024;
|
|
102670
104020
|
var MAXIMUM_IGNORE_FILE_BYTES = 1024 * 1024;
|
|
@@ -102743,7 +104093,7 @@ async function readOpenedDirectory(root, target, handle, offset, limit, signal)
|
|
|
102743
104093
|
if (entry.name.includes("\\") || entry.name.length > MAXIMUM_NAME_LENGTH) {
|
|
102744
104094
|
continue;
|
|
102745
104095
|
}
|
|
102746
|
-
const path6 = portable(relative4(root,
|
|
104096
|
+
const path6 = portable(relative4(root, join35(target, entry.name)));
|
|
102747
104097
|
const matchedPath = entry.isDirectory() ? `${path6}/` : path6;
|
|
102748
104098
|
if (path6.length > MAXIMUM_PATH_LENGTH || isGitPath(path6) || matcher.ignores(matchedPath)) {
|
|
102749
104099
|
continue;
|
|
@@ -102765,7 +104115,7 @@ async function readOpenedDirectory(root, target, handle, offset, limit, signal)
|
|
|
102765
104115
|
continue;
|
|
102766
104116
|
}
|
|
102767
104117
|
try {
|
|
102768
|
-
const metadata = await lstat5(
|
|
104118
|
+
const metadata = await lstat5(join35(access4, entry.name));
|
|
102769
104119
|
signal.throwIfAborted();
|
|
102770
104120
|
if (metadata.isFile()) {
|
|
102771
104121
|
entries.push({ kind, name: entry.name, path: path6, size: metadata.size });
|
|
@@ -102857,7 +104207,7 @@ async function recordAncestry(resolved) {
|
|
|
102857
104207
|
const below = relative4(top, resolved.path);
|
|
102858
104208
|
const paths = [top];
|
|
102859
104209
|
for (const segment of below === "" ? [] : below.split(sep6)) {
|
|
102860
|
-
paths.push(
|
|
104210
|
+
paths.push(join35(paths[paths.length - 1] ?? top, segment));
|
|
102861
104211
|
}
|
|
102862
104212
|
const ancestry = [];
|
|
102863
104213
|
for (const path6 of paths) {
|
|
@@ -102929,7 +104279,7 @@ function requestedTarget(root, path6) {
|
|
|
102929
104279
|
if (path6.length === 0 || path6.length > MAXIMUM_PATH_LENGTH || /[\0\\]/u.test(path6) || segments.some((segment) => segment.length === 0 || segment === "." || segment === "..")) {
|
|
102930
104280
|
throw new WorkspaceFileError("file_outside_scope", "The workspace path leaves its directory");
|
|
102931
104281
|
}
|
|
102932
|
-
return
|
|
104282
|
+
return join35(root, ...segments);
|
|
102933
104283
|
}
|
|
102934
104284
|
function containedPath(root, canonical) {
|
|
102935
104285
|
const child = relative4(root, canonical);
|
|
@@ -102946,12 +104296,12 @@ async function ignoreMatcher(root, throughDirectory, explicitDirectory, signal)
|
|
|
102946
104296
|
for (let index2 = 0; index2 <= segments.length; index2 += 1) {
|
|
102947
104297
|
const matcher = (0, import_ignore.default)();
|
|
102948
104298
|
for (const name2 of [".gitignore", ".ignore"]) {
|
|
102949
|
-
matcher.add(await readIgnoreFile(
|
|
104299
|
+
matcher.add(await readIgnoreFile(join35(directory, name2), signal));
|
|
102950
104300
|
}
|
|
102951
104301
|
rules.push({ base: portable(relative4(root, directory)), matcher });
|
|
102952
104302
|
const segment = segments[index2];
|
|
102953
104303
|
if (segment !== void 0) {
|
|
102954
|
-
directory =
|
|
104304
|
+
directory = join35(directory, segment);
|
|
102955
104305
|
}
|
|
102956
104306
|
}
|
|
102957
104307
|
const explicit = portable(relative4(root, explicitDirectory));
|
|
@@ -103115,7 +104465,7 @@ async function resolveFile(value, workingDirectory, signal) {
|
|
|
103115
104465
|
if (isAbsolute18(requested.path) && normalize3(requested.path) !== requested.path) {
|
|
103116
104466
|
return null;
|
|
103117
104467
|
}
|
|
103118
|
-
const candidates = requested.explicitUrl || workingDirectory === null ? [requested.path] : isAbsolute18(requested.path) ? [
|
|
104468
|
+
const candidates = requested.explicitUrl || workingDirectory === null ? [requested.path] : isAbsolute18(requested.path) ? [join36(workingDirectory, requested.path), requested.path] : [resolve18(workingDirectory, requested.path)];
|
|
103119
104469
|
for (const candidate of candidates) {
|
|
103120
104470
|
if (!isAbsolute18(candidate) || normalize3(candidate) !== candidate) {
|
|
103121
104471
|
continue;
|
|
@@ -103759,6 +105109,7 @@ async function executePrompt({
|
|
|
103759
105109
|
attemptId,
|
|
103760
105110
|
epoch,
|
|
103761
105111
|
waitForSessionAvailability,
|
|
105112
|
+
fallbackSteerToPrompt,
|
|
103762
105113
|
signal,
|
|
103763
105114
|
cancellationRequested
|
|
103764
105115
|
}) {
|
|
@@ -103798,6 +105149,9 @@ async function executePrompt({
|
|
|
103798
105149
|
"resolve-agent",
|
|
103799
105150
|
async () => await resolveAgent(command.agentId, signal, command.sessionId)
|
|
103800
105151
|
);
|
|
105152
|
+
if (command.disposition === SessionPromptDisposition.Queue) {
|
|
105153
|
+
await sessions.trySettleIdlePrompt(command.sessionId);
|
|
105154
|
+
}
|
|
103801
105155
|
const availability = await metrics.measure(
|
|
103802
105156
|
"await-session-availability",
|
|
103803
105157
|
async () => await waitForSessionAvailability(signal)
|
|
@@ -103877,26 +105231,15 @@ async function executePrompt({
|
|
|
103877
105231
|
if (command.prompt.trim().length === 0 && attachments.images.length === 0 && attachments.resources.length === 0) {
|
|
103878
105232
|
throw new PromptArtifactError("prompt_attachments_unsupported", "No supported prompt content remains");
|
|
103879
105233
|
}
|
|
103880
|
-
|
|
103881
|
-
|
|
103882
|
-
|
|
103883
|
-
|
|
103884
|
-
|
|
103885
|
-
|
|
103886
|
-
|
|
103887
|
-
|
|
103888
|
-
|
|
103889
|
-
images: attachments.images,
|
|
103890
|
-
lifecycle,
|
|
103891
|
-
prompt: command.prompt,
|
|
103892
|
-
resources: attachments.resources,
|
|
103893
|
-
sessionId: command.sessionId,
|
|
103894
|
-
signal,
|
|
103895
|
-
targetCommandId: command.targetCommandId
|
|
103896
|
-
});
|
|
103897
|
-
stopReason = "steered";
|
|
103898
|
-
} else {
|
|
103899
|
-
const suggestion2 = command.suggestNextPrompt !== true ? "not-requested" : prepared.capabilities.promptSuggestions ? "requested" : "unsupported";
|
|
105234
|
+
const runAsPrompt = async (disposition, activePrepared) => {
|
|
105235
|
+
const promptLifecycle = eventProjection.lifecycle(
|
|
105236
|
+
command.sessionId,
|
|
105237
|
+
command.commandId,
|
|
105238
|
+
attemptId,
|
|
105239
|
+
epoch,
|
|
105240
|
+
disposition
|
|
105241
|
+
);
|
|
105242
|
+
const suggestion2 = command.suggestNextPrompt !== true ? "not-requested" : activePrepared.capabilities.promptSuggestions ? "requested" : "unsupported";
|
|
103900
105243
|
sessions.promptSuggestions.begin(command.sessionId, command.commandId, suggestion2);
|
|
103901
105244
|
const result = await sessions.runPrompt({
|
|
103902
105245
|
adapter,
|
|
@@ -103906,9 +105249,9 @@ async function executePrompt({
|
|
|
103906
105249
|
agent: executionAgent,
|
|
103907
105250
|
commandId: command.commandId,
|
|
103908
105251
|
cwd: resolved.cwd,
|
|
103909
|
-
disposition
|
|
105252
|
+
disposition,
|
|
103910
105253
|
images: attachments.images,
|
|
103911
|
-
lifecycle,
|
|
105254
|
+
lifecycle: promptLifecycle,
|
|
103912
105255
|
prompt: command.prompt,
|
|
103913
105256
|
resources: attachments.resources,
|
|
103914
105257
|
sessionId: command.sessionId,
|
|
@@ -103918,8 +105261,66 @@ async function executePrompt({
|
|
|
103918
105261
|
targetCommandId: command.targetCommandId,
|
|
103919
105262
|
recovery
|
|
103920
105263
|
});
|
|
103921
|
-
|
|
103922
|
-
|
|
105264
|
+
sessions.promptSuggestions.finish(command.sessionId, command.commandId, result.stopReason);
|
|
105265
|
+
return result.stopReason;
|
|
105266
|
+
};
|
|
105267
|
+
let stopReason;
|
|
105268
|
+
if (availability.disposition === SessionPromptDisposition.Steer) {
|
|
105269
|
+
try {
|
|
105270
|
+
await sessions.steerPrompt({
|
|
105271
|
+
adapter,
|
|
105272
|
+
...externalizeSessionUpdate === void 0 ? {} : { externalizeSessionUpdate },
|
|
105273
|
+
additionalDirectories: resolved.additionalDirectories,
|
|
105274
|
+
agent: executionAgent,
|
|
105275
|
+
commandId: command.commandId,
|
|
105276
|
+
cwd: resolved.cwd,
|
|
105277
|
+
images: attachments.images,
|
|
105278
|
+
lifecycle,
|
|
105279
|
+
prompt: command.prompt,
|
|
105280
|
+
resources: attachments.resources,
|
|
105281
|
+
sessionId: command.sessionId,
|
|
105282
|
+
signal,
|
|
105283
|
+
targetCommandId: command.targetCommandId
|
|
105284
|
+
});
|
|
105285
|
+
stopReason = "steered";
|
|
105286
|
+
} catch (error62) {
|
|
105287
|
+
if (!(error62 instanceof AcpExecutionError) || error62.code !== "steering_target_unavailable" || fallbackSteerToPrompt === void 0) {
|
|
105288
|
+
throw error62;
|
|
105289
|
+
}
|
|
105290
|
+
await fallbackSteerToPrompt(signal);
|
|
105291
|
+
signal.throwIfAborted();
|
|
105292
|
+
sessions.promptSuggestions.want(command.sessionId, command.suggestNextPrompt === true);
|
|
105293
|
+
let fallbackPrepared = await metrics.measure(
|
|
105294
|
+
"prepare-session",
|
|
105295
|
+
async () => await sessions.prepareExecutionSession(preparation)
|
|
105296
|
+
);
|
|
105297
|
+
if (command.sessionConfigurations !== void 0) {
|
|
105298
|
+
const configurations = fallbackPrepared.configOptions;
|
|
105299
|
+
await metrics.measure(
|
|
105300
|
+
"apply-configuration",
|
|
105301
|
+
async () => await applyCompleteSessionConfiguration(
|
|
105302
|
+
sessions,
|
|
105303
|
+
configurations,
|
|
105304
|
+
sessionConfigurations ?? [],
|
|
105305
|
+
executionAgent,
|
|
105306
|
+
adapter,
|
|
105307
|
+
resolved.cwd,
|
|
105308
|
+
resolved.additionalDirectories,
|
|
105309
|
+
command.commandId,
|
|
105310
|
+
command.sessionId,
|
|
105311
|
+
signal
|
|
105312
|
+
)
|
|
105313
|
+
);
|
|
105314
|
+
fallbackPrepared = await metrics.measure(
|
|
105315
|
+
"prepare-session",
|
|
105316
|
+
async () => await sessions.prepareExecutionSession(preparation)
|
|
105317
|
+
);
|
|
105318
|
+
}
|
|
105319
|
+
signal.throwIfAborted();
|
|
105320
|
+
stopReason = await runAsPrompt(SessionPromptDisposition.Queue, fallbackPrepared);
|
|
105321
|
+
}
|
|
105322
|
+
} else {
|
|
105323
|
+
stopReason = await runAsPrompt(availability.disposition, prepared);
|
|
103923
105324
|
}
|
|
103924
105325
|
await eventProjection.completed(command.sessionId, command.commandId, stopReason);
|
|
103925
105326
|
} catch (error62) {
|
|
@@ -104027,6 +105428,7 @@ var sessionPromptCommand = {
|
|
|
104027
105428
|
waitForSessionAvailability: (signal) => context.sessionTurns.admitAndWait(turn, signal, () => {
|
|
104028
105429
|
queueChanged();
|
|
104029
105430
|
}),
|
|
105431
|
+
fallbackSteerToPrompt: (signal) => context.sessionTurns.fallbackSteerToPrompt(turn, signal),
|
|
104030
105432
|
signal: turn.signal,
|
|
104031
105433
|
cancellationRequested: turn.cancellationRequested
|
|
104032
105434
|
}).catch((error62) => {
|
|
@@ -106302,4 +107704,4 @@ export {
|
|
|
106302
107704
|
* MIT Licensed
|
|
106303
107705
|
*)
|
|
106304
107706
|
*/
|
|
106305
|
-
//# sourceMappingURL=chunk-
|
|
107707
|
+
//# sourceMappingURL=chunk-MYBYMYDN.js.map
|