Public: anyone can read this; the crew can change it.

On you and Needs you are one list with one word and one count, each row saying what it waits for #1771

Closed opened this
Closed without merging

scout/forge:scout/1603-on-you-and-needs-you-are-one-list-with-o → main 3 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
12 files changed +460 −71
README.md +6 −4
@@ -260,11 +260,13 @@ my machine", and the dashboard grows an **On your machine** card listing them.
260260 The server remembers only the choice — nothing about the state of a laptop —
261261 and `forge sync` below is what acts on it.
262262
263 **Muting a repository from the home**: each ask row on the home carries a "Mute owner/name" chip. A muted repository's asks leave the home, `/api/v1/asks`, the header count and the phone's pushes (the same per-user mute the On you card uses, no new table); the home says "N muted repositories still ask" with a "Listen again" button, and an app's own page still counts them.
263 **One list, one count**: work assigned to you and the crew's asks are one list on the home ("Needs you"), counted once in the sentence, the top bar, `/api/v1/asks` (`count`) and the MCP `asks` tool. Every row says what it waits for — "ready to land", "conflicts with main", "your review", "a decision", "assigned to you" — as `waitingFor` in the data and a bold label on the page (`src/web/studio/waiting.ts`). A pull that is both assigned to you and an ask counts once.
264264
265 **On you, in the terminal**, answers to the same mutes and one-move verbs as
265 **Muting a repository from the home**: each ask row on the home carries a "Mute owner/name" chip. A muted repository's asks leave the home, `/api/v1/asks`, the header count and the phone's pushes (the same per-user mute the Needs you card uses, no new table); the home says "N muted repositories still ask" with a "Listen again" button, and an app's own page still counts them.
266
267 **Needs you, in the terminal**, shows the web's one count in the pane title ("Needs you (3)") and the same waiting-for label on every row ("assigned to you", "conflicts with main", "a decision"), from the same helpers (`assignedLines`, `waitingForAsk`). It answers to the same mutes and one-move verbs as
266268 the web card. Repositories you muted are hidden and counted ("2 repositories
267 muted"). On the On you card: `space` marks a row, `x` closes the marked rows
269 muted"). On the card: `space` marks a row, `x` closes the marked rows
268270 (or the row under the cursor) with one reason, `m` mutes their repositories,
269271 `S` ships them, `u` undoes the latest set within its day, and `L` listens
270272 again to every muted repository. Each goes through `applyAsksBulk`, so the
@@ -272,7 +274,7 @@ per-row access checks and refusals are the web's, shown in the toast.
272274
273275 **Let the decider** answers a hand-over card (an issue the crew parked) when
274276 you would rather not: the third tap on the card, `POST /api/v1/asks/decide`
275 (`{"item": "parked:<id>"}`), the MCP tool `asks_decide`, or `D` on the On you
277 (`{"item": "parked:<id>"}`), the MCP tool `asks_decide`, or `D` on the Needs you
276278 card in the terminal. It sees only the direction text, whether you pinned or
277279 muted the app, the day's spend against the ceiling, your last ten decisions
278280 there and the card's own evidence; the decision ledger row carries exactly
scripts/gate.ts +2
@@ -29,6 +29,8 @@ export const GATE: readonly string[] = [
2929 "test/cloud-use.test.ts",
3030 "test/accounts.test.ts",
3131 "test/asks-mute.test.ts",
32 "test/inbox.test.ts",
33 "test/needs-you.test.ts",
3234 "test/agents.test.ts",
3335 "test/app-domains.test.ts",
3436 "test/app.test.ts",
src/tui/screens/dashboard.ts +14 −4
@@ -20,7 +20,8 @@ import { forgeLane, forgeNeeds } from "../../actions/health.ts";
2020 import { mayView } from "../../core/sealed.ts";
2121 import { pinRepo, unpinRepo } from "../../actions/origins.ts";
2222 import { getIssueById, listAssignedTo, type Issue } from "../../core/issues.ts";
23 import { askLinesFor } from "../../web/studio/asks.ts";
23 import { askLinesFor, assignedLines } from "../../web/studio/asks.ts";
24 import { assignedWaitingFor, WAITING_FOR } from "../../web/studio/waiting.ts";
2425 import { decideAsk, undoDecideAsk } from "../../actions/asks_decide.ts";
2526 import {
2627 applyAsksBulk,
@@ -84,7 +85,7 @@ type PaneId = "repos" | "onyou" | "machine";
8485
8586 const TITLES: Readonly<Record<PaneId, string>> = {
8687 repos: "Repositories",
87 onyou: "On you",
88 onyou: "Needs you",
8889 machine: "On your machine",
8990 };
9091
@@ -113,6 +114,8 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
113114 /** Why planning is paused, for the autonomous apps where it is; as on the board. */
114115 let holds = new Map<string, string>();
115116 let forge: string[] | undefined;
117 /** The one count the web shows too: asks, the forge's own needs and assigned work, once each. */
118 let needs = 0;
116119 /** The check lane, as the board's strip says it; null when nothing is queued. */
117120 let lane: string | null = null;
118121 const filter = new Filter();
@@ -143,6 +146,13 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
143146 }),
144147 );
145148 forge = forgeNeeds(f.app, f.user);
149 if (f.user !== undefined) {
150 const asked = askLinesFor(f.db, f.user);
151 needs =
152 asked.length +
153 (forge?.length ?? 0) +
154 assignedLines(f.db, f.user, new Set(asked.flatMap((r) => r.items))).length;
155 }
146156 lane = forgeLane(f.app, f.user);
147157 // "Yours" is ownership plus the orgs you are on a team of; typing in the
148158 // filter reaches every repository you can see.
@@ -618,7 +628,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
618628 const on = focus === "onyou";
619629 const footer = onYouFooter();
620630 const inner = card(s, r, c, {
621 title: `${icon("person", set)} ${TITLES.onyou}`,
631 title: `${icon("person", set)} ${TITLES.onyou}${needs > 0 ? ` (${needs})` : ""}`,
622632 focused: on,
623633 ...(footer === undefined ? {} : { footer }),
624634 });
@@ -644,7 +654,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
644654 : ISSUE_MARK;
645655 return {
646656 title: `${marked.has(item.issue.id) ? "[x] " : ""}${item.hand === true ? "parked " : ""}${mark} #${item.issue.number} ${item.issue.title}`,
647 meta: `${item.repo.ownerName}/${item.repo.name}`,
657 meta: `${item.hand === true ? WAITING_FOR.parked : assignedWaitingFor(f.db, item.issue)} · ${item.repo.ownerName}/${item.repo.name}`,
648658 };
649659 }),
650660 on,
src/web/pages/site.ts +7 −38
@@ -9,22 +9,20 @@
99 */
1010
1111 import { limitValue } from "../../settings/limits.ts";
12 import { mayView } from "../../core/sealed.ts";
12 import { ASSIGNED_WAITING_FOR, assignedTo } from "../studio/waiting.ts";
1313 import { signOutHere } from "../../actions/signins.ts";
1414 import { clientAddress } from "../../http/peer.ts";
1515 import { verifyEmail } from "../../actions/verify.ts";
1616 import { STRANGER_MAX } from "../../http/limits.ts";
1717 import { createRepo } from "../../actions/repos.ts";
1818 import { HUMAN_CHECK_MESSAGE, signUp } from "../../actions/users.ts";
19 import { listAssignedTo, type Issue } from "../../core/issues.ts";
19 import { type Issue } from "../../core/issues.ts";
2020 import { joinMany } from "../../core/pulls.ts";
2121 import { conflictsOf } from "../../crew/stale_asks.ts";
2222 import { accessAllows, listOrgsForUser, orgAccess } from "../../core/orgs.ts";
2323 import { listPins } from "../../core/pins.ts";
2424 import {
25 canRead,
2625 getReposByIds,
27 listReposVisibleTo,
2826 type Repo,
2927 } from "../../core/repos.ts";
3028 import { createSession } from "../../core/sessions.ts";
@@ -34,7 +32,6 @@ import { cookieValue, crossOrigin, type Ctx } from "../../http/context.ts";
3432 import { studioDoor, studioHome } from "../studio/home.ts";
3533 import { homeTop, onYouBulk } from "../studio/asks_page.ts";
3634 import { latestUndoable } from "../../actions/asks_bulk.ts";
37 import { mutedRepos } from "../../core/interactions.ts";
3835 import { edgeLoginUrl } from "../../http/edge.ts";
3936 import { sshCommand } from "../../ssh/command.ts";
4037 import { hostOf, pageHead, signInFirst } from "../chrome.ts";
@@ -182,37 +179,7 @@ const threadPath = (repo: Repo, issue: Issue): string =>
182179 /** Open issues and pulls assigned to the viewer, anywhere they can see. */
183180 export function onYouCard(ctx: Ctx, user: User): Html | undefined {
184181 const db = ctx.app.db;
185 const assigned = listAssignedTo(db, user.id, 20);
186 if (assigned.length === 0) return undefined;
187 const repos = getReposByIds(
188 db,
189 assigned.map((issue) => issue.repoId),
190 );
191 // `listAssignedTo` has no visibility filter of its own (an assignment can
192 // outlive the access that made it), so each repo needs a real `canRead`.
193 // Checking it straight would cost one query per row for any repo the
194 // viewer does not own outright — `canRead` resolves org ownership from
195 // the database. `listReposVisibleTo` answers the common case with one
196 // query for the whole page; `canRead` only runs for the rare repo it
197 // did not reach (its own cap), so the cost stays flat as rows grow.
198 const visible = new Set(
199 listReposVisibleTo(db, user, { limit: 200 }).map((repo) => repo.id),
200 );
201 const muted = mutedRepos(db, user.id);
202 const shown: { issue: Issue; repo: Repo }[] = [];
203 // Muted repositories that hold work assigned to the viewer: said, never silent.
204 const silenced = new Map<string, Repo>();
205 for (const issue of assigned) {
206 const repo = repos.get(issue.repoId);
207 if (!repo) continue;
208 if (!visible.has(repo.id) && !canRead(db, repo, user)) continue;
209 if (!mayView(db, repo, issue, user)) continue;
210 if (muted.has(repo.id)) {
211 silenced.set(repo.id, repo);
212 continue;
213 }
214 shown.push({ issue, repo });
215 }
182 const { shown, silenced } = assignedTo(db, user);
216183 // Two or more can be given one move: a box each, and one form for the set.
217184 const bulk = shown.length >= 2;
218185 const heads = new Map(
@@ -243,7 +210,9 @@ export function onYouCard(ctx: Ctx, user: User): Html | undefined {
243210 ? html`<a href="${threadPath(repo, issue)}">${issue.title}</a>`
244211 : issue.title,
245212 titleAttr: issue.title,
246 meta: html`${repo.ownerName}/${repo.name} #${issue.number} · updated
213 meta: html`<b class="ask-kind"
214 >${conflicts > 0 ? "conflicts with main" : ASSIGNED_WAITING_FOR}</b
215 >${repo.ownerName}/${repo.name} #${issue.number} · updated
247216 ${time(issue.updatedAt)}${conflicts > 0
248217 ? html` · <span class="conflicts">Conflicts in ${conflicts}
249218 ${conflicts === 1 ? "file" : "files"}</span>`
@@ -261,7 +230,7 @@ export function onYouCard(ctx: Ctx, user: User): Html | undefined {
261230 );
262231 return listCard(rows, {
263232 head: html`${icon("user")}
264 <h2>On you</h2>`,
233 <h2>Needs you</h2>`,
265234 ...(bulk || last !== undefined || silenced.size > 0
266235 ? {
267236 foot: onYouBulk(
src/web/studio/asks.ts +43 −6
@@ -52,6 +52,7 @@ import {
5252 import { breakerParked, WAITING_NOTES } from "../../crew/breaker.ts";
5353 import { CHECK_FAILED_LIMIT } from "../../crew/dispatch.ts";
5454 import { isStalePull, mergesAgainSince } from "../../crew/stale_asks.ts";
55 import { assignedTo, assignedWaitingFor, waitingForAsk } from "./waiting.ts";
5556 import { waitsForPerson, waitsForReviewer, type ReviewWait } from "../../crew/review.ts";
5657 import type { Ctx } from "../../http/context.ts";
5758 import { vitals } from "../../kernel/vitals.ts";
@@ -738,6 +739,8 @@ export function askLinesFor(
738739 items: string[];
739740 /** The decision, its options and what happens if nobody acts (`ASK_WORDS`). */
740741 words: AskWords;
742 /** What it waits for, in a few words: "ready to land", "a decision" (`WAITING_FOR`). */
743 waitingFor: string;
741744 /** Why it ranks where it does; rows come most consequential first. */
742745 consequence: Consequence;
743746 }[] {
@@ -753,24 +756,28 @@ export function askLinesFor(
753756 consequence: row.consequence,
754757 };
755758 const only = row.items.length === 1 ? row.items[0]! : undefined;
759 const waitingFor = waitingForAsk(db, row.kind, only?.pull);
756760 if (only === undefined)
757761 return {
758762 ...about,
763 waitingFor,
759764 line: `${row.repo.name}: ${rowLine(row.kind, row.items.length)}`,
760765 link: `/#${askAnchor(row.id)}`,
761766 };
762767 const line = `${row.repo.name}${only.kind === "paused" ? " " : ": "}${lineOf(only)}`;
763768 if (only.kind === "paused")
764 return { ...about, line, link: `${base}/settings/autonomy` };
769 return { ...about, waitingFor, line, link: `${base}/settings/autonomy` };
765770 if (only.kind === "parked" || only.kind === "declined")
766771 return {
767772 ...about,
773 waitingFor,
768774 line,
769775 number: only.issue!.number,
770776 link: `${base}/issues/${only.issue!.number}`,
771777 };
772778 return {
773779 ...about,
780 waitingFor,
774781 line,
775782 number: only.pull!.number,
776783 link: `${base}/changes/${only.pull!.number}`,
@@ -1019,13 +1026,33 @@ export function forgeNeedsFor(ctx: Ctx, user: User | undefined): Degraded[] {
10191026 */
10201027 export function askCountFor(ctx: Ctx, user: User | undefined): number {
10211028 if (!user) return 0;
1022 const repos = listReposVisibleTo(ctx.app.db, user, { limit: 200 });
1029 const db = ctx.app.db;
1030 const rows = askRows(waitingOn(db, user, listReposVisibleTo(db, user, { limit: 200 })));
10231031 return (
1024 askRows(waitingOn(ctx.app.db, user, repos)).length +
1025 forgeNeedsFor(ctx, user).length
1032 rows.length +
1033 forgeNeedsFor(ctx, user).length +
1034 assignedTo(db, user, idsOf(rows)).shown.length
10261035 );
10271036 }
10281037
1038 /** The ids of every item the asks hold: what assigned work is not counted twice against. */
1039 export const idsOf = (rows: readonly { items: readonly { id: string }[] }[]): Set<string> =>
1040 new Set(rows.flatMap((r) => r.items.map((c) => c.id)));
1041
1042 /** The work assigned to the viewer that no ask already holds, as rows of the one list. */
1043 export function assignedLines(db: Database, user: User, taken: ReadonlySet<string>) {
1044 return assignedTo(db, user, taken).shown.map(({ issue, repo }) => ({
1045 id: `assigned:${issue.id}`,
1046 kind: "assigned" as const,
1047 repoId: repo.id,
1048 line: `${repo.name}: ${issue.title}`,
1049 number: issue.number,
1050 link: `/${repo.ownerName}/${repo.name}/${issue.kind === "pull" ? "changes" : "issues"}/${issue.number}`,
1051 items: [`issue:${issue.id}`],
1052 waitingFor: assignedWaitingFor(db, issue),
1053 }));
1054 }
1055
10291056 /** The single sentence the asks page leads with, and the dashboard links with. */
10301057 export function askSentence(count: number): string {
10311058 return count === 0
@@ -1041,9 +1068,19 @@ export function askSentence(count: number): string {
10411068 */
10421069 export function asksAnswer(ctx: Ctx, user: User) {
10431070 const since = new Date(Date.now() - 7 * 86_400_000).toISOString();
1071 const rows = askLinesFor(ctx.app.db, user);
1072 const assigned = assignedLines(
1073 ctx.app.db,
1074 user,
1075 new Set(rows.flatMap((r) => r.items)),
1076 );
1077 const forge = forgeNeedsFor(ctx, user).map((d) => needLine(d));
10441078 return {
1045 rows: askLinesFor(ctx.app.db, user),
1046 forge: forgeNeedsFor(ctx, user).map((d) => needLine(d)),
1079 /** The one count: what the top bar and the home's sentence say. */
1080 count: rows.length + forge.length + assigned.length,
1081 rows,
1082 assigned,
1083 forge,
10471084 measure: { days: 7, ...askMeasure(ctx.app.db, user.id, since) },
10481085 };
10491086 }
src/web/studio/asks_page.ts +7 −12
@@ -46,11 +46,13 @@ import {
4646 decisionForm,
4747 decisionsFor,
4848 forgeNeedsFor,
49 idsOf,
4950 silencedRepos,
5051 type AskRow,
5152 type Consequence,
5253 type Decision,
5354 } from "./asks.ts";
55 import { assignedTo, waitingForAsk } from "./waiting.ts";
5456 import { changeHref } from "./nouns.ts";
5557
5658 /** The kinds, in a word each, for "select by kind". */
@@ -156,16 +158,6 @@ const clause = (
156158 >
157159 </p>`;
158160
159 /** The kind, in two words: what a phone's row says in place of the sentence under it. */
160 const KIND_LABEL: Readonly<Record<Decision["kind"], string>> = {
161 look: "Ready to ship",
162 review: "Needs review",
163 stopped: "Stopped",
164 parked: "Parked",
165 declined: "Declined",
166 paused: "Paused",
167 };
168
169161 /**
170162 * An ask's actions: the one that decides, then the rest. A wide screen
171163 * lays them in a line; a phone puts the decider at the trailing edge, 44 px
@@ -200,7 +192,7 @@ function decisionCard(ctx: Ctx, d: Decision, picked: ReadonlySet<string>): Html
200192 head: html`${pick(d, picked)}
201193 <h2>${title}</h2>
202194 <span class="ask-meta muted small"
203 ><b class="ask-kind">${KIND_LABEL[d.kind]}</b>${d.repo.ownerName}/${d.repo.name}</span
195 ><b class="ask-kind">${waitingForAsk(ctx.app.db, d.kind, d.pull)}</b>${d.repo.ownerName}/${d.repo.name}</span
204196 >`,
205197 },
206198 );
@@ -366,7 +358,10 @@ export function needsYouSection(
366358 >
367359 <button type="submit" class="btn btn-sm btn-ghost">Listen again</button>
368360 </form>`;
369 const count = rows.length + needs.length;
361 const count =
362 rows.length +
363 needs.length +
364 assignedTo(ctx.app.db, user, idsOf(rows)).shown.length;
370365 if (count === 0 && top === undefined)
371366 return {
372367 body: html`<h2 id="asks-sentence" class="sr-only">${askSentence(0)}</h2>${silencedNote}`,
src/web/studio/waiting.ts added +101
@@ -0,0 +1,101 @@
1 /**
2 * What waits on a person, in one word each. The asks (decisions the crew
3 * raised) and the work assigned to the viewer are one list: they share a
4 * count (the top bar, the home's sentence, `/api/v1/asks`, the MCP) and each
5 * row says what it waits for — "ready to land", "conflicts with main", "a
6 * decision", "your review", "assigned to you".
7 */
8
9 import type { Database } from "bun:sqlite";
10 import { mutedRepos } from "../../core/interactions.ts";
11 import { listAssignedTo, type Issue } from "../../core/issues.ts";
12 import { joinMany } from "../../core/pulls.ts";
13 import { mayView } from "../../core/sealed.ts";
14 import {
15 canRead,
16 getReposByIds,
17 listReposVisibleTo,
18 type Repo,
19 } from "../../core/repos.ts";
20 import type { User } from "../../core/users.ts";
21 import { conflictsOf } from "../../crew/stale_asks.ts";
22 import type { DecisionKind } from "./asks.ts";
23
24 /** What each kind of ask waits for, when nothing about the thing says more. */
25 export const WAITING_FOR: Readonly<Record<DecisionKind, string>> = {
26 look: "ready to land",
27 review: "your review",
28 stopped: "a decision",
29 parked: "a decision",
30 declined: "a decision",
31 paused: "a decision",
32 };
33
34 /** What work assigned to the viewer waits for. */
35 export const ASSIGNED_WAITING_FOR = "assigned to you";
36
37 /** A green pull that cannot merge waits for a fix, not a landing. */
38 export function waitingForAsk(
39 db: Database,
40 kind: DecisionKind,
41 pull: { id: string; headOid: string } | undefined,
42 ): string {
43 if (kind === "look" && pull !== undefined && conflictsOf(db, pull.id, pull.headOid) > 0)
44 return "conflicts with main";
45 return WAITING_FOR[kind];
46 }
47
48 /** What a piece of assigned work waits for: a pull that cannot merge says so. */
49 export function assignedWaitingFor(db: Database, issue: Issue): string {
50 if (issue.kind !== "pull") return ASSIGNED_WAITING_FOR;
51 const head = joinMany(db, [issue])[0]?.headOid ?? "";
52 return conflictsOf(db, issue.id, head) > 0 ? "conflicts with main" : ASSIGNED_WAITING_FOR;
53 }
54
55 export interface Assigned {
56 readonly issue: Issue;
57 readonly repo: Repo;
58 }
59
60 /**
61 * Open issues and pulls assigned to the viewer that they may see: `shown`,
62 * and the repositories they muted that hold some, `silenced` (said, never
63 * silent). Work that is already one of `taken` — an ask's item ids — is
64 * left out: a row is counted once.
65 */
66 export function assignedTo(
67 db: Database,
68 user: User,
69 taken: ReadonlySet<string> = new Set(),
70 ): { shown: Assigned[]; silenced: Map<string, Repo> } {
71 const shown: Assigned[] = [];
72 const silenced = new Map<string, Repo>();
73 const assigned = listAssignedTo(db, user.id, 20);
74 if (assigned.length === 0) return { shown, silenced };
75 const repos = getReposByIds(
76 db,
77 assigned.map((issue) => issue.repoId),
78 );
79 // `listAssignedTo` has no visibility filter of its own (an assignment can
80 // outlive the access that made it), so each repo needs a real `canRead`.
81 // `listReposVisibleTo` answers the common case with one query for the
82 // whole page; `canRead` only runs for the rare repo it did not reach.
83 const visible = new Set(
84 listReposVisibleTo(db, user, { limit: 200 }).map((repo) => repo.id),
85 );
86 const muted = mutedRepos(db, user.id);
87 for (const issue of assigned) {
88 const repo = repos.get(issue.repoId);
89 if (!repo) continue;
90 if (!visible.has(repo.id) && !canRead(db, repo, user)) continue;
91 if (!mayView(db, repo, issue, user)) continue;
92 if (muted.has(repo.id)) {
93 silenced.set(repo.id, repo);
94 continue;
95 }
96 if (["look", "review", "stopped", "parked"].some((k) => taken.has(`${k}:${issue.id}`)))
97 continue;
98 shown.push({ issue, repo });
99 }
100 return { shown, silenced };
101 }
test/home-feed.test.ts +1 −1
@@ -370,7 +370,7 @@ describe("home is the feed", () => {
370370 expect(assignIssue(app, alice, repo, issue, alice).ok).toBe(true);
371371 const text = await (await get("/", aliceCookie)).text();
372372 const card = text.slice(text.indexOf('id="live-on-you"')).replace(/\s+/g, " ");
373 expect(card).toContain("On you");
373 expect(card).toContain("Needs you");
374374 expect(card).toContain(`value="issue:${one.value.id}"`);
375375 expect(card).toContain(`value="issue:${two.value.id}"`);
376376 expect((card.match(/form="onyou-bulk"/g) ?? []).length).toBeGreaterThanOrEqual(2);
test/inbox.test.ts added +110
@@ -0,0 +1,110 @@
1 /**
2 * One list: what is assigned to the viewer and what the crew asks of them
3 * share one word ("Needs you"), one count (the home's sentence, the top bar,
4 * `/api/v1/asks`, the MCP) and a "waiting for" on every row.
5 */
6
7 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
8 import { mkdtemp, rm } from "node:fs/promises";
9 import { tmpdir } from "node:os";
10 import { join } from "node:path";
11 import { createApp, type App } from "../src/app.ts";
12 import { assignIssue } from "../src/actions/issues.ts";
13 import { createRepo } from "../src/actions/repos.ts";
14 import { createIssue } from "../src/core/issues.ts";
15 import type { Repo } from "../src/core/repos.ts";
16 import { createToken } from "../src/core/tokens.ts";
17 import { createUser, type User } from "../src/core/users.ts";
18 import { serve, type Servers } from "../src/http/server.ts";
19 import { onYouCard } from "../src/web/pages/site.ts";
20 import { askCountFor, asksAnswer } from "../src/web/studio/asks.ts";
21 import { needsYouSection } from "../src/web/studio/asks_page.ts";
22 import { quietLogs } from "./helpers/globals.ts";
23
24 quietLogs();
25
26 describe("one list on you", () => {
27 let dataDir = "";
28 let app: App;
29 let servers: Servers;
30 let alice: User;
31 let repo: Repo;
32 let token = "";
33 const ctx = () => ({ app, auth: { user: alice } }) as never;
34
35 beforeAll(async () => {
36 dataDir = await mkdtemp(join(tmpdir(), "forge-inbox-"));
37 app = createApp({ dataDir, port: 0 });
38 servers = await serve(app);
39 const a = await createUser(app.db, {
40 trusted: true,
41 username: "alice",
42 email: "[email protected]",
43 password: "a-long-inbox-passphrase",
44 adminIfFirst: true,
45 });
46 if (!a.ok) throw new Error(a.error);
47 alice = a.value;
48 const made = await createRepo(app, alice, { name: "garden", visibility: "public" });
49 if (!made.ok) throw new Error(String(made.error));
50 repo = made.value;
51 token = createToken(app.db, alice.id, "ro", "ro").token;
52 }, 30_000);
53
54 afterAll(async () => {
55 await servers.stop();
56 await rm(dataDir, { recursive: true, force: true });
57 });
58
59 test("nothing assigned, nothing asked: zero, and All fine", () => {
60 expect(askCountFor(ctx(), alice)).toBe(0);
61 expect(needsYouSection(ctx(), alice).body.text).toContain("All fine");
62 expect(onYouCard(ctx(), alice)).toBeUndefined();
63 });
64
65 test("work assigned to you is counted once by the header, the home, the API and the MCP, and says what it waits for", async () => {
66 const made = createIssue(app.db, {
67 repoId: repo.id,
68 authorId: alice.id,
69 title: "Water the beans",
70 });
71 if (!made.ok) throw new Error(made.error);
72 expect(assignIssue(app, alice, repo, made.value, alice).ok).toBe(true);
73
74 expect(askCountFor(ctx(), alice)).toBe(1);
75 const section = needsYouSection(ctx(), alice).body.text.replace(/\s+/g, " ");
76 expect(section).toContain("1 thing needs you");
77
78 const card = onYouCard(ctx(), alice)?.text.replace(/\s+/g, " ") ?? "";
79 expect(card).toContain("<h2>Needs you</h2>");
80 expect(card).not.toContain("On you");
81 expect(card).toContain("assigned to you");
82 expect(card).toContain("Water the beans");
83
84 const answer = asksAnswer(ctx(), alice);
85 expect(answer.count).toBe(1);
86 expect(answer.assigned.map((r) => r.waitingFor)).toEqual(["assigned to you"]);
87
88 const res = await fetch(`${servers.url}/mcp`, {
89 method: "POST",
90 headers: {
91 "content-type": "application/json",
92 accept: "application/json, text/event-stream",
93 authorization: `Bearer ${token}`,
94 },
95 body: JSON.stringify({
96 jsonrpc: "2.0",
97 id: 1,
98 method: "tools/call",
99 params: { name: "asks", arguments: {} },
100 }),
101 });
102 const body = (await res.json()) as { result: { content: { text: string }[] } };
103 const seen = JSON.parse(body.result.content[0]!.text) as {
104 count: number;
105 assigned: { waitingFor: string }[];
106 };
107 expect(seen.count).toBe(1);
108 expect(seen.assigned[0]!.waitingFor).toBe("assigned to you");
109 });
110 });
test/needs-you.test.ts added +160
@@ -0,0 +1,160 @@
1 /**
2 * The one list's hard parts (#1603): a pull that is both assigned to you and
3 * an ask counts once everywhere; each row says what it waits for; a green
4 * pull that cannot merge says "conflicts with main"; a muted repository is
5 * still said to be silenced; and the terminal shows the same count and label.
6 */
7
8 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
9 import { mkdtemp, rm } from "node:fs/promises";
10 import { tmpdir } from "node:os";
11 import { join } from "node:path";
12 import { createApp, type App } from "../src/app.ts";
13 import { addToCrew, createAgent } from "../src/actions/crew.ts";
14 import { openPull } from "../src/actions/pulls.ts";
15 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
16 import { muteRepo } from "../src/core/interactions.ts";
17 import { setAssignee } from "../src/core/issues.ts";
18 import type { Pull } from "../src/core/pulls.ts";
19 import type { Repo } from "../src/core/repos.ts";
20 import { claimRun, createRun, finishRun } from "../src/core/runs.ts";
21 import { createUser, getUserByName, type User } from "../src/core/users.ts";
22 import { sweepStaleAsks } from "../src/crew/stale_asks.ts";
23 import { onYouCard } from "../src/web/pages/site.ts";
24 import {
25 askCountFor,
26 askLinesFor,
27 asksAnswer,
28 assignedLines,
29 type DecisionKind,
30 } from "../src/web/studio/asks.ts";
31 import { needsYouSection } from "../src/web/studio/asks_page.ts";
32 import { WAITING_FOR, waitingForAsk } from "../src/web/studio/waiting.ts";
33 import { quietLogs } from "./helpers/globals.ts";
34
35 quietLogs();
36
37 describe("one list: dedupe, waiting for, conflicts, mutes", () => {
38 let dataDir = "";
39 let app: App;
40 let alice: User;
41 let repo: Repo;
42 const ctx = () => ({ app, auth: { user: alice } }) as never;
43 const flat = (text: string): string => text.replace(/\s+/g, " ");
44
45 const pullFor = async (slug: string, path: string, content: string): Promise<Pull> => {
46 await commitToBranch(app, alice, repo, {
47 branch: `bot/${slug}`,
48 base: "main",
49 message: slug,
50 files: [{ path, content }],
51 });
52 const opened = await openPull(app, getUserByName(app.db, "bot")!, repo, {
53 title: `Bot: ${slug}`,
54 body: "",
55 baseBranch: "main",
56 headBranch: `bot/${slug}`,
57 });
58 if (!opened.ok) throw new Error(String(opened.error));
59 const run = createRun(app.db, {
60 repoId: repo.id,
61 kind: "check",
62 issueId: opened.value.id,
63 env: `pull-${opened.value.number}`,
64 commitOid: opened.value.headOid,
65 reason: "pull",
66 });
67 claimRun(app.db, run.id);
68 finishRun(app.db, run.id, { state: "ok", summary: "green" });
69 return opened.value;
70 };
71
72 beforeAll(async () => {
73 dataDir = await mkdtemp(join(tmpdir(), "forge-needs-you-"));
74 app = createApp({ dataDir, port: 0 });
75 const a = await createUser(app.db, {
76 trusted: true,
77 username: "alice",
78 email: "[email protected]",
79 password: "a-long-needs-passphrase",
80 adminIfFirst: true,
81 });
82 if (!a.ok) throw new Error(a.error);
83 alice = a.value;
84 const made = await createRepo(app, alice, { name: "orchard", visibility: "public" });
85 if (!made.ok) throw new Error(String(made.error));
86 repo = made.value;
87 await commitToBranch(app, alice, repo, {
88 message: "seed",
89 files: [{ path: "README.md", content: "# orchard\n" }],
90 });
91 await createAgent(app, alice, { username: "bot" });
92 addToCrew(app, alice, repo, "bot");
93 }, 30_000);
94
95 afterAll(async () => {
96 await rm(dataDir, { recursive: true, force: true });
97 });
98
99 let apples: Pull;
100
101 test("a pull that is an ask and assigned to you counts once, everywhere", async () => {
102 apples = await pullFor("apples", "APPLES.md", "apples\n");
103 expect(askCountFor(ctx(), alice)).toBe(1);
104 setAssignee(app.db, apples.id, alice.id);
105
106 expect(askCountFor(ctx(), alice)).toBe(1);
107 const answer = asksAnswer(ctx(), alice);
108 expect(answer.count).toBe(1);
109 expect(answer.rows).toHaveLength(1);
110 expect(answer.assigned).toHaveLength(0);
111 expect(assignedLines(app.db, alice, new Set())).toHaveLength(1);
112 expect(flat(needsYouSection(ctx(), alice).body.text)).toContain("1 thing needs you");
113 // The assigned card does not list it a second time.
114 expect(onYouCard(ctx(), alice)).toBeDefined();
115 });
116
117 test("an ask row says what it waits for, in the data and on the page", () => {
118 const [row] = asksAnswer(ctx(), alice).rows;
119 expect(row!.waitingFor).toBe("ready to land");
120 expect(flat(needsYouSection(ctx(), alice).body.text)).toContain("ready to land");
121 });
122
123 test("every kind of ask has a label, and a review or a decision says so", () => {
124 const kinds = Object.keys(WAITING_FOR) as DecisionKind[];
125 expect(kinds.length).toBeGreaterThanOrEqual(6);
126 expect(waitingForAsk(app.db, "review", undefined)).toBe("your review");
127 for (const k of ["stopped", "parked", "declined", "paused"] as const)
128 expect(waitingForAsk(app.db, k, undefined)).toBe("a decision");
129 expect(waitingForAsk(app.db, "look", undefined)).toBe("ready to land");
130 });
131
132 test("a green pull that conflicts with main says so, as an ask label and as an assigned row", async () => {
133 const plums = await pullFor("plums", "README.md", "# plums\n");
134 setAssignee(app.db, plums.id, alice.id);
135 await commitToBranch(app, alice, repo, {
136 message: "main moves",
137 files: [{ path: "README.md", content: "# orchard, renamed\n" }],
138 });
139 await sweepStaleAsks(app);
140 expect(waitingForAsk(app.db, "look", plums)).toBe("conflicts with main");
141 expect(waitingForAsk(app.db, "look", apples)).toBe("ready to land");
142 const lines = assignedLines(app.db, alice, new Set());
143 expect(lines.find((l) => l.id === `assigned:${plums.id}`)!.waitingFor).toBe("conflicts with main");
144 const answer = asksAnswer(ctx(), alice);
145 expect(answer.assigned.map((l) => l.waitingFor)).toEqual(["conflicts with main"]);
146 expect(answer.count).toBe(answer.rows.length + 1);
147 expect(flat(onYouCard(ctx(), alice)!.text)).toContain("conflicts with main");
148 });
149
150 test("a muted repository leaves the count and is still said to be silenced", () => {
151 muteRepo(app.db, alice.id, repo.id);
152 expect(askLinesFor(app.db, alice)).toHaveLength(0);
153 expect(askCountFor(ctx(), alice)).toBe(0);
154 expect(asksAnswer(ctx(), alice).count).toBe(0);
155 const section = flat(needsYouSection(ctx(), alice).body.text);
156 expect(section).toContain("1 muted repository still asks");
157 expect(section).toContain("Listen again");
158 expect(flat(onYouCard(ctx(), alice)?.text ?? "")).toContain("muted");
159 });
160 });
test/tui-apps.test.ts +7 −4
@@ -401,7 +401,7 @@ describe("terminal: apps, runs and the crew", () => {
401401 }
402402 }, 30_000);
403403
404 test("the dashboard: an On you pane, enterable, and no Apps pane", async () => {
404 test("the dashboard: a Needs you pane, enterable, and no Apps pane", async () => {
405405 const mine = openIssue(forge, alice, site, {
406406 title: "Tune the drums",
407407 body: "",
@@ -413,8 +413,11 @@ describe("terminal: apps, runs and the crew", () => {
413413
414414 const h = boot(forge, identityFor(alice));
415415 try {
416 await h.until("On you");
416 await h.until("Needs you");
417417 expect(h.text()).toContain("Tune the drums");
418 // The web's one count and its waiting-for label, in the terminal.
419 expect(h.text()).toContain("Needs you (1)");
420 expect(h.text()).toContain("assigned to you");
418421 expect(h.text()).not.toContain("Apps");
419422 // repos → on you.
420423 await h.press("tab", "enter");
@@ -439,7 +442,7 @@ describe("terminal: apps, runs and the crew", () => {
439442 expect(hidden.ok).toBe(true);
440443 const h = boot(forge, identityFor(bob));
441444 try {
442 await h.until("On you");
445 await h.until("Needs you");
443446 expect(h.text()).not.toContain("alice/alices-lantern");
444447 await h.press("/");
445448 await h.type("alices");
@@ -456,7 +459,7 @@ describe("terminal: apps, runs and the crew", () => {
456459 test("the removed screens are unreachable: no palette entry, no dashboard or account key", async () => {
457460 const h = boot(forge, identityFor(alice));
458461 try {
459 await h.until("On you");
462 await h.until("Needs you");
460463 // alice is the site admin, so the crew entry would have been there.
461464 const ids = forgeCommands(h.session)(h.app.ctx).map((c) => c.id);
462465 for (const gone of ["apps", "app", "runs", "new-app", "crew"])
test/web-apps.test.ts +2 −2
@@ -823,9 +823,9 @@ describe("apps, runs and the crew on the web", () => {
823823 });
824824 expect(assigned.status).toBe(303);
825825 const dash = await bodyOf(alice, "/");
826 expect(dash).toContain("<h2>On you</h2>");
826 expect(dash).toContain("<h2>Needs you</h2>");
827827 expect(dash).toContain("Say hello");
828 expect(await bodyOf(bob, "/")).not.toContain("<h2>On you</h2>");
828 expect(await bodyOf(bob, "/")).not.toContain("<h2>Needs you</h2>");
829829
830830 // Needs you: a pull the crew opened, in a repository alice can write.
831831 expect(addToCrew(app, aliceUser, hello, "bot").ok).toBe(true);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs