forgex-agent 0.6.1 → 0.6.2

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/main.js +217 -230
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -18,7 +18,7 @@ forgex --version
18
18
  ## 快速开始
19
19
 
20
20
  ```bash
21
- # 方式一:直接启动。首次运行会自动进入连接向导(provider → baseUrl → API Key → model)
21
+ # 方式一:直接启动。即使尚未配置模型,也会先进入 TUI;在会话中用 /connect 或 /key 配置
22
22
  forgex
23
23
 
24
24
  # 方式二:先单独配置,会做一次连通性测试
package/main.js CHANGED
@@ -6237,7 +6237,7 @@ var init_load_config = __esm({
6237
6237
  function modelSetupHint(options) {
6238
6238
  const lines = [
6239
6239
  "\u5C1A\u672A\u914D\u7F6E\u6A21\u578B\u3002",
6240
- options.interactive ? "\u5728\u4EA4\u4E92\u5F0F\u7EC8\u7AEF\u91CC\u76F4\u63A5\u8FD0\u884C `forgex` \u4F1A\u81EA\u52A8\u8FDB\u5165\u8FDE\u63A5\u5411\u5BFC\u3002" : "\u4EFB\u9009\u4E00\u79CD\u65B9\u5F0F\u5B8C\u6210\u914D\u7F6E\uFF1A",
6240
+ options.interactive ? "\u8FDB\u5165 TUI \u540E\u4F7F\u7528 `/connect` \u6216 `/key` \u914D\u7F6E\u6A21\u578B\u3002" : "\u4EFB\u9009\u4E00\u79CD\u65B9\u5F0F\u5B8C\u6210\u914D\u7F6E\uFF1A",
6241
6241
  " 1. \u4EA4\u4E92\u5F0F\u5411\u5BFC\uFF1Aforgex connect",
6242
6242
  " 2. \u975E\u4EA4\u4E92\u5F0F\uFF1Aforgex connect --provider deepseek --api-key sk-xxx --model deepseek-flash",
6243
6243
  " 3. \u53EA\u8BBE\u7F6E Key\uFF1Aexport DEEPSEEK_API_KEY=sk-xxx\uFF08\u542F\u52A8\u65F6\u81EA\u52A8\u8BC6\u522B DeepSeek\uFF09",
@@ -8405,7 +8405,7 @@ function execFileText(program, args, options = {}) {
8405
8405
  maxBuffer: options.maxBuffer ?? 8 * 1024 * 1024,
8406
8406
  windowsHide: true,
8407
8407
  encoding: "utf8"
8408
- }, (error, stdout12, stderr5) => {
8408
+ }, (error, stdout12, stderr4) => {
8409
8409
  if (error) {
8410
8410
  const errCode = error.code;
8411
8411
  if (errCode === "ENOENT") {
@@ -8418,11 +8418,11 @@ function execFileText(program, args, options = {}) {
8418
8418
  resolve9({
8419
8419
  code: typeof errCode === "number" ? errCode : -1,
8420
8420
  stdout: String(stdout12 ?? ""),
8421
- stderr: String(stderr5 ?? error.message)
8421
+ stderr: String(stderr4 ?? error.message)
8422
8422
  });
8423
8423
  return;
8424
8424
  }
8425
- resolve9({ code: 0, stdout: String(stdout12 ?? ""), stderr: String(stderr5 ?? "") });
8425
+ resolve9({ code: 0, stdout: String(stdout12 ?? ""), stderr: String(stderr4 ?? "") });
8426
8426
  });
8427
8427
  });
8428
8428
  }
@@ -9183,7 +9183,7 @@ var init_ssh_client = __esm({
9183
9183
  return this.abortedResult(command, spec, started, "SSH \u8FDE\u63A5\u88AB\u53D6\u6D88");
9184
9184
  }
9185
9185
  let stdout12 = "";
9186
- let stderr5 = "";
9186
+ let stderr4 = "";
9187
9187
  let truncated = false;
9188
9188
  let timedOut = false;
9189
9189
  let exitCode = null;
@@ -9229,9 +9229,9 @@ var init_ssh_client = __esm({
9229
9229
  }).stderr.on("data", (data) => {
9230
9230
  const chunk = data.toString("utf8");
9231
9231
  const stderrLimit = Math.floor(maxOutputBytes * 0.5);
9232
- if (byteLength(stderr5) < stderrLimit) {
9233
- stderr5 += chunk;
9234
- if (byteLength(stderr5) >= stderrLimit)
9232
+ if (byteLength(stderr4) < stderrLimit) {
9233
+ stderr4 += chunk;
9234
+ if (byteLength(stderr4) >= stderrLimit)
9235
9235
  truncated = true;
9236
9236
  } else {
9237
9237
  truncated = true;
@@ -9253,7 +9253,7 @@ var init_ssh_client = __esm({
9253
9253
  return {
9254
9254
  exitCode,
9255
9255
  stdout: truncated ? truncateWithNote(stdout12, maxOutputBytes, 0.9) : stdout12,
9256
- stderr: truncated ? truncateWithNote(stderr5, Math.floor(maxOutputBytes * 0.5), 0.9) : stderr5,
9256
+ stderr: truncated ? truncateWithNote(stderr4, Math.floor(maxOutputBytes * 0.5), 0.9) : stderr4,
9257
9257
  truncated,
9258
9258
  timedOut,
9259
9259
  durationMs: Date.now() - started,
@@ -10280,8 +10280,8 @@ function runViaExecutor(binary, spec, signal) {
10280
10280
  cleanup();
10281
10281
  const raw = Buffer.concat(outChunks).toString("utf8").trim();
10282
10282
  if (!raw) {
10283
- const stderr5 = Buffer.concat(errChunks).toString("utf8").trim();
10284
- finish(() => reject(new ForgeError("TOOL_FAILED", `\u6267\u884C\u5668\u672A\u8FD4\u56DE\u7ED3\u679C${stderr5 ? `: ${stderr5}` : ""}`)));
10283
+ const stderr4 = Buffer.concat(errChunks).toString("utf8").trim();
10284
+ finish(() => reject(new ForgeError("TOOL_FAILED", `\u6267\u884C\u5668\u672A\u8FD4\u56DE\u7ED3\u679C${stderr4 ? `: ${stderr4}` : ""}`)));
10285
10285
  return;
10286
10286
  }
10287
10287
  let parsed;
@@ -19334,7 +19334,7 @@ async function captureWsl(program, args) {
19334
19334
  env: process.env
19335
19335
  });
19336
19336
  let stdout12 = Buffer.alloc(0);
19337
- let stderr5 = Buffer.alloc(0);
19337
+ let stderr4 = Buffer.alloc(0);
19338
19338
  let settled = false;
19339
19339
  const timeout = setTimeout(() => {
19340
19340
  child.kill();
@@ -19346,7 +19346,7 @@ async function captureWsl(program, args) {
19346
19346
  stdout12 = appendBounded(stdout12, chunk);
19347
19347
  });
19348
19348
  child.stderr.on("data", (chunk) => {
19349
- stderr5 = appendBounded(stderr5, chunk);
19349
+ stderr4 = appendBounded(stderr4, chunk);
19350
19350
  });
19351
19351
  child.on("error", (error) => {
19352
19352
  if (settled)
@@ -19361,7 +19361,7 @@ async function captureWsl(program, args) {
19361
19361
  settled = true;
19362
19362
  clearTimeout(timeout);
19363
19363
  if (code !== 0) {
19364
- rejectOutput(new ForgeError("SANDBOX_UNAVAILABLE", `WSL \u547D\u4EE4\u5931\u8D25: ${decode(stderr5).trim() || `exit code ${code}`}`));
19364
+ rejectOutput(new ForgeError("SANDBOX_UNAVAILABLE", `WSL \u547D\u4EE4\u5931\u8D25: ${decode(stderr4).trim() || `exit code ${code}`}`));
19365
19365
  return;
19366
19366
  }
19367
19367
  resolveOutput(decode(stdout12));
@@ -19429,10 +19429,10 @@ function unavailableStatus(platform, reason, details, bwrapPath = null) {
19429
19429
  details: { ...details, untrusted: "denied" }
19430
19430
  };
19431
19431
  }
19432
- function detectBwrapSetupError(stderr5, code) {
19432
+ function detectBwrapSetupError(stderr4, code) {
19433
19433
  if (code === 0)
19434
19434
  return null;
19435
- const line = stderr5.split("\n").map((item) => item.trim()).find((item) => item.startsWith("bwrap:"));
19435
+ const line = stderr4.split("\n").map((item) => item.trim()).find((item) => item.startsWith("bwrap:"));
19436
19436
  return line ? line.slice(0, 500) : null;
19437
19437
  }
19438
19438
  var OsSandboxProvider;
@@ -19925,9 +19925,9 @@ async function detectGit() {
19925
19925
  stdio: ["ignore", "pipe", "pipe"]
19926
19926
  });
19927
19927
  let stdout12 = "";
19928
- let stderr5 = "";
19928
+ let stderr4 = "";
19929
19929
  child.stdout.on("data", (d) => stdout12 += d.toString());
19930
- child.stderr.on("data", (d) => stderr5 += d.toString());
19930
+ child.stderr.on("data", (d) => stderr4 += d.toString());
19931
19931
  const timer = setTimeout(() => {
19932
19932
  child.kill();
19933
19933
  resolve9({
@@ -19966,7 +19966,7 @@ async function detectGit() {
19966
19966
  category: "workspace_isolation",
19967
19967
  available: false,
19968
19968
  verified: false,
19969
- reason: `git --version \u5931\u8D25: ${stderr5.trim() || `exit code ${code}`}`
19969
+ reason: `git --version \u5931\u8D25: ${stderr4.trim() || `exit code ${code}`}`
19970
19970
  });
19971
19971
  }
19972
19972
  });
@@ -20366,7 +20366,7 @@ function git(args, cwd, signal, extraEnv, maxOutputBytes = 8 * 1024 * 1024) {
20366
20366
  stdio: ["ignore", "pipe", "pipe"]
20367
20367
  });
20368
20368
  const stdout12 = [];
20369
- const stderr5 = [];
20369
+ const stderr4 = [];
20370
20370
  let outputBytes = 0;
20371
20371
  let truncated = false;
20372
20372
  const timer = setTimeout(() => {
@@ -20386,7 +20386,7 @@ function git(args, cwd, signal, extraEnv, maxOutputBytes = 8 * 1024 * 1024) {
20386
20386
  if (chunk.length > remaining) truncated = true;
20387
20387
  });
20388
20388
  child.stderr.on("data", (chunk) => {
20389
- if (stderr5.reduce((sum, item) => sum + item.length, 0) < 1024 * 1024) stderr5.push(chunk);
20389
+ if (stderr4.reduce((sum, item) => sum + item.length, 0) < 1024 * 1024) stderr4.push(chunk);
20390
20390
  });
20391
20391
  child.once("error", (error) => {
20392
20392
  clearTimeout(timer);
@@ -20400,7 +20400,7 @@ function git(args, cwd, signal, extraEnv, maxOutputBytes = 8 * 1024 * 1024) {
20400
20400
  reject(new ForgeError("ABORTED", "\u5B50 Agent \u6D3E\u53D1\u5DF2\u53D6\u6D88"));
20401
20401
  return;
20402
20402
  }
20403
- resolvePromise({ code: code ?? -1, stdout: Buffer.concat(stdout12).toString("utf8"), stderr: Buffer.concat(stderr5).toString("utf8"), truncated });
20403
+ resolvePromise({ code: code ?? -1, stdout: Buffer.concat(stdout12).toString("utf8"), stderr: Buffer.concat(stderr4).toString("utf8"), truncated });
20404
20404
  });
20405
20405
  });
20406
20406
  }
@@ -22750,7 +22750,7 @@ var init_task_run_store = __esm({
22750
22750
  // apps/cli/src/task-run/review-worktree.ts
22751
22751
  import { spawn as spawn10 } from "node:child_process";
22752
22752
  import { existsSync as existsSync11, mkdirSync as mkdirSync3, realpathSync } from "node:fs";
22753
- import { basename as basename3, isAbsolute as isAbsolute10, join as join16, relative as relative14, resolve as resolve8, sep as sep14 } from "node:path";
22753
+ import { basename as basename3, isAbsolute as isAbsolute10, join as join16, relative as relative14, resolve as resolve7, sep as sep14 } from "node:path";
22754
22754
  async function inspectRepo(repoDir, run = defaultGitRunner) {
22755
22755
  const inside = await run(["rev-parse", "--is-inside-work-tree"], repoDir);
22756
22756
  if (inside.code !== 0 || inside.stdout.trim() !== "true") {
@@ -22807,7 +22807,7 @@ async function assertCleanRepo(repoDir, run = defaultGitRunner) {
22807
22807
  );
22808
22808
  }
22809
22809
  function canonicalPath(target) {
22810
- const abs = resolve8(target);
22810
+ const abs = resolve7(target);
22811
22811
  try {
22812
22812
  return realpathSync.native(abs);
22813
22813
  } catch {
@@ -23093,7 +23093,7 @@ var init_review_worktree = __esm({
23093
23093
  return;
23094
23094
  }
23095
23095
  let stdout12 = "";
23096
- let stderr5 = "";
23096
+ let stderr4 = "";
23097
23097
  const timer = setTimeout(() => {
23098
23098
  child.kill("SIGKILL");
23099
23099
  }, GIT_TIMEOUT_MS2);
@@ -23101,7 +23101,7 @@ var init_review_worktree = __esm({
23101
23101
  stdout12 += d.toString("utf8");
23102
23102
  });
23103
23103
  child.stderr.on("data", (d) => {
23104
- stderr5 += d.toString("utf8");
23104
+ stderr4 += d.toString("utf8");
23105
23105
  });
23106
23106
  child.on("error", (err) => {
23107
23107
  clearTimeout(timer);
@@ -23109,7 +23109,7 @@ var init_review_worktree = __esm({
23109
23109
  });
23110
23110
  child.on("close", (code) => {
23111
23111
  clearTimeout(timer);
23112
- resolvePromise({ code: code ?? -1, stdout: stdout12, stderr: stderr5 });
23112
+ resolvePromise({ code: code ?? -1, stdout: stdout12, stderr: stderr4 });
23113
23113
  });
23114
23114
  });
23115
23115
  STATUS_BY_CODE = {
@@ -23500,8 +23500,8 @@ var run_exports = {};
23500
23500
  __export(run_exports, {
23501
23501
  runCommand: () => runCommand
23502
23502
  });
23503
- import { createInterface as createInterface4 } from "node:readline/promises";
23504
- import { stdin as stdin3, stdout as stdout3, stderr as stderr3 } from "node:process";
23503
+ import { createInterface as createInterface3 } from "node:readline/promises";
23504
+ import { stdin as stdin2, stdout as stdout2, stderr } from "node:process";
23505
23505
  async function runCommand(args, options) {
23506
23506
  const loaded = loadConfig({
23507
23507
  cwd: options.cwd,
@@ -23531,8 +23531,8 @@ ${workflow.nodes.map((node, index) => `${index + 1}. ${node.name}: ${node.descri
23531
23531
  if (resumeRunId && (useWorktree || planOnly || workflowId || useRequirements)) {
23532
23532
  throw new ForgeError("CONFIG_INVALID", "--resume \u4E0D\u80FD\u4E0E --worktree / --plan / --workflow / --requirements \u7EC4\u5408\uFF1A\u6062\u590D\u4EFB\u52A1\u6CBF\u7528\u4E2D\u65AD\u524D\u7684\u8BA1\u5212\u548C\u8BB0\u5F55");
23533
23533
  }
23534
- const interactive = Boolean(stdin3.isTTY) && !json;
23535
- const rl = interactive ? createInterface4({ input: stdin3, output: stderr3, terminal: true }) : null;
23534
+ const interactive = Boolean(stdin2.isTTY) && !json;
23535
+ const rl = interactive ? createInterface3({ input: stdin2, output: stderr, terminal: true }) : null;
23536
23536
  let approvalHandler;
23537
23537
  if (autoApprove) {
23538
23538
  approvalHandler = () => true;
@@ -23670,7 +23670,7 @@ ${workflow.nodes.map((node, index) => `${index + 1}. ${node.name}: ${node.descri
23670
23670
  }));
23671
23671
  store.updateRun(resumeRunId, { status: "blocked", final_message: `\u6062\u590D\u88AB\u62D2\u7EDD\uFF1A${message}` });
23672
23672
  emitResult({ runId: resumeRunId, resumeError: message, analysis }, json, "failed", 2);
23673
- emitText(stderr3, json, `
23673
+ emitText(stderr, json, `
23674
23674
  \u2717 \u6062\u590D\u88AB\u62D2\u7EDD\uFF1A${message}
23675
23675
  `);
23676
23676
  return 2;
@@ -23679,12 +23679,12 @@ ${workflow.nodes.map((node, index) => `${index + 1}. ${node.name}: ${node.descri
23679
23679
  const planManager = new PlanManager({ checkpoint: store.createCheckpointManager() });
23680
23680
  let plan;
23681
23681
  if (resumed) {
23682
- emitText(stderr3, json, `
23682
+ emitText(stderr, json, `
23683
23683
  \u{1F501} \u6062\u590D\u4EFB\u52A1 ${resumed.summary.runId}\uFF08\u5FEB\u7167\u65F6\u95F4 ${resumed.record.snapshot_at}\uFF09
23684
23684
  `);
23685
23685
  plan = planManager.restoreFromCheckpoint(resumed.record);
23686
23686
  } else {
23687
- emitText(stderr3, json, "\u{1F50E} \u6B63\u5728\u8BA9\u6A21\u578B\u62C6\u89E3\u4EFB\u52A1...\n");
23687
+ emitText(stderr, json, "\u{1F50E} \u6B63\u5728\u8BA9\u6A21\u578B\u62C6\u89E3\u4EFB\u52A1...\n");
23688
23688
  const generator = new TaskPlanGenerator(createProvider(loaded.config.model, { logger }), planManager);
23689
23689
  try {
23690
23690
  const { plan: generatedPlan, adjustments, modelCallCount, tokenUsage } = await generator.generate(prompt, {
@@ -23696,7 +23696,7 @@ ${workflow.nodes.map((node, index) => `${index + 1}. ${node.name}: ${node.descri
23696
23696
  taskMetrics.modelCalls += modelCallCount;
23697
23697
  taskMetrics.totalTokens += tokenUsage;
23698
23698
  if (!json && adjustments.length > 0) {
23699
- emitText(stderr3, false, `
23699
+ emitText(stderr, false, `
23700
23700
  \u26A0\uFE0F \u5DF2\u81EA\u52A8\u8C03\u6574 ${adjustments.length} \u4E2A\u6B65\u9AA4\u7684 risk_level\uFF08\u4E0D\u4FE1\u4EFB\u6A21\u578B\u7684\u98CE\u9669\u8BC4\u4F30\uFF09
23701
23701
  `);
23702
23702
  }
@@ -23720,30 +23720,30 @@ ${workflow.nodes.map((node, index) => `${index + 1}. ${node.name}: ${node.descri
23720
23720
  throw err;
23721
23721
  }
23722
23722
  }
23723
- emitText(stderr3, json, `
23723
+ emitText(stderr, json, `
23724
23724
  \u{1F4CB} ${resumed ? "\u5DF2\u6062\u590D\u8BA1\u5212" : "\u8BA1\u5212\u5DF2\u751F\u6210"}\uFF1A${plan.steps.length} \u4E2A\u6B65\u9AA4
23725
23725
 
23726
23726
  `);
23727
23727
  for (let i = 0; i < plan.steps.length; i++) {
23728
23728
  const s = plan.steps[i];
23729
23729
  const deps = s.dependencies.length > 0 ? ` [\u2190 ${s.dependencies.join(", ")}]` : "";
23730
- emitText(stderr3, json, ` ${i + 1}. [${s.status}] ${s.description}${deps} (risk=${s.risk_level})
23730
+ emitText(stderr, json, ` ${i + 1}. [${s.status}] ${s.description}${deps} (risk=${s.risk_level})
23731
23731
  `);
23732
23732
  }
23733
23733
  if (useRequirements) {
23734
23734
  requirementReport = createRequirementReport(prompt, plan);
23735
- emitText(stderr3, json, `
23735
+ emitText(stderr, json, `
23736
23736
  \u9700\u6C42\u9A8C\u6536\u8349\u6848\uFF08${requirementReport.requirement.acceptanceCriteria.length} \u9879\uFF0C\u5747\u5F85\u7528\u6237\u786E\u8BA4\uFF09\uFF1A
23737
23737
  `);
23738
23738
  for (const [index, criterion] of requirementReport.requirement.acceptanceCriteria.entries()) {
23739
- emitText(stderr3, json, ` ${index + 1}. ${criterion.description} [${criterion.verificationMethod}]
23739
+ emitText(stderr, json, ` ${index + 1}. ${criterion.description} [${criterion.verificationMethod}]
23740
23740
  `);
23741
23741
  }
23742
- emitText(stderr3, json, ` \u5C31\u7EEA\u5206\u6790\uFF1A${requirementReport.analysis.ready ? "ready" : requirementReport.analysis.reasons.join("\uFF1B")}
23742
+ emitText(stderr, json, ` \u5C31\u7EEA\u5206\u6790\uFF1A${requirementReport.analysis.ready ? "ready" : requirementReport.analysis.reasons.join("\uFF1B")}
23743
23743
  `);
23744
23744
  }
23745
23745
  if (planOnly) {
23746
- emitText(stderr3, json, `
23746
+ emitText(stderr, json, `
23747
23747
  \u2713 \u8BA1\u5212\u751F\u6210\u5B8C\u6BD5\uFF08--plan \u6A21\u5F0F\uFF1A\u4E0D\u6267\u884C\u4EFB\u4F55\u5199\u64CD\u4F5C\uFF09
23748
23748
  `);
23749
23749
  emitResult({ plan, ...workflow ? { workflowId: workflow.id } : {}, ...requirementReport ? { requirementReport } : {} }, json, "planned", 0);
@@ -23751,7 +23751,7 @@ ${workflow.nodes.map((node, index) => `${index + 1}. ${node.name}: ${node.descri
23751
23751
  }
23752
23752
  if (useWorktree && !resumed) {
23753
23753
  emitText(
23754
- stderr3,
23754
+ stderr,
23755
23755
  json,
23756
23756
  `
23757
23757
  \u{1F33F} --worktree\uFF1A\u5C06\u5728 ${loaded.config.worktree.root} \u4E0B\u521B\u5EFA\u72EC\u7ACB\u5DE5\u4F5C\u6811\u4E0E\u5206\u652F\uFF08\u53EA\u9694\u79BB\u5DE5\u4F5C\u533A\u4E0E\u6539\u52A8\uFF0C\u4E0D\u662F OS \u6C99\u7BB1\uFF09
@@ -23760,7 +23760,7 @@ ${workflow.nodes.map((node, index) => `${index + 1}. ${node.name}: ${node.descri
23760
23760
  }
23761
23761
  if (resumed && worktree) {
23762
23762
  emitText(
23763
- stderr3,
23763
+ stderr,
23764
23764
  json,
23765
23765
  `
23766
23766
  \u{1F33F} \u6CBF\u7528\u5DF2\u6709\u9694\u79BB worktree\uFF08\u4E0D\u91CD\u5EFA\u3001\u4E0D\u79FB\u52A8\uFF09
@@ -23773,11 +23773,11 @@ ${workflow.nodes.map((node, index) => `${index + 1}. ${node.name}: ${node.descri
23773
23773
  if (!resumed) {
23774
23774
  let userConfirmed = autoApprove;
23775
23775
  if (rl && !autoApprove) {
23776
- emitText(stderr3, false, "\n\u5F00\u59CB\u6267\u884C\u4EE5\u4E0A\u8BA1\u5212\uFF1F(y/N) ");
23776
+ emitText(stderr, false, "\n\u5F00\u59CB\u6267\u884C\u4EE5\u4E0A\u8BA1\u5212\uFF1F(y/N) ");
23777
23777
  const answer = (await rl.question("")).trim();
23778
23778
  userConfirmed = /^y(es)?$/i.test(answer);
23779
23779
  if (!userConfirmed) {
23780
- emitText(stderr3, false, "\n\u5DF2\u53D6\u6D88\n");
23780
+ emitText(stderr, false, "\n\u5DF2\u53D6\u6D88\n");
23781
23781
  emitResult({ plan, cancellationReason: "\u7528\u6237\u62D2\u7EDD\u8BA1\u5212\u6267\u884C" }, json, "aborted", 1);
23782
23782
  return 1;
23783
23783
  }
@@ -23785,7 +23785,7 @@ ${workflow.nodes.map((node, index) => `${index + 1}. ${node.name}: ${node.descri
23785
23785
  const hasApprovalGates = loaded.config.security.requireApprovalForWrite || loaded.config.security.requireApprovalForExecute;
23786
23786
  if (!autoApprove && !rl && !hasApprovalGates) {
23787
23787
  const reason = "\u975E\u4EA4\u4E92\u6A21\u5F0F\u4E0B\u5FC5\u987B\u663E\u5F0F\u4F20\u5165 --yes \u624D\u80FD\u6267\u884C\u8BA1\u5212\uFF1B\u5F53\u524D\u7B56\u7565\u672A\u8BBE\u7F6E\u5199\u5165\u6216\u6267\u884C\u5BA1\u6279\u95E8\u69DB";
23788
- emitText(stderr3, json, `
23788
+ emitText(stderr, json, `
23789
23789
  \u26D4 ${reason}
23790
23790
  `);
23791
23791
  emitResult({ plan, cancellationReason: reason }, json, "aborted", 1);
@@ -23825,7 +23825,7 @@ ${workflow.nodes.map((node, index) => `${index + 1}. ${node.name}: ${node.descri
23825
23825
  loaded.config.security.workspaceRoots = [worktree.path];
23826
23826
  loaded.config.security.writableRoots = [worktree.path];
23827
23827
  emitText(
23828
- stderr3,
23828
+ stderr,
23829
23829
  json,
23830
23830
  `
23831
23831
  \u{1F33F} \u5DF2\u521B\u5EFA\u9694\u79BB worktree
@@ -23874,7 +23874,7 @@ ${workflow.nodes.map((node, index) => `${index + 1}. ${node.name}: ${node.descri
23874
23874
  }
23875
23875
  });
23876
23876
  }
23877
- emitText(stderr3, json, "\n\u{1F680} \u5F00\u59CB\u6267\u884C\u8BA1\u5212...\n");
23877
+ emitText(stderr, json, "\n\u{1F680} \u5F00\u59CB\u6267\u884C\u8BA1\u5212...\n");
23878
23878
  const executor = new StepExecutor({
23879
23879
  planManager,
23880
23880
  agent: runtime.agent,
@@ -23921,7 +23921,7 @@ ${failedSteps || ""}
23921
23921
  onStepResult: persistStepResult
23922
23922
  });
23923
23923
  const execDurationMs = Date.now() - execStart;
23924
- emitText(stderr3, json, `
23924
+ emitText(stderr, json, `
23925
23925
  \u2705 \u6267\u884C\u5B8C\u6210\uFF1A${execResult.completed}/${execResult.total_steps} \u6B65\u6210\u529F\uFF0C${execResult.failed} \u5931\u8D25\uFF0C${execResult.cancelled} \u53D6\u6D88\uFF08${execDurationMs}ms\uFF09
23926
23926
  `);
23927
23927
  if (execResult.plan_status !== "completed" || execResult.failed > 0 || execResult.cancelled > 0 || execResult.truncated) {
@@ -23949,7 +23949,7 @@ ${failedSteps || ""}
23949
23949
  );
23950
23950
  return 1;
23951
23951
  }
23952
- emitText(stderr3, json, "\n\u{1F50D} \u8FD0\u884C\u8D28\u91CF\u95E8\u7981...\n");
23952
+ emitText(stderr, json, "\n\u{1F50D} \u8FD0\u884C\u8D28\u91CF\u95E8\u7981...\n");
23953
23953
  const gate = new ProductionQualityGate(runtime);
23954
23954
  const gateResult = await gate.run({
23955
23955
  cwd: runtime.settings.workspaceRoots[0] ?? options.cwd,
@@ -23973,10 +23973,10 @@ ${failedSteps || ""}
23973
23973
  }
23974
23974
  for (const s of gateResult.stages) {
23975
23975
  if (s.note) {
23976
- emitText(stderr3, json, ` \u2796 ${s.name}: ${s.note}
23976
+ emitText(stderr, json, ` \u2796 ${s.name}: ${s.note}
23977
23977
  `);
23978
23978
  } else {
23979
- emitText(stderr3, json, ` ${s.passed ? "\u2705" : "\u274C"} ${s.name}: ${s.command} \u2192 exit=${s.exit_code} (${s.duration_ms}ms)${s.failure_summary ? "\n " + s.failure_summary.split("\n").join("\n ") : ""}
23979
+ emitText(stderr, json, ` ${s.passed ? "\u2705" : "\u274C"} ${s.name}: ${s.command} \u2192 exit=${s.exit_code} (${s.duration_ms}ms)${s.failure_summary ? "\n " + s.failure_summary.split("\n").join("\n ") : ""}
23980
23980
  `);
23981
23981
  }
23982
23982
  }
@@ -24092,7 +24092,7 @@ function worktreeInfo(worktree) {
24092
24092
  }
24093
24093
  function emitWorktreeFooter(worktree, json) {
24094
24094
  if (json) return;
24095
- stdout3.write(
24095
+ stdout2.write(
24096
24096
  [
24097
24097
  "",
24098
24098
  "\u{1F4E6} \u4EA7\u7269\u4FDD\u5B58\u5728\u9694\u79BB worktree\uFF08\u672A\u5408\u5E76\u3001\u672A\u590D\u5236\u56DE\u539F\u5DE5\u4F5C\u533A\u3001\u672A\u5220\u9664\uFF09",
@@ -24106,7 +24106,7 @@ function emitWorktreeFooter(worktree, json) {
24106
24106
  }
24107
24107
  function emitResult(payload, json, status, exitCode) {
24108
24108
  if (json) {
24109
- stdout3.write(
24109
+ stdout2.write(
24110
24110
  JSON.stringify(
24111
24111
  {
24112
24112
  runId: payload.runId ?? null,
@@ -24120,27 +24120,27 @@ function emitResult(payload, json, status, exitCode) {
24120
24120
  );
24121
24121
  } else {
24122
24122
  const banner = status === "completed" ? "\u{1F389} \u4EFB\u52A1\u5B8C\u6210\uFF08\u8D28\u91CF\u95E8\u7981\u901A\u8FC7\uFF09" : status === "failed" ? "\u274C \u4EFB\u52A1\u5931\u8D25" : status === "blocked" ? "\u26A0\uFE0F \u4EFB\u52A1\u88AB\u963B\u585E" : status === "unverified" ? "\u{1F50E} \u4EFB\u52A1\u6267\u884C\u4F46\u672A\u9A8C\u8BC1\uFF08\u65E0\u53EF\u7528\u6D4B\u8BD5\u811A\u672C\uFF09" : status === "aborted" ? "\u23F9\uFE0F \u4EFB\u52A1\u53D6\u6D88" : status === "invalid_plan" ? "\u{1F6AB} \u8BA1\u5212\u751F\u6210\u5931\u8D25" : "\u{1F4CB} \u8BA1\u5212\u5DF2\u751F\u6210";
24123
- stdout3.write(`
24123
+ stdout2.write(`
24124
24124
  ${banner}
24125
24125
  `);
24126
24126
  if (status !== "planned" && status !== "invalid_plan") {
24127
24127
  const plan = payload.plan;
24128
24128
  const exec = payload.execution;
24129
24129
  if (plan && exec) {
24130
- stdout3.write(` ${exec.completed ?? 0}/${exec.total_steps ?? plan.steps.length} \u6B65\u5B8C\u6210\uFF0C${exec.failed ?? 0} \u5931\u8D25\uFF0C${exec.cancelled ?? 0} \u53D6\u6D88
24130
+ stdout2.write(` ${exec.completed ?? 0}/${exec.total_steps ?? plan.steps.length} \u6B65\u5B8C\u6210\uFF0C${exec.failed ?? 0} \u5931\u8D25\uFF0C${exec.cancelled ?? 0} \u53D6\u6D88
24131
24131
  `);
24132
24132
  }
24133
24133
  const gate = payload.gateResult;
24134
- if (gate) stdout3.write(` \u8D28\u91CF\u95E8\u7981: ${gate.verdict}\uFF08${gate.run_count}/${gate.total_count} \u9636\u6BB5\uFF09
24134
+ if (gate) stdout2.write(` \u8D28\u91CF\u95E8\u7981: ${gate.verdict}\uFF08${gate.run_count}/${gate.total_count} \u9636\u6BB5\uFF09
24135
24135
  `);
24136
- if (payload.worktree) stdout3.write(` \u9694\u79BB worktree: ${payload.worktree.path}\uFF08\u5206\u652F ${payload.worktree.branch}\uFF09
24136
+ if (payload.worktree) stdout2.write(` \u9694\u79BB worktree: ${payload.worktree.path}\uFF08\u5206\u652F ${payload.worktree.branch}\uFF09
24137
24137
  `);
24138
24138
  }
24139
- if (payload.planError) stdout3.write(` \u8BA1\u5212\u9519\u8BEF: ${payload.planError}
24139
+ if (payload.planError) stdout2.write(` \u8BA1\u5212\u9519\u8BEF: ${payload.planError}
24140
24140
  `);
24141
- if (payload.worktreeError) stdout3.write(` \u9694\u79BB\u5931\u8D25: ${payload.worktreeError}
24141
+ if (payload.worktreeError) stdout2.write(` \u9694\u79BB\u5931\u8D25: ${payload.worktreeError}
24142
24142
  `);
24143
- if (payload.cancellationReason) stdout3.write(` ${payload.cancellationReason}
24143
+ if (payload.cancellationReason) stdout2.write(` ${payload.cancellationReason}
24144
24144
  `);
24145
24145
  }
24146
24146
  }
@@ -24148,9 +24148,9 @@ function emitText(stream, json, text) {
24148
24148
  if (!json) stream.write(text);
24149
24149
  }
24150
24150
  async function readStdin() {
24151
- if (stdin3.isTTY) return "";
24151
+ if (stdin2.isTTY) return "";
24152
24152
  const chunks = [];
24153
- for await (const chunk of stdin3) chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk)));
24153
+ for await (const chunk of stdin2) chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk)));
24154
24154
  return Buffer.concat(chunks).toString("utf8");
24155
24155
  }
24156
24156
  var init_run = __esm({
@@ -24177,7 +24177,7 @@ var init_run = __esm({
24177
24177
  // apps/cli/src/main.ts
24178
24178
  init_dist();
24179
24179
  init_args();
24180
- import { stderr as stderr4, stdout as stdout11 } from "node:process";
24180
+ import { stderr as stderr3, stdout as stdout11 } from "node:process";
24181
24181
 
24182
24182
  // apps/cli/src/commands/chat.ts
24183
24183
  init_dist();
@@ -24187,7 +24187,6 @@ init_setup_hint();
24187
24187
  init_create_runtime();
24188
24188
  import React2 from "react";
24189
24189
  import { render } from "ink";
24190
- import { stderr as stderr2 } from "node:process";
24191
24190
 
24192
24191
  // apps/cli/src/ui/App.tsx
24193
24192
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
@@ -24977,7 +24976,7 @@ function applyApiKey(runtime, key) {
24977
24976
  }
24978
24977
 
24979
24978
  // apps/cli/src/version.ts
24980
- var VERSION = "0.6.1";
24979
+ var VERSION = "0.6.2";
24981
24980
 
24982
24981
  // apps/cli/src/ui/input-edit.ts
24983
24982
  function applyInputKey(state, char, key) {
@@ -26745,131 +26744,6 @@ function printHelp(extensionCommands = []) {
26745
26744
  );
26746
26745
  }
26747
26746
 
26748
- // apps/cli/src/commands/connect.ts
26749
- init_args();
26750
- import { createInterface as createInterface3 } from "node:readline/promises";
26751
- import { resolve as resolve7 } from "node:path";
26752
- import { stderr, stdin as stdin2, stdout as stdout2 } from "node:process";
26753
- async function connectCommand(args, _options) {
26754
- const isInteractive = Boolean(stdin2.isTTY);
26755
- const configPath = defaultConfigPath();
26756
- const existing = readExistingConfig(configPath);
26757
- if (!isInteractive) {
26758
- const provider = flagString(args.flags, "provider") ?? "custom";
26759
- const apiKey = flagString(args.flags, "api-key") ?? "";
26760
- const preset = PROVIDERS[provider.toLowerCase()];
26761
- const baseUrl = flagString(args.flags, "base-url") ?? preset?.defaultBaseUrl ?? "";
26762
- const model = flagString(args.flags, "model") ?? preset?.defaultModel ?? "";
26763
- if (!apiKey) {
26764
- stderr.write("[connect] --api-key \u5728\u975E\u4EA4\u4E92\u6A21\u5F0F\u4E0B\u5FC5\u586B\n");
26765
- return 2;
26766
- }
26767
- return await doConnect({ provider, apiKey, baseUrl, model, configPath, existing });
26768
- }
26769
- stdout2.write("ForgeX Connect \u2014 \u8FDE\u63A5\u4F60\u7684\u6A21\u578B\u63D0\u4F9B\u65B9\n\n");
26770
- const rl = createInterface3({ input: stdin2, output: stderr });
26771
- try {
26772
- stdout2.write("\u9009\u62E9\u6A21\u578B\u63D0\u4F9B\u65B9\uFF08\u8F93\u5165\u7F16\u53F7\u6216\u540D\u79F0\uFF09\uFF1A\n");
26773
- PROVIDERS_KEYS.forEach((key, i) => {
26774
- const p = PROVIDERS[key];
26775
- stdout2.write(` ${i + 1}. ${p.name} (${p.defaultBaseUrl})
26776
- `);
26777
- });
26778
- stdout2.write("\n> ");
26779
- const providerInput = (await rl.question("")).trim();
26780
- const provider = resolveProvider(providerInput);
26781
- const preset = PROVIDERS[provider];
26782
- const baseUrlDefault = preset?.defaultBaseUrl ?? existing.model.baseUrl;
26783
- stdout2.write(`baseUrl [${baseUrlDefault}]: `);
26784
- const baseUrl = (await rl.question("")).trim() || baseUrlDefault;
26785
- stdout2.write("\nAPI Key\uFF08\u8F93\u5165\u4E0D\u4F1A\u88AB\u9690\u85CF\uFF0C\u7C98\u8D34\u540E\u6309\u56DE\u8F66\uFF09: ");
26786
- const apiKey = (await rl.question("")).trim();
26787
- if (!apiKey) {
26788
- stderr.write("[connect] API Key \u4E0D\u80FD\u4E3A\u7A7A\n");
26789
- return 2;
26790
- }
26791
- const modelDefault = preset?.defaultModel ?? existing.model.model;
26792
- stdout2.write(`
26793
- \u6A21\u578B\u540D [${modelDefault}]: `);
26794
- const model = (await rl.question("")).trim() || modelDefault;
26795
- const saveDefault = configPath;
26796
- stdout2.write(`
26797
- \u4FDD\u5B58\u914D\u7F6E\u5230 [${saveDefault}]\uFF1A`);
26798
- const saveInput = (await rl.question("")).trim();
26799
- const finalConfigPath = saveInput ? resolve7(saveInput) : saveDefault;
26800
- stdout2.write("\n--------------------------------------------\n");
26801
- stdout2.write(`Provider : ${provider}
26802
- `);
26803
- stdout2.write(`Base URL : ${baseUrl}
26804
- `);
26805
- stdout2.write(`Model : ${model}
26806
- `);
26807
- stdout2.write(`API Key : ${maskKey(apiKey)}
26808
- `);
26809
- stdout2.write(`Config : ${finalConfigPath}
26810
- `);
26811
- stdout2.write("--------------------------------------------\n");
26812
- stdout2.write("\u8FDE\u901A\u6027\u6D4B\u8BD5\u4E2D\uFF085s \u8D85\u65F6\uFF09...\n");
26813
- return await doConnect({ provider, apiKey, baseUrl, model, configPath: finalConfigPath, existing });
26814
- } finally {
26815
- rl.close();
26816
- }
26817
- }
26818
- async function doConnect(params) {
26819
- const { provider, apiKey, baseUrl, model, configPath, existing } = params;
26820
- const testResult = await testConnectivity({ baseUrl, apiKey, model });
26821
- if (!testResult.ok) {
26822
- stderr.write(`
26823
- [FAIL] \u8FDE\u901A\u6027\u6D4B\u8BD5\u5931\u8D25\uFF1A${testResult.reason}
26824
- `);
26825
- if (testResult.detail) stderr.write(` ${testResult.detail}
26826
- `);
26827
- stderr.write("\n\u63D0\u793A\uFF1A\n");
26828
- stderr.write(" \xB7 \u786E\u8BA4 API Key \u6709\u6548\uFF1A\u53BB provider \u63A7\u5236\u53F0\u65B0\u5EFA\u4E00\u4E2A\n");
26829
- stderr.write(" \xB7 \u786E\u8BA4 baseUrl \u6B63\u786E\uFF08DeepSeek: https://api.deepseek.com\uFF09\n");
26830
- stderr.write(" \xB7 \u786E\u8BA4\u6A21\u578B\u540D\uFF08DeepSeek: deepseek-flash / deepseek-v4-pro\uFF09\n");
26831
- return 1;
26832
- }
26833
- const preset = PROVIDERS[provider];
26834
- const envName = preset?.apiKeyEnv ?? provider.toUpperCase().replace(/[^A-Z0-9_]/g, "_") + "_API_KEY";
26835
- const envPersisted = persistApiKey(envName, apiKey);
26836
- process.env[envName] = apiKey;
26837
- saveConnectionConfig(configPath, existing, {
26838
- baseUrl,
26839
- model,
26840
- envName,
26841
- ...preset ? { contextWindow: preset.contextWindow, maxOutputTokens: preset.maxOutputTokens } : {}
26842
- });
26843
- stdout2.write(`
26844
- [OK] \u8FDE\u901A\u6027\u6D4B\u8BD5\u901A\u8FC7 \u2705
26845
- `);
26846
- stdout2.write(` \u54CD\u5E94\u8017\u65F6: ${testResult.latencyMs}ms
26847
- `);
26848
- stdout2.write(`
26849
- \u914D\u7F6E\u5DF2\u5199\u5165\uFF1A${configPath}
26850
- `);
26851
- stdout2.write(`API Key \u6301\u4E45\u5316\uFF1A`);
26852
- if (envPersisted.ok) {
26853
- stdout2.write(`\u2705 ${envName} \u2192 ${envPersisted.hint}
26854
- `);
26855
- stdout2.write(` \u5F53\u524D\u4F1A\u8BDD\u5DF2\u751F\u6548\uFF0C\u91CD\u5F00\u4F1A\u8BDD\u81EA\u52A8\u8BFB\u53D6 \u2705
26856
- `);
26857
- } else {
26858
- stdout2.write(`\u26A0\uFE0F \u9700\u624B\u52A8\u8BBE\u7F6E\uFF1A
26859
- `);
26860
- stdout2.write(` ${envPersisted.hint}
26861
- `);
26862
- }
26863
- stdout2.write(`
26864
- \u73B0\u5728\u53EF\u4EE5\u8DD1\uFF1A
26865
- `);
26866
- stdout2.write(` forgex run "\u4F60\u597D\uFF0C\u4ECB\u7ECD\u4E00\u4E0B ForgeX"
26867
- `);
26868
- stdout2.write(` forgex doctor
26869
- `);
26870
- return 0;
26871
- }
26872
-
26873
26747
  // apps/cli/src/commands/chat.ts
26874
26748
  async function chatCommand(args, options) {
26875
26749
  const configFlag = flagString(args.flags, "config");
@@ -26879,24 +26753,12 @@ async function chatCommand(args, options) {
26879
26753
  ...configFlag ? { configPath: configFlag } : {},
26880
26754
  ...modeFlag ? { permissionMode: modeFlag } : {}
26881
26755
  });
26882
- let loaded = readConfig();
26756
+ const loaded = readConfig();
26883
26757
  if (!loaded.modelConfigured) {
26884
26758
  const interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY);
26885
26759
  if (!interactive) {
26886
26760
  throw new ForgeError("CONFIG_INVALID", modelSetupHint({ interactive: false }));
26887
26761
  }
26888
- stderr2.write("\u5C1A\u672A\u914D\u7F6E\u6A21\u578B\uFF0C\u5148\u8FDB\u5165\u8FDE\u63A5\u5411\u5BFC\uFF08Ctrl+C \u53EF\u53D6\u6D88\uFF09\n\n");
26889
- const code = await connectCommand(args, { cwd: options.cwd });
26890
- if (code !== 0) {
26891
- throw new ForgeError("CONFIG_INVALID", "\u6A21\u578B\u8FDE\u63A5\u672A\u5B8C\u6210\uFF0C\u5DF2\u9000\u51FA\u3002\u7A0D\u540E\u53EF\u91CD\u65B0\u6267\u884C\uFF1Aforgex connect");
26892
- }
26893
- loaded = readConfig();
26894
- if (!loaded.modelConfigured) {
26895
- throw new ForgeError(
26896
- "CONFIG_INVALID",
26897
- `\u8FDE\u63A5\u5411\u5BFC\u6CA1\u6709\u751F\u6210\u53EF\u7528\u7684\u6A21\u578B\u914D\u7F6E\uFF08${loaded.configPath ?? "\u672A\u627E\u5230\u914D\u7F6E\u6587\u4EF6"}\uFF09\uFF0C\u8BF7\u68C0\u67E5\u4FDD\u5B58\u8DEF\u5F84\u540E\u91CD\u8BD5`
26898
- );
26899
- }
26900
26762
  }
26901
26763
  const bridge = new ApprovalBridge();
26902
26764
  const runtime = createRuntime({
@@ -26939,7 +26801,7 @@ init_permission_mode();
26939
26801
  import { execFile as execFile3 } from "node:child_process";
26940
26802
  import { accessSync as accessSync3, constants as constants3, existsSync as existsSync13 } from "node:fs";
26941
26803
  import { dirname as dirname6 } from "node:path";
26942
- import { stdout as stdout4 } from "node:process";
26804
+ import { stdout as stdout3 } from "node:process";
26943
26805
  async function doctorCommand(args, options) {
26944
26806
  const checks = [];
26945
26807
  const full = flagBool(args.flags, "full");
@@ -27123,20 +26985,20 @@ async function doctorCommand(args, options) {
27123
26985
  detail: `mode=${loaded.config.security.mode} \u5199\u5BA1\u6279=${loaded.config.security.requireApprovalForWrite} \u6267\u884C\u5BA1\u6279=${loaded.config.security.requireApprovalForExecute}`
27124
26986
  });
27125
26987
  }
27126
- stdout4.write("ForgeX \u73AF\u5883\u81EA\u68C0\n");
26988
+ stdout3.write("ForgeX \u73AF\u5883\u81EA\u68C0\n");
27127
26989
  for (const check of checks) {
27128
- stdout4.write(`[${label(check.status)}] ${check.name}: ${check.detail}
26990
+ stdout3.write(`[${label(check.status)}] ${check.name}: ${check.detail}
27129
26991
  `);
27130
26992
  }
27131
26993
  const failed = checks.filter((check) => check.status === "fail").length;
27132
26994
  const warned = checks.filter((check) => check.status === "warn").length;
27133
- stdout4.write(`
26995
+ stdout3.write(`
27134
26996
  \u7ED3\u679C\uFF1A${checks.length} \u9879\u68C0\u67E5\uFF0C${failed} \u9879\u5931\u8D25\uFF0C${warned} \u9879\u8B66\u544A
27135
26997
  `);
27136
26998
  if (full && sandboxReport) {
27137
- stdout4.write("\n\u6C99\u7BB1\u80FD\u529B\u660E\u7EC6\n");
26999
+ stdout3.write("\n\u6C99\u7BB1\u80FD\u529B\u660E\u7EC6\n");
27138
27000
  for (const line of describeCapabilityReport(sandboxReport)) {
27139
- stdout4.write(` ${line}
27001
+ stdout3.write(` ${line}
27140
27002
  `);
27141
27003
  }
27142
27004
  }
@@ -27171,21 +27033,21 @@ function formatBytes2(bytes) {
27171
27033
 
27172
27034
  // apps/cli/src/commands/tools.ts
27173
27035
  init_dist5();
27174
- import { stdout as stdout5 } from "node:process";
27036
+ import { stdout as stdout4 } from "node:process";
27175
27037
  function toolsCommand() {
27176
27038
  const registry = new ToolRegistry(createBuiltinTools());
27177
27039
  const tools = registry.list();
27178
- stdout5.write(`ForgeX \u5185\u7F6E\u5DE5\u5177\uFF08${tools.length} \u4E2A\uFF09
27040
+ stdout4.write(`ForgeX \u5185\u7F6E\u5DE5\u5177\uFF08${tools.length} \u4E2A\uFF09
27179
27041
 
27180
27042
  `);
27181
27043
  for (const tool of tools) {
27182
27044
  const tags = tool.tags && tool.tags.length > 0 ? ` \u6807\u7B7E=${tool.tags.join(",")}` : "";
27183
- stdout5.write(`- ${tool.name} [${tool.riskLevel}] \u8D85\u65F6=${tool.timeoutMs}ms \u8F93\u51FA\u4E0A\u9650=${tool.maxOutputBytes}B${tags}
27045
+ stdout4.write(`- ${tool.name} [${tool.riskLevel}] \u8D85\u65F6=${tool.timeoutMs}ms \u8F93\u51FA\u4E0A\u9650=${tool.maxOutputBytes}B${tags}
27184
27046
  `);
27185
- stdout5.write(` ${tool.description.split("\n")[0]}
27047
+ stdout4.write(` ${tool.description.split("\n")[0]}
27186
27048
  `);
27187
27049
  }
27188
- stdout5.write(
27050
+ stdout4.write(
27189
27051
  "\n\u8BF4\u660E\uFF1A\u98CE\u9669\u7B49\u7EA7\u51B3\u5B9A\u9ED8\u8BA4\u6743\u9650\u7B56\u7565\uFF1Bexecute \u7EA7\u547D\u4EE4\u9ED8\u8BA4\u9700\u8981\u4EBA\u5DE5\u5BA1\u6279\uFF0Cprivileged \u7EA7\u9ED8\u8BA4\u62D2\u7EDD\u3002\n\u6B64\u5217\u8868\u4E0D\u5305\u542B\u9700\u8981\u4F1A\u8BDD\u8FD0\u884C\u65F6\u6267\u884C\u5668\u6CE8\u5165\u7684\u5DE5\u5177\u3002\n"
27190
27052
  );
27191
27053
  return 0;
@@ -27196,7 +27058,7 @@ init_dist6();
27196
27058
  init_args();
27197
27059
  init_load_config();
27198
27060
  import { existsSync as existsSync14 } from "node:fs";
27199
- import { stdout as stdout6 } from "node:process";
27061
+ import { stdout as stdout5 } from "node:process";
27200
27062
  function sessionsCommand(args, options) {
27201
27063
  const loaded = loadConfig({
27202
27064
  cwd: options.cwd,
@@ -27206,7 +27068,7 @@ function sessionsCommand(args, options) {
27206
27068
  const action = args.positionals[0];
27207
27069
  const sourceId = args.positionals[1];
27208
27070
  if (!existsSync14(dbPath) && action !== "fork") {
27209
- stdout6.write(`\u4F1A\u8BDD\u4E8B\u4EF6\u65E5\u5FD7\u5C1A\u672A\u521B\u5EFA: ${dbPath}
27071
+ stdout5.write(`\u4F1A\u8BDD\u4E8B\u4EF6\u65E5\u5FD7\u5C1A\u672A\u521B\u5EFA: ${dbPath}
27210
27072
  `);
27211
27073
  return 0;
27212
27074
  }
@@ -27215,29 +27077,29 @@ function sessionsCommand(args, options) {
27215
27077
  try {
27216
27078
  if (action === "fork") {
27217
27079
  if (!sourceId) {
27218
- stdout6.write("\u7528\u6CD5: forgex sessions fork <sessionId> [--at <messageEventId>]\n");
27080
+ stdout5.write("\u7528\u6CD5: forgex sessions fork <sessionId> [--at <messageEventId>]\n");
27219
27081
  return 2;
27220
27082
  }
27221
27083
  const branch = store.forkSession(sourceId, flagString(args.flags, "at"));
27222
- stdout6.write(`\u5DF2\u521B\u5EFA\u4F1A\u8BDD\u5206\u652F: ${branch.id}
27084
+ stdout5.write(`\u5DF2\u521B\u5EFA\u4F1A\u8BDD\u5206\u652F: ${branch.id}
27223
27085
  \u7EE7\u7EED\u4F7F\u7528: forgex chat --session ${branch.id}
27224
27086
  `);
27225
27087
  return 0;
27226
27088
  }
27227
27089
  const sessions = store.listSessions(limit);
27228
27090
  if (sessions.length === 0) {
27229
- stdout6.write("\u6682\u65E0\u4F1A\u8BDD\u8BB0\u5F55\n");
27091
+ stdout5.write("\u6682\u65E0\u4F1A\u8BDD\u8BB0\u5F55\n");
27230
27092
  return 0;
27231
27093
  }
27232
- stdout6.write(`\u6700\u8FD1 ${sessions.length} \u4E2A\u4F1A\u8BDD\uFF08\u4E8B\u4EF6\u65E5\u5FD7: ${dbPath}\uFF09
27094
+ stdout5.write(`\u6700\u8FD1 ${sessions.length} \u4E2A\u4F1A\u8BDD\uFF08\u4E8B\u4EF6\u65E5\u5FD7: ${dbPath}\uFF09
27233
27095
 
27234
27096
  `);
27235
27097
  for (const session of sessions) {
27236
27098
  const title = session.title ?? "(\u672A\u547D\u540D)";
27237
- stdout6.write(`${session.id} ${session.updatedAt} ${session.model} ${title}
27099
+ stdout5.write(`${session.id} ${session.updatedAt} ${session.model} ${title}
27238
27100
  `);
27239
27101
  }
27240
- stdout6.write('\n\u4F7F\u7528 forgex chat --session <id> \u6062\u590D\u4F1A\u8BDD\uFF1Bforgex run --session <id> "..." \u7EE7\u7EED\u4EFB\u52A1\u3002\n');
27102
+ stdout5.write('\n\u4F7F\u7528 forgex chat --session <id> \u6062\u590D\u4F1A\u8BDD\uFF1Bforgex run --session <id> "..." \u7EE7\u7EED\u4EFB\u52A1\u3002\n');
27241
27103
  return 0;
27242
27104
  } finally {
27243
27105
  store.close();
@@ -27247,7 +27109,7 @@ function sessionsCommand(args, options) {
27247
27109
  // apps/cli/src/commands/config.ts
27248
27110
  init_args();
27249
27111
  init_load_config();
27250
- import { stdout as stdout7 } from "node:process";
27112
+ import { stdout as stdout6 } from "node:process";
27251
27113
  function configCommand(args, options) {
27252
27114
  const loaded = loadConfig({
27253
27115
  cwd: options.cwd,
@@ -27255,7 +27117,7 @@ function configCommand(args, options) {
27255
27117
  ...flagString(args.flags, "mode") ? { permissionMode: flagString(args.flags, "mode") } : {}
27256
27118
  });
27257
27119
  const { apiKey, ...safeModel } = loaded.config.model;
27258
- stdout7.write(
27120
+ stdout6.write(
27259
27121
  `${JSON.stringify(
27260
27122
  {
27261
27123
  configPath: loaded.configPath,
@@ -27274,8 +27136,133 @@ function configCommand(args, options) {
27274
27136
  `
27275
27137
  );
27276
27138
  if (!loaded.modelConfigured) {
27277
- stdout7.write("\n[warn] \u5C1A\u672A\u914D\u7F6E\u6A21\u578B\uFF1A\u8BF7\u8BBE\u7F6E forgex.config.json \u6216 FORGEX_BASE_URL / FORGEX_MODEL\u3002\n");
27139
+ stdout6.write("\n[warn] \u5C1A\u672A\u914D\u7F6E\u6A21\u578B\uFF1A\u8BF7\u8BBE\u7F6E forgex.config.json \u6216 FORGEX_BASE_URL / FORGEX_MODEL\u3002\n");
27140
+ }
27141
+ return 0;
27142
+ }
27143
+
27144
+ // apps/cli/src/commands/connect.ts
27145
+ init_args();
27146
+ import { createInterface as createInterface4 } from "node:readline/promises";
27147
+ import { resolve as resolve8 } from "node:path";
27148
+ import { stderr as stderr2, stdin as stdin3, stdout as stdout7 } from "node:process";
27149
+ async function connectCommand(args, _options) {
27150
+ const isInteractive = Boolean(stdin3.isTTY);
27151
+ const configPath = defaultConfigPath();
27152
+ const existing = readExistingConfig(configPath);
27153
+ if (!isInteractive) {
27154
+ const provider = flagString(args.flags, "provider") ?? "custom";
27155
+ const apiKey = flagString(args.flags, "api-key") ?? "";
27156
+ const preset = PROVIDERS[provider.toLowerCase()];
27157
+ const baseUrl = flagString(args.flags, "base-url") ?? preset?.defaultBaseUrl ?? "";
27158
+ const model = flagString(args.flags, "model") ?? preset?.defaultModel ?? "";
27159
+ if (!apiKey) {
27160
+ stderr2.write("[connect] --api-key \u5728\u975E\u4EA4\u4E92\u6A21\u5F0F\u4E0B\u5FC5\u586B\n");
27161
+ return 2;
27162
+ }
27163
+ return await doConnect({ provider, apiKey, baseUrl, model, configPath, existing });
27164
+ }
27165
+ stdout7.write("ForgeX Connect \u2014 \u8FDE\u63A5\u4F60\u7684\u6A21\u578B\u63D0\u4F9B\u65B9\n\n");
27166
+ const rl = createInterface4({ input: stdin3, output: stderr2 });
27167
+ try {
27168
+ stdout7.write("\u9009\u62E9\u6A21\u578B\u63D0\u4F9B\u65B9\uFF08\u8F93\u5165\u7F16\u53F7\u6216\u540D\u79F0\uFF09\uFF1A\n");
27169
+ PROVIDERS_KEYS.forEach((key, i) => {
27170
+ const p = PROVIDERS[key];
27171
+ stdout7.write(` ${i + 1}. ${p.name} (${p.defaultBaseUrl})
27172
+ `);
27173
+ });
27174
+ stdout7.write("\n> ");
27175
+ const providerInput = (await rl.question("")).trim();
27176
+ const provider = resolveProvider(providerInput);
27177
+ const preset = PROVIDERS[provider];
27178
+ const baseUrlDefault = preset?.defaultBaseUrl ?? existing.model.baseUrl;
27179
+ stdout7.write(`baseUrl [${baseUrlDefault}]: `);
27180
+ const baseUrl = (await rl.question("")).trim() || baseUrlDefault;
27181
+ stdout7.write("\nAPI Key\uFF08\u8F93\u5165\u4E0D\u4F1A\u88AB\u9690\u85CF\uFF0C\u7C98\u8D34\u540E\u6309\u56DE\u8F66\uFF09: ");
27182
+ const apiKey = (await rl.question("")).trim();
27183
+ if (!apiKey) {
27184
+ stderr2.write("[connect] API Key \u4E0D\u80FD\u4E3A\u7A7A\n");
27185
+ return 2;
27186
+ }
27187
+ const modelDefault = preset?.defaultModel ?? existing.model.model;
27188
+ stdout7.write(`
27189
+ \u6A21\u578B\u540D [${modelDefault}]: `);
27190
+ const model = (await rl.question("")).trim() || modelDefault;
27191
+ const saveDefault = configPath;
27192
+ stdout7.write(`
27193
+ \u4FDD\u5B58\u914D\u7F6E\u5230 [${saveDefault}]\uFF1A`);
27194
+ const saveInput = (await rl.question("")).trim();
27195
+ const finalConfigPath = saveInput ? resolve8(saveInput) : saveDefault;
27196
+ stdout7.write("\n--------------------------------------------\n");
27197
+ stdout7.write(`Provider : ${provider}
27198
+ `);
27199
+ stdout7.write(`Base URL : ${baseUrl}
27200
+ `);
27201
+ stdout7.write(`Model : ${model}
27202
+ `);
27203
+ stdout7.write(`API Key : ${maskKey(apiKey)}
27204
+ `);
27205
+ stdout7.write(`Config : ${finalConfigPath}
27206
+ `);
27207
+ stdout7.write("--------------------------------------------\n");
27208
+ stdout7.write("\u8FDE\u901A\u6027\u6D4B\u8BD5\u4E2D\uFF085s \u8D85\u65F6\uFF09...\n");
27209
+ return await doConnect({ provider, apiKey, baseUrl, model, configPath: finalConfigPath, existing });
27210
+ } finally {
27211
+ rl.close();
27212
+ }
27213
+ }
27214
+ async function doConnect(params) {
27215
+ const { provider, apiKey, baseUrl, model, configPath, existing } = params;
27216
+ const testResult = await testConnectivity({ baseUrl, apiKey, model });
27217
+ if (!testResult.ok) {
27218
+ stderr2.write(`
27219
+ [FAIL] \u8FDE\u901A\u6027\u6D4B\u8BD5\u5931\u8D25\uFF1A${testResult.reason}
27220
+ `);
27221
+ if (testResult.detail) stderr2.write(` ${testResult.detail}
27222
+ `);
27223
+ stderr2.write("\n\u63D0\u793A\uFF1A\n");
27224
+ stderr2.write(" \xB7 \u786E\u8BA4 API Key \u6709\u6548\uFF1A\u53BB provider \u63A7\u5236\u53F0\u65B0\u5EFA\u4E00\u4E2A\n");
27225
+ stderr2.write(" \xB7 \u786E\u8BA4 baseUrl \u6B63\u786E\uFF08DeepSeek: https://api.deepseek.com\uFF09\n");
27226
+ stderr2.write(" \xB7 \u786E\u8BA4\u6A21\u578B\u540D\uFF08DeepSeek: deepseek-flash / deepseek-v4-pro\uFF09\n");
27227
+ return 1;
27228
+ }
27229
+ const preset = PROVIDERS[provider];
27230
+ const envName = preset?.apiKeyEnv ?? provider.toUpperCase().replace(/[^A-Z0-9_]/g, "_") + "_API_KEY";
27231
+ const envPersisted = persistApiKey(envName, apiKey);
27232
+ process.env[envName] = apiKey;
27233
+ saveConnectionConfig(configPath, existing, {
27234
+ baseUrl,
27235
+ model,
27236
+ envName,
27237
+ ...preset ? { contextWindow: preset.contextWindow, maxOutputTokens: preset.maxOutputTokens } : {}
27238
+ });
27239
+ stdout7.write(`
27240
+ [OK] \u8FDE\u901A\u6027\u6D4B\u8BD5\u901A\u8FC7 \u2705
27241
+ `);
27242
+ stdout7.write(` \u54CD\u5E94\u8017\u65F6: ${testResult.latencyMs}ms
27243
+ `);
27244
+ stdout7.write(`
27245
+ \u914D\u7F6E\u5DF2\u5199\u5165\uFF1A${configPath}
27246
+ `);
27247
+ stdout7.write(`API Key \u6301\u4E45\u5316\uFF1A`);
27248
+ if (envPersisted.ok) {
27249
+ stdout7.write(`\u2705 ${envName} \u2192 ${envPersisted.hint}
27250
+ `);
27251
+ stdout7.write(` \u5F53\u524D\u4F1A\u8BDD\u5DF2\u751F\u6548\uFF0C\u91CD\u5F00\u4F1A\u8BDD\u81EA\u52A8\u8BFB\u53D6 \u2705
27252
+ `);
27253
+ } else {
27254
+ stdout7.write(`\u26A0\uFE0F \u9700\u624B\u52A8\u8BBE\u7F6E\uFF1A
27255
+ `);
27256
+ stdout7.write(` ${envPersisted.hint}
27257
+ `);
27278
27258
  }
27259
+ stdout7.write(`
27260
+ \u73B0\u5728\u53EF\u4EE5\u8DD1\uFF1A
27261
+ `);
27262
+ stdout7.write(` forgex run "\u4F60\u597D\uFF0C\u4ECB\u7ECD\u4E00\u4E0B ForgeX"
27263
+ `);
27264
+ stdout7.write(` forgex doctor
27265
+ `);
27279
27266
  return 0;
27280
27267
  }
27281
27268
 
@@ -27686,7 +27673,7 @@ async function main(argv) {
27686
27673
  const unknown = unknownFlags(args.flags);
27687
27674
  if (unknown.length > 0) {
27688
27675
  const rendered = unknown.map((name) => name.length === 1 ? `-${name}` : `--${name}`).join(", ");
27689
- stderr4.write(`\u672A\u77E5\u53C2\u6570: ${rendered}
27676
+ stderr3.write(`\u672A\u77E5\u53C2\u6570: ${rendered}
27690
27677
 
27691
27678
  `);
27692
27679
  printHelp2();
@@ -27695,7 +27682,7 @@ async function main(argv) {
27695
27682
  const missingValue = flagsMissingValue(args.flags);
27696
27683
  if (missingValue.length > 0) {
27697
27684
  const rendered = missingValue.map((name) => `--${name}`).join(", ");
27698
- stderr4.write(`\u53C2\u6570\u7F3A\u5C11\u53D6\u503C: ${rendered}
27685
+ stderr3.write(`\u53C2\u6570\u7F3A\u5C11\u53D6\u503C: ${rendered}
27699
27686
 
27700
27687
  `);
27701
27688
  printHelp2();
@@ -27737,7 +27724,7 @@ async function main(argv) {
27737
27724
  case "workflows":
27738
27725
  return workflowsCommand(args);
27739
27726
  default:
27740
- stderr4.write(`\u672A\u77E5\u547D\u4EE4: ${args.command}
27727
+ stderr3.write(`\u672A\u77E5\u547D\u4EE4: ${args.command}
27741
27728
 
27742
27729
  `);
27743
27730
  printHelp2();
@@ -27798,7 +27785,7 @@ function formatError(err) {
27798
27785
  void main(process.argv.slice(2)).then((code) => {
27799
27786
  process.exitCode = code;
27800
27787
  }).catch((err) => {
27801
- stderr4.write(`[\u9519\u8BEF] ${formatError(err)}
27788
+ stderr3.write(`[\u9519\u8BEF] ${formatError(err)}
27802
27789
  `);
27803
27790
  process.exitCode = 1;
27804
27791
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "forgex-agent",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "ForgeX - TUI-first coding & DevOps agent runtime",
5
5
  "license": "MIT",
6
6
  "type": "module",