@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,6 +1,6 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import * as path from "node:path";
3
- import { mergeSelectedItems, validateManifest } from "./catalog.js";
3
+ import { mergeSelectedItems, validateManifest, validateTarget } from "./catalog.js";
4
4
  import { normalizeManifestPath } from "./paths.js";
5
5
  function validateSelectionEntry(rawEntry, kind, index) {
6
6
  if (!rawEntry || typeof rawEntry !== "object") {
@@ -19,6 +19,19 @@ function validateSelectionEntry(rawEntry, kind, index) {
19
19
  const sourcePath = typeof entry.sourcePath === "string" && entry.sourcePath.trim() !== ""
20
20
  ? normalizeManifestPath(entry.sourcePath, `${entry.id}.sourcePath`)
21
21
  : undefined;
22
+ let targets;
23
+ if (entry.targets && typeof entry.targets === "object" && !Array.isArray(entry.targets)) {
24
+ const rawTargets = entry.targets;
25
+ targets = {};
26
+ for (const agent of ["codex", "claude"]) {
27
+ if (rawTargets[agent]) {
28
+ targets[agent] = validateTarget(rawTargets[agent], agent, entry.id.trim());
29
+ }
30
+ }
31
+ if (Object.keys(targets).length === 0) {
32
+ targets = undefined;
33
+ }
34
+ }
22
35
  return {
23
36
  id: entry.id.trim(),
24
37
  label: entry.label.trim(),
@@ -26,7 +39,8 @@ function validateSelectionEntry(rawEntry, kind, index) {
26
39
  ? entry.description.trim()
27
40
  : "",
28
41
  sourceBranch,
29
- sourcePath
42
+ sourcePath,
43
+ targets
30
44
  };
31
45
  }
32
46
  export async function loadSelectionCatalog(config) {
@@ -87,11 +101,7 @@ export async function resolveSelectionItems(input) {
87
101
  description: selection.description,
88
102
  sourceBranch,
89
103
  sourcePath: selection.sourcePath,
90
- targets: {
91
- codex: {
92
- type: "directory"
93
- }
94
- }
104
+ targets: selection.targets ?? { codex: { type: "directory" }, claude: { type: "directory" } }
95
105
  });
96
106
  continue;
97
107
  }
@@ -1,37 +1,37 @@
1
1
  import blessed from "blessed";
2
+ import { canRun, DEBOUNCE_MOVE_MS, DEBOUNCE_SELECT_MS, renderBannerHeader, renderKeycaps, renderListRow } from "./tui-utils.js";
2
3
  const MENU_ITEMS = [
3
4
  {
4
5
  id: "install-skills",
5
6
  label: "Install agent skills",
6
- description: "Open the terminal UI to install skills for Codex and Claude."
7
+ description: "Open the guided installer for Codex skills and Claude custom agents.",
8
+ meta: "Codex + Claude"
7
9
  },
8
10
  {
9
11
  id: "install-project-docs",
10
12
  label: "Install project docs",
11
- description: "Install project documentation templates and guidance."
13
+ description: "Copy selected project docs and workflow templates into the current repository.",
14
+ meta: "Current repo"
12
15
  },
13
16
  {
14
17
  id: "install-libs",
15
18
  label: "Install libs for AI",
16
- description: "Install shared AI libraries and tooling."
19
+ description: "Install shared AI libraries and tooling.",
20
+ meta: "Coming soon"
17
21
  },
18
22
  {
19
23
  id: "cancel",
20
24
  label: "Cancel",
21
- description: "Exit without running any installer."
25
+ description: "Exit without running any installer.",
26
+ meta: "Safe exit"
22
27
  }
23
28
  ];
24
- function renderHeader() {
25
- return [
26
- "{black-fg}{cyan-bg} AI-TOOLS {/cyan-bg}{/black-fg}",
27
- "{bold}Main menu{/bold}",
28
- "{gray-fg}Choose the workflow you want to run.{/gray-fg}",
29
- "{cyan-fg}------------------------------------------------------------------------{/cyan-fg}"
30
- ].join("\n");
31
- }
32
29
  function renderItem(item, isActive) {
33
- const text = `${isActive ? "> " : " "}${item.label}`;
34
- return isActive ? `{black-fg}{yellow-bg}${text}{/yellow-bg}{/black-fg}` : text;
30
+ return renderListRow({
31
+ active: isActive,
32
+ label: item.label,
33
+ meta: item.meta
34
+ });
35
35
  }
36
36
  export async function runEntryMenu() {
37
37
  return new Promise((resolve) => {
@@ -41,28 +41,49 @@ export async function runEntryMenu() {
41
41
  const screen = blessed.screen({
42
42
  smartCSR: true,
43
43
  fullUnicode: true,
44
+ dockBorders: true,
44
45
  title: "ai-tools"
45
46
  });
46
47
  const headerBox = blessed.box({
47
48
  parent: screen,
48
- top: 0,
49
- left: 0,
50
- width: "100%",
51
- height: 4,
52
- tags: true
49
+ top: 1,
50
+ left: 2,
51
+ width: "100%-4",
52
+ height: 6,
53
+ tags: true,
54
+ border: { type: "line" },
55
+ label: " overview ",
56
+ padding: {
57
+ left: 1,
58
+ right: 1
59
+ },
60
+ style: {
61
+ border: {
62
+ fg: "cyan"
63
+ }
64
+ }
53
65
  });
54
66
  const listBox = blessed.list({
55
67
  parent: screen,
56
- top: 6,
57
- left: 0,
58
- width: "100%",
59
- height: 6,
68
+ top: 8,
69
+ left: 2,
70
+ width: "100%-4",
71
+ height: 8,
60
72
  tags: true,
61
73
  keys: false,
62
74
  vi: false,
63
75
  mouse: false,
64
76
  interactive: false,
77
+ border: { type: "line" },
78
+ label: " workflows ",
79
+ padding: {
80
+ left: 1,
81
+ right: 1
82
+ },
65
83
  style: {
84
+ border: {
85
+ fg: "blue"
86
+ },
66
87
  selected: {
67
88
  bold: true,
68
89
  fg: "black",
@@ -72,37 +93,62 @@ export async function runEntryMenu() {
72
93
  });
73
94
  const detailBox = blessed.box({
74
95
  parent: screen,
75
- top: 14,
76
- left: 0,
77
- width: "100%",
78
- height: 3,
96
+ top: 17,
97
+ left: 2,
98
+ width: "100%-4",
99
+ height: 7,
79
100
  tags: true,
80
- wrap: true
101
+ wrap: true,
102
+ border: { type: "line" },
103
+ label: " preview ",
104
+ padding: {
105
+ left: 1,
106
+ right: 1
107
+ },
108
+ style: {
109
+ border: {
110
+ fg: "green"
111
+ }
112
+ }
81
113
  });
82
114
  const footerBox = blessed.box({
83
115
  parent: screen,
84
116
  bottom: 0,
85
- left: 0,
86
- width: "100%",
117
+ left: 2,
118
+ width: "100%-4",
87
119
  height: 1,
88
- tags: true
120
+ tags: true,
121
+ style: {
122
+ fg: "gray"
123
+ }
89
124
  });
90
125
  function cleanup() {
91
126
  screen.destroy();
92
127
  }
93
128
  function render() {
94
- headerBox.setContent(renderHeader());
129
+ headerBox.setContent(renderBannerHeader("Main menu", "Choose the workflow you want to run.", [
130
+ { label: `${MENU_ITEMS.length - 1} workflows`, tone: "accent" },
131
+ { label: "Keyboard only", tone: "muted" },
132
+ { label: "Safe by default", tone: "success" }
133
+ ]));
95
134
  listBox.setItems(MENU_ITEMS.map((item, index) => renderItem(item, index === cursor)));
96
135
  listBox.select(cursor);
97
- detailBox.setContent(`{bold}Details{/bold}\n${MENU_ITEMS[cursor].description}`);
98
- footerBox.setContent("↑ ↓ move • enter select • q quit");
136
+ detailBox.setContent([
137
+ `{bold}${MENU_ITEMS[cursor].label}{/bold} {gray-fg}${MENU_ITEMS[cursor].meta}{/gray-fg}`,
138
+ "",
139
+ MENU_ITEMS[cursor].description,
140
+ "",
141
+ "{gray-fg}Tip: complete one workflow, then rerun the CLI for another task.{/gray-fg}"
142
+ ].join("\n"));
143
+ footerBox.setContent(renderKeycaps([
144
+ { key: "UP/DOWN", label: "move" },
145
+ { key: "ENTER", label: "select" },
146
+ { key: "Q", label: "quit" }
147
+ ]));
99
148
  screen.render();
100
149
  }
101
- function canRun(lastAt, thresholdMs) {
102
- return Date.now() - lastAt >= thresholdMs;
103
- }
104
150
  screen.key(["up"], () => {
105
- if (!canRun(lastMoveAt, 100)) {
151
+ if (!canRun(lastMoveAt, DEBOUNCE_MOVE_MS)) {
106
152
  return;
107
153
  }
108
154
  lastMoveAt = Date.now();
@@ -110,7 +156,7 @@ export async function runEntryMenu() {
110
156
  render();
111
157
  });
112
158
  screen.key(["down"], () => {
113
- if (!canRun(lastMoveAt, 100)) {
159
+ if (!canRun(lastMoveAt, DEBOUNCE_MOVE_MS)) {
114
160
  return;
115
161
  }
116
162
  lastMoveAt = Date.now();
@@ -118,7 +164,7 @@ export async function runEntryMenu() {
118
164
  render();
119
165
  });
120
166
  screen.key(["enter"], () => {
121
- if (!canRun(lastSelectAt, 120)) {
167
+ if (!canRun(lastSelectAt, DEBOUNCE_SELECT_MS)) {
122
168
  return;
123
169
  }
124
170
  lastSelectAt = Date.now();
@@ -1,4 +1,4 @@
1
- import blessed from "blessed";
1
+ import { canRun, createTabbedLayout, DEBOUNCE_MOVE_MS, DEBOUNCE_SELECT_MS, renderBannerHeader, renderKeycaps, renderListRow, renderStepSummary, renderTabBar } from "./tui-utils.js";
2
2
  const TAB_ORDER = ["skills", "review"];
3
3
  function buildInitialState() {
4
4
  return {
@@ -12,9 +12,6 @@ function buildInitialState() {
12
12
  notice: ""
13
13
  };
14
14
  }
15
- function selectionArray(items) {
16
- return [...items];
17
- }
18
15
  function currentTabItems(state, catalog) {
19
16
  if (state.activeTab === "skills") {
20
17
  return catalog.skills.map((skill) => ({
@@ -46,10 +43,11 @@ function currentTabItems(state, catalog) {
46
43
  ];
47
44
  }
48
45
  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(" ");
46
+ return renderTabBar(TAB_ORDER.map((tab, index) => ({
47
+ label: `${index + 1}. ${tab.charAt(0).toUpperCase() + tab.slice(1)}`,
48
+ meta: tab === "skills" ? `${state.selectedSkills.size} selected` : "ready",
49
+ active: state.activeTab === tab
50
+ })));
53
51
  }
54
52
  function isItemSelected(item, state) {
55
53
  if (item.kind === "skills") {
@@ -70,21 +68,20 @@ function toggleItem(item, state) {
70
68
  state.reviewAction = item.id;
71
69
  }
72
70
  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
71
  if (item.kind === "review") {
76
- return wrapCursorRow(`${cursorPrefix}${state.reviewAction === item.id ? "[x]" : "[ ]"} ${item.label}`);
72
+ return renderListRow({
73
+ active: isCursorRow,
74
+ selected: state.reviewAction === item.id,
75
+ label: item.label,
76
+ meta: item.description
77
+ });
77
78
  }
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");
79
+ return renderListRow({
80
+ active: isCursorRow,
81
+ selected: isItemSelected(item, state),
82
+ label: item.label,
83
+ meta: item.description
84
+ });
88
85
  }
89
86
  function renderReviewSummary(state, catalog) {
90
87
  const selectedSkills = catalog.skills
@@ -92,7 +89,7 @@ function renderReviewSummary(state, catalog) {
92
89
  .map((skill) => skill.label);
93
90
  const lines = [
94
91
  "{bold}Selections{/bold}",
95
- `Skills: ${selectedSkills.length ? selectedSkills.join(", ") : "none"}`
92
+ `Skills ${selectedSkills.length ? selectedSkills.join(", ") : "none"}`
96
93
  ];
97
94
  if (state.notice) {
98
95
  lines.push("", `{yellow-fg}${state.notice}{/yellow-fg}`);
@@ -110,15 +107,26 @@ function renderDetailBody(state, catalog) {
110
107
  lines.push(`{yellow-fg}${state.notice}{/yellow-fg}`, "");
111
108
  }
112
109
  if (current) {
113
- lines.push("{bold}Details{/bold}", current.description);
110
+ lines.push("{bold}Selected in this step{/bold}", `${state.selectedSkills.size} of ${items.length}`, "", "{bold}About current item{/bold}", current.description);
114
111
  }
115
112
  return lines.join("\n");
116
113
  }
117
114
  function renderFooter(state) {
118
115
  if (state.activeTab === "review") {
119
- return "← → switch tab • ↑ ↓ move • enter confirm action • q quit";
116
+ return renderKeycaps([
117
+ { key: "LEFT/RIGHT", label: "switch tab" },
118
+ { key: "UP/DOWN", label: "move" },
119
+ { key: "ENTER", label: "confirm action" },
120
+ { key: "Q", label: "quit" }
121
+ ]);
120
122
  }
121
- return "← → switch tab • ↑ ↓ move • space/enter toggle • a toggle all • q quit";
123
+ return renderKeycaps([
124
+ { key: "LEFT/RIGHT", label: "switch tab" },
125
+ { key: "UP/DOWN", label: "move" },
126
+ { key: "SPACE", label: "toggle" },
127
+ { key: "A", label: "toggle all" },
128
+ { key: "Q", label: "quit" }
129
+ ]);
122
130
  }
123
131
  function moveTab(state, delta) {
124
132
  const index = TAB_ORDER.indexOf(state.activeTab);
@@ -159,90 +167,35 @@ export async function runProjectDocsWizard(catalog) {
159
167
  let lastTabSwitchAt = 0;
160
168
  let lastMoveAt = 0;
161
169
  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
- });
170
+ const { screen, headerBox, tabsBox, titleBox, listBox, detailBox, footerBox } = createTabbedLayout();
230
171
  function cleanup() {
231
172
  screen.destroy();
232
173
  }
233
174
  function render() {
175
+ const currentStep = TAB_ORDER.indexOf(state.activeTab) + 1;
234
176
  const stepTitle = state.activeTab === "skills" ? "Select skills" : "Review selections";
235
- headerBox.setContent(renderHeader());
177
+ const stepDescription = state.activeTab === "skills"
178
+ ? "Choose the project docs packages to copy into this repository."
179
+ : "Double-check the selected docs before installation starts.";
180
+ const stepStatus = state.activeTab === "skills"
181
+ ? `${state.selectedSkills.size} selected`
182
+ : state.notice || "Ready for confirmation";
183
+ headerBox.setContent(renderBannerHeader("Install project docs", "Choose skills first, then confirm from review.", [
184
+ { label: `${state.selectedSkills.size} selected`, tone: "accent" },
185
+ { label: "Current repository", tone: "muted" }
186
+ ]));
236
187
  tabsBox.setContent(renderTabs(state));
237
- titleBox.setContent(`{bold}${stepTitle}{/bold}`);
188
+ titleBox.setContent(renderStepSummary({
189
+ step: `STEP ${currentStep}/${TAB_ORDER.length}`,
190
+ title: stepTitle,
191
+ description: stepDescription,
192
+ status: stepStatus
193
+ }));
238
194
  syncListSelection(listBox, state, catalog);
239
195
  detailBox.setContent(renderDetailBody(state, catalog));
240
196
  footerBox.setContent(renderFooter(state));
241
197
  screen.render();
242
198
  }
243
- function canRun(lastAt, thresholdMs) {
244
- return Date.now() - lastAt >= thresholdMs;
245
- }
246
199
  function finishBackToMenu() {
247
200
  cleanup();
248
201
  resolve({ backToMenu: true });
@@ -258,7 +211,7 @@ export async function runProjectDocsWizard(catalog) {
258
211
  reject(new Error(message));
259
212
  }
260
213
  function handleToggleOrConfirm() {
261
- if (!canRun(lastToggleAt, 120)) {
214
+ if (!canRun(lastToggleAt, DEBOUNCE_SELECT_MS)) {
262
215
  return;
263
216
  }
264
217
  lastToggleAt = Date.now();
@@ -305,7 +258,7 @@ export async function runProjectDocsWizard(catalog) {
305
258
  render();
306
259
  }
307
260
  screen.key(["left"], () => {
308
- if (!canRun(lastTabSwitchAt, 120)) {
261
+ if (!canRun(lastTabSwitchAt, DEBOUNCE_SELECT_MS)) {
309
262
  return;
310
263
  }
311
264
  lastTabSwitchAt = Date.now();
@@ -313,7 +266,7 @@ export async function runProjectDocsWizard(catalog) {
313
266
  render();
314
267
  });
315
268
  screen.key(["right"], () => {
316
- if (!canRun(lastTabSwitchAt, 120)) {
269
+ if (!canRun(lastTabSwitchAt, DEBOUNCE_SELECT_MS)) {
317
270
  return;
318
271
  }
319
272
  lastTabSwitchAt = Date.now();
@@ -321,7 +274,7 @@ export async function runProjectDocsWizard(catalog) {
321
274
  render();
322
275
  });
323
276
  screen.key(["up"], () => {
324
- if (!canRun(lastMoveAt, 100)) {
277
+ if (!canRun(lastMoveAt, DEBOUNCE_MOVE_MS)) {
325
278
  return;
326
279
  }
327
280
  lastMoveAt = Date.now();
@@ -329,7 +282,7 @@ export async function runProjectDocsWizard(catalog) {
329
282
  render();
330
283
  });
331
284
  screen.key(["down"], () => {
332
- if (!canRun(lastMoveAt, 100)) {
285
+ if (!canRun(lastMoveAt, DEBOUNCE_MOVE_MS)) {
333
286
  return;
334
287
  }
335
288
  lastMoveAt = Date.now();