@dexto/tools-process 1.6.0 → 1.6.2

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.
@@ -1,25 +0,0 @@
1
- import { z } from 'zod';
2
- import { Tool } from '@dexto/core';
3
- import { ProcessServiceGetter } from './bash-exec-tool.cjs';
4
- import './process-service.cjs';
5
- import './types.cjs';
6
-
7
- /**
8
- * Bash Output Tool
9
- *
10
- * Internal tool for retrieving output from background processes
11
- */
12
-
13
- declare const BashOutputInputSchema: z.ZodObject<{
14
- process_id: z.ZodString;
15
- }, "strict", z.ZodTypeAny, {
16
- process_id: string;
17
- }, {
18
- process_id: string;
19
- }>;
20
- /**
21
- * Create the bash_output internal tool
22
- */
23
- declare function createBashOutputTool(getProcessService: ProcessServiceGetter): Tool<typeof BashOutputInputSchema>;
24
-
25
- export { createBashOutputTool };
@@ -1,30 +0,0 @@
1
- /**
2
- * Utility functions for generating approval patterns for shell commands.
3
- *
4
- * Pattern-based approvals allow users to approve command patterns like "git *"
5
- * that automatically cover future matching commands (e.g., "git status", "git push").
6
- */
7
- /**
8
- * Commands that should never get auto-approve pattern suggestions.
9
- * These require explicit approval each time for safety.
10
- */
11
- declare const DANGEROUS_COMMAND_PREFIXES: readonly ["rm", "chmod", "chown", "chgrp", "sudo", "su", "dd", "mkfs", "fdisk", "parted", "kill", "killall", "pkill", "shutdown", "reboot", "halt", "poweroff"];
12
- declare function isDangerousCommand(command: string): boolean;
13
- /**
14
- * Generate the pattern key for a shell command.
15
- *
16
- * Examples:
17
- * - "ls -la" → "ls *" (flags don't count as subcommand)
18
- * - "git push origin" → "git push *" (first non-flag arg is subcommand)
19
- * - "rm -rf /" → null (dangerous command)
20
- */
21
- declare function generateCommandPatternKey(command: string): string | null;
22
- /**
23
- * Generate suggested patterns for UI selection.
24
- * Returns progressively broader patterns from specific to general.
25
- *
26
- * Example: "git push origin main" → ["git push *", "git *"]
27
- */
28
- declare function generateCommandPatternSuggestions(command: string): string[];
29
-
30
- export { DANGEROUS_COMMAND_PREFIXES, generateCommandPatternKey, generateCommandPatternSuggestions, isDangerousCommand };
@@ -1,2 +0,0 @@
1
-
2
- export { }
@@ -1,52 +0,0 @@
1
- import { ProcessConfig, CommandValidation } from './types.cjs';
2
- import { Logger } from '@dexto/core';
3
-
4
- /**
5
- * Command Validator
6
- *
7
- * Security-focused command validation for process execution
8
- */
9
-
10
- /**
11
- * CommandValidator - Validates commands for security and policy compliance
12
- *
13
- * Security checks:
14
- * 1. Command length limits
15
- * 2. Dangerous command patterns
16
- * 3. Command injection detection
17
- * 4. Allowed/blocked command lists
18
- * 5. Shell metacharacter analysis
19
- * TODO: Add tests for this class
20
- */
21
- declare class CommandValidator {
22
- private config;
23
- private logger;
24
- constructor(config: ProcessConfig, logger: Logger);
25
- /**
26
- * Validate a command for security and policy compliance
27
- */
28
- validateCommand(command: string): CommandValidation;
29
- /**
30
- * Detect command injection attempts
31
- */
32
- private detectInjection;
33
- /**
34
- * Determine if a command requires approval
35
- * Handles compound commands (with &&, ||, ;) by checking each sub-command
36
- */
37
- private determineApprovalRequirement;
38
- /**
39
- * Get list of blocked commands
40
- */
41
- getBlockedCommands(): string[];
42
- /**
43
- * Get list of allowed commands
44
- */
45
- getAllowedCommands(): string[];
46
- /**
47
- * Get security level
48
- */
49
- getSecurityLevel(): string;
50
- }
51
-
52
- export { CommandValidator };
@@ -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,25 +0,0 @@
1
- import { z } from 'zod';
2
- import { Tool } from '@dexto/core';
3
- import { ProcessServiceGetter } from './bash-exec-tool.cjs';
4
- import './process-service.cjs';
5
- import './types.cjs';
6
-
7
- /**
8
- * Kill Process Tool
9
- *
10
- * Internal tool for terminating background processes
11
- */
12
-
13
- declare const KillProcessInputSchema: z.ZodObject<{
14
- process_id: z.ZodString;
15
- }, "strict", z.ZodTypeAny, {
16
- process_id: string;
17
- }, {
18
- process_id: string;
19
- }>;
20
- /**
21
- * Create the kill_process internal tool
22
- */
23
- declare function createKillProcessTool(getProcessService: ProcessServiceGetter): Tool<typeof KillProcessInputSchema>;
24
-
25
- export { createKillProcessTool };
@@ -1,100 +0,0 @@
1
- import { ProcessConfig, ExecuteOptions, ProcessResult, ProcessHandle, ProcessOutput, ProcessInfo } from './types.cjs';
2
- import { Logger } 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 Factory.
14
- * All defaults have been applied by the factory'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 the factory schema.
30
- * All required fields have values, defaults already applied.
31
- * @param logger - Logger instance for this service
32
- */
33
- constructor(config: ProcessConfig, logger: Logger);
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
- * Update the working directory at runtime (e.g., when workspace changes).
88
- */
89
- setWorkingDirectory(workingDirectory: string): void;
90
- /**
91
- * Resolve and confine cwd to the configured working directory
92
- */
93
- private resolveSafeCwd;
94
- /**
95
- * Cleanup completed processes
96
- */
97
- cleanup(): Promise<void>;
98
- }
99
-
100
- export { ProcessService };
@@ -1,56 +0,0 @@
1
- import { z } from 'zod';
2
-
3
- /**
4
- * Process Tools Factory
5
- *
6
- * Provides process execution and management tools by wrapping ProcessService.
7
- * When registered, the factory initializes ProcessService and creates tools
8
- * for command execution and process management.
9
- */
10
-
11
- /**
12
- * Configuration schema for Process tools factory.
13
- *
14
- * This is the SINGLE SOURCE OF TRUTH for all configuration:
15
- * - Validation rules
16
- * - Default values (using constants above)
17
- * - Documentation
18
- * - Type definitions
19
- *
20
- * Services receive fully-validated config from this schema and use it as-is,
21
- * with no additional defaults or fallbacks needed.
22
- */
23
- declare const ProcessToolsConfigSchema: z.ZodObject<{
24
- type: z.ZodLiteral<"process-tools">;
25
- securityLevel: z.ZodDefault<z.ZodEnum<["strict", "moderate", "permissive"]>>;
26
- maxTimeout: z.ZodDefault<z.ZodNumber>;
27
- maxConcurrentProcesses: z.ZodDefault<z.ZodNumber>;
28
- maxOutputBuffer: z.ZodDefault<z.ZodNumber>;
29
- workingDirectory: z.ZodOptional<z.ZodString>;
30
- allowedCommands: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
31
- blockedCommands: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
32
- environment: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
33
- }, "strict", z.ZodTypeAny, {
34
- type: "process-tools";
35
- securityLevel: "strict" | "moderate" | "permissive";
36
- maxTimeout: number;
37
- maxConcurrentProcesses: number;
38
- maxOutputBuffer: number;
39
- allowedCommands: string[];
40
- blockedCommands: string[];
41
- environment: Record<string, string>;
42
- workingDirectory?: string | undefined;
43
- }, {
44
- type: "process-tools";
45
- securityLevel?: "strict" | "moderate" | "permissive" | undefined;
46
- maxTimeout?: number | undefined;
47
- maxConcurrentProcesses?: number | undefined;
48
- maxOutputBuffer?: number | undefined;
49
- allowedCommands?: string[] | undefined;
50
- blockedCommands?: string[] | undefined;
51
- environment?: Record<string, string> | undefined;
52
- workingDirectory?: string | undefined;
53
- }>;
54
- type ProcessToolsConfig = z.output<typeof ProcessToolsConfigSchema>;
55
-
56
- export { type ProcessToolsConfig, ProcessToolsConfigSchema };
@@ -1,7 +0,0 @@
1
- import { ToolFactory } from '@dexto/agent-config';
2
- import { ProcessToolsConfig } from './tool-factory-config.cjs';
3
- import 'zod';
4
-
5
- declare const processToolsFactory: ToolFactory<ProcessToolsConfig>;
6
-
7
- export { processToolsFactory };
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 };