@artifactshare/cli 0.19.2 → 0.20.1
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 +15 -0
- package/README.md +36 -24
- package/dist/cli.js +957 -128
- package/package.json +1 -1
- package/skills/artifactshare/SKILL.md +86 -610
- package/skills/artifactshare/references/authentication-profiles-skills.md +76 -0
- package/skills/artifactshare/references/comments.md +64 -0
- package/skills/artifactshare/references/local-write-recovery.md +35 -0
- package/skills/artifactshare/references/organize-settings.md +109 -0
- package/skills/artifactshare/references/preview.md +155 -0
- package/skills/artifactshare/references/rest-api-only.md +76 -0
- package/skills/artifactshare/references/static-sites.md +39 -0
- package/skills/artifactshare/references/upload-path-safety.md +18 -0
- package/skills/artifactshare/references/version-labels.md +30 -0
- package/skills/artifactshare/artifactshare.mdc +0 -352
package/dist/cli.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { C as defaultPreviewNotificationRegistration, D as isPreviewAnchor, O as isPreviewAnnotation, S as createPreviewNotificationCoordinator, T as PREVIEW_MUTATION_HEADER, _ as resolveLiveSession, a as annotationsFilePath, b as updateSessionNotificationRegistration, c as isSessionId, d as previewsDir, f as probeSession, g as removeSessionFile, h as releaseStaleClaim, i as cursorNotificationRegistration, k as isPreviewDoneItemInput, l as previewIdentityPath, m as readSessionFile, n as CURSOR_ACP_NOTIFICATION_TIMEOUT_MS, o as claimSessionStart, p as processAlive, r as createCursorAcpAdapter, s as isConnectionRefused, u as previewRealpath, v as sessionIdForPath, w as samePreviewNotificationRegistration, x as writeSessionFile, y as tokenFingerprint } from "./cursor-notification-Hz6fuACK.js";
|
|
2
2
|
import { chmodSync, constants, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, statSync, watch, writeFileSync } from "node:fs";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
3
4
|
import { cli, define, lazy } from "gunshi";
|
|
4
5
|
import { generate } from "gunshi/generator";
|
|
5
6
|
import { z } from "zod";
|
|
6
7
|
import { execFile, spawn } from "node:child_process";
|
|
7
8
|
import * as fs from "node:fs/promises";
|
|
8
|
-
import { chmod, lstat, mkdir, readFile, realpath, rm, rmdir, stat, writeFile } from "node:fs/promises";
|
|
9
|
+
import { chmod, lstat, mkdir, readFile, readdir, realpath, rename, rm, rmdir, stat, unlink, writeFile } from "node:fs/promises";
|
|
9
10
|
import { arch, homedir, platform } from "node:os";
|
|
10
11
|
import path, { basename, dirname, extname, join, relative, resolve, sep } from "node:path";
|
|
11
12
|
import { createHash, randomUUID } from "node:crypto";
|
|
@@ -708,6 +709,105 @@ const PROJECT_EDIT_RESPONSE_SCHEMA = ProjectEditResponseSchema;
|
|
|
708
709
|
const CLI_EDIT_RESPONSE_SCHEMA = CliEditResponseSchema;
|
|
709
710
|
const CLI_MOVE_RESPONSE_SCHEMA = CliMoveResponseSchema;
|
|
710
711
|
const RESOLVE_RESPONSE_SCHEMA = ResolveResponseSchema;
|
|
712
|
+
const SkillLegacyDiagnosticSchema = z.object({
|
|
713
|
+
path: z.string(),
|
|
714
|
+
present: z.boolean(),
|
|
715
|
+
managed: z.boolean(),
|
|
716
|
+
coexistence: z.boolean(),
|
|
717
|
+
hint: z.string().nullable()
|
|
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
|
+
};
|
|
728
|
+
const LocalSkillTargetSchema = z.object({
|
|
729
|
+
...SkillTargetIdentityShape,
|
|
730
|
+
folder_path: z.string().nullable(),
|
|
731
|
+
complete: z.boolean(),
|
|
732
|
+
current: z.boolean(),
|
|
733
|
+
older_version: z.boolean(),
|
|
734
|
+
missing_files: z.array(z.string()),
|
|
735
|
+
different_files: z.array(z.string()),
|
|
736
|
+
modified_files: z.array(z.string()),
|
|
737
|
+
interrupted_update: z.boolean().optional(),
|
|
738
|
+
ownership_manifest: z.enum([
|
|
739
|
+
"valid",
|
|
740
|
+
"absent",
|
|
741
|
+
"invalid"
|
|
742
|
+
]),
|
|
743
|
+
legacy_rule: SkillLegacyDiagnosticSchema.optional()
|
|
744
|
+
}).extend({
|
|
745
|
+
tool: z.string(),
|
|
746
|
+
scope: z.string(),
|
|
747
|
+
path: z.string().nullable(),
|
|
748
|
+
available: z.boolean().optional(),
|
|
749
|
+
code: z.string().optional(),
|
|
750
|
+
hint: z.string().optional(),
|
|
751
|
+
installed: z.boolean(),
|
|
752
|
+
managed: z.boolean(),
|
|
753
|
+
installed_version: z.number().nullable(),
|
|
754
|
+
update_available: z.boolean()
|
|
755
|
+
});
|
|
756
|
+
z.object({
|
|
757
|
+
bundled_version: z.number(),
|
|
758
|
+
targets: z.array(LocalSkillTargetSchema.extend({ detected: z.boolean() }))
|
|
759
|
+
});
|
|
760
|
+
z.object({
|
|
761
|
+
bundled_version: z.number(),
|
|
762
|
+
update_available: z.boolean(),
|
|
763
|
+
update_command: z.string().nullable(),
|
|
764
|
+
targets: z.array(LocalSkillTargetSchema.extend({ update_command: z.string().nullable() }))
|
|
765
|
+
});
|
|
766
|
+
const SkillLegacyActionSchema = z.object({
|
|
767
|
+
path: z.string(),
|
|
768
|
+
action: z.enum([
|
|
769
|
+
"removed",
|
|
770
|
+
"would_remove",
|
|
771
|
+
"kept_unmanaged",
|
|
772
|
+
"remove_failed"
|
|
773
|
+
]),
|
|
774
|
+
hint: z.string().optional()
|
|
775
|
+
});
|
|
776
|
+
const SkillsActionTargetSchema = z.object({
|
|
777
|
+
...SkillTargetIdentityShape,
|
|
778
|
+
tool: z.string(),
|
|
779
|
+
scope: z.string(),
|
|
780
|
+
path: z.string().nullable(),
|
|
781
|
+
folder_path: z.string().nullable(),
|
|
782
|
+
action: z.enum([
|
|
783
|
+
"installed",
|
|
784
|
+
"updated",
|
|
785
|
+
"update_recommended",
|
|
786
|
+
"unchanged",
|
|
787
|
+
"removed",
|
|
788
|
+
"not_installed",
|
|
789
|
+
"skipped_unmanaged",
|
|
790
|
+
"skipped"
|
|
791
|
+
]),
|
|
792
|
+
update_command: z.string().optional(),
|
|
793
|
+
code: z.string().optional(),
|
|
794
|
+
hint: z.string().optional(),
|
|
795
|
+
legacy_rule: SkillLegacyActionSchema.optional()
|
|
796
|
+
});
|
|
797
|
+
z.object({
|
|
798
|
+
dry_run: z.boolean(),
|
|
799
|
+
targets: z.array(SkillsActionTargetSchema)
|
|
800
|
+
});
|
|
801
|
+
const SkillAutoUpdateTargetSchema = SkillsActionTargetSchema.extend({
|
|
802
|
+
path: z.string(),
|
|
803
|
+
folder_path: z.string(),
|
|
804
|
+
scope: z.enum(["user", "project"]),
|
|
805
|
+
action: z.enum(["updated", "update_recommended"]),
|
|
806
|
+
installed_version: z.number().nullable(),
|
|
807
|
+
bundled_version: z.number()
|
|
808
|
+
});
|
|
809
|
+
const SkillAutoUpdateDataSchema = z.object({ targets: z.array(SkillAutoUpdateTargetSchema) });
|
|
810
|
+
z.object({ skills: z.object({ auto_update: SkillAutoUpdateDataSchema.optional() }).optional() });
|
|
711
811
|
//#endregion
|
|
712
812
|
//#region src/constants.ts
|
|
713
813
|
const DEFAULT_BASE_URL = "https://artifactshare.com";
|
|
@@ -1470,9 +1570,9 @@ function configHomeUnavailableError(profile) {
|
|
|
1470
1570
|
function skillUpdateConflictError(path) {
|
|
1471
1571
|
return cliError({
|
|
1472
1572
|
code: "skill_update_conflict",
|
|
1473
|
-
message: `The
|
|
1474
|
-
why: "Artifact Share
|
|
1475
|
-
hint: "Inspect the
|
|
1573
|
+
message: `The skill folder at ${path} has an ownership or path conflict.`,
|
|
1574
|
+
why: "Artifact Share requires a managed entry, valid ownership metadata, regular owned files, and no unowned path collisions.",
|
|
1575
|
+
hint: "Inspect the skill folder and repair invalid metadata or unsafe paths before reinstalling. Use skills install --tool <tool> --force only to take over bundled paths; user additions are preserved.",
|
|
1476
1576
|
agentRecoverable: false,
|
|
1477
1577
|
requiresHuman: true,
|
|
1478
1578
|
recovery: { kind: "ask_human" },
|
|
@@ -2069,8 +2169,11 @@ function skillAutoUpdateHumanOutput(data) {
|
|
|
2069
2169
|
const autoUpdate = skills.auto_update;
|
|
2070
2170
|
if (!isRecord$1(autoUpdate) || !Array.isArray(autoUpdate.targets)) return "";
|
|
2071
2171
|
const lines = autoUpdate.targets.filter(isRecord$1).map((target) => {
|
|
2072
|
-
const label = typeof target.tool === "string" && typeof target.scope === "string" ? `${target.tool}:${target.scope}` : "unknown";
|
|
2073
|
-
if (target.action === "update_recommended"
|
|
2172
|
+
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";
|
|
2173
|
+
if (target.action === "update_recommended") {
|
|
2174
|
+
const advice = [target.update_command, target.hint].filter((value) => typeof value === "string").join("; ");
|
|
2175
|
+
return `Skill update recommended: ${label}${advice ? ` (${advice})` : ""}`;
|
|
2176
|
+
}
|
|
2074
2177
|
return `Skill updated: ${label}`;
|
|
2075
2178
|
});
|
|
2076
2179
|
return lines.length > 0 ? `${lines.join("\n")}\n` : "";
|
|
@@ -4144,6 +4247,455 @@ async function runArtifactsList(parsed, mode) {
|
|
|
4144
4247
|
return writeSuccess(command, body, mode);
|
|
4145
4248
|
}
|
|
4146
4249
|
//#endregion
|
|
4250
|
+
//#region src/command-runners/skill-folder.ts
|
|
4251
|
+
const MANIFEST = ".artifactshare-managed.json";
|
|
4252
|
+
const PENDING = ".artifactshare-pending.json";
|
|
4253
|
+
function managedState(content) {
|
|
4254
|
+
if (content === null) return { kind: "missing" };
|
|
4255
|
+
if (!content.includes("artifactshare-skill")) return { kind: "unmanaged" };
|
|
4256
|
+
const block = content.match(/<!--\s*artifactshare-skill([\s\S]*?)-->/)?.[1];
|
|
4257
|
+
const version = block?.match(/(?:^|\n)\s*version:\s*(\d+)\s*(?:\n|$)/)?.[1];
|
|
4258
|
+
if (version === void 0 || !/(?:^|\n)\s*managed:\s*true\s*(?:\n|$)/.test(block ?? "") || !Number.isSafeInteger(Number(version))) return { kind: "broken" };
|
|
4259
|
+
return {
|
|
4260
|
+
kind: "managed",
|
|
4261
|
+
version: Number(version)
|
|
4262
|
+
};
|
|
4263
|
+
}
|
|
4264
|
+
const hash = (text) => createHash("sha256").update(text).digest("hex");
|
|
4265
|
+
const validPath = (path) => (path === "SKILL.md" || path.startsWith("references/")) && !/[\\:]/.test(path) && path.split("/").every((part) => part !== "" && part !== "." && part !== "..");
|
|
4266
|
+
async function info(path) {
|
|
4267
|
+
try {
|
|
4268
|
+
return await lstat(path);
|
|
4269
|
+
} catch (error) {
|
|
4270
|
+
if (error.code === "ENOENT") return null;
|
|
4271
|
+
throw error;
|
|
4272
|
+
}
|
|
4273
|
+
}
|
|
4274
|
+
var SkillFolderResolutionError = class extends Error {
|
|
4275
|
+
missingAncestor;
|
|
4276
|
+
constructor(path, missingAncestor = false) {
|
|
4277
|
+
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.`);
|
|
4278
|
+
this.missingAncestor = missingAncestor;
|
|
4279
|
+
}
|
|
4280
|
+
};
|
|
4281
|
+
function resolveSkillFolder(entry) {
|
|
4282
|
+
const resolveDirectory = async (path) => {
|
|
4283
|
+
let item;
|
|
4284
|
+
try {
|
|
4285
|
+
item = await info(path);
|
|
4286
|
+
if (!item) return join(await resolveDirectory(dirname(path)), basename(path));
|
|
4287
|
+
const canonical = await realpath(path);
|
|
4288
|
+
if (!(await lstat(canonical)).isDirectory()) throw new Error("Not a directory");
|
|
4289
|
+
return canonical;
|
|
4290
|
+
} catch (error) {
|
|
4291
|
+
if (error instanceof SkillFolderResolutionError) throw error;
|
|
4292
|
+
throw new SkillFolderResolutionError(path, item?.isSymbolicLink() === true && error.code === "ENOENT");
|
|
4293
|
+
}
|
|
4294
|
+
};
|
|
4295
|
+
return resolveDirectory(dirname(entry));
|
|
4296
|
+
}
|
|
4297
|
+
const rootFor = resolveSkillFolder;
|
|
4298
|
+
const uuid = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
|
4299
|
+
const legacyTemp = new RegExp(`^\\.artifactshare-${uuid}\\.tmp$`, "i");
|
|
4300
|
+
const stagingName = new RegExp(`^\\.artifactshare-staging-${uuid}$`, "i");
|
|
4301
|
+
const stale = (item) => item.mtimeMs < Date.now() - 6e5;
|
|
4302
|
+
async function inspectTree(root, cleanup = false, folderRoot = root) {
|
|
4303
|
+
if (!await info(root)) return;
|
|
4304
|
+
for (const name of await readdir(root)) {
|
|
4305
|
+
const path = join(root, name);
|
|
4306
|
+
const item = await lstat(path);
|
|
4307
|
+
if (item.isSymbolicLink()) throw new Error(`Unsafe skill path (link): ${path}. Preserve edits and replace the internal link with ordinary bundled content, then retry.`);
|
|
4308
|
+
if (item.isDirectory() && root === folderRoot && stagingName.test(name)) {
|
|
4309
|
+
if (cleanup && stale(item)) await rm(path, {
|
|
4310
|
+
recursive: true,
|
|
4311
|
+
force: true
|
|
4312
|
+
});
|
|
4313
|
+
} else if (item.isDirectory()) await inspectTree(path, cleanup, folderRoot);
|
|
4314
|
+
else if (cleanup && item.isFile() && legacyTemp.test(name) && stale(item)) await unlink(path);
|
|
4315
|
+
}
|
|
4316
|
+
}
|
|
4317
|
+
async function cleanupSkillFolder(entry, bundle) {
|
|
4318
|
+
const root = await rootFor(entry);
|
|
4319
|
+
if (bundle) {
|
|
4320
|
+
const pending = await ownership(root, await stateAt(root), PENDING);
|
|
4321
|
+
if (pending.manifest && pending.manifest.version > bundle.version) throw new Error(newerIntentHint(pending.manifest.version));
|
|
4322
|
+
}
|
|
4323
|
+
await inspectTree(root, true);
|
|
4324
|
+
const parent = dirname(root);
|
|
4325
|
+
if (await info(parent)) for (const name of await readdir(parent)) {
|
|
4326
|
+
if (!stagingName.test(name)) continue;
|
|
4327
|
+
const item = await lstat(join(parent, name));
|
|
4328
|
+
if (item.isDirectory() && stale(item)) await rm(join(parent, name), {
|
|
4329
|
+
recursive: true,
|
|
4330
|
+
force: true
|
|
4331
|
+
});
|
|
4332
|
+
}
|
|
4333
|
+
}
|
|
4334
|
+
async function safe(root, relative, retiredAncestors = /* @__PURE__ */ new Set(), replacedDirectories = /* @__PURE__ */ new Set()) {
|
|
4335
|
+
const parts = [
|
|
4336
|
+
dirname(root),
|
|
4337
|
+
root,
|
|
4338
|
+
...relative.split("/").map((_, i, all) => join(root, ...all.slice(0, i + 1)))
|
|
4339
|
+
];
|
|
4340
|
+
for (let i = 0; i < parts.length; i++) {
|
|
4341
|
+
const item = await info(parts[i]);
|
|
4342
|
+
if (i < parts.length - 1 && item?.isFile() && retiredAncestors.has(parts[i])) return;
|
|
4343
|
+
if (i === parts.length - 1 && item?.isDirectory() && replacedDirectories.has(parts[i])) continue;
|
|
4344
|
+
if (item && (item.isSymbolicLink() || (i === parts.length - 1 ? !item.isFile() : !item.isDirectory()))) throw new Error(`Unsafe skill path (type change or link): ${parts[i]}. Preserve edits and replace internal links with ordinary bundled content, then retry.`);
|
|
4345
|
+
}
|
|
4346
|
+
}
|
|
4347
|
+
async function bytesAt(root, path) {
|
|
4348
|
+
await safe(root, path);
|
|
4349
|
+
return await readFile(join(root, path)).catch((error) => {
|
|
4350
|
+
if (error.code === "ENOENT") return null;
|
|
4351
|
+
throw error;
|
|
4352
|
+
});
|
|
4353
|
+
}
|
|
4354
|
+
async function textAt(root, path) {
|
|
4355
|
+
return (await bytesAt(root, path))?.toString("utf8") ?? null;
|
|
4356
|
+
}
|
|
4357
|
+
async function stateAt(root) {
|
|
4358
|
+
try {
|
|
4359
|
+
return managedState(await textAt(root, "SKILL.md"));
|
|
4360
|
+
} catch {
|
|
4361
|
+
return { kind: "broken" };
|
|
4362
|
+
}
|
|
4363
|
+
}
|
|
4364
|
+
async function readSkillState(entry) {
|
|
4365
|
+
try {
|
|
4366
|
+
return await stateAt(await rootFor(entry));
|
|
4367
|
+
} catch (error) {
|
|
4368
|
+
if (error instanceof SkillFolderResolutionError && error.missingAncestor) return {
|
|
4369
|
+
kind: "missing",
|
|
4370
|
+
hint: error.message
|
|
4371
|
+
};
|
|
4372
|
+
return { kind: "broken" };
|
|
4373
|
+
}
|
|
4374
|
+
}
|
|
4375
|
+
async function loadSkillBundle(root) {
|
|
4376
|
+
const files = {};
|
|
4377
|
+
const visit = async (relative) => {
|
|
4378
|
+
const path = join(root, relative);
|
|
4379
|
+
const item = await info(path);
|
|
4380
|
+
if (!item) return;
|
|
4381
|
+
if (item.isDirectory()) for (const name of (await readdir(path)).sort()) await visit(`${relative}/${name}`);
|
|
4382
|
+
else if (item.isFile() && validPath(relative)) files[relative] = await readFile(path, "utf8");
|
|
4383
|
+
else throw new Error(`Invalid bundled skill path: ${relative}`);
|
|
4384
|
+
};
|
|
4385
|
+
await visit("SKILL.md");
|
|
4386
|
+
await visit("references");
|
|
4387
|
+
const state = managedState(files["SKILL.md"] ?? null);
|
|
4388
|
+
if (state.kind !== "managed") throw new Error("The bundled SKILL.md has a missing or invalid managed marker.");
|
|
4389
|
+
if (new Set(Object.keys(files).map((path) => path.toLowerCase())).size !== Object.keys(files).length) throw new Error("Colliding bundled skill paths.");
|
|
4390
|
+
return {
|
|
4391
|
+
files,
|
|
4392
|
+
version: state.version
|
|
4393
|
+
};
|
|
4394
|
+
}
|
|
4395
|
+
async function ownership(root, state, record = MANIFEST, pending) {
|
|
4396
|
+
try {
|
|
4397
|
+
const text = await textAt(root, record);
|
|
4398
|
+
if (text === null) return { status: "absent" };
|
|
4399
|
+
const value = JSON.parse(text);
|
|
4400
|
+
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" };
|
|
4401
|
+
for (const files of [value.files, ...value.previous_files === void 0 ? [] : [value.previous_files]]) {
|
|
4402
|
+
if (!files || typeof files !== "object" || Array.isArray(files)) return { status: "invalid" };
|
|
4403
|
+
const paths = Object.keys(files);
|
|
4404
|
+
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" };
|
|
4405
|
+
}
|
|
4406
|
+
return {
|
|
4407
|
+
status: "valid",
|
|
4408
|
+
manifest: value
|
|
4409
|
+
};
|
|
4410
|
+
} catch {
|
|
4411
|
+
return { status: "invalid" };
|
|
4412
|
+
}
|
|
4413
|
+
}
|
|
4414
|
+
async function recoveryOwnership(root, state) {
|
|
4415
|
+
const pending = await ownership(root, state, PENDING);
|
|
4416
|
+
const owned = await ownership(root, state, MANIFEST, pending.manifest);
|
|
4417
|
+
const recorded = { ...owned.manifest?.files ?? (state.kind === "managed" && pending.status === "absent" ? { "SKILL.md": hash(await bytesAt(root, "SKILL.md")) } : {}) };
|
|
4418
|
+
for (const [path, expected] of Object.entries(pending.manifest?.previous_files ?? {})) {
|
|
4419
|
+
const bytes = await bytesAt(root, path).catch(() => null);
|
|
4420
|
+
if (bytes !== null && hash(bytes) === expected) recorded[path] = expected;
|
|
4421
|
+
}
|
|
4422
|
+
for (const [path, expected] of Object.entries(pending.manifest?.files ?? {})) {
|
|
4423
|
+
const bytes = await bytesAt(root, path).catch(() => null);
|
|
4424
|
+
if (bytes !== null && hash(bytes) === expected) recorded[path] = expected;
|
|
4425
|
+
}
|
|
4426
|
+
for (const [path, expected] of Object.entries(pending.manifest?.files ?? {})) {
|
|
4427
|
+
const bytes = await bytesAt(root, path).catch(() => null);
|
|
4428
|
+
if (bytes !== null && hash(bytes) === expected) {
|
|
4429
|
+
for (const old of Object.keys(recorded)) if (old.startsWith(`${path}/`)) delete recorded[old];
|
|
4430
|
+
}
|
|
4431
|
+
}
|
|
4432
|
+
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];
|
|
4433
|
+
return {
|
|
4434
|
+
owned,
|
|
4435
|
+
pending,
|
|
4436
|
+
recorded
|
|
4437
|
+
};
|
|
4438
|
+
}
|
|
4439
|
+
async function folderDiagnostics(entry, bundle) {
|
|
4440
|
+
let root = null;
|
|
4441
|
+
try {
|
|
4442
|
+
root = await rootFor(entry);
|
|
4443
|
+
await inspectTree(root);
|
|
4444
|
+
} catch (error) {
|
|
4445
|
+
return {
|
|
4446
|
+
folder_path: dirname(entry),
|
|
4447
|
+
resolved_folder_path: root,
|
|
4448
|
+
complete: false,
|
|
4449
|
+
current: false,
|
|
4450
|
+
older_version: false,
|
|
4451
|
+
missing_files: [],
|
|
4452
|
+
different_files: [],
|
|
4453
|
+
modified_files: [],
|
|
4454
|
+
...error instanceof SkillFolderResolutionError && error.missingAncestor ? { ownership_manifest: "absent" } : {
|
|
4455
|
+
ownership_manifest: "invalid",
|
|
4456
|
+
code: "skill_update_conflict"
|
|
4457
|
+
},
|
|
4458
|
+
hint: error.message
|
|
4459
|
+
};
|
|
4460
|
+
}
|
|
4461
|
+
const state = await stateAt(root);
|
|
4462
|
+
const { owned, pending, recorded } = await recoveryOwnership(root, state);
|
|
4463
|
+
const newerIntent = pending.manifest && pending.manifest.version > bundle.version;
|
|
4464
|
+
const missing_files = [], different_files = [], modified_files = [];
|
|
4465
|
+
for (const path of Object.keys(bundle.files).sort()) {
|
|
4466
|
+
const text = await bytesAt(root, path).catch(() => null);
|
|
4467
|
+
if (text === null) missing_files.push(path);
|
|
4468
|
+
else if (!text.equals(Buffer.from(bundle.files[path]))) different_files.push(path);
|
|
4469
|
+
}
|
|
4470
|
+
for (const [path, expected] of Object.entries(recorded).sort()) {
|
|
4471
|
+
const text = await bytesAt(root, path).catch(() => null);
|
|
4472
|
+
if (expected && (text === null ? pending.status === "absent" : hash(text) !== expected)) modified_files.push(path);
|
|
4473
|
+
}
|
|
4474
|
+
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));
|
|
4475
|
+
return {
|
|
4476
|
+
folder_path: dirname(entry),
|
|
4477
|
+
resolved_folder_path: root,
|
|
4478
|
+
complete: missing_files.length === 0,
|
|
4479
|
+
current: state.kind === "managed" && state.version === bundle.version && !missing_files.length && !different_files.length && owned.status === "valid" && manifestMatches && pending.status === "absent",
|
|
4480
|
+
...pending.status !== "absent" ? { interrupted_update: true } : {},
|
|
4481
|
+
older_version: state.kind === "managed" && state.version < bundle.version,
|
|
4482
|
+
missing_files,
|
|
4483
|
+
different_files,
|
|
4484
|
+
modified_files,
|
|
4485
|
+
ownership_manifest: owned.status,
|
|
4486
|
+
...newerIntent ? { hint: newerIntentHint(pending.manifest.version) } : {}
|
|
4487
|
+
};
|
|
4488
|
+
}
|
|
4489
|
+
function newerIntentHint(version) {
|
|
4490
|
+
return `Interrupted skill update requires a newer CLI with bundled skill version ${version} or later. Upgrade the CLI, then retry.`;
|
|
4491
|
+
}
|
|
4492
|
+
async function preflightFolder(entry, bundle, force = false, forceRetirement = force) {
|
|
4493
|
+
const root = await rootFor(entry);
|
|
4494
|
+
const state = await stateAt(root);
|
|
4495
|
+
await inspectTree(root);
|
|
4496
|
+
await safe(root, "SKILL.md");
|
|
4497
|
+
const { owned, pending, recorded } = await recoveryOwnership(root, state);
|
|
4498
|
+
if (bundle && pending.manifest && pending.manifest.version > bundle.version) throw new Error(newerIntentHint(pending.manifest.version));
|
|
4499
|
+
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.`);
|
|
4500
|
+
const previous = recorded;
|
|
4501
|
+
await safe(root, PENDING);
|
|
4502
|
+
await safe(root, MANIFEST);
|
|
4503
|
+
for (const path of Object.keys(previous)) await safe(root, path);
|
|
4504
|
+
if (!forceRetirement) for (const [path, expected] of Object.entries(previous)) {
|
|
4505
|
+
const bytes = await bytesAt(root, path);
|
|
4506
|
+
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.`);
|
|
4507
|
+
}
|
|
4508
|
+
const blockers = Object.keys(previous).filter((path) => bundle && !Object.hasOwn(bundle.files, path) && Object.keys(bundle.files).some((next) => next.startsWith(`${path}/`)));
|
|
4509
|
+
const retiredAncestors = new Set(blockers.map((path) => join(root, path)));
|
|
4510
|
+
const replacedDirectories = /* @__PURE__ */ new Set();
|
|
4511
|
+
const checkDirectory = async (relative) => {
|
|
4512
|
+
if (!Object.keys(previous).some((path) => path.startsWith(`${relative}/`))) throw new Error(`Unowned skill directory (type change): ${relative}. Preserve or move this entry before updating.`);
|
|
4513
|
+
for (const name of await readdir(join(root, relative))) {
|
|
4514
|
+
const child = `${relative}/${name}`;
|
|
4515
|
+
const item = await info(join(root, child));
|
|
4516
|
+
if (item?.isFile() && legacyTemp.test(name)) {
|
|
4517
|
+
if (stale(item)) continue;
|
|
4518
|
+
throw new Error(`Recent skill temporary file: ${child}. Retry after the active update has finished and temporary files are older than ten minutes.`);
|
|
4519
|
+
}
|
|
4520
|
+
if (item?.isDirectory()) await checkDirectory(child);
|
|
4521
|
+
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.`);
|
|
4522
|
+
}
|
|
4523
|
+
replacedDirectories.add(join(root, relative));
|
|
4524
|
+
};
|
|
4525
|
+
for (const path of Object.keys(bundle?.files ?? {})) {
|
|
4526
|
+
if (!blockers.some((ancestor) => path.startsWith(`${ancestor}/`))) {
|
|
4527
|
+
await safe(root, path, retiredAncestors, /* @__PURE__ */ new Set([join(root, path)]));
|
|
4528
|
+
if ((await info(join(root, path)))?.isDirectory()) await checkDirectory(path);
|
|
4529
|
+
}
|
|
4530
|
+
await safe(root, path, retiredAncestors, replacedDirectories);
|
|
4531
|
+
if (!Object.hasOwn(previous, path) && !replacedDirectories.has(join(root, path)) && !blockers.some((ancestor) => path.startsWith(`${ancestor}/`)) && await info(join(root, path)) && !force) throw new Error(`Unowned skill file: ${path}. Use skills install --force to take over bundled paths.`);
|
|
4532
|
+
}
|
|
4533
|
+
return {
|
|
4534
|
+
root,
|
|
4535
|
+
previous,
|
|
4536
|
+
blockers,
|
|
4537
|
+
replacedDirectories
|
|
4538
|
+
};
|
|
4539
|
+
}
|
|
4540
|
+
async function prune(root, paths) {
|
|
4541
|
+
const dirs = /* @__PURE__ */ new Set();
|
|
4542
|
+
for (const path of paths) {
|
|
4543
|
+
let dir = dirname(join(root, path));
|
|
4544
|
+
while (dir.startsWith(root) && dir !== root) {
|
|
4545
|
+
dirs.add(dir);
|
|
4546
|
+
dir = dirname(dir);
|
|
4547
|
+
}
|
|
4548
|
+
}
|
|
4549
|
+
for (const dir of [...dirs].sort((a, b) => b.length - a.length)) await rmdir(dir).catch(() => {});
|
|
4550
|
+
}
|
|
4551
|
+
async function writeSkillFolder(entry, bundle, force = false, forceRetirement = force, cleanup = true) {
|
|
4552
|
+
if (cleanup) await cleanupSkillFolder(entry, bundle);
|
|
4553
|
+
const { root, previous, blockers, replacedDirectories } = await preflightFolder(entry, bundle, force, forceRetirement);
|
|
4554
|
+
const files = {
|
|
4555
|
+
...bundle.files,
|
|
4556
|
+
[MANIFEST]: JSON.stringify({
|
|
4557
|
+
schema_version: 1,
|
|
4558
|
+
version: bundle.version,
|
|
4559
|
+
files: Object.fromEntries(Object.entries(bundle.files).map(([path, text]) => [path, hash(text)]))
|
|
4560
|
+
}, null, 2) + "\n"
|
|
4561
|
+
};
|
|
4562
|
+
const stagingDirectories = [];
|
|
4563
|
+
let internalStaging = false;
|
|
4564
|
+
const staged = /* @__PURE__ */ new Map();
|
|
4565
|
+
const backups = /* @__PURE__ */ new Map();
|
|
4566
|
+
const changed = /* @__PURE__ */ new Set();
|
|
4567
|
+
const createdDirectories = [];
|
|
4568
|
+
const removedDirectories = [];
|
|
4569
|
+
const ensureDirectory = async (path) => {
|
|
4570
|
+
if (await info(path)) return;
|
|
4571
|
+
await ensureDirectory(dirname(path));
|
|
4572
|
+
await mkdir(path);
|
|
4573
|
+
createdDirectories.push(path);
|
|
4574
|
+
};
|
|
4575
|
+
for (const path of /* @__PURE__ */ new Set([
|
|
4576
|
+
...Object.keys(previous),
|
|
4577
|
+
...Object.keys(files),
|
|
4578
|
+
PENDING
|
|
4579
|
+
])) {
|
|
4580
|
+
const blocked = blockers.some((ancestor) => path.startsWith(`${ancestor}/`));
|
|
4581
|
+
backups.set(path, !blocked && (await info(join(root, path)))?.isFile() ? await readFile(join(root, path)) : null);
|
|
4582
|
+
}
|
|
4583
|
+
const intent = JSON.stringify({
|
|
4584
|
+
...JSON.parse(files[MANIFEST]),
|
|
4585
|
+
previous_files: previous
|
|
4586
|
+
}) + "\n";
|
|
4587
|
+
const stage = async (parent) => {
|
|
4588
|
+
await ensureDirectory(parent);
|
|
4589
|
+
const stagingDir = join(parent, `.artifactshare-staging-${randomUUID()}`);
|
|
4590
|
+
await mkdir(stagingDir, { mode: 448 });
|
|
4591
|
+
stagingDirectories.push(stagingDir);
|
|
4592
|
+
for (const [path, text] of Object.entries({
|
|
4593
|
+
...files,
|
|
4594
|
+
[PENDING]: intent
|
|
4595
|
+
})) {
|
|
4596
|
+
const temp = join(stagingDir, basename(path) === "SKILL.md" ? `${randomUUID()}.tmp` : path);
|
|
4597
|
+
await mkdir(dirname(temp), { recursive: true });
|
|
4598
|
+
await writeFile(temp, text, { flag: "wx" });
|
|
4599
|
+
staged.set(path, temp);
|
|
4600
|
+
}
|
|
4601
|
+
};
|
|
4602
|
+
const stageInside = async () => {
|
|
4603
|
+
internalStaging = true;
|
|
4604
|
+
await stage(root);
|
|
4605
|
+
};
|
|
4606
|
+
const retire = async (path) => {
|
|
4607
|
+
if (backups.get(path) !== null) {
|
|
4608
|
+
await unlink(join(root, path));
|
|
4609
|
+
changed.add(path);
|
|
4610
|
+
}
|
|
4611
|
+
};
|
|
4612
|
+
const commit = async (path) => {
|
|
4613
|
+
await ensureDirectory(dirname(join(root, path)));
|
|
4614
|
+
try {
|
|
4615
|
+
await rename(staged.get(path), join(root, path));
|
|
4616
|
+
} catch (error) {
|
|
4617
|
+
if (internalStaging || error.code !== "EXDEV") throw error;
|
|
4618
|
+
await stageInside();
|
|
4619
|
+
await rename(staged.get(path), join(root, path));
|
|
4620
|
+
}
|
|
4621
|
+
changed.add(path);
|
|
4622
|
+
};
|
|
4623
|
+
try {
|
|
4624
|
+
try {
|
|
4625
|
+
await stage(dirname(root));
|
|
4626
|
+
} catch (error) {
|
|
4627
|
+
if (stagingDirectories.length !== 0 || ![
|
|
4628
|
+
"EACCES",
|
|
4629
|
+
"EPERM",
|
|
4630
|
+
"EROFS"
|
|
4631
|
+
].includes(error.code ?? "")) throw error;
|
|
4632
|
+
await stageInside();
|
|
4633
|
+
}
|
|
4634
|
+
await commit(PENDING);
|
|
4635
|
+
const retired = Object.keys(previous).filter((path) => !Object.hasOwn(bundle.files, path));
|
|
4636
|
+
const earlyRetired = new Set(retired.filter((path) => blockers.includes(path) || [...replacedDirectories].some((dir) => join(root, path).startsWith(`${dir}${sep}`))));
|
|
4637
|
+
for (const path of earlyRetired) await retire(path);
|
|
4638
|
+
for (const dir of [...replacedDirectories].sort((a, b) => b.length - a.length)) {
|
|
4639
|
+
await rmdir(dir);
|
|
4640
|
+
removedDirectories.push(dir);
|
|
4641
|
+
}
|
|
4642
|
+
for (const path of Object.keys(bundle.files).filter((relative) => relative !== "SKILL.md").sort()) await commit(path);
|
|
4643
|
+
for (const path of retired) if (!earlyRetired.has(path)) await retire(path);
|
|
4644
|
+
await commit(MANIFEST);
|
|
4645
|
+
await commit("SKILL.md");
|
|
4646
|
+
await unlink(join(root, PENDING));
|
|
4647
|
+
await prune(root, retired);
|
|
4648
|
+
} catch (error) {
|
|
4649
|
+
for (const path of [...changed].reverse()) {
|
|
4650
|
+
if (path === PENDING) continue;
|
|
4651
|
+
if ((await info(join(root, path)))?.isFile()) await unlink(join(root, path));
|
|
4652
|
+
}
|
|
4653
|
+
for (const dir of [...createdDirectories].reverse()) await rmdir(dir).catch(() => {});
|
|
4654
|
+
for (const dir of removedDirectories.reverse()) await mkdir(dir, { recursive: true });
|
|
4655
|
+
for (const path of changed) {
|
|
4656
|
+
if (path === PENDING) continue;
|
|
4657
|
+
const bytes = backups.get(path);
|
|
4658
|
+
if (bytes !== null && bytes !== void 0) {
|
|
4659
|
+
await mkdir(dirname(join(root, path)), { recursive: true });
|
|
4660
|
+
await writeFile(join(root, path), bytes);
|
|
4661
|
+
}
|
|
4662
|
+
}
|
|
4663
|
+
if (changed.has(PENDING)) {
|
|
4664
|
+
const previousIntent = backups.get(PENDING);
|
|
4665
|
+
if (previousIntent) await writeFile(join(root, PENDING), previousIntent);
|
|
4666
|
+
else await unlink(join(root, PENDING));
|
|
4667
|
+
}
|
|
4668
|
+
throw error;
|
|
4669
|
+
} finally {
|
|
4670
|
+
for (const dir of stagingDirectories) await rm(dir, {
|
|
4671
|
+
recursive: true,
|
|
4672
|
+
force: true
|
|
4673
|
+
});
|
|
4674
|
+
for (const dir of [...createdDirectories].reverse()) await rmdir(dir).catch(() => {});
|
|
4675
|
+
}
|
|
4676
|
+
}
|
|
4677
|
+
async function removeSkillFolder(entry, retainRoot = false) {
|
|
4678
|
+
const { root, previous } = await preflightFolder(entry);
|
|
4679
|
+
for (const path of [
|
|
4680
|
+
...Object.keys(previous),
|
|
4681
|
+
MANIFEST,
|
|
4682
|
+
PENDING
|
|
4683
|
+
]) await unlink(join(root, path)).catch((error) => {
|
|
4684
|
+
if (error.code !== "ENOENT") throw error;
|
|
4685
|
+
});
|
|
4686
|
+
await prune(root, Object.keys(previous));
|
|
4687
|
+
let path = dirname(entry);
|
|
4688
|
+
while (path !== dirname(path)) {
|
|
4689
|
+
if ((await info(path))?.isSymbolicLink()) retainRoot = true;
|
|
4690
|
+
if (path === dirname(dirname(dirname(entry)))) break;
|
|
4691
|
+
path = dirname(path);
|
|
4692
|
+
}
|
|
4693
|
+
if (!retainRoot) {
|
|
4694
|
+
await rmdir(root).catch(() => {});
|
|
4695
|
+
await rmdir(dirname(root)).catch(() => {});
|
|
4696
|
+
}
|
|
4697
|
+
}
|
|
4698
|
+
//#endregion
|
|
4147
4699
|
//#region src/command-runners/skills.ts
|
|
4148
4700
|
const SKILL_TOOLS = [
|
|
4149
4701
|
"codex",
|
|
@@ -4165,25 +4717,63 @@ const TOOL_CONFIG = {
|
|
|
4165
4717
|
detectDirs: [".cursor"]
|
|
4166
4718
|
}
|
|
4167
4719
|
};
|
|
4168
|
-
function scopeTargetConfig(tool,
|
|
4169
|
-
if (tool === "cursor") {
|
|
4170
|
-
if (scope === "project") return {
|
|
4171
|
-
relativePath: join(".cursor", "rules", "artifactshare.mdc"),
|
|
4172
|
-
bundledFile: "artifactshare.mdc",
|
|
4173
|
-
pruneDirs: []
|
|
4174
|
-
};
|
|
4175
|
-
return {
|
|
4176
|
-
relativePath: join(".cursor", "skills", "artifactshare", "SKILL.md"),
|
|
4177
|
-
bundledFile: "SKILL.md",
|
|
4178
|
-
pruneDirs: ["artifactshare", "skills"]
|
|
4179
|
-
};
|
|
4180
|
-
}
|
|
4720
|
+
function scopeTargetConfig(tool, _scope) {
|
|
4181
4721
|
return {
|
|
4182
|
-
relativePath: join(tool === "codex" ? ".agents" : ".claude", SKILL_FILE_PATH),
|
|
4183
|
-
bundledFile: "SKILL.md",
|
|
4722
|
+
relativePath: join(tool === "codex" ? ".agents" : tool === "cursor" ? ".cursor" : ".claude", SKILL_FILE_PATH),
|
|
4184
4723
|
pruneDirs: ["artifactshare", "skills"]
|
|
4185
4724
|
};
|
|
4186
4725
|
}
|
|
4726
|
+
function aliases(target) {
|
|
4727
|
+
return "aliases" in target && target.aliases || [{
|
|
4728
|
+
tool: target.tool,
|
|
4729
|
+
scope: target.scope,
|
|
4730
|
+
path: target.path,
|
|
4731
|
+
folder_path: target.path === null ? null : dirname(target.path)
|
|
4732
|
+
}];
|
|
4733
|
+
}
|
|
4734
|
+
function identity(target) {
|
|
4735
|
+
return {
|
|
4736
|
+
aliases: aliases(target),
|
|
4737
|
+
resolved_folder_path: "resolved_folder_path" in target ? target.resolved_folder_path ?? null : null
|
|
4738
|
+
};
|
|
4739
|
+
}
|
|
4740
|
+
function targetOrder(a, b) {
|
|
4741
|
+
return SKILL_TOOLS.indexOf(a.tool) - SKILL_TOOLS.indexOf(b.tool) || (a.scope === b.scope ? 0 : a.scope === "project" ? -1 : 1);
|
|
4742
|
+
}
|
|
4743
|
+
async function cleanupTarget(target, bundled) {
|
|
4744
|
+
if (target.cleaned) return;
|
|
4745
|
+
await cleanupSkillFolder(target.absolutePath, bundled);
|
|
4746
|
+
target.cleaned = true;
|
|
4747
|
+
}
|
|
4748
|
+
async function groupTargets(targets) {
|
|
4749
|
+
const groups = /* @__PURE__ */ new Map();
|
|
4750
|
+
const result = [];
|
|
4751
|
+
for (const target of [...targets].sort((a, b) => targetOrder(aliases(a)[0], aliases(b)[0]))) {
|
|
4752
|
+
if (!availableTarget(target)) {
|
|
4753
|
+
result.push(target);
|
|
4754
|
+
continue;
|
|
4755
|
+
}
|
|
4756
|
+
const key = await resolveSkillFolder(target.absolutePath).catch(() => null);
|
|
4757
|
+
target.resolved_folder_path = key;
|
|
4758
|
+
const existing = key === null ? void 0 : groups.get(key);
|
|
4759
|
+
if (existing && availableTarget(existing)) existing.aliases = [...aliases(existing), ...aliases(target)];
|
|
4760
|
+
else {
|
|
4761
|
+
target.aliases = aliases(target);
|
|
4762
|
+
result.push(target);
|
|
4763
|
+
if (key !== null) groups.set(key, target);
|
|
4764
|
+
}
|
|
4765
|
+
}
|
|
4766
|
+
return result;
|
|
4767
|
+
}
|
|
4768
|
+
async function conflictFor(target) {
|
|
4769
|
+
const error = skillUpdateConflictError(target.path);
|
|
4770
|
+
try {
|
|
4771
|
+
await preflightFolder(target.absolutePath);
|
|
4772
|
+
} catch (cause) {
|
|
4773
|
+
error.hint = cause.message;
|
|
4774
|
+
}
|
|
4775
|
+
return error;
|
|
4776
|
+
}
|
|
4187
4777
|
const CLAUDE_CONFIG_HINT = "Set CLAUDE_CONFIG_DIR to a non-empty path or unset it to use ~/.claude.";
|
|
4188
4778
|
function claudeUserRoot() {
|
|
4189
4779
|
const value = process.env.CLAUDE_CONFIG_DIR;
|
|
@@ -4204,6 +4794,7 @@ function availableTarget(target) {
|
|
|
4204
4794
|
}
|
|
4205
4795
|
function unavailableState(target) {
|
|
4206
4796
|
return {
|
|
4797
|
+
...identity(target),
|
|
4207
4798
|
tool: target.tool,
|
|
4208
4799
|
scope: target.scope,
|
|
4209
4800
|
path: null,
|
|
@@ -4213,7 +4804,15 @@ function unavailableState(target) {
|
|
|
4213
4804
|
installed: false,
|
|
4214
4805
|
managed: false,
|
|
4215
4806
|
installed_version: null,
|
|
4216
|
-
update_available: false
|
|
4807
|
+
update_available: false,
|
|
4808
|
+
folder_path: null,
|
|
4809
|
+
complete: false,
|
|
4810
|
+
current: false,
|
|
4811
|
+
older_version: false,
|
|
4812
|
+
missing_files: [],
|
|
4813
|
+
different_files: [],
|
|
4814
|
+
modified_files: [],
|
|
4815
|
+
ownership_manifest: "absent"
|
|
4217
4816
|
};
|
|
4218
4817
|
}
|
|
4219
4818
|
function unavailableActionTargets(tools, scope) {
|
|
@@ -4250,44 +4849,52 @@ function skillTarget(tool, scope) {
|
|
|
4250
4849
|
absolutePath: resolve(path)
|
|
4251
4850
|
};
|
|
4252
4851
|
}
|
|
4253
|
-
function bundledContentForTarget(bundled, target) {
|
|
4254
|
-
const file = scopeTargetConfig(target.tool, target.scope).bundledFile;
|
|
4255
|
-
return bundled.contentsByFile[file];
|
|
4256
|
-
}
|
|
4257
4852
|
function allTargets() {
|
|
4258
4853
|
return SKILL_TOOLS.flatMap((tool) => TOOL_CONFIG[tool].scopes.map((scope) => skillTarget(tool, scope)));
|
|
4259
4854
|
}
|
|
4260
|
-
function
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4855
|
+
function readTarget(target) {
|
|
4856
|
+
return readSkillState(target.absolutePath);
|
|
4857
|
+
}
|
|
4858
|
+
function loadBundledSkills() {
|
|
4859
|
+
return loadSkillBundle(fileURLToPath(new URL("../skills/artifactshare/", import.meta.url)));
|
|
4860
|
+
}
|
|
4861
|
+
function cursorProjectAlias(target) {
|
|
4862
|
+
return aliases(target).find((alias) => alias.tool === "cursor" && alias.scope === "project");
|
|
4863
|
+
}
|
|
4864
|
+
async function legacyRule(target) {
|
|
4865
|
+
const cursor = cursorProjectAlias(target);
|
|
4866
|
+
if (!cursor) return void 0;
|
|
4867
|
+
const path = join(".cursor", "rules", "artifactshare.mdc");
|
|
4868
|
+
const info = await lstat(path).catch(() => null);
|
|
4869
|
+
const parent = await lstat(dirname(path)).catch(() => null);
|
|
4870
|
+
const content = info?.isFile() && !parent?.isSymbolicLink() ? await readFile(path, "utf8").catch(() => null) : null;
|
|
4871
|
+
const present = info !== null;
|
|
4872
|
+
const managed = managedState(content).kind === "managed";
|
|
4267
4873
|
return {
|
|
4268
|
-
|
|
4269
|
-
|
|
4874
|
+
path,
|
|
4875
|
+
present,
|
|
4876
|
+
managed,
|
|
4877
|
+
coexistence: present && await lstat(resolve(cursor.path)).catch(() => null) !== null,
|
|
4878
|
+
hint: present && !managed ? "Inspect the legacy Cursor rule and manually remove it if the skill folder replaces it." : null
|
|
4270
4879
|
};
|
|
4271
4880
|
}
|
|
4272
|
-
async function
|
|
4273
|
-
|
|
4881
|
+
async function legacyManagedVersion(target) {
|
|
4882
|
+
const legacy = await legacyRule(target);
|
|
4883
|
+
if (!legacy?.managed) return void 0;
|
|
4884
|
+
const state = managedState(await readFile(legacy.path, "utf8"));
|
|
4885
|
+
return state.kind === "managed" ? state.version : void 0;
|
|
4274
4886
|
}
|
|
4275
|
-
async function
|
|
4276
|
-
const
|
|
4277
|
-
let version;
|
|
4278
|
-
for (const file of ["SKILL.md", "artifactshare.mdc"]) {
|
|
4279
|
-
const url = new URL(`../skills/artifactshare/${file}`, import.meta.url);
|
|
4280
|
-
const content = await readFile(url, "utf8");
|
|
4281
|
-
const state = managedState(content);
|
|
4282
|
-
if (state.kind !== "managed" || (version ?? state.version) !== state.version) throw new Error(`The bundled ${file} has a missing or mismatched managed marker.`);
|
|
4283
|
-
version = state.version;
|
|
4284
|
-
contentsByFile[file] = content;
|
|
4285
|
-
}
|
|
4887
|
+
async function diagnostic(target, bundle) {
|
|
4888
|
+
const legacy = await legacyRule(target);
|
|
4286
4889
|
return {
|
|
4287
|
-
|
|
4288
|
-
|
|
4890
|
+
...await folderDiagnostics(target.absolutePath, bundle),
|
|
4891
|
+
folder_path: dirname(target.path),
|
|
4892
|
+
...legacy ? { legacy_rule: legacy } : {}
|
|
4289
4893
|
};
|
|
4290
4894
|
}
|
|
4895
|
+
async function isCurrent(target, bundle) {
|
|
4896
|
+
return (await folderDiagnostics(target.absolutePath, bundle)).current;
|
|
4897
|
+
}
|
|
4291
4898
|
function parseTools(value, options = {}) {
|
|
4292
4899
|
const raws = arrayOption(value);
|
|
4293
4900
|
const tools = [];
|
|
@@ -4377,35 +4984,101 @@ async function autoTargets(scope) {
|
|
|
4377
4984
|
};
|
|
4378
4985
|
}
|
|
4379
4986
|
function targetPathKey(target) {
|
|
4380
|
-
return
|
|
4987
|
+
return resolveSkillFolder(target.absolutePath).catch(() => target.absolutePath);
|
|
4381
4988
|
}
|
|
4382
|
-
async function
|
|
4383
|
-
if (content
|
|
4384
|
-
|
|
4385
|
-
|
|
4989
|
+
async function prepareAction(item, dryRun) {
|
|
4990
|
+
if (!dryRun && (item.content || item.action === "unchanged")) await cleanupTarget(item.target, item.content ?? await loadBundledSkills());
|
|
4991
|
+
if (item.content) {
|
|
4992
|
+
if (item.automatic) {
|
|
4993
|
+
const details = await diagnostic(item.target, item.content);
|
|
4994
|
+
if (details.modified_files.length) throw new Error(`Modified skill files: ${details.modified_files.join(", ")}`);
|
|
4995
|
+
}
|
|
4996
|
+
await preflightFolder(item.target.absolutePath, item.content, item.force, item.forceRetirement);
|
|
4997
|
+
}
|
|
4998
|
+
if (item.action === "removed") await preflightFolder(item.target.absolutePath);
|
|
4999
|
+
const legacy = await legacyRule(item.target);
|
|
5000
|
+
if (legacy?.managed && item.action === "unchanged" && !await isCurrent(item.target, await loadBundledSkills())) {
|
|
5001
|
+
item.action = "update_recommended";
|
|
4386
5002
|
return;
|
|
4387
5003
|
}
|
|
4388
|
-
if (
|
|
4389
|
-
|
|
4390
|
-
|
|
5004
|
+
if (legacy?.present) {
|
|
5005
|
+
if (!legacy.managed) item.legacy = {
|
|
5006
|
+
path: legacy.path,
|
|
5007
|
+
action: "kept_unmanaged",
|
|
5008
|
+
hint: legacy.hint ?? "Inspect the legacy rule."
|
|
5009
|
+
};
|
|
5010
|
+
else if (item.content || item.action === "unchanged" || item.action === "removed" || item.action === "not_installed" || item.removeLegacy) item.legacy = {
|
|
5011
|
+
path: legacy.path,
|
|
5012
|
+
action: dryRun ? "would_remove" : "removed"
|
|
5013
|
+
};
|
|
5014
|
+
}
|
|
5015
|
+
}
|
|
5016
|
+
async function applyAction(item) {
|
|
5017
|
+
if (item.content) await writeSkillFolder(item.target.absolutePath, item.content, item.force, item.forceRetirement, false);
|
|
5018
|
+
if (item.action === "removed") await removeSkillFolder(item.target.absolutePath, aliases(item.target).length > 1);
|
|
5019
|
+
if (item.legacy?.action === "removed") try {
|
|
5020
|
+
await unlink(item.legacy.path);
|
|
5021
|
+
} catch {
|
|
5022
|
+
item.legacy = {
|
|
5023
|
+
path: item.legacy.path,
|
|
5024
|
+
action: "remove_failed",
|
|
5025
|
+
hint: "Retry skills update --tool cursor --scope project --json to remove the legacy rule."
|
|
5026
|
+
};
|
|
4391
5027
|
}
|
|
4392
5028
|
}
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
5029
|
+
function skillUpdateCommand(target) {
|
|
5030
|
+
return `${CLI_INVOCATION} skills update --tool ${target.tool} --scope ${target.scope} --json`;
|
|
5031
|
+
}
|
|
5032
|
+
async function recoveryRecommendation(target, bundled) {
|
|
5033
|
+
const details = await diagnostic(target, bundled);
|
|
5034
|
+
let update_command = skillUpdateCommand(target);
|
|
5035
|
+
try {
|
|
5036
|
+
await preflightFolder(target.absolutePath, bundled);
|
|
5037
|
+
} catch {
|
|
4397
5038
|
try {
|
|
4398
|
-
await
|
|
5039
|
+
await preflightFolder(target.absolutePath, bundled, false, true);
|
|
5040
|
+
update_command = update_command.replace(" --json", " --force --json");
|
|
4399
5041
|
} catch {
|
|
4400
|
-
|
|
5042
|
+
try {
|
|
5043
|
+
await preflightFolder(target.absolutePath, bundled, true);
|
|
5044
|
+
update_command = `${CLI_INVOCATION} skills install --tool ${target.tool} --scope ${target.scope} --force --json`;
|
|
5045
|
+
} catch (error) {
|
|
5046
|
+
return {
|
|
5047
|
+
hint: error.message,
|
|
5048
|
+
...details.modified_files.length ? { modified_files: details.modified_files } : {}
|
|
5049
|
+
};
|
|
5050
|
+
}
|
|
4401
5051
|
}
|
|
4402
|
-
dir = dirname(dir);
|
|
4403
5052
|
}
|
|
5053
|
+
return {
|
|
5054
|
+
update_command,
|
|
5055
|
+
...details.modified_files.length ? {
|
|
5056
|
+
modified_files: details.modified_files,
|
|
5057
|
+
hint: `Modified skill files: ${details.modified_files.join(", ")}. Preserve your edits before running the recommended command.`
|
|
5058
|
+
} : {}
|
|
5059
|
+
};
|
|
4404
5060
|
}
|
|
4405
|
-
function
|
|
4406
|
-
|
|
5061
|
+
async function skipAutomaticTarget(target, state) {
|
|
5062
|
+
if (await legacyManagedVersion(target) !== void 0) return false;
|
|
5063
|
+
if (state.kind === "unmanaged") return true;
|
|
5064
|
+
return state.kind === "missing" && !await lstat(join(dirname(target.absolutePath), ".artifactshare-pending.json")).catch(() => null);
|
|
4407
5065
|
}
|
|
4408
5066
|
async function finishActions(command, planned, dryRun, mode) {
|
|
5067
|
+
planned.sort((a, b) => targetOrder(aliases(a.target)[0], aliases(b.target)[0]));
|
|
5068
|
+
for (const item of planned) try {
|
|
5069
|
+
await prepareAction(item, dryRun);
|
|
5070
|
+
} catch (error) {
|
|
5071
|
+
if (item.fallbackAction) {
|
|
5072
|
+
item.hint = error.message;
|
|
5073
|
+
item.action = item.fallbackAction;
|
|
5074
|
+
delete item.content;
|
|
5075
|
+
continue;
|
|
5076
|
+
}
|
|
5077
|
+
const conflict = skillUpdateConflictError(item.target.path);
|
|
5078
|
+
if (error instanceof Error) conflict.hint = error.message;
|
|
5079
|
+
writeFailure(command, conflict, mode, 1);
|
|
5080
|
+
return;
|
|
5081
|
+
}
|
|
4409
5082
|
const completed = [...planned];
|
|
4410
5083
|
if (!dryRun) for (const [index, item] of planned.entries()) try {
|
|
4411
5084
|
await applyAction(item);
|
|
@@ -4414,7 +5087,8 @@ async function finishActions(command, planned, dryRun, mode) {
|
|
|
4414
5087
|
if (item.fallbackAction) {
|
|
4415
5088
|
completed[index] = {
|
|
4416
5089
|
target: item.target,
|
|
4417
|
-
action: item.fallbackAction
|
|
5090
|
+
action: item.fallbackAction,
|
|
5091
|
+
hint: error.message
|
|
4418
5092
|
};
|
|
4419
5093
|
continue;
|
|
4420
5094
|
}
|
|
@@ -4423,13 +5097,17 @@ async function finishActions(command, planned, dryRun, mode) {
|
|
|
4423
5097
|
}
|
|
4424
5098
|
return {
|
|
4425
5099
|
dry_run: dryRun,
|
|
4426
|
-
targets: completed.map(({ target, action }) => ({
|
|
5100
|
+
targets: await Promise.all(completed.map(async ({ target, action, legacy, hint }) => ({
|
|
5101
|
+
...hint ? { hint } : {},
|
|
4427
5102
|
tool: target.tool,
|
|
4428
5103
|
scope: target.scope,
|
|
4429
5104
|
path: target.path,
|
|
5105
|
+
...identity(target),
|
|
5106
|
+
folder_path: dirname(target.path),
|
|
5107
|
+
...legacy ? { legacy_rule: legacy } : {},
|
|
4430
5108
|
action,
|
|
4431
|
-
...action === "update_recommended" ?
|
|
4432
|
-
}))
|
|
5109
|
+
...action === "update_recommended" ? await recoveryRecommendation(target, await loadBundledSkills()) : {}
|
|
5110
|
+
})))
|
|
4433
5111
|
};
|
|
4434
5112
|
}
|
|
4435
5113
|
async function runActions(command, planned, dryRun, mode, unavailableTargets = []) {
|
|
@@ -4439,6 +5117,8 @@ async function runActions(command, planned, dryRun, mode, unavailableTargets = [
|
|
|
4439
5117
|
tool: target.tool,
|
|
4440
5118
|
scope: target.scope,
|
|
4441
5119
|
path: null,
|
|
5120
|
+
...identity(target),
|
|
5121
|
+
folder_path: null,
|
|
4442
5122
|
action: "skipped",
|
|
4443
5123
|
code: target.error.code,
|
|
4444
5124
|
hint: target.error.hint
|
|
@@ -4465,12 +5145,11 @@ async function runSkillsInstall(parsed, mode) {
|
|
|
4465
5145
|
const bundled = await bundledOrFailure(command, mode);
|
|
4466
5146
|
if (!bundled) return;
|
|
4467
5147
|
const planned = [];
|
|
4468
|
-
for (const
|
|
4469
|
-
const target = skillTarget(tool, scope);
|
|
5148
|
+
for (const target of await groupTargets(allTargets().filter((candidate) => tools.includes(candidate.tool) && candidate.scope === scope))) {
|
|
4470
5149
|
if (!availableTarget(target)) return writeFailure(command, target.error, mode, 1);
|
|
4471
5150
|
const state = await readTarget(target);
|
|
4472
|
-
if ((state.kind === "unmanaged" || state.kind === "broken") && !force) return writeFailure(command,
|
|
4473
|
-
if (state.kind === "managed" &&
|
|
5151
|
+
if ((state.kind === "unmanaged" || state.kind === "broken") && !force) return writeFailure(command, await conflictFor(target), mode, 1);
|
|
5152
|
+
if (state.kind === "managed" && await isCurrent(target, bundled) && !force) {
|
|
4474
5153
|
planned.push({
|
|
4475
5154
|
target,
|
|
4476
5155
|
action: "unchanged"
|
|
@@ -4480,7 +5159,8 @@ async function runSkillsInstall(parsed, mode) {
|
|
|
4480
5159
|
planned.push({
|
|
4481
5160
|
target,
|
|
4482
5161
|
action: state.kind === "missing" ? "installed" : "updated",
|
|
4483
|
-
content:
|
|
5162
|
+
content: bundled,
|
|
5163
|
+
force
|
|
4484
5164
|
});
|
|
4485
5165
|
}
|
|
4486
5166
|
await runActions(command, planned, parsed.options.dryRun === true, mode);
|
|
@@ -4505,75 +5185,180 @@ async function ensureSkills(parsed, mode, options = {}) {
|
|
|
4505
5185
|
if (!bundled) return void 0;
|
|
4506
5186
|
const targets = (filters.auto ? await autoTargets(filters.scope) : void 0)?.targets ?? filteredTargets(filters.tools, filters.scope ?? "project");
|
|
4507
5187
|
const planned = [];
|
|
4508
|
-
for (const target of targets) {
|
|
5188
|
+
for (const target of await groupTargets(targets)) {
|
|
4509
5189
|
const state = await readTarget(target);
|
|
4510
5190
|
if (state.kind === "unmanaged" || state.kind === "broken") {
|
|
4511
|
-
if (options.skipBrokenUserSkills && state.kind === "broken")
|
|
4512
|
-
|
|
5191
|
+
if (options.skipBrokenUserSkills && state.kind === "broken") {
|
|
5192
|
+
const details = await diagnostic(target, bundled);
|
|
5193
|
+
if (details.hint) planned.push({
|
|
5194
|
+
target,
|
|
5195
|
+
action: "update_recommended",
|
|
5196
|
+
hint: details.hint,
|
|
5197
|
+
fallbackAction: "update_recommended"
|
|
5198
|
+
});
|
|
5199
|
+
continue;
|
|
5200
|
+
}
|
|
5201
|
+
writeFailure(command, await conflictFor(target), mode, 1);
|
|
4513
5202
|
return;
|
|
4514
5203
|
}
|
|
4515
|
-
const
|
|
5204
|
+
const automaticUpdate = filters.auto || options.command === "init" || options.command === "open";
|
|
5205
|
+
if (automaticUpdate && state.kind === "missing" && state.hint) continue;
|
|
5206
|
+
if (automaticUpdate && state.kind === "managed" && state.version > bundled.version) continue;
|
|
5207
|
+
const details = await diagnostic(target, bundled);
|
|
5208
|
+
if (automaticUpdate && state.kind === "managed" && details.modified_files.length) {
|
|
5209
|
+
planned.push({
|
|
5210
|
+
target,
|
|
5211
|
+
action: "update_recommended"
|
|
5212
|
+
});
|
|
5213
|
+
continue;
|
|
5214
|
+
}
|
|
5215
|
+
const unchanged = state.kind === "managed" && (state.version >= bundled.version && !details.interrupted_update && automaticUpdate || state.version > bundled.version || details.current);
|
|
4516
5216
|
planned.push(unchanged ? {
|
|
4517
5217
|
target,
|
|
4518
|
-
action: "unchanged"
|
|
5218
|
+
action: "unchanged",
|
|
5219
|
+
...automaticUpdate ? { fallbackAction: "update_recommended" } : {}
|
|
4519
5220
|
} : {
|
|
4520
5221
|
target,
|
|
4521
5222
|
action: state.kind === "missing" ? "installed" : "updated",
|
|
4522
|
-
content:
|
|
5223
|
+
content: bundled,
|
|
5224
|
+
automatic: automaticUpdate,
|
|
5225
|
+
...automaticUpdate ? { fallbackAction: "update_recommended" } : {}
|
|
4523
5226
|
});
|
|
4524
5227
|
}
|
|
4525
|
-
if (options.autoUpdateUserManaged) {
|
|
5228
|
+
if (options.autoUpdateUserManaged || filters.auto) {
|
|
4526
5229
|
const plannedPaths = new Set(await Promise.all(planned.map((action) => targetPathKey(action.target))));
|
|
4527
|
-
for (const target of
|
|
4528
|
-
if (plannedPaths.has(await targetPathKey(target)))
|
|
5230
|
+
for (const target of await groupTargets(await automaticTargets(bundled))) {
|
|
5231
|
+
if (plannedPaths.has(await targetPathKey(target))) {
|
|
5232
|
+
const existing = planned.find((item) => target.resolved_folder_path !== null ? item.target.resolved_folder_path === target.resolved_folder_path : item.target.absolutePath === target.absolutePath);
|
|
5233
|
+
if (existing) {
|
|
5234
|
+
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);
|
|
5235
|
+
const primary = existing.target.aliases[0];
|
|
5236
|
+
existing.target.tool = primary.tool;
|
|
5237
|
+
existing.target.scope = primary.scope;
|
|
5238
|
+
existing.target.path = primary.path;
|
|
5239
|
+
existing.target.absolutePath = resolve(primary.path);
|
|
5240
|
+
}
|
|
5241
|
+
continue;
|
|
5242
|
+
}
|
|
4529
5243
|
const state = await readTarget(target);
|
|
4530
|
-
if (
|
|
5244
|
+
if (await skipAutomaticTarget(target, state)) continue;
|
|
5245
|
+
if (state.kind === "managed" && state.version > bundled.version) continue;
|
|
5246
|
+
if (parsed.options.dryRun !== true) try {
|
|
5247
|
+
await cleanupTarget(target, bundled);
|
|
5248
|
+
} catch (error) {
|
|
5249
|
+
planned.push({
|
|
5250
|
+
target,
|
|
5251
|
+
action: "update_recommended",
|
|
5252
|
+
hint: error.message,
|
|
5253
|
+
fallbackAction: "update_recommended"
|
|
5254
|
+
});
|
|
5255
|
+
continue;
|
|
5256
|
+
}
|
|
5257
|
+
const details = await diagnostic(target, bundled);
|
|
5258
|
+
if (state.kind === "managed" && details.modified_files.length) {
|
|
5259
|
+
planned.push({
|
|
5260
|
+
target,
|
|
5261
|
+
action: "update_recommended",
|
|
5262
|
+
installedVersion: state.version
|
|
5263
|
+
});
|
|
5264
|
+
continue;
|
|
5265
|
+
}
|
|
5266
|
+
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;
|
|
4531
5267
|
planned.push({
|
|
4532
5268
|
target,
|
|
4533
|
-
action: "updated",
|
|
4534
|
-
content:
|
|
5269
|
+
action: state.kind === "managed" && state.version >= bundled.version && !details.interrupted_update ? "unchanged" : "updated",
|
|
5270
|
+
...state.kind === "managed" && state.version >= bundled.version && !details.interrupted_update ? {} : { content: bundled },
|
|
5271
|
+
automatic: true,
|
|
4535
5272
|
fallbackAction: "update_recommended"
|
|
4536
5273
|
});
|
|
4537
5274
|
}
|
|
4538
5275
|
}
|
|
4539
5276
|
return finishActions(command, planned, parsed.options.dryRun === true, mode);
|
|
4540
5277
|
}
|
|
5278
|
+
async function automaticTargets(bundled) {
|
|
5279
|
+
const targets = allTargets().filter(availableTarget).filter((target) => target.scope === "user");
|
|
5280
|
+
const project = skillTarget("cursor", "project");
|
|
5281
|
+
if (availableTarget(project)) {
|
|
5282
|
+
const version = await legacyManagedVersion(project);
|
|
5283
|
+
if (version !== void 0 && version <= bundled.version) targets.push(project);
|
|
5284
|
+
}
|
|
5285
|
+
return targets;
|
|
5286
|
+
}
|
|
4541
5287
|
async function autoUpdateUserManagedSkills() {
|
|
4542
5288
|
try {
|
|
4543
5289
|
const bundled = await loadBundledSkills();
|
|
4544
5290
|
const planned = [];
|
|
4545
|
-
for (const target of
|
|
5291
|
+
for (const target of await groupTargets(await automaticTargets(bundled))) {
|
|
4546
5292
|
const state = await readTarget(target);
|
|
4547
|
-
if (
|
|
5293
|
+
if (await skipAutomaticTarget(target, state)) continue;
|
|
5294
|
+
if (state.kind === "managed" && state.version > bundled.version) continue;
|
|
5295
|
+
try {
|
|
5296
|
+
await cleanupTarget(target, bundled);
|
|
5297
|
+
} catch (error) {
|
|
5298
|
+
planned.push({
|
|
5299
|
+
target,
|
|
5300
|
+
action: "update_recommended",
|
|
5301
|
+
hint: error.message,
|
|
5302
|
+
...state.kind === "managed" ? { installedVersion: state.version } : {}
|
|
5303
|
+
});
|
|
5304
|
+
continue;
|
|
5305
|
+
}
|
|
5306
|
+
const details = await diagnostic(target, bundled);
|
|
5307
|
+
if (details.hint) {
|
|
5308
|
+
planned.push({
|
|
5309
|
+
target,
|
|
5310
|
+
action: "update_recommended",
|
|
5311
|
+
hint: details.hint,
|
|
5312
|
+
fallbackAction: "update_recommended",
|
|
5313
|
+
...state.kind === "managed" ? { installedVersion: state.version } : {}
|
|
5314
|
+
});
|
|
5315
|
+
continue;
|
|
5316
|
+
}
|
|
5317
|
+
if (state.kind === "managed" && details.modified_files.length) {
|
|
5318
|
+
planned.push({
|
|
5319
|
+
target,
|
|
5320
|
+
action: "update_recommended",
|
|
5321
|
+
installedVersion: state.version
|
|
5322
|
+
});
|
|
5323
|
+
continue;
|
|
5324
|
+
}
|
|
5325
|
+
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;
|
|
4548
5326
|
planned.push({
|
|
4549
5327
|
target,
|
|
4550
|
-
action: "updated",
|
|
4551
|
-
content:
|
|
5328
|
+
action: state.kind === "managed" && state.version >= bundled.version && !details.interrupted_update ? "unchanged" : "updated",
|
|
5329
|
+
...state.kind === "managed" && state.version >= bundled.version && !details.interrupted_update ? {} : { content: bundled },
|
|
5330
|
+
automatic: true,
|
|
4552
5331
|
fallbackAction: "update_recommended",
|
|
4553
|
-
installedVersion: state.version
|
|
5332
|
+
installedVersion: state.kind === "managed" ? state.version : await legacyManagedVersion(target) ?? null
|
|
4554
5333
|
});
|
|
4555
5334
|
}
|
|
4556
5335
|
if (planned.length === 0) return void 0;
|
|
4557
5336
|
const completed = [...planned];
|
|
4558
5337
|
for (const [index, item] of planned.entries()) try {
|
|
5338
|
+
await prepareAction(item, false);
|
|
4559
5339
|
await applyAction(item);
|
|
4560
5340
|
completed[index] = item;
|
|
4561
|
-
} catch {
|
|
5341
|
+
} catch (error) {
|
|
4562
5342
|
completed[index] = {
|
|
5343
|
+
hint: error.message,
|
|
4563
5344
|
target: item.target,
|
|
4564
5345
|
action: "update_recommended",
|
|
4565
5346
|
...item.installedVersion !== void 0 ? { installedVersion: item.installedVersion } : {}
|
|
4566
5347
|
};
|
|
4567
5348
|
}
|
|
4568
|
-
return { targets: completed.map(({ target, action, installedVersion }) => ({
|
|
5349
|
+
return { targets: await Promise.all(completed.map(async ({ target, action, installedVersion, legacy, hint }) => ({
|
|
5350
|
+
...hint ? { hint } : {},
|
|
4569
5351
|
tool: target.tool,
|
|
4570
|
-
scope:
|
|
5352
|
+
scope: target.scope,
|
|
4571
5353
|
path: target.path,
|
|
4572
|
-
|
|
4573
|
-
|
|
5354
|
+
...identity(target),
|
|
5355
|
+
folder_path: dirname(target.path),
|
|
5356
|
+
...legacy ? { legacy_rule: legacy } : {},
|
|
5357
|
+
action: action === "update_recommended" ? "update_recommended" : "updated",
|
|
5358
|
+
installed_version: action === "update_recommended" ? installedVersion ?? null : installedVersion ?? bundled.version,
|
|
4574
5359
|
bundled_version: bundled.version,
|
|
4575
|
-
...action === "update_recommended" ?
|
|
4576
|
-
})) };
|
|
5360
|
+
...action === "update_recommended" ? await recoveryRecommendation(target, bundled) : {}
|
|
5361
|
+
}))) };
|
|
4577
5362
|
} catch {
|
|
4578
5363
|
return;
|
|
4579
5364
|
}
|
|
@@ -4586,7 +5371,7 @@ async function runSkillsList(parsed, mode) {
|
|
|
4586
5371
|
const bundled = await bundledOrFailure("skills list", mode);
|
|
4587
5372
|
if (!bundled) return;
|
|
4588
5373
|
const targets = [];
|
|
4589
|
-
for (const target of allTargets()) {
|
|
5374
|
+
for (const target of await groupTargets(allTargets())) {
|
|
4590
5375
|
if (!availableTarget(target)) {
|
|
4591
5376
|
targets.push({
|
|
4592
5377
|
...unavailableState(target),
|
|
@@ -4599,7 +5384,9 @@ async function runSkillsList(parsed, mode) {
|
|
|
4599
5384
|
tool: target.tool,
|
|
4600
5385
|
scope: target.scope,
|
|
4601
5386
|
path: target.path,
|
|
4602
|
-
|
|
5387
|
+
...identity(target),
|
|
5388
|
+
...await diagnostic(target, bundled),
|
|
5389
|
+
detected: (await Promise.all(aliases(target).map((alias) => isToolDetected(alias.tool, alias.scope)))).some(Boolean),
|
|
4603
5390
|
installed: state.kind !== "missing",
|
|
4604
5391
|
managed: state.kind === "managed",
|
|
4605
5392
|
installed_version: state.kind === "managed" ? state.version : null,
|
|
@@ -4614,7 +5401,7 @@ async function runSkillsList(parsed, mode) {
|
|
|
4614
5401
|
async function skillDiagnostics() {
|
|
4615
5402
|
const bundled = await loadBundledSkills();
|
|
4616
5403
|
const targets = [];
|
|
4617
|
-
for (const target of allTargets()) {
|
|
5404
|
+
for (const target of await groupTargets(allTargets())) {
|
|
4618
5405
|
if (!availableTarget(target)) {
|
|
4619
5406
|
targets.push({
|
|
4620
5407
|
...unavailableState(target),
|
|
@@ -4623,7 +5410,10 @@ async function skillDiagnostics() {
|
|
|
4623
5410
|
continue;
|
|
4624
5411
|
}
|
|
4625
5412
|
const state = await readTarget(target);
|
|
5413
|
+
const details = await diagnostic(target, bundled);
|
|
4626
5414
|
const updateAvailable = state.kind === "managed" && state.version !== bundled.version;
|
|
5415
|
+
const recommendation = await recoveryRecommendation(target, bundled);
|
|
5416
|
+
const recoveryCommand = recommendation.update_command ?? null;
|
|
4627
5417
|
targets.push({
|
|
4628
5418
|
tool: target.tool,
|
|
4629
5419
|
scope: target.scope,
|
|
@@ -4632,14 +5422,19 @@ async function skillDiagnostics() {
|
|
|
4632
5422
|
managed: state.kind === "managed",
|
|
4633
5423
|
installed_version: state.kind === "managed" ? state.version : null,
|
|
4634
5424
|
update_available: updateAvailable,
|
|
4635
|
-
|
|
5425
|
+
...identity(target),
|
|
5426
|
+
...details,
|
|
5427
|
+
...!recoveryCommand && recommendation.hint ? { hint: recommendation.hint } : {},
|
|
5428
|
+
update_command: details.hint ? null : updateAvailable || details.interrupted_update || state.kind === "managed" && !details.current ? recoveryCommand : null
|
|
4636
5429
|
});
|
|
4637
5430
|
}
|
|
4638
|
-
const updateTargets = targets.filter((target) => target.
|
|
5431
|
+
const updateTargets = targets.filter((target) => target.update_command !== null);
|
|
5432
|
+
const commonCommand = updateTargets[0]?.update_command?.replace(/ --tool \S+ --scope \S+/, "");
|
|
5433
|
+
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);
|
|
4639
5434
|
return {
|
|
4640
5435
|
bundled_version: bundled.version,
|
|
4641
|
-
update_available:
|
|
4642
|
-
update_command: updateTargets.length
|
|
5436
|
+
update_available: targets.some((target) => target.update_available),
|
|
5437
|
+
update_command: updateTargets.length === 0 ? null : canUpdateTogether && (updateTargets.length > 1 || !commonCommand?.includes(" --force")) ? commonCommand : updateTargets.map((target) => target.update_command).join(" && "),
|
|
4643
5438
|
targets
|
|
4644
5439
|
};
|
|
4645
5440
|
}
|
|
@@ -4653,21 +5448,35 @@ async function runSkillsUpdate(parsed, mode) {
|
|
|
4653
5448
|
const bundled = await bundledOrFailure(command, mode);
|
|
4654
5449
|
if (!bundled) return;
|
|
4655
5450
|
const planned = [];
|
|
4656
|
-
for (const target of filteredTargets(filters.tools, filters.scope)) {
|
|
5451
|
+
for (const target of await groupTargets(filteredTargets(filters.tools, filters.scope))) {
|
|
4657
5452
|
const state = await readTarget(target);
|
|
4658
|
-
if (state.kind === "broken") return writeFailure(command,
|
|
4659
|
-
if (state.kind === "missing")
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
5453
|
+
if (state.kind === "broken") return writeFailure(command, await conflictFor(target), mode, 1);
|
|
5454
|
+
if (state.kind === "missing") {
|
|
5455
|
+
if (state.hint) {
|
|
5456
|
+
planned.push({
|
|
5457
|
+
target,
|
|
5458
|
+
action: "not_installed",
|
|
5459
|
+
hint: state.hint
|
|
5460
|
+
});
|
|
5461
|
+
continue;
|
|
5462
|
+
}
|
|
5463
|
+
planned.push((await legacyRule(target))?.managed || (await diagnostic(target, bundled)).interrupted_update ? {
|
|
5464
|
+
target,
|
|
5465
|
+
action: "installed",
|
|
5466
|
+
content: bundled
|
|
5467
|
+
} : {
|
|
5468
|
+
target,
|
|
5469
|
+
action: "not_installed"
|
|
5470
|
+
});
|
|
5471
|
+
} else if (state.kind === "unmanaged") planned.push({
|
|
4664
5472
|
target,
|
|
4665
5473
|
action: "skipped_unmanaged"
|
|
4666
5474
|
});
|
|
4667
|
-
else if (
|
|
5475
|
+
else if (!await isCurrent(target, bundled) || force) planned.push({
|
|
4668
5476
|
target,
|
|
4669
5477
|
action: "updated",
|
|
4670
|
-
content:
|
|
5478
|
+
content: bundled,
|
|
5479
|
+
forceRetirement: force
|
|
4671
5480
|
});
|
|
4672
5481
|
else planned.push({
|
|
4673
5482
|
target,
|
|
@@ -4683,12 +5492,23 @@ async function runSkillsRemove(parsed, mode) {
|
|
|
4683
5492
|
const unavailable = unavailableSelection(filters.tools, filters.scope);
|
|
4684
5493
|
if (unavailable) return writeFailure(command, unavailable, mode, 1);
|
|
4685
5494
|
const planned = [];
|
|
4686
|
-
for (const target of filteredTargets(filters.tools, filters.scope)) {
|
|
5495
|
+
for (const target of await groupTargets(filteredTargets(filters.tools, filters.scope))) {
|
|
4687
5496
|
const state = await readTarget(target);
|
|
4688
|
-
|
|
5497
|
+
if (state.kind === "broken") return writeFailure(command, await conflictFor(target), mode, 1);
|
|
5498
|
+
if (state.kind === "missing" && state.hint) {
|
|
5499
|
+
planned.push({
|
|
5500
|
+
target,
|
|
5501
|
+
action: "not_installed",
|
|
5502
|
+
hint: state.hint
|
|
5503
|
+
});
|
|
5504
|
+
continue;
|
|
5505
|
+
}
|
|
5506
|
+
const managedLegacy = (await legacyRule(target))?.managed === true;
|
|
5507
|
+
const action = state.kind === "missing" ? managedLegacy || (await diagnostic(target, await loadBundledSkills())).interrupted_update ? "removed" : "not_installed" : state.kind === "managed" ? "removed" : "skipped_unmanaged";
|
|
4689
5508
|
planned.push({
|
|
4690
5509
|
target,
|
|
4691
|
-
action
|
|
5510
|
+
action,
|
|
5511
|
+
removeLegacy: true
|
|
4692
5512
|
});
|
|
4693
5513
|
}
|
|
4694
5514
|
await runActions(command, planned, parsed.options.dryRun === true, mode, unavailableActionTargets(filters.tools, filters.scope));
|
|
@@ -15873,13 +16693,14 @@ const skillsInstallDefinition = define({
|
|
|
15873
16693
|
force: {
|
|
15874
16694
|
type: "boolean",
|
|
15875
16695
|
toKebab: true,
|
|
15876
|
-
description: "
|
|
16696
|
+
description: "Take over bundled paths only; preserve user additions"
|
|
15877
16697
|
}
|
|
15878
16698
|
},
|
|
15879
16699
|
examples: `npm exec --yes --package=@artifactshare/cli -- artifactshare skills install --tool codex --scope project --json
|
|
15880
16700
|
npm exec --yes --package=@artifactshare/cli -- artifactshare skills install --tool claude --tool cursor --dry-run --json
|
|
15881
16701
|
|
|
15882
|
-
Writes
|
|
16702
|
+
Writes SKILL.md and bundled references into skills/artifactshare/ for every tool and scope.
|
|
16703
|
+
Project Cursor uses .cursor/skills/artifactshare/. A manifest tracks owned files.
|
|
15883
16704
|
Files without the Artifact Share managed marker are never overwritten without --force.
|
|
15884
16705
|
|
|
15885
16706
|
Claude Code user skills go to $CLAUDE_CONFIG_DIR/skills when set, otherwise
|
|
@@ -15889,7 +16710,7 @@ skip automatic writes. Set a non-empty path or unset CLAUDE_CONFIG_DIR.
|
|
|
15889
16710
|
Explicit Claude user installs reject blank values with validation_failed.
|
|
15890
16711
|
|
|
15891
16712
|
Common failures:
|
|
15892
|
-
validation_failed Pass --tool codex|claude|cursor;
|
|
16713
|
+
validation_failed Pass --tool codex|claude|cursor; all tools support --scope project or user
|
|
15893
16714
|
skill_update_conflict An unmanaged file exists at the target path; inspect it or pass --force`
|
|
15894
16715
|
});
|
|
15895
16716
|
const skillsListDefinition = define({
|
|
@@ -15899,7 +16720,9 @@ const skillsListDefinition = define({
|
|
|
15899
16720
|
args: commonArgs,
|
|
15900
16721
|
examples: `npm exec --yes --package=@artifactshare/cli -- artifactshare skills list --json
|
|
15901
16722
|
|
|
15902
|
-
Reports each tool and scope with detection,
|
|
16723
|
+
Reports each tool and scope with detection, version, completeness, missing/differing files,
|
|
16724
|
+
ownership metadata, and legacy Cursor rule coexistence. Shared folders appear once with aliases
|
|
16725
|
+
and resolved_folder_path; broken links include repair hints.
|
|
15903
16726
|
Runs locally; no network or authentication is used.`
|
|
15904
16727
|
});
|
|
15905
16728
|
const skillsUpdateDefinition = define({
|
|
@@ -15912,13 +16735,17 @@ const skillsUpdateDefinition = define({
|
|
|
15912
16735
|
force: {
|
|
15913
16736
|
type: "boolean",
|
|
15914
16737
|
toKebab: true,
|
|
15915
|
-
description: "Rewrite managed files
|
|
16738
|
+
description: "Rewrite managed folder files; never take over an unmanaged entry"
|
|
15916
16739
|
}
|
|
15917
16740
|
},
|
|
15918
16741
|
examples: `npm exec --yes --package=@artifactshare/cli -- artifactshare skills update --json
|
|
15919
16742
|
npm exec --yes --package=@artifactshare/cli -- artifactshare skills update --tool codex --scope user --json
|
|
15920
16743
|
|
|
15921
|
-
|
|
16744
|
+
Updates managed folders and repairs missing files. Edited owned files require --force; user additions are preserved.
|
|
16745
|
+
Folder and ancestor directory symlinks are resolved; internal links are refused even with --force.
|
|
16746
|
+
Shared folders are written once. JSON rows include aliases and resolved_folder_path.
|
|
16747
|
+
Real mutations clean reserved stale staging and UUID temporary files; dry runs do not.
|
|
16748
|
+
Managed legacy Cursor rules migrate after the new project folder is ready.
|
|
15922
16749
|
|
|
15923
16750
|
Common failures:
|
|
15924
16751
|
skill_update_conflict A managed marker is broken; inspect the file or reinstall with --force`
|
|
@@ -15944,7 +16771,8 @@ Use --tool auto from an agent workspace. It detects .claude, .codex/.agents, or
|
|
|
15944
16771
|
.cursor in the current directory, or the Claude user root when CLAUDE_CONFIG_DIR
|
|
15945
16772
|
is nonblank, and installs
|
|
15946
16773
|
or updates the matching user-scope skills. If none are present, it prepares user-scope Codex, Claude Code, and Cursor
|
|
15947
|
-
skills. Cursor project scope needs skills install --tool cursor --scope project
|
|
16774
|
+
skills. Cursor project scope needs skills install --tool cursor --scope project,
|
|
16775
|
+
except existing managed legacy Cursor rules migrate automatically.
|
|
15948
16776
|
|
|
15949
16777
|
Claude user skills use CLAUDE_CONFIG_DIR when set, otherwise ~/.claude.
|
|
15950
16778
|
Relative paths resolve against cwd; tilde is literal. Blank values skip automatic
|
|
@@ -15968,7 +16796,8 @@ const skillsRemoveDefinition = define({
|
|
|
15968
16796
|
examples: `npm exec --yes --package=@artifactshare/cli -- artifactshare skills remove --json
|
|
15969
16797
|
npm exec --yes --package=@artifactshare/cli -- artifactshare skills remove --tool cursor --json
|
|
15970
16798
|
|
|
15971
|
-
Only files
|
|
16799
|
+
Only manifest-owned files (or a legacy managed SKILL.md) are deleted; user files are preserved.
|
|
16800
|
+
Project Cursor removal also cleans managed legacy rules.`
|
|
15972
16801
|
});
|
|
15973
16802
|
const skillsDefinition = define({
|
|
15974
16803
|
name: "skills",
|
|
@@ -16012,7 +16841,7 @@ Without flags, init detects Claude Code, Codex, or Cursor in the working directo
|
|
|
16012
16841
|
installs or updates the bundled skill in user scope, and shows the next steps (sign
|
|
16013
16842
|
in, then share). With no agent detected, it prepares user-scope Codex, Claude Code,
|
|
16014
16843
|
and Cursor skills. Cursor project scope is not auto-installed; use skills install
|
|
16015
|
-
--tool cursor --scope project. Existing project-scope skills are not modified.
|
|
16844
|
+
--tool cursor --scope project. Existing project-scope skills are not modified, except managed legacy Cursor rules migrate to .cursor/skills/artifactshare/.
|
|
16016
16845
|
data.mode is "onboarding".
|
|
16017
16846
|
|
|
16018
16847
|
Claude Code user skills go to $CLAUDE_CONFIG_DIR/skills when set, otherwise
|