toc-ocra 0.3.18 → 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 +155 -110
- package/dist/service/agent.mjs +144 -99
- 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/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], {
|
|
@@ -21324,15 +21341,15 @@ function parseClaudeModelCatalog(settings, environment = process.env, fetchedAt
|
|
|
21324
21341
|
models: [...models2.values()]
|
|
21325
21342
|
};
|
|
21326
21343
|
}
|
|
21327
|
-
var claudeHome = () => process.env.CLAUDE_CONFIG_DIR?.trim() ||
|
|
21328
|
-
var codexHome2 = () => process.env.CODEX_HOME?.trim() ||
|
|
21329
|
-
var geminiHome = () => process.env.GEMINI_CLI_HOME?.trim() ||
|
|
21330
|
-
var grokHome = () => process.env.GROK_HOME?.trim() ||
|
|
21331
|
-
var opencodeHome = () =>
|
|
21332
|
-
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");
|
|
21333
21350
|
async function readClaudeModelCatalog() {
|
|
21334
21351
|
const home = claudeHome();
|
|
21335
|
-
const content = await readFile4(
|
|
21352
|
+
const content = await readFile4(join10(home, "settings.json"), "utf8").catch(() => "");
|
|
21336
21353
|
let settings = {};
|
|
21337
21354
|
if (content) {
|
|
21338
21355
|
try {
|
|
@@ -21390,13 +21407,13 @@ async function readCodexModels(codexHome3, config2) {
|
|
|
21390
21407
|
const configuredModels = parseCodexModels(await readFile4(catalogPath, "utf8").catch(() => ""));
|
|
21391
21408
|
if (configuredModels?.length) return configuredModels;
|
|
21392
21409
|
}
|
|
21393
|
-
const cached3 = parseCodexModels(await readFile4(
|
|
21410
|
+
const cached3 = parseCodexModels(await readFile4(join10(codexHome3, "models_cache.json"), "utf8").catch(() => ""));
|
|
21394
21411
|
if (cached3?.length) return cached3;
|
|
21395
21412
|
return codexModelsFrom(await codexBundledCatalog().catch(() => void 0), { listedOnly: true }) ?? [];
|
|
21396
21413
|
}
|
|
21397
21414
|
async function readCodexModelCatalog() {
|
|
21398
21415
|
const home = codexHome2();
|
|
21399
|
-
const config2 = await readFile4(
|
|
21416
|
+
const config2 = await readFile4(join10(home, "config.toml"), "utf8").catch(() => "");
|
|
21400
21417
|
const models2 = await readCodexModels(home, config2);
|
|
21401
21418
|
const defaultModel = configValue(config2, "model");
|
|
21402
21419
|
const defaultReasoningEffort = configValue(config2, "model_reasoning_effort");
|
|
@@ -21510,7 +21527,7 @@ async function readKiroModelCatalog(options = {}) {
|
|
|
21510
21527
|
if (current) return known.catalog;
|
|
21511
21528
|
try {
|
|
21512
21529
|
const launch = launchCli({ spec: kiro, args: ["acp", "--trust-tools="], env: environment });
|
|
21513
|
-
const catalog = await readKiroNativeModels(launch,
|
|
21530
|
+
const catalog = await readKiroNativeModels(launch, homedir7(), { catalog: base });
|
|
21514
21531
|
kiroEfforts = { signature, readAt: Date.now(), catalog };
|
|
21515
21532
|
return catalog;
|
|
21516
21533
|
} catch {
|
|
@@ -21519,7 +21536,7 @@ async function readKiroModelCatalog(options = {}) {
|
|
|
21519
21536
|
};
|
|
21520
21537
|
const [payload, content] = await Promise.all([
|
|
21521
21538
|
readEfforts(),
|
|
21522
|
-
readFile4(
|
|
21539
|
+
readFile4(join10(kiroHome(), "settings", "cli.json"), "utf8").catch(() => "{}")
|
|
21523
21540
|
]);
|
|
21524
21541
|
let settings;
|
|
21525
21542
|
try {
|
|
@@ -21576,7 +21593,7 @@ function geminiModelsUrl(baseUrl) {
|
|
|
21576
21593
|
}
|
|
21577
21594
|
async function readGeminiModelCatalog() {
|
|
21578
21595
|
const fileEnvironment = parseEnvFile(
|
|
21579
|
-
await readFile4(
|
|
21596
|
+
await readFile4(join10(geminiHome(), ".env"), "utf8").catch(() => "")
|
|
21580
21597
|
);
|
|
21581
21598
|
const environment = { ...fileEnvironment, ...process.env };
|
|
21582
21599
|
const baseUrl = environment.GOOGLE_GEMINI_BASE_URL?.trim();
|
|
@@ -21621,7 +21638,7 @@ function parseGrokModelCatalog(output2, config2 = "", fetchedAt = (/* @__PURE__
|
|
|
21621
21638
|
return catalog;
|
|
21622
21639
|
}
|
|
21623
21640
|
async function readGrokModelCatalog() {
|
|
21624
|
-
const config2 = await readFile4(
|
|
21641
|
+
const config2 = await readFile4(join10(grokHome(), "config.toml"), "utf8").catch(() => "");
|
|
21625
21642
|
const output2 = await runModelListCommand(cliExecutable("grok"), ["models"], "grok");
|
|
21626
21643
|
const catalog = parseGrokModelCatalog(output2, config2);
|
|
21627
21644
|
if (catalog.models.length === 0) throw new Error("Grok \u672C\u673A\u672A\u8FD4\u56DE\u53EF\u7528\u6A21\u578B");
|
|
@@ -21640,7 +21657,7 @@ function parseOpencodeModelCatalog(output2, config2 = "", fetchedAt = (/* @__PUR
|
|
|
21640
21657
|
return catalog;
|
|
21641
21658
|
}
|
|
21642
21659
|
async function readOpencodeModelCatalog() {
|
|
21643
|
-
const config2 = await readFile4(
|
|
21660
|
+
const config2 = await readFile4(join10(opencodeHome(), "opencode.json"), "utf8").catch(() => "") || await readFile4(join10(opencodeHome(), "opencode.jsonc"), "utf8").catch(() => "");
|
|
21644
21661
|
const output2 = await runModelListCommand(cliExecutable("opencode"), ["models"], "opencode");
|
|
21645
21662
|
const catalog = parseOpencodeModelCatalog(output2, config2);
|
|
21646
21663
|
if (catalog.models.length === 0) throw new Error("OpenCode \u672C\u673A\u672A\u8FD4\u56DE\u53EF\u7528\u6A21\u578B");
|
|
@@ -21648,22 +21665,22 @@ async function readOpencodeModelCatalog() {
|
|
|
21648
21665
|
}
|
|
21649
21666
|
var TEN_MINUTES = 10 * 60 * 1e3;
|
|
21650
21667
|
var MODEL_SOURCES = {
|
|
21651
|
-
claude: { read: readClaudeModelCatalog, watchFiles: () => [
|
|
21668
|
+
claude: { read: readClaudeModelCatalog, watchFiles: () => [join10(claudeHome(), "settings.json")] },
|
|
21652
21669
|
codex: {
|
|
21653
21670
|
read: readCodexModelCatalog,
|
|
21654
21671
|
watchFiles: () => {
|
|
21655
21672
|
const home = codexHome2();
|
|
21656
|
-
return [
|
|
21673
|
+
return [join10(home, "config.toml"), join10(home, "models_cache.json")];
|
|
21657
21674
|
},
|
|
21658
21675
|
// model_catalog_json may point anywhere; a periodic re-read covers it.
|
|
21659
21676
|
refreshEveryMs: TEN_MINUTES
|
|
21660
21677
|
},
|
|
21661
|
-
gemini: { read: readGeminiModelCatalog, watchFiles: () => [
|
|
21662
|
-
grok: { read: readGrokModelCatalog, watchFiles: () => [
|
|
21663
|
-
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")] },
|
|
21664
21681
|
opencode: {
|
|
21665
21682
|
read: readOpencodeModelCatalog,
|
|
21666
|
-
watchFiles: () => [
|
|
21683
|
+
watchFiles: () => [join10(opencodeHome(), "opencode.json"), join10(opencodeHome(), "opencode.jsonc")],
|
|
21667
21684
|
refreshEveryMs: TEN_MINUTES
|
|
21668
21685
|
}
|
|
21669
21686
|
};
|
|
@@ -21777,11 +21794,11 @@ function classifySpawnError(error62, context) {
|
|
|
21777
21794
|
|
|
21778
21795
|
// src/providers/cli/kiro-session-log.ts
|
|
21779
21796
|
import { open as open2, readdir, readFile as readFile5, stat as stat2 } from "node:fs/promises";
|
|
21780
|
-
import { homedir as
|
|
21781
|
-
import { join as
|
|
21797
|
+
import { homedir as homedir8 } from "node:os";
|
|
21798
|
+
import { join as join11 } from "node:path";
|
|
21782
21799
|
var SHELL_TOOLS = /* @__PURE__ */ new Set(["shell", "execute_bash", "bash"]);
|
|
21783
21800
|
function kiroSessionsDirectory() {
|
|
21784
|
-
return process.env.TOC_OCRA_KIRO_SESSIONS_DIR ||
|
|
21801
|
+
return process.env.TOC_OCRA_KIRO_SESSIONS_DIR || join11(homedir8(), ".kiro", "sessions", "cli");
|
|
21785
21802
|
}
|
|
21786
21803
|
var KiroSessionLog = class {
|
|
21787
21804
|
constructor(options) {
|
|
@@ -21800,7 +21817,7 @@ var KiroSessionLog = class {
|
|
|
21800
21817
|
/** Called before the CLI starts: a resumed log is followed from its current end. */
|
|
21801
21818
|
async begin() {
|
|
21802
21819
|
if (!this.options.sessionId) return;
|
|
21803
|
-
this.path =
|
|
21820
|
+
this.path = join11(this.directory, `${this.options.sessionId}.jsonl`);
|
|
21804
21821
|
this.offset = await stat2(this.path).then((info) => info.size, () => 0);
|
|
21805
21822
|
}
|
|
21806
21823
|
/**
|
|
@@ -21813,11 +21830,11 @@ var KiroSessionLog = class {
|
|
|
21813
21830
|
const found = [];
|
|
21814
21831
|
for (const name of names) {
|
|
21815
21832
|
if (!name.endsWith(".json")) continue;
|
|
21816
|
-
const meta3 = await readFile5(
|
|
21833
|
+
const meta3 = await readFile5(join11(this.directory, name), "utf8").then((text3) => JSON.parse(text3), () => void 0);
|
|
21817
21834
|
const created = meta3?.created_at ? Date.parse(meta3.created_at) : NaN;
|
|
21818
21835
|
if (meta3?.cwd && sameFolder(meta3.cwd, this.options.workdir) && created >= this.options.startedAt - 2e3) found.push(name.slice(0, -5));
|
|
21819
21836
|
}
|
|
21820
|
-
if (found.length === 1) this.path =
|
|
21837
|
+
if (found.length === 1) this.path = join11(this.directory, `${found[0]}.jsonl`);
|
|
21821
21838
|
}
|
|
21822
21839
|
/** Reads entries appended since the last call. */
|
|
21823
21840
|
async refresh() {
|
|
@@ -22186,9 +22203,9 @@ var OPENCODE_ACP_DIALECT = {
|
|
|
22186
22203
|
// src/acp/vendor.ts
|
|
22187
22204
|
import { spawn as spawn6 } from "node:child_process";
|
|
22188
22205
|
import { createHash } from "node:crypto";
|
|
22189
|
-
import { existsSync as
|
|
22206
|
+
import { existsSync as existsSync6, readFileSync as readFileSync5 } from "node:fs";
|
|
22190
22207
|
import { copyFile, mkdir as mkdir4, rename as rename4, rm as rm2, writeFile as writeFile4 } from "node:fs/promises";
|
|
22191
|
-
import { dirname as dirname7, join as
|
|
22208
|
+
import { dirname as dirname7, join as join12, resolve as resolve4 } from "node:path";
|
|
22192
22209
|
import { fileURLToPath } from "node:url";
|
|
22193
22210
|
var AcpRuntimeUnavailable = class extends Error {
|
|
22194
22211
|
constructor(message) {
|
|
@@ -22201,7 +22218,7 @@ function packageRoot() {
|
|
|
22201
22218
|
let directory = dirname7(fileURLToPath(import.meta.url));
|
|
22202
22219
|
while (true) {
|
|
22203
22220
|
const path = resolve4(directory, "package.json");
|
|
22204
|
-
if (
|
|
22221
|
+
if (existsSync6(path)) {
|
|
22205
22222
|
try {
|
|
22206
22223
|
if (JSON.parse(readFileSync5(path, "utf8")).name === "toc-ocra") return directory;
|
|
22207
22224
|
} catch {
|
|
@@ -22221,21 +22238,21 @@ function agentPackageVersion() {
|
|
|
22221
22238
|
const directory = agentRoot();
|
|
22222
22239
|
if (!directory) return "0";
|
|
22223
22240
|
try {
|
|
22224
|
-
return JSON.parse(readFileSync5(
|
|
22241
|
+
return JSON.parse(readFileSync5(join12(directory, "package.json"), "utf8")).version ?? "0";
|
|
22225
22242
|
} catch {
|
|
22226
22243
|
return "0";
|
|
22227
22244
|
}
|
|
22228
22245
|
}
|
|
22229
22246
|
function vendoredAdapter(name) {
|
|
22230
22247
|
const directory = agentRoot();
|
|
22231
|
-
const entry = directory ?
|
|
22232
|
-
return entry &&
|
|
22248
|
+
const entry = directory ? join12(directory, "assets", "acp", name, "index.mjs") : void 0;
|
|
22249
|
+
return entry && existsSync6(entry) ? entry : void 0;
|
|
22233
22250
|
}
|
|
22234
22251
|
var installs = /* @__PURE__ */ new Map();
|
|
22235
22252
|
function ensureClaudeRuntime(dataDir2) {
|
|
22236
22253
|
const entry = vendoredAdapter("claude");
|
|
22237
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"));
|
|
22238
|
-
const manifestPath =
|
|
22255
|
+
const manifestPath = join12(dirname7(entry), "runtime.json");
|
|
22239
22256
|
let manifest;
|
|
22240
22257
|
try {
|
|
22241
22258
|
manifest = JSON.parse(readFileSync5(manifestPath, "utf8"));
|
|
@@ -22243,7 +22260,7 @@ function ensureClaudeRuntime(dataDir2) {
|
|
|
22243
22260
|
return Promise.reject(new AcpRuntimeUnavailable("Claude ACP \u9002\u914D\u5668\u7F3A\u5C11 runtime.json"));
|
|
22244
22261
|
}
|
|
22245
22262
|
const hash2 = createHash("sha256").update(readFileSync5(entry)).digest("hex").slice(0, 12);
|
|
22246
|
-
const directory =
|
|
22263
|
+
const directory = join12(dataDir2, "acp-runtimes", `claude-${manifest.adapterVersion}-sdk-${manifest.sdk.version}-${hash2}`);
|
|
22247
22264
|
const existing = installs.get(directory);
|
|
22248
22265
|
if (existing) return existing;
|
|
22249
22266
|
const install = installClaudeRuntime(directory, entry, manifest).catch((error62) => {
|
|
@@ -22254,19 +22271,19 @@ function ensureClaudeRuntime(dataDir2) {
|
|
|
22254
22271
|
return install;
|
|
22255
22272
|
}
|
|
22256
22273
|
async function installClaudeRuntime(directory, entry, manifest) {
|
|
22257
|
-
const sdkPackage =
|
|
22258
|
-
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;
|
|
22259
22276
|
const temporary = `${directory}.tmp-${process.pid}-${Date.now()}`;
|
|
22260
22277
|
await mkdir4(temporary, { recursive: true, mode: 448 });
|
|
22261
22278
|
try {
|
|
22262
|
-
await writeFile4(
|
|
22279
|
+
await writeFile4(join12(temporary, "package.json"), JSON.stringify({
|
|
22263
22280
|
name: "toc-ocra-claude-acp-runtime",
|
|
22264
22281
|
private: true,
|
|
22265
22282
|
type: "module",
|
|
22266
22283
|
dependencies: { [manifest.sdk.name]: manifest.sdk.version }
|
|
22267
22284
|
}, null, 2));
|
|
22268
22285
|
await runNpm(["install", "--omit=optional", "--no-audit", "--no-fund", "--no-package-lock", "--loglevel=error"], temporary);
|
|
22269
|
-
await copyFile(entry,
|
|
22286
|
+
await copyFile(entry, join12(temporary, "index.mjs"));
|
|
22270
22287
|
await rm2(directory, { recursive: true, force: true });
|
|
22271
22288
|
await rename4(temporary, directory);
|
|
22272
22289
|
} catch (error62) {
|
|
@@ -22389,13 +22406,15 @@ var CLAUDE_LAUNCH_SPEC = {
|
|
|
22389
22406
|
const executable = installedCli(claude);
|
|
22390
22407
|
const runtime = await ensureClaudeRuntime(dataDir2);
|
|
22391
22408
|
return {
|
|
22392
|
-
launch: { executable: process.execPath, args: [
|
|
22409
|
+
launch: { executable: process.execPath, args: [join13(runtime, "index.mjs")], env: { ...providerEnvironment(), CLAUDE_CODE_EXECUTABLE: executable }, cwd: workdir },
|
|
22393
22410
|
fingerprint: `claude:${runtime}:${executable}`
|
|
22394
22411
|
};
|
|
22395
22412
|
},
|
|
22396
22413
|
// Manual mode asks for every edit and command; the user or the level's policy answers.
|
|
22397
22414
|
permissionModeConfig: { values: { ask: "default", acceptEdits: "acceptEdits", bypassPermissions: "bypassPermissions", plan: "plan" } },
|
|
22398
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()),
|
|
22399
22418
|
dialect: { failureRules: [{ kind: "sessionMissing", pattern: /No conversation found with session ID|session[^\n]{0,40}not found/i }] },
|
|
22400
22419
|
modelDiscovery: { kind: "reader", source: MODEL_SOURCES.claude }
|
|
22401
22420
|
};
|
|
@@ -22506,7 +22525,7 @@ var ACP_CHAT_IDS = [...ACP_CHAT.keys()];
|
|
|
22506
22525
|
// src/acp/acp-model-catalog-probe.ts
|
|
22507
22526
|
import { mkdtemp, rm as rm3 } from "node:fs/promises";
|
|
22508
22527
|
import { tmpdir } from "node:os";
|
|
22509
|
-
import { join as
|
|
22528
|
+
import { join as join14 } from "node:path";
|
|
22510
22529
|
|
|
22511
22530
|
// src/acp/acp-options.ts
|
|
22512
22531
|
var text = (value) => typeof value === "string" && value ? value : void 0;
|
|
@@ -23139,9 +23158,9 @@ async function readSessionModels(row, clientVersion = "1") {
|
|
|
23139
23158
|
const discovery = row.modelDiscovery;
|
|
23140
23159
|
if (discovery.kind !== "session") throw new Error(`${row.agent} does not list its models in a session`);
|
|
23141
23160
|
const cli = requireCliSpec(row.agent);
|
|
23142
|
-
const folder = await mkdtemp(
|
|
23161
|
+
const folder = await mkdtemp(join14(tmpdir(), `toc-ocra-acp-models-${row.agent}-`));
|
|
23143
23162
|
try {
|
|
23144
|
-
const folderArgs = discovery.sessionFolderArgs?.(
|
|
23163
|
+
const folderArgs = discovery.sessionFolderArgs?.(join14(folder, "sessions")) ?? [];
|
|
23145
23164
|
const args = [...row.args({ access: "read-only", model: "", reasoningEffort: "" }), ...folderArgs];
|
|
23146
23165
|
const launch = launchCli({ spec: cli, args, env: { ...providerEnvironment(), ...row.env } });
|
|
23147
23166
|
const connection = await AcpConnection.open({ executable: launch.executable, args: launch.args, env: launch.env, cwd: folder }, {
|
|
@@ -23770,14 +23789,14 @@ function isWriterConflict(message) {
|
|
|
23770
23789
|
}
|
|
23771
23790
|
|
|
23772
23791
|
// src/providers/cli/claude.ts
|
|
23773
|
-
import { readdirSync as
|
|
23774
|
-
import { homedir as
|
|
23775
|
-
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";
|
|
23776
23795
|
var CLAUDE = requireCliSpec("claude");
|
|
23777
23796
|
function claudeProjectRoots() {
|
|
23778
23797
|
const configured = process.env.CLAUDE_CONFIG_DIR;
|
|
23779
|
-
const dirs = configured ? configured.split(process.platform === "win32" ? ";" : ":").map((entry) => entry.trim()).filter(Boolean) : [
|
|
23780
|
-
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"));
|
|
23781
23800
|
}
|
|
23782
23801
|
function claudeTranscriptExists(sessionId) {
|
|
23783
23802
|
return claudeTranscriptPath(sessionId) !== void 0;
|
|
@@ -23787,13 +23806,13 @@ function claudeTranscriptPath(sessionId) {
|
|
|
23787
23806
|
for (const root2 of claudeProjectRoots()) {
|
|
23788
23807
|
let projects;
|
|
23789
23808
|
try {
|
|
23790
|
-
projects =
|
|
23809
|
+
projects = readdirSync4(root2);
|
|
23791
23810
|
} catch {
|
|
23792
23811
|
continue;
|
|
23793
23812
|
}
|
|
23794
23813
|
for (const project of projects) {
|
|
23795
23814
|
try {
|
|
23796
|
-
if (
|
|
23815
|
+
if (readdirSync4(join15(root2, project)).includes(file2)) return join15(root2, project, file2);
|
|
23797
23816
|
} catch {
|
|
23798
23817
|
}
|
|
23799
23818
|
}
|
|
@@ -23837,7 +23856,7 @@ var claudeProvider = {
|
|
|
23837
23856
|
settings.disableAllHooks = true;
|
|
23838
23857
|
args.push("--restricted", "--permission-mode", "plan", "--tools", "Read,Glob,Grep", "--strict-mcp-config", "--mcp-config", '{"mcpServers":{}}', "--disallowedTools", "mcp__*");
|
|
23839
23858
|
try {
|
|
23840
|
-
const userSettings = JSON.parse(readFileSync6(
|
|
23859
|
+
const userSettings = JSON.parse(readFileSync6(join15(homedir9(), ".claude", "settings.json"), "utf8"));
|
|
23841
23860
|
for (const [key, value] of Object.entries(userSettings.env ?? {})) {
|
|
23842
23861
|
if (/^ANTHROPIC_[A-Z0-9_]+$/.test(key) && typeof value === "string" && env[key] === void 0) env[key] = value;
|
|
23843
23862
|
}
|
|
@@ -25007,7 +25026,7 @@ var cliDetection = new CliDetectionService();
|
|
|
25007
25026
|
|
|
25008
25027
|
// src/runtime/agent-runtime.ts
|
|
25009
25028
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
25010
|
-
import { join as
|
|
25029
|
+
import { join as join22 } from "node:path";
|
|
25011
25030
|
|
|
25012
25031
|
// src/exec/script-runner.ts
|
|
25013
25032
|
import { spawn as spawn10 } from "node:child_process";
|
|
@@ -25296,15 +25315,15 @@ async function readCLIQuotaReport(agentType) {
|
|
|
25296
25315
|
|
|
25297
25316
|
// src/providers/tb-switch-control.ts
|
|
25298
25317
|
import { readFile as readFile6 } from "node:fs/promises";
|
|
25299
|
-
import { homedir as
|
|
25300
|
-
import { join as
|
|
25318
|
+
import { homedir as homedir10 } from "node:os";
|
|
25319
|
+
import { join as join16 } from "node:path";
|
|
25301
25320
|
function dataDir() {
|
|
25302
|
-
return process.env.TB_SWITCH_HOME?.trim() ||
|
|
25321
|
+
return process.env.TB_SWITCH_HOME?.trim() || join16(homedir10(), ".tb-switch");
|
|
25303
25322
|
}
|
|
25304
25323
|
async function readLocalService() {
|
|
25305
25324
|
let discovery;
|
|
25306
25325
|
try {
|
|
25307
|
-
discovery = JSON.parse(await readFile6(
|
|
25326
|
+
discovery = JSON.parse(await readFile6(join16(dataDir(), "api.json"), "utf8"));
|
|
25308
25327
|
} catch {
|
|
25309
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");
|
|
25310
25329
|
}
|
|
@@ -25320,7 +25339,7 @@ async function readLocalService() {
|
|
|
25320
25339
|
}
|
|
25321
25340
|
let token = process.env.TB_SWITCH_API_TOKEN?.trim() ?? "";
|
|
25322
25341
|
try {
|
|
25323
|
-
token = (await readFile6(
|
|
25342
|
+
token = (await readFile6(join16(dataDir(), "api-token"), "utf8")).trim();
|
|
25324
25343
|
} catch {
|
|
25325
25344
|
}
|
|
25326
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");
|
|
@@ -25465,7 +25484,7 @@ function commandOf(pid) {
|
|
|
25465
25484
|
// src/runs/run-supervisor.ts
|
|
25466
25485
|
import { spawn as spawn12 } from "node:child_process";
|
|
25467
25486
|
import { mkdir as mkdir8, realpath as realpath2, stat as stat6, writeFile as writeFile8 } from "node:fs/promises";
|
|
25468
|
-
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";
|
|
25469
25488
|
import { createInterface as createInterface5 } from "node:readline";
|
|
25470
25489
|
|
|
25471
25490
|
// src/session/terminal-tail-buffer.ts
|
|
@@ -25827,19 +25846,19 @@ async function forkCodexThread(options) {
|
|
|
25827
25846
|
|
|
25828
25847
|
// src/runs/run-recorder.ts
|
|
25829
25848
|
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3 } from "node:fs";
|
|
25830
|
-
import { homedir as
|
|
25831
|
-
import { join as
|
|
25849
|
+
import { homedir as homedir11 } from "node:os";
|
|
25850
|
+
import { join as join17 } from "node:path";
|
|
25832
25851
|
var RunRecorder = class _RunRecorder {
|
|
25833
25852
|
constructor(path) {
|
|
25834
25853
|
this.path = path;
|
|
25835
25854
|
}
|
|
25836
25855
|
path;
|
|
25837
|
-
home =
|
|
25856
|
+
home = homedir11();
|
|
25838
25857
|
static fromEnvironment(runId, meta3) {
|
|
25839
25858
|
const directory = process.env.TOC_OCRA_RECORD_DIR?.trim();
|
|
25840
25859
|
if (!directory) return void 0;
|
|
25841
25860
|
mkdirSync3(directory, { recursive: true });
|
|
25842
|
-
const recorder = new _RunRecorder(
|
|
25861
|
+
const recorder = new _RunRecorder(join17(directory, `${String(meta3.agent ?? "cli")}-${runId}.jsonl`));
|
|
25843
25862
|
recorder.write({ meta: meta3 });
|
|
25844
25863
|
return recorder;
|
|
25845
25864
|
}
|
|
@@ -25855,7 +25874,7 @@ var RunRecorder = class _RunRecorder {
|
|
|
25855
25874
|
|
|
25856
25875
|
// src/runs/run-transcript.ts
|
|
25857
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";
|
|
25858
|
-
import { join as
|
|
25877
|
+
import { join as join18 } from "node:path";
|
|
25859
25878
|
var MAX_TRANSCRIPT_ITEMS = 5e3;
|
|
25860
25879
|
var MAX_TRANSCRIPT_TEXT = 2e5;
|
|
25861
25880
|
var MAX_TRANSCRIPT_LINES = 2e4;
|
|
@@ -26120,7 +26139,7 @@ function transcriptFileName(runId) {
|
|
|
26120
26139
|
var TranscriptStore = class {
|
|
26121
26140
|
constructor(dataDir2, logger, env = process.env) {
|
|
26122
26141
|
this.logger = logger;
|
|
26123
|
-
this.directory = dataDir2 ?
|
|
26142
|
+
this.directory = dataDir2 ? join18(dataDir2, "transcripts") : "";
|
|
26124
26143
|
this.enabled = Boolean(dataDir2) && transcriptsOnDisk(env);
|
|
26125
26144
|
}
|
|
26126
26145
|
logger;
|
|
@@ -26175,7 +26194,7 @@ var TranscriptStore = class {
|
|
|
26175
26194
|
await this.writes.get(runId);
|
|
26176
26195
|
let text3;
|
|
26177
26196
|
try {
|
|
26178
|
-
text3 = await readFile8(
|
|
26197
|
+
text3 = await readFile8(join18(this.directory, name), "utf8");
|
|
26179
26198
|
} catch (error62) {
|
|
26180
26199
|
if (errorCode(error62) !== "ENOENT") this.logger.warn("run-transcript-read-failed", { runId, error: errorMessage(error62) });
|
|
26181
26200
|
return void 0;
|
|
@@ -26240,7 +26259,7 @@ var TranscriptStore = class {
|
|
|
26240
26259
|
transcript.dirty = false;
|
|
26241
26260
|
const body = JSON.stringify(transcript.toFile());
|
|
26242
26261
|
await this.ensureDirectory();
|
|
26243
|
-
const file2 =
|
|
26262
|
+
const file2 = join18(this.directory, name);
|
|
26244
26263
|
const temporary = `${file2}.${process.pid}.tmp`;
|
|
26245
26264
|
await writeFile6(temporary, body, { mode: 384 });
|
|
26246
26265
|
await rename6(temporary, file2);
|
|
@@ -26277,7 +26296,7 @@ var TranscriptStore = class {
|
|
|
26277
26296
|
const now = Date.now();
|
|
26278
26297
|
const files = [];
|
|
26279
26298
|
for (const name of names) {
|
|
26280
|
-
const path =
|
|
26299
|
+
const path = join18(this.directory, name);
|
|
26281
26300
|
if (name.endsWith(".tmp")) {
|
|
26282
26301
|
const info2 = await stat4(path).catch(() => void 0);
|
|
26283
26302
|
if (info2?.isFile() && now - info2.mtimeMs > STALE_TEMPORARY_MS) await unlink(path).catch(() => void 0);
|
|
@@ -26327,7 +26346,7 @@ function errorMessage(error62) {
|
|
|
26327
26346
|
import { createHash as createHash3, randomUUID as randomUUID2 } from "node:crypto";
|
|
26328
26347
|
import { constants as constants2 } from "node:fs";
|
|
26329
26348
|
import { lstat, mkdir as mkdir7, open as open3, realpath, rename as rename7, rm as rm4, writeFile as writeFile7 } from "node:fs/promises";
|
|
26330
|
-
import { basename as basename2, isAbsolute as isAbsolute3, join as
|
|
26349
|
+
import { basename as basename2, isAbsolute as isAbsolute3, join as join19, relative } from "node:path";
|
|
26331
26350
|
function within(root2, path) {
|
|
26332
26351
|
const segment = relative(root2, path);
|
|
26333
26352
|
return segment === "" || !segment.startsWith("..") && !isAbsolute3(segment);
|
|
@@ -26335,7 +26354,7 @@ function within(root2, path) {
|
|
|
26335
26354
|
async function attachmentDirectory(workdir, messageId) {
|
|
26336
26355
|
let directory = workdir;
|
|
26337
26356
|
for (const segment of [".echo", "attachments", `message-${encodeURIComponent(messageId).slice(0, 180)}`]) {
|
|
26338
|
-
directory =
|
|
26357
|
+
directory = join19(directory, segment);
|
|
26339
26358
|
await mkdir7(directory, { mode: 448 }).catch((error62) => {
|
|
26340
26359
|
if (error62.code !== "EEXIST") throw error62;
|
|
26341
26360
|
});
|
|
@@ -26343,7 +26362,7 @@ async function attachmentDirectory(workdir, messageId) {
|
|
|
26343
26362
|
if (metadata.isSymbolicLink() || !metadata.isDirectory() || !within(workdir, await realpath(directory))) {
|
|
26344
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");
|
|
26345
26364
|
}
|
|
26346
|
-
if (segment === ".echo") await writeFile7(
|
|
26365
|
+
if (segment === ".echo") await writeFile7(join19(directory, ".gitignore"), "*\n", { flag: "wx", mode: 384 }).catch((error62) => {
|
|
26347
26366
|
if (error62.code !== "EEXIST") throw error62;
|
|
26348
26367
|
});
|
|
26349
26368
|
}
|
|
@@ -26380,9 +26399,9 @@ async function prepareTaskAttachments(payload, workdir, download, signal2) {
|
|
|
26380
26399
|
const characters = Array.from(basename2(file2.name.replace(/\\/g, "/")).replace(/[^\p{L}\p{N}._-]/gu, "_").replace(/\.+$/u, ""));
|
|
26381
26400
|
while (Buffer.byteLength(characters.join("")) > 160) characters.shift();
|
|
26382
26401
|
const name = characters.join("") || "attachment";
|
|
26383
|
-
const path =
|
|
26402
|
+
const path = join19(directory, `${file2.file_id}-${name}`);
|
|
26384
26403
|
if (!await matches(path, file2.size, file2.sha256, signal2)) {
|
|
26385
|
-
const temporary =
|
|
26404
|
+
const temporary = join19(directory, `.download-${file2.file_id}-${randomUUID2()}.part`);
|
|
26386
26405
|
try {
|
|
26387
26406
|
await download(payload.run_id, file2.file_id, temporary, file2.size, file2.sha256, signal2);
|
|
26388
26407
|
signal2.throwIfAborted();
|
|
@@ -26782,6 +26801,7 @@ var QUESTION_OPTIONS = [
|
|
|
26782
26801
|
{ optionId: "answer", name: "Submit answers", kind: "allow_once" },
|
|
26783
26802
|
{ optionId: "cancel", name: "Cancel", kind: "reject_once" }
|
|
26784
26803
|
];
|
|
26804
|
+
var TURN_OUTPUT = /* @__PURE__ */ new Set(["agent_message_chunk", "agent_thought_chunk", "tool_call", "tool_call_update", "plan"]);
|
|
26785
26805
|
var CANCEL_GRACE_MS = 1e4;
|
|
26786
26806
|
var MAX_IMAGE_BYTES = 10 * 1024 * 1024;
|
|
26787
26807
|
var IMAGE_TYPES = { ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".webp": "image/webp" };
|
|
@@ -26814,14 +26834,15 @@ var AcpChatSession = class {
|
|
|
26814
26834
|
this.clearIdle();
|
|
26815
26835
|
this.lastUsedAt = Date.now();
|
|
26816
26836
|
const transcript = new TurnTranscript((events) => sink.events(events), (rows) => sink.rows(rows));
|
|
26817
|
-
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 };
|
|
26818
26838
|
this.turn = turn;
|
|
26819
26839
|
for (const note of request.notes) transcript.note(note);
|
|
26820
26840
|
let result;
|
|
26821
26841
|
try {
|
|
26822
26842
|
result = await this.execute(turn, launch);
|
|
26823
26843
|
} catch (error62) {
|
|
26824
|
-
|
|
26844
|
+
const failure2 = this.classify(error62);
|
|
26845
|
+
result = this.startsFresh(turn, failure2) ? await this.runFresh(turn, launch) : this.failed(turn, failure2);
|
|
26825
26846
|
} finally {
|
|
26826
26847
|
if (turn.cancelTimer) clearTimeout(turn.cancelTimer);
|
|
26827
26848
|
}
|
|
@@ -26840,6 +26861,28 @@ var AcpChatSession = class {
|
|
|
26840
26861
|
this.scheduleIdle();
|
|
26841
26862
|
return result;
|
|
26842
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
|
+
}
|
|
26843
26886
|
/** Stops the running turn: `session/cancel`, then the process if the agent does not stop. */
|
|
26844
26887
|
cancel() {
|
|
26845
26888
|
const turn = this.turn;
|
|
@@ -27025,6 +27068,7 @@ var AcpChatSession = class {
|
|
|
27025
27068
|
transcript.note(`\u4F1A\u8BDD ${wanted} \u5DF2\u53D6\u6D88\u5F52\u6863`);
|
|
27026
27069
|
this.session = await connection.openSaved(wanted, request.workdir, reopen);
|
|
27027
27070
|
}
|
|
27071
|
+
turn.reopened = wanted;
|
|
27028
27072
|
transcript.note(`\u7EE7\u7EED\u4F1A\u8BDD ${wanted}`);
|
|
27029
27073
|
return this.session;
|
|
27030
27074
|
} catch (error62) {
|
|
@@ -27098,6 +27142,7 @@ var AcpChatSession = class {
|
|
|
27098
27142
|
const sessionLevel = kind === "available_commands_update" || kind === "current_mode_update" || kind === "config_option_update";
|
|
27099
27143
|
if (this.session ? sessionId !== this.session.sessionId : !sessionLevel) return;
|
|
27100
27144
|
if (turn.loading && !sessionLevel) return;
|
|
27145
|
+
if (typeof kind === "string" && TURN_OUTPUT.has(kind)) turn.output = true;
|
|
27101
27146
|
const normalize = this.spec.dialect?.normalizeToolUpdate;
|
|
27102
27147
|
turn.transcript.update(normalize && (kind === "tool_call" || kind === "tool_call_update") ? normalize(update) : update);
|
|
27103
27148
|
}
|
|
@@ -28311,12 +28356,12 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
28311
28356
|
async prepareChatAttachments(payload) {
|
|
28312
28357
|
if (!payload.attachments?.length) return [];
|
|
28313
28358
|
if (!this.reporter.chatMedia) throw new Error("\u9644\u4EF6\u8F6C\u53D1\u672A\u914D\u7F6E");
|
|
28314
|
-
const directory =
|
|
28359
|
+
const directory = join20(this.config.dataDir, "chat-media", encodeURIComponent(payload.chat_session_id ?? payload.run_id));
|
|
28315
28360
|
await mkdir8(directory, { recursive: true, mode: 448 });
|
|
28316
28361
|
const files = [];
|
|
28317
28362
|
for (const attachment of payload.attachments) {
|
|
28318
28363
|
const name = basename3(attachment.name).replace(/[^\p{L}\p{N}._-]/gu, "_").slice(-120) || "attachment";
|
|
28319
|
-
const path =
|
|
28364
|
+
const path = join20(directory, `${encodeURIComponent(attachment.media_id)}-${name}`);
|
|
28320
28365
|
const existing = await stat6(path).catch(() => void 0);
|
|
28321
28366
|
if (!existing?.isFile()) {
|
|
28322
28367
|
const data = await this.reporter.chatMedia(payload.run_id, attachment.media_id);
|
|
@@ -28630,11 +28675,11 @@ var GatewayClient = class {
|
|
|
28630
28675
|
|
|
28631
28676
|
// src/workspace/directory-browser.ts
|
|
28632
28677
|
import { mkdir as mkdir9, readdir as readdir3, realpath as realpath3, stat as stat7 } from "node:fs/promises";
|
|
28633
|
-
import { homedir as
|
|
28678
|
+
import { homedir as homedir12 } from "node:os";
|
|
28634
28679
|
import { dirname as dirname9, isAbsolute as isAbsolute5, parse as parse3, resolve as resolve6 } from "node:path";
|
|
28635
28680
|
var MAX_ENTRIES = 1e3;
|
|
28636
28681
|
async function listDirectory(requested, allowedRoots) {
|
|
28637
|
-
const raw = requested.trim().replace(/^~(?=$|[\\/])/,
|
|
28682
|
+
const raw = requested.trim().replace(/^~(?=$|[\\/])/, homedir12()) || homedir12();
|
|
28638
28683
|
const directory = await realpath3(resolve6(raw)).catch(() => {
|
|
28639
28684
|
throw new Error(`\u76EE\u5F55\u4E0D\u5B58\u5728\uFF1A${requested}`);
|
|
28640
28685
|
});
|
|
@@ -28652,8 +28697,8 @@ async function listDirectory(requested, allowedRoots) {
|
|
|
28652
28697
|
else if (entry.isFile()) files.push(item);
|
|
28653
28698
|
}
|
|
28654
28699
|
const parent = dirname9(directory);
|
|
28655
|
-
const places = [{ label: "\u4E3B\u76EE\u5F55", path:
|
|
28656
|
-
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 });
|
|
28657
28702
|
places.push({ label: "\u6839\u76EE\u5F55", path: process.platform === "win32" ? parse3(directory).root : "/" });
|
|
28658
28703
|
return {
|
|
28659
28704
|
path: directory,
|
|
@@ -28691,7 +28736,7 @@ async function createDirectory(parentRequested, name) {
|
|
|
28691
28736
|
// src/workspace/workspace-manager.ts
|
|
28692
28737
|
import { spawn as spawn13 } from "node:child_process";
|
|
28693
28738
|
import { opendir, realpath as realpath4, stat as stat8 } from "node:fs/promises";
|
|
28694
|
-
import { homedir as
|
|
28739
|
+
import { homedir as homedir13 } from "node:os";
|
|
28695
28740
|
import { isAbsolute as isAbsolute6, relative as relative3, resolve as resolve7 } from "node:path";
|
|
28696
28741
|
var MAX_NODES = 2e3;
|
|
28697
28742
|
var MAX_DIRECTORY_ENTRIES = 12e3;
|
|
@@ -28727,7 +28772,7 @@ var WorkspaceManager = class {
|
|
|
28727
28772
|
return { root_path: rootPath, nodes, truncated: nodes.length >= MAX_NODES, duration_ms: Date.now() - startedAt };
|
|
28728
28773
|
}
|
|
28729
28774
|
validateRootPath(value) {
|
|
28730
|
-
const raw = value.trim().replace(/^~(?=$|[\\/])/,
|
|
28775
|
+
const raw = value.trim().replace(/^~(?=$|[\\/])/, homedir13());
|
|
28731
28776
|
const root2 = resolve7(raw);
|
|
28732
28777
|
if (!isAbsolute6(raw)) throw new Error("\u6839\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");
|
|
28733
28778
|
if (relative3(root2, resolve7(root2, "..")) === "") throw new Error("\u4E0D\u80FD\u628A\u6587\u4EF6\u7CFB\u7EDF\u6839\u76EE\u5F55\u4F5C\u4E3A\u76EE\u5F55\u6839");
|
|
@@ -29067,7 +29112,7 @@ var AgentRuntime = class {
|
|
|
29067
29112
|
}
|
|
29068
29113
|
};
|
|
29069
29114
|
this.workspaces = new WorkspaceManager(config2, this.logger);
|
|
29070
|
-
this.orphans = new OrphanRegistry(
|
|
29115
|
+
this.orphans = new OrphanRegistry(join22(config2.dataDir, "active-runs.json"));
|
|
29071
29116
|
this.runs = new RunSupervisor(config2, this.logger, reporter, this.orphans);
|
|
29072
29117
|
}
|
|
29073
29118
|
config;
|
|
@@ -29772,7 +29817,7 @@ function errorMessage3(error62) {
|
|
|
29772
29817
|
}
|
|
29773
29818
|
|
|
29774
29819
|
// src/runtime/run-service.ts
|
|
29775
|
-
import { existsSync as
|
|
29820
|
+
import { existsSync as existsSync7, readFileSync as readFileSync7 } from "node:fs";
|
|
29776
29821
|
import { dirname as dirname10, resolve as resolve8 } from "node:path";
|
|
29777
29822
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
29778
29823
|
var PACKAGE_NAME = "toc-ocra";
|
|
@@ -29780,7 +29825,7 @@ function agentPackageRoot() {
|
|
|
29780
29825
|
let directory = dirname10(fileURLToPath2(import.meta.url));
|
|
29781
29826
|
while (true) {
|
|
29782
29827
|
const packagePath = resolve8(directory, "package.json");
|
|
29783
|
-
if (
|
|
29828
|
+
if (existsSync7(packagePath)) {
|
|
29784
29829
|
try {
|
|
29785
29830
|
const info = JSON.parse(readFileSync7(packagePath, "utf8"));
|
|
29786
29831
|
if (info.name === PACKAGE_NAME && typeof info.version === "string") return directory;
|
|
@@ -29850,8 +29895,8 @@ function preferSystemNode() {
|
|
|
29850
29895
|
const names = process.platform === "win32" ? ["node.exe"] : ["node"];
|
|
29851
29896
|
for (const directory of (process.env.PATH ?? "").split(delimiter5)) {
|
|
29852
29897
|
for (const name of names) {
|
|
29853
|
-
const candidate = directory &&
|
|
29854
|
-
if (candidate &&
|
|
29898
|
+
const candidate = directory && join23(directory, name);
|
|
29899
|
+
if (candidate && existsSync8(candidate)) {
|
|
29855
29900
|
process.env.TOC_OCRA_NODE_PATH = candidate;
|
|
29856
29901
|
return;
|
|
29857
29902
|
}
|