feat(process): support explicit stdin closure

This commit is contained in:
morluto
2026-07-24 13:13:09 +00:00
parent 62ac73cdd7
commit 205bf1529b
8 changed files with 74 additions and 14 deletions
+10 -4
View File
@@ -34,12 +34,12 @@ export interface RenderedTerminalFrame {
readonly serialized_state: string;
}
/** Scheduled input, resize, or signal with its observed dispatch outcome. */
/** Scheduled terminal interaction with its observed dispatch outcome. */
export interface InteractionEvent {
readonly sequence: number;
readonly scheduled_at_ms: number;
readonly dispatched_at_ms: number;
readonly type: "input" | "resize" | "signal";
readonly type: "input" | "resize" | "stdin_close" | "signal";
readonly data: string;
readonly outcome: "dispatched" | "target_exited" | "failed";
}
@@ -307,7 +307,7 @@ export const processCaptureSchema: z.ZodType<ProcessCapture> = z.object({
sequence: z.number().int().nonnegative(),
scheduled_at_ms: z.number().int().nonnegative(),
dispatched_at_ms: z.number().int().nonnegative(),
type: z.enum(["input", "resize", "signal"]),
type: z.enum(["input", "resize", "stdin_close", "signal"]),
data: z.string(),
outcome: z.enum(["dispatched", "target_exited", "failed"]),
}),
@@ -447,7 +447,13 @@ export const processCaptureSchema: z.ZodType<ProcessCapture> = z.object({
.max(PROCESS_REACTIVE_LIMITS.actionsPerTransition),
action_types: z
.array(
z.enum(["send_input", "resize", "send_signal", "checkpoint"]),
z.enum([
"send_input",
"resize",
"close_stdin",
"send_signal",
"checkpoint",
]),
)
.max(PROCESS_REACTIVE_LIMITS.actionsPerTransition),
}),
+1
View File
@@ -190,6 +190,7 @@ const processReactiveActionSchema = z.discriminatedUnion("type", [
columns: z.number().int().min(1).max(1_000),
rows: z.number().int().min(1).max(1_000),
}),
z.strictObject({ type: z.literal("close_stdin") }),
z.strictObject({
type: z.literal("send_signal"),
target: signalTargetSchema,
+18 -6
View File
@@ -121,6 +121,23 @@ const applyProcessReactiveTransition = (input: {
};
};
const terminalControlObservationMatches = (
action: Exclude<
ProcessReactiveScenario["states"][number]["on"][number]["actions"][number],
{ readonly type: "checkpoint" | "send_input" }
>,
payload: Readonly<Record<string, unknown>>,
): boolean => {
if (action.type === "resize")
return (
payload["type"] === "resize" &&
payload["data"] === `${String(action.columns)}x${String(action.rows)}`
);
if (action.type === "close_stdin")
return payload["type"] === "stdin_close" && payload["data"] === "";
return payload["type"] === "signal" && payload["data"] === action.signal;
};
const effectObservationMatchesAction = (
action: ProcessReactiveScenario["states"][number]["on"][number]["actions"][number],
observation: ProcessObservation,
@@ -160,12 +177,7 @@ const effectObservationMatchesAction = (
committedSensitiveInputs,
)
);
if (action.type === "resize")
return (
payload["type"] === "resize" &&
payload["data"] === `${String(action.columns)}x${String(action.rows)}`
);
return payload["type"] === "signal" && payload["data"] === action.signal;
return terminalControlObservationMatches(action, payload);
};
const expectedInputEvidence = (