@artifactshare/cli 0.19.2 → 0.20.0
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 +7 -0
- package/README.md +32 -24
- package/dist/cli.js +538 -100
- package/package.json +1 -1
- package/skills/artifactshare/SKILL.md +86 -610
- package/skills/artifactshare/references/authentication-profiles-skills.md +72 -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,
|
|
9
|
+
import { chmod, lstat, mkdir, readFile, readdir, realpath, rename, 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,83 @@ 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 LocalSkillTargetSchema = z.object({
|
|
720
|
+
folder_path: z.string().nullable(),
|
|
721
|
+
complete: z.boolean(),
|
|
722
|
+
current: z.boolean(),
|
|
723
|
+
older_version: z.boolean(),
|
|
724
|
+
missing_files: z.array(z.string()),
|
|
725
|
+
different_files: z.array(z.string()),
|
|
726
|
+
modified_files: z.array(z.string()),
|
|
727
|
+
ownership_manifest: z.enum([
|
|
728
|
+
"valid",
|
|
729
|
+
"absent",
|
|
730
|
+
"invalid"
|
|
731
|
+
]),
|
|
732
|
+
legacy_rule: SkillLegacyDiagnosticSchema.optional()
|
|
733
|
+
}).extend({
|
|
734
|
+
tool: z.string(),
|
|
735
|
+
scope: z.string(),
|
|
736
|
+
path: z.string().nullable(),
|
|
737
|
+
available: z.boolean().optional(),
|
|
738
|
+
code: z.string().optional(),
|
|
739
|
+
hint: z.string().optional(),
|
|
740
|
+
installed: z.boolean(),
|
|
741
|
+
managed: z.boolean(),
|
|
742
|
+
installed_version: z.number().nullable(),
|
|
743
|
+
update_available: z.boolean()
|
|
744
|
+
});
|
|
745
|
+
z.object({
|
|
746
|
+
bundled_version: z.number(),
|
|
747
|
+
targets: z.array(LocalSkillTargetSchema.extend({ detected: z.boolean() }))
|
|
748
|
+
});
|
|
749
|
+
z.object({
|
|
750
|
+
bundled_version: z.number(),
|
|
751
|
+
update_available: z.boolean(),
|
|
752
|
+
update_command: z.string().nullable(),
|
|
753
|
+
targets: z.array(LocalSkillTargetSchema.extend({ update_command: z.string().nullable() }))
|
|
754
|
+
});
|
|
755
|
+
const SkillLegacyActionSchema = z.object({
|
|
756
|
+
path: z.string(),
|
|
757
|
+
action: z.enum([
|
|
758
|
+
"removed",
|
|
759
|
+
"would_remove",
|
|
760
|
+
"kept_unmanaged",
|
|
761
|
+
"remove_failed"
|
|
762
|
+
]),
|
|
763
|
+
hint: z.string().optional()
|
|
764
|
+
});
|
|
765
|
+
const SkillsActionTargetSchema = z.object({
|
|
766
|
+
tool: z.string(),
|
|
767
|
+
scope: z.string(),
|
|
768
|
+
path: z.string().nullable(),
|
|
769
|
+
folder_path: z.string().nullable(),
|
|
770
|
+
action: z.enum([
|
|
771
|
+
"installed",
|
|
772
|
+
"updated",
|
|
773
|
+
"update_recommended",
|
|
774
|
+
"unchanged",
|
|
775
|
+
"removed",
|
|
776
|
+
"not_installed",
|
|
777
|
+
"skipped_unmanaged",
|
|
778
|
+
"skipped"
|
|
779
|
+
]),
|
|
780
|
+
update_command: z.string().optional(),
|
|
781
|
+
code: z.string().optional(),
|
|
782
|
+
hint: z.string().optional(),
|
|
783
|
+
legacy_rule: SkillLegacyActionSchema.optional()
|
|
784
|
+
});
|
|
785
|
+
z.object({
|
|
786
|
+
dry_run: z.boolean(),
|
|
787
|
+
targets: z.array(SkillsActionTargetSchema)
|
|
788
|
+
});
|
|
711
789
|
//#endregion
|
|
712
790
|
//#region src/constants.ts
|
|
713
791
|
const DEFAULT_BASE_URL = "https://artifactshare.com";
|
|
@@ -1470,9 +1548,9 @@ function configHomeUnavailableError(profile) {
|
|
|
1470
1548
|
function skillUpdateConflictError(path) {
|
|
1471
1549
|
return cliError({
|
|
1472
1550
|
code: "skill_update_conflict",
|
|
1473
|
-
message: `The
|
|
1474
|
-
why: "Artifact Share
|
|
1475
|
-
hint: "Inspect the
|
|
1551
|
+
message: `The skill folder at ${path} has an ownership or path conflict.`,
|
|
1552
|
+
why: "Artifact Share requires a managed entry, valid ownership metadata, regular owned files, and no unowned path collisions.",
|
|
1553
|
+
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
1554
|
agentRecoverable: false,
|
|
1477
1555
|
requiresHuman: true,
|
|
1478
1556
|
recovery: { kind: "ask_human" },
|
|
@@ -4144,6 +4222,266 @@ async function runArtifactsList(parsed, mode) {
|
|
|
4144
4222
|
return writeSuccess(command, body, mode);
|
|
4145
4223
|
}
|
|
4146
4224
|
//#endregion
|
|
4225
|
+
//#region src/command-runners/skill-folder.ts
|
|
4226
|
+
const MANIFEST = ".artifactshare-managed.json";
|
|
4227
|
+
function managedState(content) {
|
|
4228
|
+
if (content === null) return { kind: "missing" };
|
|
4229
|
+
if (!content.includes("artifactshare-skill")) return { kind: "unmanaged" };
|
|
4230
|
+
const block = content.match(/<!--\s*artifactshare-skill([\s\S]*?)-->/)?.[1];
|
|
4231
|
+
const version = block?.match(/(?:^|\n)\s*version:\s*(\d+)\s*(?:\n|$)/)?.[1];
|
|
4232
|
+
if (version === void 0 || !/(?:^|\n)\s*managed:\s*true\s*(?:\n|$)/.test(block ?? "") || !Number.isSafeInteger(Number(version))) return { kind: "broken" };
|
|
4233
|
+
return {
|
|
4234
|
+
kind: "managed",
|
|
4235
|
+
version: Number(version)
|
|
4236
|
+
};
|
|
4237
|
+
}
|
|
4238
|
+
const hash = (text) => createHash("sha256").update(text).digest("hex");
|
|
4239
|
+
const validPath = (path) => (path === "SKILL.md" || path.startsWith("references/")) && !/[\\:]/.test(path) && path.split("/").every((part) => part !== "" && part !== "." && part !== "..");
|
|
4240
|
+
async function info(path) {
|
|
4241
|
+
try {
|
|
4242
|
+
return await lstat(path);
|
|
4243
|
+
} catch (error) {
|
|
4244
|
+
if (error.code === "ENOENT") return null;
|
|
4245
|
+
throw error;
|
|
4246
|
+
}
|
|
4247
|
+
}
|
|
4248
|
+
async function rootFor(entry) {
|
|
4249
|
+
const config = dirname(dirname(dirname(entry)));
|
|
4250
|
+
const root = await realpath(config).catch(() => config);
|
|
4251
|
+
return join(root, "skills", "artifactshare");
|
|
4252
|
+
}
|
|
4253
|
+
async function safe(root, relative, retiredAncestors = /* @__PURE__ */ new Set(), replacedDirectories = /* @__PURE__ */ new Set()) {
|
|
4254
|
+
const parts = [
|
|
4255
|
+
dirname(root),
|
|
4256
|
+
root,
|
|
4257
|
+
...relative.split("/").map((_, i, all) => join(root, ...all.slice(0, i + 1)))
|
|
4258
|
+
];
|
|
4259
|
+
for (let i = 0; i < parts.length; i++) {
|
|
4260
|
+
const item = await info(parts[i]);
|
|
4261
|
+
if (i < parts.length - 1 && item?.isFile() && retiredAncestors.has(parts[i])) return;
|
|
4262
|
+
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]}. Inspect the path and reinstall the skill.`);
|
|
4264
|
+
}
|
|
4265
|
+
}
|
|
4266
|
+
async function bytesAt(root, path) {
|
|
4267
|
+
await safe(root, path);
|
|
4268
|
+
return await readFile(join(root, path)).catch((error) => {
|
|
4269
|
+
if (error.code === "ENOENT") return null;
|
|
4270
|
+
throw error;
|
|
4271
|
+
});
|
|
4272
|
+
}
|
|
4273
|
+
async function textAt(root, path) {
|
|
4274
|
+
return (await bytesAt(root, path))?.toString("utf8") ?? null;
|
|
4275
|
+
}
|
|
4276
|
+
async function stateAt(root) {
|
|
4277
|
+
try {
|
|
4278
|
+
return managedState(await textAt(root, "SKILL.md"));
|
|
4279
|
+
} catch {
|
|
4280
|
+
return { kind: "broken" };
|
|
4281
|
+
}
|
|
4282
|
+
}
|
|
4283
|
+
async function readSkillState(entry) {
|
|
4284
|
+
return stateAt(await rootFor(entry));
|
|
4285
|
+
}
|
|
4286
|
+
async function loadSkillBundle(root) {
|
|
4287
|
+
const files = {};
|
|
4288
|
+
const visit = async (relative) => {
|
|
4289
|
+
const path = join(root, relative);
|
|
4290
|
+
const item = await info(path);
|
|
4291
|
+
if (!item) return;
|
|
4292
|
+
if (item.isDirectory()) for (const name of (await readdir(path)).sort()) await visit(`${relative}/${name}`);
|
|
4293
|
+
else if (item.isFile() && validPath(relative)) files[relative] = await readFile(path, "utf8");
|
|
4294
|
+
else throw new Error(`Invalid bundled skill path: ${relative}`);
|
|
4295
|
+
};
|
|
4296
|
+
await visit("SKILL.md");
|
|
4297
|
+
await visit("references");
|
|
4298
|
+
const state = managedState(files["SKILL.md"] ?? null);
|
|
4299
|
+
if (state.kind !== "managed") throw new Error("The bundled SKILL.md has a missing or invalid managed marker.");
|
|
4300
|
+
if (new Set(Object.keys(files).map((path) => path.toLowerCase())).size !== Object.keys(files).length) throw new Error("Colliding bundled skill paths.");
|
|
4301
|
+
return {
|
|
4302
|
+
files,
|
|
4303
|
+
version: state.version
|
|
4304
|
+
};
|
|
4305
|
+
}
|
|
4306
|
+
async function ownership(root, state) {
|
|
4307
|
+
try {
|
|
4308
|
+
const text = await textAt(root, MANIFEST);
|
|
4309
|
+
if (text === null) return { status: "absent" };
|
|
4310
|
+
const value = JSON.parse(text);
|
|
4311
|
+
if (state.kind !== "managed" || value.schema_version !== 1 || value.version !== state.version || !value.files || typeof value.files !== "object" || Array.isArray(value.files) || !Object.hasOwn(value.files, "SKILL.md")) return { status: "invalid" };
|
|
4312
|
+
const paths = Object.keys(value.files);
|
|
4313
|
+
if (new Set(paths.map((path) => path.toLowerCase())).size !== paths.length || !paths.every((path) => validPath(path) && typeof value.files[path] === "string" && /^[a-f0-9]{64}$/.test(value.files[path]))) return { status: "invalid" };
|
|
4314
|
+
return {
|
|
4315
|
+
status: "valid",
|
|
4316
|
+
manifest: value
|
|
4317
|
+
};
|
|
4318
|
+
} catch {
|
|
4319
|
+
return { status: "invalid" };
|
|
4320
|
+
}
|
|
4321
|
+
}
|
|
4322
|
+
async function folderDiagnostics(entry, bundle) {
|
|
4323
|
+
const root = await rootFor(entry);
|
|
4324
|
+
const state = await stateAt(root);
|
|
4325
|
+
const owned = await ownership(root, state);
|
|
4326
|
+
const missing_files = [], different_files = [], modified_files = [];
|
|
4327
|
+
for (const path of Object.keys(bundle.files).sort()) {
|
|
4328
|
+
const text = await bytesAt(root, path).catch(() => null);
|
|
4329
|
+
if (text === null) missing_files.push(path);
|
|
4330
|
+
else if (!text.equals(Buffer.from(bundle.files[path]))) different_files.push(path);
|
|
4331
|
+
}
|
|
4332
|
+
if (owned.manifest) for (const path of Object.keys(owned.manifest.files).sort()) {
|
|
4333
|
+
const text = await bytesAt(root, path).catch(() => null);
|
|
4334
|
+
if (text === null || hash(text) !== owned.manifest.files[path]) modified_files.push(path);
|
|
4335
|
+
}
|
|
4336
|
+
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
|
+
return {
|
|
4338
|
+
folder_path: dirname(entry),
|
|
4339
|
+
complete: missing_files.length === 0,
|
|
4340
|
+
current: state.kind === "managed" && state.version === bundle.version && !missing_files.length && !different_files.length && owned.status === "valid" && manifestMatches,
|
|
4341
|
+
older_version: state.kind === "managed" && state.version < bundle.version,
|
|
4342
|
+
missing_files,
|
|
4343
|
+
different_files,
|
|
4344
|
+
modified_files,
|
|
4345
|
+
ownership_manifest: owned.status
|
|
4346
|
+
};
|
|
4347
|
+
}
|
|
4348
|
+
async function preflightFolder(entry, bundle, force = false, forceRetirement = force) {
|
|
4349
|
+
const root = await rootFor(entry);
|
|
4350
|
+
const state = await stateAt(root);
|
|
4351
|
+
await safe(root, "SKILL.md");
|
|
4352
|
+
const owned = await ownership(root, state);
|
|
4353
|
+
if (owned.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.`);
|
|
4354
|
+
const previous = owned.manifest?.files ?? (state.kind === "managed" ? { "SKILL.md": "" } : {});
|
|
4355
|
+
await safe(root, MANIFEST);
|
|
4356
|
+
for (const path of Object.keys(previous)) await safe(root, path);
|
|
4357
|
+
if (!forceRetirement) for (const [path, expected] of Object.entries(previous)) {
|
|
4358
|
+
if (bundle && Object.hasOwn(bundle.files, path)) continue;
|
|
4359
|
+
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 or retiring this file, or reinstall with skills install --force.`);
|
|
4361
|
+
}
|
|
4362
|
+
const blockers = Object.keys(previous).filter((path) => bundle && !Object.hasOwn(bundle.files, path) && Object.keys(bundle.files).some((next) => next.startsWith(`${path}/`)));
|
|
4363
|
+
const retiredAncestors = new Set(blockers.map((path) => join(root, path)));
|
|
4364
|
+
const replacedDirectories = /* @__PURE__ */ new Set();
|
|
4365
|
+
const checkDirectory = async (relative) => {
|
|
4366
|
+
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.`);
|
|
4367
|
+
for (const name of await readdir(join(root, relative))) {
|
|
4368
|
+
const child = `${relative}/${name}`;
|
|
4369
|
+
const item = await info(join(root, child));
|
|
4370
|
+
if (item?.isDirectory()) await checkDirectory(child);
|
|
4371
|
+
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
|
+
}
|
|
4373
|
+
replacedDirectories.add(join(root, relative));
|
|
4374
|
+
};
|
|
4375
|
+
for (const path of Object.keys(bundle?.files ?? {})) {
|
|
4376
|
+
if (!blockers.some((ancestor) => path.startsWith(`${ancestor}/`))) {
|
|
4377
|
+
await safe(root, path, retiredAncestors, /* @__PURE__ */ new Set([join(root, path)]));
|
|
4378
|
+
if ((await info(join(root, path)))?.isDirectory()) await checkDirectory(path);
|
|
4379
|
+
}
|
|
4380
|
+
await safe(root, path, retiredAncestors, replacedDirectories);
|
|
4381
|
+
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.`);
|
|
4382
|
+
}
|
|
4383
|
+
return {
|
|
4384
|
+
root,
|
|
4385
|
+
previous,
|
|
4386
|
+
blockers,
|
|
4387
|
+
replacedDirectories
|
|
4388
|
+
};
|
|
4389
|
+
}
|
|
4390
|
+
async function prune(root, paths) {
|
|
4391
|
+
const dirs = /* @__PURE__ */ new Set();
|
|
4392
|
+
for (const path of paths) {
|
|
4393
|
+
let dir = dirname(join(root, path));
|
|
4394
|
+
while (dir.startsWith(root) && dir !== root) {
|
|
4395
|
+
dirs.add(dir);
|
|
4396
|
+
dir = dirname(dir);
|
|
4397
|
+
}
|
|
4398
|
+
}
|
|
4399
|
+
for (const dir of [...dirs].sort((a, b) => b.length - a.length)) await rmdir(dir).catch(() => {});
|
|
4400
|
+
}
|
|
4401
|
+
async function writeSkillFolder(entry, bundle, force = false, forceRetirement = force) {
|
|
4402
|
+
const { root, previous, blockers, replacedDirectories } = await preflightFolder(entry, bundle, force, forceRetirement);
|
|
4403
|
+
const files = {
|
|
4404
|
+
...bundle.files,
|
|
4405
|
+
[MANIFEST]: JSON.stringify({
|
|
4406
|
+
schema_version: 1,
|
|
4407
|
+
version: bundle.version,
|
|
4408
|
+
files: Object.fromEntries(Object.entries(bundle.files).map(([path, text]) => [path, hash(text)]))
|
|
4409
|
+
}, null, 2) + "\n"
|
|
4410
|
+
};
|
|
4411
|
+
const staged = /* @__PURE__ */ new Map();
|
|
4412
|
+
const backups = /* @__PURE__ */ new Map();
|
|
4413
|
+
const changed = /* @__PURE__ */ new Set();
|
|
4414
|
+
const createdDirectories = [];
|
|
4415
|
+
const removedDirectories = [];
|
|
4416
|
+
const ensureDirectory = async (path) => {
|
|
4417
|
+
if (await info(path)) return;
|
|
4418
|
+
await ensureDirectory(dirname(path));
|
|
4419
|
+
await mkdir(path);
|
|
4420
|
+
createdDirectories.push(path);
|
|
4421
|
+
};
|
|
4422
|
+
for (const path of /* @__PURE__ */ new Set([...Object.keys(previous), ...Object.keys(files)])) {
|
|
4423
|
+
const blocked = blockers.some((ancestor) => path.startsWith(`${ancestor}/`));
|
|
4424
|
+
backups.set(path, !blocked && (await info(join(root, path)))?.isFile() ? await readFile(join(root, path)) : null);
|
|
4425
|
+
}
|
|
4426
|
+
const retire = async (path) => {
|
|
4427
|
+
if (backups.get(path) !== null) {
|
|
4428
|
+
await unlink(join(root, path));
|
|
4429
|
+
changed.add(path);
|
|
4430
|
+
}
|
|
4431
|
+
};
|
|
4432
|
+
const commit = async (path) => {
|
|
4433
|
+
await ensureDirectory(dirname(join(root, path)));
|
|
4434
|
+
await rename(staged.get(path), join(root, path));
|
|
4435
|
+
changed.add(path);
|
|
4436
|
+
};
|
|
4437
|
+
try {
|
|
4438
|
+
for (const [path, text] of Object.entries(files)) {
|
|
4439
|
+
const blocker = blockers.find((ancestor) => path.startsWith(`${ancestor}/`));
|
|
4440
|
+
const stagingDir = dirname(join(root, blocker ?? path));
|
|
4441
|
+
await ensureDirectory(stagingDir);
|
|
4442
|
+
const temp = join(stagingDir, `.artifactshare-${randomUUID()}.tmp`);
|
|
4443
|
+
staged.set(path, temp);
|
|
4444
|
+
await writeFile(temp, text, { flag: "wx" });
|
|
4445
|
+
}
|
|
4446
|
+
const retired = Object.keys(previous).filter((path) => !Object.hasOwn(bundle.files, path));
|
|
4447
|
+
const earlyRetired = new Set(retired.filter((path) => blockers.includes(path) || [...replacedDirectories].some((dir) => join(root, path).startsWith(`${dir}${sep}`))));
|
|
4448
|
+
for (const path of earlyRetired) await retire(path);
|
|
4449
|
+
for (const dir of [...replacedDirectories].sort((a, b) => b.length - a.length)) {
|
|
4450
|
+
await rmdir(dir);
|
|
4451
|
+
removedDirectories.push(dir);
|
|
4452
|
+
}
|
|
4453
|
+
for (const path of Object.keys(bundle.files).filter((relative) => relative !== "SKILL.md").sort()) await commit(path);
|
|
4454
|
+
for (const path of retired) if (!earlyRetired.has(path)) await retire(path);
|
|
4455
|
+
await commit(MANIFEST);
|
|
4456
|
+
await commit("SKILL.md");
|
|
4457
|
+
await prune(root, retired);
|
|
4458
|
+
} catch (error) {
|
|
4459
|
+
for (const path of [...changed].reverse()) if ((await info(join(root, path)))?.isFile()) await unlink(join(root, path));
|
|
4460
|
+
for (const dir of [...createdDirectories].reverse()) await rmdir(dir).catch(() => {});
|
|
4461
|
+
for (const dir of removedDirectories.reverse()) await mkdir(dir, { recursive: true });
|
|
4462
|
+
for (const path of changed) {
|
|
4463
|
+
const bytes = backups.get(path);
|
|
4464
|
+
if (bytes !== null && bytes !== void 0) {
|
|
4465
|
+
await mkdir(dirname(join(root, path)), { recursive: true });
|
|
4466
|
+
await writeFile(join(root, path), bytes);
|
|
4467
|
+
}
|
|
4468
|
+
}
|
|
4469
|
+
throw error;
|
|
4470
|
+
} finally {
|
|
4471
|
+
for (const path of staged.values()) await unlink(path).catch(() => {});
|
|
4472
|
+
for (const dir of [...createdDirectories].reverse()) await rmdir(dir).catch(() => {});
|
|
4473
|
+
}
|
|
4474
|
+
}
|
|
4475
|
+
async function removeSkillFolder(entry) {
|
|
4476
|
+
const { root, previous } = await preflightFolder(entry);
|
|
4477
|
+
for (const path of [...Object.keys(previous), MANIFEST]) await unlink(join(root, path)).catch((error) => {
|
|
4478
|
+
if (error.code !== "ENOENT") throw error;
|
|
4479
|
+
});
|
|
4480
|
+
await prune(root, Object.keys(previous));
|
|
4481
|
+
await rmdir(root).catch(() => {});
|
|
4482
|
+
await rmdir(dirname(root)).catch(() => {});
|
|
4483
|
+
}
|
|
4484
|
+
//#endregion
|
|
4147
4485
|
//#region src/command-runners/skills.ts
|
|
4148
4486
|
const SKILL_TOOLS = [
|
|
4149
4487
|
"codex",
|
|
@@ -4165,22 +4503,9 @@ const TOOL_CONFIG = {
|
|
|
4165
4503
|
detectDirs: [".cursor"]
|
|
4166
4504
|
}
|
|
4167
4505
|
};
|
|
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
|
-
}
|
|
4506
|
+
function scopeTargetConfig(tool, _scope) {
|
|
4181
4507
|
return {
|
|
4182
|
-
relativePath: join(tool === "codex" ? ".agents" : ".claude", SKILL_FILE_PATH),
|
|
4183
|
-
bundledFile: "SKILL.md",
|
|
4508
|
+
relativePath: join(tool === "codex" ? ".agents" : tool === "cursor" ? ".cursor" : ".claude", SKILL_FILE_PATH),
|
|
4184
4509
|
pruneDirs: ["artifactshare", "skills"]
|
|
4185
4510
|
};
|
|
4186
4511
|
}
|
|
@@ -4213,7 +4538,15 @@ function unavailableState(target) {
|
|
|
4213
4538
|
installed: false,
|
|
4214
4539
|
managed: false,
|
|
4215
4540
|
installed_version: null,
|
|
4216
|
-
update_available: false
|
|
4541
|
+
update_available: false,
|
|
4542
|
+
folder_path: null,
|
|
4543
|
+
complete: false,
|
|
4544
|
+
current: false,
|
|
4545
|
+
older_version: false,
|
|
4546
|
+
missing_files: [],
|
|
4547
|
+
different_files: [],
|
|
4548
|
+
modified_files: [],
|
|
4549
|
+
ownership_manifest: "absent"
|
|
4217
4550
|
};
|
|
4218
4551
|
}
|
|
4219
4552
|
function unavailableActionTargets(tools, scope) {
|
|
@@ -4250,44 +4583,47 @@ function skillTarget(tool, scope) {
|
|
|
4250
4583
|
absolutePath: resolve(path)
|
|
4251
4584
|
};
|
|
4252
4585
|
}
|
|
4253
|
-
function bundledContentForTarget(bundled, target) {
|
|
4254
|
-
const file = scopeTargetConfig(target.tool, target.scope).bundledFile;
|
|
4255
|
-
return bundled.contentsByFile[file];
|
|
4256
|
-
}
|
|
4257
4586
|
function allTargets() {
|
|
4258
4587
|
return SKILL_TOOLS.flatMap((tool) => TOOL_CONFIG[tool].scopes.map((scope) => skillTarget(tool, scope)));
|
|
4259
4588
|
}
|
|
4260
|
-
function
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4589
|
+
function readTarget(target) {
|
|
4590
|
+
return readSkillState(target.absolutePath);
|
|
4591
|
+
}
|
|
4592
|
+
function loadBundledSkills() {
|
|
4593
|
+
return loadSkillBundle(fileURLToPath(new URL("../skills/artifactshare/", import.meta.url)));
|
|
4594
|
+
}
|
|
4595
|
+
async function legacyRule(target) {
|
|
4596
|
+
if (target.tool !== "cursor" || target.scope !== "project") return void 0;
|
|
4597
|
+
const path = join(".cursor", "rules", "artifactshare.mdc");
|
|
4598
|
+
const info = await lstat(path).catch(() => null);
|
|
4599
|
+
const parent = await lstat(dirname(path)).catch(() => null);
|
|
4600
|
+
const content = info?.isFile() && !parent?.isSymbolicLink() ? await readFile(path, "utf8").catch(() => null) : null;
|
|
4601
|
+
const present = info !== null;
|
|
4602
|
+
const managed = managedState(content).kind === "managed";
|
|
4267
4603
|
return {
|
|
4268
|
-
|
|
4269
|
-
|
|
4604
|
+
path,
|
|
4605
|
+
present,
|
|
4606
|
+
managed,
|
|
4607
|
+
coexistence: present && await lstat(target.absolutePath).catch(() => null) !== null,
|
|
4608
|
+
hint: present && !managed ? "Inspect the legacy Cursor rule and manually remove it if the skill folder replaces it." : null
|
|
4270
4609
|
};
|
|
4271
4610
|
}
|
|
4272
|
-
async function
|
|
4273
|
-
|
|
4611
|
+
async function legacyManagedVersion(target) {
|
|
4612
|
+
const legacy = await legacyRule(target);
|
|
4613
|
+
if (!legacy?.managed) return void 0;
|
|
4614
|
+
const state = managedState(await readFile(legacy.path, "utf8"));
|
|
4615
|
+
return state.kind === "managed" ? state.version : void 0;
|
|
4274
4616
|
}
|
|
4275
|
-
async function
|
|
4276
|
-
const contentsByFile = {};
|
|
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
|
-
}
|
|
4617
|
+
async function diagnostic(target, bundle) {
|
|
4286
4618
|
return {
|
|
4287
|
-
|
|
4288
|
-
|
|
4619
|
+
...await folderDiagnostics(target.absolutePath, bundle),
|
|
4620
|
+
folder_path: dirname(target.path),
|
|
4621
|
+
...target.tool === "cursor" && target.scope === "project" ? { legacy_rule: await legacyRule(target) } : {}
|
|
4289
4622
|
};
|
|
4290
4623
|
}
|
|
4624
|
+
async function isCurrent(target, bundle) {
|
|
4625
|
+
return (await folderDiagnostics(target.absolutePath, bundle)).current;
|
|
4626
|
+
}
|
|
4291
4627
|
function parseTools(value, options = {}) {
|
|
4292
4628
|
const raws = arrayOption(value);
|
|
4293
4629
|
const tools = [];
|
|
@@ -4379,35 +4715,65 @@ async function autoTargets(scope) {
|
|
|
4379
4715
|
function targetPathKey(target) {
|
|
4380
4716
|
return realpath(target.absolutePath).catch(() => target.absolutePath);
|
|
4381
4717
|
}
|
|
4382
|
-
async function
|
|
4383
|
-
if (content
|
|
4384
|
-
|
|
4385
|
-
|
|
4718
|
+
async function prepareAction(item, dryRun) {
|
|
4719
|
+
if (item.content) {
|
|
4720
|
+
if (item.automatic) {
|
|
4721
|
+
const details = await diagnostic(item.target, item.content);
|
|
4722
|
+
if (details.modified_files.length) throw new Error(`Modified skill files: ${details.modified_files.join(", ")}`);
|
|
4723
|
+
}
|
|
4724
|
+
await preflightFolder(item.target.absolutePath, item.content, item.force, item.forceRetirement);
|
|
4725
|
+
}
|
|
4726
|
+
if (item.action === "removed") await preflightFolder(item.target.absolutePath);
|
|
4727
|
+
const legacy = await legacyRule(item.target);
|
|
4728
|
+
if (legacy?.managed && item.action === "unchanged" && !await isCurrent(item.target, await loadBundledSkills())) {
|
|
4729
|
+
item.action = "update_recommended";
|
|
4386
4730
|
return;
|
|
4387
4731
|
}
|
|
4388
|
-
if (
|
|
4389
|
-
|
|
4390
|
-
|
|
4732
|
+
if (legacy?.present) {
|
|
4733
|
+
if (!legacy.managed) item.legacy = {
|
|
4734
|
+
path: legacy.path,
|
|
4735
|
+
action: "kept_unmanaged",
|
|
4736
|
+
hint: legacy.hint ?? "Inspect the legacy rule."
|
|
4737
|
+
};
|
|
4738
|
+
else if (item.content || item.action === "unchanged" || item.action === "removed" || item.action === "not_installed" || item.removeLegacy) item.legacy = {
|
|
4739
|
+
path: legacy.path,
|
|
4740
|
+
action: dryRun ? "would_remove" : "removed"
|
|
4741
|
+
};
|
|
4391
4742
|
}
|
|
4392
4743
|
}
|
|
4393
|
-
async function
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4744
|
+
async function applyAction(item) {
|
|
4745
|
+
if (item.content) await writeSkillFolder(item.target.absolutePath, item.content, item.force, item.forceRetirement);
|
|
4746
|
+
if (item.action === "removed") await removeSkillFolder(item.target.absolutePath);
|
|
4747
|
+
if (item.legacy?.action === "removed") try {
|
|
4748
|
+
await unlink(item.legacy.path);
|
|
4749
|
+
} catch {
|
|
4750
|
+
item.legacy = {
|
|
4751
|
+
path: item.legacy.path,
|
|
4752
|
+
action: "remove_failed",
|
|
4753
|
+
hint: "Retry skills update --tool cursor --scope project --json to remove the legacy rule."
|
|
4754
|
+
};
|
|
4403
4755
|
}
|
|
4404
4756
|
}
|
|
4405
4757
|
function skillUpdateCommand(target) {
|
|
4406
4758
|
return `${CLI_INVOCATION} skills update --tool ${target.tool} --scope ${target.scope} --json`;
|
|
4407
4759
|
}
|
|
4408
4760
|
async function finishActions(command, planned, dryRun, mode) {
|
|
4761
|
+
for (const item of planned) try {
|
|
4762
|
+
await prepareAction(item, dryRun);
|
|
4763
|
+
} catch (error) {
|
|
4764
|
+
if (item.fallbackAction) {
|
|
4765
|
+
item.action = item.fallbackAction;
|
|
4766
|
+
delete item.content;
|
|
4767
|
+
continue;
|
|
4768
|
+
}
|
|
4769
|
+
const conflict = skillUpdateConflictError(item.target.path);
|
|
4770
|
+
if (error instanceof Error) conflict.hint = error.message;
|
|
4771
|
+
writeFailure(command, conflict, mode, 1);
|
|
4772
|
+
return;
|
|
4773
|
+
}
|
|
4409
4774
|
const completed = [...planned];
|
|
4410
4775
|
if (!dryRun) for (const [index, item] of planned.entries()) try {
|
|
4776
|
+
await prepareAction(item, false);
|
|
4411
4777
|
await applyAction(item);
|
|
4412
4778
|
completed[index] = item;
|
|
4413
4779
|
} catch (error) {
|
|
@@ -4423,10 +4789,12 @@ async function finishActions(command, planned, dryRun, mode) {
|
|
|
4423
4789
|
}
|
|
4424
4790
|
return {
|
|
4425
4791
|
dry_run: dryRun,
|
|
4426
|
-
targets: completed.map(({ target, action }) => ({
|
|
4792
|
+
targets: completed.map(({ target, action, legacy }) => ({
|
|
4427
4793
|
tool: target.tool,
|
|
4428
4794
|
scope: target.scope,
|
|
4429
4795
|
path: target.path,
|
|
4796
|
+
folder_path: dirname(target.path),
|
|
4797
|
+
...legacy ? { legacy_rule: legacy } : {},
|
|
4430
4798
|
action,
|
|
4431
4799
|
...action === "update_recommended" ? { update_command: skillUpdateCommand(target) } : {}
|
|
4432
4800
|
}))
|
|
@@ -4439,6 +4807,7 @@ async function runActions(command, planned, dryRun, mode, unavailableTargets = [
|
|
|
4439
4807
|
tool: target.tool,
|
|
4440
4808
|
scope: target.scope,
|
|
4441
4809
|
path: null,
|
|
4810
|
+
folder_path: null,
|
|
4442
4811
|
action: "skipped",
|
|
4443
4812
|
code: target.error.code,
|
|
4444
4813
|
hint: target.error.hint
|
|
@@ -4470,7 +4839,7 @@ async function runSkillsInstall(parsed, mode) {
|
|
|
4470
4839
|
if (!availableTarget(target)) return writeFailure(command, target.error, mode, 1);
|
|
4471
4840
|
const state = await readTarget(target);
|
|
4472
4841
|
if ((state.kind === "unmanaged" || state.kind === "broken") && !force) return writeFailure(command, skillUpdateConflictError(target.path), mode, 1);
|
|
4473
|
-
if (state.kind === "managed" &&
|
|
4842
|
+
if (state.kind === "managed" && await isCurrent(target, bundled) && !force) {
|
|
4474
4843
|
planned.push({
|
|
4475
4844
|
target,
|
|
4476
4845
|
action: "unchanged"
|
|
@@ -4480,7 +4849,8 @@ async function runSkillsInstall(parsed, mode) {
|
|
|
4480
4849
|
planned.push({
|
|
4481
4850
|
target,
|
|
4482
4851
|
action: state.kind === "missing" ? "installed" : "updated",
|
|
4483
|
-
content:
|
|
4852
|
+
content: bundled,
|
|
4853
|
+
force
|
|
4484
4854
|
});
|
|
4485
4855
|
}
|
|
4486
4856
|
await runActions(command, planned, parsed.options.dryRun === true, mode);
|
|
@@ -4512,50 +4882,94 @@ async function ensureSkills(parsed, mode, options = {}) {
|
|
|
4512
4882
|
writeFailure(command, skillUpdateConflictError(target.path), mode, 1);
|
|
4513
4883
|
return;
|
|
4514
4884
|
}
|
|
4515
|
-
const
|
|
4885
|
+
const automaticUpdate = filters.auto || options.command === "init" || options.command === "open";
|
|
4886
|
+
if (automaticUpdate && state.kind === "managed" && state.version > bundled.version) continue;
|
|
4887
|
+
const details = await diagnostic(target, bundled);
|
|
4888
|
+
if (automaticUpdate && state.kind === "managed" && details.modified_files.length) {
|
|
4889
|
+
planned.push({
|
|
4890
|
+
target,
|
|
4891
|
+
action: "update_recommended"
|
|
4892
|
+
});
|
|
4893
|
+
continue;
|
|
4894
|
+
}
|
|
4895
|
+
const unchanged = state.kind === "managed" && (state.version >= bundled.version && automaticUpdate || state.version > bundled.version || details.current);
|
|
4516
4896
|
planned.push(unchanged ? {
|
|
4517
4897
|
target,
|
|
4518
4898
|
action: "unchanged"
|
|
4519
4899
|
} : {
|
|
4520
4900
|
target,
|
|
4521
4901
|
action: state.kind === "missing" ? "installed" : "updated",
|
|
4522
|
-
content:
|
|
4902
|
+
content: bundled,
|
|
4903
|
+
automatic: automaticUpdate,
|
|
4904
|
+
...automaticUpdate ? { fallbackAction: "update_recommended" } : {}
|
|
4523
4905
|
});
|
|
4524
4906
|
}
|
|
4525
|
-
if (options.autoUpdateUserManaged) {
|
|
4907
|
+
if (options.autoUpdateUserManaged || filters.auto) {
|
|
4526
4908
|
const plannedPaths = new Set(await Promise.all(planned.map((action) => targetPathKey(action.target))));
|
|
4527
|
-
for (const target of
|
|
4909
|
+
for (const target of await automaticTargets(bundled)) {
|
|
4528
4910
|
if (plannedPaths.has(await targetPathKey(target))) continue;
|
|
4529
4911
|
const state = await readTarget(target);
|
|
4530
|
-
if (state.kind
|
|
4912
|
+
if (state.kind === "managed" && state.version > bundled.version) continue;
|
|
4913
|
+
const details = await diagnostic(target, bundled);
|
|
4914
|
+
if (state.kind === "managed" && details.modified_files.length) {
|
|
4915
|
+
planned.push({
|
|
4916
|
+
target,
|
|
4917
|
+
action: "update_recommended",
|
|
4918
|
+
installedVersion: state.version
|
|
4919
|
+
});
|
|
4920
|
+
continue;
|
|
4921
|
+
}
|
|
4922
|
+
if (target.scope !== "project" && (state.kind !== "managed" || state.version >= bundled.version || await isCurrent(target, bundled))) continue;
|
|
4531
4923
|
planned.push({
|
|
4532
4924
|
target,
|
|
4533
|
-
action: "updated",
|
|
4534
|
-
content:
|
|
4925
|
+
action: state.kind === "managed" && state.version >= bundled.version ? "unchanged" : "updated",
|
|
4926
|
+
...state.kind === "managed" && state.version >= bundled.version ? {} : { content: bundled },
|
|
4927
|
+
automatic: true,
|
|
4535
4928
|
fallbackAction: "update_recommended"
|
|
4536
4929
|
});
|
|
4537
4930
|
}
|
|
4538
4931
|
}
|
|
4539
4932
|
return finishActions(command, planned, parsed.options.dryRun === true, mode);
|
|
4540
4933
|
}
|
|
4934
|
+
async function automaticTargets(bundled) {
|
|
4935
|
+
const targets = allTargets().filter(availableTarget).filter((target) => target.scope === "user");
|
|
4936
|
+
const project = skillTarget("cursor", "project");
|
|
4937
|
+
if (availableTarget(project)) {
|
|
4938
|
+
const version = await legacyManagedVersion(project);
|
|
4939
|
+
if (version !== void 0 && version <= bundled.version) targets.push(project);
|
|
4940
|
+
}
|
|
4941
|
+
return targets;
|
|
4942
|
+
}
|
|
4541
4943
|
async function autoUpdateUserManagedSkills() {
|
|
4542
4944
|
try {
|
|
4543
4945
|
const bundled = await loadBundledSkills();
|
|
4544
4946
|
const planned = [];
|
|
4545
|
-
for (const target of
|
|
4947
|
+
for (const target of await automaticTargets(bundled)) {
|
|
4546
4948
|
const state = await readTarget(target);
|
|
4547
|
-
if (state.kind
|
|
4949
|
+
if (state.kind === "managed" && state.version > bundled.version) continue;
|
|
4950
|
+
const details = await diagnostic(target, bundled);
|
|
4951
|
+
if (state.kind === "managed" && details.modified_files.length) {
|
|
4952
|
+
planned.push({
|
|
4953
|
+
target,
|
|
4954
|
+
action: "update_recommended",
|
|
4955
|
+
installedVersion: state.version
|
|
4956
|
+
});
|
|
4957
|
+
continue;
|
|
4958
|
+
}
|
|
4959
|
+
if (target.scope !== "project" && (state.kind !== "managed" || state.version >= bundled.version || await isCurrent(target, bundled))) continue;
|
|
4548
4960
|
planned.push({
|
|
4549
4961
|
target,
|
|
4550
|
-
action: "updated",
|
|
4551
|
-
content:
|
|
4962
|
+
action: state.kind === "managed" && state.version >= bundled.version ? "unchanged" : "updated",
|
|
4963
|
+
...state.kind === "managed" && state.version >= bundled.version ? {} : { content: bundled },
|
|
4964
|
+
automatic: true,
|
|
4552
4965
|
fallbackAction: "update_recommended",
|
|
4553
|
-
installedVersion: state.version
|
|
4966
|
+
installedVersion: state.kind === "managed" ? state.version : await legacyManagedVersion(target) ?? bundled.version
|
|
4554
4967
|
});
|
|
4555
4968
|
}
|
|
4556
4969
|
if (planned.length === 0) return void 0;
|
|
4557
4970
|
const completed = [...planned];
|
|
4558
4971
|
for (const [index, item] of planned.entries()) try {
|
|
4972
|
+
await prepareAction(item, false);
|
|
4559
4973
|
await applyAction(item);
|
|
4560
4974
|
completed[index] = item;
|
|
4561
4975
|
} catch {
|
|
@@ -4565,11 +4979,13 @@ async function autoUpdateUserManagedSkills() {
|
|
|
4565
4979
|
...item.installedVersion !== void 0 ? { installedVersion: item.installedVersion } : {}
|
|
4566
4980
|
};
|
|
4567
4981
|
}
|
|
4568
|
-
return { targets: completed.map(({ target, action, installedVersion }) => ({
|
|
4982
|
+
return { targets: completed.map(({ target, action, installedVersion, legacy }) => ({
|
|
4569
4983
|
tool: target.tool,
|
|
4570
|
-
scope:
|
|
4984
|
+
scope: target.scope,
|
|
4571
4985
|
path: target.path,
|
|
4572
|
-
|
|
4986
|
+
folder_path: dirname(target.path),
|
|
4987
|
+
...legacy ? { legacy_rule: legacy } : {},
|
|
4988
|
+
action: action === "update_recommended" ? "update_recommended" : "updated",
|
|
4573
4989
|
installed_version: installedVersion ?? bundled.version,
|
|
4574
4990
|
bundled_version: bundled.version,
|
|
4575
4991
|
...action === "update_recommended" ? { update_command: skillUpdateCommand(target) } : {}
|
|
@@ -4599,6 +5015,7 @@ async function runSkillsList(parsed, mode) {
|
|
|
4599
5015
|
tool: target.tool,
|
|
4600
5016
|
scope: target.scope,
|
|
4601
5017
|
path: target.path,
|
|
5018
|
+
...await diagnostic(target, bundled),
|
|
4602
5019
|
detected: await isToolDetected(target.tool, target.scope),
|
|
4603
5020
|
installed: state.kind !== "missing",
|
|
4604
5021
|
managed: state.kind === "managed",
|
|
@@ -4623,7 +5040,14 @@ async function skillDiagnostics() {
|
|
|
4623
5040
|
continue;
|
|
4624
5041
|
}
|
|
4625
5042
|
const state = await readTarget(target);
|
|
5043
|
+
const details = await diagnostic(target, bundled);
|
|
4626
5044
|
const updateAvailable = state.kind === "managed" && state.version !== bundled.version;
|
|
5045
|
+
let recoveryCommand = skillUpdateCommand(target);
|
|
5046
|
+
if (state.kind === "managed" && !details.current) try {
|
|
5047
|
+
await preflightFolder(target.absolutePath, bundled);
|
|
5048
|
+
} catch {
|
|
5049
|
+
recoveryCommand = `${CLI_INVOCATION} skills install --tool ${target.tool} --scope ${target.scope} --force --json`;
|
|
5050
|
+
}
|
|
4627
5051
|
targets.push({
|
|
4628
5052
|
tool: target.tool,
|
|
4629
5053
|
scope: target.scope,
|
|
@@ -4632,13 +5056,14 @@ async function skillDiagnostics() {
|
|
|
4632
5056
|
managed: state.kind === "managed",
|
|
4633
5057
|
installed_version: state.kind === "managed" ? state.version : null,
|
|
4634
5058
|
update_available: updateAvailable,
|
|
4635
|
-
|
|
5059
|
+
...details,
|
|
5060
|
+
update_command: updateAvailable || state.kind === "managed" && !details.current ? recoveryCommand : null
|
|
4636
5061
|
});
|
|
4637
5062
|
}
|
|
4638
|
-
const updateTargets = targets.filter((target) => target.
|
|
5063
|
+
const updateTargets = targets.filter((target) => target.update_command !== null);
|
|
4639
5064
|
return {
|
|
4640
5065
|
bundled_version: bundled.version,
|
|
4641
|
-
update_available:
|
|
5066
|
+
update_available: targets.some((target) => target.update_available),
|
|
4642
5067
|
update_command: updateTargets.length > 0 ? `${CLI_INVOCATION} skills update --json` : null,
|
|
4643
5068
|
targets
|
|
4644
5069
|
};
|
|
@@ -4656,7 +5081,11 @@ async function runSkillsUpdate(parsed, mode) {
|
|
|
4656
5081
|
for (const target of filteredTargets(filters.tools, filters.scope)) {
|
|
4657
5082
|
const state = await readTarget(target);
|
|
4658
5083
|
if (state.kind === "broken") return writeFailure(command, skillUpdateConflictError(target.path), mode, 1);
|
|
4659
|
-
if (state.kind === "missing") planned.push({
|
|
5084
|
+
if (state.kind === "missing") planned.push((await legacyRule(target))?.managed ? {
|
|
5085
|
+
target,
|
|
5086
|
+
action: "installed",
|
|
5087
|
+
content: bundled
|
|
5088
|
+
} : {
|
|
4660
5089
|
target,
|
|
4661
5090
|
action: "not_installed"
|
|
4662
5091
|
});
|
|
@@ -4664,10 +5093,11 @@ async function runSkillsUpdate(parsed, mode) {
|
|
|
4664
5093
|
target,
|
|
4665
5094
|
action: "skipped_unmanaged"
|
|
4666
5095
|
});
|
|
4667
|
-
else if (
|
|
5096
|
+
else if (!await isCurrent(target, bundled) || force) planned.push({
|
|
4668
5097
|
target,
|
|
4669
5098
|
action: "updated",
|
|
4670
|
-
content:
|
|
5099
|
+
content: bundled,
|
|
5100
|
+
forceRetirement: force
|
|
4671
5101
|
});
|
|
4672
5102
|
else planned.push({
|
|
4673
5103
|
target,
|
|
@@ -4685,10 +5115,13 @@ async function runSkillsRemove(parsed, mode) {
|
|
|
4685
5115
|
const planned = [];
|
|
4686
5116
|
for (const target of filteredTargets(filters.tools, filters.scope)) {
|
|
4687
5117
|
const state = await readTarget(target);
|
|
4688
|
-
|
|
5118
|
+
if (state.kind === "broken") return writeFailure(command, skillUpdateConflictError(target.path), mode, 1);
|
|
5119
|
+
const managedLegacy = (await legacyRule(target))?.managed === true;
|
|
5120
|
+
const action = state.kind === "missing" ? managedLegacy ? "removed" : "not_installed" : state.kind === "managed" ? "removed" : "skipped_unmanaged";
|
|
4689
5121
|
planned.push({
|
|
4690
5122
|
target,
|
|
4691
|
-
action
|
|
5123
|
+
action,
|
|
5124
|
+
removeLegacy: true
|
|
4692
5125
|
});
|
|
4693
5126
|
}
|
|
4694
5127
|
await runActions(command, planned, parsed.options.dryRun === true, mode, unavailableActionTargets(filters.tools, filters.scope));
|
|
@@ -15873,13 +16306,14 @@ const skillsInstallDefinition = define({
|
|
|
15873
16306
|
force: {
|
|
15874
16307
|
type: "boolean",
|
|
15875
16308
|
toKebab: true,
|
|
15876
|
-
description: "
|
|
16309
|
+
description: "Take over bundled paths only; preserve user additions"
|
|
15877
16310
|
}
|
|
15878
16311
|
},
|
|
15879
16312
|
examples: `npm exec --yes --package=@artifactshare/cli -- artifactshare skills install --tool codex --scope project --json
|
|
15880
16313
|
npm exec --yes --package=@artifactshare/cli -- artifactshare skills install --tool claude --tool cursor --dry-run --json
|
|
15881
16314
|
|
|
15882
|
-
Writes
|
|
16315
|
+
Writes SKILL.md and bundled references into skills/artifactshare/ for every tool and scope.
|
|
16316
|
+
Project Cursor uses .cursor/skills/artifactshare/. A manifest tracks owned files.
|
|
15883
16317
|
Files without the Artifact Share managed marker are never overwritten without --force.
|
|
15884
16318
|
|
|
15885
16319
|
Claude Code user skills go to $CLAUDE_CONFIG_DIR/skills when set, otherwise
|
|
@@ -15889,7 +16323,7 @@ skip automatic writes. Set a non-empty path or unset CLAUDE_CONFIG_DIR.
|
|
|
15889
16323
|
Explicit Claude user installs reject blank values with validation_failed.
|
|
15890
16324
|
|
|
15891
16325
|
Common failures:
|
|
15892
|
-
validation_failed Pass --tool codex|claude|cursor;
|
|
16326
|
+
validation_failed Pass --tool codex|claude|cursor; all tools support --scope project or user
|
|
15893
16327
|
skill_update_conflict An unmanaged file exists at the target path; inspect it or pass --force`
|
|
15894
16328
|
});
|
|
15895
16329
|
const skillsListDefinition = define({
|
|
@@ -15899,7 +16333,8 @@ const skillsListDefinition = define({
|
|
|
15899
16333
|
args: commonArgs,
|
|
15900
16334
|
examples: `npm exec --yes --package=@artifactshare/cli -- artifactshare skills list --json
|
|
15901
16335
|
|
|
15902
|
-
Reports each tool and scope with detection,
|
|
16336
|
+
Reports each tool and scope with detection, version, completeness, missing/differing files,
|
|
16337
|
+
ownership metadata, and legacy Cursor rule coexistence.
|
|
15903
16338
|
Runs locally; no network or authentication is used.`
|
|
15904
16339
|
});
|
|
15905
16340
|
const skillsUpdateDefinition = define({
|
|
@@ -15912,13 +16347,14 @@ const skillsUpdateDefinition = define({
|
|
|
15912
16347
|
force: {
|
|
15913
16348
|
type: "boolean",
|
|
15914
16349
|
toKebab: true,
|
|
15915
|
-
description: "Rewrite managed files
|
|
16350
|
+
description: "Rewrite managed folder files; never take over an unmanaged entry"
|
|
15916
16351
|
}
|
|
15917
16352
|
},
|
|
15918
16353
|
examples: `npm exec --yes --package=@artifactshare/cli -- artifactshare skills update --json
|
|
15919
16354
|
npm exec --yes --package=@artifactshare/cli -- artifactshare skills update --tool codex --scope user --json
|
|
15920
16355
|
|
|
15921
|
-
|
|
16356
|
+
Updates managed folders, repairs same-version drift, and preserves user-added files.
|
|
16357
|
+
Managed legacy Cursor rules migrate after the new project folder is ready.
|
|
15922
16358
|
|
|
15923
16359
|
Common failures:
|
|
15924
16360
|
skill_update_conflict A managed marker is broken; inspect the file or reinstall with --force`
|
|
@@ -15944,7 +16380,8 @@ Use --tool auto from an agent workspace. It detects .claude, .codex/.agents, or
|
|
|
15944
16380
|
.cursor in the current directory, or the Claude user root when CLAUDE_CONFIG_DIR
|
|
15945
16381
|
is nonblank, and installs
|
|
15946
16382
|
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
|
|
16383
|
+
skills. Cursor project scope needs skills install --tool cursor --scope project,
|
|
16384
|
+
except existing managed legacy Cursor rules migrate automatically.
|
|
15948
16385
|
|
|
15949
16386
|
Claude user skills use CLAUDE_CONFIG_DIR when set, otherwise ~/.claude.
|
|
15950
16387
|
Relative paths resolve against cwd; tilde is literal. Blank values skip automatic
|
|
@@ -15968,7 +16405,8 @@ const skillsRemoveDefinition = define({
|
|
|
15968
16405
|
examples: `npm exec --yes --package=@artifactshare/cli -- artifactshare skills remove --json
|
|
15969
16406
|
npm exec --yes --package=@artifactshare/cli -- artifactshare skills remove --tool cursor --json
|
|
15970
16407
|
|
|
15971
|
-
Only files
|
|
16408
|
+
Only manifest-owned files (or a legacy managed SKILL.md) are deleted; user files are preserved.
|
|
16409
|
+
Project Cursor removal also cleans managed legacy rules.`
|
|
15972
16410
|
});
|
|
15973
16411
|
const skillsDefinition = define({
|
|
15974
16412
|
name: "skills",
|
|
@@ -16012,7 +16450,7 @@ Without flags, init detects Claude Code, Codex, or Cursor in the working directo
|
|
|
16012
16450
|
installs or updates the bundled skill in user scope, and shows the next steps (sign
|
|
16013
16451
|
in, then share). With no agent detected, it prepares user-scope Codex, Claude Code,
|
|
16014
16452
|
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.
|
|
16453
|
+
--tool cursor --scope project. Existing project-scope skills are not modified, except managed legacy Cursor rules migrate to .cursor/skills/artifactshare/.
|
|
16016
16454
|
data.mode is "onboarding".
|
|
16017
16455
|
|
|
16018
16456
|
Claude Code user skills go to $CLAUDE_CONFIG_DIR/skills when set, otherwise
|