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

opened this

Merged 16h 52m ago, live in production

fix/nobody-says-so → main 0 commits 4 threads · 4 unresolved

  • Merged. fix/nobody-says-so was merged into main as 3735c77.

Review

Sign in to review this change.
5 files changed +69 −13
src/crew/idle_reason.ts +29 −3
@@ -8,12 +8,14 @@
88 * what `heldNow` sorts (`held.ts`: `nothing
99 * ready` is its empty `startable`), and the subscriptions' headroom (`pace`,
1010 * 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.
1213 */
1314
1415 import type { App } from "../app.ts";
1516 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";
1719 import { listActive } from "../core/runs.ts";
1820 import { standings } from "../core/standing.ts";
1921 import { grantedAccounts } from "../core/subscriptions.ts";
@@ -30,8 +32,17 @@ export const NO_HEADROOM = "no subscription with headroom";
3032 export interface IdleReason {
3133 readonly word: string;
3234 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;
outdated

Nothing reads repoId: home_flow.ts and the TUI idleLine both print href to every viewer. Use it to gate the link at render time, or drop it and use a viewer-independent href.

3337 }
3438
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
3546 /**
3647 * The week's share or the subscriptions, when one of them is why this repository starts
3748 * nothing; null when neither is.
@@ -59,7 +70,10 @@ export function whatBlocks(app: App, repo: Repo, now: Date): IdleReason | null {
5970 export function idleReason(app: App, now: Date): IdleReason | null {
6071 const { db } = app;
6172 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)
outdated

This leaks owner/repo of a possibly private repo to guests via the tile link and the terminal line. It also returns on the first nobody repo, hiding the reasons for the other repos.

76 return { word: NOBODY_WORD, href: `/${repo.ownerName}/${repo.name}/settings/autonomy`, repoId: repo.id };
6377 const crew = listCrewRoles(db, repo.id);
6478 if (crew.length === 0) continue;
6579
@@ -98,6 +112,18 @@ export const stallWord = (n: number): string =>
98112 export const governedWord = (slots: number, ceiling: number): string =>
99113 `new builds are held to ${slots} of ${ceiling} until open pulls land; fixes, updates and reviews of open pulls keep every slot`;
100114
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
101127 /** The reason as one line, the same words wherever it is printed. */
102128 export function idleLine(reason: IdleReason): string {
103129 return `Builders idle: ${reason.word} (${reason.href})`;
src/tui/screens/dashboard.ts +5 −4
@@ -160,7 +160,8 @@ import { firedAlarms } from "../../flow/alarms.ts";
160160 import { lastClearedNote } from "../../flow/clog_tick.ts";
161161 import { forgeCeiling } from "../../flow/ceiling.ts";
162162 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";
164165 import { weekBlock } from "../../crew/week_read.ts";
165166 import { noReleaseAlarm } from "../../flow/alarm_no_release.ts";
166167 import { redMainAlarm } from "../../flow/alarm_red_main.ts";
@@ -591,7 +592,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
591592 f.user?.isAdmin !== true
592593 ? []
593594 : [
594 ...idleLines(f.app, now),
595 ...idleLines(f.app, f.user, now),
595596 ...weekBlock(f.app, now),
596597 ...kpiLines(readKpis(f.db, now, { ...kpiForge(f.app), idle: () => idleReason(f.app, now) }), commit === null ? null : { sha: commit, since: ago(BOOTED) }),
597598 ...shipTimeLines(f.db, now),
@@ -1955,8 +1956,8 @@ export function keepFigures(figures: readonly string[], room: number): string[]
19551956 const SPEND_LINE = "Crew spend today";
19561957
19571958 /** 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));
19601961 return reason === null ? [] : [idleLine(reason)];
19611962 }
19621963
src/web/pages/home_flow.ts +6 −3
@@ -83,6 +83,7 @@ import { startedFromLine } from "../started_from.ts";
8383 import { parkedSection } from "../parked_lines.ts";
8484 import { parkedFor } from "../../flow/parked_read.ts";
8585 import { firstWeekBlock } from "../first_week.ts";
86 import { idleFor, type IdleReason } from "../../crew/idle_reason.ts";
8687
8788
8889 /**
@@ -301,6 +302,8 @@ function weekFigure(strip: StripPart): { value: string; note: string; attn: bool
301302 */
302303 interface StripViewer {
303304 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;

Non-blocking: make reads required; an omitted one silently drops the idle line.

304307 }
305308
306309 /** 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:
355358 const proof = proofWords(lastProof(dataDir), version, provingSince(dataDir, version));
356359 const b = picture.builders;
357360 // 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;
359362 const week = strip === null ? null : weekFigure(strip);
360363 const lead = strip?.lead.medianHours ?? null;
361364 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
561564 // or lean.
562565 const spawned = known !== undefined ? known.spawned : await timePhaseAsync(ctx.request, "spawned", () => spawnedForge(ctx.app));
563566 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);
565568 const need = needLine(brokenOf(picture, wide, ctx.app.config.dataDir, now), new Set(asksToAnswer(ctx.app, user).map((a) => a.username)).size);
566569 // What the old home also carried and is not a lane: the box that tells the crew (with Notes and
567570 // Talk), the welcome after an account is allowed, a
@@ -714,7 +717,7 @@ export async function liveStripFragment(ctx: Ctx): Promise<Response> {
714717 const picture = await timePhaseAsync(ctx.request, "picture", () => lanePicture(ctx.app.db, optionsOf(ctx, user), "lane", now));
715718 const rendering = performance.now();
716719 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 }) });
718721 notePhase(ctx.request, "render", performance.now() - rendering);
719722 return res;
720723 }
test/home-builders-idle.test.ts +27 −2
@@ -10,9 +10,9 @@ import { createApp, type App } from "../src/app.ts";
1010 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1111 import { openIssue } from "../src/actions/issues.ts";
1212 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";
1414 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";
1616 import { writeStamp } from "../src/core/write_clock.ts";
1717 import { cachedKpis, kpiCache } from "../src/web/studio/home_cache.ts";
1818 import { readKpis } from "../src/flow/kpis.ts";
@@ -108,6 +108,31 @@ test("nothing ready: the map has nothing a builder may start", async () => {
108108 expect(await terminal()).toContain("Builders running 0 of 1 · nothing ready");
109109 });
110110
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" });
outdated

Only asserts as admin. Add a guest/non-reader case proving the private repo's path is absent from home and the terminal.

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
111136 test("a ready issue and a builder with room: no reason is named", async () => {
112137 const opened = openIssue(app, admin, repo, { title: "Renderer" });
113138 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> {
100100 setIssueLabels(app.db, bug.value.id, [label.value.id]);
101101 const old = new Date(Date.now() - 100 * 3_600_000).toISOString();
102102 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);
104105 // An open sentinel finding.
105106 app.db
106107 .query("INSERT INTO sentinel_finding (key, issue_id, evidence, first_seen, last_seen) VALUES ('setting:x', ?1, '', 'a', 'a')")

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs