@notis_ai/cli 0.2.32 → 0.2.34

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 (95) hide show
  1. package/README.md +75 -11
  2. package/dist/agent-hooks/notis-agent-hook.mjs +4407 -905
  3. package/dist/base-skills/notis-cli/.notis-base-skill.json +1 -1
  4. package/dist/base-skills/notis-cli/SKILL.md +7 -3
  5. package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
  6. package/dist/base-skills/notis-spaces/SKILL.md +5 -3
  7. package/dist/base-skills/notis-spaces/references/comments.md +102 -0
  8. package/dist/base-skills/notis-spaces/references/context.md +20 -19
  9. package/dist/base-skills/notis-spaces/references/design.md +3 -2
  10. package/dist/base-skills/notis-spaces/references/sdk.md +135 -83
  11. package/dist/base-skills/notis-spaces/references/store.md +24 -1
  12. package/dist/sdk/src/components/NotisSelectionBoundary.tsx +13 -5
  13. package/dist/sdk/src/components/SelectionActionBar.tsx +45 -8
  14. package/dist/sdk/src/components/SpaceTextComments.tsx +293 -0
  15. package/dist/sdk/src/components/selectionRange.ts +65 -0
  16. package/dist/sdk/src/config.ts +3 -1
  17. package/dist/sdk/src/functions.ts +218 -0
  18. package/dist/sdk/src/hooks/useAgentQueue.ts +17 -28
  19. package/dist/sdk/src/hooks/useCollectionInteractions.ts +66 -9
  20. package/dist/sdk/src/hooks/useConnection.ts +102 -0
  21. package/dist/sdk/src/hooks/useFunction.ts +42 -0
  22. package/dist/sdk/src/hooks/useNotisSettings.ts +101 -0
  23. package/dist/sdk/src/index.ts +16 -4
  24. package/dist/sdk/src/interactions/shortcuts.tsx +6 -1
  25. package/dist/sdk/src/interactions/swipeDownToDismiss.ts +158 -0
  26. package/dist/sdk/src/interactions/textBoxTwoState.ts +174 -0
  27. package/dist/sdk/src/interactions.ts +17 -0
  28. package/dist/sdk/src/runtime.ts +16 -1
  29. package/dist/sdk/src/space.ts +401 -33
  30. package/dist/sdk/src/ui/comments/passageModel.ts +99 -0
  31. package/dist/sdk/src/ui/comments/textHighlights.ts +33 -0
  32. package/dist/skill-sync/index.js +262 -31
  33. package/dist/skill-sync-worker.mjs +515 -127
  34. package/dist/space-harness/host.js +389 -154
  35. package/dist/space-sdk/dist/chunk-3NPBCE6E.js +3 -0
  36. package/dist/space-sdk/dist/index.js +3 -3
  37. package/dist/space-sdk/dist/ui.js +16 -11
  38. package/dist/space-sdk/src/config.ts +3 -1
  39. package/dist/space-sdk/src/functions.ts +218 -0
  40. package/dist/space-sdk/src/hooks/useAgentQueue.d.ts +2 -13
  41. package/dist/space-sdk/src/hooks/useCollectionInteractions.d.ts +7 -0
  42. package/dist/space-sdk/src/hooks/useConnection.d.ts +42 -0
  43. package/dist/space-sdk/src/hooks/useFunction.d.ts +20 -0
  44. package/dist/space-sdk/src/hooks/useNotisSettings.d.ts +48 -0
  45. package/dist/space-sdk/src/index.d.ts +10 -4
  46. package/dist/space-sdk/src/interactions/shortcuts.d.ts +5 -0
  47. package/dist/space-sdk/src/runtime.d.ts +14 -1
  48. package/dist/space-sdk/src/space.ts +401 -33
  49. package/dist/space-sdk/src/tailwind-candidates.d.ts +400 -204
  50. package/dist/space-sdk/src/ui/comments/CommentPane.d.ts +90 -15
  51. package/dist/space-sdk/src/ui/comments/PassageComments.d.ts +4 -1
  52. package/dist/space-sdk/src/ui/comments/agentRuntime.d.ts +4 -2
  53. package/dist/space-sdk/src/ui/comments/commentDrafts.d.ts +63 -0
  54. package/dist/space-sdk/src/ui/comments/commentModel.d.ts +59 -88
  55. package/dist/space-sdk/src/ui/comments/commentWords.d.ts +32 -1
  56. package/dist/space-sdk/src/ui/comments/handover.d.ts +34 -0
  57. package/dist/space-sdk/src/ui/comments/hostComments.d.ts +13 -9
  58. package/dist/space-sdk/src/ui/comments/hostPanel.d.ts +113 -0
  59. package/dist/space-sdk/src/ui/comments/index.d.ts +7 -2
  60. package/dist/space-sdk/src/ui/comments/paneOutlet.d.ts +33 -0
  61. package/dist/space-sdk/src/ui/comments/paneParts.d.ts +71 -27
  62. package/dist/space-sdk/src/ui/comments/passageModel.d.ts +12 -36
  63. package/dist/space-sdk/src/ui/comments/reviewRun.d.ts +190 -0
  64. package/dist/space-sdk/src/ui/comments/useCommentRouting.d.ts +26 -4
  65. package/dist/space-sdk/src/ui/comments/useComments.d.ts +116 -77
  66. package/dist/space-sdk/src/ui/comments/usePassageComments.d.ts +8 -4
  67. package/dist/space-sdk/src/ui/index.d.ts +1 -1
  68. package/dist/space-sdk/src/ui/layout/SidePane.d.ts +3 -4
  69. package/dist/space-sdk/src/ui/period/dateFormat.d.ts +27 -8
  70. package/dist/view-renderer/dist/host.js +450 -215
  71. package/package.json +3 -3
  72. package/skills/notis-cli/AGENT_INSTRUCTIONS.md +2 -2
  73. package/skills/notis-spaces/cli.md +3 -3
  74. package/src/cli.js +2 -1
  75. package/src/command-specs/index.js +3 -0
  76. package/src/command-specs/repository-secrets.js +171 -0
  77. package/src/command-specs/spaces.js +3 -3
  78. package/src/runtime/agent-credential.js +175 -0
  79. package/src/runtime/agent-identity.js +95 -19
  80. package/src/runtime/app-platform.js +8 -0
  81. package/src/runtime/auth-recovery.js +14 -0
  82. package/src/runtime/profiles.js +74 -2
  83. package/src/runtime/skill-sync/cloud-client.ts +33 -3
  84. package/src/runtime/skill-sync/index.ts +4 -3
  85. package/src/runtime/skill-sync/symlink-manager.ts +354 -35
  86. package/src/runtime/skill-sync/types.ts +14 -2
  87. package/src/runtime/space-functions.js +213 -0
  88. package/src/runtime/space-platform.js +12 -3
  89. package/src/runtime/space-source.js +116 -13
  90. package/src/runtime/space-test-server.js +22 -4
  91. package/src/runtime/space-verification.js +3 -1
  92. package/src/runtime/transport.js +15 -0
  93. package/dist/sdk/src/components/NotisCommentBoundary.tsx +0 -132
  94. package/dist/space-sdk/dist/chunk-I4Z4UFGB.js +0 -3
  95. package/dist/space-sdk/src/components/NotisCommentBoundary.d.ts +0 -26
@@ -8,7 +8,14 @@ import {
8
8
  NOTIS_SKILL_SYNC_ROOT,
9
9
  safeName,
10
10
  } from './local-scanner';
11
- import { normalizeAgentTargets, type AgentTargets, type SkillSyncFailure, type CloudSkill, type NotisSyncState } from './types';
11
+ import { isNativeSkill, nativeFrontmatterName } from './native-identity';
12
+ import {
13
+ normalizeAgentTargets,
14
+ type SkillSyncFailure,
15
+ type CloudSkill,
16
+ type NotisSyncState,
17
+ type VerifiedAgentLinks,
18
+ } from './types';
12
19
 
13
20
  const HOME_DIR = os.homedir();
14
21
 
@@ -62,7 +69,9 @@ export interface SymlinkSyncResult {
62
69
  linked: number;
63
70
  removed: number;
64
71
  skipped: number;
65
- verifiedAgentLinks?: Record<string, Partial<AgentTargets>>;
72
+ /** Per skill folder: `true` when an agent's link carries the folder name, or the
73
+ * link name when a native skill is linked under its readable name. */
74
+ verifiedAgentLinks?: Record<string, VerifiedAgentLinks>;
66
75
  failures?: SkillSyncFailure[];
67
76
  }
68
77
 
@@ -116,6 +125,12 @@ export async function removeForeignAccountSymlinks(
116
125
  return removed;
117
126
  }
118
127
 
128
+ /** The skills the Notis CLI and Desktop install themselves (base-skills.js); a native skill never takes their link name. */
129
+ const BASE_SKILL_LINK_NAMES: ReadonlySet<string> = new Set(['notis-spaces', 'notis-query', 'notis-cli']);
130
+ const NATIVE_FOLDER_NAME = /^native-[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/;
131
+ /** The Agent Skills name rule Claude Code, Cursor and Codex share: lowercase words joined by hyphens. */
132
+ const READABLE_SKILL_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
133
+
119
134
  function managedSkillRoots(
120
135
  skillsDir: string,
121
136
  legacyGlobalSkillsDir: string = LEGACY_AGENTS_SKILLS_DIR,
@@ -134,6 +149,12 @@ function managedSkillRoots(
134
149
  return roots;
135
150
  }
136
151
 
152
+ function isUnderManagedRoot(resolvedTarget: string, managedRoots: string[]): boolean {
153
+ return managedRoots.some((root) => (
154
+ resolvedTarget === root || resolvedTarget.startsWith(`${root}${path.sep}`)
155
+ ));
156
+ }
157
+
137
158
  async function isManagedSymlink(linkPath: string, managedRoots: string[]): Promise<boolean> {
138
159
  try {
139
160
  const stats = await fs.lstat(linkPath);
@@ -143,9 +164,7 @@ async function isManagedSymlink(linkPath: string, managedRoots: string[]): Promi
143
164
 
144
165
  const target = await fs.readlink(linkPath);
145
166
  const resolvedTarget = path.resolve(path.dirname(linkPath), target);
146
- return managedRoots.some((root) => (
147
- resolvedTarget === root || resolvedTarget.startsWith(`${root}${path.sep}`)
148
- ));
167
+ return isUnderManagedRoot(resolvedTarget, managedRoots);
149
168
  } catch (error) {
150
169
  if ((error as NodeJS.ErrnoException)?.code === 'ENOENT') return false;
151
170
  throw error;
@@ -187,6 +206,7 @@ async function removeUndesiredManagedSymlinks(
187
206
  managedRoots: string[],
188
207
  failures: SkillSyncFailure[],
189
208
  agent: string,
209
+ movedTargets: ReadonlySet<string> = new Set(),
190
210
  ): Promise<number> {
191
211
  let removed = 0;
192
212
  try {
@@ -195,7 +215,8 @@ async function removeUndesiredManagedSymlinks(
195
215
  for (const entry of existingEntries) {
196
216
  const entryPath = path.join(agentDir, entry.name);
197
217
  try {
198
- if (!desiredSkills.has(entry.name) && await isManagedSymlink(entryPath, managedRoots)) {
218
+ if (!desiredSkills.has(entry.name) && await isManagedSymlink(entryPath, managedRoots)
219
+ && !(movedTargets.size > 0 && movedTargets.has(path.resolve(agentDir, await fs.readlink(entryPath))))) {
199
220
  await fs.unlink(entryPath);
200
221
  removed += 1;
201
222
  }
@@ -223,18 +244,259 @@ export async function removeAllSymlinksForSkill(
223
244
  const agentDirs = new Set([...Object.values(agentSkillDirs), legacyGlobalSkillsDir]);
224
245
  const expectedTarget = path.resolve(skillsDir, safeName(skillName, skillsDir));
225
246
  for (const agentDir of agentDirs) {
226
- const linkPath = path.join(agentDir, safeName(skillName, agentDir));
247
+ const linkName = safeName(skillName, agentDir);
248
+ const linkPath = path.join(agentDir, linkName);
227
249
  const owned = options.ownership === 'exact-skill-dir'
228
250
  ? await isManagedSymlink(linkPath, [expectedTarget])
229
- : await isManagedSymlink(linkPath, managedRoots);
251
+ : await isManagedSymlink(linkPath, managedRoots)
252
+ && !(await linksToOtherSkillFolder(linkPath, expectedTarget, skillsDir));
230
253
  if (owned) {
231
254
  await fs.unlink(linkPath);
232
255
  removed += 1;
233
256
  }
257
+ // A native skill's agent link carries its readable name, not its folder name:
258
+ // remove every link in the agent folder that points at this exact skill folder.
259
+ // A folder that cannot be listed keeps only that extra link; it never stops the
260
+ // removal in the other folders or the sync that called it.
261
+ if (path.resolve(agentDir) !== path.resolve(skillsDir)) {
262
+ try {
263
+ removed += await removeLinksToTarget(agentDir, expectedTarget, new Set([linkName]));
264
+ } catch (error) {
265
+ console.warn(`[skill-sync] Could not list ${agentDir} to remove the links to "${skillName}": ${(error as Error).message}`);
266
+ }
267
+ }
234
268
  }
235
269
  return removed;
236
270
  }
237
271
 
272
+ /**
273
+ * Whether `linkPath` points at another existing skill folder of this mirror: a
274
+ * native skill's readable link (whatever folder it is bound to) can carry the
275
+ * name of a removed legacy skill, and removing that skill must leave the native
276
+ * skill's link alone. The sync never links a legacy folder under another name.
277
+ */
278
+ async function linksToOtherSkillFolder(linkPath: string, expectedTarget: string, skillsDir: string): Promise<boolean> {
279
+ try {
280
+ const resolved = path.resolve(path.dirname(linkPath), await fs.readlink(linkPath));
281
+ if (resolved === expectedTarget || path.dirname(resolved) !== path.resolve(skillsDir)) return false;
282
+ return (await fs.stat(resolved)).isDirectory();
283
+ } catch {
284
+ return false;
285
+ }
286
+ }
287
+
288
+ /**
289
+ * Whether any symlink in `agentDir` resolves exactly to `targetPath`. A folder
290
+ * that cannot be read answers true: an unknown state is never a deletion.
291
+ */
292
+ async function hasLinkToTarget(agentDir: string, targetPath: string): Promise<boolean> {
293
+ let entries;
294
+ try {
295
+ entries = await fs.readdir(agentDir, { withFileTypes: true });
296
+ } catch {
297
+ return true;
298
+ }
299
+ for (const entry of entries) {
300
+ if (!entry.isSymbolicLink()) continue;
301
+ try {
302
+ if (path.resolve(agentDir, await fs.readlink(path.join(agentDir, entry.name))) === targetPath) return true;
303
+ } catch {
304
+ // A link that vanished is not a link to this skill.
305
+ }
306
+ }
307
+ return false;
308
+ }
309
+
310
+ /** The names of the symlinks in `agentDir` that resolve to each of `targets`. */
311
+ async function linkNamesByTarget(agentDir: string, targets: ReadonlySet<string>): Promise<Map<string, string[]>> {
312
+ const names = new Map<string, string[]>();
313
+ let entries;
314
+ try {
315
+ entries = await fs.readdir(agentDir, { withFileTypes: true });
316
+ } catch (error) {
317
+ if ((error as NodeJS.ErrnoException)?.code === 'ENOENT') return names;
318
+ throw error;
319
+ }
320
+ for (const entry of entries) {
321
+ if (!entry.isSymbolicLink()) continue;
322
+ try {
323
+ const resolved = path.resolve(agentDir, await fs.readlink(path.join(agentDir, entry.name)));
324
+ if (targets.has(resolved)) names.set(resolved, [...(names.get(resolved) ?? []), entry.name]);
325
+ } catch (error) {
326
+ if ((error as NodeJS.ErrnoException)?.code !== 'ENOENT') throw error;
327
+ }
328
+ }
329
+ return names;
330
+ }
331
+
332
+ /** Unlink each named entry of `agentDir` that is still a symlink to `targetPath`. */
333
+ async function unlinkIfTarget(agentDir: string, names: readonly string[], targetPath: string): Promise<number> {
334
+ let removed = 0;
335
+ for (const name of names) {
336
+ const entryPath = path.join(agentDir, name);
337
+ try {
338
+ if ((await fs.lstat(entryPath)).isSymbolicLink()
339
+ && path.resolve(agentDir, await fs.readlink(entryPath)) === targetPath) {
340
+ await fs.unlink(entryPath);
341
+ removed += 1;
342
+ }
343
+ } catch (error) {
344
+ if ((error as NodeJS.ErrnoException)?.code !== 'ENOENT') throw error;
345
+ }
346
+ }
347
+ return removed;
348
+ }
349
+
350
+ /**
351
+ * Remove the symlinks in `agentDir` that resolve exactly to `targetPath`, except
352
+ * `keepNames`, compared case-insensitively: on macOS a differently cased entry is
353
+ * the kept link itself.
354
+ */
355
+ async function removeLinksToTarget(
356
+ agentDir: string,
357
+ targetPath: string,
358
+ keepNames: ReadonlySet<string>,
359
+ ): Promise<number> {
360
+ let entries;
361
+ try {
362
+ entries = await fs.readdir(agentDir, { withFileTypes: true });
363
+ } catch (error) {
364
+ if ((error as NodeJS.ErrnoException)?.code === 'ENOENT') return 0;
365
+ throw error;
366
+ }
367
+ const keep = new Set([...keepNames].map((name) => name.toLowerCase()));
368
+ let removed = 0;
369
+ for (const entry of entries) {
370
+ if (!entry.isSymbolicLink() || keep.has(entry.name.toLowerCase())) continue;
371
+ const entryPath = path.join(agentDir, entry.name);
372
+ try {
373
+ const resolved = path.resolve(agentDir, await fs.readlink(entryPath));
374
+ if (resolved !== targetPath) continue;
375
+ await fs.unlink(entryPath);
376
+ removed += 1;
377
+ } catch (error) {
378
+ if ((error as NodeJS.ErrnoException)?.code !== 'ENOENT') throw error;
379
+ }
380
+ }
381
+ return removed;
382
+ }
383
+
384
+ /**
385
+ * The readable name a native skill is linked under in the external agent folders,
386
+ * or null when it keeps its `native-<id>` folder name. The on-disk SKILL.md
387
+ * frontmatter `name` wins because it is what the agents show; the pulled
388
+ * instructions and the display name are fallbacks for a folder not written yet.
389
+ */
390
+ export async function readableNativeLinkName(
391
+ skill: CloudSkill,
392
+ folderName: string,
393
+ skillsDir: string,
394
+ ): Promise<string | null> {
395
+ if (!isNativeSkill(skill)) return null;
396
+ let markdown = '';
397
+ try {
398
+ markdown = await fs.readFile(path.join(skillsDir, folderName, 'SKILL.md'), 'utf8');
399
+ } catch {
400
+ // Unreadable instructions are reported by the link pass itself.
401
+ }
402
+ const name = [nativeFrontmatterName(markdown), nativeFrontmatterName(skill.skill_md || ''), skill.display_name || '']
403
+ .map((value) => value.trim())
404
+ .find(Boolean);
405
+ // The name rule already rules out separators, dots and spaces.
406
+ if (!name || name === folderName || name.length > 64 || !READABLE_SKILL_NAME.test(name)
407
+ || NATIVE_FOLDER_NAME.test(name) || BASE_SKILL_LINK_NAMES.has(name)) {
408
+ return null;
409
+ }
410
+ return name;
411
+ }
412
+
413
+ /**
414
+ * Whether a native skill may take `linkName` in an agent folder: the path is free,
415
+ * already links to this skill, or (when the pass owns the whole folder) holds a
416
+ * managed link the pass would replace anyway. A real file or folder, or a link the
417
+ * sync does not manage, keeps the skill on its folder name.
418
+ */
419
+ async function readableLinkAvailable(
420
+ linkPath: string,
421
+ targetPath: string,
422
+ managedRoots: string[],
423
+ ownsWholeFolder: boolean,
424
+ ): Promise<boolean> {
425
+ let stats;
426
+ try {
427
+ stats = await fs.lstat(linkPath);
428
+ } catch (error) {
429
+ return (error as NodeJS.ErrnoException)?.code === 'ENOENT';
430
+ }
431
+ if (!stats.isSymbolicLink()) return false;
432
+ try {
433
+ const resolved = path.resolve(path.dirname(linkPath), await fs.readlink(linkPath));
434
+ if (resolved === path.resolve(targetPath)) return true;
435
+ return ownsWholeFolder && isUnderManagedRoot(resolved, managedRoots);
436
+ } catch {
437
+ return false;
438
+ }
439
+ }
440
+
441
+ interface AgentLinkCandidate {
442
+ folderName: string;
443
+ readableName: string | null;
444
+ }
445
+
446
+ /**
447
+ * Choose each skill's link name in one external agent folder. Legacy skills keep
448
+ * their folder name. A native skill takes its readable name unless that name is
449
+ * another desired link name in this folder (a legacy skill, or a second native
450
+ * skill with the same name: both then keep `native-<id>`), or an entry the sync
451
+ * does not manage blocks it. Names compare case-insensitively for macOS folders.
452
+ */
453
+ async function planAgentLinkNames(
454
+ candidates: AgentLinkCandidate[],
455
+ agentDir: string,
456
+ skillsDir: string,
457
+ managedRoots: string[],
458
+ ownsWholeFolder: boolean,
459
+ ): Promise<Map<string, string>> {
460
+ // A skill that falls back to its folder name (a legacy skill, or a native skill
461
+ // whose readable name is unusable) keeps it: a readable name equal to such a
462
+ // folder name is reserved, until no fallback and readable name collide.
463
+ const reserved = new Set(
464
+ candidates.filter((candidate) => !candidate.readableName).map((candidate) => candidate.folderName.toLowerCase()),
465
+ );
466
+ const readableCounts = new Map<string, number>();
467
+ for (const { readableName } of candidates) {
468
+ if (!readableName) continue;
469
+ const key = readableName.toLowerCase();
470
+ readableCounts.set(key, (readableCounts.get(key) ?? 0) + 1);
471
+ }
472
+ const available = new Map<string, boolean>();
473
+ for (;;) {
474
+ const plan = new Map<string, string>();
475
+ const owners = new Map<string, number>();
476
+ for (const { folderName, readableName } of candidates) {
477
+ let linkName = folderName;
478
+ if (readableName) {
479
+ const key = readableName.toLowerCase();
480
+ if (!reserved.has(key) && readableCounts.get(key) === 1) {
481
+ if (!available.has(folderName)) {
482
+ available.set(folderName, await readableLinkAvailable(
483
+ path.join(agentDir, readableName), path.join(skillsDir, folderName), managedRoots, ownsWholeFolder,
484
+ ));
485
+ }
486
+ if (available.get(folderName)) linkName = readableName;
487
+ }
488
+ }
489
+ plan.set(linkName, folderName);
490
+ owners.set(linkName.toLowerCase(), (owners.get(linkName.toLowerCase()) ?? 0) + 1);
491
+ }
492
+ // Only a readable name can newly collide; two folder names that differ only in
493
+ // case are distinct entries on a case-sensitive disk and stay as they are.
494
+ const collisions = [...owners].filter(([name, count]) => count > 1 && !reserved.has(name)).map(([name]) => name);
495
+ if (collisions.length === 0) return plan;
496
+ for (const name of collisions) reserved.add(name);
497
+ }
498
+ }
499
+
238
500
  /**
239
501
  * Detect per-agent skill symlinks that we created on a prior sync but that the user has since
240
502
  * deleted locally (e.g. `rm ~/.claude/skills/<skill>`). The caller turns each result into a
@@ -282,8 +544,12 @@ export async function detectDeletedAgentSymlinks(
282
544
  continue;
283
545
  }
284
546
  const previous = previousState.skills[skill.name];
285
- if (!previous || previous.cloudId !== skill.id
286
- || previous.verifiedAgentLinks?.[agent] !== true
547
+ // The link is looked up under the name the previous sync verified it with:
548
+ // `true` is the folder name, a string is a native skill's readable link name.
549
+ // Evidence recorded under the old `native-<id>` name therefore still finds that
550
+ // link during the move to the readable name, and is never read as a deletion.
551
+ const verified = previous?.verifiedAgentLinks?.[agent];
552
+ if (!previous || previous.cloudId !== skill.id || !verified
287
553
  || !skill.updated_at || previous.cloudUpdatedAt !== skill.updated_at) {
288
554
  continue;
289
555
  }
@@ -294,18 +560,23 @@ export async function detectDeletedAgentSymlinks(
294
560
  continue;
295
561
  }
296
562
 
297
- let safeSkillName: string;
563
+ let linkName: string;
564
+ let folderName: string;
298
565
  try {
299
- safeSkillName = safeName(skill.name, skillsDir);
566
+ folderName = safeName(skill.name, skillsDir);
567
+ linkName = safeName(typeof verified === 'string' ? verified : folderName, agentDir);
300
568
  } catch {
301
569
  continue;
302
570
  }
303
571
 
304
- const linkPath = path.join(agentDir, safeName(safeSkillName, agentDir));
572
+ const linkPath = path.join(agentDir, linkName);
305
573
  try {
306
574
  await fs.lstat(linkPath);
307
575
  } catch (error) {
308
- if ((error as NodeJS.ErrnoException)?.code === 'ENOENT') {
576
+ // A move between the folder name and the readable name that stopped
577
+ // half-way leaves the skill linked under its other name: not a deletion.
578
+ if ((error as NodeJS.ErrnoException)?.code === 'ENOENT'
579
+ && !(await hasLinkToTarget(agentDir, path.resolve(skillsDir, folderName)))) {
309
580
  deletions.push({ skillId: skill.id, skillName: skill.name, agent });
310
581
  }
311
582
  }
@@ -333,11 +604,13 @@ export async function syncSymlinks(
333
604
  const legacyGlobalSkillsDir = options.legacyGlobalSkillsDir || LEGACY_AGENTS_SKILLS_DIR;
334
605
  const managedRoots = managedSkillRoots(skillsDir, legacyGlobalSkillsDir);
335
606
 
336
- const desiredByAgent = {
337
- notis: new Set<string>(),
338
- claude_code: new Set<string>(),
339
- cursor: new Set<string>(),
340
- codex: new Set<string>(),
607
+ const ownsWholeFolder = options.removeUndesired !== false;
608
+ // Per agent: skill folder name -> the row it came from (the first active row wins).
609
+ const desiredByAgent: Record<keyof AgentSkillDirs, Map<string, CloudSkill>> = {
610
+ notis: new Map(),
611
+ claude_code: new Map(),
612
+ cursor: new Map(),
613
+ codex: new Map(),
341
614
  };
342
615
 
343
616
  for (const skill of skills) {
@@ -347,17 +620,19 @@ export async function syncSymlinks(
347
620
 
348
621
  const safeSkillName = safeName(skill.name, skillsDir);
349
622
  const targets = normalizeAgentTargets(skill.agent_targets);
350
- if (targets.notis) {
351
- desiredByAgent.notis.add(safeSkillName);
352
- }
353
- if (targets.claude_code) {
354
- desiredByAgent.claude_code.add(safeSkillName);
355
- }
356
- if (targets.cursor) {
357
- desiredByAgent.cursor.add(safeSkillName);
623
+ for (const agent of Object.keys(desiredByAgent) as Array<keyof AgentSkillDirs>) {
624
+ if (targets[agent] && !desiredByAgent[agent].has(safeSkillName)) {
625
+ desiredByAgent[agent].set(safeSkillName, skill);
626
+ }
358
627
  }
359
- if (targets.codex) {
360
- desiredByAgent.codex.add(safeSkillName);
628
+ }
629
+
630
+ const readableNames = new Map<string, string | null>();
631
+ for (const [folderName, skill] of [
632
+ ...desiredByAgent.claude_code, ...desiredByAgent.cursor, ...desiredByAgent.codex,
633
+ ]) {
634
+ if (!readableNames.has(folderName)) {
635
+ readableNames.set(folderName, await readableNativeLinkName(skill, folderName, skillsDir));
361
636
  }
362
637
  }
363
638
 
@@ -374,14 +649,44 @@ export async function syncSymlinks(
374
649
  continue;
375
650
  }
376
651
 
377
- const desiredSkills = desiredByAgent[agent];
378
- if (options.removeUndesired !== false) {
379
- result.removed += await removeUndesiredManagedSymlinks(agentDir, desiredSkills, managedRoots, result.failures, agent);
652
+ // Only Claude Code, Cursor and Codex read a native skill under its readable
653
+ // name; the Notis folder is the mirror itself and keeps `native-<id>`.
654
+ const external = (EXTERNAL_AGENTS as readonly string[]).includes(agent);
655
+ const linkPlan = await planAgentLinkNames(
656
+ [...desiredByAgent[agent].keys()].map((folderName) => ({
657
+ folderName,
658
+ readableName: external ? readableNames.get(folderName) ?? null : null,
659
+ })),
660
+ agentDir,
661
+ skillsDir,
662
+ managedRoots,
663
+ ownsWholeFolder,
664
+ );
665
+
666
+ // A native skill's old link stays until its new link exists (removed below), so
667
+ // a pass that stops half-way leaves it linked and never reads as a deletion.
668
+ const movedTargets = new Set(external
669
+ ? [...linkPlan.values()].filter((name) => isNativeSkill(desiredByAgent[agent].get(name)!))
670
+ .map((name) => path.resolve(skillsDir, name))
671
+ : []);
672
+ if (ownsWholeFolder) {
673
+ result.removed += await removeUndesiredManagedSymlinks(
674
+ agentDir, new Set(linkPlan.keys()), managedRoots, result.failures, agent, movedTargets,
675
+ );
676
+ }
677
+ // One read of the folder: the link names each moving native skill has now.
678
+ let namesByTarget = new Map<string, string[]>();
679
+ if (movedTargets.size > 0) {
680
+ try {
681
+ namesByTarget = await linkNamesByTarget(agentDir, movedTargets);
682
+ } catch (error) {
683
+ result.failures.push({ name: agentFolderFailureName(agent), error: `Could not read agent skills directory (${(error as Error).message})` });
684
+ }
380
685
  }
381
686
 
382
- for (const skillName of desiredSkills) {
687
+ for (const [linkName, skillName] of linkPlan) {
383
688
  const targetPath = path.join(skillsDir, skillName);
384
- const linkPath = path.join(agentDir, safeName(skillName, agentDir));
689
+ const linkPath = path.join(agentDir, safeName(linkName, agentDir));
385
690
  try {
386
691
  if (!(await fs.stat(path.join(targetPath, "SKILL.md"))).isFile()) throw new Error("Missing SKILL.md");
387
692
  } catch {
@@ -409,7 +714,21 @@ export async function syncSymlinks(
409
714
  result.skipped += 1;
410
715
  }
411
716
  if (syncOutcome !== "blocked") {
412
- result.verifiedAgentLinks[skillName] = { ...result.verifiedAgentLinks[skillName], [agent]: true };
717
+ result.verifiedAgentLinks[skillName] = {
718
+ ...result.verifiedAgentLinks[skillName],
719
+ [agent]: linkName === skillName ? true : linkName,
720
+ };
721
+ // Once the link exists, remove this native skill's link under its other
722
+ // name (old `native-<id>` or readable); a relink pass leaves the rest alone.
723
+ const otherNames = (namesByTarget.get(path.resolve(targetPath)) ?? [])
724
+ .filter((name) => name.toLowerCase() !== linkName.toLowerCase());
725
+ if (otherNames.length > 0) {
726
+ try {
727
+ result.removed += await unlinkIfTarget(agentDir, otherNames, path.resolve(targetPath));
728
+ } catch (error) {
729
+ result.failures.push({ name: skillName, error: `${agentFailureLabel(agent)}: could not remove skill link (${(error as Error).message})` });
730
+ }
731
+ }
413
732
  }
414
733
  }
415
734
  }
@@ -5,6 +5,15 @@ export interface AgentTargets {
5
5
  codex: boolean;
6
6
  }
7
7
 
8
+ /**
9
+ * Per-agent evidence of a readable managed link. `true` means the link carries the
10
+ * skill's folder name. A string means the link carries that name instead: a native
11
+ * skill's mirror folder is `native-<id>`, but its agent link carries its readable
12
+ * skill name. Older clients only act on `true`, so they never read a renamed link
13
+ * as a missing one.
14
+ */
15
+ export type VerifiedAgentLinks = Partial<Record<keyof AgentTargets, boolean | string>>;
16
+
8
17
  export interface NativeSkillReference {
9
18
  kind: 'native_standalone_skill';
10
19
  skill_id: string;
@@ -23,7 +32,7 @@ export interface SyncedSkill {
23
32
  folderHash: string;
24
33
  agentTargets: AgentTargets;
25
34
  /** Actual readable managed links, never inferred from desired targets. */
26
- verifiedAgentLinks?: Partial<AgentTargets>;
35
+ verifiedAgentLinks?: VerifiedAgentLinks;
27
36
  cloudUpdatedAt?: string;
28
37
  /** Content accepted on disk; independent of server-specific folder hash formats. */
29
38
  cloudContentHash?: string;
@@ -138,8 +147,11 @@ export interface SkillSyncFailure {
138
147
  error: string;
139
148
  /** HTTP status of a refused upload, when the push itself was answered non-2xx. */
140
149
  status?: number;
141
- /** Classified cause (e.g. `edge_blocked`, `http_413`); never a response body. */
150
+ /** Classified cause (e.g. `edge_blocked`, `http_413`, `skill_too_large`); never a response body. */
142
151
  code?: string;
152
+ /** `skill_too_large`: the Skill's upload size and the largest size the server accepts. */
153
+ size_bytes?: number;
154
+ limit_bytes?: number;
143
155
  }
144
156
 
145
157
  export interface SyncPushResponse {