luminae-helper 0.0.9 → 0.0.10
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/lib/constants.js +4 -0
- package/src/lib/ui.js +209 -12
package/package.json
CHANGED
package/src/lib/constants.js
CHANGED
|
@@ -140,6 +140,7 @@ function generateInstallTargets(skillId, skillType) {
|
|
|
140
140
|
targets.push({
|
|
141
141
|
toolId: tool.id,
|
|
142
142
|
installMode: "file",
|
|
143
|
+
conversion: null,
|
|
143
144
|
destPath: () => join(tool.commandDir(), `${skillId}.md`),
|
|
144
145
|
});
|
|
145
146
|
} else if (supportsSkill) {
|
|
@@ -147,6 +148,7 @@ function generateInstallTargets(skillId, skillType) {
|
|
|
147
148
|
targets.push({
|
|
148
149
|
toolId: tool.id,
|
|
149
150
|
installMode: "dir",
|
|
151
|
+
conversion: "command-to-skill",
|
|
150
152
|
destPath: () => join(tool.skillDir(), skillId),
|
|
151
153
|
});
|
|
152
154
|
}
|
|
@@ -155,6 +157,7 @@ function generateInstallTargets(skillId, skillType) {
|
|
|
155
157
|
targets.push({
|
|
156
158
|
toolId: tool.id,
|
|
157
159
|
installMode: "dir",
|
|
160
|
+
conversion: null,
|
|
158
161
|
destPath: () => join(tool.skillDir(), skillId),
|
|
159
162
|
});
|
|
160
163
|
} else if (supportsCommand) {
|
|
@@ -162,6 +165,7 @@ function generateInstallTargets(skillId, skillType) {
|
|
|
162
165
|
targets.push({
|
|
163
166
|
toolId: tool.id,
|
|
164
167
|
installMode: "file",
|
|
168
|
+
conversion: "skill-to-command",
|
|
165
169
|
destPath: () => join(tool.commandDir(), `${skillId}.md`),
|
|
166
170
|
});
|
|
167
171
|
}
|
package/src/lib/ui.js
CHANGED
|
@@ -20,6 +20,14 @@ export const TERM_GUTTER = " ";
|
|
|
20
20
|
*/
|
|
21
21
|
const inquirerContext = { clearPromptOnDone: true };
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* 转换提示开关:true 时保持当前交互流程,安装前逐工具询问是否允许 fallback 转换;
|
|
25
|
+
* false 时用户无感知,安装阶段自动转换,仅在完成后汇总告知哪些内容发生了转换。
|
|
26
|
+
*
|
|
27
|
+
* 这是代码内开关,暂不暴露 CLI 参数或配置项,便于后续确认是否开启转换提示。
|
|
28
|
+
*/
|
|
29
|
+
const SHOW_CONVERSION_CONFIRM_PROMPT = false;
|
|
30
|
+
|
|
23
31
|
/**
|
|
24
32
|
* 在关闭一个 inquirer prompt 之后、再 `printBanner` 或打开下一个 prompt 之前调用。
|
|
25
33
|
* 使用 `setImmediate` 推迟到当前轮询阶段之后,让 readline 的 `close`、MuteStream 的 flush
|
|
@@ -76,6 +84,130 @@ export function parseCheckboxResult(ans) {
|
|
|
76
84
|
return "back";
|
|
77
85
|
}
|
|
78
86
|
|
|
87
|
+
/**
|
|
88
|
+
* 找出安装时会发生“源类型 != 目标工具能力”的 fallback 转换。
|
|
89
|
+
* @param {string[]} skillIds
|
|
90
|
+
* @param {string[]} toolIds
|
|
91
|
+
* @returns {Map<string, { tool: object, items: { skill: object, target: object }[] }>}
|
|
92
|
+
*/
|
|
93
|
+
export function collectConversionFallbacks(skillIds, toolIds) {
|
|
94
|
+
const result = new Map();
|
|
95
|
+
const sids = asIdArray(skillIds);
|
|
96
|
+
const tids = asIdArray(toolIds);
|
|
97
|
+
|
|
98
|
+
for (const toolId of tids) {
|
|
99
|
+
const tool = TOOLS.find(t => t.id === toolId);
|
|
100
|
+
if (!tool) continue;
|
|
101
|
+
|
|
102
|
+
const items = [];
|
|
103
|
+
for (const skillId of sids) {
|
|
104
|
+
const skill = SKILLS.find(s => s.id === skillId);
|
|
105
|
+
if (!skill) continue;
|
|
106
|
+
|
|
107
|
+
const target = skill.installTargets?.find(tgt => tgt.toolId === toolId);
|
|
108
|
+
if (target?.conversion) items.push({ skill, target });
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (items.length > 0) result.set(toolId, { tool, items });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function conversionDescription(conversion) {
|
|
118
|
+
if (conversion === "command-to-skill") return "command 源 → skill 目录";
|
|
119
|
+
if (conversion === "skill-to-command") return "skill 源 → command 文件";
|
|
120
|
+
return "fallback 转换";
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function installModeDescription(target) {
|
|
124
|
+
if (!target) return "未知";
|
|
125
|
+
if (target.conversion) return `转换:${conversionDescription(target.conversion)}`;
|
|
126
|
+
return target.installMode === "file" ? "原生 command 文件" : "原生 skill 目录";
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function stripAnsi(text) {
|
|
130
|
+
return String(text).replace(/\x1b\[[0-9;]*m/g, "");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function displayWidth(text) {
|
|
134
|
+
const width = wcswidth(stripAnsi(text));
|
|
135
|
+
return width < 0 ? stripAnsi(text).length : width;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function padCell(text, width) {
|
|
139
|
+
const value = String(text);
|
|
140
|
+
return value + " ".repeat(Math.max(0, width - displayWidth(value)));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function printResultTable(title, rows) {
|
|
144
|
+
if (rows.length === 0) return;
|
|
145
|
+
|
|
146
|
+
const headers = ["工具", "内容", "状态", "安装方式"];
|
|
147
|
+
const data = rows.map(row => [row.toolName, row.skillName, row.status, row.mode]);
|
|
148
|
+
const widths = headers.map((header, idx) => Math.max(displayWidth(header), ...data.map(row => displayWidth(row[idx]))));
|
|
149
|
+
const gap = " ";
|
|
150
|
+
const formatRow = (cells) => TERM_GUTTER + cells.map((cell, idx) => padCell(cell, widths[idx])).join(gap);
|
|
151
|
+
|
|
152
|
+
console.log(chalk.cyan.bold(TERM_GUTTER + title));
|
|
153
|
+
console.log(formatRow(headers.map(header => chalk.gray(header))));
|
|
154
|
+
console.log(TERM_GUTTER + widths.map(width => chalk.gray("─".repeat(width))).join(gap));
|
|
155
|
+
for (const row of rows) {
|
|
156
|
+
console.log(formatRow([row.toolName, row.skillName, row.status, row.mode]));
|
|
157
|
+
}
|
|
158
|
+
console.log();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function mergeResultRows(...rowGroups) {
|
|
162
|
+
const merged = new Map();
|
|
163
|
+
for (const rows of rowGroups) {
|
|
164
|
+
for (const row of rows) merged.set(row.key, row);
|
|
165
|
+
}
|
|
166
|
+
return [...merged.values()];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// ── Step 3: Fallback conversion confirm(每个目标工具单独确认)──
|
|
170
|
+
async function stepConfirmConversionFallbacks(skillIds, toolIds) {
|
|
171
|
+
const fallbacks = collectConversionFallbacks(skillIds, toolIds);
|
|
172
|
+
const skippedKeys = new Set();
|
|
173
|
+
|
|
174
|
+
if (fallbacks.size === 0) return { action: "continue", skippedKeys };
|
|
175
|
+
|
|
176
|
+
for (const [toolId, { tool, items }] of fallbacks) {
|
|
177
|
+
await afterPromptFlush();
|
|
178
|
+
printBanner();
|
|
179
|
+
printSectionTitle("━━━ 兼容安装确认 ━━━");
|
|
180
|
+
|
|
181
|
+
console.log(chalk.yellow(TERM_GUTTER + `${tool.name} 不原生支持以下源类型,需要转换安装:\n`));
|
|
182
|
+
for (const { skill, target } of items) {
|
|
183
|
+
console.log(TERM_GUTTER + TERM_GUTTER + `- ${skill.name}:${conversionDescription(target.conversion)}`);
|
|
184
|
+
}
|
|
185
|
+
console.log();
|
|
186
|
+
|
|
187
|
+
const ans = await Select(
|
|
188
|
+
{
|
|
189
|
+
message: `是否允许对 ${tool.name} 使用以上兼容转换?`,
|
|
190
|
+
choices: [
|
|
191
|
+
{ name: "✓ 允许转换并安装", value: "allow" },
|
|
192
|
+
{ name: "- 跳过该工具的这些转换项", value: "skip" },
|
|
193
|
+
{ name: "↩ 返回上一步", value: "back" },
|
|
194
|
+
{ name: "✕ 退出", value: "exit" },
|
|
195
|
+
],
|
|
196
|
+
theme: { prefix: chalk.cyan(" ◆"), style: { highlight: (t) => chalk.cyan(t) } },
|
|
197
|
+
},
|
|
198
|
+
inquirerContext
|
|
199
|
+
).catch(() => "back");
|
|
200
|
+
|
|
201
|
+
if (ans === "back") return { action: "back", skippedKeys };
|
|
202
|
+
if (ans === "exit") return { action: "exit", skippedKeys };
|
|
203
|
+
if (ans === "skip") {
|
|
204
|
+
for (const { skill } of items) skippedKeys.add(`${toolId}::${skill.id}`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return { action: "continue", skippedKeys };
|
|
209
|
+
}
|
|
210
|
+
|
|
79
211
|
/**
|
|
80
212
|
* 在列表末尾追加「返回 / 退出」两项(`value` 为 `__back__` / `__exit__`)。
|
|
81
213
|
* 由 `checkbox-with-action-rows` 渲染为功能行:方向键移上去后按回车即触发,空格不会勾选。
|
|
@@ -227,9 +359,10 @@ async function stepPreviewConfirm(isUninstall) {
|
|
|
227
359
|
* @param {boolean} isUninstall
|
|
228
360
|
* @param {Set<string>|null} failedKeys - 若提供,只执行 key 在此集合中的组合;否则执行全部
|
|
229
361
|
* key 格式: `${toolId}::${skillId}`
|
|
230
|
-
* @
|
|
362
|
+
* @param {Set<string>} skippedKeys - 用户明确跳过的兼容转换项
|
|
363
|
+
* @returns {{ allSuccess: boolean, failedKeys: Set<string>, permanentFailedKeys: Set<string>, resultRows: object[] }}
|
|
231
364
|
*/
|
|
232
|
-
async function stepExecute(skillIds, toolIds, installedTools, isUninstall, failedKeys = null) {
|
|
365
|
+
async function stepExecute(skillIds, toolIds, installedTools, isUninstall, failedKeys = null, skippedKeys = new Set()) {
|
|
233
366
|
const sids = asIdArray(skillIds);
|
|
234
367
|
const tids = asIdArray(toolIds);
|
|
235
368
|
await afterPromptFlush();
|
|
@@ -242,6 +375,10 @@ async function stepExecute(skillIds, toolIds, installedTools, isUninstall, faile
|
|
|
242
375
|
const retryableFailedKeys = new Set();
|
|
243
376
|
/** 不可重试的失败(不支持、未注册等) */
|
|
244
377
|
const permanentFailedKeys = new Set();
|
|
378
|
+
/** 本轮执行结果,用于最终表格展示 */
|
|
379
|
+
const resultRows = [];
|
|
380
|
+
const total = tids.length * sids.length;
|
|
381
|
+
let current = 0;
|
|
245
382
|
|
|
246
383
|
for (const toolId of tids) {
|
|
247
384
|
const tool = TOOLS.find(t => t.id === toolId);
|
|
@@ -251,6 +388,7 @@ async function stepExecute(skillIds, toolIds, installedTools, isUninstall, faile
|
|
|
251
388
|
}
|
|
252
389
|
|
|
253
390
|
for (const skillId of sids) {
|
|
391
|
+
current += 1;
|
|
254
392
|
const skill = SKILLS.find(s => s.id === skillId);
|
|
255
393
|
if (!skill) {
|
|
256
394
|
console.log(chalk.gray(TERM_GUTTER + "- Skill " + skillId + " 未识别,跳过"));
|
|
@@ -258,12 +396,32 @@ async function stepExecute(skillIds, toolIds, installedTools, isUninstall, faile
|
|
|
258
396
|
}
|
|
259
397
|
|
|
260
398
|
const key = `${toolId}::${skillId}`;
|
|
399
|
+
if (skippedKeys.has(key)) {
|
|
400
|
+
const target = skill.installTargets?.find(tgt => tgt.toolId === toolId);
|
|
401
|
+
const reason = target?.conversion ? conversionDescription(target.conversion) : "用户跳过";
|
|
402
|
+
resultRows.push({
|
|
403
|
+
key,
|
|
404
|
+
toolName: tool.name,
|
|
405
|
+
skillName: skill.name,
|
|
406
|
+
status: chalk.gray("已跳过"),
|
|
407
|
+
mode: target?.conversion ? `跳过转换:${reason}` : "用户跳过",
|
|
408
|
+
});
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
261
411
|
// 如果是重试模式,只执行之前失败的组合
|
|
262
412
|
if (failedKeys && !failedKeys.has(key)) continue;
|
|
263
413
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
414
|
+
console.log(chalk.gray(TERM_GUTTER + `正在${isUninstall ? "卸载" : "安装"} ${current}/${total}:${skill.name} → ${tool.name}`));
|
|
415
|
+
|
|
416
|
+
const target = skill.installTargets?.find(tgt => tgt.toolId === toolId);
|
|
417
|
+
if (!target) {
|
|
418
|
+
resultRows.push({
|
|
419
|
+
key,
|
|
420
|
+
toolName: tool.name,
|
|
421
|
+
skillName: skill.name,
|
|
422
|
+
status: chalk.yellow("不支持"),
|
|
423
|
+
mode: "不适用",
|
|
424
|
+
});
|
|
267
425
|
allSuccess = false;
|
|
268
426
|
permanentFailedKeys.add(key);
|
|
269
427
|
continue;
|
|
@@ -272,9 +430,21 @@ async function stepExecute(skillIds, toolIds, installedTools, isUninstall, faile
|
|
|
272
430
|
if (isUninstall) {
|
|
273
431
|
const result = uninstallSkillFromTool(skill, tool);
|
|
274
432
|
if (result.success) {
|
|
275
|
-
|
|
433
|
+
resultRows.push({
|
|
434
|
+
key,
|
|
435
|
+
toolName: tool.name,
|
|
436
|
+
skillName: skill.name,
|
|
437
|
+
status: chalk.green("已卸载"),
|
|
438
|
+
mode: installModeDescription(target),
|
|
439
|
+
});
|
|
276
440
|
} else {
|
|
277
|
-
|
|
441
|
+
resultRows.push({
|
|
442
|
+
key,
|
|
443
|
+
toolName: tool.name,
|
|
444
|
+
skillName: skill.name,
|
|
445
|
+
status: chalk.yellow("未卸载"),
|
|
446
|
+
mode: result.message,
|
|
447
|
+
});
|
|
278
448
|
allSuccess = false;
|
|
279
449
|
// "未安装" 不可重试,"非本工具安装" 也不可重试
|
|
280
450
|
permanentFailedKeys.add(key);
|
|
@@ -282,9 +452,21 @@ async function stepExecute(skillIds, toolIds, installedTools, isUninstall, faile
|
|
|
282
452
|
} else {
|
|
283
453
|
const result = installSkillToTool(skill, tool);
|
|
284
454
|
if (result.success) {
|
|
285
|
-
|
|
455
|
+
resultRows.push({
|
|
456
|
+
key,
|
|
457
|
+
toolName: tool.name,
|
|
458
|
+
skillName: skill.name,
|
|
459
|
+
status: chalk.green("已安装"),
|
|
460
|
+
mode: installModeDescription(target),
|
|
461
|
+
});
|
|
286
462
|
} else {
|
|
287
|
-
|
|
463
|
+
resultRows.push({
|
|
464
|
+
key,
|
|
465
|
+
toolName: tool.name,
|
|
466
|
+
skillName: skill.name,
|
|
467
|
+
status: chalk.red("失败"),
|
|
468
|
+
mode: result.message,
|
|
469
|
+
});
|
|
288
470
|
allSuccess = false;
|
|
289
471
|
// 安装失败可能是临时 I/O 问题,可重试
|
|
290
472
|
retryableFailedKeys.add(key);
|
|
@@ -303,7 +485,7 @@ async function stepExecute(skillIds, toolIds, installedTools, isUninstall, faile
|
|
|
303
485
|
console.log(chalk.yellow(TERM_GUTTER + `⚠ 部分操作失败(${parts.join(",")}),请检查错误信息。\n`));
|
|
304
486
|
}
|
|
305
487
|
|
|
306
|
-
return { allSuccess, failedKeys: retryableFailedKeys, permanentFailedKeys };
|
|
488
|
+
return { allSuccess, failedKeys: retryableFailedKeys, permanentFailedKeys, resultRows };
|
|
307
489
|
}
|
|
308
490
|
|
|
309
491
|
// ── Unified flow (install / uninstall) ──
|
|
@@ -332,6 +514,7 @@ async function runFlow(isUninstall) {
|
|
|
332
514
|
let step = 1;
|
|
333
515
|
let selectedSkillIds = null;
|
|
334
516
|
let selectedToolIds = null;
|
|
517
|
+
let skippedConversionKeys = new Set();
|
|
335
518
|
|
|
336
519
|
while (true) {
|
|
337
520
|
if (step === 1) {
|
|
@@ -345,15 +528,23 @@ async function runFlow(isUninstall) {
|
|
|
345
528
|
if (result === "back") { step = 1; continue; }
|
|
346
529
|
if (result === "exit") return "exit";
|
|
347
530
|
selectedToolIds = result;
|
|
531
|
+
skippedConversionKeys = new Set();
|
|
348
532
|
step = 3;
|
|
349
533
|
} else if (step === 3) {
|
|
350
534
|
const result = await stepPreviewConfirm(isUninstall);
|
|
351
535
|
if (result === "back") { step = 2; continue; }
|
|
352
536
|
if (result === "exit") return "exit";
|
|
537
|
+
if (!isUninstall && SHOW_CONVERSION_CONFIRM_PROMPT) {
|
|
538
|
+
const fallbackResult = await stepConfirmConversionFallbacks(selectedSkillIds, selectedToolIds);
|
|
539
|
+
if (fallbackResult.action === "back") { step = 2; continue; }
|
|
540
|
+
if (fallbackResult.action === "exit") return "exit";
|
|
541
|
+
skippedConversionKeys = fallbackResult.skippedKeys;
|
|
542
|
+
}
|
|
353
543
|
step = 4;
|
|
354
544
|
} else if (step === 4) {
|
|
355
|
-
const { allSuccess, failedKeys, permanentFailedKeys } = await stepExecute(selectedSkillIds, selectedToolIds, installedTools, isUninstall);
|
|
545
|
+
const { allSuccess, failedKeys, permanentFailedKeys, resultRows } = await stepExecute(selectedSkillIds, selectedToolIds, installedTools, isUninstall, null, skippedConversionKeys);
|
|
356
546
|
if (allSuccess) {
|
|
547
|
+
printResultTable(isUninstall ? "卸载结果" : "安装结果", resultRows);
|
|
357
548
|
await input(
|
|
358
549
|
{
|
|
359
550
|
message: "按任意键退出...",
|
|
@@ -369,16 +560,19 @@ async function runFlow(isUninstall) {
|
|
|
369
560
|
let retrySuccess = false;
|
|
370
561
|
let retryFailedKeys = failedKeys;
|
|
371
562
|
let accumulatedPermanent = new Set(permanentFailedKeys);
|
|
563
|
+
let accumulatedResultRows = [...resultRows];
|
|
372
564
|
while (attempt < 3) {
|
|
373
565
|
console.log(chalk.yellow(TERM_GUTTER + `第 ${attempt} 次重试(${retryFailedKeys.size} 项)...\n`));
|
|
374
|
-
const retryResult = await stepExecute(selectedSkillIds, selectedToolIds, installedTools, isUninstall, retryFailedKeys);
|
|
566
|
+
const retryResult = await stepExecute(selectedSkillIds, selectedToolIds, installedTools, isUninstall, retryFailedKeys, skippedConversionKeys);
|
|
375
567
|
retrySuccess = retryResult.allSuccess;
|
|
376
568
|
retryFailedKeys = retryResult.failedKeys;
|
|
569
|
+
accumulatedResultRows = mergeResultRows(accumulatedResultRows, retryResult.resultRows);
|
|
377
570
|
for (const k of retryResult.permanentFailedKeys) accumulatedPermanent.add(k);
|
|
378
571
|
if (retrySuccess) break;
|
|
379
572
|
attempt++;
|
|
380
573
|
}
|
|
381
574
|
if (retrySuccess && accumulatedPermanent.size === 0) {
|
|
575
|
+
printResultTable("安装结果", accumulatedResultRows);
|
|
382
576
|
await input(
|
|
383
577
|
{
|
|
384
578
|
message: "按任意键退出...",
|
|
@@ -389,6 +583,7 @@ async function runFlow(isUninstall) {
|
|
|
389
583
|
return "exit";
|
|
390
584
|
} else if (retrySuccess && accumulatedPermanent.size > 0) {
|
|
391
585
|
// 重试成功但仍有不可重试的失败项(如"不支持")
|
|
586
|
+
printResultTable("安装结果", accumulatedResultRows);
|
|
392
587
|
console.log(chalk.yellow(TERM_GUTTER + `⚠ ${accumulatedPermanent.size} 项不可重试的操作已跳过(不支持或非本工具安装)\n`));
|
|
393
588
|
await input(
|
|
394
589
|
{
|
|
@@ -401,6 +596,7 @@ async function runFlow(isUninstall) {
|
|
|
401
596
|
}
|
|
402
597
|
} else if (permanentFailedKeys.size > 0 && failedKeys.size === 0) {
|
|
403
598
|
// 全部是 permanent 失败,无重试价值
|
|
599
|
+
printResultTable(isUninstall ? "卸载结果" : "安装结果", resultRows);
|
|
404
600
|
console.log(chalk.yellow(TERM_GUTTER + `⚠ ${permanentFailedKeys.size} 项操作不可执行(不支持或非本工具安装),已跳过\n`));
|
|
405
601
|
await input(
|
|
406
602
|
{
|
|
@@ -411,6 +607,7 @@ async function runFlow(isUninstall) {
|
|
|
411
607
|
).catch(() => {});
|
|
412
608
|
return "back";
|
|
413
609
|
}
|
|
610
|
+
printResultTable(isUninstall ? "卸载结果" : "安装结果", resultRows);
|
|
414
611
|
console.log(chalk.red(TERM_GUTTER + "❌ 操作未能全部成功,请手动检查。\n"));
|
|
415
612
|
await input(
|
|
416
613
|
{
|