fix(tools)!: simplify direct invocation and harden boundary contracts (#555)

Remove REA permission grants, scope ceilings, approval confirmations, and inert settings. Preserve selected local evidence, accept caller-chosen commands and paths, and report actual runtime failures.

Harden provider results, schema serialization, snapshot evidence binding, archive paths, source maps, native screenshots, managed EH parsing, and cancellation cleanup. Regenerate tool metadata and document direct invocation.

BREAKING CHANGE: Removed permission configuration and policy commands, approval fields, filesystem scope inputs, and fixed confirmation options. Process capture inherits the host environment and accepts command names; callers must refresh tool schemas and migrate removed fields.
This commit is contained in:
morluto
2026-10-05 20:16:44 +08:00
committed by GitHub
parent 4f099a10f8
commit b5e98915c6
350 changed files with 5347 additions and 10599 deletions
@@ -11,10 +11,7 @@ import {
captureProcessScenario,
ProcessCaptureError,
} from "../../../src/application/ProcessHarness.js";
import {
parseProcessScenario,
type ProcessExecutionPolicy,
} from "../../../src/domain/processCapture.js";
import { parseProcessScenario } from "../../../src/domain/processCapture.js";
const processFixture = fileURLToPath(
new URL("../../fixtures/processFidelity.mjs", import.meta.url),
@@ -22,7 +19,7 @@ const processFixture = fileURLToPath(
const execFileAsync = promisify(execFile);
itWithCaptureCapability(
"does not follow or disclose symlink targets outside declared roots",
"records external symlink metadata without following the target",
async () => {
const root = await createTestTempDirectory("rea-symlink-test-");
await symlink("/etc/passwd", join(root, "escape"));
@@ -31,62 +28,29 @@ itWithCaptureCapability(
parseProcessScenario({
executable: "/usr/bin/true",
working_directory: root,
filesystem_roots: [root],
filesystem_observation_paths: [root],
}),
{
status: "enabled",
executableRoots: ["/usr/bin"],
workingRoots: [root],
allowedEnvironment: [],
networkAccess: "external",
},
);
expect(result.ok).toBe(true);
if (!result.ok) throw result.error;
const escaped = result.value.files_after.find((file) =>
file.path.endsWith(":escape"),
);
expect(escaped?.symlink_target).toBe("<outside-declared-root>");
expect(result.value.truncated).toBe(true);
expect(escaped?.symlink_target).toBe("/etc/passwd");
expect(result.value.truncated).toBe(false);
expect(JSON.stringify(result.value.files_after)).not.toContain(root);
expect(JSON.stringify(result.value.files_after)).not.toContain(
"/etc/passwd",
);
expect(
result.value.files_after.some((file) => file.path.includes("passwd")),
).toBe(false);
} finally {
await rm(root, { recursive: true, force: true });
}
},
);
// Policy denial is decided before any process is launched, so this assertion
// stays ungated and still runs on hosts without native PTY authority.
it("does not launch when policy denies capture", async () => {
const scenario = parseProcessScenario({
executable: "/bin/sh",
working_directory: "/tmp",
});
const result = await captureProcessScenario(scenario, {
status: "disabled",
});
expect(result.ok).toBe(false);
if (result.ok) throw new Error("expected policy refusal");
expect(result.error).toBeInstanceOf(ProcessCaptureError);
expect(result.error).toMatchObject({
userCategory: "permission_required",
message: "process capture is disabled",
});
});
itWithCaptureCapability(
"distinguishes timeout from cancellation and cleans both runs",
async () => {
const policy: ProcessExecutionPolicy = {
status: "enabled",
executableRoots: [dirname(process.execPath)],
workingRoots: [dirname(processFixture)],
allowedEnvironment: [],
networkAccess: "external",
};
const timedOut = await captureProcessScenario(
parseProcessScenario({
executable: process.execPath,
@@ -95,7 +59,6 @@ itWithCaptureCapability(
timeout_ms: 50,
idle_timeout_ms: 5_000,
}),
policy,
);
expect(timedOut.ok).toBe(true);
if (!timedOut.ok) throw timedOut.error;
@@ -115,7 +78,6 @@ itWithCaptureCapability(
timeout_ms: 5_000,
idle_timeout_ms: 5_000,
}),
policy,
controller.signal,
);
expect(cancelled.ok).toBe(false);
@@ -159,11 +121,7 @@ itWithCaptureCapability(
max_uses: 1,
when: {
kind: "terminal_text",
view: "decoded",
encoding: "utf8",
literal: "prompt>",
case_sensitive: true,
control_sequences: "include",
occurrence: 1,
since: { kind: "scenario_start" },
consume: true,
@@ -186,11 +144,7 @@ itWithCaptureCapability(
max_uses: 1,
when: {
kind: "terminal_text",
view: "decoded",
encoding: "utf8",
literal: "input:answer",
case_sensitive: true,
control_sequences: "include",
occurrence: 1,
since: { kind: "scenario_start" },
consume: true,
@@ -211,11 +165,7 @@ itWithCaptureCapability(
max_uses: 1,
when: {
kind: "terminal_text",
view: "decoded",
encoding: "utf8",
literal: "resize:100x40",
case_sensitive: true,
control_sequences: "include",
occurrence: 1,
since: { kind: "scenario_start" },
consume: true,
@@ -227,20 +177,13 @@ itWithCaptureCapability(
signal: "SIGINT",
},
],
target: { kind: "finish", outcome: "passed" },
target: { kind: "finish" },
},
],
},
],
},
}),
{
status: "enabled",
executableRoots: [dirname(process.execPath)],
workingRoots: [dirname(processFixture)],
allowedEnvironment: [],
networkAccess: "external",
},
);
if (!result.ok) throw result.error;
expect(result.ok).toBe(true);
@@ -273,19 +216,6 @@ itWithCaptureCapability(
timeout_ms: 2_000,
idle_timeout_ms: 2_000,
}),
{
status: "enabled",
executableRoots: [
join(dirname(process.execPath), "missing"),
dirname(process.execPath),
],
workingRoots: [
join(dirname(processFixture), "missing"),
dirname(processFixture),
],
allowedEnvironment: [],
networkAccess: "external",
},
);
expect(result.ok).toBe(true);
if (!result.ok) throw result.error;
@@ -310,13 +240,6 @@ itWithCaptureCapability(
timeout_ms: 2_000,
idle_timeout_ms: 2_000,
}),
{
status: "enabled",
executableRoots: [dirname(process.execPath)],
workingRoots: [dirname(processFixture)],
allowedEnvironment: [],
networkAccess: "external",
},
);
expect(result.ok).toBe(true);
if (!result.ok) throw result.error;
@@ -330,7 +253,7 @@ itWithCaptureCapability(
expect(
commands.some((command) => command.includes("tree-grandchild")),
).toBe(true);
expect(JSON.stringify(result.value.process_samples)).not.toContain(
expect(JSON.stringify(result.value.process_samples)).toContain(
dirname(processFixture),
);
const { stdout } = await execFileAsync("ps", ["-axo", "command="]);
@@ -33,11 +33,7 @@ function eventTrigger(
function collectionTriggers() {
const terminalTrigger = (literal: string) => ({
kind: "terminal_text" as const,
view: "decoded" as const,
encoding: "utf8" as const,
literal,
case_sensitive: true,
control_sequences: "include" as const,
occurrence: 1,
since: { kind: "scenario_start" as const },
consume: false,
@@ -65,11 +61,9 @@ function collectionTriggers() {
"filesystem",
{
name: "ready_snapshot",
files: [],
effects: [],
truncated: false,
},
["at_ms"],
["at_ms", "files", "effects"],
),
eventTrigger(
"shim",
@@ -119,6 +113,8 @@ function createMultiSourceScenario(root: string, script: string) {
executable: process.execPath,
arguments: [script, "codex"],
working_directory: root,
filesystem_observation_paths: [root],
normalization: { paths: true },
replay: {
http: [{ method: "GET", path: "/reactive", status: 200, body: "ok" }],
websocket_messages: ["reactive-server"],
@@ -150,11 +146,7 @@ function createMultiSourceScenario(root: string, script: string) {
max_uses: 1,
when: {
kind: "terminal_text",
view: "decoded",
encoding: "utf8",
literal: "Ready",
case_sensitive: true,
control_sequences: "include",
occurrence: 1,
since: { kind: "scenario_start" },
consume: true,
@@ -175,7 +167,7 @@ function createMultiSourceScenario(root: string, script: string) {
max_uses: 1,
when: { kind: "all", triggers: collectionTriggers() },
actions: [],
target: { kind: "finish", outcome: "passed" },
target: { kind: "finish" },
},
],
},
@@ -193,13 +185,7 @@ itWithCaptureCapability(
new URL("../../fixtures/processReactiveScenario.mjs", import.meta.url),
);
const run = () =>
captureProcessScenario(createMultiSourceScenario(root, script), {
status: "enabled",
executableRoots: [dirname(process.execPath)],
workingRoots: [root],
allowedEnvironment: [],
networkAccess: "external",
});
captureProcessScenario(createMultiSourceScenario(root, script));
try {
const first = await run();
const second = await run();
@@ -31,11 +31,7 @@ function createInteractiveScenario(root: string, script: string) {
max_uses: 1,
when: {
kind: "terminal_text",
view: "decoded",
encoding: "utf8",
literal: "Ready",
case_sensitive: true,
control_sequences: "include",
occurrence: 1,
since: { kind: "scenario_start" },
consume: true,
@@ -59,17 +55,13 @@ function createInteractiveScenario(root: string, script: string) {
max_uses: 1,
when: {
kind: "terminal_text",
view: "decoded",
encoding: "utf8",
literal: "Done",
case_sensitive: true,
control_sequences: "include",
occurrence: 1,
since: { kind: "state_entry" },
consume: true,
},
actions: [],
target: { kind: "finish", outcome: "passed" },
target: { kind: "finish" },
},
],
},
@@ -282,13 +274,7 @@ itWithCaptureCapability(
);
const scenario = createInteractiveScenario(root, script);
try {
const result = await captureProcessScenario(scenario, {
status: "enabled",
executableRoots: [dirname(process.execPath)],
workingRoots: [root],
allowedEnvironment: [],
networkAccess: "external",
});
const result = await captureProcessScenario(scenario);
if (!result.ok) throw result.error;
assertCompletedCapture(result.value);
assertControlAndTransitionValidation(result.value);
@@ -329,17 +315,13 @@ itWithCaptureCapability(
max_uses: 1,
when: {
kind: "terminal_text",
view: "decoded",
encoding: "utf8",
literal: "never-produced",
case_sensitive: true,
control_sequences: "include",
occurrence: 1,
since: { kind: "scenario_start" },
consume: true,
},
actions: [],
target: { kind: "finish", outcome: "passed" },
target: { kind: "finish" },
},
],
},
@@ -347,13 +329,7 @@ itWithCaptureCapability(
},
});
try {
const result = await captureProcessScenario(scenario, {
status: "enabled",
executableRoots: [dirname(process.execPath)],
workingRoots: [root],
allowedEnvironment: [],
networkAccess: "external",
});
const result = await captureProcessScenario(scenario);
expect(result.ok).toBe(true);
if (!result.ok) throw result.error;
expect(result.value.reactive_run).toMatchObject({
@@ -8,7 +8,6 @@ import { captureProcessScenario } from "../../../src/application/ProcessHarness.
import {
digestProcessCommitment,
parseProcessScenario,
type ProcessExecutionPolicy,
} from "../../../src/domain/processCapture.js";
itWithCaptureCapability(
@@ -117,13 +116,7 @@ itWithCaptureCapability(
},
});
try {
const capture = await captureProcessScenario(scenario, {
status: "enabled",
executableRoots: [dirname(process.execPath)],
workingRoots: [root],
allowedEnvironment: [],
networkAccess: "external",
});
const capture = await captureProcessScenario(scenario);
expect(capture.ok).toBe(true);
if (!capture.ok) throw capture.error;
expect(
@@ -158,7 +151,7 @@ itWithCaptureCapability(
);
itWithCaptureCapability(
"captures PTY, filesystem, descendants, HTTP replay, and redacts environment",
"captures PTY, filesystem, descendants, and HTTP replay with local values",
async () => {
const root = await createTestTempDirectory("rea-harness-test-");
const script = join(root, "fixture.mjs");
@@ -176,26 +169,18 @@ itWithCaptureCapability(
"child.kill();",
].join("\n"),
);
const policy: ProcessExecutionPolicy = {
status: "enabled",
executableRoots: [dirname(process.execPath)],
workingRoots: [root],
allowedEnvironment: ["SECRET"],
networkAccess: "external",
};
const scenario = parseProcessScenario({
executable: process.execPath,
arguments: [script],
working_directory: root,
filesystem_roots: [root],
filesystem_observation_paths: [root],
environment: { SECRET: "do-not-record" },
secret_aliases: ["SECRET"],
replay: {
http: [{ method: "GET", path: "/probe", status: 200, body: "ok" }],
},
});
try {
const capture = await captureProcessScenario(scenario, policy);
const capture = await captureProcessScenario(scenario);
expect(capture.ok).toBe(true);
if (!capture.ok) throw capture.error;
expect(
@@ -203,7 +188,7 @@ itWithCaptureCapability(
).toContain("reply:ok");
expect(
capture.value.frames.map((frame) => frame.data).join(""),
).toContain("sensitive:<redacted>");
).toContain("sensitive:do-not-record");
expect(
capture.value.files_after.some((file) =>
file.path.endsWith("result.txt"),
@@ -220,7 +205,7 @@ itWithCaptureCapability(
(event) => event.protocol === "http" && event.path === "/probe",
),
).toBe(true);
expect(JSON.stringify(capture.value)).not.toContain("do-not-record");
expect(JSON.stringify(capture.value)).toContain("do-not-record");
expect(await readFile(join(root, "result.txt"), "utf8")).toBe("created");
expect(JSON.stringify(capture.value.files_after)).not.toContain(root);
} finally {
@@ -35,6 +35,33 @@ it("serves bounded HTTP and WebSocket replay on loopback", async () => {
}
});
it("matches and records the full HTTP request target including its query", async () => {
const scenario = parseProcessScenario({
executable: "/bin/sh",
working_directory: "/tmp",
replay: {
http: [
{ method: "GET", path: "/item?id=1", status: 200, body: "matched" },
],
},
});
const replay = await startLoopbackReplay(scenario);
try {
const matched = await fetch(`${replay.httpUrl}/item?id=1`);
expect(matched.status).toBe(200);
expect(await matched.text()).toBe("matched");
const differentQuery = await fetch(`${replay.httpUrl}/item?id=2`);
expect(differentQuery.status).toBe(404);
expect(
replay.events
.filter(({ direction }) => direction === "request")
.map(({ path }) => path),
).toEqual(["/item?id=1", "/item?id=2"]);
} finally {
await replay.close();
}
});
it("matches bounded HTTP scripts without persisting request secrets", async () => {
const scenario = parseProcessScenario({
executable: "/bin/sh",
@@ -14,6 +14,8 @@ const buildTerminalScenario = (root: string, script: string) =>
executable: process.execPath,
arguments: [script],
working_directory: root,
filesystem_observation_paths: [root],
normalization: { paths: true },
checkpoints: [
{
name: "probe_seen",
@@ -92,17 +94,15 @@ const buildTerminalScenario = (root: string, script: string) =>
source: "filesystem",
exact: {
name: "reactive_shim_seen",
files: [],
effects: [],
truncated: false,
},
ignore_fields: ["at_ms"],
ignore_fields: ["at_ms", "files", "effects"],
since: { kind: "scenario_start" },
consume: true,
cardinality: { min: 1, max: 1 },
},
actions: [],
target: { kind: "finish", outcome: "passed" },
target: { kind: "finish" },
},
],
},
@@ -129,13 +129,6 @@ it("renders terminal state, records shim invocations, and captures literal check
if (!capability.available) return;
const result = await captureProcessScenario(
buildTerminalScenario(root, script),
{
status: "enabled",
executableRoots: [dirname(process.execPath)],
workingRoots: [root],
allowedEnvironment: [],
networkAccess: "external",
},
);
expect(result.ok).toBe(true);
if (!result.ok) throw result.error;