micro-models-agent 0.28.17 → 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.
Files changed (94) hide show
  1. package/dist/cli/commands.js +3 -116
  2. package/dist/cli/main.js +8 -35
  3. package/dist/cli/repl.js +611 -110
  4. package/dist/cli/setup.js +12 -32
  5. package/dist/config/config.js +30 -46
  6. package/dist/config/defaults.js +1 -10
  7. package/dist/config/security.js +8 -15
  8. package/dist/core/agent-moe.js +12 -24
  9. package/dist/core/agent.js +47 -281
  10. package/dist/core/bootstrap.js +36 -52
  11. package/dist/core/session-logger.js +2 -35
  12. package/dist/i18n/en.json +15 -79
  13. package/dist/i18n/index.js +9 -12
  14. package/dist/i18n/ru.json +15 -79
  15. package/dist/index.js +13 -13
  16. package/dist/llm/openai-compat.js +10 -39
  17. package/dist/logger/app-logger.js +16 -83
  18. package/dist/main.js +624 -243
  19. package/dist/modules/browser/session.js +60 -108
  20. package/dist/modules/context/history.js +15 -0
  21. package/dist/modules/context/manager.js +10 -119
  22. package/dist/modules/execution/auditor.js +39 -33
  23. package/dist/modules/execution/index.js +6 -8
  24. package/dist/modules/execution/module.js +32 -474
  25. package/dist/modules/execution/moe-executor.js +40 -97
  26. package/dist/modules/execution/planner.js +13 -63
  27. package/dist/modules/execution/stuck-detector.js +39 -252
  28. package/dist/modules/execution/tracker.js +7 -21
  29. package/dist/modules/execution/verifier.js +17 -46
  30. package/dist/modules/hallucination/confidence.js +2 -7
  31. package/dist/modules/hallucination/consistency.js +42 -8
  32. package/dist/modules/hallucination/detector.js +21 -26
  33. package/dist/modules/hallucination/factual.js +150 -170
  34. package/dist/modules/hallucination/index.js +4 -5
  35. package/dist/modules/index.js +5 -5
  36. package/dist/modules/mcp/client.js +2 -8
  37. package/dist/modules/memory/store.js +0 -4
  38. package/dist/modules/plugins/builtin/lint-on-write.js +38 -143
  39. package/dist/modules/processes/detect.js +34 -0
  40. package/dist/modules/processes/index.js +2 -1
  41. package/dist/modules/processes/registry.js +35 -125
  42. package/dist/modules/processes/runner.js +110 -9
  43. package/dist/modules/security/audit-log.js +10 -30
  44. package/dist/modules/security/command-validator.js +16 -42
  45. package/dist/modules/security/content-scanner.js +8 -9
  46. package/dist/modules/security/network-validator.js +2 -2
  47. package/dist/modules/security/path-validator.js +10 -64
  48. package/dist/modules/security/security-policies.js +67 -221
  49. package/dist/modules/security/session-encryption.js +25 -42
  50. package/dist/modules/session/manager.js +10 -15
  51. package/dist/modules/session/store.js +8 -62
  52. package/dist/modules/skills/index.js +3 -2
  53. package/dist/modules/skills/matcher.js +27 -0
  54. package/dist/modules/skills/module.js +23 -10
  55. package/dist/tools/bash.js +90 -287
  56. package/dist/tools/create-dir.js +1 -0
  57. package/dist/tools/delete-file.js +1 -0
  58. package/dist/tools/edit-file.js +8 -10
  59. package/dist/tools/executor.js +7 -57
  60. package/dist/tools/grep-tool.js +29 -51
  61. package/dist/tools/index.js +40 -55
  62. package/dist/tools/load-skill.js +18 -14
  63. package/dist/tools/move-file.js +2 -3
  64. package/dist/tools/pipeline-run.js +1 -1
  65. package/dist/tools/read-file.js +5 -15
  66. package/dist/tools/search-history.js +22 -42
  67. package/dist/tools/subagent.js +12 -21
  68. package/dist/tools/web-browse.js +25 -54
  69. package/dist/tools/web-fetch.js +34 -60
  70. package/dist/tools/web-search.js +20 -39
  71. package/dist/tools/write-file.js +10 -13
  72. package/dist/ui/diff.js +16 -9
  73. package/dist/ui/renderer.js +6 -69
  74. package/package.json +1 -1
  75. package/dist/cli/repl-commands.js +0 -633
  76. package/dist/core/workspace.js +0 -76
  77. package/dist/logger/file-log.js +0 -151
  78. package/dist/modules/certification/cli.js +0 -176
  79. package/dist/modules/certification/fact-checker.js +0 -84
  80. package/dist/modules/certification/loader.js +0 -111
  81. package/dist/modules/certification/manifest.js +0 -50
  82. package/dist/modules/certification/runner.js +0 -162
  83. package/dist/modules/certification/scenarios.js +0 -124
  84. package/dist/modules/certification/types.js +0 -1
  85. package/dist/modules/execution/plan-coverage.js +0 -68
  86. package/dist/modules/execution/plan-persister.js +0 -46
  87. package/dist/modules/execution/plan-store.js +0 -159
  88. package/dist/modules/hallucination/js-identifiers.js +0 -72
  89. package/dist/modules/hallucination/llm-judge.js +0 -103
  90. package/dist/modules/lsp/client.js +0 -235
  91. package/dist/modules/lsp/config.js +0 -81
  92. package/dist/modules/lsp/index.js +0 -3
  93. package/dist/modules/lsp/module.js +0 -68
  94. package/dist/modules/lsp/types.js +0 -1
@@ -1,134 +1,46 @@
1
- import { mergeSecurityConfig, } from "../../config/security";
1
+ import { mergeSecurityConfig } from '../../config/security';
2
2
  /**
3
3
  * Strict security policy - maximum security, minimum flexibility
4
4
  * Recommended for: production environments, sensitive data, multi-user systems
5
5
  */
6
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"],
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
11
  config: {
12
- enabled: true,
13
12
  bash: {
14
- enabled: true,
15
13
  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",
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',
53
19
  ],
54
- whitelist: ["ls", "cat", "echo", "grep", "find", "pwd", "whoami", "date"],
20
+ whitelist: ['ls', 'cat', 'echo', 'grep', 'find', 'pwd', 'whoami', 'date'],
55
21
  blockDangerousFlags: true,
56
22
  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: [
74
- ">",
75
- ">>",
76
- "2>",
77
- "2>>",
78
- "|",
79
- "&&",
80
- "||",
81
- ";",
82
- "&",
83
- "`",
23
+ '--force', '-rf', '--no-preserve-root', '--recursive', '--all',
24
+ '-x', '-e', '--delete', '--remove', '--dangerous', '--yes', '-y',
25
+ '--no-confirm', '-R', '--no-clobber',
84
26
  ],
27
+ dangerousOperators: ['>', '>>', '2>', '2>>', '|', '&&', '||', ';', '&', '`'],
85
28
  logCommands: true,
86
29
  },
87
30
  paths: {
88
- enabled: true,
89
31
  denied: [
90
- ".git/",
91
- "node_modules/",
92
- ".env",
93
- "*.key",
94
- "*.pem",
95
- "*.crt",
96
- "*.p12",
97
- "*.pfx",
98
- "*.secret",
99
- "*.token",
100
- "package-lock.json",
101
- "bun.lock",
102
- "yarn.lock",
103
- "pnpm-lock.yaml",
104
- ".ssh/",
105
- ".config/",
106
- ".bashrc",
107
- ".bash_profile",
108
- ".zshrc",
109
- ".profile",
110
- "/etc/",
111
- "/usr/",
112
- "/var/",
113
- "/bin/",
114
- "/sbin/",
115
- "/root/",
116
- "/home/",
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/',
117
37
  ],
118
38
  allowed: [],
119
39
  },
120
40
  network: {
121
- enabled: true,
122
41
  deniedDomains: [
123
- "localhost",
124
- "127.0.0.1",
125
- "0.0.0.0",
126
- "::1",
127
- "*.internal",
128
- "*.local",
129
- "192.168.*",
130
- "10.*",
131
- "172.16.*",
42
+ 'localhost', '127.0.0.1', '0.0.0.0', '::1',
43
+ '*.internal', '*.local', '192.168.*', '10.*', '172.16.*',
132
44
  ],
133
45
  allowedDomains: [],
134
46
  requestTimeout: 10000,
@@ -169,16 +81,11 @@ export const STRICT_POLICY = {
169
81
  },
170
82
  auditNotifier: {
171
83
  enabled: true,
172
- minSeverity: "low",
84
+ minSeverity: 'low',
173
85
  eventTypes: [
174
- "security_block",
175
- "bash_command",
176
- "file_operation",
177
- "network_request",
178
- "authentication",
179
- "configuration_change",
180
- "session_start",
181
- "session_end",
86
+ 'security_block', 'bash_command', 'file_operation',
87
+ 'network_request', 'authentication', 'configuration_change',
88
+ 'session_start', 'session_end',
182
89
  ],
183
90
  maxRetries: 3,
184
91
  },
@@ -189,81 +96,37 @@ export const STRICT_POLICY = {
189
96
  * Recommended for: development, single-user systems, general use
190
97
  */
191
98
  export const BALANCED_POLICY = {
192
- name: "Balanced",
193
- description: "Good security with reasonable flexibility. Default policy.",
194
- preset: "balanced",
195
- recommendedFor: ["development", "single-user", "general-use", "testing"],
99
+ name: 'Balanced',
100
+ description: 'Good security with reasonable flexibility. Default policy.',
101
+ preset: 'balanced',
102
+ recommendedFor: ['development', 'single-user', 'general-use', 'testing'],
196
103
  config: {
197
- enabled: true,
198
104
  bash: {
199
- enabled: true,
200
105
  blacklist: [
201
- "rm",
202
- "dd",
203
- "chmod",
204
- "wget",
205
- "curl",
206
- "scp",
207
- "ssh",
208
- "nc",
209
- "netcat",
210
- "mknod",
211
- "mkfifo",
212
- "useradd",
213
- "usermod",
214
- "passwd",
215
- "sudo",
216
- "su",
217
- "shutdown",
218
- "reboot",
219
- "halt",
220
- "poweroff",
221
- "format",
222
- "fdisk",
223
- "parted",
224
- "mkfs",
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',
225
110
  ],
226
111
  whitelist: [],
227
112
  blockDangerousFlags: true,
228
113
  dangerousFlags: [
229
- "--force",
230
- "-rf",
231
- "--no-preserve-root",
232
- "--recursive",
233
- "--all",
234
- "--delete",
235
- "--remove",
236
- "--dangerous",
237
- "--yes",
238
- "-y",
239
- "--no-confirm",
114
+ '--force', '-rf', '--no-preserve-root', '--recursive', '--all',
115
+ '--delete', '--remove', '--dangerous', '--yes', '-y',
116
+ '--no-confirm',
240
117
  ],
241
- dangerousOperators: ["|", "&&", "||", ";", "&", "`"],
118
+ dangerousOperators: ['|', '&&', '||', ';', '&', '`'],
242
119
  logCommands: true,
243
120
  },
244
121
  paths: {
245
- enabled: true,
246
122
  denied: [
247
- ".git/",
248
- "node_modules/",
249
- ".env",
250
- "*.key",
251
- "*.pem",
252
- "*.crt",
253
- "*.p12",
254
- "*.pfx",
255
- "*.secret",
256
- "*.token",
257
- "package-lock.json",
258
- "bun.lock",
259
- "yarn.lock",
260
- "pnpm-lock.yaml",
261
- ".ssh/",
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/',
262
126
  ],
263
127
  allowed: [],
264
128
  },
265
129
  network: {
266
- enabled: true,
267
130
  deniedDomains: [],
268
131
  allowedDomains: [],
269
132
  requestTimeout: 15000,
@@ -298,13 +161,8 @@ export const BALANCED_POLICY = {
298
161
  },
299
162
  auditNotifier: {
300
163
  enabled: false,
301
- minSeverity: "medium",
302
- eventTypes: [
303
- "security_block",
304
- "bash_command",
305
- "file_operation",
306
- "network_request",
307
- ],
164
+ minSeverity: 'medium',
165
+ eventTypes: ['security_block', 'bash_command', 'file_operation', 'network_request'],
308
166
  maxRetries: 3,
309
167
  },
310
168
  },
@@ -314,39 +172,27 @@ export const BALANCED_POLICY = {
314
172
  * Recommended for: trusted environments, local development, testing
315
173
  */
316
174
  export const PERMISSIVE_POLICY = {
317
- name: "Permissive",
318
- description: "Minimal security with maximum flexibility. Use with caution.",
319
- preset: "permissive",
320
- recommendedFor: ["trusted-environment", "local-dev", "testing", "sandbox"],
175
+ name: 'Permissive',
176
+ description: 'Minimal security with maximum flexibility. Use with caution.',
177
+ preset: 'permissive',
178
+ recommendedFor: ['trusted-environment', 'local-dev', 'testing', 'sandbox'],
321
179
  config: {
322
- enabled: true,
323
180
  bash: {
324
- enabled: true,
325
181
  blacklist: [
326
- "rm",
327
- "dd",
328
- "shutdown",
329
- "reboot",
330
- "halt",
331
- "poweroff",
332
- "format",
333
- "fdisk",
334
- "parted",
335
- "mkfs",
182
+ 'rm', 'dd', 'shutdown', 'reboot', 'halt', 'poweroff',
183
+ 'format', 'fdisk', 'parted', 'mkfs',
336
184
  ],
337
185
  whitelist: [],
338
186
  blockDangerousFlags: false,
339
- dangerousFlags: ["--force", "-rf", "--no-preserve-root"],
187
+ dangerousFlags: ['--force', '-rf', '--no-preserve-root'],
340
188
  dangerousOperators: [],
341
189
  logCommands: true,
342
190
  },
343
191
  paths: {
344
- enabled: true,
345
- denied: [".env", "*.key", "*.pem", "*.crt", "*.p12", "*.pfx"],
192
+ denied: ['.env', '*.key', '*.pem', '*.crt', '*.p12', '*.pfx'],
346
193
  allowed: [],
347
194
  },
348
195
  network: {
349
- enabled: true,
350
196
  deniedDomains: [],
351
197
  allowedDomains: [],
352
198
  requestTimeout: 30000,
@@ -376,8 +222,8 @@ export const PERMISSIVE_POLICY = {
376
222
  },
377
223
  auditNotifier: {
378
224
  enabled: false,
379
- minSeverity: "high",
380
- eventTypes: ["security_block"],
225
+ minSeverity: 'high',
226
+ eventTypes: ['security_block'],
381
227
  maxRetries: 2,
382
228
  },
383
229
  },
@@ -390,9 +236,9 @@ export const SECURITY_POLICIES = {
390
236
  balanced: BALANCED_POLICY,
391
237
  permissive: PERMISSIVE_POLICY,
392
238
  custom: {
393
- name: "Custom",
394
- description: "Custom security configuration",
395
- preset: "custom",
239
+ name: 'Custom',
240
+ description: 'Custom security configuration',
241
+ preset: 'custom',
396
242
  recommendedFor: [],
397
243
  config: {},
398
244
  },
@@ -401,7 +247,7 @@ export const SECURITY_POLICIES = {
401
247
  * Security policy manager
402
248
  */
403
249
  export class SecurityPolicyManager {
404
- currentPolicy = "balanced";
250
+ currentPolicy = 'balanced';
405
251
  customConfig = {};
406
252
  /**
407
253
  * Get all available policies
@@ -419,7 +265,7 @@ export class SecurityPolicyManager {
419
265
  * Get the current policy
420
266
  */
421
267
  getCurrentPolicy() {
422
- if (this.currentPolicy === "custom") {
268
+ if (this.currentPolicy === 'custom') {
423
269
  return {
424
270
  ...SECURITY_POLICIES.custom,
425
271
  config: this.customConfig,
@@ -438,7 +284,7 @@ export class SecurityPolicyManager {
438
284
  */
439
285
  setCustomConfig(config) {
440
286
  this.customConfig = config;
441
- this.currentPolicy = "custom";
287
+ this.currentPolicy = 'custom';
442
288
  }
443
289
  /**
444
290
  * Get the current security configuration
@@ -447,7 +293,7 @@ export class SecurityPolicyManager {
447
293
  const policy = this.getCurrentPolicy();
448
294
  return mergeSecurityConfig({
449
295
  ...policy.config,
450
- ...(this.currentPolicy === "custom" ? this.customConfig : {}),
296
+ ...(this.currentPolicy === 'custom' ? this.customConfig : {}),
451
297
  });
452
298
  }
453
299
  /**
@@ -457,7 +303,7 @@ export class SecurityPolicyManager {
457
303
  this.setPolicy(preset);
458
304
  if (customOverrides) {
459
305
  this.customConfig = customOverrides;
460
- this.currentPolicy = "custom";
306
+ this.currentPolicy = 'custom';
461
307
  }
462
308
  return this.getConfig();
463
309
  }
@@ -478,25 +324,25 @@ export class SecurityPolicyManager {
478
324
  allowsAction(action, context) {
479
325
  const config = this.getConfig();
480
326
  switch (action) {
481
- case "bash":
327
+ case 'bash':
482
328
  if (context?.command) {
483
- const cmd = context.command.split(" ")[0];
329
+ const cmd = context.command.split(' ')[0];
484
330
  return !config.bash.blacklist.includes(cmd);
485
331
  }
486
332
  return true;
487
- case "file_access":
333
+ case 'file_access':
488
334
  if (context?.path) {
489
335
  for (const denied of config.paths.denied) {
490
- if (context.path.includes(denied.replace("*", ""))) {
336
+ if (context.path.includes(denied.replace('*', ''))) {
491
337
  return false;
492
338
  }
493
339
  }
494
340
  }
495
341
  return true;
496
- case "network":
342
+ case 'network':
497
343
  if (context?.path) {
498
344
  for (const denied of config.network.deniedDomains) {
499
- if (context.path.includes(denied.replace("*", ""))) {
345
+ if (context.path.includes(denied.replace('*', ''))) {
500
346
  return false;
501
347
  }
502
348
  }
@@ -1,7 +1,7 @@
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";
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
5
  /**
6
6
  * Default session encryption configuration
7
7
  */
@@ -19,7 +19,7 @@ export class SessionFileEncryptor {
19
19
  constructor(config) {
20
20
  this.config = { ...DEFAULT_SESSION_ENCRYPTION, ...config };
21
21
  this.encryptor = new ConfigEncryptor({
22
- keyPath: config?.keyPath || join(homedir(), ".mma", ".session-encryption-key"),
22
+ keyPath: config?.keyPath || join(homedir(), '.mma', '.session-encryption-key')
23
23
  });
24
24
  }
25
25
  /**
@@ -58,16 +58,10 @@ export class SessionFileEncryptor {
58
58
  * Decrypt a JSON string
59
59
  */
60
60
  decryptJSON(content) {
61
- let plain = content;
62
- if (this.config.enabled) {
63
- plain = this.decryptFileContent(content);
64
- }
65
- try {
66
- return JSON.parse(plain);
67
- }
68
- catch {
69
- throw new Error("Invalid JSON content in session file — file may be corrupted or encrypted with a different key");
70
- }
61
+ if (!this.config.enabled)
62
+ return JSON.parse(content);
63
+ const decrypted = this.decryptFileContent(content);
64
+ return JSON.parse(decrypted);
71
65
  }
72
66
  /**
73
67
  * Encrypt a JSONL file (one JSON object per line)
@@ -75,7 +69,7 @@ export class SessionFileEncryptor {
75
69
  encryptJSONL(lines) {
76
70
  if (!this.config.enabled)
77
71
  return lines;
78
- return lines.map((line) => this.encryptFileContent(line));
72
+ return lines.map(line => this.encryptFileContent(line));
79
73
  }
80
74
  /**
81
75
  * Decrypt a JSONL file
@@ -83,13 +77,13 @@ export class SessionFileEncryptor {
83
77
  decryptJSONL(lines) {
84
78
  if (!this.config.enabled)
85
79
  return lines;
86
- return lines.map((line) => this.decryptFileContent(line));
80
+ return lines.map(line => this.decryptFileContent(line));
87
81
  }
88
82
  /**
89
83
  * Read and decrypt a session file
90
84
  */
91
85
  readSessionFile(filePath) {
92
- const content = readFileSync(filePath, "utf8");
86
+ const content = readFileSync(filePath, 'utf8');
93
87
  return this.decryptFileContent(content);
94
88
  }
95
89
  /**
@@ -97,13 +91,13 @@ export class SessionFileEncryptor {
97
91
  */
98
92
  writeSessionFile(filePath, content) {
99
93
  const encrypted = this.encryptFileContent(content);
100
- writeFileSync(filePath, encrypted, "utf8");
94
+ writeFileSync(filePath, encrypted, 'utf8');
101
95
  }
102
96
  /**
103
97
  * Read and decrypt a JSON session file
104
98
  */
105
99
  readSessionJSON(filePath) {
106
- const content = readFileSync(filePath, "utf8");
100
+ const content = readFileSync(filePath, 'utf8');
107
101
  return this.decryptJSON(content);
108
102
  }
109
103
  /**
@@ -111,34 +105,23 @@ export class SessionFileEncryptor {
111
105
  */
112
106
  writeSessionJSON(filePath, obj) {
113
107
  const content = this.encryptJSON(obj);
114
- writeFileSync(filePath, content, "utf8");
108
+ writeFileSync(filePath, content, 'utf8');
115
109
  }
116
110
  /**
117
111
  * Read and decrypt a JSONL session file
118
112
  */
119
113
  readSessionJSONL(filePath) {
120
- const content = readFileSync(filePath, "utf8");
121
- const lines = content.split("\n").filter((line) => line.trim());
114
+ const content = readFileSync(filePath, 'utf8');
115
+ const lines = content.split('\n').filter(line => line.trim());
122
116
  const decryptedLines = this.decryptJSONL(lines);
123
- // Skip malformed lines instead of crashing the whole session log
124
- return decryptedLines.flatMap((line) => {
125
- try {
126
- return [JSON.parse(line)];
127
- }
128
- catch {
129
- return [];
130
- }
131
- });
117
+ return decryptedLines.map(line => JSON.parse(line));
132
118
  }
133
119
  /**
134
120
  * Append an encrypted entry to a JSONL file
135
121
  */
136
122
  appendToSessionJSONL(filePath, obj) {
137
123
  const encryptedLine = this.encryptFileContent(JSON.stringify(obj));
138
- writeFileSync(filePath, encryptedLine + "\n", {
139
- flag: "a",
140
- encoding: "utf8",
141
- });
124
+ writeFileSync(filePath, encryptedLine + '\n', { flag: 'a', encoding: 'utf8' });
142
125
  }
143
126
  /**
144
127
  * Encrypt all session files in a directory
@@ -149,11 +132,11 @@ export class SessionFileEncryptor {
149
132
  const files = readdirSync(sessionDir);
150
133
  for (const file of files) {
151
134
  const filePath = join(sessionDir, file);
152
- if (existsSync(filePath) && !file.endsWith(".enc")) {
135
+ if (existsSync(filePath) && !file.endsWith('.enc')) {
153
136
  try {
154
- const content = readFileSync(filePath, "utf8");
137
+ const content = readFileSync(filePath, 'utf8');
155
138
  const encrypted = this.encryptFileContent(content);
156
- writeFileSync(filePath + ".enc", encrypted, "utf8");
139
+ writeFileSync(filePath + '.enc', encrypted, 'utf8');
157
140
  unlinkSync(filePath);
158
141
  }
159
142
  catch {
@@ -170,13 +153,13 @@ export class SessionFileEncryptor {
170
153
  return;
171
154
  const files = readdirSync(sessionDir);
172
155
  for (const file of files) {
173
- if (file.endsWith(".enc")) {
156
+ if (file.endsWith('.enc')) {
174
157
  const encFilePath = join(sessionDir, file);
175
158
  const decFilePath = encFilePath.slice(0, -4); // Remove .enc
176
159
  try {
177
- const content = readFileSync(encFilePath, "utf8");
160
+ const content = readFileSync(encFilePath, 'utf8');
178
161
  const decrypted = this.decryptFileContent(content);
179
- writeFileSync(decFilePath, decrypted, "utf8");
162
+ writeFileSync(decFilePath, decrypted, 'utf8');
180
163
  unlinkSync(encFilePath);
181
164
  }
182
165
  catch {
@@ -1,5 +1,5 @@
1
- import { t } from "../../i18n/index";
2
- import { createSessionContext, DEFAULT_SESSION_ISOLATION, } from "../../modules/security/session-isolation";
1
+ import { t } from '../../i18n/index';
2
+ import { createSessionContext, DEFAULT_SESSION_ISOLATION } from '../../modules/security/session-isolation';
3
3
  export class SessionManager {
4
4
  store;
5
5
  activeId = null;
@@ -32,7 +32,7 @@ export class SessionManager {
32
32
  create(name, securityOverrides) {
33
33
  const now = new Date().toISOString();
34
34
  const id = `ses_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
35
- const sessionName = name || t("session.default_name", { date: now.slice(0, 10) });
35
+ const sessionName = name || t('session.default_name', { date: now.slice(0, 10) });
36
36
  const meta = {
37
37
  id,
38
38
  name: sessionName,
@@ -73,7 +73,7 @@ export class SessionManager {
73
73
  rename(id, name) {
74
74
  const meta = this.store.loadMeta(id);
75
75
  if (!meta)
76
- throw new Error(t("session.not_found", { id }));
76
+ throw new Error(t('session.not_found', { id }));
77
77
  meta.name = name;
78
78
  this.store.saveMeta(id, meta);
79
79
  }
@@ -87,13 +87,13 @@ export class SessionManager {
87
87
  }
88
88
  setActive(id) {
89
89
  if (!this.store.sessionExists(id)) {
90
- throw new Error(t("session.not_found", { id }));
90
+ throw new Error(t('session.not_found', { id }));
91
91
  }
92
92
  this.activeId = id;
93
93
  }
94
94
  appendMessage(msg) {
95
95
  if (!this.activeId)
96
- throw new Error(t("session.no_active"));
96
+ throw new Error(t('session.no_active'));
97
97
  this.store.appendMessage(this.activeId, msg);
98
98
  }
99
99
  appendLog(entry) {
@@ -117,9 +117,6 @@ export class SessionManager {
117
117
  /**
118
118
  * Get the session context for a specific session
119
119
  */
120
- getSessionDirectory(id) {
121
- return this.store.getSessionDir(id);
122
- }
123
120
  getSessionContextById(sessionId) {
124
121
  if (!this.sessionContexts.has(sessionId)) {
125
122
  const meta = this.store.loadMeta(sessionId);
@@ -151,12 +148,10 @@ export class SessionManager {
151
148
  return {
152
149
  maxFileOperations: overrides.maxFileOperations,
153
150
  maxRecursionDepth: overrides.maxRecursionDepth,
154
- rateLimits: overrides.rateLimits
155
- ? {
156
- maxRequestsPerMinute: overrides.rateLimits.maxRequestsPerMinute ?? 60,
157
- maxParallelTasks: overrides.rateLimits.maxParallelTasks ?? 5,
158
- }
159
- : undefined,
151
+ rateLimits: overrides.rateLimits ? {
152
+ maxRequestsPerMinute: overrides.rateLimits.maxRequestsPerMinute ?? 60,
153
+ maxParallelTasks: overrides.rateLimits.maxParallelTasks ?? 5,
154
+ } : undefined,
160
155
  };
161
156
  }
162
157
  enforceMaxSessions() {