@minhluudev/ai-tools 1.0.2 → 1.0.4

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/dist/src/cli.js CHANGED
@@ -4,25 +4,113 @@ import { createGitHubClient } from "./lib/github.js";
4
4
  import { detectExistingTargets, installPlannedItems, installProjectDocsItems, planInstallations, planProjectDocsInstallations, resolveInstallRoot, resolveProjectDocsRoot } from "./lib/install.js";
5
5
  import { loadProjectDocsCatalog } from "./lib/project-docs-catalog.js";
6
6
  import { loadSelectionCatalog, resolveSelectionItems } from "./lib/selection-catalog.js";
7
- import { blessedSelect } from "./lib/tui-utils.js";
7
+ import { blessedConfirm } from "./lib/tui-utils.js";
8
8
  import { runEntryMenu } from "./lib/tui-entry-menu.js";
9
9
  import { runProjectDocsWizard } from "./lib/tui-project-docs.js";
10
10
  import { runTabbedWizard } from "./lib/tui-wizard.js";
11
+ const ANSI = {
12
+ reset: "\u001B[0m",
13
+ bold: "\u001B[1m",
14
+ dim: "\u001B[2m",
15
+ cyan: "\u001B[36m",
16
+ green: "\u001B[32m",
17
+ yellow: "\u001B[33m",
18
+ gray: "\u001B[90m"
19
+ };
20
+ function paint(text, color, bold = false) {
21
+ return `${bold ? ANSI.bold : ""}${color}${text}${ANSI.reset}`;
22
+ }
23
+ function stripAnsi(value) {
24
+ return value.replace(/\u001B\[[0-9;]*m/g, "");
25
+ }
26
+ function visibleLength(value) {
27
+ return stripAnsi(value).length;
28
+ }
29
+ function wrapText(value, width) {
30
+ if (value.length === 0) {
31
+ return [""];
32
+ }
33
+ const words = value.split(" ");
34
+ const lines = [];
35
+ let current = "";
36
+ for (const word of words) {
37
+ const candidate = current.length === 0 ? word : `${current} ${word}`;
38
+ if (candidate.length <= width) {
39
+ current = candidate;
40
+ continue;
41
+ }
42
+ if (current.length > 0) {
43
+ lines.push(current);
44
+ current = "";
45
+ }
46
+ if (word.length <= width) {
47
+ current = word;
48
+ continue;
49
+ }
50
+ let remainder = word;
51
+ while (remainder.length > width) {
52
+ lines.push(remainder.slice(0, width));
53
+ remainder = remainder.slice(width);
54
+ }
55
+ current = remainder;
56
+ }
57
+ if (current.length > 0) {
58
+ lines.push(current);
59
+ }
60
+ return lines.length > 0 ? lines : [""];
61
+ }
62
+ function buildPanel(title, lines, accent = "info") {
63
+ const accentColor = {
64
+ info: ANSI.cyan,
65
+ success: ANSI.green,
66
+ warning: ANSI.yellow,
67
+ muted: ANSI.gray
68
+ }[accent];
69
+ const maxWidth = Math.min(process.stdout.columns ?? 92, 100);
70
+ const innerWidth = Math.max(48, Math.min(maxWidth - 4, Math.max(visibleLength(title) + 14, ...lines.map((line) => Math.min(stripAnsi(line).length, maxWidth - 6))) + 2));
71
+ const wrappedLines = lines.flatMap((line) => {
72
+ if (line.length === 0) {
73
+ return [""];
74
+ }
75
+ return wrapText(line, innerWidth);
76
+ });
77
+ const header = paint(`[ AI TOOLS ] ${title}`, accentColor, true);
78
+ const border = `+${"-".repeat(innerWidth + 2)}+`;
79
+ return [
80
+ "",
81
+ border,
82
+ `| ${header}${" ".repeat(Math.max(0, innerWidth - visibleLength(header)))} |`,
83
+ ...wrappedLines.map((line) => `| ${line}${" ".repeat(Math.max(0, innerWidth - visibleLength(line)))} |`),
84
+ border
85
+ ].join("\n");
86
+ }
11
87
  function printSectionHeader(title, subtitle) {
12
- const lines = [
13
- `AI-TOOLS :: ${title}`,
14
- subtitle
15
- ];
16
- const width = Math.max(...lines.map((line) => line.length)) + 4;
17
- const border = "+".padEnd(width - 1, "-") + "+";
88
+ console.log(buildPanel(title, [subtitle], "info"));
18
89
  console.log("");
19
- console.log(border);
20
- for (const line of lines) {
21
- console.log(`| ${line.padEnd(width - 4, " ")} |`);
22
- }
23
- console.log(border);
90
+ }
91
+ function printLabeledRows(title, rows, accent = "muted") {
92
+ const labelWidth = Math.max(...rows.map(([label]) => label.length));
93
+ const lines = rows.map(([label, value]) => `${paint(label.padEnd(labelWidth, " "), ANSI.gray, true)} ${value}`);
94
+ console.log(buildPanel(title, lines, accent));
24
95
  console.log("");
25
96
  }
97
+ function printBulletPanel(title, items, accent = "muted") {
98
+ console.log(buildPanel(title, items.map((item) => `- ${item}`), accent));
99
+ console.log("");
100
+ }
101
+ function printStatusLine(label, message, tone = "info") {
102
+ const color = {
103
+ info: ANSI.cyan,
104
+ success: ANSI.green,
105
+ warning: ANSI.yellow,
106
+ muted: ANSI.gray
107
+ }[tone];
108
+ const badge = paint(`[${label}]`, color, true);
109
+ console.log(`${badge} ${message}`);
110
+ }
111
+ function formatInstallProgressLine(input) {
112
+ return `${input.id} ${paint(`[${input.sourceBranch}]`, ANSI.gray)} -> ${input.targetPath}`;
113
+ }
26
114
  function printSkillSelectionSummary(input) {
27
115
  const selectedSkillLabels = input.selectionCatalog.skills
28
116
  .filter((skill) => input.selectedSkills.includes(skill.id))
@@ -30,18 +118,20 @@ function printSkillSelectionSummary(input) {
30
118
  const selectedGroupLabels = input.selectionCatalog.groups
31
119
  .filter((group) => input.selectedGroups.includes(group.id))
32
120
  .map((group) => group.label);
33
- console.log("Selected items:");
34
- console.log(`- Skills: ${selectedSkillLabels.length ? selectedSkillLabels.join(", ") : "none"}`);
121
+ const rows = [
122
+ ["Skills", selectedSkillLabels.length ? selectedSkillLabels.join(", ") : "none"]
123
+ ];
35
124
  if (selectedGroupLabels.length > 0) {
36
- console.log(`- Groups: ${selectedGroupLabels.join(", ")}`);
125
+ rows.push(["Groups", selectedGroupLabels.join(", ")]);
37
126
  }
38
- console.log(`- Locations: ${input.locations.length ? input.locations.join(", ") : "none"}`);
39
- console.log(`- Agents: ${input.agents.length ? input.agents.join(", ") : "none"}`);
127
+ rows.push(["Locations", input.locations.length ? input.locations.join(", ") : "none"], ["Agents", input.agents.length ? input.agents.join(", ") : "none"]);
128
+ printLabeledRows("Selected items", rows);
40
129
  }
41
130
  function printProjectDocsSelectionSummary(input) {
42
- console.log("Selected items:");
43
- console.log(`- Skills: ${input.selectedSkills.map((skill) => skill.label).join(", ")}`);
44
- console.log(`- Install root: ${resolveProjectDocsRoot(input.cwd)}`);
131
+ printLabeledRows("Selected items", [
132
+ ["Skills", input.selectedSkills.map((skill) => skill.label).join(", ")],
133
+ ["Install root", resolveProjectDocsRoot(input.cwd)]
134
+ ]);
45
135
  }
46
136
  export async function runCli() {
47
137
  while (true) {
@@ -51,7 +141,7 @@ export async function runCli() {
51
141
  }
52
142
  if (entryAction === "install-libs") {
53
143
  printSectionHeader("Install libs for AI", "Shared AI libraries and tooling are not implemented yet.");
54
- console.log("Install libs for AI is not implemented yet.");
144
+ printStatusLine("todo", "Install libs for AI is not implemented yet.", "warning");
55
145
  return;
56
146
  }
57
147
  if (entryAction === "install-project-docs") {
@@ -66,27 +156,22 @@ export async function runCli() {
66
156
  selectedSkills: projectDocsResult.selectedSkills,
67
157
  cwd: process.cwd()
68
158
  });
69
- console.log("Resolving selected sources...");
159
+ printStatusLine("resolve", "Resolving selected sources...");
70
160
  const client = createGitHubClient(config.github);
71
161
  const plannedItems = planProjectDocsInstallations({
72
162
  skills: projectDocsResult.selectedSkills,
73
163
  cwd: process.cwd()
74
164
  });
75
- console.log("");
76
- console.log("Installing...");
165
+ printStatusLine("install", "Installing selected project docs...");
77
166
  const results = await installProjectDocsItems({
78
167
  plannedItems,
79
168
  client,
80
169
  overwriteExisting: false,
81
170
  onProgress(item) {
82
- console.log(`- ${item.id} from ${item.sourceBranch} -> ${item.targetPath}`);
171
+ printStatusLine("write", formatInstallProgressLine(item), "muted");
83
172
  }
84
173
  });
85
- console.log("");
86
- console.log("Install complete");
87
- for (const result of results) {
88
- console.log(`- ${result.id}: ${result.targetPath}`);
89
- }
174
+ printBulletPanel(`Install complete (${results.length})`, results.map((result) => `${result.id} -> ${result.targetPath}`), "success");
90
175
  return;
91
176
  }
92
177
  // install-skills
@@ -102,7 +187,7 @@ export async function runCli() {
102
187
  const { selectedSkills, selectedGroups, locations, agents } = selectionResult;
103
188
  printSectionHeader("Install agent skills", "Preparing selected skills for resolution and installation.");
104
189
  printSkillSelectionSummary({ selectionCatalog, selectedSkills, selectedGroups, locations, agents });
105
- console.log("Resolving selected sources...");
190
+ printStatusLine("resolve", "Resolving selected sources...");
106
191
  const client = createGitHubClient(config.github);
107
192
  const finalItems = await resolveSelectionItems({
108
193
  client,
@@ -132,47 +217,30 @@ export async function runCli() {
132
217
  }
133
218
  }
134
219
  if (skipped.length > 0) {
135
- console.log("");
136
- console.log("Skipped (agent not supported by skill):");
137
- for (const line of skipped) {
138
- console.log(line);
139
- }
220
+ printBulletPanel("Skipped targets", skipped.map((line) => line.trimStart().replace(/^- /, "")), "warning");
140
221
  }
141
222
  const existingTargets = await detectExistingTargets(plannedItems);
142
223
  let overwriteExisting = false;
143
224
  if (existingTargets.length > 0) {
144
- console.log("");
145
- console.log("Existing targets detected:");
146
- for (const item of existingTargets) {
147
- console.log(`- ${item.id}: ${item.targetPath}`);
148
- }
149
- const answer = await blessedSelect({
225
+ printBulletPanel("Existing targets detected", existingTargets.map((item) => `${item.id} -> ${item.targetPath}`), "warning");
226
+ overwriteExisting = await blessedConfirm({
150
227
  message: "Overwrite all existing targets?",
151
- choices: [
152
- { value: "no", label: "No — keep existing files" },
153
- { value: "yes", label: "Yes — overwrite all" }
154
- ]
228
+ description: "Choose Yes to replace all detected targets, or No to cancel the installation."
155
229
  });
156
- overwriteExisting = answer === "yes";
157
230
  if (!overwriteExisting) {
158
231
  throw new Error("Installation cancelled because existing targets would be overwritten.");
159
232
  }
160
233
  }
161
- console.log("");
162
- console.log("Installing...");
234
+ printStatusLine("install", "Installing selected agent skills...");
163
235
  const results = await installPlannedItems({
164
236
  plannedItems,
165
237
  client,
166
238
  overwriteExisting,
167
239
  onProgress(item) {
168
- console.log(`- ${item.id} from ${item.sourceBranch} -> ${item.targetPath}`);
240
+ printStatusLine("write", formatInstallProgressLine(item), "muted");
169
241
  }
170
242
  });
171
- console.log("");
172
- console.log("Install complete");
173
- for (const result of results) {
174
- console.log(`- ${result.id}: ${result.targetPath}`);
175
- }
243
+ printBulletPanel(`Install complete (${results.length})`, results.map((result) => `${result.id} -> ${result.targetPath}`), "success");
176
244
  return;
177
245
  }
178
246
  }
@@ -1,30 +1,37 @@
1
1
  import blessed from "blessed";
2
- import { canRun, DEBOUNCE_MOVE_MS, DEBOUNCE_SELECT_MS, renderBannerHeader } from "./tui-utils.js";
2
+ import { canRun, DEBOUNCE_MOVE_MS, DEBOUNCE_SELECT_MS, renderBannerHeader, renderKeycaps, renderListRow } from "./tui-utils.js";
3
3
  const MENU_ITEMS = [
4
4
  {
5
5
  id: "install-skills",
6
6
  label: "Install agent skills",
7
- 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"
8
9
  },
9
10
  {
10
11
  id: "install-project-docs",
11
12
  label: "Install project docs",
12
- description: "Install project documentation templates and guidance."
13
+ description: "Copy selected project docs and workflow templates into the current repository.",
14
+ meta: "Current repo"
13
15
  },
14
16
  {
15
17
  id: "install-libs",
16
18
  label: "Install libs for AI",
17
- description: "Install shared AI libraries and tooling."
19
+ description: "Install shared AI libraries and tooling.",
20
+ meta: "Coming soon"
18
21
  },
19
22
  {
20
23
  id: "cancel",
21
24
  label: "Cancel",
22
- description: "Exit without running any installer."
25
+ description: "Exit without running any installer.",
26
+ meta: "Safe exit"
23
27
  }
24
28
  ];
25
29
  function renderItem(item, isActive) {
26
- const text = `${isActive ? "> " : " "}${item.label}`;
27
- 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
+ });
28
35
  }
29
36
  export async function runEntryMenu() {
30
37
  return new Promise((resolve) => {
@@ -34,28 +41,49 @@ export async function runEntryMenu() {
34
41
  const screen = blessed.screen({
35
42
  smartCSR: true,
36
43
  fullUnicode: true,
44
+ dockBorders: true,
37
45
  title: "ai-tools"
38
46
  });
39
47
  const headerBox = blessed.box({
40
48
  parent: screen,
41
- top: 0,
42
- left: 0,
43
- width: "100%",
44
- height: 4,
45
- 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
+ }
46
65
  });
47
66
  const listBox = blessed.list({
48
67
  parent: screen,
49
- top: 6,
50
- left: 0,
51
- width: "100%",
52
- height: 6,
68
+ top: 8,
69
+ left: 2,
70
+ width: "100%-4",
71
+ height: 8,
53
72
  tags: true,
54
73
  keys: false,
55
74
  vi: false,
56
75
  mouse: false,
57
76
  interactive: false,
77
+ border: { type: "line" },
78
+ label: " workflows ",
79
+ padding: {
80
+ left: 1,
81
+ right: 1
82
+ },
58
83
  style: {
84
+ border: {
85
+ fg: "blue"
86
+ },
59
87
  selected: {
60
88
  bold: true,
61
89
  fg: "black",
@@ -65,30 +93,58 @@ export async function runEntryMenu() {
65
93
  });
66
94
  const detailBox = blessed.box({
67
95
  parent: screen,
68
- top: 14,
69
- left: 0,
70
- width: "100%",
71
- height: 3,
96
+ top: 17,
97
+ left: 2,
98
+ width: "100%-4",
99
+ height: 7,
72
100
  tags: true,
73
- 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
+ }
74
113
  });
75
114
  const footerBox = blessed.box({
76
115
  parent: screen,
77
116
  bottom: 0,
78
- left: 0,
79
- width: "100%",
117
+ left: 2,
118
+ width: "100%-4",
80
119
  height: 1,
81
- tags: true
120
+ tags: true,
121
+ style: {
122
+ fg: "gray"
123
+ }
82
124
  });
83
125
  function cleanup() {
84
126
  screen.destroy();
85
127
  }
86
128
  function render() {
87
- headerBox.setContent(renderBannerHeader("Main menu", "Choose the workflow you want to run."));
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
+ ]));
88
134
  listBox.setItems(MENU_ITEMS.map((item, index) => renderItem(item, index === cursor)));
89
135
  listBox.select(cursor);
90
- detailBox.setContent(`{bold}Details{/bold}\n${MENU_ITEMS[cursor].description}`);
91
- 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
+ ]));
92
148
  screen.render();
93
149
  }
94
150
  screen.key(["up"], () => {
@@ -1,4 +1,4 @@
1
- import { canRun, createTabbedLayout, DEBOUNCE_MOVE_MS, DEBOUNCE_SELECT_MS, renderBannerHeader } from "./tui-utils.js";
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 {
@@ -43,10 +43,11 @@ function currentTabItems(state, catalog) {
43
43
  ];
44
44
  }
45
45
  function renderTabs(state) {
46
- return TAB_ORDER.map((tab) => {
47
- const label = tab.charAt(0).toUpperCase() + tab.slice(1);
48
- return state.activeTab === tab ? `{inverse}${label}{/inverse}` : label;
49
- }).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
+ })));
50
51
  }
51
52
  function isItemSelected(item, state) {
52
53
  if (item.kind === "skills") {
@@ -67,13 +68,20 @@ function toggleItem(item, state) {
67
68
  state.reviewAction = item.id;
68
69
  }
69
70
  function formatListItem(item, state, isCursorRow) {
70
- const cursorPrefix = isCursorRow ? "> " : " ";
71
- const wrapCursorRow = (value) => isCursorRow ? `{black-fg}{yellow-bg}${value}{/yellow-bg}{/black-fg}` : value;
72
71
  if (item.kind === "review") {
73
- 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
+ });
74
78
  }
75
- const checked = isItemSelected(item, state) ? "x" : " ";
76
- return wrapCursorRow(`${cursorPrefix}[${checked}] ${item.label}`);
79
+ return renderListRow({
80
+ active: isCursorRow,
81
+ selected: isItemSelected(item, state),
82
+ label: item.label,
83
+ meta: item.description
84
+ });
77
85
  }
78
86
  function renderReviewSummary(state, catalog) {
79
87
  const selectedSkills = catalog.skills
@@ -81,7 +89,7 @@ function renderReviewSummary(state, catalog) {
81
89
  .map((skill) => skill.label);
82
90
  const lines = [
83
91
  "{bold}Selections{/bold}",
84
- `Skills: ${selectedSkills.length ? selectedSkills.join(", ") : "none"}`
92
+ `Skills ${selectedSkills.length ? selectedSkills.join(", ") : "none"}`
85
93
  ];
86
94
  if (state.notice) {
87
95
  lines.push("", `{yellow-fg}${state.notice}{/yellow-fg}`);
@@ -99,15 +107,26 @@ function renderDetailBody(state, catalog) {
99
107
  lines.push(`{yellow-fg}${state.notice}{/yellow-fg}`, "");
100
108
  }
101
109
  if (current) {
102
- 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);
103
111
  }
104
112
  return lines.join("\n");
105
113
  }
106
114
  function renderFooter(state) {
107
115
  if (state.activeTab === "review") {
108
- 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
+ ]);
109
122
  }
110
- 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
+ ]);
111
130
  }
112
131
  function moveTab(state, delta) {
113
132
  const index = TAB_ORDER.indexOf(state.activeTab);
@@ -153,10 +172,25 @@ export async function runProjectDocsWizard(catalog) {
153
172
  screen.destroy();
154
173
  }
155
174
  function render() {
175
+ const currentStep = TAB_ORDER.indexOf(state.activeTab) + 1;
156
176
  const stepTitle = state.activeTab === "skills" ? "Select skills" : "Review selections";
157
- headerBox.setContent(renderBannerHeader("Install project docs", "Choose skills first, then confirm from review."));
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
+ ]));
158
187
  tabsBox.setContent(renderTabs(state));
159
- 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
+ }));
160
194
  syncListSelection(listBox, state, catalog);
161
195
  detailBox.setContent(renderDetailBody(state, catalog));
162
196
  footerBox.setContent(renderFooter(state));
@@ -7,36 +7,125 @@ export function canRun(lastAt, thresholdMs) {
7
7
  export function selectionArray(items) {
8
8
  return [...items];
9
9
  }
10
- export function renderBannerHeader(title, subtitle) {
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");
11
31
  return [
12
- "{black-fg}{cyan-bg} AI-TOOLS {/cyan-bg}{/black-fg}",
13
- `{bold}${title}{/bold}`,
32
+ `{bold}${renderChip("AI TOOLS")} ${title}{/bold}`,
14
33
  `{gray-fg}${subtitle}{/gray-fg}`,
15
- "{cyan-fg}------------------------------------------------------------------------{/cyan-fg}"
34
+ chipLine,
35
+ "{cyan-fg}======================================================================{/cyan-fg}"
16
36
  ].join("\n");
17
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
+ }
18
80
  export async function blessedSelect(input) {
19
81
  return new Promise((resolve) => {
20
82
  let cursor = 0;
21
- const screen = blessed.screen({ smartCSR: true, fullUnicode: true, title: "ai-tools" });
83
+ const screen = blessed.screen({
84
+ smartCSR: true,
85
+ fullUnicode: true,
86
+ dockBorders: true,
87
+ title: "ai-tools"
88
+ });
22
89
  const promptBox = blessed.box({
23
90
  parent: screen,
24
91
  top: "center",
25
92
  left: "center",
26
- width: 50,
27
- height: input.choices.length + 4,
93
+ width: "70%",
94
+ height: Math.max(input.choices.length + 8, 10),
28
95
  border: { type: "line" },
29
- tags: true
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
+ }
30
109
  });
31
110
  function render() {
32
111
  const lines = [
33
- `{bold}${input.message}{/bold}`,
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
+ ]),
34
120
  ""
35
121
  ];
36
122
  for (let i = 0; i < input.choices.length; i++) {
37
123
  const choice = input.choices[i];
38
- const row = `${i === cursor ? "> " : " "}${choice.label}`;
39
- lines.push(i === cursor ? `{black-fg}{yellow-bg}${row}{/yellow-bg}{/black-fg}` : row);
124
+ lines.push(renderListRow({
125
+ active: i === cursor,
126
+ label: choice.label,
127
+ meta: choice.description
128
+ }));
40
129
  }
41
130
  promptBox.setContent(lines.join("\n"));
42
131
  screen.render();
@@ -61,43 +150,149 @@ export async function blessedSelect(input) {
61
150
  render();
62
151
  });
63
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
+ }
64
225
  export function createTabbedLayout() {
65
226
  const screen = blessed.screen({
66
227
  smartCSR: true,
67
228
  fullUnicode: true,
229
+ dockBorders: true,
68
230
  title: "ai-tools"
69
231
  });
70
232
  const headerBox = blessed.box({
71
233
  parent: screen,
72
- top: 0,
73
- left: 0,
74
- width: "100%",
75
- height: 4,
234
+ top: 1,
235
+ left: 2,
236
+ width: "100%-4",
237
+ height: 6,
76
238
  tags: true,
77
- wrap: 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
+ }
78
251
  });
79
252
  const tabsBox = blessed.box({
80
253
  parent: screen,
81
- top: 4,
82
- left: 0,
83
- width: "100%",
84
- height: 1,
85
- tags: true
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
+ }
86
270
  });
87
271
  const titleBox = blessed.box({
88
272
  parent: screen,
89
- top: 6,
90
- left: 0,
91
- width: "100%",
92
- height: 1,
93
- tags: true
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
+ }
94
289
  });
95
290
  const listBox = blessed.list({
96
291
  parent: screen,
97
- top: 8,
98
- left: 0,
99
- width: "100%",
100
- height: "100%-13",
292
+ top: 15,
293
+ left: 2,
294
+ width: "100%-4",
295
+ height: "100%-23",
101
296
  tags: true,
102
297
  keys: false,
103
298
  vi: false,
@@ -105,30 +300,62 @@ export function createTabbedLayout() {
105
300
  interactive: false,
106
301
  scrollable: true,
107
302
  alwaysScroll: true,
303
+ border: { type: "line" },
304
+ label: " options ",
305
+ padding: {
306
+ left: 1,
307
+ right: 1
308
+ },
108
309
  style: {
310
+ border: {
311
+ fg: "blue"
312
+ },
109
313
  selected: {
110
314
  bold: true,
111
315
  fg: "black",
112
316
  bg: "yellow"
113
317
  }
318
+ },
319
+ scrollbar: {
320
+ ch: " ",
321
+ track: {
322
+ bg: "gray"
323
+ },
324
+ style: {
325
+ bg: "cyan"
326
+ }
114
327
  }
115
328
  });
116
329
  const detailBox = blessed.box({
117
330
  parent: screen,
118
- left: 0,
119
- bottom: 1,
120
- width: "100%",
121
- height: 4,
331
+ left: 2,
332
+ bottom: 2,
333
+ width: "100%-4",
334
+ height: 5,
122
335
  tags: true,
123
- wrap: 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
+ }
124
348
  });
125
349
  const footerBox = blessed.box({
126
350
  parent: screen,
127
351
  bottom: 0,
128
- left: 0,
129
- width: "100%",
352
+ left: 2,
353
+ width: "100%-4",
130
354
  height: 1,
131
- tags: true
355
+ tags: true,
356
+ style: {
357
+ fg: "gray"
358
+ }
132
359
  });
133
360
  return { screen, headerBox, tabsBox, titleBox, listBox, detailBox, footerBox };
134
361
  }
@@ -1,5 +1,5 @@
1
1
  import { resolveInstallRoot } from "./install.js";
2
- import { canRun, createTabbedLayout, DEBOUNCE_MOVE_MS, DEBOUNCE_SELECT_MS, renderBannerHeader, selectionArray } from "./tui-utils.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
4
  function buildInitialState() {
5
5
  return {
@@ -125,19 +125,35 @@ function toggleItem(item, state) {
125
125
  state.reviewAction = item.id;
126
126
  }
127
127
  function renderTabs(state) {
128
- return TAB_ORDER.map((tab) => {
129
- const label = tab.charAt(0).toUpperCase() + tab.slice(1);
130
- return state.activeTab === tab ? `{inverse}${label}{/inverse}` : label;
131
- }).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
+ })));
132
139
  }
133
- function formatListItem(item, state, isCursorRow) {
134
- const cursorPrefix = isCursorRow ? "> " : " ";
135
- const wrapCursorRow = (value) => isCursorRow ? `{black-fg}{yellow-bg}${value}{/yellow-bg}{/black-fg}` : value;
140
+ function formatListItem(item, state, isCursorRow, index) {
136
141
  if (item.kind === "review") {
137
- 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
+ });
138
149
  }
139
- const checked = isItemSelected(item, state) ? "x" : " ";
140
- return wrapCursorRow(`${cursorPrefix}[${checked}] ${item.label}`);
150
+ return renderListRow({
151
+ active: isCursorRow,
152
+ selected: isItemSelected(item, state),
153
+ label: item.label,
154
+ meta: item.description,
155
+ index
156
+ });
141
157
  }
142
158
  function renderReviewSummary(state, selectionCatalog) {
143
159
  const selectedSkillLabels = selectionCatalog.skills
@@ -150,15 +166,15 @@ function renderReviewSummary(state, selectionCatalog) {
150
166
  const selectedAgents = selectionArray(state.selectedAgents);
151
167
  const lines = [
152
168
  "{bold}Selections{/bold}",
153
- `Skills: ${selectedSkillLabels.length ? selectedSkillLabels.join(", ") : "none"}`,
154
- `Locations: ${selectedLocations.length ? selectedLocations.join(", ") : "none"}`,
155
- `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"}`
156
172
  ];
157
173
  if (selectedGroupLabels.length > 0) {
158
- lines.splice(2, 0, `Groups: ${selectedGroupLabels.join(", ")}`);
174
+ lines.splice(2, 0, `Groups ${selectedGroupLabels.join(", ")}`);
159
175
  }
160
176
  if (selectedLocations.length > 0 && selectedAgents.length > 0) {
161
- lines.push("", "{bold}Targets{/bold}");
177
+ lines.push("", "{bold}Resolved targets{/bold}");
162
178
  for (const agent of selectedAgents) {
163
179
  for (const location of selectedLocations) {
164
180
  lines.push(`- ${agent} + ${location}: ${resolveInstallRoot({ agent, location, cwd: process.cwd() })}`);
@@ -181,15 +197,27 @@ function renderDetailBody(state, selectionCatalog) {
181
197
  lines.push(`{yellow-fg}${state.notice}{/yellow-fg}`, "");
182
198
  }
183
199
  if (current) {
184
- 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);
185
202
  }
186
203
  return lines.join("\n");
187
204
  }
188
205
  function renderFooter(state) {
189
206
  if (state.activeTab === "review") {
190
- 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
+ ]);
191
213
  }
192
- 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
+ ]);
193
221
  }
194
222
  function setNotice(state, message) {
195
223
  state.notice = message;
@@ -240,7 +268,7 @@ function syncListSelection(listBox, state, selectionCatalog) {
240
268
  const maxIndex = Math.max(items.length - 1, 0);
241
269
  const cursor = Math.min(state.listCursor[state.activeTab], maxIndex);
242
270
  state.listCursor[state.activeTab] = cursor;
243
- listBox.setItems(items.map((item, index) => formatListItem(item, state, index === cursor)));
271
+ listBox.setItems(items.map((item, index) => formatListItem(item, state, index === cursor, index)));
244
272
  listBox.select(cursor);
245
273
  listBox.scrollTo(cursor);
246
274
  }
@@ -274,15 +302,37 @@ export async function runTabbedWizard(selectionCatalog, headerTitle = "Install a
274
302
  });
275
303
  }
276
304
  function render() {
305
+ const currentStep = TAB_ORDER.indexOf(state.activeTab) + 1;
277
306
  const stepTitle = {
278
307
  skills: "Select skills",
279
308
  locations: "Select installation locations",
280
309
  agents: "Select agents",
281
310
  review: "Review selections"
282
311
  }[state.activeTab];
283
- headerBox.setContent(renderBannerHeader(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
+ ]));
284
329
  tabsBox.setContent(renderTabs(state));
285
- titleBox.setContent(`{bold}${stepTitle}{/bold}`);
330
+ titleBox.setContent(renderStepSummary({
331
+ step: `STEP ${currentStep}/${TAB_ORDER.length}`,
332
+ title: stepTitle,
333
+ description: stepDescription,
334
+ status: stepStatus
335
+ }));
286
336
  syncListSelection(listBox, state, selectionCatalog);
287
337
  detailBox.setContent(renderDetailBody(state, selectionCatalog));
288
338
  footerBox.setContent(renderFooter(state));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minhluudev/ai-tools",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "CLI to install AI skills from GitHub branches into Codex and Claude.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,13 @@
1
1
  {
2
2
  "version": 1,
3
3
  "skills": [
4
+ {
5
+ "id": "bugfix",
6
+ "label": "Bugfix",
7
+ "description": "Folder: bugfix",
8
+ "sourceBranch": "agent-skills",
9
+ "sourcePath": "bugfix"
10
+ },
4
11
  {
5
12
  "id": "git-engineering-workflow",
6
13
  "label": "Git engineering workflow",