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 #1787

Closed opened this
Closed without merging

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

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
12 files changed +469 −72
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
@@ -115,6 +116,8 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
115116 /** Why planning is paused, for the autonomous apps where it is; as on the board. */
116117 let holds = new Map<string, string>();
117118 let forge: string[] | undefined;
119 /** The one count the web shows too: asks, the forge's own needs and assigned work, once each. */
120 let needs = 0;
118121 /** The check lane, as the board's strip says it; null when nothing is queued. */
119122 let lane: string | null = null;
120123 const filter = new Filter();
@@ -145,6 +148,13 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
145148 }),
146149 );
147150 forge = forgeNeeds(f.app, f.user);
151 if (f.user !== undefined) {
152 const asked = askLinesFor(f.db, f.user);
153 needs =
154 asked.length +
155 (forge?.length ?? 0) +
156 assignedLines(f.db, f.user, new Set(asked.flatMap((r) => r.items))).length;
157 }
148158 lane = forgeLane(f.app, f.user);
149159 // "Yours" is ownership plus the orgs you are on a team of; typing in the
150160 // filter reaches every repository you can see.
@@ -633,7 +643,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
633643 const on = focus === "onyou";
634644 const footer = onYouFooter();
635645 const inner = card(s, r, c, {
636 title: `${icon("person", set)} ${TITLES.onyou}`,
646 title: `${icon("person", set)} ${TITLES.onyou}${needs > 0 ? ` (${needs})` : ""}`,
637647 focused: on,
638648 ...(footer === undefined ? {} : { footer }),
639649 });
@@ -659,7 +669,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
659669 : ISSUE_MARK;
660670 return {
661671 title: `${marked.has(item.issue.id) ? "[x] " : ""}${item.hand === true ? "parked " : item.over === true ? "handed over " : ""}${mark} #${item.issue.number} ${item.issue.title}`,
662 meta: `${item.repo.ownerName}/${item.repo.name}`,
672 meta: `${item.hand === true ? WAITING_FOR.parked : item.over === true ? WAITING_FOR.handover : assignedWaitingFor(f.db, item.issue)} · ${item.repo.ownerName}/${item.repo.name}`,
663673 };
664674 }),
665675 on,
src/web/pages/site.ts +8 −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";
@@ -32,9 +30,9 @@ import { hasAnyUser, verifyPassword, type User } from "../../core/users.ts";
3230 import { isThemeName } from "../../design/themes.ts";
3331 import { cookieValue, crossOrigin, type Ctx } from "../../http/context.ts";
3432 import { studioDoor, studioHome } from "../studio/home.ts";
33 import { askItemIdsFor } from "../studio/asks.ts";
3534 import { homeTop, onYouBulk } from "../studio/asks_page.ts";
3635 import { latestUndoable } from "../../actions/asks_bulk.ts";
37 import { mutedRepos } from "../../core/interactions.ts";
3836 import { edgeLoginUrl } from "../../http/edge.ts";
3937 import { sshCommand } from "../../ssh/command.ts";
4038 import { hostOf, pageHead, signInFirst } from "../chrome.ts";
@@ -182,37 +180,7 @@ const threadPath = (repo: Repo, issue: Issue): string =>
182180 /** Open issues and pulls assigned to the viewer, anywhere they can see. */
183181 export function onYouCard(ctx: Ctx, user: User): Html | undefined {
184182 const db = ctx.app.db;
outdated

assignedTo(db, user) is called without the taken set, so a pull that is both an ask and assigned to you appears here as well as in the ask rows. The count dedupes it and the page does not. Pass idsOf(askRows) here.

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 }
183 const { shown, silenced } = assignedTo(db, user, askItemIdsFor(db, user));
216184 // Two or more can be given one move: a box each, and one form for the set.
217185 const bulk = shown.length >= 2;
218186 const heads = new Map(
@@ -243,7 +211,9 @@ export function onYouCard(ctx: Ctx, user: User): Html | undefined {
243211 ? html`<a href="${threadPath(repo, issue)}">${issue.title}</a>`
244212 : issue.title,
245213 titleAttr: issue.title,
246 meta: html`${repo.ownerName}/${repo.name} #${issue.number} · updated
214 meta: html`<b class="ask-kind"
215 >${conflicts > 0 ? "conflicts with main" : ASSIGNED_WAITING_FOR}</b
216 >${repo.ownerName}/${repo.name} #${issue.number} · updated
247217 ${time(issue.updatedAt)}${conflicts > 0
248218 ? html` · <span class="conflicts">Conflicts in ${conflicts}
249219 ${conflicts === 1 ? "file" : "files"}</span>`
@@ -261,7 +231,7 @@ export function onYouCard(ctx: Ctx, user: User): Html | undefined {
261231 );
262232 return listCard(rows, {
263233 head: html`${icon("user")}
264 <h2>On you</h2>`,
234 <h2>Needs you</h2>`,
265235 ...(bulk || last !== undefined || silenced.size > 0
266236 ? {
267237 foot: onYouBulk(
src/web/studio/asks.ts +48 −6
@@ -53,6 +53,7 @@ import { breakerParked, WAITING_NOTES } from "../../crew/breaker.ts";
5353 import { CHECK_FAILED_LIMIT } from "../../crew/dispatch.ts";
5454 import { handoverLines, handoverOf, type Handover } from "../../crew/guard.ts";
5555 import { isStalePull, mergesAgainSince } from "../../crew/stale_asks.ts";
56 import { assignedTo, assignedWaitingFor, waitingForAsk } from "./waiting.ts";
5657 import { waitsForPerson, waitsForReviewer, type ReviewWait } from "../../crew/review.ts";
5758 import type { Ctx } from "../../http/context.ts";
5859 import { vitals } from "../../kernel/vitals.ts";
@@ -775,6 +776,8 @@ export function askLinesFor(
775776 items: string[];
776777 /** The decision, its options and what happens if nobody acts (`ASK_WORDS`). */
777778 words: AskWords;
779 /** What it waits for, in a few words: "ready to land", "a decision" (`WAITING_FOR`). */
780 waitingFor: string;
778781 /** Why it ranks where it does; rows come most consequential first. */
779782 consequence: Consequence;
780783 }[] {
@@ -790,24 +793,28 @@ export function askLinesFor(
790793 consequence: row.consequence,
791794 };
792795 const only = row.items.length === 1 ? row.items[0]! : undefined;
796 const waitingFor = waitingForAsk(db, row.kind, only?.pull);
793797 if (only === undefined)
794798 return {
795799 ...about,
800 waitingFor,
796801 line: `${row.repo.name}: ${rowLine(row.kind, row.items.length)}`,
797802 link: `/#${askAnchor(row.id)}`,
798803 };
799804 const line = `${row.repo.name}${only.kind === "paused" ? " " : ": "}${lineOf(only)}`;
800805 if (only.kind === "paused")
801 return { ...about, line, link: `${base}/settings/autonomy` };
806 return { ...about, waitingFor, line, link: `${base}/settings/autonomy` };
802807 if (only.kind === "parked" || only.kind === "declined")
803808 return {
804809 ...about,
810 waitingFor,
805811 line,
806812 number: only.issue!.number,
807813 link: `${base}/issues/${only.issue!.number}`,
808814 };
809815 return {
810816 ...about,
817 waitingFor,
811818 line,
812819 number: only.pull!.number,
813820 link: `${base}/changes/${only.pull!.number}`,
@@ -1067,13 +1074,38 @@ export function forgeNeedsFor(ctx: Ctx, user: User | undefined): Degraded[] {
10671074 */
10681075 export function askCountFor(ctx: Ctx, user: User | undefined): number {
10691076 if (!user) return 0;
1070 const repos = listReposVisibleTo(ctx.app.db, user, { limit: 200 });
1077 const db = ctx.app.db;
1078 const rows = askRows(waitingOn(db, user, listReposVisibleTo(db, user, { limit: 200 })));
10711079 return (
1072 askRows(waitingOn(ctx.app.db, user, repos)).length +
1073 forgeNeedsFor(ctx, user).length
1080 rows.length +
1081 forgeNeedsFor(ctx, user).length +
1082 assignedTo(db, user, idsOf(rows)).shown.length
10741083 );
10751084 }
10761085
1086 /** The item ids of every ask the viewer has: what their assigned work is held against. */
1087 export function askItemIdsFor(db: Database, user: User): Set<string> {
1088 return idsOf(askRows(waitingOn(db, user, listReposVisibleTo(db, user, { limit: 200 }))));
1089 }
1090
1091 /** The ids of every item the asks hold: what assigned work is not counted twice against. */
1092 export const idsOf = (rows: readonly { items: readonly { id: string }[] }[]): Set<string> =>
1093 new Set(rows.flatMap((r) => r.items.map((c) => c.id)));
1094
1095 /** The work assigned to the viewer that no ask already holds, as rows of the one list. */
1096 export function assignedLines(db: Database, user: User, taken: ReadonlySet<string>) {
1097 return assignedTo(db, user, taken).shown.map(({ issue, repo }) => ({
1098 id: `assigned:${issue.id}`,
1099 kind: "assigned" as const,
1100 repoId: repo.id,
1101 line: `${repo.name}: ${issue.title}`,
1102 number: issue.number,
1103 link: `/${repo.ownerName}/${repo.name}/${issue.kind === "pull" ? "changes" : "issues"}/${issue.number}`,
1104 items: [`issue:${issue.id}`],
1105 waitingFor: assignedWaitingFor(db, issue),
1106 }));
1107 }
1108
10771109 /** The single sentence the asks page leads with, and the dashboard links with. */
10781110 export function askSentence(count: number): string {
10791111 return count === 0
@@ -1089,9 +1121,19 @@ export function askSentence(count: number): string {
10891121 */
10901122 export function asksAnswer(ctx: Ctx, user: User) {
10911123 const since = new Date(Date.now() - 7 * 86_400_000).toISOString();
1124 const rows = askLinesFor(ctx.app.db, user);
1125 const assigned = assignedLines(
1126 ctx.app.db,
1127 user,
1128 new Set(rows.flatMap((r) => r.items)),
1129 );
1130 const forge = forgeNeedsFor(ctx, user).map((d) => needLine(d));
10921131 return {
1093 rows: askLinesFor(ctx.app.db, user),
1094 forge: forgeNeedsFor(ctx, user).map((d) => needLine(d)),
1132 /** The one count: what the top bar and the home's sentence say. */
1133 count: rows.length + forge.length + assigned.length,
1134 rows,
1135 assigned,
1136 forge,
10951137 measure: { days: 7, ...askMeasure(ctx.app.db, user.id, since) },
10961138 };
10971139 }
src/web/studio/asks_page.ts +7 −13
@@ -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,17 +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 handover: "Handed over",
165 parked: "Parked",
166 declined: "Declined",
167 paused: "Paused",
168 };
169
170161 /**
171162 * An ask's actions: the one that decides, then the rest. A wide screen
172163 * lays them in a line; a phone puts the decider at the trailing edge, 44 px
@@ -201,7 +192,7 @@ function decisionCard(ctx: Ctx, d: Decision, picked: ReadonlySet<string>): Html
201192 head: html`${pick(d, picked)}
202193 <h2>${title}</h2>
203194 <span class="ask-meta muted small"
204 ><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
205196 >`,
206197 },
207198 );
@@ -367,7 +358,10 @@ export function needsYouSection(
367358 >
368359 <button type="submit" class="btn btn-sm btn-ghost">Listen again</button>
369360 </form>`;
370 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;
371365 if (count === 0 && top === undefined)
372366 return {
373367 body: html`<h2 id="asks-sentence" class="sr-only">${askSentence(0)}</h2>${silencedNote}`,
src/web/studio/waiting.ts added +103
@@ -0,0 +1,103 @@
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 handover: "a decision",
33 };
34
35 /** What work assigned to the viewer waits for. */
36 export const ASSIGNED_WAITING_FOR = "assigned to you";
37
38 /** A green pull that cannot merge waits for a fix, not a landing. */
39 export function waitingForAsk(
40 db: Database,
41 kind: DecisionKind,
42 pull: { id: string; headOid: string } | undefined,
43 ): string {
44 if (kind === "look" && pull !== undefined && conflictsOf(db, pull.id, pull.headOid) > 0)
45 return "conflicts with main";
46 return WAITING_FOR[kind];
47 }
48
49 /** What a piece of assigned work waits for: a pull that cannot merge says so. */
50 export function assignedWaitingFor(db: Database, issue: Issue): string {
51 if (issue.kind !== "pull") return ASSIGNED_WAITING_FOR;
52 const head = joinMany(db, [issue])[0]?.headOid ?? "";
53 return conflictsOf(db, issue.id, head) > 0 ? "conflicts with main" : ASSIGNED_WAITING_FOR;
54 }
55
56 export interface Assigned {
57 readonly issue: Issue;
58 readonly repo: Repo;
59 }
60
61 /**
62 * Open issues and pulls assigned to the viewer that they may see: `shown`,
63 * and the repositories they muted that hold some, `silenced` (said, never
64 * silent). Work that is already one of `taken` — an ask's item ids — is
65 * left out: a row is counted once.
66 */
67 export function assignedTo(
68 db: Database,
69 user: User,
70 taken: ReadonlySet<string> = new Set(),
71 ): { shown: Assigned[]; silenced: Map<string, Repo> } {
72 const shown: Assigned[] = [];
73 const silenced = new Map<string, Repo>();
74 const assigned = listAssignedTo(db, user.id, 20);
75 if (assigned.length === 0) return { shown, silenced };
76 const repos = getReposByIds(
77 db,
78 assigned.map((issue) => issue.repoId),
79 );
80 // `listAssignedTo` has no visibility filter of its own (an assignment can
81 // outlive the access that made it), so each repo needs a real `canRead`.
82 // `listReposVisibleTo` answers the common case with one query for the
83 // whole page; `canRead` only runs for the rare repo it did not reach.
84 const visible = new Set(
85 listReposVisibleTo(db, user, { limit: 200 }).map((repo) => repo.id),
86 );
87 const muted = mutedRepos(db, user.id);
88 // An ask item id is `<kind>:<issue id>`: whatever the kind, the work is held.
89 const held = new Set([...taken].map((id) => id.slice(id.indexOf(":") + 1)));
90 for (const issue of assigned) {
91 const repo = repos.get(issue.repoId);
92 if (!repo) continue;
93 if (!visible.has(repo.id) && !canRead(db, repo, user)) continue;
94 if (!mayView(db, repo, issue, user)) continue;
95 if (muted.has(repo.id)) {
96 silenced.set(repo.id, repo);
97 continue;
98 }
outdated

The hard-coded kind list leaves out declined and handover. An item that is assigned to you and carries one of those asks is counted twice. Match on the ask item ids and not on a list of kinds.

99 if (held.has(issue.id)) continue;
100 shown.push({ issue, repo });
101 }
102 return { shown, silenced };
103 }
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 }, url: new URL("http://localhost/") }) 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 +161
@@ -0,0 +1,161 @@
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 }, url: new URL("http://localhost/") }) 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");

This only asserts that the card is defined. Assert that the card does not contain the pull's title, which fails today because of the duplicate.

113 // The assigned card does not list it a second time.
114 const card = onYouCard(ctx(), alice);
115 expect(card === undefined ? "" : flat(card.text)).not.toContain(apples.title);
116 });
117
118 test("an ask row says what it waits for, in the data and on the page", () => {
119 const [row] = asksAnswer(ctx(), alice).rows;
120 expect(row!.waitingFor).toBe("ready to land");
121 expect(flat(needsYouSection(ctx(), alice).body.text)).toContain("ready to land");
122 });
123
124 test("every kind of ask has a label, and a review or a decision says so", () => {
125 const kinds = Object.keys(WAITING_FOR) as DecisionKind[];
126 expect(kinds.length).toBeGreaterThanOrEqual(6);
127 expect(waitingForAsk(app.db, "review", undefined)).toBe("your review");
128 for (const k of ["stopped", "parked", "declined", "paused"] as const)
129 expect(waitingForAsk(app.db, k, undefined)).toBe("a decision");
130 expect(waitingForAsk(app.db, "look", undefined)).toBe("ready to land");
131 });
132
133 test("a green pull that conflicts with main says so, as an ask label and as an assigned row", async () => {
134 const plums = await pullFor("plums", "README.md", "# plums\n");
135 setAssignee(app.db, plums.id, alice.id);
136 await commitToBranch(app, alice, repo, {
137 message: "main moves",
138 files: [{ path: "README.md", content: "# orchard, renamed\n" }],
139 });
140 await sweepStaleAsks(app);
141 expect(waitingForAsk(app.db, "look", plums)).toBe("conflicts with main");
142 expect(waitingForAsk(app.db, "look", apples)).toBe("ready to land");
143 const lines = assignedLines(app.db, alice, new Set());
144 expect(lines.find((l) => l.id === `assigned:${plums.id}`)!.waitingFor).toBe("conflicts with main");
145 const answer = asksAnswer(ctx(), alice);
146 expect(answer.assigned.map((l) => l.waitingFor)).toEqual(["conflicts with main"]);
147 expect(answer.count).toBe(answer.rows.length + 1);
148 expect(flat(onYouCard(ctx(), alice)!.text)).toContain("conflicts with main");
149 });
150
151 test("a muted repository leaves the count and is still said to be silenced", () => {
152 muteRepo(app.db, alice.id, repo.id);
153 expect(askLinesFor(app.db, alice)).toHaveLength(0);
154 expect(askCountFor(ctx(), alice)).toBe(0);
155 expect(asksAnswer(ctx(), alice).count).toBe(0);
156 const section = flat(needsYouSection(ctx(), alice).body.text);
157 expect(section).toContain("1 muted repository still asks");
158 expect(section).toContain("Listen again");
159 expect(flat(onYouCard(ctx(), alice)?.text ?? "")).toContain("muted");
160 });
161 });
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