deeper-cli 1.0.0

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 (188) hide show
  1. package/README.md +254 -0
  2. package/dist/cli/index.d.ts +1 -0
  3. package/dist/cli/index.js +12067 -0
  4. package/dist/cli/index.js.map +1 -0
  5. package/dist/index.d.ts +415 -0
  6. package/dist/index.js +1599 -0
  7. package/dist/index.js.map +1 -0
  8. package/docs/superpowers/plans/2026-05-14-deepercode-implementation.md +24 -0
  9. package/docs/superpowers/plans/2026-05-14-deepercode-plan.md +1248 -0
  10. package/docs/superpowers/specs/2026-05-14-deepercode-design.md +560 -0
  11. package/package.json +60 -0
  12. package/src/cli/bootstrap.ts +69 -0
  13. package/src/cli/chat-repl.ts +932 -0
  14. package/src/cli/commands/chat.ts +39 -0
  15. package/src/cli/commands/chat.tsx +39 -0
  16. package/src/cli/commands/config.ts +133 -0
  17. package/src/cli/commands/mcp.ts +172 -0
  18. package/src/cli/commands/run.ts +147 -0
  19. package/src/cli/commands/skill.ts +152 -0
  20. package/src/cli/index.ts +184 -0
  21. package/src/core/bugscan.ts +145 -0
  22. package/src/core/config.ts +285 -0
  23. package/src/core/constants.ts +49 -0
  24. package/src/core/eventbus.ts +202 -0
  25. package/src/core/logger.ts +109 -0
  26. package/src/core/storage.ts +96 -0
  27. package/src/index.ts +26 -0
  28. package/src/mcp/ConfigLoader.ts +74 -0
  29. package/src/mcp/MCPClient.ts +326 -0
  30. package/src/mcp/ResourceAdapter.ts +58 -0
  31. package/src/mcp/SSETransport.ts +133 -0
  32. package/src/mcp/StdioTransport.ts +116 -0
  33. package/src/mcp/ToolAdapter.ts +71 -0
  34. package/src/mcp/types.ts +58 -0
  35. package/src/memory/xmemory.ts +275 -0
  36. package/src/model/DeepSeekClient.ts +292 -0
  37. package/src/model/MessageBuilder.ts +155 -0
  38. package/src/model/RetryManager.ts +82 -0
  39. package/src/model/StreamHandler.ts +158 -0
  40. package/src/model/types.ts +86 -0
  41. package/src/skills/SkillCreator.ts +153 -0
  42. package/src/skills/SkillEngine.ts +158 -0
  43. package/src/skills/SkillExecutor.ts +107 -0
  44. package/src/skills/SkillLoader.ts +182 -0
  45. package/src/skills/SkillRegistry.ts +73 -0
  46. package/src/skills/SkillTrigger.ts +82 -0
  47. package/src/skills/types.ts +28 -0
  48. package/src/tools/ToolExecutor.ts +103 -0
  49. package/src/tools/ToolRegistry.ts +71 -0
  50. package/src/tools/ToolValidator.ts +103 -0
  51. package/src/tools/builtin/ai/context_summarize.ts +76 -0
  52. package/src/tools/builtin/ai/memory_store.ts +86 -0
  53. package/src/tools/builtin/ai/prompt_template.ts +71 -0
  54. package/src/tools/builtin/ai/skill_create.ts +53 -0
  55. package/src/tools/builtin/ai/subagent.ts +39 -0
  56. package/src/tools/builtin/ai/todo_manager.ts +157 -0
  57. package/src/tools/builtin/ai/token_count.ts +196 -0
  58. package/src/tools/builtin/ai/tool_create.ts +52 -0
  59. package/src/tools/builtin/code/analyze_deps.ts +72 -0
  60. package/src/tools/builtin/code/bug_scan.ts +80 -0
  61. package/src/tools/builtin/code/code_metrics.ts +111 -0
  62. package/src/tools/builtin/code/extract_function.ts +86 -0
  63. package/src/tools/builtin/code/format_code.ts +57 -0
  64. package/src/tools/builtin/code/generate_code.ts +75 -0
  65. package/src/tools/builtin/code/import_organizer.ts +82 -0
  66. package/src/tools/builtin/code/lint_code.ts +48 -0
  67. package/src/tools/builtin/code/parse_ast.ts +86 -0
  68. package/src/tools/builtin/code/refactor_code.ts +63 -0
  69. package/src/tools/builtin/code/type_check.ts +48 -0
  70. package/src/tools/builtin/data/chart_generate.ts +62 -0
  71. package/src/tools/builtin/data/csv_parse.ts +56 -0
  72. package/src/tools/builtin/data/data_diff.ts +79 -0
  73. package/src/tools/builtin/data/data_transform.ts +74 -0
  74. package/src/tools/builtin/data/data_validate.ts +75 -0
  75. package/src/tools/builtin/data/json_parse.ts +71 -0
  76. package/src/tools/builtin/data/template_render.ts +58 -0
  77. package/src/tools/builtin/data/toml_parse.ts +42 -0
  78. package/src/tools/builtin/data/xml_parse.ts +79 -0
  79. package/src/tools/builtin/data/yaml_parse.ts +42 -0
  80. package/src/tools/builtin/database/db_backup.ts +53 -0
  81. package/src/tools/builtin/database/db_restore.ts +51 -0
  82. package/src/tools/builtin/database/db_schema.ts +66 -0
  83. package/src/tools/builtin/database/nosql_query.ts +50 -0
  84. package/src/tools/builtin/database/orm_generate.ts +66 -0
  85. package/src/tools/builtin/database/redis_command.ts +46 -0
  86. package/src/tools/builtin/database/sql_migrate.ts +55 -0
  87. package/src/tools/builtin/database/sql_query.ts +60 -0
  88. package/src/tools/builtin/filesystem/batch_read.ts +56 -0
  89. package/src/tools/builtin/filesystem/batch_write.ts +67 -0
  90. package/src/tools/builtin/filesystem/copy_file.ts +36 -0
  91. package/src/tools/builtin/filesystem/create_dir.ts +30 -0
  92. package/src/tools/builtin/filesystem/delete_file.ts +30 -0
  93. package/src/tools/builtin/filesystem/diff_files.ts +47 -0
  94. package/src/tools/builtin/filesystem/edit_file.ts +47 -0
  95. package/src/tools/builtin/filesystem/file_info.ts +52 -0
  96. package/src/tools/builtin/filesystem/glob_find.ts +44 -0
  97. package/src/tools/builtin/filesystem/list_dir.ts +51 -0
  98. package/src/tools/builtin/filesystem/merge_files.ts +44 -0
  99. package/src/tools/builtin/filesystem/move_file.ts +37 -0
  100. package/src/tools/builtin/filesystem/read_file.ts +55 -0
  101. package/src/tools/builtin/filesystem/watch_file.ts +33 -0
  102. package/src/tools/builtin/filesystem/write_file.ts +45 -0
  103. package/src/tools/builtin/index.ts +244 -0
  104. package/src/tools/builtin/network/api_call.ts +79 -0
  105. package/src/tools/builtin/network/browser_action.ts +54 -0
  106. package/src/tools/builtin/network/check_url.ts +59 -0
  107. package/src/tools/builtin/network/download_file.ts +64 -0
  108. package/src/tools/builtin/network/graphql_query.ts +46 -0
  109. package/src/tools/builtin/network/http_request.ts +61 -0
  110. package/src/tools/builtin/network/parse_html.ts +101 -0
  111. package/src/tools/builtin/network/proxy_request.ts +53 -0
  112. package/src/tools/builtin/network/screenshot_page.ts +58 -0
  113. package/src/tools/builtin/network/web_fetch.ts +70 -0
  114. package/src/tools/builtin/network/web_search.ts +128 -0
  115. package/src/tools/builtin/network/websocket_connect.ts +70 -0
  116. package/src/tools/builtin/project/build_project.ts +68 -0
  117. package/src/tools/builtin/project/config_manage.ts +99 -0
  118. package/src/tools/builtin/project/coverage_report.ts +59 -0
  119. package/src/tools/builtin/project/docker_manage.ts +90 -0
  120. package/src/tools/builtin/project/env_manage.ts +88 -0
  121. package/src/tools/builtin/project/npm_manage.ts +71 -0
  122. package/src/tools/builtin/project/project_init.ts +59 -0
  123. package/src/tools/builtin/project/run_test.ts +74 -0
  124. package/src/tools/builtin/search/codebase_search.ts +76 -0
  125. package/src/tools/builtin/search/find_definition.ts +84 -0
  126. package/src/tools/builtin/search/find_references.ts +75 -0
  127. package/src/tools/builtin/search/fuzzy_find.ts +75 -0
  128. package/src/tools/builtin/search/grep_search.ts +90 -0
  129. package/src/tools/builtin/search/regex_find.ts +91 -0
  130. package/src/tools/builtin/search/search_docs.ts +51 -0
  131. package/src/tools/builtin/search/search_package.ts +50 -0
  132. package/src/tools/builtin/search/symbol_search.ts +82 -0
  133. package/src/tools/builtin/search/text_search.ts +63 -0
  134. package/src/tools/builtin/security/decrypt_file.ts +54 -0
  135. package/src/tools/builtin/security/encrypt_file.ts +52 -0
  136. package/src/tools/builtin/security/hash_generate.ts +48 -0
  137. package/src/tools/builtin/security/jwt_decode.ts +53 -0
  138. package/src/tools/builtin/security/secret_scan.ts +82 -0
  139. package/src/tools/builtin/security/vulnerability_check.ts +71 -0
  140. package/src/tools/builtin/shell/background_terminal.ts +38 -0
  141. package/src/tools/builtin/shell/check_status.ts +48 -0
  142. package/src/tools/builtin/shell/interactive_terminal.ts +31 -0
  143. package/src/tools/builtin/shell/kill_terminal.ts +29 -0
  144. package/src/tools/builtin/shell/list_terminals.ts +61 -0
  145. package/src/tools/builtin/shell/pipe_commands.ts +55 -0
  146. package/src/tools/builtin/shell/process-pool.ts +150 -0
  147. package/src/tools/builtin/shell/run_async.ts +73 -0
  148. package/src/tools/builtin/shell/run_command.ts +60 -0
  149. package/src/tools/builtin/shell/send_ctrl_keys.ts +43 -0
  150. package/src/tools/builtin/shell/send_keys.ts +36 -0
  151. package/src/tools/builtin/shell/send_text.ts +35 -0
  152. package/src/tools/builtin/shell/shell_script.ts +65 -0
  153. package/src/tools/builtin/shell/stop_command.ts +40 -0
  154. package/src/tools/builtin/shell/terminal_resize.ts +31 -0
  155. package/src/tools/builtin/shell/terminal_screenshot.ts +28 -0
  156. package/src/tools/builtin/system/log_viewer.ts +89 -0
  157. package/src/tools/builtin/system/notify_user.ts +55 -0
  158. package/src/tools/builtin/system/process_list.ts +66 -0
  159. package/src/tools/builtin/system/resource_monitor.ts +66 -0
  160. package/src/tools/builtin/system/system_info.ts +41 -0
  161. package/src/tools/tool-types.ts +97 -0
  162. package/src/ui/AgentTree.tsx +98 -0
  163. package/src/ui/App.tsx +46 -0
  164. package/src/ui/ChatView.tsx +278 -0
  165. package/src/ui/ConfirmDialog.tsx +68 -0
  166. package/src/ui/DiffView.tsx +64 -0
  167. package/src/ui/FilePreview.tsx +59 -0
  168. package/src/ui/InputBox.tsx +267 -0
  169. package/src/ui/MessageBubble.tsx +30 -0
  170. package/src/ui/Spinner.tsx +35 -0
  171. package/src/ui/StatusBar.tsx +41 -0
  172. package/src/ui/ToolCallCard.tsx +73 -0
  173. package/src/ui/ansi.ts +50 -0
  174. package/src/ui/markdown.ts +238 -0
  175. package/src/ui/themes/dark.ts +4 -0
  176. package/src/ui/themes/default.ts +25 -0
  177. package/src/ui/themes/light.ts +14 -0
  178. package/tests/unit/BuiltinTools.test.ts +129 -0
  179. package/tests/unit/BuiltinToolsIntegration.test.ts +111 -0
  180. package/tests/unit/FilesystemTools.test.ts +211 -0
  181. package/tests/unit/SkillLoader.test.ts +141 -0
  182. package/tests/unit/SkillRegistry.test.ts +113 -0
  183. package/tests/unit/ToolExecutor.test.ts +160 -0
  184. package/tests/unit/ToolRegistry.test.ts +103 -0
  185. package/tests/unit/ToolValidator.test.ts +137 -0
  186. package/tsconfig.json +28 -0
  187. package/tsup.config.ts +17 -0
  188. package/vitest.config.ts +20 -0
@@ -0,0 +1,52 @@
1
+ import { statSync, existsSync } from 'node:fs';
2
+ import { resolve, basename } from 'node:path';
3
+ import type { Tool } from '../../tool-types.js';
4
+
5
+ export const file_info: Tool = {
6
+ name: 'file_info',
7
+ description: '获取文件元信息(大小、修改时间等)',
8
+ category: 'filesystem',
9
+ parameters: {
10
+ type: 'object',
11
+ properties: {
12
+ file_path: { type: 'string', description: '文件绝对路径' },
13
+ },
14
+ required: ['file_path'],
15
+ },
16
+ dangerous: false,
17
+ requiresApproval: false,
18
+ async execute(params) {
19
+ try {
20
+ const filePath = resolve(params.file_path as string);
21
+ if (!existsSync(filePath)) {
22
+ return { success: false, error: `文件不存在: ${filePath}`, output: '' };
23
+ }
24
+ const stat = statSync(filePath);
25
+ const info = {
26
+ name: basename(filePath),
27
+ path: filePath,
28
+ size: stat.size,
29
+ sizeFormatted: formatSize(stat.size),
30
+ isDirectory: stat.isDirectory(),
31
+ isFile: stat.isFile(),
32
+ isSymlink: stat.isSymbolicLink(),
33
+ created: stat.birthtime.toISOString(),
34
+ modified: stat.mtime.toISOString(),
35
+ accessed: stat.atime.toISOString(),
36
+ permissions: stat.mode.toString(8).slice(-3),
37
+ readable: true,
38
+ writable: true,
39
+ };
40
+ return { success: true, output: JSON.stringify(info, null, 2), metadata: info };
41
+ } catch (err: unknown) {
42
+ return { success: false, error: (err as Error).message, output: '' };
43
+ }
44
+ },
45
+ };
46
+
47
+ function formatSize(bytes: number): string {
48
+ if (bytes < 1024) return `${bytes} B`;
49
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
50
+ if (bytes < 1024 * 1024 * 1024) return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
51
+ return `${(bytes / 1024 / 1024 / 1024).toFixed(1)} GB`;
52
+ }
@@ -0,0 +1,44 @@
1
+ import { resolve } from 'node:path';
2
+ import type { Tool } from '../../tool-types.js';
3
+
4
+ export const glob_find: Tool = {
5
+ name: 'glob_find',
6
+ description: '使用 glob 模式匹配查找文件',
7
+ category: 'filesystem',
8
+ parameters: {
9
+ type: 'object',
10
+ properties: {
11
+ pattern: { type: 'string', description: 'Glob 匹配模式,如 **/*.ts' },
12
+ cwd: { type: 'string', description: '搜索根目录' },
13
+ ignore: { type: 'array', items: { type: 'string' }, description: '忽略模式列表' },
14
+ max_results: { type: 'number', description: '最大结果数' },
15
+ },
16
+ required: ['pattern'],
17
+ },
18
+ dangerous: false,
19
+ requiresApproval: false,
20
+ async execute(params) {
21
+ try {
22
+ const pattern = params.pattern as string;
23
+ const cwd = (params.cwd as string) ? resolve(params.cwd as string) : process.cwd();
24
+ const ignore = (params.ignore as string[]) ?? [];
25
+ const maxResults = (params.max_results as number) ?? 1000;
26
+ const fg = await import('fast-glob');
27
+ const files = await fg.default(pattern, {
28
+ cwd,
29
+ ignore: ['node_modules/**', '.git/**', ...ignore],
30
+ absolute: false,
31
+ dot: false,
32
+ onlyFiles: true,
33
+ });
34
+ const results = files.slice(0, maxResults);
35
+ return {
36
+ success: true,
37
+ output: results.join('\n'),
38
+ metadata: { count: results.length, total: files.length, pattern },
39
+ };
40
+ } catch (err: unknown) {
41
+ return { success: false, error: (err as Error).message, output: '' };
42
+ }
43
+ },
44
+ };
@@ -0,0 +1,51 @@
1
+ import { readdirSync, existsSync } from 'node:fs';
2
+ import { resolve, join } from 'node:path';
3
+ import type { Tool } from '../../tool-types.js';
4
+
5
+ export const list_dir: Tool = {
6
+ name: 'list_dir',
7
+ description: '列出目录内容',
8
+ category: 'filesystem',
9
+ parameters: {
10
+ type: 'object',
11
+ properties: {
12
+ dir_path: { type: 'string', description: '目录绝对路径' },
13
+ recursive: { type: 'boolean', description: '是否递归列出' },
14
+ max_depth: { type: 'number', description: '递归最大深度' },
15
+ },
16
+ required: ['dir_path'],
17
+ },
18
+ dangerous: false,
19
+ requiresApproval: false,
20
+ async execute(params) {
21
+ try {
22
+ const dirPath = resolve(params.dir_path as string);
23
+ const recursive = (params.recursive as boolean) ?? false;
24
+ const maxDepth = (params.max_depth as number) ?? 3;
25
+ if (!existsSync(dirPath)) {
26
+ return { success: false, error: `目录不存在: ${dirPath}`, output: '' };
27
+ }
28
+ const { statSync } = await import('node:fs');
29
+ const lines: string[] = [];
30
+ function walk(dir: string, depth: number, prefix: string) {
31
+ if (depth > maxDepth) return;
32
+ try {
33
+ const entries = readdirSync(dir, { withFileTypes: true });
34
+ for (const entry of entries) {
35
+ const isDir = entry.isDirectory();
36
+ lines.push(`${prefix}${isDir ? '📁' : '📄'} ${entry.name}`);
37
+ if (isDir && recursive) {
38
+ walk(join(dir, entry.name), depth + 1, prefix + ' ');
39
+ }
40
+ }
41
+ } catch {
42
+ lines.push(`${prefix}权限不足`);
43
+ }
44
+ }
45
+ walk(dirPath, 1, '');
46
+ return { success: true, output: lines.join('\n'), metadata: { path: dirPath, entries: lines.length } };
47
+ } catch (err: unknown) {
48
+ return { success: false, error: (err as Error).message, output: '' };
49
+ }
50
+ },
51
+ };
@@ -0,0 +1,44 @@
1
+ import { readFileSync, writeFileSync, existsSync } from 'node:fs';
2
+ import { resolve } from 'node:path';
3
+ import type { Tool } from '../../tool-types.js';
4
+
5
+ export const merge_files: Tool = {
6
+ name: 'merge_files',
7
+ description: '合并多个文件内容写入目标文件',
8
+ category: 'filesystem',
9
+ parameters: {
10
+ type: 'object',
11
+ properties: {
12
+ file_paths: { type: 'array', items: { type: 'string' }, description: '源文件路径列表' },
13
+ output: { type: 'string', description: '输出文件路径' },
14
+ separator: { type: 'string', description: '文件间分隔符,默认换行' },
15
+ },
16
+ required: ['file_paths', 'output'],
17
+ },
18
+ dangerous: false,
19
+ requiresApproval: true,
20
+ async execute(params) {
21
+ try {
22
+ const paths = params.file_paths as string[];
23
+ const output = resolve(params.output as string);
24
+ const sep = (params.separator as string) ?? '\n';
25
+ const parts: string[] = [];
26
+ for (const p of paths) {
27
+ const abs = resolve(p);
28
+ if (!existsSync(abs)) {
29
+ return { success: false, error: `文件不存在: ${abs}`, output: '' };
30
+ }
31
+ parts.push(readFileSync(abs, 'utf-8'));
32
+ }
33
+ const merged = parts.join(sep);
34
+ writeFileSync(output, merged, 'utf-8');
35
+ return {
36
+ success: true,
37
+ output: `已合并 ${paths.length} 个文件到: ${output}`,
38
+ metadata: { count: paths.length, size: merged.length },
39
+ };
40
+ } catch (err: unknown) {
41
+ return { success: false, error: (err as Error).message, output: '' };
42
+ }
43
+ },
44
+ };
@@ -0,0 +1,37 @@
1
+ import { renameSync, existsSync } from 'node:fs';
2
+ import { resolve, dirname } from 'node:path';
3
+ import type { Tool } from '../../tool-types.js';
4
+
5
+ export const move_file: Tool = {
6
+ name: 'move_file',
7
+ description: '移动或重命名文件',
8
+ category: 'filesystem',
9
+ parameters: {
10
+ type: 'object',
11
+ properties: {
12
+ source: { type: 'string', description: '源文件路径' },
13
+ destination: { type: 'string', description: '目标文件路径' },
14
+ },
15
+ required: ['source', 'destination'],
16
+ },
17
+ dangerous: false,
18
+ requiresApproval: true,
19
+ async execute(params) {
20
+ try {
21
+ const source = resolve(params.source as string);
22
+ const dest = resolve(params.destination as string);
23
+ if (!existsSync(source)) {
24
+ return { success: false, error: `源文件不存在: ${source}`, output: '' };
25
+ }
26
+ const destDir = dirname(dest);
27
+ const { mkdirSync } = await import('node:fs');
28
+ if (!existsSync(destDir)) {
29
+ mkdirSync(destDir, { recursive: true });
30
+ }
31
+ renameSync(source, dest);
32
+ return { success: true, output: `已移动: ${source} -> ${dest}` };
33
+ } catch (err: unknown) {
34
+ return { success: false, error: (err as Error).message, output: '' };
35
+ }
36
+ },
37
+ };
@@ -0,0 +1,55 @@
1
+ import { readFileSync, existsSync } from 'node:fs';
2
+ import { resolve, normalize } from 'node:path';
3
+ import type { Tool } from '../../tool-types.js';
4
+
5
+ export const read_file: Tool = {
6
+ name: 'read_file',
7
+ description: '读取文件内容,支持指定行范围和偏移量,最大支持1万行',
8
+ category: 'filesystem',
9
+ parameters: {
10
+ type: 'object',
11
+ properties: {
12
+ file_path: { type: 'string', description: '文件绝对路径' },
13
+ offset: { type: 'number', description: '起始行号(从1开始)' },
14
+ limit: { type: 'number', description: '读取行数(最大10000)' },
15
+ },
16
+ required: ['file_path'],
17
+ },
18
+ dangerous: false,
19
+ requiresApproval: false,
20
+ async execute(params) {
21
+ try {
22
+ const filePath = resolve(params.file_path as string);
23
+ if (!existsSync(filePath)) {
24
+ return { success: false, error: `文件不存在: ${filePath}`, output: '' };
25
+ }
26
+ const statSync = await import('node:fs').then(m => m.statSync);
27
+ const stat = statSync(filePath);
28
+ if (stat.isDirectory()) {
29
+ return { success: false, error: `路径是目录,不是文件: ${filePath}`, output: '' };
30
+ }
31
+ const maxSize = 20 * 1024 * 1024;
32
+ if (stat.size > maxSize) {
33
+ return { success: false, error: `文件过大 (${(stat.size / 1024 / 1024).toFixed(1)}MB),限制 ${maxSize / 1024 / 1024}MB`, output: '' };
34
+ }
35
+ let raw = readFileSync(filePath, 'utf-8');
36
+ const offset = (params.offset as number) ?? 1;
37
+ let limit = params.limit as number | undefined;
38
+ if (limit !== undefined) limit = Math.min(limit, 10000);
39
+ if (offset > 1 || limit !== undefined) {
40
+ const lines = raw.split('\n');
41
+ const start = Math.max(0, offset - 1);
42
+ const end = limit !== undefined ? Math.min(start + limit, lines.length) : lines.length;
43
+ raw = lines.slice(start, end).join('\n');
44
+ } else {
45
+ const lines = raw.split('\n');
46
+ if (lines.length > 10000) {
47
+ raw = lines.slice(0, 10000).join('\n') + `\n... (共${lines.length}行,仅显示前10000行)`;
48
+ }
49
+ }
50
+ return { success: true, output: raw, metadata: { size: stat.size, path: normalize(filePath) } };
51
+ } catch (err: unknown) {
52
+ return { success: false, error: (err as Error).message, output: '' };
53
+ }
54
+ },
55
+ };
@@ -0,0 +1,33 @@
1
+ import { watch, existsSync } from 'node:fs';
2
+ import { resolve } from 'node:path';
3
+ import type { Tool } from '../../tool-types.js';
4
+
5
+ export const watch_file: Tool = {
6
+ name: 'watch_file',
7
+ description: '监听文件变化并返回初始状态',
8
+ category: 'filesystem',
9
+ parameters: {
10
+ type: 'object',
11
+ properties: {
12
+ file_path: { type: 'string', description: '文件绝对路径' },
13
+ },
14
+ required: ['file_path'],
15
+ },
16
+ dangerous: false,
17
+ requiresApproval: false,
18
+ async execute(params) {
19
+ try {
20
+ const filePath = resolve(params.file_path as string);
21
+ if (!existsSync(filePath)) {
22
+ return { success: false, error: `文件不存在: ${filePath}`, output: '' };
23
+ }
24
+ return {
25
+ success: true,
26
+ output: `监听已设置: ${filePath}(文件变化将在下次查询时反映)`,
27
+ metadata: { watching: true, path: filePath },
28
+ };
29
+ } catch (err: unknown) {
30
+ return { success: false, error: (err as Error).message, output: '' };
31
+ }
32
+ },
33
+ };
@@ -0,0 +1,45 @@
1
+ import { existsSync, mkdirSync } from 'node:fs';
2
+ import { writeFile, appendFile, readFile } from 'node:fs/promises';
3
+ import { dirname, resolve } from 'node:path';
4
+ import type { Tool } from '../../tool-types.js';
5
+
6
+ export const write_file: Tool = {
7
+ name: 'write_file',
8
+ description: '写入文件内容,自动创建父目录。最大 512KB。空内容会跳过写入。',
9
+ category: 'filesystem',
10
+ parameters: {
11
+ type: 'object',
12
+ properties: {
13
+ file_path: { type: 'string', description: '文件绝对路径' },
14
+ content: { type: 'string', description: '要写入的内容' },
15
+ append: { type: 'boolean', description: '是否追加模式' },
16
+ },
17
+ required: ['file_path', 'content'],
18
+ },
19
+ dangerous: false,
20
+ requiresApproval: false,
21
+ async execute(params) {
22
+ const content = params.content as string;
23
+ if (content.length > 524_288) {
24
+ return { success: false, error: `内容过大 (${content.length}B, 最大 512KB)`, output: '' };
25
+ }
26
+ try {
27
+ const filePath = resolve(params.file_path as string);
28
+ const append = (params.append as boolean) ?? false;
29
+ if (!content.trim() && !append) {
30
+ return { success: false, error: `内容为空,跳过写入: ${filePath}`, output: '' };
31
+ }
32
+ const dir = dirname(filePath);
33
+ if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
34
+ if (append) {
35
+ await appendFile(filePath, content, 'utf-8');
36
+ } else {
37
+ await writeFile(filePath, content, 'utf-8');
38
+ }
39
+ const lineCount = content.split('\n').length;
40
+ return { success: true, output: `文件已${append ? '追加' : '写入'}: ${filePath} (${lineCount}行)` };
41
+ } catch (err: unknown) {
42
+ return { success: false, error: (err as Error).message, output: '' };
43
+ }
44
+ },
45
+ };
@@ -0,0 +1,244 @@
1
+ import type { Tool } from '../tool-types.js';
2
+
3
+ import { read_file } from './filesystem/read_file.js';
4
+ import { write_file } from './filesystem/write_file.js';
5
+ import { edit_file } from './filesystem/edit_file.js';
6
+ import { delete_file } from './filesystem/delete_file.js';
7
+ import { list_dir } from './filesystem/list_dir.js';
8
+ import { glob_find } from './filesystem/glob_find.js';
9
+ import { move_file } from './filesystem/move_file.js';
10
+ import { copy_file } from './filesystem/copy_file.js';
11
+ import { create_dir } from './filesystem/create_dir.js';
12
+ import { file_info } from './filesystem/file_info.js';
13
+ import { watch_file } from './filesystem/watch_file.js';
14
+ import { batch_read } from './filesystem/batch_read.js';
15
+ import { batch_write } from './filesystem/batch_write.js';
16
+ import { diff_files } from './filesystem/diff_files.js';
17
+ import { merge_files } from './filesystem/merge_files.js';
18
+
19
+ import { grep_search } from './search/grep_search.js';
20
+ import { codebase_search } from './search/codebase_search.js';
21
+ import { symbol_search } from './search/symbol_search.js';
22
+ import { find_references } from './search/find_references.js';
23
+ import { find_definition } from './search/find_definition.js';
24
+ import { text_search } from './search/text_search.js';
25
+ import { fuzzy_find } from './search/fuzzy_find.js';
26
+ import { regex_find } from './search/regex_find.js';
27
+ import { search_package } from './search/search_package.js';
28
+ import { search_docs } from './search/search_docs.js';
29
+
30
+ import { run_command } from './shell/run_command.js';
31
+ import { run_async } from './shell/run_async.js';
32
+ import { check_status } from './shell/check_status.js';
33
+ import { stop_command } from './shell/stop_command.js';
34
+ import { pipe_commands } from './shell/pipe_commands.js';
35
+ import { shell_script } from './shell/shell_script.js';
36
+ import { background_terminal } from './shell/background_terminal.js';
37
+ import { send_keys } from './shell/send_keys.js';
38
+ import { send_ctrl_keys } from './shell/send_ctrl_keys.js';
39
+ import { send_text } from './shell/send_text.js';
40
+ import { terminal_screenshot } from './shell/terminal_screenshot.js';
41
+ import { terminal_resize } from './shell/terminal_resize.js';
42
+ import { list_terminals, read_terminal } from './shell/list_terminals.js';
43
+ import { kill_terminal } from './shell/kill_terminal.js';
44
+ import { interactive_terminal } from './shell/interactive_terminal.js';
45
+
46
+ import { web_fetch } from './network/web_fetch.js';
47
+ import { web_search } from './network/web_search.js';
48
+ import { http_request } from './network/http_request.js';
49
+ import { download_file } from './network/download_file.js';
50
+ import { api_call } from './network/api_call.js';
51
+ import { graphql_query } from './network/graphql_query.js';
52
+ import { websocket_connect } from './network/websocket_connect.js';
53
+ import { check_url } from './network/check_url.js';
54
+ import { screenshot_page } from './network/screenshot_page.js';
55
+ import { parse_html } from './network/parse_html.js';
56
+ import { browser_action } from './network/browser_action.js';
57
+ import { proxy_request } from './network/proxy_request.js';
58
+
59
+ import { parse_ast } from './code/parse_ast.js';
60
+ import { format_code } from './code/format_code.js';
61
+ import { lint_code } from './code/lint_code.js';
62
+ import { type_check } from './code/type_check.js';
63
+ import { generate_code } from './code/generate_code.js';
64
+ import { refactor_code } from './code/refactor_code.js';
65
+ import { extract_function } from './code/extract_function.js';
66
+ import { analyze_deps } from './code/analyze_deps.js';
67
+ import { import_organizer } from './code/import_organizer.js';
68
+ import { code_metrics } from './code/code_metrics.js';
69
+ import { bug_scan } from './code/bug_scan.js';
70
+
71
+ import { sql_query } from './database/sql_query.js';
72
+ import { sql_migrate } from './database/sql_migrate.js';
73
+ import { nosql_query } from './database/nosql_query.js';
74
+ import { db_schema } from './database/db_schema.js';
75
+ import { db_backup } from './database/db_backup.js';
76
+ import { db_restore } from './database/db_restore.js';
77
+ import { redis_command } from './database/redis_command.js';
78
+ import { orm_generate } from './database/orm_generate.js';
79
+
80
+ import { json_parse } from './data/json_parse.js';
81
+ import { csv_parse } from './data/csv_parse.js';
82
+ import { xml_parse } from './data/xml_parse.js';
83
+ import { yaml_parse } from './data/yaml_parse.js';
84
+ import { toml_parse } from './data/toml_parse.js';
85
+ import { data_transform } from './data/data_transform.js';
86
+ import { data_validate } from './data/data_validate.js';
87
+ import { data_diff } from './data/data_diff.js';
88
+ import { template_render } from './data/template_render.js';
89
+ import { chart_generate } from './data/chart_generate.js';
90
+
91
+ import { secret_scan } from './security/secret_scan.js';
92
+ import { encrypt_file } from './security/encrypt_file.js';
93
+ import { decrypt_file } from './security/decrypt_file.js';
94
+ import { hash_generate } from './security/hash_generate.js';
95
+ import { jwt_decode } from './security/jwt_decode.js';
96
+ import { vulnerability_check } from './security/vulnerability_check.js';
97
+
98
+ import { npm_manage } from './project/npm_manage.js';
99
+ import { project_init } from './project/project_init.js';
100
+ import { build_project } from './project/build_project.js';
101
+ import { run_test } from './project/run_test.js';
102
+ import { coverage_report } from './project/coverage_report.js';
103
+ import { env_manage } from './project/env_manage.js';
104
+ import { config_manage } from './project/config_manage.js';
105
+ import { docker_manage } from './project/docker_manage.js';
106
+
107
+ import { token_count } from './ai/token_count.js';
108
+ import { context_summarize } from './ai/context_summarize.js';
109
+ import { prompt_template } from './ai/prompt_template.js';
110
+ import { skill_create } from './ai/skill_create.js';
111
+ import { tool_create } from './ai/tool_create.js';
112
+ import { memory_store } from './ai/memory_store.js';
113
+ import { todo_manager } from './ai/todo_manager.js';
114
+ import { subagent, setSubagentRunner } from './ai/subagent.js';
115
+
116
+ import { process_list } from './system/process_list.js';
117
+ import { system_info } from './system/system_info.js';
118
+ import { resource_monitor } from './system/resource_monitor.js';
119
+ import { notify_user } from './system/notify_user.js';
120
+ import { log_viewer } from './system/log_viewer.js';
121
+
122
+ export const builtinTools: Tool[] = [
123
+ read_file,
124
+ write_file,
125
+ edit_file,
126
+ delete_file,
127
+ list_dir,
128
+ glob_find,
129
+ move_file,
130
+ copy_file,
131
+ create_dir,
132
+ file_info,
133
+ watch_file,
134
+ batch_read,
135
+ batch_write,
136
+ diff_files,
137
+ merge_files,
138
+
139
+ grep_search,
140
+ codebase_search,
141
+ symbol_search,
142
+ find_references,
143
+ find_definition,
144
+ text_search,
145
+ fuzzy_find,
146
+ regex_find,
147
+ search_package,
148
+ search_docs,
149
+
150
+ run_command,
151
+ run_async,
152
+ check_status,
153
+ stop_command,
154
+ pipe_commands,
155
+ shell_script,
156
+ background_terminal,
157
+ send_keys,
158
+ send_ctrl_keys,
159
+ send_text,
160
+ terminal_screenshot,
161
+ terminal_resize,
162
+ list_terminals,
163
+ read_terminal,
164
+ kill_terminal,
165
+ interactive_terminal,
166
+
167
+ web_fetch,
168
+ web_search,
169
+ http_request,
170
+ download_file,
171
+ api_call,
172
+ graphql_query,
173
+ websocket_connect,
174
+ check_url,
175
+ screenshot_page,
176
+ parse_html,
177
+ browser_action,
178
+ proxy_request,
179
+
180
+ parse_ast,
181
+ format_code,
182
+ lint_code,
183
+ type_check,
184
+ generate_code,
185
+ refactor_code,
186
+ extract_function,
187
+ analyze_deps,
188
+ import_organizer,
189
+ code_metrics,
190
+ bug_scan,
191
+
192
+ sql_query,
193
+ sql_migrate,
194
+ nosql_query,
195
+ db_schema,
196
+ db_backup,
197
+ db_restore,
198
+ redis_command,
199
+ orm_generate,
200
+
201
+ json_parse,
202
+ csv_parse,
203
+ xml_parse,
204
+ yaml_parse,
205
+ toml_parse,
206
+ data_transform,
207
+ data_validate,
208
+ data_diff,
209
+ template_render,
210
+ chart_generate,
211
+
212
+ secret_scan,
213
+ encrypt_file,
214
+ decrypt_file,
215
+ hash_generate,
216
+ jwt_decode,
217
+ vulnerability_check,
218
+
219
+ npm_manage,
220
+ project_init,
221
+ build_project,
222
+ run_test,
223
+ coverage_report,
224
+ env_manage,
225
+ config_manage,
226
+ docker_manage,
227
+
228
+ token_count,
229
+ context_summarize,
230
+ prompt_template,
231
+ skill_create,
232
+ tool_create,
233
+ memory_store,
234
+ todo_manager,
235
+ subagent,
236
+
237
+ process_list,
238
+ system_info,
239
+ resource_monitor,
240
+ notify_user,
241
+ log_viewer,
242
+ ];
243
+
244
+ export { setSubagentRunner };