@dexto/tools-process 1.5.8 → 1.6.1

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 (55) hide show
  1. package/dist/bash-exec-tool.cjs +40 -23
  2. package/dist/bash-exec-tool.d.ts +27 -9
  3. package/dist/bash-exec-tool.d.ts.map +1 -0
  4. package/dist/bash-exec-tool.js +43 -23
  5. package/dist/bash-output-tool.cjs +13 -5
  6. package/dist/bash-output-tool.d.ts +13 -8
  7. package/dist/bash-output-tool.d.ts.map +1 -0
  8. package/dist/bash-output-tool.js +13 -5
  9. package/dist/command-pattern-utils.cjs +83 -0
  10. package/dist/command-pattern-utils.d.ts +29 -0
  11. package/dist/command-pattern-utils.d.ts.map +1 -0
  12. package/dist/command-pattern-utils.js +56 -0
  13. package/dist/command-pattern-utils.test.cjs +80 -0
  14. package/dist/command-pattern-utils.test.d.ts +2 -0
  15. package/dist/command-pattern-utils.test.d.ts.map +1 -0
  16. package/dist/command-pattern-utils.test.js +83 -0
  17. package/dist/command-validator.d.ts +5 -8
  18. package/dist/command-validator.d.ts.map +1 -0
  19. package/dist/error-codes.d.ts +2 -3
  20. package/dist/error-codes.d.ts.map +1 -0
  21. package/dist/errors.d.ts +4 -7
  22. package/dist/errors.d.ts.map +1 -0
  23. package/dist/index.cjs +6 -3
  24. package/dist/index.d.cts +485 -11
  25. package/dist/index.d.ts +10 -4
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/index.js +4 -2
  28. package/dist/kill-process-tool.cjs +13 -5
  29. package/dist/kill-process-tool.d.ts +13 -8
  30. package/dist/kill-process-tool.d.ts.map +1 -0
  31. package/dist/kill-process-tool.js +13 -5
  32. package/dist/process-service.cjs +11 -1
  33. package/dist/process-service.d.ts +12 -11
  34. package/dist/process-service.d.ts.map +1 -0
  35. package/dist/process-service.js +11 -1
  36. package/dist/{tool-provider.cjs → tool-factory-config.cjs} +6 -48
  37. package/dist/{tool-provider.d.ts → tool-factory-config.d.ts} +8 -27
  38. package/dist/tool-factory-config.d.ts.map +1 -0
  39. package/dist/{tool-provider.js → tool-factory-config.js} +2 -44
  40. package/dist/tool-factory.cjs +89 -0
  41. package/dist/tool-factory.d.ts +4 -0
  42. package/dist/tool-factory.d.ts.map +1 -0
  43. package/dist/tool-factory.js +65 -0
  44. package/dist/types.d.ts +9 -10
  45. package/dist/types.d.ts.map +1 -0
  46. package/package.json +5 -4
  47. package/dist/bash-exec-tool.d.cts +0 -17
  48. package/dist/bash-output-tool.d.cts +0 -16
  49. package/dist/command-validator.d.cts +0 -52
  50. package/dist/error-codes.d.cts +0 -26
  51. package/dist/errors.d.cts +0 -90
  52. package/dist/kill-process-tool.d.cts +0 -16
  53. package/dist/process-service.d.cts +0 -96
  54. package/dist/tool-provider.d.cts +0 -72
  55. package/dist/types.d.cts +0 -108
@@ -1,26 +0,0 @@
1
- /**
2
- * Process Service Error Codes
3
- *
4
- * Standardized error codes for process execution and management
5
- */
6
- declare enum ProcessErrorCode {
7
- INVALID_COMMAND = "PROCESS_INVALID_COMMAND",
8
- COMMAND_BLOCKED = "PROCESS_COMMAND_BLOCKED",
9
- COMMAND_TOO_LONG = "PROCESS_COMMAND_TOO_LONG",
10
- INJECTION_DETECTED = "PROCESS_INJECTION_DETECTED",
11
- APPROVAL_REQUIRED = "PROCESS_APPROVAL_REQUIRED",
12
- APPROVAL_DENIED = "PROCESS_APPROVAL_DENIED",
13
- EXECUTION_FAILED = "PROCESS_EXECUTION_FAILED",
14
- TIMEOUT = "PROCESS_TIMEOUT",
15
- PERMISSION_DENIED = "PROCESS_PERMISSION_DENIED",
16
- COMMAND_NOT_FOUND = "PROCESS_COMMAND_NOT_FOUND",
17
- WORKING_DIRECTORY_INVALID = "PROCESS_WORKING_DIRECTORY_INVALID",
18
- PROCESS_NOT_FOUND = "PROCESS_NOT_FOUND",
19
- TOO_MANY_PROCESSES = "PROCESS_TOO_MANY_PROCESSES",
20
- KILL_FAILED = "PROCESS_KILL_FAILED",
21
- OUTPUT_BUFFER_FULL = "PROCESS_OUTPUT_BUFFER_FULL",
22
- INVALID_CONFIG = "PROCESS_INVALID_CONFIG",
23
- SERVICE_NOT_INITIALIZED = "PROCESS_SERVICE_NOT_INITIALIZED"
24
- }
25
-
26
- export { ProcessErrorCode };
package/dist/errors.d.cts DELETED
@@ -1,90 +0,0 @@
1
- import { DextoRuntimeError } from '@dexto/core';
2
-
3
- /**
4
- * Process Service Errors
5
- *
6
- * Error classes for process execution and management
7
- */
8
-
9
- interface ProcessErrorContext {
10
- command?: string;
11
- processId?: string;
12
- timeout?: number;
13
- [key: string]: unknown;
14
- }
15
- /**
16
- * Factory class for creating Process-related errors
17
- */
18
- declare class ProcessError {
19
- private constructor();
20
- /**
21
- * Invalid command error
22
- */
23
- static invalidCommand(command: string, reason: string): DextoRuntimeError;
24
- /**
25
- * Command blocked error
26
- */
27
- static commandBlocked(command: string, reason: string): DextoRuntimeError;
28
- /**
29
- * Command too long error
30
- */
31
- static commandTooLong(length: number, maxLength: number): DextoRuntimeError;
32
- /**
33
- * Command injection detected error
34
- */
35
- static commandInjection(command: string, pattern: string): DextoRuntimeError;
36
- /**
37
- * Command approval required error
38
- */
39
- static approvalRequired(command: string, reason?: string): DextoRuntimeError;
40
- /**
41
- * Command approval denied error
42
- */
43
- static approvalDenied(command: string): DextoRuntimeError;
44
- /**
45
- * Command execution failed error
46
- */
47
- static executionFailed(command: string, cause: string): DextoRuntimeError;
48
- /**
49
- * Command timeout error
50
- */
51
- static timeout(command: string, timeout: number): DextoRuntimeError;
52
- /**
53
- * Permission denied error
54
- */
55
- static permissionDenied(command: string): DextoRuntimeError;
56
- /**
57
- * Command not found error
58
- */
59
- static commandNotFound(command: string): DextoRuntimeError;
60
- /**
61
- * Invalid working directory error
62
- */
63
- static invalidWorkingDirectory(path: string, reason: string): DextoRuntimeError;
64
- /**
65
- * Process not found error
66
- */
67
- static processNotFound(processId: string): DextoRuntimeError;
68
- /**
69
- * Too many concurrent processes error
70
- */
71
- static tooManyProcesses(current: number, max: number): DextoRuntimeError;
72
- /**
73
- * Kill process failed error
74
- */
75
- static killFailed(processId: string, cause: string): DextoRuntimeError;
76
- /**
77
- * Output buffer full error
78
- */
79
- static outputBufferFull(processId: string, size: number, maxSize: number): DextoRuntimeError;
80
- /**
81
- * Invalid configuration error
82
- */
83
- static invalidConfig(reason: string): DextoRuntimeError;
84
- /**
85
- * Service not initialized error
86
- */
87
- static notInitialized(): DextoRuntimeError;
88
- }
89
-
90
- export { ProcessError, type ProcessErrorContext };
@@ -1,16 +0,0 @@
1
- import { InternalTool } from '@dexto/core';
2
- import { ProcessService } from './process-service.cjs';
3
- import './types.cjs';
4
-
5
- /**
6
- * Kill Process Tool
7
- *
8
- * Internal tool for terminating background processes
9
- */
10
-
11
- /**
12
- * Create the kill_process internal tool
13
- */
14
- declare function createKillProcessTool(processService: ProcessService): InternalTool;
15
-
16
- export { createKillProcessTool };
@@ -1,96 +0,0 @@
1
- import { ProcessConfig, ExecuteOptions, ProcessResult, ProcessHandle, ProcessOutput, ProcessInfo } from './types.cjs';
2
- import { IDextoLogger } from '@dexto/core';
3
-
4
- /**
5
- * Process Service
6
- *
7
- * Secure command execution and process management for Dexto internal tools
8
- */
9
-
10
- /**
11
- * ProcessService - Handles command execution and process management
12
- *
13
- * This service receives fully-validated configuration from the Process Tools Provider.
14
- * All defaults have been applied by the provider's schema, so the service trusts the config
15
- * and uses it as-is without any fallback logic.
16
- *
17
- * TODO: Add tests for this class
18
- */
19
- declare class ProcessService {
20
- private config;
21
- private commandValidator;
22
- private initialized;
23
- private initPromise;
24
- private backgroundProcesses;
25
- private logger;
26
- /**
27
- * Create a new ProcessService with validated configuration.
28
- *
29
- * @param config - Fully-validated configuration from provider schema.
30
- * All required fields have values, defaults already applied.
31
- * @param logger - Logger instance for this service
32
- */
33
- constructor(config: ProcessConfig, logger: IDextoLogger);
34
- /**
35
- * Initialize the service.
36
- * Safe to call multiple times - subsequent calls return the same promise.
37
- */
38
- initialize(): Promise<void>;
39
- /**
40
- * Internal initialization logic.
41
- */
42
- private doInitialize;
43
- /**
44
- * Ensure the service is initialized before use.
45
- * Tools should call this at the start of their execute methods.
46
- * Safe to call multiple times - will await the same initialization promise.
47
- */
48
- ensureInitialized(): Promise<void>;
49
- /**
50
- * Execute a command
51
- */
52
- executeCommand(command: string, options?: ExecuteOptions): Promise<ProcessResult | ProcessHandle>;
53
- private static readonly SIGKILL_TIMEOUT_MS;
54
- /**
55
- * Kill a process tree (process group on Unix, taskkill on Windows)
56
- */
57
- private killProcessTree;
58
- /**
59
- * Execute command in foreground with timeout and abort support
60
- */
61
- private executeForeground;
62
- /**
63
- * Execute command in background
64
- */
65
- private executeInBackground;
66
- /**
67
- * Get output from a background process
68
- */
69
- getProcessOutput(processId: string): Promise<ProcessOutput>;
70
- /**
71
- * Kill a background process
72
- */
73
- killProcess(processId: string): Promise<void>;
74
- /**
75
- * List all background processes
76
- */
77
- listProcesses(): Promise<ProcessInfo[]>;
78
- /**
79
- * Get buffer size in bytes
80
- */
81
- private getBufferSize;
82
- /**
83
- * Get service configuration
84
- */
85
- getConfig(): Readonly<ProcessConfig>;
86
- /**
87
- * Resolve and confine cwd to the configured working directory
88
- */
89
- private resolveSafeCwd;
90
- /**
91
- * Cleanup completed processes
92
- */
93
- cleanup(): Promise<void>;
94
- }
95
-
96
- export { ProcessService };
@@ -1,72 +0,0 @@
1
- import { z } from 'zod';
2
- import { CustomToolProvider } from '@dexto/core';
3
-
4
- /**
5
- * Process Tools Provider
6
- *
7
- * Provides process execution and management tools by wrapping ProcessService.
8
- * When registered, the provider initializes ProcessService and creates tools
9
- * for command execution and process management.
10
- */
11
-
12
- /**
13
- * Configuration schema for Process tools provider.
14
- *
15
- * This is the SINGLE SOURCE OF TRUTH for all configuration:
16
- * - Validation rules
17
- * - Default values (using constants above)
18
- * - Documentation
19
- * - Type definitions
20
- *
21
- * Services receive fully-validated config from this schema and use it as-is,
22
- * with no additional defaults or fallbacks needed.
23
- */
24
- declare const ProcessToolsConfigSchema: z.ZodObject<{
25
- type: z.ZodLiteral<"process-tools">;
26
- securityLevel: z.ZodDefault<z.ZodEnum<["strict", "moderate", "permissive"]>>;
27
- maxTimeout: z.ZodDefault<z.ZodNumber>;
28
- maxConcurrentProcesses: z.ZodDefault<z.ZodNumber>;
29
- maxOutputBuffer: z.ZodDefault<z.ZodNumber>;
30
- workingDirectory: z.ZodOptional<z.ZodString>;
31
- allowedCommands: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
32
- blockedCommands: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
33
- environment: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
34
- timeout: z.ZodOptional<z.ZodNumber>;
35
- }, "strict", z.ZodTypeAny, {
36
- type: "process-tools";
37
- securityLevel: "strict" | "moderate" | "permissive";
38
- maxTimeout: number;
39
- maxConcurrentProcesses: number;
40
- maxOutputBuffer: number;
41
- allowedCommands: string[];
42
- blockedCommands: string[];
43
- environment: Record<string, string>;
44
- timeout?: number | undefined;
45
- workingDirectory?: string | undefined;
46
- }, {
47
- type: "process-tools";
48
- timeout?: number | undefined;
49
- securityLevel?: "strict" | "moderate" | "permissive" | undefined;
50
- maxTimeout?: number | undefined;
51
- maxConcurrentProcesses?: number | undefined;
52
- maxOutputBuffer?: number | undefined;
53
- allowedCommands?: string[] | undefined;
54
- blockedCommands?: string[] | undefined;
55
- environment?: Record<string, string> | undefined;
56
- workingDirectory?: string | undefined;
57
- }>;
58
- type ProcessToolsConfig = z.output<typeof ProcessToolsConfigSchema>;
59
- /**
60
- * Process tools provider.
61
- *
62
- * Wraps ProcessService and provides process operation tools:
63
- * - bash_exec: Execute bash commands (foreground or background)
64
- * - bash_output: Retrieve output from background processes
65
- * - kill_process: Terminate background processes
66
- *
67
- * When registered via customToolRegistry, ProcessService is automatically
68
- * initialized and process operation tools become available to the agent.
69
- */
70
- declare const processToolsProvider: CustomToolProvider<'process-tools', ProcessToolsConfig>;
71
-
72
- export { processToolsProvider };
package/dist/types.d.cts DELETED
@@ -1,108 +0,0 @@
1
- /**
2
- * Process Service Types
3
- *
4
- * Types and interfaces for command execution and process management
5
- */
6
- /**
7
- * Process execution options
8
- */
9
- interface ExecuteOptions {
10
- /** Working directory */
11
- cwd?: string | undefined;
12
- /** Timeout in milliseconds (max: 600000) */
13
- timeout?: number | undefined;
14
- /** Run command in background */
15
- runInBackground?: boolean | undefined;
16
- /** Environment variables */
17
- env?: Record<string, string> | undefined;
18
- /** Description of what the command does (5-10 words) */
19
- description?: string | undefined;
20
- /** Abort signal for cancellation support */
21
- abortSignal?: AbortSignal | undefined;
22
- }
23
- /**
24
- * Process execution result (foreground execution only)
25
- * For background execution, see ProcessHandle
26
- */
27
- interface ProcessResult {
28
- stdout: string;
29
- stderr: string;
30
- exitCode: number;
31
- duration: number;
32
- }
33
- /**
34
- * Background process handle
35
- */
36
- interface ProcessHandle {
37
- processId: string;
38
- command: string;
39
- pid?: number | undefined;
40
- startedAt: Date;
41
- description?: string | undefined;
42
- }
43
- /**
44
- * Process output (for retrieving from background processes)
45
- */
46
- interface ProcessOutput {
47
- stdout: string;
48
- stderr: string;
49
- status: 'running' | 'completed' | 'failed';
50
- exitCode?: number | undefined;
51
- duration?: number | undefined;
52
- }
53
- /**
54
- * Process information
55
- */
56
- interface ProcessInfo {
57
- processId: string;
58
- command: string;
59
- pid?: number | undefined;
60
- status: 'running' | 'completed' | 'failed';
61
- startedAt: Date;
62
- completedAt?: Date | undefined;
63
- exitCode?: number | undefined;
64
- description?: string | undefined;
65
- }
66
- /**
67
- * Command validation result
68
- */
69
- interface CommandValidation {
70
- isValid: boolean;
71
- error?: string;
72
- normalizedCommand?: string;
73
- requiresApproval?: boolean;
74
- }
75
- /**
76
- * Process service configuration
77
- */
78
- interface ProcessConfig {
79
- /** Security level for command execution */
80
- securityLevel: 'strict' | 'moderate' | 'permissive';
81
- /** Maximum timeout for commands in milliseconds */
82
- maxTimeout: number;
83
- /** Maximum concurrent background processes */
84
- maxConcurrentProcesses: number;
85
- /** Maximum output buffer size in bytes */
86
- maxOutputBuffer: number;
87
- /** Explicitly allowed commands (empty = all allowed with approval) */
88
- allowedCommands: string[];
89
- /** Blocked command patterns */
90
- blockedCommands: string[];
91
- /** Custom environment variables */
92
- environment: Record<string, string>;
93
- /** Working directory (defaults to process.cwd()) */
94
- workingDirectory?: string | undefined;
95
- }
96
- /**
97
- * Output buffer management
98
- */
99
- interface OutputBuffer {
100
- stdout: string[];
101
- stderr: string[];
102
- complete: boolean;
103
- lastRead: number;
104
- bytesUsed: number;
105
- truncated?: boolean;
106
- }
107
-
108
- export type { CommandValidation, ExecuteOptions, OutputBuffer, ProcessConfig, ProcessHandle, ProcessInfo, ProcessOutput, ProcessResult };