agent-dealer 1.4.3 → 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.
@@ -31,7 +31,7 @@ function claudeDisallowedTools(policy) {
31
31
  // enforceable capabilities here on purpose.
32
32
  return policy.outboundMutation ? [] : [DENY_SEND_TOOL];
33
33
  }
34
- function buildArgs(runtime, policy, prompt, model, mcpConfigPath, effort) {
34
+ function buildArgs(runtime, policy, model, mcpConfigPath, effort) {
35
35
  if (runtime === "muse_code") {
36
36
  // Muse's developer argv is built by runners/muse-config.ts (`prepareMuseAttempt`,
37
37
  // NOT-278) inside coordinator/muse-spawn.ts; it needs a per-attempt deck, session id, and
@@ -61,7 +61,7 @@ function buildArgs(runtime, policy, prompt, model, mcpConfigPath, effort) {
61
61
  // exec session banner. Cursor has no equivalent separate flag.
62
62
  if (effort)
63
63
  args.push("-c", `model_reasoning_effort=${effort}`);
64
- args.push(prompt);
64
+ args.push("-");
65
65
  return args;
66
66
  }
67
67
  if (runtime === "cursor_local") {
@@ -85,7 +85,6 @@ function buildArgs(runtime, policy, prompt, model, mcpConfigPath, effort) {
85
85
  "--stream-partial-output",
86
86
  ...(policy.worktreeWrite ? [] : ["--mode", "ask"]),
87
87
  ...(model ? ["--model", model] : []),
88
- prompt,
89
88
  ];
90
89
  }
91
90
  const { builtins, allowed } = claudeToolSets(policy);
@@ -95,7 +94,6 @@ function buildArgs(runtime, policy, prompt, model, mcpConfigPath, effort) {
95
94
  ...(model ? ["--model", model] : []),
96
95
  ...(effort ? ["--effort", effort] : []),
97
96
  "-p",
98
- prompt,
99
97
  "--output-format",
100
98
  "stream-json",
101
99
  "--verbose",
@@ -125,11 +123,11 @@ function buildArgs(runtime, policy, prompt, model, mcpConfigPath, effort) {
125
123
  return args;
126
124
  }
127
125
  export function buildWorkerArgs(opts) {
128
- return buildArgs(opts.runtime, opts.policy ?? roleCeiling(opts.role), opts.prompt, opts.model, opts.mcpConfigPath, opts.effort);
126
+ return buildArgs(opts.runtime, opts.policy ?? roleCeiling(opts.role), opts.model, opts.mcpConfigPath, opts.effort);
129
127
  }
130
- export function buildDeveloperArgs(runtime, prompt, model, policy, mcpConfigPath, effort) {
131
- return buildArgs(runtime, policy ?? roleCeiling("developer"), prompt, model, mcpConfigPath, effort);
128
+ export function buildDeveloperArgs(runtime, _prompt, model, policy, mcpConfigPath, effort) {
129
+ return buildArgs(runtime, policy ?? roleCeiling("developer"), model, mcpConfigPath, effort);
132
130
  }
133
- export function buildReviewerArgs(runtime, prompt, model, policy, mcpConfigPath, effort) {
134
- return buildArgs(runtime, policy ?? roleCeiling("reviewer"), prompt, model, mcpConfigPath, effort);
131
+ export function buildReviewerArgs(runtime, _prompt, model, policy, mcpConfigPath, effort) {
132
+ return buildArgs(runtime, policy ?? roleCeiling("reviewer"), model, mcpConfigPath, effort);
135
133
  }
@@ -4,7 +4,6 @@ import { buildDeveloperArgs, buildReviewerArgs } from "./args.js";
4
4
  test("buildDeveloperArgs for claude_code allows Bash and Write/Edit", () => {
5
5
  const args = buildDeveloperArgs("claude_code", "do the task");
6
6
  assert.ok(args.includes("-p"));
7
- assert.ok(args.includes("do the task"));
8
7
  const toolsIdx = args.indexOf("--allowedTools");
9
8
  assert.ok(toolsIdx >= 0);
10
9
  assert.ok(args[toolsIdx + 1].includes("Bash"));
@@ -26,6 +25,7 @@ test("buildDeveloperArgs passes model through when given", () => {
26
25
  test("buildDeveloperArgs for codex_local uses exec subcommand shape", () => {
27
26
  const args = buildDeveloperArgs("codex_local", "do the task");
28
27
  assert.equal(args[0], "exec");
28
+ assert.equal(args.at(-1), "-");
29
29
  assert.ok(args.includes("workspace-write"));
30
30
  });
31
31
  test("buildReviewerArgs for codex_local uses read-only sandbox", () => {
@@ -140,7 +140,10 @@ test("every runtime either builds developer args or is the not-yet-wired muse_co
140
140
  assert.throws(() => buildReviewerArgs(runtime, "prompt"), /not wired/);
141
141
  }
142
142
  else {
143
- assert.ok(buildDeveloperArgs(runtime, "prompt").includes("prompt"), runtime);
143
+ const prompt = "sentinel worker prompt";
144
+ for (const buildArgs of [buildDeveloperArgs, buildReviewerArgs]) {
145
+ assert.ok(buildArgs(runtime, prompt).every((arg) => !arg.includes(prompt)), `${runtime} ${buildArgs.name}`);
146
+ }
144
147
  }
145
148
  }
146
149
  });
@@ -245,6 +245,7 @@ export async function runMuseDeveloperSession(input) {
245
245
  timeoutMs: input.timeoutMs,
246
246
  env: { ...attempt.env },
247
247
  exactEnv: true,
248
+ runtime: "muse_code",
248
249
  stdin: attempt.stdin,
249
250
  signal: input.signal,
250
251
  onSpawn: input.onSpawn,
@@ -202,9 +202,8 @@ export function resolveProbeBin(runtime) {
202
202
  }
203
203
  }
204
204
  /**
205
- * Exact argv the real reviewer path would spawn for this probe prompt. Same
206
- * builder (`buildReviewerArgs`) and same ceiling (`roleCeiling("reviewer")`) as
207
- * production — the probe records it and `realReviewerSpawn` re-derives it.
205
+ * Reviewer argv from the same builder and role ceiling as production.
206
+ * Cursor's per-attempt prompt file is allocated later by realReviewerSpawn.
208
207
  */
209
208
  export function resolveProbeArgv(opts) {
210
209
  return buildReviewerArgs(opts.runtime, opts.prompt, opts.model, opts.policy ?? roleCeiling("reviewer"), opts.mcpConfigPath, opts.effort ?? null);
@@ -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
- const { exitCode, transcript, timedOut } = await spawnCli(input.sessionId, BIN_FOR[input.runtime](), args, input.cwd, { logPath, timeoutMs: input.timeoutMs, env: input.mcpEnv, signal: input.signal, onSpawn: input.onSpawn });
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
- const { exitCode, transcript, timedOut } = await spawnCli(input.sessionId, BIN_FOR[input.runtime](), args, input.cwd, { logPath, timeoutMs: input.timeoutMs, env: input.mcpEnv, signal: input.signal, onSpawn: input.onSpawn });
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
+ }
@@ -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.prompt);
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 prompt is the last positional; flags inside it would be parsed by Muse.
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 under $HOME.
9
- const SCRATCH = fs.mkdtempSync(path.join(os.homedir(), ".dealer-muse-config-test-"));
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
- assert.equal(attempt.argv.at(-1), "Implement the ticket");
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, prompt: "x" }), "reviewer")), "invalid_argv");
182
- assert.equal(code(() => assertMuseArgv(buildMuseArgv({ role: "reviewer", sessionId: SESSION, maxModelSteps: 5, prompt: "x" }), "developer")), "invalid_argv");
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, prompt: "x" });
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, -1), bad, "x"];
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
- // NOT-225: sanitize before spawn — a raw NUL in any arg throws
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
- // NOT-278: the stdin payload (Muse API key) is written once and closed right after
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",
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.3",
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",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-dealer/shared",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-dealer",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "description": "Human control plane for agent execution — queue, plan approval, audit",
5
5
  "license": "MIT",
6
6
  "type": "module",