@lance2026/ai-tools 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 (42) hide show
  1. package/README.md +173 -0
  2. package/bin/ai-error +4 -0
  3. package/bin/ai-shell +4 -0
  4. package/bin/ai-sql +4 -0
  5. package/bin/ai-tools +3 -0
  6. package/dist/commands/error-solve.d.ts +2 -0
  7. package/dist/commands/error-solve.d.ts.map +1 -0
  8. package/dist/commands/error-solve.js +81 -0
  9. package/dist/commands/error-solve.js.map +1 -0
  10. package/dist/commands/smart-shell.d.ts +2 -0
  11. package/dist/commands/smart-shell.d.ts.map +1 -0
  12. package/dist/commands/smart-shell.js +83 -0
  13. package/dist/commands/smart-shell.js.map +1 -0
  14. package/dist/commands/smart-sql.d.ts +2 -0
  15. package/dist/commands/smart-sql.d.ts.map +1 -0
  16. package/dist/commands/smart-sql.js +59 -0
  17. package/dist/commands/smart-sql.js.map +1 -0
  18. package/dist/config.d.ts +6 -0
  19. package/dist/config.d.ts.map +1 -0
  20. package/dist/config.js +148 -0
  21. package/dist/config.js.map +1 -0
  22. package/dist/detector.d.ts +4 -0
  23. package/dist/detector.d.ts.map +1 -0
  24. package/dist/detector.js +122 -0
  25. package/dist/detector.js.map +1 -0
  26. package/dist/formatter.d.ts +17 -0
  27. package/dist/formatter.d.ts.map +1 -0
  28. package/dist/formatter.js +109 -0
  29. package/dist/formatter.js.map +1 -0
  30. package/dist/index.d.ts +2 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +36 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/llm.d.ts +4 -0
  35. package/dist/llm.d.ts.map +1 -0
  36. package/dist/llm.js +39 -0
  37. package/dist/llm.js.map +1 -0
  38. package/dist/types.d.ts +26 -0
  39. package/dist/types.d.ts.map +1 -0
  40. package/dist/types.js +3 -0
  41. package/dist/types.js.map +1 -0
  42. package/package.json +54 -0
package/README.md ADDED
@@ -0,0 +1,173 @@
1
+ # AI Tools
2
+
3
+ AI 驱动的开发工具 - 报错分析、Shell 生成、SQL 生成
4
+
5
+ ## ✨ 工具列表
6
+
7
+ | 命令 | 功能 |
8
+ |------|------|
9
+ | `ai-error` | 报错分析 |
10
+ | `ai-shell` | Shell 命令生成 |
11
+ | `ai-sql` | SQL 查询生成 |
12
+
13
+ ## 🚀 安装
14
+
15
+ ```bash
16
+ npm install -g @lance2026/ai-tools
17
+ ```
18
+
19
+ ## 📖 使用方法
20
+
21
+ ### 1. 报错分析
22
+
23
+ ```bash
24
+ # 交互模式
25
+ ai-error
26
+
27
+ # 直接读取剪贴板
28
+ ai-error -y
29
+
30
+ # 详细解释模式
31
+ ai-error -e
32
+ ```
33
+
34
+ ### 2. Shell 命令生成
35
+
36
+ ```bash
37
+ # 交互模式
38
+ ai-shell
39
+
40
+ # 生成并执行(需确认)
41
+ ai-shell -r
42
+ ```
43
+
44
+ 示例:
45
+ ```
46
+ 📋 请输入你想要执行的操作 (例如:查找所有大于 100M 的文件):
47
+ 描述:查找当前目录下所有大于 100M 的文件
48
+
49
+ 📝 命令:find . -type f -size +100M
50
+ 📖 说明:使用 find 命令查找当前目录下所有大小超过 100M 的文件
51
+ ```
52
+
53
+ ### 3. SQL 查询生成
54
+
55
+ ```bash
56
+ # 交互模式
57
+ ai-sql
58
+
59
+ # 指定 SQL 方言
60
+ ai-sql --dialect postgresql
61
+ ```
62
+
63
+ 示例:
64
+ ```
65
+ 📋 请输入你想要查询的内容 (例如:查询年龄大于 18 岁的用户):
66
+ 描述:查询订单数大于 10 的用户,按订单数降序排列
67
+
68
+ 📝 SQL: SELECT user_id, COUNT(*) as order_count FROM orders GROUP BY user_id HAVING COUNT(*) > 10 ORDER BY order_count DESC;
69
+ 📖 说明:使用 GROUP BY 和 HAVING 子句筛选订单数大于 10 的用户
70
+ ```
71
+
72
+ ## ⚙️ 配置说明
73
+
74
+ 配置文件路径:`~/.config/ai-tools/config.json`
75
+
76
+ ### 配置示例
77
+
78
+ ```json
79
+ {
80
+ "_comment": "通用配置,所有工具共享",
81
+ "baseUrl": "https://dashscope.aliyuncs.com/compatible-mode/v1",
82
+ "apiKey": "sk-xxxxx",
83
+ "model": "qwen-turbo",
84
+
85
+ "_comment": "工具独立配置,覆盖通用配置",
86
+ "errorSolver": {
87
+ "model": "qwen-plus",
88
+ "explainMode": true
89
+ },
90
+ "smartShell": {
91
+ "model": "qwen-turbo"
92
+ },
93
+ "smartSql": {
94
+ "model": "qwen-plus",
95
+ "dialect": "mysql"
96
+ }
97
+ }
98
+ ```
99
+
100
+ ### 配置字段说明
101
+
102
+ | 字段 | 类型 | 说明 |
103
+ |------|------|------|
104
+ | `baseUrl` | string | API 基础 URL(阿里云 DashScope 或其他 OpenAI 兼容接口) |
105
+ | `apiKey` | string | API 密钥 |
106
+ | `model` | string | 默认模型 |
107
+ | `errorSolver.model` | string | 错误分析专用模型 |
108
+ | `errorSolver.explainMode` | boolean | 是否启用详细解释模式 |
109
+ | `smartShell.model` | string | Shell 生成专用模型 |
110
+ | `smartSql.model` | string | SQL 生成专用模型 |
111
+
112
+ ## 📋 CLI 选项
113
+
114
+ ### ai-error
115
+
116
+ | 选项 | 简写 | 说明 |
117
+ |------|------|------|
118
+ | `--yes` | `-y` | 直接读取剪贴板,不进入交互模式 |
119
+ | `--config <path>` | `-c` | 指定配置文件路径 |
120
+ | `--explain` | `-e` | 启用详细解释模式 |
121
+
122
+ ### ai-shell
123
+
124
+ | 选项 | 简写 | 说明 |
125
+ |------|------|------|
126
+ | `--config <path>` | `-c` | 指定配置文件路径 |
127
+ | `--run` | `-r` | 生成后直接执行(需确认) |
128
+
129
+ ### ai-sql
130
+
131
+ | 选项 | 简写 | 说明 |
132
+ |------|------|------|
133
+ | `--config <path>` | `-c` | 指定配置文件路径 |
134
+ | `--dialect <type>` | | SQL 方言 (mysql/postgresql/sqlite),默认 mysql |
135
+
136
+ ## 🛠️ 开发
137
+
138
+ ```bash
139
+ # 安装依赖
140
+ npm install
141
+
142
+ # 编译 TypeScript
143
+ npm run build
144
+
145
+ # 本地运行
146
+ npm run start
147
+
148
+ # 开发模式
149
+ npm run dev
150
+ ```
151
+
152
+ ## 📦 发布
153
+
154
+ ```bash
155
+ # 登录 npm
156
+ npm login
157
+
158
+ # 发布
159
+ npm publish --access public
160
+ ```
161
+
162
+ ## 📝 计划工具
163
+
164
+ - [x] ai-error - 报错分析
165
+ - [x] ai-shell - Shell 命令生成
166
+ - [x] ai-sql - SQL 查询生成
167
+ - [ ] ai-commit - Git 提交信息生成
168
+ - [ ] ai-review - 代码审查
169
+ - [ ] ai-log - 日志分析
170
+
171
+ ## 📄 许可证
172
+
173
+ MIT
package/bin/ai-error ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+
3
+ // ai-error 命令入口
4
+ require('../dist/commands/error-solve.js');
package/bin/ai-shell ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+
3
+ // ai-shell 命令入口
4
+ require('../dist/commands/smart-shell.js');
package/bin/ai-sql ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+
3
+ // ai-sql 命令入口
4
+ require('../dist/commands/smart-sql.js');
package/bin/ai-tools ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ require('../dist/index.js');
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=error-solve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-solve.d.ts","sourceRoot":"","sources":["../../src/commands/error-solve.ts"],"names":[],"mappings":""}
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const commander_1 = require("commander");
7
+ const prompts_1 = __importDefault(require("prompts"));
8
+ const clipboardy_1 = __importDefault(require("clipboardy"));
9
+ const config_1 = require("../config");
10
+ const llm_1 = require("../llm");
11
+ const detector_1 = require("../detector");
12
+ const formatter_1 = require("../formatter");
13
+ const TOOL_NAME = 'errorSolver';
14
+ const program = new commander_1.Command();
15
+ program
16
+ .name('ai-error')
17
+ .description('AI 驱动的报错分析工具 - 粘贴报错信息,AI 自动分析原因并给出修复方案')
18
+ .version('1.0.0')
19
+ .option('-y, --yes', '直接读取剪贴板,不交互')
20
+ .option('-c, --config <path>', '指定配置文件路径')
21
+ .option('-e, --explain', '启用详细解释模式')
22
+ .parse(process.argv);
23
+ const options = program.opts();
24
+ async function main() {
25
+ const config = (0, config_1.loadConfig)(TOOL_NAME, options.config);
26
+ if (!options.yes) {
27
+ (0, formatter_1.printWelcome)();
28
+ }
29
+ let errorText;
30
+ if (options.yes) {
31
+ try {
32
+ errorText = clipboardy_1.default.readSync();
33
+ (0, formatter_1.printClipboardRead)();
34
+ }
35
+ catch (error) {
36
+ (0, formatter_1.printError)('无法读取剪贴板内容');
37
+ process.exit(1);
38
+ }
39
+ }
40
+ else {
41
+ (0, formatter_1.printInputPrompt)();
42
+ const response = await (0, prompts_1.default)({
43
+ type: 'text',
44
+ name: 'error',
45
+ message: '报错信息:',
46
+ initial: '',
47
+ validate: (value) => value.trim().length > 0 || '请输入报错信息',
48
+ });
49
+ errorText = response.error?.trim() || '';
50
+ if (!errorText) {
51
+ (0, formatter_1.printError)('未输入报错信息');
52
+ process.exit(1);
53
+ }
54
+ }
55
+ const detectedLang = (0, detector_1.detectLanguage)(errorText);
56
+ (0, formatter_1.printLanguageDetected)(detectedLang);
57
+ let promptText = `请分析以下报错信息:\n\n${errorText}`;
58
+ if (detectedLang !== 'unknown') {
59
+ promptText += `\n\n检测到编程语言:${(0, detector_1.formatLanguageName)(detectedLang)}`;
60
+ }
61
+ if (options.explain) {
62
+ promptText += '\n\n请详细解释错误原因,帮助我理解。';
63
+ }
64
+ (0, formatter_1.printLoading)('正在分析');
65
+ try {
66
+ const messages = (0, llm_1.createMessages)(config.systemMessage, promptText);
67
+ const result = await (0, llm_1.callLLM)(config, messages);
68
+ const parsed = (0, formatter_1.formatResult)(result);
69
+ (0, formatter_1.printResult)(parsed, detectedLang);
70
+ (0, formatter_1.printSuccess)('分析完成');
71
+ }
72
+ catch (error) {
73
+ (0, formatter_1.printError)(error instanceof Error ? error.message : '分析失败');
74
+ process.exit(1);
75
+ }
76
+ }
77
+ main().catch((error) => {
78
+ (0, formatter_1.printError)(error instanceof Error ? error.message : '未知错误');
79
+ process.exit(1);
80
+ });
81
+ //# sourceMappingURL=error-solve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-solve.js","sourceRoot":"","sources":["../../src/commands/error-solve.ts"],"names":[],"mappings":";;;;;AAEA,yCAAoC;AACpC,sDAA8B;AAC9B,4DAAmC;AACnC,sCAAuC;AACvC,gCAAiD;AACjD,0CAAiE;AACjE,4CAUsB;AAEtB,MAAM,SAAS,GAAG,aAAa,CAAC;AAEhC,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,UAAU,CAAC;KAChB,WAAW,CAAC,wCAAwC,CAAC;KACrD,OAAO,CAAC,OAAO,CAAC;KAChB,MAAM,CAAC,WAAW,EAAE,aAAa,CAAC;KAClC,MAAM,CAAC,qBAAqB,EAAE,UAAU,CAAC;KACzC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC;KACnC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAEvB,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;AAE/B,KAAK,UAAU,IAAI;IAEjB,MAAM,MAAM,GAAG,IAAA,mBAAU,EAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAGrD,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;QACjB,IAAA,wBAAY,GAAE,CAAC;IACjB,CAAC;IAGD,IAAI,SAAiB,CAAC;IAEtB,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QAEhB,I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QAAQ,GAAG,IAAA,oBAAc,EAAC,MAAM,CAAC,aAAc,EAAE,UAAU,CAAC,CAAC;QACnE,MAAM,MAAM,GAAG,MAAM,IAAA,aAAO,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAG/C,MAAM,MAAM,GAAG,IAAA,wBAAY,EAAC,MAAM,CAAC,CAAC;QACpC,IAAA,uBAAW,EAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QAElC,IAAA,wBAAY,EAAC,MAAM,CAAC,CAAC;IACvB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAA,sBAAU,EAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,IAAA,sBAAU,EAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=smart-shell.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smart-shell.d.ts","sourceRoot":"","sources":["../../src/commands/smart-shell.ts"],"names":[],"mappings":""}
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const commander_1 = require("commander");
7
+ const prompts_1 = __importDefault(require("prompts"));
8
+ const child_process_1 = require("child_process");
9
+ const config_1 = require("../config");
10
+ const llm_1 = require("../llm");
11
+ const formatter_1 = require("../formatter");
12
+ const TOOL_NAME = 'smartShell';
13
+ const program = new commander_1.Command();
14
+ program
15
+ .name('ai-shell')
16
+ .description('AI 驱动的 Shell 命令生成工具 - 根据自然语言描述生成 Shell 命令')
17
+ .version('1.0.0')
18
+ .option('-c, --config <path>', '指定配置文件路径')
19
+ .option('-r, --run', '直接执行生成的命令')
20
+ .parse(process.argv);
21
+ const options = program.opts();
22
+ async function main() {
23
+ const config = (0, config_1.loadConfig)(TOOL_NAME, options.config);
24
+ console.log('');
25
+ console.log('🐚 AI Shell - 根据描述生成 Shell 命令');
26
+ console.log('');
27
+ console.log('📋 请输入你想要执行的操作 (例如:查找所有大于 100M 的文件):');
28
+ const response = await (0, prompts_1.default)({
29
+ type: 'text',
30
+ name: 'description',
31
+ message: '描述:',
32
+ initial: '',
33
+ validate: (value) => value.trim().length > 0 || '请输入描述',
34
+ });
35
+ const description = response.description?.trim() || '';
36
+ if (!description) {
37
+ (0, formatter_1.printError)('未输入描述');
38
+ process.exit(1);
39
+ }
40
+ (0, formatter_1.printLoading)('正在生成命令');
41
+ try {
42
+ const messages = (0, llm_1.createMessages)(config.systemMessage, description);
43
+ const result = await (0, llm_1.callLLM)(config, messages);
44
+ const parsed = (0, formatter_1.formatResult)(result);
45
+ (0, formatter_1.printResult)(parsed);
46
+ if (options.run && parsed.fix) {
47
+ console.log('⚠️ 即将执行以下命令:');
48
+ console.log(parsed.fix);
49
+ const confirm = await (0, prompts_1.default)({
50
+ type: 'confirm',
51
+ name: 'confirmed',
52
+ message: '确认执行?此操作可能有风险',
53
+ initial: false,
54
+ });
55
+ if (confirm.confirmed) {
56
+ console.log('⏳ 执行中...\n');
57
+ (0, child_process_1.exec)(parsed.fix, (error, stdout, stderr) => {
58
+ if (error) {
59
+ (0, formatter_1.printError)(`执行失败:${error.message}`);
60
+ return;
61
+ }
62
+ if (stderr) {
63
+ console.log('STDERR:', stderr);
64
+ }
65
+ if (stdout) {
66
+ console.log('STDOUT:', stdout);
67
+ }
68
+ (0, formatter_1.printSuccess)('执行完成');
69
+ });
70
+ }
71
+ }
72
+ (0, formatter_1.printSuccess)('生成完成');
73
+ }
74
+ catch (error) {
75
+ (0, formatter_1.printError)(error instanceof Error ? error.message : '生成失败');
76
+ process.exit(1);
77
+ }
78
+ }
79
+ main().catch((error) => {
80
+ (0, formatter_1.printError)(error instanceof Error ? error.message : '未知错误');
81
+ process.exit(1);
82
+ });
83
+ //# sourceMappingURL=smart-shell.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smart-shell.js","sourceRoot":"","sources":["../../src/commands/smart-shell.ts"],"names":[],"mappings":";;;;;AAEA,yCAAoC;AACpC,sDAA8B;AAC9B,iDAAqC;AACrC,sCAAuC;AACvC,gCAAiD;AACjD,4CAMsB;AAEtB,MAAM,SAAS,GAAG,YAAY,CAAC;AAE/B,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,UAAU,CAAC;KAChB,WAAW,CAAC,2CAA2C,CAAC;KACxD,OAAO,CAAC,OAAO,CAAC;KAChB,MAAM,CAAC,qBAAqB,EAAE,UAAU,CAAC;KACzC,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC;KAChC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAEvB,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;AAE/B,KAAK,UAAU,IAAI;IAEjB,MAAM,MAAM,GAAG,IAAA,mBAAU,EAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAErD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;IAC7C,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAGhB,OAAO,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;IAEpD,MAAM,QAAQ,GAAG,MAAM,IAAA,iBAAO,EAAC;QAC7B,IAAI,EA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CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;oBACzC,IAAI,KAAK,EAAE,CAAC;wBACV,IAAA,sBAAU,EAAC,QAAQ,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;wBACpC,OAAO;oBACT,CAAC;oBACD,IAAI,MAAM,EAAE,CAAC;wBACX,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;oBACjC,CAAC;oBACD,IAAI,MAAM,EAAE,CAAC;wBACX,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;oBACjC,CAAC;oBACD,IAAA,wBAAY,EAAC,MAAM,CAAC,CAAC;gBACvB,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,IAAA,wBAAY,EAAC,MAAM,CAAC,CAAC;IACvB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAA,sBAAU,EAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,IAAA,sBAAU,EAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=smart-sql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smart-sql.d.ts","sourceRoot":"","sources":["../../src/commands/smart-sql.ts"],"names":[],"mappings":""}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const commander_1 = require("commander");
7
+ const prompts_1 = __importDefault(require("prompts"));
8
+ const config_1 = require("../config");
9
+ const llm_1 = require("../llm");
10
+ const formatter_1 = require("../formatter");
11
+ const TOOL_NAME = 'smartSql';
12
+ const program = new commander_1.Command();
13
+ program
14
+ .name('ai-sql')
15
+ .description('AI 驱动的 SQL 查询生成工具 - 根据自然语言描述生成 SQL 查询')
16
+ .version('1.0.0')
17
+ .option('-c, --config <path>', '指定配置文件路径')
18
+ .option('--dialect <type>', 'SQL 方言 (mysql/postgresql/sqlite)', 'mysql')
19
+ .parse(process.argv);
20
+ const options = program.opts();
21
+ async function main() {
22
+ const config = (0, config_1.loadConfig)(TOOL_NAME, options.config);
23
+ const dialect = options.dialect || 'mysql';
24
+ console.log('');
25
+ console.log('📊 AI SQL - 根据描述生成 SQL 查询');
26
+ console.log(`🔧 当前方言:${dialect}`);
27
+ console.log('');
28
+ console.log('📋 请输入你想要查询的内容 (例如:查询年龄大于 18 岁的用户):');
29
+ const response = await (0, prompts_1.default)({
30
+ type: 'text',
31
+ name: 'description',
32
+ message: '描述:',
33
+ initial: '',
34
+ validate: (value) => value.trim().length > 0 || '请输入描述',
35
+ });
36
+ const description = response.description?.trim() || '';
37
+ if (!description) {
38
+ (0, formatter_1.printError)('未输入描述');
39
+ process.exit(1);
40
+ }
41
+ (0, formatter_1.printLoading)('正在生成 SQL');
42
+ try {
43
+ const promptText = `${description}\n\nSQL 方言:${dialect}`;
44
+ const messages = (0, llm_1.createMessages)(config.systemMessage, promptText);
45
+ const result = await (0, llm_1.callLLM)(config, messages);
46
+ const parsed = (0, formatter_1.formatResult)(result);
47
+ (0, formatter_1.printResult)(parsed);
48
+ (0, formatter_1.printSuccess)('生成完成');
49
+ }
50
+ catch (error) {
51
+ (0, formatter_1.printError)(error instanceof Error ? error.message : '生成失败');
52
+ process.exit(1);
53
+ }
54
+ }
55
+ main().catch((error) => {
56
+ (0, formatter_1.printError)(error instanceof Error ? error.message : '未知错误');
57
+ process.exit(1);
58
+ });
59
+ //# sourceMappingURL=smart-sql.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smart-sql.js","sourceRoot":"","sources":["../../src/commands/smart-sql.ts"],"names":[],"mappings":";;;;;AAEA,yCAAoC;AACpC,sDAA8B;AAC9B,sCAAuC;AACvC,gCAAiD;AACjD,4CAMsB;AAEtB,MAAM,SAAS,GAAG,UAAU,CAAC;AAE7B,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,QAAQ,CAAC;KACd,WAAW,CAAC,uCAAuC,CAAC;KACpD,OAAO,CAAC,OAAO,CAAC;KAChB,MAAM,CAAC,qBAAqB,EAAE,UAAU,CAAC;KACzC,MAAM,CAAC,kBAAkB,EAAE,kCAAkC,EAAE,OAAO,CAAC;KACvE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAEvB,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;AAE/B,KAAK,UAAU,IAAI;IAEjB,MAAM,MAAM,GAAG,IAAA,mBAAU,EAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAErD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC;IAE3C,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;IACzC,OAAO,CAAC,GAAG,CAAC,WAAW,OAAO,EAAE,CAAC,CAAC;IAClC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAGhB,OAAO,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAC;IAEnD,MAAM,QAAQ,GAAG,MAAM,IAAA,iBAAO,EAAC;QAC7B,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,aAAa;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C;IAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { MergedConfig } from './types';
2
+ export declare function loadConfig(toolName: string, customPath?: string): MergedConfig;
3
+ export declare function getConfigPath(customPath?: string): string;
4
+ export declare function ensureConfigDir(): void;
5
+ export declare function createDefaultConfig(): void;
6
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAKA,OAAO,EAAgB,YAAY,EAAc,MAAM,SAAS,CAAC;AAuCjE,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,YAAY,CAwD9E;AAED,wBAAgB,aAAa,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED,wBAAgB,eAAe,IAAI,IAAI,CAKtC;AAED,wBAAgB,mBAAmB,IAAI,IAAI,CAqB1C"}
package/dist/config.js ADDED
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.loadConfig = loadConfig;
37
+ exports.getConfigPath = getConfigPath;
38
+ exports.ensureConfigDir = ensureConfigDir;
39
+ exports.createDefaultConfig = createDefaultConfig;
40
+ const fs = __importStar(require("fs"));
41
+ const path = __importStar(require("path"));
42
+ const os = __importStar(require("os"));
43
+ const DEFAULT_CONFIG_PATH = path.join(os.homedir(), '.config', 'ai-tools', 'config.json');
44
+ const DEFAULT_COMMON_CONFIG = {
45
+ baseUrl: 'https://dashscope.aliyuncs.com/compatible-mode/v1',
46
+ model: 'qwen-turbo',
47
+ };
48
+ const DEFAULT_SYSTEM_MESSAGES = {
49
+ errorSolver: `你是资深程序员,擅长分析各种编程错误。
50
+
51
+ 任务:分析用户提供的报错信息,给出:
52
+ 1. 错误原因(简洁说明)
53
+ 2. 具体修复命令或步骤
54
+ 3. 预防建议(可选)
55
+
56
+ 输出格式:
57
+ ❌ 错误:[原因]
58
+ ✅ 修复:[命令/步骤]
59
+ 💡 提示:[额外建议]`,
60
+ smartShell: `你是 Shell 脚本专家,擅长根据自然语言描述生成正确的 Shell 命令。
61
+
62
+ 任务:根据用户描述生成对应的 Shell 命令。
63
+
64
+ 输出格式:
65
+ 📝 命令:[生成的命令]
66
+ 📖 说明:[命令解释]`,
67
+ smartSql: `你是 SQL 专家,擅长根据自然语言描述生成 SQL 查询语句。
68
+
69
+ 任务:根据用户描述生成对应的 SQL 查询。
70
+
71
+ 输出格式:
72
+ 📝 SQL: [生成的 SQL]
73
+ 📖 说明:[查询解释]`,
74
+ };
75
+ function loadConfig(toolName, customPath) {
76
+ const configPath = customPath || DEFAULT_CONFIG_PATH;
77
+ let rawConfig = {};
78
+ if (fs.existsSync(configPath)) {
79
+ try {
80
+ const content = fs.readFileSync(configPath, 'utf-8');
81
+ rawConfig = JSON.parse(content);
82
+ }
83
+ catch (error) {
84
+ console.error(`⚠️ 配置文件解析失败:${error}`);
85
+ console.error(`📁 文件路径:${configPath}`);
86
+ process.exit(1);
87
+ }
88
+ }
89
+ const commonConfig = {
90
+ baseUrl: rawConfig.baseUrl || DEFAULT_COMMON_CONFIG.baseUrl,
91
+ apiKey: rawConfig.apiKey || '',
92
+ model: rawConfig.model || DEFAULT_COMMON_CONFIG.model,
93
+ ...rawConfig,
94
+ };
95
+ const toolConfig = rawConfig[toolName] || {};
96
+ const mergedConfig = {
97
+ ...commonConfig,
98
+ ...toolConfig,
99
+ };
100
+ if (!mergedConfig.systemMessage) {
101
+ mergedConfig.systemMessage = DEFAULT_SYSTEM_MESSAGES[toolName] || '';
102
+ }
103
+ if (!mergedConfig.apiKey) {
104
+ console.error('❌ 错误:缺少 API Key 配置');
105
+ console.error(`📁 请在配置文件中添加 apiKey 字段:${configPath}`);
106
+ console.error('\n📖 配置示例:');
107
+ console.error(JSON.stringify({
108
+ baseUrl: 'https://dashscope.aliyuncs.com/compatible-mode/v1',
109
+ apiKey: 'sk-xxxxx',
110
+ model: 'qwen-turbo',
111
+ [toolName]: {
112
+ model: 'qwen-plus',
113
+ }
114
+ }, null, 2));
115
+ process.exit(1);
116
+ }
117
+ return mergedConfig;
118
+ }
119
+ function getConfigPath(customPath) {
120
+ return customPath || DEFAULT_CONFIG_PATH;
121
+ }
122
+ function ensureConfigDir() {
123
+ const configDir = path.dirname(DEFAULT_CONFIG_PATH);
124
+ if (!fs.existsSync(configDir)) {
125
+ fs.mkdirSync(configDir, { recursive: true });
126
+ }
127
+ }
128
+ function createDefaultConfig() {
129
+ ensureConfigDir();
130
+ const defaultConfig = {
131
+ _comment: 'AI Tools 通用配置文件',
132
+ _docs: 'https://github.com/lance2026/ai-tools',
133
+ baseUrl: 'https://dashscope.aliyuncs.com/compatible-mode/v1',
134
+ apiKey: 'sk-xxxxx',
135
+ model: 'qwen-turbo',
136
+ errorSolver: {
137
+ model: 'qwen-plus',
138
+ explainMode: true,
139
+ },
140
+ };
141
+ const configPath = DEFAULT_CONFIG_PATH;
142
+ if (!fs.existsSync(configPath)) {
143
+ fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2));
144
+ console.log(`✅ 默认配置文件已创建:${configPath}`);
145
+ console.log('⚠️ 请编辑配置文件,填入你的 API Key');
146
+ }
147
+ }
148
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,gCAwDC;AAED,sCAEC;AAED,0CAKC;AAED,kDAqBC;AApID,uCAAyB;AACzB,2CAA6B;AAC7B,uCAAyB;AAGzB,MAAM,mBAAmB,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC;AAE1F,MAAM,qBAAqB,GAA0B;IACnD,OAAO,EAAE,mDAAmD;IAC5D,KAAK,EAAE,YAAY;CACpB,CAAC;AAEF,MAAM,uBAAuB,GAA2B;IACtD,WAAW,EAAE;;;;;;;;;;aAUF;IAEX,UAAU,EAAE;;;;;;aAMD;IAEX,QAAQ,EAAE;;;;;;aAMC;CACZ,CAAC;AAEF,SAAgB,UAAU,CAAC,QAAgB,EAAE,UAAmB;IAC9D,MAAM,UAAU,GAAG,UAAU,IAAI,mBAAmB,CAAC;IAGrD,IAAI,SAAS,GAAwB,EAAE,CAAC;IAExC,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9B,IAAI,CA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+ export declare function getLanguageIcon(lang: string): string;
3
+ export declare function formatLanguageName(lang: string): string;
4
+ //# sourceMappingURL=detector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detector.d.ts","sourceRoot":"","sources":["../src/detector.ts"],"names":[],"mappings":"AAEA,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CA8GxD;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAWpD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAWvD"}
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.detectLanguage = detectLanguage;
4
+ exports.getLanguageIcon = getLanguageIcon;
5
+ exports.formatLanguageName = formatLanguageName;
6
+ function detectLanguage(errorText) {
7
+ const lowerText = errorText.toLowerCase();
8
+ const pythonPatterns = [
9
+ /modulenotfounderror/i,
10
+ /importerror/i,
11
+ /syntaxerror:\s*invalid syntax/i,
12
+ /typeerror/i,
13
+ /valueerror/i,
14
+ /attributeerror/i,
15
+ /indentationerror/i,
16
+ /nameerror/i,
17
+ /keyerror/i,
18
+ /indexerror/i,
19
+ /pip\s+install/i,
20
+ /python\s+[0-9.]+/i,
21
+ /file\s+"[^"]+\.py"/i,
22
+ /line\s+\d+/i,
23
+ /traceback\s+\(most recent call last\)/i,
24
+ ];
25
+ const jsPatterns = [
26
+ /referenceerror/i,
27
+ /typeerror:?\s*cannot read/i,
28
+ /syntaxerror:/i,
29
+ /cannot find module/i,
30
+ /require\(/i,
31
+ /import\s+.*\s+from/i,
32
+ /undefined\s+is\s+not\s+a\s+function/i,
33
+ /webpack/i,
34
+ /babel/i,
35
+ /typescript/i,
36
+ /ts-node/i,
37
+ /npm\s+install/i,
38
+ /yarn\s+add/i,
39
+ /pnpm\s+add/i,
40
+ /node_modules/i,
41
+ /package\.json/i,
42
+ ];
43
+ const javaPatterns = [
44
+ /java\.lang\./i,
45
+ /exception\s+in\s+thread/i,
46
+ /caused by:/i,
47
+ /at\s+[\w.]+\([^)]*\)/i,
48
+ /maven/i,
49
+ /gradle/i,
50
+ /build\.gradle/i,
51
+ /pom\.xml/i,
52
+ ];
53
+ const goPatterns = [
54
+ /panic:/i,
55
+ /fatal error:/i,
56
+ /undefined:/i,
57
+ /cannot use\s+.*\s+as\s+type/i,
58
+ /go build/i,
59
+ /go run/i,
60
+ /go mod/i,
61
+ /import\s+"[^"]+"/i,
62
+ ];
63
+ const rustPatterns = [
64
+ /error\[E\d+\]:/i,
65
+ /could not find `[^`]+` in/i,
66
+ /the trait `[^`]+` is not implemented/i,
67
+ /cannot find value `[^`]+`/i,
68
+ /mismatched types/i,
69
+ /borrowed value does not live long enough/i,
70
+ /cargo\s+(build|run)/i,
71
+ /Cargo\.toml/i,
72
+ ];
73
+ function checkPatterns(text, patterns) {
74
+ return patterns.reduce((count, pattern) => {
75
+ return count + (pattern.test(text) ? 1 : 0);
76
+ }, 0);
77
+ }
78
+ const scores = {
79
+ python: checkPatterns(lowerText, pythonPatterns),
80
+ javascript: checkPatterns(lowerText, jsPatterns),
81
+ java: checkPatterns(lowerText, javaPatterns),
82
+ go: checkPatterns(lowerText, goPatterns),
83
+ rust: checkPatterns(lowerText, rustPatterns),
84
+ };
85
+ let maxScore = 0;
86
+ let detectedLang = 'unknown';
87
+ for (const [lang, score] of Object.entries(scores)) {
88
+ if (score > maxScore) {
89
+ maxScore = score;
90
+ detectedLang = lang;
91
+ }
92
+ }
93
+ if (maxScore === 0) {
94
+ return 'unknown';
95
+ }
96
+ return detectedLang;
97
+ }
98
+ function getLanguageIcon(lang) {
99
+ const icons = {
100
+ python: '🐍',
101
+ javascript: '🟨',
102
+ typescript: '🟦',
103
+ java: '☕',
104
+ go: '🐹',
105
+ rust: '🦀',
106
+ unknown: '🔍',
107
+ };
108
+ return icons[lang] || '🔍';
109
+ }
110
+ function formatLanguageName(lang) {
111
+ const names = {
112
+ python: 'Python',
113
+ javascript: 'JavaScript',
114
+ typescript: 'TypeScript',
115
+ java: 'Java',
116
+ go: 'Go',
117
+ rust: 'Rust',
118
+ unknown: '未知',
119
+ };
120
+ return names[lang] || lang;
121
+ }
122
+ //# sourceMappingURL=detector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detector.js","sourceRoot":"","sources":["../src/detector.ts"],"names":[],"mappings":";;AAEA,wCA8GC;AAED,0CAWC;AAED,gDAWC;AAxID,SAAgB,cAAc,CAAC,SAAiB;IAC9C,MAAM,SAAS,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;IAG1C,MAAM,cAAc,GAAG;QACrB,sBAAsB;QACtB,cAAc;QACd,gCAAgC;QAChC,YAAY;QACZ,aAAa;QACb,iBAAiB;QACjB,mBAAmB;QACnB,YAAY;QACZ,WAAW;QACX,aAAa;QACb,gBAAgB;QAChB,mBAAmB;QACnB,qBAAqB;QACrB,aAAa;QACb,wCAAwC;KACzC,CAAC;IAGF,MAAM,UAAU,GAAG;QACjB,iBAAiB;QACjB,4BAA4B;QAC5B,eAAe;QACf,qBAAqB;QACrB,YAAY;QACZ,qBAAqB;QACrB,sCAAsC;QACtC,UAAU;QACV,QAAQ;QACR,aAAa;QACb,UAAU;QACV,gBAAgB;QAChB,aAAa;QACb,aAAa;QACb,eAAe;QACf,gBAAgB;KACjB,CAAC;IAGF,MAAM,YAAY,GAAG;QACnB,eAAe;QACf,0BAA0B;QAC1B,aAAa;QACb,uBAAuB;QACvB,QAAQ;QACR,SAAS;QACT,gBAAgB;QAChB,WAAW;KACZ,CAAC;IAGF,MAAM,UAAU,GAAG;QACjB,SAAS;QACT,eAAe;QACf,aAAa;QACb,8BAA8B;QAC9B,WAAW;QACX,SAAS;QACT,SAAS;QACT,mBAAmB;KACpB,CAAC;IAGF,MAAM,YAAY,GAAG;QACnB,iBAAiB;QACjB,4BAA4B;QAC5B,uCAAuC;QACvC,4BAA4B;QAC5B,mBAAmB;QACnB,2CAA2C;QAC3C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AI,EAAE,IAAI;QACV,OAAO,EAAE,IAAI;KACd,CAAC;IACF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;AAC7B,CAAC;AAED,SAAgB,kBAAkB,CAAC,IAAY;IAC7C,MAAM,KAAK,GAA2B;QACpC,MAAM,EAAE,QAAQ;QAChB,UAAU,EAAE,YAAY;QACxB,UAAU,EAAE,YAAY;QACxB,IAAI,EAAE,MAAM;QACZ,EAAE,EAAE,IAAI;QACR,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,IAAI;KACd,CAAC;IACF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,17 @@
1
+ export interface AnalysisResult {
2
+ error?: string;
3
+ fix?: string;
4
+ hint?: string;
5
+ raw?: string;
6
+ }
7
+ export declare function formatResult(result: string): AnalysisResult;
8
+ export declare function printResult(result: AnalysisResult, _language?: string): void;
9
+ export declare function printLoading(text?: string): void;
10
+ export declare function printWelcome(): void;
11
+ export declare function printInputPrompt(): void;
12
+ export declare function printClipboardRead(): void;
13
+ export declare function printLanguageDetected(lang: string): void;
14
+ export declare function printError(message: string): void;
15
+ export declare function printInfo(message: string): void;
16
+ export declare function printSuccess(message: string): void;
17
+ //# sourceMappingURL=formatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,CAsB3D;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,cAAc,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAoB5E;AAED,wBAAgB,YAAY,CAAC,IAAI,GAAE,MAAc,GAAG,IAAI,CAEvD;AAED,wBAAgB,YAAY,IAAI,IAAI,CAMnC;AAED,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC;AAED,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAIxD;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAEhD;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE/C;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAElD"}
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.formatResult = formatResult;
7
+ exports.printResult = printResult;
8
+ exports.printLoading = printLoading;
9
+ exports.printWelcome = printWelcome;
10
+ exports.printInputPrompt = printInputPrompt;
11
+ exports.printClipboardRead = printClipboardRead;
12
+ exports.printLanguageDetected = printLanguageDetected;
13
+ exports.printError = printError;
14
+ exports.printInfo = printInfo;
15
+ exports.printSuccess = printSuccess;
16
+ const chalk_1 = __importDefault(require("chalk"));
17
+ function formatResult(result) {
18
+ const lines = result.split('\n');
19
+ const parsed = {};
20
+ for (const line of lines) {
21
+ const trimmed = line.trim();
22
+ if (trimmed.startsWith('❌ 错误:')) {
23
+ parsed.error = trimmed.replace('❌ 错误:', '').trim();
24
+ }
25
+ else if (trimmed.startsWith('✅ 修复:')) {
26
+ parsed.fix = trimmed.replace('✅ 修复:', '').trim();
27
+ }
28
+ else if (trimmed.startsWith('💡 提示:')) {
29
+ parsed.hint = trimmed.replace('💡 提示:', '').trim();
30
+ }
31
+ }
32
+ if (!parsed.error && !parsed.fix && !parsed.hint) {
33
+ parsed.raw = result;
34
+ }
35
+ return parsed;
36
+ }
37
+ function printResult(result, _language) {
38
+ console.log('');
39
+ if (result.raw) {
40
+ console.log(chalk_1.default.white(result.raw));
41
+ }
42
+ else {
43
+ if (result.error) {
44
+ console.log(chalk_1.default.red('❌ 错误: ') + chalk_1.default.yellow(result.error));
45
+ }
46
+ if (result.fix) {
47
+ console.log(chalk_1.default.green('✅ 修复: ') + chalk_1.default.cyan(result.fix));
48
+ }
49
+ if (result.hint) {
50
+ console.log(chalk_1.default.blue('💡 提示: ') + chalk_1.default.gray(result.hint));
51
+ }
52
+ }
53
+ console.log('');
54
+ }
55
+ function printLoading(text = '分析中') {
56
+ console.log(chalk_1.default.yellow('⏳ ') + chalk_1.default.gray(text) + '...');
57
+ }
58
+ function printWelcome() {
59
+ console.log('');
60
+ console.log(chalk_1.default.green.bold('🔧 Error Solver ') + chalk_1.default.gray('v1.0.0'));
61
+ console.log(chalk_1.default.gray('粘贴报错信息,AI 自动分析原因并给出修复方案'));
62
+ console.log(chalk_1.default.gray('输入 Ctrl+C 退出'));
63
+ console.log('');
64
+ }
65
+ function printInputPrompt() {
66
+ console.log(chalk_1.default.yellow('📋 ') + chalk_1.default.gray('请输入报错信息 (或直接粘贴):'));
67
+ }
68
+ function printClipboardRead() {
69
+ console.log(chalk_1.default.green('✅ ') + chalk_1.default.gray('已从剪贴板读取内容'));
70
+ }
71
+ function printLanguageDetected(lang) {
72
+ const icon = lang === 'unknown' ? '🔍' : getLanguageIcon(lang);
73
+ const name = formatLanguageName(lang);
74
+ console.log(chalk_1.default.cyan(`${icon} `) + chalk_1.default.gray(`检测到语言:${name}`));
75
+ }
76
+ function printError(message) {
77
+ console.error(chalk_1.default.red('❌ 错误: ') + message);
78
+ }
79
+ function printInfo(message) {
80
+ console.log(chalk_1.default.blue('ℹ️ ') + chalk_1.default.gray(message));
81
+ }
82
+ function printSuccess(message) {
83
+ console.log(chalk_1.default.green('✅ ') + message);
84
+ }
85
+ function getLanguageIcon(lang) {
86
+ const icons = {
87
+ python: '🐍',
88
+ javascript: '🟨',
89
+ typescript: '🟦',
90
+ java: '☕',
91
+ go: '🐹',
92
+ rust: '🦀',
93
+ unknown: '🔍',
94
+ };
95
+ return icons[lang] || '🔍';
96
+ }
97
+ function formatLanguageName(lang) {
98
+ const names = {
99
+ python: 'Python',
100
+ javascript: 'JavaScript',
101
+ typescript: 'TypeScript',
102
+ java: 'Java',
103
+ go: 'Go',
104
+ rust: 'Rust',
105
+ unknown: '未知',
106
+ };
107
+ return names[lang] || lang;
108
+ }
109
+ //# sourceMappingURL=formatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatter.js","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":";;;;;AAWA,oCAsBC;AAED,kCAoBC;AAED,oCAEC;AAED,oCAMC;AAED,4CAEC;AAED,gDAEC;AAED,sDAIC;AAED,gCAEC;AAED,8BAEC;AAED,oCAEC;AA3FD,kDAA0B;AAS1B,SAAgB,YAAY,CAAC,MAAc;IACzC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,MAAM,GAAmB,EAAE,CAAC;IAElC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAE5B,IAAI,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YAChC,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACrD,CAAC;aAAM,IAAI,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YACvC,MAAM,CAAC,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACnD,CAAC;aAAM,IAAI,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CA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C,CAAC;AACpE,CAAC;AAED,SAAgB,UAAU,CAAC,OAAe;IACxC,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,CAAC;AAC/C,CAAC;AAED,SAAgB,SAAS,CAAC,OAAe;IACvC,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,eAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,SAAgB,YAAY,CAAC,OAAe;IAC1C,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC;AAC3C,CAAC;AAGD,SAAS,eAAe,CAAC,IAAY;IACnC,MAAM,KAAK,GAA2B;QACpC,MAAM,EAAE,IAAI;QACZ,UAAU,EAAE,IAAI;QAChB,UAAU,EAAE,IAAI;QAChB,IAAI,EAAE,GAAG;QACT,EAAE,EAAE,IAAI;QACR,IAAI,EAAE,IAAI;QACV,OAAO,EAAE,IAAI;KACd,CAAC;IACF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;AAC7B,CAAC;AAED,SAAS,kBAAkB,CAAC,IAAY;IACtC,MAAM,KAAK,GAA2B;QACpC,MAAM,EAAE,QAAQ;QAChB,UAAU,EAAE,YAAY;QACxB,UAAU,EAAE,YAAY;QACxB,IAAI,EAAE,MAAM;QACZ,EAAE,EAAE,IAAI;QACR,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,IAAI;KACd,CAAC;IACF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const commander_1 = require("commander");
7
+ const package_json_1 = require("../package.json");
8
+ const error_solve_1 = __importDefault(require("./commands/error-solve"));
9
+ const smart_shell_1 = __importDefault(require("./commands/smart-shell"));
10
+ const smart_sql_1 = __importDefault(require("./commands/smart-sql"));
11
+ const program = new commander_1.Command();
12
+ program
13
+ .name('ai-tools')
14
+ .description(package_json_1.description)
15
+ .version(package_json_1.version);
16
+ program.command('error-solve')
17
+ .alias('es')
18
+ .description('AI 驱动的报错分析工具')
19
+ .option('-y, --yes', '直接读取剪贴板,不交互')
20
+ .option('-c, --config <path>', '指定配置文件路径')
21
+ .option('-e, --explain', '启用详细解释模式')
22
+ .action((options) => (0, error_solve_1.default)(options));
23
+ program.command('smart-shell')
24
+ .alias('shell')
25
+ .description('根据自然语言生成 Shell 命令')
26
+ .option('-c, --config <path>', '指定配置文件路径')
27
+ .option('-r, --run', '直接执行生成的命令')
28
+ .action((options) => (0, smart_shell_1.default)(options));
29
+ program.command('smart-sql')
30
+ .alias('sql')
31
+ .description('根据自然语言生成 SQL 查询')
32
+ .option('-c, --config <path>', '指定配置文件路径')
33
+ .option('--dialect <type>', 'SQL 方言 (mysql/postgresql/sqlite)', 'mysql')
34
+ .action((options) => (0, smart_sql_1.default)(options));
35
+ program.parse(process.argv);
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAEA,yCAAoC;AACpC,kDAAuD;AAGvD,yEAAuD;AACvD,yEAAuD;AACvD,qEAAmD;AAEnD,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,UAAU,CAAC;KAChB,WAAW,CAAC,0BAAW,CAAC;KACxB,OAAO,CAAC,sBAAO,CAAC,CAAC;AAGpB,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC;KAC3B,KAAK,CAAC,IAAI,CAAC;KACX,WAAW,CAAC,cAAc,CAAC;KAC3B,MAAM,CAAC,WAAW,EAAE,aAAa,CAAC;KAClC,MAAM,CAAC,qBAAqB,EAAE,UAAU,CAAC;KACzC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC;KACnC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAA,qBAAiB,EAAC,OAAO,CAAC,CAAC,CAAC;AAEnD,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC;KAC3B,KAAK,CAAC,OAAO,CAAC;KACd,WAAW,CAAC,mBAAmB,CAAC;KAChC,MAAM,CAAC,qBAAqB,EAAE,UAAU,CAAC;KACzC,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC;KAChC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAA,qBAAiB,EAAC,OAAO,CAAC,CAAC,CAAC;AAEnD,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC;KACzB,KAAK,CAAC,KAAK,CAAC;KACZ,WAAW,CAAC,iBAAiB,CAAC;KAC9B,MAAM,CAAC,qBAAqB,EAAE,UAAU,CAAC;KACzC,MAAM,CAAC,kBAAkB,EAAE,kCAAkC,EAAE,OAAO,CAAC;KACvE,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAA,mBAAe,EAAC,OAAO,CAAC,CAAC,CAAC;AAEjD,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
package/dist/llm.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { MergedConfig, Message } from './types';
2
+ export declare function callLLM(config: MergedConfig, messages: Message[]): Promise<string>;
3
+ export declare function createMessages(systemMessage: string, userContent: string): Message[];
4
+ //# sourceMappingURL=llm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm.d.ts","sourceRoot":"","sources":["../src/llm.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAe,MAAM,SAAS,CAAC;AAE7D,wBAAsB,OAAO,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CA6BxF;AAED,wBAAgB,cAAc,CAAC,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,EAAE,CAKpF"}
package/dist/llm.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.callLLM = callLLM;
4
+ exports.createMessages = createMessages;
5
+ async function callLLM(config, messages) {
6
+ const url = `${config.baseUrl}/chat/completions`;
7
+ try {
8
+ const response = await fetch(url, {
9
+ method: 'POST',
10
+ headers: {
11
+ 'Authorization': `Bearer ${config.apiKey}`,
12
+ 'Content-Type': 'application/json',
13
+ },
14
+ body: JSON.stringify({
15
+ model: config.model,
16
+ messages,
17
+ }),
18
+ });
19
+ if (!response.ok) {
20
+ const errorText = await response.text();
21
+ throw new Error(`API 请求失败 (${response.status}): ${errorText}`);
22
+ }
23
+ const data = await response.json();
24
+ return data.choices[0]?.message?.content || '未获取到响应内容';
25
+ }
26
+ catch (error) {
27
+ if (error instanceof Error) {
28
+ throw error;
29
+ }
30
+ throw new Error('调用 LLM 服务时发生未知错误');
31
+ }
32
+ }
33
+ function createMessages(systemMessage, userContent) {
34
+ return [
35
+ { role: 'system', content: systemMessage },
36
+ { role: 'user', content: userContent },
37
+ ];
38
+ }
39
+ //# sourceMappingURL=llm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm.js","sourceRoot":"","sources":["../src/llm.ts"],"names":[],"mappings":";;AAIA,0BA6BC;AAED,wCAKC;AApCM,KAAK,UAAU,OAAO,CAAC,MAAoB,EAAE,QAAmB;IACrE,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC,OAAO,mBAAmB,CAAC;IAEjD,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;YAChC,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,eAAe,EAAE,UAAU,MAAM,CAAC,MAAM,EAAE;gBAC1C,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,QAAQ;aACT,CAAC;SACH,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CAAC,aAAa,QAAQ,CAAC,MAAM,MAAM,SAAS,EAAE,CAAC,CAAC;QACjE,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAiB,CAAC;QAClD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,IAAI,UAAU,CAAC;IACzD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,MAAM,KAAK,CAAC;QACd,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACtC,CAAC;AACH,CAAC;AAED,SAAgB,cAAc,CAAC,aAAqB,EAAE,WAAmB;IACvE,OAAO;QACL,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE;QAC1C,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE;KACvC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,26 @@
1
+ export interface CommonConfig {
2
+ baseUrl: string;
3
+ apiKey: string;
4
+ model: string;
5
+ }
6
+ export interface ToolConfig {
7
+ model?: string;
8
+ systemMessage?: string;
9
+ languages?: string[];
10
+ explainMode?: boolean;
11
+ autoCopyFix?: boolean;
12
+ [key: string]: any;
13
+ }
14
+ export type MergedConfig = Omit<CommonConfig, keyof ToolConfig> & CommonConfig & ToolConfig;
15
+ export interface Message {
16
+ role: 'system' | 'user' | 'assistant';
17
+ content: string;
18
+ }
19
+ export interface LLMResponse {
20
+ choices: {
21
+ message: {
22
+ content: string;
23
+ };
24
+ }[];
25
+ }
26
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,EAAE,MAAM,UAAU,CAAC,GAAG,YAAY,GAAG,UAAU,CAAC;AAE5F,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE;QACP,OAAO,EAAE;YACP,OAAO,EAAE,MAAM,CAAC;SACjB,CAAC;KACH,EAAE,CAAC;CACL"}
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@lance2026/ai-tools",
3
+ "version": "1.0.0",
4
+ "description": "AI 驱动的开发工具集 - 报错分析、Shell 生成、SQL 生成等",
5
+ "main": "dist/index.js",
6
+ "bin": {
7
+ "ai-error": "./bin/ai-error",
8
+ "ai-shell": "./bin/ai-shell",
9
+ "ai-sql": "./bin/ai-sql"
10
+ },
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "prepublishOnly": "npm run build",
14
+ "start": "npm run build && node bin/ai-error",
15
+ "dev": "tsc && node bin/ai-error"
16
+ },
17
+ "keywords": [
18
+ "ai",
19
+ "cli",
20
+ "error",
21
+ "debug",
22
+ "shell",
23
+ "sql",
24
+ "llm",
25
+ "qwen",
26
+ "openai",
27
+ "dev-tools"
28
+ ],
29
+ "author": "lance2026",
30
+ "license": "MIT",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/lance2026/ai-tools.git"
34
+ },
35
+ "engines": {
36
+ "node": ">=18"
37
+ },
38
+ "files": [
39
+ "dist",
40
+ "bin",
41
+ "README.md"
42
+ ],
43
+ "dependencies": {
44
+ "chalk": "^5.6.2",
45
+ "clipboardy": "^5.3.1",
46
+ "commander": "^14.0.3",
47
+ "prompts": "^2.4.2"
48
+ },
49
+ "devDependencies": {
50
+ "@types/node": "^25.3.0",
51
+ "@types/prompts": "^2.4.9",
52
+ "typescript": "^5.9.3"
53
+ }
54
+ }