@ia-ccun/code-agent-cli 0.0.54-beta.1 → 0.0.54-beta.3

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 (142) hide show
  1. package/bin/cli.js +97 -69
  2. package/config/agent/extensions/aicode-advisor.ts +187 -64
  3. package/config/agent/extensions/aicode-banner.ts +101 -0
  4. package/config/agent/extensions/aicode-btw.ts +619 -182
  5. package/config/agent/extensions/aicode-cd.ts +246 -63
  6. package/config/agent/extensions/aicode-pets.ts +0 -11
  7. package/config/agent/extensions/aicode-plan.ts +2 -0
  8. package/config/agent/extensions/aicode-safety-guard.ts +3 -0
  9. package/config/agent/extensions/aicode-tips.ts +1 -16
  10. package/config/agent/extensions/context-monitor.ts +30 -15
  11. package/config/agent/extensions/context.ts +132 -60
  12. package/config/agent/extensions/custom-footer.ts +0 -5
  13. package/config/agent/extensions/custom.ts +41 -29
  14. package/config/agent/extensions/error-monitor.ts +37 -33
  15. package/config/agent/extensions/goal.ts +8 -6
  16. package/config/agent/extensions/msg-debug.ts +103 -112
  17. package/config/agent/extensions/review.ts +365 -164
  18. package/config/agent/extensions/working-msg.ts +2 -4
  19. package/config/agent/settings.json +15 -14
  20. package/config/agent/skills/hello/SKILL.md +1 -1
  21. package/config/agent/skills/refactor/SKILL.md +40 -0
  22. package/dist/banner.d.ts.map +1 -1
  23. package/dist/banner.js +8 -1
  24. package/dist/banner.js.map +1 -1
  25. package/dist/config-loader.d.ts.map +1 -1
  26. package/dist/config-loader.js +9 -2
  27. package/dist/config-loader.js.map +1 -1
  28. package/package.json +6 -7
  29. package/scripts/regression/README.md +224 -0
  30. package/scripts/regression/cases/01-version-and-deps.sh +94 -0
  31. package/scripts/regression/cases/02-extension-loading.sh +130 -0
  32. package/scripts/regression/cases/03-rpc-protocol.sh +259 -0
  33. package/scripts/regression/cases/04-prompt-stream.sh +130 -0
  34. package/scripts/regression/cases/05-slash-commands-and-skills.sh +119 -0
  35. package/scripts/regression/cases/06-tool-execution.sh +115 -0
  36. package/scripts/regression/cases/07-pi-new-features.sh +141 -0
  37. package/scripts/regression/lib/common.sh +287 -0
  38. package/scripts/regression/results/.last_pid +1 -0
  39. package/scripts/regression/results/.last_workdir +1 -0
  40. package/scripts/regression/results/02-extension-loading.log +21 -0
  41. package/scripts/regression/results/03-prompt-stream.log +16 -0
  42. package/scripts/regression/results/03-rpc-protocol.log +27 -0
  43. package/scripts/regression/results/04-slash-commands-and-skills.log +11 -0
  44. package/scripts/regression/results/05-tool-execution.log +8 -0
  45. package/scripts/regression/results/06-pi-new-features.log +27 -0
  46. package/scripts/regression/run-all.sh +187 -0
  47. package/config/agent/bin/fd.exe +0 -0
  48. package/config/agent/bin/rg.exe +0 -0
  49. package/config/agent/extensions/aicode-filter-outputs.ts +0 -131
  50. package/config/agent/extensions/aicode-snake.ts +0 -354
  51. /package/config/agent/{skills_bak → skills}/csv-data-summarizer/SKILL.md +0 -0
  52. /package/config/agent/{skills_bak → skills}/csv-data-summarizer/analyze.py +0 -0
  53. /package/config/agent/{skills_bak → skills}/csv-data-summarizer/examples/showcase_financial_pl_data.csv +0 -0
  54. /package/config/agent/{skills_bak → skills}/csv-data-summarizer/requirements.txt +0 -0
  55. /package/config/agent/{skills_bak → skills}/csv-data-summarizer/resources/sample.csv +0 -0
  56. /package/config/agent/{skills_bak → skills}/dispatching-parallel-agents/SKILL.md +0 -0
  57. /package/config/agent/{skills_bak → skills}/find-skills/SKILL.md +0 -0
  58. /package/config/agent/{skills_bak → skills}/finishing-a-development-branch/SKILL.md +0 -0
  59. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/LICENSE +0 -0
  60. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/README.md +0 -0
  61. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/README.zh.md +0 -0
  62. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/SKILL.md +0 -0
  63. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/agentloop-core.svg +0 -0
  64. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/agents/openai.yaml +0 -0
  65. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/assets/samples/sample-style1-flat.png +0 -0
  66. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/assets/samples/sample-style2-dark.png +0 -0
  67. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/assets/samples/sample-style3-blueprint.png +0 -0
  68. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/assets/samples/sample-style4-notion.png +0 -0
  69. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/assets/samples/sample-style5-glass.png +0 -0
  70. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/assets/samples/sample-style6-claude.png +0 -0
  71. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/assets/samples/sample-style7-openai.png +0 -0
  72. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/fixtures/agent-memory-types-style4.json +0 -0
  73. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/fixtures/api-flow-style7.json +0 -0
  74. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/fixtures/mem0-style1.json +0 -0
  75. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/fixtures/microservices-style3.json +0 -0
  76. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/fixtures/multi-agent-style5.json +0 -0
  77. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/fixtures/system-architecture-style6.json +0 -0
  78. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/fixtures/tool-call-style2.json +0 -0
  79. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/package.json +0 -0
  80. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/references/icons.md +0 -0
  81. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/references/style-1-flat-icon.md +0 -0
  82. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/references/style-2-dark-terminal.md +0 -0
  83. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/references/style-3-blueprint.md +0 -0
  84. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/references/style-4-notion-clean.md +0 -0
  85. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/references/style-5-glassmorphism.md +0 -0
  86. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/references/style-6-claude-official.md +0 -0
  87. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/references/style-7-openai.md +0 -0
  88. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/references/style-diagram-matrix.md +0 -0
  89. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/references/svg-layout-best-practices.md +0 -0
  90. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/scripts/README.md +0 -0
  91. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/scripts/generate-diagram.sh +0 -0
  92. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/scripts/generate-from-template.py +0 -0
  93. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/scripts/test-all-styles.sh +0 -0
  94. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/scripts/validate-svg.sh +0 -0
  95. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/templates/agent-architecture.svg +0 -0
  96. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/templates/architecture.svg +0 -0
  97. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/templates/comparison-matrix.svg +0 -0
  98. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/templates/data-flow.svg +0 -0
  99. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/templates/er-diagram.svg +0 -0
  100. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/templates/flowchart.svg +0 -0
  101. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/templates/sequence.svg +0 -0
  102. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/templates/state-machine.svg +0 -0
  103. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/templates/timeline.svg +0 -0
  104. /package/config/agent/{skills_bak → skills}/fireworks-tech-graph/templates/use-case.svg +0 -0
  105. /package/config/agent/{skills_bak → skills}/librarian/SKILL.md +0 -0
  106. /package/config/agent/{skills_bak → skills}/markdown-to-html/SKILL.md +0 -0
  107. /package/config/agent/{skills_bak → skills}/milvus-skill/LICENSE +0 -0
  108. /package/config/agent/{skills_bak → skills}/milvus-skill/README.md +0 -0
  109. /package/config/agent/{skills_bak → skills}/milvus-skill/SKILL.md +0 -0
  110. /package/config/agent/{skills_bak → skills}/milvus-skill/references/collection.md +0 -0
  111. /package/config/agent/{skills_bak → skills}/milvus-skill/references/database.md +0 -0
  112. /package/config/agent/{skills_bak → skills}/milvus-skill/references/index.md +0 -0
  113. /package/config/agent/{skills_bak → skills}/milvus-skill/references/partition.md +0 -0
  114. /package/config/agent/{skills_bak → skills}/milvus-skill/references/patterns.md +0 -0
  115. /package/config/agent/{skills_bak → skills}/milvus-skill/references/user-role.md +0 -0
  116. /package/config/agent/{skills_bak → skills}/milvus-skill/references/vector.md +0 -0
  117. /package/config/agent/{skills_bak → skills}/pr/SKILL.md +0 -0
  118. /package/config/agent/{skills_bak → skills}/receiving-code-review/SKILL.md +0 -0
  119. /package/config/agent/{skills_bak → skills}/requesting-code-review/SKILL.md +0 -0
  120. /package/config/agent/{skills_bak → skills}/requesting-code-review/code-reviewer.md +0 -0
  121. /package/config/agent/{skills_bak → skills}/subagent-driven-development/SKILL.md +0 -0
  122. /package/config/agent/{skills_bak → skills}/subagent-driven-development/code-quality-reviewer-prompt.md +0 -0
  123. /package/config/agent/{skills_bak → skills}/subagent-driven-development/implementer-prompt.md +0 -0
  124. /package/config/agent/{skills_bak → skills}/subagent-driven-development/spec-reviewer-prompt.md +0 -0
  125. /package/config/agent/{skills_bak → skills}/systematic-debugging/CREATION-LOG.md +0 -0
  126. /package/config/agent/{skills_bak → skills}/systematic-debugging/SKILL.md +0 -0
  127. /package/config/agent/{skills_bak → skills}/systematic-debugging/condition-based-waiting-example.ts +0 -0
  128. /package/config/agent/{skills_bak → skills}/systematic-debugging/condition-based-waiting.md +0 -0
  129. /package/config/agent/{skills_bak → skills}/systematic-debugging/defense-in-depth.md +0 -0
  130. /package/config/agent/{skills_bak → skills}/systematic-debugging/find-polluter.sh +0 -0
  131. /package/config/agent/{skills_bak → skills}/systematic-debugging/root-cause-tracing.md +0 -0
  132. /package/config/agent/{skills_bak → skills}/systematic-debugging/test-academic.md +0 -0
  133. /package/config/agent/{skills_bak → skills}/systematic-debugging/test-pressure-1.md +0 -0
  134. /package/config/agent/{skills_bak → skills}/systematic-debugging/test-pressure-2.md +0 -0
  135. /package/config/agent/{skills_bak → skills}/systematic-debugging/test-pressure-3.md +0 -0
  136. /package/config/agent/{skills_bak → skills}/test-driven-development/SKILL.md +0 -0
  137. /package/config/agent/{skills_bak → skills}/test-driven-development/testing-anti-patterns.md +0 -0
  138. /package/config/agent/{skills_bak → skills}/unit-test/SKILL.md +0 -0
  139. /package/config/agent/{skills_bak → skills}/using-git-worktrees/SKILL.md +0 -0
  140. /package/config/agent/{skills_bak → skills}/zread/README.md +0 -0
  141. /package/config/agent/{skills_bak → skills}/zread/SKILL.md +0 -0
  142. /package/config/agent/{skills_bak → skills}/zread/references/stdio-protocol.md +0 -0
package/bin/cli.js CHANGED
@@ -6,15 +6,21 @@
6
6
  */
7
7
 
8
8
  // 设置终端标题
9
- process.title = 'aicode-cli';
10
-
11
- import { spawn } from 'child_process';
12
- import { fileURLToPath } from 'url';
13
- import { dirname, join } from 'path';
14
- import { existsSync, readFileSync, writeFileSync } from 'fs';
15
- import { getConfig, getConfigDir, loadConfig } from '../dist/config-loader.js';
16
- import { generateBanner } from '../dist/banner.js';
9
+ process.title = "aicode-cli";
17
10
 
11
+ // 防御 CWD 被删除的边缘场景: process.cwd() 会抛 ENOENT
12
+ // 提前 chdir 到 homedir, 避免 banner / config-loader / pi-coding-agent 内部任何 cwd 调用炸
13
+ import { homedir } from "os";
14
+ try {
15
+ process.chdir(homedir());
16
+ } catch {
17
+ // 极端情况: homedir 不可访问; 让后续抛清晰错误, 不要进 graceful-fs 模糊栈
18
+ }
19
+ import { spawn } from "child_process";
20
+ import { fileURLToPath } from "url";
21
+ import { dirname, join } from "path";
22
+ import { existsSync, readFileSync, writeFileSync } from "fs";
23
+ import { getConfig, getConfigDir, loadConfig } from "../dist/config-loader.js";
18
24
  const __filename = fileURLToPath(import.meta.url);
19
25
  const __dirname = dirname(__filename);
20
26
 
@@ -22,9 +28,9 @@ const __dirname = dirname(__filename);
22
28
  function getLocalVersion() {
23
29
  let rootDir = __dirname;
24
30
  while (rootDir !== dirname(rootDir)) {
25
- const pkgPath = join(rootDir, 'package.json');
31
+ const pkgPath = join(rootDir, "package.json");
26
32
  if (existsSync(pkgPath)) {
27
- return JSON.parse(readFileSync(pkgPath, 'utf-8')).version;
33
+ return JSON.parse(readFileSync(pkgPath, "utf-8")).version;
28
34
  }
29
35
  rootDir = dirname(rootDir);
30
36
  }
@@ -33,33 +39,37 @@ function getLocalVersion() {
33
39
 
34
40
  // 获取版本缓存文件路径
35
41
  function getVersionCachePath() {
36
- return join(process.env.HOME || process.env.USERPROFILE, '.aicode-cli', '.version-cache.json');
42
+ return join(
43
+ process.env.HOME || process.env.USERPROFILE,
44
+ ".aicode-cli",
45
+ ".version-cache.json",
46
+ );
37
47
  }
38
48
 
39
49
  // 解析命令行参数
40
50
  function parseArgs() {
41
51
  const args = process.argv.slice(2);
42
52
  let configDir;
43
-
53
+
44
54
  // 处理 --version 参数,显示 CLI 自己的版本
45
- if (args.includes('--version') || args.includes('-v')) {
46
- const pkgPath = join(__dirname, '..', 'package.json');
55
+ if (args.includes("--version") || args.includes("-v")) {
56
+ const pkgPath = join(__dirname, "..", "package.json");
47
57
  if (existsSync(pkgPath)) {
48
- const { version } = JSON.parse(readFileSync(pkgPath, 'utf-8'));
58
+ const { version } = JSON.parse(readFileSync(pkgPath, "utf-8"));
49
59
  console.log(version);
50
60
  }
51
61
  process.exit(0);
52
62
  }
53
-
63
+
54
64
  for (let i = 0; i < args.length; i++) {
55
65
  const arg = args[i];
56
- if (arg === '--config' || arg === '-c') {
66
+ if (arg === "--config" || arg === "-c") {
57
67
  configDir = args[i + 1];
58
68
  args.splice(i, 2);
59
69
  break;
60
70
  }
61
71
  }
62
-
72
+
63
73
  return { remainingArgs: args, configDir };
64
74
  }
65
75
 
@@ -86,39 +96,39 @@ function replaceCLIVersionPlaceholder() {
86
96
  // 找到项目根目录的 package.json
87
97
  let rootDir = __dirname;
88
98
  while (rootDir !== dirname(rootDir)) {
89
- const pkgPath = join(rootDir, 'package.json');
99
+ const pkgPath = join(rootDir, "package.json");
90
100
  if (existsSync(pkgPath)) {
91
- const { version } = JSON.parse(readFileSync(pkgPath, 'utf-8'));
101
+ const { version } = JSON.parse(readFileSync(pkgPath, "utf-8"));
92
102
  const versionString = `aicode-cli/${version}`;
93
-
103
+
94
104
  // 查找配置目录下的 models.json
95
105
  const homeDir = process.env.HOME || process.env.USERPROFILE;
96
106
  const configDirs = [
97
- join(homeDir, '.aicode-cli', 'agent'),
98
- join(homeDir, '.pi', 'agent'),
107
+ join(homeDir, ".aicode-cli", "agent"),
108
+ join(homeDir, ".pi", "agent"),
99
109
  ];
100
-
110
+
101
111
  for (const dir of configDirs) {
102
- const modelsPath = join(dir, 'models.json');
112
+ const modelsPath = join(dir, "models.json");
103
113
  if (!existsSync(modelsPath)) continue;
104
-
114
+
105
115
  try {
106
- let content = readFileSync(modelsPath, 'utf-8');
116
+ let content = readFileSync(modelsPath, "utf-8");
107
117
  const config = JSON.parse(content);
108
-
118
+
109
119
  // 遍历所有 provider,替换 headers.User-Agent 中的占位符
110
120
  for (const provider of Object.values(config.providers || {})) {
111
- if (provider.headers && provider.headers['User-Agent']) {
112
- const ua = provider.headers['User-Agent'];
113
- if (ua && ua.startsWith('${') && ua.endsWith('}')) {
114
- provider.headers['User-Agent'] = versionString;
121
+ if (provider.headers && provider.headers["User-Agent"]) {
122
+ const ua = provider.headers["User-Agent"];
123
+ if (ua && ua.startsWith("${") && ua.endsWith("}")) {
124
+ provider.headers["User-Agent"] = versionString;
115
125
  }
116
126
  }
117
127
  }
118
-
128
+
119
129
  const newContent = JSON.stringify(config, null, 2);
120
130
  if (newContent !== content) {
121
- writeFileSync(modelsPath, newContent, 'utf-8');
131
+ writeFileSync(modelsPath, newContent, "utf-8");
122
132
  }
123
133
  } catch (e) {
124
134
  // 忽略错误
@@ -138,24 +148,21 @@ replaceCLIVersionPlaceholder();
138
148
 
139
149
  // 提前获取版本号(用于 banner 显示)
140
150
  const localVersion = getLocalVersion();
141
- process.env.AICODE_CLI_VERSION = localVersion || '';
151
+ process.env.AICODE_CLI_VERSION = localVersion || "";
142
152
 
143
- // 显示 Banner
144
- if (config.banner === '__default__' || config.banner !== '') {
145
- console.log(generateBanner(config.themeColor));
146
- }
153
+ // banner 启动后打印已移交给 config/agent/extensions/aicode-banner.ts
154
+ // 理由: 1) 避免 RPC 父进程的 stdout JSON-RPC 污染; 2) chdir 到 homedir 后再触发更稳
147
155
 
148
- // 检查新版本
149
156
  async function checkForUpdates() {
150
157
  try {
151
- const { execFileSync } = await import('child_process');
158
+ const { execFileSync } = await import("child_process");
152
159
  // 读取本地版本 - 向上查找 package.json
153
160
  let rootDir = __dirname;
154
161
  let localVersion = null;
155
162
  while (rootDir !== dirname(rootDir)) {
156
- const pkgPath = join(rootDir, 'package.json');
163
+ const pkgPath = join(rootDir, "package.json");
157
164
  if (existsSync(pkgPath)) {
158
- localVersion = JSON.parse(readFileSync(pkgPath, 'utf-8')).version;
165
+ localVersion = JSON.parse(readFileSync(pkgPath, "utf-8")).version;
159
166
  break;
160
167
  }
161
168
  rootDir = dirname(rootDir);
@@ -163,30 +170,41 @@ async function checkForUpdates() {
163
170
  if (!localVersion) return;
164
171
 
165
172
  // 🔒 Security: Use execFileSync instead of execSync to prevent command injection
166
- const registry = execFileSync('npm', ['config', 'get', 'registry'], { encoding: 'utf8', stdio: 'pipe' }).trim();
167
- const latestVersion = execFileSync('npm', ['view', '@ia-ccun/code-agent-cli', 'version', '--registry=' + registry], { encoding: 'utf8', stdio: 'pipe' }).trim();
173
+ const registry = execFileSync("npm", ["config", "get", "registry"], {
174
+ encoding: "utf8",
175
+ stdio: "pipe",
176
+ }).trim();
177
+ const latestVersion = execFileSync(
178
+ "npm",
179
+ ["view", "@ia-ccun/code-agent-cli", "version", "--registry=" + registry],
180
+ { encoding: "utf8", stdio: "pipe" },
181
+ ).trim();
168
182
 
169
183
  // 比较版本号
170
- const localParts = localVersion.split('.').map(Number);
171
- const latestParts = latestVersion.split('.').map(Number);
172
- const needsUpdate = latestParts[0] > localParts[0] ||
173
- (latestParts[0] === localParts[0] && latestParts[1] > localParts[1]) ||
174
- (latestParts[0] === localParts[0] && latestParts[1] === localParts[1] && latestParts[2] > localParts[2]);
175
-
176
-
184
+ const localParts = localVersion.split(".").map(Number);
185
+ const latestParts = latestVersion.split(".").map(Number);
186
+ const needsUpdate =
187
+ latestParts[0] > localParts[0] ||
188
+ (latestParts[0] === localParts[0] && latestParts[1] > localParts[1]) ||
189
+ (latestParts[0] === localParts[0] &&
190
+ latestParts[1] === localParts[1] &&
191
+ latestParts[2] > localParts[2]);
177
192
 
178
193
  // 写入版本缓存
179
194
  try {
180
- const cacheDir = join(process.env.HOME || process.env.USERPROFILE, '.aicode-cli');
195
+ const cacheDir = join(
196
+ process.env.HOME || process.env.USERPROFILE,
197
+ ".aicode-cli",
198
+ );
181
199
  if (!existsSync(cacheDir)) {
182
200
  // 🔒 Security: Use execFileSync for mkdir instead of execSync
183
- execFileSync('mkdir', ['-p', cacheDir], { stdio: 'pipe' });
201
+ execFileSync("mkdir", ["-p", cacheDir], { stdio: "pipe" });
184
202
  }
185
203
  const cacheData = {
186
204
  localVersion,
187
205
  latestVersion,
188
206
  needsUpdate,
189
- timestamp: Date.now()
207
+ timestamp: Date.now(),
190
208
  };
191
209
  writeFileSync(versionCachePath, JSON.stringify(cacheData, null, 2));
192
210
  } catch (e) {
@@ -198,7 +216,10 @@ async function checkForUpdates() {
198
216
  }
199
217
  checkForUpdates();
200
218
 
201
- const piAgentPathUrl = new URL('../node_modules/@earendil-works/pi-coding-agent/dist/cli.js', import.meta.url);
219
+ const piAgentPathUrl = new URL(
220
+ "../node_modules/@earendil-works/pi-coding-agent/dist/cli.js",
221
+ import.meta.url,
222
+ );
202
223
  const piAgentPath = fileURLToPath(piAgentPathUrl); // 解码中文路径
203
224
 
204
225
  // 获取版本缓存文件路径
@@ -209,30 +230,37 @@ const env = {
209
230
  ...process.env,
210
231
  AICODE_CLI_CONFIG_DIR: config.configDir,
211
232
  AICODE_CLI_NAME: config.name,
212
- AICODE_CLI_VERSION: localVersion || '',
233
+ AICODE_CLI_VERSION: localVersion || "",
213
234
  AICODE_CLI_VERSION_CACHE: versionCachePath,
214
- PI_SKIP_VERSION_CHECK: '1',
215
- PI_OFFLINE: '1' // 禁用包更新检查
235
+ PI_SKIP_VERSION_CHECK: "1",
236
+ PI_OFFLINE: "1", // 禁用包更新检查
216
237
  };
217
238
 
218
239
  // 传递配置目录给 pi
219
- // pi 使用 AICODE_CLI_CODING_AGENT_DIR 环境变量 (基于 piConfig.name)
220
- // 确保使用完整的绝对路径
221
- const fullPath = join(process.env.HOME || process.env.USERPROFILE, config.configDir);
222
- const agentDir = join(fullPath, 'agent');
240
+ // pi 使用 ${APP_NAME.toUpperCase()}_CODING_AGENT_DIR 环境变量识别 agent 目录
241
+ // 注意 "aicode-cli".toUpperCase() = "AICODE-CLI"(连字符,不是下划线)
242
+ // 所以 pi 0.85+ 读的是 AICODE-CLI_CODING_AGENT_DIR(连字符),不是 AICODE_CLI_CODING_AGENT_DIR(下划线)
243
+ // 下划线版本保留向后兼容 0.80~0.84
244
+ const fullPath = join(
245
+ process.env.HOME || process.env.USERPROFILE,
246
+ config.configDir,
247
+ );
248
+ const agentDir = join(fullPath, "agent");
249
+ env["AICODE-CLI_CODING_AGENT_DIR"] = agentDir;
223
250
  env.AICODE_CLI_CODING_AGENT_DIR = agentDir;
251
+ env.PI_CODING_AGENT_DIR = agentDir;
224
252
 
225
253
  // 启动 pi-coding-agent
226
- const child = spawn('node', [piAgentPath, ...remainingArgs], {
227
- stdio: 'inherit',
228
- env
254
+ const child = spawn("node", [piAgentPath, ...remainingArgs], {
255
+ stdio: "inherit",
256
+ env,
229
257
  });
230
258
 
231
- child.on('exit', (code) => {
259
+ child.on("exit", (code) => {
232
260
  process.exit(code ?? 0);
233
261
  });
234
262
 
235
- child.on('error', (err) => {
236
- console.error('Failed to start agent:', err);
263
+ child.on("error", (err) => {
264
+ console.error("Failed to start agent:", err);
237
265
  process.exit(1);
238
266
  });