toc-ocra 0.2.27 → 0.2.29
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 +3 -3
- package/dist/cli/cli.mjs +287 -104
- package/dist/service/agent.mjs +283 -103
- package/dist/src/index.js +5 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/providers/cli/claude.js +95 -18
- package/dist/src/providers/cli/claude.js.map +1 -1
- package/dist/src/providers/cli/kiro.d.ts +8 -1
- package/dist/src/providers/cli/kiro.js +156 -100
- package/dist/src/providers/cli/kiro.js.map +1 -1
- package/dist/src/providers/provider.d.ts +57 -2
- package/dist/src/providers/provider.js +59 -0
- package/dist/src/providers/provider.js.map +1 -1
- package/dist/src/runs/run-supervisor.js +55 -8
- package/dist/src/runs/run-supervisor.js.map +1 -1
- package/package.json +1 -1
- package/scripts/installation.cjs +115 -127
- package/scripts/postinstall.cjs +15 -2
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ node dist/src/index.js run
|
|
|
27
27
|
|
|
28
28
|
**本机**(一键启用 / 关闭)
|
|
29
29
|
|
|
30
|
-
1. 打开「本机设备代理」开关:桌面端用自带的 Node
|
|
30
|
+
1. 打开「本机设备代理」开关:桌面端用自带的 Node 运行唯一 npm 全局安装里的 `dist/service/agent.mjs`(`tocPlugin.entries.service`,权限 `service:local`),不需要终端,也不需要另装 Node。
|
|
31
31
|
2. 桌面端给这次启动生成令牌(`TOC_PLUGIN_SERVICE_TOKEN`)并交给插件,插件直接用它访问本机控制接口,不再输入 6 位连接码,随后自动绑定到当前登录的服务器。
|
|
32
32
|
3. 设备代理跟随桌面端:开关保持打开时,下次打开桌面端自动启动;退出桌面端、关闭开关、禁用或卸载插件时停止。
|
|
33
33
|
4. 这台电脑已有 toc-ocra 在运行(后台服务或终端启动)时,桌面端不会再启动第二个:开关直接显示「已启用」并连接已有实例(首次需输入连接码;此时开关不可操作,它不随桌面端退出而停止,停用请 `toc-ocra service:uninstall`)。若桌面端仍启动了实例,会因端口被占用退出(退出码 3),插件同样按已有实例处理,保证一台设备只有一个 Agent。
|
|
@@ -103,9 +103,9 @@ kiro-cli chat --no-interactive --trust-all-tools --model gpt-5.6-luna --effort h
|
|
|
103
103
|
|
|
104
104
|
下载文件暂时保留,可手工清理;`.echo` 不进入设备目录扫描,并带有仅作用于该内部目录的 Git 忽略规则。视频也可下载为文件,实际解析取决于 CLI 的能力。
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
终端 `toc-ocra update` 和 Echo 插件中心升级都会更新同一份 npm 全局安装,并在空闲时重启实际运行的 Agent。插件界面、后台服务和 `toc-ocra --version` 都读取该目录的真实版本;Echo 插件缓存只保留版本记录,不存放第二份包。桌面端每 5 秒读取当前版本,终端升级后会同步刷新。源码开发模式仍直接运行工作目录中的构建。
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
`~/Library/Application Support/toc-ocra/installation/current.json` 只记录唯一安装位置。macOS 本机保留 nvm 下的一份 `toc-ocra`;Homebrew 副本、共享程序副本和额外启动入口都不再使用。
|
|
109
109
|
|
|
110
110
|
从 `0.2.25` 起,一台电脑只允许一个主 Agent,任务链与聊天统一在该进程中处理。重复执行 `toc-ocra run` 会提示已有实例并退出;改变配置目录或健康端口不能绕过本机单实例锁。安装或升级会检查活动任务,等待旧服务退出后只启动一次;正常退出释放本机锁和服务器租约,崩溃后的服务器租约最多等待 90 秒再恢复。
|
|
111
111
|
|
package/dist/cli/cli.mjs
CHANGED
|
@@ -16675,8 +16675,8 @@ function rewriteKeyNames(ctx) {
|
|
|
16675
16675
|
bySchema.set(entry.schema, entry);
|
|
16676
16676
|
}
|
|
16677
16677
|
const rewrites = /* @__PURE__ */ new Map();
|
|
16678
|
-
for (const
|
|
16679
|
-
const seen = ctx.seen.get(
|
|
16678
|
+
for (const record4 of pendingRecords.get(ctx) ?? []) {
|
|
16679
|
+
const seen = ctx.seen.get(record4);
|
|
16680
16680
|
const names = (seen?.def ?? seen?.schema)?.propertyNames;
|
|
16681
16681
|
if (!names || names === true || rewrites.has(names))
|
|
16682
16682
|
continue;
|
|
@@ -20286,6 +20286,42 @@ function getVersionManagerBinPaths(options = {}) {
|
|
|
20286
20286
|
}
|
|
20287
20287
|
|
|
20288
20288
|
// src/providers/provider.ts
|
|
20289
|
+
function pickCreatedSession(before, after, prompt) {
|
|
20290
|
+
const created = after.filter((session) => !before.has(session.id));
|
|
20291
|
+
if (created.length <= 1) return created[0]?.id;
|
|
20292
|
+
const flat = (text) => text.replace(/\s+/g, " ").trim();
|
|
20293
|
+
const wanted = flat(prompt);
|
|
20294
|
+
const titled = created.filter((session) => {
|
|
20295
|
+
const title = flat(session.title ?? "").replace(/(\.\.\.|…)$/, "").trim();
|
|
20296
|
+
return title.length > 0 && wanted.startsWith(title);
|
|
20297
|
+
});
|
|
20298
|
+
return titled.length === 1 ? titled[0].id : void 0;
|
|
20299
|
+
}
|
|
20300
|
+
var runLog = {
|
|
20301
|
+
event: (text) => `\u25CF ${text}`,
|
|
20302
|
+
error: (text) => `\u2717 ${clip(text)}`,
|
|
20303
|
+
reply: (text) => textRows("\u203A ", text),
|
|
20304
|
+
/** Rows continuing the previous reply. */
|
|
20305
|
+
replyMore: (text) => text.split(/\r?\n/).map((row) => ` ${row}`),
|
|
20306
|
+
thinking: (text) => textRows("\u2026 ", clip(text, 600), 8),
|
|
20307
|
+
command: (command) => `$ ${clip(command)}`,
|
|
20308
|
+
commandOutput: (output2) => output2 ? textRows(" ", clip(output2, 2e3), 20) : [],
|
|
20309
|
+
commandExit: (code2) => ` (exit ${typeof code2 === "number" ? code2 : "?"})`,
|
|
20310
|
+
fileChange: (path) => `\u270E \u4FEE\u6539\u6587\u4EF6${path ? ` ${path}` : ""}`,
|
|
20311
|
+
/** A tool call without its own row type, by the kinds the clients name. */
|
|
20312
|
+
tool: (kind) => `\xB7 ${kind}`
|
|
20313
|
+
};
|
|
20314
|
+
var EDIT_TOOLS = /^(edit|multiedit|write|notebookedit|fs_write|write_file|edit_file|create_file|str_replace|apply_patch|create)$/;
|
|
20315
|
+
var READ_TOOLS = /^(read|fs_read|glob|grep|ls|list|code|view|search_files|find|read_file|list_directory)$/;
|
|
20316
|
+
function toolCallRows(name, path) {
|
|
20317
|
+
const tool = name.trim().toLowerCase();
|
|
20318
|
+
if (EDIT_TOOLS.test(tool)) return [runLog.fileChange(path)];
|
|
20319
|
+
if (READ_TOOLS.test(tool)) return [];
|
|
20320
|
+
if (tool.startsWith("mcp__") || tool.startsWith("@")) return [runLog.tool("mcp_tool_call")];
|
|
20321
|
+
if (/web_?(search|fetch)/.test(tool)) return [runLog.tool("web_search")];
|
|
20322
|
+
if (/todo/.test(tool)) return [runLog.tool("todo_list")];
|
|
20323
|
+
return [runLog.tool("tool_call")];
|
|
20324
|
+
}
|
|
20289
20325
|
function providerEnvironment() {
|
|
20290
20326
|
const env = { ...process.env };
|
|
20291
20327
|
const commandPaths = [
|
|
@@ -20359,32 +20395,92 @@ var claudeProvider = {
|
|
|
20359
20395
|
return resolveExecutable("claude", args, env, process.env.TOC_OCRA_CLAUDE_PATH);
|
|
20360
20396
|
},
|
|
20361
20397
|
parseLine(line) {
|
|
20398
|
+
return claudeLineParser()(line);
|
|
20399
|
+
},
|
|
20400
|
+
createLineParser: () => claudeLineParser()
|
|
20401
|
+
};
|
|
20402
|
+
var record2 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
20403
|
+
function toolResultText(content) {
|
|
20404
|
+
if (typeof content === "string") return content;
|
|
20405
|
+
if (Array.isArray(content)) return content.map((part) => str(record2(part).text) ?? "").filter(Boolean).join("\n");
|
|
20406
|
+
return "";
|
|
20407
|
+
}
|
|
20408
|
+
function claudeLineParser() {
|
|
20409
|
+
const shells = /* @__PURE__ */ new Map();
|
|
20410
|
+
let lastShell = "";
|
|
20411
|
+
let started = false;
|
|
20412
|
+
return (line) => {
|
|
20362
20413
|
const event = tryJson(line);
|
|
20363
20414
|
if (!event) return { display: line.trim() ? [line] : [] };
|
|
20415
|
+
if (event.parent_tool_use_id) return { display: [] };
|
|
20364
20416
|
const sessionId = str(event.session_id);
|
|
20365
20417
|
const base = sessionId ? { sessionId } : {};
|
|
20366
20418
|
switch (str(event.type)) {
|
|
20367
|
-
case "
|
|
20368
|
-
|
|
20369
|
-
|
|
20370
|
-
return { ...base,
|
|
20419
|
+
case "system": {
|
|
20420
|
+
if (started || str(event.subtype) !== "init") return { ...base, display: [] };
|
|
20421
|
+
started = true;
|
|
20422
|
+
return { ...base, display: [`\u25CF \u4F1A\u8BDD ${sessionId ?? ""}`, runLog.event("\u5F00\u59CB\u5904\u7406")] };
|
|
20371
20423
|
}
|
|
20372
20424
|
case "assistant": {
|
|
20373
|
-
const content = event.message
|
|
20374
|
-
const rows =
|
|
20375
|
-
|
|
20376
|
-
|
|
20377
|
-
|
|
20378
|
-
|
|
20425
|
+
const content = record2(event.message).content ?? [];
|
|
20426
|
+
const rows = [];
|
|
20427
|
+
for (const value of Array.isArray(content) ? content : []) {
|
|
20428
|
+
const part = record2(value);
|
|
20429
|
+
if (part.type === "text") {
|
|
20430
|
+
if (str(part.text)) rows.push(...runLog.reply(String(part.text)));
|
|
20431
|
+
lastShell = "";
|
|
20432
|
+
continue;
|
|
20433
|
+
}
|
|
20434
|
+
if (part.type === "thinking") {
|
|
20435
|
+
if (str(part.thinking)) rows.push(...runLog.thinking(String(part.thinking)));
|
|
20436
|
+
lastShell = "";
|
|
20437
|
+
continue;
|
|
20438
|
+
}
|
|
20439
|
+
if (part.type !== "tool_use") continue;
|
|
20440
|
+
const name = str(part.name) ?? "tool";
|
|
20441
|
+
const input2 = record2(part.input);
|
|
20442
|
+
const id = str(part.id) ?? "";
|
|
20443
|
+
if (name === "Bash") {
|
|
20444
|
+
const command = str(input2.command) ?? "";
|
|
20445
|
+
shells.set(id, command);
|
|
20446
|
+
rows.push(runLog.command(command));
|
|
20447
|
+
lastShell = id;
|
|
20448
|
+
continue;
|
|
20449
|
+
}
|
|
20450
|
+
rows.push(...toolCallRows(name, str(input2.file_path) ?? str(input2.notebook_path)));
|
|
20451
|
+
lastShell = "";
|
|
20452
|
+
}
|
|
20379
20453
|
return { ...base, display: rows };
|
|
20380
20454
|
}
|
|
20381
|
-
case "
|
|
20382
|
-
|
|
20455
|
+
case "user": {
|
|
20456
|
+
const content = record2(event.message).content ?? [];
|
|
20457
|
+
const rows = [];
|
|
20458
|
+
for (const value of Array.isArray(content) ? content : []) {
|
|
20459
|
+
const part = record2(value);
|
|
20460
|
+
if (part.type !== "tool_result") continue;
|
|
20461
|
+
const id = str(part.tool_use_id) ?? "";
|
|
20462
|
+
const command = shells.get(id);
|
|
20463
|
+
if (command === void 0) {
|
|
20464
|
+
if (part.is_error === true) rows.push(runLog.error(toolResultText(part.content) || "\u5DE5\u5177\u8C03\u7528\u5931\u8D25"));
|
|
20465
|
+
continue;
|
|
20466
|
+
}
|
|
20467
|
+
shells.delete(id);
|
|
20468
|
+
if (lastShell !== id) rows.push(runLog.command(command));
|
|
20469
|
+
rows.push(...runLog.commandOutput(toolResultText(part.content)), runLog.commandExit(part.is_error === true ? 1 : 0));
|
|
20470
|
+
lastShell = "";
|
|
20471
|
+
}
|
|
20472
|
+
return { ...base, display: rows };
|
|
20473
|
+
}
|
|
20474
|
+
case "result": {
|
|
20475
|
+
const text = str(event.result) ?? "";
|
|
20476
|
+
if (event.is_error === true) return { ...base, turnError: text || "claude failed", display: [runLog.error(text || "Claude \u672C\u8F6E\u6267\u884C\u5931\u8D25")] };
|
|
20477
|
+
return { ...base, message: text, turnCompleted: true, display: [runLog.event("\u672C\u8F6E\u5B8C\u6210")] };
|
|
20478
|
+
}
|
|
20383
20479
|
default:
|
|
20384
20480
|
return { ...base, display: [] };
|
|
20385
20481
|
}
|
|
20386
|
-
}
|
|
20387
|
-
}
|
|
20482
|
+
};
|
|
20483
|
+
}
|
|
20388
20484
|
|
|
20389
20485
|
// src/providers/cli/codex.ts
|
|
20390
20486
|
var codexProvider = {
|
|
@@ -20494,44 +20590,103 @@ var grokProvider = {
|
|
|
20494
20590
|
};
|
|
20495
20591
|
|
|
20496
20592
|
// src/providers/cli/kiro.ts
|
|
20497
|
-
import { execFile
|
|
20593
|
+
import { execFile } from "node:child_process";
|
|
20498
20594
|
import { promisify } from "node:util";
|
|
20499
20595
|
var execFileAsync = promisify(execFile);
|
|
20500
|
-
|
|
20501
|
-
if (!text) return true;
|
|
20502
|
-
if (text.startsWith("\u22EE") || text.startsWith("\u25B8") || text.startsWith("\u25CF")) return true;
|
|
20503
|
-
if (/^Running tool\b/.test(text)) return true;
|
|
20504
|
-
if (/^- Completed in\b/.test(text)) return true;
|
|
20505
|
-
if (/^All tools are now trusted\b/.test(text)) return true;
|
|
20506
|
-
if (/^Agents can sometimes do unexpected things\b/.test(text)) return true;
|
|
20507
|
-
if (/^Learn more at\b/.test(text)) return true;
|
|
20508
|
-
return false;
|
|
20509
|
-
}
|
|
20596
|
+
var ANSI = /\u001b(?:\][^\u0007]*?(?:\u0007|\u001b\\)|\[[0-?]*[ -/]*[@-~]|[@-Z\\-_])/g;
|
|
20510
20597
|
function kiroLaunch(args) {
|
|
20511
20598
|
return resolveExecutable("kiro-cli", args, providerEnvironment(), process.env.TOC_OCRA_KIRO_PATH);
|
|
20512
20599
|
}
|
|
20513
20600
|
var LIST_SESSIONS = ["chat", "--list-sessions", "--format", "json"];
|
|
20514
|
-
function
|
|
20601
|
+
function parseKiroSessions(stdout) {
|
|
20515
20602
|
const parsed = JSON.parse(stdout);
|
|
20516
|
-
return parsed.flatMap((entry) => entry.sessions ?? []).filter((entry) => entry.source !== "v3" && !entry.sessionId
|
|
20517
|
-
}
|
|
20518
|
-
|
|
20519
|
-
|
|
20520
|
-
|
|
20521
|
-
|
|
20522
|
-
|
|
20523
|
-
|
|
20524
|
-
|
|
20525
|
-
|
|
20526
|
-
|
|
20527
|
-
|
|
20528
|
-
|
|
20529
|
-
|
|
20530
|
-
|
|
20531
|
-
|
|
20532
|
-
|
|
20533
|
-
return
|
|
20534
|
-
|
|
20603
|
+
return parsed.flatMap((entry) => entry.sessions ?? []).filter((entry) => entry.source !== "v3" && entry.sessionId && !entry.sessionId.startsWith("sess_")).map((entry) => ({ id: entry.sessionId, ...entry.title ? { title: entry.title } : {} }));
|
|
20604
|
+
}
|
|
20605
|
+
function isChrome(text) {
|
|
20606
|
+
return /^(⋮|▸|●)/.test(text) || /^Purpose:/.test(text) || /^All tools are now trusted\b/.test(text) || /^Agents can sometimes do unexpected things\b/.test(text) || /^Learn more at\b/.test(text);
|
|
20607
|
+
}
|
|
20608
|
+
function kiroLineParser() {
|
|
20609
|
+
let mode = "none";
|
|
20610
|
+
let command = "";
|
|
20611
|
+
let commandLast = false;
|
|
20612
|
+
let reply = [];
|
|
20613
|
+
const commandRows = (text) => {
|
|
20614
|
+
const rows = commandLast ? [] : [runLog.command(command)];
|
|
20615
|
+
commandLast = true;
|
|
20616
|
+
return [...rows, ...runLog.commandOutput(text)];
|
|
20617
|
+
};
|
|
20618
|
+
const parse4 = (raw) => {
|
|
20619
|
+
const event = tryJson(raw);
|
|
20620
|
+
if (event && raw.trim().startsWith("{")) return jsonLine(event, raw);
|
|
20621
|
+
const text = raw.replace(ANSI, "").replace(/^λ↯\s*/, "").replace(/\s+$/, "");
|
|
20622
|
+
const trimmed = text.trim();
|
|
20623
|
+
if (!trimmed) {
|
|
20624
|
+
if (mode === "reply") reply.push("");
|
|
20625
|
+
return { display: [] };
|
|
20626
|
+
}
|
|
20627
|
+
const answer = /^>\s?(.*)$/.exec(trimmed);
|
|
20628
|
+
if (answer && !(command && !raw.includes("\x1B"))) {
|
|
20629
|
+
mode = "reply";
|
|
20630
|
+
commandLast = false;
|
|
20631
|
+
reply = [answer[1] ?? ""];
|
|
20632
|
+
return { message: reply.join("\n").trim(), display: runLog.reply(answer[1] ?? "") };
|
|
20633
|
+
}
|
|
20634
|
+
const using = /^(.*?)\s*\(using tool: ([\w@/.-]+)\)(.*)$/.exec(trimmed);
|
|
20635
|
+
if (using) {
|
|
20636
|
+
const [, head = "", tool = "", rest = ""] = using;
|
|
20637
|
+
mode = "tool";
|
|
20638
|
+
let rows;
|
|
20639
|
+
if (tool === "shell" || tool === "execute_bash") {
|
|
20640
|
+
command = head.replace(/^I will run the following command:\s*/i, "").trim();
|
|
20641
|
+
commandLast = false;
|
|
20642
|
+
rows = commandRows("");
|
|
20643
|
+
} else {
|
|
20644
|
+
const path = /:\s*(\S+?)(?:,|$)/.exec(head)?.[1];
|
|
20645
|
+
rows = toolCallRows(tool, path);
|
|
20646
|
+
if (rows.length) commandLast = false;
|
|
20647
|
+
}
|
|
20648
|
+
const more = rest.trim() ? parse4(rest).display : [];
|
|
20649
|
+
return { display: [...rows, ...more] };
|
|
20650
|
+
}
|
|
20651
|
+
if (/^Running tool\b/.test(trimmed)) {
|
|
20652
|
+
mode = "tool";
|
|
20653
|
+
commandLast = false;
|
|
20654
|
+
return { display: [/\(from mcp server:/.test(trimmed) ? runLog.tool("mcp_tool_call") : runLog.tool("tool_call")] };
|
|
20655
|
+
}
|
|
20656
|
+
if (/^- Completed in\b/.test(trimmed)) {
|
|
20657
|
+
const done = command && commandLast ? [runLog.commandExit(0)] : [];
|
|
20658
|
+
if (command && commandLast) {
|
|
20659
|
+
command = "";
|
|
20660
|
+
commandLast = false;
|
|
20661
|
+
}
|
|
20662
|
+
mode = "none";
|
|
20663
|
+
return { display: done };
|
|
20664
|
+
}
|
|
20665
|
+
if (isChrome(trimmed)) return { display: [] };
|
|
20666
|
+
if (/^✓/.test(trimmed)) return { display: [] };
|
|
20667
|
+
if (/^[✗❗]/.test(trimmed) && mode !== "reply" && !command) return { display: [runLog.error(trimmed.replace(/^[✗❗]\s*/, ""))] };
|
|
20668
|
+
if (mode === "reply") {
|
|
20669
|
+
reply.push(text);
|
|
20670
|
+
return { message: reply.join("\n").trim(), display: runLog.replyMore(text) };
|
|
20671
|
+
}
|
|
20672
|
+
if (command) return { display: commandRows(text) };
|
|
20673
|
+
if (mode === "tool") return { display: [] };
|
|
20674
|
+
return { display: [text] };
|
|
20675
|
+
};
|
|
20676
|
+
return parse4;
|
|
20677
|
+
}
|
|
20678
|
+
function jsonLine(event, line) {
|
|
20679
|
+
const sessionId = str(event.session_id) ?? str(event.sessionId);
|
|
20680
|
+
const message = str(event.response) ?? str(event.message) ?? str(event.text);
|
|
20681
|
+
const error62 = typeof event.error === "string" ? event.error : event.error && typeof event.error === "object" ? str(event.error.message) : void 0;
|
|
20682
|
+
const type = str(event.type) ?? "";
|
|
20683
|
+
return {
|
|
20684
|
+
...sessionId ? { sessionId } : {},
|
|
20685
|
+
...message ? { message } : {},
|
|
20686
|
+
...error62 ? { turnError: error62 } : {},
|
|
20687
|
+
...message && (type === "result" || type === "turn.completed") ? { turnCompleted: true } : {},
|
|
20688
|
+
display: message ? runLog.reply(message) : error62 ? [runLog.error(error62)] : [line]
|
|
20689
|
+
};
|
|
20535
20690
|
}
|
|
20536
20691
|
var kiroProvider = {
|
|
20537
20692
|
id: "kiro",
|
|
@@ -20541,44 +20696,33 @@ var kiroProvider = {
|
|
|
20541
20696
|
else args.push("--trust-tools=@doer/echo_report_task_progress");
|
|
20542
20697
|
if (request.model) args.push("--model", request.model);
|
|
20543
20698
|
if (request.reasoningEffort) args.push("--effort", request.reasoningEffort);
|
|
20544
|
-
if (request.sessionId &&
|
|
20699
|
+
if (request.sessionId && !request.sessionId.startsWith("sess_")) args.push("--resume-id", request.sessionId);
|
|
20545
20700
|
args.push("--", request.prompt);
|
|
20546
20701
|
return kiroLaunch(args);
|
|
20547
20702
|
},
|
|
20548
|
-
async
|
|
20549
|
-
const
|
|
20550
|
-
|
|
20551
|
-
|
|
20552
|
-
|
|
20553
|
-
|
|
20554
|
-
|
|
20703
|
+
async listSessions(workdir) {
|
|
20704
|
+
const { executable, args, env } = kiroLaunch(LIST_SESSIONS);
|
|
20705
|
+
try {
|
|
20706
|
+
const { stdout } = await execFileAsync(executable, args, { cwd: workdir, env, timeout: 15e3, maxBuffer: 8 * 1024 * 1024 });
|
|
20707
|
+
return parseKiroSessions(stdout);
|
|
20708
|
+
} catch {
|
|
20709
|
+
return void 0;
|
|
20555
20710
|
}
|
|
20556
|
-
|
|
20711
|
+
},
|
|
20712
|
+
inspectExit(context) {
|
|
20713
|
+
const businessError = kiroStderrError(context.stderr);
|
|
20714
|
+
if (businessError) return { turnError: businessError };
|
|
20715
|
+
const credits = context.stderr.map((line) => /^\s*▸\s*(Credits:.*)$/.exec(line.replace(ANSI, ""))?.[1]).find(Boolean);
|
|
20716
|
+
return credits ? { display: [runLog.event(`\u672C\u8F6E\u5B8C\u6210\uFF08${credits.trim().replace(/\s*•\s*/g, " \xB7 ")}\uFF09`)] } : {};
|
|
20557
20717
|
},
|
|
20558
20718
|
parseLine(line) {
|
|
20559
|
-
|
|
20560
|
-
|
|
20561
|
-
|
|
20562
|
-
|
|
20563
|
-
|
|
20564
|
-
|
|
20565
|
-
|
|
20566
|
-
return {
|
|
20567
|
-
...sessionId ? { sessionId } : {},
|
|
20568
|
-
...message ? { message } : {},
|
|
20569
|
-
...error62 ? { turnError: error62 } : {},
|
|
20570
|
-
...message && (type === "result" || type === "turn.completed") ? { turnCompleted: true } : {},
|
|
20571
|
-
display: message ? textRows("\u203A ", message) : error62 ? [`\u2717 ${error62}`] : [line]
|
|
20572
|
-
};
|
|
20573
|
-
}
|
|
20574
|
-
const text = line.replace(/^λ↯\s*/, "").trim();
|
|
20575
|
-
if (!text) return { display: [] };
|
|
20576
|
-
const answer = text.match(/^>\s?(.*)$/);
|
|
20577
|
-
if (answer && answer[1]?.trim()) {
|
|
20578
|
-
return { message: answer[1].trim(), display: [`\u203A ${answer[1].trim()}`] };
|
|
20579
|
-
}
|
|
20580
|
-
if (isNoiseLine(text)) return { display: [] };
|
|
20581
|
-
return { display: [line.replace(/^λ↯\s*/, "")] };
|
|
20719
|
+
return kiroLineParser()(line);
|
|
20720
|
+
},
|
|
20721
|
+
createLineParser: () => kiroLineParser(),
|
|
20722
|
+
stderrDisplay(line) {
|
|
20723
|
+
const text = line.replace(ANSI, "").trim();
|
|
20724
|
+
if (!text || isChrome(text)) return [];
|
|
20725
|
+
return [line];
|
|
20582
20726
|
}
|
|
20583
20727
|
};
|
|
20584
20728
|
function kiroStderrError(stderrLines) {
|
|
@@ -21363,8 +21507,8 @@ function codexChatProvider(request, attachments) {
|
|
|
21363
21507
|
}
|
|
21364
21508
|
|
|
21365
21509
|
// src/providers/chat/claude-stream-json.ts
|
|
21366
|
-
var
|
|
21367
|
-
var textContent = (value) => typeof value === "string" ? value : Array.isArray(value) ? value.map((part) => str(
|
|
21510
|
+
var record3 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
21511
|
+
var textContent = (value) => typeof value === "string" ? value : Array.isArray(value) ? value.map((part) => str(record3(part).text) ?? "").filter(Boolean).join("\n") : JSON.stringify(value ?? "");
|
|
21368
21512
|
function claudeChatProvider(attachments) {
|
|
21369
21513
|
let messageID = "";
|
|
21370
21514
|
let messageSequence = 0;
|
|
@@ -21394,14 +21538,14 @@ function claudeChatProvider(attachments) {
|
|
|
21394
21538
|
const events = [];
|
|
21395
21539
|
if (envelope.parent_tool_use_id) return { ...base, display: [] };
|
|
21396
21540
|
if (envelope.type === "stream_event") {
|
|
21397
|
-
const event =
|
|
21541
|
+
const event = record3(envelope.event);
|
|
21398
21542
|
const index = Number(event.index ?? 0);
|
|
21399
21543
|
if (event.type === "message_start") {
|
|
21400
|
-
messageID = str(
|
|
21544
|
+
messageID = str(record3(event.message).id) ?? `message:${++messageSequence}`;
|
|
21401
21545
|
blocks.clear();
|
|
21402
21546
|
} else if (event.type === "content_block_start") {
|
|
21403
21547
|
if (!messageID) messageID = `message:${++messageSequence}`;
|
|
21404
|
-
const part =
|
|
21548
|
+
const part = record3(event.content_block);
|
|
21405
21549
|
const type = part.type === "tool_use" ? "tool_call" : part.type === "thinking" ? "thought" : "text";
|
|
21406
21550
|
if (!["tool_use", "thinking", "text"].includes(String(part.type))) return { ...base, display: [] };
|
|
21407
21551
|
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: "" };
|
|
@@ -21410,7 +21554,7 @@ function claudeChatProvider(attachments) {
|
|
|
21410
21554
|
events.push(asItem(block, "in_progress"));
|
|
21411
21555
|
} else if (event.type === "content_block_delta") {
|
|
21412
21556
|
const block = blocks.get(index);
|
|
21413
|
-
const delta =
|
|
21557
|
+
const delta = record3(event.delta);
|
|
21414
21558
|
if (!block) return { ...base, display: [] };
|
|
21415
21559
|
if (delta.type === "text_delta" || delta.type === "thinking_delta") {
|
|
21416
21560
|
const text = String(delta.text ?? delta.thinking ?? "");
|
|
@@ -21427,11 +21571,11 @@ function claudeChatProvider(attachments) {
|
|
|
21427
21571
|
if (block && block.type !== "tool_call") events.push(asItem(block, "completed"));
|
|
21428
21572
|
}
|
|
21429
21573
|
} else if (envelope.type === "assistant") {
|
|
21430
|
-
const message =
|
|
21574
|
+
const message = record3(envelope.message);
|
|
21431
21575
|
const id = str(message.id) || messageID || `message:${++messageSequence}`;
|
|
21432
21576
|
const parts = Array.isArray(message.content) ? message.content : [];
|
|
21433
21577
|
parts.forEach((value, index) => {
|
|
21434
|
-
const part =
|
|
21578
|
+
const part = record3(value);
|
|
21435
21579
|
if (!["text", "thinking", "tool_use"].includes(String(part.type))) return;
|
|
21436
21580
|
const type = part.type === "tool_use" ? "tool_call" : part.type === "thinking" ? "thought" : "text";
|
|
21437
21581
|
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: "" };
|
|
@@ -21440,9 +21584,9 @@ function claudeChatProvider(attachments) {
|
|
|
21440
21584
|
events.push(asItem(block, type === "tool_call" ? "in_progress" : "completed"));
|
|
21441
21585
|
});
|
|
21442
21586
|
} else if (envelope.type === "user") {
|
|
21443
|
-
const message =
|
|
21587
|
+
const message = record3(envelope.message);
|
|
21444
21588
|
for (const value of Array.isArray(message.content) ? message.content : []) {
|
|
21445
|
-
const part =
|
|
21589
|
+
const part = record3(value);
|
|
21446
21590
|
if (part.type !== "tool_result") continue;
|
|
21447
21591
|
const id = str(part.tool_use_id);
|
|
21448
21592
|
if (!id) continue;
|
|
@@ -22349,8 +22493,8 @@ var OrphanRegistry = class {
|
|
|
22349
22493
|
file;
|
|
22350
22494
|
records = /* @__PURE__ */ new Map();
|
|
22351
22495
|
writing = Promise.resolve();
|
|
22352
|
-
add(
|
|
22353
|
-
this.records.set(
|
|
22496
|
+
add(record4) {
|
|
22497
|
+
this.records.set(record4.runId, record4);
|
|
22354
22498
|
this.persist();
|
|
22355
22499
|
}
|
|
22356
22500
|
remove(runId) {
|
|
@@ -22374,12 +22518,12 @@ var OrphanRegistry = class {
|
|
|
22374
22518
|
return [];
|
|
22375
22519
|
}
|
|
22376
22520
|
const reaped = [];
|
|
22377
|
-
for (const
|
|
22378
|
-
if (!
|
|
22379
|
-
const command = await commandOf(
|
|
22380
|
-
if (command && command.includes(basename(
|
|
22381
|
-
await killProcessTree(
|
|
22382
|
-
reaped.push(
|
|
22521
|
+
for (const record4 of previous) {
|
|
22522
|
+
if (!record4 || typeof record4.pid !== "number" || record4.pid <= 1) continue;
|
|
22523
|
+
const command = await commandOf(record4.pid);
|
|
22524
|
+
if (command && command.includes(basename(record4.executable))) {
|
|
22525
|
+
await killProcessTree(record4.pid);
|
|
22526
|
+
reaped.push(record4);
|
|
22383
22527
|
}
|
|
22384
22528
|
}
|
|
22385
22529
|
this.records.clear();
|
|
@@ -22721,12 +22865,30 @@ var RunSupervisor = class {
|
|
|
22721
22865
|
}
|
|
22722
22866
|
}
|
|
22723
22867
|
if (!payload.prompt && !payload.attachments?.length) return refuse("\u6D88\u606F\u5185\u5BB9\u4E3A\u7A7A");
|
|
22868
|
+
let sessionId = payload.session_id;
|
|
22869
|
+
let sessionsBefore;
|
|
22870
|
+
let sessionNote = "";
|
|
22871
|
+
if (!payload.chat_session_id && provider.listSessions) {
|
|
22872
|
+
const saved = await provider.listSessions(workdir);
|
|
22873
|
+
if (!saved) {
|
|
22874
|
+
if (sessionId) sessionNote = `\u25CF \u65E0\u6CD5\u8BFB\u53D6 ${provider.id} \u7684\u5DF2\u4FDD\u5B58\u4F1A\u8BDD\uFF0C\u672C\u8F6E\u5F00\u59CB\u65B0\u4F1A\u8BDD
|
|
22875
|
+
`;
|
|
22876
|
+
sessionId = "";
|
|
22877
|
+
} else if (sessionId && !saved.some((session) => session.id === sessionId)) {
|
|
22878
|
+
sessionNote = `\u25CF \u539F\u4F1A\u8BDD ${sessionId} \u4E0D\u5728\u6B64\u76EE\u5F55\uFF0C\u672C\u8F6E\u5F00\u59CB\u65B0\u4F1A\u8BDD
|
|
22879
|
+
`;
|
|
22880
|
+
sessionId = "";
|
|
22881
|
+
sessionsBefore = new Set(saved.map((session) => session.id));
|
|
22882
|
+
} else if (!sessionId) {
|
|
22883
|
+
sessionsBefore = new Set(saved.map((session) => session.id));
|
|
22884
|
+
}
|
|
22885
|
+
}
|
|
22724
22886
|
if ([...this.active.values()].some((run3) => run3.workstationId === payload.workstation_id)) return refuse("\u672C\u673A\u8BE5\u5DE5\u4F4D\u5DF2\u6709\u4EFB\u52A1\u5728\u8FD0\u884C");
|
|
22725
22887
|
if (this.active.size + this.preparing.size > this.config.maxConcurrentRuns) return refuse("\u672C\u673A\u540C\u65F6\u8FD0\u884C\u7684\u4EFB\u52A1\u5DF2\u8FBE\u4E0A\u9650");
|
|
22726
22888
|
const launch = provider.buildLaunch({
|
|
22727
22889
|
permissionMode,
|
|
22728
22890
|
prompt: payload.prompt,
|
|
22729
|
-
sessionId
|
|
22891
|
+
sessionId,
|
|
22730
22892
|
model: payload.model,
|
|
22731
22893
|
reasoningEffort: payload.reasoning_effort,
|
|
22732
22894
|
workdir
|
|
@@ -22757,11 +22919,14 @@ var RunSupervisor = class {
|
|
|
22757
22919
|
workstationId: payload.workstation_id,
|
|
22758
22920
|
agentType: provider.id,
|
|
22759
22921
|
provider,
|
|
22922
|
+
parse: provider.createLineParser?.() ?? ((line) => provider.parseLine(line)),
|
|
22923
|
+
...sessionsBefore ? { sessionsBefore } : {},
|
|
22924
|
+
prompt: payload.prompt,
|
|
22760
22925
|
child,
|
|
22761
22926
|
pid: child.pid ?? 0,
|
|
22762
22927
|
startedAt: Date.now(),
|
|
22763
22928
|
workdir,
|
|
22764
|
-
sessionId
|
|
22929
|
+
sessionId,
|
|
22765
22930
|
finalMessage: "",
|
|
22766
22931
|
turnCompleted: false,
|
|
22767
22932
|
turnError: "",
|
|
@@ -22776,9 +22941,10 @@ var RunSupervisor = class {
|
|
|
22776
22941
|
this.preparing.delete(run2.runId);
|
|
22777
22942
|
this.unreported.add(run2.runId);
|
|
22778
22943
|
if (run2.pid > 1) this.orphans?.add({ runId: run2.runId, pid: run2.pid, executable: launch.executable, startedAt: run2.startedAt });
|
|
22779
|
-
run2.tail.append(
|
|
22944
|
+
if (sessionNote) run2.tail.append(sessionNote);
|
|
22945
|
+
run2.tail.append(`\u25CF ${provider.id} \u542F\u52A8\u4E8E ${workdir}${sessionId ? `\uFF08\u7EE7\u7EED\u4F1A\u8BDD ${sessionId}\uFF09` : ""}
|
|
22780
22946
|
`);
|
|
22781
|
-
this.logger.info("run-started", { runId: run2.runId, agentType: provider.id, pid: run2.pid, resume: Boolean(
|
|
22947
|
+
this.logger.info("run-started", { runId: run2.runId, agentType: provider.id, pid: run2.pid, resume: Boolean(sessionId) });
|
|
22782
22948
|
let spawnError = "";
|
|
22783
22949
|
child.stdin?.on("error", () => void 0);
|
|
22784
22950
|
child.once("error", (error62) => {
|
|
@@ -22790,8 +22956,11 @@ var RunSupervisor = class {
|
|
|
22790
22956
|
if (!clean.trim()) return;
|
|
22791
22957
|
run2.stderr.push(clean);
|
|
22792
22958
|
if (run2.stderr.length > MAX_ERROR_ROWS) run2.stderr.shift();
|
|
22793
|
-
|
|
22959
|
+
for (const row of provider.stderrDisplay ? provider.stderrDisplay(line) : [clean]) {
|
|
22960
|
+
const shown = sanitizeTerminalLine(row);
|
|
22961
|
+
if (shown.trim()) run2.tail.append(`${shown}
|
|
22794
22962
|
`);
|
|
22963
|
+
}
|
|
22795
22964
|
});
|
|
22796
22965
|
child.once("close", (code2, signal3) => void this.onExit(run2, code2, signal3, spawnError));
|
|
22797
22966
|
if (provider.startInput) {
|
|
@@ -22824,7 +22993,7 @@ var RunSupervisor = class {
|
|
|
22824
22993
|
});
|
|
22825
22994
|
}
|
|
22826
22995
|
onStdout(run2, rawLine) {
|
|
22827
|
-
const parsed = run2.
|
|
22996
|
+
const parsed = run2.parse(rawLine);
|
|
22828
22997
|
if (run2.chat && !run2.forwardingFailed) {
|
|
22829
22998
|
for (const event of parsed.chatEvents ?? []) this.queueChatEvent(run2, sanitizeChatEvent(event));
|
|
22830
22999
|
if (parsed.sessionId) run2.chatReady = true;
|
|
@@ -22866,11 +23035,22 @@ var RunSupervisor = class {
|
|
|
22866
23035
|
try {
|
|
22867
23036
|
const inspection = await run2.provider.inspectExit({ exitCode: code2, stderr: run2.stderr, workdir: run2.workdir, sessionId: run2.sessionId });
|
|
22868
23037
|
if (inspection.turnError && !run2.turnError) run2.turnError = sanitizeTerminalLine(inspection.turnError);
|
|
23038
|
+
for (const row of inspection.display ?? []) run2.tail.append(`${sanitizeTerminalLine(row)}
|
|
23039
|
+
`);
|
|
22869
23040
|
if (inspection.sessionId && inspection.sessionId !== run2.sessionId) run2.sessionId = inspection.sessionId;
|
|
22870
23041
|
} catch (error62) {
|
|
22871
23042
|
this.logger.warn("inspect-exit-failed", { runId: run2.runId, error: errorMessage(error62) });
|
|
22872
23043
|
}
|
|
22873
23044
|
}
|
|
23045
|
+
if (run2.sessionsBefore && !run2.sessionId && !spawnError && run2.provider.listSessions) {
|
|
23046
|
+
const after = await run2.provider.listSessions(run2.workdir).catch(() => void 0);
|
|
23047
|
+
const created = after ? pickCreatedSession(run2.sessionsBefore, after, run2.prompt) : void 0;
|
|
23048
|
+
if (created) run2.sessionId = created;
|
|
23049
|
+
else if (after?.some((session) => !run2.sessionsBefore.has(session.id))) {
|
|
23050
|
+
run2.tail.append("\u25CF \u540C\u76EE\u5F55\u6709\u5176\u4ED6\u4F1A\u8BDD\u540C\u65F6\u65B0\u5EFA\uFF0C\u65E0\u6CD5\u786E\u8BA4\u672C\u8F6E\u4F1A\u8BDD\uFF0C\u4E0B\u8F6E\u5C06\u5F00\u59CB\u65B0\u4F1A\u8BDD\n");
|
|
23051
|
+
this.logger.warn("session-ambiguous", { runId: run2.runId, agentType: run2.agentType });
|
|
23052
|
+
}
|
|
23053
|
+
}
|
|
22874
23054
|
const durationMs = Date.now() - run2.startedAt;
|
|
22875
23055
|
let report;
|
|
22876
23056
|
if (run2.cancelRequested) {
|
|
@@ -24577,8 +24757,11 @@ async function update(args) {
|
|
|
24577
24757
|
process.exitCode = install.status ?? 1;
|
|
24578
24758
|
return;
|
|
24579
24759
|
}
|
|
24760
|
+
const previousVersion = agentVersion();
|
|
24580
24761
|
const current = await installShared(join12(temporary, "node_modules", PACKAGE_NAME), { startService: existsSync6(defaultConfigPath()) });
|
|
24581
|
-
process.stdout.write(`toc-ocra \u5DF2\
|
|
24762
|
+
if (current.version === previousVersion) process.stdout.write(`toc-ocra \u5DF2\u662F\u6700\u65B0\u7248\u672C ${current.version}
|
|
24763
|
+
`);
|
|
24764
|
+
else process.stdout.write(`toc-ocra \u5DF2\u5347\u7EA7\u5230 ${current.version}\uFF0C\u7EC8\u7AEF\u4E0E Echo \u63D2\u4EF6\u5171\u7528\u6B64\u7248\u672C
|
|
24582
24765
|
`);
|
|
24583
24766
|
} finally {
|
|
24584
24767
|
rmSync(temporary, { recursive: true, force: true });
|