Public: anyone can read this; the crew can change it.
Live triage: open means someone will act, closed means done on main or decided - kept true continuously, in the background #3245
scout/forge:scout/3242-live-triage-open-means-someone-will-act → main 5 commits fork 2 threads · 2 unresolved
6 files
changed +157
−6
README.md +6
| @@ -823,6 +823,12 @@ configured leaves it with you. Undo for a day (`/api/v1/asks/decide/<id>/undo`, | ||
| 823 | 823 | `asks_undecide`, `U`). Each tap is a paid call, so one card is handed over |
| 824 | 824 | once in ten minutes. |
| 825 | 825 | |
| 826 | **Waiting on you.** Home and the terminal dashboard show `waiting on you: N, | |
| 827 | oldest X h`: open agent pulls whose check at the head passed, that nobody holds, | |
| 828 | opened a day or more ago (age from opening, so a comment does not reset it). It | |
| 829 | sits under the figures, not in them, as plain muted text. The per-tick pass that | |
| 830 | closes, folds and files issues is `crew/livetriage.ts`. | |
| 831 | ||
| 826 | 832 | **The standing rule** says who answers a repository's hand-overs without a |
| 827 | 833 | tap, three ways: `me` (the default: they wait for you), `decider` (the sweep |
| 828 | 834 | asks the decider about each parked card and its word stands, whatever its |
src/flow/kpi_words.ts +7
| @@ -99,11 +99,17 @@ export function reactNote(r: Reach): string { | ||
| 99 | 99 | return r.inpP75 === null ? "no taps measured yet" : `reacts in ${speedWords(r.inpP75)}`; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | /** `waiting on you: 2, oldest 50 h`, the one figure for agent pulls a person has left a day; null when none wait. */ | |
| 103 | export function waitingWords(w: Kpis["waiting"]): string | null { | |
| 104 | return w === undefined || w.count === 0 ? null : `waiting on you: ${w.count}, oldest ${w.oldestHours} h`; | |
| 105 | } | |
| 106 | ||
| 102 | 107 | /** |
| 103 | 108 | * The terminal's row: the same figures in the same words, as plain |
| 104 | 109 | * lines. Forge-wide like the web's, so the caller shows them to an admin only. |
| 105 | 110 | */ |
| 106 | 111 | export function kpiLines(k: Kpis, live: { sha: string; since: string } | null, now: Date = new Date()): string[] { |
| 112 | const waiting = waitingWords(k.waiting); | |
| 107 | 113 | return [ |
| 108 | 114 | `Shipped per hour ${(k.landed / k.landedHours.length).toFixed(1)} ${sparkText(k.landedHours)} ${k.landed} ${k.landed === 1 ? "change" : "changes"} in 24 h`, |
| 109 | 115 | `Live version ${live === null ? "— nothing live yet" : `${live.sha.slice(0, 7)}, live ${live.since}`}`, |
| @@ -114,5 +120,6 @@ export function kpiLines(k: Kpis, live: { sha: string; since: string } | null, n | ||
| 114 | 120 | `Visitors ${visitorsValue(k.reach)}, ${visitorsNote(k.reach)} ${trendText(k.reach.visitorDays)} 30 days`, |
| 115 | 121 | `Accounts ${usersValue(k.reach)} signed in today`, |
| 116 | 122 | `Page speed ${k.reach.loadP75 === null ? "no page views measured yet" : `loads in ${speedWords(k.reach.loadP75)}`}, ${reactNote(k.reach)}`, |
| 123 | ...(waiting === null ? [] : [waiting[0]!.toUpperCase() + waiting.slice(1)]), | |
| 117 | 124 | ]; |
| 118 | 125 | } |
src/flow/kpis.ts +21
| @@ -36,6 +36,8 @@ export interface Kpis { | ||
| 36 | 36 | readonly spend: { readonly todayUsd: number; readonly ceilingUsd: number | null }; |
| 37 | 37 | /** When a snapshot was last known off the machine (a bucket destination or the mirror, `off_box.ts`); null when never. */ |
| 38 | 38 | readonly backupAt: string | null; |
| 39 | /** Open pulls an agent wrote that no person has touched in a day: how many, and the oldest's age in hours. */ | |
| 40 | readonly waiting?: { readonly count: number; readonly oldestHours: number }; | |
| 39 | 41 | /** Accounts, visitors and page speed (`reach.ts`). */ |
| 40 | 42 | readonly reach: Reach; |
| 41 | 43 | } |
| @@ -94,10 +96,29 @@ export function readKpis( | ||
| 94 | 96 | |
| 95 | 97 | const todayUsd = spentTodayEverywhere(db, now); |
| 96 | 98 | |
| 99 | // Awaiting a person: an agent's open pull whose check at its head passed and | |
| 100 | // that nobody holds, opened a day ago. The clock is `created_at`, which no | |
| 101 | // comment or bot touch resets; a pull still on checks or on the builder is not here. | |
| 102 | const idle = db | |
| 103 | .query<{ n: number; oldest: string | null }, [string]>( | |
| 104 | `SELECT COUNT(*) AS n, MIN(i.created_at) AS oldest | |
| 105 | FROM issue i JOIN pull p ON p.issue_id = i.id JOIN user u ON u.id = i.author_id JOIN repo r ON r.id = i.repo_id | |
| 106 | WHERE i.kind = 'pull' AND i.state = 'open' AND p.merged_at IS NULL AND u.is_agent = 1 | |
| 107 | AND r.archived_at IS NULL AND i.created_at <= ?1 | |
| 108 | AND EXISTS (SELECT 1 FROM run c WHERE c.kind = 'check' AND c.state = 'ok' AND c.repo_id = i.repo_id AND c.commit_oid = p.head_oid) | |
| 109 | AND NOT EXISTS (SELECT 1 FROM pull_hold h WHERE h.issue_id = i.id AND h.released_at IS NULL)`, | |
| 110 | ) | |
| 111 | .get(new Date(end - 24 * HOUR_MS).toISOString()); | |
| 112 | const waiting = { | |
| 113 | count: idle?.n ?? 0, | |
| 114 | oldestHours: idle?.oldest ? Math.floor((end - Date.parse(idle.oldest)) / HOUR_MS) : 0, | |
| 115 | }; | |
| 116 | ||
| 97 | 117 | const backupAt = forge.dataDir === undefined ? null : lastOffBox(forge.dataDir); |
| 98 | 118 | |
| 99 | 119 | return { |
| 100 | 120 | backupAt, |
| 121 | waiting, | |
| 101 | 122 | builders, |
| 102 | 123 | reach: readReach(db, now), |
| 103 | 124 | spend: { todayUsd, ceilingUsd: forge.ceilingUsd }, |
src/web/studio/kpi_row.ts +9 −2
| @@ -8,7 +8,7 @@ | ||
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | import type { Database } from "bun:sqlite"; |
| 11 | import { backupAge, backupFull, backupOverdue, buildersValue, checkTime, reactNote, speedWords, spendFull, spendValue, usersValue, visitorsNote, visitorsValue } from "../../flow/kpi_words.ts"; | |
| 11 | import { waitingWords, backupAge, backupFull, backupOverdue, buildersValue, checkTime, reactNote, speedWords, spendFull, spendValue, usersValue, visitorsNote, visitorsValue } from "../../flow/kpi_words.ts"; | |
| 12 | 12 | import type { Kpis } from "../../flow/kpis.ts"; |
| 13 | 13 | import { cachedKpis } from "./home_cache.ts"; |
| 14 | 14 | import { escapeHtml, html, raw, type Html } from "../html.ts"; |
| @@ -155,7 +155,14 @@ export function kpiRowFor(k: Kpis, live: { sha: string; at: string } | null, now | ||
| 155 | 155 | reactNote(k.reach), |
| 156 | 156 | "Page load, and delay after a tap, for the slowest quarter of views over 7 days", |
| 157 | 157 | )} |
| 158 | </section>`; | |
| 158 | </section> | |
| 159 | ${waitingOnYou(k.waiting)}`; | |
| 160 | } | |
| 161 | ||
| 162 | /** One figure, not a list: the pulls a person has left a day or more (#3242). Plain muted text with a link, no tone. */ | |
| 163 | export function waitingOnYou(w: Kpis["waiting"]): Html { | |
| 164 | const words = waitingWords(w); | |
| 165 | return words === null ? html`` : html`<p class="small muted"><a href="/pulls">${words}</a></p>`; | |
| 159 | 166 | } |
| 160 | 167 | |
| 161 | 168 | /** The figures count every repository, so the caller shows this to an admin only. */ |
test/home-kpi-row.test.ts +17 −4
| @@ -110,6 +110,16 @@ describe("home kpi row", () => { | ||
| 110 | 110 | }); |
| 111 | 111 | }); |
| 112 | 112 | |
| 113 | /** What the waiting-on-you figure reads, added to the bare tables these tests build. */ | |
| 114 | function waitingColumns(db: Database): void { | |
| 115 | db.run("ALTER TABLE user ADD COLUMN is_agent INTEGER"); | |
| 116 | db.run("ALTER TABLE repo ADD COLUMN archived_at TEXT"); | |
| 117 | db.run("ALTER TABLE issue ADD COLUMN created_at TEXT"); | |
| 118 | db.run("ALTER TABLE pull ADD COLUMN head_oid TEXT"); | |
| 119 | db.run("ALTER TABLE run ADD COLUMN repo_id TEXT"); | |
| 120 | db.run("CREATE TABLE pull_hold (issue_id TEXT, released_at TEXT)"); | |
| 121 | } | |
| 122 | ||
| 113 | 123 | describe("the builders figure from the database", () => { |
| 114 | 124 | test("counts running agent runs against the autonomous repositories' slots", async () => { |
| 115 | 125 | const { Database } = await import("bun:sqlite"); |
| @@ -117,9 +127,10 @@ describe("the builders figure from the database", () => { | ||
| 117 | 127 | db.run("CREATE TABLE repo (autonomy TEXT, autonomy_slots INTEGER, default_branch TEXT, id TEXT)"); |
| 118 | 128 | db.run("CREATE TABLE run (id TEXT, kind TEXT, state TEXT, started_at TEXT, finished_at TEXT, serving_at TEXT, env TEXT, commit_oid TEXT, cost_usd REAL, created_at TEXT)"); |
| 119 | 129 | db.run("CREATE TABLE pull (merged_at TEXT, merged_oid TEXT, base_oid TEXT, base_branch TEXT, issue_id TEXT)"); |
| 120 | db.run("CREATE TABLE issue (id TEXT, repo_id TEXT)"); | |
| 130 | db.run("CREATE TABLE issue (id TEXT, repo_id TEXT, kind TEXT, state TEXT, author_id TEXT, updated_at TEXT)"); | |
| 121 | 131 | reachTables(db); |
| 122 | db.run("INSERT INTO repo VALUES ('autonomous', 3, 'main', 'a'), ('autonomous', 1, 'main', 'b'), ('off', 8, 'main', 'c')"); | |
| 132 | waitingColumns(db); | |
| 133 | db.run("INSERT INTO repo (autonomy, autonomy_slots, default_branch, id) VALUES ('autonomous', 3, 'main', 'a'), ('autonomous', 1, 'main', 'b'), ('off', 8, 'main', 'c')"); | |
| 123 | 134 | db.run("INSERT INTO run (id, kind, state) VALUES ('1','agent','running'), ('2','agent','running'), ('3','agent','queued'), ('4','check','running')"); |
| 124 | 135 | const { readKpis } = await import("../src/flow/kpis.ts"); |
| 125 | 136 | expect(readKpis(db, new Date()).builders).toEqual({ running: 2, slots: 4 }); |
| @@ -181,8 +192,9 @@ describe("the spend figure from the database", () => { | ||
| 181 | 192 | db.run("CREATE TABLE repo (autonomy TEXT, autonomy_slots INTEGER, default_branch TEXT, id TEXT)"); |
| 182 | 193 | db.run("CREATE TABLE run (id TEXT, kind TEXT, state TEXT, started_at TEXT, finished_at TEXT, serving_at TEXT, env TEXT, commit_oid TEXT, cost_usd REAL, created_at TEXT)"); |
| 183 | 194 | db.run("CREATE TABLE pull (merged_at TEXT, merged_oid TEXT, base_oid TEXT, base_branch TEXT, issue_id TEXT)"); |
| 184 | db.run("CREATE TABLE issue (id TEXT, repo_id TEXT)"); | |
| 195 | db.run("CREATE TABLE issue (id TEXT, repo_id TEXT, kind TEXT, state TEXT, author_id TEXT, updated_at TEXT)"); | |
| 185 | 196 | reachTables(db); |
| 197 | waitingColumns(db); | |
| 186 | 198 | db.run( |
| 187 | 199 | `INSERT INTO run (id, kind, cost_usd, created_at) VALUES |
| 188 | 200 | ('1','agent',5,'2026-10-19T00:00:00.000Z'), ('2','agent',7.5,'2026-10-19T14:00:00.000Z'), |
| @@ -233,8 +245,9 @@ describe("home kpi row: the last off-box backup", () => { | ||
| 233 | 245 | db.run("CREATE TABLE repo (autonomy TEXT, autonomy_slots INTEGER, default_branch TEXT, id TEXT)"); |
| 234 | 246 | db.run("CREATE TABLE run (id TEXT, kind TEXT, state TEXT, started_at TEXT, finished_at TEXT, serving_at TEXT, env TEXT, commit_oid TEXT, cost_usd REAL, created_at TEXT)"); |
| 235 | 247 | db.run("CREATE TABLE pull (merged_at TEXT, merged_oid TEXT, base_oid TEXT, base_branch TEXT, issue_id TEXT)"); |
| 236 | db.run("CREATE TABLE issue (id TEXT, repo_id TEXT)"); | |
| 248 | db.run("CREATE TABLE issue (id TEXT, repo_id TEXT, kind TEXT, state TEXT, author_id TEXT, updated_at TEXT)"); | |
| 237 | 249 | reachTables(db); |
| 250 | waitingColumns(db); | |
| 238 | 251 | expect(readKpis(db, NOW, { ceilingUsd: null, dataDir: dir }).backupAt).toBeNull(); |
| 239 | 252 | recordMirror(dir, { where: "b2", attemptAt: hoursAgo(1), reachable: true, newest: "s1", newestAt: hoursAgo(3) }); |
| 240 | 253 | expect(readKpis(db, NOW, { ceilingUsd: null, dataDir: dir }).backupAt).toBe(hoursAgo(3)); |
test/live-triage.test.ts added +97
| @@ -0,0 +1,97 @@ | ||
| 1 | /** Live triage (#3242): each case seeded, each outcome asserted. */ | |
| 2 | ||
| 3 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 4 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 5 | import { tmpdir } from "node:os"; | |
| 6 | import { join } from "node:path"; | |
| 7 | import { createApp, type App } from "../src/app.ts"; | |
| 8 | import { assignIssue, openIssue } from "../src/actions/issues.ts"; | |
| 9 | import { createRepo, updateRepoSettings } from "../src/actions/repos.ts"; | |
| 10 | import { addComment, getIssue, labelsFor, listComments } from "../src/core/issues.ts"; | |
| 11 | import { addDependency, readyNow, repoGraph } from "../src/core/dependencies.ts"; | |
| 12 | import { DONE_NOTE } from "../src/core/done_on_main.ts"; | |
| 13 | import { getRepoById, type Repo } from "../src/core/repos.ts"; | |
| 14 | import { createUser, type User } from "../src/core/users.ts"; | |
| 15 | import { createRun } from "../src/core/runs.ts"; | |
| 16 | import { readKpis } from "../src/flow/kpis.ts"; | |
| 17 | import { createOrigin, linkRepoToOrigin } from "../src/core/origins.ts"; | |
| 18 | import { kpiLines } from "../src/flow/kpi_words.ts"; | |
| 19 | import { waitingOnYou } from "../src/web/studio/kpi_row.ts"; | |
| 20 | ||
| 21 | describe("waiting on you", () => { | |
| 22 | let dataDir: string; | |
| 23 | let app: App; | |
| 24 | let alice: User; | |
| 25 | let repo: Repo; | |
| 26 | const fresh = () => getRepoById(app.db, repo.id)!; | |
| 27 | const ask = (title: string, body = "") => { | |
| 28 | const o = openIssue(app, alice, fresh(), { title, body: body || title }); | |
| 29 | if (!o.ok) throw new Error(String(o.error)); | |
| 30 | return o.value; | |
| 31 | }; | |
| 32 | let bot: User; | |
| 33 | const byAgent = (issue: { id: string; number: number }) => { | |
| 34 | app.db.query("UPDATE issue SET author_id = ?1 WHERE id = ?2").run(bot.id, issue.id); | |
| 35 | return issue; | |
| 36 | }; | |
| 37 | const state = (n: number) => getIssue(app.db, repo.id, n)!; | |
| 38 | const notes = (n: number) => listComments(app.db, state(n).id).map((c) => c.body); | |
| 39 | const names = (n: number) => labelsFor(app.db, state(n).id).map((l) => l.name); | |
| 40 | const merge = (pullNumber: number, oid: string) => | |
| 41 | app.db.query("INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, merged_at, merged_oid) VALUES (?1, 'main', 'b', '', '', ?2, ?3)") | |
| 42 | .run(state(pullNumber).id, new Date().toISOString(), oid); | |
| 43 | const asPull = (n: number) => app.db.query("UPDATE issue SET kind = 'pull' WHERE id = ?1").run(state(n).id); | |
| 44 | ||
| 45 | beforeAll(async () => { | |
| 46 | dataDir = await mkdtemp(join(tmpdir(), "forge-live-triage-")); | |
| 47 | app = createApp({ dataDir, port: 0 }); | |
| 48 | const made = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 49 | if (!made.ok) throw new Error(String(made.error)); | |
| 50 | alice = made.value; | |
| 51 | const b = await createUser(app.db, { origin: "seed", trusted: true, username: "botty", email: "[email protected]", password: "a-good-passphrase" }); | |
| 52 | if (!b.ok) throw new Error(String(b.error)); | |
| 53 | bot = b.value; | |
| 54 | app.db.query("UPDATE user SET is_agent = 1 WHERE id = ?1").run(bot.id); | |
| 55 | const r = await createRepo(app, alice, { name: "forge", visibility: "private" }); | |
| 56 | if (!r.ok) throw new Error(String(r.error)); | |
| 57 | await updateRepoSettings(app, alice, r.value, { autonomy: "autonomous", autonomyDirection: "Steer.", autonomyCeilingUsd: 10, autonomySlots: 1, autonomyBy: alice.id }); | |
| 58 | repo = r.value; | |
| 59 | }); | |
| 60 | ||
| 61 | afterAll(async () => { | |
| 62 | app.close(); | |
| 63 | await rm(dataDir, { recursive: true, force: true }); | |
| 64 | }); | |
| 65 | ||
| 66 | ||
| 67 | test("an old agent pull waiting on a person is one figure on home", () => { | |
| 68 | const now = new Date(); | |
| 69 | const open = (title: string, head: string, hoursOld: number, green: boolean) => { | |
| 70 | const p = byAgent(ask(title)); | |
| 71 | asPull(p.number); | |
| 72 | app.db.query("INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid) VALUES (?1, 'main', ?2, '', ?2)").run(p.id, head); | |
| 73 | app.db.query("UPDATE issue SET created_at = ?1 WHERE id = ?2").run(new Date(now.getTime() - hoursOld * 3_600_000).toISOString(), p.id); | |
| 74 | if (green) { | |
| 75 | const r = createRun(app.db, { repoId: repo.id, kind: "check" }); | |
| 76 | app.db.query("UPDATE run SET state = 'ok', commit_oid = ?1 WHERE id = ?2").run(head, r.id); | |
| 77 | } | |
| 78 | return p; | |
| 79 | }; | |
| 80 | open("Pull waiting", "w1", 50, true); | |
| 81 | open("Pull recent", "w2", 2, true); | |
| 82 | open("Pull still on checks", "w3", 60, false); | |
| 83 | const held = open("Pull held", "w4", 70, true); | |
| 84 | app.db.query("INSERT INTO pull_hold (issue_id, held_by, why, held_at) VALUES (?1, ?2, 'later', ?3)").run(held.id, alice.id, now.toISOString()); | |
| 85 | const k = readKpis(app.db, now); | |
| 86 | expect(k.waiting).toEqual({ count: 1, oldestHours: 50 }); | |
| 87 | expect(String(waitingOnYou(k.waiting))).toContain("waiting on you: 1, oldest 50 h"); | |
| 88 | expect(String(waitingOnYou({ count: 0, oldestHours: 0 }))).toBe(""); | |
| 89 | }); | |
| 90 | ||
| 91 | test("the terminal's lines carry the same waiting figure, and only when something waits", () => { | |
| 92 | const k = readKpis(app.db, new Date(Date.now() + 100 * 3_600_000)); | |
| 93 | expect(k.waiting!.count).toBeGreaterThan(0); | |
| 94 | expect(kpiLines(k, null).at(-1)).toBe(`Waiting on you: ${k.waiting!.count}, oldest ${k.waiting!.oldestHours} h`); | |
| 95 | expect(kpiLines({ ...k, waiting: { count: 0, oldestHours: 0 } }, null).some((l) => /waiting on you/i.test(l))).toBe(false); | |
| 96 | }); | |
| 97 | }); |
new above
offline