micro-models-agent 0.46.2 → 0.46.3

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 (218) hide show
  1. package/README.md +312 -312
  2. package/dist/main.js +711 -784
  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 +48 -48
  7. package/dist/cli/commands.js +0 -323
  8. package/dist/cli/completer.js +0 -167
  9. package/dist/cli/index.js +0 -2
  10. package/dist/cli/main.js +0 -165
  11. package/dist/cli/plugin-commands.js +0 -36
  12. package/dist/cli/repl-commands.js +0 -661
  13. package/dist/cli/repl.js +0 -616
  14. package/dist/cli/run-result.js +0 -22
  15. package/dist/cli/security-commands.js +0 -164
  16. package/dist/cli/setup.js +0 -231
  17. package/dist/config/config.js +0 -249
  18. package/dist/config/defaults.js +0 -124
  19. package/dist/config/experts.js +0 -15
  20. package/dist/config/index.js +0 -3
  21. package/dist/config/security.js +0 -193
  22. package/dist/config/types.js +0 -1
  23. package/dist/core/agent-moe.js +0 -102
  24. package/dist/core/agent.js +0 -886
  25. package/dist/core/bootstrap.js +0 -404
  26. package/dist/core/index.js +0 -2
  27. package/dist/core/prompt-builder.js +0 -76
  28. package/dist/core/session-logger.js +0 -197
  29. package/dist/core/types.js +0 -1
  30. package/dist/core/version.js +0 -24
  31. package/dist/core/workspace.js +0 -76
  32. package/dist/i18n/en.json +0 -598
  33. package/dist/i18n/index.js +0 -46
  34. package/dist/i18n/ru.json +0 -598
  35. package/dist/index.js +0 -22
  36. package/dist/llm/image-utils.js +0 -143
  37. package/dist/llm/index.js +0 -4
  38. package/dist/llm/model-loader.js +0 -78
  39. package/dist/llm/openai-compat.js +0 -359
  40. package/dist/llm/orchestrator.js +0 -198
  41. package/dist/llm/provider.js +0 -10
  42. package/dist/llm/response.js +0 -39
  43. package/dist/llm/token-counter.js +0 -39
  44. package/dist/llm/types.js +0 -1
  45. package/dist/logger/app-logger.js +0 -143
  46. package/dist/logger/file-log.js +0 -151
  47. package/dist/logger/index.js +0 -1
  48. package/dist/migration/backup.js +0 -45
  49. package/dist/migration/detect.js +0 -50
  50. package/dist/migration/index.js +0 -2
  51. package/dist/modules/artifacts/store.js +0 -61
  52. package/dist/modules/browser/actions.js +0 -76
  53. package/dist/modules/browser/bridge-client.js +0 -199
  54. package/dist/modules/browser/bridge-path.js +0 -10
  55. package/dist/modules/browser/cookie-store.js +0 -24
  56. package/dist/modules/browser/driver.js +0 -136
  57. package/dist/modules/browser/index.js +0 -7
  58. package/dist/modules/browser/module.js +0 -29
  59. package/dist/modules/browser/session.js +0 -338
  60. package/dist/modules/browser/snapshot.js +0 -148
  61. package/dist/modules/browser/types.js +0 -12
  62. package/dist/modules/certification/cli.js +0 -174
  63. package/dist/modules/certification/fact-checker.js +0 -82
  64. package/dist/modules/certification/loader.js +0 -105
  65. package/dist/modules/certification/manifest.js +0 -50
  66. package/dist/modules/certification/runner.js +0 -159
  67. package/dist/modules/certification/scenarios.js +0 -124
  68. package/dist/modules/certification/types.js +0 -1
  69. package/dist/modules/context/chunk-query.js +0 -100
  70. package/dist/modules/context/fact-extractor.js +0 -162
  71. package/dist/modules/context/history.js +0 -15
  72. package/dist/modules/context/index.js +0 -1
  73. package/dist/modules/context/manager.js +0 -423
  74. package/dist/modules/execution/audit-runners.js +0 -152
  75. package/dist/modules/execution/auditor.js +0 -218
  76. package/dist/modules/execution/execution-plugin.js +0 -272
  77. package/dist/modules/execution/index.js +0 -8
  78. package/dist/modules/execution/module.js +0 -436
  79. package/dist/modules/execution/moe-executor.js +0 -291
  80. package/dist/modules/execution/plan-coverage.js +0 -68
  81. package/dist/modules/execution/plan-persister.js +0 -46
  82. package/dist/modules/execution/plan-store.js +0 -157
  83. package/dist/modules/execution/plan-tool.js +0 -508
  84. package/dist/modules/execution/plan-validator.js +0 -153
  85. package/dist/modules/execution/planner.js +0 -90
  86. package/dist/modules/execution/stuck-detector.js +0 -510
  87. package/dist/modules/execution/tracker.js +0 -67
  88. package/dist/modules/execution/types.js +0 -1
  89. package/dist/modules/execution/verifier.js +0 -222
  90. package/dist/modules/execution/windows-commands.js +0 -41
  91. package/dist/modules/hallucination/confidence.js +0 -66
  92. package/dist/modules/hallucination/consistency.js +0 -26
  93. package/dist/modules/hallucination/detector.js +0 -43
  94. package/dist/modules/hallucination/factual.js +0 -129
  95. package/dist/modules/hallucination/index.js +0 -5
  96. package/dist/modules/hallucination/js-identifiers.js +0 -262
  97. package/dist/modules/hallucination/llm-judge.js +0 -101
  98. package/dist/modules/index.js +0 -5
  99. package/dist/modules/indexer/cache.js +0 -40
  100. package/dist/modules/indexer/index.js +0 -3
  101. package/dist/modules/indexer/module.js +0 -245
  102. package/dist/modules/indexer/project-profile.js +0 -183
  103. package/dist/modules/indexer/walker.js +0 -101
  104. package/dist/modules/lsp/check-tool.js +0 -58
  105. package/dist/modules/lsp/client.js +0 -278
  106. package/dist/modules/lsp/command.js +0 -60
  107. package/dist/modules/lsp/config.js +0 -135
  108. package/dist/modules/lsp/index.js +0 -3
  109. package/dist/modules/lsp/module.js +0 -232
  110. package/dist/modules/lsp/probe.js +0 -76
  111. package/dist/modules/lsp/project-root.js +0 -32
  112. package/dist/modules/lsp/startup-check.js +0 -141
  113. package/dist/modules/lsp/types.js +0 -1
  114. package/dist/modules/mcp/client.js +0 -399
  115. package/dist/modules/mcp/index.js +0 -3
  116. package/dist/modules/mcp/module.js +0 -142
  117. package/dist/modules/mcp/registry.js +0 -15
  118. package/dist/modules/memory/index.js +0 -1
  119. package/dist/modules/memory/module.js +0 -96
  120. package/dist/modules/memory/search.js +0 -42
  121. package/dist/modules/memory/store.js +0 -69
  122. package/dist/modules/pipelines/engine.js +0 -60
  123. package/dist/modules/pipelines/index.js +0 -3
  124. package/dist/modules/pipelines/parser.js +0 -56
  125. package/dist/modules/pipelines/template.js +0 -14
  126. package/dist/modules/plugins/builtin/lint-on-write.js +0 -231
  127. package/dist/modules/plugins/builtin/notify.js +0 -9
  128. package/dist/modules/plugins/index.js +0 -1
  129. package/dist/modules/plugins/loader.js +0 -70
  130. package/dist/modules/plugins/manager.js +0 -217
  131. package/dist/modules/plugins/types.js +0 -1
  132. package/dist/modules/processes/detect.js +0 -34
  133. package/dist/modules/processes/index.js +0 -2
  134. package/dist/modules/processes/registry.js +0 -327
  135. package/dist/modules/processes/runner.js +0 -23
  136. package/dist/modules/registry.js +0 -47
  137. package/dist/modules/security/audit-log.js +0 -136
  138. package/dist/modules/security/audit-notifier.js +0 -292
  139. package/dist/modules/security/command-validator.js +0 -205
  140. package/dist/modules/security/content-scanner.js +0 -53
  141. package/dist/modules/security/data-sanitizer.js +0 -89
  142. package/dist/modules/security/encryption.js +0 -242
  143. package/dist/modules/security/index.js +0 -14
  144. package/dist/modules/security/network-validator.js +0 -71
  145. package/dist/modules/security/path-validator.js +0 -207
  146. package/dist/modules/security/rate-limiter.js +0 -119
  147. package/dist/modules/security/security-policies.js +0 -531
  148. package/dist/modules/security/session-encryption.js +0 -210
  149. package/dist/modules/security/session-isolation.js +0 -95
  150. package/dist/modules/session/index.js +0 -3
  151. package/dist/modules/session/manager.js +0 -172
  152. package/dist/modules/session/module.js +0 -24
  153. package/dist/modules/session/store.js +0 -222
  154. package/dist/modules/session/types.js +0 -1
  155. package/dist/modules/skills/index.js +0 -2
  156. package/dist/modules/skills/loader.js +0 -72
  157. package/dist/modules/skills/matcher.js +0 -27
  158. package/dist/modules/skills/module.js +0 -129
  159. package/dist/modules/types.js +0 -1
  160. package/dist/modules/updater/checker.js +0 -96
  161. package/dist/modules/updater/index.js +0 -2
  162. package/dist/modules/updater/module.js +0 -116
  163. package/dist/modules/user-profile/compressor.js +0 -16
  164. package/dist/modules/user-profile/index.js +0 -1
  165. package/dist/modules/user-profile/profile.js +0 -68
  166. package/dist/tools/approve.js +0 -32
  167. package/dist/tools/attach-image.js +0 -89
  168. package/dist/tools/bash.js +0 -496
  169. package/dist/tools/browser.js +0 -114
  170. package/dist/tools/chunk-query.js +0 -99
  171. package/dist/tools/create-dir.js +0 -55
  172. package/dist/tools/delete-file.js +0 -62
  173. package/dist/tools/download-file.js +0 -116
  174. package/dist/tools/edit-file.js +0 -79
  175. package/dist/tools/enable-tools.js +0 -58
  176. package/dist/tools/executor.js +0 -144
  177. package/dist/tools/file-info.js +0 -46
  178. package/dist/tools/filter-tools.js +0 -17
  179. package/dist/tools/glob-tool.js +0 -26
  180. package/dist/tools/grep-tool.js +0 -84
  181. package/dist/tools/hidden-tools-block.js +0 -37
  182. package/dist/tools/index.js +0 -78
  183. package/dist/tools/list-dir.js +0 -48
  184. package/dist/tools/load-skill.js +0 -42
  185. package/dist/tools/mcp-call.js +0 -68
  186. package/dist/tools/move-file.js +0 -85
  187. package/dist/tools/path-utils.js +0 -51
  188. package/dist/tools/pipeline-run.js +0 -144
  189. package/dist/tools/preview.js +0 -2
  190. package/dist/tools/process-kill.js +0 -29
  191. package/dist/tools/process-list.js +0 -36
  192. package/dist/tools/process-log.js +0 -45
  193. package/dist/tools/question.js +0 -140
  194. package/dist/tools/read-file.js +0 -91
  195. package/dist/tools/recall.js +0 -117
  196. package/dist/tools/registry.js +0 -47
  197. package/dist/tools/remember.js +0 -67
  198. package/dist/tools/scope-check.js +0 -30
  199. package/dist/tools/search-history.js +0 -84
  200. package/dist/tools/subagent.js +0 -196
  201. package/dist/tools/types.js +0 -1
  202. package/dist/tools/user-input.js +0 -123
  203. package/dist/tools/web-browse.js +0 -86
  204. package/dist/tools/web-fetch.js +0 -98
  205. package/dist/tools/web-search.js +0 -78
  206. package/dist/tools/write-file.js +0 -81
  207. package/dist/ui/box.js +0 -77
  208. package/dist/ui/colors.js +0 -4
  209. package/dist/ui/diff.js +0 -178
  210. package/dist/ui/index.js +0 -6
  211. package/dist/ui/line-editor.js +0 -703
  212. package/dist/ui/line-math.js +0 -69
  213. package/dist/ui/md-formatter.js +0 -212
  214. package/dist/ui/output.js +0 -13
  215. package/dist/ui/plan-view.js +0 -103
  216. package/dist/ui/renderer.js +0 -209
  217. package/dist/ui/spinner.js +0 -70
  218. package/dist/ui/table.js +0 -144
@@ -1,119 +0,0 @@
1
- /**
2
- * Rate limiter for LLM requests
3
- * Prevents DoS attacks by limiting the number of requests per time window
4
- */
5
- const DEFAULT_CONFIG = {
6
- maxRequestsPerMinute: 60,
7
- maxParallelTasks: 5,
8
- };
9
- /**
10
- * Rate limiter class for tracking LLM requests
11
- */
12
- export class RateLimiter {
13
- config;
14
- state;
15
- lastCleanup = 0;
16
- constructor(config) {
17
- this.config = { ...DEFAULT_CONFIG, ...config };
18
- this.state = {
19
- requests: [],
20
- parallelTasks: 0,
21
- };
22
- }
23
- /**
24
- * Check if a new request is allowed
25
- * Returns true if the request is allowed, false if rate limited
26
- */
27
- canMakeRequest() {
28
- this.cleanupOldRequests();
29
- if (this.state.requests.length >= this.config.maxRequestsPerMinute) {
30
- return false;
31
- }
32
- return true;
33
- }
34
- /**
35
- * Record a request
36
- */
37
- recordRequest() {
38
- this.cleanupOldRequests();
39
- this.state.requests.push(Date.now());
40
- }
41
- /**
42
- * Check if a new parallel task is allowed
43
- */
44
- canStartParallelTask() {
45
- if (this.state.parallelTasks >= this.config.maxParallelTasks) {
46
- return false;
47
- }
48
- return true;
49
- }
50
- /**
51
- * Start a parallel task
52
- */
53
- startParallelTask() {
54
- this.state.parallelTasks++;
55
- }
56
- /**
57
- * End a parallel task
58
- */
59
- endParallelTask() {
60
- this.state.parallelTasks = Math.max(0, this.state.parallelTasks - 1);
61
- }
62
- /**
63
- * Get current parallel task count
64
- */
65
- getParallelTaskCount() {
66
- return this.state.parallelTasks;
67
- }
68
- /**
69
- * Get remaining requests in current window
70
- */
71
- getRemainingRequests() {
72
- this.cleanupOldRequests();
73
- return Math.max(0, this.config.maxRequestsPerMinute - this.state.requests.length);
74
- }
75
- /**
76
- * Clean up old requests (older than 1 minute)
77
- */
78
- cleanupOldRequests() {
79
- const now = Date.now();
80
- const oneMinuteAgo = now - 60_000;
81
- // Only cleanup every 5 seconds to avoid performance overhead
82
- if (now - this.lastCleanup < 5000) {
83
- return;
84
- }
85
- this.state.requests = this.state.requests.filter((timestamp) => timestamp > oneMinuteAgo);
86
- this.lastCleanup = now;
87
- }
88
- /**
89
- * Reset the rate limiter
90
- */
91
- reset() {
92
- this.state.requests = [];
93
- this.state.parallelTasks = 0;
94
- this.lastCleanup = 0;
95
- }
96
- /**
97
- * Get rate limit configuration
98
- */
99
- getConfig() {
100
- return this.config;
101
- }
102
- /**
103
- * Update rate limit configuration
104
- */
105
- updateConfig(config) {
106
- this.config = { ...this.config, ...config };
107
- }
108
- }
109
- /**
110
- * Global rate limiter instance
111
- * Can be used by LLM provider to enforce rate limits
112
- */
113
- export const globalRateLimiter = new RateLimiter();
114
- /**
115
- * Create a rate limiter with custom configuration
116
- */
117
- export function createRateLimiter(config) {
118
- return new RateLimiter(config);
119
- }
@@ -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
- }