@kingsoftcloud/agentkit-harness-node 0.0.4 → 0.0.5
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/package.json +4 -3
- package/src/package-integrity.mjs +61 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kingsoftcloud/agentkit-harness-node",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Standalone Native Harness Node adapters: a durable SQLite run store, a one-request model HTTP port, and a minimal versioned JSON-RPC 2.0 over NDJSON process entry. Reuses the shared Native adapter implementations and externalizes @kingsoftcloud/agentkit-harness-core; depends on no Studio/DSH code at runtime.",
|
|
@@ -133,10 +133,11 @@
|
|
|
133
133
|
"LICENSE",
|
|
134
134
|
"NOTICE",
|
|
135
135
|
"ZCode-LICENSE",
|
|
136
|
-
"THIRD_PARTY_NOTICES.md"
|
|
136
|
+
"THIRD_PARTY_NOTICES.md",
|
|
137
|
+
"src/package-integrity.mjs"
|
|
137
138
|
],
|
|
138
139
|
"dependencies": {
|
|
139
|
-
"@kingsoftcloud/agentkit-harness-core": "0.0.
|
|
140
|
+
"@kingsoftcloud/agentkit-harness-core": "0.0.5",
|
|
140
141
|
"@astral-sh/ruff-wasm-nodejs": "0.16.8",
|
|
141
142
|
"parse5": "7.3.0",
|
|
142
143
|
"playwright-core": "1.58.2",
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { lstatSync, readdirSync, readFileSync, realpathSync } from 'node:fs';
|
|
2
|
+
import { isAbsolute, join } from 'node:path';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
|
|
5
|
+
/** Verify the exact regular-file set of an installed release. Dependency
|
|
6
|
+
* resolution belongs to the caller; nothing inside a package may be a link.
|
|
7
|
+
*/
|
|
8
|
+
export function verifyPackageFiles(directory, expected, { dependencyPackages = {} } = {}) {
|
|
9
|
+
const root = realpathSync(directory), files = new Map(Object.entries(expected ?? {}));
|
|
10
|
+
if (!files.size) throw Error('Package file manifest is empty');
|
|
11
|
+
for (const [path, hash] of files) {
|
|
12
|
+
if (isAbsolute(path) || path.includes('\\') || path.split('/').some(part => !part || part === '.' || part === '..')
|
|
13
|
+
|| !/^[a-f0-9]{64}$/.test(hash)) throw Error('Invalid package file pin: ' + path);
|
|
14
|
+
}
|
|
15
|
+
const directories = new Set([...files.keys()].flatMap(path => {
|
|
16
|
+
const parts = path.split('/'); return parts.slice(0, -1).map((_, index) => parts.slice(0, index + 1).join('/'));
|
|
17
|
+
}));
|
|
18
|
+
let checked = 0;
|
|
19
|
+
function dependencyDirectory(path) {
|
|
20
|
+
const metadataPath = join(root, 'package.json');
|
|
21
|
+
if (!files.has('package.json') || createHash('sha256').update(readFileSync(metadataPath)).digest('hex') !== files.get('package.json'))
|
|
22
|
+
throw Error('Dependencies require a verified package manifest');
|
|
23
|
+
const metadata = JSON.parse(readFileSync(metadataPath, 'utf8'));
|
|
24
|
+
const declared = { ...metadata.dependencies, ...metadata.optionalDependencies, ...metadata.peerDependencies };
|
|
25
|
+
const names = [];
|
|
26
|
+
for (const name of readdirSync(path)) {
|
|
27
|
+
const entry = join(path, name), info = lstatSync(entry);
|
|
28
|
+
if (!info.isDirectory() || info.isSymbolicLink()) throw Error('Package dependency must be a regular directory: ' + name);
|
|
29
|
+
if (name.startsWith('@')) for (const child of readdirSync(entry)) names.push(name + '/' + child);
|
|
30
|
+
else names.push(name);
|
|
31
|
+
}
|
|
32
|
+
for (const name of names) {
|
|
33
|
+
const entry = join(path, name), info = lstatSync(entry);
|
|
34
|
+
if (!Object.hasOwn(declared, name) || !info.isDirectory() || info.isSymbolicLink())
|
|
35
|
+
throw Error('Unexpected package dependency: ' + name);
|
|
36
|
+
const installed = JSON.parse(readFileSync(join(entry, 'package.json'), 'utf8'));
|
|
37
|
+
const pin = dependencyPackages[`${name}@${installed.version}`];
|
|
38
|
+
if (installed.name !== name || !pin?.files) throw Error('Package dependency has no registry evidence: ' + name);
|
|
39
|
+
verifyPackageFiles(entry, pin.files, { dependencyPackages });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function visit(path, prefix = '') {
|
|
43
|
+
for (const name of readdirSync(path)) {
|
|
44
|
+
const relative = prefix + name, target = join(path, name), info = lstatSync(target);
|
|
45
|
+
if (info.isSymbolicLink()) throw Error('Package link is not allowed: ' + relative);
|
|
46
|
+
if (info.isDirectory()) {
|
|
47
|
+
if (relative === 'node_modules' && Object.keys(dependencyPackages).length) { dependencyDirectory(target); continue; }
|
|
48
|
+
if (!directories.has(relative)) throw Error('Unexpected package directory: ' + relative);
|
|
49
|
+
visit(target, relative + '/');
|
|
50
|
+
} else {
|
|
51
|
+
if (!info.isFile() || !files.has(relative)) throw Error('Unexpected package file: ' + relative);
|
|
52
|
+
const actual = createHash('sha256').update(readFileSync(target)).digest('hex');
|
|
53
|
+
if (actual !== files.get(relative)) throw Error('Package file is stale or modified: ' + relative);
|
|
54
|
+
checked++;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
visit(root);
|
|
59
|
+
if (checked !== files.size) throw Error('Package file is missing');
|
|
60
|
+
return checked;
|
|
61
|
+
}
|