@inupedia/spotlight-client 0.3.6 → 0.4.1

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 (111) hide show
  1. package/README.md +14 -123
  2. package/dist/clientTool.d.ts +42 -0
  3. package/dist/clientTool.d.ts.map +1 -0
  4. package/dist/clientTool.js +181 -0
  5. package/dist/index.d.ts +2 -19
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +2 -18
  8. package/dist/node/capabilities/skillFileValidator.d.ts +0 -8
  9. package/dist/node/capabilities/skillFileValidator.d.ts.map +1 -1
  10. package/dist/node/capabilities/skillFileValidator.js +26 -46
  11. package/dist/node/index.d.ts +0 -10
  12. package/dist/node/index.d.ts.map +1 -1
  13. package/dist/node/index.js +0 -9
  14. package/dist/vite/index.d.ts +1 -7
  15. package/dist/vite/index.d.ts.map +1 -1
  16. package/dist/vite/index.js +1 -4
  17. package/dist/vite/spotlightClientTools.d.ts +27 -0
  18. package/dist/vite/spotlightClientTools.d.ts.map +1 -0
  19. package/dist/vite/spotlightClientTools.js +424 -0
  20. package/package.json +6 -20
  21. package/dist/capabilities/channel.d.ts +0 -28
  22. package/dist/capabilities/channel.d.ts.map +0 -1
  23. package/dist/capabilities/channel.js +0 -194
  24. package/dist/capabilities/errors.d.ts +0 -9
  25. package/dist/capabilities/errors.d.ts.map +0 -1
  26. package/dist/capabilities/errors.js +0 -19
  27. package/dist/capabilities/handshake.d.ts +0 -38
  28. package/dist/capabilities/handshake.d.ts.map +0 -1
  29. package/dist/capabilities/handshake.js +0 -139
  30. package/dist/capabilities/hostActionExecutor.d.ts +0 -22
  31. package/dist/capabilities/hostActionExecutor.d.ts.map +0 -1
  32. package/dist/capabilities/hostActionExecutor.js +0 -56
  33. package/dist/capabilities/jsonSchema.d.ts +0 -2
  34. package/dist/capabilities/jsonSchema.d.ts.map +0 -1
  35. package/dist/capabilities/jsonSchema.js +0 -73
  36. package/dist/capabilities/runtimeCapabilities.d.ts +0 -25
  37. package/dist/capabilities/runtimeCapabilities.d.ts.map +0 -1
  38. package/dist/capabilities/runtimeCapabilities.js +0 -53
  39. package/dist/node/capabilities/archivePath.d.ts +0 -4
  40. package/dist/node/capabilities/archivePath.d.ts.map +0 -1
  41. package/dist/node/capabilities/archivePath.js +0 -22
  42. package/dist/node/capabilities/canonicalJson.d.ts +0 -7
  43. package/dist/node/capabilities/canonicalJson.d.ts.map +0 -1
  44. package/dist/node/capabilities/canonicalJson.js +0 -122
  45. package/dist/node/capabilities/capabilityArtifact.d.ts +0 -15
  46. package/dist/node/capabilities/capabilityArtifact.d.ts.map +0 -1
  47. package/dist/node/capabilities/capabilityArtifact.js +0 -37
  48. package/dist/node/capabilities/capabilityArtifactError.d.ts +0 -7
  49. package/dist/node/capabilities/capabilityArtifactError.d.ts.map +0 -1
  50. package/dist/node/capabilities/capabilityArtifactError.js +0 -19
  51. package/dist/node/capabilities/capabilityArtifactTypes.d.ts +0 -32
  52. package/dist/node/capabilities/capabilityArtifactTypes.d.ts.map +0 -1
  53. package/dist/node/capabilities/capabilityArtifactTypes.js +0 -1
  54. package/dist/node/capabilities/capabilityFileMap.d.ts +0 -19
  55. package/dist/node/capabilities/capabilityFileMap.d.ts.map +0 -1
  56. package/dist/node/capabilities/capabilityFileMap.js +0 -234
  57. package/dist/node/capabilities/deterministicGzip.d.ts +0 -2
  58. package/dist/node/capabilities/deterministicGzip.d.ts.map +0 -1
  59. package/dist/node/capabilities/deterministicGzip.js +0 -51
  60. package/dist/node/capabilities/deterministicTar.d.ts +0 -6
  61. package/dist/node/capabilities/deterministicTar.d.ts.map +0 -1
  62. package/dist/node/capabilities/deterministicTar.js +0 -128
  63. package/dist/node/capabilities/skillDirectoryLoader.d.ts +0 -24
  64. package/dist/node/capabilities/skillDirectoryLoader.d.ts.map +0 -1
  65. package/dist/node/capabilities/skillDirectoryLoader.js +0 -308
  66. package/dist/node/capabilities/skillManifest.d.ts +0 -16
  67. package/dist/node/capabilities/skillManifest.d.ts.map +0 -1
  68. package/dist/node/capabilities/skillManifest.js +0 -22
  69. package/dist/node/capabilities/toolManifest.d.ts +0 -12
  70. package/dist/node/capabilities/toolManifest.d.ts.map +0 -1
  71. package/dist/node/capabilities/toolManifest.js +0 -111
  72. package/dist/node/capabilityPublishCli.d.ts +0 -2
  73. package/dist/node/capabilityPublishCli.d.ts.map +0 -1
  74. package/dist/node/capabilityPublishCli.js +0 -115
  75. package/dist/node/cli/spotlightCapabilitiesPublish.d.ts +0 -3
  76. package/dist/node/cli/spotlightCapabilitiesPublish.d.ts.map +0 -1
  77. package/dist/node/cli/spotlightCapabilitiesPublish.js +0 -3
  78. package/dist/node/publishCapabilitiesCli.d.ts +0 -3
  79. package/dist/node/publishCapabilitiesCli.d.ts.map +0 -1
  80. package/dist/node/publishCapabilitiesCli.js +0 -36
  81. package/dist/node/publishCapabilityArtifact.d.ts +0 -12
  82. package/dist/node/publishCapabilityArtifact.d.ts.map +0 -1
  83. package/dist/node/publishCapabilityArtifact.js +0 -25
  84. package/dist/runtimeId.d.ts +0 -3
  85. package/dist/runtimeId.d.ts.map +0 -1
  86. package/dist/runtimeId.js +0 -29
  87. package/dist/tools/frontendTool.d.ts +0 -39
  88. package/dist/tools/frontendTool.d.ts.map +0 -1
  89. package/dist/tools/frontendTool.js +0 -51
  90. package/dist/vite/capabilityBuild.d.ts +0 -9
  91. package/dist/vite/capabilityBuild.d.ts.map +0 -1
  92. package/dist/vite/capabilityBuild.js +0 -169
  93. package/dist/vite/capabilityBuildTypes.d.ts +0 -32
  94. package/dist/vite/capabilityBuildTypes.d.ts.map +0 -1
  95. package/dist/vite/capabilityBuildTypes.js +0 -1
  96. package/dist/vite/capabilityDevMiddleware.d.ts +0 -5
  97. package/dist/vite/capabilityDevMiddleware.d.ts.map +0 -1
  98. package/dist/vite/capabilityDevMiddleware.js +0 -42
  99. package/dist/vite/capabilityVirtualModule.d.ts +0 -11
  100. package/dist/vite/capabilityVirtualModule.d.ts.map +0 -1
  101. package/dist/vite/capabilityVirtualModule.js +0 -60
  102. package/dist/vite/capabilityVirtualModuleTypes.d.ts +0 -12
  103. package/dist/vite/capabilityVirtualModuleTypes.d.ts.map +0 -1
  104. package/dist/vite/capabilityVirtualModuleTypes.js +0 -1
  105. package/dist/vite/spotlightAgentIoc.d.ts +0 -11
  106. package/dist/vite/spotlightAgentIoc.d.ts.map +0 -1
  107. package/dist/vite/spotlightAgentIoc.js +0 -331
  108. package/dist/vite/spotlightCapabilities.d.ts +0 -4
  109. package/dist/vite/spotlightCapabilities.d.ts.map +0 -1
  110. package/dist/vite/spotlightCapabilities.js +0 -187
  111. package/src/agentDecorator.d.ts +0 -17
@@ -1,51 +0,0 @@
1
- import { deflateSync } from "fflate";
2
- import { CapabilityArtifactError } from "./capabilityArtifactError.js";
3
- const GZIP_HEADER = Uint8Array.from([
4
- 0x1f,
5
- 0x8b,
6
- 8,
7
- 0,
8
- 0,
9
- 0,
10
- 0,
11
- 0,
12
- 2,
13
- 255,
14
- ]);
15
- const GZIP_FOOTER_SIZE = 8;
16
- const CRC32_TABLE = createCrc32Table();
17
- function createCrc32Table() {
18
- const table = new Uint32Array(256);
19
- for (let value = 0; value < table.length; value += 1) {
20
- let crc = value;
21
- for (let bit = 0; bit < 8; bit += 1) {
22
- crc = (crc >>> 1) ^ (crc & 1 ? 0xedb88320 : 0);
23
- }
24
- table[value] = crc >>> 0;
25
- }
26
- return table;
27
- }
28
- function crc32(bytes) {
29
- let crc = 0xffffffff;
30
- for (const byte of bytes) {
31
- crc = (crc >>> 8) ^ (CRC32_TABLE[(crc ^ byte) & 0xff] ?? 0);
32
- }
33
- return (crc ^ 0xffffffff) >>> 0;
34
- }
35
- export function encodeDeterministicGzipV1(input) {
36
- const compressed = Uint8Array.from(deflateSync(input, {
37
- level: 9,
38
- mem: 8,
39
- }));
40
- const totalLength = GZIP_HEADER.byteLength + compressed.byteLength + GZIP_FOOTER_SIZE;
41
- if (!Number.isSafeInteger(totalLength)) {
42
- throw new CapabilityArtifactError("ARTIFACT_SIZE_OVERFLOW", "gzip output exceeds the safe integer range");
43
- }
44
- const output = new Uint8Array(totalLength);
45
- output.set(GZIP_HEADER, 0);
46
- output.set(compressed, GZIP_HEADER.byteLength);
47
- const footer = new DataView(output.buffer, output.byteOffset + output.byteLength - GZIP_FOOTER_SIZE, GZIP_FOOTER_SIZE);
48
- footer.setUint32(0, crc32(input), true);
49
- footer.setUint32(4, input.byteLength >>> 0, true);
50
- return output;
51
- }
@@ -1,6 +0,0 @@
1
- export interface TarFileEntryV1 {
2
- path: string;
3
- bytes: Uint8Array;
4
- }
5
- export declare function encodeDeterministicUstarV1(files: TarFileEntryV1[]): Uint8Array;
6
- //# sourceMappingURL=deterministicTar.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"deterministicTar.d.ts","sourceRoot":"","sources":["../../../src/node/capabilities/deterministicTar.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,UAAU,CAAC;CACnB;AAwJD,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,UAAU,CA2B9E"}
@@ -1,128 +0,0 @@
1
- import { compareUtf16 } from "./canonicalJson.js";
2
- import { canonicalArchivePathProblem } from "./archivePath.js";
3
- import { CapabilityArtifactError } from "./capabilityArtifactError.js";
4
- const TAR_BLOCK_SIZE = 512;
5
- const textEncoder = new TextEncoder();
6
- function failInvalidPath(path) {
7
- throw new CapabilityArtifactError("ARTIFACT_PATH_INVALID", `Invalid USTAR file path: ${path}`);
8
- }
9
- function validateFilePath(path) {
10
- if (canonicalArchivePathProblem(path))
11
- failInvalidPath(path);
12
- }
13
- function byteLength(value) {
14
- return textEncoder.encode(value).byteLength;
15
- }
16
- function splitUstarPath(path) {
17
- if (byteLength(path) <= 100)
18
- return { name: path, prefix: "" };
19
- for (let index = path.lastIndexOf("/"); index > 0; index = path.lastIndexOf("/", index - 1)) {
20
- const prefix = path.slice(0, index);
21
- const name = path.slice(index + 1);
22
- if (name.length > 0 && byteLength(prefix) <= 155 && byteLength(name) <= 100) {
23
- return { name, prefix };
24
- }
25
- }
26
- throw new CapabilityArtifactError("ARTIFACT_PATH_USTAR_UNREPRESENTABLE", `Path cannot be represented by POSIX USTAR: ${path}`);
27
- }
28
- function writeAscii(block, offset, length, value) {
29
- const bytes = textEncoder.encode(value);
30
- if (bytes.byteLength > length) {
31
- throw new CapabilityArtifactError("ARTIFACT_PATH_USTAR_UNREPRESENTABLE", `USTAR field exceeds ${length} bytes: ${value}`);
32
- }
33
- block.set(bytes, offset);
34
- }
35
- function writeOctal(block, offset, length, value) {
36
- if (!Number.isSafeInteger(value) || value < 0) {
37
- throw new CapabilityArtifactError("ARTIFACT_SIZE_OVERFLOW", `USTAR numeric field is outside the safe integer range: ${value}`);
38
- }
39
- const octal = value.toString(8);
40
- if (octal.length > length - 1) {
41
- throw new CapabilityArtifactError("ARTIFACT_SIZE_OVERFLOW", `USTAR numeric field exceeds ${length - 1} octal digits: ${value}`);
42
- }
43
- writeAscii(block, offset, length, `${octal.padStart(length - 1, "0")}\0`);
44
- }
45
- function writeChecksum(block, checksum) {
46
- const octal = checksum.toString(8);
47
- if (octal.length > 6) {
48
- throw new CapabilityArtifactError("ARTIFACT_SIZE_OVERFLOW", `USTAR checksum exceeds six octal digits: ${checksum}`);
49
- }
50
- writeAscii(block, 148, 8, `${octal.padStart(6, "0")}\0 `);
51
- }
52
- function createHeader(entry) {
53
- const block = new Uint8Array(TAR_BLOCK_SIZE);
54
- const { name, prefix } = splitUstarPath(entry.path);
55
- writeAscii(block, 0, 100, name);
56
- writeOctal(block, 100, 8, entry.type === "directory" ? 0o755 : 0o644);
57
- writeOctal(block, 108, 8, 0);
58
- writeOctal(block, 116, 8, 0);
59
- writeOctal(block, 124, 12, entry.type === "directory" ? 0 : entry.bytes.byteLength);
60
- writeOctal(block, 136, 12, 0);
61
- block.fill(0x20, 148, 156);
62
- block[156] = (entry.type === "directory" ? "5" : "0").charCodeAt(0);
63
- writeAscii(block, 257, 6, "ustar\0");
64
- writeAscii(block, 263, 2, "00");
65
- writeOctal(block, 329, 8, 0);
66
- writeOctal(block, 337, 8, 0);
67
- writeAscii(block, 345, 155, prefix);
68
- let checksum = 0;
69
- for (const byte of block)
70
- checksum += byte;
71
- writeChecksum(block, checksum);
72
- return block;
73
- }
74
- function collectEntries(files) {
75
- const filePaths = new Set();
76
- const directoryPaths = new Set();
77
- const fileEntries = [];
78
- for (const file of files) {
79
- validateFilePath(file.path);
80
- splitUstarPath(file.path);
81
- if (filePaths.has(file.path)) {
82
- throw new CapabilityArtifactError("ARTIFACT_PATH_DUPLICATE", `Duplicate USTAR file path: ${file.path}`);
83
- }
84
- filePaths.add(file.path);
85
- fileEntries.push({ path: file.path, type: "file", bytes: file.bytes });
86
- const segments = file.path.split("/");
87
- for (let index = 1; index < segments.length; index += 1) {
88
- const directory = `${segments.slice(0, index).join("/")}/`;
89
- splitUstarPath(directory);
90
- directoryPaths.add(directory);
91
- }
92
- }
93
- for (const directory of directoryPaths) {
94
- if (filePaths.has(directory.slice(0, -1))) {
95
- throw new CapabilityArtifactError("ARTIFACT_PATH_DUPLICATE", `USTAR path is both a file and directory: ${directory}`);
96
- }
97
- }
98
- const entries = [
99
- ...[...directoryPaths].map((path) => ({ path, type: "directory" })),
100
- ...fileEntries,
101
- ];
102
- entries.sort((left, right) => compareUtf16(left.path, right.path));
103
- return entries;
104
- }
105
- export function encodeDeterministicUstarV1(files) {
106
- const entries = collectEntries(files);
107
- let totalLength = TAR_BLOCK_SIZE * 2;
108
- for (const entry of entries) {
109
- totalLength += TAR_BLOCK_SIZE;
110
- if (entry.type === "file") {
111
- totalLength += Math.ceil(entry.bytes.byteLength / TAR_BLOCK_SIZE) * TAR_BLOCK_SIZE;
112
- }
113
- if (!Number.isSafeInteger(totalLength)) {
114
- throw new CapabilityArtifactError("ARTIFACT_SIZE_OVERFLOW", "USTAR archive size exceeds the safe integer range");
115
- }
116
- }
117
- const archive = new Uint8Array(totalLength);
118
- let offset = 0;
119
- for (const entry of entries) {
120
- archive.set(createHeader(entry), offset);
121
- offset += TAR_BLOCK_SIZE;
122
- if (entry.type === "file") {
123
- archive.set(entry.bytes, offset);
124
- offset += Math.ceil(entry.bytes.byteLength / TAR_BLOCK_SIZE) * TAR_BLOCK_SIZE;
125
- }
126
- }
127
- return archive;
128
- }
@@ -1,24 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -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,16 +0,0 @@
1
- import type { CanonicalSkillInputV1 } from "./capabilityArtifactTypes.js";
2
- export interface CapabilitySkillManifestEntryV1 {
3
- name: string;
4
- entrypoint: string;
5
- files: string[];
6
- }
7
- export interface CapabilitySkillManifestV1 {
8
- schemaVersion: "spotlight.skill-manifest/1";
9
- skills: CapabilitySkillManifestEntryV1[];
10
- }
11
- export declare function buildSkillManifestV1(skills: CanonicalSkillInputV1[]): {
12
- manifest: CapabilitySkillManifestV1;
13
- bytes: Uint8Array<ArrayBufferLike>;
14
- digest: string;
15
- };
16
- //# sourceMappingURL=skillManifest.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"skillManifest.d.ts","sourceRoot":"","sources":["../../../src/node/capabilities/skillManifest.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAE1E,MAAM,WAAW,8BAA8B;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,yBAAyB;IACxC,aAAa,EAAE,4BAA4B,CAAC;IAC5C,MAAM,EAAE,8BAA8B,EAAE,CAAC;CAC1C;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,qBAAqB,EAAE;cAeP,yBAAyB;;;EAIrF"}
@@ -1,22 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { canonicalizeJson, compareUtf16 } from "./canonicalJson.js";
3
- export function buildSkillManifestV1(skills) {
4
- const manifest = {
5
- schemaVersion: "spotlight.skill-manifest/1",
6
- skills: skills
7
- .map((skill) => ({
8
- name: skill.name,
9
- entrypoint: `skills/${skill.name}/SKILL.md`,
10
- files: skill.files
11
- .map((file) => `skills/${skill.name}/${file.relativePath}`)
12
- .sort(compareUtf16),
13
- }))
14
- .sort((left, right) => compareUtf16(left.name, right.name)),
15
- };
16
- const bytes = canonicalizeJson(manifest);
17
- return {
18
- manifest: JSON.parse(new TextDecoder().decode(bytes)),
19
- bytes,
20
- digest: `sha256:${createHash("sha256").update(bytes).digest("hex")}`,
21
- };
22
- }
@@ -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"}