yuangs 1.3.32 → 1.3.34
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.
- package/README.md +12 -1
- package/cli.js +60 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -51,7 +51,14 @@ yuangs ai
|
|
|
51
51
|
- 直接输入问题进行对话
|
|
52
52
|
- 输入 `/clear` 清空对话历史
|
|
53
53
|
- 输入 `/history` 查看对话历史
|
|
54
|
-
|
|
54
|
+
### 命令生成模式(v1.3.32)
|
|
55
|
+
|
|
56
|
+
使用 `-e` 参数让 AI 为你生成 Linux 命令:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
yuangs ai -e "查看当前目录下大于100M的文件"
|
|
60
|
+
# 输出: > find . -type f -size +100M
|
|
61
|
+
```
|
|
55
62
|
|
|
56
63
|
## 应用列表
|
|
57
64
|
|
|
@@ -119,6 +126,10 @@ yuangs mail # 打开邮箱
|
|
|
119
126
|
|
|
120
127
|
## 近期主要更新日志
|
|
121
128
|
|
|
129
|
+
### v1.3.32 (2026-01-16)
|
|
130
|
+
- **新增** AI 命令生成模式:使用 `yuangs ai -e <描述>` 快速生成 Linux 命令。
|
|
131
|
+
- **优化** AI 接口升级:全面迁移至 OpenAI 兼容接口,提升稳定性。
|
|
132
|
+
|
|
122
133
|
### v1.3.22 (2025-11-30)
|
|
123
134
|
- **新增** AI 命令支持 `-p` `-f` `-l` 简写,快速选择gemini默认模型
|
|
124
135
|
|
package/cli.js
CHANGED
|
@@ -173,8 +173,68 @@ async function handleAICommand() {
|
|
|
173
173
|
if (command) {
|
|
174
174
|
console.log(chalk.gray('生成命令:'));
|
|
175
175
|
console.log(chalk.bold.green(`> ${command}`));
|
|
176
|
+
|
|
177
|
+
// 1. Try to copy to clipboard
|
|
178
|
+
let copied = false;
|
|
179
|
+
try {
|
|
180
|
+
const { spawn } = require('child_process');
|
|
181
|
+
let copyCmd, copyArgs = [];
|
|
182
|
+
if (process.platform === 'darwin') {
|
|
183
|
+
copyCmd = 'pbcopy';
|
|
184
|
+
} else if (process.platform === 'win32') {
|
|
185
|
+
copyCmd = 'clip';
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (copyCmd) {
|
|
189
|
+
const proc = spawn(copyCmd, copyArgs);
|
|
190
|
+
proc.stdin.write(command);
|
|
191
|
+
proc.stdin.end();
|
|
192
|
+
copied = true;
|
|
193
|
+
console.log(chalk.gray('(已复制到剪贴板)'));
|
|
194
|
+
}
|
|
195
|
+
} catch (e) {
|
|
196
|
+
// Ignore copy errors
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// 2. Pre-fill and ask to execute
|
|
200
|
+
const readline = require('readline');
|
|
201
|
+
const rl = readline.createInterface({
|
|
202
|
+
input: process.stdin,
|
|
203
|
+
output: process.stdout
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
console.log(chalk.gray('👇 您可以直接回车执行,或修改后回车:'));
|
|
207
|
+
|
|
208
|
+
// This puts the command into the input line, effectively "pre-filling" it
|
|
209
|
+
rl.write(command);
|
|
210
|
+
|
|
211
|
+
rl.on('line', (input) => {
|
|
212
|
+
rl.close();
|
|
213
|
+
const finalCommand = input.trim();
|
|
214
|
+
|
|
215
|
+
if (!finalCommand) {
|
|
216
|
+
process.exit(0);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const { spawn } = require('child_process');
|
|
220
|
+
console.log(chalk.gray('正在执行...'));
|
|
221
|
+
// Use shell: true to support pipes, redirects, etc.
|
|
222
|
+
const child = spawn(finalCommand, [], { shell: true, stdio: 'inherit' });
|
|
223
|
+
|
|
224
|
+
child.on('close', (code) => {
|
|
225
|
+
if (code !== 0) {
|
|
226
|
+
console.log(chalk.red(`\n命令执行失败 (退出码: ${code})`));
|
|
227
|
+
}
|
|
228
|
+
process.exit(code);
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// Return to avoid continuing to other logic, let callback handle exit
|
|
233
|
+
return;
|
|
234
|
+
|
|
176
235
|
} else {
|
|
177
236
|
console.log(chalk.yellow('未能生成有效的命令。'));
|
|
237
|
+
process.exit(1);
|
|
178
238
|
}
|
|
179
239
|
return;
|
|
180
240
|
}
|