@theoremjs/agents 0.3.4-next.484.g20d8b9d → 0.3.4-next.508.geda6db0

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 (68) hide show
  1. package/README.md +61 -51
  2. package/esm/mod.d.ts +2 -2
  3. package/esm/mod.js +1 -1
  4. package/esm/src/guardrails/credential-scan.d.ts +1 -1
  5. package/esm/src/guardrails/credential-scan.js +41 -18
  6. package/esm/src/guardrails/destinations.js +6 -2
  7. package/esm/src/guardrails/detect-at.d.ts +1 -3
  8. package/esm/src/guardrails/detect-at.js +6 -22
  9. package/esm/src/guardrails/egress-automata.js +203 -202
  10. package/esm/src/guardrails/egress-stream.js +10 -3
  11. package/esm/src/guardrails/egress-urls.js +4 -2
  12. package/esm/src/guardrails/injection-patterns.d.ts +3 -1
  13. package/esm/src/guardrails/injection-patterns.js +87 -4
  14. package/esm/src/guardrails/labels.d.ts +2 -2
  15. package/esm/src/guardrails/labels.js +7 -5
  16. package/esm/src/guardrails/mod.d.ts +1 -1
  17. package/esm/src/guardrails/normalize.js +4 -2
  18. package/esm/src/guardrails/prompt-echo.js +4 -2
  19. package/esm/src/guardrails/sensitive.d.ts +2 -2
  20. package/esm/src/guardrails/sensitive.js +1 -1
  21. package/esm/src/interface/profile-interface.js +13 -0
  22. package/esm/src/kernel/answer-tool.d.ts +14 -0
  23. package/esm/src/kernel/answer-tool.js +26 -0
  24. package/esm/src/kernel/engine/decision-references.d.ts +14 -0
  25. package/esm/src/kernel/engine/decision-references.js +55 -0
  26. package/esm/src/kernel/engine/decision.d.ts +3 -3
  27. package/esm/src/kernel/engine/decision.js +38 -22
  28. package/esm/src/kernel/engine/embedding.js +0 -2
  29. package/esm/src/kernel/engine/runner/gates.js +38 -4
  30. package/esm/src/kernel/engine/runner/steps.js +47 -10
  31. package/esm/src/kernel/engine/runner/stream.d.ts +14 -8
  32. package/esm/src/kernel/engine/runner/stream.js +25 -13
  33. package/esm/src/kernel/mod.d.ts +1 -1
  34. package/esm/src/kernel/mod.js +1 -1
  35. package/esm/src/kernel/profile-presence.js +12 -0
  36. package/esm/src/kernel/profile-scope.js +14 -14
  37. package/esm/src/kernel/protocols/binding.d.ts +3 -1
  38. package/esm/src/kernel/protocols/binding.js +6 -0
  39. package/esm/src/kernel/protocols/limits.d.ts +10 -11
  40. package/esm/src/kernel/protocols/limits.js +9 -23
  41. package/esm/src/kernel/protocols/runtime.d.ts +3 -2
  42. package/esm/src/kernel/protocols/runtime.js +1 -2
  43. package/esm/src/kernel/provider-budget.d.ts +2 -2
  44. package/esm/src/kernel/provider-budget.js +22 -12
  45. package/esm/src/kernel/provider-runtime.js +2 -2
  46. package/esm/src/kernel/registry/profiles.js +1 -1
  47. package/esm/src/kernel/registry/resolve.js +4 -0
  48. package/esm/src/kernel/registry/schemas.js +1 -1
  49. package/esm/src/kernel/schema.js +12 -2
  50. package/esm/src/kernel/types.d.ts +4 -2
  51. package/esm/src/observability/spans.js +7 -8
  52. package/esm/src/providers/embedding-limits.js +4 -4
  53. package/esm/src/providers/gemini/{embedding-protocol.d.ts → embeddings-protocol.d.ts} +3 -3
  54. package/esm/src/providers/gemini/{embedding-protocol.js → embeddings-protocol.js} +3 -3
  55. package/esm/src/providers/gemini/live-protocol.js +4 -1
  56. package/esm/src/providers/gemini/provider.js +2 -2
  57. package/esm/src/providers/local/embeddings-protocol.d.ts +7 -0
  58. package/esm/src/providers/local/{embedding-protocol.js → embeddings-protocol.js} +2 -2
  59. package/esm/src/providers/local/provider.js +2 -2
  60. package/esm/src/providers/mod.d.ts +3 -3
  61. package/esm/src/providers/mod.js +3 -3
  62. package/esm/src/providers/openrouter/decisions-protocol.js +11 -8
  63. package/esm/src/providers/openrouter/embeddings-protocol.d.ts +6 -0
  64. package/esm/src/providers/openrouter/{embedding-protocol.js → embeddings-protocol.js} +2 -2
  65. package/esm/src/providers/openrouter/provider.js +2 -2
  66. package/package.json +1 -1
  67. package/esm/src/providers/local/embedding-protocol.d.ts +0 -7
  68. package/esm/src/providers/openrouter/embedding-protocol.d.ts +0 -6
@@ -471,7 +471,7 @@ const FORWARD_AUTOMATON = {
471
471
  18938, 18985, 18998, 19054, 19136, 19239, 19332, 19427, 19537, 19610, 19694, 19810, 19918,
472
472
  20026, 20121, 20186, 20221, 20294, 20383, 20493, 20562, 20656, 20822, 20930, 21075, 21227,
473
473
  21365, 21450, 21533, 21617, 21643, 21672, 21700, 21733, 21750, 21856, 21881, 21921, 21975,
474
- 21994, 22019, 22028, 22035, 22054, 22072, 22075, 22092, 22109, 22127, 22145, 22182, 22197,
474
+ 21995, 22020, 22029, 22036, 22055, 22073, 22076, 22093, 22110, 22128, 22146, 22183, 22198,
475
475
  ],
476
476
  leads: [
477
477
  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
@@ -22492,229 +22492,230 @@ const FORWARD_AUTOMATON = {
22492
22492
  [272, 0, 21989, 85],
22493
22493
  [272, 0, 21990, 85],
22494
22494
  [272, 0, 21991, 85],
22495
- [272, 1, 21991, 85, 21992, 86],
22496
- [272, 1, 21993, 86],
22495
+ [272, 1, 21992, 85, 21993, 86],
22496
+ [272, 1, 21992, 85, 21993, 86],
22497
+ [272, 1, 21994, 86],
22497
22498
  [272, 1],
22498
- [273, 0, 21995, 80],
22499
22499
  [273, 0, 21996, 80],
22500
- [273, 0, 21997, 6, 21998, 80],
22501
- [273, 0, 21998, 80],
22500
+ [273, 0, 21997, 80],
22501
+ [273, 0, 21998, 6, 21999, 80],
22502
22502
  [273, 0, 21999, 80],
22503
- [273, 0, 22000, 6, 22001, 80],
22504
- [273, 0, 22001, 80],
22503
+ [273, 0, 22000, 80],
22504
+ [273, 0, 22001, 6, 22002, 80],
22505
22505
  [273, 0, 22002, 80],
22506
- [273, 0, 22003, 6, 22004, 80],
22507
- [273, 0, 22004, 80],
22506
+ [273, 0, 22003, 80],
22507
+ [273, 0, 22004, 6, 22005, 80],
22508
22508
  [273, 0, 22005, 80],
22509
- [273, 0, 22006, 6, 22007, 80],
22510
- [273, 0, 22007, 80],
22509
+ [273, 0, 22006, 80],
22510
+ [273, 0, 22007, 6, 22008, 80],
22511
22511
  [273, 0, 22008, 80],
22512
- [273, 0, 22009, 6, 22010, 80],
22513
- [273, 0, 22010, 80],
22512
+ [273, 0, 22009, 80],
22513
+ [273, 0, 22010, 6, 22011, 80],
22514
22514
  [273, 0, 22011, 80],
22515
- [273, 0, 22012, 6, 22013, 80],
22516
- [273, 0, 22013, 80],
22515
+ [273, 0, 22012, 80],
22516
+ [273, 0, 22013, 6, 22014, 80],
22517
22517
  [273, 0, 22014, 80],
22518
- [273, 0, 22015, 6, 22016, 80],
22519
- [273, 0, 22016, 80],
22518
+ [273, 0, 22015, 80],
22519
+ [273, 0, 22016, 6, 22017, 80],
22520
22520
  [273, 0, 22017, 80],
22521
- [273, 1, 22018, 6, 22016, 80],
22522
- [273, 1, 22016, 80],
22523
- [274, 0, 22020, 144],
22524
- [274, 0, 22021, 171],
22525
- [274, 0, 22022, 144],
22526
- [274, 0, 22023, 171],
22527
- [274, 0, 22024, 144],
22528
- [274, 0, 22025, 171],
22529
- [274, 0, 22024, 144, 22026, 144],
22530
- [274, 1, 22027, 26],
22521
+ [273, 0, 22018, 80],
22522
+ [273, 1, 22019, 6, 22017, 80],
22523
+ [273, 1, 22017, 80],
22524
+ [274, 0, 22021, 144],
22525
+ [274, 0, 22022, 171],
22526
+ [274, 0, 22023, 144],
22527
+ [274, 0, 22024, 171],
22528
+ [274, 0, 22025, 144],
22529
+ [274, 0, 22026, 171],
22530
+ [274, 0, 22025, 144, 22027, 144],
22531
+ [274, 1, 22028, 26],
22531
22532
  [274, 1],
22532
- [275, 0, 22029, 144],
22533
- [275, 0, 22029, 144, 22030, 51],
22534
- [275, 0, 22031, 144],
22535
- [275, 0, 22031, 144, 22032, 51],
22536
- [275, 0, 22031, 144, 22033, 144],
22537
- [275, 1, 22033, 144, 22034, 26],
22533
+ [275, 0, 22030, 144],
22534
+ [275, 0, 22030, 144, 22031, 51],
22535
+ [275, 0, 22032, 144],
22536
+ [275, 0, 22032, 144, 22033, 51],
22537
+ [275, 0, 22032, 144, 22034, 144],
22538
+ [275, 1, 22034, 144, 22035, 26],
22538
22539
  [275, 1],
22539
- [276, 0, 22036, 184],
22540
- [276, 0, 22037, 50],
22541
- [276, 0, 22038, 49, 22039, 138, 22040, 49, 22041, 48],
22542
- [276, 0, 22042, 142, 22039, 185],
22543
- [276, 0, 22038, 49, 22039, 138, 22040, 49, 22041, 48],
22544
- [276, 0, 22043, 142, 22041, 48],
22545
- [276, 0, 22044, 186],
22546
- [276, 0, 22042, 142, 22039, 185],
22547
- [276, 0, 22043, 142, 22041, 48],
22548
- [276, 0, 22045, 142, 22046, 49, 22047, 44, 22048, 93, 22049, 187],
22549
- [276, 0, 22045, 142, 22046, 49, 22047, 44, 22048, 93, 22049, 187],
22550
- [276, 0, 22050, 142, 22047, 44, 22048, 93, 22049, 187],
22551
- [276, 0, 22051, 93, 22052, 188, 22053, 47],
22552
- [276, 0, 22049, 185],
22553
- [276, 1, 22048, 93, 22049, 187],
22554
- [276, 0, 22050, 142, 22047, 44, 22048, 93, 22049, 187],
22555
- [276, 0, 22052, 138],
22556
- [276, 0, 22051, 93, 22052, 188, 22053, 47],
22540
+ [276, 0, 22037, 184],
22541
+ [276, 0, 22038, 50],
22542
+ [276, 0, 22039, 49, 22040, 138, 22041, 49, 22042, 48],
22543
+ [276, 0, 22043, 142, 22040, 185],
22544
+ [276, 0, 22039, 49, 22040, 138, 22041, 49, 22042, 48],
22545
+ [276, 0, 22044, 142, 22042, 48],
22546
+ [276, 0, 22045, 186],
22547
+ [276, 0, 22043, 142, 22040, 185],
22548
+ [276, 0, 22044, 142, 22042, 48],
22549
+ [276, 0, 22046, 142, 22047, 49, 22048, 44, 22049, 93, 22050, 187],
22550
+ [276, 0, 22046, 142, 22047, 49, 22048, 44, 22049, 93, 22050, 187],
22551
+ [276, 0, 22051, 142, 22048, 44, 22049, 93, 22050, 187],
22552
+ [276, 0, 22052, 93, 22053, 188, 22054, 47],
22553
+ [276, 0, 22050, 185],
22554
+ [276, 1, 22049, 93, 22050, 187],
22555
+ [276, 0, 22051, 142, 22048, 44, 22049, 93, 22050, 187],
22556
+ [276, 0, 22053, 138],
22557
+ [276, 0, 22052, 93, 22053, 188, 22054, 47],
22557
22558
  [276, 1],
22558
- [277, 0, 22055, 49, 22056, 171, 22057, 50],
22559
- [277, 0, 22056, 171, 22057, 50],
22560
- [277, 0, 22058, 171, 22057, 50],
22561
- [277, 0, 22059, 93, 22060, 189],
22562
- [277, 0, 22061, 171, 22057, 50],
22563
- [277, 0, 22060, 33],
22564
- [277, 0, 22059, 93, 22060, 189, 22062, 48],
22565
- [277, 0, 22057, 50],
22566
- [277, 0, 22063, 23],
22567
- [277, 0, 22064, 142, 22065, 49, 22066, 44, 22067, 185],
22568
- [277, 0, 22064, 142, 22065, 49, 22066, 44, 22067, 185],
22569
- [277, 0, 22068, 142, 22066, 44, 22067, 185],
22570
- [277, 0, 22069, 93, 22070, 188, 22071, 47],
22571
- [277, 1, 22067, 185],
22572
- [277, 0, 22068, 142, 22066, 44, 22067, 185],
22573
- [277, 0, 22070, 138],
22574
- [277, 0, 22069, 93, 22070, 188, 22071, 47],
22559
+ [277, 0, 22056, 49, 22057, 171, 22058, 50],
22560
+ [277, 0, 22057, 171, 22058, 50],
22561
+ [277, 0, 22059, 171, 22058, 50],
22562
+ [277, 0, 22060, 93, 22061, 189],
22563
+ [277, 0, 22062, 171, 22058, 50],
22564
+ [277, 0, 22061, 33],
22565
+ [277, 0, 22060, 93, 22061, 189, 22063, 48],
22566
+ [277, 0, 22058, 50],
22567
+ [277, 0, 22064, 23],
22568
+ [277, 0, 22065, 142, 22066, 49, 22067, 44, 22068, 185],
22569
+ [277, 0, 22065, 142, 22066, 49, 22067, 44, 22068, 185],
22570
+ [277, 0, 22069, 142, 22067, 44, 22068, 185],
22571
+ [277, 0, 22070, 93, 22071, 188, 22072, 47],
22572
+ [277, 1, 22068, 185],
22573
+ [277, 0, 22069, 142, 22067, 44, 22068, 185],
22574
+ [277, 0, 22071, 138],
22575
+ [277, 0, 22070, 93, 22071, 188, 22072, 47],
22575
22576
  [277, 1],
22576
- [278, 0, 22073, 184],
22577
- [278, 0, 22074, 50],
22577
+ [278, 0, 22074, 184],
22578
+ [278, 0, 22075, 50],
22578
22579
  [278, 1],
22579
- [279, 0, 22076, 44],
22580
- [279, 0, 22077, 144],
22581
- [279, 0, 22078, 190, 22079, 190, 22080, 191, 22081, 47],
22582
- [279, 0, 22078, 190, 22079, 190, 22080, 191, 22081, 47],
22583
- [279, 0, 22082, 192, 22083, 193, 22084, 86, 22079, 190, 22080, 191, 22081, 47],
22584
- [279, 0, 22079, 190, 22080, 191, 22081, 47],
22580
+ [279, 0, 22077, 44],
22581
+ [279, 0, 22078, 144],
22582
+ [279, 0, 22079, 190, 22080, 190, 22081, 191, 22082, 47],
22583
+ [279, 0, 22079, 190, 22080, 190, 22081, 191, 22082, 47],
22584
+ [279, 0, 22083, 192, 22084, 193, 22085, 86, 22080, 190, 22081, 191, 22082, 47],
22585
+ [279, 0, 22080, 190, 22081, 191, 22082, 47],
22585
22586
  [279, 1],
22586
- [279, 0, 22082, 192, 22083, 193, 22084, 86, 22079, 190, 22080, 191, 22081, 47],
22587
- [279, 0, 22083, 193, 22084, 86, 22079, 190, 22080, 191, 22081, 47],
22588
- [279, 0, 22085, 193, 22086, 143, 22087, 28, 22088, 194, 22079, 190, 22080, 191, 22081, 47],
22589
- [279, 0, 22085, 193, 22086, 143, 22087, 28, 22088, 194, 22079, 190, 22080, 191, 22081, 47],
22590
- [279, 0, 22089, 147, 22080, 143],
22591
- [279, 0, 22090, 149, 22080, 28],
22592
- [279, 0, 22091, 195, 22079, 190, 22080, 191, 22081, 47],
22593
- [279, 0, 22089, 147, 22080, 143],
22594
- [279, 0, 22090, 149, 22080, 28],
22595
- [279, 0, 22091, 195, 22079, 190, 22080, 191, 22081, 47],
22596
- [280, 0, 22093, 44],
22597
- [280, 0, 22094, 14],
22598
- [280, 0, 22095, 15],
22599
- [280, 0, 22096, 16],
22600
- [280, 0, 22097, 9],
22601
- [280, 0, 22098, 5],
22602
- [280, 0, 22099, 196],
22603
- [280, 0, 22100, 33, 22101, 44],
22604
- [280, 0, 22100, 33, 22101, 44],
22605
- [280, 0, 22102, 46],
22606
- [280, 0, 22103, 14],
22607
- [280, 0, 22104, 15],
22608
- [280, 0, 22105, 16],
22609
- [280, 0, 22106, 9],
22610
- [280, 0, 22107, 5],
22611
- [280, 0, 22108, 196],
22587
+ [279, 0, 22083, 192, 22084, 193, 22085, 86, 22080, 190, 22081, 191, 22082, 47],
22588
+ [279, 0, 22084, 193, 22085, 86, 22080, 190, 22081, 191, 22082, 47],
22589
+ [279, 0, 22086, 193, 22087, 143, 22088, 28, 22089, 194, 22080, 190, 22081, 191, 22082, 47],
22590
+ [279, 0, 22086, 193, 22087, 143, 22088, 28, 22089, 194, 22080, 190, 22081, 191, 22082, 47],
22591
+ [279, 0, 22090, 147, 22081, 143],
22592
+ [279, 0, 22091, 149, 22081, 28],
22593
+ [279, 0, 22092, 195, 22080, 190, 22081, 191, 22082, 47],
22594
+ [279, 0, 22090, 147, 22081, 143],
22595
+ [279, 0, 22091, 149, 22081, 28],
22596
+ [279, 0, 22092, 195, 22080, 190, 22081, 191, 22082, 47],
22597
+ [280, 0, 22094, 44],
22598
+ [280, 0, 22095, 14],
22599
+ [280, 0, 22096, 15],
22600
+ [280, 0, 22097, 16],
22601
+ [280, 0, 22098, 9],
22602
+ [280, 0, 22099, 5],
22603
+ [280, 0, 22100, 196],
22604
+ [280, 0, 22101, 33, 22102, 44],
22605
+ [280, 0, 22101, 33, 22102, 44],
22606
+ [280, 0, 22103, 46],
22607
+ [280, 0, 22104, 14],
22608
+ [280, 0, 22105, 15],
22609
+ [280, 0, 22106, 16],
22610
+ [280, 0, 22107, 9],
22611
+ [280, 0, 22108, 5],
22612
+ [280, 0, 22109, 196],
22612
22613
  [280, 1],
22613
- [281, 0, 22110, 50],
22614
- [281, 0, 22111, 49, 22112, 138, 22113, 49, 22114, 48],
22615
- [281, 0, 22115, 142, 22112, 185],
22616
- [281, 0, 22111, 49, 22112, 138, 22113, 49, 22114, 48],
22617
- [281, 0, 22116, 142, 22114, 48],
22618
- [281, 0, 22117, 186],
22619
- [281, 0, 22115, 142, 22112, 185],
22620
- [281, 0, 22116, 142, 22114, 48],
22621
- [281, 0, 22118, 142, 22119, 49, 22120, 44, 22121, 93, 22122, 187],
22622
- [281, 0, 22118, 142, 22119, 49, 22120, 44, 22121, 93, 22122, 187],
22623
- [281, 0, 22123, 142, 22120, 44, 22121, 93, 22122, 187],
22624
- [281, 0, 22124, 93, 22125, 188, 22126, 47],
22625
- [281, 0, 22122, 185],
22626
- [281, 1, 22121, 93, 22122, 187],
22627
- [281, 0, 22123, 142, 22120, 44, 22121, 93, 22122, 187],
22628
- [281, 0, 22125, 138],
22629
- [281, 0, 22124, 93, 22125, 188, 22126, 47],
22614
+ [281, 0, 22111, 50],
22615
+ [281, 0, 22112, 49, 22113, 138, 22114, 49, 22115, 48],
22616
+ [281, 0, 22116, 142, 22113, 185],
22617
+ [281, 0, 22112, 49, 22113, 138, 22114, 49, 22115, 48],
22618
+ [281, 0, 22117, 142, 22115, 48],
22619
+ [281, 0, 22118, 186],
22620
+ [281, 0, 22116, 142, 22113, 185],
22621
+ [281, 0, 22117, 142, 22115, 48],
22622
+ [281, 0, 22119, 142, 22120, 49, 22121, 44, 22122, 93, 22123, 187],
22623
+ [281, 0, 22119, 142, 22120, 49, 22121, 44, 22122, 93, 22123, 187],
22624
+ [281, 0, 22124, 142, 22121, 44, 22122, 93, 22123, 187],
22625
+ [281, 0, 22125, 93, 22126, 188, 22127, 47],
22626
+ [281, 0, 22123, 185],
22627
+ [281, 1, 22122, 93, 22123, 187],
22628
+ [281, 0, 22124, 142, 22121, 44, 22122, 93, 22123, 187],
22629
+ [281, 0, 22126, 138],
22630
+ [281, 0, 22125, 93, 22126, 188, 22127, 47],
22630
22631
  [281, 1],
22631
- [282, 0, 22128, 49, 22129, 171, 22130, 50],
22632
- [282, 0, 22129, 171, 22130, 50],
22633
- [282, 0, 22131, 171, 22130, 50],
22634
- [282, 0, 22132, 93, 22133, 189],
22635
- [282, 0, 22134, 171, 22130, 50],
22636
- [282, 0, 22133, 33],
22637
- [282, 0, 22132, 93, 22133, 189, 22135, 48],
22638
- [282, 0, 22130, 50],
22639
- [282, 0, 22136, 23],
22640
- [282, 0, 22137, 142, 22138, 49, 22139, 44, 22140, 185],
22641
- [282, 0, 22137, 142, 22138, 49, 22139, 44, 22140, 185],
22642
- [282, 0, 22141, 142, 22139, 44, 22140, 185],
22643
- [282, 0, 22142, 93, 22143, 188, 22144, 47],
22644
- [282, 1, 22140, 185],
22645
- [282, 0, 22141, 142, 22139, 44, 22140, 185],
22646
- [282, 0, 22143, 138],
22647
- [282, 0, 22142, 93, 22143, 188, 22144, 47],
22632
+ [282, 0, 22129, 49, 22130, 171, 22131, 50],
22633
+ [282, 0, 22130, 171, 22131, 50],
22634
+ [282, 0, 22132, 171, 22131, 50],
22635
+ [282, 0, 22133, 93, 22134, 189],
22636
+ [282, 0, 22135, 171, 22131, 50],
22637
+ [282, 0, 22134, 33],
22638
+ [282, 0, 22133, 93, 22134, 189, 22136, 48],
22639
+ [282, 0, 22131, 50],
22640
+ [282, 0, 22137, 23],
22641
+ [282, 0, 22138, 142, 22139, 49, 22140, 44, 22141, 185],
22642
+ [282, 0, 22138, 142, 22139, 49, 22140, 44, 22141, 185],
22643
+ [282, 0, 22142, 142, 22140, 44, 22141, 185],
22644
+ [282, 0, 22143, 93, 22144, 188, 22145, 47],
22645
+ [282, 1, 22141, 185],
22646
+ [282, 0, 22142, 142, 22140, 44, 22141, 185],
22647
+ [282, 0, 22144, 138],
22648
+ [282, 0, 22143, 93, 22144, 188, 22145, 47],
22648
22649
  [282, 1],
22649
- [283, 0, 22146, 44],
22650
- [283, 0, 22147, 144],
22651
- [283, 0, 22148, 197],
22652
- [283, 0, 22149, 197, 22150, 23],
22653
- [283, 0, 22151, 197, 22150, 23],
22654
- [283, 0, 22152, 198, 22153, 47],
22655
- [283, 0, 22154, 197, 22150, 23],
22656
- [283, 0, 22152, 198, 22153, 47],
22650
+ [283, 0, 22147, 44],
22651
+ [283, 0, 22148, 144],
22652
+ [283, 0, 22149, 197],
22653
+ [283, 0, 22150, 197, 22151, 23],
22654
+ [283, 0, 22152, 197, 22151, 23],
22655
+ [283, 0, 22153, 198, 22154, 47],
22656
+ [283, 0, 22155, 197, 22151, 23],
22657
+ [283, 0, 22153, 198, 22154, 47],
22657
22658
  [283, 1],
22658
- [283, 0, 22155, 197, 22150, 23],
22659
- [283, 0, 22156, 197, 22150, 23],
22660
- [283, 0, 22157, 197, 22150, 23],
22661
- [283, 0, 22158, 197, 22150, 23],
22662
- [283, 0, 22159, 197, 22150, 23],
22663
- [283, 0, 22160, 197, 22150, 23],
22664
- [283, 0, 22161, 197, 22150, 23],
22665
- [283, 0, 22162, 197, 22150, 23],
22666
- [283, 0, 22163, 197, 22150, 23],
22667
- [283, 0, 22164, 197, 22150, 23],
22668
- [283, 0, 22165, 197, 22150, 23],
22669
- [283, 0, 22166, 197, 22150, 23],
22670
- [283, 0, 22167, 197, 22150, 23],
22671
- [283, 0, 22168, 197, 22150, 23],
22672
- [283, 0, 22169, 197, 22150, 23],
22673
- [283, 0, 22170, 197, 22150, 23],
22674
- [283, 0, 22171, 197, 22150, 23],
22675
- [283, 0, 22172, 197, 22150, 23],
22676
- [283, 0, 22173, 197, 22150, 23],
22677
- [283, 0, 22174, 197, 22150, 23],
22678
- [283, 0, 22175, 197, 22150, 23],
22679
- [283, 0, 22176, 197, 22150, 23],
22680
- [283, 0, 22177, 197, 22150, 23],
22681
- [283, 0, 22178, 197, 22150, 23],
22682
- [283, 0, 22179, 197, 22150, 23],
22683
- [283, 0, 22180, 197, 22150, 23],
22684
- [283, 0, 22181, 197, 22150, 23],
22685
- [283, 0, 22150, 23],
22686
- [284, 0, 22183, 21, 22184, 18, 22185, 22],
22687
- [284, 0, 22186, 15],
22659
+ [283, 0, 22156, 197, 22151, 23],
22660
+ [283, 0, 22157, 197, 22151, 23],
22661
+ [283, 0, 22158, 197, 22151, 23],
22662
+ [283, 0, 22159, 197, 22151, 23],
22663
+ [283, 0, 22160, 197, 22151, 23],
22664
+ [283, 0, 22161, 197, 22151, 23],
22665
+ [283, 0, 22162, 197, 22151, 23],
22666
+ [283, 0, 22163, 197, 22151, 23],
22667
+ [283, 0, 22164, 197, 22151, 23],
22668
+ [283, 0, 22165, 197, 22151, 23],
22669
+ [283, 0, 22166, 197, 22151, 23],
22670
+ [283, 0, 22167, 197, 22151, 23],
22671
+ [283, 0, 22168, 197, 22151, 23],
22672
+ [283, 0, 22169, 197, 22151, 23],
22673
+ [283, 0, 22170, 197, 22151, 23],
22674
+ [283, 0, 22171, 197, 22151, 23],
22675
+ [283, 0, 22172, 197, 22151, 23],
22676
+ [283, 0, 22173, 197, 22151, 23],
22677
+ [283, 0, 22174, 197, 22151, 23],
22678
+ [283, 0, 22175, 197, 22151, 23],
22679
+ [283, 0, 22176, 197, 22151, 23],
22680
+ [283, 0, 22177, 197, 22151, 23],
22681
+ [283, 0, 22178, 197, 22151, 23],
22682
+ [283, 0, 22179, 197, 22151, 23],
22683
+ [283, 0, 22180, 197, 22151, 23],
22684
+ [283, 0, 22181, 197, 22151, 23],
22685
+ [283, 0, 22182, 197, 22151, 23],
22686
+ [283, 0, 22151, 23],
22687
+ [284, 0, 22184, 21, 22185, 18, 22186, 22],
22688
22688
  [284, 0, 22187, 15],
22689
- [284, 0, 22188, 22],
22690
- [284, 0, 22189, 15],
22691
- [284, 0, 22190, 8],
22692
- [284, 0, 22191, 22],
22693
- [284, 0, 22192, 8],
22694
- [284, 0, 22193, 23],
22695
- [284, 0, 22194, 78],
22696
- [284, 0, 22190, 14, 22193, 23],
22689
+ [284, 0, 22188, 15],
22690
+ [284, 0, 22189, 22],
22691
+ [284, 0, 22190, 15],
22692
+ [284, 0, 22191, 8],
22693
+ [284, 0, 22192, 22],
22694
+ [284, 0, 22193, 8],
22695
+ [284, 0, 22194, 23],
22696
+ [284, 0, 22195, 78],
22697
+ [284, 0, 22191, 14, 22194, 23],
22698
+ [284, 0, 22196, 46],
22699
+ [284, 1, 22197, 199],
22697
22700
  [284, 0, 22195, 46],
22698
- [284, 1, 22196, 199],
22699
- [284, 0, 22194, 46],
22700
- [284, 1, 22196, 199],
22701
- [285, 0, 22198, 44],
22702
- [285, 0, 22199, 144],
22703
- [285, 0, 22200, 190, 22201, 190, 22202, 191, 22203, 47],
22704
- [285, 0, 22200, 190, 22201, 190, 22202, 191, 22203, 47],
22705
- [285, 0, 22204, 192, 22205, 193, 22206, 86, 22201, 190, 22202, 191, 22203, 47],
22706
- [285, 0, 22201, 190, 22202, 191, 22203, 47],
22701
+ [284, 1, 22197, 199],
22702
+ [285, 0, 22199, 44],
22703
+ [285, 0, 22200, 144],
22704
+ [285, 0, 22201, 190, 22202, 190, 22203, 191, 22204, 47],
22705
+ [285, 0, 22201, 190, 22202, 190, 22203, 191, 22204, 47],
22706
+ [285, 0, 22205, 192, 22206, 193, 22207, 86, 22202, 190, 22203, 191, 22204, 47],
22707
+ [285, 0, 22202, 190, 22203, 191, 22204, 47],
22707
22708
  [285, 1],
22708
- [285, 0, 22204, 192, 22205, 193, 22206, 86, 22201, 190, 22202, 191, 22203, 47],
22709
- [285, 0, 22205, 193, 22206, 86, 22201, 190, 22202, 191, 22203, 47],
22710
- [285, 0, 22207, 193, 22208, 143, 22209, 28, 22210, 194, 22201, 190, 22202, 191, 22203, 47],
22711
- [285, 0, 22207, 193, 22208, 143, 22209, 28, 22210, 194, 22201, 190, 22202, 191, 22203, 47],
22712
- [285, 0, 22211, 147, 22202, 143],
22713
- [285, 0, 22212, 149, 22202, 28],
22714
- [285, 0, 22213, 195, 22201, 190, 22202, 191, 22203, 47],
22715
- [285, 0, 22211, 147, 22202, 143],
22716
- [285, 0, 22212, 149, 22202, 28],
22717
- [285, 0, 22213, 195, 22201, 190, 22202, 191, 22203, 47],
22709
+ [285, 0, 22205, 192, 22206, 193, 22207, 86, 22202, 190, 22203, 191, 22204, 47],
22710
+ [285, 0, 22206, 193, 22207, 86, 22202, 190, 22203, 191, 22204, 47],
22711
+ [285, 0, 22208, 193, 22209, 143, 22210, 28, 22211, 194, 22202, 190, 22203, 191, 22204, 47],
22712
+ [285, 0, 22208, 193, 22209, 143, 22210, 28, 22211, 194, 22202, 190, 22203, 191, 22204, 47],
22713
+ [285, 0, 22212, 147, 22203, 143],
22714
+ [285, 0, 22213, 149, 22203, 28],
22715
+ [285, 0, 22214, 195, 22202, 190, 22203, 191, 22204, 47],
22716
+ [285, 0, 22212, 147, 22203, 143],
22717
+ [285, 0, 22213, 149, 22203, 28],
22718
+ [285, 0, 22214, 195, 22202, 190, 22203, 191, 22204, 47],
22718
22719
  ],
22719
22720
  };
22720
22721
  /** Each reversed injection pattern, loosened the same way. */
@@ -20,6 +20,7 @@
20
20
  import { EGRESS_PATTERNS, notePattern, } from './egress-patterns.js';
21
21
  import { IMAGE_PATTERNS, imageReadings, LINK_PATTERNS, linkReadings, } from './egress-urls.js';
22
22
  import { decodeUrlRuns, INJECTION_BLOBS, TYPO_TARGETS, tryLeet, tryRot13, typoNormalize, } from './injection.js';
23
+ import { freshPattern } from './injection-patterns.js';
23
24
  import { REVERSED_INJECTION_PATTERNS } from './injection-reversed.js';
24
25
  import { isEmoji, normalizeCodePoint } from './normalize.js';
25
26
  import { detectRule } from './rules.js';
@@ -471,7 +472,7 @@ function forwardPatterns(detectors, { given, allow, skipImages }) {
471
472
  out.push({
472
473
  ...rule,
473
474
  id,
474
- regex: new RegExp(entry.pattern.source, entry.pattern.flags),
475
+ regex: freshPattern(entry.pattern),
475
476
  ...patternReading(entry.kind, entry.pattern, urls),
476
477
  });
477
478
  });
@@ -487,7 +488,7 @@ function injectionPatterns() {
487
488
  out.push({
488
489
  ...INJECTION_RULE,
489
490
  id,
490
- regex: new RegExp(pattern.source, pattern.flags),
491
+ regex: freshPattern(pattern),
491
492
  ...(hit ? { hit } : {}),
492
493
  });
493
494
  });
@@ -649,6 +650,12 @@ function createScan(view, automaton, patterns) {
649
650
  resume[p] = Math.max(from, at) + 1;
650
651
  return { rule, severity, start: view.rawAt(at), detector };
651
652
  }
653
+ let lowered = { text: '', lower: '' };
654
+ const lower = () => {
655
+ if (lowered.text !== view.text)
656
+ lowered = { text: view.text, lower: view.text.toLowerCase() };
657
+ return lowered.lower;
658
+ };
652
659
  /** A regex pattern's hit up to `settledTo`. */
653
660
  function matched(p, settledTo) {
654
661
  if (!reached[p] && !recheck[p]) {
@@ -667,7 +674,7 @@ function createScan(view, automaton, patterns) {
667
674
  return undefined;
668
675
  }
669
676
  const [blob] = match;
670
- if (blob && (!hit || hit(blob, text, match.index))) {
677
+ if (blob && (!hit || hit(blob, text, match.index, lower))) {
671
678
  // why: The scan reads on from the end of the match, so the next call finds the one after it.
672
679
  resume[p] = regex.lastIndex;
673
680
  recheck[p] = 1;
@@ -448,8 +448,10 @@ function inlineLeaks(text, openers, scope, meter) {
448
448
  while (next < openers.length && openers[next].open < end) {
449
449
  inside.push(openers[next++]);
450
450
  }
451
- if (inside.length > 0)
452
- spans.push(...paragraphLeaks(text, start, end, inside, scope, meter));
451
+ if (inside.length > 0) {
452
+ for (const span of paragraphLeaks(text, start, end, inside, scope, meter))
453
+ spans.push(span);
454
+ }
453
455
  }
454
456
  return spans;
455
457
  }
@@ -17,4 +17,6 @@ declare const HEX_BLOB: RegExp;
17
17
  declare const SPACED_LETTERS: RegExp;
18
18
  /** Three+ alphabetic tokens joined by `|` (no shell spaces around pipes). */
19
19
  declare const PIPE_SEPARATED: RegExp;
20
- export { BASE64_BLOB, HEX_BLOB, INJECTION_PATTERNS, overrideFrame, PIPE_SEPARATED, SPACED_LETTERS };
20
+ /** A pattern of its own for one scan to move `lastIndex` on, of the same class as `pattern`. */
21
+ declare function freshPattern(pattern: RegExp): RegExp;
22
+ export { BASE64_BLOB, freshPattern, HEX_BLOB, INJECTION_PATTERNS, overrideFrame, PIPE_SEPARATED, SPACED_LETTERS, };
@@ -117,10 +117,93 @@ const INJECTION_PATTERNS = [
117
117
  IGNORE_MULTILANG,
118
118
  OVERRIDE_FRAME,
119
119
  ];
120
+ /**
121
+ * A pattern whose `exec` is a scan written by hand, which finds exactly the matches of its `source`.
122
+ * V8 grows its regex stack once per step of a repeated group whose steps differ in length, so on a run
123
+ * of millions of characters that regex throws. The egress automata are still built from `source`.
124
+ */
125
+ class ScannedPattern extends RegExp {
126
+ exec(text) {
127
+ for (let start = this.lastIndex; start < text.length; start++) {
128
+ const end = this.endOf(text, start);
129
+ if (end < 0)
130
+ continue;
131
+ this.lastIndex = end;
132
+ return Object.assign([text.slice(start, end)], {
133
+ index: start,
134
+ input: text,
135
+ });
136
+ }
137
+ this.lastIndex = 0;
138
+ return null;
139
+ }
140
+ }
141
+ const WHITESPACE = /\s/;
142
+ function isHex(code) {
143
+ return (code >= 48 && code <= 57) || (code >= 65 && code <= 70) || (code >= 97 && code <= 102);
144
+ }
145
+ function isLetter(code) {
146
+ return (code >= 65 && code <= 90) || (code >= 97 && code <= 122);
147
+ }
148
+ /** A character `\b` counts as part of a word: a letter, a digit, or `_`. */
149
+ function isWordChar(code) {
150
+ return isLetter(code) || (code >= 48 && code <= 57) || code === 95;
151
+ }
152
+ class HexBlob extends ScannedPattern {
153
+ constructor() {
154
+ super('(?:[0-9a-f]{2}[\\s]?){8,}', 'gi');
155
+ }
156
+ endOf(text, start) {
157
+ let at = start;
158
+ let pairs = 0;
159
+ while (isHex(text.charCodeAt(at)) && isHex(text.charCodeAt(at + 1))) {
160
+ at += 2;
161
+ pairs++;
162
+ if (at < text.length && WHITESPACE.test(text[at]))
163
+ at++;
164
+ }
165
+ return pairs >= 8 ? at : -1;
166
+ }
167
+ }
168
+ class PipeSeparated extends ScannedPattern {
169
+ constructor() {
170
+ super('\\b(?:[A-Za-z]+\\|){2,}[A-Za-z]+\\b', 'g');
171
+ }
172
+ endOf(text, start) {
173
+ if (!isLetter(text.charCodeAt(start)) || isWordChar(text.charCodeAt(start - 1)))
174
+ return -1;
175
+ let at = start;
176
+ let piped = 0;
177
+ let lastWordEnd = -1;
178
+ for (;;) {
179
+ let end = at;
180
+ while (isLetter(text.charCodeAt(end)))
181
+ end++;
182
+ if (end > at && text[end] === '|') {
183
+ piped++;
184
+ lastWordEnd = end;
185
+ at = end + 1;
186
+ continue;
187
+ }
188
+ if (end > at && piped >= 2 && !isWordChar(text.charCodeAt(end)))
189
+ return end;
190
+ // why: The regex backtracks one step, so the last piped word is the final one.
191
+ return piped >= 3 ? lastWordEnd : -1;
192
+ }
193
+ }
194
+ }
120
195
  /** Runs that might encode an injection; each is decoded and checked in `injection.ts`. */
121
- const BASE64_BLOB = /[A-Za-z0-9+/]{16,}={0,2}/g;
122
- const HEX_BLOB = /(?:[0-9a-f]{2}[\s]?){8,}/gi;
196
+ const BASE64_BLOB = /[A-Za-z0-9+/]{16}[A-Za-z0-9+/]*={0,2}/g;
197
+ const HEX_BLOB = new HexBlob();
123
198
  const SPACED_LETTERS = /\b(?:[A-Za-z] ){3,}[A-Za-z]\b/g;
124
199
  /** Three+ alphabetic tokens joined by `|` (no shell spaces around pipes). */
125
- const PIPE_SEPARATED = /\b(?:[A-Za-z]+\|){2,}[A-Za-z]+\b/g;
126
- export { BASE64_BLOB, HEX_BLOB, INJECTION_PATTERNS, overrideFrame, PIPE_SEPARATED, SPACED_LETTERS };
200
+ const PIPE_SEPARATED = new PipeSeparated();
201
+ /** A pattern of its own for one scan to move `lastIndex` on, of the same class as `pattern`. */
202
+ function freshPattern(pattern) {
203
+ if (pattern instanceof HexBlob)
204
+ return new HexBlob();
205
+ if (pattern instanceof PipeSeparated)
206
+ return new PipeSeparated();
207
+ return new RegExp(pattern.source, pattern.flags);
208
+ }
209
+ export { BASE64_BLOB, freshPattern, HEX_BLOB, INJECTION_PATTERNS, overrideFrame, PIPE_SEPARATED, SPACED_LETTERS, };