@agentteams/runner 0.0.46
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/api-client.d.ts +22 -0
- package/dist/api-client.js +201 -0
- package/dist/api-client.js.map +1 -0
- package/dist/api-client.test.d.ts +1 -0
- package/dist/api-client.test.js +118 -0
- package/dist/api-client.test.js.map +1 -0
- package/dist/autostart.d.ts +19 -0
- package/dist/autostart.js +359 -0
- package/dist/autostart.js.map +1 -0
- package/dist/autostart.test.d.ts +1 -0
- package/dist/autostart.test.js +42 -0
- package/dist/autostart.test.js.map +1 -0
- package/dist/commands/cleanup.d.ts +1 -0
- package/dist/commands/cleanup.js +12 -0
- package/dist/commands/cleanup.js.map +1 -0
- package/dist/commands/init.d.ts +1 -0
- package/dist/commands/init.js +57 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/restart.d.ts +1 -0
- package/dist/commands/restart.js +7 -0
- package/dist/commands/restart.js.map +1 -0
- package/dist/commands/start.d.ts +1 -0
- package/dist/commands/start.js +34 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/commands/status.d.ts +1 -0
- package/dist/commands/status.js +20 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/stop.d.ts +1 -0
- package/dist/commands/stop.js +21 -0
- package/dist/commands/stop.js.map +1 -0
- package/dist/commands/uninstall.d.ts +1 -0
- package/dist/commands/uninstall.js +21 -0
- package/dist/commands/uninstall.js.map +1 -0
- package/dist/commands/update.d.ts +10 -0
- package/dist/commands/update.js +58 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/commands/update.test.d.ts +1 -0
- package/dist/commands/update.test.js +104 -0
- package/dist/commands/update.test.js.map +1 -0
- package/dist/config.d.ts +6 -0
- package/dist/config.js +69 -0
- package/dist/config.js.map +1 -0
- package/dist/config.test.d.ts +1 -0
- package/dist/config.test.js +133 -0
- package/dist/config.test.js.map +1 -0
- package/dist/daemon-control.d.ts +21 -0
- package/dist/daemon-control.js +58 -0
- package/dist/daemon-control.js.map +1 -0
- package/dist/daemon-control.test.d.ts +1 -0
- package/dist/daemon-control.test.js +48 -0
- package/dist/daemon-control.test.js.map +1 -0
- package/dist/executable.d.ts +25 -0
- package/dist/executable.js +141 -0
- package/dist/executable.js.map +1 -0
- package/dist/executable.test.d.ts +1 -0
- package/dist/executable.test.js +57 -0
- package/dist/executable.test.js.map +1 -0
- package/dist/handlers/trigger-handler.d.ts +25 -0
- package/dist/handlers/trigger-handler.js +308 -0
- package/dist/handlers/trigger-handler.js.map +1 -0
- package/dist/handlers/trigger-handler.test.d.ts +1 -0
- package/dist/handlers/trigger-handler.test.js +496 -0
- package/dist/handlers/trigger-handler.test.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +82 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +5 -0
- package/dist/logger.js +25 -0
- package/dist/logger.js.map +1 -0
- package/dist/pid.d.ts +8 -0
- package/dist/pid.js +49 -0
- package/dist/pid.js.map +1 -0
- package/dist/poller.d.ts +20 -0
- package/dist/poller.js +214 -0
- package/dist/poller.js.map +1 -0
- package/dist/poller.test.d.ts +1 -0
- package/dist/poller.test.js +382 -0
- package/dist/poller.test.js.map +1 -0
- package/dist/runners/amp.d.ts +5 -0
- package/dist/runners/amp.js +316 -0
- package/dist/runners/amp.js.map +1 -0
- package/dist/runners/claude-code.d.ts +6 -0
- package/dist/runners/claude-code.js +340 -0
- package/dist/runners/claude-code.js.map +1 -0
- package/dist/runners/claude-code.test.d.ts +1 -0
- package/dist/runners/claude-code.test.js +39 -0
- package/dist/runners/claude-code.test.js.map +1 -0
- package/dist/runners/codex.d.ts +6 -0
- package/dist/runners/codex.js +324 -0
- package/dist/runners/codex.js.map +1 -0
- package/dist/runners/codex.test.d.ts +1 -0
- package/dist/runners/codex.test.js +66 -0
- package/dist/runners/codex.test.js.map +1 -0
- package/dist/runners/gemini.d.ts +5 -0
- package/dist/runners/gemini.js +304 -0
- package/dist/runners/gemini.js.map +1 -0
- package/dist/runners/gemini.test.d.ts +1 -0
- package/dist/runners/gemini.test.js +16 -0
- package/dist/runners/gemini.test.js.map +1 -0
- package/dist/runners/index.d.ts +2 -0
- package/dist/runners/index.js +27 -0
- package/dist/runners/index.js.map +1 -0
- package/dist/runners/index.test.d.ts +1 -0
- package/dist/runners/index.test.js +19 -0
- package/dist/runners/index.test.js.map +1 -0
- package/dist/runners/log-reporter.d.ts +18 -0
- package/dist/runners/log-reporter.js +127 -0
- package/dist/runners/log-reporter.js.map +1 -0
- package/dist/runners/log-reporter.test.d.ts +1 -0
- package/dist/runners/log-reporter.test.js +152 -0
- package/dist/runners/log-reporter.test.js.map +1 -0
- package/dist/runners/opencode.d.ts +6 -0
- package/dist/runners/opencode.js +304 -0
- package/dist/runners/opencode.js.map +1 -0
- package/dist/runners/stream-json-parser.d.ts +17 -0
- package/dist/runners/stream-json-parser.js +116 -0
- package/dist/runners/stream-json-parser.js.map +1 -0
- package/dist/runners/types.d.ts +26 -0
- package/dist/runners/types.js +2 -0
- package/dist/runners/types.js.map +1 -0
- package/dist/types.d.ts +69 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/auth-path-store.d.ts +3 -0
- package/dist/utils/auth-path-store.js +37 -0
- package/dist/utils/auth-path-store.js.map +1 -0
- package/dist/utils/auth-path-store.test.d.ts +1 -0
- package/dist/utils/auth-path-store.test.js +70 -0
- package/dist/utils/auth-path-store.test.js.map +1 -0
- package/dist/utils/convention-sync.d.ts +8 -0
- package/dist/utils/convention-sync.js +41 -0
- package/dist/utils/convention-sync.js.map +1 -0
- package/dist/utils/convention-sync.test.d.ts +1 -0
- package/dist/utils/convention-sync.test.js +75 -0
- package/dist/utils/convention-sync.test.js.map +1 -0
- package/dist/utils/git-worktree.d.ts +9 -0
- package/dist/utils/git-worktree.js +150 -0
- package/dist/utils/git-worktree.js.map +1 -0
- package/dist/utils/git-worktree.test.d.ts +1 -0
- package/dist/utils/git-worktree.test.js +294 -0
- package/dist/utils/git-worktree.test.js.map +1 -0
- package/dist/utils/origin-issue-safeguard.d.ts +16 -0
- package/dist/utils/origin-issue-safeguard.js +198 -0
- package/dist/utils/origin-issue-safeguard.js.map +1 -0
- package/dist/utils/runner-cleanup.d.ts +10 -0
- package/dist/utils/runner-cleanup.js +59 -0
- package/dist/utils/runner-cleanup.js.map +1 -0
- package/dist/utils/runner-cleanup.test.d.ts +1 -0
- package/dist/utils/runner-cleanup.test.js +93 -0
- package/dist/utils/runner-cleanup.test.js.map +1 -0
- package/dist/utils/runner-history.d.ts +6 -0
- package/dist/utils/runner-history.js +13 -0
- package/dist/utils/runner-history.js.map +1 -0
- package/dist/utils/runner-history.test.d.ts +1 -0
- package/dist/utils/runner-history.test.js +25 -0
- package/dist/utils/runner-history.test.js.map +1 -0
- package/package.json +50 -0
- package/readme.md +188 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { createWriteStream } from "node:fs";
|
|
2
|
+
import { execFileSync, spawn } from "node:child_process";
|
|
3
|
+
import { mkdir } from "node:fs/promises";
|
|
4
|
+
import { platform } from "node:os";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
|
+
import { describeExecutableResolution, resolveExecutablePathWithPreference, spawnExecutable } from "../executable.js";
|
|
7
|
+
import { logger } from "../logger.js";
|
|
8
|
+
import { extractResultTextFromStreamJson } from "./claude-code.js";
|
|
9
|
+
import { createStreamJsonLineParser } from "./stream-json-parser.js";
|
|
10
|
+
const FORCE_KILL_AFTER_MS = 10_000;
|
|
11
|
+
const PROMPT_PREVIEW_MAX = 500;
|
|
12
|
+
const OUTPUT_PREVIEW_MAX = 400;
|
|
13
|
+
const OUTPUT_CAPTURE_MAX = 200_000;
|
|
14
|
+
export const buildAmpExecArgs = (prompt, model) => {
|
|
15
|
+
const modeArgs = model ? ["--mode", model] : [];
|
|
16
|
+
return ["--execute", prompt, "--dangerously-allow-all", "--stream-json-thinking", ...modeArgs];
|
|
17
|
+
};
|
|
18
|
+
const toPowerShellEncodedCommand = (resolvedExecutablePath, prompt, model) => {
|
|
19
|
+
const modelSegment = model ? ` '--mode' '${model.replaceAll("'", "''")}'` : "";
|
|
20
|
+
const scriptContent = [
|
|
21
|
+
"$ErrorActionPreference = 'Stop'",
|
|
22
|
+
"$utf8NoBom = [System.Text.UTF8Encoding]::new($false)",
|
|
23
|
+
"[Console]::InputEncoding = $utf8NoBom",
|
|
24
|
+
"[Console]::OutputEncoding = $utf8NoBom",
|
|
25
|
+
"$OutputEncoding = $utf8NoBom",
|
|
26
|
+
"chcp 65001 > $null",
|
|
27
|
+
`$promptText = @'`,
|
|
28
|
+
`${prompt.replaceAll("'@", "'@")}`,
|
|
29
|
+
`'@`,
|
|
30
|
+
`& '${resolvedExecutablePath.replaceAll("'", "''")}' '--execute' $promptText '--dangerously-allow-all' '--stream-json-thinking'${modelSegment}`
|
|
31
|
+
].join("\r\n");
|
|
32
|
+
return Buffer.from(scriptContent, "utf16le").toString("base64");
|
|
33
|
+
};
|
|
34
|
+
const toPromptPreview = (prompt) => {
|
|
35
|
+
if (prompt.length <= PROMPT_PREVIEW_MAX) {
|
|
36
|
+
return prompt;
|
|
37
|
+
}
|
|
38
|
+
return `${prompt.slice(0, PROMPT_PREVIEW_MAX)}...`;
|
|
39
|
+
};
|
|
40
|
+
const toOutputPreview = (chunk) => {
|
|
41
|
+
const text = (typeof chunk === "string" ? chunk : String(chunk)).trim();
|
|
42
|
+
if (text.length <= OUTPUT_PREVIEW_MAX) {
|
|
43
|
+
return text;
|
|
44
|
+
}
|
|
45
|
+
return `${text.slice(0, OUTPUT_PREVIEW_MAX)}...`;
|
|
46
|
+
};
|
|
47
|
+
const terminateRunnerChild = (child, isWindows, triggerId, reason) => {
|
|
48
|
+
if (!child.pid) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
logger.warn(reason === "cancel" ? "Runner cancellation requested; sending SIGTERM" : "Runner fail-safe timeout reached; sending SIGTERM", {
|
|
52
|
+
triggerId,
|
|
53
|
+
pid: child.pid
|
|
54
|
+
});
|
|
55
|
+
try {
|
|
56
|
+
if (isWindows) {
|
|
57
|
+
execFileSync("taskkill", ["/F", "/T", "/PID", String(child.pid)], { stdio: "ignore" });
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
process.kill(-child.pid, "SIGTERM");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// ignore
|
|
65
|
+
}
|
|
66
|
+
if (!isWindows) {
|
|
67
|
+
setTimeout(() => {
|
|
68
|
+
try {
|
|
69
|
+
if (child.pid) {
|
|
70
|
+
process.kill(-child.pid, "SIGKILL");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// ignore
|
|
75
|
+
}
|
|
76
|
+
}, FORCE_KILL_AFTER_MS);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
export class AmpCodeRunner {
|
|
80
|
+
async run(opts) {
|
|
81
|
+
if (!opts.authPath || opts.authPath.trim().length === 0) {
|
|
82
|
+
logger.error("authPath is missing for trigger");
|
|
83
|
+
return {
|
|
84
|
+
exitCode: 1,
|
|
85
|
+
errorMessage: "authPath is missing for trigger"
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const cwd = opts.authPath;
|
|
89
|
+
const logPath = join(cwd, ".agentteams", "runner", "log", `${opts.triggerId}.log`);
|
|
90
|
+
await mkdir(dirname(logPath), { recursive: true });
|
|
91
|
+
const isWindows = platform() === "win32";
|
|
92
|
+
const resolvedExecutablePath = isWindows
|
|
93
|
+
? resolveExecutablePathWithPreference("amp", ["amp.cmd", "amp"])
|
|
94
|
+
: resolveExecutablePathWithPreference("amp", ["amp"]);
|
|
95
|
+
const windowsEncodedCommand = isWindows
|
|
96
|
+
? toPowerShellEncodedCommand(resolvedExecutablePath, opts.prompt, opts.model)
|
|
97
|
+
: null;
|
|
98
|
+
const executableInfo = describeExecutableResolution("amp", {
|
|
99
|
+
platform: () => (isWindows ? "win32" : platform())
|
|
100
|
+
});
|
|
101
|
+
const ampArgs = buildAmpExecArgs(opts.prompt, opts.model);
|
|
102
|
+
logger.info("Runner prompt", {
|
|
103
|
+
triggerId: opts.triggerId,
|
|
104
|
+
promptLength: opts.prompt.length,
|
|
105
|
+
promptPreview: toPromptPreview(opts.prompt),
|
|
106
|
+
requestedCommand: executableInfo.requestedCommand,
|
|
107
|
+
resolvedExecutablePath,
|
|
108
|
+
platform: executableInfo.platform,
|
|
109
|
+
shell: executableInfo.shell,
|
|
110
|
+
detached: isWindows ? false : true,
|
|
111
|
+
windowsWrapper: isWindows ? "powershell.exe -EncodedCommand" : null
|
|
112
|
+
});
|
|
113
|
+
const child = isWindows
|
|
114
|
+
? spawn("powershell.exe", [
|
|
115
|
+
"-NoLogo",
|
|
116
|
+
"-NonInteractive",
|
|
117
|
+
"-ExecutionPolicy",
|
|
118
|
+
"Bypass",
|
|
119
|
+
"-EncodedCommand",
|
|
120
|
+
windowsEncodedCommand ?? ""
|
|
121
|
+
], {
|
|
122
|
+
cwd,
|
|
123
|
+
detached: false,
|
|
124
|
+
shell: false,
|
|
125
|
+
windowsHide: true,
|
|
126
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
127
|
+
env: {
|
|
128
|
+
...process.env,
|
|
129
|
+
AGENTTEAMS_API_KEY: opts.apiKey,
|
|
130
|
+
AGENTTEAMS_API_URL: opts.apiUrl,
|
|
131
|
+
AGENTTEAMS_TEAM_ID: opts.teamId,
|
|
132
|
+
AGENTTEAMS_PROJECT_ID: opts.projectId,
|
|
133
|
+
AGENTTEAMS_AGENT_NAME: opts.agentConfigId
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
: spawnExecutable("amp", ampArgs, {
|
|
137
|
+
cwd,
|
|
138
|
+
detached: true,
|
|
139
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
140
|
+
env: {
|
|
141
|
+
...process.env,
|
|
142
|
+
AGENTTEAMS_API_KEY: opts.apiKey,
|
|
143
|
+
AGENTTEAMS_API_URL: opts.apiUrl,
|
|
144
|
+
AGENTTEAMS_TEAM_ID: opts.teamId,
|
|
145
|
+
AGENTTEAMS_PROJECT_ID: opts.projectId,
|
|
146
|
+
AGENTTEAMS_AGENT_NAME: opts.agentConfigId
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
const logStream = createWriteStream(logPath, { flags: "a" });
|
|
150
|
+
logStream.on("error", (err) => {
|
|
151
|
+
logger.warn("Runner log stream error", { triggerId: opts.triggerId, error: err.message });
|
|
152
|
+
});
|
|
153
|
+
child.stdout?.pipe(logStream);
|
|
154
|
+
child.stderr?.pipe(logStream);
|
|
155
|
+
let lastOutput = "";
|
|
156
|
+
let lastErrorOutput = "";
|
|
157
|
+
let outputText = "";
|
|
158
|
+
const appendOutputText = (chunk) => {
|
|
159
|
+
if (outputText.length >= OUTPUT_CAPTURE_MAX) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
outputText += chunk.slice(0, OUTPUT_CAPTURE_MAX - outputText.length);
|
|
163
|
+
};
|
|
164
|
+
const idleTimer = { reset: () => { } };
|
|
165
|
+
const streamParser = createStreamJsonLineParser((entries) => {
|
|
166
|
+
for (const entry of entries) {
|
|
167
|
+
opts.onStdoutChunk?.(entry.message);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
child.stdout?.on("data", (chunk) => {
|
|
171
|
+
const rawOutput = Buffer.isBuffer(chunk) ? chunk.toString("utf8") : String(chunk);
|
|
172
|
+
appendOutputText(rawOutput);
|
|
173
|
+
streamParser.push(rawOutput);
|
|
174
|
+
const output = toOutputPreview(rawOutput);
|
|
175
|
+
if (output.length > 0) {
|
|
176
|
+
lastOutput = output;
|
|
177
|
+
idleTimer.reset();
|
|
178
|
+
logger.info("Runner stdout", {
|
|
179
|
+
triggerId: opts.triggerId,
|
|
180
|
+
pid: child.pid,
|
|
181
|
+
output
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
child.stderr?.on("data", (chunk) => {
|
|
186
|
+
const output = toOutputPreview(Buffer.isBuffer(chunk) ? chunk.toString("utf8") : chunk);
|
|
187
|
+
if (output.length > 0) {
|
|
188
|
+
lastOutput = output;
|
|
189
|
+
lastErrorOutput = output;
|
|
190
|
+
idleTimer.reset();
|
|
191
|
+
opts.onStderrChunk?.(output);
|
|
192
|
+
logger.warn("Runner stderr", {
|
|
193
|
+
triggerId: opts.triggerId,
|
|
194
|
+
pid: child.pid,
|
|
195
|
+
output
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
logger.info("Runner started", {
|
|
200
|
+
triggerId: opts.triggerId,
|
|
201
|
+
cwd,
|
|
202
|
+
logPath,
|
|
203
|
+
pid: child.pid
|
|
204
|
+
});
|
|
205
|
+
return await new Promise((resolve) => {
|
|
206
|
+
let finished = false;
|
|
207
|
+
let timedOut = false;
|
|
208
|
+
let idleTimedOut = false;
|
|
209
|
+
let cancelled = false;
|
|
210
|
+
let idleTimeoutId = null;
|
|
211
|
+
const startIdleTimeout = () => {
|
|
212
|
+
if (idleTimeoutId) {
|
|
213
|
+
clearTimeout(idleTimeoutId);
|
|
214
|
+
}
|
|
215
|
+
idleTimeoutId = setTimeout(() => {
|
|
216
|
+
idleTimedOut = true;
|
|
217
|
+
timedOut = true;
|
|
218
|
+
logger.warn("Runner idle timeout reached; no output for configured idle period", {
|
|
219
|
+
triggerId: opts.triggerId,
|
|
220
|
+
idleTimeoutMs: opts.idleTimeoutMs
|
|
221
|
+
});
|
|
222
|
+
terminateRunnerChild(child, isWindows, opts.triggerId, "timeout");
|
|
223
|
+
}, opts.idleTimeoutMs);
|
|
224
|
+
};
|
|
225
|
+
idleTimer.reset = () => {
|
|
226
|
+
startIdleTimeout();
|
|
227
|
+
};
|
|
228
|
+
startIdleTimeout();
|
|
229
|
+
const cleanup = () => {
|
|
230
|
+
if (finished) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
finished = true;
|
|
234
|
+
if (idleTimeoutId) {
|
|
235
|
+
clearTimeout(idleTimeoutId);
|
|
236
|
+
}
|
|
237
|
+
idleTimer.reset = () => { };
|
|
238
|
+
logStream.end();
|
|
239
|
+
if (opts.signal) {
|
|
240
|
+
opts.signal.removeEventListener("abort", handleAbort);
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
const handleAbort = () => {
|
|
244
|
+
cancelled = true;
|
|
245
|
+
terminateRunnerChild(child, isWindows, opts.triggerId, "cancel");
|
|
246
|
+
};
|
|
247
|
+
const timeoutId = setTimeout(() => {
|
|
248
|
+
timedOut = true;
|
|
249
|
+
terminateRunnerChild(child, isWindows, opts.triggerId, "timeout");
|
|
250
|
+
}, opts.timeoutMs);
|
|
251
|
+
if (opts.signal?.aborted) {
|
|
252
|
+
handleAbort();
|
|
253
|
+
}
|
|
254
|
+
else if (opts.signal) {
|
|
255
|
+
opts.signal.addEventListener("abort", handleAbort, { once: true });
|
|
256
|
+
}
|
|
257
|
+
child.on("error", (error) => {
|
|
258
|
+
clearTimeout(timeoutId);
|
|
259
|
+
cleanup();
|
|
260
|
+
logger.error("Runner process launch failed", {
|
|
261
|
+
triggerId: opts.triggerId,
|
|
262
|
+
error: error.message
|
|
263
|
+
});
|
|
264
|
+
resolve({
|
|
265
|
+
exitCode: 1,
|
|
266
|
+
lastOutput,
|
|
267
|
+
outputText: outputText.trim() || undefined,
|
|
268
|
+
errorMessage: error.message
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
child.on("close", (code) => {
|
|
272
|
+
clearTimeout(timeoutId);
|
|
273
|
+
streamParser.flush();
|
|
274
|
+
cleanup();
|
|
275
|
+
logger.info("Runner process closed", {
|
|
276
|
+
triggerId: opts.triggerId,
|
|
277
|
+
pid: child.pid,
|
|
278
|
+
exitCode: code,
|
|
279
|
+
timedOut
|
|
280
|
+
});
|
|
281
|
+
if (timedOut) {
|
|
282
|
+
const trimmedOutputText = outputText.trim();
|
|
283
|
+
const resolvedOutputText = idleTimedOut && trimmedOutputText.length > 0
|
|
284
|
+
? extractResultTextFromStreamJson(outputText)
|
|
285
|
+
: (trimmedOutputText || undefined);
|
|
286
|
+
resolve({
|
|
287
|
+
exitCode: 1,
|
|
288
|
+
lastOutput,
|
|
289
|
+
outputText: resolvedOutputText,
|
|
290
|
+
errorMessage: idleTimedOut
|
|
291
|
+
? `Runner idle timed out after ${Math.round(opts.idleTimeoutMs / 60_000)}m of no output`
|
|
292
|
+
: `Runner fail-safe timed out after ${Math.round(opts.timeoutMs / 3_600_000)}h`
|
|
293
|
+
});
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
if (cancelled) {
|
|
297
|
+
resolve({
|
|
298
|
+
exitCode: 1,
|
|
299
|
+
cancelled: true,
|
|
300
|
+
lastOutput,
|
|
301
|
+
outputText: outputText.trim() || undefined,
|
|
302
|
+
errorMessage: "Runner cancelled by user"
|
|
303
|
+
});
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
resolve({
|
|
307
|
+
exitCode: code ?? 1,
|
|
308
|
+
lastOutput,
|
|
309
|
+
outputText: outputText.trim() || undefined,
|
|
310
|
+
errorMessage: code === 0 ? undefined : (lastErrorOutput || lastOutput || `Runner exited with code ${code ?? 1}`)
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
//# sourceMappingURL=amp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amp.js","sourceRoot":"","sources":["../../src/runners/amp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,IAAI,E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iBACjH,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Runner, RunnerOptions, RunResult } from "./types.js";
|
|
2
|
+
export declare const buildClaudeCodeArgs: (model?: string | null) => string[];
|
|
3
|
+
export declare const extractResultTextFromStreamJson: (outputText: string) => string;
|
|
4
|
+
export declare class ClaudeCodeRunner implements Runner {
|
|
5
|
+
run(opts: RunnerOptions): Promise<RunResult>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { createWriteStream } from "node:fs";
|
|
2
|
+
import { execFileSync, spawn } from "node:child_process";
|
|
3
|
+
import { mkdir } from "node:fs/promises";
|
|
4
|
+
import { platform } from "node:os";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
|
+
import { describeExecutableResolution, resolveExecutablePathWithPreference, spawnExecutable } from "../executable.js";
|
|
7
|
+
import { logger } from "../logger.js";
|
|
8
|
+
import { createStreamJsonLineParser } from "./stream-json-parser.js";
|
|
9
|
+
const FORCE_KILL_AFTER_MS = 10_000;
|
|
10
|
+
const PROMPT_PREVIEW_MAX = 500;
|
|
11
|
+
const OUTPUT_PREVIEW_MAX = 400;
|
|
12
|
+
const OUTPUT_CAPTURE_MAX = 200_000;
|
|
13
|
+
export const buildClaudeCodeArgs = (model) => {
|
|
14
|
+
const modelArgs = model ? ["--model", model] : [];
|
|
15
|
+
return ["-p", "--output-format", "stream-json", "--verbose", "--dangerously-skip-permissions", ...modelArgs];
|
|
16
|
+
};
|
|
17
|
+
export const extractResultTextFromStreamJson = (outputText) => {
|
|
18
|
+
const trimmedOutput = outputText.trim();
|
|
19
|
+
const lines = trimmedOutput
|
|
20
|
+
.split(/\r?\n/)
|
|
21
|
+
.map((line) => line.trim())
|
|
22
|
+
.filter((line) => line.length > 0);
|
|
23
|
+
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
24
|
+
const line = lines[index];
|
|
25
|
+
if (!line.includes("\"type\":\"result\"")) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const parsed = JSON.parse(line);
|
|
30
|
+
if (parsed.type === "result" && typeof parsed.result === "string" && parsed.result.trim().length > 0) {
|
|
31
|
+
return parsed.result.trim();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return trimmedOutput;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return trimmedOutput;
|
|
39
|
+
};
|
|
40
|
+
const toPowerShellEncodedCommand = (resolvedExecutablePath, prompt, model) => {
|
|
41
|
+
const argSegment = buildClaudeCodeArgs(model)
|
|
42
|
+
.map((arg) => ` '${arg.replaceAll("'", "''")}'`)
|
|
43
|
+
.join("");
|
|
44
|
+
const scriptContent = [
|
|
45
|
+
"$ErrorActionPreference = 'Stop'",
|
|
46
|
+
"$utf8NoBom = [System.Text.UTF8Encoding]::new($false)",
|
|
47
|
+
"[Console]::InputEncoding = $utf8NoBom",
|
|
48
|
+
"[Console]::OutputEncoding = $utf8NoBom",
|
|
49
|
+
"$OutputEncoding = $utf8NoBom",
|
|
50
|
+
"chcp 65001 > $null",
|
|
51
|
+
`$promptText = @'`,
|
|
52
|
+
`${prompt.replaceAll("'@", "'@")}`,
|
|
53
|
+
`'@`,
|
|
54
|
+
`$promptText | & '${resolvedExecutablePath.replaceAll("'", "''")}'${argSegment}`
|
|
55
|
+
].join("\r\n");
|
|
56
|
+
return Buffer.from(scriptContent, "utf16le").toString("base64");
|
|
57
|
+
};
|
|
58
|
+
const toPromptPreview = (prompt) => {
|
|
59
|
+
if (prompt.length <= PROMPT_PREVIEW_MAX) {
|
|
60
|
+
return prompt;
|
|
61
|
+
}
|
|
62
|
+
return `${prompt.slice(0, PROMPT_PREVIEW_MAX)}...`;
|
|
63
|
+
};
|
|
64
|
+
const toOutputPreview = (chunk) => {
|
|
65
|
+
const text = (typeof chunk === "string" ? chunk : String(chunk)).trim();
|
|
66
|
+
if (text.length <= OUTPUT_PREVIEW_MAX) {
|
|
67
|
+
return text;
|
|
68
|
+
}
|
|
69
|
+
return `${text.slice(0, OUTPUT_PREVIEW_MAX)}...`;
|
|
70
|
+
};
|
|
71
|
+
const terminateRunnerChild = (child, isWindows, triggerId, reason) => {
|
|
72
|
+
if (!child.pid) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
logger.warn(reason === "cancel" ? "Runner cancellation requested; sending SIGTERM" : "Runner fail-safe timeout reached; sending SIGTERM", {
|
|
76
|
+
triggerId,
|
|
77
|
+
pid: child.pid
|
|
78
|
+
});
|
|
79
|
+
try {
|
|
80
|
+
if (isWindows) {
|
|
81
|
+
execFileSync("taskkill", ["/F", "/T", "/PID", String(child.pid)], { stdio: "ignore" });
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
process.kill(-child.pid, "SIGTERM");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// ignore
|
|
89
|
+
}
|
|
90
|
+
if (!isWindows) {
|
|
91
|
+
setTimeout(() => {
|
|
92
|
+
try {
|
|
93
|
+
if (child.pid) {
|
|
94
|
+
process.kill(-child.pid, "SIGKILL");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// ignore
|
|
99
|
+
}
|
|
100
|
+
}, FORCE_KILL_AFTER_MS);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
export class ClaudeCodeRunner {
|
|
104
|
+
async run(opts) {
|
|
105
|
+
if (!opts.authPath || opts.authPath.trim().length === 0) {
|
|
106
|
+
logger.error("authPath is missing for trigger");
|
|
107
|
+
return {
|
|
108
|
+
exitCode: 1,
|
|
109
|
+
errorMessage: "authPath is missing for trigger"
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
const cwd = opts.authPath;
|
|
113
|
+
const logPath = join(cwd, ".agentteams", "runner", "log", `${opts.triggerId}.log`);
|
|
114
|
+
await mkdir(dirname(logPath), { recursive: true });
|
|
115
|
+
const isWindows = platform() === "win32";
|
|
116
|
+
const resolvedExecutablePath = isWindows
|
|
117
|
+
? resolveExecutablePathWithPreference("claude", ["claude.cmd", "claude"])
|
|
118
|
+
: resolveExecutablePathWithPreference("claude", ["claude"]);
|
|
119
|
+
const windowsEncodedCommand = isWindows
|
|
120
|
+
? toPowerShellEncodedCommand(resolvedExecutablePath, opts.prompt, opts.model)
|
|
121
|
+
: null;
|
|
122
|
+
const claudeArgs = buildClaudeCodeArgs(opts.model);
|
|
123
|
+
const executableInfo = describeExecutableResolution("claude", {
|
|
124
|
+
platform: () => (isWindows ? "win32" : platform())
|
|
125
|
+
});
|
|
126
|
+
logger.info("Runner prompt", {
|
|
127
|
+
triggerId: opts.triggerId,
|
|
128
|
+
promptLength: opts.prompt.length,
|
|
129
|
+
promptPreview: toPromptPreview(opts.prompt),
|
|
130
|
+
requestedCommand: executableInfo.requestedCommand,
|
|
131
|
+
resolvedExecutablePath,
|
|
132
|
+
platform: executableInfo.platform,
|
|
133
|
+
shell: executableInfo.shell,
|
|
134
|
+
detached: isWindows ? false : true,
|
|
135
|
+
windowsWrapper: isWindows ? "powershell.exe -EncodedCommand" : null
|
|
136
|
+
});
|
|
137
|
+
const child = isWindows
|
|
138
|
+
? spawn("powershell.exe", [
|
|
139
|
+
"-NoLogo",
|
|
140
|
+
"-NonInteractive",
|
|
141
|
+
"-ExecutionPolicy",
|
|
142
|
+
"Bypass",
|
|
143
|
+
"-EncodedCommand",
|
|
144
|
+
windowsEncodedCommand ?? ""
|
|
145
|
+
], {
|
|
146
|
+
cwd,
|
|
147
|
+
detached: false,
|
|
148
|
+
shell: false,
|
|
149
|
+
windowsHide: true,
|
|
150
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
151
|
+
env: {
|
|
152
|
+
...process.env,
|
|
153
|
+
AGENTTEAMS_API_KEY: opts.apiKey,
|
|
154
|
+
AGENTTEAMS_API_URL: opts.apiUrl,
|
|
155
|
+
AGENTTEAMS_TEAM_ID: opts.teamId,
|
|
156
|
+
AGENTTEAMS_PROJECT_ID: opts.projectId,
|
|
157
|
+
AGENTTEAMS_AGENT_NAME: opts.agentConfigId
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
: spawnExecutable("claude", [...claudeArgs, opts.prompt], {
|
|
161
|
+
cwd,
|
|
162
|
+
detached: true,
|
|
163
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
164
|
+
env: {
|
|
165
|
+
...process.env,
|
|
166
|
+
AGENTTEAMS_API_KEY: opts.apiKey,
|
|
167
|
+
AGENTTEAMS_API_URL: opts.apiUrl,
|
|
168
|
+
AGENTTEAMS_TEAM_ID: opts.teamId,
|
|
169
|
+
AGENTTEAMS_PROJECT_ID: opts.projectId,
|
|
170
|
+
AGENTTEAMS_AGENT_NAME: opts.agentConfigId
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
const logStream = createWriteStream(logPath, { flags: "a" });
|
|
174
|
+
logStream.on("error", (err) => {
|
|
175
|
+
logger.warn("Runner log stream error", { triggerId: opts.triggerId, error: err.message });
|
|
176
|
+
});
|
|
177
|
+
child.stdout?.pipe(logStream);
|
|
178
|
+
child.stderr?.pipe(logStream);
|
|
179
|
+
let lastOutput = "";
|
|
180
|
+
let lastErrorOutput = "";
|
|
181
|
+
let outputText = "";
|
|
182
|
+
const appendOutputText = (chunk) => {
|
|
183
|
+
if (outputText.length >= OUTPUT_CAPTURE_MAX) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
outputText += chunk.slice(0, OUTPUT_CAPTURE_MAX - outputText.length);
|
|
187
|
+
};
|
|
188
|
+
const idleTimer = { reset: () => { } };
|
|
189
|
+
const streamParser = createStreamJsonLineParser((entries) => {
|
|
190
|
+
for (const entry of entries) {
|
|
191
|
+
opts.onStdoutChunk?.(entry.message);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
child.stdout?.on("data", (chunk) => {
|
|
195
|
+
const rawOutput = Buffer.isBuffer(chunk) ? chunk.toString("utf8") : String(chunk);
|
|
196
|
+
appendOutputText(rawOutput);
|
|
197
|
+
streamParser.push(rawOutput);
|
|
198
|
+
const output = toOutputPreview(rawOutput);
|
|
199
|
+
if (output.length > 0) {
|
|
200
|
+
lastOutput = output;
|
|
201
|
+
idleTimer.reset();
|
|
202
|
+
logger.info("Runner stdout", {
|
|
203
|
+
triggerId: opts.triggerId,
|
|
204
|
+
pid: child.pid,
|
|
205
|
+
output
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
child.stderr?.on("data", (chunk) => {
|
|
210
|
+
const output = toOutputPreview(Buffer.isBuffer(chunk) ? chunk.toString("utf8") : chunk);
|
|
211
|
+
if (output.length > 0) {
|
|
212
|
+
lastOutput = output;
|
|
213
|
+
lastErrorOutput = output;
|
|
214
|
+
idleTimer.reset();
|
|
215
|
+
opts.onStderrChunk?.(output);
|
|
216
|
+
logger.warn("Runner stderr", {
|
|
217
|
+
triggerId: opts.triggerId,
|
|
218
|
+
pid: child.pid,
|
|
219
|
+
output
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
logger.info("Runner started", {
|
|
224
|
+
triggerId: opts.triggerId,
|
|
225
|
+
cwd,
|
|
226
|
+
logPath,
|
|
227
|
+
pid: child.pid
|
|
228
|
+
});
|
|
229
|
+
return await new Promise((resolve) => {
|
|
230
|
+
let finished = false;
|
|
231
|
+
let timedOut = false;
|
|
232
|
+
let idleTimedOut = false;
|
|
233
|
+
let cancelled = false;
|
|
234
|
+
let idleTimeoutId = null;
|
|
235
|
+
const startIdleTimeout = () => {
|
|
236
|
+
if (idleTimeoutId) {
|
|
237
|
+
clearTimeout(idleTimeoutId);
|
|
238
|
+
}
|
|
239
|
+
idleTimeoutId = setTimeout(() => {
|
|
240
|
+
idleTimedOut = true;
|
|
241
|
+
timedOut = true;
|
|
242
|
+
logger.warn("Runner idle timeout reached; no output for configured idle period", {
|
|
243
|
+
triggerId: opts.triggerId,
|
|
244
|
+
idleTimeoutMs: opts.idleTimeoutMs
|
|
245
|
+
});
|
|
246
|
+
terminateRunnerChild(child, isWindows, opts.triggerId, "timeout");
|
|
247
|
+
}, opts.idleTimeoutMs);
|
|
248
|
+
};
|
|
249
|
+
idleTimer.reset = () => {
|
|
250
|
+
startIdleTimeout();
|
|
251
|
+
};
|
|
252
|
+
startIdleTimeout();
|
|
253
|
+
const cleanup = () => {
|
|
254
|
+
if (finished) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
finished = true;
|
|
258
|
+
if (idleTimeoutId) {
|
|
259
|
+
clearTimeout(idleTimeoutId);
|
|
260
|
+
}
|
|
261
|
+
idleTimer.reset = () => { };
|
|
262
|
+
logStream.end();
|
|
263
|
+
if (opts.signal) {
|
|
264
|
+
opts.signal.removeEventListener("abort", handleAbort);
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
const handleAbort = () => {
|
|
268
|
+
cancelled = true;
|
|
269
|
+
terminateRunnerChild(child, isWindows, opts.triggerId, "cancel");
|
|
270
|
+
};
|
|
271
|
+
const timeoutId = setTimeout(() => {
|
|
272
|
+
timedOut = true;
|
|
273
|
+
terminateRunnerChild(child, isWindows, opts.triggerId, "timeout");
|
|
274
|
+
}, opts.timeoutMs);
|
|
275
|
+
if (opts.signal?.aborted) {
|
|
276
|
+
handleAbort();
|
|
277
|
+
}
|
|
278
|
+
else if (opts.signal) {
|
|
279
|
+
opts.signal.addEventListener("abort", handleAbort, { once: true });
|
|
280
|
+
}
|
|
281
|
+
child.on("error", (error) => {
|
|
282
|
+
clearTimeout(timeoutId);
|
|
283
|
+
cleanup();
|
|
284
|
+
logger.error("Runner process launch failed", {
|
|
285
|
+
triggerId: opts.triggerId,
|
|
286
|
+
error: error.message
|
|
287
|
+
});
|
|
288
|
+
resolve({
|
|
289
|
+
exitCode: 1,
|
|
290
|
+
lastOutput,
|
|
291
|
+
outputText: outputText.trim() || undefined,
|
|
292
|
+
errorMessage: error.message
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
child.on("close", (code) => {
|
|
296
|
+
clearTimeout(timeoutId);
|
|
297
|
+
streamParser.flush();
|
|
298
|
+
cleanup();
|
|
299
|
+
logger.info("Runner process closed", {
|
|
300
|
+
triggerId: opts.triggerId,
|
|
301
|
+
pid: child.pid,
|
|
302
|
+
exitCode: code,
|
|
303
|
+
timedOut
|
|
304
|
+
});
|
|
305
|
+
if (timedOut) {
|
|
306
|
+
const trimmedOutputText = outputText.trim();
|
|
307
|
+
const resolvedOutputText = idleTimedOut && trimmedOutputText.length > 0
|
|
308
|
+
? extractResultTextFromStreamJson(outputText)
|
|
309
|
+
: (trimmedOutputText || undefined);
|
|
310
|
+
resolve({
|
|
311
|
+
exitCode: 1,
|
|
312
|
+
lastOutput,
|
|
313
|
+
outputText: resolvedOutputText,
|
|
314
|
+
errorMessage: idleTimedOut
|
|
315
|
+
? `Runner idle timed out after ${Math.round(opts.idleTimeoutMs / 60_000)}m of no output`
|
|
316
|
+
: `Runner fail-safe timed out after ${Math.round(opts.timeoutMs / 3_600_000)}h`
|
|
317
|
+
});
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (cancelled) {
|
|
321
|
+
resolve({
|
|
322
|
+
exitCode: 1,
|
|
323
|
+
cancelled: true,
|
|
324
|
+
lastOutput,
|
|
325
|
+
outputText: outputText.trim() || undefined,
|
|
326
|
+
errorMessage: "Runner cancelled by user"
|
|
327
|
+
});
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
resolve({
|
|
331
|
+
exitCode: code ?? 1,
|
|
332
|
+
lastOutput,
|
|
333
|
+
outputText: outputText.trim() || undefined,
|
|
334
|
+
errorMessage: code === 0 ? undefined : (lastErrorOutput || lastOutput || `Runner exited with code ${code ?? 1}`)
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
//# sourceMappingURL=claude-code.js.map
|