@notis_ai/cli 0.2.32 → 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.
- package/README.md +74 -9
- package/dist/agent-hooks/notis-agent-hook.mjs +4330 -891
- package/dist/base-skills/notis-cli/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-cli/SKILL.md +7 -3
- package/dist/base-skills/notis-spaces/.notis-base-skill.json +1 -1
- package/dist/base-skills/notis-spaces/SKILL.md +5 -3
- package/dist/base-skills/notis-spaces/references/comments.md +94 -0
- package/dist/base-skills/notis-spaces/references/context.md +20 -19
- package/dist/base-skills/notis-spaces/references/design.md +3 -2
- package/dist/base-skills/notis-spaces/references/sdk.md +135 -83
- package/dist/base-skills/notis-spaces/references/store.md +24 -1
- package/dist/sdk/src/components/SelectionActionBar.tsx +42 -7
- package/dist/sdk/src/components/SpaceTextComments.tsx +284 -0
- package/dist/sdk/src/config.ts +3 -1
- package/dist/sdk/src/functions.ts +203 -0
- package/dist/sdk/src/hooks/useAgentQueue.ts +17 -28
- package/dist/sdk/src/hooks/useCollectionInteractions.ts +7 -2
- package/dist/sdk/src/hooks/useConnection.ts +102 -0
- package/dist/sdk/src/hooks/useFunction.ts +42 -0
- package/dist/sdk/src/hooks/useNotisSettings.ts +101 -0
- package/dist/sdk/src/index.ts +15 -4
- package/dist/sdk/src/runtime.ts +16 -1
- package/dist/sdk/src/space.ts +333 -33
- package/dist/sdk/src/ui/comments/passageModel.ts +99 -0
- package/dist/sdk/src/ui/comments/textHighlights.ts +33 -0
- package/dist/skill-sync/index.js +239 -30
- package/dist/skill-sync-worker.mjs +453 -124
- package/dist/space-harness/host.js +213 -92
- package/dist/space-sdk/dist/chunk-4GWS2IFO.js +3 -0
- package/dist/space-sdk/dist/index.js +3 -3
- package/dist/space-sdk/dist/ui.js +8 -7
- package/dist/space-sdk/src/config.ts +3 -1
- package/dist/space-sdk/src/functions.ts +203 -0
- package/dist/space-sdk/src/hooks/useAgentQueue.d.ts +2 -13
- package/dist/space-sdk/src/hooks/useCollectionInteractions.d.ts +2 -0
- package/dist/space-sdk/src/hooks/useConnection.d.ts +42 -0
- package/dist/space-sdk/src/hooks/useFunction.d.ts +20 -0
- package/dist/space-sdk/src/hooks/useNotisSettings.d.ts +48 -0
- package/dist/space-sdk/src/index.d.ts +10 -4
- package/dist/space-sdk/src/runtime.d.ts +14 -1
- package/dist/space-sdk/src/space.ts +333 -33
- package/dist/space-sdk/src/tailwind-candidates.d.ts +185 -152
- package/dist/space-sdk/src/ui/comments/CommentPane.d.ts +7 -4
- package/dist/space-sdk/src/ui/comments/agentRuntime.d.ts +10 -2
- package/dist/space-sdk/src/ui/comments/commentModel.d.ts +55 -88
- package/dist/space-sdk/src/ui/comments/commentWords.d.ts +9 -0
- package/dist/space-sdk/src/ui/comments/hostComments.d.ts +13 -9
- package/dist/space-sdk/src/ui/comments/index.d.ts +1 -1
- package/dist/space-sdk/src/ui/comments/paneParts.d.ts +27 -5
- package/dist/space-sdk/src/ui/comments/passageModel.d.ts +12 -36
- package/dist/space-sdk/src/ui/comments/useCommentRouting.d.ts +26 -4
- package/dist/space-sdk/src/ui/comments/useComments.d.ts +64 -74
- package/dist/space-sdk/src/ui/comments/usePassageComments.d.ts +8 -4
- package/dist/space-sdk/src/ui/index.d.ts +1 -1
- package/dist/space-sdk/src/ui/layout/SidePane.d.ts +3 -4
- package/dist/space-sdk/src/ui/period/dateFormat.d.ts +27 -8
- package/dist/view-renderer/dist/host.js +280 -159
- package/package.json +3 -3
- package/skills/notis-cli/AGENT_INSTRUCTIONS.md +2 -2
- package/skills/notis-spaces/cli.md +3 -3
- package/src/cli.js +2 -1
- package/src/command-specs/index.js +3 -0
- package/src/command-specs/repository-secrets.js +171 -0
- package/src/command-specs/spaces.js +3 -3
- package/src/runtime/agent-credential.js +175 -0
- package/src/runtime/agent-identity.js +92 -15
- package/src/runtime/app-platform.js +8 -0
- package/src/runtime/auth-recovery.js +14 -0
- package/src/runtime/profiles.js +15 -0
- package/src/runtime/skill-sync/index.ts +3 -2
- package/src/runtime/skill-sync/symlink-manager.ts +354 -35
- package/src/runtime/skill-sync/types.ts +10 -1
- package/src/runtime/space-functions.js +211 -0
- package/src/runtime/space-platform.js +12 -3
- package/src/runtime/space-source.js +116 -13
- package/src/runtime/space-test-server.js +22 -4
- package/src/runtime/space-verification.js +3 -1
- package/src/runtime/transport.js +15 -0
- package/dist/sdk/src/components/NotisCommentBoundary.tsx +0 -132
- package/dist/space-sdk/dist/chunk-I4Z4UFGB.js +0 -3
- 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
|
+
}
|
package/dist/skill-sync/index.js
CHANGED
|
@@ -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
|
|
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
|
|
1312
|
-
const
|
|
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
|
-
|
|
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
|
|
1518
|
+
let linkName;
|
|
1519
|
+
let folderName;
|
|
1353
1520
|
try {
|
|
1354
|
-
|
|
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,
|
|
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
|
|
1384
|
-
claude_code: /* @__PURE__ */ new
|
|
1385
|
-
cursor: /* @__PURE__ */ new
|
|
1386
|
-
codex: /* @__PURE__ */ new
|
|
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
|
-
|
|
1395
|
-
desiredByAgent.
|
|
1396
|
-
|
|
1397
|
-
|
|
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
|
-
|
|
1404
|
-
|
|
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
|
|
1419
|
-
|
|
1420
|
-
|
|
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
|
-
|
|
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(
|
|
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] = {
|
|
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
|
}
|