safemode 1.0.0 → 2.0.0

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 (265) hide show
  1. package/LICENSE +190 -0
  2. package/dist/bin/safemode.d.ts +15 -0
  3. package/dist/bin/safemode.d.ts.map +1 -0
  4. package/dist/bin/safemode.js +439 -0
  5. package/dist/bin/safemode.js.map +1 -0
  6. package/dist/hooks/hook-runner.bundle.js +8296 -0
  7. package/dist/src/approvals/discord.d.ts +90 -0
  8. package/dist/src/approvals/discord.d.ts.map +1 -0
  9. package/dist/src/approvals/discord.js +212 -0
  10. package/dist/src/approvals/discord.js.map +1 -0
  11. package/dist/src/approvals/index.d.ts +12 -0
  12. package/dist/src/approvals/index.d.ts.map +1 -0
  13. package/dist/src/approvals/index.js +9 -0
  14. package/dist/src/approvals/index.js.map +1 -0
  15. package/dist/src/approvals/manager.d.ts +98 -0
  16. package/dist/src/approvals/manager.d.ts.map +1 -0
  17. package/dist/src/approvals/manager.js +220 -0
  18. package/dist/src/approvals/manager.js.map +1 -0
  19. package/dist/src/approvals/telegram.d.ts +94 -0
  20. package/dist/src/approvals/telegram.d.ts.map +1 -0
  21. package/dist/src/approvals/telegram.js +234 -0
  22. package/dist/src/approvals/telegram.js.map +1 -0
  23. package/dist/src/atsp/index.d.ts +77 -0
  24. package/dist/src/atsp/index.d.ts.map +1 -0
  25. package/dist/src/atsp/index.js +281 -0
  26. package/dist/src/atsp/index.js.map +1 -0
  27. package/dist/src/bridge/auth.d.ts +78 -0
  28. package/dist/src/bridge/auth.d.ts.map +1 -0
  29. package/dist/src/bridge/auth.js +248 -0
  30. package/dist/src/bridge/auth.js.map +1 -0
  31. package/dist/src/bridge/client.d.ts +194 -0
  32. package/dist/src/bridge/client.d.ts.map +1 -0
  33. package/dist/src/bridge/client.js +343 -0
  34. package/dist/src/bridge/client.js.map +1 -0
  35. package/dist/src/bridge/heartbeat.d.ts +86 -0
  36. package/dist/src/bridge/heartbeat.d.ts.map +1 -0
  37. package/dist/src/bridge/heartbeat.js +344 -0
  38. package/dist/src/bridge/heartbeat.js.map +1 -0
  39. package/dist/src/bridge/index.d.ts +13 -0
  40. package/dist/src/bridge/index.d.ts.map +1 -0
  41. package/dist/src/bridge/index.js +17 -0
  42. package/dist/src/bridge/index.js.map +1 -0
  43. package/dist/src/bridge/policy.d.ts +79 -0
  44. package/dist/src/bridge/policy.d.ts.map +1 -0
  45. package/dist/src/bridge/policy.js +340 -0
  46. package/dist/src/bridge/policy.js.map +1 -0
  47. package/dist/src/bridge/sync.d.ts +81 -0
  48. package/dist/src/bridge/sync.d.ts.map +1 -0
  49. package/dist/src/bridge/sync.js +353 -0
  50. package/dist/src/bridge/sync.js.map +1 -0
  51. package/dist/src/bridge/types.d.ts +308 -0
  52. package/dist/src/bridge/types.d.ts.map +1 -0
  53. package/dist/src/bridge/types.js +18 -0
  54. package/dist/src/bridge/types.js.map +1 -0
  55. package/dist/src/cet/index.d.ts +49 -0
  56. package/dist/src/cet/index.d.ts.map +1 -0
  57. package/dist/src/cet/index.js +341 -0
  58. package/dist/src/cet/index.js.map +1 -0
  59. package/dist/src/cet/types.d.ts +94 -0
  60. package/dist/src/cet/types.d.ts.map +1 -0
  61. package/dist/src/cet/types.js +106 -0
  62. package/dist/src/cet/types.js.map +1 -0
  63. package/dist/src/cli/commands.d.ts +53 -0
  64. package/dist/src/cli/commands.d.ts.map +1 -0
  65. package/dist/src/cli/commands.js +1106 -0
  66. package/dist/src/cli/commands.js.map +1 -0
  67. package/dist/src/cli/phone.d.ts +12 -0
  68. package/dist/src/cli/phone.d.ts.map +1 -0
  69. package/dist/src/cli/phone.js +174 -0
  70. package/dist/src/cli/phone.js.map +1 -0
  71. package/dist/src/config/allowlist.d.ts +17 -0
  72. package/dist/src/config/allowlist.d.ts.map +1 -0
  73. package/dist/src/config/allowlist.js +68 -0
  74. package/dist/src/config/allowlist.js.map +1 -0
  75. package/dist/src/config/index.d.ts +114 -0
  76. package/dist/src/config/index.d.ts.map +1 -0
  77. package/dist/src/config/index.js +362 -0
  78. package/dist/src/config/index.js.map +1 -0
  79. package/dist/src/engines/01-loop-killer.d.ts +20 -0
  80. package/dist/src/engines/01-loop-killer.d.ts.map +1 -0
  81. package/dist/src/engines/01-loop-killer.js +86 -0
  82. package/dist/src/engines/01-loop-killer.js.map +1 -0
  83. package/dist/src/engines/02-oscillation.d.ts +19 -0
  84. package/dist/src/engines/02-oscillation.d.ts.map +1 -0
  85. package/dist/src/engines/02-oscillation.js +108 -0
  86. package/dist/src/engines/02-oscillation.js.map +1 -0
  87. package/dist/src/engines/03-velocity-limiter.d.ts +18 -0
  88. package/dist/src/engines/03-velocity-limiter.d.ts.map +1 -0
  89. package/dist/src/engines/03-velocity-limiter.js +67 -0
  90. package/dist/src/engines/03-velocity-limiter.js.map +1 -0
  91. package/dist/src/engines/04-cost-exposure.d.ts +18 -0
  92. package/dist/src/engines/04-cost-exposure.d.ts.map +1 -0
  93. package/dist/src/engines/04-cost-exposure.js +54 -0
  94. package/dist/src/engines/04-cost-exposure.js.map +1 -0
  95. package/dist/src/engines/05-action-growth.d.ts +17 -0
  96. package/dist/src/engines/05-action-growth.d.ts.map +1 -0
  97. package/dist/src/engines/05-action-growth.js +93 -0
  98. package/dist/src/engines/05-action-growth.js.map +1 -0
  99. package/dist/src/engines/06-latency-spike.d.ts +16 -0
  100. package/dist/src/engines/06-latency-spike.d.ts.map +1 -0
  101. package/dist/src/engines/06-latency-spike.js +68 -0
  102. package/dist/src/engines/06-latency-spike.js.map +1 -0
  103. package/dist/src/engines/07-error-rate.d.ts +18 -0
  104. package/dist/src/engines/07-error-rate.d.ts.map +1 -0
  105. package/dist/src/engines/07-error-rate.js +83 -0
  106. package/dist/src/engines/07-error-rate.js.map +1 -0
  107. package/dist/src/engines/08-throughput-drop.d.ts +16 -0
  108. package/dist/src/engines/08-throughput-drop.d.ts.map +1 -0
  109. package/dist/src/engines/08-throughput-drop.js +78 -0
  110. package/dist/src/engines/08-throughput-drop.js.map +1 -0
  111. package/dist/src/engines/09-pii-scanner.d.ts +15 -0
  112. package/dist/src/engines/09-pii-scanner.d.ts.map +1 -0
  113. package/dist/src/engines/09-pii-scanner.js +146 -0
  114. package/dist/src/engines/09-pii-scanner.js.map +1 -0
  115. package/dist/src/engines/10-secrets-scanner.d.ts +15 -0
  116. package/dist/src/engines/10-secrets-scanner.d.ts.map +1 -0
  117. package/dist/src/engines/10-secrets-scanner.js +125 -0
  118. package/dist/src/engines/10-secrets-scanner.js.map +1 -0
  119. package/dist/src/engines/11-prompt-injection.d.ts +42 -0
  120. package/dist/src/engines/11-prompt-injection.d.ts.map +1 -0
  121. package/dist/src/engines/11-prompt-injection.js +197 -0
  122. package/dist/src/engines/11-prompt-injection.js.map +1 -0
  123. package/dist/src/engines/12-jailbreak.d.ts +42 -0
  124. package/dist/src/engines/12-jailbreak.d.ts.map +1 -0
  125. package/dist/src/engines/12-jailbreak.js +225 -0
  126. package/dist/src/engines/12-jailbreak.js.map +1 -0
  127. package/dist/src/engines/13-command-firewall.d.ts +20 -0
  128. package/dist/src/engines/13-command-firewall.d.ts.map +1 -0
  129. package/dist/src/engines/13-command-firewall.js +230 -0
  130. package/dist/src/engines/13-command-firewall.js.map +1 -0
  131. package/dist/src/engines/14-budget-cap.d.ts +20 -0
  132. package/dist/src/engines/14-budget-cap.d.ts.map +1 -0
  133. package/dist/src/engines/14-budget-cap.js +56 -0
  134. package/dist/src/engines/14-budget-cap.js.map +1 -0
  135. package/dist/src/engines/15-action-label-mismatch.d.ts +31 -0
  136. package/dist/src/engines/15-action-label-mismatch.d.ts.map +1 -0
  137. package/dist/src/engines/15-action-label-mismatch.js +150 -0
  138. package/dist/src/engines/15-action-label-mismatch.js.map +1 -0
  139. package/dist/src/engines/base.d.ts +167 -0
  140. package/dist/src/engines/base.d.ts.map +1 -0
  141. package/dist/src/engines/base.js +89 -0
  142. package/dist/src/engines/base.js.map +1 -0
  143. package/dist/src/engines/index.d.ts +58 -0
  144. package/dist/src/engines/index.d.ts.map +1 -0
  145. package/dist/src/engines/index.js +215 -0
  146. package/dist/src/engines/index.js.map +1 -0
  147. package/dist/src/hooks/executor.d.ts +46 -0
  148. package/dist/src/hooks/executor.d.ts.map +1 -0
  149. package/dist/src/hooks/executor.js +291 -0
  150. package/dist/src/hooks/executor.js.map +1 -0
  151. package/dist/src/hooks/hook-runner.d.ts +23 -0
  152. package/dist/src/hooks/hook-runner.d.ts.map +1 -0
  153. package/dist/src/hooks/hook-runner.js +367 -0
  154. package/dist/src/hooks/hook-runner.js.map +1 -0
  155. package/dist/src/hooks/index.d.ts +12 -0
  156. package/dist/src/hooks/index.d.ts.map +1 -0
  157. package/dist/src/hooks/index.js +13 -0
  158. package/dist/src/hooks/index.js.map +1 -0
  159. package/dist/src/hooks/installer.d.ts +56 -0
  160. package/dist/src/hooks/installer.d.ts.map +1 -0
  161. package/dist/src/hooks/installer.js +785 -0
  162. package/dist/src/hooks/installer.js.map +1 -0
  163. package/dist/src/hooks/types.d.ts +128 -0
  164. package/dist/src/hooks/types.d.ts.map +1 -0
  165. package/dist/src/hooks/types.js +21 -0
  166. package/dist/src/hooks/types.js.map +1 -0
  167. package/dist/src/index.d.ts +41 -0
  168. package/dist/src/index.d.ts.map +1 -0
  169. package/dist/src/index.js +46 -0
  170. package/dist/src/index.js.map +1 -0
  171. package/dist/src/knobs/categories.d.ts +58 -0
  172. package/dist/src/knobs/categories.d.ts.map +1 -0
  173. package/dist/src/knobs/categories.js +867 -0
  174. package/dist/src/knobs/categories.js.map +1 -0
  175. package/dist/src/knobs/gate.d.ts +56 -0
  176. package/dist/src/knobs/gate.d.ts.map +1 -0
  177. package/dist/src/knobs/gate.js +236 -0
  178. package/dist/src/knobs/gate.js.map +1 -0
  179. package/dist/src/knobs/index.d.ts +6 -0
  180. package/dist/src/knobs/index.d.ts.map +1 -0
  181. package/dist/src/knobs/index.js +6 -0
  182. package/dist/src/knobs/index.js.map +1 -0
  183. package/dist/src/ml/index.d.ts +12 -0
  184. package/dist/src/ml/index.d.ts.map +1 -0
  185. package/dist/src/ml/index.js +9 -0
  186. package/dist/src/ml/index.js.map +1 -0
  187. package/dist/src/ml/inference.d.ts +66 -0
  188. package/dist/src/ml/inference.d.ts.map +1 -0
  189. package/dist/src/ml/inference.js +258 -0
  190. package/dist/src/ml/inference.js.map +1 -0
  191. package/dist/src/ml/model-manager.d.ts +89 -0
  192. package/dist/src/ml/model-manager.d.ts.map +1 -0
  193. package/dist/src/ml/model-manager.js +242 -0
  194. package/dist/src/ml/model-manager.js.map +1 -0
  195. package/dist/src/ml/tokenizer.d.ts +76 -0
  196. package/dist/src/ml/tokenizer.d.ts.map +1 -0
  197. package/dist/src/ml/tokenizer.js +293 -0
  198. package/dist/src/ml/tokenizer.js.map +1 -0
  199. package/dist/src/notifications/index.d.ts +74 -0
  200. package/dist/src/notifications/index.d.ts.map +1 -0
  201. package/dist/src/notifications/index.js +190 -0
  202. package/dist/src/notifications/index.js.map +1 -0
  203. package/dist/src/proxy/interceptor.d.ts +153 -0
  204. package/dist/src/proxy/interceptor.d.ts.map +1 -0
  205. package/dist/src/proxy/interceptor.js +304 -0
  206. package/dist/src/proxy/interceptor.js.map +1 -0
  207. package/dist/src/proxy/protocol.d.ts +116 -0
  208. package/dist/src/proxy/protocol.d.ts.map +1 -0
  209. package/dist/src/proxy/protocol.js +99 -0
  210. package/dist/src/proxy/protocol.js.map +1 -0
  211. package/dist/src/proxy/spawn.d.ts +64 -0
  212. package/dist/src/proxy/spawn.d.ts.map +1 -0
  213. package/dist/src/proxy/spawn.js +146 -0
  214. package/dist/src/proxy/spawn.js.map +1 -0
  215. package/dist/src/proxy/wrapper.d.ts +89 -0
  216. package/dist/src/proxy/wrapper.d.ts.map +1 -0
  217. package/dist/src/proxy/wrapper.js +238 -0
  218. package/dist/src/proxy/wrapper.js.map +1 -0
  219. package/dist/src/quarantine/index.d.ts +6 -0
  220. package/dist/src/quarantine/index.d.ts.map +1 -0
  221. package/dist/src/quarantine/index.js +6 -0
  222. package/dist/src/quarantine/index.js.map +1 -0
  223. package/dist/src/quarantine/output.d.ts +26 -0
  224. package/dist/src/quarantine/output.d.ts.map +1 -0
  225. package/dist/src/quarantine/output.js +175 -0
  226. package/dist/src/quarantine/output.js.map +1 -0
  227. package/dist/src/quarantine/schema.d.ts +56 -0
  228. package/dist/src/quarantine/schema.d.ts.map +1 -0
  229. package/dist/src/quarantine/schema.js +363 -0
  230. package/dist/src/quarantine/schema.js.map +1 -0
  231. package/dist/src/rules/engine.d.ts +130 -0
  232. package/dist/src/rules/engine.d.ts.map +1 -0
  233. package/dist/src/rules/engine.js +351 -0
  234. package/dist/src/rules/engine.js.map +1 -0
  235. package/dist/src/rules/index.d.ts +8 -0
  236. package/dist/src/rules/index.d.ts.map +1 -0
  237. package/dist/src/rules/index.js +7 -0
  238. package/dist/src/rules/index.js.map +1 -0
  239. package/dist/src/scanner/index.d.ts +41 -0
  240. package/dist/src/scanner/index.d.ts.map +1 -0
  241. package/dist/src/scanner/index.js +197 -0
  242. package/dist/src/scanner/index.js.map +1 -0
  243. package/dist/src/store/index.d.ts +138 -0
  244. package/dist/src/store/index.d.ts.map +1 -0
  245. package/dist/src/store/index.js +370 -0
  246. package/dist/src/store/index.js.map +1 -0
  247. package/dist/src/timemachine/index.d.ts +8 -0
  248. package/dist/src/timemachine/index.d.ts.map +1 -0
  249. package/dist/src/timemachine/index.js +7 -0
  250. package/dist/src/timemachine/index.js.map +1 -0
  251. package/dist/src/timemachine/snapshot.d.ts +143 -0
  252. package/dist/src/timemachine/snapshot.d.ts.map +1 -0
  253. package/dist/src/timemachine/snapshot.js +446 -0
  254. package/dist/src/timemachine/snapshot.js.map +1 -0
  255. package/dist/src/tofu/index.d.ts +52 -0
  256. package/dist/src/tofu/index.d.ts.map +1 -0
  257. package/dist/src/tofu/index.js +117 -0
  258. package/dist/src/tofu/index.js.map +1 -0
  259. package/dist/src/watchdog/index.d.ts +123 -0
  260. package/dist/src/watchdog/index.d.ts.map +1 -0
  261. package/dist/src/watchdog/index.js +322 -0
  262. package/dist/src/watchdog/index.js.map +1 -0
  263. package/package.json +63 -7
  264. package/safemode/package.json +0 -12
  265. package/safemode/safemode/package.json +0 -12
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 TrustScope
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Safe Mode CLI Entry Point
4
+ *
5
+ * Commands:
6
+ * init Initialize Safe Mode
7
+ * proxy Run as MCP proxy wrapper
8
+ * doctor Health check
9
+ * restore Restore original MCP configs
10
+ * history View event history
11
+ * summary View summary statistics
12
+ * activity View activity feed
13
+ */
14
+ export {};
15
+ //# sourceMappingURL=safemode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"safemode.d.ts","sourceRoot":"","sources":["../../bin/safemode.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;GAWG"}
@@ -0,0 +1,439 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Safe Mode CLI Entry Point
4
+ *
5
+ * Commands:
6
+ * init Initialize Safe Mode
7
+ * proxy Run as MCP proxy wrapper
8
+ * doctor Health check
9
+ * restore Restore original MCP configs
10
+ * history View event history
11
+ * summary View summary statistics
12
+ * activity View activity feed
13
+ */
14
+ import { Command } from 'commander';
15
+ import { runProxy } from '../src/proxy/wrapper.js';
16
+ import { parseProxyArgs } from '../src/proxy/spawn.js';
17
+ import { initCommand, doctorCommand, restoreCommand, uninstallCommand, historyCommand, summaryCommand, activityCommand, hookCheckCommand, claudeCodeCommand, cursorCommand, connectCommand, disconnectCommand, syncCommand, cloudStatusCommand, versionCommand, statusCommand, presetCommand, allowCommand, } from '../src/cli/commands.js';
18
+ import { phoneCommand } from '../src/cli/phone.js';
19
+ import { ConfigLoader } from '../src/config/index.js';
20
+ import { getEventStore } from '../src/store/index.js';
21
+ import { CETClassifier } from '../src/cet/index.js';
22
+ import { ATSPEngine, createATSPConfig } from '../src/atsp/index.js';
23
+ import { KnobGate } from '../src/knobs/gate.js';
24
+ import { EngineRegistry } from '../src/engines/index.js';
25
+ import { SchemaQuarantine } from '../src/quarantine/schema.js';
26
+ import { OutputQuarantine } from '../src/quarantine/output.js';
27
+ import { TOFUManager } from '../src/tofu/index.js';
28
+ import { getNotificationManager } from '../src/notifications/index.js';
29
+ const program = new Command();
30
+ program
31
+ .name('safemode')
32
+ .description('AI governance for MCP servers')
33
+ .version('0.1.0');
34
+ // ============================================================================
35
+ // Init Command
36
+ // ============================================================================
37
+ program
38
+ .command('init')
39
+ .description('Initialize Safe Mode')
40
+ .option('-p, --preset <preset>', 'Preset (yolo, coding, personal, trading, strict)', 'coding')
41
+ .option('--ml', 'Enable ML engines (downloads ~85MB, opt-in)')
42
+ .option('--skip-scan', 'Skip first-run project scan')
43
+ .option('-f, --force', 'Overwrite existing config')
44
+ .action(async (options) => {
45
+ await initCommand({
46
+ preset: options.preset,
47
+ mlEnabled: options.ml,
48
+ skipScan: options.skipScan,
49
+ force: options.force,
50
+ });
51
+ });
52
+ // ============================================================================
53
+ // Proxy Command
54
+ // ============================================================================
55
+ program
56
+ .command('proxy')
57
+ .description('Run as MCP proxy wrapper')
58
+ .option('--preset <preset>', 'Override preset')
59
+ .allowUnknownOption()
60
+ .action(async (options, _command) => {
61
+ // Parse arguments after --
62
+ const dashIndex = process.argv.indexOf('--');
63
+ if (dashIndex === -1) {
64
+ console.error('Usage: safemode proxy [--preset <preset>] -- <command> [args...]');
65
+ process.exit(1);
66
+ }
67
+ const serverArgs = process.argv.slice(dashIndex + 1);
68
+ if (serverArgs.length === 0) {
69
+ console.error('Error: No server command specified');
70
+ process.exit(1);
71
+ }
72
+ const spawnOptions = parseProxyArgs(serverArgs);
73
+ if (!spawnOptions) {
74
+ console.error('Error: Failed to parse server command');
75
+ process.exit(1);
76
+ }
77
+ // Load configuration
78
+ const configLoader = new ConfigLoader();
79
+ const config = await configLoader.load();
80
+ const preset = options.preset || config.preset;
81
+ // Initialize dependencies
82
+ const store = getEventStore();
83
+ const cet = new CETClassifier();
84
+ const atspConfig = createATSPConfig(preset, config.knobs);
85
+ const atsp = new ATSPEngine(atspConfig);
86
+ const knobGate = new KnobGate({
87
+ knobs: config.knobs,
88
+ approveFallback: config.approve_fallback,
89
+ });
90
+ const engines = new EngineRegistry({
91
+ maxSessionCost: config.budget.max_session_cost,
92
+ alertAt: config.budget.alert_at,
93
+ failBehavior: 'closed',
94
+ });
95
+ const schemaQuarantine = new SchemaQuarantine(store);
96
+ const outputQuarantine = new OutputQuarantine(store);
97
+ const tofu = new TOFUManager(store);
98
+ const notifications = getNotificationManager();
99
+ // Create dependencies object
100
+ const deps = {
101
+ schemaQuarantine: {
102
+ scan: (tools) => schemaQuarantine.scan(tools),
103
+ },
104
+ atsp: {
105
+ rewrite: (tools) => atsp.rewrite(tools),
106
+ },
107
+ tofu: {
108
+ pin: (serverName, tools) => tofu.pin(serverName, tools),
109
+ },
110
+ cet: {
111
+ classify: (toolName, params) => cet.classify(toolName, params),
112
+ },
113
+ knobGate: {
114
+ evaluate: (effect) => knobGate.evaluate(effect),
115
+ },
116
+ engines: {
117
+ evaluate: (toolName, serverName, params, effect, session) => engines.evaluate(toolName, serverName, params, effect, session),
118
+ },
119
+ outputQuarantine: {
120
+ scan: (response) => outputQuarantine.scan(response),
121
+ },
122
+ eventStore: {
123
+ logEvent: (event) => store.logEvent(event),
124
+ },
125
+ notifications: {
126
+ notify: (severity, message) => notifications.notify(severity, message),
127
+ },
128
+ };
129
+ // Run proxy
130
+ try {
131
+ await runProxy(spawnOptions, preset, deps);
132
+ }
133
+ catch (error) {
134
+ console.error(`Proxy error: ${error.message}`);
135
+ process.exit(1);
136
+ }
137
+ });
138
+ // ============================================================================
139
+ // Doctor Command
140
+ // ============================================================================
141
+ program
142
+ .command('doctor')
143
+ .description('Health check')
144
+ .action(async () => {
145
+ await doctorCommand();
146
+ });
147
+ // ============================================================================
148
+ // Restore Command (Time Machine)
149
+ // ============================================================================
150
+ program
151
+ .command('restore [timestamp]')
152
+ .description('Restore files from Time Machine snapshots')
153
+ .option('--latest', 'Restore most recent session (default)')
154
+ .option('--list', 'List available restore points')
155
+ .option('-s, --session <id>', 'Restore a specific session')
156
+ .option('-t, --time <HH:MM>', 'Find closest session to timestamp')
157
+ .action(async (timestamp, options) => {
158
+ await restoreCommand({
159
+ latest: options.latest,
160
+ list: options.list,
161
+ session: options.session,
162
+ time: options.time || timestamp,
163
+ });
164
+ });
165
+ // ============================================================================
166
+ // Uninstall Command
167
+ // ============================================================================
168
+ program
169
+ .command('uninstall')
170
+ .description('Restore original MCP configurations and remove hooks')
171
+ .action(async () => {
172
+ await uninstallCommand();
173
+ });
174
+ // ============================================================================
175
+ // History Command
176
+ // ============================================================================
177
+ program
178
+ .command('history')
179
+ .description('View event history')
180
+ .option('-l, --limit <number>', 'Number of events', '20')
181
+ .option('-o, --outcome <outcome>', 'Filter by outcome (block, alert, allowed)')
182
+ .option('--json', 'Output as JSON')
183
+ .action(async (options) => {
184
+ await historyCommand({
185
+ limit: parseInt(options.limit, 10),
186
+ outcome: options.outcome,
187
+ json: options.json,
188
+ });
189
+ });
190
+ // ============================================================================
191
+ // Summary Command
192
+ // ============================================================================
193
+ program
194
+ .command('summary')
195
+ .description('View summary statistics')
196
+ .option('-s, --since <date>', 'Start date (ISO format)')
197
+ .action(async (options) => {
198
+ await summaryCommand({ since: options.since });
199
+ });
200
+ // ============================================================================
201
+ // Activity Command
202
+ // ============================================================================
203
+ program
204
+ .command('activity')
205
+ .description('View activity feed')
206
+ .option('-l, --limit <number>', 'Number of entries', '50')
207
+ .option('-s, --severity <level>', 'Minimum severity (info, low, medium, high, critical)')
208
+ .action(async (options) => {
209
+ await activityCommand({
210
+ limit: parseInt(options.limit, 10),
211
+ severity: options.severity,
212
+ });
213
+ });
214
+ // ============================================================================
215
+ // Hook Check Command
216
+ // ============================================================================
217
+ program
218
+ .command('hook-check')
219
+ .description('Check IDE hook installation status')
220
+ .option('--fix', 'Install missing hooks')
221
+ .action(async (options) => {
222
+ await hookCheckCommand({ fix: options.fix });
223
+ });
224
+ // ============================================================================
225
+ // Claude Code Command
226
+ // ============================================================================
227
+ program
228
+ .command('claude-code <action>')
229
+ .description('Manage Claude Code integration (install|uninstall|status)')
230
+ .action(async (action) => {
231
+ await claudeCodeCommand(action);
232
+ });
233
+ // ============================================================================
234
+ // Cursor Command
235
+ // ============================================================================
236
+ program
237
+ .command('cursor <action>')
238
+ .description('Manage Cursor integration (install|uninstall|status)')
239
+ .action(async (action) => {
240
+ await cursorCommand(action);
241
+ });
242
+ // ============================================================================
243
+ // Connect Command
244
+ // ============================================================================
245
+ program
246
+ .command('connect')
247
+ .description('Connect to TrustScope cloud')
248
+ .option('-k, --api-key <key>', 'API key (smdev_ or ts_ prefix)')
249
+ .option('-u, --api-url <url>', 'API URL (default: https://api.trustscope.ai)')
250
+ .action(async (options) => {
251
+ await connectCommand({
252
+ apiKey: options.apiKey,
253
+ apiUrl: options.apiUrl,
254
+ });
255
+ });
256
+ // ============================================================================
257
+ // Disconnect Command
258
+ // ============================================================================
259
+ program
260
+ .command('disconnect')
261
+ .description('Disconnect from TrustScope cloud')
262
+ .action(async () => {
263
+ await disconnectCommand();
264
+ });
265
+ // ============================================================================
266
+ // Sync Command
267
+ // ============================================================================
268
+ program
269
+ .command('sync')
270
+ .description('View and trigger event sync')
271
+ .option('-f, --force', 'Force sync even if no pending events')
272
+ .action(async (options) => {
273
+ await syncCommand({ force: options.force });
274
+ });
275
+ // ============================================================================
276
+ // Cloud Status Command
277
+ // ============================================================================
278
+ program
279
+ .command('cloud-status')
280
+ .description('View TrustScope cloud connection status')
281
+ .action(async () => {
282
+ await cloudStatusCommand();
283
+ });
284
+ // ============================================================================
285
+ // Version Command (explicit, beyond commander's --version)
286
+ // ============================================================================
287
+ program
288
+ .command('version')
289
+ .description('Show Safe Mode version')
290
+ .action(async () => {
291
+ await versionCommand();
292
+ });
293
+ // ============================================================================
294
+ // Status Command
295
+ // ============================================================================
296
+ program
297
+ .command('status')
298
+ .description('Show Safe Mode status (hooks, preset, cloud)')
299
+ .action(async () => {
300
+ await statusCommand();
301
+ });
302
+ // ============================================================================
303
+ // Preset Command
304
+ // ============================================================================
305
+ program
306
+ .command('preset <name>')
307
+ .description('Switch active preset (yolo, coding, personal, trading, strict)')
308
+ .action(async (name) => {
309
+ await presetCommand(name);
310
+ });
311
+ // ============================================================================
312
+ // Allow Command
313
+ // ============================================================================
314
+ program
315
+ .command('allow <action>')
316
+ .description('Allow a blocked action (secrets, pii, delete, write, git, network, packages, commands)')
317
+ .option('--once', 'Allow for this session only (default)')
318
+ .option('--always', 'Permanently allow in config')
319
+ .action(async (action, options) => {
320
+ await allowCommand(action, { once: options.once, always: options.always });
321
+ });
322
+ // ============================================================================
323
+ // Phone Command
324
+ // ============================================================================
325
+ program
326
+ .command('phone')
327
+ .description('Configure phone notifications (Telegram/Discord)')
328
+ .option('--telegram', 'Set up Telegram notifications')
329
+ .option('--discord', 'Set up Discord notifications')
330
+ .option('--test', 'Test current notification setup')
331
+ .option('--disable', 'Disable notifications')
332
+ .action(async (options) => {
333
+ await phoneCommand({
334
+ telegram: options.telegram,
335
+ discord: options.discord,
336
+ test: options.test,
337
+ disable: options.disable,
338
+ });
339
+ });
340
+ // ============================================================================
341
+ // Hook Command (invoked by platform hooks: safemode hook pre/post/cursor-pre/cursor-post)
342
+ // ============================================================================
343
+ import { runGovernancePipeline } from '../src/hooks/hook-runner.js';
344
+ import { closeEventStore } from '../src/store/index.js';
345
+ const hookCmd = program
346
+ .command('hook')
347
+ .description('Run governance hook (called by platform hook configs)');
348
+ async function runHook(surface) {
349
+ // Read input from stdin
350
+ let inputData = '';
351
+ if (!process.stdin.isTTY) {
352
+ inputData = await new Promise((resolve) => {
353
+ const chunks = [];
354
+ let resolved = false;
355
+ const done = (data) => { if (!resolved) {
356
+ resolved = true;
357
+ clearTimeout(timer);
358
+ resolve(data);
359
+ } };
360
+ process.stdin.on('data', (chunk) => chunks.push(chunk));
361
+ process.stdin.on('end', () => done(Buffer.concat(chunks).toString('utf8')));
362
+ const timer = setTimeout(() => done(Buffer.concat(chunks).toString('utf8')), 2000);
363
+ });
364
+ }
365
+ let input;
366
+ try {
367
+ const parsed = JSON.parse(inputData || '{}');
368
+ input = {
369
+ toolName: parsed.toolName || parsed.tool_name || 'unknown',
370
+ serverName: parsed.serverName || parsed.server_name || 'unknown',
371
+ parameters: parsed.parameters || parsed.tool_input || parsed.arguments || parsed.input || {},
372
+ sessionId: parsed.sessionId || parsed.session_id,
373
+ };
374
+ }
375
+ catch {
376
+ // Fail open on parse error — exit 0, no output
377
+ return;
378
+ }
379
+ try {
380
+ const result = await runGovernancePipeline(input, surface);
381
+ // Format output per surface
382
+ if (surface === 'claude-code') {
383
+ // Claude Code PreToolUse: hookSpecificOutput with permissionDecision
384
+ if (result.decision === 'block') {
385
+ process.stdout.write(JSON.stringify({
386
+ hookSpecificOutput: {
387
+ hookEventName: 'PreToolUse',
388
+ permissionDecision: 'deny',
389
+ permissionDecisionReason: result.reason || 'Blocked by Safe Mode',
390
+ },
391
+ }) + '\n');
392
+ }
393
+ // Allow = exit 0 with no output
394
+ }
395
+ else if (surface === 'claude-code-post') {
396
+ // PostToolUse: no blocking capability, just exit 0
397
+ }
398
+ else if (surface.startsWith('cursor')) {
399
+ if (result.decision === 'block') {
400
+ process.stdout.write(JSON.stringify({
401
+ continue: false,
402
+ permission: 'deny',
403
+ userMessage: `Blocked by Safe Mode: ${result.reason}`,
404
+ agentMessage: 'This action violates the active governance policy',
405
+ }) + '\n');
406
+ }
407
+ else {
408
+ process.stdout.write(JSON.stringify({ continue: true }) + '\n');
409
+ }
410
+ }
411
+ else if (surface.startsWith('windsurf')) {
412
+ if (result.decision === 'block') {
413
+ process.stdout.write(JSON.stringify({ blocked: true, reason: result.reason }) + '\n');
414
+ process.exitCode = 2;
415
+ }
416
+ }
417
+ }
418
+ catch (err) {
419
+ process.stderr.write(`[Safe Mode] Hook error: ${err.message}\n`);
420
+ // Fail open — exit 0, no output
421
+ }
422
+ finally {
423
+ try {
424
+ closeEventStore();
425
+ }
426
+ catch { /* ignore */ }
427
+ }
428
+ }
429
+ hookCmd.command('pre').description('Pre-tool-use hook (Claude Code)').action(() => runHook('claude-code'));
430
+ hookCmd.command('post').description('Post-tool-use hook (Claude Code)').action(() => runHook('claude-code-post'));
431
+ hookCmd.command('cursor-pre').description('Pre-tool-use hook (Cursor)').action(() => runHook('cursor'));
432
+ hookCmd.command('cursor-post').description('Post-tool-use hook (Cursor)').action(() => runHook('cursor-post'));
433
+ hookCmd.command('windsurf-pre').description('Pre-tool-use hook (Windsurf)').action(() => runHook('windsurf'));
434
+ hookCmd.command('windsurf-post').description('Post-tool-use hook (Windsurf)').action(() => runHook('windsurf-post'));
435
+ // ============================================================================
436
+ // Parse and Run
437
+ // ============================================================================
438
+ program.parse();
439
+ //# sourceMappingURL=safemode.js.map