@ia-ccun/code-agent-cli 0.0.52-release → 0.0.53

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 (58) hide show
  1. package/config/agent/bin/README.md +102 -0
  2. package/config/agent/bin/fd.exe +0 -0
  3. package/config/agent/bin/rg.exe +0 -0
  4. package/config/agent/extensions/aicode-advisor.ts +13 -0
  5. package/config/agent/extensions/aicode-btw.ts +66 -14
  6. package/config/agent/extensions/aicode-cd.ts +834 -0
  7. package/config/agent/extensions/aicode-grillMe.ts +198 -0
  8. package/config/agent/extensions/aicode-pets.ts +362 -0
  9. package/config/agent/extensions/aicode-safety-guard.ts +552 -0
  10. package/config/agent/extensions/aicode-tips.ts +70 -16
  11. package/config/agent/extensions/aicode-todo-progress.ts +547 -0
  12. package/config/agent/extensions/custom.ts +93 -95
  13. package/config/agent/extensions/error-monitor.ts +1 -18
  14. package/config/agent/extensions/ponytail.ts +441 -0
  15. package/config/agent/extensions/tps.ts +87 -0
  16. package/config/agent/extensions/working-msg.ts +165 -50
  17. package/config/agent/help.md +0 -7
  18. package/config/agent/models.json +7 -7
  19. package/config/agent/settings.json +2 -1
  20. package/config/agent/skills/chroma/LICENSE +21 -0
  21. package/config/agent/skills/chroma/chroma-local/SKILL.md +165 -0
  22. package/config/agent/skills/chroma/chroma-local/cli.md +48 -0
  23. package/config/agent/skills/chroma/chroma-local/data-model.md +103 -0
  24. package/config/agent/skills/chroma/chroma-local/error-handling/python.md +166 -0
  25. package/config/agent/skills/chroma/chroma-local/error-handling/typescript.md +231 -0
  26. package/config/agent/skills/chroma/chroma-local/local-chroma/python.md +95 -0
  27. package/config/agent/skills/chroma/chroma-local/local-chroma/typescript.md +101 -0
  28. package/config/agent/skills/chroma/chroma-local/metadata/python.md +154 -0
  29. package/config/agent/skills/chroma/chroma-local/metadata/typescript.md +153 -0
  30. package/config/agent/skills/chroma/chroma-local/querying/python.md +147 -0
  31. package/config/agent/skills/chroma/chroma-local/querying/typescript.md +157 -0
  32. package/config/agent/skills/chroma/chroma-local/regex/python.md +69 -0
  33. package/config/agent/skills/chroma/chroma-local/regex/typescript.md +71 -0
  34. package/config/agent/skills/chroma/chroma-local/understanding-a-codebase.md +80 -0
  35. package/config/agent/skills/chroma/chroma-local/updating-deleting/python.md +159 -0
  36. package/config/agent/skills/chroma/chroma-local/updating-deleting/typescript.md +228 -0
  37. package/config/agent/skills/milvus-skill/LICENSE +202 -0
  38. package/config/agent/skills/milvus-skill/README.md +37 -0
  39. package/config/agent/skills/milvus-skill/SKILL.md +259 -0
  40. package/config/agent/skills/milvus-skill/references/collection.md +86 -0
  41. package/config/agent/skills/milvus-skill/references/database.md +24 -0
  42. package/config/agent/skills/milvus-skill/references/index.md +69 -0
  43. package/config/agent/skills/milvus-skill/references/partition.md +29 -0
  44. package/config/agent/skills/milvus-skill/references/patterns.md +150 -0
  45. package/config/agent/skills/milvus-skill/references/user-role.md +90 -0
  46. package/config/agent/skills/milvus-skill/references/vector.md +247 -0
  47. package/config/agent/skills/ponytail/SKILL.md +100 -0
  48. package/config/agent/skills/ponytail-audit/SKILL.md +40 -0
  49. package/config/agent/skills/ponytail-debt/SKILL.md +44 -0
  50. package/config/agent/skills/ponytail-help/SKILL.md +68 -0
  51. package/config/agent/skills/ponytail-review/SKILL.md +56 -0
  52. package/config/agent/skills/zread/README.md +115 -0
  53. package/config/agent/skills/zread/SKILL.md +103 -0
  54. package/config/agent/skills/zread/references/stdio-protocol.md +312 -0
  55. package/package.json +6 -5
  56. package/scripts/postinstall.js +58 -1
  57. package/config/agent/dangerous-patterns.json +0 -106
  58. package/config/agent/extensions/bash-check.ts +0 -227
@@ -0,0 +1,102 @@
1
+ # CLI 工具安装指南
2
+
3
+ 本目录包含 `fd` 和 `rg`(ripgrep)两个高效文件搜索工具的各平台预编译二进制文件。
4
+
5
+ > **Author**: aicode-cli
6
+
7
+ ## 文件清单
8
+
9
+ | 文件名 | 平台 | 版本 |
10
+ |--------|------|------|
11
+ | `fd` | Linux (x86-64 ELF) | 10.3.0 |
12
+ | `rg` | Linux (x86-64 ELF) | 15.1.0 |
13
+ | `fd.exe` | Windows (x64) | 10.4.2 |
14
+ | `rg.exe` | Windows (x64) | 15.1.0 |
15
+ | `fd-win.zip` | Windows 源码包 | 10.4.2 |
16
+ | `rg-win.zip` | Windows 源码包 | 15.1.0 |
17
+
18
+ ---
19
+
20
+ ## Linux 用户
21
+
22
+ 本目录中的 `fd` 和 `rg` 已是 Linux 可执行文件,无需额外操作,只需赋予执行权限即可使用。
23
+
24
+ ```bash
25
+ # 确保有执行权限
26
+ chmod +x fd rg
27
+
28
+ # 验证安装
29
+ ./fd --version
30
+ ./rg --version
31
+ ```
32
+
33
+ ### 安装到系统路径(可选)
34
+
35
+ ```bash
36
+ sudo cp fd rg /usr/local/bin/
37
+ ```
38
+
39
+ 或安装到用户目录:
40
+
41
+ ```bash
42
+ mkdir -p ~/.local/bin
43
+ cp fd rg ~/.local/bin/
44
+ ```
45
+
46
+ 确保 `~/.local/bin` 在 `$PATH` 中。
47
+
48
+ ---
49
+
50
+ ## Windows 用户
51
+
52
+ 本目录已包含 `fd.exe` 和 `rg.exe`,可直接使用。
53
+
54
+ ### 直接使用
55
+
56
+ ```powershell
57
+ # 验证
58
+ .\fd.exe --version
59
+ .\rg.exe --version
60
+ ```
61
+
62
+ ### 添加到 PATH(可选)
63
+
64
+ 将 `fd.exe` 和 `rg.exe` 放入以下任一位置:
65
+
66
+ - `C:\Users\<用户名>\.aicode-cli\agent\bin\`
67
+ - 或任意已在 `%PATH%` 中的目录
68
+
69
+ **验证:**
70
+
71
+ ```powershell
72
+ # 重新打开终端后执行
73
+ fd --version
74
+ rg --version
75
+ ```
76
+
77
+ ---
78
+
79
+ ## macOS 用户
80
+
81
+ > ⚠️ 本目录 **不提供** macOS 版本二进制文件。
82
+
83
+ 请通过 Homebrew 安装:
84
+
85
+ ```bash
86
+ brew install fd ripgrep
87
+ ```
88
+
89
+ ---
90
+
91
+ ## 用途说明
92
+
93
+ | 工具 | 用途 | 常用示例 |
94
+ |------|------|----------|
95
+ | `fd` | 快速文件查找 | `fd -e ts "pattern"` |
96
+ | `rg` | 快速文本搜索 | `rg -t ts "pattern"` |
97
+
98
+ ---
99
+
100
+ 详细用法请参阅:
101
+ - fd: https://github.com/sharkdp/fd
102
+ - ripgrep: https://github.com/BurntSushi/ripgrep
Binary file
Binary file
@@ -146,6 +146,19 @@ function setDisabledForModels(models: Array<string | { model: string; minEffort?
146
146
  }
147
147
 
148
148
  // ============== 工具清单序列化 ==============
149
+ /**
150
+ * stableStringify - 稳定序列化对象(键排序)
151
+ *
152
+ * 用于序列化工具参数,确保参数对象的键顺序一致,便于对比和展示。
153
+ *
154
+ * 功能说明:
155
+ * - 处理 null 和非对象类型:直接 JSON.stringify
156
+ * - 处理数组:递归序列化每个元素,undefined 替换为 "null"
157
+ * - 处理对象:键排序后序列化,跳过 undefined 值
158
+ *
159
+ * @param value - 要序列化的值
160
+ * @returns 稳定的 JSON 字符串(键排序)
161
+ */
149
162
  function stableStringify(value: unknown): string {
150
163
  if (value === null || typeof value !== "object") {
151
164
  return JSON.stringify(value);
@@ -40,6 +40,18 @@ function matchesBtwFocusShortcut(data: string): boolean {
40
40
  return BTW_FOCUS_SHORTCUTS.some((shortcut) => matchesKey(data, shortcut));
41
41
  }
42
42
 
43
+ /**
44
+ * 类型守卫:检查 entry 是否是有效的 Message 对象
45
+ * ✅ 用于安全转换,避免使用危险的 as unknown as
46
+ */
47
+ function isMessageLike(entry: unknown): entry is Partial<Message> & { role?: string; customType?: string; content?: unknown } {
48
+ if (!entry || typeof entry !== "object") {
49
+ return false;
50
+ }
51
+ const candidate = entry as { role?: unknown; customType?: string; content?: unknown };
52
+ return typeof candidate.role === "string" && Array.isArray(candidate.content);
53
+ }
54
+
43
55
  const BTW_SYSTEM_PROMPT = [
44
56
  "You are having an aside conversation with the user, separate from their main working session.",
45
57
  "If main session messages are provided, they are for context only — that work is being handled by another agent.",
@@ -277,17 +289,17 @@ function buildBtwSeedState(
277
289
  (message) => !isVisibleBtwMessage(message),
278
290
  ),
279
291
  );
280
- } catch {
292
+ } catch (error) {
293
+ // ✅ 改进错误处理:记录错误而不忽略
294
+ console.warn('[btw] buildSessionContext failed, using fallback:', error);
281
295
  messages.push(
282
296
  ...ctx.sessionManager.getEntries().flatMap((entry) => {
283
- if (!entry || typeof entry !== "object") {
297
+ // ✅ 使用类型守卫进行安全转换,避免 as unknown as
298
+ if (!isMessageLike(entry)) {
284
299
  return [];
285
300
  }
286
301
 
287
- const message = entry as unknown as Partial<Message> & { role?: string; customType?: string; content?: unknown };
288
- if (typeof message.role !== "string" || !Array.isArray(message.content)) {
289
- return [];
290
- }
302
+ const message = entry; // ✅ 类型安全
291
303
 
292
304
  return isVisibleBtwMessage({ role: message.role, customType: message.customType }) ? [] : [message as Message];
293
305
  }),
@@ -380,7 +392,9 @@ function formatToolPreview(value: unknown): string {
380
392
  return "";
381
393
  }
382
394
  return preview.length > 120 ? `${preview.slice(0, 117)}...` : preview;
383
- } catch {
395
+ } catch (error) {
396
+ // ✅ 改进错误处理:记录错误而不忽略
397
+ console.warn('[btw] JSON.stringify failed in formatToolPreview:', error);
384
398
  return "";
385
399
  }
386
400
  }
@@ -396,6 +410,26 @@ function createEmptyTranscriptState(): BtwTranscriptState {
396
410
  };
397
411
  }
398
412
 
413
+ /**
414
+ * clearTranscriptState - 清理 transcriptState 的所有资源
415
+ * ✅ 清理 entries 数组
416
+ * ✅ 清理 toolCalls Map(防止内存泄漏)
417
+ * ✅ 重置所有状态
418
+ */
419
+ function clearTranscriptState(state: BtwTranscriptState): void {
420
+ // ✅ 清理 toolCalls Map(防止内存泄漏)
421
+ state.toolCalls.clear();
422
+
423
+ // 清理 entries 数组
424
+ state.entries = [];
425
+
426
+ // 重置状态
427
+ state.nextEntryId = 1;
428
+ state.nextTurnId = 1;
429
+ state.currentTurnId = null;
430
+ state.lastTurnId = null;
431
+ }
432
+
399
433
  function appendTranscriptEntry<T extends BtwTranscriptEntry>(
400
434
  state: BtwTranscriptState,
401
435
  entry: Omit<T, "id">,
@@ -444,6 +478,13 @@ function finishTranscriptTurn(state: BtwTranscriptState, turnId?: number | null)
444
478
  if (state.currentTurnId === resolvedTurnId) {
445
479
  state.currentTurnId = null;
446
480
  }
481
+
482
+ // ✅ 清理当前 turn 的 toolCalls(防止内存泄漏)
483
+ for (const [toolCallId, toolCall] of state.toolCalls.entries()) {
484
+ if (toolCall.turnId === resolvedTurnId) {
485
+ state.toolCalls.delete(toolCallId);
486
+ }
487
+ }
447
488
  }
448
489
 
449
490
  function removeTranscriptTurn(state: BtwTranscriptState, turnId: number | null): void {
@@ -574,7 +615,9 @@ function summarizeToolResult(value: unknown, maxLength = 400): { content: string
574
615
  } else if (value !== undefined) {
575
616
  try {
576
617
  content = JSON.stringify(value, null, 2);
577
- } catch {
618
+ } catch (error) {
619
+ // ✅ 改进错误处理:记录错误而不忽略
620
+ console.warn('[btw] JSON.stringify failed in summarizeToolResult:', error);
578
621
  content = String(value);
579
622
  }
580
623
  }
@@ -1340,8 +1383,9 @@ export default function (pi: ExtensionAPI) {
1340
1383
 
1341
1384
  try {
1342
1385
  unsubscribe();
1343
- } catch {
1344
- // Ignore unsubscribe errors during BTW session replacement/shutdown.
1386
+ } catch (error) {
1387
+ // ✅ 改进错误处理:记录错误而不忽略
1388
+ console.warn('[btw] Unsubscribe failed during session removal:', error);
1345
1389
  }
1346
1390
  }
1347
1391
 
@@ -1402,6 +1446,12 @@ export default function (pi: ExtensionAPI) {
1402
1446
  async function disposeBtwSession(): Promise<void> {
1403
1447
  const current = activeBtwSession;
1404
1448
  activeBtwSession = null;
1449
+
1450
+ // ✅ 清理 transcriptState(防止内存泄漏)
1451
+ if (transcriptState) {
1452
+ clearTranscriptState(transcriptState);
1453
+ }
1454
+
1405
1455
  if (!current) {
1406
1456
  return;
1407
1457
  }
@@ -1410,8 +1460,9 @@ export default function (pi: ExtensionAPI) {
1410
1460
 
1411
1461
  try {
1412
1462
  await current.session.abort();
1413
- } catch {
1414
- // Ignore abort errors during BTW session replacement/shutdown.
1463
+ } catch (error) {
1464
+ // ✅ 改进错误处理:记录错误而不忽略
1465
+ console.warn('[btw] Session abort failed during disposal:', error);
1415
1466
  }
1416
1467
 
1417
1468
  current.session.dispose();
@@ -2144,8 +2195,9 @@ export default function (pi: ExtensionAPI) {
2144
2195
  } finally {
2145
2196
  try {
2146
2197
  await session.abort();
2147
- } catch {
2148
- // Ignore abort errors during summarize session shutdown.
2198
+ } catch (error) {
2199
+ // ✅ 改进错误处理:记录错误而不忽略
2200
+ console.warn('[btw] Session abort failed during summarize shutdown:', error);
2149
2201
  }
2150
2202
  session.dispose();
2151
2203
  }