@minhluudev/ai-tools 1.0.1 → 1.0.3
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 +16 -96
- package/dist/src/bin/ai-tools.js +1 -1
- package/dist/src/cli.js +155 -137
- package/dist/src/lib/catalog.js +5 -2
- package/dist/src/lib/github.js +2 -2
- package/dist/src/lib/install.js +20 -23
- package/dist/src/lib/prompts.js +3 -13
- package/dist/src/lib/selection-catalog.js +17 -7
- package/dist/src/lib/tui-entry-menu.js +86 -40
- package/dist/src/lib/tui-project-docs.js +56 -103
- package/dist/src/lib/tui-utils.js +361 -0
- package/dist/src/lib/tui-wizard.js +95 -152
- package/package.json +1 -1
- package/dist/src/lib/args.js +0 -98
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import blessed from "blessed";
|
|
2
|
+
export const DEBOUNCE_MOVE_MS = 100;
|
|
3
|
+
export const DEBOUNCE_SELECT_MS = 120;
|
|
4
|
+
export function canRun(lastAt, thresholdMs) {
|
|
5
|
+
return Date.now() - lastAt >= thresholdMs;
|
|
6
|
+
}
|
|
7
|
+
export function selectionArray(items) {
|
|
8
|
+
return [...items];
|
|
9
|
+
}
|
|
10
|
+
function renderChip(label, tone = "accent") {
|
|
11
|
+
if (tone === "success") {
|
|
12
|
+
return `{black-fg}{green-bg} ${label} {/green-bg}{/black-fg}`;
|
|
13
|
+
}
|
|
14
|
+
if (tone === "warning") {
|
|
15
|
+
return `{black-fg}{yellow-bg} ${label} {/yellow-bg}{/black-fg}`;
|
|
16
|
+
}
|
|
17
|
+
if (tone === "muted") {
|
|
18
|
+
return `{white-fg}{gray-bg} ${label} {/gray-bg}{/white-fg}`;
|
|
19
|
+
}
|
|
20
|
+
return `{black-fg}{cyan-bg} ${label} {/cyan-bg}{/black-fg}`;
|
|
21
|
+
}
|
|
22
|
+
export function renderKeycaps(items) {
|
|
23
|
+
return items
|
|
24
|
+
.map((item) => `${renderChip(item.key, "muted")} {gray-fg}${item.label}{/gray-fg}`)
|
|
25
|
+
.join(" ");
|
|
26
|
+
}
|
|
27
|
+
export function renderBannerHeader(title, subtitle, chips = []) {
|
|
28
|
+
const chipLine = chips.length > 0
|
|
29
|
+
? chips.map((chip) => renderChip(chip.label, chip.tone)).join(" ")
|
|
30
|
+
: renderChip("Terminal installer", "muted");
|
|
31
|
+
return [
|
|
32
|
+
`{bold}${renderChip("AI TOOLS")} ${title}{/bold}`,
|
|
33
|
+
`{gray-fg}${subtitle}{/gray-fg}`,
|
|
34
|
+
chipLine,
|
|
35
|
+
"{cyan-fg}======================================================================{/cyan-fg}"
|
|
36
|
+
].join("\n");
|
|
37
|
+
}
|
|
38
|
+
export function renderTabBar(tabs) {
|
|
39
|
+
return tabs
|
|
40
|
+
.map((tab) => {
|
|
41
|
+
const meta = tab.meta ? ` {gray-fg}${tab.meta}{/gray-fg}` : "";
|
|
42
|
+
const content = ` ${tab.label}${meta} `;
|
|
43
|
+
return tab.active
|
|
44
|
+
? `{black-fg}{yellow-bg}${content}{/yellow-bg}{/black-fg}`
|
|
45
|
+
: `{cyan-fg}${content}{/cyan-fg}`;
|
|
46
|
+
})
|
|
47
|
+
.join(" ");
|
|
48
|
+
}
|
|
49
|
+
export function renderStepSummary(input) {
|
|
50
|
+
const lines = [
|
|
51
|
+
`{bold}${input.step}{/bold} {white-fg}${input.title}{/white-fg}`,
|
|
52
|
+
`{gray-fg}${input.description}{/gray-fg}`
|
|
53
|
+
];
|
|
54
|
+
if (input.status) {
|
|
55
|
+
lines.push(renderChip(input.status, "muted"));
|
|
56
|
+
}
|
|
57
|
+
return lines.join("\n");
|
|
58
|
+
}
|
|
59
|
+
export function renderListRow(input) {
|
|
60
|
+
const marker = input.selected === undefined ? " " : input.selected ? "x" : " ";
|
|
61
|
+
const indexLabel = input.index === undefined ? "" : `${String(input.index + 1).padStart(2, "0")} `;
|
|
62
|
+
const row = `${input.active ? ">" : " "} [${marker}] ${indexLabel}${input.label}`;
|
|
63
|
+
const content = input.meta ? `${row} {gray-fg}${input.meta}{/gray-fg}` : row;
|
|
64
|
+
return input.active
|
|
65
|
+
? `{black-fg}{yellow-bg}${content}{/yellow-bg}{/black-fg}`
|
|
66
|
+
: content;
|
|
67
|
+
}
|
|
68
|
+
function renderActionButton(label, active, tone) {
|
|
69
|
+
if (active && tone === "success") {
|
|
70
|
+
return `{black-fg}{green-bg} ${label} {/green-bg}{/black-fg}`;
|
|
71
|
+
}
|
|
72
|
+
if (active) {
|
|
73
|
+
return `{black-fg}{yellow-bg} ${label} {/yellow-bg}{/black-fg}`;
|
|
74
|
+
}
|
|
75
|
+
if (tone === "success") {
|
|
76
|
+
return `{green-fg}[ ${label} ]{/green-fg}`;
|
|
77
|
+
}
|
|
78
|
+
return `{gray-fg}[ ${label} ]{/gray-fg}`;
|
|
79
|
+
}
|
|
80
|
+
export async function blessedSelect(input) {
|
|
81
|
+
return new Promise((resolve) => {
|
|
82
|
+
let cursor = 0;
|
|
83
|
+
const screen = blessed.screen({
|
|
84
|
+
smartCSR: true,
|
|
85
|
+
fullUnicode: true,
|
|
86
|
+
dockBorders: true,
|
|
87
|
+
title: "ai-tools"
|
|
88
|
+
});
|
|
89
|
+
const promptBox = blessed.box({
|
|
90
|
+
parent: screen,
|
|
91
|
+
top: "center",
|
|
92
|
+
left: "center",
|
|
93
|
+
width: "70%",
|
|
94
|
+
height: Math.max(input.choices.length + 8, 10),
|
|
95
|
+
border: { type: "line" },
|
|
96
|
+
label: " confirm ",
|
|
97
|
+
tags: true,
|
|
98
|
+
padding: {
|
|
99
|
+
top: 1,
|
|
100
|
+
left: 2,
|
|
101
|
+
right: 2,
|
|
102
|
+
bottom: 1
|
|
103
|
+
},
|
|
104
|
+
style: {
|
|
105
|
+
border: {
|
|
106
|
+
fg: "cyan"
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
function render() {
|
|
111
|
+
const lines = [
|
|
112
|
+
`{bold}${renderChip("ATTENTION", "warning")} ${input.message}{/bold}`,
|
|
113
|
+
"{gray-fg}This applies to every conflicting target in the current run.{/gray-fg}",
|
|
114
|
+
"",
|
|
115
|
+
renderKeycaps([
|
|
116
|
+
{ key: "UP/DOWN", label: "move" },
|
|
117
|
+
{ key: "ENTER", label: "select" },
|
|
118
|
+
{ key: "Q", label: "cancel" }
|
|
119
|
+
]),
|
|
120
|
+
""
|
|
121
|
+
];
|
|
122
|
+
for (let i = 0; i < input.choices.length; i++) {
|
|
123
|
+
const choice = input.choices[i];
|
|
124
|
+
lines.push(renderListRow({
|
|
125
|
+
active: i === cursor,
|
|
126
|
+
label: choice.label,
|
|
127
|
+
meta: choice.description
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
promptBox.setContent(lines.join("\n"));
|
|
131
|
+
screen.render();
|
|
132
|
+
}
|
|
133
|
+
screen.key(["up"], () => {
|
|
134
|
+
cursor = (cursor - 1 + input.choices.length) % input.choices.length;
|
|
135
|
+
render();
|
|
136
|
+
});
|
|
137
|
+
screen.key(["down"], () => {
|
|
138
|
+
cursor = (cursor + 1) % input.choices.length;
|
|
139
|
+
render();
|
|
140
|
+
});
|
|
141
|
+
screen.key(["enter", "space"], () => {
|
|
142
|
+
const value = input.choices[cursor].value;
|
|
143
|
+
screen.destroy();
|
|
144
|
+
resolve(value);
|
|
145
|
+
});
|
|
146
|
+
screen.key(["escape", "q", "C-c"], () => {
|
|
147
|
+
screen.destroy();
|
|
148
|
+
resolve(input.choices[0].value);
|
|
149
|
+
});
|
|
150
|
+
render();
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
export async function blessedConfirm(input) {
|
|
154
|
+
return new Promise((resolve) => {
|
|
155
|
+
let accept = false;
|
|
156
|
+
const screen = blessed.screen({
|
|
157
|
+
smartCSR: true,
|
|
158
|
+
fullUnicode: true,
|
|
159
|
+
dockBorders: true,
|
|
160
|
+
title: "ai-tools"
|
|
161
|
+
});
|
|
162
|
+
const promptBox = blessed.box({
|
|
163
|
+
parent: screen,
|
|
164
|
+
top: "center",
|
|
165
|
+
left: "center",
|
|
166
|
+
width: "70%",
|
|
167
|
+
height: 11,
|
|
168
|
+
border: { type: "line" },
|
|
169
|
+
label: " confirm ",
|
|
170
|
+
tags: true,
|
|
171
|
+
padding: {
|
|
172
|
+
top: 1,
|
|
173
|
+
left: 2,
|
|
174
|
+
right: 2,
|
|
175
|
+
bottom: 1
|
|
176
|
+
},
|
|
177
|
+
style: {
|
|
178
|
+
border: {
|
|
179
|
+
fg: "cyan"
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
const confirmLabel = input.confirmLabel ?? "Yes";
|
|
184
|
+
const cancelLabel = input.cancelLabel ?? "No";
|
|
185
|
+
function finish(value) {
|
|
186
|
+
screen.destroy();
|
|
187
|
+
resolve(value);
|
|
188
|
+
}
|
|
189
|
+
function toggle() {
|
|
190
|
+
accept = !accept;
|
|
191
|
+
render();
|
|
192
|
+
}
|
|
193
|
+
function render() {
|
|
194
|
+
const actionRow = `${renderActionButton(confirmLabel, accept, "success")} ${renderActionButton(cancelLabel, !accept, "muted")}`;
|
|
195
|
+
const lines = [
|
|
196
|
+
`{bold}${renderChip("ATTENTION", "warning")} ${input.message}{/bold}`,
|
|
197
|
+
`{gray-fg}${input.description ?? "This applies to every conflicting target in the current run."}{/gray-fg}`,
|
|
198
|
+
"",
|
|
199
|
+
actionRow,
|
|
200
|
+
"",
|
|
201
|
+
renderKeycaps([
|
|
202
|
+
{ key: "LEFT/RIGHT", label: "switch" },
|
|
203
|
+
{ key: "ENTER", label: "confirm" },
|
|
204
|
+
{ key: "ESC", label: "cancel" }
|
|
205
|
+
])
|
|
206
|
+
];
|
|
207
|
+
promptBox.setContent(lines.join("\n"));
|
|
208
|
+
screen.render();
|
|
209
|
+
}
|
|
210
|
+
screen.key(["left", "right", "tab", "S-tab", "h", "l"], () => {
|
|
211
|
+
toggle();
|
|
212
|
+
});
|
|
213
|
+
screen.key(["up", "down"], () => {
|
|
214
|
+
toggle();
|
|
215
|
+
});
|
|
216
|
+
screen.key(["enter", "space"], () => {
|
|
217
|
+
finish(accept);
|
|
218
|
+
});
|
|
219
|
+
screen.key(["escape", "q", "C-c"], () => {
|
|
220
|
+
finish(false);
|
|
221
|
+
});
|
|
222
|
+
render();
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
export function createTabbedLayout() {
|
|
226
|
+
const screen = blessed.screen({
|
|
227
|
+
smartCSR: true,
|
|
228
|
+
fullUnicode: true,
|
|
229
|
+
dockBorders: true,
|
|
230
|
+
title: "ai-tools"
|
|
231
|
+
});
|
|
232
|
+
const headerBox = blessed.box({
|
|
233
|
+
parent: screen,
|
|
234
|
+
top: 1,
|
|
235
|
+
left: 2,
|
|
236
|
+
width: "100%-4",
|
|
237
|
+
height: 6,
|
|
238
|
+
tags: true,
|
|
239
|
+
wrap: true,
|
|
240
|
+
border: { type: "line" },
|
|
241
|
+
label: " overview ",
|
|
242
|
+
padding: {
|
|
243
|
+
left: 1,
|
|
244
|
+
right: 1
|
|
245
|
+
},
|
|
246
|
+
style: {
|
|
247
|
+
border: {
|
|
248
|
+
fg: "cyan"
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
const tabsBox = blessed.box({
|
|
253
|
+
parent: screen,
|
|
254
|
+
top: 8,
|
|
255
|
+
left: 2,
|
|
256
|
+
width: "100%-4",
|
|
257
|
+
height: 3,
|
|
258
|
+
tags: true,
|
|
259
|
+
border: { type: "line" },
|
|
260
|
+
label: " flow ",
|
|
261
|
+
padding: {
|
|
262
|
+
left: 1,
|
|
263
|
+
right: 1
|
|
264
|
+
},
|
|
265
|
+
style: {
|
|
266
|
+
border: {
|
|
267
|
+
fg: "blue"
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
const titleBox = blessed.box({
|
|
272
|
+
parent: screen,
|
|
273
|
+
top: 11,
|
|
274
|
+
left: 2,
|
|
275
|
+
width: "100%-4",
|
|
276
|
+
height: 4,
|
|
277
|
+
tags: true,
|
|
278
|
+
border: { type: "line" },
|
|
279
|
+
label: " current step ",
|
|
280
|
+
padding: {
|
|
281
|
+
left: 1,
|
|
282
|
+
right: 1
|
|
283
|
+
},
|
|
284
|
+
style: {
|
|
285
|
+
border: {
|
|
286
|
+
fg: "magenta"
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
const listBox = blessed.list({
|
|
291
|
+
parent: screen,
|
|
292
|
+
top: 15,
|
|
293
|
+
left: 2,
|
|
294
|
+
width: "100%-4",
|
|
295
|
+
height: "100%-23",
|
|
296
|
+
tags: true,
|
|
297
|
+
keys: false,
|
|
298
|
+
vi: false,
|
|
299
|
+
mouse: false,
|
|
300
|
+
interactive: false,
|
|
301
|
+
scrollable: true,
|
|
302
|
+
alwaysScroll: true,
|
|
303
|
+
border: { type: "line" },
|
|
304
|
+
label: " options ",
|
|
305
|
+
padding: {
|
|
306
|
+
left: 1,
|
|
307
|
+
right: 1
|
|
308
|
+
},
|
|
309
|
+
style: {
|
|
310
|
+
border: {
|
|
311
|
+
fg: "blue"
|
|
312
|
+
},
|
|
313
|
+
selected: {
|
|
314
|
+
bold: true,
|
|
315
|
+
fg: "black",
|
|
316
|
+
bg: "yellow"
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
scrollbar: {
|
|
320
|
+
ch: " ",
|
|
321
|
+
track: {
|
|
322
|
+
bg: "gray"
|
|
323
|
+
},
|
|
324
|
+
style: {
|
|
325
|
+
bg: "cyan"
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
const detailBox = blessed.box({
|
|
330
|
+
parent: screen,
|
|
331
|
+
left: 2,
|
|
332
|
+
bottom: 2,
|
|
333
|
+
width: "100%-4",
|
|
334
|
+
height: 5,
|
|
335
|
+
tags: true,
|
|
336
|
+
wrap: true,
|
|
337
|
+
border: { type: "line" },
|
|
338
|
+
label: " details ",
|
|
339
|
+
padding: {
|
|
340
|
+
left: 1,
|
|
341
|
+
right: 1
|
|
342
|
+
},
|
|
343
|
+
style: {
|
|
344
|
+
border: {
|
|
345
|
+
fg: "green"
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
const footerBox = blessed.box({
|
|
350
|
+
parent: screen,
|
|
351
|
+
bottom: 0,
|
|
352
|
+
left: 2,
|
|
353
|
+
width: "100%-4",
|
|
354
|
+
height: 1,
|
|
355
|
+
tags: true,
|
|
356
|
+
style: {
|
|
357
|
+
fg: "gray"
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
return { screen, headerBox, tabsBox, titleBox, listBox, detailBox, footerBox };
|
|
361
|
+
}
|