@mcpilotx/intentorch 0.5.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 (101) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +545 -0
  3. package/dist/ai/ai.d.ts +205 -0
  4. package/dist/ai/ai.js +1200 -0
  5. package/dist/ai/cloud-intent-engine.d.ts +270 -0
  6. package/dist/ai/cloud-intent-engine.js +956 -0
  7. package/dist/ai/command.d.ts +59 -0
  8. package/dist/ai/command.js +285 -0
  9. package/dist/ai/config.d.ts +66 -0
  10. package/dist/ai/config.js +211 -0
  11. package/dist/ai/enhanced-intent.d.ts +17 -0
  12. package/dist/ai/enhanced-intent.js +32 -0
  13. package/dist/ai/index.d.ts +29 -0
  14. package/dist/ai/index.js +44 -0
  15. package/dist/ai/intent.d.ts +16 -0
  16. package/dist/ai/intent.js +30 -0
  17. package/dist/core/ai-config.d.ts +25 -0
  18. package/dist/core/ai-config.js +326 -0
  19. package/dist/core/config-manager.d.ts +36 -0
  20. package/dist/core/config-manager.js +400 -0
  21. package/dist/core/config-validator.d.ts +9 -0
  22. package/dist/core/config-validator.js +184 -0
  23. package/dist/core/constants.d.ts +34 -0
  24. package/dist/core/constants.js +37 -0
  25. package/dist/core/error-ai.d.ts +23 -0
  26. package/dist/core/error-ai.js +217 -0
  27. package/dist/core/error-handler.d.ts +197 -0
  28. package/dist/core/error-handler.js +467 -0
  29. package/dist/core/index.d.ts +13 -0
  30. package/dist/core/index.js +17 -0
  31. package/dist/core/logger.d.ts +27 -0
  32. package/dist/core/logger.js +108 -0
  33. package/dist/core/performance-monitor.d.ts +74 -0
  34. package/dist/core/performance-monitor.js +260 -0
  35. package/dist/core/providers.d.ts +36 -0
  36. package/dist/core/providers.js +304 -0
  37. package/dist/core/retry-manager.d.ts +41 -0
  38. package/dist/core/retry-manager.js +204 -0
  39. package/dist/core/types.d.ts +155 -0
  40. package/dist/core/types.js +2 -0
  41. package/dist/daemon/index.d.ts +10 -0
  42. package/dist/daemon/index.js +15 -0
  43. package/dist/daemon/intent-engine.d.ts +22 -0
  44. package/dist/daemon/intent-engine.js +50 -0
  45. package/dist/daemon/orchestrator.d.ts +24 -0
  46. package/dist/daemon/orchestrator.js +100 -0
  47. package/dist/daemon/pm.d.ts +33 -0
  48. package/dist/daemon/pm.js +127 -0
  49. package/dist/daemon/process.d.ts +11 -0
  50. package/dist/daemon/process.js +49 -0
  51. package/dist/daemon/server.d.ts +17 -0
  52. package/dist/daemon/server.js +435 -0
  53. package/dist/daemon/service.d.ts +36 -0
  54. package/dist/daemon/service.js +278 -0
  55. package/dist/index.d.ts +30 -0
  56. package/dist/index.js +36 -0
  57. package/dist/mcp/client.d.ts +51 -0
  58. package/dist/mcp/client.js +276 -0
  59. package/dist/mcp/index.d.ts +162 -0
  60. package/dist/mcp/index.js +199 -0
  61. package/dist/mcp/tool-registry.d.ts +71 -0
  62. package/dist/mcp/tool-registry.js +308 -0
  63. package/dist/mcp/transport.d.ts +83 -0
  64. package/dist/mcp/transport.js +515 -0
  65. package/dist/mcp/types.d.ts +136 -0
  66. package/dist/mcp/types.js +31 -0
  67. package/dist/runtime/adapter-advanced.d.ts +184 -0
  68. package/dist/runtime/adapter-advanced.js +160 -0
  69. package/dist/runtime/adapter.d.ts +9 -0
  70. package/dist/runtime/adapter.js +2 -0
  71. package/dist/runtime/detector-advanced.d.ts +59 -0
  72. package/dist/runtime/detector-advanced.js +487 -0
  73. package/dist/runtime/detector.d.ts +5 -0
  74. package/dist/runtime/detector.js +56 -0
  75. package/dist/runtime/docker-adapter.d.ts +18 -0
  76. package/dist/runtime/docker-adapter.js +170 -0
  77. package/dist/runtime/docker.d.ts +17 -0
  78. package/dist/runtime/docker.js +71 -0
  79. package/dist/runtime/executable-analyzer.d.ts +56 -0
  80. package/dist/runtime/executable-analyzer.js +391 -0
  81. package/dist/runtime/go-adapter.d.ts +19 -0
  82. package/dist/runtime/go-adapter.js +190 -0
  83. package/dist/runtime/index.d.ts +9 -0
  84. package/dist/runtime/index.js +10 -0
  85. package/dist/runtime/node-adapter.d.ts +10 -0
  86. package/dist/runtime/node-adapter.js +23 -0
  87. package/dist/runtime/node.d.ts +20 -0
  88. package/dist/runtime/node.js +86 -0
  89. package/dist/runtime/python-adapter.d.ts +11 -0
  90. package/dist/runtime/python-adapter.js +102 -0
  91. package/dist/runtime/python.d.ts +17 -0
  92. package/dist/runtime/python.js +72 -0
  93. package/dist/runtime/rust-adapter.d.ts +21 -0
  94. package/dist/runtime/rust-adapter.js +267 -0
  95. package/dist/sdk.d.ts +500 -0
  96. package/dist/sdk.js +904 -0
  97. package/docs/README.ZH_CN.md +545 -0
  98. package/docs/api.md +888 -0
  99. package/docs/architecture.md +731 -0
  100. package/docs/development.md +744 -0
  101. package/package.json +112 -0
@@ -0,0 +1,86 @@
1
+ import { spawn, execSync } from 'child_process';
2
+ export class NodeAdapter {
3
+ options;
4
+ process = null;
5
+ requestId = 0;
6
+ pendingRequests = new Map();
7
+ runtime = 'bun';
8
+ constructor(options) {
9
+ this.options = options;
10
+ // Determine which runtime to use
11
+ if (options.runtime) {
12
+ this.runtime = options.runtime;
13
+ }
14
+ else {
15
+ // Auto-detect: try bun first, fallback to node
16
+ try {
17
+ execSync('which bun', { stdio: 'ignore' });
18
+ // Further verify that bun is executable
19
+ execSync('bun --version', { stdio: 'ignore' });
20
+ this.runtime = 'bun';
21
+ }
22
+ catch {
23
+ this.runtime = 'node';
24
+ }
25
+ }
26
+ }
27
+ async start() {
28
+ return new Promise((resolve, reject) => {
29
+ console.log(`[RAL] Starting Node.js service: ${this.options.name} (using ${this.runtime})`);
30
+ const command = this.runtime === 'bun' ? 'bun' : 'node';
31
+ const args = this.runtime === 'bun' ? ['run', 'index.js'] : ['index.js'];
32
+ this.process = spawn(command, args, {
33
+ cwd: this.options.cwd,
34
+ env: { ...process.env, ...this.options.env },
35
+ stdio: ['pipe', 'pipe', 'pipe'],
36
+ });
37
+ this.process.stdout?.on('data', (data) => {
38
+ const raw = data.toString().trim();
39
+ try {
40
+ const json = JSON.parse(raw);
41
+ if (json.id !== undefined && this.pendingRequests.has(json.id)) {
42
+ const resolver = this.pendingRequests.get(json.id);
43
+ resolver?.(json);
44
+ this.pendingRequests.delete(json.id);
45
+ }
46
+ }
47
+ catch (e) {
48
+ // Ignore non-JSON output (such as regular logs)
49
+ console.log(`[${this.options.name}] ${raw}`);
50
+ }
51
+ });
52
+ this.process.stderr?.on('data', (data) => {
53
+ console.error(`[${this.options.name}] ERR: ${data.toString()}`);
54
+ });
55
+ this.process.on('spawn', () => resolve());
56
+ this.process.on('error', (err) => reject(err));
57
+ });
58
+ }
59
+ // Send MCP JSON-RPC request
60
+ async call(method, params = {}) {
61
+ if (!this.process) {
62
+ throw new Error(`Service ${this.options.name} is not running.`);
63
+ }
64
+ const id = ++this.requestId;
65
+ const request = {
66
+ jsonrpc: '2.0',
67
+ id,
68
+ method,
69
+ params,
70
+ };
71
+ return new Promise((resolve) => {
72
+ this.pendingRequests.set(id, resolve);
73
+ this.process?.stdin?.write(JSON.stringify(request) + '\n');
74
+ });
75
+ }
76
+ stop() {
77
+ if (this.process) {
78
+ this.process.kill();
79
+ this.process = null;
80
+ }
81
+ }
82
+ isRunning() {
83
+ return this.process !== null;
84
+ }
85
+ }
86
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1,11 @@
1
+ import { RuntimeAdapter } from './adapter';
2
+ import { ServiceConfig } from '../core/types';
3
+ export declare class PythonAdapter implements RuntimeAdapter {
4
+ getSpawnArgs(config: ServiceConfig): {
5
+ command: string;
6
+ args: string[];
7
+ };
8
+ setup(config: ServiceConfig): Promise<void>;
9
+ private installDependencies;
10
+ }
11
+ //# sourceMappingURL=python-adapter.d.ts.map
@@ -0,0 +1,102 @@
1
+ import { VENVS_DIR } from '../core/constants.js';
2
+ import * as path from 'path';
3
+ import * as fs from 'fs';
4
+ import { exec } from 'child_process';
5
+ import { promisify } from 'util';
6
+ import { logger } from '../core/logger.js';
7
+ const execAsync = promisify(exec);
8
+ export class PythonAdapter {
9
+ getSpawnArgs(config) {
10
+ const venvPath = path.join(VENVS_DIR, config.name);
11
+ const pythonPath = path.join(venvPath, 'bin', 'python');
12
+ return {
13
+ command: pythonPath,
14
+ args: [config.entry, ...(config.args || [])],
15
+ };
16
+ }
17
+ async setup(config) {
18
+ const venvPath = path.join(VENVS_DIR, config.name);
19
+ try {
20
+ // Ensure virtual environment directory exists
21
+ if (!fs.existsSync(VENVS_DIR)) {
22
+ fs.mkdirSync(VENVS_DIR, { recursive: true });
23
+ logger.info(`Created virtual environments directory: ${VENVS_DIR}`);
24
+ }
25
+ // Check if virtual environment already exists
26
+ const venvExists = fs.existsSync(venvPath) &&
27
+ fs.existsSync(path.join(venvPath, 'bin', 'python'));
28
+ if (!venvExists) {
29
+ logger.info(`Creating Python virtual environment for ${config.name} at ${venvPath}`);
30
+ // Create virtual environment
31
+ const { stdout, stderr } = await execAsync(`python3 -m venv "${venvPath}"`);
32
+ if (stderr && !stderr.includes('created virtual environment')) {
33
+ logger.warn(`Virtual environment creation warnings: ${stderr}`);
34
+ }
35
+ logger.info(`Virtual environment created successfully for ${config.name}`);
36
+ }
37
+ else {
38
+ logger.info(`Using existing virtual environment for ${config.name} at ${venvPath}`);
39
+ }
40
+ // Install dependencies (if requirements are configured)
41
+ const pythonConfig = config.runtimeConfig?.python;
42
+ if (pythonConfig?.dependencies) {
43
+ await this.installDependencies(config, venvPath);
44
+ }
45
+ logger.info(`Python setup completed for ${config.name}`);
46
+ }
47
+ catch (error) {
48
+ logger.error(`Failed to setup Python environment for ${config.name}: ${error.message}`, {
49
+ stack: error.stack,
50
+ });
51
+ throw new Error(`Python environment setup failed: ${error.message}`);
52
+ }
53
+ }
54
+ async installDependencies(config, venvPath) {
55
+ const pythonPath = path.join(venvPath, 'bin', 'python');
56
+ const pipPath = path.join(venvPath, 'bin', 'pip');
57
+ try {
58
+ // Check if pip is available
59
+ await execAsync(`${pipPath} --version`);
60
+ const pythonConfig = config.runtimeConfig?.python;
61
+ const deps = pythonConfig?.dependencies;
62
+ if (Array.isArray(deps) && deps.length > 0) {
63
+ logger.info(`Installing Python dependencies for ${config.name}: ${deps.join(', ')}`);
64
+ // Install each dependency
65
+ for (const dep of deps) {
66
+ try {
67
+ const { stdout, stderr } = await execAsync(`${pipPath} install "${dep}"`);
68
+ logger.info(`Installed dependency: ${dep}`);
69
+ if (stderr && stderr.includes('WARNING')) {
70
+ logger.warn(`Installation warnings for ${dep}: ${stderr}`);
71
+ }
72
+ }
73
+ catch (depError) {
74
+ logger.error(`Failed to install dependency ${dep}: ${depError.message}`);
75
+ // Continue installing other dependencies
76
+ }
77
+ }
78
+ logger.info(`All dependencies installed for ${config.name}`);
79
+ }
80
+ else if (typeof deps === 'string' && deps.trim().endsWith('.txt')) {
81
+ // Handle requirements.txt file
82
+ const requirementsPath = path.isAbsolute(deps) ? deps : path.join(process.cwd(), deps);
83
+ if (fs.existsSync(requirementsPath)) {
84
+ logger.info(`Installing dependencies from requirements file: ${requirementsPath}`);
85
+ const { stdout, stderr } = await execAsync(`${pipPath} install -r "${requirementsPath}"`);
86
+ if (stderr && stderr.includes('WARNING')) {
87
+ logger.warn(`Requirements installation warnings: ${stderr}`);
88
+ }
89
+ logger.info(`Dependencies installed from requirements file for ${config.name}`);
90
+ }
91
+ else {
92
+ logger.warn(`Requirements file not found: ${requirementsPath}`);
93
+ }
94
+ }
95
+ }
96
+ catch (error) {
97
+ logger.error(`Failed to install dependencies for ${config.name}: ${error.message}`);
98
+ throw new Error(`Dependency installation failed: ${error.message}`);
99
+ }
100
+ }
101
+ }
102
+ //# sourceMappingURL=python-adapter.js.map
@@ -0,0 +1,17 @@
1
+ export interface AdapterOptions {
2
+ name: string;
3
+ cwd: string;
4
+ env?: Record<string, string>;
5
+ }
6
+ export declare class PythonAdapter {
7
+ private options;
8
+ private process;
9
+ private requestId;
10
+ private pendingRequests;
11
+ constructor(options: AdapterOptions);
12
+ start(): Promise<void>;
13
+ call(method: string, params?: any): Promise<any>;
14
+ stop(): void;
15
+ isRunning(): boolean;
16
+ }
17
+ //# sourceMappingURL=python.d.ts.map
@@ -0,0 +1,72 @@
1
+ import { spawn } from 'child_process';
2
+ import * as path from 'path';
3
+ import * as fs from 'fs';
4
+ export class PythonAdapter {
5
+ options;
6
+ process = null;
7
+ requestId = 0;
8
+ pendingRequests = new Map();
9
+ constructor(options) {
10
+ this.options = options;
11
+ }
12
+ async start() {
13
+ return new Promise((resolve, reject) => {
14
+ console.log(`[RAL] Starting Python service: ${this.options.name}`);
15
+ // Automatically find python interpreter in virtual environment
16
+ const venvPath = path.join(this.options.cwd, 'venv', 'bin', 'python');
17
+ const pythonPath = fs.existsSync(venvPath) ? venvPath : 'python3';
18
+ // Start command, usually MCP Python services are started via main.py or -m module
19
+ // Here we assume entry is main.py (will be read from configuration later)
20
+ this.process = spawn(pythonPath, ['main.py'], {
21
+ cwd: this.options.cwd,
22
+ env: { ...process.env, ...this.options.env },
23
+ stdio: ['pipe', 'pipe', 'pipe'],
24
+ });
25
+ this.process.stdout?.on('data', (data) => {
26
+ const raw = data.toString().trim();
27
+ try {
28
+ const json = JSON.parse(raw);
29
+ if (json.id !== undefined && this.pendingRequests.has(json.id)) {
30
+ const resolver = this.pendingRequests.get(json.id);
31
+ resolver?.(json);
32
+ this.pendingRequests.delete(json.id);
33
+ }
34
+ }
35
+ catch (e) {
36
+ console.log(`[Python:${this.options.name}] ${raw}`);
37
+ }
38
+ });
39
+ this.process.stderr?.on('data', (data) => {
40
+ console.error(`[Python:${this.options.name}] ERR: ${data.toString()}`);
41
+ });
42
+ this.process.on('spawn', () => resolve());
43
+ this.process.on('error', (err) => reject(err));
44
+ });
45
+ }
46
+ async call(method, params = {}) {
47
+ if (!this.process) {
48
+ throw new Error(`Service ${this.options.name} is not running.`);
49
+ }
50
+ const id = ++this.requestId;
51
+ const request = {
52
+ jsonrpc: '2.0',
53
+ id,
54
+ method,
55
+ params,
56
+ };
57
+ return new Promise((resolve) => {
58
+ this.pendingRequests.set(id, resolve);
59
+ this.process?.stdin?.write(JSON.stringify(request) + '\n');
60
+ });
61
+ }
62
+ stop() {
63
+ if (this.process) {
64
+ this.process.kill();
65
+ this.process = null;
66
+ }
67
+ }
68
+ isRunning() {
69
+ return this.process !== null;
70
+ }
71
+ }
72
+ //# sourceMappingURL=python.js.map
@@ -0,0 +1,21 @@
1
+ import { RuntimeAdapter } from './adapter';
2
+ import { ServiceConfig } from '../core/types';
3
+ import { type ChildProcess } from 'child_process';
4
+ export declare class RustAdapter implements RuntimeAdapter {
5
+ private process;
6
+ getSpawnArgs(config: ServiceConfig): {
7
+ command: string;
8
+ args: string[];
9
+ };
10
+ setup(config: ServiceConfig): Promise<void>;
11
+ private findRustBinary;
12
+ private isExecutable;
13
+ startService(config: ServiceConfig): Promise<ChildProcess>;
14
+ stopService(): Promise<void>;
15
+ getServiceStatus(): Promise<string>;
16
+ compile(config: ServiceConfig): Promise<boolean>;
17
+ test(config: ServiceConfig): Promise<boolean>;
18
+ check(config: ServiceConfig): Promise<boolean>;
19
+ clippy(config: ServiceConfig): Promise<boolean>;
20
+ }
21
+ //# sourceMappingURL=rust-adapter.d.ts.map
@@ -0,0 +1,267 @@
1
+ import { spawn } from 'child_process';
2
+ import * as path from 'path';
3
+ import * as fs from 'fs';
4
+ export class RustAdapter {
5
+ process = null;
6
+ getSpawnArgs(config) {
7
+ const rustBinary = this.findRustBinary(config);
8
+ return {
9
+ command: rustBinary,
10
+ args: [...(config.args || [])],
11
+ };
12
+ }
13
+ async setup(config) {
14
+ console.log(`[Rust] Setting up service: ${config.name}`);
15
+ // Check if Rust is installed
16
+ try {
17
+ const { execSync } = require('child_process');
18
+ execSync('cargo --version', { stdio: 'ignore' });
19
+ console.log('[Rust] Cargo is installed');
20
+ }
21
+ catch (error) {
22
+ throw new Error('Rust/Cargo is not installed or not in PATH. Please install Rust from https://rustup.rs/');
23
+ }
24
+ const servicePath = config.path || '.';
25
+ // Check Cargo.toml file
26
+ const cargoTomlPath = path.join(servicePath, 'Cargo.toml');
27
+ if (!fs.existsSync(cargoTomlPath)) {
28
+ console.log('[Rust] Cargo.toml not found, checking if this is a binary crate');
29
+ // Check if this is a single Rust file
30
+ if (config.entry && config.entry.endsWith('.rs')) {
31
+ console.log(`[Rust] Single Rust file detected: ${config.entry}`);
32
+ // For a single Rust file, we can compile directly using rustc
33
+ }
34
+ else {
35
+ console.log(`[Rust] Creating basic Cargo.toml for ${config.name}`);
36
+ try {
37
+ const { execSync } = require('child_process');
38
+ execSync(`cargo init --name ${config.name} --bin`, {
39
+ stdio: 'inherit',
40
+ cwd: servicePath,
41
+ });
42
+ }
43
+ catch (error) {
44
+ console.warn(`[Rust] Failed to create Cargo.toml: ${error.message}`);
45
+ }
46
+ }
47
+ }
48
+ // Build project
49
+ console.log('[Rust] Building project...');
50
+ try {
51
+ const { execSync } = require('child_process');
52
+ const rustConfig = config.runtimeConfig?.rust;
53
+ if (rustConfig?.release) {
54
+ execSync('cargo build --release', {
55
+ stdio: 'inherit',
56
+ cwd: servicePath,
57
+ });
58
+ console.log('[Rust] Release build completed');
59
+ }
60
+ else {
61
+ execSync('cargo build', {
62
+ stdio: 'inherit',
63
+ cwd: servicePath,
64
+ });
65
+ console.log('[Rust] Debug build completed');
66
+ }
67
+ }
68
+ catch (error) {
69
+ console.warn(`[Rust] Build failed: ${error.message}`);
70
+ // Continue, might just be a warning
71
+ }
72
+ // Run tests (optional)
73
+ const rustConfig = config.runtimeConfig?.rust;
74
+ if (rustConfig?.test) {
75
+ console.log('[Rust] Running tests...');
76
+ try {
77
+ const { execSync } = require('child_process');
78
+ execSync('cargo test', {
79
+ stdio: 'inherit',
80
+ cwd: servicePath,
81
+ });
82
+ console.log('[Rust] Tests passed');
83
+ }
84
+ catch (error) {
85
+ console.warn(`[Rust] Tests failed: ${error.message}`);
86
+ }
87
+ }
88
+ console.log(`[Rust] Setup completed for service: ${config.name}`);
89
+ }
90
+ findRustBinary(config) {
91
+ const servicePath = config.path || '.';
92
+ const rustConfig = config.runtimeConfig?.rust;
93
+ // First check if there is a pre-built executable file
94
+ if (rustConfig?.binary) {
95
+ const binaryPath = path.join(servicePath, rustConfig.binary);
96
+ if (fs.existsSync(binaryPath)) {
97
+ return binaryPath;
98
+ }
99
+ }
100
+ // Check for executable files in the target directory
101
+ const buildType = rustConfig?.release ? 'release' : 'debug';
102
+ const possiblePaths = [
103
+ path.join(servicePath, 'target', buildType, config.name),
104
+ path.join(servicePath, 'target', buildType, 'main'),
105
+ path.join(servicePath, config.name),
106
+ `./${config.name}`,
107
+ ];
108
+ for (const binaryPath of possiblePaths) {
109
+ if (fs.existsSync(binaryPath) && this.isExecutable(binaryPath)) {
110
+ return binaryPath;
111
+ }
112
+ }
113
+ // If it's a single Rust file, compile and run using rustc
114
+ if (config.entry && config.entry.endsWith('.rs')) {
115
+ const outputName = rustConfig?.output || config.name;
116
+ const outputPath = path.join(servicePath, outputName);
117
+ console.log(`[Rust] Compiling single file: ${config.entry}`);
118
+ try {
119
+ const { execSync } = require('child_process');
120
+ execSync(`rustc ${config.entry} -o ${outputPath}`, {
121
+ stdio: 'inherit',
122
+ cwd: servicePath,
123
+ });
124
+ if (fs.existsSync(outputPath)) {
125
+ return outputPath;
126
+ }
127
+ }
128
+ catch (error) {
129
+ console.warn(`[Rust] Failed to compile single file: ${error.message}`);
130
+ }
131
+ }
132
+ // Finally try using cargo run
133
+ return 'cargo';
134
+ }
135
+ isExecutable(filePath) {
136
+ try {
137
+ fs.accessSync(filePath, fs.constants.X_OK);
138
+ return true;
139
+ }
140
+ catch {
141
+ return false;
142
+ }
143
+ }
144
+ async startService(config) {
145
+ const { command, args } = this.getSpawnArgs(config);
146
+ console.log(`[Rust] Starting service: ${config.name}`);
147
+ console.log(`[Rust] Command: ${command} ${args.join(' ')}`);
148
+ const finalArgs = command === 'cargo' ? ['run', '--', ...args] : args;
149
+ const finalCommand = command === 'cargo' ? 'cargo' : command;
150
+ const childProcess = spawn(finalCommand, finalArgs, {
151
+ stdio: ['pipe', 'pipe', 'pipe'],
152
+ detached: false,
153
+ env: {
154
+ ...process.env,
155
+ ...config.env,
156
+ RUST_BACKTRACE: config.runtimeConfig?.rust?.debug ? 'full' : '0',
157
+ },
158
+ cwd: config.path || '.',
159
+ });
160
+ childProcess.stdout?.on('data', (data) => {
161
+ console.log(`[Rust:${config.name}] ${data.toString().trim()}`);
162
+ });
163
+ childProcess.stderr?.on('data', (data) => {
164
+ console.error(`[Rust:${config.name}] ERR: ${data.toString().trim()}`);
165
+ });
166
+ childProcess.on('error', (error) => {
167
+ console.error(`[Rust:${config.name}] Failed to start: ${error.message}`);
168
+ });
169
+ childProcess.on('exit', (code, signal) => {
170
+ console.log(`[Rust:${config.name}] Process exited with code ${code}, signal ${signal}`);
171
+ this.process = null;
172
+ });
173
+ this.process = childProcess;
174
+ return childProcess;
175
+ }
176
+ async stopService() {
177
+ if (this.process) {
178
+ console.log('[Rust] Stopping service');
179
+ this.process.kill();
180
+ this.process = null;
181
+ }
182
+ }
183
+ async getServiceStatus() {
184
+ if (!this.process) {
185
+ return 'stopped';
186
+ }
187
+ // Check if the process is still running
188
+ if (this.process.exitCode !== null) {
189
+ return 'exited';
190
+ }
191
+ try {
192
+ // Send signal 0 to check if the process exists
193
+ this.process.kill(0);
194
+ return 'running';
195
+ }
196
+ catch (error) {
197
+ return 'stopped';
198
+ }
199
+ }
200
+ async compile(config) {
201
+ console.log(`[Rust] Compiling service: ${config.name}`);
202
+ try {
203
+ const { execSync } = require('child_process');
204
+ const rustConfig = config.runtimeConfig?.rust;
205
+ const buildArgs = rustConfig?.release ? ['build', '--release'] : ['build'];
206
+ execSync(`cargo ${buildArgs.join(' ')}`, {
207
+ stdio: 'inherit',
208
+ cwd: config.path || '.',
209
+ });
210
+ console.log('[Rust] Successfully compiled');
211
+ return true;
212
+ }
213
+ catch (error) {
214
+ console.error(`[Rust] Compilation failed: ${error.message}`);
215
+ return false;
216
+ }
217
+ }
218
+ async test(config) {
219
+ console.log(`[Rust] Running tests for service: ${config.name}`);
220
+ try {
221
+ const { execSync } = require('child_process');
222
+ execSync('cargo test', {
223
+ stdio: 'inherit',
224
+ cwd: config.path || '.',
225
+ });
226
+ console.log('[Rust] Tests passed');
227
+ return true;
228
+ }
229
+ catch (error) {
230
+ console.error(`[Rust] Tests failed: ${error.message}`);
231
+ return false;
232
+ }
233
+ }
234
+ async check(config) {
235
+ console.log(`[Rust] Running cargo check for service: ${config.name}`);
236
+ try {
237
+ const { execSync } = require('child_process');
238
+ execSync('cargo check', {
239
+ stdio: 'inherit',
240
+ cwd: config.path || '.',
241
+ });
242
+ console.log('[Rust] Check passed');
243
+ return true;
244
+ }
245
+ catch (error) {
246
+ console.error(`[Rust] Check failed: ${error.message}`);
247
+ return false;
248
+ }
249
+ }
250
+ async clippy(config) {
251
+ console.log(`[Rust] Running cargo clippy for service: ${config.name}`);
252
+ try {
253
+ const { execSync } = require('child_process');
254
+ execSync('cargo clippy', {
255
+ stdio: 'inherit',
256
+ cwd: config.path || '.',
257
+ });
258
+ console.log('[Rust] Clippy passed');
259
+ return true;
260
+ }
261
+ catch (error) {
262
+ console.error(`[Rust] Clippy failed: ${error.message}`);
263
+ return false;
264
+ }
265
+ }
266
+ }
267
+ //# sourceMappingURL=rust-adapter.js.map