@wenathlan/devthink 2.0.14 → 2.0.19

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 (444) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/{dist/bridge.d.ts → bridge.d.ts} +1 -1
  3. package/bridge.d.ts.map +1 -0
  4. package/bridge.js +1877 -0
  5. package/bun.d.ts.map +1 -0
  6. package/bun.js +52329 -0
  7. package/caps/background.json +712 -0
  8. package/caps/cli.json +360 -0
  9. package/caps/library.json +3611 -0
  10. package/caps/mcp.json +126 -0
  11. package/caps/pagebridge.json +377 -0
  12. package/caps/popup.json +51 -0
  13. package/caps/sidepanel.json +522 -0
  14. package/checksums.txt +142 -0
  15. package/cli.d.ts.map +1 -0
  16. package/{dist/cli.js → cli.js} +2 -2
  17. package/companion.d.ts.map +1 -0
  18. package/companion.js +389 -0
  19. package/crossbrowser.d.ts.map +1 -0
  20. package/crossbrowser.js +1191 -0
  21. package/dashdone.d.ts.map +1 -0
  22. package/dashdone.js +368 -0
  23. package/deno.d.ts.map +1 -0
  24. package/deno.js +52325 -0
  25. package/devthink.umd.js +52346 -0
  26. package/fixtures/bun.ts +7 -0
  27. package/fixtures/cjs.js +6 -0
  28. package/fixtures/deno.ts +6 -0
  29. package/fixtures/example-org-pagestate.json +22 -0
  30. package/fixtures/importers/automa-workflow.json +18 -0
  31. package/fixtures/importers/selenium-side.json +20 -0
  32. package/fixtures/importers/tabular-plan.csv +7 -0
  33. package/fixtures/importers/uivision-macro.json +10 -0
  34. package/fixtures/importers/v1-plan.json +13 -0
  35. package/fixtures/mcp-client.mjs +14 -0
  36. package/fixtures/pages/checkout.html +192 -0
  37. package/fixtures/pages/dashboard.html +110 -0
  38. package/fixtures/pages/feed.html +113 -0
  39. package/fixtures/pages/product-grid.html +150 -0
  40. package/fixtures/plans/form-inventory-plan.json +11 -0
  41. package/fixtures/plans/release-notes-plan.json +11 -0
  42. package/fixtures/recipes/agentscompete.json +11 -0
  43. package/fixtures/recipes/agentsforms.json +11 -0
  44. package/fixtures/recipes/agentsmonitor.json +11 -0
  45. package/fixtures/recipes/agentsreview.json +29 -0
  46. package/fixtures/recipes/agentswarm.json +11 -0
  47. package/fixtures/recipes/fillcalendar.json +12 -0
  48. package/fixtures/recipes/fillcheckout.json +13 -0
  49. package/fixtures/recipes/filldependentdropdowns.json +12 -0
  50. package/fixtures/recipes/fillfromcsv.json +13 -0
  51. package/fixtures/recipes/fillloginform.json +12 -0
  52. package/fixtures/recipes/fillmultistepwizard.json +13 -0
  53. package/fixtures/recipes/fillregistration.json +12 -0
  54. package/fixtures/recipes/fillsearchfilters.json +12 -0
  55. package/fixtures/recipes/filltypeahead.json +11 -0
  56. package/fixtures/recipes/monitoralerts.json +12 -0
  57. package/fixtures/recipes/monitoravailability.json +11 -0
  58. package/fixtures/recipes/monitornetworkquiet.json +12 -0
  59. package/fixtures/recipes/monitorpagechanges.json +11 -0
  60. package/fixtures/recipes/monitorpricechange.json +11 -0
  61. package/fixtures/recipes/monitorschedule.json +12 -0
  62. package/fixtures/recipes/scrapedynamicprices.json +13 -0
  63. package/fixtures/recipes/scrapeimagegallery.json +12 -0
  64. package/fixtures/recipes/scrapeinfinitefeed.json +13 -0
  65. package/fixtures/recipes/scrapenestedlists.json +12 -0
  66. package/fixtures/recipes/scrapeproductgrid.json +12 -0
  67. package/fixtures/recipes/scrapereviews.json +12 -0
  68. package/fixtures/recipes/scrapesearchresults.json +12 -0
  69. package/fixtures/recipes/scrapetablepagination.json +12 -0
  70. package/fixtures/recipes/testaccessibility.json +34 -0
  71. package/fixtures/recipes/testconsoleerrors.json +12 -0
  72. package/fixtures/recipes/testdeeplinks.json +12 -0
  73. package/fixtures/recipes/testformvalidation.json +13 -0
  74. package/fixtures/recipes/testlayoutshift.json +12 -0
  75. package/fixtures/recipes/testlinkcheck.json +12 -0
  76. package/fixtures/recipes/testloadtiming.json +12 -0
  77. package/fixtures/recipes/testvisualdiff.json +12 -0
  78. package/fixtures/workflows/changelog-digest-workflow.json +13 -0
  79. package/fixtures/workflows/form-survey-workflow.json +13 -0
  80. package/gallery.json +706 -0
  81. package/hardening.d.ts.map +1 -0
  82. package/hardening.js +188 -0
  83. package/headless.d.ts.map +1 -0
  84. package/headless.js +11522 -0
  85. package/http.d.ts.map +1 -0
  86. package/http.js +2165 -0
  87. package/index.cjs +54682 -0
  88. package/index.d.ts.map +1 -0
  89. package/index.js +52310 -0
  90. package/index.neutral.js +46343 -0
  91. package/{web/manifest.json → manifest.json} +1 -1
  92. package/mcp.d.ts.map +1 -0
  93. package/mcp.js +20515 -0
  94. package/memory.d.ts.map +1 -0
  95. package/{memory.ts → memory.js} +2310 -3834
  96. package/nativehost.template.json +10 -0
  97. package/node.cjs +54686 -0
  98. package/node.d.ts.map +1 -0
  99. package/pack.d.ts.map +1 -0
  100. package/pack.js +805 -0
  101. package/package.json +83 -176
  102. package/policy.d.ts.map +1 -0
  103. package/{policy.ts → policy.js} +4679 -5073
  104. package/progress.d.ts.map +1 -0
  105. package/progress.js +645 -0
  106. package/protocol.d.ts.map +1 -0
  107. package/protocol.js +8334 -0
  108. package/schemas/audit.schema.json +226 -0
  109. package/schemas/capability.schema.json +113 -0
  110. package/schemas/envelope.schema.json +162 -0
  111. package/schemas/memory.schema.json +51 -0
  112. package/schemas/observation.schema.json +113 -0
  113. package/schemas/plan.schema.json +208 -0
  114. package/schemas/progress.schema.json +126 -0
  115. package/schemas/proposal.schema.json +68 -0
  116. package/schemas/session.schema.json +82 -0
  117. package/schemas/tool.schema.json +94 -0
  118. package/server.d.ts.map +1 -0
  119. package/server.js +28877 -0
  120. package/umd-example.html +18 -0
  121. package/umd.d.ts.map +1 -0
  122. package/accounts.ts +0 -2087
  123. package/agent.ts +0 -2331
  124. package/antigravity.ts +0 -2139
  125. package/apifreeze.ts +0 -4146
  126. package/auth.ts +0 -642
  127. package/background.ts +0 -16837
  128. package/bridge.ts +0 -2080
  129. package/build.ts +0 -54
  130. package/bun.ts +0 -26
  131. package/capture.ts +0 -1614
  132. package/checksecrets.ts +0 -72
  133. package/cjs.ts +0 -9
  134. package/cli.ts +0 -3500
  135. package/commands.ts +0 -1101
  136. package/companion.ts +0 -450
  137. package/compatibility.ts +0 -37
  138. package/config.ts +0 -3137
  139. package/constants.ts +0 -943
  140. package/core.ts +0 -1473
  141. package/crossbrowser.ts +0 -1359
  142. package/dashdone.ts +0 -605
  143. package/data.ts +0 -943
  144. package/database.ts +0 -133
  145. package/debug.ts +0 -850
  146. package/deno.ts +0 -27
  147. package/devthink.ts +0 -707
  148. package/dist/accounts.d.ts +0 -409
  149. package/dist/agent.d.ts +0 -837
  150. package/dist/antigravity.d.ts +0 -380
  151. package/dist/apifreeze.d.ts +0 -113
  152. package/dist/auth.d.ts +0 -224
  153. package/dist/capture.d.ts +0 -595
  154. package/dist/cjs.d.ts +0 -6
  155. package/dist/commands.d.ts +0 -310
  156. package/dist/compatibility.d.ts +0 -17
  157. package/dist/config.d.ts +0 -1853
  158. package/dist/constants.d.ts +0 -637
  159. package/dist/core.d.ts +0 -361
  160. package/dist/data.d.ts +0 -330
  161. package/dist/database.d.ts +0 -24
  162. package/dist/debug.d.ts +0 -270
  163. package/dist/engine.d.ts +0 -74
  164. package/dist/environments.d.ts +0 -244
  165. package/dist/evidence.d.ts +0 -277
  166. package/dist/export.d.ts +0 -311
  167. package/dist/fingerprint.d.ts +0 -594
  168. package/dist/flow.d.ts +0 -300
  169. package/dist/gates.d.ts +0 -103
  170. package/dist/identity.d.ts +0 -51
  171. package/dist/ids.d.ts +0 -7
  172. package/dist/llm.d.ts +0 -652
  173. package/dist/models.d.ts +0 -1807
  174. package/dist/net.d.ts +0 -325
  175. package/dist/neutral.d.ts +0 -41
  176. package/dist/oauth.d.ts +0 -703
  177. package/dist/page.d.ts +0 -1166
  178. package/dist/perf.d.ts +0 -481
  179. package/dist/plan.d.ts +0 -134
  180. package/dist/project.d.ts +0 -395
  181. package/dist/providers.d.ts +0 -37
  182. package/dist/quota.d.ts +0 -453
  183. package/dist/recovery.d.ts +0 -621
  184. package/dist/request.d.ts +0 -1492
  185. package/dist/run.d.ts +0 -779
  186. package/dist/runtime.d.ts +0 -212
  187. package/dist/search.d.ts +0 -375
  188. package/dist/security.d.ts +0 -534
  189. package/dist/serve.d.ts +0 -136
  190. package/dist/session.d.ts +0 -296
  191. package/dist/storage.d.ts +0 -53
  192. package/dist/streaming.d.ts +0 -1119
  193. package/dist/swarm.d.ts +0 -328
  194. package/dist/tools.d.ts +0 -170
  195. package/dist/types.d.ts +0 -8357
  196. package/dist/utils.d.ts +0 -82
  197. package/dist/version.d.ts +0 -7
  198. package/dist/versionregistry.d.ts +0 -406
  199. package/dist/views.d.ts +0 -579
  200. package/dist/workbenchsession.d.ts +0 -69
  201. package/dist/workflow.d.ts +0 -649
  202. package/docs/readme.md +0 -92
  203. package/docs/schemas/antigravity.json +0 -192
  204. package/engine.ts +0 -1524
  205. package/environments.ts +0 -1005
  206. package/evidence.ts +0 -643
  207. package/export.ts +0 -889
  208. package/fingerprint.ts +0 -1458
  209. package/flow.ts +0 -1190
  210. package/gates.ts +0 -307
  211. package/gateway.ts +0 -34
  212. package/hardening.ts +0 -191
  213. package/headless.ts +0 -369
  214. package/http.ts +0 -2110
  215. package/identity.ts +0 -246
  216. package/ids.ts +0 -26
  217. package/index.ts +0 -369
  218. package/llm.ts +0 -2682
  219. package/mcp.ts +0 -1835
  220. package/models.ts +0 -3805
  221. package/modes.ts +0 -43
  222. package/net.ts +0 -1214
  223. package/neutral.ts +0 -362
  224. package/node.ts +0 -26
  225. package/oauth.ts +0 -2216
  226. package/offscreen.ts +0 -170
  227. package/pack.ts +0 -956
  228. package/page.ts +0 -7824
  229. package/pagebridge.ts +0 -1116
  230. package/perf.ts +0 -957
  231. package/plan.ts +0 -672
  232. package/plugin.ts +0 -76
  233. package/prisma.config.ts +0 -27
  234. package/progress.ts +0 -1308
  235. package/project.ts +0 -1291
  236. package/protocol.ts +0 -4187
  237. package/providers.ts +0 -246
  238. package/quota.ts +0 -1887
  239. package/recovery.ts +0 -2433
  240. package/request.ts +0 -4482
  241. package/run.ts +0 -2135
  242. package/runtime.ts +0 -526
  243. package/search.ts +0 -1760
  244. package/security.ts +0 -1673
  245. package/serve.ts +0 -419
  246. package/server.ts +0 -5538
  247. package/session.ts +0 -1162
  248. package/storage.ts +0 -182
  249. package/streaming.ts +0 -4101
  250. package/swarm.ts +0 -884
  251. package/sync.ts +0 -56
  252. package/tests/agentcert.test.ts +0 -128
  253. package/tests/agentfleet.test.ts +0 -214
  254. package/tests/agentreview.test.ts +0 -241
  255. package/tests/agentstream.test.ts +0 -335
  256. package/tests/agentwork.test.ts +0 -356
  257. package/tests/apifreeze.test.ts +0 -290
  258. package/tests/apimap.test.ts +0 -112
  259. package/tests/approvalgate.test.ts +0 -175
  260. package/tests/artifactmanifest.test.ts +0 -204
  261. package/tests/attentionfeed.test.ts +0 -163
  262. package/tests/backgroundruns.test.ts +0 -100
  263. package/tests/batchscheduling.test.ts +0 -131
  264. package/tests/blackboard.test.ts +0 -238
  265. package/tests/bridge.test.ts +0 -1088
  266. package/tests/browsercoverage.test.ts +0 -134
  267. package/tests/browserpolyfills.test.ts +0 -124
  268. package/tests/build.mjs +0 -1260
  269. package/tests/clientauth.test.ts +0 -223
  270. package/tests/clitools.test.ts +0 -578
  271. package/tests/confirmgates.test.ts +0 -190
  272. package/tests/containerpack.test.ts +0 -143
  273. package/tests/controlflow.test.ts +0 -2120
  274. package/tests/coordination.test.ts +0 -345
  275. package/tests/copyscreen.test.ts +0 -139
  276. package/tests/core.test.ts +0 -417
  277. package/tests/costcert.test.ts +0 -95
  278. package/tests/crossbrowser.test.ts +0 -115
  279. package/tests/cspaudit.test.ts +0 -79
  280. package/tests/dashdone.test.ts +0 -615
  281. package/tests/datagrid.test.ts +0 -137
  282. package/tests/doccheck.test.ts +0 -107
  283. package/tests/dombatch.test.ts +0 -109
  284. package/tests/emulation.test.ts +0 -282
  285. package/tests/environments.test.ts +0 -259
  286. package/tests/evidenceviews.test.ts +0 -88
  287. package/tests/exporttools.test.ts +0 -185
  288. package/tests/firefoxprep.test.ts +0 -134
  289. package/tests/flowlibrary.test.ts +0 -242
  290. package/tests/flowrun.test.ts +0 -303
  291. package/tests/forensics.test.ts +0 -439
  292. package/tests/gateway.test.ts +0 -939
  293. package/tests/headlesslib.test.ts +0 -171
  294. package/tests/httpstream.test.ts +0 -277
  295. package/tests/immutablelog.test.ts +0 -157
  296. package/tests/inboundguard.test.ts +0 -177
  297. package/tests/lazyload.test.ts +0 -72
  298. package/tests/librarymodes.test.ts +0 -623
  299. package/tests/llm.test.ts +0 -696
  300. package/tests/manifest.test.ts +0 -226
  301. package/tests/maskinputs.test.ts +0 -150
  302. package/tests/matrixverify.test.ts +0 -111
  303. package/tests/mavenpack.test.ts +0 -75
  304. package/tests/mcpserver.test.ts +0 -704
  305. package/tests/memory.test.ts +0 -4155
  306. package/tests/memorycare.test.ts +0 -230
  307. package/tests/migrateplan.test.ts +0 -349
  308. package/tests/minimization.test.ts +0 -414
  309. package/tests/modelroute.test.ts +0 -112
  310. package/tests/multiagent.test.ts +0 -440
  311. package/tests/nativebridge.test.ts +0 -807
  312. package/tests/navigation.test.ts +0 -284
  313. package/tests/nugetpack.test.ts +0 -83
  314. package/tests/orchestration.test.ts +0 -449
  315. package/tests/originpolicy.test.ts +0 -405
  316. package/tests/outputcompare.test.ts +0 -97
  317. package/tests/package.test.ts +0 -91
  318. package/tests/pagebridge.test.ts +0 -5909
  319. package/tests/pentest.test.ts +0 -75
  320. package/tests/perfrecords.test.ts +0 -257
  321. package/tests/permdiff.test.ts +0 -85
  322. package/tests/phishguard.test.ts +0 -128
  323. package/tests/pickerviews.test.ts +0 -155
  324. package/tests/pipelines.test.ts +0 -381
  325. package/tests/planlint.test.ts +0 -240
  326. package/tests/planreview.test.ts +0 -383
  327. package/tests/platformtargets.test.ts +0 -56
  328. package/tests/policy.test.ts +0 -8284
  329. package/tests/portability.test.ts +0 -96
  330. package/tests/progress.test.ts +0 -1036
  331. package/tests/promptlibrary.test.ts +0 -116
  332. package/tests/protocol.test.ts +0 -4793
  333. package/tests/publishingpipeline.test.ts +0 -314
  334. package/tests/quickactions.test.ts +0 -164
  335. package/tests/readiness.test.ts +0 -78
  336. package/tests/recipes.test.ts +0 -163
  337. package/tests/redactshots.test.ts +0 -216
  338. package/tests/registernvidiakeys.ts +0 -51
  339. package/tests/relayserve.test.ts +0 -304
  340. package/tests/releasenotes.test.ts +0 -276
  341. package/tests/resilience.test.ts +0 -467
  342. package/tests/resourceaware.test.ts +0 -187
  343. package/tests/runbudget.test.ts +0 -125
  344. package/tests/runhistory.test.ts +0 -299
  345. package/tests/runreplay.test.ts +0 -113
  346. package/tests/runresume.test.ts +0 -184
  347. package/tests/runstate.test.ts +0 -288
  348. package/tests/runtimeadapters.test.ts +0 -251
  349. package/tests/safariskeleton.test.ts +0 -115
  350. package/tests/sandboxframe.test.ts +0 -196
  351. package/tests/sbom.test.ts +0 -105
  352. package/tests/secretvault.test.ts +0 -188
  353. package/tests/selcache.test.ts +0 -111
  354. package/tests/sessioninterface.test.ts +0 -791
  355. package/tests/sessions.test.ts +0 -591
  356. package/tests/siteprefs.test.ts +0 -228
  357. package/tests/snapshotdelta.test.ts +0 -165
  358. package/tests/statusviews.test.ts +0 -237
  359. package/tests/stepmeter.test.ts +0 -200
  360. package/tests/streamparse.test.ts +0 -163
  361. package/tests/stylepruning.test.ts +0 -90
  362. package/tests/surfaces.test.ts +0 -282
  363. package/tests/sweep.test.ts +0 -78
  364. package/tests/syncbridge.test.ts +0 -164
  365. package/tests/taskqueue.test.ts +0 -206
  366. package/tests/toolcalls.test.ts +0 -336
  367. package/tests/toolcatalog.test.ts +0 -201
  368. package/tests/torture-agent.test.ts +0 -706
  369. package/tests/torture-auth.test.ts +0 -461
  370. package/tests/torture-commands.test.ts +0 -895
  371. package/tests/torture-data.test.ts +0 -923
  372. package/tests/torture-environments.test.ts +0 -285
  373. package/tests/torture-export.test.ts +0 -263
  374. package/tests/torture-http.test.ts +0 -1379
  375. package/tests/torture-llm.test.ts +0 -808
  376. package/tests/torture-memory.test.ts +0 -1084
  377. package/tests/torture-plan.test.ts +0 -829
  378. package/tests/torture-run.test.ts +0 -626
  379. package/tests/torture-session.test.ts +0 -928
  380. package/tests/torture-swarm.test.ts +0 -1245
  381. package/tests/torture-tools.test.ts +0 -964
  382. package/tests/torture-workflow.test.ts +0 -2354
  383. package/tests/tourviews.test.ts +0 -52
  384. package/tests/transparency.test.ts +0 -147
  385. package/tests/trigger.test.ts +0 -941
  386. package/tests/v1sunset.test.ts +0 -428
  387. package/tests/virtlist.test.ts +0 -94
  388. package/tests/vision.test.ts +0 -540
  389. package/tests/vsixpack.test.ts +0 -145
  390. package/tests/webapi.test.ts +0 -523
  391. package/tests/workflow.test.ts +0 -1785
  392. package/tests/workfloweditor.test.ts +0 -759
  393. package/tests/xpipack.test.ts +0 -128
  394. package/tools.ts +0 -734
  395. package/types.ts +0 -9908
  396. package/umd.ts +0 -9
  397. package/utils.ts +0 -249
  398. package/version.ts +0 -8
  399. package/versionregistry.ts +0 -1310
  400. package/views.ts +0 -2153
  401. package/vitest.config.ts +0 -12
  402. package/web/App.tsx +0 -78
  403. package/web/README.md +0 -47
  404. package/web/capacitor.config.ts +0 -46
  405. package/web/const.ts +0 -19
  406. package/web/control.shell.tsx +0 -66
  407. package/web/dashboardpage.ts +0 -554
  408. package/web/db.ts +0 -493
  409. package/web/design.html +0 -541
  410. package/web/gatewayview/Gateway.tsx +0 -345
  411. package/web/gatewayview/config.ts +0 -1042
  412. package/web/gatewayview/definition.ts +0 -174
  413. package/web/icons.ts +0 -15
  414. package/web/optionspage.ts +0 -691
  415. package/web/popup.ts +0 -1651
  416. package/web/schema.prisma +0 -176
  417. package/web/sidepanel.ts +0 -7941
  418. package/web/sitemanifest.json +0 -13
  419. package/web/terminal-ui.tsx +0 -622
  420. package/web/transparencypage.ts +0 -541
  421. package/web/vite.config.ts +0 -39
  422. package/web/workspace.ts +0 -23
  423. package/workbenchmemory.ts +0 -104
  424. package/workbenchsession.ts +0 -304
  425. package/workflow.ts +0 -4495
  426. /package/{dist/bun.d.ts → bun.d.ts} +0 -0
  427. /package/{dist/cli.d.ts → cli.d.ts} +0 -0
  428. /package/{dist/companion.d.ts → companion.d.ts} +0 -0
  429. /package/{dist/crossbrowser.d.ts → crossbrowser.d.ts} +0 -0
  430. /package/{dist/dashdone.d.ts → dashdone.d.ts} +0 -0
  431. /package/{dist/deno.d.ts → deno.d.ts} +0 -0
  432. /package/{dist/hardening.d.ts → hardening.d.ts} +0 -0
  433. /package/{dist/headless.d.ts → headless.d.ts} +0 -0
  434. /package/{dist/http.d.ts → http.d.ts} +0 -0
  435. /package/{dist/index.d.ts → index.d.ts} +0 -0
  436. /package/{dist/mcp.d.ts → mcp.d.ts} +0 -0
  437. /package/{dist/memory.d.ts → memory.d.ts} +0 -0
  438. /package/{dist/node.d.ts → node.d.ts} +0 -0
  439. /package/{dist/pack.d.ts → pack.d.ts} +0 -0
  440. /package/{dist/policy.d.ts → policy.d.ts} +0 -0
  441. /package/{dist/progress.d.ts → progress.d.ts} +0 -0
  442. /package/{dist/protocol.d.ts → protocol.d.ts} +0 -0
  443. /package/{dist/server.d.ts → server.d.ts} +0 -0
  444. /package/{dist/umd.d.ts → umd.d.ts} +0 -0
@@ -1,941 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { composeworkflow, newworkflowrun, workflowstepof } from "../workflow.js";
3
- import {
4
- applycooldown,
5
- armrule,
6
- confirmmanualrun,
7
- cronnext,
8
- cronparse,
9
- defaulttriggercooldown,
10
- drainqueue,
11
- evaluatetrigger,
12
- eventrulematches,
13
- listdue,
14
- manualpreview,
15
- matchurl,
16
- observeevents,
17
- pauseall,
18
- queuefire,
19
- resumeall,
20
- ruleoriginsgranted,
21
- runurllist,
22
- schedulecron,
23
- scheduleinterval,
24
- timezonevalid,
25
- triggereventcatalog,
26
- triggerfamilyof,
27
- triggerkinds,
28
- triggersummary,
29
- updaterule,
30
- verifywebhook,
31
- visitmatch,
32
- webhooksecretok,
33
- } from "../workflow.js";
34
- import {
35
- actionrisk,
36
- canexecute,
37
- isworkflowkind,
38
- istriggeraction,
39
- triggergate,
40
- triggerorigins,
41
- validatestep,
42
- } from "../policy.js";
43
- import { manualrunpreview, outcomeresponse, parseproposal, triggerfired, triggerlist } from "../protocol.js";
44
- import { protocolversion } from "../types.js";
45
- import { recordtrigger, triggerevidences } from "../progress.js";
46
- import { sessionmemory } from "../memory.js";
47
- import type {
48
- agentplan,
49
- agentsession,
50
- manualrun,
51
- toolstep,
52
- triggerfire,
53
- triggerule,
54
- workflowrecord,
55
- } from "../types.js";
56
-
57
- const now = 1_800_000_000_000;
58
- const session: agentsession = {
59
- id: "sess",
60
- tabid: 4,
61
- origin: "https://example.com",
62
- startedat: now - 1000,
63
- expiresat: now + 600_000,
64
- grants: ["https://example.com"],
65
- };
66
- const plan: agentplan = {
67
- id: "run",
68
- objective: "Run the reviewed triggers",
69
- origin: "https://example.com",
70
- steps: [],
71
- createdat: now - 2000,
72
- expiresat: now + 600_000,
73
- state: "approved",
74
- };
75
-
76
- function kindallowed(kind: string): boolean {
77
- try {
78
- actionrisk(kind as toolstep["kind"]);
79
- return true;
80
- } catch {
81
- return false;
82
- }
83
- }
84
- function riskof(kind: string): "read" | "interaction" | "sensitive" {
85
- return actionrisk(kind as toolstep["kind"]);
86
- }
87
-
88
- /** Builds one trigger step of the given family with its reviewed rule payload. */
89
- function triggerstep(kind: string, payload: Record<string, unknown>, extra: Record<string, unknown> = {}): toolstep {
90
- return {
91
- id: "t1",
92
- kind: kind as toolstep["kind"],
93
- summary: `The reviewed ${kind} step`,
94
- risk: "sensitive",
95
- options: JSON.stringify({ workflowid: "wf1", reviewed: true, rule: payload, ...extra }),
96
- };
97
- }
98
-
99
- /** Arms one rule of the given family through the engine normalizer. */
100
- function armedrule(kind: string, payload: Record<string, unknown>, extra: Record<string, unknown> = {}): triggerule {
101
- const family = triggerfamilyof(kind);
102
- if (!family) throw new Error(`The ${kind} step is not a trigger kind.`);
103
- const rule = armrule({ family, workflowid: "wf1", payload, ...extra, now });
104
- if (!rule) throw new Error(`The ${kind} rule did not arm.`);
105
- return rule;
106
- }
107
-
108
- class fakeadapter {
109
- private readonly data = new Map<string, unknown>();
110
- async get<T>(key: string): Promise<T | undefined> {
111
- return this.data.get(key) as T | undefined;
112
- }
113
- async set<T>(key: string, value: T): Promise<void> {
114
- this.data.set(key, value);
115
- }
116
- }
117
-
118
- describe("trigger kinds, families and rule arming", () => {
119
- it("lists the ten trigger kinds and grades every automatic launcher sensitive", () => {
120
- expect(triggerkinds).toEqual([
121
- "visitrule",
122
- "urlrule",
123
- "menurule",
124
- "keyrule",
125
- "buttonrule",
126
- "cronrule",
127
- "intervalrule",
128
- "urllistrule",
129
- "webhookrule",
130
- "eventrule",
131
- ]);
132
- for (const kind of triggerkinds) {
133
- expect(istriggeraction(kind as toolstep["kind"])).toBe(true);
134
- expect(isworkflowkind(kind as toolstep["kind"])).toBe(false);
135
- expect(kindallowed(kind)).toBe(true);
136
- expect(actionrisk(kind as toolstep["kind"])).toBe("sensitive");
137
- expect(triggerfamilyof(kind)).toBeDefined();
138
- }
139
- expect(istriggeraction("runworkflow")).toBe(false);
140
- expect(triggerfamilyof("click")).toBeUndefined();
141
- });
142
-
143
- it("arms every family behind its grammar and applies the documented webhook and event cooldown defaults", () => {
144
- expect(armedrule("visitrule", { origins: ["https://example.com"] }).state.cooldown).toBe(0);
145
- expect(armedrule("urlrule", { pattern: "https://example.com/*/detail" }).pattern).toBe(
146
- "https://example.com/*/detail",
147
- );
148
- expect(armedrule("menurule", { title: "Run the reader" }).title).toBe("Run the reader");
149
- expect(armedrule("keyrule", { command: "run-reader", key: "Ctrl+Shift+R" }).command).toBe("run-reader");
150
- expect(armedrule("buttonrule", {}).kind).toBe("button");
151
- expect(armedrule("cronrule", { cron: "*/15 * * * *", timezone: "America/New_York" }).timezone).toBe(
152
- "America/New_York",
153
- );
154
- expect(armedrule("intervalrule", { period: 60_000, jitter: 10_000 }).jitter).toBe(10_000);
155
- expect(armedrule("urllistrule", { urls: ["https://example.com/a", "https://example.com/b"] }).urls).toHaveLength(2);
156
- expect(
157
- armedrule("webhookrule", {
158
- secret: "devthink-secret-2026-abc123",
159
- schema: [{ name: "task", kind: "string", required: true }],
160
- }).state.cooldown,
161
- ).toBe(defaulttriggercooldown);
162
- expect(armedrule("eventrule", { events: ["mutate", "navigate"] }).state.cooldown).toBe(defaulttriggercooldown);
163
- expect(armedrule("eventrule", { events: ["mutate"] }, { cooldown: 60_000 }).state.cooldown).toBe(60_000);
164
- });
165
-
166
- it("refuses malformed family payloads and cooldown windows", () => {
167
- expect(
168
- armrule({ family: "visit", workflowid: "wf1", payload: { origins: ["http://insecure.example"] }, now }),
169
- ).toBeUndefined();
170
- expect(armrule({ family: "visit", workflowid: "wf1", payload: { origins: [] }, now })).toBeUndefined();
171
- expect(armrule({ family: "url", workflowid: "wf1", payload: { pattern: "example.com/*" }, now })).toBeUndefined();
172
- expect(armrule({ family: "cron", workflowid: "wf1", payload: { cron: "not a cron" }, now })).toBeUndefined();
173
- expect(
174
- armrule({ family: "cron", workflowid: "wf1", payload: { cron: "* * * * *", timezone: "Not/AZone" }, now }),
175
- ).toBeUndefined();
176
- expect(armrule({ family: "interval", workflowid: "wf1", payload: { period: 0 }, now })).toBeUndefined();
177
- expect(
178
- armrule({ family: "interval", workflowid: "wf1", payload: { period: 1000, jitter: -1 }, now }),
179
- ).toBeUndefined();
180
- expect(
181
- armrule({ family: "urllist", workflowid: "wf1", payload: { urls: ["https://example.com/a", "nope"] }, now }),
182
- ).toBeUndefined();
183
- expect(
184
- armrule({
185
- family: "webhook",
186
- workflowid: "wf1",
187
- payload: { secret: "short", schema: [{ name: "task", kind: "string" }] },
188
- now,
189
- }),
190
- ).toBeUndefined();
191
- expect(
192
- armrule({
193
- family: "webhook",
194
- workflowid: "wf1",
195
- payload: { secret: "devthink-secret-2026-abc123", schema: [] },
196
- now,
197
- }),
198
- ).toBeUndefined();
199
- expect(armrule({ family: "event", workflowid: "wf1", payload: { events: ["nope"] }, now })).toBeUndefined();
200
- expect(
201
- armrule({ family: "event", workflowid: "wf1", payload: { events: ["mutate"] }, cooldown: 0, now }),
202
- ).toBeUndefined();
203
- expect(armrule({ family: "event", workflowid: "", payload: { events: ["mutate"] }, now })).toBeUndefined();
204
- expect(timezonevalid("America/New_York")).toBe(true);
205
- expect(timezonevalid("Mars/Olympus")).toBe(false);
206
- });
207
-
208
- it("summarizes every family for the review panel and checks the rule origins against the workflow grants", () => {
209
- expect(triggersummary(armedrule("cronrule", { cron: "0 9 * * *" })).cron).toBe("0 9 * * *");
210
- expect(
211
- triggersummary(
212
- armedrule("webhookrule", { secret: "devthink-secret-2026-abc123", schema: [{ name: "task", kind: "string" }] }),
213
- ).fields,
214
- ).toBe(1);
215
- const visit = armedrule("visitrule", { origins: ["https://example.com"] });
216
- expect(ruleoriginsgranted(visit, ["https://example.com"])).toBe(true);
217
- expect(ruleoriginsgranted(visit, ["https://other.example"])).toBe(false);
218
- const list = armedrule("urllistrule", { urls: ["https://example.com/a", "https://elsewhere.example/b"] });
219
- expect(ruleoriginsgranted(list, ["https://example.com"])).toBe(false);
220
- const pattern = armedrule("urlrule", { pattern: "https://example.com/*" });
221
- expect(ruleoriginsgranted(pattern, ["https://example.com"])).toBe(true);
222
- expect(ruleoriginsgranted(armedrule("buttonrule", {}), [])).toBe(true);
223
- });
224
- });
225
-
226
- describe("trigger url matching", () => {
227
- it("matches glob patterns across segments and honors explicit ports", () => {
228
- expect(matchurl("https://example.com/*/detail", "https://example.com/a/detail")).toBe(true);
229
- expect(matchurl("https://example.com/*/detail", "https://example.com/a/b/detail")).toBe(false);
230
- expect(matchurl("https://example.com/**/detail", "https://example.com/a/b/detail")).toBe(true);
231
- expect(matchurl("https://example.com/articles/*?id=*", "https://example.com/articles/one?id=7")).toBe(true);
232
- expect(matchurl("https://example.com/*", "https://other.example/x")).toBe(false);
233
- expect(matchurl("https://example.com/*", "http://example.com/x")).toBe(false);
234
- expect(matchurl("https://example.com:8443/*", "https://example.com:8443/x")).toBe(true);
235
- expect(matchurl("https://example.com:8443/*", "https://example.com/x")).toBe(false);
236
- expect(matchurl("https://example.com/*", "https://example.com:8443/x")).toBe(true);
237
- expect(matchurl("https://example.com/*", "not a url")).toBe(false);
238
- });
239
-
240
- it("fires visit rules when a navigation lands on a reviewed origin", () => {
241
- const rule = armedrule("visitrule", { origins: ["https://example.com", "https://docs.example.com"] });
242
- expect(visitmatch(rule.origins as string[], "https://example.com/articles/one")).toBe(true);
243
- expect(visitmatch(rule.origins as string[], "https://docs.example.com/guide")).toBe(true);
244
- expect(visitmatch(rule.origins as string[], "https://other.example/articles/one")).toBe(false);
245
- expect(visitmatch(rule.origins as string[], "about:blank")).toBe(false);
246
- const decision = evaluatetrigger({
247
- rule,
248
- now,
249
- cause: "visit",
250
- url: "https://example.com/articles/one",
251
- title: "One",
252
- runactive: false,
253
- workflowreviewed: true,
254
- });
255
- expect(decision.fired).toBe(true);
256
- expect(decision.fire?.url).toBe("https://example.com/articles/one");
257
- expect(decision.fire?.title).toBe("One");
258
- expect(decision.fire?.ruleid).toBe(rule.id);
259
- });
260
- });
261
-
262
- describe("cron parsing and scheduling", () => {
263
- it("parses five field expressions with lists, ranges, steps and named weekdays and months", () => {
264
- expect(cronparse("*/15 * * * *")?.minutes).toEqual([0, 15, 30, 45]);
265
- expect(cronparse("0,30 9-17 * * *")?.hours).toEqual([9, 10, 11, 12, 13, 14, 15, 16, 17]);
266
- expect(cronparse("0 0 1 jan *")?.months).toEqual([1]);
267
- expect(cronparse("0 9 * * mon-fri")?.daysofweek).toEqual([1, 2, 3, 4, 5]);
268
- expect(cronparse("0 0 * * 7")?.daysofweek).toEqual([0]);
269
- expect(cronparse("5 4 * * sun,sat")?.daysofweek).toEqual([0, 6]);
270
- expect(cronparse("1-10/3 * * * *")?.minutes).toEqual([1, 4, 7, 10]);
271
- expect(cronparse("* * * * *")?.minutes).toHaveLength(60);
272
- expect(cronparse("61 * * * *")).toBeUndefined();
273
- expect(cronparse("* 24 * * *")).toBeUndefined();
274
- expect(cronparse("* * 0 * *")).toBeUndefined();
275
- expect(cronparse("* * * 13 *")).toBeUndefined();
276
- expect(cronparse("not a cron")).toBeUndefined();
277
- expect(cronparse("* * * *")).toBeUndefined();
278
- expect(cronparse("60 * * * *")).toBeUndefined();
279
- expect(cronparse("5-1 * * * *")).toBeUndefined();
280
- });
281
-
282
- it("computes the next fire time on minute boundaries and walks sparse schedules", () => {
283
- const from = Date.UTC(2026, 0, 15, 8, 59, 30);
284
- expect(cronnext("*/15 * * * *", from)).toBe(Date.UTC(2026, 0, 15, 9, 0));
285
- expect(cronnext("30,45 * * * *", Date.UTC(2026, 0, 15, 9, 10))).toBe(Date.UTC(2026, 0, 15, 9, 30));
286
- expect(cronnext("0 9 * * *", Date.UTC(2026, 0, 15, 9, 0))).toBe(Date.UTC(2026, 0, 16, 9, 0));
287
- expect(cronnext("0 9 * * mon", Date.UTC(2026, 0, 15, 10, 0))).toBe(Date.UTC(2026, 0, 19, 9, 0));
288
- expect(cronnext("0 0 1 jan *", Date.UTC(2026, 5, 1))).toBe(Date.UTC(2027, 0, 1, 0, 0));
289
- expect(cronnext("0 0 29 2 *", Date.UTC(2026, 0, 1))).toBe(Date.UTC(2028, 1, 29, 0, 0));
290
- expect(cronnext("0 0 30 2 *", Date.UTC(2026, 0, 1))).toBeUndefined();
291
- expect(cronnext("bad", Date.UTC(2026, 0, 1))).toBeUndefined();
292
- });
293
-
294
- it("honors the classic day of month and day of week or semantics", () => {
295
- expect(cronnext("0 0 1 * 1", Date.UTC(2025, 11, 31, 12, 0))).toBe(Date.UTC(2026, 0, 1, 0, 0));
296
- expect(cronnext("0 0 1 * 1", Date.UTC(2026, 0, 1, 1, 0))).toBe(Date.UTC(2026, 0, 5, 0, 0));
297
- });
298
-
299
- it("computes cron fire times inside the reviewed timezone through the runtime timezone database", () => {
300
- const utcfrom = Date.UTC(2026, 0, 15, 13, 0, 0);
301
- expect(cronnext("0 9 * * *", utcfrom, "America/New_York")).toBe(Date.UTC(2026, 0, 15, 14, 0));
302
- expect(cronnext("0 9 * * *", Date.UTC(2026, 0, 15, 14, 0), "America/New_York")).toBe(Date.UTC(2026, 0, 16, 14, 0));
303
- expect(schedulecron({ cron: "0 9 * * *", timezone: "America/New_York" }, utcfrom)).toBe(
304
- Date.UTC(2026, 0, 15, 14, 0),
305
- );
306
- });
307
-
308
- it("spreads interval fires inside the reviewed jitter window with the seeded random source", () => {
309
- const samples = new Set<number>();
310
- for (let seed = 0; seed < 200; seed += 1)
311
- samples.add(scheduleinterval({ period: 60_000, jitter: 20_000 }, 1_000_000, 500_000, seed));
312
- expect(samples.size).toBeGreaterThan(100);
313
- for (const sample of samples) {
314
- expect(sample).toBeGreaterThanOrEqual(1_060_000 - 10_000);
315
- expect(sample).toBeLessThanOrEqual(1_060_000 + 10_000);
316
- }
317
- expect(scheduleinterval({ period: 60_000 }, 1_000_000, 500_000, 1)).toBe(1_060_000);
318
- expect(scheduleinterval({ period: 60_000, jitter: 0 }, 1_000_000, 500_000, 1)).toBe(1_060_000);
319
- });
320
-
321
- it("returns the scheduled rules whose next fire time has passed", () => {
322
- const due = armedrule("cronrule", { cron: "* * * * *" });
323
- const later = armedrule("cronrule", { cron: "0 0 1 1 *" });
324
- const interval = armedrule("intervalrule", { period: 1000 });
325
- const disabled = updaterule(armedrule("cronrule", { cron: "* * * * *" }), { state: { enabled: false } });
326
- const paused = updaterule(armedrule("cronrule", { cron: "* * * * *" }), { state: { pausedat: now } });
327
- const listed = listdue(
328
- [
329
- { ...due, state: { ...due.state, nextfireat: now - 5000 } },
330
- { ...later, state: { ...later.state, nextfireat: now + 500_000 } },
331
- { ...interval, state: { ...interval.state, nextfireat: now - 1 } },
332
- { ...disabled, state: { ...disabled.state, nextfireat: now - 1 } },
333
- { ...paused, state: { ...paused.state, nextfireat: now - 1 } },
334
- ],
335
- now,
336
- );
337
- expect(listed.map((entry) => entry.rule.kind)).toEqual(["cron", "interval"]);
338
- expect(listed[0]?.overdueby).toBe(5000);
339
- });
340
- });
341
-
342
- describe("trigger evaluation, cooldown, dedupe and the queue", () => {
343
- it("suppresses fires inside the cooldown window and reports the remaining window", () => {
344
- const rule = armedrule("eventrule", { events: ["mutate"] }, { cooldown: 60_000 });
345
- const cooled = { ...rule, state: { ...rule.state, lastfireat: now - 10_000 } };
346
- expect(applycooldown(cooled, now).suppressed).toBe(true);
347
- expect(applycooldown(cooled, now).remaining).toBe(50_000);
348
- const decision = evaluatetrigger({ rule: cooled, now, cause: "event", runactive: false, workflowreviewed: true });
349
- expect(decision.fired).toBe(false);
350
- expect(decision.suppressed).toBe("cooldown");
351
- expect(decision.remaining).toBe(50_000);
352
- expect(
353
- evaluatetrigger({
354
- rule: { ...cooled, state: { ...cooled.state, lastfireat: now - 60_000 } },
355
- now,
356
- cause: "event",
357
- runactive: false,
358
- workflowreviewed: true,
359
- }).fired,
360
- ).toBe(true);
361
- });
362
-
363
- it("never fires disabled, paused or unreviewed rules and dedupes while a run is active", () => {
364
- const rule = armedrule("visitrule", { origins: ["https://example.com"] });
365
- expect(
366
- evaluatetrigger({
367
- rule: updaterule(rule, { state: { enabled: false } }),
368
- now,
369
- cause: "visit",
370
- runactive: false,
371
- workflowreviewed: true,
372
- }).suppressed,
373
- ).toBe("disabled");
374
- expect(
375
- evaluatetrigger({
376
- rule: updaterule(rule, { state: { pausedat: now } }),
377
- now,
378
- cause: "visit",
379
- runactive: false,
380
- workflowreviewed: true,
381
- }).suppressed,
382
- ).toBe("paused");
383
- expect(evaluatetrigger({ rule, now, cause: "visit", runactive: false, workflowreviewed: false }).suppressed).toBe(
384
- "unreviewed",
385
- );
386
- expect(evaluatetrigger({ rule, now, cause: "visit", runactive: true, workflowreviewed: true }).suppressed).toBe(
387
- "dedupe",
388
- );
389
- });
390
-
391
- it("keeps one pending fire per rule in the queue while a run is active", () => {
392
- const first: triggerfire = { id: "f1", ruleid: "r1", at: now, cause: "visit", url: "https://example.com/a" };
393
- const second: triggerfire = { id: "f2", ruleid: "r1", at: now + 1, cause: "visit", url: "https://example.com/b" };
394
- const other: triggerfire = { id: "f3", ruleid: "r2", at: now + 2, cause: "visit" };
395
- const queued = queuefire([], first);
396
- expect(queued.queued).toBe(true);
397
- const deduped = queuefire(queued.queue, second);
398
- expect(deduped.deduped).toBe(true);
399
- expect(deduped.queue).toHaveLength(1);
400
- const both = queuefire(deduped.queue, other);
401
- expect(both.queue).toHaveLength(2);
402
- expect(both.queued).toBe(true);
403
- });
404
-
405
- it("drains the queued fires in arrival order and keeps the rest when a launch fails", async () => {
406
- const fires: triggerfire[] = [
407
- { id: "f1", ruleid: "r1", at: now, cause: "visit" },
408
- { id: "f2", ruleid: "r2", at: now + 1, cause: "url" },
409
- ];
410
- const launched: string[] = [];
411
- const drained = await drainqueue(fires, async (fire) => {
412
- launched.push(fire.id);
413
- });
414
- expect(launched).toEqual(["f1", "f2"]);
415
- expect(drained).toEqual({ launched: 2, remaining: [] });
416
- const failing = await drainqueue(fires, async (fire) => {
417
- if (fire.id === "f1") throw new Error("the run refused the launch");
418
- launched.push(fire.id);
419
- });
420
- expect(failing.launched).toBe(0);
421
- expect(failing.remaining).toHaveLength(2);
422
- });
423
-
424
- it("suspends every enabled rule on session pause and releases them on resume", () => {
425
- const rules = [
426
- armedrule("visitrule", { origins: ["https://example.com"] }),
427
- armedrule("cronrule", { cron: "* * * * *" }),
428
- updaterule(armedrule("eventrule", { events: ["mutate"] }), { state: { enabled: false } }),
429
- ];
430
- const paused = pauseall(rules, now);
431
- expect(paused.filter((rule) => rule.state.pausedat !== undefined)).toHaveLength(2);
432
- const resumed = resumeall(paused);
433
- expect(resumed.every((rule) => rule.state.pausedat === undefined)).toBe(true);
434
- expect(resumed[2]?.state.enabled).toBe(false);
435
- });
436
-
437
- it("plans one run per url of a url list rule", () => {
438
- const rule = armedrule("urllistrule", {
439
- urls: ["https://example.com/a", "https://example.com/b", "https://example.com/c"],
440
- });
441
- const fires = runurllist(rule, now);
442
- expect(fires).toHaveLength(3);
443
- expect(fires.every((fire) => fire.ruleid === rule.id && fire.cause === "urllist")).toBe(true);
444
- expect(fires.map((fire) => fire.url)).toEqual([
445
- "https://example.com/a",
446
- "https://example.com/b",
447
- "https://example.com/c",
448
- ]);
449
- });
450
- });
451
-
452
- describe("webhook verification and page event subscription", () => {
453
- it("verifies the shared secret and the payload schema before anything persists", () => {
454
- const rule = armedrule("webhookrule", {
455
- secret: "devthink-secret-2026-abc123",
456
- schema: [
457
- { name: "task", kind: "string", required: true },
458
- { name: "count", kind: "number" },
459
- { name: "urgent", kind: "boolean" },
460
- ],
461
- });
462
- expect(
463
- verifywebhook({ rule, secret: "devthink-secret-2026-abc123", payload: { task: "read", count: 3 } }).verified,
464
- ).toBe(true);
465
- expect(verifywebhook({ rule, secret: "wrong-secret-2026-abc1234", payload: { task: "read" } }).reason).toContain(
466
- "secret",
467
- );
468
- expect(verifywebhook({ rule, secret: "devthink-secret-2026-abc123", payload: { count: 3 } }).reason).toContain(
469
- "task",
470
- );
471
- expect(verifywebhook({ rule, secret: "devthink-secret-2026-abc123", payload: { task: 7 } }).reason).toContain(
472
- "task",
473
- );
474
- expect(
475
- verifywebhook({ rule, secret: "devthink-secret-2026-abc123", payload: { task: "read", urgent: "yes" } }).reason,
476
- ).toContain("urgent");
477
- expect(verifywebhook({ rule, secret: "devthink-secret-2026-abc123", payload: "not an object" }).reason).toContain(
478
- "object",
479
- );
480
- expect(
481
- verifywebhook({ rule: { ...rule, secret: undefined } as unknown as triggerule, secret: "", payload: {} })
482
- .verified,
483
- ).toBe(false);
484
- expect(webhooksecretok("devthink-secret-2026-abc123")).toBe(true);
485
- expect(webhooksecretok("short")).toBe(false);
486
- expect(webhooksecretok("aaaaaaaaaaaaaaaaaaaaaaaa")).toBe(false);
487
- expect(webhooksecretok("123456789012345678901234")).toBe(false);
488
- });
489
-
490
- it("subscribes event rules to the observed event catalog only", () => {
491
- expect(triggereventcatalog).toEqual(["mutate", "focus", "banner", "console", "error", "navigate"]);
492
- const rule = armedrule("eventrule", { events: ["mutate", "navigate"] });
493
- expect(eventrulematches(rule, "mutate")).toBe(true);
494
- expect(eventrulematches(rule, "focus")).toBe(false);
495
- const decision = evaluatetrigger({
496
- rule,
497
- now,
498
- cause: "event",
499
- payload: { event: "mutate" },
500
- runactive: false,
501
- workflowreviewed: true,
502
- });
503
- expect(decision.fire?.payload).toEqual({ event: "mutate" });
504
- expect(observeevents([rule], "mutate")).toEqual([rule]);
505
- expect(observeevents([rule], "focus")).toEqual([]);
506
- expect(observeevents([rule], "unknown")).toEqual([]);
507
- const disabled = updaterule(rule, { state: { enabled: false } });
508
- expect(observeevents([disabled], "mutate")).toEqual([]);
509
- const paused = updaterule(rule, { state: { pausedat: now } });
510
- expect(observeevents([paused], "mutate")).toEqual([]);
511
- const visitrule = armedrule("visitrule", { origins: ["https://example.com"] });
512
- expect(observeevents([visitrule], "navigate")).toEqual([]);
513
- });
514
- });
515
-
516
- describe("manual runs with the step preview", () => {
517
- it("renders the expanded step preview with control summaries before anything runs", () => {
518
- const record: workflowrecord = composeworkflow({
519
- id: "wf1",
520
- name: "reader",
521
- version: 1,
522
- origins: ["https://example.com"],
523
- steps: [
524
- workflowstepof({ id: "s1", kind: "readtext", label: "Read the heading", target: "h1" }) as never,
525
- {
526
- id: "s2",
527
- kind: "branch",
528
- label: "Branch by title",
529
- options: JSON.stringify({
530
- branch: {
531
- paths: [
532
- {
533
- name: "short",
534
- when: {
535
- left: { ref: "title" },
536
- right: { literal: "x" },
537
- operator: "contains",
538
- result: "match",
539
- resultkind: "boolean",
540
- },
541
- steps: [{ id: "s3", kind: "wait", label: "Wait a beat", value: "10" }],
542
- },
543
- ],
544
- else: { name: "else", steps: [{ id: "s4", kind: "wait", label: "Wait longer", value: "20" }] },
545
- },
546
- }),
547
- } as never,
548
- ],
549
- now,
550
- kindallowed,
551
- riskof,
552
- });
553
- const preview = manualpreview(record, now);
554
- expect(preview.workflowid).toBe("wf1");
555
- expect(preview.preview).toHaveLength(2);
556
- expect(preview.preview[1]?.control?.paths).toEqual(["short"]);
557
- expect(preview.preview[1]?.control?.elsepath).toBe("else");
558
- expect(preview.confirmed).toBeUndefined();
559
- const confirmed = confirmmanualrun(preview, true, now + 5);
560
- expect(confirmed.confirmed).toBe(true);
561
- expect(confirmed.decidedat).toBe(now + 5);
562
- expect(confirmmanualrun(preview, false, now + 6).confirmed).toBe(false);
563
- const envelope = manualrunpreview({ preview: confirmed, workflowname: record.name });
564
- expect(envelope.workflowname).toBe("reader");
565
- expect(envelope.manualrun.preview).toHaveLength(2);
566
- });
567
- });
568
-
569
- describe("trigger policy validation and sensitivity grading", () => {
570
- it("validates the grammar of every trigger kind", () => {
571
- expect(
572
- validatestep(triggerstep("visitrule", { origins: ["https://example.com"] }), "https://example.com").allowed,
573
- ).toBe(true);
574
- expect(
575
- validatestep(triggerstep("urlrule", { pattern: "https://example.com/*" }), "https://example.com").allowed,
576
- ).toBe(true);
577
- expect(validatestep(triggerstep("menurule", { title: "Run the reader" }), "https://example.com").allowed).toBe(
578
- true,
579
- );
580
- expect(validatestep(triggerstep("keyrule", { command: "run-reader" }), "https://example.com").allowed).toBe(true);
581
- expect(validatestep(triggerstep("buttonrule", {}), "https://example.com").allowed).toBe(true);
582
- expect(validatestep(triggerstep("cronrule", { cron: "*/15 * * * *" }), "https://example.com").allowed).toBe(true);
583
- expect(
584
- validatestep(triggerstep("intervalrule", { period: 60_000, jitter: 5_000 }), "https://example.com").allowed,
585
- ).toBe(true);
586
- expect(
587
- validatestep(triggerstep("urllistrule", { urls: ["https://example.com/a"] }), "https://example.com").allowed,
588
- ).toBe(true);
589
- expect(
590
- validatestep(
591
- triggerstep("webhookrule", {
592
- secret: "devthink-secret-2026-abc123",
593
- schema: [{ name: "task", kind: "string", required: true }],
594
- }),
595
- "https://example.com",
596
- ).allowed,
597
- ).toBe(true);
598
- expect(validatestep(triggerstep("eventrule", { events: ["mutate"] }), "https://example.com").allowed).toBe(true);
599
- expect(
600
- validatestep(triggerstep("eventrule", { events: ["mutate"] }, { label: "Panel rule" }), "https://example.com")
601
- .allowed,
602
- ).toBe(true);
603
- });
604
-
605
- it("refuses rules without the arm review, weak secrets, unparseable crons and unknown events", () => {
606
- expect(
607
- validatestep(
608
- triggerstep("visitrule", { origins: ["https://example.com"] }, { reviewed: false }),
609
- "https://example.com",
610
- ).reason,
611
- ).toContain("arm review");
612
- expect(
613
- validatestep(
614
- triggerstep("visitrule", { origins: ["https://example.com"] }, { workflowid: "" }),
615
- "https://example.com",
616
- ).reason,
617
- ).toContain("workflow");
618
- expect(validatestep(triggerstep("cronrule", { cron: "99 * * * *" }), "https://example.com").reason).toContain(
619
- "cron",
620
- );
621
- expect(
622
- validatestep(
623
- triggerstep("webhookrule", { secret: "short", schema: [{ name: "task", kind: "string" }] }),
624
- "https://example.com",
625
- ).reason,
626
- ).toContain("secret");
627
- expect(validatestep(triggerstep("eventrule", { events: ["nope"] }), "https://example.com").reason).toContain(
628
- "event",
629
- );
630
- expect(validatestep(triggerstep("intervalrule", { period: -1 }), "https://example.com").reason).toContain("period");
631
- expect(validatestep(triggerstep("urllistrule", { urls: [] }), "https://example.com").reason).toContain("url list");
632
- expect(validatestep(triggerstep("menurule", { title: "" }), "https://example.com").reason).toContain("menu");
633
- expect(validatestep(triggerstep("keyrule", { command: "Bad Command" }), "https://example.com").reason).toContain(
634
- "keyboard",
635
- );
636
- expect(
637
- validatestep(triggerstep("visitrule", { origins: ["http://insecure.example"] }), "https://example.com").reason,
638
- ).toContain("visit");
639
- expect(validatestep(triggerstep("urlrule", { pattern: "no-scheme/*" }), "https://example.com").reason).toContain(
640
- "url rule",
641
- );
642
- expect(
643
- validatestep(triggerstep("eventrule", { events: ["mutate"] }, { cooldown: 0 }), "https://example.com").reason,
644
- ).toContain("cooldown");
645
- expect(
646
- validatestep(triggerstep("eventrule", { events: ["mutate"] }, { label: "" }), "https://example.com").reason,
647
- ).toContain("label");
648
- expect(
649
- validatestep({ ...triggerstep("buttonrule", {}), kind: "nope" as toolstep["kind"] }, "https://example.com")
650
- .reason,
651
- ).toContain("Unsupported");
652
- });
653
-
654
- it("gates every trigger kind behind the live session, the approved plan and the arm review", () => {
655
- const step = triggerstep("visitrule", { origins: ["https://example.com"] });
656
- expect(triggergate({ session, plan, step, tabid: 4, origin: "https://example.com", now }).allowed).toBe(true);
657
- expect(triggergate({ session: undefined, plan, step, tabid: 4, origin: "https://example.com", now }).allowed).toBe(
658
- false,
659
- );
660
- expect(
661
- triggergate({ session: { ...session, stoppedat: now }, plan, step, tabid: 4, origin: "https://example.com", now })
662
- .allowed,
663
- ).toBe(false);
664
- expect(
665
- triggergate({ session, plan: { ...plan, state: "pending" }, step, tabid: 4, origin: "https://example.com", now })
666
- .reason,
667
- ).toContain("approved plan");
668
- expect(
669
- triggergate({
670
- session,
671
- plan,
672
- step: triggerstep("visitrule", { origins: ["https://example.com"] }, { reviewed: false }),
673
- tabid: 4,
674
- origin: "https://example.com",
675
- now,
676
- }).reason,
677
- ).toContain("arm review");
678
- expect(canexecute({ session: undefined, plan, step, tabid: 4, origin: "https://example.com", now }).allowed).toBe(
679
- false,
680
- );
681
- expect(canexecute({ session, plan, step, tabid: 4, origin: "https://example.com", now }).allowed).toBe(true);
682
- });
683
-
684
- it("extracts the match origins of a rule so proposals stay inside the grants", () => {
685
- expect(
686
- triggerorigins(triggerstep("visitrule", { origins: ["https://example.com", "https://example.com"] })),
687
- ).toEqual(["https://example.com"]);
688
- expect(triggerorigins(triggerstep("urlrule", { pattern: "https://example.com/*" }))).toEqual([
689
- "https://example.com",
690
- ]);
691
- expect(
692
- triggerorigins(triggerstep("urllistrule", { urls: ["https://example.com/a", "https://other.example/b"] })),
693
- ).toEqual(["https://example.com", "https://other.example"]);
694
- expect(triggerorigins(triggerstep("buttonrule", {}))).toEqual([]);
695
- expect(triggerorigins(triggerstep("visitrule", { origins: ["https://example.com"] }, { reviewed: false }))).toEqual(
696
- ["https://example.com"],
697
- );
698
- });
699
- });
700
-
701
- describe("trigger protocol envelopes", () => {
702
- it("builds the trigger list with workflow names, counters and the queue depth", () => {
703
- const cronrule = {
704
- ...armedrule("cronrule", { cron: "0 9 * * *" }),
705
- state: { ...armedrule("cronrule", { cron: "0 9 * * *" }).state, nextfireat: now + 3600_000 },
706
- };
707
- const unbound = armrule({ family: "button", workflowid: "wfmissing", payload: {}, now });
708
- if (!unbound) throw new Error("The button rule did not arm.");
709
- const list = triggerlist({
710
- rules: [cronrule, unbound],
711
- workflows: [
712
- {
713
- id: "wf1",
714
- name: "reader",
715
- version: 1,
716
- origins: ["https://example.com"],
717
- steps: [],
718
- blocks: [],
719
- risk: "read",
720
- createdat: now,
721
- },
722
- ],
723
- queue: [{ id: "f1", ruleid: "r1", at: now, cause: "visit" }],
724
- });
725
- expect(list.version).toBe(protocolversion);
726
- expect(list.queued).toBe(1);
727
- expect(list.rules[0]?.workflowname).toBe("reader");
728
- expect(list.rules[0]?.nextfireat).toBe(now + 3600_000);
729
- expect(list.rules[0]?.summary.cron).toBe("0 9 * * *");
730
- expect(list.rules[1]?.workflowname).toBeUndefined();
731
- });
732
-
733
- it("builds the trigger fired notification with the run binding and returns the next fire time per rule", () => {
734
- const fired = triggerfired({
735
- fire: {
736
- id: "f1",
737
- ruleid: "r1",
738
- at: now,
739
- cause: "webhook",
740
- url: "https://example.com",
741
- payload: { task: "read" },
742
- },
743
- workflowid: "wf1",
744
- runid: "run1",
745
- });
746
- expect(fired.triggerfired).toEqual({
747
- fireid: "f1",
748
- ruleid: "r1",
749
- workflowid: "wf1",
750
- at: now,
751
- cause: "webhook",
752
- url: "https://example.com",
753
- runid: "run1",
754
- });
755
- const body = JSON.parse(
756
- outcomeresponse({
757
- outcome: { stepid: "t1", ok: true, summary: "Armed.", at: now },
758
- plan,
759
- trigger: { ruleid: "r1", kind: "cron", enabled: true, nextfireat: now + 60_000 },
760
- }),
761
- );
762
- expect(body.trigger).toEqual({ ruleid: "r1", kind: "cron", enabled: true, nextfireat: now + 60_000 });
763
- const without = JSON.parse(
764
- outcomeresponse({ outcome: { stepid: "t1", ok: true, summary: "Armed.", at: now }, plan }),
765
- );
766
- expect(without.trigger).toBeUndefined();
767
- });
768
-
769
- it("refuses trigger proposals without the arm review or with origins outside the grants", () => {
770
- const proposal = parseproposal(
771
- {
772
- version: protocolversion,
773
- plan: {
774
- objective: "Arm triggers",
775
- steps: [
776
- {
777
- kind: "visitrule",
778
- options: JSON.stringify({
779
- workflowid: "wf1",
780
- reviewed: true,
781
- rule: { origins: ["https://example.com"] },
782
- }),
783
- summary: "Arm the visit rule.",
784
- },
785
- ],
786
- },
787
- },
788
- "https://example.com",
789
- );
790
- expect(proposal.plan.steps[0]?.kind).toBe("visitrule");
791
- expect(() =>
792
- parseproposal(
793
- {
794
- version: protocolversion,
795
- plan: {
796
- objective: "Unreviewed arm",
797
- steps: [
798
- {
799
- kind: "visitrule",
800
- options: JSON.stringify({ workflowid: "wf1", rule: { origins: ["https://example.com"] } }),
801
- summary: "Arm without review.",
802
- },
803
- ],
804
- },
805
- },
806
- "https://example.com",
807
- ),
808
- ).toThrow("arm review");
809
- expect(() =>
810
- parseproposal(
811
- {
812
- version: protocolversion,
813
- plan: {
814
- objective: "Outside grants",
815
- steps: [
816
- {
817
- kind: "visitrule",
818
- options: JSON.stringify({
819
- workflowid: "wf1",
820
- reviewed: true,
821
- rule: { origins: ["https://other.example"] },
822
- }),
823
- summary: "Arm outside the grants.",
824
- },
825
- ],
826
- },
827
- },
828
- "https://example.com",
829
- ),
830
- ).toThrow("outside the grants");
831
- expect(() =>
832
- parseproposal(
833
- {
834
- version: protocolversion,
835
- plan: {
836
- objective: "Url list outside grants",
837
- steps: [
838
- {
839
- kind: "urllistrule",
840
- options: JSON.stringify({
841
- workflowid: "wf1",
842
- reviewed: true,
843
- rule: { urls: ["https://elsewhere.example/a"] },
844
- }),
845
- summary: "Arm the url list.",
846
- },
847
- ],
848
- },
849
- },
850
- "https://example.com",
851
- ),
852
- ).toThrow("outside the grants");
853
- });
854
- });
855
-
856
- describe("trigger memory persistence", () => {
857
- it("stores rules with their workflow names, replaces state and removes disarmed rules", async () => {
858
- const store = new sessionmemory(new fakeadapter());
859
- const rule = armedrule("visitrule", { origins: ["https://example.com"] });
860
- await store.addtriggerule(rule);
861
- await store.addworkflowrecord({
862
- id: "wf1",
863
- name: "reader",
864
- version: 1,
865
- origins: ["https://example.com"],
866
- steps: [],
867
- blocks: [],
868
- risk: "read",
869
- createdat: now,
870
- });
871
- const listed = await store.listtriggers();
872
- expect(listed[0]?.workflowname).toBe("reader");
873
- expect((await store.gettriggerule(rule.id))?.id).toBe(rule.id);
874
- await store.settriggerule(updaterule(rule, { state: { enabled: false } }));
875
- expect((await store.gettriggerule(rule.id))?.state.enabled).toBe(false);
876
- await store.removetriggerule(rule.id);
877
- expect(await store.gettriggerules()).toHaveLength(0);
878
- expect(await store.listtriggers()).toHaveLength(0);
879
- });
880
-
881
- it("stores fire records under the reviewed retention and keeps the queue", async () => {
882
- const store = new sessionmemory(new fakeadapter());
883
- await store.setsettings({ triggerretention: 2 });
884
- await store.addtriggerfire({ id: "f1", ruleid: "r1", at: now, cause: "visit" });
885
- await store.addtriggerfire({ id: "f2", ruleid: "r1", at: now + 1, cause: "url" });
886
- await store.addtriggerfire({ id: "f3", ruleid: "r2", at: now + 2, cause: "schedule" });
887
- expect((await store.listtriggerfires()).map((fire) => fire.id)).toEqual(["f3", "f2"]);
888
- expect((await store.listtriggerfires("r1")).map((fire) => fire.id)).toEqual(["f2"]);
889
- await store.settriggerqueue([{ id: "f4", ruleid: "r1", at: now + 3, cause: "menu" }]);
890
- expect((await store.gettriggerqueue()).map((fire) => fire.cause)).toEqual(["menu"]);
891
- });
892
-
893
- it("stores webhook payloads and manual run previews with their confirmation outcomes", async () => {
894
- const store = new sessionmemory(new fakeadapter());
895
- await store.addwebhookpayload("r1", { task: "read" }, now);
896
- await store.addwebhookpayload("r1", { task: "extract" }, now + 1);
897
- expect((await store.listwebhookpayloads("r1")).map((entry) => entry.payload.task)).toEqual(["extract", "read"]);
898
- expect(await store.listwebhookpayloads("r2")).toHaveLength(0);
899
- const preview: manualrun = {
900
- id: "m1",
901
- workflowid: "wf1",
902
- preview: [{ stepid: "s1", kind: "readtext", label: "Read the heading" }],
903
- at: now,
904
- };
905
- await store.addmanualrun(preview);
906
- await store.addmanualrun({ ...preview, confirmed: true, decidedat: now + 1 });
907
- const stored = await store.listmanualruns();
908
- expect(stored[0]?.confirmed).toBe(true);
909
- expect(stored[0]?.preview[0]?.stepid).toBe("s1");
910
- await store.settriggerules([armedrule("buttonrule", {}), armedrule("keyrule", { command: "run" })]);
911
- expect(await store.gettriggerules()).toHaveLength(2);
912
- });
913
-
914
- it("records trigger evidence with the fire, launch and suppression counts", () => {
915
- let progress = recordtrigger(
916
- undefined,
917
- plan.id,
918
- "t1",
919
- { family: "arm", detail: "Armed the visit rule", ruleid: "r1", nextfireat: now + 60_000 },
920
- now,
921
- );
922
- progress = recordtrigger(
923
- progress,
924
- plan.id,
925
- "t1",
926
- { family: "fire", detail: "The visit rule fired", ruleid: "r1", fires: 1, launches: 1 },
927
- now + 1,
928
- );
929
- progress = recordtrigger(
930
- progress,
931
- plan.id,
932
- "t1",
933
- { family: "suppress", detail: "The visit rule suppressed a fire", ruleid: "r1", suppressions: 1, queued: 0 },
934
- now + 2,
935
- );
936
- const evidence = triggerevidences(progress, plan.id, "t1");
937
- expect(evidence.map((entry) => entry.family)).toEqual(["arm", "fire", "suppress"]);
938
- expect(evidence[1]?.fires).toBe(1);
939
- expect(triggerevidences(progress, "other", "t1")).toHaveLength(0);
940
- });
941
- });