@indiccoder/mentis-cli 1.0.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 (46) hide show
  1. package/README.md +90 -0
  2. package/console.log(tick) +0 -0
  3. package/debug_fs.js +12 -0
  4. package/dist/checkpoint/CheckpointManager.js +53 -0
  5. package/dist/config/ConfigManager.js +55 -0
  6. package/dist/context/ContextManager.js +55 -0
  7. package/dist/context/RepoMapper.js +112 -0
  8. package/dist/index.js +12 -0
  9. package/dist/llm/AnthropicClient.js +70 -0
  10. package/dist/llm/ModelInterface.js +2 -0
  11. package/dist/llm/OpenAIClient.js +58 -0
  12. package/dist/mcp/JsonRpcClient.js +117 -0
  13. package/dist/mcp/McpClient.js +59 -0
  14. package/dist/repl/PersistentShell.js +75 -0
  15. package/dist/repl/ReplManager.js +813 -0
  16. package/dist/tools/FileTools.js +100 -0
  17. package/dist/tools/GitTools.js +127 -0
  18. package/dist/tools/PersistentShellTool.js +30 -0
  19. package/dist/tools/SearchTools.js +83 -0
  20. package/dist/tools/Tool.js +2 -0
  21. package/dist/tools/WebSearchTool.js +60 -0
  22. package/dist/ui/UIManager.js +40 -0
  23. package/package.json +63 -0
  24. package/screenshot_1765779883482_9b30.png +0 -0
  25. package/scripts/test_features.ts +48 -0
  26. package/scripts/test_glm.ts +53 -0
  27. package/scripts/test_models.ts +38 -0
  28. package/src/checkpoint/CheckpointManager.ts +61 -0
  29. package/src/config/ConfigManager.ts +77 -0
  30. package/src/context/ContextManager.ts +63 -0
  31. package/src/context/RepoMapper.ts +119 -0
  32. package/src/index.ts +12 -0
  33. package/src/llm/ModelInterface.ts +47 -0
  34. package/src/llm/OpenAIClient.ts +64 -0
  35. package/src/mcp/JsonRpcClient.ts +103 -0
  36. package/src/mcp/McpClient.ts +75 -0
  37. package/src/repl/PersistentShell.ts +85 -0
  38. package/src/repl/ReplManager.ts +842 -0
  39. package/src/tools/FileTools.ts +89 -0
  40. package/src/tools/GitTools.ts +113 -0
  41. package/src/tools/PersistentShellTool.ts +32 -0
  42. package/src/tools/SearchTools.ts +74 -0
  43. package/src/tools/Tool.ts +6 -0
  44. package/src/tools/WebSearchTool.ts +63 -0
  45. package/src/ui/UIManager.ts +41 -0
  46. package/tsconfig.json +21 -0
@@ -0,0 +1,85 @@
1
+ import { spawn, ChildProcessWithoutNullStreams } from 'child_process';
2
+ import os from 'os';
3
+
4
+ export class PersistentShell {
5
+ private process: ChildProcessWithoutNullStreams | null = null;
6
+ private buffer: string = '';
7
+ private delimiter: string = 'MENTIS_SHELL_DELIMITER';
8
+ private resolveCallback: ((output: string) => void) | null = null;
9
+ private rejectCallback: ((error: Error) => void) | null = null;
10
+
11
+ constructor() {
12
+ // Lazy init: Do not spawn here.
13
+ }
14
+
15
+ private initialize() {
16
+ if (this.process) return;
17
+
18
+ const shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash';
19
+ const args = os.platform() === 'win32' ? ['-NoLogo', '-NoExit', '-Command', '-'] : [];
20
+
21
+ this.process = spawn(shell, args, {
22
+ stdio: ['pipe', 'pipe', 'pipe']
23
+ });
24
+
25
+ this.process.stdout.on('data', (data) => this.handleOutput(data));
26
+ this.process.stderr.on('data', (data) => this.handleOutput(data));
27
+
28
+ this.process.on('error', (err) => {
29
+ console.error('Shell process error:', err);
30
+ });
31
+
32
+ this.process.on('exit', (code) => {
33
+ if (code !== 0) {
34
+ console.warn(`Shell process exited with code ${code}`);
35
+ }
36
+ this.process = null; // Reset on exit
37
+ });
38
+ }
39
+
40
+ private handleOutput(data: Buffer) {
41
+ const chunk = data.toString();
42
+ this.buffer += chunk;
43
+
44
+ if (this.buffer.includes(this.delimiter)) {
45
+ const output = this.buffer.replace(this.delimiter, '').trim();
46
+ if (this.resolveCallback) {
47
+ this.resolveCallback(output);
48
+ this.resolveCallback = null;
49
+ this.rejectCallback = null;
50
+ }
51
+ this.buffer = '';
52
+ }
53
+ }
54
+
55
+ public async execute(command: string): Promise<string> {
56
+ this.initialize(); // Ensure shell is running
57
+
58
+ if (this.resolveCallback) {
59
+ throw new Error('Shell is busy execution another command.');
60
+ }
61
+
62
+ if (!this.process) {
63
+ throw new Error('Failed to initialize shell process.');
64
+ }
65
+
66
+ return new Promise((resolve, reject) => {
67
+ this.resolveCallback = resolve;
68
+ this.rejectCallback = reject;
69
+ this.buffer = '';
70
+
71
+ const cleanCommand = command.replace(/\n/g, '; ');
72
+
73
+ const fullCommand = `${cleanCommand}; echo "${this.delimiter}"\n`;
74
+
75
+ this.process?.stdin.write(fullCommand);
76
+ });
77
+ }
78
+
79
+ public kill() {
80
+ if (this.process) {
81
+ this.process.kill();
82
+ this.process = null;
83
+ }
84
+ }
85
+ }