replicas-engine 0.1.957 → 0.1.959
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-65SEKM3Q.js → asp-host-INCEKBYG.js} +5 -5
- package/dist/src/{chunk-42BR2ZBE.js → chunk-4HNUOSLS.js} +4 -5
- package/dist/src/{chunk-CYNWRZYJ.js → chunk-CANEL3IU.js} +1 -1
- package/dist/src/{chunk-FK3P6B55.js → chunk-QXISBAH5.js} +144 -270
- package/dist/src/{chunk-SI6WBUIS.js → chunk-SZTW4OGR.js} +3 -3
- package/dist/src/{chunk-4TRSKDZK.js → chunk-TFD6QK6J.js} +6 -6
- package/dist/src/{chunk-FLDA7BX3.js → chunk-UPCC4BX5.js} +0 -34
- package/dist/src/{chunk-RQXIJ3IG.js → chunk-X76Z5POI.js} +3 -3
- package/dist/src/{chunk-4HVJFYXK.js → chunk-XFGXRH7Q.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 +622 -436
- package/dist/src/post-tool-pr-hook.js +2 -2
- package/dist/src/{relay-mcp.js → subagent-mcp.js} +38 -39
- package/package.json +2 -2
- package/dist/src/chunk-YUMGTIR3.js +0 -45
|
@@ -3,18 +3,18 @@ import { createRequire as __createRequire } from 'node:module';
|
|
|
3
3
|
const require = __createRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
5
|
monolithRequest
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-4HNUOSLS.js";
|
|
7
7
|
import {
|
|
8
8
|
SUBPROCESS_MAX_BUFFER,
|
|
9
9
|
execFileAsync
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-CANEL3IU.js";
|
|
11
11
|
import {
|
|
12
12
|
extractCommandProtectionCommandText,
|
|
13
13
|
findCommandProtectionGitLookups,
|
|
14
14
|
findGitCommitSignals,
|
|
15
15
|
findPrMergeSignals,
|
|
16
16
|
parseCommandProtectionRequest
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-QXISBAH5.js";
|
|
18
18
|
|
|
19
19
|
// src/services/command-protection-service.ts
|
|
20
20
|
import { readFile, stat } from "fs/promises";
|
|
@@ -5,15 +5,15 @@ import {
|
|
|
5
5
|
ENGINE_ENV,
|
|
6
6
|
monolithRequest,
|
|
7
7
|
setAgentCredentialSnapshot
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-4HNUOSLS.js";
|
|
9
9
|
import {
|
|
10
10
|
AppServerProcess,
|
|
11
11
|
buildCodexAgentEnv
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-X76Z5POI.js";
|
|
13
13
|
import {
|
|
14
14
|
SUBPROCESS_MAX_BUFFER,
|
|
15
15
|
execFileAsync
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-CANEL3IU.js";
|
|
17
17
|
import {
|
|
18
18
|
isRecord
|
|
19
19
|
} from "./chunk-UZSNFLDQ.js";
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
listOpenAICompatibleModels,
|
|
28
28
|
readOllamaAuthEnv,
|
|
29
29
|
resolveOpenAICompatibleModelsUrl
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-QXISBAH5.js";
|
|
31
31
|
|
|
32
32
|
// src/managers/codex-token-manager.ts
|
|
33
33
|
import { promises as fs } from "fs";
|
|
@@ -260,7 +260,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
|
|
|
260
260
|
await this.applyCredentialUpdate(++this.credentialGeneration, async () => {
|
|
261
261
|
await this.applyCredentialsResponse(data);
|
|
262
262
|
setAgentCredentialSnapshot("codex", data);
|
|
263
|
-
const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-
|
|
263
|
+
const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-INCEKBYG.js");
|
|
264
264
|
await restartCodexAspHostIfRunning2();
|
|
265
265
|
});
|
|
266
266
|
await this.start(true);
|
|
@@ -280,7 +280,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
|
|
|
280
280
|
await this.applyCredentialUpdate(generation, async () => {
|
|
281
281
|
await this.applyCredentialsResponse(data);
|
|
282
282
|
if (restartOnChange && CODEX_AUTH_ENV_KEYS.some((key, index) => process.env[key] !== previousEnv[index])) {
|
|
283
|
-
const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-
|
|
283
|
+
const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-INCEKBYG.js");
|
|
284
284
|
await restartCodexAspHostIfRunning2();
|
|
285
285
|
}
|
|
286
286
|
setAgentCredentialSnapshot("codex", data);
|
|
@@ -2,39 +2,6 @@
|
|
|
2
2
|
import { createRequire as __createRequire } from 'node:module';
|
|
3
3
|
const require = __createRequire(import.meta.url);
|
|
4
4
|
|
|
5
|
-
// src/utils/presigned-upload.ts
|
|
6
|
-
import { createReadStream } from "fs";
|
|
7
|
-
import { request as httpRequest } from "http";
|
|
8
|
-
import { request as httpsRequest } from "https";
|
|
9
|
-
async function putPresignedFile(urlValue, filePath, size, contentType) {
|
|
10
|
-
await new Promise((resolve, reject) => {
|
|
11
|
-
const url = new URL(urlValue);
|
|
12
|
-
const request = (url.protocol === "https:" ? httpsRequest : httpRequest)(url, {
|
|
13
|
-
method: "PUT",
|
|
14
|
-
headers: {
|
|
15
|
-
"content-length": String(size),
|
|
16
|
-
"content-type": contentType
|
|
17
|
-
}
|
|
18
|
-
}, (response) => {
|
|
19
|
-
response.setEncoding("utf8");
|
|
20
|
-
let body = "";
|
|
21
|
-
response.on("data", (chunk) => {
|
|
22
|
-
body += chunk;
|
|
23
|
-
});
|
|
24
|
-
response.on("end", () => {
|
|
25
|
-
const status = response.statusCode ?? 0;
|
|
26
|
-
if (status >= 200 && status < 300) resolve();
|
|
27
|
-
else reject(new Error(`upload failed: ${status} ${body}`));
|
|
28
|
-
});
|
|
29
|
-
response.on("error", reject);
|
|
30
|
-
});
|
|
31
|
-
request.on("error", reject);
|
|
32
|
-
const file = size > 0 ? createReadStream(filePath, { start: 0, end: size - 1 }) : createReadStream(filePath);
|
|
33
|
-
file.on("error", (error) => request.destroy(error));
|
|
34
|
-
file.pipe(request);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
5
|
// src/managers/codex-asp/notification-dispatch.ts
|
|
39
6
|
var TURN_STARTED_METHOD = "turn/started";
|
|
40
7
|
var TURN_COMPLETED_METHOD = "turn/completed";
|
|
@@ -74,7 +41,6 @@ function recoverCompletedTurn(turn, completedItems, agentMessageDeltas) {
|
|
|
74
41
|
}
|
|
75
42
|
|
|
76
43
|
export {
|
|
77
|
-
putPresignedFile,
|
|
78
44
|
TURN_STARTED_METHOD,
|
|
79
45
|
TURN_COMPLETED_METHOD,
|
|
80
46
|
TURN_PLAN_UPDATED_METHOD,
|
|
@@ -3,10 +3,10 @@ import { createRequire as __createRequire } from 'node:module';
|
|
|
3
3
|
const require = __createRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
5
|
execFileAsync
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-CANEL3IU.js";
|
|
7
7
|
import {
|
|
8
8
|
isVersionBelow
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-QXISBAH5.js";
|
|
10
10
|
|
|
11
11
|
// src/utils/codex-agent-env.ts
|
|
12
12
|
function buildCodexAgentEnv(source = process.env) {
|
|
@@ -240,7 +240,7 @@ function getCodexModelProvider(method) {
|
|
|
240
240
|
if (method === "foundry") return "azure";
|
|
241
241
|
return method === "ollama" || method === "openai-compatible" ? "replicas_openai_compatible" : "openai";
|
|
242
242
|
}
|
|
243
|
-
var ENGINE_PACKAGE_VERSION = "0.1.
|
|
243
|
+
var ENGINE_PACKAGE_VERSION = "0.1.959";
|
|
244
244
|
var INITIALIZE_METHOD = "initialize";
|
|
245
245
|
var INITIALIZED_NOTIFICATION = "initialized";
|
|
246
246
|
var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
|
|
@@ -3,13 +3,13 @@ import { createRequire as __createRequire } from 'node:module';
|
|
|
3
3
|
const require = __createRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
5
|
evaluateCommandProtection
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-SZTW4OGR.js";
|
|
7
|
+
import "./chunk-4HNUOSLS.js";
|
|
8
|
+
import "./chunk-CANEL3IU.js";
|
|
9
9
|
import {
|
|
10
10
|
isRecord
|
|
11
11
|
} from "./chunk-UZSNFLDQ.js";
|
|
12
|
-
import "./chunk-
|
|
12
|
+
import "./chunk-QXISBAH5.js";
|
|
13
13
|
import "./chunk-VEQXQN22.js";
|
|
14
14
|
|
|
15
15
|
// src/command-protection-hook.ts
|
|
@@ -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-X76Z5POI.js";
|
|
11
|
+
import "./chunk-CANEL3IU.js";
|
|
13
12
|
import {
|
|
14
13
|
AGENT,
|
|
15
|
-
getMemoryOutputSafetyViolation,
|
|
16
14
|
headlessAgentRequestSchema
|
|
17
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-QXISBAH5.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) => {
|