@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.
@@ -1,13 +1,13 @@
1
- import blessed from "blessed";
2
1
  import { resolveInstallRoot } from "./install.js";
2
+ import { canRun, createTabbedLayout, DEBOUNCE_MOVE_MS, DEBOUNCE_SELECT_MS, renderBannerHeader, renderKeycaps, renderListRow, renderStepSummary, renderTabBar, selectionArray } from "./tui-utils.js";
3
3
  const TAB_ORDER = ["skills", "locations", "agents", "review"];
4
- function buildInitialState(options) {
4
+ function buildInitialState() {
5
5
  return {
6
6
  activeTab: "skills",
7
- selectedSkills: new Set(options.skills),
8
- selectedGroups: new Set(options.groups),
9
- selectedLocations: new Set(options.locations),
10
- selectedAgents: new Set(options.agents),
7
+ selectedSkills: new Set(),
8
+ selectedGroups: new Set(),
9
+ selectedLocations: new Set(),
10
+ selectedAgents: new Set(),
11
11
  listCursor: {
12
12
  skills: 0,
13
13
  locations: 0,
@@ -18,9 +18,6 @@ function buildInitialState(options) {
18
18
  notice: ""
19
19
  };
20
20
  }
21
- function selectionArray(items) {
22
- return [...items];
23
- }
24
21
  function currentTabItems(state, selectionCatalog) {
25
22
  if (state.activeTab === "skills") {
26
23
  return selectionCatalog.skills.map((skill) => ({
@@ -83,25 +80,6 @@ function currentTabItems(state, selectionCatalog) {
83
80
  }
84
81
  ];
85
82
  }
86
- function isItemLocked(item, options) {
87
- if (item.kind === "skill") {
88
- return options.skills.length > 0;
89
- }
90
- if (item.kind === "locations") {
91
- return options.locations.length > 0;
92
- }
93
- if (item.kind === "agents") {
94
- return options.agents.length > 0;
95
- }
96
- return false;
97
- }
98
- function areAllItemsLocked(state, selectionCatalog, options) {
99
- if (state.activeTab === "review") {
100
- return false;
101
- }
102
- const items = currentTabItems(state, selectionCatalog);
103
- return items.length > 0 && items.every((item) => isItemLocked(item, options));
104
- }
105
83
  function isItemSelected(item, state) {
106
84
  if (item.kind === "skill") {
107
85
  return state.selectedSkills.has(item.id);
@@ -147,20 +125,35 @@ function toggleItem(item, state) {
147
125
  state.reviewAction = item.id;
148
126
  }
149
127
  function renderTabs(state) {
150
- return TAB_ORDER.map((tab) => {
151
- const label = tab.charAt(0).toUpperCase() + tab.slice(1);
152
- return state.activeTab === tab ? `{inverse}${label}{/inverse}` : label;
153
- }).join(" ");
128
+ const counts = {
129
+ skills: state.selectedSkills.size + state.selectedGroups.size,
130
+ locations: state.selectedLocations.size,
131
+ agents: state.selectedAgents.size,
132
+ review: state.reviewAction === "confirm" ? 1 : 0
133
+ };
134
+ return renderTabBar(TAB_ORDER.map((tab, index) => ({
135
+ label: `${index + 1}. ${tab.charAt(0).toUpperCase() + tab.slice(1)}`,
136
+ meta: tab === "review" ? "ready" : `${counts[tab]} selected`,
137
+ active: state.activeTab === tab
138
+ })));
154
139
  }
155
- function formatListItem(item, state, options, isCursorRow) {
156
- const cursorPrefix = isCursorRow ? "> " : " ";
157
- const wrapCursorRow = (value) => isCursorRow ? `{black-fg}{yellow-bg}${value}{/yellow-bg}{/black-fg}` : value;
140
+ function formatListItem(item, state, isCursorRow, index) {
158
141
  if (item.kind === "review") {
159
- return wrapCursorRow(`${cursorPrefix}${state.reviewAction === item.id ? "[x]" : "[ ]"} ${item.label}`);
142
+ return renderListRow({
143
+ active: isCursorRow,
144
+ selected: state.reviewAction === item.id,
145
+ label: item.label,
146
+ meta: item.description,
147
+ index
148
+ });
160
149
  }
161
- const checked = isItemSelected(item, state) ? "x" : " ";
162
- const locked = isItemLocked(item, options) ? " {yellow-fg}(locked){/yellow-fg}" : "";
163
- return wrapCursorRow(`${cursorPrefix}[${checked}] ${item.label}${locked}`);
150
+ return renderListRow({
151
+ active: isCursorRow,
152
+ selected: isItemSelected(item, state),
153
+ label: item.label,
154
+ meta: item.description,
155
+ index
156
+ });
164
157
  }
165
158
  function renderReviewSummary(state, selectionCatalog) {
166
159
  const selectedSkillLabels = selectionCatalog.skills
@@ -173,15 +166,15 @@ function renderReviewSummary(state, selectionCatalog) {
173
166
  const selectedAgents = selectionArray(state.selectedAgents);
174
167
  const lines = [
175
168
  "{bold}Selections{/bold}",
176
- `Skills: ${selectedSkillLabels.length ? selectedSkillLabels.join(", ") : "none"}`,
177
- `Locations: ${selectedLocations.length ? selectedLocations.join(", ") : "none"}`,
178
- `Agents: ${selectedAgents.length ? selectedAgents.join(", ") : "none"}`
169
+ `Skills ${selectedSkillLabels.length ? selectedSkillLabels.join(", ") : "none"}`,
170
+ `Locations ${selectedLocations.length ? selectedLocations.join(", ") : "none"}`,
171
+ `Agents ${selectedAgents.length ? selectedAgents.join(", ") : "none"}`
179
172
  ];
180
173
  if (selectedGroupLabels.length > 0) {
181
- lines.splice(2, 0, `Groups: ${selectedGroupLabels.join(", ")}`);
174
+ lines.splice(2, 0, `Groups ${selectedGroupLabels.join(", ")}`);
182
175
  }
183
176
  if (selectedLocations.length > 0 && selectedAgents.length > 0) {
184
- lines.push("", "{bold}Targets{/bold}");
177
+ lines.push("", "{bold}Resolved targets{/bold}");
185
178
  for (const agent of selectedAgents) {
186
179
  for (const location of selectedLocations) {
187
180
  lines.push(`- ${agent} + ${location}: ${resolveInstallRoot({ agent, location, cwd: process.cwd() })}`);
@@ -193,7 +186,7 @@ function renderReviewSummary(state, selectionCatalog) {
193
186
  }
194
187
  return lines.join("\n");
195
188
  }
196
- function renderDetailBody(state, selectionCatalog, options) {
189
+ function renderDetailBody(state, selectionCatalog) {
197
190
  if (state.activeTab === "review") {
198
191
  return renderReviewSummary(state, selectionCatalog);
199
192
  }
@@ -203,22 +196,28 @@ function renderDetailBody(state, selectionCatalog, options) {
203
196
  if (state.notice) {
204
197
  lines.push(`{yellow-fg}${state.notice}{/yellow-fg}`, "");
205
198
  }
206
- if (areAllItemsLocked(state, selectionCatalog, options)) {
207
- lines.push("{yellow-fg}Locked by CLI options. Use flags to change these values.{/yellow-fg}", "");
208
- }
209
199
  if (current) {
210
- lines.push("{bold}Details{/bold}", current.description);
200
+ const selectedCount = items.filter((item) => isItemSelected(item, state)).length;
201
+ lines.push("{bold}Selected in this step{/bold}", `${selectedCount} of ${items.length}`, "", "{bold}About current item{/bold}", current.description);
211
202
  }
212
203
  return lines.join("\n");
213
204
  }
214
- function renderFooter(state, selectionCatalog, options) {
205
+ function renderFooter(state) {
215
206
  if (state.activeTab === "review") {
216
- return "← → switch tab • ↑ ↓ move • enter confirm action • q quit";
207
+ return renderKeycaps([
208
+ { key: "LEFT/RIGHT", label: "switch tab" },
209
+ { key: "UP/DOWN", label: "move" },
210
+ { key: "ENTER", label: "confirm action" },
211
+ { key: "Q", label: "quit" }
212
+ ]);
217
213
  }
218
- if (areAllItemsLocked(state, selectionCatalog, options)) {
219
- return "← → switch tab • ↑ ↓ move • q quit";
220
- }
221
- return "← → switch tab • ↑ ↓ move • space/enter toggle • a toggle all • q quit";
214
+ return renderKeycaps([
215
+ { key: "LEFT/RIGHT", label: "switch tab" },
216
+ { key: "UP/DOWN", label: "move" },
217
+ { key: "SPACE", label: "toggle" },
218
+ { key: "A", label: "toggle all" },
219
+ { key: "Q", label: "quit" }
220
+ ]);
222
221
  }
223
222
  function setNotice(state, message) {
224
223
  state.notice = message;
@@ -241,13 +240,13 @@ function moveCursor(state, selectionCatalog, delta) {
241
240
  state.reviewAction = items[next]?.id;
242
241
  }
243
242
  }
244
- function toggleCurrentItem(state, selectionCatalog, options) {
243
+ function toggleCurrentItem(state, selectionCatalog) {
245
244
  if (state.activeTab === "review") {
246
245
  return;
247
246
  }
248
247
  const items = currentTabItems(state, selectionCatalog);
249
248
  const current = items[state.listCursor[state.activeTab]];
250
- if (!current || isItemLocked(current, options)) {
249
+ if (!current) {
251
250
  return;
252
251
  }
253
252
  toggleItem(current, state);
@@ -264,97 +263,22 @@ function validateBeforeConfirm(state) {
264
263
  }
265
264
  return null;
266
265
  }
267
- function syncListSelection(listBox, state, selectionCatalog, options) {
266
+ function syncListSelection(listBox, state, selectionCatalog) {
268
267
  const items = currentTabItems(state, selectionCatalog);
269
268
  const maxIndex = Math.max(items.length - 1, 0);
270
269
  const cursor = Math.min(state.listCursor[state.activeTab], maxIndex);
271
270
  state.listCursor[state.activeTab] = cursor;
272
- listBox.setItems(items.map((item, index) => formatListItem(item, state, options, index === cursor)));
271
+ listBox.setItems(items.map((item, index) => formatListItem(item, state, index === cursor, index)));
273
272
  listBox.select(cursor);
274
273
  listBox.scrollTo(cursor);
275
274
  }
276
- function renderHeader(title, subtitle) {
277
- return [
278
- "{black-fg}{cyan-bg} AI-TOOLS {/cyan-bg}{/black-fg}",
279
- `{bold}${title}{/bold}`,
280
- `{gray-fg}${subtitle}{/gray-fg}`,
281
- "{cyan-fg}------------------------------------------------------------------------{/cyan-fg}"
282
- ].join("\n");
283
- }
284
- export async function runTabbedWizard(selectionCatalog, options, headerTitle = "Install agent skills") {
275
+ export async function runTabbedWizard(selectionCatalog, headerTitle = "Install agent skills") {
285
276
  return new Promise((resolve, reject) => {
286
- const state = buildInitialState(options);
277
+ const state = buildInitialState();
287
278
  let lastTabSwitchAt = 0;
288
279
  let lastMoveAt = 0;
289
280
  let lastToggleAt = 0;
290
- const screen = blessed.screen({
291
- smartCSR: true,
292
- fullUnicode: true,
293
- title: "ai-tools"
294
- });
295
- const headerBox = blessed.box({
296
- parent: screen,
297
- top: 0,
298
- left: 0,
299
- width: "100%",
300
- height: 4,
301
- tags: true,
302
- wrap: true
303
- });
304
- const tabsBox = blessed.box({
305
- parent: screen,
306
- top: 4,
307
- left: 0,
308
- width: "100%",
309
- height: 1,
310
- tags: true
311
- });
312
- const titleBox = blessed.box({
313
- parent: screen,
314
- top: 6,
315
- left: 0,
316
- width: "100%",
317
- height: 1,
318
- tags: true
319
- });
320
- const listBox = blessed.list({
321
- parent: screen,
322
- top: 8,
323
- left: 0,
324
- width: "100%",
325
- height: "100%-13",
326
- tags: true,
327
- keys: false,
328
- vi: false,
329
- mouse: false,
330
- interactive: false,
331
- scrollable: true,
332
- alwaysScroll: true,
333
- style: {
334
- selected: {
335
- bold: true,
336
- fg: "black",
337
- bg: "yellow"
338
- }
339
- }
340
- });
341
- const detailBox = blessed.box({
342
- parent: screen,
343
- left: 0,
344
- bottom: 1,
345
- width: "100%",
346
- height: 4,
347
- tags: true,
348
- wrap: true
349
- });
350
- const footerBox = blessed.box({
351
- parent: screen,
352
- bottom: 0,
353
- left: 0,
354
- width: "100%",
355
- height: 1,
356
- tags: true
357
- });
281
+ const { screen, headerBox, tabsBox, titleBox, listBox, detailBox, footerBox } = createTabbedLayout();
358
282
  function cleanup() {
359
283
  screen.destroy();
360
284
  }
@@ -378,25 +302,44 @@ export async function runTabbedWizard(selectionCatalog, options, headerTitle = "
378
302
  });
379
303
  }
380
304
  function render() {
305
+ const currentStep = TAB_ORDER.indexOf(state.activeTab) + 1;
381
306
  const stepTitle = {
382
307
  skills: "Select skills",
383
308
  locations: "Select installation locations",
384
309
  agents: "Select agents",
385
310
  review: "Review selections"
386
311
  }[state.activeTab];
387
- headerBox.setContent(renderHeader(headerTitle, "Browse items, move across tabs, and confirm only after review."));
312
+ const stepDescription = {
313
+ skills: "Choose the skills you want to install.",
314
+ locations: "Pick where the installer should place the files.",
315
+ agents: "Pick which agent format should be generated.",
316
+ review: "Verify selections before writing anything to disk."
317
+ }[state.activeTab];
318
+ const stepStatus = {
319
+ skills: `${state.selectedSkills.size + state.selectedGroups.size} selected`,
320
+ locations: `${state.selectedLocations.size} selected`,
321
+ agents: `${state.selectedAgents.size} selected`,
322
+ review: state.notice || "Ready for confirmation"
323
+ }[state.activeTab];
324
+ headerBox.setContent(renderBannerHeader(headerTitle, "Browse items, move across tabs, and confirm only after review.", [
325
+ { label: `${state.selectedSkills.size + state.selectedGroups.size} skills`, tone: "accent" },
326
+ { label: `${state.selectedLocations.size} locations`, tone: "muted" },
327
+ { label: `${state.selectedAgents.size} agents`, tone: "success" }
328
+ ]));
388
329
  tabsBox.setContent(renderTabs(state));
389
- titleBox.setContent(`{bold}${stepTitle}{/bold}`);
390
- syncListSelection(listBox, state, selectionCatalog, options);
391
- detailBox.setContent(renderDetailBody(state, selectionCatalog, options));
392
- footerBox.setContent(renderFooter(state, selectionCatalog, options));
330
+ titleBox.setContent(renderStepSummary({
331
+ step: `STEP ${currentStep}/${TAB_ORDER.length}`,
332
+ title: stepTitle,
333
+ description: stepDescription,
334
+ status: stepStatus
335
+ }));
336
+ syncListSelection(listBox, state, selectionCatalog);
337
+ detailBox.setContent(renderDetailBody(state, selectionCatalog));
338
+ footerBox.setContent(renderFooter(state));
393
339
  screen.render();
394
340
  }
395
- function canRun(lastAt, thresholdMs) {
396
- return Date.now() - lastAt >= thresholdMs;
397
- }
398
341
  function handleToggleOrConfirm() {
399
- if (!canRun(lastToggleAt, 120)) {
342
+ if (!canRun(lastToggleAt, DEBOUNCE_SELECT_MS)) {
400
343
  return;
401
344
  }
402
345
  lastToggleAt = Date.now();
@@ -418,14 +361,14 @@ export async function runTabbedWizard(selectionCatalog, options, headerTitle = "
418
361
  finishSuccess();
419
362
  return;
420
363
  }
421
- toggleCurrentItem(state, selectionCatalog, options);
364
+ toggleCurrentItem(state, selectionCatalog);
422
365
  render();
423
366
  }
424
367
  function toggleAllInCurrentTab() {
425
368
  if (state.activeTab === "review") {
426
369
  return;
427
370
  }
428
- const items = currentTabItems(state, selectionCatalog).filter((item) => !isItemLocked(item, options));
371
+ const items = currentTabItems(state, selectionCatalog);
429
372
  if (items.length === 0) {
430
373
  return;
431
374
  }
@@ -442,7 +385,7 @@ export async function runTabbedWizard(selectionCatalog, options, headerTitle = "
442
385
  render();
443
386
  }
444
387
  screen.key(["left"], () => {
445
- if (!canRun(lastTabSwitchAt, 120)) {
388
+ if (!canRun(lastTabSwitchAt, DEBOUNCE_SELECT_MS)) {
446
389
  return;
447
390
  }
448
391
  lastTabSwitchAt = Date.now();
@@ -450,7 +393,7 @@ export async function runTabbedWizard(selectionCatalog, options, headerTitle = "
450
393
  render();
451
394
  });
452
395
  screen.key(["right"], () => {
453
- if (!canRun(lastTabSwitchAt, 120)) {
396
+ if (!canRun(lastTabSwitchAt, DEBOUNCE_SELECT_MS)) {
454
397
  return;
455
398
  }
456
399
  lastTabSwitchAt = Date.now();
@@ -458,7 +401,7 @@ export async function runTabbedWizard(selectionCatalog, options, headerTitle = "
458
401
  render();
459
402
  });
460
403
  screen.key(["up"], () => {
461
- if (!canRun(lastMoveAt, 100)) {
404
+ if (!canRun(lastMoveAt, DEBOUNCE_MOVE_MS)) {
462
405
  return;
463
406
  }
464
407
  lastMoveAt = Date.now();
@@ -466,7 +409,7 @@ export async function runTabbedWizard(selectionCatalog, options, headerTitle = "
466
409
  render();
467
410
  });
468
411
  screen.key(["down"], () => {
469
- if (!canRun(lastMoveAt, 100)) {
412
+ if (!canRun(lastMoveAt, DEBOUNCE_MOVE_MS)) {
470
413
  return;
471
414
  }
472
415
  lastMoveAt = Date.now();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minhluudev/ai-tools",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "CLI to install AI skills from GitHub branches into Codex and Claude.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,98 +0,0 @@
1
- const COMMANDS = new Set(["install", "help"]);
2
- const AGENTS = new Set(["codex", "claude"]);
3
- const LOCATIONS = new Set(["global", "local"]);
4
- const FLAG_KEYS = new Set(["agent", "location", "skills", "groups"]);
5
- function parseCsv(value) {
6
- if (!value) {
7
- return [];
8
- }
9
- return value
10
- .split(",")
11
- .map((item) => item.trim())
12
- .filter(Boolean);
13
- }
14
- export function isAgent(value) {
15
- return AGENTS.has(value);
16
- }
17
- export function isInstallLocation(value) {
18
- return LOCATIONS.has(value);
19
- }
20
- export function parseArgs(argv) {
21
- let command = "install";
22
- const options = {
23
- help: false,
24
- yes: false,
25
- agents: [],
26
- locations: [],
27
- skills: [],
28
- groups: []
29
- };
30
- for (let index = 0; index < argv.length; index += 1) {
31
- const token = argv[index];
32
- if (token === "--help" || token === "-h") {
33
- options.help = true;
34
- continue;
35
- }
36
- if (token === "--yes") {
37
- options.yes = true;
38
- continue;
39
- }
40
- if (!token.startsWith("--")) {
41
- if (COMMANDS.has(token)) {
42
- command = token;
43
- continue;
44
- }
45
- throw new Error(`Unknown argument "${token}".`);
46
- }
47
- const key = token.slice(2);
48
- if (!FLAG_KEYS.has(key)) {
49
- throw new Error(`Unknown flag "${token}".`);
50
- }
51
- const value = argv[index + 1];
52
- if (!value || value.startsWith("--")) {
53
- throw new Error(`Flag "${token}" requires a value.`);
54
- }
55
- index += 1;
56
- if (key === "skills" || key === "groups") {
57
- options[key] = parseCsv(value);
58
- continue;
59
- }
60
- if (key === "agent") {
61
- const agents = parseCsv(value);
62
- if (agents.some((agent) => !isAgent(agent))) {
63
- throw new Error(`Invalid agent list "${value}". Use "codex" and/or "claude".`);
64
- }
65
- options.agents = agents;
66
- continue;
67
- }
68
- if (key === "location") {
69
- const locations = parseCsv(value);
70
- if (locations.some((location) => !isInstallLocation(location))) {
71
- throw new Error(`Invalid location list "${value}". Use "global" and/or "local".`);
72
- }
73
- options.locations = locations;
74
- }
75
- }
76
- return { command, options };
77
- }
78
- export function printHelp() {
79
- console.log(`ai-tools
80
-
81
- Usage:
82
- ai-tools
83
- ai-tools install [options]
84
- ai-tools help
85
-
86
- Default behavior:
87
- Running "ai-tools" in an interactive terminal opens a top-level menu.
88
- Running "ai-tools install" starts the skills installer directly.
89
-
90
- Options:
91
- --skills <ids> Comma-separated individual skill ids
92
- --groups <ids> Comma-separated group ids
93
- --location <types> Comma-separated: global,local
94
- --agent <agents> Comma-separated: codex,claude
95
- --yes Skip overwrite prompts
96
- --help, -h Show help
97
- `);
98
- }