Files
reverse-engineering-anything/src/desktop/TaskReaderProcess.ts
T
morluto 62f5946ba1 refactor(process): route remaining captured output and cancellations through their owners (#11787)
Migrate the remaining 2 direct AnalysisCancelledError constructions onto cancelledBy and the remaining 14 process-snapshot stdout/stderr copy sites onto capturedProviderOutput, burning down both architecture-guard baselines to zero.
2026-11-16 20:39:33 -05:00

45 lines
1.4 KiB
TypeScript

import { randomUUID } from "node:crypto";
import type { ReaderCommandResult } from "../domain/desktop/appTaskReaders.js";
import { capturedProviderOutput } from "../process/capturedProviderOutput.js";
import { runOwnedCommand } from "../process/OwnedCommand.js";
/** The most a reader runner prints, its one answer line, plus room for what Python says when it fails. */
const RUNNER_OUTPUT_BYTES = 2 * 1024 * 1024;
/**
* Run a reader's runner command on this host, as the export does inside the
* build computer, as an owned process: a timeout or a cancellation stops the
* runner and every process carrying its run token, the reader's session
* included, before it settles.
*/
export const runReaderHere = async (
argv: readonly string[],
timeoutS: number,
signal?: AbortSignal,
): Promise<ReaderCommandResult> => {
const [command = "", ...rest] = argv;
const snapshot = await runOwnedCommand(
{
command,
arguments: rest,
runId: randomUUID(),
expectedCommand: null,
sweepTokenOwnedProcesses: true,
},
{
timeoutMs: timeoutS * 1000,
diagnosticBytes: RUNNER_OUTPUT_BYTES,
acceptNonZeroExit: true,
},
signal === undefined ? {} : { signal },
);
const { exit_code, stdout, stderr } = capturedProviderOutput(snapshot);
return {
exit_code: exit_code ?? null,
stdout,
stderr,
timed_out: false,
};
};