@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.
@@ -0,0 +1,487 @@
1
+ import blessed from "blessed";
2
+ import { resolveInstallRoot } from "./install.js";
3
+ const TAB_ORDER = ["skills", "locations", "agents", "review"];
4
+ function buildInitialState(options) {
5
+ return {
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),
11
+ listCursor: {
12
+ skills: 0,
13
+ locations: 0,
14
+ agents: 0,
15
+ review: 0
16
+ },
17
+ reviewAction: "confirm",
18
+ notice: ""
19
+ };
20
+ }
21
+ function selectionArray(items) {
22
+ return [...items];
23
+ }
24
+ function currentTabItems(state, selectionCatalog) {
25
+ if (state.activeTab === "skills") {
26
+ return selectionCatalog.skills.map((skill) => ({
27
+ id: skill.id,
28
+ label: `[Skill] ${skill.label}`,
29
+ description: skill.description,
30
+ kind: "skill"
31
+ }));
32
+ }
33
+ if (state.activeTab === "locations") {
34
+ return [
35
+ {
36
+ id: "global",
37
+ label: "global",
38
+ description: "Install into the current user's home directory.",
39
+ kind: "locations"
40
+ },
41
+ {
42
+ id: "local",
43
+ label: "local",
44
+ description: "Install into this project's dot directories.",
45
+ kind: "locations"
46
+ }
47
+ ];
48
+ }
49
+ if (state.activeTab === "agents") {
50
+ return [
51
+ {
52
+ id: "codex",
53
+ label: "codex",
54
+ description: "Install as Codex skills.",
55
+ kind: "agents"
56
+ },
57
+ {
58
+ id: "claude",
59
+ label: "claude",
60
+ description: "Install as Claude custom agents.",
61
+ kind: "agents"
62
+ }
63
+ ];
64
+ }
65
+ return [
66
+ {
67
+ id: "confirm",
68
+ label: "Confirm install",
69
+ description: "Resolve sources and start installation.",
70
+ kind: "review"
71
+ },
72
+ {
73
+ id: "back",
74
+ label: "Back to main menu",
75
+ description: "Leave this installer and return to the main menu.",
76
+ kind: "review"
77
+ },
78
+ {
79
+ id: "cancel",
80
+ label: "Cancel",
81
+ description: "Exit without installing anything.",
82
+ kind: "review"
83
+ }
84
+ ];
85
+ }
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
+ function isItemSelected(item, state) {
106
+ if (item.kind === "skill") {
107
+ return state.selectedSkills.has(item.id);
108
+ }
109
+ if (item.kind === "locations") {
110
+ return state.selectedLocations.has(item.id);
111
+ }
112
+ if (item.kind === "agents") {
113
+ return state.selectedAgents.has(item.id);
114
+ }
115
+ return state.reviewAction === item.id;
116
+ }
117
+ function toggleItem(item, state) {
118
+ if (item.kind === "skill") {
119
+ if (state.selectedSkills.has(item.id)) {
120
+ state.selectedSkills.delete(item.id);
121
+ }
122
+ else {
123
+ state.selectedSkills.add(item.id);
124
+ }
125
+ return;
126
+ }
127
+ if (item.kind === "locations") {
128
+ const location = item.id;
129
+ if (state.selectedLocations.has(location)) {
130
+ state.selectedLocations.delete(location);
131
+ }
132
+ else {
133
+ state.selectedLocations.add(location);
134
+ }
135
+ return;
136
+ }
137
+ if (item.kind === "agents") {
138
+ const agent = item.id;
139
+ if (state.selectedAgents.has(agent)) {
140
+ state.selectedAgents.delete(agent);
141
+ }
142
+ else {
143
+ state.selectedAgents.add(agent);
144
+ }
145
+ return;
146
+ }
147
+ state.reviewAction = item.id;
148
+ }
149
+ 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(" ");
154
+ }
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;
158
+ if (item.kind === "review") {
159
+ return wrapCursorRow(`${cursorPrefix}${state.reviewAction === item.id ? "[x]" : "[ ]"} ${item.label}`);
160
+ }
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}`);
164
+ }
165
+ function renderReviewSummary(state, selectionCatalog) {
166
+ const selectedSkillLabels = selectionCatalog.skills
167
+ .filter((skill) => state.selectedSkills.has(skill.id))
168
+ .map((skill) => skill.label);
169
+ const selectedGroupLabels = selectionCatalog.groups
170
+ .filter((group) => state.selectedGroups.has(group.id))
171
+ .map((group) => group.label);
172
+ const selectedLocations = selectionArray(state.selectedLocations);
173
+ const selectedAgents = selectionArray(state.selectedAgents);
174
+ const lines = [
175
+ "{bold}Selections{/bold}",
176
+ `Skills: ${selectedSkillLabels.length ? selectedSkillLabels.join(", ") : "none"}`,
177
+ `Locations: ${selectedLocations.length ? selectedLocations.join(", ") : "none"}`,
178
+ `Agents: ${selectedAgents.length ? selectedAgents.join(", ") : "none"}`
179
+ ];
180
+ if (selectedGroupLabels.length > 0) {
181
+ lines.splice(2, 0, `Groups: ${selectedGroupLabels.join(", ")}`);
182
+ }
183
+ if (selectedLocations.length > 0 && selectedAgents.length > 0) {
184
+ lines.push("", "{bold}Targets{/bold}");
185
+ for (const agent of selectedAgents) {
186
+ for (const location of selectedLocations) {
187
+ lines.push(`- ${agent} + ${location}: ${resolveInstallRoot({ agent, location, cwd: process.cwd() })}`);
188
+ }
189
+ }
190
+ }
191
+ if (state.notice) {
192
+ lines.push("", `{yellow-fg}${state.notice}{/yellow-fg}`);
193
+ }
194
+ return lines.join("\n");
195
+ }
196
+ function renderDetailBody(state, selectionCatalog, options) {
197
+ if (state.activeTab === "review") {
198
+ return renderReviewSummary(state, selectionCatalog);
199
+ }
200
+ const items = currentTabItems(state, selectionCatalog);
201
+ const current = items[state.listCursor[state.activeTab]];
202
+ const lines = [];
203
+ if (state.notice) {
204
+ lines.push(`{yellow-fg}${state.notice}{/yellow-fg}`, "");
205
+ }
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
+ if (current) {
210
+ lines.push("{bold}Details{/bold}", current.description);
211
+ }
212
+ return lines.join("\n");
213
+ }
214
+ function renderFooter(state, selectionCatalog, options) {
215
+ if (state.activeTab === "review") {
216
+ return "← → switch tab • ↑ ↓ move • enter confirm action • q quit";
217
+ }
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";
222
+ }
223
+ function setNotice(state, message) {
224
+ state.notice = message;
225
+ }
226
+ function moveTab(state, delta) {
227
+ const index = TAB_ORDER.indexOf(state.activeTab);
228
+ const nextIndex = (index + delta + TAB_ORDER.length) % TAB_ORDER.length;
229
+ state.activeTab = TAB_ORDER[nextIndex];
230
+ state.notice = "";
231
+ }
232
+ function moveCursor(state, selectionCatalog, delta) {
233
+ const items = currentTabItems(state, selectionCatalog);
234
+ if (items.length === 0) {
235
+ return;
236
+ }
237
+ const current = state.listCursor[state.activeTab];
238
+ const next = (current + delta + items.length) % items.length;
239
+ state.listCursor[state.activeTab] = next;
240
+ if (state.activeTab === "review") {
241
+ state.reviewAction = items[next]?.id;
242
+ }
243
+ }
244
+ function toggleCurrentItem(state, selectionCatalog, options) {
245
+ if (state.activeTab === "review") {
246
+ return;
247
+ }
248
+ const items = currentTabItems(state, selectionCatalog);
249
+ const current = items[state.listCursor[state.activeTab]];
250
+ if (!current || isItemLocked(current, options)) {
251
+ return;
252
+ }
253
+ toggleItem(current, state);
254
+ }
255
+ function validateBeforeConfirm(state) {
256
+ if (state.selectedSkills.size === 0 && state.selectedGroups.size === 0) {
257
+ return "Select at least one skill or group before confirming.";
258
+ }
259
+ if (state.selectedLocations.size === 0) {
260
+ return "Select at least one installation location before confirming.";
261
+ }
262
+ if (state.selectedAgents.size === 0) {
263
+ return "Select at least one agent before confirming.";
264
+ }
265
+ return null;
266
+ }
267
+ function syncListSelection(listBox, state, selectionCatalog, options) {
268
+ const items = currentTabItems(state, selectionCatalog);
269
+ const maxIndex = Math.max(items.length - 1, 0);
270
+ const cursor = Math.min(state.listCursor[state.activeTab], maxIndex);
271
+ state.listCursor[state.activeTab] = cursor;
272
+ listBox.setItems(items.map((item, index) => formatListItem(item, state, options, index === cursor)));
273
+ listBox.select(cursor);
274
+ listBox.scrollTo(cursor);
275
+ }
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") {
285
+ return new Promise((resolve, reject) => {
286
+ const state = buildInitialState(options);
287
+ let lastTabSwitchAt = 0;
288
+ let lastMoveAt = 0;
289
+ 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
+ });
358
+ function cleanup() {
359
+ screen.destroy();
360
+ }
361
+ function finishWithError(message) {
362
+ cleanup();
363
+ reject(new Error(message));
364
+ }
365
+ function finishSuccess() {
366
+ cleanup();
367
+ resolve({
368
+ selectedSkills: selectionArray(state.selectedSkills),
369
+ selectedGroups: selectionArray(state.selectedGroups),
370
+ locations: selectionArray(state.selectedLocations),
371
+ agents: selectionArray(state.selectedAgents)
372
+ });
373
+ }
374
+ function finishBackToMenu() {
375
+ cleanup();
376
+ resolve({
377
+ backToMenu: true
378
+ });
379
+ }
380
+ function render() {
381
+ const stepTitle = {
382
+ skills: "Select skills",
383
+ locations: "Select installation locations",
384
+ agents: "Select agents",
385
+ review: "Review selections"
386
+ }[state.activeTab];
387
+ headerBox.setContent(renderHeader(headerTitle, "Browse items, move across tabs, and confirm only after review."));
388
+ 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));
393
+ screen.render();
394
+ }
395
+ function canRun(lastAt, thresholdMs) {
396
+ return Date.now() - lastAt >= thresholdMs;
397
+ }
398
+ function handleToggleOrConfirm() {
399
+ if (!canRun(lastToggleAt, 120)) {
400
+ return;
401
+ }
402
+ lastToggleAt = Date.now();
403
+ if (state.activeTab === "review") {
404
+ if (state.reviewAction === "back") {
405
+ finishBackToMenu();
406
+ return;
407
+ }
408
+ if (state.reviewAction === "cancel") {
409
+ finishWithError("Installation cancelled.");
410
+ return;
411
+ }
412
+ const validationMessage = validateBeforeConfirm(state);
413
+ if (validationMessage) {
414
+ setNotice(state, validationMessage);
415
+ render();
416
+ return;
417
+ }
418
+ finishSuccess();
419
+ return;
420
+ }
421
+ toggleCurrentItem(state, selectionCatalog, options);
422
+ render();
423
+ }
424
+ function toggleAllInCurrentTab() {
425
+ if (state.activeTab === "review") {
426
+ return;
427
+ }
428
+ const items = currentTabItems(state, selectionCatalog).filter((item) => !isItemLocked(item, options));
429
+ if (items.length === 0) {
430
+ return;
431
+ }
432
+ const allSelected = items.every((item) => isItemSelected(item, state));
433
+ for (const item of items) {
434
+ const selected = isItemSelected(item, state);
435
+ if (allSelected && selected) {
436
+ toggleItem(item, state);
437
+ }
438
+ else if (!allSelected && !selected) {
439
+ toggleItem(item, state);
440
+ }
441
+ }
442
+ render();
443
+ }
444
+ screen.key(["left"], () => {
445
+ if (!canRun(lastTabSwitchAt, 120)) {
446
+ return;
447
+ }
448
+ lastTabSwitchAt = Date.now();
449
+ moveTab(state, -1);
450
+ render();
451
+ });
452
+ screen.key(["right"], () => {
453
+ if (!canRun(lastTabSwitchAt, 120)) {
454
+ return;
455
+ }
456
+ lastTabSwitchAt = Date.now();
457
+ moveTab(state, 1);
458
+ render();
459
+ });
460
+ screen.key(["up"], () => {
461
+ if (!canRun(lastMoveAt, 100)) {
462
+ return;
463
+ }
464
+ lastMoveAt = Date.now();
465
+ moveCursor(state, selectionCatalog, -1);
466
+ render();
467
+ });
468
+ screen.key(["down"], () => {
469
+ if (!canRun(lastMoveAt, 100)) {
470
+ return;
471
+ }
472
+ lastMoveAt = Date.now();
473
+ moveCursor(state, selectionCatalog, 1);
474
+ render();
475
+ });
476
+ screen.key(["space", "enter"], () => {
477
+ handleToggleOrConfirm();
478
+ });
479
+ screen.key(["a"], () => {
480
+ toggleAllInCurrentTab();
481
+ });
482
+ screen.key(["q", "C-c"], () => {
483
+ finishWithError("Installation cancelled.");
484
+ });
485
+ render();
486
+ });
487
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minhluudev/ai-tools",
3
- "version": "0.1.1",
3
+ "version": "1.0.1",
4
4
  "description": "CLI to install AI skills from GitHub branches into Codex and Claude.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,6 +17,8 @@
17
17
  },
18
18
  "files": [
19
19
  "dist/src",
20
+ "selection-catalog.json",
21
+ "project-docs-catalog.json",
20
22
  "README.md"
21
23
  ],
22
24
  "scripts": {
@@ -31,10 +33,13 @@
31
33
  "node": ">=22.0.0"
32
34
  },
33
35
  "devDependencies": {
36
+ "@types/blessed": "^0.1.27",
34
37
  "@types/node": "^22.15.30",
35
38
  "typescript": "^5.8.3"
36
39
  },
37
40
  "aiTools": {
41
+ "selectionCatalogPath": "selection-catalog.json",
42
+ "projectDocsCatalogPath": "project-docs-catalog.json",
38
43
  "github": {
39
44
  "owner": "minhluudev",
40
45
  "repo": "ai-tools",
@@ -46,5 +51,9 @@
46
51
  "master"
47
52
  ]
48
53
  }
54
+ },
55
+ "dependencies": {
56
+ "@inquirer/prompts": "^8.5.2",
57
+ "blessed": "^0.1.81"
49
58
  }
50
59
  }
@@ -0,0 +1,19 @@
1
+ {
2
+ "version": 1,
3
+ "skills": [
4
+ {
5
+ "id": "laravel-ddd",
6
+ "label": "Laravel DDD",
7
+ "description": "Folder: laravel-ddd",
8
+ "sourceBranch": "project-docs",
9
+ "sourcePath": "laravel-ddd"
10
+ },
11
+ {
12
+ "id": "nextjs",
13
+ "label": "NextJS",
14
+ "description": "Folder: nextjs",
15
+ "sourceBranch": "project-docs",
16
+ "sourcePath": "nextjs"
17
+ }
18
+ ]
19
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "version": 1,
3
+ "skills": [
4
+ {
5
+ "id": "git-engineering-workflow",
6
+ "label": "Git engineering workflow",
7
+ "description": "Folder: git-engineering-workflow",
8
+ "sourceBranch": "agent-skills",
9
+ "sourcePath": "git-engineering-workflow"
10
+ },
11
+ {
12
+ "id": "review-code",
13
+ "label": "Review code",
14
+ "description": "Folder: review-code",
15
+ "sourceBranch": "agent-skills",
16
+ "sourcePath": "review-code"
17
+ }
18
+ ]
19
+ }