@moxt-ai/mobius 0.0.452 → 0.0.454
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-DVSY3FDV.js → chunk-7VYQEJW7.js} +1642 -160
- package/dist/{chunk-DVSY3FDV.js.map → chunk-7VYQEJW7.js.map} +4 -4
- package/dist/{chunk-TZJRGEU4.js → chunk-TOQQNYQU.js} +2 -2
- package/dist/{chunk-TZJRGEU4.js.map → chunk-TOQQNYQU.js.map} +1 -1
- package/dist/{cli-NQKQR32P.js → cli-CCIMF4WB.js} +3 -3
- package/dist/cli.js +2 -2
- package/dist/engine/acp/adapter/antigravity/adapter.d.ts.map +1 -1
- package/dist/engine/acp/adapter/antigravity/adapter.js +12 -1
- package/dist/engine/acp/adapter/antigravity/adapter.js.map +1 -1
- package/dist/engine/acp/adapter/antigravity/agent-connection.d.ts +10 -3
- package/dist/engine/acp/adapter/antigravity/agent-connection.d.ts.map +1 -1
- package/dist/engine/acp/adapter/antigravity/agent-connection.js +190 -24
- package/dist/engine/acp/adapter/antigravity/agent-connection.js.map +1 -1
- package/dist/engine/acp/adapter/antigravity/background-wakeup.d.ts +37 -0
- package/dist/engine/acp/adapter/antigravity/background-wakeup.d.ts.map +1 -0
- package/dist/engine/acp/adapter/antigravity/background-wakeup.js +1251 -0
- package/dist/engine/acp/adapter/antigravity/background-wakeup.js.map +1 -0
- package/dist/engine/acp/adapter/execution-connections.d.ts.map +1 -1
- package/dist/engine/acp/adapter/execution-connections.js +4 -1
- package/dist/engine/acp/adapter/execution-connections.js.map +1 -1
- package/dist/engine/agent/specification/vendors/antigravity-agent.d.ts +5 -1
- package/dist/engine/agent/specification/vendors/antigravity-agent.d.ts.map +1 -1
- package/dist/engine/agent/specification/vendors/antigravity-agent.js +7 -2
- package/dist/engine/agent/specification/vendors/antigravity-agent.js.map +1 -1
- package/dist/engine/session/live/agent-session.d.ts +1 -1
- package/dist/engine/session/live/agent-session.d.ts.map +1 -1
- package/dist/engine/session/live/agent-session.js +34 -8
- package/dist/engine/session/live/agent-session.js.map +1 -1
- package/dist/engine/session/manager/session-manager.d.ts.map +1 -1
- package/dist/engine/session/manager/session-manager.js +16 -1
- package/dist/engine/session/manager/session-manager.js.map +1 -1
- package/dist/engine/storage/files/local-files.d.ts +5 -0
- package/dist/engine/storage/files/local-files.d.ts.map +1 -1
- package/dist/engine/storage/files/local-files.js +38 -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-NQKQR32P.js.map → cli-CCIMF4WB.js.map} +0 -0
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
__export,
|
|
4
4
|
__using,
|
|
5
5
|
package_default
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-TOQQNYQU.js";
|
|
7
7
|
|
|
8
8
|
// src/engine/runtime/relay/runtime-revocation.ts
|
|
9
9
|
var runtimeRevocationCloseCode = 1008;
|
|
@@ -22275,6 +22275,41 @@ async function readFileStart(path6, byteLength) {
|
|
|
22275
22275
|
}
|
|
22276
22276
|
return bytes;
|
|
22277
22277
|
}
|
|
22278
|
+
async function readScopedFileTail(baseDirectory, requestedRelativePath, maximumBytes) {
|
|
22279
|
+
if (requestedRelativePath.length === 0 || isAbsolute(requestedRelativePath)) {
|
|
22280
|
+
return null;
|
|
22281
|
+
}
|
|
22282
|
+
try {
|
|
22283
|
+
const directory = await canonicalPath(resolve(baseDirectory));
|
|
22284
|
+
const candidate = resolve(directory, requestedRelativePath);
|
|
22285
|
+
if (!withinDirectory(directory, candidate)) {
|
|
22286
|
+
return null;
|
|
22287
|
+
}
|
|
22288
|
+
const target = await canonicalPath(candidate);
|
|
22289
|
+
if (!withinDirectory(directory, target)) {
|
|
22290
|
+
return null;
|
|
22291
|
+
}
|
|
22292
|
+
const handle = await open2(target, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
22293
|
+
try {
|
|
22294
|
+
const metadata = await handle.stat();
|
|
22295
|
+
if (!metadata.isFile()) {
|
|
22296
|
+
return null;
|
|
22297
|
+
}
|
|
22298
|
+
if (metadata.size === 0 || maximumBytes <= 0) {
|
|
22299
|
+
return { bytes: new Uint8Array(0), offset: 0 };
|
|
22300
|
+
}
|
|
22301
|
+
const offset = Math.max(0, metadata.size - maximumBytes);
|
|
22302
|
+
const length = metadata.size - offset;
|
|
22303
|
+
const buffer = new Uint8Array(length);
|
|
22304
|
+
const { bytesRead } = await handle.read(buffer, 0, length, offset);
|
|
22305
|
+
return { bytes: buffer.subarray(0, bytesRead), offset };
|
|
22306
|
+
} finally {
|
|
22307
|
+
await handle.close();
|
|
22308
|
+
}
|
|
22309
|
+
} catch {
|
|
22310
|
+
return null;
|
|
22311
|
+
}
|
|
22312
|
+
}
|
|
22278
22313
|
async function readFileBytes(path6) {
|
|
22279
22314
|
return await readFile(path6);
|
|
22280
22315
|
}
|
|
@@ -27675,6 +27710,20 @@ function executableLaunch2(command, args) {
|
|
|
27675
27710
|
}
|
|
27676
27711
|
var platformSpawnOptions = hostPlatform.spawnOptions;
|
|
27677
27712
|
|
|
27713
|
+
// src/engine/util/serial-task-queue.ts
|
|
27714
|
+
var SerialTaskQueue = class {
|
|
27715
|
+
#tail = Promise.resolve();
|
|
27716
|
+
run = async (task, signal) => {
|
|
27717
|
+
signal.throwIfAborted();
|
|
27718
|
+
const result = this.#tail.then(() => {
|
|
27719
|
+
signal.throwIfAborted();
|
|
27720
|
+
return task(signal);
|
|
27721
|
+
});
|
|
27722
|
+
this.#tail = result.catch(() => void 0);
|
|
27723
|
+
return await result;
|
|
27724
|
+
};
|
|
27725
|
+
};
|
|
27726
|
+
|
|
27678
27727
|
// src/engine/util/value-utils.ts
|
|
27679
27728
|
function truncate(value, maximumLength) {
|
|
27680
27729
|
return value.length <= maximumLength ? value : `${value.slice(0, Math.max(0, maximumLength - 1))}\u2026`;
|
|
@@ -27945,6 +27994,1258 @@ function createWritableAcpStream(output2) {
|
|
|
27945
27994
|
});
|
|
27946
27995
|
}
|
|
27947
27996
|
|
|
27997
|
+
// src/engine/acp/adapter/antigravity/background-wakeup.ts
|
|
27998
|
+
import { homedir } from "node:os";
|
|
27999
|
+
import { join as join11 } from "node:path";
|
|
28000
|
+
|
|
28001
|
+
// src/engine/util/timer.ts
|
|
28002
|
+
var SystemTimer = class {
|
|
28003
|
+
schedule = (callback, milliseconds) => {
|
|
28004
|
+
const timeout = setTimeout(callback, milliseconds);
|
|
28005
|
+
return {
|
|
28006
|
+
cancel: () => {
|
|
28007
|
+
clearTimeout(timeout);
|
|
28008
|
+
}
|
|
28009
|
+
};
|
|
28010
|
+
};
|
|
28011
|
+
};
|
|
28012
|
+
var systemTimer = new SystemTimer();
|
|
28013
|
+
|
|
28014
|
+
// src/engine/acp/adapter/antigravity/background-wakeup.ts
|
|
28015
|
+
var TRANSCRIPT_TAIL_BYTES = 65536;
|
|
28016
|
+
var TRANSCRIPT_INITIAL_DELAY_MS = 40;
|
|
28017
|
+
var TRANSCRIPT_POLL_INTERVAL_MS = 150;
|
|
28018
|
+
var WAKEUP_INACTIVITY_TIMEOUT_MS = 3e5;
|
|
28019
|
+
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;
|
|
28020
|
+
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;
|
|
28021
|
+
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;
|
|
28022
|
+
var AGENT_EXECUTOR_ERROR_PATTERN = /^\s*⚠ agent executor error:\s*(.+?)\s*$/su;
|
|
28023
|
+
var SUBAGENT_CREATED_MARKER = "Created the following subagent";
|
|
28024
|
+
var MAXIMUM_TOOL_DESCRIPTION_CHARS = 500;
|
|
28025
|
+
var transcriptStepSchema = external_exports.object({
|
|
28026
|
+
content: external_exports.string().optional(),
|
|
28027
|
+
status: external_exports.string().optional(),
|
|
28028
|
+
step_index: external_exports.number().int().nonnegative(),
|
|
28029
|
+
tool_calls: external_exports.array(external_exports.unknown()).optional(),
|
|
28030
|
+
type: external_exports.string()
|
|
28031
|
+
});
|
|
28032
|
+
var EMPTY_INCOMING_OUTCOME = {
|
|
28033
|
+
afterUpdates: [],
|
|
28034
|
+
beforeUpdates: []
|
|
28035
|
+
};
|
|
28036
|
+
function readString3(record2, key) {
|
|
28037
|
+
const value = record2[key];
|
|
28038
|
+
return typeof value === "string" ? value : void 0;
|
|
28039
|
+
}
|
|
28040
|
+
function requestKeyOf(id) {
|
|
28041
|
+
return typeof id === "string" || typeof id === "number" ? id : void 0;
|
|
28042
|
+
}
|
|
28043
|
+
function isRequestMessage2(message) {
|
|
28044
|
+
return "method" in message && "id" in message;
|
|
28045
|
+
}
|
|
28046
|
+
function isNotificationMessage2(message) {
|
|
28047
|
+
return "method" in message && !("id" in message);
|
|
28048
|
+
}
|
|
28049
|
+
function isResponseMessage2(message) {
|
|
28050
|
+
return "id" in message && !("method" in message);
|
|
28051
|
+
}
|
|
28052
|
+
function resolveGeminiHome(launchEnvironment) {
|
|
28053
|
+
const configured = launchEnvironment["GEMINI_HOME"]?.trim();
|
|
28054
|
+
if (configured !== void 0 && configured.length > 0) {
|
|
28055
|
+
return configured;
|
|
28056
|
+
}
|
|
28057
|
+
const home = launchEnvironment["HOME"]?.trim() || launchEnvironment["USERPROFILE"]?.trim() || homedir();
|
|
28058
|
+
return home.length > 0 ? join11(home, ".gemini") : void 0;
|
|
28059
|
+
}
|
|
28060
|
+
async function readTranscriptTailState(launchEnvironment, sessionId, baselineStepIndex) {
|
|
28061
|
+
if (!SESSION_UUID_PATTERN.test(sessionId)) {
|
|
28062
|
+
return null;
|
|
28063
|
+
}
|
|
28064
|
+
const geminiHome = resolveGeminiHome(launchEnvironment);
|
|
28065
|
+
if (geminiHome === void 0) {
|
|
28066
|
+
return null;
|
|
28067
|
+
}
|
|
28068
|
+
const tail = await readScopedFileTail(
|
|
28069
|
+
geminiHome,
|
|
28070
|
+
join11("antigravity-cli", "brain", sessionId, ".system_generated", "logs", "transcript.jsonl"),
|
|
28071
|
+
TRANSCRIPT_TAIL_BYTES
|
|
28072
|
+
);
|
|
28073
|
+
if (tail === null) {
|
|
28074
|
+
return null;
|
|
28075
|
+
}
|
|
28076
|
+
if (tail.bytes.byteLength === 0) {
|
|
28077
|
+
return { maxStepIndex: -1, settledStepIndex: null, steps: [] };
|
|
28078
|
+
}
|
|
28079
|
+
const text2 = new TextDecoder().decode(tail.bytes);
|
|
28080
|
+
const lines = text2.split("\n");
|
|
28081
|
+
const startIndex = tail.offset > 0 ? 1 : 0;
|
|
28082
|
+
const steps = [];
|
|
28083
|
+
for (const rawLine of lines.slice(startIndex)) {
|
|
28084
|
+
const trimmed = rawLine.trim();
|
|
28085
|
+
if (trimmed.length === 0) {
|
|
28086
|
+
continue;
|
|
28087
|
+
}
|
|
28088
|
+
let parsedJson;
|
|
28089
|
+
try {
|
|
28090
|
+
parsedJson = JSON.parse(trimmed);
|
|
28091
|
+
} catch {
|
|
28092
|
+
continue;
|
|
28093
|
+
}
|
|
28094
|
+
const parsed = transcriptStepSchema.safeParse(parsedJson);
|
|
28095
|
+
if (parsed.success) {
|
|
28096
|
+
steps.push(parsed.data);
|
|
28097
|
+
}
|
|
28098
|
+
}
|
|
28099
|
+
steps.sort((left, right) => left.step_index - right.step_index);
|
|
28100
|
+
const maxStepIndex = steps.at(-1)?.step_index ?? -1;
|
|
28101
|
+
const settledStep = steps.find(
|
|
28102
|
+
(step) => step.step_index > baselineStepIndex && step.type === "PLANNER_RESPONSE" && step.status === "DONE" && (step.tool_calls === void 0 || step.tool_calls.length === 0)
|
|
28103
|
+
);
|
|
28104
|
+
return {
|
|
28105
|
+
maxStepIndex,
|
|
28106
|
+
settledStepIndex: settledStep?.step_index ?? null,
|
|
28107
|
+
steps
|
|
28108
|
+
};
|
|
28109
|
+
}
|
|
28110
|
+
function extractUuidMatches(text2, pattern) {
|
|
28111
|
+
pattern.lastIndex = 0;
|
|
28112
|
+
const matches = [];
|
|
28113
|
+
for (const match of text2.matchAll(pattern)) {
|
|
28114
|
+
const captured = match[1]?.toLowerCase();
|
|
28115
|
+
if (captured !== void 0) {
|
|
28116
|
+
matches.push(captured);
|
|
28117
|
+
}
|
|
28118
|
+
}
|
|
28119
|
+
return matches;
|
|
28120
|
+
}
|
|
28121
|
+
function extractExecutorError(updateKind, update) {
|
|
28122
|
+
if (updateKind !== "agent_message_chunk" && updateKind !== "agent_message") {
|
|
28123
|
+
return void 0;
|
|
28124
|
+
}
|
|
28125
|
+
const content = update["content"];
|
|
28126
|
+
if (!isRecord5(content) || content["type"] !== "text") {
|
|
28127
|
+
return void 0;
|
|
28128
|
+
}
|
|
28129
|
+
const text2 = readString3(content, "text");
|
|
28130
|
+
if (text2 === void 0) {
|
|
28131
|
+
return void 0;
|
|
28132
|
+
}
|
|
28133
|
+
const match = AGENT_EXECUTOR_ERROR_PATTERN.exec(text2);
|
|
28134
|
+
const message = match?.[1];
|
|
28135
|
+
return message === void 0 ? void 0 : truncate(message, MAXIMUM_TOOL_DESCRIPTION_CHARS);
|
|
28136
|
+
}
|
|
28137
|
+
function extractToolInputRecords(update) {
|
|
28138
|
+
const records = [];
|
|
28139
|
+
const args = update["args"];
|
|
28140
|
+
if (isRecord5(args)) {
|
|
28141
|
+
records.push(args);
|
|
28142
|
+
}
|
|
28143
|
+
const rawInput = update["rawInput"];
|
|
28144
|
+
if (isRecord5(rawInput)) {
|
|
28145
|
+
records.push(rawInput);
|
|
28146
|
+
}
|
|
28147
|
+
return records;
|
|
28148
|
+
}
|
|
28149
|
+
function readInputString(records, key) {
|
|
28150
|
+
for (const record2 of records) {
|
|
28151
|
+
const value = readString3(record2, key)?.trim();
|
|
28152
|
+
if (value !== void 0 && value.length > 0) {
|
|
28153
|
+
return value;
|
|
28154
|
+
}
|
|
28155
|
+
}
|
|
28156
|
+
return void 0;
|
|
28157
|
+
}
|
|
28158
|
+
function readToolCategory(update, inputs, previous) {
|
|
28159
|
+
const name2 = readString3(update, "name");
|
|
28160
|
+
if (name2 === "run_command") {
|
|
28161
|
+
return "command";
|
|
28162
|
+
}
|
|
28163
|
+
if (name2 === "schedule") {
|
|
28164
|
+
return "schedule";
|
|
28165
|
+
}
|
|
28166
|
+
if (name2 === "run_workflow") {
|
|
28167
|
+
return "workflow";
|
|
28168
|
+
}
|
|
28169
|
+
if (name2 === "invoke_subagent") {
|
|
28170
|
+
return "subagent";
|
|
28171
|
+
}
|
|
28172
|
+
if (name2 === "manage_subagents") {
|
|
28173
|
+
return "manage-subagents";
|
|
28174
|
+
}
|
|
28175
|
+
const title = readString3(update, "title");
|
|
28176
|
+
if (title === "Run invoke_subagent" || title === "Running invoke_subagent" || title === "Run invoke_subagent?" || title === "Running start_subagent" || title === "Run start_subagent?") {
|
|
28177
|
+
return "subagent";
|
|
28178
|
+
}
|
|
28179
|
+
if (title === "Run schedule" || title === "Running schedule") {
|
|
28180
|
+
return "schedule";
|
|
28181
|
+
}
|
|
28182
|
+
if (title === "Run manage_subagents") {
|
|
28183
|
+
return "manage-subagents";
|
|
28184
|
+
}
|
|
28185
|
+
if (previous?.category !== void 0 && previous.category !== null) {
|
|
28186
|
+
return previous.category;
|
|
28187
|
+
}
|
|
28188
|
+
if (readInputString(inputs, "CommandLine") !== void 0) {
|
|
28189
|
+
return "command";
|
|
28190
|
+
}
|
|
28191
|
+
return null;
|
|
28192
|
+
}
|
|
28193
|
+
function inspectToolMetadata(update, previous) {
|
|
28194
|
+
const inputs = extractToolInputRecords(update);
|
|
28195
|
+
const category = readToolCategory(update, inputs, previous);
|
|
28196
|
+
let isDaemon = previous?.isDaemon ?? false;
|
|
28197
|
+
const subagentKillIds = new Set(previous?.subagentKillIds ?? []);
|
|
28198
|
+
let subagentKillAll = previous?.subagentKillAll ?? false;
|
|
28199
|
+
for (const record2 of inputs) {
|
|
28200
|
+
if (record2["IsDaemon"] === true) {
|
|
28201
|
+
isDaemon = true;
|
|
28202
|
+
}
|
|
28203
|
+
const cron = readString3(record2, "CronExpression")?.trim();
|
|
28204
|
+
if (cron !== void 0 && cron.length > 0) {
|
|
28205
|
+
isDaemon = true;
|
|
28206
|
+
}
|
|
28207
|
+
if (category === "manage-subagents") {
|
|
28208
|
+
const action = readString3(record2, "Action");
|
|
28209
|
+
if (action === "kill_all") {
|
|
28210
|
+
subagentKillAll = true;
|
|
28211
|
+
} else if (action === "kill" && Array.isArray(record2["ConversationIds"])) {
|
|
28212
|
+
for (const rawId of record2["ConversationIds"]) {
|
|
28213
|
+
if (typeof rawId === "string") {
|
|
28214
|
+
const normalized = rawId.trim().toLowerCase();
|
|
28215
|
+
if (normalized.length > 0) {
|
|
28216
|
+
subagentKillIds.add(normalized);
|
|
28217
|
+
}
|
|
28218
|
+
}
|
|
28219
|
+
}
|
|
28220
|
+
}
|
|
28221
|
+
}
|
|
28222
|
+
}
|
|
28223
|
+
const description = readInputString(inputs, "toolSummary") ?? readInputString(inputs, "Description") ?? readInputString(inputs, "Role") ?? readInputString(inputs, "CommandLine") ?? readInputString(inputs, "Prompt") ?? readString3(update, "title") ?? previous?.description;
|
|
28224
|
+
return {
|
|
28225
|
+
category,
|
|
28226
|
+
description: description === void 0 ? void 0 : truncate(description, MAXIMUM_TOOL_DESCRIPTION_CHARS),
|
|
28227
|
+
isDaemon,
|
|
28228
|
+
subagentKillAll,
|
|
28229
|
+
subagentKillIds: [...subagentKillIds]
|
|
28230
|
+
};
|
|
28231
|
+
}
|
|
28232
|
+
function backgroundKindFor(category) {
|
|
28233
|
+
switch (category) {
|
|
28234
|
+
case "command":
|
|
28235
|
+
return "shell";
|
|
28236
|
+
case "subagent":
|
|
28237
|
+
return "subagent";
|
|
28238
|
+
case "schedule":
|
|
28239
|
+
case "workflow":
|
|
28240
|
+
return "other";
|
|
28241
|
+
case "manage-subagents":
|
|
28242
|
+
case null:
|
|
28243
|
+
return null;
|
|
28244
|
+
}
|
|
28245
|
+
}
|
|
28246
|
+
function makeMetaNotification(sessionId, metaKey, payload) {
|
|
28247
|
+
return {
|
|
28248
|
+
sessionId,
|
|
28249
|
+
update: {
|
|
28250
|
+
_meta: { [metaKey]: payload },
|
|
28251
|
+
sessionUpdate: "session_info_update"
|
|
28252
|
+
}
|
|
28253
|
+
};
|
|
28254
|
+
}
|
|
28255
|
+
function isWakeupStartUpdateKind(updateKind) {
|
|
28256
|
+
switch (updateKind) {
|
|
28257
|
+
case "agent_message_chunk":
|
|
28258
|
+
case "agent_thought_chunk":
|
|
28259
|
+
case "agent_message":
|
|
28260
|
+
case "agent_thought":
|
|
28261
|
+
case "tool_call":
|
|
28262
|
+
return true;
|
|
28263
|
+
default:
|
|
28264
|
+
return false;
|
|
28265
|
+
}
|
|
28266
|
+
}
|
|
28267
|
+
function isWakeupChunkUpdateKind(updateKind) {
|
|
28268
|
+
return updateKind === "agent_message_chunk" || updateKind === "agent_thought_chunk" || updateKind === "agent_message" || updateKind === "agent_thought";
|
|
28269
|
+
}
|
|
28270
|
+
var AntigravityBackgroundWakeup = class {
|
|
28271
|
+
#emitMetaUpdate;
|
|
28272
|
+
#launchEnvironment;
|
|
28273
|
+
#timer;
|
|
28274
|
+
#sessions = /* @__PURE__ */ new Map();
|
|
28275
|
+
#pendingRequests = /* @__PURE__ */ new Map();
|
|
28276
|
+
#disposed = false;
|
|
28277
|
+
constructor(options) {
|
|
28278
|
+
this.#emitMetaUpdate = options.emitMetaUpdate;
|
|
28279
|
+
this.#launchEnvironment = options.launchEnvironment;
|
|
28280
|
+
this.#timer = options.timer ?? systemTimer;
|
|
28281
|
+
}
|
|
28282
|
+
#ensureSession = (sessionId) => {
|
|
28283
|
+
const existing = this.#sessions.get(sessionId);
|
|
28284
|
+
if (existing !== void 0) {
|
|
28285
|
+
return existing;
|
|
28286
|
+
}
|
|
28287
|
+
const created = {
|
|
28288
|
+
activeInteractions: 0,
|
|
28289
|
+
backgroundTasks: /* @__PURE__ */ new Map(),
|
|
28290
|
+
baselineStepIndex: -1,
|
|
28291
|
+
lastEmittedBackgroundKey: "[]",
|
|
28292
|
+
phase: { cancelRequested: false, kind: "idle" },
|
|
28293
|
+
sessionOpenStepIndex: -1,
|
|
28294
|
+
subagents: {
|
|
28295
|
+
boundCreationSteps: /* @__PURE__ */ new Set(),
|
|
28296
|
+
consumedIdleSteps: /* @__PURE__ */ new Set(),
|
|
28297
|
+
conversationIdByToolCallId: /* @__PURE__ */ new Map(),
|
|
28298
|
+
pendingToolCallIds: []
|
|
28299
|
+
},
|
|
28300
|
+
toolMetadata: /* @__PURE__ */ new Map(),
|
|
28301
|
+
wakeupGeneration: 0,
|
|
28302
|
+
wakeupStageSeq: 0
|
|
28303
|
+
};
|
|
28304
|
+
this.#sessions.set(sessionId, created);
|
|
28305
|
+
return created;
|
|
28306
|
+
};
|
|
28307
|
+
#cancelWakeupTimers = (phase) => {
|
|
28308
|
+
if (phase.kind !== "wakeup") {
|
|
28309
|
+
return;
|
|
28310
|
+
}
|
|
28311
|
+
switch (phase.stage.kind) {
|
|
28312
|
+
case "awaiting-output":
|
|
28313
|
+
phase.stage.timeout.cancel();
|
|
28314
|
+
phase.stage.transcriptCheck.cancel();
|
|
28315
|
+
return;
|
|
28316
|
+
case "blocked-on-work":
|
|
28317
|
+
case "verifying-timeout":
|
|
28318
|
+
return;
|
|
28319
|
+
case "streaming":
|
|
28320
|
+
phase.stage.transcriptCheck.cancel();
|
|
28321
|
+
phase.stage.inactivityTimeout.cancel();
|
|
28322
|
+
return;
|
|
28323
|
+
default: {
|
|
28324
|
+
const unreachable2 = phase.stage;
|
|
28325
|
+
throw new Error(`Unexpected wakeup stage: ${String(unreachable2)}`);
|
|
28326
|
+
}
|
|
28327
|
+
}
|
|
28328
|
+
};
|
|
28329
|
+
#emitNotifications = (notifications) => {
|
|
28330
|
+
for (const notification of notifications) {
|
|
28331
|
+
this.#emitMetaUpdate(notification);
|
|
28332
|
+
}
|
|
28333
|
+
};
|
|
28334
|
+
#takeBackgroundTasksUpdate = (sessionId, session) => {
|
|
28335
|
+
const tasks = [...session.backgroundTasks.values()];
|
|
28336
|
+
const serialized = JSON.stringify(tasks);
|
|
28337
|
+
if (serialized === session.lastEmittedBackgroundKey) {
|
|
28338
|
+
return null;
|
|
28339
|
+
}
|
|
28340
|
+
session.lastEmittedBackgroundKey = serialized;
|
|
28341
|
+
return makeMetaNotification(sessionId, BACKGROUND_TASKS_META, tasks);
|
|
28342
|
+
};
|
|
28343
|
+
#registerSubagentTask = (session, toolCallId, description) => {
|
|
28344
|
+
if (!session.backgroundTasks.has(toolCallId)) {
|
|
28345
|
+
session.backgroundTasks.set(toolCallId, {
|
|
28346
|
+
...description === void 0 ? {} : { description },
|
|
28347
|
+
kind: "subagent",
|
|
28348
|
+
state: "running",
|
|
28349
|
+
taskId: toolCallId,
|
|
28350
|
+
toolUseId: toolCallId
|
|
28351
|
+
});
|
|
28352
|
+
}
|
|
28353
|
+
if (!session.subagents.conversationIdByToolCallId.has(toolCallId) && !session.subagents.pendingToolCallIds.includes(toolCallId)) {
|
|
28354
|
+
session.subagents.pendingToolCallIds.push(toolCallId);
|
|
28355
|
+
}
|
|
28356
|
+
};
|
|
28357
|
+
#deleteSubagentTask = (session, toolCallId) => {
|
|
28358
|
+
session.backgroundTasks.delete(toolCallId);
|
|
28359
|
+
session.subagents.conversationIdByToolCallId.delete(toolCallId);
|
|
28360
|
+
const pendingIndex = session.subagents.pendingToolCallIds.indexOf(toolCallId);
|
|
28361
|
+
if (pendingIndex !== -1) {
|
|
28362
|
+
session.subagents.pendingToolCallIds.splice(pendingIndex, 1);
|
|
28363
|
+
}
|
|
28364
|
+
};
|
|
28365
|
+
#deleteAllSubagentTasks = (session) => {
|
|
28366
|
+
for (const [taskId, task] of [...session.backgroundTasks.entries()]) {
|
|
28367
|
+
if (task.kind === "subagent") {
|
|
28368
|
+
this.#deleteSubagentTask(session, taskId);
|
|
28369
|
+
}
|
|
28370
|
+
}
|
|
28371
|
+
};
|
|
28372
|
+
#clearAllBackgroundTasks = (session) => {
|
|
28373
|
+
session.backgroundTasks.clear();
|
|
28374
|
+
session.subagents.conversationIdByToolCallId.clear();
|
|
28375
|
+
session.subagents.pendingToolCallIds.length = 0;
|
|
28376
|
+
};
|
|
28377
|
+
#dropAwaitingResultTasks = (session) => {
|
|
28378
|
+
for (const [taskId, task] of [...session.backgroundTasks.entries()]) {
|
|
28379
|
+
if (task.state === "awaiting-results") {
|
|
28380
|
+
if (task.kind === "subagent") {
|
|
28381
|
+
this.#deleteSubagentTask(session, taskId);
|
|
28382
|
+
} else {
|
|
28383
|
+
session.backgroundTasks.delete(taskId);
|
|
28384
|
+
}
|
|
28385
|
+
}
|
|
28386
|
+
}
|
|
28387
|
+
};
|
|
28388
|
+
#hasSubagentTasks = (session) => {
|
|
28389
|
+
for (const task of session.backgroundTasks.values()) {
|
|
28390
|
+
if (task.kind === "subagent") {
|
|
28391
|
+
return true;
|
|
28392
|
+
}
|
|
28393
|
+
}
|
|
28394
|
+
return false;
|
|
28395
|
+
};
|
|
28396
|
+
#syncSubagentCreations = (session, steps) => {
|
|
28397
|
+
if (session.subagents.pendingToolCallIds.length === 0) {
|
|
28398
|
+
return;
|
|
28399
|
+
}
|
|
28400
|
+
for (const step of steps) {
|
|
28401
|
+
if (step.step_index <= session.sessionOpenStepIndex || step.type !== "GENERIC" || step.status !== "DONE" || session.subagents.boundCreationSteps.has(step.step_index) || step.content === void 0 || !step.content.includes(SUBAGENT_CREATED_MARKER)) {
|
|
28402
|
+
continue;
|
|
28403
|
+
}
|
|
28404
|
+
const createdIds = extractUuidMatches(step.content, SUBAGENT_CONVERSATION_ID_PATTERN);
|
|
28405
|
+
if (createdIds.length === 0) {
|
|
28406
|
+
continue;
|
|
28407
|
+
}
|
|
28408
|
+
let boundAny = false;
|
|
28409
|
+
for (const conversationId of createdIds) {
|
|
28410
|
+
let nextToolCallId;
|
|
28411
|
+
while (session.subagents.pendingToolCallIds.length > 0) {
|
|
28412
|
+
const candidate = session.subagents.pendingToolCallIds.shift();
|
|
28413
|
+
if (candidate !== void 0 && session.backgroundTasks.has(candidate)) {
|
|
28414
|
+
nextToolCallId = candidate;
|
|
28415
|
+
break;
|
|
28416
|
+
}
|
|
28417
|
+
}
|
|
28418
|
+
if (nextToolCallId === void 0) {
|
|
28419
|
+
break;
|
|
28420
|
+
}
|
|
28421
|
+
session.subagents.conversationIdByToolCallId.set(nextToolCallId, conversationId);
|
|
28422
|
+
boundAny = true;
|
|
28423
|
+
}
|
|
28424
|
+
if (boundAny) {
|
|
28425
|
+
session.subagents.boundCreationSteps.add(step.step_index);
|
|
28426
|
+
}
|
|
28427
|
+
}
|
|
28428
|
+
};
|
|
28429
|
+
#findSubagentToolCallId = (session, conversationId) => {
|
|
28430
|
+
const targetId = conversationId.toLowerCase();
|
|
28431
|
+
for (const [toolCallId, mappedId] of session.subagents.conversationIdByToolCallId) {
|
|
28432
|
+
if (mappedId === targetId && session.backgroundTasks.has(toolCallId)) {
|
|
28433
|
+
return toolCallId;
|
|
28434
|
+
}
|
|
28435
|
+
}
|
|
28436
|
+
return void 0;
|
|
28437
|
+
};
|
|
28438
|
+
#processIdleSubagentMessages = (session, steps, maxStepExclusive, onMatchedToolCall) => {
|
|
28439
|
+
for (const step of steps) {
|
|
28440
|
+
if (step.step_index <= session.sessionOpenStepIndex || maxStepExclusive !== void 0 && step.step_index >= maxStepExclusive || step.type !== "SYSTEM_MESSAGE" || session.subagents.consumedIdleSteps.has(step.step_index) || step.content === void 0) {
|
|
28441
|
+
continue;
|
|
28442
|
+
}
|
|
28443
|
+
const idleIds = extractUuidMatches(step.content, SUBAGENT_IDLE_ID_PATTERN);
|
|
28444
|
+
if (idleIds.length === 0) {
|
|
28445
|
+
continue;
|
|
28446
|
+
}
|
|
28447
|
+
session.subagents.consumedIdleSteps.add(step.step_index);
|
|
28448
|
+
for (const conversationId of idleIds) {
|
|
28449
|
+
const toolCallId = this.#findSubagentToolCallId(session, conversationId);
|
|
28450
|
+
if (toolCallId !== void 0) {
|
|
28451
|
+
onMatchedToolCall(toolCallId);
|
|
28452
|
+
}
|
|
28453
|
+
}
|
|
28454
|
+
}
|
|
28455
|
+
};
|
|
28456
|
+
#markTriggeredSubagentIdles = (session, steps) => {
|
|
28457
|
+
const matched = /* @__PURE__ */ new Set();
|
|
28458
|
+
this.#processIdleSubagentMessages(session, steps, void 0, (toolCallId) => {
|
|
28459
|
+
const existing = session.backgroundTasks.get(toolCallId);
|
|
28460
|
+
if (existing !== void 0) {
|
|
28461
|
+
session.backgroundTasks.set(toolCallId, { ...existing, state: "awaiting-results" });
|
|
28462
|
+
matched.add(toolCallId);
|
|
28463
|
+
}
|
|
28464
|
+
});
|
|
28465
|
+
return [...matched];
|
|
28466
|
+
};
|
|
28467
|
+
#consumeSubagentIdlesThrough = (session, steps, plannerStepIndex) => {
|
|
28468
|
+
this.#processIdleSubagentMessages(session, steps, plannerStepIndex, (toolCallId) => {
|
|
28469
|
+
this.#deleteSubagentTask(session, toolCallId);
|
|
28470
|
+
});
|
|
28471
|
+
};
|
|
28472
|
+
#killSubagentsByMetadata = async (sessionId, session, meta3) => {
|
|
28473
|
+
if (meta3.subagentKillAll) {
|
|
28474
|
+
this.#deleteAllSubagentTasks(session);
|
|
28475
|
+
return true;
|
|
28476
|
+
}
|
|
28477
|
+
if (meta3.subagentKillIds.length === 0) {
|
|
28478
|
+
return true;
|
|
28479
|
+
}
|
|
28480
|
+
await this.#syncPendingSubagentCreations(sessionId, session);
|
|
28481
|
+
if (this.#disposed || this.#sessions.get(sessionId) !== session) {
|
|
28482
|
+
return false;
|
|
28483
|
+
}
|
|
28484
|
+
for (const conversationId of meta3.subagentKillIds) {
|
|
28485
|
+
const targetToolCallId = this.#findSubagentToolCallId(session, conversationId);
|
|
28486
|
+
if (targetToolCallId !== void 0) {
|
|
28487
|
+
this.#deleteSubagentTask(session, targetToolCallId);
|
|
28488
|
+
}
|
|
28489
|
+
}
|
|
28490
|
+
return true;
|
|
28491
|
+
};
|
|
28492
|
+
#syncPendingSubagentCreations = async (sessionId, session) => {
|
|
28493
|
+
if (session.subagents.pendingToolCallIds.length === 0) {
|
|
28494
|
+
return;
|
|
28495
|
+
}
|
|
28496
|
+
const tail = await readTranscriptTailState(this.#launchEnvironment, sessionId, session.baselineStepIndex);
|
|
28497
|
+
if (this.#disposed || this.#sessions.get(sessionId) !== session || tail === null) {
|
|
28498
|
+
return;
|
|
28499
|
+
}
|
|
28500
|
+
this.#syncSubagentCreations(session, tail.steps);
|
|
28501
|
+
};
|
|
28502
|
+
#scheduleTranscriptPoll = (sessionId, generation, stageEpoch, delayMs) => this.#timer.schedule(() => {
|
|
28503
|
+
void this.#checkWakeupTranscript(sessionId, generation, stageEpoch);
|
|
28504
|
+
}, delayMs);
|
|
28505
|
+
#setWakeupAwaitingOutput = (sessionId, session, generation, openToolIds) => {
|
|
28506
|
+
this.#cancelWakeupTimers(session.phase);
|
|
28507
|
+
session.wakeupStageSeq += 1;
|
|
28508
|
+
const stageEpoch = session.wakeupStageSeq;
|
|
28509
|
+
const transcriptCheck = this.#scheduleTranscriptPoll(
|
|
28510
|
+
sessionId,
|
|
28511
|
+
generation,
|
|
28512
|
+
stageEpoch,
|
|
28513
|
+
TRANSCRIPT_INITIAL_DELAY_MS
|
|
28514
|
+
);
|
|
28515
|
+
const timeout = this.#timer.schedule(() => {
|
|
28516
|
+
void this.#handleWakeupTimeout(
|
|
28517
|
+
sessionId,
|
|
28518
|
+
generation,
|
|
28519
|
+
stageEpoch,
|
|
28520
|
+
"Antigravity continuation timed out waiting for output"
|
|
28521
|
+
);
|
|
28522
|
+
}, WAKEUP_INACTIVITY_TIMEOUT_MS);
|
|
28523
|
+
session.phase = {
|
|
28524
|
+
generation,
|
|
28525
|
+
kind: "wakeup",
|
|
28526
|
+
openToolIds,
|
|
28527
|
+
stage: { kind: "awaiting-output", stageEpoch, timeout, transcriptCheck }
|
|
28528
|
+
};
|
|
28529
|
+
};
|
|
28530
|
+
#setWakeupBlockedOnWork = (session, generation, openToolIds) => {
|
|
28531
|
+
this.#cancelWakeupTimers(session.phase);
|
|
28532
|
+
session.wakeupStageSeq += 1;
|
|
28533
|
+
const stageEpoch = session.wakeupStageSeq;
|
|
28534
|
+
session.phase = {
|
|
28535
|
+
generation,
|
|
28536
|
+
kind: "wakeup",
|
|
28537
|
+
openToolIds,
|
|
28538
|
+
stage: { kind: "blocked-on-work", stageEpoch }
|
|
28539
|
+
};
|
|
28540
|
+
};
|
|
28541
|
+
#setWakeupStreaming = (sessionId, session, generation, openToolIds, incomingExecutorError) => {
|
|
28542
|
+
const previousExecutorError = session.phase.kind === "wakeup" && session.phase.generation === generation && session.phase.stage.kind === "streaming" ? session.phase.stage.executorError : void 0;
|
|
28543
|
+
const executorError = incomingExecutorError ?? previousExecutorError;
|
|
28544
|
+
this.#cancelWakeupTimers(session.phase);
|
|
28545
|
+
session.wakeupStageSeq += 1;
|
|
28546
|
+
const stageEpoch = session.wakeupStageSeq;
|
|
28547
|
+
const transcriptCheck = this.#scheduleTranscriptPoll(
|
|
28548
|
+
sessionId,
|
|
28549
|
+
generation,
|
|
28550
|
+
stageEpoch,
|
|
28551
|
+
TRANSCRIPT_INITIAL_DELAY_MS
|
|
28552
|
+
);
|
|
28553
|
+
const inactivityTimeout = this.#timer.schedule(() => {
|
|
28554
|
+
void this.#handleWakeupTimeout(
|
|
28555
|
+
sessionId,
|
|
28556
|
+
generation,
|
|
28557
|
+
stageEpoch,
|
|
28558
|
+
"Antigravity continuation timed out while streaming"
|
|
28559
|
+
);
|
|
28560
|
+
}, WAKEUP_INACTIVITY_TIMEOUT_MS);
|
|
28561
|
+
session.phase = {
|
|
28562
|
+
generation,
|
|
28563
|
+
kind: "wakeup",
|
|
28564
|
+
openToolIds,
|
|
28565
|
+
stage: {
|
|
28566
|
+
executorError,
|
|
28567
|
+
executorErrorPolls: 0,
|
|
28568
|
+
inactivityTimeout,
|
|
28569
|
+
kind: "streaming",
|
|
28570
|
+
stageEpoch,
|
|
28571
|
+
transcriptCheck
|
|
28572
|
+
}
|
|
28573
|
+
};
|
|
28574
|
+
};
|
|
28575
|
+
#enterWakeup = (sessionId, session, taskIds) => {
|
|
28576
|
+
const notifications = [];
|
|
28577
|
+
const bgNotification = this.#takeBackgroundTasksUpdate(sessionId, session);
|
|
28578
|
+
if (bgNotification !== null) {
|
|
28579
|
+
notifications.push(bgNotification);
|
|
28580
|
+
}
|
|
28581
|
+
session.wakeupGeneration += 1;
|
|
28582
|
+
const generation = session.wakeupGeneration;
|
|
28583
|
+
this.#setWakeupAwaitingOutput(sessionId, session, generation, /* @__PURE__ */ new Set());
|
|
28584
|
+
notifications.push(
|
|
28585
|
+
makeMetaNotification(sessionId, AGENT_TURN_META, {
|
|
28586
|
+
reason: "background-task",
|
|
28587
|
+
stage: "started",
|
|
28588
|
+
taskIds: [...taskIds]
|
|
28589
|
+
})
|
|
28590
|
+
);
|
|
28591
|
+
return notifications;
|
|
28592
|
+
};
|
|
28593
|
+
#finishWakeup = (sessionId, session, stopReason, cancelRequested) => {
|
|
28594
|
+
if (session.phase.kind !== "wakeup") {
|
|
28595
|
+
return [];
|
|
28596
|
+
}
|
|
28597
|
+
this.#cancelWakeupTimers(session.phase);
|
|
28598
|
+
session.phase = { cancelRequested, kind: "idle" };
|
|
28599
|
+
this.#dropAwaitingResultTasks(session);
|
|
28600
|
+
const notifications = [];
|
|
28601
|
+
const bgNotification = this.#takeBackgroundTasksUpdate(sessionId, session);
|
|
28602
|
+
if (bgNotification !== null) {
|
|
28603
|
+
notifications.push(bgNotification);
|
|
28604
|
+
}
|
|
28605
|
+
notifications.push(
|
|
28606
|
+
makeMetaNotification(sessionId, AGENT_TURN_META, {
|
|
28607
|
+
stage: "ended",
|
|
28608
|
+
stopReason
|
|
28609
|
+
})
|
|
28610
|
+
);
|
|
28611
|
+
return notifications;
|
|
28612
|
+
};
|
|
28613
|
+
#failWakeup = (sessionId, session, message) => {
|
|
28614
|
+
if (session.phase.kind !== "wakeup") {
|
|
28615
|
+
return [];
|
|
28616
|
+
}
|
|
28617
|
+
this.#cancelWakeupTimers(session.phase);
|
|
28618
|
+
session.phase = { cancelRequested: false, kind: "idle" };
|
|
28619
|
+
this.#dropAwaitingResultTasks(session);
|
|
28620
|
+
const notifications = [];
|
|
28621
|
+
const bgNotification = this.#takeBackgroundTasksUpdate(sessionId, session);
|
|
28622
|
+
if (bgNotification !== null) {
|
|
28623
|
+
notifications.push(bgNotification);
|
|
28624
|
+
}
|
|
28625
|
+
notifications.push(
|
|
28626
|
+
makeMetaNotification(sessionId, AGENT_TURN_META, {
|
|
28627
|
+
message,
|
|
28628
|
+
stage: "failed"
|
|
28629
|
+
})
|
|
28630
|
+
);
|
|
28631
|
+
return notifications;
|
|
28632
|
+
};
|
|
28633
|
+
#rescheduleTranscriptCheck = (sessionId, session, generation, stageEpoch, stage) => {
|
|
28634
|
+
if (session.phase.kind !== "wakeup") {
|
|
28635
|
+
return;
|
|
28636
|
+
}
|
|
28637
|
+
const nextCheck = this.#scheduleTranscriptPoll(sessionId, generation, stageEpoch, TRANSCRIPT_POLL_INTERVAL_MS);
|
|
28638
|
+
switch (stage.kind) {
|
|
28639
|
+
case "awaiting-output":
|
|
28640
|
+
session.phase = {
|
|
28641
|
+
...session.phase,
|
|
28642
|
+
stage: { ...stage, transcriptCheck: nextCheck }
|
|
28643
|
+
};
|
|
28644
|
+
return;
|
|
28645
|
+
case "streaming":
|
|
28646
|
+
session.phase = {
|
|
28647
|
+
...session.phase,
|
|
28648
|
+
stage: {
|
|
28649
|
+
...stage,
|
|
28650
|
+
executorErrorPolls: stage.executorError === void 0 ? 0 : stage.executorErrorPolls + 1,
|
|
28651
|
+
transcriptCheck: nextCheck
|
|
28652
|
+
}
|
|
28653
|
+
};
|
|
28654
|
+
return;
|
|
28655
|
+
}
|
|
28656
|
+
};
|
|
28657
|
+
#checkWakeupTranscript = async (sessionId, generation, stageEpoch) => {
|
|
28658
|
+
if (this.#disposed) {
|
|
28659
|
+
return;
|
|
28660
|
+
}
|
|
28661
|
+
const session = this.#sessions.get(sessionId);
|
|
28662
|
+
if (session === void 0 || session.phase.kind !== "wakeup" || session.phase.generation !== generation) {
|
|
28663
|
+
return;
|
|
28664
|
+
}
|
|
28665
|
+
if (session.phase.stage.stageEpoch !== stageEpoch || session.phase.stage.kind !== "streaming" && session.phase.stage.kind !== "awaiting-output") {
|
|
28666
|
+
return;
|
|
28667
|
+
}
|
|
28668
|
+
const tail = await readTranscriptTailState(this.#launchEnvironment, sessionId, session.baselineStepIndex);
|
|
28669
|
+
if (this.#disposed) {
|
|
28670
|
+
return;
|
|
28671
|
+
}
|
|
28672
|
+
const current = this.#sessions.get(sessionId);
|
|
28673
|
+
if (current === void 0 || current.phase.kind !== "wakeup" || current.phase.generation !== generation) {
|
|
28674
|
+
return;
|
|
28675
|
+
}
|
|
28676
|
+
const currentStage = current.phase.stage;
|
|
28677
|
+
if (currentStage.stageEpoch !== stageEpoch || currentStage.kind !== "streaming" && currentStage.kind !== "awaiting-output") {
|
|
28678
|
+
return;
|
|
28679
|
+
}
|
|
28680
|
+
if (tail !== null) {
|
|
28681
|
+
this.#syncSubagentCreations(current, tail.steps);
|
|
28682
|
+
}
|
|
28683
|
+
if (tail?.settledStepIndex !== null && tail?.settledStepIndex !== void 0) {
|
|
28684
|
+
current.baselineStepIndex = Math.max(current.baselineStepIndex, tail.settledStepIndex);
|
|
28685
|
+
this.#consumeSubagentIdlesThrough(current, tail.steps, tail.settledStepIndex);
|
|
28686
|
+
this.#emitNotifications(this.#finishWakeup(sessionId, current, "end_turn", false));
|
|
28687
|
+
return;
|
|
28688
|
+
}
|
|
28689
|
+
if (currentStage.kind === "streaming" && currentStage.executorError !== void 0 && currentStage.executorErrorPolls >= 1) {
|
|
28690
|
+
if (tail !== null && tail.maxStepIndex > current.baselineStepIndex) {
|
|
28691
|
+
current.baselineStepIndex = tail.maxStepIndex;
|
|
28692
|
+
}
|
|
28693
|
+
this.#emitNotifications(this.#failWakeup(sessionId, current, currentStage.executorError));
|
|
28694
|
+
return;
|
|
28695
|
+
}
|
|
28696
|
+
this.#rescheduleTranscriptCheck(sessionId, current, generation, stageEpoch, currentStage);
|
|
28697
|
+
};
|
|
28698
|
+
#handleWakeupTimeout = async (sessionId, generation, stageEpoch, message) => {
|
|
28699
|
+
if (this.#disposed) {
|
|
28700
|
+
return;
|
|
28701
|
+
}
|
|
28702
|
+
const session = this.#sessions.get(sessionId);
|
|
28703
|
+
if (session === void 0 || session.phase.kind !== "wakeup" || session.phase.generation !== generation) {
|
|
28704
|
+
return;
|
|
28705
|
+
}
|
|
28706
|
+
if (session.phase.stage.stageEpoch !== stageEpoch || session.phase.stage.kind !== "awaiting-output" && session.phase.stage.kind !== "streaming") {
|
|
28707
|
+
return;
|
|
28708
|
+
}
|
|
28709
|
+
this.#cancelWakeupTimers(session.phase);
|
|
28710
|
+
session.wakeupStageSeq += 1;
|
|
28711
|
+
const timeoutEpoch = session.wakeupStageSeq;
|
|
28712
|
+
session.phase = {
|
|
28713
|
+
...session.phase,
|
|
28714
|
+
stage: { kind: "verifying-timeout", message, stageEpoch: timeoutEpoch }
|
|
28715
|
+
};
|
|
28716
|
+
const tail = await readTranscriptTailState(this.#launchEnvironment, sessionId, session.baselineStepIndex);
|
|
28717
|
+
if (this.#disposed) {
|
|
28718
|
+
return;
|
|
28719
|
+
}
|
|
28720
|
+
const current = this.#sessions.get(sessionId);
|
|
28721
|
+
if (current === void 0 || current.phase.kind !== "wakeup" || current.phase.generation !== generation) {
|
|
28722
|
+
return;
|
|
28723
|
+
}
|
|
28724
|
+
if (current.phase.stage.kind !== "verifying-timeout" || current.phase.stage.stageEpoch !== timeoutEpoch) {
|
|
28725
|
+
return;
|
|
28726
|
+
}
|
|
28727
|
+
if (tail !== null) {
|
|
28728
|
+
this.#syncSubagentCreations(current, tail.steps);
|
|
28729
|
+
}
|
|
28730
|
+
if (tail?.settledStepIndex !== null && tail?.settledStepIndex !== void 0) {
|
|
28731
|
+
current.baselineStepIndex = Math.max(current.baselineStepIndex, tail.settledStepIndex);
|
|
28732
|
+
this.#consumeSubagentIdlesThrough(current, tail.steps, tail.settledStepIndex);
|
|
28733
|
+
this.#emitNotifications(this.#finishWakeup(sessionId, current, "end_turn", false));
|
|
28734
|
+
return;
|
|
28735
|
+
}
|
|
28736
|
+
if (tail !== null && tail.maxStepIndex > current.baselineStepIndex) {
|
|
28737
|
+
current.baselineStepIndex = tail.maxStepIndex;
|
|
28738
|
+
}
|
|
28739
|
+
this.#emitNotifications(this.#failWakeup(sessionId, current, message));
|
|
28740
|
+
};
|
|
28741
|
+
#promoteOpenWakeupToolsToBackground = (session) => {
|
|
28742
|
+
if (session.phase.kind !== "wakeup" || session.phase.openToolIds.size === 0) {
|
|
28743
|
+
return;
|
|
28744
|
+
}
|
|
28745
|
+
const remainingOpenToolIds = new Set(session.phase.openToolIds);
|
|
28746
|
+
let changed = false;
|
|
28747
|
+
for (const toolCallId of session.phase.openToolIds) {
|
|
28748
|
+
const meta3 = session.toolMetadata.get(toolCallId);
|
|
28749
|
+
if (meta3 === void 0 || meta3.isDaemon) {
|
|
28750
|
+
continue;
|
|
28751
|
+
}
|
|
28752
|
+
const kind = backgroundKindFor(meta3.category);
|
|
28753
|
+
if (kind === "shell" || kind === "other") {
|
|
28754
|
+
remainingOpenToolIds.delete(toolCallId);
|
|
28755
|
+
changed = true;
|
|
28756
|
+
session.backgroundTasks.set(toolCallId, {
|
|
28757
|
+
...meta3.description === void 0 ? {} : { description: meta3.description },
|
|
28758
|
+
kind,
|
|
28759
|
+
state: "running",
|
|
28760
|
+
taskId: toolCallId,
|
|
28761
|
+
toolUseId: toolCallId
|
|
28762
|
+
});
|
|
28763
|
+
}
|
|
28764
|
+
}
|
|
28765
|
+
if (changed) {
|
|
28766
|
+
session.phase = { ...session.phase, openToolIds: remainingOpenToolIds };
|
|
28767
|
+
}
|
|
28768
|
+
};
|
|
28769
|
+
#pauseOrResumeWakeupTimers = (sessionId, session) => {
|
|
28770
|
+
if (session.phase.kind !== "wakeup") {
|
|
28771
|
+
return;
|
|
28772
|
+
}
|
|
28773
|
+
if (session.phase.openToolIds.size > 0 || session.activeInteractions > 0) {
|
|
28774
|
+
if (session.phase.stage.kind !== "blocked-on-work") {
|
|
28775
|
+
this.#setWakeupBlockedOnWork(session, session.phase.generation, session.phase.openToolIds);
|
|
28776
|
+
}
|
|
28777
|
+
} else if (session.phase.stage.kind === "blocked-on-work") {
|
|
28778
|
+
this.#setWakeupAwaitingOutput(sessionId, session, session.phase.generation, session.phase.openToolIds);
|
|
28779
|
+
}
|
|
28780
|
+
};
|
|
28781
|
+
#applyClientPromptToolUpdate = async (sessionId, session, update, cancelled) => {
|
|
28782
|
+
const toolCallId = readString3(update, "toolCallId");
|
|
28783
|
+
const status = readString3(update, "status");
|
|
28784
|
+
if (toolCallId === void 0 || status === void 0) {
|
|
28785
|
+
return;
|
|
28786
|
+
}
|
|
28787
|
+
const meta3 = inspectToolMetadata(update, session.toolMetadata.get(toolCallId));
|
|
28788
|
+
session.toolMetadata.set(toolCallId, meta3);
|
|
28789
|
+
if (meta3.isDaemon) {
|
|
28790
|
+
session.backgroundTasks.delete(toolCallId);
|
|
28791
|
+
return;
|
|
28792
|
+
}
|
|
28793
|
+
if (meta3.category === "manage-subagents" && status === "completed") {
|
|
28794
|
+
await this.#killSubagentsByMetadata(sessionId, session, meta3);
|
|
28795
|
+
return;
|
|
28796
|
+
}
|
|
28797
|
+
if (meta3.category === "subagent") {
|
|
28798
|
+
if (!cancelled && status === "completed") {
|
|
28799
|
+
this.#registerSubagentTask(session, toolCallId, meta3.description);
|
|
28800
|
+
await this.#syncPendingSubagentCreations(sessionId, session);
|
|
28801
|
+
}
|
|
28802
|
+
return;
|
|
28803
|
+
}
|
|
28804
|
+
const kind = backgroundKindFor(meta3.category);
|
|
28805
|
+
if (kind === null) {
|
|
28806
|
+
return;
|
|
28807
|
+
}
|
|
28808
|
+
if (!cancelled && status === "in_progress") {
|
|
28809
|
+
session.backgroundTasks.set(toolCallId, {
|
|
28810
|
+
...meta3.description === void 0 ? {} : { description: meta3.description },
|
|
28811
|
+
kind,
|
|
28812
|
+
state: "running",
|
|
28813
|
+
taskId: toolCallId,
|
|
28814
|
+
toolUseId: toolCallId
|
|
28815
|
+
});
|
|
28816
|
+
return;
|
|
28817
|
+
}
|
|
28818
|
+
if (status === "pending" || status === "completed" || status === "failed" || status === "cancelled") {
|
|
28819
|
+
session.backgroundTasks.delete(toolCallId);
|
|
28820
|
+
}
|
|
28821
|
+
};
|
|
28822
|
+
#applyWakeupToolUpdate = async (sessionId, session, update, notifications) => {
|
|
28823
|
+
if (session.phase.kind !== "wakeup") {
|
|
28824
|
+
return;
|
|
28825
|
+
}
|
|
28826
|
+
const toolCallId = readString3(update, "toolCallId");
|
|
28827
|
+
const status = readString3(update, "status");
|
|
28828
|
+
const updateKind = readString3(update, "sessionUpdate");
|
|
28829
|
+
if (toolCallId === void 0 || status === void 0 || updateKind === void 0) {
|
|
28830
|
+
return;
|
|
28831
|
+
}
|
|
28832
|
+
const meta3 = inspectToolMetadata(update, session.toolMetadata.get(toolCallId));
|
|
28833
|
+
session.toolMetadata.set(toolCallId, meta3);
|
|
28834
|
+
const trackedExisting = session.backgroundTasks.get(toolCallId);
|
|
28835
|
+
if (trackedExisting !== void 0) {
|
|
28836
|
+
if (status === "completed") {
|
|
28837
|
+
session.backgroundTasks.set(toolCallId, { ...trackedExisting, state: "awaiting-results" });
|
|
28838
|
+
const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
|
|
28839
|
+
if (bg2 !== null) {
|
|
28840
|
+
notifications.push(bg2);
|
|
28841
|
+
}
|
|
28842
|
+
if (session.phase.stage.kind === "streaming") {
|
|
28843
|
+
this.#setWakeupAwaitingOutput(
|
|
28844
|
+
sessionId,
|
|
28845
|
+
session,
|
|
28846
|
+
session.phase.generation,
|
|
28847
|
+
session.phase.openToolIds
|
|
28848
|
+
);
|
|
28849
|
+
}
|
|
28850
|
+
} else if (status === "failed" || status === "cancelled") {
|
|
28851
|
+
if (trackedExisting.kind === "subagent") {
|
|
28852
|
+
this.#deleteSubagentTask(session, toolCallId);
|
|
28853
|
+
} else {
|
|
28854
|
+
session.backgroundTasks.delete(toolCallId);
|
|
28855
|
+
}
|
|
28856
|
+
const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
|
|
28857
|
+
if (bg2 !== null) {
|
|
28858
|
+
notifications.push(bg2);
|
|
28859
|
+
}
|
|
28860
|
+
}
|
|
28861
|
+
return;
|
|
28862
|
+
}
|
|
28863
|
+
if (meta3.isDaemon) {
|
|
28864
|
+
if (session.phase.openToolIds.has(toolCallId)) {
|
|
28865
|
+
const nextOpenToolIds = new Set(session.phase.openToolIds);
|
|
28866
|
+
nextOpenToolIds.delete(toolCallId);
|
|
28867
|
+
session.phase = { ...session.phase, openToolIds: nextOpenToolIds };
|
|
28868
|
+
}
|
|
28869
|
+
return;
|
|
28870
|
+
}
|
|
28871
|
+
if (updateKind === "tool_call" && (status === "in_progress" || status === "pending")) {
|
|
28872
|
+
if (!session.phase.openToolIds.has(toolCallId)) {
|
|
28873
|
+
const nextOpenToolIds = new Set(session.phase.openToolIds);
|
|
28874
|
+
nextOpenToolIds.add(toolCallId);
|
|
28875
|
+
session.phase = { ...session.phase, openToolIds: nextOpenToolIds };
|
|
28876
|
+
}
|
|
28877
|
+
this.#pauseOrResumeWakeupTimers(sessionId, session);
|
|
28878
|
+
return;
|
|
28879
|
+
}
|
|
28880
|
+
if (status === "completed" || status === "failed" || status === "cancelled") {
|
|
28881
|
+
if (session.phase.openToolIds.has(toolCallId)) {
|
|
28882
|
+
const nextOpenToolIds = new Set(session.phase.openToolIds);
|
|
28883
|
+
nextOpenToolIds.delete(toolCallId);
|
|
28884
|
+
session.phase = { ...session.phase, openToolIds: nextOpenToolIds };
|
|
28885
|
+
}
|
|
28886
|
+
if (meta3.category === "subagent" && status === "completed") {
|
|
28887
|
+
this.#registerSubagentTask(session, toolCallId, meta3.description);
|
|
28888
|
+
await this.#syncPendingSubagentCreations(sessionId, session);
|
|
28889
|
+
if (this.#disposed || this.#sessions.get(sessionId) !== session) {
|
|
28890
|
+
return;
|
|
28891
|
+
}
|
|
28892
|
+
const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
|
|
28893
|
+
if (bg2 !== null) {
|
|
28894
|
+
notifications.push(bg2);
|
|
28895
|
+
}
|
|
28896
|
+
} else if (meta3.category === "manage-subagents" && status === "completed") {
|
|
28897
|
+
const active = await this.#killSubagentsByMetadata(sessionId, session, meta3);
|
|
28898
|
+
if (!active) {
|
|
28899
|
+
return;
|
|
28900
|
+
}
|
|
28901
|
+
const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
|
|
28902
|
+
if (bg2 !== null) {
|
|
28903
|
+
notifications.push(bg2);
|
|
28904
|
+
}
|
|
28905
|
+
}
|
|
28906
|
+
this.#pauseOrResumeWakeupTimers(sessionId, session);
|
|
28907
|
+
}
|
|
28908
|
+
};
|
|
28909
|
+
onOutgoingMessage = async (message) => {
|
|
28910
|
+
if (this.#disposed || !isRequestMessage2(message)) {
|
|
28911
|
+
return;
|
|
28912
|
+
}
|
|
28913
|
+
const key = requestKeyOf(message.id);
|
|
28914
|
+
const params = isRecord5(message.params) ? message.params : void 0;
|
|
28915
|
+
const sessionId = params === void 0 ? void 0 : readString3(params, "sessionId");
|
|
28916
|
+
switch (message.method) {
|
|
28917
|
+
case methods.agent.session.load: {
|
|
28918
|
+
if (sessionId === void 0) {
|
|
28919
|
+
return;
|
|
28920
|
+
}
|
|
28921
|
+
const session = this.#ensureSession(sessionId);
|
|
28922
|
+
this.#cancelWakeupTimers(session.phase);
|
|
28923
|
+
session.phase = { kind: "loading", requestKey: key };
|
|
28924
|
+
if (key !== void 0) {
|
|
28925
|
+
this.#pendingRequests.set(key, { kind: "load", sessionId });
|
|
28926
|
+
}
|
|
28927
|
+
return;
|
|
28928
|
+
}
|
|
28929
|
+
case methods.agent.session.new:
|
|
28930
|
+
case methods.agent.session.resume: {
|
|
28931
|
+
if (sessionId !== void 0 && key !== void 0) {
|
|
28932
|
+
this.#pendingRequests.set(key, { kind: "session-open", sessionId });
|
|
28933
|
+
}
|
|
28934
|
+
return;
|
|
28935
|
+
}
|
|
28936
|
+
case methods.agent.session.prompt: {
|
|
28937
|
+
if (sessionId === void 0) {
|
|
28938
|
+
return;
|
|
28939
|
+
}
|
|
28940
|
+
const session = this.#ensureSession(sessionId);
|
|
28941
|
+
if (session.phase.kind === "wakeup") {
|
|
28942
|
+
this.#emitNotifications(this.#finishWakeup(sessionId, session, "end_turn", false));
|
|
28943
|
+
}
|
|
28944
|
+
const tail = await readTranscriptTailState(
|
|
28945
|
+
this.#launchEnvironment,
|
|
28946
|
+
sessionId,
|
|
28947
|
+
session.baselineStepIndex
|
|
28948
|
+
);
|
|
28949
|
+
const prePromptStepIndex = Math.max(session.baselineStepIndex, tail?.maxStepIndex ?? -1);
|
|
28950
|
+
session.baselineStepIndex = prePromptStepIndex;
|
|
28951
|
+
session.phase = {
|
|
28952
|
+
cancelled: false,
|
|
28953
|
+
kind: "client-prompt",
|
|
28954
|
+
prePromptStepIndex,
|
|
28955
|
+
requestKey: key
|
|
28956
|
+
};
|
|
28957
|
+
if (key !== void 0) {
|
|
28958
|
+
this.#pendingRequests.set(key, { kind: "prompt", sessionId });
|
|
28959
|
+
}
|
|
28960
|
+
return;
|
|
28961
|
+
}
|
|
28962
|
+
default:
|
|
28963
|
+
return;
|
|
28964
|
+
}
|
|
28965
|
+
};
|
|
28966
|
+
onIncomingMessage = async (message) => {
|
|
28967
|
+
if (this.#disposed) {
|
|
28968
|
+
if (isResponseMessage2(message) && "result" in message && isRecord5(message.result) && readString3(message.result, "stopReason") !== "cancelled") {
|
|
28969
|
+
return { afterUpdates: [], beforeUpdates: [], rewritePromptCancelled: true };
|
|
28970
|
+
}
|
|
28971
|
+
return EMPTY_INCOMING_OUTCOME;
|
|
28972
|
+
}
|
|
28973
|
+
if (isResponseMessage2(message)) {
|
|
28974
|
+
const key = requestKeyOf(message.id);
|
|
28975
|
+
const tracked = key === void 0 ? void 0 : this.#pendingRequests.get(key);
|
|
28976
|
+
if (key !== void 0) {
|
|
28977
|
+
this.#pendingRequests.delete(key);
|
|
28978
|
+
}
|
|
28979
|
+
if (tracked === void 0) {
|
|
28980
|
+
return EMPTY_INCOMING_OUTCOME;
|
|
28981
|
+
}
|
|
28982
|
+
const session2 = this.#ensureSession(tracked.sessionId);
|
|
28983
|
+
if (tracked.kind === "load" || tracked.kind === "session-open") {
|
|
28984
|
+
const tail2 = await readTranscriptTailState(
|
|
28985
|
+
this.#launchEnvironment,
|
|
28986
|
+
tracked.sessionId,
|
|
28987
|
+
session2.baselineStepIndex
|
|
28988
|
+
);
|
|
28989
|
+
if (tail2 !== null) {
|
|
28990
|
+
session2.baselineStepIndex = Math.max(session2.baselineStepIndex, tail2.maxStepIndex);
|
|
28991
|
+
session2.sessionOpenStepIndex = Math.max(session2.sessionOpenStepIndex, tail2.maxStepIndex);
|
|
28992
|
+
}
|
|
28993
|
+
if (tracked.kind === "load") {
|
|
28994
|
+
session2.phase = { cancelRequested: false, kind: "idle" };
|
|
28995
|
+
}
|
|
28996
|
+
return EMPTY_INCOMING_OUTCOME;
|
|
28997
|
+
}
|
|
28998
|
+
const prePromptStepIndex = session2.phase.kind === "client-prompt" ? session2.phase.prePromptStepIndex : session2.baselineStepIndex;
|
|
28999
|
+
const responseStopReason = "result" in message && isRecord5(message.result) ? readString3(message.result, "stopReason") : void 0;
|
|
29000
|
+
const tail = await readTranscriptTailState(
|
|
29001
|
+
this.#launchEnvironment,
|
|
29002
|
+
tracked.sessionId,
|
|
29003
|
+
session2.baselineStepIndex
|
|
29004
|
+
);
|
|
29005
|
+
const promptCancelled = this.#disposed || session2.phase.kind === "client-prompt" && session2.phase.cancelled || session2.phase.kind === "idle" && session2.phase.cancelRequested || responseStopReason === "cancelled";
|
|
29006
|
+
if (tail !== null) {
|
|
29007
|
+
session2.baselineStepIndex = Math.max(session2.baselineStepIndex, tail.maxStepIndex);
|
|
29008
|
+
this.#syncSubagentCreations(session2, tail.steps);
|
|
29009
|
+
if (!promptCancelled) {
|
|
29010
|
+
let lastPlannerStepIndex;
|
|
29011
|
+
for (let index2 = tail.steps.length - 1; index2 >= 0; index2 -= 1) {
|
|
29012
|
+
const step = tail.steps[index2];
|
|
29013
|
+
if (step !== void 0 && step.step_index > prePromptStepIndex && step.step_index <= session2.baselineStepIndex && step.type === "PLANNER_RESPONSE") {
|
|
29014
|
+
lastPlannerStepIndex = step.step_index;
|
|
29015
|
+
break;
|
|
29016
|
+
}
|
|
29017
|
+
}
|
|
29018
|
+
if (lastPlannerStepIndex !== void 0) {
|
|
29019
|
+
this.#consumeSubagentIdlesThrough(session2, tail.steps, lastPlannerStepIndex);
|
|
29020
|
+
}
|
|
29021
|
+
}
|
|
29022
|
+
}
|
|
29023
|
+
if (promptCancelled) {
|
|
29024
|
+
this.#clearAllBackgroundTasks(session2);
|
|
29025
|
+
}
|
|
29026
|
+
session2.phase = { cancelRequested: promptCancelled, kind: "idle" };
|
|
29027
|
+
const bg2 = this.#takeBackgroundTasksUpdate(tracked.sessionId, session2);
|
|
29028
|
+
const rewritePromptCancelled = promptCancelled && "result" in message && isRecord5(message.result) && responseStopReason !== "cancelled";
|
|
29029
|
+
const beforeUpdates = bg2 === null ? [] : [bg2];
|
|
29030
|
+
if (beforeUpdates.length === 0 && !rewritePromptCancelled) {
|
|
29031
|
+
return EMPTY_INCOMING_OUTCOME;
|
|
29032
|
+
}
|
|
29033
|
+
return {
|
|
29034
|
+
afterUpdates: [],
|
|
29035
|
+
beforeUpdates,
|
|
29036
|
+
...rewritePromptCancelled ? { rewritePromptCancelled: true } : {}
|
|
29037
|
+
};
|
|
29038
|
+
}
|
|
29039
|
+
if (!isNotificationMessage2(message) || message.method !== methods.client.session.update) {
|
|
29040
|
+
return EMPTY_INCOMING_OUTCOME;
|
|
29041
|
+
}
|
|
29042
|
+
const params = isRecord5(message.params) ? message.params : void 0;
|
|
29043
|
+
const sessionId = params === void 0 ? void 0 : readString3(params, "sessionId");
|
|
29044
|
+
const update = params === void 0 ? void 0 : params["update"];
|
|
29045
|
+
if (sessionId === void 0 || !isRecord5(update)) {
|
|
29046
|
+
return EMPTY_INCOMING_OUTCOME;
|
|
29047
|
+
}
|
|
29048
|
+
const updateKind = readString3(update, "sessionUpdate");
|
|
29049
|
+
if (updateKind === void 0) {
|
|
29050
|
+
return EMPTY_INCOMING_OUTCOME;
|
|
29051
|
+
}
|
|
29052
|
+
const session = this.#ensureSession(sessionId);
|
|
29053
|
+
switch (session.phase.kind) {
|
|
29054
|
+
case "loading":
|
|
29055
|
+
return EMPTY_INCOMING_OUTCOME;
|
|
29056
|
+
case "client-prompt": {
|
|
29057
|
+
if (updateKind === "tool_call" || updateKind === "tool_call_update") {
|
|
29058
|
+
await this.#applyClientPromptToolUpdate(sessionId, session, update, session.phase.cancelled);
|
|
29059
|
+
}
|
|
29060
|
+
return EMPTY_INCOMING_OUTCOME;
|
|
29061
|
+
}
|
|
29062
|
+
case "idle": {
|
|
29063
|
+
if (updateKind === "tool_call_update") {
|
|
29064
|
+
const toolCallId = readString3(update, "toolCallId");
|
|
29065
|
+
const status = readString3(update, "status");
|
|
29066
|
+
if (toolCallId !== void 0 && status !== void 0) {
|
|
29067
|
+
const existing = session.backgroundTasks.get(toolCallId);
|
|
29068
|
+
if (existing !== void 0) {
|
|
29069
|
+
if (status === "failed" || status === "cancelled") {
|
|
29070
|
+
if (existing.kind === "subagent") {
|
|
29071
|
+
this.#deleteSubagentTask(session, toolCallId);
|
|
29072
|
+
} else {
|
|
29073
|
+
session.backgroundTasks.delete(toolCallId);
|
|
29074
|
+
}
|
|
29075
|
+
const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
|
|
29076
|
+
return bg2 === null ? EMPTY_INCOMING_OUTCOME : { afterUpdates: [bg2], beforeUpdates: [] };
|
|
29077
|
+
}
|
|
29078
|
+
if (status === "completed") {
|
|
29079
|
+
if (session.phase.cancelRequested) {
|
|
29080
|
+
if (existing.kind === "subagent") {
|
|
29081
|
+
this.#deleteSubagentTask(session, toolCallId);
|
|
29082
|
+
} else {
|
|
29083
|
+
session.backgroundTasks.delete(toolCallId);
|
|
29084
|
+
}
|
|
29085
|
+
const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
|
|
29086
|
+
return bg2 === null ? EMPTY_INCOMING_OUTCOME : { afterUpdates: [bg2], beforeUpdates: [] };
|
|
29087
|
+
}
|
|
29088
|
+
session.backgroundTasks.set(toolCallId, {
|
|
29089
|
+
...existing,
|
|
29090
|
+
state: "awaiting-results"
|
|
29091
|
+
});
|
|
29092
|
+
return {
|
|
29093
|
+
afterUpdates: [],
|
|
29094
|
+
beforeUpdates: this.#enterWakeup(sessionId, session, [toolCallId])
|
|
29095
|
+
};
|
|
29096
|
+
}
|
|
29097
|
+
}
|
|
29098
|
+
}
|
|
29099
|
+
return EMPTY_INCOMING_OUTCOME;
|
|
29100
|
+
}
|
|
29101
|
+
if (session.phase.cancelRequested || !isWakeupStartUpdateKind(updateKind)) {
|
|
29102
|
+
return EMPTY_INCOMING_OUTCOME;
|
|
29103
|
+
}
|
|
29104
|
+
if (updateKind === "tool_call") {
|
|
29105
|
+
const meta3 = inspectToolMetadata(update, void 0);
|
|
29106
|
+
if (meta3.isDaemon) {
|
|
29107
|
+
return EMPTY_INCOMING_OUTCOME;
|
|
29108
|
+
}
|
|
29109
|
+
}
|
|
29110
|
+
let matchedTaskIds = [];
|
|
29111
|
+
if (this.#hasSubagentTasks(session)) {
|
|
29112
|
+
const tail = await readTranscriptTailState(
|
|
29113
|
+
this.#launchEnvironment,
|
|
29114
|
+
sessionId,
|
|
29115
|
+
session.baselineStepIndex
|
|
29116
|
+
);
|
|
29117
|
+
if (this.#disposed || this.#sessions.get(sessionId) !== session) {
|
|
29118
|
+
return EMPTY_INCOMING_OUTCOME;
|
|
29119
|
+
}
|
|
29120
|
+
if (session.phase.kind !== "idle" || session.phase.cancelRequested) {
|
|
29121
|
+
return EMPTY_INCOMING_OUTCOME;
|
|
29122
|
+
}
|
|
29123
|
+
if (tail !== null) {
|
|
29124
|
+
this.#syncSubagentCreations(session, tail.steps);
|
|
29125
|
+
matchedTaskIds = this.#markTriggeredSubagentIdles(session, tail.steps);
|
|
29126
|
+
}
|
|
29127
|
+
}
|
|
29128
|
+
const startedNotifications = this.#enterWakeup(sessionId, session, matchedTaskIds);
|
|
29129
|
+
const extraWakeup = [];
|
|
29130
|
+
await this.#handleWakeupUpdate(sessionId, session, updateKind, update, extraWakeup);
|
|
29131
|
+
return {
|
|
29132
|
+
afterUpdates: [],
|
|
29133
|
+
beforeUpdates: [...startedNotifications, ...extraWakeup]
|
|
29134
|
+
};
|
|
29135
|
+
}
|
|
29136
|
+
case "wakeup": {
|
|
29137
|
+
const beforeUpdates = [];
|
|
29138
|
+
await this.#handleWakeupUpdate(sessionId, session, updateKind, update, beforeUpdates);
|
|
29139
|
+
return beforeUpdates.length === 0 ? EMPTY_INCOMING_OUTCOME : { afterUpdates: [], beforeUpdates };
|
|
29140
|
+
}
|
|
29141
|
+
default: {
|
|
29142
|
+
const unreachable2 = session.phase;
|
|
29143
|
+
throw new Error(`Unexpected Antigravity session phase: ${String(unreachable2)}`);
|
|
29144
|
+
}
|
|
29145
|
+
}
|
|
29146
|
+
};
|
|
29147
|
+
#handleWakeupUpdate = async (sessionId, session, updateKind, update, beforeUpdates) => {
|
|
29148
|
+
if (session.phase.kind !== "wakeup") {
|
|
29149
|
+
return;
|
|
29150
|
+
}
|
|
29151
|
+
if (updateKind === "tool_call" || updateKind === "tool_call_update") {
|
|
29152
|
+
await this.#applyWakeupToolUpdate(sessionId, session, update, beforeUpdates);
|
|
29153
|
+
return;
|
|
29154
|
+
}
|
|
29155
|
+
if (isWakeupChunkUpdateKind(updateKind)) {
|
|
29156
|
+
const executorError = extractExecutorError(updateKind, update);
|
|
29157
|
+
this.#promoteOpenWakeupToolsToBackground(session);
|
|
29158
|
+
const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
|
|
29159
|
+
if (bg2 !== null) {
|
|
29160
|
+
beforeUpdates.push(bg2);
|
|
29161
|
+
}
|
|
29162
|
+
if (session.phase.openToolIds.size === 0 && session.activeInteractions === 0) {
|
|
29163
|
+
this.#setWakeupStreaming(
|
|
29164
|
+
sessionId,
|
|
29165
|
+
session,
|
|
29166
|
+
session.phase.generation,
|
|
29167
|
+
session.phase.openToolIds,
|
|
29168
|
+
executorError
|
|
29169
|
+
);
|
|
29170
|
+
}
|
|
29171
|
+
}
|
|
29172
|
+
};
|
|
29173
|
+
beginInteraction = (sessionId) => {
|
|
29174
|
+
if (this.#disposed) {
|
|
29175
|
+
return;
|
|
29176
|
+
}
|
|
29177
|
+
const session = this.#ensureSession(sessionId);
|
|
29178
|
+
session.activeInteractions += 1;
|
|
29179
|
+
this.#pauseOrResumeWakeupTimers(sessionId, session);
|
|
29180
|
+
};
|
|
29181
|
+
endInteraction = (sessionId) => {
|
|
29182
|
+
if (this.#disposed) {
|
|
29183
|
+
return;
|
|
29184
|
+
}
|
|
29185
|
+
const session = this.#sessions.get(sessionId);
|
|
29186
|
+
if (session === void 0) {
|
|
29187
|
+
return;
|
|
29188
|
+
}
|
|
29189
|
+
session.activeInteractions = Math.max(0, session.activeInteractions - 1);
|
|
29190
|
+
this.#pauseOrResumeWakeupTimers(sessionId, session);
|
|
29191
|
+
};
|
|
29192
|
+
cancelSession = (sessionId) => {
|
|
29193
|
+
if (this.#disposed) {
|
|
29194
|
+
return "retain";
|
|
29195
|
+
}
|
|
29196
|
+
const session = this.#ensureSession(sessionId);
|
|
29197
|
+
const mustClose = session.phase.kind === "wakeup" || this.#hasSubagentTasks(session);
|
|
29198
|
+
if (mustClose) {
|
|
29199
|
+
this.#cancelWakeupTimers(session.phase);
|
|
29200
|
+
this.#clearAllBackgroundTasks(session);
|
|
29201
|
+
session.phase = session.phase.kind === "client-prompt" ? { ...session.phase, cancelled: true } : { cancelRequested: true, kind: "idle" };
|
|
29202
|
+
return "close";
|
|
29203
|
+
}
|
|
29204
|
+
if (session.phase.kind === "client-prompt") {
|
|
29205
|
+
session.phase = { ...session.phase, cancelled: true };
|
|
29206
|
+
} else if (session.phase.kind === "idle") {
|
|
29207
|
+
session.phase = { cancelRequested: true, kind: "idle" };
|
|
29208
|
+
}
|
|
29209
|
+
return "retain";
|
|
29210
|
+
};
|
|
29211
|
+
onUnexpectedProcessExit = (message) => {
|
|
29212
|
+
if (this.#disposed) {
|
|
29213
|
+
return;
|
|
29214
|
+
}
|
|
29215
|
+
for (const [sessionId, session] of this.#sessions) {
|
|
29216
|
+
const wasWakeup = session.phase.kind === "wakeup";
|
|
29217
|
+
this.#cancelWakeupTimers(session.phase);
|
|
29218
|
+
this.#clearAllBackgroundTasks(session);
|
|
29219
|
+
if (wasWakeup) {
|
|
29220
|
+
session.phase = { cancelRequested: false, kind: "idle" };
|
|
29221
|
+
this.#emitMetaUpdate(
|
|
29222
|
+
makeMetaNotification(sessionId, AGENT_TURN_META, {
|
|
29223
|
+
message,
|
|
29224
|
+
stage: "failed"
|
|
29225
|
+
})
|
|
29226
|
+
);
|
|
29227
|
+
} else if (session.phase.kind === "idle") {
|
|
29228
|
+
session.phase = { cancelRequested: false, kind: "idle" };
|
|
29229
|
+
}
|
|
29230
|
+
const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
|
|
29231
|
+
if (bg2 !== null) {
|
|
29232
|
+
this.#emitMetaUpdate(bg2);
|
|
29233
|
+
}
|
|
29234
|
+
}
|
|
29235
|
+
};
|
|
29236
|
+
dispose = () => {
|
|
29237
|
+
if (this.#disposed) {
|
|
29238
|
+
return;
|
|
29239
|
+
}
|
|
29240
|
+
this.#disposed = true;
|
|
29241
|
+
for (const session of this.#sessions.values()) {
|
|
29242
|
+
this.#cancelWakeupTimers(session.phase);
|
|
29243
|
+
}
|
|
29244
|
+
this.#sessions.clear();
|
|
29245
|
+
this.#pendingRequests.clear();
|
|
29246
|
+
};
|
|
29247
|
+
};
|
|
29248
|
+
|
|
27948
29249
|
// src/engine/acp/adapter/antigravity/agent-connection.ts
|
|
27949
29250
|
var FULL_ACCESS_MODE_ID = "full-access";
|
|
27950
29251
|
var FULL_ACCESS_MODE_NAME = "Full access";
|
|
@@ -28041,23 +29342,49 @@ function identifySessionUpdate(update, state) {
|
|
|
28041
29342
|
return { nextState: { kind: "none" }, update };
|
|
28042
29343
|
}
|
|
28043
29344
|
}
|
|
28044
|
-
function
|
|
29345
|
+
function isRequestMessage3(message) {
|
|
28045
29346
|
return "method" in message && "id" in message;
|
|
28046
29347
|
}
|
|
28047
|
-
function
|
|
29348
|
+
function isNotificationMessage3(message) {
|
|
28048
29349
|
return "method" in message && !("id" in message);
|
|
28049
29350
|
}
|
|
28050
|
-
function
|
|
29351
|
+
function isResponseMessage3(message) {
|
|
28051
29352
|
return "id" in message && !("method" in message);
|
|
28052
29353
|
}
|
|
28053
|
-
function
|
|
29354
|
+
function requestKeyOf2(id) {
|
|
28054
29355
|
return typeof id === "string" || typeof id === "number" ? id : void 0;
|
|
28055
29356
|
}
|
|
29357
|
+
function hasMobiusWakeupMeta(update) {
|
|
29358
|
+
if (update.sessionUpdate !== "session_info_update") {
|
|
29359
|
+
return false;
|
|
29360
|
+
}
|
|
29361
|
+
const meta3 = update._meta;
|
|
29362
|
+
return meta3 !== void 0 && meta3 !== null && (BACKGROUND_TASKS_META in meta3 || AGENT_TURN_META in meta3);
|
|
29363
|
+
}
|
|
29364
|
+
function toJsonRpcNotification(notification) {
|
|
29365
|
+
return {
|
|
29366
|
+
jsonrpc: "2.0",
|
|
29367
|
+
method: methods.client.session.update,
|
|
29368
|
+
params: notification
|
|
29369
|
+
};
|
|
29370
|
+
}
|
|
29371
|
+
var activeConnectionsByClient = /* @__PURE__ */ new WeakMap();
|
|
29372
|
+
async function prepareAntigravitySessionCancel(clientConnection2, sessionId) {
|
|
29373
|
+
const owner = activeConnectionsByClient.get(clientConnection2);
|
|
29374
|
+
if (owner === void 0) {
|
|
29375
|
+
return "retain";
|
|
29376
|
+
}
|
|
29377
|
+
return await owner.prepareSessionCancel(sessionId);
|
|
29378
|
+
}
|
|
28056
29379
|
var AntigravityAgentConnection = class {
|
|
28057
29380
|
connection;
|
|
28058
29381
|
termination;
|
|
28059
29382
|
#child;
|
|
28060
29383
|
#consumeStderr;
|
|
29384
|
+
#clientOnUpdate;
|
|
29385
|
+
#backgroundWakeup;
|
|
29386
|
+
#deliveries = new SerialTaskQueue();
|
|
29387
|
+
#deliveryAbort = new AbortController();
|
|
28061
29388
|
#permissionModes = /* @__PURE__ */ new Map();
|
|
28062
29389
|
#messageStreams = /* @__PURE__ */ new Map();
|
|
28063
29390
|
#pendingRequests = /* @__PURE__ */ new Map();
|
|
@@ -28066,21 +29393,31 @@ var AntigravityAgentConnection = class {
|
|
|
28066
29393
|
#sessionEstablished = false;
|
|
28067
29394
|
#closePromise = null;
|
|
28068
29395
|
constructor(options) {
|
|
29396
|
+
this.#clientOnUpdate = options.client.onUpdate;
|
|
29397
|
+
const launchEnvironment = {
|
|
29398
|
+
...process.env,
|
|
29399
|
+
...options.environment,
|
|
29400
|
+
BROWSER: "false"
|
|
29401
|
+
};
|
|
29402
|
+
this.#backgroundWakeup = new AntigravityBackgroundWakeup({
|
|
29403
|
+
emitMetaUpdate: (notification) => {
|
|
29404
|
+
this.#queueMetaUpdate(notification);
|
|
29405
|
+
},
|
|
29406
|
+
launchEnvironment,
|
|
29407
|
+
...options.timer === void 0 ? {} : { timer: options.timer }
|
|
29408
|
+
});
|
|
28069
29409
|
const launch = executableLaunch2(options.command, ["acp"]);
|
|
28070
29410
|
const child = spawn2(launch.command, [...launch.arguments], {
|
|
28071
29411
|
cwd: options.cwd,
|
|
28072
29412
|
...platformSpawnOptions,
|
|
28073
|
-
env:
|
|
28074
|
-
...process.env,
|
|
28075
|
-
...options.environment,
|
|
28076
|
-
BROWSER: "false"
|
|
28077
|
-
},
|
|
29413
|
+
env: launchEnvironment,
|
|
28078
29414
|
shell: false,
|
|
28079
29415
|
stdio: ["pipe", "pipe", "pipe"]
|
|
28080
29416
|
});
|
|
28081
29417
|
this.#child = child;
|
|
28082
29418
|
const { stdin, stdout, stderr } = child;
|
|
28083
29419
|
if (stdin === null || stdout === null || stderr === null) {
|
|
29420
|
+
this.#backgroundWakeup.dispose();
|
|
28084
29421
|
child.kill("SIGKILL");
|
|
28085
29422
|
throw new AcpExecutionError("Antigravity ACP process streams are unavailable");
|
|
28086
29423
|
}
|
|
@@ -28095,15 +29432,31 @@ var AntigravityAgentConnection = class {
|
|
|
28095
29432
|
};
|
|
28096
29433
|
this.termination = termination.promise;
|
|
28097
29434
|
child.once("error", (cause) => {
|
|
28098
|
-
|
|
28099
|
-
|
|
28100
|
-
|
|
29435
|
+
const terminationError = new AcpExecutionError("Antigravity ACP process failed to start", { cause });
|
|
29436
|
+
if (this.#closePromise === null) {
|
|
29437
|
+
this.#backgroundWakeup.onUnexpectedProcessExit(terminationError.message);
|
|
29438
|
+
this.#backgroundWakeup.dispose();
|
|
29439
|
+
}
|
|
29440
|
+
void this.#flushDeliveries().finally(() => {
|
|
29441
|
+
resolveTermination({
|
|
29442
|
+
kind: "failed",
|
|
29443
|
+
error: terminationError
|
|
29444
|
+
});
|
|
28101
29445
|
});
|
|
28102
29446
|
});
|
|
28103
29447
|
child.once("exit", (code, signal) => {
|
|
28104
|
-
|
|
28105
|
-
|
|
28106
|
-
|
|
29448
|
+
const terminationError = new AcpExecutionError("The Antigravity ACP process stopped", {
|
|
29449
|
+
cause: { code, signal }
|
|
29450
|
+
});
|
|
29451
|
+
if (this.#closePromise === null) {
|
|
29452
|
+
this.#backgroundWakeup.onUnexpectedProcessExit(terminationError.message);
|
|
29453
|
+
this.#backgroundWakeup.dispose();
|
|
29454
|
+
}
|
|
29455
|
+
void this.#flushDeliveries().finally(() => {
|
|
29456
|
+
resolveTermination({
|
|
29457
|
+
kind: "failed",
|
|
29458
|
+
error: terminationError
|
|
29459
|
+
});
|
|
28107
29460
|
});
|
|
28108
29461
|
});
|
|
28109
29462
|
let stderrTail = "";
|
|
@@ -28149,13 +29502,10 @@ var AntigravityAgentConnection = class {
|
|
|
28149
29502
|
};
|
|
28150
29503
|
let pendingUpdates = 0;
|
|
28151
29504
|
this.connection = createAcpClient(clientHandler).onNotification(methods.client.session.update, async ({ params }) => {
|
|
28152
|
-
const currentState = this.#messageStreams.get(params.sessionId) ?? { kind: "none" };
|
|
28153
|
-
const identified = identifySessionUpdate(params.update, currentState);
|
|
28154
|
-
this.#messageStreams.set(params.sessionId, identified.nextState);
|
|
28155
29505
|
pendingUpdates += 1;
|
|
28156
29506
|
stdout.pause();
|
|
28157
29507
|
try {
|
|
28158
|
-
await
|
|
29508
|
+
await this.#deliverUpdateNotification(params);
|
|
28159
29509
|
} finally {
|
|
28160
29510
|
pendingUpdates -= 1;
|
|
28161
29511
|
if (pendingUpdates === 0) {
|
|
@@ -28163,7 +29513,55 @@ var AntigravityAgentConnection = class {
|
|
|
28163
29513
|
}
|
|
28164
29514
|
}
|
|
28165
29515
|
}).connect(wrappedStream);
|
|
29516
|
+
activeConnectionsByClient.set(this.connection, this);
|
|
28166
29517
|
}
|
|
29518
|
+
#deliverUpdateNotification = async (params) => {
|
|
29519
|
+
if (this.#deliveryAbort.signal.aborted) {
|
|
29520
|
+
return;
|
|
29521
|
+
}
|
|
29522
|
+
try {
|
|
29523
|
+
await this.#deliveries.run(async () => {
|
|
29524
|
+
if (hasMobiusWakeupMeta(params.update)) {
|
|
29525
|
+
const meta3 = params.update._meta;
|
|
29526
|
+
if (meta3 !== void 0 && meta3 !== null && AGENT_TURN_META in meta3) {
|
|
29527
|
+
this.#messageStreams.set(params.sessionId, { kind: "none" });
|
|
29528
|
+
}
|
|
29529
|
+
await this.#clientOnUpdate({ ...params, update: params.update });
|
|
29530
|
+
return;
|
|
29531
|
+
}
|
|
29532
|
+
const currentState = this.#messageStreams.get(params.sessionId) ?? { kind: "none" };
|
|
29533
|
+
const identified = identifySessionUpdate(params.update, currentState);
|
|
29534
|
+
this.#messageStreams.set(params.sessionId, identified.nextState);
|
|
29535
|
+
await this.#clientOnUpdate({ ...params, update: identified.update });
|
|
29536
|
+
}, this.#deliveryAbort.signal);
|
|
29537
|
+
} catch (error62) {
|
|
29538
|
+
if (!this.#deliveryAbort.signal.aborted) {
|
|
29539
|
+
throw error62;
|
|
29540
|
+
}
|
|
29541
|
+
}
|
|
29542
|
+
};
|
|
29543
|
+
#queueMetaUpdate = (notification) => {
|
|
29544
|
+
if (this.#deliveryAbort.signal.aborted) {
|
|
29545
|
+
return;
|
|
29546
|
+
}
|
|
29547
|
+
void this.#deliveries.run(async () => {
|
|
29548
|
+
await this.#clientOnUpdate(notification);
|
|
29549
|
+
}, this.#deliveryAbort.signal).catch(() => void 0);
|
|
29550
|
+
};
|
|
29551
|
+
#flushDeliveries = async () => {
|
|
29552
|
+
if (this.#deliveryAbort.signal.aborted) {
|
|
29553
|
+
return;
|
|
29554
|
+
}
|
|
29555
|
+
try {
|
|
29556
|
+
await this.#deliveries.run(async () => void 0, this.#deliveryAbort.signal);
|
|
29557
|
+
} catch {
|
|
29558
|
+
}
|
|
29559
|
+
};
|
|
29560
|
+
prepareSessionCancel = async (sessionId) => {
|
|
29561
|
+
const disposition = this.#backgroundWakeup.cancelSession(sessionId);
|
|
29562
|
+
await this.#flushDeliveries();
|
|
29563
|
+
return disposition;
|
|
29564
|
+
};
|
|
28167
29565
|
initialize = async (signal) => {
|
|
28168
29566
|
signal.throwIfAborted();
|
|
28169
29567
|
};
|
|
@@ -28171,11 +29569,15 @@ var AntigravityAgentConnection = class {
|
|
|
28171
29569
|
closeProcess = () => {
|
|
28172
29570
|
this.#closePromise ??= (async () => {
|
|
28173
29571
|
try {
|
|
28174
|
-
|
|
29572
|
+
this.#child.stdout?.pause();
|
|
29573
|
+
this.#deliveryAbort.abort(new DOMException("Antigravity ACP connection closed", "AbortError"));
|
|
28175
29574
|
this.connection.close();
|
|
29575
|
+
this.#backgroundWakeup.dispose();
|
|
29576
|
+
const captured = await captureProcessTree(this.#child);
|
|
28176
29577
|
this.#child.stdin?.end();
|
|
28177
29578
|
await stopProcessTree(this.#child, captured);
|
|
28178
29579
|
} finally {
|
|
29580
|
+
this.#backgroundWakeup.dispose();
|
|
28179
29581
|
this.#child.stderr?.removeListener("data", this.#consumeStderr);
|
|
28180
29582
|
this.connection.close();
|
|
28181
29583
|
}
|
|
@@ -28218,7 +29620,12 @@ var AntigravityAgentConnection = class {
|
|
|
28218
29620
|
signal.throwIfAborted();
|
|
28219
29621
|
const modeState = this.#permissionModes.get(request.sessionId) ?? { kind: "native" };
|
|
28220
29622
|
if (modeState.kind !== "full-access") {
|
|
28221
|
-
|
|
29623
|
+
this.#backgroundWakeup.beginInteraction(request.sessionId);
|
|
29624
|
+
try {
|
|
29625
|
+
return await client2.onPermission(request, signal);
|
|
29626
|
+
} finally {
|
|
29627
|
+
this.#backgroundWakeup.endInteraction(request.sessionId);
|
|
29628
|
+
}
|
|
28222
29629
|
}
|
|
28223
29630
|
const allowOption = request.options.find((option) => option.kind === "allow_once") ?? request.options.find((option) => option.kind === "allow_always");
|
|
28224
29631
|
if (allowOption === void 0) {
|
|
@@ -28233,10 +29640,19 @@ var AntigravityAgentConnection = class {
|
|
|
28233
29640
|
if (modeState.kind === "full-access") {
|
|
28234
29641
|
return { action: "decline" };
|
|
28235
29642
|
}
|
|
28236
|
-
|
|
29643
|
+
if (sessionId !== void 0) {
|
|
29644
|
+
this.#backgroundWakeup.beginInteraction(sessionId);
|
|
29645
|
+
}
|
|
29646
|
+
try {
|
|
29647
|
+
return await client2.onElicitation(request, signal);
|
|
29648
|
+
} finally {
|
|
29649
|
+
if (sessionId !== void 0) {
|
|
29650
|
+
this.#backgroundWakeup.endInteraction(sessionId);
|
|
29651
|
+
}
|
|
29652
|
+
}
|
|
28237
29653
|
};
|
|
28238
29654
|
#transformOutgoing = (message) => {
|
|
28239
|
-
if (
|
|
29655
|
+
if (isNotificationMessage3(message) && message.method === CANCEL_REQUEST_METHOD2) {
|
|
28240
29656
|
const params2 = isRecord5(message.params) ? message.params : void 0;
|
|
28241
29657
|
const rawRequestId = params2 === void 0 ? void 0 : params2["requestId"];
|
|
28242
29658
|
const targetKey = typeof rawRequestId === "string" || typeof rawRequestId === "number" ? rawRequestId : void 0;
|
|
@@ -28246,12 +29662,12 @@ var AntigravityAgentConnection = class {
|
|
|
28246
29662
|
}
|
|
28247
29663
|
return message;
|
|
28248
29664
|
}
|
|
28249
|
-
if (!
|
|
29665
|
+
if (!isRequestMessage3(message)) {
|
|
28250
29666
|
return message;
|
|
28251
29667
|
}
|
|
28252
29668
|
const params = isRecord5(message.params) ? message.params : void 0;
|
|
28253
29669
|
const sessionId = params === void 0 ? void 0 : readStringProperty(params, "sessionId");
|
|
28254
|
-
const key =
|
|
29670
|
+
const key = requestKeyOf2(message.id);
|
|
28255
29671
|
switch (message.method) {
|
|
28256
29672
|
case methods.agent.session.prompt: {
|
|
28257
29673
|
if (sessionId !== void 0) {
|
|
@@ -28331,8 +29747,8 @@ var AntigravityAgentConnection = class {
|
|
|
28331
29747
|
return true;
|
|
28332
29748
|
};
|
|
28333
29749
|
#transformIncoming = (message) => {
|
|
28334
|
-
if (
|
|
28335
|
-
const key =
|
|
29750
|
+
if (isResponseMessage3(message)) {
|
|
29751
|
+
const key = requestKeyOf2(message.id);
|
|
28336
29752
|
const tracked = key === void 0 ? void 0 : this.#pendingRequests.get(key);
|
|
28337
29753
|
if (key !== void 0) {
|
|
28338
29754
|
this.#pendingRequests.delete(key);
|
|
@@ -28367,7 +29783,7 @@ var AntigravityAgentConnection = class {
|
|
|
28367
29783
|
const result = augmentModeInConfigPayload(message.result, modeState);
|
|
28368
29784
|
return result === message.result ? message : { ...message, result };
|
|
28369
29785
|
}
|
|
28370
|
-
if (
|
|
29786
|
+
if (isNotificationMessage3(message) && message.method === methods.client.session.update) {
|
|
28371
29787
|
const params = message.params;
|
|
28372
29788
|
if (!isRecord5(params)) {
|
|
28373
29789
|
return message;
|
|
@@ -28409,17 +29825,53 @@ var AntigravityAgentConnection = class {
|
|
|
28409
29825
|
const transformIncoming = this.#transformIncoming;
|
|
28410
29826
|
const readable = rawStream.readable.pipeThrough(
|
|
28411
29827
|
new TransformStream({
|
|
28412
|
-
transform(chunk, controller) {
|
|
29828
|
+
transform: async (chunk, controller) => {
|
|
29829
|
+
if (this.#closePromise !== null || this.#deliveryAbort.signal.aborted) {
|
|
29830
|
+
return;
|
|
29831
|
+
}
|
|
28413
29832
|
const transformed = transformIncoming(chunk);
|
|
28414
|
-
if (transformed
|
|
28415
|
-
|
|
29833
|
+
if (transformed === void 0) {
|
|
29834
|
+
return;
|
|
29835
|
+
}
|
|
29836
|
+
const outcome = await this.#backgroundWakeup.onIncomingMessage(transformed);
|
|
29837
|
+
if (this.#closePromise !== null || this.#deliveryAbort.signal.aborted) {
|
|
29838
|
+
return;
|
|
29839
|
+
}
|
|
29840
|
+
if (isResponseMessage3(transformed)) {
|
|
29841
|
+
for (const metaUpdate of outcome.beforeUpdates) {
|
|
29842
|
+
this.#queueMetaUpdate(metaUpdate);
|
|
29843
|
+
}
|
|
29844
|
+
if (outcome.beforeUpdates.length > 0) {
|
|
29845
|
+
await this.#flushDeliveries();
|
|
29846
|
+
}
|
|
29847
|
+
const outgoingResponse = outcome.rewritePromptCancelled === true && "result" in transformed && isRecord5(transformed.result) ? {
|
|
29848
|
+
...transformed,
|
|
29849
|
+
result: { ...transformed.result, stopReason: "cancelled" }
|
|
29850
|
+
} : transformed;
|
|
29851
|
+
controller.enqueue(outgoingResponse);
|
|
29852
|
+
for (const metaUpdate of outcome.afterUpdates) {
|
|
29853
|
+
this.#queueMetaUpdate(metaUpdate);
|
|
29854
|
+
}
|
|
29855
|
+
return;
|
|
29856
|
+
}
|
|
29857
|
+
for (const metaUpdate of outcome.beforeUpdates) {
|
|
29858
|
+
controller.enqueue(toJsonRpcNotification(metaUpdate));
|
|
29859
|
+
}
|
|
29860
|
+
controller.enqueue(transformed);
|
|
29861
|
+
for (const metaUpdate of outcome.afterUpdates) {
|
|
29862
|
+
controller.enqueue(toJsonRpcNotification(metaUpdate));
|
|
28416
29863
|
}
|
|
28417
29864
|
}
|
|
28418
29865
|
})
|
|
28419
29866
|
);
|
|
28420
29867
|
const writable = new WritableStream({
|
|
28421
|
-
write(chunk) {
|
|
28422
|
-
|
|
29868
|
+
write: async (chunk) => {
|
|
29869
|
+
const outgoing = transformOutgoing(chunk);
|
|
29870
|
+
await this.#backgroundWakeup.onOutgoingMessage(outgoing);
|
|
29871
|
+
if (isRequestMessage3(outgoing) && outgoing.method === methods.agent.session.prompt) {
|
|
29872
|
+
await this.#flushDeliveries();
|
|
29873
|
+
}
|
|
29874
|
+
return await writer.write(outgoing);
|
|
28423
29875
|
},
|
|
28424
29876
|
close() {
|
|
28425
29877
|
return writer.close();
|
|
@@ -28495,14 +29947,19 @@ var AntigravityAgentSpecification = class extends InProcessAcpAgentSpecification
|
|
|
28495
29947
|
acpProbeTimeoutMilliseconds = ACP_PROBE_TIMEOUT_MILLISECONDS2;
|
|
28496
29948
|
adapterVersionArguments = Object.freeze([]);
|
|
28497
29949
|
agentExecutable = "agy";
|
|
28498
|
-
|
|
29950
|
+
#timer;
|
|
29951
|
+
createConnection = (options) => new AntigravityAgentConnection({
|
|
29952
|
+
...options,
|
|
29953
|
+
...this.#timer === void 0 ? {} : { timer: this.#timer }
|
|
29954
|
+
});
|
|
28499
29955
|
id = "antigravity";
|
|
28500
29956
|
label = "Antigravity";
|
|
28501
29957
|
minimumSupportedAgentVersion = "1.5.1";
|
|
28502
29958
|
maximumTestedAgentVersion = "1.5.10";
|
|
28503
29959
|
authenticationCommand = () => "agy acp --login";
|
|
28504
|
-
constructor() {
|
|
29960
|
+
constructor(options) {
|
|
28505
29961
|
super("MOBIUS_ANTIGRAVITY_PATH");
|
|
29962
|
+
this.#timer = options?.timer;
|
|
28506
29963
|
}
|
|
28507
29964
|
resolveInstalledAgentExecutables = async (context) => {
|
|
28508
29965
|
context.signal.throwIfAborted();
|
|
@@ -74013,19 +75470,6 @@ var CodexAppServerClient = class {
|
|
|
74013
75470
|
// src/engine/acp/harness/codex/borrowed-agent.ts
|
|
74014
75471
|
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
74015
75472
|
|
|
74016
|
-
// src/engine/util/timer.ts
|
|
74017
|
-
var SystemTimer = class {
|
|
74018
|
-
schedule = (callback, milliseconds) => {
|
|
74019
|
-
const timeout = setTimeout(callback, milliseconds);
|
|
74020
|
-
return {
|
|
74021
|
-
cancel: () => {
|
|
74022
|
-
clearTimeout(timeout);
|
|
74023
|
-
}
|
|
74024
|
-
};
|
|
74025
|
-
};
|
|
74026
|
-
};
|
|
74027
|
-
var systemTimer = new SystemTimer();
|
|
74028
|
-
|
|
74029
75473
|
// src/engine/acp/harness/codex/items.ts
|
|
74030
75474
|
import { pathToFileURL } from "node:url";
|
|
74031
75475
|
var TOOL_OUTPUT_CHARACTER_LIMIT = 32768;
|
|
@@ -76641,13 +78085,13 @@ var CodexAgentSpecification = class extends InProcessAcpAgentSpecification {
|
|
|
76641
78085
|
|
|
76642
78086
|
// src/engine/agent/specification/vendors/pi-agent.ts
|
|
76643
78087
|
import { createHash as createHash3 } from "node:crypto";
|
|
76644
|
-
import { join as
|
|
78088
|
+
import { join as join23 } from "node:path";
|
|
76645
78089
|
|
|
76646
78090
|
// src/engine/acp/harness/pi/upstream/dist/acp/agent.js
|
|
76647
78091
|
import { spawnSync } from "node:child_process";
|
|
76648
78092
|
import { randomUUID as randomUUID12 } from "node:crypto";
|
|
76649
78093
|
import { existsSync as existsSync8, readdirSync as readdirSync6, readFileSync as readFileSync9, realpathSync as realpathSync3, statSync as statSync3, unlinkSync as unlinkSync2 } from "node:fs";
|
|
76650
|
-
import { basename as basename6, dirname as dirname8, isAbsolute as isAbsolute13, join as
|
|
78094
|
+
import { basename as basename6, dirname as dirname8, isAbsolute as isAbsolute13, join as join22 } from "node:path";
|
|
76651
78095
|
|
|
76652
78096
|
// src/engine/acp/harness/pi/upstream/dist/pi-rpc/process.js
|
|
76653
78097
|
import { spawn as spawn6 } from "node:child_process";
|
|
@@ -77103,20 +78547,20 @@ function maybeAuthRequiredError(err) {
|
|
|
77103
78547
|
}
|
|
77104
78548
|
|
|
77105
78549
|
// src/engine/acp/harness/pi/upstream/dist/acp/paths.js
|
|
77106
|
-
import { join as
|
|
78550
|
+
import { join as join18 } from "node:path";
|
|
77107
78551
|
|
|
77108
78552
|
// src/engine/acp/harness/pi/upstream/dist/acp/environment.js
|
|
77109
|
-
import { homedir as
|
|
78553
|
+
import { homedir as homedir3 } from "node:os";
|
|
77110
78554
|
function environmentHome(environment) {
|
|
77111
|
-
return environment["HOME"] ?? environment["USERPROFILE"] ??
|
|
78555
|
+
return environment["HOME"] ?? environment["USERPROFILE"] ?? homedir3();
|
|
77112
78556
|
}
|
|
77113
78557
|
|
|
77114
78558
|
// src/engine/acp/harness/pi/upstream/dist/acp/paths.js
|
|
77115
78559
|
function getPiAcpDir(environment = process.env) {
|
|
77116
|
-
return
|
|
78560
|
+
return join18(environmentHome(environment), ".pi", "pi-acp");
|
|
77117
78561
|
}
|
|
77118
78562
|
function getPiAcpSessionMapPath(environment = process.env) {
|
|
77119
|
-
return
|
|
78563
|
+
return join18(getPiAcpDir(environment), "session-map.json");
|
|
77120
78564
|
}
|
|
77121
78565
|
|
|
77122
78566
|
// src/engine/acp/harness/pi/upstream/dist/acp/pi-commands.js
|
|
@@ -77238,15 +78682,15 @@ async function readPiLatestEntryId(sessionFile) {
|
|
|
77238
78682
|
|
|
77239
78683
|
// src/engine/acp/harness/pi/upstream/dist/acp/pi-sessions.js
|
|
77240
78684
|
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";
|
|
77241
|
-
import { isAbsolute as isAbsolute11, join as
|
|
78685
|
+
import { isAbsolute as isAbsolute11, join as join19, resolve as resolve11 } from "node:path";
|
|
77242
78686
|
var DEFAULT_TAIL_BYTES = 256 * 1024;
|
|
77243
78687
|
var DEFAULT_HEAD_BYTES = 64 * 1024;
|
|
77244
78688
|
function getPiAgentDir(environment) {
|
|
77245
78689
|
const configured = environment["PI_CODING_AGENT_DIR"];
|
|
77246
|
-
return configured ? resolve11(configured) :
|
|
78690
|
+
return configured ? resolve11(configured) : join19(environmentHome(environment), ".pi", "agent");
|
|
77247
78691
|
}
|
|
77248
78692
|
function readSessionDirFromSettings(agentDir) {
|
|
77249
|
-
const settingsPath =
|
|
78693
|
+
const settingsPath = join19(agentDir, "settings.json");
|
|
77250
78694
|
try {
|
|
77251
78695
|
if (!existsSync5(settingsPath)) {
|
|
77252
78696
|
return null;
|
|
@@ -77267,7 +78711,7 @@ function readSessionDirFromSettings(agentDir) {
|
|
|
77267
78711
|
}
|
|
77268
78712
|
function getPiSessionsDir(environment = process.env) {
|
|
77269
78713
|
const agentDir = getPiAgentDir(environment);
|
|
77270
|
-
return readSessionDirFromSettings(agentDir) ??
|
|
78714
|
+
return readSessionDirFromSettings(agentDir) ?? join19(agentDir, "sessions");
|
|
77271
78715
|
}
|
|
77272
78716
|
function getPiSessionDiscoveryDirs(environment) {
|
|
77273
78717
|
const discoveryDirectories = [getPiSessionsDir(environment)];
|
|
@@ -77278,7 +78722,7 @@ function getPiSessionDiscoveryDirs(environment) {
|
|
|
77278
78722
|
if (!entry.isDirectory()) {
|
|
77279
78723
|
continue;
|
|
77280
78724
|
}
|
|
77281
|
-
const directory =
|
|
78725
|
+
const directory = join19(mobiusSessionsRoot, entry.name);
|
|
77282
78726
|
if (!discoveryDirectories.includes(directory)) {
|
|
77283
78727
|
discoveryDirectories.push(directory);
|
|
77284
78728
|
}
|
|
@@ -77295,7 +78739,7 @@ function walkJsonlFiles(dir, out2) {
|
|
|
77295
78739
|
}
|
|
77296
78740
|
for (const e of entries) {
|
|
77297
78741
|
const name2 = typeof e.name === "string" ? e.name : String(e.name);
|
|
77298
|
-
const p =
|
|
78742
|
+
const p = join19(dir, name2);
|
|
77299
78743
|
if (e.isDirectory()) {
|
|
77300
78744
|
walkJsonlFiles(p, out2);
|
|
77301
78745
|
} else if (e.isFile() && name2.endsWith(".jsonl")) {
|
|
@@ -77564,7 +79008,7 @@ function findPiSession(sessionId, environment = process.env) {
|
|
|
77564
79008
|
|
|
77565
79009
|
// src/engine/acp/harness/pi/upstream/dist/acp/pi-settings.js
|
|
77566
79010
|
import { existsSync as existsSync6, readFileSync as readFileSync5 } from "node:fs";
|
|
77567
|
-
import { join as
|
|
79011
|
+
import { join as join20, resolve as resolve12 } from "node:path";
|
|
77568
79012
|
function isObject2(x) {
|
|
77569
79013
|
return Boolean(x) && typeof x === "object" && !Array.isArray(x);
|
|
77570
79014
|
}
|
|
@@ -77593,7 +79037,7 @@ function readJsonFile2(path6) {
|
|
|
77593
79037
|
}
|
|
77594
79038
|
}
|
|
77595
79039
|
function getMergedSettings(cwd, environment) {
|
|
77596
|
-
const globalSettingsPath =
|
|
79040
|
+
const globalSettingsPath = join20(getAgentDir(environment), "settings.json");
|
|
77597
79041
|
const projectSettingsPath = resolve12(cwd, ".pi", "settings.json");
|
|
77598
79042
|
const global2 = readJsonFile2(globalSettingsPath);
|
|
77599
79043
|
const project = readJsonFile2(projectSettingsPath);
|
|
@@ -77601,7 +79045,7 @@ function getMergedSettings(cwd, environment) {
|
|
|
77601
79045
|
}
|
|
77602
79046
|
function getAgentDir(environment = process.env) {
|
|
77603
79047
|
const configured = environment["PI_CODING_AGENT_DIR"];
|
|
77604
|
-
return configured ? resolve12(configured) :
|
|
79048
|
+
return configured ? resolve12(configured) : join20(environmentHome(environment), ".pi", "agent");
|
|
77605
79049
|
}
|
|
77606
79050
|
function getEnableSkillCommands(cwd, environment = process.env) {
|
|
77607
79051
|
const merged = getMergedSettings(cwd, environment);
|
|
@@ -77855,7 +79299,7 @@ var SessionStore = class {
|
|
|
77855
79299
|
|
|
77856
79300
|
// src/engine/acp/harness/pi/upstream/dist/acp/slash-commands.js
|
|
77857
79301
|
import { existsSync as existsSync7, readdirSync as readdirSync5, readFileSync as readFileSync7 } from "node:fs";
|
|
77858
|
-
import { join as
|
|
79302
|
+
import { join as join21, resolve as resolve13 } from "node:path";
|
|
77859
79303
|
function parseFrontmatter(content) {
|
|
77860
79304
|
const frontmatter = {};
|
|
77861
79305
|
if (!content.startsWith("---")) {
|
|
@@ -77883,7 +79327,7 @@ function loadCommandsFromDir(dir, source, subdir = "") {
|
|
|
77883
79327
|
try {
|
|
77884
79328
|
const entries = readdirSync5(dir, { withFileTypes: true });
|
|
77885
79329
|
for (const entry of entries) {
|
|
77886
|
-
const fullPath =
|
|
79330
|
+
const fullPath = join21(dir, entry.name);
|
|
77887
79331
|
if (entry.isDirectory()) {
|
|
77888
79332
|
const newSubdir = subdir ? `${subdir}:${entry.name}` : entry.name;
|
|
77889
79333
|
commands.push(...loadCommandsFromDir(fullPath, source, newSubdir));
|
|
@@ -77923,7 +79367,7 @@ function loadCommandsFromDir(dir, source, subdir = "") {
|
|
|
77923
79367
|
}
|
|
77924
79368
|
function loadSlashCommands(cwd, environment = process.env) {
|
|
77925
79369
|
const commands = [];
|
|
77926
|
-
const userDir =
|
|
79370
|
+
const userDir = join21(environmentHome(environment), ".pi", "agent", "prompts");
|
|
77927
79371
|
const projectDir = resolve13(cwd, ".pi", "prompts");
|
|
77928
79372
|
commands.push(...loadCommandsFromDir(userDir, "user"));
|
|
77929
79373
|
commands.push(...loadCommandsFromDir(projectDir, "project"));
|
|
@@ -79592,7 +81036,7 @@ ${JSON.stringify(stats, null, 2)}`;
|
|
|
79592
81036
|
if (piPath) {
|
|
79593
81037
|
const resolved = realpathSync3(piPath);
|
|
79594
81038
|
const pkgRoot = dirname8(dirname8(resolved));
|
|
79595
|
-
const p =
|
|
81039
|
+
const p = join22(pkgRoot, "CHANGELOG.md");
|
|
79596
81040
|
if (existsSync8(p)) {
|
|
79597
81041
|
return p;
|
|
79598
81042
|
}
|
|
@@ -79603,7 +81047,7 @@ ${JSON.stringify(stats, null, 2)}`;
|
|
|
79603
81047
|
const npmRoot = spawnSync("npm", ["root", "-g"], { encoding: "utf-8" });
|
|
79604
81048
|
const root = String(npmRoot.stdout ?? "").trim();
|
|
79605
81049
|
if (root) {
|
|
79606
|
-
const p =
|
|
81050
|
+
const p = join22(root, "@earendil-works", "pi-coding-agent", "CHANGELOG.md");
|
|
79607
81051
|
if (existsSync8(p)) {
|
|
79608
81052
|
return p;
|
|
79609
81053
|
}
|
|
@@ -79697,7 +81141,7 @@ ${JSON.stringify(stats, null, 2)}`;
|
|
|
79697
81141
|
return { stopReason: "end_turn" };
|
|
79698
81142
|
}
|
|
79699
81143
|
const safeSessionId = session.sessionId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
79700
|
-
const outputPath =
|
|
81144
|
+
const outputPath = join22(session.cwd, `pi-session-${safeSessionId}.html`);
|
|
79701
81145
|
let resultPath = "";
|
|
79702
81146
|
try {
|
|
79703
81147
|
const result2 = await session.proc.exportHtml(outputPath);
|
|
@@ -80434,7 +81878,7 @@ function buildStartupInfo(opts) {
|
|
|
80434
81878
|
md.push("");
|
|
80435
81879
|
};
|
|
80436
81880
|
const contextItems = [];
|
|
80437
|
-
const contextPath =
|
|
81881
|
+
const contextPath = join22(opts.cwd, "AGENTS.md");
|
|
80438
81882
|
if (existsSync8(contextPath)) {
|
|
80439
81883
|
contextItems.push(contextPath);
|
|
80440
81884
|
}
|
|
@@ -80443,7 +81887,7 @@ function buildStartupInfo(opts) {
|
|
|
80443
81887
|
const pushSkillFromRoot = (root) => {
|
|
80444
81888
|
try {
|
|
80445
81889
|
for (const e of readdirSync6(root)) {
|
|
80446
|
-
const p =
|
|
81890
|
+
const p = join22(root, e);
|
|
80447
81891
|
try {
|
|
80448
81892
|
const st2 = statSync3(p);
|
|
80449
81893
|
if (st2.isFile() && e.toLowerCase().endsWith(".md")) {
|
|
@@ -80468,7 +81912,7 @@ function buildStartupInfo(opts) {
|
|
|
80468
81912
|
if (name2 === "node_modules" || name2 === ".git") {
|
|
80469
81913
|
continue;
|
|
80470
81914
|
}
|
|
80471
|
-
const p =
|
|
81915
|
+
const p = join22(dir, name2);
|
|
80472
81916
|
let st2;
|
|
80473
81917
|
try {
|
|
80474
81918
|
st2 = statSync3(p);
|
|
@@ -80485,16 +81929,16 @@ function buildStartupInfo(opts) {
|
|
|
80485
81929
|
} catch {
|
|
80486
81930
|
}
|
|
80487
81931
|
};
|
|
80488
|
-
const globalSkillsDir =
|
|
81932
|
+
const globalSkillsDir = join22(getAgentDir(opts.environment), "skills");
|
|
80489
81933
|
pushSkillFromRoot(globalSkillsDir);
|
|
80490
81934
|
const home = opts.environment["HOME"] ?? opts.environment["USERPROFILE"] ?? "";
|
|
80491
|
-
const legacyAgentsSkillsDir =
|
|
81935
|
+
const legacyAgentsSkillsDir = join22(home, ".agents", "skills");
|
|
80492
81936
|
pushSkillFromRoot(legacyAgentsSkillsDir);
|
|
80493
|
-
const projectSkillsDir =
|
|
81937
|
+
const projectSkillsDir = join22(opts.cwd, ".pi", "skills");
|
|
80494
81938
|
pushSkillFromRoot(projectSkillsDir);
|
|
80495
81939
|
addSection("Skills", skillsItems);
|
|
80496
81940
|
const promptsItems = [];
|
|
80497
|
-
const promptsDir =
|
|
81941
|
+
const promptsDir = join22(home, ".pi", "agent", "prompts");
|
|
80498
81942
|
try {
|
|
80499
81943
|
const prompts = readdirSync6(promptsDir).filter((f) => f.endsWith(".md"));
|
|
80500
81944
|
for (const f of prompts) {
|
|
@@ -80504,17 +81948,17 @@ function buildStartupInfo(opts) {
|
|
|
80504
81948
|
}
|
|
80505
81949
|
addSection("Prompts", promptsItems);
|
|
80506
81950
|
const extItems = [];
|
|
80507
|
-
const extDir =
|
|
81951
|
+
const extDir = join22(home, ".pi", "agent", "extensions");
|
|
80508
81952
|
try {
|
|
80509
81953
|
const exts = readdirSync6(extDir).filter((f) => f.endsWith(".ts") || f.endsWith(".js"));
|
|
80510
81954
|
for (const f of exts) {
|
|
80511
|
-
extItems.push(
|
|
81955
|
+
extItems.push(join22(extDir, f));
|
|
80512
81956
|
}
|
|
80513
81957
|
} catch {
|
|
80514
81958
|
}
|
|
80515
81959
|
const settingsPaths = [
|
|
80516
|
-
|
|
80517
|
-
|
|
81960
|
+
join22(getAgentDir(opts.environment), "settings.json"),
|
|
81961
|
+
join22(opts.cwd, ".pi", "settings.json")
|
|
80518
81962
|
];
|
|
80519
81963
|
for (const settingsPath of settingsPaths) {
|
|
80520
81964
|
try {
|
|
@@ -80705,7 +82149,7 @@ var PiAgentSpecification = class extends InProcessAcpAgentSpecification {
|
|
|
80705
82149
|
// keeps the adapter's opt-in capability flag enabled for every launch it owns.
|
|
80706
82150
|
createLaunchEnvironment = async (_agent, context) => {
|
|
80707
82151
|
const workspaceHash = createHash3("sha256").update(context.defaultWorkspace).digest("hex").slice(0, 24);
|
|
80708
|
-
const sessionDirectory =
|
|
82152
|
+
const sessionDirectory = join23(context.dataDirectory, "agents", "pi", "sessions", workspaceHash);
|
|
80709
82153
|
return Object.freeze({
|
|
80710
82154
|
PI_ACP_ENABLE_EMBEDDED_CONTEXT: "true",
|
|
80711
82155
|
MOBIUS_PI_SESSION_DIR: sessionDirectory
|
|
@@ -81536,7 +82980,7 @@ var SessionConfigProtocolError = class extends Error {
|
|
|
81536
82980
|
function isRecord8(value) {
|
|
81537
82981
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
81538
82982
|
}
|
|
81539
|
-
function
|
|
82983
|
+
function readString4(value, fallback = "") {
|
|
81540
82984
|
return typeof value === "string" ? value : fallback;
|
|
81541
82985
|
}
|
|
81542
82986
|
function truncate3(value, maximum) {
|
|
@@ -81551,10 +82995,10 @@ function normalizeConfigValue(option, groupId = "", groupName = "") {
|
|
|
81551
82995
|
return void 0;
|
|
81552
82996
|
}
|
|
81553
82997
|
return {
|
|
81554
|
-
description: truncate3(
|
|
82998
|
+
description: truncate3(readString4(option["description"]), 500),
|
|
81555
82999
|
groupId: truncate3(groupId, 128),
|
|
81556
83000
|
groupName: truncate3(groupName, 255),
|
|
81557
|
-
name: truncate3(
|
|
83001
|
+
name: truncate3(readString4(option["name"], value), 255),
|
|
81558
83002
|
value: truncate3(value, 500)
|
|
81559
83003
|
};
|
|
81560
83004
|
}
|
|
@@ -81569,8 +83013,8 @@ function normalizeConfigValues(value) {
|
|
|
81569
83013
|
}
|
|
81570
83014
|
const groupedOptions = entry["options"];
|
|
81571
83015
|
if (Array.isArray(groupedOptions)) {
|
|
81572
|
-
const groupId =
|
|
81573
|
-
const groupName =
|
|
83016
|
+
const groupId = readString4(entry["group"]);
|
|
83017
|
+
const groupName = readString4(entry["name"]);
|
|
81574
83018
|
for (const groupedOption of groupedOptions) {
|
|
81575
83019
|
if (isRecord8(groupedOption)) {
|
|
81576
83020
|
const normalizedValue = normalizeConfigValue(groupedOption, groupId, groupName);
|
|
@@ -81600,9 +83044,9 @@ function normalizeConfigOptions(value, modes) {
|
|
|
81600
83044
|
if (!isRecord8(option)) {
|
|
81601
83045
|
continue;
|
|
81602
83046
|
}
|
|
81603
|
-
const id = truncate3(
|
|
81604
|
-
const name2 = truncate3(
|
|
81605
|
-
const category = truncate3(
|
|
83047
|
+
const id = truncate3(readString4(option["id"]), 128);
|
|
83048
|
+
const name2 = truncate3(readString4(option["name"], id), 255);
|
|
83049
|
+
const category = truncate3(readString4(option["category"]), 128);
|
|
81606
83050
|
if (id.length === 0 || name2.length === 0 || category === "_mobius_permission") {
|
|
81607
83051
|
continue;
|
|
81608
83052
|
}
|
|
@@ -81611,7 +83055,7 @@ function normalizeConfigOptions(value, modes) {
|
|
|
81611
83055
|
booleanValue: readBoolean2(option["currentValue"]),
|
|
81612
83056
|
category,
|
|
81613
83057
|
currentValue: "",
|
|
81614
|
-
description: truncate3(
|
|
83058
|
+
description: truncate3(readString4(option["description"]), 500),
|
|
81615
83059
|
id,
|
|
81616
83060
|
name: name2,
|
|
81617
83061
|
type: "boolean",
|
|
@@ -81621,13 +83065,13 @@ function normalizeConfigOptions(value, modes) {
|
|
|
81621
83065
|
}
|
|
81622
83066
|
if (option["type"] === "select") {
|
|
81623
83067
|
const values = normalizeConfigValues(option["options"]);
|
|
81624
|
-
const currentValue = truncate3(
|
|
83068
|
+
const currentValue = truncate3(readString4(option["currentValue"]), 500);
|
|
81625
83069
|
if (values.some((entry) => entry.value === currentValue)) {
|
|
81626
83070
|
normalized.push({
|
|
81627
83071
|
booleanValue: false,
|
|
81628
83072
|
category,
|
|
81629
83073
|
currentValue,
|
|
81630
|
-
description: truncate3(
|
|
83074
|
+
description: truncate3(readString4(option["description"]), 500),
|
|
81631
83075
|
id,
|
|
81632
83076
|
name: name2,
|
|
81633
83077
|
type: "select",
|
|
@@ -81645,20 +83089,20 @@ function normalizeConfigOptions(value, modes) {
|
|
|
81645
83089
|
if (!isRecord8(mode)) {
|
|
81646
83090
|
continue;
|
|
81647
83091
|
}
|
|
81648
|
-
const id = truncate3(
|
|
83092
|
+
const id = truncate3(readString4(mode["id"]), 500);
|
|
81649
83093
|
if (id.length === 0) {
|
|
81650
83094
|
continue;
|
|
81651
83095
|
}
|
|
81652
83096
|
values.push({
|
|
81653
|
-
description: truncate3(
|
|
83097
|
+
description: truncate3(readString4(mode["description"]), 500),
|
|
81654
83098
|
groupId: "",
|
|
81655
83099
|
groupName: "",
|
|
81656
|
-
name: truncate3(
|
|
83100
|
+
name: truncate3(readString4(mode["name"], id), 255),
|
|
81657
83101
|
value: id
|
|
81658
83102
|
});
|
|
81659
83103
|
}
|
|
81660
83104
|
}
|
|
81661
|
-
const currentValue = truncate3(
|
|
83105
|
+
const currentValue = truncate3(readString4(modes["currentModeId"]), 500);
|
|
81662
83106
|
if (values.length > 1 && currentValue.length > 0 && values.some((entry) => entry.value === currentValue) && !normalized.some((entry) => entry.category === "mode") && !duplicatesThinkingOption(normalized, currentValue, values)) {
|
|
81663
83107
|
normalized.unshift({
|
|
81664
83108
|
booleanValue: false,
|
|
@@ -82284,6 +83728,7 @@ var targetSchema = external_exports.object({
|
|
|
82284
83728
|
});
|
|
82285
83729
|
var AcpExecutionConnections = class {
|
|
82286
83730
|
#sessions = /* @__PURE__ */ new Set();
|
|
83731
|
+
#closing = /* @__PURE__ */ new WeakSet();
|
|
82287
83732
|
#externalizer;
|
|
82288
83733
|
#normalizeEvent;
|
|
82289
83734
|
constructor(externalizer, normalizeEvent = (event) => event) {
|
|
@@ -82409,10 +83854,12 @@ var AcpExecutionConnections = class {
|
|
|
82409
83854
|
signal.throwIfAborted();
|
|
82410
83855
|
return;
|
|
82411
83856
|
}
|
|
83857
|
+
const alreadyClosing = this.#closing.has(session);
|
|
83858
|
+
this.#closing.add(session);
|
|
82412
83859
|
const { connection } = session;
|
|
82413
83860
|
try {
|
|
82414
83861
|
signal.throwIfAborted();
|
|
82415
|
-
if (connection.snapshot().capabilities.closeSession) {
|
|
83862
|
+
if (!alreadyClosing && connection.snapshot().capabilities.closeSession) {
|
|
82416
83863
|
try {
|
|
82417
83864
|
await connection.connection.agent.request(
|
|
82418
83865
|
methods.agent.session.close,
|
|
@@ -83033,7 +84480,17 @@ var AntigravityAdapter = class {
|
|
|
83033
84480
|
await connection.race(connection.events.drained(), "ACP agent exited while loading a session", signal);
|
|
83034
84481
|
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
83035
84482
|
});
|
|
83036
|
-
cancel = (
|
|
84483
|
+
cancel = async (params) => {
|
|
84484
|
+
const connection = this.#executionConnections.connection(params);
|
|
84485
|
+
if (connection !== void 0) {
|
|
84486
|
+
const disposition = await prepareAntigravitySessionCancel(connection.connection, params.nativeSessionId);
|
|
84487
|
+
if (disposition === "close") {
|
|
84488
|
+
await this.#executionConnections.closeSession(params);
|
|
84489
|
+
return "closed";
|
|
84490
|
+
}
|
|
84491
|
+
}
|
|
84492
|
+
return await this.#executionConnections.cancel(params);
|
|
84493
|
+
};
|
|
83037
84494
|
closeSession = (...args) => this.#executionConnections.closeSession(...args);
|
|
83038
84495
|
releaseSession = (params) => this.#executionConnections.releaseSession(params);
|
|
83039
84496
|
readNativeHistoryRevision = (params) => this.#executionConnections.readNativeHistoryRevision(params);
|
|
@@ -83754,11 +85211,11 @@ function describeEnvironmentProxyRoute(target) {
|
|
|
83754
85211
|
}
|
|
83755
85212
|
|
|
83756
85213
|
// src/engine/runtime/observability/diagnostic-log.ts
|
|
83757
|
-
import { join as
|
|
85214
|
+
import { join as join26 } from "node:path";
|
|
83758
85215
|
|
|
83759
85216
|
// src/engine/storage/logs/bounded-log.ts
|
|
83760
85217
|
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync10, renameSync as renameSync2, statSync as statSync5, writeFileSync as writeFileSync2 } from "node:fs";
|
|
83761
|
-
import { join as
|
|
85218
|
+
import { join as join24 } from "node:path";
|
|
83762
85219
|
var BoundedLineLog = class {
|
|
83763
85220
|
#path;
|
|
83764
85221
|
#maximumBytes;
|
|
@@ -83767,7 +85224,7 @@ var BoundedLineLog = class {
|
|
|
83767
85224
|
#onWriteFailure;
|
|
83768
85225
|
constructor(directory, filename, maximumBytes, onWriteFailure = () => void 0) {
|
|
83769
85226
|
this.#directory = directory;
|
|
83770
|
-
this.#path =
|
|
85227
|
+
this.#path = join24(directory, filename);
|
|
83771
85228
|
this.#maximumBytes = maximumBytes;
|
|
83772
85229
|
this.#onWriteFailure = onWriteFailure;
|
|
83773
85230
|
}
|
|
@@ -83818,21 +85275,21 @@ var BoundedLineLog = class {
|
|
|
83818
85275
|
|
|
83819
85276
|
// src/engine/storage/logs/log-files.ts
|
|
83820
85277
|
import { readFileSync as readFileSync11 } from "node:fs";
|
|
83821
|
-
import { join as
|
|
85278
|
+
import { join as join25 } from "node:path";
|
|
83822
85279
|
var DAEMON_LOG_FILENAME = "daemon.log";
|
|
83823
85280
|
var WORKER_LIFECYCLE_LOG_FILENAME = "worker-lifecycle.log";
|
|
83824
85281
|
function unhandledRejectionLogFilename(role) {
|
|
83825
85282
|
return `unhandled-rejections-${role}.log`;
|
|
83826
85283
|
}
|
|
83827
85284
|
function logDirectory(dataDirectory) {
|
|
83828
|
-
return
|
|
85285
|
+
return join25(dataDirectory, "logs");
|
|
83829
85286
|
}
|
|
83830
85287
|
function processLogPaths(dataDirectory) {
|
|
83831
85288
|
return [
|
|
83832
85289
|
WORKER_LIFECYCLE_LOG_FILENAME,
|
|
83833
85290
|
unhandledRejectionLogFilename("manager"),
|
|
83834
85291
|
unhandledRejectionLogFilename("worker")
|
|
83835
|
-
].map((filename) =>
|
|
85292
|
+
].map((filename) => join25(logDirectory(dataDirectory), filename));
|
|
83836
85293
|
}
|
|
83837
85294
|
function readLogText(path6) {
|
|
83838
85295
|
try {
|
|
@@ -83907,7 +85364,7 @@ var RuntimeDiagnosticLog = class {
|
|
|
83907
85364
|
this.#maximumBytes = maximumBytes;
|
|
83908
85365
|
const processLogsDirectory = options.processLogsDirectory;
|
|
83909
85366
|
this.#sources = [
|
|
83910
|
-
{ maximumBytes, path:
|
|
85367
|
+
{ maximumBytes, path: join26(directory, DAEMON_LOG_FILENAME) },
|
|
83911
85368
|
// The process logs a Runtime does not own, but must read to explain its own deaths.
|
|
83912
85369
|
...processLogsDirectory === void 0 ? [] : processLogPaths(processLogsDirectory).map((path6) => ({ maximumBytes: null, path: path6 }))
|
|
83913
85370
|
];
|
|
@@ -84138,20 +85595,6 @@ async function publishAgentCatalog(config2, signal) {
|
|
|
84138
85595
|
// src/engine/runtime/config.ts
|
|
84139
85596
|
import { resolve as resolve15 } from "node:path";
|
|
84140
85597
|
|
|
84141
|
-
// src/engine/util/serial-task-queue.ts
|
|
84142
|
-
var SerialTaskQueue = class {
|
|
84143
|
-
#tail = Promise.resolve();
|
|
84144
|
-
run = async (task, signal) => {
|
|
84145
|
-
signal.throwIfAborted();
|
|
84146
|
-
const result = this.#tail.then(() => {
|
|
84147
|
-
signal.throwIfAborted();
|
|
84148
|
-
return task(signal);
|
|
84149
|
-
});
|
|
84150
|
-
this.#tail = result.catch(() => void 0);
|
|
84151
|
-
return await result;
|
|
84152
|
-
};
|
|
84153
|
-
};
|
|
84154
|
-
|
|
84155
85598
|
// src/engine/agent/catalog.ts
|
|
84156
85599
|
var LocalAgentCatalogSnapshot = class {
|
|
84157
85600
|
agents;
|
|
@@ -85056,7 +86499,7 @@ function sql(strings, ...params) {
|
|
|
85056
86499
|
return new SQL([new StringChunk(str)]);
|
|
85057
86500
|
}
|
|
85058
86501
|
_sql.raw = raw;
|
|
85059
|
-
function
|
|
86502
|
+
function join33(chunks, separator) {
|
|
85060
86503
|
const result = [];
|
|
85061
86504
|
for (const [i, chunk] of chunks.entries()) {
|
|
85062
86505
|
if (i > 0 && separator !== void 0) result.push(separator);
|
|
@@ -85064,7 +86507,7 @@ function sql(strings, ...params) {
|
|
|
85064
86507
|
}
|
|
85065
86508
|
return new SQL(result);
|
|
85066
86509
|
}
|
|
85067
|
-
_sql.join =
|
|
86510
|
+
_sql.join = join33;
|
|
85068
86511
|
function identifier2(value) {
|
|
85069
86512
|
return new Name(value);
|
|
85070
86513
|
}
|
|
@@ -87209,7 +88652,7 @@ var SQLiteSelectBase = class extends TypedQueryBuilder {
|
|
|
87209
88652
|
const baseTableName = this.tableName;
|
|
87210
88653
|
const tableName = getTableLikeName(table);
|
|
87211
88654
|
for (const item of extractUsedTable(table)) this.usedTables.add(item);
|
|
87212
|
-
if (typeof tableName === "string" && this.config.joins?.some((
|
|
88655
|
+
if (typeof tableName === "string" && this.config.joins?.some((join33) => join33.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
87213
88656
|
if (!this.isPartialSelect) {
|
|
87214
88657
|
if (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === "string") this.config.fields = { [baseTableName]: this.config.fields };
|
|
87215
88658
|
if (typeof tableName === "string" && !is(table, SQL)) {
|
|
@@ -88048,7 +89491,7 @@ var SQLiteDialect = class {
|
|
|
88048
89491
|
if (!joins2) return;
|
|
88049
89492
|
const withEntries = Object.entries(joins2).filter(([_, v]) => v);
|
|
88050
89493
|
if (!withEntries.length) return;
|
|
88051
|
-
return sql.join(withEntries.map(([k2,
|
|
89494
|
+
return sql.join(withEntries.map(([k2, join33]) => {
|
|
88052
89495
|
const relation = tableConfig.relations[k2];
|
|
88053
89496
|
const isSingle2 = is(relation, One2);
|
|
88054
89497
|
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
|
@@ -88059,7 +89502,7 @@ var SQLiteDialect = class {
|
|
|
88059
89502
|
table: targetTable,
|
|
88060
89503
|
mode: isSingle2 ? "first" : "many",
|
|
88061
89504
|
schema,
|
|
88062
|
-
queryConfig:
|
|
89505
|
+
queryConfig: join33,
|
|
88063
89506
|
tableConfig: schema[relation.targetTableName],
|
|
88064
89507
|
relationWhere: filter,
|
|
88065
89508
|
isNested: true,
|
|
@@ -88073,7 +89516,7 @@ var SQLiteDialect = class {
|
|
|
88073
89516
|
key: k2,
|
|
88074
89517
|
selection: innerQuery.selection,
|
|
88075
89518
|
isArray: !isSingle2,
|
|
88076
|
-
isOptional: (relation.optional ?? false) ||
|
|
89519
|
+
isOptional: (relation.optional ?? false) || join33 !== true && !!join33.where
|
|
88077
89520
|
});
|
|
88078
89521
|
const jsonColumns = sql.join(innerQuery.selection.map((s) => {
|
|
88079
89522
|
return sql`${sql.raw(this.escapeString(s.key))}, ${s.selection ? sql`${jsonb}(${sql.identifier(s.key)})` : sql.identifier(s.key)}`;
|
|
@@ -88689,7 +90132,7 @@ var SQLiteUpdateBase = class {
|
|
|
88689
90132
|
createJoin(joinType) {
|
|
88690
90133
|
return ((table, on2) => {
|
|
88691
90134
|
const tableName = getTableLikeName(table);
|
|
88692
|
-
if (typeof tableName === "string" && this.config.joins.some((
|
|
90135
|
+
if (typeof tableName === "string" && this.config.joins.some((join33) => join33.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
88693
90136
|
if (typeof on2 === "function") {
|
|
88694
90137
|
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;
|
|
88695
90138
|
on2 = on2(new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
|
|
@@ -89643,7 +91086,7 @@ var SessionEventCacheTable = class {
|
|
|
89643
91086
|
// src/engine/storage/sqlite/local-databases.ts
|
|
89644
91087
|
import { createHash as createHash4 } from "node:crypto";
|
|
89645
91088
|
import { existsSync as existsSync9 } from "node:fs";
|
|
89646
|
-
import { join as
|
|
91089
|
+
import { join as join27 } from "node:path";
|
|
89647
91090
|
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
89648
91091
|
|
|
89649
91092
|
// src/engine/generated/acp-session-store-migrations.ts
|
|
@@ -89896,9 +91339,9 @@ var LocalSqliteDatabase = class {
|
|
|
89896
91339
|
function channelSessionDatabasePaths(stateDirectory, channelId) {
|
|
89897
91340
|
const channelHash = createHash4("sha256").update(channelId).digest("hex");
|
|
89898
91341
|
return {
|
|
89899
|
-
cancellations:
|
|
89900
|
-
events:
|
|
89901
|
-
sessions:
|
|
91342
|
+
cancellations: join27(stateDirectory, "sessions", `${channelHash}.cancellations.sqlite`),
|
|
91343
|
+
events: join27(stateDirectory, "sessions", `${channelHash}.events.sqlite`),
|
|
91344
|
+
sessions: join27(stateDirectory, "sessions", `${channelHash}.sqlite`)
|
|
89902
91345
|
};
|
|
89903
91346
|
}
|
|
89904
91347
|
function recordAppliedAdmissionOrder(path6) {
|
|
@@ -92477,8 +93920,26 @@ var AgentSession = class _AgentSession {
|
|
|
92477
93920
|
message: "The Agent process ended before the work it started on its own finished"
|
|
92478
93921
|
};
|
|
92479
93922
|
this.#backgroundActivity = "none";
|
|
92480
|
-
|
|
92481
|
-
|
|
93923
|
+
const agentTurn = this.#agentTurn;
|
|
93924
|
+
if (agentTurn?.cancelled === true) {
|
|
93925
|
+
if (agentTurn.held) {
|
|
93926
|
+
await this.#releaseHeld();
|
|
93927
|
+
} else {
|
|
93928
|
+
this.#agentTurn = null;
|
|
93929
|
+
await this.recordLifecycleEvent({
|
|
93930
|
+
payload: {
|
|
93931
|
+
commandId: agentTurn.commandId,
|
|
93932
|
+
kind: "prompt.completed",
|
|
93933
|
+
stopReason: "cancelled"
|
|
93934
|
+
},
|
|
93935
|
+
type: "lifecycle-metadata"
|
|
93936
|
+
});
|
|
93937
|
+
this.#getObserver().onAgentTurn?.(this.#mobiusSessionId, null);
|
|
93938
|
+
}
|
|
93939
|
+
} else {
|
|
93940
|
+
await this.#releaseHeld(agentTurn?.held === true ? failure2 : void 0);
|
|
93941
|
+
await this.#failAgentTurn(failure2.code, failure2.message);
|
|
93942
|
+
}
|
|
92482
93943
|
await this.#recordBackgroundTasks([]);
|
|
92483
93944
|
};
|
|
92484
93945
|
#failAgentTurn = async (code, message) => {
|
|
@@ -92557,19 +94018,23 @@ var AgentSession = class _AgentSession {
|
|
|
92557
94018
|
*/
|
|
92558
94019
|
cancelAgentTurn = async (commandId, signal) => {
|
|
92559
94020
|
const held = this.#held?.commandId === commandId ? this.#held : null;
|
|
92560
|
-
|
|
92561
|
-
|
|
94021
|
+
const agentTurn = this.#agentTurn?.commandId === commandId ? this.#agentTurn : null;
|
|
94022
|
+
if (held === null && agentTurn === null) {
|
|
94023
|
+
return "none";
|
|
92562
94024
|
}
|
|
92563
94025
|
if (held !== null) {
|
|
92564
94026
|
held.cancelled = true;
|
|
92565
94027
|
}
|
|
94028
|
+
if (agentTurn !== null) {
|
|
94029
|
+
this.#agentTurn = { ...agentTurn, cancelled: true };
|
|
94030
|
+
}
|
|
92566
94031
|
await this.#interactions.cancelPendingInteractions();
|
|
92567
94032
|
signal.throwIfAborted();
|
|
92568
|
-
await this.#adapter.cancel({ ...this.#target(), signal });
|
|
92569
|
-
if (held !== null && this.#agentTurn === null) {
|
|
94033
|
+
const outcome = await this.#adapter.cancel({ ...this.#target(), signal });
|
|
94034
|
+
if (outcome === "retained" && held !== null && this.#agentTurn === null) {
|
|
92570
94035
|
await this.#releaseHeld();
|
|
92571
94036
|
}
|
|
92572
|
-
return
|
|
94037
|
+
return outcome;
|
|
92573
94038
|
};
|
|
92574
94039
|
#recordAgentTurn = async (report) => {
|
|
92575
94040
|
switch (report.stage) {
|
|
@@ -92581,6 +94046,7 @@ var AgentSession = class _AgentSession {
|
|
|
92581
94046
|
if (held !== null) {
|
|
92582
94047
|
this.#agentTurn = {
|
|
92583
94048
|
attemptId: held.attemptId,
|
|
94049
|
+
cancelled: false,
|
|
92584
94050
|
commandId: held.commandId,
|
|
92585
94051
|
continues: void 0,
|
|
92586
94052
|
held: true
|
|
@@ -92593,6 +94059,7 @@ var AgentSession = class _AgentSession {
|
|
|
92593
94059
|
})[0] ?? this.#lastClientCommandId;
|
|
92594
94060
|
const agentTurn = {
|
|
92595
94061
|
attemptId: randomUUID15(),
|
|
94062
|
+
cancelled: false,
|
|
92596
94063
|
commandId: `agent-${randomUUID15()}`,
|
|
92597
94064
|
continues,
|
|
92598
94065
|
held: false
|
|
@@ -93366,7 +94833,22 @@ var SessionManager2 = class {
|
|
|
93366
94833
|
/** Cancels the named command's Agent execution; a command that is not executing has nothing to stop. */
|
|
93367
94834
|
cancelPrompt = async (sessionId, commandId, signal = AbortSignal.timeout(3e4)) => this.#operations.run({ signal }, async ({ signal: signal2 }) => {
|
|
93368
94835
|
if (this.#agentTurns.get(sessionId) === commandId) {
|
|
93369
|
-
|
|
94836
|
+
const runtime = this.#executionProcesses.get(sessionId);
|
|
94837
|
+
if (runtime !== void 0) {
|
|
94838
|
+
const outcome = await runtime.cancelAgentTurn(commandId, signal2);
|
|
94839
|
+
switch (outcome) {
|
|
94840
|
+
case "none":
|
|
94841
|
+
case "retained":
|
|
94842
|
+
break;
|
|
94843
|
+
case "closed":
|
|
94844
|
+
await this.#stopSessionProcess(sessionId, runtime);
|
|
94845
|
+
break;
|
|
94846
|
+
default: {
|
|
94847
|
+
const unreachable2 = outcome;
|
|
94848
|
+
throw new AcpExecutionError("Unexpected cancellation outcome", { cause: unreachable2 });
|
|
94849
|
+
}
|
|
94850
|
+
}
|
|
94851
|
+
}
|
|
93370
94852
|
return;
|
|
93371
94853
|
}
|
|
93372
94854
|
await this.#executions.cancel(sessionId, commandId, async () => {
|
|
@@ -94871,8 +96353,8 @@ var SessionTurns = class {
|
|
|
94871
96353
|
};
|
|
94872
96354
|
|
|
94873
96355
|
// src/engine/session/workspace/workspace-directory.ts
|
|
94874
|
-
import { homedir as
|
|
94875
|
-
import { basename as basename8, dirname as dirname10, isAbsolute as isAbsolute16, join as
|
|
96356
|
+
import { homedir as homedir4 } from "node:os";
|
|
96357
|
+
import { basename as basename8, dirname as dirname10, isAbsolute as isAbsolute16, join as join28, normalize as normalize2, relative as relative3 } from "node:path";
|
|
94876
96358
|
|
|
94877
96359
|
// src/engine/session/workspace/local-authorization-error.ts
|
|
94878
96360
|
var LocalAuthorizationError = class extends OperationError {
|
|
@@ -94903,7 +96385,7 @@ function encodePath(path6) {
|
|
|
94903
96385
|
return `path-${encoded}`;
|
|
94904
96386
|
}
|
|
94905
96387
|
function expandCurrentUserHome(path6) {
|
|
94906
|
-
return path6.replace(/^~(?=$|\/|\\)/,
|
|
96388
|
+
return path6.replace(/^~(?=$|\/|\\)/, homedir4());
|
|
94907
96389
|
}
|
|
94908
96390
|
function decodePath(value, prefix) {
|
|
94909
96391
|
const encoded = value.slice(prefix.length);
|
|
@@ -94934,7 +96416,7 @@ var WorkspaceDirectoryService = class {
|
|
|
94934
96416
|
return this.#defaultWorkspace;
|
|
94935
96417
|
}
|
|
94936
96418
|
if (id === "home") {
|
|
94937
|
-
return
|
|
96419
|
+
return homedir4();
|
|
94938
96420
|
}
|
|
94939
96421
|
if (id.startsWith("path-")) {
|
|
94940
96422
|
const path6 = expandCurrentUserHome(decodePath(id, "path-"));
|
|
@@ -94969,7 +96451,7 @@ var WorkspaceDirectoryService = class {
|
|
|
94969
96451
|
}
|
|
94970
96452
|
};
|
|
94971
96453
|
label = (path6) => {
|
|
94972
|
-
const suffix = relative3(
|
|
96454
|
+
const suffix = relative3(homedir4(), path6);
|
|
94973
96455
|
return suffix === "" ? "~" : !isAbsolute16(suffix) && suffix !== ".." && !suffix.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) ? `~/${suffix.replaceAll("\\", "/")}` : path6;
|
|
94974
96456
|
};
|
|
94975
96457
|
identify = async (bindingId, requestedPath2, signal) => {
|
|
@@ -95018,7 +96500,7 @@ var WorkspaceDirectoryService = class {
|
|
|
95018
96500
|
continue;
|
|
95019
96501
|
}
|
|
95020
96502
|
try {
|
|
95021
|
-
const path6 = await this.resolvePath(
|
|
96503
|
+
const path6 = await this.resolvePath(join28(target, child.name), signal);
|
|
95022
96504
|
entries.push({ directoryId: encodePath(path6), name: child.name });
|
|
95023
96505
|
} catch (cause) {
|
|
95024
96506
|
signal.throwIfAborted();
|
|
@@ -95203,13 +96685,13 @@ function buildSessionLayer(options) {
|
|
|
95203
96685
|
|
|
95204
96686
|
// src/engine/session/content/external-content-store.ts
|
|
95205
96687
|
import { createHash as createHash8 } from "node:crypto";
|
|
95206
|
-
import { extname as extname2, join as
|
|
96688
|
+
import { extname as extname2, join as join30 } from "node:path";
|
|
95207
96689
|
import { pathToFileURL as pathToFileURL3 } from "node:url";
|
|
95208
96690
|
|
|
95209
96691
|
// src/engine/storage/files/scratch-directory.ts
|
|
95210
96692
|
import { randomUUID as randomUUID18 } from "node:crypto";
|
|
95211
96693
|
import { lstat as lstat4, mkdir as mkdir5, readdir as readdir6, readFile as readFile7, realpath as realpath7, rename as rename4, rm as rm5, stat as stat6, utimes, writeFile as writeFile2 } from "node:fs/promises";
|
|
95212
|
-
import { dirname as dirname11, join as
|
|
96694
|
+
import { dirname as dirname11, join as join29 } from "node:path";
|
|
95213
96695
|
async function atomicWrite(path6, bytes, signal) {
|
|
95214
96696
|
const temporary = `${path6}.${randomUUID18()}.tmp`;
|
|
95215
96697
|
try {
|
|
@@ -95223,7 +96705,7 @@ async function atomicWrite(path6, bytes, signal) {
|
|
|
95223
96705
|
var ScratchDirectory = class {
|
|
95224
96706
|
#root;
|
|
95225
96707
|
constructor(parent) {
|
|
95226
|
-
this.#root =
|
|
96708
|
+
this.#root = join29(parent, randomUUID18());
|
|
95227
96709
|
}
|
|
95228
96710
|
/** Refreshes this directory's lease and removes sibling directories whose lease is older than `leaseMilliseconds`. */
|
|
95229
96711
|
refreshLease = async (leaseMilliseconds) => {
|
|
@@ -95234,7 +96716,7 @@ var ScratchDirectory = class {
|
|
|
95234
96716
|
if (!directory.isDirectory() || !/^[a-f0-9-]{36}$/u.test(directory.name)) {
|
|
95235
96717
|
continue;
|
|
95236
96718
|
}
|
|
95237
|
-
const path6 =
|
|
96719
|
+
const path6 = join29(dirname11(this.#root), directory.name);
|
|
95238
96720
|
if (path6 === this.#root) {
|
|
95239
96721
|
continue;
|
|
95240
96722
|
}
|
|
@@ -95249,10 +96731,10 @@ var ScratchDirectory = class {
|
|
|
95249
96731
|
};
|
|
95250
96732
|
/** Writes `bytes` atomically to `<group>/<name>` with owner-only permissions and returns the path. */
|
|
95251
96733
|
write = async (group, name2, bytes, signal) => {
|
|
95252
|
-
const directory =
|
|
96734
|
+
const directory = join29(this.#root, group);
|
|
95253
96735
|
await mkdir5(directory, { mode: 448, recursive: true });
|
|
95254
96736
|
signal.throwIfAborted();
|
|
95255
|
-
const path6 =
|
|
96737
|
+
const path6 = join29(directory, name2);
|
|
95256
96738
|
await atomicWrite(path6, bytes, signal);
|
|
95257
96739
|
return path6;
|
|
95258
96740
|
};
|
|
@@ -95303,7 +96785,7 @@ var LocalExternalContentStore = class {
|
|
|
95303
96785
|
#expirationTimer;
|
|
95304
96786
|
#cleanup = Promise.resolve();
|
|
95305
96787
|
constructor(stateDirectory) {
|
|
95306
|
-
this.#scratch = new ScratchDirectory(
|
|
96788
|
+
this.#scratch = new ScratchDirectory(join30(stateDirectory, "tmp", "session-content"));
|
|
95307
96789
|
this.#expirationTimer = setInterval(() => {
|
|
95308
96790
|
void this.#expire().catch(() => void 0);
|
|
95309
96791
|
}, 6e4);
|
|
@@ -95711,7 +97193,7 @@ var AgentProcessPool = class {
|
|
|
95711
97193
|
|
|
95712
97194
|
// src/engine/session/settings/agent-settings-cache.ts
|
|
95713
97195
|
import { createHash as createHash9, randomUUID as randomUUID19 } from "node:crypto";
|
|
95714
|
-
import { join as
|
|
97196
|
+
import { join as join31 } from "node:path";
|
|
95715
97197
|
var CACHE_FILE_LIMIT = 32 * 1024 * 1024;
|
|
95716
97198
|
var CACHE_FORMAT = 1;
|
|
95717
97199
|
var generationSchema = external_exports.union([external_exports.literal("initial"), external_exports.uuid()]);
|
|
@@ -95776,8 +97258,8 @@ var AgentSettingsCache = class {
|
|
|
95776
97258
|
#generationPath;
|
|
95777
97259
|
#generation = 0;
|
|
95778
97260
|
constructor(stateDirectory) {
|
|
95779
|
-
this.#directory =
|
|
95780
|
-
this.#generationPath =
|
|
97261
|
+
this.#directory = join31(stateDirectory, "agent-settings");
|
|
97262
|
+
this.#generationPath = join31(this.#directory, "generation");
|
|
95781
97263
|
}
|
|
95782
97264
|
get generation() {
|
|
95783
97265
|
return this.#generation;
|
|
@@ -95788,7 +97270,7 @@ var AgentSettingsCache = class {
|
|
|
95788
97270
|
};
|
|
95789
97271
|
open = async (agent2, signal) => {
|
|
95790
97272
|
const inspections = /* @__PURE__ */ new Map();
|
|
95791
|
-
const path6 =
|
|
97273
|
+
const path6 = join31(this.#directory, `${hash2(agent2.id)}.json`);
|
|
95792
97274
|
const fingerprint = hash2([
|
|
95793
97275
|
agent2.agentVersion,
|
|
95794
97276
|
agent2.adapterVersion,
|
|
@@ -96813,7 +98295,7 @@ function createContentWriteCommands(context) {
|
|
|
96813
98295
|
import { WebSocket as WebSocket5 } from "undici";
|
|
96814
98296
|
|
|
96815
98297
|
// src/engine/session/content/session-files.ts
|
|
96816
|
-
import { basename as basename9, extname as extname3, isAbsolute as isAbsolute17, join as
|
|
98298
|
+
import { basename as basename9, extname as extname3, isAbsolute as isAbsolute17, join as join32, normalize as normalize3, resolve as resolve17 } from "node:path";
|
|
96817
98299
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
96818
98300
|
function requestedPath(value) {
|
|
96819
98301
|
if (value.includes("\0")) {
|
|
@@ -96837,7 +98319,7 @@ async function resolveFile(value, workingDirectory, signal) {
|
|
|
96837
98319
|
if (isAbsolute17(requested.path) && normalize3(requested.path) !== requested.path) {
|
|
96838
98320
|
return null;
|
|
96839
98321
|
}
|
|
96840
|
-
const candidates = requested.explicitUrl || workingDirectory === null ? [requested.path] : isAbsolute17(requested.path) ? [
|
|
98322
|
+
const candidates = requested.explicitUrl || workingDirectory === null ? [requested.path] : isAbsolute17(requested.path) ? [join32(workingDirectory, requested.path), requested.path] : [resolve17(workingDirectory, requested.path)];
|
|
96841
98323
|
for (const candidate of candidates) {
|
|
96842
98324
|
if (!isAbsolute17(candidate) || normalize3(candidate) !== candidate) {
|
|
96843
98325
|
continue;
|
|
@@ -99414,4 +100896,4 @@ export {
|
|
|
99414
100896
|
* MIT Licensed
|
|
99415
100897
|
*)
|
|
99416
100898
|
*/
|
|
99417
|
-
//# sourceMappingURL=chunk-
|
|
100899
|
+
//# sourceMappingURL=chunk-7VYQEJW7.js.map
|