replicas-engine 0.1.956 → 0.1.958
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/src/{asp-host-K4TWHT3R.js → asp-host-QI7MAWDJ.js} +5 -5
- package/dist/src/{chunk-FK3P6B55.js → chunk-7GWXM2H5.js} +102 -195
- package/dist/src/{chunk-HOS2IL2Q.js → chunk-FHP2MB2M.js} +3 -3
- package/dist/src/{chunk-GFUPSTN3.js → chunk-LI5QEJBB.js} +6 -6
- package/dist/src/{chunk-MTCAHW2F.js → chunk-NHEZTD3X.js} +1 -3
- package/dist/src/{chunk-YUMGTIR3.js → chunk-SJ6BDSN3.js} +1 -1
- package/dist/src/{chunk-FLDA7BX3.js → chunk-UPCC4BX5.js} +0 -34
- package/dist/src/{chunk-4HVJFYXK.js → chunk-UQ3N4FNZ.js} +1 -1
- package/dist/src/{chunk-HOABEYV2.js → chunk-YEIV5OYO.js} +3 -3
- package/dist/src/{chunk-CYNWRZYJ.js → chunk-YNVHVJQR.js} +1 -1
- package/dist/src/command-protection-hook.js +4 -4
- package/dist/src/headless-agent.js +10 -105
- package/dist/src/index.js +256 -191
- package/dist/src/post-tool-pr-hook.js +2 -2
- package/dist/src/relay-mcp.js +2 -2
- package/package.json +1 -1
|
@@ -2,121 +2,33 @@
|
|
|
2
2
|
import { createRequire as __createRequire } from 'node:module';
|
|
3
3
|
const require = __createRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
|
-
putPresignedFile,
|
|
6
5
|
recoverCompletedTurn
|
|
7
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-UPCC4BX5.js";
|
|
8
7
|
import {
|
|
9
8
|
AppServerProcess,
|
|
10
9
|
buildCodexAgentEnv
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import "./chunk-
|
|
10
|
+
} from "./chunk-FHP2MB2M.js";
|
|
11
|
+
import "./chunk-YNVHVJQR.js";
|
|
13
12
|
import {
|
|
14
13
|
AGENT,
|
|
15
|
-
getMemoryOutputSafetyViolation,
|
|
16
14
|
headlessAgentRequestSchema
|
|
17
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-7GWXM2H5.js";
|
|
18
16
|
import "./chunk-VEQXQN22.js";
|
|
19
17
|
|
|
20
18
|
// src/headless-agent.ts
|
|
21
|
-
import {
|
|
22
|
-
import { createWriteStream } from "fs";
|
|
23
|
-
import { mkdir, readFile, stat, writeFile } from "fs/promises";
|
|
24
|
-
import { request as httpRequest } from "http";
|
|
25
|
-
import { request as httpsRequest } from "https";
|
|
26
|
-
import path from "path";
|
|
19
|
+
import { readFile, writeFile } from "fs/promises";
|
|
27
20
|
import { query } from "@anthropic-ai/claude-agent-sdk";
|
|
28
|
-
var FILESYSTEM_TOOLS = ["Read", "Write", "Edit", "Glob", "Grep"];
|
|
29
|
-
function resolveFile(root, relativePath) {
|
|
30
|
-
if (path.isAbsolute(relativePath)) throw new Error("Headless agent file paths must be relative");
|
|
31
|
-
const resolved = path.resolve(root, relativePath);
|
|
32
|
-
if (resolved === root || !resolved.startsWith(`${root}${path.sep}`)) {
|
|
33
|
-
throw new Error("Headless agent file path escapes its working directory");
|
|
34
|
-
}
|
|
35
|
-
return resolved;
|
|
36
|
-
}
|
|
37
|
-
async function downloadFile(urlValue, destination) {
|
|
38
|
-
await mkdir(path.dirname(destination), { recursive: true, mode: 448 });
|
|
39
|
-
await new Promise((resolve, reject) => {
|
|
40
|
-
const url = new URL(urlValue);
|
|
41
|
-
const request = (url.protocol === "https:" ? httpsRequest : httpRequest)(url, (response) => {
|
|
42
|
-
const status = response.statusCode ?? 0;
|
|
43
|
-
if (status < 200 || status >= 300) {
|
|
44
|
-
response.resume();
|
|
45
|
-
reject(new Error(`File download failed with status ${status}`));
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const file = createWriteStream(destination, { mode: 384 });
|
|
49
|
-
response.on("error", (error) => file.destroy(error));
|
|
50
|
-
file.on("error", reject);
|
|
51
|
-
file.on("finish", resolve);
|
|
52
|
-
response.pipe(file);
|
|
53
|
-
});
|
|
54
|
-
request.on("error", reject);
|
|
55
|
-
request.end();
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
async function stageFilesystemInputs(request) {
|
|
59
|
-
await Promise.all(request.inputFiles.map((file) => downloadFile(
|
|
60
|
-
file.downloadUrl,
|
|
61
|
-
resolveFile(request.workingDirectory, file.path)
|
|
62
|
-
)));
|
|
63
|
-
}
|
|
64
|
-
async function publishFilesystemOutputs(request) {
|
|
65
|
-
const files = {};
|
|
66
|
-
const uploads = [];
|
|
67
|
-
for (const output of request.outputFiles) {
|
|
68
|
-
const filePath = resolveFile(request.workingDirectory, output.path);
|
|
69
|
-
const content = (await readFile(filePath, "utf8")).trim();
|
|
70
|
-
if (output.minChars !== void 0 && content.length < output.minChars) {
|
|
71
|
-
throw new Error(`Headless agent output failed validation: ${output.path} has ${content.length} characters; minimum is ${output.minChars}`);
|
|
72
|
-
}
|
|
73
|
-
const safetyViolation = getMemoryOutputSafetyViolation(content, request.sensitiveValues, output.maxChars);
|
|
74
|
-
if (safetyViolation) {
|
|
75
|
-
const reason = safetyViolation === "max_chars" ? `has ${content.length} characters; maximum is ${output.maxChars}` : safetyViolation === "secret_pattern" ? "contains secret-like content" : "contains an installed credential";
|
|
76
|
-
throw new Error(`Headless agent output failed validation: ${output.path} ${reason}`);
|
|
77
|
-
}
|
|
78
|
-
await writeFile(filePath, content, { mode: 384 });
|
|
79
|
-
const { size } = await stat(filePath);
|
|
80
|
-
files[output.path] = { sha256: createHash("sha256").update(content).digest("hex"), sizeBytes: size };
|
|
81
|
-
uploads.push({ url: output.uploadUrl, path: filePath, contentType: output.contentType, size });
|
|
82
|
-
}
|
|
83
|
-
await Promise.all(uploads.map((upload) => putPresignedFile(
|
|
84
|
-
upload.url,
|
|
85
|
-
upload.path,
|
|
86
|
-
upload.size,
|
|
87
|
-
upload.contentType
|
|
88
|
-
)));
|
|
89
|
-
return files;
|
|
90
|
-
}
|
|
91
|
-
function filesystemPermission(root) {
|
|
92
|
-
return async (toolName, input) => {
|
|
93
|
-
const candidate = input.file_path ?? input.path;
|
|
94
|
-
if (typeof candidate === "string") {
|
|
95
|
-
const resolved = path.resolve(root, candidate);
|
|
96
|
-
if (resolved !== root && !resolved.startsWith(`${root}${path.sep}`)) {
|
|
97
|
-
return { behavior: "deny", message: "Memory maintenance is restricted to its working directory." };
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
if (toolName === "Glob" && typeof input.pattern === "string") {
|
|
101
|
-
if (path.isAbsolute(input.pattern) || input.pattern.split(/[\\/]/).includes("..")) {
|
|
102
|
-
return { behavior: "deny", message: "Memory maintenance is restricted to its working directory." };
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return { behavior: "allow", updatedInput: input };
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
21
|
async function runClaude(request) {
|
|
109
22
|
const response = query({
|
|
110
23
|
prompt: request.prompt,
|
|
111
24
|
options: {
|
|
112
25
|
cwd: request.workingDirectory,
|
|
113
26
|
model: request.model,
|
|
114
|
-
tools:
|
|
115
|
-
permissionMode:
|
|
116
|
-
...request.mode === "filesystem" ? { canUseTool: filesystemPermission(request.workingDirectory) } : {},
|
|
27
|
+
tools: [],
|
|
28
|
+
permissionMode: "dontAsk",
|
|
117
29
|
settingSources: [],
|
|
118
30
|
persistSession: false,
|
|
119
|
-
|
|
31
|
+
outputFormat: { type: "json_schema", schema: request.outputSchema },
|
|
120
32
|
env: { ...process.env, CLAUDE_CODE_DISABLE_AUTO_MEMORY: "1" }
|
|
121
33
|
}
|
|
122
34
|
});
|
|
@@ -130,7 +42,6 @@ async function runClaude(request) {
|
|
|
130
42
|
}
|
|
131
43
|
if (!result) throw new Error("Claude Agent SDK returned no result");
|
|
132
44
|
if (result.subtype !== "success") throw new Error(result.errors.join("\n") || result.subtype);
|
|
133
|
-
if (request.mode === "filesystem") return result.result;
|
|
134
45
|
return result.structured_output ?? JSON.parse(result.result);
|
|
135
46
|
}
|
|
136
47
|
function runCodexTurn(client, params, timeoutMs) {
|
|
@@ -208,19 +119,18 @@ async function runCodex(request) {
|
|
|
208
119
|
cwd: request.workingDirectory,
|
|
209
120
|
approvalPolicy: "never",
|
|
210
121
|
approvalsReviewer: "user",
|
|
211
|
-
sandbox:
|
|
122
|
+
sandbox: "read-only",
|
|
212
123
|
ephemeral: true
|
|
213
124
|
});
|
|
214
125
|
const { turn, message } = await runCodexTurn(client, {
|
|
215
126
|
threadId: thread.thread.id,
|
|
216
127
|
input: [{ type: "text", text: request.prompt, text_elements: [] }],
|
|
217
|
-
|
|
128
|
+
outputSchema: request.outputSchema,
|
|
218
129
|
approvalPolicy: "never",
|
|
219
130
|
approvalsReviewer: "user"
|
|
220
131
|
}, request.timeoutSeconds * 1e3);
|
|
221
132
|
if (turn.status === "failed") throw new Error(turn.error?.message ?? "Codex ASP turn failed");
|
|
222
133
|
if (!message) throw new Error("Codex ASP returned no final message");
|
|
223
|
-
if (request.mode === "filesystem") return message;
|
|
224
134
|
return JSON.parse(message);
|
|
225
135
|
} finally {
|
|
226
136
|
await appServer.stop();
|
|
@@ -230,7 +140,6 @@ async function main() {
|
|
|
230
140
|
const [requestPath, outputPath] = process.argv.slice(2);
|
|
231
141
|
if (!requestPath || !outputPath) throw new Error("Usage: replicas-headless-agent <request.json> <output.json>");
|
|
232
142
|
const request = headlessAgentRequestSchema.parse(JSON.parse(await readFile(requestPath, "utf8")));
|
|
233
|
-
if (request.mode === "filesystem") await stageFilesystemInputs(request);
|
|
234
143
|
let result;
|
|
235
144
|
switch (request.agent) {
|
|
236
145
|
case AGENT.CLAUDE:
|
|
@@ -242,10 +151,6 @@ async function main() {
|
|
|
242
151
|
default:
|
|
243
152
|
throw new Error(`Unsupported headless agent: ${request.agent}`);
|
|
244
153
|
}
|
|
245
|
-
if (request.mode === "filesystem") {
|
|
246
|
-
if (typeof result !== "string") throw new Error("Filesystem agent returned an invalid result");
|
|
247
|
-
result = { message: result, files: await publishFilesystemOutputs(request) };
|
|
248
|
-
}
|
|
249
154
|
await writeFile(outputPath, JSON.stringify(result), { mode: 384 });
|
|
250
155
|
}
|
|
251
156
|
main().catch((error) => {
|