Public: anyone can read this; the crew can change it.
A crew paused as "nobody" says so on home, with its autonomy setting as the one control #17593
Merged 16h 52m ago, live in production
fix/nobody-says-so → main 0 commits 4 threads · 4 unresolved
5 files
changed +69
−13
src/crew/idle_reason.ts +29 −3
| @@ -8,12 +8,14 @@ | ||
| 8 | 8 | * what `heldNow` sorts (`held.ts`: `nothing |
| 9 | 9 | * ready` is its empty `startable`), and the subscriptions' headroom (`pace`, |
| 10 | 10 | * as `repoPace` asks it). The repository is the first autonomous one with a |
| 11 | * crew and someone to act as, which is what the loop drives. | |
| 11 | * crew and someone to act as, which is what the loop drives; one with no one to act as is paused | |
| 12 | * ("nobody"), and that is the reason, with its autonomy setting as the link. | |
| 12 | 13 | */ |
| 13 | 14 | |
| 14 | 15 | import type { App } from "../app.ts"; |
| 15 | 16 | import { listCrewRoles } from "../core/agents.ts"; |
| 16 | import { listAutonomousRepos, type Repo } from "../core/repos.ts"; | |
| 17 | import { canRead, getRepoById, listAutonomousRepos, type Repo } from "../core/repos.ts"; | |
| 18 | import type { User } from "../core/users.ts"; | |
| 17 | 19 | import { listActive } from "../core/runs.ts"; |
| 18 | 20 | import { standings } from "../core/standing.ts"; |
| 19 | 21 | import { grantedAccounts } from "../core/subscriptions.ts"; |
| @@ -30,8 +32,17 @@ export const NO_HEADROOM = "no subscription with headroom"; | ||
| 30 | 32 | export interface IdleReason { |
| 31 | 33 | readonly word: string; |
| 32 | 34 | readonly href: string; |
| 35 | /** The one repository the reason is about, when it is one: a page shows its link only to someone who reads it. */ | |
| 36 | readonly repoId?: string; | |
| 33 | 37 | } |
| 34 | 38 | |
| 39 | /** | |
| 40 | * The word for a repository the crew is on in but paused as "nobody" (`autonomy_status.ts`): no | |
| 41 | * person is named to act as, so its ready work never starts. The repository's name is in the link, | |
| 42 | * not the word, so the word may be said to anyone. | |
| 43 | */ | |
| 44 | export const NOBODY_WORD = "a repository's crew is on but names nobody to act as, so it starts nothing: turn autonomy on there again"; | |
| 45 | ||
| 35 | 46 | /** |
| 36 | 47 | * The week's share or the subscriptions, when one of them is why this repository starts |
| 37 | 48 | * nothing; null when neither is. |
| @@ -59,7 +70,10 @@ export function whatBlocks(app: App, repo: Repo, now: Date): IdleReason | null { | ||
| 59 | 70 | export function idleReason(app: App, now: Date): IdleReason | null { |
| 60 | 71 | const { db } = app; |
| 61 | 72 | for (const repo of listAutonomousRepos(db)) { |
| 62 | if (repo.autonomy !== "autonomous" || repo.autonomyBy === null || repo.archivedAt !== null) continue; | |
| 73 | if (repo.autonomy !== "autonomous" || repo.archivedAt !== null) continue; | |
| 74 | // A pause nobody chose is said, never skipped: the one control is the repository's autonomy setting. | |
| 75 | if (repo.autonomyBy === null) | |
| 76 | return { word: NOBODY_WORD, href: `/${repo.ownerName}/${repo.name}/settings/autonomy`, repoId: repo.id }; | |
| 63 | 77 | const crew = listCrewRoles(db, repo.id); |
| 64 | 78 | if (crew.length === 0) continue; |
| 65 | 79 | |
| @@ -98,6 +112,18 @@ export const stallWord = (n: number): string => | ||
| 98 | 112 | export const governedWord = (slots: number, ceiling: number): string => |
| 99 | 113 | `new builds are held to ${slots} of ${ceiling} until open pulls land; fixes, updates and reviews of open pulls keep every slot`; |
| 100 | 114 | |
| 115 | /** | |
| 116 | * The reason as `viewer` may be shown it: one about a repository keeps its link (which names the | |
| 117 | * repository) only for someone who reads it; anyone else gets the words and the crew settings, so | |
| 118 | * a private repository's name never leaves through the idle line. Every door that prints a reason | |
| 119 | * asks this first. | |
| 120 | */ | |
| 121 | export function idleFor(app: App, viewer: User | undefined, reason: IdleReason | null): IdleReason | null { | |
| 122 | if (reason === null || reason.repoId === undefined) return reason; | |
| 123 | const repo = getRepoById(app.db, reason.repoId); | |
| 124 | return repo !== undefined && canRead(app.db, repo, viewer) ? reason : { word: reason.word, href: "/settings/crew" }; | |
| 125 | } | |
| 126 | ||
| 101 | 127 | /** The reason as one line, the same words wherever it is printed. */ |
| 102 | 128 | export function idleLine(reason: IdleReason): string { |
| 103 | 129 | return `Builders idle: ${reason.word} (${reason.href})`; |
src/tui/screens/dashboard.ts +5 −4
| @@ -160,7 +160,8 @@ import { firedAlarms } from "../../flow/alarms.ts"; | ||
| 160 | 160 | import { lastClearedNote } from "../../flow/clog_tick.ts"; |
| 161 | 161 | import { forgeCeiling } from "../../flow/ceiling.ts"; |
| 162 | 162 | import { alarmIdleCrew } from "../../flow/alarm_idle_crew.ts"; |
| 163 | import { idleLine, idleReason } from "../../crew/idle_reason.ts"; | |
| 163 | import { idleFor, idleLine, idleReason } from "../../crew/idle_reason.ts"; | |
| 164 | import type { User } from "../../core/users.ts"; | |
| 164 | 165 | import { weekBlock } from "../../crew/week_read.ts"; |
| 165 | 166 | import { noReleaseAlarm } from "../../flow/alarm_no_release.ts"; |
| 166 | 167 | import { redMainAlarm } from "../../flow/alarm_red_main.ts"; |
| @@ -591,7 +592,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 591 | 592 | f.user?.isAdmin !== true |
| 592 | 593 | ? [] |
| 593 | 594 | : [ |
| 594 | ...idleLines(f.app, now), | |
| 595 | ...idleLines(f.app, f.user, now), | |
| 595 | 596 | ...weekBlock(f.app, now), |
| 596 | 597 | ...kpiLines(readKpis(f.db, now, { ...kpiForge(f.app), idle: () => idleReason(f.app, now) }), commit === null ? null : { sha: commit, since: ago(BOOTED) }), |
| 597 | 598 | ...shipTimeLines(f.db, now), |
| @@ -1955,8 +1956,8 @@ export function keepFigures(figures: readonly string[], room: number): string[] | ||
| 1955 | 1956 | const SPEND_LINE = "Crew spend today"; |
| 1956 | 1957 | |
| 1957 | 1958 | /** Why the builders are idle, as the one line an admin's home reads; none while they are not. */ |
| 1958 | function idleLines(app: App, now: Date): string[] { | |
| 1959 | const reason = idleReason(app, now); | |
| 1959 | function idleLines(app: App, viewer: User | undefined, now: Date): string[] { | |
| 1960 | const reason = idleFor(app, viewer, idleReason(app, now)); | |
| 1960 | 1961 | return reason === null ? [] : [idleLine(reason)]; |
| 1961 | 1962 | } |
| 1962 | 1963 |
src/web/pages/home_flow.ts +6 −3
| @@ -83,6 +83,7 @@ import { startedFromLine } from "../started_from.ts"; | ||
| 83 | 83 | import { parkedSection } from "../parked_lines.ts"; |
| 84 | 84 | import { parkedFor } from "../../flow/parked_read.ts"; |
| 85 | 85 | import { firstWeekBlock } from "../first_week.ts"; |
| 86 | import { idleFor, type IdleReason } from "../../crew/idle_reason.ts"; | |
| 86 | 87 | |
| 87 | 88 | |
| 88 | 89 | /** |
| @@ -301,6 +302,8 @@ function weekFigure(strip: StripPart): { value: string; note: string; attn: bool | ||
| 301 | 302 | */ |
| 302 | 303 | interface StripViewer { |
| 303 | 304 | readonly isAdmin: boolean; |
| 305 | /** Whether the viewer reads a repository: an idle reason's link names one (`idleFor`). */ | |
| 306 | readonly reads?: (idle: IdleReason | null) => IdleReason | null; | |
| 304 | 307 | } |
| 305 | 308 | |
| 306 | 309 | /** What is broken about the forge, for an admin: the proof's alarm, then the picture's alarms. */ |
| @@ -355,7 +358,7 @@ export function stripRegion(picture: LanePicture, viewer: StripViewer, dataDir: | ||
| 355 | 358 | const proof = proofWords(lastProof(dataDir), version, provingSince(dataDir, version)); |
| 356 | 359 | const b = picture.builders; |
| 357 | 360 | // The reason is only said while a slot is free: a busy crew has none. |
| 358 | const idle = b.slots > 0 && b.running < b.slots ? picture.idle : null; | |
| 361 | const idle = b.slots > 0 && b.running < b.slots ? (viewer.reads ?? (() => null))(picture.idle ?? null) : null; | |
| 359 | 362 | const week = strip === null ? null : weekFigure(strip); |
| 360 | 363 | const lead = strip?.lead.medianHours ?? null; |
| 361 | 364 | return html`<section class="hf-strip" id="hf-strip" aria-label="Today's figures" data-live="${STRIP_LIVE}" data-live-src="/live/strip"> |
| @@ -561,7 +564,7 @@ export async function homeFlowPage(ctx: Ctx, known?: { readonly spawned: Awaited | ||
| 561 | 564 | // or lean. |
| 562 | 565 | const spawned = known !== undefined ? known.spawned : await timePhaseAsync(ctx.request, "spawned", () => spawnedForge(ctx.app)); |
| 563 | 566 | const wide = user.isAdmin && spawned === undefined; |
| 564 | const strip = picture === undefined ? readingStrip(wide) : stripRegion(picture, { isAdmin: wide }, ctx.app.config.dataDir, now); | |
| 567 | const strip = picture === undefined ? readingStrip(wide) : stripRegion(picture, { isAdmin: wide, reads: (idle) => idleFor(ctx.app, user, idle) }, ctx.app.config.dataDir, now); | |
| 565 | 568 | const need = needLine(brokenOf(picture, wide, ctx.app.config.dataDir, now), new Set(asksToAnswer(ctx.app, user).map((a) => a.username)).size); |
| 566 | 569 | // What the old home also carried and is not a lane: the box that tells the crew (with Notes and |
| 567 | 570 | // Talk), the welcome after an account is allowed, a |
| @@ -714,7 +717,7 @@ export async function liveStripFragment(ctx: Ctx): Promise<Response> { | ||
| 714 | 717 | const picture = await timePhaseAsync(ctx.request, "picture", () => lanePicture(ctx.app.db, optionsOf(ctx, user), "lane", now)); |
| 715 | 718 | const rendering = performance.now(); |
| 716 | 719 | const wide = user.isAdmin && (await spawnedForge(ctx.app)) === undefined; |
| 717 | const res = fragment((picture === undefined ? readingStrip(wide) : stripRegion(picture, { isAdmin: wide }, ctx.app.config.dataDir, now)) ?? html``, { request: ctx.request, ...(wide ? {} : { status: 404 }) }); | |
| 720 | const res = fragment((picture === undefined ? readingStrip(wide) : stripRegion(picture, { isAdmin: wide, reads: (idle) => idleFor(ctx.app, user, idle) }, ctx.app.config.dataDir, now)) ?? html``, { request: ctx.request, ...(wide ? {} : { status: 404 }) }); | |
| 718 | 721 | notePhase(ctx.request, "render", performance.now() - rendering); |
| 719 | 722 | return res; |
| 720 | 723 | } |
test/home-builders-idle.test.ts +27 −2
| @@ -10,9 +10,9 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 10 | 10 | import { addToCrew, createAgent } from "../src/actions/crew.ts"; |
| 11 | 11 | import { openIssue } from "../src/actions/issues.ts"; |
| 12 | 12 | import { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts"; |
| 13 | import { getUserByName } from "../src/core/users.ts"; | |
| 13 | import { createUser, getUserByName } from "../src/core/users.ts"; | |
| 14 | 14 | import { claimRun, createRun, finishRun } from "../src/core/runs.ts"; |
| 15 | import { idleReason } from "../src/crew/idle_reason.ts"; | |
| 15 | import { idleFor, idleReason, NOBODY_WORD } from "../src/crew/idle_reason.ts"; | |
| 16 | 16 | import { writeStamp } from "../src/core/write_clock.ts"; |
| 17 | 17 | import { cachedKpis, kpiCache } from "../src/web/studio/home_cache.ts"; |
| 18 | 18 | import { readKpis } from "../src/flow/kpis.ts"; |
| @@ -108,6 +108,31 @@ test("nothing ready: the map has nothing a builder may start", async () => { | ||
| 108 | 108 | expect(await terminal()).toContain("Builders running 0 of 1 · nothing ready"); |
| 109 | 109 | }); |
| 110 | 110 | |
| 111 | test("a crew that names nobody to act as is said, with the one control that fixes it, never skipped", async () => { | |
| 112 | // How trevato/app-template sat for weeks: autonomous, ready work, and no autonomy_by (#2172). | |
| 113 | app.db.run("UPDATE repo SET autonomy_by = NULL WHERE id = ?1", [repo.id]); | |
| 114 | try { | |
| 115 | expect(idleReason(app, new Date())).toEqual({ word: NOBODY_WORD, href: "/alice/engine/settings/autonomy", repoId: repo.id }); | |
| 116 | const page = await home(); | |
| 117 | expect(tile(page)).toContain("names nobody to act as"); | |
| 118 | expect(tile(page)).toContain('href="/alice/engine/settings/autonomy"'); | |
| 119 | expect(await terminal()).toContain("names nobody to act as"); | |
| 120 | // The link names the repository: only someone who reads it is given it, at either door. | |
| 121 | const reason = idleReason(app, new Date()); | |
| 122 | const made = await createUser(app.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-long-passphrase" }); | |
| 123 | const bob = made.ok ? made.value : getUserByName(app.db, "bob")!; | |
| 124 | for (const viewer of [bob, undefined]) expect(idleFor(app, viewer, reason)).toEqual({ word: NOBODY_WORD, href: "/settings/crew" }); | |
| 125 | expect(idleFor(app, admin, reason)).toEqual(reason); | |
| 126 | const bobHome = await freshHome(servers.url, `forge_session=${createSession(app.db, bob.id).token}; forge_mode=studio`); | |
| 127 | expect(bobHome).not.toContain("alice/engine"); | |
| 128 | const guest = await (await fetch(`${servers.url}/`)).text(); | |
| 129 | expect(guest).not.toContain("alice/engine"); | |
| 130 | } finally { | |
| 131 | app.db.run("UPDATE repo SET autonomy_by = ?2 WHERE id = ?1", [repo.id, admin.id]); | |
| 132 | } | |
| 133 | expect(idleReason(app, new Date())?.word).not.toBe(NOBODY_WORD); | |
| 134 | }); | |
| 135 | ||
| 111 | 136 | test("a ready issue and a builder with room: no reason is named", async () => { |
| 112 | 137 | const opened = openIssue(app, admin, repo, { title: "Renderer" }); |
| 113 | 138 | if (!opened.ok) throw new Error(String(opened.error)); |
test/no-alarm-banner.test.ts +2 −1
| @@ -100,7 +100,8 @@ async function world(spent: number): Promise<World> { | ||
| 100 | 100 | setIssueLabels(app.db, bug.value.id, [label.value.id]); |
| 101 | 101 | const old = new Date(Date.now() - 100 * 3_600_000).toISOString(); |
| 102 | 102 | app.db.query("UPDATE issue SET created_at = ?1 WHERE id = ?2").run(old, bug.value.id); |
| 103 | app.db.query("UPDATE repo SET autonomy = 'autonomous' WHERE id = ?1").run(repo.value.id); | |
| 103 | // On as a person turns it on, naming them: a crew with nobody named is paused, a different reason (`idle_reason.ts`). | |
| 104 | app.db.query("UPDATE repo SET autonomy = 'autonomous', autonomy_by = ?2 WHERE id = ?1").run(repo.value.id, made.value.id); | |
| 104 | 105 | // An open sentinel finding. |
| 105 | 106 | app.db |
| 106 | 107 | .query("INSERT INTO sentinel_finding (key, issue_id, evidence, first_seen, last_seen) VALUES ('setting:x', ?1, '', 'a', 'a')") |
new above
offline
Nothing reads
repoId: home_flow.ts and the TUI idleLine both printhrefto every viewer. Use it to gate the link at render time, or drop it and use a viewer-independent href.