claude-spotter 1.4.21 → 1.4.23

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.
@@ -0,0 +1,51 @@
1
+ import { hasRuntimeErrorReceipt, observeRuntimeError } from './runtime-error-store.mjs';
2
+
3
+ async function main() {
4
+ if (process.env.SPOTTER_RUNTIME_ERROR_WORKER !== '1' || process.argv.length !== 5) process.exit(2);
5
+ const action = process.argv[2];
6
+ const value = process.argv[3];
7
+ if (action !== 'observe' && action !== 'receipt') process.exit(2);
8
+ let options;
9
+ try {
10
+ const encoded = process.argv[4];
11
+ if (!/^[A-Za-z0-9_-]+$/.test(encoded) || encoded.length > 16_384) process.exit(2);
12
+ options = JSON.parse(Buffer.from(encoded, 'base64url').toString('utf8'));
13
+ } catch {
14
+ process.exit(2);
15
+ }
16
+ const allowed = action === 'observe'
17
+ ? new Set(['configPath', 'storePath', 'productVersion', 'platform', 'arch', 'beforeOpenDelayMs', 'observationId'])
18
+ : new Set(['configPath', 'storePath', 'productVersion', 'platform', 'arch', 'observationId', 'expectedFingerprint', 'waitMs']);
19
+ const required = new Set(['configPath', 'storePath', 'productVersion', 'platform', 'arch', 'observationId']);
20
+ if (!options || typeof options !== 'object' || Array.isArray(options)
21
+ || Object.keys(options).some((key) => !allowed.has(key))
22
+ || [...required].some((key) => !Object.hasOwn(options, key))
23
+ || (options.configPath !== null && (typeof options.configPath !== 'string' || options.configPath.length > 4_096))
24
+ || typeof options.storePath !== 'string' || options.storePath.length < 1 || options.storePath.length > 4_096
25
+ || typeof options.productVersion !== 'string' || options.productVersion.length < 1 || options.productVersion.length > 64
26
+ || typeof options.platform !== 'string' || !/^[a-z0-9_-]{1,32}$/.test(options.platform)
27
+ || typeof options.arch !== 'string' || !/^[A-Za-z0-9_-]{1,32}$/.test(options.arch)
28
+ || typeof options.observationId !== 'string' || !/^[a-f0-9]{32}$/.test(options.observationId)
29
+ || (action === 'receipt' && (typeof options.expectedFingerprint !== 'string'
30
+ || !/^[a-f0-9]{64}$/.test(options.expectedFingerprint)
31
+ || !Number.isSafeInteger(options.waitMs) || options.waitMs < 10 || options.waitMs > 10_000))
32
+ || ('beforeOpenDelayMs' in options
33
+ && (!Number.isSafeInteger(options.beforeOpenDelayMs) || options.beforeOpenDelayMs < 0 || options.beforeOpenDelayMs > 10_000))) process.exit(2);
34
+ try {
35
+ if (action === 'receipt') {
36
+ if (value !== options.observationId) process.exit(2);
37
+ const deadline = Date.now() + options.waitMs;
38
+ do {
39
+ if (await hasRuntimeErrorReceipt(value, options.expectedFingerprint, options)) process.exit(0);
40
+ await new Promise((resolve) => setTimeout(resolve, 25));
41
+ } while (Date.now() < deadline);
42
+ process.exit(11);
43
+ }
44
+ const result = await observeRuntimeError(value, options);
45
+ process.exit(result.collected ? 0 : 10);
46
+ } catch {
47
+ process.exit(1);
48
+ }
49
+ }
50
+
51
+ main();