@moxt-ai/mobius 0.0.78 → 0.0.80
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/acp/codex/agent.d.ts +2 -1
- package/dist/acp/codex/agent.d.ts.map +1 -1
- package/dist/acp/codex/agent.js +42 -7
- package/dist/acp/codex/agent.js.map +1 -1
- package/dist/acp/codex/app-server-client.d.ts +4 -2
- package/dist/acp/codex/app-server-client.d.ts.map +1 -1
- package/dist/acp/codex/app-server-client.js +50 -31
- package/dist/acp/codex/app-server-client.js.map +1 -1
- package/dist/acp/in-process/acp-endpoint.d.ts +10 -0
- package/dist/acp/in-process/acp-endpoint.d.ts.map +1 -1
- package/dist/acp/in-process/acp-endpoint.js +13 -1
- package/dist/acp/in-process/acp-endpoint.js.map +1 -1
- package/dist/acp/session-history.d.ts.map +1 -1
- package/dist/acp/session-history.js +62 -27
- package/dist/acp/session-history.js.map +1 -1
- package/dist/acp/session-manager.d.ts.map +1 -1
- package/dist/acp/session-manager.js +17 -8
- package/dist/acp/session-manager.js.map +1 -1
- package/dist/agent-catalog/acp-readiness-probe.d.ts.map +1 -1
- package/dist/agent-catalog/acp-readiness-probe.js +24 -9
- package/dist/agent-catalog/acp-readiness-probe.js.map +1 -1
- package/dist/cli.js +375 -88
- package/dist/cli.js.map +4 -4
- package/dist/index.js +374 -87
- package/dist/index.js.map +4 -4
- package/dist/run-daemon.d.ts.map +1 -1
- package/dist/run-daemon.js +131 -1
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +374 -87
- package/dist/runtime.js.map +4 -4
- package/package.json +1 -1
package/dist/runtime.js
CHANGED
|
@@ -1307,6 +1307,20 @@ var AcpConfigurationValueUnavailableError = class extends AcpExecutionError {
|
|
|
1307
1307
|
}
|
|
1308
1308
|
};
|
|
1309
1309
|
|
|
1310
|
+
// src/acp/in-process/acp-endpoint.ts
|
|
1311
|
+
function acpEndpointTerminationError(termination) {
|
|
1312
|
+
switch (termination.kind) {
|
|
1313
|
+
case "failed":
|
|
1314
|
+
return termination.error;
|
|
1315
|
+
case "closed":
|
|
1316
|
+
return new AcpExecutionError("The ACP endpoint is closed", {}, "acp_endpoint_closed");
|
|
1317
|
+
default: {
|
|
1318
|
+
const unreachable = termination;
|
|
1319
|
+
return unreachable;
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1310
1324
|
// src/acp/codex/app-server-client.ts
|
|
1311
1325
|
import { spawn as spawn2 } from "node:child_process";
|
|
1312
1326
|
|
|
@@ -21201,11 +21215,9 @@ var threadSettingsUpdatedSchema = external_exports.object({
|
|
|
21201
21215
|
// src/acp/codex/app-server-client.ts
|
|
21202
21216
|
var INITIALIZE_TIMEOUT_MILLISECONDS = 3e4;
|
|
21203
21217
|
var OUTPUT_LIMIT_BYTES = 32 * 1024 * 1024;
|
|
21204
|
-
var CodexAppServerError = class extends
|
|
21205
|
-
code;
|
|
21218
|
+
var CodexAppServerError = class extends AcpExecutionError {
|
|
21206
21219
|
constructor(code, message, options = {}) {
|
|
21207
|
-
super(message, options);
|
|
21208
|
-
this.code = code;
|
|
21220
|
+
super(message, options, code);
|
|
21209
21221
|
this.name = "CodexAppServerError";
|
|
21210
21222
|
}
|
|
21211
21223
|
};
|
|
@@ -21213,12 +21225,14 @@ var CodexAppServerClient = class {
|
|
|
21213
21225
|
#child;
|
|
21214
21226
|
#handlers;
|
|
21215
21227
|
#pending = /* @__PURE__ */ new Map();
|
|
21216
|
-
#
|
|
21217
|
-
|
|
21228
|
+
#termination = Promise.withResolvers();
|
|
21229
|
+
terminated = this.#termination.promise;
|
|
21230
|
+
#lifecycle = {
|
|
21231
|
+
kind: "open"
|
|
21232
|
+
};
|
|
21218
21233
|
#nextRequestId = 1;
|
|
21219
21234
|
#pendingBuffer = "";
|
|
21220
21235
|
#receivedBytes = 0;
|
|
21221
|
-
#closed = false;
|
|
21222
21236
|
constructor(options) {
|
|
21223
21237
|
this.#handlers = options.handlers;
|
|
21224
21238
|
this.#child = spawn2(options.command, ["app-server"], {
|
|
@@ -21243,21 +21257,56 @@ var CodexAppServerClient = class {
|
|
|
21243
21257
|
stderr.on("data", (chunk) => {
|
|
21244
21258
|
process.stderr.write(`[codex-app-server] ${chunk}`);
|
|
21245
21259
|
});
|
|
21246
|
-
this.#
|
|
21247
|
-
this.#
|
|
21248
|
-
|
|
21260
|
+
this.#child.once("error", (cause) => {
|
|
21261
|
+
this.#fail(
|
|
21262
|
+
new CodexAppServerError("codex_app_server_exited", "The Codex app-server could not run", { cause })
|
|
21263
|
+
);
|
|
21264
|
+
});
|
|
21265
|
+
this.#child.once("exit", (code, signal) => {
|
|
21266
|
+
this.#fail(
|
|
21267
|
+
new CodexAppServerError("codex_app_server_exited", "The Codex app-server stopped", {
|
|
21268
|
+
cause: { code, signal }
|
|
21269
|
+
})
|
|
21270
|
+
);
|
|
21271
|
+
});
|
|
21272
|
+
for (const stream of [stdin, stdout, stderr]) {
|
|
21273
|
+
stream.on("error", (cause) => {
|
|
21274
|
+
this.#fail(
|
|
21275
|
+
new CodexAppServerError("codex_app_server_io_error", "The Codex app-server connection failed", {
|
|
21276
|
+
cause
|
|
21277
|
+
})
|
|
21278
|
+
);
|
|
21279
|
+
});
|
|
21280
|
+
}
|
|
21281
|
+
stdout.once("end", () => {
|
|
21282
|
+
this.#fail(new CodexAppServerError("codex_app_server_exited", "The Codex app-server output closed"));
|
|
21249
21283
|
});
|
|
21250
21284
|
}
|
|
21251
21285
|
child = () => this.#child;
|
|
21252
21286
|
#fail = (error62) => {
|
|
21253
|
-
this.#
|
|
21287
|
+
this.#terminate({ kind: "failed", error: error62 });
|
|
21288
|
+
};
|
|
21289
|
+
#terminate = (result) => {
|
|
21290
|
+
if (this.#lifecycle.kind === "terminated") {
|
|
21291
|
+
return;
|
|
21292
|
+
}
|
|
21293
|
+
this.#lifecycle = { kind: "terminated", result };
|
|
21294
|
+
this.#termination.resolve(result);
|
|
21295
|
+
const error62 = acpEndpointTerminationError(result);
|
|
21254
21296
|
for (const [id, pending] of this.#pending) {
|
|
21255
21297
|
this.#pending.delete(id);
|
|
21256
21298
|
pending.completion.reject(error62);
|
|
21257
21299
|
}
|
|
21258
21300
|
};
|
|
21259
|
-
#
|
|
21301
|
+
#requireOpen = () => {
|
|
21302
|
+
if (this.#lifecycle.kind === "terminated") {
|
|
21303
|
+
throw acpEndpointTerminationError(this.#lifecycle.result);
|
|
21304
|
+
}
|
|
21305
|
+
};
|
|
21260
21306
|
#consume = (chunk) => {
|
|
21307
|
+
if (this.#lifecycle.kind === "terminated") {
|
|
21308
|
+
return;
|
|
21309
|
+
}
|
|
21261
21310
|
try {
|
|
21262
21311
|
this.#receivedBytes += Buffer.byteLength(chunk);
|
|
21263
21312
|
if (this.#receivedBytes > OUTPUT_LIMIT_BYTES) {
|
|
@@ -21286,7 +21335,6 @@ var CodexAppServerClient = class {
|
|
|
21286
21335
|
{ cause: error62 }
|
|
21287
21336
|
)
|
|
21288
21337
|
);
|
|
21289
|
-
this.#child.kill("SIGKILL");
|
|
21290
21338
|
}
|
|
21291
21339
|
};
|
|
21292
21340
|
// Handler failures are recorded as the app-server's terminal failure: an ACP client that cannot
|
|
@@ -21336,9 +21384,7 @@ var CodexAppServerClient = class {
|
|
|
21336
21384
|
/** Sends a request and waits for its response, bounded by the caller's cancellation signal. */
|
|
21337
21385
|
request = async (method, params, signal) => {
|
|
21338
21386
|
signal.throwIfAborted();
|
|
21339
|
-
|
|
21340
|
-
throw new CodexAppServerError("codex_app_server_closed", "The Codex app-server is closed");
|
|
21341
|
-
}
|
|
21387
|
+
this.#requireOpen();
|
|
21342
21388
|
const id = this.#nextRequestId;
|
|
21343
21389
|
this.#nextRequestId += 1;
|
|
21344
21390
|
const completion = Promise.withResolvers();
|
|
@@ -21351,7 +21397,7 @@ var CodexAppServerClient = class {
|
|
|
21351
21397
|
signal.addEventListener("abort", abort, { once: true });
|
|
21352
21398
|
try {
|
|
21353
21399
|
this.#write({ id, method, params });
|
|
21354
|
-
return await
|
|
21400
|
+
return await completion.promise;
|
|
21355
21401
|
} finally {
|
|
21356
21402
|
signal.removeEventListener("abort", abort);
|
|
21357
21403
|
this.#pending.delete(id);
|
|
@@ -21367,12 +21413,12 @@ var CodexAppServerClient = class {
|
|
|
21367
21413
|
this.#write({ error: { code, message }, id });
|
|
21368
21414
|
};
|
|
21369
21415
|
#write = (message) => {
|
|
21370
|
-
|
|
21371
|
-
return;
|
|
21372
|
-
}
|
|
21416
|
+
this.#requireOpen();
|
|
21373
21417
|
const stdin = this.#child.stdin;
|
|
21374
21418
|
if (stdin === null || stdin.destroyed) {
|
|
21375
|
-
|
|
21419
|
+
const error62 = new CodexAppServerError("codex_app_server_io_error", "The Codex app-server input is closed");
|
|
21420
|
+
this.#fail(error62);
|
|
21421
|
+
throw error62;
|
|
21376
21422
|
}
|
|
21377
21423
|
stdin.write(`${JSON.stringify(message)}
|
|
21378
21424
|
`);
|
|
@@ -21395,15 +21441,7 @@ var CodexAppServerClient = class {
|
|
|
21395
21441
|
* app-server and every tool subprocess it started.
|
|
21396
21442
|
*/
|
|
21397
21443
|
detach = () => {
|
|
21398
|
-
|
|
21399
|
-
return;
|
|
21400
|
-
}
|
|
21401
|
-
this.#closed = true;
|
|
21402
|
-
this.#fail(new CodexAppServerError("codex_app_server_closed", "The Codex app-server is closed"));
|
|
21403
|
-
const stdin = this.#child.stdin;
|
|
21404
|
-
if (stdin !== null && !stdin.destroyed) {
|
|
21405
|
-
stdin.end();
|
|
21406
|
-
}
|
|
21444
|
+
this.#terminate({ kind: "closed" });
|
|
21407
21445
|
};
|
|
21408
21446
|
};
|
|
21409
21447
|
|
|
@@ -21745,6 +21783,8 @@ function userInputSchema(questions) {
|
|
|
21745
21783
|
var CodexAcpAgent = class {
|
|
21746
21784
|
#app;
|
|
21747
21785
|
#appServer;
|
|
21786
|
+
terminated;
|
|
21787
|
+
#closePromise = null;
|
|
21748
21788
|
#connection = null;
|
|
21749
21789
|
#models = [];
|
|
21750
21790
|
#nativeSessionId = "";
|
|
@@ -21782,6 +21822,15 @@ var CodexAcpAgent = class {
|
|
|
21782
21822
|
}
|
|
21783
21823
|
}
|
|
21784
21824
|
});
|
|
21825
|
+
this.terminated = this.#appServer.terminated;
|
|
21826
|
+
void this.terminated.then((termination) => {
|
|
21827
|
+
this.#turn?.completion.reject(acpEndpointTerminationError(termination));
|
|
21828
|
+
if (termination.kind === "failed") {
|
|
21829
|
+
void this.close().catch((cause) => {
|
|
21830
|
+
console.error("The failed Codex endpoint could not release its process tree", cause);
|
|
21831
|
+
});
|
|
21832
|
+
}
|
|
21833
|
+
});
|
|
21785
21834
|
this.#app = createAgentApp({ name: "mobius-codex" }).onConnect((connection) => {
|
|
21786
21835
|
this.#connection = connection;
|
|
21787
21836
|
}).onRequest(methods.agent.initialize, async () => ({
|
|
@@ -21893,11 +21942,20 @@ var CodexAcpAgent = class {
|
|
|
21893
21942
|
* Releases the app-server and every process it started. Mirrors the adapter path's teardown so a
|
|
21894
21943
|
* cancelled or closed session cannot leak the tool subprocesses running under the app-server.
|
|
21895
21944
|
*/
|
|
21896
|
-
close =
|
|
21897
|
-
|
|
21898
|
-
|
|
21899
|
-
|
|
21900
|
-
|
|
21945
|
+
close = () => {
|
|
21946
|
+
if (this.#closePromise === null) {
|
|
21947
|
+
this.#appServer.detach();
|
|
21948
|
+
this.#closePromise = (async () => {
|
|
21949
|
+
const child = this.#appServer.child();
|
|
21950
|
+
try {
|
|
21951
|
+
const captured = await captureProcessTree(child);
|
|
21952
|
+
await stopProcessTree(child, captured);
|
|
21953
|
+
} finally {
|
|
21954
|
+
this.#connection?.close();
|
|
21955
|
+
}
|
|
21956
|
+
})();
|
|
21957
|
+
}
|
|
21958
|
+
return this.#closePromise;
|
|
21901
21959
|
};
|
|
21902
21960
|
/**
|
|
21903
21961
|
* Reads the model catalog once per app-server. A failure leaves the catalog empty, which costs
|
|
@@ -22141,7 +22199,7 @@ var CodexAcpAgent = class {
|
|
|
22141
22199
|
if (method === "turn/started") {
|
|
22142
22200
|
const decoded = turnNotificationSchema.safeParse(params);
|
|
22143
22201
|
if (decoded.success && decoded.data.threadId === this.#nativeSessionId && this.#turn !== null) {
|
|
22144
|
-
this.#turn
|
|
22202
|
+
this.#turn.turn.id = decoded.data.turn.id;
|
|
22145
22203
|
}
|
|
22146
22204
|
return;
|
|
22147
22205
|
}
|
|
@@ -22330,10 +22388,20 @@ var CodexAcpAgent = class {
|
|
|
22330
22388
|
this.#appServer.respond(request.id, { action: response.action, content: content3 });
|
|
22331
22389
|
};
|
|
22332
22390
|
#runTurn = async (input2, signal) => {
|
|
22391
|
+
signal.throwIfAborted();
|
|
22333
22392
|
if (this.#turn !== null) {
|
|
22334
22393
|
throw new AcpExecutionError("Another prompt is already running in this conversation", {}, "session_busy");
|
|
22335
22394
|
}
|
|
22336
22395
|
const completion = Promise.withResolvers();
|
|
22396
|
+
void completion.promise.catch(() => {
|
|
22397
|
+
});
|
|
22398
|
+
const aborted2 = () => {
|
|
22399
|
+
completion.reject(signal.reason);
|
|
22400
|
+
void this.close().catch((cause) => {
|
|
22401
|
+
console.error("The cancelled Codex endpoint could not release its process tree", cause);
|
|
22402
|
+
});
|
|
22403
|
+
};
|
|
22404
|
+
signal.addEventListener("abort", aborted2, { once: true });
|
|
22337
22405
|
const turn = { completion, turn: { id: "" } };
|
|
22338
22406
|
this.#turn = turn;
|
|
22339
22407
|
try {
|
|
@@ -22379,6 +22447,7 @@ var CodexAcpAgent = class {
|
|
|
22379
22447
|
}
|
|
22380
22448
|
return await completion.promise;
|
|
22381
22449
|
} finally {
|
|
22450
|
+
signal.removeEventListener("abort", aborted2);
|
|
22382
22451
|
if (this.#turn === turn) {
|
|
22383
22452
|
this.#turn = null;
|
|
22384
22453
|
}
|
|
@@ -22407,7 +22476,6 @@ var CodexAcpAgent = class {
|
|
|
22407
22476
|
if (active === null) {
|
|
22408
22477
|
return;
|
|
22409
22478
|
}
|
|
22410
|
-
this.#turn = null;
|
|
22411
22479
|
await this.#updateTail;
|
|
22412
22480
|
if (turn.status === "failed") {
|
|
22413
22481
|
active.completion.reject(
|
|
@@ -23529,24 +23597,40 @@ async function probeInProcessReadiness(agent, environment, defaultWorkspace, con
|
|
|
23529
23597
|
environment: { ...filterEnvironment(environment), ...agent.environment }
|
|
23530
23598
|
});
|
|
23531
23599
|
try {
|
|
23532
|
-
await inProcess.initialize(controller.signal);
|
|
23533
23600
|
const connection = createAcpClient(new DiscoveryAcpHandler()).connect(inProcess.app());
|
|
23534
|
-
|
|
23535
|
-
|
|
23536
|
-
|
|
23537
|
-
|
|
23538
|
-
|
|
23539
|
-
|
|
23540
|
-
|
|
23541
|
-
|
|
23542
|
-
|
|
23543
|
-
|
|
23544
|
-
|
|
23601
|
+
try {
|
|
23602
|
+
return await Promise.race([
|
|
23603
|
+
(async () => {
|
|
23604
|
+
await inProcess.initialize(controller.signal);
|
|
23605
|
+
const initialized = await connection.agent.request(
|
|
23606
|
+
methods6.agent.initialize,
|
|
23607
|
+
{
|
|
23608
|
+
clientCapabilities: {},
|
|
23609
|
+
clientInfo: { name: "mobius", version: "0.0.3" },
|
|
23610
|
+
protocolVersion: PROTOCOL_VERSION2
|
|
23611
|
+
},
|
|
23612
|
+
{ cancellationSignal: controller.signal }
|
|
23613
|
+
);
|
|
23614
|
+
if (initialized.protocolVersion !== PROTOCOL_VERSION2) {
|
|
23615
|
+
throw new AgentProbeError(
|
|
23616
|
+
"acp_incompatible",
|
|
23617
|
+
"ACP agent selected an unsupported protocol version"
|
|
23618
|
+
);
|
|
23619
|
+
}
|
|
23620
|
+
return new VerifiedAcpReadiness(
|
|
23621
|
+
normalizeVersionOutput(initialized.agentInfo?.version ?? ""),
|
|
23622
|
+
normalizeAcpCapabilities(initialized)
|
|
23623
|
+
);
|
|
23624
|
+
})(),
|
|
23625
|
+
inProcess.terminated.then((termination) => {
|
|
23626
|
+
throw new AgentProbeError("acp_incompatible", "The ACP endpoint stopped during initialization", {
|
|
23627
|
+
cause: acpEndpointTerminationError(termination)
|
|
23628
|
+
});
|
|
23629
|
+
})
|
|
23630
|
+
]);
|
|
23631
|
+
} finally {
|
|
23632
|
+
connection.close();
|
|
23545
23633
|
}
|
|
23546
|
-
return new VerifiedAcpReadiness(
|
|
23547
|
-
normalizeVersionOutput(initialized.agentInfo?.version ?? ""),
|
|
23548
|
-
normalizeAcpCapabilities(initialized)
|
|
23549
|
-
);
|
|
23550
23634
|
} finally {
|
|
23551
23635
|
await inProcess.close();
|
|
23552
23636
|
}
|
|
@@ -25658,6 +25742,8 @@ var encodeRecordedSessionEvent = (event) => JSON.stringify(decodeRecordedSession
|
|
|
25658
25742
|
// ../protocol/src/session-live-history.ts
|
|
25659
25743
|
var SESSION_LIVE_HISTORY_LOAD_KIND = "session.live-history.load";
|
|
25660
25744
|
var SESSION_LIVE_HISTORY_LOADED_KIND = "session.live-history.loaded";
|
|
25745
|
+
var SESSION_LIVE_HISTORY_PAGE_LOAD_KIND = "session.live-history.page.load";
|
|
25746
|
+
var SESSION_LIVE_HISTORY_PAGE_LOADED_KIND = "session.live-history.page.loaded";
|
|
25661
25747
|
var identifier2 = external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/);
|
|
25662
25748
|
var directoryIdentifier = external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/);
|
|
25663
25749
|
var sessionLiveHistoryLoadSchema = external_exports.strictObject({
|
|
@@ -25675,6 +25761,23 @@ var sessionLiveHistoryLoadedSchema = external_exports.strictObject({
|
|
|
25675
25761
|
requestId: identifier2,
|
|
25676
25762
|
sessionId: identifier2
|
|
25677
25763
|
}).readonly();
|
|
25764
|
+
var sessionLiveHistoryPageLoadSchema = external_exports.strictObject({
|
|
25765
|
+
additionalDirectoryIds: external_exports.array(directoryIdentifier).max(16).readonly(),
|
|
25766
|
+
agentId: identifier2,
|
|
25767
|
+
bindingId: identifier2,
|
|
25768
|
+
cursor: external_exports.string().min(1).max(512).nullable(),
|
|
25769
|
+
directoryId: directoryIdentifier,
|
|
25770
|
+
kind: external_exports.literal(SESSION_LIVE_HISTORY_PAGE_LOAD_KIND),
|
|
25771
|
+
limit: external_exports.number().int().min(1).max(100),
|
|
25772
|
+
requestId: identifier2,
|
|
25773
|
+
sessionId: identifier2
|
|
25774
|
+
}).readonly();
|
|
25775
|
+
var sessionLiveHistoryPageLoadedSchema = external_exports.strictObject({
|
|
25776
|
+
kind: external_exports.literal(SESSION_LIVE_HISTORY_PAGE_LOADED_KIND),
|
|
25777
|
+
page: nativeMessagePageSchema,
|
|
25778
|
+
requestId: identifier2,
|
|
25779
|
+
sessionId: identifier2
|
|
25780
|
+
}).readonly();
|
|
25678
25781
|
function decode6(schema, encoded) {
|
|
25679
25782
|
try {
|
|
25680
25783
|
const value = JSON.parse(encoded);
|
|
@@ -25687,6 +25790,10 @@ var decodeSessionLiveHistoryLoad = (encoded) => decode6(sessionLiveHistoryLoadSc
|
|
|
25687
25790
|
var decodeSessionLiveHistoryLoaded = (encoded) => decode6(sessionLiveHistoryLoadedSchema, encoded);
|
|
25688
25791
|
var encodeSessionLiveHistoryLoad = (value) => JSON.stringify(sessionLiveHistoryLoadSchema.parse(value));
|
|
25689
25792
|
var encodeSessionLiveHistoryLoaded = (value) => JSON.stringify(sessionLiveHistoryLoadedSchema.parse(value));
|
|
25793
|
+
var decodeSessionLiveHistoryPageLoad = (encoded) => decode6(sessionLiveHistoryPageLoadSchema, encoded);
|
|
25794
|
+
var decodeSessionLiveHistoryPageLoaded = (encoded) => decode6(sessionLiveHistoryPageLoadedSchema, encoded);
|
|
25795
|
+
var encodeSessionLiveHistoryPageLoad = (value) => JSON.stringify(sessionLiveHistoryPageLoadSchema.parse(value));
|
|
25796
|
+
var encodeSessionLiveHistoryPageLoaded = (value) => JSON.stringify(sessionLiveHistoryPageLoadedSchema.parse(value));
|
|
25690
25797
|
|
|
25691
25798
|
// ../protocol/src/daemon-transport.ts
|
|
25692
25799
|
function defineMessageSignature(kind, encoder, decoder) {
|
|
@@ -25790,6 +25897,11 @@ var serviceToDaemonSignatures = {
|
|
|
25790
25897
|
encodeSessionLiveHistoryLoad,
|
|
25791
25898
|
decodeSessionLiveHistoryLoad
|
|
25792
25899
|
),
|
|
25900
|
+
[SESSION_LIVE_HISTORY_PAGE_LOAD_KIND]: defineMessageSignature(
|
|
25901
|
+
SESSION_LIVE_HISTORY_PAGE_LOAD_KIND,
|
|
25902
|
+
encodeSessionLiveHistoryPageLoad,
|
|
25903
|
+
decodeSessionLiveHistoryPageLoad
|
|
25904
|
+
),
|
|
25793
25905
|
[SESSION_PERMISSION_RESPOND_KIND]: defineMessageSignature(
|
|
25794
25906
|
SESSION_PERMISSION_RESPOND_KIND,
|
|
25795
25907
|
encodeSessionPermissionRespondCommand,
|
|
@@ -25900,6 +26012,11 @@ var daemonToServiceSignatures = {
|
|
|
25900
26012
|
encodeSessionLiveHistoryLoaded,
|
|
25901
26013
|
decodeSessionLiveHistoryLoaded
|
|
25902
26014
|
),
|
|
26015
|
+
[SESSION_LIVE_HISTORY_PAGE_LOADED_KIND]: defineMessageSignature(
|
|
26016
|
+
SESSION_LIVE_HISTORY_PAGE_LOADED_KIND,
|
|
26017
|
+
encodeSessionLiveHistoryPageLoaded,
|
|
26018
|
+
decodeSessionLiveHistoryPageLoaded
|
|
26019
|
+
),
|
|
25903
26020
|
[SESSION_READY_KIND]: defineMessageSignature(SESSION_READY_KIND, encodeSessionReadyEvent, decodeSessionReadyEvent),
|
|
25904
26021
|
[WORKSPACE_ENTRIES_KIND]: defineMessageSignature(
|
|
25905
26022
|
WORKSPACE_ENTRIES_KIND,
|
|
@@ -34495,6 +34612,29 @@ function sessionConfigProtocolForAgent(agentId) {
|
|
|
34495
34612
|
}
|
|
34496
34613
|
|
|
34497
34614
|
// src/acp/session-history.ts
|
|
34615
|
+
var HISTORY_ACTIVITY_FIELD_LIMIT = 1e5;
|
|
34616
|
+
var HISTORY_ACTIVITY_LIMIT = 100;
|
|
34617
|
+
function historyActivity(activity2) {
|
|
34618
|
+
return {
|
|
34619
|
+
activityId: activity2.activityId.slice(0, 128),
|
|
34620
|
+
activityType: activity2.activityType.slice(0, 128),
|
|
34621
|
+
content: activity2.content.slice(0, 100),
|
|
34622
|
+
input: activity2.input.slice(0, HISTORY_ACTIVITY_FIELD_LIMIT),
|
|
34623
|
+
locations: activity2.locations.slice(0, 100).map((location) => location.slice(0, 2048)),
|
|
34624
|
+
name: activity2.name.slice(0, 128),
|
|
34625
|
+
output: activity2.output.slice(0, HISTORY_ACTIVITY_FIELD_LIMIT),
|
|
34626
|
+
sequence: activity2.sequence,
|
|
34627
|
+
status: activity2.status.slice(0, 64),
|
|
34628
|
+
title: activity2.title.slice(0, 500),
|
|
34629
|
+
toolKind: activity2.toolKind.slice(0, 64)
|
|
34630
|
+
};
|
|
34631
|
+
}
|
|
34632
|
+
function historyContentCharacters(messages) {
|
|
34633
|
+
return messages.reduce(
|
|
34634
|
+
(total, message) => total + message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0),
|
|
34635
|
+
0
|
|
34636
|
+
);
|
|
34637
|
+
}
|
|
34498
34638
|
var AcpHistoryReplay = class {
|
|
34499
34639
|
#activities = /* @__PURE__ */ new Map();
|
|
34500
34640
|
#messages = [];
|
|
@@ -34601,33 +34741,45 @@ var AcpHistoryReplay = class {
|
|
|
34601
34741
|
};
|
|
34602
34742
|
snapshot = async () => {
|
|
34603
34743
|
await this.#activityTracker.finish();
|
|
34744
|
+
const messages = this.#messages.map((message) => {
|
|
34745
|
+
if (message.role === "user") {
|
|
34746
|
+
return message;
|
|
34747
|
+
}
|
|
34748
|
+
const activities = message.activityIds.flatMap((id) => {
|
|
34749
|
+
const activity2 = this.#activities.get(id);
|
|
34750
|
+
return activity2 === void 0 ? [] : [historyActivity(activity2)];
|
|
34751
|
+
});
|
|
34752
|
+
if (activities.length > HISTORY_ACTIVITY_LIMIT) {
|
|
34753
|
+
this.#truncated = true;
|
|
34754
|
+
}
|
|
34755
|
+
return {
|
|
34756
|
+
role: "assistant",
|
|
34757
|
+
text: message.text,
|
|
34758
|
+
content: message.content.slice(0, 100),
|
|
34759
|
+
activities: activities.slice(-HISTORY_ACTIVITY_LIMIT)
|
|
34760
|
+
};
|
|
34761
|
+
});
|
|
34762
|
+
while (historyContentCharacters(messages) > SESSION_HISTORY_CHARACTER_LIMIT) {
|
|
34763
|
+
const richIndex = messages.findIndex(
|
|
34764
|
+
(message) => message.role === "assistant" && (message.activities.length > 0 || message.content.length > 0)
|
|
34765
|
+
);
|
|
34766
|
+
if (richIndex === -1) {
|
|
34767
|
+
messages.shift();
|
|
34768
|
+
} else {
|
|
34769
|
+
const message = messages[richIndex];
|
|
34770
|
+
if (message?.role === "assistant") {
|
|
34771
|
+
messages[richIndex] = {
|
|
34772
|
+
...message,
|
|
34773
|
+
activities: message.activities.length > 0 ? message.activities.slice(1) : message.activities,
|
|
34774
|
+
content: message.activities.length === 0 && message.content.length > 0 ? message.content.slice(1) : message.content
|
|
34775
|
+
};
|
|
34776
|
+
}
|
|
34777
|
+
}
|
|
34778
|
+
this.#truncated = true;
|
|
34779
|
+
}
|
|
34604
34780
|
return {
|
|
34605
34781
|
status: "available",
|
|
34606
|
-
messages
|
|
34607
|
-
(message) => message.role === "user" ? message : {
|
|
34608
|
-
role: "assistant",
|
|
34609
|
-
text: message.text,
|
|
34610
|
-
content: message.content,
|
|
34611
|
-
activities: message.activityIds.flatMap((id) => {
|
|
34612
|
-
const activity2 = this.#activities.get(id);
|
|
34613
|
-
return activity2 === void 0 ? [] : [
|
|
34614
|
-
{
|
|
34615
|
-
activityId: activity2.activityId,
|
|
34616
|
-
activityType: activity2.activityType,
|
|
34617
|
-
content: activity2.content,
|
|
34618
|
-
input: activity2.input,
|
|
34619
|
-
locations: activity2.locations,
|
|
34620
|
-
name: activity2.name,
|
|
34621
|
-
output: activity2.output,
|
|
34622
|
-
sequence: activity2.sequence,
|
|
34623
|
-
status: activity2.status,
|
|
34624
|
-
title: activity2.title,
|
|
34625
|
-
toolKind: activity2.toolKind
|
|
34626
|
-
}
|
|
34627
|
-
];
|
|
34628
|
-
})
|
|
34629
|
-
}
|
|
34630
|
-
),
|
|
34782
|
+
messages,
|
|
34631
34783
|
truncated: this.#truncated,
|
|
34632
34784
|
coveredCommandIds: [],
|
|
34633
34785
|
coveredMessageIds: []
|
|
@@ -35428,8 +35580,8 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
35428
35580
|
#pendingElicitations = /* @__PURE__ */ new Map();
|
|
35429
35581
|
#pendingPermissions = /* @__PURE__ */ new Map();
|
|
35430
35582
|
#preSessionUpdates = [];
|
|
35431
|
-
//
|
|
35432
|
-
#
|
|
35583
|
+
// Both topologies report a terminal outcome, even after a prompt's initial RPC is acknowledged.
|
|
35584
|
+
#termination;
|
|
35433
35585
|
#runtimeChild;
|
|
35434
35586
|
#metrics;
|
|
35435
35587
|
#sessionConfigProtocol;
|
|
@@ -35473,8 +35625,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
35473
35625
|
});
|
|
35474
35626
|
this.#inProcessAgent = inProcess;
|
|
35475
35627
|
this.#runtimeChild = null;
|
|
35476
|
-
this.#
|
|
35477
|
-
});
|
|
35628
|
+
this.#termination = inProcess.terminated;
|
|
35478
35629
|
this.#connection = createAcpClient(this).connect(inProcess.app());
|
|
35479
35630
|
return;
|
|
35480
35631
|
}
|
|
@@ -35498,9 +35649,16 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
35498
35649
|
stderr.on("data", (chunk) => {
|
|
35499
35650
|
process.stderr.write(`[${agent.id}-acp] ${chunk}`);
|
|
35500
35651
|
});
|
|
35501
|
-
this.#
|
|
35502
|
-
child.once("error",
|
|
35503
|
-
|
|
35652
|
+
this.#termination = new Promise((resolve8) => {
|
|
35653
|
+
child.once("error", (cause) => {
|
|
35654
|
+
resolve8({ kind: "failed", error: new AcpExecutionError("The ACP process could not run", { cause }) });
|
|
35655
|
+
});
|
|
35656
|
+
child.once("exit", (code, signal) => {
|
|
35657
|
+
resolve8({
|
|
35658
|
+
kind: "failed",
|
|
35659
|
+
error: new AcpExecutionError("The ACP process stopped", { cause: { code, signal } })
|
|
35660
|
+
});
|
|
35661
|
+
});
|
|
35504
35662
|
});
|
|
35505
35663
|
const stream = ndJsonStream2(createWritableAcpStream(stdin), readableWebStream(stdout));
|
|
35506
35664
|
this.#connection = createAcpClient(this).connect(stream);
|
|
@@ -36642,8 +36800,9 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
36642
36800
|
try {
|
|
36643
36801
|
return await Promise.race([
|
|
36644
36802
|
operation,
|
|
36645
|
-
this.#
|
|
36646
|
-
|
|
36803
|
+
this.#termination.then((termination) => {
|
|
36804
|
+
const cause = acpEndpointTerminationError(termination);
|
|
36805
|
+
throw new AcpExecutionError(exitMessage, { cause }, cause.code);
|
|
36647
36806
|
}),
|
|
36648
36807
|
aborted2
|
|
36649
36808
|
]);
|
|
@@ -42018,6 +42177,70 @@ async function executeSessionPrepare(publisher, socket, command, config2, direct
|
|
|
42018
42177
|
reportOperationFailure(socket, command.requestId, command.sessionId, error62, metrics.snapshot());
|
|
42019
42178
|
}
|
|
42020
42179
|
}
|
|
42180
|
+
function liveHistoryCursor(sessionId, endIndex) {
|
|
42181
|
+
return Buffer.from(JSON.stringify({ endIndex, sessionId }), "utf8").toString("base64url");
|
|
42182
|
+
}
|
|
42183
|
+
function liveHistoryEndIndex(cursor, sessionId) {
|
|
42184
|
+
try {
|
|
42185
|
+
if (!/^[A-Za-z0-9_-]{1,512}$/u.test(cursor)) {
|
|
42186
|
+
throw new Error("Invalid cursor alphabet");
|
|
42187
|
+
}
|
|
42188
|
+
const value = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8"));
|
|
42189
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
42190
|
+
throw new Error("Invalid cursor shape");
|
|
42191
|
+
}
|
|
42192
|
+
const record2 = Object.fromEntries(Object.entries(value));
|
|
42193
|
+
if (Object.keys(record2).sort().join(",") !== "endIndex,sessionId" || record2["sessionId"] !== sessionId || typeof record2["endIndex"] !== "number" || !Number.isSafeInteger(record2["endIndex"]) || record2["endIndex"] < 0) {
|
|
42194
|
+
throw new Error("Invalid cursor target");
|
|
42195
|
+
}
|
|
42196
|
+
return record2["endIndex"];
|
|
42197
|
+
} catch (cause) {
|
|
42198
|
+
throw new AcpExecutionError("The native Session history cursor is invalid", { cause }, "invalid_cursor");
|
|
42199
|
+
}
|
|
42200
|
+
}
|
|
42201
|
+
function liveHistoryCoveredTurnRanges(history) {
|
|
42202
|
+
const ranges = [];
|
|
42203
|
+
let historyIndex = history.messages.length;
|
|
42204
|
+
for (const commandId of history.coveredCommandIds) {
|
|
42205
|
+
let assistantStartIndex = historyIndex;
|
|
42206
|
+
while (assistantStartIndex > 0 && history.messages[assistantStartIndex - 1]?.role === "assistant") {
|
|
42207
|
+
assistantStartIndex -= 1;
|
|
42208
|
+
}
|
|
42209
|
+
const userIndex = assistantStartIndex - 1;
|
|
42210
|
+
if (assistantStartIndex === historyIndex || history.messages[userIndex]?.role !== "user") {
|
|
42211
|
+
break;
|
|
42212
|
+
}
|
|
42213
|
+
ranges.push({ assistantEndIndex: historyIndex, assistantStartIndex, commandId, userIndex });
|
|
42214
|
+
historyIndex = userIndex;
|
|
42215
|
+
}
|
|
42216
|
+
return ranges;
|
|
42217
|
+
}
|
|
42218
|
+
function paginateLiveSessionHistory(history, sessionId, cursor, limit) {
|
|
42219
|
+
if (history.status === "unavailable") {
|
|
42220
|
+
if (cursor !== null) {
|
|
42221
|
+
throw new AcpExecutionError("Unavailable native Session history has no cursor", {}, "invalid_cursor");
|
|
42222
|
+
}
|
|
42223
|
+
return { cause: history.cause, nextCursor: null, status: "unavailable" };
|
|
42224
|
+
}
|
|
42225
|
+
const endIndex = cursor === null ? history.messages.length : liveHistoryEndIndex(cursor, sessionId);
|
|
42226
|
+
if (endIndex > history.messages.length) {
|
|
42227
|
+
throw new AcpExecutionError("The native Session history cursor is invalid", {}, "invalid_cursor");
|
|
42228
|
+
}
|
|
42229
|
+
const startIndex = Math.max(0, endIndex - limit);
|
|
42230
|
+
const coveredMessageIds = new Set(history.coveredMessageIds);
|
|
42231
|
+
const ranges = liveHistoryCoveredTurnRanges(history);
|
|
42232
|
+
return {
|
|
42233
|
+
coveredCommandIds: ranges.filter((range) => range.userIndex >= startIndex && range.assistantEndIndex <= endIndex).map((range) => range.commandId),
|
|
42234
|
+
coveredMessageIds: ranges.flatMap((range) => [
|
|
42235
|
+
...range.userIndex >= startIndex && range.userIndex < endIndex && coveredMessageIds.has(`${range.commandId}:user`) ? [`${range.commandId}:user`] : [],
|
|
42236
|
+
...range.assistantStartIndex >= startIndex && range.assistantEndIndex <= endIndex && coveredMessageIds.has(`${range.commandId}:agent`) ? [`${range.commandId}:agent`] : []
|
|
42237
|
+
]),
|
|
42238
|
+
messages: history.messages.slice(startIndex, endIndex),
|
|
42239
|
+
nextCursor: startIndex > 0 ? liveHistoryCursor(sessionId, startIndex) : null,
|
|
42240
|
+
status: "available",
|
|
42241
|
+
truncated: history.truncated
|
|
42242
|
+
};
|
|
42243
|
+
}
|
|
42021
42244
|
async function executeSessionLiveHistoryLoad(socket, command, config2, directories, audit, sessions, signal) {
|
|
42022
42245
|
try {
|
|
42023
42246
|
const resolved = await resolveSessionDirectories(
|
|
@@ -42067,6 +42290,57 @@ async function executeSessionLiveHistoryLoad(socket, command, config2, directori
|
|
|
42067
42290
|
});
|
|
42068
42291
|
}
|
|
42069
42292
|
}
|
|
42293
|
+
async function executeSessionLiveHistoryPageLoad(socket, command, config2, directories, audit, sessions, signal) {
|
|
42294
|
+
try {
|
|
42295
|
+
const resolved = await resolveSessionDirectories(
|
|
42296
|
+
directories,
|
|
42297
|
+
config2.bindingId,
|
|
42298
|
+
command.directoryId,
|
|
42299
|
+
command.additionalDirectoryIds,
|
|
42300
|
+
signal
|
|
42301
|
+
);
|
|
42302
|
+
const history = await sessions.loadSessionHistory({
|
|
42303
|
+
additionalDirectories: resolved.additionalDirectories,
|
|
42304
|
+
agent: config2.catalog.find(command.agentId),
|
|
42305
|
+
cwd: resolved.cwd,
|
|
42306
|
+
sessionId: command.sessionId,
|
|
42307
|
+
signal
|
|
42308
|
+
});
|
|
42309
|
+
signal.throwIfAborted();
|
|
42310
|
+
const page = paginateLiveSessionHistory(history, command.sessionId, command.cursor, command.limit);
|
|
42311
|
+
audit.record({
|
|
42312
|
+
commandId: command.requestId,
|
|
42313
|
+
event: "session_history_loaded",
|
|
42314
|
+
sessionId: command.sessionId
|
|
42315
|
+
});
|
|
42316
|
+
send(socket, {
|
|
42317
|
+
kind: "session.live-history.page.loaded",
|
|
42318
|
+
page,
|
|
42319
|
+
requestId: command.requestId,
|
|
42320
|
+
sessionId: command.sessionId
|
|
42321
|
+
});
|
|
42322
|
+
} catch (error62) {
|
|
42323
|
+
if (signal.aborted) {
|
|
42324
|
+
return;
|
|
42325
|
+
}
|
|
42326
|
+
audit.record({
|
|
42327
|
+
commandId: command.requestId,
|
|
42328
|
+
details: { code: operationErrorCode(error62) },
|
|
42329
|
+
event: "session_history_unavailable",
|
|
42330
|
+
sessionId: command.sessionId
|
|
42331
|
+
});
|
|
42332
|
+
send(socket, {
|
|
42333
|
+
kind: "session.live-history.page.loaded",
|
|
42334
|
+
page: {
|
|
42335
|
+
status: "unavailable",
|
|
42336
|
+
cause: { code: operationErrorCode(error62), message: operationErrorMessage(error62) },
|
|
42337
|
+
nextCursor: null
|
|
42338
|
+
},
|
|
42339
|
+
requestId: command.requestId,
|
|
42340
|
+
sessionId: command.sessionId
|
|
42341
|
+
});
|
|
42342
|
+
}
|
|
42343
|
+
}
|
|
42070
42344
|
async function executeSessionConfigure(publisher, socket, command, config2, directories, audit, sessions, signal) {
|
|
42071
42345
|
try {
|
|
42072
42346
|
const resolved = await resolveSessionDirectories(
|
|
@@ -42926,6 +43200,19 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
42926
43200
|
);
|
|
42927
43201
|
return;
|
|
42928
43202
|
}
|
|
43203
|
+
if (kind === SESSION_LIVE_HISTORY_PAGE_LOAD_KIND) {
|
|
43204
|
+
const command2 = decodeSessionLiveHistoryPageLoad(encoded);
|
|
43205
|
+
void executeSessionLiveHistoryPageLoad(
|
|
43206
|
+
socket,
|
|
43207
|
+
command2,
|
|
43208
|
+
config2,
|
|
43209
|
+
directories,
|
|
43210
|
+
audit,
|
|
43211
|
+
sessions,
|
|
43212
|
+
connectionController.signal
|
|
43213
|
+
);
|
|
43214
|
+
return;
|
|
43215
|
+
}
|
|
42929
43216
|
if (kind === NATIVE_SESSION_CANCEL_KIND) {
|
|
42930
43217
|
const command2 = message;
|
|
42931
43218
|
const pending = nativeRequests.get(command2.requestId);
|