From 793ab582bebc40fbff2d8f7f969aad5283e7af54 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Mon, 16 Nov 2026 08:51:27 +0800 Subject: [PATCH] refactor(desktop): give the agentenv provider name an entry file and name the build computer's controlled routes as a port (#11600) * refactor(desktop): give the agentenv provider name its own entry file and move ComputerRelease into src/domain * refactor(desktop): name the build computer's controlled routes and controller answer as a port (#11604) --- scripts/lib/module-layers.baseline.json | 2 +- scripts/lib/module-layers.mjs | 1 + src/application/desktop/DesktopBuildBundle.ts | 2 +- .../desktop/DesktopBuildCapture.ts | 19 +++--- .../desktop/DesktopBuildCaptureFailure.ts | 10 +-- .../desktop/DesktopBuildCommands.ts | 8 +-- .../desktop/DesktopBuildComputers.ts | 8 +-- src/application/desktop/DesktopBuildExport.ts | 4 +- .../desktop/DesktopBuildSecrets.ts | 2 +- src/application/desktop/DesktopBuildSolves.ts | 2 +- .../desktop/DesktopBuildSummary.ts | 2 +- .../desktop/DesktopBuildWitness.ts | 2 +- .../desktop/DesktopBuildWitnessBundle.ts | 2 +- .../desktop/DesktopBuildWitnessRecord.ts | 2 +- .../desktop/DesktopRemoteTaskReaders.ts | 6 +- src/desktop/AgentEnvComputer.ts | 15 +++-- src/desktop/AgentEnvComputerHelper.ts | 15 +---- src/desktop/AgentEnvProviderIdentity.ts | 2 + src/desktop/AgentEnvSolveHelper.ts | 2 +- src/desktop/BuildComputerController.ts | 18 ++--- src/desktop/BuildComputerLongRuns.test.ts | 2 +- src/desktop/BuildComputerLongRuns.ts | 19 +++--- src/desktop/ScreenJudgeProcess.ts | 8 +-- src/domain/desktop/computerRelease.ts | 11 +++ src/ports/BuildComputerControl.ts | 67 +++++++++++++++++++ .../desktopLongBuildController.test.ts | 2 +- 26 files changed, 146 insertions(+), 87 deletions(-) create mode 100644 src/desktop/AgentEnvProviderIdentity.ts create mode 100644 src/domain/desktop/computerRelease.ts create mode 100644 src/ports/BuildComputerControl.ts diff --git a/scripts/lib/module-layers.baseline.json b/scripts/lib/module-layers.baseline.json index 6d4652455b..5c3837cb40 100644 --- a/scripts/lib/module-layers.baseline.json +++ b/scripts/lib/module-layers.baseline.json @@ -12,6 +12,6 @@ "model -> artifacts": 1 }, "entry": { - "application -> desktop": 41 + "application -> desktop": 28 } } diff --git a/scripts/lib/module-layers.mjs b/scripts/lib/module-layers.mjs index 1fc78717f5..0df5b6f1f1 100644 --- a/scripts/lib/module-layers.mjs +++ b/scripts/lib/module-layers.mjs @@ -281,6 +281,7 @@ export const ENTRY_FILES = Object.freeze( ], desktop: [ "AgentEnvComputer.ts", + "AgentEnvProviderIdentity.ts", "BuildComputerEnvironment.ts", "DconfDatabaseReader.ts", "DesktopBuildDoctorFacts.ts", diff --git a/src/application/desktop/DesktopBuildBundle.ts b/src/application/desktop/DesktopBuildBundle.ts index ccdc38b867..da8b7d11b3 100644 --- a/src/application/desktop/DesktopBuildBundle.ts +++ b/src/application/desktop/DesktopBuildBundle.ts @@ -18,7 +18,7 @@ import { AnalysisInputError, } from "../../domain/analysisErrorCore.js"; import { isLockFile } from "../../domain/desktop/appExportUnowned.js"; -import { AGENTENV_PROVIDER } from "../../desktop/AgentEnvComputerHelper.js"; +import { AGENTENV_PROVIDER } from "../../desktop/AgentEnvProviderIdentity.js"; import { PrivateRuntimeRoot } from "../../process/PrivateRuntimeRoot.js"; import { type ArtifactResourceScope, diff --git a/src/application/desktop/DesktopBuildCapture.ts b/src/application/desktop/DesktopBuildCapture.ts index 380680c7f3..7a57f4bb12 100644 --- a/src/application/desktop/DesktopBuildCapture.ts +++ b/src/application/desktop/DesktopBuildCapture.ts @@ -26,13 +26,13 @@ import { import type { JsonValue } from "../../domain/jsonValue.js"; import { ProviderAdapterError } from "../../domain/providerAdapterError.js"; import { err, ok, type Result } from "../../domain/result.js"; -import { AGENTENV_PROVIDER } from "../../desktop/AgentEnvComputerHelper.js"; +import { AGENTENV_PROVIDER } from "../../desktop/AgentEnvProviderIdentity.js"; import type { AgentEnvComputer } from "../../desktop/AgentEnvComputer.js"; -import { - controller, - type Answer, - type ControlledComputer, -} from "../../desktop/BuildComputerController.js"; +import { controller } from "../../desktop/BuildComputerController.js"; +import type { + BuildControllerAnswer, + ControlledComputer, +} from "../../ports/BuildComputerControl.js"; import { BuildComputerLongRuns } from "../../desktop/BuildComputerLongRuns.js"; import { endedCapture, @@ -394,10 +394,13 @@ export class DesktopBuildCapture { readonly package_lists: number; readonly package_lists_error: string | null; }, - { readonly failure: AnalysisError; readonly answer?: Answer } + { + readonly failure: AnalysisError; + readonly answer?: BuildControllerAnswer; + } > > { - let answer: Answer; + let answer: BuildControllerAnswer; try { answer = await controller( this.computer, diff --git a/src/application/desktop/DesktopBuildCaptureFailure.ts b/src/application/desktop/DesktopBuildCaptureFailure.ts index 640200d620..13b51089e2 100644 --- a/src/application/desktop/DesktopBuildCaptureFailure.ts +++ b/src/application/desktop/DesktopBuildCaptureFailure.ts @@ -6,11 +6,11 @@ import { type DesktopApplicationCapture, } from "../../domain/desktop/desktopCapture.js"; import { ProviderAdapterError } from "../../domain/providerAdapterError.js"; -import { AGENTENV_PROVIDER } from "../../desktop/AgentEnvComputerHelper.js"; +import { AGENTENV_PROVIDER } from "../../desktop/AgentEnvProviderIdentity.js"; import type { - Answer, + BuildControllerAnswer, ControlledComputer, -} from "../../desktop/BuildComputerController.js"; +} from "../../ports/BuildComputerControl.js"; import { adapterError, readOutput, @@ -75,7 +75,7 @@ const unredacted: Redact = (text) => text; /** Why the capture is not answering, from what the controller saw instead of the event; its output stays out of the message. */ export const notAnswered = ( operation: string, - answer: Answer, + answer: BuildControllerAnswer, redact: Redact = unredacted, ): AnalysisError => { if (answer.error !== undefined) return adapterError(operation, answer.error); @@ -151,7 +151,7 @@ const appExited = ( export const endedCapture = async ( computer: ControlledComputer, step: CaptureStep & { readonly folder: string; readonly redact?: Redact }, - answer: Answer, + answer: BuildControllerAnswer, signal: AbortSignal, ): Promise => { const { redact = unredacted } = step; diff --git a/src/application/desktop/DesktopBuildCommands.ts b/src/application/desktop/DesktopBuildCommands.ts index c88aab7aff..9ae6129920 100644 --- a/src/application/desktop/DesktopBuildCommands.ts +++ b/src/application/desktop/DesktopBuildCommands.ts @@ -16,11 +16,9 @@ import { guestFileAnswerCeiling, guestFileAnswerRefusal, } from "../../desktop/AgentEnvComputer.js"; -import { AGENTENV_PROVIDER } from "../../desktop/AgentEnvComputerHelper.js"; -import { - runRea as runControllerRea, - type ControlledComputer, -} from "../../desktop/BuildComputerController.js"; +import { AGENTENV_PROVIDER } from "../../desktop/AgentEnvProviderIdentity.js"; +import { runRea as runControllerRea } from "../../desktop/BuildComputerController.js"; +import type { ControlledComputer } from "../../ports/BuildComputerControl.js"; /** The work folder REA keeps under the computer user's home; every capture leaves it out. */ export const WORK = ".rea-build"; diff --git a/src/application/desktop/DesktopBuildComputers.ts b/src/application/desktop/DesktopBuildComputers.ts index 472b21558f..016b601992 100644 --- a/src/application/desktop/DesktopBuildComputers.ts +++ b/src/application/desktop/DesktopBuildComputers.ts @@ -35,11 +35,9 @@ import { type ComputerStartTiming, type DriverResult, } from "../../desktop/AgentEnvComputer.js"; -import { - AGENTENV_PROVIDER, - ComputerHelper, - type ComputerRelease, -} from "../../desktop/AgentEnvComputerHelper.js"; +import { ComputerHelper } from "../../desktop/AgentEnvComputerHelper.js"; +import { AGENTENV_PROVIDER } from "../../desktop/AgentEnvProviderIdentity.js"; +import type { ComputerRelease } from "../../domain/desktop/computerRelease.js"; import { resolveBuildComputerEnvironment, type BuildComputerDefaults, diff --git a/src/application/desktop/DesktopBuildExport.ts b/src/application/desktop/DesktopBuildExport.ts index 81a85b06e6..28056ca587 100644 --- a/src/application/desktop/DesktopBuildExport.ts +++ b/src/application/desktop/DesktopBuildExport.ts @@ -29,12 +29,12 @@ import { } from "../../domain/desktop/buildSecrets.js"; import { jsonValueSchema, type JsonValue } from "../../domain/jsonValue.js"; import { err, ok, type Result } from "../../domain/result.js"; -import { AGENTENV_PROVIDER } from "../../desktop/AgentEnvComputerHelper.js"; +import { AGENTENV_PROVIDER } from "../../desktop/AgentEnvProviderIdentity.js"; import { BUILD_REA_TIMEOUT_S, fetchHomeFolder, - type ControlledComputer, } from "../../desktop/BuildComputerController.js"; +import type { ControlledComputer } from "../../ports/BuildComputerControl.js"; import { adapterError, ENDS, diff --git a/src/application/desktop/DesktopBuildSecrets.ts b/src/application/desktop/DesktopBuildSecrets.ts index adf99e697d..dfa1bacc76 100644 --- a/src/application/desktop/DesktopBuildSecrets.ts +++ b/src/application/desktop/DesktopBuildSecrets.ts @@ -25,7 +25,7 @@ import type { AgentEnvComputer, DriverResult, } from "../../desktop/AgentEnvComputer.js"; -import { AGENTENV_PROVIDER } from "../../desktop/AgentEnvComputerHelper.js"; +import { AGENTENV_PROVIDER } from "../../desktop/AgentEnvProviderIdentity.js"; import { listBuildSecretHandles, readBuildSecretFile, diff --git a/src/application/desktop/DesktopBuildSolves.ts b/src/application/desktop/DesktopBuildSolves.ts index 60f92864ab..2842f4b1f4 100644 --- a/src/application/desktop/DesktopBuildSolves.ts +++ b/src/application/desktop/DesktopBuildSolves.ts @@ -38,7 +38,7 @@ import { import { ProviderAdapterError } from "../../domain/providerAdapterError.js"; import { err, ok, type Result } from "../../domain/result.js"; import { safeParseUtf8Json } from "../../domain/safeJson.js"; -import { AGENTENV_PROVIDER } from "../../desktop/AgentEnvComputerHelper.js"; +import { AGENTENV_PROVIDER } from "../../desktop/AgentEnvProviderIdentity.js"; import { runSolveHelper, SolveCleanupError, diff --git a/src/application/desktop/DesktopBuildSummary.ts b/src/application/desktop/DesktopBuildSummary.ts index 472973d61f..3a1613b275 100644 --- a/src/application/desktop/DesktopBuildSummary.ts +++ b/src/application/desktop/DesktopBuildSummary.ts @@ -19,7 +19,7 @@ import { type JsonValue, } from "../../domain/jsonValue.js"; import { err, ok, type Result } from "../../domain/result.js"; -import type { ControlledComputer } from "../../desktop/BuildComputerController.js"; +import type { ControlledComputer } from "../../ports/BuildComputerControl.js"; import { readOutput, reportedFailure, runRea } from "./DesktopBuildCommands.js"; const STOP = "stop_build_capture"; diff --git a/src/application/desktop/DesktopBuildWitness.ts b/src/application/desktop/DesktopBuildWitness.ts index 2f1b4d199f..d4168bdb8e 100644 --- a/src/application/desktop/DesktopBuildWitness.ts +++ b/src/application/desktop/DesktopBuildWitness.ts @@ -34,7 +34,7 @@ import type { AgentEnvComputer, RecordingManifest, } from "../../desktop/AgentEnvComputer.js"; -import { AGENTENV_PROVIDER } from "../../desktop/AgentEnvComputerHelper.js"; +import { AGENTENV_PROVIDER } from "../../desktop/AgentEnvProviderIdentity.js"; import { silentProgressReporter, type ProgressReporter, diff --git a/src/application/desktop/DesktopBuildWitnessBundle.ts b/src/application/desktop/DesktopBuildWitnessBundle.ts index f91176db27..51798b63e6 100644 --- a/src/application/desktop/DesktopBuildWitnessBundle.ts +++ b/src/application/desktop/DesktopBuildWitnessBundle.ts @@ -32,7 +32,7 @@ import { guestFileAnswerWorkingBytes, type AgentEnvComputer, } from "../../desktop/AgentEnvComputer.js"; -import { AGENTENV_PROVIDER } from "../../desktop/AgentEnvComputerHelper.js"; +import { AGENTENV_PROVIDER } from "../../desktop/AgentEnvProviderIdentity.js"; import { readHostFile } from "../../desktop/HostFileRead.js"; import { errorMessage } from "../../kernel/errorMessage.js"; diff --git a/src/application/desktop/DesktopBuildWitnessRecord.ts b/src/application/desktop/DesktopBuildWitnessRecord.ts index 7d82483542..d0b255026e 100644 --- a/src/application/desktop/DesktopBuildWitnessRecord.ts +++ b/src/application/desktop/DesktopBuildWitnessRecord.ts @@ -17,7 +17,7 @@ import type { AgentEnvComputer, RecordingManifest, } from "../../desktop/AgentEnvComputer.js"; -import { AGENTENV_PROVIDER } from "../../desktop/AgentEnvComputerHelper.js"; +import { AGENTENV_PROVIDER } from "../../desktop/AgentEnvProviderIdentity.js"; import { LOGGED_ACTIONS, LOGGED_BYTES, diff --git a/src/application/desktop/DesktopRemoteTaskReaders.ts b/src/application/desktop/DesktopRemoteTaskReaders.ts index bafb82efcf..998b762a26 100644 --- a/src/application/desktop/DesktopRemoteTaskReaders.ts +++ b/src/application/desktop/DesktopRemoteTaskReaders.ts @@ -19,10 +19,8 @@ import { import { ProviderCleanupError } from "../../domain/providerCleanupError.js"; import { AnalysisCleanupRelease } from "../../domain/analysisCleanupRelease.js"; import { ProviderAdapterError } from "../../domain/providerAdapterError.js"; -import { - AGENTENV_PROVIDER, - type ComputerRelease, -} from "../../desktop/AgentEnvComputerHelper.js"; +import { AGENTENV_PROVIDER } from "../../desktop/AgentEnvProviderIdentity.js"; +import type { ComputerRelease } from "../../domain/desktop/computerRelease.js"; import { AbortedWait, waitForAbortable, diff --git a/src/desktop/AgentEnvComputer.ts b/src/desktop/AgentEnvComputer.ts index 376a54568b..8c3ee4dc64 100644 --- a/src/desktop/AgentEnvComputer.ts +++ b/src/desktop/AgentEnvComputer.ts @@ -10,10 +10,12 @@ import { Deadline } from "../domain/deadline.js"; import { jsonObjectSchema, type JsonValue } from "../domain/jsonValue.js"; import { StructuredContentMcpClient } from "../providers/StructuredContentMcpClient.js"; import { validateMcpHttpResponse } from "../providers/Utf8McpResponse.js"; +import type { ComputerHelper } from "./AgentEnvComputerHelper.js"; +import type { ComputerRelease } from "../domain/desktop/computerRelease.js"; import type { - ComputerHelper, - ComputerRelease, -} from "./AgentEnvComputerHelper.js"; + ComputerCommandResult, + ControlledComputer, +} from "../ports/BuildComputerControl.js"; import { DATA_OBJECTS, dataGetSchema, @@ -183,15 +185,14 @@ const rpcSchema = z.union([ z.object({ result: z.looseObject({}) }), z.object({ error: z.looseObject({ message: z.string() }) }), ]); -const execSchema = z.object({ +/** `computer-exec/v1`'s answer: a command's outcome, its output without the control token. */ +const execSchema: z.ZodType = z.object({ exit_code: z.int().nullable(), stdout: z.string(), stderr: z.string(), truncated: z.boolean(), timed_out: z.boolean(), }); -/** A command's outcome through `computer-exec/v1`, its output without the control token. */ -export type ComputerCommandResult = z.infer; const cardSchema = z.looseObject({ children_environments: z .array(z.looseObject({ name: z.string(), url: z.string().optional() })) @@ -324,7 +325,7 @@ export class AppDataRefusal extends Error { } } -export class AgentEnvComputer { +export class AgentEnvComputer implements ControlledComputer { readonly sandboxId: string; readonly #baseUrl: string; readonly #token: string | null; diff --git a/src/desktop/AgentEnvComputerHelper.ts b/src/desktop/AgentEnvComputerHelper.ts index f390e6b612..2eca88f157 100644 --- a/src/desktop/AgentEnvComputerHelper.ts +++ b/src/desktop/AgentEnvComputerHelper.ts @@ -23,10 +23,11 @@ import { type ArtifactResourceScope, } from "../resources/index.js"; import { errorMessage } from "../kernel/errorMessage.js"; +import type { ComputerRelease } from "../domain/desktop/computerRelease.js"; +import { AGENTENV_PROVIDER } from "./AgentEnvProviderIdentity.js"; const execFileAsync = promisify(execFile); -export const AGENTENV_PROVIDER = "agentenv"; const HELPER = fileURLToPath( new URL("../../bridge/agentenv/computer.py", import.meta.url), ); @@ -48,18 +49,6 @@ const handshakeSchema = z.union([ /** The helper's one JSON line: where the kept computer is, or why there is none. */ export type Handshake = z.infer; -/** How a computer's teardown ended: confirmed by agentenv or by removing its containers, or not confirmed. */ -export type ComputerRelease = - | { - readonly verified: true; - readonly teardown: "agentenv" | "container_label"; - } - | { - readonly verified: false; - readonly reason: string; - readonly resources: readonly string[]; - }; - const unavailable = (operation: string, reason: string, cause?: unknown) => new AnalysisCapabilityUnavailableError(AGENTENV_PROVIDER, operation, reason, { userMessage: reason, diff --git a/src/desktop/AgentEnvProviderIdentity.ts b/src/desktop/AgentEnvProviderIdentity.ts new file mode 100644 index 0000000000..785cb96ebf --- /dev/null +++ b/src/desktop/AgentEnvProviderIdentity.ts @@ -0,0 +1,2 @@ +/** Provider name the desktop build workflows report for the agentenv computer they drive. */ +export const AGENTENV_PROVIDER = "agentenv"; diff --git a/src/desktop/AgentEnvSolveHelper.ts b/src/desktop/AgentEnvSolveHelper.ts index ee1c104b19..7c9d8f37b0 100644 --- a/src/desktop/AgentEnvSolveHelper.ts +++ b/src/desktop/AgentEnvSolveHelper.ts @@ -15,10 +15,10 @@ import { } from "../process/ProviderProcess.js"; import { SolveSandboxRoot } from "./SolveSandboxRoot.js"; import { - AGENTENV_PROVIDER, agentEnvInterpreter, removeSandbox, } from "./AgentEnvComputerHelper.js"; +import { AGENTENV_PROVIDER } from "./AgentEnvProviderIdentity.js"; import { errorMessage } from "../kernel/errorMessage.js"; const HELPER = fileURLToPath( diff --git a/src/desktop/BuildComputerController.ts b/src/desktop/BuildComputerController.ts index 148ab4849c..8ecff91e1d 100644 --- a/src/desktop/BuildComputerController.ts +++ b/src/desktop/BuildComputerController.ts @@ -11,8 +11,11 @@ import { guestFileAnswerBytes, guestFileAnswerCeiling, guestFileAnswerWorkingBytes, - type AgentEnvComputer, } from "./AgentEnvComputer.js"; +import type { + BuildControllerAnswer, + ControlledComputer, +} from "../ports/BuildComputerControl.js"; const CONTROLLER = fileURLToPath( new URL("../../bridge/agentenv/capture.py", import.meta.url), @@ -64,12 +67,6 @@ const controllerArgumentPieces = (text: string): readonly string[] => { return pieces; }; -/** The computer routes REA's build controller uses, and the control token's redaction for what it reads. */ -export type ControlledComputer = Pick< - AgentEnvComputer, - "exec" | "homeFiles" | "redacted" ->; - /** * Run one command of REA's build controller in the computer, as its user and * in its home, and return the JSON object it answers with. The controller's @@ -145,8 +142,8 @@ export const runBuildController = async ( ); }; -/** What REA's build controller answers a command with. The wire format stays here. */ -export const answerSchema = z.looseObject({ +/** What REA's build controller answers a command with. The wire format stays here; the port names its fields. */ +export const answerSchema: z.ZodType = z.looseObject({ error: z.string().optional(), /** Why the controller refused a request before acting on it, such as a state path outside the home. */ refused: z.string().optional(), @@ -170,7 +167,6 @@ export const answerSchema = z.looseObject({ .looseObject({ lists: z.int().nonnegative(), error: z.string().optional() }) .optional(), }); -export type Answer = z.infer; /** One controller command, its answer parsed. */ export const controller = async ( @@ -178,7 +174,7 @@ export const controller = async ( command: "start" | "mark" | "stop", argumentsJson: Readonly>, options: { readonly timeoutS: number; readonly signal: AbortSignal }, -): Promise => +): Promise => answerSchema.parse( await runBuildController(computer, command, argumentsJson, options), ); diff --git a/src/desktop/BuildComputerLongRuns.test.ts b/src/desktop/BuildComputerLongRuns.test.ts index cd6df8faf9..b54465d2da 100644 --- a/src/desktop/BuildComputerLongRuns.test.ts +++ b/src/desktop/BuildComputerLongRuns.test.ts @@ -3,7 +3,7 @@ import { expect, it } from "vitest"; import { AnalysisCancelledError } from "../domain/analysisErrorCore.js"; import { ProviderCleanupError } from "../domain/providerCleanupError.js"; import { BuildComputerLongRuns } from "./BuildComputerLongRuns.js"; -import type { ControlledComputer } from "./BuildComputerController.js"; +import type { ControlledComputer } from "../ports/BuildComputerControl.js"; const response = (value: unknown) => ({ exit_code: 0, diff --git a/src/desktop/BuildComputerLongRuns.ts b/src/desktop/BuildComputerLongRuns.ts index f2082cb0af..ef04778193 100644 --- a/src/desktop/BuildComputerLongRuns.ts +++ b/src/desktop/BuildComputerLongRuns.ts @@ -8,16 +8,13 @@ import { import type { JsonValue } from "../domain/jsonValue.js"; import { ProviderAdapterError } from "../domain/providerAdapterError.js"; import { ProviderCleanupError } from "../domain/providerCleanupError.js"; -import { - AGENTENV_PROVIDER, - type ComputerRelease, -} from "./AgentEnvComputerHelper.js"; -import { - answerSchema, - runBuildController, - type Answer, - type ControlledComputer, -} from "./BuildComputerController.js"; +import { AGENTENV_PROVIDER } from "./AgentEnvProviderIdentity.js"; +import type { ComputerRelease } from "../domain/desktop/computerRelease.js"; +import { answerSchema, runBuildController } from "./BuildComputerController.js"; +import type { + BuildControllerAnswer, + ControlledComputer, +} from "../ports/BuildComputerControl.js"; import { errorMessage } from "../kernel/errorMessage.js"; const OPERATION = "export_build_environment"; @@ -285,7 +282,7 @@ export class BuildComputerLongRuns { } } - #receipt(job: Job, answer: Answer): JsonValue { + #receipt(job: Job, answer: BuildControllerAnswer): JsonValue { return { stdout: job.stdout, ...(typeof answer.stdout_bytes === "number" diff --git a/src/desktop/ScreenJudgeProcess.ts b/src/desktop/ScreenJudgeProcess.ts index 35f5370e68..438c4ec138 100644 --- a/src/desktop/ScreenJudgeProcess.ts +++ b/src/desktop/ScreenJudgeProcess.ts @@ -15,11 +15,9 @@ import { OwnedCommandFailure, runOwnedCommand, } from "../process/OwnedCommand.js"; -import { - AGENTENV_PROVIDER, - agentEnvInterpreter, - type ComputerRelease, -} from "./AgentEnvComputerHelper.js"; +import { agentEnvInterpreter } from "./AgentEnvComputerHelper.js"; +import { AGENTENV_PROVIDER } from "./AgentEnvProviderIdentity.js"; +import type { ComputerRelease } from "../domain/desktop/computerRelease.js"; import { errorMessage } from "../kernel/errorMessage.js"; const JUDGE_TIMEOUT_MS = 10 * 60 * 1000; diff --git a/src/domain/desktop/computerRelease.ts b/src/domain/desktop/computerRelease.ts new file mode 100644 index 0000000000..4a480a6d1e --- /dev/null +++ b/src/domain/desktop/computerRelease.ts @@ -0,0 +1,11 @@ +/** How a computer's teardown ended: confirmed by agentenv or by removing its containers, or not confirmed. */ +export type ComputerRelease = + | { + readonly verified: true; + readonly teardown: "agentenv" | "container_label"; + } + | { + readonly verified: false; + readonly reason: string; + readonly resources: readonly string[]; + }; diff --git a/src/ports/BuildComputerControl.ts b/src/ports/BuildComputerControl.ts new file mode 100644 index 0000000000..d961503a2e --- /dev/null +++ b/src/ports/BuildComputerControl.ts @@ -0,0 +1,67 @@ +import type { Buffer } from "node:buffer"; + +/** + * What the desktop build workflows ask of a running build computer, and what + * REA's build controller answers. The desktop provider implements and parses + * these; application workflows consume them without the provider's wire + * formats. + */ + +/** A command's outcome in the computer, its output without the control token. */ +export interface ComputerCommandResult { + readonly exit_code: number | null; + readonly stdout: string; + readonly stderr: string; + readonly truncated: boolean; + readonly timed_out: boolean; +} + +/** The computer routes REA's build controller uses, and the control token's redaction for what it reads. */ +export interface ControlledComputer { + /** Run `argv` in the computer, as its user and in its home. */ + exec( + argv: readonly string[], + timeoutS: number, + signal?: AbortSignal, + requestId?: string, + ): Promise; + /** Read files under the computer's home, within `bytes` in total. */ + homeFiles( + paths: readonly string[], + bytes: number, + signal?: AbortSignal, + ): Promise>; + /** `text` with the computer's control token redacted. */ + redacted(text: string): string; +} + +/** What REA's build controller answers a command with. Other fields it sends are kept but not named here. */ +export interface BuildControllerAnswer { + readonly error?: string | undefined; + /** Why the controller refused a request before acting on it, such as a state path outside the home. */ + readonly refused?: string | undefined; + readonly absent?: boolean | undefined; + readonly started?: boolean | undefined; + readonly pending?: boolean | undefined; + readonly finished?: boolean | undefined; + readonly cancelled?: boolean | undefined; + readonly line?: string | undefined; + readonly exited?: number | undefined; + readonly timed_out?: boolean | undefined; + readonly progress?: string | undefined; + readonly output?: string | undefined; + readonly exit_code?: number | null | undefined; + readonly output_bytes?: number | undefined; + readonly stdout_bytes?: number | undefined; + readonly stderr?: string | undefined; + /** False when the supervisor published a result but the process group is not confirmed gone. */ + readonly settled?: boolean | undefined; + readonly apt?: + | { + readonly lists: number; + readonly error?: string | undefined; + readonly [key: string]: unknown; + } + | undefined; + readonly [key: string]: unknown; +} diff --git a/tests/boundary/providers/desktopLongBuildController.test.ts b/tests/boundary/providers/desktopLongBuildController.test.ts index f8b5758162..af38c16e2b 100644 --- a/tests/boundary/providers/desktopLongBuildController.test.ts +++ b/tests/boundary/providers/desktopLongBuildController.test.ts @@ -7,7 +7,7 @@ import { expect, it } from "vitest"; import { AnalysisCancelledError } from "../../../src/domain/analysisErrorCore.js"; import { BuildComputerLongRuns } from "../../../src/desktop/BuildComputerLongRuns.js"; -import type { ControlledComputer } from "../../../src/desktop/BuildComputerController.js"; +import type { ControlledComputer } from "../../../src/ports/BuildComputerControl.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; const execute = promisify(execFile);