@dexto/tools-process 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/LICENSE +44 -0
  2. package/dist/bash-exec-tool.cjs +130 -0
  3. package/dist/bash-exec-tool.d.cts +17 -0
  4. package/dist/bash-exec-tool.d.ts +17 -0
  5. package/dist/bash-exec-tool.js +96 -0
  6. package/dist/bash-output-tool.cjs +49 -0
  7. package/dist/bash-output-tool.d.cts +16 -0
  8. package/dist/bash-output-tool.d.ts +16 -0
  9. package/dist/bash-output-tool.js +25 -0
  10. package/dist/command-validator.cjs +554 -0
  11. package/dist/command-validator.d.cts +52 -0
  12. package/dist/command-validator.d.ts +52 -0
  13. package/dist/command-validator.js +530 -0
  14. package/dist/error-codes.cjs +47 -0
  15. package/dist/error-codes.d.cts +26 -0
  16. package/dist/error-codes.d.ts +26 -0
  17. package/dist/error-codes.js +23 -0
  18. package/dist/errors.cjs +243 -0
  19. package/dist/errors.d.cts +90 -0
  20. package/dist/errors.d.ts +90 -0
  21. package/dist/errors.js +219 -0
  22. package/dist/index.cjs +49 -0
  23. package/dist/index.d.cts +11 -0
  24. package/dist/index.d.ts +11 -0
  25. package/dist/index.js +18 -0
  26. package/dist/kill-process-tool.cjs +47 -0
  27. package/dist/kill-process-tool.d.cts +16 -0
  28. package/dist/kill-process-tool.d.ts +16 -0
  29. package/dist/kill-process-tool.js +23 -0
  30. package/dist/process-service.cjs +544 -0
  31. package/dist/process-service.d.cts +96 -0
  32. package/dist/process-service.d.ts +96 -0
  33. package/dist/process-service.js +510 -0
  34. package/dist/tool-provider.cjs +96 -0
  35. package/dist/tool-provider.d.cts +72 -0
  36. package/dist/tool-provider.d.ts +72 -0
  37. package/dist/tool-provider.js +72 -0
  38. package/dist/types.cjs +16 -0
  39. package/dist/types.d.cts +108 -0
  40. package/dist/types.d.ts +108 -0
  41. package/dist/types.js +0 -0
  42. package/package.json +38 -0
package/LICENSE ADDED
@@ -0,0 +1,44 @@
1
+ Elastic License 2.0 (ELv2)
2
+
3
+ **Acceptance**
4
+ By using the software, you agree to all of the terms and conditions below.
5
+
6
+ **Copyright License**
7
+ The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
8
+
9
+ **Limitations**
10
+ You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
11
+
12
+ You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
13
+
14
+ You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
15
+
16
+ **Patents**
17
+ The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
18
+
19
+ **Notices**
20
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
21
+
22
+ If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
23
+
24
+ **No Other Rights**
25
+ These terms do not imply any licenses other than those expressly granted in these terms.
26
+
27
+ **Termination**
28
+ If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
29
+
30
+ **No Liability**
31
+ As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
32
+
33
+ **Definitions**
34
+ The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
35
+
36
+ _you_ refers to the individual or entity agreeing to these terms.
37
+
38
+ _your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
39
+
40
+ _your licenses_ are all the licenses granted to you for the software under these terms.
41
+
42
+ _use_ means anything you do with the software requiring one of your licenses.
43
+
44
+ _trademark_ means trademarks, service marks, and similar rights.
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var bash_exec_tool_exports = {};
30
+ __export(bash_exec_tool_exports, {
31
+ createBashExecTool: () => createBashExecTool
32
+ });
33
+ module.exports = __toCommonJS(bash_exec_tool_exports);
34
+ var path = __toESM(require("node:path"), 1);
35
+ var import_zod = require("zod");
36
+ var import_errors = require("./errors.js");
37
+ const BashExecInputSchema = import_zod.z.object({
38
+ command: import_zod.z.string().describe("Shell command to execute"),
39
+ description: import_zod.z.string().optional().describe("Human-readable description of what the command does (5-10 words)"),
40
+ timeout: import_zod.z.number().int().positive().max(6e5).optional().default(12e4).describe(
41
+ "Timeout in milliseconds (max: 600000 = 10 minutes, default: 120000 = 2 minutes)"
42
+ ),
43
+ run_in_background: import_zod.z.boolean().optional().default(false).describe("Execute command in background (default: false)"),
44
+ cwd: import_zod.z.string().optional().describe("Working directory for command execution (optional)")
45
+ }).strict();
46
+ function createBashExecTool(processService) {
47
+ return {
48
+ id: "bash_exec",
49
+ description: "Execute a shell command with 2-minute default timeout. Returns stdout, stderr, exit code, and duration. For long-running commands (servers, watchers, npm run dev), MUST use run_in_background=true (use bash_output to retrieve results later). Commands ending with & are blocked - use run_in_background instead. Requires approval (with pattern-based session memory). Always quote file paths with spaces. Security: dangerous commands are blocked, injection attempts are detected.",
50
+ inputSchema: BashExecInputSchema,
51
+ /**
52
+ * Generate preview for approval UI - shows the command to be executed
53
+ */
54
+ generatePreview: async (input, _context) => {
55
+ const { command, run_in_background } = input;
56
+ const preview = {
57
+ type: "shell",
58
+ command,
59
+ exitCode: 0,
60
+ // Placeholder - not executed yet
61
+ duration: 0,
62
+ // Placeholder - not executed yet
63
+ ...run_in_background !== void 0 && { isBackground: run_in_background }
64
+ };
65
+ return preview;
66
+ },
67
+ execute: async (input, context) => {
68
+ const { command, description, timeout, run_in_background, cwd } = input;
69
+ let validatedCwd = cwd;
70
+ if (cwd) {
71
+ const baseDir = processService.getConfig().workingDirectory || process.cwd();
72
+ const candidatePath = path.isAbsolute(cwd) ? path.resolve(cwd) : path.resolve(baseDir, cwd);
73
+ const relativePath = path.relative(baseDir, candidatePath);
74
+ const isOutsideBase = relativePath.startsWith("..") || path.isAbsolute(relativePath);
75
+ if (isOutsideBase) {
76
+ throw import_errors.ProcessError.invalidWorkingDirectory(
77
+ cwd,
78
+ `Working directory must be within ${baseDir}`
79
+ );
80
+ }
81
+ validatedCwd = candidatePath;
82
+ }
83
+ const result = await processService.executeCommand(command, {
84
+ description,
85
+ timeout,
86
+ runInBackground: run_in_background,
87
+ cwd: validatedCwd,
88
+ // Pass abort signal for cancellation support
89
+ abortSignal: context?.abortSignal
90
+ });
91
+ if ("stdout" in result) {
92
+ const _display = {
93
+ type: "shell",
94
+ command,
95
+ exitCode: result.exitCode,
96
+ duration: result.duration,
97
+ isBackground: false,
98
+ stdout: result.stdout,
99
+ stderr: result.stderr
100
+ };
101
+ return {
102
+ stdout: result.stdout,
103
+ stderr: result.stderr,
104
+ exit_code: result.exitCode,
105
+ duration: result.duration,
106
+ _display
107
+ };
108
+ } else {
109
+ const _display = {
110
+ type: "shell",
111
+ command,
112
+ exitCode: 0,
113
+ // Background process hasn't exited yet
114
+ duration: 0,
115
+ // Still running
116
+ isBackground: true
117
+ };
118
+ return {
119
+ process_id: result.processId,
120
+ message: `Command started in background with ID: ${result.processId}. Use bash_output to retrieve output.`,
121
+ _display
122
+ };
123
+ }
124
+ }
125
+ };
126
+ }
127
+ // Annotate the CommonJS export names for ESM import in node:
128
+ 0 && (module.exports = {
129
+ createBashExecTool
130
+ });
@@ -0,0 +1,17 @@
1
+ import { InternalTool } from '@dexto/core';
2
+ import { ProcessService } from './process-service.cjs';
3
+ import './types.cjs';
4
+
5
+ /**
6
+ * Bash Execute Tool
7
+ *
8
+ * Internal tool for executing shell commands.
9
+ * Approval is handled at the ToolManager level with pattern-based approval.
10
+ */
11
+
12
+ /**
13
+ * Create the bash_exec internal tool
14
+ */
15
+ declare function createBashExecTool(processService: ProcessService): InternalTool;
16
+
17
+ export { createBashExecTool };
@@ -0,0 +1,17 @@
1
+ import { InternalTool } from '@dexto/core';
2
+ import { ProcessService } from './process-service.js';
3
+ import './types.js';
4
+
5
+ /**
6
+ * Bash Execute Tool
7
+ *
8
+ * Internal tool for executing shell commands.
9
+ * Approval is handled at the ToolManager level with pattern-based approval.
10
+ */
11
+
12
+ /**
13
+ * Create the bash_exec internal tool
14
+ */
15
+ declare function createBashExecTool(processService: ProcessService): InternalTool;
16
+
17
+ export { createBashExecTool };
@@ -0,0 +1,96 @@
1
+ import * as path from "node:path";
2
+ import { z } from "zod";
3
+ import { ProcessError } from "./errors.js";
4
+ const BashExecInputSchema = z.object({
5
+ command: z.string().describe("Shell command to execute"),
6
+ description: z.string().optional().describe("Human-readable description of what the command does (5-10 words)"),
7
+ timeout: z.number().int().positive().max(6e5).optional().default(12e4).describe(
8
+ "Timeout in milliseconds (max: 600000 = 10 minutes, default: 120000 = 2 minutes)"
9
+ ),
10
+ run_in_background: z.boolean().optional().default(false).describe("Execute command in background (default: false)"),
11
+ cwd: z.string().optional().describe("Working directory for command execution (optional)")
12
+ }).strict();
13
+ function createBashExecTool(processService) {
14
+ return {
15
+ id: "bash_exec",
16
+ description: "Execute a shell command with 2-minute default timeout. Returns stdout, stderr, exit code, and duration. For long-running commands (servers, watchers, npm run dev), MUST use run_in_background=true (use bash_output to retrieve results later). Commands ending with & are blocked - use run_in_background instead. Requires approval (with pattern-based session memory). Always quote file paths with spaces. Security: dangerous commands are blocked, injection attempts are detected.",
17
+ inputSchema: BashExecInputSchema,
18
+ /**
19
+ * Generate preview for approval UI - shows the command to be executed
20
+ */
21
+ generatePreview: async (input, _context) => {
22
+ const { command, run_in_background } = input;
23
+ const preview = {
24
+ type: "shell",
25
+ command,
26
+ exitCode: 0,
27
+ // Placeholder - not executed yet
28
+ duration: 0,
29
+ // Placeholder - not executed yet
30
+ ...run_in_background !== void 0 && { isBackground: run_in_background }
31
+ };
32
+ return preview;
33
+ },
34
+ execute: async (input, context) => {
35
+ const { command, description, timeout, run_in_background, cwd } = input;
36
+ let validatedCwd = cwd;
37
+ if (cwd) {
38
+ const baseDir = processService.getConfig().workingDirectory || process.cwd();
39
+ const candidatePath = path.isAbsolute(cwd) ? path.resolve(cwd) : path.resolve(baseDir, cwd);
40
+ const relativePath = path.relative(baseDir, candidatePath);
41
+ const isOutsideBase = relativePath.startsWith("..") || path.isAbsolute(relativePath);
42
+ if (isOutsideBase) {
43
+ throw ProcessError.invalidWorkingDirectory(
44
+ cwd,
45
+ `Working directory must be within ${baseDir}`
46
+ );
47
+ }
48
+ validatedCwd = candidatePath;
49
+ }
50
+ const result = await processService.executeCommand(command, {
51
+ description,
52
+ timeout,
53
+ runInBackground: run_in_background,
54
+ cwd: validatedCwd,
55
+ // Pass abort signal for cancellation support
56
+ abortSignal: context?.abortSignal
57
+ });
58
+ if ("stdout" in result) {
59
+ const _display = {
60
+ type: "shell",
61
+ command,
62
+ exitCode: result.exitCode,
63
+ duration: result.duration,
64
+ isBackground: false,
65
+ stdout: result.stdout,
66
+ stderr: result.stderr
67
+ };
68
+ return {
69
+ stdout: result.stdout,
70
+ stderr: result.stderr,
71
+ exit_code: result.exitCode,
72
+ duration: result.duration,
73
+ _display
74
+ };
75
+ } else {
76
+ const _display = {
77
+ type: "shell",
78
+ command,
79
+ exitCode: 0,
80
+ // Background process hasn't exited yet
81
+ duration: 0,
82
+ // Still running
83
+ isBackground: true
84
+ };
85
+ return {
86
+ process_id: result.processId,
87
+ message: `Command started in background with ID: ${result.processId}. Use bash_output to retrieve output.`,
88
+ _display
89
+ };
90
+ }
91
+ }
92
+ };
93
+ }
94
+ export {
95
+ createBashExecTool
96
+ };
@@ -0,0 +1,49 @@
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 bash_output_tool_exports = {};
20
+ __export(bash_output_tool_exports, {
21
+ createBashOutputTool: () => createBashOutputTool
22
+ });
23
+ module.exports = __toCommonJS(bash_output_tool_exports);
24
+ var import_zod = require("zod");
25
+ const BashOutputInputSchema = import_zod.z.object({
26
+ process_id: import_zod.z.string().describe("Process ID from bash_exec (when run_in_background=true)")
27
+ }).strict();
28
+ function createBashOutputTool(processService) {
29
+ return {
30
+ id: "bash_output",
31
+ 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
+ inputSchema: BashOutputInputSchema,
33
+ execute: async (input, _context) => {
34
+ const { process_id } = input;
35
+ const result = await processService.getProcessOutput(process_id);
36
+ return {
37
+ stdout: result.stdout,
38
+ stderr: result.stderr,
39
+ status: result.status,
40
+ ...result.exitCode !== void 0 && { exit_code: result.exitCode },
41
+ ...result.duration !== void 0 && { duration: result.duration }
42
+ };
43
+ }
44
+ };
45
+ }
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ createBashOutputTool
49
+ });
@@ -0,0 +1,16 @@
1
+ import { InternalTool } from '@dexto/core';
2
+ import { ProcessService } from './process-service.cjs';
3
+ import './types.cjs';
4
+
5
+ /**
6
+ * Bash Output Tool
7
+ *
8
+ * Internal tool for retrieving output from background processes
9
+ */
10
+
11
+ /**
12
+ * Create the bash_output internal tool
13
+ */
14
+ declare function createBashOutputTool(processService: ProcessService): InternalTool;
15
+
16
+ export { createBashOutputTool };
@@ -0,0 +1,16 @@
1
+ import { InternalTool } from '@dexto/core';
2
+ import { ProcessService } from './process-service.js';
3
+ import './types.js';
4
+
5
+ /**
6
+ * Bash Output Tool
7
+ *
8
+ * Internal tool for retrieving output from background processes
9
+ */
10
+
11
+ /**
12
+ * Create the bash_output internal tool
13
+ */
14
+ declare function createBashOutputTool(processService: ProcessService): InternalTool;
15
+
16
+ export { createBashOutputTool };
@@ -0,0 +1,25 @@
1
+ import { z } from "zod";
2
+ const BashOutputInputSchema = z.object({
3
+ process_id: z.string().describe("Process ID from bash_exec (when run_in_background=true)")
4
+ }).strict();
5
+ function createBashOutputTool(processService) {
6
+ return {
7
+ id: "bash_output",
8
+ 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
+ inputSchema: BashOutputInputSchema,
10
+ execute: async (input, _context) => {
11
+ const { process_id } = input;
12
+ const result = await processService.getProcessOutput(process_id);
13
+ return {
14
+ stdout: result.stdout,
15
+ stderr: result.stderr,
16
+ status: result.status,
17
+ ...result.exitCode !== void 0 && { exit_code: result.exitCode },
18
+ ...result.duration !== void 0 && { duration: result.duration }
19
+ };
20
+ }
21
+ };
22
+ }
23
+ export {
24
+ createBashOutputTool
25
+ };