@artifactshare/cli 0.20.0 → 0.20.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/CHANGELOG.md +16 -0
- package/README.md +33 -25
- package/dist/cli.js +675 -117
- package/package.json +1 -1
- package/skills/artifactshare/SKILL.md +2 -2
- package/skills/artifactshare/references/authentication-profiles-skills.md +9 -1
package/dist/cli.js
CHANGED
|
@@ -6,7 +6,7 @@ import { generate } from "gunshi/generator";
|
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { execFile, spawn } from "node:child_process";
|
|
8
8
|
import * as fs from "node:fs/promises";
|
|
9
|
-
import { chmod, lstat, mkdir, readFile, readdir, realpath, rename, rmdir, stat, unlink, writeFile } from "node:fs/promises";
|
|
9
|
+
import { chmod, lstat, mkdir, readFile, readdir, realpath, rename, rm, rmdir, stat, unlink, writeFile } from "node:fs/promises";
|
|
10
10
|
import { arch, homedir, platform } from "node:os";
|
|
11
11
|
import path, { basename, dirname, extname, join, relative, resolve, sep } from "node:path";
|
|
12
12
|
import { createHash, randomUUID } from "node:crypto";
|
|
@@ -716,7 +716,17 @@ const SkillLegacyDiagnosticSchema = z.object({
|
|
|
716
716
|
coexistence: z.boolean(),
|
|
717
717
|
hint: z.string().nullable()
|
|
718
718
|
});
|
|
719
|
+
const SkillTargetIdentityShape = {
|
|
720
|
+
aliases: z.array(z.object({
|
|
721
|
+
tool: z.string(),
|
|
722
|
+
scope: z.string(),
|
|
723
|
+
path: z.string().nullable(),
|
|
724
|
+
folder_path: z.string().nullable()
|
|
725
|
+
})).optional(),
|
|
726
|
+
resolved_folder_path: z.string().nullable().optional()
|
|
727
|
+
};
|
|
719
728
|
const LocalSkillTargetSchema = z.object({
|
|
729
|
+
...SkillTargetIdentityShape,
|
|
720
730
|
folder_path: z.string().nullable(),
|
|
721
731
|
complete: z.boolean(),
|
|
722
732
|
current: z.boolean(),
|
|
@@ -724,6 +734,8 @@ const LocalSkillTargetSchema = z.object({
|
|
|
724
734
|
missing_files: z.array(z.string()),
|
|
725
735
|
different_files: z.array(z.string()),
|
|
726
736
|
modified_files: z.array(z.string()),
|
|
737
|
+
user_links: z.array(z.string()).optional(),
|
|
738
|
+
interrupted_update: z.boolean().optional(),
|
|
727
739
|
ownership_manifest: z.enum([
|
|
728
740
|
"valid",
|
|
729
741
|
"absent",
|
|
@@ -763,6 +775,7 @@ const SkillLegacyActionSchema = z.object({
|
|
|
763
775
|
hint: z.string().optional()
|
|
764
776
|
});
|
|
765
777
|
const SkillsActionTargetSchema = z.object({
|
|
778
|
+
...SkillTargetIdentityShape,
|
|
766
779
|
tool: z.string(),
|
|
767
780
|
scope: z.string(),
|
|
768
781
|
path: z.string().nullable(),
|
|
@@ -775,6 +788,7 @@ const SkillsActionTargetSchema = z.object({
|
|
|
775
788
|
"removed",
|
|
776
789
|
"not_installed",
|
|
777
790
|
"skipped_unmanaged",
|
|
791
|
+
"failed",
|
|
778
792
|
"skipped"
|
|
779
793
|
]),
|
|
780
794
|
update_command: z.string().optional(),
|
|
@@ -786,6 +800,16 @@ z.object({
|
|
|
786
800
|
dry_run: z.boolean(),
|
|
787
801
|
targets: z.array(SkillsActionTargetSchema)
|
|
788
802
|
});
|
|
803
|
+
const SkillAutoUpdateTargetSchema = SkillsActionTargetSchema.extend({
|
|
804
|
+
path: z.string(),
|
|
805
|
+
folder_path: z.string(),
|
|
806
|
+
scope: z.enum(["user", "project"]),
|
|
807
|
+
action: z.enum(["updated", "update_recommended"]),
|
|
808
|
+
installed_version: z.number().nullable(),
|
|
809
|
+
bundled_version: z.number()
|
|
810
|
+
});
|
|
811
|
+
const SkillAutoUpdateDataSchema = z.object({ targets: z.array(SkillAutoUpdateTargetSchema) });
|
|
812
|
+
z.object({ skills: z.object({ auto_update: SkillAutoUpdateDataSchema.optional() }).optional() });
|
|
789
813
|
//#endregion
|
|
790
814
|
//#region src/constants.ts
|
|
791
815
|
const DEFAULT_BASE_URL = "https://artifactshare.com";
|
|
@@ -2147,8 +2171,11 @@ function skillAutoUpdateHumanOutput(data) {
|
|
|
2147
2171
|
const autoUpdate = skills.auto_update;
|
|
2148
2172
|
if (!isRecord$1(autoUpdate) || !Array.isArray(autoUpdate.targets)) return "";
|
|
2149
2173
|
const lines = autoUpdate.targets.filter(isRecord$1).map((target) => {
|
|
2150
|
-
const label = typeof target.tool === "string" && typeof target.scope === "string" ? `${target.tool}:${target.scope}` : "unknown";
|
|
2151
|
-
if (target.action === "update_recommended"
|
|
2174
|
+
const label = Array.isArray(target.aliases) ? target.aliases.filter(isRecord$1).map((alias) => `${alias.tool}:${alias.scope}`).join(", ") : typeof target.tool === "string" && typeof target.scope === "string" ? `${target.tool}:${target.scope}` : "unknown";
|
|
2175
|
+
if (target.action === "update_recommended") {
|
|
2176
|
+
const advice = [target.update_command, target.hint].filter((value) => typeof value === "string").join("; ");
|
|
2177
|
+
return `Skill update recommended: ${label}${advice ? ` (${advice})` : ""}`;
|
|
2178
|
+
}
|
|
2152
2179
|
return `Skill updated: ${label}`;
|
|
2153
2180
|
});
|
|
2154
2181
|
return lines.length > 0 ? `${lines.join("\n")}\n` : "";
|
|
@@ -4224,6 +4251,7 @@ async function runArtifactsList(parsed, mode) {
|
|
|
4224
4251
|
//#endregion
|
|
4225
4252
|
//#region src/command-runners/skill-folder.ts
|
|
4226
4253
|
const MANIFEST = ".artifactshare-managed.json";
|
|
4254
|
+
const PENDING = ".artifactshare-pending.json";
|
|
4227
4255
|
function managedState(content) {
|
|
4228
4256
|
if (content === null) return { kind: "missing" };
|
|
4229
4257
|
if (!content.includes("artifactshare-skill")) return { kind: "unmanaged" };
|
|
@@ -4245,10 +4273,110 @@ async function info(path) {
|
|
|
4245
4273
|
throw error;
|
|
4246
4274
|
}
|
|
4247
4275
|
}
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4276
|
+
var SkillFolderResolutionError = class extends Error {
|
|
4277
|
+
missingAncestor;
|
|
4278
|
+
constructor(path, missingAncestor = false) {
|
|
4279
|
+
super(`${missingAncestor ? "Skill not installed; dangling ancestor link" : "Unsafe skill folder"}: ${path}. Restore or repoint the link to a directory, or replace it with a real directory, then retry.`);
|
|
4280
|
+
this.missingAncestor = missingAncestor;
|
|
4281
|
+
}
|
|
4282
|
+
};
|
|
4283
|
+
function resolveSkillFolder(entry) {
|
|
4284
|
+
const resolveDirectory = async (path) => {
|
|
4285
|
+
let item;
|
|
4286
|
+
try {
|
|
4287
|
+
item = await info(path);
|
|
4288
|
+
if (!item) return join(await resolveDirectory(dirname(path)), basename(path));
|
|
4289
|
+
const canonical = await realpath(path);
|
|
4290
|
+
if (!(await lstat(canonical)).isDirectory()) throw new Error("Not a directory");
|
|
4291
|
+
return canonical;
|
|
4292
|
+
} catch (error) {
|
|
4293
|
+
if (error instanceof SkillFolderResolutionError) throw error;
|
|
4294
|
+
throw new SkillFolderResolutionError(path, item?.isSymbolicLink() === true && error.code === "ENOENT");
|
|
4295
|
+
}
|
|
4296
|
+
};
|
|
4297
|
+
return resolveDirectory(dirname(entry));
|
|
4298
|
+
}
|
|
4299
|
+
const rootFor = resolveSkillFolder;
|
|
4300
|
+
const uuid = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
|
4301
|
+
const legacyTemp = new RegExp(`^\\.artifactshare-${uuid}\\.tmp$`, "i");
|
|
4302
|
+
const stagingName = new RegExp(`^\\.artifactshare-staging-${uuid}$`, "i");
|
|
4303
|
+
const stale = (item) => item.mtimeMs < Date.now() - 6e5;
|
|
4304
|
+
async function protectedPaths(root, bundle) {
|
|
4305
|
+
await safe(root, MANIFEST);
|
|
4306
|
+
await safe(root, PENDING);
|
|
4307
|
+
const state = await stateAt(root);
|
|
4308
|
+
const pending = await ownership(root, state, PENDING);
|
|
4309
|
+
const owned = await ownership(root, state, MANIFEST, pending.manifest);
|
|
4310
|
+
const paths = /* @__PURE__ */ new Set([
|
|
4311
|
+
"SKILL.md",
|
|
4312
|
+
"references",
|
|
4313
|
+
MANIFEST,
|
|
4314
|
+
PENDING
|
|
4315
|
+
]);
|
|
4316
|
+
for (const path of [
|
|
4317
|
+
...Object.keys(bundle?.files ?? {}),
|
|
4318
|
+
...Object.keys(owned.manifest?.files ?? {}),
|
|
4319
|
+
...Object.keys(pending.manifest?.files ?? {}),
|
|
4320
|
+
...Object.keys(pending.manifest?.previous_files ?? {})
|
|
4321
|
+
]) {
|
|
4322
|
+
const parts = path.split("/");
|
|
4323
|
+
for (let i = 1; i <= parts.length; i++) paths.add(parts.slice(0, i).join("/"));
|
|
4324
|
+
}
|
|
4325
|
+
return paths;
|
|
4326
|
+
}
|
|
4327
|
+
async function isProtectedLink(root, item, protectedEntries, lookup = info) {
|
|
4328
|
+
for (const entry of protectedEntries) {
|
|
4329
|
+
let path = root;
|
|
4330
|
+
for (const part of entry.split("/")) {
|
|
4331
|
+
path = join(path, part);
|
|
4332
|
+
const candidate = await lookup(path);
|
|
4333
|
+
if (!candidate) break;
|
|
4334
|
+
if (candidate.dev === item.dev && candidate.ino === item.ino) return true;
|
|
4335
|
+
if (!candidate.isDirectory()) break;
|
|
4336
|
+
}
|
|
4337
|
+
}
|
|
4338
|
+
return false;
|
|
4339
|
+
}
|
|
4340
|
+
async function inspectTree(root, cleanup = false, folderRoot = root, protectedEntries, userLinks = []) {
|
|
4341
|
+
if (!await info(root)) return userLinks;
|
|
4342
|
+
for (const name of (await readdir(root)).sort()) {
|
|
4343
|
+
const path = join(root, name);
|
|
4344
|
+
const item = await lstat(path);
|
|
4345
|
+
if (item.isSymbolicLink()) {
|
|
4346
|
+
const entry = relative(folderRoot, path).split(sep).join("/");
|
|
4347
|
+
if (protectedEntries && (protectedEntries.has(entry) || await isProtectedLink(folderRoot, item, protectedEntries) || name === MANIFEST || name === PENDING || stagingName.test(name) || legacyTemp.test(name))) throw new Error(`Unsafe skill path (link): ${entry}. Replace the link with a regular file or directory or remove it, then retry.`);
|
|
4348
|
+
userLinks.push(entry);
|
|
4349
|
+
continue;
|
|
4350
|
+
}
|
|
4351
|
+
if (item.isDirectory() && root === folderRoot && stagingName.test(name)) {
|
|
4352
|
+
await inspectTree(path, false, folderRoot, protectedEntries, userLinks);
|
|
4353
|
+
if (cleanup && stale(item) && !userLinks.some((link) => link.startsWith(`${name}/`))) await rm(path, {
|
|
4354
|
+
recursive: true,
|
|
4355
|
+
force: true
|
|
4356
|
+
});
|
|
4357
|
+
} else if (item.isDirectory()) await inspectTree(path, cleanup, folderRoot, protectedEntries, userLinks);
|
|
4358
|
+
else if (cleanup && item.isFile() && legacyTemp.test(name) && stale(item)) await unlink(path);
|
|
4359
|
+
}
|
|
4360
|
+
return userLinks.sort();
|
|
4361
|
+
}
|
|
4362
|
+
async function cleanupSkillFolder(entry, bundle) {
|
|
4363
|
+
const root = await rootFor(entry);
|
|
4364
|
+
if (bundle) {
|
|
4365
|
+
const pending = await ownership(root, await stateAt(root), PENDING);
|
|
4366
|
+
if (pending.manifest && pending.manifest.version > bundle.version) throw new Error(newerIntentHint(pending.manifest.version));
|
|
4367
|
+
}
|
|
4368
|
+
const protection = await protectedPaths(root, bundle);
|
|
4369
|
+
await inspectTree(root, false, root, protection);
|
|
4370
|
+
await inspectTree(root, true, root, protection);
|
|
4371
|
+
const parent = dirname(root);
|
|
4372
|
+
if (await info(parent)) for (const name of await readdir(parent)) {
|
|
4373
|
+
if (!stagingName.test(name)) continue;
|
|
4374
|
+
const item = await lstat(join(parent, name));
|
|
4375
|
+
if (item.isDirectory() && stale(item)) await rm(join(parent, name), {
|
|
4376
|
+
recursive: true,
|
|
4377
|
+
force: true
|
|
4378
|
+
});
|
|
4379
|
+
}
|
|
4252
4380
|
}
|
|
4253
4381
|
async function safe(root, relative, retiredAncestors = /* @__PURE__ */ new Set(), replacedDirectories = /* @__PURE__ */ new Set()) {
|
|
4254
4382
|
const parts = [
|
|
@@ -4260,7 +4388,7 @@ async function safe(root, relative, retiredAncestors = /* @__PURE__ */ new Set()
|
|
|
4260
4388
|
const item = await info(parts[i]);
|
|
4261
4389
|
if (i < parts.length - 1 && item?.isFile() && retiredAncestors.has(parts[i])) return;
|
|
4262
4390
|
if (i === parts.length - 1 && item?.isDirectory() && replacedDirectories.has(parts[i])) continue;
|
|
4263
|
-
if (item && (item.isSymbolicLink() || (i === parts.length - 1 ? !item.isFile() : !item.isDirectory()))) throw new Error(`Unsafe skill path (type change or link): ${parts[i]}.
|
|
4391
|
+
if (item && (item.isSymbolicLink() || (i === parts.length - 1 ? !item.isFile() : !item.isDirectory()))) throw new Error(`Unsafe skill path (type change or link): ${parts[i]}. Replace the link with a regular file or directory or remove it, then retry.`);
|
|
4264
4392
|
}
|
|
4265
4393
|
}
|
|
4266
4394
|
async function bytesAt(root, path) {
|
|
@@ -4273,15 +4401,41 @@ async function bytesAt(root, path) {
|
|
|
4273
4401
|
async function textAt(root, path) {
|
|
4274
4402
|
return (await bytesAt(root, path))?.toString("utf8") ?? null;
|
|
4275
4403
|
}
|
|
4404
|
+
async function recordsAbsent(root) {
|
|
4405
|
+
return !await info(join(root, MANIFEST)) && !await info(join(root, PENDING));
|
|
4406
|
+
}
|
|
4407
|
+
async function unownedAt(root) {
|
|
4408
|
+
if (!await recordsAbsent(root)) return false;
|
|
4409
|
+
const entry = await info(join(root, "SKILL.md"));
|
|
4410
|
+
if (!entry || entry.isSymbolicLink()) return true;
|
|
4411
|
+
return (await stateAt(root)).kind === "unmanaged";
|
|
4412
|
+
}
|
|
4413
|
+
async function isUnownedFolder(entry, managedLegacy = false) {
|
|
4414
|
+
if (managedLegacy) return false;
|
|
4415
|
+
try {
|
|
4416
|
+
return await unownedAt(await rootFor(entry));
|
|
4417
|
+
} catch {
|
|
4418
|
+
return false;
|
|
4419
|
+
}
|
|
4420
|
+
}
|
|
4276
4421
|
async function stateAt(root) {
|
|
4277
4422
|
try {
|
|
4423
|
+
if ((await info(join(root, "SKILL.md")))?.isSymbolicLink() && await recordsAbsent(root)) return { kind: "unmanaged" };
|
|
4278
4424
|
return managedState(await textAt(root, "SKILL.md"));
|
|
4279
4425
|
} catch {
|
|
4280
4426
|
return { kind: "broken" };
|
|
4281
4427
|
}
|
|
4282
4428
|
}
|
|
4283
4429
|
async function readSkillState(entry) {
|
|
4284
|
-
|
|
4430
|
+
try {
|
|
4431
|
+
return await stateAt(await rootFor(entry));
|
|
4432
|
+
} catch (error) {
|
|
4433
|
+
if (error instanceof SkillFolderResolutionError && error.missingAncestor) return {
|
|
4434
|
+
kind: "missing",
|
|
4435
|
+
hint: error.message
|
|
4436
|
+
};
|
|
4437
|
+
return { kind: "broken" };
|
|
4438
|
+
}
|
|
4285
4439
|
}
|
|
4286
4440
|
async function loadSkillBundle(root) {
|
|
4287
4441
|
const files = {};
|
|
@@ -4303,14 +4457,17 @@ async function loadSkillBundle(root) {
|
|
|
4303
4457
|
version: state.version
|
|
4304
4458
|
};
|
|
4305
4459
|
}
|
|
4306
|
-
async function ownership(root, state) {
|
|
4460
|
+
async function ownership(root, state, record = MANIFEST, pending) {
|
|
4307
4461
|
try {
|
|
4308
|
-
const text = await textAt(root,
|
|
4462
|
+
const text = await textAt(root, record);
|
|
4309
4463
|
if (text === null) return { status: "absent" };
|
|
4310
4464
|
const value = JSON.parse(text);
|
|
4311
|
-
if (state.kind
|
|
4312
|
-
const
|
|
4313
|
-
|
|
4465
|
+
if (value.schema_version !== 1 || !Number.isSafeInteger(value.version) || value.version < 0 || record === MANIFEST && (state.kind === "managed" ? value.version !== state.version && value.version !== pending?.version : state.kind !== "missing" || !pending) || !value.files || typeof value.files !== "object" || Array.isArray(value.files) || !Object.hasOwn(value.files, "SKILL.md")) return { status: "invalid" };
|
|
4466
|
+
for (const files of [value.files, ...value.previous_files === void 0 ? [] : [value.previous_files]]) {
|
|
4467
|
+
if (!files || typeof files !== "object" || Array.isArray(files)) return { status: "invalid" };
|
|
4468
|
+
const paths = Object.keys(files);
|
|
4469
|
+
if (new Set(paths.map((path) => path.toLowerCase())).size !== paths.length || !paths.every((path) => validPath(path) && typeof files[path] === "string" && /^[a-f0-9]{64}$/.test(files[path]))) return { status: "invalid" };
|
|
4470
|
+
}
|
|
4314
4471
|
return {
|
|
4315
4472
|
status: "valid",
|
|
4316
4473
|
manifest: value
|
|
@@ -4319,45 +4476,101 @@ async function ownership(root, state) {
|
|
|
4319
4476
|
return { status: "invalid" };
|
|
4320
4477
|
}
|
|
4321
4478
|
}
|
|
4322
|
-
async function
|
|
4323
|
-
const
|
|
4479
|
+
async function recoveryOwnership(root, state) {
|
|
4480
|
+
const pending = await ownership(root, state, PENDING);
|
|
4481
|
+
const owned = await ownership(root, state, MANIFEST, pending.manifest);
|
|
4482
|
+
const recorded = { ...owned.manifest?.files ?? (state.kind === "managed" && pending.status === "absent" ? { "SKILL.md": hash(await bytesAt(root, "SKILL.md")) } : {}) };
|
|
4483
|
+
for (const [path, expected] of Object.entries(pending.manifest?.previous_files ?? {})) {
|
|
4484
|
+
const bytes = await bytesAt(root, path).catch(() => null);
|
|
4485
|
+
if (bytes !== null && hash(bytes) === expected) recorded[path] = expected;
|
|
4486
|
+
}
|
|
4487
|
+
for (const [path, expected] of Object.entries(pending.manifest?.files ?? {})) {
|
|
4488
|
+
const bytes = await bytesAt(root, path).catch(() => null);
|
|
4489
|
+
if (bytes !== null && hash(bytes) === expected) recorded[path] = expected;
|
|
4490
|
+
}
|
|
4491
|
+
for (const [path, expected] of Object.entries(pending.manifest?.files ?? {})) {
|
|
4492
|
+
const bytes = await bytesAt(root, path).catch(() => null);
|
|
4493
|
+
if (bytes !== null && hash(bytes) === expected) {
|
|
4494
|
+
for (const old of Object.keys(recorded)) if (old.startsWith(`${path}/`)) delete recorded[old];
|
|
4495
|
+
}
|
|
4496
|
+
}
|
|
4497
|
+
for (const path of Object.keys(recorded)) if ((await info(join(root, path)).catch(() => null))?.isDirectory() && Object.keys(pending.manifest?.files ?? {}).some((next) => next.startsWith(`${path}/`))) delete recorded[path];
|
|
4498
|
+
return {
|
|
4499
|
+
owned,
|
|
4500
|
+
pending,
|
|
4501
|
+
recorded
|
|
4502
|
+
};
|
|
4503
|
+
}
|
|
4504
|
+
async function folderDiagnostics(entry, bundle, managedLegacy = false) {
|
|
4505
|
+
let root = null;
|
|
4506
|
+
let user_links = [];
|
|
4507
|
+
try {
|
|
4508
|
+
root = await rootFor(entry);
|
|
4509
|
+
user_links = await inspectTree(root, false, root, !managedLegacy && await unownedAt(root) ? void 0 : await protectedPaths(root, bundle));
|
|
4510
|
+
} catch (error) {
|
|
4511
|
+
return {
|
|
4512
|
+
folder_path: dirname(entry),
|
|
4513
|
+
resolved_folder_path: root,
|
|
4514
|
+
complete: false,
|
|
4515
|
+
current: false,
|
|
4516
|
+
older_version: false,
|
|
4517
|
+
missing_files: [],
|
|
4518
|
+
different_files: [],
|
|
4519
|
+
modified_files: [],
|
|
4520
|
+
...error instanceof SkillFolderResolutionError && error.missingAncestor ? { ownership_manifest: "absent" } : {
|
|
4521
|
+
ownership_manifest: "invalid",
|
|
4522
|
+
code: "skill_update_conflict"
|
|
4523
|
+
},
|
|
4524
|
+
hint: error.message
|
|
4525
|
+
};
|
|
4526
|
+
}
|
|
4324
4527
|
const state = await stateAt(root);
|
|
4325
|
-
const owned = await
|
|
4528
|
+
const { owned, pending, recorded } = await recoveryOwnership(root, state);
|
|
4529
|
+
const newerIntent = pending.manifest && pending.manifest.version > bundle.version;
|
|
4326
4530
|
const missing_files = [], different_files = [], modified_files = [];
|
|
4327
4531
|
for (const path of Object.keys(bundle.files).sort()) {
|
|
4328
4532
|
const text = await bytesAt(root, path).catch(() => null);
|
|
4329
4533
|
if (text === null) missing_files.push(path);
|
|
4330
4534
|
else if (!text.equals(Buffer.from(bundle.files[path]))) different_files.push(path);
|
|
4331
4535
|
}
|
|
4332
|
-
|
|
4536
|
+
for (const [path, expected] of Object.entries(recorded).sort()) {
|
|
4333
4537
|
const text = await bytesAt(root, path).catch(() => null);
|
|
4334
|
-
if (text === null
|
|
4538
|
+
if (expected && (text === null ? pending.status === "absent" : hash(text) !== expected)) modified_files.push(path);
|
|
4335
4539
|
}
|
|
4336
4540
|
const manifestMatches = owned.manifest !== void 0 && Object.keys(owned.manifest.files).length === Object.keys(bundle.files).length && Object.entries(bundle.files).every(([path, text]) => owned.manifest?.files[path] === hash(text));
|
|
4337
4541
|
return {
|
|
4338
4542
|
folder_path: dirname(entry),
|
|
4543
|
+
resolved_folder_path: root,
|
|
4339
4544
|
complete: missing_files.length === 0,
|
|
4340
|
-
current: state.kind === "managed" && state.version === bundle.version && !missing_files.length && !different_files.length && owned.status === "valid" && manifestMatches,
|
|
4545
|
+
current: state.kind === "managed" && state.version === bundle.version && !missing_files.length && !different_files.length && owned.status === "valid" && manifestMatches && pending.status === "absent",
|
|
4546
|
+
...pending.status !== "absent" ? { interrupted_update: true } : {},
|
|
4341
4547
|
older_version: state.kind === "managed" && state.version < bundle.version,
|
|
4548
|
+
user_links,
|
|
4342
4549
|
missing_files,
|
|
4343
4550
|
different_files,
|
|
4344
4551
|
modified_files,
|
|
4345
|
-
ownership_manifest: owned.status
|
|
4552
|
+
ownership_manifest: owned.status,
|
|
4553
|
+
...newerIntent ? { hint: newerIntentHint(pending.manifest.version) } : {}
|
|
4346
4554
|
};
|
|
4347
4555
|
}
|
|
4348
|
-
|
|
4556
|
+
function newerIntentHint(version) {
|
|
4557
|
+
return `Interrupted skill update requires a newer CLI with bundled skill version ${version} or later. Upgrade the CLI, then retry.`;
|
|
4558
|
+
}
|
|
4559
|
+
async function preflightFolder(entry, bundle, force = false, forceRetirement = force, removing = false) {
|
|
4349
4560
|
const root = await rootFor(entry);
|
|
4350
4561
|
const state = await stateAt(root);
|
|
4562
|
+
await inspectTree(root, false, root, await protectedPaths(root, bundle));
|
|
4351
4563
|
await safe(root, "SKILL.md");
|
|
4352
|
-
const owned = await
|
|
4353
|
-
if (
|
|
4354
|
-
|
|
4564
|
+
const { owned, pending, recorded } = await recoveryOwnership(root, state);
|
|
4565
|
+
if (!removing && bundle && pending.manifest && pending.manifest.version > bundle.version) throw new Error(newerIntentHint(pending.manifest.version));
|
|
4566
|
+
if ((owned.status === "invalid" || pending.status === "invalid") && !force || !force && state.kind !== "managed" && state.kind !== "missing") throw new Error(`Skill ownership conflict: ${join(root, state.kind === "managed" ? MANIFEST : "SKILL.md")} (${state.kind === "managed" ? "invalid ownership metadata" : "user-edited file"}). Inspect the folder and use skills install --force to reinstall bundled paths.`);
|
|
4567
|
+
const previous = recorded;
|
|
4568
|
+
await safe(root, PENDING);
|
|
4355
4569
|
await safe(root, MANIFEST);
|
|
4356
4570
|
for (const path of Object.keys(previous)) await safe(root, path);
|
|
4357
4571
|
if (!forceRetirement) for (const [path, expected] of Object.entries(previous)) {
|
|
4358
|
-
if (bundle && Object.hasOwn(bundle.files, path)) continue;
|
|
4359
4572
|
const bytes = await bytesAt(root, path);
|
|
4360
|
-
if (expected && bytes !== null && hash(bytes) !== expected) throw new Error(`Modified skill file: ${path}. Preserve your edits before removing
|
|
4573
|
+
if (expected && bytes !== null && hash(bytes) !== expected) throw new Error(`Modified skill file: ${path}. Preserve your edits before removing this file, or use skills update --force to replace edited managed files.`);
|
|
4361
4574
|
}
|
|
4362
4575
|
const blockers = Object.keys(previous).filter((path) => bundle && !Object.hasOwn(bundle.files, path) && Object.keys(bundle.files).some((next) => next.startsWith(`${path}/`)));
|
|
4363
4576
|
const retiredAncestors = new Set(blockers.map((path) => join(root, path)));
|
|
@@ -4367,12 +4580,16 @@ async function preflightFolder(entry, bundle, force = false, forceRetirement = f
|
|
|
4367
4580
|
for (const name of await readdir(join(root, relative))) {
|
|
4368
4581
|
const child = `${relative}/${name}`;
|
|
4369
4582
|
const item = await info(join(root, child));
|
|
4583
|
+
if (item?.isFile() && legacyTemp.test(name)) {
|
|
4584
|
+
if (stale(item)) continue;
|
|
4585
|
+
throw new Error(`Recent skill temporary file: ${child}. Retry after the active update has finished and temporary files are older than ten minutes.`);
|
|
4586
|
+
}
|
|
4370
4587
|
if (item?.isDirectory()) await checkDirectory(child);
|
|
4371
4588
|
else if (!item?.isFile() || !Object.hasOwn(previous, child)) throw new Error(`Unowned skill file or type change: ${child}. Preserve or move this entry before updating.`);
|
|
4372
4589
|
}
|
|
4373
4590
|
replacedDirectories.add(join(root, relative));
|
|
4374
4591
|
};
|
|
4375
|
-
for (const path of Object.keys(bundle?.files ?? {})) {
|
|
4592
|
+
for (const path of Object.keys(removing ? {} : bundle?.files ?? {})) {
|
|
4376
4593
|
if (!blockers.some((ancestor) => path.startsWith(`${ancestor}/`))) {
|
|
4377
4594
|
await safe(root, path, retiredAncestors, /* @__PURE__ */ new Set([join(root, path)]));
|
|
4378
4595
|
if ((await info(join(root, path)))?.isDirectory()) await checkDirectory(path);
|
|
@@ -4398,7 +4615,8 @@ async function prune(root, paths) {
|
|
|
4398
4615
|
}
|
|
4399
4616
|
for (const dir of [...dirs].sort((a, b) => b.length - a.length)) await rmdir(dir).catch(() => {});
|
|
4400
4617
|
}
|
|
4401
|
-
async function writeSkillFolder(entry, bundle, force = false, forceRetirement = force) {
|
|
4618
|
+
async function writeSkillFolder(entry, bundle, force = false, forceRetirement = force, cleanup = true) {
|
|
4619
|
+
if (cleanup) await cleanupSkillFolder(entry, bundle);
|
|
4402
4620
|
const { root, previous, blockers, replacedDirectories } = await preflightFolder(entry, bundle, force, forceRetirement);
|
|
4403
4621
|
const files = {
|
|
4404
4622
|
...bundle.files,
|
|
@@ -4408,6 +4626,8 @@ async function writeSkillFolder(entry, bundle, force = false, forceRetirement =
|
|
|
4408
4626
|
files: Object.fromEntries(Object.entries(bundle.files).map(([path, text]) => [path, hash(text)]))
|
|
4409
4627
|
}, null, 2) + "\n"
|
|
4410
4628
|
};
|
|
4629
|
+
const stagingDirectories = [];
|
|
4630
|
+
let internalStaging = false;
|
|
4411
4631
|
const staged = /* @__PURE__ */ new Map();
|
|
4412
4632
|
const backups = /* @__PURE__ */ new Map();
|
|
4413
4633
|
const changed = /* @__PURE__ */ new Set();
|
|
@@ -4419,10 +4639,37 @@ async function writeSkillFolder(entry, bundle, force = false, forceRetirement =
|
|
|
4419
4639
|
await mkdir(path);
|
|
4420
4640
|
createdDirectories.push(path);
|
|
4421
4641
|
};
|
|
4422
|
-
for (const path of /* @__PURE__ */ new Set([
|
|
4642
|
+
for (const path of /* @__PURE__ */ new Set([
|
|
4643
|
+
...Object.keys(previous),
|
|
4644
|
+
...Object.keys(files),
|
|
4645
|
+
PENDING
|
|
4646
|
+
])) {
|
|
4423
4647
|
const blocked = blockers.some((ancestor) => path.startsWith(`${ancestor}/`));
|
|
4424
4648
|
backups.set(path, !blocked && (await info(join(root, path)))?.isFile() ? await readFile(join(root, path)) : null);
|
|
4425
4649
|
}
|
|
4650
|
+
const intent = JSON.stringify({
|
|
4651
|
+
...JSON.parse(files[MANIFEST]),
|
|
4652
|
+
previous_files: previous
|
|
4653
|
+
}) + "\n";
|
|
4654
|
+
const stage = async (parent) => {
|
|
4655
|
+
await ensureDirectory(parent);
|
|
4656
|
+
const stagingDir = join(parent, `.artifactshare-staging-${randomUUID()}`);
|
|
4657
|
+
await mkdir(stagingDir, { mode: 448 });
|
|
4658
|
+
stagingDirectories.push(stagingDir);
|
|
4659
|
+
for (const [path, text] of Object.entries({
|
|
4660
|
+
...files,
|
|
4661
|
+
[PENDING]: intent
|
|
4662
|
+
})) {
|
|
4663
|
+
const temp = join(stagingDir, basename(path) === "SKILL.md" ? `${randomUUID()}.tmp` : path);
|
|
4664
|
+
await mkdir(dirname(temp), { recursive: true });
|
|
4665
|
+
await writeFile(temp, text, { flag: "wx" });
|
|
4666
|
+
staged.set(path, temp);
|
|
4667
|
+
}
|
|
4668
|
+
};
|
|
4669
|
+
const stageInside = async () => {
|
|
4670
|
+
internalStaging = true;
|
|
4671
|
+
await stage(root);
|
|
4672
|
+
};
|
|
4426
4673
|
const retire = async (path) => {
|
|
4427
4674
|
if (backups.get(path) !== null) {
|
|
4428
4675
|
await unlink(join(root, path));
|
|
@@ -4431,18 +4678,27 @@ async function writeSkillFolder(entry, bundle, force = false, forceRetirement =
|
|
|
4431
4678
|
};
|
|
4432
4679
|
const commit = async (path) => {
|
|
4433
4680
|
await ensureDirectory(dirname(join(root, path)));
|
|
4434
|
-
|
|
4681
|
+
try {
|
|
4682
|
+
await rename(staged.get(path), join(root, path));
|
|
4683
|
+
} catch (error) {
|
|
4684
|
+
if (internalStaging || error.code !== "EXDEV") throw error;
|
|
4685
|
+
await stageInside();
|
|
4686
|
+
await rename(staged.get(path), join(root, path));
|
|
4687
|
+
}
|
|
4435
4688
|
changed.add(path);
|
|
4436
4689
|
};
|
|
4437
4690
|
try {
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4691
|
+
try {
|
|
4692
|
+
await stage(dirname(root));
|
|
4693
|
+
} catch (error) {
|
|
4694
|
+
if (stagingDirectories.length !== 0 || ![
|
|
4695
|
+
"EACCES",
|
|
4696
|
+
"EPERM",
|
|
4697
|
+
"EROFS"
|
|
4698
|
+
].includes(error.code ?? "")) throw error;
|
|
4699
|
+
await stageInside();
|
|
4700
|
+
}
|
|
4701
|
+
await commit(PENDING);
|
|
4446
4702
|
const retired = Object.keys(previous).filter((path) => !Object.hasOwn(bundle.files, path));
|
|
4447
4703
|
const earlyRetired = new Set(retired.filter((path) => blockers.includes(path) || [...replacedDirectories].some((dir) => join(root, path).startsWith(`${dir}${sep}`))));
|
|
4448
4704
|
for (const path of earlyRetired) await retire(path);
|
|
@@ -4454,32 +4710,57 @@ async function writeSkillFolder(entry, bundle, force = false, forceRetirement =
|
|
|
4454
4710
|
for (const path of retired) if (!earlyRetired.has(path)) await retire(path);
|
|
4455
4711
|
await commit(MANIFEST);
|
|
4456
4712
|
await commit("SKILL.md");
|
|
4713
|
+
await unlink(join(root, PENDING));
|
|
4457
4714
|
await prune(root, retired);
|
|
4458
4715
|
} catch (error) {
|
|
4459
|
-
for (const path of [...changed].reverse())
|
|
4716
|
+
for (const path of [...changed].reverse()) {
|
|
4717
|
+
if (path === PENDING) continue;
|
|
4718
|
+
if ((await info(join(root, path)))?.isFile()) await unlink(join(root, path));
|
|
4719
|
+
}
|
|
4460
4720
|
for (const dir of [...createdDirectories].reverse()) await rmdir(dir).catch(() => {});
|
|
4461
4721
|
for (const dir of removedDirectories.reverse()) await mkdir(dir, { recursive: true });
|
|
4462
4722
|
for (const path of changed) {
|
|
4723
|
+
if (path === PENDING) continue;
|
|
4463
4724
|
const bytes = backups.get(path);
|
|
4464
4725
|
if (bytes !== null && bytes !== void 0) {
|
|
4465
4726
|
await mkdir(dirname(join(root, path)), { recursive: true });
|
|
4466
4727
|
await writeFile(join(root, path), bytes);
|
|
4467
4728
|
}
|
|
4468
4729
|
}
|
|
4730
|
+
if (changed.has(PENDING)) {
|
|
4731
|
+
const previousIntent = backups.get(PENDING);
|
|
4732
|
+
if (previousIntent) await writeFile(join(root, PENDING), previousIntent);
|
|
4733
|
+
else await unlink(join(root, PENDING));
|
|
4734
|
+
}
|
|
4469
4735
|
throw error;
|
|
4470
4736
|
} finally {
|
|
4471
|
-
for (const
|
|
4737
|
+
for (const dir of stagingDirectories) await rm(dir, {
|
|
4738
|
+
recursive: true,
|
|
4739
|
+
force: true
|
|
4740
|
+
});
|
|
4472
4741
|
for (const dir of [...createdDirectories].reverse()) await rmdir(dir).catch(() => {});
|
|
4473
4742
|
}
|
|
4474
4743
|
}
|
|
4475
|
-
async function removeSkillFolder(entry) {
|
|
4476
|
-
const { root, previous } = await preflightFolder(entry);
|
|
4477
|
-
for (const path of [
|
|
4744
|
+
async function removeSkillFolder(entry, retainRoot = false, bundle) {
|
|
4745
|
+
const { root, previous } = await preflightFolder(entry, bundle, false, false, true);
|
|
4746
|
+
for (const path of [
|
|
4747
|
+
...Object.keys(previous),
|
|
4748
|
+
MANIFEST,
|
|
4749
|
+
PENDING
|
|
4750
|
+
]) await unlink(join(root, path)).catch((error) => {
|
|
4478
4751
|
if (error.code !== "ENOENT") throw error;
|
|
4479
4752
|
});
|
|
4480
4753
|
await prune(root, Object.keys(previous));
|
|
4481
|
-
|
|
4482
|
-
|
|
4754
|
+
let path = dirname(entry);
|
|
4755
|
+
while (path !== dirname(path)) {
|
|
4756
|
+
if ((await info(path))?.isSymbolicLink()) retainRoot = true;
|
|
4757
|
+
if (path === dirname(dirname(dirname(entry)))) break;
|
|
4758
|
+
path = dirname(path);
|
|
4759
|
+
}
|
|
4760
|
+
if (!retainRoot) {
|
|
4761
|
+
await rmdir(root).catch(() => {});
|
|
4762
|
+
await rmdir(dirname(root)).catch(() => {});
|
|
4763
|
+
}
|
|
4483
4764
|
}
|
|
4484
4765
|
//#endregion
|
|
4485
4766
|
//#region src/command-runners/skills.ts
|
|
@@ -4509,6 +4790,57 @@ function scopeTargetConfig(tool, _scope) {
|
|
|
4509
4790
|
pruneDirs: ["artifactshare", "skills"]
|
|
4510
4791
|
};
|
|
4511
4792
|
}
|
|
4793
|
+
function aliases(target) {
|
|
4794
|
+
return "aliases" in target && target.aliases || [{
|
|
4795
|
+
tool: target.tool,
|
|
4796
|
+
scope: target.scope,
|
|
4797
|
+
path: target.path,
|
|
4798
|
+
folder_path: target.path === null ? null : dirname(target.path)
|
|
4799
|
+
}];
|
|
4800
|
+
}
|
|
4801
|
+
function identity(target) {
|
|
4802
|
+
return {
|
|
4803
|
+
aliases: aliases(target),
|
|
4804
|
+
resolved_folder_path: "resolved_folder_path" in target ? target.resolved_folder_path ?? null : null
|
|
4805
|
+
};
|
|
4806
|
+
}
|
|
4807
|
+
function targetOrder(a, b) {
|
|
4808
|
+
return SKILL_TOOLS.indexOf(a.tool) - SKILL_TOOLS.indexOf(b.tool) || (a.scope === b.scope ? 0 : a.scope === "project" ? -1 : 1);
|
|
4809
|
+
}
|
|
4810
|
+
async function cleanupTarget(target, bundled) {
|
|
4811
|
+
if (target.cleaned) return;
|
|
4812
|
+
await cleanupSkillFolder(target.absolutePath, bundled);
|
|
4813
|
+
target.cleaned = true;
|
|
4814
|
+
}
|
|
4815
|
+
async function groupTargets(targets) {
|
|
4816
|
+
const groups = /* @__PURE__ */ new Map();
|
|
4817
|
+
const result = [];
|
|
4818
|
+
for (const target of [...targets].sort((a, b) => targetOrder(aliases(a)[0], aliases(b)[0]))) {
|
|
4819
|
+
if (!availableTarget(target)) {
|
|
4820
|
+
result.push(target);
|
|
4821
|
+
continue;
|
|
4822
|
+
}
|
|
4823
|
+
const key = await resolveSkillFolder(target.absolutePath).catch(() => null);
|
|
4824
|
+
target.resolved_folder_path = key;
|
|
4825
|
+
const existing = key === null ? void 0 : groups.get(key);
|
|
4826
|
+
if (existing && availableTarget(existing)) existing.aliases = [...aliases(existing), ...aliases(target)];
|
|
4827
|
+
else {
|
|
4828
|
+
target.aliases = aliases(target);
|
|
4829
|
+
result.push(target);
|
|
4830
|
+
if (key !== null) groups.set(key, target);
|
|
4831
|
+
}
|
|
4832
|
+
}
|
|
4833
|
+
return result;
|
|
4834
|
+
}
|
|
4835
|
+
async function conflictFor(target, removing = false) {
|
|
4836
|
+
const error = skillUpdateConflictError(target.path);
|
|
4837
|
+
try {
|
|
4838
|
+
await preflightFolder(target.absolutePath, await loadBundledSkills(), false, false, removing);
|
|
4839
|
+
} catch (cause) {
|
|
4840
|
+
error.hint = cause.message;
|
|
4841
|
+
}
|
|
4842
|
+
return error;
|
|
4843
|
+
}
|
|
4512
4844
|
const CLAUDE_CONFIG_HINT = "Set CLAUDE_CONFIG_DIR to a non-empty path or unset it to use ~/.claude.";
|
|
4513
4845
|
function claudeUserRoot() {
|
|
4514
4846
|
const value = process.env.CLAUDE_CONFIG_DIR;
|
|
@@ -4529,6 +4861,7 @@ function availableTarget(target) {
|
|
|
4529
4861
|
}
|
|
4530
4862
|
function unavailableState(target) {
|
|
4531
4863
|
return {
|
|
4864
|
+
...identity(target),
|
|
4532
4865
|
tool: target.tool,
|
|
4533
4866
|
scope: target.scope,
|
|
4534
4867
|
path: null,
|
|
@@ -4592,8 +4925,12 @@ function readTarget(target) {
|
|
|
4592
4925
|
function loadBundledSkills() {
|
|
4593
4926
|
return loadSkillBundle(fileURLToPath(new URL("../skills/artifactshare/", import.meta.url)));
|
|
4594
4927
|
}
|
|
4928
|
+
function cursorProjectAlias(target) {
|
|
4929
|
+
return aliases(target).find((alias) => alias.tool === "cursor" && alias.scope === "project");
|
|
4930
|
+
}
|
|
4595
4931
|
async function legacyRule(target) {
|
|
4596
|
-
|
|
4932
|
+
const cursor = cursorProjectAlias(target);
|
|
4933
|
+
if (!cursor) return void 0;
|
|
4597
4934
|
const path = join(".cursor", "rules", "artifactshare.mdc");
|
|
4598
4935
|
const info = await lstat(path).catch(() => null);
|
|
4599
4936
|
const parent = await lstat(dirname(path)).catch(() => null);
|
|
@@ -4604,7 +4941,7 @@ async function legacyRule(target) {
|
|
|
4604
4941
|
path,
|
|
4605
4942
|
present,
|
|
4606
4943
|
managed,
|
|
4607
|
-
coexistence: present && await lstat(
|
|
4944
|
+
coexistence: present && await lstat(resolve(cursor.path)).catch(() => null) !== null,
|
|
4608
4945
|
hint: present && !managed ? "Inspect the legacy Cursor rule and manually remove it if the skill folder replaces it." : null
|
|
4609
4946
|
};
|
|
4610
4947
|
}
|
|
@@ -4614,11 +4951,24 @@ async function legacyManagedVersion(target) {
|
|
|
4614
4951
|
const state = managedState(await readFile(legacy.path, "utf8"));
|
|
4615
4952
|
return state.kind === "managed" ? state.version : void 0;
|
|
4616
4953
|
}
|
|
4954
|
+
function isNewer(state, bundle) {
|
|
4955
|
+
return state.kind === "managed" && state.version > bundle.version;
|
|
4956
|
+
}
|
|
4957
|
+
function newerCliHint(installed, bundled) {
|
|
4958
|
+
return `A newer CLI installed skill version ${installed}; this CLI bundles version ${bundled}. Keeping the installed version. Use --force only for an intentional downgrade.`;
|
|
4959
|
+
}
|
|
4960
|
+
function downgradeHint(installed, bundled) {
|
|
4961
|
+
return `Intentional downgrade from skill version ${installed} to bundled version ${bundled}.`;
|
|
4962
|
+
}
|
|
4617
4963
|
async function diagnostic(target, bundle) {
|
|
4964
|
+
const legacy = await legacyRule(target);
|
|
4965
|
+
const state = await readTarget(target);
|
|
4966
|
+
const details = await folderDiagnostics(target.absolutePath, bundle, legacy?.managed);
|
|
4618
4967
|
return {
|
|
4619
|
-
...
|
|
4968
|
+
...details,
|
|
4620
4969
|
folder_path: dirname(target.path),
|
|
4621
|
-
...
|
|
4970
|
+
...isNewer(state, bundle) ? { hint: [details.hint, newerCliHint(state.version, bundle.version)].filter(Boolean).join(" ") } : {},
|
|
4971
|
+
...legacy ? { legacy_rule: legacy } : {}
|
|
4622
4972
|
};
|
|
4623
4973
|
}
|
|
4624
4974
|
async function isCurrent(target, bundle) {
|
|
@@ -4713,9 +5063,11 @@ async function autoTargets(scope) {
|
|
|
4713
5063
|
};
|
|
4714
5064
|
}
|
|
4715
5065
|
function targetPathKey(target) {
|
|
4716
|
-
return
|
|
5066
|
+
return resolveSkillFolder(target.absolutePath).catch(() => target.absolutePath);
|
|
4717
5067
|
}
|
|
4718
5068
|
async function prepareAction(item, dryRun) {
|
|
5069
|
+
if (item.preserve || item.action === "failed") return;
|
|
5070
|
+
if (!dryRun && (item.content || item.action === "unchanged")) await cleanupTarget(item.target, item.content ?? await loadBundledSkills());
|
|
4719
5071
|
if (item.content) {
|
|
4720
5072
|
if (item.automatic) {
|
|
4721
5073
|
const details = await diagnostic(item.target, item.content);
|
|
@@ -4723,7 +5075,7 @@ async function prepareAction(item, dryRun) {
|
|
|
4723
5075
|
}
|
|
4724
5076
|
await preflightFolder(item.target.absolutePath, item.content, item.force, item.forceRetirement);
|
|
4725
5077
|
}
|
|
4726
|
-
if (item.action === "removed") await preflightFolder(item.target.absolutePath);
|
|
5078
|
+
if (item.action === "removed") await preflightFolder(item.target.absolutePath, await loadBundledSkills(), false, false, true);
|
|
4727
5079
|
const legacy = await legacyRule(item.target);
|
|
4728
5080
|
if (legacy?.managed && item.action === "unchanged" && !await isCurrent(item.target, await loadBundledSkills())) {
|
|
4729
5081
|
item.action = "update_recommended";
|
|
@@ -4742,8 +5094,9 @@ async function prepareAction(item, dryRun) {
|
|
|
4742
5094
|
}
|
|
4743
5095
|
}
|
|
4744
5096
|
async function applyAction(item) {
|
|
4745
|
-
if (item.
|
|
4746
|
-
if (item.
|
|
5097
|
+
if (item.preserve || item.action === "failed") return;
|
|
5098
|
+
if (item.content) await writeSkillFolder(item.target.absolutePath, item.content, item.force, item.forceRetirement, false);
|
|
5099
|
+
if (item.action === "removed") await removeSkillFolder(item.target.absolutePath, aliases(item.target).length > 1, await loadBundledSkills());
|
|
4747
5100
|
if (item.legacy?.action === "removed") try {
|
|
4748
5101
|
await unlink(item.legacy.path);
|
|
4749
5102
|
} catch {
|
|
@@ -4757,13 +5110,53 @@ async function applyAction(item) {
|
|
|
4757
5110
|
function skillUpdateCommand(target) {
|
|
4758
5111
|
return `${CLI_INVOCATION} skills update --tool ${target.tool} --scope ${target.scope} --json`;
|
|
4759
5112
|
}
|
|
5113
|
+
async function recoveryRecommendation(target, bundled) {
|
|
5114
|
+
const state = await readTarget(target);
|
|
5115
|
+
const details = await diagnostic(target, bundled);
|
|
5116
|
+
if (await isUnownedFolder(target.absolutePath, details.legacy_rule?.managed)) return {};
|
|
5117
|
+
if (isNewer(state, bundled)) return { hint: details.hint ?? newerCliHint(state.version, bundled.version) };
|
|
5118
|
+
let update_command = skillUpdateCommand(target);
|
|
5119
|
+
try {
|
|
5120
|
+
await preflightFolder(target.absolutePath, bundled);
|
|
5121
|
+
} catch {
|
|
5122
|
+
try {
|
|
5123
|
+
await preflightFolder(target.absolutePath, bundled, false, true);
|
|
5124
|
+
update_command = update_command.replace(" --json", " --force --json");
|
|
5125
|
+
} catch {
|
|
5126
|
+
try {
|
|
5127
|
+
await preflightFolder(target.absolutePath, bundled, true);
|
|
5128
|
+
update_command = `${CLI_INVOCATION} skills install --tool ${target.tool} --scope ${target.scope} --force --json`;
|
|
5129
|
+
} catch (error) {
|
|
5130
|
+
return {
|
|
5131
|
+
hint: error.message,
|
|
5132
|
+
...details.modified_files.length ? { modified_files: details.modified_files } : {}
|
|
5133
|
+
};
|
|
5134
|
+
}
|
|
5135
|
+
}
|
|
5136
|
+
}
|
|
5137
|
+
return {
|
|
5138
|
+
update_command,
|
|
5139
|
+
...details.modified_files.length ? {
|
|
5140
|
+
modified_files: details.modified_files,
|
|
5141
|
+
hint: `Modified skill files: ${details.modified_files.join(", ")}. Preserve your edits before running the recommended command.`
|
|
5142
|
+
} : {}
|
|
5143
|
+
};
|
|
5144
|
+
}
|
|
5145
|
+
async function skipAutomaticTarget(target, state) {
|
|
5146
|
+
if (await legacyManagedVersion(target) !== void 0) return false;
|
|
5147
|
+
if (state.kind === "unmanaged") return true;
|
|
5148
|
+
return state.kind === "missing" && !await lstat(join(dirname(target.absolutePath), ".artifactshare-pending.json")).catch(() => null);
|
|
5149
|
+
}
|
|
4760
5150
|
async function finishActions(command, planned, dryRun, mode) {
|
|
5151
|
+
planned.sort((a, b) => targetOrder(aliases(a.target)[0], aliases(b.target)[0]));
|
|
4761
5152
|
for (const item of planned) try {
|
|
4762
5153
|
await prepareAction(item, dryRun);
|
|
4763
5154
|
} catch (error) {
|
|
4764
5155
|
if (item.fallbackAction) {
|
|
5156
|
+
item.hint = error.message;
|
|
4765
5157
|
item.action = item.fallbackAction;
|
|
4766
5158
|
delete item.content;
|
|
5159
|
+
delete item.legacy;
|
|
4767
5160
|
continue;
|
|
4768
5161
|
}
|
|
4769
5162
|
const conflict = skillUpdateConflictError(item.target.path);
|
|
@@ -4773,14 +5166,14 @@ async function finishActions(command, planned, dryRun, mode) {
|
|
|
4773
5166
|
}
|
|
4774
5167
|
const completed = [...planned];
|
|
4775
5168
|
if (!dryRun) for (const [index, item] of planned.entries()) try {
|
|
4776
|
-
await prepareAction(item, false);
|
|
4777
5169
|
await applyAction(item);
|
|
4778
5170
|
completed[index] = item;
|
|
4779
5171
|
} catch (error) {
|
|
4780
5172
|
if (item.fallbackAction) {
|
|
4781
5173
|
completed[index] = {
|
|
4782
5174
|
target: item.target,
|
|
4783
|
-
action: item.fallbackAction
|
|
5175
|
+
action: item.fallbackAction,
|
|
5176
|
+
hint: error.message
|
|
4784
5177
|
};
|
|
4785
5178
|
continue;
|
|
4786
5179
|
}
|
|
@@ -4789,15 +5182,18 @@ async function finishActions(command, planned, dryRun, mode) {
|
|
|
4789
5182
|
}
|
|
4790
5183
|
return {
|
|
4791
5184
|
dry_run: dryRun,
|
|
4792
|
-
targets: completed.map(({ target, action, legacy }) => ({
|
|
5185
|
+
targets: await Promise.all(completed.map(async ({ target, action, legacy, hint }) => ({
|
|
5186
|
+
...hint ? { hint } : {},
|
|
4793
5187
|
tool: target.tool,
|
|
4794
5188
|
scope: target.scope,
|
|
4795
5189
|
path: target.path,
|
|
5190
|
+
...identity(target),
|
|
4796
5191
|
folder_path: dirname(target.path),
|
|
4797
5192
|
...legacy ? { legacy_rule: legacy } : {},
|
|
4798
5193
|
action,
|
|
4799
|
-
...action === "
|
|
4800
|
-
|
|
5194
|
+
...action === "failed" ? { code: "skill_update_conflict" } : {},
|
|
5195
|
+
...action === "update_recommended" ? await recoveryRecommendation(target, await loadBundledSkills()) : {}
|
|
5196
|
+
})))
|
|
4801
5197
|
};
|
|
4802
5198
|
}
|
|
4803
5199
|
async function runActions(command, planned, dryRun, mode, unavailableTargets = []) {
|
|
@@ -4807,12 +5203,14 @@ async function runActions(command, planned, dryRun, mode, unavailableTargets = [
|
|
|
4807
5203
|
tool: target.tool,
|
|
4808
5204
|
scope: target.scope,
|
|
4809
5205
|
path: null,
|
|
5206
|
+
...identity(target),
|
|
4810
5207
|
folder_path: null,
|
|
4811
5208
|
action: "skipped",
|
|
4812
5209
|
code: target.error.code,
|
|
4813
5210
|
hint: target.error.hint
|
|
4814
5211
|
})));
|
|
4815
5212
|
writeSuccess(command, data, mode);
|
|
5213
|
+
if (data.targets.some((target) => target.action === "failed")) process.exitCode = 1;
|
|
4816
5214
|
}
|
|
4817
5215
|
}
|
|
4818
5216
|
async function bundledOrFailure(command, mode) {
|
|
@@ -4834,12 +5232,26 @@ async function runSkillsInstall(parsed, mode) {
|
|
|
4834
5232
|
const bundled = await bundledOrFailure(command, mode);
|
|
4835
5233
|
if (!bundled) return;
|
|
4836
5234
|
const planned = [];
|
|
4837
|
-
for (const
|
|
4838
|
-
const target = skillTarget(tool, scope);
|
|
5235
|
+
for (const target of await groupTargets(allTargets().filter((candidate) => tools.includes(candidate.tool) && candidate.scope === scope))) {
|
|
4839
5236
|
if (!availableTarget(target)) return writeFailure(command, target.error, mode, 1);
|
|
4840
5237
|
const state = await readTarget(target);
|
|
4841
|
-
if ((state.kind === "unmanaged" || state.kind === "broken") && !force) return writeFailure(command,
|
|
4842
|
-
if (state
|
|
5238
|
+
if ((state.kind === "unmanaged" || state.kind === "broken") && !force) return writeFailure(command, await conflictFor(target), mode, 1);
|
|
5239
|
+
if (isNewer(state, bundled) && !force) {
|
|
5240
|
+
planned.push({
|
|
5241
|
+
target,
|
|
5242
|
+
action: "unchanged",
|
|
5243
|
+
preserve: true,
|
|
5244
|
+
hint: newerCliHint(state.version, bundled.version)
|
|
5245
|
+
});
|
|
5246
|
+
continue;
|
|
5247
|
+
}
|
|
5248
|
+
const details = await diagnostic(target, bundled);
|
|
5249
|
+
if (details.code === "skill_update_conflict") {
|
|
5250
|
+
const conflict = skillUpdateConflictError(target.path);
|
|
5251
|
+
conflict.hint = details.hint ?? conflict.hint;
|
|
5252
|
+
return writeFailure(command, conflict, mode, 1);
|
|
5253
|
+
}
|
|
5254
|
+
if (state.kind === "managed" && details.current && !force) {
|
|
4843
5255
|
planned.push({
|
|
4844
5256
|
target,
|
|
4845
5257
|
action: "unchanged"
|
|
@@ -4850,7 +5262,8 @@ async function runSkillsInstall(parsed, mode) {
|
|
|
4850
5262
|
target,
|
|
4851
5263
|
action: state.kind === "missing" ? "installed" : "updated",
|
|
4852
5264
|
content: bundled,
|
|
4853
|
-
force
|
|
5265
|
+
force,
|
|
5266
|
+
...isNewer(state, bundled) ? { hint: downgradeHint(state.version, bundled.version) } : {}
|
|
4854
5267
|
});
|
|
4855
5268
|
}
|
|
4856
5269
|
await runActions(command, planned, parsed.options.dryRun === true, mode);
|
|
@@ -4875,14 +5288,44 @@ async function ensureSkills(parsed, mode, options = {}) {
|
|
|
4875
5288
|
if (!bundled) return void 0;
|
|
4876
5289
|
const targets = (filters.auto ? await autoTargets(filters.scope) : void 0)?.targets ?? filteredTargets(filters.tools, filters.scope ?? "project");
|
|
4877
5290
|
const planned = [];
|
|
4878
|
-
for (const target of targets) {
|
|
5291
|
+
for (const target of await groupTargets(targets)) {
|
|
4879
5292
|
const state = await readTarget(target);
|
|
5293
|
+
const linkedSkill = state.kind === "unmanaged" && (filters.auto || options.skipBrokenUserSkills) && (await lstat(target.absolutePath).catch(() => null))?.isSymbolicLink();
|
|
5294
|
+
if (linkedSkill && await isUnownedFolder(target.absolutePath, (await legacyRule(target))?.managed)) {
|
|
5295
|
+
if (filters.auto) planned.push({
|
|
5296
|
+
target,
|
|
5297
|
+
action: "skipped_unmanaged"
|
|
5298
|
+
});
|
|
5299
|
+
continue;
|
|
5300
|
+
}
|
|
5301
|
+
const conflicted = state.kind === "broken" || linkedSkill;
|
|
5302
|
+
if (filters.auto && command === "skills ensure" && conflicted) {
|
|
5303
|
+
const details = await diagnostic(target, bundled);
|
|
5304
|
+
if (details.code === "skill_update_conflict") {
|
|
5305
|
+
planned.push({
|
|
5306
|
+
target,
|
|
5307
|
+
action: "failed",
|
|
5308
|
+
hint: details.hint ?? skillUpdateConflictError(target.path).hint
|
|
5309
|
+
});
|
|
5310
|
+
continue;
|
|
5311
|
+
}
|
|
5312
|
+
}
|
|
4880
5313
|
if (state.kind === "unmanaged" || state.kind === "broken") {
|
|
4881
|
-
if (options.skipBrokenUserSkills &&
|
|
4882
|
-
|
|
5314
|
+
if (options.skipBrokenUserSkills && conflicted) {
|
|
5315
|
+
const details = await diagnostic(target, bundled);
|
|
5316
|
+
if (details.hint) planned.push({
|
|
5317
|
+
target,
|
|
5318
|
+
action: "update_recommended",
|
|
5319
|
+
hint: details.hint,
|
|
5320
|
+
fallbackAction: "update_recommended"
|
|
5321
|
+
});
|
|
5322
|
+
continue;
|
|
5323
|
+
}
|
|
5324
|
+
writeFailure(command, await conflictFor(target), mode, 1);
|
|
4883
5325
|
return;
|
|
4884
5326
|
}
|
|
4885
5327
|
const automaticUpdate = filters.auto || options.command === "init" || options.command === "open";
|
|
5328
|
+
if (automaticUpdate && state.kind === "missing" && state.hint) continue;
|
|
4886
5329
|
if (automaticUpdate && state.kind === "managed" && state.version > bundled.version) continue;
|
|
4887
5330
|
const details = await diagnostic(target, bundled);
|
|
4888
5331
|
if (automaticUpdate && state.kind === "managed" && details.modified_files.length) {
|
|
@@ -4892,10 +5335,11 @@ async function ensureSkills(parsed, mode, options = {}) {
|
|
|
4892
5335
|
});
|
|
4893
5336
|
continue;
|
|
4894
5337
|
}
|
|
4895
|
-
const unchanged = state.kind === "managed" && (state.version >= bundled.version && automaticUpdate || state.version > bundled.version || details.current);
|
|
5338
|
+
const unchanged = state.kind === "managed" && (state.version >= bundled.version && !details.interrupted_update && automaticUpdate || state.version > bundled.version || details.current);
|
|
4896
5339
|
planned.push(unchanged ? {
|
|
4897
5340
|
target,
|
|
4898
|
-
action: "unchanged"
|
|
5341
|
+
action: "unchanged",
|
|
5342
|
+
...automaticUpdate ? { fallbackAction: "update_recommended" } : {}
|
|
4899
5343
|
} : {
|
|
4900
5344
|
target,
|
|
4901
5345
|
action: state.kind === "missing" ? "installed" : "updated",
|
|
@@ -4906,10 +5350,33 @@ async function ensureSkills(parsed, mode, options = {}) {
|
|
|
4906
5350
|
}
|
|
4907
5351
|
if (options.autoUpdateUserManaged || filters.auto) {
|
|
4908
5352
|
const plannedPaths = new Set(await Promise.all(planned.map((action) => targetPathKey(action.target))));
|
|
4909
|
-
for (const target of await automaticTargets(bundled)) {
|
|
4910
|
-
if (plannedPaths.has(await targetPathKey(target)))
|
|
5353
|
+
for (const target of await groupTargets(await automaticTargets(bundled))) {
|
|
5354
|
+
if (plannedPaths.has(await targetPathKey(target))) {
|
|
5355
|
+
const existing = planned.find((item) => target.resolved_folder_path !== null ? item.target.resolved_folder_path === target.resolved_folder_path : item.target.absolutePath === target.absolutePath);
|
|
5356
|
+
if (existing) {
|
|
5357
|
+
existing.target.aliases = [...aliases(existing.target), ...aliases(target).filter((alias) => !aliases(existing.target).some((old) => old.tool === alias.tool && old.scope === alias.scope))].sort(targetOrder);
|
|
5358
|
+
const primary = existing.target.aliases[0];
|
|
5359
|
+
existing.target.tool = primary.tool;
|
|
5360
|
+
existing.target.scope = primary.scope;
|
|
5361
|
+
existing.target.path = primary.path;
|
|
5362
|
+
existing.target.absolutePath = resolve(primary.path);
|
|
5363
|
+
}
|
|
5364
|
+
continue;
|
|
5365
|
+
}
|
|
4911
5366
|
const state = await readTarget(target);
|
|
5367
|
+
if (await skipAutomaticTarget(target, state)) continue;
|
|
4912
5368
|
if (state.kind === "managed" && state.version > bundled.version) continue;
|
|
5369
|
+
if (parsed.options.dryRun !== true) try {
|
|
5370
|
+
await cleanupTarget(target, bundled);
|
|
5371
|
+
} catch (error) {
|
|
5372
|
+
planned.push({
|
|
5373
|
+
target,
|
|
5374
|
+
action: "update_recommended",
|
|
5375
|
+
hint: error.message,
|
|
5376
|
+
fallbackAction: "update_recommended"
|
|
5377
|
+
});
|
|
5378
|
+
continue;
|
|
5379
|
+
}
|
|
4913
5380
|
const details = await diagnostic(target, bundled);
|
|
4914
5381
|
if (state.kind === "managed" && details.modified_files.length) {
|
|
4915
5382
|
planned.push({
|
|
@@ -4919,11 +5386,11 @@ async function ensureSkills(parsed, mode, options = {}) {
|
|
|
4919
5386
|
});
|
|
4920
5387
|
continue;
|
|
4921
5388
|
}
|
|
4922
|
-
if (target.
|
|
5389
|
+
if (!cursorProjectAlias(target) && (state.kind !== "managed" && !(state.kind === "missing" && details.interrupted_update) || state.kind === "managed" && state.version >= bundled.version && !details.interrupted_update || await isCurrent(target, bundled))) continue;
|
|
4923
5390
|
planned.push({
|
|
4924
5391
|
target,
|
|
4925
|
-
action: state.kind === "managed" && state.version >= bundled.version ? "unchanged" : "updated",
|
|
4926
|
-
...state.kind === "managed" && state.version >= bundled.version ? {} : { content: bundled },
|
|
5392
|
+
action: state.kind === "managed" && state.version >= bundled.version && !details.interrupted_update ? "unchanged" : "updated",
|
|
5393
|
+
...state.kind === "managed" && state.version >= bundled.version && !details.interrupted_update ? {} : { content: bundled },
|
|
4927
5394
|
automatic: true,
|
|
4928
5395
|
fallbackAction: "update_recommended"
|
|
4929
5396
|
});
|
|
@@ -4944,10 +5411,32 @@ async function autoUpdateUserManagedSkills() {
|
|
|
4944
5411
|
try {
|
|
4945
5412
|
const bundled = await loadBundledSkills();
|
|
4946
5413
|
const planned = [];
|
|
4947
|
-
for (const target of await automaticTargets(bundled)) {
|
|
5414
|
+
for (const target of await groupTargets(await automaticTargets(bundled))) {
|
|
4948
5415
|
const state = await readTarget(target);
|
|
5416
|
+
if (await skipAutomaticTarget(target, state)) continue;
|
|
4949
5417
|
if (state.kind === "managed" && state.version > bundled.version) continue;
|
|
5418
|
+
try {
|
|
5419
|
+
await cleanupTarget(target, bundled);
|
|
5420
|
+
} catch (error) {
|
|
5421
|
+
planned.push({
|
|
5422
|
+
target,
|
|
5423
|
+
action: "update_recommended",
|
|
5424
|
+
hint: error.message,
|
|
5425
|
+
...state.kind === "managed" ? { installedVersion: state.version } : {}
|
|
5426
|
+
});
|
|
5427
|
+
continue;
|
|
5428
|
+
}
|
|
4950
5429
|
const details = await diagnostic(target, bundled);
|
|
5430
|
+
if (details.hint) {
|
|
5431
|
+
planned.push({
|
|
5432
|
+
target,
|
|
5433
|
+
action: "update_recommended",
|
|
5434
|
+
hint: details.hint,
|
|
5435
|
+
fallbackAction: "update_recommended",
|
|
5436
|
+
...state.kind === "managed" ? { installedVersion: state.version } : {}
|
|
5437
|
+
});
|
|
5438
|
+
continue;
|
|
5439
|
+
}
|
|
4951
5440
|
if (state.kind === "managed" && details.modified_files.length) {
|
|
4952
5441
|
planned.push({
|
|
4953
5442
|
target,
|
|
@@ -4956,14 +5445,14 @@ async function autoUpdateUserManagedSkills() {
|
|
|
4956
5445
|
});
|
|
4957
5446
|
continue;
|
|
4958
5447
|
}
|
|
4959
|
-
if (target.
|
|
5448
|
+
if (!cursorProjectAlias(target) && (state.kind !== "managed" && !(state.kind === "missing" && details.interrupted_update) || state.kind === "managed" && state.version >= bundled.version && !details.interrupted_update || await isCurrent(target, bundled))) continue;
|
|
4960
5449
|
planned.push({
|
|
4961
5450
|
target,
|
|
4962
|
-
action: state.kind === "managed" && state.version >= bundled.version ? "unchanged" : "updated",
|
|
4963
|
-
...state.kind === "managed" && state.version >= bundled.version ? {} : { content: bundled },
|
|
5451
|
+
action: state.kind === "managed" && state.version >= bundled.version && !details.interrupted_update ? "unchanged" : "updated",
|
|
5452
|
+
...state.kind === "managed" && state.version >= bundled.version && !details.interrupted_update ? {} : { content: bundled },
|
|
4964
5453
|
automatic: true,
|
|
4965
5454
|
fallbackAction: "update_recommended",
|
|
4966
|
-
installedVersion: state.kind === "managed" ? state.version : await legacyManagedVersion(target) ??
|
|
5455
|
+
installedVersion: state.kind === "managed" ? state.version : await legacyManagedVersion(target) ?? null
|
|
4967
5456
|
});
|
|
4968
5457
|
}
|
|
4969
5458
|
if (planned.length === 0) return void 0;
|
|
@@ -4972,37 +5461,43 @@ async function autoUpdateUserManagedSkills() {
|
|
|
4972
5461
|
await prepareAction(item, false);
|
|
4973
5462
|
await applyAction(item);
|
|
4974
5463
|
completed[index] = item;
|
|
4975
|
-
} catch {
|
|
5464
|
+
} catch (error) {
|
|
4976
5465
|
completed[index] = {
|
|
5466
|
+
hint: error.message,
|
|
4977
5467
|
target: item.target,
|
|
4978
5468
|
action: "update_recommended",
|
|
4979
5469
|
...item.installedVersion !== void 0 ? { installedVersion: item.installedVersion } : {}
|
|
4980
5470
|
};
|
|
4981
5471
|
}
|
|
4982
|
-
return { targets: completed.map(({ target, action, installedVersion, legacy }) => ({
|
|
5472
|
+
return { targets: await Promise.all(completed.map(async ({ target, action, installedVersion, legacy, hint }) => ({
|
|
5473
|
+
...hint ? { hint } : {},
|
|
4983
5474
|
tool: target.tool,
|
|
4984
5475
|
scope: target.scope,
|
|
4985
5476
|
path: target.path,
|
|
5477
|
+
...identity(target),
|
|
4986
5478
|
folder_path: dirname(target.path),
|
|
4987
5479
|
...legacy ? { legacy_rule: legacy } : {},
|
|
4988
5480
|
action: action === "update_recommended" ? "update_recommended" : "updated",
|
|
4989
|
-
installed_version: installedVersion ?? bundled.version,
|
|
5481
|
+
installed_version: action === "update_recommended" ? installedVersion ?? null : installedVersion ?? bundled.version,
|
|
4990
5482
|
bundled_version: bundled.version,
|
|
4991
|
-
...action === "update_recommended" ?
|
|
4992
|
-
})) };
|
|
5483
|
+
...action === "update_recommended" ? await recoveryRecommendation(target, bundled) : {}
|
|
5484
|
+
}))) };
|
|
4993
5485
|
} catch {
|
|
4994
5486
|
return;
|
|
4995
5487
|
}
|
|
4996
5488
|
}
|
|
4997
5489
|
async function runSkillsEnsure(parsed, mode) {
|
|
4998
5490
|
const data = await ensureSkills(parsed, mode);
|
|
4999
|
-
if (data)
|
|
5491
|
+
if (data) {
|
|
5492
|
+
writeSuccess("skills ensure", data, mode);
|
|
5493
|
+
if (data.targets.some((target) => target.action === "failed")) process.exitCode = 1;
|
|
5494
|
+
}
|
|
5000
5495
|
}
|
|
5001
5496
|
async function runSkillsList(parsed, mode) {
|
|
5002
5497
|
const bundled = await bundledOrFailure("skills list", mode);
|
|
5003
5498
|
if (!bundled) return;
|
|
5004
5499
|
const targets = [];
|
|
5005
|
-
for (const target of allTargets()) {
|
|
5500
|
+
for (const target of await groupTargets(allTargets())) {
|
|
5006
5501
|
if (!availableTarget(target)) {
|
|
5007
5502
|
targets.push({
|
|
5008
5503
|
...unavailableState(target),
|
|
@@ -5015,12 +5510,13 @@ async function runSkillsList(parsed, mode) {
|
|
|
5015
5510
|
tool: target.tool,
|
|
5016
5511
|
scope: target.scope,
|
|
5017
5512
|
path: target.path,
|
|
5513
|
+
...identity(target),
|
|
5018
5514
|
...await diagnostic(target, bundled),
|
|
5019
|
-
detected: await
|
|
5515
|
+
detected: (await Promise.all(aliases(target).map((alias) => isToolDetected(alias.tool, alias.scope)))).some(Boolean),
|
|
5020
5516
|
installed: state.kind !== "missing",
|
|
5021
5517
|
managed: state.kind === "managed",
|
|
5022
5518
|
installed_version: state.kind === "managed" ? state.version : null,
|
|
5023
|
-
update_available: state.kind === "managed" && state.version
|
|
5519
|
+
update_available: state.kind === "managed" && state.version < bundled.version
|
|
5024
5520
|
});
|
|
5025
5521
|
}
|
|
5026
5522
|
return writeSuccess("skills list", {
|
|
@@ -5031,7 +5527,7 @@ async function runSkillsList(parsed, mode) {
|
|
|
5031
5527
|
async function skillDiagnostics() {
|
|
5032
5528
|
const bundled = await loadBundledSkills();
|
|
5033
5529
|
const targets = [];
|
|
5034
|
-
for (const target of allTargets()) {
|
|
5530
|
+
for (const target of await groupTargets(allTargets())) {
|
|
5035
5531
|
if (!availableTarget(target)) {
|
|
5036
5532
|
targets.push({
|
|
5037
5533
|
...unavailableState(target),
|
|
@@ -5041,13 +5537,9 @@ async function skillDiagnostics() {
|
|
|
5041
5537
|
}
|
|
5042
5538
|
const state = await readTarget(target);
|
|
5043
5539
|
const details = await diagnostic(target, bundled);
|
|
5044
|
-
const updateAvailable = state.kind === "managed" && state.version
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
await preflightFolder(target.absolutePath, bundled);
|
|
5048
|
-
} catch {
|
|
5049
|
-
recoveryCommand = `${CLI_INVOCATION} skills install --tool ${target.tool} --scope ${target.scope} --force --json`;
|
|
5050
|
-
}
|
|
5540
|
+
const updateAvailable = state.kind === "managed" && state.version < bundled.version;
|
|
5541
|
+
const recommendation = await recoveryRecommendation(target, bundled);
|
|
5542
|
+
const recoveryCommand = recommendation.update_command ?? null;
|
|
5051
5543
|
targets.push({
|
|
5052
5544
|
tool: target.tool,
|
|
5053
5545
|
scope: target.scope,
|
|
@@ -5056,15 +5548,19 @@ async function skillDiagnostics() {
|
|
|
5056
5548
|
managed: state.kind === "managed",
|
|
5057
5549
|
installed_version: state.kind === "managed" ? state.version : null,
|
|
5058
5550
|
update_available: updateAvailable,
|
|
5551
|
+
...identity(target),
|
|
5059
5552
|
...details,
|
|
5060
|
-
|
|
5553
|
+
...!recoveryCommand && recommendation.hint ? { hint: recommendation.hint } : {},
|
|
5554
|
+
update_command: details.hint ? null : updateAvailable || details.interrupted_update || state.kind === "managed" && !details.current ? recoveryCommand : null
|
|
5061
5555
|
});
|
|
5062
5556
|
}
|
|
5063
5557
|
const updateTargets = targets.filter((target) => target.update_command !== null);
|
|
5558
|
+
const commonCommand = updateTargets[0]?.update_command?.replace(/ --tool \S+ --scope \S+/, "");
|
|
5559
|
+
const canUpdateTogether = commonCommand?.includes(" skills update ") && updateTargets.every((target) => target.update_command?.replace(/ --tool \S+ --scope \S+/, "") === commonCommand) && !targets.some((target) => target.path !== null && (target.installed || "interrupted_update" in target && target.interrupted_update) && target.hint);
|
|
5064
5560
|
return {
|
|
5065
5561
|
bundled_version: bundled.version,
|
|
5066
5562
|
update_available: targets.some((target) => target.update_available),
|
|
5067
|
-
update_command: updateTargets.length
|
|
5563
|
+
update_command: updateTargets.length === 0 ? null : canUpdateTogether && (updateTargets.length > 1 || !commonCommand?.includes(" --force")) ? commonCommand : updateTargets.map((target) => target.update_command).join(" && "),
|
|
5068
5564
|
targets
|
|
5069
5565
|
};
|
|
5070
5566
|
}
|
|
@@ -5078,18 +5574,48 @@ async function runSkillsUpdate(parsed, mode) {
|
|
|
5078
5574
|
const bundled = await bundledOrFailure(command, mode);
|
|
5079
5575
|
if (!bundled) return;
|
|
5080
5576
|
const planned = [];
|
|
5081
|
-
for (const target of filteredTargets(filters.tools, filters.scope)) {
|
|
5577
|
+
for (const target of await groupTargets(filteredTargets(filters.tools, filters.scope))) {
|
|
5082
5578
|
const state = await readTarget(target);
|
|
5083
|
-
|
|
5084
|
-
if (
|
|
5085
|
-
target
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
|
|
5091
|
-
|
|
5092
|
-
|
|
5579
|
+
const details = await diagnostic(target, bundled);
|
|
5580
|
+
if (details.code === "skill_update_conflict") {
|
|
5581
|
+
const conflict = skillUpdateConflictError(target.path);
|
|
5582
|
+
conflict.hint = details.hint ?? conflict.hint;
|
|
5583
|
+
if (filters.tools.length) return writeFailure(command, conflict, mode, 1);
|
|
5584
|
+
planned.push({
|
|
5585
|
+
target,
|
|
5586
|
+
action: "failed",
|
|
5587
|
+
hint: conflict.hint
|
|
5588
|
+
});
|
|
5589
|
+
continue;
|
|
5590
|
+
}
|
|
5591
|
+
if (state.kind === "broken") return writeFailure(command, await conflictFor(target), mode, 1);
|
|
5592
|
+
if (isNewer(state, bundled) && !force) {
|
|
5593
|
+
planned.push({
|
|
5594
|
+
target,
|
|
5595
|
+
action: "unchanged",
|
|
5596
|
+
preserve: true,
|
|
5597
|
+
hint: newerCliHint(state.version, bundled.version)
|
|
5598
|
+
});
|
|
5599
|
+
continue;
|
|
5600
|
+
}
|
|
5601
|
+
if (state.kind === "missing") {
|
|
5602
|
+
if (state.hint) {
|
|
5603
|
+
planned.push({
|
|
5604
|
+
target,
|
|
5605
|
+
action: "not_installed",
|
|
5606
|
+
hint: state.hint
|
|
5607
|
+
});
|
|
5608
|
+
continue;
|
|
5609
|
+
}
|
|
5610
|
+
planned.push((await legacyRule(target))?.managed || (await diagnostic(target, bundled)).interrupted_update ? {
|
|
5611
|
+
target,
|
|
5612
|
+
action: "installed",
|
|
5613
|
+
content: bundled
|
|
5614
|
+
} : {
|
|
5615
|
+
target,
|
|
5616
|
+
action: "not_installed"
|
|
5617
|
+
});
|
|
5618
|
+
} else if (state.kind === "unmanaged") planned.push({
|
|
5093
5619
|
target,
|
|
5094
5620
|
action: "skipped_unmanaged"
|
|
5095
5621
|
});
|
|
@@ -5097,13 +5623,15 @@ async function runSkillsUpdate(parsed, mode) {
|
|
|
5097
5623
|
target,
|
|
5098
5624
|
action: "updated",
|
|
5099
5625
|
content: bundled,
|
|
5100
|
-
forceRetirement: force
|
|
5626
|
+
forceRetirement: force,
|
|
5627
|
+
...isNewer(state, bundled) ? { hint: downgradeHint(state.version, bundled.version) } : {}
|
|
5101
5628
|
});
|
|
5102
5629
|
else planned.push({
|
|
5103
5630
|
target,
|
|
5104
5631
|
action: "unchanged"
|
|
5105
5632
|
});
|
|
5106
5633
|
}
|
|
5634
|
+
if (!filters.tools.length) for (const item of planned) item.fallbackAction = "failed";
|
|
5107
5635
|
await runActions(command, planned, parsed.options.dryRun === true, mode, unavailableActionTargets(filters.tools, filters.scope));
|
|
5108
5636
|
}
|
|
5109
5637
|
async function runSkillsRemove(parsed, mode) {
|
|
@@ -5113,17 +5641,38 @@ async function runSkillsRemove(parsed, mode) {
|
|
|
5113
5641
|
const unavailable = unavailableSelection(filters.tools, filters.scope);
|
|
5114
5642
|
if (unavailable) return writeFailure(command, unavailable, mode, 1);
|
|
5115
5643
|
const planned = [];
|
|
5116
|
-
for (const target of filteredTargets(filters.tools, filters.scope)) {
|
|
5644
|
+
for (const target of await groupTargets(filteredTargets(filters.tools, filters.scope))) {
|
|
5117
5645
|
const state = await readTarget(target);
|
|
5118
|
-
|
|
5646
|
+
const details = await diagnostic(target, await loadBundledSkills());
|
|
5647
|
+
if (details.code === "skill_update_conflict") {
|
|
5648
|
+
const conflict = skillUpdateConflictError(target.path);
|
|
5649
|
+
conflict.hint = details.hint ?? conflict.hint;
|
|
5650
|
+
if (filters.tools.length) return writeFailure(command, conflict, mode, 1);
|
|
5651
|
+
planned.push({
|
|
5652
|
+
target,
|
|
5653
|
+
action: "failed",
|
|
5654
|
+
hint: conflict.hint
|
|
5655
|
+
});
|
|
5656
|
+
continue;
|
|
5657
|
+
}
|
|
5658
|
+
if (state.kind === "broken") return writeFailure(command, await conflictFor(target, true), mode, 1);
|
|
5659
|
+
if (state.kind === "missing" && state.hint) {
|
|
5660
|
+
planned.push({
|
|
5661
|
+
target,
|
|
5662
|
+
action: "not_installed",
|
|
5663
|
+
hint: state.hint
|
|
5664
|
+
});
|
|
5665
|
+
continue;
|
|
5666
|
+
}
|
|
5119
5667
|
const managedLegacy = (await legacyRule(target))?.managed === true;
|
|
5120
|
-
const action = state.kind === "missing" ? managedLegacy ? "removed" : "not_installed" : state.kind === "managed" ? "removed" : "skipped_unmanaged";
|
|
5668
|
+
const action = state.kind === "missing" ? managedLegacy || (await diagnostic(target, await loadBundledSkills())).interrupted_update ? "removed" : "not_installed" : state.kind === "managed" ? "removed" : "skipped_unmanaged";
|
|
5121
5669
|
planned.push({
|
|
5122
5670
|
target,
|
|
5123
5671
|
action,
|
|
5124
5672
|
removeLegacy: true
|
|
5125
5673
|
});
|
|
5126
5674
|
}
|
|
5675
|
+
if (!filters.tools.length) for (const item of planned) item.fallbackAction = "failed";
|
|
5127
5676
|
await runActions(command, planned, parsed.options.dryRun === true, mode, unavailableActionTargets(filters.tools, filters.scope));
|
|
5128
5677
|
}
|
|
5129
5678
|
//#endregion
|
|
@@ -16306,7 +16855,7 @@ const skillsInstallDefinition = define({
|
|
|
16306
16855
|
force: {
|
|
16307
16856
|
type: "boolean",
|
|
16308
16857
|
toKebab: true,
|
|
16309
|
-
description: "Take over bundled paths
|
|
16858
|
+
description: "Take over bundled paths or intentionally downgrade; preserve user additions"
|
|
16310
16859
|
}
|
|
16311
16860
|
},
|
|
16312
16861
|
examples: `npm exec --yes --package=@artifactshare/cli -- artifactshare skills install --tool codex --scope project --json
|
|
@@ -16315,6 +16864,7 @@ npm exec --yes --package=@artifactshare/cli -- artifactshare skills install --to
|
|
|
16315
16864
|
Writes SKILL.md and bundled references into skills/artifactshare/ for every tool and scope.
|
|
16316
16865
|
Project Cursor uses .cursor/skills/artifactshare/. A manifest tracks owned files.
|
|
16317
16866
|
Files without the Artifact Share managed marker are never overwritten without --force.
|
|
16867
|
+
Newer installed versions are unchanged with a newer-CLI hint unless --force requests an intentional downgrade; dry runs report the same plan.
|
|
16318
16868
|
|
|
16319
16869
|
Claude Code user skills go to $CLAUDE_CONFIG_DIR/skills when set, otherwise
|
|
16320
16870
|
~/.claude/skills. Relative paths resolve against cwd without tilde expansion.
|
|
@@ -16334,7 +16884,8 @@ const skillsListDefinition = define({
|
|
|
16334
16884
|
examples: `npm exec --yes --package=@artifactshare/cli -- artifactshare skills list --json
|
|
16335
16885
|
|
|
16336
16886
|
Reports each tool and scope with detection, version, completeness, missing/differing files,
|
|
16337
|
-
ownership metadata, and legacy Cursor rule coexistence.
|
|
16887
|
+
ownership metadata, and legacy Cursor rule coexistence. Shared folders appear once with aliases
|
|
16888
|
+
and resolved_folder_path; broken links include repair hints.
|
|
16338
16889
|
Runs locally; no network or authentication is used.`
|
|
16339
16890
|
});
|
|
16340
16891
|
const skillsUpdateDefinition = define({
|
|
@@ -16347,13 +16898,19 @@ const skillsUpdateDefinition = define({
|
|
|
16347
16898
|
force: {
|
|
16348
16899
|
type: "boolean",
|
|
16349
16900
|
toKebab: true,
|
|
16350
|
-
description: "Rewrite managed folder files; never take over an unmanaged entry"
|
|
16901
|
+
description: "Rewrite managed folder files, allowing an explicit downgrade; never take over an unmanaged entry"
|
|
16351
16902
|
}
|
|
16352
16903
|
},
|
|
16353
16904
|
examples: `npm exec --yes --package=@artifactshare/cli -- artifactshare skills update --json
|
|
16354
16905
|
npm exec --yes --package=@artifactshare/cli -- artifactshare skills update --tool codex --scope user --json
|
|
16355
16906
|
|
|
16356
|
-
Updates managed folders
|
|
16907
|
+
Updates managed folders and repairs missing files. Edited owned files require --force; user additions are preserved.
|
|
16908
|
+
Folder and ancestor directory symlinks are resolved. User links outside bundled, owned, pending and reserved CLI paths are ignored and listed in user_links; protected links in managed folders are refused even with --force.
|
|
16909
|
+
Unmanaged folders without ownership records or a managed legacy rule are skipped_unmanaged, including protected-path links; link referents are never read.
|
|
16910
|
+
Newer installed versions are preserved without cleanup unless --force requests an explicit downgrade.
|
|
16911
|
+
Unfiltered update/remove continue other targets on conflict: ok: true stdout includes failed target rows with code and hint; exit status is 1.
|
|
16912
|
+
Shared folders are written once. JSON rows include aliases and resolved_folder_path.
|
|
16913
|
+
Real mutations clean reserved stale staging and UUID temporary files; dry runs do not.
|
|
16357
16914
|
Managed legacy Cursor rules migrate after the new project folder is ready.
|
|
16358
16915
|
|
|
16359
16916
|
Common failures:
|
|
@@ -16406,6 +16963,7 @@ const skillsRemoveDefinition = define({
|
|
|
16406
16963
|
npm exec --yes --package=@artifactshare/cli -- artifactshare skills remove --tool cursor --json
|
|
16407
16964
|
|
|
16408
16965
|
Only manifest-owned files (or a legacy managed SKILL.md) are deleted; user files are preserved.
|
|
16966
|
+
Unmanaged folders are skipped_unmanaged, including protected-path links when no ownership records or managed legacy rule exist.
|
|
16409
16967
|
Project Cursor removal also cleans managed legacy rules.`
|
|
16410
16968
|
});
|
|
16411
16969
|
const skillsDefinition = define({
|