@kingsoftcloud/agentkit-harness-node 0.0.4 → 0.0.6

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.
@@ -5333,12 +5333,12 @@ function createNativeRpcServer({ startup, store, ledger, owner = startup.owner,
5333
5333
  const row = ledger.lookupByRunKey(key);
5334
5334
  if (row) ledger.complete(row.requestId, compactResponse(snap), key);
5335
5335
  } catch (e) {
5336
- process.stderr.write(`complete failed for ${runId}: ${e.message}
5336
+ process.stderr.write(`complete failed for ${runId}: ${publicErrorMessage(e)}
5337
5337
  `);
5338
5338
  }
5339
5339
  }
5340
5340
  } catch (e) {
5341
- process.stderr.write(`drive failed for ${runId}: ${e.message}
5341
+ process.stderr.write(`drive failed for ${runId}: ${publicErrorMessage(e)}
5342
5342
  `);
5343
5343
  } finally {
5344
5344
  resolveDone();
@@ -5380,7 +5380,7 @@ function createNativeRpcServer({ startup, store, ledger, owner = startup.owner,
5380
5380
  if (e.code !== "run_not_found") throw e;
5381
5381
  }
5382
5382
  if (existing) {
5383
- if (terminal3(existing.snapshot)) {
5383
+ if (terminal3(existing.snapshot.phase)) {
5384
5384
  const response = compactResponse(existing.snapshot);
5385
5385
  try {
5386
5386
  ledger.complete(ledgerId(requestId), response, key);
@@ -5600,7 +5600,7 @@ async function main(argv = process.argv.slice(2)) {
5600
5600
  try {
5601
5601
  startup = buildStartup(args);
5602
5602
  } catch (e) {
5603
- process.stderr.write(`startup error: ${e.message}
5603
+ process.stderr.write(`startup error: ${publicErrorMessage(e)}
5604
5604
  `);
5605
5605
  return process.exit(2);
5606
5606
  }
@@ -5614,7 +5614,7 @@ async function main(argv = process.argv.slice(2)) {
5614
5614
  try {
5615
5615
  await server.dispose();
5616
5616
  } catch (e) {
5617
- process.stderr.write(`dispose error: ${e.message}
5617
+ process.stderr.write(`dispose error: ${publicErrorMessage(e)}
5618
5618
  `);
5619
5619
  }
5620
5620
  await Promise.allSettled(handlers);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kingsoftcloud/agentkit-harness-node",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
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.4",
140
+ "@kingsoftcloud/agentkit-harness-core": "0.0.6",
140
141
  "@astral-sh/ruff-wasm-nodejs": "0.16.8",
141
142
  "parse5": "7.3.0",
142
143
  "playwright-core": "1.58.2",
@@ -138,7 +138,17 @@ export function tryLock(path, busyTimeoutMs = 0) {
138
138
  try { createPrivate(path); } catch (error) { if (error.code !== 'EEXIST') throw error; }
139
139
  }
140
140
  const before = privateFile(path);
141
- for (const suffix of ['-journal', '-wal', '-shm']) privateFile(path + suffix, true);
141
+ for (const suffix of ['-journal', '-wal', '-shm']) {
142
+ try { privateFile(path + suffix, true); }
143
+ catch (error) {
144
+ // SQLite may unlink a sidecar while another owner checks its lstat.
145
+ // No lock has been acquired or effect dispatched: treat this transient
146
+ // tombstone as contention, then verify the next acquisition afresh.
147
+ // Main database drift, links and unsafe permissions remain hard errors.
148
+ if (error.code === 'background_state_changed') return null;
149
+ throw error;
150
+ }
151
+ }
142
152
  let db;
143
153
  try {
144
154
  db = new DatabaseSync(path);
@@ -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
+ }