@rlarua/agentrunner 0.0.3
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 +18 -0
- package/dist/api-client.js +133 -0
- package/dist/api-client.js.map +1 -0
- package/dist/autostart.d.ts +15 -0
- package/dist/autostart.js +280 -0
- package/dist/autostart.js.map +1 -0
- package/dist/commands/init.d.ts +1 -0
- package/dist/commands/init.js +56 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/start.d.ts +1 -0
- package/dist/commands/start.js +21 -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/config.d.ts +6 -0
- package/dist/config.js +66 -0
- package/dist/config.js.map +1 -0
- package/dist/handlers/trigger-handler.d.ts +3 -0
- package/dist/handlers/trigger-handler.js +145 -0
- package/dist/handlers/trigger-handler.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +64 -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 +48 -0
- package/dist/pid.js.map +1 -0
- package/dist/poller.d.ts +4 -0
- package/dist/poller.js +62 -0
- package/dist/poller.js.map +1 -0
- package/dist/runners/claude-code.d.ts +4 -0
- package/dist/runners/claude-code.js +166 -0
- package/dist/runners/claude-code.js.map +1 -0
- package/dist/runners/codex.d.ts +4 -0
- package/dist/runners/codex.js +166 -0
- package/dist/runners/codex.js.map +1 -0
- package/dist/runners/gemini.d.ts +4 -0
- package/dist/runners/gemini.js +166 -0
- package/dist/runners/gemini.js.map +1 -0
- package/dist/runners/index.d.ts +2 -0
- package/dist/runners/index.js +25 -0
- package/dist/runners/index.js.map +1 -0
- package/dist/runners/log-reporter.d.ts +17 -0
- package/dist/runners/log-reporter.js +107 -0
- package/dist/runners/log-reporter.js.map +1 -0
- package/dist/runners/opencode.d.ts +6 -0
- package/dist/runners/opencode.js +170 -0
- package/dist/runners/opencode.js.map +1 -0
- package/dist/runners/types.d.ts +19 -0
- package/dist/runners/types.js +2 -0
- package/dist/runners/types.js.map +1 -0
- package/dist/types.d.ts +52 -0
- package/dist/types.js +2 -0
- package/dist/types.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/package.json +38 -0
- package/readme.md +160 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { createWriteStream } from "node:fs";
|
|
2
|
+
import { mkdir } from "node:fs/promises";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { logger } from "../logger.js";
|
|
6
|
+
const FORCE_KILL_AFTER_MS = 10_000;
|
|
7
|
+
const PROMPT_PREVIEW_MAX = 500;
|
|
8
|
+
const OUTPUT_PREVIEW_MAX = 400;
|
|
9
|
+
const toPromptPreview = (prompt) => {
|
|
10
|
+
if (prompt.length <= PROMPT_PREVIEW_MAX) {
|
|
11
|
+
return prompt;
|
|
12
|
+
}
|
|
13
|
+
return `${prompt.slice(0, PROMPT_PREVIEW_MAX)}...`;
|
|
14
|
+
};
|
|
15
|
+
const toOutputPreview = (chunk) => {
|
|
16
|
+
const text = (typeof chunk === "string" ? chunk : String(chunk)).trim();
|
|
17
|
+
if (text.length <= OUTPUT_PREVIEW_MAX) {
|
|
18
|
+
return text;
|
|
19
|
+
}
|
|
20
|
+
return `${text.slice(0, OUTPUT_PREVIEW_MAX)}...`;
|
|
21
|
+
};
|
|
22
|
+
export class ClaudeCodeRunner {
|
|
23
|
+
async run(opts) {
|
|
24
|
+
if (!opts.authPath || opts.authPath.trim().length === 0) {
|
|
25
|
+
logger.error("authPath is missing for trigger");
|
|
26
|
+
return {
|
|
27
|
+
exitCode: 1,
|
|
28
|
+
errorMessage: "authPath is missing for trigger"
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const cwd = opts.authPath;
|
|
32
|
+
const logPath = join(cwd, ".agentteams", "runner-log", `${opts.triggerId}.log`);
|
|
33
|
+
await mkdir(dirname(logPath), { recursive: true });
|
|
34
|
+
logger.info("Runner prompt", {
|
|
35
|
+
triggerId: opts.triggerId,
|
|
36
|
+
promptLength: opts.prompt.length,
|
|
37
|
+
promptPreview: toPromptPreview(opts.prompt)
|
|
38
|
+
});
|
|
39
|
+
const child = spawn("claude", ["-p", opts.prompt], {
|
|
40
|
+
cwd,
|
|
41
|
+
detached: true,
|
|
42
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
43
|
+
env: {
|
|
44
|
+
...process.env,
|
|
45
|
+
AGENTTEAMS_API_KEY: opts.apiKey,
|
|
46
|
+
AGENTTEAMS_API_URL: opts.apiUrl,
|
|
47
|
+
AGENTTEAMS_AGENT_NAME: opts.agentConfigId
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
const logStream = createWriteStream(logPath, { flags: "a" });
|
|
51
|
+
child.stdout?.pipe(logStream);
|
|
52
|
+
child.stderr?.pipe(logStream);
|
|
53
|
+
let lastOutput = "";
|
|
54
|
+
let lastErrorOutput = "";
|
|
55
|
+
child.stdout?.on("data", (chunk) => {
|
|
56
|
+
const output = toOutputPreview(Buffer.isBuffer(chunk) ? chunk.toString("utf8") : chunk);
|
|
57
|
+
if (output.length > 0) {
|
|
58
|
+
lastOutput = output;
|
|
59
|
+
opts.onStdoutChunk?.(output);
|
|
60
|
+
logger.info("Runner stdout", {
|
|
61
|
+
triggerId: opts.triggerId,
|
|
62
|
+
pid: child.pid,
|
|
63
|
+
output
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
child.stderr?.on("data", (chunk) => {
|
|
68
|
+
const output = toOutputPreview(Buffer.isBuffer(chunk) ? chunk.toString("utf8") : chunk);
|
|
69
|
+
if (output.length > 0) {
|
|
70
|
+
lastOutput = output;
|
|
71
|
+
lastErrorOutput = output;
|
|
72
|
+
opts.onStderrChunk?.(output);
|
|
73
|
+
logger.warn("Runner stderr", {
|
|
74
|
+
triggerId: opts.triggerId,
|
|
75
|
+
pid: child.pid,
|
|
76
|
+
output
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
logger.info("Runner started", {
|
|
81
|
+
triggerId: opts.triggerId,
|
|
82
|
+
cwd,
|
|
83
|
+
logPath,
|
|
84
|
+
pid: child.pid
|
|
85
|
+
});
|
|
86
|
+
return await new Promise((resolve) => {
|
|
87
|
+
let finished = false;
|
|
88
|
+
let timedOut = false;
|
|
89
|
+
const cleanup = () => {
|
|
90
|
+
if (finished) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
finished = true;
|
|
94
|
+
logStream.end();
|
|
95
|
+
};
|
|
96
|
+
const timeoutId = setTimeout(() => {
|
|
97
|
+
timedOut = true;
|
|
98
|
+
if (!child.pid) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
logger.warn("Runner timeout reached; sending SIGTERM", {
|
|
102
|
+
triggerId: opts.triggerId,
|
|
103
|
+
pid: child.pid,
|
|
104
|
+
timeoutMs: opts.timeoutMs
|
|
105
|
+
});
|
|
106
|
+
try {
|
|
107
|
+
process.kill(-child.pid, "SIGTERM");
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
// ignore
|
|
111
|
+
}
|
|
112
|
+
setTimeout(() => {
|
|
113
|
+
if (!finished && child.pid) {
|
|
114
|
+
logger.warn("Runner still alive after SIGTERM; sending SIGKILL", {
|
|
115
|
+
triggerId: opts.triggerId,
|
|
116
|
+
pid: child.pid
|
|
117
|
+
});
|
|
118
|
+
try {
|
|
119
|
+
process.kill(-child.pid, "SIGKILL");
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// ignore
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}, FORCE_KILL_AFTER_MS);
|
|
126
|
+
}, opts.timeoutMs);
|
|
127
|
+
child.on("error", (error) => {
|
|
128
|
+
clearTimeout(timeoutId);
|
|
129
|
+
cleanup();
|
|
130
|
+
logger.error("Runner process launch failed", {
|
|
131
|
+
triggerId: opts.triggerId,
|
|
132
|
+
error: error.message
|
|
133
|
+
});
|
|
134
|
+
resolve({
|
|
135
|
+
exitCode: 1,
|
|
136
|
+
lastOutput,
|
|
137
|
+
errorMessage: error.message
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
child.on("close", (code) => {
|
|
141
|
+
clearTimeout(timeoutId);
|
|
142
|
+
cleanup();
|
|
143
|
+
logger.info("Runner process closed", {
|
|
144
|
+
triggerId: opts.triggerId,
|
|
145
|
+
pid: child.pid,
|
|
146
|
+
exitCode: code,
|
|
147
|
+
timedOut
|
|
148
|
+
});
|
|
149
|
+
if (timedOut) {
|
|
150
|
+
resolve({
|
|
151
|
+
exitCode: 1,
|
|
152
|
+
lastOutput,
|
|
153
|
+
errorMessage: `Runner timed out after ${opts.timeoutMs}ms`
|
|
154
|
+
});
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
resolve({
|
|
158
|
+
exitCode: code ?? 1,
|
|
159
|
+
lastOutput,
|
|
160
|
+
errorMessage: code === 0 ? undefined : (lastErrorOutput || lastOutput || `Runner exited with code ${code ?? 1}`)
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=claude-code.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-code.js","sourceRoot":"","sources":["../../src/runners/claude-code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAA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C;iBACjH,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { createWriteStream } from "node:fs";
|
|
2
|
+
import { mkdir } from "node:fs/promises";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { logger } from "../logger.js";
|
|
6
|
+
const FORCE_KILL_AFTER_MS = 10_000;
|
|
7
|
+
const PROMPT_PREVIEW_MAX = 500;
|
|
8
|
+
const OUTPUT_PREVIEW_MAX = 400;
|
|
9
|
+
const toPromptPreview = (prompt) => {
|
|
10
|
+
if (prompt.length <= PROMPT_PREVIEW_MAX) {
|
|
11
|
+
return prompt;
|
|
12
|
+
}
|
|
13
|
+
return `${prompt.slice(0, PROMPT_PREVIEW_MAX)}...`;
|
|
14
|
+
};
|
|
15
|
+
const toOutputPreview = (chunk) => {
|
|
16
|
+
const text = (typeof chunk === "string" ? chunk : String(chunk)).trim();
|
|
17
|
+
if (text.length <= OUTPUT_PREVIEW_MAX) {
|
|
18
|
+
return text;
|
|
19
|
+
}
|
|
20
|
+
return `${text.slice(0, OUTPUT_PREVIEW_MAX)}...`;
|
|
21
|
+
};
|
|
22
|
+
export class CodexRunner {
|
|
23
|
+
async run(opts) {
|
|
24
|
+
if (!opts.authPath || opts.authPath.trim().length === 0) {
|
|
25
|
+
logger.error("authPath is missing for trigger");
|
|
26
|
+
return {
|
|
27
|
+
exitCode: 1,
|
|
28
|
+
errorMessage: "authPath is missing for trigger"
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const cwd = opts.authPath;
|
|
32
|
+
const logPath = join(cwd, ".agentteams", "runner-log", `${opts.triggerId}.log`);
|
|
33
|
+
await mkdir(dirname(logPath), { recursive: true });
|
|
34
|
+
logger.info("Runner prompt", {
|
|
35
|
+
triggerId: opts.triggerId,
|
|
36
|
+
promptLength: opts.prompt.length,
|
|
37
|
+
promptPreview: toPromptPreview(opts.prompt)
|
|
38
|
+
});
|
|
39
|
+
const child = spawn("codex", ["exec", opts.prompt], {
|
|
40
|
+
cwd,
|
|
41
|
+
detached: true,
|
|
42
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
43
|
+
env: {
|
|
44
|
+
...process.env,
|
|
45
|
+
AGENTTEAMS_API_KEY: opts.apiKey,
|
|
46
|
+
AGENTTEAMS_API_URL: opts.apiUrl,
|
|
47
|
+
AGENTTEAMS_AGENT_NAME: opts.agentConfigId
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
const logStream = createWriteStream(logPath, { flags: "a" });
|
|
51
|
+
child.stdout?.pipe(logStream);
|
|
52
|
+
child.stderr?.pipe(logStream);
|
|
53
|
+
let lastOutput = "";
|
|
54
|
+
let lastErrorOutput = "";
|
|
55
|
+
child.stdout?.on("data", (chunk) => {
|
|
56
|
+
const output = toOutputPreview(Buffer.isBuffer(chunk) ? chunk.toString("utf8") : chunk);
|
|
57
|
+
if (output.length > 0) {
|
|
58
|
+
lastOutput = output;
|
|
59
|
+
opts.onStdoutChunk?.(output);
|
|
60
|
+
logger.info("Runner stdout", {
|
|
61
|
+
triggerId: opts.triggerId,
|
|
62
|
+
pid: child.pid,
|
|
63
|
+
output
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
child.stderr?.on("data", (chunk) => {
|
|
68
|
+
const output = toOutputPreview(Buffer.isBuffer(chunk) ? chunk.toString("utf8") : chunk);
|
|
69
|
+
if (output.length > 0) {
|
|
70
|
+
lastOutput = output;
|
|
71
|
+
lastErrorOutput = output;
|
|
72
|
+
opts.onStderrChunk?.(output);
|
|
73
|
+
logger.warn("Runner stderr", {
|
|
74
|
+
triggerId: opts.triggerId,
|
|
75
|
+
pid: child.pid,
|
|
76
|
+
output
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
logger.info("Runner started", {
|
|
81
|
+
triggerId: opts.triggerId,
|
|
82
|
+
cwd,
|
|
83
|
+
logPath,
|
|
84
|
+
pid: child.pid
|
|
85
|
+
});
|
|
86
|
+
return await new Promise((resolve) => {
|
|
87
|
+
let finished = false;
|
|
88
|
+
let timedOut = false;
|
|
89
|
+
const cleanup = () => {
|
|
90
|
+
if (finished) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
finished = true;
|
|
94
|
+
logStream.end();
|
|
95
|
+
};
|
|
96
|
+
const timeoutId = setTimeout(() => {
|
|
97
|
+
timedOut = true;
|
|
98
|
+
if (!child.pid) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
logger.warn("Runner timeout reached; sending SIGTERM", {
|
|
102
|
+
triggerId: opts.triggerId,
|
|
103
|
+
pid: child.pid,
|
|
104
|
+
timeoutMs: opts.timeoutMs
|
|
105
|
+
});
|
|
106
|
+
try {
|
|
107
|
+
process.kill(-child.pid, "SIGTERM");
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
// ignore
|
|
111
|
+
}
|
|
112
|
+
setTimeout(() => {
|
|
113
|
+
if (!finished && child.pid) {
|
|
114
|
+
logger.warn("Runner still alive after SIGTERM; sending SIGKILL", {
|
|
115
|
+
triggerId: opts.triggerId,
|
|
116
|
+
pid: child.pid
|
|
117
|
+
});
|
|
118
|
+
try {
|
|
119
|
+
process.kill(-child.pid, "SIGKILL");
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// ignore
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}, FORCE_KILL_AFTER_MS);
|
|
126
|
+
}, opts.timeoutMs);
|
|
127
|
+
child.on("error", (error) => {
|
|
128
|
+
clearTimeout(timeoutId);
|
|
129
|
+
cleanup();
|
|
130
|
+
logger.error("Runner process launch failed", {
|
|
131
|
+
triggerId: opts.triggerId,
|
|
132
|
+
error: error.message
|
|
133
|
+
});
|
|
134
|
+
resolve({
|
|
135
|
+
exitCode: 1,
|
|
136
|
+
lastOutput,
|
|
137
|
+
errorMessage: error.message
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
child.on("close", (code) => {
|
|
141
|
+
clearTimeout(timeoutId);
|
|
142
|
+
cleanup();
|
|
143
|
+
logger.info("Runner process closed", {
|
|
144
|
+
triggerId: opts.triggerId,
|
|
145
|
+
pid: child.pid,
|
|
146
|
+
exitCode: code,
|
|
147
|
+
timedOut
|
|
148
|
+
});
|
|
149
|
+
if (timedOut) {
|
|
150
|
+
resolve({
|
|
151
|
+
exitCode: 1,
|
|
152
|
+
lastOutput,
|
|
153
|
+
errorMessage: `Runner timed out after ${opts.timeoutMs}ms`
|
|
154
|
+
});
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
resolve({
|
|
158
|
+
exitCode: code ?? 1,
|
|
159
|
+
lastOutput,
|
|
160
|
+
errorMessage: code === 0 ? undefined : (lastErrorOutput || lastOutput || `Runner exited with code ${code ?? 1}`)
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=codex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex.js","sourceRoot":"","sources":["../../src/runners/codex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC,MAAM,mBAAmB,GAAG,MAAM,CAAC;AACnC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAE/B,MAAM,eAAe,GAAG,CAAC,MAAc,EAAU,EAAE;IACjD,IAAI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AQ,EAAE,CAAC;oBACX,UAAU;oBACV,YAAY,EAAE,KAAK,CAAC,OAAO;iBAC5B,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;gBACzB,YAAY,CAAC,SAAS,CAAC,CAAC;gBACxB,OAAO,EAAE,CAAC;gBACV,MAAM,CAAC,IAAI,CAAC,uBAAuB,EAAE;oBACnC,SAAS,EAAE,IAAI,CAAC,SAAS;oBACzB,GAAG,EAAE,KAAK,CAAC,GAAG;oBACd,QAAQ,EAAE,IAAI;oBACd,QAAQ;iBACT,CAAC,CAAC;gBAEH,IAAI,QAAQ,EAAE,CAAC;oBACb,OAAO,CAAC;wBACN,QAAQ,EAAE,CAAC;wBACX,UAAU;wBACV,YAAY,EAAE,0BAA0B,IAAI,CAAC,SAAS,IAAI;qBAC3D,CAAC,CAAC;oBACH,OAAO;gBACT,CAAC;gBAED,OAAO,CAAC;oBACN,QAAQ,EAAE,IAAI,IAAI,CAAC;oBACnB,UAAU;oBACV,YAAY,EAAE,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,eAAe,IAAI,UAAU,IAAI,2BAA2B,IAAI,IAAI,CAAC,EAAE,CAAC;iBACjH,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { createWriteStream } from "node:fs";
|
|
2
|
+
import { mkdir } from "node:fs/promises";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { logger } from "../logger.js";
|
|
6
|
+
const FORCE_KILL_AFTER_MS = 10_000;
|
|
7
|
+
const PROMPT_PREVIEW_MAX = 500;
|
|
8
|
+
const OUTPUT_PREVIEW_MAX = 400;
|
|
9
|
+
const toPromptPreview = (prompt) => {
|
|
10
|
+
if (prompt.length <= PROMPT_PREVIEW_MAX) {
|
|
11
|
+
return prompt;
|
|
12
|
+
}
|
|
13
|
+
return `${prompt.slice(0, PROMPT_PREVIEW_MAX)}...`;
|
|
14
|
+
};
|
|
15
|
+
const toOutputPreview = (chunk) => {
|
|
16
|
+
const text = (typeof chunk === "string" ? chunk : String(chunk)).trim();
|
|
17
|
+
if (text.length <= OUTPUT_PREVIEW_MAX) {
|
|
18
|
+
return text;
|
|
19
|
+
}
|
|
20
|
+
return `${text.slice(0, OUTPUT_PREVIEW_MAX)}...`;
|
|
21
|
+
};
|
|
22
|
+
export class GeminiRunner {
|
|
23
|
+
async run(opts) {
|
|
24
|
+
if (!opts.authPath || opts.authPath.trim().length === 0) {
|
|
25
|
+
logger.error("authPath is missing for trigger");
|
|
26
|
+
return {
|
|
27
|
+
exitCode: 1,
|
|
28
|
+
errorMessage: "authPath is missing for trigger"
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const cwd = opts.authPath;
|
|
32
|
+
const logPath = join(cwd, ".agentteams", "runner-log", `${opts.triggerId}.log`);
|
|
33
|
+
await mkdir(dirname(logPath), { recursive: true });
|
|
34
|
+
logger.info("Runner prompt", {
|
|
35
|
+
triggerId: opts.triggerId,
|
|
36
|
+
promptLength: opts.prompt.length,
|
|
37
|
+
promptPreview: toPromptPreview(opts.prompt)
|
|
38
|
+
});
|
|
39
|
+
const child = spawn("gemini", ["-p", opts.prompt], {
|
|
40
|
+
cwd,
|
|
41
|
+
detached: true,
|
|
42
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
43
|
+
env: {
|
|
44
|
+
...process.env,
|
|
45
|
+
AGENTTEAMS_API_KEY: opts.apiKey,
|
|
46
|
+
AGENTTEAMS_API_URL: opts.apiUrl,
|
|
47
|
+
AGENTTEAMS_AGENT_NAME: opts.agentConfigId
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
const logStream = createWriteStream(logPath, { flags: "a" });
|
|
51
|
+
child.stdout?.pipe(logStream);
|
|
52
|
+
child.stderr?.pipe(logStream);
|
|
53
|
+
let lastOutput = "";
|
|
54
|
+
let lastErrorOutput = "";
|
|
55
|
+
child.stdout?.on("data", (chunk) => {
|
|
56
|
+
const output = toOutputPreview(Buffer.isBuffer(chunk) ? chunk.toString("utf8") : chunk);
|
|
57
|
+
if (output.length > 0) {
|
|
58
|
+
lastOutput = output;
|
|
59
|
+
opts.onStdoutChunk?.(output);
|
|
60
|
+
logger.info("Runner stdout", {
|
|
61
|
+
triggerId: opts.triggerId,
|
|
62
|
+
pid: child.pid,
|
|
63
|
+
output
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
child.stderr?.on("data", (chunk) => {
|
|
68
|
+
const output = toOutputPreview(Buffer.isBuffer(chunk) ? chunk.toString("utf8") : chunk);
|
|
69
|
+
if (output.length > 0) {
|
|
70
|
+
lastOutput = output;
|
|
71
|
+
lastErrorOutput = output;
|
|
72
|
+
opts.onStderrChunk?.(output);
|
|
73
|
+
logger.warn("Runner stderr", {
|
|
74
|
+
triggerId: opts.triggerId,
|
|
75
|
+
pid: child.pid,
|
|
76
|
+
output
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
logger.info("Runner started", {
|
|
81
|
+
triggerId: opts.triggerId,
|
|
82
|
+
cwd,
|
|
83
|
+
logPath,
|
|
84
|
+
pid: child.pid
|
|
85
|
+
});
|
|
86
|
+
return await new Promise((resolve) => {
|
|
87
|
+
let finished = false;
|
|
88
|
+
let timedOut = false;
|
|
89
|
+
const cleanup = () => {
|
|
90
|
+
if (finished) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
finished = true;
|
|
94
|
+
logStream.end();
|
|
95
|
+
};
|
|
96
|
+
const timeoutId = setTimeout(() => {
|
|
97
|
+
timedOut = true;
|
|
98
|
+
if (!child.pid) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
logger.warn("Runner timeout reached; sending SIGTERM", {
|
|
102
|
+
triggerId: opts.triggerId,
|
|
103
|
+
pid: child.pid,
|
|
104
|
+
timeoutMs: opts.timeoutMs
|
|
105
|
+
});
|
|
106
|
+
try {
|
|
107
|
+
process.kill(-child.pid, "SIGTERM");
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
// ignore
|
|
111
|
+
}
|
|
112
|
+
setTimeout(() => {
|
|
113
|
+
if (!finished && child.pid) {
|
|
114
|
+
logger.warn("Runner still alive after SIGTERM; sending SIGKILL", {
|
|
115
|
+
triggerId: opts.triggerId,
|
|
116
|
+
pid: child.pid
|
|
117
|
+
});
|
|
118
|
+
try {
|
|
119
|
+
process.kill(-child.pid, "SIGKILL");
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// ignore
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}, FORCE_KILL_AFTER_MS);
|
|
126
|
+
}, opts.timeoutMs);
|
|
127
|
+
child.on("error", (error) => {
|
|
128
|
+
clearTimeout(timeoutId);
|
|
129
|
+
cleanup();
|
|
130
|
+
logger.error("Runner process launch failed", {
|
|
131
|
+
triggerId: opts.triggerId,
|
|
132
|
+
error: error.message
|
|
133
|
+
});
|
|
134
|
+
resolve({
|
|
135
|
+
exitCode: 1,
|
|
136
|
+
lastOutput,
|
|
137
|
+
errorMessage: error.message
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
child.on("close", (code) => {
|
|
141
|
+
clearTimeout(timeoutId);
|
|
142
|
+
cleanup();
|
|
143
|
+
logger.info("Runner process closed", {
|
|
144
|
+
triggerId: opts.triggerId,
|
|
145
|
+
pid: child.pid,
|
|
146
|
+
exitCode: code,
|
|
147
|
+
timedOut
|
|
148
|
+
});
|
|
149
|
+
if (timedOut) {
|
|
150
|
+
resolve({
|
|
151
|
+
exitCode: 1,
|
|
152
|
+
lastOutput,
|
|
153
|
+
errorMessage: `Runner timed out after ${opts.timeoutMs}ms`
|
|
154
|
+
});
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
resolve({
|
|
158
|
+
exitCode: code ?? 1,
|
|
159
|
+
lastOutput,
|
|
160
|
+
errorMessage: code === 0 ? undefined : (lastErrorOutput || lastOutput || `Runner exited with code ${code ?? 1}`)
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=gemini.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gemini.js","sourceRoot":"","sources":["../../src/runners/gemini.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAGtC,MAAM,mBAAmB,GAAG,MAAM,CAAC;AACnC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAC/B,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAE/B,MAAM,eAAe,GAAG,CAAC,MAAc,EAAU,EAAE;IACjD,IAAI,MAAM,CAAC,MAAM,IAAI,kBAAkB,EAAE,CAAC;QACxC,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,kBAAkB,CAAC,KAAK,CAAC;AACrD,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,CAAC,KAAc,EAAU,EAAE;IACjD,MAAM,IAAI,GAAG,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACxE,IAAI,IAAI,CAAC,MAAM,IAAI,kB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EH,IAAI,QAAQ,EAAE,CAAC;oBACb,OAAO,CAAC;wBACN,QAAQ,EAAE,CAAC;wBACX,UAAU;wBACV,YAAY,EAAE,0BAA0B,IAAI,CAAC,SAAS,IAAI;qBAC3D,CAAC,CAAC;oBACH,OAAO;gBACT,CAAC;gBAED,OAAO,CAAC;oBACN,QAAQ,EAAE,IAAI,IAAI,CAAC;oBACnB,UAAU;oBACV,YAAY,EAAE,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,eAAe,IAAI,UAAU,IAAI,2BAA2B,IAAI,IAAI,CAAC,EAAE,CAAC;iBACjH,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { OpenCodeRunner } from "./opencode.js";
|
|
2
|
+
import { ClaudeCodeRunner } from "./claude-code.js";
|
|
3
|
+
import { CodexRunner } from "./codex.js";
|
|
4
|
+
import { GeminiRunner } from "./gemini.js";
|
|
5
|
+
export const createRunnerFactory = (runnerCmd) => {
|
|
6
|
+
return (runnerType) => {
|
|
7
|
+
switch (runnerType) {
|
|
8
|
+
case "OPENCODE":
|
|
9
|
+
return new OpenCodeRunner(runnerCmd);
|
|
10
|
+
case "CLAUDE_CODE":
|
|
11
|
+
return new ClaudeCodeRunner();
|
|
12
|
+
case "CODEX":
|
|
13
|
+
return new CodexRunner();
|
|
14
|
+
case "GEMINI":
|
|
15
|
+
return new GeminiRunner();
|
|
16
|
+
// TODO: AIDER
|
|
17
|
+
// TODO: GOOSE
|
|
18
|
+
// TODO: PLANDEX
|
|
19
|
+
// TODO: AMP
|
|
20
|
+
default:
|
|
21
|
+
throw new Error(`Unsupported runner type: ${runnerType}`);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runners/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,SAAiB,EAAE,EAAE;IACvD,OAAO,CAAC,UAAkB,EAAU,EAAE;QACpC,QAAQ,UAAU,EAAE,CAAC;YACnB,KAAK,UAAU;gBACb,OAAO,IAAI,cAAc,CAAC,SAAS,CAAC,CAAC;YACvC,KAAK,aAAa;gBAChB,OAAO,IAAI,gBAAgB,EAAE,CAAC;YAChC,KAAK,OAAO;gBACV,OAAO,IAAI,WAAW,EAAE,CAAC;YAC3B,KAAK,QAAQ;gBACX,OAAO,IAAI,YAAY,EAAE,CAAC;YAC5B,cAAc;YACd,cAAc;YACd,gBAAgB;YAChB,YAAY;YACZ;gBACE,MAAM,IAAI,KAAK,CAAC,4BAA4B,UAAU,EAAE,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DaemonApiClient } from "../api-client.js";
|
|
2
|
+
import type { TriggerLogLevel } from "../types.js";
|
|
3
|
+
export declare class TriggerLogReporter {
|
|
4
|
+
private readonly client;
|
|
5
|
+
private readonly triggerId;
|
|
6
|
+
private readonly flushIntervalMs;
|
|
7
|
+
private readonly queue;
|
|
8
|
+
private flushTimer;
|
|
9
|
+
private flushInFlight;
|
|
10
|
+
private droppedCount;
|
|
11
|
+
constructor(client: DaemonApiClient, triggerId: string, flushIntervalMs?: number);
|
|
12
|
+
start(): void;
|
|
13
|
+
append(level: TriggerLogLevel, message: string): void;
|
|
14
|
+
stop(): Promise<void>;
|
|
15
|
+
private flush;
|
|
16
|
+
private send;
|
|
17
|
+
}
|