@serviceme/devtools-core 1.0.0 → 2.0.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/dist/device.js.map +1 -1
- package/dist/device.mjs.map +1 -1
- package/dist/{index-CXvNx2fp.d.mts → index-BMk4tqIT.d.mts} +19 -0
- package/dist/{index-CR1hbAnO.d.ts → index-CymN0x9Z.d.ts} +19 -0
- package/dist/index.d.mts +1216 -9
- package/dist/index.d.ts +1216 -9
- package/dist/index.js +4081 -643
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3986 -592
- package/dist/index.mjs.map +1 -1
- package/dist/skill-linker.d.mts +9 -4
- package/dist/skill-linker.d.ts +9 -4
- package/dist/skill-linker.js +70 -3
- package/dist/skill-linker.js.map +1 -1
- package/dist/skill-linker.mjs +69 -3
- package/dist/skill-linker.mjs.map +1 -1
- package/dist/skill-store.d.mts +21 -3
- package/dist/skill-store.d.ts +21 -3
- package/dist/skill-store.js +83 -29
- package/dist/skill-store.js.map +1 -1
- package/dist/skill-store.mjs +83 -29
- package/dist/skill-store.mjs.map +1 -1
- package/dist/submit.d.mts +1 -1
- package/dist/submit.d.ts +1 -1
- package/dist/submit.js.map +1 -1
- package/dist/submit.mjs.map +1 -1
- package/dist/toolbox.js.map +1 -1
- package/dist/toolbox.mjs.map +1 -1
- package/package.json +2 -2
package/dist/skill-linker.d.mts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* the same path Copilot/Claude actually scan for `SKILL.md` /
|
|
9
9
|
* `AGENT.md`, so linking here has real effect (see the v1 parity
|
|
10
10
|
* note below); or
|
|
11
|
-
* - the user's global scope, at `~/.
|
|
11
|
+
* - the user's global scope, at `~/.copilot/{skills,agents}/<name>`,
|
|
12
12
|
* visible to every workspace.
|
|
13
13
|
*
|
|
14
14
|
* **v1 parity note**: an earlier revision linked into a private
|
|
@@ -43,7 +43,7 @@ type EntryKind = "skill" | "agent";
|
|
|
43
43
|
/**
|
|
44
44
|
* Which scope the link lives in:
|
|
45
45
|
* - `"workspace"` (default) → `<workspaceDir>/.github/<kind>/<name>`
|
|
46
|
-
* - `"user"` → `~/.
|
|
46
|
+
* - `"user"` → `~/.copilot/<kind>/<name>` (visible to every workspace)
|
|
47
47
|
*/
|
|
48
48
|
type LinkScope = "workspace" | "user";
|
|
49
49
|
interface InstallSkillOptions {
|
|
@@ -131,7 +131,7 @@ declare function resolveSkillTarget(repoId: string, skillName: string, kind?: En
|
|
|
131
131
|
*/
|
|
132
132
|
declare function resolveSkillLinkPath(workspaceDir: string, skillName: string, kind?: EntryKind): string;
|
|
133
133
|
/**
|
|
134
|
-
* Resolve the user-scope link path — `~/.
|
|
134
|
+
* Resolve the user-scope link path — `~/.copilot/{skills,agents}/<name>` —
|
|
135
135
|
* visible to every workspace.
|
|
136
136
|
*/
|
|
137
137
|
declare function resolveUserSkillLinkPath(skillName: string, kind?: EntryKind): string;
|
|
@@ -184,5 +184,10 @@ declare function uninstallSkillFromWorkspace(opts: {
|
|
|
184
184
|
* directory doesn't exist.
|
|
185
185
|
*/
|
|
186
186
|
declare function listLinkedSkills(workspaceDir: string, kind?: EntryKind, scope?: LinkScope): Promise<LinkedSkill[]>;
|
|
187
|
+
/**
|
|
188
|
+
* List entries still living in the legacy `~/.agents` user scope.
|
|
189
|
+
* Read-only: migration is an explicit user action elsewhere.
|
|
190
|
+
*/
|
|
191
|
+
declare function listLegacyUserScopeSkills(kind?: EntryKind): Promise<LinkedSkill[]>;
|
|
187
192
|
|
|
188
|
-
export { type EntryKind, type InstallSkillOptions, type InstallSkillResult, LinkError, type LinkMode, type LinkScope, type LinkedSkill, convertToSymlink, getPlatformHint, installSkillToWorkspace, listLinkedSkills, pickMode, resolveSkillLinkPath, resolveSkillTarget, resolveUserSkillLinkPath, uninstallSkillFromWorkspace };
|
|
193
|
+
export { type EntryKind, type InstallSkillOptions, type InstallSkillResult, LinkError, type LinkMode, type LinkScope, type LinkedSkill, convertToSymlink, getPlatformHint, installSkillToWorkspace, listLegacyUserScopeSkills, listLinkedSkills, pickMode, resolveSkillLinkPath, resolveSkillTarget, resolveUserSkillLinkPath, uninstallSkillFromWorkspace };
|
package/dist/skill-linker.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* the same path Copilot/Claude actually scan for `SKILL.md` /
|
|
9
9
|
* `AGENT.md`, so linking here has real effect (see the v1 parity
|
|
10
10
|
* note below); or
|
|
11
|
-
* - the user's global scope, at `~/.
|
|
11
|
+
* - the user's global scope, at `~/.copilot/{skills,agents}/<name>`,
|
|
12
12
|
* visible to every workspace.
|
|
13
13
|
*
|
|
14
14
|
* **v1 parity note**: an earlier revision linked into a private
|
|
@@ -43,7 +43,7 @@ type EntryKind = "skill" | "agent";
|
|
|
43
43
|
/**
|
|
44
44
|
* Which scope the link lives in:
|
|
45
45
|
* - `"workspace"` (default) → `<workspaceDir>/.github/<kind>/<name>`
|
|
46
|
-
* - `"user"` → `~/.
|
|
46
|
+
* - `"user"` → `~/.copilot/<kind>/<name>` (visible to every workspace)
|
|
47
47
|
*/
|
|
48
48
|
type LinkScope = "workspace" | "user";
|
|
49
49
|
interface InstallSkillOptions {
|
|
@@ -131,7 +131,7 @@ declare function resolveSkillTarget(repoId: string, skillName: string, kind?: En
|
|
|
131
131
|
*/
|
|
132
132
|
declare function resolveSkillLinkPath(workspaceDir: string, skillName: string, kind?: EntryKind): string;
|
|
133
133
|
/**
|
|
134
|
-
* Resolve the user-scope link path — `~/.
|
|
134
|
+
* Resolve the user-scope link path — `~/.copilot/{skills,agents}/<name>` —
|
|
135
135
|
* visible to every workspace.
|
|
136
136
|
*/
|
|
137
137
|
declare function resolveUserSkillLinkPath(skillName: string, kind?: EntryKind): string;
|
|
@@ -184,5 +184,10 @@ declare function uninstallSkillFromWorkspace(opts: {
|
|
|
184
184
|
* directory doesn't exist.
|
|
185
185
|
*/
|
|
186
186
|
declare function listLinkedSkills(workspaceDir: string, kind?: EntryKind, scope?: LinkScope): Promise<LinkedSkill[]>;
|
|
187
|
+
/**
|
|
188
|
+
* List entries still living in the legacy `~/.agents` user scope.
|
|
189
|
+
* Read-only: migration is an explicit user action elsewhere.
|
|
190
|
+
*/
|
|
191
|
+
declare function listLegacyUserScopeSkills(kind?: EntryKind): Promise<LinkedSkill[]>;
|
|
187
192
|
|
|
188
|
-
export { type EntryKind, type InstallSkillOptions, type InstallSkillResult, LinkError, type LinkMode, type LinkScope, type LinkedSkill, convertToSymlink, getPlatformHint, installSkillToWorkspace, listLinkedSkills, pickMode, resolveSkillLinkPath, resolveSkillTarget, resolveUserSkillLinkPath, uninstallSkillFromWorkspace };
|
|
193
|
+
export { type EntryKind, type InstallSkillOptions, type InstallSkillResult, LinkError, type LinkMode, type LinkScope, type LinkedSkill, convertToSymlink, getPlatformHint, installSkillToWorkspace, listLegacyUserScopeSkills, listLinkedSkills, pickMode, resolveSkillLinkPath, resolveSkillTarget, resolveUserSkillLinkPath, uninstallSkillFromWorkspace };
|
package/dist/skill-linker.js
CHANGED
|
@@ -34,6 +34,7 @@ __export(skill_linker_exports, {
|
|
|
34
34
|
convertToSymlink: () => convertToSymlink,
|
|
35
35
|
getPlatformHint: () => getPlatformHint,
|
|
36
36
|
installSkillToWorkspace: () => installSkillToWorkspace,
|
|
37
|
+
listLegacyUserScopeSkills: () => listLegacyUserScopeSkills,
|
|
37
38
|
listLinkedSkills: () => listLinkedSkills,
|
|
38
39
|
pickMode: () => pickMode,
|
|
39
40
|
resolveSkillLinkPath: () => resolveSkillLinkPath,
|
|
@@ -131,7 +132,7 @@ function resolveSkillLinkPath(workspaceDir, skillName, kind = "skill") {
|
|
|
131
132
|
return path2.join(workspaceDir, ".github", ENTRY_SUBDIR[kind], skillName);
|
|
132
133
|
}
|
|
133
134
|
function resolveUserSkillLinkPath(skillName, kind = "skill") {
|
|
134
|
-
return path2.join(getHomeDir(), ".
|
|
135
|
+
return path2.join(getHomeDir(), ".copilot", ENTRY_SUBDIR[kind], skillName);
|
|
135
136
|
}
|
|
136
137
|
function resolveLinkPath(opts) {
|
|
137
138
|
if (opts.scope === "workspace" && !opts.workspaceDir) {
|
|
@@ -236,13 +237,24 @@ async function uninstallSkillFromWorkspace(opts) {
|
|
|
236
237
|
try {
|
|
237
238
|
entries = await fs.readdir(scopeDir, { withFileTypes: true });
|
|
238
239
|
} catch {
|
|
239
|
-
|
|
240
|
+
entries = [];
|
|
240
241
|
}
|
|
241
242
|
const flatMatch = entries.find(
|
|
242
243
|
(e) => e.name === opts.skillName || e.name.startsWith(`${opts.skillName}.`)
|
|
243
244
|
);
|
|
244
245
|
if (flatMatch) {
|
|
245
246
|
await removeIfExists(path2.join(scopeDir, flatMatch.name));
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (scope === "user") {
|
|
250
|
+
const legacyDir = path2.join(getHomeDir(), LEGACY_USER_SCOPE_ROOT, ENTRY_SUBDIR[kind]);
|
|
251
|
+
const legacyEntries = await fs.readdir(legacyDir, { withFileTypes: true }).catch(() => []);
|
|
252
|
+
const legacyMatch = legacyEntries.find(
|
|
253
|
+
(e) => e.name === opts.skillName || e.name.startsWith(`${opts.skillName}.`)
|
|
254
|
+
);
|
|
255
|
+
if (legacyMatch) {
|
|
256
|
+
await removeIfExists(path2.join(legacyDir, legacyMatch.name));
|
|
257
|
+
}
|
|
246
258
|
}
|
|
247
259
|
}
|
|
248
260
|
async function pathExists(p) {
|
|
@@ -257,11 +269,13 @@ var MANIFEST_FILENAME = {
|
|
|
257
269
|
skill: "SKILL.md",
|
|
258
270
|
agent: "AGENT.md"
|
|
259
271
|
};
|
|
272
|
+
var LEGACY_USER_SCOPE_ROOT = ".agents";
|
|
260
273
|
async function listLinkedSkills(workspaceDir, kind = "skill", scope = "workspace") {
|
|
261
274
|
if (scope === "workspace" && !workspaceDir) {
|
|
262
275
|
return [];
|
|
263
276
|
}
|
|
264
|
-
const
|
|
277
|
+
const userRoot = path2.join(getHomeDir(), ".copilot", ENTRY_SUBDIR[kind]);
|
|
278
|
+
const root = scope === "user" ? userRoot : path2.join(workspaceDir, ".github", ENTRY_SUBDIR[kind]);
|
|
265
279
|
let entries;
|
|
266
280
|
try {
|
|
267
281
|
entries = await fs.readdir(root, { withFileTypes: true });
|
|
@@ -313,6 +327,58 @@ async function listLinkedSkills(workspaceDir, kind = "skill", scope = "workspace
|
|
|
313
327
|
});
|
|
314
328
|
}
|
|
315
329
|
}
|
|
330
|
+
if (scope === "user") {
|
|
331
|
+
const seen = new Set(results.map((r) => r.skillName));
|
|
332
|
+
for (const legacy of await listLegacyUserScopeSkills(kind)) {
|
|
333
|
+
if (!seen.has(legacy.skillName)) {
|
|
334
|
+
results.push(legacy);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return results;
|
|
339
|
+
}
|
|
340
|
+
async function listLegacyUserScopeSkills(kind = "skill") {
|
|
341
|
+
const root = path2.join(getHomeDir(), LEGACY_USER_SCOPE_ROOT, ENTRY_SUBDIR[kind]);
|
|
342
|
+
let entries;
|
|
343
|
+
try {
|
|
344
|
+
entries = await fs.readdir(root, { withFileTypes: true });
|
|
345
|
+
} catch (err) {
|
|
346
|
+
if (err.code === "ENOENT") return [];
|
|
347
|
+
throw err;
|
|
348
|
+
}
|
|
349
|
+
const results = [];
|
|
350
|
+
for (const entry of entries) {
|
|
351
|
+
const entryPath = path2.join(root, entry.name);
|
|
352
|
+
if (entry.isSymbolicLink()) {
|
|
353
|
+
const skillName = entry.name.replace(/\.(agent|skill)\.md$/, "");
|
|
354
|
+
const rawTarget = await readLinkTarget(entryPath);
|
|
355
|
+
if (!rawTarget) continue;
|
|
356
|
+
const resolvedTarget = resolveTargetPath(entryPath, rawTarget);
|
|
357
|
+
const targetStat = await fs.stat(resolvedTarget).catch(() => null);
|
|
358
|
+
if (!targetStat) continue;
|
|
359
|
+
results.push({
|
|
360
|
+
repoId: extractRepoIdFromTarget(resolvedTarget) ?? "",
|
|
361
|
+
skillName,
|
|
362
|
+
linkPath: entryPath,
|
|
363
|
+
targetPath: resolvedTarget,
|
|
364
|
+
mode: process.platform === "win32" ? "junction" : "symlink",
|
|
365
|
+
scope: "user"
|
|
366
|
+
});
|
|
367
|
+
} else if (entry.isDirectory()) {
|
|
368
|
+
const manifestPath = path2.join(entryPath, MANIFEST_FILENAME[kind]);
|
|
369
|
+
const stat2 = await fs.stat(manifestPath).catch(() => null);
|
|
370
|
+
if (stat2?.isFile()) {
|
|
371
|
+
results.push({
|
|
372
|
+
repoId: "",
|
|
373
|
+
skillName: entry.name,
|
|
374
|
+
linkPath: entryPath,
|
|
375
|
+
targetPath: manifestPath,
|
|
376
|
+
mode: "copy",
|
|
377
|
+
scope: "user"
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
316
382
|
return results;
|
|
317
383
|
}
|
|
318
384
|
async function isCorrectLink(linkPath, expectedTarget) {
|
|
@@ -364,6 +430,7 @@ async function removeIfExists(p) {
|
|
|
364
430
|
convertToSymlink,
|
|
365
431
|
getPlatformHint,
|
|
366
432
|
installSkillToWorkspace,
|
|
433
|
+
listLegacyUserScopeSkills,
|
|
367
434
|
listLinkedSkills,
|
|
368
435
|
pickMode,
|
|
369
436
|
resolveSkillLinkPath,
|
package/dist/skill-linker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/skill-linker/index.ts","../src/paths/userHome.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport { getHomeDir, getRepoDir } from \"../paths/userHome\";\n\n/**\n * Skill & Agent v2 — Client SkillLinker (M3, path-parity revision)\n *\n * SkillLinker exposes a skill/agent from the user's global repos\n * (`~/.serviceme/repos/<repoId>/{skills,agents}/<name>/`) into either:\n *\n * - a workspace, at `<workspace>/.github/{skills,agents}/<name>` —\n * the same path Copilot/Claude actually scan for `SKILL.md` /\n * `AGENT.md`, so linking here has real effect (see the v1 parity\n * note below); or\n * - the user's global scope, at `~/.agents/{skills,agents}/<name>`,\n * visible to every workspace.\n *\n * **v1 parity note**: an earlier revision linked into a private\n * `<workspace>/.serviceme/skills/<repoId>/<name>` directory. That path\n * is never scanned by the actual tooling, so installs were silently\n * inert. The path was moved to match `.github/skills` (the same\n * location the legacy v1 marketplace pipeline used). Because the link\n * path is now flat (no `<repoId>` segment), only one repo's version of\n * a given `<name>` can be linked into a given scope at a time.\n *\n * Platform behavior (per spec §11.8 — owner explicitly chose throw\n * over silent copy fallback):\n *\n * | platform | default mode | on failure |\n * |----------|--------------|-----------------------------|\n * | macOS | symlink | throw + platform hint |\n * | Linux | symlink | throw + platform hint |\n * | Windows | junction | throw + platform hint |\n *\n * Why junction first on Windows: NTFS junction doesn't require\n * SeCreateSymbolicLinkPrivilege; it works for any user. The limit is\n * the link target must be on a local NTFS volume. OneDrive / network\n * shares sometimes fail; we surface that as a typed error so callers\n * can decide whether to retry.\n *\n * @see docs/architecture/skill-agent-v2-repo.md §5.6 SkillLinker\n * @see docs/architecture/skill-agent-v2-repo.md §11.8 (throw, not copy)\n */\n\nexport type LinkMode = \"symlink\" | \"junction\" | \"copy\";\n\n/** Kind of artifact being linked. Mirrors `BridgeSkillKind`. */\nexport type EntryKind = \"skill\" | \"agent\";\n\n/**\n * Which scope the link lives in:\n * - `\"workspace\"` (default) → `<workspaceDir>/.github/<kind>/<name>`\n * - `\"user\"` → `~/.agents/<kind>/<name>` (visible to every workspace)\n */\nexport type LinkScope = \"workspace\" | \"user\";\n\nconst ENTRY_SUBDIR: Record<EntryKind, string> = {\n\tskill: \"skills\",\n\tagent: \"agents\",\n};\n\nexport interface InstallSkillOptions {\n\trepoId: string;\n\tskillName: string;\n\tworkspaceDir: string;\n\t/** Choose link mode explicitly. Defaults to platform-optimal. */\n\tmode?: \"auto\" | LinkMode;\n\t/** \"skill\" (default) or \"agent\". */\n\tkind?: EntryKind;\n\t/** \"workspace\" (default) or \"user\". */\n\tscope?: LinkScope;\n\t/**\n\t * Pre-resolved absolute source path (from `SkillStore`), overriding\n\t * the `<repoRoot>/{skills,agents}/<name>` formula in\n\t * {@link resolveSkillTarget}. Required for repos with non-standard\n\t * layouts — flat root (no `skills/` prefix), nested scope dirs\n\t * (`skills/official/<name>`), or flat single-file agent manifests\n\t * (`agents/<name>.agent.md`) — which the formula can't predict.\n\t * When omitted, falls back to the formula (kept for callers that\n\t * install a hand-authored skill without going through `SkillStore`).\n\t */\n\tsourcePath?: string;\n\t/**\n\t * True when `sourcePath` points at a single manifest FILE (e.g. a\n\t * flat `<name>.agent.md`) rather than a directory. Determines the\n\t * symlink type (file vs dir/junction) and the link's basename (the\n\t * link mirrors the source file's name + extension, since Copilot/\n\t * VS Code scan `.github/agents/<name>.agent.md` as a FILE).\n\t */\n\tsourceIsFile?: boolean;\n}\n\nexport interface InstallSkillResult {\n\tmode: LinkMode;\n\tlinkPath: string;\n\ttargetPath: string;\n}\n\n/** Describes one symlink/junction currently present in a workspace/user scope. */\nexport interface LinkedSkill {\n\t/**\n\t * Repo id the link resolves to, parsed back out of the symlink\n\t * target. Empty string when the target isn't under a recognizable\n\t * `~/.serviceme/repos/<repoId>/...` path.\n\t */\n\trepoId: string;\n\tskillName: string;\n\tlinkPath: string;\n\ttargetPath: string;\n\tmode: LinkMode;\n\t/** Which scope this link was found in — \"workspace\" or \"user\" (global). */\n\tscope: LinkScope;\n}\n\n/**\n * Sentinel error for link failures. Carries the chosen mode + platform\n * hint so the UI can render an actionable message.\n */\nexport class LinkError extends Error {\n\treadonly mode: LinkMode;\n\treadonly target: string;\n\treadonly linkPath: string;\n\treadonly platform: NodeJS.Platform;\n\treadonly cause: unknown;\n\n\tconstructor(opts: {\n\t\tmode: LinkMode;\n\t\ttarget: string;\n\t\tlinkPath: string;\n\t\tplatform: NodeJS.Platform;\n\t\tcause: unknown;\n\t}) {\n\t\tsuper(\n\t\t\t`failed to ${opts.mode} link ${opts.linkPath} → ${opts.target} on ${opts.platform}: ${\n\t\t\t\topts.cause instanceof Error ? opts.cause.message : String(opts.cause)\n\t\t\t}`\n\t\t);\n\t\tthis.name = \"LinkError\";\n\t\tthis.mode = opts.mode;\n\t\tthis.target = opts.target;\n\t\tthis.linkPath = opts.linkPath;\n\t\tthis.platform = opts.platform;\n\t\tthis.cause = opts.cause;\n\t}\n\n\t/** A user-facing hint for the platform that failed. */\n\thint(): string {\n\t\treturn getPlatformHint(this.platform);\n\t}\n}\n\n/** Choose the platform-optimal link mode. */\nexport function pickMode(platform: NodeJS.Platform = process.platform): LinkMode {\n\treturn platform === \"win32\" ? \"junction\" : \"symlink\";\n}\n\n/** A short hint string for the platform where the link failed. */\nexport function getPlatformHint(platform: NodeJS.Platform): string {\n\tif (platform === \"win32\") {\n\t\treturn (\n\t\t\t\"On Windows, enable Developer Mode in Settings → Privacy & Security → \" +\n\t\t\t\"For developers, or run as Administrator. NTFS junction also requires the \" +\n\t\t\t\"target to be on a local NTFS volume (OneDrive / network shares are not supported).\"\n\t\t);\n\t}\n\treturn (\n\t\t\"Symlink creation failed. Check filesystem permissions and that the source \" +\n\t\t\"directory exists. On some filesystems (FAT32, exFAT, network mounts) symlinks \" +\n\t\t\"are not supported.\"\n\t);\n}\n\n/**\n * Resolve the source path inside `~/.serviceme/repos/<repoId>/{skills,agents}/<name>`.\n * Exported for callers that need to inspect the target without installing.\n */\nexport function resolveSkillTarget(\n\trepoId: string,\n\tskillName: string,\n\tkind: EntryKind = \"skill\"\n): string {\n\treturn path.join(getRepoDir(repoId), ENTRY_SUBDIR[kind], skillName);\n}\n\n/**\n * Resolve the workspace link path — `<workspaceDir>/.github/{skills,agents}/<name>` —\n * the same directory Copilot/Claude actually scan.\n */\nexport function resolveSkillLinkPath(\n\tworkspaceDir: string,\n\tskillName: string,\n\tkind: EntryKind = \"skill\"\n): string {\n\treturn path.join(workspaceDir, \".github\", ENTRY_SUBDIR[kind], skillName);\n}\n\n/**\n * Resolve the user-scope link path — `~/.agents/{skills,agents}/<name>` —\n * visible to every workspace.\n */\nexport function resolveUserSkillLinkPath(skillName: string, kind: EntryKind = \"skill\"): string {\n\treturn path.join(getHomeDir(), \".agents\", ENTRY_SUBDIR[kind], skillName);\n}\n\nfunction resolveLinkPath(opts: {\n\tworkspaceDir: string;\n\tskillName: string;\n\tkind: EntryKind;\n\tscope: LinkScope;\n\t/** When set, use this basename instead of the bare `skillName` — for\n\t * file-based sources the link must mirror the source's filename\n\t * (including its extension) to be scannable at its real path. */\n\tlinkBasename?: string;\n}): string {\n\tif (opts.scope === \"workspace\" && !opts.workspaceDir) {\n\t\tthrow new Error(\n\t\t\t\"workspaceDir is required for scope: 'workspace' (pass scope: 'user' for a global install instead).\"\n\t\t);\n\t}\n\tconst base =\n\t\topts.scope === \"user\"\n\t\t\t? resolveUserSkillLinkPath(opts.skillName, opts.kind)\n\t\t\t: resolveSkillLinkPath(opts.workspaceDir, opts.skillName, opts.kind);\n\treturn opts.linkBasename ? path.join(path.dirname(base), opts.linkBasename) : base;\n}\n\n/**\n * Install a skill into a workspace by creating a link at the standard\n * path. Throws `LinkError` on failure (no silent copy fallback per\n * §11.8).\n *\n * Idempotent: if the correct link already exists, returns the existing\n * record without touching the filesystem. If a *wrong* link exists at\n * the target path, it is replaced.\n */\nexport async function installSkillToWorkspace(\n\topts: InstallSkillOptions\n): Promise<InstallSkillResult> {\n\tconst kind = opts.kind ?? \"skill\";\n\tconst scope = opts.scope ?? \"workspace\";\n\tconst isFile = opts.sourceIsFile ?? false;\n\tconst target = opts.sourcePath ?? resolveSkillTarget(opts.repoId, opts.skillName, kind);\n\tconst linkPath = resolveLinkPath({\n\t\tworkspaceDir: opts.workspaceDir,\n\t\tskillName: opts.skillName,\n\t\tkind,\n\t\tscope,\n\t\tlinkBasename: isFile ? path.basename(target) : undefined,\n\t});\n\n\t// Sanity-check: the skill source directory must exist before we try\n\t// to link it. Otherwise the link would dangle.\n\tawait fs.access(target).catch(() => {\n\t\tthrow new LinkError({\n\t\t\tmode: \"symlink\", // placeholder — mode not chosen yet\n\t\t\ttarget,\n\t\t\tlinkPath,\n\t\t\tplatform: process.platform,\n\t\t\tcause: new Error(`skill source not found: ${target}`),\n\t\t});\n\t});\n\n\t// If the link already exists and points to the right target, no-op.\n\tif (await isCorrectLink(linkPath, target)) {\n\t\treturn { mode: \"symlink\", linkPath, targetPath: target };\n\t}\n\t// Otherwise, remove any stale entry at the path.\n\tawait removeIfExists(linkPath);\n\n\t// Junctions are directory-only — a file source can never use one,\n\t// regardless of platform default. Fall back to a real symlink.\n\tconst requestedMode = opts.mode === undefined || opts.mode === \"auto\" ? pickMode() : opts.mode;\n\tconst mode = isFile && requestedMode === \"junction\" ? \"symlink\" : requestedMode;\n\n\t// Ensure the parent directory exists — fs.symlink does NOT create\n\t// missing parents. The path is `<workspace>/.serviceme/skills/<repoId>/`,\n\t// which is several levels deep on a fresh workspace.\n\tawait fs.mkdir(path.dirname(linkPath), { recursive: true });\n\n\ttry {\n\t\tif (mode === \"junction\") {\n\t\t\t// fs.symlink with type \"junction\" works on Windows for dirs.\n\t\t\tawait fs.symlink(target, linkPath, \"junction\");\n\t\t} else if (mode === \"symlink\") {\n\t\t\t// Windows requires an explicit \"file\" type for file symlinks;\n\t\t\t// POSIX ignores the type argument either way.\n\t\t\tawait fs.symlink(target, linkPath, isFile ? \"file\" : \"dir\");\n\t\t} else {\n\t\t\t// `copy` mode is intentionally NOT implemented for v1 — see\n\t\t\t// spec §11.8 (\"throw, not copy fallback\"). Reaching this branch\n\t\t\t// means a caller explicitly passed `mode: 'copy'`; we treat\n\t\t\t// it as a configuration error rather than silently dropping\n\t\t\t// to copy semantics.\n\t\t\tthrow new LinkError({\n\t\t\t\tmode: \"copy\",\n\t\t\t\ttarget,\n\t\t\t\tlinkPath,\n\t\t\t\tplatform: process.platform,\n\t\t\t\tcause: new Error(\n\t\t\t\t\t\"copy mode is not supported in v1 — see spec §11.8 (throw, not copy fallback)\"\n\t\t\t\t),\n\t\t\t});\n\t\t}\n\t} catch (err) {\n\t\tif (err instanceof LinkError) throw err;\n\t\tthrow new LinkError({\n\t\t\tmode,\n\t\t\ttarget,\n\t\t\tlinkPath,\n\t\t\tplatform: process.platform,\n\t\t\tcause: err,\n\t\t});\n\t}\n\n\treturn { mode, linkPath, targetPath: target };\n}\n\n/**\n * Convert an existing, real (non-symlink) skill/agent directory at the\n * standard scan path into a symlink pointing at the matching global\n * repo entry. Refuses to run when there's nothing real to convert —\n * callers should only surface this action when a marketplace/scope\n * state check already confirmed a non-symlink install is present.\n */\nexport async function convertToSymlink(opts: InstallSkillOptions): Promise<InstallSkillResult> {\n\tconst kind = opts.kind ?? \"skill\";\n\tconst scope = opts.scope ?? \"workspace\";\n\tconst linkPath = resolveLinkPath({\n\t\tworkspaceDir: opts.workspaceDir,\n\t\tskillName: opts.skillName,\n\t\tkind,\n\t\tscope,\n\t\tlinkBasename: opts.sourceIsFile && opts.sourcePath ? path.basename(opts.sourcePath) : undefined,\n\t});\n\n\tconst stat = await fs.lstat(linkPath).catch(() => null);\n\tif (!stat) {\n\t\tthrow new Error(`Nothing installed at ${linkPath} to convert.`);\n\t}\n\tif (stat.isSymbolicLink()) {\n\t\tthrow new Error(`${linkPath} is already a symlink.`);\n\t}\n\n\treturn installSkillToWorkspace(opts);\n}\n\n/**\n * Remove a skill/agent link from a workspace/user scope. Idempotent:\n * succeeds when the link does not exist (no error).\n *\n * Tries the bare `<name>` path first (directory-based entries), then\n * falls back to scanning the scope dir for a `<name>.<ext>` file (flat\n * manifest entries, e.g. `CSharpExpert.agent.md`) — the caller doesn't\n * necessarily still have the source repo entry to know which shape was\n * installed (e.g. the repo may have been removed since).\n */\nexport async function uninstallSkillFromWorkspace(opts: {\n\trepoId: string;\n\tskillName: string;\n\tworkspaceDir: string;\n\tkind?: EntryKind;\n\tscope?: LinkScope;\n}): Promise<void> {\n\tconst kind = opts.kind ?? \"skill\";\n\tconst scope = opts.scope ?? \"workspace\";\n\tconst linkPath = resolveLinkPath({\n\t\tworkspaceDir: opts.workspaceDir,\n\t\tskillName: opts.skillName,\n\t\tkind,\n\t\tscope,\n\t});\n\tif (await pathExists(linkPath)) {\n\t\tawait removeIfExists(linkPath);\n\t\treturn;\n\t}\n\n\tconst scopeDir = path.dirname(linkPath);\n\tlet entries: import(\"node:fs\").Dirent[];\n\ttry {\n\t\tentries = await fs.readdir(scopeDir, { withFileTypes: true });\n\t} catch {\n\t\treturn; // nothing installed at all — idempotent no-op\n\t}\n\tconst flatMatch = entries.find(\n\t\t(e) => e.name === opts.skillName || e.name.startsWith(`${opts.skillName}.`)\n\t);\n\tif (flatMatch) {\n\t\tawait removeIfExists(path.join(scopeDir, flatMatch.name));\n\t}\n}\n\n/** `true` when `p` exists (following symlinks is irrelevant — `lstat` is enough). */\nasync function pathExists(p: string): Promise<boolean> {\n\ttry {\n\t\tawait fs.lstat(p);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nconst MANIFEST_FILENAME: Record<EntryKind, string> = {\n\tskill: \"SKILL.md\",\n\tagent: \"AGENT.md\",\n};\n\n/**\n * Enumerate all skill/agent entries currently present in a workspace/user\n * scope — both symlinked installs (`mode: \"symlink\"`/`\"junction\"`) AND\n * real, non-symlink directories/files that already carry a valid\n * manifest (`mode: \"copy\"`). Used by the UI's \"Manage installed skills\"\n * view so it can show a real (copy-installed) entry as installed too —\n * this is common for the user (global) scope, where many skills are\n * placed by other tools/installers as plain copies rather than via this\n * package's symlink-only install flow. `repoId` is `\"\"` for `\"copy\"`\n * entries since there's no symlink target to resolve it from; callers\n * match these by name only. Returns an empty array when the scan\n * directory doesn't exist.\n */\nexport async function listLinkedSkills(\n\tworkspaceDir: string,\n\tkind: EntryKind = \"skill\",\n\tscope: LinkScope = \"workspace\"\n): Promise<LinkedSkill[]> {\n\t// No workspace open + workspace scope requested — nothing to scan.\n\t// Guard explicitly rather than falling through to\n\t// `path.join(\"\", \".github\", ...)`, which resolves to a *relative*\n\t// path (anchored at the process's cwd, not a real workspace) and\n\t// could accidentally match an unrelated directory there.\n\tif (scope === \"workspace\" && !workspaceDir) {\n\t\treturn [];\n\t}\n\tconst root =\n\t\tscope === \"user\"\n\t\t\t? path.join(getHomeDir(), \".agents\", ENTRY_SUBDIR[kind])\n\t\t\t: path.join(workspaceDir, \".github\", ENTRY_SUBDIR[kind]);\n\n\tlet entries: import(\"node:fs\").Dirent[];\n\ttry {\n\t\tentries = await fs.readdir(root, { withFileTypes: true });\n\t} catch (err) {\n\t\tif ((err as NodeJS.ErrnoException).code === \"ENOENT\") return [];\n\t\tthrow err;\n\t}\n\n\tconst results: LinkedSkill[] = [];\n\tfor (const entry of entries) {\n\t\tconst entryPath = path.join(root, entry.name);\n\n\t\tif (entry.isSymbolicLink()) {\n\t\t\t// Flat manifest files (e.g. `CSharpExpert.agent.md`) report the\n\t\t\t// bare name, matching what SkillStore/install use elsewhere —\n\t\t\t// otherwise this would look like a different, unrelated entry.\n\t\t\tconst skillName = entry.name.replace(/\\.(agent|skill)\\.md$/, \"\");\n\t\t\tconst rawTarget = await readLinkTarget(entryPath);\n\t\t\tif (!rawTarget) continue; // unreadable\n\t\t\tconst resolvedTarget = resolveTargetPath(entryPath, rawTarget);\n\t\t\t// Skip dangling links — `fs.stat` follows symlinks and throws\n\t\t\t// ENOENT when the target is missing. That's the signal that\n\t\t\t// the link is broken.\n\t\t\tconst targetStat = await fs.stat(resolvedTarget).catch(() => null);\n\t\t\tif (!targetStat) continue;\n\t\t\tresults.push({\n\t\t\t\trepoId: extractRepoIdFromTarget(resolvedTarget) ?? \"\",\n\t\t\t\tskillName,\n\t\t\t\tlinkPath: entryPath,\n\t\t\t\ttargetPath: resolvedTarget,\n\t\t\t\tmode: process.platform === \"win32\" ? \"junction\" : \"symlink\",\n\t\t\t\tscope,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (entry.isDirectory()) {\n\t\t\t// A real (copy-installed) directory — only counts as an\n\t\t\t// installed entry when it actually carries the expected\n\t\t\t// manifest file, so unrelated junk directories in the scope\n\t\t\t// dir (e.g. leftover `.DS_Store`-adjacent folders) aren't\n\t\t\t// misreported as installed skills/agents.\n\t\t\tconst hasManifest = await fs\n\t\t\t\t.access(path.join(entryPath, MANIFEST_FILENAME[kind]))\n\t\t\t\t.then(() => true)\n\t\t\t\t.catch(() => false);\n\t\t\tif (!hasManifest) continue;\n\t\t\tresults.push({\n\t\t\t\trepoId: \"\",\n\t\t\t\tskillName: entry.name,\n\t\t\t\tlinkPath: entryPath,\n\t\t\t\ttargetPath: entryPath,\n\t\t\t\tmode: \"copy\",\n\t\t\t\tscope,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (entry.isFile() && entry.name.endsWith(`.${kind}.md`)) {\n\t\t\t// A real (copy-installed) flat manifest file, e.g. a plain\n\t\t\t// `CSharpExpert.agent.md` that was placed directly rather\n\t\t\t// than symlinked.\n\t\t\tresults.push({\n\t\t\t\trepoId: \"\",\n\t\t\t\tskillName: entry.name.replace(/\\.(agent|skill)\\.md$/, \"\"),\n\t\t\t\tlinkPath: entryPath,\n\t\t\t\ttargetPath: entryPath,\n\t\t\t\tmode: \"copy\",\n\t\t\t\tscope,\n\t\t\t});\n\t\t}\n\t}\n\treturn results;\n}\n\n// ─────────────────────────────────────────────────────────────────────\n// Internal helpers\n// ─────────────────────────────────────────────────────────────────────\n\n/** Returns `true` when `linkPath` is a symlink/junction pointing at `expectedTarget`. */\nasync function isCorrectLink(linkPath: string, expectedTarget: string): Promise<boolean> {\n\tlet actual: string | undefined;\n\ttry {\n\t\tactual = await readLinkTarget(linkPath);\n\t} catch {\n\t\treturn false;\n\t}\n\tif (!actual) return false;\n\treturn resolveTargetPath(linkPath, actual) === resolveTargetPath(linkPath, expectedTarget);\n}\n\n/** Read a link's target without throwing — returns undefined on ENOENT. */\nasync function readLinkTarget(linkPath: string): Promise<string | undefined> {\n\ttry {\n\t\treturn await fs.readlink(linkPath);\n\t} catch (err) {\n\t\tif ((err as NodeJS.ErrnoException).code === \"ENOENT\") return undefined;\n\t\tthrow err;\n\t}\n}\n\n/**\n * Resolve a relative symlink target against its parent directory so a\n * relative link reads back as an absolute path comparable to another\n * absolute path.\n */\nfunction resolveTargetPath(linkPath: string, target: string): string {\n\tif (path.isAbsolute(target)) return path.normalize(target);\n\treturn path.normalize(path.resolve(path.dirname(linkPath), target));\n}\n\n/**\n * Parse the `<repoId>` segment back out of a resolved link target of\n * the shape `.../.serviceme/repos/<repoId>/{skills,agents}/<name>`.\n * Returns `undefined` when the target doesn't match that shape (e.g. a\n * hand-authored local skill under `~/.agents/skills/<name>` with no\n * backing repo).\n */\nfunction extractRepoIdFromTarget(target: string): string | undefined {\n\tconst marker = `${path.sep}repos${path.sep}`;\n\tconst idx = target.indexOf(marker);\n\tif (idx === -1) return undefined;\n\tconst rest = target.slice(idx + marker.length);\n\tconst [repoId] = rest.split(path.sep);\n\treturn repoId || undefined;\n}\n\n/** Best-effort removal of a path. ENOENT is silently ignored. */\nasync function removeIfExists(p: string): Promise<void> {\n\ttry {\n\t\tconst stat = await fs.lstat(p);\n\t\tif (stat.isDirectory() && !stat.isSymbolicLink()) {\n\t\t\tawait fs.rm(p, { recursive: true, force: true });\n\t\t} else {\n\t\t\tawait fs.unlink(p);\n\t\t}\n\t} catch (err) {\n\t\tif ((err as NodeJS.ErrnoException).code === \"ENOENT\") return;\n\t\tthrow err;\n\t}\n}\n","import * as os from \"node:os\";\nimport * as path from \"node:path\";\n\n/**\n * SERVICEME user home directory helpers.\n *\n * All paths resolve under {@link getServicemeHome}, which is either the\n * `SERVICEME_HOME` environment variable (when set and non-empty) or\n * `$HOME/.serviceme` on POSIX / `%USERPROFILE%\\.serviceme` on Windows.\n *\n * Tests inject `homeDir` and `servicemeHomeEnv` overrides via\n * {@link setUserHomeOverrides} / {@link resetUserHomeOverrides} so they can\n * exercise the path logic without touching the real user environment.\n */\n\n/** Layout constants — kept in one place so other modules can reuse them. */\nexport const SERVICEME_DIR_NAME = \".serviceme\";\nexport const REPOS_SUBDIR = \"repos\";\nexport const CACHE_SUBDIR = \"cache\";\nexport const DRAFTS_SUBDIR = \"drafts\";\nexport const SKILL_DRAFTS_SUBDIR = \"skills\";\nexport const AGENT_DRAFTS_SUBDIR = \"agents\";\nexport const REPOS_CONFIG_FILENAME = \"repos.json\";\n\n/** rev.20 — r7 BYOM Server Proxy toggle self-state (read by ext + CLI + server). */\nexport const SERVER_PROXY_GLOBAL_FILENAME = \"server-proxy.json\";\n\n/**\n * Repo id regex — used to validate any `repoId` argument before it is joined\n * into a filesystem path. Keeps path traversal attempts out and gives us a\n * predictable on-disk shape.\n */\nexport const SAFE_REPO_ID_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/;\n\n/** Environment variable that overrides the user-home root directory. */\nexport const SERVICEME_HOME_ENV = \"SERVICEME_HOME\";\n\n/**\n * Test seam: lets unit tests inject deterministic values for `os.homedir()`\n * and the `SERVICEME_HOME` env override without actually mutating\n * `process.env` (which would leak into other tests).\n */\ninterface UserHomeOverrides {\n\thomeDir?: string | undefined;\n\tservicemeHomeEnv?: string | undefined;\n\tplatform?: NodeJS.Platform | undefined;\n}\n\nlet activeOverrides: UserHomeOverrides = {};\n\nexport function setUserHomeOverrides(overrides: UserHomeOverrides): void {\n\tactiveOverrides = { ...overrides };\n}\n\nexport function resetUserHomeOverrides(): void {\n\tactiveOverrides = {};\n}\n\nfunction resolveHomeDir(): string {\n\tconst injected = activeOverrides.homeDir;\n\tif (injected !== undefined) {\n\t\treturn injected;\n\t}\n\treturn os.homedir();\n}\n\nfunction resolveServicemeHomeEnv(): string | undefined {\n\tconst injected = activeOverrides.servicemeHomeEnv;\n\tif (injected !== undefined) {\n\t\t// Treat empty string as \"not set\" — `process.env` always returns a string\n\t\t// but tests may deliberately pass \"\" to opt out.\n\t\treturn injected.length > 0 ? injected : undefined;\n\t}\n\tconst envValue = process.env[SERVICEME_HOME_ENV];\n\treturn envValue && envValue.length > 0 ? envValue : undefined;\n}\n\nfunction resolvePlatform(): NodeJS.Platform {\n\treturn activeOverrides.platform ?? process.platform;\n}\n\nexport function assertSafeRepoId(repoId: string): string {\n\tif (typeof repoId !== \"string\" || repoId.length === 0 || !SAFE_REPO_ID_PATTERN.test(repoId)) {\n\t\tthrow new Error(\n\t\t\t`Invalid repo id: ${JSON.stringify(repoId)}. ` +\n\t\t\t\t`Must match ${SAFE_REPO_ID_PATTERN} (alphanumeric start, then ` +\n\t\t\t\t`alphanumerics / underscores / hyphens, ≤ 64 chars).`\n\t\t);\n\t}\n\treturn repoId;\n}\n\n/**\n * The raw OS home directory (`os.homedir()`), honoring test overrides\n * ({@link setUserHomeOverrides}). Exported for callers that need a\n * home-relative path *outside* of `~/.serviceme` — e.g. the\n * `~/.agents/{skills,agents}` convention used by `SkillLinker` for\n * user-scope links.\n */\nexport function getHomeDir(): string {\n\treturn resolveHomeDir();\n}\n\n/**\n * Root directory for all SERVICEME user-level state. Resolves to\n * `${SERVICEME_HOME}` when that env var is set, otherwise `${HOME}/.serviceme`\n * (POSIX) or `%USERPROFILE%\\.serviceme` (Windows via `os.homedir`).\n */\nexport function getServicemeHome(): string {\n\tconst override = resolveServicemeHomeEnv();\n\tif (override !== undefined) {\n\t\treturn path.resolve(override);\n\t}\n\treturn path.join(resolveHomeDir(), SERVICEME_DIR_NAME);\n}\n\n/** `$HOME/.serviceme/repos` (or `${SERVICEME_HOME}/repos`). */\nexport function getReposDir(): string {\n\treturn path.join(getServicemeHome(), REPOS_SUBDIR);\n}\n\n/** `$HOME/.serviceme/repos/<repoId>` — validates `repoId` first. */\nexport function getRepoDir(repoId: string): string {\n\treturn path.join(getReposDir(), assertSafeRepoId(repoId));\n}\n\n/** `$HOME/.serviceme/cache` — generic per-user cache. */\nexport function getCacheDir(): string {\n\treturn path.join(getServicemeHome(), CACHE_SUBDIR);\n}\n\n/** `$HOME/.serviceme/cache/<repoId>` — per-repo sync state lives here. */\nexport function getRepoCacheDir(repoId: string): string {\n\treturn path.join(getCacheDir(), assertSafeRepoId(repoId));\n}\n\n/** `$HOME/.serviceme/drafts` — local edits not yet pushed upstream. */\nexport function getDraftsDir(): string {\n\treturn path.join(getServicemeHome(), DRAFTS_SUBDIR);\n}\n\n/** `$HOME/.serviceme/drafts/skills` — local skill drafts. */\nexport function getSkillDraftsDir(): string {\n\treturn path.join(getDraftsDir(), SKILL_DRAFTS_SUBDIR);\n}\n\n/** `$HOME/.serviceme/drafts/agents` — local agent drafts. */\nexport function getAgentDraftsDir(): string {\n\treturn path.join(getDraftsDir(), AGENT_DRAFTS_SUBDIR);\n}\n\n/**\n * `$HOME/.serviceme/repos.json` — the single config entry point for repo\n * metadata. Always under the resolved home root (i.e. follows\n * `SERVICEME_HOME` overrides too).\n */\nexport function getReposConfigPath(): string {\n\treturn path.join(getServicemeHome(), REPOS_CONFIG_FILENAME);\n}\n\n/**\n * Convenience helper for callers that need to switch behaviour on platform\n * (e.g. `SkillLinker` chooses symlink vs junction). Exported mostly so tests\n * can pin the value without touching `process.platform` directly.\n */\nexport function getHomePlatform(): NodeJS.Platform {\n\treturn resolvePlatform();\n}\n\n// ─── Scheduled Tasks paths (added by M1.5.3) ───────────────────────────────\n\n/** Layout constants for scheduled-tasks files. Kept here so other modules\n * can reuse them and the names stay in sync with the design doc. */\nexport const SCHEDULED_TASKS_CONFIG_FILENAME = \"scheduled-tasks.json\";\nexport const SCHEDULED_TASKS_LOG_FILENAME = \"scheduled-tasks-log.json\";\nexport const SCHEDULER_PID_FILENAME = \"scheduler.pid\";\nexport const SCHEDULER_LOCK_FILENAME = \"scheduler.lock\";\nexport const SCHEDULER_LOG_FILENAME = \"scheduler.log\";\nexport const MIGRATION_FAILURES_FILENAME = \"migration-failures.json\";\nexport const KNOWN_WORKSPACES_FILENAME = \"known-workspaces.json\";\n\n/** `~/.serviceme/scheduled-tasks.json` — the global v2 task list. */\nexport function getScheduledTasksConfigPath(): string {\n\treturn path.join(getServicemeHome(), SCHEDULED_TASKS_CONFIG_FILENAME);\n}\n\n/** `~/.serviceme/scheduled-tasks-log.json` — the global execution log (200 LRU). */\nexport function getScheduledTasksLogPath(): string {\n\treturn path.join(getServicemeHome(), SCHEDULED_TASKS_LOG_FILENAME);\n}\n\n/** `~/.serviceme/scheduler.pid` — global daemon PID file. */\nexport function getSchedulerPidPath(): string {\n\treturn path.join(getServicemeHome(), SCHEDULER_PID_FILENAME);\n}\n\n/** `~/.serviceme/scheduler.lock` — global daemon startup flock. */\nexport function getSchedulerLockPath(): string {\n\treturn path.join(getServicemeHome(), SCHEDULER_LOCK_FILENAME);\n}\n\n/** `~/.serviceme/scheduler.log` — global daemon log (daemon lifecycle, not task execution). */\nexport function getSchedulerLogPath(): string {\n\treturn path.join(getServicemeHome(), SCHEDULER_LOG_FILENAME);\n}\n\n/** `~/.serviceme/migration-failures.json` — diagnostics for failed v1→v2 imports. */\nexport function getMigrationFailuresPath(): string {\n\treturn path.join(getServicemeHome(), MIGRATION_FAILURES_FILENAME);\n}\n\n/** `~/.serviceme/known-workspaces.json` — workspace list the extension has seen. */\nexport function getKnownWorkspacesPath(): string {\n\treturn path.join(getServicemeHome(), KNOWN_WORKSPACES_FILENAME);\n}\n\n// ─── r7 BYOM Server Proxy (rev.20) ─────────────────────────────────────────\n\n/**\n * `~/.serviceme/server-proxy.json` — r7 BYOM Server Proxy toggle\n * self-state. Written by the extension's `ProxyConfigService`, readable\n * by the CLI / Server so they can decide whether to route traffic\n * through the corporate proxy without booting VS Code.\n *\n * Lives under user-level `~/.serviceme/` (not under a workspace) because\n * the toggle is a *user preference* — the same human enabling it on\n * machine A should be able to rely on it on machine B after sync, not\n * have it disappear when they switch repos.\n */\nexport function getServerProxyGlobalPath(): string {\n\treturn path.join(getServicemeHome(), SERVER_PROXY_GLOBAL_FILENAME);\n}\n\n// ─── Phase 5 (auth + device + toolbox) placeholders (Spec §11.12) ────────\n\n/** Layout constants for the Phase 5 client-side state files. The server\n * already has the corresponding routes (`/api/v1/auth/...`,\n * `/api/v1/device/...`, etc.) — the client just needs the on-disk\n * file paths + a first-run bootstrap so the auth/device/toolbox\n * services can open + read them without a per-call existence check. */\nexport const CREDENTIALS_CONFIG_FILENAME = \"credentials.json\";\nexport const DEVICE_JSON_FILENAME = \"device.json\";\nexport const TOOLBOX_JSON_FILENAME = \"toolbox.json\";\nexport const MACHINE_ID_FILENAME = \"machine-id\";\nexport const PROFILES_JSON_FILENAME = \"profiles.json\";\n\n/** `~/.serviceme/credentials.json` — better-auth session tokens + refresh state (client-side cache). */\nexport function getCredentialsConfigPath(): string {\n\treturn path.join(getServicemeHome(), CREDENTIALS_CONFIG_FILENAME);\n}\n\n/** `~/.serviceme/device.json` — device enrollment payload (id, public key fingerprint, claimed-by). */\nexport function getDeviceJsonPath(): string {\n\treturn path.join(getServicemeHome(), DEVICE_JSON_FILENAME);\n}\n\n/** `~/.serviceme/toolbox.json` — local toolbox state (installed tool refs, per-user prefs). */\nexport function getToolboxJsonPath(): string {\n\treturn path.join(getServicemeHome(), TOOLBOX_JSON_FILENAME);\n}\n\n/** `~/.serviceme/machine-id` — opaque stable per-install id (uuid v4 string, no JSON wrapper). */\nexport function getMachineIdPath(): string {\n\treturn path.join(getServicemeHome(), MACHINE_ID_FILENAME);\n}\n\n/** `~/.serviceme/profiles.json` — cached projection of server-side profile rows; refresh on demand. */\nexport function getProfilesJsonPath(): string {\n\treturn path.join(getServicemeHome(), PROFILES_JSON_FILENAME);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAoB;AACpB,IAAAA,QAAsB;;;ACDtB,SAAoB;AACpB,WAAsB;AAef,IAAM,qBAAqB;AAC3B,IAAM,eAAe;AAerB,IAAM,uBAAuB;AAG7B,IAAM,qBAAqB;AAalC,IAAI,kBAAqC,CAAC;AAU1C,SAAS,iBAAyB;AACjC,QAAM,WAAW,gBAAgB;AACjC,MAAI,aAAa,QAAW;AAC3B,WAAO;AAAA,EACR;AACA,SAAU,WAAQ;AACnB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,GAAG;AACjD,YAAS,MAAG,GAAG,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;AAAA,IAChD,OAAO;AACN,YAAS,UAAO,CAAC;AAAA,IAClB;AAAA,EACD,SAAS,KAAK;AACb,QAAK,IAA8B,SAAS,SAAU;AACtD,UAAM;AAAA,EACP;AACD;","names":["path","stat"]}
|
|
1
|
+
{"version":3,"sources":["../src/skill-linker/index.ts","../src/paths/userHome.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport { getHomeDir, getRepoDir } from \"../paths/userHome\";\n\n/**\n * Skill & Agent v2 — Client SkillLinker (M3, path-parity revision)\n *\n * SkillLinker exposes a skill/agent from the user's global repos\n * (`~/.serviceme/repos/<repoId>/{skills,agents}/<name>/`) into either:\n *\n * - a workspace, at `<workspace>/.github/{skills,agents}/<name>` —\n * the same path Copilot/Claude actually scan for `SKILL.md` /\n * `AGENT.md`, so linking here has real effect (see the v1 parity\n * note below); or\n * - the user's global scope, at `~/.copilot/{skills,agents}/<name>`,\n * visible to every workspace.\n *\n * **v1 parity note**: an earlier revision linked into a private\n * `<workspace>/.serviceme/skills/<repoId>/<name>` directory. That path\n * is never scanned by the actual tooling, so installs were silently\n * inert. The path was moved to match `.github/skills` (the same\n * location the legacy v1 marketplace pipeline used). Because the link\n * path is now flat (no `<repoId>` segment), only one repo's version of\n * a given `<name>` can be linked into a given scope at a time.\n *\n * Platform behavior (per spec §11.8 — owner explicitly chose throw\n * over silent copy fallback):\n *\n * | platform | default mode | on failure |\n * |----------|--------------|-----------------------------|\n * | macOS | symlink | throw + platform hint |\n * | Linux | symlink | throw + platform hint |\n * | Windows | junction | throw + platform hint |\n *\n * Why junction first on Windows: NTFS junction doesn't require\n * SeCreateSymbolicLinkPrivilege; it works for any user. The limit is\n * the link target must be on a local NTFS volume. OneDrive / network\n * shares sometimes fail; we surface that as a typed error so callers\n * can decide whether to retry.\n *\n * @see docs/architecture/skill-agent-v2-repo.md §5.6 SkillLinker\n * @see docs/architecture/skill-agent-v2-repo.md §11.8 (throw, not copy)\n */\n\nexport type LinkMode = \"symlink\" | \"junction\" | \"copy\";\n\n/** Kind of artifact being linked. Mirrors `BridgeSkillKind`. */\nexport type EntryKind = \"skill\" | \"agent\";\n\n/**\n * Which scope the link lives in:\n * - `\"workspace\"` (default) → `<workspaceDir>/.github/<kind>/<name>`\n * - `\"user\"` → `~/.copilot/<kind>/<name>` (visible to every workspace)\n */\nexport type LinkScope = \"workspace\" | \"user\";\n\nconst ENTRY_SUBDIR: Record<EntryKind, string> = {\n\tskill: \"skills\",\n\tagent: \"agents\",\n};\n\nexport interface InstallSkillOptions {\n\trepoId: string;\n\tskillName: string;\n\tworkspaceDir: string;\n\t/** Choose link mode explicitly. Defaults to platform-optimal. */\n\tmode?: \"auto\" | LinkMode;\n\t/** \"skill\" (default) or \"agent\". */\n\tkind?: EntryKind;\n\t/** \"workspace\" (default) or \"user\". */\n\tscope?: LinkScope;\n\t/**\n\t * Pre-resolved absolute source path (from `SkillStore`), overriding\n\t * the `<repoRoot>/{skills,agents}/<name>` formula in\n\t * {@link resolveSkillTarget}. Required for repos with non-standard\n\t * layouts — flat root (no `skills/` prefix), nested scope dirs\n\t * (`skills/official/<name>`), or flat single-file agent manifests\n\t * (`agents/<name>.agent.md`) — which the formula can't predict.\n\t * When omitted, falls back to the formula (kept for callers that\n\t * install a hand-authored skill without going through `SkillStore`).\n\t */\n\tsourcePath?: string;\n\t/**\n\t * True when `sourcePath` points at a single manifest FILE (e.g. a\n\t * flat `<name>.agent.md`) rather than a directory. Determines the\n\t * symlink type (file vs dir/junction) and the link's basename (the\n\t * link mirrors the source file's name + extension, since Copilot/\n\t * VS Code scan `.github/agents/<name>.agent.md` as a FILE).\n\t */\n\tsourceIsFile?: boolean;\n}\n\nexport interface InstallSkillResult {\n\tmode: LinkMode;\n\tlinkPath: string;\n\ttargetPath: string;\n}\n\n/** Describes one symlink/junction currently present in a workspace/user scope. */\nexport interface LinkedSkill {\n\t/**\n\t * Repo id the link resolves to, parsed back out of the symlink\n\t * target. Empty string when the target isn't under a recognizable\n\t * `~/.serviceme/repos/<repoId>/...` path.\n\t */\n\trepoId: string;\n\tskillName: string;\n\tlinkPath: string;\n\ttargetPath: string;\n\tmode: LinkMode;\n\t/** Which scope this link was found in — \"workspace\" or \"user\" (global). */\n\tscope: LinkScope;\n}\n\n/**\n * Sentinel error for link failures. Carries the chosen mode + platform\n * hint so the UI can render an actionable message.\n */\nexport class LinkError extends Error {\n\treadonly mode: LinkMode;\n\treadonly target: string;\n\treadonly linkPath: string;\n\treadonly platform: NodeJS.Platform;\n\treadonly cause: unknown;\n\n\tconstructor(opts: {\n\t\tmode: LinkMode;\n\t\ttarget: string;\n\t\tlinkPath: string;\n\t\tplatform: NodeJS.Platform;\n\t\tcause: unknown;\n\t}) {\n\t\tsuper(\n\t\t\t`failed to ${opts.mode} link ${opts.linkPath} → ${opts.target} on ${opts.platform}: ${\n\t\t\t\topts.cause instanceof Error ? opts.cause.message : String(opts.cause)\n\t\t\t}`\n\t\t);\n\t\tthis.name = \"LinkError\";\n\t\tthis.mode = opts.mode;\n\t\tthis.target = opts.target;\n\t\tthis.linkPath = opts.linkPath;\n\t\tthis.platform = opts.platform;\n\t\tthis.cause = opts.cause;\n\t}\n\n\t/** A user-facing hint for the platform that failed. */\n\thint(): string {\n\t\treturn getPlatformHint(this.platform);\n\t}\n}\n\n/** Choose the platform-optimal link mode. */\nexport function pickMode(platform: NodeJS.Platform = process.platform): LinkMode {\n\treturn platform === \"win32\" ? \"junction\" : \"symlink\";\n}\n\n/** A short hint string for the platform where the link failed. */\nexport function getPlatformHint(platform: NodeJS.Platform): string {\n\tif (platform === \"win32\") {\n\t\treturn (\n\t\t\t\"On Windows, enable Developer Mode in Settings → Privacy & Security → \" +\n\t\t\t\"For developers, or run as Administrator. NTFS junction also requires the \" +\n\t\t\t\"target to be on a local NTFS volume (OneDrive / network shares are not supported).\"\n\t\t);\n\t}\n\treturn (\n\t\t\"Symlink creation failed. Check filesystem permissions and that the source \" +\n\t\t\"directory exists. On some filesystems (FAT32, exFAT, network mounts) symlinks \" +\n\t\t\"are not supported.\"\n\t);\n}\n\n/**\n * Resolve the source path inside `~/.serviceme/repos/<repoId>/{skills,agents}/<name>`.\n * Exported for callers that need to inspect the target without installing.\n */\nexport function resolveSkillTarget(\n\trepoId: string,\n\tskillName: string,\n\tkind: EntryKind = \"skill\"\n): string {\n\treturn path.join(getRepoDir(repoId), ENTRY_SUBDIR[kind], skillName);\n}\n\n/**\n * Resolve the workspace link path — `<workspaceDir>/.github/{skills,agents}/<name>` —\n * the same directory Copilot/Claude actually scan.\n */\nexport function resolveSkillLinkPath(\n\tworkspaceDir: string,\n\tskillName: string,\n\tkind: EntryKind = \"skill\"\n): string {\n\treturn path.join(workspaceDir, \".github\", ENTRY_SUBDIR[kind], skillName);\n}\n\n/**\n * Resolve the user-scope link path — `~/.copilot/{skills,agents}/<name>` —\n * visible to every workspace.\n */\nexport function resolveUserSkillLinkPath(skillName: string, kind: EntryKind = \"skill\"): string {\n\treturn path.join(getHomeDir(), \".copilot\", ENTRY_SUBDIR[kind], skillName);\n}\n\nfunction resolveLinkPath(opts: {\n\tworkspaceDir: string;\n\tskillName: string;\n\tkind: EntryKind;\n\tscope: LinkScope;\n\t/** When set, use this basename instead of the bare `skillName` — for\n\t * file-based sources the link must mirror the source's filename\n\t * (including its extension) to be scannable at its real path. */\n\tlinkBasename?: string;\n}): string {\n\tif (opts.scope === \"workspace\" && !opts.workspaceDir) {\n\t\tthrow new Error(\n\t\t\t\"workspaceDir is required for scope: 'workspace' (pass scope: 'user' for a global install instead).\"\n\t\t);\n\t}\n\tconst base =\n\t\topts.scope === \"user\"\n\t\t\t? resolveUserSkillLinkPath(opts.skillName, opts.kind)\n\t\t\t: resolveSkillLinkPath(opts.workspaceDir, opts.skillName, opts.kind);\n\treturn opts.linkBasename ? path.join(path.dirname(base), opts.linkBasename) : base;\n}\n\n/**\n * Install a skill into a workspace by creating a link at the standard\n * path. Throws `LinkError` on failure (no silent copy fallback per\n * §11.8).\n *\n * Idempotent: if the correct link already exists, returns the existing\n * record without touching the filesystem. If a *wrong* link exists at\n * the target path, it is replaced.\n */\nexport async function installSkillToWorkspace(\n\topts: InstallSkillOptions\n): Promise<InstallSkillResult> {\n\tconst kind = opts.kind ?? \"skill\";\n\tconst scope = opts.scope ?? \"workspace\";\n\tconst isFile = opts.sourceIsFile ?? false;\n\tconst target = opts.sourcePath ?? resolveSkillTarget(opts.repoId, opts.skillName, kind);\n\tconst linkPath = resolveLinkPath({\n\t\tworkspaceDir: opts.workspaceDir,\n\t\tskillName: opts.skillName,\n\t\tkind,\n\t\tscope,\n\t\tlinkBasename: isFile ? path.basename(target) : undefined,\n\t});\n\n\t// Sanity-check: the skill source directory must exist before we try\n\t// to link it. Otherwise the link would dangle.\n\tawait fs.access(target).catch(() => {\n\t\tthrow new LinkError({\n\t\t\tmode: \"symlink\", // placeholder — mode not chosen yet\n\t\t\ttarget,\n\t\t\tlinkPath,\n\t\t\tplatform: process.platform,\n\t\t\tcause: new Error(`skill source not found: ${target}`),\n\t\t});\n\t});\n\n\t// If the link already exists and points to the right target, no-op.\n\tif (await isCorrectLink(linkPath, target)) {\n\t\treturn { mode: \"symlink\", linkPath, targetPath: target };\n\t}\n\t// Otherwise, remove any stale entry at the path.\n\tawait removeIfExists(linkPath);\n\n\t// Junctions are directory-only — a file source can never use one,\n\t// regardless of platform default. Fall back to a real symlink.\n\tconst requestedMode = opts.mode === undefined || opts.mode === \"auto\" ? pickMode() : opts.mode;\n\tconst mode = isFile && requestedMode === \"junction\" ? \"symlink\" : requestedMode;\n\n\t// Ensure the parent directory exists — fs.symlink does NOT create\n\t// missing parents. The path is `<workspace>/.serviceme/skills/<repoId>/`,\n\t// which is several levels deep on a fresh workspace.\n\tawait fs.mkdir(path.dirname(linkPath), { recursive: true });\n\n\ttry {\n\t\tif (mode === \"junction\") {\n\t\t\t// fs.symlink with type \"junction\" works on Windows for dirs.\n\t\t\tawait fs.symlink(target, linkPath, \"junction\");\n\t\t} else if (mode === \"symlink\") {\n\t\t\t// Windows requires an explicit \"file\" type for file symlinks;\n\t\t\t// POSIX ignores the type argument either way.\n\t\t\tawait fs.symlink(target, linkPath, isFile ? \"file\" : \"dir\");\n\t\t} else {\n\t\t\t// `copy` mode is intentionally NOT implemented for v1 — see\n\t\t\t// spec §11.8 (\"throw, not copy fallback\"). Reaching this branch\n\t\t\t// means a caller explicitly passed `mode: 'copy'`; we treat\n\t\t\t// it as a configuration error rather than silently dropping\n\t\t\t// to copy semantics.\n\t\t\tthrow new LinkError({\n\t\t\t\tmode: \"copy\",\n\t\t\t\ttarget,\n\t\t\t\tlinkPath,\n\t\t\t\tplatform: process.platform,\n\t\t\t\tcause: new Error(\n\t\t\t\t\t\"copy mode is not supported in v1 — see spec §11.8 (throw, not copy fallback)\"\n\t\t\t\t),\n\t\t\t});\n\t\t}\n\t} catch (err) {\n\t\tif (err instanceof LinkError) throw err;\n\t\tthrow new LinkError({\n\t\t\tmode,\n\t\t\ttarget,\n\t\t\tlinkPath,\n\t\t\tplatform: process.platform,\n\t\t\tcause: err,\n\t\t});\n\t}\n\n\treturn { mode, linkPath, targetPath: target };\n}\n\n/**\n * Convert an existing, real (non-symlink) skill/agent directory at the\n * standard scan path into a symlink pointing at the matching global\n * repo entry. Refuses to run when there's nothing real to convert —\n * callers should only surface this action when a marketplace/scope\n * state check already confirmed a non-symlink install is present.\n */\nexport async function convertToSymlink(opts: InstallSkillOptions): Promise<InstallSkillResult> {\n\tconst kind = opts.kind ?? \"skill\";\n\tconst scope = opts.scope ?? \"workspace\";\n\tconst linkPath = resolveLinkPath({\n\t\tworkspaceDir: opts.workspaceDir,\n\t\tskillName: opts.skillName,\n\t\tkind,\n\t\tscope,\n\t\tlinkBasename: opts.sourceIsFile && opts.sourcePath ? path.basename(opts.sourcePath) : undefined,\n\t});\n\n\tconst stat = await fs.lstat(linkPath).catch(() => null);\n\tif (!stat) {\n\t\tthrow new Error(`Nothing installed at ${linkPath} to convert.`);\n\t}\n\tif (stat.isSymbolicLink()) {\n\t\tthrow new Error(`${linkPath} is already a symlink.`);\n\t}\n\n\treturn installSkillToWorkspace(opts);\n}\n\n/**\n * Remove a skill/agent link from a workspace/user scope. Idempotent:\n * succeeds when the link does not exist (no error).\n *\n * Tries the bare `<name>` path first (directory-based entries), then\n * falls back to scanning the scope dir for a `<name>.<ext>` file (flat\n * manifest entries, e.g. `CSharpExpert.agent.md`) — the caller doesn't\n * necessarily still have the source repo entry to know which shape was\n * installed (e.g. the repo may have been removed since).\n */\nexport async function uninstallSkillFromWorkspace(opts: {\n\trepoId: string;\n\tskillName: string;\n\tworkspaceDir: string;\n\tkind?: EntryKind;\n\tscope?: LinkScope;\n}): Promise<void> {\n\tconst kind = opts.kind ?? \"skill\";\n\tconst scope = opts.scope ?? \"workspace\";\n\tconst linkPath = resolveLinkPath({\n\t\tworkspaceDir: opts.workspaceDir,\n\t\tskillName: opts.skillName,\n\t\tkind,\n\t\tscope,\n\t});\n\tif (await pathExists(linkPath)) {\n\t\tawait removeIfExists(linkPath);\n\t\treturn;\n\t}\n\n\tconst scopeDir = path.dirname(linkPath);\n\tlet entries: import(\"node:fs\").Dirent[];\n\ttry {\n\t\tentries = await fs.readdir(scopeDir, { withFileTypes: true });\n\t} catch {\n\t\tentries = []; // primary scope dir missing — fall through (legacy handled below)\n\t}\n\tconst flatMatch = entries.find(\n\t\t(e) => e.name === opts.skillName || e.name.startsWith(`${opts.skillName}.`)\n\t);\n\tif (flatMatch) {\n\t\tawait removeIfExists(path.join(scopeDir, flatMatch.name));\n\t\treturn;\n\t}\n\tif (scope === \"user\") {\n\t\t// Legacy ~/.agents install — the primary root missed, so try there before giving up.\n\t\tconst legacyDir = path.join(getHomeDir(), LEGACY_USER_SCOPE_ROOT, ENTRY_SUBDIR[kind]);\n\t\tconst legacyEntries = await fs.readdir(legacyDir, { withFileTypes: true }).catch(() => []);\n\t\tconst legacyMatch = legacyEntries.find(\n\t\t\t(e) => e.name === opts.skillName || e.name.startsWith(`${opts.skillName}.`)\n\t\t);\n\t\tif (legacyMatch) {\n\t\t\tawait removeIfExists(path.join(legacyDir, legacyMatch.name));\n\t\t}\n\t}\n}\n\n/** `true` when `p` exists (following symlinks is irrelevant — `lstat` is enough). */\nasync function pathExists(p: string): Promise<boolean> {\n\ttry {\n\t\tawait fs.lstat(p);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nconst MANIFEST_FILENAME: Record<EntryKind, string> = {\n\tskill: \"SKILL.md\",\n\tagent: \"AGENT.md\",\n};\n\n/**\n * Legacy user-scope root used before the migration to `~/.copilot`.\n * Kept readable so user-scope listing can surface old links instead of\n * silently hiding content the user still has installed.\n */\nconst LEGACY_USER_SCOPE_ROOT = \".agents\";\n\n/**\n * Enumerate all skill/agent entries currently present in a workspace/user\n * scope — both symlinked installs (`mode: \"symlink\"`/`\"junction\"`) AND\n * real, non-symlink directories/files that already carry a valid\n * manifest (`mode: \"copy\"`). Used by the UI's \"Manage installed skills\"\n * view so it can show a real (copy-installed) entry as installed too —\n * this is common for the user (global) scope, where many skills are\n * placed by other tools/installers as plain copies rather than via this\n * package's symlink-only install flow. `repoId` is `\"\"` for `\"copy\"`\n * entries since there's no symlink target to resolve it from; callers\n * match these by name only. Returns an empty array when the scan\n * directory doesn't exist.\n */\nexport async function listLinkedSkills(\n\tworkspaceDir: string,\n\tkind: EntryKind = \"skill\",\n\tscope: LinkScope = \"workspace\"\n): Promise<LinkedSkill[]> {\n\t// No workspace open + workspace scope requested — nothing to scan.\n\t// Guard explicitly rather than falling through to\n\t// `path.join(\"\", \".github\", ...)`, which resolves to a *relative*\n\t// path (anchored at the process's cwd, not a real workspace) and\n\t// could accidentally match an unrelated directory there.\n\tif (scope === \"workspace\" && !workspaceDir) {\n\t\treturn [];\n\t}\n\tconst userRoot = path.join(getHomeDir(), \".copilot\", ENTRY_SUBDIR[kind]);\n\tconst root = scope === \"user\" ? userRoot : path.join(workspaceDir, \".github\", ENTRY_SUBDIR[kind]);\n\n\tlet entries: import(\"node:fs\").Dirent[];\n\ttry {\n\t\tentries = await fs.readdir(root, { withFileTypes: true });\n\t} catch (err) {\n\t\tif ((err as NodeJS.ErrnoException).code === \"ENOENT\") return [];\n\t\tthrow err;\n\t}\n\n\tconst results: LinkedSkill[] = [];\n\tfor (const entry of entries) {\n\t\tconst entryPath = path.join(root, entry.name);\n\n\t\tif (entry.isSymbolicLink()) {\n\t\t\t// Flat manifest files (e.g. `CSharpExpert.agent.md`) report the\n\t\t\t// bare name, matching what SkillStore/install use elsewhere —\n\t\t\t// otherwise this would look like a different, unrelated entry.\n\t\t\tconst skillName = entry.name.replace(/\\.(agent|skill)\\.md$/, \"\");\n\t\t\tconst rawTarget = await readLinkTarget(entryPath);\n\t\t\tif (!rawTarget) continue; // unreadable\n\t\t\tconst resolvedTarget = resolveTargetPath(entryPath, rawTarget);\n\t\t\t// Skip dangling links — `fs.stat` follows symlinks and throws\n\t\t\t// ENOENT when the target is missing. That's the signal that\n\t\t\t// the link is broken.\n\t\t\tconst targetStat = await fs.stat(resolvedTarget).catch(() => null);\n\t\t\tif (!targetStat) continue;\n\t\t\tresults.push({\n\t\t\t\trepoId: extractRepoIdFromTarget(resolvedTarget) ?? \"\",\n\t\t\t\tskillName,\n\t\t\t\tlinkPath: entryPath,\n\t\t\t\ttargetPath: resolvedTarget,\n\t\t\t\tmode: process.platform === \"win32\" ? \"junction\" : \"symlink\",\n\t\t\t\tscope,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (entry.isDirectory()) {\n\t\t\t// A real (copy-installed) directory — only counts as an\n\t\t\t// installed entry when it actually carries the expected\n\t\t\t// manifest file, so unrelated junk directories in the scope\n\t\t\t// dir (e.g. leftover `.DS_Store`-adjacent folders) aren't\n\t\t\t// misreported as installed skills/agents.\n\t\t\tconst hasManifest = await fs\n\t\t\t\t.access(path.join(entryPath, MANIFEST_FILENAME[kind]))\n\t\t\t\t.then(() => true)\n\t\t\t\t.catch(() => false);\n\t\t\tif (!hasManifest) continue;\n\t\t\tresults.push({\n\t\t\t\trepoId: \"\",\n\t\t\t\tskillName: entry.name,\n\t\t\t\tlinkPath: entryPath,\n\t\t\t\ttargetPath: entryPath,\n\t\t\t\tmode: \"copy\",\n\t\t\t\tscope,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (entry.isFile() && entry.name.endsWith(`.${kind}.md`)) {\n\t\t\t// A real (copy-installed) flat manifest file, e.g. a plain\n\t\t\t// `CSharpExpert.agent.md` that was placed directly rather\n\t\t\t// than symlinked.\n\t\t\tresults.push({\n\t\t\t\trepoId: \"\",\n\t\t\t\tskillName: entry.name.replace(/\\.(agent|skill)\\.md$/, \"\"),\n\t\t\t\tlinkPath: entryPath,\n\t\t\t\ttargetPath: entryPath,\n\t\t\t\tmode: \"copy\",\n\t\t\t\tscope,\n\t\t\t});\n\t\t}\n\t}\n\n\t// Surface legacy ~/.agents entries alongside ~/.copilot so entries installed before\n\t// the scope-root migration (or placed by other tooling) stay visible and manageable.\n\t// ~/.copilot wins on name conflicts.\n\tif (scope === \"user\") {\n\t\tconst seen = new Set(results.map((r) => r.skillName));\n\t\tfor (const legacy of await listLegacyUserScopeSkills(kind)) {\n\t\t\tif (!seen.has(legacy.skillName)) {\n\t\t\t\tresults.push(legacy);\n\t\t\t}\n\t\t}\n\t}\n\treturn results;\n}\n\n/**\n * List entries still living in the legacy `~/.agents` user scope.\n * Read-only: migration is an explicit user action elsewhere.\n */\nexport async function listLegacyUserScopeSkills(kind: EntryKind = \"skill\"): Promise<LinkedSkill[]> {\n\tconst root = path.join(getHomeDir(), LEGACY_USER_SCOPE_ROOT, ENTRY_SUBDIR[kind]);\n\tlet entries: import(\"node:fs\").Dirent[];\n\ttry {\n\t\tentries = await fs.readdir(root, { withFileTypes: true });\n\t} catch (err) {\n\t\tif ((err as NodeJS.ErrnoException).code === \"ENOENT\") return [];\n\t\tthrow err;\n\t}\n\tconst results: LinkedSkill[] = [];\n\tfor (const entry of entries) {\n\t\tconst entryPath = path.join(root, entry.name);\n\t\tif (entry.isSymbolicLink()) {\n\t\t\tconst skillName = entry.name.replace(/\\.(agent|skill)\\.md$/, \"\");\n\t\t\tconst rawTarget = await readLinkTarget(entryPath);\n\t\t\tif (!rawTarget) continue;\n\t\t\tconst resolvedTarget = resolveTargetPath(entryPath, rawTarget);\n\t\t\tconst targetStat = await fs.stat(resolvedTarget).catch(() => null);\n\t\t\tif (!targetStat) continue;\n\t\t\tresults.push({\n\t\t\t\trepoId: extractRepoIdFromTarget(resolvedTarget) ?? \"\",\n\t\t\t\tskillName,\n\t\t\t\tlinkPath: entryPath,\n\t\t\t\ttargetPath: resolvedTarget,\n\t\t\t\tmode: process.platform === \"win32\" ? \"junction\" : \"symlink\",\n\t\t\t\tscope: \"user\",\n\t\t\t});\n\t\t} else if (entry.isDirectory()) {\n\t\t\tconst manifestPath = path.join(entryPath, MANIFEST_FILENAME[kind]);\n\t\t\tconst stat = await fs.stat(manifestPath).catch(() => null);\n\t\t\tif (stat?.isFile()) {\n\t\t\t\tresults.push({\n\t\t\t\t\trepoId: \"\",\n\t\t\t\t\tskillName: entry.name,\n\t\t\t\t\tlinkPath: entryPath,\n\t\t\t\t\ttargetPath: manifestPath,\n\t\t\t\t\tmode: \"copy\",\n\t\t\t\t\tscope: \"user\",\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\treturn results;\n}\n\n// ─────────────────────────────────────────────────────────────────────\n// Internal helpers\n// ─────────────────────────────────────────────────────────────────────\n\n/** Returns `true` when `linkPath` is a symlink/junction pointing at `expectedTarget`. */\nasync function isCorrectLink(linkPath: string, expectedTarget: string): Promise<boolean> {\n\tlet actual: string | undefined;\n\ttry {\n\t\tactual = await readLinkTarget(linkPath);\n\t} catch {\n\t\treturn false;\n\t}\n\tif (!actual) return false;\n\treturn resolveTargetPath(linkPath, actual) === resolveTargetPath(linkPath, expectedTarget);\n}\n\n/** Read a link's target without throwing — returns undefined on ENOENT. */\nasync function readLinkTarget(linkPath: string): Promise<string | undefined> {\n\ttry {\n\t\treturn await fs.readlink(linkPath);\n\t} catch (err) {\n\t\tif ((err as NodeJS.ErrnoException).code === \"ENOENT\") return undefined;\n\t\tthrow err;\n\t}\n}\n\n/**\n * Resolve a relative symlink target against its parent directory so a\n * relative link reads back as an absolute path comparable to another\n * absolute path.\n */\nfunction resolveTargetPath(linkPath: string, target: string): string {\n\tif (path.isAbsolute(target)) return path.normalize(target);\n\treturn path.normalize(path.resolve(path.dirname(linkPath), target));\n}\n\n/**\n * Parse the `<repoId>` segment back out of a resolved link target of\n * the shape `.../.serviceme/repos/<repoId>/{skills,agents}/<name>`.\n * Returns `undefined` when the target doesn't match that shape (e.g. a\n * hand-authored local skill under `~/.agents/skills/<name>` with no\n * backing repo).\n */\nfunction extractRepoIdFromTarget(target: string): string | undefined {\n\tconst marker = `${path.sep}repos${path.sep}`;\n\tconst idx = target.indexOf(marker);\n\tif (idx === -1) return undefined;\n\tconst rest = target.slice(idx + marker.length);\n\tconst [repoId] = rest.split(path.sep);\n\treturn repoId || undefined;\n}\n\n/** Best-effort removal of a path. ENOENT is silently ignored. */\nasync function removeIfExists(p: string): Promise<void> {\n\ttry {\n\t\tconst stat = await fs.lstat(p);\n\t\tif (stat.isDirectory() && !stat.isSymbolicLink()) {\n\t\t\tawait fs.rm(p, { recursive: true, force: true });\n\t\t} else {\n\t\t\tawait fs.unlink(p);\n\t\t}\n\t} catch (err) {\n\t\tif ((err as NodeJS.ErrnoException).code === \"ENOENT\") return;\n\t\tthrow err;\n\t}\n}\n","import * as os from \"node:os\";\nimport * as path from \"node:path\";\n\n/**\n * SERVICEME user home directory helpers.\n *\n * All paths resolve under {@link getServicemeHome}, which is either the\n * `SERVICEME_HOME` environment variable (when set and non-empty) or\n * `$HOME/.serviceme` on POSIX / `%USERPROFILE%\\.serviceme` on Windows.\n *\n * Tests inject `homeDir` and `servicemeHomeEnv` overrides via\n * {@link setUserHomeOverrides} / {@link resetUserHomeOverrides} so they can\n * exercise the path logic without touching the real user environment.\n */\n\n/** Layout constants — kept in one place so other modules can reuse them. */\nexport const SERVICEME_DIR_NAME = \".serviceme\";\nexport const REPOS_SUBDIR = \"repos\";\nexport const CACHE_SUBDIR = \"cache\";\nexport const DRAFTS_SUBDIR = \"drafts\";\nexport const SKILL_DRAFTS_SUBDIR = \"skills\";\nexport const AGENT_DRAFTS_SUBDIR = \"agents\";\nexport const REPOS_CONFIG_FILENAME = \"repos.json\";\nexport const WORKSPACES_SUBDIR = \"workspaces\";\nexport const WORKSPACE_CONTENT_STATE_FILENAME = \"copilot-content-state.json\";\n\n/** rev.20 — r7 BYOM Server Proxy toggle self-state (read by ext + CLI + server). */\nexport const SERVER_PROXY_GLOBAL_FILENAME = \"server-proxy.json\";\n\n/**\n * Repo id regex — used to validate any `repoId` argument before it is joined\n * into a filesystem path. Keeps path traversal attempts out and gives us a\n * predictable on-disk shape.\n */\nexport const SAFE_REPO_ID_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/;\n\n/** Environment variable that overrides the user-home root directory. */\nexport const SERVICEME_HOME_ENV = \"SERVICEME_HOME\";\n\n/**\n * Test seam: lets unit tests inject deterministic values for `os.homedir()`\n * and the `SERVICEME_HOME` env override without actually mutating\n * `process.env` (which would leak into other tests).\n */\ninterface UserHomeOverrides {\n\thomeDir?: string | undefined;\n\tservicemeHomeEnv?: string | undefined;\n\tplatform?: NodeJS.Platform | undefined;\n}\n\nlet activeOverrides: UserHomeOverrides = {};\n\nexport function setUserHomeOverrides(overrides: UserHomeOverrides): void {\n\tactiveOverrides = { ...overrides };\n}\n\nexport function resetUserHomeOverrides(): void {\n\tactiveOverrides = {};\n}\n\nfunction resolveHomeDir(): string {\n\tconst injected = activeOverrides.homeDir;\n\tif (injected !== undefined) {\n\t\treturn injected;\n\t}\n\treturn os.homedir();\n}\n\nfunction resolveServicemeHomeEnv(): string | undefined {\n\tconst injected = activeOverrides.servicemeHomeEnv;\n\tif (injected !== undefined) {\n\t\t// Treat empty string as \"not set\" — `process.env` always returns a string\n\t\t// but tests may deliberately pass \"\" to opt out.\n\t\treturn injected.length > 0 ? injected : undefined;\n\t}\n\tconst envValue = process.env[SERVICEME_HOME_ENV];\n\treturn envValue && envValue.length > 0 ? envValue : undefined;\n}\n\nfunction resolvePlatform(): NodeJS.Platform {\n\treturn activeOverrides.platform ?? process.platform;\n}\n\nexport function assertSafeRepoId(repoId: string): string {\n\tif (typeof repoId !== \"string\" || repoId.length === 0 || !SAFE_REPO_ID_PATTERN.test(repoId)) {\n\t\tthrow new Error(\n\t\t\t`Invalid repo id: ${JSON.stringify(repoId)}. ` +\n\t\t\t\t`Must match ${SAFE_REPO_ID_PATTERN} (alphanumeric start, then ` +\n\t\t\t\t`alphanumerics / underscores / hyphens, ≤ 64 chars).`\n\t\t);\n\t}\n\treturn repoId;\n}\n\n/**\n * The raw OS home directory (`os.homedir()`), honoring test overrides\n * ({@link setUserHomeOverrides}). Exported for callers that need a\n * home-relative path *outside* of `~/.serviceme` — e.g. the\n * `~/.agents/{skills,agents}` convention used by `SkillLinker` for\n * user-scope links.\n */\nexport function getHomeDir(): string {\n\treturn resolveHomeDir();\n}\n\n/**\n * Root directory for all SERVICEME user-level state. Resolves to\n * `${SERVICEME_HOME}` when that env var is set, otherwise `${HOME}/.serviceme`\n * (POSIX) or `%USERPROFILE%\\.serviceme` (Windows via `os.homedir`).\n */\nexport function getServicemeHome(): string {\n\tconst override = resolveServicemeHomeEnv();\n\tif (override !== undefined) {\n\t\treturn path.resolve(override);\n\t}\n\treturn path.join(resolveHomeDir(), SERVICEME_DIR_NAME);\n}\n\n/** `$HOME/.serviceme/repos` (or `${SERVICEME_HOME}/repos`). */\nexport function getReposDir(): string {\n\treturn path.join(getServicemeHome(), REPOS_SUBDIR);\n}\n\n/** `$HOME/.serviceme/repos/<repoId>` — validates `repoId` first. */\nexport function getRepoDir(repoId: string): string {\n\treturn path.join(getReposDir(), assertSafeRepoId(repoId));\n}\n\n/** `$HOME/.serviceme/cache` — generic per-user cache. */\nexport function getCacheDir(): string {\n\treturn path.join(getServicemeHome(), CACHE_SUBDIR);\n}\n\n/** `$HOME/.serviceme/cache/<repoId>` — per-repo sync state lives here. */\nexport function getRepoCacheDir(repoId: string): string {\n\treturn path.join(getCacheDir(), assertSafeRepoId(repoId));\n}\n\n/** `$HOME/.serviceme/drafts` — local edits not yet pushed upstream. */\nexport function getDraftsDir(): string {\n\treturn path.join(getServicemeHome(), DRAFTS_SUBDIR);\n}\n\n/** `$HOME/.serviceme/drafts/skills` — local skill drafts. */\nexport function getSkillDraftsDir(): string {\n\treturn path.join(getDraftsDir(), SKILL_DRAFTS_SUBDIR);\n}\n\n/** `$HOME/.serviceme/drafts/agents` — local agent drafts. */\nexport function getAgentDraftsDir(): string {\n\treturn path.join(getDraftsDir(), AGENT_DRAFTS_SUBDIR);\n}\n\n/**\n * `$HOME/.serviceme/repos.json` — the single config entry point for repo\n * metadata. Always under the resolved home root (i.e. follows\n * `SERVICEME_HOME` overrides too).\n */\nexport function getReposConfigPath(): string {\n\treturn path.join(getServicemeHome(), REPOS_CONFIG_FILENAME);\n}\n\n/** `~/.serviceme/workspaces` — machine-local per-workspace state root. */\nexport function getWorkspacesDir(): string {\n\treturn path.join(getServicemeHome(), WORKSPACES_SUBDIR);\n}\n\n/**\n * Convenience helper for callers that need to switch behaviour on platform\n * (e.g. `SkillLinker` chooses symlink vs junction). Exported mostly so tests\n * can pin the value without touching `process.platform` directly.\n */\nexport function getHomePlatform(): NodeJS.Platform {\n\treturn resolvePlatform();\n}\n\n// ─── Scheduled Tasks paths (added by M1.5.3) ───────────────────────────────\n\n/** Layout constants for scheduled-tasks files. Kept here so other modules\n * can reuse them and the names stay in sync with the design doc. */\nexport const SCHEDULED_TASKS_CONFIG_FILENAME = \"scheduled-tasks.json\";\nexport const SCHEDULED_TASKS_LOG_FILENAME = \"scheduled-tasks-log.json\";\nexport const SCHEDULER_PID_FILENAME = \"scheduler.pid\";\nexport const SCHEDULER_LOCK_FILENAME = \"scheduler.lock\";\nexport const SCHEDULER_LOG_FILENAME = \"scheduler.log\";\nexport const MIGRATION_FAILURES_FILENAME = \"migration-failures.json\";\nexport const KNOWN_WORKSPACES_FILENAME = \"known-workspaces.json\";\n\n/** `~/.serviceme/scheduled-tasks.json` — the global v2 task list. */\nexport function getScheduledTasksConfigPath(): string {\n\treturn path.join(getServicemeHome(), SCHEDULED_TASKS_CONFIG_FILENAME);\n}\n\n/** `~/.serviceme/scheduled-tasks-log.json` — the global execution log (200 LRU). */\nexport function getScheduledTasksLogPath(): string {\n\treturn path.join(getServicemeHome(), SCHEDULED_TASKS_LOG_FILENAME);\n}\n\n/** `~/.serviceme/scheduler.pid` — global daemon PID file. */\nexport function getSchedulerPidPath(): string {\n\treturn path.join(getServicemeHome(), SCHEDULER_PID_FILENAME);\n}\n\n/** `~/.serviceme/scheduler.lock` — global daemon startup flock. */\nexport function getSchedulerLockPath(): string {\n\treturn path.join(getServicemeHome(), SCHEDULER_LOCK_FILENAME);\n}\n\n/** `~/.serviceme/scheduler.log` — global daemon log (daemon lifecycle, not task execution). */\nexport function getSchedulerLogPath(): string {\n\treturn path.join(getServicemeHome(), SCHEDULER_LOG_FILENAME);\n}\n\n/** `~/.serviceme/migration-failures.json` — diagnostics for failed v1→v2 imports. */\nexport function getMigrationFailuresPath(): string {\n\treturn path.join(getServicemeHome(), MIGRATION_FAILURES_FILENAME);\n}\n\n/** `~/.serviceme/known-workspaces.json` — workspace list the extension has seen. */\nexport function getKnownWorkspacesPath(): string {\n\treturn path.join(getServicemeHome(), KNOWN_WORKSPACES_FILENAME);\n}\n\n// ─── r7 BYOM Server Proxy (rev.20) ─────────────────────────────────────────\n\n/**\n * `~/.serviceme/server-proxy.json` — r7 BYOM Server Proxy toggle\n * self-state. Written by the extension's `ProxyConfigService`, readable\n * by the CLI / Server so they can decide whether to route traffic\n * through the corporate proxy without booting VS Code.\n *\n * Lives under user-level `~/.serviceme/` (not under a workspace) because\n * the toggle is a *user preference* — the same human enabling it on\n * machine A should be able to rely on it on machine B after sync, not\n * have it disappear when they switch repos.\n */\nexport function getServerProxyGlobalPath(): string {\n\treturn path.join(getServicemeHome(), SERVER_PROXY_GLOBAL_FILENAME);\n}\n\n// ─── Phase 5 (auth + device + toolbox) placeholders (Spec §11.12) ────────\n\n/** Layout constants for the Phase 5 client-side state files. The server\n * already has the corresponding routes (`/api/v1/auth/...`,\n * `/api/v1/device/...`, etc.) — the client just needs the on-disk\n * file paths + a first-run bootstrap so the auth/device/toolbox\n * services can open + read them without a per-call existence check. */\nexport const CREDENTIALS_CONFIG_FILENAME = \"credentials.json\";\nexport const DEVICE_JSON_FILENAME = \"device.json\";\nexport const TOOLBOX_JSON_FILENAME = \"toolbox.json\";\nexport const MACHINE_ID_FILENAME = \"machine-id\";\nexport const PROFILES_JSON_FILENAME = \"profiles.json\";\n\n/** `~/.serviceme/credentials.json` — better-auth session tokens + refresh state (client-side cache). */\nexport function getCredentialsConfigPath(): string {\n\treturn path.join(getServicemeHome(), CREDENTIALS_CONFIG_FILENAME);\n}\n\n/** `~/.serviceme/device.json` — device enrollment payload (id, public key fingerprint, claimed-by). */\nexport function getDeviceJsonPath(): string {\n\treturn path.join(getServicemeHome(), DEVICE_JSON_FILENAME);\n}\n\n/** `~/.serviceme/toolbox.json` — local toolbox state (installed tool refs, per-user prefs). */\nexport function getToolboxJsonPath(): string {\n\treturn path.join(getServicemeHome(), TOOLBOX_JSON_FILENAME);\n}\n\n/** `~/.serviceme/machine-id` — opaque stable per-install id (uuid v4 string, no JSON wrapper). */\nexport function getMachineIdPath(): string {\n\treturn path.join(getServicemeHome(), MACHINE_ID_FILENAME);\n}\n\n/** `~/.serviceme/profiles.json` — cached projection of server-side profile rows; refresh on demand. */\nexport function getProfilesJsonPath(): string {\n\treturn path.join(getServicemeHome(), PROFILES_JSON_FILENAME);\n}\n"],"mappings":";;;;;;;;;;;;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K,IAA8B,SAAS,SAAU;AACtD,UAAM;AAAA,EACP;AACD;","names":["path","stat"]}
|
package/dist/skill-linker.mjs
CHANGED
|
@@ -88,7 +88,7 @@ function resolveSkillLinkPath(workspaceDir, skillName, kind = "skill") {
|
|
|
88
88
|
return path2.join(workspaceDir, ".github", ENTRY_SUBDIR[kind], skillName);
|
|
89
89
|
}
|
|
90
90
|
function resolveUserSkillLinkPath(skillName, kind = "skill") {
|
|
91
|
-
return path2.join(getHomeDir(), ".
|
|
91
|
+
return path2.join(getHomeDir(), ".copilot", ENTRY_SUBDIR[kind], skillName);
|
|
92
92
|
}
|
|
93
93
|
function resolveLinkPath(opts) {
|
|
94
94
|
if (opts.scope === "workspace" && !opts.workspaceDir) {
|
|
@@ -193,13 +193,24 @@ async function uninstallSkillFromWorkspace(opts) {
|
|
|
193
193
|
try {
|
|
194
194
|
entries = await fs.readdir(scopeDir, { withFileTypes: true });
|
|
195
195
|
} catch {
|
|
196
|
-
|
|
196
|
+
entries = [];
|
|
197
197
|
}
|
|
198
198
|
const flatMatch = entries.find(
|
|
199
199
|
(e) => e.name === opts.skillName || e.name.startsWith(`${opts.skillName}.`)
|
|
200
200
|
);
|
|
201
201
|
if (flatMatch) {
|
|
202
202
|
await removeIfExists(path2.join(scopeDir, flatMatch.name));
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
if (scope === "user") {
|
|
206
|
+
const legacyDir = path2.join(getHomeDir(), LEGACY_USER_SCOPE_ROOT, ENTRY_SUBDIR[kind]);
|
|
207
|
+
const legacyEntries = await fs.readdir(legacyDir, { withFileTypes: true }).catch(() => []);
|
|
208
|
+
const legacyMatch = legacyEntries.find(
|
|
209
|
+
(e) => e.name === opts.skillName || e.name.startsWith(`${opts.skillName}.`)
|
|
210
|
+
);
|
|
211
|
+
if (legacyMatch) {
|
|
212
|
+
await removeIfExists(path2.join(legacyDir, legacyMatch.name));
|
|
213
|
+
}
|
|
203
214
|
}
|
|
204
215
|
}
|
|
205
216
|
async function pathExists(p) {
|
|
@@ -214,11 +225,13 @@ var MANIFEST_FILENAME = {
|
|
|
214
225
|
skill: "SKILL.md",
|
|
215
226
|
agent: "AGENT.md"
|
|
216
227
|
};
|
|
228
|
+
var LEGACY_USER_SCOPE_ROOT = ".agents";
|
|
217
229
|
async function listLinkedSkills(workspaceDir, kind = "skill", scope = "workspace") {
|
|
218
230
|
if (scope === "workspace" && !workspaceDir) {
|
|
219
231
|
return [];
|
|
220
232
|
}
|
|
221
|
-
const
|
|
233
|
+
const userRoot = path2.join(getHomeDir(), ".copilot", ENTRY_SUBDIR[kind]);
|
|
234
|
+
const root = scope === "user" ? userRoot : path2.join(workspaceDir, ".github", ENTRY_SUBDIR[kind]);
|
|
222
235
|
let entries;
|
|
223
236
|
try {
|
|
224
237
|
entries = await fs.readdir(root, { withFileTypes: true });
|
|
@@ -270,6 +283,58 @@ async function listLinkedSkills(workspaceDir, kind = "skill", scope = "workspace
|
|
|
270
283
|
});
|
|
271
284
|
}
|
|
272
285
|
}
|
|
286
|
+
if (scope === "user") {
|
|
287
|
+
const seen = new Set(results.map((r) => r.skillName));
|
|
288
|
+
for (const legacy of await listLegacyUserScopeSkills(kind)) {
|
|
289
|
+
if (!seen.has(legacy.skillName)) {
|
|
290
|
+
results.push(legacy);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return results;
|
|
295
|
+
}
|
|
296
|
+
async function listLegacyUserScopeSkills(kind = "skill") {
|
|
297
|
+
const root = path2.join(getHomeDir(), LEGACY_USER_SCOPE_ROOT, ENTRY_SUBDIR[kind]);
|
|
298
|
+
let entries;
|
|
299
|
+
try {
|
|
300
|
+
entries = await fs.readdir(root, { withFileTypes: true });
|
|
301
|
+
} catch (err) {
|
|
302
|
+
if (err.code === "ENOENT") return [];
|
|
303
|
+
throw err;
|
|
304
|
+
}
|
|
305
|
+
const results = [];
|
|
306
|
+
for (const entry of entries) {
|
|
307
|
+
const entryPath = path2.join(root, entry.name);
|
|
308
|
+
if (entry.isSymbolicLink()) {
|
|
309
|
+
const skillName = entry.name.replace(/\.(agent|skill)\.md$/, "");
|
|
310
|
+
const rawTarget = await readLinkTarget(entryPath);
|
|
311
|
+
if (!rawTarget) continue;
|
|
312
|
+
const resolvedTarget = resolveTargetPath(entryPath, rawTarget);
|
|
313
|
+
const targetStat = await fs.stat(resolvedTarget).catch(() => null);
|
|
314
|
+
if (!targetStat) continue;
|
|
315
|
+
results.push({
|
|
316
|
+
repoId: extractRepoIdFromTarget(resolvedTarget) ?? "",
|
|
317
|
+
skillName,
|
|
318
|
+
linkPath: entryPath,
|
|
319
|
+
targetPath: resolvedTarget,
|
|
320
|
+
mode: process.platform === "win32" ? "junction" : "symlink",
|
|
321
|
+
scope: "user"
|
|
322
|
+
});
|
|
323
|
+
} else if (entry.isDirectory()) {
|
|
324
|
+
const manifestPath = path2.join(entryPath, MANIFEST_FILENAME[kind]);
|
|
325
|
+
const stat2 = await fs.stat(manifestPath).catch(() => null);
|
|
326
|
+
if (stat2?.isFile()) {
|
|
327
|
+
results.push({
|
|
328
|
+
repoId: "",
|
|
329
|
+
skillName: entry.name,
|
|
330
|
+
linkPath: entryPath,
|
|
331
|
+
targetPath: manifestPath,
|
|
332
|
+
mode: "copy",
|
|
333
|
+
scope: "user"
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
273
338
|
return results;
|
|
274
339
|
}
|
|
275
340
|
async function isCorrectLink(linkPath, expectedTarget) {
|
|
@@ -320,6 +385,7 @@ export {
|
|
|
320
385
|
convertToSymlink,
|
|
321
386
|
getPlatformHint,
|
|
322
387
|
installSkillToWorkspace,
|
|
388
|
+
listLegacyUserScopeSkills,
|
|
323
389
|
listLinkedSkills,
|
|
324
390
|
pickMode,
|
|
325
391
|
resolveSkillLinkPath,
|