n8n-nodes-claude-code-cli 1.0.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/LICENSE +21 -0
- package/README.md +603 -0
- package/dist/credentials/ClaudeCodeDockerApi.credentials.d.ts +9 -0
- package/dist/credentials/ClaudeCodeDockerApi.credentials.d.ts.map +1 -0
- package/dist/credentials/ClaudeCodeDockerApi.credentials.js +82 -0
- package/dist/credentials/ClaudeCodeDockerApi.credentials.js.map +1 -0
- package/dist/credentials/ClaudeCodeLocalApi.credentials.d.ts +9 -0
- package/dist/credentials/ClaudeCodeLocalApi.credentials.d.ts.map +1 -0
- package/dist/credentials/ClaudeCodeLocalApi.credentials.js +35 -0
- package/dist/credentials/ClaudeCodeLocalApi.credentials.js.map +1 -0
- package/dist/credentials/ClaudeCodeSshApi.credentials.d.ts +9 -0
- package/dist/credentials/ClaudeCodeSshApi.credentials.d.ts.map +1 -0
- package/dist/credentials/ClaudeCodeSshApi.credentials.js +119 -0
- package/dist/credentials/ClaudeCodeSshApi.credentials.js.map +1 -0
- package/dist/icons/claudecode.svg +40 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/nodes/ClaudeCode/ClaudeCode.node.d.ts +6 -0
- package/dist/nodes/ClaudeCode/ClaudeCode.node.d.ts.map +1 -0
- package/dist/nodes/ClaudeCode/ClaudeCode.node.js +131 -0
- package/dist/nodes/ClaudeCode/ClaudeCode.node.js.map +1 -0
- package/dist/nodes/ClaudeCode/descriptions/connectionModeDescription.d.ts +3 -0
- package/dist/nodes/ClaudeCode/descriptions/connectionModeDescription.d.ts.map +1 -0
- package/dist/nodes/ClaudeCode/descriptions/connectionModeDescription.js +30 -0
- package/dist/nodes/ClaudeCode/descriptions/connectionModeDescription.js.map +1 -0
- package/dist/nodes/ClaudeCode/descriptions/contextDescription.d.ts +3 -0
- package/dist/nodes/ClaudeCode/descriptions/contextDescription.d.ts.map +1 -0
- package/dist/nodes/ClaudeCode/descriptions/contextDescription.js +52 -0
- package/dist/nodes/ClaudeCode/descriptions/contextDescription.js.map +1 -0
- package/dist/nodes/ClaudeCode/descriptions/index.d.ts +9 -0
- package/dist/nodes/ClaudeCode/descriptions/index.d.ts.map +1 -0
- package/dist/nodes/ClaudeCode/descriptions/index.js +20 -0
- package/dist/nodes/ClaudeCode/descriptions/index.js.map +1 -0
- package/dist/nodes/ClaudeCode/descriptions/modelDescription.d.ts +3 -0
- package/dist/nodes/ClaudeCode/descriptions/modelDescription.d.ts.map +1 -0
- package/dist/nodes/ClaudeCode/descriptions/modelDescription.js +49 -0
- package/dist/nodes/ClaudeCode/descriptions/modelDescription.js.map +1 -0
- package/dist/nodes/ClaudeCode/descriptions/operationDescription.d.ts +3 -0
- package/dist/nodes/ClaudeCode/descriptions/operationDescription.d.ts.map +1 -0
- package/dist/nodes/ClaudeCode/descriptions/operationDescription.js +39 -0
- package/dist/nodes/ClaudeCode/descriptions/operationDescription.js.map +1 -0
- package/dist/nodes/ClaudeCode/descriptions/optionsDescription.d.ts +3 -0
- package/dist/nodes/ClaudeCode/descriptions/optionsDescription.d.ts.map +1 -0
- package/dist/nodes/ClaudeCode/descriptions/optionsDescription.js +67 -0
- package/dist/nodes/ClaudeCode/descriptions/optionsDescription.js.map +1 -0
- package/dist/nodes/ClaudeCode/descriptions/promptDescription.d.ts +3 -0
- package/dist/nodes/ClaudeCode/descriptions/promptDescription.d.ts.map +1 -0
- package/dist/nodes/ClaudeCode/descriptions/promptDescription.js +28 -0
- package/dist/nodes/ClaudeCode/descriptions/promptDescription.js.map +1 -0
- package/dist/nodes/ClaudeCode/descriptions/sessionDescription.d.ts +3 -0
- package/dist/nodes/ClaudeCode/descriptions/sessionDescription.d.ts.map +1 -0
- package/dist/nodes/ClaudeCode/descriptions/sessionDescription.js +20 -0
- package/dist/nodes/ClaudeCode/descriptions/sessionDescription.js.map +1 -0
- package/dist/nodes/ClaudeCode/descriptions/toolPermissionsDescription.d.ts +3 -0
- package/dist/nodes/ClaudeCode/descriptions/toolPermissionsDescription.d.ts.map +1 -0
- package/dist/nodes/ClaudeCode/descriptions/toolPermissionsDescription.js +31 -0
- package/dist/nodes/ClaudeCode/descriptions/toolPermissionsDescription.js.map +1 -0
- package/dist/nodes/ClaudeCode/interfaces/ClaudeCodeTypes.d.ts +143 -0
- package/dist/nodes/ClaudeCode/interfaces/ClaudeCodeTypes.d.ts.map +1 -0
- package/dist/nodes/ClaudeCode/interfaces/ClaudeCodeTypes.js +3 -0
- package/dist/nodes/ClaudeCode/interfaces/ClaudeCodeTypes.js.map +1 -0
- package/dist/nodes/ClaudeCode/interfaces/index.d.ts +2 -0
- package/dist/nodes/ClaudeCode/interfaces/index.d.ts.map +1 -0
- package/dist/nodes/ClaudeCode/interfaces/index.js +3 -0
- package/dist/nodes/ClaudeCode/interfaces/index.js.map +1 -0
- package/dist/nodes/ClaudeCode/transport/DockerExecutor.d.ts +29 -0
- package/dist/nodes/ClaudeCode/transport/DockerExecutor.d.ts.map +1 -0
- package/dist/nodes/ClaudeCode/transport/DockerExecutor.js +153 -0
- package/dist/nodes/ClaudeCode/transport/DockerExecutor.js.map +1 -0
- package/dist/nodes/ClaudeCode/transport/ExecutorFactory.d.ts +6 -0
- package/dist/nodes/ClaudeCode/transport/ExecutorFactory.d.ts.map +1 -0
- package/dist/nodes/ClaudeCode/transport/ExecutorFactory.js +22 -0
- package/dist/nodes/ClaudeCode/transport/ExecutorFactory.js.map +1 -0
- package/dist/nodes/ClaudeCode/transport/LocalExecutor.d.ts +18 -0
- package/dist/nodes/ClaudeCode/transport/LocalExecutor.d.ts.map +1 -0
- package/dist/nodes/ClaudeCode/transport/LocalExecutor.js +83 -0
- package/dist/nodes/ClaudeCode/transport/LocalExecutor.js.map +1 -0
- package/dist/nodes/ClaudeCode/transport/SshExecutor.d.ts +25 -0
- package/dist/nodes/ClaudeCode/transport/SshExecutor.d.ts.map +1 -0
- package/dist/nodes/ClaudeCode/transport/SshExecutor.js +174 -0
- package/dist/nodes/ClaudeCode/transport/SshExecutor.js.map +1 -0
- package/dist/nodes/ClaudeCode/transport/index.d.ts +5 -0
- package/dist/nodes/ClaudeCode/transport/index.d.ts.map +1 -0
- package/dist/nodes/ClaudeCode/transport/index.js +12 -0
- package/dist/nodes/ClaudeCode/transport/index.js.map +1 -0
- package/dist/nodes/ClaudeCode/utils/commandBuilder.d.ts +16 -0
- package/dist/nodes/ClaudeCode/utils/commandBuilder.d.ts.map +1 -0
- package/dist/nodes/ClaudeCode/utils/commandBuilder.js +100 -0
- package/dist/nodes/ClaudeCode/utils/commandBuilder.js.map +1 -0
- package/dist/nodes/ClaudeCode/utils/index.d.ts +4 -0
- package/dist/nodes/ClaudeCode/utils/index.d.ts.map +1 -0
- package/dist/nodes/ClaudeCode/utils/index.js +14 -0
- package/dist/nodes/ClaudeCode/utils/index.js.map +1 -0
- package/dist/nodes/ClaudeCode/utils/optionsBuilder.d.ts +7 -0
- package/dist/nodes/ClaudeCode/utils/optionsBuilder.d.ts.map +1 -0
- package/dist/nodes/ClaudeCode/utils/optionsBuilder.js +84 -0
- package/dist/nodes/ClaudeCode/utils/optionsBuilder.js.map +1 -0
- package/dist/nodes/ClaudeCode/utils/outputParser.d.ts +14 -0
- package/dist/nodes/ClaudeCode/utils/outputParser.d.ts.map +1 -0
- package/dist/nodes/ClaudeCode/utils/outputParser.js +80 -0
- package/dist/nodes/ClaudeCode/utils/outputParser.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DockerExecutor = void 0;
|
|
4
|
+
const node_child_process_1 = require("node:child_process");
|
|
5
|
+
const index_js_1 = require("../utils/index.js");
|
|
6
|
+
/**
|
|
7
|
+
* Executor for Claude Code CLI execution via Docker exec
|
|
8
|
+
*/
|
|
9
|
+
class DockerExecutor {
|
|
10
|
+
credentials;
|
|
11
|
+
constructor(credentials) {
|
|
12
|
+
this.credentials = credentials;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Get the container reference (name or ID)
|
|
16
|
+
*/
|
|
17
|
+
getContainerRef() {
|
|
18
|
+
return this.credentials.containerIdentifier === "id"
|
|
19
|
+
? this.credentials.containerId || ""
|
|
20
|
+
: this.credentials.containerName || "";
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Build docker exec arguments
|
|
24
|
+
*/
|
|
25
|
+
buildDockerExecArgs(options) {
|
|
26
|
+
const args = ["exec"];
|
|
27
|
+
// Note: Don't use -i or -t flags for headless execution
|
|
28
|
+
// Claude Code with -p flag works without interactive input
|
|
29
|
+
// User to run as
|
|
30
|
+
if (this.credentials.user) {
|
|
31
|
+
args.push("-u", this.credentials.user);
|
|
32
|
+
}
|
|
33
|
+
// Working directory inside container
|
|
34
|
+
const workDir = options.workingDirectory || this.credentials.defaultWorkingDir;
|
|
35
|
+
if (workDir) {
|
|
36
|
+
args.push("-w", workDir);
|
|
37
|
+
}
|
|
38
|
+
// Container reference
|
|
39
|
+
args.push(this.getContainerRef());
|
|
40
|
+
return args;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get environment for docker command
|
|
44
|
+
*/
|
|
45
|
+
getDockerEnv() {
|
|
46
|
+
if (this.credentials.dockerHost) {
|
|
47
|
+
return { ...process.env, DOCKER_HOST: this.credentials.dockerHost };
|
|
48
|
+
}
|
|
49
|
+
return process.env;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Execute a Claude Code command via Docker exec
|
|
53
|
+
*/
|
|
54
|
+
execute(options) {
|
|
55
|
+
return new Promise((resolve) => {
|
|
56
|
+
const startTime = Date.now();
|
|
57
|
+
const dockerArgs = this.buildDockerExecArgs(options);
|
|
58
|
+
const { command: claudePath, args: claudeArgs } = (0, index_js_1.buildCommand)(options, this.credentials);
|
|
59
|
+
// Add Claude Code command and args
|
|
60
|
+
dockerArgs.push(claudePath, ...claudeArgs);
|
|
61
|
+
const timeoutMs = options.timeout ? options.timeout * 1000 : 300000;
|
|
62
|
+
let stdout = "";
|
|
63
|
+
let stderr = "";
|
|
64
|
+
let killed = false;
|
|
65
|
+
let resolved = false;
|
|
66
|
+
const proc = (0, node_child_process_1.spawn)("docker", dockerArgs, {
|
|
67
|
+
env: this.getDockerEnv(),
|
|
68
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
69
|
+
});
|
|
70
|
+
// Manual timeout handling
|
|
71
|
+
const timeoutHandle = setTimeout(() => {
|
|
72
|
+
if (!resolved) {
|
|
73
|
+
killed = true;
|
|
74
|
+
proc.kill("SIGTERM");
|
|
75
|
+
// Force kill after 5 seconds if SIGTERM doesn't work
|
|
76
|
+
setTimeout(() => {
|
|
77
|
+
if (!resolved) {
|
|
78
|
+
proc.kill("SIGKILL");
|
|
79
|
+
}
|
|
80
|
+
}, 5000);
|
|
81
|
+
}
|
|
82
|
+
}, timeoutMs);
|
|
83
|
+
proc.stdout.on("data", (data) => {
|
|
84
|
+
stdout += data.toString();
|
|
85
|
+
});
|
|
86
|
+
proc.stderr.on("data", (data) => {
|
|
87
|
+
stderr += data.toString();
|
|
88
|
+
});
|
|
89
|
+
proc.on("close", (code) => {
|
|
90
|
+
clearTimeout(timeoutHandle);
|
|
91
|
+
if (resolved)
|
|
92
|
+
return;
|
|
93
|
+
resolved = true;
|
|
94
|
+
const duration = Date.now() - startTime;
|
|
95
|
+
// Check if process was killed due to timeout
|
|
96
|
+
if (killed) {
|
|
97
|
+
resolve((0, index_js_1.createErrorResult)(`Execution timed out after ${options.timeout} seconds`, 124, duration));
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const exitCode = code ?? 0;
|
|
101
|
+
if (options.outputFormat === "json") {
|
|
102
|
+
const parsed = (0, index_js_1.parseJsonOutput)(stdout);
|
|
103
|
+
resolve((0, index_js_1.normalizeOutput)(parsed, exitCode, duration, stderr));
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
resolve({
|
|
107
|
+
success: exitCode === 0,
|
|
108
|
+
sessionId: "",
|
|
109
|
+
output: stdout,
|
|
110
|
+
exitCode,
|
|
111
|
+
duration,
|
|
112
|
+
error: exitCode !== 0 ? stderr : undefined,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
proc.on("error", (error) => {
|
|
117
|
+
clearTimeout(timeoutHandle);
|
|
118
|
+
if (resolved)
|
|
119
|
+
return;
|
|
120
|
+
resolved = true;
|
|
121
|
+
const duration = Date.now() - startTime;
|
|
122
|
+
resolve((0, index_js_1.createErrorResult)(`Docker exec failed: ${error.message}`, 1, duration));
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Test Docker connection and Claude Code availability
|
|
128
|
+
*/
|
|
129
|
+
testConnection() {
|
|
130
|
+
return new Promise((resolve) => {
|
|
131
|
+
const containerRef = this.getContainerRef();
|
|
132
|
+
if (!containerRef) {
|
|
133
|
+
resolve(false);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const claudePath = this.credentials.claudePath || "claude";
|
|
137
|
+
const args = ["exec", containerRef, claudePath, "--version"];
|
|
138
|
+
const proc = (0, node_child_process_1.spawn)("docker", args, {
|
|
139
|
+
env: this.getDockerEnv(),
|
|
140
|
+
timeout: 10000,
|
|
141
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
142
|
+
});
|
|
143
|
+
proc.on("close", (code) => {
|
|
144
|
+
resolve(code === 0);
|
|
145
|
+
});
|
|
146
|
+
proc.on("error", () => {
|
|
147
|
+
resolve(false);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
exports.DockerExecutor = DockerExecutor;
|
|
153
|
+
//# sourceMappingURL=DockerExecutor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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AAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAmB,EAAE,EAAE;gBACxC,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC;YACrB,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;gBACrB,OAAO,CAAC,KAAK,CAAC,CAAC;YAChB,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACJ,CAAC;CACD;AAvLD,wCAuLC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ConnectionMode, IClaudeCodeExecutor } from "../interfaces/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Create an executor for the specified connection mode
|
|
4
|
+
*/
|
|
5
|
+
export declare function createExecutor(mode: ConnectionMode, credentials: unknown): IClaudeCodeExecutor;
|
|
6
|
+
//# sourceMappingURL=ExecutorFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExecutorFactory.d.ts","sourceRoot":"","sources":["../../../../nodes/ClaudeCode/transport/ExecutorFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,cAAc,EACd,mBAAmB,EACnB,MAAM,wBAAwB,CAAC;AAKhC;;GAEG;AACH,wBAAgB,cAAc,CAC7B,IAAI,EAAE,cAAc,EACpB,WAAW,EAAE,OAAO,GAClB,mBAAmB,CAWrB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createExecutor = createExecutor;
|
|
4
|
+
const LocalExecutor_js_1 = require("./LocalExecutor.js");
|
|
5
|
+
const SshExecutor_js_1 = require("./SshExecutor.js");
|
|
6
|
+
const DockerExecutor_js_1 = require("./DockerExecutor.js");
|
|
7
|
+
/**
|
|
8
|
+
* Create an executor for the specified connection mode
|
|
9
|
+
*/
|
|
10
|
+
function createExecutor(mode, credentials) {
|
|
11
|
+
switch (mode) {
|
|
12
|
+
case "local":
|
|
13
|
+
return new LocalExecutor_js_1.LocalExecutor(credentials);
|
|
14
|
+
case "ssh":
|
|
15
|
+
return new SshExecutor_js_1.SshExecutor(credentials);
|
|
16
|
+
case "docker":
|
|
17
|
+
return new DockerExecutor_js_1.DockerExecutor(credentials);
|
|
18
|
+
default:
|
|
19
|
+
throw new Error(`Unsupported connection mode: ${mode}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=ExecutorFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExecutorFactory.js","sourceRoot":"","sources":["../../../../nodes/ClaudeCode/transport/ExecutorFactory.ts"],"names":[],"mappings":";;AAWA,wCAcC;AArBD,yDAAmD;AACnD,qDAA+C;AAC/C,2DAAqD;AAErD;;GAEG;AACH,SAAgB,cAAc,CAC7B,IAAoB,EACpB,WAAoB;IAEpB,QAAQ,IAAI,EAAE,CAAC;QACd,KAAK,OAAO;YACX,OAAO,IAAI,gCAAa,CAAC,WAAW,CAAC,CAAC;QACvC,KAAK,KAAK;YACT,OAAO,IAAI,4BAAW,CAAC,WAAW,CAAC,CAAC;QACrC,KAAK,QAAQ;YACZ,OAAO,IAAI,kCAAc,CAAC,WAAW,CAAC,CAAC;QACxC;YACC,MAAM,IAAI,KAAK,CAAC,gCAAgC,IAAI,EAAE,CAAC,CAAC;IAC1D,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { IClaudeCodeExecutor, ClaudeCodeExecutionOptions, ClaudeCodeResult } from "../interfaces/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Executor for local Claude Code CLI execution
|
|
4
|
+
* Uses child_process.spawn to run Claude Code on the same machine as n8n
|
|
5
|
+
*/
|
|
6
|
+
export declare class LocalExecutor implements IClaudeCodeExecutor {
|
|
7
|
+
private credentials;
|
|
8
|
+
constructor(credentials: unknown);
|
|
9
|
+
/**
|
|
10
|
+
* Execute a Claude Code command and wait for the result
|
|
11
|
+
*/
|
|
12
|
+
execute(options: ClaudeCodeExecutionOptions): Promise<ClaudeCodeResult>;
|
|
13
|
+
/**
|
|
14
|
+
* Test if Claude Code is accessible
|
|
15
|
+
*/
|
|
16
|
+
testConnection(): Promise<boolean>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=LocalExecutor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalExecutor.d.ts","sourceRoot":"","sources":["../../../../nodes/ClaudeCode/transport/LocalExecutor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,mBAAmB,EACnB,0BAA0B,EAC1B,gBAAgB,EAEhB,MAAM,wBAAwB,CAAC;AAQhC;;;GAGG;AACH,qBAAa,aAAc,YAAW,mBAAmB;IACxD,OAAO,CAAC,WAAW,CAAmB;gBAE1B,WAAW,EAAE,OAAO;IAIhC;;OAEG;IACH,OAAO,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA8DvE;;OAEG;IACH,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;CAkBlC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LocalExecutor = void 0;
|
|
4
|
+
const node_child_process_1 = require("node:child_process");
|
|
5
|
+
const index_js_1 = require("../utils/index.js");
|
|
6
|
+
/**
|
|
7
|
+
* Executor for local Claude Code CLI execution
|
|
8
|
+
* Uses child_process.spawn to run Claude Code on the same machine as n8n
|
|
9
|
+
*/
|
|
10
|
+
class LocalExecutor {
|
|
11
|
+
credentials;
|
|
12
|
+
constructor(credentials) {
|
|
13
|
+
this.credentials = credentials;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Execute a Claude Code command and wait for the result
|
|
17
|
+
*/
|
|
18
|
+
execute(options) {
|
|
19
|
+
return new Promise((resolve) => {
|
|
20
|
+
const { command, args, env, cwd } = (0, index_js_1.buildCommand)(options, this.credentials);
|
|
21
|
+
const startTime = Date.now();
|
|
22
|
+
let stdout = "";
|
|
23
|
+
let stderr = "";
|
|
24
|
+
const timeoutMs = options.timeout ? options.timeout * 1000 : 300000;
|
|
25
|
+
const proc = (0, node_child_process_1.spawn)(command, args, {
|
|
26
|
+
cwd: cwd || process.cwd(),
|
|
27
|
+
env: { ...process.env, ...env },
|
|
28
|
+
timeout: timeoutMs,
|
|
29
|
+
shell: false,
|
|
30
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
31
|
+
});
|
|
32
|
+
proc.stdout.on("data", (data) => {
|
|
33
|
+
stdout += data.toString();
|
|
34
|
+
});
|
|
35
|
+
proc.stderr.on("data", (data) => {
|
|
36
|
+
stderr += data.toString();
|
|
37
|
+
});
|
|
38
|
+
proc.on("close", (code) => {
|
|
39
|
+
const duration = Date.now() - startTime;
|
|
40
|
+
const exitCode = code ?? 0;
|
|
41
|
+
if (options.outputFormat === "json") {
|
|
42
|
+
const parsed = (0, index_js_1.parseJsonOutput)(stdout);
|
|
43
|
+
resolve((0, index_js_1.normalizeOutput)(parsed, exitCode, duration, stderr));
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
// Text format
|
|
47
|
+
resolve({
|
|
48
|
+
success: exitCode === 0,
|
|
49
|
+
sessionId: "",
|
|
50
|
+
output: stdout,
|
|
51
|
+
exitCode,
|
|
52
|
+
duration,
|
|
53
|
+
error: exitCode !== 0 ? stderr : undefined,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
proc.on("error", (error) => {
|
|
58
|
+
const duration = Date.now() - startTime;
|
|
59
|
+
resolve((0, index_js_1.createErrorResult)(`Failed to execute Claude Code: ${error.message}`, 1, duration));
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Test if Claude Code is accessible
|
|
65
|
+
*/
|
|
66
|
+
testConnection() {
|
|
67
|
+
return new Promise((resolve) => {
|
|
68
|
+
const claudePath = this.credentials.claudePath || "claude";
|
|
69
|
+
const proc = (0, node_child_process_1.spawn)(claudePath, ["--version"], {
|
|
70
|
+
timeout: 10000,
|
|
71
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
72
|
+
});
|
|
73
|
+
proc.on("close", (code) => {
|
|
74
|
+
resolve(code === 0);
|
|
75
|
+
});
|
|
76
|
+
proc.on("error", () => {
|
|
77
|
+
resolve(false);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.LocalExecutor = LocalExecutor;
|
|
83
|
+
//# sourceMappingURL=LocalExecutor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalExecutor.js","sourceRoot":"","sources":["../../../../nodes/ClaudeCode/transport/LocalExecutor.ts"],"names":[],"mappings":";;;AAAA,2DAA2C;AAO3C,gDAK2B;AAE3B;;;GAGG;AACH,MAAa,aAAa;IACjB,WAAW,CAAmB;IAEtC,YAAY,WAAoB;QAC/B,IAAI,CAAC,WAAW,GAAG,WAA+B,CAAC;IACpD,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,OAAmC;QAC1C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC9B,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAA,uBAAY,EAC/C,OAAO,EACP,IAAI,CAAC,WAAW,CAChB,CAAC;YAEF,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAC7B,IAAI,MAAM,GAAG,EAAE,CAAC;YAChB,IAAI,MAAM,GAAG,EAAE,CAAC;YAEhB,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;YAEpE,MAAM,IAAI,GAAG,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,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;qBAC1C,CAAC,CAAC;gBACJ,CAAC;YACF,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAY,EAAE,EAAE;gBACjC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;gBACxC,OAAO,CACN,IAAA,4BAAiB,EAChB,kCAAkC,KAAK,CAAC,OAAO,EAAE,EACjD,CAAC,EACD,QAAQ,CACR,CACD,CAAC;YACH,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,cAAc;QACb,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC9B,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,UAAU,IAAI,QAAQ,CAAC;YAE3D,MAAM,IAAI,GAAG,IAAA,0BAAK,EAAC,UAAU,EAAE,CAAC,WAAW,CAAC,EAAE;gBAC7C,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;aACjC,CAAC,CAAC;YAEH,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAmB,EAAE,EAAE;gBACxC,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC;YACrB,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;gBACrB,OAAO,CAAC,KAAK,CAAC,CAAC;YAChB,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACJ,CAAC;CACD;AA7FD,sCA6FC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { IClaudeCodeExecutor, ClaudeCodeExecutionOptions, ClaudeCodeResult } from "../interfaces/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Executor for remote Claude Code CLI execution via SSH
|
|
4
|
+
*/
|
|
5
|
+
export declare class SshExecutor implements IClaudeCodeExecutor {
|
|
6
|
+
private credentials;
|
|
7
|
+
constructor(credentials: unknown);
|
|
8
|
+
/**
|
|
9
|
+
* Build SSH connection configuration
|
|
10
|
+
*/
|
|
11
|
+
private buildSshConfig;
|
|
12
|
+
/**
|
|
13
|
+
* Build the remote command to execute
|
|
14
|
+
*/
|
|
15
|
+
private buildRemoteCommand;
|
|
16
|
+
/**
|
|
17
|
+
* Execute a Claude Code command via SSH
|
|
18
|
+
*/
|
|
19
|
+
execute(options: ClaudeCodeExecutionOptions): Promise<ClaudeCodeResult>;
|
|
20
|
+
/**
|
|
21
|
+
* Test SSH connection and Claude Code availability
|
|
22
|
+
*/
|
|
23
|
+
testConnection(): Promise<boolean>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=SshExecutor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SshExecutor.d.ts","sourceRoot":"","sources":["../../../../nodes/ClaudeCode/transport/SshExecutor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACX,mBAAmB,EACnB,0BAA0B,EAC1B,gBAAgB,EAEhB,MAAM,wBAAwB,CAAC;AAShC;;GAEG;AACH,qBAAa,WAAY,YAAW,mBAAmB;IACtD,OAAO,CAAC,WAAW,CAAiB;gBAExB,WAAW,EAAE,OAAO;IAIhC;;OAEG;IACH,OAAO,CAAC,cAAc;IA8BtB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAK1B;;OAEG;IACH,OAAO,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA0FvE;;OAEG;IACH,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;CAiDlC"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SshExecutor = void 0;
|
|
4
|
+
const ssh2_1 = require("ssh2");
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
6
|
+
const node_os_1 = require("node:os");
|
|
7
|
+
const index_js_1 = require("../utils/index.js");
|
|
8
|
+
/**
|
|
9
|
+
* Executor for remote Claude Code CLI execution via SSH
|
|
10
|
+
*/
|
|
11
|
+
class SshExecutor {
|
|
12
|
+
credentials;
|
|
13
|
+
constructor(credentials) {
|
|
14
|
+
this.credentials = credentials;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Build SSH connection configuration
|
|
18
|
+
*/
|
|
19
|
+
buildSshConfig() {
|
|
20
|
+
const config = {
|
|
21
|
+
host: this.credentials.host,
|
|
22
|
+
port: this.credentials.port || 22,
|
|
23
|
+
username: this.credentials.username,
|
|
24
|
+
};
|
|
25
|
+
if (this.credentials.authMethod === "password") {
|
|
26
|
+
config.password = this.credentials.password;
|
|
27
|
+
}
|
|
28
|
+
else if (this.credentials.authMethod === "privateKey") {
|
|
29
|
+
if (this.credentials.privateKey) {
|
|
30
|
+
config.privateKey = this.credentials.privateKey;
|
|
31
|
+
}
|
|
32
|
+
else if (this.credentials.privateKeyPath) {
|
|
33
|
+
// Expand ~ to home directory
|
|
34
|
+
const keyPath = this.credentials.privateKeyPath.replace(/^~/, (0, node_os_1.homedir)());
|
|
35
|
+
config.privateKey = (0, node_fs_1.readFileSync)(keyPath);
|
|
36
|
+
}
|
|
37
|
+
if (this.credentials.passphrase) {
|
|
38
|
+
config.passphrase = this.credentials.passphrase;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// For 'agent' method, ssh2 will automatically use the SSH agent
|
|
42
|
+
return config;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Build the remote command to execute
|
|
46
|
+
*/
|
|
47
|
+
buildRemoteCommand(options) {
|
|
48
|
+
const commandParts = (0, index_js_1.buildCommand)(options, this.credentials);
|
|
49
|
+
return (0, index_js_1.buildShellCommand)(commandParts);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Execute a Claude Code command via SSH
|
|
53
|
+
*/
|
|
54
|
+
execute(options) {
|
|
55
|
+
return new Promise((resolve) => {
|
|
56
|
+
const startTime = Date.now();
|
|
57
|
+
const remoteCmd = this.buildRemoteCommand(options);
|
|
58
|
+
const sshConfig = this.buildSshConfig();
|
|
59
|
+
const timeoutMs = options.timeout ? options.timeout * 1000 : 300000;
|
|
60
|
+
let stdout = "";
|
|
61
|
+
let stderr = "";
|
|
62
|
+
let connectionClosed = false;
|
|
63
|
+
const conn = new ssh2_1.Client();
|
|
64
|
+
// Set connection timeout
|
|
65
|
+
const connectionTimeout = setTimeout(() => {
|
|
66
|
+
if (!connectionClosed) {
|
|
67
|
+
connectionClosed = true;
|
|
68
|
+
conn.end();
|
|
69
|
+
const duration = Date.now() - startTime;
|
|
70
|
+
resolve((0, index_js_1.createErrorResult)("SSH connection timeout", 1, duration));
|
|
71
|
+
}
|
|
72
|
+
}, timeoutMs);
|
|
73
|
+
conn.on("ready", () => {
|
|
74
|
+
conn.exec(remoteCmd, (err, stream) => {
|
|
75
|
+
if (err) {
|
|
76
|
+
clearTimeout(connectionTimeout);
|
|
77
|
+
connectionClosed = true;
|
|
78
|
+
conn.end();
|
|
79
|
+
const duration = Date.now() - startTime;
|
|
80
|
+
resolve((0, index_js_1.createErrorResult)(`SSH exec error: ${err.message}`, 1, duration));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
stream.on("close", (code) => {
|
|
84
|
+
clearTimeout(connectionTimeout);
|
|
85
|
+
if (!connectionClosed) {
|
|
86
|
+
connectionClosed = true;
|
|
87
|
+
conn.end();
|
|
88
|
+
const duration = Date.now() - startTime;
|
|
89
|
+
const exitCode = code ?? 0;
|
|
90
|
+
if (options.outputFormat === "json") {
|
|
91
|
+
const parsed = (0, index_js_1.parseJsonOutput)(stdout);
|
|
92
|
+
resolve((0, index_js_1.normalizeOutput)(parsed, exitCode, duration, stderr));
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
resolve({
|
|
96
|
+
success: exitCode === 0,
|
|
97
|
+
sessionId: "",
|
|
98
|
+
output: stdout,
|
|
99
|
+
exitCode,
|
|
100
|
+
duration,
|
|
101
|
+
error: exitCode !== 0 ? stderr : undefined,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
stream.on("data", (data) => {
|
|
107
|
+
stdout += data.toString();
|
|
108
|
+
});
|
|
109
|
+
stream.stderr.on("data", (data) => {
|
|
110
|
+
stderr += data.toString();
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
conn.on("error", (err) => {
|
|
115
|
+
clearTimeout(connectionTimeout);
|
|
116
|
+
if (!connectionClosed) {
|
|
117
|
+
connectionClosed = true;
|
|
118
|
+
const duration = Date.now() - startTime;
|
|
119
|
+
resolve((0, index_js_1.createErrorResult)(`SSH connection error: ${err.message}`, 1, duration));
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
conn.connect(sshConfig);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Test SSH connection and Claude Code availability
|
|
127
|
+
*/
|
|
128
|
+
testConnection() {
|
|
129
|
+
return new Promise((resolve) => {
|
|
130
|
+
const sshConfig = this.buildSshConfig();
|
|
131
|
+
const conn = new ssh2_1.Client();
|
|
132
|
+
let resolved = false;
|
|
133
|
+
const timeout = setTimeout(() => {
|
|
134
|
+
if (!resolved) {
|
|
135
|
+
resolved = true;
|
|
136
|
+
conn.end();
|
|
137
|
+
resolve(false);
|
|
138
|
+
}
|
|
139
|
+
}, 10000);
|
|
140
|
+
conn.on("ready", () => {
|
|
141
|
+
const claudePath = this.credentials.claudePath || "claude";
|
|
142
|
+
conn.exec(`${claudePath} --version`, (err, stream) => {
|
|
143
|
+
if (err) {
|
|
144
|
+
clearTimeout(timeout);
|
|
145
|
+
if (!resolved) {
|
|
146
|
+
resolved = true;
|
|
147
|
+
conn.end();
|
|
148
|
+
resolve(false);
|
|
149
|
+
}
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
stream.on("close", (code) => {
|
|
153
|
+
clearTimeout(timeout);
|
|
154
|
+
if (!resolved) {
|
|
155
|
+
resolved = true;
|
|
156
|
+
conn.end();
|
|
157
|
+
resolve(code === 0);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
conn.on("error", () => {
|
|
163
|
+
clearTimeout(timeout);
|
|
164
|
+
if (!resolved) {
|
|
165
|
+
resolved = true;
|
|
166
|
+
resolve(false);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
conn.connect(sshConfig);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
exports.SshExecutor = SshExecutor;
|
|
174
|
+
//# sourceMappingURL=SshExecutor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SshExecutor.js","sourceRoot":"","sources":["../../../../nodes/ClaudeCode/transport/SshExecutor.ts"],"names":[],"mappings":";;;AAAA,+BAAkD;AAClD,qCAAuC;AACvC,qCAAkC;AAOlC,gDAM2B;AAE3B;;GAEG;AACH,MAAa,WAAW;IACf,WAAW,CAAiB;IAEpC,YAAY,WAAoB;QAC/B,IAAI,CAAC,WAAW,GAAG,WAA6B,CAAC;IAClD,CAAC;IAED;;OAEG;IACK,cAAc;QACrB,MAAM,MAAM,GAAkB;YAC7B,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI;YAC3B,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,EAAE;YACjC,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,QAAQ;SACnC,CAAC;QAEF,IAAI,IAAI,CAAC,WAAW,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;YAChD,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;QAC7C,CAAC;aAAM,IAAI,IAA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AY,EAAE,EAAE;wBACnC,YAAY,CAAC,OAAO,CAAC,CAAC;wBACtB,IAAI,CAAC,QAAQ,EAAE,CAAC;4BACf,QAAQ,GAAG,IAAI,CAAC;4BAChB,IAAI,CAAC,GAAG,EAAE,CAAC;4BACX,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC;wBACrB,CAAC;oBACF,CAAC,CAAC,CAAC;gBACJ,CAAC,CAAC,CAAC;YACJ,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;gBACrB,YAAY,CAAC,OAAO,CAAC,CAAC;gBACtB,IAAI,CAAC,QAAQ,EAAE,CAAC;oBACf,QAAQ,GAAG,IAAI,CAAC;oBAChB,OAAO,CAAC,KAAK,CAAC,CAAC;gBAChB,CAAC;YACF,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;IACJ,CAAC;CACD;AAjMD,kCAiMC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../nodes/ClaudeCode/transport/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DockerExecutor = exports.SshExecutor = exports.LocalExecutor = exports.createExecutor = void 0;
|
|
4
|
+
var ExecutorFactory_js_1 = require("./ExecutorFactory.js");
|
|
5
|
+
Object.defineProperty(exports, "createExecutor", { enumerable: true, get: function () { return ExecutorFactory_js_1.createExecutor; } });
|
|
6
|
+
var LocalExecutor_js_1 = require("./LocalExecutor.js");
|
|
7
|
+
Object.defineProperty(exports, "LocalExecutor", { enumerable: true, get: function () { return LocalExecutor_js_1.LocalExecutor; } });
|
|
8
|
+
var SshExecutor_js_1 = require("./SshExecutor.js");
|
|
9
|
+
Object.defineProperty(exports, "SshExecutor", { enumerable: true, get: function () { return SshExecutor_js_1.SshExecutor; } });
|
|
10
|
+
var DockerExecutor_js_1 = require("./DockerExecutor.js");
|
|
11
|
+
Object.defineProperty(exports, "DockerExecutor", { enumerable: true, get: function () { return DockerExecutor_js_1.DockerExecutor; } });
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../nodes/ClaudeCode/transport/index.ts"],"names":[],"mappings":";;;AAAA,2DAAsD;AAA7C,oHAAA,cAAc,OAAA;AACvB,uDAAmD;AAA1C,iHAAA,aAAa,OAAA;AACtB,mDAA+C;AAAtC,6GAAA,WAAW,OAAA;AACpB,yDAAqD;AAA5C,mHAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ClaudeCodeExecutionOptions, CommandParts, LocalCredentials, SshCredentials, DockerCredentials } from "../interfaces/index.js";
|
|
2
|
+
type AnyCredentials = LocalCredentials | SshCredentials | DockerCredentials;
|
|
3
|
+
/**
|
|
4
|
+
* Builds the Claude Code CLI command parts from execution options
|
|
5
|
+
*/
|
|
6
|
+
export declare function buildCommand(options: ClaudeCodeExecutionOptions, credentials: AnyCredentials): CommandParts;
|
|
7
|
+
/**
|
|
8
|
+
* Escapes a shell argument for safe use in SSH/Docker exec commands
|
|
9
|
+
*/
|
|
10
|
+
export declare function escapeShellArg(arg: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Builds a complete shell command string from parts
|
|
13
|
+
*/
|
|
14
|
+
export declare function buildShellCommand(parts: CommandParts): string;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=commandBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandBuilder.d.ts","sourceRoot":"","sources":["../../../../nodes/ClaudeCode/utils/commandBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,0BAA0B,EAC1B,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,MAAM,wBAAwB,CAAC;AAEhC,KAAK,cAAc,GAAG,gBAAgB,GAAG,cAAc,GAAG,iBAAiB,CAAC;AAE5E;;GAEG;AACH,wBAAgB,YAAY,CAC3B,OAAO,EAAE,0BAA0B,EACnC,WAAW,EAAE,cAAc,GACzB,YAAY,CA0Fd;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGlD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAW7D"}
|