@minhluudev/ai-tools 0.1.1 → 1.0.1
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 +37 -15
- package/dist/src/bin/ai-tools.js +8 -0
- package/dist/src/cli.js +185 -171
- package/dist/src/lib/args.js +17 -10
- package/dist/src/lib/catalog.js +45 -13
- package/dist/src/lib/config.js +2 -0
- package/dist/src/lib/github.js +9 -6
- package/dist/src/lib/install.js +73 -1
- package/dist/src/lib/project-docs-catalog.js +45 -0
- package/dist/src/lib/prompts.js +34 -78
- package/dist/src/lib/selection-catalog.js +130 -0
- package/dist/src/lib/tui-entry-menu.js +135 -0
- package/dist/src/lib/tui-project-docs.js +350 -0
- package/dist/src/lib/tui-wizard.js +487 -0
- package/package.json +10 -1
- package/project-docs-catalog.json +19 -0
- package/selection-catalog.json +19 -0
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import blessed from "blessed";
|
|
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 selectionArray(items) {
|
|
16
|
+
return [...items];
|
|
17
|
+
}
|
|
18
|
+
function currentTabItems(state, catalog) {
|
|
19
|
+
if (state.activeTab === "skills") {
|
|
20
|
+
return catalog.skills.map((skill) => ({
|
|
21
|
+
id: skill.id,
|
|
22
|
+
label: skill.label,
|
|
23
|
+
description: skill.description,
|
|
24
|
+
kind: "skills"
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
return [
|
|
28
|
+
{
|
|
29
|
+
id: "confirm",
|
|
30
|
+
label: "Confirm install",
|
|
31
|
+
description: "Continue with the selected skills.",
|
|
32
|
+
kind: "review"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: "back",
|
|
36
|
+
label: "Back to main menu",
|
|
37
|
+
description: "Leave this installer and return to the main menu.",
|
|
38
|
+
kind: "review"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: "cancel",
|
|
42
|
+
label: "Cancel",
|
|
43
|
+
description: "Exit without installing anything.",
|
|
44
|
+
kind: "review"
|
|
45
|
+
}
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
function renderTabs(state) {
|
|
49
|
+
return TAB_ORDER.map((tab) => {
|
|
50
|
+
const label = tab.charAt(0).toUpperCase() + tab.slice(1);
|
|
51
|
+
return state.activeTab === tab ? `{inverse}${label}{/inverse}` : label;
|
|
52
|
+
}).join(" ");
|
|
53
|
+
}
|
|
54
|
+
function isItemSelected(item, state) {
|
|
55
|
+
if (item.kind === "skills") {
|
|
56
|
+
return state.selectedSkills.has(item.id);
|
|
57
|
+
}
|
|
58
|
+
return state.reviewAction === item.id;
|
|
59
|
+
}
|
|
60
|
+
function toggleItem(item, state) {
|
|
61
|
+
if (item.kind === "skills") {
|
|
62
|
+
if (state.selectedSkills.has(item.id)) {
|
|
63
|
+
state.selectedSkills.delete(item.id);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
state.selectedSkills.add(item.id);
|
|
67
|
+
}
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
state.reviewAction = item.id;
|
|
71
|
+
}
|
|
72
|
+
function formatListItem(item, state, isCursorRow) {
|
|
73
|
+
const cursorPrefix = isCursorRow ? "> " : " ";
|
|
74
|
+
const wrapCursorRow = (value) => isCursorRow ? `{black-fg}{yellow-bg}${value}{/yellow-bg}{/black-fg}` : value;
|
|
75
|
+
if (item.kind === "review") {
|
|
76
|
+
return wrapCursorRow(`${cursorPrefix}${state.reviewAction === item.id ? "[x]" : "[ ]"} ${item.label}`);
|
|
77
|
+
}
|
|
78
|
+
const checked = isItemSelected(item, state) ? "x" : " ";
|
|
79
|
+
return wrapCursorRow(`${cursorPrefix}[${checked}] ${item.label}`);
|
|
80
|
+
}
|
|
81
|
+
function renderHeader() {
|
|
82
|
+
return [
|
|
83
|
+
"{black-fg}{cyan-bg} AI-TOOLS {/cyan-bg}{/black-fg}",
|
|
84
|
+
"{bold}Install project docs{/bold}",
|
|
85
|
+
"{gray-fg}Choose skills first, then confirm from review.{/gray-fg}",
|
|
86
|
+
"{cyan-fg}------------------------------------------------------------------------{/cyan-fg}"
|
|
87
|
+
].join("\n");
|
|
88
|
+
}
|
|
89
|
+
function renderReviewSummary(state, catalog) {
|
|
90
|
+
const selectedSkills = catalog.skills
|
|
91
|
+
.filter((skill) => state.selectedSkills.has(skill.id))
|
|
92
|
+
.map((skill) => skill.label);
|
|
93
|
+
const lines = [
|
|
94
|
+
"{bold}Selections{/bold}",
|
|
95
|
+
`Skills: ${selectedSkills.length ? selectedSkills.join(", ") : "none"}`
|
|
96
|
+
];
|
|
97
|
+
if (state.notice) {
|
|
98
|
+
lines.push("", `{yellow-fg}${state.notice}{/yellow-fg}`);
|
|
99
|
+
}
|
|
100
|
+
return lines.join("\n");
|
|
101
|
+
}
|
|
102
|
+
function renderDetailBody(state, catalog) {
|
|
103
|
+
if (state.activeTab === "review") {
|
|
104
|
+
return renderReviewSummary(state, catalog);
|
|
105
|
+
}
|
|
106
|
+
const items = currentTabItems(state, catalog);
|
|
107
|
+
const current = items[state.listCursor[state.activeTab]];
|
|
108
|
+
const lines = [];
|
|
109
|
+
if (state.notice) {
|
|
110
|
+
lines.push(`{yellow-fg}${state.notice}{/yellow-fg}`, "");
|
|
111
|
+
}
|
|
112
|
+
if (current) {
|
|
113
|
+
lines.push("{bold}Details{/bold}", current.description);
|
|
114
|
+
}
|
|
115
|
+
return lines.join("\n");
|
|
116
|
+
}
|
|
117
|
+
function renderFooter(state) {
|
|
118
|
+
if (state.activeTab === "review") {
|
|
119
|
+
return "← → switch tab • ↑ ↓ move • enter confirm action • q quit";
|
|
120
|
+
}
|
|
121
|
+
return "← → switch tab • ↑ ↓ move • space/enter toggle • a toggle all • q quit";
|
|
122
|
+
}
|
|
123
|
+
function moveTab(state, delta) {
|
|
124
|
+
const index = TAB_ORDER.indexOf(state.activeTab);
|
|
125
|
+
const nextIndex = (index + delta + TAB_ORDER.length) % TAB_ORDER.length;
|
|
126
|
+
state.activeTab = TAB_ORDER[nextIndex];
|
|
127
|
+
state.notice = "";
|
|
128
|
+
}
|
|
129
|
+
function moveCursor(state, catalog, delta) {
|
|
130
|
+
const items = currentTabItems(state, catalog);
|
|
131
|
+
if (items.length === 0) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const current = state.listCursor[state.activeTab];
|
|
135
|
+
const next = (current + delta + items.length) % items.length;
|
|
136
|
+
state.listCursor[state.activeTab] = next;
|
|
137
|
+
if (state.activeTab === "review") {
|
|
138
|
+
state.reviewAction = items[next]?.id;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function validateBeforeConfirm(state) {
|
|
142
|
+
if (state.selectedSkills.size === 0) {
|
|
143
|
+
return "Select at least one skill before confirming.";
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
function syncListSelection(listBox, state, catalog) {
|
|
148
|
+
const items = currentTabItems(state, catalog);
|
|
149
|
+
const maxIndex = Math.max(items.length - 1, 0);
|
|
150
|
+
const cursor = Math.min(state.listCursor[state.activeTab], maxIndex);
|
|
151
|
+
state.listCursor[state.activeTab] = cursor;
|
|
152
|
+
listBox.setItems(items.map((item, index) => formatListItem(item, state, index === cursor)));
|
|
153
|
+
listBox.select(cursor);
|
|
154
|
+
listBox.scrollTo(cursor);
|
|
155
|
+
}
|
|
156
|
+
export async function runProjectDocsWizard(catalog) {
|
|
157
|
+
return new Promise((resolve, reject) => {
|
|
158
|
+
const state = buildInitialState();
|
|
159
|
+
let lastTabSwitchAt = 0;
|
|
160
|
+
let lastMoveAt = 0;
|
|
161
|
+
let lastToggleAt = 0;
|
|
162
|
+
const screen = blessed.screen({
|
|
163
|
+
smartCSR: true,
|
|
164
|
+
fullUnicode: true,
|
|
165
|
+
title: "ai-tools"
|
|
166
|
+
});
|
|
167
|
+
const headerBox = blessed.box({
|
|
168
|
+
parent: screen,
|
|
169
|
+
top: 0,
|
|
170
|
+
left: 0,
|
|
171
|
+
width: "100%",
|
|
172
|
+
height: 4,
|
|
173
|
+
tags: true,
|
|
174
|
+
wrap: true
|
|
175
|
+
});
|
|
176
|
+
const tabsBox = blessed.box({
|
|
177
|
+
parent: screen,
|
|
178
|
+
top: 4,
|
|
179
|
+
left: 0,
|
|
180
|
+
width: "100%",
|
|
181
|
+
height: 1,
|
|
182
|
+
tags: true
|
|
183
|
+
});
|
|
184
|
+
const titleBox = blessed.box({
|
|
185
|
+
parent: screen,
|
|
186
|
+
top: 6,
|
|
187
|
+
left: 0,
|
|
188
|
+
width: "100%",
|
|
189
|
+
height: 1,
|
|
190
|
+
tags: true
|
|
191
|
+
});
|
|
192
|
+
const listBox = blessed.list({
|
|
193
|
+
parent: screen,
|
|
194
|
+
top: 8,
|
|
195
|
+
left: 0,
|
|
196
|
+
width: "100%",
|
|
197
|
+
height: "100%-13",
|
|
198
|
+
tags: true,
|
|
199
|
+
keys: false,
|
|
200
|
+
vi: false,
|
|
201
|
+
mouse: false,
|
|
202
|
+
interactive: false,
|
|
203
|
+
scrollable: true,
|
|
204
|
+
alwaysScroll: true,
|
|
205
|
+
style: {
|
|
206
|
+
selected: {
|
|
207
|
+
bold: true,
|
|
208
|
+
fg: "black",
|
|
209
|
+
bg: "yellow"
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
const detailBox = blessed.box({
|
|
214
|
+
parent: screen,
|
|
215
|
+
left: 0,
|
|
216
|
+
bottom: 1,
|
|
217
|
+
width: "100%",
|
|
218
|
+
height: 4,
|
|
219
|
+
tags: true,
|
|
220
|
+
wrap: true
|
|
221
|
+
});
|
|
222
|
+
const footerBox = blessed.box({
|
|
223
|
+
parent: screen,
|
|
224
|
+
bottom: 0,
|
|
225
|
+
left: 0,
|
|
226
|
+
width: "100%",
|
|
227
|
+
height: 1,
|
|
228
|
+
tags: true
|
|
229
|
+
});
|
|
230
|
+
function cleanup() {
|
|
231
|
+
screen.destroy();
|
|
232
|
+
}
|
|
233
|
+
function render() {
|
|
234
|
+
const stepTitle = state.activeTab === "skills" ? "Select skills" : "Review selections";
|
|
235
|
+
headerBox.setContent(renderHeader());
|
|
236
|
+
tabsBox.setContent(renderTabs(state));
|
|
237
|
+
titleBox.setContent(`{bold}${stepTitle}{/bold}`);
|
|
238
|
+
syncListSelection(listBox, state, catalog);
|
|
239
|
+
detailBox.setContent(renderDetailBody(state, catalog));
|
|
240
|
+
footerBox.setContent(renderFooter(state));
|
|
241
|
+
screen.render();
|
|
242
|
+
}
|
|
243
|
+
function canRun(lastAt, thresholdMs) {
|
|
244
|
+
return Date.now() - lastAt >= thresholdMs;
|
|
245
|
+
}
|
|
246
|
+
function finishBackToMenu() {
|
|
247
|
+
cleanup();
|
|
248
|
+
resolve({ backToMenu: true });
|
|
249
|
+
}
|
|
250
|
+
function finishSuccess() {
|
|
251
|
+
cleanup();
|
|
252
|
+
resolve({
|
|
253
|
+
selectedSkills: catalog.skills.filter((skill) => state.selectedSkills.has(skill.id))
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
function finishWithError(message) {
|
|
257
|
+
cleanup();
|
|
258
|
+
reject(new Error(message));
|
|
259
|
+
}
|
|
260
|
+
function handleToggleOrConfirm() {
|
|
261
|
+
if (!canRun(lastToggleAt, 120)) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
lastToggleAt = Date.now();
|
|
265
|
+
if (state.activeTab === "review") {
|
|
266
|
+
if (state.reviewAction === "back") {
|
|
267
|
+
finishBackToMenu();
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
if (state.reviewAction === "cancel") {
|
|
271
|
+
finishWithError("Installation cancelled.");
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const validationMessage = validateBeforeConfirm(state);
|
|
275
|
+
if (validationMessage) {
|
|
276
|
+
state.notice = validationMessage;
|
|
277
|
+
render();
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
finishSuccess();
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
const items = currentTabItems(state, catalog);
|
|
284
|
+
const current = items[state.listCursor.skills];
|
|
285
|
+
if (current) {
|
|
286
|
+
toggleItem(current, state);
|
|
287
|
+
}
|
|
288
|
+
render();
|
|
289
|
+
}
|
|
290
|
+
function toggleAllSkills() {
|
|
291
|
+
if (state.activeTab !== "skills") {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
const items = currentTabItems(state, catalog);
|
|
295
|
+
const allSelected = items.every((item) => state.selectedSkills.has(item.id));
|
|
296
|
+
for (const item of items) {
|
|
297
|
+
const selected = state.selectedSkills.has(item.id);
|
|
298
|
+
if (allSelected && selected) {
|
|
299
|
+
state.selectedSkills.delete(item.id);
|
|
300
|
+
}
|
|
301
|
+
else if (!allSelected && !selected) {
|
|
302
|
+
state.selectedSkills.add(item.id);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
render();
|
|
306
|
+
}
|
|
307
|
+
screen.key(["left"], () => {
|
|
308
|
+
if (!canRun(lastTabSwitchAt, 120)) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
lastTabSwitchAt = Date.now();
|
|
312
|
+
moveTab(state, -1);
|
|
313
|
+
render();
|
|
314
|
+
});
|
|
315
|
+
screen.key(["right"], () => {
|
|
316
|
+
if (!canRun(lastTabSwitchAt, 120)) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
lastTabSwitchAt = Date.now();
|
|
320
|
+
moveTab(state, 1);
|
|
321
|
+
render();
|
|
322
|
+
});
|
|
323
|
+
screen.key(["up"], () => {
|
|
324
|
+
if (!canRun(lastMoveAt, 100)) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
lastMoveAt = Date.now();
|
|
328
|
+
moveCursor(state, catalog, -1);
|
|
329
|
+
render();
|
|
330
|
+
});
|
|
331
|
+
screen.key(["down"], () => {
|
|
332
|
+
if (!canRun(lastMoveAt, 100)) {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
lastMoveAt = Date.now();
|
|
336
|
+
moveCursor(state, catalog, 1);
|
|
337
|
+
render();
|
|
338
|
+
});
|
|
339
|
+
screen.key(["space", "enter"], () => {
|
|
340
|
+
handleToggleOrConfirm();
|
|
341
|
+
});
|
|
342
|
+
screen.key(["a"], () => {
|
|
343
|
+
toggleAllSkills();
|
|
344
|
+
});
|
|
345
|
+
screen.key(["q", "C-c"], () => {
|
|
346
|
+
finishWithError("Installation cancelled.");
|
|
347
|
+
});
|
|
348
|
+
render();
|
|
349
|
+
});
|
|
350
|
+
}
|