@moxt-ai/mobius 0.0.359 → 0.0.360
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/cli.js +935 -490
- package/dist/cli.js.map +4 -4
- package/dist/engine/acp/adapter/agent-initialization.d.ts +2 -2
- package/dist/engine/acp/adapter/agent-initialization.d.ts.map +1 -1
- package/dist/engine/acp/adapter/agent-initialization.js.map +1 -1
- package/dist/engine/acp/adapter/claude/adapter.d.ts +21 -4
- package/dist/engine/acp/adapter/claude/adapter.d.ts.map +1 -1
- package/dist/engine/acp/adapter/claude/adapter.js +52 -15
- package/dist/engine/acp/adapter/claude/adapter.js.map +1 -1
- package/dist/engine/acp/adapter/codex/adapter.d.ts +22 -5
- package/dist/engine/acp/adapter/codex/adapter.d.ts.map +1 -1
- package/dist/engine/acp/adapter/codex/adapter.js +70 -20
- package/dist/engine/acp/adapter/codex/adapter.js.map +1 -1
- package/dist/engine/acp/adapter/configuration-changes.d.ts +25 -0
- package/dist/engine/acp/adapter/configuration-changes.d.ts.map +1 -0
- package/dist/engine/acp/adapter/configuration-changes.js +47 -0
- package/dist/engine/acp/adapter/configuration-changes.js.map +1 -0
- package/dist/engine/acp/adapter/execution-connections.d.ts +26 -0
- package/dist/engine/acp/adapter/execution-connections.d.ts.map +1 -0
- package/dist/engine/acp/adapter/{live-sessions.js → execution-connections.js} +92 -24
- package/dist/engine/acp/adapter/execution-connections.js.map +1 -0
- package/dist/engine/acp/adapter/lifecycle-output.d.ts +10 -0
- package/dist/engine/acp/adapter/lifecycle-output.d.ts.map +1 -0
- package/dist/engine/acp/adapter/lifecycle-output.js +26 -0
- package/dist/engine/acp/adapter/lifecycle-output.js.map +1 -0
- package/dist/engine/acp/adapter/native-session-lookup.d.ts +2 -2
- package/dist/engine/acp/adapter/native-session-lookup.d.ts.map +1 -1
- package/dist/engine/acp/adapter/native-session-lookup.js +4 -4
- package/dist/engine/acp/adapter/native-session-lookup.js.map +1 -1
- package/dist/engine/acp/adapter/pi/adapter.d.ts +21 -4
- package/dist/engine/acp/adapter/pi/adapter.d.ts.map +1 -1
- package/dist/engine/acp/adapter/pi/adapter.js +52 -15
- package/dist/engine/acp/adapter/pi/adapter.js.map +1 -1
- package/dist/engine/acp/adapter/query-processes.d.ts +6 -5
- package/dist/engine/acp/adapter/query-processes.d.ts.map +1 -1
- package/dist/engine/acp/adapter/query-processes.js +36 -36
- package/dist/engine/acp/adapter/query-processes.js.map +1 -1
- package/dist/engine/acp/adapter/query-scope.d.ts +8 -0
- package/dist/engine/acp/adapter/query-scope.d.ts.map +1 -0
- package/dist/engine/acp/adapter/query-scope.js +16 -0
- package/dist/engine/acp/adapter/query-scope.js.map +1 -0
- package/dist/engine/acp/adapter/query-session.d.ts +3 -4
- package/dist/engine/acp/adapter/query-session.d.ts.map +1 -1
- package/dist/engine/acp/adapter/query-session.js +26 -31
- package/dist/engine/acp/adapter/query-session.js.map +1 -1
- package/dist/engine/acp/adapter/session-events.d.ts +34 -6
- package/dist/engine/acp/adapter/session-events.d.ts.map +1 -1
- package/dist/engine/acp/adapter/session-events.js +95 -3
- package/dist/engine/acp/adapter/session-events.js.map +1 -1
- package/dist/engine/acp/content/content-externalizer.d.ts +1 -0
- package/dist/engine/acp/content/content-externalizer.d.ts.map +1 -1
- package/dist/engine/acp/content/content-externalizer.js.map +1 -1
- package/dist/engine/acp/native-history/preview-contract.d.ts +73 -16
- package/dist/engine/acp/native-history/preview-contract.d.ts.map +1 -1
- package/dist/engine/acp/protocol/session-config-protocol.d.ts +1 -0
- package/dist/engine/acp/protocol/session-config-protocol.d.ts.map +1 -1
- package/dist/engine/acp/protocol/session-config-protocol.js +1 -1
- package/dist/engine/acp/protocol/session-config-protocol.js.map +1 -1
- package/dist/engine/agent/runtime-agents.d.ts +4 -1
- package/dist/engine/agent/runtime-agents.d.ts.map +1 -1
- package/dist/engine/agent/runtime-agents.js +6 -4
- package/dist/engine/agent/runtime-agents.js.map +1 -1
- package/dist/engine/runtime/run.d.ts.map +1 -1
- package/dist/engine/runtime/run.js +6 -2
- package/dist/engine/runtime/run.js.map +1 -1
- package/dist/engine/session/api/session-api.d.ts +3 -0
- package/dist/engine/session/api/session-api.d.ts.map +1 -1
- package/dist/engine/session/api/session-api.js.map +1 -1
- package/dist/engine/session/live/agent-session-restore.d.ts +6 -16
- package/dist/engine/session/live/agent-session-restore.d.ts.map +1 -1
- package/dist/engine/session/live/agent-session.d.ts +7 -14
- package/dist/engine/session/live/agent-session.d.ts.map +1 -1
- package/dist/engine/session/live/agent-session.js +108 -87
- package/dist/engine/session/live/agent-session.js.map +1 -1
- package/dist/engine/session/live/session-restore.d.ts.map +1 -1
- package/dist/engine/session/live/session-restore.js +12 -35
- package/dist/engine/session/live/session-restore.js.map +1 -1
- package/dist/engine/session/manager/session-manager.d.ts.map +1 -1
- package/dist/engine/session/manager/session-manager.js +13 -5
- package/dist/engine/session/manager/session-manager.js.map +1 -1
- package/dist/engine/session/native/native-query.d.ts +5 -0
- package/dist/engine/session/native/native-query.d.ts.map +1 -0
- package/dist/engine/session/native/native-query.js +14 -0
- package/dist/engine/session/native/native-query.js.map +1 -0
- package/dist/engine/session/native/native-session-browser.d.ts.map +1 -1
- package/dist/engine/session/native/native-session-browser.js +27 -16
- package/dist/engine/session/native/native-session-browser.js.map +1 -1
- package/dist/engine/session/process/retained-agent-processes.d.ts +10 -10
- package/dist/engine/session/process/retained-agent-processes.d.ts.map +1 -1
- package/dist/engine/session/process/retained-agent-processes.js.map +1 -1
- package/dist/engine/session/prompt/execute-prompt.d.ts.map +1 -1
- package/dist/engine/session/prompt/execute-prompt.js +4 -1
- package/dist/engine/session/prompt/execute-prompt.js.map +1 -1
- package/dist/engine/util/branded-type.d.ts +4 -0
- package/dist/engine/util/branded-type.d.ts.map +1 -0
- package/dist/engine/util/branded-type.js +2 -0
- package/dist/engine/util/branded-type.js.map +1 -0
- package/dist/engine.js +874 -471
- package/dist/engine.js.map +4 -4
- package/package.json +1 -1
- package/dist/engine/acp/adapter/live-sessions.d.ts +0 -26
- package/dist/engine/acp/adapter/live-sessions.d.ts.map +0 -1
- package/dist/engine/acp/adapter/live-sessions.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -2086,7 +2086,7 @@ var init_package = __esm({
|
|
|
2086
2086
|
"package.json"() {
|
|
2087
2087
|
package_default = {
|
|
2088
2088
|
name: "@moxt-ai/mobius",
|
|
2089
|
-
version: "0.0.
|
|
2089
|
+
version: "0.0.360",
|
|
2090
2090
|
description: "Mobius CLI for pairing and running local AI agent services.",
|
|
2091
2091
|
type: "module",
|
|
2092
2092
|
bin: {
|
|
@@ -82887,6 +82887,29 @@ var init_run_cleanup = __esm({
|
|
|
82887
82887
|
}
|
|
82888
82888
|
});
|
|
82889
82889
|
|
|
82890
|
+
// src/engine/acp/protocol/native-session.ts
|
|
82891
|
+
var path7, title, nativeSessionIdSchema, nativeSessionInfoSchema, nativeSessionPageSchema;
|
|
82892
|
+
var init_native_session = __esm({
|
|
82893
|
+
"src/engine/acp/protocol/native-session.ts"() {
|
|
82894
|
+
"use strict";
|
|
82895
|
+
init_zod();
|
|
82896
|
+
path7 = external_exports.string().min(1).max(2048).refine((value) => !value.includes("\0"));
|
|
82897
|
+
title = external_exports.string().transform((value) => value.slice(0, 500));
|
|
82898
|
+
nativeSessionIdSchema = external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,255}$/);
|
|
82899
|
+
nativeSessionInfoSchema = external_exports.object({
|
|
82900
|
+
sessionId: nativeSessionIdSchema,
|
|
82901
|
+
cwd: path7,
|
|
82902
|
+
additionalDirectories: external_exports.array(path7).max(16).default([]).readonly(),
|
|
82903
|
+
title: title.nullish(),
|
|
82904
|
+
updatedAt: external_exports.iso.datetime({ offset: true }).nullish()
|
|
82905
|
+
}).readonly();
|
|
82906
|
+
nativeSessionPageSchema = external_exports.object({
|
|
82907
|
+
sessions: external_exports.array(nativeSessionInfoSchema).max(500).readonly(),
|
|
82908
|
+
nextCursor: external_exports.string().min(1).max(4096).nullish()
|
|
82909
|
+
}).readonly();
|
|
82910
|
+
}
|
|
82911
|
+
});
|
|
82912
|
+
|
|
82890
82913
|
// src/engine/acp/client/prompt-content.ts
|
|
82891
82914
|
function validatePromptContent(options, capabilities) {
|
|
82892
82915
|
if (options.images.length > 0 && !capabilities.imagePrompt) {
|
|
@@ -82949,29 +82972,6 @@ var init_prompt_content = __esm({
|
|
|
82949
82972
|
}
|
|
82950
82973
|
});
|
|
82951
82974
|
|
|
82952
|
-
// src/engine/acp/protocol/native-session.ts
|
|
82953
|
-
var path7, title, nativeSessionIdSchema, nativeSessionInfoSchema, nativeSessionPageSchema;
|
|
82954
|
-
var init_native_session = __esm({
|
|
82955
|
-
"src/engine/acp/protocol/native-session.ts"() {
|
|
82956
|
-
"use strict";
|
|
82957
|
-
init_zod();
|
|
82958
|
-
path7 = external_exports.string().min(1).max(2048).refine((value) => !value.includes("\0"));
|
|
82959
|
-
title = external_exports.string().transform((value) => value.slice(0, 500));
|
|
82960
|
-
nativeSessionIdSchema = external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,255}$/);
|
|
82961
|
-
nativeSessionInfoSchema = external_exports.object({
|
|
82962
|
-
sessionId: nativeSessionIdSchema,
|
|
82963
|
-
cwd: path7,
|
|
82964
|
-
additionalDirectories: external_exports.array(path7).max(16).default([]).readonly(),
|
|
82965
|
-
title: title.nullish(),
|
|
82966
|
-
updatedAt: external_exports.iso.datetime({ offset: true }).nullish()
|
|
82967
|
-
}).readonly();
|
|
82968
|
-
nativeSessionPageSchema = external_exports.object({
|
|
82969
|
-
sessions: external_exports.array(nativeSessionInfoSchema).max(500).readonly(),
|
|
82970
|
-
nextCursor: external_exports.string().min(1).max(4096).nullish()
|
|
82971
|
-
}).readonly();
|
|
82972
|
-
}
|
|
82973
|
-
});
|
|
82974
|
-
|
|
82975
82975
|
// src/engine/acp/protocol/session-config-protocol.ts
|
|
82976
82976
|
import { methods as methods9 } from "@agentclientprotocol/sdk";
|
|
82977
82977
|
function isRecord6(value) {
|
|
@@ -83295,6 +83295,117 @@ var init_agent_update_stream = __esm({
|
|
|
83295
83295
|
}
|
|
83296
83296
|
});
|
|
83297
83297
|
|
|
83298
|
+
// src/engine/acp/adapter/agent-initialization.ts
|
|
83299
|
+
import { methods as methods10, PROTOCOL_VERSION as PROTOCOL_VERSION3 } from "@agentclientprotocol/sdk";
|
|
83300
|
+
async function validateAgentRuntime(agent, signal) {
|
|
83301
|
+
signal.throwIfAborted();
|
|
83302
|
+
const unchanged = await Promise.all(agent.runtimeExecutables.map((identity2) => revalidateExecutable(identity2)));
|
|
83303
|
+
signal.throwIfAborted();
|
|
83304
|
+
if (unchanged.some((result) => !result)) {
|
|
83305
|
+
throw new AcpExecutionError(
|
|
83306
|
+
"The local Agent runtime changed; restart Mobius before starting a new conversation",
|
|
83307
|
+
{},
|
|
83308
|
+
"agent_runtime_changed"
|
|
83309
|
+
);
|
|
83310
|
+
}
|
|
83311
|
+
}
|
|
83312
|
+
async function initializeAgentConnection(connection, agentId, verifiedVersion, signal) {
|
|
83313
|
+
await connection.race(connection.initialize(signal), "The Agent runtime exited during initialization", signal).catch((cause) => {
|
|
83314
|
+
signal.throwIfAborted();
|
|
83315
|
+
throw new RetryableAcpInitializationError(cause);
|
|
83316
|
+
});
|
|
83317
|
+
const initialized = await connection.race(
|
|
83318
|
+
connection.connection.agent.request(
|
|
83319
|
+
methods10.agent.initialize,
|
|
83320
|
+
{
|
|
83321
|
+
clientCapabilities: {
|
|
83322
|
+
elicitation: { form: {}, url: {} },
|
|
83323
|
+
plan: {},
|
|
83324
|
+
session: { compaction: {}, configOptions: { boolean: {} } }
|
|
83325
|
+
},
|
|
83326
|
+
clientInfo: { name: "mobius", version: "0.0.3" },
|
|
83327
|
+
protocolVersion: PROTOCOL_VERSION3
|
|
83328
|
+
},
|
|
83329
|
+
{ cancellationSignal: signal }
|
|
83330
|
+
),
|
|
83331
|
+
"ACP agent exited during initialization",
|
|
83332
|
+
signal
|
|
83333
|
+
).catch((cause) => {
|
|
83334
|
+
signal.throwIfAborted();
|
|
83335
|
+
throw new RetryableAcpInitializationError(cause);
|
|
83336
|
+
});
|
|
83337
|
+
if (initialized.protocolVersion !== PROTOCOL_VERSION3) {
|
|
83338
|
+
throw new AcpExecutionError(
|
|
83339
|
+
"ACP agent selected an unsupported protocol version",
|
|
83340
|
+
{},
|
|
83341
|
+
"unsupported_acp_protocol"
|
|
83342
|
+
);
|
|
83343
|
+
}
|
|
83344
|
+
return {
|
|
83345
|
+
capabilities: normalizeAcpCapabilities(initialized),
|
|
83346
|
+
agentName: truncate(initialized.agentInfo?.title ?? initialized.agentInfo?.name ?? agentId, 255),
|
|
83347
|
+
agentVersion: truncate(
|
|
83348
|
+
verifiedVersion.length > 0 ? verifiedVersion : initialized.agentInfo?.version ?? "",
|
|
83349
|
+
128
|
|
83350
|
+
)
|
|
83351
|
+
};
|
|
83352
|
+
}
|
|
83353
|
+
var RetryableAcpInitializationError;
|
|
83354
|
+
var init_agent_initialization = __esm({
|
|
83355
|
+
"src/engine/acp/adapter/agent-initialization.ts"() {
|
|
83356
|
+
"use strict";
|
|
83357
|
+
init_executable();
|
|
83358
|
+
init_value_utils();
|
|
83359
|
+
init_acp_error();
|
|
83360
|
+
init_session_capabilities();
|
|
83361
|
+
RetryableAcpInitializationError = class extends AcpExecutionError {
|
|
83362
|
+
constructor(cause) {
|
|
83363
|
+
super("ACP agent initialization failed", { cause });
|
|
83364
|
+
this.name = "RetryableAcpInitializationError";
|
|
83365
|
+
}
|
|
83366
|
+
};
|
|
83367
|
+
}
|
|
83368
|
+
});
|
|
83369
|
+
|
|
83370
|
+
// src/engine/acp/adapter/configuration-changes.ts
|
|
83371
|
+
function recordConfigurationOptions(changes, options) {
|
|
83372
|
+
const modes = options.filter((option) => option.category === "mode");
|
|
83373
|
+
const selection = modes.length > 0 ? { kind: "unchanged" } : changes.kind === "mode" ? { kind: "selected", modeId: changes.modeId } : changes.kind === "replacement" ? changes.selection : { kind: "unchanged" };
|
|
83374
|
+
return {
|
|
83375
|
+
kind: "replacement",
|
|
83376
|
+
options,
|
|
83377
|
+
modes: modes.length > 0 ? modes : changes.kind === "replacement" ? changes.modes : [],
|
|
83378
|
+
selection
|
|
83379
|
+
};
|
|
83380
|
+
}
|
|
83381
|
+
function recordConfigurationMode(changes, modeId) {
|
|
83382
|
+
return changes.kind === "replacement" ? { ...changes, selection: { kind: "selected", modeId } } : { kind: "mode", modeId };
|
|
83383
|
+
}
|
|
83384
|
+
function applyConfigurationMode(options, modeId) {
|
|
83385
|
+
return options.map((option) => option.category === "mode" ? { ...option, currentValue: modeId } : option);
|
|
83386
|
+
}
|
|
83387
|
+
function applyConfigurationChanges(base, changes) {
|
|
83388
|
+
switch (changes.kind) {
|
|
83389
|
+
case "unchanged":
|
|
83390
|
+
return base;
|
|
83391
|
+
case "mode":
|
|
83392
|
+
return applyConfigurationMode(base, changes.modeId);
|
|
83393
|
+
case "replacement": {
|
|
83394
|
+
const options = changes.options.some((option) => option.category === "mode") ? changes.options : [
|
|
83395
|
+
...changes.modes.length > 0 ? changes.modes : base.filter((option) => option.category === "mode"),
|
|
83396
|
+
...changes.options
|
|
83397
|
+
].slice(0, MAXIMUM_CONFIG_OPTIONS);
|
|
83398
|
+
return changes.selection.kind === "selected" ? applyConfigurationMode(options, changes.selection.modeId) : options;
|
|
83399
|
+
}
|
|
83400
|
+
}
|
|
83401
|
+
}
|
|
83402
|
+
var init_configuration_changes = __esm({
|
|
83403
|
+
"src/engine/acp/adapter/configuration-changes.ts"() {
|
|
83404
|
+
"use strict";
|
|
83405
|
+
init_session_config_protocol();
|
|
83406
|
+
}
|
|
83407
|
+
});
|
|
83408
|
+
|
|
83298
83409
|
// src/engine/acp/adapter/session-events.ts
|
|
83299
83410
|
import { setImmediate as yieldToRuntime2 } from "node:timers/promises";
|
|
83300
83411
|
var AdapterSessionConnection, AcpSessionConnector;
|
|
@@ -83305,7 +83416,10 @@ var init_session_events = __esm({
|
|
|
83305
83416
|
init_value_utils();
|
|
83306
83417
|
init_acp_error();
|
|
83307
83418
|
init_agent_update_stream();
|
|
83419
|
+
init_session_capabilities();
|
|
83308
83420
|
init_session_config_protocol();
|
|
83421
|
+
init_agent_initialization();
|
|
83422
|
+
init_configuration_changes();
|
|
83309
83423
|
AdapterSessionConnection = class {
|
|
83310
83424
|
#connection;
|
|
83311
83425
|
#onBackgroundActivity;
|
|
@@ -83314,19 +83428,24 @@ var init_session_events = __esm({
|
|
|
83314
83428
|
#updates;
|
|
83315
83429
|
#lifetime = new AbortController();
|
|
83316
83430
|
#onClosed;
|
|
83431
|
+
#agent;
|
|
83432
|
+
#state = { kind: "uninitialized" };
|
|
83433
|
+
#initialization = {
|
|
83434
|
+
kind: "not-started"
|
|
83435
|
+
};
|
|
83317
83436
|
events;
|
|
83318
83437
|
constructor(options, externalizer, normalizeEvent, onClosed = () => void 0) {
|
|
83438
|
+
this.#agent = options.agent;
|
|
83319
83439
|
this.#onClosed = onClosed;
|
|
83320
83440
|
this.#onBackgroundActivity = options.onBackgroundActivity ?? (() => {
|
|
83321
83441
|
});
|
|
83322
|
-
const protocol = sessionConfigProtocolForAgent(options.agent.id);
|
|
83323
83442
|
this.#updates = new AgentUpdateStream(async (notification) => {
|
|
83324
83443
|
this.#lifetime.signal.throwIfAborted();
|
|
83325
83444
|
if (notification.sessionId !== this.#updates.sessionId()) {
|
|
83326
83445
|
throw new AcpExecutionError("ACP agent referenced an unknown session", {}, "invalid_agent_session");
|
|
83327
83446
|
}
|
|
83328
83447
|
const signal = AbortSignal.any([this.#lifetime.signal, AbortSignal.timeout(3e4)]);
|
|
83329
|
-
const externalized = await externalizer.update(
|
|
83448
|
+
const externalized = options.externalizeUpdate === void 0 ? await externalizer.update(notification.sessionId, notification.update, signal) : await options.externalizeUpdate(notification.update, signal);
|
|
83330
83449
|
signal.throwIfAborted();
|
|
83331
83450
|
const update = externalized.agent;
|
|
83332
83451
|
for (const eventUpdate of externalized.events) {
|
|
@@ -83352,13 +83471,15 @@ var init_session_events = __esm({
|
|
|
83352
83471
|
};
|
|
83353
83472
|
break;
|
|
83354
83473
|
case "config_option_update":
|
|
83474
|
+
this.#applyConfigurationUpdate(update.configOptions);
|
|
83355
83475
|
event = {
|
|
83356
83476
|
kind: "configuration",
|
|
83357
83477
|
payload,
|
|
83358
|
-
configOptions:
|
|
83478
|
+
configOptions: this.snapshot().configOptions
|
|
83359
83479
|
};
|
|
83360
83480
|
break;
|
|
83361
83481
|
case "current_mode_update":
|
|
83482
|
+
this.#applyModeUpdate(update.currentModeId);
|
|
83362
83483
|
event = { kind: "mode", payload, modeId: update.currentModeId };
|
|
83363
83484
|
break;
|
|
83364
83485
|
case "session_info_update": {
|
|
@@ -83430,10 +83551,92 @@ var init_session_events = __esm({
|
|
|
83430
83551
|
get termination() {
|
|
83431
83552
|
return this.#connection.termination;
|
|
83432
83553
|
}
|
|
83554
|
+
#ready = () => {
|
|
83555
|
+
const state = this.#state;
|
|
83556
|
+
if (state.kind !== "ready") {
|
|
83557
|
+
throw new AcpExecutionError(
|
|
83558
|
+
"The Agent session is not initialized or has closed",
|
|
83559
|
+
{},
|
|
83560
|
+
"invalid_agent_session"
|
|
83561
|
+
);
|
|
83562
|
+
}
|
|
83563
|
+
return state;
|
|
83564
|
+
};
|
|
83565
|
+
snapshot = () => this.#ready().snapshot;
|
|
83566
|
+
beginStateChange = () => {
|
|
83567
|
+
const state = this.#ready();
|
|
83568
|
+
if (state.operation.kind !== "idle") {
|
|
83569
|
+
throw new AcpExecutionError("Another session configuration operation is running", {}, "session_busy");
|
|
83570
|
+
}
|
|
83571
|
+
this.#state = { ...state, operation: { kind: "pending", changes: { kind: "unchanged" } } };
|
|
83572
|
+
};
|
|
83573
|
+
cancelStateChange = () => {
|
|
83574
|
+
if (this.#state.kind === "ready") {
|
|
83575
|
+
this.#state = { ...this.#state, operation: { kind: "idle" } };
|
|
83576
|
+
}
|
|
83577
|
+
};
|
|
83578
|
+
commitConfiguration = (options) => {
|
|
83579
|
+
const state = this.#ready();
|
|
83580
|
+
if (state.operation.kind !== "pending") {
|
|
83581
|
+
throw new AcpExecutionError("No session configuration operation is running", {}, "invalid_agent_session");
|
|
83582
|
+
}
|
|
83583
|
+
const configOptions = applyConfigurationChanges(options, state.operation.changes);
|
|
83584
|
+
this.#state = { ...state, snapshot: { ...state.snapshot, configOptions }, operation: { kind: "idle" } };
|
|
83585
|
+
return configOptions;
|
|
83586
|
+
};
|
|
83587
|
+
commitLifecycle = (response) => {
|
|
83588
|
+
const state = this.#ready();
|
|
83589
|
+
const capabilities = restrictAcpSessionCapabilities(state.snapshot.capabilities, response);
|
|
83590
|
+
this.commitConfiguration(sessionConfigProtocolForAgent(this.#agent.id).normalizeLifecycle(response));
|
|
83591
|
+
this.#state = { ...this.#ready(), snapshot: { capabilities, configOptions: this.snapshot().configOptions } };
|
|
83592
|
+
return this.snapshot();
|
|
83593
|
+
};
|
|
83594
|
+
#applyConfigurationUpdate = (value) => {
|
|
83595
|
+
const state = this.#ready();
|
|
83596
|
+
const protocol = sessionConfigProtocolForAgent(this.#agent.id);
|
|
83597
|
+
const configOptions = protocol.normalizeUpdate(state.snapshot.configOptions, value);
|
|
83598
|
+
const operation = state.operation.kind === "pending" ? {
|
|
83599
|
+
kind: "pending",
|
|
83600
|
+
changes: recordConfigurationOptions(state.operation.changes, protocol.normalizeUpdate([], value))
|
|
83601
|
+
} : state.operation;
|
|
83602
|
+
this.#state = { ...state, snapshot: { ...state.snapshot, configOptions }, operation };
|
|
83603
|
+
};
|
|
83604
|
+
#applyModeUpdate = (modeId) => {
|
|
83605
|
+
const state = this.#ready();
|
|
83606
|
+
const operation = state.operation.kind === "pending" ? { kind: "pending", changes: recordConfigurationMode(state.operation.changes, modeId) } : state.operation;
|
|
83607
|
+
this.#state = {
|
|
83608
|
+
...state,
|
|
83609
|
+
snapshot: {
|
|
83610
|
+
...state.snapshot,
|
|
83611
|
+
configOptions: applyConfigurationMode(state.snapshot.configOptions, modeId)
|
|
83612
|
+
},
|
|
83613
|
+
operation
|
|
83614
|
+
};
|
|
83615
|
+
};
|
|
83433
83616
|
initialize = (signal) => this.#connection.initialize(signal);
|
|
83617
|
+
initializeAgent = (signal) => {
|
|
83618
|
+
if (this.#initialization.kind === "not-started") {
|
|
83619
|
+
this.#initialization = {
|
|
83620
|
+
kind: "started",
|
|
83621
|
+
result: initializeAgentConnection(this, this.#agent.id, this.#agent.agentVersion, signal).then(
|
|
83622
|
+
(agent) => {
|
|
83623
|
+
this.#lifetime.signal.throwIfAborted();
|
|
83624
|
+
this.#state = {
|
|
83625
|
+
kind: "ready",
|
|
83626
|
+
snapshot: { capabilities: agent.capabilities, configOptions: [] },
|
|
83627
|
+
operation: { kind: "idle" }
|
|
83628
|
+
};
|
|
83629
|
+
return agent;
|
|
83630
|
+
}
|
|
83631
|
+
)
|
|
83632
|
+
};
|
|
83633
|
+
}
|
|
83634
|
+
return this.#initialization.result;
|
|
83635
|
+
};
|
|
83434
83636
|
agentSettingsModelEffort = () => this.#connection.agentSettingsModelEffort();
|
|
83435
83637
|
race = (operation, exitMessage, signal) => this.#connection.race(operation, exitMessage, signal);
|
|
83436
83638
|
closeProcess = async () => {
|
|
83639
|
+
this.#state = { kind: "closed" };
|
|
83437
83640
|
this.#lifetime.abort(new DOMException("The adapter event subscription closed", "AbortError"));
|
|
83438
83641
|
try {
|
|
83439
83642
|
await this.#connection.closeProcess();
|
|
@@ -83481,12 +83684,12 @@ var init_session_events = __esm({
|
|
|
83481
83684
|
}
|
|
83482
83685
|
});
|
|
83483
83686
|
|
|
83484
|
-
// src/engine/acp/adapter/
|
|
83687
|
+
// src/engine/acp/adapter/execution-connections.ts
|
|
83485
83688
|
import { isAbsolute as isAbsolute14, resolve as resolve14 } from "node:path";
|
|
83486
|
-
import { methods as
|
|
83487
|
-
var absolutePathSchema, targetSchema,
|
|
83488
|
-
var
|
|
83489
|
-
"src/engine/acp/adapter/
|
|
83689
|
+
import { methods as methods11 } from "@agentclientprotocol/sdk";
|
|
83690
|
+
var absolutePathSchema, targetSchema, AcpExecutionConnections;
|
|
83691
|
+
var init_execution_connections = __esm({
|
|
83692
|
+
"src/engine/acp/adapter/execution-connections.ts"() {
|
|
83490
83693
|
"use strict";
|
|
83491
83694
|
init_protocol();
|
|
83492
83695
|
init_zod();
|
|
@@ -83502,7 +83705,7 @@ var init_live_sessions = __esm({
|
|
|
83502
83705
|
cwd: absolutePathSchema,
|
|
83503
83706
|
additionalDirectories: external_exports.array(absolutePathSchema)
|
|
83504
83707
|
});
|
|
83505
|
-
|
|
83708
|
+
AcpExecutionConnections = class {
|
|
83506
83709
|
#sessions = /* @__PURE__ */ new Set();
|
|
83507
83710
|
#externalizer;
|
|
83508
83711
|
#normalizeEvent;
|
|
@@ -83510,16 +83713,72 @@ var init_live_sessions = __esm({
|
|
|
83510
83713
|
this.#externalizer = externalizer;
|
|
83511
83714
|
this.#normalizeEvent = normalizeEvent;
|
|
83512
83715
|
}
|
|
83513
|
-
|
|
83716
|
+
acquire = (params) => {
|
|
83717
|
+
params.signal.throwIfAborted();
|
|
83718
|
+
const existing = [...this.#sessions].find(
|
|
83719
|
+
({ subscriber }) => subscriber.onSessionEvent === params.onSessionEvent
|
|
83720
|
+
);
|
|
83721
|
+
if (existing !== void 0) {
|
|
83722
|
+
if (existing.scope.agent !== params.scope.agent || existing.scope.cwd !== params.scope.cwd || !arraysEqual(existing.scope.additionalDirectories, params.scope.additionalDirectories)) {
|
|
83723
|
+
throw new AcpExecutionError(
|
|
83724
|
+
"The agent or workspace cannot change after a conversation has started",
|
|
83725
|
+
{},
|
|
83726
|
+
"session_identity_mismatch"
|
|
83727
|
+
);
|
|
83728
|
+
}
|
|
83729
|
+
return existing;
|
|
83730
|
+
}
|
|
83514
83731
|
const connection = new AdapterSessionConnection(
|
|
83515
|
-
|
|
83732
|
+
{
|
|
83733
|
+
agent: params.scope.agent,
|
|
83734
|
+
cwd: params.scope.cwd,
|
|
83735
|
+
...params.scope.externalizeUpdate === void 0 ? {} : { externalizeUpdate: params.scope.externalizeUpdate },
|
|
83736
|
+
onEvent: (event) => params.onSessionEvent(connection.events.sessionId(), event),
|
|
83737
|
+
...params.onBackgroundActivity === void 0 ? {} : { onBackgroundActivity: params.onBackgroundActivity },
|
|
83738
|
+
interactions: params.interactions
|
|
83739
|
+
},
|
|
83516
83740
|
this.#externalizer,
|
|
83517
83741
|
this.#normalizeEvent,
|
|
83518
83742
|
() => this.#sessions.delete(session)
|
|
83519
83743
|
);
|
|
83520
|
-
const session = { connection, scope };
|
|
83744
|
+
const session = { connection, scope: params.scope, subscriber: params };
|
|
83521
83745
|
this.#sessions.add(session);
|
|
83522
|
-
return
|
|
83746
|
+
return session;
|
|
83747
|
+
};
|
|
83748
|
+
/** Resource scope only: the concrete adapter supplies the protocol operation. */
|
|
83749
|
+
withConnection = async (params, operation) => {
|
|
83750
|
+
const signal = AbortSignal.any([params.signal, AbortSignal.timeout(6e4)]);
|
|
83751
|
+
signal.throwIfAborted();
|
|
83752
|
+
const session = this.acquire(params);
|
|
83753
|
+
const wasBound = session.connection.events.sessionId().length > 0;
|
|
83754
|
+
try {
|
|
83755
|
+
await session.connection.initializeAgent(signal);
|
|
83756
|
+
session.connection.beginStateChange();
|
|
83757
|
+
try {
|
|
83758
|
+
const result = await operation(session, signal);
|
|
83759
|
+
signal.throwIfAborted();
|
|
83760
|
+
return result;
|
|
83761
|
+
} catch (cause) {
|
|
83762
|
+
session.connection.cancelStateChange();
|
|
83763
|
+
throw cause;
|
|
83764
|
+
}
|
|
83765
|
+
} catch (cause) {
|
|
83766
|
+
if (!wasBound) {
|
|
83767
|
+
await session.connection.closeProcess();
|
|
83768
|
+
}
|
|
83769
|
+
throw cause;
|
|
83770
|
+
}
|
|
83771
|
+
};
|
|
83772
|
+
bind = (session, nativeSessionId) => {
|
|
83773
|
+
const existing = this.#find({
|
|
83774
|
+
nativeSessionId,
|
|
83775
|
+
cwd: session.scope.cwd,
|
|
83776
|
+
additionalDirectories: session.scope.additionalDirectories
|
|
83777
|
+
});
|
|
83778
|
+
if (existing !== void 0 && existing !== session) {
|
|
83779
|
+
throw new AcpExecutionError("Another writer is using this native session", {}, "session_busy");
|
|
83780
|
+
}
|
|
83781
|
+
session.connection.events.select(nativeSessionId);
|
|
83523
83782
|
};
|
|
83524
83783
|
#find = (target) => {
|
|
83525
83784
|
const decoded = targetSchema.safeParse(target);
|
|
@@ -83548,12 +83807,12 @@ var init_live_sessions = __esm({
|
|
|
83548
83807
|
}
|
|
83549
83808
|
return session;
|
|
83550
83809
|
};
|
|
83551
|
-
cancel = async (
|
|
83810
|
+
cancel = async ({ signal, ...target }) => {
|
|
83552
83811
|
const bounded = AbortSignal.any([signal, AbortSignal.timeout(3e4)]);
|
|
83553
83812
|
bounded.throwIfAborted();
|
|
83554
83813
|
const { connection } = this.#resolve(target);
|
|
83555
83814
|
await connection.race(
|
|
83556
|
-
connection.connection.agent.notify(
|
|
83815
|
+
connection.connection.agent.notify(methods11.agent.session.cancel, {
|
|
83557
83816
|
sessionId: connection.events.sessionId()
|
|
83558
83817
|
}),
|
|
83559
83818
|
"ACP agent exited while cancelling a prompt",
|
|
@@ -83561,19 +83820,19 @@ var init_live_sessions = __esm({
|
|
|
83561
83820
|
);
|
|
83562
83821
|
return "retained";
|
|
83563
83822
|
};
|
|
83564
|
-
closeSession = async (
|
|
83823
|
+
closeSession = async ({ signal, ...target }) => {
|
|
83565
83824
|
const session = this.#find(target);
|
|
83566
83825
|
if (session === void 0) {
|
|
83567
83826
|
signal.throwIfAborted();
|
|
83568
83827
|
return;
|
|
83569
83828
|
}
|
|
83570
|
-
const { connection
|
|
83829
|
+
const { connection } = session;
|
|
83571
83830
|
try {
|
|
83572
83831
|
signal.throwIfAborted();
|
|
83573
|
-
if (
|
|
83832
|
+
if (connection.snapshot().capabilities.closeSession) {
|
|
83574
83833
|
try {
|
|
83575
83834
|
await connection.connection.agent.request(
|
|
83576
|
-
|
|
83835
|
+
methods11.agent.session.close,
|
|
83577
83836
|
{ sessionId: connection.events.sessionId() },
|
|
83578
83837
|
{ cancellationSignal: AbortSignal.any([signal, AbortSignal.timeout(1e3)]) }
|
|
83579
83838
|
);
|
|
@@ -83586,13 +83845,20 @@ var init_live_sessions = __esm({
|
|
|
83586
83845
|
}
|
|
83587
83846
|
signal.throwIfAborted();
|
|
83588
83847
|
};
|
|
83589
|
-
|
|
83848
|
+
releaseSession = async ({ signal, ...target }) => {
|
|
83849
|
+
const session = this.#find(target);
|
|
83850
|
+
if (session !== void 0) {
|
|
83851
|
+
await session.connection.closeProcess();
|
|
83852
|
+
}
|
|
83590
83853
|
signal.throwIfAborted();
|
|
83591
|
-
|
|
83592
|
-
|
|
83854
|
+
};
|
|
83855
|
+
prompt = async ({ content, signal, ...target }) => {
|
|
83856
|
+
signal.throwIfAborted();
|
|
83857
|
+
const { connection } = this.#resolve(target);
|
|
83858
|
+
const prompt = buildPromptContent(content, connection.snapshot().capabilities);
|
|
83593
83859
|
const response = await connection.race(
|
|
83594
83860
|
connection.connection.agent.request(
|
|
83595
|
-
|
|
83861
|
+
methods11.agent.session.prompt,
|
|
83596
83862
|
{ prompt, sessionId: target.nativeSessionId },
|
|
83597
83863
|
{ cancellationSignal: signal }
|
|
83598
83864
|
),
|
|
@@ -83619,10 +83885,10 @@ var init_live_sessions = __esm({
|
|
|
83619
83885
|
);
|
|
83620
83886
|
}
|
|
83621
83887
|
};
|
|
83622
|
-
steer = async (
|
|
83888
|
+
steer = async ({ content, signal, ...target }) => {
|
|
83623
83889
|
signal.throwIfAborted();
|
|
83624
|
-
const { connection
|
|
83625
|
-
if (!
|
|
83890
|
+
const { connection } = this.#resolve(target);
|
|
83891
|
+
if (!connection.snapshot().capabilities.steering) {
|
|
83626
83892
|
throw new AcpExecutionError(
|
|
83627
83893
|
"The selected agent does not support mid-turn steering",
|
|
83628
83894
|
{},
|
|
@@ -83634,7 +83900,7 @@ var init_live_sessions = __esm({
|
|
|
83634
83900
|
"_session/steering",
|
|
83635
83901
|
{
|
|
83636
83902
|
_meta: { steering: { idleBehavior: "promptRequired" } },
|
|
83637
|
-
prompt: buildPromptContent(content,
|
|
83903
|
+
prompt: buildPromptContent(content, connection.snapshot().capabilities),
|
|
83638
83904
|
sessionId: target.nativeSessionId
|
|
83639
83905
|
},
|
|
83640
83906
|
{ cancellationSignal: signal }
|
|
@@ -83664,14 +83930,14 @@ var init_live_sessions = __esm({
|
|
|
83664
83930
|
"acp_invalid_steering_response"
|
|
83665
83931
|
);
|
|
83666
83932
|
};
|
|
83667
|
-
renameSession = async (
|
|
83933
|
+
renameSession = async ({ title: title2, signal, ...target }) => {
|
|
83668
83934
|
signal.throwIfAborted();
|
|
83669
|
-
const { connection
|
|
83935
|
+
const { connection } = this.#resolve(target);
|
|
83670
83936
|
const normalized = truncate(title2, 500);
|
|
83671
83937
|
if (normalized.length === 0) {
|
|
83672
83938
|
throw new AcpExecutionError("The Session title cannot be empty", {}, "invalid_session_title");
|
|
83673
83939
|
}
|
|
83674
|
-
if (!
|
|
83940
|
+
if (!connection.snapshot().capabilities.renameSession) {
|
|
83675
83941
|
return { nativeRenameApplied: false };
|
|
83676
83942
|
}
|
|
83677
83943
|
try {
|
|
@@ -83697,10 +83963,14 @@ var init_live_sessions = __esm({
|
|
|
83697
83963
|
}
|
|
83698
83964
|
return { nativeRenameApplied: true };
|
|
83699
83965
|
};
|
|
83700
|
-
configureSession = async (
|
|
83966
|
+
configureSession = async ({
|
|
83967
|
+
selection,
|
|
83968
|
+
signal,
|
|
83969
|
+
...target
|
|
83970
|
+
}) => {
|
|
83701
83971
|
signal.throwIfAborted();
|
|
83702
83972
|
const { connection, scope } = this.#resolve(target);
|
|
83703
|
-
const current =
|
|
83973
|
+
const current = connection.snapshot().configOptions;
|
|
83704
83974
|
const existing = current.find((option) => option.id === selection.configId);
|
|
83705
83975
|
if (existing === void 0 || existing.type !== selection.type || existing.type === "select" && existing.values.length < 2) {
|
|
83706
83976
|
throw new AcpExecutionError(
|
|
@@ -83716,6 +83986,7 @@ var init_live_sessions = __esm({
|
|
|
83716
83986
|
existing.values.map((entry) => entry.value)
|
|
83717
83987
|
);
|
|
83718
83988
|
}
|
|
83989
|
+
connection.beginStateChange();
|
|
83719
83990
|
try {
|
|
83720
83991
|
const configured = await sessionConfigProtocolForAgent(scope.agent.id).configure(
|
|
83721
83992
|
current,
|
|
@@ -83743,8 +84014,9 @@ var init_live_sessions = __esm({
|
|
|
83743
84014
|
);
|
|
83744
84015
|
}
|
|
83745
84016
|
await connection.events.drained();
|
|
83746
|
-
return configured;
|
|
84017
|
+
return connection.commitConfiguration(configured);
|
|
83747
84018
|
} catch (error62) {
|
|
84019
|
+
connection.cancelStateChange();
|
|
83748
84020
|
if (error62 instanceof SessionConfigProtocolError) {
|
|
83749
84021
|
throw new AcpExecutionError(error62.message, { cause: error62 }, error62.code);
|
|
83750
84022
|
}
|
|
@@ -83765,8 +84037,48 @@ var init_live_sessions = __esm({
|
|
|
83765
84037
|
}
|
|
83766
84038
|
});
|
|
83767
84039
|
|
|
84040
|
+
// src/engine/acp/adapter/lifecycle-output.ts
|
|
84041
|
+
function sessionWorkspace(scope) {
|
|
84042
|
+
return { cwd: scope.cwd, additionalDirectories: [...scope.additionalDirectories], mcpServers: [] };
|
|
84043
|
+
}
|
|
84044
|
+
function createdNativeSessionId(response) {
|
|
84045
|
+
const decoded = external_exports.object({ sessionId: nativeSessionIdSchema }).safeParse(response);
|
|
84046
|
+
if (!decoded.success) {
|
|
84047
|
+
throw new AcpExecutionError(
|
|
84048
|
+
"The Agent returned an invalid native session",
|
|
84049
|
+
{ cause: decoded.error },
|
|
84050
|
+
"invalid_native_session_response"
|
|
84051
|
+
);
|
|
84052
|
+
}
|
|
84053
|
+
return decoded.data.sessionId;
|
|
84054
|
+
}
|
|
84055
|
+
async function normalizeOpenedSession(session, nativeSessionId, response, signal) {
|
|
84056
|
+
await session.connection.race(
|
|
84057
|
+
session.connection.events.drained(),
|
|
84058
|
+
"ACP agent exited while opening a session",
|
|
84059
|
+
signal
|
|
84060
|
+
);
|
|
84061
|
+
signal.throwIfAborted();
|
|
84062
|
+
const initialized = await session.connection.initializeAgent(signal);
|
|
84063
|
+
return {
|
|
84064
|
+
nativeSessionId,
|
|
84065
|
+
agentName: initialized.agentName,
|
|
84066
|
+
agentVersion: initialized.agentVersion,
|
|
84067
|
+
agentSettingsModelEffort: session.connection.agentSettingsModelEffort(),
|
|
84068
|
+
...session.connection.commitLifecycle(response)
|
|
84069
|
+
};
|
|
84070
|
+
}
|
|
84071
|
+
var init_lifecycle_output = __esm({
|
|
84072
|
+
"src/engine/acp/adapter/lifecycle-output.ts"() {
|
|
84073
|
+
"use strict";
|
|
84074
|
+
init_zod();
|
|
84075
|
+
init_acp_error();
|
|
84076
|
+
init_native_session();
|
|
84077
|
+
}
|
|
84078
|
+
});
|
|
84079
|
+
|
|
83768
84080
|
// src/engine/acp/adapter/native-session-lookup.ts
|
|
83769
|
-
async function findNativeSession(list,
|
|
84081
|
+
async function findNativeSession(list, query, nativeSessionId, budget) {
|
|
83770
84082
|
const decoded = lookupSchema.safeParse({ nativeSessionId, budget });
|
|
83771
84083
|
if (!decoded.success) {
|
|
83772
84084
|
throw new AcpExecutionError(
|
|
@@ -83780,9 +84092,9 @@ async function findNativeSession(list, cwd, nativeSessionId, budget, signal) {
|
|
|
83780
84092
|
let inspected = 0;
|
|
83781
84093
|
const visited = /* @__PURE__ */ new Set();
|
|
83782
84094
|
for (let pageNumber = 0; pageNumber < limits.maximumPages; pageNumber += 1) {
|
|
83783
|
-
signal.throwIfAborted();
|
|
83784
|
-
const page = await list(
|
|
83785
|
-
signal.throwIfAborted();
|
|
84095
|
+
query.signal.throwIfAborted();
|
|
84096
|
+
const page = await list({ query, cursor });
|
|
84097
|
+
query.signal.throwIfAborted();
|
|
83786
84098
|
inspected += page.sessions.length;
|
|
83787
84099
|
const found = page.sessions.find((session) => session.sessionId === decoded.data.nativeSessionId);
|
|
83788
84100
|
if (found !== void 0) {
|
|
@@ -84485,75 +84797,27 @@ var init_retained_agent_processes = __esm({
|
|
|
84485
84797
|
}
|
|
84486
84798
|
});
|
|
84487
84799
|
|
|
84488
|
-
// src/engine/acp/adapter/
|
|
84489
|
-
|
|
84490
|
-
|
|
84491
|
-
|
|
84492
|
-
|
|
84493
|
-
|
|
84494
|
-
|
|
84495
|
-
|
|
84496
|
-
|
|
84497
|
-
|
|
84498
|
-
"agent_runtime_changed"
|
|
84499
|
-
);
|
|
84500
|
-
}
|
|
84800
|
+
// src/engine/acp/adapter/query-scope.ts
|
|
84801
|
+
function nativeSessionQueryKey(query) {
|
|
84802
|
+
return queryKeySchema.parse(
|
|
84803
|
+
JSON.stringify([
|
|
84804
|
+
query.agent.id,
|
|
84805
|
+
query.cwd,
|
|
84806
|
+
query.additionalDirectories,
|
|
84807
|
+
Object.entries(query.agent.environment).sort(([left], [right]) => left.localeCompare(right))
|
|
84808
|
+
])
|
|
84809
|
+
);
|
|
84501
84810
|
}
|
|
84502
|
-
|
|
84503
|
-
|
|
84504
|
-
signal.throwIfAborted();
|
|
84505
|
-
throw new RetryableAcpInitializationError(cause);
|
|
84506
|
-
});
|
|
84507
|
-
const initialized = await connection.race(
|
|
84508
|
-
connection.connection.agent.request(
|
|
84509
|
-
methods11.agent.initialize,
|
|
84510
|
-
{
|
|
84511
|
-
clientCapabilities: {
|
|
84512
|
-
elicitation: { form: {}, url: {} },
|
|
84513
|
-
plan: {},
|
|
84514
|
-
session: { compaction: {}, configOptions: { boolean: {} } }
|
|
84515
|
-
},
|
|
84516
|
-
clientInfo: { name: "mobius", version: "0.0.3" },
|
|
84517
|
-
protocolVersion: PROTOCOL_VERSION3
|
|
84518
|
-
},
|
|
84519
|
-
{ cancellationSignal: signal }
|
|
84520
|
-
),
|
|
84521
|
-
"ACP agent exited during initialization",
|
|
84522
|
-
signal
|
|
84523
|
-
).catch((cause) => {
|
|
84524
|
-
signal.throwIfAborted();
|
|
84525
|
-
throw new RetryableAcpInitializationError(cause);
|
|
84526
|
-
});
|
|
84527
|
-
if (initialized.protocolVersion !== PROTOCOL_VERSION3) {
|
|
84528
|
-
throw new AcpExecutionError(
|
|
84529
|
-
"ACP agent selected an unsupported protocol version",
|
|
84530
|
-
{},
|
|
84531
|
-
"unsupported_acp_protocol"
|
|
84532
|
-
);
|
|
84533
|
-
}
|
|
84534
|
-
return {
|
|
84535
|
-
capabilities: normalizeAcpCapabilities(initialized),
|
|
84536
|
-
agentName: truncate(initialized.agentInfo?.title ?? initialized.agentInfo?.name ?? agentId, 255),
|
|
84537
|
-
agentVersion: truncate(
|
|
84538
|
-
verifiedVersion.length > 0 ? verifiedVersion : initialized.agentInfo?.version ?? "",
|
|
84539
|
-
128
|
|
84540
|
-
)
|
|
84541
|
-
};
|
|
84811
|
+
function nativeSessionPreviewKey(queryKey, nativeSessionId) {
|
|
84812
|
+
return previewKeySchema.parse(JSON.stringify([queryKey, nativeSessionId]));
|
|
84542
84813
|
}
|
|
84543
|
-
var
|
|
84544
|
-
var
|
|
84545
|
-
"src/engine/acp/adapter/
|
|
84814
|
+
var queryKeySchema, previewKeySchema;
|
|
84815
|
+
var init_query_scope = __esm({
|
|
84816
|
+
"src/engine/acp/adapter/query-scope.ts"() {
|
|
84546
84817
|
"use strict";
|
|
84547
|
-
|
|
84548
|
-
|
|
84549
|
-
|
|
84550
|
-
init_session_capabilities();
|
|
84551
|
-
RetryableAcpInitializationError = class extends AcpExecutionError {
|
|
84552
|
-
constructor(cause) {
|
|
84553
|
-
super("ACP agent initialization failed", { cause });
|
|
84554
|
-
this.name = "RetryableAcpInitializationError";
|
|
84555
|
-
}
|
|
84556
|
-
};
|
|
84818
|
+
init_zod();
|
|
84819
|
+
queryKeySchema = external_exports.string().brand();
|
|
84820
|
+
previewKeySchema = external_exports.string().brand();
|
|
84557
84821
|
}
|
|
84558
84822
|
});
|
|
84559
84823
|
|
|
@@ -84565,48 +84829,35 @@ var init_query_session = __esm({
|
|
|
84565
84829
|
"use strict";
|
|
84566
84830
|
init_acp_error();
|
|
84567
84831
|
init_native_session();
|
|
84568
|
-
init_session_capabilities();
|
|
84569
84832
|
init_agent_initialization();
|
|
84570
84833
|
AcpQuerySession = class _AcpQuerySession {
|
|
84571
|
-
#
|
|
84572
|
-
#sessionId;
|
|
84834
|
+
#options;
|
|
84573
84835
|
#events;
|
|
84574
84836
|
#connection;
|
|
84575
84837
|
#lifecycle = { kind: "open" };
|
|
84576
|
-
#
|
|
84577
|
-
|
|
84578
|
-
|
|
84579
|
-
this.#cwd = cwd;
|
|
84580
|
-
this.#sessionId = sessionId;
|
|
84838
|
+
#eventScope = crypto.randomUUID();
|
|
84839
|
+
constructor(options, events, connector) {
|
|
84840
|
+
this.#options = options;
|
|
84581
84841
|
this.#events = events;
|
|
84582
84842
|
this.#connection = connector.connectQuerySession({
|
|
84583
|
-
agent,
|
|
84584
|
-
cwd,
|
|
84585
|
-
|
|
84586
|
-
configOptions: () => this.#configOptions,
|
|
84843
|
+
agent: options.agent,
|
|
84844
|
+
cwd: options.cwd,
|
|
84845
|
+
...options.externalizeUpdate === void 0 ? {} : { externalizeUpdate: options.externalizeUpdate },
|
|
84587
84846
|
onEvent: async (event) => {
|
|
84588
|
-
this.#events.append(
|
|
84589
|
-
if (event.kind === "configuration") {
|
|
84590
|
-
this.#configOptions = event.configOptions;
|
|
84591
|
-
}
|
|
84847
|
+
this.#events.append(this.#eventScope, { type: "acp", payload: event.payload });
|
|
84592
84848
|
}
|
|
84593
84849
|
});
|
|
84594
84850
|
void this.#connection.termination.then(() => {
|
|
84595
84851
|
this.#lifecycle = { kind: "terminated" };
|
|
84596
84852
|
});
|
|
84597
84853
|
}
|
|
84598
|
-
static start = async (
|
|
84854
|
+
static start = async (options, events, connector) => {
|
|
84855
|
+
const { agent, signal } = options;
|
|
84599
84856
|
for (let attempt = 1; attempt <= 2; attempt += 1) {
|
|
84600
84857
|
await validateAgentRuntime(agent, signal);
|
|
84601
|
-
const runtime = new _AcpQuerySession(
|
|
84858
|
+
const runtime = new _AcpQuerySession(options, events, connector);
|
|
84602
84859
|
try {
|
|
84603
|
-
|
|
84604
|
-
runtime.#connection,
|
|
84605
|
-
agent.id,
|
|
84606
|
-
agent.agentVersion,
|
|
84607
|
-
signal
|
|
84608
|
-
);
|
|
84609
|
-
runtime.#capabilities = initialized.capabilities;
|
|
84860
|
+
await runtime.#connection.initializeAgent(options.signal);
|
|
84610
84861
|
return runtime;
|
|
84611
84862
|
} catch (error62) {
|
|
84612
84863
|
await runtime.closeProcess();
|
|
@@ -84623,7 +84874,7 @@ var init_query_session = __esm({
|
|
|
84623
84874
|
}
|
|
84624
84875
|
throw new AcpExecutionError("ACP agent initialization failed");
|
|
84625
84876
|
};
|
|
84626
|
-
capabilities = () => this.#capabilities;
|
|
84877
|
+
capabilities = () => this.#connection.snapshot().capabilities;
|
|
84627
84878
|
hasTerminated = () => {
|
|
84628
84879
|
switch (this.#lifecycle.kind) {
|
|
84629
84880
|
case "open":
|
|
@@ -84637,7 +84888,7 @@ var init_query_session = __esm({
|
|
|
84637
84888
|
}
|
|
84638
84889
|
};
|
|
84639
84890
|
listNativeSessions = async (cursor, signal) => {
|
|
84640
|
-
if (!this
|
|
84891
|
+
if (!this.capabilities().listSessions) {
|
|
84641
84892
|
throw new AcpExecutionError(
|
|
84642
84893
|
"This Agent does not support native session listing",
|
|
84643
84894
|
{},
|
|
@@ -84661,22 +84912,24 @@ var init_query_session = __esm({
|
|
|
84661
84912
|
}
|
|
84662
84913
|
return decoded.data;
|
|
84663
84914
|
};
|
|
84664
|
-
previewEvents = async (nativeSessionId, eventLimit,
|
|
84665
|
-
if (!this
|
|
84915
|
+
previewEvents = async (nativeSessionId, eventLimit, signal) => {
|
|
84916
|
+
if (!this.capabilities().loadSession) {
|
|
84666
84917
|
throw new AcpExecutionError(
|
|
84667
84918
|
"This Agent restores context but does not provide message history.",
|
|
84668
84919
|
{},
|
|
84669
84920
|
"native_history_unsupported"
|
|
84670
84921
|
);
|
|
84671
84922
|
}
|
|
84672
|
-
this.#
|
|
84923
|
+
this.#eventScope = nativeSessionId;
|
|
84924
|
+
this.#events.reset(nativeSessionId);
|
|
84673
84925
|
this.#connection.events.select(nativeSessionId);
|
|
84674
|
-
|
|
84926
|
+
this.#connection.beginStateChange();
|
|
84927
|
+
const response = await this.#connection.race(
|
|
84675
84928
|
this.#connection.connection.agent.request(
|
|
84676
84929
|
methods12.agent.session.load,
|
|
84677
84930
|
{
|
|
84678
|
-
additionalDirectories: [...additionalDirectories],
|
|
84679
|
-
cwd: this.#cwd,
|
|
84931
|
+
additionalDirectories: [...this.#options.additionalDirectories],
|
|
84932
|
+
cwd: this.#options.cwd,
|
|
84680
84933
|
mcpServers: [],
|
|
84681
84934
|
sessionId: nativeSessionId
|
|
84682
84935
|
},
|
|
@@ -84687,16 +84940,16 @@ var init_query_session = __esm({
|
|
|
84687
84940
|
);
|
|
84688
84941
|
await this.#connection.events.drained();
|
|
84689
84942
|
signal.throwIfAborted();
|
|
84690
|
-
|
|
84943
|
+
this.#connection.commitLifecycle(response);
|
|
84944
|
+
return this.#events.page(nativeSessionId, eventLimit, null);
|
|
84691
84945
|
};
|
|
84692
84946
|
closeProcess = async () => await this.#connection.closeProcess();
|
|
84693
|
-
discardEvents = () => this.#events.remove(this.#
|
|
84947
|
+
discardEvents = () => this.#events.remove(this.#eventScope);
|
|
84694
84948
|
};
|
|
84695
84949
|
}
|
|
84696
84950
|
});
|
|
84697
84951
|
|
|
84698
84952
|
// src/engine/acp/adapter/query-processes.ts
|
|
84699
|
-
import { randomUUID as randomUUID14 } from "node:crypto";
|
|
84700
84953
|
var AgentQueryProcesses;
|
|
84701
84954
|
var init_query_processes = __esm({
|
|
84702
84955
|
"src/engine/acp/adapter/query-processes.ts"() {
|
|
@@ -84704,6 +84957,7 @@ var init_query_processes = __esm({
|
|
|
84704
84957
|
init_session_event_store();
|
|
84705
84958
|
init_operation_drain();
|
|
84706
84959
|
init_retained_agent_processes();
|
|
84960
|
+
init_query_scope();
|
|
84707
84961
|
init_query_session();
|
|
84708
84962
|
AgentQueryProcesses = class {
|
|
84709
84963
|
#eventPreviewsBySession = /* @__PURE__ */ new Map();
|
|
@@ -84720,45 +84974,46 @@ var init_query_processes = __esm({
|
|
|
84720
84974
|
refreshAgent = (agent) => {
|
|
84721
84975
|
this.#agent = agent;
|
|
84722
84976
|
};
|
|
84723
|
-
retire = async (readers,
|
|
84724
|
-
readers.detach(
|
|
84977
|
+
retire = async (readers, key, runtime) => {
|
|
84978
|
+
readers.detach(key, runtime);
|
|
84725
84979
|
try {
|
|
84726
84980
|
await this.#processes.retire(runtime, () => runtime.closeProcess());
|
|
84727
84981
|
} finally {
|
|
84728
84982
|
runtime.discardEvents();
|
|
84729
84983
|
}
|
|
84730
84984
|
};
|
|
84731
|
-
async #ensure(
|
|
84732
|
-
signal.throwIfAborted();
|
|
84733
|
-
const
|
|
84985
|
+
async #ensure(readers, query) {
|
|
84986
|
+
query.signal.throwIfAborted();
|
|
84987
|
+
const key = nativeSessionQueryKey(query);
|
|
84988
|
+
const pending = readers.pending(key);
|
|
84734
84989
|
if (pending !== void 0) {
|
|
84735
|
-
return await waitForSharedOperation(pending, signal);
|
|
84990
|
+
return await waitForSharedOperation(pending, query.signal);
|
|
84736
84991
|
}
|
|
84737
|
-
const existing = readers.get(
|
|
84992
|
+
const existing = readers.get(key);
|
|
84738
84993
|
if (existing !== void 0 && !existing.hasTerminated()) {
|
|
84739
|
-
readers.touch(
|
|
84994
|
+
readers.touch(key, existing);
|
|
84740
84995
|
return existing;
|
|
84741
84996
|
}
|
|
84742
|
-
return await readers.prepare(
|
|
84997
|
+
return await readers.prepare(key, async () => {
|
|
84743
84998
|
if (existing !== void 0) {
|
|
84744
|
-
await this.retire(readers,
|
|
84999
|
+
await this.retire(readers, key, existing);
|
|
84745
85000
|
}
|
|
84746
|
-
const readerId = randomUUID14();
|
|
84747
85001
|
const runtime = await this.#processes.startRetained(
|
|
84748
|
-
signal,
|
|
84749
|
-
() => AcpQuerySession.start(
|
|
85002
|
+
query.signal,
|
|
85003
|
+
() => AcpQuerySession.start(query, this.#store, this.#connector),
|
|
84750
85004
|
{
|
|
84751
|
-
isBusy: () => readers.isBusy(
|
|
84752
|
-
retire: (runtime2) => this.retire(readers,
|
|
84753
|
-
retireIdle: (runtime2) => this.retire(readers,
|
|
85005
|
+
isBusy: () => readers.isBusy(key),
|
|
85006
|
+
retire: (runtime2) => this.retire(readers, key, runtime2),
|
|
85007
|
+
retireIdle: (runtime2) => this.retire(readers, key, runtime2)
|
|
84754
85008
|
}
|
|
84755
85009
|
);
|
|
84756
|
-
readers.retain(
|
|
85010
|
+
readers.retain(key, runtime);
|
|
84757
85011
|
return runtime;
|
|
84758
85012
|
});
|
|
84759
85013
|
}
|
|
84760
|
-
#use = async (
|
|
85014
|
+
#use = async (query, operation) => {
|
|
84761
85015
|
const agent = this.#agent;
|
|
85016
|
+
const scoped = { ...query, agent };
|
|
84762
85017
|
let readers = this.#processesByAgent.get(agent);
|
|
84763
85018
|
if (readers === void 0) {
|
|
84764
85019
|
readers = new RetainedAgentProcesses({
|
|
@@ -84768,35 +85023,38 @@ var init_query_processes = __esm({
|
|
|
84768
85023
|
this.#processesByAgent.set(agent, readers);
|
|
84769
85024
|
}
|
|
84770
85025
|
const current = readers;
|
|
84771
|
-
return await current.use(
|
|
85026
|
+
return await current.use(
|
|
85027
|
+
nativeSessionQueryKey(scoped),
|
|
85028
|
+
async () => await operation(await this.#ensure(current, scoped))
|
|
85029
|
+
);
|
|
84772
85030
|
};
|
|
84773
|
-
capabilities = async (
|
|
84774
|
-
listNativeSessions = async (
|
|
84775
|
-
previewSessionEvents = async (
|
|
84776
|
-
signal.throwIfAborted();
|
|
84777
|
-
const
|
|
84778
|
-
const { nativeSessionId, eventLimit, cursor
|
|
85031
|
+
capabilities = async (query) => await this.#use(query, async (runtime) => runtime.capabilities());
|
|
85032
|
+
listNativeSessions = async (query, cursor) => await this.#use(query, async (runtime) => await runtime.listNativeSessions(cursor, query.signal));
|
|
85033
|
+
previewSessionEvents = async (query, request) => {
|
|
85034
|
+
query.signal.throwIfAborted();
|
|
85035
|
+
const scoped = { ...query, agent: this.#agent };
|
|
85036
|
+
const { nativeSessionId, eventLimit, cursor } = request;
|
|
85037
|
+
const key = nativeSessionPreviewKey(nativeSessionQueryKey(scoped), nativeSessionId);
|
|
84779
85038
|
if (cursor !== null) {
|
|
84780
|
-
const preview = this.#eventPreviewsBySession.get(
|
|
85039
|
+
const preview = this.#eventPreviewsBySession.get(key);
|
|
84781
85040
|
if (preview === void 0 || preview.nativeSessionId !== nativeSessionId) {
|
|
84782
85041
|
throw new Error("The native event cursor is invalid");
|
|
84783
85042
|
}
|
|
84784
|
-
return preview.store.page(
|
|
85043
|
+
return preview.store.page(nativeSessionId, eventLimit, cursor);
|
|
84785
85044
|
}
|
|
84786
85045
|
const store = new MemorySessionEventStore();
|
|
84787
|
-
|
|
84788
|
-
|
|
84789
|
-
this.#eventPreviewsBySession.set(sessionId, { nativeSessionId, store });
|
|
85046
|
+
this.#eventPreviewsBySession.get(key)?.store.close();
|
|
85047
|
+
this.#eventPreviewsBySession.set(key, { nativeSessionId, store });
|
|
84790
85048
|
try {
|
|
84791
85049
|
return await this.#processes.runTransient(
|
|
84792
|
-
signal,
|
|
84793
|
-
|
|
84794
|
-
|
|
84795
|
-
|
|
85050
|
+
query.signal,
|
|
85051
|
+
() => AcpQuerySession.start(scoped, store, this.#connector),
|
|
85052
|
+
(runtime) => runtime.previewEvents(nativeSessionId, eventLimit, query.signal),
|
|
85053
|
+
(runtime) => runtime.closeProcess()
|
|
84796
85054
|
);
|
|
84797
85055
|
} catch (error62) {
|
|
84798
|
-
if (this.#eventPreviewsBySession.get(
|
|
84799
|
-
this.#eventPreviewsBySession.delete(
|
|
85056
|
+
if (this.#eventPreviewsBySession.get(key)?.store === store) {
|
|
85057
|
+
this.#eventPreviewsBySession.delete(key);
|
|
84800
85058
|
}
|
|
84801
85059
|
store.close();
|
|
84802
85060
|
throw error62;
|
|
@@ -84805,7 +85063,7 @@ var init_query_processes = __esm({
|
|
|
84805
85063
|
close = async () => {
|
|
84806
85064
|
await Promise.all(
|
|
84807
85065
|
[...this.#processesByAgent.values()].flatMap(
|
|
84808
|
-
(readers) => readers.entries().map(async ([
|
|
85066
|
+
(readers) => readers.entries().map(async ([key, runtime]) => await this.retire(readers, key, runtime))
|
|
84809
85067
|
)
|
|
84810
85068
|
);
|
|
84811
85069
|
this.#processesByAgent.clear();
|
|
@@ -84820,39 +85078,104 @@ var init_query_processes = __esm({
|
|
|
84820
85078
|
});
|
|
84821
85079
|
|
|
84822
85080
|
// src/engine/acp/adapter/claude/adapter.ts
|
|
85081
|
+
import { methods as methods13 } from "@agentclientprotocol/sdk";
|
|
84823
85082
|
var ClaudeAdapter;
|
|
84824
85083
|
var init_adapter = __esm({
|
|
84825
85084
|
"src/engine/acp/adapter/claude/adapter.ts"() {
|
|
84826
85085
|
"use strict";
|
|
84827
85086
|
init_run_cleanup();
|
|
84828
|
-
|
|
85087
|
+
init_native_session();
|
|
85088
|
+
init_execution_connections();
|
|
85089
|
+
init_lifecycle_output();
|
|
84829
85090
|
init_native_session_lookup();
|
|
84830
85091
|
init_query_processes();
|
|
84831
85092
|
init_session_events();
|
|
84832
85093
|
ClaudeAdapter = class {
|
|
84833
85094
|
#queryProcesses;
|
|
84834
85095
|
#connector;
|
|
84835
|
-
#
|
|
85096
|
+
#executionConnections;
|
|
84836
85097
|
constructor(agent, dependencies) {
|
|
84837
85098
|
this.#connector = new AcpSessionConnector(dependencies.contentExternalizer);
|
|
84838
|
-
this.#
|
|
85099
|
+
this.#executionConnections = new AcpExecutionConnections(dependencies.contentExternalizer);
|
|
84839
85100
|
this.#queryProcesses = new AgentQueryProcesses(agent, dependencies.processes, this.#connector);
|
|
84840
85101
|
}
|
|
84841
85102
|
refreshAgent = (agent) => this.#queryProcesses.refreshAgent(agent);
|
|
84842
|
-
getCapabilities = (
|
|
84843
|
-
|
|
84844
|
-
|
|
84845
|
-
|
|
84846
|
-
|
|
84847
|
-
|
|
84848
|
-
|
|
84849
|
-
|
|
84850
|
-
|
|
84851
|
-
|
|
84852
|
-
|
|
85103
|
+
getCapabilities = async (query) => await this.#queryProcesses.capabilities(query);
|
|
85104
|
+
createSession = (params) => this.#executionConnections.withConnection(params, async (execution, signal) => {
|
|
85105
|
+
const { connection } = execution;
|
|
85106
|
+
const response = await connection.race(
|
|
85107
|
+
connection.connection.agent.request(methods13.agent.session.new, sessionWorkspace(params.scope), {
|
|
85108
|
+
cancellationSignal: signal
|
|
85109
|
+
}),
|
|
85110
|
+
"ACP agent exited while starting a session",
|
|
85111
|
+
signal
|
|
85112
|
+
);
|
|
85113
|
+
const nativeSessionId = createdNativeSessionId(response);
|
|
85114
|
+
this.#executionConnections.bind(execution, nativeSessionId);
|
|
85115
|
+
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
85116
|
+
});
|
|
85117
|
+
forkSession = (params) => this.#executionConnections.withConnection(params, async (execution, signal) => {
|
|
85118
|
+
const { connection } = execution;
|
|
85119
|
+
const response = await connection.race(
|
|
85120
|
+
connection.connection.agent.request(
|
|
85121
|
+
methods13.agent.session.fork,
|
|
85122
|
+
{
|
|
85123
|
+
...sessionWorkspace(params.scope),
|
|
85124
|
+
sessionId: nativeSessionIdSchema.parse(params.sourceNativeSessionId)
|
|
85125
|
+
},
|
|
85126
|
+
{ cancellationSignal: signal }
|
|
85127
|
+
),
|
|
85128
|
+
"ACP agent exited while forking a session",
|
|
85129
|
+
signal
|
|
85130
|
+
);
|
|
85131
|
+
const nativeSessionId = createdNativeSessionId(response);
|
|
85132
|
+
this.#executionConnections.bind(execution, nativeSessionId);
|
|
85133
|
+
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
85134
|
+
});
|
|
85135
|
+
openSession = (params) => this.#executionConnections.withConnection(params, async (execution, signal) => {
|
|
85136
|
+
const { connection } = execution;
|
|
85137
|
+
const nativeSessionId = nativeSessionIdSchema.parse(params.nativeSessionId);
|
|
85138
|
+
this.#executionConnections.bind(execution, nativeSessionId);
|
|
85139
|
+
const response = await connection.race(
|
|
85140
|
+
connection.connection.agent.request(
|
|
85141
|
+
methods13.agent.session.resume,
|
|
85142
|
+
{ ...sessionWorkspace(params.scope), sessionId: nativeSessionId },
|
|
85143
|
+
{ cancellationSignal: signal }
|
|
85144
|
+
),
|
|
85145
|
+
"ACP agent exited while resuming a session",
|
|
85146
|
+
signal
|
|
85147
|
+
);
|
|
85148
|
+
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
85149
|
+
});
|
|
85150
|
+
openSessionWithReplay = (params) => this.#executionConnections.withConnection(params, async (execution, signal) => {
|
|
85151
|
+
const { connection } = execution;
|
|
85152
|
+
const nativeSessionId = nativeSessionIdSchema.parse(params.nativeSessionId);
|
|
85153
|
+
this.#executionConnections.bind(execution, nativeSessionId);
|
|
85154
|
+
const response = await connection.race(
|
|
85155
|
+
connection.connection.agent.request(
|
|
85156
|
+
methods13.agent.session.load,
|
|
85157
|
+
{ ...sessionWorkspace(params.scope), sessionId: nativeSessionId },
|
|
85158
|
+
{ cancellationSignal: signal }
|
|
85159
|
+
),
|
|
85160
|
+
"ACP agent exited while loading a session",
|
|
85161
|
+
signal
|
|
85162
|
+
);
|
|
85163
|
+
await connection.race(connection.events.drained(), "ACP agent exited while loading a session", signal);
|
|
85164
|
+
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
85165
|
+
});
|
|
85166
|
+
cancel = (...args) => this.#executionConnections.cancel(...args);
|
|
85167
|
+
closeSession = (...args) => this.#executionConnections.closeSession(...args);
|
|
85168
|
+
releaseSession = (params) => this.#executionConnections.releaseSession(params);
|
|
85169
|
+
prompt = (...args) => this.#executionConnections.prompt(...args);
|
|
85170
|
+
steer = (...args) => this.#executionConnections.steer(...args);
|
|
85171
|
+
renameSession = (...args) => this.#executionConnections.renameSession(...args);
|
|
85172
|
+
configureSession = (...args) => this.#executionConnections.configureSession(...args);
|
|
85173
|
+
listSessions = async ({ query, cursor }) => await this.#queryProcesses.listNativeSessions(query, cursor);
|
|
85174
|
+
findSession = ({ query, nativeSessionId, budget }) => findNativeSession(this.listSessions, query, nativeSessionId, budget);
|
|
85175
|
+
readSessionHistory = async ({ query, request }) => await this.#queryProcesses.previewSessionEvents(query, request);
|
|
84853
85176
|
close = async () => await runCleanup(
|
|
84854
85177
|
() => this.#queryProcesses.close(),
|
|
84855
|
-
() => this.#
|
|
85178
|
+
() => this.#executionConnections.close()
|
|
84856
85179
|
);
|
|
84857
85180
|
};
|
|
84858
85181
|
}
|
|
@@ -90768,6 +91091,7 @@ var init_tool_event = __esm({
|
|
|
90768
91091
|
|
|
90769
91092
|
// src/engine/acp/adapter/codex/adapter.ts
|
|
90770
91093
|
import { createHash as createHash5 } from "node:crypto";
|
|
91094
|
+
import { methods as methods14 } from "@agentclientprotocol/sdk";
|
|
90771
91095
|
var CodexAdapter;
|
|
90772
91096
|
var init_adapter2 = __esm({
|
|
90773
91097
|
"src/engine/acp/adapter/codex/adapter.ts"() {
|
|
@@ -90779,7 +91103,8 @@ var init_adapter2 = __esm({
|
|
|
90779
91103
|
init_app_server_client();
|
|
90780
91104
|
init_history2();
|
|
90781
91105
|
init_native_session();
|
|
90782
|
-
|
|
91106
|
+
init_execution_connections();
|
|
91107
|
+
init_lifecycle_output();
|
|
90783
91108
|
init_native_session_lookup();
|
|
90784
91109
|
init_preview_event_cache();
|
|
90785
91110
|
init_query_processes();
|
|
@@ -90789,7 +91114,7 @@ var init_adapter2 = __esm({
|
|
|
90789
91114
|
#agent;
|
|
90790
91115
|
#queryProcesses;
|
|
90791
91116
|
#connector;
|
|
90792
|
-
#
|
|
91117
|
+
#executionConnections;
|
|
90793
91118
|
#dependencies;
|
|
90794
91119
|
#contentExternalizer;
|
|
90795
91120
|
#previewCache = null;
|
|
@@ -90805,37 +91130,112 @@ var init_adapter2 = __esm({
|
|
|
90805
91130
|
}
|
|
90806
91131
|
};
|
|
90807
91132
|
this.#connector = new AcpSessionConnector(this.#contentExternalizer, fitCodexToolEvent);
|
|
90808
|
-
this.#
|
|
91133
|
+
this.#executionConnections = new AcpExecutionConnections(this.#contentExternalizer, fitCodexToolEvent);
|
|
90809
91134
|
this.#queryProcesses = new AgentQueryProcesses(agent, dependencies.processes, this.#connector);
|
|
90810
91135
|
}
|
|
90811
91136
|
refreshAgent = (agent) => {
|
|
90812
91137
|
this.#agent = agent;
|
|
90813
91138
|
this.#queryProcesses.refreshAgent(agent);
|
|
90814
91139
|
};
|
|
90815
|
-
getCapabilities = (
|
|
90816
|
-
|
|
90817
|
-
|
|
90818
|
-
|
|
91140
|
+
getCapabilities = async (query) => await this.#queryProcesses.capabilities(query);
|
|
91141
|
+
#executionParams = (params) => {
|
|
91142
|
+
const externalize = params.scope.externalizeUpdate;
|
|
91143
|
+
return externalize === void 0 ? params : {
|
|
91144
|
+
...params,
|
|
91145
|
+
scope: {
|
|
91146
|
+
...params.scope,
|
|
91147
|
+
externalizeUpdate: (update, signal) => externalize(prepareCodexToolUpdate(update), signal)
|
|
91148
|
+
}
|
|
91149
|
+
};
|
|
91150
|
+
};
|
|
91151
|
+
createSession = (params) => this.#executionConnections.withConnection(this.#executionParams(params), async (execution, signal) => {
|
|
91152
|
+
const { connection } = execution;
|
|
91153
|
+
const response = await connection.race(
|
|
91154
|
+
connection.connection.agent.request(methods14.agent.session.new, sessionWorkspace(params.scope), {
|
|
91155
|
+
cancellationSignal: signal
|
|
91156
|
+
}),
|
|
91157
|
+
"ACP agent exited while starting a session",
|
|
91158
|
+
signal
|
|
91159
|
+
);
|
|
91160
|
+
const nativeSessionId = createdNativeSessionId(response);
|
|
91161
|
+
this.#executionConnections.bind(execution, nativeSessionId);
|
|
91162
|
+
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
91163
|
+
});
|
|
91164
|
+
forkSession = (params) => this.#executionConnections.withConnection(this.#executionParams(params), async (execution, signal) => {
|
|
91165
|
+
const { connection } = execution;
|
|
91166
|
+
const response = await connection.race(
|
|
91167
|
+
connection.connection.agent.request(
|
|
91168
|
+
methods14.agent.session.fork,
|
|
91169
|
+
{
|
|
91170
|
+
...sessionWorkspace(params.scope),
|
|
91171
|
+
sessionId: nativeSessionIdSchema.parse(params.sourceNativeSessionId)
|
|
91172
|
+
},
|
|
91173
|
+
{ cancellationSignal: signal }
|
|
91174
|
+
),
|
|
91175
|
+
"ACP agent exited while forking a session",
|
|
91176
|
+
signal
|
|
91177
|
+
);
|
|
91178
|
+
const nativeSessionId = createdNativeSessionId(response);
|
|
91179
|
+
this.#executionConnections.bind(execution, nativeSessionId);
|
|
91180
|
+
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
91181
|
+
});
|
|
91182
|
+
openSession = (params) => this.#executionConnections.withConnection(this.#executionParams(params), async (execution, signal) => {
|
|
91183
|
+
const { connection } = execution;
|
|
91184
|
+
const nativeSessionId = nativeSessionIdSchema.parse(params.nativeSessionId);
|
|
91185
|
+
this.#executionConnections.bind(execution, nativeSessionId);
|
|
91186
|
+
const response = await connection.race(
|
|
91187
|
+
connection.connection.agent.request(
|
|
91188
|
+
methods14.agent.session.resume,
|
|
91189
|
+
{ ...sessionWorkspace(params.scope), sessionId: nativeSessionId },
|
|
91190
|
+
{ cancellationSignal: signal }
|
|
91191
|
+
),
|
|
91192
|
+
"ACP agent exited while resuming a session",
|
|
91193
|
+
signal
|
|
91194
|
+
);
|
|
91195
|
+
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
91196
|
+
});
|
|
91197
|
+
openSessionWithReplay = (params) => this.#executionConnections.withConnection(this.#executionParams(params), async (execution, signal) => {
|
|
91198
|
+
const { connection } = execution;
|
|
91199
|
+
const nativeSessionId = nativeSessionIdSchema.parse(params.nativeSessionId);
|
|
91200
|
+
this.#executionConnections.bind(execution, nativeSessionId);
|
|
91201
|
+
const response = await connection.race(
|
|
91202
|
+
connection.connection.agent.request(
|
|
91203
|
+
methods14.agent.session.load,
|
|
91204
|
+
{ ...sessionWorkspace(params.scope), sessionId: nativeSessionId },
|
|
91205
|
+
{ cancellationSignal: signal }
|
|
91206
|
+
),
|
|
91207
|
+
"ACP agent exited while loading a session",
|
|
91208
|
+
signal
|
|
91209
|
+
);
|
|
91210
|
+
await connection.race(connection.events.drained(), "ACP agent exited while loading a session", signal);
|
|
91211
|
+
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
91212
|
+
});
|
|
91213
|
+
cancel = async (params) => {
|
|
91214
|
+
await this.#executionConnections.closeSession(params);
|
|
90819
91215
|
return "closed";
|
|
90820
91216
|
};
|
|
90821
|
-
closeSession = (...args) => this.#
|
|
90822
|
-
|
|
90823
|
-
|
|
90824
|
-
|
|
90825
|
-
|
|
90826
|
-
|
|
90827
|
-
|
|
91217
|
+
closeSession = (...args) => this.#executionConnections.closeSession(...args);
|
|
91218
|
+
releaseSession = (params) => this.#executionConnections.releaseSession(params);
|
|
91219
|
+
prompt = (...args) => this.#executionConnections.prompt(...args);
|
|
91220
|
+
steer = (...args) => this.#executionConnections.steer(...args);
|
|
91221
|
+
renameSession = (...args) => this.#executionConnections.renameSession(...args);
|
|
91222
|
+
configureSession = (...args) => this.#executionConnections.configureSession(...args);
|
|
91223
|
+
listSessions = async ({ query, cursor }) => await this.#queryProcesses.listNativeSessions(query, cursor);
|
|
91224
|
+
findSession = ({ query, nativeSessionId, budget }) => findNativeSession(this.listSessions, query, nativeSessionId, budget);
|
|
90828
91225
|
close = async () => {
|
|
90829
91226
|
await runCleanup(
|
|
90830
91227
|
() => this.#queryProcesses.close(),
|
|
90831
|
-
() => this.#
|
|
91228
|
+
() => this.#executionConnections.close(),
|
|
90832
91229
|
() => this.#previewCache?.close()
|
|
90833
91230
|
);
|
|
90834
91231
|
};
|
|
90835
|
-
readSessionHistory = async (
|
|
90836
|
-
|
|
90837
|
-
|
|
90838
|
-
|
|
91232
|
+
readSessionHistory = async ({
|
|
91233
|
+
query,
|
|
91234
|
+
request
|
|
91235
|
+
}) => {
|
|
91236
|
+
const { agent, cwd } = query;
|
|
91237
|
+
const signal = AbortSignal.any([query.signal, AbortSignal.timeout(6e4)]);
|
|
91238
|
+
const sessionId = request.nativeSessionId;
|
|
90839
91239
|
signal.throwIfAborted();
|
|
90840
91240
|
nativeSessionIdSchema.parse(request.nativeSessionId);
|
|
90841
91241
|
if (agent.id !== "codex") {
|
|
@@ -90886,7 +91286,7 @@ var init_adapter2 = __esm({
|
|
|
90886
91286
|
client2,
|
|
90887
91287
|
request.nativeSessionId,
|
|
90888
91288
|
async (update) => {
|
|
90889
|
-
const externalized = await this.#contentExternalizer.update(sessionId, update, signal);
|
|
91289
|
+
const externalized = query.externalizeUpdate === void 0 ? await this.#contentExternalizer.update(sessionId, update, signal) : await query.externalizeUpdate(prepareCodexToolUpdate(update), signal);
|
|
90890
91290
|
for (const event of externalized.events) {
|
|
90891
91291
|
events.push({
|
|
90892
91292
|
type: "acp",
|
|
@@ -90908,39 +91308,104 @@ var init_adapter2 = __esm({
|
|
|
90908
91308
|
});
|
|
90909
91309
|
|
|
90910
91310
|
// src/engine/acp/adapter/pi/adapter.ts
|
|
91311
|
+
import { methods as methods15 } from "@agentclientprotocol/sdk";
|
|
90911
91312
|
var PiAdapter;
|
|
90912
91313
|
var init_adapter3 = __esm({
|
|
90913
91314
|
"src/engine/acp/adapter/pi/adapter.ts"() {
|
|
90914
91315
|
"use strict";
|
|
90915
91316
|
init_run_cleanup();
|
|
90916
|
-
|
|
91317
|
+
init_native_session();
|
|
91318
|
+
init_execution_connections();
|
|
91319
|
+
init_lifecycle_output();
|
|
90917
91320
|
init_native_session_lookup();
|
|
90918
91321
|
init_query_processes();
|
|
90919
91322
|
init_session_events();
|
|
90920
91323
|
PiAdapter = class {
|
|
90921
91324
|
#queryProcesses;
|
|
90922
91325
|
#connector;
|
|
90923
|
-
#
|
|
91326
|
+
#executionConnections;
|
|
90924
91327
|
constructor(agent, dependencies) {
|
|
90925
91328
|
this.#connector = new AcpSessionConnector(dependencies.contentExternalizer);
|
|
90926
|
-
this.#
|
|
91329
|
+
this.#executionConnections = new AcpExecutionConnections(dependencies.contentExternalizer);
|
|
90927
91330
|
this.#queryProcesses = new AgentQueryProcesses(agent, dependencies.processes, this.#connector);
|
|
90928
91331
|
}
|
|
90929
91332
|
refreshAgent = (agent) => this.#queryProcesses.refreshAgent(agent);
|
|
90930
|
-
getCapabilities = (
|
|
90931
|
-
|
|
90932
|
-
|
|
90933
|
-
|
|
90934
|
-
|
|
90935
|
-
|
|
90936
|
-
|
|
90937
|
-
|
|
90938
|
-
|
|
90939
|
-
|
|
90940
|
-
|
|
91333
|
+
getCapabilities = async (query) => await this.#queryProcesses.capabilities(query);
|
|
91334
|
+
createSession = (params) => this.#executionConnections.withConnection(params, async (execution, signal) => {
|
|
91335
|
+
const { connection } = execution;
|
|
91336
|
+
const response = await connection.race(
|
|
91337
|
+
connection.connection.agent.request(methods15.agent.session.new, sessionWorkspace(params.scope), {
|
|
91338
|
+
cancellationSignal: signal
|
|
91339
|
+
}),
|
|
91340
|
+
"ACP agent exited while starting a session",
|
|
91341
|
+
signal
|
|
91342
|
+
);
|
|
91343
|
+
const nativeSessionId = createdNativeSessionId(response);
|
|
91344
|
+
this.#executionConnections.bind(execution, nativeSessionId);
|
|
91345
|
+
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
91346
|
+
});
|
|
91347
|
+
forkSession = (params) => this.#executionConnections.withConnection(params, async (execution, signal) => {
|
|
91348
|
+
const { connection } = execution;
|
|
91349
|
+
const response = await connection.race(
|
|
91350
|
+
connection.connection.agent.request(
|
|
91351
|
+
methods15.agent.session.fork,
|
|
91352
|
+
{
|
|
91353
|
+
...sessionWorkspace(params.scope),
|
|
91354
|
+
sessionId: nativeSessionIdSchema.parse(params.sourceNativeSessionId)
|
|
91355
|
+
},
|
|
91356
|
+
{ cancellationSignal: signal }
|
|
91357
|
+
),
|
|
91358
|
+
"ACP agent exited while forking a session",
|
|
91359
|
+
signal
|
|
91360
|
+
);
|
|
91361
|
+
const nativeSessionId = createdNativeSessionId(response);
|
|
91362
|
+
this.#executionConnections.bind(execution, nativeSessionId);
|
|
91363
|
+
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
91364
|
+
});
|
|
91365
|
+
openSession = (params) => this.#executionConnections.withConnection(params, async (execution, signal) => {
|
|
91366
|
+
const { connection } = execution;
|
|
91367
|
+
const nativeSessionId = nativeSessionIdSchema.parse(params.nativeSessionId);
|
|
91368
|
+
this.#executionConnections.bind(execution, nativeSessionId);
|
|
91369
|
+
const response = await connection.race(
|
|
91370
|
+
connection.connection.agent.request(
|
|
91371
|
+
methods15.agent.session.resume,
|
|
91372
|
+
{ ...sessionWorkspace(params.scope), sessionId: nativeSessionId },
|
|
91373
|
+
{ cancellationSignal: signal }
|
|
91374
|
+
),
|
|
91375
|
+
"ACP agent exited while resuming a session",
|
|
91376
|
+
signal
|
|
91377
|
+
);
|
|
91378
|
+
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
91379
|
+
});
|
|
91380
|
+
openSessionWithReplay = (params) => this.#executionConnections.withConnection(params, async (execution, signal) => {
|
|
91381
|
+
const { connection } = execution;
|
|
91382
|
+
const nativeSessionId = nativeSessionIdSchema.parse(params.nativeSessionId);
|
|
91383
|
+
this.#executionConnections.bind(execution, nativeSessionId);
|
|
91384
|
+
const response = await connection.race(
|
|
91385
|
+
connection.connection.agent.request(
|
|
91386
|
+
methods15.agent.session.load,
|
|
91387
|
+
{ ...sessionWorkspace(params.scope), sessionId: nativeSessionId },
|
|
91388
|
+
{ cancellationSignal: signal }
|
|
91389
|
+
),
|
|
91390
|
+
"ACP agent exited while loading a session",
|
|
91391
|
+
signal
|
|
91392
|
+
);
|
|
91393
|
+
await connection.race(connection.events.drained(), "ACP agent exited while loading a session", signal);
|
|
91394
|
+
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
91395
|
+
});
|
|
91396
|
+
cancel = (...args) => this.#executionConnections.cancel(...args);
|
|
91397
|
+
closeSession = (...args) => this.#executionConnections.closeSession(...args);
|
|
91398
|
+
releaseSession = (params) => this.#executionConnections.releaseSession(params);
|
|
91399
|
+
prompt = (...args) => this.#executionConnections.prompt(...args);
|
|
91400
|
+
steer = (...args) => this.#executionConnections.steer(...args);
|
|
91401
|
+
renameSession = (...args) => this.#executionConnections.renameSession(...args);
|
|
91402
|
+
configureSession = (...args) => this.#executionConnections.configureSession(...args);
|
|
91403
|
+
listSessions = async ({ query, cursor }) => await this.#queryProcesses.listNativeSessions(query, cursor);
|
|
91404
|
+
findSession = ({ query, nativeSessionId, budget }) => findNativeSession(this.listSessions, query, nativeSessionId, budget);
|
|
91405
|
+
readSessionHistory = async ({ query, request }) => await this.#queryProcesses.previewSessionEvents(query, request);
|
|
90941
91406
|
close = async () => await runCleanup(
|
|
90942
91407
|
() => this.#queryProcesses.close(),
|
|
90943
|
-
() => this.#
|
|
91408
|
+
() => this.#executionConnections.close()
|
|
90944
91409
|
);
|
|
90945
91410
|
};
|
|
90946
91411
|
}
|
|
@@ -91258,10 +91723,12 @@ var init_content_externalizer = __esm({
|
|
|
91258
91723
|
|
|
91259
91724
|
// src/engine/agent/runtime-agents.ts
|
|
91260
91725
|
function createRuntimeAdapterRegistry(adapters, processes, externalize, linkedResources) {
|
|
91261
|
-
|
|
91262
|
-
|
|
91263
|
-
|
|
91264
|
-
|
|
91726
|
+
const contentExternalizer = new AcpContentExternalizer(externalize, linkedResources);
|
|
91727
|
+
const externalizeSessionUpdate = (sessionId, update, signal) => contentExternalizer.update(sessionId, update, signal);
|
|
91728
|
+
return {
|
|
91729
|
+
adapters: new AdapterRegistry(adapters, { processes, contentExternalizer }),
|
|
91730
|
+
externalizeSessionUpdate
|
|
91731
|
+
};
|
|
91265
91732
|
}
|
|
91266
91733
|
var RuntimeAgentDependencies;
|
|
91267
91734
|
var init_runtime_agents = __esm({
|
|
@@ -93525,7 +93992,6 @@ var init_agent_turn = __esm({
|
|
|
93525
93992
|
});
|
|
93526
93993
|
|
|
93527
93994
|
// src/engine/session/live/session-restore.ts
|
|
93528
|
-
import { methods as methods13 } from "@agentclientprotocol/sdk";
|
|
93529
93995
|
function hasMethodNotFoundCode(cause) {
|
|
93530
93996
|
const visited = /* @__PURE__ */ new Set();
|
|
93531
93997
|
let current = cause;
|
|
@@ -93543,7 +94009,6 @@ async function restoreSession(session, signal, recovery, origin) {
|
|
|
93543
94009
|
if (origin !== void 0) {
|
|
93544
94010
|
session.setSessionTitle(origin.title);
|
|
93545
94011
|
}
|
|
93546
|
-
await session.initializeAgent(signal);
|
|
93547
94012
|
let stored = session.metrics.measureSync(
|
|
93548
94013
|
"session-state-read",
|
|
93549
94014
|
() => origin?.kind === "import" ? new FoundStoredSession(
|
|
@@ -93563,7 +94028,7 @@ async function restoreSession(session, signal, recovery, origin) {
|
|
|
93563
94028
|
stored = session.metrics.measureSync("session-state-read", () => session.store.read(session.sessionId));
|
|
93564
94029
|
}
|
|
93565
94030
|
const forkSource = origin?.kind === "fork" ? session.store.findNative(session.agentId, origin.nativeSessionId)[0] : void 0;
|
|
93566
|
-
let
|
|
94031
|
+
let opened;
|
|
93567
94032
|
if (origin?.kind === "fork") {
|
|
93568
94033
|
if (!session.capabilities.unstableForkSession) {
|
|
93569
94034
|
throw new AcpExecutionError(
|
|
@@ -93581,22 +94046,9 @@ async function restoreSession(session, signal, recovery, origin) {
|
|
|
93581
94046
|
}
|
|
93582
94047
|
const forked = await session.metrics.measure(
|
|
93583
94048
|
"session-fork",
|
|
93584
|
-
async () => await session.
|
|
93585
|
-
session.agentRequest(
|
|
93586
|
-
methods13.agent.session.fork,
|
|
93587
|
-
{
|
|
93588
|
-
sessionId: nativeSessionIdSchema.parse(origin.nativeSessionId),
|
|
93589
|
-
cwd: session.cwd,
|
|
93590
|
-
additionalDirectories: [...session.additionalDirectories],
|
|
93591
|
-
mcpServers: []
|
|
93592
|
-
},
|
|
93593
|
-
{ cancellationSignal: signal }
|
|
93594
|
-
),
|
|
93595
|
-
"ACP agent exited while forking a session",
|
|
93596
|
-
signal
|
|
93597
|
-
)
|
|
94049
|
+
async () => await session.forkSession(origin.nativeSessionId, signal)
|
|
93598
94050
|
);
|
|
93599
|
-
session.selectNativeSession(forked.
|
|
94051
|
+
session.selectNativeSession(forked.nativeSessionId);
|
|
93600
94052
|
if (session.nativeSessionId() === origin.nativeSessionId || session.store.findNative(session.agentId, session.nativeSessionId()).length > 0) {
|
|
93601
94053
|
throw new AcpExecutionError(
|
|
93602
94054
|
"The Agent did not create an independent fork",
|
|
@@ -93609,7 +94061,7 @@ async function restoreSession(session, signal, recovery, origin) {
|
|
|
93609
94061
|
if (recovery.kind === "execution-only") {
|
|
93610
94062
|
session.startExecutionOnlyCapture();
|
|
93611
94063
|
}
|
|
93612
|
-
|
|
94064
|
+
opened = forked;
|
|
93613
94065
|
} else if (stored instanceof FoundStoredSession && stored.session.agentId === session.agentId && stored.session.cwd === session.cwd && arraysEqual(stored.session.additionalDirectories, session.additionalDirectories)) {
|
|
93614
94066
|
session.selectNativeSession(stored.session.nativeSessionId);
|
|
93615
94067
|
session.setPrompted(stored.session.prompted);
|
|
@@ -93623,29 +94075,13 @@ async function restoreSession(session, signal, recovery, origin) {
|
|
|
93623
94075
|
"native_history_unsupported"
|
|
93624
94076
|
);
|
|
93625
94077
|
}
|
|
93626
|
-
|
|
94078
|
+
opened = await session.metrics.measure(
|
|
93627
94079
|
"session-load",
|
|
93628
|
-
async () =>
|
|
94080
|
+
async () => await session.openSessionWithReplay(signal)
|
|
93629
94081
|
);
|
|
93630
94082
|
} else if (recovery.kind === "execution-only") {
|
|
93631
94083
|
try {
|
|
93632
|
-
|
|
93633
|
-
"session-resume",
|
|
93634
|
-
async () => await session.race(
|
|
93635
|
-
session.agentRequest(
|
|
93636
|
-
methods13.agent.session.resume,
|
|
93637
|
-
{
|
|
93638
|
-
additionalDirectories: [...session.additionalDirectories],
|
|
93639
|
-
cwd: session.cwd,
|
|
93640
|
-
mcpServers: [],
|
|
93641
|
-
sessionId: session.nativeSessionId()
|
|
93642
|
-
},
|
|
93643
|
-
{ cancellationSignal: signal }
|
|
93644
|
-
),
|
|
93645
|
-
"ACP agent exited while resuming a session",
|
|
93646
|
-
signal
|
|
93647
|
-
)
|
|
93648
|
-
);
|
|
94084
|
+
opened = await session.metrics.measure("session-resume", async () => await session.openSession(signal));
|
|
93649
94085
|
} catch (cause) {
|
|
93650
94086
|
signal.throwIfAborted();
|
|
93651
94087
|
if (cause instanceof AcpExecutionError && !hasMethodNotFoundCode(cause)) {
|
|
@@ -93659,27 +94095,11 @@ async function restoreSession(session, signal, recovery, origin) {
|
|
|
93659
94095
|
}
|
|
93660
94096
|
session.startExecutionOnlyCapture();
|
|
93661
94097
|
} else if (session.capabilities.resumeSession) {
|
|
93662
|
-
|
|
93663
|
-
"session-resume",
|
|
93664
|
-
async () => await session.race(
|
|
93665
|
-
session.agentRequest(
|
|
93666
|
-
methods13.agent.session.resume,
|
|
93667
|
-
{
|
|
93668
|
-
additionalDirectories: [...session.additionalDirectories],
|
|
93669
|
-
cwd: session.cwd,
|
|
93670
|
-
mcpServers: [],
|
|
93671
|
-
sessionId: session.nativeSessionId()
|
|
93672
|
-
},
|
|
93673
|
-
{ cancellationSignal: signal }
|
|
93674
|
-
),
|
|
93675
|
-
"ACP agent exited while resuming a session",
|
|
93676
|
-
signal
|
|
93677
|
-
)
|
|
93678
|
-
);
|
|
94098
|
+
opened = await session.metrics.measure("session-resume", async () => await session.openSession(signal));
|
|
93679
94099
|
} else if (session.capabilities.loadSession) {
|
|
93680
|
-
|
|
94100
|
+
opened = await session.metrics.measure(
|
|
93681
94101
|
"session-load",
|
|
93682
|
-
async () =>
|
|
94102
|
+
async () => await session.openSessionWithReplay(signal)
|
|
93683
94103
|
);
|
|
93684
94104
|
} else {
|
|
93685
94105
|
throw new AcpExecutionError(
|
|
@@ -93699,37 +94119,20 @@ async function restoreSession(session, signal, recovery, origin) {
|
|
|
93699
94119
|
}
|
|
93700
94120
|
session.store.remove(session.sessionId);
|
|
93701
94121
|
}
|
|
93702
|
-
const created = await session.metrics.measure(
|
|
93703
|
-
|
|
93704
|
-
async () => await session.race(
|
|
93705
|
-
session.agentRequest(
|
|
93706
|
-
methods13.agent.session.new,
|
|
93707
|
-
{
|
|
93708
|
-
additionalDirectories: [...session.additionalDirectories],
|
|
93709
|
-
cwd: session.cwd,
|
|
93710
|
-
mcpServers: []
|
|
93711
|
-
},
|
|
93712
|
-
{ cancellationSignal: signal }
|
|
93713
|
-
),
|
|
93714
|
-
"ACP agent exited while starting a session",
|
|
93715
|
-
signal
|
|
93716
|
-
)
|
|
93717
|
-
);
|
|
93718
|
-
session.selectNativeSession(created.sessionId);
|
|
94122
|
+
const created = await session.metrics.measure("session-new", async () => await session.createSession(signal));
|
|
94123
|
+
session.selectNativeSession(created.nativeSessionId);
|
|
93719
94124
|
session.setNativeHistoryOwnership({ kind: "fresh-session" });
|
|
93720
94125
|
if (recovery.kind === "execution-only") {
|
|
93721
94126
|
session.startExecutionOnlyCapture();
|
|
93722
94127
|
}
|
|
93723
|
-
|
|
94128
|
+
opened = created;
|
|
93724
94129
|
}
|
|
93725
|
-
session.
|
|
93726
|
-
session.setConfigOptions(session.sessionConfigProtocol.normalizeLifecycle(lifecycleResponse2));
|
|
94130
|
+
session.applySessionOpened(opened);
|
|
93727
94131
|
if (forkSource !== void 0) {
|
|
93728
94132
|
await session.restoreStoredConfigurations(forkSource, signal, "fork");
|
|
93729
94133
|
} else if (stored instanceof FoundStoredSession && session.restored) {
|
|
93730
94134
|
await session.restoreStoredConfigurations(stored.session, signal);
|
|
93731
94135
|
}
|
|
93732
|
-
await session.drained();
|
|
93733
94136
|
signal.throwIfAborted();
|
|
93734
94137
|
session.writeStoredSession(
|
|
93735
94138
|
stored instanceof FoundStoredSession && session.restored ? stored.session.updatedAt : (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -93746,7 +94149,6 @@ var init_session_restore = __esm({
|
|
|
93746
94149
|
});
|
|
93747
94150
|
|
|
93748
94151
|
// src/engine/session/live/agent-session.ts
|
|
93749
|
-
import { methods as methods14 } from "@agentclientprotocol/sdk";
|
|
93750
94152
|
var AgentSession;
|
|
93751
94153
|
var init_agent_session = __esm({
|
|
93752
94154
|
"src/engine/session/live/agent-session.ts"() {
|
|
@@ -93757,7 +94159,6 @@ var init_agent_session = __esm({
|
|
|
93757
94159
|
init_agent_initialization();
|
|
93758
94160
|
init_prompt_content();
|
|
93759
94161
|
init_session_capabilities();
|
|
93760
|
-
init_session_config_protocol();
|
|
93761
94162
|
init_serial_task_queue();
|
|
93762
94163
|
init_value_utils();
|
|
93763
94164
|
init_session_api();
|
|
@@ -93793,14 +94194,20 @@ var init_agent_session = __esm({
|
|
|
93793
94194
|
get sessionId() {
|
|
93794
94195
|
return this.#mobiusSessionId;
|
|
93795
94196
|
}
|
|
93796
|
-
get sessionConfigProtocol() {
|
|
93797
|
-
return this.#sessionConfigProtocol;
|
|
93798
|
-
}
|
|
93799
94197
|
get store() {
|
|
93800
94198
|
return this.#store;
|
|
93801
94199
|
}
|
|
93802
|
-
hasBackgroundActivity = () => this.#
|
|
93803
|
-
#
|
|
94200
|
+
hasBackgroundActivity = () => this.#backgroundActivity !== "none";
|
|
94201
|
+
#backgroundActivity = "none";
|
|
94202
|
+
#modelEffort = null;
|
|
94203
|
+
#scope;
|
|
94204
|
+
#subscriber;
|
|
94205
|
+
#nativeIdentity = {
|
|
94206
|
+
kind: "unbound"
|
|
94207
|
+
};
|
|
94208
|
+
get #nativeSessionId() {
|
|
94209
|
+
return this.#nativeIdentity.kind === "bound" ? this.#nativeIdentity.nativeSessionId : "";
|
|
94210
|
+
}
|
|
93804
94211
|
#adapter;
|
|
93805
94212
|
#additionalDirectories;
|
|
93806
94213
|
#agentId;
|
|
@@ -93809,11 +94216,8 @@ var init_agent_session = __esm({
|
|
|
93809
94216
|
#getObserver;
|
|
93810
94217
|
#interactions;
|
|
93811
94218
|
#mobiusSessionId;
|
|
93812
|
-
#updates;
|
|
93813
94219
|
#metrics;
|
|
93814
|
-
#sessionConfigProtocol;
|
|
93815
94220
|
#store;
|
|
93816
|
-
#verifiedAgentVersion;
|
|
93817
94221
|
#agentName = "";
|
|
93818
94222
|
#agentVersion = "";
|
|
93819
94223
|
#capabilities = unsupportedSessionCapabilities();
|
|
@@ -93829,7 +94233,7 @@ var init_agent_session = __esm({
|
|
|
93829
94233
|
#sessionTitle = null;
|
|
93830
94234
|
#sessionUpdatedAt = "";
|
|
93831
94235
|
#turn = new IdleAgentTurn();
|
|
93832
|
-
constructor(agent, cwd, additionalDirectories, mobiusSessionId, getObserver, store, metrics, adapter) {
|
|
94236
|
+
constructor(agent, cwd, additionalDirectories, mobiusSessionId, getObserver, store, metrics, adapter, externalize) {
|
|
93833
94237
|
this.#additionalDirectories = [...additionalDirectories];
|
|
93834
94238
|
this.#adapter = adapter;
|
|
93835
94239
|
this.#agentId = agent.id;
|
|
@@ -93838,9 +94242,7 @@ var init_agent_session = __esm({
|
|
|
93838
94242
|
this.#environment = agent.environment;
|
|
93839
94243
|
this.#mobiusSessionId = mobiusSessionId;
|
|
93840
94244
|
this.#metrics = metrics;
|
|
93841
|
-
this.#sessionConfigProtocol = sessionConfigProtocolForAgent(agent.id);
|
|
93842
94245
|
this.#store = store;
|
|
93843
|
-
this.#verifiedAgentVersion = agent.agentVersion;
|
|
93844
94246
|
this.#getObserver = getObserver;
|
|
93845
94247
|
this.#interactions = new SessionInteractions({
|
|
93846
94248
|
cwd: () => this.#cwd,
|
|
@@ -93851,25 +94253,31 @@ var init_agent_session = __esm({
|
|
|
93851
94253
|
observer: getObserver,
|
|
93852
94254
|
recordSessionEvent: this.recordLifecycleEvent
|
|
93853
94255
|
});
|
|
93854
|
-
|
|
94256
|
+
this.#scope = {
|
|
93855
94257
|
agent,
|
|
93856
94258
|
cwd,
|
|
93857
|
-
sessionId: () => this.#mobiusSessionId,
|
|
93858
|
-
configOptions: () => this.#configOptions,
|
|
93859
|
-
onEvent: this.#processEvent
|
|
93860
|
-
};
|
|
93861
|
-
this.#connection = this.#adapter.connectSession({
|
|
93862
|
-
...scope,
|
|
93863
94259
|
additionalDirectories: this.#additionalDirectories,
|
|
93864
|
-
|
|
93865
|
-
|
|
94260
|
+
...externalize === void 0 ? {} : { externalizeUpdate: (update, signal) => externalize(this.#mobiusSessionId, update, signal) }
|
|
94261
|
+
};
|
|
94262
|
+
this.#subscriber = {
|
|
94263
|
+
onSessionEvent: async (nativeSessionId, event) => {
|
|
94264
|
+
if (this.#nativeSessionId.length === 0) {
|
|
94265
|
+
this.selectNativeSession(nativeSessionId);
|
|
94266
|
+
} else {
|
|
94267
|
+
this.assertNativeSession(nativeSessionId);
|
|
94268
|
+
}
|
|
94269
|
+
await this.#processEvent(event);
|
|
94270
|
+
},
|
|
94271
|
+
onBackgroundActivity: (activity) => {
|
|
94272
|
+
this.#backgroundActivity = activity;
|
|
94273
|
+
this.#getObserver().onBackgroundActivity?.(this, activity);
|
|
94274
|
+
},
|
|
93866
94275
|
interactions: {
|
|
93867
94276
|
onPermission: this.#interactions.onPermission,
|
|
93868
94277
|
onElicitation: this.#interactions.onElicitation,
|
|
93869
94278
|
onElicitationComplete: this.#interactions.onElicitationComplete
|
|
93870
94279
|
}
|
|
93871
|
-
}
|
|
93872
|
-
this.#updates = this.#connection.events;
|
|
94280
|
+
};
|
|
93873
94281
|
}
|
|
93874
94282
|
static async #start(options, getObserver, store, initialize, metrics, adapter) {
|
|
93875
94283
|
for (let attempt = 1; attempt <= 2; attempt += 1) {
|
|
@@ -93887,7 +94295,8 @@ var init_agent_session = __esm({
|
|
|
93887
94295
|
getObserver,
|
|
93888
94296
|
store,
|
|
93889
94297
|
metrics,
|
|
93890
|
-
adapter
|
|
94298
|
+
adapter,
|
|
94299
|
+
options.externalizeSessionUpdate
|
|
93891
94300
|
)
|
|
93892
94301
|
);
|
|
93893
94302
|
try {
|
|
@@ -93910,11 +94319,14 @@ var init_agent_session = __esm({
|
|
|
93910
94319
|
}
|
|
93911
94320
|
throw new AcpExecutionError("ACP agent initialization failed");
|
|
93912
94321
|
}
|
|
93913
|
-
static start = async (options, recovery, getObserver, store, metrics, adapter) => await _AgentSession.#start(
|
|
94322
|
+
static start = async (options, recovery, getObserver, store, metrics, adapter, capabilities = unsupportedSessionCapabilities()) => await _AgentSession.#start(
|
|
93914
94323
|
options,
|
|
93915
94324
|
getObserver,
|
|
93916
94325
|
store,
|
|
93917
|
-
async (runtime) =>
|
|
94326
|
+
async (runtime) => {
|
|
94327
|
+
runtime.#capabilities = capabilities;
|
|
94328
|
+
await runtime.initialize(options.signal, recovery, options.origin);
|
|
94329
|
+
},
|
|
93918
94330
|
metrics,
|
|
93919
94331
|
adapter
|
|
93920
94332
|
);
|
|
@@ -93927,7 +94339,7 @@ var init_agent_session = __esm({
|
|
|
93927
94339
|
new StoredSession(
|
|
93928
94340
|
this.#mobiusSessionId,
|
|
93929
94341
|
this.#agentId,
|
|
93930
|
-
this.#
|
|
94342
|
+
this.#nativeSessionId,
|
|
93931
94343
|
this.#cwd,
|
|
93932
94344
|
this.#additionalDirectories,
|
|
93933
94345
|
this.#prompted,
|
|
@@ -93949,9 +94361,9 @@ var init_agent_session = __esm({
|
|
|
93949
94361
|
if (normalized.length === 0) {
|
|
93950
94362
|
throw new AcpExecutionError("The Session title cannot be empty", {}, "invalid_session_title");
|
|
93951
94363
|
}
|
|
93952
|
-
const nativeSessionId = this.#
|
|
94364
|
+
const nativeSessionId = this.#nativeSessionId;
|
|
93953
94365
|
if (nativeSessionId.length > 0) {
|
|
93954
|
-
await this.#adapter.renameSession(this.#target(), normalized, signal);
|
|
94366
|
+
await this.#adapter.renameSession({ ...this.#target(), title: normalized, signal });
|
|
93955
94367
|
}
|
|
93956
94368
|
const updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
93957
94369
|
await this.#processEvent({
|
|
@@ -93966,7 +94378,7 @@ var init_agent_session = __esm({
|
|
|
93966
94378
|
};
|
|
93967
94379
|
#captureSelectedConfigurationValues = () => {
|
|
93968
94380
|
this.#sessionConfigurations.capture(this.#configOptions);
|
|
93969
|
-
if (this.#
|
|
94381
|
+
if (this.#nativeSessionId.length > 0) {
|
|
93970
94382
|
this.writeStoredSession((/* @__PURE__ */ new Date()).toISOString());
|
|
93971
94383
|
}
|
|
93972
94384
|
};
|
|
@@ -93996,8 +94408,12 @@ var init_agent_session = __esm({
|
|
|
93996
94408
|
}
|
|
93997
94409
|
}
|
|
93998
94410
|
};
|
|
93999
|
-
|
|
94000
|
-
this.#
|
|
94411
|
+
applySessionOpened = (opened) => {
|
|
94412
|
+
this.#agentName = opened.agentName;
|
|
94413
|
+
this.#agentVersion = opened.agentVersion;
|
|
94414
|
+
this.#modelEffort = opened.agentSettingsModelEffort;
|
|
94415
|
+
this.#capabilities = opened.capabilities;
|
|
94416
|
+
this.setConfigOptions(opened.configOptions);
|
|
94001
94417
|
};
|
|
94002
94418
|
prepared = () => new PreparedSession(
|
|
94003
94419
|
this.#agentName,
|
|
@@ -94017,7 +94433,7 @@ var init_agent_session = __esm({
|
|
|
94017
94433
|
"native_history_unsupported"
|
|
94018
94434
|
);
|
|
94019
94435
|
}
|
|
94020
|
-
await this.#completedHistory(signal
|
|
94436
|
+
await this.#completedHistory(signal);
|
|
94021
94437
|
};
|
|
94022
94438
|
/** Starts live event capture without asking the native Agent to replay its persisted history. */
|
|
94023
94439
|
startExecutionOnlyCapture = () => {
|
|
@@ -94037,26 +94453,33 @@ var init_agent_session = __esm({
|
|
|
94037
94453
|
"native_history_unsupported"
|
|
94038
94454
|
);
|
|
94039
94455
|
}
|
|
94040
|
-
const history = await this.#completedHistory(signal
|
|
94456
|
+
const history = await this.#completedHistory(signal);
|
|
94041
94457
|
return history.eventPage(eventLimit, cursor);
|
|
94042
94458
|
};
|
|
94043
|
-
async #completedHistory(signal
|
|
94459
|
+
async #completedHistory(signal) {
|
|
94044
94460
|
if (!this.#prompted && this.#nativeHistoryOwnership.kind === "fresh-session") {
|
|
94045
94461
|
if (this.#sessionLoad.kind === "not-requested") {
|
|
94046
94462
|
this.#store.events.reset(this.#mobiusSessionId);
|
|
94047
94463
|
this.#sessionLoad = {
|
|
94048
94464
|
history: new HistoryReplayCapture(this.#store.events, this.#mobiusSessionId),
|
|
94049
94465
|
kind: "loaded",
|
|
94050
|
-
|
|
94466
|
+
opened: {
|
|
94467
|
+
nativeSessionId: this.nativeSessionId(),
|
|
94468
|
+
capabilities: this.#capabilities,
|
|
94469
|
+
configOptions: [],
|
|
94470
|
+
agentName: this.#agentName,
|
|
94471
|
+
agentVersion: this.#agentVersion,
|
|
94472
|
+
agentSettingsModelEffort: this.#modelEffort
|
|
94473
|
+
}
|
|
94051
94474
|
};
|
|
94052
94475
|
}
|
|
94053
94476
|
if (this.#sessionLoad.kind === "loaded") {
|
|
94054
94477
|
return this.#sessionLoad.history;
|
|
94055
94478
|
}
|
|
94056
94479
|
}
|
|
94057
|
-
return (await this.#loadSession(signal
|
|
94480
|
+
return (await this.#loadSession(signal)).history;
|
|
94058
94481
|
}
|
|
94059
|
-
async #loadSession(signal
|
|
94482
|
+
async #loadSession(signal) {
|
|
94060
94483
|
if (this.#sessionLoad.kind === "loaded") {
|
|
94061
94484
|
return this.#sessionLoad;
|
|
94062
94485
|
}
|
|
@@ -94067,24 +94490,13 @@ var init_agent_session = __esm({
|
|
|
94067
94490
|
const history = new HistoryReplayCapture(this.#store.events, this.#mobiusSessionId);
|
|
94068
94491
|
const completion = Promise.resolve().then(async () => {
|
|
94069
94492
|
try {
|
|
94070
|
-
const
|
|
94071
|
-
this.#
|
|
94072
|
-
|
|
94073
|
-
|
|
94074
|
-
additionalDirectories: [...this.#additionalDirectories],
|
|
94075
|
-
cwd: this.#cwd,
|
|
94076
|
-
mcpServers: [],
|
|
94077
|
-
sessionId: this.#updates.sessionId()
|
|
94078
|
-
},
|
|
94079
|
-
{ cancellationSignal: signal }
|
|
94080
|
-
),
|
|
94081
|
-
exitMessage,
|
|
94082
|
-
signal
|
|
94083
|
-
);
|
|
94084
|
-
await this.#updates.drained();
|
|
94493
|
+
const opened = await this.#adapter.openSessionWithReplay({
|
|
94494
|
+
...this.#sessionParams(signal),
|
|
94495
|
+
nativeSessionId: this.nativeSessionId()
|
|
94496
|
+
});
|
|
94085
94497
|
signal.throwIfAborted();
|
|
94086
|
-
this.
|
|
94087
|
-
const loaded = { history, kind: "loaded",
|
|
94498
|
+
this.#capabilities = opened.capabilities;
|
|
94499
|
+
const loaded = { history, kind: "loaded", opened };
|
|
94088
94500
|
this.#sessionLoad = loaded;
|
|
94089
94501
|
return loaded;
|
|
94090
94502
|
} catch (cause) {
|
|
@@ -94095,24 +94507,10 @@ var init_agent_session = __esm({
|
|
|
94095
94507
|
this.#sessionLoad = { completion, history, kind: "capturing" };
|
|
94096
94508
|
return await completion;
|
|
94097
94509
|
}
|
|
94098
|
-
async #initializeAgent(signal) {
|
|
94099
|
-
await this.#metrics.measure("agent-initialize", async () => await this.#initializeAgentOperation(signal));
|
|
94100
|
-
}
|
|
94101
|
-
async #initializeAgentOperation(signal) {
|
|
94102
|
-
const initialized = await initializeAgentConnection(
|
|
94103
|
-
this.#connection,
|
|
94104
|
-
this.#agentId,
|
|
94105
|
-
this.#verifiedAgentVersion,
|
|
94106
|
-
signal
|
|
94107
|
-
);
|
|
94108
|
-
this.#capabilities = initialized.capabilities;
|
|
94109
|
-
this.#agentName = initialized.agentName;
|
|
94110
|
-
this.#agentVersion = initialized.agentVersion;
|
|
94111
|
-
}
|
|
94112
94510
|
initialize = async (signal, recovery, origin) => await restoreSession(this, signal, recovery, origin);
|
|
94113
|
-
nativeSessionId = () => this.#
|
|
94511
|
+
nativeSessionId = () => this.#nativeSessionId;
|
|
94114
94512
|
adoptNativeSessionId = (sessionId) => {
|
|
94115
|
-
if (this.#prompted || this.#
|
|
94513
|
+
if (this.#prompted || this.#nativeSessionId !== sessionId) {
|
|
94116
94514
|
throw new AcpExecutionError("The new native Session cannot be adopted", {}, "session_identity_mismatch");
|
|
94117
94515
|
}
|
|
94118
94516
|
const previousSessionId = this.#mobiusSessionId;
|
|
@@ -94134,7 +94532,7 @@ var init_agent_session = __esm({
|
|
|
94134
94532
|
};
|
|
94135
94533
|
#applyConfiguration = async (selection, signal) => {
|
|
94136
94534
|
const configRevision = this.#configRevision;
|
|
94137
|
-
const configured = await this.#adapter.configureSession(this.#target(), selection, signal);
|
|
94535
|
+
const configured = await this.#adapter.configureSession({ ...this.#target(), selection, signal });
|
|
94138
94536
|
if (this.#configRevision === configRevision) {
|
|
94139
94537
|
this.#configOptions = configured;
|
|
94140
94538
|
this.#configRevision = crypto.randomUUID();
|
|
@@ -94181,7 +94579,7 @@ var init_agent_session = __esm({
|
|
|
94181
94579
|
await this.emitConfigUpdate();
|
|
94182
94580
|
};
|
|
94183
94581
|
#target = () => ({
|
|
94184
|
-
nativeSessionId: this.#
|
|
94582
|
+
nativeSessionId: this.#nativeSessionId,
|
|
94185
94583
|
cwd: this.#cwd,
|
|
94186
94584
|
additionalDirectories: this.#additionalDirectories
|
|
94187
94585
|
});
|
|
@@ -94193,11 +94591,18 @@ var init_agent_session = __esm({
|
|
|
94193
94591
|
this.#sessionLoad = {
|
|
94194
94592
|
kind: "loaded",
|
|
94195
94593
|
history: new HistoryReplayCapture(this.#store.events, this.#mobiusSessionId),
|
|
94196
|
-
|
|
94594
|
+
opened: {
|
|
94595
|
+
nativeSessionId: this.nativeSessionId(),
|
|
94596
|
+
capabilities: this.#capabilities,
|
|
94597
|
+
configOptions: [],
|
|
94598
|
+
agentName: this.#agentName,
|
|
94599
|
+
agentVersion: this.#agentVersion,
|
|
94600
|
+
agentSettingsModelEffort: this.#modelEffort
|
|
94601
|
+
}
|
|
94197
94602
|
};
|
|
94198
94603
|
}
|
|
94199
94604
|
if (this.#capabilities.loadSession && this.#sessionLoad.kind !== "execution-only") {
|
|
94200
|
-
await this.#completedHistory(options.signal
|
|
94605
|
+
await this.#completedHistory(options.signal);
|
|
94201
94606
|
}
|
|
94202
94607
|
validatePromptContent(options, this.#capabilities);
|
|
94203
94608
|
if (this.#sessionTitle === null || this.#sessionTitle.length === 0) {
|
|
@@ -94231,7 +94636,7 @@ var init_agent_session = __esm({
|
|
|
94231
94636
|
});
|
|
94232
94637
|
}
|
|
94233
94638
|
try {
|
|
94234
|
-
const result = await this.#adapter.prompt(this.#target(), options, options.signal);
|
|
94639
|
+
const result = await this.#adapter.prompt({ ...this.#target(), content: options, signal: options.signal });
|
|
94235
94640
|
this.writeStoredSession((/* @__PURE__ */ new Date()).toISOString());
|
|
94236
94641
|
if (lifecycle !== void 0) {
|
|
94237
94642
|
await this.recordLifecycleEvent({
|
|
@@ -94302,7 +94707,7 @@ var init_agent_session = __esm({
|
|
|
94302
94707
|
});
|
|
94303
94708
|
}
|
|
94304
94709
|
try {
|
|
94305
|
-
const outcome = await this.#adapter.steer(this.#target(), options, options.signal);
|
|
94710
|
+
const outcome = await this.#adapter.steer({ ...this.#target(), content: options, signal: options.signal });
|
|
94306
94711
|
if (lifecycle !== void 0) {
|
|
94307
94712
|
await this.recordLifecycleEvent({
|
|
94308
94713
|
payload: {
|
|
@@ -94336,7 +94741,7 @@ var init_agent_session = __esm({
|
|
|
94336
94741
|
await this.#interactions.cancelPendingInteractions();
|
|
94337
94742
|
signal.throwIfAborted();
|
|
94338
94743
|
if (this.#turn.running) {
|
|
94339
|
-
return await this.#adapter.cancel(this.#target(), signal);
|
|
94744
|
+
return await this.#adapter.cancel({ ...this.#target(), signal });
|
|
94340
94745
|
}
|
|
94341
94746
|
return "retained";
|
|
94342
94747
|
};
|
|
@@ -94361,7 +94766,14 @@ var init_agent_session = __esm({
|
|
|
94361
94766
|
await this.#getObserver().onSessionEvent?.(liveEvent2);
|
|
94362
94767
|
};
|
|
94363
94768
|
selectNativeSession = (sessionId) => {
|
|
94364
|
-
this.#
|
|
94769
|
+
if (this.#nativeSessionId.length > 0 && this.#nativeSessionId !== sessionId) {
|
|
94770
|
+
throw new AcpExecutionError(
|
|
94771
|
+
"ACP agent attempted to replace the selected session",
|
|
94772
|
+
{},
|
|
94773
|
+
"invalid_agent_session"
|
|
94774
|
+
);
|
|
94775
|
+
}
|
|
94776
|
+
this.#nativeIdentity = { kind: "bound", nativeSessionId: sessionId };
|
|
94365
94777
|
this.#nativeHistoryOwnership = { kind: "agent-owned" };
|
|
94366
94778
|
};
|
|
94367
94779
|
#processEvent = async (event) => {
|
|
@@ -94406,7 +94818,7 @@ var init_agent_session = __esm({
|
|
|
94406
94818
|
break;
|
|
94407
94819
|
}
|
|
94408
94820
|
}
|
|
94409
|
-
if (this.#
|
|
94821
|
+
if (this.#nativeSessionId.length > 0) {
|
|
94410
94822
|
this.writeStoredSession((/* @__PURE__ */ new Date()).toISOString());
|
|
94411
94823
|
}
|
|
94412
94824
|
await this.#getObserver().onInfo({
|
|
@@ -94428,31 +94840,28 @@ var init_agent_session = __esm({
|
|
|
94428
94840
|
await this.closeProcess();
|
|
94429
94841
|
}
|
|
94430
94842
|
}
|
|
94431
|
-
if (this.#
|
|
94843
|
+
if (this.#nativeSessionId.length === 0) {
|
|
94432
94844
|
await this.closeProcess();
|
|
94433
94845
|
return;
|
|
94434
94846
|
}
|
|
94435
|
-
await this.#adapter.closeSession(this.#target(), AbortSignal.timeout(3e4));
|
|
94847
|
+
await this.#adapter.closeSession({ ...this.#target(), signal: AbortSignal.timeout(3e4) });
|
|
94436
94848
|
};
|
|
94437
|
-
closeProcess = () =>
|
|
94438
|
-
|
|
94439
|
-
|
|
94440
|
-
|
|
94441
|
-
|
|
94442
|
-
|
|
94443
|
-
|
|
94444
|
-
|
|
94445
|
-
|
|
94446
|
-
|
|
94447
|
-
|
|
94448
|
-
|
|
94449
|
-
|
|
94450
|
-
|
|
94451
|
-
|
|
94452
|
-
|
|
94453
|
-
async loadSession(signal, exitMessage) {
|
|
94454
|
-
return await this.#loadSession(signal, exitMessage);
|
|
94455
|
-
}
|
|
94849
|
+
closeProcess = async () => {
|
|
94850
|
+
if (this.#nativeIdentity.kind === "bound") {
|
|
94851
|
+
await this.#adapter.releaseSession({ ...this.#target(), signal: AbortSignal.timeout(3e4) });
|
|
94852
|
+
}
|
|
94853
|
+
this.#backgroundActivity = "none";
|
|
94854
|
+
};
|
|
94855
|
+
agentSettingsModelEffort = () => this.#modelEffort;
|
|
94856
|
+
#sessionParams = (signal) => ({
|
|
94857
|
+
...this.#subscriber,
|
|
94858
|
+
scope: this.#scope,
|
|
94859
|
+
signal
|
|
94860
|
+
});
|
|
94861
|
+
createSession = (signal) => this.#adapter.createSession(this.#sessionParams(signal));
|
|
94862
|
+
forkSession = (sourceSessionId, signal) => this.#adapter.forkSession({ ...this.#sessionParams(signal), sourceNativeSessionId: sourceSessionId });
|
|
94863
|
+
openSession = (signal) => this.#adapter.openSession({ ...this.#sessionParams(signal), nativeSessionId: this.nativeSessionId() });
|
|
94864
|
+
openSessionWithReplay = async (signal) => (await this.#loadSession(signal)).opened;
|
|
94456
94865
|
setConfigOptions(options) {
|
|
94457
94866
|
this.#configOptions = options;
|
|
94458
94867
|
this.#configRevision = crypto.randomUUID();
|
|
@@ -94470,7 +94879,7 @@ var init_agent_session = __esm({
|
|
|
94470
94879
|
this.#sessionTitle = title2;
|
|
94471
94880
|
}
|
|
94472
94881
|
assertNativeSession = (sessionId) => {
|
|
94473
|
-
if (sessionId !== this.#
|
|
94882
|
+
if (sessionId !== this.#nativeSessionId) {
|
|
94474
94883
|
throw new AcpExecutionError("ACP agent referenced an unknown session", {}, "invalid_agent_session");
|
|
94475
94884
|
}
|
|
94476
94885
|
};
|
|
@@ -94501,6 +94910,23 @@ var init_native_chat_agent = __esm({
|
|
|
94501
94910
|
}
|
|
94502
94911
|
});
|
|
94503
94912
|
|
|
94913
|
+
// src/engine/session/native/native-query.ts
|
|
94914
|
+
function nativeSessionQuery(options) {
|
|
94915
|
+
const externalize = options.externalizeSessionUpdate;
|
|
94916
|
+
return {
|
|
94917
|
+
agent: options.agent,
|
|
94918
|
+
cwd: options.cwd,
|
|
94919
|
+
additionalDirectories: options.additionalDirectories,
|
|
94920
|
+
signal: options.signal,
|
|
94921
|
+
...externalize === void 0 ? {} : { externalizeUpdate: (update, signal) => externalize(options.sessionId, update, signal) }
|
|
94922
|
+
};
|
|
94923
|
+
}
|
|
94924
|
+
var init_native_query = __esm({
|
|
94925
|
+
"src/engine/session/native/native-query.ts"() {
|
|
94926
|
+
"use strict";
|
|
94927
|
+
}
|
|
94928
|
+
});
|
|
94929
|
+
|
|
94504
94930
|
// src/engine/session/turn/active-executions.ts
|
|
94505
94931
|
var unreachable2, ActiveExecutions;
|
|
94506
94932
|
var init_active_executions = __esm({
|
|
@@ -94596,9 +95022,11 @@ var init_session_manager = __esm({
|
|
|
94596
95022
|
"use strict";
|
|
94597
95023
|
init_protocol();
|
|
94598
95024
|
init_acp_error();
|
|
95025
|
+
init_session_capabilities();
|
|
94599
95026
|
init_operation_metrics();
|
|
94600
95027
|
init_agent_session();
|
|
94601
95028
|
init_native_chat_agent();
|
|
95029
|
+
init_native_query();
|
|
94602
95030
|
init_retained_agent_processes();
|
|
94603
95031
|
init_session_store2();
|
|
94604
95032
|
init_active_executions();
|
|
@@ -94721,21 +95149,29 @@ var init_session_manager = __esm({
|
|
|
94721
95149
|
if (retiring !== void 0) {
|
|
94722
95150
|
await waitForSharedOperation(retiring, options.signal);
|
|
94723
95151
|
}
|
|
94724
|
-
const
|
|
95152
|
+
const stored = this.#store.read(options.sessionId);
|
|
95153
|
+
const capabilities = options.origin !== void 0 || stored instanceof FoundStoredSession && stored.session.prompted ? await options.adapter.getCapabilities(nativeSessionQuery(options)) : unsupportedSessionCapabilities();
|
|
95154
|
+
const runtime = await this.#processes.startRetained(
|
|
95155
|
+
options.signal,
|
|
95156
|
+
() => start(capabilities),
|
|
95157
|
+
this.#retention(options.sessionId)
|
|
95158
|
+
);
|
|
94725
95159
|
this.#executionProcesses.retain(options.sessionId, runtime);
|
|
94726
95160
|
return runtime;
|
|
94727
95161
|
}
|
|
94728
95162
|
async #startPreparation(options, recovery, metrics = unmeasuredOperationMetrics) {
|
|
94729
95163
|
return await this.#executionProcesses.prepare(options.sessionId, async () => {
|
|
95164
|
+
const effectiveOptions = options.origin === void 0 && this.#sessionIdentity === "native" && isNativeChatSessionId(options.agent.id, options.sessionId) && this.#store.read(options.sessionId) instanceof MissingStoredSession ? { ...options, origin: { kind: "import", nativeSessionId: options.sessionId, title: "" } } : options;
|
|
94730
95165
|
return await this.#startRetainedSessionProcess(
|
|
94731
|
-
|
|
94732
|
-
async () => await AgentSession.start(
|
|
94733
|
-
|
|
95166
|
+
effectiveOptions,
|
|
95167
|
+
async (capabilities) => await AgentSession.start(
|
|
95168
|
+
effectiveOptions,
|
|
94734
95169
|
recovery,
|
|
94735
95170
|
() => this.#observer,
|
|
94736
95171
|
this.#store,
|
|
94737
95172
|
metrics,
|
|
94738
|
-
options.adapter
|
|
95173
|
+
options.adapter,
|
|
95174
|
+
capabilities
|
|
94739
95175
|
)
|
|
94740
95176
|
);
|
|
94741
95177
|
});
|
|
@@ -94750,13 +95186,14 @@ var init_session_manager = __esm({
|
|
|
94750
95186
|
this.#store.remove(options.sessionId);
|
|
94751
95187
|
return await this.#startRetainedSessionProcess(
|
|
94752
95188
|
options,
|
|
94753
|
-
async () => await AgentSession.start(
|
|
95189
|
+
async (capabilities) => await AgentSession.start(
|
|
94754
95190
|
options,
|
|
94755
95191
|
recovery,
|
|
94756
95192
|
() => this.#observer,
|
|
94757
95193
|
this.#store,
|
|
94758
95194
|
metrics,
|
|
94759
|
-
options.adapter
|
|
95195
|
+
options.adapter,
|
|
95196
|
+
capabilities
|
|
94760
95197
|
)
|
|
94761
95198
|
);
|
|
94762
95199
|
});
|
|
@@ -94768,13 +95205,14 @@ var init_session_manager = __esm({
|
|
|
94768
95205
|
await this.#retireSessionProcess(options.sessionId, existing, async () => await existing.close());
|
|
94769
95206
|
const runtime = await this.#startRetainedSessionProcess(
|
|
94770
95207
|
options,
|
|
94771
|
-
async () => await AgentSession.start(
|
|
95208
|
+
async (capabilities) => await AgentSession.start(
|
|
94772
95209
|
options,
|
|
94773
95210
|
recovery,
|
|
94774
95211
|
() => this.#observer,
|
|
94775
95212
|
this.#store,
|
|
94776
95213
|
unmeasuredOperationMetrics,
|
|
94777
|
-
options.adapter
|
|
95214
|
+
options.adapter,
|
|
95215
|
+
capabilities
|
|
94778
95216
|
)
|
|
94779
95217
|
);
|
|
94780
95218
|
try {
|
|
@@ -95402,7 +95840,7 @@ var init_local_authorization_error = __esm({
|
|
|
95402
95840
|
});
|
|
95403
95841
|
|
|
95404
95842
|
// src/engine/session/native/native-session-browser.ts
|
|
95405
|
-
import { randomUUID as
|
|
95843
|
+
import { randomUUID as randomUUID14 } from "node:crypto";
|
|
95406
95844
|
function nextForkTitle(sourceTitle, sessions) {
|
|
95407
95845
|
let highest = 0;
|
|
95408
95846
|
for (const session of sessions) {
|
|
@@ -95433,6 +95871,7 @@ var init_native_session_browser = __esm({
|
|
|
95433
95871
|
init_native_session();
|
|
95434
95872
|
init_operation_drain();
|
|
95435
95873
|
init_local_authorization_error();
|
|
95874
|
+
init_native_query();
|
|
95436
95875
|
MAXIMUM_SESSION_TITLE_LENGTH = 500;
|
|
95437
95876
|
forkSuffixPattern = / \(Fork #([1-9][0-9]*)\)$/u;
|
|
95438
95877
|
NativeSessionService = class {
|
|
@@ -95460,17 +95899,14 @@ var init_native_session_browser = __esm({
|
|
|
95460
95899
|
(scoped) => this.#sessions.withNativeSessionOperation(
|
|
95461
95900
|
scoped,
|
|
95462
95901
|
nativeSessionId,
|
|
95463
|
-
(target) => target.adapter.readSessionHistory(
|
|
95464
|
-
target
|
|
95465
|
-
|
|
95466
|
-
{
|
|
95902
|
+
(target) => target.adapter.readSessionHistory({
|
|
95903
|
+
query: nativeSessionQuery(target),
|
|
95904
|
+
request: {
|
|
95467
95905
|
nativeSessionId,
|
|
95468
95906
|
eventLimit,
|
|
95469
|
-
cursor
|
|
95470
|
-
|
|
95471
|
-
|
|
95472
|
-
target.signal
|
|
95473
|
-
)
|
|
95907
|
+
cursor
|
|
95908
|
+
}
|
|
95909
|
+
})
|
|
95474
95910
|
)
|
|
95475
95911
|
);
|
|
95476
95912
|
#execute = async (command, signal) => {
|
|
@@ -95501,7 +95937,7 @@ var init_native_session_browser = __esm({
|
|
|
95501
95937
|
queuedCancellation: "before-start"
|
|
95502
95938
|
};
|
|
95503
95939
|
}
|
|
95504
|
-
const capabilities = await options.adapter.getCapabilities(
|
|
95940
|
+
const capabilities = await options.adapter.getCapabilities(nativeSessionQuery(options));
|
|
95505
95941
|
if (!capabilities.listSessions) {
|
|
95506
95942
|
throw new AcpExecutionError(
|
|
95507
95943
|
"This Agent does not support native session listing",
|
|
@@ -95516,7 +95952,7 @@ var init_native_session_browser = __esm({
|
|
|
95516
95952
|
if (authorized === null) {
|
|
95517
95953
|
return null;
|
|
95518
95954
|
}
|
|
95519
|
-
const entryId = decodeIdentifier(
|
|
95955
|
+
const entryId = decodeIdentifier(randomUUID14());
|
|
95520
95956
|
if (this.#entries.size >= 5e3) {
|
|
95521
95957
|
this.#entries.clear();
|
|
95522
95958
|
}
|
|
@@ -95555,7 +95991,7 @@ var init_native_session_browser = __esm({
|
|
|
95555
95991
|
}
|
|
95556
95992
|
cursor = known.cursor;
|
|
95557
95993
|
}
|
|
95558
|
-
const page = await options.adapter.listSessions(
|
|
95994
|
+
const page = await options.adapter.listSessions({ query: nativeSessionQuery(options), cursor });
|
|
95559
95995
|
const entries = [];
|
|
95560
95996
|
for (const info of page.sessions) {
|
|
95561
95997
|
const entry = await register(info);
|
|
@@ -95572,7 +96008,7 @@ var init_native_session_browser = __esm({
|
|
|
95572
96008
|
"invalid_native_session_response"
|
|
95573
96009
|
);
|
|
95574
96010
|
}
|
|
95575
|
-
nextCursor = decodeIdentifier(
|
|
96011
|
+
nextCursor = decodeIdentifier(randomUUID14());
|
|
95576
96012
|
if (this.#cursors.size >= 500) {
|
|
95577
96013
|
this.#cursors.clear();
|
|
95578
96014
|
}
|
|
@@ -95590,15 +96026,14 @@ var init_native_session_browser = __esm({
|
|
|
95590
96026
|
};
|
|
95591
96027
|
}
|
|
95592
96028
|
if (command.action === "find") {
|
|
95593
|
-
const found = await options.adapter.findSession(
|
|
95594
|
-
|
|
95595
|
-
command.nativeSessionId,
|
|
95596
|
-
{
|
|
96029
|
+
const found = await options.adapter.findSession({
|
|
96030
|
+
query: nativeSessionQuery(options),
|
|
96031
|
+
nativeSessionId: command.nativeSessionId,
|
|
96032
|
+
budget: {
|
|
95597
96033
|
maximumPages: 500,
|
|
95598
96034
|
maximumEntries: 500
|
|
95599
|
-
}
|
|
95600
|
-
|
|
95601
|
-
);
|
|
96035
|
+
}
|
|
96036
|
+
});
|
|
95602
96037
|
const entry = await register(found);
|
|
95603
96038
|
if (entry !== null) {
|
|
95604
96039
|
return { ...envelope2, action: "find", entry };
|
|
@@ -95736,15 +96171,14 @@ var init_native_session_browser = __esm({
|
|
|
95736
96171
|
}
|
|
95737
96172
|
};
|
|
95738
96173
|
resolveTarget = async (command, options, selected) => {
|
|
95739
|
-
const info = await options.adapter.findSession(
|
|
95740
|
-
options
|
|
95741
|
-
selected.nativeSessionId,
|
|
95742
|
-
{
|
|
96174
|
+
const info = await options.adapter.findSession({
|
|
96175
|
+
query: nativeSessionQuery(options),
|
|
96176
|
+
nativeSessionId: selected.nativeSessionId,
|
|
96177
|
+
budget: {
|
|
95743
96178
|
maximumPages: 100,
|
|
95744
96179
|
maximumEntries: null
|
|
95745
|
-
}
|
|
95746
|
-
|
|
95747
|
-
).catch((cause) => {
|
|
96180
|
+
}
|
|
96181
|
+
}).catch((cause) => {
|
|
95748
96182
|
options.signal.throwIfAborted();
|
|
95749
96183
|
if (cause instanceof AcpExecutionError && cause.code === "native_session_not_found") {
|
|
95750
96184
|
throw new AcpExecutionError(
|
|
@@ -96031,7 +96465,7 @@ var init_prompt_lifecycle = __esm({
|
|
|
96031
96465
|
});
|
|
96032
96466
|
|
|
96033
96467
|
// src/engine/session/turn/execution-receipts.ts
|
|
96034
|
-
import { createHash as createHash7, randomUUID as
|
|
96468
|
+
import { createHash as createHash7, randomUUID as randomUUID15 } from "node:crypto";
|
|
96035
96469
|
var MAX_TERMINAL_RECEIPTS, ExecutionReceipts;
|
|
96036
96470
|
var init_execution_receipts = __esm({
|
|
96037
96471
|
"src/engine/session/turn/execution-receipts.ts"() {
|
|
@@ -96178,7 +96612,7 @@ var init_execution_receipts = __esm({
|
|
|
96178
96612
|
).digest("hex");
|
|
96179
96613
|
this.#save(commandId, {
|
|
96180
96614
|
admissionOrder: this.#nextAdmissionOrder(),
|
|
96181
|
-
attemptId:
|
|
96615
|
+
attemptId: randomUUID15(),
|
|
96182
96616
|
commandHash,
|
|
96183
96617
|
sessionId,
|
|
96184
96618
|
started: false,
|
|
@@ -96260,7 +96694,7 @@ var init_execution_receipts = __esm({
|
|
|
96260
96694
|
if (identity2 !== void 0) {
|
|
96261
96695
|
return identity2.sessionId === sessionId && identity2.commandHash === commandHash ? { kind: "expired" } : { kind: "conflict" };
|
|
96262
96696
|
}
|
|
96263
|
-
const attemptId =
|
|
96697
|
+
const attemptId = randomUUID15();
|
|
96264
96698
|
this.#save(commandId, {
|
|
96265
96699
|
admissionOrder: this.#nextAdmissionOrder(),
|
|
96266
96700
|
attemptId,
|
|
@@ -96395,7 +96829,7 @@ var init_runtime_turn_activity = __esm({
|
|
|
96395
96829
|
});
|
|
96396
96830
|
|
|
96397
96831
|
// src/engine/session/turn/active-turn.ts
|
|
96398
|
-
import { randomUUID as
|
|
96832
|
+
import { randomUUID as randomUUID16 } from "node:crypto";
|
|
96399
96833
|
var ActiveRuntimeTurn;
|
|
96400
96834
|
var init_active_turn = __esm({
|
|
96401
96835
|
"src/engine/session/turn/active-turn.ts"() {
|
|
@@ -96410,7 +96844,7 @@ var init_active_turn = __esm({
|
|
|
96410
96844
|
#dispatch;
|
|
96411
96845
|
#sequence = 0;
|
|
96412
96846
|
#interaction = null;
|
|
96413
|
-
#epoch = decodeIdentifier(
|
|
96847
|
+
#epoch = decodeIdentifier(randomUUID16());
|
|
96414
96848
|
constructor(command, attemptId) {
|
|
96415
96849
|
this.attemptId = attemptId;
|
|
96416
96850
|
this.command = command;
|
|
@@ -97019,11 +97453,11 @@ var init_session_layer = __esm({
|
|
|
97019
97453
|
});
|
|
97020
97454
|
|
|
97021
97455
|
// src/engine/storage/files/scratch-directory.ts
|
|
97022
|
-
import { randomUUID as
|
|
97456
|
+
import { randomUUID as randomUUID17 } from "node:crypto";
|
|
97023
97457
|
import { lstat as lstat4, mkdir as mkdir5, readdir as readdir6, readFile as readFile7, realpath as realpath8, rename as rename4, rm as rm3, stat as stat8, utimes, writeFile as writeFile2 } from "node:fs/promises";
|
|
97024
97458
|
import { dirname as dirname12, join as join30 } from "node:path";
|
|
97025
97459
|
async function atomicWrite(path8, bytes, signal) {
|
|
97026
|
-
const temporary = `${path8}.${
|
|
97460
|
+
const temporary = `${path8}.${randomUUID17()}.tmp`;
|
|
97027
97461
|
try {
|
|
97028
97462
|
await writeFile2(temporary, bytes, { mode: 384, signal });
|
|
97029
97463
|
signal.throwIfAborted();
|
|
@@ -97039,7 +97473,7 @@ var init_scratch_directory = __esm({
|
|
|
97039
97473
|
ScratchDirectory = class {
|
|
97040
97474
|
#root;
|
|
97041
97475
|
constructor(parent) {
|
|
97042
|
-
this.#root = join30(parent,
|
|
97476
|
+
this.#root = join30(parent, randomUUID17());
|
|
97043
97477
|
}
|
|
97044
97478
|
/** Refreshes this directory's lease and removes sibling directories whose lease is older than `leaseMilliseconds`. */
|
|
97045
97479
|
refreshLease = async (leaseMilliseconds) => {
|
|
@@ -99231,7 +99665,7 @@ var init_native_sessions = __esm({
|
|
|
99231
99665
|
});
|
|
99232
99666
|
|
|
99233
99667
|
// src/engine/session/prompt/apply-session-configuration.ts
|
|
99234
|
-
import { randomUUID as
|
|
99668
|
+
import { randomUUID as randomUUID18 } from "node:crypto";
|
|
99235
99669
|
function invalidSessionConfiguration(message) {
|
|
99236
99670
|
return new AcpExecutionError(message, {}, "invalid_session_configuration");
|
|
99237
99671
|
}
|
|
@@ -99369,7 +99803,7 @@ async function applySessionConfigurationSelection(sessions, options, selection,
|
|
|
99369
99803
|
booleanValue: selection.booleanValue,
|
|
99370
99804
|
configId: selection.configId,
|
|
99371
99805
|
cwd,
|
|
99372
|
-
requestId: `cfg_${
|
|
99806
|
+
requestId: `cfg_${randomUUID18()}`,
|
|
99373
99807
|
sessionId,
|
|
99374
99808
|
signal,
|
|
99375
99809
|
value: selection.value,
|
|
@@ -99442,7 +99876,11 @@ async function executePrompt({
|
|
|
99442
99876
|
command.additionalDirectoryIds,
|
|
99443
99877
|
signal
|
|
99444
99878
|
);
|
|
99445
|
-
const { agent, adapter } = await resolveAgent(
|
|
99879
|
+
const { agent, adapter, externalizeSessionUpdate } = await resolveAgent(
|
|
99880
|
+
command.agentId,
|
|
99881
|
+
signal,
|
|
99882
|
+
command.sessionId
|
|
99883
|
+
);
|
|
99446
99884
|
const availability = await waitForSessionAvailability(signal);
|
|
99447
99885
|
if (availability.kind === "busy") {
|
|
99448
99886
|
throw new AcpExecutionError("Another prompt is already running in this conversation", {}, "session_busy");
|
|
@@ -99460,6 +99898,7 @@ async function executePrompt({
|
|
|
99460
99898
|
const recovery = command.historyPolicy === SessionHistoryPolicy.ExecutionOnly ? { kind: "execution-only" } : { kind: "interactive-only" };
|
|
99461
99899
|
const preparation = {
|
|
99462
99900
|
adapter,
|
|
99901
|
+
...externalizeSessionUpdate === void 0 ? {} : { externalizeSessionUpdate },
|
|
99463
99902
|
additionalDirectories: resolved.additionalDirectories,
|
|
99464
99903
|
agent: executionAgent,
|
|
99465
99904
|
cwd: resolved.cwd,
|
|
@@ -99514,6 +99953,7 @@ async function executePrompt({
|
|
|
99514
99953
|
if (availability.disposition === SessionPromptDisposition.Steer) {
|
|
99515
99954
|
await sessions.steerPrompt({
|
|
99516
99955
|
adapter,
|
|
99956
|
+
...externalizeSessionUpdate === void 0 ? {} : { externalizeSessionUpdate },
|
|
99517
99957
|
additionalDirectories: resolved.additionalDirectories,
|
|
99518
99958
|
agent: executionAgent,
|
|
99519
99959
|
commandId: command.commandId,
|
|
@@ -99530,6 +99970,7 @@ async function executePrompt({
|
|
|
99530
99970
|
} else {
|
|
99531
99971
|
const result = await sessions.runPrompt({
|
|
99532
99972
|
adapter,
|
|
99973
|
+
...externalizeSessionUpdate === void 0 ? {} : { externalizeSessionUpdate },
|
|
99533
99974
|
additionalDirectories: resolved.additionalDirectories,
|
|
99534
99975
|
agent: executionAgent,
|
|
99535
99976
|
commandId: command.commandId,
|
|
@@ -100943,7 +101384,7 @@ async function runRuntime(config2, parentSignal, timer = systemTimer, options =
|
|
|
100943
101384
|
const publisher = new RuntimeSessionEventPublisher(timer);
|
|
100944
101385
|
const externalContent = __using(_stack, new LocalExternalContentStore(stateDirectory), true);
|
|
100945
101386
|
const processes = new AgentProcessPool(config2.localContext.maxAcpProcesses, timer);
|
|
100946
|
-
const adapters = createRuntimeAdapterRegistry(
|
|
101387
|
+
const { adapters, externalizeSessionUpdate } = createRuntimeAdapterRegistry(
|
|
100947
101388
|
config2.adapters,
|
|
100948
101389
|
processes,
|
|
100949
101390
|
(sessionId, content, contentSignal) => externalContent.put({ ...content, sessionId, signal: contentSignal }),
|
|
@@ -100953,7 +101394,11 @@ async function runRuntime(config2, parentSignal, timer = systemTimer, options =
|
|
|
100953
101394
|
const catalogAgent = await resolveCatalogAgent(config2, agentId, resolveSignal);
|
|
100954
101395
|
const environment = sessionId === void 0 ? void 0 : config2.sessionEnvironment?.({ sessionId, agentId });
|
|
100955
101396
|
const agent = environment === void 0 ? catalogAgent : catalogAgent.withEnvironment({ ...catalogAgent.environment, ...environment });
|
|
100956
|
-
return {
|
|
101397
|
+
return {
|
|
101398
|
+
agent,
|
|
101399
|
+
adapter: adapters.resolve(catalogAgent),
|
|
101400
|
+
externalizeSessionUpdate
|
|
101401
|
+
};
|
|
100957
101402
|
};
|
|
100958
101403
|
const layer = buildSessionLayer({
|
|
100959
101404
|
processes,
|
|
@@ -101338,7 +101783,7 @@ var init_engine = __esm({
|
|
|
101338
101783
|
});
|
|
101339
101784
|
|
|
101340
101785
|
// src/storage/daemon/version-data.ts
|
|
101341
|
-
import { randomUUID as
|
|
101786
|
+
import { randomUUID as randomUUID19 } from "node:crypto";
|
|
101342
101787
|
import { cp as cp2, lstat as lstat5, mkdtemp, readFile as readFile8, rename as rename5, rm as rm4, writeFile as writeFile3 } from "node:fs/promises";
|
|
101343
101788
|
import { join as join33, relative as relative3, sep as sep5 } from "node:path";
|
|
101344
101789
|
async function prepareVersionDataDirectory(root, version2, signal) {
|
|
@@ -101429,7 +101874,7 @@ async function discardVersionData(root, version2, signal) {
|
|
|
101429
101874
|
return;
|
|
101430
101875
|
}
|
|
101431
101876
|
const versions = join33(root, STATE_ROOT_LAYOUT.versions);
|
|
101432
|
-
const discarded = join33(versions, `.${version2}-discarded-${
|
|
101877
|
+
const discarded = join33(versions, `.${version2}-discarded-${randomUUID19()}`);
|
|
101433
101878
|
try {
|
|
101434
101879
|
await rename5(join33(versions, version2), discarded);
|
|
101435
101880
|
} catch (cause) {
|
|
@@ -101443,7 +101888,7 @@ async function discardVersionData(root, version2, signal) {
|
|
|
101443
101888
|
async function writeCurrentDataVersion(root, version2, signal) {
|
|
101444
101889
|
await validateLocalPath(root, true, true, signal);
|
|
101445
101890
|
await validateLocalPath(join33(root, STATE_ROOT_LAYOUT.versions, version2), true, true, signal);
|
|
101446
|
-
const temporary = join33(root, `.current-data-${
|
|
101891
|
+
const temporary = join33(root, `.current-data-${randomUUID19()}.txt`);
|
|
101447
101892
|
try {
|
|
101448
101893
|
await writeFile3(temporary, `versions/${version2}
|
|
101449
101894
|
`, { mode: 384, flag: "wx", signal });
|
|
@@ -103047,7 +103492,7 @@ var init_quit = __esm({
|
|
|
103047
103492
|
});
|
|
103048
103493
|
|
|
103049
103494
|
// src/daemon/upgrades/upgrade.ts
|
|
103050
|
-
import { randomUUID as
|
|
103495
|
+
import { randomUUID as randomUUID20 } from "node:crypto";
|
|
103051
103496
|
import { setInterval as setInterval2, setTimeout as setTimeout4 } from "node:timers/promises";
|
|
103052
103497
|
async function reportDaemonUpgradeAvailability(send2, signal) {
|
|
103053
103498
|
if (!process.connected) {
|
|
@@ -103106,7 +103551,7 @@ async function requestDaemonReleaseUpgrade(stateDirectory, currentVersion, signa
|
|
|
103106
103551
|
return await requestInstalledDaemonReleaseSwitch(stateDirectory, launch, signal);
|
|
103107
103552
|
}
|
|
103108
103553
|
async function requestInstalledDaemonReleaseSwitch(stateDirectory, launch, signal) {
|
|
103109
|
-
const id =
|
|
103554
|
+
const id = randomUUID20();
|
|
103110
103555
|
const response = decodeKnownLifecycleResponse(
|
|
103111
103556
|
await sendLocalRequest(stateDirectory, "manager", { kind: "switch", id, context: "npm", launch }, signal)
|
|
103112
103557
|
);
|