@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.
package/dist/index.d.cts CHANGED
@@ -1,13 +1,485 @@
1
- export { processToolsFactory } from './tool-factory.cjs';
2
- export { ProcessService } from './process-service.cjs';
3
- export { CommandValidator } from './command-validator.cjs';
4
- export { ProcessError } from './errors.cjs';
5
- export { ProcessErrorCode } from './error-codes.cjs';
6
- export { CommandValidation, ExecuteOptions, OutputBuffer, ProcessConfig, ProcessHandle, ProcessInfo, ProcessOutput, ProcessResult } from './types.cjs';
7
- export { createBashExecTool } from './bash-exec-tool.cjs';
8
- export { createBashOutputTool } from './bash-output-tool.cjs';
9
- export { createKillProcessTool } from './kill-process-tool.cjs';
10
- import '@dexto/agent-config';
11
- import './tool-factory-config.cjs';
12
- import 'zod';
13
- import '@dexto/core';
1
+ import { ToolFactory } from '@dexto/agent-config';
2
+ import { z } from 'zod';
3
+ import { Logger, DextoRuntimeError, ToolExecutionContext, Tool } from '@dexto/core';
4
+
5
+ /**
6
+ * Process Tools Factory
7
+ *
8
+ * Provides process execution and management tools by wrapping ProcessService.
9
+ * When registered, the factory initializes ProcessService and creates tools
10
+ * for command execution and process management.
11
+ */
12
+
13
+ /**
14
+ * Configuration schema for Process tools factory.
15
+ *
16
+ * This is the SINGLE SOURCE OF TRUTH for all configuration:
17
+ * - Validation rules
18
+ * - Default values (using constants above)
19
+ * - Documentation
20
+ * - Type definitions
21
+ *
22
+ * Services receive fully-validated config from this schema and use it as-is,
23
+ * with no additional defaults or fallbacks needed.
24
+ */
25
+ declare const ProcessToolsConfigSchema: z.ZodObject<{
26
+ type: z.ZodLiteral<"process-tools">;
27
+ securityLevel: z.ZodDefault<z.ZodEnum<["strict", "moderate", "permissive"]>>;
28
+ maxTimeout: z.ZodDefault<z.ZodNumber>;
29
+ maxConcurrentProcesses: z.ZodDefault<z.ZodNumber>;
30
+ maxOutputBuffer: z.ZodDefault<z.ZodNumber>;
31
+ workingDirectory: z.ZodOptional<z.ZodString>;
32
+ allowedCommands: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
33
+ blockedCommands: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
34
+ environment: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
35
+ }, "strict", z.ZodTypeAny, {
36
+ securityLevel: "strict" | "moderate" | "permissive";
37
+ maxTimeout: number;
38
+ maxConcurrentProcesses: number;
39
+ maxOutputBuffer: number;
40
+ allowedCommands: string[];
41
+ blockedCommands: string[];
42
+ environment: Record<string, string>;
43
+ type: "process-tools";
44
+ workingDirectory?: string | undefined;
45
+ }, {
46
+ type: "process-tools";
47
+ securityLevel?: "strict" | "moderate" | "permissive" | undefined;
48
+ maxTimeout?: number | undefined;
49
+ maxConcurrentProcesses?: number | undefined;
50
+ maxOutputBuffer?: number | undefined;
51
+ allowedCommands?: string[] | undefined;
52
+ blockedCommands?: string[] | undefined;
53
+ environment?: Record<string, string> | undefined;
54
+ workingDirectory?: string | undefined;
55
+ }>;
56
+ type ProcessToolsConfig = z.output<typeof ProcessToolsConfigSchema>;
57
+
58
+ declare const processToolsFactory: ToolFactory<ProcessToolsConfig>;
59
+
60
+ /**
61
+ * Process Service Types
62
+ *
63
+ * Types and interfaces for command execution and process management
64
+ */
65
+ /**
66
+ * Process execution options
67
+ */
68
+ interface ExecuteOptions {
69
+ /** Working directory */
70
+ cwd?: string | undefined;
71
+ /** Timeout in milliseconds (max: 600000) */
72
+ timeout?: number | undefined;
73
+ /** Run command in background */
74
+ runInBackground?: boolean | undefined;
75
+ /** Environment variables */
76
+ env?: Record<string, string> | undefined;
77
+ /** Description of what the command does (5-10 words) */
78
+ description?: string | undefined;
79
+ /** Abort signal for cancellation support */
80
+ abortSignal?: AbortSignal | undefined;
81
+ }
82
+ /**
83
+ * Process execution result (foreground execution only)
84
+ * For background execution, see ProcessHandle
85
+ */
86
+ interface ProcessResult {
87
+ stdout: string;
88
+ stderr: string;
89
+ exitCode: number;
90
+ duration: number;
91
+ }
92
+ /**
93
+ * Background process handle
94
+ */
95
+ interface ProcessHandle {
96
+ processId: string;
97
+ command: string;
98
+ pid?: number | undefined;
99
+ startedAt: Date;
100
+ description?: string | undefined;
101
+ }
102
+ /**
103
+ * Process output (for retrieving from background processes)
104
+ */
105
+ interface ProcessOutput {
106
+ stdout: string;
107
+ stderr: string;
108
+ status: 'running' | 'completed' | 'failed';
109
+ exitCode?: number | undefined;
110
+ duration?: number | undefined;
111
+ }
112
+ /**
113
+ * Process information
114
+ */
115
+ interface ProcessInfo {
116
+ processId: string;
117
+ command: string;
118
+ pid?: number | undefined;
119
+ status: 'running' | 'completed' | 'failed';
120
+ startedAt: Date;
121
+ completedAt?: Date | undefined;
122
+ exitCode?: number | undefined;
123
+ description?: string | undefined;
124
+ }
125
+ /**
126
+ * Command validation result
127
+ */
128
+ interface CommandValidation {
129
+ isValid: boolean;
130
+ error?: string;
131
+ normalizedCommand?: string;
132
+ requiresApproval?: boolean;
133
+ }
134
+ /**
135
+ * Process service configuration
136
+ */
137
+ interface ProcessConfig {
138
+ /** Security level for command execution */
139
+ securityLevel: 'strict' | 'moderate' | 'permissive';
140
+ /** Maximum timeout for commands in milliseconds */
141
+ maxTimeout: number;
142
+ /** Maximum concurrent background processes */
143
+ maxConcurrentProcesses: number;
144
+ /** Maximum output buffer size in bytes */
145
+ maxOutputBuffer: number;
146
+ /** Explicitly allowed commands (empty = all allowed with approval) */
147
+ allowedCommands: string[];
148
+ /** Blocked command patterns */
149
+ blockedCommands: string[];
150
+ /** Custom environment variables */
151
+ environment: Record<string, string>;
152
+ /** Working directory (defaults to process.cwd()) */
153
+ workingDirectory?: string | undefined;
154
+ }
155
+ /**
156
+ * Output buffer management
157
+ */
158
+ interface OutputBuffer {
159
+ stdout: string[];
160
+ stderr: string[];
161
+ complete: boolean;
162
+ lastRead: number;
163
+ bytesUsed: number;
164
+ truncated?: boolean;
165
+ }
166
+
167
+ /**
168
+ * Process Service
169
+ *
170
+ * Secure command execution and process management for Dexto internal tools
171
+ */
172
+
173
+ /**
174
+ * ProcessService - Handles command execution and process management
175
+ *
176
+ * This service receives fully-validated configuration from the Process Tools Factory.
177
+ * All defaults have been applied by the factory's schema, so the service trusts the config
178
+ * and uses it as-is without any fallback logic.
179
+ *
180
+ * TODO: Add tests for this class
181
+ */
182
+ declare class ProcessService {
183
+ private config;
184
+ private commandValidator;
185
+ private initialized;
186
+ private initPromise;
187
+ private backgroundProcesses;
188
+ private logger;
189
+ /**
190
+ * Create a new ProcessService with validated configuration.
191
+ *
192
+ * @param config - Fully-validated configuration from the factory schema.
193
+ * All required fields have values, defaults already applied.
194
+ * @param logger - Logger instance for this service
195
+ */
196
+ constructor(config: ProcessConfig, logger: Logger);
197
+ /**
198
+ * Initialize the service.
199
+ * Safe to call multiple times - subsequent calls return the same promise.
200
+ */
201
+ initialize(): Promise<void>;
202
+ /**
203
+ * Internal initialization logic.
204
+ */
205
+ private doInitialize;
206
+ /**
207
+ * Ensure the service is initialized before use.
208
+ * Tools should call this at the start of their execute methods.
209
+ * Safe to call multiple times - will await the same initialization promise.
210
+ */
211
+ ensureInitialized(): Promise<void>;
212
+ /**
213
+ * Execute a command
214
+ */
215
+ executeCommand(command: string, options?: ExecuteOptions): Promise<ProcessResult | ProcessHandle>;
216
+ private static readonly SIGKILL_TIMEOUT_MS;
217
+ /**
218
+ * Kill a process tree (process group on Unix, taskkill on Windows)
219
+ */
220
+ private killProcessTree;
221
+ /**
222
+ * Execute command in foreground with timeout and abort support
223
+ */
224
+ private executeForeground;
225
+ /**
226
+ * Execute command in background
227
+ */
228
+ private executeInBackground;
229
+ /**
230
+ * Get output from a background process
231
+ */
232
+ getProcessOutput(processId: string): Promise<ProcessOutput>;
233
+ /**
234
+ * Kill a background process
235
+ */
236
+ killProcess(processId: string): Promise<void>;
237
+ /**
238
+ * List all background processes
239
+ */
240
+ listProcesses(): Promise<ProcessInfo[]>;
241
+ /**
242
+ * Get buffer size in bytes
243
+ */
244
+ private getBufferSize;
245
+ /**
246
+ * Get service configuration
247
+ */
248
+ getConfig(): Readonly<ProcessConfig>;
249
+ /**
250
+ * Update the working directory at runtime (e.g., when workspace changes).
251
+ */
252
+ setWorkingDirectory(workingDirectory: string): void;
253
+ /**
254
+ * Resolve and confine cwd to the configured working directory
255
+ */
256
+ private resolveSafeCwd;
257
+ /**
258
+ * Cleanup completed processes
259
+ */
260
+ cleanup(): Promise<void>;
261
+ }
262
+
263
+ /**
264
+ * Command Validator
265
+ *
266
+ * Security-focused command validation for process execution
267
+ */
268
+
269
+ /**
270
+ * CommandValidator - Validates commands for security and policy compliance
271
+ *
272
+ * Security checks:
273
+ * 1. Command length limits
274
+ * 2. Dangerous command patterns
275
+ * 3. Command injection detection
276
+ * 4. Allowed/blocked command lists
277
+ * 5. Shell metacharacter analysis
278
+ * TODO: Add tests for this class
279
+ */
280
+ declare class CommandValidator {
281
+ private config;
282
+ private logger;
283
+ constructor(config: ProcessConfig, logger: Logger);
284
+ /**
285
+ * Validate a command for security and policy compliance
286
+ */
287
+ validateCommand(command: string): CommandValidation;
288
+ /**
289
+ * Detect command injection attempts
290
+ */
291
+ private detectInjection;
292
+ /**
293
+ * Determine if a command requires approval
294
+ * Handles compound commands (with &&, ||, ;) by checking each sub-command
295
+ */
296
+ private determineApprovalRequirement;
297
+ /**
298
+ * Get list of blocked commands
299
+ */
300
+ getBlockedCommands(): string[];
301
+ /**
302
+ * Get list of allowed commands
303
+ */
304
+ getAllowedCommands(): string[];
305
+ /**
306
+ * Get security level
307
+ */
308
+ getSecurityLevel(): string;
309
+ }
310
+
311
+ /**
312
+ * Process Service Errors
313
+ *
314
+ * Error classes for process execution and management
315
+ */
316
+
317
+ /**
318
+ * Factory class for creating Process-related errors
319
+ */
320
+ declare class ProcessError {
321
+ private constructor();
322
+ /**
323
+ * Invalid command error
324
+ */
325
+ static invalidCommand(command: string, reason: string): DextoRuntimeError;
326
+ /**
327
+ * Command blocked error
328
+ */
329
+ static commandBlocked(command: string, reason: string): DextoRuntimeError;
330
+ /**
331
+ * Command too long error
332
+ */
333
+ static commandTooLong(length: number, maxLength: number): DextoRuntimeError;
334
+ /**
335
+ * Command injection detected error
336
+ */
337
+ static commandInjection(command: string, pattern: string): DextoRuntimeError;
338
+ /**
339
+ * Command approval required error
340
+ */
341
+ static approvalRequired(command: string, reason?: string): DextoRuntimeError;
342
+ /**
343
+ * Command approval denied error
344
+ */
345
+ static approvalDenied(command: string): DextoRuntimeError;
346
+ /**
347
+ * Command execution failed error
348
+ */
349
+ static executionFailed(command: string, cause: string): DextoRuntimeError;
350
+ /**
351
+ * Command timeout error
352
+ */
353
+ static timeout(command: string, timeout: number): DextoRuntimeError;
354
+ /**
355
+ * Permission denied error
356
+ */
357
+ static permissionDenied(command: string): DextoRuntimeError;
358
+ /**
359
+ * Command not found error
360
+ */
361
+ static commandNotFound(command: string): DextoRuntimeError;
362
+ /**
363
+ * Invalid working directory error
364
+ */
365
+ static invalidWorkingDirectory(path: string, reason: string): DextoRuntimeError;
366
+ /**
367
+ * Process not found error
368
+ */
369
+ static processNotFound(processId: string): DextoRuntimeError;
370
+ /**
371
+ * Too many concurrent processes error
372
+ */
373
+ static tooManyProcesses(current: number, max: number): DextoRuntimeError;
374
+ /**
375
+ * Kill process failed error
376
+ */
377
+ static killFailed(processId: string, cause: string): DextoRuntimeError;
378
+ /**
379
+ * Output buffer full error
380
+ */
381
+ static outputBufferFull(processId: string, size: number, maxSize: number): DextoRuntimeError;
382
+ /**
383
+ * Invalid configuration error
384
+ */
385
+ static invalidConfig(reason: string): DextoRuntimeError;
386
+ /**
387
+ * Service not initialized error
388
+ */
389
+ static notInitialized(): DextoRuntimeError;
390
+ }
391
+
392
+ /**
393
+ * Process Service Error Codes
394
+ *
395
+ * Standardized error codes for process execution and management
396
+ */
397
+ declare enum ProcessErrorCode {
398
+ INVALID_COMMAND = "PROCESS_INVALID_COMMAND",
399
+ COMMAND_BLOCKED = "PROCESS_COMMAND_BLOCKED",
400
+ COMMAND_TOO_LONG = "PROCESS_COMMAND_TOO_LONG",
401
+ INJECTION_DETECTED = "PROCESS_INJECTION_DETECTED",
402
+ APPROVAL_REQUIRED = "PROCESS_APPROVAL_REQUIRED",
403
+ APPROVAL_DENIED = "PROCESS_APPROVAL_DENIED",
404
+ EXECUTION_FAILED = "PROCESS_EXECUTION_FAILED",
405
+ TIMEOUT = "PROCESS_TIMEOUT",
406
+ PERMISSION_DENIED = "PROCESS_PERMISSION_DENIED",
407
+ COMMAND_NOT_FOUND = "PROCESS_COMMAND_NOT_FOUND",
408
+ WORKING_DIRECTORY_INVALID = "PROCESS_WORKING_DIRECTORY_INVALID",
409
+ PROCESS_NOT_FOUND = "PROCESS_NOT_FOUND",
410
+ TOO_MANY_PROCESSES = "PROCESS_TOO_MANY_PROCESSES",
411
+ KILL_FAILED = "PROCESS_KILL_FAILED",
412
+ OUTPUT_BUFFER_FULL = "PROCESS_OUTPUT_BUFFER_FULL",
413
+ INVALID_CONFIG = "PROCESS_INVALID_CONFIG",
414
+ SERVICE_NOT_INITIALIZED = "PROCESS_SERVICE_NOT_INITIALIZED"
415
+ }
416
+
417
+ /**
418
+ * Bash Execute Tool
419
+ *
420
+ * Internal tool for executing shell commands.
421
+ * Pattern-based approval support is declared on the tool (ToolManager stays generic).
422
+ */
423
+
424
+ declare const BashExecInputSchema: z.ZodObject<{
425
+ command: z.ZodString;
426
+ description: z.ZodOptional<z.ZodString>;
427
+ timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
428
+ run_in_background: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
429
+ cwd: z.ZodOptional<z.ZodString>;
430
+ }, "strict", z.ZodTypeAny, {
431
+ command: string;
432
+ timeout: number;
433
+ run_in_background: boolean;
434
+ cwd?: string | undefined;
435
+ description?: string | undefined;
436
+ }, {
437
+ command: string;
438
+ timeout?: number | undefined;
439
+ cwd?: string | undefined;
440
+ description?: string | undefined;
441
+ run_in_background?: boolean | undefined;
442
+ }>;
443
+ /**
444
+ * Create the bash_exec internal tool
445
+ */
446
+ type ProcessServiceGetter = (context: ToolExecutionContext) => Promise<ProcessService>;
447
+ declare function createBashExecTool(getProcessService: ProcessServiceGetter): Tool<typeof BashExecInputSchema>;
448
+
449
+ /**
450
+ * Bash Output Tool
451
+ *
452
+ * Internal tool for retrieving output from background processes
453
+ */
454
+
455
+ declare const BashOutputInputSchema: z.ZodObject<{
456
+ process_id: z.ZodString;
457
+ }, "strict", z.ZodTypeAny, {
458
+ process_id: string;
459
+ }, {
460
+ process_id: string;
461
+ }>;
462
+ /**
463
+ * Create the bash_output internal tool
464
+ */
465
+ declare function createBashOutputTool(getProcessService: ProcessServiceGetter): Tool<typeof BashOutputInputSchema>;
466
+
467
+ /**
468
+ * Kill Process Tool
469
+ *
470
+ * Internal tool for terminating background processes
471
+ */
472
+
473
+ declare const KillProcessInputSchema: z.ZodObject<{
474
+ process_id: z.ZodString;
475
+ }, "strict", z.ZodTypeAny, {
476
+ process_id: string;
477
+ }, {
478
+ process_id: string;
479
+ }>;
480
+ /**
481
+ * Create the kill_process internal tool
482
+ */
483
+ declare function createKillProcessTool(getProcessService: ProcessServiceGetter): Tool<typeof KillProcessInputSchema>;
484
+
485
+ export { type CommandValidation, CommandValidator, type ExecuteOptions, type OutputBuffer, type ProcessConfig, ProcessError, ProcessErrorCode, type ProcessHandle, type ProcessInfo, type ProcessOutput, type ProcessResult, ProcessService, type ProcessToolsConfig, ProcessToolsConfigSchema, createBashExecTool, createBashOutputTool, createKillProcessTool, processToolsFactory };
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  * Provides process operation tools: bash exec, output, kill.
6
6
  */
7
7
  export { processToolsFactory } from './tool-factory.js';
8
+ export { ProcessToolsConfigSchema, type ProcessToolsConfig } from './tool-factory-config.js';
8
9
  export { ProcessService } from './process-service.js';
9
10
  export { CommandValidator } from './command-validator.js';
10
11
  export { ProcessError } from './errors.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAGxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGpD,YAAY,EACR,aAAa,EACb,cAAc,EACd,aAAa,EACb,aAAa,EACb,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,YAAY,GACf,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,KAAK,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAG7F,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGpD,YAAY,EACR,aAAa,EACb,cAAc,EACd,aAAa,EACb,aAAa,EACb,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,YAAY,GACf,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { processToolsFactory } from "./tool-factory.js";
2
+ import { ProcessToolsConfigSchema } from "./tool-factory-config.js";
2
3
  import { ProcessService } from "./process-service.js";
3
4
  import { CommandValidator } from "./command-validator.js";
4
5
  import { ProcessError } from "./errors.js";
@@ -11,6 +12,7 @@ export {
11
12
  ProcessError,
12
13
  ProcessErrorCode,
13
14
  ProcessService,
15
+ ProcessToolsConfigSchema,
14
16
  createBashExecTool,
15
17
  createBashOutputTool,
16
18
  createKillProcessTool,
@@ -29,9 +29,14 @@ const KillProcessInputSchema = import_zod.z.object({
29
29
  function createKillProcessTool(getProcessService) {
30
30
  return (0, import_core.defineTool)({
31
31
  id: "kill_process",
32
- displayName: "Kill",
33
32
  description: "Terminate a background process started with bash_exec. Sends SIGTERM signal first, then SIGKILL if process doesn't terminate within 5 seconds. Only works on processes started by this agent. Returns success status and whether the process was running. Does not require additional approval (process was already approved when started).",
34
33
  inputSchema: KillProcessInputSchema,
34
+ presentation: {
35
+ describeHeader: (input) => (0, import_core.createLocalToolCallHeader)({
36
+ title: "Kill",
37
+ argsText: (0, import_core.truncateForHeader)(input.process_id, 80)
38
+ })
39
+ },
35
40
  async execute(input, context) {
36
41
  const resolvedProcessService = await getProcessService(context);
37
42
  const { process_id } = input;
@@ -1 +1 @@
1
- {"version":3,"file":"kill-process-tool.d.ts","sourceRoot":"","sources":["../src/kill-process-tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,IAAI,EAAwB,MAAM,aAAa,CAAC;AAC9D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAEhE,QAAA,MAAM,sBAAsB;;;;;;EAIf,CAAC;AAEd;;GAEG;AACH,wBAAgB,qBAAqB,CACjC,iBAAiB,EAAE,oBAAoB,GACxC,IAAI,CAAC,OAAO,sBAAsB,CAAC,CAwBrC"}
1
+ {"version":3,"file":"kill-process-tool.d.ts","sourceRoot":"","sources":["../src/kill-process-tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,IAAI,EAAwB,MAAM,aAAa,CAAC;AAC9D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAEhE,QAAA,MAAM,sBAAsB;;;;;;EAIf,CAAC;AAEd;;GAEG;AACH,wBAAgB,qBAAqB,CACjC,iBAAiB,EAAE,oBAAoB,GACxC,IAAI,CAAC,OAAO,sBAAsB,CAAC,CA8BrC"}
@@ -1,14 +1,19 @@
1
1
  import { z } from "zod";
2
- import { defineTool } from "@dexto/core";
2
+ import { createLocalToolCallHeader, defineTool, truncateForHeader } from "@dexto/core";
3
3
  const KillProcessInputSchema = z.object({
4
4
  process_id: z.string().describe("Process ID of the background process to terminate")
5
5
  }).strict();
6
6
  function createKillProcessTool(getProcessService) {
7
7
  return defineTool({
8
8
  id: "kill_process",
9
- displayName: "Kill",
10
9
  description: "Terminate a background process started with bash_exec. Sends SIGTERM signal first, then SIGKILL if process doesn't terminate within 5 seconds. Only works on processes started by this agent. Returns success status and whether the process was running. Does not require additional approval (process was already approved when started).",
11
10
  inputSchema: KillProcessInputSchema,
11
+ presentation: {
12
+ describeHeader: (input) => createLocalToolCallHeader({
13
+ title: "Kill",
14
+ argsText: truncateForHeader(input.process_id, 80)
15
+ })
16
+ },
12
17
  async execute(input, context) {
13
18
  const resolvedProcessService = await getProcessService(context);
14
19
  const { process_id } = input;
@@ -50,7 +50,19 @@ const processToolsFactory = {
50
50
  const workingDirectory = resolveWorkingDirectory(context);
51
51
  service.setWorkingDirectory(workingDirectory);
52
52
  };
53
+ const resolveInjectedService = (context) => {
54
+ const candidate = context.services?.processService;
55
+ if (!candidate) return null;
56
+ if (candidate instanceof import_process_service.ProcessService) return candidate;
57
+ const hasMethods = typeof candidate.executeCommand === "function" && typeof candidate.killProcess === "function" && typeof candidate.setWorkingDirectory === "function" && typeof candidate.getConfig === "function";
58
+ return hasMethods ? candidate : null;
59
+ };
53
60
  const getProcessService = async (context) => {
61
+ const injectedService = resolveInjectedService(context);
62
+ if (injectedService) {
63
+ applyWorkspace(context, injectedService);
64
+ return injectedService;
65
+ }
54
66
  if (processService) {
55
67
  applyWorkspace(context, processService);
56
68
  return processService;
@@ -1 +1 @@
1
- {"version":3,"file":"tool-factory.d.ts","sourceRoot":"","sources":["../src/tool-factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAMvD,OAAO,EAA4B,KAAK,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAG7F,eAAO,MAAM,mBAAmB,EAAE,WAAW,CAAC,kBAAkB,CAuD/D,CAAC"}
1
+ {"version":3,"file":"tool-factory.d.ts","sourceRoot":"","sources":["../src/tool-factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAMvD,OAAO,EAA4B,KAAK,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAG7F,eAAO,MAAM,mBAAmB,EAAE,WAAW,CAAC,kBAAkB,CA0E/D,CAAC"}
@@ -27,7 +27,19 @@ const processToolsFactory = {
27
27
  const workingDirectory = resolveWorkingDirectory(context);
28
28
  service.setWorkingDirectory(workingDirectory);
29
29
  };
30
+ const resolveInjectedService = (context) => {
31
+ const candidate = context.services?.processService;
32
+ if (!candidate) return null;
33
+ if (candidate instanceof ProcessService) return candidate;
34
+ const hasMethods = typeof candidate.executeCommand === "function" && typeof candidate.killProcess === "function" && typeof candidate.setWorkingDirectory === "function" && typeof candidate.getConfig === "function";
35
+ return hasMethods ? candidate : null;
36
+ };
30
37
  const getProcessService = async (context) => {
38
+ const injectedService = resolveInjectedService(context);
39
+ if (injectedService) {
40
+ applyWorkspace(context, injectedService);
41
+ return injectedService;
42
+ }
31
43
  if (processService) {
32
44
  applyWorkspace(context, processService);
33
45
  return processService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dexto/tools-process",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "description": "Process tools factory for Dexto agents",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -20,8 +20,8 @@
20
20
  ],
21
21
  "dependencies": {
22
22
  "zod": "^3.25.0",
23
- "@dexto/agent-config": "1.6.0",
24
- "@dexto/core": "1.6.0"
23
+ "@dexto/agent-config": "1.6.2",
24
+ "@dexto/core": "1.6.2"
25
25
  },
26
26
  "devDependencies": {
27
27
  "tsup": "^8.0.0",
@@ -32,7 +32,7 @@
32
32
  "README.md"
33
33
  ],
34
34
  "scripts": {
35
- "build": "tsup",
35
+ "build": "tsup && node ../../scripts/clean-tsbuildinfo.mjs && tsc -b tsconfig.json --emitDeclarationOnly",
36
36
  "typecheck": "tsc --noEmit",
37
37
  "clean": "rm -rf dist"
38
38
  }
@@ -1,38 +0,0 @@
1
- import { z } from 'zod';
2
- import { ToolExecutionContext, Tool } from '@dexto/core';
3
- import { ProcessService } from './process-service.cjs';
4
- import './types.cjs';
5
-
6
- /**
7
- * Bash Execute Tool
8
- *
9
- * Internal tool for executing shell commands.
10
- * Pattern-based approval support is declared on the tool (ToolManager stays generic).
11
- */
12
-
13
- declare const BashExecInputSchema: z.ZodObject<{
14
- command: z.ZodString;
15
- description: z.ZodOptional<z.ZodString>;
16
- timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
17
- run_in_background: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
18
- cwd: z.ZodOptional<z.ZodString>;
19
- }, "strict", z.ZodTypeAny, {
20
- command: string;
21
- timeout: number;
22
- run_in_background: boolean;
23
- description?: string | undefined;
24
- cwd?: string | undefined;
25
- }, {
26
- command: string;
27
- description?: string | undefined;
28
- timeout?: number | undefined;
29
- run_in_background?: boolean | undefined;
30
- cwd?: string | undefined;
31
- }>;
32
- /**
33
- * Create the bash_exec internal tool
34
- */
35
- type ProcessServiceGetter = (context: ToolExecutionContext) => Promise<ProcessService>;
36
- declare function createBashExecTool(getProcessService: ProcessServiceGetter): Tool<typeof BashExecInputSchema>;
37
-
38
- export { type ProcessServiceGetter, createBashExecTool };