@agenticmail/enterprise 0.5.327 → 0.5.329

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 (888) hide show
  1. package/dist/agent-tools-F3CYENMK.js +13949 -0
  2. package/dist/browser-tool-P57PLVW2.js +4002 -0
  3. package/dist/chunk-3RI3AIJN.js +1519 -0
  4. package/dist/chunk-AD4DFKHR.js +4928 -0
  5. package/dist/chunk-UQXPVWXG.js +5101 -0
  6. package/dist/cli-agent-K6UFZRXC.js +2473 -0
  7. package/dist/cli-serve-4MT7RDEL.js +260 -0
  8. package/dist/cli.js +3 -3
  9. package/dist/dashboard/app.js +1 -1
  10. package/dist/dashboard/components/transport-encryption.js +0 -62
  11. package/dist/dashboard/pages/agent-detail/index.js +5 -2
  12. package/dist/dashboard/pages/agent-detail/manager.js +1 -1
  13. package/dist/dashboard/pages/agent-detail/overview.js +4 -2
  14. package/dist/dashboard/pages/agent-detail/tool-security.js +1 -1
  15. package/dist/dashboard/pages/domain-status.js +3 -6
  16. package/dist/dashboard/pages/memory-transfer.js +1 -1
  17. package/dist/dashboard/pages/messages.js +0 -1
  18. package/dist/dashboard/pages/roles.js +0 -2
  19. package/dist/dashboard/pages/workforce.js +0 -1
  20. package/dist/index.js +3 -3
  21. package/dist/runtime-L5ADJORP.js +45 -0
  22. package/dist/server-KSN56EZQ.js +28 -0
  23. package/dist/setup-UUNBBOQH.js +20 -0
  24. package/logs/cloudflared-error.log +42 -0
  25. package/logs/enterprise-out.log +6 -0
  26. package/package.json +1 -1
  27. package/src/admin/page-registry.ts +0 -290
  28. package/src/admin/routes.ts +0 -2968
  29. package/src/agent-tools/common.ts +0 -260
  30. package/src/agent-tools/index.ts +0 -542
  31. package/src/agent-tools/merge.ts +0 -62
  32. package/src/agent-tools/middleware.ts +0 -436
  33. package/src/agent-tools/schema/typebox.ts +0 -25
  34. package/src/agent-tools/security.ts +0 -352
  35. package/src/agent-tools/tool-resolver.ts +0 -1018
  36. package/src/agent-tools/tools/agenticmail.ts +0 -1017
  37. package/src/agent-tools/tools/bash.ts +0 -179
  38. package/src/agent-tools/tools/browser-tool.schema.ts +0 -112
  39. package/src/agent-tools/tools/browser-tool.ts +0 -388
  40. package/src/agent-tools/tools/browser.ts +0 -764
  41. package/src/agent-tools/tools/edit.ts +0 -100
  42. package/src/agent-tools/tools/enterprise-code-sandbox.ts +0 -395
  43. package/src/agent-tools/tools/enterprise-database.ts +0 -377
  44. package/src/agent-tools/tools/enterprise-diff.ts +0 -580
  45. package/src/agent-tools/tools/enterprise-documents.ts +0 -896
  46. package/src/agent-tools/tools/enterprise-http.ts +0 -485
  47. package/src/agent-tools/tools/enterprise-security-scan.ts +0 -528
  48. package/src/agent-tools/tools/enterprise-spreadsheet.ts +0 -825
  49. package/src/agent-tools/tools/glob.ts +0 -129
  50. package/src/agent-tools/tools/google/calendar.ts +0 -230
  51. package/src/agent-tools/tools/google/chat.ts +0 -725
  52. package/src/agent-tools/tools/google/contacts.ts +0 -209
  53. package/src/agent-tools/tools/google/docs.ts +0 -162
  54. package/src/agent-tools/tools/google/drive.ts +0 -392
  55. package/src/agent-tools/tools/google/forms.ts +0 -367
  56. package/src/agent-tools/tools/google/gmail.ts +0 -897
  57. package/src/agent-tools/tools/google/index.ts +0 -86
  58. package/src/agent-tools/tools/google/maps.ts +0 -543
  59. package/src/agent-tools/tools/google/meeting-voice.ts +0 -885
  60. package/src/agent-tools/tools/google/meetings.ts +0 -1094
  61. package/src/agent-tools/tools/google/sheets.ts +0 -215
  62. package/src/agent-tools/tools/google/slides.ts +0 -559
  63. package/src/agent-tools/tools/google/tasks.ts +0 -200
  64. package/src/agent-tools/tools/grep.ts +0 -178
  65. package/src/agent-tools/tools/integrations/_factory.ts +0 -102
  66. package/src/agent-tools/tools/integrations/activecampaign.ts +0 -14
  67. package/src/agent-tools/tools/integrations/adobe-sign.ts +0 -14
  68. package/src/agent-tools/tools/integrations/adp.ts +0 -14
  69. package/src/agent-tools/tools/integrations/airtable.ts +0 -14
  70. package/src/agent-tools/tools/integrations/apollo.ts +0 -14
  71. package/src/agent-tools/tools/integrations/asana.ts +0 -14
  72. package/src/agent-tools/tools/integrations/auth0.ts +0 -14
  73. package/src/agent-tools/tools/integrations/aws.ts +0 -14
  74. package/src/agent-tools/tools/integrations/azure-devops.ts +0 -14
  75. package/src/agent-tools/tools/integrations/bamboohr.ts +0 -14
  76. package/src/agent-tools/tools/integrations/basecamp.ts +0 -14
  77. package/src/agent-tools/tools/integrations/bigcommerce.ts +0 -14
  78. package/src/agent-tools/tools/integrations/bitbucket.ts +0 -14
  79. package/src/agent-tools/tools/integrations/box.ts +0 -14
  80. package/src/agent-tools/tools/integrations/brex.ts +0 -14
  81. package/src/agent-tools/tools/integrations/buffer.ts +0 -14
  82. package/src/agent-tools/tools/integrations/calendly.ts +0 -14
  83. package/src/agent-tools/tools/integrations/canva.ts +0 -14
  84. package/src/agent-tools/tools/integrations/chargebee.ts +0 -14
  85. package/src/agent-tools/tools/integrations/circleci.ts +0 -14
  86. package/src/agent-tools/tools/integrations/clickup.ts +0 -14
  87. package/src/agent-tools/tools/integrations/close.ts +0 -14
  88. package/src/agent-tools/tools/integrations/cloudflare.ts +0 -14
  89. package/src/agent-tools/tools/integrations/confluence.ts +0 -14
  90. package/src/agent-tools/tools/integrations/contentful.ts +0 -14
  91. package/src/agent-tools/tools/integrations/copper.ts +0 -14
  92. package/src/agent-tools/tools/integrations/crisp.ts +0 -14
  93. package/src/agent-tools/tools/integrations/crowdstrike.ts +0 -14
  94. package/src/agent-tools/tools/integrations/datadog.ts +0 -14
  95. package/src/agent-tools/tools/integrations/digitalocean.ts +0 -14
  96. package/src/agent-tools/tools/integrations/discord.ts +0 -14
  97. package/src/agent-tools/tools/integrations/docker.ts +0 -14
  98. package/src/agent-tools/tools/integrations/docusign.ts +0 -14
  99. package/src/agent-tools/tools/integrations/drift.ts +0 -14
  100. package/src/agent-tools/tools/integrations/dropbox.ts +0 -14
  101. package/src/agent-tools/tools/integrations/figma.ts +0 -14
  102. package/src/agent-tools/tools/integrations/firebase.ts +0 -14
  103. package/src/agent-tools/tools/integrations/flyio.ts +0 -14
  104. package/src/agent-tools/tools/integrations/freshbooks.ts +0 -14
  105. package/src/agent-tools/tools/integrations/freshdesk.ts +0 -14
  106. package/src/agent-tools/tools/integrations/freshsales.ts +0 -14
  107. package/src/agent-tools/tools/integrations/freshservice.ts +0 -14
  108. package/src/agent-tools/tools/integrations/front.ts +0 -14
  109. package/src/agent-tools/tools/integrations/github-actions.ts +0 -14
  110. package/src/agent-tools/tools/integrations/github.ts +0 -14
  111. package/src/agent-tools/tools/integrations/gitlab.ts +0 -14
  112. package/src/agent-tools/tools/integrations/gong.ts +0 -14
  113. package/src/agent-tools/tools/integrations/google-ads.ts +0 -14
  114. package/src/agent-tools/tools/integrations/google-analytics.ts +0 -14
  115. package/src/agent-tools/tools/integrations/google-cloud.ts +0 -14
  116. package/src/agent-tools/tools/integrations/gotomeeting.ts +0 -14
  117. package/src/agent-tools/tools/integrations/grafana.ts +0 -14
  118. package/src/agent-tools/tools/integrations/greenhouse.ts +0 -14
  119. package/src/agent-tools/tools/integrations/gusto.ts +0 -14
  120. package/src/agent-tools/tools/integrations/hashicorp-vault.ts +0 -14
  121. package/src/agent-tools/tools/integrations/heroku.ts +0 -14
  122. package/src/agent-tools/tools/integrations/hibob.ts +0 -14
  123. package/src/agent-tools/tools/integrations/hootsuite.ts +0 -14
  124. package/src/agent-tools/tools/integrations/hubspot.ts +0 -14
  125. package/src/agent-tools/tools/integrations/huggingface.ts +0 -14
  126. package/src/agent-tools/tools/integrations/index.ts +0 -474
  127. package/src/agent-tools/tools/integrations/intercom.ts +0 -14
  128. package/src/agent-tools/tools/integrations/jira.ts +0 -14
  129. package/src/agent-tools/tools/integrations/klaviyo.ts +0 -14
  130. package/src/agent-tools/tools/integrations/kubernetes.ts +0 -14
  131. package/src/agent-tools/tools/integrations/lattice.ts +0 -14
  132. package/src/agent-tools/tools/integrations/launchdarkly.ts +0 -14
  133. package/src/agent-tools/tools/integrations/lever.ts +0 -14
  134. package/src/agent-tools/tools/integrations/linear.ts +0 -14
  135. package/src/agent-tools/tools/integrations/linkedin.ts +0 -14
  136. package/src/agent-tools/tools/integrations/livechat.ts +0 -14
  137. package/src/agent-tools/tools/integrations/loom.ts +0 -14
  138. package/src/agent-tools/tools/integrations/mailchimp.ts +0 -14
  139. package/src/agent-tools/tools/integrations/mailgun.ts +0 -14
  140. package/src/agent-tools/tools/integrations/miro.ts +0 -14
  141. package/src/agent-tools/tools/integrations/mixpanel.ts +0 -14
  142. package/src/agent-tools/tools/integrations/monday.ts +0 -14
  143. package/src/agent-tools/tools/integrations/mongodb-atlas.ts +0 -14
  144. package/src/agent-tools/tools/integrations/neon.ts +0 -14
  145. package/src/agent-tools/tools/integrations/netlify.ts +0 -14
  146. package/src/agent-tools/tools/integrations/netsuite.ts +0 -14
  147. package/src/agent-tools/tools/integrations/newrelic.ts +0 -14
  148. package/src/agent-tools/tools/integrations/notion.ts +0 -14
  149. package/src/agent-tools/tools/integrations/okta.ts +0 -14
  150. package/src/agent-tools/tools/integrations/openai.ts +0 -14
  151. package/src/agent-tools/tools/integrations/opsgenie.ts +0 -14
  152. package/src/agent-tools/tools/integrations/outreach.ts +0 -14
  153. package/src/agent-tools/tools/integrations/paddle.ts +0 -14
  154. package/src/agent-tools/tools/integrations/pagerduty.ts +0 -14
  155. package/src/agent-tools/tools/integrations/pandadoc.ts +0 -14
  156. package/src/agent-tools/tools/integrations/paypal.ts +0 -14
  157. package/src/agent-tools/tools/integrations/personio.ts +0 -14
  158. package/src/agent-tools/tools/integrations/pinecone.ts +0 -14
  159. package/src/agent-tools/tools/integrations/pipedrive.ts +0 -14
  160. package/src/agent-tools/tools/integrations/plaid.ts +0 -14
  161. package/src/agent-tools/tools/integrations/postmark.ts +0 -14
  162. package/src/agent-tools/tools/integrations/power-automate.ts +0 -14
  163. package/src/agent-tools/tools/integrations/quickbooks.ts +0 -14
  164. package/src/agent-tools/tools/integrations/recurly.ts +0 -14
  165. package/src/agent-tools/tools/integrations/reddit.ts +0 -14
  166. package/src/agent-tools/tools/integrations/render.ts +0 -14
  167. package/src/agent-tools/tools/integrations/ringcentral.ts +0 -14
  168. package/src/agent-tools/tools/integrations/rippling.ts +0 -14
  169. package/src/agent-tools/tools/integrations/salesforce.ts +0 -14
  170. package/src/agent-tools/tools/integrations/salesloft.ts +0 -14
  171. package/src/agent-tools/tools/integrations/sanity.ts +0 -14
  172. package/src/agent-tools/tools/integrations/sap.ts +0 -14
  173. package/src/agent-tools/tools/integrations/segment.ts +0 -14
  174. package/src/agent-tools/tools/integrations/sendgrid.ts +0 -14
  175. package/src/agent-tools/tools/integrations/sentry.ts +0 -14
  176. package/src/agent-tools/tools/integrations/servicenow.ts +0 -14
  177. package/src/agent-tools/tools/integrations/shopify.ts +0 -14
  178. package/src/agent-tools/tools/integrations/shortcut.ts +0 -14
  179. package/src/agent-tools/tools/integrations/slack.ts +0 -14
  180. package/src/agent-tools/tools/integrations/smartsheet.ts +0 -14
  181. package/src/agent-tools/tools/integrations/snowflake.ts +0 -14
  182. package/src/agent-tools/tools/integrations/snyk.ts +0 -14
  183. package/src/agent-tools/tools/integrations/splunk.ts +0 -14
  184. package/src/agent-tools/tools/integrations/square.ts +0 -14
  185. package/src/agent-tools/tools/integrations/statuspage.ts +0 -14
  186. package/src/agent-tools/tools/integrations/stripe.ts +0 -14
  187. package/src/agent-tools/tools/integrations/supabase.ts +0 -14
  188. package/src/agent-tools/tools/integrations/teamwork.ts +0 -14
  189. package/src/agent-tools/tools/integrations/telegram.ts +0 -14
  190. package/src/agent-tools/tools/integrations/terraform.ts +0 -14
  191. package/src/agent-tools/tools/integrations/todoist.ts +0 -14
  192. package/src/agent-tools/tools/integrations/trello.ts +0 -14
  193. package/src/agent-tools/tools/integrations/twilio.ts +0 -14
  194. package/src/agent-tools/tools/integrations/twitter.ts +0 -14
  195. package/src/agent-tools/tools/integrations/vercel.ts +0 -14
  196. package/src/agent-tools/tools/integrations/weaviate.ts +0 -14
  197. package/src/agent-tools/tools/integrations/webex.ts +0 -14
  198. package/src/agent-tools/tools/integrations/webflow.ts +0 -14
  199. package/src/agent-tools/tools/integrations/whatsapp.ts +0 -14
  200. package/src/agent-tools/tools/integrations/whereby.ts +0 -14
  201. package/src/agent-tools/tools/integrations/woocommerce.ts +0 -14
  202. package/src/agent-tools/tools/integrations/wordpress.ts +0 -14
  203. package/src/agent-tools/tools/integrations/workday.ts +0 -14
  204. package/src/agent-tools/tools/integrations/wrike.ts +0 -14
  205. package/src/agent-tools/tools/integrations/xero.ts +0 -14
  206. package/src/agent-tools/tools/integrations/youtube.ts +0 -14
  207. package/src/agent-tools/tools/integrations/zendesk.ts +0 -14
  208. package/src/agent-tools/tools/integrations/zoho-crm.ts +0 -14
  209. package/src/agent-tools/tools/integrations/zoom.ts +0 -14
  210. package/src/agent-tools/tools/integrations/zuora.ts +0 -14
  211. package/src/agent-tools/tools/knowledge-search.ts +0 -318
  212. package/src/agent-tools/tools/local/coding.ts +0 -626
  213. package/src/agent-tools/tools/local/dependency-manager.ts +0 -647
  214. package/src/agent-tools/tools/local/file-edit.ts +0 -31
  215. package/src/agent-tools/tools/local/file-list.ts +0 -39
  216. package/src/agent-tools/tools/local/file-ops.ts +0 -48
  217. package/src/agent-tools/tools/local/file-read.ts +0 -39
  218. package/src/agent-tools/tools/local/file-search.ts +0 -46
  219. package/src/agent-tools/tools/local/file-write.ts +0 -28
  220. package/src/agent-tools/tools/local/filesystem.ts +0 -5
  221. package/src/agent-tools/tools/local/index.ts +0 -55
  222. package/src/agent-tools/tools/local/resolve-path.ts +0 -18
  223. package/src/agent-tools/tools/local/shell.ts +0 -277
  224. package/src/agent-tools/tools/local/system-info.ts +0 -29
  225. package/src/agent-tools/tools/management.ts +0 -425
  226. package/src/agent-tools/tools/mcp-bridge.ts +0 -142
  227. package/src/agent-tools/tools/mcp-server-tools.ts +0 -91
  228. package/src/agent-tools/tools/meeting-lifecycle.ts +0 -438
  229. package/src/agent-tools/tools/memory.ts +0 -509
  230. package/src/agent-tools/tools/messaging/index.ts +0 -6
  231. package/src/agent-tools/tools/messaging/telegram.ts +0 -167
  232. package/src/agent-tools/tools/messaging/whatsapp.ts +0 -651
  233. package/src/agent-tools/tools/microsoft/contacts.ts +0 -176
  234. package/src/agent-tools/tools/microsoft/excel-vba.ts +0 -331
  235. package/src/agent-tools/tools/microsoft/excel.ts +0 -261
  236. package/src/agent-tools/tools/microsoft/graph-api.ts +0 -161
  237. package/src/agent-tools/tools/microsoft/index.ts +0 -95
  238. package/src/agent-tools/tools/microsoft/onedrive.ts +0 -429
  239. package/src/agent-tools/tools/microsoft/onenote.ts +0 -186
  240. package/src/agent-tools/tools/microsoft/outlook-calendar.ts +0 -286
  241. package/src/agent-tools/tools/microsoft/outlook-mail.ts +0 -723
  242. package/src/agent-tools/tools/microsoft/planner.ts +0 -200
  243. package/src/agent-tools/tools/microsoft/powerbi.ts +0 -266
  244. package/src/agent-tools/tools/microsoft/powerpoint.ts +0 -186
  245. package/src/agent-tools/tools/microsoft/sharepoint.ts +0 -328
  246. package/src/agent-tools/tools/microsoft/teams.ts +0 -463
  247. package/src/agent-tools/tools/microsoft/todo.ts +0 -181
  248. package/src/agent-tools/tools/oauth-token-provider.ts +0 -101
  249. package/src/agent-tools/tools/read.ts +0 -160
  250. package/src/agent-tools/tools/visual-memory/capture.ts +0 -217
  251. package/src/agent-tools/tools/visual-memory/diff.ts +0 -283
  252. package/src/agent-tools/tools/visual-memory/index.ts +0 -698
  253. package/src/agent-tools/tools/visual-memory/phash.ts +0 -120
  254. package/src/agent-tools/tools/visual-memory/similarity.ts +0 -354
  255. package/src/agent-tools/tools/visual-memory/storage.ts +0 -534
  256. package/src/agent-tools/tools/visual-memory/types.ts +0 -100
  257. package/src/agent-tools/tools/web-fetch-utils.ts +0 -202
  258. package/src/agent-tools/tools/web-fetch.ts +0 -464
  259. package/src/agent-tools/tools/web-search.ts +0 -480
  260. package/src/agent-tools/tools/web-shared.ts +0 -232
  261. package/src/agent-tools/tools/write.ts +0 -68
  262. package/src/agent-tools/types.ts +0 -214
  263. package/src/agenticmail/index.ts +0 -34
  264. package/src/agenticmail/manager.ts +0 -253
  265. package/src/agenticmail/providers/google.ts +0 -391
  266. package/src/agenticmail/providers/imap.ts +0 -454
  267. package/src/agenticmail/providers/index.ts +0 -28
  268. package/src/agenticmail/providers/microsoft.ts +0 -260
  269. package/src/agenticmail/types.ts +0 -173
  270. package/src/auth/routes.ts +0 -1589
  271. package/src/browser/bridge-auth-registry.ts +0 -34
  272. package/src/browser/bridge-server.ts +0 -93
  273. package/src/browser/cdp.helpers.ts +0 -180
  274. package/src/browser/cdp.ts +0 -466
  275. package/src/browser/chrome.executables.ts +0 -625
  276. package/src/browser/chrome.profile-decoration.ts +0 -198
  277. package/src/browser/chrome.ts +0 -349
  278. package/src/browser/client-actions-core.ts +0 -259
  279. package/src/browser/client-actions-observe.ts +0 -184
  280. package/src/browser/client-actions-state.ts +0 -284
  281. package/src/browser/client-actions-types.ts +0 -16
  282. package/src/browser/client-actions-url.ts +0 -11
  283. package/src/browser/client-actions.ts +0 -4
  284. package/src/browser/client-fetch.ts +0 -253
  285. package/src/browser/client.ts +0 -337
  286. package/src/browser/config.ts +0 -301
  287. package/src/browser/constants.ts +0 -8
  288. package/src/browser/control-auth.ts +0 -94
  289. package/src/browser/control-service.ts +0 -81
  290. package/src/browser/csrf.ts +0 -87
  291. package/src/browser/enterprise-compat.ts +0 -562
  292. package/src/browser/extension-relay.ts +0 -834
  293. package/src/browser/http-auth.ts +0 -63
  294. package/src/browser/navigation-guard.ts +0 -50
  295. package/src/browser/paths.ts +0 -49
  296. package/src/browser/playwright.d.ts +0 -12
  297. package/src/browser/profiles-service.ts +0 -187
  298. package/src/browser/profiles.ts +0 -114
  299. package/src/browser/proxy-files.ts +0 -41
  300. package/src/browser/pw-ai-module.ts +0 -52
  301. package/src/browser/pw-ai-state.ts +0 -9
  302. package/src/browser/pw-ai.ts +0 -65
  303. package/src/browser/pw-role-snapshot.ts +0 -434
  304. package/src/browser/pw-session.ts +0 -810
  305. package/src/browser/pw-tools-core.activity.ts +0 -68
  306. package/src/browser/pw-tools-core.downloads.ts +0 -281
  307. package/src/browser/pw-tools-core.interactions.ts +0 -646
  308. package/src/browser/pw-tools-core.responses.ts +0 -124
  309. package/src/browser/pw-tools-core.shared.ts +0 -70
  310. package/src/browser/pw-tools-core.snapshot.ts +0 -213
  311. package/src/browser/pw-tools-core.state.ts +0 -209
  312. package/src/browser/pw-tools-core.storage.ts +0 -128
  313. package/src/browser/pw-tools-core.trace.ts +0 -37
  314. package/src/browser/pw-tools-core.ts +0 -8
  315. package/src/browser/resolved-config-refresh.ts +0 -59
  316. package/src/browser/routes/agent.act.shared.ts +0 -52
  317. package/src/browser/routes/agent.act.ts +0 -575
  318. package/src/browser/routes/agent.debug.ts +0 -149
  319. package/src/browser/routes/agent.shared.ts +0 -143
  320. package/src/browser/routes/agent.snapshot.ts +0 -333
  321. package/src/browser/routes/agent.storage.ts +0 -451
  322. package/src/browser/routes/agent.ts +0 -13
  323. package/src/browser/routes/basic.ts +0 -202
  324. package/src/browser/routes/dispatcher.ts +0 -126
  325. package/src/browser/routes/index.ts +0 -11
  326. package/src/browser/routes/path-output.ts +0 -1
  327. package/src/browser/routes/tabs.ts +0 -217
  328. package/src/browser/routes/types.ts +0 -26
  329. package/src/browser/routes/utils.ts +0 -73
  330. package/src/browser/screenshot.ts +0 -54
  331. package/src/browser/server-context.ts +0 -688
  332. package/src/browser/server-context.types.ts +0 -65
  333. package/src/browser/server-lifecycle.ts +0 -48
  334. package/src/browser/server-middleware.ts +0 -37
  335. package/src/browser/server.ts +0 -110
  336. package/src/browser/target-id.ts +0 -30
  337. package/src/browser/trash.ts +0 -21
  338. package/src/cli-agent.ts +0 -2452
  339. package/src/cli-reset-password.ts +0 -138
  340. package/src/cli-serve.ts +0 -314
  341. package/src/cli.ts +0 -103
  342. package/src/dashboard/app.js +0 -579
  343. package/src/dashboard/assets/brand-logos.js +0 -350
  344. package/src/dashboard/assets/icons/emoji-icons.js +0 -893
  345. package/src/dashboard/assets/logo.png +0 -0
  346. package/src/dashboard/assets/provider-logos.js +0 -139
  347. package/src/dashboard/components/error-boundary.js +0 -21
  348. package/src/dashboard/components/help-button.js +0 -65
  349. package/src/dashboard/components/icons.js +0 -64
  350. package/src/dashboard/components/knowledge-link.js +0 -79
  351. package/src/dashboard/components/modal.js +0 -125
  352. package/src/dashboard/components/org-switcher.js +0 -156
  353. package/src/dashboard/components/persona-fields.js +0 -460
  354. package/src/dashboard/components/settings-help.js +0 -193
  355. package/src/dashboard/components/tag-input.js +0 -96
  356. package/src/dashboard/components/timezones.js +0 -352
  357. package/src/dashboard/components/transport-encryption.js +0 -288
  358. package/src/dashboard/components/utils.js +0 -205
  359. package/src/dashboard/data/countries.js +0 -255
  360. package/src/dashboard/docs/activity.html +0 -253
  361. package/src/dashboard/docs/agent-activity.html +0 -199
  362. package/src/dashboard/docs/agent-autonomy.html +0 -161
  363. package/src/dashboard/docs/agent-budget.html +0 -190
  364. package/src/dashboard/docs/agent-channels.html +0 -189
  365. package/src/dashboard/docs/agent-communication.html +0 -171
  366. package/src/dashboard/docs/agent-configuration.html +0 -194
  367. package/src/dashboard/docs/agent-deployment.html +0 -323
  368. package/src/dashboard/docs/agent-email.html +0 -184
  369. package/src/dashboard/docs/agent-guardrails.html +0 -206
  370. package/src/dashboard/docs/agent-manager.html +0 -226
  371. package/src/dashboard/docs/agent-memory.html +0 -215
  372. package/src/dashboard/docs/agent-overview.html +0 -226
  373. package/src/dashboard/docs/agent-permissions.html +0 -305
  374. package/src/dashboard/docs/agent-personal.html +0 -155
  375. package/src/dashboard/docs/agent-security.html +0 -188
  376. package/src/dashboard/docs/agent-skills.html +0 -224
  377. package/src/dashboard/docs/agent-tool-security.html +0 -205
  378. package/src/dashboard/docs/agent-tools.html +0 -238
  379. package/src/dashboard/docs/agent-whatsapp.html +0 -210
  380. package/src/dashboard/docs/agent-workforce.html +0 -199
  381. package/src/dashboard/docs/agents.html +0 -258
  382. package/src/dashboard/docs/approvals.html +0 -200
  383. package/src/dashboard/docs/audit.html +0 -206
  384. package/src/dashboard/docs/browser-providers.html +0 -313
  385. package/src/dashboard/docs/cluster.html +0 -285
  386. package/src/dashboard/docs/community-skills.html +0 -253
  387. package/src/dashboard/docs/compliance.html +0 -221
  388. package/src/dashboard/docs/dashboard.html +0 -84
  389. package/src/dashboard/docs/database-access.html +0 -322
  390. package/src/dashboard/docs/dlp.html +0 -268
  391. package/src/dashboard/docs/docs-style.css +0 -26
  392. package/src/dashboard/docs/domain-status.html +0 -294
  393. package/src/dashboard/docs/guardrails.html +0 -265
  394. package/src/dashboard/docs/journal.html +0 -197
  395. package/src/dashboard/docs/knowledge-contributions.html +0 -286
  396. package/src/dashboard/docs/knowledge.html +0 -268
  397. package/src/dashboard/docs/memory-transfer.html +0 -311
  398. package/src/dashboard/docs/messages.html +0 -217
  399. package/src/dashboard/docs/multi-tenant.html +0 -311
  400. package/src/dashboard/docs/org-chart.html +0 -239
  401. package/src/dashboard/docs/organizations.html +0 -182
  402. package/src/dashboard/docs/roles.html +0 -195
  403. package/src/dashboard/docs/settings-network.html +0 -321
  404. package/src/dashboard/docs/settings-security.html +0 -347
  405. package/src/dashboard/docs/settings-tool-security.html +0 -176
  406. package/src/dashboard/docs/settings.html +0 -280
  407. package/src/dashboard/docs/skill-connections.html +0 -270
  408. package/src/dashboard/docs/skills.html +0 -206
  409. package/src/dashboard/docs/task-pipeline.html +0 -261
  410. package/src/dashboard/docs/transport-encryption.html +0 -359
  411. package/src/dashboard/docs/users.html +0 -225
  412. package/src/dashboard/docs/vault.html +0 -260
  413. package/src/dashboard/docs/workforce.html +0 -245
  414. package/src/dashboard/index.html +0 -444
  415. package/src/dashboard/pages/activity.js +0 -379
  416. package/src/dashboard/pages/agent-detail/activity.js +0 -277
  417. package/src/dashboard/pages/agent-detail/autonomy.js +0 -244
  418. package/src/dashboard/pages/agent-detail/budget.js +0 -269
  419. package/src/dashboard/pages/agent-detail/channels.js +0 -494
  420. package/src/dashboard/pages/agent-detail/communication.js +0 -296
  421. package/src/dashboard/pages/agent-detail/configuration.js +0 -882
  422. package/src/dashboard/pages/agent-detail/deployment.js +0 -958
  423. package/src/dashboard/pages/agent-detail/email.js +0 -674
  424. package/src/dashboard/pages/agent-detail/guardrails.js +0 -521
  425. package/src/dashboard/pages/agent-detail/index.js +0 -261
  426. package/src/dashboard/pages/agent-detail/manager.js +0 -357
  427. package/src/dashboard/pages/agent-detail/meeting-browser.js +0 -933
  428. package/src/dashboard/pages/agent-detail/memory.js +0 -368
  429. package/src/dashboard/pages/agent-detail/overview.js +0 -844
  430. package/src/dashboard/pages/agent-detail/permissions.js +0 -1163
  431. package/src/dashboard/pages/agent-detail/personal-details.js +0 -404
  432. package/src/dashboard/pages/agent-detail/security.js +0 -409
  433. package/src/dashboard/pages/agent-detail/shared.js +0 -85
  434. package/src/dashboard/pages/agent-detail/skills-section.js +0 -183
  435. package/src/dashboard/pages/agent-detail/tool-security.js +0 -380
  436. package/src/dashboard/pages/agent-detail/tools.js +0 -322
  437. package/src/dashboard/pages/agent-detail/whatsapp.js +0 -824
  438. package/src/dashboard/pages/agent-detail/workforce.js +0 -683
  439. package/src/dashboard/pages/agents.js +0 -1242
  440. package/src/dashboard/pages/approvals.js +0 -100
  441. package/src/dashboard/pages/audit.js +0 -198
  442. package/src/dashboard/pages/cluster.js +0 -512
  443. package/src/dashboard/pages/community-skills.js +0 -1219
  444. package/src/dashboard/pages/compliance.js +0 -475
  445. package/src/dashboard/pages/dashboard.js +0 -180
  446. package/src/dashboard/pages/database-access.js +0 -812
  447. package/src/dashboard/pages/dlp.js +0 -293
  448. package/src/dashboard/pages/domain-status.js +0 -951
  449. package/src/dashboard/pages/guardrails.js +0 -1035
  450. package/src/dashboard/pages/journal.js +0 -172
  451. package/src/dashboard/pages/knowledge-contributions.js +0 -1682
  452. package/src/dashboard/pages/knowledge-import.js +0 -455
  453. package/src/dashboard/pages/knowledge.js +0 -582
  454. package/src/dashboard/pages/login.js +0 -1056
  455. package/src/dashboard/pages/memory-transfer.js +0 -631
  456. package/src/dashboard/pages/messages.js +0 -303
  457. package/src/dashboard/pages/org-chart.js +0 -349
  458. package/src/dashboard/pages/organizations.js +0 -1081
  459. package/src/dashboard/pages/roles.js +0 -780
  460. package/src/dashboard/pages/settings.js +0 -3790
  461. package/src/dashboard/pages/skill-connections.js +0 -982
  462. package/src/dashboard/pages/skills.js +0 -879
  463. package/src/dashboard/pages/task-pipeline.js +0 -684
  464. package/src/dashboard/pages/users.js +0 -867
  465. package/src/dashboard/pages/vault.js +0 -791
  466. package/src/dashboard/pages/workforce.js +0 -851
  467. package/src/dashboard/vendor/react-dom.development.js +0 -29924
  468. package/src/dashboard/vendor/react-dom.production.min.js +0 -267
  469. package/src/dashboard/vendor/react.development.js +0 -3343
  470. package/src/dashboard/vendor/react.production.min.js +0 -31
  471. package/src/database-access/agent-tools.ts +0 -193
  472. package/src/database-access/connection-manager.ts +0 -1341
  473. package/src/database-access/index.ts +0 -21
  474. package/src/database-access/query-sanitizer.ts +0 -220
  475. package/src/database-access/routes.ts +0 -226
  476. package/src/database-access/types.ts +0 -226
  477. package/src/db/adapter.ts +0 -510
  478. package/src/db/dynamodb.ts +0 -454
  479. package/src/db/factory.ts +0 -129
  480. package/src/db/mongodb.ts +0 -360
  481. package/src/db/mysql.ts +0 -531
  482. package/src/db/postgres.ts +0 -863
  483. package/src/db/proxy.ts +0 -39
  484. package/src/db/resolve-driver.ts +0 -29
  485. package/src/db/sql-schema.ts +0 -124
  486. package/src/db/sqlite.ts +0 -493
  487. package/src/db/turso.ts +0 -470
  488. package/src/deploy/fly.ts +0 -368
  489. package/src/deploy/managed.ts +0 -235
  490. package/src/domain-lock/cli-recover.ts +0 -591
  491. package/src/domain-lock/cli-verify.ts +0 -190
  492. package/src/domain-lock/index.ts +0 -220
  493. package/src/engine/activity-routes.ts +0 -154
  494. package/src/engine/activity.ts +0 -568
  495. package/src/engine/agent-autonomy.ts +0 -974
  496. package/src/engine/agent-config.ts +0 -646
  497. package/src/engine/agent-heartbeat.ts +0 -720
  498. package/src/engine/agent-hierarchy.ts +0 -1064
  499. package/src/engine/agent-memory.ts +0 -806
  500. package/src/engine/agent-notify.ts +0 -50
  501. package/src/engine/agent-routes.ts +0 -2583
  502. package/src/engine/agent-status.ts +0 -311
  503. package/src/engine/ambient-memory.ts +0 -401
  504. package/src/engine/approvals.ts +0 -615
  505. package/src/engine/assets/thinking-hum.mp3 +0 -0
  506. package/src/engine/catalog-routes.ts +0 -232
  507. package/src/engine/chat-poller.ts +0 -913
  508. package/src/engine/chat-webhook-routes.ts +0 -304
  509. package/src/engine/cli-build-skill.ts +0 -285
  510. package/src/engine/cli-submit-skill.ts +0 -200
  511. package/src/engine/cli-validate.ts +0 -188
  512. package/src/engine/cluster.ts +0 -278
  513. package/src/engine/communication-routes.ts +0 -139
  514. package/src/engine/communication.ts +0 -765
  515. package/src/engine/community-registry.ts +0 -1529
  516. package/src/engine/community-routes.ts +0 -260
  517. package/src/engine/compliance-routes.ts +0 -133
  518. package/src/engine/compliance.ts +0 -1679
  519. package/src/engine/config-bus.ts +0 -103
  520. package/src/engine/db-adapter.ts +0 -1156
  521. package/src/engine/db-schema.ts +0 -1945
  522. package/src/engine/deploy-schema-routes.ts +0 -176
  523. package/src/engine/deployer.ts +0 -957
  524. package/src/engine/dlp-routes.ts +0 -101
  525. package/src/engine/dlp.ts +0 -410
  526. package/src/engine/email-poller.ts +0 -855
  527. package/src/engine/emoji.ts +0 -106
  528. package/src/engine/guardrail-routes.ts +0 -125
  529. package/src/engine/guardrails.ts +0 -465
  530. package/src/engine/index.ts +0 -255
  531. package/src/engine/journal-routes.ts +0 -56
  532. package/src/engine/journal.ts +0 -249
  533. package/src/engine/knowledge-contribution-routes.ts +0 -633
  534. package/src/engine/knowledge-contribution.ts +0 -1386
  535. package/src/engine/knowledge-import/chunker.ts +0 -241
  536. package/src/engine/knowledge-import/import-manager.ts +0 -416
  537. package/src/engine/knowledge-import/index.ts +0 -27
  538. package/src/engine/knowledge-import/processors/clean.ts +0 -149
  539. package/src/engine/knowledge-import/processors/extract-gdrive.ts +0 -102
  540. package/src/engine/knowledge-import/processors/extract-github.ts +0 -74
  541. package/src/engine/knowledge-import/processors/extract-sharepoint.ts +0 -69
  542. package/src/engine/knowledge-import/processors/extract-web.ts +0 -275
  543. package/src/engine/knowledge-import/processors/index.ts +0 -18
  544. package/src/engine/knowledge-import/processors/pipeline.ts +0 -171
  545. package/src/engine/knowledge-import/processors/types.ts +0 -78
  546. package/src/engine/knowledge-import/processors/validate.ts +0 -150
  547. package/src/engine/knowledge-import/provider-file-upload.ts +0 -95
  548. package/src/engine/knowledge-import/provider-github.ts +0 -144
  549. package/src/engine/knowledge-import/provider-google-sites.ts +0 -323
  550. package/src/engine/knowledge-import/provider-sharepoint.ts +0 -276
  551. package/src/engine/knowledge-import/provider-url.ts +0 -218
  552. package/src/engine/knowledge-import/routes.ts +0 -94
  553. package/src/engine/knowledge-import/types.ts +0 -92
  554. package/src/engine/knowledge-routes.ts +0 -231
  555. package/src/engine/knowledge.ts +0 -587
  556. package/src/engine/lifecycle.ts +0 -1420
  557. package/src/engine/mcp-process-manager.ts +0 -573
  558. package/src/engine/meeting-monitor.ts +0 -483
  559. package/src/engine/meeting-voice-intelligence.ts +0 -340
  560. package/src/engine/memory-routes.ts +0 -142
  561. package/src/engine/memory-transfer-routes.ts +0 -339
  562. package/src/engine/messaging-history.ts +0 -177
  563. package/src/engine/messaging-poller.ts +0 -786
  564. package/src/engine/model-fallback.ts +0 -141
  565. package/src/engine/oauth-connect-routes.ts +0 -603
  566. package/src/engine/oauth-connect.ts +0 -304
  567. package/src/engine/onboarding-routes.ts +0 -148
  568. package/src/engine/onboarding.ts +0 -574
  569. package/src/engine/org-approval-routes.ts +0 -146
  570. package/src/engine/org-integration-routes.ts +0 -399
  571. package/src/engine/org-integrations.ts +0 -608
  572. package/src/engine/org-policies.ts +0 -502
  573. package/src/engine/policy-import-routes.ts +0 -125
  574. package/src/engine/policy-import.ts +0 -1186
  575. package/src/engine/policy-routes.ts +0 -163
  576. package/src/engine/routes.ts +0 -1236
  577. package/src/engine/screen-unlock.ts +0 -136
  578. package/src/engine/session-router.ts +0 -212
  579. package/src/engine/skill-updater-routes.ts +0 -132
  580. package/src/engine/skill-updater.ts +0 -480
  581. package/src/engine/skill-validator.ts +0 -331
  582. package/src/engine/skills/agent-management.ts +0 -119
  583. package/src/engine/skills/agent-memory.ts +0 -19
  584. package/src/engine/skills/agenticmail.ts +0 -116
  585. package/src/engine/skills/core-tools.ts +0 -25
  586. package/src/engine/skills/database-access.ts +0 -78
  587. package/src/engine/skills/enterprise-code-sandbox.ts +0 -113
  588. package/src/engine/skills/enterprise-database.ts +0 -123
  589. package/src/engine/skills/enterprise-diff.ts +0 -95
  590. package/src/engine/skills/enterprise-documents.ts +0 -162
  591. package/src/engine/skills/enterprise-http.ts +0 -99
  592. package/src/engine/skills/enterprise-security-scan.ts +0 -125
  593. package/src/engine/skills/enterprise-spreadsheet.ts +0 -171
  594. package/src/engine/skills/gws-admin.ts +0 -18
  595. package/src/engine/skills/gws-calendar.ts +0 -21
  596. package/src/engine/skills/gws-chat.ts +0 -29
  597. package/src/engine/skills/gws-contacts.ts +0 -20
  598. package/src/engine/skills/gws-docs.ts +0 -18
  599. package/src/engine/skills/gws-drive.ts +0 -23
  600. package/src/engine/skills/gws-forms.ts +0 -23
  601. package/src/engine/skills/gws-gmail.ts +0 -30
  602. package/src/engine/skills/gws-groups.ts +0 -17
  603. package/src/engine/skills/gws-keep.ts +0 -17
  604. package/src/engine/skills/gws-maps.ts +0 -25
  605. package/src/engine/skills/gws-meet.ts +0 -23
  606. package/src/engine/skills/gws-sheets.ts +0 -22
  607. package/src/engine/skills/gws-sites.ts +0 -16
  608. package/src/engine/skills/gws-slides.ts +0 -27
  609. package/src/engine/skills/gws-tasks.ts +0 -22
  610. package/src/engine/skills/gws-vault.ts +0 -17
  611. package/src/engine/skills/index.ts +0 -159
  612. package/src/engine/skills/knowledge-search.ts +0 -18
  613. package/src/engine/skills/local-system.ts +0 -61
  614. package/src/engine/skills/m365-admin.ts +0 -18
  615. package/src/engine/skills/m365-bookings.ts +0 -17
  616. package/src/engine/skills/m365-copilot.ts +0 -17
  617. package/src/engine/skills/m365-excel.ts +0 -60
  618. package/src/engine/skills/m365-forms.ts +0 -17
  619. package/src/engine/skills/m365-onedrive.ts +0 -60
  620. package/src/engine/skills/m365-onenote.ts +0 -17
  621. package/src/engine/skills/m365-outlook.ts +0 -27
  622. package/src/engine/skills/m365-planner.ts +0 -18
  623. package/src/engine/skills/m365-power-automate.ts +0 -18
  624. package/src/engine/skills/m365-power-bi.ts +0 -19
  625. package/src/engine/skills/m365-powerpoint.ts +0 -33
  626. package/src/engine/skills/m365-sharepoint.ts +0 -20
  627. package/src/engine/skills/m365-teams.ts +0 -21
  628. package/src/engine/skills/m365-todo.ts +0 -17
  629. package/src/engine/skills/m365-whiteboard.ts +0 -16
  630. package/src/engine/skills/m365-word.ts +0 -42
  631. package/src/engine/skills/mcp-bridge.ts +0 -45
  632. package/src/engine/skills/meeting-lifecycle.ts +0 -20
  633. package/src/engine/skills/messaging.ts +0 -46
  634. package/src/engine/skills/visual-memory.ts +0 -25
  635. package/src/engine/skills.ts +0 -688
  636. package/src/engine/soul-library.ts +0 -142
  637. package/src/engine/soul-templates.json +0 -1525
  638. package/src/engine/storage-manager.ts +0 -252
  639. package/src/engine/storage-routes.ts +0 -113
  640. package/src/engine/storage.ts +0 -528
  641. package/src/engine/task-poller.ts +0 -394
  642. package/src/engine/task-queue-after-spawn.ts +0 -66
  643. package/src/engine/task-queue-before-spawn.ts +0 -113
  644. package/src/engine/task-queue-routes.ts +0 -161
  645. package/src/engine/task-queue.ts +0 -664
  646. package/src/engine/tenant.ts +0 -409
  647. package/src/engine/tool-catalog.ts +0 -354
  648. package/src/engine/vault-routes.ts +0 -134
  649. package/src/engine/vault.ts +0 -601
  650. package/src/engine/workforce-routes.ts +0 -331
  651. package/src/engine/workforce.ts +0 -1161
  652. package/src/index.ts +0 -77
  653. package/src/lib/cidr.ts +0 -122
  654. package/src/lib/config-store.ts +0 -86
  655. package/src/lib/resilience.ts +0 -326
  656. package/src/lib/text-search.ts +0 -358
  657. package/src/mcp/adapters/activecampaign.adapter.ts +0 -391
  658. package/src/mcp/adapters/adobe-sign.adapter.ts +0 -469
  659. package/src/mcp/adapters/adp.adapter.ts +0 -358
  660. package/src/mcp/adapters/airtable.adapter.ts +0 -273
  661. package/src/mcp/adapters/apollo.adapter.ts +0 -420
  662. package/src/mcp/adapters/asana.adapter.ts +0 -315
  663. package/src/mcp/adapters/auth0.adapter.ts +0 -386
  664. package/src/mcp/adapters/aws.adapter.ts +0 -345
  665. package/src/mcp/adapters/azure-devops.adapter.ts +0 -389
  666. package/src/mcp/adapters/bamboohr.adapter.ts +0 -376
  667. package/src/mcp/adapters/basecamp.adapter.ts +0 -366
  668. package/src/mcp/adapters/bigcommerce.adapter.ts +0 -429
  669. package/src/mcp/adapters/bitbucket.adapter.ts +0 -260
  670. package/src/mcp/adapters/box.adapter.ts +0 -350
  671. package/src/mcp/adapters/brex.adapter.ts +0 -367
  672. package/src/mcp/adapters/buffer.adapter.ts +0 -303
  673. package/src/mcp/adapters/calendly.adapter.ts +0 -262
  674. package/src/mcp/adapters/canva.adapter.ts +0 -256
  675. package/src/mcp/adapters/chargebee.adapter.ts +0 -448
  676. package/src/mcp/adapters/circleci.adapter.ts +0 -216
  677. package/src/mcp/adapters/clickup.adapter.ts +0 -335
  678. package/src/mcp/adapters/close.adapter.ts +0 -390
  679. package/src/mcp/adapters/cloudflare.adapter.ts +0 -378
  680. package/src/mcp/adapters/confluence.adapter.ts +0 -301
  681. package/src/mcp/adapters/contentful.adapter.ts +0 -355
  682. package/src/mcp/adapters/copper.adapter.ts +0 -468
  683. package/src/mcp/adapters/crisp.adapter.ts +0 -415
  684. package/src/mcp/adapters/crowdstrike.adapter.ts +0 -413
  685. package/src/mcp/adapters/datadog.adapter.ts +0 -373
  686. package/src/mcp/adapters/digitalocean.adapter.ts +0 -336
  687. package/src/mcp/adapters/discord.adapter.ts +0 -248
  688. package/src/mcp/adapters/docker.adapter.ts +0 -238
  689. package/src/mcp/adapters/docusign.adapter.ts +0 -431
  690. package/src/mcp/adapters/drift.adapter.ts +0 -386
  691. package/src/mcp/adapters/dropbox.adapter.ts +0 -315
  692. package/src/mcp/adapters/figma.adapter.ts +0 -302
  693. package/src/mcp/adapters/firebase.adapter.ts +0 -446
  694. package/src/mcp/adapters/flyio.adapter.ts +0 -302
  695. package/src/mcp/adapters/freshbooks.adapter.ts +0 -474
  696. package/src/mcp/adapters/freshdesk.adapter.ts +0 -441
  697. package/src/mcp/adapters/freshsales.adapter.ts +0 -457
  698. package/src/mcp/adapters/freshservice.adapter.ts +0 -481
  699. package/src/mcp/adapters/front.adapter.ts +0 -357
  700. package/src/mcp/adapters/github-actions.adapter.ts +0 -329
  701. package/src/mcp/adapters/github.adapter.ts +0 -387
  702. package/src/mcp/adapters/gitlab.adapter.ts +0 -368
  703. package/src/mcp/adapters/gong.adapter.ts +0 -386
  704. package/src/mcp/adapters/google-ads.adapter.ts +0 -363
  705. package/src/mcp/adapters/google-analytics.adapter.ts +0 -316
  706. package/src/mcp/adapters/google-cloud.adapter.ts +0 -312
  707. package/src/mcp/adapters/gotomeeting.adapter.ts +0 -255
  708. package/src/mcp/adapters/grafana.adapter.ts +0 -361
  709. package/src/mcp/adapters/greenhouse.adapter.ts +0 -354
  710. package/src/mcp/adapters/gusto.adapter.ts +0 -329
  711. package/src/mcp/adapters/hashicorp-vault.adapter.ts +0 -355
  712. package/src/mcp/adapters/heroku.adapter.ts +0 -291
  713. package/src/mcp/adapters/hibob.adapter.ts +0 -334
  714. package/src/mcp/adapters/hootsuite.adapter.ts +0 -322
  715. package/src/mcp/adapters/hubspot.adapter.ts +0 -400
  716. package/src/mcp/adapters/huggingface.adapter.ts +0 -349
  717. package/src/mcp/adapters/index.ts +0 -524
  718. package/src/mcp/adapters/intercom.adapter.ts +0 -269
  719. package/src/mcp/adapters/jira.adapter.ts +0 -482
  720. package/src/mcp/adapters/klaviyo.adapter.ts +0 -353
  721. package/src/mcp/adapters/kubernetes.adapter.ts +0 -431
  722. package/src/mcp/adapters/lattice.adapter.ts +0 -339
  723. package/src/mcp/adapters/launchdarkly.adapter.ts +0 -368
  724. package/src/mcp/adapters/lever.adapter.ts +0 -347
  725. package/src/mcp/adapters/linear.adapter.ts +0 -300
  726. package/src/mcp/adapters/linkedin.adapter.ts +0 -331
  727. package/src/mcp/adapters/livechat.adapter.ts +0 -259
  728. package/src/mcp/adapters/loom.adapter.ts +0 -230
  729. package/src/mcp/adapters/mailchimp.adapter.ts +0 -394
  730. package/src/mcp/adapters/mailgun.adapter.ts +0 -425
  731. package/src/mcp/adapters/miro.adapter.ts +0 -274
  732. package/src/mcp/adapters/mixpanel.adapter.ts +0 -324
  733. package/src/mcp/adapters/monday.adapter.ts +0 -308
  734. package/src/mcp/adapters/mongodb-atlas.adapter.ts +0 -345
  735. package/src/mcp/adapters/neon.adapter.ts +0 -312
  736. package/src/mcp/adapters/netlify.adapter.ts +0 -324
  737. package/src/mcp/adapters/netsuite.adapter.ts +0 -411
  738. package/src/mcp/adapters/newrelic.adapter.ts +0 -339
  739. package/src/mcp/adapters/notion.adapter.ts +0 -338
  740. package/src/mcp/adapters/okta.adapter.ts +0 -394
  741. package/src/mcp/adapters/openai.adapter.ts +0 -315
  742. package/src/mcp/adapters/opsgenie.adapter.ts +0 -375
  743. package/src/mcp/adapters/outreach.adapter.ts +0 -372
  744. package/src/mcp/adapters/paddle.adapter.ts +0 -467
  745. package/src/mcp/adapters/pagerduty.adapter.ts +0 -412
  746. package/src/mcp/adapters/pandadoc.adapter.ts +0 -389
  747. package/src/mcp/adapters/paypal.adapter.ts +0 -465
  748. package/src/mcp/adapters/personio.adapter.ts +0 -401
  749. package/src/mcp/adapters/pinecone.adapter.ts +0 -340
  750. package/src/mcp/adapters/pipedrive.adapter.ts +0 -324
  751. package/src/mcp/adapters/plaid.adapter.ts +0 -444
  752. package/src/mcp/adapters/postmark.adapter.ts +0 -387
  753. package/src/mcp/adapters/power-automate.adapter.ts +0 -388
  754. package/src/mcp/adapters/quickbooks.adapter.ts +0 -431
  755. package/src/mcp/adapters/recurly.adapter.ts +0 -433
  756. package/src/mcp/adapters/reddit.adapter.ts +0 -371
  757. package/src/mcp/adapters/render.adapter.ts +0 -332
  758. package/src/mcp/adapters/ringcentral.adapter.ts +0 -281
  759. package/src/mcp/adapters/rippling.adapter.ts +0 -287
  760. package/src/mcp/adapters/salesforce.adapter.ts +0 -321
  761. package/src/mcp/adapters/salesloft.adapter.ts +0 -413
  762. package/src/mcp/adapters/sanity.adapter.ts +0 -363
  763. package/src/mcp/adapters/sap.adapter.ts +0 -483
  764. package/src/mcp/adapters/segment.adapter.ts +0 -260
  765. package/src/mcp/adapters/sendgrid.adapter.ts +0 -265
  766. package/src/mcp/adapters/sentry.adapter.ts +0 -331
  767. package/src/mcp/adapters/servicenow.adapter.ts +0 -468
  768. package/src/mcp/adapters/shopify.adapter.ts +0 -451
  769. package/src/mcp/adapters/shortcut.adapter.ts +0 -290
  770. package/src/mcp/adapters/slack.adapter.ts +0 -380
  771. package/src/mcp/adapters/smartsheet.adapter.ts +0 -326
  772. package/src/mcp/adapters/snowflake.adapter.ts +0 -347
  773. package/src/mcp/adapters/snyk.adapter.ts +0 -394
  774. package/src/mcp/adapters/splunk.adapter.ts +0 -403
  775. package/src/mcp/adapters/square.adapter.ts +0 -467
  776. package/src/mcp/adapters/statuspage.adapter.ts +0 -401
  777. package/src/mcp/adapters/stripe.adapter.ts +0 -380
  778. package/src/mcp/adapters/supabase.adapter.ts +0 -334
  779. package/src/mcp/adapters/teamwork.adapter.ts +0 -404
  780. package/src/mcp/adapters/telegram.adapter.ts +0 -299
  781. package/src/mcp/adapters/terraform.adapter.ts +0 -300
  782. package/src/mcp/adapters/todoist.adapter.ts +0 -239
  783. package/src/mcp/adapters/trello.adapter.ts +0 -316
  784. package/src/mcp/adapters/twilio.adapter.ts +0 -233
  785. package/src/mcp/adapters/twitter.adapter.ts +0 -348
  786. package/src/mcp/adapters/vercel.adapter.ts +0 -219
  787. package/src/mcp/adapters/weaviate.adapter.ts +0 -371
  788. package/src/mcp/adapters/webex.adapter.ts +0 -237
  789. package/src/mcp/adapters/webflow.adapter.ts +0 -287
  790. package/src/mcp/adapters/whatsapp.adapter.ts +0 -273
  791. package/src/mcp/adapters/whereby.adapter.ts +0 -240
  792. package/src/mcp/adapters/woocommerce.adapter.ts +0 -454
  793. package/src/mcp/adapters/wordpress.adapter.ts +0 -455
  794. package/src/mcp/adapters/workday.adapter.ts +0 -354
  795. package/src/mcp/adapters/wrike.adapter.ts +0 -349
  796. package/src/mcp/adapters/xero.adapter.ts +0 -472
  797. package/src/mcp/adapters/youtube.adapter.ts +0 -401
  798. package/src/mcp/adapters/zendesk.adapter.ts +0 -399
  799. package/src/mcp/adapters/zoho-crm.adapter.ts +0 -410
  800. package/src/mcp/adapters/zoom.adapter.ts +0 -241
  801. package/src/mcp/adapters/zuora.adapter.ts +0 -476
  802. package/src/mcp/framework/api-executor.ts +0 -192
  803. package/src/mcp/framework/aws-sigv4.ts +0 -216
  804. package/src/mcp/framework/credential-resolver.ts +0 -128
  805. package/src/mcp/framework/oauth-token-manager.ts +0 -22
  806. package/src/mcp/framework/skill-mcp-framework.ts +0 -226
  807. package/src/mcp/framework/types.ts +0 -130
  808. package/src/mcp/index.ts +0 -124
  809. package/src/mcp/integration-catalog.ts +0 -178
  810. package/src/middleware/dns-rebinding.ts +0 -44
  811. package/src/middleware/egress-filter.ts +0 -104
  812. package/src/middleware/firewall.ts +0 -192
  813. package/src/middleware/geo-ip.ts +0 -156
  814. package/src/middleware/index.ts +0 -390
  815. package/src/middleware/network-config.ts +0 -90
  816. package/src/middleware/proxy-config.ts +0 -71
  817. package/src/middleware/request-limits.ts +0 -59
  818. package/src/middleware/transport-encryption.ts +0 -398
  819. package/src/registry/cli.ts +0 -63
  820. package/src/registry/server.ts +0 -504
  821. package/src/runtime/agent-loop.ts +0 -779
  822. package/src/runtime/compaction.ts +0 -638
  823. package/src/runtime/email-channel.ts +0 -120
  824. package/src/runtime/environment.ts +0 -300
  825. package/src/runtime/followup.ts +0 -211
  826. package/src/runtime/gateway.ts +0 -260
  827. package/src/runtime/hooks.ts +0 -564
  828. package/src/runtime/index.ts +0 -1110
  829. package/src/runtime/llm-client.ts +0 -1056
  830. package/src/runtime/model-router.ts +0 -97
  831. package/src/runtime/providers.ts +0 -228
  832. package/src/runtime/session-manager.ts +0 -345
  833. package/src/runtime/subagent.ts +0 -153
  834. package/src/runtime/tool-executor.ts +0 -208
  835. package/src/runtime/types.ts +0 -255
  836. package/src/security/brute-force.ts +0 -423
  837. package/src/security/config.ts +0 -159
  838. package/src/security/csp.ts +0 -407
  839. package/src/security/external-content.ts +0 -299
  840. package/src/security/index.ts +0 -557
  841. package/src/security/input-sanitizer.ts +0 -452
  842. package/src/security/output-filter.ts +0 -575
  843. package/src/security/port-scanner.ts +0 -342
  844. package/src/security/prompt-guard.ts +0 -387
  845. package/src/security/sql-guard.ts +0 -338
  846. package/src/security/threat-logger.ts +0 -484
  847. package/src/server.ts +0 -828
  848. package/src/setup/company.ts +0 -183
  849. package/src/setup/database.ts +0 -153
  850. package/src/setup/deployment.ts +0 -561
  851. package/src/setup/domain.ts +0 -112
  852. package/src/setup/index.ts +0 -171
  853. package/src/setup/provision.ts +0 -532
  854. package/src/setup/registration.ts +0 -302
  855. package/src/system-prompts/catchup.ts +0 -48
  856. package/src/system-prompts/google/calendar.ts +0 -37
  857. package/src/system-prompts/google/chat.ts +0 -92
  858. package/src/system-prompts/google/contacts.ts +0 -25
  859. package/src/system-prompts/google/docs.ts +0 -29
  860. package/src/system-prompts/google/drive.ts +0 -34
  861. package/src/system-prompts/google/forms.ts +0 -25
  862. package/src/system-prompts/google/gmail.ts +0 -50
  863. package/src/system-prompts/google/index.ts +0 -23
  864. package/src/system-prompts/google/maps.ts +0 -20
  865. package/src/system-prompts/google/meet.ts +0 -130
  866. package/src/system-prompts/google/sheets.ts +0 -32
  867. package/src/system-prompts/google/slides.ts +0 -26
  868. package/src/system-prompts/google/tasks.ts +0 -27
  869. package/src/system-prompts/index.ts +0 -88
  870. package/src/system-prompts/microsoft/contacts.ts +0 -34
  871. package/src/system-prompts/microsoft/excel.ts +0 -52
  872. package/src/system-prompts/microsoft/index.ts +0 -31
  873. package/src/system-prompts/microsoft/onedrive.ts +0 -41
  874. package/src/system-prompts/microsoft/onenote.ts +0 -36
  875. package/src/system-prompts/microsoft/outlook-calendar.ts +0 -37
  876. package/src/system-prompts/microsoft/outlook-mail.ts +0 -46
  877. package/src/system-prompts/microsoft/planner.ts +0 -37
  878. package/src/system-prompts/microsoft/powerbi.ts +0 -38
  879. package/src/system-prompts/microsoft/powerpoint.ts +0 -35
  880. package/src/system-prompts/microsoft/sharepoint.ts +0 -44
  881. package/src/system-prompts/microsoft/teams.ts +0 -49
  882. package/src/system-prompts/microsoft/todo.ts +0 -37
  883. package/src/system-prompts/shared-blocks.ts +0 -87
  884. package/src/system-prompts/task.ts +0 -21
  885. package/src/system-prompts/triage.ts +0 -34
  886. package/src/types/hono-env.ts +0 -18
  887. package/src/types/optional-deps.d.ts +0 -10
  888. /package/{src → dist}/dashboard/HELP-TOOLTIPS-GUIDE.md +0 -0
@@ -1,1679 +0,0 @@
1
- /**
2
- * Compliance Reporting Engine — Enterprise SOC 2 Grade
3
- *
4
- * Generates comprehensive compliance reports mapping to SOC 2 Trust Service Criteria:
5
- * CC1: Control Environment (org structure, policies, agent governance)
6
- * CC2: Communication & Information (logging, monitoring, audit trails)
7
- * CC3: Risk Assessment (DLP, anomaly detection, threat analysis)
8
- * CC4: Monitoring Activities (interventions, guardrails, real-time controls)
9
- * CC5: Control Activities (approvals, permissions, tool restrictions)
10
- * CC6: Logical & Physical Access (auth, SSO, vault, session management)
11
- * CC7: System Operations (uptime, task pipeline, agent health, incidents)
12
- * CC8: Change Management (config changes, deployments, journal rollbacks)
13
- * CC9: Risk Mitigation (escalations, budget controls, compliance posture)
14
- *
15
- * Also: GDPR data export (Art. 15 DSAR), SOX-ready audit trails, full CSV/JSON export.
16
- */
17
-
18
- import type { EngineDatabase } from './db-adapter.js';
19
-
20
- function sj(v: string|null|undefined, fb: any = {}): any { if(!v) return fb; try { return JSON.parse(v); } catch { return fb; } }
21
-
22
- // ─── Types ──────────────────────────────────────────────
23
-
24
- export interface ComplianceReport {
25
- id: string;
26
- orgId: string;
27
- type: 'soc2' | 'gdpr' | 'audit' | 'incident' | 'access-review';
28
- title: string;
29
- parameters: Record<string, any>;
30
- status: 'generating' | 'completed' | 'failed';
31
- data?: Record<string, any>;
32
- format: 'json' | 'csv';
33
- generatedBy: string;
34
- error?: string;
35
- createdAt: string;
36
- completedAt?: string;
37
- }
38
-
39
- interface DateRange { from: string; to: string; }
40
- type Rows = any[];
41
-
42
- // ─── Compliance Reporter ────────────────────────────────
43
-
44
- export class ComplianceReporter {
45
- private reports: ComplianceReport[] = [];
46
- private engineDb?: EngineDatabase;
47
-
48
- async setDb(db: EngineDatabase): Promise<void> {
49
- this.engineDb = db;
50
- await this.loadFromDb();
51
- }
52
-
53
- private async loadFromDb(): Promise<void> {
54
- if (!this.engineDb) return;
55
- try {
56
- const rows = await this.engineDb.query<any>(
57
- 'SELECT * FROM compliance_reports ORDER BY created_at DESC LIMIT 200'
58
- );
59
- this.reports = rows.map((r: any) => ({
60
- id: r.id, orgId: r.org_id, type: r.type, title: r.title,
61
- parameters: r.parameters ? sj(r.parameters) : {},
62
- status: r.status, data: r.data ? sj(r.data) : undefined,
63
- format: r.format || 'json', generatedBy: r.generated_by,
64
- error: r.error, createdAt: r.created_at, completedAt: r.completed_at,
65
- }));
66
- } catch { /* table may not exist yet */ }
67
- }
68
-
69
- // ─── Helper: safe query ───────────────────────────
70
-
71
- private async q(sql: string, params: any[]): Promise<Rows> {
72
- if (!this.engineDb) return [];
73
- try { return await this.engineDb.query<any>(sql, params); } catch { return []; }
74
- }
75
-
76
- private cnt(rows: Rows): number { return rows[0]?.cnt || rows[0]?.count || 0; }
77
-
78
- // ─── SOC 2 Report ─────────────────────────────────
79
-
80
- async generateSOC2(orgId: string, dateRange: DateRange, generatedBy: string, agentIds?: string[]): Promise<ComplianceReport> {
81
- const report = this.createReport(orgId, 'soc2', `SOC 2 Type II Report — ${dateRange.from} to ${dateRange.to}`, { dateRange, agentIds }, generatedBy);
82
- const { from, to } = dateRange;
83
-
84
- try {
85
- const data: Record<string, any> = {
86
- reportMetadata: {
87
- framework: 'SOC 2 Type II',
88
- trustServiceCriteria: ['Security', 'Availability', 'Processing Integrity', 'Confidentiality', 'Privacy'],
89
- reportingPeriod: dateRange,
90
- generatedAt: new Date().toISOString(),
91
- generatedBy,
92
- orgId,
93
- agentScope: agentIds?.length ? agentIds : 'all',
94
- }
95
- };
96
-
97
- // ═══════════════════════════════════════════════
98
- // CC1: CONTROL ENVIRONMENT
99
- // ═══════════════════════════════════════════════
100
-
101
- const agents = await this.q('SELECT * FROM managed_agents WHERE org_id = ?', [orgId]);
102
- const policies = await this.q('SELECT * FROM org_policies WHERE org_id = ?', [orgId]);
103
- const permProfiles = await this.q('SELECT * FROM permission_profiles WHERE org_id = ?', [orgId]);
104
- const guardrailRules = await this.q('SELECT * FROM guardrail_rules WHERE org_id = ?', [orgId]);
105
- const dlpRules = await this.q('SELECT * FROM dlp_rules WHERE org_id = ?', [orgId]);
106
- const escalationChains = await this.q('SELECT * FROM escalation_chains WHERE org_id = ?', [orgId]);
107
- const org = await this.q('SELECT * FROM organizations WHERE id = ?', [orgId]);
108
- const orgName = org[0]?.name || orgId;
109
- data.reportMetadata.organization = orgName;
110
- data._orgName = orgName;
111
-
112
- data.cc1_controlEnvironment = {
113
- title: 'CC1: Control Environment',
114
- description: 'Organization structure, governance policies, and agent management framework.',
115
- organization: org[0] ? { id: org[0].id, name: org[0].name, createdAt: org[0].created_at, settings: sj(org[0].settings) } : null,
116
- agentInventory: {
117
- totalAgents: agents.length,
118
- agents: agents.map((a: any) => ({
119
- id: a.id, name: sj(a.config)?.displayName || sj(a.config)?.name || a.id,
120
- status: a.status, role: sj(a.config)?.identity?.role || 'agent',
121
- model: sj(a.config)?.model, createdAt: a.created_at,
122
- hasPermissionProfile: !!sj(a.config)?.permissionProfile,
123
- permissionProfile: sj(a.config)?.permissionProfile || 'default',
124
- hasBudgetConfig: !!a.budget_config,
125
- budgetConfig: a.budget_config ? sj(a.budget_config) : null,
126
- })),
127
- },
128
- governancePolicies: {
129
- totalPolicies: policies.length,
130
- policies: policies.map((p: any) => ({
131
- id: p.id, name: p.name, category: p.category, enforcement: p.enforcement,
132
- enabled: !!p.enabled, priority: p.priority, createdAt: p.created_at,
133
- description: p.description,
134
- })),
135
- byCategory: this.groupCount(policies, 'category'),
136
- byEnforcement: this.groupCount(policies, 'enforcement'),
137
- },
138
- permissionProfiles: {
139
- totalProfiles: permProfiles.length,
140
- profiles: permProfiles.map((p: any) => ({
141
- id: p.id, name: p.name, preset: p.preset, description: p.description,
142
- createdAt: p.created_at,
143
- })),
144
- },
145
- escalationChains: {
146
- total: escalationChains.length,
147
- chains: escalationChains.map((c: any) => ({
148
- id: c.id, name: c.name, enabled: !!c.enabled,
149
- steps: sj(c.steps, []).length,
150
- })),
151
- },
152
- };
153
-
154
- // Build agent name map for display resolution
155
- const agentNameMap: Record<string, string> = {};
156
- for (const a of agents) {
157
- const cfg = sj(a.config);
158
- agentNameMap[a.id] = cfg?.displayName || cfg?.name || a.id;
159
- }
160
- data._agentNameMap = agentNameMap;
161
-
162
- // Resolve generatedBy to user name
163
- try {
164
- const users = await this.q('SELECT id, email, name FROM users WHERE id = ? LIMIT 1', [generatedBy]);
165
- if (users[0]) {
166
- data._generatedByName = users[0].name || users[0].email || generatedBy;
167
- }
168
- } catch {}
169
-
170
- // Also count approval policies with escalation/notification as escalation mechanisms
171
- const approvalPoliciesWithNotify = await this.q(
172
- "SELECT * FROM approval_policies WHERE org_id = ? AND notify IS NOT NULL AND notify::text != '{}'", [orgId]);
173
- data._escalationViaApprovalPolicies = approvalPoliciesWithNotify.length;
174
-
175
- // ═══════════════════════════════════════════════
176
- // CC2: COMMUNICATION & INFORMATION
177
- // ═══════════════════════════════════════════════
178
-
179
- const totalToolCalls = this.cnt(await this.q(
180
- 'SELECT COUNT(*) as cnt FROM tool_calls WHERE org_id = ? AND created_at BETWEEN ? AND ?', [orgId, from, to]));
181
- const toolCallsByAgent = await this.q(
182
- 'SELECT agent_id, COUNT(*) as cnt FROM tool_calls WHERE org_id = ? AND created_at BETWEEN ? AND ? GROUP BY agent_id', [orgId, from, to]);
183
- const toolCallsByTool = await this.q(
184
- 'SELECT tool_id, tool_name, COUNT(*) as cnt, SUM(CASE WHEN success = false THEN 1 ELSE 0 END) as failures FROM tool_calls WHERE org_id = ? AND created_at BETWEEN ? AND ? GROUP BY tool_id, tool_name ORDER BY cnt DESC LIMIT 50', [orgId, from, to]);
185
- const toolCallsByDay = await this.q(
186
- "SELECT DATE(created_at) as day, COUNT(*) as cnt FROM tool_calls WHERE org_id = ? AND created_at BETWEEN ? AND ? GROUP BY DATE(created_at) ORDER BY day", [orgId, from, to]);
187
-
188
- const totalEvents = this.cnt(await this.q(
189
- 'SELECT COUNT(*) as cnt FROM activity_events WHERE org_id = ? AND created_at BETWEEN ? AND ?', [orgId, from, to]));
190
- const eventsByType = await this.q(
191
- 'SELECT type, COUNT(*) as cnt FROM activity_events WHERE org_id = ? AND created_at BETWEEN ? AND ? GROUP BY type ORDER BY cnt DESC', [orgId, from, to]);
192
-
193
- const totalMessages = this.cnt(await this.q(
194
- 'SELECT COUNT(*) as cnt FROM agent_messages WHERE org_id = ? AND created_at BETWEEN ? AND ?', [orgId, from, to]));
195
- const messagesByAgent = await this.q(
196
- 'SELECT from_agent_id as agent_id, COUNT(*) as cnt FROM agent_messages WHERE org_id = ? AND created_at BETWEEN ? AND ? GROUP BY from_agent_id', [orgId, from, to]);
197
-
198
- data.cc2_communicationInformation = {
199
- title: 'CC2: Communication & Information',
200
- description: 'Audit trail completeness, logging coverage, and information flow monitoring.',
201
- auditTrail: {
202
- toolCalls: {
203
- totalExecutions: totalToolCalls,
204
- byAgent: this.rowsToMap(toolCallsByAgent, 'agent_id', 'cnt'),
205
- topTools: toolCallsByTool.map((r: any) => ({ toolId: r.tool_id, toolName: r.tool_name, executions: r.cnt, failures: r.failures || 0 })),
206
- dailyVolume: toolCallsByDay.map((r: any) => ({ date: r.day, count: r.cnt })),
207
- },
208
- activityEvents: {
209
- totalEvents,
210
- byType: this.rowsToMap(eventsByType, 'type', 'cnt'),
211
- },
212
- agentCommunications: {
213
- totalMessages,
214
- byAgent: this.rowsToMap(messagesByAgent, 'agent_id', 'cnt'),
215
- },
216
- },
217
- loggingCoverage: {
218
- toolCallLogging: 'ENABLED — All tool executions logged with parameters, results, timing',
219
- activityEventLogging: 'ENABLED — All agent lifecycle events captured',
220
- interventionLogging: 'ENABLED — All guardrail interventions recorded',
221
- dlpScanning: `ENABLED — ${dlpRules.length} active DLP rules`,
222
- journalTracking: 'ENABLED — Reversible action journal with rollback support',
223
- },
224
- };
225
-
226
- // ═══════════════════════════════════════════════
227
- // CC3: RISK ASSESSMENT
228
- // ═══════════════════════════════════════════════
229
-
230
- const dlpViolations = await this.q(
231
- 'SELECT * FROM dlp_violations WHERE org_id = ? AND created_at BETWEEN ? AND ? ORDER BY created_at DESC', [orgId, from, to]);
232
- const dlpByAction = await this.q(
233
- 'SELECT action_taken, COUNT(*) as cnt FROM dlp_violations WHERE org_id = ? AND created_at BETWEEN ? AND ? GROUP BY action_taken', [orgId, from, to]);
234
- const dlpByAgent = await this.q(
235
- 'SELECT agent_id, COUNT(*) as cnt FROM dlp_violations WHERE org_id = ? AND created_at BETWEEN ? AND ? GROUP BY agent_id ORDER BY cnt DESC', [orgId, from, to]);
236
- const dlpByRule = await this.q(
237
- 'SELECT rule_id, COUNT(*) as cnt FROM dlp_violations WHERE org_id = ? AND created_at BETWEEN ? AND ? GROUP BY rule_id ORDER BY cnt DESC', [orgId, from, to]);
238
-
239
- const securityEvents = await this.q(
240
- 'SELECT * FROM security_events WHERE org_id = ? AND created_at BETWEEN ? AND ? ORDER BY created_at DESC', [orgId, from, to]);
241
-
242
- data.cc3_riskAssessment = {
243
- title: 'CC3: Risk Assessment',
244
- description: 'Data loss prevention, threat detection, and risk scoring.',
245
- dlpControls: {
246
- activeRules: dlpRules.length,
247
- rulesByAction: this.groupCount(dlpRules, 'action'),
248
- rulesBySeverity: this.groupCount(dlpRules, 'severity'),
249
- rules: dlpRules.map((r: any) => ({
250
- id: r.id, name: r.name, patternType: r.pattern_type, action: r.action,
251
- severity: r.severity, enabled: !!r.enabled, appliesTo: r.applies_to,
252
- })),
253
- },
254
- dlpViolations: {
255
- totalViolations: dlpViolations.length,
256
- byAction: this.rowsToMap(dlpByAction, 'action_taken', 'cnt'),
257
- byAgent: this.rowsToMap(dlpByAgent, 'agent_id', 'cnt'),
258
- byRule: this.rowsToMap(dlpByRule, 'rule_id', 'cnt'),
259
- recentViolations: dlpViolations.slice(0, 50).map((v: any) => ({
260
- id: v.id, agentId: v.agent_id, ruleId: v.rule_id, toolId: v.tool_id,
261
- actionTaken: v.action_taken, direction: v.direction,
262
- matchContext: v.match_context, timestamp: v.created_at,
263
- })),
264
- },
265
- securityEvents: {
266
- total: securityEvents.length,
267
- events: securityEvents.map((e: any) => ({
268
- id: e.id, type: e.type, severity: e.severity, agentId: e.agent_id,
269
- description: e.description, timestamp: e.created_at,
270
- })),
271
- },
272
- riskScore: this.calculateRiskScore(dlpViolations, securityEvents, guardrailRules, dlpRules),
273
- };
274
-
275
- // ═══════════════════════════════════════════════
276
- // CC4: MONITORING ACTIVITIES
277
- // ═══════════════════════════════════════════════
278
-
279
- const interventions = await this.q(
280
- 'SELECT * FROM interventions WHERE org_id = ? AND created_at BETWEEN ? AND ? ORDER BY created_at DESC', [orgId, from, to]);
281
- const interventionsByType = await this.q(
282
- 'SELECT type, COUNT(*) as cnt FROM interventions WHERE org_id = ? AND created_at BETWEEN ? AND ? GROUP BY type', [orgId, from, to]);
283
- const interventionsByAgent = await this.q(
284
- 'SELECT agent_id, COUNT(*) as cnt FROM interventions WHERE org_id = ? AND created_at BETWEEN ? AND ? GROUP BY agent_id ORDER BY cnt DESC', [orgId, from, to]);
285
-
286
- data.cc4_monitoringActivities = {
287
- title: 'CC4: Monitoring Activities',
288
- description: 'Guardrail interventions, real-time monitoring, and anomaly detection.',
289
- guardrailRules: {
290
- totalRules: guardrailRules.length,
291
- rules: guardrailRules.map((r: any) => ({
292
- id: r.id, name: r.name, type: r.type, action: r.action,
293
- enabled: !!r.enabled, severity: r.severity, createdAt: r.created_at,
294
- })),
295
- },
296
- interventions: {
297
- totalInterventions: interventions.length,
298
- byType: this.rowsToMap(interventionsByType, 'type', 'cnt'),
299
- byAgent: this.rowsToMap(interventionsByAgent, 'agent_id', 'cnt'),
300
- recentInterventions: interventions.slice(0, 100).map((i: any) => ({
301
- id: i.id, agentId: i.agent_id, type: i.type, reason: i.reason,
302
- action: i.action, ruleId: i.rule_id, toolId: i.tool_id,
303
- timestamp: i.created_at,
304
- })),
305
- },
306
- };
307
-
308
- // ═══════════════════════════════════════════════
309
- // CC5: CONTROL ACTIVITIES
310
- // ═══════════════════════════════════════════════
311
-
312
- const approvals = await this.q(
313
- 'SELECT * FROM approval_requests WHERE org_id = ? AND created_at BETWEEN ? AND ? ORDER BY created_at DESC', [orgId, from, to]);
314
- const approvalsByStatus = await this.q(
315
- 'SELECT status, COUNT(*) as cnt FROM approval_requests WHERE org_id = ? AND created_at BETWEEN ? AND ? GROUP BY status', [orgId, from, to]);
316
- const approvalsByAgent = await this.q(
317
- 'SELECT agent_id, COUNT(*) as cnt FROM approval_requests WHERE org_id = ? AND created_at BETWEEN ? AND ? GROUP BY agent_id', [orgId, from, to]);
318
- const approvalPolicies = await this.q('SELECT * FROM approval_policies WHERE org_id = ?', [orgId]);
319
-
320
- const escalations = await this.q(
321
- 'SELECT * FROM agent_escalations WHERE org_id = ? AND created_at BETWEEN ? AND ? ORDER BY created_at DESC', [orgId, from, to]);
322
-
323
- data.cc5_controlActivities = {
324
- title: 'CC5: Control Activities',
325
- description: 'Approval workflows, permission enforcement, and operational controls.',
326
- approvalWorkflows: {
327
- totalRequests: approvals.length,
328
- byStatus: this.rowsToMap(approvalsByStatus, 'status', 'cnt'),
329
- byAgent: this.rowsToMap(approvalsByAgent, 'agent_id', 'cnt'),
330
- policies: approvalPolicies.map((p: any) => ({
331
- id: p.id, name: p.name, toolPattern: p.tool_pattern,
332
- requireApproval: !!p.require_approval, autoApprove: !!p.auto_approve,
333
- })),
334
- recentRequests: approvals.slice(0, 50).map((a: any) => ({
335
- id: a.id, agentId: a.agent_id, toolId: a.tool_id, status: a.status,
336
- requestedAt: a.created_at, resolvedAt: a.resolved_at,
337
- resolvedBy: a.resolved_by, reason: a.reason,
338
- })),
339
- approvalRate: approvals.length > 0 ? ((approvals.filter((a: any) => a.status === 'approved').length / approvals.length) * 100).toFixed(1) + '%' : 'N/A',
340
- avgResponseTime: this.calcAvgResponseTime(approvals),
341
- },
342
- escalations: {
343
- total: escalations.length,
344
- escalations: escalations.slice(0, 50).map((e: any) => ({
345
- id: e.id, agentId: e.agent_id, type: e.type, priority: e.priority,
346
- status: e.status, reason: e.reason, timestamp: e.created_at,
347
- })),
348
- },
349
- permissionEnforcement: {
350
- profiles: permProfiles.length,
351
- summary: 'All agent tool access governed by permission profiles with allow/deny/approval controls.',
352
- },
353
- };
354
-
355
- // ═══════════════════════════════════════════════
356
- // CC6: LOGICAL & PHYSICAL ACCESS
357
- // ═══════════════════════════════════════════════
358
-
359
- const vaultAudit = await this.q(
360
- 'SELECT * FROM vault_audit_log WHERE org_id = ? AND created_at BETWEEN ? AND ? ORDER BY created_at DESC', [orgId, from, to]);
361
- const vaultByAction = await this.q(
362
- 'SELECT action, COUNT(*) as cnt FROM vault_audit_log WHERE org_id = ? AND created_at BETWEEN ? AND ? GROUP BY action', [orgId, from, to]);
363
- const vaultEntries = await this.q(
364
- 'SELECT id, key, agent_id, created_at, updated_at, expires_at FROM vault_entries WHERE org_id = ?', [orgId]);
365
-
366
- const ssoIntegrations = await this.q('SELECT * FROM sso_integrations WHERE org_id = ?', [orgId]);
367
-
368
- const sessions = await this.q(
369
- 'SELECT agent_id, COUNT(*) as cnt, MAX(created_at) as last_session FROM agent_sessions WHERE org_id = ? AND created_at BETWEEN ? AND ? GROUP BY agent_id', [orgId, from, to]);
370
-
371
- data.cc6_logicalAccess = {
372
- title: 'CC6: Logical & Physical Access Controls',
373
- description: 'Authentication, secrets management, session tracking, and SSO controls.',
374
- vaultManagement: {
375
- totalSecrets: vaultEntries.length,
376
- secrets: vaultEntries.map((v: any) => ({
377
- id: v.id, key: v.key, agentId: v.agent_id,
378
- createdAt: v.created_at, updatedAt: v.updated_at,
379
- expiresAt: v.expires_at, expired: v.expires_at ? new Date(v.expires_at) < new Date() : false,
380
- })),
381
- auditLog: {
382
- totalAccesses: vaultAudit.length,
383
- byAction: this.rowsToMap(vaultByAction, 'action', 'cnt'),
384
- recentAccesses: vaultAudit.slice(0, 50).map((v: any) => ({
385
- id: v.id, action: v.action, key: v.key, agentId: v.agent_id,
386
- timestamp: v.created_at, ip: v.ip_address,
387
- })),
388
- },
389
- },
390
- ssoIntegrations: {
391
- total: ssoIntegrations.length,
392
- integrations: ssoIntegrations.map((s: any) => ({
393
- id: s.id, provider: s.provider, enabled: !!s.enabled,
394
- createdAt: s.created_at,
395
- })),
396
- },
397
- sessionManagement: {
398
- agentSessions: sessions.map((s: any) => ({
399
- agentId: s.agent_id, sessionCount: s.cnt, lastSession: s.last_session,
400
- })),
401
- },
402
- };
403
-
404
- // ═══════════════════════════════════════════════
405
- // CC7: SYSTEM OPERATIONS
406
- // ═══════════════════════════════════════════════
407
-
408
- const taskPipeline = await this.q(
409
- 'SELECT status, COUNT(*) as cnt FROM task_pipeline WHERE org_id = ? AND created_at BETWEEN ? AND ? GROUP BY status', [orgId, from, to]);
410
- const taskQueue = await this.q(
411
- 'SELECT status, COUNT(*) as cnt FROM task_queue WHERE org_id = ? AND created_at BETWEEN ? AND ? GROUP BY status', [orgId, from, to]);
412
-
413
- const clockRecords = await this.q(
414
- 'SELECT * FROM clock_records WHERE org_id = ? AND created_at BETWEEN ? AND ? ORDER BY created_at DESC', [orgId, from, to]);
415
- const workSchedules = await this.q('SELECT * FROM work_schedules WHERE org_id = ?', [orgId]);
416
-
417
- const conversations = await this.q(
418
- 'SELECT agent_id, COUNT(*) as cnt, SUM(CASE WHEN status = \'completed\' THEN 1 ELSE 0 END) as completed FROM conversations WHERE org_id = ? AND created_at BETWEEN ? AND ? GROUP BY agent_id', [orgId, from, to]);
419
-
420
- data.cc7_systemOperations = {
421
- title: 'CC7: System Operations',
422
- description: 'Agent availability, task processing, workforce management, and operational health.',
423
- taskPipeline: {
424
- byStatus: this.rowsToMap(taskPipeline, 'status', 'cnt'),
425
- },
426
- taskQueue: {
427
- byStatus: this.rowsToMap(taskQueue, 'status', 'cnt'),
428
- },
429
- workforceManagement: {
430
- schedules: workSchedules.map((w: any) => ({
431
- id: w.id, agentId: w.agent_id, schedule: sj(w.schedule),
432
- timezone: w.timezone, enabled: !!w.enabled,
433
- })),
434
- clockRecords: {
435
- total: clockRecords.length,
436
- records: clockRecords.slice(0, 100).map((r: any) => ({
437
- agentId: r.agent_id, type: r.type, timestamp: r.created_at,
438
- source: r.source, duration: r.duration_minutes,
439
- })),
440
- },
441
- },
442
- conversationMetrics: {
443
- byAgent: conversations.map((c: any) => ({
444
- agentId: c.agent_id, total: c.cnt, completed: c.completed,
445
- completionRate: c.cnt > 0 ? ((c.completed / c.cnt) * 100).toFixed(1) + '%' : 'N/A',
446
- })),
447
- },
448
- };
449
-
450
- // ═══════════════════════════════════════════════
451
- // CC8: CHANGE MANAGEMENT
452
- // ═══════════════════════════════════════════════
453
-
454
- const journalActions = await this.q(
455
- 'SELECT * FROM action_journal WHERE org_id = ? AND created_at BETWEEN ? AND ? ORDER BY created_at DESC', [orgId, from, to]);
456
- const journalByType = await this.q(
457
- 'SELECT action_type, COUNT(*) as cnt, SUM(CASE WHEN reversed = true OR reversed = 1 THEN 1 ELSE 0 END) as reversed_cnt FROM action_journal WHERE org_id = ? AND created_at BETWEEN ? AND ? GROUP BY action_type', [orgId, from, to]);
458
- const journalByAgent = await this.q(
459
- 'SELECT agent_id, COUNT(*) as cnt FROM action_journal WHERE org_id = ? AND created_at BETWEEN ? AND ? GROUP BY agent_id', [orgId, from, to]);
460
-
461
- const stateHistory = await this.q(
462
- 'SELECT * FROM agent_state_history WHERE org_id = ? AND created_at BETWEEN ? AND ? ORDER BY created_at DESC LIMIT 200', [orgId, from, to]);
463
-
464
- data.cc8_changeManagement = {
465
- title: 'CC8: Change Management',
466
- description: 'Configuration changes, action journal with rollback tracking, and deployment history.',
467
- actionJournal: {
468
- totalActions: journalActions.length,
469
- byType: journalByType.map((r: any) => ({
470
- actionType: r.action_type, total: r.cnt, reversed: r.reversed_cnt || 0,
471
- rollbackRate: r.cnt > 0 ? (((r.reversed_cnt || 0) / r.cnt) * 100).toFixed(1) + '%' : '0%',
472
- })),
473
- byAgent: this.rowsToMap(journalByAgent, 'agent_id', 'cnt'),
474
- recentActions: journalActions.slice(0, 100).map((j: any) => ({
475
- id: j.id, agentId: j.agent_id, toolName: j.tool_name || j.tool_id,
476
- actionType: j.action_type, reversible: !!j.reversible,
477
- reversed: !!j.reversed, reversedAt: j.reversed_at, reversedBy: j.reversed_by,
478
- sessionId: j.session_id, timestamp: j.created_at,
479
- })),
480
- totalReversed: journalActions.filter((j: any) => j.reversed).length,
481
- reversalRate: journalActions.length > 0
482
- ? ((journalActions.filter((j: any) => j.reversed).length / journalActions.length) * 100).toFixed(1) + '%' : '0%',
483
- },
484
- configurationChanges: {
485
- totalStateChanges: stateHistory.length,
486
- recentChanges: stateHistory.slice(0, 50).map((s: any) => ({
487
- agentId: s.agent_id, fromState: s.from_state, toState: s.to_state,
488
- changedBy: s.changed_by, reason: s.reason, timestamp: s.created_at,
489
- })),
490
- },
491
- };
492
-
493
- // ═══════════════════════════════════════════════
494
- // CC9: RISK MITIGATION
495
- // ═══════════════════════════════════════════════
496
-
497
- const budgetAlerts = await this.q(
498
- 'SELECT * FROM budget_alerts WHERE org_id = ? AND created_at BETWEEN ? AND ? ORDER BY created_at DESC', [orgId, from, to]);
499
- const budgetByType = await this.q(
500
- 'SELECT alert_type, COUNT(*) as cnt FROM budget_alerts WHERE org_id = ? AND created_at BETWEEN ? AND ? GROUP BY alert_type', [orgId, from, to]);
501
-
502
- data.cc9_riskMitigation = {
503
- title: 'CC9: Risk Mitigation',
504
- description: 'Budget controls, cost management, and financial risk mitigation.',
505
- budgetControls: {
506
- totalAlerts: budgetAlerts.length,
507
- byType: this.rowsToMap(budgetByType, 'alert_type', 'cnt'),
508
- recentAlerts: budgetAlerts.slice(0, 50).map((b: any) => ({
509
- id: b.id, agentId: b.agent_id, alertType: b.alert_type,
510
- threshold: b.threshold, currentValue: b.current_value,
511
- message: b.message, timestamp: b.created_at,
512
- })),
513
- },
514
- };
515
-
516
- // ═══════════════════════════════════════════════
517
- // EXECUTIVE SUMMARY
518
- // ═══════════════════════════════════════════════
519
-
520
- data.executiveSummary = {
521
- title: 'Executive Summary',
522
- reportingPeriod: dateRange,
523
- overallRiskScore: data.cc3_riskAssessment.riskScore,
524
- keyMetrics: {
525
- totalAgents: agents.length,
526
- totalToolExecutions: totalToolCalls,
527
- totalInterventions: interventions.length,
528
- totalDLPViolations: dlpViolations.length,
529
- totalApprovalRequests: approvals.length,
530
- approvalRate: data.cc5_controlActivities.approvalWorkflows.approvalRate,
531
- totalJournalActions: journalActions.length,
532
- journalReversalRate: data.cc8_changeManagement.actionJournal.reversalRate,
533
- totalBudgetAlerts: budgetAlerts.length,
534
- activeDLPRules: dlpRules.filter((r: any) => r.enabled).length,
535
- activeGuardrailRules: guardrailRules.filter((r: any) => r.enabled).length,
536
- activePolicies: policies.filter((p: any) => p.enabled).length,
537
- },
538
- controlEffectiveness: {
539
- dlpBlockRate: dlpViolations.length > 0 ? ((dlpViolations.filter((v: any) => v.action_taken === 'blocked').length / dlpViolations.length) * 100).toFixed(1) + '%' : 'N/A',
540
- guardrailCoverage: `${guardrailRules.length} rules active`,
541
- permissionCoverage: `${permProfiles.length} profiles configured`,
542
- vaultSecrets: `${vaultEntries.length} secrets managed`,
543
- },
544
- findings: this.generateFindings(data),
545
- };
546
-
547
- report.data = data;
548
- report.status = 'completed';
549
- report.completedAt = new Date().toISOString();
550
- } catch (err: any) {
551
- report.status = 'failed';
552
- report.error = err.message;
553
- }
554
-
555
- this.persistReport(report);
556
- return report;
557
- }
558
-
559
- // ─── GDPR Report (Art. 15 DSAR) ──────────────────
560
-
561
- async generateGDPR(orgId: string, agentId: string, generatedBy: string): Promise<ComplianceReport> {
562
- const report = this.createReport(orgId, 'gdpr', `GDPR Data Subject Access Report — Agent ${agentId}`, { agentId }, generatedBy);
563
-
564
- try {
565
- const data: Record<string, any> = {
566
- reportMetadata: {
567
- framework: 'GDPR Article 15 — Right of Access',
568
- dataSubject: agentId,
569
- generatedAt: new Date().toISOString(),
570
- generatedBy,
571
- orgId,
572
- organization: await this.resolveOrgName(orgId),
573
- },
574
- _orgName: await this.resolveOrgName(orgId),
575
- };
576
-
577
- if (this.engineDb) {
578
- // Agent config (data controller records)
579
- const agent = await this.q('SELECT * FROM managed_agents WHERE id = ? AND org_id = ?', [agentId, orgId]);
580
- data.agentProfile = agent[0] ? { id: agent[0].id, config: sj(agent[0].config), status: agent[0].status, createdAt: agent[0].created_at } : null;
581
-
582
- // All tool calls (processing records)
583
- data.toolCalls = await this.q('SELECT * FROM tool_calls WHERE org_id = ? AND agent_id = ? ORDER BY created_at DESC', [orgId, agentId]);
584
- data.toolCallCount = data.toolCalls.length;
585
-
586
- // Activity events
587
- data.activityEvents = await this.q('SELECT * FROM activity_events WHERE org_id = ? AND agent_id = ? ORDER BY created_at DESC', [orgId, agentId]);
588
-
589
- // Conversations
590
- data.conversations = await this.q('SELECT * FROM conversations WHERE org_id = ? AND agent_id = ? ORDER BY created_at DESC', [orgId, agentId]);
591
-
592
- // Messages sent/received
593
- data.messages = await this.q('SELECT * FROM agent_messages WHERE org_id = ? AND (from_agent_id = ? OR to_agent_id = ?) ORDER BY created_at DESC', [orgId, agentId, agentId]);
594
-
595
- // Journal entries (actions taken)
596
- data.journalEntries = await this.q('SELECT * FROM action_journal WHERE org_id = ? AND agent_id = ? ORDER BY created_at DESC', [orgId, agentId]);
597
-
598
- // Interventions (restrictions applied)
599
- data.interventions = await this.q('SELECT * FROM interventions WHERE org_id = ? AND agent_id = ? ORDER BY created_at DESC', [orgId, agentId]);
600
-
601
- // Approval requests
602
- data.approvalRequests = await this.q('SELECT * FROM approval_requests WHERE org_id = ? AND agent_id = ? ORDER BY created_at DESC', [orgId, agentId]);
603
-
604
- // DLP violations
605
- data.dlpViolations = await this.q('SELECT * FROM dlp_violations WHERE org_id = ? AND agent_id = ? ORDER BY created_at DESC', [orgId, agentId]);
606
-
607
- // Memory (stored knowledge)
608
- data.memories = await this.q('SELECT * FROM agent_memory WHERE org_id = ? AND agent_id = ? ORDER BY created_at DESC', [orgId, agentId]);
609
-
610
- // Sessions
611
- data.sessions = await this.q('SELECT * FROM agent_sessions WHERE org_id = ? AND agent_id = ? ORDER BY created_at DESC LIMIT 200', [orgId, agentId]);
612
-
613
- // Vault accesses
614
- data.vaultAccesses = await this.q('SELECT * FROM vault_audit_log WHERE org_id = ? AND agent_id = ? ORDER BY created_at DESC', [orgId, agentId]);
615
-
616
- // Escalations
617
- data.escalations = await this.q('SELECT * FROM agent_escalations WHERE org_id = ? AND agent_id = ? ORDER BY created_at DESC', [orgId, agentId]);
618
-
619
- // Budget alerts
620
- data.budgetAlerts = await this.q('SELECT * FROM budget_alerts WHERE org_id = ? AND agent_id = ? ORDER BY created_at DESC', [orgId, agentId]);
621
-
622
- data.dataSummary = {
623
- toolCalls: data.toolCalls.length,
624
- activityEvents: data.activityEvents.length,
625
- conversations: data.conversations.length,
626
- messages: data.messages.length,
627
- journalEntries: data.journalEntries.length,
628
- interventions: data.interventions.length,
629
- approvalRequests: data.approvalRequests.length,
630
- dlpViolations: data.dlpViolations.length,
631
- memories: data.memories.length,
632
- sessions: data.sessions.length,
633
- vaultAccesses: data.vaultAccesses.length,
634
- escalations: data.escalations.length,
635
- budgetAlerts: data.budgetAlerts.length,
636
- };
637
- }
638
-
639
- report.data = data;
640
- report.status = 'completed';
641
- report.completedAt = new Date().toISOString();
642
- } catch (err: any) {
643
- report.status = 'failed';
644
- report.error = err.message;
645
- }
646
-
647
- this.persistReport(report);
648
- return report;
649
- }
650
-
651
- // ─── Audit Report ─────────────────────────────────
652
-
653
- async generateAudit(orgId: string, dateRange: DateRange, generatedBy: string, agentIds?: string[]): Promise<ComplianceReport> {
654
- const report = this.createReport(orgId, 'audit', `Comprehensive Audit Trail — ${dateRange.from} to ${dateRange.to}`, { dateRange, agentIds }, generatedBy);
655
- const { from, to } = dateRange;
656
-
657
- try {
658
- const data: Record<string, any> = {
659
- reportMetadata: { framework: 'SOX-Ready Audit Trail', reportingPeriod: dateRange, generatedAt: new Date().toISOString(), generatedBy, orgId },
660
- _orgName: await this.resolveOrgName(orgId),
661
- };
662
- data.reportMetadata.organization = data._orgName;
663
-
664
- // Build unified timeline from ALL auditable tables
665
- const timeline: any[] = [];
666
-
667
- const tools = await this.q('SELECT * FROM tool_calls WHERE org_id = ? AND created_at BETWEEN ? AND ? ORDER BY created_at', [orgId, from, to]);
668
- for (const t of tools) {
669
- if (agentIds?.length && !agentIds.includes(t.agent_id)) continue;
670
- timeline.push({ timestamp: t.created_at, source: 'tool_call', category: 'execution', agentId: t.agent_id, detail: `Tool: ${t.tool_name || t.tool_id}`, success: t.success !== false, data: { toolId: t.tool_id, toolName: t.tool_name, parameters: sj(t.parameters), sessionId: t.session_id } });
671
- }
672
-
673
- const ints = await this.q('SELECT * FROM interventions WHERE org_id = ? AND created_at BETWEEN ? AND ? ORDER BY created_at', [orgId, from, to]);
674
- for (const i of ints) {
675
- if (agentIds?.length && !agentIds.includes(i.agent_id)) continue;
676
- timeline.push({ timestamp: i.created_at, source: 'intervention', category: 'control', agentId: i.agent_id, detail: i.reason, data: { type: i.type, action: i.action, ruleId: i.rule_id, toolId: i.tool_id } });
677
- }
678
-
679
- const dlps = await this.q('SELECT * FROM dlp_violations WHERE org_id = ? AND created_at BETWEEN ? AND ? ORDER BY created_at', [orgId, from, to]);
680
- for (const d of dlps) {
681
- if (agentIds?.length && !agentIds.includes(d.agent_id)) continue;
682
- timeline.push({ timestamp: d.created_at, source: 'dlp_violation', category: 'security', agentId: d.agent_id, detail: `DLP ${d.action_taken}: Rule ${d.rule_id}`, data: { ruleId: d.rule_id, actionTaken: d.action_taken, direction: d.direction, matchContext: d.match_context } });
683
- }
684
-
685
- const approvals = await this.q('SELECT * FROM approval_requests WHERE org_id = ? AND created_at BETWEEN ? AND ? ORDER BY created_at', [orgId, from, to]);
686
- for (const a of approvals) {
687
- if (agentIds?.length && !agentIds.includes(a.agent_id)) continue;
688
- timeline.push({ timestamp: a.created_at, source: 'approval_request', category: 'control', agentId: a.agent_id, detail: `Approval ${a.status}: ${a.tool_id}`, data: { status: a.status, toolId: a.tool_id, resolvedBy: a.resolved_by, resolvedAt: a.resolved_at } });
689
- }
690
-
691
- const journal = await this.q('SELECT * FROM action_journal WHERE org_id = ? AND created_at BETWEEN ? AND ? ORDER BY created_at', [orgId, from, to]);
692
- for (const j of journal) {
693
- if (agentIds?.length && !agentIds.includes(j.agent_id)) continue;
694
- timeline.push({ timestamp: j.created_at, source: 'journal_action', category: 'change', agentId: j.agent_id, detail: `${j.action_type}: ${j.tool_name || j.tool_id}${j.reversed ? ' [REVERSED]' : ''}`, data: { actionType: j.action_type, toolId: j.tool_id, reversible: !!j.reversible, reversed: !!j.reversed, reversedAt: j.reversed_at, reversedBy: j.reversed_by } });
695
- }
696
-
697
- const budgets = await this.q('SELECT * FROM budget_alerts WHERE org_id = ? AND created_at BETWEEN ? AND ? ORDER BY created_at', [orgId, from, to]);
698
- for (const b of budgets) {
699
- if (agentIds?.length && !agentIds.includes(b.agent_id)) continue;
700
- timeline.push({ timestamp: b.created_at, source: 'budget_alert', category: 'financial', agentId: b.agent_id, detail: `${b.alert_type}: ${b.message}`, data: { alertType: b.alert_type, threshold: b.threshold, currentValue: b.current_value } });
701
- }
702
-
703
- const vaultLogs = await this.q('SELECT * FROM vault_audit_log WHERE org_id = ? AND created_at BETWEEN ? AND ? ORDER BY created_at', [orgId, from, to]);
704
- for (const v of vaultLogs) {
705
- timeline.push({ timestamp: v.created_at, source: 'vault_access', category: 'access', agentId: v.agent_id, detail: `Vault ${v.action}: ${v.key}`, data: { action: v.action, key: v.key } });
706
- }
707
-
708
- timeline.sort((a, b) => String(a.timestamp || '').localeCompare(String(b.timestamp || '')));
709
- data.timeline = timeline;
710
-
711
- // Summary statistics
712
- data.summary = {
713
- totalEvents: timeline.length,
714
- bySource: {} as Record<string, number>,
715
- byCategory: {} as Record<string, number>,
716
- byAgent: {} as Record<string, number>,
717
- byDay: {} as Record<string, number>,
718
- };
719
- for (const e of timeline) {
720
- data.summary.bySource[e.source] = (data.summary.bySource[e.source] || 0) + 1;
721
- data.summary.byCategory[e.category] = (data.summary.byCategory[e.category] || 0) + 1;
722
- data.summary.byAgent[e.agentId] = (data.summary.byAgent[e.agentId] || 0) + 1;
723
- const day = String(e.timestamp || '').substring(0, 10);
724
- if (day) data.summary.byDay[day] = (data.summary.byDay[day] || 0) + 1;
725
- }
726
-
727
- report.data = data;
728
- report.status = 'completed';
729
- report.completedAt = new Date().toISOString();
730
- } catch (err: any) {
731
- report.status = 'failed';
732
- report.error = err.message;
733
- }
734
-
735
- this.persistReport(report);
736
- return report;
737
- }
738
-
739
- // ─── Incident Report ──────────────────────────────
740
-
741
- async generateIncident(orgId: string, dateRange: DateRange, generatedBy: string): Promise<ComplianceReport> {
742
- const report = this.createReport(orgId, 'incident', `Security Incident Report — ${dateRange.from} to ${dateRange.to}`, { dateRange }, generatedBy);
743
- const { from, to } = dateRange;
744
-
745
- try {
746
- const data: Record<string, any> = {
747
- reportMetadata: { framework: 'Incident Response Report', reportingPeriod: dateRange, generatedAt: new Date().toISOString(), generatedBy, orgId },
748
- _orgName: await this.resolveOrgName(orgId),
749
- };
750
- data.reportMetadata.organization = data._orgName;
751
-
752
- // All security-relevant events
753
- data.dlpViolations = await this.q('SELECT * FROM dlp_violations WHERE org_id = ? AND created_at BETWEEN ? AND ? ORDER BY created_at DESC', [orgId, from, to]);
754
- data.interventions = await this.q('SELECT * FROM interventions WHERE org_id = ? AND created_at BETWEEN ? AND ? ORDER BY created_at DESC', [orgId, from, to]);
755
- data.securityEvents = await this.q('SELECT * FROM security_events WHERE org_id = ? AND created_at BETWEEN ? AND ? ORDER BY created_at DESC', [orgId, from, to]);
756
- data.blockedApprovals = await this.q("SELECT * FROM approval_requests WHERE org_id = ? AND status = 'denied' AND created_at BETWEEN ? AND ? ORDER BY created_at DESC", [orgId, from, to]);
757
- data.escalations = await this.q('SELECT * FROM agent_escalations WHERE org_id = ? AND created_at BETWEEN ? AND ? ORDER BY created_at DESC', [orgId, from, to]);
758
- data.budgetBreaches = await this.q("SELECT * FROM budget_alerts WHERE org_id = ? AND alert_type IN ('budget_exceeded', 'rate_limit') AND created_at BETWEEN ? AND ? ORDER BY created_at DESC", [orgId, from, to]);
759
- data.reversedActions = await this.q("SELECT * FROM action_journal WHERE org_id = ? AND (reversed = true OR reversed = 1) AND created_at BETWEEN ? AND ? ORDER BY created_at DESC", [orgId, from, to]);
760
-
761
- data.incidentSummary = {
762
- totalIncidents: (data.dlpViolations?.length || 0) + (data.securityEvents?.length || 0) + (data.blockedApprovals?.length || 0),
763
- dlpViolations: data.dlpViolations?.length || 0,
764
- interventions: data.interventions?.length || 0,
765
- securityEvents: data.securityEvents?.length || 0,
766
- deniedApprovals: data.blockedApprovals?.length || 0,
767
- escalations: data.escalations?.length || 0,
768
- budgetBreaches: data.budgetBreaches?.length || 0,
769
- reversedActions: data.reversedActions?.length || 0,
770
- };
771
-
772
- report.data = data;
773
- report.status = 'completed';
774
- report.completedAt = new Date().toISOString();
775
- } catch (err: any) {
776
- report.status = 'failed';
777
- report.error = err.message;
778
- }
779
-
780
- this.persistReport(report);
781
- return report;
782
- }
783
-
784
- // ─── Access Review Report ─────────────────────────
785
-
786
- async generateAccessReview(orgId: string, generatedBy: string): Promise<ComplianceReport> {
787
- const report = this.createReport(orgId, 'access-review', `Access Review Report — ${new Date().toISOString().split('T')[0]}`, {}, generatedBy);
788
-
789
- try {
790
- const data: Record<string, any> = {
791
- reportMetadata: { framework: 'Periodic Access Review', generatedAt: new Date().toISOString(), generatedBy, orgId },
792
- _orgName: await this.resolveOrgName(orgId),
793
- };
794
- data.reportMetadata.organization = data._orgName;
795
-
796
- const agents = await this.q('SELECT * FROM managed_agents WHERE org_id = ?', [orgId]);
797
- const permProfiles = await this.q('SELECT * FROM permission_profiles WHERE org_id = ?', [orgId]);
798
- const vaultEntries = await this.q('SELECT id, key, agent_id, created_at, updated_at, expires_at FROM vault_entries WHERE org_id = ?', [orgId]);
799
- const approvalPolicies = await this.q('SELECT * FROM approval_policies WHERE org_id = ?', [orgId]);
800
-
801
- data.agentAccess = agents.map((a: any) => {
802
- const config = sj(a.config);
803
- const vaultSecrets = vaultEntries.filter((v: any) => v.agent_id === a.id);
804
- return {
805
- agentId: a.id,
806
- name: config?.displayName || config?.name || a.id,
807
- status: a.status,
808
- role: config?.identity?.role || 'agent',
809
- permissionProfile: config?.permissionProfile || 'default',
810
- model: config?.model,
811
- hasBudget: !!a.budget_config,
812
- vaultSecrets: vaultSecrets.length,
813
- expiredSecrets: vaultSecrets.filter((v: any) => v.expires_at && new Date(v.expires_at) < new Date()).length,
814
- channels: Object.keys(config?.messagingChannels || config?.channels || {}).length,
815
- tools: config?.deployment?.tools ? Object.keys(config.deployment.tools).length : 'default',
816
- createdAt: a.created_at,
817
- lastActivity: a.updated_at,
818
- };
819
- });
820
-
821
- data.permissionProfiles = permProfiles.map((p: any) => ({
822
- id: p.id, name: p.name, preset: p.preset, description: p.description,
823
- assignedAgents: agents.filter((a: any) => sj(a.config)?.permissionProfile === p.name).length,
824
- }));
825
-
826
- data.vaultReview = {
827
- totalSecrets: vaultEntries.length,
828
- expiredSecrets: vaultEntries.filter((v: any) => v.expires_at && new Date(v.expires_at) < new Date()).length,
829
- secretsWithoutExpiry: vaultEntries.filter((v: any) => !v.expires_at).length,
830
- };
831
-
832
- data.approvalPolicies = approvalPolicies.map((p: any) => ({
833
- id: p.id, name: p.name, toolPattern: p.tool_pattern,
834
- requireApproval: !!p.require_approval, autoApprove: !!p.auto_approve,
835
- }));
836
-
837
- data.recommendations = [];
838
- if (data.vaultReview.expiredSecrets > 0) data.recommendations.push({ severity: 'high', message: `${data.vaultReview.expiredSecrets} vault secrets have expired and should be rotated.` });
839
- if (data.vaultReview.secretsWithoutExpiry > 0) data.recommendations.push({ severity: 'medium', message: `${data.vaultReview.secretsWithoutExpiry} vault secrets have no expiration set.` });
840
- for (const a of data.agentAccess) {
841
- if (a.status !== 'active' && a.vaultSecrets > 0) data.recommendations.push({ severity: 'high', message: `Non-active agent "${a.name}" still has ${a.vaultSecrets} vault secrets.` });
842
- if (a.permissionProfile === 'default') data.recommendations.push({ severity: 'low', message: `Agent "${a.name}" uses default permission profile — consider assigning a specific profile.` });
843
- }
844
-
845
- report.data = data;
846
- report.status = 'completed';
847
- report.completedAt = new Date().toISOString();
848
- } catch (err: any) {
849
- report.status = 'failed';
850
- report.error = err.message;
851
- }
852
-
853
- this.persistReport(report);
854
- return report;
855
- }
856
-
857
- // ─── Query ────────────────────────────────────────
858
-
859
- getReports(opts?: { orgId?: string; type?: string; limit?: number }): ComplianceReport[] {
860
- let list = [...this.reports];
861
- if (opts?.orgId) list = list.filter(r => r.orgId === opts.orgId);
862
- if (opts?.type) list = list.filter(r => r.type === opts.type);
863
- return list.slice(0, opts?.limit || 50);
864
- }
865
-
866
- getReport(id: string): ComplianceReport | undefined {
867
- return this.reports.find(r => r.id === id);
868
- }
869
-
870
- deleteReport(id: string): boolean {
871
- const idx = this.reports.findIndex(r => r.id === id);
872
- if (idx === -1) return false;
873
- this.reports.splice(idx, 1);
874
- this.engineDb?.execute('DELETE FROM compliance_reports WHERE id = ?', [id]).catch(() => {});
875
- return true;
876
- }
877
-
878
- // ─── CSV Export (SOC 2 Grade) ─────────────────────
879
-
880
- toCSV(report: ComplianceReport): string {
881
- if (!report.data) return '';
882
-
883
- if (report.type === 'soc2') return this.soc2ToCSV(report.data);
884
- if (report.type === 'audit') return this.auditToCSV(report.data);
885
- if (report.type === 'gdpr') return this.gdprToCSV(report.data);
886
- if (report.type === 'incident') return this.incidentToCSV(report.data);
887
- if (report.type === 'access-review') return this.accessReviewToCSV(report.data);
888
-
889
- // Fallback: flatten
890
- const flat = this.flattenObject(report.data);
891
- return 'key,value\n' + Object.entries(flat).map(([k, v]) => `${k},"${String(v).replace(/"/g, '""')}"`).join('\n');
892
- }
893
-
894
- private soc2ToCSV(data: any): string {
895
- const sheets: string[] = [];
896
-
897
- // Sheet 1: Executive Summary
898
- sheets.push('=== EXECUTIVE SUMMARY ===');
899
- sheets.push('Metric,Value');
900
- const km = data.executiveSummary?.keyMetrics || {};
901
- for (const [k, v] of Object.entries(km)) sheets.push(`${k},"${v}"`);
902
- sheets.push('');
903
-
904
- // Sheet 2: Agent Inventory
905
- sheets.push('=== AGENT INVENTORY (CC1) ===');
906
- sheets.push('Agent ID,Name,Status,Role,Model,Permission Profile,Has Budget,Created At');
907
- for (const a of data.cc1_controlEnvironment?.agentInventory?.agents || []) {
908
- sheets.push(`${a.id},"${a.name}",${a.status},"${a.role}","${a.model || ''}","${a.permissionProfile}",${a.hasBudgetConfig},${a.createdAt}`);
909
- }
910
- sheets.push('');
911
-
912
- // Sheet 3: Policies
913
- sheets.push('=== GOVERNANCE POLICIES (CC1) ===');
914
- sheets.push('Policy ID,Name,Category,Enforcement,Enabled,Priority,Created At');
915
- for (const p of data.cc1_controlEnvironment?.governancePolicies?.policies || []) {
916
- sheets.push(`${p.id},"${p.name}",${p.category},${p.enforcement},${p.enabled},${p.priority},${p.createdAt}`);
917
- }
918
- sheets.push('');
919
-
920
- // Sheet 4: Tool Calls
921
- sheets.push('=== TOOL CALL VOLUME (CC2) ===');
922
- sheets.push('Date,Count');
923
- for (const d of data.cc2_communicationInformation?.auditTrail?.toolCalls?.dailyVolume || []) {
924
- sheets.push(`${d.date},${d.count}`);
925
- }
926
- sheets.push('');
927
-
928
- // Sheet 5: Top Tools
929
- sheets.push('=== TOP TOOLS BY USAGE (CC2) ===');
930
- sheets.push('Tool ID,Tool Name,Executions,Failures');
931
- for (const t of data.cc2_communicationInformation?.auditTrail?.toolCalls?.topTools || []) {
932
- sheets.push(`"${t.toolId}","${t.toolName || ''}",${t.executions},${t.failures}`);
933
- }
934
- sheets.push('');
935
-
936
- // Sheet 6: DLP Rules
937
- sheets.push('=== DLP RULES (CC3) ===');
938
- sheets.push('Rule ID,Name,Pattern Type,Action,Severity,Enabled,Applies To');
939
- for (const r of data.cc3_riskAssessment?.dlpControls?.rules || []) {
940
- sheets.push(`${r.id},"${r.name}",${r.patternType},${r.action},${r.severity},${r.enabled},${r.appliesTo}`);
941
- }
942
- sheets.push('');
943
-
944
- // Sheet 7: DLP Violations
945
- sheets.push('=== DLP VIOLATIONS (CC3) ===');
946
- sheets.push('Violation ID,Agent ID,Rule ID,Tool ID,Action Taken,Direction,Match Context,Timestamp');
947
- for (const v of data.cc3_riskAssessment?.dlpViolations?.recentViolations || []) {
948
- sheets.push(`${v.id},${v.agentId},${v.ruleId},"${v.toolId || ''}",${v.actionTaken},${v.direction},"${(v.matchContext || '').replace(/"/g, '""')}",${v.timestamp}`);
949
- }
950
- sheets.push('');
951
-
952
- // Sheet 8: Interventions
953
- sheets.push('=== GUARDRAIL INTERVENTIONS (CC4) ===');
954
- sheets.push('Intervention ID,Agent ID,Type,Reason,Action,Rule ID,Tool ID,Timestamp');
955
- for (const i of data.cc4_monitoringActivities?.interventions?.recentInterventions || []) {
956
- sheets.push(`${i.id},${i.agentId},"${i.type}","${(i.reason || '').replace(/"/g, '""')}","${i.action || ''}","${i.ruleId || ''}","${i.toolId || ''}",${i.timestamp}`);
957
- }
958
- sheets.push('');
959
-
960
- // Sheet 9: Approval Requests
961
- sheets.push('=== APPROVAL REQUESTS (CC5) ===');
962
- sheets.push('Request ID,Agent ID,Tool ID,Status,Requested At,Resolved At,Resolved By,Reason');
963
- for (const a of data.cc5_controlActivities?.approvalWorkflows?.recentRequests || []) {
964
- sheets.push(`${a.id},${a.agentId},"${a.toolId || ''}",${a.status},${a.requestedAt},${a.resolvedAt || ''},"${a.resolvedBy || ''}","${(a.reason || '').replace(/"/g, '""')}"`);
965
- }
966
- sheets.push('');
967
-
968
- // Sheet 10: Vault Audit
969
- sheets.push('=== VAULT ACCESS LOG (CC6) ===');
970
- sheets.push('ID,Action,Key,Agent ID,IP Address,Timestamp');
971
- for (const v of data.cc6_logicalAccess?.vaultManagement?.auditLog?.recentAccesses || []) {
972
- sheets.push(`${v.id},${v.action},"${v.key}",${v.agentId},"${v.ip || ''}",${v.timestamp}`);
973
- }
974
- sheets.push('');
975
-
976
- // Sheet 11: Action Journal
977
- sheets.push('=== ACTION JOURNAL (CC8) ===');
978
- sheets.push('Journal ID,Agent ID,Tool Name,Action Type,Reversible,Reversed,Reversed At,Reversed By,Session ID,Timestamp');
979
- for (const j of data.cc8_changeManagement?.actionJournal?.recentActions || []) {
980
- sheets.push(`${j.id},${j.agentId},"${j.toolName || ''}","${j.actionType}",${j.reversible},${j.reversed},${j.reversedAt || ''},${j.reversedBy || ''},${j.sessionId || ''},${j.timestamp}`);
981
- }
982
- sheets.push('');
983
-
984
- // Sheet 12: Budget Alerts
985
- sheets.push('=== BUDGET ALERTS (CC9) ===');
986
- sheets.push('ID,Agent ID,Alert Type,Threshold,Current Value,Message,Timestamp');
987
- for (const b of data.cc9_riskMitigation?.budgetControls?.recentAlerts || []) {
988
- sheets.push(`${b.id},${b.agentId},"${b.alertType}",${b.threshold || ''},${b.currentValue || ''},"${(b.message || '').replace(/"/g, '""')}",${b.timestamp}`);
989
- }
990
- sheets.push('');
991
-
992
- // Sheet 13: Risk Score & Findings
993
- sheets.push('=== RISK ASSESSMENT ===');
994
- sheets.push('Category,Score');
995
- const rs = data.cc3_riskAssessment?.riskScore || {};
996
- for (const [k, v] of Object.entries(rs)) sheets.push(`"${k}","${v}"`);
997
- sheets.push('');
998
- sheets.push('=== FINDINGS ===');
999
- sheets.push('Severity,Category,Finding');
1000
- for (const f of data.executiveSummary?.findings || []) sheets.push(`${f.severity},"${f.category || ''}","${(f.message || '').replace(/"/g, '""')}"`);
1001
-
1002
- return sheets.join('\n');
1003
- }
1004
-
1005
- private auditToCSV(data: any): string {
1006
- const rows = data.timeline || [];
1007
- const header = 'Timestamp,Source,Category,Agent ID,Detail,Success,Data';
1008
- const lines = rows.map((r: any) =>
1009
- `${r.timestamp},${r.source},${r.category},${r.agentId},"${(r.detail || '').replace(/"/g, '""')}",${r.success ?? ''},"${JSON.stringify(r.data || {}).replace(/"/g, '""')}"`
1010
- );
1011
- return header + '\n' + lines.join('\n');
1012
- }
1013
-
1014
- private gdprToCSV(data: any): string {
1015
- const sheets: string[] = [];
1016
- sheets.push('=== GDPR DATA SUBJECT ACCESS REPORT ===');
1017
- sheets.push('Data Category,Record Count');
1018
- for (const [k, v] of Object.entries(data.dataSummary || {})) sheets.push(`${k},${v}`);
1019
- sheets.push('');
1020
-
1021
- // Export each data category
1022
- for (const key of ['toolCalls', 'activityEvents', 'journalEntries', 'interventions', 'approvalRequests', 'dlpViolations', 'memories']) {
1023
- const items = data[key] || [];
1024
- if (items.length === 0) continue;
1025
- sheets.push(`=== ${key.toUpperCase()} ===`);
1026
- if (items.length > 0) {
1027
- const cols = Object.keys(items[0]).filter(k => typeof items[0][k] !== 'object');
1028
- sheets.push(cols.join(','));
1029
- for (const item of items) {
1030
- sheets.push(cols.map(c => `"${String(item[c] ?? '').replace(/"/g, '""')}"`).join(','));
1031
- }
1032
- }
1033
- sheets.push('');
1034
- }
1035
- return sheets.join('\n');
1036
- }
1037
-
1038
- private incidentToCSV(data: any): string {
1039
- const sheets: string[] = [];
1040
- sheets.push('=== INCIDENT SUMMARY ===');
1041
- sheets.push('Category,Count');
1042
- for (const [k, v] of Object.entries(data.incidentSummary || {})) sheets.push(`${k},${v}`);
1043
- sheets.push('');
1044
-
1045
- for (const key of ['dlpViolations', 'interventions', 'securityEvents', 'blockedApprovals', 'escalations', 'reversedActions']) {
1046
- const items = data[key] || [];
1047
- if (items.length === 0) continue;
1048
- sheets.push(`=== ${key.toUpperCase()} ===`);
1049
- const cols = Object.keys(items[0]).filter(k => typeof items[0][k] !== 'object');
1050
- sheets.push(cols.join(','));
1051
- for (const item of items) sheets.push(cols.map(c => `"${String(item[c] ?? '').replace(/"/g, '""')}"`).join(','));
1052
- sheets.push('');
1053
- }
1054
- return sheets.join('\n');
1055
- }
1056
-
1057
- private accessReviewToCSV(data: any): string {
1058
- const sheets: string[] = [];
1059
- sheets.push('=== AGENT ACCESS REVIEW ===');
1060
- sheets.push('Agent ID,Name,Status,Role,Permission Profile,Model,Has Budget,Vault Secrets,Expired Secrets,Channels,Tools,Created At,Last Activity');
1061
- for (const a of data.agentAccess || []) {
1062
- sheets.push(`${a.agentId},"${a.name}",${a.status},"${a.role}","${a.permissionProfile}","${a.model || ''}",${a.hasBudget},${a.vaultSecrets},${a.expiredSecrets},${a.channels},${a.tools},${a.createdAt},${a.lastActivity || ''}`);
1063
- }
1064
- sheets.push('');
1065
-
1066
- sheets.push('=== VAULT REVIEW ===');
1067
- sheets.push('Metric,Value');
1068
- for (const [k, v] of Object.entries(data.vaultReview || {})) sheets.push(`${k},${v}`);
1069
- sheets.push('');
1070
-
1071
- sheets.push('=== RECOMMENDATIONS ===');
1072
- sheets.push('Severity,Recommendation');
1073
- for (const r of data.recommendations || []) sheets.push(`${r.severity},"${r.message.replace(/"/g, '""')}"`);
1074
- return sheets.join('\n');
1075
- }
1076
-
1077
- // ─── HTML Export (Full Printable Report) ───────────
1078
-
1079
- toHTML(report: ComplianceReport): string {
1080
- if (!report.data) return '<html><body><h1>No data</h1></body></html>';
1081
- const d = report.data;
1082
- const esc = (s: any) => String(s ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
1083
-
1084
- const css = `
1085
- * { margin: 0; padding: 0; box-sizing: border-box; }
1086
- body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; color: #2c2410; background: #d0c5a0; padding: 40px; max-width: 1100px; margin: 0 auto; font-size: 13px; line-height: 1.6; }
1087
- h1 { font-size: 24px; margin-bottom: 4px; color: #2c2410; }
1088
- h2 { font-size: 18px; margin: 32px 0 16px; padding-bottom: 8px; border-bottom: 2px solid #b0a47a; color: #2c2410; page-break-after: avoid; }
1089
- h3 { font-size: 14px; margin: 20px 0 8px; color: #4a3f28; }
1090
- .subtitle { color: #7a6e50; font-size: 13px; margin-bottom: 24px; }
1091
- .meta { display: flex; gap: 24px; margin-bottom: 24px; padding: 16px; background: #ddd3b2; border-radius: 8px; border: 1px solid #b0a47a; flex-wrap: wrap; }
1092
- .meta-item { font-size: 12px; }
1093
- .meta-item strong { display: block; color: #4a3f28; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
1094
- .metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-bottom: 24px; }
1095
- .metric { text-align: center; padding: 16px; background: #ddd3b2; border-radius: 8px; border: 1px solid #b0a47a; }
1096
- .metric .value { font-size: 28px; font-weight: 700; color: #2c2410; }
1097
- .metric .label { font-size: 11px; color: #7a6e50; margin-top: 4px; }
1098
- .grade { display: inline-flex; align-items: center; justify-content: center; width: 64px; height: 64px; border-radius: 50%; font-size: 32px; font-weight: 800; color: #fff; }
1099
- .grade-A { background: #22c55e; } .grade-B { background: #3b82f6; } .grade-C { background: #eab308; } .grade-D { background: #f97316; } .grade-F { background: #ef4444; }
1100
- table { width: 100%; border-collapse: collapse; margin-bottom: 16px; font-size: 12px; }
1101
- th { text-align: left; padding: 8px 12px; background: #c8bc94; border-bottom: 2px solid #b0a47a; font-weight: 600; color: #4a3f28; font-size: 11px; text-transform: uppercase; }
1102
- td { padding: 8px 12px; border-bottom: 1px solid #c4b890; vertical-align: top; }
1103
- tr:hover { background: #ddd3b2; }
1104
- .badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }
1105
- .badge-pass { background: #dcfce7; color: #166534; } .badge-high { background: #fef2f2; color: #991b1b; }
1106
- .badge-medium { background: #fefce8; color: #854d0e; } .badge-low { background: #ddd3b2; color: #4a3f28; }
1107
- .badge-info { background: #eff6ff; color: #1e40af; } .badge-critical { background: #fef2f2; color: #7f1d1d; }
1108
- .finding { padding: 12px 16px; margin-bottom: 8px; border-radius: 8px; border-left: 4px solid; }
1109
- .finding-pass { background: #f0fdf4; border-color: #22c55e; }
1110
- .finding-high { background: #fef2f2; border-color: #ef4444; }
1111
- .finding-medium { background: #fefce8; border-color: #eab308; }
1112
- .finding-low { background: #ddd3b2; border-color: #7a6e50; }
1113
- .finding-info { background: #eff6ff; border-color: #8B6914; }
1114
- .finding .cat { font-size: 11px; color: #7a6e50; margin-bottom: 2px; }
1115
- .kv { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 24px; margin-bottom: 16px; }
1116
- .kv dt { font-size: 11px; color: #7a6e50; } .kv dd { font-weight: 500; margin: 0; }
1117
- code { background: #c8bc94; padding: 1px 4px; border-radius: 3px; font-size: 11px; }
1118
- .page-break { page-break-before: always; }
1119
- @media print { body { padding: 20px; } h2 { page-break-after: avoid; } table { page-break-inside: auto; } tr { page-break-inside: avoid; } }
1120
- .toc { margin: 16px 0 32px; padding: 16px; background: #ddd3b2; border-radius: 8px; }
1121
- .toc a { color: #8B6914; text-decoration: none; } .toc a:hover { text-decoration: underline; }
1122
- .toc li { margin: 4px 0; }
1123
- `;
1124
-
1125
- const agentMap: Record<string, string> = d._agentNameMap || {};
1126
- const resolveAgent = (id: any) => {
1127
- if (!id || id === '-') return String(id ?? '-');
1128
- const name = agentMap[id];
1129
- if (name && name !== id) return `${name} (${String(id).slice(0, 8)})`;
1130
- return String(id).slice(0, 12) + (String(id).length > 12 ? '...' : '');
1131
- };
1132
- const generatedByDisplay = d._generatedByName || report.generatedBy;
1133
-
1134
- const parts: string[] = [];
1135
- parts.push(`<!DOCTYPE html><html><head><meta charset="utf-8"><title>${esc(report.title)}</title><style>${css}</style></head><body>`);
1136
-
1137
- // Header
1138
- const orgDisplay = d._orgName || report.orgId || '';
1139
- parts.push(`<h1>${esc(report.title)}</h1>`);
1140
- parts.push(`<div class="subtitle">${esc(this.typeLabel(report.type))}${orgDisplay ? ' &bull; ' + esc(orgDisplay) : ''} &bull; Generated ${new Date(report.createdAt).toLocaleString()} &bull; by ${esc(generatedByDisplay)}</div>`);
1141
-
1142
- // Metadata
1143
- const meta = d.reportMetadata || {};
1144
- parts.push(`<div class="meta">`);
1145
- for (const [k, v] of Object.entries(meta)) {
1146
- if (typeof v === 'object') continue;
1147
- parts.push(`<div class="meta-item"><strong>${esc(k)}</strong>${esc(v)}</div>`);
1148
- }
1149
- parts.push(`</div>`);
1150
-
1151
- if (report.type === 'soc2') {
1152
- parts.push(this.soc2ToHTML(d, esc, resolveAgent));
1153
- } else if (report.type === 'audit') {
1154
- parts.push(this.auditToHTML(d, esc, resolveAgent));
1155
- } else if (report.type === 'gdpr') {
1156
- parts.push(this.gdprToHTML(d, esc, resolveAgent));
1157
- } else if (report.type === 'incident') {
1158
- parts.push(this.incidentToHTML(d, esc, resolveAgent));
1159
- } else if (report.type === 'access-review') {
1160
- parts.push(this.accessReviewToHTML(d, esc, resolveAgent));
1161
- } else {
1162
- parts.push(`<pre>${esc(JSON.stringify(d, null, 2))}</pre>`);
1163
- }
1164
-
1165
- parts.push(`<div style="margin-top: 40px; padding-top: 16px; border-top: 1px solid #b0a47a; color: #7a6e50; font-size: 11px; text-align: center;">Generated by AgenticMail Enterprise Compliance Engine &bull; Report ID: ${esc(report.id)} &bull; ${new Date().toISOString()}</div>`);
1166
- parts.push(`</body></html>`);
1167
- return parts.join('\n');
1168
- }
1169
-
1170
- private async resolveOrgName(orgId: string): Promise<string> {
1171
- try {
1172
- const org = await this.q('SELECT name FROM organizations WHERE id = ?', [orgId]);
1173
- return org[0]?.name || orgId;
1174
- } catch { return orgId; }
1175
- }
1176
-
1177
- private typeLabel(type: string): string {
1178
- return ({ soc2: 'SOC 2 Type II Report', gdpr: 'GDPR Data Subject Access Report (Article 15)', audit: 'SOX-Ready Audit Trail', incident: 'Security Incident Report', 'access-review': 'Periodic Access Review Report' } as any)[type] || type;
1179
- }
1180
-
1181
- private htmlTable(rows: any[], columns: { key: string; label: string }[], esc: (s: any) => string, resolveAgent?: (id: any) => string): string {
1182
- if (!rows?.length) return '<p style="color:#94a3b8">No records.</p>';
1183
- const agentKeys = new Set(['agentId', 'agent_id', 'resolvedBy', 'changedBy', 'reversed_by', 'reversedBy']);
1184
- let html = '<table><thead><tr>';
1185
- for (const c of columns) html += `<th>${esc(c.label)}</th>`;
1186
- html += '</tr></thead><tbody>';
1187
- for (const row of rows.slice(0, 500)) {
1188
- html += '<tr>';
1189
- for (const c of columns) {
1190
- let v = row[c.key];
1191
- if (typeof v === 'boolean') v = v ? 'Yes' : 'No';
1192
- if (resolveAgent && agentKeys.has(c.key) && v && v !== '-') v = resolveAgent(v);
1193
- html += `<td>${esc(v)}</td>`;
1194
- }
1195
- html += '</tr>';
1196
- }
1197
- html += '</tbody></table>';
1198
- if (rows.length > 500) html += `<p style="color:#94a3b8;font-size:11px">${rows.length - 500} more rows not shown.</p>`;
1199
- return html;
1200
- }
1201
-
1202
- private htmlKV(obj: Record<string, any>, esc: (s: any) => string): string {
1203
- const entries = Object.entries(obj || {});
1204
- if (!entries.length) return '';
1205
- let html = '<dl class="kv">';
1206
- for (const [k, v] of entries) html += `<dt>${esc(k)}</dt><dd>${esc(v)}</dd>`;
1207
- html += '</dl>';
1208
- return html;
1209
- }
1210
-
1211
- private htmlMetrics(obj: Record<string, any>, esc: (s: any) => string): string {
1212
- let html = '<div class="metrics">';
1213
- for (const [k, v] of Object.entries(obj || {})) {
1214
- const label = k.replace(/([A-Z])/g, ' $1').replace(/^./, s => s.toUpperCase());
1215
- html += `<div class="metric"><div class="value">${esc(v)}</div><div class="label">${esc(label)}</div></div>`;
1216
- }
1217
- html += '</div>';
1218
- return html;
1219
- }
1220
-
1221
- private soc2ToHTML(d: any, esc: (s: any) => string, resolveAgent?: (id: any) => string): string {
1222
- const p: string[] = [];
1223
- const km = d.executiveSummary?.keyMetrics || {};
1224
- const risk = d.cc3_riskAssessment?.riskScore || {};
1225
- const findings = d.executiveSummary?.findings || [];
1226
-
1227
- // TOC
1228
- p.push(`<div class="toc"><strong>Table of Contents</strong><ol>`);
1229
- p.push(`<li><a href="#exec">Executive Summary</a></li>`);
1230
- for (let i = 1; i <= 9; i++) p.push(`<li><a href="#cc${i}">CC${i}: ${this.ccTitle(i)}</a></li>`);
1231
- p.push(`<li><a href="#findings">Findings & Recommendations</a></li>`);
1232
- p.push(`</ol></div>`);
1233
-
1234
- // Executive Summary
1235
- p.push(`<h2 id="exec">Executive Summary</h2>`);
1236
- p.push(this.htmlMetrics(km, esc));
1237
- p.push(`<div style="display:flex;align-items:center;gap:16px;margin:16px 0"><div class="grade grade-${risk.grade || 'F'}">${risk.grade || '-'}</div><div><strong>Risk Score: ${risk.score ?? '-'}/100</strong>`);
1238
- for (const dd of risk.deductions || []) p.push(`<br><span style="font-size:12px;color:#64748b">-${dd.points} ${esc(dd.reason)}</span>`);
1239
- p.push(`</div></div>`);
1240
-
1241
- // CC1-CC9
1242
- const sections = [
1243
- { key: 'cc1_controlEnvironment', tables: [
1244
- { path: 'agentInventory.agents', label: 'Agent Inventory', cols: [{ key: 'name', label: 'Name' }, { key: 'status', label: 'Status' }, { key: 'role', label: 'Role' }, { key: 'model', label: 'Model' }, { key: 'permissionProfile', label: 'Permission Profile' }, { key: 'hasBudgetConfig', label: 'Budget' }] },
1245
- { path: 'governancePolicies.policies', label: 'Governance Policies', cols: [{ key: 'name', label: 'Name' }, { key: 'category', label: 'Category' }, { key: 'enforcement', label: 'Enforcement' }, { key: 'enabled', label: 'Enabled' }] },
1246
- { path: 'permissionProfiles.profiles', label: 'Permission Profiles', cols: [{ key: 'name', label: 'Name' }, { key: 'preset', label: 'Preset' }, { key: 'description', label: 'Description' }] },
1247
- ]},
1248
- { key: 'cc2_communicationInformation', tables: [
1249
- { path: 'auditTrail.toolCalls.topTools', label: 'Top Tools by Usage', cols: [{ key: 'toolName', label: 'Tool' }, { key: 'executions', label: 'Executions' }, { key: 'failures', label: 'Failures' }] },
1250
- { path: 'auditTrail.toolCalls.dailyVolume', label: 'Daily Tool Call Volume', cols: [{ key: 'date', label: 'Date' }, { key: 'count', label: 'Count' }] },
1251
- ]},
1252
- { key: 'cc3_riskAssessment', tables: [
1253
- { path: 'dlpControls.rules', label: 'DLP Rules', cols: [{ key: 'name', label: 'Name' }, { key: 'patternType', label: 'Type' }, { key: 'action', label: 'Action' }, { key: 'severity', label: 'Severity' }, { key: 'enabled', label: 'Enabled' }] },
1254
- { path: 'dlpViolations.recentViolations', label: 'DLP Violations', cols: [{ key: 'agentId', label: 'Agent' }, { key: 'ruleId', label: 'Rule' }, { key: 'actionTaken', label: 'Action' }, { key: 'direction', label: 'Direction' }, { key: 'timestamp', label: 'Time' }] },
1255
- ]},
1256
- { key: 'cc4_monitoringActivities', tables: [
1257
- { path: 'guardrailRules.rules', label: 'Guardrail Rules', cols: [{ key: 'name', label: 'Name' }, { key: 'type', label: 'Type' }, { key: 'action', label: 'Action' }, { key: 'severity', label: 'Severity' }] },
1258
- { path: 'interventions.recentInterventions', label: 'Interventions', cols: [{ key: 'agentId', label: 'Agent' }, { key: 'type', label: 'Type' }, { key: 'reason', label: 'Reason' }, { key: 'timestamp', label: 'Time' }] },
1259
- ]},
1260
- { key: 'cc5_controlActivities', tables: [
1261
- { path: 'approvalWorkflows.recentRequests', label: 'Approval Requests', cols: [{ key: 'agentId', label: 'Agent' }, { key: 'toolId', label: 'Tool' }, { key: 'status', label: 'Status' }, { key: 'requestedAt', label: 'Requested' }, { key: 'resolvedBy', label: 'Resolved By' }] },
1262
- { path: 'escalations.escalations', label: 'Escalations', cols: [{ key: 'agentId', label: 'Agent' }, { key: 'type', label: 'Type' }, { key: 'priority', label: 'Priority' }, { key: 'status', label: 'Status' }] },
1263
- ]},
1264
- { key: 'cc6_logicalAccess', tables: [
1265
- { path: 'vaultManagement.secrets', label: 'Vault Secrets', cols: [{ key: 'key', label: 'Key' }, { key: 'agentId', label: 'Agent' }, { key: 'expired', label: 'Expired' }, { key: 'expiresAt', label: 'Expires' }] },
1266
- { path: 'vaultManagement.auditLog.recentAccesses', label: 'Vault Access Log', cols: [{ key: 'action', label: 'Action' }, { key: 'key', label: 'Key' }, { key: 'agentId', label: 'Agent' }, { key: 'timestamp', label: 'Time' }] },
1267
- ]},
1268
- { key: 'cc7_systemOperations', tables: [
1269
- { path: 'conversationMetrics.byAgent', label: 'Conversation Metrics', cols: [{ key: 'agentId', label: 'Agent' }, { key: 'total', label: 'Total' }, { key: 'completed', label: 'Completed' }, { key: 'completionRate', label: 'Rate' }] },
1270
- ]},
1271
- { key: 'cc8_changeManagement', tables: [
1272
- { path: 'actionJournal.recentActions', label: 'Action Journal', cols: [{ key: 'agentId', label: 'Agent' }, { key: 'toolName', label: 'Tool' }, { key: 'actionType', label: 'Type' }, { key: 'reversed', label: 'Reversed' }, { key: 'timestamp', label: 'Time' }] },
1273
- { path: 'configurationChanges.recentChanges', label: 'Config Changes', cols: [{ key: 'agentId', label: 'Agent' }, { key: 'fromState', label: 'From' }, { key: 'toState', label: 'To' }, { key: 'changedBy', label: 'Changed By' }, { key: 'timestamp', label: 'Time' }] },
1274
- ]},
1275
- { key: 'cc9_riskMitigation', tables: [
1276
- { path: 'budgetControls.recentAlerts', label: 'Budget Alerts', cols: [{ key: 'agentId', label: 'Agent' }, { key: 'alertType', label: 'Type' }, { key: 'message', label: 'Message' }, { key: 'timestamp', label: 'Time' }] },
1277
- ]},
1278
- ];
1279
-
1280
- for (let i = 0; i < sections.length; i++) {
1281
- const sec = sections[i];
1282
- const secData = d[sec.key];
1283
- if (!secData) continue;
1284
- const ccNum = i + 1;
1285
- p.push(`<h2 id="cc${ccNum}" class="page-break">CC${ccNum}: ${this.ccTitle(ccNum)}</h2>`);
1286
- if (secData.description) p.push(`<p style="color:#64748b;margin-bottom:16px">${esc(secData.description)}</p>`);
1287
-
1288
- // Add summary KVs if present
1289
- for (const [k, v] of Object.entries(secData)) {
1290
- if (typeof v === 'object' && v !== null && !Array.isArray(v) && k !== 'title' && k !== 'description') {
1291
- const resolved = this.resolvePath(secData, k);
1292
- if (typeof resolved === 'object' && !Array.isArray(resolved)) {
1293
- // Check if it's a table-target; skip if covered by tables below
1294
- const isTableTarget = sec.tables.some(t => t.path.startsWith(k + '.') || t.path === k);
1295
- if (!isTableTarget && Object.values(resolved).every(v => typeof v !== 'object')) {
1296
- p.push(`<h3>${esc(k.replace(/([A-Z])/g, ' $1').replace(/^./, s => s.toUpperCase()))}</h3>`);
1297
- p.push(this.htmlKV(resolved, esc));
1298
- }
1299
- }
1300
- }
1301
- }
1302
-
1303
- for (const t of sec.tables) {
1304
- const items = this.resolvePath(secData, t.path);
1305
- if (!items || (Array.isArray(items) && items.length === 0)) continue;
1306
- const arr = Array.isArray(items) ? items : [];
1307
- p.push(`<h3>${esc(t.label)} (${arr.length})</h3>`);
1308
- p.push(this.htmlTable(arr, t.cols, esc, resolveAgent));
1309
- }
1310
- }
1311
-
1312
- // Findings
1313
- p.push(`<h2 id="findings" class="page-break">Findings & Recommendations</h2>`);
1314
- const passes = findings.filter((f: any) => f.severity === 'pass');
1315
- const issues = findings.filter((f: any) => f.severity !== 'pass' && f.severity !== 'info');
1316
- if (passes.length) {
1317
- p.push(`<h3>Controls In Place (${passes.length})</h3>`);
1318
- for (const f of passes) p.push(`<div class="finding finding-pass"><div class="cat">${esc(f.category)}</div><span class="badge badge-pass">PASS</span> ${esc(f.message)}</div>`);
1319
- }
1320
- if (issues.length) {
1321
- p.push(`<h3>Gaps & Recommendations (${issues.length})</h3>`);
1322
- for (const f of issues) p.push(`<div class="finding finding-${f.severity}"><div class="cat">${esc(f.category)}</div><span class="badge badge-${f.severity}">${esc(f.severity.toUpperCase())}</span> ${esc(f.message)}</div>`);
1323
- }
1324
-
1325
- return p.join('\n');
1326
- }
1327
-
1328
- private auditToHTML(d: any, esc: (s: any) => string, resolveAgent?: (id: any) => string): string {
1329
- const p: string[] = [];
1330
- const summary = d.summary || {};
1331
- p.push(`<h2>Summary</h2>`);
1332
- p.push(this.htmlMetrics({ 'Total Events': summary.totalEvents, ...summary.bySource }, esc));
1333
- p.push(`<h3>By Category</h3>`);
1334
- p.push(this.htmlKV(summary.byCategory || {}, esc));
1335
- p.push(`<h3>By Agent</h3>`);
1336
- const byAgentResolved: Record<string, any> = {};
1337
- for (const [k, v] of Object.entries(summary.byAgent || {})) {
1338
- byAgentResolved[resolveAgent ? resolveAgent(k) : k] = v;
1339
- }
1340
- p.push(this.htmlKV(byAgentResolved, esc));
1341
- p.push(`<h2 class="page-break">Audit Timeline (${(d.timeline || []).length} events)</h2>`);
1342
- p.push(this.htmlTable(d.timeline || [], [
1343
- { key: 'timestamp', label: 'Time' }, { key: 'source', label: 'Source' }, { key: 'category', label: 'Category' },
1344
- { key: 'agentId', label: 'Agent' }, { key: 'detail', label: 'Detail' }
1345
- ], esc, resolveAgent));
1346
- return p.join('\n');
1347
- }
1348
-
1349
- private gdprToHTML(d: any, esc: (s: any) => string, resolveAgent?: (id: any) => string): string {
1350
- const p: string[] = [];
1351
- p.push(`<h2>Data Summary</h2>`);
1352
- p.push(this.htmlKV(d.dataSummary || {}, esc));
1353
- const tables: [string, string, { key: string; label: string }[]][] = [
1354
- ['toolCalls', 'Tool Calls', [{ key: 'tool_id', label: 'Tool' }, { key: 'tool_name', label: 'Name' }, { key: 'created_at', label: 'Time' }]],
1355
- ['journalEntries', 'Journal Entries', [{ key: 'tool_id', label: 'Tool' }, { key: 'action_type', label: 'Action' }, { key: 'reversed', label: 'Reversed' }, { key: 'created_at', label: 'Time' }]],
1356
- ['interventions', 'Interventions', [{ key: 'type', label: 'Type' }, { key: 'reason', label: 'Reason' }, { key: 'created_at', label: 'Time' }]],
1357
- ['memories', 'Memories', [{ key: 'key', label: 'Key' }, { key: 'category', label: 'Category' }, { key: 'created_at', label: 'Created' }]],
1358
- ];
1359
- for (const [key, label, cols] of tables) {
1360
- const items = d[key] || [];
1361
- if (items.length === 0) continue;
1362
- p.push(`<h2 class="page-break">${esc(label)} (${items.length})</h2>`);
1363
- p.push(this.htmlTable(items, cols, esc, resolveAgent));
1364
- }
1365
- return p.join('\n');
1366
- }
1367
-
1368
- private incidentToHTML(d: any, esc: (s: any) => string, resolveAgent?: (id: any) => string): string {
1369
- const p: string[] = [];
1370
- p.push(`<h2>Incident Summary</h2>`);
1371
- p.push(this.htmlMetrics(d.incidentSummary || {}, esc));
1372
- const tables: [string, string, { key: string; label: string }[]][] = [
1373
- ['dlpViolations', 'DLP Violations', [{ key: 'agent_id', label: 'Agent' }, { key: 'rule_id', label: 'Rule' }, { key: 'action_taken', label: 'Action' }, { key: 'direction', label: 'Dir' }, { key: 'created_at', label: 'Time' }]],
1374
- ['interventions', 'Interventions', [{ key: 'agent_id', label: 'Agent' }, { key: 'type', label: 'Type' }, { key: 'reason', label: 'Reason' }, { key: 'created_at', label: 'Time' }]],
1375
- ['escalations', 'Escalations', [{ key: 'agent_id', label: 'Agent' }, { key: 'type', label: 'Type' }, { key: 'priority', label: 'Priority' }, { key: 'status', label: 'Status' }, { key: 'created_at', label: 'Time' }]],
1376
- ['reversedActions', 'Reversed Actions', [{ key: 'agent_id', label: 'Agent' }, { key: 'tool_name', label: 'Tool' }, { key: 'action_type', label: 'Type' }, { key: 'reversed_by', label: 'By' }, { key: 'created_at', label: 'Time' }]],
1377
- ];
1378
- for (const [key, label, cols] of tables) {
1379
- const items = d[key] || [];
1380
- if (items.length === 0) continue;
1381
- p.push(`<h2 class="page-break">${esc(label)} (${items.length})</h2>`);
1382
- p.push(this.htmlTable(items, cols, esc, resolveAgent));
1383
- }
1384
- return p.join('\n');
1385
- }
1386
-
1387
- private accessReviewToHTML(d: any, esc: (s: any) => string, resolveAgent?: (id: any) => string): string {
1388
- const p: string[] = [];
1389
- p.push(`<h2>Agent Access Review</h2>`);
1390
- p.push(this.htmlTable(d.agentAccess || [], [
1391
- { key: 'name', label: 'Agent' }, { key: 'status', label: 'Status' }, { key: 'role', label: 'Role' },
1392
- { key: 'permissionProfile', label: 'Permissions' }, { key: 'hasBudget', label: 'Budget' },
1393
- { key: 'vaultSecrets', label: 'Vault Secrets' }, { key: 'expiredSecrets', label: 'Expired' }
1394
- ], esc, resolveAgent));
1395
- p.push(`<h2>Vault Review</h2>`);
1396
- p.push(this.htmlKV(d.vaultReview || {}, esc));
1397
- if ((d.recommendations || []).length) {
1398
- p.push(`<h2>Recommendations</h2>`);
1399
- for (const r of d.recommendations) p.push(`<div class="finding finding-${r.severity}"><span class="badge badge-${r.severity}">${esc(r.severity.toUpperCase())}</span> ${esc(r.message)}</div>`);
1400
- }
1401
- return p.join('\n');
1402
- }
1403
-
1404
- private ccTitle(num: number): string {
1405
- return ['', 'Control Environment', 'Communication & Information', 'Risk Assessment', 'Monitoring Activities', 'Control Activities', 'Logical & Physical Access', 'System Operations', 'Change Management', 'Risk Mitigation'][num] || '';
1406
- }
1407
-
1408
- private resolvePath(obj: any, path: string): any {
1409
- return path.split('.').reduce((o, k) => o?.[k], obj);
1410
- }
1411
-
1412
- // ─── Risk Score Calculator ────────────────────────
1413
-
1414
- private calculateRiskScore(dlpViolations: Rows, securityEvents: Rows, guardrailRules: Rows, dlpRules: Rows): Record<string, any> {
1415
- let score = 100; // Start at 100 (best)
1416
- const deductions: { category: string; points: number; reason: string }[] = [];
1417
-
1418
- // DLP violations reduce score
1419
- if (dlpViolations.length > 0) {
1420
- const blocked = dlpViolations.filter((v: any) => v.action_taken === 'blocked').length;
1421
- const pts = Math.min(blocked * 2, 20);
1422
- score -= pts;
1423
- deductions.push({ category: 'DLP', points: pts, reason: `${blocked} blocked DLP violations` });
1424
- }
1425
-
1426
- // Lack of DLP rules
1427
- if (dlpRules.length < 5) {
1428
- score -= 10;
1429
- deductions.push({ category: 'DLP Controls', points: 10, reason: `Only ${dlpRules.length} DLP rules (recommend 5+)` });
1430
- }
1431
-
1432
- // Lack of guardrails
1433
- if (guardrailRules.length < 3) {
1434
- score -= 10;
1435
- deductions.push({ category: 'Guardrails', points: 10, reason: `Only ${guardrailRules.length} guardrail rules (recommend 3+)` });
1436
- }
1437
-
1438
- // Security events
1439
- if (securityEvents.length > 0) {
1440
- const criticals = securityEvents.filter((e: any) => e.severity === 'critical').length;
1441
- const pts = Math.min(criticals * 5 + securityEvents.length, 30);
1442
- score -= pts;
1443
- deductions.push({ category: 'Security', points: pts, reason: `${securityEvents.length} security events (${criticals} critical)` });
1444
- }
1445
-
1446
- return {
1447
- score: Math.max(0, score),
1448
- grade: score >= 90 ? 'A' : score >= 80 ? 'B' : score >= 70 ? 'C' : score >= 60 ? 'D' : 'F',
1449
- deductions,
1450
- };
1451
- }
1452
-
1453
- // ─── Findings Generator ───────────────────────────
1454
-
1455
- private generateFindings(data: any): { severity: string; message: string; category: string }[] {
1456
- const findings: { severity: string; message: string; category: string }[] = [];
1457
- const km = data.executiveSummary?.keyMetrics || {};
1458
- const cc1 = data.cc1_controlEnvironment || {};
1459
- const cc5 = data.cc5_controlActivities || {};
1460
- const cc6 = data.cc6_logicalAccess || {};
1461
-
1462
- // ─── Positive findings (controls in place) ────────────
1463
-
1464
- // Approval system
1465
- const approvalPolicies = cc5.approvalWorkflows?.policies || [];
1466
- const totalApprovals = km.totalApprovalRequests || 0;
1467
- if (approvalPolicies.length > 0) {
1468
- findings.push({ severity: 'pass', category: 'CC5: Control Activities', message: `Human-in-the-loop approval system active with ${approvalPolicies.length} approval ${approvalPolicies.length === 1 ? 'policy' : 'policies'}. ${totalApprovals} approval requests processed during the reporting period (approval rate: ${km.approvalRate || 'N/A'}).` });
1469
- }
1470
-
1471
- // Escalation chains + approval policies with notification
1472
- const escalationChains = cc1.escalationChains?.total || 0;
1473
- const escalationViaApproval = data._escalationViaApprovalPolicies || 0;
1474
- const totalEscalation = escalationChains + escalationViaApproval;
1475
- if (totalEscalation > 0) {
1476
- const parts: string[] = [];
1477
- if (escalationChains > 0) parts.push(`${escalationChains} dedicated escalation ${escalationChains === 1 ? 'chain' : 'chains'}`);
1478
- if (escalationViaApproval > 0) parts.push(`${escalationViaApproval} approval ${escalationViaApproval === 1 ? 'policy' : 'policies'} with notification/escalation routing`);
1479
- findings.push({ severity: 'pass', category: 'CC4: Monitoring', message: `Escalation procedures in place: ${parts.join(', ')}. Critical incidents are routed to managers via configured notification channels.` });
1480
- }
1481
-
1482
- // Guardrails
1483
- if (km.activeGuardrailRules > 0) {
1484
- findings.push({ severity: 'pass', category: 'CC4: Monitoring', message: `${km.activeGuardrailRules} active guardrail rules enforcing real-time agent behavior monitoring. ${km.totalInterventions} interventions triggered during the reporting period.` });
1485
- }
1486
-
1487
- // DLP
1488
- if (km.activeDLPRules >= 5) {
1489
- findings.push({ severity: 'pass', category: 'CC3: Risk Assessment', message: `${km.activeDLPRules} active DLP rules providing data loss prevention coverage across PII, credentials, and compliance categories.` });
1490
- }
1491
-
1492
- // Policies
1493
- if (km.activePolicies > 0) {
1494
- findings.push({ severity: 'pass', category: 'CC1: Control Environment', message: `${km.activePolicies} governance policies active, covering ${Object.keys(cc1.governancePolicies?.byCategory || {}).join(', ') || 'multiple categories'}.` });
1495
- }
1496
-
1497
- // Permission profiles
1498
- const permProfiles = cc1.permissionProfiles?.totalProfiles || 0;
1499
- if (permProfiles > 0) {
1500
- findings.push({ severity: 'pass', category: 'CC6: Access Controls', message: `${permProfiles} permission profiles configured, enforcing least-privilege tool access for agents.` });
1501
- }
1502
-
1503
- // Vault management
1504
- const vaultSecrets = (cc6.vaultManagement?.totalSecrets ?? cc6.vaultManagement?.secrets?.length) || 0;
1505
- if (vaultSecrets > 0) {
1506
- findings.push({ severity: 'pass', category: 'CC6: Access Controls', message: `Vault secrets management active with ${vaultSecrets} secrets under management. ${cc6.vaultManagement?.auditLog?.totalAccesses || 0} audited accesses during the reporting period.` });
1507
- }
1508
-
1509
- // SSO
1510
- const ssoCount = cc6.ssoIntegrations?.total || 0;
1511
- if (ssoCount > 0) {
1512
- findings.push({ severity: 'pass', category: 'CC6: Access Controls', message: `${ssoCount} SSO integration(s) configured for centralized authentication.` });
1513
- }
1514
-
1515
- // Budget controls
1516
- const agentsWithBudgets = (cc1.agentInventory?.agents || []).filter((a: any) => a.hasBudgetConfig).length;
1517
- if (agentsWithBudgets > 0) {
1518
- findings.push({ severity: 'pass', category: 'CC9: Risk Mitigation', message: `Budget controls configured for ${agentsWithBudgets} of ${km.totalAgents} agents. ${km.totalBudgetAlerts} budget alerts triggered during the reporting period.` });
1519
- }
1520
-
1521
- // Journal / reversibility
1522
- const journalActions = km.totalJournalActions || 0;
1523
- if (journalActions > 0) {
1524
- findings.push({ severity: 'pass', category: 'CC8: Change Management', message: `Action journal tracking ${journalActions} reversible actions with rollback support. Reversal rate: ${km.journalReversalRate || '0%'}.` });
1525
- }
1526
-
1527
- // ─── Negative findings (gaps to address) ──────────────
1528
-
1529
- // Missing approval system
1530
- if (approvalPolicies.length === 0) {
1531
- findings.push({ severity: 'high', category: 'CC5: Control Activities', message: 'No approval policies configured. Implement human-in-the-loop approval workflows for sensitive tool executions (email sends, file deletions, external API calls).' });
1532
- }
1533
-
1534
- // Missing escalation chains
1535
- if (totalEscalation === 0) {
1536
- findings.push({ severity: 'medium', category: 'CC4: Monitoring', message: 'No escalation chains configured. Set up escalation procedures to route critical agent incidents to managers via email/notification.' });
1537
- }
1538
-
1539
- // Insufficient DLP
1540
- if (km.activeDLPRules < 5) {
1541
- findings.push({ severity: 'high', category: 'CC3: Risk Assessment', message: `Only ${km.activeDLPRules} active DLP rules. Enterprise environments should have comprehensive DLP coverage (recommend 15+ rules across PII, credentials, and compliance categories). Use the DLP Rule Packs to quickly apply enterprise-grade defaults.` });
1542
- }
1543
-
1544
- // No guardrails
1545
- if (km.activeGuardrailRules === 0) {
1546
- findings.push({ severity: 'high', category: 'CC4: Monitoring', message: 'No guardrail rules configured. Implement rate limits, content filters, and tool restrictions for real-time agent behavior control.' });
1547
- } else if (km.activeGuardrailRules < 3) {
1548
- findings.push({ severity: 'medium', category: 'CC4: Monitoring', message: `Only ${km.activeGuardrailRules} guardrail rules active. Consider adding additional rules for rate limits, content filters, and tool restrictions.` });
1549
- }
1550
-
1551
- // DLP violations detected
1552
- if (km.totalDLPViolations > 0) {
1553
- const blocked = data.cc3_riskAssessment?.dlpViolations?.byAction?.blocked || 0;
1554
- findings.push({ severity: blocked > 0 ? 'medium' : 'low', category: 'CC3: Risk Assessment', message: `${km.totalDLPViolations} DLP violations detected (${blocked} blocked). Review violation details in CC3 section to assess data exposure risk.` });
1555
- }
1556
-
1557
- // High reversal rate
1558
- const reversalRate = parseFloat(data.cc8_changeManagement?.actionJournal?.reversalRate || '0');
1559
- if (reversalRate > 5) {
1560
- findings.push({ severity: 'medium', category: 'CC8: Change Management', message: `${reversalRate}% action reversal rate detected. High reversal rates may indicate agent reliability issues or overly aggressive actions.` });
1561
- }
1562
-
1563
- // Expired vault secrets
1564
- const expiredSecrets = (cc6.vaultManagement?.secrets || []).filter((s: any) => s.expired).length;
1565
- if (expiredSecrets > 0) {
1566
- findings.push({ severity: 'high', category: 'CC6: Access Controls', message: `${expiredSecrets} vault secrets have expired. Rotate or remove expired credentials immediately.` });
1567
- }
1568
-
1569
- // Secrets without expiry
1570
- const noExpiry = (cc6.vaultManagement?.secrets || []).filter((s: any) => !s.expiresAt).length;
1571
- if (noExpiry > 0) {
1572
- findings.push({ severity: 'low', category: 'CC6: Access Controls', message: `${noExpiry} vault secrets have no expiration set. Consider setting expiry dates to enforce credential rotation.` });
1573
- }
1574
-
1575
- // Agents without budget controls
1576
- const agentsNoBudget = km.totalAgents - agentsWithBudgets;
1577
- if (agentsNoBudget > 0 && km.totalAgents > 0) {
1578
- findings.push({ severity: 'low', category: 'CC9: Risk Mitigation', message: `${agentsNoBudget} of ${km.totalAgents} agents have no budget controls configured. Consider setting spending limits to prevent cost overruns.` });
1579
- }
1580
-
1581
- // Agents on default permission profile
1582
- const defaultPermAgents = (cc1.agentInventory?.agents || []).filter((a: any) => a.permissionProfile === 'default').length;
1583
- if (defaultPermAgents > 0) {
1584
- findings.push({ severity: 'low', category: 'CC6: Access Controls', message: `${defaultPermAgents} agents using the default permission profile. Assign specific permission profiles to enforce least-privilege access.` });
1585
- }
1586
-
1587
- // No policies
1588
- if (km.activePolicies === 0) {
1589
- findings.push({ severity: 'medium', category: 'CC1: Control Environment', message: 'No governance policies configured. Define organizational policies for agent behavior, data handling, and compliance requirements.' });
1590
- }
1591
-
1592
- // Budget alerts fired
1593
- if (km.totalBudgetAlerts > 5) {
1594
- findings.push({ severity: 'medium', category: 'CC9: Risk Mitigation', message: `${km.totalBudgetAlerts} budget alerts triggered during the reporting period. Review budget configurations and agent spending patterns.` });
1595
- } else if (km.totalBudgetAlerts > 0) {
1596
- findings.push({ severity: 'low', category: 'CC9: Risk Mitigation', message: `${km.totalBudgetAlerts} budget alerts triggered. Review cost management controls in CC9 section.` });
1597
- }
1598
-
1599
- // Denied approvals (may indicate agents attempting unauthorized actions)
1600
- const deniedApprovals = cc5.approvalWorkflows?.byStatus?.denied || cc5.approvalWorkflows?.byStatus?.rejected || 0;
1601
- if (deniedApprovals > 0) {
1602
- findings.push({ severity: 'medium', category: 'CC5: Control Activities', message: `${deniedApprovals} approval requests were denied/rejected. Investigate whether agents are attempting unauthorized operations.` });
1603
- }
1604
-
1605
- // Sort: pass first, then by severity
1606
- const order: Record<string, number> = { pass: 0, info: 1, low: 2, medium: 3, high: 4, critical: 5 };
1607
- findings.sort((a, b) => (order[a.severity] ?? 3) - (order[b.severity] ?? 3));
1608
-
1609
- if (findings.length === 0) {
1610
- findings.push({ severity: 'info', category: 'General', message: 'No significant findings. All controls operating effectively within the reporting period.' });
1611
- }
1612
-
1613
- return findings;
1614
- }
1615
-
1616
- // ─── Helpers ──────────────────────────────────────
1617
-
1618
- private groupCount(rows: Rows, field: string): Record<string, number> {
1619
- const map: Record<string, number> = {};
1620
- for (const r of rows) { const k = r[field] || 'unknown'; map[k] = (map[k] || 0) + 1; }
1621
- return map;
1622
- }
1623
-
1624
- private rowsToMap(rows: Rows, keyField: string, valField: string): Record<string, number> {
1625
- const map: Record<string, number> = {};
1626
- for (const r of rows) map[r[keyField]] = r[valField];
1627
- return map;
1628
- }
1629
-
1630
- private calcAvgResponseTime(approvals: Rows): string {
1631
- const resolved = approvals.filter((a: any) => a.resolved_at && a.created_at);
1632
- if (resolved.length === 0) return 'N/A';
1633
- const total = resolved.reduce((sum: number, a: any) => {
1634
- return sum + (new Date(a.resolved_at).getTime() - new Date(a.created_at).getTime());
1635
- }, 0);
1636
- const avgMs = total / resolved.length;
1637
- if (avgMs < 60000) return `${(avgMs / 1000).toFixed(0)}s`;
1638
- if (avgMs < 3600000) return `${(avgMs / 60000).toFixed(0)}m`;
1639
- return `${(avgMs / 3600000).toFixed(1)}h`;
1640
- }
1641
-
1642
- private createReport(orgId: string, type: ComplianceReport['type'], title: string, parameters: Record<string, any>, generatedBy: string): ComplianceReport {
1643
- const report: ComplianceReport = {
1644
- id: crypto.randomUUID(),
1645
- orgId, type, title, parameters,
1646
- status: 'generating',
1647
- format: 'json',
1648
- generatedBy,
1649
- createdAt: new Date().toISOString(),
1650
- };
1651
- this.reports.unshift(report);
1652
- if (this.reports.length > 200) this.reports = this.reports.slice(0, 200);
1653
- return report;
1654
- }
1655
-
1656
- private persistReport(report: ComplianceReport): void {
1657
- this.engineDb?.execute(
1658
- `INSERT INTO compliance_reports (id, org_id, type, title, parameters, status, data, format, generated_by, error, created_at, completed_at)
1659
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
1660
- ON CONFLICT(id) DO UPDATE SET status=excluded.status, data=excluded.data, error=excluded.error, completed_at=excluded.completed_at`,
1661
- [report.id, report.orgId, report.type, report.title, JSON.stringify(report.parameters),
1662
- report.status, report.data ? JSON.stringify(report.data) : null, report.format,
1663
- report.generatedBy, report.error || null, report.createdAt, report.completedAt || null]
1664
- ).catch((err) => { console.error('[compliance] Failed to persist report:', err); });
1665
- }
1666
-
1667
- private flattenObject(obj: Record<string, any>, prefix = ''): Record<string, string> {
1668
- const result: Record<string, string> = {};
1669
- for (const [key, value] of Object.entries(obj)) {
1670
- const path = prefix ? `${prefix}.${key}` : key;
1671
- if (value && typeof value === 'object' && !Array.isArray(value)) {
1672
- Object.assign(result, this.flattenObject(value, path));
1673
- } else {
1674
- result[path] = Array.isArray(value) ? `[${value.length} items]` : String(value);
1675
- }
1676
- }
1677
- return result;
1678
- }
1679
- }