Merge web/drop-finish-control into main
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by oscabriel · committed by oscabriel · parents 19405f6, f34b38d · Browse files · 8 files·+18 added−368 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+18 added−368 removed
- tests:+7 added−89 removed
- other:+11 added−279 removed
Provenance
- Commit
87cbd15- Tree
938def9- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent 1
19405f6- Parent 2
f34b38d
8 files changed+18 added−368 removed
deleted:apps/web/src/client/finish.ts-33 removed
123456789101112131415161718192021222324252627282930313233import type { Finish } from "@repo/protocol/contracts";import type { Rev } from "@repo/protocol/domain/code";import type { ProjectName } from "@repo/protocol/ids";import { Effect } from "effect";import { Atom, Reactivity } from "effect/reactivity";
import { ContractsClient } from "../surfaces.ts";import { keys } from "./keys.ts";
/** The newest commit on a fork's branch: what a finish would check. Read in the browser only. */export const forkHeadAtom = Atom.family((project: ProjectName) => Atom.family((at: Rev) => Atom.withServerValueInitial( ContractsClient.query( "log", { at, limit: 1, project }, { reactivityKeys: keys.project(project) } ) ) ));
export const finishAtom = ContractsClient.runtime.fn< typeof Finish.payloadSchema.Type>()( Effect.fnUntraced(function* (input) { const client = yield* ContractsClient;
return yield* client("finish", input).pipe( Reactivity.mutation([...keys.today(), ...keys.project(input.project)]) ); }));modified:apps/web/src/features/finish/finish-view.tsx+3 added-167 removed
1-import type { Finish } from "@repo/protocol/contracts";2-import type { AnswerReceipt, Verdict } from "@repo/protocol/domain/answer";1+/** The web never calls `finish` itself: a maintainer finishes from the CLI. */2+import type { Verdict } from "@repo/protocol/domain/answer";3 import type { Ask } from "@repo/protocol/domain/ask";4 import type { ChangedFile } from "@repo/protocol/domain/code";5-import { RequestId } from "@repo/protocol/ids";5 import type { CommitSha } from "@repo/protocol/ids";7-import { Option } from "effect";6 import type { DateTime } from "effect";7 import { ChevronLeft, ChevronRight, FileDiff, RotateCw } from "lucide-react";8 import { useState } from "react";9 import type { ReactNode } from "react";20 unmodified lines30 import type { PatchFile } from "./files.ts";31 import { FinishPlainDiff } from "./finish-plain.tsx";32 import type { LineNote } from "./finish-plain.tsx";33 import { MarkRead } from "./mark-read.tsx";36-import { forkOf } from "./patch.ts";34 import type { FinishDecision } from "./patch.ts";35 import type { MarkedFile } from "./read-marks.ts";36 37 export { patchOf } from "./patch.ts";27 unmodified lines65 </div>66 </FactBlock>67 );68 72-export type FinishInput = typeof Finish.payloadSchema.Type;73-69 export interface FinishViewProps {70 readonly decision: FinishDecision;71 readonly ask?: Ask | undefined;72 readonly verdict?: Verdict | undefined;14 unmodified lines87 readonly draw?: boolean;88 readonly filesButton?: ReactNode;89 readonly stamp?: boolean;90 readonly failure?: ReactNode;96- /** The answer fork's newest commit; undefined while it is read, none when it could not be. */97- readonly forkHead?: Option.Option<CommitSha> | undefined;98- readonly onReadFork?: (() => void) | undefined;99- readonly onFinish?: ((input: FinishInput) => void) | undefined;100- readonly finishing?: boolean;101- readonly finished?: AnswerReceipt | undefined;102- readonly finishFailure?: ReactNode;91 }92 93 const NO_FILES: ReadonlySet<string> = new Set();94 354 unmodified lines449 )}450 </div>451 );452 465-const ForkHeadLine = ({466- answer,467- forkHead,468-}: {469- readonly answer: CommitSha;470- readonly forkHead: Option.Option<CommitSha> | undefined;471-}) => {472- if (forkHead === undefined) {473- return (474- <p className="text-ui text-muted-foreground">475- Reading the fork's head…476- </p>477- );478- }479-480- if (Option.isNone(forkHead)) {481- return (482- <p className="text-ui text-muted-foreground">483- The fork's head could not be read.484- </p>485- );486- }487-488- const head = forkHead.value;489-490- return head === answer ? (491- <p className="text-ui text-muted-foreground" data-fork-head={head}>492- Nothing is on top of the answer yet: the fork's head is still{" "}493- <code className="text-mono font-mono">{shortSha(head)}</code>.494- </p>495- ) : (496- <p className="text-ui" data-fork-head={head}>497- The fork's head is{" "}498- <code className="text-mono font-mono">{shortSha(head)}</code>, on top of499- the answer.500- </p>501- );502-};503-504-/** A head on top of the answer's, with the verdict's base to finish from. */505-export const finishInput = (506- decision: FinishDecision,507- verdict: Verdict | undefined,508- forkHead: Option.Option<CommitSha> | undefined509-): Option.Option<FinishInput> =>510- Option.flatMap(511- Option.filter(512- Option.flatten(Option.fromUndefinedOr(forkHead)),513- (head) => head !== decision.subject.head514- ),515- (head) =>516- Option.map(Option.fromUndefinedOr(verdict), ({ base }) => ({517- ask: decision.subject.ask,518- base,519- head,520- project: decision.project,521- requestId: RequestId.make(`finish-${head}`),522- }))523- );524-525-const FinishItFacts = ({526- decision,527- finishFailure,528- finished,529- finishing = false,530- forkHead,531- onFinish,532- onReadFork,533- verdict,534-}: Pick<535- FinishViewProps,536- | "decision"537- | "finishFailure"538- | "finished"539- | "finishing"540- | "forkHead"541- | "onFinish"542- | "onReadFork"543- | "verdict"544->) => {545- const fork = forkOf(decision);546- const input = finishInput(decision, verdict, forkHead);547-548- return (549- <FactBlock label="Finish it">550- <p className="text-ui">551- To finish it with your own changes, push your commits onto the552- answer's fork, on top of its head, then finish it here. They are553- checked again, and you are credited as Finished-by.554- </p>555- {Option.isSome(fork) ? (556- <p className="text-ui text-muted-foreground">557- The fork:{" "}558- <code className="text-mono text-foreground font-mono [overflow-wrap:anywhere]">559- {fork.value}560- </code>561- </p>562- ) : null}563- <ForkHeadLine answer={decision.subject.head} forkHead={forkHead} />564- <div className="flex flex-wrap items-center gap-2">565- <Button566- data-action="finish"567- disabled={finishing || onFinish === undefined || Option.isNone(input)}568- onClick={() => {569- if (Option.isSome(input)) {570- onFinish?.(input.value);571- }572- }}573- size="sm"574- >575- Finish with these commits576- </Button>577- {onReadFork === undefined ? null : (578- <Button onClick={onReadFork} size="sm" variant="outline">579- <RotateCw aria-hidden="true" strokeWidth={1.75} />580- Read the fork again581- </Button>582- )}583- </div>584- {finished === undefined ? null : (585- <div data-finished={finished.head}>586- <StatusLine587- subject={{588- kind: "answer",589- outcome: finished.outcome,590- project: finished.project,591- }}592- />593- </div>594- )}595- <Failure>{finishFailure}</Failure>596- <p className="text-ui text-muted-foreground">597- To land the answer as it is, accept the decision instead.598- </p>599- </FactBlock>600- );601-};602-453 const FinishFacts = ({454 ask,455 busy,456 decision,2 unmodified lines459 onDecide,460 soon,461 stamp,462 verdict,613- ...finish463 }: Required<464 Pick<465 FinishViewProps,466 "busy" | "decision" | "files" | "now" | "onDecide" | "soon" | "stamp"467 >468 > &620- Pick<621- FinishViewProps,622- | "ask"623- | "finishFailure"624- | "finished"625- | "finishing"626- | "forkHead"627- | "onFinish"628- | "onReadFork"629- | "verdict"630- >) => (469+ Pick<FinishViewProps, "ask" | "verdict">) => (470 <>471 {ask === undefined ? null : <WantFacts ask={ask} />}472 {verdict === undefined ? null : <VerdictFacts verdict={verdict} />}473 {verdict === undefined ? null : (14 unmodified lines488 soon={soon}489 stamp={stamp}490 />491 </FactBlock>653- {decision.decided === undefined ? (654- <FinishItFacts {...finish} decision={decision} verdict={verdict} />655- ) : null}492 {files.length === 0 ? null : (493 <DiffStatsFacts stats={statsOf(files, ask?.territory.paths ?? [])} />494 )}495 </>86 unmodified linesmodified:apps/web/src/features/finish/patch.ts+1 added-20 removed
1234345677 unmodified lines151617182021222324252627282930313233343536371920212290 unmodified linesimport { DecisionSubject } from "@repo/protocol/domain/decision";import type { Decision } from "@repo/protocol/domain/decision";import { Handle } from "@repo/protocol/ids";import { Array as Arr, Option, Schema } from "effect";import { Array as Arr, Option } from "effect";
export const PATCH_LABEL = "patch";
export const FORK_LABEL = "fork";7 unmodified linesexport const isFinishDecision = ( decision: Decision): decision is FinishDecision => finishes(decision.subject);
const evidenceOf = (decision: Decision, label: string) => Arr.findFirst(decision.evidence, (fact) => fact.label === label);
const decodeHandle = Schema.decodeUnknownOption(Handle);
/** The answerer, as the decision's `answer` evidence names them: `<handle> at <head> (<request>)`. */export const answererOf = (decision: FinishDecision): Option.Option<Handle> => Option.flatMap(evidenceOf(decision, "answer"), ({ value }) => decodeHandle(value.split(" at ")[0]) );
/** The answer's fork, as its `fork` evidence names it: a link when it carries one, else the fork's repo. */export const forkOf = (decision: FinishDecision): Option.Option<string> => Option.map( evidenceOf(decision, FORK_LABEL), ({ href, value }) => href ?? value.trim() );
export const patchOf = (decision: Decision): Option.Option<string> => isFinishDecision(decision) ? Option.map( Arr.findFirst(decision.evidence, ({ label }) => label === PATCH_LABEL),90 unmodified linesmodified:apps/web/src/routes/$owner/$project/decisions/$decision.tsx+3 added-56 removed
1-import {2- useAtom,3- useAtomMount,4- useAtomRefresh,5- useAtomValue,6-} from "@effect/atom-react";7-import { forkRev } from "@repo/protocol/domain/code";1+import { useAtom, useAtomMount, useAtomValue } from "@effect/atom-react";2 import type { Decision } from "@repo/protocol/domain/decision";9-import type { CommitSha } from "@repo/protocol/ids";3 import {4 createFileRoute,5 useLocation,6 useRouter,7 } from "@tanstack/react-router";8 import { createServerFn } from "@tanstack/react-start";9 import { getRequest } from "@tanstack/react-start/server";10 import { env } from "cloudflare:workers";18-import { Array as Arr, Effect, Option, Schema } from "effect";11+import { Effect, Option, Schema } from "effect";12 import type { DateTime } from "effect";20-import { Atom, AsyncResult } from "effect/reactivity";13+import { AsyncResult } from "effect/reactivity";14 import { useCallback, useMemo, useState } from "react";15 import type { ReactNode } from "react";16 17 import { decideAtom } from "../../../../client/decide.ts";18 import { projectEventsAtom } from "../../../../client/events.ts";26-import { finishAtom, forkHeadAtom } from "../../../../client/finish.ts";19 import { watchAtom } from "../../../../client/watch.ts";20 import { hereOf } from "../../../../features/auth/session-slot.tsx";21 import { useCodeFileKeys } from "../../../../features/code/file-keys.ts";22 import { parseDiffHash } from "../../../../features/code/line-hash.ts";12 unmodified lines35 import { FinishColumn } from "../../../../features/finish/finish-column.tsx";36 import { FinishFilesButton } from "../../../../features/finish/finish-files-button.tsx";37 import { FinishView } from "../../../../features/finish/finish-view.tsx";38 import {47- answererOf,39 isFinishDecision,40 patchOf,41 waiverPatchOf,42 } from "../../../../features/finish/patch.ts";45 unmodified lines88 taken.decided !== undefined89 )90 );91 101-type ForkLog = AsyncResult.AsyncResult<102- { readonly commits: readonly { readonly sha: CommitSha }[] },103- unknown104->;105-106-// A decision that names no answerer has no fork to read.107-const noFork: Atom.Atom<ForkLog> = Atom.make<ForkLog>(108- AsyncResult.success({ commits: [] })109-);110-111-const forkLogOf = (decision: FinishDecision): Atom.Atom<ForkLog> =>112- Option.match(answererOf(decision), {113- onNone: () => noFork,114- onSome: (handle) =>115- forkHeadAtom(decision.project)(116- forkRev({ ask: decision.subject.ask, handle })117- ),118- });119-120-/** Undefined while it is read; none when the fork could not be read or holds nothing. */121-const headOf = (log: ForkLog): Option.Option<CommitSha> | undefined => {122- if (AsyncResult.isSuccess(log)) {123- return Option.map(Arr.head(log.value.commits), ({ sha }) => sha);124- }125-126- return AsyncResult.isFailure(log) ? Option.none() : undefined;127-};128-92 const Finish = ({93 busy,94 decision,95 failure,10 unmodified lines106 readonly taken: Decision | undefined;107 readonly failure: ReactNode;108 }) => {109 const router = useRouter();147- const here = useLocation({ select: hereOf });110 const { ask, head } = decision.subject;111 150- const forkLog = useMemo(() => forkLogOf(decision), [decision]);151- const forkHead = headOf(useAtomValue(forkLog));152- const readFork = useAtomRefresh(forkLog);153- const [finished, finish] = useAtom(finishAtom);154-112 useAtomMount(watchAtom(decision.project));113 const events = useAtomValue(projectEventsAtom(decision.project));114 115 const newerHead =93 unmodified lines209 draw210 failure={failure}211 files={files}212 filesButton={<FinishFilesButton />}256- finishFailure={257- AsyncResult.isFailure(finished) ? (258- <CallFailure cause={finished.cause} doing="finish it" here={here} />259- ) : undefined260- }261- finished={Option.getOrUndefined(AsyncResult.value(finished))}262- finishing={finished.waiting}213 folded={folded}264- forkHead={forkHead}214 newerHead={newerHead}215 now={now}216 onDecide={onDecide}217 onFold={onFold}218 onFoldAll={(fold) => {219 setFolded(fold ? new Set(paths) : new Set());220 }}272- onFinish={finish}221 onMark={mark}274- onReadFork={readFork}222 onSplit={setChosen}223 placed={found.placed}224 read={read}225 soon={found.soon}75 unmodified linesmodified:apps/web/test/finish.test.tsx+6 added-88 removed
19 unmodified lines20 ProjectName,21 RepoPath,22 TreeSha,23 } from "@repo/protocol/ids";24-import { StaleBase, Weakened } from "@repo/protocol/refusal";25-import { Cause, DateTime, Option } from "effect";24+import { Weakened } from "@repo/protocol/refusal";25+import { DateTime, Option } from "effect";26 import type { ReactElement } from "react";27 import { renderToStaticMarkup } from "react-dom/server";28 29 import type { PlacedRefusal } from "../src/features/finish/annotation.tsx";30 import { patchFiles } from "../src/features/finish/files.ts";31-import {32- finishInput,33- FinishView,34-} from "../src/features/finish/finish-view.tsx";31+import { FinishView } from "../src/features/finish/finish-view.tsx";32 import type {33 FinishDecision,34 FinishViewProps,35 } from "../src/features/finish/finish-view.tsx";36+import { changedFiles, patchOf } from "../src/features/finish/patch.ts";37 import {40- answererOf,41- changedFiles,42- patchOf,43-} from "../src/features/finish/patch.ts";44-import {38 marksKey,39 readMarks,40 writeMark,41 } from "../src/features/finish/read-marks.ts";49-import { CallFailure } from "../src/features/shared/call-failure.tsx";42 43 const ENTITIES: ReadonlyMap<string, string> = new Map([44 ["'", "'"],45 ["&", "&"],230 unmodified lines276 "export const parse = (text: string) => fromIso(text);"277 );278 });279 288- it("gives no command lines to finish it from a clone", () => {280+ it("gives no command lines and no control to finish it: a maintainer finishes from the CLI", () => {281 const markup = markupOf(pageOf(withPatch, { verdict }));282 const text = textOf(pageOf(withPatch, { verdict }));283 284 expect(markup).not.toContain("data-finish-lines");285+ expect(markup).not.toContain('data-action="finish"');286 expect(text).not.toContain("git fetch");287 expect(text).not.toContain(`${Brand.cli} finish`);288 });289 25 unmodified lines315 );316 });317 });318 326-const finishButtonOf = (markup: string) =>327- /<button\b[^>]*data-action="finish"[^>]*>/u.exec(markup)?.[0] ?? "";328-329-const onTop = CommitSha.make("f".repeat(40));330-331-describe("finishing it from the page", () => {332- it("offers no Finish while the fork's head is still the answer's own", () => {333- const element = pageOf(withPatch, {334- forkHead: Option.some(head),335- onFinish: () => {},336- verdict,337- });338-339- expect(finishButtonOf(markupOf(element))).toContain('disabled=""');340- expect(textOf(element)).toContain("Nothing is on top of the answer yet");341- });342-343- it("offers Finish once commits sit on top, and finishes from the verdict's base at the fork's head", () => {344- const markup = markupOf(345- pageOf(withPatch, {346- forkHead: Option.some(onTop),347- onFinish: () => {},348- verdict,349- })350- );351-352- expect(finishButtonOf(markup)).not.toBe("");353- expect(finishButtonOf(markup)).not.toContain('disabled=""');354- expect(finishInput(withPatch, verdict, Option.some(onTop))).toStrictEqual(355- Option.some({356- ask: parseIso,357- base,358- head: onTop,359- project: datekit,360- requestId: `finish-${onTop}`,361- })362- );363- });364-365- it("finishes nothing with no verdict to take the base from, or no fork head", () => {366- expect(finishInput(withPatch, undefined, Option.some(onTop))).toStrictEqual(367- Option.none()368- );369- expect(finishInput(withPatch, verdict, Option.none())).toStrictEqual(370- Option.none()371- );372- });373-374- it("shows a refused finish as the refusal", () => {375- const markup = markupOf(376- pageOf(withPatch, {377- finishFailure: (378- <CallFailure379- cause={Cause.fail(380- new StaleBase({ base, conflicts: [], main: onTop })381- )}382- doing="finish it"383- here="/oscabriel/datekit/decisions/dec-000007"384- />385- ),386- forkHead: Option.some(onTop),387- verdict,388- })389- );390-391- expect(markup).toContain('data-refusal="StaleBase"');392- });393-394- it("reads the answerer from the decision's answer evidence, to find their fork", () => {395- expect(answererOf(withPatch)).toStrictEqual(396- Option.some(Handle.make("ines-v"))397- );398- });399-});400-319 describe("a finish taken on its page", () => {320 it("keeps the choice's record at the diff's foot, where its choices were, and offers them no more", () => {321 const markup = markupOf(322 pageOf({153 unmodified linesmodified:packages/protocol/src/contracts.ts+2 added-1 removed
122 unmodified lines123 decide: SurfaceName.literals,124 [envSchemaTag]: SurfaceName.literals,125 // A log may hold text an agent's transcript should not carry: never MCP.126 evidence: ["rpc", "cli", "web"],127- finish: SurfaceName.literals,127+ // A finish lands a maintainer's commits: the CLI and MCP, as every change does, never the web.128+ finish: ["rpc", "mcp", "cli"],129 fork: ["rpc", "mcp", "cli"],130 frontPage: SurfaceName.literals,131 initProject: ["rpc", "mcp", "cli", "web"],132 land: ["rpc", "mcp", "cli"],1030 unmodified linesmodified:packages/protocol/test/contracts.test.ts+1 added-1 removed
335 unmodified lines336 "RepoBusy",337 "TouchedJudge",338 ],339 flags: "IA",340- on: "RMCW",340+ on: "RMC",341 tag: "finish",342 },343 {344 audience: "decider",278 unmodified linesmodified:DESIGN.md+2 added-2 removed
275 unmodified lines276 277 - Four shells (site, project, docs, focus), each named by its route, with no global rail and no generic right rail. The site, the docs and a focused page are ruled (the rails); a project is full-bleed.278 - A project has one header and eight tabs, and opens on Overview.279 - State is a mark, then a word, then a colour; red belongs to refusals, violet to sealed things, green to what is on main, olive to waiting, blue to checking. In a row the colour is the mark's; the word is ink, except Refused and Landed.280-- A page names no CLI command. What a person does on the web is a control: a maintainer's choices, claiming and releasing an ask, posting in a discussion, reading a failed lane's log, finishing an answer, importing a repo, the theme preference, and signing in or out. A command box shows only the install line and `git clone` (`apps/web/test/no-cli-commands.test.ts`).280+- A page names no CLI command. What a person does on the web is a control: a maintainer's choices, claiming and releasing an ask, posting in a discussion, reading a failed lane's log, importing a repo, the theme preference, and signing in or out. A command box shows only the install line and `git clone` (`apps/web/test/no-cli-commands.test.ts`).281 - Light and dark follow the system setting, or its opposite by the reader's choice on `/settings` (ADR 0042).282 - Motion carries state, never decoration: transitions of 120 to 200 ms, the landing's stamp, and the landing's music box, whose every move is a step of an answer through the gate.283 284 ## Colors232 unmodified lines517 ### Decisions, the inbox and the finish518 519 - **Inbox** (`/inbox`, once Home and Today, which redirect to it with their query kept): the reader's handle and record, how many decisions wait as one sentence for a decider, then sections under sticky headers: the decisions (Due today, Later), every open one, each decided in its row; Your claims, each answer's stage strip under its row; Asks you may take; and what happened lately in the projects the reader decides for (Newcomers to welcome, Landed without a decision). `?project=` narrows it to one project. A personal page: never kept at the edge.520 - **Choices:** one tap each, no confirm. Primary buttons, the default the outline button with "default" beside its name; 36 px in a row from 640 px, 44 px in a two-column grid on a phone. Under each, a 13 px muted consequence line written from what the platform does. After a choice the record replaces the buttons, landed green only for a choice that took effect.521-- **Finish:** the changed files in the tree column with status letters, `+n −m` and a local read mark; the diff with sticky file headers and "Mark read"; the want, verdict, choices, and Finish it: the answer fork's head, read in the browser, and a button that finishes with the commits on top of the answer.521+- **Finish:** the changed files in the tree column with status letters, `+n −m` and a local read mark; the diff with sticky file headers and "Mark read"; the want, verdict and choices. A maintainer who finishes it with commits of their own does so from the CLI; the page has no control for it.522 523 ### Code browser (the Code tab)524 525 - **Code bar:** one row under the project's header, not sticky, wrapping on a narrow screen: Files | History (a segmented control marking the view, nothing on the refs list), the revision picker (a field-bordered button reading "At main", "At v1.2.0" or "At handle/ask", with no branch mark or heading, since a tag and a fork are revisions, not branches; its list reads the refs only when it opens: main, the tags, then "Answers in claim forks", each fork as its ask in mono over its claimant and the claim's state in a word; its field finds a tag or an answer; a fork's entry opens the same page in that fork at its address, `@<handle>/<ask>`, shown as `handle/ask` with the fork mark; no repo is named), the revision's head commit (short SHA and subject linking the commit, then author and age; from 640 px), Go to file (`t`, a dialog over the paths at the revision, a match in the file's own name first) and Clone (a popover: the clone command, and the checkout of a tag or a commit, quoted when it is not one plain word; none for a fork, whose commits come with a claim). Below `columns`, a Files button at its start opens the tree, or a commit's changed files, as a sheet. Its reads are the route's (`routes/$owner/$project/-code-bar.tsx`); the bar itself, in `features/code/`, reads nothing. Inside a fork every link that pins a commit (raw, the permalink, a log row, a commit's parent and files, why one step back) pins it inside the fork, `@<handle>/<ask>:<sha>`, so a fork's page is a permalink.113 unmodified lines