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,103 @@
1
+ import { describe, it, expect, beforeEach } from 'vitest';
2
+ import { ToolRegistry } from '../../src/tools/ToolRegistry.js';
3
+ import type { Tool } from '../../src/tools/tool-types.js';
4
+
5
+ function makeTool(overrides: Partial<Tool> = {}): Tool {
6
+ return {
7
+ name: 'test_tool',
8
+ description: 'A test tool',
9
+ category: 'filesystem',
10
+ parameters: { type: 'object', properties: {}, required: [] },
11
+ dangerous: false,
12
+ requiresApproval: false,
13
+ async execute(params) {
14
+ return { success: true, output: JSON.stringify(params) };
15
+ },
16
+ ...overrides,
17
+ };
18
+ }
19
+
20
+ describe('ToolRegistry', () => {
21
+ let registry: ToolRegistry;
22
+
23
+ beforeEach(() => {
24
+ registry = new ToolRegistry();
25
+ });
26
+
27
+ it('应该能注册工具', () => {
28
+ const tool = makeTool({ name: 'read_file' });
29
+ registry.register(tool);
30
+ expect(registry.has('read_file')).toBe(true);
31
+ expect(registry.count()).toBe(1);
32
+ });
33
+
34
+ it('注册重复工具应该抛出错误', () => {
35
+ const tool = makeTool({ name: 'read_file' });
36
+ registry.register(tool);
37
+ expect(() => registry.register(tool)).toThrow('工具已注册');
38
+ });
39
+
40
+ it('应该能获取工具', () => {
41
+ const tool = makeTool({ name: 'write_file', category: 'filesystem' });
42
+ registry.register(tool);
43
+ const found = registry.get('write_file');
44
+ expect(found).toBeDefined();
45
+ expect(found!.name).toBe('write_file');
46
+ expect(found!.category).toBe('filesystem');
47
+ });
48
+
49
+ it('获取不存在的工具返回 undefined', () => {
50
+ expect(registry.get('nonexistent')).toBeUndefined();
51
+ });
52
+
53
+ it('应该能注销工具', () => {
54
+ registry.register(makeTool({ name: 'delete_file' }));
55
+ registry.unregister('delete_file');
56
+ expect(registry.has('delete_file')).toBe(false);
57
+ });
58
+
59
+ it('应该能按分类获取工具', () => {
60
+ registry.register(makeTool({ name: 't1', category: 'filesystem' }));
61
+ registry.register(makeTool({ name: 't2', category: 'filesystem' }));
62
+ registry.register(makeTool({ name: 't3', category: 'search' }));
63
+
64
+ const fsTools = registry.getByCategory('filesystem');
65
+ expect(fsTools).toHaveLength(2);
66
+
67
+ const searchTools = registry.getByCategory('search');
68
+ expect(searchTools).toHaveLength(1);
69
+ });
70
+
71
+ it('getDefinitions 应返回正确的定义格式', () => {
72
+ registry.register(makeTool({ name: 'read_file', category: 'filesystem' }));
73
+ const defs = registry.getDefinitions();
74
+ expect(defs).toHaveLength(1);
75
+ expect(defs[0]).toHaveProperty('name', 'read_file');
76
+ expect(defs[0]).toHaveProperty('parameters');
77
+ expect(defs[0]).not.toHaveProperty('execute');
78
+ });
79
+
80
+ it('categories 应返回所有分类', () => {
81
+ registry.register(makeTool({ name: 'a', category: 'filesystem' }));
82
+ registry.register(makeTool({ name: 'b', category: 'search' }));
83
+ registry.register(makeTool({ name: 'c', category: 'shell' }));
84
+ expect(registry.categories()).toHaveLength(3);
85
+ });
86
+
87
+ it('clear 应清空所有工具', () => {
88
+ registry.register(makeTool({ name: 't1' }));
89
+ registry.register(makeTool({ name: 't2' }));
90
+ registry.clear();
91
+ expect(registry.count()).toBe(0);
92
+ });
93
+
94
+ it('registerAll 应批量注册', () => {
95
+ const tools: Tool[] = [
96
+ makeTool({ name: 't1' }),
97
+ makeTool({ name: 't2' }),
98
+ makeTool({ name: 't3' }),
99
+ ];
100
+ registry.registerAll(tools);
101
+ expect(registry.count()).toBe(3);
102
+ });
103
+ });
@@ -0,0 +1,137 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { ToolValidator } from '../../src/tools/ToolValidator.js';
3
+ import type { Tool } from '../../src/tools/tool-types.js';
4
+
5
+ describe('ToolValidator', () => {
6
+ const validator = new ToolValidator();
7
+
8
+ const readFileTool: Tool = {
9
+ name: 'read_file',
10
+ description: 'Read file',
11
+ category: 'filesystem',
12
+ parameters: {
13
+ type: 'object',
14
+ properties: {
15
+ file_path: { type: 'string', description: '文件路径' },
16
+ offset: { type: 'integer', description: '起始行' },
17
+ limit: { type: 'integer', description: '行数' },
18
+ },
19
+ required: ['file_path'],
20
+ },
21
+ dangerous: false,
22
+ requiresApproval: false,
23
+ async execute() {
24
+ return { success: true, output: '' };
25
+ },
26
+ };
27
+
28
+ it('应验证正确的参数', () => {
29
+ const result = validator.validate(readFileTool, { file_path: '/test.ts' });
30
+ expect(result.success).toBe(true);
31
+ });
32
+
33
+ it('应检测缺少必需参数', () => {
34
+ const result = validator.validate(readFileTool, {});
35
+ expect(result.success).toBe(false);
36
+ expect(result.error).toContain('缺少必需参数');
37
+ expect(result.error).toContain('file_path');
38
+ });
39
+
40
+ it('应检测错误的参数类型', () => {
41
+ const result = validator.validate(readFileTool, { file_path: 123 });
42
+ expect(result.success).toBe(false);
43
+ expect(result.error).toContain('应为字符串类型');
44
+ });
45
+
46
+ it('valid params with extra fields pass', () => {
47
+ const result = validator.validate(readFileTool, {
48
+ file_path: '/test.ts',
49
+ offset: 10,
50
+ limit: 20,
51
+ extra_field: 'ignored',
52
+ });
53
+ expect(result.success).toBe(true);
54
+ });
55
+
56
+ it('应验证枚举值', () => {
57
+ const enumTool: Tool = {
58
+ name: 'set_theme',
59
+ description: 'Set theme',
60
+ category: 'system',
61
+ parameters: {
62
+ type: 'object',
63
+ properties: {
64
+ theme: { type: 'string', description: '主题', enum: ['dark', 'light'] },
65
+ },
66
+ required: [],
67
+ },
68
+ dangerous: false,
69
+ requiresApproval: false,
70
+ async execute() {
71
+ return { success: true, output: '' };
72
+ },
73
+ };
74
+ const good = validator.validate(enumTool, { theme: 'dark' });
75
+ expect(good.success).toBe(true);
76
+
77
+ const bad = validator.validate(enumTool, { theme: 'blue' });
78
+ expect(bad.success).toBe(false);
79
+ expect(bad.error).toContain('不在允许范围内');
80
+ });
81
+
82
+ it('应验证数组类型参数', () => {
83
+ const arrayTool: Tool = {
84
+ name: 'batch_read',
85
+ description: 'Batch read',
86
+ category: 'filesystem',
87
+ parameters: {
88
+ type: 'object',
89
+ properties: {
90
+ paths: {
91
+ type: 'array',
92
+ description: 'Paths',
93
+ items: { type: 'string' },
94
+ },
95
+ },
96
+ required: ['paths'],
97
+ },
98
+ dangerous: false,
99
+ requiresApproval: false,
100
+ async execute() {
101
+ return { success: true, output: '' };
102
+ },
103
+ };
104
+ const good = validator.validate(arrayTool, { paths: ['a.ts', 'b.ts'] });
105
+ expect(good.success).toBe(true);
106
+
107
+ const badType = validator.validate(arrayTool, { paths: 'not_array' });
108
+ expect(badType.success).toBe(false);
109
+ expect(badType.error).toContain('应为数组类型');
110
+
111
+ const badItem = validator.validate(arrayTool, { paths: [1, 2, 3] });
112
+ expect(badItem.success).toBe(false);
113
+ expect(badItem.error).toContain('应为字符串类型');
114
+ });
115
+
116
+ it('应验证布尔类型参数', () => {
117
+ const boolTool: Tool = {
118
+ name: 'set_flag',
119
+ description: 'Set flag',
120
+ category: 'system',
121
+ parameters: {
122
+ type: 'object',
123
+ properties: {
124
+ enabled: { type: 'boolean', description: 'Enabled' },
125
+ },
126
+ required: [],
127
+ },
128
+ dangerous: false,
129
+ requiresApproval: false,
130
+ async execute() {
131
+ return { success: true, output: '' };
132
+ },
133
+ };
134
+ expect(validator.validate(boolTool, { enabled: true }).success).toBe(true);
135
+ expect(validator.validate(boolTool, { enabled: 'yes' }).success).toBe(false);
136
+ });
137
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "lib": ["ES2022"],
7
+ "jsx": "react-jsx",
8
+ "outDir": "dist",
9
+ "rootDir": "src",
10
+ "strict": true,
11
+ "esModuleInterop": true,
12
+ "skipLibCheck": true,
13
+ "forceConsistentCasingInFileNames": true,
14
+ "resolveJsonModule": true,
15
+ "declaration": true,
16
+ "declarationMap": true,
17
+ "sourceMap": true,
18
+ "isolatedModules": true,
19
+ "allowImportingTsExtensions": true,
20
+ "noEmit": true,
21
+ "baseUrl": ".",
22
+ "paths": {
23
+ "@/*": ["src/*"]
24
+ }
25
+ },
26
+ "include": ["src/**/*.ts", "src/**/*.tsx"],
27
+ "exclude": ["node_modules", "dist"]
28
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { defineConfig } from 'tsup';
2
+
3
+ export default defineConfig({
4
+ entry: {
5
+ 'index': 'src/index.ts',
6
+ 'cli/index': 'src/cli/index.ts',
7
+ },
8
+ format: ['esm'],
9
+ dts: true,
10
+ sourcemap: true,
11
+ clean: true,
12
+ target: 'node20',
13
+ platform: 'node',
14
+ outDir: 'dist',
15
+ splitting: false,
16
+ external: ['react', 'ink'],
17
+ });
@@ -0,0 +1,20 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ globals: true,
6
+ environment: 'node',
7
+ testTimeout: 30000,
8
+ include: ['tests/**/*.test.ts'],
9
+ coverage: {
10
+ provider: 'v8',
11
+ include: ['src/**/*.ts'],
12
+ exclude: ['src/**/*.tsx'],
13
+ },
14
+ },
15
+ resolve: {
16
+ alias: {
17
+ '@': '/src',
18
+ },
19
+ },
20
+ });