@elyracode/agent-core 0.1.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/README.md +488 -0
- package/dist/agent-loop.d.ts +24 -0
- package/dist/agent-loop.d.ts.map +1 -0
- package/dist/agent-loop.js +479 -0
- package/dist/agent-loop.js.map +1 -0
- package/dist/agent.d.ts +118 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +402 -0
- package/dist/agent.js.map +1 -0
- package/dist/harness/agent-harness.d.ts +78 -0
- package/dist/harness/agent-harness.d.ts.map +1 -0
- package/dist/harness/agent-harness.js +602 -0
- package/dist/harness/agent-harness.js.map +1 -0
- package/dist/harness/compaction/branch-summarization.d.ts +88 -0
- package/dist/harness/compaction/branch-summarization.d.ts.map +1 -0
- package/dist/harness/compaction/branch-summarization.js +243 -0
- package/dist/harness/compaction/branch-summarization.js.map +1 -0
- package/dist/harness/compaction/compaction.d.ts +122 -0
- package/dist/harness/compaction/compaction.d.ts.map +1 -0
- package/dist/harness/compaction/compaction.js +616 -0
- package/dist/harness/compaction/compaction.js.map +1 -0
- package/dist/harness/compaction/utils.d.ts +38 -0
- package/dist/harness/compaction/utils.d.ts.map +1 -0
- package/dist/harness/compaction/utils.js +153 -0
- package/dist/harness/compaction/utils.js.map +1 -0
- package/dist/harness/env/nodejs.d.ts +44 -0
- package/dist/harness/env/nodejs.d.ts.map +1 -0
- package/dist/harness/env/nodejs.js +348 -0
- package/dist/harness/env/nodejs.js.map +1 -0
- package/dist/harness/execution-env.d.ts +4 -0
- package/dist/harness/execution-env.d.ts.map +1 -0
- package/dist/harness/execution-env.js +3 -0
- package/dist/harness/execution-env.js.map +1 -0
- package/dist/harness/messages.d.ts +51 -0
- package/dist/harness/messages.d.ts.map +1 -0
- package/dist/harness/messages.js +102 -0
- package/dist/harness/messages.js.map +1 -0
- package/dist/harness/prompt-templates.d.ts +45 -0
- package/dist/harness/prompt-templates.d.ts.map +1 -0
- package/dist/harness/prompt-templates.js +200 -0
- package/dist/harness/prompt-templates.js.map +1 -0
- package/dist/harness/session/repo/jsonl.d.ts +20 -0
- package/dist/harness/session/repo/jsonl.d.ts.map +1 -0
- package/dist/harness/session/repo/jsonl.js +92 -0
- package/dist/harness/session/repo/jsonl.js.map +1 -0
- package/dist/harness/session/repo/memory.d.ts +18 -0
- package/dist/harness/session/repo/memory.d.ts.map +1 -0
- package/dist/harness/session/repo/memory.js +42 -0
- package/dist/harness/session/repo/memory.js.map +1 -0
- package/dist/harness/session/repo/shared.d.ts +10 -0
- package/dist/harness/session/repo/shared.d.ts.map +1 -0
- package/dist/harness/session/repo/shared.js +31 -0
- package/dist/harness/session/repo/shared.js.map +1 -0
- package/dist/harness/session/session.d.ts +32 -0
- package/dist/harness/session/session.d.ts.map +1 -0
- package/dist/harness/session/session.js +196 -0
- package/dist/harness/session/session.js.map +1 -0
- package/dist/harness/session/storage/jsonl.d.ts +30 -0
- package/dist/harness/session/storage/jsonl.d.ts.map +1 -0
- package/dist/harness/session/storage/jsonl.js +170 -0
- package/dist/harness/session/storage/jsonl.js.map +1 -0
- package/dist/harness/session/storage/memory.d.ts +26 -0
- package/dist/harness/session/storage/memory.d.ts.map +1 -0
- package/dist/harness/session/storage/memory.js +90 -0
- package/dist/harness/session/storage/memory.js.map +1 -0
- package/dist/harness/skills.d.ts +41 -0
- package/dist/harness/skills.d.ts.map +1 -0
- package/dist/harness/skills.js +259 -0
- package/dist/harness/skills.js.map +1 -0
- package/dist/harness/system-prompt.d.ts +3 -0
- package/dist/harness/system-prompt.d.ts.map +1 -0
- package/dist/harness/system-prompt.js +30 -0
- package/dist/harness/system-prompt.js.map +1 -0
- package/dist/harness/types.d.ts +497 -0
- package/dist/harness/types.d.ts.map +1 -0
- package/dist/harness/types.js +16 -0
- package/dist/harness/types.js.map +1 -0
- package/dist/harness/utils/shell-output.d.ts +14 -0
- package/dist/harness/utils/shell-output.d.ts.map +1 -0
- package/dist/harness/utils/shell-output.js +97 -0
- package/dist/harness/utils/shell-output.js.map +1 -0
- package/dist/harness/utils/truncate.d.ts +70 -0
- package/dist/harness/utils/truncate.d.ts.map +1 -0
- package/dist/harness/utils/truncate.js +205 -0
- package/dist/harness/utils/truncate.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/proxy.d.ts +69 -0
- package/dist/proxy.d.ts.map +1 -0
- package/dist/proxy.js +278 -0
- package/dist/proxy.js.map +1 -0
- package/dist/types.d.ts +386 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +47 -0
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { constants } from "node:fs";
|
|
4
|
+
import { access, lstat, mkdir, mkdtemp, readdir, readFile, realpath, rm, writeFile } from "node:fs/promises";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
7
|
+
import { FileError } from "../types.js";
|
|
8
|
+
function resolvePath(cwd, path) {
|
|
9
|
+
return isAbsolute(path) ? path : resolve(cwd, path);
|
|
10
|
+
}
|
|
11
|
+
function fileKindFromStats(stats) {
|
|
12
|
+
if (stats.isFile())
|
|
13
|
+
return "file";
|
|
14
|
+
if (stats.isDirectory())
|
|
15
|
+
return "directory";
|
|
16
|
+
if (stats.isSymbolicLink())
|
|
17
|
+
return "symlink";
|
|
18
|
+
throw new FileError("invalid", "Unsupported file type");
|
|
19
|
+
}
|
|
20
|
+
function fileInfoFromStats(path, stats) {
|
|
21
|
+
return {
|
|
22
|
+
name: path.replace(/\/+$/, "").split("/").pop() ?? path,
|
|
23
|
+
path,
|
|
24
|
+
kind: fileKindFromStats(stats),
|
|
25
|
+
size: stats.size,
|
|
26
|
+
mtimeMs: stats.mtimeMs,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function isNodeError(error) {
|
|
30
|
+
return error instanceof Error && "code" in error;
|
|
31
|
+
}
|
|
32
|
+
function toFileError(error, path) {
|
|
33
|
+
if (error instanceof FileError)
|
|
34
|
+
return error;
|
|
35
|
+
if (isNodeError(error)) {
|
|
36
|
+
const message = error.message;
|
|
37
|
+
switch (error.code) {
|
|
38
|
+
case "ENOENT":
|
|
39
|
+
return new FileError("not_found", message, path, { cause: error });
|
|
40
|
+
case "EACCES":
|
|
41
|
+
case "EPERM":
|
|
42
|
+
return new FileError("permission_denied", message, path, { cause: error });
|
|
43
|
+
case "ENOTDIR":
|
|
44
|
+
return new FileError("not_directory", message, path, { cause: error });
|
|
45
|
+
case "EISDIR":
|
|
46
|
+
return new FileError("is_directory", message, path, { cause: error });
|
|
47
|
+
case "EINVAL":
|
|
48
|
+
return new FileError("invalid", message, path, { cause: error });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return new FileError("unknown", error instanceof Error ? error.message : String(error), path, { cause: error });
|
|
52
|
+
}
|
|
53
|
+
async function pathExists(path) {
|
|
54
|
+
try {
|
|
55
|
+
await access(path, constants.F_OK);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async function runCommand(command, args, timeoutMs) {
|
|
63
|
+
return await new Promise((resolve) => {
|
|
64
|
+
let stdout = "";
|
|
65
|
+
const child = spawn(command, args, { stdio: ["ignore", "pipe", "ignore"] });
|
|
66
|
+
const timeout = setTimeout(() => {
|
|
67
|
+
if (child.pid)
|
|
68
|
+
killProcessTree(child.pid);
|
|
69
|
+
}, timeoutMs);
|
|
70
|
+
child.stdout?.setEncoding("utf8");
|
|
71
|
+
child.stdout?.on("data", (chunk) => {
|
|
72
|
+
stdout += chunk;
|
|
73
|
+
});
|
|
74
|
+
child.on("error", () => {
|
|
75
|
+
clearTimeout(timeout);
|
|
76
|
+
resolve({ stdout: "", status: null });
|
|
77
|
+
});
|
|
78
|
+
child.on("close", (status) => {
|
|
79
|
+
clearTimeout(timeout);
|
|
80
|
+
resolve({ stdout, status });
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
async function findBashOnPath() {
|
|
85
|
+
const result = process.platform === "win32"
|
|
86
|
+
? await runCommand("where", ["bash.exe"], 5000)
|
|
87
|
+
: await runCommand("which", ["bash"], 5000);
|
|
88
|
+
if (result.status !== 0 || !result.stdout)
|
|
89
|
+
return null;
|
|
90
|
+
const firstMatch = result.stdout.trim().split(/\r?\n/)[0];
|
|
91
|
+
return firstMatch && (await pathExists(firstMatch)) ? firstMatch : null;
|
|
92
|
+
}
|
|
93
|
+
async function getShellConfig(customShellPath) {
|
|
94
|
+
if (customShellPath) {
|
|
95
|
+
if (await pathExists(customShellPath)) {
|
|
96
|
+
return { shell: customShellPath, args: ["-c"] };
|
|
97
|
+
}
|
|
98
|
+
throw new Error(`Custom shell path not found: ${customShellPath}`);
|
|
99
|
+
}
|
|
100
|
+
if (process.platform === "win32") {
|
|
101
|
+
const candidates = [];
|
|
102
|
+
const programFiles = process.env.ProgramFiles;
|
|
103
|
+
if (programFiles)
|
|
104
|
+
candidates.push(`${programFiles}\\Git\\bin\\bash.exe`);
|
|
105
|
+
const programFilesX86 = process.env["ProgramFiles(x86)"];
|
|
106
|
+
if (programFilesX86)
|
|
107
|
+
candidates.push(`${programFilesX86}\\Git\\bin\\bash.exe`);
|
|
108
|
+
for (const candidate of candidates) {
|
|
109
|
+
if (await pathExists(candidate)) {
|
|
110
|
+
return { shell: candidate, args: ["-c"] };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const bashOnPath = await findBashOnPath();
|
|
114
|
+
if (bashOnPath) {
|
|
115
|
+
return { shell: bashOnPath, args: ["-c"] };
|
|
116
|
+
}
|
|
117
|
+
throw new Error("No bash shell found");
|
|
118
|
+
}
|
|
119
|
+
if (await pathExists("/bin/bash")) {
|
|
120
|
+
return { shell: "/bin/bash", args: ["-c"] };
|
|
121
|
+
}
|
|
122
|
+
const bashOnPath = await findBashOnPath();
|
|
123
|
+
if (bashOnPath) {
|
|
124
|
+
return { shell: bashOnPath, args: ["-c"] };
|
|
125
|
+
}
|
|
126
|
+
return { shell: "sh", args: ["-c"] };
|
|
127
|
+
}
|
|
128
|
+
function getShellEnv(baseEnv, extraEnv) {
|
|
129
|
+
return {
|
|
130
|
+
...process.env,
|
|
131
|
+
...baseEnv,
|
|
132
|
+
...extraEnv,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function killProcessTree(pid) {
|
|
136
|
+
if (process.platform === "win32") {
|
|
137
|
+
try {
|
|
138
|
+
spawn("taskkill", ["/F", "/T", "/PID", String(pid)], {
|
|
139
|
+
stdio: "ignore",
|
|
140
|
+
detached: true,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
// Ignore errors.
|
|
145
|
+
}
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
process.kill(-pid, "SIGKILL");
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
try {
|
|
153
|
+
process.kill(pid, "SIGKILL");
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
// Process already dead.
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
export class NodeExecutionEnv {
|
|
161
|
+
cwd;
|
|
162
|
+
shellPath;
|
|
163
|
+
shellEnv;
|
|
164
|
+
constructor(options) {
|
|
165
|
+
this.cwd = options.cwd;
|
|
166
|
+
this.shellPath = options.shellPath;
|
|
167
|
+
this.shellEnv = options.shellEnv;
|
|
168
|
+
}
|
|
169
|
+
async exec(command, options) {
|
|
170
|
+
const cwd = options?.cwd ? resolvePath(this.cwd, options.cwd) : this.cwd;
|
|
171
|
+
const { shell, args } = await getShellConfig(this.shellPath);
|
|
172
|
+
return await new Promise((resolvePromise, reject) => {
|
|
173
|
+
let stdout = "";
|
|
174
|
+
let stderr = "";
|
|
175
|
+
let settled = false;
|
|
176
|
+
let timedOut = false;
|
|
177
|
+
const child = spawn(shell, [...args, command], {
|
|
178
|
+
cwd,
|
|
179
|
+
detached: process.platform !== "win32",
|
|
180
|
+
env: getShellEnv(this.shellEnv, options?.env),
|
|
181
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
182
|
+
});
|
|
183
|
+
const timeoutId = typeof options?.timeout === "number"
|
|
184
|
+
? setTimeout(() => {
|
|
185
|
+
timedOut = true;
|
|
186
|
+
if (child.pid) {
|
|
187
|
+
killProcessTree(child.pid);
|
|
188
|
+
}
|
|
189
|
+
}, options.timeout * 1000)
|
|
190
|
+
: undefined;
|
|
191
|
+
const onAbort = () => {
|
|
192
|
+
if (child.pid) {
|
|
193
|
+
killProcessTree(child.pid);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
if (options?.signal) {
|
|
197
|
+
if (options.signal.aborted) {
|
|
198
|
+
onAbort();
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
options.signal.addEventListener("abort", onAbort, { once: true });
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
child.stdout?.setEncoding("utf8");
|
|
205
|
+
child.stderr?.setEncoding("utf8");
|
|
206
|
+
child.stdout?.on("data", (chunk) => {
|
|
207
|
+
stdout += chunk;
|
|
208
|
+
options?.onStdout?.(chunk);
|
|
209
|
+
});
|
|
210
|
+
child.stderr?.on("data", (chunk) => {
|
|
211
|
+
stderr += chunk;
|
|
212
|
+
options?.onStderr?.(chunk);
|
|
213
|
+
});
|
|
214
|
+
child.on("error", (error) => {
|
|
215
|
+
if (timeoutId)
|
|
216
|
+
clearTimeout(timeoutId);
|
|
217
|
+
if (options?.signal)
|
|
218
|
+
options.signal.removeEventListener("abort", onAbort);
|
|
219
|
+
if (settled)
|
|
220
|
+
return;
|
|
221
|
+
settled = true;
|
|
222
|
+
reject(error);
|
|
223
|
+
});
|
|
224
|
+
child.on("close", (code) => {
|
|
225
|
+
if (timeoutId)
|
|
226
|
+
clearTimeout(timeoutId);
|
|
227
|
+
if (options?.signal)
|
|
228
|
+
options.signal.removeEventListener("abort", onAbort);
|
|
229
|
+
if (settled)
|
|
230
|
+
return;
|
|
231
|
+
settled = true;
|
|
232
|
+
if (options?.signal?.aborted) {
|
|
233
|
+
reject(new Error("aborted"));
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
if (timedOut) {
|
|
237
|
+
reject(new Error(`timeout:${options?.timeout}`));
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
resolvePromise({ stdout, stderr, exitCode: code ?? 0 });
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
async readTextFile(path) {
|
|
245
|
+
const resolved = resolvePath(this.cwd, path);
|
|
246
|
+
try {
|
|
247
|
+
return await readFile(resolved, "utf8");
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
throw toFileError(error, resolved);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
async readBinaryFile(path) {
|
|
254
|
+
const resolved = resolvePath(this.cwd, path);
|
|
255
|
+
try {
|
|
256
|
+
return await readFile(resolved);
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
throw toFileError(error, resolved);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
async writeFile(path, content) {
|
|
263
|
+
const resolved = resolvePath(this.cwd, path);
|
|
264
|
+
try {
|
|
265
|
+
await mkdir(resolve(resolved, ".."), { recursive: true });
|
|
266
|
+
await writeFile(resolved, content);
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
throw toFileError(error, resolved);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
async fileInfo(path) {
|
|
273
|
+
const resolved = resolvePath(this.cwd, path);
|
|
274
|
+
try {
|
|
275
|
+
return fileInfoFromStats(resolved, await lstat(resolved));
|
|
276
|
+
}
|
|
277
|
+
catch (error) {
|
|
278
|
+
throw toFileError(error, resolved);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
async listDir(path) {
|
|
282
|
+
const resolved = resolvePath(this.cwd, path);
|
|
283
|
+
try {
|
|
284
|
+
const entries = await readdir(resolved, { withFileTypes: true });
|
|
285
|
+
const infos = [];
|
|
286
|
+
for (const entry of entries) {
|
|
287
|
+
const entryPath = resolve(resolved, entry.name);
|
|
288
|
+
try {
|
|
289
|
+
infos.push(fileInfoFromStats(entryPath, await lstat(entryPath)));
|
|
290
|
+
}
|
|
291
|
+
catch (error) {
|
|
292
|
+
if (error instanceof FileError && error.code === "invalid")
|
|
293
|
+
continue;
|
|
294
|
+
throw error;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return infos;
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
throw toFileError(error, resolved);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
async realPath(path) {
|
|
304
|
+
const resolved = resolvePath(this.cwd, path);
|
|
305
|
+
try {
|
|
306
|
+
return await realpath(resolved);
|
|
307
|
+
}
|
|
308
|
+
catch (error) {
|
|
309
|
+
throw toFileError(error, resolved);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
async exists(path) {
|
|
313
|
+
try {
|
|
314
|
+
await this.fileInfo(path);
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
catch (error) {
|
|
318
|
+
if (error instanceof FileError && error.code === "not_found")
|
|
319
|
+
return false;
|
|
320
|
+
throw error;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
async createDir(path, options) {
|
|
324
|
+
await mkdir(resolvePath(this.cwd, path), { recursive: options?.recursive });
|
|
325
|
+
}
|
|
326
|
+
async remove(path, options) {
|
|
327
|
+
const resolved = resolvePath(this.cwd, path);
|
|
328
|
+
try {
|
|
329
|
+
await rm(resolved, { recursive: options?.recursive ?? false, force: options?.force ?? false });
|
|
330
|
+
}
|
|
331
|
+
catch (error) {
|
|
332
|
+
throw toFileError(error, resolved);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
async createTempDir(prefix = "tmp-") {
|
|
336
|
+
return await mkdtemp(join(tmpdir(), prefix));
|
|
337
|
+
}
|
|
338
|
+
async createTempFile(options) {
|
|
339
|
+
const dir = await this.createTempDir("tmp-");
|
|
340
|
+
const filePath = join(dir, `${options?.prefix ?? ""}${randomUUID()}${options?.suffix ?? ""}`);
|
|
341
|
+
await writeFile(filePath, "");
|
|
342
|
+
return filePath;
|
|
343
|
+
}
|
|
344
|
+
async cleanup() {
|
|
345
|
+
// nothing to clean up for the local node implementation
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
//# sourceMappingURL=nodejs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodejs.js","sourceRoot":"","sources":["../../../src/harness/env/nodejs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7G,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAqB,SAAS,EAAgC,MAAM,aAAa,CAAC;AAEzF,SAAS,WAAW,CAAC,GAAW,EAAE,IAAY,EAAU;IACvD,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAA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AC,GAAG,EAAE,GAAG,OAAO,EAAE,MAAM,IAAI,EAAE,GAAG,UAAU,EAAE,GAAG,OAAO,EAAE,MAAM,IAAI,EAAE,EAAE,CAAC,CAAC;QAC9F,MAAM,SAAS,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAC9B,OAAO,QAAQ,CAAC;IAAA,CAChB;IAED,KAAK,CAAC,OAAO,GAAkB;QAC9B,wDAAwD;IADzB,CAE/B;CACD","sourcesContent":["import { spawn } from \"node:child_process\";\nimport { randomUUID } from \"node:crypto\";\nimport { constants } from \"node:fs\";\nimport { access, lstat, mkdir, mkdtemp, readdir, readFile, realpath, rm, writeFile } from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { isAbsolute, join, resolve } from \"node:path\";\nimport { type ExecutionEnv, FileError, type FileInfo, type FileKind } from \"../types.js\";\n\nfunction resolvePath(cwd: string, path: string): string {\n\treturn isAbsolute(path) ? path : resolve(cwd, path);\n}\n\nfunction fileKindFromStats(stats: { isFile(): boolean; isDirectory(): boolean; isSymbolicLink(): boolean }): FileKind {\n\tif (stats.isFile()) return \"file\";\n\tif (stats.isDirectory()) return \"directory\";\n\tif (stats.isSymbolicLink()) return \"symlink\";\n\tthrow new FileError(\"invalid\", \"Unsupported file type\");\n}\n\nfunction fileInfoFromStats(\n\tpath: string,\n\tstats: { isFile(): boolean; isDirectory(): boolean; isSymbolicLink(): boolean; size: number; mtimeMs: number },\n): FileInfo {\n\treturn {\n\t\tname: path.replace(/\\/+$/, \"\").split(\"/\").pop() ?? path,\n\t\tpath,\n\t\tkind: fileKindFromStats(stats),\n\t\tsize: stats.size,\n\t\tmtimeMs: stats.mtimeMs,\n\t};\n}\n\nfunction isNodeError(error: unknown): error is NodeJS.ErrnoException {\n\treturn error instanceof Error && \"code\" in error;\n}\n\nfunction toFileError(error: unknown, path?: string): FileError {\n\tif (error instanceof FileError) return error;\n\tif (isNodeError(error)) {\n\t\tconst message = error.message;\n\t\tswitch (error.code) {\n\t\t\tcase \"ENOENT\":\n\t\t\t\treturn new FileError(\"not_found\", message, path, { cause: error });\n\t\t\tcase \"EACCES\":\n\t\t\tcase \"EPERM\":\n\t\t\t\treturn new FileError(\"permission_denied\", message, path, { cause: error });\n\t\t\tcase \"ENOTDIR\":\n\t\t\t\treturn new FileError(\"not_directory\", message, path, { cause: error });\n\t\t\tcase \"EISDIR\":\n\t\t\t\treturn new FileError(\"is_directory\", message, path, { cause: error });\n\t\t\tcase \"EINVAL\":\n\t\t\t\treturn new FileError(\"invalid\", message, path, { cause: error });\n\t\t}\n\t}\n\treturn new FileError(\"unknown\", error instanceof Error ? error.message : String(error), path, { cause: error });\n}\n\nasync function pathExists(path: string): Promise<boolean> {\n\ttry {\n\t\tawait access(path, constants.F_OK);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nasync function runCommand(\n\tcommand: string,\n\targs: string[],\n\ttimeoutMs: number,\n): Promise<{ stdout: string; status: number | null }> {\n\treturn await new Promise((resolve) => {\n\t\tlet stdout = \"\";\n\t\tconst child = spawn(command, args, { stdio: [\"ignore\", \"pipe\", \"ignore\"] });\n\t\tconst timeout = setTimeout(() => {\n\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t}, timeoutMs);\n\t\tchild.stdout?.setEncoding(\"utf8\");\n\t\tchild.stdout?.on(\"data\", (chunk: string) => {\n\t\t\tstdout += chunk;\n\t\t});\n\t\tchild.on(\"error\", () => {\n\t\t\tclearTimeout(timeout);\n\t\t\tresolve({ stdout: \"\", status: null });\n\t\t});\n\t\tchild.on(\"close\", (status) => {\n\t\t\tclearTimeout(timeout);\n\t\t\tresolve({ stdout, status });\n\t\t});\n\t});\n}\n\nasync function findBashOnPath(): Promise<string | null> {\n\tconst result =\n\t\tprocess.platform === \"win32\"\n\t\t\t? await runCommand(\"where\", [\"bash.exe\"], 5000)\n\t\t\t: await runCommand(\"which\", [\"bash\"], 5000);\n\tif (result.status !== 0 || !result.stdout) return null;\n\tconst firstMatch = result.stdout.trim().split(/\\r?\\n/)[0];\n\treturn firstMatch && (await pathExists(firstMatch)) ? firstMatch : null;\n}\n\nasync function getShellConfig(customShellPath?: string): Promise<{ shell: string; args: string[] }> {\n\tif (customShellPath) {\n\t\tif (await pathExists(customShellPath)) {\n\t\t\treturn { shell: customShellPath, args: [\"-c\"] };\n\t\t}\n\t\tthrow new Error(`Custom shell path not found: ${customShellPath}`);\n\t}\n\tif (process.platform === \"win32\") {\n\t\tconst candidates: string[] = [];\n\t\tconst programFiles = process.env.ProgramFiles;\n\t\tif (programFiles) candidates.push(`${programFiles}\\\\Git\\\\bin\\\\bash.exe`);\n\t\tconst programFilesX86 = process.env[\"ProgramFiles(x86)\"];\n\t\tif (programFilesX86) candidates.push(`${programFilesX86}\\\\Git\\\\bin\\\\bash.exe`);\n\t\tfor (const candidate of candidates) {\n\t\t\tif (await pathExists(candidate)) {\n\t\t\t\treturn { shell: candidate, args: [\"-c\"] };\n\t\t\t}\n\t\t}\n\t\tconst bashOnPath = await findBashOnPath();\n\t\tif (bashOnPath) {\n\t\t\treturn { shell: bashOnPath, args: [\"-c\"] };\n\t\t}\n\t\tthrow new Error(\"No bash shell found\");\n\t}\n\n\tif (await pathExists(\"/bin/bash\")) {\n\t\treturn { shell: \"/bin/bash\", args: [\"-c\"] };\n\t}\n\tconst bashOnPath = await findBashOnPath();\n\tif (bashOnPath) {\n\t\treturn { shell: bashOnPath, args: [\"-c\"] };\n\t}\n\treturn { shell: \"sh\", args: [\"-c\"] };\n}\n\nfunction getShellEnv(baseEnv?: NodeJS.ProcessEnv, extraEnv?: Record<string, string>): NodeJS.ProcessEnv {\n\treturn {\n\t\t...process.env,\n\t\t...baseEnv,\n\t\t...extraEnv,\n\t};\n}\n\nfunction killProcessTree(pid: number): void {\n\tif (process.platform === \"win32\") {\n\t\ttry {\n\t\t\tspawn(\"taskkill\", [\"/F\", \"/T\", \"/PID\", String(pid)], {\n\t\t\t\tstdio: \"ignore\",\n\t\t\t\tdetached: true,\n\t\t\t});\n\t\t} catch {\n\t\t\t// Ignore errors.\n\t\t}\n\t\treturn;\n\t}\n\n\ttry {\n\t\tprocess.kill(-pid, \"SIGKILL\");\n\t} catch {\n\t\ttry {\n\t\t\tprocess.kill(pid, \"SIGKILL\");\n\t\t} catch {\n\t\t\t// Process already dead.\n\t\t}\n\t}\n}\n\nexport class NodeExecutionEnv implements ExecutionEnv {\n\tcwd: string;\n\tprivate shellPath?: string;\n\tprivate shellEnv?: NodeJS.ProcessEnv;\n\n\tconstructor(options: { cwd: string; shellPath?: string; shellEnv?: NodeJS.ProcessEnv }) {\n\t\tthis.cwd = options.cwd;\n\t\tthis.shellPath = options.shellPath;\n\t\tthis.shellEnv = options.shellEnv;\n\t}\n\n\tasync exec(\n\t\tcommand: string,\n\t\toptions?: {\n\t\t\tcwd?: string;\n\t\t\tenv?: Record<string, string>;\n\t\t\ttimeout?: number;\n\t\t\tsignal?: AbortSignal;\n\t\t\tonStdout?: (chunk: string) => void;\n\t\t\tonStderr?: (chunk: string) => void;\n\t\t},\n\t): Promise<{ stdout: string; stderr: string; exitCode: number }> {\n\t\tconst cwd = options?.cwd ? resolvePath(this.cwd, options.cwd) : this.cwd;\n\t\tconst { shell, args } = await getShellConfig(this.shellPath);\n\n\t\treturn await new Promise((resolvePromise, reject) => {\n\t\t\tlet stdout = \"\";\n\t\t\tlet stderr = \"\";\n\t\t\tlet settled = false;\n\t\t\tlet timedOut = false;\n\t\t\tconst child = spawn(shell, [...args, command], {\n\t\t\t\tcwd,\n\t\t\t\tdetached: process.platform !== \"win32\",\n\t\t\t\tenv: getShellEnv(this.shellEnv, options?.env),\n\t\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t\t});\n\n\t\t\tconst timeoutId =\n\t\t\t\ttypeof options?.timeout === \"number\"\n\t\t\t\t\t? setTimeout(() => {\n\t\t\t\t\t\t\ttimedOut = true;\n\t\t\t\t\t\t\tif (child.pid) {\n\t\t\t\t\t\t\t\tkillProcessTree(child.pid);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}, options.timeout * 1000)\n\t\t\t\t\t: undefined;\n\n\t\t\tconst onAbort = () => {\n\t\t\t\tif (child.pid) {\n\t\t\t\t\tkillProcessTree(child.pid);\n\t\t\t\t}\n\t\t\t};\n\t\t\tif (options?.signal) {\n\t\t\t\tif (options.signal.aborted) {\n\t\t\t\t\tonAbort();\n\t\t\t\t} else {\n\t\t\t\t\toptions.signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tchild.stdout?.setEncoding(\"utf8\");\n\t\t\tchild.stderr?.setEncoding(\"utf8\");\n\t\t\tchild.stdout?.on(\"data\", (chunk: string) => {\n\t\t\t\tstdout += chunk;\n\t\t\t\toptions?.onStdout?.(chunk);\n\t\t\t});\n\t\t\tchild.stderr?.on(\"data\", (chunk: string) => {\n\t\t\t\tstderr += chunk;\n\t\t\t\toptions?.onStderr?.(chunk);\n\t\t\t});\n\n\t\t\tchild.on(\"error\", (error) => {\n\t\t\t\tif (timeoutId) clearTimeout(timeoutId);\n\t\t\t\tif (options?.signal) options.signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\tif (settled) return;\n\t\t\t\tsettled = true;\n\t\t\t\treject(error);\n\t\t\t});\n\n\t\t\tchild.on(\"close\", (code) => {\n\t\t\t\tif (timeoutId) clearTimeout(timeoutId);\n\t\t\t\tif (options?.signal) options.signal.removeEventListener(\"abort\", onAbort);\n\t\t\t\tif (settled) return;\n\t\t\t\tsettled = true;\n\t\t\t\tif (options?.signal?.aborted) {\n\t\t\t\t\treject(new Error(\"aborted\"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (timedOut) {\n\t\t\t\t\treject(new Error(`timeout:${options?.timeout}`));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tresolvePromise({ stdout, stderr, exitCode: code ?? 0 });\n\t\t\t});\n\t\t});\n\t}\n\n\tasync readTextFile(path: string): Promise<string> {\n\t\tconst resolved = resolvePath(this.cwd, path);\n\t\ttry {\n\t\t\treturn await readFile(resolved, \"utf8\");\n\t\t} catch (error) {\n\t\t\tthrow toFileError(error, resolved);\n\t\t}\n\t}\n\n\tasync readBinaryFile(path: string): Promise<Uint8Array> {\n\t\tconst resolved = resolvePath(this.cwd, path);\n\t\ttry {\n\t\t\treturn await readFile(resolved);\n\t\t} catch (error) {\n\t\t\tthrow toFileError(error, resolved);\n\t\t}\n\t}\n\n\tasync writeFile(path: string, content: string | Uint8Array): Promise<void> {\n\t\tconst resolved = resolvePath(this.cwd, path);\n\t\ttry {\n\t\t\tawait mkdir(resolve(resolved, \"..\"), { recursive: true });\n\t\t\tawait writeFile(resolved, content);\n\t\t} catch (error) {\n\t\t\tthrow toFileError(error, resolved);\n\t\t}\n\t}\n\n\tasync fileInfo(path: string): Promise<FileInfo> {\n\t\tconst resolved = resolvePath(this.cwd, path);\n\t\ttry {\n\t\t\treturn fileInfoFromStats(resolved, await lstat(resolved));\n\t\t} catch (error) {\n\t\t\tthrow toFileError(error, resolved);\n\t\t}\n\t}\n\n\tasync listDir(path: string): Promise<FileInfo[]> {\n\t\tconst resolved = resolvePath(this.cwd, path);\n\t\ttry {\n\t\t\tconst entries = await readdir(resolved, { withFileTypes: true });\n\t\t\tconst infos: FileInfo[] = [];\n\t\t\tfor (const entry of entries) {\n\t\t\t\tconst entryPath = resolve(resolved, entry.name);\n\t\t\t\ttry {\n\t\t\t\t\tinfos.push(fileInfoFromStats(entryPath, await lstat(entryPath)));\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (error instanceof FileError && error.code === \"invalid\") continue;\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn infos;\n\t\t} catch (error) {\n\t\t\tthrow toFileError(error, resolved);\n\t\t}\n\t}\n\n\tasync realPath(path: string): Promise<string> {\n\t\tconst resolved = resolvePath(this.cwd, path);\n\t\ttry {\n\t\t\treturn await realpath(resolved);\n\t\t} catch (error) {\n\t\t\tthrow toFileError(error, resolved);\n\t\t}\n\t}\n\n\tasync exists(path: string): Promise<boolean> {\n\t\ttry {\n\t\t\tawait this.fileInfo(path);\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tif (error instanceof FileError && error.code === \"not_found\") return false;\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tasync createDir(path: string, options?: { recursive?: boolean }): Promise<void> {\n\t\tawait mkdir(resolvePath(this.cwd, path), { recursive: options?.recursive });\n\t}\n\n\tasync remove(path: string, options?: { recursive?: boolean; force?: boolean }): Promise<void> {\n\t\tconst resolved = resolvePath(this.cwd, path);\n\t\ttry {\n\t\t\tawait rm(resolved, { recursive: options?.recursive ?? false, force: options?.force ?? false });\n\t\t} catch (error) {\n\t\t\tthrow toFileError(error, resolved);\n\t\t}\n\t}\n\n\tasync createTempDir(prefix: string = \"tmp-\"): Promise<string> {\n\t\treturn await mkdtemp(join(tmpdir(), prefix));\n\t}\n\n\tasync createTempFile(options?: { prefix?: string; suffix?: string }): Promise<string> {\n\t\tconst dir = await this.createTempDir(\"tmp-\");\n\t\tconst filePath = join(dir, `${options?.prefix ?? \"\"}${randomUUID()}${options?.suffix ?? \"\"}`);\n\t\tawait writeFile(filePath, \"\");\n\t\treturn filePath;\n\t}\n\n\tasync cleanup(): Promise<void> {\n\t\t// nothing to clean up for the local node implementation\n\t}\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution-env.d.ts","sourceRoot":"","sources":["../../src/harness/execution-env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,YAAY,EAAE,YAAY,EAAE,uBAAuB,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3G,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC","sourcesContent":["export { NodeExecutionEnv } from \"./env/nodejs.js\";\nexport type { ExecutionEnv, ExecutionEnvExecOptions, FileErrorCode, FileInfo, FileKind } from \"./types.js\";\nexport { FileError } from \"./types.js\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution-env.js","sourceRoot":"","sources":["../../src/harness/execution-env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC","sourcesContent":["export { NodeExecutionEnv } from \"./env/nodejs.js\";\nexport type { ExecutionEnv, ExecutionEnvExecOptions, FileErrorCode, FileInfo, FileKind } from \"./types.js\";\nexport { FileError } from \"./types.js\";\n"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ImageContent, Message, TextContent } from "@elyracode/ai";
|
|
2
|
+
import type { AgentMessage } from "../types.js";
|
|
3
|
+
export declare const COMPACTION_SUMMARY_PREFIX = "The conversation history before this point was compacted into the following summary:\n\n<summary>\n";
|
|
4
|
+
export declare const COMPACTION_SUMMARY_SUFFIX = "\n</summary>";
|
|
5
|
+
export declare const BRANCH_SUMMARY_PREFIX = "The following is a summary of a branch that this conversation came back from:\n\n<summary>\n";
|
|
6
|
+
export declare const BRANCH_SUMMARY_SUFFIX = "</summary>";
|
|
7
|
+
export interface BashExecutionMessage {
|
|
8
|
+
role: "bashExecution";
|
|
9
|
+
command: string;
|
|
10
|
+
output: string;
|
|
11
|
+
exitCode: number | undefined;
|
|
12
|
+
cancelled: boolean;
|
|
13
|
+
truncated: boolean;
|
|
14
|
+
fullOutputPath?: string;
|
|
15
|
+
timestamp: number;
|
|
16
|
+
excludeFromContext?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface CustomMessage<T = unknown> {
|
|
19
|
+
role: "custom";
|
|
20
|
+
customType: string;
|
|
21
|
+
content: string | (TextContent | ImageContent)[];
|
|
22
|
+
display: boolean;
|
|
23
|
+
details?: T;
|
|
24
|
+
timestamp: number;
|
|
25
|
+
}
|
|
26
|
+
export interface BranchSummaryMessage {
|
|
27
|
+
role: "branchSummary";
|
|
28
|
+
summary: string;
|
|
29
|
+
fromId: string;
|
|
30
|
+
timestamp: number;
|
|
31
|
+
}
|
|
32
|
+
export interface CompactionSummaryMessage {
|
|
33
|
+
role: "compactionSummary";
|
|
34
|
+
summary: string;
|
|
35
|
+
tokensBefore: number;
|
|
36
|
+
timestamp: number;
|
|
37
|
+
}
|
|
38
|
+
declare module "../types.js" {
|
|
39
|
+
interface CustomAgentMessages {
|
|
40
|
+
bashExecution: BashExecutionMessage;
|
|
41
|
+
custom: CustomMessage;
|
|
42
|
+
branchSummary: BranchSummaryMessage;
|
|
43
|
+
compactionSummary: CompactionSummaryMessage;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export declare function bashExecutionToText(msg: BashExecutionMessage): string;
|
|
47
|
+
export declare function createBranchSummaryMessage(summary: string, fromId: string, timestamp: string): BranchSummaryMessage;
|
|
48
|
+
export declare function createCompactionSummaryMessage(summary: string, tokensBefore: number, timestamp: string): CompactionSummaryMessage;
|
|
49
|
+
export declare function createCustomMessage(customType: string, content: string | (TextContent | ImageContent)[], display: boolean, details: unknown | undefined, timestamp: string): CustomMessage;
|
|
50
|
+
export declare function convertToLlm(messages: AgentMessage[]): Message[];
|
|
51
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/harness/messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,eAAO,MAAM,yBAAyB,wGAGrC,CAAC;AAEF,eAAO,MAAM,yBAAyB,iBAC3B,CAAC;AAEZ,eAAO,MAAM,qBAAqB,iGAGjC,CAAC;AAEF,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAEl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AAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,oBAAoB,CAOnH;AAED,wBAAgB,8BAA8B,CAC7C,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,GACf,wBAAwB,CAO1B;AAED,wBAAgB,mBAAmB,CAClC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,GAAG,CAAC,WAAW,GAAG,YAAY,CAAC,EAAE,EAChD,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,GAAG,SAAS,EAC5B,SAAS,EAAE,MAAM,GACf,aAAa,CASf;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,OAAO,EAAE,CA4ChE","sourcesContent":["import type { ImageContent, Message, TextContent } from \"@elyracode/ai\";\nimport type { AgentMessage } from \"../types.js\";\n\nexport const COMPACTION_SUMMARY_PREFIX = `The conversation history before this point was compacted into the following summary:\n\n<summary>\n`;\n\nexport const COMPACTION_SUMMARY_SUFFIX = `\n</summary>`;\n\nexport const BRANCH_SUMMARY_PREFIX = `The following is a summary of a branch that this conversation came back from:\n\n<summary>\n`;\n\nexport const BRANCH_SUMMARY_SUFFIX = `</summary>`;\n\nexport interface BashExecutionMessage {\n\trole: \"bashExecution\";\n\tcommand: string;\n\toutput: string;\n\texitCode: number | undefined;\n\tcancelled: boolean;\n\ttruncated: boolean;\n\tfullOutputPath?: string;\n\ttimestamp: number;\n\texcludeFromContext?: boolean;\n}\n\nexport interface CustomMessage<T = unknown> {\n\trole: \"custom\";\n\tcustomType: string;\n\tcontent: string | (TextContent | ImageContent)[];\n\tdisplay: boolean;\n\tdetails?: T;\n\ttimestamp: number;\n}\n\nexport interface BranchSummaryMessage {\n\trole: \"branchSummary\";\n\tsummary: string;\n\tfromId: string;\n\ttimestamp: number;\n}\n\nexport interface CompactionSummaryMessage {\n\trole: \"compactionSummary\";\n\tsummary: string;\n\ttokensBefore: number;\n\ttimestamp: number;\n}\n\ndeclare module \"../types.js\" {\n\tinterface CustomAgentMessages {\n\t\tbashExecution: BashExecutionMessage;\n\t\tcustom: CustomMessage;\n\t\tbranchSummary: BranchSummaryMessage;\n\t\tcompactionSummary: CompactionSummaryMessage;\n\t}\n}\n\nexport function bashExecutionToText(msg: BashExecutionMessage): string {\n\tlet text = `Ran \\`${msg.command}\\`\\n`;\n\tif (msg.output) {\n\t\ttext += `\\`\\`\\`\\n${msg.output}\\n\\`\\`\\``;\n\t} else {\n\t\ttext += \"(no output)\";\n\t}\n\tif (msg.cancelled) {\n\t\ttext += \"\\n\\n(command cancelled)\";\n\t} else if (msg.exitCode !== null && msg.exitCode !== undefined && msg.exitCode !== 0) {\n\t\ttext += `\\n\\nCommand exited with code ${msg.exitCode}`;\n\t}\n\tif (msg.truncated && msg.fullOutputPath) {\n\t\ttext += `\\n\\n[Output truncated. Full output: ${msg.fullOutputPath}]`;\n\t}\n\treturn text;\n}\n\nexport function createBranchSummaryMessage(summary: string, fromId: string, timestamp: string): BranchSummaryMessage {\n\treturn {\n\t\trole: \"branchSummary\",\n\t\tsummary,\n\t\tfromId,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\nexport function createCompactionSummaryMessage(\n\tsummary: string,\n\ttokensBefore: number,\n\ttimestamp: string,\n): CompactionSummaryMessage {\n\treturn {\n\t\trole: \"compactionSummary\",\n\t\tsummary,\n\t\ttokensBefore,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\nexport function createCustomMessage(\n\tcustomType: string,\n\tcontent: string | (TextContent | ImageContent)[],\n\tdisplay: boolean,\n\tdetails: unknown | undefined,\n\ttimestamp: string,\n): CustomMessage {\n\treturn {\n\t\trole: \"custom\",\n\t\tcustomType,\n\t\tcontent,\n\t\tdisplay,\n\t\tdetails,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\nexport function convertToLlm(messages: AgentMessage[]): Message[] {\n\treturn messages\n\t\t.map((m): Message | undefined => {\n\t\t\tswitch (m.role) {\n\t\t\t\tcase \"bashExecution\":\n\t\t\t\t\tif (m.excludeFromContext) {\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: bashExecutionToText(m) }],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"custom\": {\n\t\t\t\t\tconst content = typeof m.content === \"string\" ? [{ type: \"text\" as const, text: m.content }] : m.content;\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent,\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tcase \"branchSummary\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: BRANCH_SUMMARY_PREFIX + m.summary + BRANCH_SUMMARY_SUFFIX }],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"compactionSummary\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{ type: \"text\" as const, text: COMPACTION_SUMMARY_PREFIX + m.summary + COMPACTION_SUMMARY_SUFFIX },\n\t\t\t\t\t\t],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"user\":\n\t\t\t\tcase \"assistant\":\n\t\t\t\tcase \"toolResult\":\n\t\t\t\t\treturn m;\n\t\t\t\tdefault:\n\t\t\t\t\treturn undefined;\n\t\t\t}\n\t\t})\n\t\t.filter((m): m is Message => m !== undefined);\n}\n"]}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
export const COMPACTION_SUMMARY_PREFIX = `The conversation history before this point was compacted into the following summary:
|
|
2
|
+
|
|
3
|
+
<summary>
|
|
4
|
+
`;
|
|
5
|
+
export const COMPACTION_SUMMARY_SUFFIX = `
|
|
6
|
+
</summary>`;
|
|
7
|
+
export const BRANCH_SUMMARY_PREFIX = `The following is a summary of a branch that this conversation came back from:
|
|
8
|
+
|
|
9
|
+
<summary>
|
|
10
|
+
`;
|
|
11
|
+
export const BRANCH_SUMMARY_SUFFIX = `</summary>`;
|
|
12
|
+
export function bashExecutionToText(msg) {
|
|
13
|
+
let text = `Ran \`${msg.command}\`\n`;
|
|
14
|
+
if (msg.output) {
|
|
15
|
+
text += `\`\`\`\n${msg.output}\n\`\`\``;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
text += "(no output)";
|
|
19
|
+
}
|
|
20
|
+
if (msg.cancelled) {
|
|
21
|
+
text += "\n\n(command cancelled)";
|
|
22
|
+
}
|
|
23
|
+
else if (msg.exitCode !== null && msg.exitCode !== undefined && msg.exitCode !== 0) {
|
|
24
|
+
text += `\n\nCommand exited with code ${msg.exitCode}`;
|
|
25
|
+
}
|
|
26
|
+
if (msg.truncated && msg.fullOutputPath) {
|
|
27
|
+
text += `\n\n[Output truncated. Full output: ${msg.fullOutputPath}]`;
|
|
28
|
+
}
|
|
29
|
+
return text;
|
|
30
|
+
}
|
|
31
|
+
export function createBranchSummaryMessage(summary, fromId, timestamp) {
|
|
32
|
+
return {
|
|
33
|
+
role: "branchSummary",
|
|
34
|
+
summary,
|
|
35
|
+
fromId,
|
|
36
|
+
timestamp: new Date(timestamp).getTime(),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export function createCompactionSummaryMessage(summary, tokensBefore, timestamp) {
|
|
40
|
+
return {
|
|
41
|
+
role: "compactionSummary",
|
|
42
|
+
summary,
|
|
43
|
+
tokensBefore,
|
|
44
|
+
timestamp: new Date(timestamp).getTime(),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export function createCustomMessage(customType, content, display, details, timestamp) {
|
|
48
|
+
return {
|
|
49
|
+
role: "custom",
|
|
50
|
+
customType,
|
|
51
|
+
content,
|
|
52
|
+
display,
|
|
53
|
+
details,
|
|
54
|
+
timestamp: new Date(timestamp).getTime(),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export function convertToLlm(messages) {
|
|
58
|
+
return messages
|
|
59
|
+
.map((m) => {
|
|
60
|
+
switch (m.role) {
|
|
61
|
+
case "bashExecution":
|
|
62
|
+
if (m.excludeFromContext) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
role: "user",
|
|
67
|
+
content: [{ type: "text", text: bashExecutionToText(m) }],
|
|
68
|
+
timestamp: m.timestamp,
|
|
69
|
+
};
|
|
70
|
+
case "custom": {
|
|
71
|
+
const content = typeof m.content === "string" ? [{ type: "text", text: m.content }] : m.content;
|
|
72
|
+
return {
|
|
73
|
+
role: "user",
|
|
74
|
+
content,
|
|
75
|
+
timestamp: m.timestamp,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
case "branchSummary":
|
|
79
|
+
return {
|
|
80
|
+
role: "user",
|
|
81
|
+
content: [{ type: "text", text: BRANCH_SUMMARY_PREFIX + m.summary + BRANCH_SUMMARY_SUFFIX }],
|
|
82
|
+
timestamp: m.timestamp,
|
|
83
|
+
};
|
|
84
|
+
case "compactionSummary":
|
|
85
|
+
return {
|
|
86
|
+
role: "user",
|
|
87
|
+
content: [
|
|
88
|
+
{ type: "text", text: COMPACTION_SUMMARY_PREFIX + m.summary + COMPACTION_SUMMARY_SUFFIX },
|
|
89
|
+
],
|
|
90
|
+
timestamp: m.timestamp,
|
|
91
|
+
};
|
|
92
|
+
case "user":
|
|
93
|
+
case "assistant":
|
|
94
|
+
case "toolResult":
|
|
95
|
+
return m;
|
|
96
|
+
default:
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
})
|
|
100
|
+
.filter((m) => m !== undefined);
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=messages.js.map
|
|
@@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S,EAAE,CAAC,CAAC,SAAS;iBACtB,CAAC;YACH,CAAC;YACD,KAAK,eAAe;gBACnB,OAAO;oBACN,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,qBAAqB,GAAG,CAAC,CAAC,OAAO,GAAG,qBAAqB,EAAE,CAAC;oBACrG,SAAS,EAAE,CAAC,CAAC,SAAS;iBACtB,CAAC;YACH,KAAK,mBAAmB;gBACvB,OAAO;oBACN,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE;wBACR,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,yBAAyB,GAAG,CAAC,CAAC,OAAO,GAAG,yBAAyB,EAAE;qBAClG;oBACD,SAAS,EAAE,CAAC,CAAC,SAAS;iBACtB,CAAC;YACH,KAAK,MAAM,CAAC;YACZ,KAAK,WAAW,CAAC;YACjB,KAAK,YAAY;gBAChB,OAAO,CAAC,CAAC;YACV;gBACC,OAAO,SAAS,CAAC;QACnB,CAAC;IAAA,CACD,CAAC;SACD,MAAM,CAAC,CAAC,CAAC,EAAgB,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;AAAA,CAC/C","sourcesContent":["import type { ImageContent, Message, TextContent } from \"@elyracode/ai\";\nimport type { AgentMessage } from \"../types.js\";\n\nexport const COMPACTION_SUMMARY_PREFIX = `The conversation history before this point was compacted into the following summary:\n\n<summary>\n`;\n\nexport const COMPACTION_SUMMARY_SUFFIX = `\n</summary>`;\n\nexport const BRANCH_SUMMARY_PREFIX = `The following is a summary of a branch that this conversation came back from:\n\n<summary>\n`;\n\nexport const BRANCH_SUMMARY_SUFFIX = `</summary>`;\n\nexport interface BashExecutionMessage {\n\trole: \"bashExecution\";\n\tcommand: string;\n\toutput: string;\n\texitCode: number | undefined;\n\tcancelled: boolean;\n\ttruncated: boolean;\n\tfullOutputPath?: string;\n\ttimestamp: number;\n\texcludeFromContext?: boolean;\n}\n\nexport interface CustomMessage<T = unknown> {\n\trole: \"custom\";\n\tcustomType: string;\n\tcontent: string | (TextContent | ImageContent)[];\n\tdisplay: boolean;\n\tdetails?: T;\n\ttimestamp: number;\n}\n\nexport interface BranchSummaryMessage {\n\trole: \"branchSummary\";\n\tsummary: string;\n\tfromId: string;\n\ttimestamp: number;\n}\n\nexport interface CompactionSummaryMessage {\n\trole: \"compactionSummary\";\n\tsummary: string;\n\ttokensBefore: number;\n\ttimestamp: number;\n}\n\ndeclare module \"../types.js\" {\n\tinterface CustomAgentMessages {\n\t\tbashExecution: BashExecutionMessage;\n\t\tcustom: CustomMessage;\n\t\tbranchSummary: BranchSummaryMessage;\n\t\tcompactionSummary: CompactionSummaryMessage;\n\t}\n}\n\nexport function bashExecutionToText(msg: BashExecutionMessage): string {\n\tlet text = `Ran \\`${msg.command}\\`\\n`;\n\tif (msg.output) {\n\t\ttext += `\\`\\`\\`\\n${msg.output}\\n\\`\\`\\``;\n\t} else {\n\t\ttext += \"(no output)\";\n\t}\n\tif (msg.cancelled) {\n\t\ttext += \"\\n\\n(command cancelled)\";\n\t} else if (msg.exitCode !== null && msg.exitCode !== undefined && msg.exitCode !== 0) {\n\t\ttext += `\\n\\nCommand exited with code ${msg.exitCode}`;\n\t}\n\tif (msg.truncated && msg.fullOutputPath) {\n\t\ttext += `\\n\\n[Output truncated. Full output: ${msg.fullOutputPath}]`;\n\t}\n\treturn text;\n}\n\nexport function createBranchSummaryMessage(summary: string, fromId: string, timestamp: string): BranchSummaryMessage {\n\treturn {\n\t\trole: \"branchSummary\",\n\t\tsummary,\n\t\tfromId,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\nexport function createCompactionSummaryMessage(\n\tsummary: string,\n\ttokensBefore: number,\n\ttimestamp: string,\n): CompactionSummaryMessage {\n\treturn {\n\t\trole: \"compactionSummary\",\n\t\tsummary,\n\t\ttokensBefore,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\nexport function createCustomMessage(\n\tcustomType: string,\n\tcontent: string | (TextContent | ImageContent)[],\n\tdisplay: boolean,\n\tdetails: unknown | undefined,\n\ttimestamp: string,\n): CustomMessage {\n\treturn {\n\t\trole: \"custom\",\n\t\tcustomType,\n\t\tcontent,\n\t\tdisplay,\n\t\tdetails,\n\t\ttimestamp: new Date(timestamp).getTime(),\n\t};\n}\n\nexport function convertToLlm(messages: AgentMessage[]): Message[] {\n\treturn messages\n\t\t.map((m): Message | undefined => {\n\t\t\tswitch (m.role) {\n\t\t\t\tcase \"bashExecution\":\n\t\t\t\t\tif (m.excludeFromContext) {\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\", text: bashExecutionToText(m) }],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"custom\": {\n\t\t\t\t\tconst content = typeof m.content === \"string\" ? [{ type: \"text\" as const, text: m.content }] : m.content;\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent,\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tcase \"branchSummary\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [{ type: \"text\" as const, text: BRANCH_SUMMARY_PREFIX + m.summary + BRANCH_SUMMARY_SUFFIX }],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"compactionSummary\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t{ type: \"text\" as const, text: COMPACTION_SUMMARY_PREFIX + m.summary + COMPACTION_SUMMARY_SUFFIX },\n\t\t\t\t\t\t],\n\t\t\t\t\t\ttimestamp: m.timestamp,\n\t\t\t\t\t};\n\t\t\t\tcase \"user\":\n\t\t\t\tcase \"assistant\":\n\t\t\t\tcase \"toolResult\":\n\t\t\t\t\treturn m;\n\t\t\t\tdefault:\n\t\t\t\t\treturn undefined;\n\t\t\t}\n\t\t})\n\t\t.filter((m): m is Message => m !== undefined);\n}\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ExecutionEnv, PromptTemplate } from "./types.js";
|
|
2
|
+
/** Warning produced while loading prompt templates. */
|
|
3
|
+
export interface PromptTemplateDiagnostic {
|
|
4
|
+
/** Diagnostic severity. Currently only warnings are emitted. */
|
|
5
|
+
type: "warning";
|
|
6
|
+
/** Human-readable diagnostic message. */
|
|
7
|
+
message: string;
|
|
8
|
+
/** Path associated with the diagnostic. */
|
|
9
|
+
path: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Load prompt templates from one or more paths.
|
|
13
|
+
*
|
|
14
|
+
* Directory inputs load direct `.md` children non-recursively. File inputs load explicit `.md` files. Missing paths and
|
|
15
|
+
* non-markdown files are skipped. Read and parse failures are returned as diagnostics.
|
|
16
|
+
*/
|
|
17
|
+
export declare function loadPromptTemplates(env: ExecutionEnv, paths: string | string[]): Promise<{
|
|
18
|
+
promptTemplates: PromptTemplate[];
|
|
19
|
+
diagnostics: PromptTemplateDiagnostic[];
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Load prompt templates from source-tagged paths.
|
|
23
|
+
*
|
|
24
|
+
* Source values are preserved exactly and attached to every loaded prompt template and diagnostic. The agent package does
|
|
25
|
+
* not interpret source values; applications define their own provenance shape.
|
|
26
|
+
*/
|
|
27
|
+
export declare function loadSourcedPromptTemplates<TSource, TPromptTemplate extends PromptTemplate = PromptTemplate>(env: ExecutionEnv, inputs: Array<{
|
|
28
|
+
path: string;
|
|
29
|
+
source: TSource;
|
|
30
|
+
}>, mapPromptTemplate?: (promptTemplate: PromptTemplate, source: TSource) => TPromptTemplate): Promise<{
|
|
31
|
+
promptTemplates: Array<{
|
|
32
|
+
promptTemplate: TPromptTemplate;
|
|
33
|
+
source: TSource;
|
|
34
|
+
}>;
|
|
35
|
+
diagnostics: Array<PromptTemplateDiagnostic & {
|
|
36
|
+
source: TSource;
|
|
37
|
+
}>;
|
|
38
|
+
}>;
|
|
39
|
+
/** Parse an argument string using simple shell-style single and double quotes. */
|
|
40
|
+
export declare function parseCommandArgs(argsString: string): string[];
|
|
41
|
+
/** Substitute prompt template placeholders (`$1`, `$@`, `$ARGUMENTS`, `${@:N}`, `${@:N:L}`) with command arguments. */
|
|
42
|
+
export declare function substituteArgs(content: string, args: string[]): string;
|
|
43
|
+
/** Format a prompt template invocation with positional arguments. */
|
|
44
|
+
export declare function formatPromptTemplateInvocation(template: PromptTemplate, args?: string[]): string;
|
|
45
|
+
//# sourceMappingURL=prompt-templates.d.ts.map
|