@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,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.McpClient = void 0;
4
+ const JsonRpcClient_1 = require("./JsonRpcClient");
5
+ class McpClient {
6
+ constructor(command, args) {
7
+ this.serverName = 'unknown';
8
+ this.rpc = new JsonRpcClient_1.JsonRpcClient(command, args);
9
+ }
10
+ async initialize() {
11
+ const result = await this.rpc.sendRequest('initialize', {
12
+ protocolVersion: '2024-11-05',
13
+ capabilities: {},
14
+ clientInfo: {
15
+ name: 'mentis-cli',
16
+ version: '1.0.0',
17
+ },
18
+ });
19
+ this.serverName = result.serverInfo.name;
20
+ // Notify initialized
21
+ this.rpc.sendNotification('notifications/initialized');
22
+ return result;
23
+ }
24
+ async listTools() {
25
+ const result = await this.rpc.sendRequest('tools/list');
26
+ const mcpTools = result.tools || [];
27
+ return mcpTools.map((t) => new McpToolAdapter(this, t));
28
+ }
29
+ async callTool(name, args) {
30
+ return this.rpc.sendRequest('tools/call', {
31
+ name,
32
+ arguments: args,
33
+ });
34
+ }
35
+ disconnect() {
36
+ this.rpc.disconnect();
37
+ }
38
+ }
39
+ exports.McpClient = McpClient;
40
+ class McpToolAdapter {
41
+ constructor(client, toolDef) {
42
+ this.client = client;
43
+ this.name = toolDef.name;
44
+ this.description = toolDef.description || '';
45
+ this.parameters = toolDef.inputSchema || {};
46
+ }
47
+ async execute(args) {
48
+ const result = await this.client.callTool(this.name, args);
49
+ // MCP returns { content: [ { type: 'text', text: '...' } ], isError: boolean }
50
+ if (result.isError) {
51
+ throw new Error('MCP Tool Error');
52
+ }
53
+ // Extract text content
54
+ if (result.content && Array.isArray(result.content)) {
55
+ return result.content.map((c) => c.text).join('\n');
56
+ }
57
+ return JSON.stringify(result);
58
+ }
59
+ }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PersistentShell = void 0;
7
+ const child_process_1 = require("child_process");
8
+ const os_1 = __importDefault(require("os"));
9
+ class PersistentShell {
10
+ constructor() {
11
+ this.process = null;
12
+ this.buffer = '';
13
+ this.delimiter = 'MENTIS_SHELL_DELIMITER';
14
+ this.resolveCallback = null;
15
+ this.rejectCallback = null;
16
+ // Lazy init: Do not spawn here.
17
+ }
18
+ initialize() {
19
+ if (this.process)
20
+ return;
21
+ const shell = os_1.default.platform() === 'win32' ? 'powershell.exe' : 'bash';
22
+ const args = os_1.default.platform() === 'win32' ? ['-NoLogo', '-NoExit', '-Command', '-'] : [];
23
+ this.process = (0, child_process_1.spawn)(shell, args, {
24
+ stdio: ['pipe', 'pipe', 'pipe']
25
+ });
26
+ this.process.stdout.on('data', (data) => this.handleOutput(data));
27
+ this.process.stderr.on('data', (data) => this.handleOutput(data));
28
+ this.process.on('error', (err) => {
29
+ console.error('Shell process error:', err);
30
+ });
31
+ this.process.on('exit', (code) => {
32
+ if (code !== 0) {
33
+ console.warn(`Shell process exited with code ${code}`);
34
+ }
35
+ this.process = null; // Reset on exit
36
+ });
37
+ }
38
+ handleOutput(data) {
39
+ const chunk = data.toString();
40
+ this.buffer += chunk;
41
+ if (this.buffer.includes(this.delimiter)) {
42
+ const output = this.buffer.replace(this.delimiter, '').trim();
43
+ if (this.resolveCallback) {
44
+ this.resolveCallback(output);
45
+ this.resolveCallback = null;
46
+ this.rejectCallback = null;
47
+ }
48
+ this.buffer = '';
49
+ }
50
+ }
51
+ async execute(command) {
52
+ this.initialize(); // Ensure shell is running
53
+ if (this.resolveCallback) {
54
+ throw new Error('Shell is busy execution another command.');
55
+ }
56
+ if (!this.process) {
57
+ throw new Error('Failed to initialize shell process.');
58
+ }
59
+ return new Promise((resolve, reject) => {
60
+ this.resolveCallback = resolve;
61
+ this.rejectCallback = reject;
62
+ this.buffer = '';
63
+ const cleanCommand = command.replace(/\n/g, '; ');
64
+ const fullCommand = `${cleanCommand}; echo "${this.delimiter}"\n`;
65
+ this.process?.stdin.write(fullCommand);
66
+ });
67
+ }
68
+ kill() {
69
+ if (this.process) {
70
+ this.process.kill();
71
+ this.process = null;
72
+ }
73
+ }
74
+ }
75
+ exports.PersistentShell = PersistentShell;