toc-ocra 0.3.12 → 0.3.14
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/service/agent.mjs
CHANGED
|
@@ -16669,8 +16669,8 @@ function rewriteKeyNames(ctx) {
|
|
|
16669
16669
|
bySchema.set(entry.schema, entry);
|
|
16670
16670
|
}
|
|
16671
16671
|
const rewrites = /* @__PURE__ */ new Map();
|
|
16672
|
-
for (const
|
|
16673
|
-
const seen = ctx.seen.get(
|
|
16672
|
+
for (const record10 of pendingRecords.get(ctx) ?? []) {
|
|
16673
|
+
const seen = ctx.seen.get(record10);
|
|
16674
16674
|
const names = (seen?.def ?? seen?.schema)?.propertyNames;
|
|
16675
16675
|
if (!names || names === true || rewrites.has(names))
|
|
16676
16676
|
continue;
|
|
@@ -22905,12 +22905,24 @@ function rpcErrorText(error62) {
|
|
|
22905
22905
|
return /^internal error$/i.test(error62.message) ? detail : `${error62.message}: ${detail}`;
|
|
22906
22906
|
}
|
|
22907
22907
|
|
|
22908
|
+
// src/acp/cli-command.ts
|
|
22909
|
+
var record3 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
22910
|
+
function cliCommands(value) {
|
|
22911
|
+
if (!Array.isArray(value)) return void 0;
|
|
22912
|
+
return value.map(record3).filter((item) => typeof item.name === "string" && item.name.length > 0).map((item) => ({
|
|
22913
|
+
name: item.name,
|
|
22914
|
+
...typeof item.description === "string" ? { description: item.description } : {},
|
|
22915
|
+
..."input" in item ? { input: item.input } : {},
|
|
22916
|
+
..."_meta" in item ? { _meta: item._meta } : {}
|
|
22917
|
+
}));
|
|
22918
|
+
}
|
|
22919
|
+
|
|
22908
22920
|
// src/acp/connection.ts
|
|
22909
22921
|
var PROTOCOL_VERSION = 1;
|
|
22910
22922
|
var INITIALIZE_TIMEOUT_MS = 12e4;
|
|
22911
22923
|
var SESSION_OPEN_TIMEOUT_MS = 18e4;
|
|
22912
22924
|
var EXT_REQUEST_TIMEOUT_MS = 6e4;
|
|
22913
|
-
var
|
|
22925
|
+
var record4 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
22914
22926
|
var text2 = (value) => typeof value === "string" && value ? value : void 0;
|
|
22915
22927
|
var AcpConnection = class _AcpConnection {
|
|
22916
22928
|
constructor(launch, hooks, elicitation) {
|
|
@@ -22919,8 +22931,8 @@ var AcpConnection = class _AcpConnection {
|
|
|
22919
22931
|
let peer;
|
|
22920
22932
|
this.process = AgentProcess.spawn(launch, (line) => peer?.receive(line), (line) => hooks.stderr(line));
|
|
22921
22933
|
peer = new JsonRpcPeer((line) => this.process.write(line), {
|
|
22922
|
-
request: async (method, params, signal2) => this.onRequest(method,
|
|
22923
|
-
notification: (method, params) => this.onNotification(method,
|
|
22934
|
+
request: async (method, params, signal2) => this.onRequest(method, record4(params), signal2),
|
|
22935
|
+
notification: (method, params) => this.onNotification(method, record4(params))
|
|
22924
22936
|
});
|
|
22925
22937
|
this.peer = peer;
|
|
22926
22938
|
this.closed = this.process.exited.then((exit) => {
|
|
@@ -22943,6 +22955,8 @@ var AcpConnection = class _AcpConnection {
|
|
|
22943
22955
|
steering;
|
|
22944
22956
|
initialized = {};
|
|
22945
22957
|
peer;
|
|
22958
|
+
commandLists = /* @__PURE__ */ new Map();
|
|
22959
|
+
commandListeners = /* @__PURE__ */ new Set();
|
|
22946
22960
|
/**
|
|
22947
22961
|
* Starts the agent and completes `initialize`; the process is stopped on
|
|
22948
22962
|
* failure. `elicitation`: advertise form elicitation (Claude's adapter only
|
|
@@ -22952,7 +22966,7 @@ var AcpConnection = class _AcpConnection {
|
|
|
22952
22966
|
const elicitation = options.elicitation === true && hooks.elicitation !== void 0;
|
|
22953
22967
|
const connection = new _AcpConnection(launch, hooks, elicitation);
|
|
22954
22968
|
try {
|
|
22955
|
-
const result =
|
|
22969
|
+
const result = record4(await connection.call("initialize", {
|
|
22956
22970
|
protocolVersion: PROTOCOL_VERSION,
|
|
22957
22971
|
clientCapabilities: {
|
|
22958
22972
|
fs: { readTextFile: false, writeTextFile: false },
|
|
@@ -22973,16 +22987,18 @@ var AcpConnection = class _AcpConnection {
|
|
|
22973
22987
|
}
|
|
22974
22988
|
/** `auth`: the row's sign-in method, tried once when the agent answers `auth_required`. */
|
|
22975
22989
|
async newSession(cwd, auth) {
|
|
22976
|
-
const result =
|
|
22990
|
+
const result = record4(await this.withAuthentication(() => this.call("session/new", { cwd, mcpServers: [] }, SESSION_OPEN_TIMEOUT_MS), auth));
|
|
22977
22991
|
const sessionId = text2(result.sessionId);
|
|
22978
22992
|
if (!sessionId) throw new Error("ACP session/new \u6CA1\u6709\u8FD4\u56DE\u4F1A\u8BDD ID");
|
|
22993
|
+
this.captureCommands(sessionId, result.availableCommands);
|
|
22979
22994
|
return sessionState(sessionId, result);
|
|
22980
22995
|
}
|
|
22981
22996
|
/** Reopens a saved session: `session/load` (replays history) or `session/resume`, as the capabilities allow. */
|
|
22982
22997
|
async openSaved(sessionId, cwd, options = {}) {
|
|
22983
22998
|
const method = acpSessionMethod(this.initialized, sessionId, options.resumePreference);
|
|
22984
22999
|
if (!method || method === "new") throw new Error("ACP agent cannot load or resume this session");
|
|
22985
|
-
const result =
|
|
23000
|
+
const result = record4(await this.withAuthentication(() => this.call(`session/${method}`, { sessionId, cwd, mcpServers: [] }, SESSION_OPEN_TIMEOUT_MS), options.auth));
|
|
23001
|
+
this.captureCommands(sessionId, result.availableCommands);
|
|
22986
23002
|
return sessionState(sessionId, result);
|
|
22987
23003
|
}
|
|
22988
23004
|
/** Removes a session the agent created for a listing; only when `deleteSession`. */
|
|
@@ -22992,9 +23008,41 @@ var AcpConnection = class _AcpConnection {
|
|
|
22992
23008
|
get canOpenSaved() {
|
|
22993
23009
|
return this.loadSession || this.resumeSession;
|
|
22994
23010
|
}
|
|
23011
|
+
async commands(sessionId) {
|
|
23012
|
+
const known = this.commandLists.get(sessionId);
|
|
23013
|
+
if (known) return known;
|
|
23014
|
+
return await new Promise((resolve9, reject) => {
|
|
23015
|
+
const finish = () => {
|
|
23016
|
+
const items = this.commandLists.get(sessionId);
|
|
23017
|
+
if (!items) return;
|
|
23018
|
+
cleanup();
|
|
23019
|
+
resolve9(items);
|
|
23020
|
+
};
|
|
23021
|
+
const cleanup = () => {
|
|
23022
|
+
clearTimeout(timer);
|
|
23023
|
+
this.commandListeners.delete(finish);
|
|
23024
|
+
};
|
|
23025
|
+
const timer = setTimeout(() => {
|
|
23026
|
+
cleanup();
|
|
23027
|
+
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"));
|
|
23028
|
+
}, 8e3);
|
|
23029
|
+
this.commandListeners.add(finish);
|
|
23030
|
+
void this.closed.then((error62) => {
|
|
23031
|
+
cleanup();
|
|
23032
|
+
reject(error62);
|
|
23033
|
+
});
|
|
23034
|
+
finish();
|
|
23035
|
+
});
|
|
23036
|
+
}
|
|
23037
|
+
captureCommands(sessionId, value) {
|
|
23038
|
+
const items = cliCommands(value);
|
|
23039
|
+
if (!items) return;
|
|
23040
|
+
this.commandLists.set(sessionId, items);
|
|
23041
|
+
for (const notify of this.commandListeners) notify();
|
|
23042
|
+
}
|
|
22995
23043
|
/** Resolves with the prompt's `stopReason` once the agent ends the turn. */
|
|
22996
23044
|
async prompt(sessionId, prompt, meta3) {
|
|
22997
|
-
const result =
|
|
23045
|
+
const result = record4(await this.peer.request("session/prompt", { sessionId, prompt, ...meta3 ? { _meta: meta3 } : {} }));
|
|
22998
23046
|
return text2(result.stopReason) ?? "end_turn";
|
|
22999
23047
|
}
|
|
23000
23048
|
cancel(sessionId) {
|
|
@@ -23006,7 +23054,7 @@ var AcpConnection = class _AcpConnection {
|
|
|
23006
23054
|
}
|
|
23007
23055
|
/** `_lody/session/steer`: `injected` means the agent took the prompt into the running turn. */
|
|
23008
23056
|
async steer(sessionId, prompt, steerId) {
|
|
23009
|
-
const result =
|
|
23057
|
+
const result = record4(await this.peer.request("_lody/session/steer", { sessionId, prompt, steerId }));
|
|
23010
23058
|
return result.outcome === "injected" ? "injected" : "failed";
|
|
23011
23059
|
}
|
|
23012
23060
|
/** An adapter extension request (`_session/archive`, `_session/unarchive`, …) with a time limit. */
|
|
@@ -23037,14 +23085,14 @@ var AcpConnection = class _AcpConnection {
|
|
|
23037
23085
|
);
|
|
23038
23086
|
}
|
|
23039
23087
|
readCapabilities(result) {
|
|
23040
|
-
const capabilities =
|
|
23088
|
+
const capabilities = record4(result.agentCapabilities);
|
|
23041
23089
|
this.initialized = result;
|
|
23042
|
-
this.agentName = text2(
|
|
23090
|
+
this.agentName = text2(record4(result.agentInfo).name) ?? "";
|
|
23043
23091
|
this.loadSession = capabilities.loadSession === true;
|
|
23044
|
-
this.resumeSession =
|
|
23045
|
-
this.deleteSession =
|
|
23046
|
-
this.imagePrompts =
|
|
23047
|
-
const steering =
|
|
23092
|
+
this.resumeSession = record4(capabilities.sessionCapabilities).resume != null;
|
|
23093
|
+
this.deleteSession = record4(capabilities.sessionCapabilities).delete != null;
|
|
23094
|
+
this.imagePrompts = record4(capabilities.promptCapabilities).image === true;
|
|
23095
|
+
const steering = record4(record4(record4(capabilities._meta).lody).steering);
|
|
23048
23096
|
if (steering.version === 1 && (steering.transport === "request" || steering.transport === "prompt")) {
|
|
23049
23097
|
this.steering = { transport: steering.transport, upstreamTurn: steering.upstreamTurn === "handoff" ? "handoff" : "same" };
|
|
23050
23098
|
}
|
|
@@ -23057,7 +23105,9 @@ var AcpConnection = class _AcpConnection {
|
|
|
23057
23105
|
onNotification(method, params) {
|
|
23058
23106
|
if (method === "session/update") {
|
|
23059
23107
|
const sessionId = text2(params.sessionId);
|
|
23060
|
-
|
|
23108
|
+
const update = record4(params.update);
|
|
23109
|
+
if (sessionId && update.sessionUpdate === "available_commands_update") this.captureCommands(sessionId, update.availableCommands);
|
|
23110
|
+
if (sessionId) this.hooks.update(sessionId, record4(params.update));
|
|
23061
23111
|
return;
|
|
23062
23112
|
}
|
|
23063
23113
|
this.hooks.notification(method, params);
|
|
@@ -23148,7 +23198,7 @@ var TurnTranscript = class {
|
|
|
23148
23198
|
case "plan":
|
|
23149
23199
|
return this.item({ itemId: "plan", type: "plan", entries: planEntries(update.entries) });
|
|
23150
23200
|
case "plan_update": {
|
|
23151
|
-
const plan =
|
|
23201
|
+
const plan = record4(update.plan);
|
|
23152
23202
|
if (plan.type === "items") return this.item({ itemId: "plan", type: "plan", entries: planEntries(plan.entries) });
|
|
23153
23203
|
if (plan.type === "markdown" && typeof plan.planId === "string") {
|
|
23154
23204
|
return this.item({ itemId: `proposed_plan:${plan.planId}`, type: "proposed_plan", turnId: plan.planId, markdown: clipText(String(plan.content ?? ""), 64e3), status: "delta", isLatest: true });
|
|
@@ -23175,7 +23225,7 @@ var TurnTranscript = class {
|
|
|
23175
23225
|
/** The agent's slash commands, also known before the first prompt. */
|
|
23176
23226
|
availableCommands(list) {
|
|
23177
23227
|
if (!Array.isArray(list)) return;
|
|
23178
|
-
const commands = list.map(
|
|
23228
|
+
const commands = list.map(record4).filter((command) => typeof command.name === "string").map((command) => ({
|
|
23179
23229
|
name: command.name,
|
|
23180
23230
|
description: clipText(typeof command.description === "string" ? command.description : "", 600),
|
|
23181
23231
|
...command.input && typeof command.input === "object" ? { input: clip2(command.input, 600) } : {}
|
|
@@ -23213,7 +23263,7 @@ var TurnTranscript = class {
|
|
|
23213
23263
|
if (rows.length) this.rows(rows);
|
|
23214
23264
|
}
|
|
23215
23265
|
chunk(kind, content) {
|
|
23216
|
-
const part =
|
|
23266
|
+
const part = record4(content);
|
|
23217
23267
|
if (part.type !== "text" || typeof part.text !== "string" || !part.text) return;
|
|
23218
23268
|
let open4 = this.open;
|
|
23219
23269
|
if (open4?.kind !== kind) {
|
|
@@ -23295,14 +23345,14 @@ var TurnTranscript = class {
|
|
|
23295
23345
|
}
|
|
23296
23346
|
/** Run-log rows for the output tail (the 运行日志 view). */
|
|
23297
23347
|
toolRows(tool, first) {
|
|
23298
|
-
const input2 =
|
|
23348
|
+
const input2 = record4(tool.rawInput);
|
|
23299
23349
|
const command = typeof input2.command === "string" ? input2.command : Array.isArray(input2.command) ? input2.command.join(" ") : void 0;
|
|
23300
23350
|
if (tool.kind === "execute") {
|
|
23301
23351
|
if (first) {
|
|
23302
23352
|
this.shellOpen = tool.toolCallId;
|
|
23303
23353
|
this.rows([runLog.command(command ?? tool.title ?? "shell")]);
|
|
23304
23354
|
} else {
|
|
23305
|
-
const output2 =
|
|
23355
|
+
const output2 = record4(tool.rawOutput);
|
|
23306
23356
|
const text3 = typeof output2.aggregated_output === "string" ? output2.aggregated_output : typeof output2.stdout === "string" ? output2.stdout : "";
|
|
23307
23357
|
const header = this.shellOpen === tool.toolCallId ? [] : [runLog.command(command ?? tool.title ?? "shell")];
|
|
23308
23358
|
this.shellOpen = "";
|
|
@@ -23316,7 +23366,7 @@ var TurnTranscript = class {
|
|
|
23316
23366
|
return;
|
|
23317
23367
|
}
|
|
23318
23368
|
this.shellOpen = "";
|
|
23319
|
-
const location =
|
|
23369
|
+
const location = record4(tool.locations?.[0]);
|
|
23320
23370
|
const path = typeof location.path === "string" ? location.path : void 0;
|
|
23321
23371
|
if (tool.kind === "edit" || tool.kind === "delete" || tool.kind === "move") this.rows([runLog.fileChange(path)]);
|
|
23322
23372
|
else if (tool.kind === "fetch") this.rows([runLog.tool("web_search")]);
|
|
@@ -23328,7 +23378,7 @@ var TurnTranscript = class {
|
|
|
23328
23378
|
};
|
|
23329
23379
|
function planEntries(value) {
|
|
23330
23380
|
if (!Array.isArray(value)) return [];
|
|
23331
|
-
return value.map(
|
|
23381
|
+
return value.map(record4).map((entry) => ({
|
|
23332
23382
|
content: clipText(String(entry.content ?? ""), 2e3),
|
|
23333
23383
|
priority: typeof entry.priority === "string" ? entry.priority : "medium",
|
|
23334
23384
|
status: typeof entry.status === "string" ? entry.status : "pending"
|
|
@@ -23336,7 +23386,7 @@ function planEntries(value) {
|
|
|
23336
23386
|
}
|
|
23337
23387
|
function toolContent(content) {
|
|
23338
23388
|
return content.map((block) => {
|
|
23339
|
-
const part =
|
|
23389
|
+
const part = record4(block);
|
|
23340
23390
|
if (part.type === "diff") {
|
|
23341
23391
|
return {
|
|
23342
23392
|
type: "diff",
|
|
@@ -23349,10 +23399,10 @@ function toolContent(content) {
|
|
|
23349
23399
|
});
|
|
23350
23400
|
}
|
|
23351
23401
|
function toolMeta(value) {
|
|
23352
|
-
const meta3 =
|
|
23402
|
+
const meta3 = record4(value);
|
|
23353
23403
|
const out = {};
|
|
23354
23404
|
if (meta3.lody !== void 0) out.lody = clip2(meta3.lody, 2e3);
|
|
23355
|
-
const claudeCode =
|
|
23405
|
+
const claudeCode = record4(meta3.claudeCode);
|
|
23356
23406
|
if (Object.keys(claudeCode).length) {
|
|
23357
23407
|
out.claudeCode = {
|
|
23358
23408
|
...typeof claudeCode.toolName === "string" ? { toolName: claudeCode.toolName } : {},
|
|
@@ -23376,7 +23426,7 @@ function clip2(value, max, depth = 0) {
|
|
|
23376
23426
|
|
|
23377
23427
|
// src/providers/cli/codex.ts
|
|
23378
23428
|
var CODEX = requireCliSpec("codex");
|
|
23379
|
-
var
|
|
23429
|
+
var record5 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
23380
23430
|
function toolItem(id, fields) {
|
|
23381
23431
|
return { event: "item", item: { itemId: `tool:${id}`, type: "tool_call", toolCallId: id, ...fields } };
|
|
23382
23432
|
}
|
|
@@ -23413,7 +23463,7 @@ function codexItemEvents(phase, item) {
|
|
|
23413
23463
|
})];
|
|
23414
23464
|
}
|
|
23415
23465
|
case "file_change": {
|
|
23416
|
-
const changes = Array.isArray(item.changes) ? item.changes.map(
|
|
23466
|
+
const changes = Array.isArray(item.changes) ? item.changes.map(record5) : [];
|
|
23417
23467
|
const paths = changes.map((change) => str(change.path)).filter((path) => Boolean(path));
|
|
23418
23468
|
const title = !paths.length ? "\u4FEE\u6539\u6587\u4EF6" : paths.length <= 3 ? paths.join(", ") : `${paths.slice(0, 3).join(", ")} \u7B49 ${paths.length} \u4E2A\u6587\u4EF6`;
|
|
23419
23469
|
return [toolItem(id, {
|
|
@@ -23439,7 +23489,7 @@ function codexItemEvents(phase, item) {
|
|
|
23439
23489
|
})];
|
|
23440
23490
|
}
|
|
23441
23491
|
case "web_search": {
|
|
23442
|
-
const action =
|
|
23492
|
+
const action = record5(item.action);
|
|
23443
23493
|
const query = str(item.query) ?? str(action.query) ?? str(action.url) ?? "";
|
|
23444
23494
|
return [toolItem(id, {
|
|
23445
23495
|
title: query || "web_search",
|
|
@@ -23449,7 +23499,7 @@ function codexItemEvents(phase, item) {
|
|
|
23449
23499
|
})];
|
|
23450
23500
|
}
|
|
23451
23501
|
case "todo_list": {
|
|
23452
|
-
const entries = (Array.isArray(item.items) ? item.items.map(
|
|
23502
|
+
const entries = (Array.isArray(item.items) ? item.items.map(record5) : []).map((entry) => ({
|
|
23453
23503
|
content: clipText(String(entry.text ?? ""), 2e3),
|
|
23454
23504
|
priority: "medium",
|
|
23455
23505
|
status: entry.completed === true ? "completed" : "pending"
|
|
@@ -23745,9 +23795,9 @@ function claudeTranscriptPath(sessionId) {
|
|
|
23745
23795
|
}
|
|
23746
23796
|
function isPromptEntry(entry) {
|
|
23747
23797
|
if (entry.type !== "user" || entry.isSidechain === true || entry.isMeta === true) return false;
|
|
23748
|
-
const content =
|
|
23798
|
+
const content = record6(entry.message).content;
|
|
23749
23799
|
if (typeof content === "string") return content.trim().length > 0;
|
|
23750
|
-
return Array.isArray(content) && content.some((part) =>
|
|
23800
|
+
return Array.isArray(content) && content.some((part) => record6(part).type === "text");
|
|
23751
23801
|
}
|
|
23752
23802
|
function claudeForkBoundary(transcript, keepTurns) {
|
|
23753
23803
|
if (keepTurns <= 0) return void 0;
|
|
@@ -23814,10 +23864,10 @@ var claudeProvider = {
|
|
|
23814
23864
|
// `--resume <id>` for a chat this computer no longer has.
|
|
23815
23865
|
failureRules: [{ kind: "sessionMissing", pattern: /No conversation found with session ID/i }]
|
|
23816
23866
|
};
|
|
23817
|
-
var
|
|
23867
|
+
var record6 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
23818
23868
|
function toolResultText(content) {
|
|
23819
23869
|
if (typeof content === "string") return content;
|
|
23820
|
-
if (Array.isArray(content)) return content.map((part) => str(
|
|
23870
|
+
if (Array.isArray(content)) return content.map((part) => str(record6(part).text) ?? "").filter(Boolean).join("\n");
|
|
23821
23871
|
return "";
|
|
23822
23872
|
}
|
|
23823
23873
|
var CLAUDE_TOOL_KINDS = {
|
|
@@ -23859,7 +23909,7 @@ function claudeToolItem(id, name, input2) {
|
|
|
23859
23909
|
title = path && `Edit ${path}`;
|
|
23860
23910
|
break;
|
|
23861
23911
|
case "MultiEdit":
|
|
23862
|
-
if (path && Array.isArray(input2.edits)) for (const edit of input2.edits.slice(0, 50).map(
|
|
23912
|
+
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));
|
|
23863
23913
|
title = path && `Edit ${path}`;
|
|
23864
23914
|
break;
|
|
23865
23915
|
case "Write":
|
|
@@ -23911,7 +23961,7 @@ function claudeToolItem(id, name, input2) {
|
|
|
23911
23961
|
};
|
|
23912
23962
|
}
|
|
23913
23963
|
function claudePlanItem(input2) {
|
|
23914
|
-
const todos = Array.isArray(input2.todos) ? input2.todos.map(
|
|
23964
|
+
const todos = Array.isArray(input2.todos) ? input2.todos.map(record6) : [];
|
|
23915
23965
|
return {
|
|
23916
23966
|
itemId: "plan",
|
|
23917
23967
|
type: "plan",
|
|
@@ -23952,13 +24002,13 @@ function claudeLineParser() {
|
|
|
23952
24002
|
return { ...base, display: [`\u25CF \u4F1A\u8BDD ${sessionId ?? ""}`, runLog.event("\u5F00\u59CB\u5904\u7406")] };
|
|
23953
24003
|
}
|
|
23954
24004
|
case "assistant": {
|
|
23955
|
-
const message =
|
|
24005
|
+
const message = record6(event.message);
|
|
23956
24006
|
const content = message.content ?? [];
|
|
23957
24007
|
const messageId = str(message.id) ?? `message${++unnamedMessages}`;
|
|
23958
24008
|
const rows = [];
|
|
23959
24009
|
const events = [];
|
|
23960
24010
|
for (const value of Array.isArray(content) ? content : []) {
|
|
23961
|
-
const part =
|
|
24011
|
+
const part = record6(value);
|
|
23962
24012
|
const index = blockCounts.get(messageId) ?? 0;
|
|
23963
24013
|
blockCounts.set(messageId, index + 1);
|
|
23964
24014
|
if (part.type === "text") {
|
|
@@ -23979,7 +24029,7 @@ function claudeLineParser() {
|
|
|
23979
24029
|
}
|
|
23980
24030
|
if (part.type !== "tool_use") continue;
|
|
23981
24031
|
const name = str(part.name) ?? "tool";
|
|
23982
|
-
const input2 =
|
|
24032
|
+
const input2 = record6(part.input);
|
|
23983
24033
|
const id = str(part.id) ?? "";
|
|
23984
24034
|
if (id && name === "TodoWrite") {
|
|
23985
24035
|
plans.add(id);
|
|
@@ -24002,11 +24052,11 @@ function claudeLineParser() {
|
|
|
24002
24052
|
return { ...base, display: rows, ...events.length ? { chatEvents: events } : {} };
|
|
24003
24053
|
}
|
|
24004
24054
|
case "user": {
|
|
24005
|
-
const content =
|
|
24055
|
+
const content = record6(event.message).content ?? [];
|
|
24006
24056
|
const rows = [];
|
|
24007
24057
|
const events = [];
|
|
24008
24058
|
for (const value of Array.isArray(content) ? content : []) {
|
|
24009
|
-
const part =
|
|
24059
|
+
const part = record6(value);
|
|
24010
24060
|
if (part.type !== "tool_result") continue;
|
|
24011
24061
|
const id = str(part.tool_use_id) ?? "";
|
|
24012
24062
|
const tool = tools.get(id);
|
|
@@ -24064,8 +24114,8 @@ function toolPath(input2, partial2) {
|
|
|
24064
24114
|
const parsed = input2 && typeof input2 === "object" && Object.keys(input2).length ? input2 : tryJson(partial2) ?? {};
|
|
24065
24115
|
return str(parsed.file_path) ?? str(parsed.notebook_path) ?? str(parsed.path);
|
|
24066
24116
|
}
|
|
24067
|
-
var
|
|
24068
|
-
var textContent = (value) => typeof value === "string" ? value : Array.isArray(value) ? value.map((part) => str(
|
|
24117
|
+
var record7 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
24118
|
+
var textContent = (value) => typeof value === "string" ? value : Array.isArray(value) ? value.map((part) => str(record7(part).text) ?? "").filter(Boolean).join("\n") : JSON.stringify(value ?? "");
|
|
24069
24119
|
function claudeChatProvider(attachments) {
|
|
24070
24120
|
let messageID = "";
|
|
24071
24121
|
let messageSequence = 0;
|
|
@@ -24095,14 +24145,14 @@ function claudeChatProvider(attachments) {
|
|
|
24095
24145
|
const events = [];
|
|
24096
24146
|
if (envelope.parent_tool_use_id) return { ...base, display: [] };
|
|
24097
24147
|
if (envelope.type === "stream_event") {
|
|
24098
|
-
const event =
|
|
24148
|
+
const event = record7(envelope.event);
|
|
24099
24149
|
const index = Number(event.index ?? 0);
|
|
24100
24150
|
if (event.type === "message_start") {
|
|
24101
|
-
messageID = str(
|
|
24151
|
+
messageID = str(record7(event.message).id) ?? `message:${++messageSequence}`;
|
|
24102
24152
|
blocks.clear();
|
|
24103
24153
|
} else if (event.type === "content_block_start") {
|
|
24104
24154
|
if (!messageID) messageID = `message:${++messageSequence}`;
|
|
24105
|
-
const part =
|
|
24155
|
+
const part = record7(event.content_block);
|
|
24106
24156
|
const type = part.type === "tool_use" ? "tool_call" : part.type === "thinking" ? "thought" : "text";
|
|
24107
24157
|
if (!["tool_use", "thinking", "text"].includes(String(part.type))) return { ...base, display: [] };
|
|
24108
24158
|
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: "" };
|
|
@@ -24111,7 +24161,7 @@ function claudeChatProvider(attachments) {
|
|
|
24111
24161
|
events.push(asItem(block, "in_progress"));
|
|
24112
24162
|
} else if (event.type === "content_block_delta") {
|
|
24113
24163
|
const block = blocks.get(index);
|
|
24114
|
-
const delta =
|
|
24164
|
+
const delta = record7(event.delta);
|
|
24115
24165
|
if (!block) return { ...base, display: [] };
|
|
24116
24166
|
if (delta.type === "text_delta" || delta.type === "thinking_delta") {
|
|
24117
24167
|
const text3 = String(delta.text ?? delta.thinking ?? "");
|
|
@@ -24128,11 +24178,11 @@ function claudeChatProvider(attachments) {
|
|
|
24128
24178
|
if (block && block.type !== "tool_call") events.push(asItem(block, "completed"));
|
|
24129
24179
|
}
|
|
24130
24180
|
} else if (envelope.type === "assistant") {
|
|
24131
|
-
const message =
|
|
24181
|
+
const message = record7(envelope.message);
|
|
24132
24182
|
const id = str(message.id) || messageID || `message:${++messageSequence}`;
|
|
24133
24183
|
const parts = Array.isArray(message.content) ? message.content : [];
|
|
24134
24184
|
parts.forEach((value, index) => {
|
|
24135
|
-
const part =
|
|
24185
|
+
const part = record7(value);
|
|
24136
24186
|
if (!["text", "thinking", "tool_use"].includes(String(part.type))) return;
|
|
24137
24187
|
const type = part.type === "tool_use" ? "tool_call" : part.type === "thinking" ? "thought" : "text";
|
|
24138
24188
|
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: "" };
|
|
@@ -24141,9 +24191,9 @@ function claudeChatProvider(attachments) {
|
|
|
24141
24191
|
events.push(asItem(block, type === "tool_call" ? "in_progress" : "completed"));
|
|
24142
24192
|
});
|
|
24143
24193
|
} else if (envelope.type === "user") {
|
|
24144
|
-
const message =
|
|
24194
|
+
const message = record7(envelope.message);
|
|
24145
24195
|
for (const value of Array.isArray(message.content) ? message.content : []) {
|
|
24146
|
-
const part =
|
|
24196
|
+
const part = record7(value);
|
|
24147
24197
|
if (part.type !== "tool_result") continue;
|
|
24148
24198
|
const id = str(part.tool_use_id);
|
|
24149
24199
|
if (!id) continue;
|
|
@@ -24194,7 +24244,7 @@ var ECHO_CALLBACK = /echo_report_task_progress/;
|
|
|
24194
24244
|
var PROTOCOL_VERSION2 = 1;
|
|
24195
24245
|
var READ_ONLY_KINDS = /* @__PURE__ */ new Set(["read", "search", "think"]);
|
|
24196
24246
|
var EDIT_KINDS = /* @__PURE__ */ new Set(["edit", "delete", "move"]);
|
|
24197
|
-
var
|
|
24247
|
+
var record8 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
24198
24248
|
function acpErrorText(error62, dialect) {
|
|
24199
24249
|
const message = str(error62?.message) ?? "ACP \u8BF7\u6C42\u5931\u8D25";
|
|
24200
24250
|
const data = error62?.data;
|
|
@@ -24205,8 +24255,8 @@ function acpErrorText(error62, dialect) {
|
|
|
24205
24255
|
function contentText(content) {
|
|
24206
24256
|
if (!Array.isArray(content)) return "";
|
|
24207
24257
|
return content.map((item) => {
|
|
24208
|
-
const part =
|
|
24209
|
-
const inner =
|
|
24258
|
+
const part = record8(item);
|
|
24259
|
+
const inner = record8(part.content);
|
|
24210
24260
|
return str(inner.text) ?? str(part.text) ?? "";
|
|
24211
24261
|
}).filter(Boolean).join("\n");
|
|
24212
24262
|
}
|
|
@@ -24230,14 +24280,14 @@ function rawStdout(rawOutput) {
|
|
|
24230
24280
|
return found.join("\n");
|
|
24231
24281
|
}
|
|
24232
24282
|
function permissionAllowed(params, request) {
|
|
24233
|
-
const call =
|
|
24283
|
+
const call = record8(params.toolCall);
|
|
24234
24284
|
const title = str(call.title) ?? "";
|
|
24235
24285
|
const kind = str(call.kind) ?? "";
|
|
24236
24286
|
const level = accessLevel(request);
|
|
24237
24287
|
return level === "bypassPermissions" || READ_ONLY_KINDS.has(kind) || level !== "restricted" && kind === "fetch" || level === "acceptEdits" && EDIT_KINDS.has(kind) || ECHO_CALLBACK.test(title);
|
|
24238
24288
|
}
|
|
24239
24289
|
function permissionOutcome(params, request) {
|
|
24240
|
-
const options = Array.isArray(params.options) ? params.options.map(
|
|
24290
|
+
const options = Array.isArray(params.options) ? params.options.map(record8) : [];
|
|
24241
24291
|
const kind = permissionAllowed(params, request) ? "allow_once" : "reject_once";
|
|
24242
24292
|
const option = options.find((item) => str(item.kind) === kind);
|
|
24243
24293
|
return option ? { outcome: { outcome: "selected", optionId: option.optionId } } : { outcome: { outcome: "cancelled" } };
|
|
@@ -24367,7 +24417,7 @@ function createAcpProvider(row) {
|
|
|
24367
24417
|
const phase = typeof message.id === "number" ? phases.get(message.id) : void 0;
|
|
24368
24418
|
if (!phase) return { display: [] };
|
|
24369
24419
|
phases.delete(message.id);
|
|
24370
|
-
const result =
|
|
24420
|
+
const result = record8(message.result);
|
|
24371
24421
|
if (phase === "open") {
|
|
24372
24422
|
if (message.error) return onOpenError(message);
|
|
24373
24423
|
loading = false;
|
|
@@ -24414,8 +24464,8 @@ function createAcpProvider(row) {
|
|
|
24414
24464
|
const onToolCall = (update) => {
|
|
24415
24465
|
const id = str(update.toolCallId) ?? "";
|
|
24416
24466
|
const known = tools.get(id);
|
|
24417
|
-
const input2 =
|
|
24418
|
-
const locations = Array.isArray(update.locations) ? update.locations.map(
|
|
24467
|
+
const input2 = record8(update.rawInput);
|
|
24468
|
+
const locations = Array.isArray(update.locations) ? update.locations.map(record8) : [];
|
|
24419
24469
|
const tool = known ?? { kind: "other", title: "tool" };
|
|
24420
24470
|
tool.kind = str(update.kind) ?? tool.kind;
|
|
24421
24471
|
if (!known) tool.title = str(update.title) ?? tool.title;
|
|
@@ -24460,7 +24510,7 @@ function createAcpProvider(row) {
|
|
|
24460
24510
|
return first;
|
|
24461
24511
|
};
|
|
24462
24512
|
const onUpdate = (params) => {
|
|
24463
|
-
const raw =
|
|
24513
|
+
const raw = record8(params.update);
|
|
24464
24514
|
const kind = str(raw.sessionUpdate);
|
|
24465
24515
|
const update = (kind === "tool_call" || kind === "tool_call_update") && dialect.normalizeToolUpdate ? dialect.normalizeToolUpdate(raw) : raw;
|
|
24466
24516
|
if (loading) {
|
|
@@ -24468,7 +24518,7 @@ function createAcpProvider(row) {
|
|
|
24468
24518
|
return withItems({ display: [] });
|
|
24469
24519
|
}
|
|
24470
24520
|
transcript.update(update);
|
|
24471
|
-
const text3 = str(
|
|
24521
|
+
const text3 = str(record8(update.content).text);
|
|
24472
24522
|
switch (kind) {
|
|
24473
24523
|
case "agent_message_chunk": {
|
|
24474
24524
|
if (!text3) return withItems({ display: [] });
|
|
@@ -24491,7 +24541,7 @@ function createAcpProvider(row) {
|
|
|
24491
24541
|
}
|
|
24492
24542
|
};
|
|
24493
24543
|
const onRequest = (message) => {
|
|
24494
|
-
const params =
|
|
24544
|
+
const params = record8(message.params);
|
|
24495
24545
|
if (message.method === "session/request_permission") {
|
|
24496
24546
|
answer(message.id, permissionOutcome(params, request));
|
|
24497
24547
|
return { display: [] };
|
|
@@ -24531,7 +24581,7 @@ function createAcpProvider(row) {
|
|
|
24531
24581
|
if (finished && message.id === void 0) return { display: [] };
|
|
24532
24582
|
if (message.method && message.id !== void 0) return onRequest(message);
|
|
24533
24583
|
if (message.method) {
|
|
24534
|
-
const params =
|
|
24584
|
+
const params = record8(message.params);
|
|
24535
24585
|
if (message.method === "session/update") return onUpdate(params);
|
|
24536
24586
|
const rows = dialect.notification?.(message.method, params);
|
|
24537
24587
|
return { display: rows ?? [] };
|
|
@@ -25362,8 +25412,8 @@ var OrphanRegistry = class {
|
|
|
25362
25412
|
file;
|
|
25363
25413
|
records = /* @__PURE__ */ new Map();
|
|
25364
25414
|
writing = Promise.resolve();
|
|
25365
|
-
add(
|
|
25366
|
-
this.records.set(
|
|
25415
|
+
add(record10) {
|
|
25416
|
+
this.records.set(record10.runId, record10);
|
|
25367
25417
|
this.persist();
|
|
25368
25418
|
}
|
|
25369
25419
|
remove(runId) {
|
|
@@ -25387,12 +25437,12 @@ var OrphanRegistry = class {
|
|
|
25387
25437
|
return [];
|
|
25388
25438
|
}
|
|
25389
25439
|
const reaped = [];
|
|
25390
|
-
for (const
|
|
25391
|
-
if (!
|
|
25392
|
-
const command = await commandOf(
|
|
25393
|
-
if (command && command.includes(basename(
|
|
25394
|
-
await killProcessTree(
|
|
25395
|
-
reaped.push(
|
|
25440
|
+
for (const record10 of previous) {
|
|
25441
|
+
if (!record10 || typeof record10.pid !== "number" || record10.pid <= 1) continue;
|
|
25442
|
+
const command = await commandOf(record10.pid);
|
|
25443
|
+
if (command && command.includes(basename(record10.executable))) {
|
|
25444
|
+
await killProcessTree(record10.pid);
|
|
25445
|
+
reaped.push(record10);
|
|
25396
25446
|
}
|
|
25397
25447
|
}
|
|
25398
25448
|
this.records.clear();
|
|
@@ -25999,7 +26049,7 @@ var RunTranscript = class _RunTranscript {
|
|
|
25999
26049
|
* that ended before the run did: it reads as `lost`.
|
|
26000
26050
|
*/
|
|
26001
26051
|
static fromFile(value) {
|
|
26002
|
-
const data =
|
|
26052
|
+
const data = record9(value);
|
|
26003
26053
|
if (data.v !== 1 || typeof data.run_id !== "string" || !data.run_id || !Array.isArray(data.items) || !Array.isArray(data.lines)) return void 0;
|
|
26004
26054
|
const transcript = new _RunTranscript({
|
|
26005
26055
|
runId: data.run_id,
|
|
@@ -26015,7 +26065,7 @@ var RunTranscript = class _RunTranscript {
|
|
|
26015
26065
|
transcript.revision = whole(data.revision);
|
|
26016
26066
|
transcript.itemRevisions = false;
|
|
26017
26067
|
for (const value2 of data.items) {
|
|
26018
|
-
const item =
|
|
26068
|
+
const item = record9(value2);
|
|
26019
26069
|
if (typeof item.itemId !== "string" || !item.itemId || transcript.positions.has(item.itemId)) continue;
|
|
26020
26070
|
transcript.positions.set(item.itemId, transcript.entries.length);
|
|
26021
26071
|
transcript.entries.push({ rev: 0, item });
|
|
@@ -26256,7 +26306,7 @@ function whole(value) {
|
|
|
26256
26306
|
function finite(value) {
|
|
26257
26307
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
26258
26308
|
}
|
|
26259
|
-
function
|
|
26309
|
+
function record9(value) {
|
|
26260
26310
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
26261
26311
|
}
|
|
26262
26312
|
function errorCode(error62) {
|
|
@@ -26871,6 +26921,10 @@ var AcpChatSession = class {
|
|
|
26871
26921
|
const session = await this.ensureSession(turn, connection);
|
|
26872
26922
|
if (turn.cancelRequested) return this.cancelled(turn);
|
|
26873
26923
|
sink.started(connection.process.pid, session.sessionId);
|
|
26924
|
+
if (request.command) {
|
|
26925
|
+
const commands = await connection.commands(session.sessionId);
|
|
26926
|
+
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");
|
|
26927
|
+
}
|
|
26874
26928
|
await this.applySettings(turn, connection, session);
|
|
26875
26929
|
if (turn.cancelRequested) return this.cancelled(turn);
|
|
26876
26930
|
let blocks = await this.promptBlocks(request, connection);
|
|
@@ -27048,17 +27102,17 @@ var AcpChatSession = class {
|
|
|
27048
27102
|
const options = permissionOptions(params.options);
|
|
27049
27103
|
if (prompts && options.length && this.forwardsPermission(params, prompts)) {
|
|
27050
27104
|
const requestId = randomUUID3();
|
|
27051
|
-
const call =
|
|
27105
|
+
const call = record4(params.toolCall);
|
|
27052
27106
|
const toolCall = typeof call.toolCallId === "string" && call.toolCallId ? call : { ...call, toolCallId: `permission:${requestId}` };
|
|
27053
|
-
const meta3 =
|
|
27107
|
+
const meta3 = record4(params._meta);
|
|
27054
27108
|
return this.ask(turn, requestId, toolCall, options, Object.keys(meta3).length ? meta3 : void 0, signal2).then((outcome2) => ({ outcome: outcome2 }));
|
|
27055
27109
|
}
|
|
27056
27110
|
const access = turn.request.access;
|
|
27057
27111
|
const outcome = permissionOutcome(params, access === "restricted" ? { permissionMode: "restricted" } : { permissionMode: "full", access: access === "default" ? "read-only" : access });
|
|
27058
|
-
const selected =
|
|
27059
|
-
const option = Array.isArray(params.options) ? params.options.map(
|
|
27112
|
+
const selected = record4(record4(outcome).outcome);
|
|
27113
|
+
const option = Array.isArray(params.options) ? params.options.map(record4).find((item) => item.optionId === selected.optionId) : void 0;
|
|
27060
27114
|
if (typeof option?.kind === "string" && option.kind.startsWith("reject")) {
|
|
27061
|
-
const call =
|
|
27115
|
+
const call = record4(params.toolCall);
|
|
27062
27116
|
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`);
|
|
27063
27117
|
}
|
|
27064
27118
|
return outcome;
|
|
@@ -27071,7 +27125,7 @@ var AcpChatSession = class {
|
|
|
27071
27125
|
forwardsPermission(params, prompts) {
|
|
27072
27126
|
if (isAskUserQuestionPermission(params)) return true;
|
|
27073
27127
|
if (prompts.permissions === "none") return false;
|
|
27074
|
-
const title =
|
|
27128
|
+
const title = record4(params.toolCall).title;
|
|
27075
27129
|
if (ECHO_CALLBACK.test(typeof title === "string" ? title : "")) return false;
|
|
27076
27130
|
if (prompts.permissions === "all") return true;
|
|
27077
27131
|
return !permissionAllowed(params, { permissionMode: "full", access: "acceptEdits" });
|
|
@@ -27227,7 +27281,7 @@ function isArchivedSessionError(error62) {
|
|
|
27227
27281
|
}
|
|
27228
27282
|
function permissionOptions(value) {
|
|
27229
27283
|
if (!Array.isArray(value)) return [];
|
|
27230
|
-
return value.map(
|
|
27284
|
+
return value.map(record4).flatMap((option) => typeof option.optionId === "string" && option.optionId ? [{ optionId: option.optionId, name: typeof option.name === "string" ? option.name : option.optionId, kind: typeof option.kind === "string" ? option.kind : "" }] : []);
|
|
27231
27285
|
}
|
|
27232
27286
|
|
|
27233
27287
|
// src/acp/chat-host.ts
|
|
@@ -27359,6 +27413,34 @@ var AcpChatHost = class {
|
|
|
27359
27413
|
}
|
|
27360
27414
|
};
|
|
27361
27415
|
|
|
27416
|
+
// src/acp/command-catalog.ts
|
|
27417
|
+
async function readCLICommands(spec, launch, cwd, clientVersion) {
|
|
27418
|
+
const connection = await AcpConnection.open(launch.launch, {
|
|
27419
|
+
update: () => {
|
|
27420
|
+
},
|
|
27421
|
+
permission: () => ({ outcome: { outcome: "cancelled" } }),
|
|
27422
|
+
notification: () => {
|
|
27423
|
+
},
|
|
27424
|
+
stderr: () => {
|
|
27425
|
+
}
|
|
27426
|
+
}, clientVersion);
|
|
27427
|
+
let sessionId = "";
|
|
27428
|
+
try {
|
|
27429
|
+
const auth = spec.authMethod ? { pick: spec.authMethod, env: launch.launch.env ?? {} } : void 0;
|
|
27430
|
+
const session = await connection.newSession(cwd, auth);
|
|
27431
|
+
sessionId = session.sessionId;
|
|
27432
|
+
return await connection.commands(sessionId);
|
|
27433
|
+
} finally {
|
|
27434
|
+
if (sessionId && connection.deleteSession) {
|
|
27435
|
+
try {
|
|
27436
|
+
await connection.removeSession(sessionId);
|
|
27437
|
+
} catch {
|
|
27438
|
+
}
|
|
27439
|
+
}
|
|
27440
|
+
await connection.dispose();
|
|
27441
|
+
}
|
|
27442
|
+
}
|
|
27443
|
+
|
|
27362
27444
|
// src/runs/run-supervisor.ts
|
|
27363
27445
|
var COMPLETION_EXIT_GRACE_MS = 15e3;
|
|
27364
27446
|
var EXIT_OUTPUT_GRACE_MS = 2e3;
|
|
@@ -27525,6 +27607,14 @@ var RunSupervisor = class {
|
|
|
27525
27607
|
this.preparing.delete(payload.run_id);
|
|
27526
27608
|
}
|
|
27527
27609
|
}
|
|
27610
|
+
async listCLICommands(input2) {
|
|
27611
|
+
const spec = acpChatSpec(input2.agent_type);
|
|
27612
|
+
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");
|
|
27613
|
+
const workdir = input2.workdir ? await this.validateWorkdir(input2.workdir) : await this.defaultChatWorkdir();
|
|
27614
|
+
const prepared = await this.acpChats.prepare(spec, { access: "read-only", workdir, model: input2.model ?? "", reasoningEffort: input2.reasoning_effort ?? "" });
|
|
27615
|
+
const items = await readCLICommands(spec, prepared, workdir, agentPackageVersion());
|
|
27616
|
+
return { agent_type: input2.agent_type, items };
|
|
27617
|
+
}
|
|
27528
27618
|
async startPrepared(payload, signal2) {
|
|
27529
27619
|
if (this.active.has(payload.run_id) || this.acpRuns.has(payload.run_id) || this.recent.has(payload.run_id)) {
|
|
27530
27620
|
this.logger.info("run-duplicate-ignored", { runId: payload.run_id });
|
|
@@ -27540,6 +27630,7 @@ var RunSupervisor = class {
|
|
|
27540
27630
|
this.remember({ runId: payload.run_id, sessionKey, tail: new TerminalTailBuffer(), transcript, finishedAt: Date.now(), status: "failed", chat: !!payload.chat_session_id });
|
|
27541
27631
|
await this.report(payload.run_id, { status: "failed", error: failure2.message, failure_kind: failure2.kind, duration_ms: 0 });
|
|
27542
27632
|
};
|
|
27633
|
+
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");
|
|
27543
27634
|
if (this.sessionBusy(sessionKey, payload.run_id)) {
|
|
27544
27635
|
return refuse("\u672C\u673A\u8BE5\u4F1A\u8BDD\u5DF2\u6709\u4EFB\u52A1\u5728\u8FD0\u884C");
|
|
27545
27636
|
}
|
|
@@ -27581,7 +27672,7 @@ var RunSupervisor = class {
|
|
|
27581
27672
|
}
|
|
27582
27673
|
return refuse(`\u9644\u4EF6\u4E0B\u8F7D\u5931\u8D25\uFF1A${errorMessage2(error62)}`);
|
|
27583
27674
|
}
|
|
27584
|
-
const prompt = turn.planPrompt ? `${payload.prompt}
|
|
27675
|
+
const prompt = payload.cli_command ? `/${payload.cli_command.name}${payload.cli_command.arguments ? " " + payload.cli_command.arguments : ""}` : turn.planPrompt ? `${payload.prompt}
|
|
27585
27676
|
|
|
27586
27677
|
${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
27587
27678
|
const request = {
|
|
@@ -27595,6 +27686,7 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
27595
27686
|
};
|
|
27596
27687
|
if (payload.chat_session_id) {
|
|
27597
27688
|
const acpSpec = acpChatSpec(cli.id);
|
|
27689
|
+
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");
|
|
27598
27690
|
if (acpSpec) {
|
|
27599
27691
|
const outcome = await this.startAcpChat(payload, { spec: acpSpec, cli, sessionKey, workdir, prompt, turn, permissionMode, memoryEnv, signal: signal2, refuse, transcript });
|
|
27600
27692
|
if (outcome === "handled") return;
|
|
@@ -27894,7 +27986,7 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
27894
27986
|
await refuse(cliFailure("cliMissing", { label: cli.label, ...cli.installHint ? { installHint: cli.installHint } : {} }));
|
|
27895
27987
|
return "handled";
|
|
27896
27988
|
}
|
|
27897
|
-
if (cli.chat) return { fallback: `${error62.message}\uFF0C\u672C\u8F6E\u6539\u7528\u65E7\u7248\u804A\u5929\u9A71\u52A8` };
|
|
27989
|
+
if (cli.chat && !payload.cli_command) return { fallback: `${error62.message}\uFF0C\u672C\u8F6E\u6539\u7528\u65E7\u7248\u804A\u5929\u9A71\u52A8` };
|
|
27898
27990
|
await refuse({ kind: "startFailed", message: error62.message });
|
|
27899
27991
|
return "handled";
|
|
27900
27992
|
}
|
|
@@ -27926,6 +28018,7 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
27926
28018
|
let reported = { pid: 0, sessionId: "" };
|
|
27927
28019
|
const result = await this.acpChats.run(sessionKey, spec, {
|
|
27928
28020
|
runId,
|
|
28021
|
+
...payload.cli_command ? { command: payload.cli_command } : {},
|
|
27929
28022
|
prompt: context.prompt,
|
|
27930
28023
|
attachments,
|
|
27931
28024
|
sessionId: payload.session_id,
|
|
@@ -27936,7 +28029,7 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
27936
28029
|
fast: turn.fast,
|
|
27937
28030
|
workdir,
|
|
27938
28031
|
notes,
|
|
27939
|
-
...turn.prompts ? { prompts: turn.prompts } : {}
|
|
28032
|
+
...turn.prompts && (!payload.cli_command || payload.cli_command_interactive) ? { prompts: turn.prompts } : {}
|
|
27940
28033
|
}, {
|
|
27941
28034
|
events: (events) => {
|
|
27942
28035
|
forwarder.push(events);
|
|
@@ -27954,6 +28047,11 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
27954
28047
|
});
|
|
27955
28048
|
}
|
|
27956
28049
|
}, launch);
|
|
28050
|
+
if (payload.cli_command && !payload.cli_command_interactive) {
|
|
28051
|
+
await this.acpChats.closeSession(sessionKey).catch((error62) => {
|
|
28052
|
+
this.logger.warn("command-process-close-failed", { runId, error: errorMessage2(error62) });
|
|
28053
|
+
});
|
|
28054
|
+
}
|
|
27957
28055
|
await forwarder.drain();
|
|
27958
28056
|
this.acpRuns.delete(runId);
|
|
27959
28057
|
const durationMs = Date.now() - run.startedAt;
|
|
@@ -28799,6 +28897,8 @@ var RunStartPayloadSchema = external_exports.object({
|
|
|
28799
28897
|
task_chain_id: external_exports.string().optional().default(""),
|
|
28800
28898
|
message_id: external_exports.string().optional().default(""),
|
|
28801
28899
|
prompt: external_exports.string().max(512 * 1024),
|
|
28900
|
+
cli_command: external_exports.object({ name: external_exports.string().min(1).max(200), arguments: external_exports.string().max(64 * 1024).optional().default("") }).optional(),
|
|
28901
|
+
cli_command_interactive: external_exports.boolean().optional(),
|
|
28802
28902
|
chat_session_id: external_exports.string().max(64).optional(),
|
|
28803
28903
|
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(),
|
|
28804
28904
|
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(),
|
|
@@ -29142,6 +29242,7 @@ var AgentRuntime = class {
|
|
|
29142
29242
|
task_attachments: { version: 1 },
|
|
29143
29243
|
// `run.transcript`: any run's structured items and run-log rows, kept on this device after the run.
|
|
29144
29244
|
run_transcripts: { version: 1 },
|
|
29245
|
+
cli_commands: { version: 1 },
|
|
29145
29246
|
// `memory.provider` commands and the `memory` field of run payloads (Lody's memoryProviders v1).
|
|
29146
29247
|
memory_providers: { version: 1, providers: [...MEMORY_PROVIDER_IDS] },
|
|
29147
29248
|
cli_execution_policy: { version: 1, modes: ["restricted", "full"] },
|
|
@@ -29269,6 +29370,16 @@ var AgentRuntime = class {
|
|
|
29269
29370
|
if (!this.catalogReport) return { success: false, error: "\u8BFB\u53D6\u6A21\u578B\u76EE\u5F55\u5931\u8D25" };
|
|
29270
29371
|
return { success: true, result: this.catalogReport };
|
|
29271
29372
|
}
|
|
29373
|
+
case "cli.commands": {
|
|
29374
|
+
const value = command.payload;
|
|
29375
|
+
if (!value || typeof value.agent_type !== "string") return { success: false, error: "CLI \u7C7B\u578B\u65E0\u6548" };
|
|
29376
|
+
return { success: true, result: await this.runs.listCLICommands({
|
|
29377
|
+
agent_type: value.agent_type,
|
|
29378
|
+
...typeof value.workdir === "string" ? { workdir: value.workdir } : {},
|
|
29379
|
+
...typeof value.model === "string" ? { model: value.model } : {},
|
|
29380
|
+
...typeof value.reasoning_effort === "string" ? { reasoning_effort: value.reasoning_effort } : {}
|
|
29381
|
+
}) };
|
|
29382
|
+
}
|
|
29272
29383
|
case "cli.quota": {
|
|
29273
29384
|
const payload = CliQuotaPayloadSchema.parse(command.payload ?? {});
|
|
29274
29385
|
try {
|