Skip to content
Myr

project-calls.ts

This file

Path

apps/platform/src/project-calls.ts

170 lines · 6.0 KiB · TypeScript

Last changed by

Merge observability into mainoscabrielbefore adoption1985111

History of this file

Take it

The walk stopped after 200 commits: lines older than 678c8b8 point at it.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 1–6why, one step back
1import { envSchemaMethod } from "@repo/project/deciders";
2import { MethodSchemas } from "@repo/project/project";3import type { ProjectApi } from "@repo/project/project";4import { ProjectName } from "@repo/protocol/ids";5import { Person, Principal } from "@repo/protocol/principal";6import { UnknownProject } from "@repo/protocol/refusal";

Merge observability into mainoscabrielbefore adoption1985111

lines 7–8why, one step back
7import { reportedElsewhere } from "@repo/telemetry/defects";
8import { Effect, Exit, Record, Schema } from "effect";

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 9–18why, one step back
9
10export type ProjectMethod = keyof ProjectApi;1112export type ArgsOf<M extends ProjectMethod> = Parameters<ProjectApi[M]>;1314type SchemasOf<M extends ProjectMethod> = (typeof MethodSchemas)[M];1516export type SuccessOf<M extends ProjectMethod> =17 SchemasOf<M>["success"]["Type"];18

Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8

lines 19–20why, one step back
19// A contract method's errors carry `UnknownProject`, which the DO answers itself
20// before `initProject`; the service never does.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 21–31why, one step back
21export type ErrorOf<M extends ProjectMethod> = SchemasOf<M>["error"]["Type"];
2223export interface ProjectCall<M extends ProjectMethod> {24 readonly caller: boolean;25 readonly payload: Schema.Codec<Readonly<ArgsOf<M>>, Schema.Json>;26 readonly success: Schema.Codec<SuccessOf<M>, Schema.Json>;27 readonly error: Schema.Codec<ErrorOf<M>, Schema.Json>;28 readonly exit: Schema.Codec<Exit.Exit<SuccessOf<M>, ErrorOf<M>>, Schema.Json>;29 readonly refusesUnmade: boolean;30}31

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

lines 32–34why, one step back
32const unmade = new UnknownProject({
33 project: ProjectName.make("oscabriel/unmade"),34});

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 35–58why, one step back
35
36const callOf = <37 const Args extends readonly Schema.Top[],38 Success extends Schema.Top,39 Error extends Schema.Top,40>(schemas: {41 readonly args: Args;42 readonly success: Success;43 readonly error: Error;44}) => ({45 caller: schemas.args[0] === Person || schemas.args[0] === Principal,46 error: Schema.toCodecJson(schemas.error),47 exit: Schema.toCodecJson(48 Schema.Exit(schemas.success, schemas.error, Schema.Defect())49 ),50 payload: Schema.toCodecJson(Schema.Tuple(schemas.args)),51 refusesUnmade: Schema.is(Schema.toType(schemas.error))(unmade),52 success: Schema.toCodecJson(schemas.success),53});5455export type ProjectCallTable = {56 readonly [M in ProjectMethod]: ProjectCall<M>;57};58

Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8

lines 59–61why, one step back
59// Typed by method name so a generic `M` reads `ProjectCalls[method]` as
60// `ProjectCall<M>`; `satisfies` would keep the literal type, which a generic index61// cannot read.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 62–71why, one step back
62const byMethod = (rows: ProjectCallTable) => rows;
6364export const ProjectCalls = byMethod({65 admissionPlan: callOf(MethodSchemas.admissionPlan),66 advanceAnswer: callOf(MethodSchemas.advanceAnswer),67 answer: callOf(MethodSchemas.answer),68 claim: callOf(MethodSchemas.claim),69 credits: callOf(MethodSchemas.credits),70 [envSchemaMethod]: callOf(MethodSchemas[envSchemaMethod]),71 decide: callOf(MethodSchemas.decide),

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

line 72why, one step back
72 draftAsk: callOf(MethodSchemas.draftAsk),

Merge branch 'build/909-draft-rehearsal-and-settling'oscabrielbefore adoption9e6b61c

lines 73–74why, one step back
73 draftContext: callOf(MethodSchemas.draftContext),
74 draftSettled: callOf(MethodSchemas.draftSettled),

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 75–80why, one step back
75 events: callOf(MethodSchemas.events),
76 evidence: callOf(MethodSchemas.evidence),77 finish: callOf(MethodSchemas.finish),78 firstPusher: callOf(MethodSchemas.firstPusher),79 flagAsk: callOf(MethodSchemas.flagAsk),80 fork: callOf(MethodSchemas.fork),

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 81–82why, one step back
81 forks: callOf(MethodSchemas.forks),
82 head: callOf(MethodSchemas.head),

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 83–86why, one step back
83 heldBackJob: callOf(MethodSchemas.heldBackJob),
84 initProject: callOf(MethodSchemas.initProject),85 land: callOf(MethodSchemas.land),86 landing: callOf(MethodSchemas.landing),

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 87why, one step back
87 landingCount: callOf(MethodSchemas.landingCount),

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

line 88why, one step back
88 landings: callOf(MethodSchemas.landings),

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 89–94why, one step back
89 layerAccess: callOf(MethodSchemas.layerAccess),
90 layerFacts: callOf(MethodSchemas.layerFacts),91 ledger: callOf(MethodSchemas.ledger),92 listAsks: callOf(MethodSchemas.listAsks),93 onAlarm: callOf(MethodSchemas.onAlarm),94 openAsk: callOf(MethodSchemas.openAsk),

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

line 95why, one step back
95 policy: callOf(MethodSchemas.policy),

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 96–102why, one step back
96 proposeAsk: callOf(MethodSchemas.proposeAsk),
97 recordAdmission: callOf(MethodSchemas.recordAdmission),98 recordFirstPush: callOf(MethodSchemas.recordFirstPush),99 recordHeldBack: callOf(MethodSchemas.recordHeldBack),100 recordLayerPush: callOf(MethodSchemas.recordLayerPush),101 recordLayerRead: callOf(MethodSchemas.recordLayerRead),102 recordPush: callOf(MethodSchemas.recordPush),

Merge branch 'build/909-draft-rehearsal-and-settling'oscabrielbefore adoption9e6b61c

line 103why, one step back
103 rehearseOpen: callOf(MethodSchemas.rehearseOpen),

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 104–107why, one step back
104 release: callOf(MethodSchemas.release),
105 scanForValues: callOf(MethodSchemas.scanForValues),106 setEnv: callOf(MethodSchemas.setEnv),107 showAsk: callOf(MethodSchemas.showAsk),

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

line 108why, one step back
108 showProposal: callOf(MethodSchemas.showProposal),

Merge build/1213-platform-performance-and-agent-surfacesoscabrielbefore adoption1d75a0d

line 109why, one step back
109 standing: callOf(MethodSchemas.standing),

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 110–162why, one step back
110 status: callOf(MethodSchemas.status),
111 submitAnswer: callOf(MethodSchemas.submitAnswer),112 today: callOf(MethodSchemas.today),113 verdict: callOf(MethodSchemas.verdict),114 vouch: callOf(MethodSchemas.vouch),115});116117export const projectMethods = Record.keys(ProjectCalls);118119export const CallRequest = Schema.Struct({120 caller: Schema.optionalKey(Principal),121 method: Schema.Literals(projectMethods),122 payload: Schema.Array(Schema.Json),123});124125export type CallRequest = typeof CallRequest.Type;126127export type ExitEncoded = Schema.Json;128129const JsonTuple = Schema.Array(Schema.Json);130131const EncodedPrincipal = Schema.toEncoded(Principal);132133export const encodeCall = <M extends ProjectMethod>(134 method: M,135 args: ArgsOf<M>136): Effect.Effect<typeof CallRequest.Encoded> =>137 Effect.gen(function* () {138 const call = ProjectCalls[method];139140 const encoded = yield* Schema.decodeUnknownEffect(JsonTuple)(141 yield* Schema.encodeUnknownEffect(call.payload)(args)142 );143144 if (!call.caller) {145 return { method, payload: encoded };146 }147148 const [first, ...rest] = encoded;149150 return {151 caller: yield* Schema.decodeUnknownEffect(EncodedPrincipal)(first),152 method,153 payload: rest,154 };155 }).pipe(Effect.orDie);156157export const decodeReply = <M extends ProjectMethod>(158 method: M,159 reply: ExitEncoded160): Effect.Effect<SuccessOf<M>, ErrorOf<M>> =>161 Schema.decodeEffect(ProjectCalls[method].exit)(reply).pipe(162 Effect.orDie,

Merge observability into mainoscabrielbefore adoption1985111

lines 163–169why, one step back
163 // The Project DO reported its defects, with their stacks, before it replied.
164 Effect.flatMap(165 Exit.match({166 onFailure: (cause) => Effect.failCause(reportedElsewhere(cause)),167 onSuccess: Effect.succeed,168 })169 )

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

line 170why, one step back
170 );