momo-ai 1.0.89 → 1.0.91
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 +1 -1
- package/src/executor/executeTask.js +24 -21
- package/src/utils/momo-menu.js +8 -1
package/package.json
CHANGED
|
@@ -183,22 +183,21 @@ const _loadSlots = async (taskDir, taskSlots) => {
|
|
|
183
183
|
return slots;
|
|
184
184
|
};
|
|
185
185
|
|
|
186
|
-
const
|
|
186
|
+
const _selectTaskSlots = async (slots) => {
|
|
187
187
|
require('colors');
|
|
188
|
-
const {
|
|
188
|
+
const { selectMultiple } = require('../utils/momo-menu');
|
|
189
189
|
const menuItems = slots.map((item) => ({
|
|
190
|
-
name: item.name,
|
|
191
|
-
description: item.
|
|
190
|
+
name: item.name.replace(/\.md$/, ''),
|
|
191
|
+
description: item.isPlaceholder ? '空' : (item.title || '任务'),
|
|
192
192
|
slot: item.slot
|
|
193
193
|
}));
|
|
194
|
-
return
|
|
194
|
+
return selectMultiple(menuItems, `选择要归档的任务(空槽位无操作)`);
|
|
195
195
|
};
|
|
196
196
|
|
|
197
197
|
module.exports = (options) => {
|
|
198
198
|
try {
|
|
199
199
|
const cwd = process.cwd();
|
|
200
200
|
const taskDir = _resolveTaskDir(cwd);
|
|
201
|
-
const title = '任务';
|
|
202
201
|
|
|
203
202
|
(async () => {
|
|
204
203
|
await fs.mkdir(taskDir, { recursive: true });
|
|
@@ -218,25 +217,29 @@ module.exports = (options) => {
|
|
|
218
217
|
process.exit(1);
|
|
219
218
|
}
|
|
220
219
|
|
|
221
|
-
|
|
222
|
-
|
|
220
|
+
// 展示所有槽位:有内容→归档到历史,空位→跳过
|
|
221
|
+
const result = await _selectTaskSlots(slots);
|
|
222
|
+
if (!result || result.items.length === 0) {
|
|
223
223
|
Ec.warn('已取消');
|
|
224
224
|
process.exit(0);
|
|
225
225
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
226
|
+
let audioPlayed = false;
|
|
227
|
+
for (const chosen of result.items) {
|
|
228
|
+
const target = slots.find((item) => item.slot === chosen.slot);
|
|
229
|
+
if (!target) continue;
|
|
230
|
+
|
|
231
|
+
if (target.isPlaceholder) {
|
|
232
|
+
// 空槽位:不做任何操作
|
|
233
|
+
Ec.info(`${target.name} 为空,已跳过`);
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
// 有内容:归档到历史,回写空占位保持槽位
|
|
237
|
+
await _archiveTask(taskDir, target.name, target.content, cwd, !audioPlayed);
|
|
238
|
+
audioPlayed = true;
|
|
239
|
+
const yaml = _yamlFrontmatter({ runAt: _formatRunAt(new Date()), title: '任务' });
|
|
240
|
+
await fs.writeFile(target.fullPath, yaml, 'utf8');
|
|
241
|
+
Ec.info(`已回写 ${target.name}(空占位)`);
|
|
230
242
|
}
|
|
231
|
-
await _archiveTask(taskDir, target.name, target.content, cwd, true);
|
|
232
|
-
|
|
233
|
-
const taskPath = target.fullPath;
|
|
234
|
-
const taskFile = target.name;
|
|
235
|
-
const yaml = _yamlFrontmatter({ runAt: _formatRunAt(new Date()), title });
|
|
236
|
-
await fs.writeFile(taskPath, yaml, 'utf8');
|
|
237
|
-
|
|
238
|
-
Ec.info(`已新建 ${taskFile}(历史任务已转移,YAML: runAt, title)`);
|
|
239
|
-
Ec.info(`路径: ${path.relative(cwd, taskPath)}`);
|
|
240
243
|
Ec.waiting('momo task 已准备好任务文件;如需复制执行提示词,请运行 momo run');
|
|
241
244
|
process.exit(0);
|
|
242
245
|
})().catch((error) => {
|
package/src/utils/momo-menu.js
CHANGED
|
@@ -63,7 +63,14 @@ const _baseSelect = (items, title, isMulti) => new Promise(resolve => {
|
|
|
63
63
|
if (key.name === 'return') {
|
|
64
64
|
cleanup();
|
|
65
65
|
if (!isMulti) resolve(items[cursor]);
|
|
66
|
-
else
|
|
66
|
+
else {
|
|
67
|
+
const indices = selected.map((v, i) => v ? i : -1).filter(i => i !== -1);
|
|
68
|
+
if (indices.length === 0) {
|
|
69
|
+
resolve({ indices: [cursor], items: [items[cursor]] });
|
|
70
|
+
} else {
|
|
71
|
+
resolve({ indices, items: items.filter((_, i) => selected[i]) });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
67
74
|
}
|
|
68
75
|
};
|
|
69
76
|
|