@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.
- package/README.md +75 -11
- package/dist/agent-hooks/notis-agent-hook.mjs +4407 -905
- 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 +102 -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/NotisSelectionBoundary.tsx +13 -5
- package/dist/sdk/src/components/SelectionActionBar.tsx +45 -8
- package/dist/sdk/src/components/SpaceTextComments.tsx +293 -0
- package/dist/sdk/src/components/selectionRange.ts +65 -0
- package/dist/sdk/src/config.ts +3 -1
- package/dist/sdk/src/functions.ts +218 -0
- package/dist/sdk/src/hooks/useAgentQueue.ts +17 -28
- package/dist/sdk/src/hooks/useCollectionInteractions.ts +66 -9
- 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 +16 -4
- package/dist/sdk/src/interactions/shortcuts.tsx +6 -1
- package/dist/sdk/src/interactions/swipeDownToDismiss.ts +158 -0
- package/dist/sdk/src/interactions/textBoxTwoState.ts +174 -0
- package/dist/sdk/src/interactions.ts +17 -0
- package/dist/sdk/src/runtime.ts +16 -1
- package/dist/sdk/src/space.ts +401 -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 +262 -31
- package/dist/skill-sync-worker.mjs +515 -127
- package/dist/space-harness/host.js +389 -154
- package/dist/space-sdk/dist/chunk-3NPBCE6E.js +3 -0
- package/dist/space-sdk/dist/index.js +3 -3
- package/dist/space-sdk/dist/ui.js +16 -11
- package/dist/space-sdk/src/config.ts +3 -1
- package/dist/space-sdk/src/functions.ts +218 -0
- package/dist/space-sdk/src/hooks/useAgentQueue.d.ts +2 -13
- package/dist/space-sdk/src/hooks/useCollectionInteractions.d.ts +7 -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/interactions/shortcuts.d.ts +5 -0
- package/dist/space-sdk/src/runtime.d.ts +14 -1
- package/dist/space-sdk/src/space.ts +401 -33
- package/dist/space-sdk/src/tailwind-candidates.d.ts +400 -204
- package/dist/space-sdk/src/ui/comments/CommentPane.d.ts +90 -15
- package/dist/space-sdk/src/ui/comments/PassageComments.d.ts +4 -1
- package/dist/space-sdk/src/ui/comments/agentRuntime.d.ts +4 -2
- package/dist/space-sdk/src/ui/comments/commentDrafts.d.ts +63 -0
- package/dist/space-sdk/src/ui/comments/commentModel.d.ts +59 -88
- package/dist/space-sdk/src/ui/comments/commentWords.d.ts +32 -1
- package/dist/space-sdk/src/ui/comments/handover.d.ts +34 -0
- package/dist/space-sdk/src/ui/comments/hostComments.d.ts +13 -9
- package/dist/space-sdk/src/ui/comments/hostPanel.d.ts +113 -0
- package/dist/space-sdk/src/ui/comments/index.d.ts +7 -2
- package/dist/space-sdk/src/ui/comments/paneOutlet.d.ts +33 -0
- package/dist/space-sdk/src/ui/comments/paneParts.d.ts +71 -27
- package/dist/space-sdk/src/ui/comments/passageModel.d.ts +12 -36
- package/dist/space-sdk/src/ui/comments/reviewRun.d.ts +190 -0
- package/dist/space-sdk/src/ui/comments/useCommentRouting.d.ts +26 -4
- package/dist/space-sdk/src/ui/comments/useComments.d.ts +116 -77
- 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 +450 -215
- 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 +95 -19
- package/src/runtime/app-platform.js +8 -0
- package/src/runtime/auth-recovery.js +14 -0
- package/src/runtime/profiles.js +74 -2
- package/src/runtime/skill-sync/cloud-client.ts +33 -3
- package/src/runtime/skill-sync/index.ts +4 -3
- package/src/runtime/skill-sync/symlink-manager.ts +354 -35
- package/src/runtime/skill-sync/types.ts +14 -2
- package/src/runtime/space-functions.js +213 -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,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comments on a passage of a page's text (pure; no React). A thread can sit on words (a subject, a Markdown body, any
|
|
3
|
+
* text of the page) instead of a pin: the comment keeps the quoted words, a few words before and after them, and the
|
|
4
|
+
* field they are in when the Space names one (`field`). The quote is found again in the text as it is now, white
|
|
5
|
+
* space ignored, the surrounding words telling apart several matches; when the quoted words are gone the thread reads
|
|
6
|
+
* Passage changed (it stays open with its old quote).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { Words } from '../../words';
|
|
10
|
+
|
|
11
|
+
/** The words a thread sits on, with the words around them. */
|
|
12
|
+
export interface TextPassage { quote: string; prefix: string; suffix: string }
|
|
13
|
+
/** A passage in one field of the record. */
|
|
14
|
+
export interface PassageAnchor extends TextPassage { field: string }
|
|
15
|
+
|
|
16
|
+
/** A text property comments can sit on. */
|
|
17
|
+
export interface PassageField {
|
|
18
|
+
/** The Space's own name for the field (`subject`, `bodyEn`). */
|
|
19
|
+
key: string;
|
|
20
|
+
/** Its name in the pane, above each quote. */
|
|
21
|
+
label: Words;
|
|
22
|
+
/** Fields shown together, such as one language. The pane lists the threads of the group on screen. */
|
|
23
|
+
group?: string;
|
|
24
|
+
/** The value is Markdown: Text changed and the reading order look at its words, not its syntax. */
|
|
25
|
+
markdown?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The Space page's selection bar hands a selection in a Space's own commentable rich text to that text with this DOM
|
|
30
|
+
* event (detail: `{ range }`), so one bar shows Cite and Comment together and the text draws no button of its own.
|
|
31
|
+
*/
|
|
32
|
+
export const PASSAGE_COMMENT_EVENT = 'notis-passage-comment';
|
|
33
|
+
/** On the Space page root while its selection bar takes comments: own rich text then leaves Comment to the bar. */
|
|
34
|
+
export const SELECTION_BAR_COMMENTS_ATTR = 'data-notis-bar-comments';
|
|
35
|
+
|
|
36
|
+
/** Characters kept before and after a quote. */
|
|
37
|
+
export const PASSAGE_CONTEXT = 40;
|
|
38
|
+
/** The longest quote kept. */
|
|
39
|
+
export const PASSAGE_MAX_QUOTE = 1000;
|
|
40
|
+
|
|
41
|
+
const collapse = (value: string) => value.replace(/\s+/g, ' ');
|
|
42
|
+
const squeeze = (value: string) => value.replace(/\s+/g, '');
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Finds a passage in `text`, white space ignored (line breaks and block gaps move with edits). With several matches,
|
|
46
|
+
* the one whose surrounding words best match the stored prefix and suffix. Offsets in `text`, or null when the quoted
|
|
47
|
+
* words are gone.
|
|
48
|
+
*/
|
|
49
|
+
export function locatePassage(text: string, passage: TextPassage): { start: number; end: number } | null {
|
|
50
|
+
const quote = squeeze(passage.quote);
|
|
51
|
+
if (!quote) return null;
|
|
52
|
+
const at: number[] = [];
|
|
53
|
+
let flat = '';
|
|
54
|
+
for (let i = 0; i < text.length; i += 1) if (!/\s/.test(text[i]!)) { at.push(i); flat += text[i]; }
|
|
55
|
+
const before = squeeze(passage.prefix);
|
|
56
|
+
const after = squeeze(passage.suffix);
|
|
57
|
+
let best = -1;
|
|
58
|
+
let bestScore = -1;
|
|
59
|
+
for (let k = flat.indexOf(quote); k !== -1; k = flat.indexOf(quote, k + 1)) {
|
|
60
|
+
let score = 0;
|
|
61
|
+
while (score < before.length && k - 1 - score >= 0 && flat[k - 1 - score] === before[before.length - 1 - score]) score += 1;
|
|
62
|
+
let tail = 0;
|
|
63
|
+
const end = k + quote.length;
|
|
64
|
+
while (tail < after.length && end + tail < flat.length && flat[end + tail] === after[tail]) tail += 1;
|
|
65
|
+
if (score + tail > bestScore) { best = k; bestScore = score + tail; }
|
|
66
|
+
}
|
|
67
|
+
if (best < 0) return null;
|
|
68
|
+
return { start: at[best]!, end: at[best + quote.length - 1]! + 1 };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The passage between two offsets of `text`, with its prefix and suffix; null when only white space is selected. */
|
|
72
|
+
export function passageAt(text: string, start: number, end: number): TextPassage | null {
|
|
73
|
+
const quote = collapse(text.slice(start, end)).trim().slice(0, PASSAGE_MAX_QUOTE);
|
|
74
|
+
if (!squeeze(quote)) return null;
|
|
75
|
+
const prefix = collapse(text.slice(Math.max(0, start - PASSAGE_CONTEXT * 2), start)).trimStart().slice(-PASSAGE_CONTEXT);
|
|
76
|
+
const suffix = collapse(text.slice(end, end + PASSAGE_CONTEXT * 2)).trimEnd().slice(0, PASSAGE_CONTEXT);
|
|
77
|
+
return { quote, prefix, suffix };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The words a reader sees in Markdown source: link and image targets, HTML tags and markup characters left out. */
|
|
81
|
+
export function markdownReadableText(source: string): string {
|
|
82
|
+
return source
|
|
83
|
+
.replace(/!\[([^\]]*)\]\([^)]*\)/g, '$1')
|
|
84
|
+
.replace(/\[([^\]]*)\]\([^)]*\)/g, '$1')
|
|
85
|
+
.replace(/<[^>]+>/g, ' ')
|
|
86
|
+
.replace(/[*_`#>|~\\]/g, '');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Where a passage starts in a field's value, or null when its words are no longer there. For Markdown the words are
|
|
91
|
+
* looked for in what a reader sees (the offset is then proportional), then in the source itself.
|
|
92
|
+
*/
|
|
93
|
+
export function passageOffset(value: string, passage: TextPassage, markdown = false): number | null {
|
|
94
|
+
if (!markdown) return locatePassage(value, passage)?.start ?? null;
|
|
95
|
+
const words = markdownReadableText(value);
|
|
96
|
+
const hit = locatePassage(words, passage);
|
|
97
|
+
if (hit) return Math.round((hit.start / Math.max(1, words.length)) * value.length);
|
|
98
|
+
return locatePassage(value, passage)?.start ?? null;
|
|
99
|
+
}
|
|
@@ -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
|
@@ -1083,6 +1083,20 @@ async function skillPushPayload(skill) {
|
|
|
1083
1083
|
};
|
|
1084
1084
|
}
|
|
1085
1085
|
var SYNC_PUSH_ENVELOPE_BYTES = Buffer.byteLength(JSON.stringify({ skill_sync_protocol: 2, skills: [] }));
|
|
1086
|
+
var SERVER_REQUEST_BODY_MAX_BYTES = 64 * 1024 * 1024;
|
|
1087
|
+
var MAX_SYNC_PUSH_SKILL_BYTES = SERVER_REQUEST_BODY_MAX_BYTES - SYNC_PUSH_ENVELOPE_BYTES;
|
|
1088
|
+
function mib(bytes) {
|
|
1089
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
1090
|
+
}
|
|
1091
|
+
function tooLargeFailure(name, sizeBytes, limitBytes) {
|
|
1092
|
+
return {
|
|
1093
|
+
name,
|
|
1094
|
+
error: `Skill is too large to sync (${mib(sizeBytes)}, the limit is ${mib(limitBytes)}); remove large files from its folder to sync it`,
|
|
1095
|
+
code: "skill_too_large",
|
|
1096
|
+
size_bytes: sizeBytes,
|
|
1097
|
+
limit_bytes: limitBytes
|
|
1098
|
+
};
|
|
1099
|
+
}
|
|
1086
1100
|
function pushBatches(payloads, maxBodyBytes) {
|
|
1087
1101
|
const batches = [];
|
|
1088
1102
|
let batch = [];
|
|
@@ -1113,9 +1127,15 @@ function pushFailure(name, error) {
|
|
|
1113
1127
|
return { name, error: "Upload failed; sync will retry", code };
|
|
1114
1128
|
}
|
|
1115
1129
|
async function pushChangedSkills(serverUrl, jwt, changedSkills, options = {}) {
|
|
1116
|
-
const
|
|
1130
|
+
const maxSkillBytes = options.maxSkillBytes ?? MAX_SYNC_PUSH_SKILL_BYTES;
|
|
1117
1131
|
const saved = [];
|
|
1118
1132
|
const failed = [];
|
|
1133
|
+
const payloadSkills = [];
|
|
1134
|
+
for (const payload of await Promise.all(changedSkills.map(skillPushPayload))) {
|
|
1135
|
+
const bytes = Buffer.byteLength(JSON.stringify(payload)) + 1;
|
|
1136
|
+
if (bytes > maxSkillBytes) failed.push(tooLargeFailure(String(payload.name), bytes, maxSkillBytes));
|
|
1137
|
+
else payloadSkills.push(payload);
|
|
1138
|
+
}
|
|
1119
1139
|
for (const batch of pushBatches(payloadSkills, options.maxBodyBytes ?? MAX_SYNC_PUSH_BODY_BYTES)) {
|
|
1120
1140
|
try {
|
|
1121
1141
|
const result = await requestJson(`${serverUrl}/portal_skills/sync-push`, jwt, {
|
|
@@ -1223,6 +1243,9 @@ async function removeForeignAccountSymlinks(skillsDir, options = {}) {
|
|
|
1223
1243
|
}
|
|
1224
1244
|
return removed;
|
|
1225
1245
|
}
|
|
1246
|
+
var BASE_SKILL_LINK_NAMES = /* @__PURE__ */ new Set(["notis-spaces", "notis-query", "notis-cli"]);
|
|
1247
|
+
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}$/;
|
|
1248
|
+
var READABLE_SKILL_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
1226
1249
|
function managedSkillRoots(skillsDir, legacyGlobalSkillsDir = LEGACY_AGENTS_SKILLS_DIR) {
|
|
1227
1250
|
const resolvedSkillsDir = path2.resolve(skillsDir);
|
|
1228
1251
|
const scopedUsersRoot = path2.dirname(path2.dirname(resolvedSkillsDir));
|
|
@@ -1237,6 +1260,9 @@ function managedSkillRoots(skillsDir, legacyGlobalSkillsDir = LEGACY_AGENTS_SKIL
|
|
|
1237
1260
|
}
|
|
1238
1261
|
return roots;
|
|
1239
1262
|
}
|
|
1263
|
+
function isUnderManagedRoot(resolvedTarget, managedRoots) {
|
|
1264
|
+
return managedRoots.some((root) => resolvedTarget === root || resolvedTarget.startsWith(`${root}${path2.sep}`));
|
|
1265
|
+
}
|
|
1240
1266
|
async function isManagedSymlink(linkPath, managedRoots) {
|
|
1241
1267
|
try {
|
|
1242
1268
|
const stats = await fs2.lstat(linkPath);
|
|
@@ -1245,7 +1271,7 @@ async function isManagedSymlink(linkPath, managedRoots) {
|
|
|
1245
1271
|
}
|
|
1246
1272
|
const target = await fs2.readlink(linkPath);
|
|
1247
1273
|
const resolvedTarget = path2.resolve(path2.dirname(linkPath), target);
|
|
1248
|
-
return
|
|
1274
|
+
return isUnderManagedRoot(resolvedTarget, managedRoots);
|
|
1249
1275
|
} catch (error) {
|
|
1250
1276
|
if (error?.code === "ENOENT") return false;
|
|
1251
1277
|
throw error;
|
|
@@ -1277,7 +1303,7 @@ function defaultAgentSkillDirs(skillsDir) {
|
|
|
1277
1303
|
...EXTERNAL_AGENT_SKILL_DIRS
|
|
1278
1304
|
};
|
|
1279
1305
|
}
|
|
1280
|
-
async function removeUndesiredManagedSymlinks(agentDir, desiredSkills, managedRoots, failures, agent) {
|
|
1306
|
+
async function removeUndesiredManagedSymlinks(agentDir, desiredSkills, managedRoots, failures, agent, movedTargets = /* @__PURE__ */ new Set()) {
|
|
1281
1307
|
let removed = 0;
|
|
1282
1308
|
try {
|
|
1283
1309
|
await fs2.mkdir(agentDir, { recursive: true });
|
|
@@ -1285,7 +1311,7 @@ async function removeUndesiredManagedSymlinks(agentDir, desiredSkills, managedRo
|
|
|
1285
1311
|
for (const entry of existingEntries) {
|
|
1286
1312
|
const entryPath = path2.join(agentDir, entry.name);
|
|
1287
1313
|
try {
|
|
1288
|
-
if (!desiredSkills.has(entry.name) && await isManagedSymlink(entryPath, managedRoots)) {
|
|
1314
|
+
if (!desiredSkills.has(entry.name) && await isManagedSymlink(entryPath, managedRoots) && !(movedTargets.size > 0 && movedTargets.has(path2.resolve(agentDir, await fs2.readlink(entryPath))))) {
|
|
1289
1315
|
await fs2.unlink(entryPath);
|
|
1290
1316
|
removed += 1;
|
|
1291
1317
|
}
|
|
@@ -1308,15 +1334,174 @@ async function removeAllSymlinksForSkill(skillName, skillsDir = LEGACY_AGENTS_SK
|
|
|
1308
1334
|
const agentDirs = /* @__PURE__ */ new Set([...Object.values(agentSkillDirs), legacyGlobalSkillsDir]);
|
|
1309
1335
|
const expectedTarget = path2.resolve(skillsDir, safeName(skillName, skillsDir));
|
|
1310
1336
|
for (const agentDir of agentDirs) {
|
|
1311
|
-
const
|
|
1312
|
-
const
|
|
1337
|
+
const linkName = safeName(skillName, agentDir);
|
|
1338
|
+
const linkPath = path2.join(agentDir, linkName);
|
|
1339
|
+
const owned = options.ownership === "exact-skill-dir" ? await isManagedSymlink(linkPath, [expectedTarget]) : await isManagedSymlink(linkPath, managedRoots) && !await linksToOtherSkillFolder(linkPath, expectedTarget, skillsDir);
|
|
1313
1340
|
if (owned) {
|
|
1314
1341
|
await fs2.unlink(linkPath);
|
|
1315
1342
|
removed += 1;
|
|
1316
1343
|
}
|
|
1344
|
+
if (path2.resolve(agentDir) !== path2.resolve(skillsDir)) {
|
|
1345
|
+
try {
|
|
1346
|
+
removed += await removeLinksToTarget(agentDir, expectedTarget, /* @__PURE__ */ new Set([linkName]));
|
|
1347
|
+
} catch (error) {
|
|
1348
|
+
console.warn(`[skill-sync] Could not list ${agentDir} to remove the links to "${skillName}": ${error.message}`);
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
return removed;
|
|
1353
|
+
}
|
|
1354
|
+
async function linksToOtherSkillFolder(linkPath, expectedTarget, skillsDir) {
|
|
1355
|
+
try {
|
|
1356
|
+
const resolved = path2.resolve(path2.dirname(linkPath), await fs2.readlink(linkPath));
|
|
1357
|
+
if (resolved === expectedTarget || path2.dirname(resolved) !== path2.resolve(skillsDir)) return false;
|
|
1358
|
+
return (await fs2.stat(resolved)).isDirectory();
|
|
1359
|
+
} catch {
|
|
1360
|
+
return false;
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
async function hasLinkToTarget(agentDir, targetPath) {
|
|
1364
|
+
let entries;
|
|
1365
|
+
try {
|
|
1366
|
+
entries = await fs2.readdir(agentDir, { withFileTypes: true });
|
|
1367
|
+
} catch {
|
|
1368
|
+
return true;
|
|
1369
|
+
}
|
|
1370
|
+
for (const entry of entries) {
|
|
1371
|
+
if (!entry.isSymbolicLink()) continue;
|
|
1372
|
+
try {
|
|
1373
|
+
if (path2.resolve(agentDir, await fs2.readlink(path2.join(agentDir, entry.name))) === targetPath) return true;
|
|
1374
|
+
} catch {
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
return false;
|
|
1378
|
+
}
|
|
1379
|
+
async function linkNamesByTarget(agentDir, targets) {
|
|
1380
|
+
const names = /* @__PURE__ */ new Map();
|
|
1381
|
+
let entries;
|
|
1382
|
+
try {
|
|
1383
|
+
entries = await fs2.readdir(agentDir, { withFileTypes: true });
|
|
1384
|
+
} catch (error) {
|
|
1385
|
+
if (error?.code === "ENOENT") return names;
|
|
1386
|
+
throw error;
|
|
1387
|
+
}
|
|
1388
|
+
for (const entry of entries) {
|
|
1389
|
+
if (!entry.isSymbolicLink()) continue;
|
|
1390
|
+
try {
|
|
1391
|
+
const resolved = path2.resolve(agentDir, await fs2.readlink(path2.join(agentDir, entry.name)));
|
|
1392
|
+
if (targets.has(resolved)) names.set(resolved, [...names.get(resolved) ?? [], entry.name]);
|
|
1393
|
+
} catch (error) {
|
|
1394
|
+
if (error?.code !== "ENOENT") throw error;
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
return names;
|
|
1398
|
+
}
|
|
1399
|
+
async function unlinkIfTarget(agentDir, names, targetPath) {
|
|
1400
|
+
let removed = 0;
|
|
1401
|
+
for (const name of names) {
|
|
1402
|
+
const entryPath = path2.join(agentDir, name);
|
|
1403
|
+
try {
|
|
1404
|
+
if ((await fs2.lstat(entryPath)).isSymbolicLink() && path2.resolve(agentDir, await fs2.readlink(entryPath)) === targetPath) {
|
|
1405
|
+
await fs2.unlink(entryPath);
|
|
1406
|
+
removed += 1;
|
|
1407
|
+
}
|
|
1408
|
+
} catch (error) {
|
|
1409
|
+
if (error?.code !== "ENOENT") throw error;
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
return removed;
|
|
1413
|
+
}
|
|
1414
|
+
async function removeLinksToTarget(agentDir, targetPath, keepNames) {
|
|
1415
|
+
let entries;
|
|
1416
|
+
try {
|
|
1417
|
+
entries = await fs2.readdir(agentDir, { withFileTypes: true });
|
|
1418
|
+
} catch (error) {
|
|
1419
|
+
if (error?.code === "ENOENT") return 0;
|
|
1420
|
+
throw error;
|
|
1421
|
+
}
|
|
1422
|
+
const keep = new Set([...keepNames].map((name) => name.toLowerCase()));
|
|
1423
|
+
let removed = 0;
|
|
1424
|
+
for (const entry of entries) {
|
|
1425
|
+
if (!entry.isSymbolicLink() || keep.has(entry.name.toLowerCase())) continue;
|
|
1426
|
+
const entryPath = path2.join(agentDir, entry.name);
|
|
1427
|
+
try {
|
|
1428
|
+
const resolved = path2.resolve(agentDir, await fs2.readlink(entryPath));
|
|
1429
|
+
if (resolved !== targetPath) continue;
|
|
1430
|
+
await fs2.unlink(entryPath);
|
|
1431
|
+
removed += 1;
|
|
1432
|
+
} catch (error) {
|
|
1433
|
+
if (error?.code !== "ENOENT") throw error;
|
|
1434
|
+
}
|
|
1317
1435
|
}
|
|
1318
1436
|
return removed;
|
|
1319
1437
|
}
|
|
1438
|
+
async function readableNativeLinkName(skill, folderName, skillsDir) {
|
|
1439
|
+
if (!isNativeSkill(skill)) return null;
|
|
1440
|
+
let markdown = "";
|
|
1441
|
+
try {
|
|
1442
|
+
markdown = await fs2.readFile(path2.join(skillsDir, folderName, "SKILL.md"), "utf8");
|
|
1443
|
+
} catch {
|
|
1444
|
+
}
|
|
1445
|
+
const name = [nativeFrontmatterName(markdown), nativeFrontmatterName(skill.skill_md || ""), skill.display_name || ""].map((value) => value.trim()).find(Boolean);
|
|
1446
|
+
if (!name || name === folderName || name.length > 64 || !READABLE_SKILL_NAME.test(name) || NATIVE_FOLDER_NAME.test(name) || BASE_SKILL_LINK_NAMES.has(name)) {
|
|
1447
|
+
return null;
|
|
1448
|
+
}
|
|
1449
|
+
return name;
|
|
1450
|
+
}
|
|
1451
|
+
async function readableLinkAvailable(linkPath, targetPath, managedRoots, ownsWholeFolder) {
|
|
1452
|
+
let stats;
|
|
1453
|
+
try {
|
|
1454
|
+
stats = await fs2.lstat(linkPath);
|
|
1455
|
+
} catch (error) {
|
|
1456
|
+
return error?.code === "ENOENT";
|
|
1457
|
+
}
|
|
1458
|
+
if (!stats.isSymbolicLink()) return false;
|
|
1459
|
+
try {
|
|
1460
|
+
const resolved = path2.resolve(path2.dirname(linkPath), await fs2.readlink(linkPath));
|
|
1461
|
+
if (resolved === path2.resolve(targetPath)) return true;
|
|
1462
|
+
return ownsWholeFolder && isUnderManagedRoot(resolved, managedRoots);
|
|
1463
|
+
} catch {
|
|
1464
|
+
return false;
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
async function planAgentLinkNames(candidates, agentDir, skillsDir, managedRoots, ownsWholeFolder) {
|
|
1468
|
+
const reserved = new Set(
|
|
1469
|
+
candidates.filter((candidate) => !candidate.readableName).map((candidate) => candidate.folderName.toLowerCase())
|
|
1470
|
+
);
|
|
1471
|
+
const readableCounts = /* @__PURE__ */ new Map();
|
|
1472
|
+
for (const { readableName } of candidates) {
|
|
1473
|
+
if (!readableName) continue;
|
|
1474
|
+
const key = readableName.toLowerCase();
|
|
1475
|
+
readableCounts.set(key, (readableCounts.get(key) ?? 0) + 1);
|
|
1476
|
+
}
|
|
1477
|
+
const available = /* @__PURE__ */ new Map();
|
|
1478
|
+
for (; ; ) {
|
|
1479
|
+
const plan = /* @__PURE__ */ new Map();
|
|
1480
|
+
const owners = /* @__PURE__ */ new Map();
|
|
1481
|
+
for (const { folderName, readableName } of candidates) {
|
|
1482
|
+
let linkName = folderName;
|
|
1483
|
+
if (readableName) {
|
|
1484
|
+
const key = readableName.toLowerCase();
|
|
1485
|
+
if (!reserved.has(key) && readableCounts.get(key) === 1) {
|
|
1486
|
+
if (!available.has(folderName)) {
|
|
1487
|
+
available.set(folderName, await readableLinkAvailable(
|
|
1488
|
+
path2.join(agentDir, readableName),
|
|
1489
|
+
path2.join(skillsDir, folderName),
|
|
1490
|
+
managedRoots,
|
|
1491
|
+
ownsWholeFolder
|
|
1492
|
+
));
|
|
1493
|
+
}
|
|
1494
|
+
if (available.get(folderName)) linkName = readableName;
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
plan.set(linkName, folderName);
|
|
1498
|
+
owners.set(linkName.toLowerCase(), (owners.get(linkName.toLowerCase()) ?? 0) + 1);
|
|
1499
|
+
}
|
|
1500
|
+
const collisions = [...owners].filter(([name, count]) => count > 1 && !reserved.has(name)).map(([name]) => name);
|
|
1501
|
+
if (collisions.length === 0) return plan;
|
|
1502
|
+
for (const name of collisions) reserved.add(name);
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1320
1505
|
async function detectDeletedAgentSymlinks(cloudSkills, previousState, skillsDir = LEGACY_AGENTS_SKILLS_DIR, options = {}) {
|
|
1321
1506
|
const agentSkillDirs = { ...defaultAgentSkillDirs(skillsDir), ...options.agentSkillDirs };
|
|
1322
1507
|
const deletions = [];
|
|
@@ -1341,7 +1526,8 @@ async function detectDeletedAgentSymlinks(cloudSkills, previousState, skillsDir
|
|
|
1341
1526
|
continue;
|
|
1342
1527
|
}
|
|
1343
1528
|
const previous = previousState.skills[skill.name];
|
|
1344
|
-
|
|
1529
|
+
const verified = previous?.verifiedAgentLinks?.[agent];
|
|
1530
|
+
if (!previous || previous.cloudId !== skill.id || !verified || !skill.updated_at || previous.cloudUpdatedAt !== skill.updated_at) {
|
|
1345
1531
|
continue;
|
|
1346
1532
|
}
|
|
1347
1533
|
const cloudTargets = normalizeAgentTargets(skill.agent_targets);
|
|
@@ -1349,17 +1535,19 @@ async function detectDeletedAgentSymlinks(cloudSkills, previousState, skillsDir
|
|
|
1349
1535
|
if (!cloudTargets[agent] || !previousTargets[agent]) {
|
|
1350
1536
|
continue;
|
|
1351
1537
|
}
|
|
1352
|
-
let
|
|
1538
|
+
let linkName;
|
|
1539
|
+
let folderName;
|
|
1353
1540
|
try {
|
|
1354
|
-
|
|
1541
|
+
folderName = safeName(skill.name, skillsDir);
|
|
1542
|
+
linkName = safeName(typeof verified === "string" ? verified : folderName, agentDir);
|
|
1355
1543
|
} catch {
|
|
1356
1544
|
continue;
|
|
1357
1545
|
}
|
|
1358
|
-
const linkPath = path2.join(agentDir,
|
|
1546
|
+
const linkPath = path2.join(agentDir, linkName);
|
|
1359
1547
|
try {
|
|
1360
1548
|
await fs2.lstat(linkPath);
|
|
1361
1549
|
} catch (error) {
|
|
1362
|
-
if (error?.code === "ENOENT") {
|
|
1550
|
+
if (error?.code === "ENOENT" && !await hasLinkToTarget(agentDir, path2.resolve(skillsDir, folderName))) {
|
|
1363
1551
|
deletions.push({ skillId: skill.id, skillName: skill.name, agent });
|
|
1364
1552
|
}
|
|
1365
1553
|
}
|
|
@@ -1379,11 +1567,12 @@ async function syncSymlinks(skills, skillsDir = LEGACY_AGENTS_SKILLS_DIR, option
|
|
|
1379
1567
|
const agentSkillDirs = { ...defaultAgentSkillDirs(skillsDir), ...options.agentSkillDirs };
|
|
1380
1568
|
const legacyGlobalSkillsDir = options.legacyGlobalSkillsDir || LEGACY_AGENTS_SKILLS_DIR;
|
|
1381
1569
|
const managedRoots = managedSkillRoots(skillsDir, legacyGlobalSkillsDir);
|
|
1570
|
+
const ownsWholeFolder = options.removeUndesired !== false;
|
|
1382
1571
|
const desiredByAgent = {
|
|
1383
|
-
notis: /* @__PURE__ */ new
|
|
1384
|
-
claude_code: /* @__PURE__ */ new
|
|
1385
|
-
cursor: /* @__PURE__ */ new
|
|
1386
|
-
codex: /* @__PURE__ */ new
|
|
1572
|
+
notis: /* @__PURE__ */ new Map(),
|
|
1573
|
+
claude_code: /* @__PURE__ */ new Map(),
|
|
1574
|
+
cursor: /* @__PURE__ */ new Map(),
|
|
1575
|
+
codex: /* @__PURE__ */ new Map()
|
|
1387
1576
|
};
|
|
1388
1577
|
for (const skill of skills) {
|
|
1389
1578
|
if (skill.status !== "active") {
|
|
@@ -1391,17 +1580,20 @@ async function syncSymlinks(skills, skillsDir = LEGACY_AGENTS_SKILLS_DIR, option
|
|
|
1391
1580
|
}
|
|
1392
1581
|
const safeSkillName = safeName(skill.name, skillsDir);
|
|
1393
1582
|
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);
|
|
1583
|
+
for (const agent of Object.keys(desiredByAgent)) {
|
|
1584
|
+
if (targets[agent] && !desiredByAgent[agent].has(safeSkillName)) {
|
|
1585
|
+
desiredByAgent[agent].set(safeSkillName, skill);
|
|
1586
|
+
}
|
|
1402
1587
|
}
|
|
1403
|
-
|
|
1404
|
-
|
|
1588
|
+
}
|
|
1589
|
+
const readableNames = /* @__PURE__ */ new Map();
|
|
1590
|
+
for (const [folderName, skill] of [
|
|
1591
|
+
...desiredByAgent.claude_code,
|
|
1592
|
+
...desiredByAgent.cursor,
|
|
1593
|
+
...desiredByAgent.codex
|
|
1594
|
+
]) {
|
|
1595
|
+
if (!readableNames.has(folderName)) {
|
|
1596
|
+
readableNames.set(folderName, await readableNativeLinkName(skill, folderName, skillsDir));
|
|
1405
1597
|
}
|
|
1406
1598
|
}
|
|
1407
1599
|
for (const [agent, agentDir] of Object.entries(agentSkillDirs)) {
|
|
@@ -1415,13 +1607,39 @@ async function syncSymlinks(skills, skillsDir = LEGACY_AGENTS_SKILLS_DIR, option
|
|
|
1415
1607
|
result.failures.push({ name: agentFolderFailureName(agent), error: `Could not create agent skills directory (${error.message})` });
|
|
1416
1608
|
continue;
|
|
1417
1609
|
}
|
|
1418
|
-
const
|
|
1419
|
-
|
|
1420
|
-
|
|
1610
|
+
const external = EXTERNAL_AGENTS.includes(agent);
|
|
1611
|
+
const linkPlan = await planAgentLinkNames(
|
|
1612
|
+
[...desiredByAgent[agent].keys()].map((folderName) => ({
|
|
1613
|
+
folderName,
|
|
1614
|
+
readableName: external ? readableNames.get(folderName) ?? null : null
|
|
1615
|
+
})),
|
|
1616
|
+
agentDir,
|
|
1617
|
+
skillsDir,
|
|
1618
|
+
managedRoots,
|
|
1619
|
+
ownsWholeFolder
|
|
1620
|
+
);
|
|
1621
|
+
const movedTargets = new Set(external ? [...linkPlan.values()].filter((name) => isNativeSkill(desiredByAgent[agent].get(name))).map((name) => path2.resolve(skillsDir, name)) : []);
|
|
1622
|
+
if (ownsWholeFolder) {
|
|
1623
|
+
result.removed += await removeUndesiredManagedSymlinks(
|
|
1624
|
+
agentDir,
|
|
1625
|
+
new Set(linkPlan.keys()),
|
|
1626
|
+
managedRoots,
|
|
1627
|
+
result.failures,
|
|
1628
|
+
agent,
|
|
1629
|
+
movedTargets
|
|
1630
|
+
);
|
|
1631
|
+
}
|
|
1632
|
+
let namesByTarget = /* @__PURE__ */ new Map();
|
|
1633
|
+
if (movedTargets.size > 0) {
|
|
1634
|
+
try {
|
|
1635
|
+
namesByTarget = await linkNamesByTarget(agentDir, movedTargets);
|
|
1636
|
+
} catch (error) {
|
|
1637
|
+
result.failures.push({ name: agentFolderFailureName(agent), error: `Could not read agent skills directory (${error.message})` });
|
|
1638
|
+
}
|
|
1421
1639
|
}
|
|
1422
|
-
for (const skillName of
|
|
1640
|
+
for (const [linkName, skillName] of linkPlan) {
|
|
1423
1641
|
const targetPath = path2.join(skillsDir, skillName);
|
|
1424
|
-
const linkPath = path2.join(agentDir, safeName(
|
|
1642
|
+
const linkPath = path2.join(agentDir, safeName(linkName, agentDir));
|
|
1425
1643
|
try {
|
|
1426
1644
|
if (!(await fs2.stat(path2.join(targetPath, "SKILL.md"))).isFile()) throw new Error("Missing SKILL.md");
|
|
1427
1645
|
} catch {
|
|
@@ -1449,7 +1667,18 @@ async function syncSymlinks(skills, skillsDir = LEGACY_AGENTS_SKILLS_DIR, option
|
|
|
1449
1667
|
result.skipped += 1;
|
|
1450
1668
|
}
|
|
1451
1669
|
if (syncOutcome !== "blocked") {
|
|
1452
|
-
result.verifiedAgentLinks[skillName] = {
|
|
1670
|
+
result.verifiedAgentLinks[skillName] = {
|
|
1671
|
+
...result.verifiedAgentLinks[skillName],
|
|
1672
|
+
[agent]: linkName === skillName ? true : linkName
|
|
1673
|
+
};
|
|
1674
|
+
const otherNames = (namesByTarget.get(path2.resolve(targetPath)) ?? []).filter((name) => name.toLowerCase() !== linkName.toLowerCase());
|
|
1675
|
+
if (otherNames.length > 0) {
|
|
1676
|
+
try {
|
|
1677
|
+
result.removed += await unlinkIfTarget(agentDir, otherNames, path2.resolve(targetPath));
|
|
1678
|
+
} catch (error) {
|
|
1679
|
+
result.failures.push({ name: skillName, error: `${agentFailureLabel(agent)}: could not remove skill link (${error.message})` });
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1453
1682
|
}
|
|
1454
1683
|
}
|
|
1455
1684
|
}
|
|
@@ -2195,6 +2424,8 @@ async function runSkillSync(serverUrl, jwt, dependencies = {}, options = {}) {
|
|
|
2195
2424
|
};
|
|
2196
2425
|
}
|
|
2197
2426
|
export {
|
|
2427
|
+
MAX_SYNC_PUSH_SKILL_BYTES,
|
|
2428
|
+
SERVER_REQUEST_BODY_MAX_BYTES,
|
|
2198
2429
|
fetchSyncSettings,
|
|
2199
2430
|
isolatedLinkOptions,
|
|
2200
2431
|
materializeCloudSkillsForLocalShell,
|