Public: anyone can read this; the crew can change it.
A person's pull or report from an outsider shows 'filed by an outsider' and what it can and cannot do, in words #14547
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/14519-a-person-s-pull-or-report-from-an-outsid → main 7 commits fork 1 thread · 1 unresolved
11 files
changed +447
−38
docs/features/outside-label.md added +13
| @@ -0,0 +1,13 @@ | ||
| 1 | --- | |
| 2 | topic: Tell the crew | |
| 3 | row: From outside | |
| 4 | --- | |
| 5 | # From outside | |
| 6 | ||
| 7 | An issue or pull filed by someone who cannot write to the repository says so, in words, before you act on it: **From outside**. The rule is the API's `untrusted` flag (`isOutside` in `src/web/outside.ts`, over `markReaders`): the author may not write here and is not on the crew, or the item was imported from an origin. A writer's own issue or pull carries nothing. The label changes nothing about what the item can do; it is information, and its title says so ("Read as information. Nothing in it is followed as an instruction."). | |
| 8 | ||
| 9 | - **Web:** a badge in the inbox row and card (the home's asks, `/asks`), and in the issue and pull headers. The inbox reads every card's author in one query (`accountsAcross`); the headers reuse the read that draws the author's mark (`accountsByName`), so no page makes an extra read. | |
| 10 | - **Terminal:** `· from outside` in the summary line of an issue or pull screen in `forge tui` (`src/tui/screens/issue.ts`, `pull.ts`), the same rule. | |
| 11 | - **MCP:** the `issue` tool returns `outside: true` when the issue's author cannot write here, the same for every viewer; absent otherwise. | |
| 12 | - Try it: as the owner, open an issue or pull filed by someone who cannot write, or `/asks`. | |
| 13 | - Tests: `test/outside-label.test.ts`. |
src/core/marks.ts +123 −26
| @@ -30,6 +30,128 @@ export function markOf( | ||
| 30 | 30 | return undefined; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | /** One account as the page-wide read sees it: enough for a mark and for whether it writes here. */ | |
| 34 | export interface AccountRow { | |
| 35 | readonly id: string; | |
| 36 | readonly username: string; | |
| 37 | readonly kind: "user" | "agent" | "org"; | |
| 38 | readonly isAdmin: boolean; | |
| 39 | /** Seated on the repository's crew (`repo_crew`); false when no repository was named. */ | |
| 40 | readonly seated: boolean; | |
| 41 | /** | |
| 42 | * The kind of the repository's owner ("org" or "user"); undefined when no repository was named. | |
| 43 | */ | |
| 44 | readonly ownerKind: "user" | "org" | undefined; | |
| 45 | } | |
| 46 | ||
| 47 | /** | |
| 48 | * The accounts behind many names, in one read: the mark, and with a | |
| 49 | * repository named, the crew seat and the owner's kind, so a page can tell | |
| 50 | * who writes there without a read per author. | |
| 51 | */ | |
| 52 | export function accountsByName( | |
| 53 | db: Database, | |
| 54 | names: Iterable<string>, | |
| 55 | repoId?: string, | |
| 56 | ): Map<string, AccountRow> { | |
| 57 | const unique = [...new Set(names)].filter((n) => n !== ""); | |
| 58 | const out = new Map<string, AccountRow>(); | |
| 59 | if (unique.length === 0) return out; | |
| 60 | const marks = unique.map((_, i) => `?${i + 2}`).join(", "); | |
| 61 | // The flag, not the column, says agent (`core/users.ts`, migration 14). | |
| 62 | const rows = db | |
| 63 | .query< | |
| 64 | { | |
| 65 | id: string; | |
| 66 | username: string; | |
| 67 | kind: "user" | "org"; | |
| 68 | is_agent: number; | |
| 69 | is_admin: number; | |
| 70 | seated: number; | |
| 71 | owner_kind: "user" | "org" | null; | |
| 72 | }, | |
| 73 | (string | null)[] | |
| 74 | >( | |
| 75 | `SELECT id, username, kind, is_agent, is_admin, | |
| 76 | EXISTS (SELECT 1 FROM repo_crew WHERE repo_id = ?1 AND user_id = user.id) AS seated, | |
| 77 | (SELECT o.kind FROM repo r JOIN user o ON o.id = r.owner_id WHERE r.id = ?1) AS owner_kind | |
| 78 | FROM user WHERE username IN (${marks})`, | |
| 79 | ) | |
| 80 | .all(repoId ?? null, ...unique); | |
| 81 | for (const row of rows) | |
| 82 | out.set(row.username, { | |
| 83 | id: row.id, | |
| 84 | username: row.username, | |
| 85 | kind: row.is_agent === 1 ? "agent" : row.kind, | |
| 86 | isAdmin: row.is_admin === 1, | |
| 87 | seated: row.seated === 1, | |
| 88 | ownerKind: row.owner_kind ?? undefined, | |
| 89 | }); | |
| 90 | return out; | |
| 91 | } | |
| 92 | ||
| 93 | /** | |
| 94 | * The accounts behind many names across many repositories, in one read: a | |
| 95 | * list of cards from several repositories asks once, not once per card. | |
| 96 | * Keyed by repository id, then name. | |
| 97 | */ | |
| 98 | export function accountsAcross( | |
| 99 | db: Database, | |
| 100 | names: Iterable<string>, | |
| 101 | repoIds: Iterable<string>, | |
| 102 | ): Map<string, Map<string, AccountRow>> { | |
| 103 | const ns = [...new Set(names)].filter((n) => n !== ""); | |
| 104 | const rs = [...new Set(repoIds)]; | |
| 105 | const out = new Map<string, Map<string, AccountRow>>(); | |
| 106 | if (ns.length === 0 || rs.length === 0) return out; | |
| 107 | const nm = ns.map((_, i) => `?${i + 1}`).join(", "); | |
| 108 | const rm = rs.map((_, i) => `?${ns.length + i + 1}`).join(", "); | |
| 109 | const rows = db | |
| 110 | .query< | |
| 111 | { | |
| 112 | id: string; | |
| 113 | username: string; | |
| 114 | kind: "user" | "org"; | |
| 115 | is_agent: number; | |
| 116 | is_admin: number; | |
| 117 | repo_id: string; | |
| 118 | seated: number; | |
| 119 | owner_kind: "user" | "org" | null; | |
| 120 | }, | |
| 121 | string[] | |
| 122 | >( | |
| 123 | `SELECT u.id, u.username, u.kind, u.is_agent, u.is_admin, r.id AS repo_id, | |
| 124 | EXISTS (SELECT 1 FROM repo_crew WHERE repo_id = r.id AND user_id = u.id) AS seated, | |
| 125 | (SELECT o.kind FROM user o WHERE o.id = r.owner_id) AS owner_kind | |
| 126 | FROM user u CROSS JOIN repo r | |
| 127 | WHERE u.username IN (${nm}) AND r.id IN (${rm})`, | |
| 128 | ) | |
| 129 | .all(...ns, ...rs); | |
| 130 | for (const row of rows) { | |
| 131 | let per = out.get(row.repo_id); | |
| 132 | if (per === undefined) out.set(row.repo_id, (per = new Map())); | |
| 133 | per.set(row.username, { | |
| 134 | id: row.id, | |
| 135 | username: row.username, | |
| 136 | kind: row.is_agent === 1 ? "agent" : row.kind, | |
| 137 | isAdmin: row.is_admin === 1, | |
| 138 | seated: row.seated === 1, | |
| 139 | ownerKind: row.owner_kind ?? undefined, | |
| 140 | }); | |
| 141 | } | |
| 142 | return out; | |
| 143 | } | |
| 144 | ||
| 145 | /** The marks of accounts already read (`accountsByName`). */ | |
| 146 | export function marksOf(accounts: ReadonlyMap<string, AccountRow>): Map<string, Mark> { | |
| 147 | const out = new Map<string, Mark>(); | |
| 148 | for (const [name, a] of accounts) { | |
| 149 | const mark = markOf(a); | |
| 150 | if (mark !== undefined) out.set(name, mark); | |
| 151 | } | |
| 152 | return out; | |
| 153 | } | |
| 154 | ||
| 33 | 155 | /** |
| 34 | 156 | * The marks of many names in one read: a page asks once for every author it |
| 35 | 157 | * will show. Names that wear none are not in the map. |
| @@ -38,30 +160,5 @@ export function marksByName( | ||
| 38 | 160 | db: Database, |
| 39 | 161 | names: Iterable<string>, |
| 40 | 162 | ): Map<string, Mark> { |
| 41 | const unique = [...new Set(names)].filter((n) => n !== ""); | |
| 42 | const out = new Map<string, Mark>(); | |
| 43 | if (unique.length === 0) return out; | |
| 44 | // The flag, not the column, says agent (`core/users.ts`, migration 14). | |
| 45 | const rows = db | |
| 46 | .query< | |
| 47 | { | |
| 48 | username: string; | |
| 49 | kind: "user" | "org"; | |
| 50 | is_agent: number; | |
| 51 | is_admin: number; | |
| 52 | }, | |
| 53 | string[] | |
| 54 | >( | |
| 55 | `SELECT username, kind, is_agent, is_admin FROM user | |
| 56 | WHERE username IN (${unique.map((_, i) => `?${i + 1}`).join(", ")})`, | |
| 57 | ) | |
| 58 | .all(...unique); | |
| 59 | for (const row of rows) { | |
| 60 | const mark = markOf({ | |
| 61 | kind: row.is_agent === 1 ? "agent" : row.kind, | |
| 62 | isAdmin: row.is_admin === 1, | |
| 63 | }); | |
| 64 | if (mark !== undefined) out.set(row.username, mark); | |
| 65 | } | |
| 66 | return out; | |
| 163 | return marksOf(accountsByName(db, names)); | |
| 67 | 164 | } |
src/http/mcp/tools/issue.ts +7 −2
| @@ -1,3 +1,4 @@ | ||
| 1 | import { isOutside } from "../../../web/outside.ts"; | |
| 1 | 2 | import { mayReadRuns } from "../../../actions/runs.ts"; |
| 2 | 3 | import { costField, issueCostFor } from "../../../core/issue_cost.ts"; |
| 3 | 4 | import { mayView } from "../../../core/sealed.ts"; |
| @@ -12,9 +13,9 @@ import { good, bad, type Tool, REPO_ARG, repoArg, isAnswer } from "../shared.ts" | ||
| 12 | 13 | |
| 13 | 14 | export const tool: Tool = { |
| 14 | 15 | name: "issue", |
| 15 | doc: "`{ repo, number }`: one issue's title, state, closeReason, body, labels, assignee, the newest 50 comments (author, authorIsAgent, body, at), `commentsTotal` and `commentsNext` (older ones: `GET …/comments?cursor=`), `standing` (`{line, ready, before, after, more}`: the sentence saying whether it can start and what holds it now, the chain of what it waits for and what waits for it, each node `{number, title, badge, word, next, quiet, holding}`), blockedBy/blocks and `cost` (`{usd, own, runs, pulls}`, absent when nothing was spent or it is not yours to see), as `GET …/issues/:number`; a sealed one you cannot see is not found; draws the `ui://forge/issue` card: title, state, assignee, labels and what it waits for, never the body or comments", | |
| 16 | doc: "`{ repo, number }`: one issue's title, state, closeReason, body, labels, assignee, `outside: true` when its author cannot write here (an outsider's issue, told the same to every viewer; absent otherwise), the newest 50 comments (author, authorIsAgent, body, at), `commentsTotal` and `commentsNext` (older ones: `GET …/comments?cursor=`), `standing` (`{line, ready, before, after, more}`: the sentence saying whether it can start and what holds it now, the chain of what it waits for and what waits for it, each node `{number, title, badge, word, next, quiet, holding}`), blockedBy/blocks and `cost` (`{usd, own, runs, pulls}`, absent when nothing was spent or it is not yours to see), as `GET …/issues/:number`; a sealed one you cannot see is not found; draws the `ui://forge/issue` card: title, state, assignee, labels and what it waits for, never the body or comments", | |
| 16 | 17 | description: |
| 17 | "One issue with comments, `blockedBy`, `blocks`; non-writers' text is `untrusted`.", | |
| 18 | "One issue with comments, `blockedBy`, `blocks`; non-writers' text is `untrusted`, an outsider's issue `outside`.", | |
| 18 | 19 | inputSchema: { |
| 19 | 20 | type: "object", |
| 20 | 21 | properties: { |
| @@ -61,6 +62,7 @@ export const tool: Tool = { | ||
| 61 | 62 | const flag = (x: { untrusted?: string }) => |
| 62 | 63 | x.untrusted === undefined ? {} : { untrusted: true }; |
| 63 | 64 | const [self] = mark([issue]); |
| 65 | const outside = isOutside(db, repo, issue); | |
| 64 | 66 | const cost = mayReadRuns(ctx.app, user, repo) |
| 65 | 67 | ? costField(issueCostFor(db, repo, issue, user)) |
| 66 | 68 | : undefined; |
| @@ -73,6 +75,9 @@ export const tool: Tool = { | ||
| 73 | 75 | author: issue.authorName, |
| 74 | 76 | authorIsAgent: issue.authorIsAgent, |
| 75 | 77 | ...flag(self!), |
| 78 | // The same rule for every viewer (`isOutside`): the issue itself, never which commenters | |
| 79 | // cannot write. | |
| 80 | ...(outside ? { outside: true } : {}), | |
| 76 | 81 | labels: labelsFor(db, issue.id).map((l) => l.name), |
| 77 | 82 | assignee: issue.assigneeName, |
| 78 | 83 | comments: comments.map((c) => ({ |
src/tui/screens/issue.ts +11 −1
| @@ -14,6 +14,7 @@ | ||
| 14 | 14 | * hook needed. |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | import { outsideClause } from "../../web/outside.ts"; | |
| 17 | 18 | import { putFlowFirst } from "../../actions/flow_first.ts"; |
| 18 | 19 | import { FLOW_LABEL } from "../../core/flow_label.ts"; |
| 19 | 20 | import { |
| @@ -177,6 +178,15 @@ export function issueScreen( | ||
| 177 | 178 | const scroll = new Scroll(); |
| 178 | 179 | const composer = new Composer(); |
| 179 | 180 | const repo = localRepo(src); |
| 181 | // The terminal's "from outside" mark, the web's rule (`isOutside`), read once per author, not per | |
| 182 | // frame. | |
| 183 | const outsideMemo = new Map<string, string>(); | |
| 184 | const outsideOf = (said: { authorName: string; originAuthor: string | null }): string => { | |
| 185 | const key = `${said.authorName}\0${said.originAuthor ?? ""}`; | |
| 186 | let v = outsideMemo.get(key); | |
| 187 | if (v === undefined) outsideMemo.set(key, (v = outsideClause(f.app.db, repo, said))); | |
| 188 | return v; | |
| 189 | }; | |
| 180 | 190 | /** The local row — who it is assigned to. Undefined on a live browse. */ |
| 181 | 191 | let issueRow: Issue | undefined; |
| 182 | 192 | /** The commits the crew found this issue done by on main; `x` closes it. */ |
| @@ -701,7 +711,7 @@ export function issueScreen( | ||
| 701 | 711 | x, |
| 702 | 712 | head!.y + 1, |
| 703 | 713 | truncate( |
| 704 | ` ${issue.state} · opened by ${who(issue.authorName, issue.originAuthor)} ${ago(issue.createdAt)} · ${plural(detail.comments.length, "comment")}${assignedText(issueRow, ctx.icons)}${doneText(doneBy, mayWrite())}${pictureText()}`, | |
| 714 | ` ${issue.state} · opened by ${who(issue.authorName, issue.originAuthor)} ${ago(issue.createdAt)}${outsideOf(issue)} · ${plural(detail.comments.length, "comment")}${assignedText(issueRow, ctx.icons)}${doneText(doneBy, mayWrite())}${pictureText()}`, | |
| 705 | 715 | Math.max(0, right - x), |
| 706 | 716 | ), |
| 707 | 717 | style(c.mutedFg, c.bg), |
src/tui/screens/pull.ts +11 −1
| @@ -26,6 +26,7 @@ | ||
| 26 | 26 | * `n`/`p` walk the unsettled ones while the cursor is inside a thread. |
| 27 | 27 | */ |
| 28 | 28 | |
| 29 | import { outsideClause } from "../../web/outside.ts"; | |
| 29 | 30 | import { teamHoldRefusal, waitingOnTeams } from "../../core/teams_words.ts"; |
| 30 | 31 | import { crewFilters, guardedRefusal, isStrangerPull, strangerGuard, strangerNext } from "../../crew/stranger.ts"; |
| 31 | 32 | import { redMain } from "../../checks/red_main.ts"; |
| @@ -299,6 +300,15 @@ export function pullScreen( | ||
| 299 | 300 | const view = new DiffView(); |
| 300 | 301 | const composer = new Composer(); |
| 301 | 302 | const repo = localRepo(src); |
| 303 | // The terminal's "from outside" mark, the web's rule (`isOutside`), read once per author, not per | |
| 304 | // frame. | |
| 305 | const outsideMemo = new Map<string, string>(); | |
| 306 | const outsideOf = (said: { authorName: string; originAuthor: string | null }): string => { | |
| 307 | const key = `${said.authorName}\0${said.originAuthor ?? ""}`; | |
| 308 | let v = outsideMemo.get(key); | |
| 309 | if (v === undefined) outsideMemo.set(key, (v = outsideClause(f.app.db, repo, said))); | |
| 310 | return v; | |
| 311 | }; | |
| 302 | 312 | /** |
| 303 | 313 | * Whether this repository demands an approval, read on every reload rather |
| 304 | 314 | * than off the row the screen opened with: a `Repo` handed down a stack is |
| @@ -1293,7 +1303,7 @@ export function pullScreen( | ||
| 1293 | 1303 | x1, |
| 1294 | 1304 | head!.y + 1, |
| 1295 | 1305 | truncate( |
| 1296 | ` ${facts?.mergedAt != null ? "merged" : issue.state} · opened by ${who(issue.authorName, issue.originAuthor)} ${ago(issue.createdAt)}${guestWaiting() ? ` · ${isContribHead(facts?.headBranch ?? "") ? OUTSIDE_NOTE : repo !== undefined && crewFilters(repo) ? GUEST_NOTE_FILTERED : GUEST_NOTE}` : ""}${assignedText(issueRow, ctx.icons)}${facts?.proposal ? ` · ${proposedByText(facts.proposal)}` : ""}${facts?.proposal?.attestation ? ` · ${attestationLine(facts.proposal.child, facts.proposal.attestation, facts.proposal.headTree)}` : ""}${hold === undefined ? "" : ` · held by ${hold.heldByName}: ${hold.why}`}${step === null ? "" : ` · step: ${stepLine(step)}`}${landing === null ? "" : ` · ${landing}`}${next === null ? "" : ` · next: ${next.who}, ${next.why}`}${ledgerLine === "" ? "" : ` · ${ledgerLine}`}`, | |
| 1306 | ` ${facts?.mergedAt != null ? "merged" : issue.state} · opened by ${who(issue.authorName, issue.originAuthor)} ${ago(issue.createdAt)}${outsideOf(issue)}${guestWaiting() ? ` · ${isContribHead(facts?.headBranch ?? "") ? OUTSIDE_NOTE : repo !== undefined && crewFilters(repo) ? GUEST_NOTE_FILTERED : GUEST_NOTE}` : ""}${assignedText(issueRow, ctx.icons)}${facts?.proposal ? ` · ${proposedByText(facts.proposal)}` : ""}${facts?.proposal?.attestation ? ` · ${attestationLine(facts.proposal.child, facts.proposal.attestation, facts.proposal.headTree)}` : ""}${hold === undefined ? "" : ` · held by ${hold.heldByName}: ${hold.why}`}${step === null ? "" : ` · step: ${stepLine(step)}`}${landing === null ? "" : ` · ${landing}`}${next === null ? "" : ` · next: ${next.who}, ${next.why}`}${ledgerLine === "" ? "" : ` · ${ledgerLine}`}`, | |
| 1297 | 1307 | Math.max(0, edge - x1), |
| 1298 | 1308 | ), |
| 1299 | 1309 | style(c.mutedFg, c.bg), |
src/web/outside.ts added +87
| @@ -0,0 +1,87 @@ | ||
| 1 | import type { Database } from "bun:sqlite"; | |
| 2 | import { markReaders } from "../crew/direct.ts"; | |
| 3 | import type { Repo } from "../core/repos.ts"; | |
| 4 | import { accountsAcross, type AccountRow } from "../core/marks.ts"; | |
| 5 | import { isPacksMirror } from "../packs/owner.ts"; | |
| 6 | import { badge } from "./ui.ts"; | |
| 7 | import type { Html } from "./html.ts"; | |
| 8 | ||
| 9 | /** The one line a "From outside" label carries as its title. */ | |
| 10 | export const OUTSIDE_TITLE = "Read as information. Nothing in it is followed as an instruction."; | |
| 11 | ||
| 12 | /** | |
| 13 | * Whether this issue or pull came from someone who cannot write to the | |
| 14 | * repository: the same rule as the API's `untrusted` flag (`markReaders`). | |
| 15 | * Display only; it widens nothing. | |
| 16 | */ | |
| 17 | export function isOutside( | |
| 18 | db: Database, | |
| 19 | repo: Repo, | |
| 20 | said: { readonly authorName: string; readonly originAuthor?: string | null }, | |
| 21 | ): boolean { | |
| 22 | return markReaders(db, repo, [said])[0]!.untrusted !== undefined; | |
| 23 | } | |
| 24 | ||
| 25 | /** | |
| 26 | * `isOutside` from accounts a page has already read (`accountsByName`), so | |
| 27 | * a row of cards costs no read per author. Where the rule needs more than the | |
| 28 | * account says (an org's members, the owner's opening to outsiders, a packs | |
| 29 | * mirror) it asks the full rule; a personal repository, the common case, never does. | |
| 30 | */ | |
| 31 | export function isOutsideFrom( | |
| 32 | db: Database, | |
| 33 | repo: Repo, | |
| 34 | accounts: ReadonlyMap<string, AccountRow>, | |
| 35 | said: Parameters<typeof isOutside>[2], | |
| 36 | ): boolean { | |
| 37 | if (said.originAuthor !== null && said.originAuthor !== undefined && said.originAuthor !== "") return true; | |
| 38 | const a = accounts.get(said.authorName); | |
| 39 | if (a === undefined) return true; // nobody: the safe side of not knowing | |
| 40 | if (a.kind === "agent" && a.seated) return false; | |
| 41 | if (a.kind === "org") return true; | |
| 42 | if (isPacksMirror(repo)) return isOutside(db, repo, said); | |
| 43 | if (a.id === repo.ownerId || a.isAdmin) return false; | |
| 44 | if (a.ownerKind === "user" && !repo.crewOutsiders) return true; | |
| 45 | return isOutside(db, repo, said); | |
| 46 | } | |
| 47 | ||
| 48 | /** The label for an author whose account a page has read already. */ | |
| 49 | export function outsideLabelFrom( | |
| 50 | db: Database, | |
| 51 | repo: Repo, | |
| 52 | accounts: ReadonlyMap<string, AccountRow>, | |
| 53 | said: Parameters<typeof isOutside>[2], | |
| 54 | ): Html | null { | |
| 55 | return isOutsideFrom(db, repo, accounts, said) ? outsideBadge() : null; | |
| 56 | } | |
| 57 | ||
| 58 | /** The label itself: the existing badge, with its title. */ | |
| 59 | export function outsideBadge(): Html { | |
| 60 | return badge("From outside", { variant: "outline", title: OUTSIDE_TITLE }); | |
| 61 | } | |
| 62 | ||
| 63 | /** | |
| 64 | * Of many items, across repositories, those filed from outside: one read of | |
| 65 | * the authors for all of them, never one per card. | |
| 66 | */ | |
| 67 | export function outsideSet<K extends object>( | |
| 68 | db: Database, | |
| 69 | items: readonly { readonly key: K; readonly repo: Repo; readonly said: Parameters<typeof isOutside>[2] }[], | |
| 70 | ): K[] { | |
| 71 | const across = accountsAcross( | |
| 72 | db, | |
| 73 | items.map((i) => i.said.authorName), | |
| 74 | items.map((i) => i.repo.id), | |
| 75 | ); | |
| 76 | return items | |
| 77 | .filter((i) => isOutsideFrom(db, i.repo, across.get(i.repo.id) ?? new Map(), i.said)) | |
| 78 | .map((i) => i.key); | |
| 79 | } | |
| 80 | ||
| 81 | /** The terminal's words for the same label: a clause in an issue or pull's summary line. */ | |
| 82 | export const OUTSIDE_WORD = "from outside"; | |
| 83 | ||
| 84 | /** The clause for the terminal's summary line, or "" when the author may write here. */ | |
| 85 | export function outsideClause(db: Database, repo: Repo | undefined, said: Parameters<typeof isOutside>[2]): string { | |
| 86 | return repo !== undefined && isOutside(db, repo, said) ? ` · ${OUTSIDE_WORD}` : ""; | |
| 87 | } |
src/web/studio/asks_page.ts +11 −2
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | * (`actions/asks_bulk.ts`). `/asks` was its own screen; it lands here now. |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | import { outsideBadge, outsideSet } from "../outside.ts"; | |
| 10 | 11 | import { askedAsleep, asleepLine, type Asleep } from "../../actions/needs_asleep.ts"; |
| 11 | 12 | import { UNDO_LABEL, VERB_WORDS } from "../../actions/asks_words.ts"; |
| 12 | 13 | import { notePhase, timePhase } from "../../core/route_timing.ts"; |
| @@ -218,6 +219,9 @@ function proposalBody(ctx: Ctx, d: Decision): Html | null { | ||
| 218 | 219 | </form>`; |
| 219 | 220 | } |
| 220 | 221 | |
| 222 | /** The decisions of the render in hand whose item came from outside, read once for all of them. */ | |
| 223 | const OUTSIDE = new WeakSet<Decision>(); | |
| 224 | ||
| 221 | 225 | function decisionCard(ctx: Ctx, d: Decision, picked: ReadonlySet<string>): Html { |
| 222 | 226 | const base = repoBase(d.repo); |
| 223 | 227 | const title = d.pull |
| @@ -237,7 +241,7 @@ function decisionCard(ctx: Ctx, d: Decision, picked: ReadonlySet<string>): Html | ||
| 237 | 241 | head: html`${pick(d, picked)} |
| 238 | 242 | <h2>${title}</h2> |
| 239 | 243 | <span class="muted small"><b>${KIND_LABEL[d.kind]}</b> · ${d.repo.ownerName}/${d.repo.name}</span |
| 240 | >${waitChip(d.waiting)}`, | |
| 244 | >${OUTSIDE.has(d) ? outsideBadge() : null}${waitChip(d.waiting)}`, | |
| 241 | 245 | }, |
| 242 | 246 | ); |
| 243 | 247 | } |
| @@ -389,7 +393,7 @@ function rowCard(ctx: Ctx, r: AskRow<Decision>, picked: ReadonlySet<string>): Ht | ||
| 389 | 393 | const box = pick(d, picked); |
| 390 | 394 | return row({ |
| 391 | 395 | ...(box === null ? {} : { lead: box }), |
| 392 | title: html`<a href="${href}" data-nav>${d.pull?.title ?? d.issue?.title ?? ""}</a>`, | |
| 396 | title: html`<a href="${href}" data-nav>${d.pull?.title ?? d.issue?.title ?? ""}</a>${OUTSIDE.has(d) ? html` ${outsideBadge()}` : null}`, | |
| 393 | 397 | meta: acts(ctx, d), |
| 394 | 398 | }); |
| 395 | 399 | }); |
| @@ -557,6 +561,11 @@ export function needsYouSection( | ||
| 557 | 561 | const decisions = ctx.request instanceof Request ? timePhase(ctx.request, "asks", read) : read(); |
| 558 | 562 | const needs = forgeNeedsFor(ctx, user); |
| 559 | 563 | const rows = askRows(decisions); |
| 564 | for (const d of outsideSet( | |
| 565 | ctx.app.db, | |
| 566 | decisions.flatMap((d) => (d.pull ?? d.issue ? [{ key: d, repo: d.repo, said: (d.pull ?? d.issue)! }] : [])), | |
| 567 | )) | |
| 568 | OUTSIDE.add(d); | |
| 560 | 569 | const filtered = filterNote(ctx, rows, hidden); |
| 561 | 570 | const silenced = silencedRepos(ctx.app.db, user); |
| 562 | 571 | const silencedNote = |
src/web/studio/change.ts +5 −3
| @@ -16,7 +16,8 @@ import { pullProposalAt, type PullProposalAt } from "../../core/proposal_token.t | ||
| 16 | 16 | import { attestationLine } from "../../core/attestation.ts"; |
| 17 | 17 | import { getIssueById } from "../../core/issues.ts"; |
| 18 | 18 | import { mayEditIssue } from "../../actions/issues.ts"; |
| 19 | import { marksByName, type Mark } from "../../core/marks.ts"; | |
| 19 | import { outsideLabelFrom } from "../outside.ts"; | |
| 20 | import { accountsByName, marksByName, marksOf, type Mark } from "../../core/marks.ts"; | |
| 20 | 21 | import { waitingFor } from "../../core/waiting_for.ts"; |
| 21 | 22 | import { mayView } from "../../core/sealed.ts"; |
| 22 | 23 | import { threadNote } from "../../crew/direct.ts"; |
| @@ -264,7 +265,8 @@ export function changeHead( | ||
| 264 | 265 | ? null |
| 265 | 266 | : stepOfPull(ctx.app.db, repo, pull, live ?? { headOid: pull.headOid, conflicts: 0 }, next); |
| 266 | 267 | const who = toldBy(ctx.app.db, pull); |
| 267 | const marks = marksByName(ctx.app.db, [pull.authorName, who ?? ""]); | |
| 268 | const accounts = accountsByName(ctx.app.db, [pull.authorName, who ?? ""], repo.id); | |
| 269 | const marks = marksOf(accounts); | |
| 268 | 270 | return html`<div class="page-head"> |
| 269 | 271 | <h1>${pull.title} <span class="num">#${pull.number}</span></h1> |
| 270 | 272 | <div class="page-head-sub bar muted small"> |
| @@ -277,7 +279,7 @@ export function changeHead( | ||
| 277 | 279 | ? originTag(pull.originAuthor, originGlyph(repo)) |
| 278 | 280 | : userLink(pull.authorName, { mark: marks.get(pull.authorName) })} |
| 279 | 281 | opened this ${time(pull.createdAt)}</span |
| 280 | >${when( | |
| 282 | >${outsideLabelFrom(ctx.app.db, repo, accounts, pull)}${when( | |
| 281 | 283 | who, |
| 282 | 284 | (name) => |
| 283 | 285 | html`<span class="told-by" |
src/web/studio/tell.ts +5 −2
| @@ -13,7 +13,8 @@ import { costRows, issueCostFor, spentLine, type IssueCost } from "../../core/is | ||
| 13 | 13 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; |
| 14 | 14 | import { cardPath } from "../og/path.ts"; |
| 15 | 15 | import { mayEditIssue } from "../../actions/issues.ts"; |
| 16 | import { marksByName } from "../../core/marks.ts"; | |
| 16 | import { outsideLabelFrom } from "../outside.ts"; | |
| 17 | import { accountsByName, marksOf } from "../../core/marks.ts"; | |
| 17 | 18 | import { TELL_RUNS_SHOWN, tellStatus } from "../../runs/tell_status.ts"; |
| 18 | 19 | import { threadNote } from "../../crew/direct.ts"; |
| 19 | 20 | import { alreadyDone } from "../../core/done_on_main.ts"; |
| @@ -534,7 +535,8 @@ async function studioTell( | ||
| 534 | 535 | : null |
| 535 | 536 | }</p>`; |
| 536 | 537 | |
| 537 | const marks = marksByName(db, [issue.authorName, issue.assigneeName ?? ""]); | |
| 538 | const accounts = accountsByName(db, [issue.authorName, issue.assigneeName ?? ""], repo.id); | |
| 539 | const marks = marksOf(accounts); | |
| 538 | 540 | const head = html`<div class="page-head"> |
| 539 | 541 | <h1>${issue.title} <span class="num">#${issue.number}</span></h1> |
| 540 | 542 | <div class="page-head-sub bar muted small"> |
| @@ -554,6 +556,7 @@ async function studioTell( | ||
| 554 | 556 | : userLink(issue.authorName, { mark: marks.get(issue.authorName) })} |
| 555 | 557 | opened this ${time(issue.createdAt)}</span |
| 556 | 558 | > |
| 559 | ${outsideLabelFrom(db, repo, accounts, issue)} | |
| 557 | 560 | ${when( |
| 558 | 561 | issue.originUrl, |
| 559 | 562 | (url) => |
src/web/ui.ts +2 −1
| @@ -297,13 +297,14 @@ export function copyField( | ||
| 297 | 297 | |
| 298 | 298 | export function badge( |
| 299 | 299 | text: Html | string, |
| 300 | o: { tone?: Tone; icon?: IconName; variant?: "secondary" | "outline" } = {}, | |
| 300 | o: { tone?: Tone; icon?: IconName; variant?: "secondary" | "outline"; title?: string } = {}, | |
| 301 | 301 | ): Html { |
| 302 | 302 | const variant = |
| 303 | 303 | o.tone && o.tone !== "default" ? o.tone : (o.variant ?? undefined); |
| 304 | 304 | return html`<span |
| 305 | 305 | class="badge" |
| 306 | 306 | ${variant ? html`data-variant="${variant}"` : null} |
| 307 | ${o.title === undefined ? null : html`title="${o.title}"`} | |
| 307 | 308 | >${o.icon ? icon(o.icon) : null}${text}</span |
| 308 | 309 | >`; |
| 309 | 310 | } |
test/outside-label.test.ts added +172
| @@ -0,0 +1,172 @@ | ||
| 1 | /** | |
| 2 | * Something filed by someone who cannot write to the repository says so, in | |
| 3 | * words, where the owner reads it: the inbox row, the issue and pull headers, | |
| 4 | * the terminal's summary line and the MCP issue read (`outside: true`). A | |
| 5 | * writer's own carries nothing. | |
| 6 | */ | |
| 7 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 8 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 9 | import { tmpdir } from "node:os"; | |
| 10 | import { join } from "node:path"; | |
| 11 | import { openIssue } from "../src/actions/issues.ts"; | |
| 12 | import { openPull } from "../src/actions/pulls.ts"; | |
| 13 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 14 | import { createApp, type App } from "../src/app.ts"; | |
| 15 | import { getPull, type Pull } from "../src/core/pulls.ts"; | |
| 16 | import type { Repo } from "../src/core/repos.ts"; | |
| 17 | import { claimRun, createRun, finishRun, setRunBase } from "../src/core/runs.ts"; | |
| 18 | import { createSession } from "../src/core/sessions.ts"; | |
| 19 | import { createToken } from "../src/core/tokens.ts"; | |
| 20 | import { createUser, type User } from "../src/core/users.ts"; | |
| 21 | import { resolveOid } from "../src/git/merge.ts"; | |
| 22 | import { repoDir } from "../src/git/repos.ts"; | |
| 23 | import { forgeHttp, serve, type ForgeHttp, type Servers } from "../src/http/server.ts"; | |
| 24 | import { sweepStaleAsks } from "../src/crew/stale_asks.ts"; | |
| 25 | import { OUTSIDE_TITLE } from "../src/web/outside.ts"; | |
| 26 | import { createForgeApp } from "../src/tui/forge.ts"; | |
| 27 | import { issueScreen } from "../src/tui/screens/issue.ts"; | |
| 28 | import { pullScreen } from "../src/tui/screens/pull.ts"; | |
| 29 | import { local } from "../src/tui/screens/where.ts"; | |
| 30 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; | |
| 31 | import { settleApp } from "./helpers/tui.ts"; | |
| 32 | import { quietLogs } from "./helpers/globals.ts"; | |
| 33 | import { promote } from "./helpers/members.ts"; | |
| 34 | ||
| 35 | quietLogs(); | |
| 36 | ||
| 37 | const LABEL = "From outside"; | |
| 38 | let dataDir = ""; | |
| 39 | let app: App; | |
| 40 | let http: ForgeHttp; | |
| 41 | let servers: Servers; | |
| 42 | let alice: User; | |
| 43 | let mallory: User; | |
| 44 | let repo: Repo; | |
| 45 | let cookie = ""; | |
| 46 | let token = ""; | |
| 47 | let outsideIssue = 0; | |
| 48 | let ownIssue = 0; | |
| 49 | let outsidePull = 0; | |
| 50 | let ownPull = 0; | |
| 51 | let outsidePullRow: Pull; | |
| 52 | ||
| 53 | const mk = async (username: string, first: boolean) => { | |
| 54 | const made = await createUser(app.db, { | |
| 55 | origin: "seed", trusted: true, username, email: `${username}@forge.local`, | |
| 56 | password: "a-good-passphrase", adminIfFirst: first, | |
| 57 | }); | |
| 58 | if (!made.ok) throw new Error(made.error); | |
| 59 | return made.value; | |
| 60 | }; | |
| 61 | const page = async (path: string) => | |
| 62 | (await http.handle(new Request(`http://forge.test${path}`, { headers: { cookie } }))).text(); | |
| 63 | const mcpIssue = async (number: number) => { | |
| 64 | const res = await fetch(`${servers.url}/mcp`, { | |
| 65 | method: "POST", | |
| 66 | headers: { "content-type": "application/json", accept: "application/json, text/event-stream", authorization: `Bearer ${token}` }, | |
| 67 | body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "issue", arguments: { repo: "alice/lib", number } } }), | |
| 68 | }); | |
| 69 | const out: any = await res.json(); | |
| 70 | return JSON.parse(out.result.content[0].text) as { outside?: boolean }; | |
| 71 | }; | |
| 72 | ||
| 73 | beforeAll(async () => { | |
| 74 | dataDir = await mkdtemp(join(tmpdir(), "forge-outside-label-")); | |
| 75 | app = createApp({ dataDir, port: 0, host: "forge.test" }); | |
| 76 | http = forgeHttp(app); | |
| 77 | servers = await serve(app); | |
| 78 | alice = await mk("alice", true); | |
| 79 | mallory = await mk("mallory", false); | |
| 80 | promote(app.db, mallory); | |
| 81 | cookie = `forge_session=${createSession(app.db, alice.id).token}`; | |
| 82 | token = createToken(app.db, alice.id, "rw", "rw").token; | |
| 83 | const made = await createRepo(app, alice, { name: "lib", visibility: "public" }); | |
| 84 | if (!made.ok) throw new Error(String(made.error)); | |
| 85 | repo = made.value; | |
| 86 | for (const [branch, path] of [["main", "a.md"], ["feat", "f.md"], ["own", "o.md"]] as const) { | |
| 87 | const done = await commitToBranch(app, alice, repo, { branch, message: path, files: [{ path, content: `${path}\n` }] }); | |
| 88 | if (!done.ok) throw new Error(JSON.stringify(done.error)); | |
| 89 | } | |
| 90 | const i1 = openIssue(app, mallory, repo, { title: "From a stranger" }); | |
| 91 | const i2 = openIssue(app, alice, repo, { title: "From the owner" }); | |
| 92 | if (!i1.ok || !i2.ok) throw new Error("issues"); | |
| 93 | outsideIssue = i1.value.number; | |
| 94 | ownIssue = i2.value.number; | |
| 95 | const p1 = await openPull(app, alice, repo, { title: "Stranger pull", baseBranch: "main", headBranch: "feat" }); | |
| 96 | const p2 = await openPull(app, alice, repo, { title: "Owner pull", baseBranch: "main", headBranch: "own" }); | |
| 97 | if (!p1.ok || !p2.ok) throw new Error("pulls"); | |
| 98 | outsidePull = p1.value.number; | |
| 99 | ownPull = p2.value.number; | |
| 100 | // A person outside writes through a fork; here the author is set directly. | |
| 101 | app.db.run("UPDATE issue SET author_id = ?1 WHERE repo_id = ?2 AND number = ?3", [mallory.id, repo.id, outsidePull]); | |
| 102 | outsidePullRow = getPull(app.db, repo.id, outsidePull)!; | |
| 103 | const mainOid = (await resolveOid(repoDir(app.reposRoot, "alice", "lib"), "refs/heads/main"))!; | |
| 104 | for (const row of [outsidePullRow, getPull(app.db, repo.id, ownPull)!]) { | |
| 105 | const run = createRun(app.db, { repoId: repo.id, kind: "check", issueId: row.id, env: `pull-${row.number}`, commitOid: row.headOid }); | |
| 106 | claimRun(app.db, run.id); | |
| 107 | finishRun(app.db, run.id, { state: "ok", summary: "all green" }); | |
| 108 | setRunBase(app.db, run.id, mainOid); | |
| 109 | } | |
| 110 | await sweepStaleAsks(app); | |
| 111 | }, 60_000); | |
| 112 | ||
| 113 | afterAll(async () => { | |
| 114 | servers.stop(); | |
| 115 | app.close(); | |
| 116 | await rm(dataDir, { recursive: true, force: true }); | |
| 117 | }); | |
| 118 | ||
| 119 | describe("From outside", () => { | |
| 120 | test("the issue header carries the label and its title", async () => { | |
| 121 | const mine = await page(`/alice/lib/issues/${outsideIssue}`); | |
| 122 | expect(mine).toContain(LABEL); | |
| 123 | expect(mine).toContain(`title="${OUTSIDE_TITLE}"`); | |
| 124 | expect(await page(`/alice/lib/issues/${ownIssue}`)).not.toContain(LABEL); | |
| 125 | }); | |
| 126 | ||
| 127 | test("the pull header carries the label", async () => { | |
| 128 | expect(await page(`/alice/lib/pulls/${outsidePull}`)).toContain(LABEL); | |
| 129 | expect(await page(`/alice/lib/pulls/${ownPull}`)).not.toContain(LABEL); | |
| 130 | }); | |
| 131 | ||
| 132 | test("the inbox row of an outsider's item carries the label, a writer's does not", async () => { | |
| 133 | const asks = await page("/live/on-you"); | |
| 134 | expect(asks).toContain("Stranger pull"); | |
| 135 | expect(asks).toContain(LABEL); | |
| 136 | // Both cards are there; only the outsider's carries the label. | |
| 137 | expect(asks).toContain("Owner pull"); | |
| 138 | expect(asks.split(LABEL).length - 1).toBe(1); | |
| 139 | }); | |
| 140 | ||
| 141 | test("the terminal's issue and pull screens say 'from outside', and only for an outsider's", async () => { | |
| 142 | const terminal = headlessTerminal(160, 40); | |
| 143 | const { app: tui, session } = createForgeApp( | |
| 144 | app, | |
| 145 | { sshUsername: "t", remoteAddress: "127.0.0.1", user: alice }, | |
| 146 | { terminal, exitHooks: false }, | |
| 147 | ); | |
| 148 | tui.start(); | |
| 149 | try { | |
| 150 | await settleApp(tui); | |
| 151 | for (const [screen, number, says] of [ | |
| 152 | [issueScreen, outsideIssue, true], | |
| 153 | [issueScreen, ownIssue, false], | |
| 154 | [pullScreen, outsidePull, true], | |
| 155 | [pullScreen, ownPull, false], | |
| 156 | ] as const) { | |
| 157 | tui.push(screen(session, tui.ctx, local(session, repo), number)); | |
| 158 | await settleApp(tui); | |
| 159 | expect(tui.screen.toText().includes("from outside")).toBe(says); | |
| 160 | tui.pop(); | |
| 161 | await settleApp(tui); | |
| 162 | } | |
| 163 | } finally { | |
| 164 | tui.stop(); | |
| 165 | } | |
| 166 | }); | |
| 167 | ||
| 168 | test("the MCP issue read says outside: true, and only for an outsider's", async () => { | |
| 169 | expect((await mcpIssue(outsideIssue)).outside).toBe(true); | |
| 170 | expect((await mcpIssue(ownIssue)).outside).toBeUndefined(); | |
| 171 | }); | |
| 172 | }); |
new above
offline