@inupedia/spotlight-client 0.2.13 → 0.2.14

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 (31) hide show
  1. package/dist/node/capabilities/skillDirectoryLoader.d.ts +24 -0
  2. package/dist/node/capabilities/skillDirectoryLoader.d.ts.map +1 -0
  3. package/dist/node/capabilities/skillDirectoryLoader.js +308 -0
  4. package/dist/node/capabilities/skillFileValidator.d.ts +8 -0
  5. package/dist/node/capabilities/skillFileValidator.d.ts.map +1 -1
  6. package/dist/node/capabilities/skillFileValidator.js +46 -26
  7. package/dist/node/index.d.ts +1 -0
  8. package/dist/node/index.d.ts.map +1 -1
  9. package/dist/node/index.js +1 -0
  10. package/dist/vite/capabilityBuild.d.ts +9 -0
  11. package/dist/vite/capabilityBuild.d.ts.map +1 -0
  12. package/dist/vite/capabilityBuild.js +141 -0
  13. package/dist/vite/capabilityBuildTypes.d.ts +29 -0
  14. package/dist/vite/capabilityBuildTypes.d.ts.map +1 -0
  15. package/dist/vite/capabilityBuildTypes.js +1 -0
  16. package/dist/vite/capabilityDevMiddleware.d.ts +5 -0
  17. package/dist/vite/capabilityDevMiddleware.d.ts.map +1 -0
  18. package/dist/vite/capabilityDevMiddleware.js +40 -0
  19. package/dist/vite/capabilityVirtualModule.d.ts +11 -0
  20. package/dist/vite/capabilityVirtualModule.d.ts.map +1 -0
  21. package/dist/vite/capabilityVirtualModule.js +43 -0
  22. package/dist/vite/capabilityVirtualModuleTypes.d.ts +12 -0
  23. package/dist/vite/capabilityVirtualModuleTypes.d.ts.map +1 -0
  24. package/dist/vite/capabilityVirtualModuleTypes.js +1 -0
  25. package/dist/vite/index.d.ts +4 -0
  26. package/dist/vite/index.d.ts.map +1 -1
  27. package/dist/vite/index.js +3 -0
  28. package/dist/vite/spotlightCapabilities.d.ts +4 -0
  29. package/dist/vite/spotlightCapabilities.d.ts.map +1 -0
  30. package/dist/vite/spotlightCapabilities.js +165 -0
  31. package/package.json +4 -4
@@ -0,0 +1,24 @@
1
+ import type { CanonicalSkillInputV1 } from "./capabilityArtifactTypes.js";
2
+ import type { ScannedSkill } from "./skillScanner.js";
3
+ export declare const CAPABILITY_SKILL_LIMITS_V1: {
4
+ readonly maxSkills: 200;
5
+ readonly maxFiles: 2000;
6
+ readonly maxExpandedBytes: number;
7
+ };
8
+ export type CapabilitySkillLoadErrorCodeV1 = "CAPABILITY_SKILL_ENTRY_UNSAFE" | "CAPABILITY_SKILL_LIMIT_EXCEEDED" | "CAPABILITY_FILE_LIMIT_EXCEEDED" | "CAPABILITY_EXPANDED_SIZE_EXCEEDED";
9
+ export declare class CapabilitySkillLoadErrorV1 extends Error {
10
+ readonly code: CapabilitySkillLoadErrorCodeV1;
11
+ constructor(code: CapabilitySkillLoadErrorCodeV1, message: string);
12
+ }
13
+ export interface LoadCanonicalSkillsInputV1 {
14
+ projectRoot: string;
15
+ skills: readonly ScannedSkill[];
16
+ }
17
+ export interface LoadedCanonicalSkillsV1 {
18
+ skills: CanonicalSkillInputV1[];
19
+ watchedFiles: string[];
20
+ fileCount: number;
21
+ expandedBytes: number;
22
+ }
23
+ export declare function loadCanonicalSkillsV1(input: LoadCanonicalSkillsInputV1): Promise<LoadedCanonicalSkillsV1>;
24
+ //# sourceMappingURL=skillDirectoryLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skillDirectoryLoader.d.ts","sourceRoot":"","sources":["../../../src/node/capabilities/skillDirectoryLoader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,eAAO,MAAM,0BAA0B;;;;CAI7B,CAAC;AAEX,MAAM,MAAM,8BAA8B,GACtC,+BAA+B,GAC/B,iCAAiC,GACjC,gCAAgC,GAChC,mCAAmC,CAAC;AAExC,qBAAa,0BAA2B,SAAQ,KAAK;IACnD,QAAQ,CAAC,IAAI,EAAE,8BAA8B,CAAC;gBAElC,IAAI,EAAE,8BAA8B,EAAE,OAAO,EAAE,MAAM;CAKlE;AAED,MAAM,WAAW,0BAA0B;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,SAAS,YAAY,EAAE,CAAC;CACjC;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,qBAAqB,EAAE,CAAC;IAChC,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;CACvB;AA4PD,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,0BAA0B,GAChC,OAAO,CAAC,uBAAuB,CAAC,CAiJlC"}
@@ -0,0 +1,308 @@
1
+ import { constants } from "node:fs";
2
+ import { lstat, open, opendir, realpath } from "node:fs/promises";
3
+ import { isAbsolute, relative, resolve, sep } from "node:path";
4
+ export const CAPABILITY_SKILL_LIMITS_V1 = {
5
+ maxSkills: 200,
6
+ maxFiles: 2_000,
7
+ maxExpandedBytes: 20 * 1024 * 1024,
8
+ };
9
+ export class CapabilitySkillLoadErrorV1 extends Error {
10
+ code;
11
+ constructor(code, message) {
12
+ super(message);
13
+ this.name = "CapabilitySkillLoadErrorV1";
14
+ this.code = code;
15
+ }
16
+ }
17
+ const compareUtf8 = (left, right) => Buffer.compare(Buffer.from(left, "utf8"), Buffer.from(right, "utf8"));
18
+ function isContained(base, candidate) {
19
+ const path = relative(base, candidate);
20
+ return path !== ".." && !path.startsWith(`..${sep}`) && !isAbsolute(path);
21
+ }
22
+ function toPosix(path) {
23
+ return path.split(sep).join("/");
24
+ }
25
+ function unsafe(message) {
26
+ return new CapabilitySkillLoadErrorV1("CAPABILITY_SKILL_ENTRY_UNSAFE", message);
27
+ }
28
+ function hasSameIdentity(left, right) {
29
+ return left.dev === right.dev && left.ino === right.ino;
30
+ }
31
+ function hasSameSnapshot(left, right) {
32
+ return (hasSameIdentity(left, right) &&
33
+ left.size === right.size &&
34
+ left.mtimeNs === right.mtimeNs &&
35
+ left.ctimeNs === right.ctimeNs);
36
+ }
37
+ function validateSkillDefinitions(projectRoot, skills) {
38
+ const sortedNames = [...skills].map((skill) => skill.name).sort(compareUtf8);
39
+ for (let index = 1; index < sortedNames.length; index += 1) {
40
+ if (sortedNames[index] === sortedNames[index - 1]) {
41
+ throw unsafe(`Duplicate Skill name is not allowed: ${sortedNames[index]}`);
42
+ }
43
+ }
44
+ const sortedDirectories = skills
45
+ .map((skill) => ({
46
+ name: skill.name,
47
+ directory: resolve(projectRoot, skill.directory),
48
+ }))
49
+ .sort((left, right) => compareUtf8(left.directory, right.directory) ||
50
+ compareUtf8(left.name, right.name));
51
+ for (let parentIndex = 0; parentIndex < sortedDirectories.length; parentIndex += 1) {
52
+ const parent = sortedDirectories[parentIndex];
53
+ for (let candidateIndex = parentIndex + 1; candidateIndex < sortedDirectories.length; candidateIndex += 1) {
54
+ const candidate = sortedDirectories[candidateIndex];
55
+ if (parent.directory === candidate.directory ||
56
+ isContained(parent.directory, candidate.directory)) {
57
+ throw unsafe(`Duplicate or overlapping Skill directories are not allowed for Skills "${parent.name}" and "${candidate.name}"`);
58
+ }
59
+ }
60
+ }
61
+ }
62
+ async function pinDirectory(directory, canonicalSkillRoot) {
63
+ try {
64
+ const before = await lstat(directory, { bigint: true });
65
+ if (before.isSymbolicLink() || !before.isDirectory()) {
66
+ throw unsafe("Skill directory is not a regular directory");
67
+ }
68
+ const canonicalPath = await realpath(directory);
69
+ const after = await lstat(directory, { bigint: true });
70
+ if (after.isSymbolicLink() ||
71
+ !after.isDirectory() ||
72
+ !hasSameIdentity(before, after)) {
73
+ throw unsafe("Skill directory changed while inspected");
74
+ }
75
+ if (canonicalSkillRoot !== undefined &&
76
+ !isContained(canonicalSkillRoot, canonicalPath)) {
77
+ throw unsafe("Skill directory resolves outside its root");
78
+ }
79
+ return {
80
+ path: directory,
81
+ canonicalPath,
82
+ dev: after.dev,
83
+ ino: after.ino,
84
+ size: after.size,
85
+ mtimeNs: after.mtimeNs,
86
+ ctimeNs: after.ctimeNs,
87
+ };
88
+ }
89
+ catch (error) {
90
+ if (error instanceof CapabilitySkillLoadErrorV1)
91
+ throw error;
92
+ throw unsafe("Cannot securely inspect Skill directory");
93
+ }
94
+ }
95
+ async function validateDirectory(pin) {
96
+ try {
97
+ const stat = await lstat(pin.path, { bigint: true });
98
+ const canonicalPath = await realpath(pin.path);
99
+ if (stat.isSymbolicLink() ||
100
+ !stat.isDirectory() ||
101
+ !hasSameSnapshot(pin, stat) ||
102
+ canonicalPath !== pin.canonicalPath) {
103
+ throw unsafe("Skill directory changed during traversal");
104
+ }
105
+ }
106
+ catch (error) {
107
+ if (error instanceof CapabilitySkillLoadErrorV1)
108
+ throw error;
109
+ throw unsafe("Cannot revalidate Skill directory");
110
+ }
111
+ }
112
+ async function readBoundedFile(candidate, parent, canonicalSkillRoot, remainingBytes) {
113
+ let handle;
114
+ try {
115
+ await validateDirectory(parent);
116
+ const pathBefore = await lstat(candidate, { bigint: true });
117
+ if (pathBefore.isSymbolicLink() || !pathBefore.isFile()) {
118
+ throw unsafe("Non-regular Skill entry is not allowed");
119
+ }
120
+ const canonicalBefore = await realpath(candidate);
121
+ if (!isContained(canonicalSkillRoot, canonicalBefore)) {
122
+ throw unsafe("Skill file resolves outside its directory");
123
+ }
124
+ // O_NOFOLLOW closes the final-component race on platforms that expose it.
125
+ // The handle/path identity and canonical containment checks below are the
126
+ // explicit safe fallback where the flag is unavailable.
127
+ const noFollow = typeof constants.O_NOFOLLOW === "number" ? constants.O_NOFOLLOW : 0;
128
+ handle = await open(candidate, constants.O_RDONLY | noFollow);
129
+ const opened = await handle.stat({ bigint: true });
130
+ const pathAfterOpen = await lstat(candidate, { bigint: true });
131
+ const canonicalAfterOpen = await realpath(candidate);
132
+ await validateDirectory(parent);
133
+ if (!opened.isFile() ||
134
+ pathAfterOpen.isSymbolicLink() ||
135
+ !pathAfterOpen.isFile() ||
136
+ !hasSameIdentity(pathBefore, opened) ||
137
+ !hasSameIdentity(opened, pathAfterOpen) ||
138
+ pathBefore.size !== opened.size ||
139
+ opened.size !== pathAfterOpen.size ||
140
+ pathBefore.mtimeNs !== opened.mtimeNs ||
141
+ pathBefore.ctimeNs !== opened.ctimeNs ||
142
+ opened.mtimeNs !== pathAfterOpen.mtimeNs ||
143
+ opened.ctimeNs !== pathAfterOpen.ctimeNs ||
144
+ canonicalBefore !== canonicalAfterOpen ||
145
+ !isContained(canonicalSkillRoot, canonicalAfterOpen)) {
146
+ throw unsafe("Skill file changed before reading");
147
+ }
148
+ const chunks = [];
149
+ let bytesRead = 0;
150
+ const maximumRead = remainingBytes + 1;
151
+ while (bytesRead < maximumRead) {
152
+ const buffer = Buffer.allocUnsafe(Math.min(64 * 1024, maximumRead - bytesRead));
153
+ const result = await handle.read(buffer, 0, buffer.byteLength, null);
154
+ if (result.bytesRead === 0)
155
+ break;
156
+ chunks.push(buffer.subarray(0, result.bytesRead));
157
+ bytesRead += result.bytesRead;
158
+ }
159
+ const openedAfterRead = await handle.stat({ bigint: true });
160
+ const pathAfterRead = await lstat(candidate, { bigint: true });
161
+ const canonicalAfterRead = await realpath(candidate);
162
+ await validateDirectory(parent);
163
+ if (pathAfterRead.isSymbolicLink() ||
164
+ !pathAfterRead.isFile() ||
165
+ !hasSameIdentity(opened, openedAfterRead) ||
166
+ !hasSameIdentity(openedAfterRead, pathAfterRead) ||
167
+ opened.size !== openedAfterRead.size ||
168
+ openedAfterRead.size !== pathAfterRead.size ||
169
+ opened.mtimeNs !== openedAfterRead.mtimeNs ||
170
+ opened.ctimeNs !== openedAfterRead.ctimeNs ||
171
+ openedAfterRead.mtimeNs !== pathAfterRead.mtimeNs ||
172
+ openedAfterRead.ctimeNs !== pathAfterRead.ctimeNs ||
173
+ canonicalAfterOpen !== canonicalAfterRead ||
174
+ !isContained(canonicalSkillRoot, canonicalAfterRead)) {
175
+ throw unsafe("Skill file changed while reading");
176
+ }
177
+ if (bytesRead > remainingBytes) {
178
+ throw new CapabilitySkillLoadErrorV1("CAPABILITY_EXPANDED_SIZE_EXCEEDED", `Expanded size exceeds ${CAPABILITY_SKILL_LIMITS_V1.maxExpandedBytes} bytes`);
179
+ }
180
+ return Buffer.concat(chunks, bytesRead);
181
+ }
182
+ catch (error) {
183
+ if (error instanceof CapabilitySkillLoadErrorV1)
184
+ throw error;
185
+ throw unsafe("Cannot securely read Skill file");
186
+ }
187
+ finally {
188
+ await handle?.close().catch(() => undefined);
189
+ }
190
+ }
191
+ export async function loadCanonicalSkillsV1(input) {
192
+ if (input.skills.length > CAPABILITY_SKILL_LIMITS_V1.maxSkills) {
193
+ throw new CapabilitySkillLoadErrorV1("CAPABILITY_SKILL_LIMIT_EXCEEDED", `Skill count ${input.skills.length} exceeds ${CAPABILITY_SKILL_LIMITS_V1.maxSkills}`);
194
+ }
195
+ const projectRoot = resolve(input.projectRoot);
196
+ validateSkillDefinitions(projectRoot, input.skills);
197
+ let canonicalProjectRoot;
198
+ try {
199
+ canonicalProjectRoot = await realpath(projectRoot);
200
+ }
201
+ catch {
202
+ throw unsafe("Cannot securely resolve project root");
203
+ }
204
+ const sortedSkills = [...input.skills].sort((left, right) => compareUtf8(left.name, right.name));
205
+ const pinnedSkills = [];
206
+ for (const skill of sortedSkills) {
207
+ const directory = resolve(projectRoot, skill.directory);
208
+ if (!isContained(projectRoot, directory)) {
209
+ throw unsafe(`Skill "${skill.name}" directory escapes project root`);
210
+ }
211
+ const root = await pinDirectory(directory);
212
+ if (!isContained(canonicalProjectRoot, root.canonicalPath)) {
213
+ throw unsafe(`Skill "${skill.name}" directory resolves outside project root`);
214
+ }
215
+ pinnedSkills.push({ skill, directory, root });
216
+ }
217
+ for (let leftIndex = 0; leftIndex < pinnedSkills.length; leftIndex += 1) {
218
+ const left = pinnedSkills[leftIndex];
219
+ for (let rightIndex = leftIndex + 1; rightIndex < pinnedSkills.length; rightIndex += 1) {
220
+ const right = pinnedSkills[rightIndex];
221
+ if (hasSameIdentity(left.root, right.root) ||
222
+ left.root.canonicalPath === right.root.canonicalPath ||
223
+ isContained(left.root.canonicalPath, right.root.canonicalPath) ||
224
+ isContained(right.root.canonicalPath, left.root.canonicalPath)) {
225
+ throw unsafe("Duplicate or overlapping Skill directories are not allowed");
226
+ }
227
+ }
228
+ }
229
+ const loadedSkills = [];
230
+ const watchedFiles = [];
231
+ let fileCount = 0;
232
+ let expandedBytes = 0;
233
+ for (const pinnedSkill of pinnedSkills) {
234
+ const { skill, directory: skillDirectory, root: skillRoot } = pinnedSkill;
235
+ const files = [];
236
+ const walk = async (directory) => {
237
+ await validateDirectory(directory);
238
+ let directoryHandle;
239
+ const entries = [];
240
+ try {
241
+ directoryHandle = await opendir(directory.path);
242
+ await validateDirectory(directory);
243
+ for (;;) {
244
+ const entry = await directoryHandle.read();
245
+ if (entry === null)
246
+ break;
247
+ entries.push(entry);
248
+ }
249
+ }
250
+ catch {
251
+ throw unsafe(`Cannot read directory for Skill "${skill.name}"`);
252
+ }
253
+ finally {
254
+ await directoryHandle?.close().catch(() => undefined);
255
+ }
256
+ await validateDirectory(directory);
257
+ entries.sort((left, right) => compareUtf8(left.name, right.name));
258
+ for (const entry of entries) {
259
+ await validateDirectory(directory);
260
+ const candidate = resolve(directory.path, entry.name);
261
+ if (!isContained(skillDirectory, candidate)) {
262
+ throw unsafe("Skill entry escapes its directory");
263
+ }
264
+ let stat;
265
+ try {
266
+ stat = await lstat(candidate, { bigint: true });
267
+ }
268
+ catch {
269
+ throw unsafe("Cannot inspect Skill entry");
270
+ }
271
+ if (stat.isSymbolicLink()) {
272
+ throw unsafe("Symbolic links are not allowed in Skills");
273
+ }
274
+ if (stat.isDirectory()) {
275
+ const child = await pinDirectory(candidate, skillRoot.canonicalPath);
276
+ await walk(child);
277
+ await validateDirectory(directory);
278
+ continue;
279
+ }
280
+ if (!stat.isFile()) {
281
+ throw unsafe("Non-regular Skill entry is not allowed");
282
+ }
283
+ fileCount += 1;
284
+ if (fileCount > CAPABILITY_SKILL_LIMITS_V1.maxFiles) {
285
+ throw new CapabilitySkillLoadErrorV1("CAPABILITY_FILE_LIMIT_EXCEEDED", `File count ${fileCount} exceeds ${CAPABILITY_SKILL_LIMITS_V1.maxFiles}`);
286
+ }
287
+ const bytes = await readBoundedFile(candidate, directory, skillRoot.canonicalPath, CAPABILITY_SKILL_LIMITS_V1.maxExpandedBytes - expandedBytes);
288
+ expandedBytes += bytes.byteLength;
289
+ files.push({
290
+ relativePath: toPosix(relative(skillDirectory, candidate)),
291
+ bytes,
292
+ });
293
+ watchedFiles.push(candidate);
294
+ }
295
+ await validateDirectory(directory);
296
+ };
297
+ await walk(skillRoot);
298
+ files.sort((left, right) => compareUtf8(left.relativePath, right.relativePath));
299
+ loadedSkills.push({ name: skill.name, files });
300
+ }
301
+ watchedFiles.sort(compareUtf8);
302
+ return {
303
+ skills: loadedSkills,
304
+ watchedFiles,
305
+ fileCount,
306
+ expandedBytes,
307
+ };
308
+ }
@@ -5,5 +5,13 @@ export type ValidateScannedSkillInput = {
5
5
  skill: ScannedSkill;
6
6
  mode?: "strict" | "compat";
7
7
  };
8
+ export type ValidateSkillContentInput = {
9
+ skill: ScannedSkill;
10
+ markdown: string;
11
+ mode?: "strict" | "compat";
12
+ skillRoot: string;
13
+ readReference: (relativePath: string) => Promise<Uint8Array | undefined>;
14
+ };
15
+ export declare function validateSkillContent(input: ValidateSkillContentInput): Promise<AgentSkillValidationResult>;
8
16
  export declare function validateScannedSkill(input: ValidateScannedSkillInput): Promise<AgentSkillValidationResult>;
9
17
  //# sourceMappingURL=skillFileValidator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"skillFileValidator.d.ts","sourceRoot":"","sources":["../../../src/node/capabilities/skillFileValidator.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAGL,KAAK,0BAA0B,EAChC,MAAM,qBAAqB,CAAC;AAO7B,MAAM,MAAM,yBAAyB,GAAG;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,YAAY,CAAC;IACpB,IAAI,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;CAC5B,CAAC;AAiGF,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,yBAAyB,GAC/B,OAAO,CAAC,0BAA0B,CAAC,CAmCrC"}
1
+ {"version":3,"file":"skillFileValidator.d.ts","sourceRoot":"","sources":["../../../src/node/capabilities/skillFileValidator.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAGL,KAAK,0BAA0B,EAChC,MAAM,qBAAqB,CAAC;AAO7B,MAAM,MAAM,yBAAyB,GAAG;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,YAAY,CAAC;IACpB,IAAI,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,KAAK,EAAE,YAAY,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,CACb,YAAY,EAAE,MAAM,KACjB,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;CACtC,CAAC;AA2FF,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,yBAAyB,GAC/B,OAAO,CAAC,0BAA0B,CAAC,CAiCrC;AAED,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,yBAAyB,GAC/B,OAAO,CAAC,0BAA0B,CAAC,CA+BrC"}
@@ -28,48 +28,37 @@ function isWithin(root, candidate) {
28
28
  return (relativePath === "" ||
29
29
  (!relativePath.startsWith("..") && !isAbsolute(relativePath)));
30
30
  }
31
- function warning(input, code, message) {
31
+ function warning(skill, code, message) {
32
32
  return {
33
33
  code,
34
34
  severity: "warning",
35
35
  message,
36
- skillFile: input.skill.skillFile,
36
+ skillFile: skill.skillFile,
37
37
  };
38
38
  }
39
- async function referenceWarnings(input, markdown, skillPath) {
40
- const skillRoot = dirname(skillPath);
39
+ async function referenceWarnings(input, markdown) {
40
+ const skillRoot = resolve(input.skillRoot);
41
41
  const diagnostics = [];
42
42
  for (const link of extractRelativeMarkdownLinks(markdown)) {
43
43
  const target = resolve(skillRoot, link);
44
44
  if (!isWithin(skillRoot, target)) {
45
- diagnostics.push(warning(input, "SKILL_REFERENCE_OUTSIDE_ROOT", `Markdown reference "${link}" resolves outside the Skill root.`));
45
+ diagnostics.push(warning(input.skill, "SKILL_REFERENCE_OUTSIDE_ROOT", `Markdown reference "${link}" resolves outside the Skill root.`));
46
46
  continue;
47
47
  }
48
- let stats;
49
- try {
50
- stats = await lstat(target);
51
- }
52
- catch (error) {
53
- if (error.code === "ENOENT")
54
- continue;
55
- throw error;
56
- }
57
- if (!stats.isFile() ||
58
- stats.isSymbolicLink() ||
59
- stats.size > MAX_REFERENCE_BYTES) {
48
+ const referencedBytes = await input.readReference(relative(skillRoot, target));
49
+ if (referencedBytes === undefined ||
50
+ referencedBytes.byteLength > MAX_REFERENCE_BYTES) {
60
51
  continue;
61
52
  }
62
- const referencedMarkdown = await readFile(target, "utf8");
53
+ const referencedMarkdown = Buffer.from(referencedBytes).toString("utf8");
63
54
  if (extractRelativeMarkdownLinks(referencedMarkdown).length > 0) {
64
- diagnostics.push(warning(input, "SKILL_REFERENCE_CHAIN_DEEP", `Markdown reference "${link}" links to another Markdown reference.`));
55
+ diagnostics.push(warning(input.skill, "SKILL_REFERENCE_CHAIN_DEEP", `Markdown reference "${link}" links to another Markdown reference.`));
65
56
  }
66
57
  }
67
58
  return diagnostics;
68
59
  }
69
- export async function validateScannedSkill(input) {
70
- const projectRoot = resolve(input.projectRoot);
71
- const skillPath = resolve(projectRoot, input.skill.skillFile);
72
- const markdown = (await readFile(skillPath, "utf8")).replace(/\r\n?/g, "\n");
60
+ export async function validateSkillContent(input) {
61
+ const markdown = input.markdown.replace(/\r\n?/g, "\n");
73
62
  const result = validateAgentSkillMarkdown({
74
63
  directoryName: input.skill.name,
75
64
  skillFile: input.skill.skillFile,
@@ -80,11 +69,42 @@ export async function validateScannedSkill(input) {
80
69
  const lineCount = markdown.split("\n").length;
81
70
  const estimatedTokens = Math.ceil(markdown.length / 4);
82
71
  if (lineCount > 500) {
83
- diagnostics.push(warning(input, "SKILL_RECOMMENDATION_LINES", `SKILL.md contains ${lineCount} lines; the Agent Skills recommendation is at most 500.`));
72
+ diagnostics.push(warning(input.skill, "SKILL_RECOMMENDATION_LINES", `SKILL.md contains ${lineCount} lines; the Agent Skills recommendation is at most 500.`));
84
73
  }
85
74
  if (estimatedTokens > 5_000) {
86
- diagnostics.push(warning(input, "SKILL_RECOMMENDATION_TOKENS", `SKILL.md has a deterministic estimate of ${estimatedTokens} tokens; the recommendation is at most 5000.`));
75
+ diagnostics.push(warning(input.skill, "SKILL_RECOMMENDATION_TOKENS", `SKILL.md has a deterministic estimate of ${estimatedTokens} tokens; the recommendation is at most 5000.`));
87
76
  }
88
- diagnostics.push(...(await referenceWarnings(input, markdown, skillPath)));
77
+ diagnostics.push(...(await referenceWarnings(input, markdown)));
89
78
  return { ...result, diagnostics };
90
79
  }
80
+ export async function validateScannedSkill(input) {
81
+ const projectRoot = resolve(input.projectRoot);
82
+ const skillPath = resolve(projectRoot, input.skill.skillFile);
83
+ const skillRoot = dirname(skillPath);
84
+ const markdown = await readFile(skillPath, "utf8");
85
+ return validateSkillContent({
86
+ skill: input.skill,
87
+ markdown,
88
+ mode: input.mode,
89
+ skillRoot,
90
+ async readReference(relativePath) {
91
+ const target = resolve(skillRoot, relativePath);
92
+ let stats;
93
+ try {
94
+ stats = await lstat(target);
95
+ }
96
+ catch (error) {
97
+ if (error.code === "ENOENT") {
98
+ return undefined;
99
+ }
100
+ throw error;
101
+ }
102
+ if (!stats.isFile() ||
103
+ stats.isSymbolicLink() ||
104
+ stats.size > MAX_REFERENCE_BYTES) {
105
+ return undefined;
106
+ }
107
+ return readFile(target);
108
+ },
109
+ });
110
+ }
@@ -1,6 +1,7 @@
1
1
  export { joinSkillScriptPath, type SkillScriptRunResult, } from "../skillScriptPath.js";
2
2
  export { createNodeSkillScriptRunner } from "./skillScriptRunner.js";
3
3
  export { DEFAULT_SKILL_ROOTS, scanProjectSkills, type ScanProjectSkillsOptions, type ScannedSkill, type SkillRootInput, type SkillScanDiagnostic, type SkillScanMode, type SkillScanResult, } from "./capabilities/skillScanner.js";
4
+ export { CAPABILITY_SKILL_LIMITS_V1, CapabilitySkillLoadErrorV1, loadCanonicalSkillsV1, type CapabilitySkillLoadErrorCodeV1, type LoadCanonicalSkillsInputV1, type LoadedCanonicalSkillsV1, } from "./capabilities/skillDirectoryLoader.js";
4
5
  export { validateAgentSkillMarkdown, type AgentSkillDiagnostic, type AgentSkillDiagnosticCode, type AgentSkillDiagnosticSeverity, type AgentSkillValidationResult, type ValidatedAgentSkill, type ValidateAgentSkillMarkdownInput, } from "./capabilities/skillValidator.js";
5
6
  export { validateScannedSkill, type ValidateScannedSkillInput, } from "./capabilities/skillFileValidator.js";
6
7
  export { buildCapabilityArtifactV1, type CapabilityArtifactBuildV1, } from "./capabilities/capabilityArtifact.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,KAAK,oBAAoB,GAC1B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,eAAe,GACrB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,0BAA0B,EAC1B,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,4BAA4B,EACjC,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,EACxB,KAAK,+BAA+B,GACrC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,oBAAoB,EACpB,KAAK,yBAAyB,GAC/B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,yBAAyB,EACzB,KAAK,yBAAyB,GAC/B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,KAAK,wBAAwB,GAC9B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,+BAA+B,EAC/B,uBAAuB,EACvB,KAAK,2BAA2B,GACjC,MAAM,2CAA2C,CAAC;AACnD,YAAY,EACV,yBAAyB,EACzB,qBAAqB,EACrB,yBAAyB,EACzB,6BAA6B,EAC7B,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,KAAK,kBAAkB,GACxB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,mBAAmB,EACnB,KAAK,mBAAmB,EACxB,KAAK,cAAc,GACpB,MAAM,gCAAgC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,KAAK,oBAAoB,GAC1B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,eAAe,GACrB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,qBAAqB,EACrB,KAAK,8BAA8B,EACnC,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,GAC7B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,0BAA0B,EAC1B,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,4BAA4B,EACjC,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,EACxB,KAAK,+BAA+B,GACrC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,oBAAoB,EACpB,KAAK,yBAAyB,GAC/B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,yBAAyB,EACzB,KAAK,yBAAyB,GAC/B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,KAAK,wBAAwB,GAC9B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,+BAA+B,EAC/B,uBAAuB,EACvB,KAAK,2BAA2B,GACjC,MAAM,2CAA2C,CAAC;AACnD,YAAY,EACV,yBAAyB,EACzB,qBAAqB,EACrB,yBAAyB,EACzB,6BAA6B,EAC7B,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,KAAK,kBAAkB,GACxB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,mBAAmB,EACnB,KAAK,mBAAmB,EACxB,KAAK,cAAc,GACpB,MAAM,gCAAgC,CAAC"}
@@ -1,6 +1,7 @@
1
1
  export { joinSkillScriptPath, } from "../skillScriptPath.js";
2
2
  export { createNodeSkillScriptRunner } from "./skillScriptRunner.js";
3
3
  export { DEFAULT_SKILL_ROOTS, scanProjectSkills, } from "./capabilities/skillScanner.js";
4
+ export { CAPABILITY_SKILL_LIMITS_V1, CapabilitySkillLoadErrorV1, loadCanonicalSkillsV1, } from "./capabilities/skillDirectoryLoader.js";
4
5
  export { validateAgentSkillMarkdown, } from "./capabilities/skillValidator.js";
5
6
  export { validateScannedSkill, } from "./capabilities/skillFileValidator.js";
6
7
  export { buildCapabilityArtifactV1, } from "./capabilities/capabilityArtifact.js";
@@ -0,0 +1,9 @@
1
+ import type { CapabilityPluginBuildResultV1, SpotlightCapabilitiesOptionsV1, SpotlightCapabilityProjectBuildV1 } from "./capabilityBuildTypes.js";
2
+ export type { CapabilityBuildInfoV1, CapabilityPluginBuildResultV1, SpotlightCapabilitiesOptionsV1, SpotlightCapabilityProjectBuildV1, } from "./capabilityBuildTypes.js";
3
+ export declare function buildViteCapabilitiesV1(input: {
4
+ root: string;
5
+ command: "serve" | "build";
6
+ project: SpotlightCapabilityProjectBuildV1;
7
+ options?: SpotlightCapabilitiesOptionsV1;
8
+ }): Promise<CapabilityPluginBuildResultV1>;
9
+ //# sourceMappingURL=capabilityBuild.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilityBuild.d.ts","sourceRoot":"","sources":["../../src/vite/capabilityBuild.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAEV,6BAA6B,EAC7B,8BAA8B,EAC9B,iCAAiC,EAClC,MAAM,2BAA2B,CAAC;AAEnC,YAAY,EACV,qBAAqB,EACrB,6BAA6B,EAC7B,8BAA8B,EAC9B,iCAAiC,GAClC,MAAM,2BAA2B,CAAC;AAyFnC,wBAAsB,uBAAuB,CAAC,KAAK,EAAE;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC;IAC3B,OAAO,EAAE,iCAAiC,CAAC;IAC3C,OAAO,CAAC,EAAE,8BAA8B,CAAC;CAC1C,GAAG,OAAO,CAAC,6BAA6B,CAAC,CA6FzC"}
@@ -0,0 +1,141 @@
1
+ import { resolve, sep } from "node:path";
2
+ import { isProxy } from "node:util/types";
3
+ import { buildCapabilityArtifactV1, buildToolManifestV1, CapabilityArtifactError, loadCanonicalSkillsV1, scanProjectSkills, } from "../node/index.js";
4
+ import { validateSkillContent } from "../node/capabilities/skillFileValidator.js";
5
+ const PROJECT_FIELDS = new Set(["projectId", "tools"]);
6
+ function invalidInput(message) {
7
+ throw new CapabilityArtifactError("ARTIFACT_INPUT_INVALID", message);
8
+ }
9
+ function validateProject(value) {
10
+ if (value === null ||
11
+ typeof value !== "object" ||
12
+ Array.isArray(value) ||
13
+ isProxy(value)) {
14
+ invalidInput("Capability project must be a plain object");
15
+ }
16
+ const prototype = Object.getPrototypeOf(value);
17
+ if (prototype !== Object.prototype && prototype !== null) {
18
+ invalidInput("Capability project must be a plain object");
19
+ }
20
+ const keys = Reflect.ownKeys(value);
21
+ if (keys.length !== PROJECT_FIELDS.size ||
22
+ keys.some((key) => typeof key !== "string" || !PROJECT_FIELDS.has(key))) {
23
+ invalidInput("Capability project own fields must be exactly projectId and tools");
24
+ }
25
+ const readDataField = (field) => {
26
+ const descriptor = Object.getOwnPropertyDescriptor(value, field);
27
+ if (!descriptor?.enumerable || !("value" in descriptor)) {
28
+ invalidInput(`Capability project field ${field} must be an enumerable data property`);
29
+ }
30
+ return descriptor.value;
31
+ };
32
+ const projectId = readDataField("projectId");
33
+ const tools = readDataField("tools");
34
+ if (typeof projectId !== "string" || projectId.trim().length === 0) {
35
+ invalidInput("Capability projectId must be a non-empty string");
36
+ }
37
+ return {
38
+ projectId,
39
+ tools: tools,
40
+ };
41
+ }
42
+ function throwDiagnostic(diagnostic) {
43
+ const message = "message" in diagnostic
44
+ ? diagnostic.message
45
+ : `Skill scan failed with ${diagnostic.code}`;
46
+ throw Object.assign(new Error(message), diagnostic);
47
+ }
48
+ function freezeDiagnostic(diagnostic) {
49
+ if ("candidates" in diagnostic) {
50
+ const candidates = [...diagnostic.candidates];
51
+ Object.freeze(candidates);
52
+ return Object.freeze({
53
+ code: diagnostic.code,
54
+ severity: diagnostic.severity,
55
+ name: diagnostic.name,
56
+ ...(diagnostic.selected === undefined
57
+ ? {}
58
+ : { selected: diagnostic.selected }),
59
+ candidates,
60
+ });
61
+ }
62
+ return Object.freeze({
63
+ code: diagnostic.code,
64
+ severity: diagnostic.severity,
65
+ message: diagnostic.message,
66
+ skillFile: diagnostic.skillFile,
67
+ });
68
+ }
69
+ export async function buildViteCapabilitiesV1(input) {
70
+ const project = validateProject(input.project);
71
+ const toolManifest = buildToolManifestV1(project.tools);
72
+ const frontendBuildId = input.options?.frontendBuildId;
73
+ if (input.command === "build" &&
74
+ (frontendBuildId === undefined || frontendBuildId.trim().length === 0)) {
75
+ invalidInput("Production capability builds require frontendBuildId");
76
+ }
77
+ const mode = input.command === "build" ? "strict" : "compat";
78
+ const scan = await scanProjectSkills({
79
+ projectRoot: input.root,
80
+ mode,
81
+ skillRoots: input.options?.skillRoots,
82
+ });
83
+ const scanErrorDiagnostic = scan.diagnostics.find((diagnostic) => diagnostic.severity === "error");
84
+ if (scanErrorDiagnostic)
85
+ throwDiagnostic(scanErrorDiagnostic);
86
+ const loaded = await loadCanonicalSkillsV1({
87
+ projectRoot: input.root,
88
+ skills: scan.skills,
89
+ });
90
+ const loadedByName = new Map(loaded.skills.map((skill) => [skill.name, skill]));
91
+ const validation = await Promise.all(scan.skills.map(async (skill) => {
92
+ const loadedSkill = loadedByName.get(skill.name);
93
+ if (!loadedSkill) {
94
+ invalidInput(`Loaded Skill snapshot is missing ${skill.name}`);
95
+ }
96
+ const skillFile = loadedSkill.files.find((file) => file.relativePath === "SKILL.md");
97
+ if (!skillFile) {
98
+ invalidInput(`Loaded Skill ${skill.name} is missing SKILL.md`);
99
+ }
100
+ const files = new Map(loadedSkill.files.map((file) => [file.relativePath, file.bytes]));
101
+ return validateSkillContent({
102
+ skill,
103
+ markdown: Buffer.from(skillFile.bytes).toString("utf8"),
104
+ mode,
105
+ skillRoot: resolve(input.root, skill.directory),
106
+ async readReference(relativePath) {
107
+ const snapshotPath = relativePath.split(sep).join("/");
108
+ return files.get(snapshotPath);
109
+ },
110
+ });
111
+ }));
112
+ const diagnostics = [
113
+ ...scan.diagnostics,
114
+ ...validation.flatMap((result) => result.diagnostics),
115
+ ].map(freezeDiagnostic);
116
+ const errorDiagnostic = diagnostics.find((diagnostic) => diagnostic.severity === "error");
117
+ if (errorDiagnostic)
118
+ throwDiagnostic(errorDiagnostic);
119
+ const artifact = buildCapabilityArtifactV1({
120
+ skills: loaded.skills,
121
+ tools: toolManifest.manifest.tools,
122
+ });
123
+ const buildInfo = Object.freeze({
124
+ schemaVersion: "spotlight.capability-build-info/1",
125
+ projectId: project.projectId,
126
+ frontendBuildId: input.command === "build"
127
+ ? frontendBuildId
128
+ : `dev:${artifact.artifactDigest}`,
129
+ artifactVersion: artifact.artifactVersion,
130
+ artifactDigest: artifact.artifactDigest,
131
+ manifestDigest: artifact.manifestDigest,
132
+ toolManifestDigest: artifact.toolManifestDigest,
133
+ byteLength: artifact.byteLength,
134
+ });
135
+ return {
136
+ buildInfo,
137
+ archive: artifact.archive,
138
+ watchedFiles: Object.freeze([...loaded.watchedFiles]),
139
+ diagnostics: Object.freeze([...diagnostics]),
140
+ };
141
+ }
@@ -0,0 +1,29 @@
1
+ import type { FrontendToolDescriptorV1 } from "@inupedia/spotlight-protocol";
2
+ import type { SkillRootInput, SkillScanDiagnostic } from "../node/capabilities/skillScanner.js";
3
+ import type { AgentSkillDiagnostic } from "../node/capabilities/skillValidator.js";
4
+ export interface SpotlightCapabilityProjectBuildV1 {
5
+ projectId: string;
6
+ tools: readonly FrontendToolDescriptorV1[];
7
+ }
8
+ export interface SpotlightCapabilitiesOptionsV1 {
9
+ skillRoots?: readonly SkillRootInput[];
10
+ frontendBuildId?: string;
11
+ devRuntimeUpload?: boolean;
12
+ }
13
+ export interface CapabilityBuildInfoV1 {
14
+ schemaVersion: "spotlight.capability-build-info/1";
15
+ projectId: string;
16
+ frontendBuildId: string;
17
+ artifactVersion: "spotlight.capability-artifact/1";
18
+ artifactDigest: string;
19
+ manifestDigest: string;
20
+ toolManifestDigest: string;
21
+ byteLength: number;
22
+ }
23
+ export interface CapabilityPluginBuildResultV1 {
24
+ buildInfo: Readonly<CapabilityBuildInfoV1>;
25
+ archive: Uint8Array;
26
+ watchedFiles: readonly string[];
27
+ diagnostics: readonly (SkillScanDiagnostic | AgentSkillDiagnostic)[];
28
+ }
29
+ //# sourceMappingURL=capabilityBuildTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilityBuildTypes.d.ts","sourceRoot":"","sources":["../../src/vite/capabilityBuildTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAE7E,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAChG,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAEnF,MAAM,WAAW,iCAAiC;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,SAAS,wBAAwB,EAAE,CAAC;CAC5C;AAED,MAAM,WAAW,8BAA8B;IAC7C,UAAU,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;IACvC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,mCAAmC,CAAC;IACnD,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,iCAAiC,CAAC;IACnD,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,6BAA6B;IAC5C,SAAS,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;IAC3C,OAAO,EAAE,UAAU,CAAC;IACpB,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,WAAW,EAAE,SAAS,CAAC,mBAAmB,GAAG,oBAAoB,CAAC,EAAE,CAAC;CACtE"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { IncomingMessage, ServerResponse } from "node:http";
2
+ import type { CapabilityPluginBuildResultV1 } from "./capabilityBuildTypes.js";
3
+ export type CapabilityDevMiddlewareV1 = (request: IncomingMessage, response: ServerResponse, next: () => void) => void;
4
+ export declare function createCapabilityDevMiddlewareV1(currentResult: () => Readonly<CapabilityPluginBuildResultV1>): CapabilityDevMiddlewareV1;
5
+ //# sourceMappingURL=capabilityDevMiddleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilityDevMiddleware.d.ts","sourceRoot":"","sources":["../../src/vite/capabilityDevMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEjE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAK/E,MAAM,MAAM,yBAAyB,GAAG,CACtC,OAAO,EAAE,eAAe,EACxB,QAAQ,EAAE,cAAc,EACxB,IAAI,EAAE,MAAM,IAAI,KACb,IAAI,CAAC;AAEV,wBAAgB,+BAA+B,CAC7C,aAAa,EAAE,MAAM,QAAQ,CAAC,6BAA6B,CAAC,GAC3D,yBAAyB,CAgD3B"}
@@ -0,0 +1,40 @@
1
+ const ROUTE_PREFIX = "/@spotlight/capability-artifacts/";
2
+ const DIGEST_PATTERN = /^sha256:[a-f0-9]{64}$/;
3
+ export function createCapabilityDevMiddlewareV1(currentResult) {
4
+ return (request, response, next) => {
5
+ const url = request.url ?? "";
6
+ if (!url.startsWith(ROUTE_PREFIX)) {
7
+ next();
8
+ return;
9
+ }
10
+ const requestedDigest = url.slice(ROUTE_PREFIX.length);
11
+ if (!DIGEST_PATTERN.test(requestedDigest)) {
12
+ response.statusCode = 404;
13
+ response.end();
14
+ return;
15
+ }
16
+ const method = request.method ?? "GET";
17
+ if (method !== "GET" && method !== "HEAD") {
18
+ response.statusCode = 405;
19
+ response.setHeader("Allow", "GET, HEAD");
20
+ response.end();
21
+ return;
22
+ }
23
+ const result = currentResult();
24
+ if (requestedDigest !== result.buildInfo.artifactDigest) {
25
+ response.statusCode = 404;
26
+ response.end();
27
+ return;
28
+ }
29
+ response.statusCode = 200;
30
+ response.setHeader("Content-Type", "application/gzip");
31
+ response.setHeader("Content-Length", String(result.archive.byteLength));
32
+ response.setHeader("Cache-Control", "no-store");
33
+ response.setHeader("X-Content-Type-Options", "nosniff");
34
+ if (method === "HEAD") {
35
+ response.end();
36
+ return;
37
+ }
38
+ response.end(Buffer.from(result.archive.buffer, result.archive.byteOffset, result.archive.byteLength));
39
+ };
40
+ }
@@ -0,0 +1,11 @@
1
+ import type { CapabilityBuildInfoV1 } from "./capabilityBuildTypes.js";
2
+ export declare const SPOTLIGHT_CAPABILITIES_MODULE_ID: "virtual:spotlight/capabilities";
3
+ export declare const RESOLVED_SPOTLIGHT_CAPABILITIES_MODULE_ID: "\0virtual:spotlight/capabilities";
4
+ export interface CapabilityVirtualModuleV1 {
5
+ canonicalBuildInfoJson: string;
6
+ source: string;
7
+ }
8
+ export declare function buildCapabilityVirtualModuleV1(buildInfo: Readonly<CapabilityBuildInfoV1>, options?: Readonly<{
9
+ runtimeUpload?: boolean;
10
+ }>): Readonly<CapabilityVirtualModuleV1>;
11
+ //# sourceMappingURL=capabilityVirtualModule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilityVirtualModule.d.ts","sourceRoot":"","sources":["../../src/vite/capabilityVirtualModule.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAEvE,eAAO,MAAM,gCAAgC,EAC3C,gCAAyC,CAAC;AAC5C,eAAO,MAAM,yCAAyC,EACpD,kCAA2C,CAAC;AAE9C,MAAM,WAAW,yBAAyB;IACxC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC;CAChB;AAyCD,wBAAgB,8BAA8B,CAC5C,SAAS,EAAE,QAAQ,CAAC,qBAAqB,CAAC,EAC1C,OAAO,GAAE,QAAQ,CAAC;IAAE,aAAa,CAAC,EAAE,OAAO,CAAA;CAAE,CAAM,GAClD,QAAQ,CAAC,yBAAyB,CAAC,CAQrC"}
@@ -0,0 +1,43 @@
1
+ import { canonicalizeJson } from "../node/capabilities/canonicalJson.js";
2
+ export const SPOTLIGHT_CAPABILITIES_MODULE_ID = "virtual:spotlight/capabilities";
3
+ export const RESOLVED_SPOTLIGHT_CAPABILITIES_MODULE_ID = "\0virtual:spotlight/capabilities";
4
+ function disabledProviderSource() {
5
+ return `export async function openUploadStream() {
6
+ const error = new Error("Runtime capability Artifact upload is disabled.");
7
+ Object.defineProperty(error, "code", {
8
+ value: "ARTIFACT_RUNTIME_UPLOAD_DISABLED",
9
+ enumerable: true,
10
+ });
11
+ throw error;
12
+ }`;
13
+ }
14
+ function developmentProviderSource(buildInfo) {
15
+ const digest = JSON.stringify(buildInfo.artifactDigest);
16
+ const path = JSON.stringify(`/@spotlight/capability-artifacts/${buildInfo.artifactDigest}`);
17
+ return `export async function openUploadStream() {
18
+ const response = await fetch(${path}, {
19
+ method: "GET",
20
+ cache: "no-store",
21
+ credentials: "same-origin",
22
+ });
23
+ if (!response.ok) {
24
+ throw new Error("Unable to open capability Artifact stream.");
25
+ }
26
+ if (response.body == null) {
27
+ throw new Error("Capability Artifact response has no stream body.");
28
+ }
29
+ return {
30
+ digest: ${digest},
31
+ byteLength: capabilityBuildInfo.byteLength,
32
+ contentType: "application/gzip",
33
+ stream: response.body,
34
+ };
35
+ }`;
36
+ }
37
+ export function buildCapabilityVirtualModuleV1(buildInfo, options = {}) {
38
+ const canonicalBuildInfoJson = new TextDecoder().decode(canonicalizeJson(buildInfo));
39
+ return Object.freeze({
40
+ canonicalBuildInfoJson,
41
+ source: `export const capabilityBuildInfo = Object.freeze(${canonicalBuildInfoJson});\n\n${options.runtimeUpload === true ? developmentProviderSource(buildInfo) : disabledProviderSource()}\n`,
42
+ });
43
+ }
@@ -0,0 +1,12 @@
1
+ declare module "virtual:spotlight/capabilities" {
2
+ import type { CapabilityBuildInfoV1 } from "@inupedia/spotlight-client/vite";
3
+ interface ArtifactUploadStreamV1 {
4
+ digest: string;
5
+ byteLength: number;
6
+ contentType: "application/gzip";
7
+ stream: ReadableStream<Uint8Array>;
8
+ }
9
+ const capabilityBuildInfo: Readonly<CapabilityBuildInfoV1>;
10
+ function openUploadStream(): Promise<ArtifactUploadStreamV1>;
11
+ }
12
+ //# sourceMappingURL=capabilityVirtualModuleTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilityVirtualModuleTypes.d.ts","sourceRoot":"","sources":["../../src/vite/capabilityVirtualModuleTypes.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,gCAAgC,CAAC;IAC9C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;IAE7E,UAAiB,sBAAsB;QACrC,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,kBAAkB,CAAC;QAChC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;KACpC;IAEM,MAAM,mBAAmB,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;IAElE,SAAgB,gBAAgB,IAAI,OAAO,CAAC,sBAAsB,CAAC,CAAC;CACrE"}
@@ -0,0 +1 @@
1
+ "use strict";
@@ -1,4 +1,8 @@
1
1
  import type { SpotlightAgentIocOptions } from "./spotlightAgentIoc.js";
2
+ import "./capabilityVirtualModuleTypes.js";
2
3
  export type { SpotlightAgentIocOptions };
4
+ export { spotlightCapabilities } from "./spotlightCapabilities.js";
5
+ export type { CapabilityBuildInfoV1, CapabilityPluginBuildResultV1, SpotlightCapabilitiesOptionsV1, SpotlightCapabilityProjectBuildV1, } from "./capabilityBuildTypes.js";
6
+ export { RESOLVED_SPOTLIGHT_CAPABILITIES_MODULE_ID, SPOTLIGHT_CAPABILITIES_MODULE_ID, } from "./capabilityVirtualModule.js";
3
7
  export { transformSpotlightAgentIoc, default, } from "./spotlightAgentIoc.js";
4
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vite/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAEvE,YAAY,EAAE,wBAAwB,EAAE,CAAC;AAEzC,OAAO,EACL,0BAA0B,EAC1B,OAAO,GACR,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vite/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAEvE,OAAO,mCAAmC,CAAC;AAE3C,YAAY,EAAE,wBAAwB,EAAE,CAAC;AAEzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,YAAY,EACV,qBAAqB,EACrB,6BAA6B,EAC7B,8BAA8B,EAC9B,iCAAiC,GAClC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,yCAAyC,EACzC,gCAAgC,GACjC,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,0BAA0B,EAC1B,OAAO,GACR,MAAM,wBAAwB,CAAC"}
@@ -1 +1,4 @@
1
+ import "./capabilityVirtualModuleTypes.js";
2
+ export { spotlightCapabilities } from "./spotlightCapabilities.js";
3
+ export { RESOLVED_SPOTLIGHT_CAPABILITIES_MODULE_ID, SPOTLIGHT_CAPABILITIES_MODULE_ID, } from "./capabilityVirtualModule.js";
1
4
  export { transformSpotlightAgentIoc, default, } from "./spotlightAgentIoc.js";
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from "vite";
2
+ import { type SpotlightCapabilitiesOptionsV1, type SpotlightCapabilityProjectBuildV1 } from "./capabilityBuild.js";
3
+ export declare function spotlightCapabilities(project: SpotlightCapabilityProjectBuildV1, options?: SpotlightCapabilitiesOptionsV1): Plugin;
4
+ //# sourceMappingURL=spotlightCapabilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spotlightCapabilities.d.ts","sourceRoot":"","sources":["../../src/vite/spotlightCapabilities.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAiC,MAAM,MAAM,CAAC;AAKlE,OAAO,EAGL,KAAK,8BAA8B,EACnC,KAAK,iCAAiC,EACvC,MAAM,sBAAsB,CAAC;AAuB9B,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,iCAAiC,EAC1C,OAAO,CAAC,EAAE,8BAA8B,GACvC,MAAM,CAoKR"}
@@ -0,0 +1,165 @@
1
+ import { isAbsolute, relative, resolve, sep } from "node:path";
2
+ import { DEFAULT_SKILL_ROOTS } from "../node/index.js";
3
+ import { createCapabilityDevMiddlewareV1 } from "./capabilityDevMiddleware.js";
4
+ import { buildViteCapabilitiesV1, } from "./capabilityBuild.js";
5
+ import { buildCapabilityVirtualModuleV1, RESOLVED_SPOTLIGHT_CAPABILITIES_MODULE_ID, SPOTLIGHT_CAPABILITIES_MODULE_ID, } from "./capabilityVirtualModule.js";
6
+ function isAtOrBelow(candidate, directory) {
7
+ const relativePath = relative(directory, candidate);
8
+ return (relativePath === "" ||
9
+ (!relativePath.startsWith(`..${sep}`) &&
10
+ relativePath !== ".." &&
11
+ !isAbsolute(relativePath)));
12
+ }
13
+ export function spotlightCapabilities(project, options) {
14
+ let root;
15
+ let command;
16
+ let state;
17
+ let server;
18
+ let rebuildChain = Promise.resolve();
19
+ let relevantRoots = [];
20
+ let removeServerListeners;
21
+ let finishInitialization;
22
+ const initialization = new Promise((resolveInitialization) => {
23
+ finishInitialization = resolveInitialization;
24
+ });
25
+ const currentState = () => {
26
+ if (state === undefined) {
27
+ throw new Error("Spotlight capabilities were not built.");
28
+ }
29
+ return state;
30
+ };
31
+ const createState = (result) => Object.freeze({
32
+ result: Object.freeze(result),
33
+ virtualModule: buildCapabilityVirtualModuleV1(result.buildInfo, {
34
+ runtimeUpload: command === "serve" && options?.devRuntimeUpload !== false,
35
+ }),
36
+ });
37
+ const isRelevantFile = (file) => {
38
+ const absoluteFile = resolve(file);
39
+ const current = state;
40
+ return (current?.result.watchedFiles.some((watchedFile) => resolve(watchedFile) === absoluteFile) === true ||
41
+ relevantRoots.some((skillRoot) => isAtOrBelow(absoluteFile, skillRoot)));
42
+ };
43
+ const enqueueRebuild = (file) => {
44
+ if (command !== "serve" || root === undefined || !isRelevantFile(file)) {
45
+ return Promise.resolve();
46
+ }
47
+ const projectRoot = root;
48
+ const task = rebuildChain.then(async () => {
49
+ await initialization;
50
+ if (state === undefined)
51
+ return;
52
+ try {
53
+ const result = await buildViteCapabilitiesV1({
54
+ root: projectRoot,
55
+ command: "serve",
56
+ project,
57
+ options,
58
+ });
59
+ const nextState = createState(result);
60
+ server?.watcher.add([...result.watchedFiles]);
61
+ const moduleNode = server?.moduleGraph.getModuleById(RESOLVED_SPOTLIGHT_CAPABILITIES_MODULE_ID);
62
+ const previousState = state;
63
+ state = nextState;
64
+ try {
65
+ if (moduleNode !== undefined) {
66
+ server?.moduleGraph.invalidateModule(moduleNode);
67
+ }
68
+ }
69
+ catch (error) {
70
+ state = previousState;
71
+ throw error;
72
+ }
73
+ }
74
+ catch {
75
+ try {
76
+ server?.config.logger.error("[CAPABILITY_DEV_REBUILD_FAILED] Capability development rebuild failed.");
77
+ }
78
+ catch {
79
+ // A development logger failure must not poison later rebuilds.
80
+ }
81
+ }
82
+ });
83
+ rebuildChain = task.catch(() => undefined);
84
+ return task;
85
+ };
86
+ return {
87
+ name: "spotlight-capabilities",
88
+ configResolved(config) {
89
+ root = config.root;
90
+ command = config.command;
91
+ const roots = options?.skillRoots ?? DEFAULT_SKILL_ROOTS;
92
+ relevantRoots = Object.freeze(roots.map((entry) => {
93
+ const path = typeof entry === "string" ? entry : entry.path;
94
+ return resolve(config.root, path);
95
+ }));
96
+ },
97
+ async buildStart() {
98
+ if (root === undefined || command === undefined) {
99
+ throw new Error("Spotlight capabilities require resolved Vite config.");
100
+ }
101
+ try {
102
+ const result = await buildViteCapabilitiesV1({
103
+ root,
104
+ command,
105
+ project,
106
+ options,
107
+ });
108
+ state = createState(result);
109
+ for (const file of result.watchedFiles)
110
+ this.addWatchFile(file);
111
+ }
112
+ finally {
113
+ finishInitialization();
114
+ }
115
+ },
116
+ configureServer(viteServer) {
117
+ removeServerListeners?.();
118
+ server = viteServer;
119
+ viteServer.watcher.add([...relevantRoots]);
120
+ const add = (file) => enqueueRebuild(file);
121
+ const change = (file) => enqueueRebuild(file);
122
+ const unlink = (file) => enqueueRebuild(file);
123
+ viteServer.watcher.on("add", add);
124
+ viteServer.watcher.on("change", change);
125
+ viteServer.watcher.on("unlink", unlink);
126
+ const cleanup = () => {
127
+ viteServer.watcher.off("add", add);
128
+ viteServer.watcher.off("change", change);
129
+ viteServer.watcher.off("unlink", unlink);
130
+ viteServer.httpServer?.off("close", cleanup);
131
+ if (removeServerListeners === cleanup) {
132
+ removeServerListeners = undefined;
133
+ }
134
+ };
135
+ removeServerListeners = cleanup;
136
+ viteServer.httpServer?.once("close", cleanup);
137
+ if (options?.devRuntimeUpload === false)
138
+ return;
139
+ viteServer.middlewares.use(createCapabilityDevMiddlewareV1(() => currentState().result));
140
+ },
141
+ resolveId(id) {
142
+ return id === SPOTLIGHT_CAPABILITIES_MODULE_ID
143
+ ? RESOLVED_SPOTLIGHT_CAPABILITIES_MODULE_ID
144
+ : null;
145
+ },
146
+ load(id) {
147
+ if (id !== RESOLVED_SPOTLIGHT_CAPABILITIES_MODULE_ID)
148
+ return null;
149
+ return currentState().virtualModule.source;
150
+ },
151
+ closeBundle() {
152
+ removeServerListeners?.();
153
+ },
154
+ generateBundle() {
155
+ if (command !== "build")
156
+ return;
157
+ const current = currentState();
158
+ this.emitFile({
159
+ type: "asset",
160
+ fileName: "capability-build-info.json",
161
+ source: `${current.virtualModule.canonicalBuildInfoJson}\n`,
162
+ });
163
+ },
164
+ };
165
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inupedia/spotlight-client",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
4
4
  "description": "HTTP/SSE helpers and host tool bridge for Inupedia Spotlight (monorepo workspace package)",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -11,8 +11,8 @@
11
11
  "import": "./dist/index.js"
12
12
  },
13
13
  "./vite": {
14
- "types": "./dist/vite/spotlightAgentIoc.d.ts",
15
- "import": "./dist/vite/spotlightAgentIoc.js"
14
+ "types": "./dist/vite/index.d.ts",
15
+ "import": "./dist/vite/index.js"
16
16
  },
17
17
  "./node": {
18
18
  "types": "./dist/node/index.d.ts",
@@ -43,7 +43,7 @@
43
43
  "fflate": "0.8.3",
44
44
  "magic-string": "^0.30.21",
45
45
  "yaml": "^2.8.4",
46
- "@inupedia/spotlight-protocol": "0.2.13"
46
+ "@inupedia/spotlight-protocol": "0.2.14"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"