@red-codes/agentguard 1.0.0 → 1.1.2

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 (434) hide show
  1. package/README.md +179 -298
  2. package/dist/args.d.ts.map +1 -0
  3. package/dist/args.js.map +1 -0
  4. package/dist/bin.d.ts.map +1 -0
  5. package/dist/bin.js +29185 -0
  6. package/dist/bin.js.map +7 -0
  7. package/dist/colors.d.ts.map +1 -0
  8. package/dist/colors.js.map +1 -0
  9. package/dist/commands/adoption.d.ts +2 -0
  10. package/dist/commands/adoption.d.ts.map +1 -0
  11. package/dist/commands/adoption.js +172 -0
  12. package/dist/commands/adoption.js.map +1 -0
  13. package/dist/commands/analytics.d.ts +3 -0
  14. package/dist/commands/analytics.d.ts.map +1 -0
  15. package/dist/commands/analytics.js +7 -0
  16. package/dist/commands/analytics.js.map +1 -0
  17. package/dist/commands/audit-verify.d.ts +3 -0
  18. package/dist/commands/audit-verify.d.ts.map +1 -0
  19. package/dist/commands/audit-verify.js +94 -0
  20. package/dist/commands/audit-verify.js.map +1 -0
  21. package/dist/commands/auto-setup.d.ts +28 -0
  22. package/dist/commands/auto-setup.d.ts.map +1 -0
  23. package/dist/commands/auto-setup.js +146 -0
  24. package/dist/commands/auto-setup.js.map +1 -0
  25. package/dist/commands/ci-check.d.ts +13 -0
  26. package/dist/commands/ci-check.d.ts.map +1 -0
  27. package/dist/commands/ci-check.js +286 -0
  28. package/dist/commands/ci-check.js.map +1 -0
  29. package/dist/commands/claude-hook.d.ts +2 -0
  30. package/dist/commands/claude-hook.d.ts.map +1 -0
  31. package/dist/commands/claude-hook.js +254 -0
  32. package/dist/commands/claude-hook.js.map +1 -0
  33. package/dist/commands/claude-init.d.ts.map +1 -0
  34. package/dist/commands/claude-init.js +401 -0
  35. package/dist/commands/claude-init.js.map +1 -0
  36. package/dist/commands/config.d.ts +39 -0
  37. package/dist/commands/config.d.ts.map +1 -0
  38. package/dist/commands/config.js +368 -0
  39. package/dist/commands/config.js.map +1 -0
  40. package/dist/commands/demo.d.ts +2 -0
  41. package/dist/commands/demo.d.ts.map +1 -0
  42. package/dist/commands/demo.js +100 -0
  43. package/dist/commands/demo.js.map +1 -0
  44. package/dist/commands/diff.d.ts +3 -0
  45. package/dist/commands/diff.d.ts.map +1 -0
  46. package/dist/commands/diff.js +364 -0
  47. package/dist/commands/diff.js.map +1 -0
  48. package/dist/commands/evidence-pr.d.ts +3 -0
  49. package/dist/commands/evidence-pr.d.ts.map +1 -0
  50. package/dist/commands/evidence-pr.js +162 -0
  51. package/dist/commands/evidence-pr.js.map +1 -0
  52. package/dist/commands/export.d.ts +22 -0
  53. package/dist/commands/export.d.ts.map +1 -0
  54. package/dist/commands/export.js +92 -0
  55. package/dist/commands/export.js.map +1 -0
  56. package/dist/commands/guard.d.ts +21 -0
  57. package/dist/commands/guard.d.ts.map +1 -0
  58. package/dist/commands/guard.js +272 -0
  59. package/dist/commands/guard.js.map +1 -0
  60. package/dist/commands/import.d.ts +3 -0
  61. package/dist/commands/import.d.ts.map +1 -0
  62. package/dist/{cli/commands → commands}/import.js +25 -26
  63. package/dist/commands/import.js.map +1 -0
  64. package/dist/commands/init.d.ts +5 -0
  65. package/dist/commands/init.d.ts.map +1 -0
  66. package/dist/commands/init.js +1288 -0
  67. package/dist/commands/init.js.map +1 -0
  68. package/dist/commands/inspect.d.ts +4 -0
  69. package/dist/commands/inspect.d.ts.map +1 -0
  70. package/dist/{cli/commands → commands}/inspect.js +97 -70
  71. package/dist/commands/inspect.js.map +1 -0
  72. package/dist/commands/learn.d.ts +2 -0
  73. package/dist/commands/learn.d.ts.map +1 -0
  74. package/dist/commands/learn.js +264 -0
  75. package/dist/commands/learn.js.map +1 -0
  76. package/dist/commands/migrate.d.ts +3 -0
  77. package/dist/commands/migrate.d.ts.map +1 -0
  78. package/dist/commands/migrate.js +270 -0
  79. package/dist/commands/migrate.js.map +1 -0
  80. package/dist/commands/plugin.d.ts.map +1 -0
  81. package/dist/{cli/commands → commands}/plugin.js +2 -2
  82. package/dist/commands/plugin.js.map +1 -0
  83. package/dist/commands/policy-verify.d.ts +46 -0
  84. package/dist/commands/policy-verify.d.ts.map +1 -0
  85. package/dist/commands/policy-verify.js +173 -0
  86. package/dist/commands/policy-verify.js.map +1 -0
  87. package/dist/commands/policy.d.ts +27 -0
  88. package/dist/commands/policy.d.ts.map +1 -0
  89. package/dist/commands/policy.js +590 -0
  90. package/dist/commands/policy.js.map +1 -0
  91. package/dist/{cli/commands → commands}/replay.d.ts +2 -1
  92. package/dist/commands/replay.d.ts.map +1 -0
  93. package/dist/{cli/commands → commands}/replay.js +78 -12
  94. package/dist/commands/replay.js.map +1 -0
  95. package/dist/commands/session-viewer.d.ts +5 -0
  96. package/dist/commands/session-viewer.d.ts.map +1 -0
  97. package/dist/commands/session-viewer.js +462 -0
  98. package/dist/commands/session-viewer.js.map +1 -0
  99. package/dist/commands/simulate.d.ts +7 -0
  100. package/dist/commands/simulate.d.ts.map +1 -0
  101. package/dist/commands/simulate.js +505 -0
  102. package/dist/commands/simulate.js.map +1 -0
  103. package/dist/commands/status.d.ts +2 -0
  104. package/dist/commands/status.d.ts.map +1 -0
  105. package/dist/commands/status.js +212 -0
  106. package/dist/commands/status.js.map +1 -0
  107. package/dist/commands/traces.d.ts +24 -0
  108. package/dist/commands/traces.d.ts.map +1 -0
  109. package/dist/commands/traces.js +282 -0
  110. package/dist/commands/traces.js.map +1 -0
  111. package/dist/commands/trust.d.ts +6 -0
  112. package/dist/commands/trust.d.ts.map +1 -0
  113. package/dist/commands/trust.js +129 -0
  114. package/dist/commands/trust.js.map +1 -0
  115. package/dist/evidence-summary.d.ts +35 -0
  116. package/dist/evidence-summary.d.ts.map +1 -0
  117. package/dist/evidence-summary.js +202 -0
  118. package/dist/evidence-summary.js.map +1 -0
  119. package/dist/{cli/file-event-store.d.ts → file-event-store.d.ts} +1 -1
  120. package/dist/file-event-store.d.ts.map +1 -0
  121. package/dist/{cli/file-event-store.js → file-event-store.js} +1 -1
  122. package/dist/file-event-store.js.map +1 -0
  123. package/{hooks → dist/hooks}/post-commit +3 -1
  124. package/{hooks → dist/hooks}/post-merge +3 -1
  125. package/dist/hooks/pre-commit +29 -0
  126. package/dist/policy-resolver.d.ts +32 -0
  127. package/dist/policy-resolver.d.ts.map +1 -0
  128. package/dist/policy-resolver.js +171 -0
  129. package/dist/policy-resolver.js.map +1 -0
  130. package/dist/{cli/recorder.d.ts → recorder.d.ts} +1 -1
  131. package/dist/recorder.d.ts.map +1 -0
  132. package/dist/{cli/recorder.js → recorder.js} +1 -1
  133. package/dist/recorder.js.map +1 -0
  134. package/dist/replay-timeline-html.d.ts +21 -0
  135. package/dist/replay-timeline-html.d.ts.map +1 -0
  136. package/dist/replay-timeline-html.js +414 -0
  137. package/dist/replay-timeline-html.js.map +1 -0
  138. package/dist/replay.d.ts.map +1 -0
  139. package/dist/{cli/replay.js → replay.js} +92 -1
  140. package/dist/replay.js.map +1 -0
  141. package/dist/{cli/session-store.d.ts → session-store.d.ts} +5 -0
  142. package/dist/session-store.d.ts.map +1 -0
  143. package/dist/{cli/session-store.js → session-store.js} +1 -0
  144. package/dist/session-store.js.map +1 -0
  145. package/dist/session-viewer-html.d.ts +10 -0
  146. package/dist/session-viewer-html.d.ts.map +1 -0
  147. package/dist/session-viewer-html.js +737 -0
  148. package/dist/session-viewer-html.js.map +1 -0
  149. package/dist/templates/ci-only.yaml +103 -0
  150. package/dist/templates/development.yaml +107 -0
  151. package/dist/templates/permissive.yaml +87 -0
  152. package/dist/templates/strict.yaml +112 -0
  153. package/dist/tui.d.ts +3 -0
  154. package/dist/tui.d.ts.map +1 -0
  155. package/dist/tui.js +2 -0
  156. package/dist/tui.js.map +1 -0
  157. package/package.json +42 -53
  158. package/dist/adapters/claude-code.d.ts +0 -24
  159. package/dist/adapters/claude-code.d.ts.map +0 -1
  160. package/dist/adapters/claude-code.js +0 -99
  161. package/dist/adapters/claude-code.js.map +0 -1
  162. package/dist/adapters/file.d.ts +0 -3
  163. package/dist/adapters/file.d.ts.map +0 -1
  164. package/dist/adapters/file.js +0 -35
  165. package/dist/adapters/file.js.map +0 -1
  166. package/dist/adapters/git.d.ts +0 -3
  167. package/dist/adapters/git.d.ts.map +0 -1
  168. package/dist/adapters/git.js +0 -61
  169. package/dist/adapters/git.js.map +0 -1
  170. package/dist/adapters/registry.d.ts +0 -5
  171. package/dist/adapters/registry.d.ts.map +0 -1
  172. package/dist/adapters/registry.js +0 -15
  173. package/dist/adapters/registry.js.map +0 -1
  174. package/dist/adapters/shell.d.ts +0 -8
  175. package/dist/adapters/shell.d.ts.map +0 -1
  176. package/dist/adapters/shell.js +0 -27
  177. package/dist/adapters/shell.js.map +0 -1
  178. package/dist/cli/args.d.ts.map +0 -1
  179. package/dist/cli/args.js.map +0 -1
  180. package/dist/cli/bin.d.ts.map +0 -1
  181. package/dist/cli/bin.js +0 -5769
  182. package/dist/cli/bin.js.map +0 -7
  183. package/dist/cli/colors.d.ts.map +0 -1
  184. package/dist/cli/colors.js.map +0 -1
  185. package/dist/cli/commands/claude-hook.d.ts +0 -2
  186. package/dist/cli/commands/claude-hook.d.ts.map +0 -1
  187. package/dist/cli/commands/claude-hook.js +0 -110
  188. package/dist/cli/commands/claude-hook.js.map +0 -1
  189. package/dist/cli/commands/claude-init.d.ts.map +0 -1
  190. package/dist/cli/commands/claude-init.js +0 -150
  191. package/dist/cli/commands/claude-init.js.map +0 -1
  192. package/dist/cli/commands/export.d.ts +0 -11
  193. package/dist/cli/commands/export.d.ts.map +0 -1
  194. package/dist/cli/commands/export.js +0 -113
  195. package/dist/cli/commands/export.js.map +0 -1
  196. package/dist/cli/commands/guard.d.ts +0 -12
  197. package/dist/cli/commands/guard.d.ts.map +0 -1
  198. package/dist/cli/commands/guard.js +0 -145
  199. package/dist/cli/commands/guard.js.map +0 -1
  200. package/dist/cli/commands/import.d.ts +0 -2
  201. package/dist/cli/commands/import.d.ts.map +0 -1
  202. package/dist/cli/commands/import.js.map +0 -1
  203. package/dist/cli/commands/inspect.d.ts +0 -3
  204. package/dist/cli/commands/inspect.d.ts.map +0 -1
  205. package/dist/cli/commands/inspect.js.map +0 -1
  206. package/dist/cli/commands/plugin.d.ts.map +0 -1
  207. package/dist/cli/commands/plugin.js.map +0 -1
  208. package/dist/cli/commands/replay.d.ts.map +0 -1
  209. package/dist/cli/commands/replay.js.map +0 -1
  210. package/dist/cli/file-event-store.d.ts.map +0 -1
  211. package/dist/cli/file-event-store.js.map +0 -1
  212. package/dist/cli/policy-resolver.d.ts +0 -4
  213. package/dist/cli/policy-resolver.d.ts.map +0 -1
  214. package/dist/cli/policy-resolver.js +0 -62
  215. package/dist/cli/policy-resolver.js.map +0 -1
  216. package/dist/cli/recorder.d.ts.map +0 -1
  217. package/dist/cli/recorder.js.map +0 -1
  218. package/dist/cli/replay.d.ts.map +0 -1
  219. package/dist/cli/replay.js.map +0 -1
  220. package/dist/cli/session-store.d.ts.map +0 -1
  221. package/dist/cli/session-store.js.map +0 -1
  222. package/dist/cli/tui.d.ts +0 -24
  223. package/dist/cli/tui.d.ts.map +0 -1
  224. package/dist/cli/tui.js +0 -197
  225. package/dist/cli/tui.js.map +0 -1
  226. package/dist/core/actions.d.ts +0 -11
  227. package/dist/core/actions.d.ts.map +0 -1
  228. package/dist/core/actions.js +0 -112
  229. package/dist/core/actions.js.map +0 -1
  230. package/dist/core/adapters.d.ts +0 -19
  231. package/dist/core/adapters.d.ts.map +0 -1
  232. package/dist/core/adapters.js +0 -85
  233. package/dist/core/adapters.js.map +0 -1
  234. package/dist/core/execution-log/bridge.d.ts +0 -12
  235. package/dist/core/execution-log/bridge.d.ts.map +0 -1
  236. package/dist/core/execution-log/bridge.js +0 -112
  237. package/dist/core/execution-log/bridge.js.map +0 -1
  238. package/dist/core/execution-log/event-log.d.ts +0 -7
  239. package/dist/core/execution-log/event-log.d.ts.map +0 -1
  240. package/dist/core/execution-log/event-log.js +0 -103
  241. package/dist/core/execution-log/event-log.js.map +0 -1
  242. package/dist/core/execution-log/event-projections.d.ts +0 -28
  243. package/dist/core/execution-log/event-projections.d.ts.map +0 -1
  244. package/dist/core/execution-log/event-projections.js +0 -272
  245. package/dist/core/execution-log/event-projections.js.map +0 -1
  246. package/dist/core/execution-log/event-schema.d.ts +0 -56
  247. package/dist/core/execution-log/event-schema.d.ts.map +0 -1
  248. package/dist/core/execution-log/event-schema.js +0 -160
  249. package/dist/core/execution-log/event-schema.js.map +0 -1
  250. package/dist/core/execution-log/index.d.ts +0 -7
  251. package/dist/core/execution-log/index.d.ts.map +0 -1
  252. package/dist/core/execution-log/index.js +0 -13
  253. package/dist/core/execution-log/index.js.map +0 -1
  254. package/dist/core/hash.d.ts +0 -5
  255. package/dist/core/hash.d.ts.map +0 -1
  256. package/dist/core/hash.js +0 -13
  257. package/dist/core/hash.js.map +0 -1
  258. package/dist/core/rng.d.ts +0 -29
  259. package/dist/core/rng.d.ts.map +0 -1
  260. package/dist/core/rng.js +0 -48
  261. package/dist/core/rng.js.map +0 -1
  262. package/dist/core/types.d.ts +0 -746
  263. package/dist/core/types.d.ts.map +0 -1
  264. package/dist/core/types.js +0 -8
  265. package/dist/core/types.js.map +0 -1
  266. package/dist/events/bus.d.ts +0 -24
  267. package/dist/events/bus.d.ts.map +0 -1
  268. package/dist/events/bus.js +0 -64
  269. package/dist/events/bus.js.map +0 -1
  270. package/dist/events/decision-jsonl.d.ts +0 -8
  271. package/dist/events/decision-jsonl.d.ts.map +0 -1
  272. package/dist/events/decision-jsonl.js +0 -44
  273. package/dist/events/decision-jsonl.js.map +0 -1
  274. package/dist/events/jsonl.d.ts +0 -8
  275. package/dist/events/jsonl.d.ts.map +0 -1
  276. package/dist/events/jsonl.js +0 -46
  277. package/dist/events/jsonl.js.map +0 -1
  278. package/dist/events/schema.d.ts +0 -59
  279. package/dist/events/schema.d.ts.map +0 -1
  280. package/dist/events/schema.js +0 -296
  281. package/dist/events/schema.js.map +0 -1
  282. package/dist/events/store.d.ts +0 -7
  283. package/dist/events/store.d.ts.map +0 -1
  284. package/dist/events/store.js +0 -64
  285. package/dist/events/store.js.map +0 -1
  286. package/dist/invariants/checker.d.ts +0 -15
  287. package/dist/invariants/checker.d.ts.map +0 -1
  288. package/dist/invariants/checker.js +0 -52
  289. package/dist/invariants/checker.js.map +0 -1
  290. package/dist/invariants/definitions.d.ts +0 -33
  291. package/dist/invariants/definitions.d.ts.map +0 -1
  292. package/dist/invariants/definitions.js +0 -168
  293. package/dist/invariants/definitions.js.map +0 -1
  294. package/dist/kernel/aab.d.ts +0 -26
  295. package/dist/kernel/aab.d.ts.map +0 -1
  296. package/dist/kernel/aab.js +0 -149
  297. package/dist/kernel/aab.js.map +0 -1
  298. package/dist/kernel/blast-radius.d.ts +0 -60
  299. package/dist/kernel/blast-radius.d.ts.map +0 -1
  300. package/dist/kernel/blast-radius.js +0 -146
  301. package/dist/kernel/blast-radius.js.map +0 -1
  302. package/dist/kernel/decision.d.ts +0 -40
  303. package/dist/kernel/decision.d.ts.map +0 -1
  304. package/dist/kernel/decision.js +0 -92
  305. package/dist/kernel/decision.js.map +0 -1
  306. package/dist/kernel/decisions/factory.d.ts +0 -12
  307. package/dist/kernel/decisions/factory.d.ts.map +0 -1
  308. package/dist/kernel/decisions/factory.js +0 -56
  309. package/dist/kernel/decisions/factory.js.map +0 -1
  310. package/dist/kernel/decisions/types.d.ts +0 -70
  311. package/dist/kernel/decisions/types.d.ts.map +0 -1
  312. package/dist/kernel/decisions/types.js +0 -5
  313. package/dist/kernel/decisions/types.js.map +0 -1
  314. package/dist/kernel/evidence.d.ts +0 -29
  315. package/dist/kernel/evidence.d.ts.map +0 -1
  316. package/dist/kernel/evidence.js +0 -61
  317. package/dist/kernel/evidence.js.map +0 -1
  318. package/dist/kernel/kernel.d.ts +0 -47
  319. package/dist/kernel/kernel.d.ts.map +0 -1
  320. package/dist/kernel/kernel.js +0 -377
  321. package/dist/kernel/kernel.js.map +0 -1
  322. package/dist/kernel/monitor.d.ts +0 -35
  323. package/dist/kernel/monitor.d.ts.map +0 -1
  324. package/dist/kernel/monitor.js +0 -144
  325. package/dist/kernel/monitor.js.map +0 -1
  326. package/dist/kernel/replay-comparator.d.ts +0 -72
  327. package/dist/kernel/replay-comparator.d.ts.map +0 -1
  328. package/dist/kernel/replay-comparator.js +0 -251
  329. package/dist/kernel/replay-comparator.js.map +0 -1
  330. package/dist/kernel/replay-engine.d.ts +0 -108
  331. package/dist/kernel/replay-engine.d.ts.map +0 -1
  332. package/dist/kernel/replay-engine.js +0 -241
  333. package/dist/kernel/replay-engine.js.map +0 -1
  334. package/dist/kernel/replay-processor.d.ts +0 -109
  335. package/dist/kernel/replay-processor.d.ts.map +0 -1
  336. package/dist/kernel/replay-processor.js +0 -118
  337. package/dist/kernel/replay-processor.js.map +0 -1
  338. package/dist/kernel/simulation/filesystem-simulator.d.ts +0 -3
  339. package/dist/kernel/simulation/filesystem-simulator.d.ts.map +0 -1
  340. package/dist/kernel/simulation/filesystem-simulator.js +0 -81
  341. package/dist/kernel/simulation/filesystem-simulator.js.map +0 -1
  342. package/dist/kernel/simulation/git-simulator.d.ts +0 -5
  343. package/dist/kernel/simulation/git-simulator.d.ts.map +0 -1
  344. package/dist/kernel/simulation/git-simulator.js +0 -115
  345. package/dist/kernel/simulation/git-simulator.js.map +0 -1
  346. package/dist/kernel/simulation/package-simulator.d.ts +0 -5
  347. package/dist/kernel/simulation/package-simulator.d.ts.map +0 -1
  348. package/dist/kernel/simulation/package-simulator.js +0 -164
  349. package/dist/kernel/simulation/package-simulator.js.map +0 -1
  350. package/dist/kernel/simulation/registry.d.ts +0 -3
  351. package/dist/kernel/simulation/registry.d.ts.map +0 -1
  352. package/dist/kernel/simulation/registry.js +0 -24
  353. package/dist/kernel/simulation/registry.js.map +0 -1
  354. package/dist/kernel/simulation/types.d.ts +0 -35
  355. package/dist/kernel/simulation/types.d.ts.map +0 -1
  356. package/dist/kernel/simulation/types.js +0 -4
  357. package/dist/kernel/simulation/types.js.map +0 -1
  358. package/dist/plugins/discovery.d.ts +0 -45
  359. package/dist/plugins/discovery.d.ts.map +0 -1
  360. package/dist/plugins/discovery.js +0 -89
  361. package/dist/plugins/discovery.js.map +0 -1
  362. package/dist/plugins/index.d.ts +0 -10
  363. package/dist/plugins/index.d.ts.map +0 -1
  364. package/dist/plugins/index.js +0 -7
  365. package/dist/plugins/index.js.map +0 -1
  366. package/dist/plugins/registry.d.ts +0 -52
  367. package/dist/plugins/registry.d.ts.map +0 -1
  368. package/dist/plugins/registry.js +0 -148
  369. package/dist/plugins/registry.js.map +0 -1
  370. package/dist/plugins/sandbox.d.ts +0 -87
  371. package/dist/plugins/sandbox.d.ts.map +0 -1
  372. package/dist/plugins/sandbox.js +0 -122
  373. package/dist/plugins/sandbox.js.map +0 -1
  374. package/dist/plugins/types.d.ts +0 -61
  375. package/dist/plugins/types.d.ts.map +0 -1
  376. package/dist/plugins/types.js +0 -16
  377. package/dist/plugins/types.js.map +0 -1
  378. package/dist/plugins/validator.d.ts +0 -36
  379. package/dist/plugins/validator.d.ts.map +0 -1
  380. package/dist/plugins/validator.js +0 -276
  381. package/dist/plugins/validator.js.map +0 -1
  382. package/dist/policy/evaluator.d.ts +0 -41
  383. package/dist/policy/evaluator.d.ts.map +0 -1
  384. package/dist/policy/evaluator.js +0 -111
  385. package/dist/policy/evaluator.js.map +0 -1
  386. package/dist/policy/loader.d.ts +0 -13
  387. package/dist/policy/loader.d.ts.map +0 -1
  388. package/dist/policy/loader.js +0 -118
  389. package/dist/policy/loader.js.map +0 -1
  390. package/dist/policy/pack-loader.d.ts +0 -40
  391. package/dist/policy/pack-loader.d.ts.map +0 -1
  392. package/dist/policy/pack-loader.js +0 -138
  393. package/dist/policy/pack-loader.js.map +0 -1
  394. package/dist/policy/yaml-loader.d.ts +0 -23
  395. package/dist/policy/yaml-loader.d.ts.map +0 -1
  396. package/dist/policy/yaml-loader.js +0 -222
  397. package/dist/policy/yaml-loader.js.map +0 -1
  398. package/dist/renderers/index.d.ts +0 -6
  399. package/dist/renderers/index.d.ts.map +0 -1
  400. package/dist/renderers/index.js +0 -4
  401. package/dist/renderers/index.js.map +0 -1
  402. package/dist/renderers/registry.d.ts +0 -39
  403. package/dist/renderers/registry.d.ts.map +0 -1
  404. package/dist/renderers/registry.js +0 -97
  405. package/dist/renderers/registry.js.map +0 -1
  406. package/dist/renderers/tui-renderer.d.ts +0 -18
  407. package/dist/renderers/tui-renderer.d.ts.map +0 -1
  408. package/dist/renderers/tui-renderer.js +0 -57
  409. package/dist/renderers/tui-renderer.js.map +0 -1
  410. package/dist/renderers/types.d.ts +0 -52
  411. package/dist/renderers/types.d.ts.map +0 -1
  412. package/dist/renderers/types.js +0 -4
  413. package/dist/renderers/types.js.map +0 -1
  414. package/dist/telemetry/index.d.ts +0 -3
  415. package/dist/telemetry/index.d.ts.map +0 -1
  416. package/dist/telemetry/index.js +0 -2
  417. package/dist/telemetry/index.js.map +0 -1
  418. package/dist/telemetry/runtimeLogger.d.ts +0 -9
  419. package/dist/telemetry/runtimeLogger.d.ts.map +0 -1
  420. package/dist/telemetry/runtimeLogger.js +0 -68
  421. package/dist/telemetry/runtimeLogger.js.map +0 -1
  422. package/dist/telemetry/types.d.ts +0 -22
  423. package/dist/telemetry/types.d.ts.map +0 -1
  424. package/dist/telemetry/types.js +0 -4
  425. package/dist/telemetry/types.js.map +0 -1
  426. package/hooks/pre-commit +0 -28
  427. /package/dist/{cli/args.d.ts → args.d.ts} +0 -0
  428. /package/dist/{cli/args.js → args.js} +0 -0
  429. /package/dist/{cli/bin.d.ts → bin.d.ts} +0 -0
  430. /package/dist/{cli/colors.d.ts → colors.d.ts} +0 -0
  431. /package/dist/{cli/colors.js → colors.js} +0 -0
  432. /package/dist/{cli/commands → commands}/claude-init.d.ts +0 -0
  433. /package/dist/{cli/commands → commands}/plugin.d.ts +0 -0
  434. /package/dist/{cli/replay.d.ts → replay.d.ts} +0 -0
@@ -0,0 +1,737 @@
1
+ // Session viewer HTML generator — produces a self-contained HTML file for
2
+ // interactive governance session visualization in a browser.
3
+ function escapeHtml(str) {
4
+ return str
5
+ .replace(/&/g, '&')
6
+ .replace(/</g, '&lt;')
7
+ .replace(/>/g, '&gt;')
8
+ .replace(/"/g, '&quot;');
9
+ }
10
+ function safeJsonEmbed(data) {
11
+ // JSON.stringify then escape </ sequences to prevent script tag injection.
12
+ return JSON.stringify(data).replace(/<\//g, '<\\/');
13
+ }
14
+ function formatTs(ms) {
15
+ const d = new Date(ms);
16
+ return d.toISOString().replace('T', ' ').replace('Z', ' UTC');
17
+ }
18
+ function formatDuration(ms) {
19
+ if (ms < 1000)
20
+ return `${ms}ms`;
21
+ const seconds = Math.floor(ms / 1000);
22
+ const minutes = Math.floor(seconds / 60);
23
+ if (minutes === 0)
24
+ return `${seconds}s`;
25
+ return `${minutes}m ${seconds % 60}s`;
26
+ }
27
+ export function generateSessionHtml(session, summary, decisions, events, options) {
28
+ const runId = escapeHtml(session.runId);
29
+ const startTime = session.startEvent ? formatTs(session.startEvent.timestamp) : 'N/A';
30
+ const duration = formatDuration(session.summary.durationMs);
31
+ const liveEndpoint = options?.liveEndpoint;
32
+ // Serialize all data for client-side rendering
33
+ const embeddedData = safeJsonEmbed({
34
+ session: {
35
+ runId: session.runId,
36
+ actions: session.actions,
37
+ summary: session.summary,
38
+ startEvent: session.startEvent,
39
+ endEvent: session.endEvent,
40
+ },
41
+ summary,
42
+ decisions,
43
+ events,
44
+ liveEndpoint: liveEndpoint || null,
45
+ });
46
+ return `<!DOCTYPE html>
47
+ <html lang="en">
48
+ <head>
49
+ <meta charset="UTF-8">
50
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
51
+ <title>AgentGuard Session — ${runId}</title>
52
+ <link rel="preconnect" href="https://fonts.googleapis.com">
53
+ <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&family=IBM+Plex+Sans:wght@400;500;600;700&display=swap" rel="stylesheet">
54
+ <script src="https://cdn.tailwindcss.com"><\/script>
55
+ <script>
56
+ tailwind.config = {
57
+ theme: {
58
+ extend: {
59
+ colors: {
60
+ bg: '#0F172A',
61
+ surface: '#1E293B',
62
+ 'surface-light': '#334155',
63
+ cta: '#22C55E',
64
+ 'cta-dark': '#16A34A',
65
+ text: '#F8FAFC',
66
+ muted: '#94A3B8',
67
+ danger: '#EF4444',
68
+ warning: '#F59E0B',
69
+ info: '#3B82F6',
70
+ },
71
+ fontFamily: {
72
+ mono: ['JetBrains Mono', 'monospace'],
73
+ sans: ['IBM Plex Sans', 'sans-serif'],
74
+ },
75
+ },
76
+ },
77
+ };
78
+ <\/script>
79
+ <style>
80
+ body {
81
+ font-family: 'IBM Plex Sans', sans-serif;
82
+ background: #0F172A;
83
+ color: #F8FAFC;
84
+ margin: 0;
85
+ }
86
+ code, pre, .font-mono {
87
+ font-family: 'JetBrains Mono', monospace;
88
+ }
89
+ .card {
90
+ background: #1E293B;
91
+ border-radius: 0.75rem;
92
+ padding: 1.5rem;
93
+ border: 1px solid #334155;
94
+ }
95
+ .card-sm {
96
+ background: #1E293B;
97
+ border-radius: 0.5rem;
98
+ padding: 1rem;
99
+ border: 1px solid #334155;
100
+ }
101
+ .badge {
102
+ display: inline-block;
103
+ padding: 0.125rem 0.5rem;
104
+ border-radius: 9999px;
105
+ font-size: 0.75rem;
106
+ font-weight: 600;
107
+ text-transform: uppercase;
108
+ }
109
+ .badge-allowed { background: rgba(34,197,94,0.15); color: #22C55E; }
110
+ .badge-denied { background: rgba(239,68,68,0.15); color: #EF4444; }
111
+ .badge-escalated { background: rgba(245,158,11,0.15); color: #F59E0B; }
112
+ .badge-executed { background: rgba(59,130,246,0.15); color: #3B82F6; }
113
+ .badge-failed { background: rgba(239,68,68,0.15); color: #EF4444; }
114
+
115
+ .timeline-dot {
116
+ width: 12px; height: 12px;
117
+ border-radius: 50%;
118
+ flex-shrink: 0;
119
+ }
120
+ .dot-allowed { background: #22C55E; }
121
+ .dot-denied { background: #EF4444; }
122
+ .dot-escalated { background: #F59E0B; }
123
+
124
+ .timeline-line {
125
+ width: 2px;
126
+ background: #334155;
127
+ position: absolute;
128
+ left: 5px;
129
+ top: 12px;
130
+ bottom: -1rem;
131
+ }
132
+
133
+ details summary { cursor: pointer; }
134
+ details summary::-webkit-details-marker { display: none; }
135
+
136
+ .escalation-step {
137
+ flex: 1;
138
+ text-align: center;
139
+ padding: 0.5rem;
140
+ border-radius: 0.375rem;
141
+ font-size: 0.75rem;
142
+ font-weight: 600;
143
+ opacity: 0.3;
144
+ transition: opacity 0.3s;
145
+ }
146
+ .escalation-step.active { opacity: 1; }
147
+ .escalation-NORMAL { background: rgba(34,197,94,0.2); color: #22C55E; }
148
+ .escalation-ELEVATED { background: rgba(245,158,11,0.2); color: #F59E0B; }
149
+ .escalation-HIGH { background: rgba(249,115,22,0.2); color: #F97316; }
150
+ .escalation-LOCKDOWN { background: rgba(239,68,68,0.2); color: #EF4444; }
151
+
152
+ .event-row:hover { background: #334155; }
153
+
154
+ @keyframes pulse {
155
+ 0%, 100% { opacity: 1; }
156
+ 50% { opacity: 0.5; }
157
+ }
158
+ @media (max-width: 768px) {
159
+ .summary-grid { grid-template-columns: repeat(2, 1fr) !important; }
160
+ }
161
+ </style>
162
+ </head>
163
+ <body class="bg-bg text-text min-h-screen">
164
+ <div id="app" style="max-width:1200px; margin:0 auto; padding:2rem 1rem;">
165
+ <!-- Header -->
166
+ <header style="margin-bottom:2rem;">
167
+ <div style="display:flex; align-items:center; gap:0.75rem; margin-bottom:0.5rem;">
168
+ <svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="#22C55E" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
169
+ <path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/>
170
+ </svg>
171
+ <h1 style="font-size:1.5rem; font-weight:700; margin:0;">AgentGuard Session Viewer</h1>
172
+ <span id="live-badge" style="display:none; margin-left:auto; padding:0.25rem 0.75rem; border-radius:9999px; font-size:0.75rem; font-weight:600; background:rgba(34,197,94,0.15); color:#22C55E; animation:pulse 2s infinite;">LIVE</span>
173
+ </div>
174
+ <div class="font-mono" style="font-size:0.875rem; color:#94A3B8;">
175
+ <span style="color:#F8FAFC; font-weight:500;">${runId}</span>
176
+ <span style="margin:0 0.5rem;">&middot;</span>
177
+ ${escapeHtml(startTime)}
178
+ <span style="margin:0 0.5rem;">&middot;</span>
179
+ Duration: ${escapeHtml(duration)}
180
+ </div>
181
+ </header>
182
+
183
+ <!-- Summary Cards -->
184
+ <section style="margin-bottom:2rem;">
185
+ <div class="summary-grid" style="display:grid; grid-template-columns:repeat(3, 1fr); gap:1rem;">
186
+ <div class="card-sm" style="text-align:center;">
187
+ <div style="font-size:2rem; font-weight:700;">${session.summary.totalActions}</div>
188
+ <div style="color:#94A3B8; font-size:0.875rem;">Total Actions</div>
189
+ </div>
190
+ <div class="card-sm" style="text-align:center;">
191
+ <div style="font-size:2rem; font-weight:700; color:#22C55E;">${session.summary.allowed}</div>
192
+ <div style="color:#94A3B8; font-size:0.875rem;">Allowed</div>
193
+ </div>
194
+ <div class="card-sm" style="text-align:center;">
195
+ <div style="font-size:2rem; font-weight:700; color:#EF4444;">${session.summary.denied}</div>
196
+ <div style="color:#94A3B8; font-size:0.875rem;">Denied</div>
197
+ </div>
198
+ <div class="card-sm" style="text-align:center;">
199
+ <div style="font-size:2rem; font-weight:700; color:#EF4444;">${summary.invariantViolations}</div>
200
+ <div style="color:#94A3B8; font-size:0.875rem;">Violations</div>
201
+ </div>
202
+ <div class="card-sm" style="text-align:center;">
203
+ <div style="font-size:2rem; font-weight:700; color:#F59E0B;">${summary.escalations}</div>
204
+ <div style="color:#94A3B8; font-size:0.875rem;">Escalations</div>
205
+ </div>
206
+ <div class="card-sm" style="text-align:center;">
207
+ <div style="font-size:2rem; font-weight:700; color:${summary.maxEscalationLevel === 'NORMAL' ? '#22C55E' : summary.maxEscalationLevel === 'ELEVATED' ? '#F59E0B' : '#EF4444'};">${escapeHtml(summary.maxEscalationLevel)}</div>
208
+ <div style="color:#94A3B8; font-size:0.875rem;">Max Escalation</div>
209
+ </div>
210
+ </div>
211
+ </section>
212
+
213
+ <!-- Escalation Progression -->
214
+ <section class="card" style="margin-bottom:2rem;" id="escalation-section">
215
+ <h2 style="font-size:1.125rem; font-weight:600; margin:0 0 1rem;">Escalation Progression</h2>
216
+ <div id="escalation-bar" style="display:flex; gap:0.5rem;"></div>
217
+ </section>
218
+
219
+ <!-- Action Timeline -->
220
+ <section class="card" style="margin-bottom:2rem;">
221
+ <h2 style="font-size:1.125rem; font-weight:600; margin:0 0 1rem;">Action Timeline</h2>
222
+ <div id="action-timeline"></div>
223
+ </section>
224
+
225
+ <!-- Invariant Violations -->
226
+ <section class="card" style="margin-bottom:2rem;" id="violations-section">
227
+ <h2 style="font-size:1.125rem; font-weight:600; margin:0 0 1rem;">Invariant Violations</h2>
228
+ <div id="violations-list"></div>
229
+ </section>
230
+
231
+ <!-- Action Type Breakdown -->
232
+ <section class="card" style="margin-bottom:2rem;">
233
+ <h2 style="font-size:1.125rem; font-weight:600; margin:0 0 1rem;">Action Type Breakdown</h2>
234
+ <div id="action-breakdown"></div>
235
+ </section>
236
+
237
+ <!-- Raw Event Stream -->
238
+ <section class="card" style="margin-bottom:2rem;">
239
+ <details>
240
+ <summary style="font-size:1.125rem; font-weight:600; display:flex; align-items:center; gap:0.5rem;">
241
+ <span id="event-toggle-icon" style="transition:transform 0.2s;">&#9654;</span>
242
+ Raw Event Stream
243
+ <span style="font-size:0.75rem; color:#94A3B8; font-weight:400;" id="event-count"></span>
244
+ </summary>
245
+ <div id="event-stream" style="margin-top:1rem; max-height:600px; overflow-y:auto;"></div>
246
+ </details>
247
+ </section>
248
+
249
+ <!-- Footer -->
250
+ <footer style="text-align:center; color:#94A3B8; font-size:0.75rem; padding:1rem 0;">
251
+ Generated by AgentGuard &middot; ${escapeHtml(startTime)}
252
+ </footer>
253
+ </div>
254
+
255
+ <script>
256
+ const DATA = ${embeddedData};
257
+
258
+ // ---- Helpers ----
259
+ function esc(s) { return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;'); }
260
+ function relTime(ts) {
261
+ const start = DATA.session.startEvent ? DATA.session.startEvent.timestamp : 0;
262
+ const ms = ts - start;
263
+ if (ms < 1000) return ms + 'ms';
264
+ const s = Math.floor(ms / 1000);
265
+ const m = Math.floor(s / 60);
266
+ if (m === 0) return s + 's';
267
+ return m + 'm ' + (s % 60) + 's';
268
+ }
269
+ function prettyJson(obj) {
270
+ return JSON.stringify(obj, null, 2);
271
+ }
272
+
273
+ // ---- Escalation Progression ----
274
+ (function() {
275
+ const levels = ['NORMAL', 'ELEVATED', 'HIGH', 'LOCKDOWN'];
276
+ const maxLevel = DATA.summary.maxEscalationLevel || 'NORMAL';
277
+ const maxIdx = levels.indexOf(maxLevel);
278
+ const bar = document.getElementById('escalation-bar');
279
+ levels.forEach(function(level, i) {
280
+ const step = document.createElement('div');
281
+ step.className = 'escalation-step escalation-' + level + (i <= maxIdx ? ' active' : '');
282
+ step.textContent = level;
283
+ bar.appendChild(step);
284
+ });
285
+ if (maxIdx <= 0 && DATA.summary.escalations === 0) {
286
+ document.getElementById('escalation-section').style.display = 'none';
287
+ }
288
+ })();
289
+
290
+ // ---- Action Timeline ----
291
+ (function() {
292
+ const container = document.getElementById('action-timeline');
293
+ const actions = DATA.session.actions;
294
+ if (!actions || actions.length === 0) {
295
+ container.innerHTML = '<div style="color:#94A3B8;">No actions recorded in this session.</div>';
296
+ return;
297
+ }
298
+ actions.forEach(function(action, idx) {
299
+ const dotClass = !action.allowed ? 'dot-denied' : action.escalationEvent ? 'dot-escalated' : 'dot-allowed';
300
+ const statusBadge = !action.allowed
301
+ ? '<span class="badge badge-denied">DENIED</span>'
302
+ : action.executed
303
+ ? (action.succeeded
304
+ ? '<span class="badge badge-allowed">EXECUTED</span>'
305
+ : '<span class="badge badge-failed">FAILED</span>')
306
+ : '<span class="badge badge-executed">ALLOWED</span>';
307
+
308
+ const ts = action.requestedEvent ? relTime(action.requestedEvent.timestamp) : '';
309
+
310
+ // Find matching decision record
311
+ const decision = DATA.decisions.find(function(d) {
312
+ return d.action && d.action.type === action.actionType && d.action.target === action.target;
313
+ });
314
+
315
+ let detailHtml = '';
316
+ if (decision) {
317
+ detailHtml = '<div class="card-sm" style="margin-top:0.75rem; font-size:0.8125rem;">';
318
+ detailHtml += '<div style="display:grid; grid-template-columns:auto 1fr; gap:0.25rem 1rem;">';
319
+ detailHtml += '<span style="color:#94A3B8;">Outcome:</span><span>' + esc(decision.outcome) + '</span>';
320
+ if (decision.reason) detailHtml += '<span style="color:#94A3B8;">Reason:</span><span>' + esc(decision.reason) + '</span>';
321
+ if (decision.intervention) detailHtml += '<span style="color:#94A3B8;">Intervention:</span><span>' + esc(decision.intervention) + '</span>';
322
+ if (decision.policy && decision.policy.matchedPolicyName) {
323
+ detailHtml += '<span style="color:#94A3B8;">Policy:</span><span>' + esc(decision.policy.matchedPolicyName) + '</span>';
324
+ }
325
+ if (decision.invariants && !decision.invariants.allHold) {
326
+ const viols = decision.invariants.violations || [];
327
+ detailHtml += '<span style="color:#94A3B8;">Invariants:</span><span style="color:#EF4444;">' +
328
+ viols.map(function(v) { return esc(v.name) + ' (severity ' + v.severity + ')'; }).join(', ') + '</span>';
329
+ }
330
+ if (decision.simulation) {
331
+ const sim = decision.simulation;
332
+ detailHtml += '<span style="color:#94A3B8;">Simulation:</span><span>risk=' + esc(String(sim.riskLevel || 'unknown')) + ', blast=' + esc(String(sim.blastRadius || '?')) + '</span>';
333
+ }
334
+ if (decision.execution) {
335
+ const ex = decision.execution;
336
+ if (ex.executed) {
337
+ detailHtml += '<span style="color:#94A3B8;">Execution:</span><span>' + (ex.success ? 'Success' : 'Failed') + (ex.durationMs != null ? ' (' + ex.durationMs + 'ms)' : '') + '</span>';
338
+ if (ex.error) detailHtml += '<span style="color:#94A3B8;">Error:</span><span style="color:#EF4444;">' + esc(ex.error) + '</span>';
339
+ }
340
+ }
341
+ if (decision.monitor) {
342
+ const levels = ['NORMAL', 'ELEVATED', 'HIGH', 'LOCKDOWN'];
343
+ detailHtml += '<span style="color:#94A3B8;">Monitor:</span><span>' + esc(levels[decision.monitor.escalationLevel] || String(decision.monitor.escalationLevel)) + ' (evals: ' + decision.monitor.totalEvaluations + ', denials: ' + decision.monitor.totalDenials + ')</span>';
344
+ }
345
+ detailHtml += '</div></div>';
346
+ }
347
+
348
+ // Governance events
349
+ let govHtml = '';
350
+ if (action.governanceEvents && action.governanceEvents.length > 0) {
351
+ govHtml = '<div style="margin-top:0.5rem;">';
352
+ action.governanceEvents.forEach(function(g) {
353
+ const detail = g.reason || g.invariant || g.policy || '';
354
+ govHtml += '<div style="font-size:0.8125rem; color:#F59E0B; padding:0.125rem 0;">&#9888; ' + esc(g.kind) + (detail ? ' — ' + esc(String(detail)) : '') + '</div>';
355
+ });
356
+ govHtml += '</div>';
357
+ }
358
+
359
+ const entryDiv = document.createElement('div');
360
+ entryDiv.style.cssText = 'position:relative; padding-left:2rem; padding-bottom:1rem;';
361
+ entryDiv.innerHTML =
362
+ (idx < actions.length - 1 ? '<div class="timeline-line"></div>' : '') +
363
+ '<div class="timeline-dot ' + dotClass + '" style="position:absolute; left:0; top:4px;"></div>' +
364
+ '<details>' +
365
+ '<summary style="display:flex; align-items:center; gap:0.75rem; flex-wrap:wrap;">' +
366
+ '<span class="font-mono" style="font-size:0.75rem; color:#94A3B8; min-width:4rem;">' + esc(ts) + '</span>' +
367
+ '<span style="font-weight:500;">' + esc(action.actionType) + '</span>' +
368
+ '<span style="color:#94A3B8; font-size:0.875rem; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; max-width:400px;">' + esc(action.target || '') + '</span>' +
369
+ statusBadge +
370
+ '</summary>' +
371
+ govHtml +
372
+ detailHtml +
373
+ '</details>';
374
+ container.appendChild(entryDiv);
375
+ });
376
+ })();
377
+
378
+ // ---- Invariant Violations ----
379
+ (function() {
380
+ const container = document.getElementById('violations-list');
381
+ const violationEvents = DATA.events.filter(function(e) { return e.kind === 'InvariantViolation'; });
382
+ if (violationEvents.length === 0) {
383
+ document.getElementById('violations-section').style.display = 'none';
384
+ return;
385
+ }
386
+ violationEvents.forEach(function(v) {
387
+ const div = document.createElement('div');
388
+ div.className = 'card-sm';
389
+ div.style.marginBottom = '0.5rem';
390
+ div.innerHTML =
391
+ '<div style="display:flex; align-items:center; gap:0.5rem; margin-bottom:0.25rem;">' +
392
+ '<span style="color:#EF4444; font-weight:600;">&#9888; ' + esc(v.invariant || 'Unknown') + '</span>' +
393
+ (v.severity != null ? '<span class="badge badge-denied">severity ' + esc(String(v.severity)) + '</span>' : '') +
394
+ '</div>' +
395
+ '<div style="font-size:0.8125rem; color:#94A3B8;">' +
396
+ (v.expected ? 'Expected: ' + esc(String(v.expected)) : '') +
397
+ (v.actual ? ' &middot; Actual: ' + esc(String(v.actual)) : '') +
398
+ '</div>';
399
+ container.appendChild(div);
400
+ });
401
+ })();
402
+
403
+ // ---- Action Type Breakdown ----
404
+ (function() {
405
+ const container = document.getElementById('action-breakdown');
406
+ const breakdown = DATA.summary.actionTypeBreakdown || {};
407
+ const types = Object.keys(breakdown).sort();
408
+ if (types.length === 0) {
409
+ container.innerHTML = '<div style="color:#94A3B8;">No action types recorded.</div>';
410
+ return;
411
+ }
412
+ let html = '<table style="width:100%; border-collapse:collapse; font-size:0.875rem;">';
413
+ html += '<thead><tr style="border-bottom:1px solid #334155;">' +
414
+ '<th style="text-align:left; padding:0.5rem; color:#94A3B8;">Action Type</th>' +
415
+ '<th style="text-align:right; padding:0.5rem; color:#22C55E;">Allowed</th>' +
416
+ '<th style="text-align:right; padding:0.5rem; color:#EF4444;">Denied</th>' +
417
+ '</tr></thead><tbody>';
418
+ types.forEach(function(t) {
419
+ const c = breakdown[t];
420
+ html += '<tr style="border-bottom:1px solid #1E293B;">' +
421
+ '<td class="font-mono" style="padding:0.5rem;">' + esc(t) + '</td>' +
422
+ '<td style="text-align:right; padding:0.5rem; color:#22C55E;">' + c.allowed + '</td>' +
423
+ '<td style="text-align:right; padding:0.5rem; color:#EF4444;">' + c.denied + '</td>' +
424
+ '</tr>';
425
+ });
426
+ html += '</tbody></table>';
427
+ container.innerHTML = html;
428
+ })();
429
+
430
+ // ---- Raw Event Stream (lazy-loaded) ----
431
+ (function() {
432
+ const container = document.getElementById('event-stream');
433
+ const countEl = document.getElementById('event-count');
434
+ const toggleIcon = document.getElementById('event-toggle-icon');
435
+ const allEvents = DATA.events || [];
436
+ countEl.textContent = '(' + allEvents.length + ' events)';
437
+
438
+ const BATCH_SIZE = 100;
439
+ let shown = 0;
440
+
441
+ // Rotate toggle icon on open/close
442
+ container.parentElement.addEventListener('toggle', function() {
443
+ toggleIcon.style.transform = this.open ? 'rotate(90deg)' : '';
444
+ if (this.open && shown === 0) renderBatch();
445
+ });
446
+
447
+ function renderBatch() {
448
+ const end = Math.min(shown + BATCH_SIZE, allEvents.length);
449
+ for (let i = shown; i < end; i++) {
450
+ const ev = allEvents[i];
451
+ const row = document.createElement('details');
452
+ row.className = 'event-row';
453
+ row.style.cssText = 'padding:0.375rem 0.5rem; border-bottom:1px solid #1E293B; font-size:0.8125rem; border-radius:0.25rem;';
454
+ const kindColor = ev.kind.includes('Denied') || ev.kind.includes('Violation') || ev.kind.includes('Failed')
455
+ ? '#EF4444'
456
+ : ev.kind.includes('Allowed') || ev.kind.includes('Executed')
457
+ ? '#22C55E'
458
+ : ev.kind.includes('Escalat')
459
+ ? '#F59E0B'
460
+ : '#94A3B8';
461
+ row.innerHTML =
462
+ '<summary class="font-mono" style="display:flex; gap:1rem; align-items:center;">' +
463
+ '<span style="color:#94A3B8; min-width:4rem;">' + esc(String(i + 1)) + '</span>' +
464
+ '<span style="color:' + kindColor + '; font-weight:500; min-width:14rem;">' + esc(ev.kind) + '</span>' +
465
+ '<span style="color:#94A3B8; font-size:0.75rem;">' + esc(new Date(ev.timestamp).toISOString().slice(11, 23)) + '</span>' +
466
+ '</summary>' +
467
+ '<pre class="font-mono" style="margin:0.5rem 0 0.5rem 5rem; padding:0.75rem; background:#0F172A; border-radius:0.375rem; font-size:0.75rem; overflow-x:auto; white-space:pre-wrap; word-break:break-all;">' + esc(prettyJson(ev)) + '</pre>';
468
+ container.appendChild(row);
469
+ }
470
+ shown = end;
471
+ // Show "load more" button if needed
472
+ const existingBtn = container.querySelector('.load-more-btn');
473
+ if (existingBtn) existingBtn.remove();
474
+ if (shown < allEvents.length) {
475
+ const btn = document.createElement('button');
476
+ btn.className = 'load-more-btn';
477
+ btn.style.cssText = 'display:block; margin:0.75rem auto; padding:0.5rem 1.5rem; background:#334155; color:#F8FAFC; border:1px solid #475569; border-radius:0.375rem; cursor:pointer; font-size:0.8125rem;';
478
+ btn.textContent = 'Load more (' + (allEvents.length - shown) + ' remaining)';
479
+ btn.onclick = renderBatch;
480
+ container.appendChild(btn);
481
+ }
482
+ }
483
+ })();
484
+
485
+ // ---- Live polling (soft-refresh) ----
486
+ // When DATA.liveEndpoint is set, polls the server for new events/decisions
487
+ // and incrementally appends them to the DOM without a hard refresh.
488
+ // All rendered strings pass through esc() to prevent injection.
489
+ (function() {
490
+ if (!DATA.liveEndpoint) return;
491
+
492
+ var liveBadge = document.getElementById('live-badge');
493
+ liveBadge.style.display = 'inline-block';
494
+
495
+ var POLL_MS = 3000;
496
+ var lastTimestamp = DATA.events.length > 0
497
+ ? DATA.events[DATA.events.length - 1].timestamp
498
+ : (DATA.session.startEvent ? DATA.session.startEvent.timestamp : 0);
499
+ var lastDecisionTimestamp = DATA.decisions.length > 0
500
+ ? DATA.decisions[DATA.decisions.length - 1].timestamp
501
+ : 0;
502
+
503
+ // References to containers for incremental appends
504
+ var timelineContainer = document.getElementById('action-timeline');
505
+ var eventStreamContainer = document.getElementById('event-stream');
506
+ var eventCountEl = document.getElementById('event-count');
507
+ var violationsContainer = document.getElementById('violations-list');
508
+ var violationsSection = document.getElementById('violations-section');
509
+
510
+ // Track whether the raw stream details panel is open
511
+ var eventStreamDetails = eventStreamContainer ? eventStreamContainer.parentElement : null;
512
+ var streamIsOpen = eventStreamDetails && eventStreamDetails.open;
513
+ if (eventStreamDetails) {
514
+ eventStreamDetails.addEventListener('toggle', function() {
515
+ streamIsOpen = this.open;
516
+ });
517
+ }
518
+
519
+ function updateSummaryCards(s) {
520
+ var cards = document.querySelectorAll('.summary-grid .card-sm');
521
+ if (cards.length >= 6) {
522
+ cards[0].querySelector('div').textContent = String(s.totalActions);
523
+ cards[1].querySelector('div').textContent = String(s.allowed);
524
+ cards[2].querySelector('div').textContent = String(s.denied);
525
+ cards[3].querySelector('div').textContent = String(s.invariantViolations);
526
+ cards[4].querySelector('div').textContent = String(s.escalations);
527
+ var maxEl = cards[5].querySelector('div');
528
+ maxEl.textContent = s.maxEscalationLevel;
529
+ maxEl.style.color = s.maxEscalationLevel === 'NORMAL' ? '#22C55E'
530
+ : s.maxEscalationLevel === 'ELEVATED' ? '#F59E0B' : '#EF4444';
531
+ }
532
+ }
533
+
534
+ function appendTimelineAction(action) {
535
+ var dotClass = !action.allowed ? 'dot-denied' : action.escalationEvent ? 'dot-escalated' : 'dot-allowed';
536
+ var statusText = !action.allowed ? 'DENIED'
537
+ : action.executed ? (action.succeeded ? 'EXECUTED' : 'FAILED') : 'ALLOWED';
538
+ var statusClass = !action.allowed ? 'badge-denied'
539
+ : action.executed ? (action.succeeded ? 'badge-allowed' : 'badge-failed') : 'badge-executed';
540
+ var ts = action.requestedEvent ? relTime(action.requestedEvent.timestamp) : '';
541
+
542
+ // Add timeline-line to previous last entry
543
+ var entries = timelineContainer.children;
544
+ if (entries.length > 0) {
545
+ var prev = entries[entries.length - 1];
546
+ if (!prev.querySelector('.timeline-line')) {
547
+ var line = document.createElement('div');
548
+ line.className = 'timeline-line';
549
+ prev.insertBefore(line, prev.firstChild);
550
+ }
551
+ }
552
+
553
+ var entryDiv = document.createElement('div');
554
+ entryDiv.style.cssText = 'position:relative; padding-left:2rem; padding-bottom:1rem;';
555
+
556
+ var dot = document.createElement('div');
557
+ dot.className = 'timeline-dot ' + dotClass;
558
+ dot.style.cssText = 'position:absolute; left:0; top:4px;';
559
+ entryDiv.appendChild(dot);
560
+
561
+ var details = document.createElement('details');
562
+ var summary = document.createElement('summary');
563
+ summary.style.cssText = 'display:flex; align-items:center; gap:0.75rem; flex-wrap:wrap;';
564
+
565
+ var tsSpan = document.createElement('span');
566
+ tsSpan.className = 'font-mono';
567
+ tsSpan.style.cssText = 'font-size:0.75rem; color:#94A3B8; min-width:4rem;';
568
+ tsSpan.textContent = ts;
569
+ summary.appendChild(tsSpan);
570
+
571
+ var typeSpan = document.createElement('span');
572
+ typeSpan.style.fontWeight = '500';
573
+ typeSpan.textContent = action.actionType;
574
+ summary.appendChild(typeSpan);
575
+
576
+ var targetSpan = document.createElement('span');
577
+ targetSpan.style.cssText = 'color:#94A3B8; font-size:0.875rem; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; max-width:400px;';
578
+ targetSpan.textContent = action.target || '';
579
+ summary.appendChild(targetSpan);
580
+
581
+ var badge = document.createElement('span');
582
+ badge.className = 'badge ' + statusClass;
583
+ badge.textContent = statusText;
584
+ summary.appendChild(badge);
585
+
586
+ details.appendChild(summary);
587
+ entryDiv.appendChild(details);
588
+ timelineContainer.appendChild(entryDiv);
589
+ }
590
+
591
+ function appendEventRow(ev, idx) {
592
+ var kindColor = ev.kind.includes('Denied') || ev.kind.includes('Violation') || ev.kind.includes('Failed')
593
+ ? '#EF4444'
594
+ : ev.kind.includes('Allowed') || ev.kind.includes('Executed')
595
+ ? '#22C55E'
596
+ : ev.kind.includes('Escalat')
597
+ ? '#F59E0B'
598
+ : '#94A3B8';
599
+
600
+ var row = document.createElement('details');
601
+ row.className = 'event-row';
602
+ row.style.cssText = 'padding:0.375rem 0.5rem; border-bottom:1px solid #1E293B; font-size:0.8125rem; border-radius:0.25rem;';
603
+
604
+ var summary = document.createElement('summary');
605
+ summary.className = 'font-mono';
606
+ summary.style.cssText = 'display:flex; gap:1rem; align-items:center;';
607
+
608
+ var numSpan = document.createElement('span');
609
+ numSpan.style.cssText = 'color:#94A3B8; min-width:4rem;';
610
+ numSpan.textContent = String(idx + 1);
611
+ summary.appendChild(numSpan);
612
+
613
+ var kindSpan = document.createElement('span');
614
+ kindSpan.style.cssText = 'color:' + kindColor + '; font-weight:500; min-width:14rem;';
615
+ kindSpan.textContent = ev.kind;
616
+ summary.appendChild(kindSpan);
617
+
618
+ var timeSpan = document.createElement('span');
619
+ timeSpan.style.cssText = 'color:#94A3B8; font-size:0.75rem;';
620
+ timeSpan.textContent = new Date(ev.timestamp).toISOString().slice(11, 23);
621
+ summary.appendChild(timeSpan);
622
+
623
+ row.appendChild(summary);
624
+
625
+ var pre = document.createElement('pre');
626
+ pre.className = 'font-mono';
627
+ pre.style.cssText = 'margin:0.5rem 0 0.5rem 5rem; padding:0.75rem; background:#0F172A; border-radius:0.375rem; font-size:0.75rem; overflow-x:auto; white-space:pre-wrap; word-break:break-all;';
628
+ pre.textContent = prettyJson(ev);
629
+ row.appendChild(pre);
630
+
631
+ var loadMoreBtn = eventStreamContainer.querySelector('.load-more-btn');
632
+ if (loadMoreBtn) {
633
+ eventStreamContainer.insertBefore(row, loadMoreBtn);
634
+ } else {
635
+ eventStreamContainer.appendChild(row);
636
+ }
637
+ }
638
+
639
+ function appendViolation(v) {
640
+ violationsSection.style.display = '';
641
+ var div = document.createElement('div');
642
+ div.className = 'card-sm';
643
+ div.style.marginBottom = '0.5rem';
644
+
645
+ var header = document.createElement('div');
646
+ header.style.cssText = 'display:flex; align-items:center; gap:0.5rem; margin-bottom:0.25rem;';
647
+ var nameSpan = document.createElement('span');
648
+ nameSpan.style.cssText = 'color:#EF4444; font-weight:600;';
649
+ nameSpan.textContent = '\u26A0 ' + (v.invariant || 'Unknown');
650
+ header.appendChild(nameSpan);
651
+ if (v.severity != null) {
652
+ var sevBadge = document.createElement('span');
653
+ sevBadge.className = 'badge badge-denied';
654
+ sevBadge.textContent = 'severity ' + String(v.severity);
655
+ header.appendChild(sevBadge);
656
+ }
657
+ div.appendChild(header);
658
+
659
+ var detail = document.createElement('div');
660
+ detail.style.cssText = 'font-size:0.8125rem; color:#94A3B8;';
661
+ var parts = [];
662
+ if (v.expected) parts.push('Expected: ' + String(v.expected));
663
+ if (v.actual) parts.push('Actual: ' + String(v.actual));
664
+ detail.textContent = parts.join(' \u00B7 ');
665
+ div.appendChild(detail);
666
+
667
+ violationsContainer.appendChild(div);
668
+ }
669
+
670
+ function poll() {
671
+ fetch(DATA.liveEndpoint + '/api/poll?afterEvent=' + lastTimestamp + '&afterDecision=' + lastDecisionTimestamp)
672
+ .then(function(res) { return res.json(); })
673
+ .then(function(data) {
674
+ if (!data) return;
675
+
676
+ // Update summary cards
677
+ if (data.summary) {
678
+ updateSummaryCards(data.summary);
679
+ }
680
+
681
+ // Append new events
682
+ var newEvents = data.events || [];
683
+ if (newEvents.length > 0) {
684
+ var baseIdx = DATA.events.length;
685
+ for (var i = 0; i < newEvents.length; i++) {
686
+ var ev = newEvents[i];
687
+ DATA.events.push(ev);
688
+
689
+ // Append to raw event stream if it has been opened
690
+ if (streamIsOpen) {
691
+ appendEventRow(ev, baseIdx + i);
692
+ }
693
+
694
+ if (ev.kind === 'InvariantViolation') {
695
+ appendViolation(ev);
696
+ }
697
+ }
698
+ lastTimestamp = newEvents[newEvents.length - 1].timestamp;
699
+ eventCountEl.textContent = '(' + DATA.events.length + ' events)';
700
+ }
701
+
702
+ // Append new actions to timeline
703
+ var newActions = data.actions || [];
704
+ for (var j = 0; j < newActions.length; j++) {
705
+ DATA.session.actions.push(newActions[j]);
706
+ appendTimelineAction(newActions[j]);
707
+ }
708
+
709
+ // Update decisions
710
+ var newDecisions = data.decisions || [];
711
+ if (newDecisions.length > 0) {
712
+ for (var k = 0; k < newDecisions.length; k++) {
713
+ DATA.decisions.push(newDecisions[k]);
714
+ }
715
+ lastDecisionTimestamp = newDecisions[newDecisions.length - 1].timestamp;
716
+ }
717
+
718
+ liveBadge.style.display = 'inline-block';
719
+ liveBadge.style.background = 'rgba(34,197,94,0.15)';
720
+ liveBadge.style.color = '#22C55E';
721
+ liveBadge.textContent = 'LIVE';
722
+ })
723
+ .catch(function() {
724
+ liveBadge.style.background = 'rgba(245,158,11,0.15)';
725
+ liveBadge.style.color = '#F59E0B';
726
+ liveBadge.textContent = 'RECONNECTING';
727
+ });
728
+ }
729
+
730
+ setInterval(poll, POLL_MS);
731
+ setTimeout(poll, 500);
732
+ })();
733
+ <\/script>
734
+ </body>
735
+ </html>`;
736
+ }
737
+ //# sourceMappingURL=session-viewer-html.js.map