@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.
@@ -1,539 +0,0 @@
1
- import { buildLibInstallPlan, detectSupportedHostOs } from "./ai-libs.js";
2
- import { canRun, createTabbedLayout, DEBOUNCE_MOVE_MS, DEBOUNCE_SELECT_MS, renderBannerHeader, renderKeycaps, renderListRow, renderListContent, renderStepSummary, renderTabBar, selectionArray } from "./tui-utils.js";
3
- const TAB_ORDER = ["libraries", "agents", "os", "scope", "mode", "review"];
4
- function buildInitialState() {
5
- return {
6
- activeTab: "libraries",
7
- selectedLibraries: new Set(),
8
- selectedAgents: new Set(),
9
- selectedOs: detectSupportedHostOs(),
10
- selectedScope: "global",
11
- selectedMode: "install",
12
- listCursor: {
13
- libraries: 0,
14
- agents: 0,
15
- os: 0,
16
- scope: 0,
17
- mode: 0,
18
- review: 0
19
- },
20
- reviewAction: "confirm",
21
- notice: ""
22
- };
23
- }
24
- function currentTabItems(state) {
25
- if (state.activeTab === "libraries") {
26
- return [
27
- {
28
- id: "rtk",
29
- label: "◈ rtk-ai/rtk",
30
- description: "Token-saving CLI proxy with agent-specific init for Codex and Claude.",
31
- kind: "library"
32
- },
33
- {
34
- id: "icm",
35
- label: "◈ rtk-ai/icm",
36
- description: "Persistent agent memory with MCP, CLI instructions, rules, and hooks.",
37
- kind: "library"
38
- },
39
- {
40
- id: "ecc",
41
- label: "◈ affaan-m/ECC",
42
- description: "Coding rules, agent instructions, hooks, and skills library for Claude Code and Codex.",
43
- kind: "library"
44
- },
45
- {
46
- id: "codegraph",
47
- label: "◈ colbymchenry/codegraph",
48
- description: "Codebase indexer that maps symbols and call paths — enables fast semantic code exploration via MCP or CLI.",
49
- kind: "library"
50
- }
51
- ];
52
- }
53
- if (state.activeTab === "agents") {
54
- return [
55
- {
56
- id: "codex",
57
- label: "◇ Codex",
58
- description: "Apply library setup to OpenAI Codex config, AGENTS.md, and agent-specific directories.",
59
- kind: "agents"
60
- },
61
- {
62
- id: "claude",
63
- label: "◇ Claude",
64
- description: "Apply library setup to Claude Code config, CLAUDE.md, and agent-specific directories.",
65
- kind: "agents"
66
- }
67
- ];
68
- }
69
- if (state.activeTab === "os") {
70
- return [
71
- {
72
- id: "mac",
73
- label: "⊙ Mac",
74
- description: "Run the install flow for a macOS host.",
75
- kind: "os"
76
- },
77
- {
78
- id: "linux",
79
- label: "⊙ Linux",
80
- description: "Run the install flow for a Linux host.",
81
- kind: "os"
82
- }
83
- ];
84
- }
85
- if (state.activeTab === "scope") {
86
- return [
87
- {
88
- id: "global",
89
- label: "⊙ Global",
90
- description: "Use global agent configuration in home-directory tool config files.",
91
- kind: "scope"
92
- },
93
- {
94
- id: "local",
95
- label: "⊕ Local",
96
- description: "Install into the project's own config dirs (.claude/, .codex/) instead of the home directory.",
97
- kind: "scope"
98
- }
99
- ];
100
- }
101
- if (state.activeTab === "mode") {
102
- return [
103
- {
104
- id: "install",
105
- label: "▶ Install",
106
- description: "Install the selected libraries and configure the chosen integrations.",
107
- kind: "mode"
108
- },
109
- {
110
- id: "uninstall",
111
- label: "← Uninstall",
112
- description: "Remove library-managed integrations safely and clean up only library-specific artifacts.",
113
- kind: "mode"
114
- }
115
- ];
116
- }
117
- return [
118
- {
119
- id: "confirm",
120
- label: "✓ Confirm install",
121
- description: "Run the planned install and configuration commands.",
122
- kind: "review"
123
- },
124
- {
125
- id: "back",
126
- label: "← Back to main menu",
127
- description: "Leave this installer and return to the main menu.",
128
- kind: "review"
129
- },
130
- {
131
- id: "cancel",
132
- label: "✕ Cancel",
133
- description: "Exit without installing anything.",
134
- kind: "review"
135
- }
136
- ];
137
- }
138
- function isItemSelected(item, state) {
139
- if (item.kind === "library") {
140
- return state.selectedLibraries.has(item.id);
141
- }
142
- if (item.kind === "agents") {
143
- return state.selectedAgents.has(item.id);
144
- }
145
- if (item.kind === "os") {
146
- return state.selectedOs === item.id;
147
- }
148
- if (item.kind === "scope") {
149
- return state.selectedScope === item.id;
150
- }
151
- if (item.kind === "mode") {
152
- return state.selectedMode === item.id;
153
- }
154
- return state.reviewAction === item.id;
155
- }
156
- function toggleItem(item, state) {
157
- if (item.kind === "library") {
158
- if (state.selectedLibraries.has(item.id)) {
159
- state.selectedLibraries.delete(item.id);
160
- }
161
- else {
162
- state.selectedLibraries.add(item.id);
163
- }
164
- return;
165
- }
166
- if (item.kind === "agents") {
167
- const agent = item.id;
168
- if (state.selectedAgents.has(agent)) {
169
- state.selectedAgents.delete(agent);
170
- }
171
- else {
172
- state.selectedAgents.add(agent);
173
- }
174
- return;
175
- }
176
- if (item.kind === "os") {
177
- state.selectedOs = item.id;
178
- return;
179
- }
180
- if (item.kind === "scope") {
181
- state.selectedScope = item.id;
182
- return;
183
- }
184
- if (item.kind === "mode") {
185
- state.selectedMode = item.id;
186
- return;
187
- }
188
- state.reviewAction = item.id;
189
- }
190
- function renderTabs(state) {
191
- const counts = {
192
- libraries: state.selectedLibraries.size,
193
- agents: state.selectedAgents.size,
194
- os: state.selectedOs ? 1 : 0,
195
- scope: 1,
196
- mode: 1,
197
- review: state.reviewAction === "confirm" ? 1 : 0
198
- };
199
- return renderTabBar(TAB_ORDER.map((tab, index) => ({
200
- label: `${index + 1}. ${tab === "os" ? "OS" : tab.charAt(0).toUpperCase() + tab.slice(1)}`,
201
- meta: tab === "review" ? "ready" : `${counts[tab]} selected`,
202
- active: state.activeTab === tab
203
- })));
204
- }
205
- function formatListItem(item, state, isCursorRow, index) {
206
- if (item.kind === "review") {
207
- return renderListRow({
208
- active: isCursorRow,
209
- selected: state.reviewAction === item.id,
210
- label: item.label,
211
- index
212
- });
213
- }
214
- return renderListRow({
215
- active: isCursorRow,
216
- selected: isItemSelected(item, state),
217
- label: item.label,
218
- index
219
- });
220
- }
221
- function renderReviewSummary(state) {
222
- const selectedLibraries = selectionArray(state.selectedLibraries);
223
- const selectedAgents = selectionArray(state.selectedAgents);
224
- const sep = `{cyan-fg}${"─".repeat(50)}{/cyan-fg}`;
225
- const none = "{gray-fg}none{/gray-fg}";
226
- const lines = [
227
- `{bold}{white-fg}◈ Summary{/white-fg}{/bold}`,
228
- sep,
229
- `{cyan-fg}◆ Libraries{/cyan-fg} ${selectedLibraries.length ? selectedLibraries.join(", ") : none}`,
230
- `{cyan-fg}◆ Agents{/cyan-fg} ${selectedAgents.length ? selectedAgents.join(", ") : none}`,
231
- `{cyan-fg}◆ OS{/cyan-fg} ${state.selectedOs ?? none}`,
232
- `{cyan-fg}◆ Scope{/cyan-fg} ${state.selectedScope}`,
233
- `{cyan-fg}◆ Mode{/cyan-fg} ${state.selectedMode}`
234
- ];
235
- if (selectedLibraries.length > 0 && selectedAgents.length > 0 && state.selectedOs) {
236
- const plan = buildLibInstallPlan({
237
- mode: state.selectedMode,
238
- os: state.selectedOs,
239
- scope: state.selectedScope,
240
- agents: selectedAgents,
241
- libraries: selectedLibraries
242
- });
243
- lines.push("", sep, `{bold}{white-fg}⊕ Planned steps{/white-fg}{/bold}`);
244
- for (const step of plan.steps) {
245
- lines.push(` {gray-fg}▶{/gray-fg} ${step.title}`);
246
- }
247
- if (plan.notes.length > 0) {
248
- lines.push("", `{bold}{white-fg}◎ Notes{/white-fg}{/bold}`);
249
- for (const note of plan.notes) {
250
- lines.push(` {gray-fg}·{/gray-fg} ${note}`);
251
- }
252
- }
253
- }
254
- if (state.notice) {
255
- lines.push("", `{yellow-fg}${state.notice}{/yellow-fg}`);
256
- }
257
- return lines.join("\n");
258
- }
259
- function renderDetailBody(state) {
260
- if (state.activeTab === "review") {
261
- return renderReviewSummary(state);
262
- }
263
- const items = currentTabItems(state);
264
- const current = items[state.listCursor[state.activeTab]];
265
- const lines = [];
266
- if (state.notice) {
267
- lines.push(`{yellow-fg}${state.notice}{/yellow-fg}`, "");
268
- }
269
- if (current) {
270
- const selectedCount = items.filter((item) => isItemSelected(item, state)).length;
271
- 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}`);
272
- }
273
- return lines.join("\n");
274
- }
275
- function renderFooter(state) {
276
- if (state.activeTab === "review") {
277
- return renderKeycaps([
278
- { key: "LEFT/RIGHT", label: "switch tab" },
279
- { key: "UP/DOWN", label: "move" },
280
- { key: "ENTER", label: "confirm action" },
281
- { key: "Q", label: "quit" }
282
- ]);
283
- }
284
- return renderKeycaps([
285
- { key: "LEFT/RIGHT", label: "switch tab" },
286
- { key: "UP/DOWN", label: "move" },
287
- { key: "SPACE", label: "toggle" },
288
- { key: "A", label: "toggle all" },
289
- { key: "Q", label: "quit" }
290
- ]);
291
- }
292
- function setNotice(state, message) {
293
- state.notice = message;
294
- }
295
- function moveTab(state, delta) {
296
- const index = TAB_ORDER.indexOf(state.activeTab);
297
- const nextIndex = (index + delta + TAB_ORDER.length) % TAB_ORDER.length;
298
- state.activeTab = TAB_ORDER[nextIndex];
299
- state.notice = "";
300
- }
301
- function moveCursor(state, delta) {
302
- const items = currentTabItems(state);
303
- if (items.length === 0) {
304
- return;
305
- }
306
- const current = state.listCursor[state.activeTab];
307
- const next = (current + delta + items.length) % items.length;
308
- state.listCursor[state.activeTab] = next;
309
- if (state.activeTab === "review") {
310
- state.reviewAction = items[next]?.id;
311
- }
312
- }
313
- function toggleCurrentItem(state) {
314
- if (state.activeTab === "review") {
315
- return;
316
- }
317
- const items = currentTabItems(state);
318
- const current = items[state.listCursor[state.activeTab]];
319
- if (!current) {
320
- return;
321
- }
322
- toggleItem(current, state);
323
- }
324
- function validateBeforeConfirm(state) {
325
- if (state.selectedLibraries.size === 0) {
326
- return "Select at least one library before confirming.";
327
- }
328
- if (state.selectedAgents.size === 0) {
329
- return "Select at least one agent before confirming.";
330
- }
331
- if (!state.selectedOs) {
332
- return "Select one OS target before confirming.";
333
- }
334
- if (!state.selectedScope) {
335
- return "Select one scope before confirming.";
336
- }
337
- if (!state.selectedMode) {
338
- return "Select one mode before confirming.";
339
- }
340
- return null;
341
- }
342
- function syncListSelection(listBox, state) {
343
- const items = currentTabItems(state);
344
- const maxIndex = Math.max(items.length - 1, 0);
345
- const cursor = Math.min(state.listCursor[state.activeTab], maxIndex);
346
- state.listCursor[state.activeTab] = cursor;
347
- const rendered = items.map((item, index) => formatListItem(item, state, index === cursor, index));
348
- renderListContent(listBox, rendered, cursor);
349
- }
350
- export async function runAiLibsWizard() {
351
- return new Promise((resolve, reject) => {
352
- const state = buildInitialState();
353
- let lastTabSwitchAt = 0;
354
- let lastMoveAt = 0;
355
- let lastToggleAt = 0;
356
- const { screen, headerBox, tabsBox, titleBox, listBox, detailBox, footerBox } = createTabbedLayout();
357
- function cleanup() {
358
- screen.destroy();
359
- }
360
- function finishWithError(message) {
361
- cleanup();
362
- reject(new Error(message));
363
- }
364
- function finishSuccess() {
365
- if (!state.selectedOs) {
366
- finishWithError("Missing OS selection.");
367
- return;
368
- }
369
- cleanup();
370
- resolve({
371
- libraries: selectionArray(state.selectedLibraries),
372
- agents: selectionArray(state.selectedAgents),
373
- os: state.selectedOs,
374
- scope: state.selectedScope,
375
- mode: state.selectedMode
376
- });
377
- }
378
- function finishBackToMenu() {
379
- cleanup();
380
- resolve({
381
- backToMenu: true
382
- });
383
- }
384
- function render() {
385
- const currentStep = TAB_ORDER.indexOf(state.activeTab) + 1;
386
- const stepTitle = {
387
- libraries: "Select libraries",
388
- agents: "Select agents",
389
- os: "Select OS",
390
- scope: "Select scope",
391
- mode: "Select mode",
392
- review: "Review selections"
393
- }[state.activeTab];
394
- const stepDescription = {
395
- libraries: "Choose one or more upstream AI libraries to install.",
396
- agents: "Pick which agent integrations should be configured.",
397
- os: "Choose the current host OS for sanity checking before install.",
398
- scope: "Choose whether setup should target global config or project-local files.",
399
- mode: "Choose whether to install or uninstall the selected libraries.",
400
- review: "Verify selections before shell commands are executed."
401
- }[state.activeTab];
402
- const stepStatus = {
403
- libraries: `${state.selectedLibraries.size} selected`,
404
- agents: `${state.selectedAgents.size} selected`,
405
- os: state.selectedOs ?? "none selected",
406
- scope: state.selectedScope,
407
- mode: state.selectedMode,
408
- review: state.notice || "Ready for confirmation"
409
- }[state.activeTab];
410
- headerBox.setContent(renderBannerHeader("Install libs for AI", "Run upstream installers and init commands for RTK, ICM, ECC, and CodeGraph.", [
411
- { label: `${state.selectedLibraries.size} libraries`, tone: "accent" },
412
- { label: `${state.selectedAgents.size} agents`, tone: "success" },
413
- { label: state.selectedOs ?? "OS pending", tone: "muted" },
414
- { label: state.selectedScope, tone: "muted" },
415
- { label: state.selectedMode, tone: "muted" }
416
- ]));
417
- tabsBox.setContent(renderTabs(state));
418
- titleBox.setContent(renderStepSummary({
419
- step: `STEP ${currentStep}/${TAB_ORDER.length}`,
420
- title: stepTitle,
421
- description: stepDescription,
422
- status: stepStatus
423
- }));
424
- syncListSelection(listBox, state);
425
- detailBox.setContent(renderDetailBody(state));
426
- footerBox.setContent(renderFooter(state));
427
- screen.render();
428
- }
429
- function handleToggleOrConfirm() {
430
- if (!canRun(lastToggleAt, DEBOUNCE_SELECT_MS)) {
431
- return;
432
- }
433
- lastToggleAt = Date.now();
434
- if (state.activeTab === "review") {
435
- if (state.reviewAction === "back") {
436
- finishBackToMenu();
437
- return;
438
- }
439
- if (state.reviewAction === "cancel") {
440
- finishWithError("Installation cancelled.");
441
- return;
442
- }
443
- const validationMessage = validateBeforeConfirm(state);
444
- if (validationMessage) {
445
- setNotice(state, validationMessage);
446
- render();
447
- return;
448
- }
449
- finishSuccess();
450
- return;
451
- }
452
- toggleCurrentItem(state);
453
- render();
454
- }
455
- function toggleAllInCurrentTab() {
456
- if (state.activeTab === "review") {
457
- return;
458
- }
459
- const items = currentTabItems(state);
460
- if (items.length === 0) {
461
- return;
462
- }
463
- if (state.activeTab === "os" || state.activeTab === "scope" || state.activeTab === "mode") {
464
- const cursor = state.listCursor[state.activeTab];
465
- const current = items[cursor];
466
- if (current && state.activeTab === "os") {
467
- state.selectedOs = current.id;
468
- render();
469
- }
470
- if (current && state.activeTab === "scope") {
471
- state.selectedScope = current.id;
472
- render();
473
- }
474
- if (current && state.activeTab === "mode") {
475
- state.selectedMode = current.id;
476
- render();
477
- }
478
- return;
479
- }
480
- const allSelected = items.every((item) => isItemSelected(item, state));
481
- for (const item of items) {
482
- const selected = isItemSelected(item, state);
483
- if (allSelected && selected) {
484
- toggleItem(item, state);
485
- }
486
- else if (!allSelected && !selected) {
487
- toggleItem(item, state);
488
- }
489
- }
490
- render();
491
- }
492
- screen.key(["left"], () => {
493
- if (!canRun(lastTabSwitchAt, DEBOUNCE_SELECT_MS)) {
494
- return;
495
- }
496
- lastTabSwitchAt = Date.now();
497
- moveTab(state, -1);
498
- render();
499
- });
500
- screen.key(["right", "tab"], () => {
501
- if (!canRun(lastTabSwitchAt, DEBOUNCE_SELECT_MS)) {
502
- return;
503
- }
504
- lastTabSwitchAt = Date.now();
505
- moveTab(state, 1);
506
- render();
507
- });
508
- screen.key(["up"], () => {
509
- if (!canRun(lastMoveAt, DEBOUNCE_MOVE_MS)) {
510
- return;
511
- }
512
- lastMoveAt = Date.now();
513
- moveCursor(state, -1);
514
- render();
515
- });
516
- screen.key(["down"], () => {
517
- if (!canRun(lastMoveAt, DEBOUNCE_MOVE_MS)) {
518
- return;
519
- }
520
- lastMoveAt = Date.now();
521
- moveCursor(state, 1);
522
- render();
523
- });
524
- screen.key(["space"], handleToggleOrConfirm);
525
- screen.key(["enter"], handleToggleOrConfirm);
526
- screen.key(["a"], () => {
527
- if (!canRun(lastToggleAt, DEBOUNCE_SELECT_MS)) {
528
- return;
529
- }
530
- lastToggleAt = Date.now();
531
- toggleAllInCurrentTab();
532
- });
533
- screen.key(["q", "escape", "C-c"], () => {
534
- cleanup();
535
- reject(new Error("Installation cancelled."));
536
- });
537
- render();
538
- });
539
- }