toc-ocra 0.3.0 → 0.3.1
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 +5 -5
- package/dist/cli/cli.mjs +438 -52
- package/dist/service/agent.mjs +426 -40
- package/dist/src/config.d.ts +1 -1
- package/dist/src/providers/acp/acp-driver.d.ts +1 -1
- package/dist/src/providers/chat/codex-app-server.d.ts +1 -1
- package/dist/src/providers/chat/codex-app-server.js +1 -1
- package/dist/src/providers/chat/codex-goal.d.ts +17 -0
- package/dist/src/providers/chat/codex-goal.js +188 -0
- package/dist/src/providers/chat/codex-goal.js.map +1 -0
- package/dist/src/providers/cli/claude.d.ts +6 -0
- package/dist/src/providers/cli/claude.js +101 -3
- package/dist/src/providers/cli/claude.js.map +1 -1
- package/dist/src/providers/cli/codex-fork.d.ts +11 -0
- package/dist/src/providers/cli/codex-fork.js +84 -0
- package/dist/src/providers/cli/codex-fork.js.map +1 -0
- package/dist/src/providers/cli/kiro.js +1 -1
- package/dist/src/providers/cli-failure.js +1 -1
- package/dist/src/providers/provider.d.ts +17 -1
- package/dist/src/providers/provider.js.map +1 -1
- package/dist/src/providers/registry.d.ts +1 -1
- package/dist/src/runs/run-supervisor.d.ts +12 -7
- package/dist/src/runs/run-supervisor.js +83 -26
- package/dist/src/runs/run-supervisor.js.map +1 -1
- package/dist/src/runtime/agent-runtime.js +10 -10
- package/dist/src/runtime/agent-runtime.js.map +1 -1
- package/dist/src/smoke/cli-smoke.js +1 -1
- package/dist/src/smoke/cli-smoke.js.map +1 -1
- package/dist/src/transport/gateway-client.d.ts +3 -1
- package/dist/src/transport/gateway-client.js +6 -0
- package/dist/src/transport/gateway-client.js.map +1 -1
- package/dist/src/types/protocol.d.ts +32 -4
- package/dist/src/types/protocol.js +14 -3
- package/dist/src/types/protocol.js.map +1 -1
- package/locales/en.json +1 -1
- package/locales/zh-CN.json +1 -1
- package/package.json +1 -1
package/dist/service/agent.mjs
CHANGED
|
@@ -21083,10 +21083,58 @@ function isWriterConflict(message) {
|
|
|
21083
21083
|
}
|
|
21084
21084
|
|
|
21085
21085
|
// src/providers/cli/claude.ts
|
|
21086
|
-
import { readFileSync as readFileSync5 } from "node:fs";
|
|
21086
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync5 } from "node:fs";
|
|
21087
21087
|
import { homedir as homedir4 } from "node:os";
|
|
21088
21088
|
import { join as join7 } from "node:path";
|
|
21089
21089
|
var CLAUDE = requireCliSpec("claude");
|
|
21090
|
+
function claudeProjectRoots() {
|
|
21091
|
+
const configured = process.env.CLAUDE_CONFIG_DIR;
|
|
21092
|
+
const dirs = configured ? configured.split(process.platform === "win32" ? ";" : ":").map((entry) => entry.trim()).filter(Boolean) : [join7(homedir4(), ".claude")];
|
|
21093
|
+
return dirs.map((dir) => join7(dir, "projects"));
|
|
21094
|
+
}
|
|
21095
|
+
function claudeTranscriptExists(sessionId) {
|
|
21096
|
+
return claudeTranscriptPath(sessionId) !== void 0;
|
|
21097
|
+
}
|
|
21098
|
+
function claudeTranscriptPath(sessionId) {
|
|
21099
|
+
const file2 = `${sessionId}.jsonl`;
|
|
21100
|
+
for (const root of claudeProjectRoots()) {
|
|
21101
|
+
let projects;
|
|
21102
|
+
try {
|
|
21103
|
+
projects = readdirSync2(root);
|
|
21104
|
+
} catch {
|
|
21105
|
+
continue;
|
|
21106
|
+
}
|
|
21107
|
+
for (const project of projects) {
|
|
21108
|
+
try {
|
|
21109
|
+
if (readdirSync2(join7(root, project)).includes(file2)) return join7(root, project, file2);
|
|
21110
|
+
} catch {
|
|
21111
|
+
}
|
|
21112
|
+
}
|
|
21113
|
+
}
|
|
21114
|
+
return void 0;
|
|
21115
|
+
}
|
|
21116
|
+
function isPromptEntry(entry) {
|
|
21117
|
+
if (entry.type !== "user" || entry.isSidechain === true || entry.isMeta === true) return false;
|
|
21118
|
+
const content = record2(entry.message).content;
|
|
21119
|
+
if (typeof content === "string") return content.trim().length > 0;
|
|
21120
|
+
return Array.isArray(content) && content.some((part) => record2(part).type === "text");
|
|
21121
|
+
}
|
|
21122
|
+
function claudeForkBoundary(transcript, keepTurns) {
|
|
21123
|
+
if (keepTurns <= 0) return void 0;
|
|
21124
|
+
let prompts = 0;
|
|
21125
|
+
let boundary;
|
|
21126
|
+
for (const line of transcript.split(/\r?\n/)) {
|
|
21127
|
+
const entry = tryJson(line);
|
|
21128
|
+
if (!entry) continue;
|
|
21129
|
+
if (isPromptEntry(entry)) {
|
|
21130
|
+
prompts++;
|
|
21131
|
+
if (prompts > keepTurns) return boundary;
|
|
21132
|
+
continue;
|
|
21133
|
+
}
|
|
21134
|
+
if (entry.type === "assistant" && entry.isSidechain !== true && typeof entry.uuid === "string") boundary = entry.uuid;
|
|
21135
|
+
}
|
|
21136
|
+
return void 0;
|
|
21137
|
+
}
|
|
21090
21138
|
var claudeProvider = {
|
|
21091
21139
|
id: "claude",
|
|
21092
21140
|
buildLaunch(request) {
|
|
@@ -21105,7 +21153,21 @@ var claudeProvider = {
|
|
|
21105
21153
|
}
|
|
21106
21154
|
if (request.model) args.push("--model", request.model);
|
|
21107
21155
|
if (request.reasoningEffort) args.push("--effort", request.reasoningEffort);
|
|
21108
|
-
if (request.sessionId
|
|
21156
|
+
if (request.sessionId && request.fork && !claudeTranscriptExists(request.sessionId)) {
|
|
21157
|
+
args.push("--resume", request.fork.sourceSessionId, "--fork-session");
|
|
21158
|
+
const source = claudeTranscriptPath(request.fork.sourceSessionId);
|
|
21159
|
+
if (source && request.fork.keepTurns > 0) {
|
|
21160
|
+
let text = "";
|
|
21161
|
+
try {
|
|
21162
|
+
text = readFileSync5(source, "utf8");
|
|
21163
|
+
} catch {
|
|
21164
|
+
}
|
|
21165
|
+
const at = claudeForkBoundary(text, request.fork.keepTurns);
|
|
21166
|
+
if (at) args.push("--resume-session-at", at);
|
|
21167
|
+
}
|
|
21168
|
+
} else if (request.sessionId) {
|
|
21169
|
+
args.push(claudeTranscriptExists(request.sessionId) ? "--resume" : "--session-id", request.sessionId);
|
|
21170
|
+
}
|
|
21109
21171
|
return launchCli({ spec: CLAUDE, args, env, prompt: request.prompt });
|
|
21110
21172
|
},
|
|
21111
21173
|
parseLine(line) {
|
|
@@ -21425,7 +21487,7 @@ var COPY = {
|
|
|
21425
21487
|
notSignedIn: ({ label }) => `${label} \u672A\u767B\u5F55\u6216\u767B\u5F55\u5DF2\u5931\u6548\uFF0C\u8BF7\u5728\u8FD9\u53F0\u7535\u8111\u4E0A\u91CD\u65B0\u767B\u5F55\u540E\u518D\u8BD5`,
|
|
21426
21488
|
usageLimit: ({ label }) => `${label} \u7684\u989D\u5EA6\u5DF2\u7528\u5C3D\uFF0C\u8BF7\u7B49\u5F85\u989D\u5EA6\u91CD\u7F6E\u6216\u5347\u7EA7\u5957\u9910\u540E\u518D\u8BD5`,
|
|
21427
21489
|
rateLimited: ({ label }) => `${label} \u8BF7\u6C42\u8FC7\u4E8E\u9891\u7E41\uFF0C\u5DF2\u88AB\u9650\u6D41\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5`,
|
|
21428
|
-
modelUnavailable: ({ label }) => `${label} \u4E0D\u80FD\u4F7F\u7528\u6240\u9009\u6A21\u578B\uFF0C\u8BF7\u5728\
|
|
21490
|
+
modelUnavailable: ({ label }) => `${label} \u4E0D\u80FD\u4F7F\u7528\u6240\u9009\u6A21\u578B\uFF0C\u8BF7\u5728\u4F1A\u8BDD\u4E2D\u6362\u4E00\u4E2A\u6A21\u578B\u6216\u6539\u4E3A\u9ED8\u8BA4`,
|
|
21429
21491
|
sessionMissing: ({ label }) => `${label} \u627E\u4E0D\u5230\u8981\u7EE7\u7EED\u7684\u4F1A\u8BDD`,
|
|
21430
21492
|
promptTooLong: ({ label }) => `\u6D88\u606F\u8FC7\u957F\uFF0C\u8D85\u51FA\u672C\u673A\u547D\u4EE4\u884C\u957F\u5EA6\u4E0A\u9650\uFF0C${label} \u6682\u4E0D\u652F\u6301\u4ECE\u6807\u51C6\u8F93\u5165\u8BFB\u53D6\u63D0\u793A\u8BCD\uFF0C\u8BF7\u7F29\u77ED\u6D88\u606F\u540E\u91CD\u8BD5`,
|
|
21431
21493
|
contextTooLong: ({ label }) => `${label} \u7684\u4F1A\u8BDD\u5185\u5BB9\u5DF2\u8D85\u8FC7\u6A21\u578B\u4E0A\u4E0B\u6587\u4E0A\u9650\uFF0C\u8BF7\u5F00\u59CB\u65B0\u4F1A\u8BDD\u6216\u7CBE\u7B80\u6D88\u606F`,
|
|
@@ -23306,10 +23368,10 @@ function commandOf(pid) {
|
|
|
23306
23368
|
}
|
|
23307
23369
|
|
|
23308
23370
|
// src/runs/run-supervisor.ts
|
|
23309
|
-
import { spawn as
|
|
23371
|
+
import { spawn as spawn9 } from "node:child_process";
|
|
23310
23372
|
import { mkdir as mkdir5, realpath as realpath2, stat as stat3, writeFile as writeFile5 } from "node:fs/promises";
|
|
23311
23373
|
import { basename as basename3, isAbsolute as isAbsolute3, join as join13, relative as relative2, resolve as resolve3 } from "node:path";
|
|
23312
|
-
import { createInterface as
|
|
23374
|
+
import { createInterface as createInterface4 } from "node:readline";
|
|
23313
23375
|
|
|
23314
23376
|
// src/session/terminal-line-sanitizer.ts
|
|
23315
23377
|
var TERMINAL_ESCAPE = /\u001b(?:\][^\u0007]*?(?:\u0007|\u001b\\)|\[[0-?]*[ -/]*[@-~]|[@-Z\\-_])/g;
|
|
@@ -23431,6 +23493,260 @@ function clipToCharacterBudget(rows, budget) {
|
|
|
23431
23493
|
return { lines: rows, limited: false };
|
|
23432
23494
|
}
|
|
23433
23495
|
|
|
23496
|
+
// src/providers/chat/codex-goal.ts
|
|
23497
|
+
var GOAL_IDLE_END_MS = 18e4;
|
|
23498
|
+
var GOAL_STATUSES = /* @__PURE__ */ new Set(["active", "paused", "blocked", "usageLimited", "budgetLimited", "complete"]);
|
|
23499
|
+
function codexGoalProvider(request, goal) {
|
|
23500
|
+
let write;
|
|
23501
|
+
let threadId = request.sessionId;
|
|
23502
|
+
let nextId = 10;
|
|
23503
|
+
let turnRunning = false;
|
|
23504
|
+
let currentTurn = "";
|
|
23505
|
+
let turnMessage = "";
|
|
23506
|
+
let goalStatus = "active";
|
|
23507
|
+
let goalSet = false;
|
|
23508
|
+
let ended = false;
|
|
23509
|
+
let idleSince = 0;
|
|
23510
|
+
const send = (message) => write?.(`${JSON.stringify(message)}
|
|
23511
|
+
`);
|
|
23512
|
+
const sandboxPolicy = request.permissionMode === "full" ? { type: "dangerFullAccess" } : { type: "readOnly", access: { type: "restricted", includePlatformDefaults: true, readableRoots: [request.workdir] } };
|
|
23513
|
+
const empty = () => ({ display: [] });
|
|
23514
|
+
const end = (rows = []) => {
|
|
23515
|
+
if (ended) return { display: rows };
|
|
23516
|
+
ended = true;
|
|
23517
|
+
return { display: [...rows, runLog.event("\u76EE\u6807\u8FD0\u884C\u7ED3\u675F")], turnCompleted: true, endProcess: true };
|
|
23518
|
+
};
|
|
23519
|
+
const maybeEnd = (rows = []) => {
|
|
23520
|
+
if (!turnRunning && goalSet && goalStatus !== "active") return end(rows);
|
|
23521
|
+
return { display: rows };
|
|
23522
|
+
};
|
|
23523
|
+
const snapshot = (value) => {
|
|
23524
|
+
const status = str(value.status);
|
|
23525
|
+
if (!status || !GOAL_STATUSES.has(status)) return void 0;
|
|
23526
|
+
return {
|
|
23527
|
+
objective: String(value.objective ?? ""),
|
|
23528
|
+
status,
|
|
23529
|
+
...typeof value.tokenBudget === "number" ? { token_budget: value.tokenBudget } : {},
|
|
23530
|
+
tokens_used: typeof value.tokensUsed === "number" ? value.tokensUsed : 0,
|
|
23531
|
+
time_used_seconds: typeof value.timeUsedSeconds === "number" ? value.timeUsedSeconds : 0
|
|
23532
|
+
};
|
|
23533
|
+
};
|
|
23534
|
+
const startTurn = () => {
|
|
23535
|
+
send({ id: 3, method: "turn/start", params: {
|
|
23536
|
+
threadId,
|
|
23537
|
+
input: [{ type: "text", text: request.prompt }],
|
|
23538
|
+
cwd: request.workdir,
|
|
23539
|
+
approvalPolicy: "never",
|
|
23540
|
+
sandboxPolicy,
|
|
23541
|
+
...request.model ? { model: request.model } : {},
|
|
23542
|
+
...request.reasoningEffort ? { effort: request.reasoningEffort } : {}
|
|
23543
|
+
} });
|
|
23544
|
+
};
|
|
23545
|
+
const setGoal = () => {
|
|
23546
|
+
send({ id: 4, method: "thread/goal/set", params: {
|
|
23547
|
+
threadId,
|
|
23548
|
+
objective: goal.objective,
|
|
23549
|
+
status: "active",
|
|
23550
|
+
origin: "user",
|
|
23551
|
+
...goal.tokenBudget ? { tokenBudget: goal.tokenBudget } : {}
|
|
23552
|
+
} });
|
|
23553
|
+
};
|
|
23554
|
+
return {
|
|
23555
|
+
id: "codex",
|
|
23556
|
+
buildLaunch() {
|
|
23557
|
+
return launchCli({ spec: requireCliSpec("codex"), args: [
|
|
23558
|
+
"app-server",
|
|
23559
|
+
"--listen",
|
|
23560
|
+
"stdio://",
|
|
23561
|
+
...request.permissionMode === "full" ? [] : ["-c", "mcp_servers={}", "-c", 'web_search="disabled"']
|
|
23562
|
+
] });
|
|
23563
|
+
},
|
|
23564
|
+
startInput(writer) {
|
|
23565
|
+
write = writer;
|
|
23566
|
+
send({ id: 1, method: "initialize", params: { clientInfo: { name: "echo_goal", title: "Echo Goal", version: "1.0" }, capabilities: { experimentalApi: true } } });
|
|
23567
|
+
},
|
|
23568
|
+
tick() {
|
|
23569
|
+
if (!ended && !turnRunning && goalSet && idleSince && Date.now() - idleSince > GOAL_IDLE_END_MS) {
|
|
23570
|
+
return end([runLog.event("\u76EE\u6807\u957F\u65F6\u95F4\u6CA1\u6709\u7EE7\u7EED\uFF0C\u5DF2\u7ED3\u675F\u672C\u6B21\u8FD0\u884C")]);
|
|
23571
|
+
}
|
|
23572
|
+
return void 0;
|
|
23573
|
+
},
|
|
23574
|
+
controlGoal(action) {
|
|
23575
|
+
if (!write || !threadId || ended) return false;
|
|
23576
|
+
if (action === "pause") send({ id: nextId++, method: "thread/goal/set", params: { threadId, status: "paused", origin: "user" } });
|
|
23577
|
+
else send({ id: nextId++, method: "thread/goal/clear", params: { threadId, origin: "user" } });
|
|
23578
|
+
return true;
|
|
23579
|
+
},
|
|
23580
|
+
parseLine(line) {
|
|
23581
|
+
const message = tryJson(line);
|
|
23582
|
+
if (!message) return empty();
|
|
23583
|
+
if (message.id !== void 0 && !message.method) {
|
|
23584
|
+
const error62 = message.error;
|
|
23585
|
+
if (error62) {
|
|
23586
|
+
if (message.id === 4) return { display: [runLog.error(`\u8BBE\u7F6E\u76EE\u6807\u5931\u8D25\uFF1A${str(error62.message) ?? ""}`)], turnError: str(error62.message) ?? "\u8BBE\u7F6E\u76EE\u6807\u5931\u8D25", endProcess: true };
|
|
23587
|
+
if (typeof message.id === "number" && message.id < 10) return { display: [], turnError: str(error62.message) ?? "Codex \u8BF7\u6C42\u5931\u8D25", endProcess: true };
|
|
23588
|
+
return { display: [runLog.error(str(error62.message) ?? "\u76EE\u6807\u64CD\u4F5C\u5931\u8D25")] };
|
|
23589
|
+
}
|
|
23590
|
+
const result = message.result ?? {};
|
|
23591
|
+
if (message.id === 1) {
|
|
23592
|
+
send({ method: "initialized" });
|
|
23593
|
+
send({ id: 2, method: threadId ? "thread/resume" : "thread/start", params: {
|
|
23594
|
+
cwd: request.workdir,
|
|
23595
|
+
approvalPolicy: "never",
|
|
23596
|
+
sandbox: request.permissionMode === "full" ? "danger-full-access" : "read-only",
|
|
23597
|
+
...request.model ? { model: request.model } : {},
|
|
23598
|
+
...threadId ? { threadId } : { ephemeral: false }
|
|
23599
|
+
} });
|
|
23600
|
+
return empty();
|
|
23601
|
+
}
|
|
23602
|
+
if (message.id === 2) {
|
|
23603
|
+
const id = str((result.thread ?? {}).id);
|
|
23604
|
+
if (!id) return { display: [], turnError: "Codex \u672A\u8FD4\u56DE\u539F\u751F\u4F1A\u8BDD ID", endProcess: true };
|
|
23605
|
+
threadId = id;
|
|
23606
|
+
startTurn();
|
|
23607
|
+
return { display: [runLog.event(`\u4F1A\u8BDD ${id}`)], sessionId: id };
|
|
23608
|
+
}
|
|
23609
|
+
if (message.id === 3) {
|
|
23610
|
+
setGoal();
|
|
23611
|
+
return empty();
|
|
23612
|
+
}
|
|
23613
|
+
if (message.id === 4) {
|
|
23614
|
+
goalSet = true;
|
|
23615
|
+
const goalSnapshot = snapshot(result.goal ?? {});
|
|
23616
|
+
if (goalSnapshot) goalStatus = goalSnapshot.status;
|
|
23617
|
+
return { display: [runLog.event(`\u76EE\u6807\uFF1A${goal.objective}`)], ...goalSnapshot ? { goal: goalSnapshot } : {} };
|
|
23618
|
+
}
|
|
23619
|
+
return empty();
|
|
23620
|
+
}
|
|
23621
|
+
const params = message.params ?? {};
|
|
23622
|
+
if (params.threadId && params.threadId !== threadId) return empty();
|
|
23623
|
+
if (message.id !== void 0) {
|
|
23624
|
+
send({ id: message.id, error: { code: -32601, message: "\u76EE\u6807\u8FD0\u884C\u4E0D\u652F\u6301\u4EA4\u4E92\u5F0F\u786E\u8BA4" } });
|
|
23625
|
+
return { display: [runLog.error("CLI \u8BF7\u6C42\u4EA4\u4E92\u786E\u8BA4\uFF0C\u76EE\u6807\u8FD0\u884C\u65E0\u6CD5\u56DE\u7B54\uFF0C\u5DF2\u62D2\u7EDD")] };
|
|
23626
|
+
}
|
|
23627
|
+
switch (message.method) {
|
|
23628
|
+
case "turn/started": {
|
|
23629
|
+
turnRunning = true;
|
|
23630
|
+
idleSince = 0;
|
|
23631
|
+
currentTurn = str((params.turn ?? {}).id) ?? currentTurn;
|
|
23632
|
+
turnMessage = "";
|
|
23633
|
+
return { display: [runLog.event("\u5F00\u59CB\u5904\u7406")] };
|
|
23634
|
+
}
|
|
23635
|
+
case "item/completed": {
|
|
23636
|
+
const item = params.item ?? {};
|
|
23637
|
+
if (item.type === "agentMessage") {
|
|
23638
|
+
turnMessage = String(item.text ?? "");
|
|
23639
|
+
return { display: textRows("\u203A ", turnMessage), message: turnMessage };
|
|
23640
|
+
}
|
|
23641
|
+
if (item.type === "commandExecution") return { display: [runLog.command(String(item.command ?? "")), runLog.commandExit(typeof item.exitCode === "number" ? item.exitCode : void 0)] };
|
|
23642
|
+
if (item.type === "fileChange") return { display: [runLog.fileChange()] };
|
|
23643
|
+
return empty();
|
|
23644
|
+
}
|
|
23645
|
+
case "turn/completed": {
|
|
23646
|
+
turnRunning = false;
|
|
23647
|
+
idleSince = Date.now();
|
|
23648
|
+
const turn = params.turn ?? {};
|
|
23649
|
+
const id = str(turn.id) ?? currentTurn;
|
|
23650
|
+
const rows = [runLog.event(turn.status === "completed" ? "\u672C\u8F6E\u5B8C\u6210" : `\u672C\u8F6E\u7ED3\u675F\uFF08${String(turn.status ?? "")}\uFF09`)];
|
|
23651
|
+
const parsed = maybeEnd(rows);
|
|
23652
|
+
return { ...parsed, ...id && turnMessage ? { goalTurn: { turnId: id, message: turnMessage } } : {} };
|
|
23653
|
+
}
|
|
23654
|
+
case "thread/goal/updated": {
|
|
23655
|
+
const goalSnapshot = snapshot(params.goal ?? {});
|
|
23656
|
+
if (!goalSnapshot) return empty();
|
|
23657
|
+
goalStatus = goalSnapshot.status;
|
|
23658
|
+
return { ...maybeEnd(goalSnapshot.status === "active" ? [] : [runLog.event(`\u76EE\u6807\u72B6\u6001\uFF1A${goalSnapshot.status}`)]), goal: goalSnapshot };
|
|
23659
|
+
}
|
|
23660
|
+
case "thread/goal/cleared": {
|
|
23661
|
+
goalStatus = "cleared";
|
|
23662
|
+
return { ...maybeEnd([runLog.event("\u76EE\u6807\u5DF2\u6E05\u9664")]), goal: { objective: "", status: "paused", tokens_used: 0, time_used_seconds: 0, cleared: true } };
|
|
23663
|
+
}
|
|
23664
|
+
default:
|
|
23665
|
+
return empty();
|
|
23666
|
+
}
|
|
23667
|
+
}
|
|
23668
|
+
};
|
|
23669
|
+
}
|
|
23670
|
+
|
|
23671
|
+
// src/providers/cli/codex-fork.ts
|
|
23672
|
+
import { spawn as spawn8 } from "node:child_process";
|
|
23673
|
+
import { createInterface as createInterface3 } from "node:readline";
|
|
23674
|
+
var FORK_TIMEOUT_MS = 9e4;
|
|
23675
|
+
async function forkCodexThread(options) {
|
|
23676
|
+
const launch = launchCli({ spec: requireCliSpec("codex"), args: ["app-server", "--listen", "stdio://"] });
|
|
23677
|
+
const child = spawn8(launch.executable, launch.args, {
|
|
23678
|
+
cwd: options.workdir,
|
|
23679
|
+
env: launch.env,
|
|
23680
|
+
shell: false,
|
|
23681
|
+
windowsHide: true,
|
|
23682
|
+
detached: currentPlatform.runsInOwnProcessGroup,
|
|
23683
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
23684
|
+
});
|
|
23685
|
+
const stderr = [];
|
|
23686
|
+
createInterface3({ input: child.stderr }).on("line", (line) => {
|
|
23687
|
+
stderr.push(line);
|
|
23688
|
+
if (stderr.length > 20) stderr.shift();
|
|
23689
|
+
});
|
|
23690
|
+
let nextId = 1;
|
|
23691
|
+
const pending = /* @__PURE__ */ new Map();
|
|
23692
|
+
const call = (method, params) => new Promise((resolve7, reject) => {
|
|
23693
|
+
const id = nextId++;
|
|
23694
|
+
pending.set(id, { resolve: resolve7, reject });
|
|
23695
|
+
child.stdin.write(`${JSON.stringify({ id, method, params })}
|
|
23696
|
+
`);
|
|
23697
|
+
});
|
|
23698
|
+
createInterface3({ input: child.stdout }).on("line", (line) => {
|
|
23699
|
+
const message = tryJson(line);
|
|
23700
|
+
if (!message || typeof message.id !== "number" || message.method) return;
|
|
23701
|
+
const waiter = pending.get(message.id);
|
|
23702
|
+
if (!waiter) return;
|
|
23703
|
+
pending.delete(message.id);
|
|
23704
|
+
const error62 = message.error;
|
|
23705
|
+
if (error62) waiter.reject(new Error(String(error62.message ?? "Codex \u8BF7\u6C42\u5931\u8D25")));
|
|
23706
|
+
else waiter.resolve(message.result ?? {});
|
|
23707
|
+
});
|
|
23708
|
+
const failed = new Promise((_, reject) => {
|
|
23709
|
+
child.once("error", (error62) => reject(new Error(`\u65E0\u6CD5\u542F\u52A8 Codex\uFF1A${error62.message}`)));
|
|
23710
|
+
child.once("exit", (code) => reject(new Error(`Codex \u5DF2\u9000\u51FA\uFF08exit ${code ?? "?"}\uFF09${stderr.length ? `\uFF1A${stderr.slice(-3).join(" ")}` : ""}`)));
|
|
23711
|
+
});
|
|
23712
|
+
const timer = setTimeout(() => {
|
|
23713
|
+
void killProcessTree(child.pid ?? 0);
|
|
23714
|
+
}, FORK_TIMEOUT_MS);
|
|
23715
|
+
try {
|
|
23716
|
+
const run = async () => {
|
|
23717
|
+
await call("initialize", { clientInfo: { name: "echo_session_fork", title: "Echo Session Fork", version: "1.0" }, capabilities: { experimentalApi: true } });
|
|
23718
|
+
child.stdin.write(`${JSON.stringify({ method: "initialized" })}
|
|
23719
|
+
`);
|
|
23720
|
+
let lastTurnId;
|
|
23721
|
+
if (options.keepTurns > 0) {
|
|
23722
|
+
const ids = [];
|
|
23723
|
+
let cursor;
|
|
23724
|
+
do {
|
|
23725
|
+
const page = await call("thread/turns/list", { threadId: options.sourceThreadId, sortDirection: "asc", limit: 100, ...cursor ? { cursor } : {} });
|
|
23726
|
+
for (const turn of page.data ?? []) if (typeof turn.id === "string") ids.push(turn.id);
|
|
23727
|
+
cursor = typeof page.nextCursor === "string" ? page.nextCursor : void 0;
|
|
23728
|
+
} while (cursor && ids.length < options.keepTurns);
|
|
23729
|
+
if (ids.length > options.keepTurns) lastTurnId = ids[options.keepTurns - 1];
|
|
23730
|
+
}
|
|
23731
|
+
const result = await call("thread/fork", {
|
|
23732
|
+
threadId: options.sourceThreadId,
|
|
23733
|
+
ephemeral: false,
|
|
23734
|
+
excludeTurns: true,
|
|
23735
|
+
cwd: options.workdir,
|
|
23736
|
+
...lastTurnId ? { lastTurnId } : {}
|
|
23737
|
+
});
|
|
23738
|
+
const thread = result.thread ?? {};
|
|
23739
|
+
if (typeof thread.id !== "string" || !thread.id) throw new Error("Codex \u672A\u8FD4\u56DE\u5206\u53C9\u540E\u7684\u4F1A\u8BDD ID");
|
|
23740
|
+
return thread.id;
|
|
23741
|
+
};
|
|
23742
|
+
return await Promise.race([run(), failed]);
|
|
23743
|
+
} finally {
|
|
23744
|
+
clearTimeout(timer);
|
|
23745
|
+
child.stdin?.end();
|
|
23746
|
+
void killProcessTree(child.pid ?? 0, 1e3);
|
|
23747
|
+
}
|
|
23748
|
+
}
|
|
23749
|
+
|
|
23434
23750
|
// src/runs/run-recorder.ts
|
|
23435
23751
|
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3 } from "node:fs";
|
|
23436
23752
|
import { homedir as homedir8 } from "node:os";
|
|
@@ -23617,17 +23933,17 @@ var RunSupervisor = class {
|
|
|
23617
23933
|
this.chatRunIds.delete(runId);
|
|
23618
23934
|
}
|
|
23619
23935
|
recentRuns() {
|
|
23620
|
-
const running = [...this.active.values()].map((run) => ({ runId: run.runId,
|
|
23621
|
-
const done = [...this.recent.values()].map((run) => ({ runId: run.runId,
|
|
23936
|
+
const running = [...this.active.values()].map((run) => ({ runId: run.runId, sessionKey: run.sessionKey, status: "running", at: run.startedAt }));
|
|
23937
|
+
const done = [...this.recent.values()].map((run) => ({ runId: run.runId, sessionKey: run.sessionKey, status: run.status, at: run.finishedAt }));
|
|
23622
23938
|
return [...running, ...done].sort((a, b) => b.at - a.at).slice(0, 30);
|
|
23623
23939
|
}
|
|
23624
23940
|
/**
|
|
23625
|
-
* Starts a turn. Refusals (busy
|
|
23941
|
+
* Starts a turn. Refusals (busy session, concurrency limit, bad work
|
|
23626
23942
|
* directory, unknown CLI) are reported as a failed run, never thrown.
|
|
23627
23943
|
*/
|
|
23628
23944
|
/**
|
|
23629
|
-
* Different
|
|
23630
|
-
* default; each
|
|
23945
|
+
* Different sessions run in parallel without a machine-wide cap by
|
|
23946
|
+
* default; each session still runs one turn at a time. A cap applies
|
|
23631
23947
|
* only when the operator sets TOC_OCRA_MAX_RUNS / maxConcurrentRuns.
|
|
23632
23948
|
* The run being started is already counted in `preparing`.
|
|
23633
23949
|
*/
|
|
@@ -23638,7 +23954,7 @@ var RunSupervisor = class {
|
|
|
23638
23954
|
async start(payload) {
|
|
23639
23955
|
if (this.preparing.has(payload.run_id)) return;
|
|
23640
23956
|
const controller = new AbortController();
|
|
23641
|
-
this.preparing.set(payload.run_id, {
|
|
23957
|
+
this.preparing.set(payload.run_id, { sessionKey: sessionKeyOf(payload), controller });
|
|
23642
23958
|
try {
|
|
23643
23959
|
await this.startPrepared(payload, controller.signal);
|
|
23644
23960
|
} finally {
|
|
@@ -23651,14 +23967,15 @@ var RunSupervisor = class {
|
|
|
23651
23967
|
return;
|
|
23652
23968
|
}
|
|
23653
23969
|
if (payload.chat_session_id) this.chatRunIds.add(payload.run_id);
|
|
23970
|
+
const sessionKey = sessionKeyOf(payload);
|
|
23654
23971
|
const refuse = async (reason) => {
|
|
23655
23972
|
const failure2 = typeof reason === "string" ? { kind: "hostFault", message: reason } : reason;
|
|
23656
23973
|
this.logger.warn("run-refused", { runId: payload.run_id, error: failure2.message, kind: failure2.kind });
|
|
23657
|
-
this.remember({ runId: payload.run_id,
|
|
23974
|
+
this.remember({ runId: payload.run_id, sessionKey, tail: new TerminalTailBuffer(), finishedAt: Date.now(), status: "failed", chat: !!payload.chat_session_id });
|
|
23658
23975
|
await this.report(payload.run_id, { status: "failed", error: failure2.message, failure_kind: failure2.kind, duration_ms: 0 });
|
|
23659
23976
|
};
|
|
23660
|
-
if ([...this.active.values()].some((run2) => run2.
|
|
23661
|
-
return refuse("\u672C\u673A\u8BE5\
|
|
23977
|
+
if ([...this.active.values()].some((run2) => run2.sessionKey === sessionKey) || [...this.preparing].some(([id, run2]) => id !== payload.run_id && run2.sessionKey === sessionKey)) {
|
|
23978
|
+
return refuse("\u672C\u673A\u8BE5\u4F1A\u8BDD\u5DF2\u6709\u4EFB\u52A1\u5728\u8FD0\u884C");
|
|
23662
23979
|
}
|
|
23663
23980
|
if (this.overConcurrencyCap()) {
|
|
23664
23981
|
return refuse(`\u672C\u673A\u540C\u65F6\u8FD0\u884C\u7684\u4EFB\u52A1\u5DF2\u8FBE\u4E0A\u9650\uFF08${this.config.maxConcurrentRuns}\uFF09`);
|
|
@@ -23671,7 +23988,7 @@ var RunSupervisor = class {
|
|
|
23671
23988
|
let provider = cli.headless;
|
|
23672
23989
|
let workdir;
|
|
23673
23990
|
try {
|
|
23674
|
-
if (payload.task_attachments?.length && !payload.workdir) throw new Error("\u9644\u4EF6\u9700\u8981\u914D\u7F6E\u8BBE\u5907\u9ED8\u8BA4\u76EE\u5F55\u6216\
|
|
23991
|
+
if (payload.task_attachments?.length && !payload.workdir) throw new Error("\u9644\u4EF6\u9700\u8981\u914D\u7F6E\u8BBE\u5907\u9ED8\u8BA4\u76EE\u5F55\u6216\u4F1A\u8BDD\u5DE5\u4F5C\u76EE\u5F55");
|
|
23675
23992
|
workdir = payload.chat_session_id && !payload.workdir ? await this.defaultChatWorkdir() : await this.validateWorkdir(payload.workdir || this.config.allowedRoots[0]);
|
|
23676
23993
|
} catch (error62) {
|
|
23677
23994
|
return refuse(errorMessage(error62));
|
|
@@ -23681,7 +23998,7 @@ var RunSupervisor = class {
|
|
|
23681
23998
|
signal2.throwIfAborted();
|
|
23682
23999
|
} catch (error62) {
|
|
23683
24000
|
if (signal2.aborted) {
|
|
23684
|
-
this.remember({ runId: payload.run_id,
|
|
24001
|
+
this.remember({ runId: payload.run_id, sessionKey, tail: new TerminalTailBuffer(), finishedAt: Date.now(), status: "cancelled", chat: !!payload.chat_session_id });
|
|
23685
24002
|
await this.report(payload.run_id, { status: "cancelled", error: "\u9644\u4EF6\u51C6\u5907\u5DF2\u53D6\u6D88", duration_ms: 0 });
|
|
23686
24003
|
return;
|
|
23687
24004
|
}
|
|
@@ -23735,7 +24052,24 @@ var RunSupervisor = class {
|
|
|
23735
24052
|
sessionsBefore = new Set(saved.map((session) => session.id));
|
|
23736
24053
|
}
|
|
23737
24054
|
}
|
|
23738
|
-
|
|
24055
|
+
const fork = payload.fork && !payload.chat_session_id ? { sourceSessionId: payload.fork.source_session_id, keepTurns: payload.fork.keep_turns } : void 0;
|
|
24056
|
+
if (fork && provider.id === "codex" && !sessionId) {
|
|
24057
|
+
try {
|
|
24058
|
+
sessionId = await forkCodexThread({ sourceThreadId: fork.sourceSessionId, keepTurns: fork.keepTurns, workdir, permissionMode });
|
|
24059
|
+
sessionNote += `\u25CF \u5DF2\u4ECE\u4F1A\u8BDD ${fork.sourceSessionId} \u5206\u53C9${fork.keepTurns > 0 ? `\uFF08\u4FDD\u7559\u524D ${fork.keepTurns} \u8F6E\uFF09` : ""}\uFF0C\u65B0\u4F1A\u8BDD ${sessionId}
|
|
24060
|
+
`;
|
|
24061
|
+
} catch (error62) {
|
|
24062
|
+
return refuse({ kind: "startFailed", message: `\u5206\u53C9 Codex \u4F1A\u8BDD\u5931\u8D25\uFF1A${errorMessage(error62)}` });
|
|
24063
|
+
}
|
|
24064
|
+
}
|
|
24065
|
+
if (payload.goal && !payload.chat_session_id) {
|
|
24066
|
+
if (provider.id !== "codex") return refuse("\u76EE\u6807\u6A21\u5F0F\u53EA\u652F\u6301 Codex");
|
|
24067
|
+
provider = codexGoalProvider(
|
|
24068
|
+
{ permissionMode, prompt: payload.prompt, sessionId, model: payload.model, reasoningEffort: payload.reasoning_effort, workdir },
|
|
24069
|
+
{ objective: payload.goal.objective, ...payload.goal.token_budget ? { tokenBudget: payload.goal.token_budget } : {} }
|
|
24070
|
+
);
|
|
24071
|
+
}
|
|
24072
|
+
if ([...this.active.values()].some((run2) => run2.sessionKey === sessionKey)) return refuse("\u672C\u673A\u8BE5\u4F1A\u8BDD\u5DF2\u6709\u4EFB\u52A1\u5728\u8FD0\u884C");
|
|
23739
24073
|
if (this.overConcurrencyCap()) return refuse(`\u672C\u673A\u540C\u65F6\u8FD0\u884C\u7684\u4EFB\u52A1\u5DF2\u8FBE\u4E0A\u9650\uFF08${this.config.maxConcurrentRuns}\uFF09`);
|
|
23740
24074
|
if (provider.forTurn) provider = provider.forTurn();
|
|
23741
24075
|
const launch = provider.buildLaunch({
|
|
@@ -23744,12 +24078,13 @@ var RunSupervisor = class {
|
|
|
23744
24078
|
sessionId,
|
|
23745
24079
|
model: payload.model,
|
|
23746
24080
|
reasoningEffort: payload.reasoning_effort,
|
|
23747
|
-
workdir
|
|
24081
|
+
workdir,
|
|
24082
|
+
...fork ? { fork } : {}
|
|
23748
24083
|
});
|
|
23749
24084
|
if (!fitsCommandLine(launch)) return refuse(cliFailure("promptTooLong", { label: cli.label }));
|
|
23750
24085
|
let child;
|
|
23751
24086
|
try {
|
|
23752
|
-
child =
|
|
24087
|
+
child = spawn9(launch.executable, launch.args, {
|
|
23753
24088
|
cwd: workdir,
|
|
23754
24089
|
env: launch.env,
|
|
23755
24090
|
detached: currentPlatform.runsInOwnProcessGroup,
|
|
@@ -23770,7 +24105,7 @@ var RunSupervisor = class {
|
|
|
23770
24105
|
queuedBytes: 0,
|
|
23771
24106
|
forwardingFailed: false,
|
|
23772
24107
|
runId: payload.run_id,
|
|
23773
|
-
|
|
24108
|
+
sessionKey,
|
|
23774
24109
|
agentType: provider.id,
|
|
23775
24110
|
cli: { label: cli.label, ...cli.installHint ? { installHint: cli.installHint } : {} },
|
|
23776
24111
|
provider,
|
|
@@ -23792,7 +24127,8 @@ var RunSupervisor = class {
|
|
|
23792
24127
|
timedOut: false,
|
|
23793
24128
|
tail: new TerminalTailBuffer(),
|
|
23794
24129
|
timers: [],
|
|
23795
|
-
|
|
24130
|
+
// A goal run waits between turns while the CLI decides; no stall check.
|
|
24131
|
+
...payload.stall_policy && !payload.chat_session_id && !payload.goal ? { stallPolicy: { idleSeconds: payload.stall_policy.idle_seconds, categorySeconds: payload.stall_policy.category_seconds ?? {} } } : {},
|
|
23796
24132
|
lastCategory: "other",
|
|
23797
24133
|
lastLine: "",
|
|
23798
24134
|
lastOutputAt: Date.now()
|
|
@@ -23839,9 +24175,9 @@ var RunSupervisor = class {
|
|
|
23839
24175
|
this.applyParsed(run, run.stream.stdout(chunk), chunk);
|
|
23840
24176
|
});
|
|
23841
24177
|
} else {
|
|
23842
|
-
|
|
24178
|
+
createInterface4({ input: child.stdout }).on("line", (line) => this.onStdout(run, line));
|
|
23843
24179
|
}
|
|
23844
|
-
|
|
24180
|
+
createInterface4({ input: child.stderr }).on("line", (line) => {
|
|
23845
24181
|
run.recorder?.write({ stream: "stderr", data: line });
|
|
23846
24182
|
const clean = sanitizeTerminalLine(line);
|
|
23847
24183
|
if (!clean.trim()) return;
|
|
@@ -23905,6 +24241,14 @@ var RunSupervisor = class {
|
|
|
23905
24241
|
void killProcessTree(run.pid);
|
|
23906
24242
|
}, this.config.maxRunSeconds * 1e3));
|
|
23907
24243
|
}
|
|
24244
|
+
if (provider.tick) {
|
|
24245
|
+
const ticker = setInterval(() => {
|
|
24246
|
+
const parsed = this.active.has(run.runId) ? run.provider.tick?.() : void 0;
|
|
24247
|
+
if (parsed) this.applyParsed(run, parsed, "");
|
|
24248
|
+
}, STALL_CHECK_INTERVAL_MS);
|
|
24249
|
+
ticker.unref?.();
|
|
24250
|
+
run.timers.push(ticker);
|
|
24251
|
+
}
|
|
23908
24252
|
if (run.stallPolicy) {
|
|
23909
24253
|
const watchdog = setInterval(() => this.checkStall(run), STALL_CHECK_INTERVAL_MS);
|
|
23910
24254
|
watchdog.unref?.();
|
|
@@ -23932,6 +24276,14 @@ var RunSupervisor = class {
|
|
|
23932
24276
|
}
|
|
23933
24277
|
if (!parsed.display.length && rawLine.trim()) run.lastOutputAt = Date.now();
|
|
23934
24278
|
if (parsed.message !== void 0) run.finalMessage = sanitizeTerminalLine(parsed.message);
|
|
24279
|
+
if (parsed.goal) {
|
|
24280
|
+
const goal = { ...parsed.goal, objective: sanitizeChatText(parsed.goal.objective) };
|
|
24281
|
+
void this.reporter.goal?.(run.runId, goal).catch((error62) => this.logger.warn("goal-report-failed", { runId: run.runId, error: errorMessage(error62) }));
|
|
24282
|
+
}
|
|
24283
|
+
if (parsed.goalTurn) {
|
|
24284
|
+
const turn = { turn_id: parsed.goalTurn.turnId, message: sanitizeChatText(parsed.goalTurn.message) };
|
|
24285
|
+
void this.reporter.goalTurn?.(run.runId, turn).catch((error62) => this.logger.warn("goal-turn-report-failed", { runId: run.runId, error: errorMessage(error62) }));
|
|
24286
|
+
}
|
|
23935
24287
|
if (parsed.turnError) {
|
|
23936
24288
|
run.turnError = sanitizeTerminalLine(parsed.turnError);
|
|
23937
24289
|
if (parsed.failureKind) run.turnFailure = parsed.failureKind;
|
|
@@ -24034,7 +24386,7 @@ var RunSupervisor = class {
|
|
|
24034
24386
|
run.tail.append(`\u25CF \u8FDB\u7A0B\u5DF2\u9000\u51FA\uFF1A${report.status}${code !== null ? `\uFF08exit ${code}\uFF09` : ""}
|
|
24035
24387
|
`);
|
|
24036
24388
|
run.recorder?.write({ result: { ...report, duration_ms: 0 }, log: run.tail.read({ limit: 2e3 }).lines });
|
|
24037
|
-
this.remember({ runId: run.runId,
|
|
24389
|
+
this.remember({ runId: run.runId, sessionKey: run.sessionKey, tail: run.tail, finishedAt: Date.now(), status: report.status, chat: !!run.chat });
|
|
24038
24390
|
this.logger.info("run-finished", { runId: run.runId, status: report.status, code, durationMs });
|
|
24039
24391
|
await this.report(run.runId, report);
|
|
24040
24392
|
}
|
|
@@ -24150,13 +24502,22 @@ var RunSupervisor = class {
|
|
|
24150
24502
|
await killProcessTree(run.pid);
|
|
24151
24503
|
return true;
|
|
24152
24504
|
}
|
|
24505
|
+
/** Pauses or clears the goal of a running goal run; false when there is none. */
|
|
24506
|
+
controlGoal(runId, action) {
|
|
24507
|
+
const run = this.active.get(runId);
|
|
24508
|
+
if (!run?.provider.controlGoal) return false;
|
|
24509
|
+
const applied = run.provider.controlGoal(action);
|
|
24510
|
+
if (applied) run.tail.append(`\u25CF \u6536\u5230${action === "pause" ? "\u6682\u505C" : "\u6E05\u9664"}\u76EE\u6807\u6307\u4EE4
|
|
24511
|
+
`);
|
|
24512
|
+
return applied;
|
|
24513
|
+
}
|
|
24153
24514
|
tail(query, limit, beforeCursor) {
|
|
24154
24515
|
const byId = (id) => id ? this.active.get(id) ?? this.recent.get(id) : void 0;
|
|
24155
|
-
const
|
|
24516
|
+
const bySession = (id) => {
|
|
24156
24517
|
if (!id) return void 0;
|
|
24157
|
-
const live = [...this.active.values()].find((run) => run.
|
|
24518
|
+
const live = [...this.active.values()].find((run) => run.sessionKey === id);
|
|
24158
24519
|
if (live) return live;
|
|
24159
|
-
return [...this.recent.values()].filter((run) => run.
|
|
24520
|
+
return [...this.recent.values()].filter((run) => run.sessionKey === id).sort((a, b) => b.finishedAt - a.finishedAt)[0];
|
|
24160
24521
|
};
|
|
24161
24522
|
const empty = { lines: [], startCursor: 0, nextCursor: 0, oldestCursor: 0, latestCursor: 0, hasMore: false, truncated: false, limited: false, idleMs: void 0 };
|
|
24162
24523
|
if (query.runId) {
|
|
@@ -24165,7 +24526,7 @@ var RunSupervisor = class {
|
|
|
24165
24526
|
const read2 = run.tail.read(beforeCursor === void 0 ? { limit } : { limit, beforeCursor });
|
|
24166
24527
|
return { ...read2, status: this.active.has(run.runId) ? "running" : "finished", run_id: run.runId };
|
|
24167
24528
|
}
|
|
24168
|
-
const target =
|
|
24529
|
+
const target = bySession(query.taskChainId);
|
|
24169
24530
|
if (!target) return { ...empty, status: "idle" };
|
|
24170
24531
|
const read = target.tail.read(beforeCursor === void 0 ? { limit } : { limit, beforeCursor });
|
|
24171
24532
|
return { ...read, status: this.active.has(target.runId) ? "running" : "finished", run_id: target.runId };
|
|
@@ -24209,7 +24570,7 @@ var RunSupervisor = class {
|
|
|
24209
24570
|
throw new Error(`\u5DE5\u4F5C\u76EE\u5F55\u4E0D\u5728\u5141\u8BB8\u8303\u56F4\u5185\uFF1A${input2}`);
|
|
24210
24571
|
}
|
|
24211
24572
|
async prepareTaskFiles(payload, signal2 = AbortSignal.timeout(15 * 6e4), workdir) {
|
|
24212
|
-
if (!payload.workdir) throw new Error("\u8BF7\u5148\u914D\u7F6E\u8BBE\u5907\u9ED8\u8BA4\u76EE\u5F55\u6216\
|
|
24573
|
+
if (!payload.workdir) throw new Error("\u8BF7\u5148\u914D\u7F6E\u8BBE\u5907\u9ED8\u8BA4\u76EE\u5F55\u6216\u4F1A\u8BDD\u5DE5\u4F5C\u76EE\u5F55");
|
|
24213
24574
|
if (!this.reporter.taskFile) throw new Error("\u4EFB\u52A1\u9644\u4EF6\u4E0B\u8F7D\u672A\u914D\u7F6E");
|
|
24214
24575
|
return prepareTaskAttachments(payload, workdir ?? await this.validateWorkdir(payload.workdir), this.reporter.taskFile, AbortSignal.any([signal2, AbortSignal.timeout(15 * 6e4)]));
|
|
24215
24576
|
}
|
|
@@ -24217,6 +24578,9 @@ var RunSupervisor = class {
|
|
|
24217
24578
|
function failedReport(failure2, durationMs) {
|
|
24218
24579
|
return { status: "failed", error: failure2.message, failure_kind: failure2.kind, duration_ms: durationMs };
|
|
24219
24580
|
}
|
|
24581
|
+
function sessionKeyOf(payload) {
|
|
24582
|
+
return payload.task_chain_id || payload.chat_session_id || payload.run_id;
|
|
24583
|
+
}
|
|
24220
24584
|
function errorMessage(error62) {
|
|
24221
24585
|
return error62 instanceof Error ? error62.message : String(error62);
|
|
24222
24586
|
}
|
|
@@ -24353,6 +24717,12 @@ var GatewayClient = class {
|
|
|
24353
24717
|
await pipeline(Readable.fromWeb(response.body), verifier, target, { signal: signal2 });
|
|
24354
24718
|
if (received !== size || hash2.digest("hex") !== sha256) throw new Error("\u9644\u4EF6\u4E0B\u8F7D\u4E0D\u5B8C\u6574\u6216\u6821\u9A8C\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5");
|
|
24355
24719
|
}
|
|
24720
|
+
runGoal(runId, body) {
|
|
24721
|
+
return this.request("POST", `/runs/${encodeURIComponent(runId)}/goal`, body, 15e3);
|
|
24722
|
+
}
|
|
24723
|
+
runGoalTurn(runId, body) {
|
|
24724
|
+
return this.request("POST", `/runs/${encodeURIComponent(runId)}/goal-turn`, body, 15e3);
|
|
24725
|
+
}
|
|
24356
24726
|
runFinished(runId, body) {
|
|
24357
24727
|
return this.request("POST", `/runs/${encodeURIComponent(runId)}/finished`, body, 15e3);
|
|
24358
24728
|
}
|
|
@@ -24396,7 +24766,7 @@ async function listDirectory(requested, allowedRoots) {
|
|
|
24396
24766
|
}
|
|
24397
24767
|
|
|
24398
24768
|
// src/workspace/workspace-manager.ts
|
|
24399
|
-
import { spawn as
|
|
24769
|
+
import { spawn as spawn10 } from "node:child_process";
|
|
24400
24770
|
import { chmod as chmod3, mkdir as mkdir6, mkdtemp, opendir, realpath as realpath4, rm as rm3, stat as stat5, writeFile as writeFile6 } from "node:fs/promises";
|
|
24401
24771
|
import { homedir as homedir10, tmpdir as tmpdir2 } from "node:os";
|
|
24402
24772
|
import { isAbsolute as isAbsolute4, join as join14, relative as relative3, resolve as resolve5 } from "node:path";
|
|
@@ -24740,7 +25110,7 @@ var WorkspaceManager = class {
|
|
|
24740
25110
|
}
|
|
24741
25111
|
runGit(args, cwd, timeoutSeconds, allowFailure = false, environment) {
|
|
24742
25112
|
return new Promise((resolveCommand, rejectCommand) => {
|
|
24743
|
-
const child =
|
|
25113
|
+
const child = spawn10("git", args, {
|
|
24744
25114
|
cwd,
|
|
24745
25115
|
env: environment ?? process.env,
|
|
24746
25116
|
shell: false,
|
|
@@ -24818,8 +25188,6 @@ var DEFAULT_POLICY = { script: { enabled: false }, sql: { enabled: false } };
|
|
|
24818
25188
|
var RunStartPayloadSchema = external_exports.object({
|
|
24819
25189
|
cli_policy: external_exports.object({ enabled: external_exports.boolean(), mode: external_exports.enum(["restricted", "full"]), version: external_exports.literal(1) }).optional(),
|
|
24820
25190
|
run_id: external_exports.string().min(1).max(64),
|
|
24821
|
-
workstation_id: external_exports.string().min(1).max(64),
|
|
24822
|
-
workstation_name: external_exports.string().optional().default(""),
|
|
24823
25191
|
agent_type: external_exports.string().min(1).max(40),
|
|
24824
25192
|
task_chain_id: external_exports.string().optional().default(""),
|
|
24825
25193
|
message_id: external_exports.string().optional().default(""),
|
|
@@ -24831,6 +25199,17 @@ var RunStartPayloadSchema = external_exports.object({
|
|
|
24831
25199
|
model: external_exports.string().max(100).optional().default(""),
|
|
24832
25200
|
reasoning_effort: external_exports.string().max(40).optional().default(""),
|
|
24833
25201
|
workdir: external_exports.string().max(4096).optional().default(""),
|
|
25202
|
+
/**
|
|
25203
|
+
* CLI fork (分叉): before this turn, copy `source_session_id` (its first
|
|
25204
|
+
* `keep_turns` CLI turns; 0 = all) into this session's own CLI session.
|
|
25205
|
+
* Ignored once the session exists on this computer.
|
|
25206
|
+
*/
|
|
25207
|
+
fork: external_exports.object({ source_session_id: external_exports.string().min(1).max(200), keep_turns: external_exports.number().int().min(0).max(1e5) }).nullish(),
|
|
25208
|
+
/**
|
|
25209
|
+
* Goal run (目标模式, Codex): after the turn starts, hand the CLI this
|
|
25210
|
+
* objective; the run stays open while the CLI continues by itself.
|
|
25211
|
+
*/
|
|
25212
|
+
goal: external_exports.object({ objective: external_exports.string().max(8e3), token_budget: external_exports.number().int().positive().nullish() }).nullish(),
|
|
24834
25213
|
/** Shown as the first line of this run's log (e.g. why it is an automatic resume). */
|
|
24835
25214
|
notice: external_exports.string().max(1e3).nullish(),
|
|
24836
25215
|
/**
|
|
@@ -24844,9 +25223,10 @@ var RunStartPayloadSchema = external_exports.object({
|
|
|
24844
25223
|
}).nullish()
|
|
24845
25224
|
});
|
|
24846
25225
|
var RunCancelPayloadSchema = external_exports.object({ run_id: external_exports.string().min(1).max(64) });
|
|
25226
|
+
var RunGoalPayloadSchema = external_exports.object({ run_id: external_exports.string().min(1).max(64), action: external_exports.enum(["pause", "clear"]) });
|
|
24847
25227
|
var RunTailPayloadSchema = external_exports.object({
|
|
24848
25228
|
run_id: external_exports.string().max(64).optional(),
|
|
24849
|
-
|
|
25229
|
+
task_chain_id: external_exports.string().max(64).optional(),
|
|
24850
25230
|
lines: external_exports.number().int().positive().max(2e3).optional(),
|
|
24851
25231
|
before_cursor: external_exports.number().int().min(0).optional()
|
|
24852
25232
|
});
|
|
@@ -24926,6 +25306,12 @@ var AgentRuntime = class {
|
|
|
24926
25306
|
finished: async (runId, report) => {
|
|
24927
25307
|
this.pendingReports.set(runId, report);
|
|
24928
25308
|
await this.flushReport(runId);
|
|
25309
|
+
},
|
|
25310
|
+
goal: async (runId, report) => {
|
|
25311
|
+
await this.retry(() => this.client.runGoal(runId, report), 3);
|
|
25312
|
+
},
|
|
25313
|
+
goalTurn: async (runId, report) => {
|
|
25314
|
+
await this.retry(() => this.client.runGoalTurn(runId, report), 9);
|
|
24929
25315
|
}
|
|
24930
25316
|
};
|
|
24931
25317
|
this.workspaces = new WorkspaceManager(config2, this.logger);
|
|
@@ -24998,7 +25384,7 @@ var AgentRuntime = class {
|
|
|
24998
25384
|
activeSessions: this.runs.activeCount,
|
|
24999
25385
|
storedRuns: this.runs.recentRuns().length,
|
|
25000
25386
|
startedAt: this.startedAt,
|
|
25001
|
-
runs: this.runs.recentRuns().map((run) => ({ runId: run.runId, status: run.status, sessionId: run.
|
|
25387
|
+
runs: this.runs.recentRuns().map((run) => ({ runId: run.runId, status: run.status, sessionId: run.sessionKey, updatedAt: new Date(run.at).toISOString() })),
|
|
25002
25388
|
capabilities: this.detection?.detectedIds ?? [],
|
|
25003
25389
|
...this.detection ? { detection: this.detection } : {},
|
|
25004
25390
|
...!this.lastHeartbeatOk && this.lastError ? { connectionError: this.lastError } : {},
|
|
@@ -25178,15 +25564,15 @@ var AgentRuntime = class {
|
|
|
25178
25564
|
const cancelled = await this.runs.cancel(payload.run_id);
|
|
25179
25565
|
return { success: true, result: { cancelled } };
|
|
25180
25566
|
}
|
|
25567
|
+
case "run.goal": {
|
|
25568
|
+
const payload = RunGoalPayloadSchema.parse(command.payload);
|
|
25569
|
+
return { success: true, result: { applied: this.runs.controlGoal(payload.run_id, payload.action) } };
|
|
25570
|
+
}
|
|
25181
25571
|
case "run.tail": {
|
|
25182
25572
|
const payload = RunTailPayloadSchema.parse(command.payload);
|
|
25183
|
-
const tail = this.runs.tail({ ...payload.run_id ? { runId: payload.run_id } : {}, ...payload.
|
|
25573
|
+
const tail = this.runs.tail({ ...payload.run_id ? { runId: payload.run_id } : {}, ...payload.task_chain_id ? { taskChainId: payload.task_chain_id } : {} }, payload.lines ?? 200, payload.before_cursor);
|
|
25184
25574
|
return { success: true, result: tail };
|
|
25185
25575
|
}
|
|
25186
|
-
case "workstation.create": {
|
|
25187
|
-
const workstationId = String(command.payload?.workstation_id ?? command.workstation_id);
|
|
25188
|
-
return { success: true, session_key: workstationId, result: { ready: true } };
|
|
25189
|
-
}
|
|
25190
25576
|
case "cli.detect":
|
|
25191
25577
|
this.detection = await cliDetection.detect(true);
|
|
25192
25578
|
void this.refreshCatalogs({ force: true });
|