@serviceme/devtools-core 0.1.8 → 0.2.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.
Files changed (47) hide show
  1. package/dist/auth.d.mts +590 -0
  2. package/dist/auth.d.ts +590 -0
  3. package/dist/auth.js +842 -0
  4. package/dist/auth.js.map +1 -0
  5. package/dist/auth.mjs +804 -0
  6. package/dist/auth.mjs.map +1 -0
  7. package/dist/device.d.mts +456 -0
  8. package/dist/device.d.ts +456 -0
  9. package/dist/device.js +696 -0
  10. package/dist/device.js.map +1 -0
  11. package/dist/device.mjs +647 -0
  12. package/dist/device.mjs.map +1 -0
  13. package/dist/index-CrNC-aao.d.ts +277 -0
  14. package/dist/index-Dmyy4urr.d.mts +277 -0
  15. package/dist/index.d.mts +1372 -27
  16. package/dist/index.d.ts +1372 -27
  17. package/dist/index.js +5125 -888
  18. package/dist/index.js.map +1 -0
  19. package/dist/index.mjs +5022 -906
  20. package/dist/index.mjs.map +1 -0
  21. package/dist/skill-linker.d.mts +188 -0
  22. package/dist/skill-linker.d.ts +188 -0
  23. package/dist/skill-linker.js +374 -0
  24. package/dist/skill-linker.js.map +1 -0
  25. package/dist/skill-linker.mjs +330 -0
  26. package/dist/skill-linker.mjs.map +1 -0
  27. package/dist/skill-store.d.mts +35 -0
  28. package/dist/skill-store.d.ts +35 -0
  29. package/dist/skill-store.js +291 -0
  30. package/dist/skill-store.js.map +1 -0
  31. package/dist/skill-store.mjs +254 -0
  32. package/dist/skill-store.mjs.map +1 -0
  33. package/dist/submit.d.mts +3 -0
  34. package/dist/submit.d.ts +3 -0
  35. package/dist/submit.js +166 -0
  36. package/dist/submit.js.map +1 -0
  37. package/dist/submit.mjs +130 -0
  38. package/dist/submit.mjs.map +1 -0
  39. package/dist/toolbox.d.mts +240 -0
  40. package/dist/toolbox.d.ts +240 -0
  41. package/dist/toolbox.js +530 -0
  42. package/dist/toolbox.js.map +1 -0
  43. package/dist/toolbox.mjs +482 -0
  44. package/dist/toolbox.mjs.map +1 -0
  45. package/dist/types-B9gk3dXH.d.mts +62 -0
  46. package/dist/types-B9gk3dXH.d.ts +62 -0
  47. package/package.json +50 -5
@@ -0,0 +1,374 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/skill-linker/index.ts
31
+ var skill_linker_exports = {};
32
+ __export(skill_linker_exports, {
33
+ LinkError: () => LinkError,
34
+ convertToSymlink: () => convertToSymlink,
35
+ getPlatformHint: () => getPlatformHint,
36
+ installSkillToWorkspace: () => installSkillToWorkspace,
37
+ listLinkedSkills: () => listLinkedSkills,
38
+ pickMode: () => pickMode,
39
+ resolveSkillLinkPath: () => resolveSkillLinkPath,
40
+ resolveSkillTarget: () => resolveSkillTarget,
41
+ resolveUserSkillLinkPath: () => resolveUserSkillLinkPath,
42
+ uninstallSkillFromWorkspace: () => uninstallSkillFromWorkspace
43
+ });
44
+ module.exports = __toCommonJS(skill_linker_exports);
45
+ var fs = __toESM(require("fs/promises"));
46
+ var path2 = __toESM(require("path"));
47
+
48
+ // src/paths/userHome.ts
49
+ var os = __toESM(require("os"));
50
+ var path = __toESM(require("path"));
51
+ var SERVICEME_DIR_NAME = ".serviceme";
52
+ var REPOS_SUBDIR = "repos";
53
+ var SAFE_REPO_ID_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$/;
54
+ var SERVICEME_HOME_ENV = "SERVICEME_HOME";
55
+ var activeOverrides = {};
56
+ function resolveHomeDir() {
57
+ const injected = activeOverrides.homeDir;
58
+ if (injected !== void 0) {
59
+ return injected;
60
+ }
61
+ return os.homedir();
62
+ }
63
+ function resolveServicemeHomeEnv() {
64
+ const injected = activeOverrides.servicemeHomeEnv;
65
+ if (injected !== void 0) {
66
+ return injected.length > 0 ? injected : void 0;
67
+ }
68
+ const envValue = process.env[SERVICEME_HOME_ENV];
69
+ return envValue && envValue.length > 0 ? envValue : void 0;
70
+ }
71
+ function assertSafeRepoId(repoId) {
72
+ if (typeof repoId !== "string" || repoId.length === 0 || !SAFE_REPO_ID_PATTERN.test(repoId)) {
73
+ throw new Error(
74
+ `Invalid repo id: ${JSON.stringify(repoId)}. Must match ${SAFE_REPO_ID_PATTERN} (alphanumeric start, then alphanumerics / underscores / hyphens, \u2264 64 chars).`
75
+ );
76
+ }
77
+ return repoId;
78
+ }
79
+ function getHomeDir() {
80
+ return resolveHomeDir();
81
+ }
82
+ function getServicemeHome() {
83
+ const override = resolveServicemeHomeEnv();
84
+ if (override !== void 0) {
85
+ return path.resolve(override);
86
+ }
87
+ return path.join(resolveHomeDir(), SERVICEME_DIR_NAME);
88
+ }
89
+ function getReposDir() {
90
+ return path.join(getServicemeHome(), REPOS_SUBDIR);
91
+ }
92
+ function getRepoDir(repoId) {
93
+ return path.join(getReposDir(), assertSafeRepoId(repoId));
94
+ }
95
+
96
+ // src/skill-linker/index.ts
97
+ var ENTRY_SUBDIR = {
98
+ skill: "skills",
99
+ agent: "agents"
100
+ };
101
+ var LinkError = class extends Error {
102
+ constructor(opts) {
103
+ super(
104
+ `failed to ${opts.mode} link ${opts.linkPath} \u2192 ${opts.target} on ${opts.platform}: ${opts.cause instanceof Error ? opts.cause.message : String(opts.cause)}`
105
+ );
106
+ this.name = "LinkError";
107
+ this.mode = opts.mode;
108
+ this.target = opts.target;
109
+ this.linkPath = opts.linkPath;
110
+ this.platform = opts.platform;
111
+ this.cause = opts.cause;
112
+ }
113
+ /** A user-facing hint for the platform that failed. */
114
+ hint() {
115
+ return getPlatformHint(this.platform);
116
+ }
117
+ };
118
+ function pickMode(platform = process.platform) {
119
+ return platform === "win32" ? "junction" : "symlink";
120
+ }
121
+ function getPlatformHint(platform) {
122
+ if (platform === "win32") {
123
+ return "On Windows, enable Developer Mode in Settings \u2192 Privacy & Security \u2192 For developers, or run as Administrator. NTFS junction also requires the target to be on a local NTFS volume (OneDrive / network shares are not supported).";
124
+ }
125
+ return "Symlink creation failed. Check filesystem permissions and that the source directory exists. On some filesystems (FAT32, exFAT, network mounts) symlinks are not supported.";
126
+ }
127
+ function resolveSkillTarget(repoId, skillName, kind = "skill") {
128
+ return path2.join(getRepoDir(repoId), ENTRY_SUBDIR[kind], skillName);
129
+ }
130
+ function resolveSkillLinkPath(workspaceDir, skillName, kind = "skill") {
131
+ return path2.join(workspaceDir, ".github", ENTRY_SUBDIR[kind], skillName);
132
+ }
133
+ function resolveUserSkillLinkPath(skillName, kind = "skill") {
134
+ return path2.join(getHomeDir(), ".agents", ENTRY_SUBDIR[kind], skillName);
135
+ }
136
+ function resolveLinkPath(opts) {
137
+ if (opts.scope === "workspace" && !opts.workspaceDir) {
138
+ throw new Error(
139
+ "workspaceDir is required for scope: 'workspace' (pass scope: 'user' for a global install instead)."
140
+ );
141
+ }
142
+ const base = opts.scope === "user" ? resolveUserSkillLinkPath(opts.skillName, opts.kind) : resolveSkillLinkPath(opts.workspaceDir, opts.skillName, opts.kind);
143
+ return opts.linkBasename ? path2.join(path2.dirname(base), opts.linkBasename) : base;
144
+ }
145
+ async function installSkillToWorkspace(opts) {
146
+ const kind = opts.kind ?? "skill";
147
+ const scope = opts.scope ?? "workspace";
148
+ const isFile = opts.sourceIsFile ?? false;
149
+ const target = opts.sourcePath ?? resolveSkillTarget(opts.repoId, opts.skillName, kind);
150
+ const linkPath = resolveLinkPath({
151
+ workspaceDir: opts.workspaceDir,
152
+ skillName: opts.skillName,
153
+ kind,
154
+ scope,
155
+ linkBasename: isFile ? path2.basename(target) : void 0
156
+ });
157
+ await fs.access(target).catch(() => {
158
+ throw new LinkError({
159
+ mode: "symlink",
160
+ // placeholder — mode not chosen yet
161
+ target,
162
+ linkPath,
163
+ platform: process.platform,
164
+ cause: new Error(`skill source not found: ${target}`)
165
+ });
166
+ });
167
+ if (await isCorrectLink(linkPath, target)) {
168
+ return { mode: "symlink", linkPath, targetPath: target };
169
+ }
170
+ await removeIfExists(linkPath);
171
+ const requestedMode = opts.mode === void 0 || opts.mode === "auto" ? pickMode() : opts.mode;
172
+ const mode = isFile && requestedMode === "junction" ? "symlink" : requestedMode;
173
+ await fs.mkdir(path2.dirname(linkPath), { recursive: true });
174
+ try {
175
+ if (mode === "junction") {
176
+ await fs.symlink(target, linkPath, "junction");
177
+ } else if (mode === "symlink") {
178
+ await fs.symlink(target, linkPath, isFile ? "file" : "dir");
179
+ } else {
180
+ throw new LinkError({
181
+ mode: "copy",
182
+ target,
183
+ linkPath,
184
+ platform: process.platform,
185
+ cause: new Error(
186
+ "copy mode is not supported in v1 \u2014 see spec \xA711.8 (throw, not copy fallback)"
187
+ )
188
+ });
189
+ }
190
+ } catch (err) {
191
+ if (err instanceof LinkError) throw err;
192
+ throw new LinkError({
193
+ mode,
194
+ target,
195
+ linkPath,
196
+ platform: process.platform,
197
+ cause: err
198
+ });
199
+ }
200
+ return { mode, linkPath, targetPath: target };
201
+ }
202
+ async function convertToSymlink(opts) {
203
+ const kind = opts.kind ?? "skill";
204
+ const scope = opts.scope ?? "workspace";
205
+ const linkPath = resolveLinkPath({
206
+ workspaceDir: opts.workspaceDir,
207
+ skillName: opts.skillName,
208
+ kind,
209
+ scope,
210
+ linkBasename: opts.sourceIsFile && opts.sourcePath ? path2.basename(opts.sourcePath) : void 0
211
+ });
212
+ const stat2 = await fs.lstat(linkPath).catch(() => null);
213
+ if (!stat2) {
214
+ throw new Error(`Nothing installed at ${linkPath} to convert.`);
215
+ }
216
+ if (stat2.isSymbolicLink()) {
217
+ throw new Error(`${linkPath} is already a symlink.`);
218
+ }
219
+ return installSkillToWorkspace(opts);
220
+ }
221
+ async function uninstallSkillFromWorkspace(opts) {
222
+ const kind = opts.kind ?? "skill";
223
+ const scope = opts.scope ?? "workspace";
224
+ const linkPath = resolveLinkPath({
225
+ workspaceDir: opts.workspaceDir,
226
+ skillName: opts.skillName,
227
+ kind,
228
+ scope
229
+ });
230
+ if (await pathExists(linkPath)) {
231
+ await removeIfExists(linkPath);
232
+ return;
233
+ }
234
+ const scopeDir = path2.dirname(linkPath);
235
+ let entries;
236
+ try {
237
+ entries = await fs.readdir(scopeDir, { withFileTypes: true });
238
+ } catch {
239
+ return;
240
+ }
241
+ const flatMatch = entries.find(
242
+ (e) => e.name === opts.skillName || e.name.startsWith(`${opts.skillName}.`)
243
+ );
244
+ if (flatMatch) {
245
+ await removeIfExists(path2.join(scopeDir, flatMatch.name));
246
+ }
247
+ }
248
+ async function pathExists(p) {
249
+ try {
250
+ await fs.lstat(p);
251
+ return true;
252
+ } catch {
253
+ return false;
254
+ }
255
+ }
256
+ var MANIFEST_FILENAME = {
257
+ skill: "SKILL.md",
258
+ agent: "AGENT.md"
259
+ };
260
+ async function listLinkedSkills(workspaceDir, kind = "skill", scope = "workspace") {
261
+ if (scope === "workspace" && !workspaceDir) {
262
+ return [];
263
+ }
264
+ const root = scope === "user" ? path2.join(getHomeDir(), ".agents", ENTRY_SUBDIR[kind]) : path2.join(workspaceDir, ".github", ENTRY_SUBDIR[kind]);
265
+ let entries;
266
+ try {
267
+ entries = await fs.readdir(root, { withFileTypes: true });
268
+ } catch (err) {
269
+ if (err.code === "ENOENT") return [];
270
+ throw err;
271
+ }
272
+ const results = [];
273
+ for (const entry of entries) {
274
+ const entryPath = path2.join(root, entry.name);
275
+ if (entry.isSymbolicLink()) {
276
+ const skillName = entry.name.replace(/\.(agent|skill)\.md$/, "");
277
+ const rawTarget = await readLinkTarget(entryPath);
278
+ if (!rawTarget) continue;
279
+ const resolvedTarget = resolveTargetPath(entryPath, rawTarget);
280
+ const targetStat = await fs.stat(resolvedTarget).catch(() => null);
281
+ if (!targetStat) continue;
282
+ results.push({
283
+ repoId: extractRepoIdFromTarget(resolvedTarget) ?? "",
284
+ skillName,
285
+ linkPath: entryPath,
286
+ targetPath: resolvedTarget,
287
+ mode: process.platform === "win32" ? "junction" : "symlink",
288
+ scope
289
+ });
290
+ continue;
291
+ }
292
+ if (entry.isDirectory()) {
293
+ const hasManifest = await fs.access(path2.join(entryPath, MANIFEST_FILENAME[kind])).then(() => true).catch(() => false);
294
+ if (!hasManifest) continue;
295
+ results.push({
296
+ repoId: "",
297
+ skillName: entry.name,
298
+ linkPath: entryPath,
299
+ targetPath: entryPath,
300
+ mode: "copy",
301
+ scope
302
+ });
303
+ continue;
304
+ }
305
+ if (entry.isFile() && entry.name.endsWith(`.${kind}.md`)) {
306
+ results.push({
307
+ repoId: "",
308
+ skillName: entry.name.replace(/\.(agent|skill)\.md$/, ""),
309
+ linkPath: entryPath,
310
+ targetPath: entryPath,
311
+ mode: "copy",
312
+ scope
313
+ });
314
+ }
315
+ }
316
+ return results;
317
+ }
318
+ async function isCorrectLink(linkPath, expectedTarget) {
319
+ let actual;
320
+ try {
321
+ actual = await readLinkTarget(linkPath);
322
+ } catch {
323
+ return false;
324
+ }
325
+ if (!actual) return false;
326
+ return resolveTargetPath(linkPath, actual) === resolveTargetPath(linkPath, expectedTarget);
327
+ }
328
+ async function readLinkTarget(linkPath) {
329
+ try {
330
+ return await fs.readlink(linkPath);
331
+ } catch (err) {
332
+ if (err.code === "ENOENT") return void 0;
333
+ throw err;
334
+ }
335
+ }
336
+ function resolveTargetPath(linkPath, target) {
337
+ if (path2.isAbsolute(target)) return path2.normalize(target);
338
+ return path2.normalize(path2.resolve(path2.dirname(linkPath), target));
339
+ }
340
+ function extractRepoIdFromTarget(target) {
341
+ const marker = `${path2.sep}repos${path2.sep}`;
342
+ const idx = target.indexOf(marker);
343
+ if (idx === -1) return void 0;
344
+ const rest = target.slice(idx + marker.length);
345
+ const [repoId] = rest.split(path2.sep);
346
+ return repoId || void 0;
347
+ }
348
+ async function removeIfExists(p) {
349
+ try {
350
+ const stat2 = await fs.lstat(p);
351
+ if (stat2.isDirectory() && !stat2.isSymbolicLink()) {
352
+ await fs.rm(p, { recursive: true, force: true });
353
+ } else {
354
+ await fs.unlink(p);
355
+ }
356
+ } catch (err) {
357
+ if (err.code === "ENOENT") return;
358
+ throw err;
359
+ }
360
+ }
361
+ // Annotate the CommonJS export names for ESM import in node:
362
+ 0 && (module.exports = {
363
+ LinkError,
364
+ convertToSymlink,
365
+ getPlatformHint,
366
+ installSkillToWorkspace,
367
+ listLinkedSkills,
368
+ pickMode,
369
+ resolveSkillLinkPath,
370
+ resolveSkillTarget,
371
+ resolveUserSkillLinkPath,
372
+ uninstallSkillFromWorkspace
373
+ });
374
+ //# sourceMappingURL=skill-linker.js.map
@@ -0,0 +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(\n\tplatform: NodeJS.Platform = process.platform,\n): 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(\n\tskillName: string,\n\tkind: EntryKind = \"skill\",\n): 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\n\t\t? path.join(path.dirname(base), opts.linkBasename)\n\t\t: 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 =\n\t\topts.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 =\n\t\topts.mode === undefined || opts.mode === \"auto\" ? pickMode() : opts.mode;\n\tconst mode =\n\t\tisFile && 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(\n\topts: InstallSkillOptions,\n): 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:\n\t\t\topts.sourceIsFile && opts.sourcePath\n\t\t\t\t? path.basename(opts.sourcePath)\n\t\t\t\t: 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(\n\tlinkPath: string,\n\texpectedTarget: string,\n): 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 (\n\t\tresolveTargetPath(linkPath, actual) ===\n\t\tresolveTargetPath(linkPath, expectedTarget)\n\t);\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/**\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// ─── 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;AAYrB,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;AAEA,SAAS,0BAA8C;AACtD,QAAM,WAAW,gBAAgB;AACjC,MAAI,aAAa,QAAW;AAG3B,WAAO,SAAS,SAAS,IAAI,WAAW;AAAA,EACzC;AACA,QAAM,WAAW,QAAQ,IAAI,kBA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