micro-models-agent 0.28.0 → 0.28.2

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 (167) hide show
  1. package/dist/main.js +826 -650
  2. package/package.json +1 -1
  3. package/dist/cli/commands.js +0 -220
  4. package/dist/cli/completer.js +0 -168
  5. package/dist/cli/index.js +0 -2
  6. package/dist/cli/main.js +0 -113
  7. package/dist/cli/repl.js +0 -987
  8. package/dist/cli/security-commands.js +0 -166
  9. package/dist/cli/setup.js +0 -229
  10. package/dist/config/config.js +0 -186
  11. package/dist/config/defaults.js +0 -91
  12. package/dist/config/experts.js +0 -15
  13. package/dist/config/index.js +0 -3
  14. package/dist/config/security.js +0 -193
  15. package/dist/config/types.js +0 -1
  16. package/dist/core/agent-moe.js +0 -98
  17. package/dist/core/agent.js +0 -461
  18. package/dist/core/bootstrap.js +0 -321
  19. package/dist/core/index.js +0 -2
  20. package/dist/core/prompt-builder.js +0 -55
  21. package/dist/core/session-logger.js +0 -122
  22. package/dist/core/types.js +0 -1
  23. package/dist/i18n/en.json +0 -461
  24. package/dist/i18n/index.js +0 -43
  25. package/dist/i18n/ru.json +0 -461
  26. package/dist/index.js +0 -22
  27. package/dist/llm/image-utils.js +0 -144
  28. package/dist/llm/index.js +0 -4
  29. package/dist/llm/model-loader.js +0 -78
  30. package/dist/llm/openai-compat.js +0 -324
  31. package/dist/llm/orchestrator.js +0 -194
  32. package/dist/llm/provider.js +0 -10
  33. package/dist/llm/response.js +0 -39
  34. package/dist/llm/token-counter.js +0 -39
  35. package/dist/llm/types.js +0 -1
  36. package/dist/logger/app-logger.js +0 -76
  37. package/dist/logger/index.js +0 -1
  38. package/dist/migration/backup.js +0 -45
  39. package/dist/migration/detect.js +0 -50
  40. package/dist/migration/index.js +0 -2
  41. package/dist/modules/browser/actions.js +0 -46
  42. package/dist/modules/browser/cookie-store.js +0 -24
  43. package/dist/modules/browser/index.js +0 -5
  44. package/dist/modules/browser/module.js +0 -28
  45. package/dist/modules/browser/session.js +0 -287
  46. package/dist/modules/browser/snapshot.js +0 -114
  47. package/dist/modules/browser/types.js +0 -9
  48. package/dist/modules/context/history.js +0 -15
  49. package/dist/modules/context/index.js +0 -1
  50. package/dist/modules/context/manager.js +0 -240
  51. package/dist/modules/execution/auditor.js +0 -72
  52. package/dist/modules/execution/index.js +0 -6
  53. package/dist/modules/execution/module.js +0 -337
  54. package/dist/modules/execution/moe-executor.js +0 -209
  55. package/dist/modules/execution/plan-validator.js +0 -153
  56. package/dist/modules/execution/planner.js +0 -35
  57. package/dist/modules/execution/stuck-detector.js +0 -134
  58. package/dist/modules/execution/tracker.js +0 -53
  59. package/dist/modules/execution/types.js +0 -1
  60. package/dist/modules/execution/verifier.js +0 -149
  61. package/dist/modules/hallucination/confidence.js +0 -54
  62. package/dist/modules/hallucination/consistency.js +0 -60
  63. package/dist/modules/hallucination/detector.js +0 -41
  64. package/dist/modules/hallucination/factual.js +0 -170
  65. package/dist/modules/hallucination/index.js +0 -4
  66. package/dist/modules/index.js +0 -5
  67. package/dist/modules/indexer/cache.js +0 -38
  68. package/dist/modules/indexer/index.js +0 -3
  69. package/dist/modules/indexer/module.js +0 -192
  70. package/dist/modules/indexer/walker.js +0 -101
  71. package/dist/modules/mcp/client.js +0 -393
  72. package/dist/modules/mcp/index.js +0 -3
  73. package/dist/modules/mcp/module.js +0 -146
  74. package/dist/modules/mcp/registry.js +0 -15
  75. package/dist/modules/memory/index.js +0 -1
  76. package/dist/modules/memory/module.js +0 -48
  77. package/dist/modules/memory/search.js +0 -40
  78. package/dist/modules/memory/store.js +0 -65
  79. package/dist/modules/pipelines/engine.js +0 -60
  80. package/dist/modules/pipelines/index.js +0 -3
  81. package/dist/modules/pipelines/parser.js +0 -53
  82. package/dist/modules/pipelines/template.js +0 -14
  83. package/dist/modules/plugins/builtin/lint-on-write.js +0 -121
  84. package/dist/modules/plugins/builtin/notify.js +0 -8
  85. package/dist/modules/plugins/index.js +0 -1
  86. package/dist/modules/plugins/loader.js +0 -28
  87. package/dist/modules/plugins/manager.js +0 -161
  88. package/dist/modules/plugins/types.js +0 -1
  89. package/dist/modules/processes/detect.js +0 -34
  90. package/dist/modules/processes/index.js +0 -3
  91. package/dist/modules/processes/registry.js +0 -148
  92. package/dist/modules/processes/runner.js +0 -124
  93. package/dist/modules/registry.js +0 -45
  94. package/dist/modules/security/audit-log.js +0 -116
  95. package/dist/modules/security/audit-notifier.js +0 -292
  96. package/dist/modules/security/command-validator.js +0 -185
  97. package/dist/modules/security/content-scanner.js +0 -52
  98. package/dist/modules/security/data-sanitizer.js +0 -97
  99. package/dist/modules/security/encryption.js +0 -240
  100. package/dist/modules/security/index.js +0 -14
  101. package/dist/modules/security/network-validator.js +0 -79
  102. package/dist/modules/security/path-validator.js +0 -155
  103. package/dist/modules/security/rate-limiter.js +0 -119
  104. package/dist/modules/security/security-policies.js +0 -393
  105. package/dist/modules/security/session-encryption.js +0 -193
  106. package/dist/modules/security/session-isolation.js +0 -95
  107. package/dist/modules/session/index.js +0 -3
  108. package/dist/modules/session/manager.js +0 -167
  109. package/dist/modules/session/module.js +0 -24
  110. package/dist/modules/session/store.js +0 -174
  111. package/dist/modules/session/types.js +0 -1
  112. package/dist/modules/skills/index.js +0 -3
  113. package/dist/modules/skills/loader.js +0 -72
  114. package/dist/modules/skills/matcher.js +0 -27
  115. package/dist/modules/skills/module.js +0 -143
  116. package/dist/modules/types.js +0 -1
  117. package/dist/modules/updater/checker.js +0 -32
  118. package/dist/modules/updater/index.js +0 -1
  119. package/dist/modules/user-profile/compressor.js +0 -16
  120. package/dist/modules/user-profile/index.js +0 -1
  121. package/dist/modules/user-profile/profile.js +0 -68
  122. package/dist/tools/approve.js +0 -32
  123. package/dist/tools/attach-image.js +0 -89
  124. package/dist/tools/bash.js +0 -140
  125. package/dist/tools/browser.js +0 -97
  126. package/dist/tools/create-dir.js +0 -56
  127. package/dist/tools/delete-file.js +0 -63
  128. package/dist/tools/edit-file.js +0 -77
  129. package/dist/tools/executor.js +0 -95
  130. package/dist/tools/file-info.js +0 -45
  131. package/dist/tools/filter-tools.js +0 -10
  132. package/dist/tools/glob-tool.js +0 -26
  133. package/dist/tools/grep-tool.js +0 -64
  134. package/dist/tools/index.js +0 -52
  135. package/dist/tools/list-dir.js +0 -47
  136. package/dist/tools/load-skill.js +0 -48
  137. package/dist/tools/mcp-call.js +0 -68
  138. package/dist/tools/move-file.js +0 -84
  139. package/dist/tools/path-utils.js +0 -51
  140. package/dist/tools/pipeline-run.js +0 -144
  141. package/dist/tools/preview.js +0 -2
  142. package/dist/tools/process-kill.js +0 -29
  143. package/dist/tools/process-list.js +0 -38
  144. package/dist/tools/process-log.js +0 -41
  145. package/dist/tools/question.js +0 -142
  146. package/dist/tools/read-file.js +0 -73
  147. package/dist/tools/recall.js +0 -110
  148. package/dist/tools/registry.js +0 -36
  149. package/dist/tools/remember.js +0 -67
  150. package/dist/tools/scope-check.js +0 -30
  151. package/dist/tools/search-history.js +0 -64
  152. package/dist/tools/subagent.js +0 -142
  153. package/dist/tools/types.js +0 -1
  154. package/dist/tools/user-input.js +0 -123
  155. package/dist/tools/web-browse.js +0 -57
  156. package/dist/tools/web-fetch.js +0 -72
  157. package/dist/tools/web-search.js +0 -59
  158. package/dist/tools/write-file.js +0 -80
  159. package/dist/ui/box.js +0 -81
  160. package/dist/ui/colors.js +0 -4
  161. package/dist/ui/diff.js +0 -185
  162. package/dist/ui/index.js +0 -6
  163. package/dist/ui/md-formatter.js +0 -212
  164. package/dist/ui/output.js +0 -13
  165. package/dist/ui/renderer.js +0 -141
  166. package/dist/ui/spinner.js +0 -70
  167. package/dist/ui/table.js +0 -144
@@ -1,393 +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
- 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
- }
@@ -1,193 +0,0 @@
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
- }
@@ -1,95 +0,0 @@
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
- }
@@ -1,3 +0,0 @@
1
- export { SessionStore } from './store';
2
- export { SessionManager } from './manager';
3
- export { SessionModule } from './module';