toc-ocra 0.3.12 → 0.3.13
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/README.md +7 -0
- package/dist/cli/cli.mjs +199 -88
- package/dist/service/agent.mjs +196 -85
- package/dist/src/acp/chat-session.d.ts +4 -0
- package/dist/src/acp/chat-session.js +5 -0
- package/dist/src/acp/chat-session.js.map +1 -1
- package/dist/src/acp/cli-command.d.ts +8 -0
- package/dist/src/acp/cli-command.js +11 -0
- package/dist/src/acp/cli-command.js.map +1 -0
- package/dist/src/acp/command-catalog.d.ts +5 -0
- package/dist/src/acp/command-catalog.js +24 -0
- package/dist/src/acp/command-catalog.js.map +1 -0
- package/dist/src/acp/connection.d.ts +5 -0
- package/dist/src/acp/connection.js +35 -0
- package/dist/src/acp/connection.js.map +1 -1
- package/dist/src/runs/run-supervisor.d.ts +9 -0
- package/dist/src/runs/run-supervisor.js +27 -3
- package/dist/src/runs/run-supervisor.js.map +1 -1
- package/dist/src/runtime/agent-runtime.js +10 -0
- package/dist/src/runtime/agent-runtime.js.map +1 -1
- package/dist/src/types/protocol.d.ts +5 -0
- package/dist/src/types/protocol.js +2 -0
- package/dist/src/types/protocol.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/cli.mjs
CHANGED
|
@@ -21242,8 +21242,8 @@ function rewriteKeyNames(ctx) {
|
|
|
21242
21242
|
bySchema.set(entry.schema, entry);
|
|
21243
21243
|
}
|
|
21244
21244
|
const rewrites = /* @__PURE__ */ new Map();
|
|
21245
|
-
for (const
|
|
21246
|
-
const seen = ctx.seen.get(
|
|
21245
|
+
for (const record10 of pendingRecords.get(ctx) ?? []) {
|
|
21246
|
+
const seen = ctx.seen.get(record10);
|
|
21247
21247
|
const names = (seen?.def ?? seen?.schema)?.propertyNames;
|
|
21248
21248
|
if (!names || names === true || rewrites.has(names))
|
|
21249
21249
|
continue;
|
|
@@ -27268,12 +27268,24 @@ function rpcErrorText(error62) {
|
|
|
27268
27268
|
return /^internal error$/i.test(error62.message) ? detail : `${error62.message}: ${detail}`;
|
|
27269
27269
|
}
|
|
27270
27270
|
|
|
27271
|
+
// src/acp/cli-command.ts
|
|
27272
|
+
var record3 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
27273
|
+
function cliCommands(value) {
|
|
27274
|
+
if (!Array.isArray(value)) return void 0;
|
|
27275
|
+
return value.map(record3).filter((item) => typeof item.name === "string" && item.name.length > 0).map((item) => ({
|
|
27276
|
+
name: item.name,
|
|
27277
|
+
...typeof item.description === "string" ? { description: item.description } : {},
|
|
27278
|
+
..."input" in item ? { input: item.input } : {},
|
|
27279
|
+
..."_meta" in item ? { _meta: item._meta } : {}
|
|
27280
|
+
}));
|
|
27281
|
+
}
|
|
27282
|
+
|
|
27271
27283
|
// src/acp/connection.ts
|
|
27272
27284
|
var PROTOCOL_VERSION = 1;
|
|
27273
27285
|
var INITIALIZE_TIMEOUT_MS = 12e4;
|
|
27274
27286
|
var SESSION_OPEN_TIMEOUT_MS = 18e4;
|
|
27275
27287
|
var EXT_REQUEST_TIMEOUT_MS = 6e4;
|
|
27276
|
-
var
|
|
27288
|
+
var record4 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
27277
27289
|
var text2 = (value) => typeof value === "string" && value ? value : void 0;
|
|
27278
27290
|
var AcpConnection = class _AcpConnection {
|
|
27279
27291
|
constructor(launch, hooks, elicitation) {
|
|
@@ -27282,8 +27294,8 @@ var AcpConnection = class _AcpConnection {
|
|
|
27282
27294
|
let peer;
|
|
27283
27295
|
this.process = AgentProcess.spawn(launch, (line) => peer?.receive(line), (line) => hooks.stderr(line));
|
|
27284
27296
|
peer = new JsonRpcPeer((line) => this.process.write(line), {
|
|
27285
|
-
request: async (method, params, signal2) => this.onRequest(method,
|
|
27286
|
-
notification: (method, params) => this.onNotification(method,
|
|
27297
|
+
request: async (method, params, signal2) => this.onRequest(method, record4(params), signal2),
|
|
27298
|
+
notification: (method, params) => this.onNotification(method, record4(params))
|
|
27287
27299
|
});
|
|
27288
27300
|
this.peer = peer;
|
|
27289
27301
|
this.closed = this.process.exited.then((exit) => {
|
|
@@ -27306,6 +27318,8 @@ var AcpConnection = class _AcpConnection {
|
|
|
27306
27318
|
steering;
|
|
27307
27319
|
initialized = {};
|
|
27308
27320
|
peer;
|
|
27321
|
+
commandLists = /* @__PURE__ */ new Map();
|
|
27322
|
+
commandListeners = /* @__PURE__ */ new Set();
|
|
27309
27323
|
/**
|
|
27310
27324
|
* Starts the agent and completes `initialize`; the process is stopped on
|
|
27311
27325
|
* failure. `elicitation`: advertise form elicitation (Claude's adapter only
|
|
@@ -27315,7 +27329,7 @@ var AcpConnection = class _AcpConnection {
|
|
|
27315
27329
|
const elicitation = options.elicitation === true && hooks.elicitation !== void 0;
|
|
27316
27330
|
const connection = new _AcpConnection(launch, hooks, elicitation);
|
|
27317
27331
|
try {
|
|
27318
|
-
const result =
|
|
27332
|
+
const result = record4(await connection.call("initialize", {
|
|
27319
27333
|
protocolVersion: PROTOCOL_VERSION,
|
|
27320
27334
|
clientCapabilities: {
|
|
27321
27335
|
fs: { readTextFile: false, writeTextFile: false },
|
|
@@ -27336,16 +27350,18 @@ var AcpConnection = class _AcpConnection {
|
|
|
27336
27350
|
}
|
|
27337
27351
|
/** `auth`: the row's sign-in method, tried once when the agent answers `auth_required`. */
|
|
27338
27352
|
async newSession(cwd, auth) {
|
|
27339
|
-
const result =
|
|
27353
|
+
const result = record4(await this.withAuthentication(() => this.call("session/new", { cwd, mcpServers: [] }, SESSION_OPEN_TIMEOUT_MS), auth));
|
|
27340
27354
|
const sessionId = text2(result.sessionId);
|
|
27341
27355
|
if (!sessionId) throw new Error("ACP session/new \u6CA1\u6709\u8FD4\u56DE\u4F1A\u8BDD ID");
|
|
27356
|
+
this.captureCommands(sessionId, result.availableCommands);
|
|
27342
27357
|
return sessionState(sessionId, result);
|
|
27343
27358
|
}
|
|
27344
27359
|
/** Reopens a saved session: `session/load` (replays history) or `session/resume`, as the capabilities allow. */
|
|
27345
27360
|
async openSaved(sessionId, cwd, options = {}) {
|
|
27346
27361
|
const method = acpSessionMethod(this.initialized, sessionId, options.resumePreference);
|
|
27347
27362
|
if (!method || method === "new") throw new Error("ACP agent cannot load or resume this session");
|
|
27348
|
-
const result =
|
|
27363
|
+
const result = record4(await this.withAuthentication(() => this.call(`session/${method}`, { sessionId, cwd, mcpServers: [] }, SESSION_OPEN_TIMEOUT_MS), options.auth));
|
|
27364
|
+
this.captureCommands(sessionId, result.availableCommands);
|
|
27349
27365
|
return sessionState(sessionId, result);
|
|
27350
27366
|
}
|
|
27351
27367
|
/** Removes a session the agent created for a listing; only when `deleteSession`. */
|
|
@@ -27355,9 +27371,41 @@ var AcpConnection = class _AcpConnection {
|
|
|
27355
27371
|
get canOpenSaved() {
|
|
27356
27372
|
return this.loadSession || this.resumeSession;
|
|
27357
27373
|
}
|
|
27374
|
+
async commands(sessionId) {
|
|
27375
|
+
const known = this.commandLists.get(sessionId);
|
|
27376
|
+
if (known) return known;
|
|
27377
|
+
return await new Promise((resolve10, reject) => {
|
|
27378
|
+
const finish = () => {
|
|
27379
|
+
const items = this.commandLists.get(sessionId);
|
|
27380
|
+
if (!items) return;
|
|
27381
|
+
cleanup();
|
|
27382
|
+
resolve10(items);
|
|
27383
|
+
};
|
|
27384
|
+
const cleanup = () => {
|
|
27385
|
+
clearTimeout(timer);
|
|
27386
|
+
this.commandListeners.delete(finish);
|
|
27387
|
+
};
|
|
27388
|
+
const timer = setTimeout(() => {
|
|
27389
|
+
cleanup();
|
|
27390
|
+
reject(new Error("CLI \u672A\u8FD4\u56DE\u547D\u4EE4\u5217\u8868\uFF0C\u8BF7\u5347\u7EA7\u8BBE\u5907\u4EE3\u7406\u6216\u786E\u8BA4\u6B64 CLI \u652F\u6301 ACP \u547D\u4EE4\u3002"));
|
|
27391
|
+
}, 8e3);
|
|
27392
|
+
this.commandListeners.add(finish);
|
|
27393
|
+
void this.closed.then((error62) => {
|
|
27394
|
+
cleanup();
|
|
27395
|
+
reject(error62);
|
|
27396
|
+
});
|
|
27397
|
+
finish();
|
|
27398
|
+
});
|
|
27399
|
+
}
|
|
27400
|
+
captureCommands(sessionId, value) {
|
|
27401
|
+
const items = cliCommands(value);
|
|
27402
|
+
if (!items) return;
|
|
27403
|
+
this.commandLists.set(sessionId, items);
|
|
27404
|
+
for (const notify of this.commandListeners) notify();
|
|
27405
|
+
}
|
|
27358
27406
|
/** Resolves with the prompt's `stopReason` once the agent ends the turn. */
|
|
27359
27407
|
async prompt(sessionId, prompt, meta3) {
|
|
27360
|
-
const result =
|
|
27408
|
+
const result = record4(await this.peer.request("session/prompt", { sessionId, prompt, ...meta3 ? { _meta: meta3 } : {} }));
|
|
27361
27409
|
return text2(result.stopReason) ?? "end_turn";
|
|
27362
27410
|
}
|
|
27363
27411
|
cancel(sessionId) {
|
|
@@ -27369,7 +27417,7 @@ var AcpConnection = class _AcpConnection {
|
|
|
27369
27417
|
}
|
|
27370
27418
|
/** `_lody/session/steer`: `injected` means the agent took the prompt into the running turn. */
|
|
27371
27419
|
async steer(sessionId, prompt, steerId) {
|
|
27372
|
-
const result =
|
|
27420
|
+
const result = record4(await this.peer.request("_lody/session/steer", { sessionId, prompt, steerId }));
|
|
27373
27421
|
return result.outcome === "injected" ? "injected" : "failed";
|
|
27374
27422
|
}
|
|
27375
27423
|
/** An adapter extension request (`_session/archive`, `_session/unarchive`, …) with a time limit. */
|
|
@@ -27400,14 +27448,14 @@ var AcpConnection = class _AcpConnection {
|
|
|
27400
27448
|
);
|
|
27401
27449
|
}
|
|
27402
27450
|
readCapabilities(result) {
|
|
27403
|
-
const capabilities =
|
|
27451
|
+
const capabilities = record4(result.agentCapabilities);
|
|
27404
27452
|
this.initialized = result;
|
|
27405
|
-
this.agentName = text2(
|
|
27453
|
+
this.agentName = text2(record4(result.agentInfo).name) ?? "";
|
|
27406
27454
|
this.loadSession = capabilities.loadSession === true;
|
|
27407
|
-
this.resumeSession =
|
|
27408
|
-
this.deleteSession =
|
|
27409
|
-
this.imagePrompts =
|
|
27410
|
-
const steering =
|
|
27455
|
+
this.resumeSession = record4(capabilities.sessionCapabilities).resume != null;
|
|
27456
|
+
this.deleteSession = record4(capabilities.sessionCapabilities).delete != null;
|
|
27457
|
+
this.imagePrompts = record4(capabilities.promptCapabilities).image === true;
|
|
27458
|
+
const steering = record4(record4(record4(capabilities._meta).lody).steering);
|
|
27411
27459
|
if (steering.version === 1 && (steering.transport === "request" || steering.transport === "prompt")) {
|
|
27412
27460
|
this.steering = { transport: steering.transport, upstreamTurn: steering.upstreamTurn === "handoff" ? "handoff" : "same" };
|
|
27413
27461
|
}
|
|
@@ -27420,7 +27468,9 @@ var AcpConnection = class _AcpConnection {
|
|
|
27420
27468
|
onNotification(method, params) {
|
|
27421
27469
|
if (method === "session/update") {
|
|
27422
27470
|
const sessionId = text2(params.sessionId);
|
|
27423
|
-
|
|
27471
|
+
const update2 = record4(params.update);
|
|
27472
|
+
if (sessionId && update2.sessionUpdate === "available_commands_update") this.captureCommands(sessionId, update2.availableCommands);
|
|
27473
|
+
if (sessionId) this.hooks.update(sessionId, record4(params.update));
|
|
27424
27474
|
return;
|
|
27425
27475
|
}
|
|
27426
27476
|
this.hooks.notification(method, params);
|
|
@@ -27511,7 +27561,7 @@ var TurnTranscript = class {
|
|
|
27511
27561
|
case "plan":
|
|
27512
27562
|
return this.item({ itemId: "plan", type: "plan", entries: planEntries(update2.entries) });
|
|
27513
27563
|
case "plan_update": {
|
|
27514
|
-
const plan =
|
|
27564
|
+
const plan = record4(update2.plan);
|
|
27515
27565
|
if (plan.type === "items") return this.item({ itemId: "plan", type: "plan", entries: planEntries(plan.entries) });
|
|
27516
27566
|
if (plan.type === "markdown" && typeof plan.planId === "string") {
|
|
27517
27567
|
return this.item({ itemId: `proposed_plan:${plan.planId}`, type: "proposed_plan", turnId: plan.planId, markdown: clipText(String(plan.content ?? ""), 64e3), status: "delta", isLatest: true });
|
|
@@ -27538,7 +27588,7 @@ var TurnTranscript = class {
|
|
|
27538
27588
|
/** The agent's slash commands, also known before the first prompt. */
|
|
27539
27589
|
availableCommands(list) {
|
|
27540
27590
|
if (!Array.isArray(list)) return;
|
|
27541
|
-
const commands = list.map(
|
|
27591
|
+
const commands = list.map(record4).filter((command) => typeof command.name === "string").map((command) => ({
|
|
27542
27592
|
name: command.name,
|
|
27543
27593
|
description: clipText(typeof command.description === "string" ? command.description : "", 600),
|
|
27544
27594
|
...command.input && typeof command.input === "object" ? { input: clip2(command.input, 600) } : {}
|
|
@@ -27576,7 +27626,7 @@ var TurnTranscript = class {
|
|
|
27576
27626
|
if (rows.length) this.rows(rows);
|
|
27577
27627
|
}
|
|
27578
27628
|
chunk(kind, content) {
|
|
27579
|
-
const part =
|
|
27629
|
+
const part = record4(content);
|
|
27580
27630
|
if (part.type !== "text" || typeof part.text !== "string" || !part.text) return;
|
|
27581
27631
|
let open4 = this.open;
|
|
27582
27632
|
if (open4?.kind !== kind) {
|
|
@@ -27658,14 +27708,14 @@ var TurnTranscript = class {
|
|
|
27658
27708
|
}
|
|
27659
27709
|
/** Run-log rows for the output tail (the 运行日志 view). */
|
|
27660
27710
|
toolRows(tool, first) {
|
|
27661
|
-
const input2 =
|
|
27711
|
+
const input2 = record4(tool.rawInput);
|
|
27662
27712
|
const command = typeof input2.command === "string" ? input2.command : Array.isArray(input2.command) ? input2.command.join(" ") : void 0;
|
|
27663
27713
|
if (tool.kind === "execute") {
|
|
27664
27714
|
if (first) {
|
|
27665
27715
|
this.shellOpen = tool.toolCallId;
|
|
27666
27716
|
this.rows([runLog.command(command ?? tool.title ?? "shell")]);
|
|
27667
27717
|
} else {
|
|
27668
|
-
const output2 =
|
|
27718
|
+
const output2 = record4(tool.rawOutput);
|
|
27669
27719
|
const text3 = typeof output2.aggregated_output === "string" ? output2.aggregated_output : typeof output2.stdout === "string" ? output2.stdout : "";
|
|
27670
27720
|
const header = this.shellOpen === tool.toolCallId ? [] : [runLog.command(command ?? tool.title ?? "shell")];
|
|
27671
27721
|
this.shellOpen = "";
|
|
@@ -27679,7 +27729,7 @@ var TurnTranscript = class {
|
|
|
27679
27729
|
return;
|
|
27680
27730
|
}
|
|
27681
27731
|
this.shellOpen = "";
|
|
27682
|
-
const location =
|
|
27732
|
+
const location = record4(tool.locations?.[0]);
|
|
27683
27733
|
const path = typeof location.path === "string" ? location.path : void 0;
|
|
27684
27734
|
if (tool.kind === "edit" || tool.kind === "delete" || tool.kind === "move") this.rows([runLog.fileChange(path)]);
|
|
27685
27735
|
else if (tool.kind === "fetch") this.rows([runLog.tool("web_search")]);
|
|
@@ -27691,7 +27741,7 @@ var TurnTranscript = class {
|
|
|
27691
27741
|
};
|
|
27692
27742
|
function planEntries(value) {
|
|
27693
27743
|
if (!Array.isArray(value)) return [];
|
|
27694
|
-
return value.map(
|
|
27744
|
+
return value.map(record4).map((entry) => ({
|
|
27695
27745
|
content: clipText(String(entry.content ?? ""), 2e3),
|
|
27696
27746
|
priority: typeof entry.priority === "string" ? entry.priority : "medium",
|
|
27697
27747
|
status: typeof entry.status === "string" ? entry.status : "pending"
|
|
@@ -27699,7 +27749,7 @@ function planEntries(value) {
|
|
|
27699
27749
|
}
|
|
27700
27750
|
function toolContent(content) {
|
|
27701
27751
|
return content.map((block) => {
|
|
27702
|
-
const part =
|
|
27752
|
+
const part = record4(block);
|
|
27703
27753
|
if (part.type === "diff") {
|
|
27704
27754
|
return {
|
|
27705
27755
|
type: "diff",
|
|
@@ -27712,10 +27762,10 @@ function toolContent(content) {
|
|
|
27712
27762
|
});
|
|
27713
27763
|
}
|
|
27714
27764
|
function toolMeta(value) {
|
|
27715
|
-
const meta3 =
|
|
27765
|
+
const meta3 = record4(value);
|
|
27716
27766
|
const out = {};
|
|
27717
27767
|
if (meta3.lody !== void 0) out.lody = clip2(meta3.lody, 2e3);
|
|
27718
|
-
const claudeCode =
|
|
27768
|
+
const claudeCode = record4(meta3.claudeCode);
|
|
27719
27769
|
if (Object.keys(claudeCode).length) {
|
|
27720
27770
|
out.claudeCode = {
|
|
27721
27771
|
...typeof claudeCode.toolName === "string" ? { toolName: claudeCode.toolName } : {},
|
|
@@ -27739,7 +27789,7 @@ function clip2(value, max, depth = 0) {
|
|
|
27739
27789
|
|
|
27740
27790
|
// src/providers/cli/codex.ts
|
|
27741
27791
|
var CODEX = requireCliSpec("codex");
|
|
27742
|
-
var
|
|
27792
|
+
var record5 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
27743
27793
|
function toolItem(id, fields) {
|
|
27744
27794
|
return { event: "item", item: { itemId: `tool:${id}`, type: "tool_call", toolCallId: id, ...fields } };
|
|
27745
27795
|
}
|
|
@@ -27776,7 +27826,7 @@ function codexItemEvents(phase, item) {
|
|
|
27776
27826
|
})];
|
|
27777
27827
|
}
|
|
27778
27828
|
case "file_change": {
|
|
27779
|
-
const changes = Array.isArray(item.changes) ? item.changes.map(
|
|
27829
|
+
const changes = Array.isArray(item.changes) ? item.changes.map(record5) : [];
|
|
27780
27830
|
const paths = changes.map((change) => str(change.path)).filter((path) => Boolean(path));
|
|
27781
27831
|
const title = !paths.length ? "\u4FEE\u6539\u6587\u4EF6" : paths.length <= 3 ? paths.join(", ") : `${paths.slice(0, 3).join(", ")} \u7B49 ${paths.length} \u4E2A\u6587\u4EF6`;
|
|
27782
27832
|
return [toolItem(id, {
|
|
@@ -27802,7 +27852,7 @@ function codexItemEvents(phase, item) {
|
|
|
27802
27852
|
})];
|
|
27803
27853
|
}
|
|
27804
27854
|
case "web_search": {
|
|
27805
|
-
const action =
|
|
27855
|
+
const action = record5(item.action);
|
|
27806
27856
|
const query = str(item.query) ?? str(action.query) ?? str(action.url) ?? "";
|
|
27807
27857
|
return [toolItem(id, {
|
|
27808
27858
|
title: query || "web_search",
|
|
@@ -27812,7 +27862,7 @@ function codexItemEvents(phase, item) {
|
|
|
27812
27862
|
})];
|
|
27813
27863
|
}
|
|
27814
27864
|
case "todo_list": {
|
|
27815
|
-
const entries = (Array.isArray(item.items) ? item.items.map(
|
|
27865
|
+
const entries = (Array.isArray(item.items) ? item.items.map(record5) : []).map((entry) => ({
|
|
27816
27866
|
content: clipText(String(entry.text ?? ""), 2e3),
|
|
27817
27867
|
priority: "medium",
|
|
27818
27868
|
status: entry.completed === true ? "completed" : "pending"
|
|
@@ -28108,9 +28158,9 @@ function claudeTranscriptPath(sessionId) {
|
|
|
28108
28158
|
}
|
|
28109
28159
|
function isPromptEntry(entry) {
|
|
28110
28160
|
if (entry.type !== "user" || entry.isSidechain === true || entry.isMeta === true) return false;
|
|
28111
|
-
const content =
|
|
28161
|
+
const content = record6(entry.message).content;
|
|
28112
28162
|
if (typeof content === "string") return content.trim().length > 0;
|
|
28113
|
-
return Array.isArray(content) && content.some((part) =>
|
|
28163
|
+
return Array.isArray(content) && content.some((part) => record6(part).type === "text");
|
|
28114
28164
|
}
|
|
28115
28165
|
function claudeForkBoundary(transcript, keepTurns) {
|
|
28116
28166
|
if (keepTurns <= 0) return void 0;
|
|
@@ -28177,10 +28227,10 @@ var claudeProvider = {
|
|
|
28177
28227
|
// `--resume <id>` for a chat this computer no longer has.
|
|
28178
28228
|
failureRules: [{ kind: "sessionMissing", pattern: /No conversation found with session ID/i }]
|
|
28179
28229
|
};
|
|
28180
|
-
var
|
|
28230
|
+
var record6 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
28181
28231
|
function toolResultText(content) {
|
|
28182
28232
|
if (typeof content === "string") return content;
|
|
28183
|
-
if (Array.isArray(content)) return content.map((part) => str(
|
|
28233
|
+
if (Array.isArray(content)) return content.map((part) => str(record6(part).text) ?? "").filter(Boolean).join("\n");
|
|
28184
28234
|
return "";
|
|
28185
28235
|
}
|
|
28186
28236
|
var CLAUDE_TOOL_KINDS = {
|
|
@@ -28222,7 +28272,7 @@ function claudeToolItem(id, name, input2) {
|
|
|
28222
28272
|
title = path && `Edit ${path}`;
|
|
28223
28273
|
break;
|
|
28224
28274
|
case "MultiEdit":
|
|
28225
|
-
if (path && Array.isArray(input2.edits)) for (const edit of input2.edits.slice(0, 50).map(
|
|
28275
|
+
if (path && Array.isArray(input2.edits)) for (const edit of input2.edits.slice(0, 50).map(record6)) content.push(diff(path, edit.old_string, edit.new_string));
|
|
28226
28276
|
title = path && `Edit ${path}`;
|
|
28227
28277
|
break;
|
|
28228
28278
|
case "Write":
|
|
@@ -28274,7 +28324,7 @@ function claudeToolItem(id, name, input2) {
|
|
|
28274
28324
|
};
|
|
28275
28325
|
}
|
|
28276
28326
|
function claudePlanItem(input2) {
|
|
28277
|
-
const todos = Array.isArray(input2.todos) ? input2.todos.map(
|
|
28327
|
+
const todos = Array.isArray(input2.todos) ? input2.todos.map(record6) : [];
|
|
28278
28328
|
return {
|
|
28279
28329
|
itemId: "plan",
|
|
28280
28330
|
type: "plan",
|
|
@@ -28315,13 +28365,13 @@ function claudeLineParser() {
|
|
|
28315
28365
|
return { ...base, display: [`\u25CF \u4F1A\u8BDD ${sessionId ?? ""}`, runLog.event("\u5F00\u59CB\u5904\u7406")] };
|
|
28316
28366
|
}
|
|
28317
28367
|
case "assistant": {
|
|
28318
|
-
const message =
|
|
28368
|
+
const message = record6(event.message);
|
|
28319
28369
|
const content = message.content ?? [];
|
|
28320
28370
|
const messageId = str(message.id) ?? `message${++unnamedMessages}`;
|
|
28321
28371
|
const rows = [];
|
|
28322
28372
|
const events = [];
|
|
28323
28373
|
for (const value of Array.isArray(content) ? content : []) {
|
|
28324
|
-
const part =
|
|
28374
|
+
const part = record6(value);
|
|
28325
28375
|
const index = blockCounts.get(messageId) ?? 0;
|
|
28326
28376
|
blockCounts.set(messageId, index + 1);
|
|
28327
28377
|
if (part.type === "text") {
|
|
@@ -28342,7 +28392,7 @@ function claudeLineParser() {
|
|
|
28342
28392
|
}
|
|
28343
28393
|
if (part.type !== "tool_use") continue;
|
|
28344
28394
|
const name = str(part.name) ?? "tool";
|
|
28345
|
-
const input2 =
|
|
28395
|
+
const input2 = record6(part.input);
|
|
28346
28396
|
const id = str(part.id) ?? "";
|
|
28347
28397
|
if (id && name === "TodoWrite") {
|
|
28348
28398
|
plans.add(id);
|
|
@@ -28365,11 +28415,11 @@ function claudeLineParser() {
|
|
|
28365
28415
|
return { ...base, display: rows, ...events.length ? { chatEvents: events } : {} };
|
|
28366
28416
|
}
|
|
28367
28417
|
case "user": {
|
|
28368
|
-
const content =
|
|
28418
|
+
const content = record6(event.message).content ?? [];
|
|
28369
28419
|
const rows = [];
|
|
28370
28420
|
const events = [];
|
|
28371
28421
|
for (const value of Array.isArray(content) ? content : []) {
|
|
28372
|
-
const part =
|
|
28422
|
+
const part = record6(value);
|
|
28373
28423
|
if (part.type !== "tool_result") continue;
|
|
28374
28424
|
const id = str(part.tool_use_id) ?? "";
|
|
28375
28425
|
const tool = tools.get(id);
|
|
@@ -28427,8 +28477,8 @@ function toolPath(input2, partial2) {
|
|
|
28427
28477
|
const parsed = input2 && typeof input2 === "object" && Object.keys(input2).length ? input2 : tryJson(partial2) ?? {};
|
|
28428
28478
|
return str(parsed.file_path) ?? str(parsed.notebook_path) ?? str(parsed.path);
|
|
28429
28479
|
}
|
|
28430
|
-
var
|
|
28431
|
-
var textContent = (value) => typeof value === "string" ? value : Array.isArray(value) ? value.map((part) => str(
|
|
28480
|
+
var record7 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
28481
|
+
var textContent = (value) => typeof value === "string" ? value : Array.isArray(value) ? value.map((part) => str(record7(part).text) ?? "").filter(Boolean).join("\n") : JSON.stringify(value ?? "");
|
|
28432
28482
|
function claudeChatProvider(attachments) {
|
|
28433
28483
|
let messageID = "";
|
|
28434
28484
|
let messageSequence = 0;
|
|
@@ -28458,14 +28508,14 @@ function claudeChatProvider(attachments) {
|
|
|
28458
28508
|
const events = [];
|
|
28459
28509
|
if (envelope.parent_tool_use_id) return { ...base, display: [] };
|
|
28460
28510
|
if (envelope.type === "stream_event") {
|
|
28461
|
-
const event =
|
|
28511
|
+
const event = record7(envelope.event);
|
|
28462
28512
|
const index = Number(event.index ?? 0);
|
|
28463
28513
|
if (event.type === "message_start") {
|
|
28464
|
-
messageID = str(
|
|
28514
|
+
messageID = str(record7(event.message).id) ?? `message:${++messageSequence}`;
|
|
28465
28515
|
blocks.clear();
|
|
28466
28516
|
} else if (event.type === "content_block_start") {
|
|
28467
28517
|
if (!messageID) messageID = `message:${++messageSequence}`;
|
|
28468
|
-
const part =
|
|
28518
|
+
const part = record7(event.content_block);
|
|
28469
28519
|
const type = part.type === "tool_use" ? "tool_call" : part.type === "thinking" ? "thought" : "text";
|
|
28470
28520
|
if (!["tool_use", "thinking", "text"].includes(String(part.type))) return { ...base, display: [] };
|
|
28471
28521
|
const block = { id: type === "tool_call" ? str(part.id) ?? `${messageID}:${index}` : `${messageID}:${index}`, type, name: str(part.name) ?? "tool", text: String(part.text ?? part.thinking ?? ""), input: part.input ?? {}, partialInput: "" };
|
|
@@ -28474,7 +28524,7 @@ function claudeChatProvider(attachments) {
|
|
|
28474
28524
|
events.push(asItem(block, "in_progress"));
|
|
28475
28525
|
} else if (event.type === "content_block_delta") {
|
|
28476
28526
|
const block = blocks.get(index);
|
|
28477
|
-
const delta =
|
|
28527
|
+
const delta = record7(event.delta);
|
|
28478
28528
|
if (!block) return { ...base, display: [] };
|
|
28479
28529
|
if (delta.type === "text_delta" || delta.type === "thinking_delta") {
|
|
28480
28530
|
const text3 = String(delta.text ?? delta.thinking ?? "");
|
|
@@ -28491,11 +28541,11 @@ function claudeChatProvider(attachments) {
|
|
|
28491
28541
|
if (block && block.type !== "tool_call") events.push(asItem(block, "completed"));
|
|
28492
28542
|
}
|
|
28493
28543
|
} else if (envelope.type === "assistant") {
|
|
28494
|
-
const message =
|
|
28544
|
+
const message = record7(envelope.message);
|
|
28495
28545
|
const id = str(message.id) || messageID || `message:${++messageSequence}`;
|
|
28496
28546
|
const parts = Array.isArray(message.content) ? message.content : [];
|
|
28497
28547
|
parts.forEach((value, index) => {
|
|
28498
|
-
const part =
|
|
28548
|
+
const part = record7(value);
|
|
28499
28549
|
if (!["text", "thinking", "tool_use"].includes(String(part.type))) return;
|
|
28500
28550
|
const type = part.type === "tool_use" ? "tool_call" : part.type === "thinking" ? "thought" : "text";
|
|
28501
28551
|
const block = { id: type === "tool_call" ? str(part.id) ?? `${id}:${index}` : `${id}:${index}`, type, name: str(part.name) ?? "tool", text: String(part.text ?? part.thinking ?? ""), input: part.input ?? {}, partialInput: "" };
|
|
@@ -28504,9 +28554,9 @@ function claudeChatProvider(attachments) {
|
|
|
28504
28554
|
events.push(asItem(block, type === "tool_call" ? "in_progress" : "completed"));
|
|
28505
28555
|
});
|
|
28506
28556
|
} else if (envelope.type === "user") {
|
|
28507
|
-
const message =
|
|
28557
|
+
const message = record7(envelope.message);
|
|
28508
28558
|
for (const value of Array.isArray(message.content) ? message.content : []) {
|
|
28509
|
-
const part =
|
|
28559
|
+
const part = record7(value);
|
|
28510
28560
|
if (part.type !== "tool_result") continue;
|
|
28511
28561
|
const id = str(part.tool_use_id);
|
|
28512
28562
|
if (!id) continue;
|
|
@@ -28557,7 +28607,7 @@ var ECHO_CALLBACK = /echo_report_task_progress/;
|
|
|
28557
28607
|
var PROTOCOL_VERSION2 = 1;
|
|
28558
28608
|
var READ_ONLY_KINDS = /* @__PURE__ */ new Set(["read", "search", "think"]);
|
|
28559
28609
|
var EDIT_KINDS = /* @__PURE__ */ new Set(["edit", "delete", "move"]);
|
|
28560
|
-
var
|
|
28610
|
+
var record8 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
28561
28611
|
function acpErrorText(error62, dialect) {
|
|
28562
28612
|
const message = str(error62?.message) ?? "ACP \u8BF7\u6C42\u5931\u8D25";
|
|
28563
28613
|
const data = error62?.data;
|
|
@@ -28568,8 +28618,8 @@ function acpErrorText(error62, dialect) {
|
|
|
28568
28618
|
function contentText(content) {
|
|
28569
28619
|
if (!Array.isArray(content)) return "";
|
|
28570
28620
|
return content.map((item) => {
|
|
28571
|
-
const part =
|
|
28572
|
-
const inner =
|
|
28621
|
+
const part = record8(item);
|
|
28622
|
+
const inner = record8(part.content);
|
|
28573
28623
|
return str(inner.text) ?? str(part.text) ?? "";
|
|
28574
28624
|
}).filter(Boolean).join("\n");
|
|
28575
28625
|
}
|
|
@@ -28593,14 +28643,14 @@ function rawStdout(rawOutput) {
|
|
|
28593
28643
|
return found.join("\n");
|
|
28594
28644
|
}
|
|
28595
28645
|
function permissionAllowed(params, request) {
|
|
28596
|
-
const call =
|
|
28646
|
+
const call = record8(params.toolCall);
|
|
28597
28647
|
const title = str(call.title) ?? "";
|
|
28598
28648
|
const kind = str(call.kind) ?? "";
|
|
28599
28649
|
const level = accessLevel(request);
|
|
28600
28650
|
return level === "bypassPermissions" || READ_ONLY_KINDS.has(kind) || level !== "restricted" && kind === "fetch" || level === "acceptEdits" && EDIT_KINDS.has(kind) || ECHO_CALLBACK.test(title);
|
|
28601
28651
|
}
|
|
28602
28652
|
function permissionOutcome(params, request) {
|
|
28603
|
-
const options = Array.isArray(params.options) ? params.options.map(
|
|
28653
|
+
const options = Array.isArray(params.options) ? params.options.map(record8) : [];
|
|
28604
28654
|
const kind = permissionAllowed(params, request) ? "allow_once" : "reject_once";
|
|
28605
28655
|
const option2 = options.find((item) => str(item.kind) === kind);
|
|
28606
28656
|
return option2 ? { outcome: { outcome: "selected", optionId: option2.optionId } } : { outcome: { outcome: "cancelled" } };
|
|
@@ -28730,7 +28780,7 @@ function createAcpProvider(row) {
|
|
|
28730
28780
|
const phase = typeof message.id === "number" ? phases.get(message.id) : void 0;
|
|
28731
28781
|
if (!phase) return { display: [] };
|
|
28732
28782
|
phases.delete(message.id);
|
|
28733
|
-
const result =
|
|
28783
|
+
const result = record8(message.result);
|
|
28734
28784
|
if (phase === "open") {
|
|
28735
28785
|
if (message.error) return onOpenError(message);
|
|
28736
28786
|
loading = false;
|
|
@@ -28777,8 +28827,8 @@ function createAcpProvider(row) {
|
|
|
28777
28827
|
const onToolCall = (update2) => {
|
|
28778
28828
|
const id = str(update2.toolCallId) ?? "";
|
|
28779
28829
|
const known = tools.get(id);
|
|
28780
|
-
const input2 =
|
|
28781
|
-
const locations = Array.isArray(update2.locations) ? update2.locations.map(
|
|
28830
|
+
const input2 = record8(update2.rawInput);
|
|
28831
|
+
const locations = Array.isArray(update2.locations) ? update2.locations.map(record8) : [];
|
|
28782
28832
|
const tool = known ?? { kind: "other", title: "tool" };
|
|
28783
28833
|
tool.kind = str(update2.kind) ?? tool.kind;
|
|
28784
28834
|
if (!known) tool.title = str(update2.title) ?? tool.title;
|
|
@@ -28823,7 +28873,7 @@ function createAcpProvider(row) {
|
|
|
28823
28873
|
return first;
|
|
28824
28874
|
};
|
|
28825
28875
|
const onUpdate = (params) => {
|
|
28826
|
-
const raw =
|
|
28876
|
+
const raw = record8(params.update);
|
|
28827
28877
|
const kind = str(raw.sessionUpdate);
|
|
28828
28878
|
const update2 = (kind === "tool_call" || kind === "tool_call_update") && dialect.normalizeToolUpdate ? dialect.normalizeToolUpdate(raw) : raw;
|
|
28829
28879
|
if (loading) {
|
|
@@ -28831,7 +28881,7 @@ function createAcpProvider(row) {
|
|
|
28831
28881
|
return withItems({ display: [] });
|
|
28832
28882
|
}
|
|
28833
28883
|
transcript.update(update2);
|
|
28834
|
-
const text3 = str(
|
|
28884
|
+
const text3 = str(record8(update2.content).text);
|
|
28835
28885
|
switch (kind) {
|
|
28836
28886
|
case "agent_message_chunk": {
|
|
28837
28887
|
if (!text3) return withItems({ display: [] });
|
|
@@ -28854,7 +28904,7 @@ function createAcpProvider(row) {
|
|
|
28854
28904
|
}
|
|
28855
28905
|
};
|
|
28856
28906
|
const onRequest = (message) => {
|
|
28857
|
-
const params =
|
|
28907
|
+
const params = record8(message.params);
|
|
28858
28908
|
if (message.method === "session/request_permission") {
|
|
28859
28909
|
answer(message.id, permissionOutcome(params, request));
|
|
28860
28910
|
return { display: [] };
|
|
@@ -28894,7 +28944,7 @@ function createAcpProvider(row) {
|
|
|
28894
28944
|
if (finished && message.id === void 0) return { display: [] };
|
|
28895
28945
|
if (message.method && message.id !== void 0) return onRequest(message);
|
|
28896
28946
|
if (message.method) {
|
|
28897
|
-
const params =
|
|
28947
|
+
const params = record8(message.params);
|
|
28898
28948
|
if (message.method === "session/update") return onUpdate(params);
|
|
28899
28949
|
const rows = dialect.notification?.(message.method, params);
|
|
28900
28950
|
return { display: rows ?? [] };
|
|
@@ -29917,7 +29967,7 @@ var RunTranscript = class _RunTranscript {
|
|
|
29917
29967
|
* that ended before the run did: it reads as `lost`.
|
|
29918
29968
|
*/
|
|
29919
29969
|
static fromFile(value) {
|
|
29920
|
-
const data =
|
|
29970
|
+
const data = record9(value);
|
|
29921
29971
|
if (data.v !== 1 || typeof data.run_id !== "string" || !data.run_id || !Array.isArray(data.items) || !Array.isArray(data.lines)) return void 0;
|
|
29922
29972
|
const transcript = new _RunTranscript({
|
|
29923
29973
|
runId: data.run_id,
|
|
@@ -29933,7 +29983,7 @@ var RunTranscript = class _RunTranscript {
|
|
|
29933
29983
|
transcript.revision = whole(data.revision);
|
|
29934
29984
|
transcript.itemRevisions = false;
|
|
29935
29985
|
for (const value2 of data.items) {
|
|
29936
|
-
const item =
|
|
29986
|
+
const item = record9(value2);
|
|
29937
29987
|
if (typeof item.itemId !== "string" || !item.itemId || transcript.positions.has(item.itemId)) continue;
|
|
29938
29988
|
transcript.positions.set(item.itemId, transcript.entries.length);
|
|
29939
29989
|
transcript.entries.push({ rev: 0, item });
|
|
@@ -30174,7 +30224,7 @@ function whole(value) {
|
|
|
30174
30224
|
function finite(value) {
|
|
30175
30225
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
30176
30226
|
}
|
|
30177
|
-
function
|
|
30227
|
+
function record9(value) {
|
|
30178
30228
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
30179
30229
|
}
|
|
30180
30230
|
function errorCode(error62) {
|
|
@@ -30789,6 +30839,10 @@ var AcpChatSession = class {
|
|
|
30789
30839
|
const session = await this.ensureSession(turn, connection);
|
|
30790
30840
|
if (turn.cancelRequested) return this.cancelled(turn);
|
|
30791
30841
|
sink.started(connection.process.pid, session.sessionId);
|
|
30842
|
+
if (request.command) {
|
|
30843
|
+
const commands = await connection.commands(session.sessionId);
|
|
30844
|
+
if (!commands.some((item) => item.name === request.command.name)) throw new Error("CLI \u5F53\u524D\u6CA1\u6709\u63D0\u4F9B\u8FD9\u4E2A\u547D\u4EE4\uFF0C\u8BF7\u5237\u65B0\u547D\u4EE4\u5217\u8868\u540E\u91CD\u8BD5\u3002");
|
|
30845
|
+
}
|
|
30792
30846
|
await this.applySettings(turn, connection, session);
|
|
30793
30847
|
if (turn.cancelRequested) return this.cancelled(turn);
|
|
30794
30848
|
let blocks = await this.promptBlocks(request, connection);
|
|
@@ -30966,17 +31020,17 @@ var AcpChatSession = class {
|
|
|
30966
31020
|
const options = permissionOptions(params.options);
|
|
30967
31021
|
if (prompts && options.length && this.forwardsPermission(params, prompts)) {
|
|
30968
31022
|
const requestId = randomUUID3();
|
|
30969
|
-
const call =
|
|
31023
|
+
const call = record4(params.toolCall);
|
|
30970
31024
|
const toolCall = typeof call.toolCallId === "string" && call.toolCallId ? call : { ...call, toolCallId: `permission:${requestId}` };
|
|
30971
|
-
const meta3 =
|
|
31025
|
+
const meta3 = record4(params._meta);
|
|
30972
31026
|
return this.ask(turn, requestId, toolCall, options, Object.keys(meta3).length ? meta3 : void 0, signal2).then((outcome2) => ({ outcome: outcome2 }));
|
|
30973
31027
|
}
|
|
30974
31028
|
const access = turn.request.access;
|
|
30975
31029
|
const outcome = permissionOutcome(params, access === "restricted" ? { permissionMode: "restricted" } : { permissionMode: "full", access: access === "default" ? "read-only" : access });
|
|
30976
|
-
const selected =
|
|
30977
|
-
const option2 = Array.isArray(params.options) ? params.options.map(
|
|
31030
|
+
const selected = record4(record4(outcome).outcome);
|
|
31031
|
+
const option2 = Array.isArray(params.options) ? params.options.map(record4).find((item) => item.optionId === selected.optionId) : void 0;
|
|
30978
31032
|
if (typeof option2?.kind === "string" && option2.kind.startsWith("reject")) {
|
|
30979
|
-
const call =
|
|
31033
|
+
const call = record4(params.toolCall);
|
|
30980
31034
|
turn.transcript.note(`\u5DF2\u62D2\u7EDD\uFF1A${typeof call.title === "string" ? call.title : "\u5DE5\u5177\u8C03\u7528"}\uFF08\u5F53\u524D\u6743\u9650\u4E0D\u5141\u8BB8\uFF09`);
|
|
30981
31035
|
}
|
|
30982
31036
|
return outcome;
|
|
@@ -30989,7 +31043,7 @@ var AcpChatSession = class {
|
|
|
30989
31043
|
forwardsPermission(params, prompts) {
|
|
30990
31044
|
if (isAskUserQuestionPermission(params)) return true;
|
|
30991
31045
|
if (prompts.permissions === "none") return false;
|
|
30992
|
-
const title =
|
|
31046
|
+
const title = record4(params.toolCall).title;
|
|
30993
31047
|
if (ECHO_CALLBACK.test(typeof title === "string" ? title : "")) return false;
|
|
30994
31048
|
if (prompts.permissions === "all") return true;
|
|
30995
31049
|
return !permissionAllowed(params, { permissionMode: "full", access: "acceptEdits" });
|
|
@@ -31145,7 +31199,7 @@ function isArchivedSessionError(error62) {
|
|
|
31145
31199
|
}
|
|
31146
31200
|
function permissionOptions(value) {
|
|
31147
31201
|
if (!Array.isArray(value)) return [];
|
|
31148
|
-
return value.map(
|
|
31202
|
+
return value.map(record4).flatMap((option2) => typeof option2.optionId === "string" && option2.optionId ? [{ optionId: option2.optionId, name: typeof option2.name === "string" ? option2.name : option2.optionId, kind: typeof option2.kind === "string" ? option2.kind : "" }] : []);
|
|
31149
31203
|
}
|
|
31150
31204
|
|
|
31151
31205
|
// src/acp/chat-host.ts
|
|
@@ -31387,6 +31441,34 @@ async function handleMemoryProviderRequest(input2, registry2 = providers) {
|
|
|
31387
31441
|
}
|
|
31388
31442
|
}
|
|
31389
31443
|
|
|
31444
|
+
// src/acp/command-catalog.ts
|
|
31445
|
+
async function readCLICommands(spec, launch, cwd, clientVersion) {
|
|
31446
|
+
const connection = await AcpConnection.open(launch.launch, {
|
|
31447
|
+
update: () => {
|
|
31448
|
+
},
|
|
31449
|
+
permission: () => ({ outcome: { outcome: "cancelled" } }),
|
|
31450
|
+
notification: () => {
|
|
31451
|
+
},
|
|
31452
|
+
stderr: () => {
|
|
31453
|
+
}
|
|
31454
|
+
}, clientVersion);
|
|
31455
|
+
let sessionId = "";
|
|
31456
|
+
try {
|
|
31457
|
+
const auth = spec.authMethod ? { pick: spec.authMethod, env: launch.launch.env ?? {} } : void 0;
|
|
31458
|
+
const session = await connection.newSession(cwd, auth);
|
|
31459
|
+
sessionId = session.sessionId;
|
|
31460
|
+
return await connection.commands(sessionId);
|
|
31461
|
+
} finally {
|
|
31462
|
+
if (sessionId && connection.deleteSession) {
|
|
31463
|
+
try {
|
|
31464
|
+
await connection.removeSession(sessionId);
|
|
31465
|
+
} catch {
|
|
31466
|
+
}
|
|
31467
|
+
}
|
|
31468
|
+
await connection.dispose();
|
|
31469
|
+
}
|
|
31470
|
+
}
|
|
31471
|
+
|
|
31390
31472
|
// src/runs/run-supervisor.ts
|
|
31391
31473
|
var COMPLETION_EXIT_GRACE_MS = 15e3;
|
|
31392
31474
|
var EXIT_OUTPUT_GRACE_MS = 2e3;
|
|
@@ -31553,6 +31635,14 @@ var RunSupervisor = class {
|
|
|
31553
31635
|
this.preparing.delete(payload.run_id);
|
|
31554
31636
|
}
|
|
31555
31637
|
}
|
|
31638
|
+
async listCLICommands(input2) {
|
|
31639
|
+
const spec = acpChatSpec(input2.agent_type);
|
|
31640
|
+
if (!spec) throw new Error("\u6B64\u8BBE\u5907\u4E0A\u7684 CLI \u6682\u4E0D\u652F\u6301\u547D\u4EE4\u67E5\u8BE2\uFF0C\u8BF7\u5347\u7EA7\u8BBE\u5907\u4EE3\u7406\u3002");
|
|
31641
|
+
const workdir = input2.workdir ? await this.validateWorkdir(input2.workdir) : await this.defaultChatWorkdir();
|
|
31642
|
+
const prepared = await this.acpChats.prepare(spec, { access: "read-only", workdir, model: input2.model ?? "", reasoningEffort: input2.reasoning_effort ?? "" });
|
|
31643
|
+
const items = await readCLICommands(spec, prepared, workdir, agentPackageVersion());
|
|
31644
|
+
return { agent_type: input2.agent_type, items };
|
|
31645
|
+
}
|
|
31556
31646
|
async startPrepared(payload, signal2) {
|
|
31557
31647
|
if (this.active.has(payload.run_id) || this.acpRuns.has(payload.run_id) || this.recent.has(payload.run_id)) {
|
|
31558
31648
|
this.logger.info("run-duplicate-ignored", { runId: payload.run_id });
|
|
@@ -31568,6 +31658,7 @@ var RunSupervisor = class {
|
|
|
31568
31658
|
this.remember({ runId: payload.run_id, sessionKey, tail: new TerminalTailBuffer(), transcript, finishedAt: Date.now(), status: "failed", chat: !!payload.chat_session_id });
|
|
31569
31659
|
await this.report(payload.run_id, { status: "failed", error: failure2.message, failure_kind: failure2.kind, duration_ms: 0 });
|
|
31570
31660
|
};
|
|
31661
|
+
if (payload.cli_command && !payload.chat_session_id) return refuse("\u539F\u751F\u547D\u4EE4\u9700\u8981 ACP \u4F1A\u8BDD\uFF0C\u4E0D\u80FD\u901A\u8FC7\u666E\u901A\u6D88\u606F\u9A71\u52A8\u6267\u884C\u3002");
|
|
31571
31662
|
if (this.sessionBusy(sessionKey, payload.run_id)) {
|
|
31572
31663
|
return refuse("\u672C\u673A\u8BE5\u4F1A\u8BDD\u5DF2\u6709\u4EFB\u52A1\u5728\u8FD0\u884C");
|
|
31573
31664
|
}
|
|
@@ -31609,7 +31700,7 @@ var RunSupervisor = class {
|
|
|
31609
31700
|
}
|
|
31610
31701
|
return refuse(`\u9644\u4EF6\u4E0B\u8F7D\u5931\u8D25\uFF1A${errorMessage2(error62)}`);
|
|
31611
31702
|
}
|
|
31612
|
-
const prompt = turn.planPrompt ? `${payload.prompt}
|
|
31703
|
+
const prompt = payload.cli_command ? `/${payload.cli_command.name}${payload.cli_command.arguments ? " " + payload.cli_command.arguments : ""}` : turn.planPrompt ? `${payload.prompt}
|
|
31613
31704
|
|
|
31614
31705
|
${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
31615
31706
|
const request = {
|
|
@@ -31623,6 +31714,7 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
31623
31714
|
};
|
|
31624
31715
|
if (payload.chat_session_id) {
|
|
31625
31716
|
const acpSpec = acpChatSpec(cli.id);
|
|
31717
|
+
if (payload.cli_command && !acpSpec) return refuse("\u6B64\u8BBE\u5907\u65E0\u6CD5\u6267\u884C\u539F\u751F\u547D\u4EE4\uFF0C\u8BF7\u5347\u7EA7\u8BBE\u5907\u4EE3\u7406\u3002");
|
|
31626
31718
|
if (acpSpec) {
|
|
31627
31719
|
const outcome = await this.startAcpChat(payload, { spec: acpSpec, cli, sessionKey, workdir, prompt, turn, permissionMode, memoryEnv, signal: signal2, refuse, transcript });
|
|
31628
31720
|
if (outcome === "handled") return;
|
|
@@ -31922,7 +32014,7 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
31922
32014
|
await refuse(cliFailure("cliMissing", { label: cli.label, ...cli.installHint ? { installHint: cli.installHint } : {} }));
|
|
31923
32015
|
return "handled";
|
|
31924
32016
|
}
|
|
31925
|
-
if (cli.chat) return { fallback: `${error62.message}\uFF0C\u672C\u8F6E\u6539\u7528\u65E7\u7248\u804A\u5929\u9A71\u52A8` };
|
|
32017
|
+
if (cli.chat && !payload.cli_command) return { fallback: `${error62.message}\uFF0C\u672C\u8F6E\u6539\u7528\u65E7\u7248\u804A\u5929\u9A71\u52A8` };
|
|
31926
32018
|
await refuse({ kind: "startFailed", message: error62.message });
|
|
31927
32019
|
return "handled";
|
|
31928
32020
|
}
|
|
@@ -31954,6 +32046,7 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
31954
32046
|
let reported = { pid: 0, sessionId: "" };
|
|
31955
32047
|
const result = await this.acpChats.run(sessionKey, spec, {
|
|
31956
32048
|
runId,
|
|
32049
|
+
...payload.cli_command ? { command: payload.cli_command } : {},
|
|
31957
32050
|
prompt: context.prompt,
|
|
31958
32051
|
attachments,
|
|
31959
32052
|
sessionId: payload.session_id,
|
|
@@ -31964,7 +32057,7 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
31964
32057
|
fast: turn.fast,
|
|
31965
32058
|
workdir,
|
|
31966
32059
|
notes,
|
|
31967
|
-
...turn.prompts ? { prompts: turn.prompts } : {}
|
|
32060
|
+
...turn.prompts && (!payload.cli_command || payload.cli_command_interactive) ? { prompts: turn.prompts } : {}
|
|
31968
32061
|
}, {
|
|
31969
32062
|
events: (events) => {
|
|
31970
32063
|
forwarder.push(events);
|
|
@@ -31982,6 +32075,11 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
31982
32075
|
});
|
|
31983
32076
|
}
|
|
31984
32077
|
}, launch);
|
|
32078
|
+
if (payload.cli_command && !payload.cli_command_interactive) {
|
|
32079
|
+
await this.acpChats.closeSession(sessionKey).catch((error62) => {
|
|
32080
|
+
this.logger.warn("command-process-close-failed", { runId, error: errorMessage2(error62) });
|
|
32081
|
+
});
|
|
32082
|
+
}
|
|
31985
32083
|
await forwarder.drain();
|
|
31986
32084
|
this.acpRuns.delete(runId);
|
|
31987
32085
|
const durationMs = Date.now() - run2.startedAt;
|
|
@@ -33170,8 +33268,8 @@ var OrphanRegistry = class {
|
|
|
33170
33268
|
file;
|
|
33171
33269
|
records = /* @__PURE__ */ new Map();
|
|
33172
33270
|
writing = Promise.resolve();
|
|
33173
|
-
add(
|
|
33174
|
-
this.records.set(
|
|
33271
|
+
add(record10) {
|
|
33272
|
+
this.records.set(record10.runId, record10);
|
|
33175
33273
|
this.persist();
|
|
33176
33274
|
}
|
|
33177
33275
|
remove(runId) {
|
|
@@ -33195,12 +33293,12 @@ var OrphanRegistry = class {
|
|
|
33195
33293
|
return [];
|
|
33196
33294
|
}
|
|
33197
33295
|
const reaped = [];
|
|
33198
|
-
for (const
|
|
33199
|
-
if (!
|
|
33200
|
-
const command = await commandOf(
|
|
33201
|
-
if (command && command.includes(basename3(
|
|
33202
|
-
await killProcessTree(
|
|
33203
|
-
reaped.push(
|
|
33296
|
+
for (const record10 of previous) {
|
|
33297
|
+
if (!record10 || typeof record10.pid !== "number" || record10.pid <= 1) continue;
|
|
33298
|
+
const command = await commandOf(record10.pid);
|
|
33299
|
+
if (command && command.includes(basename3(record10.executable))) {
|
|
33300
|
+
await killProcessTree(record10.pid);
|
|
33301
|
+
reaped.push(record10);
|
|
33204
33302
|
}
|
|
33205
33303
|
}
|
|
33206
33304
|
this.records.clear();
|
|
@@ -33617,6 +33715,8 @@ var RunStartPayloadSchema = external_exports.object({
|
|
|
33617
33715
|
task_chain_id: external_exports.string().optional().default(""),
|
|
33618
33716
|
message_id: external_exports.string().optional().default(""),
|
|
33619
33717
|
prompt: external_exports.string().max(512 * 1024),
|
|
33718
|
+
cli_command: external_exports.object({ name: external_exports.string().min(1).max(200), arguments: external_exports.string().max(64 * 1024).optional().default("") }).optional(),
|
|
33719
|
+
cli_command_interactive: external_exports.boolean().optional(),
|
|
33620
33720
|
chat_session_id: external_exports.string().max(64).optional(),
|
|
33621
33721
|
attachments: external_exports.array(external_exports.object({ media_id: external_exports.string().min(1).max(64), name: external_exports.string().max(200), kind: external_exports.enum(["image", "file"]) })).max(16).optional(),
|
|
33622
33722
|
task_attachments: external_exports.array(external_exports.object({ file_id: external_exports.uuid(), name: external_exports.string().min(1).max(255), mime: external_exports.string().max(255), size: external_exports.number().int().positive(), sha256: external_exports.string().regex(/^[a-f0-9]{64}$/), prompt_token: external_exports.string().max(100) })).max(16).nullish(),
|
|
@@ -33960,6 +34060,7 @@ var AgentRuntime = class {
|
|
|
33960
34060
|
task_attachments: { version: 1 },
|
|
33961
34061
|
// `run.transcript`: any run's structured items and run-log rows, kept on this device after the run.
|
|
33962
34062
|
run_transcripts: { version: 1 },
|
|
34063
|
+
cli_commands: { version: 1 },
|
|
33963
34064
|
// `memory.provider` commands and the `memory` field of run payloads (Lody's memoryProviders v1).
|
|
33964
34065
|
memory_providers: { version: 1, providers: [...MEMORY_PROVIDER_IDS] },
|
|
33965
34066
|
cli_execution_policy: { version: 1, modes: ["restricted", "full"] },
|
|
@@ -34087,6 +34188,16 @@ var AgentRuntime = class {
|
|
|
34087
34188
|
if (!this.catalogReport) return { success: false, error: "\u8BFB\u53D6\u6A21\u578B\u76EE\u5F55\u5931\u8D25" };
|
|
34088
34189
|
return { success: true, result: this.catalogReport };
|
|
34089
34190
|
}
|
|
34191
|
+
case "cli.commands": {
|
|
34192
|
+
const value = command.payload;
|
|
34193
|
+
if (!value || typeof value.agent_type !== "string") return { success: false, error: "CLI \u7C7B\u578B\u65E0\u6548" };
|
|
34194
|
+
return { success: true, result: await this.runs.listCLICommands({
|
|
34195
|
+
agent_type: value.agent_type,
|
|
34196
|
+
...typeof value.workdir === "string" ? { workdir: value.workdir } : {},
|
|
34197
|
+
...typeof value.model === "string" ? { model: value.model } : {},
|
|
34198
|
+
...typeof value.reasoning_effort === "string" ? { reasoning_effort: value.reasoning_effort } : {}
|
|
34199
|
+
}) };
|
|
34200
|
+
}
|
|
34090
34201
|
case "cli.quota": {
|
|
34091
34202
|
const payload = CliQuotaPayloadSchema.parse(command.payload ?? {});
|
|
34092
34203
|
try {
|
|
@@ -34554,19 +34665,19 @@ async function smoke(args) {
|
|
|
34554
34665
|
const only = [];
|
|
34555
34666
|
let full = false;
|
|
34556
34667
|
let json2 = false;
|
|
34557
|
-
let
|
|
34668
|
+
let record10;
|
|
34558
34669
|
let timeout;
|
|
34559
34670
|
for (let index = 0; index < args.length; index++) {
|
|
34560
34671
|
const arg = args[index];
|
|
34561
34672
|
if (arg === "--full") full = true;
|
|
34562
34673
|
else if (arg === "--json") json2 = true;
|
|
34563
|
-
else if (arg === "--record")
|
|
34674
|
+
else if (arg === "--record") record10 = resolve9(args[++index] ?? "recordings");
|
|
34564
34675
|
else if (arg === "--timeout") timeout = Number(args[++index]) || void 0;
|
|
34565
34676
|
else if (arg !== "--smoke") only.push(arg);
|
|
34566
34677
|
}
|
|
34567
34678
|
const hydration = await hydrateShellPath({ force: true });
|
|
34568
34679
|
if (hydration.ok) mergePathSegments(hydration.segments);
|
|
34569
|
-
const results = await runCliSmoke({ only, full, ...
|
|
34680
|
+
const results = await runCliSmoke({ only, full, ...record10 ? { record: record10 } : {}, ...timeout ? { timeoutSeconds: timeout } : {}, ...json2 ? {} : { log: (line) => process.stdout.write(`${line}
|
|
34570
34681
|
`) } });
|
|
34571
34682
|
if (json2) process.stdout.write(`${JSON.stringify(results, null, 2)}
|
|
34572
34683
|
`);
|