@moxt-ai/mobius 0.0.356 → 0.0.358
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/LICENSE +202 -0
- package/dist/cli.js +414 -290
- package/dist/cli.js.map +3 -3
- package/dist/engine/acp/adapter/adapter-registry.d.ts +1 -1
- package/dist/engine/acp/adapter/adapter-registry.d.ts.map +1 -1
- package/dist/engine/acp/adapter/adapter-registry.js +2 -1
- package/dist/engine/acp/adapter/adapter-registry.js.map +1 -1
- package/dist/engine/acp/adapter/claude/adapter.d.ts +8 -35
- package/dist/engine/acp/adapter/claude/adapter.d.ts.map +1 -1
- package/dist/engine/acp/adapter/claude/adapter.js +7 -6
- package/dist/engine/acp/adapter/claude/adapter.js.map +1 -1
- package/dist/engine/acp/adapter/codex/adapter.d.ts +8 -35
- package/dist/engine/acp/adapter/codex/adapter.d.ts.map +1 -1
- package/dist/engine/acp/adapter/codex/adapter.js +27 -13
- package/dist/engine/acp/adapter/codex/adapter.js.map +1 -1
- package/dist/engine/acp/adapter/live-sessions.d.ts +1 -1
- package/dist/engine/acp/adapter/live-sessions.d.ts.map +1 -1
- package/dist/engine/acp/adapter/live-sessions.js +1 -0
- package/dist/engine/acp/adapter/live-sessions.js.map +1 -1
- 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 +8 -35
- package/dist/engine/acp/adapter/pi/adapter.d.ts.map +1 -1
- package/dist/engine/acp/adapter/pi/adapter.js +7 -6
- package/dist/engine/acp/adapter/pi/adapter.js.map +1 -1
- package/dist/engine/acp/adapter/query-processes.d.ts +10 -7
- package/dist/engine/acp/adapter/query-processes.d.ts.map +1 -1
- package/dist/engine/acp/adapter/query-processes.js +66 -79
- package/dist/engine/acp/adapter/query-processes.js.map +1 -1
- package/dist/engine/acp/adapter/query-session.d.ts +6 -4
- package/dist/engine/acp/adapter/query-session.d.ts.map +1 -1
- package/dist/engine/acp/adapter/query-session.js +37 -22
- package/dist/engine/acp/adapter/query-session.js.map +1 -1
- package/dist/engine/acp/adapter/registry.js +3 -3
- package/dist/engine/acp/adapter/registry.js.map +1 -1
- package/dist/engine/acp/adapter/session-events.d.ts +1 -0
- package/dist/engine/acp/adapter/session-events.d.ts.map +1 -1
- package/dist/engine/acp/adapter/session-events.js +60 -56
- package/dist/engine/acp/adapter/session-events.js.map +1 -1
- package/dist/engine/acp/content/content-externalizer.d.ts +8 -2
- package/dist/engine/acp/content/content-externalizer.d.ts.map +1 -1
- package/dist/engine/acp/content/content-externalizer.js +23 -6
- package/dist/engine/acp/content/content-externalizer.js.map +1 -1
- package/dist/engine/acp/harness/codex/agent.d.ts.map +1 -1
- package/dist/engine/acp/harness/codex/agent.js +14 -8
- package/dist/engine/acp/harness/codex/agent.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 +8 -2
- package/dist/engine/acp/harness/codex/borrowed-agent.js.map +1 -1
- package/dist/engine/acp/harness/codex/history.d.ts.map +1 -1
- package/dist/engine/acp/harness/codex/history.js +25 -23
- package/dist/engine/acp/harness/codex/history.js.map +1 -1
- package/dist/engine/acp/native-history/preview-contract.d.ts +6 -13
- package/dist/engine/acp/native-history/preview-contract.d.ts.map +1 -1
- package/dist/engine/agent/runtime-agents.d.ts +1 -1
- package/dist/engine/agent/runtime-agents.d.ts.map +1 -1
- package/dist/engine/agent/runtime-agents.js +2 -2
- 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 +2 -2
- package/dist/engine/runtime/run.js.map +1 -1
- package/dist/engine/session/content/external-content-store.d.ts +4 -0
- package/dist/engine/session/content/external-content-store.d.ts.map +1 -1
- package/dist/engine/session/content/external-content-store.js +31 -1
- package/dist/engine/session/content/external-content-store.js.map +1 -1
- package/dist/engine/session/live/agent-session.d.ts +1 -1
- package/dist/engine/session/live/agent-session.d.ts.map +1 -1
- package/dist/engine/session/live/agent-session.js +2 -1
- package/dist/engine/session/live/agent-session.js.map +1 -1
- package/dist/engine/session/manager/session-manager.d.ts.map +1 -1
- package/dist/engine/session/manager/session-manager.js +14 -1
- package/dist/engine/session/manager/session-manager.js.map +1 -1
- package/dist/engine/session/native/native-session-browser.d.ts.map +1 -1
- package/dist/engine/session/native/native-session-browser.js +8 -8
- package/dist/engine/session/native/native-session-browser.js.map +1 -1
- package/dist/engine/session/prompt/prompt-lifecycle.d.ts.map +1 -1
- package/dist/engine/session/prompt/prompt-lifecycle.js +6 -1
- package/dist/engine/session/prompt/prompt-lifecycle.js.map +1 -1
- package/dist/engine/session/turn/execution-receipts.d.ts.map +1 -1
- package/dist/engine/session/turn/execution-receipts.js +14 -4
- package/dist/engine/session/turn/execution-receipts.js.map +1 -1
- package/dist/engine.js +408 -283
- package/dist/engine.js.map +4 -4
- package/package.json +4 -4
package/dist/cli.js
CHANGED
|
@@ -2086,7 +2086,7 @@ var init_package = __esm({
|
|
|
2086
2086
|
"package.json"() {
|
|
2087
2087
|
package_default = {
|
|
2088
2088
|
name: "@moxt-ai/mobius",
|
|
2089
|
-
version: "0.0.
|
|
2089
|
+
version: "0.0.358",
|
|
2090
2090
|
description: "Mobius CLI for pairing and running local AI agent services.",
|
|
2091
2091
|
type: "module",
|
|
2092
2092
|
bin: {
|
|
@@ -2161,8 +2161,8 @@ var init_package = __esm({
|
|
|
2161
2161
|
ws: "^8.21.3"
|
|
2162
2162
|
},
|
|
2163
2163
|
keywords: [],
|
|
2164
|
-
author: "",
|
|
2165
|
-
license: "
|
|
2164
|
+
author: "Moxt",
|
|
2165
|
+
license: "Apache-2.0",
|
|
2166
2166
|
bugs: {
|
|
2167
2167
|
url: "https://github.com/moxt-ai/mobius/issues"
|
|
2168
2168
|
},
|
|
@@ -27237,6 +27237,7 @@ var init_events = __esm({
|
|
|
27237
27237
|
external_exports.object({
|
|
27238
27238
|
...lifecycleBase,
|
|
27239
27239
|
kind: external_exports.literal("prompt.completed"),
|
|
27240
|
+
execution: external_exports.literal("not-started").optional(),
|
|
27240
27241
|
stopReason: shortString
|
|
27241
27242
|
}).readonly(),
|
|
27242
27243
|
external_exports.object({
|
|
@@ -75794,6 +75795,7 @@ var init_borrowed_agent = __esm({
|
|
|
75794
75795
|
content,
|
|
75795
75796
|
clientId: randomUUID7(),
|
|
75796
75797
|
completion: Promise.withResolvers(),
|
|
75798
|
+
settled: Promise.withResolvers(),
|
|
75797
75799
|
input: { kind: "awaiting" }
|
|
75798
75800
|
};
|
|
75799
75801
|
this.#pending = pending;
|
|
@@ -75831,7 +75833,6 @@ var init_borrowed_agent = __esm({
|
|
|
75831
75833
|
throw cause;
|
|
75832
75834
|
} finally {
|
|
75833
75835
|
signal.removeEventListener("abort", abort);
|
|
75834
|
-
this.#pending = null;
|
|
75835
75836
|
if (outcome === "cancelled") {
|
|
75836
75837
|
try {
|
|
75837
75838
|
await this.#removeQueuedInput(pending.clientId);
|
|
@@ -75839,6 +75840,8 @@ var init_borrowed_agent = __esm({
|
|
|
75839
75840
|
console.error("The cancelled Codex queued input could not be removed", cause);
|
|
75840
75841
|
}
|
|
75841
75842
|
}
|
|
75843
|
+
this.#pending = null;
|
|
75844
|
+
pending.settled.resolve();
|
|
75842
75845
|
}
|
|
75843
75846
|
};
|
|
75844
75847
|
#removeQueuedInput = async (clientId) => {
|
|
@@ -75898,7 +75901,11 @@ var init_borrowed_agent = __esm({
|
|
|
75898
75901
|
);
|
|
75899
75902
|
};
|
|
75900
75903
|
cancel = async () => {
|
|
75901
|
-
this.#pending
|
|
75904
|
+
const pending = this.#pending;
|
|
75905
|
+
if (pending !== null) {
|
|
75906
|
+
pending.completion.resolve({ stopReason: "cancelled" });
|
|
75907
|
+
await pending.settled.promise;
|
|
75908
|
+
}
|
|
75902
75909
|
};
|
|
75903
75910
|
close = async () => {
|
|
75904
75911
|
this.#lifecycle = { kind: "closed" };
|
|
@@ -76925,40 +76932,42 @@ async function replayCodexHistory(client2, threadId, emit, signal) {
|
|
|
76925
76932
|
continue;
|
|
76926
76933
|
}
|
|
76927
76934
|
if (item.type === "userMessage") {
|
|
76928
|
-
const
|
|
76935
|
+
const contents = item.content.flatMap((content) => {
|
|
76929
76936
|
if (typeof content !== "object" || content === null) {
|
|
76930
76937
|
return [];
|
|
76931
76938
|
}
|
|
76932
76939
|
const type = Reflect.get(content, "type");
|
|
76933
|
-
const
|
|
76940
|
+
const text2 = Reflect.get(content, "text");
|
|
76934
76941
|
const url2 = Reflect.get(content, "url");
|
|
76935
76942
|
if (type === "image" && typeof url2 === "string") {
|
|
76936
76943
|
return [`[@image](${url2})`];
|
|
76937
76944
|
}
|
|
76938
|
-
return type === "text" && typeof
|
|
76939
|
-
})
|
|
76940
|
-
const
|
|
76941
|
-
|
|
76942
|
-
|
|
76943
|
-
|
|
76944
|
-
|
|
76945
|
-
|
|
76946
|
-
|
|
76947
|
-
|
|
76948
|
-
|
|
76949
|
-
|
|
76950
|
-
|
|
76951
|
-
|
|
76952
|
-
|
|
76953
|
-
|
|
76954
|
-
|
|
76955
|
-
|
|
76956
|
-
|
|
76957
|
-
|
|
76958
|
-
|
|
76959
|
-
|
|
76960
|
-
|
|
76961
|
-
|
|
76945
|
+
return type === "text" && typeof text2 === "string" ? [text2] : [];
|
|
76946
|
+
});
|
|
76947
|
+
for (const text2 of contents) {
|
|
76948
|
+
const history = await embedLocalHistoryImages(
|
|
76949
|
+
{ status: "available", truncated: false, messages: [{ role: "user", text: text2 }] },
|
|
76950
|
+
deadline
|
|
76951
|
+
);
|
|
76952
|
+
if (history.status !== "available") {
|
|
76953
|
+
continue;
|
|
76954
|
+
}
|
|
76955
|
+
const message = history.messages[0];
|
|
76956
|
+
for (const image of message?.images ?? []) {
|
|
76957
|
+
await emit({
|
|
76958
|
+
content: { type: "image", data: image.data, mimeType: image.mimeType },
|
|
76959
|
+
messageId: item.id,
|
|
76960
|
+
sessionUpdate: "user_message_chunk"
|
|
76961
|
+
});
|
|
76962
|
+
}
|
|
76963
|
+
const restoredText = message?.text ?? "";
|
|
76964
|
+
if (restoredText.length > 0) {
|
|
76965
|
+
await emit({
|
|
76966
|
+
content: { text: restoredText, type: "text" },
|
|
76967
|
+
messageId: item.id,
|
|
76968
|
+
sessionUpdate: "user_message_chunk"
|
|
76969
|
+
});
|
|
76970
|
+
}
|
|
76962
76971
|
}
|
|
76963
76972
|
} else if (item.type === "agentMessage") {
|
|
76964
76973
|
await emit(agentMessageUpdate(item.id, item.text));
|
|
@@ -77660,16 +77669,19 @@ var init_agent = __esm({
|
|
|
77660
77669
|
*/
|
|
77661
77670
|
close = () => {
|
|
77662
77671
|
if (this.#closePromise === null) {
|
|
77663
|
-
this.#appServer.detach();
|
|
77664
77672
|
this.#closePromise = (async () => {
|
|
77665
|
-
await this.#sessionAgent.close();
|
|
77666
|
-
const child = this.#appServer.child();
|
|
77667
77673
|
try {
|
|
77668
|
-
|
|
77669
|
-
await stopProcessTree(child, captured);
|
|
77674
|
+
await this.#sessionAgent.close();
|
|
77670
77675
|
} finally {
|
|
77671
|
-
this.#
|
|
77672
|
-
this.#
|
|
77676
|
+
this.#appServer.detach();
|
|
77677
|
+
const child = this.#appServer.child();
|
|
77678
|
+
try {
|
|
77679
|
+
const captured = await captureProcessTree(child);
|
|
77680
|
+
await stopProcessTree(child, captured);
|
|
77681
|
+
} finally {
|
|
77682
|
+
this.#connection?.close();
|
|
77683
|
+
this.#onBackgroundActivity?.("none");
|
|
77684
|
+
}
|
|
77673
77685
|
}
|
|
77674
77686
|
})();
|
|
77675
77687
|
}
|
|
@@ -80153,14 +80165,17 @@ var init_session = __esm({
|
|
|
80153
80165
|
});
|
|
80154
80166
|
|
|
80155
80167
|
// src/engine/acp/harness/pi/upstream/dist/acp/translate/pi-messages.js
|
|
80156
|
-
function
|
|
80168
|
+
function piUserMessageContent(content) {
|
|
80157
80169
|
if (typeof content === "string") {
|
|
80158
|
-
return content;
|
|
80170
|
+
return content.length === 0 ? [] : [{ type: "text", text: content }];
|
|
80159
80171
|
}
|
|
80160
80172
|
if (!Array.isArray(content)) {
|
|
80161
|
-
return
|
|
80173
|
+
return [];
|
|
80162
80174
|
}
|
|
80163
|
-
return content.
|
|
80175
|
+
return content.flatMap((value) => {
|
|
80176
|
+
const parsed = userContentSchema.safeParse(value);
|
|
80177
|
+
return parsed.success ? [parsed.data] : [];
|
|
80178
|
+
});
|
|
80164
80179
|
}
|
|
80165
80180
|
function normalizePiAssistantText(content) {
|
|
80166
80181
|
if (!Array.isArray(content)) {
|
|
@@ -80168,9 +80183,15 @@ function normalizePiAssistantText(content) {
|
|
|
80168
80183
|
}
|
|
80169
80184
|
return content.map((c) => c?.type === "text" && typeof c.text === "string" ? c.text : "").filter(Boolean).join("");
|
|
80170
80185
|
}
|
|
80186
|
+
var userContentSchema;
|
|
80171
80187
|
var init_pi_messages = __esm({
|
|
80172
80188
|
"src/engine/acp/harness/pi/upstream/dist/acp/translate/pi-messages.js"() {
|
|
80173
80189
|
"use strict";
|
|
80190
|
+
init_zod();
|
|
80191
|
+
userContentSchema = external_exports.discriminatedUnion("type", [
|
|
80192
|
+
external_exports.object({ type: external_exports.literal("text"), text: external_exports.string() }),
|
|
80193
|
+
external_exports.object({ type: external_exports.literal("image"), data: external_exports.string(), mimeType: external_exports.string() })
|
|
80194
|
+
]);
|
|
80174
80195
|
}
|
|
80175
80196
|
});
|
|
80176
80197
|
|
|
@@ -81612,13 +81633,13 @@ ${JSON.stringify(stats, null, 2)}`;
|
|
|
81612
81633
|
const m = entry.message;
|
|
81613
81634
|
const role = String(m?.role ?? "");
|
|
81614
81635
|
if (role === "user") {
|
|
81615
|
-
|
|
81616
|
-
|
|
81636
|
+
this.conn.startUserMessage();
|
|
81637
|
+
for (const content of piUserMessageContent(m.content)) {
|
|
81617
81638
|
await this.conn.sessionUpdate({
|
|
81618
81639
|
sessionId: session.sessionId,
|
|
81619
81640
|
update: {
|
|
81620
81641
|
sessionUpdate: "user_message_chunk",
|
|
81621
|
-
content
|
|
81642
|
+
content
|
|
81622
81643
|
}
|
|
81623
81644
|
});
|
|
81624
81645
|
}
|
|
@@ -82830,6 +82851,7 @@ var init_adapter_registry = __esm({
|
|
|
82830
82851
|
resolve = (agent) => {
|
|
82831
82852
|
const existing = this.#adapters.get(agent.id);
|
|
82832
82853
|
if (existing !== void 0) {
|
|
82854
|
+
existing.refreshAgent(agent);
|
|
82833
82855
|
return existing;
|
|
82834
82856
|
}
|
|
82835
82857
|
const adapter = this.#resolve(agent, this.#dependencies);
|
|
@@ -83304,63 +83326,64 @@ var init_session_events = __esm({
|
|
|
83304
83326
|
const externalized = await externalizer.update(options.sessionId(), notification.update, signal);
|
|
83305
83327
|
signal.throwIfAborted();
|
|
83306
83328
|
const update = externalized.agent;
|
|
83307
|
-
const eventUpdate
|
|
83308
|
-
|
|
83309
|
-
|
|
83310
|
-
|
|
83311
|
-
|
|
83312
|
-
|
|
83329
|
+
for (const eventUpdate of externalized.events) {
|
|
83330
|
+
const backgroundTask = update._meta?.["mobius.backgroundTask"];
|
|
83331
|
+
const payload = decodeAcpSessionUpdate(
|
|
83332
|
+
JSON.stringify(
|
|
83333
|
+
normalizeEvent(
|
|
83334
|
+
(update.sessionUpdate === "tool_call" || update.sessionUpdate === "tool_call_update") && backgroundTask !== void 0 && typeof eventUpdate === "object" && eventUpdate !== null ? { ...eventUpdate, backgroundTask } : eventUpdate
|
|
83335
|
+
)
|
|
83313
83336
|
)
|
|
83314
|
-
)
|
|
83315
|
-
|
|
83316
|
-
|
|
83317
|
-
|
|
83318
|
-
|
|
83319
|
-
|
|
83320
|
-
|
|
83321
|
-
|
|
83322
|
-
|
|
83323
|
-
|
|
83324
|
-
|
|
83325
|
-
|
|
83326
|
-
}
|
|
83327
|
-
|
|
83328
|
-
|
|
83329
|
-
|
|
83330
|
-
|
|
83331
|
-
|
|
83332
|
-
|
|
83333
|
-
|
|
83334
|
-
|
|
83335
|
-
|
|
83336
|
-
|
|
83337
|
-
|
|
83338
|
-
|
|
83339
|
-
|
|
83340
|
-
|
|
83341
|
-
|
|
83342
|
-
|
|
83343
|
-
|
|
83344
|
-
|
|
83345
|
-
|
|
83337
|
+
);
|
|
83338
|
+
let event;
|
|
83339
|
+
switch (update.sessionUpdate) {
|
|
83340
|
+
case "available_commands_update":
|
|
83341
|
+
event = {
|
|
83342
|
+
kind: "commands",
|
|
83343
|
+
payload,
|
|
83344
|
+
commands: update.availableCommands.slice(0, 500).map((command) => ({
|
|
83345
|
+
description: truncate(command.description, 500),
|
|
83346
|
+
inputHint: truncate(command.input?.hint ?? "", 255),
|
|
83347
|
+
name: truncate(command.name, 128)
|
|
83348
|
+
})).filter((command) => command.name.length > 0)
|
|
83349
|
+
};
|
|
83350
|
+
break;
|
|
83351
|
+
case "config_option_update":
|
|
83352
|
+
event = {
|
|
83353
|
+
kind: "configuration",
|
|
83354
|
+
payload,
|
|
83355
|
+
configOptions: protocol.normalizeUpdate(options.configOptions(), update.configOptions)
|
|
83356
|
+
};
|
|
83357
|
+
break;
|
|
83358
|
+
case "current_mode_update":
|
|
83359
|
+
event = { kind: "mode", payload, modeId: update.currentModeId };
|
|
83360
|
+
break;
|
|
83361
|
+
case "session_info_update": {
|
|
83362
|
+
const changes = [];
|
|
83363
|
+
if (Object.hasOwn(update, "title")) {
|
|
83364
|
+
changes.push({ kind: "title", value: truncate(update.title ?? "", 500) });
|
|
83365
|
+
}
|
|
83366
|
+
if (Object.hasOwn(update, "updatedAt")) {
|
|
83367
|
+
changes.push({ kind: "updated-at", value: truncate(update.updatedAt ?? "", 128) });
|
|
83368
|
+
}
|
|
83369
|
+
event = { kind: "info", payload, changes };
|
|
83370
|
+
break;
|
|
83346
83371
|
}
|
|
83347
|
-
|
|
83348
|
-
|
|
83372
|
+
case "user_message_chunk":
|
|
83373
|
+
case "agent_message_chunk":
|
|
83374
|
+
case "agent_thought_chunk":
|
|
83375
|
+
case "tool_call":
|
|
83376
|
+
case "tool_call_update":
|
|
83377
|
+
case "plan":
|
|
83378
|
+
case "plan_update":
|
|
83379
|
+
case "plan_removed":
|
|
83380
|
+
event = { kind: "content", payload };
|
|
83381
|
+
break;
|
|
83382
|
+
default:
|
|
83383
|
+
event = { kind: "other", payload };
|
|
83349
83384
|
}
|
|
83350
|
-
|
|
83351
|
-
case "agent_message_chunk":
|
|
83352
|
-
case "agent_thought_chunk":
|
|
83353
|
-
case "tool_call":
|
|
83354
|
-
case "tool_call_update":
|
|
83355
|
-
case "plan":
|
|
83356
|
-
case "plan_update":
|
|
83357
|
-
case "plan_removed":
|
|
83358
|
-
event = { kind: "content", payload };
|
|
83359
|
-
break;
|
|
83360
|
-
default:
|
|
83361
|
-
event = { kind: "other", payload };
|
|
83385
|
+
await options.onEvent(event);
|
|
83362
83386
|
}
|
|
83363
|
-
await options.onEvent(event);
|
|
83364
83387
|
});
|
|
83365
83388
|
this.events = this.#updates;
|
|
83366
83389
|
const client2 = {
|
|
@@ -83401,6 +83424,9 @@ var init_session_events = __esm({
|
|
|
83401
83424
|
get connection() {
|
|
83402
83425
|
return this.#connection.connection;
|
|
83403
83426
|
}
|
|
83427
|
+
get termination() {
|
|
83428
|
+
return this.#connection.termination;
|
|
83429
|
+
}
|
|
83404
83430
|
initialize = (signal) => this.#connection.initialize(signal);
|
|
83405
83431
|
agentSettingsModelEffort = () => this.#connection.agentSettingsModelEffort();
|
|
83406
83432
|
race = (operation, exitMessage, signal) => this.#connection.race(operation, exitMessage, signal);
|
|
@@ -83530,6 +83556,7 @@ var init_live_sessions = __esm({
|
|
|
83530
83556
|
"ACP agent exited while cancelling a prompt",
|
|
83531
83557
|
bounded
|
|
83532
83558
|
);
|
|
83559
|
+
return "retained";
|
|
83533
83560
|
};
|
|
83534
83561
|
closeSession = async (target, signal) => {
|
|
83535
83562
|
const session = this.#find(target);
|
|
@@ -83736,7 +83763,7 @@ var init_live_sessions = __esm({
|
|
|
83736
83763
|
});
|
|
83737
83764
|
|
|
83738
83765
|
// src/engine/acp/adapter/native-session-lookup.ts
|
|
83739
|
-
async function findNativeSession(list,
|
|
83766
|
+
async function findNativeSession(list, cwd, nativeSessionId, budget, signal) {
|
|
83740
83767
|
const decoded = lookupSchema.safeParse({ nativeSessionId, budget });
|
|
83741
83768
|
if (!decoded.success) {
|
|
83742
83769
|
throw new AcpExecutionError(
|
|
@@ -83750,9 +83777,9 @@ async function findNativeSession(list, query, nativeSessionId, budget) {
|
|
|
83750
83777
|
let inspected = 0;
|
|
83751
83778
|
const visited = /* @__PURE__ */ new Set();
|
|
83752
83779
|
for (let pageNumber = 0; pageNumber < limits.maximumPages; pageNumber += 1) {
|
|
83753
|
-
|
|
83754
|
-
const page = await list(
|
|
83755
|
-
|
|
83780
|
+
signal.throwIfAborted();
|
|
83781
|
+
const page = await list(cwd, cursor, signal);
|
|
83782
|
+
signal.throwIfAborted();
|
|
83756
83783
|
inspected += page.sessions.length;
|
|
83757
83784
|
const found = page.sessions.find((session) => session.sessionId === decoded.data.nativeSessionId);
|
|
83758
83785
|
if (found !== void 0) {
|
|
@@ -84533,51 +84560,56 @@ var AcpQuerySession;
|
|
|
84533
84560
|
var init_query_session = __esm({
|
|
84534
84561
|
"src/engine/acp/adapter/query-session.ts"() {
|
|
84535
84562
|
"use strict";
|
|
84536
|
-
init_value_utils();
|
|
84537
84563
|
init_acp_error();
|
|
84538
84564
|
init_native_session();
|
|
84539
84565
|
init_session_capabilities();
|
|
84540
84566
|
init_agent_initialization();
|
|
84541
84567
|
AcpQuerySession = class _AcpQuerySession {
|
|
84542
|
-
#
|
|
84568
|
+
#cwd;
|
|
84569
|
+
#sessionId;
|
|
84543
84570
|
#events;
|
|
84544
84571
|
#connection;
|
|
84572
|
+
#lifecycle = { kind: "open" };
|
|
84545
84573
|
#capabilities = unsupportedSessionCapabilities();
|
|
84546
84574
|
#configOptions = [];
|
|
84547
|
-
constructor(
|
|
84548
|
-
this.#
|
|
84575
|
+
constructor(agent, cwd, sessionId, events, connector) {
|
|
84576
|
+
this.#cwd = cwd;
|
|
84577
|
+
this.#sessionId = sessionId;
|
|
84549
84578
|
this.#events = events;
|
|
84550
84579
|
this.#connection = connector.connectQuerySession({
|
|
84551
|
-
agent
|
|
84552
|
-
cwd
|
|
84553
|
-
sessionId: () =>
|
|
84580
|
+
agent,
|
|
84581
|
+
cwd,
|
|
84582
|
+
sessionId: () => sessionId,
|
|
84554
84583
|
configOptions: () => this.#configOptions,
|
|
84555
84584
|
onEvent: async (event) => {
|
|
84556
|
-
this.#events.append(
|
|
84585
|
+
this.#events.append(sessionId, { type: "acp", payload: event.payload });
|
|
84557
84586
|
if (event.kind === "configuration") {
|
|
84558
84587
|
this.#configOptions = event.configOptions;
|
|
84559
84588
|
}
|
|
84560
84589
|
}
|
|
84561
84590
|
});
|
|
84591
|
+
void this.#connection.termination.then(() => {
|
|
84592
|
+
this.#lifecycle = { kind: "terminated" };
|
|
84593
|
+
});
|
|
84562
84594
|
}
|
|
84563
|
-
static start = async (
|
|
84595
|
+
static start = async (agent, cwd, sessionId, events, connector, signal) => {
|
|
84564
84596
|
for (let attempt = 1; attempt <= 2; attempt += 1) {
|
|
84565
|
-
await validateAgentRuntime(
|
|
84566
|
-
const runtime = new _AcpQuerySession(
|
|
84597
|
+
await validateAgentRuntime(agent, signal);
|
|
84598
|
+
const runtime = new _AcpQuerySession(agent, cwd, sessionId, events, connector);
|
|
84567
84599
|
try {
|
|
84568
84600
|
const initialized = await initializeAgentConnection(
|
|
84569
84601
|
runtime.#connection,
|
|
84570
|
-
|
|
84571
|
-
|
|
84572
|
-
|
|
84602
|
+
agent.id,
|
|
84603
|
+
agent.agentVersion,
|
|
84604
|
+
signal
|
|
84573
84605
|
);
|
|
84574
84606
|
runtime.#capabilities = initialized.capabilities;
|
|
84575
84607
|
return runtime;
|
|
84576
84608
|
} catch (error62) {
|
|
84577
84609
|
await runtime.closeProcess();
|
|
84578
|
-
|
|
84610
|
+
signal.throwIfAborted();
|
|
84579
84611
|
if (error62 instanceof RetryableAcpInitializationError && attempt === 1) {
|
|
84580
|
-
console.warn(`[${
|
|
84612
|
+
console.warn(`[${agent.id}-acp] ACP agent initialization failed; retrying once`);
|
|
84581
84613
|
continue;
|
|
84582
84614
|
}
|
|
84583
84615
|
if (error62 instanceof AcpExecutionError) {
|
|
@@ -84589,7 +84621,18 @@ var init_query_session = __esm({
|
|
|
84589
84621
|
throw new AcpExecutionError("ACP agent initialization failed");
|
|
84590
84622
|
};
|
|
84591
84623
|
capabilities = () => this.#capabilities;
|
|
84592
|
-
|
|
84624
|
+
hasTerminated = () => {
|
|
84625
|
+
switch (this.#lifecycle.kind) {
|
|
84626
|
+
case "open":
|
|
84627
|
+
return false;
|
|
84628
|
+
case "terminated":
|
|
84629
|
+
return true;
|
|
84630
|
+
default: {
|
|
84631
|
+
const unreachable3 = this.#lifecycle;
|
|
84632
|
+
return unreachable3;
|
|
84633
|
+
}
|
|
84634
|
+
}
|
|
84635
|
+
};
|
|
84593
84636
|
listNativeSessions = async (cursor, signal) => {
|
|
84594
84637
|
if (!this.#capabilities.listSessions) {
|
|
84595
84638
|
throw new AcpExecutionError(
|
|
@@ -84615,7 +84658,7 @@ var init_query_session = __esm({
|
|
|
84615
84658
|
}
|
|
84616
84659
|
return decoded.data;
|
|
84617
84660
|
};
|
|
84618
|
-
previewEvents = async (nativeSessionId, eventLimit, signal) => {
|
|
84661
|
+
previewEvents = async (nativeSessionId, eventLimit, additionalDirectories, signal) => {
|
|
84619
84662
|
if (!this.#capabilities.loadSession) {
|
|
84620
84663
|
throw new AcpExecutionError(
|
|
84621
84664
|
"This Agent restores context but does not provide message history.",
|
|
@@ -84623,14 +84666,14 @@ var init_query_session = __esm({
|
|
|
84623
84666
|
"native_history_unsupported"
|
|
84624
84667
|
);
|
|
84625
84668
|
}
|
|
84626
|
-
this.#events.reset(this.#
|
|
84669
|
+
this.#events.reset(this.#sessionId);
|
|
84627
84670
|
this.#connection.events.select(nativeSessionId);
|
|
84628
84671
|
await this.#connection.race(
|
|
84629
84672
|
this.#connection.connection.agent.request(
|
|
84630
84673
|
methods12.agent.session.load,
|
|
84631
84674
|
{
|
|
84632
|
-
additionalDirectories: [...
|
|
84633
|
-
cwd: this.#
|
|
84675
|
+
additionalDirectories: [...additionalDirectories],
|
|
84676
|
+
cwd: this.#cwd,
|
|
84634
84677
|
mcpServers: [],
|
|
84635
84678
|
sessionId: nativeSessionId
|
|
84636
84679
|
},
|
|
@@ -84641,14 +84684,16 @@ var init_query_session = __esm({
|
|
|
84641
84684
|
);
|
|
84642
84685
|
await this.#connection.events.drained();
|
|
84643
84686
|
signal.throwIfAborted();
|
|
84644
|
-
return this.#events.page(this.#
|
|
84687
|
+
return this.#events.page(this.#sessionId, eventLimit, null);
|
|
84645
84688
|
};
|
|
84646
84689
|
closeProcess = async () => await this.#connection.closeProcess();
|
|
84690
|
+
discardEvents = () => this.#events.remove(this.#sessionId);
|
|
84647
84691
|
};
|
|
84648
84692
|
}
|
|
84649
84693
|
});
|
|
84650
84694
|
|
|
84651
84695
|
// src/engine/acp/adapter/query-processes.ts
|
|
84696
|
+
import { randomUUID as randomUUID14 } from "node:crypto";
|
|
84652
84697
|
var AgentQueryProcesses;
|
|
84653
84698
|
var init_query_processes = __esm({
|
|
84654
84699
|
"src/engine/acp/adapter/query-processes.ts"() {
|
|
@@ -84656,121 +84701,99 @@ var init_query_processes = __esm({
|
|
|
84656
84701
|
init_session_event_store();
|
|
84657
84702
|
init_operation_drain();
|
|
84658
84703
|
init_retained_agent_processes();
|
|
84659
|
-
init_acp_error();
|
|
84660
84704
|
init_query_session();
|
|
84661
84705
|
AgentQueryProcesses = class {
|
|
84662
84706
|
#eventPreviewsBySession = /* @__PURE__ */ new Map();
|
|
84663
|
-
#
|
|
84707
|
+
#processesByAgent = /* @__PURE__ */ new Map();
|
|
84708
|
+
#agent;
|
|
84664
84709
|
#processes;
|
|
84665
84710
|
#store = new MemorySessionEventStore();
|
|
84666
84711
|
#connector;
|
|
84667
|
-
constructor(processes, connector) {
|
|
84712
|
+
constructor(agent, processes, connector) {
|
|
84713
|
+
this.#agent = agent;
|
|
84668
84714
|
this.#processes = processes;
|
|
84669
84715
|
this.#connector = connector;
|
|
84670
|
-
this.#processesByQuery = new RetainedAgentProcesses({
|
|
84671
|
-
touch: processes.touch,
|
|
84672
|
-
changed: processes.notifyChanged
|
|
84673
|
-
});
|
|
84674
84716
|
}
|
|
84675
|
-
|
|
84676
|
-
|
|
84677
|
-
|
|
84678
|
-
|
|
84717
|
+
refreshAgent = (agent) => {
|
|
84718
|
+
this.#agent = agent;
|
|
84719
|
+
};
|
|
84720
|
+
retire = async (readers, cwd, runtime) => {
|
|
84721
|
+
readers.detach(cwd, runtime);
|
|
84722
|
+
try {
|
|
84723
|
+
await this.#processes.retire(runtime, () => runtime.closeProcess());
|
|
84724
|
+
} finally {
|
|
84725
|
+
runtime.discardEvents();
|
|
84679
84726
|
}
|
|
84680
|
-
await this.#processes.retire(runtime, () => runtime.closeProcess());
|
|
84681
84727
|
};
|
|
84682
|
-
async #
|
|
84683
|
-
|
|
84684
|
-
|
|
84685
|
-
() => AcpQuerySession.start(options, this.#store, this.#connector),
|
|
84686
|
-
{
|
|
84687
|
-
isBusy: () => this.#processesByQuery.isBusy(options.sessionId),
|
|
84688
|
-
retire: (runtime2) => this.retire(options.sessionId, runtime2),
|
|
84689
|
-
retireIdle: (runtime2) => this.retire(options.sessionId, runtime2)
|
|
84690
|
-
}
|
|
84691
|
-
);
|
|
84692
|
-
this.#processesByQuery.retain(options.sessionId, runtime);
|
|
84693
|
-
return runtime;
|
|
84694
|
-
}
|
|
84695
|
-
async #startPreparation(options) {
|
|
84696
|
-
return await this.#processesByQuery.prepare(options.sessionId, async () => {
|
|
84697
|
-
return await this.#startRetained(options);
|
|
84698
|
-
});
|
|
84699
|
-
}
|
|
84700
|
-
async #replacePreparation(existing, options) {
|
|
84701
|
-
return await this.#processesByQuery.prepare(options.sessionId, async () => {
|
|
84702
|
-
await this.retire(options.sessionId, existing);
|
|
84703
|
-
return await this.#startRetained(options);
|
|
84704
|
-
});
|
|
84705
|
-
}
|
|
84706
|
-
#prepare = async (options) => {
|
|
84707
|
-
const pending = this.#processesByQuery.pending(options.sessionId);
|
|
84728
|
+
async #ensure(agent, readers, cwd, signal) {
|
|
84729
|
+
signal.throwIfAborted();
|
|
84730
|
+
const pending = readers.pending(cwd);
|
|
84708
84731
|
if (pending !== void 0) {
|
|
84709
|
-
|
|
84710
|
-
if (runtime2.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
|
|
84711
|
-
this.#processesByQuery.touch(options.sessionId, runtime2);
|
|
84712
|
-
return runtime2.capabilities();
|
|
84713
|
-
}
|
|
84714
|
-
return await this.#prepare(options);
|
|
84715
|
-
}
|
|
84716
|
-
const existing = this.#processesByQuery.get(options.sessionId);
|
|
84717
|
-
if (existing !== void 0) {
|
|
84718
|
-
if (existing.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
|
|
84719
|
-
this.#processesByQuery.touch(options.sessionId, existing);
|
|
84720
|
-
return existing.capabilities();
|
|
84721
|
-
}
|
|
84722
|
-
const runtime2 = await this.#replacePreparation(existing, options);
|
|
84723
|
-
return runtime2.capabilities();
|
|
84732
|
+
return await waitForSharedOperation(pending, signal);
|
|
84724
84733
|
}
|
|
84725
|
-
const
|
|
84726
|
-
|
|
84727
|
-
|
|
84728
|
-
async #ensure(options) {
|
|
84729
|
-
const existing = this.#processesByQuery.get(options.sessionId);
|
|
84730
|
-
if (existing !== void 0) {
|
|
84731
|
-
if (!existing.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
|
|
84732
|
-
throw new AcpExecutionError(
|
|
84733
|
-
"The agent or workspace cannot change after a conversation has started",
|
|
84734
|
-
{},
|
|
84735
|
-
"session_identity_mismatch"
|
|
84736
|
-
);
|
|
84737
|
-
}
|
|
84738
|
-
this.#processesByQuery.touch(options.sessionId, existing);
|
|
84734
|
+
const existing = readers.get(cwd);
|
|
84735
|
+
if (existing !== void 0 && !existing.hasTerminated()) {
|
|
84736
|
+
readers.touch(cwd, existing);
|
|
84739
84737
|
return existing;
|
|
84740
84738
|
}
|
|
84741
|
-
await
|
|
84742
|
-
|
|
84743
|
-
|
|
84744
|
-
|
|
84745
|
-
|
|
84746
|
-
|
|
84739
|
+
return await readers.prepare(cwd, async () => {
|
|
84740
|
+
if (existing !== void 0) {
|
|
84741
|
+
await this.retire(readers, cwd, existing);
|
|
84742
|
+
}
|
|
84743
|
+
const readerId = randomUUID14();
|
|
84744
|
+
const runtime = await this.#processes.startRetained(
|
|
84745
|
+
signal,
|
|
84746
|
+
() => AcpQuerySession.start(agent, cwd, readerId, this.#store, this.#connector, signal),
|
|
84747
|
+
{
|
|
84748
|
+
isBusy: () => readers.isBusy(cwd),
|
|
84749
|
+
retire: (runtime2) => this.retire(readers, cwd, runtime2),
|
|
84750
|
+
retireIdle: (runtime2) => this.retire(readers, cwd, runtime2)
|
|
84751
|
+
}
|
|
84752
|
+
);
|
|
84753
|
+
readers.retain(cwd, runtime);
|
|
84754
|
+
return runtime;
|
|
84755
|
+
});
|
|
84747
84756
|
}
|
|
84748
|
-
#use = async (
|
|
84749
|
-
|
|
84750
|
-
|
|
84751
|
-
|
|
84752
|
-
|
|
84757
|
+
#use = async (cwd, signal, operation) => {
|
|
84758
|
+
const agent = this.#agent;
|
|
84759
|
+
let readers = this.#processesByAgent.get(agent);
|
|
84760
|
+
if (readers === void 0) {
|
|
84761
|
+
readers = new RetainedAgentProcesses({
|
|
84762
|
+
touch: this.#processes.touch,
|
|
84763
|
+
changed: this.#processes.notifyChanged
|
|
84764
|
+
});
|
|
84765
|
+
this.#processesByAgent.set(agent, readers);
|
|
84766
|
+
}
|
|
84767
|
+
const current = readers;
|
|
84768
|
+
return await current.use(cwd, async () => await operation(await this.#ensure(agent, current, cwd, signal)));
|
|
84769
|
+
};
|
|
84770
|
+
capabilities = async (cwd, signal) => await this.#use(cwd, signal, async (runtime) => runtime.capabilities());
|
|
84771
|
+
listNativeSessions = async (cwd, cursor, signal) => await this.#use(cwd, signal, async (runtime) => await runtime.listNativeSessions(cursor, signal));
|
|
84772
|
+
previewSessionEvents = async (cwd, additionalDirectories, request, signal) => {
|
|
84773
|
+
signal.throwIfAborted();
|
|
84774
|
+
const agent = this.#agent;
|
|
84775
|
+
const { nativeSessionId, eventLimit, cursor, sessionId } = request;
|
|
84753
84776
|
if (cursor !== null) {
|
|
84754
|
-
const preview = this.#eventPreviewsBySession.get(
|
|
84777
|
+
const preview = this.#eventPreviewsBySession.get(sessionId);
|
|
84755
84778
|
if (preview === void 0 || preview.nativeSessionId !== nativeSessionId) {
|
|
84756
84779
|
throw new Error("The native event cursor is invalid");
|
|
84757
84780
|
}
|
|
84758
|
-
return preview.store.page(
|
|
84781
|
+
return preview.store.page(sessionId, eventLimit, cursor);
|
|
84759
84782
|
}
|
|
84760
84783
|
const store = new MemorySessionEventStore();
|
|
84761
|
-
const previous = this.#eventPreviewsBySession.get(
|
|
84784
|
+
const previous = this.#eventPreviewsBySession.get(sessionId);
|
|
84762
84785
|
previous?.store.close();
|
|
84763
|
-
this.#eventPreviewsBySession.set(
|
|
84786
|
+
this.#eventPreviewsBySession.set(sessionId, { nativeSessionId, store });
|
|
84764
84787
|
try {
|
|
84765
84788
|
return await this.#processes.runTransient(
|
|
84766
|
-
|
|
84767
|
-
async () => await AcpQuerySession.start(
|
|
84768
|
-
async (runtime) => await runtime.previewEvents(nativeSessionId, eventLimit,
|
|
84789
|
+
signal,
|
|
84790
|
+
async () => await AcpQuerySession.start(agent, cwd, sessionId, store, this.#connector, signal),
|
|
84791
|
+
async (runtime) => await runtime.previewEvents(nativeSessionId, eventLimit, additionalDirectories, signal),
|
|
84769
84792
|
async (runtime) => await runtime.closeProcess()
|
|
84770
84793
|
);
|
|
84771
84794
|
} catch (error62) {
|
|
84772
|
-
if (this.#eventPreviewsBySession.get(
|
|
84773
|
-
this.#eventPreviewsBySession.delete(
|
|
84795
|
+
if (this.#eventPreviewsBySession.get(sessionId)?.store === store) {
|
|
84796
|
+
this.#eventPreviewsBySession.delete(sessionId);
|
|
84774
84797
|
}
|
|
84775
84798
|
store.close();
|
|
84776
84799
|
throw error62;
|
|
@@ -84778,8 +84801,11 @@ var init_query_processes = __esm({
|
|
|
84778
84801
|
};
|
|
84779
84802
|
close = async () => {
|
|
84780
84803
|
await Promise.all(
|
|
84781
|
-
this.#
|
|
84804
|
+
[...this.#processesByAgent.values()].flatMap(
|
|
84805
|
+
(readers) => readers.entries().map(async ([cwd, runtime]) => await this.retire(readers, cwd, runtime))
|
|
84806
|
+
)
|
|
84782
84807
|
);
|
|
84808
|
+
this.#processesByAgent.clear();
|
|
84783
84809
|
for (const preview of this.#eventPreviewsBySession.values()) {
|
|
84784
84810
|
preview.store.close();
|
|
84785
84811
|
}
|
|
@@ -84804,12 +84830,13 @@ var init_adapter = __esm({
|
|
|
84804
84830
|
#queryProcesses;
|
|
84805
84831
|
#connector;
|
|
84806
84832
|
#liveSessions;
|
|
84807
|
-
constructor(dependencies) {
|
|
84833
|
+
constructor(agent, dependencies) {
|
|
84808
84834
|
this.#connector = new AcpSessionConnector(dependencies.contentExternalizer);
|
|
84809
84835
|
this.#liveSessions = new AcpLiveSessions(dependencies.contentExternalizer);
|
|
84810
|
-
this.#queryProcesses = new AgentQueryProcesses(dependencies.processes, this.#connector);
|
|
84836
|
+
this.#queryProcesses = new AgentQueryProcesses(agent, dependencies.processes, this.#connector);
|
|
84811
84837
|
}
|
|
84812
|
-
|
|
84838
|
+
refreshAgent = (agent) => this.#queryProcesses.refreshAgent(agent);
|
|
84839
|
+
getCapabilities = (cwd, signal) => this.#queryProcesses.capabilities(cwd, signal);
|
|
84813
84840
|
connectSession = (options) => this.#liveSessions.connectSession(options);
|
|
84814
84841
|
cancel = (...args) => this.#liveSessions.cancel(...args);
|
|
84815
84842
|
closeSession = (...args) => this.#liveSessions.closeSession(...args);
|
|
@@ -84817,9 +84844,9 @@ var init_adapter = __esm({
|
|
|
84817
84844
|
steer = (...args) => this.#liveSessions.steer(...args);
|
|
84818
84845
|
renameSession = (...args) => this.#liveSessions.renameSession(...args);
|
|
84819
84846
|
configureSession = (...args) => this.#liveSessions.configureSession(...args);
|
|
84820
|
-
listSessions =
|
|
84821
|
-
findSession = (
|
|
84822
|
-
readSessionHistory =
|
|
84847
|
+
listSessions = (cwd, cursor, signal) => this.#queryProcesses.listNativeSessions(cwd, cursor, signal);
|
|
84848
|
+
findSession = (cwd, nativeSessionId, budget, signal) => findNativeSession(this.listSessions, cwd, nativeSessionId, budget, signal);
|
|
84849
|
+
readSessionHistory = (cwd, additionalDirectories, request, signal) => this.#queryProcesses.previewSessionEvents(cwd, additionalDirectories, request, signal);
|
|
84823
84850
|
close = async () => await runCleanup(
|
|
84824
84851
|
() => this.#queryProcesses.close(),
|
|
84825
84852
|
() => this.#liveSessions.close()
|
|
@@ -90756,13 +90783,15 @@ var init_adapter2 = __esm({
|
|
|
90756
90783
|
init_session_events();
|
|
90757
90784
|
init_tool_event();
|
|
90758
90785
|
CodexAdapter = class {
|
|
90786
|
+
#agent;
|
|
90759
90787
|
#queryProcesses;
|
|
90760
90788
|
#connector;
|
|
90761
90789
|
#liveSessions;
|
|
90762
90790
|
#dependencies;
|
|
90763
90791
|
#contentExternalizer;
|
|
90764
90792
|
#previewCache = null;
|
|
90765
|
-
constructor(dependencies) {
|
|
90793
|
+
constructor(agent, dependencies) {
|
|
90794
|
+
this.#agent = agent;
|
|
90766
90795
|
this.#dependencies = dependencies;
|
|
90767
90796
|
this.#contentExternalizer = {
|
|
90768
90797
|
update: async (sessionId, update, signal) => {
|
|
@@ -90774,18 +90803,25 @@ var init_adapter2 = __esm({
|
|
|
90774
90803
|
};
|
|
90775
90804
|
this.#connector = new AcpSessionConnector(this.#contentExternalizer, fitCodexToolEvent);
|
|
90776
90805
|
this.#liveSessions = new AcpLiveSessions(this.#contentExternalizer, fitCodexToolEvent);
|
|
90777
|
-
this.#queryProcesses = new AgentQueryProcesses(dependencies.processes, this.#connector);
|
|
90806
|
+
this.#queryProcesses = new AgentQueryProcesses(agent, dependencies.processes, this.#connector);
|
|
90778
90807
|
}
|
|
90779
|
-
|
|
90808
|
+
refreshAgent = (agent) => {
|
|
90809
|
+
this.#agent = agent;
|
|
90810
|
+
this.#queryProcesses.refreshAgent(agent);
|
|
90811
|
+
};
|
|
90812
|
+
getCapabilities = (cwd, signal) => this.#queryProcesses.capabilities(cwd, signal);
|
|
90780
90813
|
connectSession = (options) => this.#liveSessions.connectSession(options);
|
|
90781
|
-
cancel = (
|
|
90814
|
+
cancel = async (target, signal) => {
|
|
90815
|
+
await this.#liveSessions.closeSession(target, signal);
|
|
90816
|
+
return "closed";
|
|
90817
|
+
};
|
|
90782
90818
|
closeSession = (...args) => this.#liveSessions.closeSession(...args);
|
|
90783
90819
|
prompt = (...args) => this.#liveSessions.prompt(...args);
|
|
90784
90820
|
steer = (...args) => this.#liveSessions.steer(...args);
|
|
90785
90821
|
renameSession = (...args) => this.#liveSessions.renameSession(...args);
|
|
90786
90822
|
configureSession = (...args) => this.#liveSessions.configureSession(...args);
|
|
90787
|
-
listSessions =
|
|
90788
|
-
findSession = (
|
|
90823
|
+
listSessions = (cwd, cursor, signal) => this.#queryProcesses.listNativeSessions(cwd, cursor, signal);
|
|
90824
|
+
findSession = (cwd, nativeSessionId, budget, signal) => findNativeSession(this.listSessions, cwd, nativeSessionId, budget, signal);
|
|
90789
90825
|
close = async () => {
|
|
90790
90826
|
await runCleanup(
|
|
90791
90827
|
() => this.#queryProcesses.close(),
|
|
@@ -90793,9 +90829,9 @@ var init_adapter2 = __esm({
|
|
|
90793
90829
|
() => this.#previewCache?.close()
|
|
90794
90830
|
);
|
|
90795
90831
|
};
|
|
90796
|
-
readSessionHistory = async (
|
|
90797
|
-
const
|
|
90798
|
-
const signal = AbortSignal.any([
|
|
90832
|
+
readSessionHistory = async (cwd, _additionalDirectories, request, cancellation) => {
|
|
90833
|
+
const agent = this.#agent;
|
|
90834
|
+
const signal = AbortSignal.any([cancellation, AbortSignal.timeout(6e4)]);
|
|
90799
90835
|
const { sessionId } = request;
|
|
90800
90836
|
signal.throwIfAborted();
|
|
90801
90837
|
nativeSessionIdSchema.parse(request.nativeSessionId);
|
|
@@ -90848,10 +90884,12 @@ var init_adapter2 = __esm({
|
|
|
90848
90884
|
request.nativeSessionId,
|
|
90849
90885
|
async (update) => {
|
|
90850
90886
|
const externalized = await this.#contentExternalizer.update(sessionId, update, signal);
|
|
90851
|
-
events
|
|
90852
|
-
|
|
90853
|
-
|
|
90854
|
-
|
|
90887
|
+
for (const event of externalized.events) {
|
|
90888
|
+
events.push({
|
|
90889
|
+
type: "acp",
|
|
90890
|
+
payload: decodeAcpSessionUpdate(JSON.stringify(fitCodexToolEvent(event)))
|
|
90891
|
+
});
|
|
90892
|
+
}
|
|
90855
90893
|
},
|
|
90856
90894
|
signal
|
|
90857
90895
|
);
|
|
@@ -90880,12 +90918,13 @@ var init_adapter3 = __esm({
|
|
|
90880
90918
|
#queryProcesses;
|
|
90881
90919
|
#connector;
|
|
90882
90920
|
#liveSessions;
|
|
90883
|
-
constructor(dependencies) {
|
|
90921
|
+
constructor(agent, dependencies) {
|
|
90884
90922
|
this.#connector = new AcpSessionConnector(dependencies.contentExternalizer);
|
|
90885
90923
|
this.#liveSessions = new AcpLiveSessions(dependencies.contentExternalizer);
|
|
90886
|
-
this.#queryProcesses = new AgentQueryProcesses(dependencies.processes, this.#connector);
|
|
90924
|
+
this.#queryProcesses = new AgentQueryProcesses(agent, dependencies.processes, this.#connector);
|
|
90887
90925
|
}
|
|
90888
|
-
|
|
90926
|
+
refreshAgent = (agent) => this.#queryProcesses.refreshAgent(agent);
|
|
90927
|
+
getCapabilities = (cwd, signal) => this.#queryProcesses.capabilities(cwd, signal);
|
|
90889
90928
|
connectSession = (options) => this.#liveSessions.connectSession(options);
|
|
90890
90929
|
cancel = (...args) => this.#liveSessions.cancel(...args);
|
|
90891
90930
|
closeSession = (...args) => this.#liveSessions.closeSession(...args);
|
|
@@ -90893,9 +90932,9 @@ var init_adapter3 = __esm({
|
|
|
90893
90932
|
steer = (...args) => this.#liveSessions.steer(...args);
|
|
90894
90933
|
renameSession = (...args) => this.#liveSessions.renameSession(...args);
|
|
90895
90934
|
configureSession = (...args) => this.#liveSessions.configureSession(...args);
|
|
90896
|
-
listSessions =
|
|
90897
|
-
findSession = (
|
|
90898
|
-
readSessionHistory =
|
|
90935
|
+
listSessions = (cwd, cursor, signal) => this.#queryProcesses.listNativeSessions(cwd, cursor, signal);
|
|
90936
|
+
findSession = (cwd, nativeSessionId, budget, signal) => findNativeSession(this.listSessions, cwd, nativeSessionId, budget, signal);
|
|
90937
|
+
readSessionHistory = (cwd, additionalDirectories, request, signal) => this.#queryProcesses.previewSessionEvents(cwd, additionalDirectories, request, signal);
|
|
90899
90938
|
close = async () => await runCleanup(
|
|
90900
90939
|
() => this.#queryProcesses.close(),
|
|
90901
90940
|
() => this.#liveSessions.close()
|
|
@@ -90916,11 +90955,11 @@ var init_registry = __esm({
|
|
|
90916
90955
|
harnessAdapters = (agent, dependencies) => {
|
|
90917
90956
|
switch (agent.id) {
|
|
90918
90957
|
case "codex":
|
|
90919
|
-
return new CodexAdapter(dependencies);
|
|
90958
|
+
return new CodexAdapter(agent, dependencies);
|
|
90920
90959
|
case "claude":
|
|
90921
|
-
return new ClaudeAdapter(dependencies);
|
|
90960
|
+
return new ClaudeAdapter(agent, dependencies);
|
|
90922
90961
|
case "pi":
|
|
90923
|
-
return new PiAdapter(dependencies);
|
|
90962
|
+
return new PiAdapter(agent, dependencies);
|
|
90924
90963
|
default:
|
|
90925
90964
|
throw new AcpExecutionError(
|
|
90926
90965
|
`Agent "${agent.id}" has no registered harness adapter.`,
|
|
@@ -91001,8 +91040,18 @@ var init_content_externalizer = __esm({
|
|
|
91001
91040
|
]);
|
|
91002
91041
|
AcpContentExternalizer = class {
|
|
91003
91042
|
#store;
|
|
91004
|
-
|
|
91043
|
+
#linkedResources;
|
|
91044
|
+
constructor(store, linkedResources = () => []) {
|
|
91005
91045
|
this.#store = store;
|
|
91046
|
+
this.#linkedResources = linkedResources;
|
|
91047
|
+
}
|
|
91048
|
+
#resourceLinks(text2) {
|
|
91049
|
+
return this.#linkedResources(text2).map((resource) => ({
|
|
91050
|
+
type: "resource_link",
|
|
91051
|
+
uri: resource.uri,
|
|
91052
|
+
name: resource.name,
|
|
91053
|
+
mimeType: resource.mediaType
|
|
91054
|
+
}));
|
|
91006
91055
|
}
|
|
91007
91056
|
async #content(sessionId, content, signal) {
|
|
91008
91057
|
switch (content.type) {
|
|
@@ -91154,7 +91203,7 @@ var init_content_externalizer = __esm({
|
|
|
91154
91203
|
const hasContent = update.content !== void 0 && update.content !== null || agentContent.length > 0;
|
|
91155
91204
|
return {
|
|
91156
91205
|
agent: { ...update, ...meta3, ...output2, ...hasContent ? { content: agentContent } : {} },
|
|
91157
|
-
|
|
91206
|
+
events: [{ ...update, ...meta3, ...output2, ...hasContent ? { content: eventContent } : {} }]
|
|
91158
91207
|
};
|
|
91159
91208
|
}
|
|
91160
91209
|
update = async (sessionId, update, signal) => {
|
|
@@ -91166,7 +91215,12 @@ var init_content_externalizer = __esm({
|
|
|
91166
91215
|
const content = await this.#content(sessionId, update.content, signal);
|
|
91167
91216
|
return {
|
|
91168
91217
|
agent: { ...update, content: content.agent },
|
|
91169
|
-
|
|
91218
|
+
events: [
|
|
91219
|
+
{ ...update, content: content.event },
|
|
91220
|
+
// Keep native text intact. Only add cards for exact file URLs whose
|
|
91221
|
+
// original upload metadata is still known; arbitrary context stays text.
|
|
91222
|
+
...update.sessionUpdate === "user_message_chunk" && update.content.type === "text" ? this.#resourceLinks(update.content.text).map((content2) => ({ ...update, content: content2 })) : []
|
|
91223
|
+
]
|
|
91170
91224
|
};
|
|
91171
91225
|
}
|
|
91172
91226
|
case "tool_call":
|
|
@@ -91174,14 +91228,14 @@ var init_content_externalizer = __esm({
|
|
|
91174
91228
|
return await this.#toolUpdate(sessionId, update, signal);
|
|
91175
91229
|
case "compaction_update": {
|
|
91176
91230
|
if (update.summary === void 0 || update.summary === null) {
|
|
91177
|
-
return { agent: update,
|
|
91231
|
+
return { agent: update, events: [update] };
|
|
91178
91232
|
}
|
|
91179
91233
|
const content = await Promise.all(
|
|
91180
91234
|
update.summary.map(async (item) => await this.#content(sessionId, item, signal))
|
|
91181
91235
|
);
|
|
91182
91236
|
return {
|
|
91183
91237
|
agent: { ...update, summary: content.map((item) => item.agent) },
|
|
91184
|
-
|
|
91238
|
+
events: [{ ...update, summary: content.map((item) => item.event) }]
|
|
91185
91239
|
};
|
|
91186
91240
|
}
|
|
91187
91241
|
case "plan":
|
|
@@ -91192,7 +91246,7 @@ var init_content_externalizer = __esm({
|
|
|
91192
91246
|
case "config_option_update":
|
|
91193
91247
|
case "session_info_update":
|
|
91194
91248
|
case "usage_update":
|
|
91195
|
-
return { agent: update,
|
|
91249
|
+
return { agent: update, events: [update] };
|
|
91196
91250
|
}
|
|
91197
91251
|
};
|
|
91198
91252
|
};
|
|
@@ -91200,10 +91254,10 @@ var init_content_externalizer = __esm({
|
|
|
91200
91254
|
});
|
|
91201
91255
|
|
|
91202
91256
|
// src/engine/agent/runtime-agents.ts
|
|
91203
|
-
function createRuntimeAdapterRegistry(adapters, processes, externalize) {
|
|
91257
|
+
function createRuntimeAdapterRegistry(adapters, processes, externalize, linkedResources) {
|
|
91204
91258
|
return new AdapterRegistry(adapters, {
|
|
91205
91259
|
processes,
|
|
91206
|
-
contentExternalizer: new AcpContentExternalizer(externalize)
|
|
91260
|
+
contentExternalizer: new AcpContentExternalizer(externalize, linkedResources)
|
|
91207
91261
|
});
|
|
91208
91262
|
}
|
|
91209
91263
|
var RuntimeAgentDependencies;
|
|
@@ -94279,8 +94333,9 @@ var init_agent_session = __esm({
|
|
|
94279
94333
|
await this.#interactions.cancelPendingInteractions();
|
|
94280
94334
|
signal.throwIfAborted();
|
|
94281
94335
|
if (this.#turn.running) {
|
|
94282
|
-
await this.#adapter.cancel(this.#target(), signal);
|
|
94336
|
+
return await this.#adapter.cancel(this.#target(), signal);
|
|
94283
94337
|
}
|
|
94338
|
+
return "retained";
|
|
94284
94339
|
};
|
|
94285
94340
|
respondPermission = async (options) => {
|
|
94286
94341
|
await this.#interactions.respondPermission(options);
|
|
@@ -94950,7 +95005,18 @@ var init_session_manager = __esm({
|
|
|
94950
95005
|
await this.#executions.cancel(sessionId, async () => {
|
|
94951
95006
|
const runtime = this.#executionProcesses.get(sessionId);
|
|
94952
95007
|
if (runtime !== void 0) {
|
|
94953
|
-
await runtime.cancel(signal2);
|
|
95008
|
+
const outcome = await runtime.cancel(signal2);
|
|
95009
|
+
switch (outcome) {
|
|
95010
|
+
case "retained":
|
|
95011
|
+
break;
|
|
95012
|
+
case "closed":
|
|
95013
|
+
await this.#stopSessionProcess(sessionId, runtime);
|
|
95014
|
+
break;
|
|
95015
|
+
default: {
|
|
95016
|
+
const unreachable3 = outcome;
|
|
95017
|
+
throw new AcpExecutionError("Unexpected cancellation outcome", { cause: unreachable3 });
|
|
95018
|
+
}
|
|
95019
|
+
}
|
|
94954
95020
|
}
|
|
94955
95021
|
});
|
|
94956
95022
|
});
|
|
@@ -95333,7 +95399,7 @@ var init_local_authorization_error = __esm({
|
|
|
95333
95399
|
});
|
|
95334
95400
|
|
|
95335
95401
|
// src/engine/session/native/native-session-browser.ts
|
|
95336
|
-
import { randomUUID as
|
|
95402
|
+
import { randomUUID as randomUUID15 } from "node:crypto";
|
|
95337
95403
|
function nextForkTitle(sourceTitle, sessions) {
|
|
95338
95404
|
let highest = 0;
|
|
95339
95405
|
for (const session of sessions) {
|
|
@@ -95391,12 +95457,17 @@ var init_native_session_browser = __esm({
|
|
|
95391
95457
|
(scoped) => this.#sessions.withNativeSessionOperation(
|
|
95392
95458
|
scoped,
|
|
95393
95459
|
nativeSessionId,
|
|
95394
|
-
(target) => target.adapter.readSessionHistory(
|
|
95395
|
-
|
|
95396
|
-
|
|
95397
|
-
|
|
95398
|
-
|
|
95399
|
-
|
|
95460
|
+
(target) => target.adapter.readSessionHistory(
|
|
95461
|
+
target.cwd,
|
|
95462
|
+
target.additionalDirectories,
|
|
95463
|
+
{
|
|
95464
|
+
nativeSessionId,
|
|
95465
|
+
eventLimit,
|
|
95466
|
+
cursor,
|
|
95467
|
+
sessionId: target.sessionId
|
|
95468
|
+
},
|
|
95469
|
+
target.signal
|
|
95470
|
+
)
|
|
95400
95471
|
)
|
|
95401
95472
|
);
|
|
95402
95473
|
#execute = async (command, signal) => {
|
|
@@ -95427,7 +95498,7 @@ var init_native_session_browser = __esm({
|
|
|
95427
95498
|
queuedCancellation: "before-start"
|
|
95428
95499
|
};
|
|
95429
95500
|
}
|
|
95430
|
-
const capabilities = await options.adapter.getCapabilities(
|
|
95501
|
+
const capabilities = await options.adapter.getCapabilities(cwd, signal);
|
|
95431
95502
|
if (!capabilities.listSessions) {
|
|
95432
95503
|
throw new AcpExecutionError(
|
|
95433
95504
|
"This Agent does not support native session listing",
|
|
@@ -95442,7 +95513,7 @@ var init_native_session_browser = __esm({
|
|
|
95442
95513
|
if (authorized === null) {
|
|
95443
95514
|
return null;
|
|
95444
95515
|
}
|
|
95445
|
-
const entryId = decodeIdentifier(
|
|
95516
|
+
const entryId = decodeIdentifier(randomUUID15());
|
|
95446
95517
|
if (this.#entries.size >= 5e3) {
|
|
95447
95518
|
this.#entries.clear();
|
|
95448
95519
|
}
|
|
@@ -95481,7 +95552,7 @@ var init_native_session_browser = __esm({
|
|
|
95481
95552
|
}
|
|
95482
95553
|
cursor = known.cursor;
|
|
95483
95554
|
}
|
|
95484
|
-
const page = await options.adapter.listSessions(
|
|
95555
|
+
const page = await options.adapter.listSessions(cwd, cursor, signal);
|
|
95485
95556
|
const entries = [];
|
|
95486
95557
|
for (const info of page.sessions) {
|
|
95487
95558
|
const entry = await register(info);
|
|
@@ -95498,7 +95569,7 @@ var init_native_session_browser = __esm({
|
|
|
95498
95569
|
"invalid_native_session_response"
|
|
95499
95570
|
);
|
|
95500
95571
|
}
|
|
95501
|
-
nextCursor = decodeIdentifier(
|
|
95572
|
+
nextCursor = decodeIdentifier(randomUUID15());
|
|
95502
95573
|
if (this.#cursors.size >= 500) {
|
|
95503
95574
|
this.#cursors.clear();
|
|
95504
95575
|
}
|
|
@@ -95516,10 +95587,15 @@ var init_native_session_browser = __esm({
|
|
|
95516
95587
|
};
|
|
95517
95588
|
}
|
|
95518
95589
|
if (command.action === "find") {
|
|
95519
|
-
const found = await options.adapter.findSession(
|
|
95520
|
-
|
|
95521
|
-
|
|
95522
|
-
|
|
95590
|
+
const found = await options.adapter.findSession(
|
|
95591
|
+
cwd,
|
|
95592
|
+
command.nativeSessionId,
|
|
95593
|
+
{
|
|
95594
|
+
maximumPages: 500,
|
|
95595
|
+
maximumEntries: 500
|
|
95596
|
+
},
|
|
95597
|
+
signal
|
|
95598
|
+
);
|
|
95523
95599
|
const entry = await register(found);
|
|
95524
95600
|
if (entry !== null) {
|
|
95525
95601
|
return { ...envelope2, action: "find", entry };
|
|
@@ -95657,10 +95733,15 @@ var init_native_session_browser = __esm({
|
|
|
95657
95733
|
}
|
|
95658
95734
|
};
|
|
95659
95735
|
resolveTarget = async (command, options, selected) => {
|
|
95660
|
-
const info = await options.adapter.findSession(
|
|
95661
|
-
|
|
95662
|
-
|
|
95663
|
-
|
|
95736
|
+
const info = await options.adapter.findSession(
|
|
95737
|
+
options.cwd,
|
|
95738
|
+
selected.nativeSessionId,
|
|
95739
|
+
{
|
|
95740
|
+
maximumPages: 100,
|
|
95741
|
+
maximumEntries: null
|
|
95742
|
+
},
|
|
95743
|
+
options.signal
|
|
95744
|
+
).catch((cause) => {
|
|
95664
95745
|
options.signal.throwIfAborted();
|
|
95665
95746
|
if (cause instanceof AcpExecutionError && cause.code === "native_session_not_found") {
|
|
95666
95747
|
throw new AcpExecutionError(
|
|
@@ -95905,7 +95986,12 @@ var init_prompt_lifecycle = __esm({
|
|
|
95905
95986
|
}
|
|
95906
95987
|
const recorded = await this.#recordLifecycle(sessionId, {
|
|
95907
95988
|
type: "lifecycle-metadata",
|
|
95908
|
-
payload: {
|
|
95989
|
+
payload: {
|
|
95990
|
+
kind: "prompt.completed",
|
|
95991
|
+
commandId,
|
|
95992
|
+
stopReason,
|
|
95993
|
+
...request.phase === "queued" ? { execution: "not-started" } : {}
|
|
95994
|
+
}
|
|
95909
95995
|
});
|
|
95910
95996
|
if (!recorded) {
|
|
95911
95997
|
this.#sink.publishOperationFailure(
|
|
@@ -95942,7 +96028,7 @@ var init_prompt_lifecycle = __esm({
|
|
|
95942
96028
|
});
|
|
95943
96029
|
|
|
95944
96030
|
// src/engine/session/turn/execution-receipts.ts
|
|
95945
|
-
import { createHash as createHash7, randomUUID as
|
|
96031
|
+
import { createHash as createHash7, randomUUID as randomUUID16 } from "node:crypto";
|
|
95946
96032
|
var MAX_TERMINAL_RECEIPTS, ExecutionReceipts;
|
|
95947
96033
|
var init_execution_receipts = __esm({
|
|
95948
96034
|
"src/engine/session/turn/execution-receipts.ts"() {
|
|
@@ -96061,7 +96147,7 @@ var init_execution_receipts = __esm({
|
|
|
96061
96147
|
/** Started identities remain authoritative after their detailed receipt is evicted. */
|
|
96062
96148
|
hasStarted = (commandId, sessionId) => {
|
|
96063
96149
|
const receipt = this.#executions.get(commandId);
|
|
96064
|
-
return receipt ===
|
|
96150
|
+
return receipt?.sessionId === sessionId && receipt.started || this.#table.identity(commandId)?.sessionId === sessionId;
|
|
96065
96151
|
};
|
|
96066
96152
|
/** Reserves an unseen command for cancellation before a delayed prompt can claim its identity. */
|
|
96067
96153
|
recordCancellationBeforeAdmission = (commandId, sessionId) => {
|
|
@@ -96069,9 +96155,16 @@ var init_execution_receipts = __esm({
|
|
|
96069
96155
|
if (existing !== void 0) {
|
|
96070
96156
|
return existing.sessionId === sessionId ? this.outcome(commandId) : void 0;
|
|
96071
96157
|
}
|
|
96158
|
+
const identity2 = this.#table.identity(commandId);
|
|
96159
|
+
if (identity2 !== void 0) {
|
|
96160
|
+
return identity2.sessionId === sessionId ? {
|
|
96161
|
+
type: "lifecycle-metadata",
|
|
96162
|
+
payload: { kind: "prompt.completed", commandId, stopReason: "cancelled" }
|
|
96163
|
+
} : void 0;
|
|
96164
|
+
}
|
|
96072
96165
|
const outcome = {
|
|
96073
96166
|
type: "lifecycle-metadata",
|
|
96074
|
-
payload: { kind: "prompt.completed", commandId, stopReason: "cancelled" }
|
|
96167
|
+
payload: { kind: "prompt.completed", commandId, stopReason: "cancelled", execution: "not-started" }
|
|
96075
96168
|
};
|
|
96076
96169
|
const commandHash = createHash7("sha256").update(
|
|
96077
96170
|
encodeSessionCancelBeforeStartCommand({
|
|
@@ -96082,7 +96175,7 @@ var init_execution_receipts = __esm({
|
|
|
96082
96175
|
).digest("hex");
|
|
96083
96176
|
this.#save(commandId, {
|
|
96084
96177
|
admissionOrder: this.#nextAdmissionOrder(),
|
|
96085
|
-
attemptId:
|
|
96178
|
+
attemptId: randomUUID16(),
|
|
96086
96179
|
commandHash,
|
|
96087
96180
|
sessionId,
|
|
96088
96181
|
started: false,
|
|
@@ -96164,7 +96257,7 @@ var init_execution_receipts = __esm({
|
|
|
96164
96257
|
if (identity2 !== void 0) {
|
|
96165
96258
|
return identity2.sessionId === sessionId && identity2.commandHash === commandHash ? { kind: "expired" } : { kind: "conflict" };
|
|
96166
96259
|
}
|
|
96167
|
-
const attemptId =
|
|
96260
|
+
const attemptId = randomUUID16();
|
|
96168
96261
|
this.#save(commandId, {
|
|
96169
96262
|
admissionOrder: this.#nextAdmissionOrder(),
|
|
96170
96263
|
attemptId,
|
|
@@ -96299,7 +96392,7 @@ var init_runtime_turn_activity = __esm({
|
|
|
96299
96392
|
});
|
|
96300
96393
|
|
|
96301
96394
|
// src/engine/session/turn/active-turn.ts
|
|
96302
|
-
import { randomUUID as
|
|
96395
|
+
import { randomUUID as randomUUID17 } from "node:crypto";
|
|
96303
96396
|
var ActiveRuntimeTurn;
|
|
96304
96397
|
var init_active_turn = __esm({
|
|
96305
96398
|
"src/engine/session/turn/active-turn.ts"() {
|
|
@@ -96314,7 +96407,7 @@ var init_active_turn = __esm({
|
|
|
96314
96407
|
#dispatch;
|
|
96315
96408
|
#sequence = 0;
|
|
96316
96409
|
#interaction = null;
|
|
96317
|
-
#epoch = decodeIdentifier(
|
|
96410
|
+
#epoch = decodeIdentifier(randomUUID17());
|
|
96318
96411
|
constructor(command, attemptId) {
|
|
96319
96412
|
this.attemptId = attemptId;
|
|
96320
96413
|
this.command = command;
|
|
@@ -96923,11 +97016,11 @@ var init_session_layer = __esm({
|
|
|
96923
97016
|
});
|
|
96924
97017
|
|
|
96925
97018
|
// src/engine/storage/files/scratch-directory.ts
|
|
96926
|
-
import { randomUUID as
|
|
97019
|
+
import { randomUUID as randomUUID18 } from "node:crypto";
|
|
96927
97020
|
import { lstat as lstat4, mkdir as mkdir5, readdir as readdir6, readFile as readFile7, realpath as realpath8, rename as rename4, rm as rm3, stat as stat8, utimes, writeFile as writeFile2 } from "node:fs/promises";
|
|
96928
97021
|
import { dirname as dirname12, join as join30 } from "node:path";
|
|
96929
97022
|
async function atomicWrite(path8, bytes, signal) {
|
|
96930
|
-
const temporary = `${path8}.${
|
|
97023
|
+
const temporary = `${path8}.${randomUUID18()}.tmp`;
|
|
96931
97024
|
try {
|
|
96932
97025
|
await writeFile2(temporary, bytes, { mode: 384, signal });
|
|
96933
97026
|
signal.throwIfAborted();
|
|
@@ -96943,7 +97036,7 @@ var init_scratch_directory = __esm({
|
|
|
96943
97036
|
ScratchDirectory = class {
|
|
96944
97037
|
#root;
|
|
96945
97038
|
constructor(parent) {
|
|
96946
|
-
this.#root = join30(parent,
|
|
97039
|
+
this.#root = join30(parent, randomUUID18());
|
|
96947
97040
|
}
|
|
96948
97041
|
/** Refreshes this directory's lease and removes sibling directories whose lease is older than `leaseMilliseconds`. */
|
|
96949
97042
|
refreshLease = async (leaseMilliseconds) => {
|
|
@@ -97008,6 +97101,7 @@ var init_scratch_directory = __esm({
|
|
|
97008
97101
|
// src/engine/session/content/external-content-store.ts
|
|
97009
97102
|
import { createHash as createHash8 } from "node:crypto";
|
|
97010
97103
|
import { extname as extname2, join as join31 } from "node:path";
|
|
97104
|
+
import { pathToFileURL as pathToFileURL3 } from "node:url";
|
|
97011
97105
|
function contentFileName(key, name2) {
|
|
97012
97106
|
const extension = extname2(name2).toLowerCase();
|
|
97013
97107
|
return /^\.[a-z0-9]{1,16}$/u.test(extension) ? `${key}${extension}` : key;
|
|
@@ -97017,6 +97111,7 @@ var init_external_content_store = __esm({
|
|
|
97017
97111
|
"src/engine/session/content/external-content-store.ts"() {
|
|
97018
97112
|
"use strict";
|
|
97019
97113
|
init_zod();
|
|
97114
|
+
init_operation_error();
|
|
97020
97115
|
init_scratch_directory();
|
|
97021
97116
|
contentRequest = /^mobius-content:(image|audio|resource):([a-f0-9]{64})$/u;
|
|
97022
97117
|
CONTENT_LIFETIME_MILLISECONDS = 24 * 60 * 60 * 1e3;
|
|
@@ -97080,8 +97175,12 @@ var init_external_content_store = __esm({
|
|
|
97080
97175
|
}
|
|
97081
97176
|
await this.#expire();
|
|
97082
97177
|
active.throwIfAborted();
|
|
97083
|
-
const
|
|
97178
|
+
const writtenPath = await this.#scratch.write(kind, contentFileName(key, metadata.name), bytes, active);
|
|
97179
|
+
const path8 = await this.#scratch.resolveFile(writtenPath);
|
|
97084
97180
|
active.throwIfAborted();
|
|
97181
|
+
if (path8 === null) {
|
|
97182
|
+
throw new OperationError("content_unavailable", "The cached content file is unavailable");
|
|
97183
|
+
}
|
|
97085
97184
|
const retained = this.#entries.get(request);
|
|
97086
97185
|
this.#entries.set(request, {
|
|
97087
97186
|
byteLength: bytes.byteLength,
|
|
@@ -97122,6 +97221,30 @@ var init_external_content_store = __esm({
|
|
|
97122
97221
|
const bytes = await this.#scratch.read(resolved.path, active);
|
|
97123
97222
|
return bytes === null ? null : { ...resolved, bytes };
|
|
97124
97223
|
});
|
|
97224
|
+
/** Metadata for exact, still-cached file URLs. This does not grant content access. */
|
|
97225
|
+
linkedResources = (text2) => {
|
|
97226
|
+
if (!text2.includes("file:///")) {
|
|
97227
|
+
return [];
|
|
97228
|
+
}
|
|
97229
|
+
const resources = [];
|
|
97230
|
+
for (const [request, entry] of this.#entries) {
|
|
97231
|
+
if (!request.startsWith("mobius-content:resource:") || entry.expiresAt <= Date.now()) {
|
|
97232
|
+
continue;
|
|
97233
|
+
}
|
|
97234
|
+
const uri = pathToFileURL3(entry.path).href;
|
|
97235
|
+
for (let index2 = text2.indexOf(uri); index2 >= 0; index2 = text2.indexOf(uri, index2 + uri.length)) {
|
|
97236
|
+
const following = text2[index2 + uri.length];
|
|
97237
|
+
if (following === void 0 || /[\s<>"')\]]/u.test(following)) {
|
|
97238
|
+
resources.push({
|
|
97239
|
+
index: index2,
|
|
97240
|
+
resource: { uri, mediaType: entry.mediaType, name: entry.name, path: entry.path }
|
|
97241
|
+
});
|
|
97242
|
+
break;
|
|
97243
|
+
}
|
|
97244
|
+
}
|
|
97245
|
+
}
|
|
97246
|
+
return resources.sort((left, right) => left.index - right.index).map(({ resource }) => resource);
|
|
97247
|
+
};
|
|
97125
97248
|
[Symbol.asyncDispose] = async () => {
|
|
97126
97249
|
clearInterval(this.#expirationTimer);
|
|
97127
97250
|
this.#lifetime.abort();
|
|
@@ -99105,7 +99228,7 @@ var init_native_sessions = __esm({
|
|
|
99105
99228
|
});
|
|
99106
99229
|
|
|
99107
99230
|
// src/engine/session/prompt/apply-session-configuration.ts
|
|
99108
|
-
import { randomUUID as
|
|
99231
|
+
import { randomUUID as randomUUID19 } from "node:crypto";
|
|
99109
99232
|
function invalidSessionConfiguration(message) {
|
|
99110
99233
|
return new AcpExecutionError(message, {}, "invalid_session_configuration");
|
|
99111
99234
|
}
|
|
@@ -99243,7 +99366,7 @@ async function applySessionConfigurationSelection(sessions, options, selection,
|
|
|
99243
99366
|
booleanValue: selection.booleanValue,
|
|
99244
99367
|
configId: selection.configId,
|
|
99245
99368
|
cwd,
|
|
99246
|
-
requestId: `cfg_${
|
|
99369
|
+
requestId: `cfg_${randomUUID19()}`,
|
|
99247
99370
|
sessionId,
|
|
99248
99371
|
signal,
|
|
99249
99372
|
value: selection.value,
|
|
@@ -100820,13 +100943,14 @@ async function runRuntime(config2, parentSignal, timer = systemTimer, options =
|
|
|
100820
100943
|
const adapters = createRuntimeAdapterRegistry(
|
|
100821
100944
|
config2.adapters,
|
|
100822
100945
|
processes,
|
|
100823
|
-
(sessionId, content, contentSignal) => externalContent.put({ ...content, sessionId, signal: contentSignal })
|
|
100946
|
+
(sessionId, content, contentSignal) => externalContent.put({ ...content, sessionId, signal: contentSignal }),
|
|
100947
|
+
externalContent.linkedResources
|
|
100824
100948
|
);
|
|
100825
100949
|
const resolveAgent = async (agentId, resolveSignal, sessionId) => {
|
|
100826
100950
|
const catalogAgent = await resolveCatalogAgent(config2, agentId, resolveSignal);
|
|
100827
100951
|
const environment = sessionId === void 0 ? void 0 : config2.sessionEnvironment?.({ sessionId, agentId });
|
|
100828
100952
|
const agent = environment === void 0 ? catalogAgent : catalogAgent.withEnvironment({ ...catalogAgent.environment, ...environment });
|
|
100829
|
-
return { agent, adapter: adapters.resolve(
|
|
100953
|
+
return { agent, adapter: adapters.resolve(catalogAgent) };
|
|
100830
100954
|
};
|
|
100831
100955
|
const layer = buildSessionLayer({
|
|
100832
100956
|
processes,
|
|
@@ -101211,7 +101335,7 @@ var init_engine = __esm({
|
|
|
101211
101335
|
});
|
|
101212
101336
|
|
|
101213
101337
|
// src/storage/daemon/version-data.ts
|
|
101214
|
-
import { randomUUID as
|
|
101338
|
+
import { randomUUID as randomUUID20 } from "node:crypto";
|
|
101215
101339
|
import { cp as cp2, lstat as lstat5, mkdtemp, readFile as readFile8, rename as rename5, rm as rm4, writeFile as writeFile3 } from "node:fs/promises";
|
|
101216
101340
|
import { join as join33, relative as relative3, sep as sep5 } from "node:path";
|
|
101217
101341
|
async function prepareVersionDataDirectory(root, version2, signal) {
|
|
@@ -101302,7 +101426,7 @@ async function discardVersionData(root, version2, signal) {
|
|
|
101302
101426
|
return;
|
|
101303
101427
|
}
|
|
101304
101428
|
const versions = join33(root, STATE_ROOT_LAYOUT.versions);
|
|
101305
|
-
const discarded = join33(versions, `.${version2}-discarded-${
|
|
101429
|
+
const discarded = join33(versions, `.${version2}-discarded-${randomUUID20()}`);
|
|
101306
101430
|
try {
|
|
101307
101431
|
await rename5(join33(versions, version2), discarded);
|
|
101308
101432
|
} catch (cause) {
|
|
@@ -101316,7 +101440,7 @@ async function discardVersionData(root, version2, signal) {
|
|
|
101316
101440
|
async function writeCurrentDataVersion(root, version2, signal) {
|
|
101317
101441
|
await validateLocalPath(root, true, true, signal);
|
|
101318
101442
|
await validateLocalPath(join33(root, STATE_ROOT_LAYOUT.versions, version2), true, true, signal);
|
|
101319
|
-
const temporary = join33(root, `.current-data-${
|
|
101443
|
+
const temporary = join33(root, `.current-data-${randomUUID20()}.txt`);
|
|
101320
101444
|
try {
|
|
101321
101445
|
await writeFile3(temporary, `versions/${version2}
|
|
101322
101446
|
`, { mode: 384, flag: "wx", signal });
|
|
@@ -102920,7 +103044,7 @@ var init_quit = __esm({
|
|
|
102920
103044
|
});
|
|
102921
103045
|
|
|
102922
103046
|
// src/daemon/upgrades/upgrade.ts
|
|
102923
|
-
import { randomUUID as
|
|
103047
|
+
import { randomUUID as randomUUID21 } from "node:crypto";
|
|
102924
103048
|
import { setInterval as setInterval2, setTimeout as setTimeout4 } from "node:timers/promises";
|
|
102925
103049
|
async function reportDaemonUpgradeAvailability(send2, signal) {
|
|
102926
103050
|
if (!process.connected) {
|
|
@@ -102979,7 +103103,7 @@ async function requestDaemonReleaseUpgrade(stateDirectory, currentVersion, signa
|
|
|
102979
103103
|
return await requestInstalledDaemonReleaseSwitch(stateDirectory, launch, signal);
|
|
102980
103104
|
}
|
|
102981
103105
|
async function requestInstalledDaemonReleaseSwitch(stateDirectory, launch, signal) {
|
|
102982
|
-
const id =
|
|
103106
|
+
const id = randomUUID21();
|
|
102983
103107
|
const response = decodeKnownLifecycleResponse(
|
|
102984
103108
|
await sendLocalRequest(stateDirectory, "manager", { kind: "switch", id, context: "npm", launch }, signal)
|
|
102985
103109
|
);
|