Skip to content
Myr

answer.ts

This file

Path

apps/platform/src/workflows/answer.ts

148 lines · 5.1 KiB · TypeScript

Last changed by

Close the code browser and drafting wave: its decisions in two ADRs, every rule it added held, and its leftovers folded inoscabrielbefore adoption009640c

History of this file

Take it

The walk stopped after 200 commits: lines older than 878da37 point at it.

Merge build/420-release-downloads: the CLI installs from the platform itself, with no GitHub in the release pathoscabrielbefore adoption878da37

lines 1–2why, one step back
1/**
2 * The `Answer` Workflow: carries one admitted answer through merge, checks

Drop the private build plan's citations from the code, and fail verify if one comes backoscabrielbefore adoptiona29cef6

line 3why, one step back
3 * and landing, each a durable step. The class is thin:

Merge build/420-release-downloads: the CLI installs from the platform itself, with no GitHub in the release pathoscabrielbefore adoption878da37

lines 4–11why, one step back
4 * it decodes its params, runs `runAnswer` with its steps over the engine's
5 * `step.do`, and hands the engine the outcome encoded as JSON. The program6 * lives in `answer/program.ts`. The class name is frozen.7 *8 * Every port comes from the Worker's env through `workerPorts`, as the9 * Worker's own ports do. The project's Durable Object is reached as the10 * platform itself: its answer queue (`answer`, `advanceAnswer`) takes no11 * caller.

Plug typed visibility in through neutral ports, so removing the cartridge is a deletionoscabrielbefore adoption9031e57

line 12why, one step back
12 *

Drop the private build plan's citations from the code, and fail verify if one comes backoscabrielbefore adoptiona29cef6

line 13why, one step back
13 * The same Workflow admits a layer push's sealed checks: params

Plug typed visibility in through neutral ports, so removing the cartridge is a deletionoscabrielbefore adoption9031e57

lines 14–15why, one step back
14 * tagged `Admission` run `admissionSteps`, so typed visibility adds no
15 * Workflow binding. An admission's output is `null`.

Merge branch 'build/910-draft-workflow'oscabrielbefore adoptiona0c8f4f

lines 16–17why, one step back
16 *
17 * So does a round of a proposal's draft: params tagged `Draft` run

Close the code browser and drafting wave: its decisions in two ADRs, every rule it added held, and its leftovers folded inoscabrielbefore adoption009640c

line 18why, one step back
18 * `draftSteps` (ADR 0018), over the Worker's ports and the drafter

Merge branch 'build/910-draft-workflow'oscabrielbefore adoptiona0c8f4f

lines 19–20why, one step back
19 * (`draftPorts`), with each step's timeout handed to the engine. A draft's
20 * output is `null` too.

Merge build/420-release-downloads: the CLI installs from the platform itself, with no GitHub in the release pathoscabrielbefore adoption878da37

line 21why, one step back
21 */

Merge branch 'build/910-draft-workflow'oscabrielbefore adoptiona0c8f4f

lines 22–24why, one step back
22import type { RepoHost } from "@repo/artifacts/repo-host";
23import type { Drafter } from "@repo/drafting/drafter";24import type { Projects } from "@repo/project/projects";

Merge build/420-release-downloads: the CLI installs from the platform itself, with no GitHub in the release pathoscabrielbefore adoption878da37

lines 25–29why, one step back
25import { Outcome } from "@repo/protocol/domain/outcome";
26import { WorkflowEntrypoint } from "cloudflare:workers";27import type { WorkflowEvent } from "cloudflare:workers";28import { Effect, Layer, Schema } from "effect";29

Plug typed visibility in through neutral ports, so removing the cartridge is a deletionoscabrielbefore adoption9031e57

line 30why, one step back
30import type { WorkflowParams } from "../answer-runs.ts";

Merge branch 'build/910-draft-workflow'oscabrielbefore adoptiona0c8f4f

line 31why, one step back
31import { AdmissionParams, AnswerParams, DraftParams } from "../answer-runs.ts";

Merge build/420-release-downloads: the CLI installs from the platform itself, with no GitHub in the release pathoscabrielbefore adoption878da37

line 32why, one step back
32import { decodeEnv } from "../platform.ts";

Merge branch 'build/910-draft-workflow'oscabrielbefore adoptiona0c8f4f

line 33why, one step back
33import { draftPorts, workerPorts } from "../ports.ts";

Plug typed visibility in through neutral ports, so removing the cartridge is a deletionoscabrielbefore adoption9031e57

line 34why, one step back
34import { admissionSteps } from "./admission-steps.ts";

Merge build/420-release-downloads: the CLI installs from the platform itself, with no GitHub in the release pathoscabrielbefore adoption878da37

lines 35–36why, one step back
35import { runAnswer } from "./answer/program.ts";
36import type { AnswerPorts } from "./answer/program.ts";

Merge branch 'build/910-draft-workflow'oscabrielbefore adoptiona0c8f4f

lines 37–38why, one step back
37import { draftSteps, timedSteps } from "./draft-steps.ts";
38import type { EngineSteps } from "./draft-steps.ts";

Merge build/420-release-downloads: the CLI installs from the platform itself, with no GitHub in the release pathoscabrielbefore adoption878da37

lines 39–68why, one step back
39import { workflowSteps } from "./step.ts";
40import type { StepRunner, WorkflowSteps } from "./step.ts";4142/** An answer's outcome as the engine keeps it: JSON. */43export const OutcomeJson = Schema.toCodecJson(Outcome);4445export type OutcomeEncoded = typeof OutcomeJson.Encoded;4647/**48 * One run of the Workflow over `ports`: the params decoded (a run that49 * can't decode them fails, and no step runs), the program run with its50 * steps over the engine's, and the outcome encoded.51 */52export const runWorkflow = <E>(53 ports: Layer.Layer<Exclude<AnswerPorts, StepRunner>, E>,54 payload: typeof AnswerParams.Encoded,55 steps: WorkflowSteps56): Promise<OutcomeEncoded> =>57 Effect.runPromise(58 Effect.gen(function* () {59 const params = yield* Schema.decodeEffect(AnswerParams)(payload);60 const outcome = yield* runAnswer(params);6162 return yield* Schema.encodeEffect(OutcomeJson)(outcome);63 }).pipe(64 Effect.provide(Layer.merge(ports, workflowSteps(steps))),65 Effect.orDie66 )67 );68

Plug typed visibility in through neutral ports, so removing the cartridge is a deletionoscabrielbefore adoption9031e57

lines 69–87why, one step back
69/** One admission's run of the Workflow over `ports`, its params decoded as an answer's are. */
70export const runAdmission = <E>(71 ports: Layer.Layer<Exclude<AnswerPorts, StepRunner>, E>,72 payload: typeof AdmissionParams.Encoded,73 steps: WorkflowSteps74): Promise<null> =>75 Effect.runPromise(76 Effect.gen(function* () {77 yield* admissionSteps(78 yield* Schema.decodeEffect(AdmissionParams)(payload)79 );8081 return null;82 }).pipe(83 Effect.provide(Layer.merge(ports, workflowSteps(steps))),84 Effect.orDie85 )86 );87

Merge branch 'build/910-draft-workflow'oscabrielbefore adoptiona0c8f4f

lines 88–107why, one step back
88/**
89 * One draft round's run of the Workflow over `ports`, its params decoded90 * first, each step handed its timeout.91 */92export const runDraftWorkflow = <E>(93 ports: Layer.Layer<Projects | Drafter | RepoHost, E>,94 payload: typeof DraftParams.Encoded,95 steps: EngineSteps96): Promise<null> =>97 Effect.runPromise(98 Effect.gen(function* () {99 yield* draftSteps(yield* Schema.decodeEffect(DraftParams)(payload));100101 return null;102 }).pipe(103 Effect.provide(Layer.merge(ports, workflowSteps(timedSteps(steps)))),104 Effect.orDie105 )106 );107

Plug typed visibility in through neutral ports, so removing the cartridge is a deletionoscabrielbefore adoption9031e57

lines 108–110why, one step back
108/** Whether the engine's params start an admission rather than an answer. */
109const admits = Schema.is(Schema.toEncoded(AdmissionParams));110

Merge branch 'build/910-draft-workflow'oscabrielbefore adoptiona0c8f4f

lines 111–113why, one step back
111/** Whether the engine's params start a draft's round. */
112const drafts = Schema.is(Schema.toEncoded(DraftParams));113

Merge build/420-release-downloads: the CLI installs from the platform itself, with no GitHub in the release pathoscabrielbefore adoption878da37

lines 114–115why, one step back
114export class Answer extends WorkflowEntrypoint<
115 Env,

Plug typed visibility in through neutral ports, so removing the cartridge is a deletionoscabrielbefore adoption9031e57

line 116why, one step back
116 typeof WorkflowParams.Encoded

Merge build/420-release-downloads: the CLI installs from the platform itself, with no GitHub in the release pathoscabrielbefore adoption878da37

lines 117–119why, one step back
117> {
118 /**119 * `step` is the engine's `WorkflowStep`; the run uses only its `do`

Merge branch 'build/910-draft-workflow'oscabrielbefore adoptiona0c8f4f

line 120why, one step back
120 * (`EngineSteps`), so a test can hand it a fake engine.

Merge build/420-release-downloads: the CLI installs from the platform itself, with no GitHub in the release pathoscabrielbefore adoption878da37

lines 121–122why, one step back
121 */
122 override run(

Plug typed visibility in through neutral ports, so removing the cartridge is a deletionoscabrielbefore adoption9031e57

line 123why, one step back
123 event: Readonly<WorkflowEvent<typeof WorkflowParams.Encoded>>,

Merge branch 'build/910-draft-workflow'oscabrielbefore adoptiona0c8f4f

line 124why, one step back
124 step: EngineSteps

Plug typed visibility in through neutral ports, so removing the cartridge is a deletionoscabrielbefore adoption9031e57

line 125why, one step back
125 ): Promise<OutcomeEncoded | null> {

Merge branch 'build/910-draft-workflow'oscabrielbefore adoptiona0c8f4f

line 126why, one step back
126 const config = decodeEnv(this.env);

Plug typed visibility in through neutral ports, so removing the cartridge is a deletionoscabrielbefore adoption9031e57

line 127why, one step back
127 const { payload } = event;

Merge branch 'build/910-draft-workflow'oscabrielbefore adoptiona0c8f4f

lines 128–142why, one step back
128
129 if (drafts(payload)) {130 // The env decoded once: the Worker's ports and the drafter from it.131 return runDraftWorkflow(132 Layer.unwrap(133 Effect.map(config, (decoded) =>134 Layer.merge(workerPorts(decoded), draftPorts(decoded))135 )136 ),137 payload,138 step139 );140 }141142 const ports = Layer.unwrap(Effect.map(config, workerPorts));

Plug typed visibility in through neutral ports, so removing the cartridge is a deletionoscabrielbefore adoption9031e57

lines 143–146why, one step back
143
144 return admits(payload)145 ? runAdmission(ports, payload, step)146 : runWorkflow(ports, payload, step);

Merge build/420-release-downloads: the CLI installs from the platform itself, with no GitHub in the release pathoscabrielbefore adoption878da37

lines 147–148why, one step back
147 }
148}