@mondaydotcomorg/atp-server 0.17.14

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 (307) hide show
  1. package/README.md +489 -0
  2. package/dist/aggregator/index.d.ts +59 -0
  3. package/dist/aggregator/index.d.ts.map +1 -0
  4. package/dist/aggregator/index.js +171 -0
  5. package/dist/aggregator/index.js.map +1 -0
  6. package/dist/callback/index.d.ts +98 -0
  7. package/dist/callback/index.d.ts.map +1 -0
  8. package/dist/callback/index.js +136 -0
  9. package/dist/callback/index.js.map +1 -0
  10. package/dist/client-sessions.d.ts +82 -0
  11. package/dist/client-sessions.d.ts.map +1 -0
  12. package/dist/client-sessions.js +174 -0
  13. package/dist/client-sessions.js.map +1 -0
  14. package/dist/controllers/definitions.controller.d.ts +4 -0
  15. package/dist/controllers/definitions.controller.d.ts.map +1 -0
  16. package/dist/controllers/definitions.controller.js +11 -0
  17. package/dist/controllers/definitions.controller.js.map +1 -0
  18. package/dist/controllers/execute.controller.d.ts +18 -0
  19. package/dist/controllers/execute.controller.d.ts.map +1 -0
  20. package/dist/controllers/execute.controller.js +122 -0
  21. package/dist/controllers/execute.controller.js.map +1 -0
  22. package/dist/controllers/info.controller.d.ts +3 -0
  23. package/dist/controllers/info.controller.d.ts.map +1 -0
  24. package/dist/controllers/info.controller.js +13 -0
  25. package/dist/controllers/info.controller.js.map +1 -0
  26. package/dist/controllers/resume.controller.d.ts +11 -0
  27. package/dist/controllers/resume.controller.d.ts.map +1 -0
  28. package/dist/controllers/resume.controller.js +61 -0
  29. package/dist/controllers/resume.controller.js.map +1 -0
  30. package/dist/controllers/search.controller.d.ts +4 -0
  31. package/dist/controllers/search.controller.d.ts.map +1 -0
  32. package/dist/controllers/search.controller.js +7 -0
  33. package/dist/controllers/search.controller.js.map +1 -0
  34. package/dist/controllers/stream.controller.d.ts +19 -0
  35. package/dist/controllers/stream.controller.d.ts.map +1 -0
  36. package/dist/controllers/stream.controller.js +141 -0
  37. package/dist/controllers/stream.controller.js.map +1 -0
  38. package/dist/core/config.d.ts +161 -0
  39. package/dist/core/config.d.ts.map +1 -0
  40. package/dist/core/config.js +7 -0
  41. package/dist/core/config.js.map +1 -0
  42. package/dist/core/http.d.ts +4 -0
  43. package/dist/core/http.d.ts.map +1 -0
  44. package/dist/core/http.js +17 -0
  45. package/dist/core/http.js.map +1 -0
  46. package/dist/create-server.d.ts +120 -0
  47. package/dist/create-server.d.ts.map +1 -0
  48. package/dist/create-server.js +423 -0
  49. package/dist/create-server.js.map +1 -0
  50. package/dist/execution-state/index.d.ts +95 -0
  51. package/dist/execution-state/index.d.ts.map +1 -0
  52. package/dist/execution-state/index.js +128 -0
  53. package/dist/execution-state/index.js.map +1 -0
  54. package/dist/executor/ast-provenance-bridge.d.ts +12 -0
  55. package/dist/executor/ast-provenance-bridge.d.ts.map +1 -0
  56. package/dist/executor/ast-provenance-bridge.js +66 -0
  57. package/dist/executor/ast-provenance-bridge.js.map +1 -0
  58. package/dist/executor/ast-tracking-runtime.d.ts +7 -0
  59. package/dist/executor/ast-tracking-runtime.d.ts.map +1 -0
  60. package/dist/executor/ast-tracking-runtime.js +559 -0
  61. package/dist/executor/ast-tracking-runtime.js.map +1 -0
  62. package/dist/executor/bootstrap-generated.d.ts +32 -0
  63. package/dist/executor/bootstrap-generated.d.ts.map +1 -0
  64. package/dist/executor/bootstrap-generated.js +90 -0
  65. package/dist/executor/bootstrap-generated.js.map +1 -0
  66. package/dist/executor/compiler-config.d.ts +32 -0
  67. package/dist/executor/compiler-config.d.ts.map +1 -0
  68. package/dist/executor/compiler-config.js +99 -0
  69. package/dist/executor/compiler-config.js.map +1 -0
  70. package/dist/executor/constants.d.ts +4 -0
  71. package/dist/executor/constants.d.ts.map +1 -0
  72. package/dist/executor/constants.js +4 -0
  73. package/dist/executor/constants.js.map +1 -0
  74. package/dist/executor/error-handler.d.ts +9 -0
  75. package/dist/executor/error-handler.d.ts.map +1 -0
  76. package/dist/executor/error-handler.js +95 -0
  77. package/dist/executor/error-handler.js.map +1 -0
  78. package/dist/executor/execution-error-handler.d.ts +7 -0
  79. package/dist/executor/execution-error-handler.d.ts.map +1 -0
  80. package/dist/executor/execution-error-handler.js +136 -0
  81. package/dist/executor/execution-error-handler.js.map +1 -0
  82. package/dist/executor/executor.d.ts +20 -0
  83. package/dist/executor/executor.d.ts.map +1 -0
  84. package/dist/executor/executor.js +452 -0
  85. package/dist/executor/executor.js.map +1 -0
  86. package/dist/executor/index.d.ts +4 -0
  87. package/dist/executor/index.d.ts.map +1 -0
  88. package/dist/executor/index.js +3 -0
  89. package/dist/executor/index.js.map +1 -0
  90. package/dist/executor/resume-handler.d.ts +9 -0
  91. package/dist/executor/resume-handler.d.ts.map +1 -0
  92. package/dist/executor/resume-handler.js +22 -0
  93. package/dist/executor/resume-handler.js.map +1 -0
  94. package/dist/executor/sandbox-builder.d.ts +29 -0
  95. package/dist/executor/sandbox-builder.d.ts.map +1 -0
  96. package/dist/executor/sandbox-builder.js +538 -0
  97. package/dist/executor/sandbox-builder.js.map +1 -0
  98. package/dist/executor/sandbox-injector.d.ts +7 -0
  99. package/dist/executor/sandbox-injector.d.ts.map +1 -0
  100. package/dist/executor/sandbox-injector.js +293 -0
  101. package/dist/executor/sandbox-injector.js.map +1 -0
  102. package/dist/executor/types.d.ts +21 -0
  103. package/dist/executor/types.d.ts.map +1 -0
  104. package/dist/executor/types.js +2 -0
  105. package/dist/executor/types.js.map +1 -0
  106. package/dist/explorer/index.d.ts +69 -0
  107. package/dist/explorer/index.d.ts.map +1 -0
  108. package/dist/explorer/index.js +228 -0
  109. package/dist/explorer/index.js.map +1 -0
  110. package/dist/handlers/definitions.handler.d.ts +3 -0
  111. package/dist/handlers/definitions.handler.d.ts.map +1 -0
  112. package/dist/handlers/definitions.handler.js +11 -0
  113. package/dist/handlers/definitions.handler.js.map +1 -0
  114. package/dist/handlers/execute.handler.d.ts +7 -0
  115. package/dist/handlers/execute.handler.d.ts.map +1 -0
  116. package/dist/handlers/execute.handler.js +225 -0
  117. package/dist/handlers/execute.handler.js.map +1 -0
  118. package/dist/handlers/explorer.handler.d.ts +4 -0
  119. package/dist/handlers/explorer.handler.d.ts.map +1 -0
  120. package/dist/handlers/explorer.handler.js +10 -0
  121. package/dist/handlers/explorer.handler.js.map +1 -0
  122. package/dist/handlers/init.handler.d.ts +5 -0
  123. package/dist/handlers/init.handler.d.ts.map +1 -0
  124. package/dist/handlers/init.handler.js +41 -0
  125. package/dist/handlers/init.handler.js.map +1 -0
  126. package/dist/handlers/resume.handler.d.ts +6 -0
  127. package/dist/handlers/resume.handler.d.ts.map +1 -0
  128. package/dist/handlers/resume.handler.js +256 -0
  129. package/dist/handlers/resume.handler.js.map +1 -0
  130. package/dist/handlers/search.handler.d.ts +5 -0
  131. package/dist/handlers/search.handler.d.ts.map +1 -0
  132. package/dist/handlers/search.handler.js +11 -0
  133. package/dist/handlers/search.handler.js.map +1 -0
  134. package/dist/http/request-handler.d.ts +15 -0
  135. package/dist/http/request-handler.d.ts.map +1 -0
  136. package/dist/http/request-handler.js +94 -0
  137. package/dist/http/request-handler.js.map +1 -0
  138. package/dist/http/router.d.ts +4 -0
  139. package/dist/http/router.d.ts.map +1 -0
  140. package/dist/http/router.js +32 -0
  141. package/dist/http/router.js.map +1 -0
  142. package/dist/index.d.ts +10 -0
  143. package/dist/index.d.ts.map +1 -0
  144. package/dist/index.js +8 -0
  145. package/dist/index.js.map +1 -0
  146. package/dist/instrumentation/index.d.ts +5 -0
  147. package/dist/instrumentation/index.d.ts.map +1 -0
  148. package/dist/instrumentation/index.js +5 -0
  149. package/dist/instrumentation/index.js.map +1 -0
  150. package/dist/instrumentation/serializer.d.ts +61 -0
  151. package/dist/instrumentation/serializer.d.ts.map +1 -0
  152. package/dist/instrumentation/serializer.js +334 -0
  153. package/dist/instrumentation/serializer.js.map +1 -0
  154. package/dist/instrumentation/state-manager.d.ts +61 -0
  155. package/dist/instrumentation/state-manager.d.ts.map +1 -0
  156. package/dist/instrumentation/state-manager.js +205 -0
  157. package/dist/instrumentation/state-manager.js.map +1 -0
  158. package/dist/instrumentation/transformer.d.ts +9 -0
  159. package/dist/instrumentation/transformer.d.ts.map +1 -0
  160. package/dist/instrumentation/transformer.js +70 -0
  161. package/dist/instrumentation/transformer.js.map +1 -0
  162. package/dist/instrumentation/types.d.ts +59 -0
  163. package/dist/instrumentation/types.d.ts.map +1 -0
  164. package/dist/instrumentation/types.js +5 -0
  165. package/dist/instrumentation/types.js.map +1 -0
  166. package/dist/middleware/audit.d.ts +18 -0
  167. package/dist/middleware/audit.d.ts.map +1 -0
  168. package/dist/middleware/audit.js +76 -0
  169. package/dist/middleware/audit.js.map +1 -0
  170. package/dist/openapi/index.d.ts +133 -0
  171. package/dist/openapi/index.d.ts.map +1 -0
  172. package/dist/openapi/index.js +235 -0
  173. package/dist/openapi/index.js.map +1 -0
  174. package/dist/openapi-loader.d.ts +87 -0
  175. package/dist/openapi-loader.d.ts.map +1 -0
  176. package/dist/openapi-loader.js +491 -0
  177. package/dist/openapi-loader.js.map +1 -0
  178. package/dist/routes/index.d.ts +21 -0
  179. package/dist/routes/index.d.ts.map +1 -0
  180. package/dist/routes/index.js +47 -0
  181. package/dist/routes/index.js.map +1 -0
  182. package/dist/search/index.d.ts +48 -0
  183. package/dist/search/index.d.ts.map +1 -0
  184. package/dist/search/index.js +156 -0
  185. package/dist/search/index.js.map +1 -0
  186. package/dist/security/index.d.ts +2 -0
  187. package/dist/security/index.d.ts.map +1 -0
  188. package/dist/security/index.js +2 -0
  189. package/dist/security/index.js.map +1 -0
  190. package/dist/shutdown.d.ts +19 -0
  191. package/dist/shutdown.d.ts.map +1 -0
  192. package/dist/shutdown.js +87 -0
  193. package/dist/shutdown.js.map +1 -0
  194. package/dist/utils/banner.d.ts +12 -0
  195. package/dist/utils/banner.d.ts.map +1 -0
  196. package/dist/utils/banner.js +18 -0
  197. package/dist/utils/banner.js.map +1 -0
  198. package/dist/utils/context.d.ts +16 -0
  199. package/dist/utils/context.d.ts.map +1 -0
  200. package/dist/utils/context.js +44 -0
  201. package/dist/utils/context.js.map +1 -0
  202. package/dist/utils/error.d.ts +8 -0
  203. package/dist/utils/error.d.ts.map +1 -0
  204. package/dist/utils/error.js +17 -0
  205. package/dist/utils/error.js.map +1 -0
  206. package/dist/utils/hint-based-instrumentation.d.ts +14 -0
  207. package/dist/utils/hint-based-instrumentation.d.ts.map +1 -0
  208. package/dist/utils/hint-based-instrumentation.js +84 -0
  209. package/dist/utils/hint-based-instrumentation.js.map +1 -0
  210. package/dist/utils/index.d.ts +8 -0
  211. package/dist/utils/index.d.ts.map +1 -0
  212. package/dist/utils/index.js +8 -0
  213. package/dist/utils/index.js.map +1 -0
  214. package/dist/utils/info.d.ts +20 -0
  215. package/dist/utils/info.d.ts.map +1 -0
  216. package/dist/utils/info.js +15 -0
  217. package/dist/utils/info.js.map +1 -0
  218. package/dist/utils/provenance-reattachment.d.ts +32 -0
  219. package/dist/utils/provenance-reattachment.d.ts.map +1 -0
  220. package/dist/utils/provenance-reattachment.js +115 -0
  221. package/dist/utils/provenance-reattachment.js.map +1 -0
  222. package/dist/utils/request.d.ts +21 -0
  223. package/dist/utils/request.d.ts.map +1 -0
  224. package/dist/utils/request.js +44 -0
  225. package/dist/utils/request.js.map +1 -0
  226. package/dist/utils/response.d.ts +30 -0
  227. package/dist/utils/response.d.ts.map +1 -0
  228. package/dist/utils/response.js +53 -0
  229. package/dist/utils/response.js.map +1 -0
  230. package/dist/utils/runtime-types.d.ts +6 -0
  231. package/dist/utils/runtime-types.d.ts.map +1 -0
  232. package/dist/utils/runtime-types.js +14 -0
  233. package/dist/utils/runtime-types.js.map +1 -0
  234. package/dist/utils/schema.d.ts +9 -0
  235. package/dist/utils/schema.d.ts.map +1 -0
  236. package/dist/utils/schema.js +13 -0
  237. package/dist/utils/schema.js.map +1 -0
  238. package/dist/utils/token-emitter.d.ts +21 -0
  239. package/dist/utils/token-emitter.d.ts.map +1 -0
  240. package/dist/utils/token-emitter.js +129 -0
  241. package/dist/utils/token-emitter.js.map +1 -0
  242. package/dist/validator/index.d.ts +36 -0
  243. package/dist/validator/index.d.ts.map +1 -0
  244. package/dist/validator/index.js +224 -0
  245. package/dist/validator/index.js.map +1 -0
  246. package/package.json +68 -0
  247. package/src/aggregator/index.ts +207 -0
  248. package/src/callback/index.ts +191 -0
  249. package/src/client-sessions.ts +234 -0
  250. package/src/controllers/definitions.controller.ts +19 -0
  251. package/src/controllers/execute.controller.ts +166 -0
  252. package/src/controllers/info.controller.ts +14 -0
  253. package/src/controllers/resume.controller.ts +92 -0
  254. package/src/controllers/search.controller.ts +16 -0
  255. package/src/controllers/stream.controller.ts +190 -0
  256. package/src/core/config.ts +180 -0
  257. package/src/core/http.ts +21 -0
  258. package/src/create-server.ts +536 -0
  259. package/src/execution-state/index.ts +204 -0
  260. package/src/executor/ast-provenance-bridge.ts +80 -0
  261. package/src/executor/ast-tracking-runtime.ts +558 -0
  262. package/src/executor/bootstrap-generated.ts +90 -0
  263. package/src/executor/compiler-config.ts +146 -0
  264. package/src/executor/constants.ts +5 -0
  265. package/src/executor/error-handler.ts +118 -0
  266. package/src/executor/execution-error-handler.ts +178 -0
  267. package/src/executor/executor.ts +631 -0
  268. package/src/executor/index.ts +3 -0
  269. package/src/executor/resume-handler.ts +39 -0
  270. package/src/executor/sandbox-builder.ts +684 -0
  271. package/src/executor/sandbox-injector.ts +345 -0
  272. package/src/executor/types.ts +22 -0
  273. package/src/explorer/index.ts +297 -0
  274. package/src/handlers/definitions.handler.ts +13 -0
  275. package/src/handlers/execute.handler.ts +286 -0
  276. package/src/handlers/explorer.handler.ts +18 -0
  277. package/src/handlers/init.handler.ts +53 -0
  278. package/src/handlers/resume.handler.ts +316 -0
  279. package/src/handlers/search.handler.ts +32 -0
  280. package/src/http/request-handler.ts +117 -0
  281. package/src/http/router.ts +29 -0
  282. package/src/index.ts +60 -0
  283. package/src/instrumentation/index.ts +4 -0
  284. package/src/instrumentation/serializer.ts +421 -0
  285. package/src/instrumentation/state-manager.ts +237 -0
  286. package/src/instrumentation/transformer.ts +84 -0
  287. package/src/instrumentation/types.ts +76 -0
  288. package/src/middleware/audit.ts +101 -0
  289. package/src/openapi/index.ts +378 -0
  290. package/src/openapi-loader.ts +744 -0
  291. package/src/routes/index.ts +93 -0
  292. package/src/search/index.ts +216 -0
  293. package/src/security/index.ts +1 -0
  294. package/src/shutdown.ts +108 -0
  295. package/src/utils/banner.ts +25 -0
  296. package/src/utils/context.ts +58 -0
  297. package/src/utils/error.ts +25 -0
  298. package/src/utils/hint-based-instrumentation.ts +99 -0
  299. package/src/utils/index.ts +15 -0
  300. package/src/utils/info.ts +31 -0
  301. package/src/utils/provenance-reattachment.ts +144 -0
  302. package/src/utils/request.ts +53 -0
  303. package/src/utils/response.ts +69 -0
  304. package/src/utils/runtime-types.ts +14 -0
  305. package/src/utils/schema.ts +18 -0
  306. package/src/utils/token-emitter.ts +182 -0
  307. package/src/validator/index.ts +253 -0
@@ -0,0 +1,95 @@
1
+ import type { ExecutionConfig, CallbackType, CacheProvider } from '@mondaydotcomorg/atp-protocol';
2
+ import type { ProvenanceState, ProvenanceSnapshot } from '@mondaydotcomorg/atp-provenance';
3
+ /**
4
+ * Callback request sent to client when execution is paused
5
+ */
6
+ export interface CallbackRequest {
7
+ type: CallbackType;
8
+ operation: string;
9
+ payload: Record<string, unknown>;
10
+ }
11
+ /**
12
+ * Callback execution record for replay
13
+ */
14
+ export interface CallbackRecord {
15
+ type: CallbackType;
16
+ operation: string;
17
+ payload: Record<string, unknown>;
18
+ result?: unknown;
19
+ timestamp: number;
20
+ sequenceNumber: number;
21
+ }
22
+ /**
23
+ * Paused execution state
24
+ */
25
+ export interface PausedExecution {
26
+ executionId: string;
27
+ code: string;
28
+ config: ExecutionConfig;
29
+ clientId: string;
30
+ callbackRequest: CallbackRequest;
31
+ pausedAt: number;
32
+ callbackHistory: CallbackRecord[];
33
+ currentCallbackIndex: number;
34
+ context: {
35
+ variables?: Record<string, unknown>;
36
+ codeTransformed?: boolean;
37
+ };
38
+ provenanceState?: ProvenanceState | ProvenanceSnapshot;
39
+ }
40
+ /**
41
+ * Execution state manager using CacheProvider
42
+ * Works with any CacheProvider (MemoryCache, RedisCache, etc.)
43
+ */
44
+ export declare class ExecutionStateManager {
45
+ private cache;
46
+ private keyPrefix;
47
+ private ttl;
48
+ private maxPauseDuration;
49
+ private metrics;
50
+ constructor(cache: CacheProvider, options?: {
51
+ keyPrefix?: string;
52
+ ttl?: number;
53
+ maxPauseDuration?: number;
54
+ });
55
+ /**
56
+ * Saves paused execution state
57
+ */
58
+ pause(state: PausedExecution): Promise<void>;
59
+ /**
60
+ * Retrieves paused execution state
61
+ */
62
+ get(executionId: string): Promise<PausedExecution | null>;
63
+ /**
64
+ * Deletes execution state
65
+ */
66
+ delete(executionId: string): Promise<void>;
67
+ /**
68
+ * Gets the full cache key for an execution ID
69
+ */
70
+ private getKey;
71
+ /**
72
+ * Closes connections and cleanup
73
+ */
74
+ close(): Promise<void>;
75
+ /**
76
+ * Gets storage type from cache provider
77
+ */
78
+ getStorageType(): string;
79
+ /**
80
+ * Gets pause/resume metrics
81
+ */
82
+ getMetrics(): {
83
+ successRate: string;
84
+ expiredRate: string;
85
+ totalPauses: number;
86
+ totalResumes: number;
87
+ totalExpired: number;
88
+ totalFailed: number;
89
+ };
90
+ /**
91
+ * Resets metrics (useful for testing)
92
+ */
93
+ resetMetrics(): void;
94
+ }
95
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/execution-state/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAClG,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAE3F;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,YAAY,CA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E,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBlD;;OAEG;IACG,GAAG,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IA8B/D;;OAEG;IACG,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMhD;;OAEG;IACH,OAAO,CAAC,MAAM;IAId;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAO5B;;OAEG;IACH,cAAc,IAAI,MAAM;IAIxB;;OAEG;IACH,UAAU;;;qBAzHI,MAAM;sBACL,MAAM;sBACN,MAAM;qBACP,MAAM;;IAoIpB;;OAEG;IACH,YAAY,IAAI,IAAI;CAQpB"}
@@ -0,0 +1,128 @@
1
+ import { log } from '@mondaydotcomorg/atp-runtime';
2
+ /**
3
+ * Execution state manager using CacheProvider
4
+ * Works with any CacheProvider (MemoryCache, RedisCache, etc.)
5
+ */
6
+ export class ExecutionStateManager {
7
+ cache;
8
+ keyPrefix;
9
+ ttl;
10
+ maxPauseDuration;
11
+ metrics;
12
+ constructor(cache, options) {
13
+ this.cache = cache;
14
+ this.keyPrefix = options?.keyPrefix || 'atp:execution:';
15
+ this.ttl = options?.ttl || 3600;
16
+ this.maxPauseDuration = (options?.maxPauseDuration ?? 3600) * 1000;
17
+ this.metrics = {
18
+ totalPauses: 0,
19
+ totalResumes: 0,
20
+ totalExpired: 0,
21
+ totalFailed: 0,
22
+ };
23
+ log.info('ExecutionStateManager initialized', {
24
+ cacheProvider: cache.name,
25
+ ttl: this.ttl,
26
+ maxPauseDuration: this.maxPauseDuration / 1000,
27
+ });
28
+ }
29
+ /**
30
+ * Saves paused execution state
31
+ */
32
+ async pause(state) {
33
+ this.metrics.totalPauses++;
34
+ const key = this.getKey(state.executionId);
35
+ const serialized = JSON.stringify(state);
36
+ await this.cache.set(key, serialized, this.ttl);
37
+ log.info('Execution paused', {
38
+ executionId: state.executionId,
39
+ clientId: state.clientId,
40
+ callbackType: state.callbackRequest.type,
41
+ cacheProvider: this.cache.name,
42
+ ttl: this.ttl,
43
+ maxPauseDuration: this.maxPauseDuration / 1000,
44
+ });
45
+ }
46
+ /**
47
+ * Retrieves paused execution state
48
+ */
49
+ async get(executionId) {
50
+ const key = this.getKey(executionId);
51
+ const serialized = await this.cache.get(key);
52
+ if (!serialized) {
53
+ log.warn('Execution not found or expired', { executionId });
54
+ this.metrics.totalExpired++;
55
+ return null;
56
+ }
57
+ const state = JSON.parse(serialized);
58
+ const pauseDuration = Date.now() - state.pausedAt;
59
+ if (pauseDuration > this.maxPauseDuration) {
60
+ log.warn('Execution pause duration exceeded maximum', {
61
+ executionId,
62
+ pauseDuration: pauseDuration / 1000,
63
+ maxDuration: this.maxPauseDuration / 1000,
64
+ });
65
+ await this.delete(executionId);
66
+ this.metrics.totalExpired++;
67
+ return null;
68
+ }
69
+ await this.cache.set(key, serialized, this.ttl);
70
+ this.metrics.totalResumes++;
71
+ return state;
72
+ }
73
+ /**
74
+ * Deletes execution state
75
+ */
76
+ async delete(executionId) {
77
+ const key = this.getKey(executionId);
78
+ await this.cache.delete(key);
79
+ log.debug('Execution state deleted', { executionId });
80
+ }
81
+ /**
82
+ * Gets the full cache key for an execution ID
83
+ */
84
+ getKey(executionId) {
85
+ return `${this.keyPrefix}${executionId}`;
86
+ }
87
+ /**
88
+ * Closes connections and cleanup
89
+ */
90
+ async close() {
91
+ if (this.cache.disconnect) {
92
+ await this.cache.disconnect();
93
+ }
94
+ log.debug('ExecutionStateManager closed');
95
+ }
96
+ /**
97
+ * Gets storage type from cache provider
98
+ */
99
+ getStorageType() {
100
+ return this.cache.name;
101
+ }
102
+ /**
103
+ * Gets pause/resume metrics
104
+ */
105
+ getMetrics() {
106
+ return {
107
+ ...this.metrics,
108
+ successRate: this.metrics.totalResumes > 0
109
+ ? ((this.metrics.totalResumes / (this.metrics.totalPauses || 1)) * 100).toFixed(2) + '%'
110
+ : '0%',
111
+ expiredRate: this.metrics.totalExpired > 0
112
+ ? ((this.metrics.totalExpired / (this.metrics.totalPauses || 1)) * 100).toFixed(2) + '%'
113
+ : '0%',
114
+ };
115
+ }
116
+ /**
117
+ * Resets metrics (useful for testing)
118
+ */
119
+ resetMetrics() {
120
+ this.metrics = {
121
+ totalPauses: 0,
122
+ totalResumes: 0,
123
+ totalExpired: 0,
124
+ totalFailed: 0,
125
+ };
126
+ }
127
+ }
128
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/execution-state/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,8BAA8B,CAAC;AA+CnD;;;GAGG;AACH,MAAM,OAAO,qBAAqB;IACzB,KAAK,CAAgB;IACrB,SAAS,CAAS;IAClB,GAAG,CAAS;IACZ,gBAAgB,CAAS;IACzB,OAAO,CAKb;IAEF,YACC,KAAoB,EACpB,OAIC;QAED,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,SAAS,GAAG,OAAO,EAAE,SAAS,IAAI,gBAAgB,CAAC;QACxD,IAAI,CAAC,GAAG,GAAG,OAAO,EAAE,GAAG,IAAI,IAAI,CAAC;QAChC,IAAI,CAAC,gBAAgB,GAAG,CAAC,OAAO,EAAE,gBAAgB,IAAI,IAAI,CAAC,GAAG,IAAI,CAAC;QACnE,IAAI,CAAC,OAAO,GAAG;YACd,WAAW,EAAE,CAAC;YACd,YAAY,EAAE,CAAC;YACf,YAAY,EAAE,CAAC;YACf,WAAW,EAAE,CAAC;SACd,CAAC;QAEF,GAAG,CAAC,IAAI,CAAC,mCAAmC,EAAE;YAC7C,aAAa,EAAE,KAAK,CAAC,IAAI;YACzB,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,gBAAgB,EAAE,IAAI,CAAC,gBAAgB,GAAG,IAAI;SAC9C,CAAC,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK,CAA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I,CAAC,OAAO;YACf,WAAW,EACV,IAAI,CAAC,OAAO,CAAC,YAAY,GAAG,CAAC;gBAC5B,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,GAAG;gBACxF,CAAC,CAAC,IAAI;YACR,WAAW,EACV,IAAI,CAAC,OAAO,CAAC,YAAY,GAAG,CAAC;gBAC5B,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,GAAG;gBACxF,CAAC,CAAC,IAAI;SACR,CAAC;IACH,CAAC;IAED;;OAEG;IACH,YAAY;QACX,IAAI,CAAC,OAAO,GAAG;YACd,WAAW,EAAE,CAAC;YACd,YAAY,EAAE,CAAC;YACf,YAAY,EAAE,CAAC;YACf,WAAW,EAAE,CAAC;SACd,CAAC;IACH,CAAC;CACD"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Bridge between AST tracker in isolated-vm and host policy engine
3
+ */
4
+ import * as ivm from 'isolated-vm';
5
+ export declare function registerIsolateContext(executionId: string, context: ivm.Context): void;
6
+ export declare function unregisterIsolateContext(executionId: string): void;
7
+ /**
8
+ * Create a getProvenance function that can check AST tracker inside the isolate
9
+ * Falls back to host-side getProvenance for hint-based tracking
10
+ */
11
+ export declare function createASTProvenanceChecker(executionId: string): (value: unknown) => any;
12
+ //# sourceMappingURL=ast-provenance-bridge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast-provenance-bridge.d.ts","sourceRoot":"","sources":["../../src/executor/ast-provenance-bridge.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AASnC,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,GAAG,IAAI,CAEtF;AAED,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAElE;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,MAAM,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,GAAG,CAuDvF"}
@@ -0,0 +1,66 @@
1
+ import { getProvenance, getProvenanceForPrimitive } from '@mondaydotcomorg/atp-provenance';
2
+ // Store active isolate contexts for AST mode provenance checking
3
+ const activeIsolates = new Map();
4
+ // Cache the getProvenance function to avoid repeated requires
5
+ let cachedGetProvenance = null;
6
+ export function registerIsolateContext(executionId, context) {
7
+ activeIsolates.set(executionId, context);
8
+ }
9
+ export function unregisterIsolateContext(executionId) {
10
+ activeIsolates.delete(executionId);
11
+ }
12
+ /**
13
+ * Create a getProvenance function that can check AST tracker inside the isolate
14
+ * Falls back to host-side getProvenance for hint-based tracking
15
+ */
16
+ export function createASTProvenanceChecker(executionId) {
17
+ return (value) => {
18
+ const context = activeIsolates.get(executionId);
19
+ // First, try checking in the isolate's AST tracker
20
+ if (context) {
21
+ try {
22
+ // Serialize the value to pass into isolate for checking
23
+ const valueStr = typeof value === 'string' || typeof value === 'number'
24
+ ? JSON.stringify(String(value))
25
+ : JSON.stringify(value);
26
+ // Call __check_provenance inside the isolate
27
+ const checkCode = `
28
+ (function() {
29
+ try {
30
+ if (typeof globalThis.__check_provenance !== 'function') {
31
+ return null;
32
+ }
33
+ const value = ${valueStr};
34
+ const result = globalThis.__check_provenance(value);
35
+ return result;
36
+ } catch (e) {
37
+ return null;
38
+ }
39
+ })()
40
+ `;
41
+ const result = context.evalSync(checkCode, { timeout: 100, copy: true });
42
+ if (result) {
43
+ return result;
44
+ }
45
+ }
46
+ catch (error) {
47
+ // Fall through to host check
48
+ }
49
+ }
50
+ // Fall back to host-side provenance check (for hints and registered metadata)
51
+ // This is critical for checking primitives that were registered via hints
52
+ if (!cachedGetProvenance) {
53
+ cachedGetProvenance = getProvenance;
54
+ }
55
+ const hostResult = cachedGetProvenance?.(value);
56
+ // Also check getProvenanceForPrimitive for tainted primitives
57
+ if (!hostResult && (typeof value === 'string' || typeof value === 'number')) {
58
+ const primitiveResult = getProvenanceForPrimitive?.(value);
59
+ if (primitiveResult) {
60
+ return primitiveResult;
61
+ }
62
+ }
63
+ return hostResult;
64
+ };
65
+ }
66
+ //# sourceMappingURL=ast-provenance-bridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast-provenance-bridge.js","sourceRoot":"","sources":["../../src/executor/ast-provenance-bridge.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAE3F,iEAAiE;AACjE,MAAM,cAAc,GAAG,IAAI,GAAG,EAAuB,CAAC;AAEtD,8DAA8D;AAC9D,IAAI,mBAAmB,GAAqC,IAAI,CAAC;AAEjE,MAAM,UAAU,sBAAsB,CAAC,WAAmB,EAAE,OAAoB;IAC/E,cAAc,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,WAAmB;IAC3D,cAAc,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AACpC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CAAC,WAAmB;IAC7D,OAAO,CAAC,KAAc,EAAE,EAAE;QACzB,MAAM,OAAO,GAAG,cAAc,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QAEhD,mDAAmD;QACnD,IAAI,OAAO,EAAE,CAAC;YACb,IAAI,CAAC;gBACJ,wDAAwD;gBACxD,MAAM,QAAQ,GACb,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ;oBACrD,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBAC/B,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;gBAE1B,6CAA6C;gBAC7C,MAAM,SAAS,GAAG;;;;;;uBAMC,QAAQ;;;;;;;KAO1B,CAAC;gBAEF,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;gBACzE,IAAI,MAAM,EAAE,CAAC;oBACZ,OAAO,MAAM,CAAC;gBACf,CAAC;YACF,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,6BAA6B;YAC9B,CAAC;QACF,CAAC;QAED,8EAA8E;QAC9E,0EAA0E;QAC1E,IAAI,CAAC,mBAAmB,EAAE,CAAC;YAC1B,mBAAmB,GAAG,aAAa,CAAC;QACrC,CAAC;QACD,MAAM,UAAU,GAAG,mBAAmB,EAAE,CAAC,KAAK,CAAC,CAAC;QAEhD,8DAA8D;QAC9D,IAAI,CAAC,UAAU,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,EAAE,CAAC;YAC7E,MAAM,eAAe,GAAG,yBAAyB,EAAE,CAAC,KAAK,CAAC,CAAC;YAC3D,IAAI,eAAe,EAAE,CAAC;gBACrB,OAAO,eAAe,CAAC;YACxB,CAAC;QACF,CAAC;QAED,OAAO,UAAU,CAAC;IACnB,CAAC,CAAC;AACH,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * AST Provenance Tracking Runtime for isolated-vm
3
+ * This code is injected into the isolate and runs INSIDE the sandbox
4
+ * It must be plain JavaScript with no imports
5
+ */
6
+ export declare const AST_TRACKING_RUNTIME = "\n// Pure JavaScript SHA-256 implementation for digest computation\nfunction sha256(str) {\n\tfunction rightRotate(value, amount) {\n\t\treturn (value >>> amount) | (value << (32 - amount));\n\t}\n\t\n\tconst mathPow = Math.pow;\n\tconst maxWord = mathPow(2, 32);\n\tconst lengthProperty = 'length';\n\tlet i, j;\n\tlet result = '';\n\t\n\tconst words = [];\n\tconst asciiBitLength = str[lengthProperty] * 8;\n\t\n\tlet hash = sha256.h = sha256.h || [];\n\tconst k = sha256.k = sha256.k || [];\n\tlet primeCounter = k[lengthProperty];\n\t\n\tconst isComposite = {};\n\tfor (let candidate = 2; primeCounter < 64; candidate++) {\n\t\tif (!isComposite[candidate]) {\n\t\t\tfor (i = 0; i < 313; i += candidate) {\n\t\t\t\tisComposite[i] = candidate;\n\t\t\t}\n\t\t\thash[primeCounter] = (mathPow(candidate, .5) * maxWord) | 0;\n\t\t\tk[primeCounter++] = (mathPow(candidate, 1 / 3) * maxWord) | 0;\n\t\t}\n\t}\n\t\n\tstr += '\\x80';\n\twhile (str[lengthProperty] % 64 - 56) str += '\\x00';\n\tfor (i = 0; i < str[lengthProperty]; i++) {\n\t\tj = str.charCodeAt(i);\n\t\tif (j >> 8) return;\n\t\twords[i >> 2] |= j << ((3 - i) % 4) * 8;\n\t}\n\twords[words[lengthProperty]] = ((asciiBitLength / maxWord) | 0);\n\twords[words[lengthProperty]] = (asciiBitLength);\n\t\n\tfor (j = 0; j < words[lengthProperty];) {\n\t\tconst w = words.slice(j, j += 16);\n\t\tconst oldHash = hash;\n\t\thash = hash.slice(0, 8);\n\t\t\n\t\tfor (i = 0; i < 64; i++) {\n\t\t\tconst w15 = w[i - 15], w2 = w[i - 2];\n\t\t\t\n\t\t\tconst a = hash[0], e = hash[4];\n\t\t\tconst temp1 = hash[7]\n\t\t\t\t+ (rightRotate(e, 6) ^ rightRotate(e, 11) ^ rightRotate(e, 25))\n\t\t\t\t+ ((e & hash[5]) ^ ((~e) & hash[6]))\n\t\t\t\t+ k[i]\n\t\t\t\t+ (w[i] = (i < 16) ? w[i] : (\n\t\t\t\t\t\tw[i - 16]\n\t\t\t\t\t\t+ (rightRotate(w15, 7) ^ rightRotate(w15, 18) ^ (w15 >>> 3))\n\t\t\t\t\t\t+ w[i - 7]\n\t\t\t\t\t\t+ (rightRotate(w2, 17) ^ rightRotate(w2, 19) ^ (w2 >>> 10))\n\t\t\t\t\t) | 0\n\t\t\t\t);\n\t\t\tconst temp2 = (rightRotate(a, 2) ^ rightRotate(a, 13) ^ rightRotate(a, 22))\n\t\t\t\t+ ((a & hash[1]) ^ (a & hash[2]) ^ (hash[1] & hash[2]));\n\t\t\t\n\t\t\thash = [(temp1 + temp2) | 0].concat(hash);\n\t\t\thash[4] = (hash[4] + temp1) | 0;\n\t\t}\n\t\t\n\t\tfor (i = 0; i < 8; i++) {\n\t\t\thash[i] = (hash[i] + oldHash[i]) | 0;\n\t\t}\n\t}\n\t\n\tfor (i = 0; i < 8; i++) {\n\t\tfor (j = 3; j + 1; j--) {\n\t\t\tconst b = (hash[i] >> (j * 8)) & 255;\n\t\t\tresult += ((b < 16) ? 0 : '') + b.toString(16);\n\t\t}\n\t}\n\t\n\t// Convert hex to base64url\n\tconst hex = result;\n\tconst bytes = [];\n\tfor (let i = 0; i < hex.length; i += 2) {\n\t\tbytes.push(parseInt(hex.substring(i, i + 2), 16));\n\t}\n\tlet binary = '';\n\tfor (let i = 0; i < bytes.length; i++) {\n\t\tbinary += String.fromCharCode(bytes[i]);\n\t}\n\tconst base64 = btoa(binary);\n\treturn base64.replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=/g, '');\n}\n\nconst __astTracker = {\n\tmetadata: new Map(),\n\tnextId: 0,\n\thints: new Map(globalThis.__provenance_hints || []),\n\thintValues: new Map(globalThis.__provenance_hint_values || []),\n\t\n\t// SHA-256 digest computation to match server-side\n\tcomputeDigest(value) {\n\t\ttry {\n\t\t\tconst str = JSON.stringify(value);\n\t\t\treturn sha256(str);\n\t\t} catch (e) {\n\t\t\treturn null;\n\t\t}\n\t},\n\t\n\tgetId(value) {\n\t\tif (typeof value === 'object' && value !== null) {\n\t\t\tif (!value.__prov_id__) {\n\t\t\t\tconst id = 'tracked_' + this.nextId++;\n\t\t\t\ttry {\n\t\t\t\t\tObject.defineProperty(value, '__prov_id__', {\n\t\t\t\t\t\tvalue: id,\n\t\t\t\t\t\twritable: false,\n\t\t\t\t\t\tenumerable: false,\n\t\t\t\t\t\tconfigurable: true\n\t\t\t\t\t});\n\t\t\t\t} catch (e) {\n\t\t\t\t\treturn 'temp_' + Date.now() + '_' + Math.random();\n\t\t\t\t}\n\t\t\t\treturn id;\n\t\t\t}\n\t\t\treturn value.__prov_id__;\n\t\t}\n\t\treturn 'primitive_' + Date.now() + '_' + Math.random();\n\t},\n\t\n\ttrack(value, source, deps) {\n\t\ttry {\n\t\t\tconst id = this.getId(value);\n\t\t\tthis.metadata.set(id, { id, source, deps: deps || [] });\n\t\t\tconsole.log('[__track] Stored metadata:', id, 'source:', source.type, 'metadataSize:', this.metadata.size);\n\t\t\treturn value;\n\t\t} catch (error) {\n\t\t\tconsole.error('[__track] Error:', error);\n\t\t\treturn value;\n\t\t}\n\t},\n\t\n\ttrackBinary(left, right, operator) {\n\t\t// Perform the actual operation\n\t\tlet result;\n\t\tswitch (operator) {\n\t\t\tcase '+': result = left + right; break;\n\t\t\tcase '-': result = left - right; break;\n\t\t\tcase '*': result = left * right; break;\n\t\t\tcase '/': result = left / right; break;\n\t\t\tcase '%': result = left % right; break;\n\t\t\tcase '==': result = left == right; break;\n\t\t\tcase '===': result = left === right; break;\n\t\t\tcase '!=': result = left != right; break;\n\t\t\tcase '!==': result = left !== right; break;\n\t\t\tcase '<': result = left < right; break;\n\t\t\tcase '>': result = left > right; break;\n\t\t\tcase '<=': result = left <= right; break;\n\t\t\tcase '>=': result = left >= right; break;\n\t\t\tcase '&&': result = left && right; break;\n\t\t\tcase '||': result = left || right; break;\n\t\t\tdefault: result = left;\n\t\t}\n\t\t\n\t\t// Check if either operand has provenance\n\t\tlet hasToolSource = false;\n\t\tlet toolMetadata = null;\n\t\t\n\t\t// Helper to check primitive provenance\n\t\tconst checkPrimitive = (value) => {\n\t\t\tif (typeof value !== 'string' && typeof value !== 'number') {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\t\n\t\t\t// Check tainted key first\n\t\t\tconst taintedKey = 'tainted:' + String(value);\n\t\t\tconst taintedMeta = this.metadata.get(taintedKey);\n\t\t\tif (taintedMeta && taintedMeta.source && taintedMeta.source.type === 'tool') {\n\t\t\t\treturn taintedMeta;\n\t\t\t}\n\t\t\t\n\t\t\t// Check hint-based tracking\n\t\t\tconst digest = this.computeDigest(value);\n\t\t\tconst hintMeta = this.hints.get(digest);\n\t\t\tif (hintMeta && hintMeta.source && hintMeta.source.type === 'tool') {\n\t\t\t\treturn hintMeta;\n\t\t\t}\n\t\t\t\n\t\t\t// Check primitive map (id:key:value format)\n\t\t\tfor (const [key, meta] of this.metadata.entries()) {\n\t\t\t\tif (!key.startsWith('tainted:') && key.includes(':')) {\n\t\t\t\t\tconst parts = key.split(':');\n\t\t\t\t\tif (parts.length >= 3) {\n\t\t\t\t\t\tconst primitiveValue = parts.slice(2).join(':');\n\t\t\t\t\t\tif (primitiveValue === String(value) && meta.source && meta.source.type === 'tool') {\n\t\t\t\t\t\t\treturn meta;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\treturn null;\n\t\t};\n\t\t\n\t\t// Check left operand\n\t\tif (typeof left === 'object' && left && left.__prov_id__) {\n\t\t\tconst leftMeta = this.metadata.get(left.__prov_id__);\n\t\t\tif (leftMeta && leftMeta.source && leftMeta.source.type === 'tool') {\n\t\t\t\thasToolSource = true;\n\t\t\t\ttoolMetadata = leftMeta;\n\t\t\t}\n\t\t} else {\n\t\t\tconst primMeta = checkPrimitive(left);\n\t\t\tif (primMeta) {\n\t\t\t\thasToolSource = true;\n\t\t\t\ttoolMetadata = primMeta;\n\t\t\t}\n\t\t}\n\t\t\n\t\t// Check right operand\n\t\tif (!hasToolSource) {\n\t\t\tif (typeof right === 'object' && right && right.__prov_id__) {\n\t\t\t\tconst rightMeta = this.metadata.get(right.__prov_id__);\n\t\t\t\tif (rightMeta && rightMeta.source && rightMeta.source.type === 'tool') {\n\t\t\t\t\thasToolSource = true;\n\t\t\t\t\ttoolMetadata = rightMeta;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst primMeta = checkPrimitive(right);\n\t\t\t\tif (primMeta) {\n\t\t\t\t\thasToolSource = true;\n\t\t\t\t\ttoolMetadata = primMeta;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\t// If result is a string and has tool-sourced operand, mark it as tainted\n\t\tif (hasToolSource && toolMetadata && (typeof result === 'string' || typeof result === 'number')) {\n\t\t\tconst taintedKey = 'tainted:' + String(result);\n\t\t\t// Ensure metadata has all required fields, preserving readers from source\n\t\t\tconst fullMetadata = {\n\t\t\t\t...toolMetadata,\n\t\t\t\treaders: toolMetadata.readers || { type: 'restricted', readers: [] },\n\t\t\t\tdependencies: toolMetadata.dependencies || toolMetadata.deps || []\n\t\t\t};\n\t\t\tthis.metadata.set(taintedKey, fullMetadata);\n\t\t}\n\t\t\n\t\treturn result;\n\t},\n\t\n\ttrackAssign(name, value) {\n\t\treturn value;\n\t},\n\t\n\tasync trackMethod(object, method, args) {\n\t\t// Recursively wrap tainted primitives in arguments before calling the method\n\t\tfunction wrapTaintedInArgs(val, visited = new WeakSet()) {\n\t\t\tif (val === null || val === undefined) return val;\n\t\t\t\n\t\t\t// Check if this value has provenance\n\t\t\tconst prov = this.checkProvenance(val);\n\t\t\tif (prov && (typeof val === 'string' || typeof val === 'number')) {\n\t\t\t\t// Wrap tainted primitive\n\t\t\t\treturn { __tainted_value: val, __prov_meta: prov };\n\t\t\t}\n\t\t\t\n\t\t\t// Recursively process objects/arrays\n\t\t\tif (typeof val === 'object') {\n\t\t\t\tif (visited.has(val)) return val;\n\t\t\t\tvisited.add(val);\n\t\t\t\t\n\t\t\t\tif (Array.isArray(val)) {\n\t\t\t\t\treturn val.map(item => wrapTaintedInArgs.call(this, item, visited));\n\t\t\t\t} else {\n\t\t\t\t\tconst wrapped = {};\n\t\t\t\t\tfor (const [key, v] of Object.entries(val)) {\n\t\t\t\t\t\twrapped[key] = wrapTaintedInArgs.call(this, v, visited);\n\t\t\t\t\t}\n\t\t\t\t\treturn wrapped;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\treturn val;\n\t\t}\n\t\t\n\t\t// Wrap arguments\n\t\tconst wrappedArgs = args.map(arg => wrapTaintedInArgs.call(this, arg));\n\t\t\n\t\t// Call the method with wrapped arguments\n\t\tif (typeof object === 'object' && object !== null && method in object) {\n\t\t\tconst result = await object[method](...wrappedArgs);\n\t\t\t\n\t\t\t// Track the result\n\t\t\tif (result && typeof result === 'object') {\n\t\t\t\tconst id = this.getId(result);\n\t\t\t\t\n\t\t\t\t// Extract authorized readers from common param patterns (email, userId, username, user)\n\t\t\t\t// Match server-side logic in sandbox-builder.ts (lines 459-470)\n\t\t\t\tlet authorizedReaders = [];\n\t\t\t\tfor (const arg of args) {\n\t\t\t\t\tif (arg && typeof arg === 'object') {\n\t\t\t\t\t\t// Check for user identifier fields (email, user, userId only - no generic 'id')\n\t\t\t\t\t\tconst value = arg.email || arg.user || arg.userId;\n\t\t\t\t\t\tif (typeof value === 'string' && value.length > 0) {\n\t\t\t\t\t\t\tauthorizedReaders.push(value);\n\t\t\t\t\t\t\tbreak; // Only take first identifier\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t// If no email found, use tool-scoped authorization (matches server logic line 467-470)\n\t\t\t\tif (authorizedReaders.length === 0) {\n\t\t\t\t\tauthorizedReaders = ['tool:' + method];\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t// Tool data should be restricted by default to prevent exfiltration\n\t\t\t\tconst metadata = { \n\t\t\t\t\tid, \n\t\t\t\t\tsource: { \n\t\t\t\t\t\ttype: 'tool', \n\t\t\t\t\t\toperation: method, \n\t\t\t\t\t\ttoolName: method, \n\t\t\t\t\t\ttimestamp: Date.now() \n\t\t\t\t\t},\n\t\t\t\t\treaders: { type: 'restricted', readers: authorizedReaders },\n\t\t\t\t\tdeps: [this.getId(object), ...args.map(a => this.getId(a))],\n\t\t\t\t\tdependencies: []\n\t\t\t\t};\n\t\t\t\tthis.metadata.set(id, metadata);\n\t\t\t\t\n\t\t\t\t\t\t// Track primitive properties for token emission\n\t\t\t\t\t\tfor (const key in result) {\n\t\t\t\t\t\t\tif (Object.prototype.hasOwnProperty.call(result, key)) {\n\t\t\t\t\t\t\t\tconst value = result[key];\n\t\t\t\t\t\t\t\tif (typeof value === 'string' || typeof value === 'number') {\n\t\t\t\t\t\t\t\t\t// Check if this primitive matches any hints\n\t\t\t\t\t\t\t\t\tconst digest = this.computeDigest(value);\n\t\t\t\t\t\t\t\t\tconst hintMeta = this.hints.get(digest);\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\tconst primitiveKey = id + ':' + key + ':' + String(value);\n\t\t\t\t\t\t\t\t\t// Use hint metadata if available, otherwise use result metadata\n\t\t\t\t\t\t\t\t\tthis.metadata.set(primitiveKey, hintMeta || metadata);\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t// Also store by digest for cross-execution matching\n\t\t\t\t\t\t\t\t\tif (hintMeta) {\n\t\t\t\t\t\t\t\t\t\tconst taintedKey = 'tainted:' + String(value);\n\t\t\t\t\t\t\t\t\t\tthis.metadata.set(taintedKey, hintMeta);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\treturn result;\n\t\t}\n\t\treturn undefined;\n\t},\n\t\n\ttrackTemplate(expressions, quasis) {\n\t\tlet result = '';\n\t\tlet hasToolSource = false;\n\t\tlet toolMetadata = null;\n\t\t\n\t\t// Helper to check primitive provenance\n\t\tconst checkPrimitive = (value) => {\n\t\t\tif (typeof value !== 'string' && typeof value !== 'number') {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\t\n\t\t\t// Check tainted key first\n\t\t\tconst taintedKey = 'tainted:' + String(value);\n\t\t\tconst taintedMeta = this.metadata.get(taintedKey);\n\t\t\tif (taintedMeta && taintedMeta.source && taintedMeta.source.type === 'tool') {\n\t\t\t\treturn taintedMeta;\n\t\t\t}\n\t\t\t\n\t\t\t// Check hint-based tracking\n\t\t\tconst digest = this.computeDigest(value);\n\t\t\tconst hintMeta = this.hints.get(digest);\n\t\t\tif (hintMeta && hintMeta.source && hintMeta.source.type === 'tool') {\n\t\t\t\treturn hintMeta;\n\t\t\t}\n\t\t\t\n\t\t\t// Check primitive map (id:key:value format)\n\t\t\tfor (const [key, meta] of this.metadata.entries()) {\n\t\t\t\tif (!key.startsWith('tainted:') && key.includes(':')) {\n\t\t\t\t\tconst parts = key.split(':');\n\t\t\t\t\tif (parts.length >= 3) {\n\t\t\t\t\t\tconst primitiveValue = parts.slice(2).join(':');\n\t\t\t\t\t\tif (primitiveValue === String(value) && meta.source && meta.source.type === 'tool') {\n\t\t\t\t\t\t\treturn meta;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\treturn null;\n\t\t};\n\t\t\n\t\tfor (let i = 0; i < quasis.length; i++) {\n\t\t\tresult += quasis[i] || '';\n\t\t\tif (i < expressions.length) {\n\t\t\t\tconst expr = expressions[i];\n\t\t\t\tresult += String(expr);\n\t\t\t\t\n\t\t\t\t// Check if expression has provenance\n\t\t\t\tif (!hasToolSource) {\n\t\t\t\t\t// Check object provenance\n\t\t\t\t\tif (typeof expr === 'object' && expr && expr.__prov_id__) {\n\t\t\t\t\t\tconst exprMeta = this.metadata.get(expr.__prov_id__);\n\t\t\t\t\t\tif (exprMeta && exprMeta.source && exprMeta.source.type === 'tool') {\n\t\t\t\t\t\t\thasToolSource = true;\n\t\t\t\t\t\t\ttoolMetadata = exprMeta;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst primMeta = checkPrimitive(expr);\n\t\t\t\t\t\tif (primMeta) {\n\t\t\t\t\t\t\thasToolSource = true;\n\t\t\t\t\t\t\ttoolMetadata = primMeta;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\t// If template contains tool-sourced data, mark result as tainted\n\t\tif (hasToolSource && toolMetadata) {\n\t\t\tconst taintedKey = 'tainted:' + result;\n\t\t\t// Ensure metadata has all required fields, preserving readers from source\n\t\t\tconst fullMetadata = {\n\t\t\t\t...toolMetadata,\n\t\t\t\treaders: toolMetadata.readers || { type: 'restricted', readers: [] },\n\t\t\t\tdependencies: toolMetadata.dependencies || toolMetadata.deps || []\n\t\t\t};\n\t\t\tthis.metadata.set(taintedKey, fullMetadata);\n\t\t}\n\t\t\n\t\treturn result;\n\t},\n\t\n\tgetMetadata(value) {\n\t\tconst id = typeof value === 'object' && value && value.__prov_id__;\n\t\treturn id ? this.metadata.get(id) : null;\n\t},\n\t\n\tgetAllMetadata() {\n\t\treturn Array.from(this.metadata.entries());\n\t},\n\t\n\t// Check if a value or any nested value has tool-sourced provenance\n\tcheckProvenance(value) {\n\t\tif (value === null || value === undefined) {\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\t// Check if it's an object with __prov_id__\n\t\tif (typeof value === 'object' && value.__prov_id__) {\n\t\t\tconst meta = this.metadata.get(value.__prov_id__);\n\t\t\tif (meta && meta.source && meta.source.type === 'tool') {\n\t\t\t\treturn meta;\n\t\t\t}\n\t\t}\n\t\t\n\t\t// Check if it's a primitive with tainted metadata\n\t\tif (typeof value === 'string' || typeof value === 'number') {\n\t\t\tconst taintedKey = 'tainted:' + String(value);\n\t\t\tconst taintedMeta = this.metadata.get(taintedKey);\n\t\t\tif (taintedMeta && taintedMeta.source && taintedMeta.source.type === 'tool') {\n\t\t\t\treturn taintedMeta;\n\t\t\t}\n\t\t\t\n\t\t\t// Check primitive map\n\t\t\tfor (const [key, meta] of this.metadata.entries()) {\n\t\t\t\tif (!key.startsWith('tainted:') && key.includes(':')) {\n\t\t\t\t\tconst parts = key.split(':');\n\t\t\t\t\tif (parts.length >= 3) {\n\t\t\t\t\t\tconst primitiveValue = parts.slice(2).join(':');\n\t\t\t\t\t\tif (primitiveValue === String(value) && meta.source && meta.source.type === 'tool') {\n\t\t\t\t\t\t\treturn meta;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\t// Check hints\n\t\t\tconst digest = this.computeDigest(value);\n\t\t\tconst hintMeta = this.hints.get(digest);\n\t\t\tif (hintMeta && hintMeta.source && hintMeta.source.type === 'tool') {\n\t\t\t\treturn hintMeta;\n\t\t\t}\n\t\t}\n\t\t\n\t\t// For objects/arrays, recursively check all values\n\t\tif (typeof value === 'object') {\n\t\t\tfor (const key in value) {\n\t\t\t\tif (Object.prototype.hasOwnProperty.call(value, key)) {\n\t\t\t\t\tconst nestedMeta = this.checkProvenance(value[key]);\n\t\t\t\t\tif (nestedMeta) {\n\t\t\t\t\t\treturn nestedMeta;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn null;\n\t}\n};\n\n// Expose tracking functions globally\nglobalThis.__track = (v, s, d) => __astTracker.track(v, s, d);\nglobalThis.__track_binary = (l, r, o) => __astTracker.trackBinary(l, r, o);\nglobalThis.__track_assign = (n, v) => __astTracker.trackAssign(n, v);\nglobalThis.__track_method = (o, m, a) => __astTracker.trackMethod(o, m, a);\nglobalThis.__track_template = (e, q) => __astTracker.trackTemplate(e, q);\nglobalThis.__get_provenance = (v) => __astTracker.getMetadata(v);\nglobalThis.__get_all_metadata = () => __astTracker.getAllMetadata();\nglobalThis.__check_provenance = (v) => __astTracker.checkProvenance(v);\n\n// Mark a string literal as tainted (for cross-execution tracking)\nglobalThis.__mark_tainted = (value) => {\n\t// Check if this value matches a hint by exact digest\n\tconst digest = __astTracker.computeDigest(value);\n\tconst hintMeta = __astTracker.hints.get(digest);\n\tif (hintMeta) {\n\t\tconst taintedKey = 'tainted:' + String(value);\n\t\t__astTracker.metadata.set(taintedKey, hintMeta);\n\t\treturn value;\n\t}\n\t\n\t// ALSO check if this value CONTAINS any hint values (substring match)\n\t// This enables cross-execution tracking for template literals/concatenation\n\tif (typeof value === 'string' && __astTracker.hintValues && __astTracker.hintValues.size > 0) {\n\t\tfor (const [hintValue, metadata] of __astTracker.hintValues.entries()) {\n\t\t\tif (value.includes(hintValue)) {\n\t\t\t\tconst taintedKey = 'tainted:' + String(value);\n\t\t\t\t// Ensure metadata has all required fields, use restricted readers for tool data\n\t\t\t\tconst fullMetadata = {\n\t\t\t\t\t...metadata,\n\t\t\t\t\treaders: metadata.readers || { type: 'restricted', readers: [] },\n\t\t\t\t\tdependencies: metadata.dependencies || metadata.deps || []\n\t\t\t\t};\n\t\t\t\t__astTracker.metadata.set(taintedKey, fullMetadata);\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\t}\n\t\n\treturn value;\n};\n";
7
+ //# sourceMappingURL=ast-tracking-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast-tracking-runtime.d.ts","sourceRoot":"","sources":["../../src/executor/ast-tracking-runtime.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAO,MAAM,oBAAoB,6xlBAuiBhC,CAAC"}