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/cli/cli.mjs
CHANGED
|
@@ -4577,7 +4577,7 @@ var require_lib = __commonJS({
|
|
|
4577
4577
|
import { spawnSync } from "node:child_process";
|
|
4578
4578
|
import { createHash as createHash5 } from "node:crypto";
|
|
4579
4579
|
import { existsSync as existsSync7, mkdtempSync, rmSync, writeFileSync as writeFileSync3 } from "node:fs";
|
|
4580
|
-
import { tmpdir as
|
|
4580
|
+
import { tmpdir as tmpdir4 } from "node:os";
|
|
4581
4581
|
import { createRequire } from "node:module";
|
|
4582
4582
|
import { dirname as dirname11, join as join23, resolve as resolve9 } from "node:path";
|
|
4583
4583
|
import { fileURLToPath as fileURLToPath3, pathToFileURL as pathToFileURL2 } from "node:url";
|
|
@@ -21242,8 +21242,8 @@ function rewriteKeyNames(ctx) {
|
|
|
21242
21242
|
bySchema.set(entry.schema, entry);
|
|
21243
21243
|
}
|
|
21244
21244
|
const rewrites = /* @__PURE__ */ new Map();
|
|
21245
|
-
for (const
|
|
21246
|
-
const seen = ctx.seen.get(
|
|
21245
|
+
for (const record10 of pendingRecords.get(ctx) ?? []) {
|
|
21246
|
+
const seen = ctx.seen.get(record10);
|
|
21247
21247
|
const names = (seen?.def ?? seen?.schema)?.propertyNames;
|
|
21248
21248
|
if (!names || names === true || rewrites.has(names))
|
|
21249
21249
|
continue;
|
|
@@ -25140,6 +25140,7 @@ function mergePathSegments(segments) {
|
|
|
25140
25140
|
// src/providers/cli-specs.ts
|
|
25141
25141
|
var SOURCES = [
|
|
25142
25142
|
{ id: "codex", label: "Codex", command: "codex", versionArguments: ["--version"], promptStdin: { replaceWith: "-" }, restrictedPermission: true, installHint: "npm i -g @openai/codex" },
|
|
25143
|
+
{ id: "kimi", label: "Kimi Code CLI", command: "kimi", versionArguments: ["--version"], installHint: "curl -fsSL https://code.kimi.com/kimi-code/install.sh | bash" },
|
|
25143
25144
|
{ 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" },
|
|
25144
25145
|
{ id: "grok", label: "Grok CLI", command: "grok", versionArguments: ["--version"] },
|
|
25145
25146
|
{ id: "gemini", label: "Gemini CLI", command: "gemini", versionArguments: ["--version"], restrictedPermission: true, installHint: "npm i -g @google/gemini-cli" },
|
|
@@ -26675,6 +26676,14 @@ var KIRO_LAUNCH_SPEC = {
|
|
|
26675
26676
|
resumable: (sessionId) => !sessionId.startsWith("sess_"),
|
|
26676
26677
|
modelDiscovery: { kind: "reader", source: MODEL_SOURCES.kiro }
|
|
26677
26678
|
};
|
|
26679
|
+
var KIMI_LAUNCH_SPEC = {
|
|
26680
|
+
agent: "kimi",
|
|
26681
|
+
headless: "acp",
|
|
26682
|
+
args: () => ["acp"],
|
|
26683
|
+
resumePreference: "resume",
|
|
26684
|
+
dialect: { failureRules: [{ kind: "sessionMissing", pattern: /session[^\n]{0,60}(?:not found|does not exist)|no such session/i }] },
|
|
26685
|
+
modelDiscovery: { kind: "session" }
|
|
26686
|
+
};
|
|
26678
26687
|
var GEMINI_LAUNCH_SPEC = {
|
|
26679
26688
|
agent: "gemini",
|
|
26680
26689
|
headless: "acp",
|
|
@@ -26780,6 +26789,7 @@ var CODEX_LAUNCH_SPEC = {
|
|
|
26780
26789
|
};
|
|
26781
26790
|
var ACP_LAUNCH_SPECS = [
|
|
26782
26791
|
KIRO_LAUNCH_SPEC,
|
|
26792
|
+
KIMI_LAUNCH_SPEC,
|
|
26783
26793
|
GEMINI_LAUNCH_SPEC,
|
|
26784
26794
|
GROK_LAUNCH_SPEC,
|
|
26785
26795
|
OPENCODE_LAUNCH_SPEC,
|
|
@@ -27258,12 +27268,24 @@ function rpcErrorText(error62) {
|
|
|
27258
27268
|
return /^internal error$/i.test(error62.message) ? detail : `${error62.message}: ${detail}`;
|
|
27259
27269
|
}
|
|
27260
27270
|
|
|
27271
|
+
// src/acp/cli-command.ts
|
|
27272
|
+
var record3 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
27273
|
+
function cliCommands(value) {
|
|
27274
|
+
if (!Array.isArray(value)) return void 0;
|
|
27275
|
+
return value.map(record3).filter((item) => typeof item.name === "string" && item.name.length > 0).map((item) => ({
|
|
27276
|
+
name: item.name,
|
|
27277
|
+
...typeof item.description === "string" ? { description: item.description } : {},
|
|
27278
|
+
..."input" in item ? { input: item.input } : {},
|
|
27279
|
+
..."_meta" in item ? { _meta: item._meta } : {}
|
|
27280
|
+
}));
|
|
27281
|
+
}
|
|
27282
|
+
|
|
27261
27283
|
// src/acp/connection.ts
|
|
27262
27284
|
var PROTOCOL_VERSION = 1;
|
|
27263
27285
|
var INITIALIZE_TIMEOUT_MS = 12e4;
|
|
27264
27286
|
var SESSION_OPEN_TIMEOUT_MS = 18e4;
|
|
27265
27287
|
var EXT_REQUEST_TIMEOUT_MS = 6e4;
|
|
27266
|
-
var
|
|
27288
|
+
var record4 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
27267
27289
|
var text2 = (value) => typeof value === "string" && value ? value : void 0;
|
|
27268
27290
|
var AcpConnection = class _AcpConnection {
|
|
27269
27291
|
constructor(launch, hooks, elicitation) {
|
|
@@ -27272,8 +27294,8 @@ var AcpConnection = class _AcpConnection {
|
|
|
27272
27294
|
let peer;
|
|
27273
27295
|
this.process = AgentProcess.spawn(launch, (line) => peer?.receive(line), (line) => hooks.stderr(line));
|
|
27274
27296
|
peer = new JsonRpcPeer((line) => this.process.write(line), {
|
|
27275
|
-
request: async (method, params, signal2) => this.onRequest(method,
|
|
27276
|
-
notification: (method, params) => this.onNotification(method,
|
|
27297
|
+
request: async (method, params, signal2) => this.onRequest(method, record4(params), signal2),
|
|
27298
|
+
notification: (method, params) => this.onNotification(method, record4(params))
|
|
27277
27299
|
});
|
|
27278
27300
|
this.peer = peer;
|
|
27279
27301
|
this.closed = this.process.exited.then((exit) => {
|
|
@@ -27296,6 +27318,8 @@ var AcpConnection = class _AcpConnection {
|
|
|
27296
27318
|
steering;
|
|
27297
27319
|
initialized = {};
|
|
27298
27320
|
peer;
|
|
27321
|
+
commandLists = /* @__PURE__ */ new Map();
|
|
27322
|
+
commandListeners = /* @__PURE__ */ new Set();
|
|
27299
27323
|
/**
|
|
27300
27324
|
* Starts the agent and completes `initialize`; the process is stopped on
|
|
27301
27325
|
* failure. `elicitation`: advertise form elicitation (Claude's adapter only
|
|
@@ -27305,7 +27329,7 @@ var AcpConnection = class _AcpConnection {
|
|
|
27305
27329
|
const elicitation = options.elicitation === true && hooks.elicitation !== void 0;
|
|
27306
27330
|
const connection = new _AcpConnection(launch, hooks, elicitation);
|
|
27307
27331
|
try {
|
|
27308
|
-
const result =
|
|
27332
|
+
const result = record4(await connection.call("initialize", {
|
|
27309
27333
|
protocolVersion: PROTOCOL_VERSION,
|
|
27310
27334
|
clientCapabilities: {
|
|
27311
27335
|
fs: { readTextFile: false, writeTextFile: false },
|
|
@@ -27326,16 +27350,18 @@ var AcpConnection = class _AcpConnection {
|
|
|
27326
27350
|
}
|
|
27327
27351
|
/** `auth`: the row's sign-in method, tried once when the agent answers `auth_required`. */
|
|
27328
27352
|
async newSession(cwd, auth) {
|
|
27329
|
-
const result =
|
|
27353
|
+
const result = record4(await this.withAuthentication(() => this.call("session/new", { cwd, mcpServers: [] }, SESSION_OPEN_TIMEOUT_MS), auth));
|
|
27330
27354
|
const sessionId = text2(result.sessionId);
|
|
27331
27355
|
if (!sessionId) throw new Error("ACP session/new \u6CA1\u6709\u8FD4\u56DE\u4F1A\u8BDD ID");
|
|
27356
|
+
this.captureCommands(sessionId, result.availableCommands);
|
|
27332
27357
|
return sessionState(sessionId, result);
|
|
27333
27358
|
}
|
|
27334
27359
|
/** Reopens a saved session: `session/load` (replays history) or `session/resume`, as the capabilities allow. */
|
|
27335
27360
|
async openSaved(sessionId, cwd, options = {}) {
|
|
27336
27361
|
const method = acpSessionMethod(this.initialized, sessionId, options.resumePreference);
|
|
27337
27362
|
if (!method || method === "new") throw new Error("ACP agent cannot load or resume this session");
|
|
27338
|
-
const result =
|
|
27363
|
+
const result = record4(await this.withAuthentication(() => this.call(`session/${method}`, { sessionId, cwd, mcpServers: [] }, SESSION_OPEN_TIMEOUT_MS), options.auth));
|
|
27364
|
+
this.captureCommands(sessionId, result.availableCommands);
|
|
27339
27365
|
return sessionState(sessionId, result);
|
|
27340
27366
|
}
|
|
27341
27367
|
/** Removes a session the agent created for a listing; only when `deleteSession`. */
|
|
@@ -27345,9 +27371,41 @@ var AcpConnection = class _AcpConnection {
|
|
|
27345
27371
|
get canOpenSaved() {
|
|
27346
27372
|
return this.loadSession || this.resumeSession;
|
|
27347
27373
|
}
|
|
27374
|
+
async commands(sessionId) {
|
|
27375
|
+
const known = this.commandLists.get(sessionId);
|
|
27376
|
+
if (known) return known;
|
|
27377
|
+
return await new Promise((resolve10, reject) => {
|
|
27378
|
+
const finish = () => {
|
|
27379
|
+
const items = this.commandLists.get(sessionId);
|
|
27380
|
+
if (!items) return;
|
|
27381
|
+
cleanup();
|
|
27382
|
+
resolve10(items);
|
|
27383
|
+
};
|
|
27384
|
+
const cleanup = () => {
|
|
27385
|
+
clearTimeout(timer);
|
|
27386
|
+
this.commandListeners.delete(finish);
|
|
27387
|
+
};
|
|
27388
|
+
const timer = setTimeout(() => {
|
|
27389
|
+
cleanup();
|
|
27390
|
+
reject(new Error("CLI \u672A\u8FD4\u56DE\u547D\u4EE4\u5217\u8868\uFF0C\u8BF7\u5347\u7EA7\u8BBE\u5907\u4EE3\u7406\u6216\u786E\u8BA4\u6B64 CLI \u652F\u6301 ACP \u547D\u4EE4\u3002"));
|
|
27391
|
+
}, 8e3);
|
|
27392
|
+
this.commandListeners.add(finish);
|
|
27393
|
+
void this.closed.then((error62) => {
|
|
27394
|
+
cleanup();
|
|
27395
|
+
reject(error62);
|
|
27396
|
+
});
|
|
27397
|
+
finish();
|
|
27398
|
+
});
|
|
27399
|
+
}
|
|
27400
|
+
captureCommands(sessionId, value) {
|
|
27401
|
+
const items = cliCommands(value);
|
|
27402
|
+
if (!items) return;
|
|
27403
|
+
this.commandLists.set(sessionId, items);
|
|
27404
|
+
for (const notify of this.commandListeners) notify();
|
|
27405
|
+
}
|
|
27348
27406
|
/** Resolves with the prompt's `stopReason` once the agent ends the turn. */
|
|
27349
27407
|
async prompt(sessionId, prompt, meta3) {
|
|
27350
|
-
const result =
|
|
27408
|
+
const result = record4(await this.peer.request("session/prompt", { sessionId, prompt, ...meta3 ? { _meta: meta3 } : {} }));
|
|
27351
27409
|
return text2(result.stopReason) ?? "end_turn";
|
|
27352
27410
|
}
|
|
27353
27411
|
cancel(sessionId) {
|
|
@@ -27359,7 +27417,7 @@ var AcpConnection = class _AcpConnection {
|
|
|
27359
27417
|
}
|
|
27360
27418
|
/** `_lody/session/steer`: `injected` means the agent took the prompt into the running turn. */
|
|
27361
27419
|
async steer(sessionId, prompt, steerId) {
|
|
27362
|
-
const result =
|
|
27420
|
+
const result = record4(await this.peer.request("_lody/session/steer", { sessionId, prompt, steerId }));
|
|
27363
27421
|
return result.outcome === "injected" ? "injected" : "failed";
|
|
27364
27422
|
}
|
|
27365
27423
|
/** An adapter extension request (`_session/archive`, `_session/unarchive`, …) with a time limit. */
|
|
@@ -27390,14 +27448,14 @@ var AcpConnection = class _AcpConnection {
|
|
|
27390
27448
|
);
|
|
27391
27449
|
}
|
|
27392
27450
|
readCapabilities(result) {
|
|
27393
|
-
const capabilities =
|
|
27451
|
+
const capabilities = record4(result.agentCapabilities);
|
|
27394
27452
|
this.initialized = result;
|
|
27395
|
-
this.agentName = text2(
|
|
27453
|
+
this.agentName = text2(record4(result.agentInfo).name) ?? "";
|
|
27396
27454
|
this.loadSession = capabilities.loadSession === true;
|
|
27397
|
-
this.resumeSession =
|
|
27398
|
-
this.deleteSession =
|
|
27399
|
-
this.imagePrompts =
|
|
27400
|
-
const steering =
|
|
27455
|
+
this.resumeSession = record4(capabilities.sessionCapabilities).resume != null;
|
|
27456
|
+
this.deleteSession = record4(capabilities.sessionCapabilities).delete != null;
|
|
27457
|
+
this.imagePrompts = record4(capabilities.promptCapabilities).image === true;
|
|
27458
|
+
const steering = record4(record4(record4(capabilities._meta).lody).steering);
|
|
27401
27459
|
if (steering.version === 1 && (steering.transport === "request" || steering.transport === "prompt")) {
|
|
27402
27460
|
this.steering = { transport: steering.transport, upstreamTurn: steering.upstreamTurn === "handoff" ? "handoff" : "same" };
|
|
27403
27461
|
}
|
|
@@ -27410,7 +27468,9 @@ var AcpConnection = class _AcpConnection {
|
|
|
27410
27468
|
onNotification(method, params) {
|
|
27411
27469
|
if (method === "session/update") {
|
|
27412
27470
|
const sessionId = text2(params.sessionId);
|
|
27413
|
-
|
|
27471
|
+
const update2 = record4(params.update);
|
|
27472
|
+
if (sessionId && update2.sessionUpdate === "available_commands_update") this.captureCommands(sessionId, update2.availableCommands);
|
|
27473
|
+
if (sessionId) this.hooks.update(sessionId, record4(params.update));
|
|
27414
27474
|
return;
|
|
27415
27475
|
}
|
|
27416
27476
|
this.hooks.notification(method, params);
|
|
@@ -27501,7 +27561,7 @@ var TurnTranscript = class {
|
|
|
27501
27561
|
case "plan":
|
|
27502
27562
|
return this.item({ itemId: "plan", type: "plan", entries: planEntries(update2.entries) });
|
|
27503
27563
|
case "plan_update": {
|
|
27504
|
-
const plan =
|
|
27564
|
+
const plan = record4(update2.plan);
|
|
27505
27565
|
if (plan.type === "items") return this.item({ itemId: "plan", type: "plan", entries: planEntries(plan.entries) });
|
|
27506
27566
|
if (plan.type === "markdown" && typeof plan.planId === "string") {
|
|
27507
27567
|
return this.item({ itemId: `proposed_plan:${plan.planId}`, type: "proposed_plan", turnId: plan.planId, markdown: clipText(String(plan.content ?? ""), 64e3), status: "delta", isLatest: true });
|
|
@@ -27528,7 +27588,7 @@ var TurnTranscript = class {
|
|
|
27528
27588
|
/** The agent's slash commands, also known before the first prompt. */
|
|
27529
27589
|
availableCommands(list) {
|
|
27530
27590
|
if (!Array.isArray(list)) return;
|
|
27531
|
-
const commands = list.map(
|
|
27591
|
+
const commands = list.map(record4).filter((command) => typeof command.name === "string").map((command) => ({
|
|
27532
27592
|
name: command.name,
|
|
27533
27593
|
description: clipText(typeof command.description === "string" ? command.description : "", 600),
|
|
27534
27594
|
...command.input && typeof command.input === "object" ? { input: clip2(command.input, 600) } : {}
|
|
@@ -27566,7 +27626,7 @@ var TurnTranscript = class {
|
|
|
27566
27626
|
if (rows.length) this.rows(rows);
|
|
27567
27627
|
}
|
|
27568
27628
|
chunk(kind, content) {
|
|
27569
|
-
const part =
|
|
27629
|
+
const part = record4(content);
|
|
27570
27630
|
if (part.type !== "text" || typeof part.text !== "string" || !part.text) return;
|
|
27571
27631
|
let open4 = this.open;
|
|
27572
27632
|
if (open4?.kind !== kind) {
|
|
@@ -27648,14 +27708,14 @@ var TurnTranscript = class {
|
|
|
27648
27708
|
}
|
|
27649
27709
|
/** Run-log rows for the output tail (the 运行日志 view). */
|
|
27650
27710
|
toolRows(tool, first) {
|
|
27651
|
-
const input2 =
|
|
27711
|
+
const input2 = record4(tool.rawInput);
|
|
27652
27712
|
const command = typeof input2.command === "string" ? input2.command : Array.isArray(input2.command) ? input2.command.join(" ") : void 0;
|
|
27653
27713
|
if (tool.kind === "execute") {
|
|
27654
27714
|
if (first) {
|
|
27655
27715
|
this.shellOpen = tool.toolCallId;
|
|
27656
27716
|
this.rows([runLog.command(command ?? tool.title ?? "shell")]);
|
|
27657
27717
|
} else {
|
|
27658
|
-
const output2 =
|
|
27718
|
+
const output2 = record4(tool.rawOutput);
|
|
27659
27719
|
const text3 = typeof output2.aggregated_output === "string" ? output2.aggregated_output : typeof output2.stdout === "string" ? output2.stdout : "";
|
|
27660
27720
|
const header = this.shellOpen === tool.toolCallId ? [] : [runLog.command(command ?? tool.title ?? "shell")];
|
|
27661
27721
|
this.shellOpen = "";
|
|
@@ -27669,7 +27729,7 @@ var TurnTranscript = class {
|
|
|
27669
27729
|
return;
|
|
27670
27730
|
}
|
|
27671
27731
|
this.shellOpen = "";
|
|
27672
|
-
const location =
|
|
27732
|
+
const location = record4(tool.locations?.[0]);
|
|
27673
27733
|
const path = typeof location.path === "string" ? location.path : void 0;
|
|
27674
27734
|
if (tool.kind === "edit" || tool.kind === "delete" || tool.kind === "move") this.rows([runLog.fileChange(path)]);
|
|
27675
27735
|
else if (tool.kind === "fetch") this.rows([runLog.tool("web_search")]);
|
|
@@ -27681,7 +27741,7 @@ var TurnTranscript = class {
|
|
|
27681
27741
|
};
|
|
27682
27742
|
function planEntries(value) {
|
|
27683
27743
|
if (!Array.isArray(value)) return [];
|
|
27684
|
-
return value.map(
|
|
27744
|
+
return value.map(record4).map((entry) => ({
|
|
27685
27745
|
content: clipText(String(entry.content ?? ""), 2e3),
|
|
27686
27746
|
priority: typeof entry.priority === "string" ? entry.priority : "medium",
|
|
27687
27747
|
status: typeof entry.status === "string" ? entry.status : "pending"
|
|
@@ -27689,7 +27749,7 @@ function planEntries(value) {
|
|
|
27689
27749
|
}
|
|
27690
27750
|
function toolContent(content) {
|
|
27691
27751
|
return content.map((block) => {
|
|
27692
|
-
const part =
|
|
27752
|
+
const part = record4(block);
|
|
27693
27753
|
if (part.type === "diff") {
|
|
27694
27754
|
return {
|
|
27695
27755
|
type: "diff",
|
|
@@ -27702,10 +27762,10 @@ function toolContent(content) {
|
|
|
27702
27762
|
});
|
|
27703
27763
|
}
|
|
27704
27764
|
function toolMeta(value) {
|
|
27705
|
-
const meta3 =
|
|
27765
|
+
const meta3 = record4(value);
|
|
27706
27766
|
const out = {};
|
|
27707
27767
|
if (meta3.lody !== void 0) out.lody = clip2(meta3.lody, 2e3);
|
|
27708
|
-
const claudeCode =
|
|
27768
|
+
const claudeCode = record4(meta3.claudeCode);
|
|
27709
27769
|
if (Object.keys(claudeCode).length) {
|
|
27710
27770
|
out.claudeCode = {
|
|
27711
27771
|
...typeof claudeCode.toolName === "string" ? { toolName: claudeCode.toolName } : {},
|
|
@@ -27729,7 +27789,7 @@ function clip2(value, max, depth = 0) {
|
|
|
27729
27789
|
|
|
27730
27790
|
// src/providers/cli/codex.ts
|
|
27731
27791
|
var CODEX = requireCliSpec("codex");
|
|
27732
|
-
var
|
|
27792
|
+
var record5 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
27733
27793
|
function toolItem(id, fields) {
|
|
27734
27794
|
return { event: "item", item: { itemId: `tool:${id}`, type: "tool_call", toolCallId: id, ...fields } };
|
|
27735
27795
|
}
|
|
@@ -27766,7 +27826,7 @@ function codexItemEvents(phase, item) {
|
|
|
27766
27826
|
})];
|
|
27767
27827
|
}
|
|
27768
27828
|
case "file_change": {
|
|
27769
|
-
const changes = Array.isArray(item.changes) ? item.changes.map(
|
|
27829
|
+
const changes = Array.isArray(item.changes) ? item.changes.map(record5) : [];
|
|
27770
27830
|
const paths = changes.map((change) => str(change.path)).filter((path) => Boolean(path));
|
|
27771
27831
|
const title = !paths.length ? "\u4FEE\u6539\u6587\u4EF6" : paths.length <= 3 ? paths.join(", ") : `${paths.slice(0, 3).join(", ")} \u7B49 ${paths.length} \u4E2A\u6587\u4EF6`;
|
|
27772
27832
|
return [toolItem(id, {
|
|
@@ -27792,7 +27852,7 @@ function codexItemEvents(phase, item) {
|
|
|
27792
27852
|
})];
|
|
27793
27853
|
}
|
|
27794
27854
|
case "web_search": {
|
|
27795
|
-
const action =
|
|
27855
|
+
const action = record5(item.action);
|
|
27796
27856
|
const query = str(item.query) ?? str(action.query) ?? str(action.url) ?? "";
|
|
27797
27857
|
return [toolItem(id, {
|
|
27798
27858
|
title: query || "web_search",
|
|
@@ -27802,7 +27862,7 @@ function codexItemEvents(phase, item) {
|
|
|
27802
27862
|
})];
|
|
27803
27863
|
}
|
|
27804
27864
|
case "todo_list": {
|
|
27805
|
-
const entries = (Array.isArray(item.items) ? item.items.map(
|
|
27865
|
+
const entries = (Array.isArray(item.items) ? item.items.map(record5) : []).map((entry) => ({
|
|
27806
27866
|
content: clipText(String(entry.text ?? ""), 2e3),
|
|
27807
27867
|
priority: "medium",
|
|
27808
27868
|
status: entry.completed === true ? "completed" : "pending"
|
|
@@ -28098,9 +28158,9 @@ function claudeTranscriptPath(sessionId) {
|
|
|
28098
28158
|
}
|
|
28099
28159
|
function isPromptEntry(entry) {
|
|
28100
28160
|
if (entry.type !== "user" || entry.isSidechain === true || entry.isMeta === true) return false;
|
|
28101
|
-
const content =
|
|
28161
|
+
const content = record6(entry.message).content;
|
|
28102
28162
|
if (typeof content === "string") return content.trim().length > 0;
|
|
28103
|
-
return Array.isArray(content) && content.some((part) =>
|
|
28163
|
+
return Array.isArray(content) && content.some((part) => record6(part).type === "text");
|
|
28104
28164
|
}
|
|
28105
28165
|
function claudeForkBoundary(transcript, keepTurns) {
|
|
28106
28166
|
if (keepTurns <= 0) return void 0;
|
|
@@ -28167,10 +28227,10 @@ var claudeProvider = {
|
|
|
28167
28227
|
// `--resume <id>` for a chat this computer no longer has.
|
|
28168
28228
|
failureRules: [{ kind: "sessionMissing", pattern: /No conversation found with session ID/i }]
|
|
28169
28229
|
};
|
|
28170
|
-
var
|
|
28230
|
+
var record6 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
28171
28231
|
function toolResultText(content) {
|
|
28172
28232
|
if (typeof content === "string") return content;
|
|
28173
|
-
if (Array.isArray(content)) return content.map((part) => str(
|
|
28233
|
+
if (Array.isArray(content)) return content.map((part) => str(record6(part).text) ?? "").filter(Boolean).join("\n");
|
|
28174
28234
|
return "";
|
|
28175
28235
|
}
|
|
28176
28236
|
var CLAUDE_TOOL_KINDS = {
|
|
@@ -28212,7 +28272,7 @@ function claudeToolItem(id, name, input2) {
|
|
|
28212
28272
|
title = path && `Edit ${path}`;
|
|
28213
28273
|
break;
|
|
28214
28274
|
case "MultiEdit":
|
|
28215
|
-
if (path && Array.isArray(input2.edits)) for (const edit of input2.edits.slice(0, 50).map(
|
|
28275
|
+
if (path && Array.isArray(input2.edits)) for (const edit of input2.edits.slice(0, 50).map(record6)) content.push(diff(path, edit.old_string, edit.new_string));
|
|
28216
28276
|
title = path && `Edit ${path}`;
|
|
28217
28277
|
break;
|
|
28218
28278
|
case "Write":
|
|
@@ -28264,7 +28324,7 @@ function claudeToolItem(id, name, input2) {
|
|
|
28264
28324
|
};
|
|
28265
28325
|
}
|
|
28266
28326
|
function claudePlanItem(input2) {
|
|
28267
|
-
const todos = Array.isArray(input2.todos) ? input2.todos.map(
|
|
28327
|
+
const todos = Array.isArray(input2.todos) ? input2.todos.map(record6) : [];
|
|
28268
28328
|
return {
|
|
28269
28329
|
itemId: "plan",
|
|
28270
28330
|
type: "plan",
|
|
@@ -28305,13 +28365,13 @@ function claudeLineParser() {
|
|
|
28305
28365
|
return { ...base, display: [`\u25CF \u4F1A\u8BDD ${sessionId ?? ""}`, runLog.event("\u5F00\u59CB\u5904\u7406")] };
|
|
28306
28366
|
}
|
|
28307
28367
|
case "assistant": {
|
|
28308
|
-
const message =
|
|
28368
|
+
const message = record6(event.message);
|
|
28309
28369
|
const content = message.content ?? [];
|
|
28310
28370
|
const messageId = str(message.id) ?? `message${++unnamedMessages}`;
|
|
28311
28371
|
const rows = [];
|
|
28312
28372
|
const events = [];
|
|
28313
28373
|
for (const value of Array.isArray(content) ? content : []) {
|
|
28314
|
-
const part =
|
|
28374
|
+
const part = record6(value);
|
|
28315
28375
|
const index = blockCounts.get(messageId) ?? 0;
|
|
28316
28376
|
blockCounts.set(messageId, index + 1);
|
|
28317
28377
|
if (part.type === "text") {
|
|
@@ -28332,7 +28392,7 @@ function claudeLineParser() {
|
|
|
28332
28392
|
}
|
|
28333
28393
|
if (part.type !== "tool_use") continue;
|
|
28334
28394
|
const name = str(part.name) ?? "tool";
|
|
28335
|
-
const input2 =
|
|
28395
|
+
const input2 = record6(part.input);
|
|
28336
28396
|
const id = str(part.id) ?? "";
|
|
28337
28397
|
if (id && name === "TodoWrite") {
|
|
28338
28398
|
plans.add(id);
|
|
@@ -28355,11 +28415,11 @@ function claudeLineParser() {
|
|
|
28355
28415
|
return { ...base, display: rows, ...events.length ? { chatEvents: events } : {} };
|
|
28356
28416
|
}
|
|
28357
28417
|
case "user": {
|
|
28358
|
-
const content =
|
|
28418
|
+
const content = record6(event.message).content ?? [];
|
|
28359
28419
|
const rows = [];
|
|
28360
28420
|
const events = [];
|
|
28361
28421
|
for (const value of Array.isArray(content) ? content : []) {
|
|
28362
|
-
const part =
|
|
28422
|
+
const part = record6(value);
|
|
28363
28423
|
if (part.type !== "tool_result") continue;
|
|
28364
28424
|
const id = str(part.tool_use_id) ?? "";
|
|
28365
28425
|
const tool = tools.get(id);
|
|
@@ -28417,8 +28477,8 @@ function toolPath(input2, partial2) {
|
|
|
28417
28477
|
const parsed = input2 && typeof input2 === "object" && Object.keys(input2).length ? input2 : tryJson(partial2) ?? {};
|
|
28418
28478
|
return str(parsed.file_path) ?? str(parsed.notebook_path) ?? str(parsed.path);
|
|
28419
28479
|
}
|
|
28420
|
-
var
|
|
28421
|
-
var textContent = (value) => typeof value === "string" ? value : Array.isArray(value) ? value.map((part) => str(
|
|
28480
|
+
var record7 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
28481
|
+
var textContent = (value) => typeof value === "string" ? value : Array.isArray(value) ? value.map((part) => str(record7(part).text) ?? "").filter(Boolean).join("\n") : JSON.stringify(value ?? "");
|
|
28422
28482
|
function claudeChatProvider(attachments) {
|
|
28423
28483
|
let messageID = "";
|
|
28424
28484
|
let messageSequence = 0;
|
|
@@ -28448,14 +28508,14 @@ function claudeChatProvider(attachments) {
|
|
|
28448
28508
|
const events = [];
|
|
28449
28509
|
if (envelope.parent_tool_use_id) return { ...base, display: [] };
|
|
28450
28510
|
if (envelope.type === "stream_event") {
|
|
28451
|
-
const event =
|
|
28511
|
+
const event = record7(envelope.event);
|
|
28452
28512
|
const index = Number(event.index ?? 0);
|
|
28453
28513
|
if (event.type === "message_start") {
|
|
28454
|
-
messageID = str(
|
|
28514
|
+
messageID = str(record7(event.message).id) ?? `message:${++messageSequence}`;
|
|
28455
28515
|
blocks.clear();
|
|
28456
28516
|
} else if (event.type === "content_block_start") {
|
|
28457
28517
|
if (!messageID) messageID = `message:${++messageSequence}`;
|
|
28458
|
-
const part =
|
|
28518
|
+
const part = record7(event.content_block);
|
|
28459
28519
|
const type = part.type === "tool_use" ? "tool_call" : part.type === "thinking" ? "thought" : "text";
|
|
28460
28520
|
if (!["tool_use", "thinking", "text"].includes(String(part.type))) return { ...base, display: [] };
|
|
28461
28521
|
const block = { id: type === "tool_call" ? str(part.id) ?? `${messageID}:${index}` : `${messageID}:${index}`, type, name: str(part.name) ?? "tool", text: String(part.text ?? part.thinking ?? ""), input: part.input ?? {}, partialInput: "" };
|
|
@@ -28464,7 +28524,7 @@ function claudeChatProvider(attachments) {
|
|
|
28464
28524
|
events.push(asItem(block, "in_progress"));
|
|
28465
28525
|
} else if (event.type === "content_block_delta") {
|
|
28466
28526
|
const block = blocks.get(index);
|
|
28467
|
-
const delta =
|
|
28527
|
+
const delta = record7(event.delta);
|
|
28468
28528
|
if (!block) return { ...base, display: [] };
|
|
28469
28529
|
if (delta.type === "text_delta" || delta.type === "thinking_delta") {
|
|
28470
28530
|
const text3 = String(delta.text ?? delta.thinking ?? "");
|
|
@@ -28481,11 +28541,11 @@ function claudeChatProvider(attachments) {
|
|
|
28481
28541
|
if (block && block.type !== "tool_call") events.push(asItem(block, "completed"));
|
|
28482
28542
|
}
|
|
28483
28543
|
} else if (envelope.type === "assistant") {
|
|
28484
|
-
const message =
|
|
28544
|
+
const message = record7(envelope.message);
|
|
28485
28545
|
const id = str(message.id) || messageID || `message:${++messageSequence}`;
|
|
28486
28546
|
const parts = Array.isArray(message.content) ? message.content : [];
|
|
28487
28547
|
parts.forEach((value, index) => {
|
|
28488
|
-
const part =
|
|
28548
|
+
const part = record7(value);
|
|
28489
28549
|
if (!["text", "thinking", "tool_use"].includes(String(part.type))) return;
|
|
28490
28550
|
const type = part.type === "tool_use" ? "tool_call" : part.type === "thinking" ? "thought" : "text";
|
|
28491
28551
|
const block = { id: type === "tool_call" ? str(part.id) ?? `${id}:${index}` : `${id}:${index}`, type, name: str(part.name) ?? "tool", text: String(part.text ?? part.thinking ?? ""), input: part.input ?? {}, partialInput: "" };
|
|
@@ -28494,9 +28554,9 @@ function claudeChatProvider(attachments) {
|
|
|
28494
28554
|
events.push(asItem(block, type === "tool_call" ? "in_progress" : "completed"));
|
|
28495
28555
|
});
|
|
28496
28556
|
} else if (envelope.type === "user") {
|
|
28497
|
-
const message =
|
|
28557
|
+
const message = record7(envelope.message);
|
|
28498
28558
|
for (const value of Array.isArray(message.content) ? message.content : []) {
|
|
28499
|
-
const part =
|
|
28559
|
+
const part = record7(value);
|
|
28500
28560
|
if (part.type !== "tool_result") continue;
|
|
28501
28561
|
const id = str(part.tool_use_id);
|
|
28502
28562
|
if (!id) continue;
|
|
@@ -28547,7 +28607,7 @@ var ECHO_CALLBACK = /echo_report_task_progress/;
|
|
|
28547
28607
|
var PROTOCOL_VERSION2 = 1;
|
|
28548
28608
|
var READ_ONLY_KINDS = /* @__PURE__ */ new Set(["read", "search", "think"]);
|
|
28549
28609
|
var EDIT_KINDS = /* @__PURE__ */ new Set(["edit", "delete", "move"]);
|
|
28550
|
-
var
|
|
28610
|
+
var record8 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
28551
28611
|
function acpErrorText(error62, dialect) {
|
|
28552
28612
|
const message = str(error62?.message) ?? "ACP \u8BF7\u6C42\u5931\u8D25";
|
|
28553
28613
|
const data = error62?.data;
|
|
@@ -28558,8 +28618,8 @@ function acpErrorText(error62, dialect) {
|
|
|
28558
28618
|
function contentText(content) {
|
|
28559
28619
|
if (!Array.isArray(content)) return "";
|
|
28560
28620
|
return content.map((item) => {
|
|
28561
|
-
const part =
|
|
28562
|
-
const inner =
|
|
28621
|
+
const part = record8(item);
|
|
28622
|
+
const inner = record8(part.content);
|
|
28563
28623
|
return str(inner.text) ?? str(part.text) ?? "";
|
|
28564
28624
|
}).filter(Boolean).join("\n");
|
|
28565
28625
|
}
|
|
@@ -28583,14 +28643,14 @@ function rawStdout(rawOutput) {
|
|
|
28583
28643
|
return found.join("\n");
|
|
28584
28644
|
}
|
|
28585
28645
|
function permissionAllowed(params, request) {
|
|
28586
|
-
const call =
|
|
28646
|
+
const call = record8(params.toolCall);
|
|
28587
28647
|
const title = str(call.title) ?? "";
|
|
28588
28648
|
const kind = str(call.kind) ?? "";
|
|
28589
28649
|
const level = accessLevel(request);
|
|
28590
28650
|
return level === "bypassPermissions" || READ_ONLY_KINDS.has(kind) || level !== "restricted" && kind === "fetch" || level === "acceptEdits" && EDIT_KINDS.has(kind) || ECHO_CALLBACK.test(title);
|
|
28591
28651
|
}
|
|
28592
28652
|
function permissionOutcome(params, request) {
|
|
28593
|
-
const options = Array.isArray(params.options) ? params.options.map(
|
|
28653
|
+
const options = Array.isArray(params.options) ? params.options.map(record8) : [];
|
|
28594
28654
|
const kind = permissionAllowed(params, request) ? "allow_once" : "reject_once";
|
|
28595
28655
|
const option2 = options.find((item) => str(item.kind) === kind);
|
|
28596
28656
|
return option2 ? { outcome: { outcome: "selected", optionId: option2.optionId } } : { outcome: { outcome: "cancelled" } };
|
|
@@ -28720,7 +28780,7 @@ function createAcpProvider(row) {
|
|
|
28720
28780
|
const phase = typeof message.id === "number" ? phases.get(message.id) : void 0;
|
|
28721
28781
|
if (!phase) return { display: [] };
|
|
28722
28782
|
phases.delete(message.id);
|
|
28723
|
-
const result =
|
|
28783
|
+
const result = record8(message.result);
|
|
28724
28784
|
if (phase === "open") {
|
|
28725
28785
|
if (message.error) return onOpenError(message);
|
|
28726
28786
|
loading = false;
|
|
@@ -28767,8 +28827,8 @@ function createAcpProvider(row) {
|
|
|
28767
28827
|
const onToolCall = (update2) => {
|
|
28768
28828
|
const id = str(update2.toolCallId) ?? "";
|
|
28769
28829
|
const known = tools.get(id);
|
|
28770
|
-
const input2 =
|
|
28771
|
-
const locations = Array.isArray(update2.locations) ? update2.locations.map(
|
|
28830
|
+
const input2 = record8(update2.rawInput);
|
|
28831
|
+
const locations = Array.isArray(update2.locations) ? update2.locations.map(record8) : [];
|
|
28772
28832
|
const tool = known ?? { kind: "other", title: "tool" };
|
|
28773
28833
|
tool.kind = str(update2.kind) ?? tool.kind;
|
|
28774
28834
|
if (!known) tool.title = str(update2.title) ?? tool.title;
|
|
@@ -28813,7 +28873,7 @@ function createAcpProvider(row) {
|
|
|
28813
28873
|
return first;
|
|
28814
28874
|
};
|
|
28815
28875
|
const onUpdate = (params) => {
|
|
28816
|
-
const raw =
|
|
28876
|
+
const raw = record8(params.update);
|
|
28817
28877
|
const kind = str(raw.sessionUpdate);
|
|
28818
28878
|
const update2 = (kind === "tool_call" || kind === "tool_call_update") && dialect.normalizeToolUpdate ? dialect.normalizeToolUpdate(raw) : raw;
|
|
28819
28879
|
if (loading) {
|
|
@@ -28821,7 +28881,7 @@ function createAcpProvider(row) {
|
|
|
28821
28881
|
return withItems({ display: [] });
|
|
28822
28882
|
}
|
|
28823
28883
|
transcript.update(update2);
|
|
28824
|
-
const text3 = str(
|
|
28884
|
+
const text3 = str(record8(update2.content).text);
|
|
28825
28885
|
switch (kind) {
|
|
28826
28886
|
case "agent_message_chunk": {
|
|
28827
28887
|
if (!text3) return withItems({ display: [] });
|
|
@@ -28844,7 +28904,7 @@ function createAcpProvider(row) {
|
|
|
28844
28904
|
}
|
|
28845
28905
|
};
|
|
28846
28906
|
const onRequest = (message) => {
|
|
28847
|
-
const params =
|
|
28907
|
+
const params = record8(message.params);
|
|
28848
28908
|
if (message.method === "session/request_permission") {
|
|
28849
28909
|
answer(message.id, permissionOutcome(params, request));
|
|
28850
28910
|
return { display: [] };
|
|
@@ -28884,7 +28944,7 @@ function createAcpProvider(row) {
|
|
|
28884
28944
|
if (finished && message.id === void 0) return { display: [] };
|
|
28885
28945
|
if (message.method && message.id !== void 0) return onRequest(message);
|
|
28886
28946
|
if (message.method) {
|
|
28887
|
-
const params =
|
|
28947
|
+
const params = record8(message.params);
|
|
28888
28948
|
if (message.method === "session/update") return onUpdate(params);
|
|
28889
28949
|
const rows = dialect.notification?.(message.method, params);
|
|
28890
28950
|
return { display: rows ?? [] };
|
|
@@ -29907,7 +29967,7 @@ var RunTranscript = class _RunTranscript {
|
|
|
29907
29967
|
* that ended before the run did: it reads as `lost`.
|
|
29908
29968
|
*/
|
|
29909
29969
|
static fromFile(value) {
|
|
29910
|
-
const data =
|
|
29970
|
+
const data = record9(value);
|
|
29911
29971
|
if (data.v !== 1 || typeof data.run_id !== "string" || !data.run_id || !Array.isArray(data.items) || !Array.isArray(data.lines)) return void 0;
|
|
29912
29972
|
const transcript = new _RunTranscript({
|
|
29913
29973
|
runId: data.run_id,
|
|
@@ -29923,7 +29983,7 @@ var RunTranscript = class _RunTranscript {
|
|
|
29923
29983
|
transcript.revision = whole(data.revision);
|
|
29924
29984
|
transcript.itemRevisions = false;
|
|
29925
29985
|
for (const value2 of data.items) {
|
|
29926
|
-
const item =
|
|
29986
|
+
const item = record9(value2);
|
|
29927
29987
|
if (typeof item.itemId !== "string" || !item.itemId || transcript.positions.has(item.itemId)) continue;
|
|
29928
29988
|
transcript.positions.set(item.itemId, transcript.entries.length);
|
|
29929
29989
|
transcript.entries.push({ rev: 0, item });
|
|
@@ -30164,7 +30224,7 @@ function whole(value) {
|
|
|
30164
30224
|
function finite(value) {
|
|
30165
30225
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
30166
30226
|
}
|
|
30167
|
-
function
|
|
30227
|
+
function record9(value) {
|
|
30168
30228
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
30169
30229
|
}
|
|
30170
30230
|
function errorCode(error62) {
|
|
@@ -30779,6 +30839,10 @@ var AcpChatSession = class {
|
|
|
30779
30839
|
const session = await this.ensureSession(turn, connection);
|
|
30780
30840
|
if (turn.cancelRequested) return this.cancelled(turn);
|
|
30781
30841
|
sink.started(connection.process.pid, session.sessionId);
|
|
30842
|
+
if (request.command) {
|
|
30843
|
+
const commands = await connection.commands(session.sessionId);
|
|
30844
|
+
if (!commands.some((item) => item.name === request.command.name)) throw new Error("CLI \u5F53\u524D\u6CA1\u6709\u63D0\u4F9B\u8FD9\u4E2A\u547D\u4EE4\uFF0C\u8BF7\u5237\u65B0\u547D\u4EE4\u5217\u8868\u540E\u91CD\u8BD5\u3002");
|
|
30845
|
+
}
|
|
30782
30846
|
await this.applySettings(turn, connection, session);
|
|
30783
30847
|
if (turn.cancelRequested) return this.cancelled(turn);
|
|
30784
30848
|
let blocks = await this.promptBlocks(request, connection);
|
|
@@ -30956,17 +31020,17 @@ var AcpChatSession = class {
|
|
|
30956
31020
|
const options = permissionOptions(params.options);
|
|
30957
31021
|
if (prompts && options.length && this.forwardsPermission(params, prompts)) {
|
|
30958
31022
|
const requestId = randomUUID3();
|
|
30959
|
-
const call =
|
|
31023
|
+
const call = record4(params.toolCall);
|
|
30960
31024
|
const toolCall = typeof call.toolCallId === "string" && call.toolCallId ? call : { ...call, toolCallId: `permission:${requestId}` };
|
|
30961
|
-
const meta3 =
|
|
31025
|
+
const meta3 = record4(params._meta);
|
|
30962
31026
|
return this.ask(turn, requestId, toolCall, options, Object.keys(meta3).length ? meta3 : void 0, signal2).then((outcome2) => ({ outcome: outcome2 }));
|
|
30963
31027
|
}
|
|
30964
31028
|
const access = turn.request.access;
|
|
30965
31029
|
const outcome = permissionOutcome(params, access === "restricted" ? { permissionMode: "restricted" } : { permissionMode: "full", access: access === "default" ? "read-only" : access });
|
|
30966
|
-
const selected =
|
|
30967
|
-
const option2 = Array.isArray(params.options) ? params.options.map(
|
|
31030
|
+
const selected = record4(record4(outcome).outcome);
|
|
31031
|
+
const option2 = Array.isArray(params.options) ? params.options.map(record4).find((item) => item.optionId === selected.optionId) : void 0;
|
|
30968
31032
|
if (typeof option2?.kind === "string" && option2.kind.startsWith("reject")) {
|
|
30969
|
-
const call =
|
|
31033
|
+
const call = record4(params.toolCall);
|
|
30970
31034
|
turn.transcript.note(`\u5DF2\u62D2\u7EDD\uFF1A${typeof call.title === "string" ? call.title : "\u5DE5\u5177\u8C03\u7528"}\uFF08\u5F53\u524D\u6743\u9650\u4E0D\u5141\u8BB8\uFF09`);
|
|
30971
31035
|
}
|
|
30972
31036
|
return outcome;
|
|
@@ -30979,7 +31043,7 @@ var AcpChatSession = class {
|
|
|
30979
31043
|
forwardsPermission(params, prompts) {
|
|
30980
31044
|
if (isAskUserQuestionPermission(params)) return true;
|
|
30981
31045
|
if (prompts.permissions === "none") return false;
|
|
30982
|
-
const title =
|
|
31046
|
+
const title = record4(params.toolCall).title;
|
|
30983
31047
|
if (ECHO_CALLBACK.test(typeof title === "string" ? title : "")) return false;
|
|
30984
31048
|
if (prompts.permissions === "all") return true;
|
|
30985
31049
|
return !permissionAllowed(params, { permissionMode: "full", access: "acceptEdits" });
|
|
@@ -31135,7 +31199,7 @@ function isArchivedSessionError(error62) {
|
|
|
31135
31199
|
}
|
|
31136
31200
|
function permissionOptions(value) {
|
|
31137
31201
|
if (!Array.isArray(value)) return [];
|
|
31138
|
-
return value.map(
|
|
31202
|
+
return value.map(record4).flatMap((option2) => typeof option2.optionId === "string" && option2.optionId ? [{ optionId: option2.optionId, name: typeof option2.name === "string" ? option2.name : option2.optionId, kind: typeof option2.kind === "string" ? option2.kind : "" }] : []);
|
|
31139
31203
|
}
|
|
31140
31204
|
|
|
31141
31205
|
// src/acp/chat-host.ts
|
|
@@ -31377,6 +31441,34 @@ async function handleMemoryProviderRequest(input2, registry2 = providers) {
|
|
|
31377
31441
|
}
|
|
31378
31442
|
}
|
|
31379
31443
|
|
|
31444
|
+
// src/acp/command-catalog.ts
|
|
31445
|
+
async function readCLICommands(spec, launch, cwd, clientVersion) {
|
|
31446
|
+
const connection = await AcpConnection.open(launch.launch, {
|
|
31447
|
+
update: () => {
|
|
31448
|
+
},
|
|
31449
|
+
permission: () => ({ outcome: { outcome: "cancelled" } }),
|
|
31450
|
+
notification: () => {
|
|
31451
|
+
},
|
|
31452
|
+
stderr: () => {
|
|
31453
|
+
}
|
|
31454
|
+
}, clientVersion);
|
|
31455
|
+
let sessionId = "";
|
|
31456
|
+
try {
|
|
31457
|
+
const auth = spec.authMethod ? { pick: spec.authMethod, env: launch.launch.env ?? {} } : void 0;
|
|
31458
|
+
const session = await connection.newSession(cwd, auth);
|
|
31459
|
+
sessionId = session.sessionId;
|
|
31460
|
+
return await connection.commands(sessionId);
|
|
31461
|
+
} finally {
|
|
31462
|
+
if (sessionId && connection.deleteSession) {
|
|
31463
|
+
try {
|
|
31464
|
+
await connection.removeSession(sessionId);
|
|
31465
|
+
} catch {
|
|
31466
|
+
}
|
|
31467
|
+
}
|
|
31468
|
+
await connection.dispose();
|
|
31469
|
+
}
|
|
31470
|
+
}
|
|
31471
|
+
|
|
31380
31472
|
// src/runs/run-supervisor.ts
|
|
31381
31473
|
var COMPLETION_EXIT_GRACE_MS = 15e3;
|
|
31382
31474
|
var EXIT_OUTPUT_GRACE_MS = 2e3;
|
|
@@ -31543,6 +31635,14 @@ var RunSupervisor = class {
|
|
|
31543
31635
|
this.preparing.delete(payload.run_id);
|
|
31544
31636
|
}
|
|
31545
31637
|
}
|
|
31638
|
+
async listCLICommands(input2) {
|
|
31639
|
+
const spec = acpChatSpec(input2.agent_type);
|
|
31640
|
+
if (!spec) throw new Error("\u6B64\u8BBE\u5907\u4E0A\u7684 CLI \u6682\u4E0D\u652F\u6301\u547D\u4EE4\u67E5\u8BE2\uFF0C\u8BF7\u5347\u7EA7\u8BBE\u5907\u4EE3\u7406\u3002");
|
|
31641
|
+
const workdir = input2.workdir ? await this.validateWorkdir(input2.workdir) : await this.defaultChatWorkdir();
|
|
31642
|
+
const prepared = await this.acpChats.prepare(spec, { access: "read-only", workdir, model: input2.model ?? "", reasoningEffort: input2.reasoning_effort ?? "" });
|
|
31643
|
+
const items = await readCLICommands(spec, prepared, workdir, agentPackageVersion());
|
|
31644
|
+
return { agent_type: input2.agent_type, items };
|
|
31645
|
+
}
|
|
31546
31646
|
async startPrepared(payload, signal2) {
|
|
31547
31647
|
if (this.active.has(payload.run_id) || this.acpRuns.has(payload.run_id) || this.recent.has(payload.run_id)) {
|
|
31548
31648
|
this.logger.info("run-duplicate-ignored", { runId: payload.run_id });
|
|
@@ -31558,6 +31658,7 @@ var RunSupervisor = class {
|
|
|
31558
31658
|
this.remember({ runId: payload.run_id, sessionKey, tail: new TerminalTailBuffer(), transcript, finishedAt: Date.now(), status: "failed", chat: !!payload.chat_session_id });
|
|
31559
31659
|
await this.report(payload.run_id, { status: "failed", error: failure2.message, failure_kind: failure2.kind, duration_ms: 0 });
|
|
31560
31660
|
};
|
|
31661
|
+
if (payload.cli_command && !payload.chat_session_id) return refuse("\u539F\u751F\u547D\u4EE4\u9700\u8981 ACP \u4F1A\u8BDD\uFF0C\u4E0D\u80FD\u901A\u8FC7\u666E\u901A\u6D88\u606F\u9A71\u52A8\u6267\u884C\u3002");
|
|
31561
31662
|
if (this.sessionBusy(sessionKey, payload.run_id)) {
|
|
31562
31663
|
return refuse("\u672C\u673A\u8BE5\u4F1A\u8BDD\u5DF2\u6709\u4EFB\u52A1\u5728\u8FD0\u884C");
|
|
31563
31664
|
}
|
|
@@ -31599,7 +31700,7 @@ var RunSupervisor = class {
|
|
|
31599
31700
|
}
|
|
31600
31701
|
return refuse(`\u9644\u4EF6\u4E0B\u8F7D\u5931\u8D25\uFF1A${errorMessage2(error62)}`);
|
|
31601
31702
|
}
|
|
31602
|
-
const prompt = turn.planPrompt ? `${payload.prompt}
|
|
31703
|
+
const prompt = payload.cli_command ? `/${payload.cli_command.name}${payload.cli_command.arguments ? " " + payload.cli_command.arguments : ""}` : turn.planPrompt ? `${payload.prompt}
|
|
31603
31704
|
|
|
31604
31705
|
${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
31605
31706
|
const request = {
|
|
@@ -31613,6 +31714,7 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
31613
31714
|
};
|
|
31614
31715
|
if (payload.chat_session_id) {
|
|
31615
31716
|
const acpSpec = acpChatSpec(cli.id);
|
|
31717
|
+
if (payload.cli_command && !acpSpec) return refuse("\u6B64\u8BBE\u5907\u65E0\u6CD5\u6267\u884C\u539F\u751F\u547D\u4EE4\uFF0C\u8BF7\u5347\u7EA7\u8BBE\u5907\u4EE3\u7406\u3002");
|
|
31616
31718
|
if (acpSpec) {
|
|
31617
31719
|
const outcome = await this.startAcpChat(payload, { spec: acpSpec, cli, sessionKey, workdir, prompt, turn, permissionMode, memoryEnv, signal: signal2, refuse, transcript });
|
|
31618
31720
|
if (outcome === "handled") return;
|
|
@@ -31912,7 +32014,7 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
31912
32014
|
await refuse(cliFailure("cliMissing", { label: cli.label, ...cli.installHint ? { installHint: cli.installHint } : {} }));
|
|
31913
32015
|
return "handled";
|
|
31914
32016
|
}
|
|
31915
|
-
if (cli.chat) return { fallback: `${error62.message}\uFF0C\u672C\u8F6E\u6539\u7528\u65E7\u7248\u804A\u5929\u9A71\u52A8` };
|
|
32017
|
+
if (cli.chat && !payload.cli_command) return { fallback: `${error62.message}\uFF0C\u672C\u8F6E\u6539\u7528\u65E7\u7248\u804A\u5929\u9A71\u52A8` };
|
|
31916
32018
|
await refuse({ kind: "startFailed", message: error62.message });
|
|
31917
32019
|
return "handled";
|
|
31918
32020
|
}
|
|
@@ -31944,6 +32046,7 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
31944
32046
|
let reported = { pid: 0, sessionId: "" };
|
|
31945
32047
|
const result = await this.acpChats.run(sessionKey, spec, {
|
|
31946
32048
|
runId,
|
|
32049
|
+
...payload.cli_command ? { command: payload.cli_command } : {},
|
|
31947
32050
|
prompt: context.prompt,
|
|
31948
32051
|
attachments,
|
|
31949
32052
|
sessionId: payload.session_id,
|
|
@@ -31954,7 +32057,7 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
31954
32057
|
fast: turn.fast,
|
|
31955
32058
|
workdir,
|
|
31956
32059
|
notes,
|
|
31957
|
-
...turn.prompts ? { prompts: turn.prompts } : {}
|
|
32060
|
+
...turn.prompts && (!payload.cli_command || payload.cli_command_interactive) ? { prompts: turn.prompts } : {}
|
|
31958
32061
|
}, {
|
|
31959
32062
|
events: (events) => {
|
|
31960
32063
|
forwarder.push(events);
|
|
@@ -31972,6 +32075,11 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
31972
32075
|
});
|
|
31973
32076
|
}
|
|
31974
32077
|
}, launch);
|
|
32078
|
+
if (payload.cli_command && !payload.cli_command_interactive) {
|
|
32079
|
+
await this.acpChats.closeSession(sessionKey).catch((error62) => {
|
|
32080
|
+
this.logger.warn("command-process-close-failed", { runId, error: errorMessage2(error62) });
|
|
32081
|
+
});
|
|
32082
|
+
}
|
|
31975
32083
|
await forwarder.drain();
|
|
31976
32084
|
this.acpRuns.delete(runId);
|
|
31977
32085
|
const durationMs = Date.now() - run2.startedAt;
|
|
@@ -33160,8 +33268,8 @@ var OrphanRegistry = class {
|
|
|
33160
33268
|
file;
|
|
33161
33269
|
records = /* @__PURE__ */ new Map();
|
|
33162
33270
|
writing = Promise.resolve();
|
|
33163
|
-
add(
|
|
33164
|
-
this.records.set(
|
|
33271
|
+
add(record10) {
|
|
33272
|
+
this.records.set(record10.runId, record10);
|
|
33165
33273
|
this.persist();
|
|
33166
33274
|
}
|
|
33167
33275
|
remove(runId) {
|
|
@@ -33185,12 +33293,12 @@ var OrphanRegistry = class {
|
|
|
33185
33293
|
return [];
|
|
33186
33294
|
}
|
|
33187
33295
|
const reaped = [];
|
|
33188
|
-
for (const
|
|
33189
|
-
if (!
|
|
33190
|
-
const command = await commandOf(
|
|
33191
|
-
if (command && command.includes(basename3(
|
|
33192
|
-
await killProcessTree(
|
|
33193
|
-
reaped.push(
|
|
33296
|
+
for (const record10 of previous) {
|
|
33297
|
+
if (!record10 || typeof record10.pid !== "number" || record10.pid <= 1) continue;
|
|
33298
|
+
const command = await commandOf(record10.pid);
|
|
33299
|
+
if (command && command.includes(basename3(record10.executable))) {
|
|
33300
|
+
await killProcessTree(record10.pid);
|
|
33301
|
+
reaped.push(record10);
|
|
33194
33302
|
}
|
|
33195
33303
|
}
|
|
33196
33304
|
this.records.clear();
|
|
@@ -33332,9 +33440,9 @@ var GatewayClient = class {
|
|
|
33332
33440
|
};
|
|
33333
33441
|
|
|
33334
33442
|
// src/workspace/directory-browser.ts
|
|
33335
|
-
import { readdir as readdir3, realpath as realpath4, stat as stat7 } from "node:fs/promises";
|
|
33443
|
+
import { mkdir as mkdir9, readdir as readdir3, realpath as realpath4, stat as stat7 } from "node:fs/promises";
|
|
33336
33444
|
import { homedir as homedir11 } from "node:os";
|
|
33337
|
-
import { dirname as dirname9, parse as parse3, resolve as resolve6 } from "node:path";
|
|
33445
|
+
import { dirname as dirname9, isAbsolute as isAbsolute5, parse as parse3, resolve as resolve6 } from "node:path";
|
|
33338
33446
|
var MAX_ENTRIES = 1e3;
|
|
33339
33447
|
async function listDirectory(requested, allowedRoots) {
|
|
33340
33448
|
const raw = requested.trim().replace(/^~(?=$|[\\/])/, homedir11()) || homedir11();
|
|
@@ -33367,12 +33475,35 @@ async function listDirectory(requested, allowedRoots) {
|
|
|
33367
33475
|
places
|
|
33368
33476
|
};
|
|
33369
33477
|
}
|
|
33478
|
+
async function createDirectory(parentRequested, name) {
|
|
33479
|
+
const parentInput = parentRequested.trim();
|
|
33480
|
+
if (!parentInput || !isAbsolute5(parentInput)) throw new Error("\u4E0A\u7EA7\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");
|
|
33481
|
+
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)) {
|
|
33482
|
+
throw new Error("\u8BF7\u8F93\u5165\u6709\u6548\u7684\u6587\u4EF6\u5939\u540D\u79F0");
|
|
33483
|
+
}
|
|
33484
|
+
const parent = await realpath4(resolve6(parentInput)).catch(() => {
|
|
33485
|
+
throw new Error(`\u4E0A\u7EA7\u76EE\u5F55\u4E0D\u5B58\u5728\uFF1A${parentRequested}`);
|
|
33486
|
+
});
|
|
33487
|
+
if (!(await stat7(parent)).isDirectory()) throw new Error("\u4E0A\u7EA7\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55");
|
|
33488
|
+
const path = resolve6(parent, name);
|
|
33489
|
+
if (dirname9(path) !== parent) throw new Error("\u6587\u4EF6\u5939\u540D\u79F0\u65E0\u6548");
|
|
33490
|
+
try {
|
|
33491
|
+
await mkdir9(path);
|
|
33492
|
+
} catch (error62) {
|
|
33493
|
+
const code2 = error62.code;
|
|
33494
|
+
if (code2 === "EEXIST") throw new Error("\u8BE5\u6587\u4EF6\u5939\u5DF2\u5B58\u5728");
|
|
33495
|
+
if (code2 === "EACCES" || code2 === "EPERM") throw new Error("\u6CA1\u6709\u6743\u9650\u5728\u6B64\u4F4D\u7F6E\u521B\u5EFA\u6587\u4EF6\u5939");
|
|
33496
|
+
if (code2 === "ENOENT") throw new Error("\u4E0A\u7EA7\u76EE\u5F55\u4E0D\u5B58\u5728");
|
|
33497
|
+
throw error62;
|
|
33498
|
+
}
|
|
33499
|
+
return { path };
|
|
33500
|
+
}
|
|
33370
33501
|
|
|
33371
33502
|
// src/workspace/workspace-manager.ts
|
|
33372
33503
|
import { spawn as spawn13 } from "node:child_process";
|
|
33373
|
-
import {
|
|
33374
|
-
import { homedir as homedir12
|
|
33375
|
-
import { isAbsolute as
|
|
33504
|
+
import { opendir, realpath as realpath5, stat as stat8 } from "node:fs/promises";
|
|
33505
|
+
import { homedir as homedir12 } from "node:os";
|
|
33506
|
+
import { isAbsolute as isAbsolute6, relative as relative3, resolve as resolve7 } from "node:path";
|
|
33376
33507
|
var MAX_NODES = 2e3;
|
|
33377
33508
|
var MAX_DIRECTORY_ENTRIES = 12e3;
|
|
33378
33509
|
var IGNORED_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
@@ -33406,193 +33537,13 @@ var WorkspaceManager = class {
|
|
|
33406
33537
|
const nodes = await this.scanTree(rootPath, request.max_depth, request.scan_roots);
|
|
33407
33538
|
return { root_path: rootPath, nodes, truncated: nodes.length >= MAX_NODES, duration_ms: Date.now() - startedAt };
|
|
33408
33539
|
}
|
|
33409
|
-
/** Creates missing folders, clones missing repos, fast-forwards clean ones. */
|
|
33410
|
-
async sync(request) {
|
|
33411
|
-
const startedAt = Date.now();
|
|
33412
|
-
const rootPath = this.validateRootPath(request.root_path);
|
|
33413
|
-
const results = await this.syncTree(rootPath, request);
|
|
33414
|
-
const failed = results.some((result) => result.status === "failed");
|
|
33415
|
-
return {
|
|
33416
|
-
root_path: rootPath,
|
|
33417
|
-
results,
|
|
33418
|
-
...failed ? { error: "\u90E8\u5206\u76EE\u5F55\u6216\u4ED3\u5E93\u540C\u6B65\u5931\u8D25" } : {},
|
|
33419
|
-
duration_ms: Date.now() - startedAt
|
|
33420
|
-
};
|
|
33421
|
-
}
|
|
33422
33540
|
validateRootPath(value) {
|
|
33423
33541
|
const raw = value.trim().replace(/^~(?=$|[\\/])/, homedir12());
|
|
33424
33542
|
const root2 = resolve7(raw);
|
|
33425
|
-
if (!
|
|
33543
|
+
if (!isAbsolute6(raw)) throw new Error("\u6839\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");
|
|
33426
33544
|
if (relative3(root2, resolve7(root2, "..")) === "") throw new Error("\u4E0D\u80FD\u628A\u6587\u4EF6\u7CFB\u7EDF\u6839\u76EE\u5F55\u4F5C\u4E3A\u76EE\u5F55\u6839");
|
|
33427
33545
|
return root2;
|
|
33428
33546
|
}
|
|
33429
|
-
async syncTree(rootPath, request) {
|
|
33430
|
-
await mkdir9(rootPath, { recursive: true });
|
|
33431
|
-
await addAllowedRoot(this.config, rootPath);
|
|
33432
|
-
const results = [];
|
|
33433
|
-
const requestedPaths = /* @__PURE__ */ new Set();
|
|
33434
|
-
for (const directory of request.directories) {
|
|
33435
|
-
const relativePath = this.cleanRelativePath(directory);
|
|
33436
|
-
if (requestedPaths.has(relativePath)) continue;
|
|
33437
|
-
requestedPaths.add(relativePath);
|
|
33438
|
-
const target = this.resolveWithinRoot(rootPath, relativePath);
|
|
33439
|
-
try {
|
|
33440
|
-
const metadata = await stat8(target).catch(() => void 0);
|
|
33441
|
-
if (metadata) {
|
|
33442
|
-
if (!metadata.isDirectory()) {
|
|
33443
|
-
throw new Error("The existing workspace path is not a directory");
|
|
33444
|
-
}
|
|
33445
|
-
results.push({
|
|
33446
|
-
relative_path: relativePath,
|
|
33447
|
-
status: "skipped",
|
|
33448
|
-
kind: "directory",
|
|
33449
|
-
action: "skip",
|
|
33450
|
-
message: "\u76EE\u5F55\u5DF2\u5B58\u5728"
|
|
33451
|
-
});
|
|
33452
|
-
continue;
|
|
33453
|
-
}
|
|
33454
|
-
await mkdir9(target, { recursive: true });
|
|
33455
|
-
results.push({
|
|
33456
|
-
relative_path: relativePath,
|
|
33457
|
-
status: "created",
|
|
33458
|
-
kind: "directory",
|
|
33459
|
-
action: "mkdir",
|
|
33460
|
-
message: "\u76EE\u5F55\u5DF2\u521B\u5EFA"
|
|
33461
|
-
});
|
|
33462
|
-
} catch (error62) {
|
|
33463
|
-
results.push({
|
|
33464
|
-
relative_path: relativePath,
|
|
33465
|
-
status: "failed",
|
|
33466
|
-
kind: "directory",
|
|
33467
|
-
action: "mkdir",
|
|
33468
|
-
error: this.message(error62)
|
|
33469
|
-
});
|
|
33470
|
-
}
|
|
33471
|
-
}
|
|
33472
|
-
const authEnvironment = await this.createGitAuthEnvironment(request.git_auth);
|
|
33473
|
-
try {
|
|
33474
|
-
for (const repo of request.repos) {
|
|
33475
|
-
const relativePath = this.cleanRelativePath(repo.relative_path);
|
|
33476
|
-
try {
|
|
33477
|
-
results.push(await this.syncRepository(rootPath, relativePath, repo.git_url?.trim() || void 0, repo.branch?.trim() || void 0, request.timeout_s, authEnvironment?.env));
|
|
33478
|
-
} catch (error62) {
|
|
33479
|
-
results.push({
|
|
33480
|
-
relative_path: relativePath,
|
|
33481
|
-
status: "failed",
|
|
33482
|
-
kind: "repo",
|
|
33483
|
-
action: "sync",
|
|
33484
|
-
error: this.message(error62)
|
|
33485
|
-
});
|
|
33486
|
-
}
|
|
33487
|
-
}
|
|
33488
|
-
} finally {
|
|
33489
|
-
await authEnvironment?.cleanup();
|
|
33490
|
-
}
|
|
33491
|
-
return results;
|
|
33492
|
-
}
|
|
33493
|
-
async syncRepository(rootPath, relativePath, gitUrl, branch, timeoutSeconds, gitEnvironment) {
|
|
33494
|
-
const target = this.resolveWithinRoot(rootPath, relativePath);
|
|
33495
|
-
let created = false;
|
|
33496
|
-
let metadata;
|
|
33497
|
-
try {
|
|
33498
|
-
metadata = await stat8(target);
|
|
33499
|
-
} catch {
|
|
33500
|
-
}
|
|
33501
|
-
if (!metadata) {
|
|
33502
|
-
if (!gitUrl) throw new Error("A missing repository needs a Git remote URL");
|
|
33503
|
-
await mkdir9(resolve7(target, ".."), { recursive: true });
|
|
33504
|
-
const cloneArgs = branch ? ["clone", "--branch", branch, "--single-branch", gitUrl, target] : ["clone", gitUrl, target];
|
|
33505
|
-
await this.runGit(cloneArgs, rootPath, timeoutSeconds, false, gitEnvironment);
|
|
33506
|
-
created = true;
|
|
33507
|
-
} else {
|
|
33508
|
-
if (!metadata.isDirectory()) throw new Error("The repository path is not a directory");
|
|
33509
|
-
if (!await this.isGitRepository(target, timeoutSeconds)) {
|
|
33510
|
-
throw new Error("The existing directory is not a Git repository");
|
|
33511
|
-
}
|
|
33512
|
-
if (gitUrl) {
|
|
33513
|
-
const currentOrigin = (await this.runGit(["config", "--get", "remote.origin.url"], target, timeoutSeconds, true)).stdout.trim();
|
|
33514
|
-
if (currentOrigin && currentOrigin !== gitUrl) {
|
|
33515
|
-
throw new Error("The existing repository origin does not match the configured Git URL");
|
|
33516
|
-
}
|
|
33517
|
-
}
|
|
33518
|
-
const worktree = await this.runGit(["status", "--porcelain"], target, timeoutSeconds);
|
|
33519
|
-
if (worktree.stdout.trim()) {
|
|
33520
|
-
return {
|
|
33521
|
-
relative_path: relativePath,
|
|
33522
|
-
status: "skipped",
|
|
33523
|
-
kind: "repo",
|
|
33524
|
-
action: "skip",
|
|
33525
|
-
message: "\u4ED3\u5E93\u5B58\u5728\u672A\u63D0\u4EA4\u7684\u672C\u5730\u4FEE\u6539"
|
|
33526
|
-
};
|
|
33527
|
-
}
|
|
33528
|
-
if (branch) {
|
|
33529
|
-
const currentBranch = await this.runGit(["branch", "--show-current"], target, timeoutSeconds);
|
|
33530
|
-
if (currentBranch.stdout.trim() !== branch) {
|
|
33531
|
-
return {
|
|
33532
|
-
relative_path: relativePath,
|
|
33533
|
-
status: "skipped",
|
|
33534
|
-
kind: "repo",
|
|
33535
|
-
action: "skip",
|
|
33536
|
-
message: `\u5F53\u524D\u5206\u652F ${currentBranch.stdout.trim() || "(detached)"} \u4E0E\u76EE\u6807\u5206\u652F ${branch} \u4E0D\u4E00\u81F4`
|
|
33537
|
-
};
|
|
33538
|
-
}
|
|
33539
|
-
}
|
|
33540
|
-
}
|
|
33541
|
-
await this.runGit(["fetch", "--prune", "origin"], target, timeoutSeconds, false, gitEnvironment);
|
|
33542
|
-
if (branch) {
|
|
33543
|
-
const remoteBranch = await this.runGit(
|
|
33544
|
-
["show-ref", "--verify", "--quiet", `refs/remotes/origin/${branch}`],
|
|
33545
|
-
target,
|
|
33546
|
-
timeoutSeconds,
|
|
33547
|
-
true
|
|
33548
|
-
);
|
|
33549
|
-
if (remoteBranch.exitCode !== 0) {
|
|
33550
|
-
return {
|
|
33551
|
-
relative_path: relativePath,
|
|
33552
|
-
status: "skipped",
|
|
33553
|
-
kind: "repo",
|
|
33554
|
-
action: "skip",
|
|
33555
|
-
message: `\u8FDC\u7AEF\u5206\u652F origin/${branch} \u4E0D\u5B58\u5728`
|
|
33556
|
-
};
|
|
33557
|
-
}
|
|
33558
|
-
if (!created) {
|
|
33559
|
-
const currentCommit = await this.runGit(["rev-parse", "HEAD"], target, timeoutSeconds);
|
|
33560
|
-
const remoteCommit = await this.runGit(["rev-parse", `origin/${branch}`], target, timeoutSeconds);
|
|
33561
|
-
if (currentCommit.stdout.trim() === remoteCommit.stdout.trim()) {
|
|
33562
|
-
return {
|
|
33563
|
-
relative_path: relativePath,
|
|
33564
|
-
status: "skipped",
|
|
33565
|
-
kind: "repo",
|
|
33566
|
-
action: "skip",
|
|
33567
|
-
message: "\u4ED3\u5E93\u5DF2\u662F\u6700\u65B0"
|
|
33568
|
-
};
|
|
33569
|
-
}
|
|
33570
|
-
const fastForward = await this.runGit(
|
|
33571
|
-
["merge-base", "--is-ancestor", "HEAD", `origin/${branch}`],
|
|
33572
|
-
target,
|
|
33573
|
-
timeoutSeconds,
|
|
33574
|
-
true
|
|
33575
|
-
);
|
|
33576
|
-
if (fastForward.exitCode !== 0) {
|
|
33577
|
-
return {
|
|
33578
|
-
relative_path: relativePath,
|
|
33579
|
-
status: "skipped",
|
|
33580
|
-
kind: "repo",
|
|
33581
|
-
action: "skip",
|
|
33582
|
-
message: "\u672C\u5730\u63D0\u4EA4\u65E0\u6CD5\u5FEB\u8FDB\u5230\u8FDC\u7AEF\u5206\u652F"
|
|
33583
|
-
};
|
|
33584
|
-
}
|
|
33585
|
-
}
|
|
33586
|
-
await this.runGit(["pull", "--ff-only", "origin", branch], target, timeoutSeconds, false, gitEnvironment);
|
|
33587
|
-
}
|
|
33588
|
-
return {
|
|
33589
|
-
relative_path: relativePath,
|
|
33590
|
-
status: created ? "created" : "updated",
|
|
33591
|
-
kind: "repo",
|
|
33592
|
-
action: created ? "clone" : "pull",
|
|
33593
|
-
message: created ? "\u4ED3\u5E93\u5DF2\u514B\u9686" : "\u4ED3\u5E93\u5DF2\u5FEB\u8FDB\u66F4\u65B0"
|
|
33594
|
-
};
|
|
33595
|
-
}
|
|
33596
33547
|
async scanTree(rootPath, maxDepth, scanRoots) {
|
|
33597
33548
|
const resolvedRoot = await realpath5(rootPath);
|
|
33598
33549
|
const rootMetadata = await stat8(resolvedRoot);
|
|
@@ -33706,16 +33657,16 @@ var WorkspaceManager = class {
|
|
|
33706
33657
|
resolveWithinRoot(rootPath, relativePath) {
|
|
33707
33658
|
const target = resolve7(rootPath, relativePath);
|
|
33708
33659
|
const relativeToRoot = relative3(rootPath, target);
|
|
33709
|
-
if (relativeToRoot.startsWith("..") ||
|
|
33660
|
+
if (relativeToRoot.startsWith("..") || isAbsolute6(relativeToRoot)) {
|
|
33710
33661
|
throw new Error("A workspace path must remain under the configured workspace root");
|
|
33711
33662
|
}
|
|
33712
33663
|
return target;
|
|
33713
33664
|
}
|
|
33714
|
-
runGit(args, cwd, timeoutSeconds, allowFailure = false
|
|
33665
|
+
runGit(args, cwd, timeoutSeconds, allowFailure = false) {
|
|
33715
33666
|
return new Promise((resolveCommand, rejectCommand) => {
|
|
33716
33667
|
const child = spawn13("git", args, {
|
|
33717
33668
|
cwd,
|
|
33718
|
-
env:
|
|
33669
|
+
env: process.env,
|
|
33719
33670
|
shell: false,
|
|
33720
33671
|
stdio: ["ignore", "pipe", "pipe"]
|
|
33721
33672
|
});
|
|
@@ -33745,37 +33696,6 @@ var WorkspaceManager = class {
|
|
|
33745
33696
|
});
|
|
33746
33697
|
});
|
|
33747
33698
|
}
|
|
33748
|
-
async createGitAuthEnvironment(auth) {
|
|
33749
|
-
if (!auth) return void 0;
|
|
33750
|
-
const directory = await mkdtemp3(join21(tmpdir4(), "toc-ocra-git-auth-"));
|
|
33751
|
-
const isWindows = process.platform === "win32";
|
|
33752
|
-
const scriptPath = join21(directory, isWindows ? "askpass.cmd" : "askpass.sh");
|
|
33753
|
-
let script;
|
|
33754
|
-
if (isWindows) {
|
|
33755
|
-
const helperPath = join21(directory, "askpass.cjs");
|
|
33756
|
-
await writeFile9(
|
|
33757
|
-
helperPath,
|
|
33758
|
-
'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',
|
|
33759
|
-
{ mode: 448 }
|
|
33760
|
-
);
|
|
33761
|
-
script = '@echo off\r\n"%ECHO_NODE_PATH%" "%~dp0askpass.cjs" "%~1"\r\n';
|
|
33762
|
-
} else {
|
|
33763
|
-
script = '#!/bin/sh\ncase "$1" in *Username*|*username*) printf "%s\\n" "$ECHO_GIT_USERNAME" ;; *) printf "%s\\n" "$ECHO_GIT_PASSWORD" ;; esac\n';
|
|
33764
|
-
}
|
|
33765
|
-
await writeFile9(scriptPath, script, { mode: 448 });
|
|
33766
|
-
if (!isWindows) await chmod5(scriptPath, 448);
|
|
33767
|
-
return {
|
|
33768
|
-
env: {
|
|
33769
|
-
...process.env,
|
|
33770
|
-
GIT_ASKPASS: scriptPath,
|
|
33771
|
-
GIT_TERMINAL_PROMPT: "0",
|
|
33772
|
-
ECHO_NODE_PATH: process.execPath,
|
|
33773
|
-
ECHO_GIT_USERNAME: auth.username,
|
|
33774
|
-
ECHO_GIT_PASSWORD: auth.password
|
|
33775
|
-
},
|
|
33776
|
-
cleanup: () => rm6(directory, { recursive: true, force: true })
|
|
33777
|
-
};
|
|
33778
|
-
}
|
|
33779
33699
|
message(error62) {
|
|
33780
33700
|
return error62 instanceof Error ? error62.message : String(error62);
|
|
33781
33701
|
}
|
|
@@ -33795,6 +33715,8 @@ var RunStartPayloadSchema = external_exports.object({
|
|
|
33795
33715
|
task_chain_id: external_exports.string().optional().default(""),
|
|
33796
33716
|
message_id: external_exports.string().optional().default(""),
|
|
33797
33717
|
prompt: external_exports.string().max(512 * 1024),
|
|
33718
|
+
cli_command: external_exports.object({ name: external_exports.string().min(1).max(200), arguments: external_exports.string().max(64 * 1024).optional().default("") }).optional(),
|
|
33719
|
+
cli_command_interactive: external_exports.boolean().optional(),
|
|
33798
33720
|
chat_session_id: external_exports.string().max(64).optional(),
|
|
33799
33721
|
attachments: external_exports.array(external_exports.object({ media_id: external_exports.string().min(1).max(64), name: external_exports.string().max(200), kind: external_exports.enum(["image", "file"]) })).max(16).optional(),
|
|
33800
33722
|
task_attachments: external_exports.array(external_exports.object({ file_id: external_exports.uuid(), name: external_exports.string().min(1).max(255), mime: external_exports.string().max(255), size: external_exports.number().int().positive(), sha256: external_exports.string().regex(/^[a-f0-9]{64}$/), prompt_token: external_exports.string().max(100) })).max(16).nullish(),
|
|
@@ -33901,22 +33823,15 @@ var CliProviderControlPayloadSchema = external_exports.object({
|
|
|
33901
33823
|
}).strict();
|
|
33902
33824
|
var RelativePathSchema = external_exports.string().min(1).max(500);
|
|
33903
33825
|
var FsListPayloadSchema = external_exports.object({ path: external_exports.string().max(4096).optional().default("") });
|
|
33826
|
+
var FsMkdirPayloadSchema = external_exports.object({
|
|
33827
|
+
parent_path: external_exports.string().min(1).max(4096),
|
|
33828
|
+
name: external_exports.string().min(1).max(255)
|
|
33829
|
+
}).strict();
|
|
33904
33830
|
var WorkspaceScanPayloadSchema = external_exports.object({
|
|
33905
33831
|
root_path: external_exports.string().min(1).max(4096),
|
|
33906
33832
|
max_depth: external_exports.number().int().positive().max(20).optional(),
|
|
33907
33833
|
scan_roots: external_exports.array(external_exports.object({ relative_path: RelativePathSchema, max_depth: external_exports.number().int().positive().max(20) })).max(2e3).optional()
|
|
33908
33834
|
});
|
|
33909
|
-
var WorkspaceSyncPayloadSchema = external_exports.object({
|
|
33910
|
-
root_path: external_exports.string().min(1).max(4096),
|
|
33911
|
-
directories: external_exports.array(RelativePathSchema).max(2e3).default([]),
|
|
33912
|
-
repos: external_exports.array(external_exports.object({
|
|
33913
|
-
relative_path: RelativePathSchema,
|
|
33914
|
-
git_url: external_exports.string().max(2e3).nullable().optional(),
|
|
33915
|
-
branch: external_exports.string().max(200).nullable().optional()
|
|
33916
|
-
})).max(2e3).default([]),
|
|
33917
|
-
timeout_s: external_exports.number().int().positive().max(3600).optional(),
|
|
33918
|
-
git_auth: external_exports.object({ username: external_exports.string().min(1).max(500), password: external_exports.string().min(1).max(4096) }).optional()
|
|
33919
|
-
});
|
|
33920
33835
|
|
|
33921
33836
|
// src/runtime/agent-runtime.ts
|
|
33922
33837
|
var sleep3 = (ms, signal2) => new Promise((resolve10) => {
|
|
@@ -34145,6 +34060,7 @@ var AgentRuntime = class {
|
|
|
34145
34060
|
task_attachments: { version: 1 },
|
|
34146
34061
|
// `run.transcript`: any run's structured items and run-log rows, kept on this device after the run.
|
|
34147
34062
|
run_transcripts: { version: 1 },
|
|
34063
|
+
cli_commands: { version: 1 },
|
|
34148
34064
|
// `memory.provider` commands and the `memory` field of run payloads (Lody's memoryProviders v1).
|
|
34149
34065
|
memory_providers: { version: 1, providers: [...MEMORY_PROVIDER_IDS] },
|
|
34150
34066
|
cli_execution_policy: { version: 1, modes: ["restricted", "full"] },
|
|
@@ -34272,6 +34188,16 @@ var AgentRuntime = class {
|
|
|
34272
34188
|
if (!this.catalogReport) return { success: false, error: "\u8BFB\u53D6\u6A21\u578B\u76EE\u5F55\u5931\u8D25" };
|
|
34273
34189
|
return { success: true, result: this.catalogReport };
|
|
34274
34190
|
}
|
|
34191
|
+
case "cli.commands": {
|
|
34192
|
+
const value = command.payload;
|
|
34193
|
+
if (!value || typeof value.agent_type !== "string") return { success: false, error: "CLI \u7C7B\u578B\u65E0\u6548" };
|
|
34194
|
+
return { success: true, result: await this.runs.listCLICommands({
|
|
34195
|
+
agent_type: value.agent_type,
|
|
34196
|
+
...typeof value.workdir === "string" ? { workdir: value.workdir } : {},
|
|
34197
|
+
...typeof value.model === "string" ? { model: value.model } : {},
|
|
34198
|
+
...typeof value.reasoning_effort === "string" ? { reasoning_effort: value.reasoning_effort } : {}
|
|
34199
|
+
}) };
|
|
34200
|
+
}
|
|
34275
34201
|
case "cli.quota": {
|
|
34276
34202
|
const payload = CliQuotaPayloadSchema.parse(command.payload ?? {});
|
|
34277
34203
|
try {
|
|
@@ -34309,15 +34235,14 @@ var AgentRuntime = class {
|
|
|
34309
34235
|
const payload = FsListPayloadSchema.parse(command.payload ?? {});
|
|
34310
34236
|
return { success: true, result: await listDirectory(payload.path, this.config.allowedRoots) };
|
|
34311
34237
|
}
|
|
34238
|
+
case "fs.mkdir": {
|
|
34239
|
+
const payload = FsMkdirPayloadSchema.parse(command.payload);
|
|
34240
|
+
return { success: true, result: await createDirectory(payload.parent_path, payload.name) };
|
|
34241
|
+
}
|
|
34312
34242
|
case "workspace.scan": {
|
|
34313
34243
|
const payload = WorkspaceScanPayloadSchema.parse(command.payload);
|
|
34314
34244
|
return { success: true, result: await this.workspaces.scan(payload) };
|
|
34315
34245
|
}
|
|
34316
|
-
case "workspace.sync": {
|
|
34317
|
-
const payload = WorkspaceSyncPayloadSchema.parse(command.payload);
|
|
34318
|
-
const result = await this.workspaces.sync(payload);
|
|
34319
|
-
return { success: !result.error, result, ...result.error ? { error: result.error } : {} };
|
|
34320
|
-
}
|
|
34321
34246
|
case "sql.run": {
|
|
34322
34247
|
const payload = SqlRunPayloadSchema.parse(command.payload);
|
|
34323
34248
|
this.checkPolicy("sql", payload.policy);
|
|
@@ -34328,16 +34253,14 @@ var AgentRuntime = class {
|
|
|
34328
34253
|
}
|
|
34329
34254
|
}
|
|
34330
34255
|
/**
|
|
34331
|
-
* Script / SQL run
|
|
34332
|
-
* owner has not switched it off. The policy attached to the command was
|
|
34256
|
+
* Script / SQL run when the server policy allows it. The policy attached to the command was
|
|
34333
34257
|
* checked by the server at enqueue time, so it wins over the (up to one
|
|
34334
34258
|
* heartbeat old) cached copy. New policy fields (read-only SQL,
|
|
34335
34259
|
* allowlists) are enforced here.
|
|
34336
34260
|
*/
|
|
34337
34261
|
checkPolicy(kind, commandPolicy) {
|
|
34338
|
-
const localOff = kind === "script" ? this.config.disableScript : this.config.disableSql;
|
|
34339
34262
|
const policy = commandPolicy ?? this.policy;
|
|
34340
|
-
const enabled =
|
|
34263
|
+
const enabled = policy[kind].enabled;
|
|
34341
34264
|
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");
|
|
34342
34265
|
}
|
|
34343
34266
|
// ---- Reports ----
|
|
@@ -34742,19 +34665,19 @@ async function smoke(args) {
|
|
|
34742
34665
|
const only = [];
|
|
34743
34666
|
let full = false;
|
|
34744
34667
|
let json2 = false;
|
|
34745
|
-
let
|
|
34668
|
+
let record10;
|
|
34746
34669
|
let timeout;
|
|
34747
34670
|
for (let index = 0; index < args.length; index++) {
|
|
34748
34671
|
const arg = args[index];
|
|
34749
34672
|
if (arg === "--full") full = true;
|
|
34750
34673
|
else if (arg === "--json") json2 = true;
|
|
34751
|
-
else if (arg === "--record")
|
|
34674
|
+
else if (arg === "--record") record10 = resolve9(args[++index] ?? "recordings");
|
|
34752
34675
|
else if (arg === "--timeout") timeout = Number(args[++index]) || void 0;
|
|
34753
34676
|
else if (arg !== "--smoke") only.push(arg);
|
|
34754
34677
|
}
|
|
34755
34678
|
const hydration = await hydrateShellPath({ force: true });
|
|
34756
34679
|
if (hydration.ok) mergePathSegments(hydration.segments);
|
|
34757
|
-
const results = await runCliSmoke({ only, full, ...
|
|
34680
|
+
const results = await runCliSmoke({ only, full, ...record10 ? { record: record10 } : {}, ...timeout ? { timeoutSeconds: timeout } : {}, ...json2 ? {} : { log: (line) => process.stdout.write(`${line}
|
|
34758
34681
|
`) } });
|
|
34759
34682
|
if (json2) process.stdout.write(`${JSON.stringify(results, null, 2)}
|
|
34760
34683
|
`);
|
|
@@ -34855,7 +34778,7 @@ async function update(args) {
|
|
|
34855
34778
|
if (customConfig) process.env.TOC_OCRA_CONFIG = resolve9(customConfig);
|
|
34856
34779
|
await ensureIdle();
|
|
34857
34780
|
const npmPath = resolveCliCommand("npm");
|
|
34858
|
-
const temporary = mkdtempSync(join23(
|
|
34781
|
+
const temporary = mkdtempSync(join23(tmpdir4(), "toc-ocra-update-"));
|
|
34859
34782
|
try {
|
|
34860
34783
|
const metadataResponse = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}`, { headers: { accept: "application/json", "cache-control": "no-cache" }, signal: AbortSignal.timeout(15e3) });
|
|
34861
34784
|
if (!metadataResponse.ok) throw new Error("\u65E0\u6CD5\u8BFB\u53D6 npm \u6700\u65B0\u7248\u672C\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");
|