Public: anyone can read this; the crew can change it.
Dependencies on an issue read at a glance: what this waits for, what waits for this, and what is actually holding it now #13648
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13641-dependencies-on-an-issue-read-at-a-glanc → main 5 commits fork 5 threads · 5 unresolved
17 files
changed +745
−40
docs/design/areas/chain.md added +5
| @@ -0,0 +1,5 @@ | ||
| 1 | # Dependency chain (what an issue waits for, drawn as rows) | |
| 2 | ||
| 3 | `.chain` is a column of rows, no boxes: `.chain-col` lists what it waits for (further back first), then `.chain-self` (the issue, between two hairlines), then what waits for it. Each `.chain-node` is one link holding the one `.badge` (queued, running, ok, held), `.chain-no`, `.chain-title` (five words) and `.chain-word` (where it stands; who is next is its `title`, as "next: …"). A closed and landed node is `data-quiet` (struck, faded); the one holding the issue now is `data-holding` (heavier weight and "holding this" in its words, no colour). `.chain-more` is the "+N more" fold. `.dep-line` is the one sentence above it, in the text colour. Drawn by `src/web/pages/dep_chain.ts` from a `Standing` (`src/core/dep_standing.ts`). | |
| 4 | ||
| 5 | On the home lanes a tile for an issue held by an open dependency carries `.tile-waits` under its title: "waits for #12, #14 +1", muted, one line (`src/web/pages/home_flow.ts`). |
docs/design/size-budget.json +1 −1
| @@ -21,7 +21,7 @@ | ||
| 21 | 21 | }, |
| 22 | 22 | "/:owner/:name/next": { |
| 23 | 23 | "js": 23296, |
| 24 | "css": 44800 | |
| 24 | "css": 45056 | |
| 25 | 25 | }, |
| 26 | 26 | "/:owner/:name/space": { |
| 27 | 27 | "js": 29696, |
docs/features/README.md +1
| @@ -375,6 +375,7 @@ Read with the guide page [Bring your own AI](../guide-own-ai.md). | ||
| 375 | 375 | - [](economics.md) |
| 376 | 376 | - [](model-escalation.md) |
| 377 | 377 | - [](issue-cost.md) |
| 378 | - [](dependency-standing.md) | |
| 378 | 379 | - [](mirror-credit.md) |
| 379 | 380 | - [](openai-runner.md) |
| 380 | 381 | - [](model-review.md) |
docs/features/dependency-standing.md added +10
| @@ -0,0 +1,10 @@ | ||
| 1 | # Dependency standing | |
| 2 | ||
| 3 | An issue says in one sentence whether it can start and what holds it now: "Ready.", "Waits for #643 (building now, Scout).", "Waits for 3 issues; the nearest to done is #8941 (in review).", "Nothing holds this: its two blockers have landed." Under it a chain draws what it waits for (two levels back), the issue, and what waits for it; each node is a row with one badge (queued, running, ok, held), its number, five words of title and where it stands; who is next (the builder, the reviewer, a person, the queue) is its hover text. Closed and landed blockers are struck and quiet; the one holding the issue is bolder and says "holding this"; more than three on a side fold to "+N more". | |
| 4 | ||
| 5 | - **Page:** the Depends on card on an issue. A writer types a number or words of a title in the same box; two matches ask for the number; a cycle is refused with its path ("#7 waits for #5 waits for #3 (this one)"); a step the writer may not see is printed as "…". | |
| 6 | - **MCP:** the `issue` tool's `standing` field (`line`, `ready`, `before`, `after`, `more`). | |
| 7 | - **Terminal:** the issue screen's waits line ends with the sentence and up to five chain rows sit under it; `w` takes a number or words of a title, as the page does. | |
| 8 | - **Home:** a tile for an issue held by an open dependency says "waits for #N" under its title. | |
| 9 | ||
| 10 | Code: `src/core/dep_standing.ts` (`standingOf`, `cyclePath`, `blockerByTitle`, `chainLines`, `openBlockerNumbers`), `src/web/pages/dep_chain.ts`. Tests: `test/dep-standing.test.ts`. |
src/core/dep_standing.ts added +303
| @@ -0,0 +1,303 @@ | ||
| 1 | /** | |
| 2 | * An issue's standing among its dependencies, read at a glance (#13641): one | |
| 3 | * sentence saying whether it can start and what holds it now, and a small | |
| 4 | * chain — what it waits for, up to two levels back, and what waits for it — | |
| 5 | * each node one badge, one number, five words of title and who is next. | |
| 6 | * Plain records in (the database read once per level), plain data out: the | |
| 7 | * page, the API, the MCP and the terminal draw the same `Standing`. | |
| 8 | */ | |
| 9 | ||
| 10 | import type { Database } from "bun:sqlite"; | |
| 11 | import { openPullStages } from "../flow/read.ts"; | |
| 12 | import type { Stage } from "../flow/stage.ts"; | |
| 13 | import { dependenciesOf } from "./dependencies.ts"; | |
| 14 | import { getIssuesByIds, type Issue } from "./issues.ts"; | |
| 15 | import type { Repo } from "./repos.ts"; | |
| 16 | import { mayView, sealedScope } from "./sealed.ts"; | |
| 17 | import type { User } from "./users.ts"; | |
| 18 | ||
| 19 | export type Badge = "queued" | "running" | "ok" | "held"; | |
| 20 | ||
| 21 | export interface StandingNode { | |
| 22 | readonly number: number; | |
| 23 | /** The first five words of the title. */ | |
| 24 | readonly title: string; | |
| 25 | readonly badge: Badge; | |
| 26 | /** Where it stands, in words: "building now, Scout", "in review", "landed". */ | |
| 27 | readonly word: string; | |
| 28 | /** Who is next on it: the builder, the reviewer, a person, the queue; empty when nothing is. */ | |
| 29 | readonly next: string; | |
| 30 | /** Closed and landed, or closed and confirmed: drawn struck and quiet. */ | |
| 31 | readonly quiet: boolean; | |
| 32 | /** The one blocker holding the issue now. */ | |
| 33 | readonly holding: boolean; | |
| 34 | } | |
| 35 | ||
| 36 | export interface Standing { | |
| 37 | /** The sentence at the top of the issue. */ | |
| 38 | readonly line: string; | |
| 39 | /** Nothing holds it: it can start. */ | |
| 40 | readonly ready: boolean; | |
| 41 | /** Levels of what it waits for, nearest first, each at most `SHOWN` nodes. */ | |
| 42 | readonly before: readonly (readonly StandingNode[])[]; | |
| 43 | /** What waits for it. */ | |
| 44 | readonly after: readonly StandingNode[]; | |
| 45 | /** How many nodes each side left out, "+N more". */ | |
| 46 | readonly moreBefore: number; | |
| 47 | readonly moreAfter: number; | |
| 48 | } | |
| 49 | ||
| 50 | const SHOWN = 3; | |
| 51 | const LEVELS = 2; | |
| 52 | const RANK: Record<Stage, number> = { issue: 0, pull: 1, check: 2, review: 3, land: 4, live: 5 }; | |
| 53 | const NUMBER_WORDS = ["no", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]; | |
| 54 | ||
| 55 | /** The first five words of a title, with an ellipsis when cut. */ | |
| 56 | export function fiveWords(title: string): string { | |
| 57 | const words = title.replace(/\s+/g, " ").trim().split(" "); | |
| 58 | return words.length <= 5 ? words.join(" ") : `${words.slice(0, 5).join(" ")}…`; | |
| 59 | } | |
| 60 | ||
| 61 | function count(n: number): string { | |
| 62 | return NUMBER_WORDS[n] ?? String(n); | |
| 63 | } | |
| 64 | ||
| 65 | /** | |
| 66 | * Whether a closed blocker still holds what waits for it: dropped or split, and nobody confirmed. | |
| 67 | */ | |
| 68 | function closedHolds(db: Database, issueId: string, blocker: Issue): boolean { | |
| 69 | if (blocker.state !== "closed") return false; | |
| 70 | if (blocker.closeReason !== "dropped" && blocker.closeReason !== "split") return false; | |
| 71 | const row = db | |
| 72 | .query<{ confirmed: number }, [string, string]>( | |
| 73 | "SELECT confirmed FROM issue_dependency WHERE issue_id = ?1 AND blocked_by_id = ?2", | |
| 74 | ) | |
| 75 | .get(issueId, blocker.id); | |
| 76 | return row !== null && row.confirmed === 0; | |
| 77 | } | |
| 78 | ||
| 79 | function node( | |
| 80 | db: Database, | |
| 81 | stages: ReadonlyMap<number, Stage>, | |
| 82 | waiter: Issue, | |
| 83 | issue: Issue, | |
| 84 | blockedItself: boolean, | |
| 85 | ): Omit<StandingNode, "holding"> { | |
| 86 | const base = { number: issue.number, title: fiveWords(issue.title) }; | |
| 87 | if (issue.state === "closed") { | |
| 88 | if (closedHolds(db, waiter.id, issue)) | |
| 89 | return { ...base, badge: "held", word: `closed as ${issue.closeReason}; still holds`, next: "a person", quiet: false }; | |
| 90 | return { | |
| 91 | ...base, | |
| 92 | badge: "ok", | |
| 93 | word: issue.closeReason === "done" || issue.closeReason === null ? "landed" : `closed as ${issue.closeReason}`, | |
| 94 | next: "", | |
| 95 | quiet: true, | |
| 96 | }; | |
| 97 | } | |
| 98 | const stage = stages.get(issue.number) ?? "issue"; | |
| 99 | const who = issue.assigneeName; | |
| 100 | const person = who !== null && !issue.assigneeIsAgent; | |
| 101 | if (stage === "pull" || stage === "check") | |
| 102 | return { ...base, badge: "running", word: `building now${who === null ? "" : `, ${who}`}`, next: "the builder", quiet: false }; | |
| 103 | if (stage === "review") | |
| 104 | return { ...base, badge: "running", word: "in review", next: "the reviewer", quiet: false }; | |
| 105 | if (stage === "land" || stage === "live") | |
| 106 | return { ...base, badge: "running", word: "landing", next: "a person", quiet: false }; | |
| 107 | if (blockedItself) return { ...base, badge: "held", word: "waits for others itself", next: "its own blockers", quiet: false }; | |
| 108 | if (person) return { ...base, badge: "queued", word: `${who} has it`, next: "a person", quiet: false }; | |
| 109 | if (who !== null) return { ...base, badge: "running", word: `building now, ${who}`, next: "the builder", quiet: false }; | |
| 110 | return { ...base, badge: "queued", word: "queued", next: "the queue", quiet: false }; | |
| 111 | } | |
| 112 | ||
| 113 | /** The standing of `issue` for `user`; `seen` leaves out what the user may not see. */ | |
| 114 | export function standingOf( | |
| 115 | db: Database, | |
| 116 | repo: Repo, | |
| 117 | issue: Issue, | |
| 118 | user: User | undefined, | |
| 119 | seen: (i: Issue) => boolean = () => true, | |
| 120 | now: Date = new Date(), | |
| 121 | direct: { blockedBy: Issue[]; blocks: Issue[] } = dependenciesOf(db, issue.id), | |
| 122 | ): Standing { | |
| 123 | const blockers = direct.blockedBy.filter(seen); | |
| 124 | const dependents = direct.blocks.filter(seen); | |
| 125 | // Levels back: the blockers of the blockers that are still open. | |
| 126 | const levels: Issue[][] = [blockers]; | |
| 127 | const parents = new Map<string, Issue>(); // blocker id -> the issue that waits for it | |
| 128 | for (const b of blockers) parents.set(b.id, issue); | |
| 129 | const seenIds = new Set<string>([issue.id, ...blockers.map((b) => b.id)]); | |
| 130 | const open = new Map<string, Issue[]>(); // open issue id -> its blockers (visible) | |
| 131 | for (let depth = 1; depth < LEVELS; depth++) { | |
| 132 | const next: Issue[] = []; | |
| 133 | for (const b of levels[depth - 1]!) { | |
| 134 | if (b.state !== "open") continue; | |
| 135 | const own = dependenciesOf(db, b.id).blockedBy.filter(seen); | |
| 136 | open.set(b.id, own); | |
| 137 | for (const o of own) | |
| 138 | if (!seenIds.has(o.id)) { | |
| 139 | seenIds.add(o.id); | |
| 140 | parents.set(o.id, b); | |
| 141 | next.push(o); | |
| 142 | } | |
| 143 | } | |
| 144 | if (next.length === 0) break; | |
| 145 | levels.push(next); | |
| 146 | } | |
| 147 | // Which of the nodes we draw wait for something still holding them. | |
| 148 | const everyone = [...levels.flat(), ...dependents]; | |
| 149 | for (const d of dependents) | |
| 150 | if (!open.has(d.id)) open.set(d.id, dependenciesOf(db, d.id).blockedBy.filter(seen)); | |
| 151 | const holdsOf = (i: Issue, own: readonly Issue[]): boolean => | |
| 152 | own.some((o) => o.state === "open" || closedHolds(db, i.id, o)); | |
| 153 | // Nothing open to place in the pipeline costs no read of it. | |
| 154 | const placed = new Set(everyone.filter((i) => i.state === "open").map((i) => i.number)); | |
| 155 | const stages = placed.size === 0 ? new Map<number, Stage>() : openPullStages(db, repo, sealedScope(db, repo, user), now, placed); | |
| 156 | const describe = (waiter: Issue, i: Issue) => | |
| 157 | node(db, stages, waiter, i, i.state === "open" && holdsOf(i, open.get(i.id) ?? [])); | |
| 158 | ||
| 159 | const first = blockers.map((b) => ({ b, n: describe(issue, b) })); | |
| 160 | const holders = first.filter((x) => x.n.badge !== "ok"); | |
| 161 | // The one holding it now: the furthest along, then the lowest number. | |
| 162 | const holding = [...holders].sort((a, b) => { | |
| 163 | const live = (x: { b: Issue; n: Omit<StandingNode, "holding"> }) => (x.n.badge === "held" ? -1 : RANK[stages.get(x.b.number) ?? "issue"] + (x.b.assigneeName !== null ? 0.5 : 0)); | |
| 164 | return live(b) - live(a) || a.b.number - b.b.number; | |
| 165 | })[0]; | |
| 166 | ||
| 167 | const mark = (n: Omit<StandingNode, "holding">, h: boolean): StandingNode => ({ ...n, holding: h }); | |
| 168 | const nodesBefore = levels.map((level, depth) => | |
| 169 | level.map((b) => | |
| 170 | depth === 0 | |
| 171 | ? mark(first.find((x) => x.b.id === b.id)!.n, holding?.b.id === b.id && holders.length > 0) | |
| 172 | : mark(describe(parents.get(b.id) ?? issue, b), false), | |
| 173 | ), | |
| 174 | ); | |
| 175 | const cut = (nodes: readonly StandingNode[]) => nodes.slice(0, SHOWN); | |
| 176 | const before = nodesBefore.map(cut); | |
| 177 | const moreBefore = nodesBefore.reduce((n, l) => n + Math.max(0, l.length - SHOWN), 0); | |
| 178 | const after = dependents.map((d) => mark(describe(issue, d), false)); | |
| 179 | ||
| 180 | let line: string; | |
| 181 | let ready = false; | |
| 182 | const hold = holding === undefined ? undefined : holding.n; | |
| 183 | if (issue.state === "closed") line = issue.closeReason === "done" || issue.closeReason === null ? "Done." : `Closed as ${issue.closeReason}.`; | |
| 184 | else if (blockers.length === 0) { | |
| 185 | ready = true; | |
| 186 | line = "Ready."; | |
| 187 | } else if (hold === undefined) { | |
| 188 | ready = true; | |
| 189 | line = `Nothing holds this: its ${blockers.length === 1 ? "blocker has" : `${count(blockers.length)} blockers have`} landed.`; | |
| 190 | } else if (holders.length === 1) { | |
| 191 | line = | |
| 192 | hold.badge === "held" | |
| 193 | ? `Held by #${hold.number}, which ${hold.word}: say whether it still holds, or remove it.` | |
| 194 | : `Waits for #${hold.number} (${hold.word}).`; | |
| 195 | } else { | |
| 196 | line = `Waits for ${holders.length} issues; the nearest to done is #${hold.number} (${hold.word}).`; | |
| 197 | } | |
| 198 | return { line, ready, before, after: cut(after), moreBefore, moreAfter: Math.max(0, after.length - SHOWN) }; | |
| 199 | } | |
| 200 | ||
| 201 | /** | |
| 202 | * The path a link would close into a loop: `blocker` already waits, through | |
| 203 | * others, for `issue`. "#7 → #5 → #3" reads: #7 waits for #5, which waits for #3. | |
| 204 | * Empty when there is none. A step `seen` refuses is `null`: its number is not | |
| 205 | * the viewer's to learn, only that the loop runs through something hidden. | |
| 206 | */ | |
| 207 | export function cyclePath( | |
| 208 | db: Database, | |
| 209 | issue: Issue, | |
| 210 | blocker: Issue, | |
| 211 | seen: (i: Issue) => boolean = () => true, | |
| 212 | ): (number | null)[] { | |
| 213 | const prev = new Map<string, string>(); | |
| 214 | const queue = [blocker.id]; | |
| 215 | const reached = new Set(queue); | |
| 216 | while (queue.length > 0) { | |
| 217 | const current = queue.shift()!; | |
| 218 | const rows = db | |
| 219 | .query<{ blocked_by_id: string }, [string]>("SELECT blocked_by_id FROM issue_dependency WHERE issue_id = ?1") | |
| 220 | .all(current); | |
| 221 | for (const { blocked_by_id: next } of rows) { | |
| 222 | if (reached.has(next)) continue; | |
| 223 | reached.add(next); | |
| 224 | prev.set(next, current); | |
| 225 | if (next === issue.id) { | |
| 226 | const ids = [next]; | |
| 227 | for (let at = next; prev.has(at); ) { | |
| 228 | at = prev.get(at)!; | |
| 229 | ids.unshift(at); | |
| 230 | } | |
| 231 | const by = getIssuesByIds(db, ids); | |
| 232 | return ids.map((id) => { | |
| 233 | const i = by.get(id); | |
| 234 | return i !== undefined && seen(i) ? i.number : null; | |
| 235 | }); | |
| 236 | } | |
| 237 | queue.push(next); | |
| 238 | } | |
| 239 | } | |
| 240 | return []; | |
| 241 | } | |
| 242 | ||
| 243 | /** | |
| 244 | * Open blockers' numbers for a batch of issues, one query: what the home lanes say under a card. | |
| 245 | */ | |
| 246 | export function openBlockerNumbers(db: Database, issueIds: readonly string[]): Map<string, number[]> { | |
| 247 | const out = new Map<string, number[]>(); | |
| 248 | if (issueIds.length === 0) return out; | |
| 249 | const rows = db | |
| 250 | .query<{ issue_id: string; number: number }, [string]>( | |
| 251 | `SELECT d.issue_id, b.number FROM issue_dependency d JOIN issue b ON b.id = d.blocked_by_id | |
| 252 | WHERE d.issue_id IN (SELECT value FROM json_each(?1)) AND b.state = 'open' AND b.sealed = 0 | |
| 253 | ORDER BY b.number`, | |
| 254 | ) | |
| 255 | .all(JSON.stringify(issueIds)); | |
| 256 | for (const r of rows) out.set(r.issue_id, [...(out.get(r.issue_id) ?? []), r.number]); | |
| 257 | return out; | |
| 258 | } | |
| 259 | ||
| 260 | /** | |
| 261 | * The one open issue whose title holds `words`, for a writer who types words | |
| 262 | * where a number goes. Anything but exactly one says why in a sentence; the | |
| 263 | * issue itself and what the user may not see are never offered. | |
| 264 | */ | |
| 265 | export function blockerByTitle( | |
| 266 | db: Database, | |
| 267 | repo: Repo, | |
| 268 | issue: Issue, | |
| 269 | user: User | undefined, | |
| 270 | words: string, | |
| 271 | ): { issue: Issue } | { says: string } { | |
| 272 | const wanted = words.replace(/\s+/g, " ").trim(); | |
| 273 | if (wanted.length < 2 || wanted.length > 100) return { says: "Type an issue number, or two or more letters of its title." }; | |
| 274 | const like = `%${wanted.replace(/[\\%_]/g, (c) => `\\${c}`)}%`; | |
| 275 | const hits = db | |
| 276 | .query<{ id: string }, [string, string]>( | |
| 277 | "SELECT id FROM issue WHERE repo_id = ?1 AND kind = 'issue' AND state = 'open' AND title LIKE ?2 ESCAPE '\\' ORDER BY number LIMIT 12", | |
| 278 | ) | |
| 279 | .all(repo.id, like) | |
| 280 | .map((r) => r.id); | |
| 281 | const found = [...getIssuesByIds(db, hits).values()] | |
| 282 | .filter((i) => i.id !== issue.id && mayView(db, repo, i, user)) | |
| 283 | .sort((a, b) => a.number - b.number); | |
| 284 | if (found.length === 1) return { issue: found[0]! }; | |
| 285 | if (found.length === 0) return { says: `No open issue here has "${wanted}" in its title.` }; | |
| 286 | return { says: `${found.length > 5 ? "More than five" : found.length} issues match "${wanted}": ${found.slice(0, 5).map((i) => `#${i.number}`).join(", ")}. Type the number.` }; | |
| 287 | } | |
| 288 | ||
| 289 | /** The chain as plain lines for the terminal: what it waits for (furthest back first), then what waits for it. */ | |
| 290 | export function chainLines(s: Standing): string[] { | |
| 291 | const row = (lead: string, n: StandingNode): string => | |
| 292 | `${lead} #${n.number} ${n.title} - ${n.word}${n.holding ? " · holding this" : ""}${n.next === "" ? "" : ` · next: ${n.next}`}`; | |
| 293 | const out: string[] = []; | |
| 294 | const levels = [...s.before].reverse(); | |
| 295 | levels.forEach((level, i) => { | |
| 296 | const near = i === levels.length - 1; | |
| 297 | for (const n of level) out.push(row(near ? "waits for" : " and before that", n)); | |
| 298 | }); | |
| 299 | if (s.moreBefore > 0) out.push(`waits for +${s.moreBefore} more`); | |
| 300 | for (const n of s.after) out.push(row("held up:", n)); | |
| 301 | if (s.moreAfter > 0) out.push(`held up: +${s.moreAfter} more`); | |
| 302 | return out; | |
| 303 | } |
src/flow/lanes_read.ts +33 −7
| @@ -16,6 +16,7 @@ | ||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | import type { Database } from "bun:sqlite"; |
| 19 | import { openBlockerNumbers } from "../core/dep_standing.ts"; | |
| 19 | 20 | import type { App } from "../app.ts"; |
| 20 | 21 | import { nextUp, type NextRow } from "../core/next_up.ts"; |
| 21 | 22 | import { idleReason, type IdleReason } from "../crew/idle_reason.ts"; |
| @@ -74,6 +75,8 @@ export interface LaneItem { | ||
| 74 | 75 | readonly issueId: string | null; |
| 75 | 76 | /** When the issue or pull was opened; null where there is none. */ |
| 76 | 77 | readonly born: string | null; |
| 78 | /** The open issues this one waits for, ascending; absent when none (#13641). */ | |
| 79 | readonly waits?: readonly number[]; | |
| 77 | 80 | } |
| 78 | 81 | |
| 79 | 82 | export interface LaneRead { |
| @@ -532,14 +535,15 @@ export function readFast(db: Database, now: Date): Fast { | ||
| 532 | 535 | `SELECT COUNT(*) AS n FROM run WHERE kind = 'agent' AND reason != 'review' AND started_at >= ?1`, |
| 533 | 536 | recent, |
| 534 | 537 | ); |
| 538 | const read: Record<Exclude<LaneKey, "asked">, LaneRead> = { | |
| 539 | building: building(runRows(db, "agent", "x.reason != 'review'", iso)), | |
| 540 | checks: checks(runRows(db, "check", "1 = 1", iso, true)), | |
| 541 | review: review(runRows(db, "agent", "x.reason = 'review'", iso)), | |
| 542 | landing: landing(approvedRows(db), mergedRows(db, week)), | |
| 543 | live: live(db, day), | |
| 544 | }; | |
| 535 | 545 | return { |
| 536 | lanes: { | |
| 537 | building: building(runRows(db, "agent", "x.reason != 'review'", iso)), | |
| 538 | checks: checks(runRows(db, "check", "1 = 1", iso, true)), | |
| 539 | review: review(runRows(db, "agent", "x.reason = 'review'", iso)), | |
| 540 | landing: landing(approvedRows(db), mergedRows(db, week)), | |
| 541 | live: live(db, day), | |
| 542 | }, | |
| 546 | lanes: withWaits(db, read), | |
| 543 | 547 | moved: { |
| 544 | 548 | asked: started, |
| 545 | 549 | building: started, |
| @@ -569,6 +573,28 @@ export function readFast(db: Database, now: Date): Fast { | ||
| 569 | 573 | }; |
| 570 | 574 | } |
| 571 | 575 | |
| 576 | /** Each issue's tile says what it waits for: one query for every tile in the lanes. */ | |
| 577 | export function withWaits( | |
| 578 | db: Database, | |
| 579 | lanes: Record<Exclude<LaneKey, "asked">, LaneRead>, | |
| 580 | ): Record<Exclude<LaneKey, "asked">, LaneRead> { | |
| 581 | const ids = new Set<string>(); | |
| 582 | for (const k of Object.keys(lanes) as (keyof typeof lanes)[]) | |
| 583 | for (const i of lanes[k].items) if (i.kind === "issue" && i.issueId !== null) ids.add(i.issueId); | |
| 584 | const waits = openBlockerNumbers(db, [...ids]); | |
| 585 | if (waits.size === 0) return lanes; | |
| 586 | const out = { ...lanes }; | |
| 587 | for (const k of Object.keys(out) as (keyof typeof out)[]) | |
| 588 | out[k] = { | |
| 589 | ...out[k], | |
| 590 | items: out[k].items.map((i) => { | |
| 591 | const w = i.issueId === null ? undefined : waits.get(i.issueId); | |
| 592 | return w === undefined ? i : { ...i, waits: w }; | |
| 593 | }), | |
| 594 | }; | |
| 595 | return out; | |
| 596 | } | |
| 597 | ||
| 572 | 598 | export interface Slow { |
| 573 | 599 | /** The crew's next asks in its own order, a few more than a lane draws so a build starting leaves the lane full. */ |
| 574 | 600 | readonly asked: readonly LaneItem[]; |
src/http/mcp/tools/issue.ts +9 −1
| @@ -4,6 +4,7 @@ import { mayView } from "../../../core/sealed.ts"; | ||
| 4 | 4 | import { countThread, EMBEDDED_COMMENTS, getIssue, labelsFor, listComments } from "../../../core/issues.ts"; |
| 5 | 5 | import { isCrew } from "../../../core/agents.ts"; |
| 6 | 6 | import { canWrite } from "../../../core/repos.ts"; |
| 7 | import { standingOf } from "../../../core/dep_standing.ts"; | |
| 7 | 8 | import { dependenciesOf } from "../../../core/dependencies.ts"; |
| 8 | 9 | import { getUsersByIds } from "../../../core/users.ts"; |
| 9 | 10 | import { markReaders } from "../../../crew/direct.ts"; |
| @@ -11,7 +12,7 @@ import { good, bad, type Tool, REPO_ARG, repoArg, isAnswer } from "../shared.ts" | ||
| 11 | 12 | |
| 12 | 13 | export const tool: Tool = { |
| 13 | 14 | name: "issue", |
| 14 | 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=`), blockedBy/blocks and `cost` (`{usd, own, 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", | |
| 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, 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", | |
| 15 | 16 | description: |
| 16 | 17 | "One issue with comments, `blockedBy`, `blocks`; non-writers' text is `untrusted`.", |
| 17 | 18 | inputSchema: { |
| @@ -83,6 +84,13 @@ export const tool: Tool = { | ||
| 83 | 84 | })), |
| 84 | 85 | commentsTotal: total, |
| 85 | 86 | commentsNext: comments.length > 0 && comments.length < total ? comments[0]!.id : null, |
| 87 | standing: (({ line, ready, before, after, moreBefore, moreAfter }) => ({ | |
| 88 | line, | |
| 89 | ready, | |
| 90 | before, | |
| 91 | after, | |
| 92 | more: moreBefore + moreAfter, | |
| 93 | }))(standingOf(db, repo, issue, user, seen)), | |
| 86 | 94 | blockedBy: deps.blockedBy.filter(seen).map(brief), |
| 87 | 95 | blocks: deps.blocks.filter(seen).map(brief), |
| 88 | 96 | ...(cost === undefined ? {} : { cost }), |
src/tui/screens/issue.ts +34 −8
| @@ -47,6 +47,8 @@ import { costLineFor } from "../../core/ledger_rollup.ts"; | ||
| 47 | 47 | import { privateRepoForSealed } from "../../actions/repos.ts"; |
| 48 | 48 | import { confirmIssue } from "../../actions/dependencies.ts"; |
| 49 | 49 | import { isCrew } from "../../core/agents.ts"; |
| 50 | import { blockerByTitle, chainLines, standingOf } from "../../core/dep_standing.ts"; | |
| 51 | import { mayView } from "../../core/sealed.ts"; | |
| 50 | 52 | import { dependenciesOf, heldBlockers } from "../../core/dependencies.ts"; |
| 51 | 53 | import { alreadyDone } from "../../core/done_on_main.ts"; |
| 52 | 54 | import { hasPicture } from "../../core/note_pictures.ts"; |
| @@ -123,6 +125,10 @@ export function readEditText(text: string): { title: string; body: string } { | ||
| 123 | 125 | |
| 124 | 126 | /** What an issue waits for and holds up, by number, ascending. */ |
| 125 | 127 | export interface Waits { |
| 128 | /** The sentence that says whether it can start and what holds it (`core/dep_standing.ts`). */ | |
| 129 | readonly standing?: string | undefined; | |
| 130 | /** The chain's nodes as lines (`chainLines`): what it waits for, then what waits for it. */ | |
| 131 | readonly chain?: readonly string[]; | |
| 126 | 132 | readonly blockedBy: readonly number[]; |
| 127 | 133 | readonly blocks: readonly number[]; |
| 128 | 134 | } |
| @@ -141,6 +147,7 @@ export function waitsParts(waits: Waits): { text: string; opens?: number }[] { | ||
| 141 | 147 | }; |
| 142 | 148 | run("Waits for", waits.blockedBy); |
| 143 | 149 | run("Holds up", waits.blocks); |
| 150 | if (waits.standing !== undefined && parts.length > 0) parts.push({ text: ` — ${waits.standing}` }); | |
| 144 | 151 | return parts; |
| 145 | 152 | } |
| 146 | 153 | |
| @@ -222,7 +229,13 @@ export function issueScreen( | ||
| 222 | 229 | held = |
| 223 | 230 | issueRow?.state === "open" ? heldBlockers(f.db, issueRow.id) : []; |
| 224 | 231 | const deps = issueRow === undefined ? undefined : dependenciesOf(f.db, issueRow.id); |
| 232 | const standing = | |
| 233 | issueRow === undefined || repo === undefined || deps === undefined | |
| 234 | ? undefined | |
| 235 | : standingOf(f.db, repo, issueRow, f.user, (i) => mayView(f.db, repo, i, f.user), new Date(), deps); | |
| 225 | 236 | waits = { |
| 237 | standing: standing?.line, | |
| 238 | chain: standing === undefined ? [] : chainLines(standing), | |
| 226 | 239 | blockedBy: deps?.blockedBy.map((i) => i.number) ?? [], |
| 227 | 240 | blocks: deps?.blocks.map((i) => i.number) ?? [], |
| 228 | 241 | }; |
| @@ -534,16 +547,24 @@ export function issueScreen( | ||
| 534 | 547 | promptScreen(ctx, screen, { |
| 535 | 548 | title: "Waits for", |
| 536 | 549 | label: `#${number} waits for issue`, |
| 537 | placeholder: "12", | |
| 550 | placeholder: "12 or words of a title", | |
| 538 | 551 | hint: |
| 539 | 552 | waits.blockedBy.length === 0 |
| 540 | ? "the number of the issue that must land first" | |
| 553 | ? "the number, or words of the title, of the issue that must land first" | |
| 541 | 554 | : "a number it already waits for stops the wait", |
| 542 | 555 | onSubmit: (value) => { |
| 543 | const n = Number(value.replace(/^#/, "")); | |
| 544 | if (!Number.isInteger(n) || n <= 0) return "an issue number, like 12"; | |
| 545 | const blocker = getIssue(f.db, target.id, n); | |
| 546 | if (blocker === undefined) return `no #${n} here`; | |
| 556 | const asNumber = Number(value.replace(/^#/, "")); | |
| 557 | let blocker: Issue | undefined; | |
| 558 | if (Number.isInteger(asNumber) && asNumber > 0) { | |
| 559 | blocker = getIssue(f.db, target.id, asNumber); | |
| 560 | if (blocker === undefined) return `no #${asNumber} here`; | |
| 561 | } else { | |
| 562 | // Words of a title, as the page's box takes them. | |
| 563 | const hit = blockerByTitle(f.db, target, issue, f.user, value); | |
| 564 | if ("says" in hit) return hit.says; | |
| 565 | blocker = hit.issue; | |
| 566 | } | |
| 567 | const n = blocker.number; | |
| 547 | 568 | // Asked now, not from the last reload: another door may have |
| 548 | 569 | // linked or unlinked since. |
| 549 | 570 | const waiting = dependenciesOf(f.db, issue.id).blockedBy.some((i) => i.id === blocker.id); |
| @@ -643,16 +664,18 @@ export function issueScreen( | ||
| 643 | 664 | const planH = planRows.length === 0 ? 0 : Math.min(planRows.length, CREW_ROWS + 2) + 2; |
| 644 | 665 | const waitsLine = waitsParts(waits); |
| 645 | 666 | const headH = waitsLine.length === 0 ? 3 : 4; |
| 667 | const chainH = Math.min(waits.chain?.length ?? 0, 5); | |
| 646 | 668 | const costH = cost === null && ledgerLine === "" && statusText === "" ? 0 : 1; |
| 647 | const [strip, head, waitRow, crewRow, costRow, planRow, body, box] = split(area, "v", [ | |
| 669 | const [strip, head, waitRow, chainRow, crewRow, costRow, planRow, body, box] = split(area, "v", [ | |
| 648 | 670 | len(whereRows(src)), |
| 649 | 671 | len(headH), |
| 650 | 672 | len(held.length === 0 ? 0 : 1), |
| 673 | len(chainH), | |
| 651 | 674 | len(crewH), |
| 652 | 675 | len(costH), |
| 653 | 676 | len(planH), |
| 654 | 677 | fill(1), |
| 655 | len(Math.min(foot, Math.max(0, area.h - 4 - headH - crewH - costH - planH - whereRows(src) - (held.length === 0 ? 0 : 1)))), | |
| 678 | len(Math.min(foot, Math.max(0, area.h - 4 - headH - crewH - chainH - costH - planH - whereRows(src) - (held.length === 0 ? 0 : 1)))), | |
| 656 | 679 | ]); |
| 657 | 680 | whereStrip(s, strip!, c, f, src); |
| 658 | 681 | const right = head!.x + head!.w; |
| @@ -733,6 +756,9 @@ export function issueScreen( | ||
| 733 | 756 | style(c.fg, c.bg), |
| 734 | 757 | waitRow!.x + waitRow!.w, |
| 735 | 758 | ); |
| 759 | (waits.chain ?? []).slice(0, chainH).forEach((line, i) => | |
| 760 | s.text(chainRow!.x, chainRow!.y + i, truncate(line, chainRow!.w), style(c.mutedFg, c.bg), chainRow!.x + chainRow!.w), | |
| 761 | ); | |
| 736 | 762 | if (crewH > 0) { |
| 737 | 763 | const inner = card(s, crewRow!, c, { |
| 738 | 764 | title: `Crew · ${plural(crew.runs.length, "run")}`, |
src/web/pages/dep_chain.ts added +42
| @@ -0,0 +1,42 @@ | ||
| 1 | /** | |
| 2 | * The chain of an issue's dependencies (#13641): what it waits for, this | |
| 3 | * issue, what waits for it, as rows in one list. Drawn from a `Standing` | |
| 4 | * (`core/dep_standing.ts`); each node is one row: a badge, a number, five | |
| 5 | * words and where it stands; who is next is its hover text. | |
| 6 | */ | |
| 7 | import type { Badge, Standing, StandingNode } from "../../core/dep_standing.ts"; | |
| 8 | import { html, type Html } from "../html.ts"; | |
| 9 | import { tellHref } from "../studio/nouns.ts"; | |
| 10 | import { badge, type Tone } from "../ui.ts"; | |
| 11 | ||
| 12 | const TONE: Record<Badge, Tone> = { queued: "default", running: "attn", ok: "success", held: "danger" }; | |
| 13 | ||
| 14 | function nodeView(base: string, n: StandingNode): Html { | |
| 15 | ||
| 16 | return html`<li class="chain-node" data-badge="${n.badge}" ${n.quiet ? html`data-quiet` : null} ${n.holding ? html`data-holding` : null}> | |
| 17 | <a href="${tellHref(base, n.number)}" title="${n.next === "" ? "" : `next: ${n.next}`}"> | |
| 18 | ${badge(n.badge, { tone: TONE[n.badge] })} | |
| 19 | <span class="chain-no">#${n.number}</span> | |
| 20 | <span class="chain-title">${n.title}</span> | |
| 21 | <span class="chain-word">${n.word}${n.holding ? " · holding this" : ""}</span> | |
| 22 | </a> | |
| 23 | </li>`; | |
| 24 | } | |
| 25 | ||
| 26 | function column(base: string, label: string, nodes: readonly StandingNode[], more: number): Html { | |
| 27 | return html`<ol class="chain-col" aria-label="${label}"> | |
| 28 | ${nodes.map((n) => nodeView(base, n))} | |
| 29 | ${more > 0 ? html`<li class="chain-more muted small">+${more} more</li>` : null} | |
| 30 | </ol>`; | |
| 31 | } | |
| 32 | ||
| 33 | /** The chain, or nothing when the issue has neither blockers nor dependents. */ | |
| 34 | export function chain(base: string, issue: { number: number }, s: Standing): Html | null { | |
| 35 | if ((s.before[0] ?? []).length === 0 && s.after.length === 0) return null; | |
| 36 | const levels = [...s.before].reverse(); | |
| 37 | return html`<div class="chain" role="group" aria-label="Dependencies"> | |
| 38 | ${levels.map((level, i) => column(base, i === levels.length - 1 ? "Waits for" : "Waits for, further back", level, i === levels.length - 1 ? s.moreBefore : 0))} | |
| 39 | <div class="chain-self" aria-current="true"><span class="chain-no">#${issue.number}</span> this</div> | |
| 40 | ${s.after.length === 0 ? null : column(base, "Waits for this", s.after, s.moreAfter)} | |
| 41 | </div>`; | |
| 42 | } |
src/web/pages/home_flow.ts +3
| @@ -138,6 +138,9 @@ function tile(i: LaneView["items"][number], now: number): Html { | ||
| 138 | 138 | ><span class="tile-clock">${age(i.since, now)}</span></span |
| 139 | 139 | > |
| 140 | 140 | <span class="tile-title">${i.title}</span> |
| 141 | ${i.waits === undefined || i.waits.length === 0 | |
| 142 | ? null | |
| 143 | : html`<span class="tile-waits">waits for ${i.waits.slice(0, 3).map((n) => `#${n}`).join(", ")}${i.waits.length > 3 ? ` +${i.waits.length - 3}` : ""}</span>`} | |
| 141 | 144 | <span class="tile-hint" |
| 142 | 145 | >${i.who === "" |
| 143 | 146 | ? "" |
src/web/pages/home_flow_style.ts +2 −1
| @@ -65,7 +65,7 @@ export const homeFlowCss = /* css */ ` | ||
| 65 | 65 | .tile-clock { flex: none; color: var(--muted-fg); font-variant-numeric: tabular-nums; } |
| 66 | 66 | .tile[data-state="active"] .tile-clock::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 6px; vertical-align: 1px; border-radius: 999px; background: var(--accent); animation: hf-pulse 1.8s ease-in-out infinite; } |
| 67 | 67 | .tile-title { display: -webkit-box; overflow: hidden; font-size: 13px; line-height: 18px; overflow-wrap: anywhere; -webkit-line-clamp: 2; -webkit-box-orient: vertical; } |
| 68 | .tile-hint { font-size: var(--fs-min); line-height: 16px; color: var(--muted-fg); } | |
| 68 | .tile-hint, .tile-waits { font-size: var(--fs-min); line-height: 16px; color: var(--muted-fg); } | |
| 69 | 69 | .tile-who { font-weight: 600; color: var(--fg); } |
| 70 | 70 | .tile[data-new] { animation: hf-arrive 900ms var(--ease); } |
| 71 | 71 | .lane-more { margin: 0; padding-inline: 4px; font-size: 13px; } |
| @@ -99,6 +99,7 @@ export const homeFlowCss = /* css */ ` | ||
| 99 | 99 | .tile-title { grid-area: title; } |
| 100 | 100 | .tile-app { grid-area: app; } |
| 101 | 101 | .tile-clock { grid-area: clock; } |
| 102 | .tile-waits { grid-column: 1 / -1; } | |
| 102 | 103 | .tile-hint { grid-area: hint; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } |
| 103 | 104 | .lane-health { display: -webkit-box; overflow: hidden; -webkit-line-clamp: 2; -webkit-box-orient: vertical; } |
| 104 | 105 | .tile-title { -webkit-line-clamp: 1; line-clamp: 1; } |
src/web/pages/thread.ts +53 −21
| @@ -18,10 +18,13 @@ import { listTeams } from "../../core/teams.ts"; | ||
| 18 | 18 | import { listCrew } from "../../actions/crew.ts"; |
| 19 | 19 | import { |
| 20 | 20 | confirmIssue, |
| 21 | dependencyWords, | |
| 21 | 22 | linkIssue, |
| 22 | 23 | unlinkIssue, |
| 23 | 24 | } from "../../actions/dependencies.ts"; |
| 24 | 25 | import { dependenciesOf } from "../../core/dependencies.ts"; |
| 26 | import { blockerByTitle, cyclePath, standingOf } from "../../core/dep_standing.ts"; | |
| 27 | import { chain } from "./dep_chain.ts"; | |
| 25 | 28 | import { isCrew } from "../../core/agents.ts"; |
| 26 | 29 | import { |
| 27 | 30 | assignIssue, |
| @@ -1190,9 +1193,11 @@ export function dependenciesCard( | ||
| 1190 | 1193 | issue: Issue, |
| 1191 | 1194 | action: string, |
| 1192 | 1195 | ): Html { |
| 1193 | const { blockedBy, blocks } = dependenciesOf(ctx.app.db, issue.id); | |
| 1196 | const direct = dependenciesOf(ctx.app.db, issue.id); | |
| 1197 | const { blockedBy } = direct; | |
| 1194 | 1198 | const base = repoBase(repo); |
| 1195 | 1199 | const user = ctx.auth.user; |
| 1200 | const standing = standingOf(ctx.app.db, repo, issue, user, (i) => mayView(ctx.app.db, repo, i, user), new Date(), direct); | |
| 1196 | 1201 | const mayEdit = |
| 1197 | 1202 | user !== undefined && |
| 1198 | 1203 | (canWrite(ctx.app.db, repo, user) || isCrew(ctx.app.db, repo.id, user.id)); |
| @@ -1234,22 +1239,12 @@ export function dependenciesCard( | ||
| 1234 | 1239 | </li>`, |
| 1235 | 1240 | )} |
| 1236 | 1241 | </ul>`; |
| 1237 | const openBlockers = blockedBy.filter((i) => i.state === "open").length; | |
| 1238 | const waits = | |
| 1239 | openBlockers === 0 | |
| 1240 | ? `Waits for ${blockedBy.length}, all done` | |
| 1241 | : openBlockers === blockedBy.length | |
| 1242 | ? `Waits for ${blockedBy.length}` | |
| 1243 | : `Waits for ${blockedBy.length}, ${openBlockers} still open`; | |
| 1244 | const holds = `Holds up ${blocks.length}`; | |
| 1245 | const body = html`${blockedBy.length === 0 | |
| 1246 | ? html`<p class="muted small">Waits for nothing.</p>` | |
| 1247 | : html`<p class="small">${waits}</p> | |
| 1248 | ${list(blockedBy, true)}`} | |
| 1249 | ${blocks.length === 0 | |
| 1250 | ? null | |
| 1251 | : html`<p class="small mt">${holds}</p> | |
| 1252 | ${list(blocks, false)}`} | |
| 1242 | const body = html`<p class="dep-line" data-ready="${standing.ready ? "yes" : "no"}">${standing.line}</p> | |
| 1243 | ${chain(base, issue, standing)} | |
| 1244 | ${mayEdit && blockedBy.length > 0 | |
| 1245 | ? html`<p class="small mt">Change what it waits for</p> | |
| 1246 | ${list(blockedBy, true)}` | |
| 1247 | : null} | |
| 1253 | 1248 | ${mayEdit |
| 1254 | 1249 | ? html`<form method="post" action="${action}" class="edit-row mt"> |
| 1255 | 1250 | <label class="sr-only" for="f-blocked-by" |
| @@ -1260,8 +1255,9 @@ export function dependenciesCard( | ||
| 1260 | 1255 | id="f-blocked-by" |
| 1261 | 1256 | name="blockedBy" |
| 1262 | 1257 | inputmode="numeric" |
| 1263 | placeholder="#" | |
| 1264 | aria-label="Issue number this one waits for" | |
| 1258 | placeholder="# or words of a title" | |
| 1259 | aria-label="Issue number or title this one waits for" | |
| 1260 | autocomplete="off" | |
| 1265 | 1261 | /> |
| 1266 | 1262 | ${btn("Waits for", { type: "submit", size: "sm" })} |
| 1267 | 1263 | </form>` |
| @@ -1297,7 +1293,14 @@ export async function dependencySubmit(ctx: Ctx): Promise<Response> { | ||
| 1297 | 1293 | : confirm !== "" |
| 1298 | 1294 | ? confirm |
| 1299 | 1295 | : field(form, "blockedBy").trim(); |
| 1300 | const number = Number(raw.replace(/^#/, "")); | |
| 1296 | const wanted = raw.replace(/^#/, "").trim(); | |
| 1297 | const number = /^\d{1,9}$/.test(wanted) ? Number(wanted) : Number.NaN; | |
| 1298 | // Words of a title find the one open issue they name; more than one is asked to be narrowed. | |
| 1299 | if (Number.isNaN(number) && wanted.length >= 2 && unlink === "" && confirm === "") { | |
| 1300 | const hit = blockerByTitle(ctx.app.db, found.repo, found.issue, ctx.auth.user, wanted); | |
| 1301 | if ("says" in hit) return flashTo(ctx, dest, { tone: "danger", message: hit.says }); | |
| 1302 | return linkWith(ctx, found, dest, hit.issue); | |
| 1303 | } | |
| 1301 | 1304 | const other = |
| 1302 | 1305 | Number.isInteger(number) && number > 0 |
| 1303 | 1306 | ? getIssue(ctx.app.db, found.repo.id, number) |
| @@ -1316,7 +1319,7 @@ export async function dependencySubmit(ctx: Ctx): Promise<Response> { | ||
| 1316 | 1319 | if (!result.ok) { |
| 1317 | 1320 | const words: Record<string, string> = { |
| 1318 | 1321 | self: "An issue cannot wait for itself.", |
| 1319 | cycle: `#${other.number} already waits for this one, directly or through others; linking would make a loop.`, | |
| 1322 | cycle: cycleSays(ctx, found.repo, found.issue, other), | |
| 1320 | 1323 | cross_repo: "Dependencies stay inside one repository.", |
| 1321 | 1324 | not_an_issue: "Only issues can depend on issues.", |
| 1322 | 1325 | forbidden: THREAD_SAYS.planForbidden, |
| @@ -1335,3 +1338,32 @@ export async function dependencySubmit(ctx: Ctx): Promise<Response> { | ||
| 1335 | 1338 | : `#${found.issue.number} waits for #${other.number}.`, |
| 1336 | 1339 | }); |
| 1337 | 1340 | } |
| 1341 | ||
| 1342 | /** The refusal that names the loop: "#9 waits for #4, which waits for #7 (this one)". */ | |
| 1343 | function cycleSays(ctx: Ctx, repo: Repo, issue: Issue, other: Issue): string { | |
| 1344 | const path = cyclePath(ctx.app.db, issue, other, (i) => mayView(ctx.app.db, repo, i, ctx.auth.user)); | |
| 1345 | if (path.length < 2) return `#${other.number} already waits for this one; linking would make a loop.`; | |
| 1346 | const steps = path.map((n) => (n === null ? "…" : n === issue.number ? `#${n} (this one)` : `#${n}`)); | |
| 1347 | return `That would make a loop: ${steps.join(" waits for ")}, and this one would wait for #${other.number}.`; | |
| 1348 | } | |
| 1349 | ||
| 1350 | /** Link `issue` to wait for `other` and say what happened, as the number path does. */ | |
| 1351 | async function linkWith( | |
| 1352 | ctx: Ctx, | |
| 1353 | found: { repo: Repo; issue: Issue }, | |
| 1354 | dest: string, | |
| 1355 | other: Issue, | |
| 1356 | ): Promise<Response> { | |
| 1357 | const result = linkIssue(ctx.app, ctx.auth.user, found.repo, found.issue, other); | |
| 1358 | if (!result.ok) | |
| 1359 | return flashTo(ctx, dest, { | |
| 1360 | tone: "danger", | |
| 1361 | message: | |
| 1362 | result.error === "cycle" | |
| 1363 | ? cycleSays(ctx, found.repo, found.issue, other) | |
| 1364 | : result.error === "forbidden" | |
| 1365 | ? THREAD_SAYS.planForbidden | |
| 1366 | : (dependencyWords[result.error] ?? "That could not be linked."), | |
| 1367 | }); | |
| 1368 | return flashTo(ctx, dest, { message: `#${found.issue.number} waits for #${other.number}.` }); | |
| 1369 | } |
src/web/style/components.ts +10
| @@ -1294,4 +1294,14 @@ ul.list { overflow-anchor: none; } | ||
| 1294 | 1294 | } |
| 1295 | 1295 | .btn[aria-busy="true"] .ico-loader { opacity: .6; } |
| 1296 | 1296 | } |
| 1297 | ||
| 1298 | /* ---- dependency chain: what it waits for -> this -> what waits for it, as rows ---- */ | |
| 1299 | .dep-line { margin: 0 0 8px; font-weight: 600; } | |
| 1300 | .chain { padding: 4px 16px 8px; } | |
| 1301 | .chain-col { margin: 0; padding: 0; list-style: none; } | |
| 1302 | .chain-node a { display: block; min-height: 44px; padding: 6px 0; color: var(--fg); } | |
| 1303 | .chain-no, .chain-word { color: var(--muted-fg); } | |
outdated
DESIGN.md 6/7: a bordered box around every node. Rows over boxes; use a hairline where it ends or none. |
||
| 1304 | .chain-node[data-quiet] a { opacity: .6; text-decoration: line-through; } | |
| 1305 | .chain-node[data-holding] a { font-weight: 600; } | |
| 1306 | .chain-self { padding: 6px 0; font-weight: 600; } | |
| 1297 | 1307 | `; |
test/dep-standing.test.ts added +171
| @@ -0,0 +1,171 @@ | ||
| 1 | /** | |
| 2 | * The standing of an issue among its dependencies (#13641): the sentence, the chain, the cycle | |
| 3 | * path, the lanes' "waits for". | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 6 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { createApp, type App } from "../src/app.ts"; | |
| 10 | import { openIssue, setIssueState } from "../src/actions/issues.ts"; | |
| 11 | import { createRepo } from "../src/actions/repos.ts"; | |
| 12 | import { addDependency, dependenciesOf } from "../src/core/dependencies.ts"; | |
| 13 | import { blockerByTitle, chainLines, cyclePath, fiveWords, openBlockerNumbers, standingOf } from "../src/core/dep_standing.ts"; | |
| 14 | import { getIssue, type Issue } from "../src/core/issues.ts"; | |
| 15 | import type { Repo } from "../src/core/repos.ts"; | |
| 16 | import { createUser, type User } from "../src/core/users.ts"; | |
| 17 | import { withWaits, type LaneItem } from "../src/flow/lanes_read.ts"; | |
| 18 | import { chain } from "../src/web/pages/dep_chain.ts"; | |
| 19 | ||
| 20 | describe("dependency standing", () => { | |
| 21 | let dir: string; | |
| 22 | let app: App; | |
| 23 | let alice: User; | |
| 24 | let repo: Repo; | |
| 25 | const made: Issue[] = []; | |
| 26 | const n = (i: number) => getIssue(app.db, repo.id, made[i - 1]!.number)!; | |
| 27 | const stand = (i: number) => standingOf(app.db, repo, n(i), alice); | |
| 28 | ||
| 29 | beforeAll(async () => { | |
| 30 | dir = await mkdtemp(join(tmpdir(), "forge-standing-")); | |
| 31 | app = createApp({ dataDir: dir, port: 0 }); | |
| 32 | const a = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 33 | if (!a.ok) throw new Error(a.error); | |
| 34 | alice = a.value; | |
| 35 | const r = await createRepo(app, alice, { name: "plan", visibility: "private" }); | |
| 36 | if (!r.ok) throw new Error(String(r.error)); | |
| 37 | repo = r.value; | |
| 38 | for (let i = 1; i <= 16; i++) { | |
| 39 | const o = openIssue(app, alice, repo, { title: `Issue ${i} has a rather long title indeed` }); | |
| 40 | if (!o.ok) throw new Error(String(o.error)); | |
| 41 | made.push(o.value); | |
| 42 | } | |
| 43 | }); | |
| 44 | afterAll(async () => { | |
| 45 | app.close(); | |
| 46 | await rm(dir, { recursive: true, force: true }); | |
| 47 | }); | |
| 48 | ||
| 49 | test("no dependencies: ready, and no chain", () => { | |
| 50 | const s = stand(1); | |
| 51 | expect(s.line).toBe("Ready."); | |
| 52 | expect(s.ready).toBe(true); | |
| 53 | expect(chain("/alice/plan", n(1), s)).toBeNull(); | |
| 54 | }); | |
| 55 | ||
| 56 | test("one live blocker holds it and is emphasised; five words of title", () => { | |
| 57 | addDependency(app.db, n(2), n(3), alice.id); | |
| 58 | const s = stand(2); | |
| 59 | expect(s.line).toBe("Waits for #3 (queued)."); | |
| 60 | expect(s.ready).toBe(false); | |
| 61 | const node = s.before[0]![0]!; | |
| 62 | expect(node).toMatchObject({ number: 3, badge: "queued", holding: true, quiet: false, next: "the queue" }); | |
| 63 | expect(node.title).toBe("Issue 3 has a rather…"); | |
| 64 | expect(fiveWords("one two three")).toBe("one two three"); | |
| 65 | expect(String(chain("/alice/plan", n(2), s))).toContain("data-holding"); | |
| 66 | }); | |
| 67 | ||
| 68 | test("a chain three deep reaches two levels back", () => { | |
| 69 | addDependency(app.db, n(3), n(4), alice.id); | |
| 70 | const s = stand(2); | |
| 71 | expect(s.before).toHaveLength(2); | |
| 72 | expect(s.before[1]![0]!.number).toBe(4); | |
| 73 | // The nearer blocker waits for others itself: held, not running. | |
| 74 | expect(s.before[0]![0]!.badge).toBe("held"); | |
| 75 | expect(s.after).toHaveLength(0); | |
| 76 | expect(stand(4).after.map((x) => x.number)).toEqual([3]); | |
| 77 | }); | |
| 78 | ||
| 79 | test("closed and landed blockers are quiet and nothing holds it", () => { | |
| 80 | addDependency(app.db, n(5), n(6), alice.id); | |
| 81 | addDependency(app.db, n(5), n(7), alice.id); | |
| 82 | expect(stand(5).line).toBe("Waits for 2 issues; the nearest to done is #6 (queued)."); | |
| 83 | setIssueState(app, alice, repo, n(6), "closed"); | |
| 84 | setIssueState(app, alice, repo, n(7), "closed"); | |
| 85 | const s = stand(5); | |
| 86 | expect(s.line).toBe("Nothing holds this: its two blockers have landed."); | |
| 87 | expect(s.ready).toBe(true); | |
| 88 | expect(s.before[0]!.every((x) => x.quiet && x.badge === "ok")).toBe(true); | |
| 89 | expect(String(chain("/alice/plan", n(5), s))).toContain("data-quiet"); | |
| 90 | }); | |
| 91 | ||
| 92 | test("a blocker closed as dropped still holds until confirmed", () => { | |
| 93 | addDependency(app.db, n(8), n(9), alice.id); | |
| 94 | setIssueState(app, alice, repo, n(9), "closed", { reason: "dropped" }); | |
| 95 | const s = stand(8); | |
| 96 | expect(s.ready).toBe(false); | |
| 97 | expect(s.before[0]![0]!.badge).toBe("held"); | |
| 98 | expect(s.line).toContain("#9"); | |
| 99 | }); | |
| 100 | ||
| 101 | test("seven dependents fold to three and '+4 more'", () => { | |
| 102 | for (const i of [1, 11, 12, 13, 14, 15, 16]) addDependency(app.db, n(i), n(10), alice.id); | |
| 103 | const s = stand(10); | |
| 104 | expect(s.after).toHaveLength(3); | |
| 105 | expect(s.moreAfter).toBe(4); | |
| 106 | expect(String(chain("/alice/plan", n(10), s))).toContain(`+${s.moreAfter} more`); | |
| 107 | }); | |
| 108 | ||
| 109 | test("a cycle's path is named", () => { | |
| 110 | // 2 waits for 3, 3 waits for 4: linking 4 to wait for 2 closes it. | |
| 111 | expect(cyclePath(app.db, n(4), n(2))).toEqual([2, 3, 4]); | |
| 112 | expect(cyclePath(app.db, n(1), n(2))).toEqual([]); | |
| 113 | }); | |
| 114 | ||
| 115 | test("a cycle's path hides the steps the viewer may not see", () => { | |
| 116 | expect(cyclePath(app.db, n(4), n(2), (i) => i.number !== n(3).number)).toEqual([n(2).number, null, n(4).number]); | |
| 117 | }); | |
| 118 | ||
| 119 | test("words of a title name the one open issue, or say why not", () => { | |
| 120 | const by = (words: string) => blockerByTitle(app.db, repo, n(1), alice, words); | |
| 121 | expect(by("Issue 12 has")).toMatchObject({ issue: { number: n(12).number } }); | |
| 122 | expect(by("rather long")).toEqual({ says: expect.stringContaining("More than five issues match") }); | |
| 123 | expect(by("zzzz")).toEqual({ says: 'No open issue here has "zzzz" in its title.' }); | |
| 124 | expect(by("x")).toEqual({ says: expect.stringContaining("two or more letters") }); | |
| 125 | // The issue itself is never offered, and a closed one is not open. | |
| 126 | expect(by("Issue 1 has")).toEqual({ says: 'No open issue here has "Issue 1 has" in its title.' }); | |
| 127 | expect(by("Issue 6 has")).toEqual({ says: 'No open issue here has "Issue 6 has" in its title.' }); | |
| 128 | }); | |
| 129 | ||
| 130 | test("the chain as terminal lines: furthest back first, the holder named, the folds counted", () => { | |
| 131 | const lines = chainLines(stand(2)); | |
| 132 | expect(lines[0]).toStartWith(" and before that #4 "); | |
| 133 | expect(lines[1]).toContain("waits for #3"); | |
| 134 | expect(lines[1]).toContain("holding this"); | |
| 135 | expect(lines[1]).toContain("next: "); | |
| 136 | expect(chainLines(stand(10)).at(-1)).toBe("held up: +4 more"); | |
| 137 | expect(chainLines(stand(14))).toEqual([expect.stringContaining("waits for #10")]); | |
| 138 | }); | |
| 139 | ||
| 140 | test("a read the page already made is not made again", () => { | |
| 141 | const direct = dependenciesOf(app.db, n(2).id); | |
| 142 | let reads = 0; | |
| 143 | const counting = new Proxy(app.db, { | |
| 144 | get: (db, key) => { | |
| 145 | if (key === "query") reads++; | |
| 146 | const v = Reflect.get(db, key) as unknown; | |
| 147 | return typeof v === "function" ? (v as (...a: unknown[]) => unknown).bind(db) : v; | |
| 148 | }, | |
| 149 | }); | |
| 150 | standingOf(counting, repo, n(2), alice, () => true, new Date(), direct); | |
| 151 | const given = reads; | |
| 152 | reads = 0; | |
| 153 | standingOf(counting, repo, n(2), alice); | |
| 154 | expect(reads).toBeGreaterThan(given); | |
| 155 | }); | |
| 156 | ||
| 157 | test("open blockers' numbers, for the lanes' 'waits for #N'", () => { | |
| 158 | const got = openBlockerNumbers(app.db, [n(2).id, n(5).id, n(3).id]); | |
| 159 | expect(got.get(n(2).id)).toEqual([3]); | |
| 160 | expect(got.has(n(5).id)).toBe(false); // both closed | |
| 161 | expect(got.get(n(3).id)).toEqual([4]); | |
| 162 | }); | |
| 163 | ||
| 164 | test("a lane tile held by an open dependency carries waits for #N", () => { | |
| 165 | const tile = (i: Issue): LaneItem => ({ key: `i-${i.id}`, repoId: repo.id, kind: "issue", number: i.number, title: i.title, sealed: false, who: "", since: "", state: "waiting", hint: "", position: null, beat: null, issueId: i.id, born: null }); | |
| 166 | const empty = { items: [], total: 0 }; | |
| 167 | const lanes = withWaits(app.db, { building: { items: [tile(n(2)), tile(n(5))], total: 2 }, checks: empty, review: empty, landing: empty, live: empty }); | |
| 168 | expect(lanes.building.items[0]!.waits).toEqual([3]); | |
| 169 | expect(lanes.building.items[1]!.waits).toBeUndefined(); | |
| 170 | }); | |
| 171 | }); |
test/dependencies.test.ts +37 −1
| @@ -294,7 +294,8 @@ describe("dependencies", () => { | ||
| 294 | 294 | await fetch(`${base}/alice/engine/issues/5`, { headers: { cookie } }) |
| 295 | 295 | ).text(); |
| 296 | 296 | expect(page).toContain("Waits for 2"); |
| 297 | expect(page).toContain("Holds up 1"); | |
| 297 | expect(page).toContain("Waits for 2 issues; the nearest to done is #"); | |
| 298 | expect(page).toContain('aria-label="Waits for this"'); | |
| 298 | 299 | expect(page).toContain('href="/alice/engine/map"'); |
| 299 | 300 | |
| 300 | 301 | const map = await ( |
| @@ -317,5 +318,40 @@ describe("dependencies", () => { | ||
| 317 | 318 | expect( |
| 318 | 319 | dependenciesOf(app.db, issue(7).id).blockedBy.map((i) => i.number), |
| 319 | 320 | ).toEqual([6]); |
| 321 | ||
| 322 | // Words of a title link the one issue they name (#13641). | |
| 323 | const byTitle = await fetch(`${base}/alice/engine/issues/7/dependencies`, { | |
| 324 | method: "POST", | |
| 325 | headers: { cookie, origin: base }, | |
| 326 | body: new URLSearchParams({ blockedBy: "Input layer" }), | |
| 327 | redirect: "manual", | |
| 328 | }); | |
| 329 | expect(byTitle.status).toBe(303); | |
| 330 | expect(dependenciesOf(app.db, issue(7).id).blockedBy.map((i) => i.number)).toEqual([2, 6]); | |
| 331 | ||
| 332 | // A cycle is refused with the path that would close it. | |
| 333 | const loop = await fetch(`${base}/alice/engine/issues/6/dependencies`, { | |
| 334 | method: "POST", | |
| 335 | headers: { cookie, origin: base }, | |
| 336 | body: new URLSearchParams({ blockedBy: "7" }), | |
| 337 | redirect: "manual", | |
| 338 | }); | |
| 339 | const flashed = await (await fetch(`${base}${new URL(loop.headers.get("location")!, base).pathname}`, { headers: { cookie: `${cookie}; ${(loop.headers.getSetCookie() ?? []).map((c) => c.split(";")[0]).join("; ")}` } })).text(); | |
| 340 | expect(flashed).toContain("That would make a loop: #7 waits for #6 (this one)"); | |
| 341 | ||
| 342 | // Two matches ask for the number; none says so; neither links anything. | |
| 343 | const flashOf = async (words: string): Promise<string> => { | |
| 344 | const res = await fetch(`${base}/alice/engine/issues/7/dependencies`, { | |
| 345 | method: "POST", | |
| 346 | headers: { cookie, origin: base }, | |
| 347 | body: new URLSearchParams({ blockedBy: words }), | |
| 348 | redirect: "manual", | |
| 349 | }); | |
| 350 | const set = (res.headers.getSetCookie() ?? []).map((c) => c.split(";")[0]).join("; "); | |
| 351 | return (await fetch(new URL(res.headers.get("location")!, base), { headers: { cookie: `${cookie}; ${set}` } })).text(); | |
| 352 | }; | |
| 353 | expect(await flashOf("ph")).toContain("2 issues match "ph": #3, #4. Type the number."); | |
| 354 | expect(await flashOf("zzzz")).toContain("No open issue here has "zzzz" in its title."); | |
| 355 | expect(dependenciesOf(app.db, issue(7).id).blockedBy.map((i) => i.number)).toEqual([2, 6]); | |
| 320 | 356 | }); |
| 321 | 357 | }); |
test/mcp.test.ts +8
| @@ -693,6 +693,14 @@ describe("the forge over MCP", () => { | ||
| 693 | 693 | blockedBy: [{ number: first.number, title: "first", state: "open" }], |
| 694 | 694 | blocks: [], |
| 695 | 695 | }); |
| 696 | // The sentence and the chain the page draws (#13641). | |
| 697 | expect(read.standing).toMatchObject({ | |
| 698 | line: `Waits for #${first.number} (queued).`, | |
| 699 | ready: false, | |
| 700 | before: [[{ number: first.number, badge: "queued", holding: true }]], | |
| 701 | after: [], | |
| 702 | more: 0, | |
| 703 | }); | |
| 696 | 704 | expect(read.comments.map((c: any) => [c.author, c.authorIsAgent, c.body])).toEqual([ |
| 697 | 705 | ["alice", false, "one"], |
| 698 | 706 | ["issuebot", true, "two"], |
test/tui-issue-waits.test.ts +23
| @@ -127,6 +127,29 @@ describe("the terminal's issue screen and its waits", () => { | ||
| 127 | 127 | } |
| 128 | 128 | }); |
| 129 | 129 | |
| 130 | test("the sentence and the chain show on the screen, and w takes words of a title", async () => { | |
| 131 | const blocker = newIssue("Dig the trenches"); | |
| 132 | const issue = newIssue("Lay the pipes"); | |
| 133 | const t = await open(alice, issue.number); | |
| 134 | try { | |
| 135 | await t.press("w"); | |
| 136 | await t.type("trenches"); | |
| 137 | await t.press("enter"); | |
| 138 | expect(waitsFor(issue)).toEqual([blocker.number]); | |
| 139 | // The sentence ends the waits line; the node is a row under it. | |
| 140 | expect(t.text()).toContain(`Waits for #${blocker.number} (queued).`); | |
| 141 | expect(t.text()).toContain(`waits for #${blocker.number} Dig the trenches - queued · holding this · next: the queue`); | |
| 142 | // Words that name nothing stay in the prompt and say so. | |
| 143 | await t.press("w"); | |
| 144 | await t.type("nonesuch"); | |
| 145 | await t.press("enter"); | |
| 146 | expect(t.text()).toContain('No open issue here has "nonesuch" in its title.'); | |
| 147 | expect(waitsFor(issue)).toEqual([blocker.number]); | |
| 148 | } finally { | |
| 149 | t.stop(); | |
| 150 | } | |
| 151 | }); | |
| 152 | ||
| 130 | 153 | test("w on a number it already waits for asks, then unlinks", async () => { |
| 131 | 154 | const blocker = newIssue("Buy seeds"); |
| 132 | 155 | const issue = newIssue("Sow"); |
new above
offline
Muddled nested condition. Say: if there are no blockers and no dependents, return null.