@mondaydotcomorg/atp-provenance 0.19.7 → 0.19.8

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/dist/index.cjs ADDED
@@ -0,0 +1,1987 @@
1
+ 'use strict';
2
+
3
+ var nanoid = require('nanoid');
4
+ var atpRuntime = require('@mondaydotcomorg/atp-runtime');
5
+ var crypto = require('crypto');
6
+ var zod = require('zod');
7
+ var acorn = require('acorn');
8
+ var walk = require('acorn-walk');
9
+ var escodegen = require('escodegen');
10
+
11
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
12
+
13
+ function _interopNamespace(e) {
14
+ if (e && e.__esModule) return e;
15
+ var n = Object.create(null);
16
+ if (e) {
17
+ Object.keys(e).forEach(function (k) {
18
+ if (k !== 'default') {
19
+ var d = Object.getOwnPropertyDescriptor(e, k);
20
+ Object.defineProperty(n, k, d.get ? d : {
21
+ enumerable: true,
22
+ get: function () { return e[k]; }
23
+ });
24
+ }
25
+ });
26
+ }
27
+ n.default = e;
28
+ return Object.freeze(n);
29
+ }
30
+
31
+ var crypto__default = /*#__PURE__*/_interopDefault(crypto);
32
+ var acorn__namespace = /*#__PURE__*/_interopNamespace(acorn);
33
+ var walk__namespace = /*#__PURE__*/_interopNamespace(walk);
34
+ var escodegen__namespace = /*#__PURE__*/_interopNamespace(escodegen);
35
+
36
+ var __defProp = Object.defineProperty;
37
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
38
+
39
+ // src/types.ts
40
+ exports.ProvenanceMode = void 0;
41
+ (function(ProvenanceMode2) {
42
+ ProvenanceMode2["NONE"] = "none";
43
+ ProvenanceMode2["PROXY"] = "proxy";
44
+ ProvenanceMode2["AST"] = "ast";
45
+ })(exports.ProvenanceMode || (exports.ProvenanceMode = {}));
46
+ exports.ProvenanceSource = void 0;
47
+ (function(ProvenanceSource2) {
48
+ ProvenanceSource2["USER"] = "user";
49
+ ProvenanceSource2["LLM"] = "llm";
50
+ ProvenanceSource2["TOOL"] = "tool";
51
+ ProvenanceSource2["SYSTEM"] = "system";
52
+ })(exports.ProvenanceSource || (exports.ProvenanceSource = {}));
53
+ var ProvenanceSecurityError = class extends Error {
54
+ static {
55
+ __name(this, "ProvenanceSecurityError");
56
+ }
57
+ policy;
58
+ toolName;
59
+ details;
60
+ constructor(message, policy, toolName, details) {
61
+ super(message);
62
+ this.policy = policy;
63
+ this.toolName = toolName;
64
+ this.details = details;
65
+ this.name = "ProvenanceSecurityError";
66
+ }
67
+ };
68
+ var MAX_VALUE_SIZE = 1024 * 1024;
69
+ function stableStringify(value) {
70
+ try {
71
+ if (value === null || value === void 0) {
72
+ return String(value);
73
+ }
74
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
75
+ return JSON.stringify(value);
76
+ }
77
+ if (typeof value === "function" || typeof value === "symbol") {
78
+ return null;
79
+ }
80
+ const seen = /* @__PURE__ */ new WeakSet();
81
+ const replacer = /* @__PURE__ */ __name((_key, val) => {
82
+ if (val !== null && typeof val === "object") {
83
+ if (seen.has(val)) {
84
+ return "[Circular]";
85
+ }
86
+ seen.add(val);
87
+ if (!Array.isArray(val)) {
88
+ const sorted = {};
89
+ const keys = Object.keys(val).sort();
90
+ for (const k of keys) {
91
+ sorted[k] = val[k];
92
+ }
93
+ return sorted;
94
+ }
95
+ }
96
+ return val;
97
+ }, "replacer");
98
+ const result = JSON.stringify(value, replacer);
99
+ if (result.length > MAX_VALUE_SIZE) {
100
+ return null;
101
+ }
102
+ return result;
103
+ } catch (error) {
104
+ return null;
105
+ }
106
+ }
107
+ __name(stableStringify, "stableStringify");
108
+ function computeDigest(value) {
109
+ const serialized = stableStringify(value);
110
+ if (!serialized) {
111
+ return null;
112
+ }
113
+ return crypto__default.default.createHash("sha256").update(serialized).digest("base64url");
114
+ }
115
+ __name(computeDigest, "computeDigest");
116
+ function getClientSecret(clientId) {
117
+ const secret = process.env.PROVENANCE_SECRET;
118
+ if (!secret) {
119
+ throw new Error("PROVENANCE_SECRET environment variable is required for provenance tracking. Generate a strong secret with: openssl rand -base64 32");
120
+ }
121
+ const secretBytes = Buffer.from(secret, "utf-8").length;
122
+ if (secretBytes < 32) {
123
+ throw new Error(`PROVENANCE_SECRET must be at least 32 bytes (currently ${secretBytes} bytes). Generate a strong secret with: openssl rand -base64 32`);
124
+ }
125
+ return secret;
126
+ }
127
+ __name(getClientSecret, "getClientSecret");
128
+ function hmacSign(data, secret) {
129
+ return crypto__default.default.createHmac("sha256", secret).update(data).digest("base64url");
130
+ }
131
+ __name(hmacSign, "hmacSign");
132
+ async function issueProvenanceToken(metadata, value, clientId, executionId, cacheProvider, ttl = 3600) {
133
+ const valueDigest = computeDigest(value);
134
+ if (!valueDigest) {
135
+ return null;
136
+ }
137
+ const metaId = nanoid.nanoid();
138
+ const cacheKey = `prov:meta:${clientId}:${metaId}`;
139
+ try {
140
+ await cacheProvider.set(cacheKey, JSON.stringify(metadata), ttl);
141
+ if (typeof value === "string" || typeof value === "number") {
142
+ const valueKey = `prov:value:${clientId}:${valueDigest}`;
143
+ await cacheProvider.set(valueKey, JSON.stringify({
144
+ value: String(value),
145
+ metaId
146
+ }), ttl);
147
+ }
148
+ } catch (error) {
149
+ atpRuntime.log.error("Failed to store provenance metadata in cache", {
150
+ error
151
+ });
152
+ return null;
153
+ }
154
+ const payload = {
155
+ v: 1,
156
+ clientId,
157
+ executionId,
158
+ createdAt: Date.now(),
159
+ expiresAt: Date.now() + ttl * 1e3,
160
+ valueDigest,
161
+ metaId
162
+ };
163
+ const payloadStr = JSON.stringify(payload);
164
+ const payloadB64 = Buffer.from(payloadStr).toString("base64url");
165
+ const secret = getClientSecret();
166
+ const signature = hmacSign(payloadB64, secret);
167
+ return `${payloadB64}.${signature}`;
168
+ }
169
+ __name(issueProvenanceToken, "issueProvenanceToken");
170
+ async function verifyProvenanceToken(token, value, clientId, executionId, cacheProvider) {
171
+ try {
172
+ const parts = token.split(".");
173
+ if (parts.length !== 2) {
174
+ return null;
175
+ }
176
+ const [payloadB64, signature] = parts;
177
+ if (!payloadB64 || !signature) {
178
+ return null;
179
+ }
180
+ const secret = getClientSecret(clientId);
181
+ const expectedSig = hmacSign(payloadB64, secret);
182
+ try {
183
+ const sigBuf = Buffer.from(signature, "base64url");
184
+ const expectedBuf = Buffer.from(expectedSig, "base64url");
185
+ if (sigBuf.length !== expectedBuf.length || !crypto__default.default.timingSafeEqual(sigBuf, expectedBuf)) {
186
+ atpRuntime.log.error("Token signature verification failed");
187
+ return null;
188
+ }
189
+ } catch (error) {
190
+ atpRuntime.log.error("Token signature comparison error", {
191
+ error
192
+ });
193
+ return null;
194
+ }
195
+ const payloadStr = Buffer.from(payloadB64, "base64url").toString();
196
+ const payload = JSON.parse(payloadStr);
197
+ if (payload.v !== 1) {
198
+ atpRuntime.log.error("Unsupported token version", {
199
+ version: payload.v
200
+ });
201
+ return null;
202
+ }
203
+ if (payload.clientId !== clientId) {
204
+ atpRuntime.log.error("Token clientId mismatch", {
205
+ tokenClientId: payload.clientId,
206
+ expectedClientId: clientId
207
+ });
208
+ return null;
209
+ }
210
+ if (payload.executionId !== executionId) {
211
+ atpRuntime.log.error("Token executionId mismatch", {
212
+ tokenExecutionId: payload.executionId,
213
+ expectedExecutionId: executionId
214
+ });
215
+ return null;
216
+ }
217
+ if (Date.now() > payload.expiresAt) {
218
+ atpRuntime.log.warn("Token expired");
219
+ return null;
220
+ }
221
+ const valueDigest = computeDigest(value);
222
+ if (!valueDigest || valueDigest !== payload.valueDigest) {
223
+ atpRuntime.log.warn("Token value digest mismatch (value may have been modified)");
224
+ return null;
225
+ }
226
+ const cacheKey = `prov:meta:${payload.clientId}:${payload.metaId}`;
227
+ const metaStr = await cacheProvider.get(cacheKey);
228
+ if (!metaStr || typeof metaStr !== "string") {
229
+ atpRuntime.log.warn("Token metadata not found in cache (expired or evicted)");
230
+ return null;
231
+ }
232
+ const metadata = JSON.parse(metaStr);
233
+ return metadata;
234
+ } catch (error) {
235
+ atpRuntime.log.error("Token verification error", {
236
+ error
237
+ });
238
+ return null;
239
+ }
240
+ }
241
+ __name(verifyProvenanceToken, "verifyProvenanceToken");
242
+ async function verifyProvenanceHints(hints, clientId, executionId, cacheProvider, maxHints = 1e3) {
243
+ const map = /* @__PURE__ */ new Map();
244
+ const hintsToProcess = hints.slice(0, maxHints);
245
+ if (hints.length > maxHints) {
246
+ atpRuntime.log.warn(`Capped provenance hints from ${hints.length} to ${maxHints}`);
247
+ }
248
+ const timeout = 100;
249
+ const promises = hintsToProcess.map(async (token) => {
250
+ try {
251
+ const parts = token.split(".");
252
+ if (parts.length !== 2) return;
253
+ const [payloadB64] = parts;
254
+ if (!payloadB64) return;
255
+ const payloadStr = Buffer.from(payloadB64, "base64url").toString();
256
+ const payload = JSON.parse(payloadStr);
257
+ const cacheKey = `prov:meta:${payload.clientId}:${payload.metaId}`;
258
+ const fetchPromise = cacheProvider.get(cacheKey);
259
+ const timeoutPromise = new Promise((resolve) => setTimeout(() => resolve(null), timeout));
260
+ const metaStr = await Promise.race([
261
+ fetchPromise,
262
+ timeoutPromise
263
+ ]);
264
+ if (metaStr && typeof metaStr === "string") {
265
+ const metadata = JSON.parse(metaStr);
266
+ map.set(payload.valueDigest, metadata);
267
+ const valueKey = `prov:value:${payload.clientId}:${payload.valueDigest}`;
268
+ const valueStr = await Promise.race([
269
+ cacheProvider.get(valueKey),
270
+ new Promise((resolve) => setTimeout(() => resolve(null), timeout))
271
+ ]);
272
+ if (valueStr && typeof valueStr === "string") {
273
+ try {
274
+ const { value } = JSON.parse(valueStr);
275
+ map.__valueMap = map.__valueMap || /* @__PURE__ */ new Map();
276
+ map.__valueMap.set(value, metadata);
277
+ } catch (e) {
278
+ }
279
+ }
280
+ }
281
+ } catch (error) {
282
+ }
283
+ });
284
+ await Promise.all(promises);
285
+ return map;
286
+ }
287
+ __name(verifyProvenanceHints, "verifyProvenanceHints");
288
+
289
+ // src/store.ts
290
+ var InMemoryProvenanceStore = class {
291
+ static {
292
+ __name(this, "InMemoryProvenanceStore");
293
+ }
294
+ registry = /* @__PURE__ */ new Map();
295
+ primitives = /* @__PURE__ */ new Map();
296
+ executionIds = /* @__PURE__ */ new Map();
297
+ executionPrimitives = /* @__PURE__ */ new Map();
298
+ async get(id) {
299
+ return this.registry.get(id) || null;
300
+ }
301
+ async getBatch(ids) {
302
+ const result = /* @__PURE__ */ new Map();
303
+ for (const id of ids) {
304
+ const meta = this.registry.get(id);
305
+ if (meta) {
306
+ result.set(id, meta);
307
+ }
308
+ }
309
+ return result;
310
+ }
311
+ async set(id, metadata, executionId) {
312
+ this.registry.set(id, metadata);
313
+ if (executionId) {
314
+ let ids = this.executionIds.get(executionId);
315
+ if (!ids) {
316
+ ids = /* @__PURE__ */ new Set();
317
+ this.executionIds.set(executionId, ids);
318
+ }
319
+ ids.add(id);
320
+ }
321
+ }
322
+ async getPrimitive(key) {
323
+ return this.primitives.get(key) || null;
324
+ }
325
+ async setPrimitive(key, metadata, executionId) {
326
+ this.primitives.set(key, metadata);
327
+ if (executionId) {
328
+ let keys = this.executionPrimitives.get(executionId);
329
+ if (!keys) {
330
+ keys = /* @__PURE__ */ new Set();
331
+ this.executionPrimitives.set(executionId, keys);
332
+ }
333
+ keys.add(key);
334
+ }
335
+ }
336
+ async cleanupExecution(executionId) {
337
+ const ids = this.executionIds.get(executionId);
338
+ if (ids) {
339
+ for (const id of ids) {
340
+ this.registry.delete(id);
341
+ }
342
+ this.executionIds.delete(executionId);
343
+ }
344
+ const primKeys = this.executionPrimitives.get(executionId);
345
+ if (primKeys) {
346
+ for (const key of primKeys) {
347
+ this.primitives.delete(key);
348
+ }
349
+ this.executionPrimitives.delete(executionId);
350
+ }
351
+ }
352
+ async getExecution(executionId) {
353
+ const result = /* @__PURE__ */ new Map();
354
+ const ids = this.executionIds.get(executionId);
355
+ if (ids) {
356
+ for (const id of ids) {
357
+ const meta = this.registry.get(id);
358
+ if (meta) {
359
+ result.set(id, meta);
360
+ }
361
+ }
362
+ }
363
+ return result;
364
+ }
365
+ };
366
+
367
+ // src/registry.ts
368
+ var PROVENANCE_KEY = "__provenance__";
369
+ var PROVENANCE_ID_KEY = "__prov_id__";
370
+ var provenanceStore = /* @__PURE__ */ new WeakMap();
371
+ var provenanceRegistry = /* @__PURE__ */ new Map();
372
+ var executionProvenanceIds = /* @__PURE__ */ new Map();
373
+ var currentExecutionId = null;
374
+ var primitiveProvenanceMap = /* @__PURE__ */ new Map();
375
+ var executionTaintedPrimitives = /* @__PURE__ */ new Map();
376
+ var globalStore = new InMemoryProvenanceStore();
377
+ function setGlobalProvenanceStore(store) {
378
+ globalStore = store;
379
+ }
380
+ __name(setGlobalProvenanceStore, "setGlobalProvenanceStore");
381
+ function markPrimitiveTainted(value, sourceMetadata) {
382
+ if (typeof value !== "string" && typeof value !== "number") {
383
+ return;
384
+ }
385
+ if (currentExecutionId) {
386
+ const tainted = executionTaintedPrimitives.get(currentExecutionId);
387
+ if (tainted) {
388
+ tainted.add(value);
389
+ }
390
+ }
391
+ const key = `tainted:${String(value)}`;
392
+ primitiveProvenanceMap.set(key, sourceMetadata);
393
+ globalStore.setPrimitive(key, sourceMetadata, currentExecutionId || void 0).catch((err) => {
394
+ atpRuntime.log.warn("Failed to save primitive taint to provenance store", {
395
+ error: err
396
+ });
397
+ });
398
+ }
399
+ __name(markPrimitiveTainted, "markPrimitiveTainted");
400
+ function isPrimitiveTainted(value) {
401
+ if (typeof value !== "string" && typeof value !== "number") {
402
+ return false;
403
+ }
404
+ if (currentExecutionId) {
405
+ const tainted = executionTaintedPrimitives.get(currentExecutionId);
406
+ if (tainted && tainted.has(value)) {
407
+ return true;
408
+ }
409
+ }
410
+ return false;
411
+ }
412
+ __name(isPrimitiveTainted, "isPrimitiveTainted");
413
+ function setProvenanceExecutionId(executionId) {
414
+ currentExecutionId = executionId;
415
+ if (!executionProvenanceIds.has(executionId)) {
416
+ executionProvenanceIds.set(executionId, /* @__PURE__ */ new Set());
417
+ }
418
+ if (!executionTaintedPrimitives.has(executionId)) {
419
+ executionTaintedPrimitives.set(executionId, /* @__PURE__ */ new Set());
420
+ }
421
+ }
422
+ __name(setProvenanceExecutionId, "setProvenanceExecutionId");
423
+ function clearProvenanceExecutionId() {
424
+ currentExecutionId = null;
425
+ }
426
+ __name(clearProvenanceExecutionId, "clearProvenanceExecutionId");
427
+ async function hydrateProvenance(ids) {
428
+ const batch = await globalStore.getBatch(ids);
429
+ for (const [id, metadata] of batch.entries()) {
430
+ provenanceRegistry.set(id, metadata);
431
+ if (currentExecutionId) {
432
+ let execIds = executionProvenanceIds.get(currentExecutionId);
433
+ if (!execIds) {
434
+ execIds = /* @__PURE__ */ new Set();
435
+ executionProvenanceIds.set(currentExecutionId, execIds);
436
+ }
437
+ execIds.add(id);
438
+ }
439
+ }
440
+ }
441
+ __name(hydrateProvenance, "hydrateProvenance");
442
+ async function hydrateExecutionProvenance(executionId) {
443
+ const batch = await globalStore.getExecution(executionId);
444
+ for (const [id, metadata] of batch.entries()) {
445
+ provenanceRegistry.set(id, metadata);
446
+ if (currentExecutionId === executionId) {
447
+ let executionSet = executionProvenanceIds.get(executionId);
448
+ if (!executionSet) {
449
+ executionSet = /* @__PURE__ */ new Set();
450
+ executionProvenanceIds.set(executionId, executionSet);
451
+ }
452
+ executionSet.add(id);
453
+ }
454
+ }
455
+ }
456
+ __name(hydrateExecutionProvenance, "hydrateExecutionProvenance");
457
+ function registerProvenanceMetadata(id, metadata, executionId) {
458
+ if (id.startsWith("tainted:") || id.includes(":")) {
459
+ primitiveProvenanceMap.set(id, metadata);
460
+ globalStore.setPrimitive(id, metadata, executionId).catch((err) => {
461
+ atpRuntime.log.warn("Failed to save primitive provenance to store", {
462
+ error: err
463
+ });
464
+ });
465
+ if (id.startsWith("tainted:")) {
466
+ const value = id.slice("tainted:".length);
467
+ if (executionId) {
468
+ let tainted = executionTaintedPrimitives.get(executionId);
469
+ if (!tainted) {
470
+ tainted = /* @__PURE__ */ new Set();
471
+ executionTaintedPrimitives.set(executionId, tainted);
472
+ }
473
+ tainted.add(value);
474
+ }
475
+ }
476
+ } else {
477
+ provenanceRegistry.set(id, metadata);
478
+ globalStore.set(id, metadata, executionId).catch((err) => {
479
+ atpRuntime.log.warn("Failed to save provenance to store", {
480
+ error: err
481
+ });
482
+ });
483
+ }
484
+ if (executionId) {
485
+ let ids = executionProvenanceIds.get(executionId);
486
+ if (!ids) {
487
+ ids = /* @__PURE__ */ new Set();
488
+ executionProvenanceIds.set(executionId, ids);
489
+ }
490
+ ids.add(id);
491
+ }
492
+ }
493
+ __name(registerProvenanceMetadata, "registerProvenanceMetadata");
494
+ function cleanupProvenanceForExecution(executionId) {
495
+ const ids = executionProvenanceIds.get(executionId);
496
+ if (ids) {
497
+ for (const id of ids) {
498
+ provenanceRegistry.delete(id);
499
+ const keysToDelete = [];
500
+ for (const key of primitiveProvenanceMap.keys()) {
501
+ if (key.startsWith(`${id}:`) || key.startsWith("tainted:")) {
502
+ keysToDelete.push(key);
503
+ }
504
+ }
505
+ for (const key of keysToDelete) {
506
+ primitiveProvenanceMap.delete(key);
507
+ }
508
+ }
509
+ executionProvenanceIds.delete(executionId);
510
+ }
511
+ executionTaintedPrimitives.delete(executionId);
512
+ globalStore.cleanupExecution(executionId).catch((err) => {
513
+ atpRuntime.log.warn("Failed to cleanup provenance store", {
514
+ error: err
515
+ });
516
+ });
517
+ }
518
+ __name(cleanupProvenanceForExecution, "cleanupProvenanceForExecution");
519
+ function getProvenanceForPrimitive(value) {
520
+ if (typeof value !== "string" && typeof value !== "number") {
521
+ return null;
522
+ }
523
+ const valueStr = String(value);
524
+ if (isPrimitiveTainted(value)) {
525
+ const taintedKey2 = `tainted:${valueStr}`;
526
+ const metadata = primitiveProvenanceMap.get(taintedKey2);
527
+ if (metadata) {
528
+ return metadata;
529
+ }
530
+ }
531
+ const taintedKey = `tainted:${valueStr}`;
532
+ const taintedMetadata = primitiveProvenanceMap.get(taintedKey);
533
+ if (taintedMetadata) {
534
+ return taintedMetadata;
535
+ }
536
+ for (const [key, metadata] of primitiveProvenanceMap.entries()) {
537
+ const parts = key.split(":");
538
+ if (parts.length >= 3 && !key.startsWith("tainted:")) {
539
+ const primitiveValue = parts.slice(2).join(":");
540
+ if (primitiveValue === valueStr) {
541
+ return metadata;
542
+ }
543
+ }
544
+ }
545
+ const digest = computeDigest(value);
546
+ if (digest) {
547
+ const digestMetadata = provenanceRegistry.get(digest);
548
+ if (digestMetadata) {
549
+ return digestMetadata;
550
+ }
551
+ }
552
+ return null;
553
+ }
554
+ __name(getProvenanceForPrimitive, "getProvenanceForPrimitive");
555
+ function captureProvenanceState(executionId) {
556
+ const state = /* @__PURE__ */ new Map();
557
+ const ids = executionProvenanceIds.get(executionId);
558
+ if (ids) {
559
+ for (const id of ids) {
560
+ const metadata = provenanceRegistry.get(id);
561
+ if (metadata) {
562
+ state.set(id, metadata);
563
+ }
564
+ }
565
+ }
566
+ return state;
567
+ }
568
+ __name(captureProvenanceState, "captureProvenanceState");
569
+ function captureProvenanceSnapshot(executionId) {
570
+ const registryMap = captureProvenanceState(executionId);
571
+ const registry = Array.from(registryMap.entries());
572
+ const primitives = [];
573
+ const ids = executionProvenanceIds.get(executionId) || /* @__PURE__ */ new Set();
574
+ const tainted = executionTaintedPrimitives.get(executionId);
575
+ if (tainted) {
576
+ for (const value of tainted) {
577
+ const key = `tainted:${String(value)}`;
578
+ const meta = primitiveProvenanceMap.get(key);
579
+ if (meta) {
580
+ primitives.push([
581
+ key,
582
+ meta
583
+ ]);
584
+ }
585
+ }
586
+ }
587
+ for (const [key, meta] of primitiveProvenanceMap.entries()) {
588
+ if (key.startsWith("tainted:")) {
589
+ continue;
590
+ }
591
+ const [first] = key.split(":");
592
+ if (first && ids.has(first)) {
593
+ primitives.push([
594
+ key,
595
+ meta
596
+ ]);
597
+ }
598
+ }
599
+ return {
600
+ registry,
601
+ primitives
602
+ };
603
+ }
604
+ __name(captureProvenanceSnapshot, "captureProvenanceSnapshot");
605
+ function restoreProvenanceState(executionId, state) {
606
+ setProvenanceExecutionId(executionId);
607
+ const ids = executionProvenanceIds.get(executionId);
608
+ for (const [id, metadata] of state) {
609
+ provenanceRegistry.set(id, metadata);
610
+ ids.add(id);
611
+ globalStore.set(id, metadata, executionId).catch((err) => {
612
+ atpRuntime.log.error("Failed to save provenance to store", {
613
+ error: err
614
+ });
615
+ });
616
+ }
617
+ }
618
+ __name(restoreProvenanceState, "restoreProvenanceState");
619
+ function restoreProvenanceSnapshot(executionId, snapshot) {
620
+ const registryMap = new Map(snapshot.registry);
621
+ restoreProvenanceState(executionId, registryMap);
622
+ for (const [key, meta] of snapshot.primitives) {
623
+ primitiveProvenanceMap.set(key, meta);
624
+ globalStore.setPrimitive(key, meta, executionId).catch((err) => {
625
+ atpRuntime.log.error("Failed to save primitive provenance to store", {
626
+ error: err
627
+ });
628
+ });
629
+ if (key.startsWith("tainted:")) {
630
+ const value = key.slice("tainted:".length);
631
+ let set = executionTaintedPrimitives.get(executionId);
632
+ if (!set) {
633
+ set = /* @__PURE__ */ new Set();
634
+ executionTaintedPrimitives.set(executionId, set);
635
+ }
636
+ set.add(value);
637
+ }
638
+ }
639
+ }
640
+ __name(restoreProvenanceSnapshot, "restoreProvenanceSnapshot");
641
+ function createProvenanceProxy(value, source, readers = {
642
+ type: "public"
643
+ }, dependencies = []) {
644
+ if (value === null || value === void 0) {
645
+ return value;
646
+ }
647
+ if (typeof value !== "object" && typeof value !== "function") {
648
+ return value;
649
+ }
650
+ const id = nanoid.nanoid();
651
+ const metadata = {
652
+ id,
653
+ source,
654
+ readers,
655
+ dependencies,
656
+ context: {}
657
+ };
658
+ provenanceRegistry.set(id, metadata);
659
+ if (currentExecutionId) {
660
+ const ids = executionProvenanceIds.get(currentExecutionId);
661
+ if (ids) {
662
+ ids.add(id);
663
+ }
664
+ }
665
+ globalStore.set(id, metadata, currentExecutionId || void 0).catch((err) => {
666
+ atpRuntime.log.warn("Failed to persist provenance to store", {
667
+ error: err
668
+ });
669
+ });
670
+ try {
671
+ Object.defineProperty(value, PROVENANCE_ID_KEY, {
672
+ value: id,
673
+ writable: false,
674
+ enumerable: true,
675
+ configurable: true,
676
+ // @ts-ignore
677
+ __proto__: null
678
+ });
679
+ } catch (e) {
680
+ provenanceStore.set(value, metadata);
681
+ }
682
+ if (Array.isArray(value)) {
683
+ for (const item of value) {
684
+ if (typeof item === "object" && item !== null && !hasProvenance(item)) {
685
+ createProvenanceProxy(item, source, readers, [
686
+ id,
687
+ ...dependencies
688
+ ]);
689
+ }
690
+ }
691
+ } else if (typeof value === "object") {
692
+ for (const key in value) {
693
+ if (Object.prototype.hasOwnProperty.call(value, key) && key !== PROVENANCE_ID_KEY) {
694
+ const nestedValue = value[key];
695
+ if (typeof nestedValue === "object" && nestedValue !== null && !hasProvenance(nestedValue)) {
696
+ createProvenanceProxy(nestedValue, source, readers, [
697
+ id,
698
+ ...dependencies
699
+ ]);
700
+ } else if (typeof nestedValue === "string" || typeof nestedValue === "number") {
701
+ const primitiveKey = `${id}:${key}:${String(nestedValue)}`;
702
+ primitiveProvenanceMap.set(primitiveKey, metadata);
703
+ globalStore.setPrimitive(primitiveKey, metadata, currentExecutionId || void 0).catch((err) => {
704
+ atpRuntime.log.error("Failed to save primitive provenance to store", {
705
+ error: err
706
+ });
707
+ });
708
+ }
709
+ }
710
+ }
711
+ }
712
+ return value;
713
+ }
714
+ __name(createProvenanceProxy, "createProvenanceProxy");
715
+ function getProvenance(value) {
716
+ if (value === null || value === void 0) {
717
+ return null;
718
+ }
719
+ if (typeof value === "string" || typeof value === "number") {
720
+ const primitiveProvenance = getProvenanceForPrimitive(value);
721
+ if (primitiveProvenance) {
722
+ return primitiveProvenance;
723
+ }
724
+ }
725
+ if (typeof value === "object") {
726
+ const id = value[PROVENANCE_ID_KEY];
727
+ if (id && typeof id === "string") {
728
+ const metadata = provenanceRegistry.get(id);
729
+ if (metadata) {
730
+ return metadata;
731
+ }
732
+ }
733
+ if (PROVENANCE_KEY in value) {
734
+ return value[PROVENANCE_KEY];
735
+ }
736
+ const stored = provenanceStore.get(value);
737
+ if (stored) {
738
+ return stored;
739
+ }
740
+ }
741
+ return null;
742
+ }
743
+ __name(getProvenance, "getProvenance");
744
+ function hasProvenance(value) {
745
+ return getProvenance(value) !== null;
746
+ }
747
+ __name(hasProvenance, "hasProvenance");
748
+ function getAllProvenance(value, visited = /* @__PURE__ */ new Set()) {
749
+ if (value === null || value === void 0 || typeof value !== "object") {
750
+ return [];
751
+ }
752
+ if (visited.has(value)) {
753
+ return [];
754
+ }
755
+ visited.add(value);
756
+ const results = [];
757
+ const metadata = getProvenance(value);
758
+ if (metadata) {
759
+ results.push(metadata);
760
+ }
761
+ if (Array.isArray(value)) {
762
+ for (const item of value) {
763
+ results.push(...getAllProvenance(item, visited));
764
+ }
765
+ } else if (typeof value === "object") {
766
+ for (const key in value) {
767
+ if (key !== PROVENANCE_KEY && key !== PROVENANCE_ID_KEY && Object.prototype.hasOwnProperty.call(value, key)) {
768
+ results.push(...getAllProvenance(value[key], visited));
769
+ }
770
+ }
771
+ }
772
+ return results;
773
+ }
774
+ __name(getAllProvenance, "getAllProvenance");
775
+ function canRead(reader, permissions) {
776
+ if (permissions.type === "public") {
777
+ return true;
778
+ }
779
+ return permissions.readers.includes(reader);
780
+ }
781
+ __name(canRead, "canRead");
782
+
783
+ // src/policies/engine.ts
784
+ var SecurityPolicyEngine = class {
785
+ static {
786
+ __name(this, "SecurityPolicyEngine");
787
+ }
788
+ policies;
789
+ logger;
790
+ approvalCallback;
791
+ customGetProvenance;
792
+ constructor(policies, logger, customGetProvenance) {
793
+ this.policies = policies;
794
+ this.logger = logger;
795
+ this.customGetProvenance = customGetProvenance;
796
+ }
797
+ /**
798
+ * Set a custom getProvenance function (e.g., for AST mode)
799
+ */
800
+ setGetProvenance(fn) {
801
+ this.customGetProvenance = fn;
802
+ }
803
+ /**
804
+ * Set approval callback for policies that return action='approve'
805
+ */
806
+ setApprovalCallback(callback) {
807
+ this.approvalCallback = callback;
808
+ }
809
+ async checkTool(toolName, apiGroup, args) {
810
+ this.logger.debug("Checking security policies", {
811
+ toolName,
812
+ apiGroup,
813
+ policyCount: this.policies.length
814
+ });
815
+ const getProvenanceFn = this.customGetProvenance || getProvenance;
816
+ for (const policy of this.policies) {
817
+ const result = await policy.check(toolName, args, getProvenanceFn);
818
+ const action = this.normalizeAction(result);
819
+ if (action === "block") {
820
+ this.logger.warn("Security policy blocked tool execution", {
821
+ toolName,
822
+ apiGroup,
823
+ policy: policy.name,
824
+ reason: result.reason
825
+ });
826
+ throw new ProvenanceSecurityError(result.reason || `Policy ${policy.name} denied execution`, policy.name, toolName, {
827
+ apiGroup,
828
+ args: this.sanitizeArgs(args),
829
+ context: result.context
830
+ });
831
+ }
832
+ if (action === "approve") {
833
+ this.logger.info("Security policy requires approval", {
834
+ toolName,
835
+ apiGroup,
836
+ policy: policy.name,
837
+ reason: result.reason
838
+ });
839
+ const approved = await this.requestApproval(toolName, apiGroup, policy.name, result);
840
+ if (!approved) {
841
+ this.logger.warn("Security policy approval denied", {
842
+ toolName,
843
+ apiGroup,
844
+ policy: policy.name
845
+ });
846
+ throw new ProvenanceSecurityError(`Approval denied: ${result.reason || "Operation requires approval"}`, policy.name, toolName, {
847
+ apiGroup,
848
+ args: this.sanitizeArgs(args),
849
+ approvalDenied: true
850
+ });
851
+ }
852
+ this.logger.info("Security policy approval granted", {
853
+ toolName,
854
+ apiGroup,
855
+ policy: policy.name
856
+ });
857
+ }
858
+ if (action === "log") {
859
+ this.logger.warn("Security policy audit event", {
860
+ toolName,
861
+ apiGroup,
862
+ policy: policy.name,
863
+ reason: result.reason,
864
+ context: result.context,
865
+ args: this.sanitizeArgs(args)
866
+ });
867
+ }
868
+ }
869
+ this.logger.debug("All security policies passed", {
870
+ toolName,
871
+ apiGroup
872
+ });
873
+ }
874
+ normalizeAction(result) {
875
+ if (result.action) {
876
+ return result.action;
877
+ }
878
+ if (result.allowed !== void 0) {
879
+ return result.allowed ? "log" : "block";
880
+ }
881
+ return "log";
882
+ }
883
+ async requestApproval(toolName, apiGroup, policyName, result) {
884
+ if (!this.approvalCallback) {
885
+ this.logger.error("Approval required but no callback configured", {
886
+ toolName,
887
+ policy: policyName
888
+ });
889
+ throw new ProvenanceSecurityError("Approval required but approval handler not configured", policyName, toolName, {
890
+ requiresApproval: true
891
+ });
892
+ }
893
+ const message = result.reason || `Policy ${policyName} requires approval for ${toolName}`;
894
+ const context = {
895
+ toolName,
896
+ apiGroup,
897
+ policy: policyName,
898
+ ...result.context || {}
899
+ };
900
+ try {
901
+ return await this.approvalCallback(message, context);
902
+ } catch (error) {
903
+ this.logger.error("Approval request failed", {
904
+ error,
905
+ toolName,
906
+ policy: policyName
907
+ });
908
+ return false;
909
+ }
910
+ }
911
+ sanitizeArgs(args) {
912
+ const sanitized = {};
913
+ for (const [key, value] of Object.entries(args)) {
914
+ if (typeof value === "string" && value.length > 100) {
915
+ sanitized[key] = value.substring(0, 100) + "...";
916
+ } else if (typeof value === "object") {
917
+ sanitized[key] = "[object]";
918
+ } else {
919
+ sanitized[key] = value;
920
+ }
921
+ }
922
+ return sanitized;
923
+ }
924
+ };
925
+ function getAllProvenanceFromArgs(args, getProvenance2) {
926
+ const allProvenance = [];
927
+ const visited = /* @__PURE__ */ new Set();
928
+ function scan(value) {
929
+ if (value === null || value === void 0) return;
930
+ if (typeof value === "string" || typeof value === "number") {
931
+ try {
932
+ const primitiveProv = getProvenance2(value);
933
+ if (primitiveProv) {
934
+ allProvenance.push(primitiveProv);
935
+ }
936
+ } catch (error) {
937
+ }
938
+ return;
939
+ }
940
+ if (typeof value !== "object") return;
941
+ if (visited.has(value)) return;
942
+ visited.add(value);
943
+ const provenance = getProvenance2(value);
944
+ if (provenance) {
945
+ allProvenance.push(provenance);
946
+ }
947
+ if (Array.isArray(value)) {
948
+ for (const item of value) {
949
+ scan(item);
950
+ }
951
+ } else {
952
+ for (const key in value) {
953
+ if (Object.prototype.hasOwnProperty.call(value, key)) {
954
+ scan(value[key]);
955
+ }
956
+ }
957
+ }
958
+ }
959
+ __name(scan, "scan");
960
+ for (const key in args) {
961
+ if (Object.prototype.hasOwnProperty.call(args, key)) {
962
+ scan(args[key]);
963
+ }
964
+ }
965
+ return allProvenance;
966
+ }
967
+ __name(getAllProvenanceFromArgs, "getAllProvenanceFromArgs");
968
+ var preventDataExfiltration = {
969
+ name: "prevent-data-exfiltration",
970
+ description: "Prevents sending data to recipients who cannot read it",
971
+ check: /* @__PURE__ */ __name((toolName, args, getProvenance2) => {
972
+ const recipientKeys = [
973
+ "to",
974
+ "recipient",
975
+ "recipients",
976
+ "email",
977
+ "address"
978
+ ];
979
+ let recipient = null;
980
+ for (const key of recipientKeys) {
981
+ if (args[key] && typeof args[key] === "string") {
982
+ recipient = args[key];
983
+ break;
984
+ }
985
+ }
986
+ if (!recipient) {
987
+ return {
988
+ action: "log"
989
+ };
990
+ }
991
+ const allProvenance = getAllProvenanceFromArgs(args, getProvenance2);
992
+ for (const metadata of allProvenance) {
993
+ if (metadata.source.type === exports.ProvenanceSource.TOOL) {
994
+ if (metadata.readers.type === "restricted") {
995
+ if (!canRead(recipient, metadata.readers)) {
996
+ return {
997
+ action: "block",
998
+ reason: `Recipient "${recipient}" cannot read data from ${metadata.source.toolName}. Authorized readers: ${metadata.readers.readers.join(", ")}`,
999
+ policy: "prevent-data-exfiltration",
1000
+ context: {
1001
+ recipient,
1002
+ toolSource: metadata.source.toolName,
1003
+ authorizedReaders: metadata.readers.readers
1004
+ }
1005
+ };
1006
+ }
1007
+ }
1008
+ }
1009
+ }
1010
+ return {
1011
+ action: "log"
1012
+ };
1013
+ }, "check")
1014
+ };
1015
+ var preventDataExfiltrationWithApproval = {
1016
+ name: "prevent-data-exfiltration-approval",
1017
+ description: "Requires approval for sending data to recipients who cannot read it",
1018
+ check: /* @__PURE__ */ __name((toolName, args, getProvenance2) => {
1019
+ const recipientKeys = [
1020
+ "to",
1021
+ "recipient",
1022
+ "recipients",
1023
+ "email",
1024
+ "address"
1025
+ ];
1026
+ let recipient = null;
1027
+ for (const key of recipientKeys) {
1028
+ if (args[key] && typeof args[key] === "string") {
1029
+ recipient = args[key];
1030
+ break;
1031
+ }
1032
+ }
1033
+ if (!recipient) {
1034
+ return {
1035
+ action: "log"
1036
+ };
1037
+ }
1038
+ const allProvenance = getAllProvenanceFromArgs(args, getProvenance2);
1039
+ for (const metadata of allProvenance) {
1040
+ if (metadata.source.type === exports.ProvenanceSource.TOOL) {
1041
+ if (metadata.readers.type === "restricted") {
1042
+ if (!canRead(recipient, metadata.readers)) {
1043
+ return {
1044
+ action: "approve",
1045
+ reason: `Sending data from ${metadata.source.toolName} to "${recipient}" (not in authorized readers)`,
1046
+ policy: "prevent-data-exfiltration-approval",
1047
+ context: {
1048
+ recipient,
1049
+ toolSource: metadata.source.toolName,
1050
+ authorizedReaders: metadata.readers.readers,
1051
+ sensitiveFields: Object.keys(args).filter((k) => args[k] !== null)
1052
+ }
1053
+ };
1054
+ }
1055
+ }
1056
+ }
1057
+ }
1058
+ return {
1059
+ action: "log"
1060
+ };
1061
+ }, "check")
1062
+ };
1063
+ var requireUserOrigin = {
1064
+ name: "require-user-origin",
1065
+ description: "Requires critical parameters to come directly from user input",
1066
+ check: /* @__PURE__ */ __name((toolName, args, getProvenance2) => {
1067
+ const criticalTools = [
1068
+ "deleteDatabase",
1069
+ "dropTable",
1070
+ "executeSQL",
1071
+ "sendMoney",
1072
+ "transfer"
1073
+ ];
1074
+ if (!criticalTools.some((t) => toolName.toLowerCase().includes(t.toLowerCase()))) {
1075
+ return {
1076
+ action: "log"
1077
+ };
1078
+ }
1079
+ for (const [key, value] of Object.entries(args)) {
1080
+ const allProvenance = getAllProvenance(value);
1081
+ for (const metadata of allProvenance) {
1082
+ if (metadata.source.type !== exports.ProvenanceSource.USER && metadata.source.type !== exports.ProvenanceSource.SYSTEM) {
1083
+ return {
1084
+ action: "block",
1085
+ reason: `Critical tool "${toolName}" parameter "${key}" must come from user input, but came from ${metadata.source.type}`,
1086
+ policy: "require-user-origin",
1087
+ context: {
1088
+ toolName,
1089
+ parameterKey: key,
1090
+ actualSource: metadata.source.type
1091
+ }
1092
+ };
1093
+ }
1094
+ }
1095
+ }
1096
+ return {
1097
+ action: "log"
1098
+ };
1099
+ }, "check")
1100
+ };
1101
+ var requireUserOriginWithApproval = {
1102
+ name: "require-user-origin-approval",
1103
+ description: "Requires approval for critical operations with non-user data",
1104
+ check: /* @__PURE__ */ __name((toolName, args, getProvenance2) => {
1105
+ const criticalTools = [
1106
+ "deleteDatabase",
1107
+ "dropTable",
1108
+ "executeSQL",
1109
+ "sendMoney",
1110
+ "transfer"
1111
+ ];
1112
+ if (!criticalTools.some((t) => toolName.toLowerCase().includes(t.toLowerCase()))) {
1113
+ return {
1114
+ action: "log"
1115
+ };
1116
+ }
1117
+ for (const [key, value] of Object.entries(args)) {
1118
+ const allProvenance = getAllProvenance(value);
1119
+ for (const metadata of allProvenance) {
1120
+ if (metadata.source.type !== exports.ProvenanceSource.USER && metadata.source.type !== exports.ProvenanceSource.SYSTEM) {
1121
+ return {
1122
+ action: "approve",
1123
+ reason: `Critical operation "${toolName}" with parameter "${key}" from ${metadata.source.type} source`,
1124
+ policy: "require-user-origin-approval",
1125
+ context: {
1126
+ toolName,
1127
+ parameterKey: key,
1128
+ actualSource: metadata.source.type,
1129
+ value: String(value).substring(0, 100)
1130
+ }
1131
+ };
1132
+ }
1133
+ }
1134
+ }
1135
+ return {
1136
+ action: "log"
1137
+ };
1138
+ }, "check")
1139
+ };
1140
+ var blockLLMRecipients = {
1141
+ name: "block-llm-recipients",
1142
+ description: "Blocks sending data to LLM-extracted email addresses",
1143
+ check: /* @__PURE__ */ __name((toolName, args, getProvenance2) => {
1144
+ const recipientKeys = [
1145
+ "to",
1146
+ "recipient",
1147
+ "recipients",
1148
+ "email"
1149
+ ];
1150
+ for (const key of recipientKeys) {
1151
+ if (!args[key]) continue;
1152
+ const metadata = getProvenance2(args[key]);
1153
+ if (metadata && metadata.source.type === exports.ProvenanceSource.LLM) {
1154
+ return {
1155
+ action: "block",
1156
+ reason: `Cannot send to LLM-extracted recipient in parameter "${key}". Recipients must come from user input or trusted sources.`,
1157
+ policy: "block-llm-recipients",
1158
+ context: {
1159
+ parameterKey: key,
1160
+ recipientValue: String(args[key]).substring(0, 50)
1161
+ }
1162
+ };
1163
+ }
1164
+ }
1165
+ return {
1166
+ action: "log"
1167
+ };
1168
+ }, "check")
1169
+ };
1170
+ var blockLLMRecipientsWithApproval = {
1171
+ name: "block-llm-recipients-approval",
1172
+ description: "Requires approval for sending to LLM-extracted email addresses",
1173
+ check: /* @__PURE__ */ __name((toolName, args, getProvenance2) => {
1174
+ const recipientKeys = [
1175
+ "to",
1176
+ "recipient",
1177
+ "recipients",
1178
+ "email"
1179
+ ];
1180
+ for (const key of recipientKeys) {
1181
+ if (!args[key]) continue;
1182
+ const metadata = getProvenance2(args[key]);
1183
+ if (metadata && metadata.source.type === exports.ProvenanceSource.LLM) {
1184
+ return {
1185
+ action: "approve",
1186
+ reason: `Sending to LLM-extracted recipient "${args[key]}" in parameter "${key}"`,
1187
+ policy: "block-llm-recipients-approval",
1188
+ context: {
1189
+ parameterKey: key,
1190
+ recipientValue: String(args[key]),
1191
+ llmOperation: metadata.source.operation
1192
+ }
1193
+ };
1194
+ }
1195
+ }
1196
+ return {
1197
+ action: "log"
1198
+ };
1199
+ }, "check")
1200
+ };
1201
+ var auditSensitiveAccess = {
1202
+ name: "audit-sensitive-access",
1203
+ description: "Logs access to sensitive data (does not block)",
1204
+ check: /* @__PURE__ */ __name((toolName, args, getProvenance2) => {
1205
+ const sensitiveTools = [
1206
+ "getPassword",
1207
+ "getCreditCard",
1208
+ "getSSN",
1209
+ "getBankAccount"
1210
+ ];
1211
+ if (sensitiveTools.some((t) => toolName.toLowerCase().includes(t.toLowerCase()))) {
1212
+ const allProvenance = getAllProvenance(args);
1213
+ return {
1214
+ action: "log",
1215
+ reason: `Sensitive data accessed via ${toolName}`,
1216
+ policy: "audit-sensitive-access",
1217
+ context: {
1218
+ toolName,
1219
+ provenanceChain: allProvenance.map((p) => ({
1220
+ source: p.source,
1221
+ id: p.id
1222
+ }))
1223
+ }
1224
+ };
1225
+ }
1226
+ return {
1227
+ action: "log"
1228
+ };
1229
+ }, "check")
1230
+ };
1231
+ function createCustomPolicy(name, description, checkFn) {
1232
+ return {
1233
+ name,
1234
+ description,
1235
+ check: checkFn
1236
+ };
1237
+ }
1238
+ __name(createCustomPolicy, "createCustomPolicy");
1239
+ function getBuiltInPolicies() {
1240
+ return [
1241
+ preventDataExfiltration,
1242
+ requireUserOrigin,
1243
+ blockLLMRecipients,
1244
+ auditSensitiveAccess
1245
+ ];
1246
+ }
1247
+ __name(getBuiltInPolicies, "getBuiltInPolicies");
1248
+ function getBuiltInPoliciesWithApproval() {
1249
+ return [
1250
+ preventDataExfiltrationWithApproval,
1251
+ requireUserOriginWithApproval,
1252
+ blockLLMRecipientsWithApproval,
1253
+ auditSensitiveAccess
1254
+ ];
1255
+ }
1256
+ __name(getBuiltInPoliciesWithApproval, "getBuiltInPoliciesWithApproval");
1257
+
1258
+ // src/policies/declarative.ts
1259
+ function resolveValue(path, args, getProvenance2) {
1260
+ const parts = path.split(".");
1261
+ const root = parts.shift();
1262
+ if (root === "args") {
1263
+ let current = args;
1264
+ for (const part of parts) {
1265
+ if (current === null || current === void 0) {
1266
+ return void 0;
1267
+ }
1268
+ current = current[part];
1269
+ }
1270
+ return current;
1271
+ }
1272
+ if (root === "provenance" && parts[0] === "args") {
1273
+ parts.shift();
1274
+ const argName = parts.shift();
1275
+ if (!argName) return void 0;
1276
+ const argValue = args[argName];
1277
+ let remainingParts = [
1278
+ ...parts
1279
+ ];
1280
+ const metadataKeys = [
1281
+ "source",
1282
+ "readers",
1283
+ "dependencies",
1284
+ "id",
1285
+ "context"
1286
+ ];
1287
+ let splitIndex = -1;
1288
+ for (let i = 0; i < remainingParts.length; i++) {
1289
+ if (metadataKeys.includes(remainingParts[i])) {
1290
+ splitIndex = i;
1291
+ break;
1292
+ }
1293
+ }
1294
+ if (splitIndex === -1) {
1295
+ return void 0;
1296
+ }
1297
+ let valuePath = remainingParts.slice(0, splitIndex);
1298
+ let metaPath = remainingParts.slice(splitIndex);
1299
+ let currentVal = argValue;
1300
+ for (const part of valuePath) {
1301
+ if (currentVal === null || currentVal === void 0) return void 0;
1302
+ currentVal = currentVal[part];
1303
+ }
1304
+ const metadata = getProvenance2(currentVal);
1305
+ if (!metadata) return void 0;
1306
+ let currentMeta = metadata;
1307
+ for (const part of metaPath) {
1308
+ if (currentMeta === null || currentMeta === void 0) return void 0;
1309
+ currentMeta = currentMeta[part];
1310
+ }
1311
+ return currentMeta;
1312
+ }
1313
+ return void 0;
1314
+ }
1315
+ __name(resolveValue, "resolveValue");
1316
+ function evaluateCondition(actual, operator, expected) {
1317
+ switch (operator) {
1318
+ case "equals":
1319
+ return actual === expected;
1320
+ case "notEquals":
1321
+ return actual !== expected;
1322
+ case "contains":
1323
+ return Array.isArray(actual) || typeof actual === "string" ? actual.includes(expected) : false;
1324
+ case "notContains":
1325
+ return Array.isArray(actual) || typeof actual === "string" ? !actual.includes(expected) : true;
1326
+ case "startsWith":
1327
+ return typeof actual === "string" ? actual.startsWith(expected) : false;
1328
+ case "notStartsWith":
1329
+ return typeof actual === "string" ? !actual.startsWith(expected) : true;
1330
+ case "endsWith":
1331
+ return typeof actual === "string" ? actual.endsWith(expected) : false;
1332
+ case "notEndsWith":
1333
+ return typeof actual === "string" ? !actual.endsWith(expected) : true;
1334
+ case "matches":
1335
+ if (typeof actual === "string") {
1336
+ return new RegExp(expected).test(actual);
1337
+ }
1338
+ if (typeof actual === "number" && typeof expected === "string") {
1339
+ const match = expected.match(/^([<>]=?|==|!=)(\d+(?:\.\d+)?)$/);
1340
+ if (match) {
1341
+ const [, op, value] = match;
1342
+ const numValue = parseFloat(value);
1343
+ switch (op) {
1344
+ case ">":
1345
+ return actual > numValue;
1346
+ case ">=":
1347
+ return actual >= numValue;
1348
+ case "<":
1349
+ return actual < numValue;
1350
+ case "<=":
1351
+ return actual <= numValue;
1352
+ case "==":
1353
+ return actual === numValue;
1354
+ case "!=":
1355
+ return actual !== numValue;
1356
+ }
1357
+ }
1358
+ }
1359
+ return false;
1360
+ case "in":
1361
+ return Array.isArray(expected) ? expected.includes(actual) : false;
1362
+ case "notIn":
1363
+ return Array.isArray(expected) ? !expected.includes(actual) : true;
1364
+ default:
1365
+ return false;
1366
+ }
1367
+ }
1368
+ __name(evaluateCondition, "evaluateCondition");
1369
+ function createDeclarativePolicy(config) {
1370
+ return {
1371
+ name: config.id,
1372
+ description: config.description,
1373
+ check: /* @__PURE__ */ __name(async (toolName, args, getProvenance2) => {
1374
+ if (config.scope.toolName) {
1375
+ const toolRegex = new RegExp(`^${config.scope.toolName}$`);
1376
+ if (!toolRegex.test(toolName)) {
1377
+ return {
1378
+ action: "log"
1379
+ };
1380
+ }
1381
+ }
1382
+ if (config.scope.apiGroup) {
1383
+ const extractedGroup = toolName.split(".")[0] || "";
1384
+ const groupRegex = new RegExp(`^${config.scope.apiGroup}$`);
1385
+ if (!groupRegex.test(extractedGroup)) {
1386
+ return {
1387
+ action: "log"
1388
+ };
1389
+ }
1390
+ }
1391
+ for (const rule of config.rules) {
1392
+ const allMatch = rule.conditions.every((condition) => {
1393
+ const actualValue = resolveValue(condition.field, args, getProvenance2);
1394
+ return evaluateCondition(actualValue, condition.operator, condition.value);
1395
+ });
1396
+ if (allMatch) {
1397
+ return {
1398
+ action: rule.action,
1399
+ reason: rule.reason || `Matched rule ${rule.id || "unknown"} in policy ${config.id}`,
1400
+ policy: config.id,
1401
+ context: {
1402
+ ruleId: rule.id,
1403
+ conditions: rule.conditions
1404
+ }
1405
+ };
1406
+ }
1407
+ }
1408
+ return {
1409
+ action: "log"
1410
+ };
1411
+ }, "check")
1412
+ };
1413
+ }
1414
+ __name(createDeclarativePolicy, "createDeclarativePolicy");
1415
+ function loadDeclarativePolicies(config) {
1416
+ if (Array.isArray(config)) {
1417
+ return config.map(createDeclarativePolicy);
1418
+ }
1419
+ return config.policies.map(createDeclarativePolicy);
1420
+ }
1421
+ __name(loadDeclarativePolicies, "loadDeclarativePolicies");
1422
+ var OperatorSchema = zod.z.enum([
1423
+ "equals",
1424
+ "notEquals",
1425
+ "contains",
1426
+ "notContains",
1427
+ "startsWith",
1428
+ "notStartsWith",
1429
+ "endsWith",
1430
+ "notEndsWith",
1431
+ "matches",
1432
+ "in",
1433
+ "notIn"
1434
+ ]);
1435
+ var ConditionSchema = zod.z.object({
1436
+ field: zod.z.string().describe("Field to check (e.g. args.paramName, provenance.args.param.source.type)"),
1437
+ operator: OperatorSchema,
1438
+ value: zod.z.any().describe("Value to compare against")
1439
+ });
1440
+ var PolicyActionSchema = zod.z.enum([
1441
+ "log",
1442
+ "approve",
1443
+ "block"
1444
+ ]);
1445
+ var PolicyRuleSchema = zod.z.object({
1446
+ id: zod.z.string().optional(),
1447
+ action: PolicyActionSchema,
1448
+ conditions: zod.z.array(ConditionSchema).describe("All conditions must match (implicit AND)"),
1449
+ reason: zod.z.string().optional()
1450
+ });
1451
+ var DeclarativePolicyConfigSchema = zod.z.object({
1452
+ id: zod.z.string(),
1453
+ description: zod.z.string().optional(),
1454
+ scope: zod.z.object({
1455
+ toolName: zod.z.string().optional().describe("Regex pattern or exact match for tool name"),
1456
+ apiGroup: zod.z.string().optional().describe("Regex pattern or exact match for API group")
1457
+ }),
1458
+ rules: zod.z.array(PolicyRuleSchema).describe("Rules are evaluated in order. First match wins.")
1459
+ });
1460
+ var PolicyConfigurationSchema = zod.z.object({
1461
+ version: zod.z.string(),
1462
+ policies: zod.z.array(DeclarativePolicyConfigSchema)
1463
+ });
1464
+
1465
+ // src/policies/builder.ts
1466
+ var RuleBuilder = class {
1467
+ static {
1468
+ __name(this, "RuleBuilder");
1469
+ }
1470
+ rule = {
1471
+ action: "log",
1472
+ conditions: []
1473
+ };
1474
+ constructor(action = "log") {
1475
+ this.rule.action = action;
1476
+ }
1477
+ action(action) {
1478
+ this.rule.action = action;
1479
+ return this;
1480
+ }
1481
+ id(id) {
1482
+ this.rule.id = id;
1483
+ return this;
1484
+ }
1485
+ reason(reason) {
1486
+ this.rule.reason = reason;
1487
+ return this;
1488
+ }
1489
+ condition(field, operator, value) {
1490
+ this.rule.conditions.push({
1491
+ field,
1492
+ operator,
1493
+ value
1494
+ });
1495
+ return this;
1496
+ }
1497
+ build() {
1498
+ return this.rule;
1499
+ }
1500
+ };
1501
+ var PolicyBuilder = class {
1502
+ static {
1503
+ __name(this, "PolicyBuilder");
1504
+ }
1505
+ config;
1506
+ constructor(id) {
1507
+ this.config = {
1508
+ id,
1509
+ scope: {},
1510
+ rules: []
1511
+ };
1512
+ }
1513
+ description(desc) {
1514
+ this.config.description = desc;
1515
+ return this;
1516
+ }
1517
+ scopeTool(toolNamePattern) {
1518
+ this.config.scope.toolName = toolNamePattern;
1519
+ return this;
1520
+ }
1521
+ scopeApiGroup(apiGroupPattern) {
1522
+ this.config.scope.apiGroup = apiGroupPattern;
1523
+ return this;
1524
+ }
1525
+ /**
1526
+ * Add a rule using a builder callback
1527
+ * @example
1528
+ * .addRule(r => r.action('block').condition('args.amount', 'matches', '>1000'))
1529
+ */
1530
+ addRule(buildFn) {
1531
+ const builder = new RuleBuilder();
1532
+ this.config.rules.push(buildFn(builder).build());
1533
+ return this;
1534
+ }
1535
+ /**
1536
+ * Add a fully formed rule object
1537
+ */
1538
+ addRuleObject(rule) {
1539
+ this.config.rules.push(rule);
1540
+ return this;
1541
+ }
1542
+ build() {
1543
+ return this.config;
1544
+ }
1545
+ };
1546
+
1547
+ // src/policies/dynamic.ts
1548
+ var DynamicPolicyRegistry = class {
1549
+ static {
1550
+ __name(this, "DynamicPolicyRegistry");
1551
+ }
1552
+ name = "dynamic-policy-registry";
1553
+ description = "Container for dynamically managed security policies";
1554
+ policies = /* @__PURE__ */ new Map();
1555
+ constructor(initialPolicies = []) {
1556
+ for (const policy of initialPolicies) {
1557
+ this.policies.set(policy.name, policy);
1558
+ }
1559
+ }
1560
+ /**
1561
+ * Add or update a policy
1562
+ */
1563
+ addPolicy(policy) {
1564
+ this.policies.set(policy.name, policy);
1565
+ }
1566
+ /**
1567
+ * Remove a policy by name
1568
+ */
1569
+ removePolicy(name) {
1570
+ this.policies.delete(name);
1571
+ }
1572
+ /**
1573
+ * clear all policies
1574
+ */
1575
+ clear() {
1576
+ this.policies.clear();
1577
+ }
1578
+ /**
1579
+ * Load policies from declarative configurations (JSON)
1580
+ * This is useful for loading policies saved from a UI
1581
+ */
1582
+ loadFromConfigs(configs, replace = false) {
1583
+ if (replace) {
1584
+ this.policies.clear();
1585
+ }
1586
+ for (const config of configs) {
1587
+ const policy = createDeclarativePolicy(config);
1588
+ this.policies.set(policy.name, policy);
1589
+ }
1590
+ }
1591
+ /**
1592
+ * Get all registered policies
1593
+ */
1594
+ getPolicies() {
1595
+ return Array.from(this.policies.values());
1596
+ }
1597
+ /**
1598
+ * Implementation of the SecurityPolicy check interface.
1599
+ * Delegates to all registered policies.
1600
+ */
1601
+ async check(toolName, args, getProvenance2) {
1602
+ let requiresApproval = null;
1603
+ for (const policy of this.policies.values()) {
1604
+ const result = await policy.check(toolName, args, getProvenance2);
1605
+ if (result.action === "block") {
1606
+ return result;
1607
+ }
1608
+ if (result.action === "approve") {
1609
+ if (!requiresApproval) {
1610
+ requiresApproval = result;
1611
+ }
1612
+ }
1613
+ }
1614
+ if (requiresApproval) {
1615
+ return requiresApproval;
1616
+ }
1617
+ return {
1618
+ action: "log"
1619
+ };
1620
+ }
1621
+ };
1622
+ function instrumentCode(code) {
1623
+ const wrappedCode = `(async function() {
1624
+ ${code}
1625
+ })`;
1626
+ const ast = acorn__namespace.parse(wrappedCode, {
1627
+ ecmaVersion: 2022,
1628
+ sourceType: "script"
1629
+ });
1630
+ const context = {
1631
+ trackingCalls: 0
1632
+ };
1633
+ walk__namespace.simple(ast, {
1634
+ BinaryExpression(node) {
1635
+ wrapBinaryExpression(node, context);
1636
+ },
1637
+ AssignmentExpression(node) {
1638
+ wrapAssignment(node, context);
1639
+ },
1640
+ CallExpression(node) {
1641
+ if (node.callee.type === "MemberExpression") {
1642
+ wrapMethodCall(node, context);
1643
+ }
1644
+ },
1645
+ TemplateLiteral(node) {
1646
+ wrapTemplateLiteral(node, context);
1647
+ }
1648
+ });
1649
+ let instrumentedCode = escodegen__namespace.generate(ast);
1650
+ if (instrumentedCode.endsWith(");")) {
1651
+ instrumentedCode = instrumentedCode.slice(0, -1);
1652
+ }
1653
+ return {
1654
+ code: instrumentedCode,
1655
+ metadata: {
1656
+ trackingCalls: context.trackingCalls
1657
+ }
1658
+ };
1659
+ }
1660
+ __name(instrumentCode, "instrumentCode");
1661
+ function wrapBinaryExpression(node, context) {
1662
+ context.trackingCalls++;
1663
+ const originalNode = {
1664
+ ...node
1665
+ };
1666
+ node.type = "CallExpression";
1667
+ node.callee = {
1668
+ type: "Identifier",
1669
+ name: "__track_binary"
1670
+ };
1671
+ node.arguments = [
1672
+ originalNode.left,
1673
+ originalNode.right,
1674
+ {
1675
+ type: "Literal",
1676
+ value: originalNode.operator
1677
+ }
1678
+ ];
1679
+ }
1680
+ __name(wrapBinaryExpression, "wrapBinaryExpression");
1681
+ function wrapAssignment(node, context) {
1682
+ context.trackingCalls++;
1683
+ const originalRight = node.right;
1684
+ node.right = {
1685
+ type: "CallExpression",
1686
+ callee: {
1687
+ type: "Identifier",
1688
+ name: "__track_assign"
1689
+ },
1690
+ arguments: [
1691
+ {
1692
+ type: "Literal",
1693
+ value: node.left.type === "Identifier" ? node.left.name : "unknown"
1694
+ },
1695
+ originalRight
1696
+ ]
1697
+ };
1698
+ }
1699
+ __name(wrapAssignment, "wrapAssignment");
1700
+ function wrapMethodCall(node, context) {
1701
+ const obj = node.callee.object;
1702
+ const isAPICall = obj.type === "Identifier" && (obj.name === "api" || obj.name === "atp") || obj.type === "MemberExpression" && isAPIObject(obj);
1703
+ if (!isAPICall) {
1704
+ return;
1705
+ }
1706
+ context.trackingCalls++;
1707
+ const originalNode = {
1708
+ ...node
1709
+ };
1710
+ node.type = "CallExpression";
1711
+ node.callee = {
1712
+ type: "Identifier",
1713
+ name: "__track_method"
1714
+ };
1715
+ node.arguments = [
1716
+ originalNode.callee.object,
1717
+ {
1718
+ type: "Literal",
1719
+ value: originalNode.callee.property.name || originalNode.callee.property.value
1720
+ },
1721
+ {
1722
+ type: "ArrayExpression",
1723
+ elements: originalNode.arguments
1724
+ }
1725
+ ];
1726
+ }
1727
+ __name(wrapMethodCall, "wrapMethodCall");
1728
+ function isAPIObject(node) {
1729
+ if (node.type === "Identifier") {
1730
+ return node.name === "api" || node.name === "atp";
1731
+ }
1732
+ if (node.type === "MemberExpression") {
1733
+ return isAPIObject(node.object);
1734
+ }
1735
+ return false;
1736
+ }
1737
+ __name(isAPIObject, "isAPIObject");
1738
+ function wrapTemplateLiteral(node, context) {
1739
+ context.trackingCalls++;
1740
+ const originalNode = {
1741
+ ...node
1742
+ };
1743
+ node.type = "CallExpression";
1744
+ node.callee = {
1745
+ type: "Identifier",
1746
+ name: "__track_template"
1747
+ };
1748
+ node.arguments = [
1749
+ {
1750
+ type: "ArrayExpression",
1751
+ elements: originalNode.expressions || []
1752
+ },
1753
+ {
1754
+ type: "ArrayExpression",
1755
+ elements: (originalNode.quasis || []).map((quasi) => ({
1756
+ type: "Literal",
1757
+ value: quasi.value.cooked || quasi.value.raw
1758
+ }))
1759
+ }
1760
+ ];
1761
+ }
1762
+ __name(wrapTemplateLiteral, "wrapTemplateLiteral");
1763
+ var ASTProvenanceTracker = class {
1764
+ static {
1765
+ __name(this, "ASTProvenanceTracker");
1766
+ }
1767
+ metadata = /* @__PURE__ */ new Map();
1768
+ valueToId = /* @__PURE__ */ new WeakMap();
1769
+ nextId = 0;
1770
+ getId(value) {
1771
+ if (typeof value === "object" && value !== null) {
1772
+ const existing = this.valueToId.get(value);
1773
+ if (existing) return existing;
1774
+ const id = `tracked_${this.nextId++}`;
1775
+ this.valueToId.set(value, id);
1776
+ return id;
1777
+ }
1778
+ return `primitive_${nanoid.nanoid()}`;
1779
+ }
1780
+ track(value, source, dependencies = []) {
1781
+ if (value === null || value === void 0) {
1782
+ return value;
1783
+ }
1784
+ const id = this.getId(value);
1785
+ if (!this.metadata.has(id)) {
1786
+ this.metadata.set(id, {
1787
+ id,
1788
+ source,
1789
+ readers: {
1790
+ type: "public"
1791
+ },
1792
+ dependencies
1793
+ });
1794
+ }
1795
+ return value;
1796
+ }
1797
+ trackBinary(left, right, operator) {
1798
+ const leftId = this.getId(left);
1799
+ const rightId = this.getId(right);
1800
+ const leftProv = getProvenance(left) || getProvenanceForPrimitive(left);
1801
+ const rightProv = getProvenance(right) || getProvenanceForPrimitive(right);
1802
+ const toolMetadata = leftProv?.source.type === exports.ProvenanceSource.TOOL ? leftProv : rightProv?.source.type === exports.ProvenanceSource.TOOL ? rightProv : null;
1803
+ let result;
1804
+ switch (operator) {
1805
+ case "+":
1806
+ result = left + right;
1807
+ if (typeof result === "string" && toolMetadata) {
1808
+ markPrimitiveTainted(result, toolMetadata);
1809
+ }
1810
+ break;
1811
+ case "-":
1812
+ result = left - right;
1813
+ break;
1814
+ case "*":
1815
+ result = left * right;
1816
+ break;
1817
+ case "/":
1818
+ result = left / right;
1819
+ break;
1820
+ case "%":
1821
+ result = left % right;
1822
+ break;
1823
+ case "===":
1824
+ case "==":
1825
+ result = left === right;
1826
+ break;
1827
+ case "!==":
1828
+ case "!=":
1829
+ result = left !== right;
1830
+ break;
1831
+ case "<":
1832
+ result = left < right;
1833
+ break;
1834
+ case ">":
1835
+ result = left > right;
1836
+ break;
1837
+ case "<=":
1838
+ result = left <= right;
1839
+ break;
1840
+ case ">=":
1841
+ result = left >= right;
1842
+ break;
1843
+ case "&&":
1844
+ result = left && right;
1845
+ break;
1846
+ case "||":
1847
+ result = left || right;
1848
+ break;
1849
+ default:
1850
+ result = void 0;
1851
+ }
1852
+ return this.track(result, {
1853
+ type: "system",
1854
+ operation: `binary_${operator}`,
1855
+ timestamp: Date.now()
1856
+ }, [
1857
+ leftId,
1858
+ rightId
1859
+ ]);
1860
+ }
1861
+ trackAssign(name, value) {
1862
+ return this.track(value, {
1863
+ type: "system",
1864
+ operation: "assignment",
1865
+ timestamp: Date.now()
1866
+ }, [
1867
+ this.getId(value)
1868
+ ]);
1869
+ }
1870
+ trackMethod(object, method, args) {
1871
+ if (typeof object === "object" && object !== null && method in object) {
1872
+ const result = object[method](...args);
1873
+ return this.track(result, {
1874
+ type: "system",
1875
+ operation: `method_${method}`,
1876
+ timestamp: Date.now()
1877
+ }, [
1878
+ this.getId(object),
1879
+ ...args.map((a) => this.getId(a))
1880
+ ]);
1881
+ }
1882
+ return void 0;
1883
+ }
1884
+ trackTemplate(expressions, quasis) {
1885
+ let result = "";
1886
+ let toolMetadata = null;
1887
+ for (let i = 0; i < quasis.length; i++) {
1888
+ result += quasis[i] || "";
1889
+ if (i < expressions.length) {
1890
+ const expr = expressions[i];
1891
+ result += String(expr);
1892
+ const prov = getProvenance(expr) || getProvenanceForPrimitive(expr);
1893
+ if (prov && prov.source.type === exports.ProvenanceSource.TOOL && !toolMetadata) {
1894
+ toolMetadata = prov;
1895
+ }
1896
+ }
1897
+ }
1898
+ if (toolMetadata) {
1899
+ markPrimitiveTainted(result, toolMetadata);
1900
+ }
1901
+ return result;
1902
+ }
1903
+ getMetadata(value) {
1904
+ if (typeof value === "object" && value !== null) {
1905
+ const id = this.valueToId.get(value);
1906
+ if (id) {
1907
+ return this.metadata.get(id) || null;
1908
+ }
1909
+ }
1910
+ return null;
1911
+ }
1912
+ getAllMetadata() {
1913
+ return new Map(this.metadata);
1914
+ }
1915
+ restoreMetadata(metadata) {
1916
+ this.metadata = new Map(metadata);
1917
+ }
1918
+ };
1919
+ function createTrackingRuntime() {
1920
+ const tracker = new ASTProvenanceTracker();
1921
+ return {
1922
+ tracker,
1923
+ runtime: {
1924
+ __track: /* @__PURE__ */ __name((value, source, deps) => tracker.track(value, source, deps), "__track"),
1925
+ __track_binary: /* @__PURE__ */ __name((left, right, operator) => tracker.trackBinary(left, right, operator), "__track_binary"),
1926
+ __track_assign: /* @__PURE__ */ __name((name, value) => tracker.trackAssign(name, value), "__track_assign"),
1927
+ __track_method: /* @__PURE__ */ __name((object, method, args) => tracker.trackMethod(object, method, args), "__track_method"),
1928
+ __track_template: /* @__PURE__ */ __name((expressions, quasis) => tracker.trackTemplate(expressions, quasis), "__track_template"),
1929
+ __get_provenance: /* @__PURE__ */ __name((value) => tracker.getMetadata(value), "__get_provenance")
1930
+ }
1931
+ };
1932
+ }
1933
+ __name(createTrackingRuntime, "createTrackingRuntime");
1934
+
1935
+ exports.ConditionSchema = ConditionSchema;
1936
+ exports.DeclarativePolicyConfigSchema = DeclarativePolicyConfigSchema;
1937
+ exports.DynamicPolicyRegistry = DynamicPolicyRegistry;
1938
+ exports.InMemoryProvenanceStore = InMemoryProvenanceStore;
1939
+ exports.OperatorSchema = OperatorSchema;
1940
+ exports.PolicyActionSchema = PolicyActionSchema;
1941
+ exports.PolicyBuilder = PolicyBuilder;
1942
+ exports.PolicyConfigurationSchema = PolicyConfigurationSchema;
1943
+ exports.PolicyRuleSchema = PolicyRuleSchema;
1944
+ exports.ProvenanceSecurityError = ProvenanceSecurityError;
1945
+ exports.RuleBuilder = RuleBuilder;
1946
+ exports.SecurityPolicyEngine = SecurityPolicyEngine;
1947
+ exports.auditSensitiveAccess = auditSensitiveAccess;
1948
+ exports.blockLLMRecipients = blockLLMRecipients;
1949
+ exports.blockLLMRecipientsWithApproval = blockLLMRecipientsWithApproval;
1950
+ exports.canRead = canRead;
1951
+ exports.captureProvenanceSnapshot = captureProvenanceSnapshot;
1952
+ exports.captureProvenanceState = captureProvenanceState;
1953
+ exports.cleanupProvenanceForExecution = cleanupProvenanceForExecution;
1954
+ exports.clearProvenanceExecutionId = clearProvenanceExecutionId;
1955
+ exports.computeDigest = computeDigest;
1956
+ exports.createCustomPolicy = createCustomPolicy;
1957
+ exports.createDeclarativePolicy = createDeclarativePolicy;
1958
+ exports.createProvenanceProxy = createProvenanceProxy;
1959
+ exports.createTrackingRuntime = createTrackingRuntime;
1960
+ exports.getAllProvenance = getAllProvenance;
1961
+ exports.getBuiltInPolicies = getBuiltInPolicies;
1962
+ exports.getBuiltInPoliciesWithApproval = getBuiltInPoliciesWithApproval;
1963
+ exports.getClientSecret = getClientSecret;
1964
+ exports.getProvenance = getProvenance;
1965
+ exports.getProvenanceForPrimitive = getProvenanceForPrimitive;
1966
+ exports.hasProvenance = hasProvenance;
1967
+ exports.hydrateExecutionProvenance = hydrateExecutionProvenance;
1968
+ exports.hydrateProvenance = hydrateProvenance;
1969
+ exports.instrumentCode = instrumentCode;
1970
+ exports.isPrimitiveTainted = isPrimitiveTainted;
1971
+ exports.issueProvenanceToken = issueProvenanceToken;
1972
+ exports.loadDeclarativePolicies = loadDeclarativePolicies;
1973
+ exports.markPrimitiveTainted = markPrimitiveTainted;
1974
+ exports.preventDataExfiltration = preventDataExfiltration;
1975
+ exports.preventDataExfiltrationWithApproval = preventDataExfiltrationWithApproval;
1976
+ exports.registerProvenanceMetadata = registerProvenanceMetadata;
1977
+ exports.requireUserOrigin = requireUserOrigin;
1978
+ exports.requireUserOriginWithApproval = requireUserOriginWithApproval;
1979
+ exports.restoreProvenanceSnapshot = restoreProvenanceSnapshot;
1980
+ exports.restoreProvenanceState = restoreProvenanceState;
1981
+ exports.setGlobalProvenanceStore = setGlobalProvenanceStore;
1982
+ exports.setProvenanceExecutionId = setProvenanceExecutionId;
1983
+ exports.stableStringify = stableStringify;
1984
+ exports.verifyProvenanceHints = verifyProvenanceHints;
1985
+ exports.verifyProvenanceToken = verifyProvenanceToken;
1986
+ //# sourceMappingURL=index.cjs.map
1987
+ //# sourceMappingURL=index.cjs.map