toc-ocra 0.3.11 → 0.3.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # toc-ocra
2
2
 
3
- 运行在用户电脑上的 CLI 执行端。它接收 echo_admin 派发的任务,在本机以无界面模式运行 codex / claude / kiro / grok / gemini / opencode 等 CLI,并把运行状态和结果报回服务端。它也可以在设备开启相应开关后执行脚本和 SQL(SQL 执行器目前是预留接口)。
3
+ 运行在用户电脑上的 CLI 执行端。它接收 echo_admin 派发的任务,在本机以无界面模式运行 codex / claude / kimi / kiro / grok / gemini / opencode 等 CLI,并把运行状态和结果报回服务端。它也可以在设备开启相应开关后执行脚本和 SQL(SQL 执行器目前是预留接口)。
4
4
 
5
5
  参照 Orca 和 `api/api_ocra` 重构而来;`api_ocra` 保持原样不动。
6
6
 
@@ -34,6 +34,10 @@ node dist/src/index.js run
34
34
 
35
35
  其它命令:`toc-ocra code`(查看插件连接码)、`toc-ocra detect`(本机 CLI 探测)、`toc-ocra doctor`(配置 + 探测)、`toc-ocra version`。
36
36
 
37
+ ### 使用 Kimi Code CLI
38
+
39
+ macOS 上可按 [Kimi Code CLI 官方说明](https://github.com/MoonshotAI/kimi-code)安装;也可运行 `brew install kimi-code`。安装后在终端运行 `kimi`,输入 `/login` 完成登录。登录信息保存在本机,设备代理通过 `kimi acp` 复用该登录状态;设备在线且探测到 `kimi` 后,网页的 CLI 选项中会显示「Kimi Code CLI」。
40
+
37
41
  ## 桌面插件「设备代理」
38
42
 
39
43
  同一个 npm 包也是 Echo 桌面插件 `echo.device-agent`(`package.json › tocPlugin`,界面源码在 `plugin/`,构建产物 `dist/plugin/renderer.js`)。页面分三个页签:
@@ -94,7 +98,7 @@ kiro-cli chat --no-interactive --trust-all-tools --model gpt-5.6-luna --effort h
94
98
  | `TOC_OCRA_ALLOWED_ROOTS` | `allowedRoots` | 用户主目录 | CLI 可使用的工作目录根,PATH 风格列表 |
95
99
  | `TOC_OCRA_MAX_RUNS` | `maxConcurrentRuns` | 不限 | 本机同时运行的 CLI 回合上限,默认不限(配置文件填 0 也表示不限);同一会话始终一次只跑一个回合 |
96
100
  | `TOC_OCRA_MAX_RUN_SECONDS` | `maxRunSeconds` | 0 | 单个回合的时长上限,默认 0 表示不限时;长时间没有输出由服务端的卡住判定停止 |
97
- | `TOC_OCRA_DISABLE_SCRIPT` / `TOC_OCRA_DISABLE_SQL` | `disableScript` / `disableSql` | false | 本机强制关闭脚本 / SQL(优先于服务端开关) |
101
+ | `TOC_OCRA_DISABLE_SCRIPT` / `TOC_OCRA_DISABLE_SQL` | `disableScript` / `disableSql` | false | 旧配置项,为兼容已有配置保留,不再限制执行 |
98
102
  | `TOC_OCRA_DATA_DIR` / `TOC_OCRA_CONFIG` | — | 见下 | 数据目录 / 配置文件路径 |
99
103
  | `TOC_OCRA_HEALTH_HOST` / `TOC_OCRA_HEALTH_PORT` | `healthHost` / `healthPort` | 127.0.0.1 / 17339 | 本机状态页(仅本机可访问) |
100
104
  | `TOC_OCRA_LOG_LEVEL` | `logLevel` | info | 诊断日志级别 |
@@ -125,7 +129,7 @@ Windows CLI 探测会读取系统和用户 PATH、实际的 `%APPDATA%` / `%LOCA
125
129
  - 权限:按工具 kind 和权限级别回答,只选 `allow_once` / `reject_once`,不会替用户选“总是允许 / 总是拒绝”,没有一次性选项就取消;受限权限下只放行只读工具和 Echo 回调。
126
130
  - CLI 自己的扩展和怪癖写在 `acp/acp-dialects/`(错误文字、工具名、shell 输出格式、私有通知、模型档位),没有就是 `GENERIC_ACP_DIALECT`。
127
131
  - 模型列表(`acp/acp-model-catalog-probe.ts`):有自己读法的 CLI 用原来的读取器;只在会话里列模型的(如 OMP)开一个临时会话读选项,用完删除会话或删掉临时目录。
128
- - **现在的 ACP 行**:Kiro(`kiro-cli acp`)、Gemini(`gemini --acp`)、Grok(`grok agent stdio`)、OpenCode(`opencode acp`,≥ 1.18.31 / 2.0.14)、OMP(`omp acp`,≥ 17.0.5)跑任务和实时聊天;Claude Code、Codex 任务仍用原生驱动,实时聊天走 Lody 的 ACP 适配器。Grok、OpenCode、OMP 的参数、环境、版本下限和 dialect 来自 Orca。
132
+ - **现在的 ACP 行**:Kimi Code CLI(`kimi acp`)、Kiro(`kiro-cli acp`)、Gemini(`gemini --acp`)、Grok(`grok agent stdio`)、OpenCode(`opencode acp`,≥ 1.18.31 / 2.0.14)、OMP(`omp acp`,≥ 17.0.5)跑任务和实时聊天;Claude Code、Codex 任务仍用原生驱动,实时聊天走 Lody 的 ACP 适配器。Grok、OpenCode、OMP 的参数、环境、版本下限和 dialect 来自 Orca。
129
133
  - **回退**:`TOC_OCRA_<ID>_DRIVER=legacy`(如 `TOC_OCRA_GROK_DRIVER=legacy`)改回原来的驱动;装的版本低于行里的最低版本时自动用原来的驱动,也不提供实时聊天。原来的 Gemini、Grok、OpenCode 驱动不支持受限权限。
130
134
  - 其余 CLI(Codex、Claude 的任务)一个文件解析自己的 JSON 输出。ACP 下提示词走 stdin 的 JSON,不受命令行长度限制;会话 ID 由 `session/new` 直接返回;原会话不存在时同一进程内改开新会话。
131
135
  - **实时聊天(直接回复)走常驻 ACP 连接**(`src/acp/`,对应 Lody 的 `AgentClient` + 回合运行时):每个聊天会话一个长期运行的 ACP 进程,`initialize` 只做一次,之后每轮只发 `session/prompt`,回合以 `stopReason` 结束,不再是“一轮一个进程、进程退出才算结束”。
@@ -137,7 +141,7 @@ Windows CLI 探测会读取系统和用户 PATH、实际的 `%APPDATA%` / `%LOCA
137
141
  - **统一错误**:`src/providers/cli-failure.ts` 定义失败类型(未安装、未登录、额度用完、限流、模型不可用、会话丢失、超时、卡住等)和中文提示;各 CLI 只用 `failureRules` 把自己的报错对应到类型。回报里带 `failure_kind`。
138
142
  - **本机冒烟检查**:`toc-ocra smoke` 对每个已安装、能运行的 CLI 发一句最小提示,经过和任务完全相同的执行器与驱动,逐个给出结果和失败类型;`--full` 再测执行命令、续接会话、原会话不存在三种情况;也可指定 CLI,如 `toc-ocra smoke kiro codex`。`toc-ocra doctor --smoke` 在诊断信息后附带这项检查。
139
143
  - **录制回放测试**:`toc-ocra smoke --full --record <目录>` 把每轮与 CLI 的原始通信存成 JSONL,`node scripts/import-recordings.mjs <目录>` 导入 `tests/recordings/`。`tests/recordings.test.ts` 把录制内容当作 CLI 回放,跑真实的执行器和驱动,结果和运行日志必须与录制时一致;新增 CLI 的覆盖只需要录制,不用写测试代码。也可在运行中设置 `TOC_OCRA_RECORD_DIR` 录制任意一轮。
140
- - **加一个 CLI**:先在 `cli-specs.ts` 加一行(检测用)。支持 ACP 的,再在 `acp/acp-launch-specs.ts` 加一行,任务、实时聊天、模型列表和运行设置就都有了;只有它扩展或偏离协议时才写 dialect。不支持 ACP 的,在 `src/providers/cli/` 新增一个文件实现 `HeadlessProvider`,`buildLaunch` 里调用 `launchCli({ spec, args, prompt })`,在 `registry.ts` 挂上。不要在 provider 里判断操作系统。服务端和网页的 CLI 类型列表(`agent_type`)目前是固定的六种,新的 CLI 类型要在那边一起加上。
144
+ - **加一个 CLI**:先在 `cli-specs.ts` 加一行(检测用)。支持 ACP 的,再在 `acp/acp-launch-specs.ts` 加一行,任务、实时聊天、模型列表和运行设置就都有了;只有它扩展或偏离协议时才写 dialect。不支持 ACP 的,在 `src/providers/cli/` 新增一个文件实现 `HeadlessProvider`,`buildLaunch` 里调用 `launchCli({ spec, args, prompt })`,在 `registry.ts` 挂上。不要在 provider 里判断操作系统。服务端和网页的 CLI 类型列表(`agent_type`)需同步维护。
141
145
 
142
146
  ### 记忆(Nowledge Mem)
143
147
  对应 Lody 的记忆系统。记忆本身保存在设备上的 [Nowledge Mem](https://mem.nowledge.co) 里,Echo 只记录每台设备导入了哪些记忆体(Agent 身份),角色绑定其中一个,会话创建时从角色复制过来。
package/dist/cli/cli.mjs CHANGED
@@ -4577,7 +4577,7 @@ var require_lib = __commonJS({
4577
4577
  import { spawnSync } from "node:child_process";
4578
4578
  import { createHash as createHash5 } from "node:crypto";
4579
4579
  import { existsSync as existsSync7, mkdtempSync, rmSync, writeFileSync as writeFileSync3 } from "node:fs";
4580
- import { tmpdir as tmpdir5 } from "node:os";
4580
+ import { tmpdir as tmpdir4 } from "node:os";
4581
4581
  import { createRequire } from "node:module";
4582
4582
  import { dirname as dirname11, join as join23, resolve as resolve9 } from "node:path";
4583
4583
  import { fileURLToPath as fileURLToPath3, pathToFileURL as pathToFileURL2 } from "node:url";
@@ -25140,6 +25140,7 @@ function mergePathSegments(segments) {
25140
25140
  // src/providers/cli-specs.ts
25141
25141
  var SOURCES = [
25142
25142
  { id: "codex", label: "Codex", command: "codex", versionArguments: ["--version"], promptStdin: { replaceWith: "-" }, restrictedPermission: true, installHint: "npm i -g @openai/codex" },
25143
+ { id: "kimi", label: "Kimi Code CLI", command: "kimi", versionArguments: ["--version"], installHint: "curl -fsSL https://code.kimi.com/kimi-code/install.sh | bash" },
25143
25144
  { id: "claude", label: "Claude Code", aliases: ["claude-code"], command: "claude", commandAliases: ["claude-code"], versionArguments: ["--version"], promptStdin: "omit", restrictedPermission: true, installHint: "npm i -g @anthropic-ai/claude-code" },
25144
25145
  { id: "grok", label: "Grok CLI", command: "grok", versionArguments: ["--version"] },
25145
25146
  { id: "gemini", label: "Gemini CLI", command: "gemini", versionArguments: ["--version"], restrictedPermission: true, installHint: "npm i -g @google/gemini-cli" },
@@ -26675,6 +26676,14 @@ var KIRO_LAUNCH_SPEC = {
26675
26676
  resumable: (sessionId) => !sessionId.startsWith("sess_"),
26676
26677
  modelDiscovery: { kind: "reader", source: MODEL_SOURCES.kiro }
26677
26678
  };
26679
+ var KIMI_LAUNCH_SPEC = {
26680
+ agent: "kimi",
26681
+ headless: "acp",
26682
+ args: () => ["acp"],
26683
+ resumePreference: "resume",
26684
+ dialect: { failureRules: [{ kind: "sessionMissing", pattern: /session[^\n]{0,60}(?:not found|does not exist)|no such session/i }] },
26685
+ modelDiscovery: { kind: "session" }
26686
+ };
26678
26687
  var GEMINI_LAUNCH_SPEC = {
26679
26688
  agent: "gemini",
26680
26689
  headless: "acp",
@@ -26780,6 +26789,7 @@ var CODEX_LAUNCH_SPEC = {
26780
26789
  };
26781
26790
  var ACP_LAUNCH_SPECS = [
26782
26791
  KIRO_LAUNCH_SPEC,
26792
+ KIMI_LAUNCH_SPEC,
26783
26793
  GEMINI_LAUNCH_SPEC,
26784
26794
  GROK_LAUNCH_SPEC,
26785
26795
  OPENCODE_LAUNCH_SPEC,
@@ -33332,9 +33342,9 @@ var GatewayClient = class {
33332
33342
  };
33333
33343
 
33334
33344
  // src/workspace/directory-browser.ts
33335
- import { readdir as readdir3, realpath as realpath4, stat as stat7 } from "node:fs/promises";
33345
+ import { mkdir as mkdir9, readdir as readdir3, realpath as realpath4, stat as stat7 } from "node:fs/promises";
33336
33346
  import { homedir as homedir11 } from "node:os";
33337
- import { dirname as dirname9, parse as parse3, resolve as resolve6 } from "node:path";
33347
+ import { dirname as dirname9, isAbsolute as isAbsolute5, parse as parse3, resolve as resolve6 } from "node:path";
33338
33348
  var MAX_ENTRIES = 1e3;
33339
33349
  async function listDirectory(requested, allowedRoots) {
33340
33350
  const raw = requested.trim().replace(/^~(?=$|[\\/])/, homedir11()) || homedir11();
@@ -33367,12 +33377,35 @@ async function listDirectory(requested, allowedRoots) {
33367
33377
  places
33368
33378
  };
33369
33379
  }
33380
+ async function createDirectory(parentRequested, name) {
33381
+ const parentInput = parentRequested.trim();
33382
+ if (!parentInput || !isAbsolute5(parentInput)) throw new Error("\u4E0A\u7EA7\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");
33383
+ if (!name || name !== name.trim() || name === "." || name === ".." || name.includes("/") || name.includes("\\") || Array.from(name).length > 255 || Array.from(name).some((character) => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127)) {
33384
+ throw new Error("\u8BF7\u8F93\u5165\u6709\u6548\u7684\u6587\u4EF6\u5939\u540D\u79F0");
33385
+ }
33386
+ const parent = await realpath4(resolve6(parentInput)).catch(() => {
33387
+ throw new Error(`\u4E0A\u7EA7\u76EE\u5F55\u4E0D\u5B58\u5728\uFF1A${parentRequested}`);
33388
+ });
33389
+ if (!(await stat7(parent)).isDirectory()) throw new Error("\u4E0A\u7EA7\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55");
33390
+ const path = resolve6(parent, name);
33391
+ if (dirname9(path) !== parent) throw new Error("\u6587\u4EF6\u5939\u540D\u79F0\u65E0\u6548");
33392
+ try {
33393
+ await mkdir9(path);
33394
+ } catch (error62) {
33395
+ const code2 = error62.code;
33396
+ if (code2 === "EEXIST") throw new Error("\u8BE5\u6587\u4EF6\u5939\u5DF2\u5B58\u5728");
33397
+ if (code2 === "EACCES" || code2 === "EPERM") throw new Error("\u6CA1\u6709\u6743\u9650\u5728\u6B64\u4F4D\u7F6E\u521B\u5EFA\u6587\u4EF6\u5939");
33398
+ if (code2 === "ENOENT") throw new Error("\u4E0A\u7EA7\u76EE\u5F55\u4E0D\u5B58\u5728");
33399
+ throw error62;
33400
+ }
33401
+ return { path };
33402
+ }
33370
33403
 
33371
33404
  // src/workspace/workspace-manager.ts
33372
33405
  import { spawn as spawn13 } from "node:child_process";
33373
- import { chmod as chmod5, mkdir as mkdir9, mkdtemp as mkdtemp3, opendir, realpath as realpath5, rm as rm6, stat as stat8, writeFile as writeFile9 } from "node:fs/promises";
33374
- import { homedir as homedir12, tmpdir as tmpdir4 } from "node:os";
33375
- import { isAbsolute as isAbsolute5, join as join21, relative as relative3, resolve as resolve7 } from "node:path";
33406
+ import { opendir, realpath as realpath5, stat as stat8 } from "node:fs/promises";
33407
+ import { homedir as homedir12 } from "node:os";
33408
+ import { isAbsolute as isAbsolute6, relative as relative3, resolve as resolve7 } from "node:path";
33376
33409
  var MAX_NODES = 2e3;
33377
33410
  var MAX_DIRECTORY_ENTRIES = 12e3;
33378
33411
  var IGNORED_DIRECTORIES = /* @__PURE__ */ new Set([
@@ -33406,193 +33439,13 @@ var WorkspaceManager = class {
33406
33439
  const nodes = await this.scanTree(rootPath, request.max_depth, request.scan_roots);
33407
33440
  return { root_path: rootPath, nodes, truncated: nodes.length >= MAX_NODES, duration_ms: Date.now() - startedAt };
33408
33441
  }
33409
- /** Creates missing folders, clones missing repos, fast-forwards clean ones. */
33410
- async sync(request) {
33411
- const startedAt = Date.now();
33412
- const rootPath = this.validateRootPath(request.root_path);
33413
- const results = await this.syncTree(rootPath, request);
33414
- const failed = results.some((result) => result.status === "failed");
33415
- return {
33416
- root_path: rootPath,
33417
- results,
33418
- ...failed ? { error: "\u90E8\u5206\u76EE\u5F55\u6216\u4ED3\u5E93\u540C\u6B65\u5931\u8D25" } : {},
33419
- duration_ms: Date.now() - startedAt
33420
- };
33421
- }
33422
33442
  validateRootPath(value) {
33423
33443
  const raw = value.trim().replace(/^~(?=$|[\\/])/, homedir12());
33424
33444
  const root2 = resolve7(raw);
33425
- if (!isAbsolute5(raw)) throw new Error("\u6839\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");
33445
+ if (!isAbsolute6(raw)) throw new Error("\u6839\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");
33426
33446
  if (relative3(root2, resolve7(root2, "..")) === "") throw new Error("\u4E0D\u80FD\u628A\u6587\u4EF6\u7CFB\u7EDF\u6839\u76EE\u5F55\u4F5C\u4E3A\u76EE\u5F55\u6839");
33427
33447
  return root2;
33428
33448
  }
33429
- async syncTree(rootPath, request) {
33430
- await mkdir9(rootPath, { recursive: true });
33431
- await addAllowedRoot(this.config, rootPath);
33432
- const results = [];
33433
- const requestedPaths = /* @__PURE__ */ new Set();
33434
- for (const directory of request.directories) {
33435
- const relativePath = this.cleanRelativePath(directory);
33436
- if (requestedPaths.has(relativePath)) continue;
33437
- requestedPaths.add(relativePath);
33438
- const target = this.resolveWithinRoot(rootPath, relativePath);
33439
- try {
33440
- const metadata = await stat8(target).catch(() => void 0);
33441
- if (metadata) {
33442
- if (!metadata.isDirectory()) {
33443
- throw new Error("The existing workspace path is not a directory");
33444
- }
33445
- results.push({
33446
- relative_path: relativePath,
33447
- status: "skipped",
33448
- kind: "directory",
33449
- action: "skip",
33450
- message: "\u76EE\u5F55\u5DF2\u5B58\u5728"
33451
- });
33452
- continue;
33453
- }
33454
- await mkdir9(target, { recursive: true });
33455
- results.push({
33456
- relative_path: relativePath,
33457
- status: "created",
33458
- kind: "directory",
33459
- action: "mkdir",
33460
- message: "\u76EE\u5F55\u5DF2\u521B\u5EFA"
33461
- });
33462
- } catch (error62) {
33463
- results.push({
33464
- relative_path: relativePath,
33465
- status: "failed",
33466
- kind: "directory",
33467
- action: "mkdir",
33468
- error: this.message(error62)
33469
- });
33470
- }
33471
- }
33472
- const authEnvironment = await this.createGitAuthEnvironment(request.git_auth);
33473
- try {
33474
- for (const repo of request.repos) {
33475
- const relativePath = this.cleanRelativePath(repo.relative_path);
33476
- try {
33477
- results.push(await this.syncRepository(rootPath, relativePath, repo.git_url?.trim() || void 0, repo.branch?.trim() || void 0, request.timeout_s, authEnvironment?.env));
33478
- } catch (error62) {
33479
- results.push({
33480
- relative_path: relativePath,
33481
- status: "failed",
33482
- kind: "repo",
33483
- action: "sync",
33484
- error: this.message(error62)
33485
- });
33486
- }
33487
- }
33488
- } finally {
33489
- await authEnvironment?.cleanup();
33490
- }
33491
- return results;
33492
- }
33493
- async syncRepository(rootPath, relativePath, gitUrl, branch, timeoutSeconds, gitEnvironment) {
33494
- const target = this.resolveWithinRoot(rootPath, relativePath);
33495
- let created = false;
33496
- let metadata;
33497
- try {
33498
- metadata = await stat8(target);
33499
- } catch {
33500
- }
33501
- if (!metadata) {
33502
- if (!gitUrl) throw new Error("A missing repository needs a Git remote URL");
33503
- await mkdir9(resolve7(target, ".."), { recursive: true });
33504
- const cloneArgs = branch ? ["clone", "--branch", branch, "--single-branch", gitUrl, target] : ["clone", gitUrl, target];
33505
- await this.runGit(cloneArgs, rootPath, timeoutSeconds, false, gitEnvironment);
33506
- created = true;
33507
- } else {
33508
- if (!metadata.isDirectory()) throw new Error("The repository path is not a directory");
33509
- if (!await this.isGitRepository(target, timeoutSeconds)) {
33510
- throw new Error("The existing directory is not a Git repository");
33511
- }
33512
- if (gitUrl) {
33513
- const currentOrigin = (await this.runGit(["config", "--get", "remote.origin.url"], target, timeoutSeconds, true)).stdout.trim();
33514
- if (currentOrigin && currentOrigin !== gitUrl) {
33515
- throw new Error("The existing repository origin does not match the configured Git URL");
33516
- }
33517
- }
33518
- const worktree = await this.runGit(["status", "--porcelain"], target, timeoutSeconds);
33519
- if (worktree.stdout.trim()) {
33520
- return {
33521
- relative_path: relativePath,
33522
- status: "skipped",
33523
- kind: "repo",
33524
- action: "skip",
33525
- message: "\u4ED3\u5E93\u5B58\u5728\u672A\u63D0\u4EA4\u7684\u672C\u5730\u4FEE\u6539"
33526
- };
33527
- }
33528
- if (branch) {
33529
- const currentBranch = await this.runGit(["branch", "--show-current"], target, timeoutSeconds);
33530
- if (currentBranch.stdout.trim() !== branch) {
33531
- return {
33532
- relative_path: relativePath,
33533
- status: "skipped",
33534
- kind: "repo",
33535
- action: "skip",
33536
- message: `\u5F53\u524D\u5206\u652F ${currentBranch.stdout.trim() || "(detached)"} \u4E0E\u76EE\u6807\u5206\u652F ${branch} \u4E0D\u4E00\u81F4`
33537
- };
33538
- }
33539
- }
33540
- }
33541
- await this.runGit(["fetch", "--prune", "origin"], target, timeoutSeconds, false, gitEnvironment);
33542
- if (branch) {
33543
- const remoteBranch = await this.runGit(
33544
- ["show-ref", "--verify", "--quiet", `refs/remotes/origin/${branch}`],
33545
- target,
33546
- timeoutSeconds,
33547
- true
33548
- );
33549
- if (remoteBranch.exitCode !== 0) {
33550
- return {
33551
- relative_path: relativePath,
33552
- status: "skipped",
33553
- kind: "repo",
33554
- action: "skip",
33555
- message: `\u8FDC\u7AEF\u5206\u652F origin/${branch} \u4E0D\u5B58\u5728`
33556
- };
33557
- }
33558
- if (!created) {
33559
- const currentCommit = await this.runGit(["rev-parse", "HEAD"], target, timeoutSeconds);
33560
- const remoteCommit = await this.runGit(["rev-parse", `origin/${branch}`], target, timeoutSeconds);
33561
- if (currentCommit.stdout.trim() === remoteCommit.stdout.trim()) {
33562
- return {
33563
- relative_path: relativePath,
33564
- status: "skipped",
33565
- kind: "repo",
33566
- action: "skip",
33567
- message: "\u4ED3\u5E93\u5DF2\u662F\u6700\u65B0"
33568
- };
33569
- }
33570
- const fastForward = await this.runGit(
33571
- ["merge-base", "--is-ancestor", "HEAD", `origin/${branch}`],
33572
- target,
33573
- timeoutSeconds,
33574
- true
33575
- );
33576
- if (fastForward.exitCode !== 0) {
33577
- return {
33578
- relative_path: relativePath,
33579
- status: "skipped",
33580
- kind: "repo",
33581
- action: "skip",
33582
- message: "\u672C\u5730\u63D0\u4EA4\u65E0\u6CD5\u5FEB\u8FDB\u5230\u8FDC\u7AEF\u5206\u652F"
33583
- };
33584
- }
33585
- }
33586
- await this.runGit(["pull", "--ff-only", "origin", branch], target, timeoutSeconds, false, gitEnvironment);
33587
- }
33588
- return {
33589
- relative_path: relativePath,
33590
- status: created ? "created" : "updated",
33591
- kind: "repo",
33592
- action: created ? "clone" : "pull",
33593
- message: created ? "\u4ED3\u5E93\u5DF2\u514B\u9686" : "\u4ED3\u5E93\u5DF2\u5FEB\u8FDB\u66F4\u65B0"
33594
- };
33595
- }
33596
33449
  async scanTree(rootPath, maxDepth, scanRoots) {
33597
33450
  const resolvedRoot = await realpath5(rootPath);
33598
33451
  const rootMetadata = await stat8(resolvedRoot);
@@ -33706,16 +33559,16 @@ var WorkspaceManager = class {
33706
33559
  resolveWithinRoot(rootPath, relativePath) {
33707
33560
  const target = resolve7(rootPath, relativePath);
33708
33561
  const relativeToRoot = relative3(rootPath, target);
33709
- if (relativeToRoot.startsWith("..") || isAbsolute5(relativeToRoot)) {
33562
+ if (relativeToRoot.startsWith("..") || isAbsolute6(relativeToRoot)) {
33710
33563
  throw new Error("A workspace path must remain under the configured workspace root");
33711
33564
  }
33712
33565
  return target;
33713
33566
  }
33714
- runGit(args, cwd, timeoutSeconds, allowFailure = false, environment) {
33567
+ runGit(args, cwd, timeoutSeconds, allowFailure = false) {
33715
33568
  return new Promise((resolveCommand, rejectCommand) => {
33716
33569
  const child = spawn13("git", args, {
33717
33570
  cwd,
33718
- env: environment ?? process.env,
33571
+ env: process.env,
33719
33572
  shell: false,
33720
33573
  stdio: ["ignore", "pipe", "pipe"]
33721
33574
  });
@@ -33745,37 +33598,6 @@ var WorkspaceManager = class {
33745
33598
  });
33746
33599
  });
33747
33600
  }
33748
- async createGitAuthEnvironment(auth) {
33749
- if (!auth) return void 0;
33750
- const directory = await mkdtemp3(join21(tmpdir4(), "toc-ocra-git-auth-"));
33751
- const isWindows = process.platform === "win32";
33752
- const scriptPath = join21(directory, isWindows ? "askpass.cmd" : "askpass.sh");
33753
- let script;
33754
- if (isWindows) {
33755
- const helperPath = join21(directory, "askpass.cjs");
33756
- await writeFile9(
33757
- helperPath,
33758
- 'const prompt = process.argv.slice(2).join(" ");\nprocess.stdout.write(/username/i.test(prompt) ? process.env.ECHO_GIT_USERNAME ?? "" : process.env.ECHO_GIT_PASSWORD ?? "");\n',
33759
- { mode: 448 }
33760
- );
33761
- script = '@echo off\r\n"%ECHO_NODE_PATH%" "%~dp0askpass.cjs" "%~1"\r\n';
33762
- } else {
33763
- script = '#!/bin/sh\ncase "$1" in *Username*|*username*) printf "%s\\n" "$ECHO_GIT_USERNAME" ;; *) printf "%s\\n" "$ECHO_GIT_PASSWORD" ;; esac\n';
33764
- }
33765
- await writeFile9(scriptPath, script, { mode: 448 });
33766
- if (!isWindows) await chmod5(scriptPath, 448);
33767
- return {
33768
- env: {
33769
- ...process.env,
33770
- GIT_ASKPASS: scriptPath,
33771
- GIT_TERMINAL_PROMPT: "0",
33772
- ECHO_NODE_PATH: process.execPath,
33773
- ECHO_GIT_USERNAME: auth.username,
33774
- ECHO_GIT_PASSWORD: auth.password
33775
- },
33776
- cleanup: () => rm6(directory, { recursive: true, force: true })
33777
- };
33778
- }
33779
33601
  message(error62) {
33780
33602
  return error62 instanceof Error ? error62.message : String(error62);
33781
33603
  }
@@ -33901,22 +33723,15 @@ var CliProviderControlPayloadSchema = external_exports.object({
33901
33723
  }).strict();
33902
33724
  var RelativePathSchema = external_exports.string().min(1).max(500);
33903
33725
  var FsListPayloadSchema = external_exports.object({ path: external_exports.string().max(4096).optional().default("") });
33726
+ var FsMkdirPayloadSchema = external_exports.object({
33727
+ parent_path: external_exports.string().min(1).max(4096),
33728
+ name: external_exports.string().min(1).max(255)
33729
+ }).strict();
33904
33730
  var WorkspaceScanPayloadSchema = external_exports.object({
33905
33731
  root_path: external_exports.string().min(1).max(4096),
33906
33732
  max_depth: external_exports.number().int().positive().max(20).optional(),
33907
33733
  scan_roots: external_exports.array(external_exports.object({ relative_path: RelativePathSchema, max_depth: external_exports.number().int().positive().max(20) })).max(2e3).optional()
33908
33734
  });
33909
- var WorkspaceSyncPayloadSchema = external_exports.object({
33910
- root_path: external_exports.string().min(1).max(4096),
33911
- directories: external_exports.array(RelativePathSchema).max(2e3).default([]),
33912
- repos: external_exports.array(external_exports.object({
33913
- relative_path: RelativePathSchema,
33914
- git_url: external_exports.string().max(2e3).nullable().optional(),
33915
- branch: external_exports.string().max(200).nullable().optional()
33916
- })).max(2e3).default([]),
33917
- timeout_s: external_exports.number().int().positive().max(3600).optional(),
33918
- git_auth: external_exports.object({ username: external_exports.string().min(1).max(500), password: external_exports.string().min(1).max(4096) }).optional()
33919
- });
33920
33735
 
33921
33736
  // src/runtime/agent-runtime.ts
33922
33737
  var sleep3 = (ms, signal2) => new Promise((resolve10) => {
@@ -34309,15 +34124,14 @@ var AgentRuntime = class {
34309
34124
  const payload = FsListPayloadSchema.parse(command.payload ?? {});
34310
34125
  return { success: true, result: await listDirectory(payload.path, this.config.allowedRoots) };
34311
34126
  }
34127
+ case "fs.mkdir": {
34128
+ const payload = FsMkdirPayloadSchema.parse(command.payload);
34129
+ return { success: true, result: await createDirectory(payload.parent_path, payload.name) };
34130
+ }
34312
34131
  case "workspace.scan": {
34313
34132
  const payload = WorkspaceScanPayloadSchema.parse(command.payload);
34314
34133
  return { success: true, result: await this.workspaces.scan(payload) };
34315
34134
  }
34316
- case "workspace.sync": {
34317
- const payload = WorkspaceSyncPayloadSchema.parse(command.payload);
34318
- const result = await this.workspaces.sync(payload);
34319
- return { success: !result.error, result, ...result.error ? { error: result.error } : {} };
34320
- }
34321
34135
  case "sql.run": {
34322
34136
  const payload = SqlRunPayloadSchema.parse(command.payload);
34323
34137
  this.checkPolicy("sql", payload.policy);
@@ -34328,16 +34142,14 @@ var AgentRuntime = class {
34328
34142
  }
34329
34143
  }
34330
34144
  /**
34331
- * Script / SQL run only when the server policy allows it and the local
34332
- * owner has not switched it off. The policy attached to the command was
34145
+ * Script / SQL run when the server policy allows it. The policy attached to the command was
34333
34146
  * checked by the server at enqueue time, so it wins over the (up to one
34334
34147
  * heartbeat old) cached copy. New policy fields (read-only SQL,
34335
34148
  * allowlists) are enforced here.
34336
34149
  */
34337
34150
  checkPolicy(kind, commandPolicy) {
34338
- const localOff = kind === "script" ? this.config.disableScript : this.config.disableSql;
34339
34151
  const policy = commandPolicy ?? this.policy;
34340
- const enabled = !localOff && policy[kind].enabled;
34152
+ const enabled = policy[kind].enabled;
34341
34153
  if (!enabled) throw new Error(kind === "script" ? "\u8BE5\u8BBE\u5907\u672A\u5F00\u542F\u811A\u672C\u6267\u884C" : "\u8BE5\u8BBE\u5907\u672A\u5F00\u542F SQL \u6267\u884C");
34342
34154
  }
34343
34155
  // ---- Reports ----
@@ -34855,7 +34667,7 @@ async function update(args) {
34855
34667
  if (customConfig) process.env.TOC_OCRA_CONFIG = resolve9(customConfig);
34856
34668
  await ensureIdle();
34857
34669
  const npmPath = resolveCliCommand("npm");
34858
- const temporary = mkdtempSync(join23(tmpdir5(), "toc-ocra-update-"));
34670
+ const temporary = mkdtempSync(join23(tmpdir4(), "toc-ocra-update-"));
34859
34671
  try {
34860
34672
  const metadataResponse = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}`, { headers: { accept: "application/json", "cache-control": "no-cache" }, signal: AbortSignal.timeout(15e3) });
34861
34673
  if (!metadataResponse.ok) throw new Error("\u65E0\u6CD5\u8BFB\u53D6 npm \u6700\u65B0\u7248\u672C\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");