@rbbtsn0w/adg 0.10.1-dev.pr150.a0bbc4c → 0.10.1-dev.pr152.b8c43a6
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 +9 -0
- package/dist/src/sources.js +3 -1
- package/dist/vendor/skills/src/add.js +594 -278
- package/dist/vendor/skills/src/agents.js +42 -7
- package/dist/vendor/skills/src/blob.js +92 -38
- package/dist/vendor/skills/src/cli.js +54 -26
- package/dist/vendor/skills/src/download-source.js +9 -6
- package/dist/vendor/skills/src/frontmatter.js +1 -1
- package/dist/vendor/skills/src/git.js +83 -2
- package/dist/vendor/skills/src/install.js +23 -12
- package/dist/vendor/skills/src/installer.js +64 -38
- package/dist/vendor/skills/src/local-lock.js +18 -7
- package/dist/vendor/skills/src/notion-test.js +440 -0
- package/dist/vendor/skills/src/prompts/search-multiselect.js +22 -0
- package/dist/vendor/skills/src/remove.js +31 -10
- package/dist/vendor/skills/src/skill-relocation.js +56 -0
- package/dist/vendor/skills/src/skills-field.js +50 -0
- package/dist/vendor/skills/src/skills.js +73 -53
- package/dist/vendor/skills/src/source-parser.js +75 -1
- package/dist/vendor/skills/src/sync.js +606 -186
- package/dist/vendor/skills/src/telemetry.js +1 -1
- package/dist/vendor/skills/src/test-utils.js +5 -8
- package/dist/vendor/skills/src/update.js +135 -50
- package/dist/vendor/skills/src/use.js +2 -1
- package/package.json +1 -1
- package/vendor/skills/PROVENANCE.md +130 -10
- package/vendor/skills/ThirdPartyNoticeText.txt +4 -4
|
@@ -1,16 +1,38 @@
|
|
|
1
1
|
import * as p from '@clack/prompts';
|
|
2
2
|
import pc from 'picocolors';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { existsSync } from 'fs';
|
|
4
|
+
import { glob, lstat, readdir, readFile, readlink, realpath, rm } from 'fs/promises';
|
|
5
|
+
import { basename, dirname, join, posix, relative, resolve, sep } from 'path';
|
|
6
|
+
import { parse as parseYaml } from 'yaml';
|
|
5
7
|
import { homedir } from 'os';
|
|
6
|
-
import { parseSkillMd } from './skills.js';
|
|
7
|
-
import { installSkillForAgent, getCanonicalPath } from './installer.js';
|
|
8
|
+
import { hasSkillMd, parseSkillMd } from './skills.js';
|
|
9
|
+
import { installSkillForAgent, getCanonicalPath, getCanonicalSkillsDir, getInstallPath, sanitizeName, } from './installer.js';
|
|
8
10
|
import { detectInstalledAgents, agents, getUniversalAgents, getVisibleUniversalAgents, getNonUniversalAgents, } from './agents.js';
|
|
9
11
|
import { searchMultiselect } from './prompts/search-multiselect.js';
|
|
10
|
-
import { addSkillToLocalLock, computeSkillFolderHash, readLocalLock } from './local-lock.js';
|
|
12
|
+
import { addSkillToLocalLock, computeSkillFolderHash, readLocalLock, writeLocalLock, } from './local-lock.js';
|
|
11
13
|
import { track } from './telemetry.js';
|
|
12
14
|
import { detectAgent, getAgentType } from './detect-agent.js';
|
|
15
|
+
import { getLastSelectedAgents, saveSelectedAgents } from './skill-lock.js';
|
|
16
|
+
import { parseSkillsField } from './skills-field.js';
|
|
17
|
+
import { getProjectLockSource, installFromSource } from './add.js';
|
|
13
18
|
const isCancelled = (value) => typeof value === 'symbol';
|
|
19
|
+
/**
|
|
20
|
+
* `<package>` matches every skill of a package, `<package>#<skill>` one of them.
|
|
21
|
+
* Both parts are globs. Package names cannot contain `#`, so the split is unambiguous.
|
|
22
|
+
*/
|
|
23
|
+
function matchesSkill(skill, patterns) {
|
|
24
|
+
return patterns.some((pattern) => {
|
|
25
|
+
const hash = pattern.indexOf('#');
|
|
26
|
+
const packagePattern = hash === -1 ? pattern : pattern.slice(0, hash);
|
|
27
|
+
const skillPattern = hash === -1 ? '**' : pattern.slice(hash + 1);
|
|
28
|
+
return (posix.matchesGlob(skill.packageName, packagePattern) &&
|
|
29
|
+
posix.matchesGlob(sanitizeName(skill.name), skillPattern));
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function allowedByFilters(skill, { include, exclude }) {
|
|
33
|
+
return ((!include?.length || matchesSkill(skill, include)) &&
|
|
34
|
+
!(exclude?.length && matchesSkill(skill, exclude)));
|
|
35
|
+
}
|
|
14
36
|
/**
|
|
15
37
|
* Shortens a path for display: replaces homedir with ~ and cwd with .
|
|
16
38
|
*/
|
|
@@ -24,92 +46,408 @@ function shortenPath(fullPath, cwd) {
|
|
|
24
46
|
}
|
|
25
47
|
return fullPath;
|
|
26
48
|
}
|
|
49
|
+
async function readPackageJson(dir) {
|
|
50
|
+
try {
|
|
51
|
+
return JSON.parse(await readFile(join(dir, 'package.json'), 'utf-8'));
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async function discoverPackageSkills(pkgDir, packageName, depth) {
|
|
58
|
+
const pkg = await readPackageJson(pkgDir);
|
|
59
|
+
if (!pkg)
|
|
60
|
+
return []; // not installed
|
|
61
|
+
const rootSkill = (await hasSkillMd(pkgDir))
|
|
62
|
+
? await parseSkillMd(join(pkgDir, 'SKILL.md'))
|
|
63
|
+
: null;
|
|
64
|
+
if (rootSkill) {
|
|
65
|
+
return [
|
|
66
|
+
{ ...rootSkill, packageName, packageVersion: pkg.version, skillPath: 'SKILL.md', depth },
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
const skills = [];
|
|
70
|
+
for (const dir of ['skills', 'dist/skills']) {
|
|
71
|
+
for (const name of await readdir(join(pkgDir, dir)).catch(() => [])) {
|
|
72
|
+
const skillDir = join(pkgDir, dir, name);
|
|
73
|
+
if (!(await hasSkillMd(skillDir)))
|
|
74
|
+
continue;
|
|
75
|
+
const skill = await parseSkillMd(join(skillDir, 'SKILL.md'));
|
|
76
|
+
if (skill) {
|
|
77
|
+
skills.push({
|
|
78
|
+
...skill,
|
|
79
|
+
packageName,
|
|
80
|
+
packageVersion: pkg.version,
|
|
81
|
+
skillPath: `${dir}/${name}/SKILL.md`,
|
|
82
|
+
depth,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return skills;
|
|
88
|
+
}
|
|
27
89
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* Returns discovered skills with their source package name.
|
|
90
|
+
* Node's node_modules lookup from `from` (realpath, then walk up), so the
|
|
91
|
+
* declaring package's own dependencies resolve in pnpm's isolated layout.
|
|
31
92
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
93
|
+
function findInstalledPackage(from, name) {
|
|
94
|
+
for (let dir = from;; dir = dirname(dir)) {
|
|
95
|
+
const candidate = join(dir, 'node_modules', name);
|
|
96
|
+
if (existsSync(join(candidate, 'package.json')))
|
|
97
|
+
return candidate;
|
|
98
|
+
if (dirname(dir) === dir)
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function remoteAllowsSkill(request, name, options) {
|
|
103
|
+
return request.declarers.some((packageName) => allowedByFilters({ name, packageName }, options));
|
|
104
|
+
}
|
|
105
|
+
/** Drop excluded packages before fetching; skill patterns are also applied after discovery. */
|
|
106
|
+
function filterRemoteRequests(requests, options) {
|
|
107
|
+
return requests.flatMap((request) => {
|
|
108
|
+
const declarers = request.declarers.filter((name) => (!options.include?.length ||
|
|
109
|
+
options.include.some((p) => posix.matchesGlob(name, p.split('#')[0]))) &&
|
|
110
|
+
!options.exclude?.some((p) => !p.includes('#') && posix.matchesGlob(name, p)));
|
|
111
|
+
if (declarers.length === 0)
|
|
112
|
+
return [];
|
|
113
|
+
const filtered = { ...request, via: declarers[0], declarers };
|
|
114
|
+
if (request.skills.length === 0)
|
|
115
|
+
return [filtered];
|
|
116
|
+
const skills = request.skills.filter((name) => remoteAllowsSkill(filtered, name, options));
|
|
117
|
+
return skills.length > 0 ? [{ ...filtered, skills }] : [];
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
function requestsLockedSkill(request, name, entry) {
|
|
121
|
+
return (isFromRequest(entry, request) &&
|
|
122
|
+
(request.skills.length === 0 ||
|
|
123
|
+
request.skills.some((selected) => sanitizeName(selected) === sanitizeName(name) ||
|
|
124
|
+
selected === posix.basename(posix.dirname(entry.skillPath ?? '')))));
|
|
125
|
+
}
|
|
126
|
+
/** Every package the project declares; a missing one (e.g. an omitted optional) is skipped. */
|
|
127
|
+
const DEPENDENCY_FIELDS = [
|
|
128
|
+
'dependencies',
|
|
129
|
+
'devDependencies',
|
|
130
|
+
'optionalDependencies',
|
|
131
|
+
'peerDependencies',
|
|
132
|
+
];
|
|
133
|
+
/**
|
|
134
|
+
* Find skills shipped by the project's direct dependencies, plus the skills
|
|
135
|
+
* that `npm:` entries in `skills` fields point at. Fields are read from the
|
|
136
|
+
* project and its direct dependencies, then from every `npm:` target in turn.
|
|
137
|
+
*
|
|
138
|
+
* Only packages listed in package.json are scanned, so a transitive package
|
|
139
|
+
* reaches the agent only when a direct dependency names it, and the package
|
|
140
|
+
* manager's version resolution decides which copy of a package is seen.
|
|
141
|
+
*/
|
|
142
|
+
/** Directories of the workspace packages declared in pnpm-workspace.yaml or package.json. */
|
|
143
|
+
async function findWorkspacePackages(cwd, pkg) {
|
|
144
|
+
const patterns = [
|
|
145
|
+
...(Array.isArray(pkg.workspaces) ? pkg.workspaces : (pkg.workspaces?.packages ?? [])),
|
|
146
|
+
];
|
|
36
147
|
try {
|
|
37
|
-
|
|
148
|
+
const pnpm = parseYaml(await readFile(join(cwd, 'pnpm-workspace.yaml'), 'utf-8'));
|
|
149
|
+
if (pnpm && typeof pnpm === 'object' && 'packages' in pnpm && Array.isArray(pnpm.packages)) {
|
|
150
|
+
patterns.push(...pnpm.packages.filter((p) => typeof p === 'string'));
|
|
151
|
+
}
|
|
38
152
|
}
|
|
39
153
|
catch {
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
154
|
+
// no pnpm workspace
|
|
155
|
+
}
|
|
156
|
+
const negated = patterns.filter((p) => p.startsWith('!')).map((p) => p.slice(1));
|
|
157
|
+
const included = patterns.filter((p) => !p.startsWith('!'));
|
|
158
|
+
const dirs = new Set();
|
|
159
|
+
for await (const file of glob(included.map((p) => posix.join(p, 'package.json')), { cwd, exclude: (path) => basename(path) === 'node_modules' })) {
|
|
160
|
+
const dir = dirname(file).split(sep).join('/');
|
|
161
|
+
if (dir !== '.' && !negated.some((n) => posix.matchesGlob(dir, n)))
|
|
162
|
+
dirs.add(join(cwd, dir));
|
|
163
|
+
}
|
|
164
|
+
return [...dirs].sort();
|
|
165
|
+
}
|
|
166
|
+
async function discoverNodeModuleSkills(cwd, recursive) {
|
|
167
|
+
const warnings = [];
|
|
168
|
+
const errors = [];
|
|
169
|
+
// identical requests from several packages are one
|
|
170
|
+
const remote = new Map();
|
|
171
|
+
const pkg = await readPackageJson(cwd);
|
|
172
|
+
if (!pkg)
|
|
173
|
+
return { skills: [], remote: [], warnings, errors };
|
|
174
|
+
const skills = [];
|
|
175
|
+
const seen = new Set();
|
|
176
|
+
const add = async (found) => {
|
|
177
|
+
for (const skill of found) {
|
|
178
|
+
const key = await realpath(skill.path).catch(() => skill.path);
|
|
179
|
+
if (seen.has(key))
|
|
180
|
+
continue;
|
|
181
|
+
seen.add(key);
|
|
182
|
+
skills.push(skill);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
// the project, then with --recursive each workspace package, one level further away
|
|
186
|
+
const projects = [{ name: '.', dir: cwd, pkg, depth: 0 }];
|
|
187
|
+
for (const dir of recursive ? await findWorkspacePackages(cwd, pkg) : []) {
|
|
188
|
+
const workspacePkg = await readPackageJson(dir);
|
|
189
|
+
const name = workspacePkg?.name ?? relative(cwd, dir).split(sep).join('/');
|
|
190
|
+
if (workspacePkg)
|
|
191
|
+
projects.push({ name, dir, pkg: workspacePkg, depth: 1 });
|
|
192
|
+
}
|
|
193
|
+
// `depth` is what this declarer's npm: targets get
|
|
194
|
+
const declarers = [];
|
|
195
|
+
for (const project of projects) {
|
|
196
|
+
const deps = new Set(DEPENDENCY_FIELDS.flatMap((field) => Object.keys(project.pkg[field] ?? {})));
|
|
197
|
+
const installed = [...deps].flatMap((name) => {
|
|
198
|
+
const dir = findInstalledPackage(project.dir, name);
|
|
199
|
+
return dir ? [{ name, dir }] : [];
|
|
200
|
+
});
|
|
201
|
+
const shipped = await Promise.all(installed.map(({ name, dir }) => discoverPackageSkills(dir, name, project.depth)));
|
|
202
|
+
await add(shipped.flat());
|
|
203
|
+
declarers.push({ name: project.name, dir: project.dir, depth: project.depth }, ...installed.map(({ name, dir }) => ({ name, dir, depth: project.depth + 1 })));
|
|
204
|
+
}
|
|
205
|
+
const visited = new Set();
|
|
206
|
+
for (const declarer of declarers) {
|
|
207
|
+
const dir = await realpath(declarer.dir).catch(() => null);
|
|
208
|
+
if (!dir || visited.has(dir))
|
|
209
|
+
continue;
|
|
210
|
+
visited.add(dir);
|
|
211
|
+
// the project's own field must be valid; a dependency's only produces warnings
|
|
212
|
+
const problems = declarer.name === '.' ? errors : warnings;
|
|
213
|
+
const field = (await readPackageJson(dir))?.skills;
|
|
214
|
+
if (field === undefined)
|
|
215
|
+
continue;
|
|
216
|
+
if (!Array.isArray(field)) {
|
|
217
|
+
// a dependency may use the key for something else
|
|
218
|
+
if (problems === errors)
|
|
219
|
+
errors.push('package.json: "skills" must be an array');
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
const parsed = parseSkillsField(field, declarer.name);
|
|
223
|
+
problems.push(...parsed.errors);
|
|
224
|
+
for (const request of parsed.remote) {
|
|
225
|
+
const { url, ref, subpath } = request.parsed;
|
|
226
|
+
const key = JSON.stringify([url, ref, subpath, request.skills]);
|
|
227
|
+
const existing = remote.get(key);
|
|
228
|
+
if (existing) {
|
|
229
|
+
if (!existing.declarers.includes(declarer.name))
|
|
230
|
+
existing.declarers.push(declarer.name);
|
|
69
231
|
}
|
|
70
|
-
|
|
71
|
-
|
|
232
|
+
else {
|
|
233
|
+
remote.set(key, { ...request, via: declarer.name, declarers: [declarer.name] });
|
|
72
234
|
}
|
|
73
235
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
const s = await stat(fullPath);
|
|
81
|
-
if (!s.isDirectory())
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
catch {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
if (name.startsWith('@')) {
|
|
88
|
-
// Scoped package: read @org/* entries
|
|
89
|
-
try {
|
|
90
|
-
const scopeNames = await readdir(fullPath);
|
|
91
|
-
await Promise.all(scopeNames.map(async (scopedName) => {
|
|
92
|
-
const scopedPath = join(fullPath, scopedName);
|
|
93
|
-
try {
|
|
94
|
-
const s = await stat(scopedPath);
|
|
95
|
-
if (!s.isDirectory())
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
catch {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
await processPackageDir(scopedPath, `${name}/${scopedName}`);
|
|
102
|
-
}));
|
|
236
|
+
for (const request of parsed.npm) {
|
|
237
|
+
const target = findInstalledPackage(dir, request.package);
|
|
238
|
+
if (!target) {
|
|
239
|
+
problems.push(`${declarer.name}: cannot resolve "npm:${request.package}"; is it a dependency?`);
|
|
240
|
+
continue;
|
|
103
241
|
}
|
|
104
|
-
|
|
105
|
-
|
|
242
|
+
const found = await discoverPackageSkills(target, request.package, declarer.depth);
|
|
243
|
+
await add(found
|
|
244
|
+
.filter((skill) => request.skills.length === 0 ||
|
|
245
|
+
request.skills.includes(basename(skill.path)) ||
|
|
246
|
+
request.skills.includes(sanitizeName(skill.name)))
|
|
247
|
+
.map((skill) => ({ ...skill, via: declarer.name })));
|
|
248
|
+
declarers.push({ name: request.package, dir: target, depth: declarer.depth + 1 });
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return { skills, remote: [...remote.values()], warnings, errors };
|
|
252
|
+
}
|
|
253
|
+
function isUnderNodeModules(path) {
|
|
254
|
+
return path.split(sep).includes('node_modules');
|
|
255
|
+
}
|
|
256
|
+
/** Sync installed this skill: shipped by a package, or requested by a `skills` field. */
|
|
257
|
+
function installedBySync(entry) {
|
|
258
|
+
return entry?.sourceType === 'node_modules' || entry?.via !== undefined;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Why `dest` must not be touched, or null when it is free or already ours.
|
|
262
|
+
* Sync owns a symlink whose target is in node_modules or is the canonical dir,
|
|
263
|
+
* and a real directory whose lock entry sync wrote.
|
|
264
|
+
*/
|
|
265
|
+
async function foreignDestination(dest, canonicalDir, lockEntry, cwd) {
|
|
266
|
+
let stats;
|
|
267
|
+
try {
|
|
268
|
+
stats = await lstat(dest);
|
|
269
|
+
}
|
|
270
|
+
catch {
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
if (stats.isSymbolicLink()) {
|
|
274
|
+
const target = resolve(dirname(dest), await readlink(dest));
|
|
275
|
+
if (isUnderNodeModules(target) || target === canonicalDir)
|
|
276
|
+
return null;
|
|
277
|
+
return `${shortenPath(dest, cwd)} is a symlink to ${shortenPath(target, cwd)}`;
|
|
278
|
+
}
|
|
279
|
+
if (installedBySync(lockEntry))
|
|
280
|
+
return null;
|
|
281
|
+
return `${shortenPath(dest, cwd)} already exists and was not installed by sync`;
|
|
282
|
+
}
|
|
283
|
+
async function linksIntoNodeModules(path) {
|
|
284
|
+
try {
|
|
285
|
+
if (!(await lstat(path)).isSymbolicLink())
|
|
286
|
+
return false;
|
|
287
|
+
return isUnderNodeModules(resolve(dirname(path), await readlink(path)));
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Remove skills that sync installed earlier and nothing provides anymore.
|
|
295
|
+
* A name is a candidate when its lock entry comes from node_modules, or from a
|
|
296
|
+
* remote `skills` entry that `keepRemote` rejects, or when its canonical dir
|
|
297
|
+
* links into node_modules. Only destinations sync owns are removed.
|
|
298
|
+
*/
|
|
299
|
+
async function pruneStaleSkills(cwd, keep, keepRemote, lock, dryRun) {
|
|
300
|
+
const canonicalBase = getCanonicalSkillsDir(false, cwd);
|
|
301
|
+
const lockKeys = new Map();
|
|
302
|
+
const explicit = new Set();
|
|
303
|
+
for (const [key, entry] of Object.entries(lock.skills)) {
|
|
304
|
+
const remote = entry.sourceType !== 'node_modules';
|
|
305
|
+
if (installedBySync(entry) && !(remote && keepRemote(entry, key))) {
|
|
306
|
+
lockKeys.set(sanitizeName(key), key);
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
explicit.add(sanitizeName(key));
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
const candidates = new Set(lockKeys.keys());
|
|
313
|
+
for (const name of await readdir(canonicalBase).catch(() => [])) {
|
|
314
|
+
if (await linksIntoNodeModules(join(canonicalBase, name)))
|
|
315
|
+
candidates.add(name);
|
|
316
|
+
}
|
|
317
|
+
const stale = [...candidates].filter((name) => !keep.has(name) && !explicit.has(name)).sort();
|
|
318
|
+
if (dryRun || stale.length === 0)
|
|
319
|
+
return stale;
|
|
320
|
+
const allAgents = Object.keys(agents);
|
|
321
|
+
for (const name of stale) {
|
|
322
|
+
const canonicalDir = join(canonicalBase, name);
|
|
323
|
+
const key = lockKeys.get(name);
|
|
324
|
+
const lockEntry = key ? lock.skills[key] : undefined;
|
|
325
|
+
const destinations = new Set([
|
|
326
|
+
canonicalDir,
|
|
327
|
+
...allAgents.map((agent) => getInstallPath(name, agent, { cwd })),
|
|
328
|
+
]);
|
|
329
|
+
for (const dest of destinations) {
|
|
330
|
+
if (!(await foreignDestination(dest, canonicalDir, lockEntry, cwd))) {
|
|
331
|
+
await rm(dest, { recursive: true, force: true });
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
if (key)
|
|
335
|
+
delete lock.skills[key];
|
|
336
|
+
}
|
|
337
|
+
await writeLocalLock(lock, cwd);
|
|
338
|
+
return stale;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Why sync must not install `name`, or null: a skill installed with
|
|
342
|
+
* `skills add` is never shadowed, and a destination sync does not own is
|
|
343
|
+
* never replaced.
|
|
344
|
+
*/
|
|
345
|
+
async function blockedReason(name, targetAgents, lockEntry, cwd) {
|
|
346
|
+
if (lockEntry && !installedBySync(lockEntry)) {
|
|
347
|
+
return `installed with \`skills add\` from ${lockEntry.source}`;
|
|
348
|
+
}
|
|
349
|
+
const canonicalDir = getCanonicalPath(name, { cwd });
|
|
350
|
+
const destinations = new Set([
|
|
351
|
+
canonicalDir,
|
|
352
|
+
...targetAgents.map((agent) => getInstallPath(name, agent, { cwd })),
|
|
353
|
+
]);
|
|
354
|
+
for (const dest of destinations) {
|
|
355
|
+
const reason = await foreignDestination(dest, canonicalDir, lockEntry, cwd);
|
|
356
|
+
if (reason)
|
|
357
|
+
return reason;
|
|
358
|
+
}
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Conflict rules for shipped skills, in order:
|
|
363
|
+
* 1. a skill from a direct dependency wins over one from a transitive package
|
|
364
|
+
* 2. two packages at the same depth shipping the same skill name install neither
|
|
365
|
+
* 3. blockedReason: never shadow `skills add`, never replace what sync does not own
|
|
366
|
+
*
|
|
367
|
+
* A shipped skill replaces one that a remote `skills` entry installed.
|
|
368
|
+
*/
|
|
369
|
+
async function resolveConflicts(skills, targetAgents, lockSkills, cwd) {
|
|
370
|
+
const lockBySanitizedName = new Map(Object.entries(lockSkills).map(([name, entry]) => [sanitizeName(name), entry]));
|
|
371
|
+
// ADG patch: keep the vendored source compatible with the ES2023 build target.
|
|
372
|
+
const byName = new Map();
|
|
373
|
+
for (const skill of skills) {
|
|
374
|
+
const name = sanitizeName(skill.name);
|
|
375
|
+
const group = byName.get(name) ?? [];
|
|
376
|
+
group.push(skill);
|
|
377
|
+
byName.set(name, group);
|
|
378
|
+
}
|
|
379
|
+
const install = [];
|
|
380
|
+
const skipped = [];
|
|
381
|
+
for (const [name, all] of byName) {
|
|
382
|
+
// A direct dependency (or the project's own field) wins over a transitive package
|
|
383
|
+
const depth = Math.min(...all.map((c) => c.depth));
|
|
384
|
+
const candidates = all.filter((c) => c.depth === depth);
|
|
385
|
+
for (const skill of all.filter((c) => c.depth !== depth)) {
|
|
386
|
+
skipped.push({ skill, reason: `${candidates[0].packageName} is closer to the project` });
|
|
387
|
+
}
|
|
388
|
+
if (candidates.length > 1) {
|
|
389
|
+
const packages = candidates.map((c) => c.packageName).join(', ');
|
|
390
|
+
for (const skill of candidates) {
|
|
391
|
+
skipped.push({
|
|
392
|
+
skill,
|
|
393
|
+
reason: `shipped by ${packages}; drop this one with --exclude ${skill.packageName}#${name}`,
|
|
394
|
+
});
|
|
106
395
|
}
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
const skill = candidates[0];
|
|
399
|
+
const reason = await blockedReason(name, targetAgents, lockBySanitizedName.get(name), cwd);
|
|
400
|
+
if (reason) {
|
|
401
|
+
skipped.push({ skill, reason });
|
|
107
402
|
}
|
|
108
403
|
else {
|
|
109
|
-
|
|
404
|
+
install.push(skill);
|
|
110
405
|
}
|
|
111
|
-
}
|
|
112
|
-
return
|
|
406
|
+
}
|
|
407
|
+
return { install, skipped };
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Ask which agents to sync to, with universal agents always included.
|
|
411
|
+
* Preselects the last choice from `skills add` or sync when it is still offered.
|
|
412
|
+
*/
|
|
413
|
+
async function promptForAgentChoice(choices, fallback) {
|
|
414
|
+
const universalAgents = getUniversalAgents();
|
|
415
|
+
const visibleUniversalAgents = getVisibleUniversalAgents();
|
|
416
|
+
const last = await getLastSelectedAgents().catch(() => undefined);
|
|
417
|
+
const remembered = choices.filter((a) => last?.includes(a));
|
|
418
|
+
const selected = await searchMultiselect({
|
|
419
|
+
message: 'Which agents do you want to install to?',
|
|
420
|
+
items: choices.map((a) => ({
|
|
421
|
+
value: a,
|
|
422
|
+
label: agents[a].displayName,
|
|
423
|
+
hint: agents[a].skillsDir,
|
|
424
|
+
})),
|
|
425
|
+
initialSelected: remembered.length > 0 ? remembered : fallback,
|
|
426
|
+
lockedSection: {
|
|
427
|
+
title: 'Universal (.agents/skills)',
|
|
428
|
+
items: visibleUniversalAgents.map((a) => ({ value: a, label: agents[a].displayName })),
|
|
429
|
+
hiddenCount: universalAgents.length - visibleUniversalAgents.length,
|
|
430
|
+
},
|
|
431
|
+
});
|
|
432
|
+
if (!isCancelled(selected)) {
|
|
433
|
+
await saveSelectedAgents(selected).catch(() => { });
|
|
434
|
+
}
|
|
435
|
+
return selected;
|
|
436
|
+
}
|
|
437
|
+
/** `entry` was installed by sync for the remote `skills` entry `request`. */
|
|
438
|
+
function isFromRequest(entry, request) {
|
|
439
|
+
return (entry.via !== undefined &&
|
|
440
|
+
entry.source === getProjectLockSource(request.parsed) &&
|
|
441
|
+
entry.ref === request.parsed.ref);
|
|
442
|
+
}
|
|
443
|
+
/** Every skill `request` asks for is in the lock and on disk; `skills update` refreshes them. */
|
|
444
|
+
function isRemoteInstalled(request, lock, cwd) {
|
|
445
|
+
const installed = Object.entries(lock.skills)
|
|
446
|
+
.filter(([name, entry]) => isFromRequest(entry, request) && existsSync(getCanonicalPath(name, { cwd })))
|
|
447
|
+
.map(([name]) => sanitizeName(name));
|
|
448
|
+
return request.skills.length === 0
|
|
449
|
+
? installed.length > 0
|
|
450
|
+
: request.skills.every((name) => installed.includes(sanitizeName(name)));
|
|
113
451
|
}
|
|
114
452
|
export async function runSync(args, options = {}) {
|
|
115
453
|
const cwd = process.cwd();
|
|
@@ -141,13 +479,55 @@ export async function runSync(args, options = {}) {
|
|
|
141
479
|
const spinner = p.spinner();
|
|
142
480
|
// 1. Discover skills from node_modules
|
|
143
481
|
spinner.start('Scanning node_modules for skills…');
|
|
144
|
-
const
|
|
145
|
-
if (
|
|
146
|
-
spinner.stop(pc.
|
|
147
|
-
|
|
482
|
+
const discovery = await discoverNodeModuleSkills(cwd, options.recursive ?? false);
|
|
483
|
+
if (discovery.errors.length > 0) {
|
|
484
|
+
spinner.stop(pc.red('Invalid skills field'));
|
|
485
|
+
for (const error of discovery.errors)
|
|
486
|
+
p.log.error(error);
|
|
487
|
+
p.outro(pc.red('Fix the "skills" field in package.json and run sync again.'));
|
|
488
|
+
process.exitCode = 1;
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
const discoveredSkills = discovery.skills.filter((skill) => allowedByFilters(skill, options));
|
|
492
|
+
const remote = filterRemoteRequests(discovery.remote, options);
|
|
493
|
+
spinner.stop(discoveredSkills.length === 0
|
|
494
|
+
? pc.yellow('No skills found')
|
|
495
|
+
: `Found ${pc.green(String(discoveredSkills.length))} skill${discoveredSkills.length > 1 ? 's' : ''} in node_modules`);
|
|
496
|
+
for (const warning of discovery.warnings)
|
|
497
|
+
p.log.warn(warning);
|
|
498
|
+
const localLock = await readLocalLock(cwd);
|
|
499
|
+
if (options.cleanup !== false) {
|
|
500
|
+
const keep = new Set(discoveredSkills.map((skill) => sanitizeName(skill.name)));
|
|
501
|
+
// --no-remote leaves remote skills alone, both installing and removing
|
|
502
|
+
const keepRemote = (entry, name) => options.remote === false ||
|
|
503
|
+
remote.some((r) => requestsLockedSkill(r, name, entry) && remoteAllowsSkill(r, name, options));
|
|
504
|
+
const stale = await pruneStaleSkills(cwd, keep, keepRemote, localLock, options.dryRun ?? false);
|
|
505
|
+
for (const name of stale) {
|
|
506
|
+
p.log.info(`${options.dryRun ? 'Would remove' : 'Removed'} ${pc.cyan(name)} ${pc.dim('(no longer provided by a dependency)')}`);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
const remoteRequests = (options.remote === false ? [] : remote).filter((request) => !isRemoteInstalled(request, localLock, cwd));
|
|
510
|
+
const cachedRemoteSkills = [];
|
|
511
|
+
if (options.remote !== false) {
|
|
512
|
+
const shippedNames = new Set(discoveredSkills.map((skill) => sanitizeName(skill.name)));
|
|
513
|
+
for (const [name, entry] of Object.entries(localLock.skills)) {
|
|
514
|
+
if (shippedNames.has(sanitizeName(name)))
|
|
515
|
+
continue;
|
|
516
|
+
if (!remote.some((request) => !remoteRequests.includes(request) &&
|
|
517
|
+
requestsLockedSkill(request, name, entry) &&
|
|
518
|
+
remoteAllowsSkill(request, name, options)))
|
|
519
|
+
continue;
|
|
520
|
+
const skill = await parseSkillMd(join(getCanonicalPath(name, { cwd }), 'SKILL.md'));
|
|
521
|
+
if (skill)
|
|
522
|
+
cachedRemoteSkills.push({ skill, source: entry.source });
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
if (discoveredSkills.length === 0 &&
|
|
526
|
+
remoteRequests.length === 0 &&
|
|
527
|
+
cachedRemoteSkills.length === 0) {
|
|
528
|
+
p.outro(pc.dim('Nothing to sync.'));
|
|
148
529
|
return;
|
|
149
530
|
}
|
|
150
|
-
spinner.stop(`Found ${pc.green(String(discoveredSkills.length))} skill${discoveredSkills.length > 1 ? 's' : ''} in node_modules`);
|
|
151
531
|
// Show discovered skills
|
|
152
532
|
for (const skill of discoveredSkills) {
|
|
153
533
|
p.log.info(`${pc.cyan(skill.name)} ${pc.dim(`from ${skill.packageName}`)}`);
|
|
@@ -155,42 +535,10 @@ export async function runSync(args, options = {}) {
|
|
|
155
535
|
p.log.message(pc.dim(` ${skill.description}`));
|
|
156
536
|
}
|
|
157
537
|
}
|
|
158
|
-
// 2.
|
|
159
|
-
const localLock = await readLocalLock(cwd);
|
|
160
|
-
const toInstall = [];
|
|
161
|
-
const upToDate = [];
|
|
162
|
-
if (options.force) {
|
|
163
|
-
toInstall.push(...discoveredSkills);
|
|
164
|
-
p.log.info(pc.dim('Force mode: reinstalling all skills'));
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
for (const skill of discoveredSkills) {
|
|
168
|
-
const existingEntry = localLock.skills[skill.name];
|
|
169
|
-
if (existingEntry) {
|
|
170
|
-
// Compute current hash and compare
|
|
171
|
-
const currentHash = await computeSkillFolderHash(skill.path);
|
|
172
|
-
if (currentHash === existingEntry.computedHash) {
|
|
173
|
-
upToDate.push(skill.name);
|
|
174
|
-
continue;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
toInstall.push(skill);
|
|
178
|
-
}
|
|
179
|
-
if (upToDate.length > 0) {
|
|
180
|
-
p.log.info(pc.dim(`${upToDate.length} skill${upToDate.length !== 1 ? 's' : ''} already up to date`));
|
|
181
|
-
}
|
|
182
|
-
if (toInstall.length === 0) {
|
|
183
|
-
console.log();
|
|
184
|
-
p.outro(pc.green('All skills are up to date.'));
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
p.log.info(`${toInstall.length} skill${toInstall.length !== 1 ? 's' : ''} to install/update`);
|
|
189
|
-
// 3. Select agents
|
|
538
|
+
// 2. Select agents
|
|
190
539
|
let targetAgents;
|
|
191
540
|
const validAgents = Object.keys(agents);
|
|
192
541
|
const universalAgents = getUniversalAgents();
|
|
193
|
-
const visibleUniversalAgents = getVisibleUniversalAgents();
|
|
194
542
|
if (options.agent?.includes('*')) {
|
|
195
543
|
targetAgents = validAgents;
|
|
196
544
|
p.log.info(`Installing to all ${targetAgents.length} agents`);
|
|
@@ -209,37 +557,9 @@ export async function runSync(args, options = {}) {
|
|
|
209
557
|
const installedAgents = await detectInstalledAgents();
|
|
210
558
|
const totalAgents = Object.keys(agents).length;
|
|
211
559
|
spinner.stop(`${totalAgents} agents`);
|
|
212
|
-
if (installedAgents.length === 0) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
p.log.info('Installing to universal agents');
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
const otherAgents = getNonUniversalAgents();
|
|
219
|
-
const otherChoices = otherAgents.map((a) => ({
|
|
220
|
-
value: a,
|
|
221
|
-
label: agents[a].displayName,
|
|
222
|
-
hint: agents[a].skillsDir,
|
|
223
|
-
}));
|
|
224
|
-
const selected = await searchMultiselect({
|
|
225
|
-
message: 'Which agents do you want to install to?',
|
|
226
|
-
items: otherChoices,
|
|
227
|
-
initialSelected: [],
|
|
228
|
-
lockedSection: {
|
|
229
|
-
title: 'Universal (.agents/skills)',
|
|
230
|
-
items: visibleUniversalAgents.map((a) => ({
|
|
231
|
-
value: a,
|
|
232
|
-
label: agents[a].displayName,
|
|
233
|
-
})),
|
|
234
|
-
hiddenCount: universalAgents.length - visibleUniversalAgents.length,
|
|
235
|
-
},
|
|
236
|
-
});
|
|
237
|
-
if (isCancelled(selected)) {
|
|
238
|
-
p.cancel('Sync cancelled');
|
|
239
|
-
process.exit(0);
|
|
240
|
-
}
|
|
241
|
-
targetAgents = selected;
|
|
242
|
-
}
|
|
560
|
+
if (installedAgents.length === 0 && options.yes) {
|
|
561
|
+
targetAgents = universalAgents;
|
|
562
|
+
p.log.info('Installing to universal agents');
|
|
243
563
|
}
|
|
244
564
|
else if (installedAgents.length === 1 || options.yes) {
|
|
245
565
|
// Ensure universal agents are included
|
|
@@ -251,25 +571,9 @@ export async function runSync(args, options = {}) {
|
|
|
251
571
|
}
|
|
252
572
|
}
|
|
253
573
|
else {
|
|
254
|
-
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
label: agents[a].displayName,
|
|
258
|
-
hint: agents[a].skillsDir,
|
|
259
|
-
}));
|
|
260
|
-
const selected = await searchMultiselect({
|
|
261
|
-
message: 'Which agents do you want to install to?',
|
|
262
|
-
items: otherChoices,
|
|
263
|
-
initialSelected: installedAgents.filter((a) => !universalAgents.includes(a)),
|
|
264
|
-
lockedSection: {
|
|
265
|
-
title: 'Universal (.agents/skills)',
|
|
266
|
-
items: visibleUniversalAgents.map((a) => ({
|
|
267
|
-
value: a,
|
|
268
|
-
label: agents[a].displayName,
|
|
269
|
-
})),
|
|
270
|
-
hiddenCount: universalAgents.length - visibleUniversalAgents.length,
|
|
271
|
-
},
|
|
272
|
-
});
|
|
574
|
+
// No detected agents: offer all; several: offer the detected ones
|
|
575
|
+
const choices = getNonUniversalAgents().filter((a) => installedAgents.length === 0 || installedAgents.includes(a));
|
|
576
|
+
const selected = await promptForAgentChoice(choices, installedAgents.filter((a) => !universalAgents.includes(a)));
|
|
273
577
|
if (isCancelled(selected)) {
|
|
274
578
|
p.cancel('Sync cancelled');
|
|
275
579
|
process.exit(0);
|
|
@@ -277,16 +581,50 @@ export async function runSync(args, options = {}) {
|
|
|
277
581
|
targetAgents = selected;
|
|
278
582
|
}
|
|
279
583
|
}
|
|
584
|
+
// 3. Resolve conflicts
|
|
585
|
+
const { install: toInstall, skipped } = await resolveConflicts(discoveredSkills, targetAgents, localLock.skills, cwd);
|
|
586
|
+
for (const { skill, reason } of skipped) {
|
|
587
|
+
p.log.warn(`Skipped ${pc.cyan(skill.name)} ${pc.dim(`from ${skill.packageName}`)}: ${reason}`);
|
|
588
|
+
}
|
|
589
|
+
const cachedToInstall = [];
|
|
590
|
+
for (const cached of cachedRemoteSkills) {
|
|
591
|
+
const { skill } = cached;
|
|
592
|
+
const missing = targetAgents.filter((agent) => !existsSync(getInstallPath(skill.name, agent, { cwd })));
|
|
593
|
+
if (missing.length === 0)
|
|
594
|
+
continue;
|
|
595
|
+
const reason = await blockedReason(skill.name, missing, localLock.skills[skill.name], cwd);
|
|
596
|
+
if (reason) {
|
|
597
|
+
p.log.warn(`Skipped ${pc.cyan(skill.name)}: ${reason}`);
|
|
598
|
+
}
|
|
599
|
+
else {
|
|
600
|
+
cachedToInstall.push({ ...cached, agents: missing });
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
if (toInstall.length === 0 && remoteRequests.length === 0 && cachedToInstall.length === 0) {
|
|
604
|
+
console.log();
|
|
605
|
+
p.outro(pc.yellow('Nothing to sync.'));
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
280
608
|
// 4. Build summary
|
|
609
|
+
const mode = options.copy ? 'copy' : 'link';
|
|
281
610
|
const summaryLines = [];
|
|
282
611
|
for (const skill of toInstall) {
|
|
283
|
-
const canonicalPath = getCanonicalPath(skill.name, {
|
|
284
|
-
const shortCanonical = shortenPath(canonicalPath, cwd);
|
|
612
|
+
const canonicalPath = getCanonicalPath(skill.name, { cwd });
|
|
285
613
|
summaryLines.push(`${pc.cyan(skill.name)} ${pc.dim(`← ${skill.packageName}`)}`);
|
|
286
|
-
summaryLines.push(` ${pc.dim(
|
|
614
|
+
summaryLines.push(` ${pc.dim(`${shortenPath(canonicalPath, cwd)} ${mode === 'link' ? '→' : 'copied from'} ${shortenPath(skill.path, cwd)}`)}`);
|
|
615
|
+
}
|
|
616
|
+
for (const request of remoteRequests) {
|
|
617
|
+
summaryLines.push(`${pc.cyan(getProjectLockSource(request.parsed))} ${pc.dim(`← ${request.via} (remote)`)}`);
|
|
618
|
+
}
|
|
619
|
+
for (const { skill, source, agents: missing } of cachedToInstall) {
|
|
620
|
+
summaryLines.push(`${pc.cyan(skill.name)} ${pc.dim(`← ${source} (cached), link to ${missing.join(', ')}`)}`);
|
|
287
621
|
}
|
|
288
622
|
console.log();
|
|
289
623
|
p.note(summaryLines.join('\n'), 'Sync Summary');
|
|
624
|
+
if (options.dryRun) {
|
|
625
|
+
p.outro(pc.dim('Dry run — nothing changed.'));
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
290
628
|
if (!options.yes) {
|
|
291
629
|
const confirmed = await p.confirm({ message: 'Proceed with sync?' });
|
|
292
630
|
if (p.isCancel(confirmed) || !confirmed) {
|
|
@@ -294,15 +632,34 @@ export async function runSync(args, options = {}) {
|
|
|
294
632
|
process.exit(0);
|
|
295
633
|
}
|
|
296
634
|
}
|
|
297
|
-
// 5. Install skills (always project-scoped
|
|
635
|
+
// 5. Install skills (always project-scoped)
|
|
298
636
|
spinner.start('Syncing skills…');
|
|
299
637
|
const results = [];
|
|
638
|
+
for (const { skill, source, agents: missing } of cachedToInstall) {
|
|
639
|
+
for (const agent of missing) {
|
|
640
|
+
const result = await installSkillForAgent(skill, agent, {
|
|
641
|
+
cwd,
|
|
642
|
+
mode: 'symlink',
|
|
643
|
+
createMissingAgentRoot: true,
|
|
644
|
+
});
|
|
645
|
+
results.push({
|
|
646
|
+
skill: skill.name,
|
|
647
|
+
packageName: source,
|
|
648
|
+
agent: agents[agent].displayName,
|
|
649
|
+
success: result.success,
|
|
650
|
+
path: result.path,
|
|
651
|
+
canonicalPath: result.canonicalPath,
|
|
652
|
+
error: result.error,
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
}
|
|
300
656
|
for (const skill of toInstall) {
|
|
301
657
|
for (const agent of targetAgents) {
|
|
302
658
|
const result = await installSkillForAgent(skill, agent, {
|
|
303
659
|
global: false,
|
|
304
660
|
cwd,
|
|
305
|
-
|
|
661
|
+
// Eve rewrites SKILL.md frontmatter on install, which a link cannot do
|
|
662
|
+
mode: agent === 'eve' ? 'copy' : mode,
|
|
306
663
|
});
|
|
307
664
|
results.push({
|
|
308
665
|
skill: skill.name,
|
|
@@ -327,6 +684,9 @@ export async function runSync(args, options = {}) {
|
|
|
327
684
|
await addSkillToLocalLock(skill.name, {
|
|
328
685
|
source: skill.packageName,
|
|
329
686
|
sourceType: 'node_modules',
|
|
687
|
+
skillPath: skill.skillPath,
|
|
688
|
+
...(skill.packageVersion && { version: skill.packageVersion }),
|
|
689
|
+
...(skill.via && { via: skill.via }),
|
|
330
690
|
computedHash,
|
|
331
691
|
}, cwd);
|
|
332
692
|
}
|
|
@@ -335,7 +695,48 @@ export async function runSync(args, options = {}) {
|
|
|
335
695
|
}
|
|
336
696
|
}
|
|
337
697
|
}
|
|
338
|
-
// 7.
|
|
698
|
+
// 7. Install skills that remote `skills` entries request
|
|
699
|
+
const claimed = new Set(discoveredSkills.map((skill) => sanitizeName(skill.name)));
|
|
700
|
+
const lockEntryFor = (name) => Object.entries(localLock.skills).find(([key]) => sanitizeName(key) === name)?.[1];
|
|
701
|
+
for (const request of remoteRequests) {
|
|
702
|
+
const label = getProjectLockSource(request.parsed);
|
|
703
|
+
const result = await installFromSource(request.parsed, {
|
|
704
|
+
skills: request.skills,
|
|
705
|
+
agents: targetAgents,
|
|
706
|
+
via: request.via,
|
|
707
|
+
select: async (skills) => {
|
|
708
|
+
const selected = [];
|
|
709
|
+
for (const skill of skills) {
|
|
710
|
+
const name = sanitizeName(skill.name);
|
|
711
|
+
if (!remoteAllowsSkill(request, name, options))
|
|
712
|
+
continue;
|
|
713
|
+
const reason = claimed.has(name)
|
|
714
|
+
? 'another source in this sync provides it'
|
|
715
|
+
: await blockedReason(name, targetAgents, lockEntryFor(name), cwd);
|
|
716
|
+
if (reason) {
|
|
717
|
+
p.log.warn(`Skipped ${pc.cyan(name)} from ${label}: ${reason}`);
|
|
718
|
+
continue;
|
|
719
|
+
}
|
|
720
|
+
claimed.add(name);
|
|
721
|
+
selected.push(skill);
|
|
722
|
+
}
|
|
723
|
+
return selected;
|
|
724
|
+
},
|
|
725
|
+
});
|
|
726
|
+
if (result.error) {
|
|
727
|
+
p.log.error(`Failed to install from ${pc.cyan(label)}: ${result.error}`);
|
|
728
|
+
process.exitCode = 1;
|
|
729
|
+
continue;
|
|
730
|
+
}
|
|
731
|
+
if (result.installed.length > 0) {
|
|
732
|
+
p.log.success(`Installed ${result.installed.map((name) => pc.cyan(name)).join(', ')} from ${label}`);
|
|
733
|
+
}
|
|
734
|
+
for (const failure of result.failed)
|
|
735
|
+
p.log.error(failure);
|
|
736
|
+
if (result.failed.length > 0)
|
|
737
|
+
process.exitCode = 1;
|
|
738
|
+
}
|
|
739
|
+
// 8. Display results
|
|
339
740
|
console.log();
|
|
340
741
|
if (successful.length > 0) {
|
|
341
742
|
const bySkill = new Map();
|
|
@@ -347,7 +748,7 @@ export async function runSync(args, options = {}) {
|
|
|
347
748
|
const resultLines = [];
|
|
348
749
|
for (const [skillName, skillResults] of bySkill) {
|
|
349
750
|
const firstResult = skillResults[0];
|
|
350
|
-
const pkg =
|
|
751
|
+
const pkg = firstResult.packageName;
|
|
351
752
|
if (firstResult.canonicalPath) {
|
|
352
753
|
const shortPath = shortenPath(firstResult.canonicalPath, cwd);
|
|
353
754
|
resultLines.push(`${pc.green('✓')} ${skillName} ${pc.dim(`← ${pkg}`)}`);
|
|
@@ -362,6 +763,7 @@ export async function runSync(args, options = {}) {
|
|
|
362
763
|
p.note(resultLines.join('\n'), title);
|
|
363
764
|
}
|
|
364
765
|
if (failed.length > 0) {
|
|
766
|
+
process.exitCode = 1;
|
|
365
767
|
console.log();
|
|
366
768
|
p.log.error(pc.red(`Failed to install ${failed.length}`));
|
|
367
769
|
for (const r of failed) {
|
|
@@ -371,7 +773,7 @@ export async function runSync(args, options = {}) {
|
|
|
371
773
|
// Track telemetry
|
|
372
774
|
track({
|
|
373
775
|
event: 'experimental_sync',
|
|
374
|
-
skillCount: String(toInstall.length),
|
|
776
|
+
skillCount: String(toInstall.length + cachedToInstall.length),
|
|
375
777
|
successCount: String(successfulSkillNames.size),
|
|
376
778
|
agents: targetAgents.join(','),
|
|
377
779
|
});
|
|
@@ -380,24 +782,42 @@ export async function runSync(args, options = {}) {
|
|
|
380
782
|
}
|
|
381
783
|
export function parseSyncOptions(args) {
|
|
382
784
|
const options = {};
|
|
383
|
-
|
|
785
|
+
let i = 0;
|
|
786
|
+
/** Consume the values after a flag, up to the next flag. */
|
|
787
|
+
const takeValues = () => {
|
|
788
|
+
const values = [];
|
|
789
|
+
while (args[i + 1] !== undefined && !args[i + 1].startsWith('-'))
|
|
790
|
+
values.push(args[++i]);
|
|
791
|
+
return values;
|
|
792
|
+
};
|
|
793
|
+
for (; i < args.length; i++) {
|
|
384
794
|
const arg = args[i];
|
|
385
795
|
if (arg === '-y' || arg === '--yes') {
|
|
386
796
|
options.yes = true;
|
|
387
797
|
}
|
|
388
|
-
else if (arg === '
|
|
389
|
-
options.
|
|
798
|
+
else if (arg === '--copy') {
|
|
799
|
+
options.copy = true;
|
|
800
|
+
}
|
|
801
|
+
else if (arg === '--dry-run') {
|
|
802
|
+
options.dryRun = true;
|
|
803
|
+
}
|
|
804
|
+
else if (arg === '--no-cleanup') {
|
|
805
|
+
options.cleanup = false;
|
|
806
|
+
}
|
|
807
|
+
else if (arg === '--no-remote') {
|
|
808
|
+
options.remote = false;
|
|
809
|
+
}
|
|
810
|
+
else if (arg === '-r' || arg === '--recursive') {
|
|
811
|
+
options.recursive = true;
|
|
390
812
|
}
|
|
391
813
|
else if (arg === '-a' || arg === '--agent') {
|
|
392
|
-
options.agent = options.agent
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
}
|
|
400
|
-
i--;
|
|
814
|
+
options.agent = [...(options.agent ?? []), ...takeValues()];
|
|
815
|
+
}
|
|
816
|
+
else if (arg === '--include') {
|
|
817
|
+
options.include = [...(options.include ?? []), ...takeValues()];
|
|
818
|
+
}
|
|
819
|
+
else if (arg === '--exclude') {
|
|
820
|
+
options.exclude = [...(options.exclude ?? []), ...takeValues()];
|
|
401
821
|
}
|
|
402
822
|
}
|
|
403
823
|
return { options };
|