@minhluudev/ai-tools 0.1.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 +17 -75
- package/dist/src/bin/ai-tools.js +9 -1
- package/dist/src/cli.js +159 -195
- package/dist/src/lib/catalog.js +50 -15
- package/dist/src/lib/config.js +2 -0
- package/dist/src/lib/github.js +11 -8
- package/dist/src/lib/install.js +90 -21
- package/dist/src/lib/project-docs-catalog.js +45 -0
- package/dist/src/lib/prompts.js +31 -85
- package/dist/src/lib/selection-catalog.js +140 -0
- package/dist/src/lib/tui-entry-menu.js +125 -0
- package/dist/src/lib/tui-project-docs.js +269 -0
- package/dist/src/lib/tui-utils.js +134 -0
- package/dist/src/lib/tui-wizard.js +380 -0
- package/package.json +10 -1
- package/project-docs-catalog.json +19 -0
- package/selection-catalog.json +19 -0
- package/dist/src/lib/args.js +0 -91
package/README.md
CHANGED
|
@@ -1,93 +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
|
-
|
|
14
|
-
The interactive installer asks for:
|
|
15
|
-
|
|
16
|
-
1. Individual skills from the `skill-general` branch
|
|
17
|
-
2. Skill groups from other branches such as `laravel-ddd`
|
|
18
|
-
3. Installation location: `global` or `local`
|
|
19
|
-
4. Target agent: `codex` or `claude`
|
|
20
|
-
|
|
21
|
-
Global installs write into:
|
|
22
|
-
|
|
23
|
-
- `~/.codex`
|
|
24
|
-
- `~/.claude`
|
|
25
|
-
|
|
26
|
-
Local installs write into:
|
|
27
|
-
|
|
28
|
-
- `./.codex`
|
|
29
|
-
- `./.claude`
|
|
30
|
-
|
|
31
|
-
## Manifest Contract
|
|
32
|
-
|
|
33
|
-
Each source branch must expose `ai-tools.catalog.json` at the branch root.
|
|
34
|
-
|
|
35
|
-
```json
|
|
36
|
-
{
|
|
37
|
-
"version": 1,
|
|
38
|
-
"type": "skills",
|
|
39
|
-
"label": "General Skills",
|
|
40
|
-
"description": "Standalone skills",
|
|
41
|
-
"items": [
|
|
42
|
-
{
|
|
43
|
-
"id": "laravel-code-reviewer",
|
|
44
|
-
"label": "Laravel Code Reviewer",
|
|
45
|
-
"description": "Review Laravel and PHP changes",
|
|
46
|
-
"sourcePath": "skills/laravel-code-reviewer",
|
|
47
|
-
"targets": {
|
|
48
|
-
"codex": {
|
|
49
|
-
"type": "directory",
|
|
50
|
-
"outputPath": "skills/laravel-code-reviewer"
|
|
51
|
-
},
|
|
52
|
-
"claude": {
|
|
53
|
-
"type": "file",
|
|
54
|
-
"outputPath": "agents/laravel-code-reviewer.md"
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
]
|
|
59
|
-
}
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
Rules:
|
|
63
|
-
|
|
64
|
-
- `skill-general` must use `"type": "skills"`
|
|
65
|
-
- group branches must use `"type": "group"`
|
|
66
|
-
- `sourcePath` and `outputPath` must stay inside the repository or install root
|
|
67
|
-
- each selected skill id must be unique across the final merged selection
|
|
68
|
-
|
|
69
|
-
## Non-Interactive Usage
|
|
11
|
+
## Usage
|
|
70
12
|
|
|
71
13
|
```bash
|
|
72
|
-
ai-tools
|
|
73
|
-
--skills laravel-code-reviewer,mql5-ui-designer \
|
|
74
|
-
--groups laravel-ddd \
|
|
75
|
-
--location local \
|
|
76
|
-
--agent codex \
|
|
77
|
-
--yes
|
|
14
|
+
ai-tools
|
|
78
15
|
```
|
|
79
16
|
|
|
80
|
-
|
|
17
|
+
Main menu:
|
|
81
18
|
|
|
82
|
-
|
|
19
|
+
1. `Install agent skills`
|
|
20
|
+
2. `Install project docs`
|
|
21
|
+
3. `Install libs for AI`
|
|
22
|
+
4. `Cancel`
|
|
83
23
|
|
|
84
|
-
|
|
85
|
-
- `.github/workflows/publish.yml` for npm publish on tags matching `v*.*.*` and manual dispatch
|
|
24
|
+
Controls:
|
|
86
25
|
|
|
87
|
-
|
|
26
|
+
- `← →` switch tabs
|
|
27
|
+
- `↑ ↓` move
|
|
28
|
+
- `space` or `enter` select
|
|
29
|
+
- `q` or `esc` cancel
|
|
88
30
|
|
|
89
|
-
|
|
31
|
+
`Install agent skills`
|
|
32
|
+
- installs selected skills into `~/.codex`, `~/.claude`, `./.codex`, or `./.claude`
|
|
90
33
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
```
|
|
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
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { runCli } from "../cli.js";
|
|
3
|
-
|
|
3
|
+
function isCancellationMessage(message) {
|
|
4
|
+
return message === "Installation cancelled."
|
|
5
|
+
|| message === "Installation cancelled because existing targets would be overwritten.";
|
|
6
|
+
}
|
|
7
|
+
runCli().catch((error) => {
|
|
4
8
|
const message = error instanceof Error ? error.message : String(error);
|
|
9
|
+
if (isCancellationMessage(message)) {
|
|
10
|
+
process.exitCode = 0;
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
5
13
|
console.error(`Error: ${message}`);
|
|
6
14
|
process.exitCode = 1;
|
|
7
15
|
});
|
package/dist/src/cli.js
CHANGED
|
@@ -1,214 +1,178 @@
|
|
|
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 { loadCatalogIndex, mergeSelectedItems } from "./lib/catalog.js";
|
|
5
|
-
import { createPromptSession, promptConfirm, promptMultiSelect, promptSingleSelect } from "./lib/prompts.js";
|
|
6
3
|
import { createGitHubClient } from "./lib/github.js";
|
|
7
|
-
import { detectExistingTargets, installPlannedItems, planInstallations, resolveInstallRoot } from "./lib/install.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return groups.map((group) => ({
|
|
22
|
-
value: group.id,
|
|
23
|
-
label: group.label,
|
|
24
|
-
description: `${group.description || "No description"} (${group.items.length} skill${group.items.length === 1 ? "" : "s"})`
|
|
25
|
-
}));
|
|
26
|
-
}
|
|
27
|
-
function printSelectionSummary(input) {
|
|
4
|
+
import { detectExistingTargets, installPlannedItems, installProjectDocsItems, planInstallations, planProjectDocsInstallations, resolveInstallRoot, resolveProjectDocsRoot } from "./lib/install.js";
|
|
5
|
+
import { loadProjectDocsCatalog } from "./lib/project-docs-catalog.js";
|
|
6
|
+
import { loadSelectionCatalog, resolveSelectionItems } from "./lib/selection-catalog.js";
|
|
7
|
+
import { blessedSelect } from "./lib/tui-utils.js";
|
|
8
|
+
import { runEntryMenu } from "./lib/tui-entry-menu.js";
|
|
9
|
+
import { runProjectDocsWizard } from "./lib/tui-project-docs.js";
|
|
10
|
+
import { runTabbedWizard } from "./lib/tui-wizard.js";
|
|
11
|
+
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, "-") + "+";
|
|
28
18
|
console.log("");
|
|
29
|
-
console.log(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
console.log(`- Root: ${input.installRoot}`);
|
|
33
|
-
console.log(`- Individual skills: ${input.selectedSkills.length ? input.selectedSkills.join(", ") : "none"}`);
|
|
34
|
-
console.log(`- Groups: ${input.selectedGroups.length ? input.selectedGroups.join(", ") : "none"}`);
|
|
35
|
-
console.log(`- Final items: ${input.plannedItems.map((item) => item.id).join(", ")}`);
|
|
36
|
-
}
|
|
37
|
-
async function resolveInteractiveSelections(index, options) {
|
|
38
|
-
const prompt = createPromptSession();
|
|
39
|
-
try {
|
|
40
|
-
const selectedSkills = options.skills.length > 0
|
|
41
|
-
? options.skills
|
|
42
|
-
: await promptMultiSelect(prompt, {
|
|
43
|
-
message: "Select individual skills",
|
|
44
|
-
choices: formatSelectionChoices(index.individualSkills),
|
|
45
|
-
allowEmpty: true
|
|
46
|
-
});
|
|
47
|
-
const selectedGroups = options.groups.length > 0
|
|
48
|
-
? options.groups
|
|
49
|
-
: await promptMultiSelect(prompt, {
|
|
50
|
-
message: "Select skill groups",
|
|
51
|
-
choices: formatGroupChoices(index.groups),
|
|
52
|
-
allowEmpty: true
|
|
53
|
-
});
|
|
54
|
-
const location = options.location ||
|
|
55
|
-
(await promptSingleSelect(prompt, {
|
|
56
|
-
message: "Select installation location",
|
|
57
|
-
choices: [
|
|
58
|
-
{
|
|
59
|
-
value: "global",
|
|
60
|
-
label: "global",
|
|
61
|
-
description: "Install into the current user's home directory."
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
value: "local",
|
|
65
|
-
label: "local",
|
|
66
|
-
description: "Install into this project's dot directories."
|
|
67
|
-
}
|
|
68
|
-
]
|
|
69
|
-
}));
|
|
70
|
-
const agent = options.agent ||
|
|
71
|
-
(await promptSingleSelect(prompt, {
|
|
72
|
-
message: "Select agent",
|
|
73
|
-
choices: [
|
|
74
|
-
{
|
|
75
|
-
value: "codex",
|
|
76
|
-
label: "codex",
|
|
77
|
-
description: "Install as Codex skills."
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
value: "claude",
|
|
81
|
-
label: "claude",
|
|
82
|
-
description: "Install as Claude custom agents."
|
|
83
|
-
}
|
|
84
|
-
]
|
|
85
|
-
}));
|
|
86
|
-
return { selectedSkills, selectedGroups, location, agent };
|
|
87
|
-
}
|
|
88
|
-
finally {
|
|
89
|
-
await prompt.close();
|
|
19
|
+
console.log(border);
|
|
20
|
+
for (const line of lines) {
|
|
21
|
+
console.log(`| ${line.padEnd(width - 4, " ")} |`);
|
|
90
22
|
}
|
|
23
|
+
console.log(border);
|
|
24
|
+
console.log("");
|
|
91
25
|
}
|
|
92
|
-
function
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
const unknownSkills = options.skills.filter((skillId) => !index.individualSkills.some((item) => item.id === skillId));
|
|
107
|
-
if (unknownSkills.length > 0) {
|
|
108
|
-
throw new Error(`Unknown skill id(s): ${unknownSkills.join(", ")}`);
|
|
109
|
-
}
|
|
110
|
-
const unknownGroups = options.groups.filter((groupId) => !index.groups.some((group) => group.id === groupId));
|
|
111
|
-
if (unknownGroups.length > 0) {
|
|
112
|
-
throw new Error(`Unknown group id(s): ${unknownGroups.join(", ")}`);
|
|
113
|
-
}
|
|
26
|
+
function printSkillSelectionSummary(input) {
|
|
27
|
+
const selectedSkillLabels = input.selectionCatalog.skills
|
|
28
|
+
.filter((skill) => input.selectedSkills.includes(skill.id))
|
|
29
|
+
.map((skill) => skill.label);
|
|
30
|
+
const selectedGroupLabels = input.selectionCatalog.groups
|
|
31
|
+
.filter((group) => input.selectedGroups.includes(group.id))
|
|
32
|
+
.map((group) => group.label);
|
|
33
|
+
console.log("Selected items:");
|
|
34
|
+
console.log(`- Skills: ${selectedSkillLabels.length ? selectedSkillLabels.join(", ") : "none"}`);
|
|
35
|
+
if (selectedGroupLabels.length > 0) {
|
|
36
|
+
console.log(`- Groups: ${selectedGroupLabels.join(", ")}`);
|
|
37
|
+
}
|
|
38
|
+
console.log(`- Locations: ${input.locations.length ? input.locations.join(", ") : "none"}`);
|
|
39
|
+
console.log(`- Agents: ${input.agents.length ? input.agents.join(", ") : "none"}`);
|
|
114
40
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
selectedSkills: options.skills,
|
|
120
|
-
selectedGroups: options.groups,
|
|
121
|
-
location: options.location,
|
|
122
|
-
agent: options.agent
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
return resolveInteractiveSelections(index, options);
|
|
41
|
+
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)}`);
|
|
126
45
|
}
|
|
127
|
-
export async function runCli(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
if (command !== "install") {
|
|
134
|
-
throw new Error(`Unsupported command "${command}". Only "install" is available.`);
|
|
135
|
-
}
|
|
136
|
-
const config = await loadPackageConfig();
|
|
137
|
-
const client = createGitHubClient(config.github);
|
|
138
|
-
console.log("Loading remote catalogs...");
|
|
139
|
-
const index = await loadCatalogIndex(client, config.github);
|
|
140
|
-
if (index.individualSkills.length === 0 && index.groups.length === 0) {
|
|
141
|
-
throw new Error("No installable skills or groups were found in the configured repository.");
|
|
142
|
-
}
|
|
143
|
-
const { selectedSkills, selectedGroups, location, agent } = await resolveSelections(index, options);
|
|
144
|
-
const finalItems = mergeSelectedItems({
|
|
145
|
-
individualSkills: index.individualSkills,
|
|
146
|
-
groups: index.groups,
|
|
147
|
-
selectedSkillIds: selectedSkills,
|
|
148
|
-
selectedGroupIds: selectedGroups
|
|
149
|
-
});
|
|
150
|
-
if (finalItems.length === 0) {
|
|
151
|
-
throw new Error("No skills were selected.");
|
|
152
|
-
}
|
|
153
|
-
const installRoot = resolveInstallRoot({ agent, location, cwd: process.cwd() });
|
|
154
|
-
const plannedItems = planInstallations({
|
|
155
|
-
items: finalItems,
|
|
156
|
-
agent,
|
|
157
|
-
installRoot
|
|
158
|
-
});
|
|
159
|
-
printSelectionSummary({
|
|
160
|
-
location,
|
|
161
|
-
agent,
|
|
162
|
-
installRoot,
|
|
163
|
-
selectedSkills,
|
|
164
|
-
selectedGroups,
|
|
165
|
-
plannedItems
|
|
166
|
-
});
|
|
167
|
-
const existingTargets = await detectExistingTargets(plannedItems);
|
|
168
|
-
let overwriteExisting = options.yes;
|
|
169
|
-
if (existingTargets.length > 0 && !overwriteExisting) {
|
|
170
|
-
console.log("");
|
|
171
|
-
console.log("Existing targets detected:");
|
|
172
|
-
for (const item of existingTargets) {
|
|
173
|
-
console.log(`- ${item.id}: ${item.targetPath}`);
|
|
46
|
+
export async function runCli() {
|
|
47
|
+
while (true) {
|
|
48
|
+
const entryAction = await runEntryMenu();
|
|
49
|
+
if (entryAction === "cancel") {
|
|
50
|
+
return;
|
|
174
51
|
}
|
|
175
|
-
if (
|
|
176
|
-
|
|
52
|
+
if (entryAction === "install-libs") {
|
|
53
|
+
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.");
|
|
55
|
+
return;
|
|
177
56
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
57
|
+
if (entryAction === "install-project-docs") {
|
|
58
|
+
const config = await loadPackageConfig();
|
|
59
|
+
const projectDocsCatalog = await loadProjectDocsCatalog(config);
|
|
60
|
+
const projectDocsResult = await runProjectDocsWizard(projectDocsCatalog);
|
|
61
|
+
if ("backToMenu" in projectDocsResult) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
printSectionHeader("Install project docs", "Preparing selected project docs for resolution and installation.");
|
|
65
|
+
printProjectDocsSelectionSummary({
|
|
66
|
+
selectedSkills: projectDocsResult.selectedSkills,
|
|
67
|
+
cwd: process.cwd()
|
|
68
|
+
});
|
|
69
|
+
console.log("Resolving selected sources...");
|
|
70
|
+
const client = createGitHubClient(config.github);
|
|
71
|
+
const plannedItems = planProjectDocsInstallations({
|
|
72
|
+
skills: projectDocsResult.selectedSkills,
|
|
73
|
+
cwd: process.cwd()
|
|
183
74
|
});
|
|
75
|
+
console.log("");
|
|
76
|
+
console.log("Installing...");
|
|
77
|
+
const results = await installProjectDocsItems({
|
|
78
|
+
plannedItems,
|
|
79
|
+
client,
|
|
80
|
+
overwriteExisting: false,
|
|
81
|
+
onProgress(item) {
|
|
82
|
+
console.log(`- ${item.id} from ${item.sourceBranch} -> ${item.targetPath}`);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
console.log("");
|
|
86
|
+
console.log("Install complete");
|
|
87
|
+
for (const result of results) {
|
|
88
|
+
console.log(`- ${result.id}: ${result.targetPath}`);
|
|
89
|
+
}
|
|
90
|
+
return;
|
|
184
91
|
}
|
|
185
|
-
|
|
186
|
-
|
|
92
|
+
// install-skills
|
|
93
|
+
const config = await loadPackageConfig();
|
|
94
|
+
const selectionCatalog = await loadSelectionCatalog(config);
|
|
95
|
+
if (selectionCatalog.skills.length === 0 && selectionCatalog.groups.length === 0) {
|
|
96
|
+
throw new Error("Selection catalog is empty. Add skills or groups before running the installer.");
|
|
187
97
|
}
|
|
188
|
-
|
|
189
|
-
|
|
98
|
+
const selectionResult = await runTabbedWizard(selectionCatalog, "Install agent skills");
|
|
99
|
+
if ("backToMenu" in selectionResult) {
|
|
100
|
+
continue;
|
|
190
101
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
102
|
+
const { selectedSkills, selectedGroups, locations, agents } = selectionResult;
|
|
103
|
+
printSectionHeader("Install agent skills", "Preparing selected skills for resolution and installation.");
|
|
104
|
+
printSkillSelectionSummary({ selectionCatalog, selectedSkills, selectedGroups, locations, agents });
|
|
105
|
+
console.log("Resolving selected sources...");
|
|
106
|
+
const client = createGitHubClient(config.github);
|
|
107
|
+
const finalItems = await resolveSelectionItems({
|
|
108
|
+
client,
|
|
109
|
+
config,
|
|
110
|
+
selectionCatalog,
|
|
111
|
+
selectedSkillIds: selectedSkills,
|
|
112
|
+
selectedGroupIds: selectedGroups
|
|
113
|
+
});
|
|
114
|
+
if (finalItems.length === 0) {
|
|
115
|
+
throw new Error("No installable items were resolved from the selected sources.");
|
|
116
|
+
}
|
|
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
|
+
}
|
|
141
|
+
const existingTargets = await detectExistingTargets(plannedItems);
|
|
142
|
+
let overwriteExisting = false;
|
|
143
|
+
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({
|
|
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";
|
|
157
|
+
if (!overwriteExisting) {
|
|
158
|
+
throw new Error("Installation cancelled because existing targets would be overwritten.");
|
|
159
|
+
}
|
|
200
160
|
}
|
|
201
|
-
});
|
|
202
|
-
console.log("");
|
|
203
|
-
console.log("Install complete");
|
|
204
|
-
for (const result of results) {
|
|
205
|
-
console.log(`- ${result.id}: ${result.targetPath}`);
|
|
206
|
-
}
|
|
207
|
-
if (index.warnings.length > 0) {
|
|
208
161
|
console.log("");
|
|
209
|
-
console.log("
|
|
210
|
-
|
|
211
|
-
|
|
162
|
+
console.log("Installing...");
|
|
163
|
+
const results = await installPlannedItems({
|
|
164
|
+
plannedItems,
|
|
165
|
+
client,
|
|
166
|
+
overwriteExisting,
|
|
167
|
+
onProgress(item) {
|
|
168
|
+
console.log(`- ${item.id} from ${item.sourceBranch} -> ${item.targetPath}`);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
console.log("");
|
|
172
|
+
console.log("Install complete");
|
|
173
|
+
for (const result of results) {
|
|
174
|
+
console.log(`- ${result.id}: ${result.targetPath}`);
|
|
212
175
|
}
|
|
176
|
+
return;
|
|
213
177
|
}
|
|
214
178
|
}
|
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) => ({
|
|
@@ -86,25 +89,57 @@ export function validateManifest(rawManifest, input) {
|
|
|
86
89
|
function isSkillGroup(group) {
|
|
87
90
|
return group !== null;
|
|
88
91
|
}
|
|
92
|
+
async function tryLoadManifest(client, input) {
|
|
93
|
+
try {
|
|
94
|
+
const rawManifest = await client.fetchManifest(input);
|
|
95
|
+
return validateManifest(rawManifest, {
|
|
96
|
+
branch: input.branch,
|
|
97
|
+
manifestPath: input.manifestPath
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
89
104
|
export async function loadCatalogIndex(client, githubConfig) {
|
|
90
105
|
const warnings = [];
|
|
91
106
|
const branches = await client.listBranches();
|
|
92
107
|
const branchMap = new Map(branches.map((branch) => [branch.name, branch]));
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
108
|
+
const configuredSkillsBranch = branchMap.get(githubConfig.skillsBranch);
|
|
109
|
+
const defaultBranch = branchMap.get(githubConfig.defaultBranch);
|
|
110
|
+
let skillsBranch = configuredSkillsBranch;
|
|
111
|
+
let skillManifest = null;
|
|
112
|
+
if (configuredSkillsBranch) {
|
|
113
|
+
skillManifest = await tryLoadManifest(client, {
|
|
114
|
+
branch: configuredSkillsBranch.name,
|
|
115
|
+
sha: configuredSkillsBranch.sha,
|
|
116
|
+
manifestPath: githubConfig.manifestPath
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
if (!skillManifest && defaultBranch) {
|
|
120
|
+
const defaultManifest = await tryLoadManifest(client, {
|
|
121
|
+
branch: defaultBranch.name,
|
|
122
|
+
sha: defaultBranch.sha,
|
|
123
|
+
manifestPath: githubConfig.manifestPath
|
|
124
|
+
});
|
|
125
|
+
if (defaultManifest) {
|
|
126
|
+
skillsBranch = defaultBranch;
|
|
127
|
+
skillManifest = defaultManifest;
|
|
128
|
+
if (!configuredSkillsBranch) {
|
|
129
|
+
warnings.push(`Configured skills branch "${githubConfig.skillsBranch}" was not found. Falling back to "${defaultBranch.name}".`);
|
|
130
|
+
}
|
|
131
|
+
else if (configuredSkillsBranch.name !== defaultBranch.name) {
|
|
132
|
+
warnings.push(`Configured skills branch "${githubConfig.skillsBranch}" does not contain a valid manifest. Falling back to "${defaultBranch.name}".`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (!skillsBranch || !skillManifest) {
|
|
137
|
+
const availableBranches = branches.map((branch) => branch.name).join(", ") || "none";
|
|
138
|
+
throw new Error(`Could not load skills catalog. Expected "${githubConfig.manifestPath}" in branch "${githubConfig.skillsBranch}"` +
|
|
139
|
+
` or fallback branch "${githubConfig.defaultBranch}". Available branches: ${availableBranches}.`);
|
|
96
140
|
}
|
|
97
|
-
const skillManifestRaw = await client.fetchManifest({
|
|
98
|
-
branch: skillsBranch.name,
|
|
99
|
-
sha: skillsBranch.sha,
|
|
100
|
-
manifestPath: githubConfig.manifestPath
|
|
101
|
-
});
|
|
102
|
-
const skillManifest = validateManifest(skillManifestRaw, {
|
|
103
|
-
branch: skillsBranch.name,
|
|
104
|
-
manifestPath: githubConfig.manifestPath
|
|
105
|
-
});
|
|
106
141
|
const excludedBranches = new Set([
|
|
107
|
-
|
|
142
|
+
skillsBranch.name,
|
|
108
143
|
...githubConfig.excludeBranches,
|
|
109
144
|
githubConfig.defaultBranch
|
|
110
145
|
]);
|
package/dist/src/lib/config.js
CHANGED
|
@@ -12,6 +12,8 @@ export async function loadPackageConfig() {
|
|
|
12
12
|
}
|
|
13
13
|
return {
|
|
14
14
|
packageRoot: PACKAGE_ROOT,
|
|
15
|
+
selectionCatalogPath: aiTools.selectionCatalogPath || "selection-catalog.json",
|
|
16
|
+
projectDocsCatalogPath: aiTools.projectDocsCatalogPath || "project-docs-catalog.json",
|
|
15
17
|
github: {
|
|
16
18
|
owner: aiTools.github.owner,
|
|
17
19
|
repo: aiTools.github.repo,
|
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);
|
|
@@ -89,12 +89,15 @@ export function createGitHubClient(config) {
|
|
|
89
89
|
async function getArchive(input) {
|
|
90
90
|
await ensureDirectory(archiveCacheRoot);
|
|
91
91
|
const archivePath = path.join(archiveCacheRoot, `${input.branch}-${input.sha}.tar.gz`);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
92
|
+
const shouldBypassCache = input.sha === "latest";
|
|
93
|
+
if (!shouldBypassCache) {
|
|
94
|
+
try {
|
|
95
|
+
await stat(archivePath);
|
|
96
|
+
return archivePath;
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
// Download on cache miss.
|
|
100
|
+
}
|
|
98
101
|
}
|
|
99
102
|
const archiveUrl = `https://codeload.github.com/${config.owner}/${config.repo}/tar.gz/refs/heads/${encodeURIComponent(input.branch)}`;
|
|
100
103
|
const response = await fetch(archiveUrl, {
|