@jini-ai/plugins 0.0.0-stage → 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.
- package/CHANGELOG.md +27 -0
- package/LICENSE +201 -0
- package/README.md +60 -2
- package/dist/glue/attachment-points/content-lifecycle.d.ts +52 -0
- package/dist/glue/attachment-points/content-lifecycle.js +15 -0
- package/dist/glue/attachment-points/events.d.ts +12 -0
- package/dist/glue/attachment-points/events.js +5 -0
- package/dist/glue/attachment-points/tool-registration.d.ts +23 -0
- package/dist/glue/attachment-points/tool-registration.js +43 -0
- package/dist/glue/capability-gate.d.ts +73 -0
- package/dist/glue/capability-gate.js +41 -0
- package/dist/glue/dispatch.d.ts +20 -0
- package/dist/glue/dispatch.js +9 -0
- package/dist/glue/index.d.ts +8 -0
- package/dist/glue/index.js +8 -0
- package/dist/glue/manifest.d.ts +43 -0
- package/dist/glue/manifest.js +106 -0
- package/dist/glue/ports.d.ts +60 -0
- package/dist/glue/ports.js +2 -0
- package/dist/host/activation.d.ts +118 -0
- package/dist/host/activation.js +104 -0
- package/dist/host/attach-loaded-plugin.d.ts +37 -0
- package/dist/host/attach-loaded-plugin.js +19 -0
- package/dist/host/capability-sdk.d.ts +74 -0
- package/dist/host/capability-sdk.js +94 -0
- package/dist/host/claim-conflicts.d.ts +101 -0
- package/dist/host/claim-conflicts.js +139 -0
- package/dist/host/contributions.d.ts +129 -0
- package/dist/host/contributions.js +167 -0
- package/dist/host/declarative-enable.d.ts +43 -0
- package/dist/host/declarative-enable.js +73 -0
- package/dist/host/discovery-types.d.ts +55 -0
- package/dist/host/discovery-types.js +2 -0
- package/dist/host/errors.d.ts +20 -0
- package/dist/host/errors.js +22 -0
- package/dist/host/hook-registry.d.ts +113 -0
- package/dist/host/hook-registry.js +190 -0
- package/dist/host/index.d.ts +19 -0
- package/dist/host/index.js +19 -0
- package/dist/host/manifest.d.ts +159 -0
- package/dist/host/manifest.js +417 -0
- package/dist/host/node/discovery.d.ts +32 -0
- package/dist/host/node/discovery.js +241 -0
- package/dist/host/node/index.d.ts +8 -0
- package/dist/host/node/index.js +8 -0
- package/dist/host/node/install.d.ts +118 -0
- package/dist/host/node/install.js +431 -0
- package/dist/host/node/loader.d.ts +55 -0
- package/dist/host/node/loader.js +146 -0
- package/dist/host/node/module-snapshot.d.ts +25 -0
- package/dist/host/node/module-snapshot.js +53 -0
- package/dist/host/node/package-files.d.ts +52 -0
- package/dist/host/node/package-files.js +214 -0
- package/dist/host/node/source-drafts.d.ts +98 -0
- package/dist/host/node/source-drafts.js +323 -0
- package/dist/host/plugin-claims.d.ts +75 -0
- package/dist/host/plugin-claims.js +182 -0
- package/dist/host/ports.d.ts +208 -0
- package/dist/host/ports.js +2 -0
- package/dist/host/quarantine.d.ts +19 -0
- package/dist/host/quarantine.js +28 -0
- package/dist/host/repo.memory.d.ts +27 -0
- package/dist/host/repo.memory.js +33 -0
- package/dist/host/source-policy.d.ts +18 -0
- package/dist/host/source-policy.js +13 -0
- package/dist/host/sql/index.d.ts +4 -0
- package/dist/host/sql/index.js +4 -0
- package/dist/host/sql/repo.d.ts +38 -0
- package/dist/host/sql/repo.js +50 -0
- package/dist/host/sql/repo.rows.d.ts +28 -0
- package/dist/host/sql/repo.rows.js +28 -0
- package/dist/host/tool-contributions.d.ts +26 -0
- package/dist/host/tool-contributions.js +42 -0
- package/dist/host/uninstall.d.ts +88 -0
- package/dist/host/uninstall.js +112 -0
- package/dist/host/worker/import-seam.d.ts +45 -0
- package/dist/host/worker/import-seam.js +52 -0
- package/dist/host/worker/index.d.ts +5 -0
- package/dist/host/worker/index.js +5 -0
- package/dist/host/worker/protocol.d.ts +62 -0
- package/dist/host/worker/protocol.js +31 -0
- package/dist/host/worker/run-call.d.ts +27 -0
- package/dist/host/worker/run-call.js +76 -0
- package/package.json +107 -3
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Site-plugin graph isolation. A fresh filesystem identity covers relative ESM, dynamic imports
|
|
2
|
+
* and CommonJS requires together; a query on the entry alone covers only that entry.
|
|
3
|
+
* Snapshots live outside discovery and remain available for late dynamic imports until shutdown.
|
|
4
|
+
*/
|
|
5
|
+
import { mkdir, mkdtemp, rm, writeFile, lstat } from "node:fs/promises";
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { snapshotSitePluginPackage } from "./install.js";
|
|
9
|
+
export class PluginSnapshotIntegrityError extends Error {
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Copies a site plugin's verified package into a fresh, read-only runtime snapshot and returns the
|
|
13
|
+
* snapshot's server entry. Every file must match the manifest's integrity map, and every listed file
|
|
14
|
+
* must exist; a failed copy removes the half-written snapshot.
|
|
15
|
+
* @param required.pluginRoot The installed package directory.
|
|
16
|
+
* @param required.manifest The installed manifest whose `integrity` map is enforced.
|
|
17
|
+
* @param optional.writeSnapshotFile File writer for the snapshot; defaults to `fs.writeFile`.
|
|
18
|
+
* @throws {PluginSnapshotIntegrityError} On a changed/missing file or a linked runtime root.
|
|
19
|
+
* @complexity O(total package bytes).
|
|
20
|
+
*/
|
|
21
|
+
export async function snapshotPluginModuleGraph(required, { writeSnapshotFile = writeFile } = {}) {
|
|
22
|
+
const files = await snapshotSitePluginPackage({ sourceDir: required.pluginRoot });
|
|
23
|
+
for (const [key, bytes] of files) {
|
|
24
|
+
if (key === "tovu.plugin.json")
|
|
25
|
+
continue;
|
|
26
|
+
const digest = `sha256-${createHash("sha256").update(bytes).digest("hex")}`;
|
|
27
|
+
if (required.manifest.integrity[key] !== digest)
|
|
28
|
+
throw new PluginSnapshotIntegrityError("Package changed before loading.");
|
|
29
|
+
}
|
|
30
|
+
for (const key of Object.keys(required.manifest.integrity)) {
|
|
31
|
+
if (!files.has(key))
|
|
32
|
+
throw new PluginSnapshotIntegrityError("Package file disappeared before loading.");
|
|
33
|
+
}
|
|
34
|
+
const cacheRoot = path.dirname(path.dirname(required.pluginRoot)) + "-runtime";
|
|
35
|
+
await mkdir(cacheRoot, { recursive: true, mode: 0o700 });
|
|
36
|
+
const info = await lstat(cacheRoot);
|
|
37
|
+
if (!info.isDirectory() || info.isSymbolicLink())
|
|
38
|
+
throw new PluginSnapshotIntegrityError("Runtime snapshot root must not be a link.");
|
|
39
|
+
const snapshotRoot = await mkdtemp(path.join(cacheRoot, "load-"));
|
|
40
|
+
try {
|
|
41
|
+
for (const [key, bytes] of files) {
|
|
42
|
+
const destination = path.join(snapshotRoot, key);
|
|
43
|
+
await mkdir(path.dirname(destination), { recursive: true });
|
|
44
|
+
await writeSnapshotFile(destination, bytes, { flag: "wx", mode: 0o400 });
|
|
45
|
+
}
|
|
46
|
+
return path.join(snapshotRoot, "server/index.mjs");
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
await rm(snapshotRoot, { recursive: true, force: true });
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=module-snapshot.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export interface PluginPackageFileLimits {
|
|
2
|
+
readonly maxFiles: number;
|
|
3
|
+
/** Files, symlinks, and directories visited — bounds `readdir` calls on a wide, deep tree. */
|
|
4
|
+
readonly maxEntries: number;
|
|
5
|
+
readonly maxFileBytes: number;
|
|
6
|
+
readonly maxTotalBytes: number;
|
|
7
|
+
}
|
|
8
|
+
/** Sized for a plugin package (a manifest, an entry file, a handful of skills or assets), not a
|
|
9
|
+
* vendored dependency tree. Sent to the client with every listing so its notices never hardcode them. */
|
|
10
|
+
export declare const PLUGIN_PACKAGE_FILE_LIMITS: PluginPackageFileLimits;
|
|
11
|
+
export type PluginPackageFileOmission = "binary" | "too-large" | "symlink" | "unreadable";
|
|
12
|
+
export interface PluginPackageFile {
|
|
13
|
+
/** `/`-separated, relative to the plugin's own directory. */
|
|
14
|
+
readonly relativePath: string;
|
|
15
|
+
/** Bytes on disk; `0` for a symlink or a file that could not be opened. */
|
|
16
|
+
readonly sizeBytes: number;
|
|
17
|
+
/** The file's UTF-8 text — `null` exactly when `omitted` is set. */
|
|
18
|
+
readonly content: string | null;
|
|
19
|
+
readonly omitted: PluginPackageFileOmission | null;
|
|
20
|
+
}
|
|
21
|
+
export interface PluginPackageFiles {
|
|
22
|
+
readonly files: readonly PluginPackageFile[];
|
|
23
|
+
/** A file-count, entry, or total-byte cap stopped the walk before every file was listed. */
|
|
24
|
+
readonly truncated: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** `rootDir` is a symlink, not a directory, or resolves outside `containerDir`. The message names
|
|
27
|
+
* server paths — a route must not echo it to a client. */
|
|
28
|
+
export declare class PluginPackagePathError extends Error {
|
|
29
|
+
constructor(message: string);
|
|
30
|
+
}
|
|
31
|
+
export interface ReadPluginPackageFilesRequired {
|
|
32
|
+
readonly input: {
|
|
33
|
+
/** The plugin's own directory. Missing on disk ⇒ an empty listing, not an error. */
|
|
34
|
+
readonly rootDir: string;
|
|
35
|
+
/** The directory `rootDir` must resolve inside (the install dir, or a built-in's own folder). */
|
|
36
|
+
readonly containerDir: string;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export interface ReadPluginPackageFilesOptional {
|
|
40
|
+
readonly limits?: PluginPackageFileLimits;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Lists a plugin package's files, breadth-first — so a package's top-level manifest is always listed
|
|
44
|
+
* before a deep subtree can use up the caps.
|
|
45
|
+
*
|
|
46
|
+
* @throws {PluginPackagePathError} `input.rootDir` is a symlink or not a directory, or resolves
|
|
47
|
+
* outside `input.containerDir`.
|
|
48
|
+
* @complexity O(min(entries, maxEntries)) directory entries plus O(maxTotalBytes) bytes read; memory
|
|
49
|
+
* is bounded by the same two caps.
|
|
50
|
+
*/
|
|
51
|
+
export declare function readPluginPackageFiles(required: ReadPluginPackageFilesRequired, optional?: ReadPluginPackageFilesOptional): Promise<PluginPackageFiles>;
|
|
52
|
+
//# sourceMappingURL=package-files.d.ts.map
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file `readPluginPackageFiles()` — the read-only, bounded file listing behind the admin Plugins
|
|
3
|
+
* screen's package-files viewer (`PLUGIN_FILES`, `routes/plugins/files.ts`, 2026-09-13).
|
|
4
|
+
*
|
|
5
|
+
* Purpose:
|
|
6
|
+
* Walks ONE plugin's own directory and returns each regular file's UTF-8 text. Mechanism only:
|
|
7
|
+
* which directory belongs to which plugin is the composition root's decision
|
|
8
|
+
* (`server/runtime/composition/plugin-runtime.ts`'s `readPluginPackageFiles` binding), and who may
|
|
9
|
+
* call it is the route's.
|
|
10
|
+
*
|
|
11
|
+
* Safety — each guard is independent, not presumed covered by another:
|
|
12
|
+
* - `rootDir` itself must be a plain directory (not a symlink), and its realpath must be
|
|
13
|
+
* `containerDir`'s realpath or a descendant of it. Otherwise `PluginPackagePathError`.
|
|
14
|
+
* - The walk reads `readdir` `Dirent` types, which never follow symlinks: a symlink entry is
|
|
15
|
+
* listed with `omitted: "symlink"` and is neither descended into nor read.
|
|
16
|
+
* - Every file is opened with `O_NOFOLLOW`, so a file swapped for a symlink between listing and
|
|
17
|
+
* open fails (`ELOOP`) and is reported as `"symlink"` instead of reading the link's target.
|
|
18
|
+
* - Caps on files listed, entries visited, bytes per file, and bytes in total. A count or total cap
|
|
19
|
+
* stops the walk and sets `truncated`; one oversized file is listed as `"too-large"`.
|
|
20
|
+
* - A file containing a NUL byte or invalid UTF-8 is listed as `"binary"`, with no content.
|
|
21
|
+
*
|
|
22
|
+
* Residual risk (disclosed, not closed): `O_NOFOLLOW` guards only a path's final component, so a
|
|
23
|
+
* directory swapped for a symlink mid-walk could still be descended. Doing that needs write access
|
|
24
|
+
* to the plugin install directory, which for a tier-3 plugin already means code execution on
|
|
25
|
+
* enable — this viewer is defense in depth, not the boundary.
|
|
26
|
+
*/
|
|
27
|
+
import { constants } from "node:fs";
|
|
28
|
+
import { lstat, open, readdir, realpath } from "node:fs/promises";
|
|
29
|
+
import path from "node:path";
|
|
30
|
+
/** Sized for a plugin package (a manifest, an entry file, a handful of skills or assets), not a
|
|
31
|
+
* vendored dependency tree. Sent to the client with every listing so its notices never hardcode them. */
|
|
32
|
+
export const PLUGIN_PACKAGE_FILE_LIMITS = {
|
|
33
|
+
maxFiles: 200,
|
|
34
|
+
maxEntries: 2000,
|
|
35
|
+
maxFileBytes: 512 * 1024,
|
|
36
|
+
maxTotalBytes: 4 * 1024 * 1024,
|
|
37
|
+
};
|
|
38
|
+
/** `rootDir` is a symlink, not a directory, or resolves outside `containerDir`. The message names
|
|
39
|
+
* server paths — a route must not echo it to a client. */
|
|
40
|
+
export class PluginPackagePathError extends Error {
|
|
41
|
+
constructor(message) {
|
|
42
|
+
super(message);
|
|
43
|
+
this.name = "PluginPackagePathError";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const STRICT_UTF8 = new TextDecoder("utf-8", { fatal: true });
|
|
47
|
+
function errnoCode(error) {
|
|
48
|
+
return error?.code;
|
|
49
|
+
}
|
|
50
|
+
function omittedFile(relativePath, sizeBytes, omitted) {
|
|
51
|
+
return { relativePath, sizeBytes, content: null, omitted };
|
|
52
|
+
}
|
|
53
|
+
/** Code-unit order, so the listing is identical whatever the server's locale. */
|
|
54
|
+
function byName(a, b) {
|
|
55
|
+
if (a.name === b.name)
|
|
56
|
+
return 0;
|
|
57
|
+
return a.name < b.name ? -1 : 1;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* @returns `rootDir`'s realpath, or `null` when it does not exist.
|
|
61
|
+
* @throws {PluginPackagePathError} `rootDir` is a symlink or not a directory, or resolves outside `containerDir`.
|
|
62
|
+
*/
|
|
63
|
+
async function resolvePackageRoot(rootDir, containerDir) {
|
|
64
|
+
let stats;
|
|
65
|
+
try {
|
|
66
|
+
stats = await lstat(rootDir);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
if (errnoCode(error) === "ENOENT")
|
|
70
|
+
return null;
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
if (stats.isSymbolicLink() || !stats.isDirectory()) {
|
|
74
|
+
throw new PluginPackagePathError(`'${rootDir}' is not a plain directory`);
|
|
75
|
+
}
|
|
76
|
+
const [rootReal, containerReal] = await Promise.all([realpath(rootDir), realpath(containerDir)]);
|
|
77
|
+
if (rootReal !== containerReal && !rootReal.startsWith(containerReal + path.sep)) {
|
|
78
|
+
throw new PluginPackagePathError(`'${rootDir}' resolves outside '${containerDir}'`);
|
|
79
|
+
}
|
|
80
|
+
return rootReal;
|
|
81
|
+
}
|
|
82
|
+
/** Counts one entry against the caps. `false` (and `truncated` set) once a cap is already full. */
|
|
83
|
+
function admitEntry(state) {
|
|
84
|
+
if (state.truncated)
|
|
85
|
+
return false;
|
|
86
|
+
if (state.files.length >= state.limits.maxFiles || state.entries >= state.limits.maxEntries) {
|
|
87
|
+
state.truncated = true;
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
state.entries += 1;
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
async function openNoFollow(absolutePath) {
|
|
94
|
+
try {
|
|
95
|
+
// `O_NOFOLLOW` is undefined on Windows; `?? 0` keeps the open valid there.
|
|
96
|
+
return await open(absolutePath, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
const code = errnoCode(error);
|
|
100
|
+
return code === "ELOOP" || code === "EMLINK" ? "symlink" : "unreadable";
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** Reads up to `maxBytes` from the start of the file. */
|
|
104
|
+
async function readAtMost(handle, maxBytes) {
|
|
105
|
+
const buffer = Buffer.alloc(maxBytes);
|
|
106
|
+
let offset = 0;
|
|
107
|
+
while (offset < maxBytes) {
|
|
108
|
+
const { bytesRead } = await handle.read(buffer, offset, maxBytes - offset, offset);
|
|
109
|
+
if (bytesRead === 0)
|
|
110
|
+
break;
|
|
111
|
+
offset += bytesRead;
|
|
112
|
+
}
|
|
113
|
+
return buffer.subarray(0, offset);
|
|
114
|
+
}
|
|
115
|
+
function toTextOrBinary(relativePath, bytes) {
|
|
116
|
+
if (bytes.includes(0))
|
|
117
|
+
return omittedFile(relativePath, bytes.length, "binary");
|
|
118
|
+
try {
|
|
119
|
+
return { relativePath, sizeBytes: bytes.length, content: STRICT_UTF8.decode(bytes), omitted: null };
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return omittedFile(relativePath, bytes.length, "binary");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Records one regular file. Reads at most `min(size, maxFileBytes) + 1` bytes, so a file that grew
|
|
127
|
+
* past the cap after `stat` is still caught as too large rather than read whole.
|
|
128
|
+
*/
|
|
129
|
+
async function readFileEntry(absolutePath, relativePath, state) {
|
|
130
|
+
const opened = await openNoFollow(absolutePath);
|
|
131
|
+
if (typeof opened === "string") {
|
|
132
|
+
state.files.push(omittedFile(relativePath, 0, opened));
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
try {
|
|
136
|
+
const stats = await opened.stat();
|
|
137
|
+
if (!stats.isFile())
|
|
138
|
+
return;
|
|
139
|
+
const { maxFileBytes, maxTotalBytes } = state.limits;
|
|
140
|
+
if (stats.size > maxFileBytes) {
|
|
141
|
+
state.files.push(omittedFile(relativePath, stats.size, "too-large"));
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (state.totalBytes + stats.size > maxTotalBytes) {
|
|
145
|
+
state.truncated = true;
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const bytes = await readAtMost(opened, Math.min(stats.size, maxFileBytes) + 1);
|
|
149
|
+
if (bytes.length > maxFileBytes) {
|
|
150
|
+
state.files.push(omittedFile(relativePath, bytes.length, "too-large"));
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
state.totalBytes += bytes.length;
|
|
154
|
+
state.files.push(toTextOrBinary(relativePath, bytes));
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
await opened.close();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/** Lists one directory level: symlinks and files are recorded now in name order; subdirectories are
|
|
161
|
+
* returned for the next level. An unreadable subdirectory lists as empty rather than failing the
|
|
162
|
+
* whole package. */
|
|
163
|
+
async function readDirectoryLevel(rootReal, relativeDir, state) {
|
|
164
|
+
let entries;
|
|
165
|
+
try {
|
|
166
|
+
entries = await readdir(path.join(rootReal, relativeDir), { withFileTypes: true });
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
return [];
|
|
170
|
+
}
|
|
171
|
+
const subdirectories = [];
|
|
172
|
+
for (const entry of entries.sort(byName)) {
|
|
173
|
+
if (!admitEntry(state))
|
|
174
|
+
break;
|
|
175
|
+
const relativePath = relativeDir === "" ? entry.name : `${relativeDir}/${entry.name}`;
|
|
176
|
+
if (entry.isDirectory())
|
|
177
|
+
subdirectories.push(relativePath);
|
|
178
|
+
else if (entry.isSymbolicLink())
|
|
179
|
+
state.files.push(omittedFile(relativePath, 0, "symlink"));
|
|
180
|
+
else if (entry.isFile())
|
|
181
|
+
await readFileEntry(path.join(rootReal, relativePath), relativePath, state);
|
|
182
|
+
if (state.truncated)
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
return subdirectories;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Lists a plugin package's files, breadth-first — so a package's top-level manifest is always listed
|
|
189
|
+
* before a deep subtree can use up the caps.
|
|
190
|
+
*
|
|
191
|
+
* @throws {PluginPackagePathError} `input.rootDir` is a symlink or not a directory, or resolves
|
|
192
|
+
* outside `input.containerDir`.
|
|
193
|
+
* @complexity O(min(entries, maxEntries)) directory entries plus O(maxTotalBytes) bytes read; memory
|
|
194
|
+
* is bounded by the same two caps.
|
|
195
|
+
*/
|
|
196
|
+
export async function readPluginPackageFiles(required, optional = {}) {
|
|
197
|
+
const { rootDir, containerDir } = required.input;
|
|
198
|
+
const rootReal = await resolvePackageRoot(rootDir, containerDir);
|
|
199
|
+
if (rootReal === null)
|
|
200
|
+
return { files: [], truncated: false };
|
|
201
|
+
const state = {
|
|
202
|
+
limits: optional.limits ?? PLUGIN_PACKAGE_FILE_LIMITS,
|
|
203
|
+
files: [],
|
|
204
|
+
entries: 0,
|
|
205
|
+
totalBytes: 0,
|
|
206
|
+
truncated: false,
|
|
207
|
+
};
|
|
208
|
+
const pending = [""];
|
|
209
|
+
while (pending.length > 0 && !state.truncated) {
|
|
210
|
+
pending.push(...(await readDirectoryLevel(rootReal, pending.shift(), state)));
|
|
211
|
+
}
|
|
212
|
+
return { files: state.files, truncated: state.truncated };
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=package-files.js.map
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { type FileLockOptions } from '@jini-ai/platform/fs/file-lock';
|
|
2
|
+
import type { ManifestHostPorts } from '../ports.js';
|
|
3
|
+
import type { PluginSourcePolicyPort } from '../source-policy.js';
|
|
4
|
+
import { type PluginInstallerPort, type PluginInstallPreview } from './install.js';
|
|
5
|
+
export declare class PluginSourceError extends Error {
|
|
6
|
+
readonly code: string;
|
|
7
|
+
constructor(code: string, message: string);
|
|
8
|
+
}
|
|
9
|
+
export declare const PLUGIN_SOURCE_LIMITS: {
|
|
10
|
+
readonly maxFileBytes: number;
|
|
11
|
+
readonly maxTotalBytes: number;
|
|
12
|
+
readonly maxEntries: 512;
|
|
13
|
+
};
|
|
14
|
+
type Options = Record<string, never>;
|
|
15
|
+
type Id = {
|
|
16
|
+
id: string;
|
|
17
|
+
};
|
|
18
|
+
type File = Id & {
|
|
19
|
+
path: string;
|
|
20
|
+
};
|
|
21
|
+
export interface PluginSourceSealResult {
|
|
22
|
+
readonly installed: true;
|
|
23
|
+
readonly plugin: PluginInstallPreview;
|
|
24
|
+
readonly reloaded: boolean;
|
|
25
|
+
readonly reloadError?: string;
|
|
26
|
+
readonly rollbackFrom?: string;
|
|
27
|
+
}
|
|
28
|
+
/** Only relative paths and model-facing facts cross this port; no local filesystem handles. */
|
|
29
|
+
export interface PluginSourcePort {
|
|
30
|
+
create(required: Id & {
|
|
31
|
+
name: string;
|
|
32
|
+
description: string;
|
|
33
|
+
}, optional?: Options): Promise<{
|
|
34
|
+
created: boolean;
|
|
35
|
+
}>;
|
|
36
|
+
open(required: Id, optional?: Options): Promise<{
|
|
37
|
+
created: boolean;
|
|
38
|
+
}>;
|
|
39
|
+
list(required: Id, optional?: Options): Promise<{
|
|
40
|
+
files: readonly {
|
|
41
|
+
path: string;
|
|
42
|
+
bytes: number;
|
|
43
|
+
}[];
|
|
44
|
+
}>;
|
|
45
|
+
read(required: File, optional?: Options): Promise<{
|
|
46
|
+
content: string;
|
|
47
|
+
bytes: number;
|
|
48
|
+
digest: string;
|
|
49
|
+
}>;
|
|
50
|
+
write(required: File & {
|
|
51
|
+
content: string;
|
|
52
|
+
}, optional?: Options): Promise<{
|
|
53
|
+
bytesWritten: number;
|
|
54
|
+
}>;
|
|
55
|
+
edit(required: File & {
|
|
56
|
+
oldString: string;
|
|
57
|
+
newString: string;
|
|
58
|
+
replaceAll?: boolean;
|
|
59
|
+
}, optional?: Options): Promise<{
|
|
60
|
+
bytesWritten: number;
|
|
61
|
+
replacements: number;
|
|
62
|
+
}>;
|
|
63
|
+
delete(required: File, optional?: {
|
|
64
|
+
expectedDigest?: string;
|
|
65
|
+
}): Promise<{
|
|
66
|
+
deleted: true;
|
|
67
|
+
}>;
|
|
68
|
+
seal(required: Id, optional?: Options): Promise<PluginSourceSealResult>;
|
|
69
|
+
rollback(required: Id, optional?: Options): Promise<PluginSourceSealResult>;
|
|
70
|
+
isSealedHere(required: Id & {
|
|
71
|
+
version: string;
|
|
72
|
+
}, optional?: Options): Promise<boolean>;
|
|
73
|
+
}
|
|
74
|
+
export interface PluginSourceDeps extends ManifestHostPorts {
|
|
75
|
+
readonly installDir: string;
|
|
76
|
+
readonly builtInIds: readonly string[];
|
|
77
|
+
readonly installer: PluginInstallerPort;
|
|
78
|
+
readonly policy: PluginSourcePolicyPort;
|
|
79
|
+
/** Host ABI text, avoiding an external site's dependency on npm package resolution. */
|
|
80
|
+
readonly scaffoldEntry: string;
|
|
81
|
+
/** Re-enters the validated runtime loader; returns false when this workspace has it OFF. */
|
|
82
|
+
readonly reload: (required: Id, optional?: Options) => Promise<boolean>;
|
|
83
|
+
/** Installer-owned retention runs only after reload succeeds; preserves every active pointer. */
|
|
84
|
+
readonly pruneVersions: (required: Id, optional?: Options) => Promise<readonly string[]>;
|
|
85
|
+
}
|
|
86
|
+
/** Build the bounded Node draft adapter.
|
|
87
|
+
* @param required Site path and injected manifest, installer, policy and reload owners.
|
|
88
|
+
* @param optional.temporaryDir External sealing staging root; defaults to the OS temp directory.
|
|
89
|
+
* @returns The source tool port. Typed source/install errors describe refusals; filesystem faults reject.
|
|
90
|
+
* @example createPluginSourceService({ ...host, installDir, installer, policy, reload, builtInIds: [], scaffoldEntry }, {})
|
|
91
|
+
* @complexity O(package bytes) per operation, capped at 8 MiB / 512 entries.
|
|
92
|
+
*/
|
|
93
|
+
export declare function createPluginSourceService(required: PluginSourceDeps, optional?: {
|
|
94
|
+
temporaryDir?: string;
|
|
95
|
+
lockPorts?: Pick<FileLockOptions, 'clock' | 'process' | 'hostname'>;
|
|
96
|
+
}): PluginSourcePort;
|
|
97
|
+
export {};
|
|
98
|
+
//# sourceMappingURL=source-drafts.d.ts.map
|