agent-dealer 1.4.2 → 1.4.4
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/bundle/server/dist/adapters/github.js +66 -3
- package/bundle/server/dist/adapters/github.test.js +90 -0
- package/bundle/server/dist/coordinator/args.js +7 -9
- package/bundle/server/dist/coordinator/args.test.js +5 -2
- package/bundle/server/dist/coordinator/auto-merge.js +17 -6
- package/bundle/server/dist/coordinator/commands.js +18 -2
- package/bundle/server/dist/coordinator/developer-effect.js +46 -5
- package/bundle/server/dist/coordinator/developer-effect.test.js +118 -4
- package/bundle/server/dist/coordinator/muse-spawn.js +1 -0
- package/bundle/server/dist/coordinator/operator-criteria.js +250 -17
- package/bundle/server/dist/coordinator/operator-criteria.test.js +177 -4
- package/bundle/server/dist/coordinator/operator-verification.integration.test.js +208 -0
- package/bundle/server/dist/coordinator/projection.js +5 -1
- package/bundle/server/dist/coordinator/prompts.js +77 -4
- package/bundle/server/dist/coordinator/prompts.test.js +22 -4
- package/bundle/server/dist/coordinator/reviewer-browser-probe.js +2 -3
- package/bundle/server/dist/coordinator/reviewer-effect.js +64 -45
- package/bundle/server/dist/coordinator/reviewer-effect.test.js +63 -10
- package/bundle/server/dist/coordinator/reviewer-pr-evidence.test.js +245 -0
- package/bundle/server/dist/coordinator/reviewer-result.js +4 -3
- package/bundle/server/dist/coordinator/reviewer-result.test.js +6 -0
- package/bundle/server/dist/coordinator/routing.js +3 -0
- package/bundle/server/dist/coordinator/routing.test.js +19 -0
- package/bundle/server/dist/coordinator/spawn.js +25 -5
- package/bundle/server/dist/coordinator/spawn.test.js +84 -0
- package/bundle/server/dist/docs-api-reference.test.js +89 -0
- package/bundle/server/dist/runners/muse-config-core.js +33 -9
- package/bundle/server/dist/runners/muse-config.test.js +13 -8
- package/bundle/server/dist/runners/spawn-cli.js +12 -4
- package/bundle/server/dist/runners/spawn-cli.test.js +19 -0
- package/bundle/server/package.json +2 -2
- package/bundle/shared/package.json +1 -1
- package/package.json +1 -1
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
// `realDeveloperSpawn`/`realReviewerSpawn`, tests inject a fake so no paid CLI is ever
|
|
12
12
|
// spawned in CI (the confirmed NOT-61/62 scope call: fake the agent session, keep
|
|
13
13
|
// worktree/push/PR/review verification real).
|
|
14
|
+
import fs from "node:fs";
|
|
14
15
|
import path from "node:path";
|
|
15
|
-
import { getTemporalLogsDir } from "../paths.js";
|
|
16
|
+
import { getTemporalLogsDir, getWorkerMcpConfigDir } from "../paths.js";
|
|
16
17
|
import { resolveClaudeBin, resolveCodexBin, resolveCursorBin, resolveMuseBin } from "../cli-env.js";
|
|
17
18
|
import { spawnCli } from "../runners/spawn-cli.js";
|
|
18
19
|
import { buildDeveloperArgs, buildReviewerArgs } from "./args.js";
|
|
@@ -47,8 +48,7 @@ export const realDeveloperSpawn = async (input) => {
|
|
|
47
48
|
}
|
|
48
49
|
const args = buildDeveloperArgs(input.runtime, input.prompt, input.model ?? undefined, input.policy, input.mcpConfigPath, input.effort);
|
|
49
50
|
const logPath = input.logPath ?? developerSessionLogPath(input.sessionId);
|
|
50
|
-
|
|
51
|
-
return { exitCode, transcript: extractResultTranscript(logPath, input.runtime, transcript), logPath, timedOut };
|
|
51
|
+
return spawnWorker(input, args, logPath);
|
|
52
52
|
};
|
|
53
53
|
/**
|
|
54
54
|
* Asserts the read-only invariant on the generated args before every real reviewer spawn
|
|
@@ -62,6 +62,26 @@ export const realReviewerSpawn = async (input) => {
|
|
|
62
62
|
const args = buildReviewerArgs(input.runtime, input.prompt, input.model ?? undefined, input.policy, input.mcpConfigPath, input.effort);
|
|
63
63
|
assertReviewerReadOnly(args, { mcpConfigPath: input.mcpConfigPath, mcpEnv: input.mcpEnv });
|
|
64
64
|
const logPath = input.logPath ?? reviewerSessionLogPath(input.sessionId);
|
|
65
|
-
|
|
66
|
-
return { exitCode, transcript: extractResultTranscript(logPath, input.runtime, transcript), logPath, timedOut };
|
|
65
|
+
return spawnWorker(input, args, logPath);
|
|
67
66
|
};
|
|
67
|
+
async function spawnWorker(input, args, logPath) {
|
|
68
|
+
const { runtime, sessionId, cwd, prompt, timeoutMs, mcpEnv, signal, onSpawn } = input;
|
|
69
|
+
// Cursor's headless interface takes a positional instruction. Keep the full
|
|
70
|
+
// prompt in a private attempt directory outside the checkout and retained logs.
|
|
71
|
+
const attemptDir = runtime === "cursor_local"
|
|
72
|
+
? fs.mkdtempSync(path.resolve(getWorkerMcpConfigDir(), "cursor-prompt-"))
|
|
73
|
+
: undefined;
|
|
74
|
+
try {
|
|
75
|
+
if (attemptDir) {
|
|
76
|
+
const promptPath = path.join(attemptDir, "prompt.txt");
|
|
77
|
+
fs.writeFileSync(promptPath, prompt, { mode: 0o600, flag: "wx" });
|
|
78
|
+
args.push(`Read the complete task prompt from ${JSON.stringify(promptPath)} and follow its instructions.`);
|
|
79
|
+
}
|
|
80
|
+
const { exitCode, transcript, timedOut } = await spawnCli(sessionId, BIN_FOR[runtime](), args, cwd, { logPath, timeoutMs, env: mcpEnv, signal, onSpawn, runtime, stdin: attemptDir ? undefined : prompt });
|
|
81
|
+
return { exitCode, transcript: extractResultTranscript(logPath, runtime, transcript), logPath, timedOut };
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
if (attemptDir)
|
|
85
|
+
fs.rmSync(attemptDir, { recursive: true, force: true });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { test } from "node:test";
|
|
7
|
+
import { roleCeiling } from "@agent-dealer/shared";
|
|
8
|
+
import { assertReviewerReadOnly } from "./permissions.js";
|
|
9
|
+
import { realDeveloperSpawn, realReviewerSpawn } from "./spawn.js";
|
|
10
|
+
const BIN_ENV = {
|
|
11
|
+
codex_local: "CODEX_CLI",
|
|
12
|
+
claude_code: "CLAUDE_CLI",
|
|
13
|
+
cursor_local: "CURSOR_CLI",
|
|
14
|
+
muse_code: "MUSE_CLI",
|
|
15
|
+
};
|
|
16
|
+
for (const runtime of Object.keys(BIN_ENV)) {
|
|
17
|
+
for (const role of runtime === "muse_code" ? ["developer"] : ["developer", "reviewer"]) {
|
|
18
|
+
test(`${runtime} ${role} launches with the full large prompt`, async (t) => {
|
|
19
|
+
// Muse refuses attempts under system temp directories.
|
|
20
|
+
const scratch = runtime === "muse_code" ? path.resolve(import.meta.dirname, "../../../..") : os.tmpdir();
|
|
21
|
+
const dir = fs.mkdtempSync(path.join(scratch, ".dealer-worker-spawn-"));
|
|
22
|
+
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
|
|
23
|
+
const sessionId = "00000000-0000-4000-8000-000000000635";
|
|
24
|
+
const cwd = path.join(dir, "worktrees", `${sessionId}-${role}`);
|
|
25
|
+
fs.mkdirSync(cwd, { recursive: true });
|
|
26
|
+
const bin = path.join(dir, "worker.cjs");
|
|
27
|
+
fs.writeFileSync(bin, `#!${process.execPath}
|
|
28
|
+
const fs = require("node:fs");
|
|
29
|
+
const argv = process.argv.slice(2);
|
|
30
|
+
const input = fs.readFileSync(0);
|
|
31
|
+
const muse = argv.includes("--prompt-file");
|
|
32
|
+
const pathMatch = argv.at(-1)?.match(/from (".*") and follow/);
|
|
33
|
+
const promptFile = muse ? argv[argv.indexOf("--prompt-file") + 1] : pathMatch && JSON.parse(pathMatch[1]);
|
|
34
|
+
const prompt = promptFile ? fs.readFileSync(promptFile) : input;
|
|
35
|
+
const mode = promptFile ? fs.statSync(promptFile).mode & 0o777 : null;
|
|
36
|
+
const digest = require("node:crypto").createHash("sha256").update(prompt).digest("hex");
|
|
37
|
+
const receipt = { argv, digest, bytes: prompt.length, promptFile, mode, inputBytes: input.length };
|
|
38
|
+
fs.writeFileSync("receipt.json", JSON.stringify(receipt));
|
|
39
|
+
`, { mode: 0o700 });
|
|
40
|
+
const env = {
|
|
41
|
+
[BIN_ENV[runtime]]: bin,
|
|
42
|
+
AGENT_DEALER_HOME: dir,
|
|
43
|
+
XDG_CONFIG_HOME: path.join(dir, "operator-config"),
|
|
44
|
+
META_API_KEY: "test-key",
|
|
45
|
+
};
|
|
46
|
+
for (const [key, value] of Object.entries(env)) {
|
|
47
|
+
const previous = process.env[key];
|
|
48
|
+
process.env[key] = value;
|
|
49
|
+
t.after(() => {
|
|
50
|
+
if (previous === undefined)
|
|
51
|
+
delete process.env[key];
|
|
52
|
+
else
|
|
53
|
+
process.env[key] = previous;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const prompt = "sentinel worker prompt\n" + "é".repeat(100 * 1024) + "\n";
|
|
57
|
+
const spawn = role === "reviewer" ? realReviewerSpawn : realDeveloperSpawn;
|
|
58
|
+
const result = await spawn({
|
|
59
|
+
runtime, cwd, sessionId, prompt, policy: roleCeiling(role), model: null,
|
|
60
|
+
logPath: path.join(dir, "worker.ndjson"), timeoutMs: 5000,
|
|
61
|
+
deckId: "test-deck", agentDeckUrl: "http://127.0.0.1:1111/mcp",
|
|
62
|
+
});
|
|
63
|
+
assert.equal(result.timedOut, false);
|
|
64
|
+
// The Muse stub records transport only. Muse's parser requires model events for a successful turn.
|
|
65
|
+
if (runtime !== "muse_code")
|
|
66
|
+
assert.equal(result.exitCode, 0);
|
|
67
|
+
const receipt = JSON.parse(fs.readFileSync(path.join(cwd, "receipt.json"), "utf8"));
|
|
68
|
+
assert.equal(receipt.bytes, Buffer.byteLength(prompt));
|
|
69
|
+
assert.equal(receipt.digest, createHash("sha256").update(prompt).digest("hex"));
|
|
70
|
+
assert.ok(receipt.argv.every((arg) => !arg.includes("sentinel worker prompt")));
|
|
71
|
+
if (role === "reviewer")
|
|
72
|
+
assertReviewerReadOnly(receipt.argv, {});
|
|
73
|
+
if (runtime === "codex_local")
|
|
74
|
+
assert.equal(receipt.argv.at(-1), "-");
|
|
75
|
+
if (runtime === "claude_code")
|
|
76
|
+
assert.equal(receipt.argv[receipt.argv.indexOf("-p") + 1], "--output-format");
|
|
77
|
+
if (runtime === "cursor_local" || runtime === "muse_code") {
|
|
78
|
+
assert.equal(receipt.mode, 0o600);
|
|
79
|
+
assert.equal(fs.existsSync(receipt.promptFile), false);
|
|
80
|
+
assert.equal(receipt.inputBytes, runtime === "muse_code" ? Buffer.byteLength("test-key\n") : 0);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// NOT-575: docs/API.md is the canonical guidance/resolve reference. Guards
|
|
2
|
+
// that it documents both payloads and that every stored choice per action
|
|
3
|
+
// type appears in it — the doc is generated from the same constants the
|
|
4
|
+
// server validates against, so drift fails here instead of surprising an
|
|
5
|
+
// operator at resolve time.
|
|
6
|
+
import { test } from "node:test";
|
|
7
|
+
import assert from "node:assert/strict";
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import os from "node:os";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
12
|
+
process.env.AGENT_DEALER_HOME = fs.mkdtempSync(path.join(os.tmpdir(), "dealer-docs-api-"));
|
|
13
|
+
const { responseOptionsFor } = await import("./coordinator/commands.js");
|
|
14
|
+
const { PRODUCT_SCOPE_NOTE_MAX_CHARS } = await import("./coordinator/human-resolution.js");
|
|
15
|
+
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../..");
|
|
16
|
+
const API_REF = "docs/API.md";
|
|
17
|
+
const read = () => fs.readFileSync(path.join(repoRoot, API_REF), "utf8");
|
|
18
|
+
test("the API reference exists and names the discovery fields", () => {
|
|
19
|
+
assert.ok(fs.existsSync(path.join(repoRoot, API_REF)));
|
|
20
|
+
const doc = read();
|
|
21
|
+
// The acceptance evidence: rg -n "responseOptions|resolvedBy" docs/API.md.
|
|
22
|
+
assert.match(doc, /responseOptions/);
|
|
23
|
+
assert.match(doc, /resolvedBy/);
|
|
24
|
+
});
|
|
25
|
+
test("the guidance payload is documented with its markdown field", () => {
|
|
26
|
+
const doc = read();
|
|
27
|
+
assert.match(doc, /POST \/api\/issues\/:id\/guidance/);
|
|
28
|
+
assert.match(doc, /"markdown"/);
|
|
29
|
+
});
|
|
30
|
+
test("the resolve payload is documented with resolvedBy, choice, and note", () => {
|
|
31
|
+
const doc = read();
|
|
32
|
+
assert.match(doc, /POST \/api\/human-actions\/:id\/resolve/);
|
|
33
|
+
assert.match(doc, /"resolvedBy"/);
|
|
34
|
+
assert.match(doc, /"choice"/);
|
|
35
|
+
assert.match(doc, /"note"/);
|
|
36
|
+
assert.ok(doc.includes(String(PRODUCT_SCOPE_NOTE_MAX_CHARS)), "the note cap must match code");
|
|
37
|
+
});
|
|
38
|
+
test("every stored choice per action type appears in the reference", () => {
|
|
39
|
+
const doc = read();
|
|
40
|
+
const stored = [
|
|
41
|
+
...responseOptionsFor("final_review"),
|
|
42
|
+
...responseOptionsFor("attempts_exhausted"),
|
|
43
|
+
...responseOptionsFor("policy_escalation"),
|
|
44
|
+
...responseOptionsFor("policy_escalation", false, { mergeFailure: true }),
|
|
45
|
+
...responseOptionsFor("policy_escalation", false, {
|
|
46
|
+
pushDivergence: {
|
|
47
|
+
branch: "b",
|
|
48
|
+
localSha: "l",
|
|
49
|
+
remoteSha: "r",
|
|
50
|
+
ahead: 1,
|
|
51
|
+
behind: 1,
|
|
52
|
+
relationship: "diverged",
|
|
53
|
+
},
|
|
54
|
+
}),
|
|
55
|
+
...responseOptionsFor("product_scope_decision"),
|
|
56
|
+
...responseOptionsFor("operator_verification"),
|
|
57
|
+
];
|
|
58
|
+
for (const { choice } of stored) {
|
|
59
|
+
assert.ok(doc.includes(`\`${choice}\``), `missing stored choice: ${choice}`);
|
|
60
|
+
}
|
|
61
|
+
// Accepted but not stored: the final_review legacy synonym (VALID_CHOICES in
|
|
62
|
+
// human-resolution.ts) and the special-resolver sets (reflect-trigger.ts,
|
|
63
|
+
// approve-deliver.ts, commands.ts's muse branch, linear-merge-verify.ts).
|
|
64
|
+
for (const choice of [
|
|
65
|
+
"complete",
|
|
66
|
+
"retry",
|
|
67
|
+
"dismiss",
|
|
68
|
+
"retry_send",
|
|
69
|
+
"reject",
|
|
70
|
+
"acknowledge",
|
|
71
|
+
"recheck",
|
|
72
|
+
]) {
|
|
73
|
+
assert.ok(doc.includes(`\`${choice}\``), `missing accepted choice: ${choice}`);
|
|
74
|
+
}
|
|
75
|
+
// Every action type has a row.
|
|
76
|
+
for (const actionType of [
|
|
77
|
+
"final_review",
|
|
78
|
+
"attempts_exhausted",
|
|
79
|
+
"policy_escalation",
|
|
80
|
+
"product_scope_decision",
|
|
81
|
+
"deck_interaction_required",
|
|
82
|
+
"reflection_interaction_required",
|
|
83
|
+
"outbound_delivery_interaction_required",
|
|
84
|
+
"muse_capability",
|
|
85
|
+
"operator_verification",
|
|
86
|
+
]) {
|
|
87
|
+
assert.ok(doc.includes(`\`${actionType}\``), `missing action type: ${actionType}`);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
@@ -181,13 +181,16 @@ export function buildMuseArgv(input) {
|
|
|
181
181
|
];
|
|
182
182
|
if (input.role === "reviewer")
|
|
183
183
|
argv.push("--disable-write", "--disable-shell");
|
|
184
|
-
argv.push(input.
|
|
184
|
+
argv.push("--prompt-file", input.promptFile);
|
|
185
185
|
assertMuseArgv(argv, input.role);
|
|
186
186
|
return argv;
|
|
187
187
|
}
|
|
188
188
|
/** Refuses argv that widens trust/sandbox/orchestration or drops a required restriction. */
|
|
189
189
|
export function assertMuseArgv(argv, role) {
|
|
190
|
-
// The
|
|
190
|
+
// The last argument is the path consumed by --prompt-file.
|
|
191
|
+
if (argv.at(-2) !== "--prompt-file" || !path.isAbsolute(argv.at(-1) ?? "")) {
|
|
192
|
+
throw new MuseIsolationError("invalid_argv", "Muse argv must end with --prompt-file and an absolute path");
|
|
193
|
+
}
|
|
191
194
|
const flags = argv.slice(0, -1);
|
|
192
195
|
for (const arg of flags) {
|
|
193
196
|
const name = arg.split("=")[0];
|
|
@@ -422,13 +425,6 @@ function prepareWithEvidence(rawInput, evidence) {
|
|
|
422
425
|
const settings = deepFreeze(buildMuseSettings(agentDeck, input.role, evidence));
|
|
423
426
|
assertMuseSettings(settings, agentDeck, input.role, evidence);
|
|
424
427
|
const apiKey = input.credential.kind === "api-key" ? input.credential.apiKey : undefined;
|
|
425
|
-
const argv = buildMuseArgv({
|
|
426
|
-
role: input.role,
|
|
427
|
-
sessionId: input.sessionId,
|
|
428
|
-
maxModelSteps: input.maxModelSteps,
|
|
429
|
-
prompt: input.prompt,
|
|
430
|
-
apiKeyStdin: apiKey !== undefined,
|
|
431
|
-
});
|
|
432
428
|
const root = fs.mkdtempSync(path.join(baseDir, ATTEMPT_PREFIX));
|
|
433
429
|
// Terminal only once the dir is confirmed gone, so a failed rmSync can be retried.
|
|
434
430
|
let cleaned = false;
|
|
@@ -470,6 +466,21 @@ function prepareWithEvidence(rawInput, evidence) {
|
|
|
470
466
|
throw original;
|
|
471
467
|
};
|
|
472
468
|
const settingsPath = path.join(root, "config", "muse", "settings.json");
|
|
469
|
+
// stdin may carry the API key, so Muse loads the prompt through its native file option.
|
|
470
|
+
const promptFile = path.join(root, "prompt.txt");
|
|
471
|
+
let argv;
|
|
472
|
+
try {
|
|
473
|
+
argv = buildMuseArgv({
|
|
474
|
+
role: input.role,
|
|
475
|
+
sessionId: input.sessionId,
|
|
476
|
+
maxModelSteps: input.maxModelSteps,
|
|
477
|
+
promptFile,
|
|
478
|
+
apiKeyStdin: apiKey !== undefined,
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
catch (err) {
|
|
482
|
+
return abortConstruction(err);
|
|
483
|
+
}
|
|
473
484
|
const approved = deepFreeze({
|
|
474
485
|
cwd: worktree,
|
|
475
486
|
argv: [...argv],
|
|
@@ -509,6 +520,18 @@ function prepareWithEvidence(rawInput, evidence) {
|
|
|
509
520
|
throw err;
|
|
510
521
|
throw new MuseIsolationError("invalid_settings", "Muse settings.json is missing or unreadable");
|
|
511
522
|
}
|
|
523
|
+
let promptMatches = false;
|
|
524
|
+
try {
|
|
525
|
+
const stat = fs.lstatSync(promptFile);
|
|
526
|
+
promptMatches = stat.isFile() && (stat.mode & 0o777) === 0o600
|
|
527
|
+
&& fs.readFileSync(promptFile).equals(Buffer.from(input.prompt));
|
|
528
|
+
}
|
|
529
|
+
catch {
|
|
530
|
+
// A missing or unreadable prompt also violates the launch contract.
|
|
531
|
+
}
|
|
532
|
+
if (!promptMatches) {
|
|
533
|
+
throw new MuseIsolationError("invalid_argv", "Muse prompt file differs from the approved launch prompt");
|
|
534
|
+
}
|
|
512
535
|
assertMuseSettings(onDisk, agentDeck, input.role, evidence);
|
|
513
536
|
const entries = fs.readdirSync(path.dirname(settingsPath)).sort();
|
|
514
537
|
const allowed = credentialKind === "auth-file" ? ["auth.json", "settings.json"] : ["settings.json"];
|
|
@@ -522,6 +545,7 @@ function prepareWithEvidence(rawInput, evidence) {
|
|
|
522
545
|
writePrivate(path.join(root, SENTINEL), "");
|
|
523
546
|
fs.mkdirSync(path.dirname(settingsPath), { recursive: true, mode: 0o700 });
|
|
524
547
|
fs.mkdirSync(path.join(root, "data"), { recursive: true, mode: 0o700 });
|
|
548
|
+
writePrivate(promptFile, input.prompt);
|
|
525
549
|
writePrivate(settingsPath, `${JSON.stringify(settings, null, 2)}\n`);
|
|
526
550
|
if (input.credential.kind === "auth-file") {
|
|
527
551
|
fs.symlinkSync(input.credential.path, path.join(path.dirname(settingsPath), "auth.json"));
|
|
@@ -5,8 +5,8 @@ import os from "node:os";
|
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { assertMuseArgv, buildMuseArgv, NOT_177_EVIDENCE, prepareMuseAttempt as prepareMuseAttemptPinned, unenforceableRestrictions, } from "./muse-config.js";
|
|
7
7
|
import { pathToFileURL } from "node:url";
|
|
8
|
-
// The Muse sandbox leaves temp dirs writable, so the module refuses them: fixtures live
|
|
9
|
-
const SCRATCH = fs.mkdtempSync(path.
|
|
8
|
+
// The Muse sandbox leaves temp dirs writable, so the module refuses them: fixtures live outside system temp directories.
|
|
9
|
+
const SCRATCH = fs.mkdtempSync(path.resolve(import.meta.dirname, "../../../../.dealer-muse-config-test-"));
|
|
10
10
|
after(() => fs.rmSync(SCRATCH, { recursive: true, force: true }));
|
|
11
11
|
const ENFORCED = { mcp_tool_allowlist_enforcement: true, cron_tool_disable: true };
|
|
12
12
|
// Production code has no seam that accepts other enforcement evidence. The enforced paths are exercised
|
|
@@ -142,7 +142,10 @@ test("developer: the full assigned Agent Deck surface, sandbox on, no unrestrict
|
|
|
142
142
|
assert.equal(flag("--sandbox-network"), "restricted");
|
|
143
143
|
assert.equal(flag("--model"), "muse-spark-1.3-contributor");
|
|
144
144
|
assert.equal(flag("--session-id"), SESSION);
|
|
145
|
-
|
|
145
|
+
const promptFile = path.join(attempt.root, "prompt.txt");
|
|
146
|
+
assert.deepEqual(attempt.argv.slice(-2), ["--prompt-file", promptFile]);
|
|
147
|
+
assert.equal(fs.statSync(promptFile).mode & 0o777, 0o600);
|
|
148
|
+
assert.equal(fs.readFileSync(promptFile, "utf8"), "Implement the ticket");
|
|
146
149
|
for (const bad of ["--yolo", "--disable-sandbox", "--disable-approval", "--trust-workspace", "-w", "--worktree", "--disable-write", "--disable-shell"]) {
|
|
147
150
|
assert.equal(attempt.argv.includes(bad), false, bad);
|
|
148
151
|
}
|
|
@@ -178,13 +181,13 @@ test("reviewer: read-only flags and the allowlisted deck reads, mutation denied"
|
|
|
178
181
|
attempt.cleanup();
|
|
179
182
|
}
|
|
180
183
|
// A reviewer argv without the read-only flags is refused, as is a developer with them.
|
|
181
|
-
assert.equal(code(() => assertMuseArgv(buildMuseArgv({ role: "developer", sessionId: SESSION, maxModelSteps: 5,
|
|
182
|
-
assert.equal(code(() => assertMuseArgv(buildMuseArgv({ role: "reviewer", sessionId: SESSION, maxModelSteps: 5,
|
|
184
|
+
assert.equal(code(() => assertMuseArgv(buildMuseArgv({ role: "developer", sessionId: SESSION, maxModelSteps: 5, promptFile: "/prompt.txt" }), "reviewer")), "invalid_argv");
|
|
185
|
+
assert.equal(code(() => assertMuseArgv(buildMuseArgv({ role: "reviewer", sessionId: SESSION, maxModelSteps: 5, promptFile: "/prompt.txt" }), "developer")), "invalid_argv");
|
|
183
186
|
});
|
|
184
187
|
test("argv guard refuses every trust/sandbox/orchestration widening flag", () => {
|
|
185
|
-
const base = buildMuseArgv({ role: "developer", sessionId: SESSION, maxModelSteps: 5,
|
|
188
|
+
const base = buildMuseArgv({ role: "developer", sessionId: SESSION, maxModelSteps: 5, promptFile: "/prompt.txt" });
|
|
186
189
|
for (const bad of ["--yolo", "--disable-sandbox", "--disable-approval", "--trust-workspace", "-w", "--worktree=nested", "--preset", "--agents", "--permission-profile"]) {
|
|
187
|
-
const argv = [...base.slice(0, -
|
|
190
|
+
const argv = [...base.slice(0, -2), bad, ...base.slice(-2)];
|
|
188
191
|
assert.equal(code(() => assertMuseArgv(argv, "developer")), "invalid_argv", bad);
|
|
189
192
|
}
|
|
190
193
|
const relaxed = base.map((a) => (a === "restricted" ? "proxy-only" : a));
|
|
@@ -556,7 +559,7 @@ test("launch contract: cwd is the real worktree and argv/env/cwd/stdin must matc
|
|
|
556
559
|
"drop --approval-judge off": { ...launch, argv: without("--approval-judge", 2) },
|
|
557
560
|
"add --base-url": { ...launch, argv: [...launch.argv.slice(0, -1), "--base-url", "http://evil.invalid", launch.argv.at(-1)] },
|
|
558
561
|
"duplicate flag": { ...launch, argv: [...launch.argv.slice(0, -1), "--json", launch.argv.at(-1)] },
|
|
559
|
-
"change prompt": { ...launch, argv: [...launch.argv.slice(0, -1), "other prompt"] },
|
|
562
|
+
"change prompt path": { ...launch, argv: [...launch.argv.slice(0, -1), "other prompt"] },
|
|
560
563
|
"ambient XDG_CONFIG_HOME": { ...launch, env: { ...launch.env, XDG_CONFIG_HOME: fx.operatorConfigHome } },
|
|
561
564
|
"ambient XDG_DATA_HOME": { ...launch, env: { ...launch.env, XDG_DATA_HOME: "/operator/data" } },
|
|
562
565
|
"extra env": { ...launch, env: { ...launch.env, META_API_KEY: API_KEY } },
|
|
@@ -566,6 +569,8 @@ test("launch contract: cwd is the real worktree and argv/env/cwd/stdin must matc
|
|
|
566
569
|
for (const [name, bad] of Object.entries(widened)) {
|
|
567
570
|
assert.equal(code(() => attempt.verify(bad)), "invalid_argv", name);
|
|
568
571
|
}
|
|
572
|
+
fs.writeFileSync(attempt.argv.at(-1), "changed prompt");
|
|
573
|
+
assert.equal(code(() => attempt.verify()), "invalid_argv");
|
|
569
574
|
}
|
|
570
575
|
finally {
|
|
571
576
|
attempt.cleanup();
|
|
@@ -47,6 +47,16 @@ function abortKillGraceMs() {
|
|
|
47
47
|
return Number(process.env.SPAWN_ABORT_KILL_GRACE_MS ?? 5_000);
|
|
48
48
|
}
|
|
49
49
|
export async function spawnCli(runId, cmd, args, cwd, opts) {
|
|
50
|
+
// NOT-225: Node rejects a raw NUL in argv before a process exists.
|
|
51
|
+
const argv = sanitizeArgv(args);
|
|
52
|
+
if (opts.runtime) {
|
|
53
|
+
// Linux MAX_ARG_STRLEN includes the terminating NUL. Measure UTF-8 bytes.
|
|
54
|
+
const oversized = argv.findIndex((arg) => Buffer.byteLength(arg) >= 128 * 1024);
|
|
55
|
+
if (oversized !== -1) {
|
|
56
|
+
const code = "prompt_too_large_for_argv";
|
|
57
|
+
throw Object.assign(new Error(`${code}: ${opts.runtime} argument ${oversized} exceeds the 128 KiB limit (including its terminator)`), { code });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
50
60
|
await acquireSpawnSlot();
|
|
51
61
|
try {
|
|
52
62
|
return await new Promise((resolve, reject) => {
|
|
@@ -189,9 +199,7 @@ export async function spawnCli(runId, cmd, args, cwd, opts) {
|
|
|
189
199
|
logStream.on("error", (err) => {
|
|
190
200
|
console.error(`[spawn-cli] log stream error for ${opts.logPath}`, err);
|
|
191
201
|
});
|
|
192
|
-
|
|
193
|
-
// ERR_INVALID_ARG_VALUE synchronously (no process, no pid, no log).
|
|
194
|
-
const child = spawn(cmd, sanitizeArgv(args), {
|
|
202
|
+
const child = spawn(cmd, argv, {
|
|
195
203
|
cwd,
|
|
196
204
|
// Extra vars (e.g. codex's bearer-token env var for its per-attempt CODEX_HOME
|
|
197
205
|
// MCP config, agent-deck-bind.ts) are added on top of, never in place of, the
|
|
@@ -200,7 +208,7 @@ export async function spawnCli(runId, cmd, args, cwd, opts) {
|
|
|
200
208
|
env: opts.exactEnv ? { ...opts.env } : { ...process.env, ...opts.env },
|
|
201
209
|
stdio: opts.stdin === undefined ? ["ignore", "pipe", "pipe"] : ["pipe", "pipe", "pipe"],
|
|
202
210
|
});
|
|
203
|
-
//
|
|
211
|
+
// The stdin payload is written once and closed right after
|
|
204
212
|
// spawn. It never reaches the log stream, the transcript, or any error below.
|
|
205
213
|
if (opts.stdin !== undefined) {
|
|
206
214
|
const payload = opts.stdin;
|
|
@@ -378,3 +378,22 @@ test("spawnCli does not linger-kill a child that exits inside the terminal grace
|
|
|
378
378
|
assert.equal(result.idleTimedOut, false);
|
|
379
379
|
assert.equal(result.exitCode, 0);
|
|
380
380
|
});
|
|
381
|
+
test("spawnCli delivers all 200 KiB of a UTF-8 prompt on stdin", async (t) => {
|
|
382
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "dealer-stdin-"));
|
|
383
|
+
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
|
|
384
|
+
const prompt = "é".repeat(100 * 1024);
|
|
385
|
+
const result = await spawnCli("large-stdin", process.execPath, ["-e", "const fs = require('node:fs'); fs.writeFileSync('received-bytes', String(fs.readFileSync(0).length))"], dir, { logPath: path.join(dir, "stdout.log"), timeoutMs: 5000, stdin: prompt });
|
|
386
|
+
assert.equal(result.exitCode, 0);
|
|
387
|
+
assert.equal(Number(fs.readFileSync(path.join(dir, "received-bytes"), "utf8")), Buffer.byteLength(prompt));
|
|
388
|
+
});
|
|
389
|
+
test("spawnCli rejects an oversized worker argument before spawning", async (t) => {
|
|
390
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "dealer-argv-"));
|
|
391
|
+
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
|
|
392
|
+
const logPath = path.join(dir, "stdout.log");
|
|
393
|
+
await assert.rejects(spawnCli("large-argv", "nonexistent-binary", ["é".repeat(65_537)], dir, {
|
|
394
|
+
logPath,
|
|
395
|
+
runtime: "codex_local",
|
|
396
|
+
timeoutMs: 5000,
|
|
397
|
+
}), { code: "prompt_too_large_for_argv", message: /prompt_too_large_for_argv: codex_local/ });
|
|
398
|
+
assert.equal(fs.existsSync(logPath), false);
|
|
399
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-dealer/server",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"test": "AGENT_DEALER_SKIP_GITHUB_HEALTH=1 AGENT_DEALER_SKIP_AGENT_HEALTH=1 npm run build -w @agent-dealer/shared && AGENT_DEALER_SKIP_GITHUB_HEALTH=1 AGENT_DEALER_SKIP_AGENT_HEALTH=1 node ../../scripts/run-workspace-tests.mjs"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@agent-dealer/shared": "1.4.
|
|
26
|
+
"@agent-dealer/shared": "1.4.4",
|
|
27
27
|
"@fastify/cors": "^11.0.1",
|
|
28
28
|
"@fastify/static": "^8.2.0",
|
|
29
29
|
"@modelcontextprotocol/sdk": "^1.29.0",
|