toc-ocra 0.3.11 → 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 +15 -4
- package/dist/cli/cli.mjs +253 -330
- package/dist/service/agent.mjs +248 -325
- package/dist/src/acp/acp-launch-specs.js +9 -0
- package/dist/src/acp/acp-launch-specs.js.map +1 -1
- 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/providers/cli-specs.js +1 -0
- package/dist/src/providers/cli-specs.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.d.ts +1 -2
- package/dist/src/runtime/agent-runtime.js +18 -11
- package/dist/src/runtime/agent-runtime.js.map +1 -1
- package/dist/src/types/protocol.d.ts +9 -23
- package/dist/src/types/protocol.js +6 -11
- package/dist/src/types/protocol.js.map +1 -1
- package/dist/src/workspace/directory-browser.d.ts +4 -0
- package/dist/src/workspace/directory-browser.js +43 -5
- package/dist/src/workspace/directory-browser.js.map +1 -1
- package/dist/src/workspace/workspace-manager.d.ts +1 -12
- package/dist/src/workspace/workspace-manager.js +5 -216
- package/dist/src/workspace/workspace-manager.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;
|
|
@@ -20777,6 +20777,7 @@ function mergePathSegments(segments) {
|
|
|
20777
20777
|
// src/providers/cli-specs.ts
|
|
20778
20778
|
var SOURCES = [
|
|
20779
20779
|
{ id: "codex", label: "Codex", command: "codex", versionArguments: ["--version"], promptStdin: { replaceWith: "-" }, restrictedPermission: true, installHint: "npm i -g @openai/codex" },
|
|
20780
|
+
{ id: "kimi", label: "Kimi Code CLI", command: "kimi", versionArguments: ["--version"], installHint: "curl -fsSL https://code.kimi.com/kimi-code/install.sh | bash" },
|
|
20780
20781
|
{ id: "claude", label: "Claude Code", aliases: ["claude-code"], command: "claude", commandAliases: ["claude-code"], versionArguments: ["--version"], promptStdin: "omit", restrictedPermission: true, installHint: "npm i -g @anthropic-ai/claude-code" },
|
|
20781
20782
|
{ id: "grok", label: "Grok CLI", command: "grok", versionArguments: ["--version"] },
|
|
20782
20783
|
{ id: "gemini", label: "Gemini CLI", command: "gemini", versionArguments: ["--version"], restrictedPermission: true, installHint: "npm i -g @google/gemini-cli" },
|
|
@@ -22312,6 +22313,14 @@ var KIRO_LAUNCH_SPEC = {
|
|
|
22312
22313
|
resumable: (sessionId) => !sessionId.startsWith("sess_"),
|
|
22313
22314
|
modelDiscovery: { kind: "reader", source: MODEL_SOURCES.kiro }
|
|
22314
22315
|
};
|
|
22316
|
+
var KIMI_LAUNCH_SPEC = {
|
|
22317
|
+
agent: "kimi",
|
|
22318
|
+
headless: "acp",
|
|
22319
|
+
args: () => ["acp"],
|
|
22320
|
+
resumePreference: "resume",
|
|
22321
|
+
dialect: { failureRules: [{ kind: "sessionMissing", pattern: /session[^\n]{0,60}(?:not found|does not exist)|no such session/i }] },
|
|
22322
|
+
modelDiscovery: { kind: "session" }
|
|
22323
|
+
};
|
|
22315
22324
|
var GEMINI_LAUNCH_SPEC = {
|
|
22316
22325
|
agent: "gemini",
|
|
22317
22326
|
headless: "acp",
|
|
@@ -22417,6 +22426,7 @@ var CODEX_LAUNCH_SPEC = {
|
|
|
22417
22426
|
};
|
|
22418
22427
|
var ACP_LAUNCH_SPECS = [
|
|
22419
22428
|
KIRO_LAUNCH_SPEC,
|
|
22429
|
+
KIMI_LAUNCH_SPEC,
|
|
22420
22430
|
GEMINI_LAUNCH_SPEC,
|
|
22421
22431
|
GROK_LAUNCH_SPEC,
|
|
22422
22432
|
OPENCODE_LAUNCH_SPEC,
|
|
@@ -22895,12 +22905,24 @@ function rpcErrorText(error62) {
|
|
|
22895
22905
|
return /^internal error$/i.test(error62.message) ? detail : `${error62.message}: ${detail}`;
|
|
22896
22906
|
}
|
|
22897
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
|
+
|
|
22898
22920
|
// src/acp/connection.ts
|
|
22899
22921
|
var PROTOCOL_VERSION = 1;
|
|
22900
22922
|
var INITIALIZE_TIMEOUT_MS = 12e4;
|
|
22901
22923
|
var SESSION_OPEN_TIMEOUT_MS = 18e4;
|
|
22902
22924
|
var EXT_REQUEST_TIMEOUT_MS = 6e4;
|
|
22903
|
-
var
|
|
22925
|
+
var record4 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
22904
22926
|
var text2 = (value) => typeof value === "string" && value ? value : void 0;
|
|
22905
22927
|
var AcpConnection = class _AcpConnection {
|
|
22906
22928
|
constructor(launch, hooks, elicitation) {
|
|
@@ -22909,8 +22931,8 @@ var AcpConnection = class _AcpConnection {
|
|
|
22909
22931
|
let peer;
|
|
22910
22932
|
this.process = AgentProcess.spawn(launch, (line) => peer?.receive(line), (line) => hooks.stderr(line));
|
|
22911
22933
|
peer = new JsonRpcPeer((line) => this.process.write(line), {
|
|
22912
|
-
request: async (method, params, signal2) => this.onRequest(method,
|
|
22913
|
-
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))
|
|
22914
22936
|
});
|
|
22915
22937
|
this.peer = peer;
|
|
22916
22938
|
this.closed = this.process.exited.then((exit) => {
|
|
@@ -22933,6 +22955,8 @@ var AcpConnection = class _AcpConnection {
|
|
|
22933
22955
|
steering;
|
|
22934
22956
|
initialized = {};
|
|
22935
22957
|
peer;
|
|
22958
|
+
commandLists = /* @__PURE__ */ new Map();
|
|
22959
|
+
commandListeners = /* @__PURE__ */ new Set();
|
|
22936
22960
|
/**
|
|
22937
22961
|
* Starts the agent and completes `initialize`; the process is stopped on
|
|
22938
22962
|
* failure. `elicitation`: advertise form elicitation (Claude's adapter only
|
|
@@ -22942,7 +22966,7 @@ var AcpConnection = class _AcpConnection {
|
|
|
22942
22966
|
const elicitation = options.elicitation === true && hooks.elicitation !== void 0;
|
|
22943
22967
|
const connection = new _AcpConnection(launch, hooks, elicitation);
|
|
22944
22968
|
try {
|
|
22945
|
-
const result =
|
|
22969
|
+
const result = record4(await connection.call("initialize", {
|
|
22946
22970
|
protocolVersion: PROTOCOL_VERSION,
|
|
22947
22971
|
clientCapabilities: {
|
|
22948
22972
|
fs: { readTextFile: false, writeTextFile: false },
|
|
@@ -22963,16 +22987,18 @@ var AcpConnection = class _AcpConnection {
|
|
|
22963
22987
|
}
|
|
22964
22988
|
/** `auth`: the row's sign-in method, tried once when the agent answers `auth_required`. */
|
|
22965
22989
|
async newSession(cwd, auth) {
|
|
22966
|
-
const result =
|
|
22990
|
+
const result = record4(await this.withAuthentication(() => this.call("session/new", { cwd, mcpServers: [] }, SESSION_OPEN_TIMEOUT_MS), auth));
|
|
22967
22991
|
const sessionId = text2(result.sessionId);
|
|
22968
22992
|
if (!sessionId) throw new Error("ACP session/new \u6CA1\u6709\u8FD4\u56DE\u4F1A\u8BDD ID");
|
|
22993
|
+
this.captureCommands(sessionId, result.availableCommands);
|
|
22969
22994
|
return sessionState(sessionId, result);
|
|
22970
22995
|
}
|
|
22971
22996
|
/** Reopens a saved session: `session/load` (replays history) or `session/resume`, as the capabilities allow. */
|
|
22972
22997
|
async openSaved(sessionId, cwd, options = {}) {
|
|
22973
22998
|
const method = acpSessionMethod(this.initialized, sessionId, options.resumePreference);
|
|
22974
22999
|
if (!method || method === "new") throw new Error("ACP agent cannot load or resume this session");
|
|
22975
|
-
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);
|
|
22976
23002
|
return sessionState(sessionId, result);
|
|
22977
23003
|
}
|
|
22978
23004
|
/** Removes a session the agent created for a listing; only when `deleteSession`. */
|
|
@@ -22982,9 +23008,41 @@ var AcpConnection = class _AcpConnection {
|
|
|
22982
23008
|
get canOpenSaved() {
|
|
22983
23009
|
return this.loadSession || this.resumeSession;
|
|
22984
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
|
+
}
|
|
22985
23043
|
/** Resolves with the prompt's `stopReason` once the agent ends the turn. */
|
|
22986
23044
|
async prompt(sessionId, prompt, meta3) {
|
|
22987
|
-
const result =
|
|
23045
|
+
const result = record4(await this.peer.request("session/prompt", { sessionId, prompt, ...meta3 ? { _meta: meta3 } : {} }));
|
|
22988
23046
|
return text2(result.stopReason) ?? "end_turn";
|
|
22989
23047
|
}
|
|
22990
23048
|
cancel(sessionId) {
|
|
@@ -22996,7 +23054,7 @@ var AcpConnection = class _AcpConnection {
|
|
|
22996
23054
|
}
|
|
22997
23055
|
/** `_lody/session/steer`: `injected` means the agent took the prompt into the running turn. */
|
|
22998
23056
|
async steer(sessionId, prompt, steerId) {
|
|
22999
|
-
const result =
|
|
23057
|
+
const result = record4(await this.peer.request("_lody/session/steer", { sessionId, prompt, steerId }));
|
|
23000
23058
|
return result.outcome === "injected" ? "injected" : "failed";
|
|
23001
23059
|
}
|
|
23002
23060
|
/** An adapter extension request (`_session/archive`, `_session/unarchive`, …) with a time limit. */
|
|
@@ -23027,14 +23085,14 @@ var AcpConnection = class _AcpConnection {
|
|
|
23027
23085
|
);
|
|
23028
23086
|
}
|
|
23029
23087
|
readCapabilities(result) {
|
|
23030
|
-
const capabilities =
|
|
23088
|
+
const capabilities = record4(result.agentCapabilities);
|
|
23031
23089
|
this.initialized = result;
|
|
23032
|
-
this.agentName = text2(
|
|
23090
|
+
this.agentName = text2(record4(result.agentInfo).name) ?? "";
|
|
23033
23091
|
this.loadSession = capabilities.loadSession === true;
|
|
23034
|
-
this.resumeSession =
|
|
23035
|
-
this.deleteSession =
|
|
23036
|
-
this.imagePrompts =
|
|
23037
|
-
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);
|
|
23038
23096
|
if (steering.version === 1 && (steering.transport === "request" || steering.transport === "prompt")) {
|
|
23039
23097
|
this.steering = { transport: steering.transport, upstreamTurn: steering.upstreamTurn === "handoff" ? "handoff" : "same" };
|
|
23040
23098
|
}
|
|
@@ -23047,7 +23105,9 @@ var AcpConnection = class _AcpConnection {
|
|
|
23047
23105
|
onNotification(method, params) {
|
|
23048
23106
|
if (method === "session/update") {
|
|
23049
23107
|
const sessionId = text2(params.sessionId);
|
|
23050
|
-
|
|
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));
|
|
23051
23111
|
return;
|
|
23052
23112
|
}
|
|
23053
23113
|
this.hooks.notification(method, params);
|
|
@@ -23138,7 +23198,7 @@ var TurnTranscript = class {
|
|
|
23138
23198
|
case "plan":
|
|
23139
23199
|
return this.item({ itemId: "plan", type: "plan", entries: planEntries(update.entries) });
|
|
23140
23200
|
case "plan_update": {
|
|
23141
|
-
const plan =
|
|
23201
|
+
const plan = record4(update.plan);
|
|
23142
23202
|
if (plan.type === "items") return this.item({ itemId: "plan", type: "plan", entries: planEntries(plan.entries) });
|
|
23143
23203
|
if (plan.type === "markdown" && typeof plan.planId === "string") {
|
|
23144
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 });
|
|
@@ -23165,7 +23225,7 @@ var TurnTranscript = class {
|
|
|
23165
23225
|
/** The agent's slash commands, also known before the first prompt. */
|
|
23166
23226
|
availableCommands(list) {
|
|
23167
23227
|
if (!Array.isArray(list)) return;
|
|
23168
|
-
const commands = list.map(
|
|
23228
|
+
const commands = list.map(record4).filter((command) => typeof command.name === "string").map((command) => ({
|
|
23169
23229
|
name: command.name,
|
|
23170
23230
|
description: clipText(typeof command.description === "string" ? command.description : "", 600),
|
|
23171
23231
|
...command.input && typeof command.input === "object" ? { input: clip2(command.input, 600) } : {}
|
|
@@ -23203,7 +23263,7 @@ var TurnTranscript = class {
|
|
|
23203
23263
|
if (rows.length) this.rows(rows);
|
|
23204
23264
|
}
|
|
23205
23265
|
chunk(kind, content) {
|
|
23206
|
-
const part =
|
|
23266
|
+
const part = record4(content);
|
|
23207
23267
|
if (part.type !== "text" || typeof part.text !== "string" || !part.text) return;
|
|
23208
23268
|
let open4 = this.open;
|
|
23209
23269
|
if (open4?.kind !== kind) {
|
|
@@ -23285,14 +23345,14 @@ var TurnTranscript = class {
|
|
|
23285
23345
|
}
|
|
23286
23346
|
/** Run-log rows for the output tail (the 运行日志 view). */
|
|
23287
23347
|
toolRows(tool, first) {
|
|
23288
|
-
const input2 =
|
|
23348
|
+
const input2 = record4(tool.rawInput);
|
|
23289
23349
|
const command = typeof input2.command === "string" ? input2.command : Array.isArray(input2.command) ? input2.command.join(" ") : void 0;
|
|
23290
23350
|
if (tool.kind === "execute") {
|
|
23291
23351
|
if (first) {
|
|
23292
23352
|
this.shellOpen = tool.toolCallId;
|
|
23293
23353
|
this.rows([runLog.command(command ?? tool.title ?? "shell")]);
|
|
23294
23354
|
} else {
|
|
23295
|
-
const output2 =
|
|
23355
|
+
const output2 = record4(tool.rawOutput);
|
|
23296
23356
|
const text3 = typeof output2.aggregated_output === "string" ? output2.aggregated_output : typeof output2.stdout === "string" ? output2.stdout : "";
|
|
23297
23357
|
const header = this.shellOpen === tool.toolCallId ? [] : [runLog.command(command ?? tool.title ?? "shell")];
|
|
23298
23358
|
this.shellOpen = "";
|
|
@@ -23306,7 +23366,7 @@ var TurnTranscript = class {
|
|
|
23306
23366
|
return;
|
|
23307
23367
|
}
|
|
23308
23368
|
this.shellOpen = "";
|
|
23309
|
-
const location =
|
|
23369
|
+
const location = record4(tool.locations?.[0]);
|
|
23310
23370
|
const path = typeof location.path === "string" ? location.path : void 0;
|
|
23311
23371
|
if (tool.kind === "edit" || tool.kind === "delete" || tool.kind === "move") this.rows([runLog.fileChange(path)]);
|
|
23312
23372
|
else if (tool.kind === "fetch") this.rows([runLog.tool("web_search")]);
|
|
@@ -23318,7 +23378,7 @@ var TurnTranscript = class {
|
|
|
23318
23378
|
};
|
|
23319
23379
|
function planEntries(value) {
|
|
23320
23380
|
if (!Array.isArray(value)) return [];
|
|
23321
|
-
return value.map(
|
|
23381
|
+
return value.map(record4).map((entry) => ({
|
|
23322
23382
|
content: clipText(String(entry.content ?? ""), 2e3),
|
|
23323
23383
|
priority: typeof entry.priority === "string" ? entry.priority : "medium",
|
|
23324
23384
|
status: typeof entry.status === "string" ? entry.status : "pending"
|
|
@@ -23326,7 +23386,7 @@ function planEntries(value) {
|
|
|
23326
23386
|
}
|
|
23327
23387
|
function toolContent(content) {
|
|
23328
23388
|
return content.map((block) => {
|
|
23329
|
-
const part =
|
|
23389
|
+
const part = record4(block);
|
|
23330
23390
|
if (part.type === "diff") {
|
|
23331
23391
|
return {
|
|
23332
23392
|
type: "diff",
|
|
@@ -23339,10 +23399,10 @@ function toolContent(content) {
|
|
|
23339
23399
|
});
|
|
23340
23400
|
}
|
|
23341
23401
|
function toolMeta(value) {
|
|
23342
|
-
const meta3 =
|
|
23402
|
+
const meta3 = record4(value);
|
|
23343
23403
|
const out = {};
|
|
23344
23404
|
if (meta3.lody !== void 0) out.lody = clip2(meta3.lody, 2e3);
|
|
23345
|
-
const claudeCode =
|
|
23405
|
+
const claudeCode = record4(meta3.claudeCode);
|
|
23346
23406
|
if (Object.keys(claudeCode).length) {
|
|
23347
23407
|
out.claudeCode = {
|
|
23348
23408
|
...typeof claudeCode.toolName === "string" ? { toolName: claudeCode.toolName } : {},
|
|
@@ -23366,7 +23426,7 @@ function clip2(value, max, depth = 0) {
|
|
|
23366
23426
|
|
|
23367
23427
|
// src/providers/cli/codex.ts
|
|
23368
23428
|
var CODEX = requireCliSpec("codex");
|
|
23369
|
-
var
|
|
23429
|
+
var record5 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
23370
23430
|
function toolItem(id, fields) {
|
|
23371
23431
|
return { event: "item", item: { itemId: `tool:${id}`, type: "tool_call", toolCallId: id, ...fields } };
|
|
23372
23432
|
}
|
|
@@ -23403,7 +23463,7 @@ function codexItemEvents(phase, item) {
|
|
|
23403
23463
|
})];
|
|
23404
23464
|
}
|
|
23405
23465
|
case "file_change": {
|
|
23406
|
-
const changes = Array.isArray(item.changes) ? item.changes.map(
|
|
23466
|
+
const changes = Array.isArray(item.changes) ? item.changes.map(record5) : [];
|
|
23407
23467
|
const paths = changes.map((change) => str(change.path)).filter((path) => Boolean(path));
|
|
23408
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`;
|
|
23409
23469
|
return [toolItem(id, {
|
|
@@ -23429,7 +23489,7 @@ function codexItemEvents(phase, item) {
|
|
|
23429
23489
|
})];
|
|
23430
23490
|
}
|
|
23431
23491
|
case "web_search": {
|
|
23432
|
-
const action =
|
|
23492
|
+
const action = record5(item.action);
|
|
23433
23493
|
const query = str(item.query) ?? str(action.query) ?? str(action.url) ?? "";
|
|
23434
23494
|
return [toolItem(id, {
|
|
23435
23495
|
title: query || "web_search",
|
|
@@ -23439,7 +23499,7 @@ function codexItemEvents(phase, item) {
|
|
|
23439
23499
|
})];
|
|
23440
23500
|
}
|
|
23441
23501
|
case "todo_list": {
|
|
23442
|
-
const entries = (Array.isArray(item.items) ? item.items.map(
|
|
23502
|
+
const entries = (Array.isArray(item.items) ? item.items.map(record5) : []).map((entry) => ({
|
|
23443
23503
|
content: clipText(String(entry.text ?? ""), 2e3),
|
|
23444
23504
|
priority: "medium",
|
|
23445
23505
|
status: entry.completed === true ? "completed" : "pending"
|
|
@@ -23735,9 +23795,9 @@ function claudeTranscriptPath(sessionId) {
|
|
|
23735
23795
|
}
|
|
23736
23796
|
function isPromptEntry(entry) {
|
|
23737
23797
|
if (entry.type !== "user" || entry.isSidechain === true || entry.isMeta === true) return false;
|
|
23738
|
-
const content =
|
|
23798
|
+
const content = record6(entry.message).content;
|
|
23739
23799
|
if (typeof content === "string") return content.trim().length > 0;
|
|
23740
|
-
return Array.isArray(content) && content.some((part) =>
|
|
23800
|
+
return Array.isArray(content) && content.some((part) => record6(part).type === "text");
|
|
23741
23801
|
}
|
|
23742
23802
|
function claudeForkBoundary(transcript, keepTurns) {
|
|
23743
23803
|
if (keepTurns <= 0) return void 0;
|
|
@@ -23804,10 +23864,10 @@ var claudeProvider = {
|
|
|
23804
23864
|
// `--resume <id>` for a chat this computer no longer has.
|
|
23805
23865
|
failureRules: [{ kind: "sessionMissing", pattern: /No conversation found with session ID/i }]
|
|
23806
23866
|
};
|
|
23807
|
-
var
|
|
23867
|
+
var record6 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
23808
23868
|
function toolResultText(content) {
|
|
23809
23869
|
if (typeof content === "string") return content;
|
|
23810
|
-
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");
|
|
23811
23871
|
return "";
|
|
23812
23872
|
}
|
|
23813
23873
|
var CLAUDE_TOOL_KINDS = {
|
|
@@ -23849,7 +23909,7 @@ function claudeToolItem(id, name, input2) {
|
|
|
23849
23909
|
title = path && `Edit ${path}`;
|
|
23850
23910
|
break;
|
|
23851
23911
|
case "MultiEdit":
|
|
23852
|
-
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));
|
|
23853
23913
|
title = path && `Edit ${path}`;
|
|
23854
23914
|
break;
|
|
23855
23915
|
case "Write":
|
|
@@ -23901,7 +23961,7 @@ function claudeToolItem(id, name, input2) {
|
|
|
23901
23961
|
};
|
|
23902
23962
|
}
|
|
23903
23963
|
function claudePlanItem(input2) {
|
|
23904
|
-
const todos = Array.isArray(input2.todos) ? input2.todos.map(
|
|
23964
|
+
const todos = Array.isArray(input2.todos) ? input2.todos.map(record6) : [];
|
|
23905
23965
|
return {
|
|
23906
23966
|
itemId: "plan",
|
|
23907
23967
|
type: "plan",
|
|
@@ -23942,13 +24002,13 @@ function claudeLineParser() {
|
|
|
23942
24002
|
return { ...base, display: [`\u25CF \u4F1A\u8BDD ${sessionId ?? ""}`, runLog.event("\u5F00\u59CB\u5904\u7406")] };
|
|
23943
24003
|
}
|
|
23944
24004
|
case "assistant": {
|
|
23945
|
-
const message =
|
|
24005
|
+
const message = record6(event.message);
|
|
23946
24006
|
const content = message.content ?? [];
|
|
23947
24007
|
const messageId = str(message.id) ?? `message${++unnamedMessages}`;
|
|
23948
24008
|
const rows = [];
|
|
23949
24009
|
const events = [];
|
|
23950
24010
|
for (const value of Array.isArray(content) ? content : []) {
|
|
23951
|
-
const part =
|
|
24011
|
+
const part = record6(value);
|
|
23952
24012
|
const index = blockCounts.get(messageId) ?? 0;
|
|
23953
24013
|
blockCounts.set(messageId, index + 1);
|
|
23954
24014
|
if (part.type === "text") {
|
|
@@ -23969,7 +24029,7 @@ function claudeLineParser() {
|
|
|
23969
24029
|
}
|
|
23970
24030
|
if (part.type !== "tool_use") continue;
|
|
23971
24031
|
const name = str(part.name) ?? "tool";
|
|
23972
|
-
const input2 =
|
|
24032
|
+
const input2 = record6(part.input);
|
|
23973
24033
|
const id = str(part.id) ?? "";
|
|
23974
24034
|
if (id && name === "TodoWrite") {
|
|
23975
24035
|
plans.add(id);
|
|
@@ -23992,11 +24052,11 @@ function claudeLineParser() {
|
|
|
23992
24052
|
return { ...base, display: rows, ...events.length ? { chatEvents: events } : {} };
|
|
23993
24053
|
}
|
|
23994
24054
|
case "user": {
|
|
23995
|
-
const content =
|
|
24055
|
+
const content = record6(event.message).content ?? [];
|
|
23996
24056
|
const rows = [];
|
|
23997
24057
|
const events = [];
|
|
23998
24058
|
for (const value of Array.isArray(content) ? content : []) {
|
|
23999
|
-
const part =
|
|
24059
|
+
const part = record6(value);
|
|
24000
24060
|
if (part.type !== "tool_result") continue;
|
|
24001
24061
|
const id = str(part.tool_use_id) ?? "";
|
|
24002
24062
|
const tool = tools.get(id);
|
|
@@ -24054,8 +24114,8 @@ function toolPath(input2, partial2) {
|
|
|
24054
24114
|
const parsed = input2 && typeof input2 === "object" && Object.keys(input2).length ? input2 : tryJson(partial2) ?? {};
|
|
24055
24115
|
return str(parsed.file_path) ?? str(parsed.notebook_path) ?? str(parsed.path);
|
|
24056
24116
|
}
|
|
24057
|
-
var
|
|
24058
|
-
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 ?? "");
|
|
24059
24119
|
function claudeChatProvider(attachments) {
|
|
24060
24120
|
let messageID = "";
|
|
24061
24121
|
let messageSequence = 0;
|
|
@@ -24085,14 +24145,14 @@ function claudeChatProvider(attachments) {
|
|
|
24085
24145
|
const events = [];
|
|
24086
24146
|
if (envelope.parent_tool_use_id) return { ...base, display: [] };
|
|
24087
24147
|
if (envelope.type === "stream_event") {
|
|
24088
|
-
const event =
|
|
24148
|
+
const event = record7(envelope.event);
|
|
24089
24149
|
const index = Number(event.index ?? 0);
|
|
24090
24150
|
if (event.type === "message_start") {
|
|
24091
|
-
messageID = str(
|
|
24151
|
+
messageID = str(record7(event.message).id) ?? `message:${++messageSequence}`;
|
|
24092
24152
|
blocks.clear();
|
|
24093
24153
|
} else if (event.type === "content_block_start") {
|
|
24094
24154
|
if (!messageID) messageID = `message:${++messageSequence}`;
|
|
24095
|
-
const part =
|
|
24155
|
+
const part = record7(event.content_block);
|
|
24096
24156
|
const type = part.type === "tool_use" ? "tool_call" : part.type === "thinking" ? "thought" : "text";
|
|
24097
24157
|
if (!["tool_use", "thinking", "text"].includes(String(part.type))) return { ...base, display: [] };
|
|
24098
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: "" };
|
|
@@ -24101,7 +24161,7 @@ function claudeChatProvider(attachments) {
|
|
|
24101
24161
|
events.push(asItem(block, "in_progress"));
|
|
24102
24162
|
} else if (event.type === "content_block_delta") {
|
|
24103
24163
|
const block = blocks.get(index);
|
|
24104
|
-
const delta =
|
|
24164
|
+
const delta = record7(event.delta);
|
|
24105
24165
|
if (!block) return { ...base, display: [] };
|
|
24106
24166
|
if (delta.type === "text_delta" || delta.type === "thinking_delta") {
|
|
24107
24167
|
const text3 = String(delta.text ?? delta.thinking ?? "");
|
|
@@ -24118,11 +24178,11 @@ function claudeChatProvider(attachments) {
|
|
|
24118
24178
|
if (block && block.type !== "tool_call") events.push(asItem(block, "completed"));
|
|
24119
24179
|
}
|
|
24120
24180
|
} else if (envelope.type === "assistant") {
|
|
24121
|
-
const message =
|
|
24181
|
+
const message = record7(envelope.message);
|
|
24122
24182
|
const id = str(message.id) || messageID || `message:${++messageSequence}`;
|
|
24123
24183
|
const parts = Array.isArray(message.content) ? message.content : [];
|
|
24124
24184
|
parts.forEach((value, index) => {
|
|
24125
|
-
const part =
|
|
24185
|
+
const part = record7(value);
|
|
24126
24186
|
if (!["text", "thinking", "tool_use"].includes(String(part.type))) return;
|
|
24127
24187
|
const type = part.type === "tool_use" ? "tool_call" : part.type === "thinking" ? "thought" : "text";
|
|
24128
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: "" };
|
|
@@ -24131,9 +24191,9 @@ function claudeChatProvider(attachments) {
|
|
|
24131
24191
|
events.push(asItem(block, type === "tool_call" ? "in_progress" : "completed"));
|
|
24132
24192
|
});
|
|
24133
24193
|
} else if (envelope.type === "user") {
|
|
24134
|
-
const message =
|
|
24194
|
+
const message = record7(envelope.message);
|
|
24135
24195
|
for (const value of Array.isArray(message.content) ? message.content : []) {
|
|
24136
|
-
const part =
|
|
24196
|
+
const part = record7(value);
|
|
24137
24197
|
if (part.type !== "tool_result") continue;
|
|
24138
24198
|
const id = str(part.tool_use_id);
|
|
24139
24199
|
if (!id) continue;
|
|
@@ -24184,7 +24244,7 @@ var ECHO_CALLBACK = /echo_report_task_progress/;
|
|
|
24184
24244
|
var PROTOCOL_VERSION2 = 1;
|
|
24185
24245
|
var READ_ONLY_KINDS = /* @__PURE__ */ new Set(["read", "search", "think"]);
|
|
24186
24246
|
var EDIT_KINDS = /* @__PURE__ */ new Set(["edit", "delete", "move"]);
|
|
24187
|
-
var
|
|
24247
|
+
var record8 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
24188
24248
|
function acpErrorText(error62, dialect) {
|
|
24189
24249
|
const message = str(error62?.message) ?? "ACP \u8BF7\u6C42\u5931\u8D25";
|
|
24190
24250
|
const data = error62?.data;
|
|
@@ -24195,8 +24255,8 @@ function acpErrorText(error62, dialect) {
|
|
|
24195
24255
|
function contentText(content) {
|
|
24196
24256
|
if (!Array.isArray(content)) return "";
|
|
24197
24257
|
return content.map((item) => {
|
|
24198
|
-
const part =
|
|
24199
|
-
const inner =
|
|
24258
|
+
const part = record8(item);
|
|
24259
|
+
const inner = record8(part.content);
|
|
24200
24260
|
return str(inner.text) ?? str(part.text) ?? "";
|
|
24201
24261
|
}).filter(Boolean).join("\n");
|
|
24202
24262
|
}
|
|
@@ -24220,14 +24280,14 @@ function rawStdout(rawOutput) {
|
|
|
24220
24280
|
return found.join("\n");
|
|
24221
24281
|
}
|
|
24222
24282
|
function permissionAllowed(params, request) {
|
|
24223
|
-
const call =
|
|
24283
|
+
const call = record8(params.toolCall);
|
|
24224
24284
|
const title = str(call.title) ?? "";
|
|
24225
24285
|
const kind = str(call.kind) ?? "";
|
|
24226
24286
|
const level = accessLevel(request);
|
|
24227
24287
|
return level === "bypassPermissions" || READ_ONLY_KINDS.has(kind) || level !== "restricted" && kind === "fetch" || level === "acceptEdits" && EDIT_KINDS.has(kind) || ECHO_CALLBACK.test(title);
|
|
24228
24288
|
}
|
|
24229
24289
|
function permissionOutcome(params, request) {
|
|
24230
|
-
const options = Array.isArray(params.options) ? params.options.map(
|
|
24290
|
+
const options = Array.isArray(params.options) ? params.options.map(record8) : [];
|
|
24231
24291
|
const kind = permissionAllowed(params, request) ? "allow_once" : "reject_once";
|
|
24232
24292
|
const option = options.find((item) => str(item.kind) === kind);
|
|
24233
24293
|
return option ? { outcome: { outcome: "selected", optionId: option.optionId } } : { outcome: { outcome: "cancelled" } };
|
|
@@ -24357,7 +24417,7 @@ function createAcpProvider(row) {
|
|
|
24357
24417
|
const phase = typeof message.id === "number" ? phases.get(message.id) : void 0;
|
|
24358
24418
|
if (!phase) return { display: [] };
|
|
24359
24419
|
phases.delete(message.id);
|
|
24360
|
-
const result =
|
|
24420
|
+
const result = record8(message.result);
|
|
24361
24421
|
if (phase === "open") {
|
|
24362
24422
|
if (message.error) return onOpenError(message);
|
|
24363
24423
|
loading = false;
|
|
@@ -24404,8 +24464,8 @@ function createAcpProvider(row) {
|
|
|
24404
24464
|
const onToolCall = (update) => {
|
|
24405
24465
|
const id = str(update.toolCallId) ?? "";
|
|
24406
24466
|
const known = tools.get(id);
|
|
24407
|
-
const input2 =
|
|
24408
|
-
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) : [];
|
|
24409
24469
|
const tool = known ?? { kind: "other", title: "tool" };
|
|
24410
24470
|
tool.kind = str(update.kind) ?? tool.kind;
|
|
24411
24471
|
if (!known) tool.title = str(update.title) ?? tool.title;
|
|
@@ -24450,7 +24510,7 @@ function createAcpProvider(row) {
|
|
|
24450
24510
|
return first;
|
|
24451
24511
|
};
|
|
24452
24512
|
const onUpdate = (params) => {
|
|
24453
|
-
const raw =
|
|
24513
|
+
const raw = record8(params.update);
|
|
24454
24514
|
const kind = str(raw.sessionUpdate);
|
|
24455
24515
|
const update = (kind === "tool_call" || kind === "tool_call_update") && dialect.normalizeToolUpdate ? dialect.normalizeToolUpdate(raw) : raw;
|
|
24456
24516
|
if (loading) {
|
|
@@ -24458,7 +24518,7 @@ function createAcpProvider(row) {
|
|
|
24458
24518
|
return withItems({ display: [] });
|
|
24459
24519
|
}
|
|
24460
24520
|
transcript.update(update);
|
|
24461
|
-
const text3 = str(
|
|
24521
|
+
const text3 = str(record8(update.content).text);
|
|
24462
24522
|
switch (kind) {
|
|
24463
24523
|
case "agent_message_chunk": {
|
|
24464
24524
|
if (!text3) return withItems({ display: [] });
|
|
@@ -24481,7 +24541,7 @@ function createAcpProvider(row) {
|
|
|
24481
24541
|
}
|
|
24482
24542
|
};
|
|
24483
24543
|
const onRequest = (message) => {
|
|
24484
|
-
const params =
|
|
24544
|
+
const params = record8(message.params);
|
|
24485
24545
|
if (message.method === "session/request_permission") {
|
|
24486
24546
|
answer(message.id, permissionOutcome(params, request));
|
|
24487
24547
|
return { display: [] };
|
|
@@ -24521,7 +24581,7 @@ function createAcpProvider(row) {
|
|
|
24521
24581
|
if (finished && message.id === void 0) return { display: [] };
|
|
24522
24582
|
if (message.method && message.id !== void 0) return onRequest(message);
|
|
24523
24583
|
if (message.method) {
|
|
24524
|
-
const params =
|
|
24584
|
+
const params = record8(message.params);
|
|
24525
24585
|
if (message.method === "session/update") return onUpdate(params);
|
|
24526
24586
|
const rows = dialect.notification?.(message.method, params);
|
|
24527
24587
|
return { display: rows ?? [] };
|
|
@@ -25352,8 +25412,8 @@ var OrphanRegistry = class {
|
|
|
25352
25412
|
file;
|
|
25353
25413
|
records = /* @__PURE__ */ new Map();
|
|
25354
25414
|
writing = Promise.resolve();
|
|
25355
|
-
add(
|
|
25356
|
-
this.records.set(
|
|
25415
|
+
add(record10) {
|
|
25416
|
+
this.records.set(record10.runId, record10);
|
|
25357
25417
|
this.persist();
|
|
25358
25418
|
}
|
|
25359
25419
|
remove(runId) {
|
|
@@ -25377,12 +25437,12 @@ var OrphanRegistry = class {
|
|
|
25377
25437
|
return [];
|
|
25378
25438
|
}
|
|
25379
25439
|
const reaped = [];
|
|
25380
|
-
for (const
|
|
25381
|
-
if (!
|
|
25382
|
-
const command = await commandOf(
|
|
25383
|
-
if (command && command.includes(basename(
|
|
25384
|
-
await killProcessTree(
|
|
25385
|
-
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);
|
|
25386
25446
|
}
|
|
25387
25447
|
}
|
|
25388
25448
|
this.records.clear();
|
|
@@ -25989,7 +26049,7 @@ var RunTranscript = class _RunTranscript {
|
|
|
25989
26049
|
* that ended before the run did: it reads as `lost`.
|
|
25990
26050
|
*/
|
|
25991
26051
|
static fromFile(value) {
|
|
25992
|
-
const data =
|
|
26052
|
+
const data = record9(value);
|
|
25993
26053
|
if (data.v !== 1 || typeof data.run_id !== "string" || !data.run_id || !Array.isArray(data.items) || !Array.isArray(data.lines)) return void 0;
|
|
25994
26054
|
const transcript = new _RunTranscript({
|
|
25995
26055
|
runId: data.run_id,
|
|
@@ -26005,7 +26065,7 @@ var RunTranscript = class _RunTranscript {
|
|
|
26005
26065
|
transcript.revision = whole(data.revision);
|
|
26006
26066
|
transcript.itemRevisions = false;
|
|
26007
26067
|
for (const value2 of data.items) {
|
|
26008
|
-
const item =
|
|
26068
|
+
const item = record9(value2);
|
|
26009
26069
|
if (typeof item.itemId !== "string" || !item.itemId || transcript.positions.has(item.itemId)) continue;
|
|
26010
26070
|
transcript.positions.set(item.itemId, transcript.entries.length);
|
|
26011
26071
|
transcript.entries.push({ rev: 0, item });
|
|
@@ -26246,7 +26306,7 @@ function whole(value) {
|
|
|
26246
26306
|
function finite(value) {
|
|
26247
26307
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
26248
26308
|
}
|
|
26249
|
-
function
|
|
26309
|
+
function record9(value) {
|
|
26250
26310
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
26251
26311
|
}
|
|
26252
26312
|
function errorCode(error62) {
|
|
@@ -26861,6 +26921,10 @@ var AcpChatSession = class {
|
|
|
26861
26921
|
const session = await this.ensureSession(turn, connection);
|
|
26862
26922
|
if (turn.cancelRequested) return this.cancelled(turn);
|
|
26863
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
|
+
}
|
|
26864
26928
|
await this.applySettings(turn, connection, session);
|
|
26865
26929
|
if (turn.cancelRequested) return this.cancelled(turn);
|
|
26866
26930
|
let blocks = await this.promptBlocks(request, connection);
|
|
@@ -27038,17 +27102,17 @@ var AcpChatSession = class {
|
|
|
27038
27102
|
const options = permissionOptions(params.options);
|
|
27039
27103
|
if (prompts && options.length && this.forwardsPermission(params, prompts)) {
|
|
27040
27104
|
const requestId = randomUUID3();
|
|
27041
|
-
const call =
|
|
27105
|
+
const call = record4(params.toolCall);
|
|
27042
27106
|
const toolCall = typeof call.toolCallId === "string" && call.toolCallId ? call : { ...call, toolCallId: `permission:${requestId}` };
|
|
27043
|
-
const meta3 =
|
|
27107
|
+
const meta3 = record4(params._meta);
|
|
27044
27108
|
return this.ask(turn, requestId, toolCall, options, Object.keys(meta3).length ? meta3 : void 0, signal2).then((outcome2) => ({ outcome: outcome2 }));
|
|
27045
27109
|
}
|
|
27046
27110
|
const access = turn.request.access;
|
|
27047
27111
|
const outcome = permissionOutcome(params, access === "restricted" ? { permissionMode: "restricted" } : { permissionMode: "full", access: access === "default" ? "read-only" : access });
|
|
27048
|
-
const selected =
|
|
27049
|
-
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;
|
|
27050
27114
|
if (typeof option?.kind === "string" && option.kind.startsWith("reject")) {
|
|
27051
|
-
const call =
|
|
27115
|
+
const call = record4(params.toolCall);
|
|
27052
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`);
|
|
27053
27117
|
}
|
|
27054
27118
|
return outcome;
|
|
@@ -27061,7 +27125,7 @@ var AcpChatSession = class {
|
|
|
27061
27125
|
forwardsPermission(params, prompts) {
|
|
27062
27126
|
if (isAskUserQuestionPermission(params)) return true;
|
|
27063
27127
|
if (prompts.permissions === "none") return false;
|
|
27064
|
-
const title =
|
|
27128
|
+
const title = record4(params.toolCall).title;
|
|
27065
27129
|
if (ECHO_CALLBACK.test(typeof title === "string" ? title : "")) return false;
|
|
27066
27130
|
if (prompts.permissions === "all") return true;
|
|
27067
27131
|
return !permissionAllowed(params, { permissionMode: "full", access: "acceptEdits" });
|
|
@@ -27217,7 +27281,7 @@ function isArchivedSessionError(error62) {
|
|
|
27217
27281
|
}
|
|
27218
27282
|
function permissionOptions(value) {
|
|
27219
27283
|
if (!Array.isArray(value)) return [];
|
|
27220
|
-
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 : "" }] : []);
|
|
27221
27285
|
}
|
|
27222
27286
|
|
|
27223
27287
|
// src/acp/chat-host.ts
|
|
@@ -27349,6 +27413,34 @@ var AcpChatHost = class {
|
|
|
27349
27413
|
}
|
|
27350
27414
|
};
|
|
27351
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
|
+
|
|
27352
27444
|
// src/runs/run-supervisor.ts
|
|
27353
27445
|
var COMPLETION_EXIT_GRACE_MS = 15e3;
|
|
27354
27446
|
var EXIT_OUTPUT_GRACE_MS = 2e3;
|
|
@@ -27515,6 +27607,14 @@ var RunSupervisor = class {
|
|
|
27515
27607
|
this.preparing.delete(payload.run_id);
|
|
27516
27608
|
}
|
|
27517
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
|
+
}
|
|
27518
27618
|
async startPrepared(payload, signal2) {
|
|
27519
27619
|
if (this.active.has(payload.run_id) || this.acpRuns.has(payload.run_id) || this.recent.has(payload.run_id)) {
|
|
27520
27620
|
this.logger.info("run-duplicate-ignored", { runId: payload.run_id });
|
|
@@ -27530,6 +27630,7 @@ var RunSupervisor = class {
|
|
|
27530
27630
|
this.remember({ runId: payload.run_id, sessionKey, tail: new TerminalTailBuffer(), transcript, finishedAt: Date.now(), status: "failed", chat: !!payload.chat_session_id });
|
|
27531
27631
|
await this.report(payload.run_id, { status: "failed", error: failure2.message, failure_kind: failure2.kind, duration_ms: 0 });
|
|
27532
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");
|
|
27533
27634
|
if (this.sessionBusy(sessionKey, payload.run_id)) {
|
|
27534
27635
|
return refuse("\u672C\u673A\u8BE5\u4F1A\u8BDD\u5DF2\u6709\u4EFB\u52A1\u5728\u8FD0\u884C");
|
|
27535
27636
|
}
|
|
@@ -27571,7 +27672,7 @@ var RunSupervisor = class {
|
|
|
27571
27672
|
}
|
|
27572
27673
|
return refuse(`\u9644\u4EF6\u4E0B\u8F7D\u5931\u8D25\uFF1A${errorMessage2(error62)}`);
|
|
27573
27674
|
}
|
|
27574
|
-
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}
|
|
27575
27676
|
|
|
27576
27677
|
${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
27577
27678
|
const request = {
|
|
@@ -27585,6 +27686,7 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
27585
27686
|
};
|
|
27586
27687
|
if (payload.chat_session_id) {
|
|
27587
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");
|
|
27588
27690
|
if (acpSpec) {
|
|
27589
27691
|
const outcome = await this.startAcpChat(payload, { spec: acpSpec, cli, sessionKey, workdir, prompt, turn, permissionMode, memoryEnv, signal: signal2, refuse, transcript });
|
|
27590
27692
|
if (outcome === "handled") return;
|
|
@@ -27884,7 +27986,7 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
27884
27986
|
await refuse(cliFailure("cliMissing", { label: cli.label, ...cli.installHint ? { installHint: cli.installHint } : {} }));
|
|
27885
27987
|
return "handled";
|
|
27886
27988
|
}
|
|
27887
|
-
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` };
|
|
27888
27990
|
await refuse({ kind: "startFailed", message: error62.message });
|
|
27889
27991
|
return "handled";
|
|
27890
27992
|
}
|
|
@@ -27916,6 +28018,7 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
27916
28018
|
let reported = { pid: 0, sessionId: "" };
|
|
27917
28019
|
const result = await this.acpChats.run(sessionKey, spec, {
|
|
27918
28020
|
runId,
|
|
28021
|
+
...payload.cli_command ? { command: payload.cli_command } : {},
|
|
27919
28022
|
prompt: context.prompt,
|
|
27920
28023
|
attachments,
|
|
27921
28024
|
sessionId: payload.session_id,
|
|
@@ -27926,7 +28029,7 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
27926
28029
|
fast: turn.fast,
|
|
27927
28030
|
workdir,
|
|
27928
28031
|
notes,
|
|
27929
|
-
...turn.prompts ? { prompts: turn.prompts } : {}
|
|
28032
|
+
...turn.prompts && (!payload.cli_command || payload.cli_command_interactive) ? { prompts: turn.prompts } : {}
|
|
27930
28033
|
}, {
|
|
27931
28034
|
events: (events) => {
|
|
27932
28035
|
forwarder.push(events);
|
|
@@ -27944,6 +28047,11 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
27944
28047
|
});
|
|
27945
28048
|
}
|
|
27946
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
|
+
}
|
|
27947
28055
|
await forwarder.drain();
|
|
27948
28056
|
this.acpRuns.delete(runId);
|
|
27949
28057
|
const durationMs = Date.now() - run.startedAt;
|
|
@@ -28514,9 +28622,9 @@ var GatewayClient = class {
|
|
|
28514
28622
|
};
|
|
28515
28623
|
|
|
28516
28624
|
// src/workspace/directory-browser.ts
|
|
28517
|
-
import { readdir as readdir3, realpath as realpath3, stat as stat7 } from "node:fs/promises";
|
|
28625
|
+
import { mkdir as mkdir9, readdir as readdir3, realpath as realpath3, stat as stat7 } from "node:fs/promises";
|
|
28518
28626
|
import { homedir as homedir11 } from "node:os";
|
|
28519
|
-
import { dirname as dirname9, parse as parse3, resolve as resolve6 } from "node:path";
|
|
28627
|
+
import { dirname as dirname9, isAbsolute as isAbsolute5, parse as parse3, resolve as resolve6 } from "node:path";
|
|
28520
28628
|
var MAX_ENTRIES = 1e3;
|
|
28521
28629
|
async function listDirectory(requested, allowedRoots) {
|
|
28522
28630
|
const raw = requested.trim().replace(/^~(?=$|[\\/])/, homedir11()) || homedir11();
|
|
@@ -28549,12 +28657,35 @@ async function listDirectory(requested, allowedRoots) {
|
|
|
28549
28657
|
places
|
|
28550
28658
|
};
|
|
28551
28659
|
}
|
|
28660
|
+
async function createDirectory(parentRequested, name) {
|
|
28661
|
+
const parentInput = parentRequested.trim();
|
|
28662
|
+
if (!parentInput || !isAbsolute5(parentInput)) throw new Error("\u4E0A\u7EA7\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");
|
|
28663
|
+
if (!name || name !== name.trim() || name === "." || name === ".." || name.includes("/") || name.includes("\\") || Array.from(name).length > 255 || Array.from(name).some((character) => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127)) {
|
|
28664
|
+
throw new Error("\u8BF7\u8F93\u5165\u6709\u6548\u7684\u6587\u4EF6\u5939\u540D\u79F0");
|
|
28665
|
+
}
|
|
28666
|
+
const parent = await realpath3(resolve6(parentInput)).catch(() => {
|
|
28667
|
+
throw new Error(`\u4E0A\u7EA7\u76EE\u5F55\u4E0D\u5B58\u5728\uFF1A${parentRequested}`);
|
|
28668
|
+
});
|
|
28669
|
+
if (!(await stat7(parent)).isDirectory()) throw new Error("\u4E0A\u7EA7\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55");
|
|
28670
|
+
const path = resolve6(parent, name);
|
|
28671
|
+
if (dirname9(path) !== parent) throw new Error("\u6587\u4EF6\u5939\u540D\u79F0\u65E0\u6548");
|
|
28672
|
+
try {
|
|
28673
|
+
await mkdir9(path);
|
|
28674
|
+
} catch (error62) {
|
|
28675
|
+
const code = error62.code;
|
|
28676
|
+
if (code === "EEXIST") throw new Error("\u8BE5\u6587\u4EF6\u5939\u5DF2\u5B58\u5728");
|
|
28677
|
+
if (code === "EACCES" || code === "EPERM") throw new Error("\u6CA1\u6709\u6743\u9650\u5728\u6B64\u4F4D\u7F6E\u521B\u5EFA\u6587\u4EF6\u5939");
|
|
28678
|
+
if (code === "ENOENT") throw new Error("\u4E0A\u7EA7\u76EE\u5F55\u4E0D\u5B58\u5728");
|
|
28679
|
+
throw error62;
|
|
28680
|
+
}
|
|
28681
|
+
return { path };
|
|
28682
|
+
}
|
|
28552
28683
|
|
|
28553
28684
|
// src/workspace/workspace-manager.ts
|
|
28554
28685
|
import { spawn as spawn13 } from "node:child_process";
|
|
28555
|
-
import {
|
|
28556
|
-
import { homedir as homedir12
|
|
28557
|
-
import { isAbsolute as
|
|
28686
|
+
import { opendir, realpath as realpath4, stat as stat8 } from "node:fs/promises";
|
|
28687
|
+
import { homedir as homedir12 } from "node:os";
|
|
28688
|
+
import { isAbsolute as isAbsolute6, relative as relative3, resolve as resolve7 } from "node:path";
|
|
28558
28689
|
var MAX_NODES = 2e3;
|
|
28559
28690
|
var MAX_DIRECTORY_ENTRIES = 12e3;
|
|
28560
28691
|
var IGNORED_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
@@ -28588,193 +28719,13 @@ var WorkspaceManager = class {
|
|
|
28588
28719
|
const nodes = await this.scanTree(rootPath, request.max_depth, request.scan_roots);
|
|
28589
28720
|
return { root_path: rootPath, nodes, truncated: nodes.length >= MAX_NODES, duration_ms: Date.now() - startedAt };
|
|
28590
28721
|
}
|
|
28591
|
-
/** Creates missing folders, clones missing repos, fast-forwards clean ones. */
|
|
28592
|
-
async sync(request) {
|
|
28593
|
-
const startedAt = Date.now();
|
|
28594
|
-
const rootPath = this.validateRootPath(request.root_path);
|
|
28595
|
-
const results = await this.syncTree(rootPath, request);
|
|
28596
|
-
const failed = results.some((result) => result.status === "failed");
|
|
28597
|
-
return {
|
|
28598
|
-
root_path: rootPath,
|
|
28599
|
-
results,
|
|
28600
|
-
...failed ? { error: "\u90E8\u5206\u76EE\u5F55\u6216\u4ED3\u5E93\u540C\u6B65\u5931\u8D25" } : {},
|
|
28601
|
-
duration_ms: Date.now() - startedAt
|
|
28602
|
-
};
|
|
28603
|
-
}
|
|
28604
28722
|
validateRootPath(value) {
|
|
28605
28723
|
const raw = value.trim().replace(/^~(?=$|[\\/])/, homedir12());
|
|
28606
28724
|
const root2 = resolve7(raw);
|
|
28607
|
-
if (!
|
|
28725
|
+
if (!isAbsolute6(raw)) throw new Error("\u6839\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");
|
|
28608
28726
|
if (relative3(root2, resolve7(root2, "..")) === "") throw new Error("\u4E0D\u80FD\u628A\u6587\u4EF6\u7CFB\u7EDF\u6839\u76EE\u5F55\u4F5C\u4E3A\u76EE\u5F55\u6839");
|
|
28609
28727
|
return root2;
|
|
28610
28728
|
}
|
|
28611
|
-
async syncTree(rootPath, request) {
|
|
28612
|
-
await mkdir9(rootPath, { recursive: true });
|
|
28613
|
-
await addAllowedRoot(this.config, rootPath);
|
|
28614
|
-
const results = [];
|
|
28615
|
-
const requestedPaths = /* @__PURE__ */ new Set();
|
|
28616
|
-
for (const directory of request.directories) {
|
|
28617
|
-
const relativePath = this.cleanRelativePath(directory);
|
|
28618
|
-
if (requestedPaths.has(relativePath)) continue;
|
|
28619
|
-
requestedPaths.add(relativePath);
|
|
28620
|
-
const target = this.resolveWithinRoot(rootPath, relativePath);
|
|
28621
|
-
try {
|
|
28622
|
-
const metadata = await stat8(target).catch(() => void 0);
|
|
28623
|
-
if (metadata) {
|
|
28624
|
-
if (!metadata.isDirectory()) {
|
|
28625
|
-
throw new Error("The existing workspace path is not a directory");
|
|
28626
|
-
}
|
|
28627
|
-
results.push({
|
|
28628
|
-
relative_path: relativePath,
|
|
28629
|
-
status: "skipped",
|
|
28630
|
-
kind: "directory",
|
|
28631
|
-
action: "skip",
|
|
28632
|
-
message: "\u76EE\u5F55\u5DF2\u5B58\u5728"
|
|
28633
|
-
});
|
|
28634
|
-
continue;
|
|
28635
|
-
}
|
|
28636
|
-
await mkdir9(target, { recursive: true });
|
|
28637
|
-
results.push({
|
|
28638
|
-
relative_path: relativePath,
|
|
28639
|
-
status: "created",
|
|
28640
|
-
kind: "directory",
|
|
28641
|
-
action: "mkdir",
|
|
28642
|
-
message: "\u76EE\u5F55\u5DF2\u521B\u5EFA"
|
|
28643
|
-
});
|
|
28644
|
-
} catch (error62) {
|
|
28645
|
-
results.push({
|
|
28646
|
-
relative_path: relativePath,
|
|
28647
|
-
status: "failed",
|
|
28648
|
-
kind: "directory",
|
|
28649
|
-
action: "mkdir",
|
|
28650
|
-
error: this.message(error62)
|
|
28651
|
-
});
|
|
28652
|
-
}
|
|
28653
|
-
}
|
|
28654
|
-
const authEnvironment = await this.createGitAuthEnvironment(request.git_auth);
|
|
28655
|
-
try {
|
|
28656
|
-
for (const repo of request.repos) {
|
|
28657
|
-
const relativePath = this.cleanRelativePath(repo.relative_path);
|
|
28658
|
-
try {
|
|
28659
|
-
results.push(await this.syncRepository(rootPath, relativePath, repo.git_url?.trim() || void 0, repo.branch?.trim() || void 0, request.timeout_s, authEnvironment?.env));
|
|
28660
|
-
} catch (error62) {
|
|
28661
|
-
results.push({
|
|
28662
|
-
relative_path: relativePath,
|
|
28663
|
-
status: "failed",
|
|
28664
|
-
kind: "repo",
|
|
28665
|
-
action: "sync",
|
|
28666
|
-
error: this.message(error62)
|
|
28667
|
-
});
|
|
28668
|
-
}
|
|
28669
|
-
}
|
|
28670
|
-
} finally {
|
|
28671
|
-
await authEnvironment?.cleanup();
|
|
28672
|
-
}
|
|
28673
|
-
return results;
|
|
28674
|
-
}
|
|
28675
|
-
async syncRepository(rootPath, relativePath, gitUrl, branch, timeoutSeconds, gitEnvironment) {
|
|
28676
|
-
const target = this.resolveWithinRoot(rootPath, relativePath);
|
|
28677
|
-
let created = false;
|
|
28678
|
-
let metadata;
|
|
28679
|
-
try {
|
|
28680
|
-
metadata = await stat8(target);
|
|
28681
|
-
} catch {
|
|
28682
|
-
}
|
|
28683
|
-
if (!metadata) {
|
|
28684
|
-
if (!gitUrl) throw new Error("A missing repository needs a Git remote URL");
|
|
28685
|
-
await mkdir9(resolve7(target, ".."), { recursive: true });
|
|
28686
|
-
const cloneArgs = branch ? ["clone", "--branch", branch, "--single-branch", gitUrl, target] : ["clone", gitUrl, target];
|
|
28687
|
-
await this.runGit(cloneArgs, rootPath, timeoutSeconds, false, gitEnvironment);
|
|
28688
|
-
created = true;
|
|
28689
|
-
} else {
|
|
28690
|
-
if (!metadata.isDirectory()) throw new Error("The repository path is not a directory");
|
|
28691
|
-
if (!await this.isGitRepository(target, timeoutSeconds)) {
|
|
28692
|
-
throw new Error("The existing directory is not a Git repository");
|
|
28693
|
-
}
|
|
28694
|
-
if (gitUrl) {
|
|
28695
|
-
const currentOrigin = (await this.runGit(["config", "--get", "remote.origin.url"], target, timeoutSeconds, true)).stdout.trim();
|
|
28696
|
-
if (currentOrigin && currentOrigin !== gitUrl) {
|
|
28697
|
-
throw new Error("The existing repository origin does not match the configured Git URL");
|
|
28698
|
-
}
|
|
28699
|
-
}
|
|
28700
|
-
const worktree = await this.runGit(["status", "--porcelain"], target, timeoutSeconds);
|
|
28701
|
-
if (worktree.stdout.trim()) {
|
|
28702
|
-
return {
|
|
28703
|
-
relative_path: relativePath,
|
|
28704
|
-
status: "skipped",
|
|
28705
|
-
kind: "repo",
|
|
28706
|
-
action: "skip",
|
|
28707
|
-
message: "\u4ED3\u5E93\u5B58\u5728\u672A\u63D0\u4EA4\u7684\u672C\u5730\u4FEE\u6539"
|
|
28708
|
-
};
|
|
28709
|
-
}
|
|
28710
|
-
if (branch) {
|
|
28711
|
-
const currentBranch = await this.runGit(["branch", "--show-current"], target, timeoutSeconds);
|
|
28712
|
-
if (currentBranch.stdout.trim() !== branch) {
|
|
28713
|
-
return {
|
|
28714
|
-
relative_path: relativePath,
|
|
28715
|
-
status: "skipped",
|
|
28716
|
-
kind: "repo",
|
|
28717
|
-
action: "skip",
|
|
28718
|
-
message: `\u5F53\u524D\u5206\u652F ${currentBranch.stdout.trim() || "(detached)"} \u4E0E\u76EE\u6807\u5206\u652F ${branch} \u4E0D\u4E00\u81F4`
|
|
28719
|
-
};
|
|
28720
|
-
}
|
|
28721
|
-
}
|
|
28722
|
-
}
|
|
28723
|
-
await this.runGit(["fetch", "--prune", "origin"], target, timeoutSeconds, false, gitEnvironment);
|
|
28724
|
-
if (branch) {
|
|
28725
|
-
const remoteBranch = await this.runGit(
|
|
28726
|
-
["show-ref", "--verify", "--quiet", `refs/remotes/origin/${branch}`],
|
|
28727
|
-
target,
|
|
28728
|
-
timeoutSeconds,
|
|
28729
|
-
true
|
|
28730
|
-
);
|
|
28731
|
-
if (remoteBranch.exitCode !== 0) {
|
|
28732
|
-
return {
|
|
28733
|
-
relative_path: relativePath,
|
|
28734
|
-
status: "skipped",
|
|
28735
|
-
kind: "repo",
|
|
28736
|
-
action: "skip",
|
|
28737
|
-
message: `\u8FDC\u7AEF\u5206\u652F origin/${branch} \u4E0D\u5B58\u5728`
|
|
28738
|
-
};
|
|
28739
|
-
}
|
|
28740
|
-
if (!created) {
|
|
28741
|
-
const currentCommit = await this.runGit(["rev-parse", "HEAD"], target, timeoutSeconds);
|
|
28742
|
-
const remoteCommit = await this.runGit(["rev-parse", `origin/${branch}`], target, timeoutSeconds);
|
|
28743
|
-
if (currentCommit.stdout.trim() === remoteCommit.stdout.trim()) {
|
|
28744
|
-
return {
|
|
28745
|
-
relative_path: relativePath,
|
|
28746
|
-
status: "skipped",
|
|
28747
|
-
kind: "repo",
|
|
28748
|
-
action: "skip",
|
|
28749
|
-
message: "\u4ED3\u5E93\u5DF2\u662F\u6700\u65B0"
|
|
28750
|
-
};
|
|
28751
|
-
}
|
|
28752
|
-
const fastForward = await this.runGit(
|
|
28753
|
-
["merge-base", "--is-ancestor", "HEAD", `origin/${branch}`],
|
|
28754
|
-
target,
|
|
28755
|
-
timeoutSeconds,
|
|
28756
|
-
true
|
|
28757
|
-
);
|
|
28758
|
-
if (fastForward.exitCode !== 0) {
|
|
28759
|
-
return {
|
|
28760
|
-
relative_path: relativePath,
|
|
28761
|
-
status: "skipped",
|
|
28762
|
-
kind: "repo",
|
|
28763
|
-
action: "skip",
|
|
28764
|
-
message: "\u672C\u5730\u63D0\u4EA4\u65E0\u6CD5\u5FEB\u8FDB\u5230\u8FDC\u7AEF\u5206\u652F"
|
|
28765
|
-
};
|
|
28766
|
-
}
|
|
28767
|
-
}
|
|
28768
|
-
await this.runGit(["pull", "--ff-only", "origin", branch], target, timeoutSeconds, false, gitEnvironment);
|
|
28769
|
-
}
|
|
28770
|
-
return {
|
|
28771
|
-
relative_path: relativePath,
|
|
28772
|
-
status: created ? "created" : "updated",
|
|
28773
|
-
kind: "repo",
|
|
28774
|
-
action: created ? "clone" : "pull",
|
|
28775
|
-
message: created ? "\u4ED3\u5E93\u5DF2\u514B\u9686" : "\u4ED3\u5E93\u5DF2\u5FEB\u8FDB\u66F4\u65B0"
|
|
28776
|
-
};
|
|
28777
|
-
}
|
|
28778
28729
|
async scanTree(rootPath, maxDepth, scanRoots) {
|
|
28779
28730
|
const resolvedRoot = await realpath4(rootPath);
|
|
28780
28731
|
const rootMetadata = await stat8(resolvedRoot);
|
|
@@ -28888,16 +28839,16 @@ var WorkspaceManager = class {
|
|
|
28888
28839
|
resolveWithinRoot(rootPath, relativePath) {
|
|
28889
28840
|
const target = resolve7(rootPath, relativePath);
|
|
28890
28841
|
const relativeToRoot = relative3(rootPath, target);
|
|
28891
|
-
if (relativeToRoot.startsWith("..") ||
|
|
28842
|
+
if (relativeToRoot.startsWith("..") || isAbsolute6(relativeToRoot)) {
|
|
28892
28843
|
throw new Error("A workspace path must remain under the configured workspace root");
|
|
28893
28844
|
}
|
|
28894
28845
|
return target;
|
|
28895
28846
|
}
|
|
28896
|
-
runGit(args, cwd, timeoutSeconds, allowFailure = false
|
|
28847
|
+
runGit(args, cwd, timeoutSeconds, allowFailure = false) {
|
|
28897
28848
|
return new Promise((resolveCommand, rejectCommand) => {
|
|
28898
28849
|
const child = spawn13("git", args, {
|
|
28899
28850
|
cwd,
|
|
28900
|
-
env:
|
|
28851
|
+
env: process.env,
|
|
28901
28852
|
shell: false,
|
|
28902
28853
|
stdio: ["ignore", "pipe", "pipe"]
|
|
28903
28854
|
});
|
|
@@ -28927,37 +28878,6 @@ var WorkspaceManager = class {
|
|
|
28927
28878
|
});
|
|
28928
28879
|
});
|
|
28929
28880
|
}
|
|
28930
|
-
async createGitAuthEnvironment(auth) {
|
|
28931
|
-
if (!auth) return void 0;
|
|
28932
|
-
const directory = await mkdtemp2(join20(tmpdir3(), "toc-ocra-git-auth-"));
|
|
28933
|
-
const isWindows = process.platform === "win32";
|
|
28934
|
-
const scriptPath = join20(directory, isWindows ? "askpass.cmd" : "askpass.sh");
|
|
28935
|
-
let script;
|
|
28936
|
-
if (isWindows) {
|
|
28937
|
-
const helperPath = join20(directory, "askpass.cjs");
|
|
28938
|
-
await writeFile9(
|
|
28939
|
-
helperPath,
|
|
28940
|
-
'const prompt = process.argv.slice(2).join(" ");\nprocess.stdout.write(/username/i.test(prompt) ? process.env.ECHO_GIT_USERNAME ?? "" : process.env.ECHO_GIT_PASSWORD ?? "");\n',
|
|
28941
|
-
{ mode: 448 }
|
|
28942
|
-
);
|
|
28943
|
-
script = '@echo off\r\n"%ECHO_NODE_PATH%" "%~dp0askpass.cjs" "%~1"\r\n';
|
|
28944
|
-
} else {
|
|
28945
|
-
script = '#!/bin/sh\ncase "$1" in *Username*|*username*) printf "%s\\n" "$ECHO_GIT_USERNAME" ;; *) printf "%s\\n" "$ECHO_GIT_PASSWORD" ;; esac\n';
|
|
28946
|
-
}
|
|
28947
|
-
await writeFile9(scriptPath, script, { mode: 448 });
|
|
28948
|
-
if (!isWindows) await chmod5(scriptPath, 448);
|
|
28949
|
-
return {
|
|
28950
|
-
env: {
|
|
28951
|
-
...process.env,
|
|
28952
|
-
GIT_ASKPASS: scriptPath,
|
|
28953
|
-
GIT_TERMINAL_PROMPT: "0",
|
|
28954
|
-
ECHO_NODE_PATH: process.execPath,
|
|
28955
|
-
ECHO_GIT_USERNAME: auth.username,
|
|
28956
|
-
ECHO_GIT_PASSWORD: auth.password
|
|
28957
|
-
},
|
|
28958
|
-
cleanup: () => rm5(directory, { recursive: true, force: true })
|
|
28959
|
-
};
|
|
28960
|
-
}
|
|
28961
28881
|
message(error62) {
|
|
28962
28882
|
return error62 instanceof Error ? error62.message : String(error62);
|
|
28963
28883
|
}
|
|
@@ -28977,6 +28897,8 @@ var RunStartPayloadSchema = external_exports.object({
|
|
|
28977
28897
|
task_chain_id: external_exports.string().optional().default(""),
|
|
28978
28898
|
message_id: external_exports.string().optional().default(""),
|
|
28979
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(),
|
|
28980
28902
|
chat_session_id: external_exports.string().max(64).optional(),
|
|
28981
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(),
|
|
28982
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(),
|
|
@@ -29083,22 +29005,15 @@ var CliProviderControlPayloadSchema = external_exports.object({
|
|
|
29083
29005
|
}).strict();
|
|
29084
29006
|
var RelativePathSchema = external_exports.string().min(1).max(500);
|
|
29085
29007
|
var FsListPayloadSchema = external_exports.object({ path: external_exports.string().max(4096).optional().default("") });
|
|
29008
|
+
var FsMkdirPayloadSchema = external_exports.object({
|
|
29009
|
+
parent_path: external_exports.string().min(1).max(4096),
|
|
29010
|
+
name: external_exports.string().min(1).max(255)
|
|
29011
|
+
}).strict();
|
|
29086
29012
|
var WorkspaceScanPayloadSchema = external_exports.object({
|
|
29087
29013
|
root_path: external_exports.string().min(1).max(4096),
|
|
29088
29014
|
max_depth: external_exports.number().int().positive().max(20).optional(),
|
|
29089
29015
|
scan_roots: external_exports.array(external_exports.object({ relative_path: RelativePathSchema, max_depth: external_exports.number().int().positive().max(20) })).max(2e3).optional()
|
|
29090
29016
|
});
|
|
29091
|
-
var WorkspaceSyncPayloadSchema = external_exports.object({
|
|
29092
|
-
root_path: external_exports.string().min(1).max(4096),
|
|
29093
|
-
directories: external_exports.array(RelativePathSchema).max(2e3).default([]),
|
|
29094
|
-
repos: external_exports.array(external_exports.object({
|
|
29095
|
-
relative_path: RelativePathSchema,
|
|
29096
|
-
git_url: external_exports.string().max(2e3).nullable().optional(),
|
|
29097
|
-
branch: external_exports.string().max(200).nullable().optional()
|
|
29098
|
-
})).max(2e3).default([]),
|
|
29099
|
-
timeout_s: external_exports.number().int().positive().max(3600).optional(),
|
|
29100
|
-
git_auth: external_exports.object({ username: external_exports.string().min(1).max(500), password: external_exports.string().min(1).max(4096) }).optional()
|
|
29101
|
-
});
|
|
29102
29017
|
|
|
29103
29018
|
// src/runtime/agent-runtime.ts
|
|
29104
29019
|
var sleep2 = (ms, signal2) => new Promise((resolve9) => {
|
|
@@ -29327,6 +29242,7 @@ var AgentRuntime = class {
|
|
|
29327
29242
|
task_attachments: { version: 1 },
|
|
29328
29243
|
// `run.transcript`: any run's structured items and run-log rows, kept on this device after the run.
|
|
29329
29244
|
run_transcripts: { version: 1 },
|
|
29245
|
+
cli_commands: { version: 1 },
|
|
29330
29246
|
// `memory.provider` commands and the `memory` field of run payloads (Lody's memoryProviders v1).
|
|
29331
29247
|
memory_providers: { version: 1, providers: [...MEMORY_PROVIDER_IDS] },
|
|
29332
29248
|
cli_execution_policy: { version: 1, modes: ["restricted", "full"] },
|
|
@@ -29454,6 +29370,16 @@ var AgentRuntime = class {
|
|
|
29454
29370
|
if (!this.catalogReport) return { success: false, error: "\u8BFB\u53D6\u6A21\u578B\u76EE\u5F55\u5931\u8D25" };
|
|
29455
29371
|
return { success: true, result: this.catalogReport };
|
|
29456
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
|
+
}
|
|
29457
29383
|
case "cli.quota": {
|
|
29458
29384
|
const payload = CliQuotaPayloadSchema.parse(command.payload ?? {});
|
|
29459
29385
|
try {
|
|
@@ -29491,15 +29417,14 @@ var AgentRuntime = class {
|
|
|
29491
29417
|
const payload = FsListPayloadSchema.parse(command.payload ?? {});
|
|
29492
29418
|
return { success: true, result: await listDirectory(payload.path, this.config.allowedRoots) };
|
|
29493
29419
|
}
|
|
29420
|
+
case "fs.mkdir": {
|
|
29421
|
+
const payload = FsMkdirPayloadSchema.parse(command.payload);
|
|
29422
|
+
return { success: true, result: await createDirectory(payload.parent_path, payload.name) };
|
|
29423
|
+
}
|
|
29494
29424
|
case "workspace.scan": {
|
|
29495
29425
|
const payload = WorkspaceScanPayloadSchema.parse(command.payload);
|
|
29496
29426
|
return { success: true, result: await this.workspaces.scan(payload) };
|
|
29497
29427
|
}
|
|
29498
|
-
case "workspace.sync": {
|
|
29499
|
-
const payload = WorkspaceSyncPayloadSchema.parse(command.payload);
|
|
29500
|
-
const result = await this.workspaces.sync(payload);
|
|
29501
|
-
return { success: !result.error, result, ...result.error ? { error: result.error } : {} };
|
|
29502
|
-
}
|
|
29503
29428
|
case "sql.run": {
|
|
29504
29429
|
const payload = SqlRunPayloadSchema.parse(command.payload);
|
|
29505
29430
|
this.checkPolicy("sql", payload.policy);
|
|
@@ -29510,16 +29435,14 @@ var AgentRuntime = class {
|
|
|
29510
29435
|
}
|
|
29511
29436
|
}
|
|
29512
29437
|
/**
|
|
29513
|
-
* Script / SQL run
|
|
29514
|
-
* owner has not switched it off. The policy attached to the command was
|
|
29438
|
+
* Script / SQL run when the server policy allows it. The policy attached to the command was
|
|
29515
29439
|
* checked by the server at enqueue time, so it wins over the (up to one
|
|
29516
29440
|
* heartbeat old) cached copy. New policy fields (read-only SQL,
|
|
29517
29441
|
* allowlists) are enforced here.
|
|
29518
29442
|
*/
|
|
29519
29443
|
checkPolicy(kind, commandPolicy) {
|
|
29520
|
-
const localOff = kind === "script" ? this.config.disableScript : this.config.disableSql;
|
|
29521
29444
|
const policy = commandPolicy ?? this.policy;
|
|
29522
|
-
const enabled =
|
|
29445
|
+
const enabled = policy[kind].enabled;
|
|
29523
29446
|
if (!enabled) throw new Error(kind === "script" ? "\u8BE5\u8BBE\u5907\u672A\u5F00\u542F\u811A\u672C\u6267\u884C" : "\u8BE5\u8BBE\u5907\u672A\u5F00\u542F SQL \u6267\u884C");
|
|
29524
29447
|
}
|
|
29525
29448
|
// ---- Reports ----
|