toc-ocra 0.3.17 → 0.3.19
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/dist/cli/cli.mjs +165 -116
- package/dist/service/agent.mjs +154 -105
- package/dist/src/acp/acp-launch-specs.js +3 -0
- package/dist/src/acp/acp-launch-specs.js.map +1 -1
- package/dist/src/acp/chat-session.d.ts +8 -0
- package/dist/src/acp/chat-session.js +31 -2
- package/dist/src/acp/chat-session.js.map +1 -1
- package/dist/src/providers/claude-sessions.d.ts +10 -0
- package/dist/src/providers/claude-sessions.js +27 -0
- package/dist/src/providers/claude-sessions.js.map +1 -0
- package/dist/src/providers/model-catalog.d.ts +9 -0
- package/dist/src/providers/model-catalog.js +17 -7
- package/dist/src/providers/model-catalog.js.map +1 -1
- package/package.json +1 -1
package/dist/service/agent.mjs
CHANGED
|
@@ -6,8 +6,8 @@ var __export = (target, all) => {
|
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
// src/plugin-service.ts
|
|
9
|
-
import { existsSync as
|
|
10
|
-
import { delimiter as delimiter5, join as
|
|
9
|
+
import { existsSync as existsSync8 } from "node:fs";
|
|
10
|
+
import { delimiter as delimiter5, join as join23 } from "node:path";
|
|
11
11
|
|
|
12
12
|
// src/config.ts
|
|
13
13
|
import { randomUUID } from "node:crypto";
|
|
@@ -21011,15 +21011,32 @@ function textRows(prefix, text3, maxRows = 40) {
|
|
|
21011
21011
|
|
|
21012
21012
|
// src/acp/acp-launch-specs.ts
|
|
21013
21013
|
import { realpathSync as realpathSync2 } from "node:fs";
|
|
21014
|
-
import { join as
|
|
21014
|
+
import { join as join13 } from "node:path";
|
|
21015
|
+
|
|
21016
|
+
// src/providers/claude-sessions.ts
|
|
21017
|
+
import { existsSync as existsSync5, readdirSync as readdirSync3 } from "node:fs";
|
|
21018
|
+
import { homedir as homedir4 } from "node:os";
|
|
21019
|
+
import { join as join7 } from "node:path";
|
|
21020
|
+
function claudeSessionSaved(sessionId, env = process.env) {
|
|
21021
|
+
const id = sessionId.trim();
|
|
21022
|
+
if (!id || /[/\\]/.test(id) || id.includes("..")) return false;
|
|
21023
|
+
const projects = join7(env.CLAUDE_CONFIG_DIR?.trim() || join7(homedir4(), ".claude"), "projects");
|
|
21024
|
+
let folders;
|
|
21025
|
+
try {
|
|
21026
|
+
folders = readdirSync3(projects);
|
|
21027
|
+
} catch (error62) {
|
|
21028
|
+
return error62.code !== "ENOENT";
|
|
21029
|
+
}
|
|
21030
|
+
return folders.some((folder) => existsSync5(join7(projects, folder, `${id}.jsonl`)));
|
|
21031
|
+
}
|
|
21015
21032
|
|
|
21016
21033
|
// src/providers/cli/codex-catalog.ts
|
|
21017
21034
|
import { spawn as spawn3 } from "node:child_process";
|
|
21018
21035
|
import { statSync as statSync4 } from "node:fs";
|
|
21019
21036
|
import { chmod as chmod3, mkdir as mkdir3, readFile as readFile3, rename as rename3, stat, writeFile as writeFile3 } from "node:fs/promises";
|
|
21020
|
-
import { homedir as
|
|
21021
|
-
import { dirname as dirname6, isAbsolute, join as
|
|
21022
|
-
var codexHome = () => process.env.CODEX_HOME?.trim() ||
|
|
21037
|
+
import { homedir as homedir5 } from "node:os";
|
|
21038
|
+
import { dirname as dirname6, isAbsolute, join as join8, resolve as resolve2 } from "node:path";
|
|
21039
|
+
var codexHome = () => process.env.CODEX_HOME?.trim() || join8(homedir5(), ".codex");
|
|
21023
21040
|
var BUNDLED_TIMEOUT_MS = 1e4;
|
|
21024
21041
|
function configuredCatalogPath(config2, home = codexHome()) {
|
|
21025
21042
|
const value = config2.match(/^\s*model_catalog_json\s*=\s*["']([^"']+)["']\s*(?:#.*)?$/m)?.[1]?.trim();
|
|
@@ -21097,11 +21114,11 @@ function fileStamp(path) {
|
|
|
21097
21114
|
}
|
|
21098
21115
|
var stampOf = (configPath, sourcePath) => `${fileStamp(configPath)}|${fileStamp(sourcePath)}`;
|
|
21099
21116
|
function overlayPath() {
|
|
21100
|
-
return
|
|
21117
|
+
return join8(agentDataDir(), "codex", "model-catalog.json");
|
|
21101
21118
|
}
|
|
21102
21119
|
async function rebuild() {
|
|
21103
21120
|
const home = codexHome();
|
|
21104
|
-
const configPath =
|
|
21121
|
+
const configPath = join8(home, "config.toml");
|
|
21105
21122
|
const config2 = await readFile3(configPath, "utf8").catch(() => "");
|
|
21106
21123
|
const sourcePath = configuredCatalogPath(config2, home);
|
|
21107
21124
|
if (!sourcePath) {
|
|
@@ -21156,20 +21173,20 @@ function codexCatalogArgs() {
|
|
|
21156
21173
|
// src/providers/model-catalog.ts
|
|
21157
21174
|
import { spawn as spawn5 } from "node:child_process";
|
|
21158
21175
|
import { readFile as readFile4 } from "node:fs/promises";
|
|
21159
|
-
import { homedir as
|
|
21160
|
-
import { isAbsolute as isAbsolute2, join as
|
|
21176
|
+
import { homedir as homedir7 } from "node:os";
|
|
21177
|
+
import { isAbsolute as isAbsolute2, join as join10, resolve as resolve3 } from "node:path";
|
|
21161
21178
|
|
|
21162
21179
|
// src/providers/kiro-auth.ts
|
|
21163
21180
|
import { execFile as execFile3 } from "node:child_process";
|
|
21164
|
-
import { homedir as
|
|
21165
|
-
import { join as
|
|
21181
|
+
import { homedir as homedir6 } from "node:os";
|
|
21182
|
+
import { join as join9 } from "node:path";
|
|
21166
21183
|
import { promisify } from "node:util";
|
|
21167
21184
|
var execFileAsync = promisify(execFile3);
|
|
21168
21185
|
var NOT_AUTHENTICATED = "Kiro CLI \u672A\u767B\u5F55\u6216\u65E0\u6CD5\u786E\u8BA4\u767B\u5F55\u72B6\u6001\uFF0C\u8BF7\u5728\u672C\u673A\u767B\u5F55\u540E\u91CD\u8BD5";
|
|
21169
21186
|
var knownUnauthenticated = false;
|
|
21170
21187
|
async function hasStoredAuthentication(environment) {
|
|
21171
21188
|
if (environment.KIRO_API_KEY?.trim()) return true;
|
|
21172
|
-
const database = process.platform === "darwin" ?
|
|
21189
|
+
const database = process.platform === "darwin" ? join9(homedir6(), "Library", "Application Support", "kiro-cli", "data.sqlite3") : process.platform === "win32" ? join9(environment.LOCALAPPDATA || join9(homedir6(), "AppData", "Local"), "Kiro-Cli", "data.sqlite3") : join9(environment.XDG_DATA_HOME || join9(homedir6(), ".local", "share"), "kiro-cli", "data.sqlite3");
|
|
21173
21190
|
const sql = "SELECT 1 FROM auth_kv WHERE key IN ('kirocli:odic:token', 'codewhisperer:odic:token', 'kirocli:external-idp:token', 'kirocli:social:token') AND (json_extract(value, '$.expires_at') IS NULL OR julianday(json_extract(value, '$.expires_at')) > julianday('now')) LIMIT 1;";
|
|
21174
21191
|
try {
|
|
21175
21192
|
const { stdout } = await execFileAsync("sqlite3", ["-readonly", database, sql], {
|
|
@@ -21285,6 +21302,11 @@ function objectValue(value) {
|
|
|
21285
21302
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
21286
21303
|
}
|
|
21287
21304
|
var CLAUDE_REASONING_EFFORTS = ["low", "medium", "high", "xhigh", "max"];
|
|
21305
|
+
var CLAUDE_BUILTIN_MODELS = [
|
|
21306
|
+
{ id: "opus", name: "Opus" },
|
|
21307
|
+
{ id: "sonnet", name: "Sonnet" },
|
|
21308
|
+
{ id: "haiku", name: "Haiku" }
|
|
21309
|
+
];
|
|
21288
21310
|
function parseClaudeModelCatalog(settings, environment = process.env, fetchedAt = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
21289
21311
|
const source = objectValue(settings);
|
|
21290
21312
|
const mergedEnv = { ...objectValue(source.env), ...environment };
|
|
@@ -21308,7 +21330,10 @@ function parseClaudeModelCatalog(settings, environment = process.env, fetchedAt
|
|
|
21308
21330
|
if (id) addModel(id, stringValue(mergedEnv[`${key}_NAME`]));
|
|
21309
21331
|
}
|
|
21310
21332
|
const defaultModel = stringValue(mergedEnv.ANTHROPIC_MODEL) ?? stringValue(source.model);
|
|
21311
|
-
if (
|
|
21333
|
+
if (models2.size === 0) {
|
|
21334
|
+
if (defaultModel) addModel(defaultModel);
|
|
21335
|
+
for (const model of CLAUDE_BUILTIN_MODELS) addModel(model.id, model.name);
|
|
21336
|
+
}
|
|
21312
21337
|
return {
|
|
21313
21338
|
agent_type: "claude",
|
|
21314
21339
|
...defaultModel && { default_model: defaultModel },
|
|
@@ -21316,15 +21341,15 @@ function parseClaudeModelCatalog(settings, environment = process.env, fetchedAt
|
|
|
21316
21341
|
models: [...models2.values()]
|
|
21317
21342
|
};
|
|
21318
21343
|
}
|
|
21319
|
-
var claudeHome = () => process.env.CLAUDE_CONFIG_DIR?.trim() ||
|
|
21320
|
-
var codexHome2 = () => process.env.CODEX_HOME?.trim() ||
|
|
21321
|
-
var geminiHome = () => process.env.GEMINI_CLI_HOME?.trim() ||
|
|
21322
|
-
var grokHome = () => process.env.GROK_HOME?.trim() ||
|
|
21323
|
-
var opencodeHome = () =>
|
|
21324
|
-
var kiroHome = () =>
|
|
21344
|
+
var claudeHome = () => process.env.CLAUDE_CONFIG_DIR?.trim() || join10(homedir7(), ".claude");
|
|
21345
|
+
var codexHome2 = () => process.env.CODEX_HOME?.trim() || join10(homedir7(), ".codex");
|
|
21346
|
+
var geminiHome = () => process.env.GEMINI_CLI_HOME?.trim() || join10(homedir7(), ".gemini");
|
|
21347
|
+
var grokHome = () => process.env.GROK_HOME?.trim() || join10(homedir7(), ".grok");
|
|
21348
|
+
var opencodeHome = () => join10(process.env.XDG_CONFIG_HOME?.trim() || join10(homedir7(), ".config"), "opencode");
|
|
21349
|
+
var kiroHome = () => join10(homedir7(), ".kiro");
|
|
21325
21350
|
async function readClaudeModelCatalog() {
|
|
21326
21351
|
const home = claudeHome();
|
|
21327
|
-
const content = await readFile4(
|
|
21352
|
+
const content = await readFile4(join10(home, "settings.json"), "utf8").catch(() => "");
|
|
21328
21353
|
let settings = {};
|
|
21329
21354
|
if (content) {
|
|
21330
21355
|
try {
|
|
@@ -21333,11 +21358,7 @@ async function readClaudeModelCatalog() {
|
|
|
21333
21358
|
throw new Error("Claude \u672C\u673A settings.json \u4E0D\u662F\u6709\u6548 JSON");
|
|
21334
21359
|
}
|
|
21335
21360
|
}
|
|
21336
|
-
|
|
21337
|
-
if (catalog.models.length === 0) {
|
|
21338
|
-
throw new Error("Claude \u672C\u673A\u672A\u914D\u7F6E\u53EF\u53D1\u73B0\u7684\u6A21\u578B\u9009\u9879\u6216\u522B\u540D");
|
|
21339
|
-
}
|
|
21340
|
-
return catalog;
|
|
21361
|
+
return parseClaudeModelCatalog(settings);
|
|
21341
21362
|
}
|
|
21342
21363
|
function configValue(content, key) {
|
|
21343
21364
|
const match = content.match(new RegExp(`^\\s*${key}\\s*=\\s*["']([^"']+)["']\\s*(?:#.*)?$`, "m"));
|
|
@@ -21386,13 +21407,13 @@ async function readCodexModels(codexHome3, config2) {
|
|
|
21386
21407
|
const configuredModels = parseCodexModels(await readFile4(catalogPath, "utf8").catch(() => ""));
|
|
21387
21408
|
if (configuredModels?.length) return configuredModels;
|
|
21388
21409
|
}
|
|
21389
|
-
const cached3 = parseCodexModels(await readFile4(
|
|
21410
|
+
const cached3 = parseCodexModels(await readFile4(join10(codexHome3, "models_cache.json"), "utf8").catch(() => ""));
|
|
21390
21411
|
if (cached3?.length) return cached3;
|
|
21391
21412
|
return codexModelsFrom(await codexBundledCatalog().catch(() => void 0), { listedOnly: true }) ?? [];
|
|
21392
21413
|
}
|
|
21393
21414
|
async function readCodexModelCatalog() {
|
|
21394
21415
|
const home = codexHome2();
|
|
21395
|
-
const config2 = await readFile4(
|
|
21416
|
+
const config2 = await readFile4(join10(home, "config.toml"), "utf8").catch(() => "");
|
|
21396
21417
|
const models2 = await readCodexModels(home, config2);
|
|
21397
21418
|
const defaultModel = configValue(config2, "model");
|
|
21398
21419
|
const defaultReasoningEffort = configValue(config2, "model_reasoning_effort");
|
|
@@ -21506,7 +21527,7 @@ async function readKiroModelCatalog(options = {}) {
|
|
|
21506
21527
|
if (current) return known.catalog;
|
|
21507
21528
|
try {
|
|
21508
21529
|
const launch = launchCli({ spec: kiro, args: ["acp", "--trust-tools="], env: environment });
|
|
21509
|
-
const catalog = await readKiroNativeModels(launch,
|
|
21530
|
+
const catalog = await readKiroNativeModels(launch, homedir7(), { catalog: base });
|
|
21510
21531
|
kiroEfforts = { signature, readAt: Date.now(), catalog };
|
|
21511
21532
|
return catalog;
|
|
21512
21533
|
} catch {
|
|
@@ -21515,7 +21536,7 @@ async function readKiroModelCatalog(options = {}) {
|
|
|
21515
21536
|
};
|
|
21516
21537
|
const [payload, content] = await Promise.all([
|
|
21517
21538
|
readEfforts(),
|
|
21518
|
-
readFile4(
|
|
21539
|
+
readFile4(join10(kiroHome(), "settings", "cli.json"), "utf8").catch(() => "{}")
|
|
21519
21540
|
]);
|
|
21520
21541
|
let settings;
|
|
21521
21542
|
try {
|
|
@@ -21572,7 +21593,7 @@ function geminiModelsUrl(baseUrl) {
|
|
|
21572
21593
|
}
|
|
21573
21594
|
async function readGeminiModelCatalog() {
|
|
21574
21595
|
const fileEnvironment = parseEnvFile(
|
|
21575
|
-
await readFile4(
|
|
21596
|
+
await readFile4(join10(geminiHome(), ".env"), "utf8").catch(() => "")
|
|
21576
21597
|
);
|
|
21577
21598
|
const environment = { ...fileEnvironment, ...process.env };
|
|
21578
21599
|
const baseUrl = environment.GOOGLE_GEMINI_BASE_URL?.trim();
|
|
@@ -21617,7 +21638,7 @@ function parseGrokModelCatalog(output2, config2 = "", fetchedAt = (/* @__PURE__
|
|
|
21617
21638
|
return catalog;
|
|
21618
21639
|
}
|
|
21619
21640
|
async function readGrokModelCatalog() {
|
|
21620
|
-
const config2 = await readFile4(
|
|
21641
|
+
const config2 = await readFile4(join10(grokHome(), "config.toml"), "utf8").catch(() => "");
|
|
21621
21642
|
const output2 = await runModelListCommand(cliExecutable("grok"), ["models"], "grok");
|
|
21622
21643
|
const catalog = parseGrokModelCatalog(output2, config2);
|
|
21623
21644
|
if (catalog.models.length === 0) throw new Error("Grok \u672C\u673A\u672A\u8FD4\u56DE\u53EF\u7528\u6A21\u578B");
|
|
@@ -21636,7 +21657,7 @@ function parseOpencodeModelCatalog(output2, config2 = "", fetchedAt = (/* @__PUR
|
|
|
21636
21657
|
return catalog;
|
|
21637
21658
|
}
|
|
21638
21659
|
async function readOpencodeModelCatalog() {
|
|
21639
|
-
const config2 = await readFile4(
|
|
21660
|
+
const config2 = await readFile4(join10(opencodeHome(), "opencode.json"), "utf8").catch(() => "") || await readFile4(join10(opencodeHome(), "opencode.jsonc"), "utf8").catch(() => "");
|
|
21640
21661
|
const output2 = await runModelListCommand(cliExecutable("opencode"), ["models"], "opencode");
|
|
21641
21662
|
const catalog = parseOpencodeModelCatalog(output2, config2);
|
|
21642
21663
|
if (catalog.models.length === 0) throw new Error("OpenCode \u672C\u673A\u672A\u8FD4\u56DE\u53EF\u7528\u6A21\u578B");
|
|
@@ -21644,22 +21665,22 @@ async function readOpencodeModelCatalog() {
|
|
|
21644
21665
|
}
|
|
21645
21666
|
var TEN_MINUTES = 10 * 60 * 1e3;
|
|
21646
21667
|
var MODEL_SOURCES = {
|
|
21647
|
-
claude: { read: readClaudeModelCatalog, watchFiles: () => [
|
|
21668
|
+
claude: { read: readClaudeModelCatalog, watchFiles: () => [join10(claudeHome(), "settings.json")] },
|
|
21648
21669
|
codex: {
|
|
21649
21670
|
read: readCodexModelCatalog,
|
|
21650
21671
|
watchFiles: () => {
|
|
21651
21672
|
const home = codexHome2();
|
|
21652
|
-
return [
|
|
21673
|
+
return [join10(home, "config.toml"), join10(home, "models_cache.json")];
|
|
21653
21674
|
},
|
|
21654
21675
|
// model_catalog_json may point anywhere; a periodic re-read covers it.
|
|
21655
21676
|
refreshEveryMs: TEN_MINUTES
|
|
21656
21677
|
},
|
|
21657
|
-
gemini: { read: readGeminiModelCatalog, watchFiles: () => [
|
|
21658
|
-
grok: { read: readGrokModelCatalog, watchFiles: () => [
|
|
21659
|
-
kiro: { read: readKiroModelCatalog, watchFiles: () => [
|
|
21678
|
+
gemini: { read: readGeminiModelCatalog, watchFiles: () => [join10(geminiHome(), ".env")], refreshEveryMs: TEN_MINUTES },
|
|
21679
|
+
grok: { read: readGrokModelCatalog, watchFiles: () => [join10(grokHome(), "config.toml")], refreshEveryMs: TEN_MINUTES },
|
|
21680
|
+
kiro: { read: readKiroModelCatalog, watchFiles: () => [join10(kiroHome(), "settings", "cli.json")] },
|
|
21660
21681
|
opencode: {
|
|
21661
21682
|
read: readOpencodeModelCatalog,
|
|
21662
|
-
watchFiles: () => [
|
|
21683
|
+
watchFiles: () => [join10(opencodeHome(), "opencode.json"), join10(opencodeHome(), "opencode.jsonc")],
|
|
21663
21684
|
refreshEveryMs: TEN_MINUTES
|
|
21664
21685
|
}
|
|
21665
21686
|
};
|
|
@@ -21773,11 +21794,11 @@ function classifySpawnError(error62, context) {
|
|
|
21773
21794
|
|
|
21774
21795
|
// src/providers/cli/kiro-session-log.ts
|
|
21775
21796
|
import { open as open2, readdir, readFile as readFile5, stat as stat2 } from "node:fs/promises";
|
|
21776
|
-
import { homedir as
|
|
21777
|
-
import { join as
|
|
21797
|
+
import { homedir as homedir8 } from "node:os";
|
|
21798
|
+
import { join as join11 } from "node:path";
|
|
21778
21799
|
var SHELL_TOOLS = /* @__PURE__ */ new Set(["shell", "execute_bash", "bash"]);
|
|
21779
21800
|
function kiroSessionsDirectory() {
|
|
21780
|
-
return process.env.TOC_OCRA_KIRO_SESSIONS_DIR ||
|
|
21801
|
+
return process.env.TOC_OCRA_KIRO_SESSIONS_DIR || join11(homedir8(), ".kiro", "sessions", "cli");
|
|
21781
21802
|
}
|
|
21782
21803
|
var KiroSessionLog = class {
|
|
21783
21804
|
constructor(options) {
|
|
@@ -21796,7 +21817,7 @@ var KiroSessionLog = class {
|
|
|
21796
21817
|
/** Called before the CLI starts: a resumed log is followed from its current end. */
|
|
21797
21818
|
async begin() {
|
|
21798
21819
|
if (!this.options.sessionId) return;
|
|
21799
|
-
this.path =
|
|
21820
|
+
this.path = join11(this.directory, `${this.options.sessionId}.jsonl`);
|
|
21800
21821
|
this.offset = await stat2(this.path).then((info) => info.size, () => 0);
|
|
21801
21822
|
}
|
|
21802
21823
|
/**
|
|
@@ -21809,11 +21830,11 @@ var KiroSessionLog = class {
|
|
|
21809
21830
|
const found = [];
|
|
21810
21831
|
for (const name of names) {
|
|
21811
21832
|
if (!name.endsWith(".json")) continue;
|
|
21812
|
-
const meta3 = await readFile5(
|
|
21833
|
+
const meta3 = await readFile5(join11(this.directory, name), "utf8").then((text3) => JSON.parse(text3), () => void 0);
|
|
21813
21834
|
const created = meta3?.created_at ? Date.parse(meta3.created_at) : NaN;
|
|
21814
21835
|
if (meta3?.cwd && sameFolder(meta3.cwd, this.options.workdir) && created >= this.options.startedAt - 2e3) found.push(name.slice(0, -5));
|
|
21815
21836
|
}
|
|
21816
|
-
if (found.length === 1) this.path =
|
|
21837
|
+
if (found.length === 1) this.path = join11(this.directory, `${found[0]}.jsonl`);
|
|
21817
21838
|
}
|
|
21818
21839
|
/** Reads entries appended since the last call. */
|
|
21819
21840
|
async refresh() {
|
|
@@ -22182,9 +22203,9 @@ var OPENCODE_ACP_DIALECT = {
|
|
|
22182
22203
|
// src/acp/vendor.ts
|
|
22183
22204
|
import { spawn as spawn6 } from "node:child_process";
|
|
22184
22205
|
import { createHash } from "node:crypto";
|
|
22185
|
-
import { existsSync as
|
|
22206
|
+
import { existsSync as existsSync6, readFileSync as readFileSync5 } from "node:fs";
|
|
22186
22207
|
import { copyFile, mkdir as mkdir4, rename as rename4, rm as rm2, writeFile as writeFile4 } from "node:fs/promises";
|
|
22187
|
-
import { dirname as dirname7, join as
|
|
22208
|
+
import { dirname as dirname7, join as join12, resolve as resolve4 } from "node:path";
|
|
22188
22209
|
import { fileURLToPath } from "node:url";
|
|
22189
22210
|
var AcpRuntimeUnavailable = class extends Error {
|
|
22190
22211
|
constructor(message) {
|
|
@@ -22197,7 +22218,7 @@ function packageRoot() {
|
|
|
22197
22218
|
let directory = dirname7(fileURLToPath(import.meta.url));
|
|
22198
22219
|
while (true) {
|
|
22199
22220
|
const path = resolve4(directory, "package.json");
|
|
22200
|
-
if (
|
|
22221
|
+
if (existsSync6(path)) {
|
|
22201
22222
|
try {
|
|
22202
22223
|
if (JSON.parse(readFileSync5(path, "utf8")).name === "toc-ocra") return directory;
|
|
22203
22224
|
} catch {
|
|
@@ -22217,21 +22238,21 @@ function agentPackageVersion() {
|
|
|
22217
22238
|
const directory = agentRoot();
|
|
22218
22239
|
if (!directory) return "0";
|
|
22219
22240
|
try {
|
|
22220
|
-
return JSON.parse(readFileSync5(
|
|
22241
|
+
return JSON.parse(readFileSync5(join12(directory, "package.json"), "utf8")).version ?? "0";
|
|
22221
22242
|
} catch {
|
|
22222
22243
|
return "0";
|
|
22223
22244
|
}
|
|
22224
22245
|
}
|
|
22225
22246
|
function vendoredAdapter(name) {
|
|
22226
22247
|
const directory = agentRoot();
|
|
22227
|
-
const entry = directory ?
|
|
22228
|
-
return entry &&
|
|
22248
|
+
const entry = directory ? join12(directory, "assets", "acp", name, "index.mjs") : void 0;
|
|
22249
|
+
return entry && existsSync6(entry) ? entry : void 0;
|
|
22229
22250
|
}
|
|
22230
22251
|
var installs = /* @__PURE__ */ new Map();
|
|
22231
22252
|
function ensureClaudeRuntime(dataDir2) {
|
|
22232
22253
|
const entry = vendoredAdapter("claude");
|
|
22233
22254
|
if (!entry) return Promise.reject(new AcpRuntimeUnavailable("\u8FD9\u4E2A\u7248\u672C\u7684\u8BBE\u5907\u4EE3\u7406\u6CA1\u6709\u9644\u5E26 Claude ACP \u9002\u914D\u5668"));
|
|
22234
|
-
const manifestPath =
|
|
22255
|
+
const manifestPath = join12(dirname7(entry), "runtime.json");
|
|
22235
22256
|
let manifest;
|
|
22236
22257
|
try {
|
|
22237
22258
|
manifest = JSON.parse(readFileSync5(manifestPath, "utf8"));
|
|
@@ -22239,7 +22260,7 @@ function ensureClaudeRuntime(dataDir2) {
|
|
|
22239
22260
|
return Promise.reject(new AcpRuntimeUnavailable("Claude ACP \u9002\u914D\u5668\u7F3A\u5C11 runtime.json"));
|
|
22240
22261
|
}
|
|
22241
22262
|
const hash2 = createHash("sha256").update(readFileSync5(entry)).digest("hex").slice(0, 12);
|
|
22242
|
-
const directory =
|
|
22263
|
+
const directory = join12(dataDir2, "acp-runtimes", `claude-${manifest.adapterVersion}-sdk-${manifest.sdk.version}-${hash2}`);
|
|
22243
22264
|
const existing = installs.get(directory);
|
|
22244
22265
|
if (existing) return existing;
|
|
22245
22266
|
const install = installClaudeRuntime(directory, entry, manifest).catch((error62) => {
|
|
@@ -22250,19 +22271,19 @@ function ensureClaudeRuntime(dataDir2) {
|
|
|
22250
22271
|
return install;
|
|
22251
22272
|
}
|
|
22252
22273
|
async function installClaudeRuntime(directory, entry, manifest) {
|
|
22253
|
-
const sdkPackage =
|
|
22254
|
-
if (
|
|
22274
|
+
const sdkPackage = join12(directory, "node_modules", ...manifest.sdk.name.split("/"), "package.json");
|
|
22275
|
+
if (existsSync6(sdkPackage) && existsSync6(join12(directory, "index.mjs"))) return directory;
|
|
22255
22276
|
const temporary = `${directory}.tmp-${process.pid}-${Date.now()}`;
|
|
22256
22277
|
await mkdir4(temporary, { recursive: true, mode: 448 });
|
|
22257
22278
|
try {
|
|
22258
|
-
await writeFile4(
|
|
22279
|
+
await writeFile4(join12(temporary, "package.json"), JSON.stringify({
|
|
22259
22280
|
name: "toc-ocra-claude-acp-runtime",
|
|
22260
22281
|
private: true,
|
|
22261
22282
|
type: "module",
|
|
22262
22283
|
dependencies: { [manifest.sdk.name]: manifest.sdk.version }
|
|
22263
22284
|
}, null, 2));
|
|
22264
22285
|
await runNpm(["install", "--omit=optional", "--no-audit", "--no-fund", "--no-package-lock", "--loglevel=error"], temporary);
|
|
22265
|
-
await copyFile(entry,
|
|
22286
|
+
await copyFile(entry, join12(temporary, "index.mjs"));
|
|
22266
22287
|
await rm2(directory, { recursive: true, force: true });
|
|
22267
22288
|
await rename4(temporary, directory);
|
|
22268
22289
|
} catch (error62) {
|
|
@@ -22385,13 +22406,15 @@ var CLAUDE_LAUNCH_SPEC = {
|
|
|
22385
22406
|
const executable = installedCli(claude);
|
|
22386
22407
|
const runtime = await ensureClaudeRuntime(dataDir2);
|
|
22387
22408
|
return {
|
|
22388
|
-
launch: { executable: process.execPath, args: [
|
|
22409
|
+
launch: { executable: process.execPath, args: [join13(runtime, "index.mjs")], env: { ...providerEnvironment(), CLAUDE_CODE_EXECUTABLE: executable }, cwd: workdir },
|
|
22389
22410
|
fingerprint: `claude:${runtime}:${executable}`
|
|
22390
22411
|
};
|
|
22391
22412
|
},
|
|
22392
22413
|
// Manual mode asks for every edit and command; the user or the level's policy answers.
|
|
22393
22414
|
permissionModeConfig: { values: { ask: "default", acceptEdits: "acceptEdits", bypassPermissions: "bypassPermissions", plan: "plan" } },
|
|
22394
22415
|
resumePreference: "resume",
|
|
22416
|
+
// The adapter accepts `session/resume` of a conversation Claude no longer has; only the prompt fails.
|
|
22417
|
+
resumable: (sessionId) => claudeSessionSaved(sessionId, providerEnvironment()),
|
|
22395
22418
|
dialect: { failureRules: [{ kind: "sessionMissing", pattern: /No conversation found with session ID|session[^\n]{0,40}not found/i }] },
|
|
22396
22419
|
modelDiscovery: { kind: "reader", source: MODEL_SOURCES.claude }
|
|
22397
22420
|
};
|
|
@@ -22502,7 +22525,7 @@ var ACP_CHAT_IDS = [...ACP_CHAT.keys()];
|
|
|
22502
22525
|
// src/acp/acp-model-catalog-probe.ts
|
|
22503
22526
|
import { mkdtemp, rm as rm3 } from "node:fs/promises";
|
|
22504
22527
|
import { tmpdir } from "node:os";
|
|
22505
|
-
import { join as
|
|
22528
|
+
import { join as join14 } from "node:path";
|
|
22506
22529
|
|
|
22507
22530
|
// src/acp/acp-options.ts
|
|
22508
22531
|
var text = (value) => typeof value === "string" && value ? value : void 0;
|
|
@@ -23135,9 +23158,9 @@ async function readSessionModels(row, clientVersion = "1") {
|
|
|
23135
23158
|
const discovery = row.modelDiscovery;
|
|
23136
23159
|
if (discovery.kind !== "session") throw new Error(`${row.agent} does not list its models in a session`);
|
|
23137
23160
|
const cli = requireCliSpec(row.agent);
|
|
23138
|
-
const folder = await mkdtemp(
|
|
23161
|
+
const folder = await mkdtemp(join14(tmpdir(), `toc-ocra-acp-models-${row.agent}-`));
|
|
23139
23162
|
try {
|
|
23140
|
-
const folderArgs = discovery.sessionFolderArgs?.(
|
|
23163
|
+
const folderArgs = discovery.sessionFolderArgs?.(join14(folder, "sessions")) ?? [];
|
|
23141
23164
|
const args = [...row.args({ access: "read-only", model: "", reasoningEffort: "" }), ...folderArgs];
|
|
23142
23165
|
const launch = launchCli({ spec: cli, args, env: { ...providerEnvironment(), ...row.env } });
|
|
23143
23166
|
const connection = await AcpConnection.open({ executable: launch.executable, args: launch.args, env: launch.env, cwd: folder }, {
|
|
@@ -23766,14 +23789,14 @@ function isWriterConflict(message) {
|
|
|
23766
23789
|
}
|
|
23767
23790
|
|
|
23768
23791
|
// src/providers/cli/claude.ts
|
|
23769
|
-
import { readdirSync as
|
|
23770
|
-
import { homedir as
|
|
23771
|
-
import { join as
|
|
23792
|
+
import { readdirSync as readdirSync4, readFileSync as readFileSync6 } from "node:fs";
|
|
23793
|
+
import { homedir as homedir9 } from "node:os";
|
|
23794
|
+
import { join as join15 } from "node:path";
|
|
23772
23795
|
var CLAUDE = requireCliSpec("claude");
|
|
23773
23796
|
function claudeProjectRoots() {
|
|
23774
23797
|
const configured = process.env.CLAUDE_CONFIG_DIR;
|
|
23775
|
-
const dirs = configured ? configured.split(process.platform === "win32" ? ";" : ":").map((entry) => entry.trim()).filter(Boolean) : [
|
|
23776
|
-
return dirs.map((dir) =>
|
|
23798
|
+
const dirs = configured ? configured.split(process.platform === "win32" ? ";" : ":").map((entry) => entry.trim()).filter(Boolean) : [join15(homedir9(), ".claude")];
|
|
23799
|
+
return dirs.map((dir) => join15(dir, "projects"));
|
|
23777
23800
|
}
|
|
23778
23801
|
function claudeTranscriptExists(sessionId) {
|
|
23779
23802
|
return claudeTranscriptPath(sessionId) !== void 0;
|
|
@@ -23783,13 +23806,13 @@ function claudeTranscriptPath(sessionId) {
|
|
|
23783
23806
|
for (const root2 of claudeProjectRoots()) {
|
|
23784
23807
|
let projects;
|
|
23785
23808
|
try {
|
|
23786
|
-
projects =
|
|
23809
|
+
projects = readdirSync4(root2);
|
|
23787
23810
|
} catch {
|
|
23788
23811
|
continue;
|
|
23789
23812
|
}
|
|
23790
23813
|
for (const project of projects) {
|
|
23791
23814
|
try {
|
|
23792
|
-
if (
|
|
23815
|
+
if (readdirSync4(join15(root2, project)).includes(file2)) return join15(root2, project, file2);
|
|
23793
23816
|
} catch {
|
|
23794
23817
|
}
|
|
23795
23818
|
}
|
|
@@ -23833,7 +23856,7 @@ var claudeProvider = {
|
|
|
23833
23856
|
settings.disableAllHooks = true;
|
|
23834
23857
|
args.push("--restricted", "--permission-mode", "plan", "--tools", "Read,Glob,Grep", "--strict-mcp-config", "--mcp-config", '{"mcpServers":{}}', "--disallowedTools", "mcp__*");
|
|
23835
23858
|
try {
|
|
23836
|
-
const userSettings = JSON.parse(readFileSync6(
|
|
23859
|
+
const userSettings = JSON.parse(readFileSync6(join15(homedir9(), ".claude", "settings.json"), "utf8"));
|
|
23837
23860
|
for (const [key, value] of Object.entries(userSettings.env ?? {})) {
|
|
23838
23861
|
if (/^ANTHROPIC_[A-Z0-9_]+$/.test(key) && typeof value === "string" && env[key] === void 0) env[key] = value;
|
|
23839
23862
|
}
|
|
@@ -25003,7 +25026,7 @@ var cliDetection = new CliDetectionService();
|
|
|
25003
25026
|
|
|
25004
25027
|
// src/runtime/agent-runtime.ts
|
|
25005
25028
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
25006
|
-
import { join as
|
|
25029
|
+
import { join as join22 } from "node:path";
|
|
25007
25030
|
|
|
25008
25031
|
// src/exec/script-runner.ts
|
|
25009
25032
|
import { spawn as spawn10 } from "node:child_process";
|
|
@@ -25292,15 +25315,15 @@ async function readCLIQuotaReport(agentType) {
|
|
|
25292
25315
|
|
|
25293
25316
|
// src/providers/tb-switch-control.ts
|
|
25294
25317
|
import { readFile as readFile6 } from "node:fs/promises";
|
|
25295
|
-
import { homedir as
|
|
25296
|
-
import { join as
|
|
25318
|
+
import { homedir as homedir10 } from "node:os";
|
|
25319
|
+
import { join as join16 } from "node:path";
|
|
25297
25320
|
function dataDir() {
|
|
25298
|
-
return process.env.TB_SWITCH_HOME?.trim() ||
|
|
25321
|
+
return process.env.TB_SWITCH_HOME?.trim() || join16(homedir10(), ".tb-switch");
|
|
25299
25322
|
}
|
|
25300
25323
|
async function readLocalService() {
|
|
25301
25324
|
let discovery;
|
|
25302
25325
|
try {
|
|
25303
|
-
discovery = JSON.parse(await readFile6(
|
|
25326
|
+
discovery = JSON.parse(await readFile6(join16(dataDir(), "api.json"), "utf8"));
|
|
25304
25327
|
} catch {
|
|
25305
25328
|
throw new Error("\u8FD9\u53F0\u8BBE\u5907\u4E0A\u7684 TB Switch \u670D\u52A1\u672A\u8FD0\u884C\uFF0C\u8BF7\u6253\u5F00\u684C\u9762\u7AEF\u63D2\u4EF6\u540E\u91CD\u8BD5\u3002");
|
|
25306
25329
|
}
|
|
@@ -25316,7 +25339,7 @@ async function readLocalService() {
|
|
|
25316
25339
|
}
|
|
25317
25340
|
let token = process.env.TB_SWITCH_API_TOKEN?.trim() ?? "";
|
|
25318
25341
|
try {
|
|
25319
|
-
token = (await readFile6(
|
|
25342
|
+
token = (await readFile6(join16(dataDir(), "api-token"), "utf8")).trim();
|
|
25320
25343
|
} catch {
|
|
25321
25344
|
}
|
|
25322
25345
|
if (!token) throw new Error("\u65E0\u6CD5\u8BFB\u53D6 TB Switch \u672C\u673A\u670D\u52A1\u51ED\u636E\uFF0C\u8BF7\u91CD\u542F\u684C\u9762\u7AEF\u63D2\u4EF6\u540E\u91CD\u8BD5\u3002");
|
|
@@ -25461,7 +25484,7 @@ function commandOf(pid) {
|
|
|
25461
25484
|
// src/runs/run-supervisor.ts
|
|
25462
25485
|
import { spawn as spawn12 } from "node:child_process";
|
|
25463
25486
|
import { mkdir as mkdir8, realpath as realpath2, stat as stat6, writeFile as writeFile8 } from "node:fs/promises";
|
|
25464
|
-
import { basename as basename3, isAbsolute as isAbsolute4, join as
|
|
25487
|
+
import { basename as basename3, isAbsolute as isAbsolute4, join as join20, relative as relative2, resolve as resolve5 } from "node:path";
|
|
25465
25488
|
import { createInterface as createInterface5 } from "node:readline";
|
|
25466
25489
|
|
|
25467
25490
|
// src/session/terminal-tail-buffer.ts
|
|
@@ -25823,19 +25846,19 @@ async function forkCodexThread(options) {
|
|
|
25823
25846
|
|
|
25824
25847
|
// src/runs/run-recorder.ts
|
|
25825
25848
|
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3 } from "node:fs";
|
|
25826
|
-
import { homedir as
|
|
25827
|
-
import { join as
|
|
25849
|
+
import { homedir as homedir11 } from "node:os";
|
|
25850
|
+
import { join as join17 } from "node:path";
|
|
25828
25851
|
var RunRecorder = class _RunRecorder {
|
|
25829
25852
|
constructor(path) {
|
|
25830
25853
|
this.path = path;
|
|
25831
25854
|
}
|
|
25832
25855
|
path;
|
|
25833
|
-
home =
|
|
25856
|
+
home = homedir11();
|
|
25834
25857
|
static fromEnvironment(runId, meta3) {
|
|
25835
25858
|
const directory = process.env.TOC_OCRA_RECORD_DIR?.trim();
|
|
25836
25859
|
if (!directory) return void 0;
|
|
25837
25860
|
mkdirSync3(directory, { recursive: true });
|
|
25838
|
-
const recorder = new _RunRecorder(
|
|
25861
|
+
const recorder = new _RunRecorder(join17(directory, `${String(meta3.agent ?? "cli")}-${runId}.jsonl`));
|
|
25839
25862
|
recorder.write({ meta: meta3 });
|
|
25840
25863
|
return recorder;
|
|
25841
25864
|
}
|
|
@@ -25851,7 +25874,7 @@ var RunRecorder = class _RunRecorder {
|
|
|
25851
25874
|
|
|
25852
25875
|
// src/runs/run-transcript.ts
|
|
25853
25876
|
import { chmod as chmod4, mkdir as mkdir6, readdir as readdir2, readFile as readFile8, rename as rename6, stat as stat4, unlink, writeFile as writeFile6 } from "node:fs/promises";
|
|
25854
|
-
import { join as
|
|
25877
|
+
import { join as join18 } from "node:path";
|
|
25855
25878
|
var MAX_TRANSCRIPT_ITEMS = 5e3;
|
|
25856
25879
|
var MAX_TRANSCRIPT_TEXT = 2e5;
|
|
25857
25880
|
var MAX_TRANSCRIPT_LINES = 2e4;
|
|
@@ -26116,7 +26139,7 @@ function transcriptFileName(runId) {
|
|
|
26116
26139
|
var TranscriptStore = class {
|
|
26117
26140
|
constructor(dataDir2, logger, env = process.env) {
|
|
26118
26141
|
this.logger = logger;
|
|
26119
|
-
this.directory = dataDir2 ?
|
|
26142
|
+
this.directory = dataDir2 ? join18(dataDir2, "transcripts") : "";
|
|
26120
26143
|
this.enabled = Boolean(dataDir2) && transcriptsOnDisk(env);
|
|
26121
26144
|
}
|
|
26122
26145
|
logger;
|
|
@@ -26171,7 +26194,7 @@ var TranscriptStore = class {
|
|
|
26171
26194
|
await this.writes.get(runId);
|
|
26172
26195
|
let text3;
|
|
26173
26196
|
try {
|
|
26174
|
-
text3 = await readFile8(
|
|
26197
|
+
text3 = await readFile8(join18(this.directory, name), "utf8");
|
|
26175
26198
|
} catch (error62) {
|
|
26176
26199
|
if (errorCode(error62) !== "ENOENT") this.logger.warn("run-transcript-read-failed", { runId, error: errorMessage(error62) });
|
|
26177
26200
|
return void 0;
|
|
@@ -26236,7 +26259,7 @@ var TranscriptStore = class {
|
|
|
26236
26259
|
transcript.dirty = false;
|
|
26237
26260
|
const body = JSON.stringify(transcript.toFile());
|
|
26238
26261
|
await this.ensureDirectory();
|
|
26239
|
-
const file2 =
|
|
26262
|
+
const file2 = join18(this.directory, name);
|
|
26240
26263
|
const temporary = `${file2}.${process.pid}.tmp`;
|
|
26241
26264
|
await writeFile6(temporary, body, { mode: 384 });
|
|
26242
26265
|
await rename6(temporary, file2);
|
|
@@ -26273,7 +26296,7 @@ var TranscriptStore = class {
|
|
|
26273
26296
|
const now = Date.now();
|
|
26274
26297
|
const files = [];
|
|
26275
26298
|
for (const name of names) {
|
|
26276
|
-
const path =
|
|
26299
|
+
const path = join18(this.directory, name);
|
|
26277
26300
|
if (name.endsWith(".tmp")) {
|
|
26278
26301
|
const info2 = await stat4(path).catch(() => void 0);
|
|
26279
26302
|
if (info2?.isFile() && now - info2.mtimeMs > STALE_TEMPORARY_MS) await unlink(path).catch(() => void 0);
|
|
@@ -26323,7 +26346,7 @@ function errorMessage(error62) {
|
|
|
26323
26346
|
import { createHash as createHash3, randomUUID as randomUUID2 } from "node:crypto";
|
|
26324
26347
|
import { constants as constants2 } from "node:fs";
|
|
26325
26348
|
import { lstat, mkdir as mkdir7, open as open3, realpath, rename as rename7, rm as rm4, writeFile as writeFile7 } from "node:fs/promises";
|
|
26326
|
-
import { basename as basename2, isAbsolute as isAbsolute3, join as
|
|
26349
|
+
import { basename as basename2, isAbsolute as isAbsolute3, join as join19, relative } from "node:path";
|
|
26327
26350
|
function within(root2, path) {
|
|
26328
26351
|
const segment = relative(root2, path);
|
|
26329
26352
|
return segment === "" || !segment.startsWith("..") && !isAbsolute3(segment);
|
|
@@ -26331,7 +26354,7 @@ function within(root2, path) {
|
|
|
26331
26354
|
async function attachmentDirectory(workdir, messageId) {
|
|
26332
26355
|
let directory = workdir;
|
|
26333
26356
|
for (const segment of [".echo", "attachments", `message-${encodeURIComponent(messageId).slice(0, 180)}`]) {
|
|
26334
|
-
directory =
|
|
26357
|
+
directory = join19(directory, segment);
|
|
26335
26358
|
await mkdir7(directory, { mode: 448 }).catch((error62) => {
|
|
26336
26359
|
if (error62.code !== "EEXIST") throw error62;
|
|
26337
26360
|
});
|
|
@@ -26339,7 +26362,7 @@ async function attachmentDirectory(workdir, messageId) {
|
|
|
26339
26362
|
if (metadata.isSymbolicLink() || !metadata.isDirectory() || !within(workdir, await realpath(directory))) {
|
|
26340
26363
|
throw new Error("\u9644\u4EF6\u76EE\u5F55\u5FC5\u987B\u4F4D\u4E8E CLI \u5DE5\u4F5C\u76EE\u5F55\u5185\uFF0C\u4E14\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5");
|
|
26341
26364
|
}
|
|
26342
|
-
if (segment === ".echo") await writeFile7(
|
|
26365
|
+
if (segment === ".echo") await writeFile7(join19(directory, ".gitignore"), "*\n", { flag: "wx", mode: 384 }).catch((error62) => {
|
|
26343
26366
|
if (error62.code !== "EEXIST") throw error62;
|
|
26344
26367
|
});
|
|
26345
26368
|
}
|
|
@@ -26376,9 +26399,9 @@ async function prepareTaskAttachments(payload, workdir, download, signal2) {
|
|
|
26376
26399
|
const characters = Array.from(basename2(file2.name.replace(/\\/g, "/")).replace(/[^\p{L}\p{N}._-]/gu, "_").replace(/\.+$/u, ""));
|
|
26377
26400
|
while (Buffer.byteLength(characters.join("")) > 160) characters.shift();
|
|
26378
26401
|
const name = characters.join("") || "attachment";
|
|
26379
|
-
const path =
|
|
26402
|
+
const path = join19(directory, `${file2.file_id}-${name}`);
|
|
26380
26403
|
if (!await matches(path, file2.size, file2.sha256, signal2)) {
|
|
26381
|
-
const temporary =
|
|
26404
|
+
const temporary = join19(directory, `.download-${file2.file_id}-${randomUUID2()}.part`);
|
|
26382
26405
|
try {
|
|
26383
26406
|
await download(payload.run_id, file2.file_id, temporary, file2.size, file2.sha256, signal2);
|
|
26384
26407
|
signal2.throwIfAborted();
|
|
@@ -26778,6 +26801,7 @@ var QUESTION_OPTIONS = [
|
|
|
26778
26801
|
{ optionId: "answer", name: "Submit answers", kind: "allow_once" },
|
|
26779
26802
|
{ optionId: "cancel", name: "Cancel", kind: "reject_once" }
|
|
26780
26803
|
];
|
|
26804
|
+
var TURN_OUTPUT = /* @__PURE__ */ new Set(["agent_message_chunk", "agent_thought_chunk", "tool_call", "tool_call_update", "plan"]);
|
|
26781
26805
|
var CANCEL_GRACE_MS = 1e4;
|
|
26782
26806
|
var MAX_IMAGE_BYTES = 10 * 1024 * 1024;
|
|
26783
26807
|
var IMAGE_TYPES = { ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".webp": "image/webp" };
|
|
@@ -26810,14 +26834,15 @@ var AcpChatSession = class {
|
|
|
26810
26834
|
this.clearIdle();
|
|
26811
26835
|
this.lastUsedAt = Date.now();
|
|
26812
26836
|
const transcript = new TurnTranscript((events) => sink.events(events), (rows) => sink.rows(rows));
|
|
26813
|
-
const turn = { runId: request.runId, phase: "starting", request, transcript, sink, cancelRequested: false, loading: false, queued: [], awaiting: /* @__PURE__ */ new Map(), pending: /* @__PURE__ */ new Map(), usage: new UsageTally() };
|
|
26837
|
+
const turn = { runId: request.runId, phase: "starting", request, transcript, sink, cancelRequested: false, loading: false, queued: [], awaiting: /* @__PURE__ */ new Map(), pending: /* @__PURE__ */ new Map(), usage: new UsageTally(), output: false };
|
|
26814
26838
|
this.turn = turn;
|
|
26815
26839
|
for (const note of request.notes) transcript.note(note);
|
|
26816
26840
|
let result;
|
|
26817
26841
|
try {
|
|
26818
26842
|
result = await this.execute(turn, launch);
|
|
26819
26843
|
} catch (error62) {
|
|
26820
|
-
|
|
26844
|
+
const failure2 = this.classify(error62);
|
|
26845
|
+
result = this.startsFresh(turn, failure2) ? await this.runFresh(turn, launch) : this.failed(turn, failure2);
|
|
26821
26846
|
} finally {
|
|
26822
26847
|
if (turn.cancelTimer) clearTimeout(turn.cancelTimer);
|
|
26823
26848
|
}
|
|
@@ -26836,6 +26861,28 @@ var AcpChatSession = class {
|
|
|
26836
26861
|
this.scheduleIdle();
|
|
26837
26862
|
return result;
|
|
26838
26863
|
}
|
|
26864
|
+
/**
|
|
26865
|
+
* Whether a failed turn runs again in a new session: the saved session it
|
|
26866
|
+
* reopened turned out to be gone before the agent answered anything (Claude
|
|
26867
|
+
* Code accepts `session/resume` of a conversation it no longer has and fails
|
|
26868
|
+
* only at the prompt).
|
|
26869
|
+
*/
|
|
26870
|
+
startsFresh(turn, failure2) {
|
|
26871
|
+
return Boolean(turn.reopened) && !turn.output && !turn.cancelRequested && failure2.kind === "sessionMissing";
|
|
26872
|
+
}
|
|
26873
|
+
async runFresh(turn, launch) {
|
|
26874
|
+
turn.transcript.note(`\u539F\u4F1A\u8BDD ${turn.reopened} \u5DF2\u65E0\u6CD5\u7EE7\u7EED\uFF0C\u672C\u8F6E\u5F00\u59CB\u65B0\u4F1A\u8BDD`);
|
|
26875
|
+
this.deps.logger.info("acp-session-missing-restart", { session: this.key, sessionId: turn.reopened });
|
|
26876
|
+
turn.request = { ...turn.request, sessionId: "" };
|
|
26877
|
+
turn.reopened = void 0;
|
|
26878
|
+
turn.phase = "starting";
|
|
26879
|
+
this.session = void 0;
|
|
26880
|
+
try {
|
|
26881
|
+
return await this.execute(turn, launch);
|
|
26882
|
+
} catch (error62) {
|
|
26883
|
+
return this.failed(turn, this.classify(error62));
|
|
26884
|
+
}
|
|
26885
|
+
}
|
|
26839
26886
|
/** Stops the running turn: `session/cancel`, then the process if the agent does not stop. */
|
|
26840
26887
|
cancel() {
|
|
26841
26888
|
const turn = this.turn;
|
|
@@ -27021,6 +27068,7 @@ var AcpChatSession = class {
|
|
|
27021
27068
|
transcript.note(`\u4F1A\u8BDD ${wanted} \u5DF2\u53D6\u6D88\u5F52\u6863`);
|
|
27022
27069
|
this.session = await connection.openSaved(wanted, request.workdir, reopen);
|
|
27023
27070
|
}
|
|
27071
|
+
turn.reopened = wanted;
|
|
27024
27072
|
transcript.note(`\u7EE7\u7EED\u4F1A\u8BDD ${wanted}`);
|
|
27025
27073
|
return this.session;
|
|
27026
27074
|
} catch (error62) {
|
|
@@ -27094,6 +27142,7 @@ var AcpChatSession = class {
|
|
|
27094
27142
|
const sessionLevel = kind === "available_commands_update" || kind === "current_mode_update" || kind === "config_option_update";
|
|
27095
27143
|
if (this.session ? sessionId !== this.session.sessionId : !sessionLevel) return;
|
|
27096
27144
|
if (turn.loading && !sessionLevel) return;
|
|
27145
|
+
if (typeof kind === "string" && TURN_OUTPUT.has(kind)) turn.output = true;
|
|
27097
27146
|
const normalize = this.spec.dialect?.normalizeToolUpdate;
|
|
27098
27147
|
turn.transcript.update(normalize && (kind === "tool_call" || kind === "tool_call_update") ? normalize(update) : update);
|
|
27099
27148
|
}
|
|
@@ -28307,12 +28356,12 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
28307
28356
|
async prepareChatAttachments(payload) {
|
|
28308
28357
|
if (!payload.attachments?.length) return [];
|
|
28309
28358
|
if (!this.reporter.chatMedia) throw new Error("\u9644\u4EF6\u8F6C\u53D1\u672A\u914D\u7F6E");
|
|
28310
|
-
const directory =
|
|
28359
|
+
const directory = join20(this.config.dataDir, "chat-media", encodeURIComponent(payload.chat_session_id ?? payload.run_id));
|
|
28311
28360
|
await mkdir8(directory, { recursive: true, mode: 448 });
|
|
28312
28361
|
const files = [];
|
|
28313
28362
|
for (const attachment of payload.attachments) {
|
|
28314
28363
|
const name = basename3(attachment.name).replace(/[^\p{L}\p{N}._-]/gu, "_").slice(-120) || "attachment";
|
|
28315
|
-
const path =
|
|
28364
|
+
const path = join20(directory, `${encodeURIComponent(attachment.media_id)}-${name}`);
|
|
28316
28365
|
const existing = await stat6(path).catch(() => void 0);
|
|
28317
28366
|
if (!existing?.isFile()) {
|
|
28318
28367
|
const data = await this.reporter.chatMedia(payload.run_id, attachment.media_id);
|
|
@@ -28626,11 +28675,11 @@ var GatewayClient = class {
|
|
|
28626
28675
|
|
|
28627
28676
|
// src/workspace/directory-browser.ts
|
|
28628
28677
|
import { mkdir as mkdir9, readdir as readdir3, realpath as realpath3, stat as stat7 } from "node:fs/promises";
|
|
28629
|
-
import { homedir as
|
|
28678
|
+
import { homedir as homedir12 } from "node:os";
|
|
28630
28679
|
import { dirname as dirname9, isAbsolute as isAbsolute5, parse as parse3, resolve as resolve6 } from "node:path";
|
|
28631
28680
|
var MAX_ENTRIES = 1e3;
|
|
28632
28681
|
async function listDirectory(requested, allowedRoots) {
|
|
28633
|
-
const raw = requested.trim().replace(/^~(?=$|[\\/])/,
|
|
28682
|
+
const raw = requested.trim().replace(/^~(?=$|[\\/])/, homedir12()) || homedir12();
|
|
28634
28683
|
const directory = await realpath3(resolve6(raw)).catch(() => {
|
|
28635
28684
|
throw new Error(`\u76EE\u5F55\u4E0D\u5B58\u5728\uFF1A${requested}`);
|
|
28636
28685
|
});
|
|
@@ -28648,8 +28697,8 @@ async function listDirectory(requested, allowedRoots) {
|
|
|
28648
28697
|
else if (entry.isFile()) files.push(item);
|
|
28649
28698
|
}
|
|
28650
28699
|
const parent = dirname9(directory);
|
|
28651
|
-
const places = [{ label: "\u4E3B\u76EE\u5F55", path:
|
|
28652
|
-
for (const root2 of allowedRoots) if (root2 !==
|
|
28700
|
+
const places = [{ label: "\u4E3B\u76EE\u5F55", path: homedir12() }];
|
|
28701
|
+
for (const root2 of allowedRoots) if (root2 !== homedir12()) places.push({ label: "\u5141\u8BB8\u7684\u76EE\u5F55", path: root2 });
|
|
28653
28702
|
places.push({ label: "\u6839\u76EE\u5F55", path: process.platform === "win32" ? parse3(directory).root : "/" });
|
|
28654
28703
|
return {
|
|
28655
28704
|
path: directory,
|
|
@@ -28687,7 +28736,7 @@ async function createDirectory(parentRequested, name) {
|
|
|
28687
28736
|
// src/workspace/workspace-manager.ts
|
|
28688
28737
|
import { spawn as spawn13 } from "node:child_process";
|
|
28689
28738
|
import { opendir, realpath as realpath4, stat as stat8 } from "node:fs/promises";
|
|
28690
|
-
import { homedir as
|
|
28739
|
+
import { homedir as homedir13 } from "node:os";
|
|
28691
28740
|
import { isAbsolute as isAbsolute6, relative as relative3, resolve as resolve7 } from "node:path";
|
|
28692
28741
|
var MAX_NODES = 2e3;
|
|
28693
28742
|
var MAX_DIRECTORY_ENTRIES = 12e3;
|
|
@@ -28723,7 +28772,7 @@ var WorkspaceManager = class {
|
|
|
28723
28772
|
return { root_path: rootPath, nodes, truncated: nodes.length >= MAX_NODES, duration_ms: Date.now() - startedAt };
|
|
28724
28773
|
}
|
|
28725
28774
|
validateRootPath(value) {
|
|
28726
|
-
const raw = value.trim().replace(/^~(?=$|[\\/])/,
|
|
28775
|
+
const raw = value.trim().replace(/^~(?=$|[\\/])/, homedir13());
|
|
28727
28776
|
const root2 = resolve7(raw);
|
|
28728
28777
|
if (!isAbsolute6(raw)) throw new Error("\u6839\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");
|
|
28729
28778
|
if (relative3(root2, resolve7(root2, "..")) === "") throw new Error("\u4E0D\u80FD\u628A\u6587\u4EF6\u7CFB\u7EDF\u6839\u76EE\u5F55\u4F5C\u4E3A\u76EE\u5F55\u6839");
|
|
@@ -29063,7 +29112,7 @@ var AgentRuntime = class {
|
|
|
29063
29112
|
}
|
|
29064
29113
|
};
|
|
29065
29114
|
this.workspaces = new WorkspaceManager(config2, this.logger);
|
|
29066
|
-
this.orphans = new OrphanRegistry(
|
|
29115
|
+
this.orphans = new OrphanRegistry(join22(config2.dataDir, "active-runs.json"));
|
|
29067
29116
|
this.runs = new RunSupervisor(config2, this.logger, reporter, this.orphans);
|
|
29068
29117
|
}
|
|
29069
29118
|
config;
|
|
@@ -29768,7 +29817,7 @@ function errorMessage3(error62) {
|
|
|
29768
29817
|
}
|
|
29769
29818
|
|
|
29770
29819
|
// src/runtime/run-service.ts
|
|
29771
|
-
import { existsSync as
|
|
29820
|
+
import { existsSync as existsSync7, readFileSync as readFileSync7 } from "node:fs";
|
|
29772
29821
|
import { dirname as dirname10, resolve as resolve8 } from "node:path";
|
|
29773
29822
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
29774
29823
|
var PACKAGE_NAME = "toc-ocra";
|
|
@@ -29776,7 +29825,7 @@ function agentPackageRoot() {
|
|
|
29776
29825
|
let directory = dirname10(fileURLToPath2(import.meta.url));
|
|
29777
29826
|
while (true) {
|
|
29778
29827
|
const packagePath = resolve8(directory, "package.json");
|
|
29779
|
-
if (
|
|
29828
|
+
if (existsSync7(packagePath)) {
|
|
29780
29829
|
try {
|
|
29781
29830
|
const info = JSON.parse(readFileSync7(packagePath, "utf8"));
|
|
29782
29831
|
if (info.name === PACKAGE_NAME && typeof info.version === "string") return directory;
|
|
@@ -29846,8 +29895,8 @@ function preferSystemNode() {
|
|
|
29846
29895
|
const names = process.platform === "win32" ? ["node.exe"] : ["node"];
|
|
29847
29896
|
for (const directory of (process.env.PATH ?? "").split(delimiter5)) {
|
|
29848
29897
|
for (const name of names) {
|
|
29849
|
-
const candidate = directory &&
|
|
29850
|
-
if (candidate &&
|
|
29898
|
+
const candidate = directory && join23(directory, name);
|
|
29899
|
+
if (candidate && existsSync8(candidate)) {
|
|
29851
29900
|
process.env.TOC_OCRA_NODE_PATH = candidate;
|
|
29852
29901
|
return;
|
|
29853
29902
|
}
|