@inupedia/spotlight-client 0.2.14 → 0.2.15
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/dist/node/capabilities/skillFileValidator.d.ts +0 -8
- package/dist/node/capabilities/skillFileValidator.d.ts.map +1 -1
- package/dist/node/capabilities/skillFileValidator.js +26 -46
- package/dist/node/index.d.ts +0 -7
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +0 -6
- package/dist/vite/index.d.ts +0 -4
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +0 -3
- package/package.json +6 -8
- package/dist/node/capabilities/canonicalJson.d.ts +0 -7
- package/dist/node/capabilities/canonicalJson.d.ts.map +0 -1
- package/dist/node/capabilities/canonicalJson.js +0 -122
- package/dist/node/capabilities/capabilityArtifact.d.ts +0 -13
- package/dist/node/capabilities/capabilityArtifact.d.ts.map +0 -1
- package/dist/node/capabilities/capabilityArtifact.js +0 -31
- package/dist/node/capabilities/capabilityArtifactError.d.ts +0 -7
- package/dist/node/capabilities/capabilityArtifactError.d.ts.map +0 -1
- package/dist/node/capabilities/capabilityArtifactError.js +0 -19
- package/dist/node/capabilities/capabilityArtifactTypes.d.ts +0 -32
- package/dist/node/capabilities/capabilityArtifactTypes.d.ts.map +0 -1
- package/dist/node/capabilities/capabilityArtifactTypes.js +0 -1
- package/dist/node/capabilities/capabilityFileMap.d.ts +0 -17
- package/dist/node/capabilities/capabilityFileMap.d.ts.map +0 -1
- package/dist/node/capabilities/capabilityFileMap.js +0 -235
- package/dist/node/capabilities/deterministicGzip.d.ts +0 -2
- package/dist/node/capabilities/deterministicGzip.d.ts.map +0 -1
- package/dist/node/capabilities/deterministicGzip.js +0 -51
- package/dist/node/capabilities/deterministicTar.d.ts +0 -6
- package/dist/node/capabilities/deterministicTar.d.ts.map +0 -1
- package/dist/node/capabilities/deterministicTar.js +0 -137
- package/dist/node/capabilities/skillDirectoryLoader.d.ts +0 -24
- package/dist/node/capabilities/skillDirectoryLoader.d.ts.map +0 -1
- package/dist/node/capabilities/skillDirectoryLoader.js +0 -308
- package/dist/node/capabilities/toolManifest.d.ts +0 -12
- package/dist/node/capabilities/toolManifest.d.ts.map +0 -1
- package/dist/node/capabilities/toolManifest.js +0 -111
- package/dist/vite/capabilityBuild.d.ts +0 -9
- package/dist/vite/capabilityBuild.d.ts.map +0 -1
- package/dist/vite/capabilityBuild.js +0 -141
- package/dist/vite/capabilityBuildTypes.d.ts +0 -29
- package/dist/vite/capabilityBuildTypes.d.ts.map +0 -1
- package/dist/vite/capabilityBuildTypes.js +0 -1
- package/dist/vite/capabilityDevMiddleware.d.ts +0 -5
- package/dist/vite/capabilityDevMiddleware.d.ts.map +0 -1
- package/dist/vite/capabilityDevMiddleware.js +0 -40
- package/dist/vite/capabilityVirtualModule.d.ts +0 -11
- package/dist/vite/capabilityVirtualModule.d.ts.map +0 -1
- package/dist/vite/capabilityVirtualModule.js +0 -43
- package/dist/vite/capabilityVirtualModuleTypes.d.ts +0 -12
- package/dist/vite/capabilityVirtualModuleTypes.d.ts.map +0 -1
- package/dist/vite/capabilityVirtualModuleTypes.js +0 -1
- package/dist/vite/spotlightCapabilities.d.ts +0 -4
- package/dist/vite/spotlightCapabilities.d.ts.map +0 -1
- package/dist/vite/spotlightCapabilities.js +0 -165
|
@@ -1,308 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { FrontendToolDescriptorV1 } from "@inupedia/spotlight-protocol";
|
|
2
|
-
export interface ToolManifestV1 {
|
|
3
|
-
schemaVersion: "spotlight.tool-manifest/1";
|
|
4
|
-
tools: FrontendToolDescriptorV1[];
|
|
5
|
-
}
|
|
6
|
-
export interface BuiltToolManifestV1 {
|
|
7
|
-
manifest: ToolManifestV1;
|
|
8
|
-
bytes: Uint8Array;
|
|
9
|
-
digest: string;
|
|
10
|
-
}
|
|
11
|
-
export declare function buildToolManifestV1(tools: FrontendToolDescriptorV1[]): BuiltToolManifestV1;
|
|
12
|
-
//# sourceMappingURL=toolManifest.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toolManifest.d.ts","sourceRoot":"","sources":["../../../src/node/capabilities/toolManifest.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAK7E,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,2BAA2B,CAAC;IAC3C,KAAK,EAAE,wBAAwB,EAAE,CAAC;CACnC;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,cAAc,CAAC;IACzB,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB;AAwGD,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,wBAAwB,EAAE,GAChC,mBAAmB,CAkCrB"}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { isProxy } from "node:util/types";
|
|
3
|
-
import { canonicalizeJson, compareUtf16 } from "./canonicalJson.js";
|
|
4
|
-
import { CapabilityArtifactError } from "./capabilityArtifactError.js";
|
|
5
|
-
const TOOL_FIELDS = new Set([
|
|
6
|
-
"name",
|
|
7
|
-
"version",
|
|
8
|
-
"description",
|
|
9
|
-
"inputSchema",
|
|
10
|
-
"outputSchema",
|
|
11
|
-
"maxOutputBytes",
|
|
12
|
-
"sideEffect",
|
|
13
|
-
"replayPolicy",
|
|
14
|
-
"riskLevel",
|
|
15
|
-
"requiresConfirmation",
|
|
16
|
-
]);
|
|
17
|
-
const SIDE_EFFECTS = new Set(["none", "ui", "external"]);
|
|
18
|
-
const REPLAY_POLICIES = new Set(["safe", "idempotency-key", "never"]);
|
|
19
|
-
const RISK_LEVELS = new Set(["low", "medium", "high"]);
|
|
20
|
-
function sha256(bytes) {
|
|
21
|
-
return `sha256:${createHash("sha256").update(bytes).digest("hex")}`;
|
|
22
|
-
}
|
|
23
|
-
function compareTools(left, right) {
|
|
24
|
-
return compareUtf16(left.name, right.name) || compareUtf16(left.version, right.version);
|
|
25
|
-
}
|
|
26
|
-
function invalidTool(message) {
|
|
27
|
-
throw new CapabilityArtifactError("ARTIFACT_TOOL_INVALID", message);
|
|
28
|
-
}
|
|
29
|
-
function isPlainObject(value) {
|
|
30
|
-
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
const prototype = Object.getPrototypeOf(value);
|
|
34
|
-
return prototype === Object.prototype || prototype === null;
|
|
35
|
-
}
|
|
36
|
-
function validateToolDescriptor(value) {
|
|
37
|
-
canonicalizeJson(value);
|
|
38
|
-
if (!isPlainObject(value)) {
|
|
39
|
-
invalidTool("Tool descriptor must be a plain JSON object");
|
|
40
|
-
}
|
|
41
|
-
const unknownFields = Object.keys(value)
|
|
42
|
-
.filter((field) => !TOOL_FIELDS.has(field))
|
|
43
|
-
.sort(compareUtf16);
|
|
44
|
-
if (unknownFields.length > 0) {
|
|
45
|
-
invalidTool(`Unknown Tool descriptor fields: ${unknownFields.join(", ")}`);
|
|
46
|
-
}
|
|
47
|
-
const tool = value;
|
|
48
|
-
if (typeof tool.name !== "string" || tool.name.trim().length === 0) {
|
|
49
|
-
invalidTool("Tool name must be a non-empty string");
|
|
50
|
-
}
|
|
51
|
-
if (typeof tool.version !== "string" || tool.version.trim().length === 0) {
|
|
52
|
-
invalidTool(`Tool ${tool.name} version must be a non-empty string`);
|
|
53
|
-
}
|
|
54
|
-
if (typeof tool.description !== "string" ||
|
|
55
|
-
tool.description.trim().length === 0) {
|
|
56
|
-
invalidTool(`Tool ${tool.name} description must be a non-empty string`);
|
|
57
|
-
}
|
|
58
|
-
if (!isPlainObject(tool.inputSchema)) {
|
|
59
|
-
invalidTool(`Tool ${tool.name} inputSchema must be a JSON object`);
|
|
60
|
-
}
|
|
61
|
-
if (tool.outputSchema !== undefined && !isPlainObject(tool.outputSchema)) {
|
|
62
|
-
invalidTool(`Tool ${tool.name} outputSchema must be a JSON object`);
|
|
63
|
-
}
|
|
64
|
-
if (tool.maxOutputBytes !== undefined &&
|
|
65
|
-
(!Number.isSafeInteger(tool.maxOutputBytes) || tool.maxOutputBytes <= 0)) {
|
|
66
|
-
invalidTool(`Tool ${tool.name} maxOutputBytes must be a positive safe integer`);
|
|
67
|
-
}
|
|
68
|
-
if (typeof tool.sideEffect !== "string" || !SIDE_EFFECTS.has(tool.sideEffect)) {
|
|
69
|
-
invalidTool(`Tool ${tool.name} has an invalid sideEffect`);
|
|
70
|
-
}
|
|
71
|
-
if (typeof tool.replayPolicy !== "string" ||
|
|
72
|
-
!REPLAY_POLICIES.has(tool.replayPolicy)) {
|
|
73
|
-
invalidTool(`Tool ${tool.name} has an invalid replayPolicy`);
|
|
74
|
-
}
|
|
75
|
-
if (tool.riskLevel !== undefined &&
|
|
76
|
-
(typeof tool.riskLevel !== "string" || !RISK_LEVELS.has(tool.riskLevel))) {
|
|
77
|
-
invalidTool(`Tool ${tool.name} has an invalid riskLevel`);
|
|
78
|
-
}
|
|
79
|
-
if (tool.requiresConfirmation !== undefined &&
|
|
80
|
-
typeof tool.requiresConfirmation !== "boolean") {
|
|
81
|
-
invalidTool(`Tool ${tool.name} requiresConfirmation must be boolean`);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
export function buildToolManifestV1(tools) {
|
|
85
|
-
if (isProxy(tools) || !Array.isArray(tools)) {
|
|
86
|
-
invalidTool("Tool collection must be an array");
|
|
87
|
-
}
|
|
88
|
-
canonicalizeJson(tools);
|
|
89
|
-
for (const tool of tools)
|
|
90
|
-
validateToolDescriptor(tool);
|
|
91
|
-
const sortedTools = [...tools].sort(compareTools);
|
|
92
|
-
for (let index = 1; index < sortedTools.length; index += 1) {
|
|
93
|
-
const previous = sortedTools[index - 1];
|
|
94
|
-
const current = sortedTools[index];
|
|
95
|
-
if (previous?.name === current?.name &&
|
|
96
|
-
previous.version === current.version) {
|
|
97
|
-
throw new CapabilityArtifactError("ARTIFACT_TOOL_DUPLICATE", `Duplicate Tool identity: ${current.name}@${current.version}`);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
const candidate = {
|
|
101
|
-
schemaVersion: "spotlight.tool-manifest/1",
|
|
102
|
-
tools: sortedTools,
|
|
103
|
-
};
|
|
104
|
-
const bytes = canonicalizeJson(candidate);
|
|
105
|
-
const manifest = JSON.parse(new TextDecoder().decode(bytes));
|
|
106
|
-
return {
|
|
107
|
-
manifest,
|
|
108
|
-
bytes,
|
|
109
|
-
digest: sha256(bytes),
|
|
110
|
-
};
|
|
111
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,141 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,5 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|