momo-ai 1.0.3 → 1.0.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "momo-ai",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Rachel Momo ( OpenSpec )",
5
5
  "main": "src/momo.js",
6
6
  "bin": {
@@ -22,15 +22,16 @@ const outString = (paths, content, sync = false) => __FX.fxContinue(!!content, (
22
22
  const outCopy = (data) => new Promise(function (resolve, reject) {
23
23
  const platform = os.platform();
24
24
  let cmd = '';
25
- if (os.platform() === 'win32') {
25
+ if (platform === 'win32') {
26
26
  cmd = 'clip';
27
- } else if (os.platform() === 'darwin') {
27
+ } else if (platform === 'darwin') {
28
28
  cmd = 'pbcopy';
29
29
  } else {
30
- __FX.fxError(10032, platform);
30
+ // 对于Linux和其他Unix-like系统,尝试使用xclip
31
+ cmd = 'xclip';
31
32
  }
32
33
 
33
- const proc = require('child_process').spawn(cmd);
34
+ const proc = require('child_process').spawn(cmd, platform !== 'win32' && platform !== 'darwin' ? ['-selection', 'clipboard'] : []);
34
35
  proc.on('error', function (err) {
35
36
  reject(err);
36
37
  });
@@ -49,65 +49,85 @@ const _selectLLM = async (actorName) => {
49
49
  };
50
50
  };
51
51
 
52
- module.exports = (options) => {
52
+ module.exports = async (options) => {
53
53
  // 参数提取
54
54
  const parsed = Ec.parseArgument(options);
55
+ const actorName = parsed.actor || parsed.a;
55
56
 
56
- const actorName = parsed.name;
57
- Ec.waiting(`🔍 准备创建角色: ${actorName}`);
58
-
59
- // 创建角色目录
60
- const actorDir = path.resolve(process.cwd(), 'specification', 'actor', actorName);
61
- if (!fs.existsSync(actorDir)) {
62
- Ec.waiting(`📁 创建角色目录: ${actorDir}`);
63
- fs.mkdirSync(actorDir, {recursive: true});
64
- } else {
65
- Ec.waiting(`✅ 角色目录已存在: ${actorDir}`);
57
+ if (!actorName) {
58
+ Ec.error("❌ 请提供角色名称 (-a, --actor)");
59
+ process.exit(1);
60
+ }
61
+
62
+ // Windows 上检查非法字符
63
+ if (process.platform === 'win32') {
64
+ const illegalChars = /[<>:"/\\|?*\x00-\x1F]/g;
65
+ if (illegalChars.test(actorName)) {
66
+ Ec.error(`❌ 角色名称 "${actorName}" 包含非法字符,请避免使用以下字符: < > : " / \\ | ? * 以及控制字符`);
67
+ process.exit(1);
68
+ }
66
69
  }
67
70
 
68
- // 从模板复制内容到stack.md和limit.md
69
- const templatePath = path.resolve(__dirname, '../_template/LAIN/.momo/advanced/actor.md');
70
- if (fs.existsSync(templatePath)) {
71
- const templateContent = fs.readFileSync(templatePath, 'utf8');
72
-
73
- // 提取技能说明部分作为stack.md的内容
74
- const stackMatch = templateContent.match(/## 技能说明\s*([\s\S]*?)\s*## 角色限制/);
75
- if (stackMatch && stackMatch[1]) {
76
- const stackContent = `# 技术栈信息\n\n${stackMatch[1].trim()}\n`;
77
- const stackPath = path.resolve(actorDir, 'stack.md');
78
- fs.writeFileSync(stackPath, stackContent);
79
- Ec.waiting(`📄 创建技术栈文件: ${stackPath}`);
71
+ try {
72
+ // 检查 specification/actor 目录是否存在
73
+ const actorBaseDir = path.resolve(process.cwd(), 'specification', 'actor');
74
+ if (!fs.existsSync(actorBaseDir)) {
75
+ Ec.error("❌ 未找到 specification/actor 目录,请先初始化项目");
76
+ process.exit(1);
80
77
  }
81
78
 
82
- // 提取角色限制部分作为limit.md的内容
83
- const limitMatch = templateContent.match(/## 角色限制\s*([\s\S]*)/);
84
- if (limitMatch && limitMatch[1]) {
85
- const limitContent = `# 角色限制\n\n${limitMatch[1].trim()}\n`;
86
- const limitPath = path.resolve(actorDir, 'limit.md');
87
- fs.writeFileSync(limitPath, limitContent);
88
- Ec.waiting(`📄 创建限制文件: ${limitPath}`);
79
+ // 检查角色是否已存在
80
+ const actorDir = path.resolve(actorBaseDir, actorName);
81
+ if (fs.existsSync(actorDir)) {
82
+ Ec.error(`❌ 角色 "${actorName}" 已存在`);
83
+ process.exit(1);
89
84
  }
90
- }
91
85
 
92
- // 交互式选择LLM
93
- _selectLLM(actorName)
94
- .then((llmConfig) => {
95
- // 创建config.json文件
96
- const configPath = path.resolve(actorDir, 'config.json');
97
- fs.writeFileSync(configPath, JSON.stringify(llmConfig, null, 4));
98
- Ec.waiting(`⚙️ 创建配置文件: ${configPath}`);
86
+ // 创建角色目录
87
+ if (!fs.existsSync(actorDir)) {
88
+ fs.mkdirSync(actorDir, { recursive: true });
89
+ }
99
90
 
100
- Ec.info(`✅ 角色 "${actorName}" 创建完成`);
101
- // 关闭 readline 接口
102
- Ec.askClose();
103
- // 退出程序
104
- process.exit(0);
105
- })
106
- .catch((error) => {
107
- Ec.error(`❌ 执行过程中发生错误: ${error.message}`);
108
- // 关闭 readline 接口
109
- Ec.askClose();
110
- // 退出程序
91
+ // 从模板复制内容到stack.md和limit.md
92
+ const templatePath = path.resolve(__dirname, '../_template/LAIN/.momo/advanced/actor.md');
93
+ if (fs.existsSync(templatePath)) {
94
+ const templateContent = fs.readFileSync(templatePath, 'utf8');
95
+
96
+ // 提取技术栈和限制信息
97
+ const stackMatch = templateContent.match(/## 技术栈([\s\S]*?)## 限制/);
98
+ const limitMatch = templateContent.match(/## 限制([\s\S]*)/);
99
+
100
+ if (stackMatch && limitMatch) {
101
+ const stackContent = `# 技术栈信息\n\n${stackMatch[1].trim()}\n`;
102
+ const stackPath = path.resolve(actorDir, 'stack.md');
103
+ fs.writeFileSync(stackPath, stackContent);
104
+ Ec.waiting(`📄 创建技术栈文件: ${stackPath}`);
105
+
106
+ const limitContent = `# 角色限制\n\n${limitMatch[1].trim()}\n`;
107
+ const limitPath = path.resolve(actorDir, 'limit.md');
108
+ fs.writeFileSync(limitPath, limitContent);
109
+ Ec.waiting(`📄 创建限制文件: ${limitPath}`);
110
+
111
+ // 创建config.json文件
112
+ const configPath = path.resolve(actorDir, 'config.json');
113
+ fs.writeFileSync(configPath, JSON.stringify(llmConfig, null, 4));
114
+ Ec.waiting(`📄 创建配置文件: ${configPath}`);
115
+
116
+ Ec.info(`✅ 成功添加新角色 "${actorName}"`);
117
+ process.exit(0);
118
+ } else {
119
+ Ec.error("❌ 模板文件格式不正确");
120
+ process.exit(1);
121
+ }
122
+ } else {
123
+ Ec.error(`❌ 未找到模板文件: ${templatePath}`);
111
124
  process.exit(1);
112
- });
113
- };
125
+ }
126
+ } catch (error) {
127
+ Ec.error(`❌ 执行过程中发生错误: ${error.message}`);
128
+ if (process.platform === 'win32') {
129
+ Ec.waiting('💡 Windows 用户提示: 请确保您在具有足够权限的命令行中运行此命令');
130
+ }
131
+ process.exit(1);
132
+ }
133
+ };
@@ -34,6 +34,9 @@ const _readTemplate = async (templatePath) => {
34
34
  return content;
35
35
  } catch (error) {
36
36
  Ec.waiting(`读取模板文件失败: ${error.message}`);
37
+ if (process.platform === 'win32') {
38
+ Ec.waiting('💡 Windows 用户提示: 请确保您在具有足够权限的命令行中运行此命令');
39
+ }
37
40
  throw error;
38
41
  }
39
42
  };
@@ -117,6 +120,10 @@ const _copyTemplateFiles = async (templateDir, targetDir, sourceFilePath = null)
117
120
  } else if (fs.existsSync(proposalSource)) {
118
121
  Ec.waiting(`拷贝文件: ${proposalTarget}`);
119
122
  await fsAsync.copyFile(proposalSource, proposalTarget);
123
+ } else {
124
+ // 如果模板文件不存在,则创建空文件
125
+ Ec.waiting(`创建空文件: ${proposalTarget}`);
126
+ await fsAsync.writeFile(proposalTarget, '');
120
127
  }
121
128
 
122
129
  // 拷贝 tasks.md
@@ -125,6 +132,10 @@ const _copyTemplateFiles = async (templateDir, targetDir, sourceFilePath = null)
125
132
  if (fs.existsSync(tasksSource)) {
126
133
  Ec.waiting(`拷贝文件: ${tasksTarget}`);
127
134
  await fsAsync.copyFile(tasksSource, tasksTarget);
135
+ } else {
136
+ // 如果模板文件不存在,则创建空文件
137
+ Ec.waiting(`创建空文件: ${tasksTarget}`);
138
+ await fsAsync.writeFile(tasksTarget, '');
128
139
  }
129
140
 
130
141
  // 创建 tasks 目录
@@ -140,9 +151,16 @@ const _copyTemplateFiles = async (templateDir, targetDir, sourceFilePath = null)
140
151
  if (fs.existsSync(taskDetailSource)) {
141
152
  Ec.waiting(`拷贝文件: ${taskDetailTarget}`);
142
153
  await fsAsync.copyFile(taskDetailSource, taskDetailTarget);
154
+ } else {
155
+ // 如果模板文件不存在,则创建空文件
156
+ Ec.waiting(`创建空文件: ${taskDetailTarget}`);
157
+ await fsAsync.writeFile(taskDetailTarget, '');
143
158
  }
144
159
  } catch (error) {
145
160
  Ec.waiting(`拷贝模板文件失败: ${error.message}`);
161
+ if (process.platform === 'win32') {
162
+ Ec.waiting('💡 Windows 用户提示: 请确保您在具有足够权限的命令行中运行此命令');
163
+ }
146
164
  throw error;
147
165
  }
148
166
  };
@@ -155,13 +173,26 @@ const _copyToClipboard = async (content) => {
155
173
  try {
156
174
  // 去除换行符,将内容合并为一行
157
175
  const contentWithoutNewlines = content.replace(/\r?\n|\r/g, ' ');
158
- const proc = spawn('pbcopy', { stdio: 'pipe' });
176
+
177
+ // 根据操作系统选择合适的剪贴板命令
178
+ let proc;
179
+ if (process.platform === 'darwin') {
180
+ // macOS
181
+ proc = spawn('pbcopy', { stdio: 'pipe' });
182
+ } else if (process.platform === 'win32') {
183
+ // Windows
184
+ proc = spawn('clip', { stdio: 'pipe' });
185
+ } else {
186
+ // Linux/其他系统,尝试使用xclip
187
+ proc = spawn('xclip', ['-selection', 'clipboard'], { stdio: 'pipe' });
188
+ }
189
+
159
190
  proc.stdin.write(contentWithoutNewlines);
160
191
  proc.stdin.end();
161
192
  Ec.waiting('✅ 提示词已复制到剪贴板');
162
193
  } catch (error) {
163
194
  Ec.waiting(`复制到剪贴板失败: ${error.message}`);
164
- // 在非 macOS 系统上可能没有 pbcopy,提供备选方案
195
+ // 提供备选方案
165
196
  Ec.waiting('提示词内容:');
166
197
  console.log(content);
167
198
  }
@@ -203,6 +234,15 @@ module.exports = async (options) => {
203
234
  requirementName = await _extractTitleFromMarkdown(sourceFilePath);
204
235
  }
205
236
 
237
+ // 检查需求名称是否包含非法字符(Windows 上特别检查)
238
+ if (process.platform === 'win32') {
239
+ const illegalChars = /[<>:"/\\|?*\x00-\x1F]/g;
240
+ if (illegalChars.test(requirementName)) {
241
+ Ec.error(`❌ 需求名称 "${requirementName}" 包含非法字符,请避免使用以下字符: < > : " / \\ | ? * 以及控制字符`);
242
+ process.exit(1);
243
+ }
244
+ }
245
+
206
246
  // 检查需求名称是否包含点号(除了允许的独立需求)
207
247
  if (!hasExtension && requirementName.includes('.')) {
208
248
  Ec.error("❌ 独立需求名称不能包含点号(.),以防止与文件扩展名混淆");
@@ -224,10 +264,36 @@ module.exports = async (options) => {
224
264
  process.exit(1);
225
265
  }
226
266
 
267
+ // 确保 changes 目录存在
268
+ if (!fs.existsSync(changesDir)) {
269
+ Ec.waiting(`创建目录: ${changesDir}`);
270
+ try {
271
+ await fsAsync.mkdir(changesDir, { recursive: true });
272
+ } catch (mkdirError) {
273
+ Ec.error(`❌ 创建目录失败: ${mkdirError.message}`);
274
+ if (process.platform === 'win32') {
275
+ Ec.waiting('💡 Windows 用户提示: 请确保您在具有足够权限的命令行中运行此命令');
276
+ }
277
+ process.exit(1);
278
+ }
279
+ }
280
+
227
281
  // 创建需求目录
228
282
  const requirementDir = path.join(changesDir, requirementName);
229
283
  Ec.waiting(`创建需求目录: ${requirementDir}`);
230
- await fsAsync.mkdir(requirementDir, { recursive: true });
284
+ try {
285
+ await fsAsync.mkdir(requirementDir, { recursive: true });
286
+ } catch (mkdirError) {
287
+ Ec.error(`❌ 创建目录失败: ${mkdirError.message}`);
288
+ if (process.platform === 'win32') {
289
+ Ec.waiting('💡 Windows 用户提示: 请确保您在具有足够权限的命令行中运行此命令');
290
+ // 检查是否是由于特殊字符导致的问题
291
+ if (mkdirError.message.includes('Invalid argument') || mkdirError.message.includes('EINVAL')) {
292
+ Ec.waiting('💡 可能是由于需求名称包含非法字符,请尝试使用更简单的名称');
293
+ }
294
+ }
295
+ process.exit(1);
296
+ }
231
297
 
232
298
  // 拷贝模板文件
233
299
  await _copyTemplateFiles(templateDir, requirementDir, sourceFilePath);
@@ -243,6 +309,9 @@ module.exports = async (options) => {
243
309
  process.exit(0);
244
310
  } catch (error) {
245
311
  Ec.error(`❌ 执行过程中发生错误: ${error.message}`);
312
+ if (process.platform === 'win32') {
313
+ Ec.waiting('💡 Windows 用户提示: 请确保您在具有足够权限的命令行中运行此命令');
314
+ }
246
315
  process.exit(1);
247
316
  }
248
317
  };
@@ -22,22 +22,18 @@ const _getVersion = () => {
22
22
  };
23
23
 
24
24
  /**
25
- * 检查命令是否存在
25
+ * 检查命令是否可用
26
26
  * @param {string} command 命令名称
27
- * @returns {Promise<boolean>} 命令是否存在
27
+ * @returns {Promise<boolean>} 命令是否可用
28
28
  */
29
- const _checkCommand = async (command) => {
29
+ const _isCommandAvailable = async (command) => {
30
30
  try {
31
- await execAsync(`which ${command}`);
31
+ // 在 Windows 上使用 where 命令,在其他系统上使用 which 命令
32
+ const whereCmd = process.platform === 'win32' ? 'where' : 'which';
33
+ await execAsync(`${whereCmd} ${command}`);
32
34
  return true;
33
35
  } catch (error) {
34
- try {
35
- // 在 Windows 上尝试 where 命令
36
- await execAsync(`where ${command}`);
37
- return true;
38
- } catch (winError) {
39
- return false;
40
- }
36
+ return false;
41
37
  }
42
38
  };
43
39
 
@@ -71,7 +67,7 @@ module.exports = async () => {
71
67
 
72
68
  // 检查每个命令
73
69
  for (const command of requiredCommands) {
74
- const isAvailable = await _checkCommand(command);
70
+ const isAvailable = await _isCommandAvailable(command);
75
71
 
76
72
  if (isAvailable) {
77
73
  // const version = await _getCommandVersion(command);
@@ -35,8 +35,15 @@ const _ioDirectory = async (baseDir) => {
35
35
  for (const folder of folders) {
36
36
  Ec.waiting("创建目录:" + folder);
37
37
  const directory = path.resolve(baseDir, folder);
38
- await fsAsync.mkdir(directory, {recursive: true});
39
- results.push(true);
38
+ try {
39
+ await fsAsync.mkdir(directory, {recursive: true});
40
+ results.push(true);
41
+ } catch (error) {
42
+ if (process.platform === 'win32') {
43
+ Ec.waiting(`💡 Windows 用户提示: 创建目录失败,可能是由于权限不足或路径包含非法字符`);
44
+ }
45
+ throw error;
46
+ }
40
47
  }
41
48
  return results;
42
49
  }
@@ -96,6 +96,9 @@ module.exports = async (options) => {
96
96
 
97
97
  } catch (error) {
98
98
  Ec.error(`❌ 执行过程中发生错误: ${error.message}`);
99
+ if (process.platform === 'win32') {
100
+ Ec.waiting('💡 Windows 用户提示: 请确保您在具有足够权限的命令行中运行此命令');
101
+ }
99
102
  Ec.askClose();
100
103
  process.exit(1);
101
104
  }
@@ -108,7 +111,9 @@ module.exports = async (options) => {
108
111
  */
109
112
  const _isCommandAvailable = async (command) => {
110
113
  return new Promise((resolve) => {
111
- const process = spawn('which', [command]);
114
+ // Windows 上使用 where 命令,在其他系统上使用 which 命令
115
+ const whereCmd = process.platform === 'win32' ? 'where' : 'which';
116
+ const process = spawn(whereCmd, [command]);
112
117
  process.on('close', (code) => {
113
118
  resolve(code === 0);
114
119
  });
@@ -140,6 +145,9 @@ const _openWithTool = async (tool) => {
140
145
  child.on('error', (error) => {
141
146
  if (error.code === 'ENOENT') {
142
147
  Ec.error(`❌ 未找到命令: ${tool},请确保已正确安装`);
148
+ if (process.platform === 'win32') {
149
+ Ec.waiting('💡 Windows 用户提示: 请确保工具已正确安装并在 PATH 环境变量中');
150
+ }
143
151
  reject(new Error(`未找到命令: ${tool},请确保已正确安装`));
144
152
  } else {
145
153
  Ec.error(`❌ 执行 ${tool} 时发生错误: ${error.message}`);
@@ -72,9 +72,22 @@ const _isRequirementExists = (changesDir, requirementName) => {
72
72
  */
73
73
  const _copyToClipboard = async (content, requirementName) => {
74
74
  try {
75
- // 去除换行符,将内容合并为一行后再复制到剪贴板
75
+ // 去除换行符,将内容合并为一行
76
76
  const contentWithoutNewlines = content.replace(/\r?\n|\r/g, ' ');
77
- const proc = spawn('pbcopy', { stdio: 'pipe' });
77
+
78
+ // 根据操作系统选择合适的剪贴板命令
79
+ let proc;
80
+ if (process.platform === 'darwin') {
81
+ // macOS
82
+ proc = spawn('pbcopy', { stdio: 'pipe' });
83
+ } else if (process.platform === 'win32') {
84
+ // Windows
85
+ proc = spawn('clip', { stdio: 'pipe' });
86
+ } else {
87
+ // Linux/其他系统,尝试使用xclip
88
+ proc = spawn('xclip', ['-selection', 'clipboard'], { stdio: 'pipe' });
89
+ }
90
+
78
91
  proc.stdin.write(contentWithoutNewlines);
79
92
  proc.stdin.end();
80
93
  Ec.waiting('✅ 计划提示词已复制到剪贴板');
@@ -94,9 +107,12 @@ const _copyToClipboard = async (content, requirementName) => {
94
107
  Ec.waiting(`📄 计划提示词已保存到文件: ${filePath}`);
95
108
  } catch (error) {
96
109
  Ec.waiting(`复制到剪贴板失败: ${error.message}`);
97
- // 在非 macOS 系统上可能没有 pbcopy,提供备选方案
110
+ // 提供备选方案
98
111
  Ec.waiting('计划提示词内容:');
99
112
  console.log(content);
113
+ if (process.platform === 'win32') {
114
+ Ec.waiting('💡 Windows 用户提示: 请确保您在具有足够权限的命令行中运行此命令');
115
+ }
100
116
  }
101
117
  };
102
118
 
@@ -119,6 +135,15 @@ module.exports = async (options) => {
119
135
  process.exit(1);
120
136
  }
121
137
 
138
+ // 在 Windows 上检查非法字符
139
+ if (process.platform === 'win32') {
140
+ const illegalChars = /[<>:"/\\|?*\x00-\x1F]/g;
141
+ if (illegalChars.test(requirementName)) {
142
+ Ec.error(`❌ 需求名称 "${requirementName}" 包含非法字符,请避免使用以下字符: < > : " / \\ | ? * 以及控制字符`);
143
+ process.exit(1);
144
+ }
145
+ }
146
+
122
147
  Ec.waiting(`准备生成需求计划: ${requirementName}`);
123
148
 
124
149
  try {
@@ -144,6 +169,9 @@ module.exports = async (options) => {
144
169
  process.exit(0);
145
170
  } catch (error) {
146
171
  Ec.error(`❌ 执行过程中发生错误: ${error.message}`);
172
+ if (process.platform === 'win32') {
173
+ Ec.waiting('💡 Windows 用户提示: 请确保您在具有足够权限的命令行中运行此命令');
174
+ }
147
175
  process.exit(1);
148
176
  }
149
177
  };
@@ -26,11 +26,15 @@ const _isGitRepo = async () => {
26
26
  const _initGitRepo = async () => {
27
27
  try {
28
28
  Ec.waiting('正在初始化 Git 仓库');
29
- const command = 'git init -b master';
29
+ // Windows 上使用不同的命令格式
30
+ const command = process.platform === 'win32' ? 'git init' : 'git init -b master';
30
31
  await execAsync(command);
31
32
  Ec.waiting('✅ 成功初始化 Git 仓库');
32
33
  } catch (error) {
33
34
  Ec.error(`❌ 初始化 Git 仓库失败: ${error.message}`);
35
+ if (process.platform === 'win32') {
36
+ Ec.waiting('💡 Windows 用户提示: 请确保已安装 Git 并在 PATH 环境变量中');
37
+ }
34
38
  throw error;
35
39
  }
36
40
  };
@@ -63,7 +63,19 @@ const _renderTemplate = (template, data) => {
63
63
  */
64
64
  const _copyToClipboard = async (content, requirementName, taskName) => {
65
65
  try {
66
- const proc = spawn('pbcopy', {stdio: 'pipe'});
66
+ // 根据操作系统选择合适的剪贴板命令
67
+ let proc;
68
+ if (process.platform === 'darwin') {
69
+ // macOS
70
+ proc = spawn('pbcopy', {stdio: 'pipe'});
71
+ } else if (process.platform === 'win32') {
72
+ // Windows
73
+ proc = spawn('clip', {stdio: 'pipe'});
74
+ } else {
75
+ // Linux/其他系统,尝试使用xclip
76
+ proc = spawn('xclip', ['-selection', 'clipboard'], {stdio: 'pipe'});
77
+ }
78
+
67
79
  proc.stdin.write(content);
68
80
  proc.stdin.end();
69
81
 
@@ -73,7 +85,7 @@ const _copyToClipboard = async (content, requirementName, taskName) => {
73
85
  if (code === 0) {
74
86
  resolve();
75
87
  } else {
76
- reject(new Error(`pbcopy 进程退出码: ${code}`));
88
+ reject(new Error(`剪贴板进程退出码: ${code}`));
77
89
  }
78
90
  });
79
91
  proc.on('error', reject);
@@ -99,6 +111,9 @@ const _copyToClipboard = async (content, requirementName, taskName) => {
99
111
  // 备选方案:显示内容
100
112
  Ec.waiting('提示词内容:');
101
113
  console.log(content);
114
+ if (process.platform === 'win32') {
115
+ Ec.waiting('💡 Windows 用户提示: 请确保您在具有足够权限的命令行中运行此命令');
116
+ }
102
117
  }
103
118
  };
104
119
 
@@ -61,7 +61,19 @@ const _renderTemplate = (template, data) => {
61
61
  */
62
62
  const _copyToClipboard = async (content) => {
63
63
  try {
64
- const proc = spawn('pbcopy', { stdio: 'pipe' });
64
+ // 根据操作系统选择合适的剪贴板命令
65
+ let proc;
66
+ if (process.platform === 'darwin') {
67
+ // macOS
68
+ proc = spawn('pbcopy', { stdio: 'pipe' });
69
+ } else if (process.platform === 'win32') {
70
+ // Windows
71
+ proc = spawn('clip', { stdio: 'pipe' });
72
+ } else {
73
+ // Linux/其他系统,尝试使用xclip
74
+ proc = spawn('xclip', ['-selection', 'clipboard'], { stdio: 'pipe' });
75
+ }
76
+
65
77
  proc.stdin.write(content);
66
78
  proc.stdin.end();
67
79
 
@@ -71,7 +83,7 @@ const _copyToClipboard = async (content) => {
71
83
  if (code === 0) {
72
84
  resolve();
73
85
  } else {
74
- reject(new Error(`pbcopy 进程退出码: ${code}`));
86
+ reject(new Error(`剪贴板进程退出码: ${code}`));
75
87
  }
76
88
  });
77
89
  proc.on('error', reject);
@@ -83,6 +95,9 @@ const _copyToClipboard = async (content) => {
83
95
  // 备选方案:显示内容
84
96
  Ec.waiting('提示词内容:');
85
97
  console.log(content);
98
+ if (process.platform === 'win32') {
99
+ Ec.waiting('💡 Windows 用户提示: 请确保您在具有足够权限的命令行中运行此命令');
100
+ }
86
101
  }
87
102
  };
88
103