@dexto/tools-process 1.5.8 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bash-exec-tool.cjs +40 -23
- 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 +43 -23
- package/dist/bash-output-tool.cjs +13 -5
- 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 +13 -5
- package/dist/command-pattern-utils.cjs +83 -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.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.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 +6 -3
- package/dist/index.d.cts +485 -11
- package/dist/index.d.ts +10 -4
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -2
- package/dist/kill-process-tool.cjs +13 -5
- 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 +13 -5
- package/dist/process-service.cjs +11 -1
- 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.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 +89 -0
- package/dist/tool-factory.d.ts +4 -0
- package/dist/tool-factory.d.ts.map +1 -0
- package/dist/tool-factory.js +65 -0
- package/dist/types.d.ts +9 -10
- package/dist/types.d.ts.map +1 -0
- package/package.json +5 -4
- package/dist/bash-exec-tool.d.cts +0 -17
- package/dist/bash-output-tool.d.cts +0 -16
- package/dist/command-validator.d.cts +0 -52
- package/dist/error-codes.d.cts +0 -26
- package/dist/errors.d.cts +0 -90
- package/dist/kill-process-tool.d.cts +0 -16
- package/dist/process-service.d.cts +0 -96
- package/dist/tool-provider.d.cts +0 -72
- package/dist/types.d.cts +0 -108
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generateCommandPatternKey,
|
|
3
|
+
generateCommandPatternSuggestions,
|
|
4
|
+
isDangerousCommand
|
|
5
|
+
} from "./command-pattern-utils.js";
|
|
6
|
+
import { describe, it, expect } from "vitest";
|
|
7
|
+
describe("command-pattern-utils", () => {
|
|
8
|
+
describe("isDangerousCommand", () => {
|
|
9
|
+
it("should detect dangerous commands", () => {
|
|
10
|
+
expect(isDangerousCommand("rm -rf /")).toBe(true);
|
|
11
|
+
expect(isDangerousCommand("sudo apt install")).toBe(true);
|
|
12
|
+
expect(isDangerousCommand("chmod 777 file")).toBe(true);
|
|
13
|
+
expect(isDangerousCommand("kill -9 1234")).toBe(true);
|
|
14
|
+
expect(isDangerousCommand("dd if=/dev/zero of=/dev/sda")).toBe(true);
|
|
15
|
+
});
|
|
16
|
+
it("should not flag safe commands", () => {
|
|
17
|
+
expect(isDangerousCommand("ls -la")).toBe(false);
|
|
18
|
+
expect(isDangerousCommand("git status")).toBe(false);
|
|
19
|
+
expect(isDangerousCommand("npm install")).toBe(false);
|
|
20
|
+
expect(isDangerousCommand("cat file.txt")).toBe(false);
|
|
21
|
+
});
|
|
22
|
+
it("should be case-insensitive", () => {
|
|
23
|
+
expect(isDangerousCommand("RM -rf /")).toBe(true);
|
|
24
|
+
expect(isDangerousCommand("SUDO apt install")).toBe(true);
|
|
25
|
+
expect(isDangerousCommand("Chmod 777 file")).toBe(true);
|
|
26
|
+
});
|
|
27
|
+
it("should handle empty input", () => {
|
|
28
|
+
expect(isDangerousCommand("")).toBe(false);
|
|
29
|
+
expect(isDangerousCommand(" ")).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
describe("generateCommandPatternKey", () => {
|
|
33
|
+
it("should generate patterns for simple commands", () => {
|
|
34
|
+
expect(generateCommandPatternKey("ls")).toBe("ls *");
|
|
35
|
+
expect(generateCommandPatternKey("pwd")).toBe("pwd *");
|
|
36
|
+
});
|
|
37
|
+
it("should ignore flags when choosing subcommand", () => {
|
|
38
|
+
expect(generateCommandPatternKey("ls -la")).toBe("ls *");
|
|
39
|
+
expect(generateCommandPatternKey("git -v status")).toBe("git status *");
|
|
40
|
+
expect(generateCommandPatternKey("npm --verbose install")).toBe("npm install *");
|
|
41
|
+
});
|
|
42
|
+
it("should generate subcommand patterns", () => {
|
|
43
|
+
expect(generateCommandPatternKey("git status")).toBe("git status *");
|
|
44
|
+
expect(generateCommandPatternKey("git push origin main")).toBe("git push *");
|
|
45
|
+
});
|
|
46
|
+
it("should return null for dangerous commands", () => {
|
|
47
|
+
expect(generateCommandPatternKey("rm -rf /")).toBeNull();
|
|
48
|
+
expect(generateCommandPatternKey("sudo apt install")).toBeNull();
|
|
49
|
+
expect(generateCommandPatternKey("shutdown -h now")).toBeNull();
|
|
50
|
+
});
|
|
51
|
+
it("should handle empty input", () => {
|
|
52
|
+
expect(generateCommandPatternKey("")).toBeNull();
|
|
53
|
+
expect(generateCommandPatternKey(" ")).toBeNull();
|
|
54
|
+
});
|
|
55
|
+
it("should trim and normalize whitespace", () => {
|
|
56
|
+
expect(generateCommandPatternKey(" ls -la ")).toBe("ls *");
|
|
57
|
+
expect(generateCommandPatternKey(" git push origin ")).toBe("git push *");
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
describe("generateCommandPatternSuggestions", () => {
|
|
61
|
+
it("should generate broad-to-narrow suggestions", () => {
|
|
62
|
+
expect(generateCommandPatternSuggestions("ls")).toEqual(["ls *"]);
|
|
63
|
+
expect(generateCommandPatternSuggestions("git push origin main")).toEqual([
|
|
64
|
+
"git push *",
|
|
65
|
+
"git *"
|
|
66
|
+
]);
|
|
67
|
+
});
|
|
68
|
+
it("should return empty for dangerous commands", () => {
|
|
69
|
+
expect(generateCommandPatternSuggestions("rm -rf /")).toEqual([]);
|
|
70
|
+
});
|
|
71
|
+
it("should handle empty input", () => {
|
|
72
|
+
expect(generateCommandPatternSuggestions("")).toEqual([]);
|
|
73
|
+
expect(generateCommandPatternSuggestions(" ")).toEqual([]);
|
|
74
|
+
});
|
|
75
|
+
it("should keep suggestions consistent with pattern key", () => {
|
|
76
|
+
const command = "git push origin main";
|
|
77
|
+
const patternKey = generateCommandPatternKey(command);
|
|
78
|
+
const suggestions = generateCommandPatternSuggestions(command);
|
|
79
|
+
expect(patternKey).toBe("git push *");
|
|
80
|
+
expect(suggestions[0]).toBe(patternKey);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { ProcessConfig, CommandValidation } from './types.js';
|
|
2
|
-
import { IDextoLogger } from '@dexto/core';
|
|
3
|
-
|
|
4
1
|
/**
|
|
5
2
|
* Command Validator
|
|
6
3
|
*
|
|
7
4
|
* Security-focused command validation for process execution
|
|
8
5
|
*/
|
|
9
|
-
|
|
6
|
+
import { ProcessConfig, CommandValidation } from './types.js';
|
|
7
|
+
import type { Logger } from '@dexto/core';
|
|
10
8
|
/**
|
|
11
9
|
* CommandValidator - Validates commands for security and policy compliance
|
|
12
10
|
*
|
|
@@ -18,10 +16,10 @@ import { IDextoLogger } from '@dexto/core';
|
|
|
18
16
|
* 5. Shell metacharacter analysis
|
|
19
17
|
* TODO: Add tests for this class
|
|
20
18
|
*/
|
|
21
|
-
declare class CommandValidator {
|
|
19
|
+
export declare class CommandValidator {
|
|
22
20
|
private config;
|
|
23
21
|
private logger;
|
|
24
|
-
constructor(config: ProcessConfig, logger:
|
|
22
|
+
constructor(config: ProcessConfig, logger: Logger);
|
|
25
23
|
/**
|
|
26
24
|
* Validate a command for security and policy compliance
|
|
27
25
|
*/
|
|
@@ -48,5 +46,4 @@ declare class CommandValidator {
|
|
|
48
46
|
*/
|
|
49
47
|
getSecurityLevel(): string;
|
|
50
48
|
}
|
|
51
|
-
|
|
52
|
-
export { CommandValidator };
|
|
49
|
+
//# sourceMappingURL=command-validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-validator.d.ts","sourceRoot":"","sources":["../src/command-validator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAkQ1C;;;;;;;;;;GAUG;AACH,qBAAa,gBAAgB;IACzB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM;IAQjD;;OAEG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,iBAAiB;IAgFnD;;OAEG;IACH,OAAO,CAAC,eAAe;IAgCvB;;;OAGG;IACH,OAAO,CAAC,4BAA4B;IAyCpC;;OAEG;IACH,kBAAkB,IAAI,MAAM,EAAE;IAI9B;;OAEG;IACH,kBAAkB,IAAI,MAAM,EAAE;IAI9B;;OAEG;IACH,gBAAgB,IAAI,MAAM;CAG7B"}
|
package/dist/error-codes.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Standardized error codes for process execution and management
|
|
5
5
|
*/
|
|
6
|
-
declare enum ProcessErrorCode {
|
|
6
|
+
export declare enum ProcessErrorCode {
|
|
7
7
|
INVALID_COMMAND = "PROCESS_INVALID_COMMAND",
|
|
8
8
|
COMMAND_BLOCKED = "PROCESS_COMMAND_BLOCKED",
|
|
9
9
|
COMMAND_TOO_LONG = "PROCESS_COMMAND_TOO_LONG",
|
|
@@ -22,5 +22,4 @@ declare enum ProcessErrorCode {
|
|
|
22
22
|
INVALID_CONFIG = "PROCESS_INVALID_CONFIG",
|
|
23
23
|
SERVICE_NOT_INITIALIZED = "PROCESS_SERVICE_NOT_INITIALIZED"
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
export { ProcessErrorCode };
|
|
25
|
+
//# sourceMappingURL=error-codes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-codes.d.ts","sourceRoot":"","sources":["../src/error-codes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,oBAAY,gBAAgB;IAExB,eAAe,4BAA4B;IAC3C,eAAe,4BAA4B;IAC3C,gBAAgB,6BAA6B;IAC7C,kBAAkB,+BAA+B;IACjD,iBAAiB,8BAA8B;IAC/C,eAAe,4BAA4B;IAG3C,gBAAgB,6BAA6B;IAC7C,OAAO,oBAAoB;IAC3B,iBAAiB,8BAA8B;IAC/C,iBAAiB,8BAA8B;IAC/C,yBAAyB,sCAAsC;IAG/D,iBAAiB,sBAAsB;IACvC,kBAAkB,+BAA+B;IACjD,WAAW,wBAAwB;IACnC,kBAAkB,+BAA+B;IAGjD,cAAc,2BAA2B;IACzC,uBAAuB,oCAAoC;CAC9D"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { DextoRuntimeError } from '@dexto/core';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Process Service Errors
|
|
5
3
|
*
|
|
6
4
|
* Error classes for process execution and management
|
|
7
5
|
*/
|
|
8
|
-
|
|
9
|
-
interface ProcessErrorContext {
|
|
6
|
+
import { DextoRuntimeError } from '@dexto/core';
|
|
7
|
+
export interface ProcessErrorContext {
|
|
10
8
|
command?: string;
|
|
11
9
|
processId?: string;
|
|
12
10
|
timeout?: number;
|
|
@@ -15,7 +13,7 @@ interface ProcessErrorContext {
|
|
|
15
13
|
/**
|
|
16
14
|
* Factory class for creating Process-related errors
|
|
17
15
|
*/
|
|
18
|
-
declare class ProcessError {
|
|
16
|
+
export declare class ProcessError {
|
|
19
17
|
private constructor();
|
|
20
18
|
/**
|
|
21
19
|
* Invalid command error
|
|
@@ -86,5 +84,4 @@ declare class ProcessError {
|
|
|
86
84
|
*/
|
|
87
85
|
static notInitialized(): DextoRuntimeError;
|
|
88
86
|
}
|
|
89
|
-
|
|
90
|
-
export { ProcessError, type ProcessErrorContext };
|
|
87
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,iBAAiB,EAAa,MAAM,aAAa,CAAC;AAM3D,MAAM,WAAW,mBAAmB;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAED;;GAEG;AACH,qBAAa,YAAY;IACrB,OAAO;IAIP;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,iBAAiB;IAUzE;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,iBAAiB;IAUzE;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,iBAAiB;IAU3E;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,iBAAiB;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exports, {
|
|
|
22
22
|
ProcessError: () => import_errors.ProcessError,
|
|
23
23
|
ProcessErrorCode: () => import_error_codes.ProcessErrorCode,
|
|
24
24
|
ProcessService: () => import_process_service.ProcessService,
|
|
25
|
+
ProcessToolsConfigSchema: () => import_tool_factory_config.ProcessToolsConfigSchema,
|
|
25
26
|
createBashExecTool: () => import_bash_exec_tool.createBashExecTool,
|
|
26
27
|
createBashOutputTool: () => import_bash_output_tool.createBashOutputTool,
|
|
27
28
|
createKillProcessTool: () => import_kill_process_tool.createKillProcessTool,
|
|
28
|
-
|
|
29
|
+
processToolsFactory: () => import_tool_factory.processToolsFactory
|
|
29
30
|
});
|
|
30
31
|
module.exports = __toCommonJS(index_exports);
|
|
31
|
-
var
|
|
32
|
+
var import_tool_factory = require("./tool-factory.js");
|
|
33
|
+
var import_tool_factory_config = require("./tool-factory-config.js");
|
|
32
34
|
var import_process_service = require("./process-service.js");
|
|
33
35
|
var import_command_validator = require("./command-validator.js");
|
|
34
36
|
var import_errors = require("./errors.js");
|
|
@@ -42,8 +44,9 @@ var import_kill_process_tool = require("./kill-process-tool.js");
|
|
|
42
44
|
ProcessError,
|
|
43
45
|
ProcessErrorCode,
|
|
44
46
|
ProcessService,
|
|
47
|
+
ProcessToolsConfigSchema,
|
|
45
48
|
createBashExecTool,
|
|
46
49
|
createBashOutputTool,
|
|
47
50
|
createKillProcessTool,
|
|
48
|
-
|
|
51
|
+
processToolsFactory
|
|
49
52
|
});
|