@minhluudev/ai-tools 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -96
- package/dist/src/bin/ai-tools.js +1 -1
- package/dist/src/cli.js +155 -137
- 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 +86 -40
- package/dist/src/lib/tui-project-docs.js +56 -103
- package/dist/src/lib/tui-utils.js +361 -0
- package/dist/src/lib/tui-wizard.js +95 -152
- 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,29 +1,116 @@
|
|
|
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 { blessedConfirm } 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";
|
|
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
|
+
}
|
|
12
87
|
function printSectionHeader(title, subtitle) {
|
|
13
|
-
|
|
14
|
-
`AI-TOOLS :: ${title}`,
|
|
15
|
-
subtitle
|
|
16
|
-
];
|
|
17
|
-
const width = Math.max(...lines.map((line) => line.length)) + 4;
|
|
18
|
-
const border = "+".padEnd(width - 1, "-") + "+";
|
|
88
|
+
console.log(buildPanel(title, [subtitle], "info"));
|
|
19
89
|
console.log("");
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
console.log(
|
|
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));
|
|
95
|
+
console.log("");
|
|
96
|
+
}
|
|
97
|
+
function printBulletPanel(title, items, accent = "muted") {
|
|
98
|
+
console.log(buildPanel(title, items.map((item) => `- ${item}`), accent));
|
|
25
99
|
console.log("");
|
|
26
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
|
+
}
|
|
27
114
|
function printSkillSelectionSummary(input) {
|
|
28
115
|
const selectedSkillLabels = input.selectionCatalog.skills
|
|
29
116
|
.filter((skill) => input.selectedSkills.includes(skill.id))
|
|
@@ -31,68 +118,30 @@ function printSkillSelectionSummary(input) {
|
|
|
31
118
|
const selectedGroupLabels = input.selectionCatalog.groups
|
|
32
119
|
.filter((group) => input.selectedGroups.includes(group.id))
|
|
33
120
|
.map((group) => group.label);
|
|
34
|
-
|
|
35
|
-
|
|
121
|
+
const rows = [
|
|
122
|
+
["Skills", selectedSkillLabels.length ? selectedSkillLabels.join(", ") : "none"]
|
|
123
|
+
];
|
|
36
124
|
if (selectedGroupLabels.length > 0) {
|
|
37
|
-
|
|
125
|
+
rows.push(["Groups", selectedGroupLabels.join(", ")]);
|
|
38
126
|
}
|
|
39
|
-
|
|
40
|
-
|
|
127
|
+
rows.push(["Locations", input.locations.length ? input.locations.join(", ") : "none"], ["Agents", input.agents.length ? input.agents.join(", ") : "none"]);
|
|
128
|
+
printLabeledRows("Selected items", rows);
|
|
41
129
|
}
|
|
42
130
|
function printProjectDocsSelectionSummary(input) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
function ensureNonInteractiveInputs(selectionCatalog, options) {
|
|
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");
|
|
131
|
+
printLabeledRows("Selected items", [
|
|
132
|
+
["Skills", input.selectedSkills.map((skill) => skill.label).join(", ")],
|
|
133
|
+
["Install root", resolveProjectDocsRoot(input.cwd)]
|
|
134
|
+
]);
|
|
81
135
|
}
|
|
82
|
-
async function
|
|
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;
|
|
136
|
+
export async function runCli() {
|
|
91
137
|
while (true) {
|
|
92
|
-
const entryAction =
|
|
138
|
+
const entryAction = await runEntryMenu();
|
|
139
|
+
if (entryAction === "cancel") {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
93
142
|
if (entryAction === "install-libs") {
|
|
94
143
|
printSectionHeader("Install libs for AI", "Shared AI libraries and tooling are not implemented yet.");
|
|
95
|
-
|
|
144
|
+
printStatusLine("todo", "Install libs for AI is not implemented yet.", "warning");
|
|
96
145
|
return;
|
|
97
146
|
}
|
|
98
147
|
if (entryAction === "install-project-docs") {
|
|
@@ -100,73 +149,45 @@ export async function runCli(argv = process.argv) {
|
|
|
100
149
|
const projectDocsCatalog = await loadProjectDocsCatalog(config);
|
|
101
150
|
const projectDocsResult = await runProjectDocsWizard(projectDocsCatalog);
|
|
102
151
|
if ("backToMenu" in projectDocsResult) {
|
|
103
|
-
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
return;
|
|
152
|
+
continue;
|
|
107
153
|
}
|
|
108
154
|
printSectionHeader("Install project docs", "Preparing selected project docs for resolution and installation.");
|
|
109
155
|
printProjectDocsSelectionSummary({
|
|
110
156
|
selectedSkills: projectDocsResult.selectedSkills,
|
|
111
157
|
cwd: process.cwd()
|
|
112
158
|
});
|
|
113
|
-
|
|
159
|
+
printStatusLine("resolve", "Resolving selected sources...");
|
|
114
160
|
const client = createGitHubClient(config.github);
|
|
115
161
|
const plannedItems = planProjectDocsInstallations({
|
|
116
162
|
skills: projectDocsResult.selectedSkills,
|
|
117
163
|
cwd: process.cwd()
|
|
118
164
|
});
|
|
119
|
-
|
|
120
|
-
console.log("Installing...");
|
|
165
|
+
printStatusLine("install", "Installing selected project docs...");
|
|
121
166
|
const results = await installProjectDocsItems({
|
|
122
167
|
plannedItems,
|
|
123
168
|
client,
|
|
124
169
|
overwriteExisting: false,
|
|
125
170
|
onProgress(item) {
|
|
126
|
-
|
|
171
|
+
printStatusLine("write", formatInstallProgressLine(item), "muted");
|
|
127
172
|
}
|
|
128
173
|
});
|
|
129
|
-
|
|
130
|
-
console.log("Install complete");
|
|
131
|
-
for (const result of results) {
|
|
132
|
-
console.log(`- ${result.id}: ${result.targetPath}`);
|
|
133
|
-
}
|
|
174
|
+
printBulletPanel(`Install complete (${results.length})`, results.map((result) => `${result.id} -> ${result.targetPath}`), "success");
|
|
134
175
|
return;
|
|
135
176
|
}
|
|
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
|
-
}
|
|
177
|
+
// install-skills
|
|
148
178
|
const config = await loadPackageConfig();
|
|
149
179
|
const selectionCatalog = await loadSelectionCatalog(config);
|
|
150
180
|
if (selectionCatalog.skills.length === 0 && selectionCatalog.groups.length === 0) {
|
|
151
181
|
throw new Error("Selection catalog is empty. Add skills or groups before running the installer.");
|
|
152
182
|
}
|
|
153
|
-
const selectionResult = await
|
|
183
|
+
const selectionResult = await runTabbedWizard(selectionCatalog, "Install agent skills");
|
|
154
184
|
if ("backToMenu" in selectionResult) {
|
|
155
|
-
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
return;
|
|
185
|
+
continue;
|
|
159
186
|
}
|
|
160
187
|
const { selectedSkills, selectedGroups, locations, agents } = selectionResult;
|
|
161
188
|
printSectionHeader("Install agent skills", "Preparing selected skills for resolution and installation.");
|
|
162
|
-
printSkillSelectionSummary({
|
|
163
|
-
|
|
164
|
-
selectedSkills,
|
|
165
|
-
selectedGroups,
|
|
166
|
-
locations,
|
|
167
|
-
agents
|
|
168
|
-
});
|
|
169
|
-
console.log("Resolving selected sources...");
|
|
189
|
+
printSkillSelectionSummary({ selectionCatalog, selectedSkills, selectedGroups, locations, agents });
|
|
190
|
+
printStatusLine("resolve", "Resolving selected sources...");
|
|
170
191
|
const client = createGitHubClient(config.github);
|
|
171
192
|
const finalItems = await resolveSelectionItems({
|
|
172
193
|
client,
|
|
@@ -178,51 +199,48 @@ export async function runCli(argv = process.argv) {
|
|
|
178
199
|
if (finalItems.length === 0) {
|
|
179
200
|
throw new Error("No installable items were resolved from the selected sources.");
|
|
180
201
|
}
|
|
181
|
-
const plannedItems =
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
console.log("");
|
|
190
|
-
console.log("Existing targets detected:");
|
|
191
|
-
for (const item of existingTargets) {
|
|
192
|
-
console.log(`- ${item.id}: ${item.targetPath}`);
|
|
193
|
-
}
|
|
194
|
-
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
195
|
-
throw new Error("Existing targets require --yes in non-interactive mode.");
|
|
196
|
-
}
|
|
197
|
-
const prompt = createPromptSession();
|
|
198
|
-
try {
|
|
199
|
-
overwriteExisting = await promptConfirm(prompt, {
|
|
200
|
-
message: "Overwrite all existing targets?",
|
|
201
|
-
defaultValue: false
|
|
202
|
+
const plannedItems = [];
|
|
203
|
+
const skipped = [];
|
|
204
|
+
for (const location of locations) {
|
|
205
|
+
for (const agent of agents) {
|
|
206
|
+
const agentItems = planInstallations({
|
|
207
|
+
items: finalItems,
|
|
208
|
+
agent,
|
|
209
|
+
installRoot: resolveInstallRoot({ agent, location, cwd: process.cwd() })
|
|
202
210
|
});
|
|
211
|
+
plannedItems.push(...agentItems);
|
|
212
|
+
for (const item of finalItems) {
|
|
213
|
+
if (!agentItems.some((p) => p.id === item.id)) {
|
|
214
|
+
skipped.push(` - ${item.id} (no ${agent} target)`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
203
217
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
218
|
+
}
|
|
219
|
+
if (skipped.length > 0) {
|
|
220
|
+
printBulletPanel("Skipped targets", skipped.map((line) => line.trimStart().replace(/^- /, "")), "warning");
|
|
221
|
+
}
|
|
222
|
+
const existingTargets = await detectExistingTargets(plannedItems);
|
|
223
|
+
let overwriteExisting = false;
|
|
224
|
+
if (existingTargets.length > 0) {
|
|
225
|
+
printBulletPanel("Existing targets detected", existingTargets.map((item) => `${item.id} -> ${item.targetPath}`), "warning");
|
|
226
|
+
overwriteExisting = await blessedConfirm({
|
|
227
|
+
message: "Overwrite all existing targets?",
|
|
228
|
+
description: "Choose Yes to replace all detected targets, or No to cancel the installation."
|
|
229
|
+
});
|
|
207
230
|
if (!overwriteExisting) {
|
|
208
231
|
throw new Error("Installation cancelled because existing targets would be overwritten.");
|
|
209
232
|
}
|
|
210
233
|
}
|
|
211
|
-
|
|
212
|
-
console.log("Installing...");
|
|
234
|
+
printStatusLine("install", "Installing selected agent skills...");
|
|
213
235
|
const results = await installPlannedItems({
|
|
214
236
|
plannedItems,
|
|
215
237
|
client,
|
|
216
238
|
overwriteExisting,
|
|
217
239
|
onProgress(item) {
|
|
218
|
-
|
|
240
|
+
printStatusLine("write", formatInstallProgressLine(item), "muted");
|
|
219
241
|
}
|
|
220
242
|
});
|
|
221
|
-
|
|
222
|
-
console.log("Install complete");
|
|
223
|
-
for (const result of results) {
|
|
224
|
-
console.log(`- ${result.id}: ${result.targetPath}`);
|
|
225
|
-
}
|
|
243
|
+
printBulletPanel(`Install complete (${results.length})`, results.map((result) => `${result.id} -> ${result.targetPath}`), "success");
|
|
226
244
|
return;
|
|
227
245
|
}
|
|
228
246
|
}
|
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
|