@haystackeditor/cli 0.15.25 → 0.15.27

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 (51) hide show
  1. package/README.md +39 -3
  2. package/dist/assets/hooks/package-lock.json +598 -0
  3. package/dist/assets/skills/map-cloud-verifier-universe/SKILL.md +2051 -0
  4. package/dist/assets/skills/map-cloud-verifier-universe/agents/openai.yaml +4 -0
  5. package/dist/assets/skills/map-cloud-verifier-universe/references/output-contract.md +3411 -0
  6. package/dist/assets/telemetry/browser-runtime.js +861 -0
  7. package/dist/assets/telemetry/runtime.cjs +1509 -0
  8. package/dist/commands/cloud-verifier-behaviors.d.ts +27 -0
  9. package/dist/commands/cloud-verifier-behaviors.js +218 -0
  10. package/dist/commands/cloud-verifier-data-store-census.d.ts +47 -0
  11. package/dist/commands/cloud-verifier-data-store-census.js +539 -0
  12. package/dist/commands/cloud-verifier-data-store-drift.d.ts +42 -0
  13. package/dist/commands/cloud-verifier-data-store-drift.js +158 -0
  14. package/dist/commands/cloud-verifier-identity-census.d.ts +88 -0
  15. package/dist/commands/cloud-verifier-identity-census.js +4057 -0
  16. package/dist/commands/cloud-verifier-materialization.d.ts +16 -0
  17. package/dist/commands/cloud-verifier-materialization.js +704 -0
  18. package/dist/commands/cloud-verifier-pascal-selector-census.d.ts +29 -0
  19. package/dist/commands/cloud-verifier-pascal-selector-census.js +1382 -0
  20. package/dist/commands/cloud-verifier-python-manifest-selector-census.d.ts +27 -0
  21. package/dist/commands/cloud-verifier-python-manifest-selector-census.js +2015 -0
  22. package/dist/commands/cloud-verifier-specialized-operational-census.d.ts +51 -0
  23. package/dist/commands/cloud-verifier-specialized-operational-census.js +11432 -0
  24. package/dist/commands/cloud-verifier-universe.d.ts +31 -0
  25. package/dist/commands/cloud-verifier-universe.js +10178 -0
  26. package/dist/commands/design-verify.d.ts +23 -0
  27. package/dist/commands/design-verify.js +142 -0
  28. package/dist/commands/hooks.js +2 -2
  29. package/dist/commands/prepare-universe-review.d.ts +115 -0
  30. package/dist/commands/prepare-universe-review.js +1092 -0
  31. package/dist/commands/production-source-deny-policy.d.ts +15 -0
  32. package/dist/commands/production-source-deny-policy.js +100 -0
  33. package/dist/commands/scaffold-provisional-universe.d.ts +468 -0
  34. package/dist/commands/scaffold-provisional-universe.js +808 -0
  35. package/dist/commands/schema-cmd.js +32 -0
  36. package/dist/commands/skills.d.ts +2 -2
  37. package/dist/commands/skills.js +415 -47
  38. package/dist/commands/telemetry.d.ts +53 -0
  39. package/dist/commands/telemetry.js +832 -0
  40. package/dist/commands/verify-hosted-reproducibility.d.ts +6 -2
  41. package/dist/commands/verify-hosted-reproducibility.js +65 -20
  42. package/dist/index.js +142 -13
  43. package/dist/triage/runner.js +7 -6
  44. package/dist/utils/design-verifier-api.d.ts +129 -0
  45. package/dist/utils/design-verifier-api.js +175 -0
  46. package/dist/utils/design-verifier-result.d.ts +52 -0
  47. package/dist/utils/design-verifier-result.js +299 -0
  48. package/dist/utils/haystack-api.d.ts +2 -0
  49. package/dist/utils/haystack-api.js +10 -3
  50. package/dist/utils/hooks.js +2 -1
  51. package/package.json +7 -2
@@ -0,0 +1,861 @@
1
+ /*
2
+ * Dependency-free browser half of Haystack's experimental web/Node behavior
3
+ * atlas. A build transform supplies an exact manifest; this runtime records
4
+ * only manifest-approved enumerated outcomes and propagates a random trace ID
5
+ * to same-origin requests. It never reads DOM text, request bodies, headers,
6
+ * cookies, storage values, or arbitrary object properties.
7
+ */
8
+ var __haystackWebAtlasModuleApi = (function installHaystackWebAtlas(host) {
9
+ 'use strict';
10
+
11
+ // Never invoke an application-owned accessor merely by checking our optional
12
+ // namespace. Only a plain own data property can represent an earlier install.
13
+ try {
14
+ var existingDescriptor = Object.getOwnPropertyDescriptor(host, '__haystackWebAtlas');
15
+ if (existingDescriptor) {
16
+ return null;
17
+ }
18
+ } catch (_) { return null; }
19
+
20
+ var MAX_EVENTS = 128;
21
+ var TRACE_HEADER = 'x-haystack-trace-id';
22
+ var ACTION_HEADER = 'x-haystack-action-id';
23
+ var COHORT_HEADER = 'x-haystack-cohort';
24
+ var PARENT_EVENT_HEADER = 'x-haystack-parent-event-id';
25
+ var REQUEST_SITE_HEADER = 'x-haystack-request-site-id';
26
+ var nativeFunctionToString = Function.prototype.toString;
27
+ var nativeGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
28
+ var nativeGetPrototypeOf = Object.getPrototypeOf;
29
+ var nativeHasOwnProperty = Object.prototype.hasOwnProperty;
30
+ var nativeReflectApply = Reflect.apply.bind(Reflect);
31
+ var nativeReflectConstruct = Reflect.construct.bind(Reflect);
32
+ function safeHostData(name) {
33
+ try {
34
+ var descriptor = nativeGetOwnPropertyDescriptor(host, name);
35
+ return descriptor && nativeReflectApply(nativeHasOwnProperty, descriptor, ['value'])
36
+ ? descriptor.value
37
+ : undefined;
38
+ } catch (_) { return undefined; }
39
+ }
40
+ var nativeFetchFunction = safeHostData('fetch');
41
+ nativeFetchFunction = typeof nativeFetchFunction === 'function' ? nativeFetchFunction : null;
42
+ var nativeFetch = nativeFetchFunction ? function () {
43
+ return nativeReflectApply(nativeFetchFunction, host, arguments);
44
+ } : null;
45
+ var initialFetchLooksNative = false;
46
+ try {
47
+ initialFetchLooksNative = !!nativeFetchFunction &&
48
+ nativeReflectApply(nativeFunctionToString, nativeFetchFunction, []).indexOf('[native code]') !== -1;
49
+ } catch (_) { initialFetchLooksNative = false; }
50
+ var nativeRandomValues = null;
51
+ var nativeStringify = JSON.stringify.bind(JSON);
52
+ var nativeBeacon = null;
53
+ var nativeAddEventListener = null;
54
+ var hostSetTimeout = safeHostData('setTimeout');
55
+ var nativeSetTimeout = nativeLooking(hostSetTimeout) ? function () {
56
+ return nativeReflectApply(hostSetTimeout, host, arguments);
57
+ } : null;
58
+ var hostPromise = safeHostData('Promise');
59
+ var promisePrototype = nativeLooking(hostPromise) ? safeNativeMember(hostPromise, 'prototype') : null;
60
+ var promiseThen = promisePrototype ? safeNativeMember(promisePrototype, 'then') : null;
61
+ var nativePromiseThen = nativeLooking(promiseThen) ? promiseThen : null;
62
+ var promiseReject = nativeLooking(hostPromise) ? safeNativeMember(hostPromise, 'reject') : null;
63
+ var nativePromiseReject = nativeLooking(promiseReject) ? promiseReject : null;
64
+ var nativeLocationHref = null;
65
+ var nativeLocationOrigin = null;
66
+ var nativeUrlConstructor = null;
67
+ var nativeUrlCanParse = null;
68
+ var nativeRequestConstructor = null;
69
+ var nativeHeadersConstructor = null;
70
+ var nativeUrlHrefGetter = null;
71
+ var nativeRequestHeadersGetter = null;
72
+ var nativeHeadersHas = null;
73
+ var nativeHeadersGet = null;
74
+ var nativeHeadersSet = null;
75
+ var nativeResponseHeadersGetter = null;
76
+ var nativeResponseOkGetter = null;
77
+ var platformCapabilitiesAcquired = false;
78
+ var pagehideInstalled = false;
79
+ var nativeArrayIsArray = Array.isArray;
80
+ var active = null;
81
+ var recorderDisabled = false;
82
+ var runtimeActions = Object.create(null);
83
+ var runtimeSites = Object.create(null);
84
+ var assignedCohort = null;
85
+ var assignedCohortCount = null;
86
+ var configuredManifest = null;
87
+ var configuredEndpoint = null;
88
+ var configuredCohort = null;
89
+ var configuredPlatformFetch = false;
90
+ var fixedOutcomes = Object.freeze({
91
+ started: true, received: true, sent: true, success: true, error: true,
92
+ 'network:error': true, 'boolean:true': true, 'boolean:false': true,
93
+ 'http:2xx': true, 'http:3xx': true, 'http:4xx': true, 'http:5xx': true,
94
+ 'shape:null': true, 'shape:undefined': true, 'shape:boolean': true,
95
+ 'shape:number': true, 'shape:string': true, 'shape:array': true,
96
+ 'shape:object': true, 'shape:uninspectable': true,
97
+ });
98
+
99
+ function failOpen() {
100
+ // Deliberately silent in the page. Delivery/coverage omissions are carried
101
+ // in successful records; recorder failures must never affect the app.
102
+ }
103
+
104
+ function ownDataValue(name) {
105
+ return safeHostData(name);
106
+ }
107
+
108
+ function nativeLooking(value) {
109
+ try {
110
+ return typeof value === 'function' &&
111
+ nativeReflectApply(nativeFunctionToString, value, []).indexOf('[native code]') !== -1;
112
+ } catch (_) { return false; }
113
+ }
114
+
115
+ function safePlatformValue(name) {
116
+ try {
117
+ var cursor = host;
118
+ for (var depth = 0; cursor && depth < 12; depth++) {
119
+ var descriptor = nativeGetOwnPropertyDescriptor(cursor, name);
120
+ if (descriptor) {
121
+ if (nativeReflectApply(nativeHasOwnProperty, descriptor, ['value'])) return descriptor.value;
122
+ if (!nativeLooking(descriptor.get)) return undefined;
123
+ return nativeReflectApply(descriptor.get, host, []);
124
+ }
125
+ cursor = nativeGetPrototypeOf(cursor);
126
+ }
127
+ } catch (_) { return undefined; }
128
+ return undefined;
129
+ }
130
+
131
+ function safePlatformAccessorValue(name) {
132
+ try {
133
+ var cursor = host;
134
+ for (var depth = 0; cursor && depth < 12; depth++) {
135
+ var descriptor = nativeGetOwnPropertyDescriptor(cursor, name);
136
+ if (descriptor) {
137
+ if (nativeReflectApply(nativeHasOwnProperty, descriptor, ['value']) || !nativeLooking(descriptor.get)) return undefined;
138
+ return nativeReflectApply(descriptor.get, host, []);
139
+ }
140
+ cursor = nativeGetPrototypeOf(cursor);
141
+ }
142
+ } catch (_) { return undefined; }
143
+ return undefined;
144
+ }
145
+
146
+ function safeNativeMember(receiver, name) {
147
+ try {
148
+ var cursor = receiver;
149
+ for (var depth = 0; cursor && depth < 12; depth++) {
150
+ var descriptor = nativeGetOwnPropertyDescriptor(cursor, name);
151
+ if (descriptor) {
152
+ if (nativeReflectApply(nativeHasOwnProperty, descriptor, ['value'])) return descriptor.value;
153
+ if (!nativeLooking(descriptor.get)) return undefined;
154
+ return nativeReflectApply(descriptor.get, receiver, []);
155
+ }
156
+ cursor = nativeGetPrototypeOf(cursor);
157
+ }
158
+ } catch (_) { return undefined; }
159
+ return undefined;
160
+ }
161
+
162
+ function safeNativeDescriptor(receiver, name) {
163
+ try {
164
+ var cursor = receiver;
165
+ for (var depth = 0; cursor && depth < 12; depth++) {
166
+ var descriptor = nativeGetOwnPropertyDescriptor(cursor, name);
167
+ if (descriptor) {
168
+ if (nativeReflectApply(nativeHasOwnProperty, descriptor, ['value'])) {
169
+ return nativeLooking(descriptor.value) ? { value: descriptor.value } : null;
170
+ }
171
+ return nativeLooking(descriptor.get) ? { get: descriptor.get } : null;
172
+ }
173
+ cursor = nativeGetPrototypeOf(cursor);
174
+ }
175
+ } catch (_) { return null; }
176
+ return null;
177
+ }
178
+
179
+ function acquirePlatformCapabilities() {
180
+ if (platformCapabilitiesAcquired) return;
181
+ platformCapabilitiesAcquired = true;
182
+ var cryptoValue = safePlatformAccessorValue('crypto');
183
+ var randomValues = cryptoValue && safeNativeMember(cryptoValue, 'getRandomValues');
184
+ if (nativeLooking(randomValues)) {
185
+ nativeRandomValues = function (value) { return nativeReflectApply(randomValues, cryptoValue, [value]); };
186
+ }
187
+ var navigatorValue = safePlatformAccessorValue('navigator');
188
+ var beacon = navigatorValue && safeNativeMember(navigatorValue, 'sendBeacon');
189
+ if (nativeLooking(beacon)) {
190
+ nativeBeacon = function () { return nativeReflectApply(beacon, navigatorValue, arguments); };
191
+ }
192
+ var addEventListener = safePlatformValue('addEventListener');
193
+ if (nativeLooking(addEventListener)) {
194
+ nativeAddEventListener = function () { return nativeReflectApply(addEventListener, host, arguments); };
195
+ }
196
+ var locationValue = safePlatformAccessorValue('location');
197
+ try {
198
+ var href = locationValue && safeNativeMember(locationValue, 'href');
199
+ var origin = locationValue && safeNativeMember(locationValue, 'origin');
200
+ nativeLocationHref = typeof href === 'string' ? href : null;
201
+ nativeLocationOrigin = typeof origin === 'string' ? origin : null;
202
+ } catch (_) { nativeLocationHref = null; nativeLocationOrigin = null; }
203
+ var urlConstructor = safePlatformValue('URL');
204
+ var requestConstructor = safePlatformValue('Request');
205
+ var headersConstructor = safePlatformValue('Headers');
206
+ var responseConstructor = safePlatformValue('Response');
207
+ nativeUrlConstructor = nativeLooking(urlConstructor) ? urlConstructor : null;
208
+ nativeRequestConstructor = nativeLooking(requestConstructor) ? requestConstructor : null;
209
+ nativeHeadersConstructor = nativeLooking(headersConstructor) ? headersConstructor : null;
210
+ var urlPrototype = nativeUrlConstructor && safeNativeMember(nativeUrlConstructor, 'prototype');
211
+ var urlCanParse = nativeUrlConstructor && safeNativeMember(nativeUrlConstructor, 'canParse');
212
+ var requestPrototype = nativeRequestConstructor && safeNativeMember(nativeRequestConstructor, 'prototype');
213
+ var headersPrototype = nativeHeadersConstructor && safeNativeMember(nativeHeadersConstructor, 'prototype');
214
+ var responsePrototype = nativeLooking(responseConstructor) && safeNativeMember(responseConstructor, 'prototype');
215
+ var urlHref = urlPrototype && safeNativeDescriptor(urlPrototype, 'href');
216
+ var requestHeaders = requestPrototype && safeNativeDescriptor(requestPrototype, 'headers');
217
+ var headersHas = headersPrototype && safeNativeDescriptor(headersPrototype, 'has');
218
+ var headersGet = headersPrototype && safeNativeDescriptor(headersPrototype, 'get');
219
+ var headersSet = headersPrototype && safeNativeDescriptor(headersPrototype, 'set');
220
+ var responseHeaders = responsePrototype && safeNativeDescriptor(responsePrototype, 'headers');
221
+ var responseOk = responsePrototype && safeNativeDescriptor(responsePrototype, 'ok');
222
+ nativeUrlHrefGetter = urlHref && urlHref.get || null;
223
+ nativeUrlCanParse = nativeLooking(urlCanParse) ? urlCanParse : null;
224
+ nativeRequestHeadersGetter = requestHeaders && requestHeaders.get || null;
225
+ nativeHeadersHas = headersHas && headersHas.value || null;
226
+ nativeHeadersGet = headersGet && headersGet.value || null;
227
+ nativeHeadersSet = headersSet && headersSet.value || null;
228
+ nativeResponseHeadersGetter = responseHeaders && responseHeaders.get || null;
229
+ nativeResponseOkGetter = responseOk && responseOk.get || null;
230
+ }
231
+
232
+ function configure(config) {
233
+ try {
234
+ if (!config || !config.manifest || config.manifest.schemaVersion !== 'haystack-web-node-atlas-manifest-v1' ||
235
+ typeof config.endpoint !== 'string' || config.endpoint.length === 0) return false;
236
+ if (configuredManifest) return configuredManifest === config.manifest;
237
+ configuredManifest = config.manifest;
238
+ configuredEndpoint = config.endpoint;
239
+ configuredCohort = Number.isInteger(config.cohort) ? config.cohort : null;
240
+ configuredPlatformFetch = config.allowPlatformFetch === true;
241
+ if (config.allowPlatformCapabilities === true) acquirePlatformCapabilities();
242
+ if (!pagehideInstalled && nativeAddEventListener && nativeSetTimeout) {
243
+ nativeAddEventListener('pagehide', function () { try { endAction(); } catch (_) { failOpen(); } });
244
+ pagehideInstalled = true;
245
+ }
246
+ return true;
247
+ } catch (_) { return false; }
248
+ }
249
+
250
+ function trustedOutcome(value) {
251
+ if (typeof value !== 'string') return false;
252
+ if (fixedOutcomes[value] === true) return true;
253
+ if (value.slice(0, 8) !== 'variant:') return false;
254
+ var index = Number(value.slice(8));
255
+ return Number.isInteger(index) && index >= 0 && index < 32 && value === 'variant:' + index;
256
+ }
257
+
258
+ function randomTraceId() {
259
+ if (!nativeRandomValues) return null;
260
+ for (var attempt = 0; attempt < 2; attempt++) {
261
+ var bytes = new Uint8Array(16);
262
+ nativeRandomValues(bytes);
263
+ var value = '';
264
+ for (var index = 0; index < bytes.length; index++) value += bytes[index].toString(16).padStart(2, '0');
265
+ if (value !== '00000000000000000000000000000000') return value;
266
+ }
267
+ return null;
268
+ }
269
+
270
+ function traceparent(traceId) {
271
+ var spanId = traceId.slice(16);
272
+ if (spanId === '0000000000000000') spanId = traceId.slice(0, 16);
273
+ return '00-' + traceId + '-' + spanId + '-01';
274
+ }
275
+
276
+ function safeNodeResponseId(traceId, requestEventId, candidate) {
277
+ try {
278
+ var requestOrdinal = Number(requestEventId.slice(-4));
279
+ var prefix = 'node-' + traceId + '-';
280
+ if (!Number.isInteger(requestOrdinal) || requestOrdinal < 1 || requestOrdinal > MAX_EVENTS ||
281
+ typeof candidate !== 'string' || candidate.slice(0, prefix.length) !== prefix) return null;
282
+ var ordinalText = candidate.slice(prefix.length);
283
+ if (!/^[0-9]{4,5}$/.test(ordinalText)) return null;
284
+ var ordinal = Number(ordinalText);
285
+ var base = requestOrdinal * MAX_EVENTS;
286
+ return ordinal > base && ordinal <= base + MAX_EVENTS && candidate === prefix + String(ordinal).padStart(4, '0')
287
+ ? candidate
288
+ : null;
289
+ } catch (_) { return null; }
290
+ }
291
+
292
+ function manifest() {
293
+ var value = configuredManifest || ownDataValue('__HAYSTACK_WEB_ATLAS_MANIFEST__');
294
+ return value && value.schemaVersion === 'haystack-web-node-atlas-manifest-v1' ? value : null;
295
+ }
296
+
297
+ function platformFetchCorrelationAllowed() {
298
+ return configuredPlatformFetch || ownDataValue('__HAYSTACK_WEB_ATLAS_ALLOW_PLATFORM_FETCH__') === true;
299
+ }
300
+
301
+ function actionFor(actionId) {
302
+ if (runtimeActions[actionId]) return runtimeActions[actionId];
303
+ var value = manifest();
304
+ if (!value || !Array.isArray(value.actions)) return null;
305
+ for (var index = 0; index < value.actions.length; index++) {
306
+ if (value.actions[index] && value.actions[index].actionId === actionId) return value.actions[index];
307
+ }
308
+ return null;
309
+ }
310
+
311
+ function siteFor(siteId) {
312
+ if (runtimeSites[siteId]) return runtimeSites[siteId];
313
+ var value = manifest();
314
+ if (!value || !Array.isArray(value.sites)) return null;
315
+ for (var index = 0; index < value.sites.length; index++) {
316
+ if (value.sites[index] && value.sites[index].siteId === siteId) return value.sites[index];
317
+ }
318
+ return null;
319
+ }
320
+
321
+ function outcomesForKind(kind) {
322
+ if (kind === 'action-start') return ['started'];
323
+ if (kind === 'input-shape' || kind === 'output-shape') return [
324
+ 'shape:null', 'shape:undefined', 'shape:boolean', 'shape:number',
325
+ 'shape:string', 'shape:array', 'shape:object', 'shape:uninspectable',
326
+ ];
327
+ if (kind === 'condition') return ['boolean:false', 'boolean:true'];
328
+ if (kind === 'request') return ['sent'];
329
+ if (kind === 'response') return ['success', 'error', 'network:error'];
330
+ return [];
331
+ }
332
+
333
+ function runtimeSite(config, siteId, kind) {
334
+ if (typeof siteId !== 'string' || !/^site-[0-9a-f]{24}$/.test(siteId)) return null;
335
+ var outcomes = outcomesForKind(kind);
336
+ if (outcomes.length === 0) return null;
337
+ return {
338
+ siteId: siteId,
339
+ actionId: config.actionId,
340
+ surface: 'browser',
341
+ kind: kind,
342
+ allowedOutcomes: outcomes,
343
+ };
344
+ }
345
+
346
+ function registerAction(config) {
347
+ try {
348
+ if (nativeArrayIsArray(config)) {
349
+ if (config.length !== 7) return false;
350
+ var compactConditions = Object.create(null);
351
+ var compactFetches = Object.create(null);
352
+ var conditionPairs = config[5];
353
+ var fetchPairs = config[6];
354
+ if (!nativeArrayIsArray(conditionPairs) || !nativeArrayIsArray(fetchPairs) ||
355
+ conditionPairs.length > MAX_EVENTS || fetchPairs.length > MAX_EVENTS) return false;
356
+ for (var compactConditionIndex = 0; compactConditionIndex < conditionPairs.length; compactConditionIndex++) {
357
+ var conditionPair = conditionPairs[compactConditionIndex];
358
+ if (!nativeArrayIsArray(conditionPair) || conditionPair.length !== 2 ||
359
+ typeof conditionPair[0] !== 'string' || !/^c-[0-9a-f]{16}$/.test(conditionPair[0]) ||
360
+ compactConditions[conditionPair[0]] !== undefined) return false;
361
+ compactConditions[conditionPair[0]] = conditionPair[1];
362
+ }
363
+ for (var compactFetchIndex = 0; compactFetchIndex < fetchPairs.length; compactFetchIndex++) {
364
+ var fetchPair = fetchPairs[compactFetchIndex];
365
+ if (!nativeArrayIsArray(fetchPair) || fetchPair.length !== 3 ||
366
+ typeof fetchPair[0] !== 'string' || !/^f-[0-9a-f]{16}$/.test(fetchPair[0]) ||
367
+ compactFetches[fetchPair[0]] !== undefined) return false;
368
+ compactFetches[fetchPair[0]] = { requestSiteId: fetchPair[1], responseSiteId: fetchPair[2] };
369
+ }
370
+ config = {
371
+ actionId: config[0], cohortIndex: config[1], actionSiteId: config[2],
372
+ inputSiteId: config[3], outputSiteId: config[4],
373
+ conditionSites: compactConditions, fetchSites: compactFetches,
374
+ };
375
+ }
376
+ if (!config || typeof config.actionId !== 'string' || !/^action-[0-9a-f]{24}$/.test(config.actionId) ||
377
+ !Number.isInteger(config.cohortIndex) || !config.conditionSites || !config.fetchSites) return false;
378
+ var configured = manifest();
379
+ if (!configured || !Number.isInteger(configured.cohortCount) ||
380
+ config.cohortIndex < 0 || config.cohortIndex >= configured.cohortCount ||
381
+ (configured.samplingMode === 'session' && config.cohortIndex !== configured.selectedSessionCohort)) return false;
382
+ if (runtimeActions[config.actionId]) return nativeStringify(runtimeActions[config.actionId]) === nativeStringify(config);
383
+ var pendingSites = [];
384
+ pendingSites.push([config.actionSiteId, 'action-start']);
385
+ pendingSites.push([config.inputSiteId, 'input-shape']);
386
+ pendingSites.push([config.outputSiteId, 'output-shape']);
387
+ var conditionTokens = Object.keys(config.conditionSites);
388
+ for (var conditionIndex = 0; conditionIndex < conditionTokens.length; conditionIndex++) {
389
+ pendingSites.push([config.conditionSites[conditionTokens[conditionIndex]], 'condition']);
390
+ }
391
+ var fetchTokens = Object.keys(config.fetchSites);
392
+ for (var fetchIndex = 0; fetchIndex < fetchTokens.length; fetchIndex++) {
393
+ var fetchSites = config.fetchSites[fetchTokens[fetchIndex]];
394
+ if (!fetchSites) return false;
395
+ pendingSites.push([fetchSites.requestSiteId, 'request']);
396
+ pendingSites.push([fetchSites.responseSiteId, 'response']);
397
+ }
398
+ var preparedSites = [];
399
+ var preparedIds = Object.create(null);
400
+ for (var siteIndex = 0; siteIndex < pendingSites.length; siteIndex++) {
401
+ var siteId = pendingSites[siteIndex][0];
402
+ var prepared = runtimeSite(config, siteId, pendingSites[siteIndex][1]);
403
+ if (!prepared || runtimeSites[siteId] || preparedIds[siteId]) return false;
404
+ preparedIds[siteId] = true;
405
+ preparedSites.push(prepared);
406
+ }
407
+ for (var commitIndex = 0; commitIndex < preparedSites.length; commitIndex++) {
408
+ runtimeSites[preparedSites[commitIndex].siteId] = preparedSites[commitIndex];
409
+ }
410
+ runtimeActions[config.actionId] = config;
411
+ return true;
412
+ } catch (_) {
413
+ failOpen();
414
+ return false;
415
+ }
416
+ }
417
+
418
+ function sessionCohort(cohortCount) {
419
+ if (assignedCohort !== null && assignedCohortCount === cohortCount) return assignedCohort;
420
+ var override = configuredCohort === null ? ownDataValue('__HAYSTACK_WEB_ATLAS_COHORT__') : configuredCohort;
421
+ if (Number.isInteger(override) && override >= 0 && override < cohortCount) {
422
+ assignedCohort = override;
423
+ assignedCohortCount = cohortCount;
424
+ return assignedCohort;
425
+ }
426
+ if (!nativeRandomValues) return -1;
427
+ var value = new Uint32Array(1);
428
+ nativeRandomValues(value);
429
+ assignedCohort = value[0] % cohortCount;
430
+ assignedCohortCount = cohortCount;
431
+ return assignedCohort;
432
+ }
433
+
434
+ function emit(siteId, kind, outcome, parentEventId) {
435
+ try {
436
+ if (!active) return null;
437
+ var site = siteFor(siteId);
438
+ if (!site || site.actionId !== active.actionId || site.surface !== 'browser' ||
439
+ site.kind !== kind || !Array.isArray(site.allowedOutcomes) ||
440
+ site.allowedOutcomes.indexOf(outcome) === -1 || !trustedOutcome(outcome)) {
441
+ active.omittedEvents++;
442
+ return null;
443
+ }
444
+ if (active.events.length >= MAX_EVENTS) {
445
+ active.omittedEvents++;
446
+ return null;
447
+ }
448
+ var eventId = 'browser-' + active.traceId + '-' + String(active.events.length + 1).padStart(4, '0');
449
+ var event = {
450
+ eventId: eventId,
451
+ parentEventId: parentEventId === undefined ? active.parentEventId : parentEventId,
452
+ siteId: siteId,
453
+ kind: kind,
454
+ outcome: outcome,
455
+ ordinal: active.events.length + 1,
456
+ };
457
+ active.events.push(event);
458
+ active.parentEventId = eventId;
459
+ return eventId;
460
+ } catch (_) {
461
+ failOpen();
462
+ return null;
463
+ }
464
+ }
465
+
466
+ function shapeOutcome(value) {
467
+ try {
468
+ if (value === null) return 'shape:null';
469
+ if (value === undefined) return 'shape:undefined';
470
+ // Array.isArray is normally trap-free, but a revoked Proxy throws. Shape
471
+ // classification is telemetry work and must therefore be total.
472
+ if (nativeArrayIsArray(value)) return 'shape:array';
473
+ var kind = typeof value;
474
+ if (kind === 'boolean' || kind === 'number' || kind === 'string') return 'shape:' + kind;
475
+ if (kind === 'object') return 'shape:object';
476
+ } catch (_) { failOpen(); }
477
+ return 'shape:uninspectable';
478
+ }
479
+
480
+ function invokeApplicationFetch(fetchImplementation, input, init, hasInit) {
481
+ // The compiler only rewrites bare `fetch(...)` calls. Calling the captured
482
+ // function as a local preserves their strict-mode `this === undefined`.
483
+ // Preserve argument count too: wrappers can distinguish fetch(url) from
484
+ // fetch(url, undefined).
485
+ return hasInit ? fetchImplementation(input, init) : fetchImplementation(input);
486
+ }
487
+
488
+ function scheduleFinish(context) {
489
+ if (!context || context !== active || !context.rootReturned || context.pendingFetches !== 0 || context.finishScheduled) return;
490
+ context.finishScheduled = true;
491
+ var finish = function () {
492
+ context.finishScheduled = false;
493
+ if (context === active && context.rootReturned && context.pendingFetches === 0) endAction();
494
+ };
495
+ if (nativeSetTimeout) nativeSetTimeout(finish, 0);
496
+ else finish();
497
+ }
498
+
499
+ function correlatedFetch(fetchImplementation, input, init, explicitSites, applicationHasInit) {
500
+ var hasInit = typeof applicationHasInit === 'boolean' ? applicationHasInit : arguments.length >= 3;
501
+ var applicationFetch = typeof fetchImplementation === 'function'
502
+ ? fetchImplementation
503
+ : nativeFetch;
504
+ if (!applicationFetch) throw new TypeError('fetch is not available');
505
+ var context = active;
506
+ if (!context) return invokeApplicationFetch(applicationFetch, input, init, hasInit);
507
+ // Adding correlation headers necessarily converts a string into Request.
508
+ // That is invisible to the platform fetch but observable to an application
509
+ // wrapper. Never alter a later-installed/customer fetch wrapper.
510
+ if (!platformFetchCorrelationAllowed() || !initialFetchLooksNative || fetchImplementation !== nativeFetchFunction) {
511
+ context.omittedEvents++;
512
+ return invokeApplicationFetch(applicationFetch, input, init, hasInit);
513
+ }
514
+ var fetchInput = input;
515
+ var fetchInit = init;
516
+ var normalizedRequest = null;
517
+ var requestParent = null;
518
+ var requestSiteId = explicitSites && explicitSites.requestSiteId || context.requestSiteId;
519
+ var responseSiteId = explicitSites && explicitSites.responseSiteId || context.responseSiteId;
520
+ try {
521
+ // A user-defined URL-like object can have stateful coercion. Inspecting
522
+ // it would perform application work twice, so leave it completely alone
523
+ // and disclose the missing continuation instead. Objects include Request
524
+ // and URL here: avoiding `instanceof` also avoids Proxy prototype traps.
525
+ if (typeof input !== 'string') {
526
+ context.omittedEvents++;
527
+ return invokeApplicationFetch(applicationFetch, input, init, hasInit);
528
+ }
529
+ if (!nativeLocationHref || !nativeLocationOrigin || !nativeUrlConstructor ||
530
+ !nativeUrlCanParse || !nativeRequestConstructor || !nativeHeadersConstructor || !nativeUrlHrefGetter ||
531
+ !nativeRequestHeadersGetter || !nativeHeadersHas || !nativeHeadersGet || !nativeHeadersSet ||
532
+ !nativeResponseHeadersGetter || !nativeResponseOkGetter || !nativePromiseReject) {
533
+ context.omittedEvents++;
534
+ return invokeApplicationFetch(applicationFetch, input, init, hasInit);
535
+ }
536
+ if (!nativeReflectApply(nativeUrlCanParse, nativeUrlConstructor, [input, nativeLocationHref])) {
537
+ context.omittedEvents++;
538
+ return invokeApplicationFetch(applicationFetch, input, init, hasInit);
539
+ }
540
+ var urlValue = nativeReflectConstruct(nativeUrlConstructor, [input, nativeLocationHref]);
541
+ var inputUrl = nativeReflectApply(nativeUrlHrefGetter, urlValue, []);
542
+ if (inputUrl.indexOf(nativeLocationOrigin + '/') === 0) {
543
+ var request = nativeReflectConstruct(nativeRequestConstructor, [input, init]);
544
+ normalizedRequest = request;
545
+ // From this point on the application RequestInit has been consumed
546
+ // exactly once. Any fail-open fetch uses this normalized Request and
547
+ // never re-reads customer dictionary fields.
548
+ fetchInput = request;
549
+ fetchInit = undefined;
550
+ hasInit = false;
551
+ var requestHeaders = nativeReflectApply(nativeRequestHeadersGetter, request, []);
552
+ var headers = nativeReflectConstruct(nativeHeadersConstructor, [requestHeaders]);
553
+ var reservedHeaders = [TRACE_HEADER, ACTION_HEADER, COHORT_HEADER, PARENT_EVENT_HEADER, REQUEST_SITE_HEADER, 'traceparent'];
554
+ var hasReservedHeader = false;
555
+ for (var headerIndex = 0; headerIndex < reservedHeaders.length; headerIndex++) {
556
+ if (nativeReflectApply(nativeHeadersHas, headers, [reservedHeaders[headerIndex]])) { hasReservedHeader = true; break; }
557
+ }
558
+ if (hasReservedHeader) {
559
+ // Existing application/distributed-tracing headers win. The already
560
+ // constructed native Request preserves their exact platform
561
+ // semantics without evaluating the original init twice.
562
+ context.omittedEvents++;
563
+ fetchInput = request;
564
+ fetchInit = undefined;
565
+ } else {
566
+ requestParent = emit(requestSiteId, 'request', 'sent', context.inputEventId || undefined);
567
+ }
568
+ if (!requestParent) {
569
+ // Either a reserved header prevented correlation or event capacity was
570
+ // exhausted. Invoke the native fetch without adding any header.
571
+ fetchInput = request;
572
+ fetchInit = undefined;
573
+ } else {
574
+ nativeReflectApply(nativeHeadersSet, headers, [TRACE_HEADER, context.traceId]);
575
+ nativeReflectApply(nativeHeadersSet, headers, [ACTION_HEADER, context.actionId]);
576
+ nativeReflectApply(nativeHeadersSet, headers, [COHORT_HEADER, '' + context.cohortIndex]);
577
+ if (requestParent) nativeReflectApply(nativeHeadersSet, headers, [PARENT_EVENT_HEADER, requestParent]);
578
+ if (requestParent) nativeReflectApply(nativeHeadersSet, headers, [REQUEST_SITE_HEADER, requestSiteId]);
579
+ nativeReflectApply(nativeHeadersSet, headers, ['traceparent', traceparent(context.traceId)]);
580
+ fetchInput = nativeReflectConstruct(nativeRequestConstructor, [request, { headers: headers }]);
581
+ fetchInit = undefined;
582
+ }
583
+ }
584
+ } catch (error) {
585
+ failOpen();
586
+ context.omittedEvents++;
587
+ if (normalizedRequest) {
588
+ // Request conversion already completed. A later telemetry-only failure
589
+ // must still perform the application fetch exactly once.
590
+ return invokeApplicationFetch(applicationFetch, normalizedRequest, undefined, false);
591
+ }
592
+ // Native fetch reports request-conversion failures asynchronously. Do
593
+ // the same without retrying the original init and invoking its getters a
594
+ // second time.
595
+ return nativeReflectApply(nativePromiseReject, hostPromise, [error]);
596
+ }
597
+ // This is the application operation. It must happen exactly once and is
598
+ // deliberately outside telemetry's catch boundary: a synchronous throw or
599
+ // rejected promise keeps the application's original semantics.
600
+ var result = invokeApplicationFetch(applicationFetch, fetchInput, fetchInit, hasInit);
601
+ if (!requestParent) return result;
602
+ if (!nativePromiseThen || result === null ||
603
+ (typeof result !== 'object' && typeof result !== 'function')) {
604
+ context.omittedEvents++;
605
+ scheduleFinish(context);
606
+ return result;
607
+ }
608
+ context.pendingFetches++;
609
+ try {
610
+ nativeReflectApply(nativePromiseThen, result, [function (response) {
611
+ context.pendingFetches--;
612
+ if (context === active) {
613
+ try {
614
+ var responseHeaders = nativeReflectApply(nativeResponseHeadersGetter, response, []);
615
+ var serverParent = nativeReflectApply(nativeHeadersHas, responseHeaders, [PARENT_EVENT_HEADER])
616
+ ? nativeReflectApply(nativeHeadersGet, responseHeaders, [PARENT_EVENT_HEADER])
617
+ : null;
618
+ var safeServerParent = safeNodeResponseId(context.traceId, requestParent, serverParent);
619
+ if (serverParent !== null && safeServerParent === null) {
620
+ context.omittedEvents++;
621
+ serverParent = null;
622
+ } else {
623
+ serverParent = safeServerParent;
624
+ }
625
+ emit(
626
+ responseSiteId,
627
+ 'response',
628
+ nativeReflectApply(nativeResponseOkGetter, response, []) ? 'success' : 'error',
629
+ serverParent || requestParent,
630
+ );
631
+ } catch (_) {
632
+ context.omittedEvents++;
633
+ failOpen();
634
+ }
635
+ scheduleFinish(context);
636
+ }
637
+ }, function (error) {
638
+ context.pendingFetches--;
639
+ if (context === active) {
640
+ try { emit(responseSiteId, 'response', 'network:error', requestParent); } catch (_) { failOpen(); }
641
+ scheduleFinish(context);
642
+ }
643
+ // Preserve an unhandled rejection signal for ignored application fetch
644
+ // Promises. It is carried by this observer child rather than the exact
645
+ // original Promise identity.
646
+ throw error;
647
+ }]);
648
+ } catch (_) {
649
+ context.pendingFetches--;
650
+ context.omittedEvents++;
651
+ scheduleFinish(context);
652
+ failOpen();
653
+ }
654
+ // Observation must not replace the application's Promise or call a
655
+ // customer-overridden `.then` method.
656
+ return result;
657
+ }
658
+
659
+ function fetchAt(token, fetchImplementation, input, init) {
660
+ if (arguments.length > 4) {
661
+ var passthroughArguments = [];
662
+ for (var argumentIndex = 2; argumentIndex < arguments.length; argumentIndex++) {
663
+ passthroughArguments[argumentIndex - 2] = arguments[argumentIndex];
664
+ }
665
+ if (active) active.omittedEvents++;
666
+ return nativeReflectApply(fetchImplementation, undefined, passthroughArguments);
667
+ }
668
+ var hasInit = arguments.length >= 4;
669
+ var context = active;
670
+ var sites = context && context.runtimeConfig && context.runtimeConfig.fetchSites[token];
671
+ if (context && !sites) return invokeApplicationFetch(fetchImplementation, input, init, hasInit);
672
+ return correlatedFetch(fetchImplementation, input, init, sites, hasInit);
673
+ }
674
+
675
+ function deliver(segment) {
676
+ try {
677
+ var endpoint = configuredEndpoint || ownDataValue('__HAYSTACK_WEB_ATLAS_ENDPOINT__');
678
+ if (typeof endpoint !== 'string' || endpoint.length === 0) return false;
679
+ var body = nativeStringify(segment);
680
+ if (nativeBeacon && nativeBeacon(endpoint, body)) return true;
681
+ if (nativeFetch && configuredPlatformFetch && initialFetchLooksNative) {
682
+ var delivery = nativeFetch(endpoint, {
683
+ method: 'POST',
684
+ body: body,
685
+ keepalive: true,
686
+ headers: { 'Content-Type': 'text/plain' },
687
+ });
688
+ if (nativePromiseThen && delivery !== null &&
689
+ (typeof delivery === 'object' || typeof delivery === 'function')) {
690
+ try { nativeReflectApply(nativePromiseThen, delivery, [function () {}, failOpen]); } catch (_) { failOpen(); }
691
+ }
692
+ return true;
693
+ }
694
+ } catch (_) { failOpen(); }
695
+ return false;
696
+ }
697
+
698
+ function beginAction(actionId, sites) {
699
+ try {
700
+ if (active || recorderDisabled) return false;
701
+ var value = manifest();
702
+ var action = actionFor(actionId);
703
+ if (!value || !action || !sites || sessionCohort(value.cohortCount) !== action.cohortIndex) return false;
704
+ var traceId = randomTraceId();
705
+ if (!traceId) return false;
706
+ active = {
707
+ traceId: traceId,
708
+ actionId: actionId,
709
+ cohortIndex: action.cohortIndex,
710
+ events: [],
711
+ omittedEvents: 0,
712
+ parentEventId: null,
713
+ requestSiteId: sites.requestSiteId,
714
+ responseSiteId: sites.responseSiteId,
715
+ pendingFetches: 0,
716
+ rootReturned: false,
717
+ finishScheduled: false,
718
+ runtimeConfig: sites,
719
+ };
720
+ emit(sites.actionSiteId, 'action-start', 'started', null);
721
+ return true;
722
+ } catch (_) {
723
+ failOpen();
724
+ active = null;
725
+ return false;
726
+ }
727
+ }
728
+
729
+ function wrapAction(actionId, handler) {
730
+ if (typeof handler !== 'function') return handler;
731
+ return function haystackWebAtlasActionWrapper() {
732
+ var sites = runtimeActions[actionId];
733
+ if (!sites) return nativeReflectApply(handler, this, arguments);
734
+ if (active) {
735
+ // A single global action cannot safely attribute probes from overlapping
736
+ // async roots. Close the partial trace with an explicit omission and
737
+ // stop recording this page rather than fabricate either action's path.
738
+ active.omittedEvents++;
739
+ recorderDisabled = true;
740
+ endAction();
741
+ return nativeReflectApply(handler, this, arguments);
742
+ }
743
+ var started = beginAction(actionId, sites);
744
+ if (!started) return nativeReflectApply(handler, this, arguments);
745
+ var context = active;
746
+ var inputEventId = emit(sites.inputSiteId, 'input-shape', shapeOutcome(arguments.length > 0 ? arguments[0] : undefined));
747
+ if (context) context.inputEventId = inputEventId;
748
+ var result;
749
+ try {
750
+ result = nativeReflectApply(handler, this, arguments);
751
+ } catch (error) {
752
+ if (context) context.rootReturned = true;
753
+ endAction();
754
+ throw error;
755
+ }
756
+
757
+ // Keep a real Promise-returning action open across awaits. We attach a
758
+ // side observer through the captured native Promise method and return the
759
+ // application's original Promise unchanged.
760
+ var observesPromise = false;
761
+ if (context && nativePromiseThen && result !== null &&
762
+ (typeof result === 'object' || typeof result === 'function')) {
763
+ try {
764
+ nativeReflectApply(nativePromiseThen, result, [function (value) {
765
+ if (context === active) {
766
+ emit(sites.outputSiteId, 'output-shape', shapeOutcome(value), context.inputEventId || undefined);
767
+ context.rootReturned = true;
768
+ scheduleFinish(context);
769
+ }
770
+ }, function (error) {
771
+ if (context === active) {
772
+ context.rootReturned = true;
773
+ scheduleFinish(context);
774
+ }
775
+ // Do not hide ignored async-handler failures from error monitoring.
776
+ throw error;
777
+ }]);
778
+ observesPromise = true;
779
+ } catch (_) { failOpen(); }
780
+ }
781
+ if (!observesPromise) {
782
+ if (context && !nativePromiseThen && result !== null &&
783
+ (typeof result === 'object' || typeof result === 'function')) context.omittedEvents++;
784
+ emit(sites.outputSiteId, 'output-shape', shapeOutcome(result), context && context.inputEventId || undefined);
785
+ if (context) {
786
+ context.rootReturned = true;
787
+ scheduleFinish(context);
788
+ }
789
+ }
790
+ return result;
791
+ };
792
+ }
793
+
794
+ function conditionAt(token, value) {
795
+ try {
796
+ var context = active;
797
+ var siteId = context && context.runtimeConfig && context.runtimeConfig.conditionSites[token];
798
+ if (siteId) emit(siteId, 'condition', value ? 'boolean:true' : 'boolean:false', context.inputEventId || undefined);
799
+ } catch (_) { failOpen(); }
800
+ return value;
801
+ }
802
+
803
+ function endAction() {
804
+ try {
805
+ if (!active) return null;
806
+ var value = manifest();
807
+ var segment = {
808
+ schemaVersion: 'haystack-web-node-atlas-segment-v1',
809
+ traceId: active.traceId,
810
+ actionId: active.actionId,
811
+ surface: 'browser',
812
+ buildId: value.browserBuildId,
813
+ cohortIndex: active.cohortIndex,
814
+ events: active.events.slice(),
815
+ omittedEvents: active.omittedEvents,
816
+ };
817
+ active = null;
818
+ deliver(segment);
819
+ return segment;
820
+ } catch (_) {
821
+ failOpen();
822
+ active = null;
823
+ return null;
824
+ }
825
+ }
826
+
827
+ var api = Object.freeze({
828
+ version: 'haystack-web-node-atlas-browser-v1',
829
+ configure: configure,
830
+ registerAction: registerAction,
831
+ beginAction: beginAction,
832
+ inputShape: function (siteId, outcome) { emit(siteId, 'input-shape', outcome); },
833
+ condition: function (siteId, outcome) { emit(siteId, 'condition', outcome); },
834
+ fetch: correlatedFetch,
835
+ fetchAt: fetchAt,
836
+ wrapAction: wrapAction,
837
+ conditionAt: conditionAt,
838
+ outputShape: function (siteId, outcome) { emit(siteId, 'output-shape', outcome); },
839
+ uiOutcome: function (siteId, outcome) { emit(siteId, 'ui-outcome', outcome); },
840
+ error: function (siteId, outcome) { emit(siteId, 'error', outcome); },
841
+ endAction: endAction,
842
+ status: function () {
843
+ return active
844
+ ? { active: true, disabled: recorderDisabled, traceId: active.traceId }
845
+ : { active: false, disabled: recorderDisabled };
846
+ },
847
+ });
848
+ try {
849
+ Object.defineProperty(host, '__haystackWebAtlas', {
850
+ configurable: false,
851
+ enumerable: false,
852
+ writable: false,
853
+ value: api,
854
+ });
855
+ } catch (_) {
856
+ // The application owns this namespace. Never redefine or mutate it, and
857
+ // never prevent the containing module from evaluating.
858
+ return null;
859
+ }
860
+ return api;
861
+ })(globalThis);