Skip to content
Myr

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

8 files+18 added−368 removed

deleted:apps/web/src/client/finish.ts-33 removed
modified:apps/web/src/features/finish/finish-view.tsx+3 added-167 removed
1import type { Finish } from "@repo/protocol/contracts";2import type { AnswerReceipt, Verdict } from "@repo/protocol/domain/answer";1/** The web never calls `finish` itself: a maintainer finishes from the CLI. */2import type { Verdict } from "@repo/protocol/domain/answer";3import type { Ask } from "@repo/protocol/domain/ask";4import type { ChangedFile } from "@repo/protocol/domain/code";5import { RequestId } from "@repo/protocol/ids";5import type { CommitSha } from "@repo/protocol/ids";7import { Option } from "effect";6import type { DateTime } from "effect";7import { ChevronLeft, ChevronRight, FileDiff, RotateCw } from "lucide-react";8import { useState } from "react";9import type { ReactNode } from "react";
20 unmodified lines
30import type { PatchFile } from "./files.ts";31import { FinishPlainDiff } from "./finish-plain.tsx";32import type { LineNote } from "./finish-plain.tsx";33import { MarkRead } from "./mark-read.tsx";36import { forkOf } from "./patch.ts";34import type { FinishDecision } from "./patch.ts";35import type { MarkedFile } from "./read-marks.ts";3637export { patchOf } from "./patch.ts";
27 unmodified lines
65 </div>66 </FactBlock>67);6872export type FinishInput = typeof Finish.payloadSchema.Type;7369export interface FinishViewProps {70 readonly decision: FinishDecision;71 readonly ask?: Ask | undefined;72 readonly verdict?: Verdict | undefined;
14 unmodified lines
87 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}9293const NO_FILES: ReadonlySet<string> = new Set();94
354 unmodified lines
449 )}450 </div>451);452465const 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&apos;s head…476 </p>477 );478 }479480 if (Option.isNone(forkHead)) {481 return (482 <p className="text-ui text-muted-foreground">483 The fork&apos;s head could not be read.484 </p>485 );486 }487488 const head = forkHead.value;489490 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&apos;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&apos;s head is{" "}498 <code className="text-mono font-mono">{shortSha(head)}</code>, on top of499 the answer.500 </p>501 );502};503504/** A head on top of the answer's, with the verdict's base to finish from. */505export 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 );524525const 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);547548 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&apos;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};602453const FinishFacts = ({454 ask,455 busy,456 decision,
2 unmodified lines
459 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 lines
488 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 lines
modified:apps/web/src/features/finish/patch.ts+1 added-20 removed
modified:apps/web/src/routes/$owner/$project/decisions/$decision.tsx+3 added-56 removed
1import {2 useAtom,3 useAtomMount,4 useAtomRefresh,5 useAtomValue,6} from "@effect/atom-react";7import { forkRev } from "@repo/protocol/domain/code";1import { useAtom, useAtomMount, useAtomValue } from "@effect/atom-react";2import type { Decision } from "@repo/protocol/domain/decision";9import type { CommitSha } from "@repo/protocol/ids";3import {4 createFileRoute,5 useLocation,6 useRouter,7} from "@tanstack/react-router";8import { createServerFn } from "@tanstack/react-start";9import { getRequest } from "@tanstack/react-start/server";10import { env } from "cloudflare:workers";18import { Array as Arr, Effect, Option, Schema } from "effect";11import { Effect, Option, Schema } from "effect";12import type { DateTime } from "effect";20import { Atom, AsyncResult } from "effect/reactivity";13import { AsyncResult } from "effect/reactivity";14import { useCallback, useMemo, useState } from "react";15import type { ReactNode } from "react";1617import { decideAtom } from "../../../../client/decide.ts";18import { projectEventsAtom } from "../../../../client/events.ts";26import { finishAtom, forkHeadAtom } from "../../../../client/finish.ts";19import { watchAtom } from "../../../../client/watch.ts";20import { hereOf } from "../../../../features/auth/session-slot.tsx";21import { useCodeFileKeys } from "../../../../features/code/file-keys.ts";22import { parseDiffHash } from "../../../../features/code/line-hash.ts";
12 unmodified lines
35import { FinishColumn } from "../../../../features/finish/finish-column.tsx";36import { FinishFilesButton } from "../../../../features/finish/finish-files-button.tsx";37import { FinishView } from "../../../../features/finish/finish-view.tsx";38import {47 answererOf,39 isFinishDecision,40 patchOf,41 waiverPatchOf,42} from "../../../../features/finish/patch.ts";
45 unmodified lines
88 taken.decided !== undefined89 )90 );91101type ForkLog = AsyncResult.AsyncResult<102 { readonly commits: readonly { readonly sha: CommitSha }[] },103 unknown104>;105106// A decision that names no answerer has no fork to read.107const noFork: Atom.Atom<ForkLog> = Atom.make<ForkLog>(108 AsyncResult.success({ commits: [] })109);110111const 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 });119120/** Undefined while it is read; none when the fork could not be read or holds nothing. */121const headOf = (log: ForkLog): Option.Option<CommitSha> | undefined => {122 if (AsyncResult.isSuccess(log)) {123 return Option.map(Arr.head(log.value.commits), ({ sha }) => sha);124 }125126 return AsyncResult.isFailure(log) ? Option.none() : undefined;127};12892const Finish = ({93 busy,94 decision,95 failure,
10 unmodified lines
106 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;111150 const forkLog = useMemo(() => forkLogOf(decision), [decision]);151 const forkHead = headOf(useAtomValue(forkLog));152 const readFork = useAtomRefresh(forkLog);153 const [finished, finish] = useAtom(finishAtom);154112 useAtomMount(watchAtom(decision.project));113 const events = useAtomValue(projectEventsAtom(decision.project));114115 const newerHead =
93 unmodified lines
209 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 lines
modified:apps/web/test/finish.test.tsx+6 added-88 removed
19 unmodified lines
20 ProjectName,21 RepoPath,22 TreeSha,23} from "@repo/protocol/ids";24import { StaleBase, Weakened } from "@repo/protocol/refusal";25import { Cause, DateTime, Option } from "effect";24import { Weakened } from "@repo/protocol/refusal";25import { DateTime, Option } from "effect";26import type { ReactElement } from "react";27import { renderToStaticMarkup } from "react-dom/server";2829import type { PlacedRefusal } from "../src/features/finish/annotation.tsx";30import { patchFiles } from "../src/features/finish/files.ts";31import {32 finishInput,33 FinishView,34} from "../src/features/finish/finish-view.tsx";31import { FinishView } from "../src/features/finish/finish-view.tsx";32import type {33 FinishDecision,34 FinishViewProps,35} from "../src/features/finish/finish-view.tsx";36import { changedFiles, patchOf } from "../src/features/finish/patch.ts";37import {40 answererOf,41 changedFiles,42 patchOf,43} from "../src/features/finish/patch.ts";44import {38 marksKey,39 readMarks,40 writeMark,41} from "../src/features/finish/read-marks.ts";49import { CallFailure } from "../src/features/shared/call-failure.tsx";4243const ENTITIES: ReadonlyMap<string, string> = new Map([44 ["&#x27;", "'"],45 ["&amp;", "&"],
230 unmodified lines
276 "export const parse = (text: string) => fromIso(text);"277 );278 });279288 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 }));283284 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 lines
315 );316 });317});318326const finishButtonOf = (markup: string) =>327 /<button\b[^>]*data-action="finish"[^>]*>/u.exec(markup)?.[0] ?? "";328329const onTop = CommitSha.make("f".repeat(40));330331describe("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 });338339 expect(finishButtonOf(markupOf(element))).toContain('disabled=""');340 expect(textOf(element)).toContain("Nothing is on top of the answer yet");341 });342343 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 );351352 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 });364365 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 });373374 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 );390391 expect(markup).toContain('data-refusal="StaleBase"');392 });393394 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});400319describe("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 lines
modified:packages/protocol/src/contracts.ts+2 added-1 removed
122 unmodified lines
123 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 lines
modified:packages/protocol/test/contracts.test.ts+1 added-1 removed
335 unmodified lines
336 "RepoBusy",337 "TouchedJudge",338 ],339 flags: "IA",340 on: "RMCW",340 on: "RMC",341 tag: "finish",342 },343 {344 audience: "decider",
278 unmodified lines
modified:DESIGN.md+2 added-2 removed
275 unmodified lines
276277- 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.283284## Colors
232 unmodified lines
517### Decisions, the inbox and the finish518519- **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.522523### Code browser (the Code tab)524525- **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