micro-models-agent 0.52.0 → 0.52.1

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 (231) hide show
  1. package/README.md +358 -358
  2. package/dist/main.js +244 -122
  3. package/dist/modules/browser/bridge-server.mjs +202 -202
  4. package/dist/skills/builtin/git.md +36 -36
  5. package/dist/skills/builtin/typescript.md +35 -35
  6. package/package.json +1 -1
  7. package/dist/cli/commands.js +0 -447
  8. package/dist/cli/completer.js +0 -167
  9. package/dist/cli/index.js +0 -2
  10. package/dist/cli/main.js +0 -153
  11. package/dist/cli/plugin-commands.js +0 -36
  12. package/dist/cli/repl-commands.js +0 -761
  13. package/dist/cli/repl.js +0 -702
  14. package/dist/cli/run-result.js +0 -33
  15. package/dist/cli/security-commands.js +0 -164
  16. package/dist/cli/setup.js +0 -237
  17. package/dist/config/config.js +0 -276
  18. package/dist/config/defaults.js +0 -141
  19. package/dist/config/domains.js +0 -179
  20. package/dist/config/experts.js +0 -15
  21. package/dist/config/index.js +0 -4
  22. package/dist/config/security.js +0 -213
  23. package/dist/config/types.js +0 -1
  24. package/dist/core/agent-moe.js +0 -102
  25. package/dist/core/agent.js +0 -1018
  26. package/dist/core/bootstrap.js +0 -481
  27. package/dist/core/crash-handler.js +0 -51
  28. package/dist/core/environment.js +0 -199
  29. package/dist/core/index.js +0 -2
  30. package/dist/core/prompt-builder.js +0 -76
  31. package/dist/core/session-logger.js +0 -251
  32. package/dist/core/types.js +0 -1
  33. package/dist/core/version.js +0 -26
  34. package/dist/core/workspace.js +0 -76
  35. package/dist/i18n/en.json +0 -679
  36. package/dist/i18n/index.js +0 -46
  37. package/dist/i18n/ru.json +0 -679
  38. package/dist/index.js +0 -22
  39. package/dist/llm/image-utils.js +0 -143
  40. package/dist/llm/index.js +0 -4
  41. package/dist/llm/model-loader.js +0 -78
  42. package/dist/llm/openai-compat.js +0 -497
  43. package/dist/llm/orchestrator.js +0 -200
  44. package/dist/llm/provider.js +0 -10
  45. package/dist/llm/response.js +0 -39
  46. package/dist/llm/token-counter.js +0 -39
  47. package/dist/llm/types.js +0 -1
  48. package/dist/logger/app-logger.js +0 -189
  49. package/dist/logger/file-log.js +0 -151
  50. package/dist/logger/index.js +0 -1
  51. package/dist/migration/backup.js +0 -45
  52. package/dist/migration/detect.js +0 -50
  53. package/dist/migration/index.js +0 -2
  54. package/dist/modules/artifacts/store.js +0 -61
  55. package/dist/modules/browser/actions.js +0 -76
  56. package/dist/modules/browser/bridge-client.js +0 -199
  57. package/dist/modules/browser/bridge-path.js +0 -10
  58. package/dist/modules/browser/cookie-store.js +0 -24
  59. package/dist/modules/browser/driver.js +0 -136
  60. package/dist/modules/browser/index.js +0 -7
  61. package/dist/modules/browser/module.js +0 -29
  62. package/dist/modules/browser/session.js +0 -342
  63. package/dist/modules/browser/snapshot.js +0 -148
  64. package/dist/modules/browser/types.js +0 -12
  65. package/dist/modules/certification/cli.js +0 -213
  66. package/dist/modules/certification/fact-checker.js +0 -82
  67. package/dist/modules/certification/loader.js +0 -106
  68. package/dist/modules/certification/manifest.js +0 -58
  69. package/dist/modules/certification/runner.js +0 -245
  70. package/dist/modules/certification/scenarios.js +0 -407
  71. package/dist/modules/certification/types.js +0 -1
  72. package/dist/modules/context/chunk-query.js +0 -100
  73. package/dist/modules/context/fact-extractor.js +0 -168
  74. package/dist/modules/context/history.js +0 -15
  75. package/dist/modules/context/index.js +0 -1
  76. package/dist/modules/context/manager.js +0 -440
  77. package/dist/modules/execution/audit-runners.js +0 -206
  78. package/dist/modules/execution/auditor.js +0 -218
  79. package/dist/modules/execution/execution-plugin.js +0 -431
  80. package/dist/modules/execution/index.js +0 -8
  81. package/dist/modules/execution/module.js +0 -625
  82. package/dist/modules/execution/moe-executor.js +0 -304
  83. package/dist/modules/execution/plan-coverage.js +0 -68
  84. package/dist/modules/execution/plan-persister.js +0 -46
  85. package/dist/modules/execution/plan-store.js +0 -196
  86. package/dist/modules/execution/plan-tool.js +0 -677
  87. package/dist/modules/execution/plan-validator.js +0 -153
  88. package/dist/modules/execution/planner.js +0 -94
  89. package/dist/modules/execution/stuck-detector.js +0 -746
  90. package/dist/modules/execution/tracker.js +0 -69
  91. package/dist/modules/execution/types.js +0 -1
  92. package/dist/modules/execution/verifier.js +0 -235
  93. package/dist/modules/execution/windows-commands.js +0 -41
  94. package/dist/modules/hallucination/confidence.js +0 -66
  95. package/dist/modules/hallucination/consistency.js +0 -26
  96. package/dist/modules/hallucination/detector.js +0 -47
  97. package/dist/modules/hallucination/factual.js +0 -169
  98. package/dist/modules/hallucination/index.js +0 -5
  99. package/dist/modules/hallucination/js-identifiers.js +0 -262
  100. package/dist/modules/hallucination/llm-judge.js +0 -101
  101. package/dist/modules/index.js +0 -5
  102. package/dist/modules/indexer/cache.js +0 -40
  103. package/dist/modules/indexer/index.js +0 -3
  104. package/dist/modules/indexer/module.js +0 -246
  105. package/dist/modules/indexer/project-profile.js +0 -183
  106. package/dist/modules/indexer/walker.js +0 -101
  107. package/dist/modules/lsp/check-tool.js +0 -58
  108. package/dist/modules/lsp/client.js +0 -389
  109. package/dist/modules/lsp/command.js +0 -60
  110. package/dist/modules/lsp/config.js +0 -135
  111. package/dist/modules/lsp/index.js +0 -3
  112. package/dist/modules/lsp/module.js +0 -260
  113. package/dist/modules/lsp/probe.js +0 -86
  114. package/dist/modules/lsp/project-root.js +0 -32
  115. package/dist/modules/lsp/startup-check.js +0 -144
  116. package/dist/modules/lsp/types.js +0 -1
  117. package/dist/modules/mcp/client.js +0 -399
  118. package/dist/modules/mcp/index.js +0 -3
  119. package/dist/modules/mcp/module.js +0 -142
  120. package/dist/modules/mcp/registry.js +0 -15
  121. package/dist/modules/memory/index.js +0 -1
  122. package/dist/modules/memory/module.js +0 -96
  123. package/dist/modules/memory/search.js +0 -42
  124. package/dist/modules/memory/store.js +0 -69
  125. package/dist/modules/pipelines/engine.js +0 -60
  126. package/dist/modules/pipelines/index.js +0 -3
  127. package/dist/modules/pipelines/parser.js +0 -56
  128. package/dist/modules/pipelines/template.js +0 -14
  129. package/dist/modules/plugins/builtin/lint-on-write.js +0 -334
  130. package/dist/modules/plugins/builtin/notify.js +0 -9
  131. package/dist/modules/plugins/index.js +0 -1
  132. package/dist/modules/plugins/loader.js +0 -70
  133. package/dist/modules/plugins/manager.js +0 -261
  134. package/dist/modules/plugins/types.js +0 -1
  135. package/dist/modules/pricing/index.js +0 -61
  136. package/dist/modules/pricing/prices.js +0 -129
  137. package/dist/modules/processes/detect.js +0 -34
  138. package/dist/modules/processes/index.js +0 -2
  139. package/dist/modules/processes/registry.js +0 -327
  140. package/dist/modules/processes/runner.js +0 -23
  141. package/dist/modules/providers/create.js +0 -22
  142. package/dist/modules/providers/fallback.js +0 -79
  143. package/dist/modules/providers/health.js +0 -46
  144. package/dist/modules/providers/index.js +0 -5
  145. package/dist/modules/providers/manager.js +0 -161
  146. package/dist/modules/providers/presets.js +0 -128
  147. package/dist/modules/providers/registry.js +0 -22
  148. package/dist/modules/providers/types.js +0 -1
  149. package/dist/modules/registry.js +0 -48
  150. package/dist/modules/security/audit-log.js +0 -136
  151. package/dist/modules/security/audit-notifier.js +0 -292
  152. package/dist/modules/security/command-validator.js +0 -219
  153. package/dist/modules/security/content-scanner.js +0 -53
  154. package/dist/modules/security/data-sanitizer.js +0 -89
  155. package/dist/modules/security/encryption.js +0 -242
  156. package/dist/modules/security/index.js +0 -14
  157. package/dist/modules/security/network-validator.js +0 -88
  158. package/dist/modules/security/path-validator.js +0 -203
  159. package/dist/modules/security/rate-limiter.js +0 -119
  160. package/dist/modules/security/security-policies.js +0 -531
  161. package/dist/modules/security/session-encryption.js +0 -210
  162. package/dist/modules/security/session-isolation.js +0 -95
  163. package/dist/modules/session/index.js +0 -3
  164. package/dist/modules/session/manager.js +0 -172
  165. package/dist/modules/session/module.js +0 -24
  166. package/dist/modules/session/store.js +0 -222
  167. package/dist/modules/session/types.js +0 -1
  168. package/dist/modules/skills/index.js +0 -2
  169. package/dist/modules/skills/loader.js +0 -72
  170. package/dist/modules/skills/matcher.js +0 -27
  171. package/dist/modules/skills/module.js +0 -129
  172. package/dist/modules/types.js +0 -1
  173. package/dist/modules/updater/checker.js +0 -96
  174. package/dist/modules/updater/index.js +0 -2
  175. package/dist/modules/updater/module.js +0 -116
  176. package/dist/modules/user-profile/compressor.js +0 -16
  177. package/dist/modules/user-profile/index.js +0 -1
  178. package/dist/modules/user-profile/profile.js +0 -68
  179. package/dist/tools/approve.js +0 -33
  180. package/dist/tools/attach-image.js +0 -101
  181. package/dist/tools/bash.js +0 -519
  182. package/dist/tools/browser.js +0 -115
  183. package/dist/tools/chunk-query.js +0 -100
  184. package/dist/tools/create-dir.js +0 -56
  185. package/dist/tools/delete-file.js +0 -63
  186. package/dist/tools/download-file.js +0 -117
  187. package/dist/tools/edit-file.js +0 -80
  188. package/dist/tools/enable-tools.js +0 -59
  189. package/dist/tools/executor.js +0 -154
  190. package/dist/tools/file-info.js +0 -47
  191. package/dist/tools/filter-tools.js +0 -17
  192. package/dist/tools/glob-tool.js +0 -27
  193. package/dist/tools/grep-tool.js +0 -125
  194. package/dist/tools/hidden-tools-block.js +0 -37
  195. package/dist/tools/index.js +0 -78
  196. package/dist/tools/list-dir.js +0 -49
  197. package/dist/tools/load-skill.js +0 -43
  198. package/dist/tools/mcp-call.js +0 -69
  199. package/dist/tools/move-file.js +0 -86
  200. package/dist/tools/path-utils.js +0 -101
  201. package/dist/tools/pipeline-run.js +0 -145
  202. package/dist/tools/preview.js +0 -2
  203. package/dist/tools/process-kill.js +0 -40
  204. package/dist/tools/process-list.js +0 -37
  205. package/dist/tools/process-log.js +0 -54
  206. package/dist/tools/question.js +0 -141
  207. package/dist/tools/read-file.js +0 -179
  208. package/dist/tools/recall.js +0 -118
  209. package/dist/tools/registry.js +0 -47
  210. package/dist/tools/remember.js +0 -68
  211. package/dist/tools/scope-check.js +0 -32
  212. package/dist/tools/search-history.js +0 -85
  213. package/dist/tools/subagent.js +0 -196
  214. package/dist/tools/types.js +0 -1
  215. package/dist/tools/user-input.js +0 -123
  216. package/dist/tools/web-browse.js +0 -87
  217. package/dist/tools/web-fetch.js +0 -119
  218. package/dist/tools/web-search.js +0 -105
  219. package/dist/tools/write-file.js +0 -82
  220. package/dist/ui/box.js +0 -77
  221. package/dist/ui/colors.js +0 -4
  222. package/dist/ui/diff.js +0 -178
  223. package/dist/ui/index.js +0 -6
  224. package/dist/ui/line-editor.js +0 -822
  225. package/dist/ui/line-math.js +0 -73
  226. package/dist/ui/md-formatter.js +0 -212
  227. package/dist/ui/output.js +0 -13
  228. package/dist/ui/plan-view.js +0 -103
  229. package/dist/ui/renderer.js +0 -259
  230. package/dist/ui/spinner.js +0 -70
  231. package/dist/ui/table.js +0 -144
@@ -1,531 +0,0 @@
1
- import { mergeSecurityConfig } from "../../config/security";
2
- /**
3
- * Strict security policy - maximum security, minimum flexibility
4
- * Recommended for: production environments, sensitive data, multi-user systems
5
- */
6
- export const STRICT_POLICY = {
7
- name: "Strict",
8
- description: "Maximum security with minimal flexibility. Blocks most dangerous operations.",
9
- preset: "strict",
10
- recommendedFor: ["production", "sensitive-data", "multi-user", "enterprise"],
11
- config: {
12
- enabled: true,
13
- bash: {
14
- enabled: true,
15
- blacklist: [
16
- "rm",
17
- "dd",
18
- "chmod",
19
- "wget",
20
- "curl",
21
- "scp",
22
- "ssh",
23
- "nc",
24
- "netcat",
25
- "mknod",
26
- "mkfifo",
27
- "ln",
28
- "chown",
29
- "chgrp",
30
- "useradd",
31
- "usermod",
32
- "passwd",
33
- "sudo",
34
- "su",
35
- "exec",
36
- "eval",
37
- "source",
38
- "kill",
39
- "pkill",
40
- "killall",
41
- "shutdown",
42
- "reboot",
43
- "halt",
44
- "poweroff",
45
- "format",
46
- "fdisk",
47
- "parted",
48
- "mkfs",
49
- "mount",
50
- "umount",
51
- "mv",
52
- "cp",
53
- ],
54
- whitelist: ["ls", "cat", "echo", "grep", "find", "pwd", "whoami", "date"],
55
- blockDangerousFlags: true,
56
- dangerousFlags: [
57
- "--force",
58
- "-rf",
59
- "--no-preserve-root",
60
- "--recursive",
61
- "--all",
62
- "-x",
63
- "-e",
64
- "--delete",
65
- "--remove",
66
- "--dangerous",
67
- "--yes",
68
- "-y",
69
- "--no-confirm",
70
- "-R",
71
- "--no-clobber",
72
- ],
73
- dangerousOperators: [">", ">>", "2>", "2>>", "|", "&&", "||", ";", "&", "`"],
74
- logCommands: true,
75
- },
76
- paths: {
77
- enabled: true,
78
- denied: [
79
- ".git/",
80
- "node_modules/",
81
- ".env",
82
- "*.key",
83
- "*.pem",
84
- "*.crt",
85
- "*.p12",
86
- "*.pfx",
87
- "*.secret",
88
- "*.token",
89
- "package-lock.json",
90
- "bun.lock",
91
- "yarn.lock",
92
- "pnpm-lock.yaml",
93
- ".ssh/",
94
- ".config/",
95
- ".bashrc",
96
- ".bash_profile",
97
- ".zshrc",
98
- ".profile",
99
- "/etc/",
100
- "/usr/",
101
- "/var/",
102
- "/bin/",
103
- "/sbin/",
104
- "/root/",
105
- "/home/",
106
- ],
107
- allowed: [],
108
- },
109
- network: {
110
- enabled: true,
111
- deniedDomains: [
112
- "localhost",
113
- "127.0.0.1",
114
- "0.0.0.0",
115
- "::1",
116
- "*.internal",
117
- "*.local",
118
- "192.168.*",
119
- "10.*",
120
- "172.16.*",
121
- ],
122
- allowedDomains: [],
123
- requestTimeout: 10000,
124
- maxResponseSize: 10000,
125
- },
126
- maxRecursionDepth: 2,
127
- maxFileOperations: 50,
128
- rateLimits: {
129
- maxRequestsPerMinute: 30,
130
- maxParallelTasks: 3,
131
- },
132
- contentScan: {
133
- enabled: true,
134
- dangerousPatterns: [
135
- /eval\(/,
136
- /new Function\(/,
137
- /child_process\.exec\(/,
138
- /child_process\.spawn\(/,
139
- /require\('child_process'\)/,
140
- /require\('http'\)\.createServer/,
141
- /require\('net'\)\.createServer/,
142
- /process\.exit\(/,
143
- /while\(true\)/,
144
- /for\(\;\;\)/,
145
- /rm -rf/,
146
- /dd if=/,
147
- /chmod 777/,
148
- /wget /,
149
- /curl /,
150
- /ssh /,
151
- /scp /,
152
- ],
153
- },
154
- sessionEncryption: {
155
- enabled: true,
156
- encryptHistory: true,
157
- encryptSessionLog: true,
158
- },
159
- auditNotifier: {
160
- enabled: true,
161
- minSeverity: "low",
162
- eventTypes: [
163
- "security_block",
164
- "bash_command",
165
- "file_operation",
166
- "network_request",
167
- "authentication",
168
- "configuration_change",
169
- "session_start",
170
- "session_end",
171
- ],
172
- maxRetries: 3,
173
- },
174
- },
175
- };
176
- /**
177
- * Balanced security policy - good security with reasonable flexibility
178
- * Recommended for: development, single-user systems, general use
179
- */
180
- export const BALANCED_POLICY = {
181
- name: "Balanced",
182
- description: "Good security with reasonable flexibility. Default policy.",
183
- preset: "balanced",
184
- recommendedFor: ["development", "single-user", "general-use", "testing"],
185
- config: {
186
- enabled: true,
187
- bash: {
188
- enabled: true,
189
- blacklist: [
190
- "rm",
191
- "dd",
192
- "chmod",
193
- "wget",
194
- "curl",
195
- "scp",
196
- "ssh",
197
- "nc",
198
- "netcat",
199
- "mknod",
200
- "mkfifo",
201
- "useradd",
202
- "usermod",
203
- "passwd",
204
- "sudo",
205
- "su",
206
- "shutdown",
207
- "reboot",
208
- "halt",
209
- "poweroff",
210
- "format",
211
- "fdisk",
212
- "parted",
213
- "mkfs",
214
- ],
215
- whitelist: [],
216
- blockDangerousFlags: true,
217
- dangerousFlags: [
218
- "--force",
219
- "-rf",
220
- "--no-preserve-root",
221
- "--recursive",
222
- "--all",
223
- "--delete",
224
- "--remove",
225
- "--dangerous",
226
- "--yes",
227
- "-y",
228
- "--no-confirm",
229
- ],
230
- dangerousOperators: ["|", "&&", "||", ";", "&", "`"],
231
- logCommands: true,
232
- },
233
- paths: {
234
- enabled: true,
235
- denied: [
236
- ".git/",
237
- "node_modules/",
238
- ".env",
239
- "*.key",
240
- "*.pem",
241
- "*.crt",
242
- "*.p12",
243
- "*.pfx",
244
- "*.secret",
245
- "*.token",
246
- "package-lock.json",
247
- "bun.lock",
248
- "yarn.lock",
249
- "pnpm-lock.yaml",
250
- ".ssh/",
251
- ],
252
- allowed: [],
253
- },
254
- network: {
255
- enabled: true,
256
- deniedDomains: [],
257
- allowedDomains: [],
258
- requestTimeout: 15000,
259
- maxResponseSize: 15000,
260
- },
261
- maxRecursionDepth: 3,
262
- maxFileOperations: 100,
263
- rateLimits: {
264
- maxRequestsPerMinute: 60,
265
- maxParallelTasks: 5,
266
- },
267
- contentScan: {
268
- enabled: true,
269
- dangerousPatterns: [
270
- /eval\(/,
271
- /new Function\(/,
272
- /child_process\.exec\(/,
273
- /child_process\.spawn\(/,
274
- /require\('child_process'\)/,
275
- /process\.exit\(/,
276
- /while\(true\)/,
277
- /for\(\;\;\)/,
278
- /rm -rf/,
279
- /dd if=/,
280
- /chmod 777/,
281
- ],
282
- },
283
- sessionEncryption: {
284
- enabled: false,
285
- encryptHistory: true,
286
- encryptSessionLog: true,
287
- },
288
- auditNotifier: {
289
- enabled: false,
290
- minSeverity: "medium",
291
- eventTypes: ["security_block", "bash_command", "file_operation", "network_request"],
292
- maxRetries: 3,
293
- },
294
- },
295
- };
296
- /**
297
- * Permissive security policy - minimal security, maximum flexibility
298
- * Recommended for: trusted environments, local development, testing
299
- */
300
- export const PERMISSIVE_POLICY = {
301
- name: "Permissive",
302
- description: "Minimal security with maximum flexibility. Use with caution.",
303
- preset: "permissive",
304
- recommendedFor: ["trusted-environment", "local-dev", "testing", "sandbox"],
305
- config: {
306
- enabled: true,
307
- bash: {
308
- enabled: true,
309
- blacklist: [
310
- "rm",
311
- "dd",
312
- "shutdown",
313
- "reboot",
314
- "halt",
315
- "poweroff",
316
- "format",
317
- "fdisk",
318
- "parted",
319
- "mkfs",
320
- ],
321
- whitelist: [],
322
- blockDangerousFlags: false,
323
- dangerousFlags: ["--force", "-rf", "--no-preserve-root"],
324
- dangerousOperators: [],
325
- logCommands: true,
326
- },
327
- paths: {
328
- enabled: true,
329
- denied: [".env", "*.key", "*.pem", "*.crt", "*.p12", "*.pfx"],
330
- allowed: [],
331
- },
332
- network: {
333
- enabled: true,
334
- deniedDomains: [],
335
- allowedDomains: [],
336
- requestTimeout: 30000,
337
- maxResponseSize: 30000,
338
- },
339
- maxRecursionDepth: 5,
340
- maxFileOperations: 200,
341
- rateLimits: {
342
- maxRequestsPerMinute: 120,
343
- maxParallelTasks: 10,
344
- },
345
- contentScan: {
346
- enabled: true,
347
- dangerousPatterns: [
348
- /eval\(/,
349
- /new Function\(/,
350
- /while\(true\)/,
351
- /for\(\;\;\)/,
352
- /rm -rf/,
353
- /dd if=/,
354
- ],
355
- },
356
- sessionEncryption: {
357
- enabled: false,
358
- encryptHistory: false,
359
- encryptSessionLog: false,
360
- },
361
- auditNotifier: {
362
- enabled: false,
363
- minSeverity: "high",
364
- eventTypes: ["security_block"],
365
- maxRetries: 2,
366
- },
367
- },
368
- };
369
- /**
370
- * All available security policies
371
- */
372
- export const SECURITY_POLICIES = {
373
- strict: STRICT_POLICY,
374
- balanced: BALANCED_POLICY,
375
- permissive: PERMISSIVE_POLICY,
376
- custom: {
377
- name: "Custom",
378
- description: "Custom security configuration",
379
- preset: "custom",
380
- recommendedFor: [],
381
- config: {},
382
- },
383
- };
384
- /**
385
- * Security policy manager
386
- */
387
- export class SecurityPolicyManager {
388
- currentPolicy = "balanced";
389
- customConfig = {};
390
- /**
391
- * Get all available policies
392
- */
393
- getPolicies() {
394
- return Object.values(SECURITY_POLICIES);
395
- }
396
- /**
397
- * Get a specific policy by name
398
- */
399
- getPolicy(preset) {
400
- return SECURITY_POLICIES[preset] || SECURITY_POLICIES.balanced;
401
- }
402
- /**
403
- * Get the current policy
404
- */
405
- getCurrentPolicy() {
406
- if (this.currentPolicy === "custom") {
407
- return {
408
- ...SECURITY_POLICIES.custom,
409
- config: this.customConfig,
410
- };
411
- }
412
- return this.getPolicy(this.currentPolicy);
413
- }
414
- /**
415
- * Set the current policy
416
- */
417
- setPolicy(preset) {
418
- this.currentPolicy = preset;
419
- }
420
- /**
421
- * Set custom configuration (for 'custom' preset)
422
- */
423
- setCustomConfig(config) {
424
- this.customConfig = config;
425
- this.currentPolicy = "custom";
426
- }
427
- /**
428
- * Get the current security configuration
429
- */
430
- getConfig() {
431
- const policy = this.getCurrentPolicy();
432
- return mergeSecurityConfig({
433
- ...policy.config,
434
- ...(this.currentPolicy === "custom" ? this.customConfig : {}),
435
- });
436
- }
437
- /**
438
- * Apply a policy and return the merged configuration
439
- */
440
- applyPolicy(preset, customOverrides) {
441
- this.setPolicy(preset);
442
- if (customOverrides) {
443
- this.customConfig = customOverrides;
444
- this.currentPolicy = "custom";
445
- }
446
- return this.getConfig();
447
- }
448
- /**
449
- * Get policy recommendation for a use case
450
- */
451
- getRecommendation(useCase) {
452
- for (const policy of this.getPolicies()) {
453
- if (policy.recommendedFor.includes(useCase)) {
454
- return policy;
455
- }
456
- }
457
- return BALANCED_POLICY;
458
- }
459
- /**
460
- * Check if current policy allows a specific action
461
- */
462
- allowsAction(action, context) {
463
- const config = this.getConfig();
464
- switch (action) {
465
- case "bash":
466
- if (context?.command) {
467
- const cmd = context.command.split(" ")[0];
468
- return !config.bash.blacklist.includes(cmd);
469
- }
470
- return true;
471
- case "file_access":
472
- if (context?.path) {
473
- for (const denied of config.paths.denied) {
474
- if (context.path.includes(denied.replace("*", ""))) {
475
- return false;
476
- }
477
- }
478
- }
479
- return true;
480
- case "network":
481
- if (context?.path) {
482
- for (const denied of config.network.deniedDomains) {
483
- if (context.path.includes(denied.replace("*", ""))) {
484
- return false;
485
- }
486
- }
487
- }
488
- return true;
489
- default:
490
- return true;
491
- }
492
- }
493
- /**
494
- * Get policy comparison
495
- */
496
- comparePolicies(policy1, policy2) {
497
- const config1 = this.getPolicy(policy1).config;
498
- const config2 = this.getPolicy(policy2).config;
499
- const comparison = {};
500
- const keys = new Set([...Object.keys(config1), ...Object.keys(config2)]);
501
- for (const key of keys) {
502
- comparison[key] = {
503
- policy1: config1[key],
504
- policy2: config2[key],
505
- };
506
- }
507
- return comparison;
508
- }
509
- }
510
- /**
511
- * Global security policy manager instance
512
- */
513
- export const globalSecurityPolicyManager = new SecurityPolicyManager();
514
- /**
515
- * Create a security policy manager with custom configuration
516
- */
517
- export function createSecurityPolicyManager() {
518
- return new SecurityPolicyManager();
519
- }
520
- /**
521
- * Get a policy by name
522
- */
523
- export function getSecurityPolicy(preset) {
524
- return globalSecurityPolicyManager.getPolicy(preset);
525
- }
526
- /**
527
- * Apply a security policy
528
- */
529
- export function applySecurityPolicy(preset, customOverrides) {
530
- return globalSecurityPolicyManager.applyPolicy(preset, customOverrides);
531
- }