micro-models-agent 0.28.9 → 0.29.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.
- package/dist/cli/commands.js +220 -0
- package/dist/cli/completer.js +168 -0
- package/dist/cli/index.js +2 -0
- package/dist/cli/main.js +113 -0
- package/dist/cli/repl.js +987 -0
- package/dist/cli/security-commands.js +166 -0
- package/dist/cli/setup.js +229 -0
- package/dist/config/config.js +186 -0
- package/dist/config/defaults.js +91 -0
- package/dist/config/experts.js +15 -0
- package/dist/config/index.js +3 -0
- package/dist/config/security.js +193 -0
- package/dist/config/types.js +1 -0
- package/dist/core/agent-moe.js +98 -0
- package/dist/core/agent.js +461 -0
- package/dist/core/bootstrap.js +321 -0
- package/dist/core/index.js +2 -0
- package/dist/core/prompt-builder.js +55 -0
- package/dist/core/session-logger.js +122 -0
- package/dist/core/types.js +1 -0
- package/dist/i18n/en.json +461 -0
- package/dist/i18n/index.js +43 -0
- package/dist/i18n/ru.json +461 -0
- package/dist/index.js +22 -0
- package/dist/llm/image-utils.js +144 -0
- package/dist/llm/index.js +4 -0
- package/dist/llm/model-loader.js +78 -0
- package/dist/llm/openai-compat.js +324 -0
- package/dist/llm/orchestrator.js +194 -0
- package/dist/llm/provider.js +10 -0
- package/dist/llm/response.js +39 -0
- package/dist/llm/token-counter.js +39 -0
- package/dist/llm/types.js +1 -0
- package/dist/logger/app-logger.js +76 -0
- package/dist/logger/index.js +1 -0
- package/dist/main.js +2251 -724
- package/dist/migration/backup.js +45 -0
- package/dist/migration/detect.js +50 -0
- package/dist/migration/index.js +2 -0
- package/dist/modules/browser/actions.js +46 -0
- package/dist/modules/browser/cookie-store.js +24 -0
- package/dist/modules/browser/index.js +5 -0
- package/dist/modules/browser/module.js +28 -0
- package/dist/modules/browser/session.js +287 -0
- package/dist/modules/browser/snapshot.js +114 -0
- package/dist/modules/browser/types.js +9 -0
- package/dist/modules/context/history.js +15 -0
- package/dist/modules/context/index.js +1 -0
- package/dist/modules/context/manager.js +240 -0
- package/dist/modules/execution/auditor.js +72 -0
- package/dist/modules/execution/index.js +6 -0
- package/dist/modules/execution/module.js +337 -0
- package/dist/modules/execution/moe-executor.js +209 -0
- package/dist/modules/execution/plan-validator.js +153 -0
- package/dist/modules/execution/planner.js +35 -0
- package/dist/modules/execution/stuck-detector.js +134 -0
- package/dist/modules/execution/tracker.js +53 -0
- package/dist/modules/execution/types.js +1 -0
- package/dist/modules/execution/verifier.js +149 -0
- package/dist/modules/hallucination/confidence.js +54 -0
- package/dist/modules/hallucination/consistency.js +60 -0
- package/dist/modules/hallucination/detector.js +41 -0
- package/dist/modules/hallucination/factual.js +170 -0
- package/dist/modules/hallucination/index.js +4 -0
- package/dist/modules/index.js +5 -0
- package/dist/modules/indexer/cache.js +38 -0
- package/dist/modules/indexer/index.js +3 -0
- package/dist/modules/indexer/module.js +192 -0
- package/dist/modules/indexer/walker.js +101 -0
- package/dist/modules/mcp/client.js +393 -0
- package/dist/modules/mcp/index.js +3 -0
- package/dist/modules/mcp/module.js +146 -0
- package/dist/modules/mcp/registry.js +15 -0
- package/dist/modules/memory/index.js +1 -0
- package/dist/modules/memory/module.js +48 -0
- package/dist/modules/memory/search.js +40 -0
- package/dist/modules/memory/store.js +65 -0
- package/dist/modules/pipelines/engine.js +60 -0
- package/dist/modules/pipelines/index.js +3 -0
- package/dist/modules/pipelines/parser.js +53 -0
- package/dist/modules/pipelines/template.js +14 -0
- package/dist/modules/plugins/builtin/lint-on-write.js +121 -0
- package/dist/modules/plugins/builtin/notify.js +8 -0
- package/dist/modules/plugins/index.js +1 -0
- package/dist/modules/plugins/loader.js +28 -0
- package/dist/modules/plugins/manager.js +161 -0
- package/dist/modules/plugins/types.js +1 -0
- package/dist/modules/processes/detect.js +34 -0
- package/dist/modules/processes/index.js +3 -0
- package/dist/modules/processes/registry.js +148 -0
- package/dist/modules/processes/runner.js +124 -0
- package/dist/modules/registry.js +45 -0
- package/dist/modules/security/audit-log.js +116 -0
- package/dist/modules/security/audit-notifier.js +292 -0
- package/dist/modules/security/command-validator.js +185 -0
- package/dist/modules/security/content-scanner.js +52 -0
- package/dist/modules/security/data-sanitizer.js +97 -0
- package/dist/modules/security/encryption.js +240 -0
- package/dist/modules/security/index.js +14 -0
- package/dist/modules/security/network-validator.js +79 -0
- package/dist/modules/security/path-validator.js +155 -0
- package/dist/modules/security/rate-limiter.js +119 -0
- package/dist/modules/security/security-policies.js +393 -0
- package/dist/modules/security/session-encryption.js +193 -0
- package/dist/modules/security/session-isolation.js +95 -0
- package/dist/modules/session/index.js +3 -0
- package/dist/modules/session/manager.js +167 -0
- package/dist/modules/session/module.js +24 -0
- package/dist/modules/session/store.js +174 -0
- package/dist/modules/session/types.js +1 -0
- package/dist/modules/skills/index.js +3 -0
- package/dist/modules/skills/loader.js +72 -0
- package/dist/modules/skills/matcher.js +27 -0
- package/dist/modules/skills/module.js +143 -0
- package/dist/modules/types.js +1 -0
- package/dist/modules/updater/checker.js +32 -0
- package/dist/modules/updater/index.js +1 -0
- package/dist/modules/user-profile/compressor.js +16 -0
- package/dist/modules/user-profile/index.js +1 -0
- package/dist/modules/user-profile/profile.js +68 -0
- package/dist/tools/approve.js +32 -0
- package/dist/tools/attach-image.js +89 -0
- package/dist/tools/bash.js +140 -0
- package/dist/tools/browser.js +97 -0
- package/dist/tools/create-dir.js +56 -0
- package/dist/tools/delete-file.js +63 -0
- package/dist/tools/edit-file.js +77 -0
- package/dist/tools/executor.js +95 -0
- package/dist/tools/file-info.js +45 -0
- package/dist/tools/filter-tools.js +10 -0
- package/dist/tools/glob-tool.js +26 -0
- package/dist/tools/grep-tool.js +64 -0
- package/dist/tools/index.js +52 -0
- package/dist/tools/list-dir.js +47 -0
- package/dist/tools/load-skill.js +48 -0
- package/dist/tools/mcp-call.js +68 -0
- package/dist/tools/move-file.js +84 -0
- package/dist/tools/path-utils.js +51 -0
- package/dist/tools/pipeline-run.js +144 -0
- package/dist/tools/preview.js +2 -0
- package/dist/tools/process-kill.js +29 -0
- package/dist/tools/process-list.js +38 -0
- package/dist/tools/process-log.js +41 -0
- package/dist/tools/question.js +142 -0
- package/dist/tools/read-file.js +73 -0
- package/dist/tools/recall.js +110 -0
- package/dist/tools/registry.js +36 -0
- package/dist/tools/remember.js +67 -0
- package/dist/tools/scope-check.js +30 -0
- package/dist/tools/search-history.js +64 -0
- package/dist/tools/subagent.js +142 -0
- package/dist/tools/types.js +1 -0
- package/dist/tools/user-input.js +123 -0
- package/dist/tools/web-browse.js +57 -0
- package/dist/tools/web-fetch.js +72 -0
- package/dist/tools/web-search.js +59 -0
- package/dist/tools/write-file.js +80 -0
- package/dist/ui/box.js +81 -0
- package/dist/ui/colors.js +4 -0
- package/dist/ui/diff.js +185 -0
- package/dist/ui/index.js +6 -0
- package/dist/ui/md-formatter.js +212 -0
- package/dist/ui/output.js +13 -0
- package/dist/ui/renderer.js +141 -0
- package/dist/ui/spinner.js +70 -0
- package/dist/ui/table.js +144 -0
- package/package.json +4 -4
|
@@ -0,0 +1,393 @@
|
|
|
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
|
+
bash: {
|
|
13
|
+
blacklist: [
|
|
14
|
+
'rm', 'dd', 'chmod', 'wget', 'curl', 'scp', 'ssh', 'nc', 'netcat',
|
|
15
|
+
'mknod', 'mkfifo', 'ln', 'chown', 'chgrp', 'useradd', 'usermod',
|
|
16
|
+
'passwd', 'sudo', 'su', 'exec', 'eval', 'source', 'kill', 'pkill',
|
|
17
|
+
'killall', 'shutdown', 'reboot', 'halt', 'poweroff', 'format',
|
|
18
|
+
'fdisk', 'parted', 'mkfs', 'mount', 'umount', 'mv', 'cp',
|
|
19
|
+
],
|
|
20
|
+
whitelist: ['ls', 'cat', 'echo', 'grep', 'find', 'pwd', 'whoami', 'date'],
|
|
21
|
+
blockDangerousFlags: true,
|
|
22
|
+
dangerousFlags: [
|
|
23
|
+
'--force', '-rf', '--no-preserve-root', '--recursive', '--all',
|
|
24
|
+
'-x', '-e', '--delete', '--remove', '--dangerous', '--yes', '-y',
|
|
25
|
+
'--no-confirm', '-R', '--no-clobber',
|
|
26
|
+
],
|
|
27
|
+
dangerousOperators: ['>', '>>', '2>', '2>>', '|', '&&', '||', ';', '&', '`'],
|
|
28
|
+
logCommands: true,
|
|
29
|
+
},
|
|
30
|
+
paths: {
|
|
31
|
+
denied: [
|
|
32
|
+
'.git/', 'node_modules/', '.env', '*.key', '*.pem', '*.crt',
|
|
33
|
+
'*.p12', '*.pfx', '*.secret', '*.token', 'package-lock.json',
|
|
34
|
+
'bun.lock', 'yarn.lock', 'pnpm-lock.yaml', '.ssh/', '.config/',
|
|
35
|
+
'.bashrc', '.bash_profile', '.zshrc', '.profile', '/etc/',
|
|
36
|
+
'/usr/', '/var/', '/bin/', '/sbin/', '/root/', '/home/',
|
|
37
|
+
],
|
|
38
|
+
allowed: [],
|
|
39
|
+
},
|
|
40
|
+
network: {
|
|
41
|
+
deniedDomains: [
|
|
42
|
+
'localhost', '127.0.0.1', '0.0.0.0', '::1',
|
|
43
|
+
'*.internal', '*.local', '192.168.*', '10.*', '172.16.*',
|
|
44
|
+
],
|
|
45
|
+
allowedDomains: [],
|
|
46
|
+
requestTimeout: 10000,
|
|
47
|
+
maxResponseSize: 10000,
|
|
48
|
+
},
|
|
49
|
+
maxRecursionDepth: 2,
|
|
50
|
+
maxFileOperations: 50,
|
|
51
|
+
rateLimits: {
|
|
52
|
+
maxRequestsPerMinute: 30,
|
|
53
|
+
maxParallelTasks: 3,
|
|
54
|
+
},
|
|
55
|
+
contentScan: {
|
|
56
|
+
enabled: true,
|
|
57
|
+
dangerousPatterns: [
|
|
58
|
+
/eval\(/,
|
|
59
|
+
/new Function\(/,
|
|
60
|
+
/child_process\.exec\(/,
|
|
61
|
+
/child_process\.spawn\(/,
|
|
62
|
+
/require\('child_process'\)/,
|
|
63
|
+
/require\('http'\)\.createServer/,
|
|
64
|
+
/require\('net'\)\.createServer/,
|
|
65
|
+
/process\.exit\(/,
|
|
66
|
+
/while\(true\)/,
|
|
67
|
+
/for\(\;\;\)/,
|
|
68
|
+
/rm -rf/,
|
|
69
|
+
/dd if=/,
|
|
70
|
+
/chmod 777/,
|
|
71
|
+
/wget /,
|
|
72
|
+
/curl /,
|
|
73
|
+
/ssh /,
|
|
74
|
+
/scp /,
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
sessionEncryption: {
|
|
78
|
+
enabled: true,
|
|
79
|
+
encryptHistory: true,
|
|
80
|
+
encryptSessionLog: true,
|
|
81
|
+
},
|
|
82
|
+
auditNotifier: {
|
|
83
|
+
enabled: true,
|
|
84
|
+
minSeverity: 'low',
|
|
85
|
+
eventTypes: [
|
|
86
|
+
'security_block', 'bash_command', 'file_operation',
|
|
87
|
+
'network_request', 'authentication', 'configuration_change',
|
|
88
|
+
'session_start', 'session_end',
|
|
89
|
+
],
|
|
90
|
+
maxRetries: 3,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Balanced security policy - good security with reasonable flexibility
|
|
96
|
+
* Recommended for: development, single-user systems, general use
|
|
97
|
+
*/
|
|
98
|
+
export const BALANCED_POLICY = {
|
|
99
|
+
name: 'Balanced',
|
|
100
|
+
description: 'Good security with reasonable flexibility. Default policy.',
|
|
101
|
+
preset: 'balanced',
|
|
102
|
+
recommendedFor: ['development', 'single-user', 'general-use', 'testing'],
|
|
103
|
+
config: {
|
|
104
|
+
bash: {
|
|
105
|
+
blacklist: [
|
|
106
|
+
'rm', 'dd', 'chmod', 'wget', 'curl', 'scp', 'ssh', 'nc', 'netcat',
|
|
107
|
+
'mknod', 'mkfifo', 'useradd', 'usermod', 'passwd', 'sudo', 'su',
|
|
108
|
+
'shutdown', 'reboot', 'halt', 'poweroff', 'format',
|
|
109
|
+
'fdisk', 'parted', 'mkfs',
|
|
110
|
+
],
|
|
111
|
+
whitelist: [],
|
|
112
|
+
blockDangerousFlags: true,
|
|
113
|
+
dangerousFlags: [
|
|
114
|
+
'--force', '-rf', '--no-preserve-root', '--recursive', '--all',
|
|
115
|
+
'--delete', '--remove', '--dangerous', '--yes', '-y',
|
|
116
|
+
'--no-confirm',
|
|
117
|
+
],
|
|
118
|
+
dangerousOperators: ['|', '&&', '||', ';', '&', '`'],
|
|
119
|
+
logCommands: true,
|
|
120
|
+
},
|
|
121
|
+
paths: {
|
|
122
|
+
denied: [
|
|
123
|
+
'.git/', 'node_modules/', '.env', '*.key', '*.pem', '*.crt',
|
|
124
|
+
'*.p12', '*.pfx', '*.secret', '*.token', 'package-lock.json',
|
|
125
|
+
'bun.lock', 'yarn.lock', 'pnpm-lock.yaml', '.ssh/',
|
|
126
|
+
],
|
|
127
|
+
allowed: [],
|
|
128
|
+
},
|
|
129
|
+
network: {
|
|
130
|
+
deniedDomains: [],
|
|
131
|
+
allowedDomains: [],
|
|
132
|
+
requestTimeout: 15000,
|
|
133
|
+
maxResponseSize: 15000,
|
|
134
|
+
},
|
|
135
|
+
maxRecursionDepth: 3,
|
|
136
|
+
maxFileOperations: 100,
|
|
137
|
+
rateLimits: {
|
|
138
|
+
maxRequestsPerMinute: 60,
|
|
139
|
+
maxParallelTasks: 5,
|
|
140
|
+
},
|
|
141
|
+
contentScan: {
|
|
142
|
+
enabled: true,
|
|
143
|
+
dangerousPatterns: [
|
|
144
|
+
/eval\(/,
|
|
145
|
+
/new Function\(/,
|
|
146
|
+
/child_process\.exec\(/,
|
|
147
|
+
/child_process\.spawn\(/,
|
|
148
|
+
/require\('child_process'\)/,
|
|
149
|
+
/process\.exit\(/,
|
|
150
|
+
/while\(true\)/,
|
|
151
|
+
/for\(\;\;\)/,
|
|
152
|
+
/rm -rf/,
|
|
153
|
+
/dd if=/,
|
|
154
|
+
/chmod 777/,
|
|
155
|
+
],
|
|
156
|
+
},
|
|
157
|
+
sessionEncryption: {
|
|
158
|
+
enabled: false,
|
|
159
|
+
encryptHistory: true,
|
|
160
|
+
encryptSessionLog: true,
|
|
161
|
+
},
|
|
162
|
+
auditNotifier: {
|
|
163
|
+
enabled: false,
|
|
164
|
+
minSeverity: 'medium',
|
|
165
|
+
eventTypes: ['security_block', 'bash_command', 'file_operation', 'network_request'],
|
|
166
|
+
maxRetries: 3,
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Permissive security policy - minimal security, maximum flexibility
|
|
172
|
+
* Recommended for: trusted environments, local development, testing
|
|
173
|
+
*/
|
|
174
|
+
export const PERMISSIVE_POLICY = {
|
|
175
|
+
name: 'Permissive',
|
|
176
|
+
description: 'Minimal security with maximum flexibility. Use with caution.',
|
|
177
|
+
preset: 'permissive',
|
|
178
|
+
recommendedFor: ['trusted-environment', 'local-dev', 'testing', 'sandbox'],
|
|
179
|
+
config: {
|
|
180
|
+
bash: {
|
|
181
|
+
blacklist: [
|
|
182
|
+
'rm', 'dd', 'shutdown', 'reboot', 'halt', 'poweroff',
|
|
183
|
+
'format', 'fdisk', 'parted', 'mkfs',
|
|
184
|
+
],
|
|
185
|
+
whitelist: [],
|
|
186
|
+
blockDangerousFlags: false,
|
|
187
|
+
dangerousFlags: ['--force', '-rf', '--no-preserve-root'],
|
|
188
|
+
dangerousOperators: [],
|
|
189
|
+
logCommands: true,
|
|
190
|
+
},
|
|
191
|
+
paths: {
|
|
192
|
+
denied: ['.env', '*.key', '*.pem', '*.crt', '*.p12', '*.pfx'],
|
|
193
|
+
allowed: [],
|
|
194
|
+
},
|
|
195
|
+
network: {
|
|
196
|
+
deniedDomains: [],
|
|
197
|
+
allowedDomains: [],
|
|
198
|
+
requestTimeout: 30000,
|
|
199
|
+
maxResponseSize: 30000,
|
|
200
|
+
},
|
|
201
|
+
maxRecursionDepth: 5,
|
|
202
|
+
maxFileOperations: 200,
|
|
203
|
+
rateLimits: {
|
|
204
|
+
maxRequestsPerMinute: 120,
|
|
205
|
+
maxParallelTasks: 10,
|
|
206
|
+
},
|
|
207
|
+
contentScan: {
|
|
208
|
+
enabled: true,
|
|
209
|
+
dangerousPatterns: [
|
|
210
|
+
/eval\(/,
|
|
211
|
+
/new Function\(/,
|
|
212
|
+
/while\(true\)/,
|
|
213
|
+
/for\(\;\;\)/,
|
|
214
|
+
/rm -rf/,
|
|
215
|
+
/dd if=/,
|
|
216
|
+
],
|
|
217
|
+
},
|
|
218
|
+
sessionEncryption: {
|
|
219
|
+
enabled: false,
|
|
220
|
+
encryptHistory: false,
|
|
221
|
+
encryptSessionLog: false,
|
|
222
|
+
},
|
|
223
|
+
auditNotifier: {
|
|
224
|
+
enabled: false,
|
|
225
|
+
minSeverity: 'high',
|
|
226
|
+
eventTypes: ['security_block'],
|
|
227
|
+
maxRetries: 2,
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* All available security policies
|
|
233
|
+
*/
|
|
234
|
+
export const SECURITY_POLICIES = {
|
|
235
|
+
strict: STRICT_POLICY,
|
|
236
|
+
balanced: BALANCED_POLICY,
|
|
237
|
+
permissive: PERMISSIVE_POLICY,
|
|
238
|
+
custom: {
|
|
239
|
+
name: 'Custom',
|
|
240
|
+
description: 'Custom security configuration',
|
|
241
|
+
preset: 'custom',
|
|
242
|
+
recommendedFor: [],
|
|
243
|
+
config: {},
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* Security policy manager
|
|
248
|
+
*/
|
|
249
|
+
export class SecurityPolicyManager {
|
|
250
|
+
currentPolicy = 'balanced';
|
|
251
|
+
customConfig = {};
|
|
252
|
+
/**
|
|
253
|
+
* Get all available policies
|
|
254
|
+
*/
|
|
255
|
+
getPolicies() {
|
|
256
|
+
return Object.values(SECURITY_POLICIES);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Get a specific policy by name
|
|
260
|
+
*/
|
|
261
|
+
getPolicy(preset) {
|
|
262
|
+
return SECURITY_POLICIES[preset] || SECURITY_POLICIES.balanced;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Get the current policy
|
|
266
|
+
*/
|
|
267
|
+
getCurrentPolicy() {
|
|
268
|
+
if (this.currentPolicy === 'custom') {
|
|
269
|
+
return {
|
|
270
|
+
...SECURITY_POLICIES.custom,
|
|
271
|
+
config: this.customConfig,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
return this.getPolicy(this.currentPolicy);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Set the current policy
|
|
278
|
+
*/
|
|
279
|
+
setPolicy(preset) {
|
|
280
|
+
this.currentPolicy = preset;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Set custom configuration (for 'custom' preset)
|
|
284
|
+
*/
|
|
285
|
+
setCustomConfig(config) {
|
|
286
|
+
this.customConfig = config;
|
|
287
|
+
this.currentPolicy = 'custom';
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Get the current security configuration
|
|
291
|
+
*/
|
|
292
|
+
getConfig() {
|
|
293
|
+
const policy = this.getCurrentPolicy();
|
|
294
|
+
return mergeSecurityConfig({
|
|
295
|
+
...policy.config,
|
|
296
|
+
...(this.currentPolicy === 'custom' ? this.customConfig : {}),
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Apply a policy and return the merged configuration
|
|
301
|
+
*/
|
|
302
|
+
applyPolicy(preset, customOverrides) {
|
|
303
|
+
this.setPolicy(preset);
|
|
304
|
+
if (customOverrides) {
|
|
305
|
+
this.customConfig = customOverrides;
|
|
306
|
+
this.currentPolicy = 'custom';
|
|
307
|
+
}
|
|
308
|
+
return this.getConfig();
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Get policy recommendation for a use case
|
|
312
|
+
*/
|
|
313
|
+
getRecommendation(useCase) {
|
|
314
|
+
for (const policy of this.getPolicies()) {
|
|
315
|
+
if (policy.recommendedFor.includes(useCase)) {
|
|
316
|
+
return policy;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return BALANCED_POLICY;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Check if current policy allows a specific action
|
|
323
|
+
*/
|
|
324
|
+
allowsAction(action, context) {
|
|
325
|
+
const config = this.getConfig();
|
|
326
|
+
switch (action) {
|
|
327
|
+
case 'bash':
|
|
328
|
+
if (context?.command) {
|
|
329
|
+
const cmd = context.command.split(' ')[0];
|
|
330
|
+
return !config.bash.blacklist.includes(cmd);
|
|
331
|
+
}
|
|
332
|
+
return true;
|
|
333
|
+
case 'file_access':
|
|
334
|
+
if (context?.path) {
|
|
335
|
+
for (const denied of config.paths.denied) {
|
|
336
|
+
if (context.path.includes(denied.replace('*', ''))) {
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return true;
|
|
342
|
+
case 'network':
|
|
343
|
+
if (context?.path) {
|
|
344
|
+
for (const denied of config.network.deniedDomains) {
|
|
345
|
+
if (context.path.includes(denied.replace('*', ''))) {
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return true;
|
|
351
|
+
default:
|
|
352
|
+
return true;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Get policy comparison
|
|
357
|
+
*/
|
|
358
|
+
comparePolicies(policy1, policy2) {
|
|
359
|
+
const config1 = this.getPolicy(policy1).config;
|
|
360
|
+
const config2 = this.getPolicy(policy2).config;
|
|
361
|
+
const comparison = {};
|
|
362
|
+
const keys = new Set([...Object.keys(config1), ...Object.keys(config2)]);
|
|
363
|
+
for (const key of keys) {
|
|
364
|
+
comparison[key] = {
|
|
365
|
+
policy1: config1[key],
|
|
366
|
+
policy2: config2[key],
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
return comparison;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Global security policy manager instance
|
|
374
|
+
*/
|
|
375
|
+
export const globalSecurityPolicyManager = new SecurityPolicyManager();
|
|
376
|
+
/**
|
|
377
|
+
* Create a security policy manager with custom configuration
|
|
378
|
+
*/
|
|
379
|
+
export function createSecurityPolicyManager() {
|
|
380
|
+
return new SecurityPolicyManager();
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Get a policy by name
|
|
384
|
+
*/
|
|
385
|
+
export function getSecurityPolicy(preset) {
|
|
386
|
+
return globalSecurityPolicyManager.getPolicy(preset);
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Apply a security policy
|
|
390
|
+
*/
|
|
391
|
+
export function applySecurityPolicy(preset, customOverrides) {
|
|
392
|
+
return globalSecurityPolicyManager.applyPolicy(preset, customOverrides);
|
|
393
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync, existsSync, readdirSync, unlinkSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { homedir } from 'os';
|
|
4
|
+
import { encryptString, decryptString, isEncryptedString, ConfigEncryptor, } from './encryption';
|
|
5
|
+
/**
|
|
6
|
+
* Default session encryption configuration
|
|
7
|
+
*/
|
|
8
|
+
export const DEFAULT_SESSION_ENCRYPTION = {
|
|
9
|
+
enabled: false,
|
|
10
|
+
encryptHistory: true,
|
|
11
|
+
encryptSessionLog: true,
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Session file encryptor/decryptor
|
|
15
|
+
*/
|
|
16
|
+
export class SessionFileEncryptor {
|
|
17
|
+
config;
|
|
18
|
+
encryptor;
|
|
19
|
+
constructor(config) {
|
|
20
|
+
this.config = { ...DEFAULT_SESSION_ENCRYPTION, ...config };
|
|
21
|
+
this.encryptor = new ConfigEncryptor({
|
|
22
|
+
keyPath: config?.keyPath || join(homedir(), '.mma', '.session-encryption-key')
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Check if session file encryption is enabled
|
|
27
|
+
*/
|
|
28
|
+
isEnabled() {
|
|
29
|
+
return this.config.enabled;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Encrypt a session file content
|
|
33
|
+
*/
|
|
34
|
+
encryptFileContent(content) {
|
|
35
|
+
if (!this.config.enabled)
|
|
36
|
+
return content;
|
|
37
|
+
return encryptString(content, this.encryptor.getKey());
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Decrypt a session file content
|
|
41
|
+
*/
|
|
42
|
+
decryptFileContent(content) {
|
|
43
|
+
if (!this.config.enabled)
|
|
44
|
+
return content;
|
|
45
|
+
if (!isEncryptedString(content))
|
|
46
|
+
return content;
|
|
47
|
+
return decryptString(content, this.encryptor.getKey());
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Encrypt a JSON object (for structured files)
|
|
51
|
+
*/
|
|
52
|
+
encryptJSON(obj) {
|
|
53
|
+
if (!this.config.enabled)
|
|
54
|
+
return JSON.stringify(obj);
|
|
55
|
+
return this.encryptFileContent(JSON.stringify(obj));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Decrypt a JSON string
|
|
59
|
+
*/
|
|
60
|
+
decryptJSON(content) {
|
|
61
|
+
if (!this.config.enabled)
|
|
62
|
+
return JSON.parse(content);
|
|
63
|
+
const decrypted = this.decryptFileContent(content);
|
|
64
|
+
return JSON.parse(decrypted);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Encrypt a JSONL file (one JSON object per line)
|
|
68
|
+
*/
|
|
69
|
+
encryptJSONL(lines) {
|
|
70
|
+
if (!this.config.enabled)
|
|
71
|
+
return lines;
|
|
72
|
+
return lines.map(line => this.encryptFileContent(line));
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Decrypt a JSONL file
|
|
76
|
+
*/
|
|
77
|
+
decryptJSONL(lines) {
|
|
78
|
+
if (!this.config.enabled)
|
|
79
|
+
return lines;
|
|
80
|
+
return lines.map(line => this.decryptFileContent(line));
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Read and decrypt a session file
|
|
84
|
+
*/
|
|
85
|
+
readSessionFile(filePath) {
|
|
86
|
+
const content = readFileSync(filePath, 'utf8');
|
|
87
|
+
return this.decryptFileContent(content);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Write and encrypt a session file
|
|
91
|
+
*/
|
|
92
|
+
writeSessionFile(filePath, content) {
|
|
93
|
+
const encrypted = this.encryptFileContent(content);
|
|
94
|
+
writeFileSync(filePath, encrypted, 'utf8');
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Read and decrypt a JSON session file
|
|
98
|
+
*/
|
|
99
|
+
readSessionJSON(filePath) {
|
|
100
|
+
const content = readFileSync(filePath, 'utf8');
|
|
101
|
+
return this.decryptJSON(content);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Write and encrypt a JSON session file
|
|
105
|
+
*/
|
|
106
|
+
writeSessionJSON(filePath, obj) {
|
|
107
|
+
const content = this.encryptJSON(obj);
|
|
108
|
+
writeFileSync(filePath, content, 'utf8');
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Read and decrypt a JSONL session file
|
|
112
|
+
*/
|
|
113
|
+
readSessionJSONL(filePath) {
|
|
114
|
+
const content = readFileSync(filePath, 'utf8');
|
|
115
|
+
const lines = content.split('\n').filter(line => line.trim());
|
|
116
|
+
const decryptedLines = this.decryptJSONL(lines);
|
|
117
|
+
return decryptedLines.map(line => JSON.parse(line));
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Append an encrypted entry to a JSONL file
|
|
121
|
+
*/
|
|
122
|
+
appendToSessionJSONL(filePath, obj) {
|
|
123
|
+
const encryptedLine = this.encryptFileContent(JSON.stringify(obj));
|
|
124
|
+
writeFileSync(filePath, encryptedLine + '\n', { flag: 'a', encoding: 'utf8' });
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Encrypt all session files in a directory
|
|
128
|
+
*/
|
|
129
|
+
encryptSessionDirectory(sessionDir) {
|
|
130
|
+
if (!this.config.enabled)
|
|
131
|
+
return;
|
|
132
|
+
const files = readdirSync(sessionDir);
|
|
133
|
+
for (const file of files) {
|
|
134
|
+
const filePath = join(sessionDir, file);
|
|
135
|
+
if (existsSync(filePath) && !file.endsWith('.enc')) {
|
|
136
|
+
try {
|
|
137
|
+
const content = readFileSync(filePath, 'utf8');
|
|
138
|
+
const encrypted = this.encryptFileContent(content);
|
|
139
|
+
writeFileSync(filePath + '.enc', encrypted, 'utf8');
|
|
140
|
+
unlinkSync(filePath);
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
// Skip binary files or files we can't read
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Decrypt all session files in a directory
|
|
150
|
+
*/
|
|
151
|
+
decryptSessionDirectory(sessionDir) {
|
|
152
|
+
if (!this.config.enabled)
|
|
153
|
+
return;
|
|
154
|
+
const files = readdirSync(sessionDir);
|
|
155
|
+
for (const file of files) {
|
|
156
|
+
if (file.endsWith('.enc')) {
|
|
157
|
+
const encFilePath = join(sessionDir, file);
|
|
158
|
+
const decFilePath = encFilePath.slice(0, -4); // Remove .enc
|
|
159
|
+
try {
|
|
160
|
+
const content = readFileSync(encFilePath, 'utf8');
|
|
161
|
+
const decrypted = this.decryptFileContent(content);
|
|
162
|
+
writeFileSync(decFilePath, decrypted, 'utf8');
|
|
163
|
+
unlinkSync(encFilePath);
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
// Skip files we can't decrypt
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Global session file encryptor instance
|
|
174
|
+
*/
|
|
175
|
+
export const globalSessionEncryptor = new SessionFileEncryptor();
|
|
176
|
+
/**
|
|
177
|
+
* Create a session file encryptor with custom configuration
|
|
178
|
+
*/
|
|
179
|
+
export function createSessionFileEncryptor(config) {
|
|
180
|
+
return new SessionFileEncryptor(config);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Helper to encrypt a message object (for SessionMessage)
|
|
184
|
+
*/
|
|
185
|
+
export function encryptSessionMessage(msg) {
|
|
186
|
+
return globalSessionEncryptor.encryptJSON(msg);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Helper to decrypt a session message
|
|
190
|
+
*/
|
|
191
|
+
export function decryptSessionMessage(encrypted) {
|
|
192
|
+
return globalSessionEncryptor.decryptJSON(encrypted);
|
|
193
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { join, resolve } from 'path';
|
|
2
|
+
import { homedir } from 'os';
|
|
3
|
+
import { mkdirSync, existsSync } from 'fs';
|
|
4
|
+
import { DEFAULT_SECURITY_CONFIG } from '../../config/security';
|
|
5
|
+
/**
|
|
6
|
+
* Default session isolation configuration
|
|
7
|
+
*/
|
|
8
|
+
export const DEFAULT_SESSION_ISOLATION = {
|
|
9
|
+
enabled: false,
|
|
10
|
+
isolatePlugins: true,
|
|
11
|
+
isolateTempFiles: true,
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Create a session context with isolation
|
|
15
|
+
*/
|
|
16
|
+
export function createSessionContext(sessionId, projectDir, isolationConfig, securityOverrides) {
|
|
17
|
+
const config = { ...DEFAULT_SESSION_ISOLATION, ...isolationConfig };
|
|
18
|
+
// Create session-specific temporary directory
|
|
19
|
+
const baseDir = config.baseDir || join(homedir(), '.mma', 'sessions', sessionId);
|
|
20
|
+
const tempDir = join(baseDir, 'temp');
|
|
21
|
+
if (config.isolateTempFiles && !existsSync(tempDir)) {
|
|
22
|
+
try {
|
|
23
|
+
mkdirSync(tempDir, { recursive: true, mode: 0o700 });
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
// If we can't create the temp dir, continue without isolation
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
sessionId,
|
|
31
|
+
tempDir,
|
|
32
|
+
securityOverrides,
|
|
33
|
+
workingDir: projectDir,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get session-specific security configuration
|
|
38
|
+
* Merges global security config with session overrides
|
|
39
|
+
*/
|
|
40
|
+
export function getSessionSecurityConfig(globalConfig, sessionContext) {
|
|
41
|
+
const globalSecurity = globalConfig.security || DEFAULT_SECURITY_CONFIG;
|
|
42
|
+
const sessionOverrides = sessionContext?.securityOverrides;
|
|
43
|
+
if (!sessionOverrides) {
|
|
44
|
+
return globalSecurity;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
...globalSecurity,
|
|
48
|
+
...sessionOverrides,
|
|
49
|
+
// Merge nested objects
|
|
50
|
+
bash: { ...globalSecurity.bash, ...sessionOverrides.bash },
|
|
51
|
+
paths: { ...globalSecurity.paths, ...sessionOverrides.paths },
|
|
52
|
+
network: { ...globalSecurity.network, ...sessionOverrides.network },
|
|
53
|
+
rateLimits: { ...globalSecurity.rateLimits, ...sessionOverrides.rateLimits },
|
|
54
|
+
contentScan: { ...globalSecurity.contentScan, ...sessionOverrides.contentScan },
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get session-specific temporary directory
|
|
59
|
+
*/
|
|
60
|
+
export function getSessionTempDir(sessionContext) {
|
|
61
|
+
return sessionContext.tempDir;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Clean up session-specific temporary data
|
|
65
|
+
*/
|
|
66
|
+
export function cleanupSessionTempDir(sessionContext) {
|
|
67
|
+
// Note: In a real implementation, we would recursively delete the temp dir
|
|
68
|
+
// For now, we just leave it as the OS will clean up eventually
|
|
69
|
+
// In production, you might want to implement proper cleanup
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Create a session-specific file path
|
|
73
|
+
* Ensures the path is within the session's working directory or temp directory
|
|
74
|
+
*/
|
|
75
|
+
export function createSessionFilePath(sessionContext, relativePath, useTempDir = false) {
|
|
76
|
+
const baseDir = useTempDir ? sessionContext.tempDir : sessionContext.workingDir;
|
|
77
|
+
return resolve(baseDir, relativePath);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Check if a path is within the session's allowed directories
|
|
81
|
+
*/
|
|
82
|
+
export function isPathInSessionScope(sessionContext, path) {
|
|
83
|
+
const resolvedPath = resolve(path);
|
|
84
|
+
const workingDir = resolve(sessionContext.workingDir);
|
|
85
|
+
const tempDir = resolve(sessionContext.tempDir);
|
|
86
|
+
// Check if path is within working directory
|
|
87
|
+
if (resolvedPath.startsWith(workingDir + '/') || resolvedPath.startsWith(workingDir + '\\')) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
// Check if path is within temp directory
|
|
91
|
+
if (resolvedPath.startsWith(tempDir + '/') || resolvedPath.startsWith(tempDir + '\\')) {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}
|