Public: anyone can read this; the crew can change it.
Talk says what the access wall asks, and the person answers it there: Allow it or Send it back #16393
Check · Review · Land · Live done — Landed and live in production.
talk/wall-says → main 0 commits 4 threads · 4 unresolved
38 files
changed +839
−105
docs/features/talk-wall.md added +14
| @@ -0,0 +1,14 @@ | ||
| 1 | --- | |
| 2 | topic: Ship and undo | |
| 3 | row: Answer the access wall from Talk or the terminal: Allow it, or Send it back | |
| 4 | --- | |
| 5 | # Answer the access wall where you are | |
| 6 | ||
| 7 | When a pull would let more people in than before (anyone signed out reading an app's records, say), the access wall holds it for a person, whoever approved it. Talk now says so where you are, in the wall's own words, and you answer there. | |
| 8 | ||
| 9 | - **The receipt in Talk**: the line under it reads "The crew pushed #2. The access wall holds it for you to decide: anyone signed out could read counter records; …", with two buttons, **Allow it** and **Send it back**. Each is its own form posting to `/talk/wall` (same origin only, no script needed). Someone who reads the repository but may not write it sees the reason and no buttons. | |
| 10 | - **Talk's agent**: asked, it puts the decision to you with `wall { repo, number, answer: "allow" | "send_back", why? }`, always as a confirm whose sentence is the wall's own words, read from the forge: "Allow it and merge pull #2 in owner/counter: anyone signed out could read counter records; …". A pull you may not read is never named in it. An agent can never answer. | |
| 11 | - **The terminal**: on the conversation's screen, the receipt's line carries `A: allow it · S: send it back` and the pull's page; `A` and `S` answer after a confirm. | |
| 12 | - **What an answer does**: Allow it is the pull page's Merge (a merge commit, as its button does); Send it back is the page's request for changes, with the wall's words as the reason unless you give one. Every door goes through `answerWall` (`src/actions/pulls.ts`), so who may merge, the checks and a draft hold the same everywhere. | |
| 13 | ||
| 14 | Proof: `test/talk-wall-says.test.ts`. |
src/actions/merge_words.ts added +86
| @@ -0,0 +1,86 @@ | ||
| 1 | /** | |
| 2 | * What a merge, an origin write and an answer to the access wall say when they are refused, in the | |
| 3 | * words the pull page uses: one place every door imports (the page, the MCP tools, the terminal), | |
| 4 | * so none says it its own way. The plain refusals they name are `pull_words.ts`'s. | |
| 5 | */ | |
| 6 | ||
| 7 | import type { AccessError } from "./access.ts"; | |
| 8 | import { MIRRORED_DO_IT_THERE } from "./mirror_words.ts"; | |
| 9 | import { CHECK_STALE_REFUSAL } from "../checks/stale.ts"; | |
| 10 | import { DRAFT_REFUSAL, type MergePullError } from "../core/pulls.ts"; | |
| 11 | import { teamHoldRefusal } from "../core/teams_words.ts"; | |
| 12 | import { guardedRefusal } from "../crew/stranger.ts"; | |
| 13 | import { NO_WRITE_ACCESS, PULL_GONE } from "./pull_words.ts"; | |
| 14 | ||
| 15 | /** | |
| 16 | * The four ways a write can fail *because of the origin*, in words. | |
| 17 | * | |
| 18 | * They are worth their own sentences: three of them mean nothing changed | |
| 19 | * anywhere and the fourth means the change belongs on another forge, and a | |
| 20 | * generic "that could not be saved" would hide which. Returns undefined for | |
| 21 | * anything that is not an origin outcome, so callers keep their own wording. | |
| 22 | */ | |
| 23 | export function originError(error: string): string | undefined { | |
| 24 | const words: Record<string, string> = { | |
| 25 | mirrored: MIRRORED_DO_IT_THERE, | |
| 26 | origin_owner_only: | |
| 27 | "Only the person who connected this origin can write through it. Your comment would otherwise appear upstream under their name.", | |
| 28 | origin_refused: "The origin refused that. Nothing was changed here either.", | |
| 29 | origin_protected: | |
| 30 | "The operator protects this repository at its origin, so nothing is pushed to it from here. Propose the change from your fork.", | |
| 31 | origin_paused: | |
| 32 | "This connection is not verified yet, so writes through it are paused. Nothing was changed. Check it again under Settings → Connected accounts.", | |
| 33 | origin_unreachable: "The origin could not be reached. Nothing was changed.", | |
| 34 | }; | |
| 35 | return words[error]; | |
| 36 | } | |
| 37 | ||
| 38 | /** | |
| 39 | * Why a merge did not land, in words. The action's error is either an access | |
| 40 | * or lifecycle code, or git's own structured `MergeError` — both are answers | |
| 41 | * the person pressing the button deserves to see. | |
| 42 | */ | |
| 43 | export function mergeFailure(error: AccessError | MergePullError): string { | |
| 44 | if (typeof error !== "string") { | |
| 45 | if (error.kind === "conflict") | |
| 46 | return `The branches conflict in ${error.files.length} file${error.files.length === 1 ? "" : "s"} — merge the base branch in and push again.`; | |
| 47 | if (error.kind === "base_moved") | |
| 48 | return "The base branch moved while merging. Try again."; | |
| 49 | if (error.kind === "ref_locked") | |
| 50 | return "The base branch is locked by another git operation. Try again in a moment."; | |
| 51 | if (error.kind === "unsafe") return "That merge was refused as unsafe."; | |
| 52 | if (error.kind === "guarded") return guardedRefusal(error.paths); | |
| 53 | if (error.kind === "team_review_required") | |
| 54 | return teamHoldRefusal(error.teams); | |
| 55 | return "Git refused the merge."; | |
| 56 | } | |
| 57 | const fromOrigin = originError(error); | |
| 58 | if (fromOrigin !== undefined) return fromOrigin; | |
| 59 | if (error === "already_merged") | |
| 60 | return "This pull request was already merged."; | |
| 61 | if (error === "closed") | |
| 62 | return "A closed pull request cannot be merged. Reopen it first."; | |
| 63 | if (error === "head_moved") | |
| 64 | return "The pull's head moved while it was being checked. Nothing was merged; look again and retry."; | |
| 65 | // The gate races: the page was rendered with an approval that a push | |
| 66 | // dismissed a second later, or a reviewer asked for changes in between. | |
| 67 | if (error === "review_required") | |
| 68 | return "This pull request needs an approving review of its current head, and does not have one. Nothing was merged."; | |
| 69 | if (error === "check_stale") return CHECK_STALE_REFUSAL; | |
| 70 | if (error === "draft") return DRAFT_REFUSAL; | |
| 71 | if (error === "checks_required") | |
| 72 | return "This pull request needs a passing deploy of its current head, and does not have one yet. Nothing was merged."; | |
| 73 | if (error === "forbidden" || error === "unauthorized") | |
| 74 | return NO_WRITE_ACCESS; | |
| 75 | return PULL_GONE; | |
| 76 | } | |
| 77 | ||
| 78 | /** | |
| 79 | * Why an answer to the access wall did not go through (`answerWall`), in the words of the page's | |
| 80 | * own merge or request for changes; its two own refusals said here. | |
| 81 | */ | |
| 82 | export function wallFailure(error: string | { readonly kind: string }): string { | |
| 83 | if (error === "no_wall") return "The access wall holds nothing on that pull's head now: there is nothing to answer."; | |
| 84 | if (error === "self_review") return "You opened this pull: someone else sends it back."; | |
| 85 | return mergeFailure(error as AccessError | MergePullError); | |
| 86 | } |
src/actions/pulls.ts +35
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | * issues — a pull is an issue with a diff. |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | import { wallWords } from "../flow/wall_wait.ts"; | |
| 7 | 8 | import { confessesUnread } from "./review_unread.ts"; |
| 8 | 9 | import { confessesUnseen } from "./review_unseen.ts"; |
| 9 | 10 | import { recombine } from "../core/recombine.ts"; |
| @@ -1210,3 +1211,37 @@ export function readyStranded(app: App): number { | ||
| 1210 | 1211 | } |
| 1211 | 1212 | return readied; |
| 1212 | 1213 | } |
| 1214 | ||
| 1215 | /** | |
| 1216 | * What the access wall asks of `pull` now, in plain words; null when it holds nothing on its head. | |
| 1217 | */ | |
| 1218 | export function wallHolds(app: App, pull: Pull): string[] | null { | |
| 1219 | const now = getPull(app.db, pull.repoId, pull.number) ?? pull; | |
| 1220 | return wallWords(app.db, now.id, now.headOid); | |
| 1221 | } | |
| 1222 | ||
| 1223 | /** | |
| 1224 | * A person's answer to the access wall (#7847): allow it, which is the pull page's merge, or send | |
| 1225 | * it back, which is its request for changes. One implementation for every door that offers the | |
| 1226 | * question (the page's card, Talk's held confirm, the terminal); each answer is the page's own | |
| 1227 | * action, so its gates (who may merge, the checks, the draft) stand as they do there. | |
| 1228 | */ | |
| 1229 | export async function answerWall( | |
| 1230 | app: App, | |
| 1231 | actor: User | undefined, | |
| 1232 | repo: Repo, | |
| 1233 | pull: Pull, | |
| 1234 | answer: "allow" | "send_back", | |
| 1235 | why = "", | |
| 1236 | ): Promise<Result<"merged" | "sent_back", AccessError | MergePullError | SubmitReviewActionError | "no_wall">> { | |
| 1237 | const words = wallHolds(app, pull); | |
| 1238 | if (words === null) return err("no_wall"); | |
| 1239 | if (answer === "allow") { | |
| 1240 | // The page's Merge button's own method: a merge commit (`landingKind` keeps a kept fork's). | |
| 1241 | const merged = await mergePull(app, actor, repo, pull, "merge"); | |
| 1242 | return merged.ok ? ok("merged") : merged; | |
| 1243 | } | |
| 1244 | const said = why.trim() === "" ? `Sent back at the access wall: ${words.join("; ")}.` : why.trim(); | |
| 1245 | const sent = await submitReview(app, actor, repo, pull, { state: "changes_requested", body: said }); | |
| 1246 | return sent.ok ? ok("sent_back") : sent; | |
| 1247 | } |
src/core/talk_work.ts +33 −3
| @@ -10,7 +10,7 @@ | ||
| 10 | 10 | import type { Database } from "bun:sqlite"; |
| 11 | 11 | import { getIssue, type Issue } from "./issues.ts"; |
| 12 | 12 | import { listTurns } from "./conversations.ts"; |
| 13 | import { canAdmin, canRead, getRepo, getRepoById, type Repo } from "./repos.ts"; | |
| 13 | import { canAdmin, canRead, canWrite, getRepo, getRepoById, type Repo } from "./repos.ts"; | |
| 14 | 14 | import { mayView } from "./sealed.ts"; |
| 15 | 15 | import { getUserById, type User } from "./users.ts"; |
| 16 | 16 | import { getPull } from "./pulls.ts"; |
| @@ -19,6 +19,7 @@ import { reviewSummary } from "./reviews.ts"; | ||
| 19 | 19 | import { checkSummary } from "./runs.ts"; |
| 20 | 20 | import { callState } from "./talk_steps.ts"; |
| 21 | 21 | import { readRunLogTail } from "../runs/log.ts"; |
| 22 | import { wallWords } from "../flow/wall_wait.ts"; | |
| 22 | 23 | |
| 23 | 24 | /** The part of a turn the reading needs: its role and its stored text. */ |
| 24 | 25 | export type Said = { readonly role: string; readonly text: string }; |
| @@ -88,7 +89,7 @@ const PREFIX = /^mcp__[a-z0-9-]+__/; | ||
| 88 | 89 | /** Tools that read one issue or pull: the line says "opened". */ |
| 89 | 90 | const OPENS = new Set(["issue", "pull"]); |
| 90 | 91 | /** Tools that change one issue or pull by `repo` and `number` (`writes: true`, held by a test): the line says "changed". */ |
| 91 | export const CHANGES = new Set(["assign", "close", "edit", "issue_teams", "keep_plan", "labels", "land_past_gate", "merge", "review", "say", "seal", "take_back", "threads", "variant"]); | |
| 92 | export const CHANGES = new Set(["assign", "close", "edit", "issue_teams", "keep_plan", "labels", "land_past_gate", "merge", "review", "say", "seal", "take_back", "threads", "variant", "wall"]); | |
| 92 | 93 | /** Tools that act on a pull; the rest of the number tools name an issue unless the forge says otherwise. */ |
| 93 | 94 | const PULL_TOOLS = new Set(["pull", "merge", "review", "land_past_gate"]); |
| 94 | 95 | const APPS = new Set(["new_app", "app_deploy", "make_it_yours", "fork", "variant"]); |
| @@ -329,6 +330,12 @@ export interface WorkLine { | ||
| 329 | 330 | readonly says: string; |
| 330 | 331 | /** The exact control that changes what the run waits on, and its words; absent when none does, or the reader may not. */ |
| 331 | 332 | readonly change?: { readonly href: string; readonly words: string }; |
| 333 | /** | |
| 334 | * The pull the access wall holds, for a reader who may answer it (`answerWall`): each door draws | |
| 335 | * its two answers, "Allow it" and "Send it back"; absent when nothing asks, or the reader may | |
| 336 | * not. | |
| 337 | */ | |
| 338 | readonly wall?: { readonly repo: string; readonly number: number }; | |
| 332 | 339 | } |
| 333 | 340 | |
| 334 | 341 | /** The prefix every hold is logged with (`crew/dispatch.ts`, `crew/week_hold.ts`, `crew/bet_cap.ts`, `checks/scheduler.ts`). */ |
| @@ -446,7 +453,30 @@ export const issueHold = (db: Database, dataDir: string, issue: Issue, reader: U | ||
| 446 | 453 | export function workLineFor(db: Database, dataDir: string, issue: Issue, now: number, reader: User | undefined): WorkLine { |
| 447 | 454 | const run = issue.state === "closed" ? null : lastRun(db, issue); |
| 448 | 455 | const hold = run?.state === "queued" ? holdNow(db, dataDir, run.id) : undefined; |
| 449 | return hold === undefined ? { says: workLine(db, issue, now) } : holdWords(hold, holdReader(db, issue.repoId, reader)); | |
| 456 | if (hold !== undefined) return holdWords(hold, holdReader(db, issue.repoId, reader)); | |
| 457 | return wallLine(db, issue, run, reader) ?? { says: workLine(db, issue, now) }; | |
| 458 | } | |
| 459 | ||
| 460 | /** | |
| 461 | * The pull its run pushed, when the access wall holds it on its head (#7847): what it would open, | |
| 462 | * in the wall's own words, and for a reader who may answer, the pull to answer it on. | |
| 463 | * Never "waiting for you to land it" without the reason. | |
| 464 | */ | |
| 465 | function wallLine(db: Database, issue: Issue, run: { branch: string } | null | undefined, reader: User | undefined): WorkLine | undefined { | |
| 466 | if (run === null || run === undefined || run.branch === "") return undefined; | |
| 467 | const row = db | |
| 468 | .query<{ id: string; number: number; head_oid: string; merged_at: string | null }, [string, string]>( | |
| 469 | "SELECT i.id, i.number, p.head_oid, p.merged_at FROM pull p JOIN issue i ON i.id = p.issue_id WHERE p.head_branch = ?1 AND i.repo_id = ?2 ORDER BY i.number DESC LIMIT 1", | |
| 470 | ) | |
| 471 | .get(run.branch, issue.repoId); | |
| 472 | if (row === null || row.merged_at !== null) return undefined; | |
| 473 | const words = wallWords(db, row.id, row.head_oid); | |
| 474 | if (words === null) return undefined; | |
| 475 | const repo = getRepoById(db, issue.repoId); | |
| 476 | const named = issue.assigneeId === null ? undefined : getUserById(db, issue.assigneeId)?.username; | |
| 477 | const says = `${named ?? WORK_WORDS.crew} pushed #${row.number}. The access wall holds it for you to decide: ${words.join("; ")}.`; | |
| 478 | if (repo === undefined || reader === undefined || reader.kind === "agent" || !canWrite(db, repo, reader)) return { says }; | |
| 479 | return { says, wall: { repo: `${repo.ownerName}/${repo.name}`, number: row.number } }; | |
| 450 | 480 | } |
| 451 | 481 | |
| 452 | 482 | /** A receipt that names an issue the person may read: what it says, the issue, and its work line now. */ |
src/crew/conversation_ask.ts +1
| @@ -142,6 +142,7 @@ export const ASKED_AS: Readonly<Record<string, Form>> = { | ||
| 142 | 142 | close: (a) => |
| 143 | 143 | a["state"] === "open" ? `Reopen ${item(a)}` : `Close ${item(a)}${clause(" as ", verb(a, "reason", { done: "done", dropped: "dropped", split: "split up" }, ""))}`, |
| 144 | 144 | merge: (a) => `Merge ${pull(a)}`, |
| 145 | wall: (a) => (a["answer"] === "send_back" ? `Send ${pull(a)} back at the access wall` : `Allow ${pull(a)} at the access wall and merge it`), | |
| 145 | 146 | edit: (a) => |
| 146 | 147 | a["title"] !== undefined ? `Retitle ${item(a)}${clause(" to ", quote(a, "title"))}` : `Rewrite the description of ${item(a)}`, |
| 147 | 148 | review: (a) => (a["verdict"] === "changes" ? `Ask for changes on ${pull(a)}${clause(": ", quote(a, "reason"))}` : `Approve ${pull(a)}`), |
src/crew/conversation_brief.ts +1
| @@ -26,6 +26,7 @@ export const VOICE: readonly string[] = [ | ||
| 26 | 26 | "After you act, say what changed and where in at most three lines, and give detail only when they ask; the known block is for questions about the state of things, never an appendix to a change.", |
| 27 | 27 | "Use a value the person gave (a colour, a name, a number) exactly; if it fails something real, such as contrast, say so in one line and offer the nearest value that passes.", |
| 28 | 28 | "Never say the forge lacks something you have not looked for, and never say a held action will do more than its call does.", |
| 29 | "When a build's pull waits at the access wall (a `tell` status with `wall`, or the receipt's line says so), name what it opens in the wall's words and say it is theirs to allow (\"The crew's pull opens counter records to anyone signed out; that is yours to allow\"), and offer `wall` to put the answer to them; never say it only waits to be landed.", | |
| 29 | 30 | "When you have set the crew building, say that the line under the receipt follows the build as it goes (waiting, working, pushed, landed): never a moment's state such as that it is queued and not built yet, and never that a pull request will appear for them to land, since the crew may land it itself and the line says when.", |
| 30 | 31 | "When a tool answer about a run carries `waiting`, say that sentence as it is and give its `change` address as a link worded with `changeWords`; never say only that it is queued or has not started.", |
| 31 | 32 | "Say each thing once: a choice offered as buttons is not asked again in prose, and never say nothing is waiting on them while you hold an ask.", |
src/crew/conversation_confirm.ts +2
| @@ -107,6 +107,8 @@ export const ASKING: Readonly<Record<string, Asking>> = { | ||
| 107 | 107 | share: {}, |
| 108 | 108 | invites: { asks: (a) => a["action"] !== "list" }, |
| 109 | 109 | invite: { asks: (a) => typeof a["who"] === "string" && a["who"] !== "" }, |
| 110 | // The access wall is a person's decision: the agent puts it to them, in the wall's words. | |
| 111 | wall: { undo: (a) => (a["answer"] === "allow" ? "`take_back` opens the pull that reverts it" : undefined) }, | |
| 110 | 112 | egress_grants: { asks: not("op", "list") }, |
| 111 | 113 | sever: {}, |
| 112 | 114 | parent_unlink: {}, |
src/http/mcp/catalog.ts +1 −1
| @@ -46,7 +46,7 @@ export const DEFAULT_TOOLS: readonly string[] = [ | ||
| 46 | 46 | export const TALK_TOOLS: readonly string[] = [ |
| 47 | 47 | ...DEFAULT_TOOLS, |
| 48 | 48 | "issue", "issues", "pull", "pulls", "commits", "threads", "search", "read_file", "repo", "run_log", |
| 49 | "preview", "assigned", "health", "releases", "person", "whoami_can", "show", "pane", "origins", "invite", | |
| 49 | "preview", "assigned", "health", "releases", "person", "whoami_can", "show", "pane", "origins", "invite", "wall", | |
| 50 | 50 | "close", "assign", "labels", "edit", "review", "merge", "keep_plan", "steer", "stop", |
| 51 | 51 | "write_file", "branches", "open_pull", "new_app", |
| 52 | 52 | ]; |
src/http/mcp/tools/index.ts +1
| @@ -198,6 +198,7 @@ export { tool as valves } from "./valves.ts"; | ||
| 198 | 198 | export { tool as variant } from "./variant.ts"; |
| 199 | 199 | export { tool as vision } from "./vision.ts"; |
| 200 | 200 | export { tool as wait_for } from "./wait_for.ts"; |
| 201 | export { tool as wall } from "./wall.ts"; | |
| 201 | 202 | export { tool as watch } from "./watch.ts"; |
| 202 | 203 | export { tool as waves } from "./waves.ts"; |
| 203 | 204 | export { tool as week } from "./week.ts"; |
src/http/mcp/tools/labels.ts +2 −1
| @@ -1,6 +1,7 @@ | ||
| 1 | import { originError } from "../../../actions/merge_words.ts"; | |
| 1 | 2 | import { THREAD_SAYS } from "../../../actions/thread_words.ts"; |
| 2 | 3 | import { setIssueLabelsThrough } from "../../../actions/issues.ts"; |
| 3 | import { originError } from "../../../web/pages/thread.ts"; | |
| 4 | ||
| 4 | 5 | import { ensureFlowLabel } from "../../../actions/flow_first.ts"; |
| 5 | 6 | import { FLOW_LABEL } from "../../../core/flow_label.ts"; |
| 6 | 7 | import { labelsFor } from "../../../core/issues.ts"; |
src/http/mcp/tools/merge.ts +2 −1
| @@ -1,3 +1,4 @@ | ||
| 1 | import { mergeFailure } from "../../../actions/merge_words.ts"; | |
| 1 | 2 | import { mayView } from "../../../core/sealed.ts"; |
| 2 | 3 | import { mergePull } from "../../../actions/pulls.ts"; |
| 3 | 4 | import { getPull, pullDir, pullMergeState } from "../../../core/pulls.ts"; |
| @@ -5,7 +6,7 @@ import { checkSummary } from "../../../core/runs.ts"; | ||
| 5 | 6 | import { canWrite } from "../../../core/repos.ts"; |
| 6 | 7 | import { canVerdict } from "../../../core/verdict.ts"; |
| 7 | 8 | import { reviewWords } from "../../../actions/review_words.ts"; |
| 8 | import { mergeFailure } from "../../../web/pages/pull.ts"; | |
| 9 | ||
| 9 | 10 | import { LAND_AS_IS, shipsPastReviews, stalledWords } from "../../../web/studio/land_as_is.ts"; |
| 10 | 11 | import { good, bad, type Answer, type Tool, REPO_ARG, repoArg, isAnswer } from "../shared.ts"; |
| 11 | 12 | import type { Ctx } from "../../context.ts"; |
src/http/mcp/tools/reports.ts +2 −1
| @@ -1,5 +1,6 @@ | ||
| 1 | import { originError } from "../../../actions/merge_words.ts"; | |
| 1 | 2 | import { REPORT_ALREADY_DECIDED } from "../../../actions/origin_app_words.ts"; |
| 2 | import { originError } from "../../../web/pages/thread.ts"; | |
| 3 | ||
| 3 | 4 | import { |
| 4 | 5 | acceptReport, |
| 5 | 6 | dismissReport, |
src/http/mcp/tools/review.ts +2 −1
| @@ -1,6 +1,7 @@ | ||
| 1 | import { originError } from "../../../actions/merge_words.ts"; | |
| 1 | 2 | import { mayView } from "../../../core/sealed.ts"; |
| 2 | 3 | import { submitReview } from "../../../actions/pulls.ts"; |
| 3 | import { originError } from "../../../web/pages/thread.ts"; | |
| 4 | ||
| 4 | 5 | import { reviewWords } from "../../../actions/review_words.ts"; |
| 5 | 6 | import { getPull } from "../../../core/pulls.ts"; |
| 6 | 7 | import { canVerdict } from "../../../core/verdict.ts"; |
src/http/mcp/tools/wall.ts added +70
| @@ -0,0 +1,70 @@ | ||
| 1 | import { wallFailure } from "../../../actions/merge_words.ts"; | |
| 2 | import { answerWall, wallHolds } from "../../../actions/pulls.ts"; | |
| 3 | import { getPull, type Pull } from "../../../core/pulls.ts"; | |
| 4 | import { canRead, getRepo } from "../../../core/repos.ts"; | |
| 5 | import { mayView } from "../../../core/sealed.ts"; | |
| 6 | import type { User } from "../../../core/users.ts"; | |
| 7 | ||
| 8 | import type { Ctx } from "../../context.ts"; | |
| 9 | import { bad, good, isAnswer, REPO_ARG, repoArg, str, type Tool } from "../shared.ts"; | |
| 10 | ||
| 11 | type Args = Record<string, unknown>; | |
| 12 | ||
| 13 | /** The pull a call names, and what the wall asks of it now; undefined when it names none. */ | |
| 14 | function heldPull(ctx: Ctx, user: User, args: Args): { pull: Pull; words: string[] | null; name: string } | undefined { | |
| 15 | const [owner, name, rest] = str(args["repo"]).split("/"); | |
outdated
HIGH: no read check on the repo before the wall words are read. |
||
| 16 | const n = args["number"]; | |
| 17 | if (owner === undefined || name === undefined || rest !== undefined || typeof n !== "number") return undefined; | |
| 18 | // Read as the person: a repository they may not read says nothing, as `repoArg` answers not | |
| 19 | // found. | |
| 20 | const repo = getRepo(ctx.app.db, owner, name); | |
| 21 | if (repo === undefined || !canRead(ctx.app.db, repo, user)) return undefined; | |
| 22 | const pull = getPull(ctx.app.db, repo.id, n); | |
| 23 | if (pull === undefined || !mayView(ctx.app.db, repo, pull, user)) return undefined; | |
| 24 | return { pull, words: wallHolds(ctx.app, pull), name: `pull #${n} in ${owner}/${name}` }; | |
| 25 | } | |
| 26 | ||
| 27 | /** | |
| 28 | * A person's answer to the access wall from Talk (#7847): the same decision the pull page's wall | |
| 29 | * card offers, put to them as a held confirm in the wall's own words. Allow is the page's merge, | |
| 30 | * send back its request for changes (`answerWall`); a person answers, never the agent. | |
| 31 | */ | |
| 32 | export const tool: Tool = { | |
| 33 | name: "wall", | |
| 34 | doc: "`{ repo, number, answer: allow|send_back, why? }`: a person answers the access wall on a pull: allow merges, send back asks for changes", | |
| 35 | description: "Answer the access wall on a pull: allow it (merge) or send it back.", | |
| 36 | inputSchema: { | |
| 37 | type: "object", | |
| 38 | properties: { | |
| 39 | repo: REPO_ARG, | |
| 40 | number: { type: "integer", minimum: 1 }, | |
| 41 | answer: { type: "string", enum: ["allow", "send_back"] }, | |
| 42 | why: { type: "string" }, | |
| 43 | }, | |
| 44 | required: ["repo", "number", "answer"], | |
| 45 | }, | |
| 46 | writes: true, | |
| 47 | // The confirm says what the wall says: what the pull would open, read from the forge, not the | |
| 48 | // agent. | |
| 49 | heldSays(ctx, user, args) { | |
| 50 | const held = heldPull(ctx, user, args); | |
| 51 | if (held === undefined || held.words === null) return undefined; | |
| 52 | const opens = held.words.join("; "); | |
| 53 | return args["answer"] === "send_back" | |
| 54 | ? `Send ${held.name} back: it would open this, which the access wall holds for you: ${opens}.` | |
| 55 | : `Allow it and merge ${held.name}: ${opens}.`; | |
| 56 | }, | |
| 57 | async run(ctx, user, args) { | |
| 58 | if (user.kind === "agent") return bad("forbidden", "the access wall is a person's to answer, never an agent's"); | |
| 59 | const repo = repoArg(ctx, user, args); | |
| 60 | if (isAnswer(repo)) return repo; | |
| 61 | const answer = args["answer"]; | |
| 62 | if (answer !== "allow" && answer !== "send_back") return bad("invalid", "answer is allow or send_back"); | |
| 63 | const n = args["number"]; | |
| 64 | const pull = typeof n === "number" && Number.isInteger(n) && n > 0 ? getPull(ctx.app.db, repo.id, n) : undefined; | |
| 65 | if (pull === undefined) return bad("not_found", `no pull #${String(n)} here`); | |
| 66 | const done = await answerWall(ctx.app, user, repo, pull, answer, str(args["why"])); | |
| 67 | if (!done.ok) return bad(typeof done.error === "string" ? done.error : done.error.kind, wallFailure(done.error)); | |
| 68 | return good({ answer: done.value, says: done.value === "merged" ? `Allowed and merged #${pull.number}.` : `Sent #${pull.number} back to its builder.` }); | |
| 69 | }, | |
| 70 | }; |
src/http/server.ts +2 −1
| @@ -171,7 +171,7 @@ import { | ||
| 171 | 171 | themeSubmit, |
| 172 | 172 | } from "../web/pages/site.ts"; |
| 173 | 173 | import { talkBuild, talkPublish, talkRestore } from "../web/talk_build.ts"; |
| 174 | import { talkAct, talkAgainSend, talkArchive, talkConfirm, talkDisplaySave, talkDownload, talkNew, talkPin, talkQueueCancel, talkRename, talkSend, talkUndo, talkStream, talkView } from "../web/pages/talk.ts"; | |
| 174 | import { talkAct, talkAgainSend, talkArchive, talkConfirm, talkDisplaySave, talkDownload, talkNew, talkPin, talkQueueCancel, talkRename, talkSend, talkUndo, talkStream, talkView, talkWall } from "../web/pages/talk.ts"; | |
| 175 | 175 | import { liveTalkCrew, liveTalkWork, talkPeek } from "../web/talk_peek.ts"; |
| 176 | 176 | import { |
| 177 | 177 | recoverFinish, |
| @@ -1259,6 +1259,7 @@ export function buildRouter(): Router<Handler> { | ||
| 1259 | 1259 | router.add("GET", "/runs/:id", runRedirect); |
| 1260 | 1260 | router.add("GET", "/talk", talkView); |
| 1261 | 1261 | router.add("POST", "/talk", talkSend); |
| 1262 | router.add("POST", "/talk/wall", talkWall); | |
| 1262 | 1263 | router.add("GET", "/talk/stream", talkStream); |
| 1263 | 1264 | router.add("GET", "/talk/peek", talkPeek); |
| 1264 | 1265 | router.add("POST", "/talk/again/:how", talkAgainSend); |
src/runs/tell_status.ts +14 −1
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | import type { Database } from "bun:sqlite"; |
| 9 | 9 | import type { Issue } from "../core/issues.ts"; |
| 10 | 10 | import { getPull, openPullsClosing, pullForBranch, type Pull } from "../core/pulls.ts"; |
| 11 | import { wallWords } from "../flow/wall_wait.ts"; | |
| 11 | 12 | import { listRuns, type Run } from "../core/runs.ts"; |
| 12 | 13 | import { getUsersByIds, type User } from "../core/users.ts"; |
| 13 | 14 | |
| @@ -141,7 +142,19 @@ export function tellStatusFields( | ||
| 141 | 142 | db: Database, |
| 142 | 143 | repoId: string, |
| 143 | 144 | issue: Issue, |
| 144 | ): { status: TellState; run: string | null; pull: number | null; says: string } { | |
| 145 | ): { status: TellState; run: string | null; pull: number | null; says: string; wall?: string[] } { | |
| 145 | 146 | const s = readTellStatusOf(db, repoId, issue); |
| 147 | // A pull the access wall holds waits on the person's answer, not on a landing (#7847): said in | |
| 148 | // the wall's own words, so the agent's reply names what it opens and whose it is. | |
| 149 | const pull = s.pull === null || issue.state === "closed" ? undefined : getPull(db, repoId, s.pull); | |
| 150 | const wall = pull === undefined ? null : wallWords(db, pull.id, pull.headOid); | |
| 151 | if (wall !== null && pull !== undefined) | |
| 152 | return { | |
| 153 | status: s.state, | |
| 154 | run: s.run, | |
| 155 | pull: s.pull, | |
| 156 | says: `#${pull.number} waits at the access wall for the person: it would open this: ${wall.join("; ")}. That is theirs to allow or send back (\`wall\`).`, | |
| 157 | wall, | |
| 158 | }; | |
| 146 | 159 | return { status: s.state, run: s.run, pull: s.pull, says: s.plain }; |
| 147 | 160 | } |
src/tui/screens/landasis.ts +2 −1
| @@ -6,9 +6,10 @@ | ||
| 6 | 6 | * refusals in its words. Offered in the palette only while there is one. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { mergeFailure } from "../../actions/merge_words.ts"; | |
| 9 | 10 | import { mergePull } from "../../actions/pulls.ts"; |
| 10 | 11 | import type { Repo } from "../../core/repos.ts"; |
| 11 | import { mergeFailure } from "../../web/pages/pull.ts"; | |
| 12 | ||
| 12 | 13 | import { LAND_AS_IS, landable, shipsPastReviews, stalledWords } from "../../web/studio/land_as_is.ts"; |
| 13 | 14 | import type { Ctx, Screen } from "../app/app.ts"; |
| 14 | 15 | import { binding } from "../app/keys.ts"; |
src/tui/screens/talk_chats.ts +47 −4
| @@ -40,6 +40,7 @@ import { waitingConfirms } from "../../actions/conversation_confirms.ts"; | ||
| 40 | 40 | import { branchDiff, chatBuildOf, mineEmpty, pullChanges, type PullChange } from "../../core/chat_build.ts"; |
| 41 | 41 | import { addCommentThrough } from "../../actions/issues.ts"; |
| 42 | 42 | import { getIssue } from "../../core/issues.ts"; |
| 43 | import { getPull } from "../../core/pulls.ts"; | |
| 43 | 44 | import { canRead, getRepo, getRepoById } from "../../core/repos.ts"; |
| 44 | 45 | import type { ShownCard } from "../../core/talk_voice.ts"; |
| 45 | 46 | import { PANE_PATH_REFUSAL, paneChoice, paneOffer, panePath, pointedAt, workspaceOf, type PaneAt, type PaneOffer } from "../../actions/talk_workspace.ts"; |
| @@ -51,7 +52,8 @@ import { truncate, wrap } from "../term/width.ts"; | ||
| 51 | 52 | import type { Session } from "../session.ts"; |
| 52 | 53 | import type { User } from "../../core/users.ts"; |
| 53 | 54 | import { fill, len, split } from "../ui/layout.ts"; |
| 54 | import { ListState, Scroll, ago, drawLines, drawList, pickerScreen, promptScreen, runAsync, type ListRow, type PickItem } from "./common.ts"; | |
| 55 | import { ListState, Scroll, ago, confirmScreen, drawLines, drawList, errorText, later, pickerScreen, promptScreen, runAsync, type ListRow, type PickItem } from "./common.ts"; | |
| 56 | import { answerWall } from "../../actions/pulls.ts"; | |
| 55 | 57 | import { fresh, mayAct, pressCard, PRESS_REFUSED } from "../../actions/talk_act.ts"; |
| 56 | 58 | |
| 57 | 59 | const BAD_TITLE = `A title is up to ${TITLE_MAX} characters, on one line.`; |
| @@ -214,6 +216,39 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr | ||
| 214 | 216 | if (crew?.issue !== undefined) return on(crew.issue); |
| 215 | 217 | return [...turns].reverse().map((t) => receipts.get(t.id)).find((r) => r !== undefined); |
| 216 | 218 | }; |
| 219 | /** | |
| 220 | * The newest receipt the access wall holds, answered as its page's wall card answers it | |
| 221 | * (`answerWall`), after a confirm in the wall's own words. | |
| 222 | */ | |
| 223 | const answerTheWall = (answer: "allow" | "send_back"): void => { | |
| 224 | const asked = [...turns].reverse().map((t) => receipts.get(t.id)).find((r) => r?.line.wall !== undefined); | |
| 225 | const wall = asked?.line.wall; | |
| 226 | const [owner, name] = (wall?.repo ?? "").split("/"); | |
| 227 | const home = wall === undefined || owner === undefined || name === undefined ? undefined : getRepo(f.app.db, owner, name); | |
| 228 | const pull = home === undefined || wall === undefined ? undefined : getPull(f.app.db, home.id, wall.number); | |
| 229 | if (home === undefined || pull === undefined || asked === undefined) { | |
| 230 | note = "Nothing here waits at the access wall."; | |
| 231 | ctx.invalidate(); | |
| 232 | return; | |
| 233 | } | |
| 234 | void later(ctx, () => | |
| 235 | confirmScreen(ctx, screen, { | |
| 236 | title: answer === "allow" ? "Allow it" : "Send it back", | |
| 237 | body: [asked.line.says, answer === "allow" ? `Allow it and merge #${pull.number}.` : `Send #${pull.number} back to its builder.`], | |
| 238 | actions: [{ label: "Cancel", variant: "ghost" }, { label: answer === "allow" ? "Allow it" : "Send it back" }], | |
| 239 | selected: 1, | |
| 240 | onChoose: (i) => { | |
| 241 | if (i !== 1) return; | |
| 242 | runAsync(ctx, async () => { | |
| 243 | const done = await answerWall(f.app, f.user, home, pull, answer); | |
| 244 | note = done.ok ? (done.value === "merged" ? `Allowed and merged #${pull.number}.` : `Sent #${pull.number} back.`) : errorText(typeof done.error === "string" ? done.error : done.error.kind); | |
| 245 | load(); | |
| 246 | ctx.invalidate(); | |
| 247 | }); | |
| 248 | }, | |
| 249 | }), | |
| 250 | ); | |
| 251 | }; | |
| 217 | 252 | const paneLines = (): string[] => { |
| 218 | 253 | if (repo === undefined || f.user === undefined) return ["No repository yet."]; |
| 219 | 254 | // Where the person picked, else where the agent pointed the pane (`pane`), as the page frames it. |
| @@ -272,9 +307,12 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr | ||
| 272 | 307 | if (receipt !== undefined) { |
| 273 | 308 | // The line, and the control that changes what a waiting run waits on, by its address. |
| 274 | 309 | const l = receipt.line; |
| 275 | const work = l.change === undefined ? l.says : `${l.says} ${l.change.words}: ${f.app.config.url === undefined ? l.change.href : publicOrigin(f.app.config.url, "") + l.change.href}`; | |
| 276 | n += work === "" ? 2 : 3; | |
| 277 | return [[{ text: `✓ ${receipt.says}`, style: style(c.fg, c.bg) }], ...(work === "" ? [] : [[{ text: ` ${work}`, style: style(c.mutedFg, c.bg) }]]), []]; | |
| 310 | const at = (href: string) => (f.app.config.url === undefined ? href : publicOrigin(f.app.config.url, "") + href); | |
| 311 | const work = l.change === undefined ? l.says : `${l.says} ${l.change.words}: ${at(l.change.href)}`; | |
| 312 | // The wall's answers on a line of their own, as keys, and the page that holds them. | |
| 313 | const answers = l.wall === undefined ? [] : [[{ text: ` A: allow it · S: send it back · ${at(`/${l.wall.repo}/pulls/${String(l.wall.number)}`)}`, style: style(c.fg, c.bg) }]]; | |
| 314 | n += (work === "" ? 2 : 3) + answers.length; | |
| 315 | return [[{ text: `✓ ${receipt.says}`, style: style(c.fg, c.bg) }], ...(work === "" ? [] : [[{ text: ` ${work}`, style: style(c.mutedFg, c.bg) }]]), ...answers, []]; | |
| 278 | 316 | } |
| 279 | 317 | const step = t.role === "tool" ? stepOf(t.text) : undefined; |
| 280 | 318 | // Folded, a run of steps reads as one line: its one step's words, or how many. |
| @@ -317,6 +355,7 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr | ||
| 317 | 355 | binding(["D"], "display"), |
| 318 | 356 | binding(["c"], "comment on the receipt's issue"), |
| 319 | 357 | binding(["a"], "answer what waits"), |
| 358 | binding(["A", "S"], "the access wall: allow it, or send it back"), | |
| 320 | 359 | binding(["d", "x"], "export as Markdown"), |
| 321 | 360 | binding(["esc"], "back"), |
| 322 | 361 | ], |
| @@ -481,6 +520,10 @@ function chatScreen(f: Session, ctx: Ctx, chat: Conversation, hit?: string): Scr | ||
| 481 | 520 | ctx.push(downloadScreen(f, ctx, chat)); |
| 482 | 521 | return true; |
| 483 | 522 | } |
| 523 | if ((e.key === "A" || e.key === "S") && f.user !== undefined) { | |
| 524 | answerTheWall(e.key === "A" ? "allow" : "send_back"); | |
| 525 | return true; | |
| 526 | } | |
| 484 | 527 | if (e.key === "c") { |
| 485 | 528 | // As the page's crew box says it: on the pull whose preview the pane shows, else the issue the |
| 486 | 529 | // crew's newest run works; else, as Reply does, the newest receipt's issue. Whoever works on |
src/web/pages/issues.ts +1 −1
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | * Mobile-first, no JavaScript required. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { originError } from "../../actions/merge_words.ts"; | |
| 8 | 9 | import { comeBack } from "../come_back.ts"; |
| 9 | 10 | import { CEILING_REFUSAL, PAUSE_REFUSAL } from "../../core/planner_pause.ts"; |
| 10 | 11 | import { |
| @@ -40,7 +41,6 @@ import { tellPage } from "../studio/tell.ts"; | ||
| 40 | 41 | import { cleanFrom, repoOfPath, withFromLine } from "../issue_from.ts"; |
| 41 | 42 | import { btn, empty, field as formField, listCard, row } from "../ui.ts"; |
| 42 | 43 | import { |
| 43 | originError, | |
| 44 | 44 | parseNumber, |
| 45 | 45 | threadContext, |
| 46 | 46 | threadFragment, |
src/web/pages/pull.ts +5 −47
| @@ -17,8 +17,8 @@ import { isPileChoice, pileWords, takePileChoice } from "../../crew/stuck_pile.t | ||
| 17 | 17 | import { placeWords, queuePlace } from "../../checks/place.ts"; |
| 18 | 18 | import { addCommentThrough } from "../../actions/issues.ts"; |
| 19 | 19 | import { COMMENT_EMPTY, COMMENT_NOT_POSTED } from "../../actions/comment_words.ts"; |
| 20 | import type { AccessError } from "../../actions/access.ts"; | |
| 21 | import { NO_WRITE_ACCESS, PULL_GONE } from "../../actions/pull_words.ts"; | |
| 20 | import { PULL_GONE } from "../../actions/pull_words.ts"; | |
| 21 | import { originError, mergeFailure } from "../../actions/merge_words.ts"; | |
| 22 | 22 | import { |
| 23 | 23 | addReview, |
| 24 | 24 | markReady, |
| @@ -46,7 +46,6 @@ import { | ||
| 46 | 46 | diffBetween, |
| 47 | 47 | pullDir, |
| 48 | 48 | pullStatus, |
| 49 | type MergePullError, | |
| 50 | 49 | type Pull, |
| 51 | 50 | type PullReviewStatus, |
| 52 | 51 | type PullStatus, |
| @@ -56,8 +55,8 @@ import { checkWords } from "../../checks/summary.ts"; | ||
| 56 | 55 | import { redMain } from "../../checks/red_main.ts"; |
| 57 | 56 | import { mainLineFor } from "../../checks/red_main_line.ts"; |
| 58 | 57 | import { runningProgress } from "../../checks/progress.ts"; |
| 59 | import { CHECK_STALE_REFUSAL, checkStale, checksHold } from "../../checks/stale.ts"; | |
| 60 | import { DRAFT_REFUSAL, isDraft } from "../../core/pulls.ts"; | |
| 58 | import { checkStale, checksHold } from "../../checks/stale.ts"; | |
| 59 | import { isDraft } from "../../core/pulls.ts"; | |
| 61 | 60 | import { checkSummary, type CheckSummary } from "../../core/runs.ts"; |
| 62 | 61 | import { |
| 63 | 62 | anchorKey, |
| @@ -98,7 +97,7 @@ import { | ||
| 98 | 97 | type ThreadView, |
| 99 | 98 | } from "../diff-view.ts"; |
| 100 | 99 | import { asRefusal, field, readForm, refused, refuseHere } from "../form.ts"; |
| 101 | import { teamHoldRefusal, waitingOnTeams } from "../../core/teams_words.ts"; | |
| 100 | import { waitingOnTeams } from "../../core/teams_words.ts"; | |
| 102 | 101 | import { teamsHolding, teamVerdicts, type TeamVerdict } from "../../core/issue_teams.ts"; |
| 103 | 102 | import { html, raw, when, type Html } from "../html.ts"; |
| 104 | 103 | import { flashTo, fragment, page, redirect } from "../layout.ts"; |
| @@ -124,7 +123,6 @@ import { | ||
| 124 | 123 | import { |
| 125 | 124 | assigneeCard, |
| 126 | 125 | labelsCard, |
| 127 | originError, | |
| 128 | 126 | threadFragment, |
| 129 | 127 | } from "./thread.ts"; |
| 130 | 128 | import { previewEnv } from "../../apps/data.ts"; |
| @@ -133,7 +131,6 @@ import { pullPreviewFindings } from "../../core/preview_findings.ts"; | ||
| 133 | 131 | import { crewActivityCard } from "./runs.ts"; |
| 134 | 132 | import { holdCard } from "../studio/hold.ts"; |
| 135 | 133 | import { guestWalls, strangerCard } from "./pull-guest.ts"; |
| 136 | import { guardedRefusal } from "../../crew/stranger.ts"; | |
| 137 | 134 | import { conflictWords } from "../../crew/stale_asks.ts"; |
| 138 | 135 | import { |
| 139 | 136 | changeHead, |
| @@ -1369,45 +1366,6 @@ export async function pullReviewSubmit(ctx: Ctx): Promise<Response> { | ||
| 1369 | 1366 | }); |
| 1370 | 1367 | } |
| 1371 | 1368 | |
| 1372 | /** | |
| 1373 | * Why a merge did not land, in words. The action's error is either an access | |
| 1374 | * or lifecycle code, or git's own structured `MergeError` — both are answers | |
| 1375 | * the person pressing the button deserves to see. | |
| 1376 | */ | |
| 1377 | export function mergeFailure(error: AccessError | MergePullError): string { | |
| 1378 | if (typeof error !== "string") { | |
| 1379 | if (error.kind === "conflict") | |
| 1380 | return `The branches conflict in ${error.files.length} file${error.files.length === 1 ? "" : "s"} — merge the base branch in and push again.`; | |
| 1381 | if (error.kind === "base_moved") | |
| 1382 | return "The base branch moved while merging. Try again."; | |
| 1383 | if (error.kind === "ref_locked") | |
| 1384 | return "The base branch is locked by another git operation. Try again in a moment."; | |
| 1385 | if (error.kind === "unsafe") return "That merge was refused as unsafe."; | |
| 1386 | if (error.kind === "guarded") return guardedRefusal(error.paths); | |
| 1387 | if (error.kind === "team_review_required") | |
| 1388 | return teamHoldRefusal(error.teams); | |
| 1389 | return "Git refused the merge."; | |
| 1390 | } | |
| 1391 | const fromOrigin = originError(error); | |
| 1392 | if (fromOrigin !== undefined) return fromOrigin; | |
| 1393 | if (error === "already_merged") | |
| 1394 | return "This pull request was already merged."; | |
| 1395 | if (error === "closed") | |
| 1396 | return "A closed pull request cannot be merged. Reopen it first."; | |
| 1397 | if (error === "head_moved") | |
| 1398 | return "The pull's head moved while it was being checked. Nothing was merged; look again and retry."; | |
| 1399 | // The gate races: the page was rendered with an approval that a push | |
| 1400 | // dismissed a second later, or a reviewer asked for changes in between. | |
| 1401 | if (error === "review_required") | |
| 1402 | return "This pull request needs an approving review of its current head, and does not have one. Nothing was merged."; | |
| 1403 | if (error === "check_stale") return CHECK_STALE_REFUSAL; | |
| 1404 | if (error === "draft") return DRAFT_REFUSAL; | |
| 1405 | if (error === "checks_required") | |
| 1406 | return "This pull request needs a passing deploy of its current head, and does not have one yet. Nothing was merged."; | |
| 1407 | if (error === "forbidden" || error === "unauthorized") | |
| 1408 | return NO_WRITE_ACCESS; | |
| 1409 | return PULL_GONE; | |
| 1410 | } | |
| 1411 | 1369 | |
| 1412 | 1370 | // ---- verdicts and threads ---- |
| 1413 | 1371 |
src/web/pages/talk.ts +24 −2
| @@ -62,7 +62,10 @@ import { signInFirst, forbiddenPage, notFoundPage } from "../chrome.ts"; | ||
| 62 | 62 | import { field, readForm } from "../form.ts"; |
| 63 | 63 | import { html, raw, type Html } from "../html.ts"; |
| 64 | 64 | import { flashTo, fragment, page, redirect } from "../layout.ts"; |
| 65 | import { getRepoById } from "../../core/repos.ts"; | |
| 65 | import { canRead, getRepo, getRepoById } from "../../core/repos.ts"; | |
| 66 | import { getPull } from "../../core/pulls.ts"; | |
| 67 | import { answerWall } from "../../actions/pulls.ts"; | |
| 68 | import { wallFailure } from "../../actions/merge_words.ts"; | |
| 66 | 69 | import { mayReadRunLog, mayReadRuns } from "../../actions/runs.ts"; |
| 67 | 70 | import { codePaneCss } from "../talk_code.ts"; |
| 68 | 71 | import { linkRefs, refTarget } from "../../text/talk_links.ts"; |
| @@ -195,7 +198,7 @@ function receiptCard(id: string, turnId: string, receipt: Receipt, at: string, s | ||
| 195 | 198 | : html`<form method="post" action="${HERE}/undo/${turnId}">${btn(receipt.undo.label, { icon: "history", label: receipt.undo.label, size: "sm", variant: "ghost" })}</form>`; |
| 196 | 199 | return html`<li class="talk-turn talk-receipt${set}" id="${id}" data-done> |
| 197 | 200 | <p class="talk-receipt-line">${icon("check")}<span><strong>${receipt.verb}</strong> <a href="${receipt.href}">${receipt.object}</a>${title === "" ? null : html` <span class="muted">${title}</span>`} <span class="talk-when">${time(at)}</span></span></p> |
| 198 | ${issue === null ? null : html`<p class="talk-work-line small muted" id="w-${turnId}" data-live="run.*,issue.*,pull.*,comment.*" data-live-repo="${issue[1]}/${issue[2]}" data-live-src="/live/talk-work?href=${encodeURIComponent(receipt.href)}&id=w-${turnId}">${workLineHtml(line)}</p>`} | |
| 201 | ${issue === null ? null : html`<div class="talk-work-line small muted" id="w-${turnId}" data-live="run.*,issue.*,pull.*,comment.*" data-live-repo="${issue[1]}/${issue[2]}" data-live-src="/live/talk-work?href=${encodeURIComponent(receipt.href)}&id=w-${turnId}">${workLineHtml(line)}</div>`} | |
| 199 | 202 | ${undo === null && issue === null ? null : html`<div class="talk-receipt-acts">${undo}${issue === null ? null : html`<a class="btn" data-size="sm" data-variant="ghost" href="${receipt.href}#comment-body" data-reply="${receipt.href}" data-reply-to="${receipt.object}">${icon("comment")} Reply on ${receipt.object}</a>`}</div>`} |
| 200 | 203 | </li>`; |
| 201 | 204 | } |
| @@ -720,6 +723,25 @@ export async function talkSend(ctx: Ctx): Promise<Response> { | ||
| 720 | 723 | return flashTo(ctx, `${here}`, { tone: "success", message: "Sent. Reload to see the answer." }); |
| 721 | 724 | } |
| 722 | 725 | |
| 726 | // POST /talk/wall — the access wall answered from a receipt in Talk (`answerWall`, the pull page's | |
| 727 | // merge or its request for changes): a same-origin form, so it works without the script. A pull | |
| 728 | // the person may not read is answered as not found, never named. | |
| 729 | export async function talkWall(ctx: Ctx): Promise<Response> { | |
| 730 | const user = ctx.auth.user; | |
| 731 | if (user === undefined) return signInFirst(ctx); | |
| 732 | const form = await readForm(ctx, "rw"); | |
| 733 | if (form instanceof Response) return form; | |
| 734 | const [owner, name, rest] = (field(form, "repo") ?? "").split("/"); | |
| 735 | const repo = owner === undefined || name === undefined || rest !== undefined ? undefined : getRepo(ctx.app.db, owner, name); | |
| 736 | const pull = repo === undefined || !canRead(ctx.app.db, repo, user) ? undefined : getPull(ctx.app.db, repo.id, Number(field(form, "number"))); | |
| 737 | const answer = field(form, "answer"); | |
| 738 | if (repo === undefined || pull === undefined || (answer !== "allow" && answer !== "send_back")) return notFoundPage(ctx); | |
| 739 | const done = await answerWall(ctx.app, user, repo, pull, answer); | |
| 740 | if (!done.ok) | |
| 741 | return flashTo(ctx, `${HERE}`, { tone: "danger", message: wallFailure(done.error) }); | |
| 742 | return flashTo(ctx, `${HERE}`, { tone: "success", message: done.value === "merged" ? `Allowed and merged #${pull.number}.` : `Sent #${pull.number} back to its builder.` }); | |
| 743 | } | |
| 744 | ||
| 723 | 745 | // POST /talk/new — an empty conversation, opened at its own URL. |
| 724 | 746 | export async function talkNew(ctx: Ctx): Promise<Response> { |
| 725 | 747 | const user = ctx.auth.user; |
src/web/pages/thread.ts +1 −23
| @@ -8,12 +8,12 @@ | ||
| 8 | 8 | * is what makes a long thread skimmable. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | import { originError } from "../../actions/merge_words.ts"; | |
| 11 | 12 | import { TELL_LIMIT_WORDS, TELL_TEXT_MAX } from "../../actions/tell_from.ts"; |
| 12 | 13 | import { returnTo, withReturn } from "../return_to.ts"; |
| 13 | 14 | import { mayView } from "../../core/sealed.ts"; |
| 14 | 15 | import { THREAD_SAYS } from "../../actions/thread_words.ts"; |
| 15 | 16 | import { ISSUE_TEAMS_SAY, nameTeams } from "../../actions/issue_teams.ts"; |
| 16 | import { MIRRORED_DO_IT_THERE } from "../../actions/mirror_words.ts"; | |
| 17 | 17 | import { teamsOfIssue, TEAMS_MAX } from "../../core/issue_teams.ts"; |
| 18 | 18 | import { listTeams } from "../../core/teams.ts"; |
| 19 | 19 | import { listCrew } from "../../actions/crew.ts"; |
| @@ -88,28 +88,6 @@ import { loadRepo, notFoundPage, repoBase, signInFirst } from "../chrome.ts"; | ||
| 88 | 88 | import { studioRecord, tellHref } from "../studio/nouns.ts"; |
| 89 | 89 | import { interruptionsOn } from "../../crew/interrupted.ts"; |
| 90 | 90 | |
| 91 | /** | |
| 92 | * The four ways a write can fail *because of the origin*, in words. | |
| 93 | * | |
| 94 | * They are worth their own sentences: three of them mean nothing changed | |
| 95 | * anywhere and the fourth means the change belongs on another forge, and a | |
| 96 | * generic "that could not be saved" would hide which. Returns undefined for | |
| 97 | * anything that is not an origin outcome, so callers keep their own wording. | |
| 98 | */ | |
| 99 | export function originError(error: string): string | undefined { | |
| 100 | const words: Record<string, string> = { | |
| 101 | mirrored: MIRRORED_DO_IT_THERE, | |
| 102 | origin_owner_only: | |
| 103 | "Only the person who connected this origin can write through it. Your comment would otherwise appear upstream under their name.", | |
| 104 | origin_refused: "The origin refused that. Nothing was changed here either.", | |
| 105 | origin_protected: | |
| 106 | "The operator protects this repository at its origin, so nothing is pushed to it from here. Propose the change from your fork.", | |
| 107 | origin_paused: | |
| 108 | "This connection is not verified yet, so writes through it are paused. Nothing was changed. Check it again under Settings → Connected accounts.", | |
| 109 | origin_unreachable: "The origin could not be reached. Nothing was changed.", | |
| 110 | }; | |
| 111 | return words[error]; | |
| 112 | } | |
| 113 | 91 | |
| 114 | 92 | /** The origin's mark, when this repo has one. */ |
| 115 | 93 | export function originGlyph(repo: Repo): Glyph { |
src/web/studio/change.ts +3 −1
| @@ -150,7 +150,7 @@ export function wallCard(wall: Wall, act?: string): Html { | ||
| 150 | 150 | </p> |
| 151 | 151 | <div class="bar mt"> |
| 152 | 152 | <form method="post" action="${thread}/merge"> |
| 153 | <input type="hidden" name="strategy" value="squash" /> | |
| 153 | <input type="hidden" name="strategy" value="merge" /> | |
| 154 | 154 | ${btn("Allow it and merge", { variant: "primary", icon: "merge" })} |
| 155 | 155 | </form> |
| 156 | 156 | <form method="post" action="${thread}/review-state"> |
| @@ -166,6 +166,8 @@ export function wallCard(wall: Wall, act?: string): Html { | ||
| 166 | 166 | { |
| 167 | 167 | tone: "attn", |
| 168 | 168 | extra: "wall mt", |
| 169 | // Where Talk's work line sends a person to answer the wall (`core/talk_work.ts`). | |
| 170 | id: "wall", | |
| 169 | 171 | head: html`${icon("shield")} |
| 170 | 172 | <strong |
| 171 | 173 | >${wall.unsound !== undefined |
src/web/studio/review_act.ts +3 −2
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | * (same-origin, `rw` scope). A person who acted lands on the next ask. |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | import { originError, mergeFailure } from "../../actions/merge_words.ts"; | |
| 10 | 11 | import type { Database } from "bun:sqlite"; |
| 11 | 12 | import { mergePull, submitReview } from "../../actions/pulls.ts"; |
| 12 | 13 | import { addCommentThrough, setIssueStateThrough } from "../../actions/issues.ts"; |
| @@ -21,8 +22,8 @@ import { field, readForm } from "../form.ts"; | ||
| 21 | 22 | import { html, type Html } from "../html.ts"; |
| 22 | 23 | import { flashTo, redirect } from "../layout.ts"; |
| 23 | 24 | import { btn } from "../ui.ts"; |
| 24 | import { originError } from "../pages/thread.ts"; | |
| 25 | import { mergeFailure } from "../pages/pull.ts"; | |
| 25 | ||
| 26 | ||
| 26 | 27 | import { askAnchor, waitingOn } from "./asks.ts"; |
| 27 | 28 | |
| 28 | 29 | type Ask = ReturnType<typeof waitingOn>[number]; |
src/web/studio/toolbar.ts +2 −1
| @@ -15,6 +15,7 @@ | ||
| 15 | 15 | * links to #606's page. Signed out, the page is where you are and home. |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | import { originError } from "../../actions/merge_words.ts"; | |
| 18 | 19 | import { keepJs } from "../keep.ts"; |
| 19 | 20 | import { HELP_BUILD } from "../../core/contribute.ts"; |
| 20 | 21 | import { lacks } from "../../core/roles.ts"; |
| @@ -42,7 +43,7 @@ import { diffTotals, pathAnchor } from "../diff-view.ts"; | ||
| 42 | 43 | import { field, readForm } from "../form.ts"; |
| 43 | 44 | import { html, when, type Html } from "../html.ts"; |
| 44 | 45 | import { page } from "../layout.ts"; |
| 45 | import { originError } from "../pages/thread.ts"; | |
| 46 | ||
| 46 | 47 | import { toolbarSide } from "./toolbar_side.ts"; |
| 47 | 48 | import { btn, card, envFacts, runStateBadge, badge } from "../ui.ts"; |
| 48 | 49 |
src/web/talk_peek.ts +19 −4
| @@ -14,7 +14,7 @@ import { getIssue } from "../core/issues.ts"; | ||
| 14 | 14 | import { canRead, getRepo } from "../core/repos.ts"; |
| 15 | 15 | import { mayView } from "../core/sealed.ts"; |
| 16 | 16 | import { html, type Html } from "./html.ts"; |
| 17 | import { icon, time } from "./ui.ts"; | |
| 17 | import { btn, icon, time } from "./ui.ts"; | |
| 18 | 18 | import { inlineIcons } from "./icons.ts"; |
| 19 | 19 | import { notePhase, takeSessionTime } from "../core/route_timing.ts"; |
| 20 | 20 | import { fragment } from "./layout.ts"; |
| @@ -177,7 +177,7 @@ function workFragment(ctx: Ctx): Response { | ||
| 177 | 177 | const repo = getRepo(ctx.app.db, m[1] ?? "", m[2] ?? ""); |
| 178 | 178 | const issue = repo === undefined || !canRead(ctx.app.db, repo, ctx.auth.user) ? undefined : getIssue(ctx.app.db, repo.id, Number(m[4])); |
| 179 | 179 | if (repo === undefined || issue === undefined || !mayView(ctx.app.db, repo, issue, ctx.auth.user)) return fragment(html``, { status: 404 }); |
| 180 | return fragment(html`<p class="talk-work-line small muted" id="${id}">${workLineHtml(workLineFor(ctx.app.db, ctx.app.config.dataDir, issue, Date.now(), ctx.auth.user))}</p>`, { request: ctx.request }); | |
| 180 | return fragment(html`<div class="talk-work-line small muted" id="${id}">${workLineHtml(workLineFor(ctx.app.db, ctx.app.config.dataDir, issue, Date.now(), ctx.auth.user))}</div>`, { request: ctx.request }); | |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | // GET /live/talk-crew — the crew's one line on Talk, empty when it is idle. |
| @@ -206,5 +206,20 @@ export const peekCss = /* css */ ` | ||
| 206 | 206 | (prefers-reduced-motion: no-preference) { .talk-peek:not([hidden]) { animation: talk-in var(--dur-2) var(--ease); } } |
| 207 | 207 | `; |
| 208 | 208 | |
| 209 | /** A work line's words, and the control that changes what it waits on as a link. */ | |
| 210 | export const workLineHtml = (l: WorkLine): Html => html`${l.says}${l.change === undefined ? null : html` <a href="${l.change.href}">${l.change.words}</a>`}`; | |
| 209 | /** | |
| 210 | * A work line's words, and the control that changes what it waits on as a link; when the access | |
| 211 | * wall holds its pull, the two answers as forms that post to Talk's own `/talk/wall`, which work | |
outdated
Principle 1: two links with the same href but different words. Each answer needs its own control. Allow is a mutation, so it belongs in a post form with a button, not an |
||
| 212 | * without the script. | |
| 213 | */ | |
| 214 | export const workLineHtml = (l: WorkLine): Html => | |
| 215 | html`${l.says}${l.change === undefined ? null : html` <a href="${l.change.href}">${l.change.words}</a>`}${l.wall === undefined ? null : wallAnswers(l.wall)}`; | |
| 216 | ||
| 217 | /** "Allow it" and "Send it back", each its own form: the answer is in the form, never a query. */ | |
| 218 | const wallAnswers = (w: { readonly repo: string; readonly number: number }): Html => { | |
| 219 | const form = (answer: "allow" | "send_back", words: string, variant: "primary" | "ghost") => | |
| 220 | html`<form method="post" action="/talk/wall" class="inline-form"> | |
| 221 | <input type="hidden" name="repo" value="${w.repo}" /><input type="hidden" name="number" value="${String(w.number)}" /><input type="hidden" name="answer" value="${answer}" /> | |
| 222 | ${btn(words, { size: "sm", variant })} | |
| 223 | </form>`; | |
| 224 | return html`<span class="bar mt" data-wall-answers>${form("allow", "Allow it", "primary")}${form("send_back", "Send it back", "ghost")}</span>`; | |
| 225 | }; |
test/conversation-ask.test.ts +2
| @@ -480,6 +480,8 @@ const SAID: readonly (readonly [string, Record<string, unknown>, string])[] = [ | ||
| 480 | 480 | ], |
| 481 | 481 | ["invite", { repo: "marin/cakes", who: "ben" }, "Make ben a contributor on marin/cakes: they can open the app and ask the crew for changes; they cannot merge or change settings."], |
| 482 | 482 | ["invite", { repo: "marin/cakes", who: "ben", remove: true }, "Take ben off marin/cakes: they can no longer open it, its app or ask its crew."], |
| 483 | ["wall", { repo: "marin/cakes", number: 2, answer: "allow" }, "Allow pull #2 in marin/cakes at the access wall and merge it."], | |
| 484 | ["wall", { repo: "marin/cakes", number: 2, answer: "send_back" }, "Send pull #2 in marin/cakes back at the access wall."], | |
| 483 | 485 | [ |
| 484 | 486 | "pinned_forge", |
| 485 | 487 | { verb: "deploy", name: "shop", target: "hetzner" }, |
test/crew-draft.test.ts +2 −1
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | * forge that stops never leaves it locked, and the repository's admin can mark it ready by hand. |
| 9 | 9 | * Any other build is as before: its early pull is checked from its first push. |
| 10 | 10 | */ |
| 11 | import { mergeFailure } from "../src/actions/merge_words.ts"; | |
| 11 | 12 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; |
| 12 | 13 | import type { App } from "../src/app.ts"; |
| 13 | 14 | import { openIssue } from "../src/actions/issues.ts"; |
| @@ -47,7 +48,7 @@ import { sendToReview } from "../src/crew/review.ts"; | ||
| 47 | 48 | import { seatAs } from "./helpers/seat.ts"; |
| 48 | 49 | import { createSession } from "../src/core/sessions.ts"; |
| 49 | 50 | import { createToken } from "../src/core/tokens.ts"; |
| 50 | import { mergeFailure } from "../src/web/pages/pull.ts"; | |
| 51 | ||
| 51 | 52 | import { errorText } from "../src/tui/screens/common.ts"; |
| 52 | 53 | import { resolveOid } from "../src/git/merge.ts"; |
| 53 | 54 | import { repoDir } from "../src/git/repos.ts"; |
test/landing-doors-review.test.ts +2
| @@ -63,6 +63,8 @@ const DOORS: readonly Door[] = [ | ||
| 63 | 63 | { name: "API merge", sites: ["src/http/api/pulls.ts:mergePull"], route: "post /api/v1/repos/{owner}/{name}/pulls/{number}/merge", way: { http: "api-merge" } }, |
| 64 | 64 | { name: "API slices", sites: ["src/http/api/pulls.ts:landSlice"], route: "post /api/v1/repos/{owner}/{name}/pulls/{number}/slices", way: { http: "api-slices" } }, |
| 65 | 65 | { name: "MCP merge", sites: ["src/http/mcp/tools/merge.ts:mergePull"], tool: "merge", way: { http: "mcp-merge" } }, |
| 66 | // Allow at the access wall (`answerWall`): the page's merge, from Talk's `wall` and the terminal. | |
| 67 | { name: "the access wall's Allow it", sites: ["src/actions/pulls.ts:mergePull"], way: { action: "mergePull" } }, | |
| 66 | 68 | { name: "MCP land_past_gate", sites: ["src/http/mcp/tools/land_past_gate.ts:landPastGate"], tool: "land_past_gate", way: { action: "mergePull", opts: { pastGate: true } } }, |
| 67 | 69 | { name: "web Merge button", sites: ["src/web/pages/pull.ts:mergePull"], way: { action: "mergePull" } }, |
| 68 | 70 | { name: "web Land slice", sites: ["src/web/pages/pull.ts:landSlice"], way: { action: "landSlice" } }, |
test/mcp-forge-protocol.test.ts +1
| @@ -192,6 +192,7 @@ describe("the forge over MCP: protocol", () => { | ||
| 192 | 192 | "branches", |
| 193 | 193 | "builds", |
| 194 | 194 | "commits", |
| 195 | "wall", | |
| 195 | 196 | "waves", |
| 196 | 197 | "probe", |
| 197 | 198 | "following", |
test/mcp-talk-tools.test.ts +1
| @@ -284,6 +284,7 @@ describe("every write Talk's agent is newly listed is held after it reads someon | ||
| 284 | 284 | close: { repo: "alice/hostile", number: 1 }, |
| 285 | 285 | edit: { repo: "alice/hostile", number: 1, title: "pwned" }, |
| 286 | 286 | invite: { repo: "alice/hostile", who: "mallory" }, |
| 287 | wall: { repo: "alice/hostile", number: 2, answer: "allow" }, | |
| 287 | 288 | keep_plan: { repo: "alice/hostile", number: 1, items: ["pwned"] }, |
| 288 | 289 | labels: { repo: "alice/hostile", number: 1, labels: ["pwned"] }, |
| 289 | 290 | merge: { repo: "alice/hostile", number: 2, dryRun: false }, |
test/merge-stale-green.test.ts +2 −1
| @@ -1,3 +1,4 @@ | ||
| 1 | import { mergeFailure } from "../src/actions/merge_words.ts"; | |
| 1 | 2 | import { afterAll, beforeAll, expect, test } from "bun:test"; |
| 2 | 3 | import { mkdtemp, rm } from "node:fs/promises"; |
| 3 | 4 | import { tmpdir } from "node:os"; |
| @@ -13,7 +14,7 @@ import { getRepo } from "../src/core/repos.ts"; | ||
| 13 | 14 | import { getUserByName } from "../src/core/users.ts"; |
| 14 | 15 | import { mergeable } from "../src/git/merge.ts"; |
| 15 | 16 | import { errorText } from "../src/tui/screens/common.ts"; |
| 16 | import { mergeFailure } from "../src/web/pages/pull.ts"; | |
| 17 | ||
| 17 | 18 | import { CHECK_STALE_REFUSAL } from "../src/checks/stale.ts"; |
| 18 | 19 | import { repoDir } from "../src/git/repos.ts"; |
| 19 | 20 |
test/mirror-words.test.ts +3 −3
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * A mirror's "do it there" sentence is said from one module (#5591): the |
| 3 | * issue teams action and the thread page import it, and neither types a | |
| 4 | * copy of it back. | |
| 3 | * issue teams action and the origin refusals the thread page says | |
| 4 | * (`merge_words.ts`) import it, and neither types a copy of it back. | |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | import { describe, expect, test } from "bun:test"; |
| @@ -9,7 +9,7 @@ import { readFileSync } from "node:fs"; | ||
| 9 | 9 | import { join } from "node:path"; |
| 10 | 10 | import * as words from "../src/actions/mirror_words.ts"; |
| 11 | 11 | |
| 12 | const READERS = ["src/actions/issue_teams.ts", "src/web/pages/thread.ts"]; | |
| 12 | const READERS = ["src/actions/issue_teams.ts", "src/actions/merge_words.ts"]; | |
| 13 | 13 | |
| 14 | 14 | describe("a mirror's words live in one module", () => { |
| 15 | 15 | const sentences = Object.entries(words); |
test/talk-live-pane-fenced.test.ts +1 −1
| @@ -187,7 +187,7 @@ test("new_app through /mcp, the owner's turns stored: the pane opens on the queu | ||
| 187 | 187 | if (repo === undefined || issue === undefined) |
| 188 | 188 | throw new Error("the app and its first issue"); |
| 189 | 189 | const line = (html: string): string => |
| 190 | /id="w-[^"]+"[^>]*>([\s\S]*?)<\/p>/ | |
| 190 | /id="w-[^"]+"[^>]*>([\s\S]*?)<\/div>/ | |
| 191 | 191 | .exec(html)?.[1] |
| 192 | 192 | ?.replace(/<[^>]+>/g, "") |
| 193 | 193 | .trim() ?? ""; |
test/talk-receipt-live.test.ts +1 −1
| @@ -171,7 +171,7 @@ test("the page draws the receipt with its live line and Reply; the line's fragme | ||
| 171 | 171 | const page = await (await get("/talk", alice)).text(); |
| 172 | 172 | expect(page).toMatch(/<li class="talk-turn talk-receipt" id="t-[0-9a-z]+" data-done>/); |
| 173 | 173 | expect(page).toMatch( |
| 174 | /<p class="talk-work-line small muted" id="w-[0-9a-z]+" data-live="run\.\*,issue\.\*,pull\.\*,comment\.\*" data-live-repo="alice\/secret" data-live-src="\/live\/talk-work\?href=%2Falice%2Fsecret%2Fissues%2F1&id=w-[0-9a-z]+">The crew landed #2\.<\/p>/, | |
| 174 | /<div class="talk-work-line small muted" id="w-[0-9a-z]+" data-live="run\.\*,issue\.\*,pull\.\*,comment\.\*" data-live-repo="alice\/secret" data-live-src="\/live\/talk-work\?href=%2Falice%2Fsecret%2Fissues%2F1&id=w-[0-9a-z]+">The crew landed #2\.<\/div>/, | |
| 175 | 175 | ); |
| 176 | 176 | expect(page).toContain( |
| 177 | 177 | 'href="/alice/secret/issues/1#comment-body" data-reply="/alice/secret/issues/1" data-reply-to="alice/secret#1"', |
test/talk-wall-says.test.ts added +441
| @@ -0,0 +1,441 @@ | ||
| 1 | /** | |
| 2 | * The access wall in Talk (#7847, the owner's counter app on 2026-11-25: its first pull opened its | |
| 3 | * records to anyone signed out, the wall held it, and the receipt said only "ready: waiting for you | |
| 4 | * to land it"). The wall stays; what it asks is said where the person is, once, with two real | |
| 5 | * answers: the receipt's line says the wall's words and offers "Allow it" and "Send it back" as | |
| 6 | * forms on Talk's own page (`/talk/wall`), and as keys in the terminal; Talk's agent can put the | |
| 7 | * same decision as a held confirm in the wall's words; and a tell's status names it, so the | |
| 8 | * agent's reply does too. Every door answers through `answerWall`, which is the pull page's merge | |
| 9 | * and its request for changes. Nothing the person may not read is ever named. | |
| 10 | */ | |
| 11 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 12 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 13 | import { tmpdir } from "node:os"; | |
| 14 | import { join } from "node:path"; | |
| 15 | import { editFiles } from "../src/actions/contents.ts"; | |
| 16 | import { | |
| 17 | sayYes, | |
| 18 | waitingConfirms, | |
| 19 | } from "../src/actions/conversation_confirms.ts"; | |
| 20 | import { createRepo } from "../src/actions/repos.ts"; | |
| 21 | import { createApp, type App } from "../src/app.ts"; | |
| 22 | import { | |
| 23 | appendTurn, | |
| 24 | createConversation, | |
| 25 | listTurns, | |
| 26 | } from "../src/core/conversations.ts"; | |
| 27 | import { recordDecision } from "../src/core/decisions.ts"; | |
| 28 | import { createIssue, type Issue } from "../src/core/issues.ts"; | |
| 29 | import { getPull, type Pull } from "../src/core/pulls.ts"; | |
| 30 | import type { Repo } from "../src/core/repos.ts"; | |
| 31 | import { reviewSummary } from "../src/core/reviews.ts"; | |
| 32 | import { createRun, finishRun } from "../src/core/runs.ts"; | |
| 33 | import { createSession } from "../src/core/sessions.ts"; | |
| 34 | import { workLineFor } from "../src/core/talk_work.ts"; | |
| 35 | import { createToken } from "../src/core/tokens.ts"; | |
| 36 | import { createUser, type User } from "../src/core/users.ts"; | |
| 37 | import { mintViaToken } from "../src/core/via_token.ts"; | |
| 38 | import type { Ctx } from "../src/http/context.ts"; | |
| 39 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 40 | import { tellStatusFields } from "../src/runs/tell_status.ts"; | |
| 41 | import { createForgeApp } from "../src/tui/forge.ts"; | |
| 42 | import { talkChatsScreen } from "../src/tui/screens/talk_chats.ts"; | |
| 43 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; | |
| 44 | import { wallCard } from "../src/web/studio/change.ts"; | |
| 45 | import { workLineHtml } from "../src/web/talk_peek.ts"; | |
| 46 | import { promote } from "./helpers/members.ts"; | |
| 47 | import { settleApp } from "./helpers/tui.ts"; | |
| 48 | import { pollUntil } from "./helpers/poll.ts"; | |
| 49 | ||
| 50 | const OPENS = [ | |
| 51 | "anyone signed out could read counter records", | |
| 52 | "anyone signed out could list counter records", | |
| 53 | ]; | |
| 54 | /** What only the owner of a private repository may read: never in another person's confirm. */ | |
| 55 | const SECRET = ["anyone signed out could read zqx-ledger records"]; | |
| 56 | ||
| 57 | let dir: string; | |
| 58 | let app: App; | |
| 59 | let servers: Servers; | |
| 60 | let alice: User; | |
| 61 | let bob: User; | |
| 62 | let carol: User; | |
| 63 | let repo: Repo; | |
| 64 | let vault: Repo; | |
| 65 | let issue: Issue; | |
| 66 | let id = 1; | |
| 67 | ||
| 68 | const person = async (username: string, first = false): Promise<User> => { | |
| 69 | const made = await createUser(app.db, { | |
| 70 | origin: "seed", | |
| 71 | trusted: true, | |
| 72 | username, | |
| 73 | email: `${username}@forge.local`, | |
| 74 | password: "a-good-passphrase", | |
| 75 | adminIfFirst: first, | |
| 76 | }); | |
| 77 | if (!made.ok) throw new Error(made.error); | |
| 78 | promote(app.db, made.value); | |
| 79 | return made.value; | |
| 80 | }; | |
| 81 | /** A pull on `branch` the access wall holds on its head, as the crew's land sweep records it. */ | |
| 82 | const wallPull = async ( | |
| 83 | on: Repo, | |
| 84 | branch: string, | |
| 85 | opens: readonly string[], | |
| 86 | body = "", | |
| 87 | ): Promise<Pull> => { | |
| 88 | const opened = await editFiles(app, alice, on, { | |
| 89 | newBranch: branch, | |
| 90 | message: `Open ${branch}`, | |
| 91 | files: [ | |
| 92 | { | |
| 93 | path: `${branch.replaceAll("/", "-")}.json`, | |
| 94 | content: '{"counter":{"read":"anon"}}\n', | |
| 95 | }, | |
| 96 | ], | |
| 97 | openPull: { title: `Open ${branch}`, body }, | |
| 98 | }); | |
| 99 | if (!opened.ok) throw new Error(JSON.stringify(opened.error)); | |
| 100 | const pull = getPull(app.db, on.id, opened.value.pull!.number)!; | |
| 101 | recordDecision(app.db, { | |
| 102 | kind: "land", | |
| 103 | repoId: on.id, | |
| 104 | issueId: pull.id, | |
| 105 | state: { head: pull.headOid, plain: [...opens] }, | |
| 106 | answer: "wall", | |
| 107 | p: 1, | |
| 108 | by: "rule", | |
| 109 | ms: 0, | |
| 110 | }); | |
| 111 | return pull; | |
| 112 | }; | |
| 113 | const mcp = async ( | |
| 114 | token: string, | |
| 115 | name: string, | |
| 116 | args: Record<string, unknown>, | |
| 117 | ): Promise<string> => { | |
| 118 | const res = await fetch(`${servers.url}/mcp`, { | |
| 119 | method: "POST", | |
| 120 | headers: { | |
| 121 | authorization: `Bearer ${token}`, | |
| 122 | "content-type": "application/json", | |
| 123 | accept: "application/json, text/event-stream", | |
| 124 | }, | |
| 125 | body: JSON.stringify({ | |
| 126 | jsonrpc: "2.0", | |
| 127 | id: id++, | |
| 128 | method: "tools/call", | |
| 129 | params: { name, arguments: args }, | |
| 130 | }), | |
| 131 | }); | |
| 132 | return JSON.stringify(await res.json()); | |
| 133 | }; | |
| 134 | const token = (u: User) => createToken(app.db, u.id, "t", "rw").token; | |
| 135 | /** Talk's token for a new conversation of `u`'s, as the forge mints one for a turn. */ | |
| 136 | const talkOf = (u: User, words: string) => { | |
| 137 | const c = createConversation(app.db, u.id); | |
| 138 | if (!c.ok) throw new Error(c.error); | |
| 139 | appendTurn(app.db, u.id, c.value.id, { role: "person", text: words }); | |
| 140 | const minted = mintViaToken( | |
| 141 | app.db, | |
| 142 | u.id, | |
| 143 | `conversation:${c.value.id}`, | |
| 144 | words, | |
| 145 | new Date(Date.now() + 600_000).toISOString(), | |
| 146 | ); | |
| 147 | if (!minted.ok) throw new Error(minted.error); | |
| 148 | return { conversation: c.value.id, token: minted.value.token }; | |
| 149 | }; | |
| 150 | const confirmOf = (u: User, conversation: string): string | undefined => { | |
| 151 | const turns = listTurns(app.db, u.id, conversation, { limit: 20 }); | |
| 152 | const t = turns.ok | |
| 153 | ? turns.value.find((x) => x.role === "confirm") | |
| 154 | : undefined; | |
| 155 | return t === undefined | |
| 156 | ? undefined | |
| 157 | : (JSON.parse(t.text) as { does: string }).does; | |
| 158 | }; | |
| 159 | const merged = (p: Pull) => | |
| 160 | getPull(app.db, p.repoId, p.number)!.mergedAt !== null; | |
| 161 | ||
| 162 | beforeAll(async () => { | |
| 163 | dir = await mkdtemp(join(tmpdir(), "forge-wall-says-")); | |
| 164 | app = createApp({ dataDir: dir, port: 0 }); | |
| 165 | servers = await serve(app); | |
| 166 | alice = await person("alice", true); | |
| 167 | bob = await person("bob"); | |
| 168 | carol = await person("carol"); | |
| 169 | const made = await createRepo(app, alice, { | |
| 170 | name: "counter", | |
| 171 | visibility: "public", | |
| 172 | }); | |
| 173 | const kept = await createRepo(app, alice, { | |
| 174 | name: "ledger", | |
| 175 | visibility: "private", | |
| 176 | }); | |
| 177 | if (!made.ok || !kept.ok) throw new Error("repo"); | |
| 178 | repo = made.value; | |
| 179 | vault = kept.value; | |
| 180 | for (const r of [repo, vault]) { | |
| 181 | const seeded = await editFiles(app, alice, r, { | |
| 182 | message: "Start", | |
| 183 | files: [{ path: "README.md", content: "# start\n" }], | |
| 184 | }); | |
| 185 | if (!seeded.ok) throw new Error(JSON.stringify(seeded.error)); | |
| 186 | } | |
| 187 | const asked = createIssue(app.db, { | |
| 188 | repoId: repo.id, | |
| 189 | authorId: alice.id, | |
| 190 | title: "Build counter", | |
| 191 | body: "One shared number.", | |
| 192 | }); | |
| 193 | if (!asked.ok) throw new Error(asked.error); | |
| 194 | issue = asked.value; | |
| 195 | }, 30_000); | |
| 196 | afterAll(async () => { | |
| 197 | servers.stop(); | |
| 198 | app.close(); | |
| 199 | await rm(dir, { recursive: true, force: true }); | |
| 200 | }); | |
| 201 | ||
| 202 | describe("the access wall, said where the person is", () => { | |
| 203 | test("the receipt's line says the wall's words once and offers two real answers, forms on Talk's own page; a reader gets the reason alone", async () => { | |
| 204 | const pull = await wallPull( | |
| 205 | repo, | |
| 206 | "crew/counter", | |
| 207 | OPENS, | |
| 208 | `Closes #${issue.number}`, | |
| 209 | ); | |
| 210 | const run = createRun(app.db, { | |
| 211 | repoId: repo.id, | |
| 212 | kind: "agent", | |
| 213 | issueId: issue.id, | |
| 214 | reason: "assigned", | |
| 215 | branch: "crew/counter", | |
| 216 | }); | |
| 217 | finishRun(app.db, run.id, { | |
| 218 | state: "ok", | |
| 219 | summary: `opened pull #${pull.number}`, | |
| 220 | }); | |
| 221 | const line = workLineFor(app.db, dir, issue, Date.now(), alice); | |
| 222 | expect(line.says).toBe( | |
| 223 | `The crew pushed #${pull.number}. The access wall holds it for you to decide: ${OPENS.join("; ")}.`, | |
| 224 | ); | |
| 225 | expect(line.wall).toEqual({ repo: "alice/counter", number: pull.number }); | |
| 226 | const html = workLineHtml(line).text; | |
| 227 | expect(html).not.toContain("waiting for you to land it"); | |
| 228 | // Two forms, each its own answer, posting to Talk: never two links to the same place. | |
outdated
The test name claims an agent is refused, but only a person's send_back is run. Cover the agent refusal, a non-writer, no_wall, and Allow merging. |
||
| 229 | const forms = [ | |
| 230 | ...html.matchAll( | |
| 231 | /<form method="post" action="\/talk\/wall"[\s\S]*?<\/form>/g, | |
| 232 | ), | |
| 233 | ].map((m) => m[0]); | |
| 234 | expect(forms.length).toBe(2); | |
| 235 | expect(forms[0]).toContain('name="answer" value="allow"'); | |
| 236 | expect(forms[0]).toContain("Allow it"); | |
| 237 | expect(forms[1]).toContain('name="answer" value="send_back"'); | |
| 238 | expect(forms[1]).toContain("Send it back"); | |
| 239 | expect(html).not.toContain('<a href="/alice/counter/pulls'); | |
| 240 | const read = workLineFor(app.db, dir, issue, Date.now(), bob); | |
| 241 | expect([read.says, read.wall]).toEqual([line.says, undefined]); | |
| 242 | // The pull page's card is where the terminal's address lands. | |
| 243 | expect( | |
| 244 | wallCard( | |
| 245 | { loosened: [], unsound: ["contract.json does not read"] }, | |
| 246 | "/alice/counter/pulls/1", | |
| 247 | ).text, | |
| 248 | ).toContain('id="wall"'); | |
| 249 | // A tell's status names it, so the agent's reply does. | |
| 250 | const status = tellStatusFields(app.db, repo.id, issue); | |
| 251 | expect(status.wall).toEqual(OPENS); | |
| 252 | expect(status.says).toContain( | |
| 253 | `it would open this: ${OPENS.join("; ")}. That is theirs to allow or send back`, | |
| 254 | ); | |
| 255 | }); | |
| 256 | ||
| 257 | test("Talk's own form answers it: Send it back is the page's request for changes; a cross-origin post does nothing", async () => { | |
| 258 | const pull = await wallPull(repo, "crew/form", OPENS); | |
| 259 | const post = (origin: string) => | |
| 260 | fetch(`${servers.url}/talk/wall`, { | |
| 261 | method: "POST", | |
| 262 | redirect: "manual", | |
| 263 | headers: { | |
| 264 | cookie: `forge_session=${createSession(app.db, alice.id).token}`, | |
| 265 | origin, | |
| 266 | "content-type": "application/x-www-form-urlencoded", | |
| 267 | }, | |
| 268 | body: new URLSearchParams({ | |
| 269 | repo: "alice/counter", | |
| 270 | number: String(pull.number), | |
| 271 | answer: "send_back", | |
| 272 | }).toString(), | |
| 273 | }); | |
| 274 | expect((await post("https://evil.example")).status).not.toBe(303); | |
| 275 | expect(reviewSummary(app.db, pull.id, pull.headOid).changesRequested).toBe( | |
| 276 | 0, | |
| 277 | ); | |
| 278 | expect((await post(servers.url)).status).toBe(303); | |
| 279 | expect(reviewSummary(app.db, pull.id, pull.headOid).changesRequested).toBe( | |
| 280 | 1, | |
| 281 | ); | |
| 282 | expect(merged(pull)).toBe(false); | |
| 283 | }); | |
| 284 | ||
| 285 | test("Talk's agent puts the decision as a held confirm in the wall's own words; the person's yes allows it and it merges", async () => { | |
| 286 | const pull = await wallPull(repo, "crew/held", OPENS); | |
| 287 | const talk = talkOf(alice, "what is waiting?"); | |
| 288 | expect( | |
| 289 | await mcp(talk.token, "wall", { | |
| 290 | repo: "alice/counter", | |
| 291 | number: pull.number, | |
| 292 | answer: "allow", | |
| 293 | }), | |
| 294 | ).toContain("needs_confirm"); | |
| 295 | expect(confirmOf(alice, talk.conversation)).toBe( | |
| 296 | `Allow it and merge pull #${pull.number} in alice/counter: ${OPENS.join("; ")}.`, | |
| 297 | ); | |
| 298 | expect(merged(pull)).toBe(false); | |
| 299 | const held = waitingConfirms({ app } as Ctx, alice).find( | |
| 300 | (w) => w.tool === "wall", | |
| 301 | )!; | |
| 302 | const yes = await sayYes( | |
| 303 | { app, url: new URL(servers.url) } as Ctx, | |
| 304 | alice, | |
| 305 | held.id, | |
| 306 | ); | |
| 307 | expect(yes.ok).toBe(true); | |
| 308 | expect(merged(pull)).toBe(true); | |
| 309 | }); | |
| 310 | ||
| 311 | test("a confirm never names what the person may not read: a private repository's pull says nothing of its wall", async () => { | |
| 312 | const hidden = await wallPull(vault, "crew/ledger", SECRET); | |
| 313 | const talk = talkOf(carol, "allow it"); | |
| 314 | await mcp(talk.token, "wall", { | |
| 315 | repo: "alice/ledger", | |
| 316 | number: hidden.number, | |
| 317 | answer: "allow", | |
| 318 | }); | |
| 319 | expect(confirmOf(carol, talk.conversation) ?? "").not.toContain( | |
| 320 | "zqx-ledger", | |
| 321 | ); | |
| 322 | expect(merged(hidden)).toBe(false); | |
| 323 | }); | |
| 324 | ||
| 325 | test("only a person who writes answers it: an agent is refused, a reader is refused, and a pull the wall does not hold has nothing to answer", async () => { | |
| 326 | const pull = await wallPull(repo, "crew/refused", OPENS); | |
| 327 | const agent = await createUser(app.db, { | |
| 328 | username: "builder", | |
| 329 | email: "[email protected]", | |
| 330 | agent: true, | |
| 331 | origin: "agent", | |
| 332 | }); | |
| 333 | if (!agent.ok) throw new Error(agent.error); | |
| 334 | expect( | |
| 335 | await mcp(token(agent.value), "wall", { | |
| 336 | repo: "alice/counter", | |
| 337 | number: pull.number, | |
| 338 | answer: "allow", | |
| 339 | }), | |
| 340 | ).toContain("never an agent"); | |
| 341 | expect( | |
| 342 | await mcp(token(bob), "wall", { | |
| 343 | repo: "alice/counter", | |
| 344 | number: pull.number, | |
| 345 | answer: "allow", | |
| 346 | }), | |
| 347 | ).toContain("You do not have write access"); | |
| 348 | expect(merged(pull)).toBe(false); | |
| 349 | const plain = await editFiles(app, alice, repo, { | |
| 350 | newBranch: "plain", | |
| 351 | message: "Plain", | |
| 352 | files: [{ path: "plain.txt", content: "x\n" }], | |
| 353 | openPull: { title: "Plain", body: "" }, | |
| 354 | }); | |
| 355 | if (!plain.ok) throw new Error(JSON.stringify(plain.error)); | |
| 356 | expect( | |
| 357 | await mcp(token(alice), "wall", { | |
| 358 | repo: "alice/counter", | |
| 359 | number: plain.value.pull!.number, | |
| 360 | answer: "allow", | |
| 361 | }), | |
| 362 | ).toContain("there is nothing to answer"); | |
| 363 | }); | |
| 364 | ||
| 365 | test("the terminal answers it by a key: A allows it after a confirm, and it lands", async () => { | |
| 366 | const pull = await wallPull(repo, "crew/counter-2", OPENS); | |
| 367 | const told = createIssue(app.db, { | |
| 368 | repoId: repo.id, | |
| 369 | authorId: alice.id, | |
| 370 | title: "Build counter again", | |
| 371 | body: "b", | |
| 372 | }); | |
| 373 | if (!told.ok) throw new Error(told.error); | |
| 374 | const run = createRun(app.db, { | |
| 375 | repoId: repo.id, | |
| 376 | kind: "agent", | |
| 377 | issueId: told.value.id, | |
| 378 | reason: "assigned", | |
| 379 | branch: "crew/counter-2", | |
| 380 | }); | |
| 381 | finishRun(app.db, run.id, { | |
| 382 | state: "ok", | |
| 383 | summary: `opened pull #${pull.number}`, | |
| 384 | }); | |
| 385 | const c = createConversation(app.db, alice.id); | |
| 386 | if (!c.ok) throw new Error(c.error); | |
| 387 | appendTurn(app.db, alice.id, c.value.id, { | |
| 388 | role: "person", | |
| 389 | text: "build a counter", | |
| 390 | }); | |
| 391 | appendTurn(app.db, alice.id, c.value.id, { | |
| 392 | role: "tool", | |
| 393 | text: JSON.stringify({ | |
| 394 | done: true, | |
| 395 | title: "Build counter again", | |
| 396 | receipt: { | |
| 397 | verb: "Filed", | |
| 398 | object: `alice/counter#${told.value.number}`, | |
| 399 | href: `/alice/counter/issues/${told.value.number}`, | |
| 400 | }, | |
| 401 | }), | |
| 402 | }); | |
| 403 | const terminal = headlessTerminal(160, 44); | |
| 404 | const { app: tui, session } = createForgeApp( | |
| 405 | app, | |
| 406 | { | |
| 407 | sshUsername: "alice", | |
| 408 | remoteAddress: "127.0.0.1", | |
| 409 | fingerprint: "SHA256:t", | |
| 410 | user: alice, | |
| 411 | }, | |
| 412 | { terminal, exitHooks: false }, | |
| 413 | ); | |
| 414 | tui.start(); | |
| 415 | await settleApp(tui); | |
| 416 | tui.ctx.push(talkChatsScreen(session, tui.ctx)); | |
| 417 | await settleApp(tui); | |
| 418 | terminal.feed("\r"); | |
| 419 | await settleApp(tui); | |
| 420 | expect(tui.screen.toText()).toContain( | |
| 421 | "The access wall holds it for you to decide", | |
| 422 | ); | |
| 423 | expect(tui.screen.toText()).toContain("A: allow it · S: send it back"); | |
| 424 | terminal.feed("A"); | |
| 425 | await settleApp(tui); | |
| 426 | expect(tui.screen.toText()).toContain( | |
| 427 | `Allow it and merge #${pull.number}.`, | |
| 428 | ); | |
| 429 | terminal.feed("\x1b[C"); | |
| 430 | terminal.feed("\r"); | |
| 431 | await pollUntil( | |
| 432 | async () => { | |
| 433 | await settleApp(tui); | |
| 434 | return merged(pull); | |
| 435 | }, | |
| 436 | "the wall's Allow it merges the pull", | |
| 437 | ); | |
| 438 | tui.stop?.(); | |
| 439 | expect(merged(pull)).toBe(true); | |
| 440 | }, 30_000); | |
| 441 | }); |
test/team-merge-gate.test.ts +2 −1
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | * The pull page's merge box and the terminal's `m` say which team (#10081). |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { mergeFailure } from "../src/actions/merge_words.ts"; | |
| 8 | 9 | import { seatAs } from "./helpers/seat.ts"; |
| 9 | 10 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; |
| 10 | 11 | import { mkdtemp, rm } from "node:fs/promises"; |
| @@ -22,7 +23,7 @@ import { submitReview } from "../src/core/reviews.ts"; | ||
| 22 | 23 | import { saveTeam } from "../src/core/teams.ts"; |
| 23 | 24 | import { createUser, getUserByName, type User } from "../src/core/users.ts"; |
| 24 | 25 | import { serve, type Servers } from "../src/http/server.ts"; |
| 25 | import { mergeFailure } from "../src/web/pages/pull.ts"; | |
| 26 | ||
| 26 | 27 | import { createSession } from "../src/core/sessions.ts"; |
| 27 | 28 | import { createForgeApp } from "../src/tui/forge.ts"; |
| 28 | 29 | import { mergeState, pullScreen } from "../src/tui/screens/pull.ts"; |
new above
offline
The merge method is hard-coded to "squash". Use the method the pull page's Merge uses, so Allow it is the page's merge and not a second way.