Skip to content
Myr

facts.ts

This file

Path

apps/cli/src/hook/facts.ts

141 lines · 4.0 KiB · TypeScript

Last changed by

Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f

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–21why, one step back
1import { Brand } from "@repo/brand";
2import { Client } from "@repo/protocol/contracts";3import type { ClaimView } from "@repo/protocol/domain/claim";4import { Cause, Duration, Effect, Option, Result, Schema } from "effect";5import type { ChildProcessSpawner } from "effect/process";67import { repoContext } from "../repo-context.ts";8import type { RepoRef } from "../repo-context.ts";9import type { HookClaim } from "./decide.ts";10import { askJudge, judgeAt } from "./judge.ts";11import type { SessionState } from "./session.ts";1213const NO_JUDGE: SessionState["judge"] = { paths: [], pointers: [] };1415const without = (root: string, why: string): SessionState => ({16 holds: 0,17 judge: NO_JUDGE,18 root,19 why,20});21

Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f

line 22why, one step back
22/** A hook the harness kills for its time also lets the agent go on, but only after the harness's own limit, every turn. */

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 23–48why, one step back
23const PLATFORM_LIMIT = Duration.seconds(10);
2425class PlatformSilent extends Schema.TaggedError<PlatformSilent>()(26 "PlatformSilent",27 { limit: Schema.String }28) {29 override get message() {30 return `the platform did not answer within ${this.limit}`;31 }32}3334const inTime = <A, E, R>(call: Effect.Effect<A, E, R>) =>35 Effect.timeoutOrElse(call, {36 duration: PLATFORM_LIMIT,37 orElse: () =>38 Effect.fail(39 new PlatformSilent({ limit: Duration.format(PLATFORM_LIMIT) })40 ),41 });4243const firstLine = (cause: Cause.Cause<unknown>) =>44 String(Cause.squash(cause)).split("\n")[0] ?? "unknown failure";4546const isLive = (claim: ClaimView) =>47 claim.state === "live" || claim.state === "warned";48

Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f

line 49why, one step back
49/** In the project's own repo or a working fork, the caller's only live claim: an answer may be made in a clone of main. */

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 50–125why, one step back
50const claimFor = (
51 ref: RepoRef,52 claims: readonly ClaimView[]53): Result.Result<ClaimView, string> => {54 const live = claims.filter(55 (claim) => isLive(claim) && claim.project === ref.project56 );5758 if (ref.kind === "claim") {59 return Result.fromOption(60 Option.fromUndefinedOr(live.find((claim) => claim.ask === ref.ask)),61 () =>62 `you hold no live claim on ${ref.ask}; ${Brand.cli} claim ${ref.ask} takes it`63 );64 }6566 const [only, ...others] = live;6768 if (ref.kind === "layer" || only === undefined) {69 return Result.fail(70 `you hold no live claim in ${ref.project}; ${Brand.cli} asks lists the open asks`71 );72 }7374 return others.length === 075 ? Result.succeed(only)76 : Result.fail(77 `you hold ${live.length} live claims in ${ref.project}, and this repo's remote names none of them`78 );79};8081export const gatherFacts = (82 cwd: string83): Effect.Effect<84 SessionState,85 never,86 Client | ChildProcessSpawner.ChildProcessSpawner87> =>88 Effect.gen(function* () {89 const context = yield* Effect.option(repoContext(cwd));9091 if (Option.isNone(context)) {92 return without(cwd, `${cwd} is not inside a git repo`);93 }9495 const { repo, root } = context.value;9697 if (Option.isNone(repo)) {98 return without(root, "this repo's remote is none of the platform's");99 }100101 const ref = repo.value;102 const client = yield* Client;103104 return yield* Effect.gen(function* () {105 const { claims } = yield* inTime(client.status({ project: ref.project }));106107 const picked = claimFor(ref, claims);108109 if (Result.isFailure(picked)) {110 return without(root, picked.failure);111 }112113 const live = picked.success;114115 const shown = yield* inTime(116 client.showAsk({ ask: live.ask, project: live.project })117 );118119 const judge = askJudge(120 yield* judgeAt({ base: live.base, root, test: live.checkCommand }),121 shown.ask122 );123124 const claim: HookClaim = {125 ask: live.ask,

Close W7: cross-compile the release again, guard pi's edits, and keep the swarm out of this checkoutoscabrielbefore adoption842f042

line 126why, one step back
126 base: live.base,

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 127–141why, one step back
127 checkCommand: live.checkCommand,
128 project: live.project,129 territory: shown.ask.territory,130 want: shown.ask.brief.want,131 };132133 return { claim, holds: 0, judge, root } satisfies SessionState;134 }).pipe(135 Effect.catchCause((cause) =>136 Effect.succeed(137 without(root, `could not read the claim: ${firstLine(cause)}`)138 )139 )140 );141 });