@skilltap/core 0.5.2 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/config.ts +20 -7
- package/src/doctor.ts +2 -3
- package/src/install.test.ts +53 -0
- package/src/install.ts +3 -2
- package/src/link.ts +3 -2
- package/src/remove.ts +3 -2
- package/src/self-update.ts +1 -1
- package/src/symlink.ts +1 -1
- package/src/update.test.ts +70 -0
- package/src/update.ts +247 -80
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -164,9 +164,14 @@ export async function saveConfig(config: Config): Promise<Result<void>> {
|
|
|
164
164
|
|
|
165
165
|
const _DEFAULT_INSTALLED: InstalledJson = { version: 1, skills: [] };
|
|
166
166
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
167
|
+
function getInstalledPath(projectRoot?: string): string {
|
|
168
|
+
return projectRoot
|
|
169
|
+
? join(projectRoot, ".agents", "installed.json")
|
|
170
|
+
: join(getConfigDir(), "installed.json");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export async function loadInstalled(projectRoot?: string): Promise<Result<InstalledJson>> {
|
|
174
|
+
const file = getInstalledPath(projectRoot);
|
|
170
175
|
|
|
171
176
|
const f = Bun.file(file);
|
|
172
177
|
const exists = await f.exists();
|
|
@@ -194,12 +199,20 @@ export async function loadInstalled(): Promise<Result<InstalledJson>> {
|
|
|
194
199
|
|
|
195
200
|
export async function saveInstalled(
|
|
196
201
|
installed: InstalledJson,
|
|
202
|
+
projectRoot?: string,
|
|
197
203
|
): Promise<Result<void>> {
|
|
198
|
-
const
|
|
199
|
-
const file = join(dir, "installed.json");
|
|
204
|
+
const file = getInstalledPath(projectRoot);
|
|
200
205
|
|
|
201
|
-
|
|
202
|
-
|
|
206
|
+
if (projectRoot) {
|
|
207
|
+
try {
|
|
208
|
+
await mkdir(join(projectRoot, ".agents"), { recursive: true });
|
|
209
|
+
} catch (e) {
|
|
210
|
+
return err(new UserError(`Failed to create .agents directory: ${e}`));
|
|
211
|
+
}
|
|
212
|
+
} else {
|
|
213
|
+
const dirsResult = await ensureDirs();
|
|
214
|
+
if (!dirsResult.ok) return dirsResult;
|
|
215
|
+
}
|
|
203
216
|
|
|
204
217
|
try {
|
|
205
218
|
await Bun.write(file, JSON.stringify(installed, null, 2));
|
package/src/doctor.ts
CHANGED
|
@@ -346,7 +346,6 @@ async function checkSkills(installed: InstalledJson): Promise<DoctorCheck> {
|
|
|
346
346
|
const trackedNames = new Set<string>();
|
|
347
347
|
|
|
348
348
|
for (const skill of installed.skills) {
|
|
349
|
-
if (skill.scope === "project") continue;
|
|
350
349
|
trackedNames.add(skill.name);
|
|
351
350
|
|
|
352
351
|
if (skill.scope === "linked") {
|
|
@@ -407,7 +406,7 @@ async function checkSkills(installed: InstalledJson): Promise<DoctorCheck> {
|
|
|
407
406
|
}
|
|
408
407
|
}
|
|
409
408
|
|
|
410
|
-
const total = installed.skills.
|
|
409
|
+
const total = installed.skills.length;
|
|
411
410
|
const missing = issues.filter((i) => i.fixable).length;
|
|
412
411
|
const onDisk = total - missing;
|
|
413
412
|
|
|
@@ -434,7 +433,7 @@ async function checkSymlinks(installed: InstalledJson): Promise<DoctorCheck> {
|
|
|
434
433
|
let valid = 0;
|
|
435
434
|
|
|
436
435
|
for (const skill of installed.skills) {
|
|
437
|
-
if (skill.
|
|
436
|
+
if (skill.also.length === 0) continue;
|
|
438
437
|
|
|
439
438
|
for (const agent of skill.also) {
|
|
440
439
|
const agentRelDir = AGENT_PATHS[agent];
|
package/src/install.test.ts
CHANGED
|
@@ -213,6 +213,59 @@ describe("installSkill — project scope", () => {
|
|
|
213
213
|
await removeTmpDir(projectRoot);
|
|
214
214
|
}
|
|
215
215
|
});
|
|
216
|
+
|
|
217
|
+
test("saves to project installed.json, not global", async () => {
|
|
218
|
+
const repo = await createStandaloneSkillRepo();
|
|
219
|
+
const projectRoot = await makeTmpDir();
|
|
220
|
+
try {
|
|
221
|
+
await $`git -C ${projectRoot} init`.quiet();
|
|
222
|
+
await installSkill(repo.path, { scope: "project", projectRoot, skipScan: true });
|
|
223
|
+
|
|
224
|
+
// Project file should have the record
|
|
225
|
+
const projectInstalled = await loadInstalled(projectRoot);
|
|
226
|
+
expect(projectInstalled.ok).toBe(true);
|
|
227
|
+
if (!projectInstalled.ok) return;
|
|
228
|
+
expect(projectInstalled.value.skills.map((s) => s.name)).toContain("standalone-skill");
|
|
229
|
+
|
|
230
|
+
// Global file should be empty
|
|
231
|
+
const globalInstalled = await loadInstalled();
|
|
232
|
+
expect(globalInstalled.ok).toBe(true);
|
|
233
|
+
if (!globalInstalled.ok) return;
|
|
234
|
+
expect(globalInstalled.value.skills).toHaveLength(0);
|
|
235
|
+
} finally {
|
|
236
|
+
await repo.cleanup();
|
|
237
|
+
await removeTmpDir(projectRoot);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
test("same skill in two projects coexist independently", async () => {
|
|
242
|
+
const repo = await createStandaloneSkillRepo();
|
|
243
|
+
const projectA = await makeTmpDir();
|
|
244
|
+
const projectB = await makeTmpDir();
|
|
245
|
+
try {
|
|
246
|
+
await $`git -C ${projectA} init`.quiet();
|
|
247
|
+
await $`git -C ${projectB} init`.quiet();
|
|
248
|
+
|
|
249
|
+
await installSkill(repo.path, { scope: "project", projectRoot: projectA, skipScan: true });
|
|
250
|
+
await installSkill(repo.path, { scope: "project", projectRoot: projectB, skipScan: true });
|
|
251
|
+
|
|
252
|
+
// Both project files have the record
|
|
253
|
+
const aInstalled = await loadInstalled(projectA);
|
|
254
|
+
const bInstalled = await loadInstalled(projectB);
|
|
255
|
+
expect(aInstalled.ok && aInstalled.value.skills).toHaveLength(1);
|
|
256
|
+
expect(bInstalled.ok && bInstalled.value.skills).toHaveLength(1);
|
|
257
|
+
|
|
258
|
+
// Global file is empty
|
|
259
|
+
const globalInstalled = await loadInstalled();
|
|
260
|
+
expect(globalInstalled.ok).toBe(true);
|
|
261
|
+
if (!globalInstalled.ok) return;
|
|
262
|
+
expect(globalInstalled.value.skills).toHaveLength(0);
|
|
263
|
+
} finally {
|
|
264
|
+
await repo.cleanup();
|
|
265
|
+
await removeTmpDir(projectA);
|
|
266
|
+
await removeTmpDir(projectB);
|
|
267
|
+
}
|
|
268
|
+
});
|
|
216
269
|
});
|
|
217
270
|
|
|
218
271
|
describe("removeSkill", () => {
|
package/src/install.ts
CHANGED
|
@@ -365,7 +365,8 @@ export async function installSkill(
|
|
|
365
365
|
const allSemanticWarnings: SemanticWarning[] = [];
|
|
366
366
|
|
|
367
367
|
// 1. Check already-installed
|
|
368
|
-
const
|
|
368
|
+
const fileRoot = options.scope === "project" ? options.projectRoot : undefined;
|
|
369
|
+
const installedResult = await loadInstalled(fileRoot);
|
|
369
370
|
if (!installedResult.ok) return installedResult;
|
|
370
371
|
const installed = installedResult.value;
|
|
371
372
|
|
|
@@ -563,7 +564,7 @@ export async function installSkill(
|
|
|
563
564
|
|
|
564
565
|
// 10. Save installed.json
|
|
565
566
|
installed.skills.push(...newRecords);
|
|
566
|
-
const saveResult = await saveInstalled(installed);
|
|
567
|
+
const saveResult = await saveInstalled(installed, fileRoot);
|
|
567
568
|
if (!saveResult.ok) return saveResult;
|
|
568
569
|
|
|
569
570
|
return ok({
|
package/src/link.ts
CHANGED
|
@@ -38,7 +38,8 @@ export async function linkSkill(
|
|
|
38
38
|
const skill = scanned[0]!;
|
|
39
39
|
|
|
40
40
|
// 3. Load installed to check for conflicts
|
|
41
|
-
const
|
|
41
|
+
const fileRoot = options.scope === "project" ? options.projectRoot : undefined;
|
|
42
|
+
const installedResult = await loadInstalled(fileRoot);
|
|
42
43
|
if (!installedResult.ok) return installedResult;
|
|
43
44
|
const installed = installedResult.value;
|
|
44
45
|
|
|
@@ -99,7 +100,7 @@ export async function linkSkill(
|
|
|
99
100
|
|
|
100
101
|
// 8. Save installed.json
|
|
101
102
|
installed.skills.push(record);
|
|
102
|
-
const saveResult = await saveInstalled(installed);
|
|
103
|
+
const saveResult = await saveInstalled(installed, fileRoot);
|
|
103
104
|
if (!saveResult.ok) return saveResult;
|
|
104
105
|
|
|
105
106
|
return ok(record);
|
package/src/remove.ts
CHANGED
|
@@ -17,7 +17,8 @@ export async function removeSkill(
|
|
|
17
17
|
options: RemoveOptions = {},
|
|
18
18
|
): Promise<Result<void, UserError>> {
|
|
19
19
|
debug("removeSkill", { name, scope: options.scope });
|
|
20
|
-
const
|
|
20
|
+
const fileRoot = options.scope === "project" ? options.projectRoot : undefined;
|
|
21
|
+
const installedResult = await loadInstalled(fileRoot);
|
|
21
22
|
if (!installedResult.ok) return installedResult;
|
|
22
23
|
const installed = installedResult.value;
|
|
23
24
|
|
|
@@ -79,7 +80,7 @@ export async function removeSkill(
|
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
installed.skills.splice(idx, 1);
|
|
82
|
-
const saveResult = await saveInstalled(installed);
|
|
83
|
+
const saveResult = await saveInstalled(installed, fileRoot);
|
|
83
84
|
if (!saveResult.ok) return saveResult;
|
|
84
85
|
|
|
85
86
|
return ok(undefined);
|
package/src/self-update.ts
CHANGED
|
@@ -164,7 +164,7 @@ export async function downloadAndInstall(
|
|
|
164
164
|
const buffer = await response.arrayBuffer();
|
|
165
165
|
await Bun.write(tmpPath, buffer);
|
|
166
166
|
await Bun.$`chmod +x ${tmpPath}`.quiet();
|
|
167
|
-
await Bun.$`
|
|
167
|
+
await Bun.$`mv -f ${tmpPath} ${execPath}`.quiet();
|
|
168
168
|
} catch (e) {
|
|
169
169
|
// Clean up temp file if possible
|
|
170
170
|
Bun.$`rm -f ${tmpPath}`.quiet();
|
package/src/symlink.ts
CHANGED
|
@@ -63,7 +63,7 @@ export async function removeAgentSymlinks(
|
|
|
63
63
|
scope: "global" | "project" | "linked",
|
|
64
64
|
projectRoot?: string,
|
|
65
65
|
): Promise<Result<void, UserError>> {
|
|
66
|
-
const effectiveScope = scope === "linked" ? "global" : scope;
|
|
66
|
+
const effectiveScope = scope === "linked" ? (projectRoot ? "project" : "global") : scope;
|
|
67
67
|
for (const agent of agents) {
|
|
68
68
|
const linkPath = symlinkPath(skillName, agent, effectiveScope, projectRoot);
|
|
69
69
|
if (!linkPath) continue;
|
package/src/update.test.ts
CHANGED
|
@@ -314,4 +314,74 @@ describe("updateSkill — multi-skill", () => {
|
|
|
314
314
|
await repo.cleanup();
|
|
315
315
|
}
|
|
316
316
|
});
|
|
317
|
+
|
|
318
|
+
test("both skills from same repo are checked when both installed", async () => {
|
|
319
|
+
const repo = await createMultiSkillRepo();
|
|
320
|
+
try {
|
|
321
|
+
// Install BOTH skills from the multi-skill repo
|
|
322
|
+
await installSkill(repo.path, { scope: "global", skipScan: true });
|
|
323
|
+
|
|
324
|
+
// Add a commit that changes BOTH skill paths
|
|
325
|
+
await addFileAndCommit(repo.path, ".agents/skills/skill-a/patch.md", "# Patch A");
|
|
326
|
+
await addFileAndCommit(repo.path, ".agents/skills/skill-b/patch.md", "# Patch B");
|
|
327
|
+
|
|
328
|
+
const result = await updateSkill({ yes: true });
|
|
329
|
+
expect(result.ok).toBe(true);
|
|
330
|
+
if (!result.ok) return;
|
|
331
|
+
|
|
332
|
+
expect(result.value.updated).toContain("skill-a");
|
|
333
|
+
expect(result.value.updated).toContain("skill-b");
|
|
334
|
+
} finally {
|
|
335
|
+
await repo.cleanup();
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
test("skill with no path changes is upToDate even when repo has changes", async () => {
|
|
340
|
+
const repo = await createMultiSkillRepo();
|
|
341
|
+
try {
|
|
342
|
+
// Install BOTH skills from the multi-skill repo
|
|
343
|
+
await installSkill(repo.path, { scope: "global", skipScan: true });
|
|
344
|
+
|
|
345
|
+
// Add a commit that ONLY changes skill-a's path
|
|
346
|
+
await addFileAndCommit(repo.path, ".agents/skills/skill-a/only-a.md", "# Only A");
|
|
347
|
+
|
|
348
|
+
const result = await updateSkill({ yes: true });
|
|
349
|
+
expect(result.ok).toBe(true);
|
|
350
|
+
if (!result.ok) return;
|
|
351
|
+
|
|
352
|
+
// skill-a has changes → updated
|
|
353
|
+
expect(result.value.updated).toContain("skill-a");
|
|
354
|
+
// skill-b has no path-specific changes → upToDate (not skipped, not updated)
|
|
355
|
+
expect(result.value.upToDate).toContain("skill-b");
|
|
356
|
+
expect(result.value.skipped).not.toContain("skill-b");
|
|
357
|
+
} finally {
|
|
358
|
+
await repo.cleanup();
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
describe("updateSkill — project scope", () => {
|
|
364
|
+
test("updates skills in project installed.json when projectRoot provided", async () => {
|
|
365
|
+
const repo = await createStandaloneSkillRepo();
|
|
366
|
+
const projectRoot = await makeTmpDir();
|
|
367
|
+
try {
|
|
368
|
+
await installSkill(repo.path, { scope: "project", projectRoot, skipScan: true });
|
|
369
|
+
await addFileAndCommit(repo.path, "new-file.md", "# New content");
|
|
370
|
+
|
|
371
|
+
const result = await updateSkill({ yes: true, projectRoot });
|
|
372
|
+
expect(result.ok).toBe(true);
|
|
373
|
+
if (!result.ok) return;
|
|
374
|
+
|
|
375
|
+
expect(result.value.updated).toContain("standalone-skill");
|
|
376
|
+
|
|
377
|
+
// Project installed.json should have updated SHA
|
|
378
|
+
const projectInstalled = await loadInstalled(projectRoot);
|
|
379
|
+
expect(projectInstalled.ok).toBe(true);
|
|
380
|
+
if (!projectInstalled.ok) return;
|
|
381
|
+
expect(projectInstalled.value.skills[0]?.sha).toBeTruthy();
|
|
382
|
+
} finally {
|
|
383
|
+
await repo.cleanup();
|
|
384
|
+
await removeTmpDir(projectRoot);
|
|
385
|
+
}
|
|
386
|
+
});
|
|
317
387
|
});
|
package/src/update.ts
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
resolveVersion,
|
|
15
15
|
} from "./npm-registry";
|
|
16
16
|
import { skillCacheDir, skillInstallDir } from "./paths";
|
|
17
|
-
import type { InstalledSkill } from "./schemas/installed";
|
|
17
|
+
import type { InstalledJson, InstalledSkill } from "./schemas/installed";
|
|
18
18
|
import type { StaticWarning } from "./security";
|
|
19
19
|
import { scanDiff, scanStatic } from "./security";
|
|
20
20
|
import type { SemanticWarning } from "./security/semantic";
|
|
@@ -41,7 +41,7 @@ export type UpdateOptions = {
|
|
|
41
41
|
yes?: boolean;
|
|
42
42
|
/** Skip skills that have security warnings in their diff */
|
|
43
43
|
strict?: boolean;
|
|
44
|
-
/** Project root
|
|
44
|
+
/** Project root — also processes project-scoped skills from {projectRoot}/.agents/installed.json */
|
|
45
45
|
projectRoot?: string;
|
|
46
46
|
onProgress?: (
|
|
47
47
|
skillName: string,
|
|
@@ -291,7 +291,7 @@ async function updateNpmSkill(
|
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
-
/** Handle updates for git
|
|
294
|
+
/** Handle updates for standalone git skills (path === null; workDir is the install dir). */
|
|
295
295
|
async function updateGitSkill(
|
|
296
296
|
record: InstalledSkill,
|
|
297
297
|
installed: { skills: InstalledSkill[] },
|
|
@@ -299,27 +299,11 @@ async function updateGitSkill(
|
|
|
299
299
|
result: UpdateResult,
|
|
300
300
|
_resolveTrust: ResolveTrustFn,
|
|
301
301
|
): Promise<Result<void, UserError | GitError | ScanError>> {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
record.name,
|
|
308
|
-
record.scope as "global" | "project",
|
|
309
|
-
options.projectRoot,
|
|
310
|
-
);
|
|
311
|
-
|
|
312
|
-
// For multi-skill, verify cache exists
|
|
313
|
-
if (isMulti) {
|
|
314
|
-
const cacheGitExists = await lstat(join(workDir, ".git"))
|
|
315
|
-
.then(() => true)
|
|
316
|
-
.catch(() => false);
|
|
317
|
-
if (!cacheGitExists) {
|
|
318
|
-
result.skipped.push(record.name);
|
|
319
|
-
options.onProgress?.(record.name, "skipped");
|
|
320
|
-
return ok(undefined);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
302
|
+
const workDir = skillInstallDir(
|
|
303
|
+
record.name,
|
|
304
|
+
record.scope as "global" | "project",
|
|
305
|
+
options.projectRoot,
|
|
306
|
+
);
|
|
323
307
|
|
|
324
308
|
const fetchResult = await fetch(workDir);
|
|
325
309
|
if (!fetchResult.ok) return fetchResult;
|
|
@@ -338,69 +322,42 @@ async function updateGitSkill(
|
|
|
338
322
|
return ok(undefined);
|
|
339
323
|
}
|
|
340
324
|
|
|
341
|
-
|
|
342
|
-
const pathSpec = record.path ?? undefined;
|
|
343
|
-
const diffResult = await diff(workDir, "HEAD", "FETCH_HEAD", pathSpec);
|
|
325
|
+
const diffResult = await diff(workDir, "HEAD", "FETCH_HEAD");
|
|
344
326
|
if (!diffResult.ok) return diffResult;
|
|
345
|
-
const diffOutput = diffResult.value;
|
|
346
327
|
|
|
347
|
-
const statResult = await diffStat(workDir, "HEAD", "FETCH_HEAD"
|
|
328
|
+
const statResult = await diffStat(workDir, "HEAD", "FETCH_HEAD");
|
|
348
329
|
if (!statResult.ok) return statResult;
|
|
349
330
|
const stat = statResult.value;
|
|
350
331
|
|
|
351
|
-
// If skill-specific path has no changes, mark as up to date
|
|
352
|
-
if (stat.filesChanged === 0) {
|
|
353
|
-
result.upToDate.push(record.name);
|
|
354
|
-
options.onProgress?.(record.name, "upToDate");
|
|
355
|
-
return ok(undefined);
|
|
356
|
-
}
|
|
357
|
-
|
|
358
332
|
options.onDiff?.(record.name, stat, localSha, remoteSha);
|
|
359
333
|
|
|
360
|
-
|
|
361
|
-
const warnings = scanDiff(diffOutput);
|
|
334
|
+
const warnings = scanDiff(diffResult.value);
|
|
362
335
|
if (await shouldSkipUpdate(warnings, options, record.name)) {
|
|
363
336
|
result.skipped.push(record.name);
|
|
364
337
|
options.onProgress?.(record.name, "skipped");
|
|
365
338
|
return ok(undefined);
|
|
366
339
|
}
|
|
367
340
|
|
|
368
|
-
// Apply update
|
|
369
341
|
const pullResult = await pull(workDir);
|
|
370
342
|
if (!pullResult.ok) return pullResult;
|
|
371
343
|
|
|
372
|
-
if (
|
|
373
|
-
const recopyResult = await recopyMultiSkill(workDir, record, options.projectRoot);
|
|
374
|
-
if (!recopyResult.ok) return recopyResult;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
const installDir = skillInstallDir(
|
|
378
|
-
record.name,
|
|
379
|
-
record.scope as "global" | "project",
|
|
380
|
-
options.projectRoot,
|
|
381
|
-
);
|
|
382
|
-
|
|
383
|
-
// Semantic scan on updated skill directory
|
|
384
|
-
if (await runUpdateSemanticScan(installDir, record.name, options)) {
|
|
344
|
+
if (await runUpdateSemanticScan(workDir, record.name, options)) {
|
|
385
345
|
result.skipped.push(record.name);
|
|
386
346
|
options.onProgress?.(record.name, "skipped");
|
|
387
347
|
return ok(undefined);
|
|
388
348
|
}
|
|
389
349
|
|
|
390
|
-
// Get new SHA
|
|
391
350
|
const newShaResult = await revParse(workDir, "HEAD");
|
|
392
351
|
if (!newShaResult.ok) return newShaResult;
|
|
393
352
|
|
|
394
|
-
// Re-verify trust for the updated skill
|
|
395
353
|
const newTrust = await _resolveTrust({
|
|
396
354
|
adapter: "git",
|
|
397
355
|
url: record.repo ?? "",
|
|
398
356
|
tap: record.tap,
|
|
399
|
-
skillDir:
|
|
357
|
+
skillDir: workDir,
|
|
400
358
|
githubRepo: record.repo ? parseGitHubRepo(record.repo) : null,
|
|
401
359
|
});
|
|
402
360
|
|
|
403
|
-
// Update the record in place
|
|
404
361
|
patchRecord(installed, record, {
|
|
405
362
|
sha: newShaResult.value,
|
|
406
363
|
updatedAt: new Date().toISOString(),
|
|
@@ -414,19 +371,232 @@ async function updateGitSkill(
|
|
|
414
371
|
return ok(undefined);
|
|
415
372
|
}
|
|
416
373
|
|
|
374
|
+
/** Handle updates for a group of skills sharing the same multi-skill git repo cache. */
|
|
375
|
+
async function updateGitSkillGroup(
|
|
376
|
+
repo: string,
|
|
377
|
+
skills: InstalledSkill[],
|
|
378
|
+
installed: { skills: InstalledSkill[] },
|
|
379
|
+
options: UpdateOptions,
|
|
380
|
+
result: UpdateResult,
|
|
381
|
+
_resolveTrust: ResolveTrustFn,
|
|
382
|
+
): Promise<Result<void, UserError | GitError | ScanError>> {
|
|
383
|
+
const workDir = skillCacheDir(repo);
|
|
384
|
+
|
|
385
|
+
// Verify cache exists
|
|
386
|
+
const cacheGitExists = await lstat(join(workDir, ".git"))
|
|
387
|
+
.then(() => true)
|
|
388
|
+
.catch(() => false);
|
|
389
|
+
if (!cacheGitExists) {
|
|
390
|
+
for (const skill of skills) {
|
|
391
|
+
result.skipped.push(skill.name);
|
|
392
|
+
options.onProgress?.(skill.name, "skipped");
|
|
393
|
+
}
|
|
394
|
+
return ok(undefined);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// Fetch once for the whole group
|
|
398
|
+
const fetchResult = await fetch(workDir);
|
|
399
|
+
if (!fetchResult.ok) return fetchResult;
|
|
400
|
+
|
|
401
|
+
// Capture SHAs BEFORE any pull
|
|
402
|
+
const localShaResult = await revParse(workDir, "HEAD");
|
|
403
|
+
if (!localShaResult.ok) return localShaResult;
|
|
404
|
+
const remoteShaResult = await revParse(workDir, "FETCH_HEAD");
|
|
405
|
+
if (!remoteShaResult.ok) return remoteShaResult;
|
|
406
|
+
|
|
407
|
+
const localSha = localShaResult.value;
|
|
408
|
+
const remoteSha = remoteShaResult.value;
|
|
409
|
+
|
|
410
|
+
// If the whole repo is up to date, all skills in the group are too
|
|
411
|
+
if (localSha === remoteSha) {
|
|
412
|
+
for (const skill of skills) {
|
|
413
|
+
result.upToDate.push(skill.name);
|
|
414
|
+
options.onProgress?.(skill.name, "upToDate");
|
|
415
|
+
}
|
|
416
|
+
return ok(undefined);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// Per-skill: check path-specific diff, scan, confirm
|
|
420
|
+
const toUpdate: InstalledSkill[] = [];
|
|
421
|
+
for (const skill of skills) {
|
|
422
|
+
options.onProgress?.(skill.name, "checking");
|
|
423
|
+
|
|
424
|
+
// biome-ignore lint/style/noNonNullAssertion: multi-skill records always have path
|
|
425
|
+
const pathSpec = skill.path!;
|
|
426
|
+
|
|
427
|
+
const statResult = await diffStat(workDir, "HEAD", "FETCH_HEAD", pathSpec);
|
|
428
|
+
if (!statResult.ok) return statResult;
|
|
429
|
+
const stat = statResult.value;
|
|
430
|
+
|
|
431
|
+
if (stat.filesChanged === 0) {
|
|
432
|
+
result.upToDate.push(skill.name);
|
|
433
|
+
options.onProgress?.(skill.name, "upToDate");
|
|
434
|
+
continue;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
options.onDiff?.(skill.name, stat, localSha, remoteSha);
|
|
438
|
+
|
|
439
|
+
const diffResult = await diff(workDir, "HEAD", "FETCH_HEAD", pathSpec);
|
|
440
|
+
if (!diffResult.ok) return diffResult;
|
|
441
|
+
|
|
442
|
+
const warnings = scanDiff(diffResult.value);
|
|
443
|
+
if (await shouldSkipUpdate(warnings, options, skill.name)) {
|
|
444
|
+
result.skipped.push(skill.name);
|
|
445
|
+
options.onProgress?.(skill.name, "skipped");
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
toUpdate.push(skill);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
if (toUpdate.length === 0) return ok(undefined);
|
|
453
|
+
|
|
454
|
+
// Pull once for the whole group
|
|
455
|
+
const pullResult = await pull(workDir);
|
|
456
|
+
if (!pullResult.ok) return pullResult;
|
|
457
|
+
|
|
458
|
+
const newShaResult = await revParse(workDir, "HEAD");
|
|
459
|
+
if (!newShaResult.ok) return newShaResult;
|
|
460
|
+
const newSha = newShaResult.value;
|
|
461
|
+
|
|
462
|
+
// Apply update to each confirmed skill
|
|
463
|
+
for (const skill of toUpdate) {
|
|
464
|
+
const recopyResult = await recopyMultiSkill(workDir, skill, options.projectRoot);
|
|
465
|
+
if (!recopyResult.ok) return recopyResult;
|
|
466
|
+
|
|
467
|
+
const installDir = skillInstallDir(
|
|
468
|
+
skill.name,
|
|
469
|
+
skill.scope as "global" | "project",
|
|
470
|
+
options.projectRoot,
|
|
471
|
+
);
|
|
472
|
+
|
|
473
|
+
if (await runUpdateSemanticScan(installDir, skill.name, options)) {
|
|
474
|
+
result.skipped.push(skill.name);
|
|
475
|
+
options.onProgress?.(skill.name, "skipped");
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
const newTrust = await _resolveTrust({
|
|
480
|
+
adapter: "git",
|
|
481
|
+
url: skill.repo ?? "",
|
|
482
|
+
tap: skill.tap,
|
|
483
|
+
skillDir: installDir,
|
|
484
|
+
githubRepo: skill.repo ? parseGitHubRepo(skill.repo) : null,
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
patchRecord(installed, skill, {
|
|
488
|
+
sha: newSha,
|
|
489
|
+
updatedAt: new Date().toISOString(),
|
|
490
|
+
trust: newTrust,
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
await refreshAgentSymlinks(skill, options.projectRoot);
|
|
494
|
+
|
|
495
|
+
result.updated.push(skill.name);
|
|
496
|
+
options.onProgress?.(skill.name, "updated");
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
return ok(undefined);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
type SkillGroup =
|
|
503
|
+
| { type: "linked"; skill: InstalledSkill }
|
|
504
|
+
| { type: "npm"; skill: InstalledSkill }
|
|
505
|
+
| { type: "git-standalone"; skill: InstalledSkill }
|
|
506
|
+
| { type: "git-multi"; repo: string; skills: InstalledSkill[] };
|
|
507
|
+
|
|
508
|
+
/** Group skills by update strategy. Multi-skill records sharing a repo cache are grouped together. */
|
|
509
|
+
function groupSkillsByRepo(skills: InstalledSkill[]): SkillGroup[] {
|
|
510
|
+
const multiGroups = new Map<string, InstalledSkill[]>();
|
|
511
|
+
const solo: SkillGroup[] = [];
|
|
512
|
+
|
|
513
|
+
for (const skill of skills) {
|
|
514
|
+
if (skill.scope === "linked") {
|
|
515
|
+
solo.push({ type: "linked", skill });
|
|
516
|
+
continue;
|
|
517
|
+
}
|
|
518
|
+
if (skill.repo?.startsWith("npm:")) {
|
|
519
|
+
solo.push({ type: "npm", skill });
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
if (skill.path !== null && skill.repo) {
|
|
523
|
+
const existing = multiGroups.get(skill.repo);
|
|
524
|
+
if (existing) {
|
|
525
|
+
existing.push(skill);
|
|
526
|
+
} else {
|
|
527
|
+
multiGroups.set(skill.repo, [skill]);
|
|
528
|
+
}
|
|
529
|
+
} else {
|
|
530
|
+
solo.push({ type: "git-standalone", skill });
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
const groups: SkillGroup[] = [...solo];
|
|
535
|
+
for (const [repo, skills] of multiGroups) {
|
|
536
|
+
groups.push({ type: "git-multi", repo, skills });
|
|
537
|
+
}
|
|
538
|
+
return groups;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
async function runUpdatePass(
|
|
542
|
+
skills: InstalledSkill[],
|
|
543
|
+
installed: InstalledJson,
|
|
544
|
+
options: UpdateOptions,
|
|
545
|
+
result: UpdateResult,
|
|
546
|
+
_resolveTrust: ResolveTrustFn,
|
|
547
|
+
): Promise<Result<void, UserError | GitError | ScanError | NetworkError>> {
|
|
548
|
+
const groups = groupSkillsByRepo(skills);
|
|
549
|
+
|
|
550
|
+
for (const group of groups) {
|
|
551
|
+
if (group.type === "linked") {
|
|
552
|
+
options.onProgress?.(group.skill.name, "linked");
|
|
553
|
+
continue;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
if (group.type === "npm") {
|
|
557
|
+
options.onProgress?.(group.skill.name, "checking");
|
|
558
|
+
const r = await updateNpmSkill(group.skill, installed, options, result, _resolveTrust);
|
|
559
|
+
if (!r.ok) return r;
|
|
560
|
+
} else if (group.type === "git-standalone") {
|
|
561
|
+
options.onProgress?.(group.skill.name, "checking");
|
|
562
|
+
const r = await updateGitSkill(group.skill, installed, options, result, _resolveTrust);
|
|
563
|
+
if (!r.ok) return r;
|
|
564
|
+
} else {
|
|
565
|
+
const r = await updateGitSkillGroup(group.repo, group.skills, installed, options, result, _resolveTrust);
|
|
566
|
+
if (!r.ok) return r;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
return ok(undefined);
|
|
571
|
+
}
|
|
572
|
+
|
|
417
573
|
export async function updateSkill(
|
|
418
574
|
options: UpdateOptions = {},
|
|
419
575
|
_resolveTrust: ResolveTrustFn = resolveTrust,
|
|
420
576
|
): Promise<Result<UpdateResult, UserError | GitError | ScanError | NetworkError>> {
|
|
421
577
|
debug("updateSkill", { name: options.name ?? "all" });
|
|
422
|
-
const installedResult = await loadInstalled();
|
|
423
|
-
if (!installedResult.ok) return installedResult;
|
|
424
|
-
const installed = installedResult.value;
|
|
425
578
|
|
|
426
|
-
|
|
579
|
+
// Load global installed
|
|
580
|
+
const globalInstalledResult = await loadInstalled();
|
|
581
|
+
if (!globalInstalledResult.ok) return globalInstalledResult;
|
|
582
|
+
const globalInstalled = globalInstalledResult.value;
|
|
583
|
+
|
|
584
|
+
// Optionally load project installed
|
|
585
|
+
let projectInstalled: InstalledJson | null = null;
|
|
586
|
+
if (options.projectRoot) {
|
|
587
|
+
const r = await loadInstalled(options.projectRoot);
|
|
588
|
+
if (!r.ok) return r;
|
|
589
|
+
projectInstalled = r.value;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// Filter by name if specified — check both files
|
|
593
|
+
let globalSkills = globalInstalled.skills;
|
|
594
|
+
let projectSkills = projectInstalled?.skills ?? [];
|
|
595
|
+
|
|
427
596
|
if (options.name) {
|
|
428
|
-
|
|
429
|
-
|
|
597
|
+
globalSkills = globalSkills.filter((s) => s.name === options.name);
|
|
598
|
+
projectSkills = projectSkills.filter((s) => s.name === options.name);
|
|
599
|
+
if (globalSkills.length === 0 && projectSkills.length === 0) {
|
|
430
600
|
return err(
|
|
431
601
|
new UserError(
|
|
432
602
|
`Skill '${options.name}' is not installed.`,
|
|
@@ -434,31 +604,28 @@ export async function updateSkill(
|
|
|
434
604
|
),
|
|
435
605
|
);
|
|
436
606
|
}
|
|
437
|
-
skills = found;
|
|
438
607
|
}
|
|
439
608
|
|
|
440
609
|
const result: UpdateResult = { updated: [], skipped: [], upToDate: [] };
|
|
441
610
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
continue;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
options.onProgress?.(record.name, "checking");
|
|
611
|
+
// Process global skills
|
|
612
|
+
const globalPass = await runUpdatePass(globalSkills, globalInstalled, options, result, _resolveTrust);
|
|
613
|
+
if (!globalPass.ok) return globalPass;
|
|
449
614
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
} else {
|
|
455
|
-
const gitResult = await updateGitSkill(record, installed, options, result, _resolveTrust);
|
|
456
|
-
if (!gitResult.ok) return gitResult;
|
|
457
|
-
}
|
|
615
|
+
// Process project skills
|
|
616
|
+
if (projectInstalled) {
|
|
617
|
+
const projectPass = await runUpdatePass(projectSkills, projectInstalled, { ...options, projectRoot: options.projectRoot }, result, _resolveTrust);
|
|
618
|
+
if (!projectPass.ok) return projectPass;
|
|
458
619
|
}
|
|
459
620
|
|
|
460
|
-
|
|
461
|
-
|
|
621
|
+
// Save both files
|
|
622
|
+
const globalSave = await saveInstalled(globalInstalled);
|
|
623
|
+
if (!globalSave.ok) return globalSave;
|
|
624
|
+
|
|
625
|
+
if (projectInstalled && options.projectRoot) {
|
|
626
|
+
const projectSave = await saveInstalled(projectInstalled, options.projectRoot);
|
|
627
|
+
if (!projectSave.ok) return projectSave;
|
|
628
|
+
}
|
|
462
629
|
|
|
463
630
|
return ok(result);
|
|
464
631
|
}
|