@minhluudev/ai-tools 1.0.22 → 1.0.26
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 +5 -31
- package/dist/src/bin/ai-tools.js +1 -2
- package/dist/src/cli.js +1 -221
- package/dist/src/lib/agent-selection.js +60 -0
- package/dist/src/lib/catalog.js +4 -1
- package/dist/src/lib/config.js +0 -2
- package/dist/src/lib/install.js +45 -79
- package/dist/src/lib/selection-catalog.js +6 -2
- package/dist/src/lib/tui-entry-menu.js +0 -24
- package/dist/src/lib/tui-skills.js +4 -2
- package/dist/src/lib/tui-wizard.js +14 -24
- package/package.json +7 -7
- package/selection-catalog.json +26 -68
- package/dist/src/lib/ai-libs.js +0 -417
- package/dist/src/lib/mcp.js +0 -665
- package/dist/src/lib/plugins.js +0 -155
- package/dist/src/lib/project-docs-catalog.js +0 -45
- package/dist/src/lib/tui-ai-libs.js +0 -539
- package/dist/src/lib/tui-mcp.js +0 -514
- package/dist/src/lib/tui-plugins.js +0 -408
- package/dist/src/lib/tui-project-docs.js +0 -303
- package/project-docs-catalog.json +0 -19
|
@@ -1,408 +0,0 @@
|
|
|
1
|
-
import { buildPluginInstallPlan } from "./plugins.js";
|
|
2
|
-
import { canRun, createTabbedLayout, DEBOUNCE_MOVE_MS, DEBOUNCE_SELECT_MS, renderBannerHeader, renderKeycaps, renderListContent, renderListRow, renderStepSummary, renderTabBar, selectionArray } from "./tui-utils.js";
|
|
3
|
-
const TAB_ORDER = ["plugins", "agents", "mode", "review"];
|
|
4
|
-
function buildInitialState() {
|
|
5
|
-
return {
|
|
6
|
-
activeTab: "plugins",
|
|
7
|
-
selectedPlugins: new Set(),
|
|
8
|
-
selectedAgents: new Set(),
|
|
9
|
-
selectedMode: "install",
|
|
10
|
-
listCursor: {
|
|
11
|
-
plugins: 0,
|
|
12
|
-
agents: 0,
|
|
13
|
-
mode: 0,
|
|
14
|
-
review: 0
|
|
15
|
-
},
|
|
16
|
-
reviewAction: "confirm",
|
|
17
|
-
notice: ""
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
function currentTabItems(state) {
|
|
21
|
-
if (state.activeTab === "plugins") {
|
|
22
|
-
return [{
|
|
23
|
-
id: "lumin",
|
|
24
|
-
label: "◈ Lumin",
|
|
25
|
-
description: "Cross-harness skill plugin for Codex and Claude with explicit commands and auto-apply skill surfaces.",
|
|
26
|
-
kind: "plugin"
|
|
27
|
-
}];
|
|
28
|
-
}
|
|
29
|
-
if (state.activeTab === "agents") {
|
|
30
|
-
return [
|
|
31
|
-
{
|
|
32
|
-
id: "codex",
|
|
33
|
-
label: "◇ Codex",
|
|
34
|
-
description: "Install the Codex-side plugin and global auto skill surface in the user home directory.",
|
|
35
|
-
kind: "agents"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
id: "claude",
|
|
39
|
-
label: "◇ Claude",
|
|
40
|
-
description: "Install Claude slash commands and namespaced host skills in the user home directory.",
|
|
41
|
-
kind: "agents"
|
|
42
|
-
}
|
|
43
|
-
];
|
|
44
|
-
}
|
|
45
|
-
if (state.activeTab === "mode") {
|
|
46
|
-
return [
|
|
47
|
-
{
|
|
48
|
-
id: "install",
|
|
49
|
-
label: "▶ Install",
|
|
50
|
-
description: "Install the selected plugins.",
|
|
51
|
-
kind: "mode"
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
id: "uninstall",
|
|
55
|
-
label: "← Uninstall",
|
|
56
|
-
description: "Remove the selected plugins safely.",
|
|
57
|
-
kind: "mode"
|
|
58
|
-
}
|
|
59
|
-
];
|
|
60
|
-
}
|
|
61
|
-
return [
|
|
62
|
-
{
|
|
63
|
-
id: "confirm",
|
|
64
|
-
label: `✓ Confirm ${state.selectedMode}`,
|
|
65
|
-
description: "Run the planned plugin actions.",
|
|
66
|
-
kind: "review"
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
id: "back",
|
|
70
|
-
label: "← Back to main menu",
|
|
71
|
-
description: "Leave this installer and return to the main menu.",
|
|
72
|
-
kind: "review"
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
id: "cancel",
|
|
76
|
-
label: "✕ Cancel",
|
|
77
|
-
description: "Exit without changing plugins.",
|
|
78
|
-
kind: "review"
|
|
79
|
-
}
|
|
80
|
-
];
|
|
81
|
-
}
|
|
82
|
-
function isItemSelected(item, state) {
|
|
83
|
-
if (item.kind === "plugin") {
|
|
84
|
-
return state.selectedPlugins.has(item.id);
|
|
85
|
-
}
|
|
86
|
-
if (item.kind === "agents") {
|
|
87
|
-
return state.selectedAgents.has(item.id);
|
|
88
|
-
}
|
|
89
|
-
if (item.kind === "mode") {
|
|
90
|
-
return state.selectedMode === item.id;
|
|
91
|
-
}
|
|
92
|
-
return state.reviewAction === item.id;
|
|
93
|
-
}
|
|
94
|
-
function toggleItem(item, state) {
|
|
95
|
-
if (item.kind === "plugin") {
|
|
96
|
-
if (state.selectedPlugins.has(item.id)) {
|
|
97
|
-
state.selectedPlugins.delete(item.id);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
state.selectedPlugins.add(item.id);
|
|
101
|
-
}
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
if (item.kind === "agents") {
|
|
105
|
-
const agent = item.id;
|
|
106
|
-
if (state.selectedAgents.has(agent)) {
|
|
107
|
-
state.selectedAgents.delete(agent);
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
state.selectedAgents.add(agent);
|
|
111
|
-
}
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
if (item.kind === "mode") {
|
|
115
|
-
state.selectedMode = item.id;
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
state.reviewAction = item.id;
|
|
119
|
-
}
|
|
120
|
-
function renderTabs(state) {
|
|
121
|
-
const counts = {
|
|
122
|
-
plugins: state.selectedPlugins.size,
|
|
123
|
-
agents: state.selectedAgents.size,
|
|
124
|
-
mode: 1,
|
|
125
|
-
review: state.reviewAction === "confirm" ? 1 : 0
|
|
126
|
-
};
|
|
127
|
-
return renderTabBar(TAB_ORDER.map((tab, index) => ({
|
|
128
|
-
label: `${index + 1}. ${tab.charAt(0).toUpperCase() + tab.slice(1)}`,
|
|
129
|
-
meta: tab === "review" ? "ready" : `${counts[tab]} selected`,
|
|
130
|
-
active: state.activeTab === tab
|
|
131
|
-
})));
|
|
132
|
-
}
|
|
133
|
-
function formatListItem(item, state, isCursorRow, index) {
|
|
134
|
-
if (item.kind === "review") {
|
|
135
|
-
return renderListRow({
|
|
136
|
-
active: isCursorRow,
|
|
137
|
-
selected: state.reviewAction === item.id,
|
|
138
|
-
label: item.label,
|
|
139
|
-
index
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
return renderListRow({
|
|
143
|
-
active: isCursorRow,
|
|
144
|
-
selected: isItemSelected(item, state),
|
|
145
|
-
label: item.label,
|
|
146
|
-
index
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
function renderReviewSummary(state) {
|
|
150
|
-
const selectedPlugins = selectionArray(state.selectedPlugins);
|
|
151
|
-
const selectedAgents = selectionArray(state.selectedAgents);
|
|
152
|
-
const sep = `{cyan-fg}${"─".repeat(50)}{/cyan-fg}`;
|
|
153
|
-
const none = "{gray-fg}none{/gray-fg}";
|
|
154
|
-
const lines = [
|
|
155
|
-
`{bold}{white-fg}◈ Summary{/white-fg}{/bold}`,
|
|
156
|
-
sep,
|
|
157
|
-
`{cyan-fg}◆ Plugins{/cyan-fg} ${selectedPlugins.length ? selectedPlugins.join(", ") : none}`,
|
|
158
|
-
`{cyan-fg}◆ Agents{/cyan-fg} ${selectedAgents.length ? selectedAgents.join(", ") : none}`,
|
|
159
|
-
`{cyan-fg}◆ Install{/cyan-fg} global`,
|
|
160
|
-
`{cyan-fg}◆ Mode{/cyan-fg} ${state.selectedMode}`
|
|
161
|
-
];
|
|
162
|
-
if (selectedPlugins.length > 0 && selectedAgents.length > 0) {
|
|
163
|
-
try {
|
|
164
|
-
const plan = buildPluginInstallPlan({
|
|
165
|
-
mode: state.selectedMode,
|
|
166
|
-
agents: selectedAgents,
|
|
167
|
-
plugins: selectedPlugins,
|
|
168
|
-
sourceBranch: "plugins"
|
|
169
|
-
});
|
|
170
|
-
lines.push("", sep, `{bold}{white-fg}⊕ Planned steps{/white-fg}{/bold}`);
|
|
171
|
-
for (const step of plan.steps) {
|
|
172
|
-
lines.push(` {gray-fg}▶{/gray-fg} ${step.title}`);
|
|
173
|
-
}
|
|
174
|
-
if (plan.notes.length > 0) {
|
|
175
|
-
lines.push("", `{bold}{white-fg}◎ Notes{/white-fg}{/bold}`);
|
|
176
|
-
for (const note of plan.notes) {
|
|
177
|
-
lines.push(` {gray-fg}·{/gray-fg} ${note}`);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
catch (error) {
|
|
182
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
183
|
-
lines.push("", `{yellow-fg}${message}{/yellow-fg}`);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
if (state.notice) {
|
|
187
|
-
lines.push("", `{yellow-fg}${state.notice}{/yellow-fg}`);
|
|
188
|
-
}
|
|
189
|
-
return lines.join("\n");
|
|
190
|
-
}
|
|
191
|
-
function renderDetailBody(state) {
|
|
192
|
-
if (state.activeTab === "review") {
|
|
193
|
-
return renderReviewSummary(state);
|
|
194
|
-
}
|
|
195
|
-
const items = currentTabItems(state);
|
|
196
|
-
const current = items[state.listCursor[state.activeTab]];
|
|
197
|
-
const lines = [];
|
|
198
|
-
if (state.notice) {
|
|
199
|
-
lines.push(`{yellow-fg}${state.notice}{/yellow-fg}`, "");
|
|
200
|
-
}
|
|
201
|
-
if (current) {
|
|
202
|
-
const selectedCount = items.filter((item) => isItemSelected(item, state)).length;
|
|
203
|
-
lines.push(`{cyan-fg}◆ ${selectedCount} of ${items.length} selected{/cyan-fg}`, `{gray-fg}${"─".repeat(40)}{/gray-fg}`, `{bold}{white-fg}${current.label}{/white-fg}{/bold}`, `{gray-fg}${current.description}{/gray-fg}`);
|
|
204
|
-
}
|
|
205
|
-
return lines.join("\n");
|
|
206
|
-
}
|
|
207
|
-
function renderFooter(state) {
|
|
208
|
-
if (state.activeTab === "review") {
|
|
209
|
-
return renderKeycaps([
|
|
210
|
-
{ key: "LEFT/RIGHT", label: "switch tab" },
|
|
211
|
-
{ key: "UP/DOWN", label: "move" },
|
|
212
|
-
{ key: "ENTER", label: "confirm action" },
|
|
213
|
-
{ key: "Q", label: "quit" }
|
|
214
|
-
]);
|
|
215
|
-
}
|
|
216
|
-
return renderKeycaps([
|
|
217
|
-
{ key: "LEFT/RIGHT", label: "switch tab" },
|
|
218
|
-
{ key: "UP/DOWN", label: "move" },
|
|
219
|
-
{ key: "SPACE", label: "toggle" },
|
|
220
|
-
{ key: "A", label: "toggle all" },
|
|
221
|
-
{ key: "Q", label: "quit" }
|
|
222
|
-
]);
|
|
223
|
-
}
|
|
224
|
-
function setNotice(state, message) {
|
|
225
|
-
state.notice = message;
|
|
226
|
-
}
|
|
227
|
-
function moveTab(state, delta) {
|
|
228
|
-
const index = TAB_ORDER.indexOf(state.activeTab);
|
|
229
|
-
const nextIndex = (index + delta + TAB_ORDER.length) % TAB_ORDER.length;
|
|
230
|
-
state.activeTab = TAB_ORDER[nextIndex];
|
|
231
|
-
state.notice = "";
|
|
232
|
-
}
|
|
233
|
-
function moveCursor(state, delta) {
|
|
234
|
-
const items = currentTabItems(state);
|
|
235
|
-
if (items.length === 0) {
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
const current = state.listCursor[state.activeTab];
|
|
239
|
-
const next = (current + delta + items.length) % items.length;
|
|
240
|
-
state.listCursor[state.activeTab] = next;
|
|
241
|
-
if (state.activeTab === "review") {
|
|
242
|
-
state.reviewAction = items[next]?.id;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
function toggleCurrentItem(state) {
|
|
246
|
-
if (state.activeTab === "review") {
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
const items = currentTabItems(state);
|
|
250
|
-
const current = items[state.listCursor[state.activeTab]];
|
|
251
|
-
if (!current) {
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
toggleItem(current, state);
|
|
255
|
-
}
|
|
256
|
-
function toggleAllItems(state) {
|
|
257
|
-
if (state.activeTab !== "plugins" && state.activeTab !== "agents") {
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
const items = currentTabItems(state);
|
|
261
|
-
if (state.activeTab === "plugins") {
|
|
262
|
-
const allSelected = items.every((item) => state.selectedPlugins.has(item.id));
|
|
263
|
-
state.selectedPlugins.clear();
|
|
264
|
-
if (!allSelected) {
|
|
265
|
-
for (const item of items) {
|
|
266
|
-
state.selectedPlugins.add(item.id);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
const allSelected = items.every((item) => state.selectedAgents.has(item.id));
|
|
272
|
-
state.selectedAgents.clear();
|
|
273
|
-
if (!allSelected) {
|
|
274
|
-
for (const item of items) {
|
|
275
|
-
state.selectedAgents.add(item.id);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
function validateReview(state) {
|
|
280
|
-
if (state.reviewAction !== "confirm") {
|
|
281
|
-
return state.reviewAction;
|
|
282
|
-
}
|
|
283
|
-
if (state.selectedPlugins.size === 0) {
|
|
284
|
-
setNotice(state, "Select at least one plugin before continuing.");
|
|
285
|
-
return null;
|
|
286
|
-
}
|
|
287
|
-
if (state.selectedAgents.size === 0) {
|
|
288
|
-
setNotice(state, "Select at least one agent before continuing.");
|
|
289
|
-
return null;
|
|
290
|
-
}
|
|
291
|
-
return "confirm";
|
|
292
|
-
}
|
|
293
|
-
export async function runPluginWizard() {
|
|
294
|
-
const state = buildInitialState();
|
|
295
|
-
const { screen, headerBox, tabsBox, titleBox, listBox, detailBox, footerBox } = createTabbedLayout();
|
|
296
|
-
let lastMoveAt = 0;
|
|
297
|
-
let lastSelectAt = 0;
|
|
298
|
-
return await new Promise((resolve) => {
|
|
299
|
-
function cleanup() {
|
|
300
|
-
screen.destroy();
|
|
301
|
-
}
|
|
302
|
-
function render() {
|
|
303
|
-
const items = currentTabItems(state);
|
|
304
|
-
const cursor = state.listCursor[state.activeTab];
|
|
305
|
-
const detail = renderDetailBody(state);
|
|
306
|
-
const renderedItems = items.map((item, index) => formatListItem(item, state, index === cursor, index));
|
|
307
|
-
headerBox.setContent(renderBannerHeader("Install plugin", "Install or remove shared plugins such as Lumin.", [
|
|
308
|
-
{ label: `${state.selectedPlugins.size} plugins`, tone: "accent" },
|
|
309
|
-
{ label: `${state.selectedAgents.size} agents`, tone: "muted" },
|
|
310
|
-
{ label: `${state.selectedMode}`, tone: "success" }
|
|
311
|
-
]));
|
|
312
|
-
tabsBox.setContent(renderTabs(state));
|
|
313
|
-
titleBox.setContent(renderStepSummary({
|
|
314
|
-
step: `${TAB_ORDER.indexOf(state.activeTab) + 1}/${TAB_ORDER.length}`,
|
|
315
|
-
title: state.activeTab === "review" ? "Review" : "Details",
|
|
316
|
-
description: "Choose plugin options and confirm the execution plan."
|
|
317
|
-
}));
|
|
318
|
-
renderListContent(listBox, renderedItems, cursor);
|
|
319
|
-
detailBox.setContent(detail);
|
|
320
|
-
footerBox.setContent(renderFooter(state));
|
|
321
|
-
screen.render();
|
|
322
|
-
}
|
|
323
|
-
screen.key(["left"], () => {
|
|
324
|
-
if (!canRun(lastMoveAt, DEBOUNCE_MOVE_MS)) {
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
327
|
-
lastMoveAt = Date.now();
|
|
328
|
-
moveTab(state, -1);
|
|
329
|
-
render();
|
|
330
|
-
});
|
|
331
|
-
screen.key(["right"], () => {
|
|
332
|
-
if (!canRun(lastMoveAt, DEBOUNCE_MOVE_MS)) {
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
-
lastMoveAt = Date.now();
|
|
336
|
-
moveTab(state, 1);
|
|
337
|
-
render();
|
|
338
|
-
});
|
|
339
|
-
screen.key(["up"], () => {
|
|
340
|
-
if (!canRun(lastMoveAt, DEBOUNCE_MOVE_MS)) {
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
lastMoveAt = Date.now();
|
|
344
|
-
moveCursor(state, -1);
|
|
345
|
-
render();
|
|
346
|
-
});
|
|
347
|
-
screen.key(["down"], () => {
|
|
348
|
-
if (!canRun(lastMoveAt, DEBOUNCE_MOVE_MS)) {
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
lastMoveAt = Date.now();
|
|
352
|
-
moveCursor(state, 1);
|
|
353
|
-
render();
|
|
354
|
-
});
|
|
355
|
-
screen.key(["space"], () => {
|
|
356
|
-
if (!canRun(lastSelectAt, DEBOUNCE_SELECT_MS)) {
|
|
357
|
-
return;
|
|
358
|
-
}
|
|
359
|
-
lastSelectAt = Date.now();
|
|
360
|
-
toggleCurrentItem(state);
|
|
361
|
-
render();
|
|
362
|
-
});
|
|
363
|
-
screen.key(["a"], () => {
|
|
364
|
-
if (!canRun(lastSelectAt, DEBOUNCE_SELECT_MS)) {
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
lastSelectAt = Date.now();
|
|
368
|
-
toggleAllItems(state);
|
|
369
|
-
render();
|
|
370
|
-
});
|
|
371
|
-
screen.key(["enter"], () => {
|
|
372
|
-
if (!canRun(lastSelectAt, DEBOUNCE_SELECT_MS)) {
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
lastSelectAt = Date.now();
|
|
376
|
-
if (state.activeTab !== "review") {
|
|
377
|
-
moveTab(state, 1);
|
|
378
|
-
render();
|
|
379
|
-
return;
|
|
380
|
-
}
|
|
381
|
-
const action = validateReview(state);
|
|
382
|
-
if (!action) {
|
|
383
|
-
render();
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
cleanup();
|
|
387
|
-
if (action === "back") {
|
|
388
|
-
resolve({ backToMenu: true });
|
|
389
|
-
return;
|
|
390
|
-
}
|
|
391
|
-
if (action === "cancel") {
|
|
392
|
-
process.exitCode = 1;
|
|
393
|
-
resolve({ backToMenu: true });
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
resolve({
|
|
397
|
-
plugins: selectionArray(state.selectedPlugins),
|
|
398
|
-
agents: selectionArray(state.selectedAgents),
|
|
399
|
-
mode: state.selectedMode
|
|
400
|
-
});
|
|
401
|
-
});
|
|
402
|
-
screen.key(["q", "escape", "C-c"], () => {
|
|
403
|
-
cleanup();
|
|
404
|
-
resolve({ backToMenu: true });
|
|
405
|
-
});
|
|
406
|
-
render();
|
|
407
|
-
});
|
|
408
|
-
}
|
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
import { canRun, createTabbedLayout, DEBOUNCE_MOVE_MS, DEBOUNCE_SELECT_MS, renderBannerHeader, renderKeycaps, renderListRow, renderListContent, renderStepSummary, renderTabBar } from "./tui-utils.js";
|
|
2
|
-
const TAB_ORDER = ["skills", "review"];
|
|
3
|
-
function buildInitialState() {
|
|
4
|
-
return {
|
|
5
|
-
activeTab: "skills",
|
|
6
|
-
selectedSkills: new Set(),
|
|
7
|
-
listCursor: {
|
|
8
|
-
skills: 0,
|
|
9
|
-
review: 0
|
|
10
|
-
},
|
|
11
|
-
reviewAction: "confirm",
|
|
12
|
-
notice: ""
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
function currentTabItems(state, catalog) {
|
|
16
|
-
if (state.activeTab === "skills") {
|
|
17
|
-
return catalog.skills.map((skill) => ({
|
|
18
|
-
id: skill.id,
|
|
19
|
-
label: `◈ ${skill.label}`,
|
|
20
|
-
description: skill.description,
|
|
21
|
-
kind: "skills"
|
|
22
|
-
}));
|
|
23
|
-
}
|
|
24
|
-
return [
|
|
25
|
-
{
|
|
26
|
-
id: "confirm",
|
|
27
|
-
label: "✓ Confirm install",
|
|
28
|
-
description: "Continue with the selected skills.",
|
|
29
|
-
kind: "review"
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
id: "back",
|
|
33
|
-
label: "← Back to main menu",
|
|
34
|
-
description: "Leave this installer and return to the main menu.",
|
|
35
|
-
kind: "review"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
id: "cancel",
|
|
39
|
-
label: "✕ Cancel",
|
|
40
|
-
description: "Exit without installing anything.",
|
|
41
|
-
kind: "review"
|
|
42
|
-
}
|
|
43
|
-
];
|
|
44
|
-
}
|
|
45
|
-
function renderTabs(state) {
|
|
46
|
-
return renderTabBar(TAB_ORDER.map((tab, index) => ({
|
|
47
|
-
label: `${index + 1}. ${tab.charAt(0).toUpperCase() + tab.slice(1)}`,
|
|
48
|
-
meta: tab === "skills" ? `${state.selectedSkills.size} selected` : "ready",
|
|
49
|
-
active: state.activeTab === tab
|
|
50
|
-
})));
|
|
51
|
-
}
|
|
52
|
-
function isItemSelected(item, state) {
|
|
53
|
-
if (item.kind === "skills") {
|
|
54
|
-
return state.selectedSkills.has(item.id);
|
|
55
|
-
}
|
|
56
|
-
return state.reviewAction === item.id;
|
|
57
|
-
}
|
|
58
|
-
function toggleItem(item, state) {
|
|
59
|
-
if (item.kind === "skills") {
|
|
60
|
-
if (state.selectedSkills.has(item.id)) {
|
|
61
|
-
state.selectedSkills.delete(item.id);
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
state.selectedSkills.add(item.id);
|
|
65
|
-
}
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
state.reviewAction = item.id;
|
|
69
|
-
}
|
|
70
|
-
function formatListItem(item, state, isCursorRow) {
|
|
71
|
-
if (item.kind === "review") {
|
|
72
|
-
return renderListRow({
|
|
73
|
-
active: isCursorRow,
|
|
74
|
-
selected: state.reviewAction === item.id,
|
|
75
|
-
label: item.label
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
return renderListRow({
|
|
79
|
-
active: isCursorRow,
|
|
80
|
-
selected: isItemSelected(item, state),
|
|
81
|
-
label: item.label
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
function renderReviewSummary(state, catalog) {
|
|
85
|
-
const selectedSkills = catalog.skills
|
|
86
|
-
.filter((skill) => state.selectedSkills.has(skill.id))
|
|
87
|
-
.map((skill) => skill.label);
|
|
88
|
-
const sep = `{cyan-fg}${"─".repeat(50)}{/cyan-fg}`;
|
|
89
|
-
const none = "{gray-fg}none{/gray-fg}";
|
|
90
|
-
const lines = [
|
|
91
|
-
`{bold}{white-fg}◈ Summary{/white-fg}{/bold}`,
|
|
92
|
-
sep,
|
|
93
|
-
`{cyan-fg}◆ Skills{/cyan-fg} ${selectedSkills.length ? selectedSkills.join(", ") : none}`
|
|
94
|
-
];
|
|
95
|
-
if (state.notice) {
|
|
96
|
-
lines.push("", `{yellow-fg}${state.notice}{/yellow-fg}`);
|
|
97
|
-
}
|
|
98
|
-
return lines.join("\n");
|
|
99
|
-
}
|
|
100
|
-
function renderDetailBody(state, catalog) {
|
|
101
|
-
if (state.activeTab === "review") {
|
|
102
|
-
return renderReviewSummary(state, catalog);
|
|
103
|
-
}
|
|
104
|
-
const items = currentTabItems(state, catalog);
|
|
105
|
-
const current = items[state.listCursor[state.activeTab]];
|
|
106
|
-
const lines = [];
|
|
107
|
-
if (state.notice) {
|
|
108
|
-
lines.push(`{yellow-fg}${state.notice}{/yellow-fg}`, "");
|
|
109
|
-
}
|
|
110
|
-
if (current) {
|
|
111
|
-
lines.push(`{cyan-fg}◆ ${state.selectedSkills.size} of ${items.length} selected{/cyan-fg}`, `{gray-fg}${"─".repeat(40)}{/gray-fg}`, `{bold}{white-fg}${current.label}{/white-fg}{/bold}`, `{gray-fg}${current.description}{/gray-fg}`);
|
|
112
|
-
}
|
|
113
|
-
return lines.join("\n");
|
|
114
|
-
}
|
|
115
|
-
function renderFooter(state) {
|
|
116
|
-
if (state.activeTab === "review") {
|
|
117
|
-
return renderKeycaps([
|
|
118
|
-
{ key: "LEFT/RIGHT", label: "switch tab" },
|
|
119
|
-
{ key: "UP/DOWN", label: "move" },
|
|
120
|
-
{ key: "ENTER", label: "confirm action" },
|
|
121
|
-
{ key: "Q", label: "quit" }
|
|
122
|
-
]);
|
|
123
|
-
}
|
|
124
|
-
return renderKeycaps([
|
|
125
|
-
{ key: "LEFT/RIGHT", label: "switch tab" },
|
|
126
|
-
{ key: "UP/DOWN", label: "move" },
|
|
127
|
-
{ key: "SPACE", label: "toggle" },
|
|
128
|
-
{ key: "A", label: "toggle all" },
|
|
129
|
-
{ key: "Q", label: "quit" }
|
|
130
|
-
]);
|
|
131
|
-
}
|
|
132
|
-
function moveTab(state, delta) {
|
|
133
|
-
const index = TAB_ORDER.indexOf(state.activeTab);
|
|
134
|
-
const nextIndex = (index + delta + TAB_ORDER.length) % TAB_ORDER.length;
|
|
135
|
-
state.activeTab = TAB_ORDER[nextIndex];
|
|
136
|
-
state.notice = "";
|
|
137
|
-
}
|
|
138
|
-
function moveCursor(state, catalog, delta) {
|
|
139
|
-
const items = currentTabItems(state, catalog);
|
|
140
|
-
if (items.length === 0) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
const current = state.listCursor[state.activeTab];
|
|
144
|
-
const next = (current + delta + items.length) % items.length;
|
|
145
|
-
state.listCursor[state.activeTab] = next;
|
|
146
|
-
if (state.activeTab === "review") {
|
|
147
|
-
state.reviewAction = items[next]?.id;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
function validateBeforeConfirm(state) {
|
|
151
|
-
if (state.selectedSkills.size === 0) {
|
|
152
|
-
return "Select at least one skill before confirming.";
|
|
153
|
-
}
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
function syncListSelection(listBox, state, catalog) {
|
|
157
|
-
const items = currentTabItems(state, catalog);
|
|
158
|
-
const maxIndex = Math.max(items.length - 1, 0);
|
|
159
|
-
const cursor = Math.min(state.listCursor[state.activeTab], maxIndex);
|
|
160
|
-
state.listCursor[state.activeTab] = cursor;
|
|
161
|
-
const rendered = items.map((item, index) => formatListItem(item, state, index === cursor));
|
|
162
|
-
renderListContent(listBox, rendered, cursor);
|
|
163
|
-
}
|
|
164
|
-
export async function runProjectDocsWizard(catalog) {
|
|
165
|
-
return new Promise((resolve, reject) => {
|
|
166
|
-
const state = buildInitialState();
|
|
167
|
-
let lastTabSwitchAt = 0;
|
|
168
|
-
let lastMoveAt = 0;
|
|
169
|
-
let lastToggleAt = 0;
|
|
170
|
-
const { screen, headerBox, tabsBox, titleBox, listBox, detailBox, footerBox } = createTabbedLayout();
|
|
171
|
-
function cleanup() {
|
|
172
|
-
screen.destroy();
|
|
173
|
-
}
|
|
174
|
-
function render() {
|
|
175
|
-
const currentStep = TAB_ORDER.indexOf(state.activeTab) + 1;
|
|
176
|
-
const stepTitle = state.activeTab === "skills" ? "Select skills" : "Review selections";
|
|
177
|
-
const stepDescription = state.activeTab === "skills"
|
|
178
|
-
? "Choose the project docs packages to copy into this repository."
|
|
179
|
-
: "Double-check the selected docs before installation starts.";
|
|
180
|
-
const stepStatus = state.activeTab === "skills"
|
|
181
|
-
? `${state.selectedSkills.size} selected`
|
|
182
|
-
: state.notice || "Ready for confirmation";
|
|
183
|
-
headerBox.setContent(renderBannerHeader("Install project docs", "Choose skills first, then confirm from review.", [
|
|
184
|
-
{ label: `${state.selectedSkills.size} selected`, tone: "accent" },
|
|
185
|
-
{ label: "Current repository", tone: "muted" }
|
|
186
|
-
]));
|
|
187
|
-
tabsBox.setContent(renderTabs(state));
|
|
188
|
-
titleBox.setContent(renderStepSummary({
|
|
189
|
-
step: `STEP ${currentStep}/${TAB_ORDER.length}`,
|
|
190
|
-
title: stepTitle,
|
|
191
|
-
description: stepDescription,
|
|
192
|
-
status: stepStatus
|
|
193
|
-
}));
|
|
194
|
-
syncListSelection(listBox, state, catalog);
|
|
195
|
-
detailBox.setContent(renderDetailBody(state, catalog));
|
|
196
|
-
footerBox.setContent(renderFooter(state));
|
|
197
|
-
screen.render();
|
|
198
|
-
}
|
|
199
|
-
function finishBackToMenu() {
|
|
200
|
-
cleanup();
|
|
201
|
-
resolve({ backToMenu: true });
|
|
202
|
-
}
|
|
203
|
-
function finishSuccess() {
|
|
204
|
-
cleanup();
|
|
205
|
-
resolve({
|
|
206
|
-
selectedSkills: catalog.skills.filter((skill) => state.selectedSkills.has(skill.id))
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
function finishWithError(message) {
|
|
210
|
-
cleanup();
|
|
211
|
-
reject(new Error(message));
|
|
212
|
-
}
|
|
213
|
-
function handleToggleOrConfirm() {
|
|
214
|
-
if (!canRun(lastToggleAt, DEBOUNCE_SELECT_MS)) {
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
lastToggleAt = Date.now();
|
|
218
|
-
if (state.activeTab === "review") {
|
|
219
|
-
if (state.reviewAction === "back") {
|
|
220
|
-
finishBackToMenu();
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
if (state.reviewAction === "cancel") {
|
|
224
|
-
finishWithError("Installation cancelled.");
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
const validationMessage = validateBeforeConfirm(state);
|
|
228
|
-
if (validationMessage) {
|
|
229
|
-
state.notice = validationMessage;
|
|
230
|
-
render();
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
finishSuccess();
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
const items = currentTabItems(state, catalog);
|
|
237
|
-
const current = items[state.listCursor.skills];
|
|
238
|
-
if (current) {
|
|
239
|
-
toggleItem(current, state);
|
|
240
|
-
}
|
|
241
|
-
render();
|
|
242
|
-
}
|
|
243
|
-
function toggleAllSkills() {
|
|
244
|
-
if (state.activeTab !== "skills") {
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
const items = currentTabItems(state, catalog);
|
|
248
|
-
const allSelected = items.every((item) => state.selectedSkills.has(item.id));
|
|
249
|
-
for (const item of items) {
|
|
250
|
-
const selected = state.selectedSkills.has(item.id);
|
|
251
|
-
if (allSelected && selected) {
|
|
252
|
-
state.selectedSkills.delete(item.id);
|
|
253
|
-
}
|
|
254
|
-
else if (!allSelected && !selected) {
|
|
255
|
-
state.selectedSkills.add(item.id);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
render();
|
|
259
|
-
}
|
|
260
|
-
screen.key(["left"], () => {
|
|
261
|
-
if (!canRun(lastTabSwitchAt, DEBOUNCE_SELECT_MS)) {
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
lastTabSwitchAt = Date.now();
|
|
265
|
-
moveTab(state, -1);
|
|
266
|
-
render();
|
|
267
|
-
});
|
|
268
|
-
screen.key(["right"], () => {
|
|
269
|
-
if (!canRun(lastTabSwitchAt, DEBOUNCE_SELECT_MS)) {
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
lastTabSwitchAt = Date.now();
|
|
273
|
-
moveTab(state, 1);
|
|
274
|
-
render();
|
|
275
|
-
});
|
|
276
|
-
screen.key(["up"], () => {
|
|
277
|
-
if (!canRun(lastMoveAt, DEBOUNCE_MOVE_MS)) {
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
lastMoveAt = Date.now();
|
|
281
|
-
moveCursor(state, catalog, -1);
|
|
282
|
-
render();
|
|
283
|
-
});
|
|
284
|
-
screen.key(["down"], () => {
|
|
285
|
-
if (!canRun(lastMoveAt, DEBOUNCE_MOVE_MS)) {
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
lastMoveAt = Date.now();
|
|
289
|
-
moveCursor(state, catalog, 1);
|
|
290
|
-
render();
|
|
291
|
-
});
|
|
292
|
-
screen.key(["space", "enter"], () => {
|
|
293
|
-
handleToggleOrConfirm();
|
|
294
|
-
});
|
|
295
|
-
screen.key(["a"], () => {
|
|
296
|
-
toggleAllSkills();
|
|
297
|
-
});
|
|
298
|
-
screen.key(["q", "C-c"], () => {
|
|
299
|
-
finishWithError("Installation cancelled.");
|
|
300
|
-
});
|
|
301
|
-
render();
|
|
302
|
-
});
|
|
303
|
-
}
|