@minhluudev/ai-tools 1.0.1 → 1.0.2
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/README.md +16 -96
- package/dist/src/bin/ai-tools.js +1 -1
- package/dist/src/cli.js +45 -95
- package/dist/src/lib/catalog.js +5 -2
- package/dist/src/lib/github.js +2 -2
- package/dist/src/lib/install.js +20 -23
- package/dist/src/lib/prompts.js +3 -13
- package/dist/src/lib/selection-catalog.js +17 -7
- package/dist/src/lib/tui-entry-menu.js +5 -15
- package/dist/src/lib/tui-project-docs.js +8 -89
- package/dist/src/lib/tui-utils.js +134 -0
- package/dist/src/lib/tui-wizard.js +28 -135
- package/package.json +1 -1
- package/dist/src/lib/args.js +0 -98
package/README.md
CHANGED
|
@@ -1,115 +1,35 @@
|
|
|
1
1
|
# ai-tools
|
|
2
2
|
|
|
3
|
-
`@minhluudev/ai-tools` is
|
|
3
|
+
`@minhluudev/ai-tools` is a personal CLI for installing the AI tools, agent skills, and project docs that I use in my own workflow.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install -g @minhluudev/ai-tools
|
|
9
|
-
ai-tools install
|
|
10
9
|
```
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
Use `← →` to switch tabs, `↑ ↓` to move within a tab, `space` or `enter` to toggle options, and `q` or `esc` to cancel. On the `Review` tab, `enter` confirms the highlighted action.
|
|
11
|
+
## Usage
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
```bash
|
|
14
|
+
ai-tools
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Main menu:
|
|
16
18
|
|
|
17
19
|
1. `Install agent skills`
|
|
18
20
|
2. `Install project docs`
|
|
19
21
|
3. `Install libs for AI`
|
|
20
22
|
4. `Cancel`
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
`Install libs for AI` is still a placeholder until that flow is implemented.
|
|
24
|
-
|
|
25
|
-
## Supported Flow
|
|
26
|
-
|
|
27
|
-
The interactive installer asks for:
|
|
28
|
-
|
|
29
|
-
1. Individual skills from the local selection catalog packaged with the CLI
|
|
30
|
-
2. Installation locations: `global`, `local`, or both
|
|
31
|
-
3. Target agents: `codex`, `claude`, or both
|
|
32
|
-
4. A review tab where you can confirm or cancel after navigating back and forth with the tab bar
|
|
33
|
-
|
|
34
|
-
The project docs installer asks for:
|
|
35
|
-
|
|
36
|
-
1. Skills from the local `project-docs-catalog.json`
|
|
37
|
-
2. A `Review` tab where you can confirm, go back to the main menu, or cancel
|
|
38
|
-
3. Copy the contents inside the selected folder directly into the current working directory
|
|
24
|
+
Controls:
|
|
39
25
|
|
|
40
|
-
|
|
26
|
+
- `← →` switch tabs
|
|
27
|
+
- `↑ ↓` move
|
|
28
|
+
- `space` or `enter` select
|
|
29
|
+
- `q` or `esc` cancel
|
|
41
30
|
|
|
42
|
-
|
|
31
|
+
`Install agent skills`
|
|
32
|
+
- installs selected skills into `~/.codex`, `~/.claude`, `./.codex`, or `./.claude`
|
|
43
33
|
|
|
44
|
-
|
|
45
|
-
-
|
|
46
|
-
|
|
47
|
-
Local installs write into:
|
|
48
|
-
|
|
49
|
-
- `./.codex`
|
|
50
|
-
- `./.claude`
|
|
51
|
-
|
|
52
|
-
## Manifest Contract
|
|
53
|
-
|
|
54
|
-
Each source branch must expose `ai-tools.catalog.json` at the branch root.
|
|
55
|
-
|
|
56
|
-
The menu shown by the wizard is driven by `selection-catalog.json` in this package. Update that file when you add or rename installable skills.
|
|
57
|
-
|
|
58
|
-
```json
|
|
59
|
-
{
|
|
60
|
-
"version": 1,
|
|
61
|
-
"type": "skills",
|
|
62
|
-
"label": "General Skills",
|
|
63
|
-
"description": "Standalone skills",
|
|
64
|
-
"items": [
|
|
65
|
-
{
|
|
66
|
-
"id": "git-engineering-workflow",
|
|
67
|
-
"label": "Git engineering workflow",
|
|
68
|
-
"description": "Folder: git-engineering-workflow",
|
|
69
|
-
"sourcePath": "skills/git-engineering-workflow",
|
|
70
|
-
"targets": {
|
|
71
|
-
"codex": {
|
|
72
|
-
"type": "directory",
|
|
73
|
-
"outputPath": "skills/git-engineering-workflow"
|
|
74
|
-
},
|
|
75
|
-
"claude": {
|
|
76
|
-
"type": "file",
|
|
77
|
-
"outputPath": "agents/git-engineering-workflow.md"
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
]
|
|
82
|
-
}
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
Rules:
|
|
86
|
-
|
|
87
|
-
- `agent-skills` must use `"type": "skills"`
|
|
88
|
-
- group branches must use `"type": "group"`
|
|
89
|
-
- `sourcePath` and `outputPath` must stay inside the repository or install root
|
|
90
|
-
- each selected skill id must be unique across the final merged selection
|
|
91
|
-
|
|
92
|
-
## Non-Interactive Usage
|
|
93
|
-
|
|
94
|
-
```bash
|
|
95
|
-
ai-tools install \
|
|
96
|
-
--skills git-engineering-workflow,review-code \
|
|
97
|
-
--location local,global \
|
|
98
|
-
--agent codex,claude \
|
|
99
|
-
--yes
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
## CI/CD
|
|
103
|
-
|
|
104
|
-
GitHub Actions includes:
|
|
105
|
-
|
|
106
|
-
- `.github/workflows/ci.yml` for test and package validation on `push` to `main` and all pull requests
|
|
107
|
-
- `.github/workflows/publish.yml` for npm publish on tags matching `v*.*.*` and manual dispatch
|
|
108
|
-
|
|
109
|
-
To publish successfully, configure the repository secret `NPM_TOKEN` with publish access to the target npm package.
|
|
110
|
-
|
|
111
|
-
For the first public publish of this scoped package, use:
|
|
112
|
-
|
|
113
|
-
```bash
|
|
114
|
-
npm publish --access public
|
|
115
|
-
```
|
|
34
|
+
`Install project docs`
|
|
35
|
+
- copies the contents inside the selected docs folder into the current working directory
|
package/dist/src/bin/ai-tools.js
CHANGED
|
@@ -4,7 +4,7 @@ function isCancellationMessage(message) {
|
|
|
4
4
|
return message === "Installation cancelled."
|
|
5
5
|
|| message === "Installation cancelled because existing targets would be overwritten.";
|
|
6
6
|
}
|
|
7
|
-
runCli(
|
|
7
|
+
runCli().catch((error) => {
|
|
8
8
|
const message = error instanceof Error ? error.message : String(error);
|
|
9
9
|
if (isCancellationMessage(message)) {
|
|
10
10
|
process.exitCode = 0;
|
package/dist/src/cli.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import * as process from "node:process";
|
|
2
|
-
import { parseArgs, printHelp } from "./lib/args.js";
|
|
3
2
|
import { loadPackageConfig } from "./lib/config.js";
|
|
4
|
-
import { createPromptSession, promptConfirm } from "./lib/prompts.js";
|
|
5
3
|
import { createGitHubClient } from "./lib/github.js";
|
|
6
4
|
import { detectExistingTargets, installPlannedItems, installProjectDocsItems, planInstallations, planProjectDocsInstallations, resolveInstallRoot, resolveProjectDocsRoot } from "./lib/install.js";
|
|
7
5
|
import { loadProjectDocsCatalog } from "./lib/project-docs-catalog.js";
|
|
8
6
|
import { loadSelectionCatalog, resolveSelectionItems } from "./lib/selection-catalog.js";
|
|
7
|
+
import { blessedSelect } from "./lib/tui-utils.js";
|
|
9
8
|
import { runEntryMenu } from "./lib/tui-entry-menu.js";
|
|
10
9
|
import { runProjectDocsWizard } from "./lib/tui-project-docs.js";
|
|
11
10
|
import { runTabbedWizard } from "./lib/tui-wizard.js";
|
|
@@ -44,52 +43,12 @@ function printProjectDocsSelectionSummary(input) {
|
|
|
44
43
|
console.log(`- Skills: ${input.selectedSkills.map((skill) => skill.label).join(", ")}`);
|
|
45
44
|
console.log(`- Install root: ${resolveProjectDocsRoot(input.cwd)}`);
|
|
46
45
|
}
|
|
47
|
-
function
|
|
48
|
-
const missing = [];
|
|
49
|
-
if (options.skills.length === 0 && options.groups.length === 0) {
|
|
50
|
-
missing.push("--skills and/or --groups");
|
|
51
|
-
}
|
|
52
|
-
if (options.locations.length === 0) {
|
|
53
|
-
missing.push("--location");
|
|
54
|
-
}
|
|
55
|
-
if (options.agents.length === 0) {
|
|
56
|
-
missing.push("--agent");
|
|
57
|
-
}
|
|
58
|
-
if (missing.length > 0) {
|
|
59
|
-
throw new Error(`Non-interactive mode requires ${missing.join(", ")}. Run in a TTY for prompts.`);
|
|
60
|
-
}
|
|
61
|
-
const unknownSkills = options.skills.filter((skillId) => !selectionCatalog.skills.some((item) => item.id === skillId));
|
|
62
|
-
if (unknownSkills.length > 0) {
|
|
63
|
-
throw new Error(`Unknown skill id(s): ${unknownSkills.join(", ")}`);
|
|
64
|
-
}
|
|
65
|
-
const unknownGroups = options.groups.filter((groupId) => !selectionCatalog.groups.some((group) => group.id === groupId));
|
|
66
|
-
if (unknownGroups.length > 0) {
|
|
67
|
-
throw new Error(`Unknown group id(s): ${unknownGroups.join(", ")}`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
async function resolveSelections(selectionCatalog, options) {
|
|
71
|
-
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
72
|
-
ensureNonInteractiveInputs(selectionCatalog, options);
|
|
73
|
-
return {
|
|
74
|
-
selectedSkills: options.skills,
|
|
75
|
-
selectedGroups: options.groups,
|
|
76
|
-
locations: options.locations,
|
|
77
|
-
agents: options.agents
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
return runTabbedWizard(selectionCatalog, options, "Install agent skills");
|
|
81
|
-
}
|
|
82
|
-
async function resolveEntryAction(rawArgs) {
|
|
83
|
-
if (rawArgs.length > 0 || !process.stdin.isTTY || !process.stdout.isTTY) {
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
return runEntryMenu();
|
|
87
|
-
}
|
|
88
|
-
export async function runCli(argv = process.argv) {
|
|
89
|
-
const rawArgs = argv.slice(2);
|
|
90
|
-
const useMainMenu = rawArgs.length === 0 && process.stdin.isTTY && process.stdout.isTTY;
|
|
46
|
+
export async function runCli() {
|
|
91
47
|
while (true) {
|
|
92
|
-
const entryAction =
|
|
48
|
+
const entryAction = await runEntryMenu();
|
|
49
|
+
if (entryAction === "cancel") {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
93
52
|
if (entryAction === "install-libs") {
|
|
94
53
|
printSectionHeader("Install libs for AI", "Shared AI libraries and tooling are not implemented yet.");
|
|
95
54
|
console.log("Install libs for AI is not implemented yet.");
|
|
@@ -100,10 +59,7 @@ export async function runCli(argv = process.argv) {
|
|
|
100
59
|
const projectDocsCatalog = await loadProjectDocsCatalog(config);
|
|
101
60
|
const projectDocsResult = await runProjectDocsWizard(projectDocsCatalog);
|
|
102
61
|
if ("backToMenu" in projectDocsResult) {
|
|
103
|
-
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
return;
|
|
62
|
+
continue;
|
|
107
63
|
}
|
|
108
64
|
printSectionHeader("Install project docs", "Preparing selected project docs for resolution and installation.");
|
|
109
65
|
printProjectDocsSelectionSummary({
|
|
@@ -133,39 +89,19 @@ export async function runCli(argv = process.argv) {
|
|
|
133
89
|
}
|
|
134
90
|
return;
|
|
135
91
|
}
|
|
136
|
-
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
const effectiveArgs = entryAction === "install-skills" ? ["install"] : rawArgs;
|
|
140
|
-
const { command, options } = parseArgs(effectiveArgs);
|
|
141
|
-
if (options.help || command === "help") {
|
|
142
|
-
printHelp();
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
if (command !== "install") {
|
|
146
|
-
throw new Error(`Unsupported command "${command}". Only "install" is available.`);
|
|
147
|
-
}
|
|
92
|
+
// install-skills
|
|
148
93
|
const config = await loadPackageConfig();
|
|
149
94
|
const selectionCatalog = await loadSelectionCatalog(config);
|
|
150
95
|
if (selectionCatalog.skills.length === 0 && selectionCatalog.groups.length === 0) {
|
|
151
96
|
throw new Error("Selection catalog is empty. Add skills or groups before running the installer.");
|
|
152
97
|
}
|
|
153
|
-
const selectionResult = await
|
|
98
|
+
const selectionResult = await runTabbedWizard(selectionCatalog, "Install agent skills");
|
|
154
99
|
if ("backToMenu" in selectionResult) {
|
|
155
|
-
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
return;
|
|
100
|
+
continue;
|
|
159
101
|
}
|
|
160
102
|
const { selectedSkills, selectedGroups, locations, agents } = selectionResult;
|
|
161
103
|
printSectionHeader("Install agent skills", "Preparing selected skills for resolution and installation.");
|
|
162
|
-
printSkillSelectionSummary({
|
|
163
|
-
selectionCatalog,
|
|
164
|
-
selectedSkills,
|
|
165
|
-
selectedGroups,
|
|
166
|
-
locations,
|
|
167
|
-
agents
|
|
168
|
-
});
|
|
104
|
+
printSkillSelectionSummary({ selectionCatalog, selectedSkills, selectedGroups, locations, agents });
|
|
169
105
|
console.log("Resolving selected sources...");
|
|
170
106
|
const client = createGitHubClient(config.github);
|
|
171
107
|
const finalItems = await resolveSelectionItems({
|
|
@@ -178,32 +114,46 @@ export async function runCli(argv = process.argv) {
|
|
|
178
114
|
if (finalItems.length === 0) {
|
|
179
115
|
throw new Error("No installable items were resolved from the selected sources.");
|
|
180
116
|
}
|
|
181
|
-
const plannedItems =
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
117
|
+
const plannedItems = [];
|
|
118
|
+
const skipped = [];
|
|
119
|
+
for (const location of locations) {
|
|
120
|
+
for (const agent of agents) {
|
|
121
|
+
const agentItems = planInstallations({
|
|
122
|
+
items: finalItems,
|
|
123
|
+
agent,
|
|
124
|
+
installRoot: resolveInstallRoot({ agent, location, cwd: process.cwd() })
|
|
125
|
+
});
|
|
126
|
+
plannedItems.push(...agentItems);
|
|
127
|
+
for (const item of finalItems) {
|
|
128
|
+
if (!agentItems.some((p) => p.id === item.id)) {
|
|
129
|
+
skipped.push(` - ${item.id} (no ${agent} target)`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
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
|
+
}
|
|
140
|
+
}
|
|
186
141
|
const existingTargets = await detectExistingTargets(plannedItems);
|
|
187
|
-
let overwriteExisting =
|
|
188
|
-
if (existingTargets.length > 0
|
|
142
|
+
let overwriteExisting = false;
|
|
143
|
+
if (existingTargets.length > 0) {
|
|
189
144
|
console.log("");
|
|
190
145
|
console.log("Existing targets detected:");
|
|
191
146
|
for (const item of existingTargets) {
|
|
192
147
|
console.log(`- ${item.id}: ${item.targetPath}`);
|
|
193
148
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
finally {
|
|
205
|
-
await prompt.close();
|
|
206
|
-
}
|
|
149
|
+
const answer = await blessedSelect({
|
|
150
|
+
message: "Overwrite all existing targets?",
|
|
151
|
+
choices: [
|
|
152
|
+
{ value: "no", label: "No — keep existing files" },
|
|
153
|
+
{ value: "yes", label: "Yes — overwrite all" }
|
|
154
|
+
]
|
|
155
|
+
});
|
|
156
|
+
overwriteExisting = answer === "yes";
|
|
207
157
|
if (!overwriteExisting) {
|
|
208
158
|
throw new Error("Installation cancelled because existing targets would be overwritten.");
|
|
209
159
|
}
|
package/dist/src/lib/catalog.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { normalizeManifestPath } from "./paths.js";
|
|
2
|
-
function validateTarget(target, agent, skillId) {
|
|
2
|
+
export function validateTarget(target, agent, skillId) {
|
|
3
3
|
if (!target || typeof target !== "object") {
|
|
4
4
|
throw new Error(`Skill "${skillId}" has an invalid ${agent} target.`);
|
|
5
5
|
}
|
|
@@ -8,10 +8,13 @@ function validateTarget(target, agent, skillId) {
|
|
|
8
8
|
if (type !== "directory" && type !== "file") {
|
|
9
9
|
throw new Error(`Skill "${skillId}" has an invalid ${agent} target type "${String(type)}".`);
|
|
10
10
|
}
|
|
11
|
+
const sourcePath = typeof targetRecord.sourcePath === "string" && targetRecord.sourcePath.trim() !== ""
|
|
12
|
+
? normalizeManifestPath(targetRecord.sourcePath, `${skillId}.${agent}.sourcePath`)
|
|
13
|
+
: undefined;
|
|
11
14
|
const outputPath = typeof targetRecord.outputPath === "string" && targetRecord.outputPath.trim() !== ""
|
|
12
15
|
? normalizeManifestPath(targetRecord.outputPath, `${skillId}.${agent}.outputPath`)
|
|
13
16
|
: undefined;
|
|
14
|
-
return { type, outputPath };
|
|
17
|
+
return { type, sourcePath, outputPath };
|
|
15
18
|
}
|
|
16
19
|
function attachBranchMetadata(items, branch, sha) {
|
|
17
20
|
return items.map((item) => ({
|
package/dist/src/lib/github.js
CHANGED
|
@@ -2,6 +2,7 @@ import { mkdtemp, mkdir, readFile, rename, rm, stat, writeFile } from "node:fs/p
|
|
|
2
2
|
import * as os from "node:os";
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import { spawn } from "node:child_process";
|
|
5
|
+
const ARCHIVE_CACHE_ROOT = path.join(os.homedir(), ".ai-tools", "cache", "archives");
|
|
5
6
|
async function ensureDirectory(dirPath) {
|
|
6
7
|
await mkdir(dirPath, { recursive: true });
|
|
7
8
|
}
|
|
@@ -76,8 +77,7 @@ async function readArchiveEntryText(input) {
|
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
export function createGitHubClient(config) {
|
|
79
|
-
const
|
|
80
|
-
const archiveCacheRoot = path.join(cacheRoot, "archives");
|
|
80
|
+
const archiveCacheRoot = ARCHIVE_CACHE_ROOT;
|
|
81
81
|
async function listBranches() {
|
|
82
82
|
const url = `https://api.github.com/repos/${config.owner}/${config.repo}/branches?per_page=100`;
|
|
83
83
|
const branches = await fetchJson(url);
|
package/dist/src/lib/install.js
CHANGED
|
@@ -2,41 +2,41 @@ import { access, cp, mkdir, mkdtemp, readdir, rm } from "node:fs/promises";
|
|
|
2
2
|
import * as os from "node:os";
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import { normalizeManifestPath, resolveInsideRoot } from "./paths.js";
|
|
5
|
+
const AGENT_INSTALL_DIR = {
|
|
6
|
+
codex: ".codex",
|
|
7
|
+
claude: ".claude"
|
|
8
|
+
};
|
|
5
9
|
export function resolveInstallRoot(input) {
|
|
6
|
-
const
|
|
7
|
-
const globalRoot = input.agent === "codex" ? path.join(homeDir, ".codex") : path.join(homeDir, ".claude");
|
|
8
|
-
const localRoot = input.agent === "codex" ? path.join(input.cwd, ".codex") : path.join(input.cwd, ".claude");
|
|
10
|
+
const dir = AGENT_INSTALL_DIR[input.agent];
|
|
9
11
|
if (input.location === "global") {
|
|
10
|
-
return
|
|
12
|
+
return path.join(os.homedir(), dir);
|
|
11
13
|
}
|
|
12
14
|
if (input.location === "local") {
|
|
13
|
-
return
|
|
15
|
+
return path.join(input.cwd, dir);
|
|
14
16
|
}
|
|
15
17
|
throw new Error(`Unsupported install location "${input.location}".`);
|
|
16
18
|
}
|
|
17
19
|
export function resolveProjectDocsRoot(cwd) {
|
|
18
20
|
return cwd;
|
|
19
21
|
}
|
|
20
|
-
function defaultOutputPath(item
|
|
21
|
-
|
|
22
|
-
return path.posix.join("skills", item.id);
|
|
23
|
-
}
|
|
24
|
-
return path.posix.join("agents", `${item.id}.md`);
|
|
22
|
+
function defaultOutputPath(item) {
|
|
23
|
+
return path.posix.join("skills", item.id);
|
|
25
24
|
}
|
|
26
25
|
export function planInstallations(input) {
|
|
27
|
-
return input.items.
|
|
26
|
+
return input.items.flatMap((item) => {
|
|
28
27
|
const target = item.targets[input.agent];
|
|
29
28
|
if (!target) {
|
|
30
|
-
|
|
29
|
+
return [];
|
|
31
30
|
}
|
|
32
|
-
const outputPath = normalizeManifestPath(target.outputPath || defaultOutputPath(item
|
|
33
|
-
return {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
const outputPath = normalizeManifestPath(target.outputPath || defaultOutputPath(item), `${item.id}.${input.agent}.outputPath`);
|
|
32
|
+
return [{
|
|
33
|
+
...item,
|
|
34
|
+
sourcePath: target.sourcePath ?? item.sourcePath,
|
|
35
|
+
agent: input.agent,
|
|
36
|
+
targetType: target.type,
|
|
37
|
+
outputPath,
|
|
38
|
+
targetPath: resolveInsideRoot(input.installRoot, outputPath)
|
|
39
|
+
}];
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
export async function detectExistingTargets(plannedItems) {
|
|
@@ -52,9 +52,6 @@ export async function detectExistingTargets(plannedItems) {
|
|
|
52
52
|
}
|
|
53
53
|
return existingItems;
|
|
54
54
|
}
|
|
55
|
-
export async function detectExistingProjectDocsTargets(plannedItems) {
|
|
56
|
-
return [];
|
|
57
|
-
}
|
|
58
55
|
export function planProjectDocsInstallations(input) {
|
|
59
56
|
const installRoot = resolveProjectDocsRoot(input.cwd);
|
|
60
57
|
return input.skills.map((skill) => {
|
package/dist/src/lib/prompts.js
CHANGED
|
@@ -2,17 +2,7 @@ import { checkbox, confirm, select } from "@inquirer/prompts";
|
|
|
2
2
|
const PROMPT_CONTEXT = {
|
|
3
3
|
clearPromptOnDone: true
|
|
4
4
|
};
|
|
5
|
-
export function
|
|
6
|
-
return {
|
|
7
|
-
async ask() {
|
|
8
|
-
throw new Error("PromptSession.ask is not used with checkbox/select prompts.");
|
|
9
|
-
},
|
|
10
|
-
async close() {
|
|
11
|
-
// No-op. @inquirer/prompts manages its own lifecycle.
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export async function promptMultiSelect(_prompt, options) {
|
|
5
|
+
export async function promptMultiSelect(options) {
|
|
16
6
|
if (options.choices.length === 0) {
|
|
17
7
|
return [];
|
|
18
8
|
}
|
|
@@ -30,7 +20,7 @@ export async function promptMultiSelect(_prompt, options) {
|
|
|
30
20
|
}
|
|
31
21
|
return selectedValues;
|
|
32
22
|
}
|
|
33
|
-
export async function promptSingleSelect(
|
|
23
|
+
export async function promptSingleSelect(options) {
|
|
34
24
|
if (options.choices.length === 0) {
|
|
35
25
|
throw new Error(`No choices available for "${options.message}".`);
|
|
36
26
|
}
|
|
@@ -46,7 +36,7 @@ export async function promptSingleSelect(_prompt, options) {
|
|
|
46
36
|
}))
|
|
47
37
|
}, PROMPT_CONTEXT);
|
|
48
38
|
}
|
|
49
|
-
export async function promptConfirm(
|
|
39
|
+
export async function promptConfirm(options) {
|
|
50
40
|
return confirm({
|
|
51
41
|
message: options.message,
|
|
52
42
|
default: options.defaultValue ?? false
|
|
@@ -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,4 +1,5 @@
|
|
|
1
1
|
import blessed from "blessed";
|
|
2
|
+
import { canRun, DEBOUNCE_MOVE_MS, DEBOUNCE_SELECT_MS, renderBannerHeader } from "./tui-utils.js";
|
|
2
3
|
const MENU_ITEMS = [
|
|
3
4
|
{
|
|
4
5
|
id: "install-skills",
|
|
@@ -21,14 +22,6 @@ const MENU_ITEMS = [
|
|
|
21
22
|
description: "Exit without running any installer."
|
|
22
23
|
}
|
|
23
24
|
];
|
|
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
25
|
function renderItem(item, isActive) {
|
|
33
26
|
const text = `${isActive ? "> " : " "}${item.label}`;
|
|
34
27
|
return isActive ? `{black-fg}{yellow-bg}${text}{/yellow-bg}{/black-fg}` : text;
|
|
@@ -91,18 +84,15 @@ export async function runEntryMenu() {
|
|
|
91
84
|
screen.destroy();
|
|
92
85
|
}
|
|
93
86
|
function render() {
|
|
94
|
-
headerBox.setContent(
|
|
87
|
+
headerBox.setContent(renderBannerHeader("Main menu", "Choose the workflow you want to run."));
|
|
95
88
|
listBox.setItems(MENU_ITEMS.map((item, index) => renderItem(item, index === cursor)));
|
|
96
89
|
listBox.select(cursor);
|
|
97
90
|
detailBox.setContent(`{bold}Details{/bold}\n${MENU_ITEMS[cursor].description}`);
|
|
98
91
|
footerBox.setContent("↑ ↓ move • enter select • q quit");
|
|
99
92
|
screen.render();
|
|
100
93
|
}
|
|
101
|
-
function canRun(lastAt, thresholdMs) {
|
|
102
|
-
return Date.now() - lastAt >= thresholdMs;
|
|
103
|
-
}
|
|
104
94
|
screen.key(["up"], () => {
|
|
105
|
-
if (!canRun(lastMoveAt,
|
|
95
|
+
if (!canRun(lastMoveAt, DEBOUNCE_MOVE_MS)) {
|
|
106
96
|
return;
|
|
107
97
|
}
|
|
108
98
|
lastMoveAt = Date.now();
|
|
@@ -110,7 +100,7 @@ export async function runEntryMenu() {
|
|
|
110
100
|
render();
|
|
111
101
|
});
|
|
112
102
|
screen.key(["down"], () => {
|
|
113
|
-
if (!canRun(lastMoveAt,
|
|
103
|
+
if (!canRun(lastMoveAt, DEBOUNCE_MOVE_MS)) {
|
|
114
104
|
return;
|
|
115
105
|
}
|
|
116
106
|
lastMoveAt = Date.now();
|
|
@@ -118,7 +108,7 @@ export async function runEntryMenu() {
|
|
|
118
108
|
render();
|
|
119
109
|
});
|
|
120
110
|
screen.key(["enter"], () => {
|
|
121
|
-
if (!canRun(lastSelectAt,
|
|
111
|
+
if (!canRun(lastSelectAt, DEBOUNCE_SELECT_MS)) {
|
|
122
112
|
return;
|
|
123
113
|
}
|
|
124
114
|
lastSelectAt = Date.now();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { canRun, createTabbedLayout, DEBOUNCE_MOVE_MS, DEBOUNCE_SELECT_MS, renderBannerHeader } 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) => ({
|
|
@@ -78,14 +75,6 @@ function formatListItem(item, state, isCursorRow) {
|
|
|
78
75
|
const checked = isItemSelected(item, state) ? "x" : " ";
|
|
79
76
|
return wrapCursorRow(`${cursorPrefix}[${checked}] ${item.label}`);
|
|
80
77
|
}
|
|
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");
|
|
88
|
-
}
|
|
89
78
|
function renderReviewSummary(state, catalog) {
|
|
90
79
|
const selectedSkills = catalog.skills
|
|
91
80
|
.filter((skill) => state.selectedSkills.has(skill.id))
|
|
@@ -159,80 +148,13 @@ export async function runProjectDocsWizard(catalog) {
|
|
|
159
148
|
let lastTabSwitchAt = 0;
|
|
160
149
|
let lastMoveAt = 0;
|
|
161
150
|
let lastToggleAt = 0;
|
|
162
|
-
const 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
|
-
});
|
|
151
|
+
const { screen, headerBox, tabsBox, titleBox, listBox, detailBox, footerBox } = createTabbedLayout();
|
|
230
152
|
function cleanup() {
|
|
231
153
|
screen.destroy();
|
|
232
154
|
}
|
|
233
155
|
function render() {
|
|
234
156
|
const stepTitle = state.activeTab === "skills" ? "Select skills" : "Review selections";
|
|
235
|
-
headerBox.setContent(
|
|
157
|
+
headerBox.setContent(renderBannerHeader("Install project docs", "Choose skills first, then confirm from review."));
|
|
236
158
|
tabsBox.setContent(renderTabs(state));
|
|
237
159
|
titleBox.setContent(`{bold}${stepTitle}{/bold}`);
|
|
238
160
|
syncListSelection(listBox, state, catalog);
|
|
@@ -240,9 +162,6 @@ export async function runProjectDocsWizard(catalog) {
|
|
|
240
162
|
footerBox.setContent(renderFooter(state));
|
|
241
163
|
screen.render();
|
|
242
164
|
}
|
|
243
|
-
function canRun(lastAt, thresholdMs) {
|
|
244
|
-
return Date.now() - lastAt >= thresholdMs;
|
|
245
|
-
}
|
|
246
165
|
function finishBackToMenu() {
|
|
247
166
|
cleanup();
|
|
248
167
|
resolve({ backToMenu: true });
|
|
@@ -258,7 +177,7 @@ export async function runProjectDocsWizard(catalog) {
|
|
|
258
177
|
reject(new Error(message));
|
|
259
178
|
}
|
|
260
179
|
function handleToggleOrConfirm() {
|
|
261
|
-
if (!canRun(lastToggleAt,
|
|
180
|
+
if (!canRun(lastToggleAt, DEBOUNCE_SELECT_MS)) {
|
|
262
181
|
return;
|
|
263
182
|
}
|
|
264
183
|
lastToggleAt = Date.now();
|
|
@@ -305,7 +224,7 @@ export async function runProjectDocsWizard(catalog) {
|
|
|
305
224
|
render();
|
|
306
225
|
}
|
|
307
226
|
screen.key(["left"], () => {
|
|
308
|
-
if (!canRun(lastTabSwitchAt,
|
|
227
|
+
if (!canRun(lastTabSwitchAt, DEBOUNCE_SELECT_MS)) {
|
|
309
228
|
return;
|
|
310
229
|
}
|
|
311
230
|
lastTabSwitchAt = Date.now();
|
|
@@ -313,7 +232,7 @@ export async function runProjectDocsWizard(catalog) {
|
|
|
313
232
|
render();
|
|
314
233
|
});
|
|
315
234
|
screen.key(["right"], () => {
|
|
316
|
-
if (!canRun(lastTabSwitchAt,
|
|
235
|
+
if (!canRun(lastTabSwitchAt, DEBOUNCE_SELECT_MS)) {
|
|
317
236
|
return;
|
|
318
237
|
}
|
|
319
238
|
lastTabSwitchAt = Date.now();
|
|
@@ -321,7 +240,7 @@ export async function runProjectDocsWizard(catalog) {
|
|
|
321
240
|
render();
|
|
322
241
|
});
|
|
323
242
|
screen.key(["up"], () => {
|
|
324
|
-
if (!canRun(lastMoveAt,
|
|
243
|
+
if (!canRun(lastMoveAt, DEBOUNCE_MOVE_MS)) {
|
|
325
244
|
return;
|
|
326
245
|
}
|
|
327
246
|
lastMoveAt = Date.now();
|
|
@@ -329,7 +248,7 @@ export async function runProjectDocsWizard(catalog) {
|
|
|
329
248
|
render();
|
|
330
249
|
});
|
|
331
250
|
screen.key(["down"], () => {
|
|
332
|
-
if (!canRun(lastMoveAt,
|
|
251
|
+
if (!canRun(lastMoveAt, DEBOUNCE_MOVE_MS)) {
|
|
333
252
|
return;
|
|
334
253
|
}
|
|
335
254
|
lastMoveAt = Date.now();
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import blessed from "blessed";
|
|
2
|
+
export const DEBOUNCE_MOVE_MS = 100;
|
|
3
|
+
export const DEBOUNCE_SELECT_MS = 120;
|
|
4
|
+
export function canRun(lastAt, thresholdMs) {
|
|
5
|
+
return Date.now() - lastAt >= thresholdMs;
|
|
6
|
+
}
|
|
7
|
+
export function selectionArray(items) {
|
|
8
|
+
return [...items];
|
|
9
|
+
}
|
|
10
|
+
export function renderBannerHeader(title, subtitle) {
|
|
11
|
+
return [
|
|
12
|
+
"{black-fg}{cyan-bg} AI-TOOLS {/cyan-bg}{/black-fg}",
|
|
13
|
+
`{bold}${title}{/bold}`,
|
|
14
|
+
`{gray-fg}${subtitle}{/gray-fg}`,
|
|
15
|
+
"{cyan-fg}------------------------------------------------------------------------{/cyan-fg}"
|
|
16
|
+
].join("\n");
|
|
17
|
+
}
|
|
18
|
+
export async function blessedSelect(input) {
|
|
19
|
+
return new Promise((resolve) => {
|
|
20
|
+
let cursor = 0;
|
|
21
|
+
const screen = blessed.screen({ smartCSR: true, fullUnicode: true, title: "ai-tools" });
|
|
22
|
+
const promptBox = blessed.box({
|
|
23
|
+
parent: screen,
|
|
24
|
+
top: "center",
|
|
25
|
+
left: "center",
|
|
26
|
+
width: 50,
|
|
27
|
+
height: input.choices.length + 4,
|
|
28
|
+
border: { type: "line" },
|
|
29
|
+
tags: true
|
|
30
|
+
});
|
|
31
|
+
function render() {
|
|
32
|
+
const lines = [
|
|
33
|
+
`{bold}${input.message}{/bold}`,
|
|
34
|
+
""
|
|
35
|
+
];
|
|
36
|
+
for (let i = 0; i < input.choices.length; i++) {
|
|
37
|
+
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);
|
|
40
|
+
}
|
|
41
|
+
promptBox.setContent(lines.join("\n"));
|
|
42
|
+
screen.render();
|
|
43
|
+
}
|
|
44
|
+
screen.key(["up"], () => {
|
|
45
|
+
cursor = (cursor - 1 + input.choices.length) % input.choices.length;
|
|
46
|
+
render();
|
|
47
|
+
});
|
|
48
|
+
screen.key(["down"], () => {
|
|
49
|
+
cursor = (cursor + 1) % input.choices.length;
|
|
50
|
+
render();
|
|
51
|
+
});
|
|
52
|
+
screen.key(["enter", "space"], () => {
|
|
53
|
+
const value = input.choices[cursor].value;
|
|
54
|
+
screen.destroy();
|
|
55
|
+
resolve(value);
|
|
56
|
+
});
|
|
57
|
+
screen.key(["escape", "q", "C-c"], () => {
|
|
58
|
+
screen.destroy();
|
|
59
|
+
resolve(input.choices[0].value);
|
|
60
|
+
});
|
|
61
|
+
render();
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
export function createTabbedLayout() {
|
|
65
|
+
const screen = blessed.screen({
|
|
66
|
+
smartCSR: true,
|
|
67
|
+
fullUnicode: true,
|
|
68
|
+
title: "ai-tools"
|
|
69
|
+
});
|
|
70
|
+
const headerBox = blessed.box({
|
|
71
|
+
parent: screen,
|
|
72
|
+
top: 0,
|
|
73
|
+
left: 0,
|
|
74
|
+
width: "100%",
|
|
75
|
+
height: 4,
|
|
76
|
+
tags: true,
|
|
77
|
+
wrap: true
|
|
78
|
+
});
|
|
79
|
+
const tabsBox = blessed.box({
|
|
80
|
+
parent: screen,
|
|
81
|
+
top: 4,
|
|
82
|
+
left: 0,
|
|
83
|
+
width: "100%",
|
|
84
|
+
height: 1,
|
|
85
|
+
tags: true
|
|
86
|
+
});
|
|
87
|
+
const titleBox = blessed.box({
|
|
88
|
+
parent: screen,
|
|
89
|
+
top: 6,
|
|
90
|
+
left: 0,
|
|
91
|
+
width: "100%",
|
|
92
|
+
height: 1,
|
|
93
|
+
tags: true
|
|
94
|
+
});
|
|
95
|
+
const listBox = blessed.list({
|
|
96
|
+
parent: screen,
|
|
97
|
+
top: 8,
|
|
98
|
+
left: 0,
|
|
99
|
+
width: "100%",
|
|
100
|
+
height: "100%-13",
|
|
101
|
+
tags: true,
|
|
102
|
+
keys: false,
|
|
103
|
+
vi: false,
|
|
104
|
+
mouse: false,
|
|
105
|
+
interactive: false,
|
|
106
|
+
scrollable: true,
|
|
107
|
+
alwaysScroll: true,
|
|
108
|
+
style: {
|
|
109
|
+
selected: {
|
|
110
|
+
bold: true,
|
|
111
|
+
fg: "black",
|
|
112
|
+
bg: "yellow"
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
const detailBox = blessed.box({
|
|
117
|
+
parent: screen,
|
|
118
|
+
left: 0,
|
|
119
|
+
bottom: 1,
|
|
120
|
+
width: "100%",
|
|
121
|
+
height: 4,
|
|
122
|
+
tags: true,
|
|
123
|
+
wrap: true
|
|
124
|
+
});
|
|
125
|
+
const footerBox = blessed.box({
|
|
126
|
+
parent: screen,
|
|
127
|
+
bottom: 0,
|
|
128
|
+
left: 0,
|
|
129
|
+
width: "100%",
|
|
130
|
+
height: 1,
|
|
131
|
+
tags: true
|
|
132
|
+
});
|
|
133
|
+
return { screen, headerBox, tabsBox, titleBox, listBox, detailBox, footerBox };
|
|
134
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import blessed from "blessed";
|
|
2
1
|
import { resolveInstallRoot } from "./install.js";
|
|
2
|
+
import { canRun, createTabbedLayout, DEBOUNCE_MOVE_MS, DEBOUNCE_SELECT_MS, renderBannerHeader, selectionArray } from "./tui-utils.js";
|
|
3
3
|
const TAB_ORDER = ["skills", "locations", "agents", "review"];
|
|
4
|
-
function buildInitialState(
|
|
4
|
+
function buildInitialState() {
|
|
5
5
|
return {
|
|
6
6
|
activeTab: "skills",
|
|
7
|
-
selectedSkills: new Set(
|
|
8
|
-
selectedGroups: new Set(
|
|
9
|
-
selectedLocations: new Set(
|
|
10
|
-
selectedAgents: new Set(
|
|
7
|
+
selectedSkills: new Set(),
|
|
8
|
+
selectedGroups: new Set(),
|
|
9
|
+
selectedLocations: new Set(),
|
|
10
|
+
selectedAgents: new Set(),
|
|
11
11
|
listCursor: {
|
|
12
12
|
skills: 0,
|
|
13
13
|
locations: 0,
|
|
@@ -18,9 +18,6 @@ function buildInitialState(options) {
|
|
|
18
18
|
notice: ""
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
-
function selectionArray(items) {
|
|
22
|
-
return [...items];
|
|
23
|
-
}
|
|
24
21
|
function currentTabItems(state, selectionCatalog) {
|
|
25
22
|
if (state.activeTab === "skills") {
|
|
26
23
|
return selectionCatalog.skills.map((skill) => ({
|
|
@@ -83,25 +80,6 @@ function currentTabItems(state, selectionCatalog) {
|
|
|
83
80
|
}
|
|
84
81
|
];
|
|
85
82
|
}
|
|
86
|
-
function isItemLocked(item, options) {
|
|
87
|
-
if (item.kind === "skill") {
|
|
88
|
-
return options.skills.length > 0;
|
|
89
|
-
}
|
|
90
|
-
if (item.kind === "locations") {
|
|
91
|
-
return options.locations.length > 0;
|
|
92
|
-
}
|
|
93
|
-
if (item.kind === "agents") {
|
|
94
|
-
return options.agents.length > 0;
|
|
95
|
-
}
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
function areAllItemsLocked(state, selectionCatalog, options) {
|
|
99
|
-
if (state.activeTab === "review") {
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
const items = currentTabItems(state, selectionCatalog);
|
|
103
|
-
return items.length > 0 && items.every((item) => isItemLocked(item, options));
|
|
104
|
-
}
|
|
105
83
|
function isItemSelected(item, state) {
|
|
106
84
|
if (item.kind === "skill") {
|
|
107
85
|
return state.selectedSkills.has(item.id);
|
|
@@ -152,15 +130,14 @@ function renderTabs(state) {
|
|
|
152
130
|
return state.activeTab === tab ? `{inverse}${label}{/inverse}` : label;
|
|
153
131
|
}).join(" ");
|
|
154
132
|
}
|
|
155
|
-
function formatListItem(item, state,
|
|
133
|
+
function formatListItem(item, state, isCursorRow) {
|
|
156
134
|
const cursorPrefix = isCursorRow ? "> " : " ";
|
|
157
135
|
const wrapCursorRow = (value) => isCursorRow ? `{black-fg}{yellow-bg}${value}{/yellow-bg}{/black-fg}` : value;
|
|
158
136
|
if (item.kind === "review") {
|
|
159
137
|
return wrapCursorRow(`${cursorPrefix}${state.reviewAction === item.id ? "[x]" : "[ ]"} ${item.label}`);
|
|
160
138
|
}
|
|
161
139
|
const checked = isItemSelected(item, state) ? "x" : " ";
|
|
162
|
-
|
|
163
|
-
return wrapCursorRow(`${cursorPrefix}[${checked}] ${item.label}${locked}`);
|
|
140
|
+
return wrapCursorRow(`${cursorPrefix}[${checked}] ${item.label}`);
|
|
164
141
|
}
|
|
165
142
|
function renderReviewSummary(state, selectionCatalog) {
|
|
166
143
|
const selectedSkillLabels = selectionCatalog.skills
|
|
@@ -193,7 +170,7 @@ function renderReviewSummary(state, selectionCatalog) {
|
|
|
193
170
|
}
|
|
194
171
|
return lines.join("\n");
|
|
195
172
|
}
|
|
196
|
-
function renderDetailBody(state, selectionCatalog
|
|
173
|
+
function renderDetailBody(state, selectionCatalog) {
|
|
197
174
|
if (state.activeTab === "review") {
|
|
198
175
|
return renderReviewSummary(state, selectionCatalog);
|
|
199
176
|
}
|
|
@@ -203,21 +180,15 @@ function renderDetailBody(state, selectionCatalog, options) {
|
|
|
203
180
|
if (state.notice) {
|
|
204
181
|
lines.push(`{yellow-fg}${state.notice}{/yellow-fg}`, "");
|
|
205
182
|
}
|
|
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
183
|
if (current) {
|
|
210
184
|
lines.push("{bold}Details{/bold}", current.description);
|
|
211
185
|
}
|
|
212
186
|
return lines.join("\n");
|
|
213
187
|
}
|
|
214
|
-
function renderFooter(state
|
|
188
|
+
function renderFooter(state) {
|
|
215
189
|
if (state.activeTab === "review") {
|
|
216
190
|
return "← → switch tab • ↑ ↓ move • enter confirm action • q quit";
|
|
217
191
|
}
|
|
218
|
-
if (areAllItemsLocked(state, selectionCatalog, options)) {
|
|
219
|
-
return "← → switch tab • ↑ ↓ move • q quit";
|
|
220
|
-
}
|
|
221
192
|
return "← → switch tab • ↑ ↓ move • space/enter toggle • a toggle all • q quit";
|
|
222
193
|
}
|
|
223
194
|
function setNotice(state, message) {
|
|
@@ -241,13 +212,13 @@ function moveCursor(state, selectionCatalog, delta) {
|
|
|
241
212
|
state.reviewAction = items[next]?.id;
|
|
242
213
|
}
|
|
243
214
|
}
|
|
244
|
-
function toggleCurrentItem(state, selectionCatalog
|
|
215
|
+
function toggleCurrentItem(state, selectionCatalog) {
|
|
245
216
|
if (state.activeTab === "review") {
|
|
246
217
|
return;
|
|
247
218
|
}
|
|
248
219
|
const items = currentTabItems(state, selectionCatalog);
|
|
249
220
|
const current = items[state.listCursor[state.activeTab]];
|
|
250
|
-
if (!current
|
|
221
|
+
if (!current) {
|
|
251
222
|
return;
|
|
252
223
|
}
|
|
253
224
|
toggleItem(current, state);
|
|
@@ -264,97 +235,22 @@ function validateBeforeConfirm(state) {
|
|
|
264
235
|
}
|
|
265
236
|
return null;
|
|
266
237
|
}
|
|
267
|
-
function syncListSelection(listBox, state, selectionCatalog
|
|
238
|
+
function syncListSelection(listBox, state, selectionCatalog) {
|
|
268
239
|
const items = currentTabItems(state, selectionCatalog);
|
|
269
240
|
const maxIndex = Math.max(items.length - 1, 0);
|
|
270
241
|
const cursor = Math.min(state.listCursor[state.activeTab], maxIndex);
|
|
271
242
|
state.listCursor[state.activeTab] = cursor;
|
|
272
|
-
listBox.setItems(items.map((item, index) => formatListItem(item, state,
|
|
243
|
+
listBox.setItems(items.map((item, index) => formatListItem(item, state, index === cursor)));
|
|
273
244
|
listBox.select(cursor);
|
|
274
245
|
listBox.scrollTo(cursor);
|
|
275
246
|
}
|
|
276
|
-
function
|
|
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") {
|
|
247
|
+
export async function runTabbedWizard(selectionCatalog, headerTitle = "Install agent skills") {
|
|
285
248
|
return new Promise((resolve, reject) => {
|
|
286
|
-
const state = buildInitialState(
|
|
249
|
+
const state = buildInitialState();
|
|
287
250
|
let lastTabSwitchAt = 0;
|
|
288
251
|
let lastMoveAt = 0;
|
|
289
252
|
let lastToggleAt = 0;
|
|
290
|
-
const 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
|
-
});
|
|
253
|
+
const { screen, headerBox, tabsBox, titleBox, listBox, detailBox, footerBox } = createTabbedLayout();
|
|
358
254
|
function cleanup() {
|
|
359
255
|
screen.destroy();
|
|
360
256
|
}
|
|
@@ -384,19 +280,16 @@ export async function runTabbedWizard(selectionCatalog, options, headerTitle = "
|
|
|
384
280
|
agents: "Select agents",
|
|
385
281
|
review: "Review selections"
|
|
386
282
|
}[state.activeTab];
|
|
387
|
-
headerBox.setContent(
|
|
283
|
+
headerBox.setContent(renderBannerHeader(headerTitle, "Browse items, move across tabs, and confirm only after review."));
|
|
388
284
|
tabsBox.setContent(renderTabs(state));
|
|
389
285
|
titleBox.setContent(`{bold}${stepTitle}{/bold}`);
|
|
390
|
-
syncListSelection(listBox, state, selectionCatalog
|
|
391
|
-
detailBox.setContent(renderDetailBody(state, selectionCatalog
|
|
392
|
-
footerBox.setContent(renderFooter(state
|
|
286
|
+
syncListSelection(listBox, state, selectionCatalog);
|
|
287
|
+
detailBox.setContent(renderDetailBody(state, selectionCatalog));
|
|
288
|
+
footerBox.setContent(renderFooter(state));
|
|
393
289
|
screen.render();
|
|
394
290
|
}
|
|
395
|
-
function canRun(lastAt, thresholdMs) {
|
|
396
|
-
return Date.now() - lastAt >= thresholdMs;
|
|
397
|
-
}
|
|
398
291
|
function handleToggleOrConfirm() {
|
|
399
|
-
if (!canRun(lastToggleAt,
|
|
292
|
+
if (!canRun(lastToggleAt, DEBOUNCE_SELECT_MS)) {
|
|
400
293
|
return;
|
|
401
294
|
}
|
|
402
295
|
lastToggleAt = Date.now();
|
|
@@ -418,14 +311,14 @@ export async function runTabbedWizard(selectionCatalog, options, headerTitle = "
|
|
|
418
311
|
finishSuccess();
|
|
419
312
|
return;
|
|
420
313
|
}
|
|
421
|
-
toggleCurrentItem(state, selectionCatalog
|
|
314
|
+
toggleCurrentItem(state, selectionCatalog);
|
|
422
315
|
render();
|
|
423
316
|
}
|
|
424
317
|
function toggleAllInCurrentTab() {
|
|
425
318
|
if (state.activeTab === "review") {
|
|
426
319
|
return;
|
|
427
320
|
}
|
|
428
|
-
const items = currentTabItems(state, selectionCatalog)
|
|
321
|
+
const items = currentTabItems(state, selectionCatalog);
|
|
429
322
|
if (items.length === 0) {
|
|
430
323
|
return;
|
|
431
324
|
}
|
|
@@ -442,7 +335,7 @@ export async function runTabbedWizard(selectionCatalog, options, headerTitle = "
|
|
|
442
335
|
render();
|
|
443
336
|
}
|
|
444
337
|
screen.key(["left"], () => {
|
|
445
|
-
if (!canRun(lastTabSwitchAt,
|
|
338
|
+
if (!canRun(lastTabSwitchAt, DEBOUNCE_SELECT_MS)) {
|
|
446
339
|
return;
|
|
447
340
|
}
|
|
448
341
|
lastTabSwitchAt = Date.now();
|
|
@@ -450,7 +343,7 @@ export async function runTabbedWizard(selectionCatalog, options, headerTitle = "
|
|
|
450
343
|
render();
|
|
451
344
|
});
|
|
452
345
|
screen.key(["right"], () => {
|
|
453
|
-
if (!canRun(lastTabSwitchAt,
|
|
346
|
+
if (!canRun(lastTabSwitchAt, DEBOUNCE_SELECT_MS)) {
|
|
454
347
|
return;
|
|
455
348
|
}
|
|
456
349
|
lastTabSwitchAt = Date.now();
|
|
@@ -458,7 +351,7 @@ export async function runTabbedWizard(selectionCatalog, options, headerTitle = "
|
|
|
458
351
|
render();
|
|
459
352
|
});
|
|
460
353
|
screen.key(["up"], () => {
|
|
461
|
-
if (!canRun(lastMoveAt,
|
|
354
|
+
if (!canRun(lastMoveAt, DEBOUNCE_MOVE_MS)) {
|
|
462
355
|
return;
|
|
463
356
|
}
|
|
464
357
|
lastMoveAt = Date.now();
|
|
@@ -466,7 +359,7 @@ export async function runTabbedWizard(selectionCatalog, options, headerTitle = "
|
|
|
466
359
|
render();
|
|
467
360
|
});
|
|
468
361
|
screen.key(["down"], () => {
|
|
469
|
-
if (!canRun(lastMoveAt,
|
|
362
|
+
if (!canRun(lastMoveAt, DEBOUNCE_MOVE_MS)) {
|
|
470
363
|
return;
|
|
471
364
|
}
|
|
472
365
|
lastMoveAt = Date.now();
|
package/package.json
CHANGED
package/dist/src/lib/args.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
const COMMANDS = new Set(["install", "help"]);
|
|
2
|
-
const AGENTS = new Set(["codex", "claude"]);
|
|
3
|
-
const LOCATIONS = new Set(["global", "local"]);
|
|
4
|
-
const FLAG_KEYS = new Set(["agent", "location", "skills", "groups"]);
|
|
5
|
-
function parseCsv(value) {
|
|
6
|
-
if (!value) {
|
|
7
|
-
return [];
|
|
8
|
-
}
|
|
9
|
-
return value
|
|
10
|
-
.split(",")
|
|
11
|
-
.map((item) => item.trim())
|
|
12
|
-
.filter(Boolean);
|
|
13
|
-
}
|
|
14
|
-
export function isAgent(value) {
|
|
15
|
-
return AGENTS.has(value);
|
|
16
|
-
}
|
|
17
|
-
export function isInstallLocation(value) {
|
|
18
|
-
return LOCATIONS.has(value);
|
|
19
|
-
}
|
|
20
|
-
export function parseArgs(argv) {
|
|
21
|
-
let command = "install";
|
|
22
|
-
const options = {
|
|
23
|
-
help: false,
|
|
24
|
-
yes: false,
|
|
25
|
-
agents: [],
|
|
26
|
-
locations: [],
|
|
27
|
-
skills: [],
|
|
28
|
-
groups: []
|
|
29
|
-
};
|
|
30
|
-
for (let index = 0; index < argv.length; index += 1) {
|
|
31
|
-
const token = argv[index];
|
|
32
|
-
if (token === "--help" || token === "-h") {
|
|
33
|
-
options.help = true;
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
if (token === "--yes") {
|
|
37
|
-
options.yes = true;
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
if (!token.startsWith("--")) {
|
|
41
|
-
if (COMMANDS.has(token)) {
|
|
42
|
-
command = token;
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
throw new Error(`Unknown argument "${token}".`);
|
|
46
|
-
}
|
|
47
|
-
const key = token.slice(2);
|
|
48
|
-
if (!FLAG_KEYS.has(key)) {
|
|
49
|
-
throw new Error(`Unknown flag "${token}".`);
|
|
50
|
-
}
|
|
51
|
-
const value = argv[index + 1];
|
|
52
|
-
if (!value || value.startsWith("--")) {
|
|
53
|
-
throw new Error(`Flag "${token}" requires a value.`);
|
|
54
|
-
}
|
|
55
|
-
index += 1;
|
|
56
|
-
if (key === "skills" || key === "groups") {
|
|
57
|
-
options[key] = parseCsv(value);
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
if (key === "agent") {
|
|
61
|
-
const agents = parseCsv(value);
|
|
62
|
-
if (agents.some((agent) => !isAgent(agent))) {
|
|
63
|
-
throw new Error(`Invalid agent list "${value}". Use "codex" and/or "claude".`);
|
|
64
|
-
}
|
|
65
|
-
options.agents = agents;
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
if (key === "location") {
|
|
69
|
-
const locations = parseCsv(value);
|
|
70
|
-
if (locations.some((location) => !isInstallLocation(location))) {
|
|
71
|
-
throw new Error(`Invalid location list "${value}". Use "global" and/or "local".`);
|
|
72
|
-
}
|
|
73
|
-
options.locations = locations;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return { command, options };
|
|
77
|
-
}
|
|
78
|
-
export function printHelp() {
|
|
79
|
-
console.log(`ai-tools
|
|
80
|
-
|
|
81
|
-
Usage:
|
|
82
|
-
ai-tools
|
|
83
|
-
ai-tools install [options]
|
|
84
|
-
ai-tools help
|
|
85
|
-
|
|
86
|
-
Default behavior:
|
|
87
|
-
Running "ai-tools" in an interactive terminal opens a top-level menu.
|
|
88
|
-
Running "ai-tools install" starts the skills installer directly.
|
|
89
|
-
|
|
90
|
-
Options:
|
|
91
|
-
--skills <ids> Comma-separated individual skill ids
|
|
92
|
-
--groups <ids> Comma-separated group ids
|
|
93
|
-
--location <types> Comma-separated: global,local
|
|
94
|
-
--agent <agents> Comma-separated: codex,claude
|
|
95
|
-
--yes Skip overwrite prompts
|
|
96
|
-
--help, -h Show help
|
|
97
|
-
`);
|
|
98
|
-
}
|