behavguard 0.0.0-stage → 0.8.3

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 (96) hide show
  1. package/.github/workflows/behavguard.yml +91 -0
  2. package/README.md +131 -2
  3. package/config/static-gates.example.json +9 -0
  4. package/dist/analysis-cache.d.ts +3 -0
  5. package/dist/analysis-cache.js +115 -0
  6. package/dist/analysis-cache.js.map +1 -0
  7. package/dist/artifacts.d.ts +32 -0
  8. package/dist/artifacts.js +170 -0
  9. package/dist/artifacts.js.map +1 -0
  10. package/dist/cli.d.ts +2 -0
  11. package/dist/cli.js +200 -0
  12. package/dist/cli.js.map +1 -0
  13. package/dist/comparator.d.ts +21 -0
  14. package/dist/comparator.js +238 -0
  15. package/dist/comparator.js.map +1 -0
  16. package/dist/controller.d.ts +93 -0
  17. package/dist/controller.js +384 -0
  18. package/dist/controller.js.map +1 -0
  19. package/dist/coverage.d.ts +14 -0
  20. package/dist/coverage.js +134 -0
  21. package/dist/coverage.js.map +1 -0
  22. package/dist/database-syntax.d.ts +3 -0
  23. package/dist/database-syntax.js +117 -0
  24. package/dist/database-syntax.js.map +1 -0
  25. package/dist/dependencies.d.ts +10 -0
  26. package/dist/dependencies.js +249 -0
  27. package/dist/dependencies.js.map +1 -0
  28. package/dist/dependency-inputs.d.ts +8 -0
  29. package/dist/dependency-inputs.js +10 -0
  30. package/dist/dependency-inputs.js.map +1 -0
  31. package/dist/effects.d.ts +12 -0
  32. package/dist/effects.js +263 -0
  33. package/dist/effects.js.map +1 -0
  34. package/dist/evidence.d.ts +3 -0
  35. package/dist/evidence.js +68 -0
  36. package/dist/evidence.js.map +1 -0
  37. package/dist/gate.d.ts +46 -0
  38. package/dist/gate.js +89 -0
  39. package/dist/gate.js.map +1 -0
  40. package/dist/index.d.ts +15 -0
  41. package/dist/index.js +11 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/model.d.ts +78 -0
  44. package/dist/model.js +2 -0
  45. package/dist/model.js.map +1 -0
  46. package/dist/package-resolution.d.ts +15 -0
  47. package/dist/package-resolution.js +156 -0
  48. package/dist/package-resolution.js.map +1 -0
  49. package/dist/planning.d.ts +35 -0
  50. package/dist/planning.js +56 -0
  51. package/dist/planning.js.map +1 -0
  52. package/dist/runtime-coverage.d.ts +8 -0
  53. package/dist/runtime-coverage.js +70 -0
  54. package/dist/runtime-coverage.js.map +1 -0
  55. package/dist/runtime-protocol.d.ts +33 -0
  56. package/dist/runtime-protocol.js +2 -0
  57. package/dist/runtime-protocol.js.map +1 -0
  58. package/dist/runtime.d.ts +17 -0
  59. package/dist/runtime.js +215 -0
  60. package/dist/runtime.js.map +1 -0
  61. package/dist/scenarios.d.ts +75 -0
  62. package/dist/scenarios.js +435 -0
  63. package/dist/scenarios.js.map +1 -0
  64. package/dist/snapshot.d.ts +5 -0
  65. package/dist/snapshot.js +93 -0
  66. package/dist/snapshot.js.map +1 -0
  67. package/dist/static-analysis.d.ts +61 -0
  68. package/dist/static-analysis.js +408 -0
  69. package/dist/static-analysis.js.map +1 -0
  70. package/dist/static-approvals.d.ts +25 -0
  71. package/dist/static-approvals.js +54 -0
  72. package/dist/static-approvals.js.map +1 -0
  73. package/dist/static-index.d.ts +113 -0
  74. package/dist/static-index.js +654 -0
  75. package/dist/static-index.js.map +1 -0
  76. package/dist/static-project.d.ts +40 -0
  77. package/dist/static-project.js +236 -0
  78. package/dist/static-project.js.map +1 -0
  79. package/dist/values.d.ts +10 -0
  80. package/dist/values.js +274 -0
  81. package/dist/values.js.map +1 -0
  82. package/dist/version.d.ts +1 -0
  83. package/dist/version.js +3 -0
  84. package/dist/version.js.map +1 -0
  85. package/dist/worker.d.ts +1 -0
  86. package/dist/worker.js +338 -0
  87. package/dist/worker.js.map +1 -0
  88. package/docs/pilot-evaluation.md +113 -0
  89. package/docs/pilot-fixtures/ky840.catalog.json +21 -0
  90. package/docs/pilot-fixtures/ky840.scenarios.json +82 -0
  91. package/docs/pilot-fixtures/ofetch482.catalog.json +45 -0
  92. package/docs/pilot-fixtures/ofetch482.scenarios.json +294 -0
  93. package/package.json +39 -4
  94. package/scripts/check-pull-request.sh +46 -0
  95. package/scripts/github-static-approvals.mjs +196 -0
  96. package/skills/behavguard/SKILL.md +15 -0
package/dist/values.js ADDED
@@ -0,0 +1,274 @@
1
+ import { types } from 'node:util';
2
+ const tagKey = '$behavguard';
3
+ const MAX_DEPTH = 32;
4
+ const MAX_NODES = 20_000;
5
+ const MAX_CHARACTERS = 1_000_000;
6
+ const { isProxy, isNativeError } = types;
7
+ const { create, defineProperty, getOwnPropertyDescriptor, getPrototypeOf, hasOwn } = Object;
8
+ const ownKeys = Reflect.ownKeys;
9
+ const isArray = Array.isArray;
10
+ const objectPrototype = Object.prototype;
11
+ const arrayPrototype = Array.prototype;
12
+ export class UnsupportedValueError extends Error {
13
+ constructor(message) {
14
+ super(message);
15
+ this.name = 'UnsupportedValueError';
16
+ }
17
+ }
18
+ class ValueBudget {
19
+ nodes = 0;
20
+ characters = 0;
21
+ addNode(depth) {
22
+ if (depth > MAX_DEPTH || ++this.nodes > MAX_NODES) {
23
+ throw new UnsupportedValueError('value exceeds the depth or size limit');
24
+ }
25
+ }
26
+ addString(value) {
27
+ this.characters += value.length;
28
+ if (this.characters > MAX_CHARACTERS)
29
+ throw new UnsupportedValueError('value exceeds the text size limit');
30
+ }
31
+ }
32
+ function tag(name) {
33
+ return { [tagKey]: name };
34
+ }
35
+ function defineValue(object, key, value) {
36
+ defineProperty(object, key, { value, writable: true, enumerable: true, configurable: true });
37
+ }
38
+ function ownData(object, key) {
39
+ const descriptor = getOwnPropertyDescriptor(object, key);
40
+ if (!descriptor?.enumerable || !hasOwn(descriptor, 'value')) {
41
+ throw new UnsupportedValueError('accessors and non-enumerable properties are unsupported');
42
+ }
43
+ return descriptor.value;
44
+ }
45
+ function recordKeys(object, budget) {
46
+ const keys = ownKeys(object);
47
+ if (keys.length > MAX_NODES)
48
+ throw new UnsupportedValueError('value exceeds the property limit');
49
+ return keys.map((key) => {
50
+ if (typeof key !== 'string')
51
+ throw new UnsupportedValueError('symbol properties are unsupported');
52
+ budget.addString(key);
53
+ return key;
54
+ });
55
+ }
56
+ function arrayLength(array) {
57
+ if (getPrototypeOf(array) !== arrayPrototype || array.length > MAX_NODES) {
58
+ throw new UnsupportedValueError('custom array prototypes and oversized arrays are unsupported');
59
+ }
60
+ for (const key of ownKeys(array)) {
61
+ if (key === 'length')
62
+ continue;
63
+ if (typeof key !== 'string' || !/^(?:0|[1-9]\d*)$/.test(key) || Number(key) >= array.length) {
64
+ throw new UnsupportedValueError('additional array properties are unsupported');
65
+ }
66
+ }
67
+ return array.length;
68
+ }
69
+ function encodeNumber(value) {
70
+ if (Object.is(value, -0))
71
+ return tag('-0');
72
+ if (Number.isNaN(value))
73
+ return tag('NaN');
74
+ if (!Number.isFinite(value))
75
+ return tag(value === Infinity ? 'Infinity' : '-Infinity');
76
+ return value;
77
+ }
78
+ export function encodeValue(value) {
79
+ const budget = new ValueBudget();
80
+ const seen = new WeakSet();
81
+ function encode(input, depth) {
82
+ budget.addNode(depth);
83
+ if (input === null || typeof input === 'boolean')
84
+ return input;
85
+ if (typeof input === 'number')
86
+ return encodeNumber(input);
87
+ if (typeof input === 'string') {
88
+ budget.addString(input);
89
+ return input;
90
+ }
91
+ if (typeof input === 'undefined')
92
+ return tag('undefined');
93
+ if (typeof input === 'bigint') {
94
+ const value = String(input);
95
+ budget.addString(value);
96
+ return { ...tag('bigint'), value };
97
+ }
98
+ if (typeof input !== 'object' || isProxy(input)) {
99
+ throw new UnsupportedValueError('functions, symbols, and proxies are unsupported');
100
+ }
101
+ if (seen.has(input))
102
+ throw new UnsupportedValueError('cyclic and shared references are unsupported');
103
+ seen.add(input);
104
+ if (isArray(input)) {
105
+ const length = arrayLength(input);
106
+ return Array.from({ length }, (_, index) => (hasOwn(input, index) ? encode(ownData(input, String(index)), depth + 1) : tag('hole')));
107
+ }
108
+ const prototype = getPrototypeOf(input);
109
+ if (prototype !== objectPrototype && prototype !== null) {
110
+ throw new UnsupportedValueError('custom object prototypes are unsupported');
111
+ }
112
+ const keys = recordKeys(input, budget);
113
+ if (prototype === null || keys.includes(tagKey)) {
114
+ return {
115
+ ...tag('record'), nullPrototype: prototype === null,
116
+ entries: keys.map((key) => [key, encode(ownData(input, key), depth + 1)]),
117
+ };
118
+ }
119
+ const output = {};
120
+ for (const key of keys)
121
+ defineValue(output, key, encode(ownData(input, key), depth + 1));
122
+ return output;
123
+ }
124
+ return encode(value, 0);
125
+ }
126
+ const MISSING = Symbol('array hole');
127
+ const scalarTags = new Map([
128
+ ['undefined', undefined], ['NaN', NaN], ['Infinity', Infinity], ['-Infinity', -Infinity], ['-0', -0],
129
+ ]);
130
+ function readWire(input, decode) {
131
+ const budget = new ValueBudget();
132
+ function visit(value, depth, inArray = false) {
133
+ budget.addNode(depth);
134
+ if (value === null || typeof value === 'boolean')
135
+ return value;
136
+ if (typeof value === 'string') {
137
+ budget.addString(value);
138
+ return value;
139
+ }
140
+ if (typeof value === 'number' && Number.isFinite(value))
141
+ return decode ? value : encodeNumber(value);
142
+ if (typeof value !== 'object' || isProxy(value))
143
+ throw new UnsupportedValueError('invalid encoded value');
144
+ if (isArray(value)) {
145
+ const length = arrayLength(value);
146
+ const output = new Array(length);
147
+ for (let index = 0; index < length; index++) {
148
+ const child = visit(ownData(value, String(index)), depth + 1, true);
149
+ if (child !== MISSING)
150
+ output[index] = child;
151
+ }
152
+ return output;
153
+ }
154
+ if (getPrototypeOf(value) !== objectPrototype && getPrototypeOf(value) !== null) {
155
+ throw new UnsupportedValueError('invalid encoded object');
156
+ }
157
+ const keys = recordKeys(value, budget);
158
+ if (!keys.includes(tagKey)) {
159
+ const output = {};
160
+ for (const key of keys)
161
+ defineValue(output, key, visit(ownData(value, key), depth + 1));
162
+ return output;
163
+ }
164
+ const name = ownData(value, tagKey);
165
+ if (typeof name === 'string' && keys.length === 1 && scalarTags.has(name)) {
166
+ return decode ? scalarTags.get(name) : tag(name);
167
+ }
168
+ if (name === 'hole' && keys.length === 1 && inArray)
169
+ return decode ? MISSING : tag(name);
170
+ if (name === 'bigint' && keys.length === 2 && keys.includes('value')) {
171
+ const digits = ownData(value, 'value');
172
+ if (typeof digits === 'string' && /^(?:0|-?[1-9]\d*)$/.test(digits)) {
173
+ budget.addString(digits);
174
+ return decode ? BigInt(digits) : { ...tag(name), value: digits };
175
+ }
176
+ }
177
+ if (name === 'record' && keys.length === 3 && keys.includes('entries') && keys.includes('nullPrototype')) {
178
+ const entries = ownData(value, 'entries');
179
+ const nullPrototype = ownData(value, 'nullPrototype');
180
+ if (typeof nullPrototype === 'boolean' && !isProxy(entries) && isArray(entries)) {
181
+ const length = arrayLength(entries);
182
+ const seen = new Set();
183
+ const record = nullPrototype ? create(null) : {};
184
+ const normalized = [];
185
+ for (let index = 0; index < length; index++) {
186
+ const entry = ownData(entries, String(index));
187
+ if (isProxy(entry) || !isArray(entry) || arrayLength(entry) !== 2) {
188
+ throw new UnsupportedValueError('invalid encoded record entry');
189
+ }
190
+ const key = ownData(entry, '0');
191
+ if (typeof key !== 'string' || seen.has(key))
192
+ throw new UnsupportedValueError('invalid encoded record key');
193
+ budget.addString(key);
194
+ seen.add(key);
195
+ const child = visit(ownData(entry, '1'), depth + 1);
196
+ if (decode)
197
+ defineValue(record, key, child);
198
+ else
199
+ normalized.push([key, child]);
200
+ }
201
+ if (decode)
202
+ return record;
203
+ if (nullPrototype || seen.has(tagKey))
204
+ return { ...tag(name), nullPrototype, entries: normalized };
205
+ return Object.fromEntries(normalized);
206
+ }
207
+ }
208
+ throw new UnsupportedValueError('invalid or misplaced encoded value tag');
209
+ }
210
+ return visit(input, 0);
211
+ }
212
+ export function normalizeWireValue(input) {
213
+ return readWire(input, false);
214
+ }
215
+ export function decodeValue(value) {
216
+ return readWire(value, true);
217
+ }
218
+ function isRecord(value) {
219
+ return value !== null && typeof value === 'object' && !isArray(value);
220
+ }
221
+ export function matchesValue(left, right, allowSubset) {
222
+ if (isArray(left)) {
223
+ return isArray(right) && left.length === right.length &&
224
+ left.every((value, index) => matchesValue(value, right[index], false));
225
+ }
226
+ if (!isRecord(left) || !isRecord(right))
227
+ return Object.is(left, right);
228
+ const keys = Object.keys(left);
229
+ if (!allowSubset || hasOwn(left, tagKey) || hasOwn(right, tagKey)) {
230
+ if (keys.length !== Object.keys(right).length)
231
+ return false;
232
+ allowSubset = false;
233
+ }
234
+ return keys.every((key) => hasOwn(right, key) && matchesValue(left[key], right[key], allowSubset));
235
+ }
236
+ export function matchesArguments(match, args) {
237
+ return match === undefined || matchesValue(match, args, true);
238
+ }
239
+ function errorProperty(error, key) {
240
+ let current = error;
241
+ for (let depth = 0; current !== null && depth <= MAX_DEPTH; depth++) {
242
+ if (isProxy(current))
243
+ throw new UnsupportedValueError('proxied error prototypes are unsupported');
244
+ const descriptor = getOwnPropertyDescriptor(current, key);
245
+ if (!descriptor) {
246
+ current = getPrototypeOf(current);
247
+ continue;
248
+ }
249
+ if (!hasOwn(descriptor, 'value'))
250
+ throw new UnsupportedValueError('error accessors are unsupported');
251
+ return descriptor.value;
252
+ }
253
+ return undefined;
254
+ }
255
+ export function encodeThrown(value) {
256
+ if (isProxy(value))
257
+ throw new UnsupportedValueError('proxied exceptions are unsupported');
258
+ if (!isNativeError(value))
259
+ return encodeValue(value);
260
+ let name = errorProperty(value, 'name');
261
+ if (name === 'Error') {
262
+ const constructor = errorProperty(value, 'constructor');
263
+ if (typeof constructor === 'function' && !isProxy(constructor)) {
264
+ name = getOwnPropertyDescriptor(constructor, 'name')?.value || name;
265
+ }
266
+ }
267
+ const message = errorProperty(value, 'message');
268
+ const code = errorProperty(value, 'code');
269
+ if (typeof name !== 'string' || typeof message !== 'string') {
270
+ throw new UnsupportedValueError('non-string error names and messages are unsupported');
271
+ }
272
+ return encodeValue({ name, message, ...(typeof code === 'string' || typeof code === 'number' ? { code } : {}) });
273
+ }
274
+ //# sourceMappingURL=values.js.map
@@ -0,0 +1 @@
1
+ {"version":3,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AI,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;YAC/D,IAAI,GAAG,wBAAwB,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,KAAK,IAAI,IAAI,CAAC;QACtE,CAAC;IACH,CAAC;IACD,MAAM,OAAO,GAAG,aAAa,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAChD,MAAM,IAAI,GAAG,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC1C,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC5D,MAAM,IAAI,qBAAqB,CAAC,qDAAqD,CAAC,CAAC;IACzF,CAAC;IACD,OAAO,WAAW,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AACnH,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const toolVersion: string;
@@ -0,0 +1,3 @@
1
+ import { readFileSync } from 'node:fs';
2
+ export const toolVersion = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
3
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,CAAC,MAAM,WAAW,GAAI,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,iBAAiB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAyB,CAAC,OAAO,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
package/dist/worker.js ADDED
@@ -0,0 +1,338 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { createHash } from 'node:crypto';
3
+ import { lstatSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
4
+ import { isBuiltin, registerHooks } from 'node:module';
5
+ import { createConnection } from 'node:net';
6
+ import { dirname, extname, isAbsolute, relative, resolve, sep } from 'node:path';
7
+ import runtimeProcess from 'node:process';
8
+ import { setImmediate as waitForTurn } from 'node:timers/promises';
9
+ import { fileURLToPath, pathToFileURL } from 'node:url';
10
+ import { Worker } from 'node:worker_threads';
11
+ import { createEffects } from './effects.js';
12
+ import { packageFileFormat, stagedPackageFile } from './package-resolution.js';
13
+ import { inspectorIsRevoked, startCoverage } from './runtime-coverage.js';
14
+ import { decodeValue, encodeThrown, encodeValue } from './values.js';
15
+ const safeBuiltins = new Set(['assert', 'assert/strict', 'buffer', 'path', 'path/posix', 'path/win32', 'querystring', 'string_decoder', 'url', 'util', 'util/types']);
16
+ const virtualProcess = 'behavguard:process';
17
+ const logicalRoot = resolve(sep, '__behavguard_snapshot__');
18
+ const factoryKey = 'behavguard.runtime.prisma';
19
+ const maxEvents = 1_000;
20
+ const maxMessageBytes = 256 * 1024;
21
+ const send = runtimeProcess.send.bind(runtimeProcess);
22
+ const stringify = JSON.stringify;
23
+ const hasOwn = Object.hasOwn;
24
+ async function isDenied(operation, denialCode = 'ERR_ACCESS_DENIED') {
25
+ try {
26
+ await operation();
27
+ return false;
28
+ }
29
+ catch (error) {
30
+ return error?.code === denialCode;
31
+ }
32
+ }
33
+ async function probe({ outsideFile, outsideWrite }) {
34
+ const checks = {
35
+ network: await isDenied(() => new Promise((resolveConnection, reject) => {
36
+ createConnection({ host: '127.0.0.1', port: 1 })
37
+ .once('connect', function () { this.destroy(); resolveConnection(undefined); })
38
+ .once('error', reject);
39
+ })),
40
+ read: await isDenied(() => readFileSync(outsideFile)),
41
+ write: await isDenied(() => writeFileSync(outsideWrite, 'synthetic probe')),
42
+ subprocess: await isDenied(() => {
43
+ const child = spawnSync(runtimeProcess.execPath, ['--version']);
44
+ if (child.error)
45
+ throw child.error;
46
+ }),
47
+ native: await isDenied(() => runtimeProcess.dlopen({ exports: {} }, outsideFile), 'ERR_DLOPEN_DISABLED'),
48
+ worker: await isDenied(() => {
49
+ const worker = new Worker('0', { eval: true });
50
+ return worker.terminate();
51
+ }),
52
+ inspectorRevoked: inspectorIsRevoked(),
53
+ sanitizedEnvironment: runtimeProcess.env.NODE_OPTIONS === undefined && runtimeProcess.env.HOME === undefined,
54
+ };
55
+ send({ type: 'probe', nodeVersion: runtimeProcess.version, checks });
56
+ }
57
+ function underRoot(root, file) {
58
+ const path = relative(root, file);
59
+ if (path === '..' || path.startsWith(`..${sep}`) || !path || isAbsolute(path))
60
+ return undefined;
61
+ return path.split(sep).join('/');
62
+ }
63
+ function createTimerTracker() {
64
+ const timers = new Set();
65
+ const original = {
66
+ setTimeout: globalThis.setTimeout,
67
+ clearTimeout: globalThis.clearTimeout,
68
+ setInterval: globalThis.setInterval,
69
+ clearInterval: globalThis.clearInterval,
70
+ setImmediate: globalThis.setImmediate,
71
+ clearImmediate: globalThis.clearImmediate,
72
+ };
73
+ globalThis.setTimeout = ((callback, delay, ...args) => {
74
+ const handle = original.setTimeout(function (...values) {
75
+ timers.delete(handle);
76
+ return callback.apply(this, values);
77
+ }, delay, ...args);
78
+ timers.add(handle);
79
+ return handle;
80
+ });
81
+ globalThis.setInterval = ((callback, delay, ...args) => {
82
+ const handle = original.setInterval(callback, delay, ...args);
83
+ timers.add(handle);
84
+ return handle;
85
+ });
86
+ globalThis.setImmediate = ((callback, ...args) => {
87
+ const handle = original.setImmediate(function (...values) {
88
+ timers.delete(handle);
89
+ return callback.apply(this, values);
90
+ }, ...args);
91
+ timers.add(handle);
92
+ return handle;
93
+ });
94
+ globalThis.clearTimeout = (handle) => { timers.delete(handle); original.clearTimeout(handle); };
95
+ globalThis.clearInterval = (handle) => { timers.delete(handle); original.clearInterval(handle); };
96
+ globalThis.clearImmediate = (handle) => { timers.delete(handle); original.clearImmediate(handle); };
97
+ return () => timers.size;
98
+ }
99
+ async function execute(input, coverage) {
100
+ let stage = 'setup';
101
+ let gap;
102
+ let eventIndex = 0;
103
+ function reportGap(code, detail) {
104
+ if (gap)
105
+ return;
106
+ gap = { code, stage, eventIndex, ...(detail ? { detail } : {}) };
107
+ send({ type: 'gap', gap });
108
+ }
109
+ function fail(code, detail) {
110
+ reportGap(code, detail);
111
+ const error = new Error('BehavGuard restricted this operation');
112
+ error.name = 'BehavGuardRuntimeError';
113
+ throw error;
114
+ }
115
+ const effects = createEffects({
116
+ mocks: input.mocks,
117
+ fail,
118
+ emit(event) {
119
+ if (gap)
120
+ return;
121
+ if (eventIndex >= maxEvents || Buffer.byteLength(stringify(event)) > maxMessageBytes)
122
+ fail('runtime_output_limit');
123
+ ++eventIndex;
124
+ send({ type: 'event', event });
125
+ },
126
+ });
127
+ const root = input.root;
128
+ const projectManifest = Object.fromEntries(Object.entries(input.manifest).filter(([path]) => !stagedPackageFile(path)));
129
+ // Expose the same repository-relative file identity to both sides while reading only verified staged bytes.
130
+ const entry = pathToFileURL(resolve(logicalRoot, input.entry.path)).href;
131
+ const virtualModules = new Map();
132
+ const mappings = new Map();
133
+ for (const [name, exports] of Object.entries(input.prismaModules ?? {})) {
134
+ const url = `behavguard:prisma:${mappings.size}`;
135
+ mappings.set(name, url);
136
+ const factory = `globalThis[Symbol.for(${stringify(factoryKey)})]`;
137
+ virtualModules.set(url, exports.map((exportName, index) => {
138
+ const binding = `_client${index}`;
139
+ const expression = exportName === 'PrismaClient'
140
+ ? `class PrismaClient { constructor() { return ${factory}(); } }`
141
+ : `${factory}()`;
142
+ return `const ${binding} = ${expression}; export { ${binding} as ${stringify(exportName)} };`;
143
+ }).join('\n'));
144
+ }
145
+ const environment = Object.freeze({ NODE_ENV: runtimeProcess.env.NODE_ENV, TZ: runtimeProcess.env.TZ, LANG: runtimeProcess.env.LANG });
146
+ const exposedProcess = new Proxy(Object.freeze({ env: environment }), {
147
+ get(target, name) {
148
+ if (name === 'env')
149
+ return target.env;
150
+ if (typeof name === 'symbol')
151
+ return undefined;
152
+ return fail('runtime_api_denied', 'process');
153
+ },
154
+ });
155
+ virtualModules.set(virtualProcess, 'const env = globalThis.process.env; export { env }; export default globalThis.process;');
156
+ Object.defineProperty(globalThis, 'process', { value: exposedProcess, configurable: false, writable: false });
157
+ Object.defineProperty(globalThis, Symbol.for(factoryKey), { value: effects.createClient });
158
+ Object.defineProperty(globalThis, 'fetch', { value: effects.fetch, configurable: false, writable: false });
159
+ for (const name of ['WebSocket', 'EventSource', 'Worker']) {
160
+ if (Object.getOwnPropertyDescriptor(globalThis, name)?.configurable !== false) {
161
+ Object.defineProperty(globalThis, name, { get: () => fail('runtime_api_denied', name) });
162
+ }
163
+ else {
164
+ fail('runtime_api_guard_unavailable', name);
165
+ }
166
+ }
167
+ const pendingTimers = createTimerTracker();
168
+ const hasSafeBuiltin = safeBuiltins.has.bind(safeBuiltins);
169
+ const getPrismaModule = mappings.get.bind(mappings);
170
+ const getVirtualModule = virtualModules.get.bind(virtualModules);
171
+ function readArtifact(path) {
172
+ if (!hasOwn(input.manifest, path))
173
+ return fail('artifact_unverified');
174
+ const file = resolve(root, path);
175
+ let source;
176
+ try {
177
+ if (realpathSync(file) !== file || !lstatSync(file).isFile())
178
+ return fail('artifact_unverified');
179
+ source = readFileSync(file);
180
+ }
181
+ catch {
182
+ return fail('artifact_unverified');
183
+ }
184
+ if (createHash('sha256').update(source).digest('hex') !== input.manifest[path])
185
+ return fail('artifact_unverified');
186
+ return source;
187
+ }
188
+ registerHooks({
189
+ resolve(specifier, context, nextResolve) {
190
+ const builtin = specifier.replace(/^node:/u, '');
191
+ if (hasSafeBuiltin(builtin))
192
+ return nextResolve(`node:${builtin}`, context);
193
+ if (builtin === 'process')
194
+ return { url: virtualProcess, shortCircuit: true };
195
+ if (specifier.startsWith('node:') || isBuiltin(specifier))
196
+ return fail('runtime_module_denied');
197
+ if (specifier === entry && context.parentURL === import.meta.url)
198
+ return { url: entry, shortCircuit: true };
199
+ if (!context.parentURL?.startsWith('file:'))
200
+ return fail('runtime_module_denied');
201
+ const parent = fileURLToPath(context.parentURL);
202
+ const parentPath = underRoot(logicalRoot, parent);
203
+ if (!parentPath || !hasOwn(input.manifest, parentPath))
204
+ return fail('runtime_module_denied');
205
+ const scope = stagedPackageFile(parentPath)?.name ?? '';
206
+ if (!scope) {
207
+ const mock = getPrismaModule(specifier);
208
+ if (mock)
209
+ return { url: mock, shortCircuit: true };
210
+ }
211
+ if (!/^(?:\.\/|\.\.\/)/u.test(specifier)) {
212
+ const imports = input.packageImports;
213
+ const permitted = imports && hasOwn(imports, scope) ? imports[scope] : undefined;
214
+ if (!permitted || !hasOwn(permitted, specifier))
215
+ return fail('runtime_module_denied');
216
+ return { url: pathToFileURL(resolve(logicalRoot, permitted[specifier])).href, shortCircuit: true };
217
+ }
218
+ const candidate = resolve(dirname(parent), specifier);
219
+ const path = underRoot(logicalRoot, candidate);
220
+ if (!path)
221
+ return fail('artifact_unverified');
222
+ if ((stagedPackageFile(path)?.name ?? '') !== scope)
223
+ return fail('runtime_module_denied');
224
+ if (hasOwn(input.manifest, path))
225
+ return { url: pathToFileURL(candidate).href, shortCircuit: true };
226
+ if (scope || extname(path))
227
+ return fail('artifact_unverified');
228
+ const matches = [`${path}.js`, `${path}.mjs`, `${path}/index.js`, `${path}/index.mjs`]
229
+ .filter((name) => hasOwn(input.manifest, name));
230
+ if (matches.length > 1)
231
+ return fail('runtime_module_ambiguous');
232
+ if (matches.length === 0)
233
+ return fail('artifact_unverified');
234
+ return { url: pathToFileURL(resolve(logicalRoot, matches[0])).href, shortCircuit: true };
235
+ },
236
+ load(url, context, nextLoad) {
237
+ if (url.startsWith('node:'))
238
+ return nextLoad(url, context);
239
+ const mock = getVirtualModule(url);
240
+ if (mock !== undefined)
241
+ return { format: 'module', source: mock, shortCircuit: true };
242
+ if (!url.startsWith('file:'))
243
+ return fail('runtime_module_denied');
244
+ const path = underRoot(logicalRoot, fileURLToPath(url));
245
+ if (!path)
246
+ return fail('artifact_unverified');
247
+ const source = readArtifact(path);
248
+ const pkg = stagedPackageFile(path);
249
+ if (pkg) {
250
+ const format = packageFileFormat(pkg.file, (metadata) => {
251
+ const name = `node_modules/${pkg.name}/${metadata}`;
252
+ return hasOwn(input.manifest, name) ? readArtifact(name) : undefined;
253
+ });
254
+ if (!format)
255
+ return fail('runtime_format_unsupported');
256
+ return { format, source, shortCircuit: true };
257
+ }
258
+ if (path.endsWith('.json'))
259
+ return { format: 'json', source, shortCircuit: true };
260
+ if (!/\.m?js$/u.test(path))
261
+ return fail('runtime_format_unsupported');
262
+ return { format: 'module', source, shortCircuit: true };
263
+ },
264
+ });
265
+ runtimeProcess.on('unhandledRejection', () => reportGap('runtime_unhandled_rejection'));
266
+ runtimeProcess.on('uncaughtException', () => reportGap('runtime_uncaught_exception'));
267
+ stage = 'import';
268
+ let target;
269
+ try {
270
+ const module = await import(entry);
271
+ target = module[input.entry.exportName];
272
+ }
273
+ catch {
274
+ reportGap('runtime_import_failed');
275
+ return;
276
+ }
277
+ if (gap)
278
+ return;
279
+ if (typeof target !== 'function')
280
+ return fail('runtime_export_unsupported');
281
+ stage = 'invoke';
282
+ const args = input.args.map(decodeValue);
283
+ let result;
284
+ let didThrow = false;
285
+ try {
286
+ result = await Reflect.apply(target, undefined, args);
287
+ }
288
+ catch (error) {
289
+ result = error;
290
+ didThrow = true;
291
+ }
292
+ await waitForTurn();
293
+ if (gap)
294
+ return;
295
+ if (pendingTimers() || effects.pending())
296
+ return fail('runtime_pending_effects');
297
+ let outcome;
298
+ let mutatedArgs;
299
+ try {
300
+ outcome = didThrow ? { kind: 'throw', value: encodeThrown(result) } : { kind: 'return', value: encodeValue(result) };
301
+ mutatedArgs = encodeValue(args);
302
+ }
303
+ catch {
304
+ return fail('runtime_value_unsupported');
305
+ }
306
+ let ranges;
307
+ try {
308
+ ranges = await coverage.ranges(logicalRoot, projectManifest);
309
+ }
310
+ catch { /* unavailable coverage is left unspecified */ }
311
+ const message = { type: 'result', outcome, mutatedArgs };
312
+ if (Buffer.byteLength(stringify(message)) > maxMessageBytes)
313
+ return fail('runtime_output_limit');
314
+ if (ranges && Buffer.byteLength(stringify({ ...message, coverage: ranges })) <= maxMessageBytes)
315
+ message.coverage = ranges;
316
+ send(message);
317
+ }
318
+ const input = await new Promise((resolveInput) => {
319
+ runtimeProcess.once('message', resolveInput);
320
+ });
321
+ let coverage;
322
+ try {
323
+ coverage = await startCoverage();
324
+ if (runtimeProcess.argv[2] === 'probe')
325
+ await probe(input);
326
+ else
327
+ await execute(input, coverage);
328
+ }
329
+ catch (error) {
330
+ if (!(error instanceof Error) || error.name !== 'BehavGuardRuntimeError') {
331
+ send({ type: 'gap', gap: { code: coverage ? 'runtime_worker_failed' : 'runtime_coverage_setup_failed', stage: 'worker' } });
332
+ }
333
+ }
334
+ finally {
335
+ await coverage?.close();
336
+ send({ type: 'done' }, undefined, undefined, () => runtimeProcess.disconnect?.());
337
+ }
338
+ //# sourceMappingURL=worker.js.map