@notis_ai/cli 0.2.31 → 0.2.33

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 (92) hide show
  1. package/README.md +88 -9
  2. package/config/notis_app_design_rules.json +22 -0
  3. package/dist/agent-hooks/notis-agent-hook.mjs +4677 -913
  4. package/dist/base-skills/notis-cli/.notis-base-skill.json +1 -1
  5. package/dist/base-skills/notis-cli/SKILL.md +7 -3
  6. package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
  7. package/dist/base-skills/notis-spaces/SKILL.md +9 -4
  8. package/dist/base-skills/notis-spaces/references/comments.md +94 -0
  9. package/dist/base-skills/notis-spaces/references/context.md +20 -19
  10. package/dist/base-skills/notis-spaces/references/design.md +3 -2
  11. package/dist/base-skills/notis-spaces/references/fixtures.md +4 -2
  12. package/dist/base-skills/notis-spaces/references/reading.md +3 -1
  13. package/dist/base-skills/notis-spaces/references/release.md +3 -1
  14. package/dist/base-skills/notis-spaces/references/sdk.md +160 -88
  15. package/dist/base-skills/notis-spaces/references/store.md +24 -1
  16. package/dist/sdk/src/components/SelectionActionBar.tsx +42 -7
  17. package/dist/sdk/src/components/SpaceTextComments.tsx +284 -0
  18. package/dist/sdk/src/config.ts +3 -1
  19. package/dist/sdk/src/functions.ts +203 -0
  20. package/dist/sdk/src/hooks/useAgentQueue.ts +17 -28
  21. package/dist/sdk/src/hooks/useCollectionInteractions.ts +7 -2
  22. package/dist/sdk/src/hooks/useConnection.ts +102 -0
  23. package/dist/sdk/src/hooks/useFunction.ts +42 -0
  24. package/dist/sdk/src/hooks/useNotisSettings.ts +101 -0
  25. package/dist/sdk/src/index.ts +15 -4
  26. package/dist/sdk/src/runtime.ts +16 -1
  27. package/dist/sdk/src/space.ts +333 -33
  28. package/dist/sdk/src/ui/comments/passageModel.ts +99 -0
  29. package/dist/sdk/src/ui/comments/textHighlights.ts +33 -0
  30. package/dist/sdk/src/ui/icons.tsx +17 -1
  31. package/dist/skill-sync/index.js +239 -30
  32. package/dist/skill-sync-worker.mjs +453 -124
  33. package/dist/space-harness/host.js +218 -93
  34. package/dist/space-sdk/dist/chunk-4GWS2IFO.js +3 -0
  35. package/dist/space-sdk/dist/index.js +3 -3
  36. package/dist/space-sdk/dist/ui.js +9 -8
  37. package/dist/space-sdk/src/config.ts +3 -1
  38. package/dist/space-sdk/src/functions.ts +203 -0
  39. package/dist/space-sdk/src/hooks/useAgentQueue.d.ts +2 -13
  40. package/dist/space-sdk/src/hooks/useCollectionInteractions.d.ts +2 -0
  41. package/dist/space-sdk/src/hooks/useConnection.d.ts +42 -0
  42. package/dist/space-sdk/src/hooks/useFunction.d.ts +20 -0
  43. package/dist/space-sdk/src/hooks/useNotisSettings.d.ts +48 -0
  44. package/dist/space-sdk/src/index.d.ts +10 -4
  45. package/dist/space-sdk/src/runtime.d.ts +14 -1
  46. package/dist/space-sdk/src/space.ts +333 -33
  47. package/dist/space-sdk/src/tailwind-candidates.d.ts +227 -152
  48. package/dist/space-sdk/src/ui/blocks/blocks.d.ts +18 -0
  49. package/dist/space-sdk/src/ui/blocks/index.d.ts +2 -2
  50. package/dist/space-sdk/src/ui/comments/CommentPane.d.ts +7 -4
  51. package/dist/space-sdk/src/ui/comments/agentRuntime.d.ts +10 -2
  52. package/dist/space-sdk/src/ui/comments/commentModel.d.ts +55 -88
  53. package/dist/space-sdk/src/ui/comments/commentWords.d.ts +9 -0
  54. package/dist/space-sdk/src/ui/comments/hostComments.d.ts +13 -9
  55. package/dist/space-sdk/src/ui/comments/index.d.ts +1 -1
  56. package/dist/space-sdk/src/ui/comments/paneParts.d.ts +27 -5
  57. package/dist/space-sdk/src/ui/comments/passageModel.d.ts +12 -36
  58. package/dist/space-sdk/src/ui/comments/useCommentRouting.d.ts +26 -4
  59. package/dist/space-sdk/src/ui/comments/useComments.d.ts +64 -74
  60. package/dist/space-sdk/src/ui/comments/usePassageComments.d.ts +8 -4
  61. package/dist/space-sdk/src/ui/icons.d.ts +6 -0
  62. package/dist/space-sdk/src/ui/index.d.ts +2 -2
  63. package/dist/space-sdk/src/ui/layout/SidePane.d.ts +3 -4
  64. package/dist/space-sdk/src/ui/list/ListReader.d.ts +8 -0
  65. package/dist/space-sdk/src/ui/period/dateFormat.d.ts +27 -8
  66. package/dist/view-renderer/dist/host.js +285 -160
  67. package/package.json +3 -3
  68. package/skills/notis-cli/AGENT_INSTRUCTIONS.md +2 -2
  69. package/skills/notis-spaces/cli.md +17 -3
  70. package/src/cli.js +2 -1
  71. package/src/command-specs/index.js +3 -0
  72. package/src/command-specs/repository-secrets.js +171 -0
  73. package/src/command-specs/spaces.js +70 -3
  74. package/src/runtime/agent-credential.js +175 -0
  75. package/src/runtime/agent-identity.js +92 -15
  76. package/src/runtime/app-boundary-validator.js +248 -3
  77. package/src/runtime/app-data-literals.js +32 -23
  78. package/src/runtime/app-platform.js +8 -0
  79. package/src/runtime/auth-recovery.js +14 -0
  80. package/src/runtime/profiles.js +15 -0
  81. package/src/runtime/skill-sync/index.ts +3 -2
  82. package/src/runtime/skill-sync/symlink-manager.ts +354 -35
  83. package/src/runtime/skill-sync/types.ts +10 -1
  84. package/src/runtime/space-functions.js +211 -0
  85. package/src/runtime/space-platform.js +12 -3
  86. package/src/runtime/space-source.js +116 -13
  87. package/src/runtime/space-test-server.js +44 -7
  88. package/src/runtime/space-verification.js +3 -1
  89. package/src/runtime/transport.js +15 -0
  90. package/dist/sdk/src/components/NotisCommentBoundary.tsx +0 -132
  91. package/dist/space-sdk/dist/chunk-3DFOGU26.js +0 -3
  92. package/dist/space-sdk/src/components/NotisCommentBoundary.d.ts +0 -26
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Which text comments of the page lost their words: the passage highlighter every Space page draws
3
+ * (`SpaceTextComments`) reports them here, and a thread card on such a comment reads Passage changed (the thread stays
4
+ * open with its old quote). One store per window, keyed by comment id.
5
+ */
6
+
7
+ import { useSyncExternalStore } from 'react';
8
+
9
+ let changed: ReadonlySet<string> = new Set();
10
+ const listeners = new Set<() => void>();
11
+
12
+ /** Sets the text comments whose words are gone (replaces the earlier set). */
13
+ export function setChangedPassages(ids: Iterable<string>): void {
14
+ const next = new Set(ids);
15
+ if (next.size === changed.size && [...next].every(id => changed.has(id))) return;
16
+ changed = next;
17
+ for (const listener of [...listeners]) listener();
18
+ }
19
+
20
+ /** The text comments whose words are gone, as last reported. */
21
+ export function changedPassages(): ReadonlySet<string> {
22
+ return changed;
23
+ }
24
+
25
+ function subscribe(listener: () => void): () => void {
26
+ listeners.add(listener);
27
+ return () => { listeners.delete(listener); };
28
+ }
29
+
30
+ /** Whether this text comment's words are gone from the page (re-renders when that changes). */
31
+ export function usePassageChanged(id: string | null | undefined): boolean {
32
+ return useSyncExternalStore(subscribe, () => Boolean(id) && changed.has(id!), () => false);
33
+ }
@@ -56,6 +56,7 @@ const SHAPES: Record<string, Shape> = {
56
56
  'check-circle-fill': <g><circle {...F} cx="8" cy="8" r="6.5" /><path d="M5 8.2l2 2 4-4" fill="none" stroke="hsl(var(--background))" strokeWidth={1.5} strokeLinecap="round" strokeLinejoin="round" /></g>,
57
57
  'minus-circle': <g {...S}><circle cx="8" cy="8" r="6" /><path d="M5.5 8h5" /></g>,
58
58
  'paper-plane-right': <path {...S} d="M2.5 2.8l11 5.2-11 5.2 1.8-5.2zM4.3 8h4.7" />,
59
+ 'paper-plane-tilt': <path {...S} d="M2.3 6.7l11.2-4.2-4.2 11.2-2.2-4.8zM7.1 8.9l3.3-3.3" />,
59
60
  paperclip: <path {...S} d="M10.5 5l-4.6 4.6a1.1 1.1 0 001.6 1.6l5-5a2.3 2.3 0 00-3.2-3.2l-5 5a3.4 3.4 0 004.8 4.8L13 8.9" />,
60
61
  'clipboard-text': <g {...S}><path d="M10.5 3h2a.5.5 0 01.5.5v10a.5.5 0 01-.5.5h-9a.5.5 0 01-.5-.5v-10a.5.5 0 01.5-.5h2" /><rect x="5.5" y="2" width="5" height="2.5" rx=".75" /><path d="M6 8h4M6 10.5h4" /></g>,
61
62
  'x-circle-fill': <g><circle {...F} cx="8" cy="8" r="6.5" /><path d="M5.8 5.8l4.4 4.4M10.2 5.8l-4.4 4.4" fill="none" stroke="hsl(var(--background))" strokeWidth={1.5} strokeLinecap="round" /></g>,
@@ -63,14 +64,29 @@ const SHAPES: Record<string, Shape> = {
63
64
  'magnifying-glass-minus': <path {...S} d="M7 12A5 5 0 107 2a5 5 0 000 10zM10.6 10.6L14 14M5 7h4" />,
64
65
  'download-simple': <path {...S} d="M8 2.5v7.5M4.5 6.5L8 10l3.5-3.5M2.5 10v3a.5.5 0 00.5.5h10a.5.5 0 00.5-.5v-3" />,
65
66
  info: <g {...S}><circle cx="8" cy="8" r="6.5" /><path d="M8 7.5V11M8 5.25v.01" /></g>,
67
+ 'arrow-square-out': <path {...S} d="M12.5 9v3.5a.5.5 0 01-.5.5H3.5a.5.5 0 01-.5-.5V4a.5.5 0 01.5-.5H7M9.5 2.5h4v4M13.5 2.5L8 8" />,
68
+ 'funnel-simple': <path {...S} d="M2.5 4.5h11M4.5 8h7M6.5 11.5h3" />,
66
69
  link: <path {...S} d="M6.8 9.2l2.4-2.4M7.6 4.6l1.2-1.2a2.8 2.8 0 014 4l-1.2 1.2M8.4 11.4l-1.2 1.2a2.8 2.8 0 01-4-4l1.2-1.2" />,
67
70
  file: <path {...S} d="M9.5 2H4a.5.5 0 00-.5.5v11a.5.5 0 00.5.5h8a.5.5 0 00.5-.5V5zM9.5 2v3h3" />,
68
71
  'file-image': <g {...S}><path d="M9.5 2H4a.5.5 0 00-.5.5v11a.5.5 0 00.5.5h8a.5.5 0 00.5-.5V5zM9.5 2v3h3" /><path d="M3.5 12l3-3 2 2 1.5-1.5 2.5 2.5" /><circle cx="6.5" cy="6.75" r=".75" /></g>,
69
72
  'file-video': <g {...S}><path d="M9.5 2H4a.5.5 0 00-.5.5v11a.5.5 0 00.5.5h8a.5.5 0 00.5-.5V5zM9.5 2v3h3" /><path d="M6.5 8v3.5L9.5 9.75z" /></g>,
70
73
  'file-audio': <g {...S}><path d="M9.5 2H4a.5.5 0 00-.5.5v11a.5.5 0 00.5.5h8a.5.5 0 00.5-.5V5zM9.5 2v3h3" /><path d="M6 9.5v1.5h1.25L9 12.25v-4.5L7.25 9H6M10.5 8.5a1.8 1.8 0 010 2.5" /></g>,
71
74
  'fork-knife': <path {...S} d="M3.5 2v3.5a1.5 1.5 0 003 0V2M5 2v12M11.5 14V2c-1.4.9-2.2 3-2.2 6.5h2.2" />,
75
+ 'check-circle': <g {...S}><circle cx="8" cy="8" r="6" /><path d="M5.5 8.2l1.8 1.8 3.4-3.6" /></g>,
76
+ 'chart-line-up': <path {...S} d="M2.5 2.5v11h11M4.5 10.5l3-3 2 2 4-4.5M10.5 5h3v3" />,
77
+ sparkle: <path {...S} d="M7 3.5l1.2 3.3 3.3 1.2-3.3 1.2L7 12.5 5.8 9.2 2.5 8l3.3-1.2zM12.5 1.75v2.5M11.25 3h2.5" />,
78
+ 'rocket-launch': <g {...S}><path d="M5.2 7.3l4.4-4.4C11 1.5 13.5 2 14 2c0 .5.5 3-.9 4.4l-4.4 4.4zM5.2 7.3H3l2-2.3h2.8M8.7 10.8V13l2.3-2V8.2M5.3 10.7c-1.3.4-2.3 1.5-2.8 2.8 1.3-.5 2.4-1.5 2.8-2.8z" /><circle cx="10.8" cy="5.2" r=".9" /></g>,
79
+ chats: <g {...S}><path d="M3 3h6.5a.5.5 0 01.5.5v5a.5.5 0 01-.5.5H5.2L2.5 11V3.5A.5.5 0 013 3z" /><path d="M10 6h3a.5.5 0 01.5.5V14l-2.6-2H7a.5.5 0 01-.5-.5V9" /></g>,
80
+ kanban: <g {...S}><rect x="2.5" y="2.5" width="3" height="10" rx=".5" /><rect x="6.5" y="2.5" width="3" height="6" rx=".5" /><rect x="10.5" y="2.5" width="3" height="8" rx=".5" /></g>,
72
81
  };
73
82
 
83
+ /**
84
+ * Every name the set draws, in the order above. `notis spaces build` refuses an `icon` or `<Icon name>` string that is
85
+ * not one of them; the CLI and the server read the same list from `server/config/notis_app_design_rules.json`, kept
86
+ * equal to this one by `icons.test.tsx`.
87
+ */
88
+ export const ICON_NAMES: readonly string[] = Object.freeze(Object.keys(SHAPES));
89
+
74
90
  export function hasIcon(name: string): boolean {
75
91
  return Object.prototype.hasOwnProperty.call(SHAPES, name);
76
92
  }
@@ -81,7 +97,7 @@ const warned = new Set<string>();
81
97
  function warnUnknown(name: string): void {
82
98
  if (warned.has(name) || typeof console === 'undefined') return;
83
99
  warned.add(name);
84
- console.warn(`[notis/ui] Unknown icon "${name}": it renders nothing. Use a name from the toolkit set (${Object.keys(SHAPES).length} icons, listed in the design system) or pass a Phosphor component.`);
100
+ console.warn(`[notis/ui] Unknown icon "${name}": it renders nothing. Use a name from the toolkit set (${ICON_NAMES.length} icons, listed in the design system) or pass a Phosphor component.`);
85
101
  }
86
102
 
87
103
  /** A built-in icon by name; an unknown name renders nothing and warns once. Decorative: the control carries the label. */
@@ -1223,6 +1223,9 @@ async function removeForeignAccountSymlinks(skillsDir, options = {}) {
1223
1223
  }
1224
1224
  return removed;
1225
1225
  }
1226
+ var BASE_SKILL_LINK_NAMES = /* @__PURE__ */ new Set(["notis-spaces", "notis-query", "notis-cli"]);
1227
+ var NATIVE_FOLDER_NAME = /^native-[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/;
1228
+ var READABLE_SKILL_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
1226
1229
  function managedSkillRoots(skillsDir, legacyGlobalSkillsDir = LEGACY_AGENTS_SKILLS_DIR) {
1227
1230
  const resolvedSkillsDir = path2.resolve(skillsDir);
1228
1231
  const scopedUsersRoot = path2.dirname(path2.dirname(resolvedSkillsDir));
@@ -1237,6 +1240,9 @@ function managedSkillRoots(skillsDir, legacyGlobalSkillsDir = LEGACY_AGENTS_SKIL
1237
1240
  }
1238
1241
  return roots;
1239
1242
  }
1243
+ function isUnderManagedRoot(resolvedTarget, managedRoots) {
1244
+ return managedRoots.some((root) => resolvedTarget === root || resolvedTarget.startsWith(`${root}${path2.sep}`));
1245
+ }
1240
1246
  async function isManagedSymlink(linkPath, managedRoots) {
1241
1247
  try {
1242
1248
  const stats = await fs2.lstat(linkPath);
@@ -1245,7 +1251,7 @@ async function isManagedSymlink(linkPath, managedRoots) {
1245
1251
  }
1246
1252
  const target = await fs2.readlink(linkPath);
1247
1253
  const resolvedTarget = path2.resolve(path2.dirname(linkPath), target);
1248
- return managedRoots.some((root) => resolvedTarget === root || resolvedTarget.startsWith(`${root}${path2.sep}`));
1254
+ return isUnderManagedRoot(resolvedTarget, managedRoots);
1249
1255
  } catch (error) {
1250
1256
  if (error?.code === "ENOENT") return false;
1251
1257
  throw error;
@@ -1277,7 +1283,7 @@ function defaultAgentSkillDirs(skillsDir) {
1277
1283
  ...EXTERNAL_AGENT_SKILL_DIRS
1278
1284
  };
1279
1285
  }
1280
- async function removeUndesiredManagedSymlinks(agentDir, desiredSkills, managedRoots, failures, agent) {
1286
+ async function removeUndesiredManagedSymlinks(agentDir, desiredSkills, managedRoots, failures, agent, movedTargets = /* @__PURE__ */ new Set()) {
1281
1287
  let removed = 0;
1282
1288
  try {
1283
1289
  await fs2.mkdir(agentDir, { recursive: true });
@@ -1285,7 +1291,7 @@ async function removeUndesiredManagedSymlinks(agentDir, desiredSkills, managedRo
1285
1291
  for (const entry of existingEntries) {
1286
1292
  const entryPath = path2.join(agentDir, entry.name);
1287
1293
  try {
1288
- if (!desiredSkills.has(entry.name) && await isManagedSymlink(entryPath, managedRoots)) {
1294
+ if (!desiredSkills.has(entry.name) && await isManagedSymlink(entryPath, managedRoots) && !(movedTargets.size > 0 && movedTargets.has(path2.resolve(agentDir, await fs2.readlink(entryPath))))) {
1289
1295
  await fs2.unlink(entryPath);
1290
1296
  removed += 1;
1291
1297
  }
@@ -1308,15 +1314,174 @@ async function removeAllSymlinksForSkill(skillName, skillsDir = LEGACY_AGENTS_SK
1308
1314
  const agentDirs = /* @__PURE__ */ new Set([...Object.values(agentSkillDirs), legacyGlobalSkillsDir]);
1309
1315
  const expectedTarget = path2.resolve(skillsDir, safeName(skillName, skillsDir));
1310
1316
  for (const agentDir of agentDirs) {
1311
- const linkPath = path2.join(agentDir, safeName(skillName, agentDir));
1312
- const owned = options.ownership === "exact-skill-dir" ? await isManagedSymlink(linkPath, [expectedTarget]) : await isManagedSymlink(linkPath, managedRoots);
1317
+ const linkName = safeName(skillName, agentDir);
1318
+ const linkPath = path2.join(agentDir, linkName);
1319
+ const owned = options.ownership === "exact-skill-dir" ? await isManagedSymlink(linkPath, [expectedTarget]) : await isManagedSymlink(linkPath, managedRoots) && !await linksToOtherSkillFolder(linkPath, expectedTarget, skillsDir);
1313
1320
  if (owned) {
1314
1321
  await fs2.unlink(linkPath);
1315
1322
  removed += 1;
1316
1323
  }
1324
+ if (path2.resolve(agentDir) !== path2.resolve(skillsDir)) {
1325
+ try {
1326
+ removed += await removeLinksToTarget(agentDir, expectedTarget, /* @__PURE__ */ new Set([linkName]));
1327
+ } catch (error) {
1328
+ console.warn(`[skill-sync] Could not list ${agentDir} to remove the links to "${skillName}": ${error.message}`);
1329
+ }
1330
+ }
1331
+ }
1332
+ return removed;
1333
+ }
1334
+ async function linksToOtherSkillFolder(linkPath, expectedTarget, skillsDir) {
1335
+ try {
1336
+ const resolved = path2.resolve(path2.dirname(linkPath), await fs2.readlink(linkPath));
1337
+ if (resolved === expectedTarget || path2.dirname(resolved) !== path2.resolve(skillsDir)) return false;
1338
+ return (await fs2.stat(resolved)).isDirectory();
1339
+ } catch {
1340
+ return false;
1341
+ }
1342
+ }
1343
+ async function hasLinkToTarget(agentDir, targetPath) {
1344
+ let entries;
1345
+ try {
1346
+ entries = await fs2.readdir(agentDir, { withFileTypes: true });
1347
+ } catch {
1348
+ return true;
1349
+ }
1350
+ for (const entry of entries) {
1351
+ if (!entry.isSymbolicLink()) continue;
1352
+ try {
1353
+ if (path2.resolve(agentDir, await fs2.readlink(path2.join(agentDir, entry.name))) === targetPath) return true;
1354
+ } catch {
1355
+ }
1356
+ }
1357
+ return false;
1358
+ }
1359
+ async function linkNamesByTarget(agentDir, targets) {
1360
+ const names = /* @__PURE__ */ new Map();
1361
+ let entries;
1362
+ try {
1363
+ entries = await fs2.readdir(agentDir, { withFileTypes: true });
1364
+ } catch (error) {
1365
+ if (error?.code === "ENOENT") return names;
1366
+ throw error;
1367
+ }
1368
+ for (const entry of entries) {
1369
+ if (!entry.isSymbolicLink()) continue;
1370
+ try {
1371
+ const resolved = path2.resolve(agentDir, await fs2.readlink(path2.join(agentDir, entry.name)));
1372
+ if (targets.has(resolved)) names.set(resolved, [...names.get(resolved) ?? [], entry.name]);
1373
+ } catch (error) {
1374
+ if (error?.code !== "ENOENT") throw error;
1375
+ }
1376
+ }
1377
+ return names;
1378
+ }
1379
+ async function unlinkIfTarget(agentDir, names, targetPath) {
1380
+ let removed = 0;
1381
+ for (const name of names) {
1382
+ const entryPath = path2.join(agentDir, name);
1383
+ try {
1384
+ if ((await fs2.lstat(entryPath)).isSymbolicLink() && path2.resolve(agentDir, await fs2.readlink(entryPath)) === targetPath) {
1385
+ await fs2.unlink(entryPath);
1386
+ removed += 1;
1387
+ }
1388
+ } catch (error) {
1389
+ if (error?.code !== "ENOENT") throw error;
1390
+ }
1391
+ }
1392
+ return removed;
1393
+ }
1394
+ async function removeLinksToTarget(agentDir, targetPath, keepNames) {
1395
+ let entries;
1396
+ try {
1397
+ entries = await fs2.readdir(agentDir, { withFileTypes: true });
1398
+ } catch (error) {
1399
+ if (error?.code === "ENOENT") return 0;
1400
+ throw error;
1401
+ }
1402
+ const keep = new Set([...keepNames].map((name) => name.toLowerCase()));
1403
+ let removed = 0;
1404
+ for (const entry of entries) {
1405
+ if (!entry.isSymbolicLink() || keep.has(entry.name.toLowerCase())) continue;
1406
+ const entryPath = path2.join(agentDir, entry.name);
1407
+ try {
1408
+ const resolved = path2.resolve(agentDir, await fs2.readlink(entryPath));
1409
+ if (resolved !== targetPath) continue;
1410
+ await fs2.unlink(entryPath);
1411
+ removed += 1;
1412
+ } catch (error) {
1413
+ if (error?.code !== "ENOENT") throw error;
1414
+ }
1317
1415
  }
1318
1416
  return removed;
1319
1417
  }
1418
+ async function readableNativeLinkName(skill, folderName, skillsDir) {
1419
+ if (!isNativeSkill(skill)) return null;
1420
+ let markdown = "";
1421
+ try {
1422
+ markdown = await fs2.readFile(path2.join(skillsDir, folderName, "SKILL.md"), "utf8");
1423
+ } catch {
1424
+ }
1425
+ const name = [nativeFrontmatterName(markdown), nativeFrontmatterName(skill.skill_md || ""), skill.display_name || ""].map((value) => value.trim()).find(Boolean);
1426
+ if (!name || name === folderName || name.length > 64 || !READABLE_SKILL_NAME.test(name) || NATIVE_FOLDER_NAME.test(name) || BASE_SKILL_LINK_NAMES.has(name)) {
1427
+ return null;
1428
+ }
1429
+ return name;
1430
+ }
1431
+ async function readableLinkAvailable(linkPath, targetPath, managedRoots, ownsWholeFolder) {
1432
+ let stats;
1433
+ try {
1434
+ stats = await fs2.lstat(linkPath);
1435
+ } catch (error) {
1436
+ return error?.code === "ENOENT";
1437
+ }
1438
+ if (!stats.isSymbolicLink()) return false;
1439
+ try {
1440
+ const resolved = path2.resolve(path2.dirname(linkPath), await fs2.readlink(linkPath));
1441
+ if (resolved === path2.resolve(targetPath)) return true;
1442
+ return ownsWholeFolder && isUnderManagedRoot(resolved, managedRoots);
1443
+ } catch {
1444
+ return false;
1445
+ }
1446
+ }
1447
+ async function planAgentLinkNames(candidates, agentDir, skillsDir, managedRoots, ownsWholeFolder) {
1448
+ const reserved = new Set(
1449
+ candidates.filter((candidate) => !candidate.readableName).map((candidate) => candidate.folderName.toLowerCase())
1450
+ );
1451
+ const readableCounts = /* @__PURE__ */ new Map();
1452
+ for (const { readableName } of candidates) {
1453
+ if (!readableName) continue;
1454
+ const key = readableName.toLowerCase();
1455
+ readableCounts.set(key, (readableCounts.get(key) ?? 0) + 1);
1456
+ }
1457
+ const available = /* @__PURE__ */ new Map();
1458
+ for (; ; ) {
1459
+ const plan = /* @__PURE__ */ new Map();
1460
+ const owners = /* @__PURE__ */ new Map();
1461
+ for (const { folderName, readableName } of candidates) {
1462
+ let linkName = folderName;
1463
+ if (readableName) {
1464
+ const key = readableName.toLowerCase();
1465
+ if (!reserved.has(key) && readableCounts.get(key) === 1) {
1466
+ if (!available.has(folderName)) {
1467
+ available.set(folderName, await readableLinkAvailable(
1468
+ path2.join(agentDir, readableName),
1469
+ path2.join(skillsDir, folderName),
1470
+ managedRoots,
1471
+ ownsWholeFolder
1472
+ ));
1473
+ }
1474
+ if (available.get(folderName)) linkName = readableName;
1475
+ }
1476
+ }
1477
+ plan.set(linkName, folderName);
1478
+ owners.set(linkName.toLowerCase(), (owners.get(linkName.toLowerCase()) ?? 0) + 1);
1479
+ }
1480
+ const collisions = [...owners].filter(([name, count]) => count > 1 && !reserved.has(name)).map(([name]) => name);
1481
+ if (collisions.length === 0) return plan;
1482
+ for (const name of collisions) reserved.add(name);
1483
+ }
1484
+ }
1320
1485
  async function detectDeletedAgentSymlinks(cloudSkills, previousState, skillsDir = LEGACY_AGENTS_SKILLS_DIR, options = {}) {
1321
1486
  const agentSkillDirs = { ...defaultAgentSkillDirs(skillsDir), ...options.agentSkillDirs };
1322
1487
  const deletions = [];
@@ -1341,7 +1506,8 @@ async function detectDeletedAgentSymlinks(cloudSkills, previousState, skillsDir
1341
1506
  continue;
1342
1507
  }
1343
1508
  const previous = previousState.skills[skill.name];
1344
- if (!previous || previous.cloudId !== skill.id || previous.verifiedAgentLinks?.[agent] !== true || !skill.updated_at || previous.cloudUpdatedAt !== skill.updated_at) {
1509
+ const verified = previous?.verifiedAgentLinks?.[agent];
1510
+ if (!previous || previous.cloudId !== skill.id || !verified || !skill.updated_at || previous.cloudUpdatedAt !== skill.updated_at) {
1345
1511
  continue;
1346
1512
  }
1347
1513
  const cloudTargets = normalizeAgentTargets(skill.agent_targets);
@@ -1349,17 +1515,19 @@ async function detectDeletedAgentSymlinks(cloudSkills, previousState, skillsDir
1349
1515
  if (!cloudTargets[agent] || !previousTargets[agent]) {
1350
1516
  continue;
1351
1517
  }
1352
- let safeSkillName;
1518
+ let linkName;
1519
+ let folderName;
1353
1520
  try {
1354
- safeSkillName = safeName(skill.name, skillsDir);
1521
+ folderName = safeName(skill.name, skillsDir);
1522
+ linkName = safeName(typeof verified === "string" ? verified : folderName, agentDir);
1355
1523
  } catch {
1356
1524
  continue;
1357
1525
  }
1358
- const linkPath = path2.join(agentDir, safeName(safeSkillName, agentDir));
1526
+ const linkPath = path2.join(agentDir, linkName);
1359
1527
  try {
1360
1528
  await fs2.lstat(linkPath);
1361
1529
  } catch (error) {
1362
- if (error?.code === "ENOENT") {
1530
+ if (error?.code === "ENOENT" && !await hasLinkToTarget(agentDir, path2.resolve(skillsDir, folderName))) {
1363
1531
  deletions.push({ skillId: skill.id, skillName: skill.name, agent });
1364
1532
  }
1365
1533
  }
@@ -1379,11 +1547,12 @@ async function syncSymlinks(skills, skillsDir = LEGACY_AGENTS_SKILLS_DIR, option
1379
1547
  const agentSkillDirs = { ...defaultAgentSkillDirs(skillsDir), ...options.agentSkillDirs };
1380
1548
  const legacyGlobalSkillsDir = options.legacyGlobalSkillsDir || LEGACY_AGENTS_SKILLS_DIR;
1381
1549
  const managedRoots = managedSkillRoots(skillsDir, legacyGlobalSkillsDir);
1550
+ const ownsWholeFolder = options.removeUndesired !== false;
1382
1551
  const desiredByAgent = {
1383
- notis: /* @__PURE__ */ new Set(),
1384
- claude_code: /* @__PURE__ */ new Set(),
1385
- cursor: /* @__PURE__ */ new Set(),
1386
- codex: /* @__PURE__ */ new Set()
1552
+ notis: /* @__PURE__ */ new Map(),
1553
+ claude_code: /* @__PURE__ */ new Map(),
1554
+ cursor: /* @__PURE__ */ new Map(),
1555
+ codex: /* @__PURE__ */ new Map()
1387
1556
  };
1388
1557
  for (const skill of skills) {
1389
1558
  if (skill.status !== "active") {
@@ -1391,17 +1560,20 @@ async function syncSymlinks(skills, skillsDir = LEGACY_AGENTS_SKILLS_DIR, option
1391
1560
  }
1392
1561
  const safeSkillName = safeName(skill.name, skillsDir);
1393
1562
  const targets = normalizeAgentTargets(skill.agent_targets);
1394
- if (targets.notis) {
1395
- desiredByAgent.notis.add(safeSkillName);
1396
- }
1397
- if (targets.claude_code) {
1398
- desiredByAgent.claude_code.add(safeSkillName);
1399
- }
1400
- if (targets.cursor) {
1401
- desiredByAgent.cursor.add(safeSkillName);
1563
+ for (const agent of Object.keys(desiredByAgent)) {
1564
+ if (targets[agent] && !desiredByAgent[agent].has(safeSkillName)) {
1565
+ desiredByAgent[agent].set(safeSkillName, skill);
1566
+ }
1402
1567
  }
1403
- if (targets.codex) {
1404
- desiredByAgent.codex.add(safeSkillName);
1568
+ }
1569
+ const readableNames = /* @__PURE__ */ new Map();
1570
+ for (const [folderName, skill] of [
1571
+ ...desiredByAgent.claude_code,
1572
+ ...desiredByAgent.cursor,
1573
+ ...desiredByAgent.codex
1574
+ ]) {
1575
+ if (!readableNames.has(folderName)) {
1576
+ readableNames.set(folderName, await readableNativeLinkName(skill, folderName, skillsDir));
1405
1577
  }
1406
1578
  }
1407
1579
  for (const [agent, agentDir] of Object.entries(agentSkillDirs)) {
@@ -1415,13 +1587,39 @@ async function syncSymlinks(skills, skillsDir = LEGACY_AGENTS_SKILLS_DIR, option
1415
1587
  result.failures.push({ name: agentFolderFailureName(agent), error: `Could not create agent skills directory (${error.message})` });
1416
1588
  continue;
1417
1589
  }
1418
- const desiredSkills = desiredByAgent[agent];
1419
- if (options.removeUndesired !== false) {
1420
- result.removed += await removeUndesiredManagedSymlinks(agentDir, desiredSkills, managedRoots, result.failures, agent);
1590
+ const external = EXTERNAL_AGENTS.includes(agent);
1591
+ const linkPlan = await planAgentLinkNames(
1592
+ [...desiredByAgent[agent].keys()].map((folderName) => ({
1593
+ folderName,
1594
+ readableName: external ? readableNames.get(folderName) ?? null : null
1595
+ })),
1596
+ agentDir,
1597
+ skillsDir,
1598
+ managedRoots,
1599
+ ownsWholeFolder
1600
+ );
1601
+ const movedTargets = new Set(external ? [...linkPlan.values()].filter((name) => isNativeSkill(desiredByAgent[agent].get(name))).map((name) => path2.resolve(skillsDir, name)) : []);
1602
+ if (ownsWholeFolder) {
1603
+ result.removed += await removeUndesiredManagedSymlinks(
1604
+ agentDir,
1605
+ new Set(linkPlan.keys()),
1606
+ managedRoots,
1607
+ result.failures,
1608
+ agent,
1609
+ movedTargets
1610
+ );
1421
1611
  }
1422
- for (const skillName of desiredSkills) {
1612
+ let namesByTarget = /* @__PURE__ */ new Map();
1613
+ if (movedTargets.size > 0) {
1614
+ try {
1615
+ namesByTarget = await linkNamesByTarget(agentDir, movedTargets);
1616
+ } catch (error) {
1617
+ result.failures.push({ name: agentFolderFailureName(agent), error: `Could not read agent skills directory (${error.message})` });
1618
+ }
1619
+ }
1620
+ for (const [linkName, skillName] of linkPlan) {
1423
1621
  const targetPath = path2.join(skillsDir, skillName);
1424
- const linkPath = path2.join(agentDir, safeName(skillName, agentDir));
1622
+ const linkPath = path2.join(agentDir, safeName(linkName, agentDir));
1425
1623
  try {
1426
1624
  if (!(await fs2.stat(path2.join(targetPath, "SKILL.md"))).isFile()) throw new Error("Missing SKILL.md");
1427
1625
  } catch {
@@ -1449,7 +1647,18 @@ async function syncSymlinks(skills, skillsDir = LEGACY_AGENTS_SKILLS_DIR, option
1449
1647
  result.skipped += 1;
1450
1648
  }
1451
1649
  if (syncOutcome !== "blocked") {
1452
- result.verifiedAgentLinks[skillName] = { ...result.verifiedAgentLinks[skillName], [agent]: true };
1650
+ result.verifiedAgentLinks[skillName] = {
1651
+ ...result.verifiedAgentLinks[skillName],
1652
+ [agent]: linkName === skillName ? true : linkName
1653
+ };
1654
+ const otherNames = (namesByTarget.get(path2.resolve(targetPath)) ?? []).filter((name) => name.toLowerCase() !== linkName.toLowerCase());
1655
+ if (otherNames.length > 0) {
1656
+ try {
1657
+ result.removed += await unlinkIfTarget(agentDir, otherNames, path2.resolve(targetPath));
1658
+ } catch (error) {
1659
+ result.failures.push({ name: skillName, error: `${agentFailureLabel(agent)}: could not remove skill link (${error.message})` });
1660
+ }
1661
+ }
1453
1662
  }
1454
1663
  }
1455
1664
  }