@dexto/tools-process 1.5.7 → 1.6.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.
- package/dist/bash-exec-tool.cjs +23 -10
- package/dist/bash-exec-tool.d.cts +25 -4
- package/dist/bash-exec-tool.d.ts +27 -9
- package/dist/bash-exec-tool.d.ts.map +1 -0
- package/dist/bash-exec-tool.js +26 -10
- package/dist/bash-output-tool.cjs +8 -5
- package/dist/bash-output-tool.d.cts +12 -3
- package/dist/bash-output-tool.d.ts +13 -8
- package/dist/bash-output-tool.d.ts.map +1 -0
- package/dist/bash-output-tool.js +8 -5
- package/dist/command-pattern-utils.cjs +83 -0
- package/dist/command-pattern-utils.d.cts +30 -0
- package/dist/command-pattern-utils.d.ts +29 -0
- package/dist/command-pattern-utils.d.ts.map +1 -0
- package/dist/command-pattern-utils.js +56 -0
- package/dist/command-pattern-utils.test.cjs +80 -0
- package/dist/command-pattern-utils.test.d.cts +2 -0
- package/dist/command-pattern-utils.test.d.ts +2 -0
- package/dist/command-pattern-utils.test.d.ts.map +1 -0
- package/dist/command-pattern-utils.test.js +83 -0
- package/dist/command-validator.d.cts +2 -2
- package/dist/command-validator.d.ts +5 -8
- package/dist/command-validator.d.ts.map +1 -0
- package/dist/error-codes.d.ts +2 -3
- package/dist/error-codes.d.ts.map +1 -0
- package/dist/errors.d.ts +4 -7
- package/dist/errors.d.ts.map +1 -0
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +9 -4
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -2
- package/dist/kill-process-tool.cjs +8 -5
- package/dist/kill-process-tool.d.cts +12 -3
- package/dist/kill-process-tool.d.ts +13 -8
- package/dist/kill-process-tool.d.ts.map +1 -0
- package/dist/kill-process-tool.js +8 -5
- package/dist/process-service.cjs +11 -1
- package/dist/process-service.d.cts +9 -5
- package/dist/process-service.d.ts +12 -11
- package/dist/process-service.d.ts.map +1 -0
- package/dist/process-service.js +11 -1
- package/dist/{tool-provider.cjs → tool-factory-config.cjs} +6 -48
- package/dist/{tool-provider.d.cts → tool-factory-config.d.cts} +4 -20
- package/dist/{tool-provider.d.ts → tool-factory-config.d.ts} +8 -27
- package/dist/tool-factory-config.d.ts.map +1 -0
- package/dist/{tool-provider.js → tool-factory-config.js} +2 -44
- package/dist/tool-factory.cjs +77 -0
- package/dist/tool-factory.d.cts +7 -0
- package/dist/tool-factory.d.ts +4 -0
- package/dist/tool-factory.d.ts.map +1 -0
- package/dist/tool-factory.js +53 -0
- package/dist/types.d.ts +9 -10
- package/dist/types.d.ts.map +1 -0
- package/package.json +4 -3
package/dist/bash-exec-tool.cjs
CHANGED
|
@@ -33,9 +33,11 @@ __export(bash_exec_tool_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(bash_exec_tool_exports);
|
|
34
34
|
var path = __toESM(require("node:path"), 1);
|
|
35
35
|
var import_zod = require("zod");
|
|
36
|
+
var import_core = require("@dexto/core");
|
|
36
37
|
var import_errors = require("./errors.js");
|
|
38
|
+
var import_command_pattern_utils = require("./command-pattern-utils.js");
|
|
37
39
|
const BashExecInputSchema = import_zod.z.object({
|
|
38
|
-
command: import_zod.z.string().describe("Shell command to execute"),
|
|
40
|
+
command: import_zod.z.string().min(1).describe("Shell command to execute"),
|
|
39
41
|
description: import_zod.z.string().optional().describe("Human-readable description of what the command does (5-10 words)"),
|
|
40
42
|
timeout: import_zod.z.number().int().positive().max(6e5).optional().default(12e4).describe(
|
|
41
43
|
"Timeout in milliseconds (max: 600000 = 10 minutes, default: 120000 = 2 minutes)"
|
|
@@ -43,9 +45,11 @@ const BashExecInputSchema = import_zod.z.object({
|
|
|
43
45
|
run_in_background: import_zod.z.boolean().optional().default(false).describe("Execute command in background (default: false)"),
|
|
44
46
|
cwd: import_zod.z.string().optional().describe("Working directory for command execution (optional)")
|
|
45
47
|
}).strict();
|
|
46
|
-
function createBashExecTool(
|
|
47
|
-
return {
|
|
48
|
+
function createBashExecTool(getProcessService) {
|
|
49
|
+
return (0, import_core.defineTool)({
|
|
48
50
|
id: "bash_exec",
|
|
51
|
+
displayName: "Bash",
|
|
52
|
+
aliases: ["bash"],
|
|
49
53
|
description: `Execute a shell command in the project root directory.
|
|
50
54
|
|
|
51
55
|
IMPORTANT: This tool is for terminal operations like git, npm, docker, etc. Do NOT use it for file operations - use the specialized tools instead:
|
|
@@ -92,10 +96,18 @@ Each command runs in a fresh shell, so cd does not persist between calls.
|
|
|
92
96
|
|
|
93
97
|
Security: Dangerous commands are blocked. Injection attempts are detected. Requires approval with pattern-based session memory.`,
|
|
94
98
|
inputSchema: BashExecInputSchema,
|
|
99
|
+
getApprovalPatternKey(input) {
|
|
100
|
+
const command = input.command;
|
|
101
|
+
return (0, import_command_pattern_utils.generateCommandPatternKey)(command);
|
|
102
|
+
},
|
|
103
|
+
suggestApprovalPatterns(input) {
|
|
104
|
+
const command = input.command;
|
|
105
|
+
return (0, import_command_pattern_utils.generateCommandPatternSuggestions)(command);
|
|
106
|
+
},
|
|
95
107
|
/**
|
|
96
108
|
* Generate preview for approval UI - shows the command to be executed
|
|
97
109
|
*/
|
|
98
|
-
|
|
110
|
+
async generatePreview(input, _context) {
|
|
99
111
|
const { command, run_in_background } = input;
|
|
100
112
|
const preview = {
|
|
101
113
|
type: "shell",
|
|
@@ -104,15 +116,16 @@ Security: Dangerous commands are blocked. Injection attempts are detected. Requi
|
|
|
104
116
|
// Placeholder - not executed yet
|
|
105
117
|
duration: 0,
|
|
106
118
|
// Placeholder - not executed yet
|
|
107
|
-
|
|
119
|
+
isBackground: run_in_background
|
|
108
120
|
};
|
|
109
121
|
return preview;
|
|
110
122
|
},
|
|
111
|
-
|
|
123
|
+
async execute(input, context) {
|
|
124
|
+
const resolvedProcessService = await getProcessService(context);
|
|
112
125
|
const { command, description, timeout, run_in_background, cwd } = input;
|
|
113
126
|
let validatedCwd = cwd;
|
|
114
127
|
if (cwd) {
|
|
115
|
-
const baseDir =
|
|
128
|
+
const baseDir = resolvedProcessService.getConfig().workingDirectory || process.cwd();
|
|
116
129
|
const candidatePath = path.isAbsolute(cwd) ? path.resolve(cwd) : path.resolve(baseDir, cwd);
|
|
117
130
|
const relativePath = path.relative(baseDir, candidatePath);
|
|
118
131
|
const isOutsideBase = relativePath.startsWith("..") || path.isAbsolute(relativePath);
|
|
@@ -124,13 +137,13 @@ Security: Dangerous commands are blocked. Injection attempts are detected. Requi
|
|
|
124
137
|
}
|
|
125
138
|
validatedCwd = candidatePath;
|
|
126
139
|
}
|
|
127
|
-
const result = await
|
|
140
|
+
const result = await resolvedProcessService.executeCommand(command, {
|
|
128
141
|
description,
|
|
129
142
|
timeout,
|
|
130
143
|
runInBackground: run_in_background,
|
|
131
144
|
cwd: validatedCwd,
|
|
132
145
|
// Pass abort signal for cancellation support
|
|
133
|
-
abortSignal: context
|
|
146
|
+
abortSignal: context.abortSignal
|
|
134
147
|
});
|
|
135
148
|
if ("stdout" in result) {
|
|
136
149
|
const _display = {
|
|
@@ -166,7 +179,7 @@ Security: Dangerous commands are blocked. Injection attempts are detected. Requi
|
|
|
166
179
|
};
|
|
167
180
|
}
|
|
168
181
|
}
|
|
169
|
-
};
|
|
182
|
+
});
|
|
170
183
|
}
|
|
171
184
|
// Annotate the CommonJS export names for ESM import in node:
|
|
172
185
|
0 && (module.exports = {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ToolExecutionContext, Tool } from '@dexto/core';
|
|
2
3
|
import { ProcessService } from './process-service.cjs';
|
|
3
4
|
import './types.cjs';
|
|
4
5
|
|
|
@@ -6,12 +7,32 @@ import './types.cjs';
|
|
|
6
7
|
* Bash Execute Tool
|
|
7
8
|
*
|
|
8
9
|
* Internal tool for executing shell commands.
|
|
9
|
-
*
|
|
10
|
+
* Pattern-based approval support is declared on the tool (ToolManager stays generic).
|
|
10
11
|
*/
|
|
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
|
+
}>;
|
|
12
32
|
/**
|
|
13
33
|
* Create the bash_exec internal tool
|
|
14
34
|
*/
|
|
15
|
-
|
|
35
|
+
type ProcessServiceGetter = (context: ToolExecutionContext) => Promise<ProcessService>;
|
|
36
|
+
declare function createBashExecTool(getProcessService: ProcessServiceGetter): Tool<typeof BashExecInputSchema>;
|
|
16
37
|
|
|
17
|
-
export { createBashExecTool };
|
|
38
|
+
export { type ProcessServiceGetter, createBashExecTool };
|
package/dist/bash-exec-tool.d.ts
CHANGED
|
@@ -1,17 +1,35 @@
|
|
|
1
|
-
import { InternalTool } from '@dexto/core';
|
|
2
|
-
import { ProcessService } from './process-service.js';
|
|
3
|
-
import './types.js';
|
|
4
|
-
|
|
5
1
|
/**
|
|
6
2
|
* Bash Execute Tool
|
|
7
3
|
*
|
|
8
4
|
* Internal tool for executing shell commands.
|
|
9
|
-
*
|
|
5
|
+
* Pattern-based approval support is declared on the tool (ToolManager stays generic).
|
|
10
6
|
*/
|
|
11
|
-
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import type { Tool, ToolExecutionContext } from '@dexto/core';
|
|
9
|
+
import { ProcessService } from './process-service.js';
|
|
10
|
+
declare const BashExecInputSchema: z.ZodObject<{
|
|
11
|
+
command: z.ZodString;
|
|
12
|
+
description: z.ZodOptional<z.ZodString>;
|
|
13
|
+
timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
14
|
+
run_in_background: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
15
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
16
|
+
}, "strict", z.ZodTypeAny, {
|
|
17
|
+
command: string;
|
|
18
|
+
timeout: number;
|
|
19
|
+
run_in_background: boolean;
|
|
20
|
+
cwd?: string | undefined;
|
|
21
|
+
description?: string | undefined;
|
|
22
|
+
}, {
|
|
23
|
+
command: string;
|
|
24
|
+
timeout?: number | undefined;
|
|
25
|
+
cwd?: string | undefined;
|
|
26
|
+
description?: string | undefined;
|
|
27
|
+
run_in_background?: boolean | undefined;
|
|
28
|
+
}>;
|
|
12
29
|
/**
|
|
13
30
|
* Create the bash_exec internal tool
|
|
14
31
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export {
|
|
32
|
+
export type ProcessServiceGetter = (context: ToolExecutionContext) => Promise<ProcessService>;
|
|
33
|
+
export declare function createBashExecTool(getProcessService: ProcessServiceGetter): Tool<typeof BashExecInputSchema>;
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=bash-exec-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bash-exec-tool.d.ts","sourceRoot":"","sources":["../src/bash-exec-tool.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,IAAI,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAQtD,QAAA,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;EAwBZ,CAAC;AAEd;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,EAAE,oBAAoB,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;AAE9F,wBAAgB,kBAAkB,CAC9B,iBAAiB,EAAE,oBAAoB,GACxC,IAAI,CAAC,OAAO,mBAAmB,CAAC,CA+JlC"}
|
package/dist/bash-exec-tool.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import * as path from "node:path";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { defineTool } from "@dexto/core";
|
|
3
4
|
import { ProcessError } from "./errors.js";
|
|
5
|
+
import {
|
|
6
|
+
generateCommandPatternKey,
|
|
7
|
+
generateCommandPatternSuggestions
|
|
8
|
+
} from "./command-pattern-utils.js";
|
|
4
9
|
const BashExecInputSchema = z.object({
|
|
5
|
-
command: z.string().describe("Shell command to execute"),
|
|
10
|
+
command: z.string().min(1).describe("Shell command to execute"),
|
|
6
11
|
description: z.string().optional().describe("Human-readable description of what the command does (5-10 words)"),
|
|
7
12
|
timeout: z.number().int().positive().max(6e5).optional().default(12e4).describe(
|
|
8
13
|
"Timeout in milliseconds (max: 600000 = 10 minutes, default: 120000 = 2 minutes)"
|
|
@@ -10,9 +15,11 @@ const BashExecInputSchema = z.object({
|
|
|
10
15
|
run_in_background: z.boolean().optional().default(false).describe("Execute command in background (default: false)"),
|
|
11
16
|
cwd: z.string().optional().describe("Working directory for command execution (optional)")
|
|
12
17
|
}).strict();
|
|
13
|
-
function createBashExecTool(
|
|
14
|
-
return {
|
|
18
|
+
function createBashExecTool(getProcessService) {
|
|
19
|
+
return defineTool({
|
|
15
20
|
id: "bash_exec",
|
|
21
|
+
displayName: "Bash",
|
|
22
|
+
aliases: ["bash"],
|
|
16
23
|
description: `Execute a shell command in the project root directory.
|
|
17
24
|
|
|
18
25
|
IMPORTANT: This tool is for terminal operations like git, npm, docker, etc. Do NOT use it for file operations - use the specialized tools instead:
|
|
@@ -59,10 +66,18 @@ Each command runs in a fresh shell, so cd does not persist between calls.
|
|
|
59
66
|
|
|
60
67
|
Security: Dangerous commands are blocked. Injection attempts are detected. Requires approval with pattern-based session memory.`,
|
|
61
68
|
inputSchema: BashExecInputSchema,
|
|
69
|
+
getApprovalPatternKey(input) {
|
|
70
|
+
const command = input.command;
|
|
71
|
+
return generateCommandPatternKey(command);
|
|
72
|
+
},
|
|
73
|
+
suggestApprovalPatterns(input) {
|
|
74
|
+
const command = input.command;
|
|
75
|
+
return generateCommandPatternSuggestions(command);
|
|
76
|
+
},
|
|
62
77
|
/**
|
|
63
78
|
* Generate preview for approval UI - shows the command to be executed
|
|
64
79
|
*/
|
|
65
|
-
|
|
80
|
+
async generatePreview(input, _context) {
|
|
66
81
|
const { command, run_in_background } = input;
|
|
67
82
|
const preview = {
|
|
68
83
|
type: "shell",
|
|
@@ -71,15 +86,16 @@ Security: Dangerous commands are blocked. Injection attempts are detected. Requi
|
|
|
71
86
|
// Placeholder - not executed yet
|
|
72
87
|
duration: 0,
|
|
73
88
|
// Placeholder - not executed yet
|
|
74
|
-
|
|
89
|
+
isBackground: run_in_background
|
|
75
90
|
};
|
|
76
91
|
return preview;
|
|
77
92
|
},
|
|
78
|
-
|
|
93
|
+
async execute(input, context) {
|
|
94
|
+
const resolvedProcessService = await getProcessService(context);
|
|
79
95
|
const { command, description, timeout, run_in_background, cwd } = input;
|
|
80
96
|
let validatedCwd = cwd;
|
|
81
97
|
if (cwd) {
|
|
82
|
-
const baseDir =
|
|
98
|
+
const baseDir = resolvedProcessService.getConfig().workingDirectory || process.cwd();
|
|
83
99
|
const candidatePath = path.isAbsolute(cwd) ? path.resolve(cwd) : path.resolve(baseDir, cwd);
|
|
84
100
|
const relativePath = path.relative(baseDir, candidatePath);
|
|
85
101
|
const isOutsideBase = relativePath.startsWith("..") || path.isAbsolute(relativePath);
|
|
@@ -91,13 +107,13 @@ Security: Dangerous commands are blocked. Injection attempts are detected. Requi
|
|
|
91
107
|
}
|
|
92
108
|
validatedCwd = candidatePath;
|
|
93
109
|
}
|
|
94
|
-
const result = await
|
|
110
|
+
const result = await resolvedProcessService.executeCommand(command, {
|
|
95
111
|
description,
|
|
96
112
|
timeout,
|
|
97
113
|
runInBackground: run_in_background,
|
|
98
114
|
cwd: validatedCwd,
|
|
99
115
|
// Pass abort signal for cancellation support
|
|
100
|
-
abortSignal: context
|
|
116
|
+
abortSignal: context.abortSignal
|
|
101
117
|
});
|
|
102
118
|
if ("stdout" in result) {
|
|
103
119
|
const _display = {
|
|
@@ -133,7 +149,7 @@ Security: Dangerous commands are blocked. Injection attempts are detected. Requi
|
|
|
133
149
|
};
|
|
134
150
|
}
|
|
135
151
|
}
|
|
136
|
-
};
|
|
152
|
+
});
|
|
137
153
|
}
|
|
138
154
|
export {
|
|
139
155
|
createBashExecTool
|
|
@@ -22,17 +22,20 @@ __export(bash_output_tool_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(bash_output_tool_exports);
|
|
24
24
|
var import_zod = require("zod");
|
|
25
|
+
var import_core = require("@dexto/core");
|
|
25
26
|
const BashOutputInputSchema = import_zod.z.object({
|
|
26
27
|
process_id: import_zod.z.string().describe("Process ID from bash_exec (when run_in_background=true)")
|
|
27
28
|
}).strict();
|
|
28
|
-
function createBashOutputTool(
|
|
29
|
-
return {
|
|
29
|
+
function createBashOutputTool(getProcessService) {
|
|
30
|
+
return (0, import_core.defineTool)({
|
|
30
31
|
id: "bash_output",
|
|
32
|
+
displayName: "Bash Output",
|
|
31
33
|
description: "Retrieve output from a background process started with bash_exec. Returns stdout, stderr, status (running/completed/failed), exit code, and duration. Each call returns only new output since last read. The output buffer is cleared after reading. Use this tool to monitor long-running commands.",
|
|
32
34
|
inputSchema: BashOutputInputSchema,
|
|
33
|
-
|
|
35
|
+
async execute(input, context) {
|
|
36
|
+
const resolvedProcessService = await getProcessService(context);
|
|
34
37
|
const { process_id } = input;
|
|
35
|
-
const result = await
|
|
38
|
+
const result = await resolvedProcessService.getProcessOutput(process_id);
|
|
36
39
|
return {
|
|
37
40
|
stdout: result.stdout,
|
|
38
41
|
stderr: result.stderr,
|
|
@@ -41,7 +44,7 @@ function createBashOutputTool(processService) {
|
|
|
41
44
|
...result.duration !== void 0 && { duration: result.duration }
|
|
42
45
|
};
|
|
43
46
|
}
|
|
44
|
-
};
|
|
47
|
+
});
|
|
45
48
|
}
|
|
46
49
|
// Annotate the CommonJS export names for ESM import in node:
|
|
47
50
|
0 && (module.exports = {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Tool } from '@dexto/core';
|
|
3
|
+
import { ProcessServiceGetter } from './bash-exec-tool.cjs';
|
|
4
|
+
import './process-service.cjs';
|
|
3
5
|
import './types.cjs';
|
|
4
6
|
|
|
5
7
|
/**
|
|
@@ -8,9 +10,16 @@ import './types.cjs';
|
|
|
8
10
|
* Internal tool for retrieving output from background processes
|
|
9
11
|
*/
|
|
10
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
|
+
}>;
|
|
11
20
|
/**
|
|
12
21
|
* Create the bash_output internal tool
|
|
13
22
|
*/
|
|
14
|
-
declare function createBashOutputTool(
|
|
23
|
+
declare function createBashOutputTool(getProcessService: ProcessServiceGetter): Tool<typeof BashOutputInputSchema>;
|
|
15
24
|
|
|
16
25
|
export { createBashOutputTool };
|
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import { InternalTool } from '@dexto/core';
|
|
2
|
-
import { ProcessService } from './process-service.js';
|
|
3
|
-
import './types.js';
|
|
4
|
-
|
|
5
1
|
/**
|
|
6
2
|
* Bash Output Tool
|
|
7
3
|
*
|
|
8
4
|
* Internal tool for retrieving output from background processes
|
|
9
5
|
*/
|
|
10
|
-
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import type { Tool } from '@dexto/core';
|
|
8
|
+
import type { ProcessServiceGetter } from './bash-exec-tool.js';
|
|
9
|
+
declare const BashOutputInputSchema: z.ZodObject<{
|
|
10
|
+
process_id: z.ZodString;
|
|
11
|
+
}, "strict", z.ZodTypeAny, {
|
|
12
|
+
process_id: string;
|
|
13
|
+
}, {
|
|
14
|
+
process_id: string;
|
|
15
|
+
}>;
|
|
11
16
|
/**
|
|
12
17
|
* Create the bash_output internal tool
|
|
13
18
|
*/
|
|
14
|
-
declare function createBashOutputTool(
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
export declare function createBashOutputTool(getProcessService: ProcessServiceGetter): Tool<typeof BashOutputInputSchema>;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=bash-output-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bash-output-tool.d.ts","sourceRoot":"","sources":["../src/bash-output-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,qBAAqB;;;;;;EAId,CAAC;AAEd;;GAEG;AACH,wBAAgB,oBAAoB,CAChC,iBAAiB,EAAE,oBAAoB,GACxC,IAAI,CAAC,OAAO,qBAAqB,CAAC,CAyBpC"}
|
package/dist/bash-output-tool.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { defineTool } from "@dexto/core";
|
|
2
3
|
const BashOutputInputSchema = z.object({
|
|
3
4
|
process_id: z.string().describe("Process ID from bash_exec (when run_in_background=true)")
|
|
4
5
|
}).strict();
|
|
5
|
-
function createBashOutputTool(
|
|
6
|
-
return {
|
|
6
|
+
function createBashOutputTool(getProcessService) {
|
|
7
|
+
return defineTool({
|
|
7
8
|
id: "bash_output",
|
|
9
|
+
displayName: "Bash Output",
|
|
8
10
|
description: "Retrieve output from a background process started with bash_exec. Returns stdout, stderr, status (running/completed/failed), exit code, and duration. Each call returns only new output since last read. The output buffer is cleared after reading. Use this tool to monitor long-running commands.",
|
|
9
11
|
inputSchema: BashOutputInputSchema,
|
|
10
|
-
|
|
12
|
+
async execute(input, context) {
|
|
13
|
+
const resolvedProcessService = await getProcessService(context);
|
|
11
14
|
const { process_id } = input;
|
|
12
|
-
const result = await
|
|
15
|
+
const result = await resolvedProcessService.getProcessOutput(process_id);
|
|
13
16
|
return {
|
|
14
17
|
stdout: result.stdout,
|
|
15
18
|
stderr: result.stderr,
|
|
@@ -18,7 +21,7 @@ function createBashOutputTool(processService) {
|
|
|
18
21
|
...result.duration !== void 0 && { duration: result.duration }
|
|
19
22
|
};
|
|
20
23
|
}
|
|
21
|
-
};
|
|
24
|
+
});
|
|
22
25
|
}
|
|
23
26
|
export {
|
|
24
27
|
createBashOutputTool
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var command_pattern_utils_exports = {};
|
|
20
|
+
__export(command_pattern_utils_exports, {
|
|
21
|
+
DANGEROUS_COMMAND_PREFIXES: () => DANGEROUS_COMMAND_PREFIXES,
|
|
22
|
+
generateCommandPatternKey: () => generateCommandPatternKey,
|
|
23
|
+
generateCommandPatternSuggestions: () => generateCommandPatternSuggestions,
|
|
24
|
+
isDangerousCommand: () => isDangerousCommand
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(command_pattern_utils_exports);
|
|
27
|
+
const DANGEROUS_COMMAND_PREFIXES = [
|
|
28
|
+
"rm",
|
|
29
|
+
"chmod",
|
|
30
|
+
"chown",
|
|
31
|
+
"chgrp",
|
|
32
|
+
"sudo",
|
|
33
|
+
"su",
|
|
34
|
+
"dd",
|
|
35
|
+
"mkfs",
|
|
36
|
+
"fdisk",
|
|
37
|
+
"parted",
|
|
38
|
+
"kill",
|
|
39
|
+
"killall",
|
|
40
|
+
"pkill",
|
|
41
|
+
"shutdown",
|
|
42
|
+
"reboot",
|
|
43
|
+
"halt",
|
|
44
|
+
"poweroff"
|
|
45
|
+
];
|
|
46
|
+
function isDangerousCommand(command) {
|
|
47
|
+
const tokens = command.trim().split(/\s+/);
|
|
48
|
+
if (!tokens[0]) return false;
|
|
49
|
+
const head = tokens[0].toLowerCase();
|
|
50
|
+
return DANGEROUS_COMMAND_PREFIXES.includes(head);
|
|
51
|
+
}
|
|
52
|
+
function generateCommandPatternKey(command) {
|
|
53
|
+
const tokens = command.trim().split(/\s+/);
|
|
54
|
+
if (!tokens[0]) return null;
|
|
55
|
+
const head = tokens[0].toLowerCase();
|
|
56
|
+
if (isDangerousCommand(command)) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
const subcommand = tokens.slice(1).find((arg) => !arg.startsWith("-"));
|
|
60
|
+
return subcommand ? `${head} ${subcommand.toLowerCase()} *` : `${head} *`;
|
|
61
|
+
}
|
|
62
|
+
function generateCommandPatternSuggestions(command) {
|
|
63
|
+
const tokens = command.trim().toLowerCase().split(/\s+/);
|
|
64
|
+
if (!tokens[0]) return [];
|
|
65
|
+
const head = tokens[0];
|
|
66
|
+
if (isDangerousCommand(command)) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
const patterns = [];
|
|
70
|
+
const nonFlagArgs = tokens.slice(1).filter((arg) => !arg.startsWith("-"));
|
|
71
|
+
if (nonFlagArgs.length > 0) {
|
|
72
|
+
patterns.push(`${head} ${nonFlagArgs[0]} *`);
|
|
73
|
+
}
|
|
74
|
+
patterns.push(`${head} *`);
|
|
75
|
+
return patterns;
|
|
76
|
+
}
|
|
77
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
+
0 && (module.exports = {
|
|
79
|
+
DANGEROUS_COMMAND_PREFIXES,
|
|
80
|
+
generateCommandPatternKey,
|
|
81
|
+
generateCommandPatternSuggestions,
|
|
82
|
+
isDangerousCommand
|
|
83
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
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 };
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
export declare const DANGEROUS_COMMAND_PREFIXES: readonly ["rm", "chmod", "chown", "chgrp", "sudo", "su", "dd", "mkfs", "fdisk", "parted", "kill", "killall", "pkill", "shutdown", "reboot", "halt", "poweroff"];
|
|
12
|
+
export 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
|
+
export 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
|
+
export declare function generateCommandPatternSuggestions(command: string): string[];
|
|
29
|
+
//# sourceMappingURL=command-pattern-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-pattern-utils.d.ts","sourceRoot":"","sources":["../src/command-pattern-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,eAAO,MAAM,0BAA0B,iKAkB7B,CAAC;AAEX,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAK3D;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAYxE;AAED;;;;;GAKG;AACH,wBAAgB,iCAAiC,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAmB3E"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const DANGEROUS_COMMAND_PREFIXES = [
|
|
2
|
+
"rm",
|
|
3
|
+
"chmod",
|
|
4
|
+
"chown",
|
|
5
|
+
"chgrp",
|
|
6
|
+
"sudo",
|
|
7
|
+
"su",
|
|
8
|
+
"dd",
|
|
9
|
+
"mkfs",
|
|
10
|
+
"fdisk",
|
|
11
|
+
"parted",
|
|
12
|
+
"kill",
|
|
13
|
+
"killall",
|
|
14
|
+
"pkill",
|
|
15
|
+
"shutdown",
|
|
16
|
+
"reboot",
|
|
17
|
+
"halt",
|
|
18
|
+
"poweroff"
|
|
19
|
+
];
|
|
20
|
+
function isDangerousCommand(command) {
|
|
21
|
+
const tokens = command.trim().split(/\s+/);
|
|
22
|
+
if (!tokens[0]) return false;
|
|
23
|
+
const head = tokens[0].toLowerCase();
|
|
24
|
+
return DANGEROUS_COMMAND_PREFIXES.includes(head);
|
|
25
|
+
}
|
|
26
|
+
function generateCommandPatternKey(command) {
|
|
27
|
+
const tokens = command.trim().split(/\s+/);
|
|
28
|
+
if (!tokens[0]) return null;
|
|
29
|
+
const head = tokens[0].toLowerCase();
|
|
30
|
+
if (isDangerousCommand(command)) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const subcommand = tokens.slice(1).find((arg) => !arg.startsWith("-"));
|
|
34
|
+
return subcommand ? `${head} ${subcommand.toLowerCase()} *` : `${head} *`;
|
|
35
|
+
}
|
|
36
|
+
function generateCommandPatternSuggestions(command) {
|
|
37
|
+
const tokens = command.trim().toLowerCase().split(/\s+/);
|
|
38
|
+
if (!tokens[0]) return [];
|
|
39
|
+
const head = tokens[0];
|
|
40
|
+
if (isDangerousCommand(command)) {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
const patterns = [];
|
|
44
|
+
const nonFlagArgs = tokens.slice(1).filter((arg) => !arg.startsWith("-"));
|
|
45
|
+
if (nonFlagArgs.length > 0) {
|
|
46
|
+
patterns.push(`${head} ${nonFlagArgs[0]} *`);
|
|
47
|
+
}
|
|
48
|
+
patterns.push(`${head} *`);
|
|
49
|
+
return patterns;
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
DANGEROUS_COMMAND_PREFIXES,
|
|
53
|
+
generateCommandPatternKey,
|
|
54
|
+
generateCommandPatternSuggestions,
|
|
55
|
+
isDangerousCommand
|
|
56
|
+
};
|