@moxt-ai/mobius 0.0.358 → 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 +943 -495
- 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/harness/codex/borrowed-agent.d.ts.map +1 -1
- package/dist/engine/acp/harness/codex/borrowed-agent.js +10 -3
- package/dist/engine/acp/harness/codex/borrowed-agent.js.map +1 -1
- package/dist/engine/acp/harness/codex/history.js +1 -1
- package/dist/engine/acp/harness/codex/history.js.map +1 -1
- package/dist/engine/acp/harness/codex/items.js +1 -1
- package/dist/engine/acp/harness/codex/owned-agent.d.ts.map +1 -1
- package/dist/engine/acp/harness/codex/owned-agent.js +3 -2
- package/dist/engine/acp/harness/codex/owned-agent.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 +882 -476
- package/dist/engine.js.map +4 -4
- package/package.json +2 -2
- 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/engine.js
CHANGED
|
@@ -69073,17 +69073,20 @@ var CodexBorrowedAcpAgent = class {
|
|
|
69073
69073
|
this.#seen.set(key, text2);
|
|
69074
69074
|
continue;
|
|
69075
69075
|
}
|
|
69076
|
+
if (item.type === "plan" && turn.status === "inProgress") {
|
|
69077
|
+
continue;
|
|
69078
|
+
}
|
|
69076
69079
|
const previous = this.#seen.get(key);
|
|
69077
|
-
const value = item.type === "agentMessage" ? item.text : reasoningText(item) ?? JSON.stringify(item);
|
|
69080
|
+
const value = item.type === "agentMessage" || item.type === "plan" ? item.text : reasoningText(item) ?? JSON.stringify(item);
|
|
69078
69081
|
this.#seen.set(key, value);
|
|
69079
69082
|
if (baseline || value === previous) {
|
|
69080
69083
|
continue;
|
|
69081
69084
|
}
|
|
69082
|
-
if (item.type === "agentMessage" || reasoningText(item) !== null) {
|
|
69085
|
+
if (item.type === "agentMessage" || item.type === "plan" || reasoningText(item) !== null) {
|
|
69083
69086
|
const text2 = previous !== void 0 && value.startsWith(previous) ? value.slice(previous.length) : value;
|
|
69084
69087
|
if (text2.length > 0) {
|
|
69085
69088
|
await this.#emit({
|
|
69086
|
-
sessionUpdate: item.type === "
|
|
69089
|
+
sessionUpdate: item.type === "reasoning" ? "agent_thought_chunk" : "agent_message_chunk",
|
|
69087
69090
|
messageId: item.id,
|
|
69088
69091
|
content: { type: "text", text: text2 }
|
|
69089
69092
|
});
|
|
@@ -69858,7 +69861,7 @@ var CodexOwnedAcpAgent = class {
|
|
|
69858
69861
|
}
|
|
69859
69862
|
return;
|
|
69860
69863
|
}
|
|
69861
|
-
if (item.type === "agentMessage") {
|
|
69864
|
+
if (item.type === "agentMessage" || item.type === "plan") {
|
|
69862
69865
|
if (method === "item/started") {
|
|
69863
69866
|
this.#agentMessages.set(item.id, "started");
|
|
69864
69867
|
return;
|
|
@@ -70276,7 +70279,7 @@ async function replayCodexHistory(client2, threadId, emit, signal) {
|
|
|
70276
70279
|
});
|
|
70277
70280
|
}
|
|
70278
70281
|
}
|
|
70279
|
-
} else if (item.type === "agentMessage") {
|
|
70282
|
+
} else if (item.type === "agentMessage" || item.type === "plan") {
|
|
70280
70283
|
await emit(agentMessageUpdate(item.id, item.text));
|
|
70281
70284
|
} else if (item.type === "reasoning") {
|
|
70282
70285
|
const text2 = reasoningText(item);
|
|
@@ -75870,9 +75873,25 @@ async function runCleanup(...actions) {
|
|
|
75870
75873
|
}
|
|
75871
75874
|
}
|
|
75872
75875
|
|
|
75873
|
-
// src/engine/acp/
|
|
75876
|
+
// src/engine/acp/protocol/native-session.ts
|
|
75877
|
+
var path6 = external_exports.string().min(1).max(2048).refine((value) => !value.includes("\0"));
|
|
75878
|
+
var title = external_exports.string().transform((value) => value.slice(0, 500));
|
|
75879
|
+
var nativeSessionIdSchema = external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,255}$/);
|
|
75880
|
+
var nativeSessionInfoSchema = external_exports.object({
|
|
75881
|
+
sessionId: nativeSessionIdSchema,
|
|
75882
|
+
cwd: path6,
|
|
75883
|
+
additionalDirectories: external_exports.array(path6).max(16).default([]).readonly(),
|
|
75884
|
+
title: title.nullish(),
|
|
75885
|
+
updatedAt: external_exports.iso.datetime({ offset: true }).nullish()
|
|
75886
|
+
}).readonly();
|
|
75887
|
+
var nativeSessionPageSchema = external_exports.object({
|
|
75888
|
+
sessions: external_exports.array(nativeSessionInfoSchema).max(500).readonly(),
|
|
75889
|
+
nextCursor: external_exports.string().min(1).max(4096).nullish()
|
|
75890
|
+
}).readonly();
|
|
75891
|
+
|
|
75892
|
+
// src/engine/acp/adapter/execution-connections.ts
|
|
75874
75893
|
import { isAbsolute as isAbsolute14, resolve as resolve13 } from "node:path";
|
|
75875
|
-
import { methods as
|
|
75894
|
+
import { methods as methods11 } from "@agentclientprotocol/sdk";
|
|
75876
75895
|
|
|
75877
75896
|
// src/engine/acp/client/prompt-content.ts
|
|
75878
75897
|
function validatePromptContent(options, capabilities) {
|
|
@@ -75930,22 +75949,6 @@ function buildPromptContent(options, capabilities) {
|
|
|
75930
75949
|
return prompt;
|
|
75931
75950
|
}
|
|
75932
75951
|
|
|
75933
|
-
// src/engine/acp/protocol/native-session.ts
|
|
75934
|
-
var path6 = external_exports.string().min(1).max(2048).refine((value) => !value.includes("\0"));
|
|
75935
|
-
var title = external_exports.string().transform((value) => value.slice(0, 500));
|
|
75936
|
-
var nativeSessionIdSchema = external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,255}$/);
|
|
75937
|
-
var nativeSessionInfoSchema = external_exports.object({
|
|
75938
|
-
sessionId: nativeSessionIdSchema,
|
|
75939
|
-
cwd: path6,
|
|
75940
|
-
additionalDirectories: external_exports.array(path6).max(16).default([]).readonly(),
|
|
75941
|
-
title: title.nullish(),
|
|
75942
|
-
updatedAt: external_exports.iso.datetime({ offset: true }).nullish()
|
|
75943
|
-
}).readonly();
|
|
75944
|
-
var nativeSessionPageSchema = external_exports.object({
|
|
75945
|
-
sessions: external_exports.array(nativeSessionInfoSchema).max(500).readonly(),
|
|
75946
|
-
nextCursor: external_exports.string().min(1).max(4096).nullish()
|
|
75947
|
-
}).readonly();
|
|
75948
|
-
|
|
75949
75952
|
// src/engine/acp/protocol/session-config-protocol.ts
|
|
75950
75953
|
import { methods as methods9 } from "@agentclientprotocol/sdk";
|
|
75951
75954
|
var MAXIMUM_CONFIG_OPTIONS = 100;
|
|
@@ -76258,6 +76261,101 @@ var AgentUpdateStream = class {
|
|
|
76258
76261
|
};
|
|
76259
76262
|
};
|
|
76260
76263
|
|
|
76264
|
+
// src/engine/acp/adapter/agent-initialization.ts
|
|
76265
|
+
import { methods as methods10, PROTOCOL_VERSION as PROTOCOL_VERSION3 } from "@agentclientprotocol/sdk";
|
|
76266
|
+
var RetryableAcpInitializationError = class extends AcpExecutionError {
|
|
76267
|
+
constructor(cause) {
|
|
76268
|
+
super("ACP agent initialization failed", { cause });
|
|
76269
|
+
this.name = "RetryableAcpInitializationError";
|
|
76270
|
+
}
|
|
76271
|
+
};
|
|
76272
|
+
async function validateAgentRuntime(agent, signal) {
|
|
76273
|
+
signal.throwIfAborted();
|
|
76274
|
+
const unchanged = await Promise.all(agent.runtimeExecutables.map((identity2) => revalidateExecutable(identity2)));
|
|
76275
|
+
signal.throwIfAborted();
|
|
76276
|
+
if (unchanged.some((result) => !result)) {
|
|
76277
|
+
throw new AcpExecutionError(
|
|
76278
|
+
"The local Agent runtime changed; restart Mobius before starting a new conversation",
|
|
76279
|
+
{},
|
|
76280
|
+
"agent_runtime_changed"
|
|
76281
|
+
);
|
|
76282
|
+
}
|
|
76283
|
+
}
|
|
76284
|
+
async function initializeAgentConnection(connection, agentId, verifiedVersion, signal) {
|
|
76285
|
+
await connection.race(connection.initialize(signal), "The Agent runtime exited during initialization", signal).catch((cause) => {
|
|
76286
|
+
signal.throwIfAborted();
|
|
76287
|
+
throw new RetryableAcpInitializationError(cause);
|
|
76288
|
+
});
|
|
76289
|
+
const initialized = await connection.race(
|
|
76290
|
+
connection.connection.agent.request(
|
|
76291
|
+
methods10.agent.initialize,
|
|
76292
|
+
{
|
|
76293
|
+
clientCapabilities: {
|
|
76294
|
+
elicitation: { form: {}, url: {} },
|
|
76295
|
+
plan: {},
|
|
76296
|
+
session: { compaction: {}, configOptions: { boolean: {} } }
|
|
76297
|
+
},
|
|
76298
|
+
clientInfo: { name: "mobius", version: "0.0.3" },
|
|
76299
|
+
protocolVersion: PROTOCOL_VERSION3
|
|
76300
|
+
},
|
|
76301
|
+
{ cancellationSignal: signal }
|
|
76302
|
+
),
|
|
76303
|
+
"ACP agent exited during initialization",
|
|
76304
|
+
signal
|
|
76305
|
+
).catch((cause) => {
|
|
76306
|
+
signal.throwIfAborted();
|
|
76307
|
+
throw new RetryableAcpInitializationError(cause);
|
|
76308
|
+
});
|
|
76309
|
+
if (initialized.protocolVersion !== PROTOCOL_VERSION3) {
|
|
76310
|
+
throw new AcpExecutionError(
|
|
76311
|
+
"ACP agent selected an unsupported protocol version",
|
|
76312
|
+
{},
|
|
76313
|
+
"unsupported_acp_protocol"
|
|
76314
|
+
);
|
|
76315
|
+
}
|
|
76316
|
+
return {
|
|
76317
|
+
capabilities: normalizeAcpCapabilities(initialized),
|
|
76318
|
+
agentName: truncate(initialized.agentInfo?.title ?? initialized.agentInfo?.name ?? agentId, 255),
|
|
76319
|
+
agentVersion: truncate(
|
|
76320
|
+
verifiedVersion.length > 0 ? verifiedVersion : initialized.agentInfo?.version ?? "",
|
|
76321
|
+
128
|
|
76322
|
+
)
|
|
76323
|
+
};
|
|
76324
|
+
}
|
|
76325
|
+
|
|
76326
|
+
// src/engine/acp/adapter/configuration-changes.ts
|
|
76327
|
+
function recordConfigurationOptions(changes, options) {
|
|
76328
|
+
const modes = options.filter((option) => option.category === "mode");
|
|
76329
|
+
const selection = modes.length > 0 ? { kind: "unchanged" } : changes.kind === "mode" ? { kind: "selected", modeId: changes.modeId } : changes.kind === "replacement" ? changes.selection : { kind: "unchanged" };
|
|
76330
|
+
return {
|
|
76331
|
+
kind: "replacement",
|
|
76332
|
+
options,
|
|
76333
|
+
modes: modes.length > 0 ? modes : changes.kind === "replacement" ? changes.modes : [],
|
|
76334
|
+
selection
|
|
76335
|
+
};
|
|
76336
|
+
}
|
|
76337
|
+
function recordConfigurationMode(changes, modeId) {
|
|
76338
|
+
return changes.kind === "replacement" ? { ...changes, selection: { kind: "selected", modeId } } : { kind: "mode", modeId };
|
|
76339
|
+
}
|
|
76340
|
+
function applyConfigurationMode(options, modeId) {
|
|
76341
|
+
return options.map((option) => option.category === "mode" ? { ...option, currentValue: modeId } : option);
|
|
76342
|
+
}
|
|
76343
|
+
function applyConfigurationChanges(base, changes) {
|
|
76344
|
+
switch (changes.kind) {
|
|
76345
|
+
case "unchanged":
|
|
76346
|
+
return base;
|
|
76347
|
+
case "mode":
|
|
76348
|
+
return applyConfigurationMode(base, changes.modeId);
|
|
76349
|
+
case "replacement": {
|
|
76350
|
+
const options = changes.options.some((option) => option.category === "mode") ? changes.options : [
|
|
76351
|
+
...changes.modes.length > 0 ? changes.modes : base.filter((option) => option.category === "mode"),
|
|
76352
|
+
...changes.options
|
|
76353
|
+
].slice(0, MAXIMUM_CONFIG_OPTIONS);
|
|
76354
|
+
return changes.selection.kind === "selected" ? applyConfigurationMode(options, changes.selection.modeId) : options;
|
|
76355
|
+
}
|
|
76356
|
+
}
|
|
76357
|
+
}
|
|
76358
|
+
|
|
76261
76359
|
// src/engine/acp/adapter/session-events.ts
|
|
76262
76360
|
var AdapterSessionConnection = class {
|
|
76263
76361
|
#connection;
|
|
@@ -76267,19 +76365,24 @@ var AdapterSessionConnection = class {
|
|
|
76267
76365
|
#updates;
|
|
76268
76366
|
#lifetime = new AbortController();
|
|
76269
76367
|
#onClosed;
|
|
76368
|
+
#agent;
|
|
76369
|
+
#state = { kind: "uninitialized" };
|
|
76370
|
+
#initialization = {
|
|
76371
|
+
kind: "not-started"
|
|
76372
|
+
};
|
|
76270
76373
|
events;
|
|
76271
76374
|
constructor(options, externalizer, normalizeEvent, onClosed = () => void 0) {
|
|
76375
|
+
this.#agent = options.agent;
|
|
76272
76376
|
this.#onClosed = onClosed;
|
|
76273
76377
|
this.#onBackgroundActivity = options.onBackgroundActivity ?? (() => {
|
|
76274
76378
|
});
|
|
76275
|
-
const protocol = sessionConfigProtocolForAgent(options.agent.id);
|
|
76276
76379
|
this.#updates = new AgentUpdateStream(async (notification) => {
|
|
76277
76380
|
this.#lifetime.signal.throwIfAborted();
|
|
76278
76381
|
if (notification.sessionId !== this.#updates.sessionId()) {
|
|
76279
76382
|
throw new AcpExecutionError("ACP agent referenced an unknown session", {}, "invalid_agent_session");
|
|
76280
76383
|
}
|
|
76281
76384
|
const signal = AbortSignal.any([this.#lifetime.signal, AbortSignal.timeout(3e4)]);
|
|
76282
|
-
const externalized = await externalizer.update(
|
|
76385
|
+
const externalized = options.externalizeUpdate === void 0 ? await externalizer.update(notification.sessionId, notification.update, signal) : await options.externalizeUpdate(notification.update, signal);
|
|
76283
76386
|
signal.throwIfAborted();
|
|
76284
76387
|
const update = externalized.agent;
|
|
76285
76388
|
for (const eventUpdate of externalized.events) {
|
|
@@ -76305,13 +76408,15 @@ var AdapterSessionConnection = class {
|
|
|
76305
76408
|
};
|
|
76306
76409
|
break;
|
|
76307
76410
|
case "config_option_update":
|
|
76411
|
+
this.#applyConfigurationUpdate(update.configOptions);
|
|
76308
76412
|
event = {
|
|
76309
76413
|
kind: "configuration",
|
|
76310
76414
|
payload,
|
|
76311
|
-
configOptions:
|
|
76415
|
+
configOptions: this.snapshot().configOptions
|
|
76312
76416
|
};
|
|
76313
76417
|
break;
|
|
76314
76418
|
case "current_mode_update":
|
|
76419
|
+
this.#applyModeUpdate(update.currentModeId);
|
|
76315
76420
|
event = { kind: "mode", payload, modeId: update.currentModeId };
|
|
76316
76421
|
break;
|
|
76317
76422
|
case "session_info_update": {
|
|
@@ -76383,10 +76488,92 @@ var AdapterSessionConnection = class {
|
|
|
76383
76488
|
get termination() {
|
|
76384
76489
|
return this.#connection.termination;
|
|
76385
76490
|
}
|
|
76491
|
+
#ready = () => {
|
|
76492
|
+
const state = this.#state;
|
|
76493
|
+
if (state.kind !== "ready") {
|
|
76494
|
+
throw new AcpExecutionError(
|
|
76495
|
+
"The Agent session is not initialized or has closed",
|
|
76496
|
+
{},
|
|
76497
|
+
"invalid_agent_session"
|
|
76498
|
+
);
|
|
76499
|
+
}
|
|
76500
|
+
return state;
|
|
76501
|
+
};
|
|
76502
|
+
snapshot = () => this.#ready().snapshot;
|
|
76503
|
+
beginStateChange = () => {
|
|
76504
|
+
const state = this.#ready();
|
|
76505
|
+
if (state.operation.kind !== "idle") {
|
|
76506
|
+
throw new AcpExecutionError("Another session configuration operation is running", {}, "session_busy");
|
|
76507
|
+
}
|
|
76508
|
+
this.#state = { ...state, operation: { kind: "pending", changes: { kind: "unchanged" } } };
|
|
76509
|
+
};
|
|
76510
|
+
cancelStateChange = () => {
|
|
76511
|
+
if (this.#state.kind === "ready") {
|
|
76512
|
+
this.#state = { ...this.#state, operation: { kind: "idle" } };
|
|
76513
|
+
}
|
|
76514
|
+
};
|
|
76515
|
+
commitConfiguration = (options) => {
|
|
76516
|
+
const state = this.#ready();
|
|
76517
|
+
if (state.operation.kind !== "pending") {
|
|
76518
|
+
throw new AcpExecutionError("No session configuration operation is running", {}, "invalid_agent_session");
|
|
76519
|
+
}
|
|
76520
|
+
const configOptions = applyConfigurationChanges(options, state.operation.changes);
|
|
76521
|
+
this.#state = { ...state, snapshot: { ...state.snapshot, configOptions }, operation: { kind: "idle" } };
|
|
76522
|
+
return configOptions;
|
|
76523
|
+
};
|
|
76524
|
+
commitLifecycle = (response) => {
|
|
76525
|
+
const state = this.#ready();
|
|
76526
|
+
const capabilities = restrictAcpSessionCapabilities(state.snapshot.capabilities, response);
|
|
76527
|
+
this.commitConfiguration(sessionConfigProtocolForAgent(this.#agent.id).normalizeLifecycle(response));
|
|
76528
|
+
this.#state = { ...this.#ready(), snapshot: { capabilities, configOptions: this.snapshot().configOptions } };
|
|
76529
|
+
return this.snapshot();
|
|
76530
|
+
};
|
|
76531
|
+
#applyConfigurationUpdate = (value) => {
|
|
76532
|
+
const state = this.#ready();
|
|
76533
|
+
const protocol = sessionConfigProtocolForAgent(this.#agent.id);
|
|
76534
|
+
const configOptions = protocol.normalizeUpdate(state.snapshot.configOptions, value);
|
|
76535
|
+
const operation = state.operation.kind === "pending" ? {
|
|
76536
|
+
kind: "pending",
|
|
76537
|
+
changes: recordConfigurationOptions(state.operation.changes, protocol.normalizeUpdate([], value))
|
|
76538
|
+
} : state.operation;
|
|
76539
|
+
this.#state = { ...state, snapshot: { ...state.snapshot, configOptions }, operation };
|
|
76540
|
+
};
|
|
76541
|
+
#applyModeUpdate = (modeId) => {
|
|
76542
|
+
const state = this.#ready();
|
|
76543
|
+
const operation = state.operation.kind === "pending" ? { kind: "pending", changes: recordConfigurationMode(state.operation.changes, modeId) } : state.operation;
|
|
76544
|
+
this.#state = {
|
|
76545
|
+
...state,
|
|
76546
|
+
snapshot: {
|
|
76547
|
+
...state.snapshot,
|
|
76548
|
+
configOptions: applyConfigurationMode(state.snapshot.configOptions, modeId)
|
|
76549
|
+
},
|
|
76550
|
+
operation
|
|
76551
|
+
};
|
|
76552
|
+
};
|
|
76386
76553
|
initialize = (signal) => this.#connection.initialize(signal);
|
|
76554
|
+
initializeAgent = (signal) => {
|
|
76555
|
+
if (this.#initialization.kind === "not-started") {
|
|
76556
|
+
this.#initialization = {
|
|
76557
|
+
kind: "started",
|
|
76558
|
+
result: initializeAgentConnection(this, this.#agent.id, this.#agent.agentVersion, signal).then(
|
|
76559
|
+
(agent) => {
|
|
76560
|
+
this.#lifetime.signal.throwIfAborted();
|
|
76561
|
+
this.#state = {
|
|
76562
|
+
kind: "ready",
|
|
76563
|
+
snapshot: { capabilities: agent.capabilities, configOptions: [] },
|
|
76564
|
+
operation: { kind: "idle" }
|
|
76565
|
+
};
|
|
76566
|
+
return agent;
|
|
76567
|
+
}
|
|
76568
|
+
)
|
|
76569
|
+
};
|
|
76570
|
+
}
|
|
76571
|
+
return this.#initialization.result;
|
|
76572
|
+
};
|
|
76387
76573
|
agentSettingsModelEffort = () => this.#connection.agentSettingsModelEffort();
|
|
76388
76574
|
race = (operation, exitMessage, signal) => this.#connection.race(operation, exitMessage, signal);
|
|
76389
76575
|
closeProcess = async () => {
|
|
76576
|
+
this.#state = { kind: "closed" };
|
|
76390
76577
|
this.#lifetime.abort(new DOMException("The adapter event subscription closed", "AbortError"));
|
|
76391
76578
|
try {
|
|
76392
76579
|
await this.#connection.closeProcess();
|
|
@@ -76432,14 +76619,14 @@ var AcpSessionConnector = class {
|
|
|
76432
76619
|
};
|
|
76433
76620
|
};
|
|
76434
76621
|
|
|
76435
|
-
// src/engine/acp/adapter/
|
|
76622
|
+
// src/engine/acp/adapter/execution-connections.ts
|
|
76436
76623
|
var absolutePathSchema = external_exports.string().min(1).refine(isAbsolute14);
|
|
76437
76624
|
var targetSchema = external_exports.object({
|
|
76438
76625
|
nativeSessionId: nativeSessionIdSchema,
|
|
76439
76626
|
cwd: absolutePathSchema,
|
|
76440
76627
|
additionalDirectories: external_exports.array(absolutePathSchema)
|
|
76441
76628
|
});
|
|
76442
|
-
var
|
|
76629
|
+
var AcpExecutionConnections = class {
|
|
76443
76630
|
#sessions = /* @__PURE__ */ new Set();
|
|
76444
76631
|
#externalizer;
|
|
76445
76632
|
#normalizeEvent;
|
|
@@ -76447,16 +76634,72 @@ var AcpLiveSessions = class {
|
|
|
76447
76634
|
this.#externalizer = externalizer;
|
|
76448
76635
|
this.#normalizeEvent = normalizeEvent;
|
|
76449
76636
|
}
|
|
76450
|
-
|
|
76637
|
+
acquire = (params) => {
|
|
76638
|
+
params.signal.throwIfAborted();
|
|
76639
|
+
const existing = [...this.#sessions].find(
|
|
76640
|
+
({ subscriber }) => subscriber.onSessionEvent === params.onSessionEvent
|
|
76641
|
+
);
|
|
76642
|
+
if (existing !== void 0) {
|
|
76643
|
+
if (existing.scope.agent !== params.scope.agent || existing.scope.cwd !== params.scope.cwd || !arraysEqual(existing.scope.additionalDirectories, params.scope.additionalDirectories)) {
|
|
76644
|
+
throw new AcpExecutionError(
|
|
76645
|
+
"The agent or workspace cannot change after a conversation has started",
|
|
76646
|
+
{},
|
|
76647
|
+
"session_identity_mismatch"
|
|
76648
|
+
);
|
|
76649
|
+
}
|
|
76650
|
+
return existing;
|
|
76651
|
+
}
|
|
76451
76652
|
const connection = new AdapterSessionConnection(
|
|
76452
|
-
|
|
76653
|
+
{
|
|
76654
|
+
agent: params.scope.agent,
|
|
76655
|
+
cwd: params.scope.cwd,
|
|
76656
|
+
...params.scope.externalizeUpdate === void 0 ? {} : { externalizeUpdate: params.scope.externalizeUpdate },
|
|
76657
|
+
onEvent: (event) => params.onSessionEvent(connection.events.sessionId(), event),
|
|
76658
|
+
...params.onBackgroundActivity === void 0 ? {} : { onBackgroundActivity: params.onBackgroundActivity },
|
|
76659
|
+
interactions: params.interactions
|
|
76660
|
+
},
|
|
76453
76661
|
this.#externalizer,
|
|
76454
76662
|
this.#normalizeEvent,
|
|
76455
76663
|
() => this.#sessions.delete(session)
|
|
76456
76664
|
);
|
|
76457
|
-
const session = { connection, scope };
|
|
76665
|
+
const session = { connection, scope: params.scope, subscriber: params };
|
|
76458
76666
|
this.#sessions.add(session);
|
|
76459
|
-
return
|
|
76667
|
+
return session;
|
|
76668
|
+
};
|
|
76669
|
+
/** Resource scope only: the concrete adapter supplies the protocol operation. */
|
|
76670
|
+
withConnection = async (params, operation) => {
|
|
76671
|
+
const signal = AbortSignal.any([params.signal, AbortSignal.timeout(6e4)]);
|
|
76672
|
+
signal.throwIfAborted();
|
|
76673
|
+
const session = this.acquire(params);
|
|
76674
|
+
const wasBound = session.connection.events.sessionId().length > 0;
|
|
76675
|
+
try {
|
|
76676
|
+
await session.connection.initializeAgent(signal);
|
|
76677
|
+
session.connection.beginStateChange();
|
|
76678
|
+
try {
|
|
76679
|
+
const result = await operation(session, signal);
|
|
76680
|
+
signal.throwIfAborted();
|
|
76681
|
+
return result;
|
|
76682
|
+
} catch (cause) {
|
|
76683
|
+
session.connection.cancelStateChange();
|
|
76684
|
+
throw cause;
|
|
76685
|
+
}
|
|
76686
|
+
} catch (cause) {
|
|
76687
|
+
if (!wasBound) {
|
|
76688
|
+
await session.connection.closeProcess();
|
|
76689
|
+
}
|
|
76690
|
+
throw cause;
|
|
76691
|
+
}
|
|
76692
|
+
};
|
|
76693
|
+
bind = (session, nativeSessionId) => {
|
|
76694
|
+
const existing = this.#find({
|
|
76695
|
+
nativeSessionId,
|
|
76696
|
+
cwd: session.scope.cwd,
|
|
76697
|
+
additionalDirectories: session.scope.additionalDirectories
|
|
76698
|
+
});
|
|
76699
|
+
if (existing !== void 0 && existing !== session) {
|
|
76700
|
+
throw new AcpExecutionError("Another writer is using this native session", {}, "session_busy");
|
|
76701
|
+
}
|
|
76702
|
+
session.connection.events.select(nativeSessionId);
|
|
76460
76703
|
};
|
|
76461
76704
|
#find = (target) => {
|
|
76462
76705
|
const decoded = targetSchema.safeParse(target);
|
|
@@ -76485,12 +76728,12 @@ var AcpLiveSessions = class {
|
|
|
76485
76728
|
}
|
|
76486
76729
|
return session;
|
|
76487
76730
|
};
|
|
76488
|
-
cancel = async (
|
|
76731
|
+
cancel = async ({ signal, ...target }) => {
|
|
76489
76732
|
const bounded = AbortSignal.any([signal, AbortSignal.timeout(3e4)]);
|
|
76490
76733
|
bounded.throwIfAborted();
|
|
76491
76734
|
const { connection } = this.#resolve(target);
|
|
76492
76735
|
await connection.race(
|
|
76493
|
-
connection.connection.agent.notify(
|
|
76736
|
+
connection.connection.agent.notify(methods11.agent.session.cancel, {
|
|
76494
76737
|
sessionId: connection.events.sessionId()
|
|
76495
76738
|
}),
|
|
76496
76739
|
"ACP agent exited while cancelling a prompt",
|
|
@@ -76498,19 +76741,19 @@ var AcpLiveSessions = class {
|
|
|
76498
76741
|
);
|
|
76499
76742
|
return "retained";
|
|
76500
76743
|
};
|
|
76501
|
-
closeSession = async (
|
|
76744
|
+
closeSession = async ({ signal, ...target }) => {
|
|
76502
76745
|
const session = this.#find(target);
|
|
76503
76746
|
if (session === void 0) {
|
|
76504
76747
|
signal.throwIfAborted();
|
|
76505
76748
|
return;
|
|
76506
76749
|
}
|
|
76507
|
-
const { connection
|
|
76750
|
+
const { connection } = session;
|
|
76508
76751
|
try {
|
|
76509
76752
|
signal.throwIfAborted();
|
|
76510
|
-
if (
|
|
76753
|
+
if (connection.snapshot().capabilities.closeSession) {
|
|
76511
76754
|
try {
|
|
76512
76755
|
await connection.connection.agent.request(
|
|
76513
|
-
|
|
76756
|
+
methods11.agent.session.close,
|
|
76514
76757
|
{ sessionId: connection.events.sessionId() },
|
|
76515
76758
|
{ cancellationSignal: AbortSignal.any([signal, AbortSignal.timeout(1e3)]) }
|
|
76516
76759
|
);
|
|
@@ -76523,13 +76766,20 @@ var AcpLiveSessions = class {
|
|
|
76523
76766
|
}
|
|
76524
76767
|
signal.throwIfAborted();
|
|
76525
76768
|
};
|
|
76526
|
-
|
|
76769
|
+
releaseSession = async ({ signal, ...target }) => {
|
|
76770
|
+
const session = this.#find(target);
|
|
76771
|
+
if (session !== void 0) {
|
|
76772
|
+
await session.connection.closeProcess();
|
|
76773
|
+
}
|
|
76527
76774
|
signal.throwIfAborted();
|
|
76528
|
-
|
|
76529
|
-
|
|
76775
|
+
};
|
|
76776
|
+
prompt = async ({ content, signal, ...target }) => {
|
|
76777
|
+
signal.throwIfAborted();
|
|
76778
|
+
const { connection } = this.#resolve(target);
|
|
76779
|
+
const prompt = buildPromptContent(content, connection.snapshot().capabilities);
|
|
76530
76780
|
const response = await connection.race(
|
|
76531
76781
|
connection.connection.agent.request(
|
|
76532
|
-
|
|
76782
|
+
methods11.agent.session.prompt,
|
|
76533
76783
|
{ prompt, sessionId: target.nativeSessionId },
|
|
76534
76784
|
{ cancellationSignal: signal }
|
|
76535
76785
|
),
|
|
@@ -76556,10 +76806,10 @@ var AcpLiveSessions = class {
|
|
|
76556
76806
|
);
|
|
76557
76807
|
}
|
|
76558
76808
|
};
|
|
76559
|
-
steer = async (
|
|
76809
|
+
steer = async ({ content, signal, ...target }) => {
|
|
76560
76810
|
signal.throwIfAborted();
|
|
76561
|
-
const { connection
|
|
76562
|
-
if (!
|
|
76811
|
+
const { connection } = this.#resolve(target);
|
|
76812
|
+
if (!connection.snapshot().capabilities.steering) {
|
|
76563
76813
|
throw new AcpExecutionError(
|
|
76564
76814
|
"The selected agent does not support mid-turn steering",
|
|
76565
76815
|
{},
|
|
@@ -76571,7 +76821,7 @@ var AcpLiveSessions = class {
|
|
|
76571
76821
|
"_session/steering",
|
|
76572
76822
|
{
|
|
76573
76823
|
_meta: { steering: { idleBehavior: "promptRequired" } },
|
|
76574
|
-
prompt: buildPromptContent(content,
|
|
76824
|
+
prompt: buildPromptContent(content, connection.snapshot().capabilities),
|
|
76575
76825
|
sessionId: target.nativeSessionId
|
|
76576
76826
|
},
|
|
76577
76827
|
{ cancellationSignal: signal }
|
|
@@ -76601,14 +76851,14 @@ var AcpLiveSessions = class {
|
|
|
76601
76851
|
"acp_invalid_steering_response"
|
|
76602
76852
|
);
|
|
76603
76853
|
};
|
|
76604
|
-
renameSession = async (
|
|
76854
|
+
renameSession = async ({ title: title2, signal, ...target }) => {
|
|
76605
76855
|
signal.throwIfAborted();
|
|
76606
|
-
const { connection
|
|
76856
|
+
const { connection } = this.#resolve(target);
|
|
76607
76857
|
const normalized = truncate(title2, 500);
|
|
76608
76858
|
if (normalized.length === 0) {
|
|
76609
76859
|
throw new AcpExecutionError("The Session title cannot be empty", {}, "invalid_session_title");
|
|
76610
76860
|
}
|
|
76611
|
-
if (!
|
|
76861
|
+
if (!connection.snapshot().capabilities.renameSession) {
|
|
76612
76862
|
return { nativeRenameApplied: false };
|
|
76613
76863
|
}
|
|
76614
76864
|
try {
|
|
@@ -76634,10 +76884,14 @@ var AcpLiveSessions = class {
|
|
|
76634
76884
|
}
|
|
76635
76885
|
return { nativeRenameApplied: true };
|
|
76636
76886
|
};
|
|
76637
|
-
configureSession = async (
|
|
76887
|
+
configureSession = async ({
|
|
76888
|
+
selection,
|
|
76889
|
+
signal,
|
|
76890
|
+
...target
|
|
76891
|
+
}) => {
|
|
76638
76892
|
signal.throwIfAborted();
|
|
76639
76893
|
const { connection, scope } = this.#resolve(target);
|
|
76640
|
-
const current =
|
|
76894
|
+
const current = connection.snapshot().configOptions;
|
|
76641
76895
|
const existing = current.find((option) => option.id === selection.configId);
|
|
76642
76896
|
if (existing === void 0 || existing.type !== selection.type || existing.type === "select" && existing.values.length < 2) {
|
|
76643
76897
|
throw new AcpExecutionError(
|
|
@@ -76653,6 +76907,7 @@ var AcpLiveSessions = class {
|
|
|
76653
76907
|
existing.values.map((entry) => entry.value)
|
|
76654
76908
|
);
|
|
76655
76909
|
}
|
|
76910
|
+
connection.beginStateChange();
|
|
76656
76911
|
try {
|
|
76657
76912
|
const configured = await sessionConfigProtocolForAgent(scope.agent.id).configure(
|
|
76658
76913
|
current,
|
|
@@ -76680,8 +76935,9 @@ var AcpLiveSessions = class {
|
|
|
76680
76935
|
);
|
|
76681
76936
|
}
|
|
76682
76937
|
await connection.events.drained();
|
|
76683
|
-
return configured;
|
|
76938
|
+
return connection.commitConfiguration(configured);
|
|
76684
76939
|
} catch (error62) {
|
|
76940
|
+
connection.cancelStateChange();
|
|
76685
76941
|
if (error62 instanceof SessionConfigProtocolError) {
|
|
76686
76942
|
throw new AcpExecutionError(error62.message, { cause: error62 }, error62.code);
|
|
76687
76943
|
}
|
|
@@ -76700,6 +76956,38 @@ var AcpLiveSessions = class {
|
|
|
76700
76956
|
};
|
|
76701
76957
|
};
|
|
76702
76958
|
|
|
76959
|
+
// src/engine/acp/adapter/lifecycle-output.ts
|
|
76960
|
+
function sessionWorkspace(scope) {
|
|
76961
|
+
return { cwd: scope.cwd, additionalDirectories: [...scope.additionalDirectories], mcpServers: [] };
|
|
76962
|
+
}
|
|
76963
|
+
function createdNativeSessionId(response) {
|
|
76964
|
+
const decoded = external_exports.object({ sessionId: nativeSessionIdSchema }).safeParse(response);
|
|
76965
|
+
if (!decoded.success) {
|
|
76966
|
+
throw new AcpExecutionError(
|
|
76967
|
+
"The Agent returned an invalid native session",
|
|
76968
|
+
{ cause: decoded.error },
|
|
76969
|
+
"invalid_native_session_response"
|
|
76970
|
+
);
|
|
76971
|
+
}
|
|
76972
|
+
return decoded.data.sessionId;
|
|
76973
|
+
}
|
|
76974
|
+
async function normalizeOpenedSession(session, nativeSessionId, response, signal) {
|
|
76975
|
+
await session.connection.race(
|
|
76976
|
+
session.connection.events.drained(),
|
|
76977
|
+
"ACP agent exited while opening a session",
|
|
76978
|
+
signal
|
|
76979
|
+
);
|
|
76980
|
+
signal.throwIfAborted();
|
|
76981
|
+
const initialized = await session.connection.initializeAgent(signal);
|
|
76982
|
+
return {
|
|
76983
|
+
nativeSessionId,
|
|
76984
|
+
agentName: initialized.agentName,
|
|
76985
|
+
agentVersion: initialized.agentVersion,
|
|
76986
|
+
agentSettingsModelEffort: session.connection.agentSettingsModelEffort(),
|
|
76987
|
+
...session.connection.commitLifecycle(response)
|
|
76988
|
+
};
|
|
76989
|
+
}
|
|
76990
|
+
|
|
76703
76991
|
// src/engine/acp/adapter/native-session-lookup.ts
|
|
76704
76992
|
var lookupSchema = external_exports.object({
|
|
76705
76993
|
nativeSessionId: nativeSessionIdSchema,
|
|
@@ -76708,7 +76996,7 @@ var lookupSchema = external_exports.object({
|
|
|
76708
76996
|
maximumEntries: external_exports.number().int().positive().nullable()
|
|
76709
76997
|
})
|
|
76710
76998
|
});
|
|
76711
|
-
async function findNativeSession(list,
|
|
76999
|
+
async function findNativeSession(list, query, nativeSessionId, budget) {
|
|
76712
77000
|
const decoded = lookupSchema.safeParse({ nativeSessionId, budget });
|
|
76713
77001
|
if (!decoded.success) {
|
|
76714
77002
|
throw new AcpExecutionError(
|
|
@@ -76722,9 +77010,9 @@ async function findNativeSession(list, cwd, nativeSessionId, budget, signal) {
|
|
|
76722
77010
|
let inspected = 0;
|
|
76723
77011
|
const visited = /* @__PURE__ */ new Set();
|
|
76724
77012
|
for (let pageNumber = 0; pageNumber < limits.maximumPages; pageNumber += 1) {
|
|
76725
|
-
signal.throwIfAborted();
|
|
76726
|
-
const page = await list(
|
|
76727
|
-
signal.throwIfAborted();
|
|
77013
|
+
query.signal.throwIfAborted();
|
|
77014
|
+
const page = await list({ query, cursor });
|
|
77015
|
+
query.signal.throwIfAborted();
|
|
76728
77016
|
inspected += page.sessions.length;
|
|
76729
77017
|
const found = page.sessions.find((session) => session.sessionId === decoded.data.nativeSessionId);
|
|
76730
77018
|
if (found !== void 0) {
|
|
@@ -76746,9 +77034,6 @@ async function findNativeSession(list, cwd, nativeSessionId, budget, signal) {
|
|
|
76746
77034
|
throw new AcpExecutionError("The native session was not found", {}, "native_session_not_found");
|
|
76747
77035
|
}
|
|
76748
77036
|
|
|
76749
|
-
// src/engine/acp/adapter/query-processes.ts
|
|
76750
|
-
import { randomUUID as randomUUID14 } from "node:crypto";
|
|
76751
|
-
|
|
76752
77037
|
// src/engine/session/history/session-event-store.ts
|
|
76753
77038
|
import { randomUUID as randomUUID13 } from "node:crypto";
|
|
76754
77039
|
|
|
@@ -77390,112 +77675,53 @@ var RetainedAgentProcesses = class {
|
|
|
77390
77675
|
};
|
|
77391
77676
|
};
|
|
77392
77677
|
|
|
77393
|
-
// src/engine/acp/adapter/query-
|
|
77394
|
-
|
|
77395
|
-
|
|
77396
|
-
|
|
77397
|
-
|
|
77398
|
-
|
|
77399
|
-
|
|
77400
|
-
|
|
77401
|
-
|
|
77402
|
-
|
|
77403
|
-
|
|
77404
|
-
|
|
77405
|
-
signal.throwIfAborted();
|
|
77406
|
-
const unchanged = await Promise.all(agent.runtimeExecutables.map((identity2) => revalidateExecutable(identity2)));
|
|
77407
|
-
signal.throwIfAborted();
|
|
77408
|
-
if (unchanged.some((result) => !result)) {
|
|
77409
|
-
throw new AcpExecutionError(
|
|
77410
|
-
"The local Agent runtime changed; restart Mobius before starting a new conversation",
|
|
77411
|
-
{},
|
|
77412
|
-
"agent_runtime_changed"
|
|
77413
|
-
);
|
|
77414
|
-
}
|
|
77678
|
+
// src/engine/acp/adapter/query-scope.ts
|
|
77679
|
+
var queryKeySchema = external_exports.string().brand();
|
|
77680
|
+
var previewKeySchema = external_exports.string().brand();
|
|
77681
|
+
function nativeSessionQueryKey(query) {
|
|
77682
|
+
return queryKeySchema.parse(
|
|
77683
|
+
JSON.stringify([
|
|
77684
|
+
query.agent.id,
|
|
77685
|
+
query.cwd,
|
|
77686
|
+
query.additionalDirectories,
|
|
77687
|
+
Object.entries(query.agent.environment).sort(([left], [right]) => left.localeCompare(right))
|
|
77688
|
+
])
|
|
77689
|
+
);
|
|
77415
77690
|
}
|
|
77416
|
-
|
|
77417
|
-
|
|
77418
|
-
signal.throwIfAborted();
|
|
77419
|
-
throw new RetryableAcpInitializationError(cause);
|
|
77420
|
-
});
|
|
77421
|
-
const initialized = await connection.race(
|
|
77422
|
-
connection.connection.agent.request(
|
|
77423
|
-
methods11.agent.initialize,
|
|
77424
|
-
{
|
|
77425
|
-
clientCapabilities: {
|
|
77426
|
-
elicitation: { form: {}, url: {} },
|
|
77427
|
-
plan: {},
|
|
77428
|
-
session: { compaction: {}, configOptions: { boolean: {} } }
|
|
77429
|
-
},
|
|
77430
|
-
clientInfo: { name: "mobius", version: "0.0.3" },
|
|
77431
|
-
protocolVersion: PROTOCOL_VERSION3
|
|
77432
|
-
},
|
|
77433
|
-
{ cancellationSignal: signal }
|
|
77434
|
-
),
|
|
77435
|
-
"ACP agent exited during initialization",
|
|
77436
|
-
signal
|
|
77437
|
-
).catch((cause) => {
|
|
77438
|
-
signal.throwIfAborted();
|
|
77439
|
-
throw new RetryableAcpInitializationError(cause);
|
|
77440
|
-
});
|
|
77441
|
-
if (initialized.protocolVersion !== PROTOCOL_VERSION3) {
|
|
77442
|
-
throw new AcpExecutionError(
|
|
77443
|
-
"ACP agent selected an unsupported protocol version",
|
|
77444
|
-
{},
|
|
77445
|
-
"unsupported_acp_protocol"
|
|
77446
|
-
);
|
|
77447
|
-
}
|
|
77448
|
-
return {
|
|
77449
|
-
capabilities: normalizeAcpCapabilities(initialized),
|
|
77450
|
-
agentName: truncate(initialized.agentInfo?.title ?? initialized.agentInfo?.name ?? agentId, 255),
|
|
77451
|
-
agentVersion: truncate(
|
|
77452
|
-
verifiedVersion.length > 0 ? verifiedVersion : initialized.agentInfo?.version ?? "",
|
|
77453
|
-
128
|
|
77454
|
-
)
|
|
77455
|
-
};
|
|
77691
|
+
function nativeSessionPreviewKey(queryKey, nativeSessionId) {
|
|
77692
|
+
return previewKeySchema.parse(JSON.stringify([queryKey, nativeSessionId]));
|
|
77456
77693
|
}
|
|
77457
77694
|
|
|
77458
77695
|
// src/engine/acp/adapter/query-session.ts
|
|
77696
|
+
import { methods as methods12 } from "@agentclientprotocol/sdk";
|
|
77459
77697
|
var AcpQuerySession = class _AcpQuerySession {
|
|
77460
|
-
#
|
|
77461
|
-
#sessionId;
|
|
77698
|
+
#options;
|
|
77462
77699
|
#events;
|
|
77463
77700
|
#connection;
|
|
77464
77701
|
#lifecycle = { kind: "open" };
|
|
77465
|
-
#
|
|
77466
|
-
|
|
77467
|
-
|
|
77468
|
-
this.#cwd = cwd;
|
|
77469
|
-
this.#sessionId = sessionId;
|
|
77702
|
+
#eventScope = crypto.randomUUID();
|
|
77703
|
+
constructor(options, events, connector) {
|
|
77704
|
+
this.#options = options;
|
|
77470
77705
|
this.#events = events;
|
|
77471
77706
|
this.#connection = connector.connectQuerySession({
|
|
77472
|
-
agent,
|
|
77473
|
-
cwd,
|
|
77474
|
-
|
|
77475
|
-
configOptions: () => this.#configOptions,
|
|
77707
|
+
agent: options.agent,
|
|
77708
|
+
cwd: options.cwd,
|
|
77709
|
+
...options.externalizeUpdate === void 0 ? {} : { externalizeUpdate: options.externalizeUpdate },
|
|
77476
77710
|
onEvent: async (event) => {
|
|
77477
|
-
this.#events.append(
|
|
77478
|
-
if (event.kind === "configuration") {
|
|
77479
|
-
this.#configOptions = event.configOptions;
|
|
77480
|
-
}
|
|
77711
|
+
this.#events.append(this.#eventScope, { type: "acp", payload: event.payload });
|
|
77481
77712
|
}
|
|
77482
77713
|
});
|
|
77483
77714
|
void this.#connection.termination.then(() => {
|
|
77484
77715
|
this.#lifecycle = { kind: "terminated" };
|
|
77485
77716
|
});
|
|
77486
77717
|
}
|
|
77487
|
-
static start = async (
|
|
77718
|
+
static start = async (options, events, connector) => {
|
|
77719
|
+
const { agent, signal } = options;
|
|
77488
77720
|
for (let attempt = 1; attempt <= 2; attempt += 1) {
|
|
77489
77721
|
await validateAgentRuntime(agent, signal);
|
|
77490
|
-
const runtime = new _AcpQuerySession(
|
|
77722
|
+
const runtime = new _AcpQuerySession(options, events, connector);
|
|
77491
77723
|
try {
|
|
77492
|
-
|
|
77493
|
-
runtime.#connection,
|
|
77494
|
-
agent.id,
|
|
77495
|
-
agent.agentVersion,
|
|
77496
|
-
signal
|
|
77497
|
-
);
|
|
77498
|
-
runtime.#capabilities = initialized.capabilities;
|
|
77724
|
+
await runtime.#connection.initializeAgent(options.signal);
|
|
77499
77725
|
return runtime;
|
|
77500
77726
|
} catch (error62) {
|
|
77501
77727
|
await runtime.closeProcess();
|
|
@@ -77512,7 +77738,7 @@ var AcpQuerySession = class _AcpQuerySession {
|
|
|
77512
77738
|
}
|
|
77513
77739
|
throw new AcpExecutionError("ACP agent initialization failed");
|
|
77514
77740
|
};
|
|
77515
|
-
capabilities = () => this.#capabilities;
|
|
77741
|
+
capabilities = () => this.#connection.snapshot().capabilities;
|
|
77516
77742
|
hasTerminated = () => {
|
|
77517
77743
|
switch (this.#lifecycle.kind) {
|
|
77518
77744
|
case "open":
|
|
@@ -77526,7 +77752,7 @@ var AcpQuerySession = class _AcpQuerySession {
|
|
|
77526
77752
|
}
|
|
77527
77753
|
};
|
|
77528
77754
|
listNativeSessions = async (cursor, signal) => {
|
|
77529
|
-
if (!this
|
|
77755
|
+
if (!this.capabilities().listSessions) {
|
|
77530
77756
|
throw new AcpExecutionError(
|
|
77531
77757
|
"This Agent does not support native session listing",
|
|
77532
77758
|
{},
|
|
@@ -77550,22 +77776,24 @@ var AcpQuerySession = class _AcpQuerySession {
|
|
|
77550
77776
|
}
|
|
77551
77777
|
return decoded.data;
|
|
77552
77778
|
};
|
|
77553
|
-
previewEvents = async (nativeSessionId, eventLimit,
|
|
77554
|
-
if (!this
|
|
77779
|
+
previewEvents = async (nativeSessionId, eventLimit, signal) => {
|
|
77780
|
+
if (!this.capabilities().loadSession) {
|
|
77555
77781
|
throw new AcpExecutionError(
|
|
77556
77782
|
"This Agent restores context but does not provide message history.",
|
|
77557
77783
|
{},
|
|
77558
77784
|
"native_history_unsupported"
|
|
77559
77785
|
);
|
|
77560
77786
|
}
|
|
77561
|
-
this.#
|
|
77787
|
+
this.#eventScope = nativeSessionId;
|
|
77788
|
+
this.#events.reset(nativeSessionId);
|
|
77562
77789
|
this.#connection.events.select(nativeSessionId);
|
|
77563
|
-
|
|
77790
|
+
this.#connection.beginStateChange();
|
|
77791
|
+
const response = await this.#connection.race(
|
|
77564
77792
|
this.#connection.connection.agent.request(
|
|
77565
77793
|
methods12.agent.session.load,
|
|
77566
77794
|
{
|
|
77567
|
-
additionalDirectories: [...additionalDirectories],
|
|
77568
|
-
cwd: this.#cwd,
|
|
77795
|
+
additionalDirectories: [...this.#options.additionalDirectories],
|
|
77796
|
+
cwd: this.#options.cwd,
|
|
77569
77797
|
mcpServers: [],
|
|
77570
77798
|
sessionId: nativeSessionId
|
|
77571
77799
|
},
|
|
@@ -77576,10 +77804,11 @@ var AcpQuerySession = class _AcpQuerySession {
|
|
|
77576
77804
|
);
|
|
77577
77805
|
await this.#connection.events.drained();
|
|
77578
77806
|
signal.throwIfAborted();
|
|
77579
|
-
|
|
77807
|
+
this.#connection.commitLifecycle(response);
|
|
77808
|
+
return this.#events.page(nativeSessionId, eventLimit, null);
|
|
77580
77809
|
};
|
|
77581
77810
|
closeProcess = async () => await this.#connection.closeProcess();
|
|
77582
|
-
discardEvents = () => this.#events.remove(this.#
|
|
77811
|
+
discardEvents = () => this.#events.remove(this.#eventScope);
|
|
77583
77812
|
};
|
|
77584
77813
|
|
|
77585
77814
|
// src/engine/acp/adapter/query-processes.ts
|
|
@@ -77598,45 +77827,46 @@ var AgentQueryProcesses = class {
|
|
|
77598
77827
|
refreshAgent = (agent) => {
|
|
77599
77828
|
this.#agent = agent;
|
|
77600
77829
|
};
|
|
77601
|
-
retire = async (readers,
|
|
77602
|
-
readers.detach(
|
|
77830
|
+
retire = async (readers, key, runtime) => {
|
|
77831
|
+
readers.detach(key, runtime);
|
|
77603
77832
|
try {
|
|
77604
77833
|
await this.#processes.retire(runtime, () => runtime.closeProcess());
|
|
77605
77834
|
} finally {
|
|
77606
77835
|
runtime.discardEvents();
|
|
77607
77836
|
}
|
|
77608
77837
|
};
|
|
77609
|
-
async #ensure(
|
|
77610
|
-
signal.throwIfAborted();
|
|
77611
|
-
const
|
|
77838
|
+
async #ensure(readers, query) {
|
|
77839
|
+
query.signal.throwIfAborted();
|
|
77840
|
+
const key = nativeSessionQueryKey(query);
|
|
77841
|
+
const pending = readers.pending(key);
|
|
77612
77842
|
if (pending !== void 0) {
|
|
77613
|
-
return await waitForSharedOperation(pending, signal);
|
|
77843
|
+
return await waitForSharedOperation(pending, query.signal);
|
|
77614
77844
|
}
|
|
77615
|
-
const existing = readers.get(
|
|
77845
|
+
const existing = readers.get(key);
|
|
77616
77846
|
if (existing !== void 0 && !existing.hasTerminated()) {
|
|
77617
|
-
readers.touch(
|
|
77847
|
+
readers.touch(key, existing);
|
|
77618
77848
|
return existing;
|
|
77619
77849
|
}
|
|
77620
|
-
return await readers.prepare(
|
|
77850
|
+
return await readers.prepare(key, async () => {
|
|
77621
77851
|
if (existing !== void 0) {
|
|
77622
|
-
await this.retire(readers,
|
|
77852
|
+
await this.retire(readers, key, existing);
|
|
77623
77853
|
}
|
|
77624
|
-
const readerId = randomUUID14();
|
|
77625
77854
|
const runtime = await this.#processes.startRetained(
|
|
77626
|
-
signal,
|
|
77627
|
-
() => AcpQuerySession.start(
|
|
77855
|
+
query.signal,
|
|
77856
|
+
() => AcpQuerySession.start(query, this.#store, this.#connector),
|
|
77628
77857
|
{
|
|
77629
|
-
isBusy: () => readers.isBusy(
|
|
77630
|
-
retire: (runtime2) => this.retire(readers,
|
|
77631
|
-
retireIdle: (runtime2) => this.retire(readers,
|
|
77858
|
+
isBusy: () => readers.isBusy(key),
|
|
77859
|
+
retire: (runtime2) => this.retire(readers, key, runtime2),
|
|
77860
|
+
retireIdle: (runtime2) => this.retire(readers, key, runtime2)
|
|
77632
77861
|
}
|
|
77633
77862
|
);
|
|
77634
|
-
readers.retain(
|
|
77863
|
+
readers.retain(key, runtime);
|
|
77635
77864
|
return runtime;
|
|
77636
77865
|
});
|
|
77637
77866
|
}
|
|
77638
|
-
#use = async (
|
|
77867
|
+
#use = async (query, operation) => {
|
|
77639
77868
|
const agent = this.#agent;
|
|
77869
|
+
const scoped = { ...query, agent };
|
|
77640
77870
|
let readers = this.#processesByAgent.get(agent);
|
|
77641
77871
|
if (readers === void 0) {
|
|
77642
77872
|
readers = new RetainedAgentProcesses({
|
|
@@ -77646,35 +77876,38 @@ var AgentQueryProcesses = class {
|
|
|
77646
77876
|
this.#processesByAgent.set(agent, readers);
|
|
77647
77877
|
}
|
|
77648
77878
|
const current = readers;
|
|
77649
|
-
return await current.use(
|
|
77879
|
+
return await current.use(
|
|
77880
|
+
nativeSessionQueryKey(scoped),
|
|
77881
|
+
async () => await operation(await this.#ensure(current, scoped))
|
|
77882
|
+
);
|
|
77650
77883
|
};
|
|
77651
|
-
capabilities = async (
|
|
77652
|
-
listNativeSessions = async (
|
|
77653
|
-
previewSessionEvents = async (
|
|
77654
|
-
signal.throwIfAborted();
|
|
77655
|
-
const
|
|
77656
|
-
const { nativeSessionId, eventLimit, cursor
|
|
77884
|
+
capabilities = async (query) => await this.#use(query, async (runtime) => runtime.capabilities());
|
|
77885
|
+
listNativeSessions = async (query, cursor) => await this.#use(query, async (runtime) => await runtime.listNativeSessions(cursor, query.signal));
|
|
77886
|
+
previewSessionEvents = async (query, request) => {
|
|
77887
|
+
query.signal.throwIfAborted();
|
|
77888
|
+
const scoped = { ...query, agent: this.#agent };
|
|
77889
|
+
const { nativeSessionId, eventLimit, cursor } = request;
|
|
77890
|
+
const key = nativeSessionPreviewKey(nativeSessionQueryKey(scoped), nativeSessionId);
|
|
77657
77891
|
if (cursor !== null) {
|
|
77658
|
-
const preview = this.#eventPreviewsBySession.get(
|
|
77892
|
+
const preview = this.#eventPreviewsBySession.get(key);
|
|
77659
77893
|
if (preview === void 0 || preview.nativeSessionId !== nativeSessionId) {
|
|
77660
77894
|
throw new Error("The native event cursor is invalid");
|
|
77661
77895
|
}
|
|
77662
|
-
return preview.store.page(
|
|
77896
|
+
return preview.store.page(nativeSessionId, eventLimit, cursor);
|
|
77663
77897
|
}
|
|
77664
77898
|
const store = new MemorySessionEventStore();
|
|
77665
|
-
|
|
77666
|
-
|
|
77667
|
-
this.#eventPreviewsBySession.set(sessionId, { nativeSessionId, store });
|
|
77899
|
+
this.#eventPreviewsBySession.get(key)?.store.close();
|
|
77900
|
+
this.#eventPreviewsBySession.set(key, { nativeSessionId, store });
|
|
77668
77901
|
try {
|
|
77669
77902
|
return await this.#processes.runTransient(
|
|
77670
|
-
signal,
|
|
77671
|
-
|
|
77672
|
-
|
|
77673
|
-
|
|
77903
|
+
query.signal,
|
|
77904
|
+
() => AcpQuerySession.start(scoped, store, this.#connector),
|
|
77905
|
+
(runtime) => runtime.previewEvents(nativeSessionId, eventLimit, query.signal),
|
|
77906
|
+
(runtime) => runtime.closeProcess()
|
|
77674
77907
|
);
|
|
77675
77908
|
} catch (error62) {
|
|
77676
|
-
if (this.#eventPreviewsBySession.get(
|
|
77677
|
-
this.#eventPreviewsBySession.delete(
|
|
77909
|
+
if (this.#eventPreviewsBySession.get(key)?.store === store) {
|
|
77910
|
+
this.#eventPreviewsBySession.delete(key);
|
|
77678
77911
|
}
|
|
77679
77912
|
store.close();
|
|
77680
77913
|
throw error62;
|
|
@@ -77683,7 +77916,7 @@ var AgentQueryProcesses = class {
|
|
|
77683
77916
|
close = async () => {
|
|
77684
77917
|
await Promise.all(
|
|
77685
77918
|
[...this.#processesByAgent.values()].flatMap(
|
|
77686
|
-
(readers) => readers.entries().map(async ([
|
|
77919
|
+
(readers) => readers.entries().map(async ([key, runtime]) => await this.retire(readers, key, runtime))
|
|
77687
77920
|
)
|
|
77688
77921
|
);
|
|
77689
77922
|
this.#processesByAgent.clear();
|
|
@@ -77696,35 +77929,99 @@ var AgentQueryProcesses = class {
|
|
|
77696
77929
|
};
|
|
77697
77930
|
|
|
77698
77931
|
// src/engine/acp/adapter/claude/adapter.ts
|
|
77932
|
+
import { methods as methods13 } from "@agentclientprotocol/sdk";
|
|
77699
77933
|
var ClaudeAdapter = class {
|
|
77700
77934
|
#queryProcesses;
|
|
77701
77935
|
#connector;
|
|
77702
|
-
#
|
|
77936
|
+
#executionConnections;
|
|
77703
77937
|
constructor(agent, dependencies) {
|
|
77704
77938
|
this.#connector = new AcpSessionConnector(dependencies.contentExternalizer);
|
|
77705
|
-
this.#
|
|
77939
|
+
this.#executionConnections = new AcpExecutionConnections(dependencies.contentExternalizer);
|
|
77706
77940
|
this.#queryProcesses = new AgentQueryProcesses(agent, dependencies.processes, this.#connector);
|
|
77707
77941
|
}
|
|
77708
77942
|
refreshAgent = (agent) => this.#queryProcesses.refreshAgent(agent);
|
|
77709
|
-
getCapabilities = (
|
|
77710
|
-
|
|
77711
|
-
|
|
77712
|
-
|
|
77713
|
-
|
|
77714
|
-
|
|
77715
|
-
|
|
77716
|
-
|
|
77717
|
-
|
|
77718
|
-
|
|
77719
|
-
|
|
77943
|
+
getCapabilities = async (query) => await this.#queryProcesses.capabilities(query);
|
|
77944
|
+
createSession = (params) => this.#executionConnections.withConnection(params, async (execution, signal) => {
|
|
77945
|
+
const { connection } = execution;
|
|
77946
|
+
const response = await connection.race(
|
|
77947
|
+
connection.connection.agent.request(methods13.agent.session.new, sessionWorkspace(params.scope), {
|
|
77948
|
+
cancellationSignal: signal
|
|
77949
|
+
}),
|
|
77950
|
+
"ACP agent exited while starting a session",
|
|
77951
|
+
signal
|
|
77952
|
+
);
|
|
77953
|
+
const nativeSessionId = createdNativeSessionId(response);
|
|
77954
|
+
this.#executionConnections.bind(execution, nativeSessionId);
|
|
77955
|
+
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
77956
|
+
});
|
|
77957
|
+
forkSession = (params) => this.#executionConnections.withConnection(params, async (execution, signal) => {
|
|
77958
|
+
const { connection } = execution;
|
|
77959
|
+
const response = await connection.race(
|
|
77960
|
+
connection.connection.agent.request(
|
|
77961
|
+
methods13.agent.session.fork,
|
|
77962
|
+
{
|
|
77963
|
+
...sessionWorkspace(params.scope),
|
|
77964
|
+
sessionId: nativeSessionIdSchema.parse(params.sourceNativeSessionId)
|
|
77965
|
+
},
|
|
77966
|
+
{ cancellationSignal: signal }
|
|
77967
|
+
),
|
|
77968
|
+
"ACP agent exited while forking a session",
|
|
77969
|
+
signal
|
|
77970
|
+
);
|
|
77971
|
+
const nativeSessionId = createdNativeSessionId(response);
|
|
77972
|
+
this.#executionConnections.bind(execution, nativeSessionId);
|
|
77973
|
+
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
77974
|
+
});
|
|
77975
|
+
openSession = (params) => this.#executionConnections.withConnection(params, async (execution, signal) => {
|
|
77976
|
+
const { connection } = execution;
|
|
77977
|
+
const nativeSessionId = nativeSessionIdSchema.parse(params.nativeSessionId);
|
|
77978
|
+
this.#executionConnections.bind(execution, nativeSessionId);
|
|
77979
|
+
const response = await connection.race(
|
|
77980
|
+
connection.connection.agent.request(
|
|
77981
|
+
methods13.agent.session.resume,
|
|
77982
|
+
{ ...sessionWorkspace(params.scope), sessionId: nativeSessionId },
|
|
77983
|
+
{ cancellationSignal: signal }
|
|
77984
|
+
),
|
|
77985
|
+
"ACP agent exited while resuming a session",
|
|
77986
|
+
signal
|
|
77987
|
+
);
|
|
77988
|
+
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
77989
|
+
});
|
|
77990
|
+
openSessionWithReplay = (params) => this.#executionConnections.withConnection(params, async (execution, signal) => {
|
|
77991
|
+
const { connection } = execution;
|
|
77992
|
+
const nativeSessionId = nativeSessionIdSchema.parse(params.nativeSessionId);
|
|
77993
|
+
this.#executionConnections.bind(execution, nativeSessionId);
|
|
77994
|
+
const response = await connection.race(
|
|
77995
|
+
connection.connection.agent.request(
|
|
77996
|
+
methods13.agent.session.load,
|
|
77997
|
+
{ ...sessionWorkspace(params.scope), sessionId: nativeSessionId },
|
|
77998
|
+
{ cancellationSignal: signal }
|
|
77999
|
+
),
|
|
78000
|
+
"ACP agent exited while loading a session",
|
|
78001
|
+
signal
|
|
78002
|
+
);
|
|
78003
|
+
await connection.race(connection.events.drained(), "ACP agent exited while loading a session", signal);
|
|
78004
|
+
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
78005
|
+
});
|
|
78006
|
+
cancel = (...args) => this.#executionConnections.cancel(...args);
|
|
78007
|
+
closeSession = (...args) => this.#executionConnections.closeSession(...args);
|
|
78008
|
+
releaseSession = (params) => this.#executionConnections.releaseSession(params);
|
|
78009
|
+
prompt = (...args) => this.#executionConnections.prompt(...args);
|
|
78010
|
+
steer = (...args) => this.#executionConnections.steer(...args);
|
|
78011
|
+
renameSession = (...args) => this.#executionConnections.renameSession(...args);
|
|
78012
|
+
configureSession = (...args) => this.#executionConnections.configureSession(...args);
|
|
78013
|
+
listSessions = async ({ query, cursor }) => await this.#queryProcesses.listNativeSessions(query, cursor);
|
|
78014
|
+
findSession = ({ query, nativeSessionId, budget }) => findNativeSession(this.listSessions, query, nativeSessionId, budget);
|
|
78015
|
+
readSessionHistory = async ({ query, request }) => await this.#queryProcesses.previewSessionEvents(query, request);
|
|
77720
78016
|
close = async () => await runCleanup(
|
|
77721
78017
|
() => this.#queryProcesses.close(),
|
|
77722
|
-
() => this.#
|
|
78018
|
+
() => this.#executionConnections.close()
|
|
77723
78019
|
);
|
|
77724
78020
|
};
|
|
77725
78021
|
|
|
77726
78022
|
// src/engine/acp/adapter/codex/adapter.ts
|
|
77727
78023
|
import { createHash as createHash5 } from "node:crypto";
|
|
78024
|
+
import { methods as methods14 } from "@agentclientprotocol/sdk";
|
|
77728
78025
|
|
|
77729
78026
|
// src/engine/storage/session/temporary-session-event-cache.ts
|
|
77730
78027
|
import { mkdtempSync, rmSync as rmSync2 } from "node:fs";
|
|
@@ -83024,7 +83321,7 @@ var CodexAdapter = class {
|
|
|
83024
83321
|
#agent;
|
|
83025
83322
|
#queryProcesses;
|
|
83026
83323
|
#connector;
|
|
83027
|
-
#
|
|
83324
|
+
#executionConnections;
|
|
83028
83325
|
#dependencies;
|
|
83029
83326
|
#contentExternalizer;
|
|
83030
83327
|
#previewCache = null;
|
|
@@ -83040,37 +83337,112 @@ var CodexAdapter = class {
|
|
|
83040
83337
|
}
|
|
83041
83338
|
};
|
|
83042
83339
|
this.#connector = new AcpSessionConnector(this.#contentExternalizer, fitCodexToolEvent);
|
|
83043
|
-
this.#
|
|
83340
|
+
this.#executionConnections = new AcpExecutionConnections(this.#contentExternalizer, fitCodexToolEvent);
|
|
83044
83341
|
this.#queryProcesses = new AgentQueryProcesses(agent, dependencies.processes, this.#connector);
|
|
83045
83342
|
}
|
|
83046
83343
|
refreshAgent = (agent) => {
|
|
83047
83344
|
this.#agent = agent;
|
|
83048
83345
|
this.#queryProcesses.refreshAgent(agent);
|
|
83049
83346
|
};
|
|
83050
|
-
getCapabilities = (
|
|
83051
|
-
|
|
83052
|
-
|
|
83053
|
-
|
|
83347
|
+
getCapabilities = async (query) => await this.#queryProcesses.capabilities(query);
|
|
83348
|
+
#executionParams = (params) => {
|
|
83349
|
+
const externalize = params.scope.externalizeUpdate;
|
|
83350
|
+
return externalize === void 0 ? params : {
|
|
83351
|
+
...params,
|
|
83352
|
+
scope: {
|
|
83353
|
+
...params.scope,
|
|
83354
|
+
externalizeUpdate: (update, signal) => externalize(prepareCodexToolUpdate(update), signal)
|
|
83355
|
+
}
|
|
83356
|
+
};
|
|
83357
|
+
};
|
|
83358
|
+
createSession = (params) => this.#executionConnections.withConnection(this.#executionParams(params), async (execution, signal) => {
|
|
83359
|
+
const { connection } = execution;
|
|
83360
|
+
const response = await connection.race(
|
|
83361
|
+
connection.connection.agent.request(methods14.agent.session.new, sessionWorkspace(params.scope), {
|
|
83362
|
+
cancellationSignal: signal
|
|
83363
|
+
}),
|
|
83364
|
+
"ACP agent exited while starting a session",
|
|
83365
|
+
signal
|
|
83366
|
+
);
|
|
83367
|
+
const nativeSessionId = createdNativeSessionId(response);
|
|
83368
|
+
this.#executionConnections.bind(execution, nativeSessionId);
|
|
83369
|
+
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
83370
|
+
});
|
|
83371
|
+
forkSession = (params) => this.#executionConnections.withConnection(this.#executionParams(params), async (execution, signal) => {
|
|
83372
|
+
const { connection } = execution;
|
|
83373
|
+
const response = await connection.race(
|
|
83374
|
+
connection.connection.agent.request(
|
|
83375
|
+
methods14.agent.session.fork,
|
|
83376
|
+
{
|
|
83377
|
+
...sessionWorkspace(params.scope),
|
|
83378
|
+
sessionId: nativeSessionIdSchema.parse(params.sourceNativeSessionId)
|
|
83379
|
+
},
|
|
83380
|
+
{ cancellationSignal: signal }
|
|
83381
|
+
),
|
|
83382
|
+
"ACP agent exited while forking a session",
|
|
83383
|
+
signal
|
|
83384
|
+
);
|
|
83385
|
+
const nativeSessionId = createdNativeSessionId(response);
|
|
83386
|
+
this.#executionConnections.bind(execution, nativeSessionId);
|
|
83387
|
+
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
83388
|
+
});
|
|
83389
|
+
openSession = (params) => this.#executionConnections.withConnection(this.#executionParams(params), async (execution, signal) => {
|
|
83390
|
+
const { connection } = execution;
|
|
83391
|
+
const nativeSessionId = nativeSessionIdSchema.parse(params.nativeSessionId);
|
|
83392
|
+
this.#executionConnections.bind(execution, nativeSessionId);
|
|
83393
|
+
const response = await connection.race(
|
|
83394
|
+
connection.connection.agent.request(
|
|
83395
|
+
methods14.agent.session.resume,
|
|
83396
|
+
{ ...sessionWorkspace(params.scope), sessionId: nativeSessionId },
|
|
83397
|
+
{ cancellationSignal: signal }
|
|
83398
|
+
),
|
|
83399
|
+
"ACP agent exited while resuming a session",
|
|
83400
|
+
signal
|
|
83401
|
+
);
|
|
83402
|
+
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
83403
|
+
});
|
|
83404
|
+
openSessionWithReplay = (params) => this.#executionConnections.withConnection(this.#executionParams(params), async (execution, signal) => {
|
|
83405
|
+
const { connection } = execution;
|
|
83406
|
+
const nativeSessionId = nativeSessionIdSchema.parse(params.nativeSessionId);
|
|
83407
|
+
this.#executionConnections.bind(execution, nativeSessionId);
|
|
83408
|
+
const response = await connection.race(
|
|
83409
|
+
connection.connection.agent.request(
|
|
83410
|
+
methods14.agent.session.load,
|
|
83411
|
+
{ ...sessionWorkspace(params.scope), sessionId: nativeSessionId },
|
|
83412
|
+
{ cancellationSignal: signal }
|
|
83413
|
+
),
|
|
83414
|
+
"ACP agent exited while loading a session",
|
|
83415
|
+
signal
|
|
83416
|
+
);
|
|
83417
|
+
await connection.race(connection.events.drained(), "ACP agent exited while loading a session", signal);
|
|
83418
|
+
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
83419
|
+
});
|
|
83420
|
+
cancel = async (params) => {
|
|
83421
|
+
await this.#executionConnections.closeSession(params);
|
|
83054
83422
|
return "closed";
|
|
83055
83423
|
};
|
|
83056
|
-
closeSession = (...args) => this.#
|
|
83057
|
-
|
|
83058
|
-
|
|
83059
|
-
|
|
83060
|
-
|
|
83061
|
-
|
|
83062
|
-
|
|
83424
|
+
closeSession = (...args) => this.#executionConnections.closeSession(...args);
|
|
83425
|
+
releaseSession = (params) => this.#executionConnections.releaseSession(params);
|
|
83426
|
+
prompt = (...args) => this.#executionConnections.prompt(...args);
|
|
83427
|
+
steer = (...args) => this.#executionConnections.steer(...args);
|
|
83428
|
+
renameSession = (...args) => this.#executionConnections.renameSession(...args);
|
|
83429
|
+
configureSession = (...args) => this.#executionConnections.configureSession(...args);
|
|
83430
|
+
listSessions = async ({ query, cursor }) => await this.#queryProcesses.listNativeSessions(query, cursor);
|
|
83431
|
+
findSession = ({ query, nativeSessionId, budget }) => findNativeSession(this.listSessions, query, nativeSessionId, budget);
|
|
83063
83432
|
close = async () => {
|
|
83064
83433
|
await runCleanup(
|
|
83065
83434
|
() => this.#queryProcesses.close(),
|
|
83066
|
-
() => this.#
|
|
83435
|
+
() => this.#executionConnections.close(),
|
|
83067
83436
|
() => this.#previewCache?.close()
|
|
83068
83437
|
);
|
|
83069
83438
|
};
|
|
83070
|
-
readSessionHistory = async (
|
|
83071
|
-
|
|
83072
|
-
|
|
83073
|
-
|
|
83439
|
+
readSessionHistory = async ({
|
|
83440
|
+
query,
|
|
83441
|
+
request
|
|
83442
|
+
}) => {
|
|
83443
|
+
const { agent, cwd } = query;
|
|
83444
|
+
const signal = AbortSignal.any([query.signal, AbortSignal.timeout(6e4)]);
|
|
83445
|
+
const sessionId = request.nativeSessionId;
|
|
83074
83446
|
signal.throwIfAborted();
|
|
83075
83447
|
nativeSessionIdSchema.parse(request.nativeSessionId);
|
|
83076
83448
|
if (agent.id !== "codex") {
|
|
@@ -83121,7 +83493,7 @@ var CodexAdapter = class {
|
|
|
83121
83493
|
client2,
|
|
83122
83494
|
request.nativeSessionId,
|
|
83123
83495
|
async (update) => {
|
|
83124
|
-
const externalized = await this.#contentExternalizer.update(sessionId, update, signal);
|
|
83496
|
+
const externalized = query.externalizeUpdate === void 0 ? await this.#contentExternalizer.update(sessionId, update, signal) : await query.externalizeUpdate(prepareCodexToolUpdate(update), signal);
|
|
83125
83497
|
for (const event of externalized.events) {
|
|
83126
83498
|
events.push({
|
|
83127
83499
|
type: "acp",
|
|
@@ -83141,30 +83513,93 @@ var CodexAdapter = class {
|
|
|
83141
83513
|
};
|
|
83142
83514
|
|
|
83143
83515
|
// src/engine/acp/adapter/pi/adapter.ts
|
|
83516
|
+
import { methods as methods15 } from "@agentclientprotocol/sdk";
|
|
83144
83517
|
var PiAdapter = class {
|
|
83145
83518
|
#queryProcesses;
|
|
83146
83519
|
#connector;
|
|
83147
|
-
#
|
|
83520
|
+
#executionConnections;
|
|
83148
83521
|
constructor(agent, dependencies) {
|
|
83149
83522
|
this.#connector = new AcpSessionConnector(dependencies.contentExternalizer);
|
|
83150
|
-
this.#
|
|
83523
|
+
this.#executionConnections = new AcpExecutionConnections(dependencies.contentExternalizer);
|
|
83151
83524
|
this.#queryProcesses = new AgentQueryProcesses(agent, dependencies.processes, this.#connector);
|
|
83152
83525
|
}
|
|
83153
83526
|
refreshAgent = (agent) => this.#queryProcesses.refreshAgent(agent);
|
|
83154
|
-
getCapabilities = (
|
|
83155
|
-
|
|
83156
|
-
|
|
83157
|
-
|
|
83158
|
-
|
|
83159
|
-
|
|
83160
|
-
|
|
83161
|
-
|
|
83162
|
-
|
|
83163
|
-
|
|
83164
|
-
|
|
83527
|
+
getCapabilities = async (query) => await this.#queryProcesses.capabilities(query);
|
|
83528
|
+
createSession = (params) => this.#executionConnections.withConnection(params, async (execution, signal) => {
|
|
83529
|
+
const { connection } = execution;
|
|
83530
|
+
const response = await connection.race(
|
|
83531
|
+
connection.connection.agent.request(methods15.agent.session.new, sessionWorkspace(params.scope), {
|
|
83532
|
+
cancellationSignal: signal
|
|
83533
|
+
}),
|
|
83534
|
+
"ACP agent exited while starting a session",
|
|
83535
|
+
signal
|
|
83536
|
+
);
|
|
83537
|
+
const nativeSessionId = createdNativeSessionId(response);
|
|
83538
|
+
this.#executionConnections.bind(execution, nativeSessionId);
|
|
83539
|
+
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
83540
|
+
});
|
|
83541
|
+
forkSession = (params) => this.#executionConnections.withConnection(params, async (execution, signal) => {
|
|
83542
|
+
const { connection } = execution;
|
|
83543
|
+
const response = await connection.race(
|
|
83544
|
+
connection.connection.agent.request(
|
|
83545
|
+
methods15.agent.session.fork,
|
|
83546
|
+
{
|
|
83547
|
+
...sessionWorkspace(params.scope),
|
|
83548
|
+
sessionId: nativeSessionIdSchema.parse(params.sourceNativeSessionId)
|
|
83549
|
+
},
|
|
83550
|
+
{ cancellationSignal: signal }
|
|
83551
|
+
),
|
|
83552
|
+
"ACP agent exited while forking a session",
|
|
83553
|
+
signal
|
|
83554
|
+
);
|
|
83555
|
+
const nativeSessionId = createdNativeSessionId(response);
|
|
83556
|
+
this.#executionConnections.bind(execution, nativeSessionId);
|
|
83557
|
+
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
83558
|
+
});
|
|
83559
|
+
openSession = (params) => this.#executionConnections.withConnection(params, async (execution, signal) => {
|
|
83560
|
+
const { connection } = execution;
|
|
83561
|
+
const nativeSessionId = nativeSessionIdSchema.parse(params.nativeSessionId);
|
|
83562
|
+
this.#executionConnections.bind(execution, nativeSessionId);
|
|
83563
|
+
const response = await connection.race(
|
|
83564
|
+
connection.connection.agent.request(
|
|
83565
|
+
methods15.agent.session.resume,
|
|
83566
|
+
{ ...sessionWorkspace(params.scope), sessionId: nativeSessionId },
|
|
83567
|
+
{ cancellationSignal: signal }
|
|
83568
|
+
),
|
|
83569
|
+
"ACP agent exited while resuming a session",
|
|
83570
|
+
signal
|
|
83571
|
+
);
|
|
83572
|
+
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
83573
|
+
});
|
|
83574
|
+
openSessionWithReplay = (params) => this.#executionConnections.withConnection(params, async (execution, signal) => {
|
|
83575
|
+
const { connection } = execution;
|
|
83576
|
+
const nativeSessionId = nativeSessionIdSchema.parse(params.nativeSessionId);
|
|
83577
|
+
this.#executionConnections.bind(execution, nativeSessionId);
|
|
83578
|
+
const response = await connection.race(
|
|
83579
|
+
connection.connection.agent.request(
|
|
83580
|
+
methods15.agent.session.load,
|
|
83581
|
+
{ ...sessionWorkspace(params.scope), sessionId: nativeSessionId },
|
|
83582
|
+
{ cancellationSignal: signal }
|
|
83583
|
+
),
|
|
83584
|
+
"ACP agent exited while loading a session",
|
|
83585
|
+
signal
|
|
83586
|
+
);
|
|
83587
|
+
await connection.race(connection.events.drained(), "ACP agent exited while loading a session", signal);
|
|
83588
|
+
return normalizeOpenedSession(execution, nativeSessionId, response, signal);
|
|
83589
|
+
});
|
|
83590
|
+
cancel = (...args) => this.#executionConnections.cancel(...args);
|
|
83591
|
+
closeSession = (...args) => this.#executionConnections.closeSession(...args);
|
|
83592
|
+
releaseSession = (params) => this.#executionConnections.releaseSession(params);
|
|
83593
|
+
prompt = (...args) => this.#executionConnections.prompt(...args);
|
|
83594
|
+
steer = (...args) => this.#executionConnections.steer(...args);
|
|
83595
|
+
renameSession = (...args) => this.#executionConnections.renameSession(...args);
|
|
83596
|
+
configureSession = (...args) => this.#executionConnections.configureSession(...args);
|
|
83597
|
+
listSessions = async ({ query, cursor }) => await this.#queryProcesses.listNativeSessions(query, cursor);
|
|
83598
|
+
findSession = ({ query, nativeSessionId, budget }) => findNativeSession(this.listSessions, query, nativeSessionId, budget);
|
|
83599
|
+
readSessionHistory = async ({ query, request }) => await this.#queryProcesses.previewSessionEvents(query, request);
|
|
83165
83600
|
close = async () => await runCleanup(
|
|
83166
83601
|
() => this.#queryProcesses.close(),
|
|
83167
|
-
() => this.#
|
|
83602
|
+
() => this.#executionConnections.close()
|
|
83168
83603
|
);
|
|
83169
83604
|
};
|
|
83170
83605
|
|
|
@@ -83462,10 +83897,12 @@ var AcpContentExternalizer = class {
|
|
|
83462
83897
|
|
|
83463
83898
|
// src/engine/agent/runtime-agents.ts
|
|
83464
83899
|
function createRuntimeAdapterRegistry(adapters, processes, externalize, linkedResources) {
|
|
83465
|
-
|
|
83466
|
-
|
|
83467
|
-
|
|
83468
|
-
|
|
83900
|
+
const contentExternalizer = new AcpContentExternalizer(externalize, linkedResources);
|
|
83901
|
+
const externalizeSessionUpdate = (sessionId, update, signal) => contentExternalizer.update(sessionId, update, signal);
|
|
83902
|
+
return {
|
|
83903
|
+
adapters: new AdapterRegistry(adapters, { processes, contentExternalizer }),
|
|
83904
|
+
externalizeSessionUpdate
|
|
83905
|
+
};
|
|
83469
83906
|
}
|
|
83470
83907
|
var RuntimeAgentDependencies = class {
|
|
83471
83908
|
agents;
|
|
@@ -84564,9 +85001,6 @@ var unmeasuredOperationMetrics = Object.freeze({
|
|
|
84564
85001
|
snapshot: () => Object.freeze([])
|
|
84565
85002
|
});
|
|
84566
85003
|
|
|
84567
|
-
// src/engine/session/live/agent-session.ts
|
|
84568
|
-
import { methods as methods14 } from "@agentclientprotocol/sdk";
|
|
84569
|
-
|
|
84570
85004
|
// ../mobius-sdk/src/conversation-title.ts
|
|
84571
85005
|
var CONVERSATION_TITLE_CHARACTER_LIMIT = 42;
|
|
84572
85006
|
function conversationTitleFromText(text2) {
|
|
@@ -85405,7 +85839,6 @@ var RunningAgentTurn = class extends AgentTurnState {
|
|
|
85405
85839
|
};
|
|
85406
85840
|
|
|
85407
85841
|
// src/engine/session/live/session-restore.ts
|
|
85408
|
-
import { methods as methods13 } from "@agentclientprotocol/sdk";
|
|
85409
85842
|
function hasMethodNotFoundCode(cause) {
|
|
85410
85843
|
const visited = /* @__PURE__ */ new Set();
|
|
85411
85844
|
let current = cause;
|
|
@@ -85423,7 +85856,6 @@ async function restoreSession(session, signal, recovery, origin) {
|
|
|
85423
85856
|
if (origin !== void 0) {
|
|
85424
85857
|
session.setSessionTitle(origin.title);
|
|
85425
85858
|
}
|
|
85426
|
-
await session.initializeAgent(signal);
|
|
85427
85859
|
let stored = session.metrics.measureSync(
|
|
85428
85860
|
"session-state-read",
|
|
85429
85861
|
() => origin?.kind === "import" ? new FoundStoredSession(
|
|
@@ -85443,7 +85875,7 @@ async function restoreSession(session, signal, recovery, origin) {
|
|
|
85443
85875
|
stored = session.metrics.measureSync("session-state-read", () => session.store.read(session.sessionId));
|
|
85444
85876
|
}
|
|
85445
85877
|
const forkSource = origin?.kind === "fork" ? session.store.findNative(session.agentId, origin.nativeSessionId)[0] : void 0;
|
|
85446
|
-
let
|
|
85878
|
+
let opened;
|
|
85447
85879
|
if (origin?.kind === "fork") {
|
|
85448
85880
|
if (!session.capabilities.unstableForkSession) {
|
|
85449
85881
|
throw new AcpExecutionError(
|
|
@@ -85461,22 +85893,9 @@ async function restoreSession(session, signal, recovery, origin) {
|
|
|
85461
85893
|
}
|
|
85462
85894
|
const forked = await session.metrics.measure(
|
|
85463
85895
|
"session-fork",
|
|
85464
|
-
async () => await session.
|
|
85465
|
-
session.agentRequest(
|
|
85466
|
-
methods13.agent.session.fork,
|
|
85467
|
-
{
|
|
85468
|
-
sessionId: nativeSessionIdSchema.parse(origin.nativeSessionId),
|
|
85469
|
-
cwd: session.cwd,
|
|
85470
|
-
additionalDirectories: [...session.additionalDirectories],
|
|
85471
|
-
mcpServers: []
|
|
85472
|
-
},
|
|
85473
|
-
{ cancellationSignal: signal }
|
|
85474
|
-
),
|
|
85475
|
-
"ACP agent exited while forking a session",
|
|
85476
|
-
signal
|
|
85477
|
-
)
|
|
85896
|
+
async () => await session.forkSession(origin.nativeSessionId, signal)
|
|
85478
85897
|
);
|
|
85479
|
-
session.selectNativeSession(forked.
|
|
85898
|
+
session.selectNativeSession(forked.nativeSessionId);
|
|
85480
85899
|
if (session.nativeSessionId() === origin.nativeSessionId || session.store.findNative(session.agentId, session.nativeSessionId()).length > 0) {
|
|
85481
85900
|
throw new AcpExecutionError(
|
|
85482
85901
|
"The Agent did not create an independent fork",
|
|
@@ -85489,7 +85908,7 @@ async function restoreSession(session, signal, recovery, origin) {
|
|
|
85489
85908
|
if (recovery.kind === "execution-only") {
|
|
85490
85909
|
session.startExecutionOnlyCapture();
|
|
85491
85910
|
}
|
|
85492
|
-
|
|
85911
|
+
opened = forked;
|
|
85493
85912
|
} else if (stored instanceof FoundStoredSession && stored.session.agentId === session.agentId && stored.session.cwd === session.cwd && arraysEqual(stored.session.additionalDirectories, session.additionalDirectories)) {
|
|
85494
85913
|
session.selectNativeSession(stored.session.nativeSessionId);
|
|
85495
85914
|
session.setPrompted(stored.session.prompted);
|
|
@@ -85503,29 +85922,13 @@ async function restoreSession(session, signal, recovery, origin) {
|
|
|
85503
85922
|
"native_history_unsupported"
|
|
85504
85923
|
);
|
|
85505
85924
|
}
|
|
85506
|
-
|
|
85925
|
+
opened = await session.metrics.measure(
|
|
85507
85926
|
"session-load",
|
|
85508
|
-
async () =>
|
|
85927
|
+
async () => await session.openSessionWithReplay(signal)
|
|
85509
85928
|
);
|
|
85510
85929
|
} else if (recovery.kind === "execution-only") {
|
|
85511
85930
|
try {
|
|
85512
|
-
|
|
85513
|
-
"session-resume",
|
|
85514
|
-
async () => await session.race(
|
|
85515
|
-
session.agentRequest(
|
|
85516
|
-
methods13.agent.session.resume,
|
|
85517
|
-
{
|
|
85518
|
-
additionalDirectories: [...session.additionalDirectories],
|
|
85519
|
-
cwd: session.cwd,
|
|
85520
|
-
mcpServers: [],
|
|
85521
|
-
sessionId: session.nativeSessionId()
|
|
85522
|
-
},
|
|
85523
|
-
{ cancellationSignal: signal }
|
|
85524
|
-
),
|
|
85525
|
-
"ACP agent exited while resuming a session",
|
|
85526
|
-
signal
|
|
85527
|
-
)
|
|
85528
|
-
);
|
|
85931
|
+
opened = await session.metrics.measure("session-resume", async () => await session.openSession(signal));
|
|
85529
85932
|
} catch (cause) {
|
|
85530
85933
|
signal.throwIfAborted();
|
|
85531
85934
|
if (cause instanceof AcpExecutionError && !hasMethodNotFoundCode(cause)) {
|
|
@@ -85539,27 +85942,11 @@ async function restoreSession(session, signal, recovery, origin) {
|
|
|
85539
85942
|
}
|
|
85540
85943
|
session.startExecutionOnlyCapture();
|
|
85541
85944
|
} else if (session.capabilities.resumeSession) {
|
|
85542
|
-
|
|
85543
|
-
"session-resume",
|
|
85544
|
-
async () => await session.race(
|
|
85545
|
-
session.agentRequest(
|
|
85546
|
-
methods13.agent.session.resume,
|
|
85547
|
-
{
|
|
85548
|
-
additionalDirectories: [...session.additionalDirectories],
|
|
85549
|
-
cwd: session.cwd,
|
|
85550
|
-
mcpServers: [],
|
|
85551
|
-
sessionId: session.nativeSessionId()
|
|
85552
|
-
},
|
|
85553
|
-
{ cancellationSignal: signal }
|
|
85554
|
-
),
|
|
85555
|
-
"ACP agent exited while resuming a session",
|
|
85556
|
-
signal
|
|
85557
|
-
)
|
|
85558
|
-
);
|
|
85945
|
+
opened = await session.metrics.measure("session-resume", async () => await session.openSession(signal));
|
|
85559
85946
|
} else if (session.capabilities.loadSession) {
|
|
85560
|
-
|
|
85947
|
+
opened = await session.metrics.measure(
|
|
85561
85948
|
"session-load",
|
|
85562
|
-
async () =>
|
|
85949
|
+
async () => await session.openSessionWithReplay(signal)
|
|
85563
85950
|
);
|
|
85564
85951
|
} else {
|
|
85565
85952
|
throw new AcpExecutionError(
|
|
@@ -85579,37 +85966,20 @@ async function restoreSession(session, signal, recovery, origin) {
|
|
|
85579
85966
|
}
|
|
85580
85967
|
session.store.remove(session.sessionId);
|
|
85581
85968
|
}
|
|
85582
|
-
const created = await session.metrics.measure(
|
|
85583
|
-
|
|
85584
|
-
async () => await session.race(
|
|
85585
|
-
session.agentRequest(
|
|
85586
|
-
methods13.agent.session.new,
|
|
85587
|
-
{
|
|
85588
|
-
additionalDirectories: [...session.additionalDirectories],
|
|
85589
|
-
cwd: session.cwd,
|
|
85590
|
-
mcpServers: []
|
|
85591
|
-
},
|
|
85592
|
-
{ cancellationSignal: signal }
|
|
85593
|
-
),
|
|
85594
|
-
"ACP agent exited while starting a session",
|
|
85595
|
-
signal
|
|
85596
|
-
)
|
|
85597
|
-
);
|
|
85598
|
-
session.selectNativeSession(created.sessionId);
|
|
85969
|
+
const created = await session.metrics.measure("session-new", async () => await session.createSession(signal));
|
|
85970
|
+
session.selectNativeSession(created.nativeSessionId);
|
|
85599
85971
|
session.setNativeHistoryOwnership({ kind: "fresh-session" });
|
|
85600
85972
|
if (recovery.kind === "execution-only") {
|
|
85601
85973
|
session.startExecutionOnlyCapture();
|
|
85602
85974
|
}
|
|
85603
|
-
|
|
85975
|
+
opened = created;
|
|
85604
85976
|
}
|
|
85605
|
-
session.
|
|
85606
|
-
session.setConfigOptions(session.sessionConfigProtocol.normalizeLifecycle(lifecycleResponse));
|
|
85977
|
+
session.applySessionOpened(opened);
|
|
85607
85978
|
if (forkSource !== void 0) {
|
|
85608
85979
|
await session.restoreStoredConfigurations(forkSource, signal, "fork");
|
|
85609
85980
|
} else if (stored instanceof FoundStoredSession && session.restored) {
|
|
85610
85981
|
await session.restoreStoredConfigurations(stored.session, signal);
|
|
85611
85982
|
}
|
|
85612
|
-
await session.drained();
|
|
85613
85983
|
signal.throwIfAborted();
|
|
85614
85984
|
session.writeStoredSession(
|
|
85615
85985
|
stored instanceof FoundStoredSession && session.restored ? stored.session.updatedAt : (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -85641,14 +86011,20 @@ var AgentSession = class _AgentSession {
|
|
|
85641
86011
|
get sessionId() {
|
|
85642
86012
|
return this.#mobiusSessionId;
|
|
85643
86013
|
}
|
|
85644
|
-
get sessionConfigProtocol() {
|
|
85645
|
-
return this.#sessionConfigProtocol;
|
|
85646
|
-
}
|
|
85647
86014
|
get store() {
|
|
85648
86015
|
return this.#store;
|
|
85649
86016
|
}
|
|
85650
|
-
hasBackgroundActivity = () => this.#
|
|
85651
|
-
#
|
|
86017
|
+
hasBackgroundActivity = () => this.#backgroundActivity !== "none";
|
|
86018
|
+
#backgroundActivity = "none";
|
|
86019
|
+
#modelEffort = null;
|
|
86020
|
+
#scope;
|
|
86021
|
+
#subscriber;
|
|
86022
|
+
#nativeIdentity = {
|
|
86023
|
+
kind: "unbound"
|
|
86024
|
+
};
|
|
86025
|
+
get #nativeSessionId() {
|
|
86026
|
+
return this.#nativeIdentity.kind === "bound" ? this.#nativeIdentity.nativeSessionId : "";
|
|
86027
|
+
}
|
|
85652
86028
|
#adapter;
|
|
85653
86029
|
#additionalDirectories;
|
|
85654
86030
|
#agentId;
|
|
@@ -85657,11 +86033,8 @@ var AgentSession = class _AgentSession {
|
|
|
85657
86033
|
#getObserver;
|
|
85658
86034
|
#interactions;
|
|
85659
86035
|
#mobiusSessionId;
|
|
85660
|
-
#updates;
|
|
85661
86036
|
#metrics;
|
|
85662
|
-
#sessionConfigProtocol;
|
|
85663
86037
|
#store;
|
|
85664
|
-
#verifiedAgentVersion;
|
|
85665
86038
|
#agentName = "";
|
|
85666
86039
|
#agentVersion = "";
|
|
85667
86040
|
#capabilities = unsupportedSessionCapabilities();
|
|
@@ -85677,7 +86050,7 @@ var AgentSession = class _AgentSession {
|
|
|
85677
86050
|
#sessionTitle = null;
|
|
85678
86051
|
#sessionUpdatedAt = "";
|
|
85679
86052
|
#turn = new IdleAgentTurn();
|
|
85680
|
-
constructor(agent, cwd, additionalDirectories, mobiusSessionId, getObserver, store, metrics, adapter) {
|
|
86053
|
+
constructor(agent, cwd, additionalDirectories, mobiusSessionId, getObserver, store, metrics, adapter, externalize) {
|
|
85681
86054
|
this.#additionalDirectories = [...additionalDirectories];
|
|
85682
86055
|
this.#adapter = adapter;
|
|
85683
86056
|
this.#agentId = agent.id;
|
|
@@ -85686,9 +86059,7 @@ var AgentSession = class _AgentSession {
|
|
|
85686
86059
|
this.#environment = agent.environment;
|
|
85687
86060
|
this.#mobiusSessionId = mobiusSessionId;
|
|
85688
86061
|
this.#metrics = metrics;
|
|
85689
|
-
this.#sessionConfigProtocol = sessionConfigProtocolForAgent(agent.id);
|
|
85690
86062
|
this.#store = store;
|
|
85691
|
-
this.#verifiedAgentVersion = agent.agentVersion;
|
|
85692
86063
|
this.#getObserver = getObserver;
|
|
85693
86064
|
this.#interactions = new SessionInteractions({
|
|
85694
86065
|
cwd: () => this.#cwd,
|
|
@@ -85699,25 +86070,31 @@ var AgentSession = class _AgentSession {
|
|
|
85699
86070
|
observer: getObserver,
|
|
85700
86071
|
recordSessionEvent: this.recordLifecycleEvent
|
|
85701
86072
|
});
|
|
85702
|
-
|
|
86073
|
+
this.#scope = {
|
|
85703
86074
|
agent,
|
|
85704
86075
|
cwd,
|
|
85705
|
-
sessionId: () => this.#mobiusSessionId,
|
|
85706
|
-
configOptions: () => this.#configOptions,
|
|
85707
|
-
onEvent: this.#processEvent
|
|
85708
|
-
};
|
|
85709
|
-
this.#connection = this.#adapter.connectSession({
|
|
85710
|
-
...scope,
|
|
85711
86076
|
additionalDirectories: this.#additionalDirectories,
|
|
85712
|
-
|
|
85713
|
-
|
|
86077
|
+
...externalize === void 0 ? {} : { externalizeUpdate: (update, signal) => externalize(this.#mobiusSessionId, update, signal) }
|
|
86078
|
+
};
|
|
86079
|
+
this.#subscriber = {
|
|
86080
|
+
onSessionEvent: async (nativeSessionId, event) => {
|
|
86081
|
+
if (this.#nativeSessionId.length === 0) {
|
|
86082
|
+
this.selectNativeSession(nativeSessionId);
|
|
86083
|
+
} else {
|
|
86084
|
+
this.assertNativeSession(nativeSessionId);
|
|
86085
|
+
}
|
|
86086
|
+
await this.#processEvent(event);
|
|
86087
|
+
},
|
|
86088
|
+
onBackgroundActivity: (activity) => {
|
|
86089
|
+
this.#backgroundActivity = activity;
|
|
86090
|
+
this.#getObserver().onBackgroundActivity?.(this, activity);
|
|
86091
|
+
},
|
|
85714
86092
|
interactions: {
|
|
85715
86093
|
onPermission: this.#interactions.onPermission,
|
|
85716
86094
|
onElicitation: this.#interactions.onElicitation,
|
|
85717
86095
|
onElicitationComplete: this.#interactions.onElicitationComplete
|
|
85718
86096
|
}
|
|
85719
|
-
}
|
|
85720
|
-
this.#updates = this.#connection.events;
|
|
86097
|
+
};
|
|
85721
86098
|
}
|
|
85722
86099
|
static async #start(options, getObserver, store, initialize, metrics, adapter) {
|
|
85723
86100
|
for (let attempt = 1; attempt <= 2; attempt += 1) {
|
|
@@ -85735,7 +86112,8 @@ var AgentSession = class _AgentSession {
|
|
|
85735
86112
|
getObserver,
|
|
85736
86113
|
store,
|
|
85737
86114
|
metrics,
|
|
85738
|
-
adapter
|
|
86115
|
+
adapter,
|
|
86116
|
+
options.externalizeSessionUpdate
|
|
85739
86117
|
)
|
|
85740
86118
|
);
|
|
85741
86119
|
try {
|
|
@@ -85758,11 +86136,14 @@ var AgentSession = class _AgentSession {
|
|
|
85758
86136
|
}
|
|
85759
86137
|
throw new AcpExecutionError("ACP agent initialization failed");
|
|
85760
86138
|
}
|
|
85761
|
-
static start = async (options, recovery, getObserver, store, metrics, adapter) => await _AgentSession.#start(
|
|
86139
|
+
static start = async (options, recovery, getObserver, store, metrics, adapter, capabilities = unsupportedSessionCapabilities()) => await _AgentSession.#start(
|
|
85762
86140
|
options,
|
|
85763
86141
|
getObserver,
|
|
85764
86142
|
store,
|
|
85765
|
-
async (runtime) =>
|
|
86143
|
+
async (runtime) => {
|
|
86144
|
+
runtime.#capabilities = capabilities;
|
|
86145
|
+
await runtime.initialize(options.signal, recovery, options.origin);
|
|
86146
|
+
},
|
|
85766
86147
|
metrics,
|
|
85767
86148
|
adapter
|
|
85768
86149
|
);
|
|
@@ -85775,7 +86156,7 @@ var AgentSession = class _AgentSession {
|
|
|
85775
86156
|
new StoredSession(
|
|
85776
86157
|
this.#mobiusSessionId,
|
|
85777
86158
|
this.#agentId,
|
|
85778
|
-
this.#
|
|
86159
|
+
this.#nativeSessionId,
|
|
85779
86160
|
this.#cwd,
|
|
85780
86161
|
this.#additionalDirectories,
|
|
85781
86162
|
this.#prompted,
|
|
@@ -85797,9 +86178,9 @@ var AgentSession = class _AgentSession {
|
|
|
85797
86178
|
if (normalized.length === 0) {
|
|
85798
86179
|
throw new AcpExecutionError("The Session title cannot be empty", {}, "invalid_session_title");
|
|
85799
86180
|
}
|
|
85800
|
-
const nativeSessionId = this.#
|
|
86181
|
+
const nativeSessionId = this.#nativeSessionId;
|
|
85801
86182
|
if (nativeSessionId.length > 0) {
|
|
85802
|
-
await this.#adapter.renameSession(this.#target(), normalized, signal);
|
|
86183
|
+
await this.#adapter.renameSession({ ...this.#target(), title: normalized, signal });
|
|
85803
86184
|
}
|
|
85804
86185
|
const updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
85805
86186
|
await this.#processEvent({
|
|
@@ -85814,7 +86195,7 @@ var AgentSession = class _AgentSession {
|
|
|
85814
86195
|
};
|
|
85815
86196
|
#captureSelectedConfigurationValues = () => {
|
|
85816
86197
|
this.#sessionConfigurations.capture(this.#configOptions);
|
|
85817
|
-
if (this.#
|
|
86198
|
+
if (this.#nativeSessionId.length > 0) {
|
|
85818
86199
|
this.writeStoredSession((/* @__PURE__ */ new Date()).toISOString());
|
|
85819
86200
|
}
|
|
85820
86201
|
};
|
|
@@ -85844,8 +86225,12 @@ var AgentSession = class _AgentSession {
|
|
|
85844
86225
|
}
|
|
85845
86226
|
}
|
|
85846
86227
|
};
|
|
85847
|
-
|
|
85848
|
-
this.#
|
|
86228
|
+
applySessionOpened = (opened) => {
|
|
86229
|
+
this.#agentName = opened.agentName;
|
|
86230
|
+
this.#agentVersion = opened.agentVersion;
|
|
86231
|
+
this.#modelEffort = opened.agentSettingsModelEffort;
|
|
86232
|
+
this.#capabilities = opened.capabilities;
|
|
86233
|
+
this.setConfigOptions(opened.configOptions);
|
|
85849
86234
|
};
|
|
85850
86235
|
prepared = () => new PreparedSession(
|
|
85851
86236
|
this.#agentName,
|
|
@@ -85865,7 +86250,7 @@ var AgentSession = class _AgentSession {
|
|
|
85865
86250
|
"native_history_unsupported"
|
|
85866
86251
|
);
|
|
85867
86252
|
}
|
|
85868
|
-
await this.#completedHistory(signal
|
|
86253
|
+
await this.#completedHistory(signal);
|
|
85869
86254
|
};
|
|
85870
86255
|
/** Starts live event capture without asking the native Agent to replay its persisted history. */
|
|
85871
86256
|
startExecutionOnlyCapture = () => {
|
|
@@ -85885,26 +86270,33 @@ var AgentSession = class _AgentSession {
|
|
|
85885
86270
|
"native_history_unsupported"
|
|
85886
86271
|
);
|
|
85887
86272
|
}
|
|
85888
|
-
const history = await this.#completedHistory(signal
|
|
86273
|
+
const history = await this.#completedHistory(signal);
|
|
85889
86274
|
return history.eventPage(eventLimit, cursor);
|
|
85890
86275
|
};
|
|
85891
|
-
async #completedHistory(signal
|
|
86276
|
+
async #completedHistory(signal) {
|
|
85892
86277
|
if (!this.#prompted && this.#nativeHistoryOwnership.kind === "fresh-session") {
|
|
85893
86278
|
if (this.#sessionLoad.kind === "not-requested") {
|
|
85894
86279
|
this.#store.events.reset(this.#mobiusSessionId);
|
|
85895
86280
|
this.#sessionLoad = {
|
|
85896
86281
|
history: new HistoryReplayCapture(this.#store.events, this.#mobiusSessionId),
|
|
85897
86282
|
kind: "loaded",
|
|
85898
|
-
|
|
86283
|
+
opened: {
|
|
86284
|
+
nativeSessionId: this.nativeSessionId(),
|
|
86285
|
+
capabilities: this.#capabilities,
|
|
86286
|
+
configOptions: [],
|
|
86287
|
+
agentName: this.#agentName,
|
|
86288
|
+
agentVersion: this.#agentVersion,
|
|
86289
|
+
agentSettingsModelEffort: this.#modelEffort
|
|
86290
|
+
}
|
|
85899
86291
|
};
|
|
85900
86292
|
}
|
|
85901
86293
|
if (this.#sessionLoad.kind === "loaded") {
|
|
85902
86294
|
return this.#sessionLoad.history;
|
|
85903
86295
|
}
|
|
85904
86296
|
}
|
|
85905
|
-
return (await this.#loadSession(signal
|
|
86297
|
+
return (await this.#loadSession(signal)).history;
|
|
85906
86298
|
}
|
|
85907
|
-
async #loadSession(signal
|
|
86299
|
+
async #loadSession(signal) {
|
|
85908
86300
|
if (this.#sessionLoad.kind === "loaded") {
|
|
85909
86301
|
return this.#sessionLoad;
|
|
85910
86302
|
}
|
|
@@ -85915,24 +86307,13 @@ var AgentSession = class _AgentSession {
|
|
|
85915
86307
|
const history = new HistoryReplayCapture(this.#store.events, this.#mobiusSessionId);
|
|
85916
86308
|
const completion = Promise.resolve().then(async () => {
|
|
85917
86309
|
try {
|
|
85918
|
-
const
|
|
85919
|
-
this.#
|
|
85920
|
-
|
|
85921
|
-
|
|
85922
|
-
additionalDirectories: [...this.#additionalDirectories],
|
|
85923
|
-
cwd: this.#cwd,
|
|
85924
|
-
mcpServers: [],
|
|
85925
|
-
sessionId: this.#updates.sessionId()
|
|
85926
|
-
},
|
|
85927
|
-
{ cancellationSignal: signal }
|
|
85928
|
-
),
|
|
85929
|
-
exitMessage,
|
|
85930
|
-
signal
|
|
85931
|
-
);
|
|
85932
|
-
await this.#updates.drained();
|
|
86310
|
+
const opened = await this.#adapter.openSessionWithReplay({
|
|
86311
|
+
...this.#sessionParams(signal),
|
|
86312
|
+
nativeSessionId: this.nativeSessionId()
|
|
86313
|
+
});
|
|
85933
86314
|
signal.throwIfAborted();
|
|
85934
|
-
this.
|
|
85935
|
-
const loaded = { history, kind: "loaded",
|
|
86315
|
+
this.#capabilities = opened.capabilities;
|
|
86316
|
+
const loaded = { history, kind: "loaded", opened };
|
|
85936
86317
|
this.#sessionLoad = loaded;
|
|
85937
86318
|
return loaded;
|
|
85938
86319
|
} catch (cause) {
|
|
@@ -85943,24 +86324,10 @@ var AgentSession = class _AgentSession {
|
|
|
85943
86324
|
this.#sessionLoad = { completion, history, kind: "capturing" };
|
|
85944
86325
|
return await completion;
|
|
85945
86326
|
}
|
|
85946
|
-
async #initializeAgent(signal) {
|
|
85947
|
-
await this.#metrics.measure("agent-initialize", async () => await this.#initializeAgentOperation(signal));
|
|
85948
|
-
}
|
|
85949
|
-
async #initializeAgentOperation(signal) {
|
|
85950
|
-
const initialized = await initializeAgentConnection(
|
|
85951
|
-
this.#connection,
|
|
85952
|
-
this.#agentId,
|
|
85953
|
-
this.#verifiedAgentVersion,
|
|
85954
|
-
signal
|
|
85955
|
-
);
|
|
85956
|
-
this.#capabilities = initialized.capabilities;
|
|
85957
|
-
this.#agentName = initialized.agentName;
|
|
85958
|
-
this.#agentVersion = initialized.agentVersion;
|
|
85959
|
-
}
|
|
85960
86327
|
initialize = async (signal, recovery, origin) => await restoreSession(this, signal, recovery, origin);
|
|
85961
|
-
nativeSessionId = () => this.#
|
|
86328
|
+
nativeSessionId = () => this.#nativeSessionId;
|
|
85962
86329
|
adoptNativeSessionId = (sessionId) => {
|
|
85963
|
-
if (this.#prompted || this.#
|
|
86330
|
+
if (this.#prompted || this.#nativeSessionId !== sessionId) {
|
|
85964
86331
|
throw new AcpExecutionError("The new native Session cannot be adopted", {}, "session_identity_mismatch");
|
|
85965
86332
|
}
|
|
85966
86333
|
const previousSessionId = this.#mobiusSessionId;
|
|
@@ -85982,7 +86349,7 @@ var AgentSession = class _AgentSession {
|
|
|
85982
86349
|
};
|
|
85983
86350
|
#applyConfiguration = async (selection, signal) => {
|
|
85984
86351
|
const configRevision = this.#configRevision;
|
|
85985
|
-
const configured = await this.#adapter.configureSession(this.#target(), selection, signal);
|
|
86352
|
+
const configured = await this.#adapter.configureSession({ ...this.#target(), selection, signal });
|
|
85986
86353
|
if (this.#configRevision === configRevision) {
|
|
85987
86354
|
this.#configOptions = configured;
|
|
85988
86355
|
this.#configRevision = crypto.randomUUID();
|
|
@@ -86029,7 +86396,7 @@ var AgentSession = class _AgentSession {
|
|
|
86029
86396
|
await this.emitConfigUpdate();
|
|
86030
86397
|
};
|
|
86031
86398
|
#target = () => ({
|
|
86032
|
-
nativeSessionId: this.#
|
|
86399
|
+
nativeSessionId: this.#nativeSessionId,
|
|
86033
86400
|
cwd: this.#cwd,
|
|
86034
86401
|
additionalDirectories: this.#additionalDirectories
|
|
86035
86402
|
});
|
|
@@ -86041,11 +86408,18 @@ var AgentSession = class _AgentSession {
|
|
|
86041
86408
|
this.#sessionLoad = {
|
|
86042
86409
|
kind: "loaded",
|
|
86043
86410
|
history: new HistoryReplayCapture(this.#store.events, this.#mobiusSessionId),
|
|
86044
|
-
|
|
86411
|
+
opened: {
|
|
86412
|
+
nativeSessionId: this.nativeSessionId(),
|
|
86413
|
+
capabilities: this.#capabilities,
|
|
86414
|
+
configOptions: [],
|
|
86415
|
+
agentName: this.#agentName,
|
|
86416
|
+
agentVersion: this.#agentVersion,
|
|
86417
|
+
agentSettingsModelEffort: this.#modelEffort
|
|
86418
|
+
}
|
|
86045
86419
|
};
|
|
86046
86420
|
}
|
|
86047
86421
|
if (this.#capabilities.loadSession && this.#sessionLoad.kind !== "execution-only") {
|
|
86048
|
-
await this.#completedHistory(options.signal
|
|
86422
|
+
await this.#completedHistory(options.signal);
|
|
86049
86423
|
}
|
|
86050
86424
|
validatePromptContent(options, this.#capabilities);
|
|
86051
86425
|
if (this.#sessionTitle === null || this.#sessionTitle.length === 0) {
|
|
@@ -86079,7 +86453,7 @@ var AgentSession = class _AgentSession {
|
|
|
86079
86453
|
});
|
|
86080
86454
|
}
|
|
86081
86455
|
try {
|
|
86082
|
-
const result = await this.#adapter.prompt(this.#target(), options, options.signal);
|
|
86456
|
+
const result = await this.#adapter.prompt({ ...this.#target(), content: options, signal: options.signal });
|
|
86083
86457
|
this.writeStoredSession((/* @__PURE__ */ new Date()).toISOString());
|
|
86084
86458
|
if (lifecycle !== void 0) {
|
|
86085
86459
|
await this.recordLifecycleEvent({
|
|
@@ -86150,7 +86524,7 @@ var AgentSession = class _AgentSession {
|
|
|
86150
86524
|
});
|
|
86151
86525
|
}
|
|
86152
86526
|
try {
|
|
86153
|
-
const outcome = await this.#adapter.steer(this.#target(), options, options.signal);
|
|
86527
|
+
const outcome = await this.#adapter.steer({ ...this.#target(), content: options, signal: options.signal });
|
|
86154
86528
|
if (lifecycle !== void 0) {
|
|
86155
86529
|
await this.recordLifecycleEvent({
|
|
86156
86530
|
payload: {
|
|
@@ -86184,7 +86558,7 @@ var AgentSession = class _AgentSession {
|
|
|
86184
86558
|
await this.#interactions.cancelPendingInteractions();
|
|
86185
86559
|
signal.throwIfAborted();
|
|
86186
86560
|
if (this.#turn.running) {
|
|
86187
|
-
return await this.#adapter.cancel(this.#target(), signal);
|
|
86561
|
+
return await this.#adapter.cancel({ ...this.#target(), signal });
|
|
86188
86562
|
}
|
|
86189
86563
|
return "retained";
|
|
86190
86564
|
};
|
|
@@ -86209,7 +86583,14 @@ var AgentSession = class _AgentSession {
|
|
|
86209
86583
|
await this.#getObserver().onSessionEvent?.(liveEvent2);
|
|
86210
86584
|
};
|
|
86211
86585
|
selectNativeSession = (sessionId) => {
|
|
86212
|
-
this.#
|
|
86586
|
+
if (this.#nativeSessionId.length > 0 && this.#nativeSessionId !== sessionId) {
|
|
86587
|
+
throw new AcpExecutionError(
|
|
86588
|
+
"ACP agent attempted to replace the selected session",
|
|
86589
|
+
{},
|
|
86590
|
+
"invalid_agent_session"
|
|
86591
|
+
);
|
|
86592
|
+
}
|
|
86593
|
+
this.#nativeIdentity = { kind: "bound", nativeSessionId: sessionId };
|
|
86213
86594
|
this.#nativeHistoryOwnership = { kind: "agent-owned" };
|
|
86214
86595
|
};
|
|
86215
86596
|
#processEvent = async (event) => {
|
|
@@ -86254,7 +86635,7 @@ var AgentSession = class _AgentSession {
|
|
|
86254
86635
|
break;
|
|
86255
86636
|
}
|
|
86256
86637
|
}
|
|
86257
|
-
if (this.#
|
|
86638
|
+
if (this.#nativeSessionId.length > 0) {
|
|
86258
86639
|
this.writeStoredSession((/* @__PURE__ */ new Date()).toISOString());
|
|
86259
86640
|
}
|
|
86260
86641
|
await this.#getObserver().onInfo({
|
|
@@ -86276,31 +86657,28 @@ var AgentSession = class _AgentSession {
|
|
|
86276
86657
|
await this.closeProcess();
|
|
86277
86658
|
}
|
|
86278
86659
|
}
|
|
86279
|
-
if (this.#
|
|
86660
|
+
if (this.#nativeSessionId.length === 0) {
|
|
86280
86661
|
await this.closeProcess();
|
|
86281
86662
|
return;
|
|
86282
86663
|
}
|
|
86283
|
-
await this.#adapter.closeSession(this.#target(), AbortSignal.timeout(3e4));
|
|
86664
|
+
await this.#adapter.closeSession({ ...this.#target(), signal: AbortSignal.timeout(3e4) });
|
|
86284
86665
|
};
|
|
86285
|
-
closeProcess = () =>
|
|
86286
|
-
|
|
86287
|
-
|
|
86288
|
-
|
|
86289
|
-
|
|
86290
|
-
|
|
86291
|
-
|
|
86292
|
-
|
|
86293
|
-
|
|
86294
|
-
|
|
86295
|
-
|
|
86296
|
-
|
|
86297
|
-
|
|
86298
|
-
|
|
86299
|
-
|
|
86300
|
-
|
|
86301
|
-
async loadSession(signal, exitMessage) {
|
|
86302
|
-
return await this.#loadSession(signal, exitMessage);
|
|
86303
|
-
}
|
|
86666
|
+
closeProcess = async () => {
|
|
86667
|
+
if (this.#nativeIdentity.kind === "bound") {
|
|
86668
|
+
await this.#adapter.releaseSession({ ...this.#target(), signal: AbortSignal.timeout(3e4) });
|
|
86669
|
+
}
|
|
86670
|
+
this.#backgroundActivity = "none";
|
|
86671
|
+
};
|
|
86672
|
+
agentSettingsModelEffort = () => this.#modelEffort;
|
|
86673
|
+
#sessionParams = (signal) => ({
|
|
86674
|
+
...this.#subscriber,
|
|
86675
|
+
scope: this.#scope,
|
|
86676
|
+
signal
|
|
86677
|
+
});
|
|
86678
|
+
createSession = (signal) => this.#adapter.createSession(this.#sessionParams(signal));
|
|
86679
|
+
forkSession = (sourceSessionId, signal) => this.#adapter.forkSession({ ...this.#sessionParams(signal), sourceNativeSessionId: sourceSessionId });
|
|
86680
|
+
openSession = (signal) => this.#adapter.openSession({ ...this.#sessionParams(signal), nativeSessionId: this.nativeSessionId() });
|
|
86681
|
+
openSessionWithReplay = async (signal) => (await this.#loadSession(signal)).opened;
|
|
86304
86682
|
setConfigOptions(options) {
|
|
86305
86683
|
this.#configOptions = options;
|
|
86306
86684
|
this.#configRevision = crypto.randomUUID();
|
|
@@ -86318,7 +86696,7 @@ var AgentSession = class _AgentSession {
|
|
|
86318
86696
|
this.#sessionTitle = title2;
|
|
86319
86697
|
}
|
|
86320
86698
|
assertNativeSession = (sessionId) => {
|
|
86321
|
-
if (sessionId !== this.#
|
|
86699
|
+
if (sessionId !== this.#nativeSessionId) {
|
|
86322
86700
|
throw new AcpExecutionError("ACP agent referenced an unknown session", {}, "invalid_agent_session");
|
|
86323
86701
|
}
|
|
86324
86702
|
};
|
|
@@ -86341,6 +86719,18 @@ function isNativeChatSessionId(agentId, sessionId) {
|
|
|
86341
86719
|
return (agentId === "codex" || agentId === "claude" || agentId === "pi") && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu.test(sessionId);
|
|
86342
86720
|
}
|
|
86343
86721
|
|
|
86722
|
+
// src/engine/session/native/native-query.ts
|
|
86723
|
+
function nativeSessionQuery(options) {
|
|
86724
|
+
const externalize = options.externalizeSessionUpdate;
|
|
86725
|
+
return {
|
|
86726
|
+
agent: options.agent,
|
|
86727
|
+
cwd: options.cwd,
|
|
86728
|
+
additionalDirectories: options.additionalDirectories,
|
|
86729
|
+
signal: options.signal,
|
|
86730
|
+
...externalize === void 0 ? {} : { externalizeUpdate: (update, signal) => externalize(options.sessionId, update, signal) }
|
|
86731
|
+
};
|
|
86732
|
+
}
|
|
86733
|
+
|
|
86344
86734
|
// src/engine/session/turn/active-executions.ts
|
|
86345
86735
|
var unreachable2 = (state) => {
|
|
86346
86736
|
throw new AcpExecutionError("Unexpected execution state", { cause: state });
|
|
@@ -86540,21 +86930,29 @@ var SessionManager2 = class {
|
|
|
86540
86930
|
if (retiring !== void 0) {
|
|
86541
86931
|
await waitForSharedOperation(retiring, options.signal);
|
|
86542
86932
|
}
|
|
86543
|
-
const
|
|
86933
|
+
const stored = this.#store.read(options.sessionId);
|
|
86934
|
+
const capabilities = options.origin !== void 0 || stored instanceof FoundStoredSession && stored.session.prompted ? await options.adapter.getCapabilities(nativeSessionQuery(options)) : unsupportedSessionCapabilities();
|
|
86935
|
+
const runtime = await this.#processes.startRetained(
|
|
86936
|
+
options.signal,
|
|
86937
|
+
() => start(capabilities),
|
|
86938
|
+
this.#retention(options.sessionId)
|
|
86939
|
+
);
|
|
86544
86940
|
this.#executionProcesses.retain(options.sessionId, runtime);
|
|
86545
86941
|
return runtime;
|
|
86546
86942
|
}
|
|
86547
86943
|
async #startPreparation(options, recovery, metrics = unmeasuredOperationMetrics) {
|
|
86548
86944
|
return await this.#executionProcesses.prepare(options.sessionId, async () => {
|
|
86945
|
+
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;
|
|
86549
86946
|
return await this.#startRetainedSessionProcess(
|
|
86550
|
-
|
|
86551
|
-
async () => await AgentSession.start(
|
|
86552
|
-
|
|
86947
|
+
effectiveOptions,
|
|
86948
|
+
async (capabilities) => await AgentSession.start(
|
|
86949
|
+
effectiveOptions,
|
|
86553
86950
|
recovery,
|
|
86554
86951
|
() => this.#observer,
|
|
86555
86952
|
this.#store,
|
|
86556
86953
|
metrics,
|
|
86557
|
-
options.adapter
|
|
86954
|
+
options.adapter,
|
|
86955
|
+
capabilities
|
|
86558
86956
|
)
|
|
86559
86957
|
);
|
|
86560
86958
|
});
|
|
@@ -86569,13 +86967,14 @@ var SessionManager2 = class {
|
|
|
86569
86967
|
this.#store.remove(options.sessionId);
|
|
86570
86968
|
return await this.#startRetainedSessionProcess(
|
|
86571
86969
|
options,
|
|
86572
|
-
async () => await AgentSession.start(
|
|
86970
|
+
async (capabilities) => await AgentSession.start(
|
|
86573
86971
|
options,
|
|
86574
86972
|
recovery,
|
|
86575
86973
|
() => this.#observer,
|
|
86576
86974
|
this.#store,
|
|
86577
86975
|
metrics,
|
|
86578
|
-
options.adapter
|
|
86976
|
+
options.adapter,
|
|
86977
|
+
capabilities
|
|
86579
86978
|
)
|
|
86580
86979
|
);
|
|
86581
86980
|
});
|
|
@@ -86587,13 +86986,14 @@ var SessionManager2 = class {
|
|
|
86587
86986
|
await this.#retireSessionProcess(options.sessionId, existing, async () => await existing.close());
|
|
86588
86987
|
const runtime = await this.#startRetainedSessionProcess(
|
|
86589
86988
|
options,
|
|
86590
|
-
async () => await AgentSession.start(
|
|
86989
|
+
async (capabilities) => await AgentSession.start(
|
|
86591
86990
|
options,
|
|
86592
86991
|
recovery,
|
|
86593
86992
|
() => this.#observer,
|
|
86594
86993
|
this.#store,
|
|
86595
86994
|
unmeasuredOperationMetrics,
|
|
86596
|
-
options.adapter
|
|
86995
|
+
options.adapter,
|
|
86996
|
+
capabilities
|
|
86597
86997
|
)
|
|
86598
86998
|
);
|
|
86599
86999
|
try {
|
|
@@ -87204,7 +87604,7 @@ var SessionManager2 = class {
|
|
|
87204
87604
|
};
|
|
87205
87605
|
|
|
87206
87606
|
// src/engine/session/native/native-session-browser.ts
|
|
87207
|
-
import { randomUUID as
|
|
87607
|
+
import { randomUUID as randomUUID14 } from "node:crypto";
|
|
87208
87608
|
|
|
87209
87609
|
// src/engine/session/workspace/local-authorization-error.ts
|
|
87210
87610
|
var LocalAuthorizationError = class extends OperationError {
|
|
@@ -87263,17 +87663,14 @@ var NativeSessionService = class {
|
|
|
87263
87663
|
(scoped) => this.#sessions.withNativeSessionOperation(
|
|
87264
87664
|
scoped,
|
|
87265
87665
|
nativeSessionId,
|
|
87266
|
-
(target) => target.adapter.readSessionHistory(
|
|
87267
|
-
target
|
|
87268
|
-
|
|
87269
|
-
{
|
|
87666
|
+
(target) => target.adapter.readSessionHistory({
|
|
87667
|
+
query: nativeSessionQuery(target),
|
|
87668
|
+
request: {
|
|
87270
87669
|
nativeSessionId,
|
|
87271
87670
|
eventLimit,
|
|
87272
|
-
cursor
|
|
87273
|
-
|
|
87274
|
-
|
|
87275
|
-
target.signal
|
|
87276
|
-
)
|
|
87671
|
+
cursor
|
|
87672
|
+
}
|
|
87673
|
+
})
|
|
87277
87674
|
)
|
|
87278
87675
|
);
|
|
87279
87676
|
#execute = async (command, signal) => {
|
|
@@ -87304,7 +87701,7 @@ var NativeSessionService = class {
|
|
|
87304
87701
|
queuedCancellation: "before-start"
|
|
87305
87702
|
};
|
|
87306
87703
|
}
|
|
87307
|
-
const capabilities = await options.adapter.getCapabilities(
|
|
87704
|
+
const capabilities = await options.adapter.getCapabilities(nativeSessionQuery(options));
|
|
87308
87705
|
if (!capabilities.listSessions) {
|
|
87309
87706
|
throw new AcpExecutionError(
|
|
87310
87707
|
"This Agent does not support native session listing",
|
|
@@ -87319,7 +87716,7 @@ var NativeSessionService = class {
|
|
|
87319
87716
|
if (authorized === null) {
|
|
87320
87717
|
return null;
|
|
87321
87718
|
}
|
|
87322
|
-
const entryId = decodeIdentifier(
|
|
87719
|
+
const entryId = decodeIdentifier(randomUUID14());
|
|
87323
87720
|
if (this.#entries.size >= 5e3) {
|
|
87324
87721
|
this.#entries.clear();
|
|
87325
87722
|
}
|
|
@@ -87358,7 +87755,7 @@ var NativeSessionService = class {
|
|
|
87358
87755
|
}
|
|
87359
87756
|
cursor = known.cursor;
|
|
87360
87757
|
}
|
|
87361
|
-
const page = await options.adapter.listSessions(
|
|
87758
|
+
const page = await options.adapter.listSessions({ query: nativeSessionQuery(options), cursor });
|
|
87362
87759
|
const entries = [];
|
|
87363
87760
|
for (const info of page.sessions) {
|
|
87364
87761
|
const entry = await register(info);
|
|
@@ -87375,7 +87772,7 @@ var NativeSessionService = class {
|
|
|
87375
87772
|
"invalid_native_session_response"
|
|
87376
87773
|
);
|
|
87377
87774
|
}
|
|
87378
|
-
nextCursor = decodeIdentifier(
|
|
87775
|
+
nextCursor = decodeIdentifier(randomUUID14());
|
|
87379
87776
|
if (this.#cursors.size >= 500) {
|
|
87380
87777
|
this.#cursors.clear();
|
|
87381
87778
|
}
|
|
@@ -87393,15 +87790,14 @@ var NativeSessionService = class {
|
|
|
87393
87790
|
};
|
|
87394
87791
|
}
|
|
87395
87792
|
if (command.action === "find") {
|
|
87396
|
-
const found = await options.adapter.findSession(
|
|
87397
|
-
|
|
87398
|
-
command.nativeSessionId,
|
|
87399
|
-
{
|
|
87793
|
+
const found = await options.adapter.findSession({
|
|
87794
|
+
query: nativeSessionQuery(options),
|
|
87795
|
+
nativeSessionId: command.nativeSessionId,
|
|
87796
|
+
budget: {
|
|
87400
87797
|
maximumPages: 500,
|
|
87401
87798
|
maximumEntries: 500
|
|
87402
|
-
}
|
|
87403
|
-
|
|
87404
|
-
);
|
|
87799
|
+
}
|
|
87800
|
+
});
|
|
87405
87801
|
const entry = await register(found);
|
|
87406
87802
|
if (entry !== null) {
|
|
87407
87803
|
return { ...envelope2, action: "find", entry };
|
|
@@ -87539,15 +87935,14 @@ var NativeSessionService = class {
|
|
|
87539
87935
|
}
|
|
87540
87936
|
};
|
|
87541
87937
|
resolveTarget = async (command, options, selected) => {
|
|
87542
|
-
const info = await options.adapter.findSession(
|
|
87543
|
-
options
|
|
87544
|
-
selected.nativeSessionId,
|
|
87545
|
-
{
|
|
87938
|
+
const info = await options.adapter.findSession({
|
|
87939
|
+
query: nativeSessionQuery(options),
|
|
87940
|
+
nativeSessionId: selected.nativeSessionId,
|
|
87941
|
+
budget: {
|
|
87546
87942
|
maximumPages: 100,
|
|
87547
87943
|
maximumEntries: null
|
|
87548
|
-
}
|
|
87549
|
-
|
|
87550
|
-
).catch((cause) => {
|
|
87944
|
+
}
|
|
87945
|
+
}).catch((cause) => {
|
|
87551
87946
|
options.signal.throwIfAborted();
|
|
87552
87947
|
if (cause instanceof AcpExecutionError && cause.code === "native_session_not_found") {
|
|
87553
87948
|
throw new AcpExecutionError(
|
|
@@ -87816,7 +88211,7 @@ async function settleAbandonedTurn(projection, operations, cancellation) {
|
|
|
87816
88211
|
}
|
|
87817
88212
|
|
|
87818
88213
|
// src/engine/session/turn/execution-receipts.ts
|
|
87819
|
-
import { createHash as createHash7, randomUUID as
|
|
88214
|
+
import { createHash as createHash7, randomUUID as randomUUID15 } from "node:crypto";
|
|
87820
88215
|
var MAX_TERMINAL_RECEIPTS = 1024;
|
|
87821
88216
|
var ExecutionReceipts = class {
|
|
87822
88217
|
#executions = /* @__PURE__ */ new Map();
|
|
@@ -87957,7 +88352,7 @@ var ExecutionReceipts = class {
|
|
|
87957
88352
|
).digest("hex");
|
|
87958
88353
|
this.#save(commandId, {
|
|
87959
88354
|
admissionOrder: this.#nextAdmissionOrder(),
|
|
87960
|
-
attemptId:
|
|
88355
|
+
attemptId: randomUUID15(),
|
|
87961
88356
|
commandHash,
|
|
87962
88357
|
sessionId,
|
|
87963
88358
|
started: false,
|
|
@@ -88039,7 +88434,7 @@ var ExecutionReceipts = class {
|
|
|
88039
88434
|
if (identity2 !== void 0) {
|
|
88040
88435
|
return identity2.sessionId === sessionId && identity2.commandHash === commandHash ? { kind: "expired" } : { kind: "conflict" };
|
|
88041
88436
|
}
|
|
88042
|
-
const attemptId =
|
|
88437
|
+
const attemptId = randomUUID15();
|
|
88043
88438
|
this.#save(commandId, {
|
|
88044
88439
|
admissionOrder: this.#nextAdmissionOrder(),
|
|
88045
88440
|
attemptId,
|
|
@@ -88166,7 +88561,7 @@ var RuntimeTurnActivity = class {
|
|
|
88166
88561
|
};
|
|
88167
88562
|
|
|
88168
88563
|
// src/engine/session/turn/active-turn.ts
|
|
88169
|
-
import { randomUUID as
|
|
88564
|
+
import { randomUUID as randomUUID16 } from "node:crypto";
|
|
88170
88565
|
var ActiveRuntimeTurn = class {
|
|
88171
88566
|
attemptId;
|
|
88172
88567
|
command;
|
|
@@ -88176,7 +88571,7 @@ var ActiveRuntimeTurn = class {
|
|
|
88176
88571
|
#dispatch;
|
|
88177
88572
|
#sequence = 0;
|
|
88178
88573
|
#interaction = null;
|
|
88179
|
-
#epoch = decodeIdentifier(
|
|
88574
|
+
#epoch = decodeIdentifier(randomUUID16());
|
|
88180
88575
|
constructor(command, attemptId) {
|
|
88181
88576
|
this.attemptId = attemptId;
|
|
88182
88577
|
this.command = command;
|
|
@@ -88742,11 +89137,11 @@ import { extname as extname2, join as join29 } from "node:path";
|
|
|
88742
89137
|
import { pathToFileURL as pathToFileURL3 } from "node:url";
|
|
88743
89138
|
|
|
88744
89139
|
// src/engine/storage/files/scratch-directory.ts
|
|
88745
|
-
import { randomUUID as
|
|
89140
|
+
import { randomUUID as randomUUID17 } from "node:crypto";
|
|
88746
89141
|
import { lstat as lstat4, mkdir as mkdir5, readdir as readdir6, readFile as readFile6, realpath as realpath7, rename as rename4, rm as rm3, stat as stat6, utimes, writeFile as writeFile2 } from "node:fs/promises";
|
|
88747
89142
|
import { dirname as dirname11, join as join28 } from "node:path";
|
|
88748
89143
|
async function atomicWrite(path7, bytes, signal) {
|
|
88749
|
-
const temporary = `${path7}.${
|
|
89144
|
+
const temporary = `${path7}.${randomUUID17()}.tmp`;
|
|
88750
89145
|
try {
|
|
88751
89146
|
await writeFile2(temporary, bytes, { mode: 384, signal });
|
|
88752
89147
|
signal.throwIfAborted();
|
|
@@ -88758,7 +89153,7 @@ async function atomicWrite(path7, bytes, signal) {
|
|
|
88758
89153
|
var ScratchDirectory = class {
|
|
88759
89154
|
#root;
|
|
88760
89155
|
constructor(parent) {
|
|
88761
|
-
this.#root = join28(parent,
|
|
89156
|
+
this.#root = join28(parent, randomUUID17());
|
|
88762
89157
|
}
|
|
88763
89158
|
/** Refreshes this directory's lease and removes sibling directories whose lease is older than `leaseMilliseconds`. */
|
|
88764
89159
|
refreshLease = async (leaseMilliseconds) => {
|
|
@@ -90764,7 +91159,7 @@ function createNativeSessionCommands(context) {
|
|
|
90764
91159
|
}
|
|
90765
91160
|
|
|
90766
91161
|
// src/engine/session/prompt/apply-session-configuration.ts
|
|
90767
|
-
import { randomUUID as
|
|
91162
|
+
import { randomUUID as randomUUID18 } from "node:crypto";
|
|
90768
91163
|
function invalidSessionConfiguration(message) {
|
|
90769
91164
|
return new AcpExecutionError(message, {}, "invalid_session_configuration");
|
|
90770
91165
|
}
|
|
@@ -90902,7 +91297,7 @@ async function applySessionConfigurationSelection(sessions, options, selection,
|
|
|
90902
91297
|
booleanValue: selection.booleanValue,
|
|
90903
91298
|
configId: selection.configId,
|
|
90904
91299
|
cwd,
|
|
90905
|
-
requestId: `cfg_${
|
|
91300
|
+
requestId: `cfg_${randomUUID18()}`,
|
|
90906
91301
|
sessionId,
|
|
90907
91302
|
signal,
|
|
90908
91303
|
value: selection.value,
|
|
@@ -90968,7 +91363,11 @@ async function executePrompt({
|
|
|
90968
91363
|
command.additionalDirectoryIds,
|
|
90969
91364
|
signal
|
|
90970
91365
|
);
|
|
90971
|
-
const { agent, adapter } = await resolveAgent(
|
|
91366
|
+
const { agent, adapter, externalizeSessionUpdate } = await resolveAgent(
|
|
91367
|
+
command.agentId,
|
|
91368
|
+
signal,
|
|
91369
|
+
command.sessionId
|
|
91370
|
+
);
|
|
90972
91371
|
const availability = await waitForSessionAvailability(signal);
|
|
90973
91372
|
if (availability.kind === "busy") {
|
|
90974
91373
|
throw new AcpExecutionError("Another prompt is already running in this conversation", {}, "session_busy");
|
|
@@ -90986,6 +91385,7 @@ async function executePrompt({
|
|
|
90986
91385
|
const recovery = command.historyPolicy === SessionHistoryPolicy.ExecutionOnly ? { kind: "execution-only" } : { kind: "interactive-only" };
|
|
90987
91386
|
const preparation = {
|
|
90988
91387
|
adapter,
|
|
91388
|
+
...externalizeSessionUpdate === void 0 ? {} : { externalizeSessionUpdate },
|
|
90989
91389
|
additionalDirectories: resolved.additionalDirectories,
|
|
90990
91390
|
agent: executionAgent,
|
|
90991
91391
|
cwd: resolved.cwd,
|
|
@@ -91040,6 +91440,7 @@ async function executePrompt({
|
|
|
91040
91440
|
if (availability.disposition === SessionPromptDisposition.Steer) {
|
|
91041
91441
|
await sessions.steerPrompt({
|
|
91042
91442
|
adapter,
|
|
91443
|
+
...externalizeSessionUpdate === void 0 ? {} : { externalizeSessionUpdate },
|
|
91043
91444
|
additionalDirectories: resolved.additionalDirectories,
|
|
91044
91445
|
agent: executionAgent,
|
|
91045
91446
|
commandId: command.commandId,
|
|
@@ -91056,6 +91457,7 @@ async function executePrompt({
|
|
|
91056
91457
|
} else {
|
|
91057
91458
|
const result = await sessions.runPrompt({
|
|
91058
91459
|
adapter,
|
|
91460
|
+
...externalizeSessionUpdate === void 0 ? {} : { externalizeSessionUpdate },
|
|
91059
91461
|
additionalDirectories: resolved.additionalDirectories,
|
|
91060
91462
|
agent: executionAgent,
|
|
91061
91463
|
commandId: command.commandId,
|
|
@@ -91192,7 +91594,7 @@ var sessionPromptCommand = {
|
|
|
91192
91594
|
// package.json
|
|
91193
91595
|
var package_default = {
|
|
91194
91596
|
name: "@moxt-ai/mobius",
|
|
91195
|
-
version: "0.0.
|
|
91597
|
+
version: "0.0.360",
|
|
91196
91598
|
description: "Mobius CLI for pairing and running local AI agent services.",
|
|
91197
91599
|
type: "module",
|
|
91198
91600
|
bin: {
|
|
@@ -92454,7 +92856,7 @@ async function runRuntime(config2, parentSignal, timer = systemTimer, options =
|
|
|
92454
92856
|
const publisher = new RuntimeSessionEventPublisher(timer);
|
|
92455
92857
|
const externalContent = __using(_stack, new LocalExternalContentStore(stateDirectory), true);
|
|
92456
92858
|
const processes = new AgentProcessPool(config2.localContext.maxAcpProcesses, timer);
|
|
92457
|
-
const adapters = createRuntimeAdapterRegistry(
|
|
92859
|
+
const { adapters, externalizeSessionUpdate } = createRuntimeAdapterRegistry(
|
|
92458
92860
|
config2.adapters,
|
|
92459
92861
|
processes,
|
|
92460
92862
|
(sessionId, content, contentSignal) => externalContent.put({ ...content, sessionId, signal: contentSignal }),
|
|
@@ -92464,7 +92866,11 @@ async function runRuntime(config2, parentSignal, timer = systemTimer, options =
|
|
|
92464
92866
|
const catalogAgent = await resolveCatalogAgent(config2, agentId, resolveSignal);
|
|
92465
92867
|
const environment = sessionId === void 0 ? void 0 : config2.sessionEnvironment?.({ sessionId, agentId });
|
|
92466
92868
|
const agent = environment === void 0 ? catalogAgent : catalogAgent.withEnvironment({ ...catalogAgent.environment, ...environment });
|
|
92467
|
-
return {
|
|
92869
|
+
return {
|
|
92870
|
+
agent,
|
|
92871
|
+
adapter: adapters.resolve(catalogAgent),
|
|
92872
|
+
externalizeSessionUpdate
|
|
92873
|
+
};
|
|
92468
92874
|
};
|
|
92469
92875
|
const layer = buildSessionLayer({
|
|
92470
92876
|
processes,
|