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

On you and Needs you become one list on the home with one count in the top bar, the same rows /live/on-you and MCP count #1937

Parked opened this
Closed without merging

scout/forge:scout/1826-on-you-and-needs-you-become-one-list-on → main 2 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
12 files changed +299 −200
scripts/gate.ts +1
@@ -196,6 +196,7 @@ export const GATE: readonly string[] = [
196196 "test/review-wait.test.ts",
197197 "test/asks-bulk.test.ts",
198198 "test/asks-waiting-for.test.ts",
199 "test/asks-one-list.test.ts",
199200 "test/hand-decider.test.ts",
200201 "test/decisions-by-doors.test.ts",
201202 "test/standing-rule.test.ts",
src/core/waiting_for.ts +1 −1
@@ -18,7 +18,7 @@ export interface WaitingFor {
1818
1919 export interface WaitFacts {
2020 /** The ask's kind (`DecisionKind`). */
21 readonly kind: "stopped" | "look" | "review" | "paused" | "parked" | "declined" | "handover";
21 readonly kind: "stopped" | "look" | "review" | "paused" | "parked" | "declined" | "handover" | "assigned";
2222 /** Files stopping the pull from merging, as the last sweep found it. */
2323 readonly conflicts: number;
2424 /** Whether the pull or issue the ask is about is assigned to the viewer. */
src/feed/feed.ts +11 −2
@@ -33,7 +33,13 @@ export function parseCursor(
3333 export function readFeed(
3434 db: Database,
3535 viewer: User,
36 options: { limit?: number; cursor?: { score: number; id: string }; now?: number } = {},
36 options: {
37 limit?: number;
38 cursor?: { score: number; id: string };
39 now?: number;
40 /** The home pins asks above the feed: they must not fill its page. */
41 withoutAsks?: boolean;
42 } = {},
3743 ): { items: FeedItem[]; next_cursor: string | null } {
3844 const now = options.now ?? Date.now();
3945 const limit = Math.min(options.limit ?? FEED_LIMIT_DEFAULT, FEED_LIMIT_MAX);
@@ -59,7 +65,10 @@ export function readFeed(
5965 c.kind === "choose" ||
6066 !muted.has(c.repoId)),
6167 );
62 let ranked = rank(candidates, affinityFor(db, viewer, now), now);
68 let ranked = rank(
69 options.withoutAsks === true ? candidates.filter((c) => c.kind !== "ask") : candidates, affinityFor(db, viewer, now),
70 now,
71 );
6372 const cursor = options.cursor;
6473 if (cursor) {
6574 const at = ranked.findIndex((i) => i.id === cursor.id);
src/web/pages/site.ts +2 −120
@@ -9,32 +9,21 @@
99 */
1010
1111 import { limitValue } from "../../settings/limits.ts";
12 import { mayView } from "../../core/sealed.ts";
1312 import { signOutHere } from "../../actions/signins.ts";
1413 import { clientAddress } from "../../http/peer.ts";
1514 import { verifyEmail } from "../../actions/verify.ts";
1615 import { STRANGER_MAX } from "../../http/limits.ts";
1716 import { createRepo } from "../../actions/repos.ts";
1817 import { HUMAN_CHECK_MESSAGE, signUp } from "../../actions/users.ts";
19 import { listAssignedTo, type Issue } from "../../core/issues.ts";
20 import { joinMany } from "../../core/pulls.ts";
21 import { conflictsOf } from "../../crew/stale_asks.ts";
2218 import { accessAllows, listOrgsForUser, orgAccess } from "../../core/orgs.ts";
2319 import { listPins } from "../../core/pins.ts";
24 import {
25 canRead,
26 getReposByIds,
27 listReposVisibleTo,
28 type Repo,
29 } from "../../core/repos.ts";
20 import { getReposByIds } from "../../core/repos.ts";
3021 import { createSession } from "../../core/sessions.ts";
3122 import { hasAnyUser, verifyPassword, type User } from "../../core/users.ts";
3223 import { isThemeName } from "../../design/themes.ts";
3324 import { cookieValue, crossOrigin, type Ctx } from "../../http/context.ts";
3425 import { studioDoor, studioHome } from "../studio/home.ts";
35 import { homeTop, onYouBulk } from "../studio/asks_page.ts";
36 import { latestUndoable } from "../../actions/asks_bulk.ts";
37 import { mutedRepos } from "../../core/interactions.ts";
26 import { homeTop } from "../studio/asks_page.ts";
3827 import { edgeLoginUrl } from "../../http/edge.ts";
3928 import { sshCommand } from "../../ssh/command.ts";
4029 import { hostOf, pageHead, signInFirst } from "../chrome.ts";
@@ -52,7 +41,6 @@ import {
5241 listCard,
5342 row,
5443 selectField,
55 time,
5644 } from "../ui.ts";
5745 import { existsSync } from "node:fs";
5846 import { join } from "node:path";
@@ -176,112 +164,6 @@ export function downloadsCard(ctx: Ctx, user: User): Html {
176164 );
177165 }
178166
179 const threadPath = (repo: Repo, issue: Issue): string =>
180 `/${repo.ownerName}/${repo.name}/${issue.kind === "pull" ? "pulls" : "issues"}/${issue.number}`;
181
182 /** Open issues and pulls assigned to the viewer, anywhere they can see. */
183 export function onYouCard(ctx: Ctx, user: User): Html | undefined {
184 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 }
216 // Two or more can be given one move: a box each, and one form for the set.
217 const bulk = shown.length >= 2;
218 const heads = new Map(
219 joinMany(
220 db,
221 shown.map((s) => s.issue).filter((i) => i.kind === "pull"),
222 ).map((p) => [p.id, p.headOid]),
223 );
224 const rows = shown.map(({ issue, repo }) => {
225 // A pull the last sweep found unable to merge is never shown as ready.
226 const conflicts = conflictsOf(db, issue.id, heads.get(issue.id) ?? "");
227 return row({
228 ...(bulk ? {} : { href: threadPath(repo, issue), nav: true as const }),
229 state: "open",
230 lead: bulk
231 ? html`<input
232 type="checkbox"
233 class="ask-pick"
234 name="item"
235 value="issue:${issue.id}"
236 form="onyou-bulk"
237 data-repo="${repo.id}"
238 data-kind="${issue.kind}"
239 aria-label="Select ${issue.title}"
240 />`
241 : icon(issue.kind === "pull" ? "pull" : "issue"),
242 title: bulk
243 ? html`<a href="${threadPath(repo, issue)}">${issue.title}</a>`
244 : issue.title,
245 titleAttr: issue.title,
246 meta: html`${repo.ownerName}/${repo.name} #${issue.number} · updated
247 ${time(issue.updatedAt)}${conflicts > 0
248 ? html` · <span class="conflicts">Conflicts in ${conflicts}
249 ${conflicts === 1 ? "file" : "files"}</span>`
250 : null}`,
251 });
252 });
253 if (rows.length === 0 && silenced.size === 0) return undefined;
254 const last = latestUndoable(ctx.app, user);
255 const byKind = [...new Set(shown.map((s) => s.issue.kind))].map((k) => ({
256 id: k,
257 label: k === "pull" ? "Pulls" : "Issues",
258 }));
259 const byRepo = [...new Map(shown.map((s) => [s.repo.id, s.repo])).values()].map(
260 (r) => ({ id: r.id, label: `${r.ownerName}/${r.name}` }),
261 );
262 return listCard(rows, {
263 head: html`${icon("user")}
264 <h2>On you</h2>`,
265 ...(bulk || last !== undefined || silenced.size > 0
266 ? {
267 foot: onYouBulk(
268 byKind,
269 byRepo,
270 last === undefined
271 ? undefined
272 : {
273 id: last.id,
274 verb: last.verb,
275 done: last.rows.filter((r) => r.outcome === "ok").length,
276 },
277 bulk,
278 [...silenced.values()].map((r) => ({ id: r.id, label: `${r.ownerName}/${r.name}` })),
279 ),
280 }
281 : {}),
282 });
283 }
284
285167 export function orgsCard(ctx: Ctx, user: User): Html {
286168 const orgs = listOrgsForUser(ctx.app.db, user.id);
287169 // A new one is the "+" menu's; with none, there is nothing to show.
src/web/studio/asks.ts +70 −4
@@ -27,6 +27,7 @@ import {
2727 listOpenPullsVisibleTo,
2828 type Issue,
2929 } from "../../core/issues.ts";
30 import { mayView } from "../../core/sealed.ts";
3031 import { looksForApps } from "../../core/looks.ts";
3132 import { closesFromBody, getPull, joinMany, type Pull } from "../../core/pulls.ts";
3233 import {
@@ -102,7 +103,7 @@ export function writableAppsOf(ctx: Ctx, user: User | undefined) {
102103 );
103104 }
104105
105 export type DecisionKind = "stopped" | "look" | "review" | "paused" | "parked" | "declined" | "handover";
106 export type DecisionKind = "stopped" | "look" | "review" | "paused" | "parked" | "declined" | "handover" | "assigned";
106107
107108 /** Dollars as a person reads them: cents when small, whole when not. */
108109 const dollars = (n: number): string => (n < 10 ? n.toFixed(2) : n.toFixed(0));
@@ -170,6 +171,11 @@ export const ASK_WORDS: Readonly<Record<DecisionKind, AskWords>> = {
170171 options: ["Answer the planner"],
171172 ifNothing: "the planner plans nothing more for this app",
172173 },
174 assigned: {
175 decision: "This is assigned to you: act on it?",
176 options: ["Open it"],
177 ifNothing: "it stays assigned to you",
178 },
173179 paused: {
174180 decision: "Raise today's ceiling?",
175181 options: ["Raise it in settings"],
@@ -197,6 +203,7 @@ export const KIND_TIER: Readonly<Record<DecisionKind, Consequence>> = {
197203 handover: { score: 55, why: "three reviews without an approval: handed to a person" },
198204 parked: { score: 40, why: "parked by the crew" },
199205 look: { score: 30, why: "green, waiting" },
206 assigned: { score: 20, why: "assigned to you" },
200207 };
201208
202209 /** When a person last spoke on a conversation, or its start. */
@@ -430,6 +437,36 @@ function askCandidatesFor(
430437 who: "the planner",
431438 decline: { runId: d.runId, words: d.words },
432439 });
440 // Open work assigned to the viewer that no ask above already covers: a
441 // pull that is an ask and assigned to them is one row, the ask's.
442 const taken = new Set(out.flatMap((a) => [a.pull?.id, a.issue?.id].filter((i) => i !== undefined)));
443 const visible = new Map(allRepos.map((r) => [r.id, r]));
444 const mine = listAssignedTo(db, user.id, 50).filter((i) => !taken.has(i.id));
445 const elsewhere = getReposByIds(
446 db,
447 [...new Set(mine.map((i) => i.repoId))].filter((id) => !visible.has(id)),
448 );
449 // An assignment can outlive the access that made it: each repo needs a real read.
450 const readable = (repo: Repo | undefined): repo is Repo =>
451 repo !== undefined && (visible.has(repo.id) || canRead(db, repo, user));
452 const joinedMine = new Map(
453 joinMany(db, mine.filter((i) => i.kind === "pull")).map((p) => [p.id, p]),
454 );
455 for (const issue of mine) {
456 const repo = visible.get(issue.repoId) ?? elsewhere.get(issue.repoId);
457 if (!readable(repo) || !mayView(db, repo, issue, user)) continue;
458 const pull = joinedMine.get(issue.id);
459 if (issue.kind === "pull" && pull === undefined) continue;
460 out.push({
461 kind: "assigned",
462 id: `assigned:${issue.id}`,
463 since: issue.updatedAt,
464 repo,
465 ...(pull === undefined ? { issue } : { pull }),
466 who: issue.authorName,
467 authorIsAgent: issue.authorIsAgent,
468 });
469 }
433470 return out;
434471 }
435472
@@ -507,8 +544,9 @@ function consequencesOf(
507544 }
508545
509546 /** The row an ask collapses into: one kind in one repository. */
510 const groupId = (a: { kind: DecisionKind; repo: Repo }): string =>
511 `${a.kind}:${a.repo.id}`;
547 const groupId = (a: { kind: DecisionKind; repo: Repo; id: string }): string =>
548 // Work assigned to you is each its own row: they share no decision.
549 a.kind === "assigned" ? a.id : `${a.kind}:${a.repo.id}`;
512550
513551 /**
514552 * The asks the viewer has not set aside: a muted repository's asks are all
@@ -671,6 +709,10 @@ export function endOf(
671709 if (pull !== undefined && pull.state !== "open") return "acted";
672710 return getHold(db, what)?.heldBy === viewerId ? "acted" : "expired";
673711 }
712 if (kind === "assigned") {
713 const issue = getIssueById(db, what);
714 return issue !== undefined && issue.state !== "open" ? "acted" : "expired";
715 }
674716 if (kind === "parked") {
675717 const issue = getIssueById(db, what);
676718 if (issue === undefined) return "expired";
@@ -738,6 +780,8 @@ export function recordAskLedger(db: Database, now = new Date()): void {
738780 /** One ask in a line, without its repository's name (the row adds that). */
739781 function lineOf(c: AskCandidate): string {
740782 if (c.kind === "paused") return "is paused at its ceiling";
783 if (c.kind === "assigned")
784 return `"${c.pull?.title ?? c.issue?.title ?? ""}" is assigned to you`;
741785 if (c.kind === "parked")
742786 return `the crew parked #${c.issue!.number} after three failed runs`;
743787 if (c.kind === "declined")
@@ -771,6 +815,7 @@ export const ROW_PLURAL: Readonly<Record<DecisionKind, (n: number) => string>> =
771815 handover: (n) => `${n} changes had three reviews asking for changes and wait for you`,
772816 declined: (n) => `the planner declined ${n} times and waits for you`,
773817 paused: (n) => `${n} pauses at the ceiling`,
818 assigned: (n) => `${n} things assigned to you`,
774819 };
775820
776821 /** Every kind has its own: a row never says "green changes" of something that is not one. */
@@ -828,7 +873,7 @@ export function askLinesFor(
828873 const line = `${row.repo.name}${only.kind === "paused" ? " " : ": "}${lineOf(only)}`;
829874 if (only.kind === "paused")
830875 return { ...about, line, link: `${base}/settings/autonomy` };
831 if (only.kind === "parked" || only.kind === "declined")
876 if (only.pull === undefined && only.issue !== undefined)
832877 return {
833878 ...about,
834879 line,
@@ -880,6 +925,18 @@ export function decisionsFor(
880925 );
881926 };
882927 const worded = (c: Scored): Omit<Decision, "consequence" | "waiting"> => {
928 if (c.kind === "assigned") {
929 const thing = c.pull ?? c.issue!;
930 return {
931 kind: "assigned",
932 id: `assigned:${thing.id}`,
933 repo: c.repo,
934 ...(c.pull === undefined ? { issue: c.issue } : { pull: c.pull }),
935 who: c.who,
936 says: `"${thing.title}" is assigned to you.`,
937 short: `assigned to you · updated ${thing.updatedAt.slice(0, 10)}`,
938 };
939 }
883940 if (c.kind === "parked" && c.issue)
884941 return {
885942 kind: "parked",
@@ -1046,6 +1103,15 @@ export function decisionButtons(ctx: Ctx, d: Decision): { primary: Html; others:
10461103 }),
10471104 ],
10481105 };
1106 if (d.kind === "assigned" && (d.pull ?? d.issue))
1107 return {
1108 primary: btn("Open", {
1109 href: pull ? changeHref(base, pull.number) : `${base}/issues/${d.issue!.number}`,
1110 size: "sm",
1111 variant: "primary",
1112 }),
1113 others: [],
1114 };
10491115 if (d.kind === "declined" && d.issue)
10501116 return {
10511117 primary: btn("Answer", {
src/web/studio/asks_page.ts +17 −46
@@ -11,6 +11,7 @@ import type { WaitingFor } from "../../core/waiting_for.ts";
1111 import {
1212 applyAsksBulk,
1313 BULK_MAX,
14 latestUndoable,
1415 ownAsksOperation,
1516 undoAsksBulk,
1617 previewAsksBulk,
@@ -60,10 +61,11 @@ const ASK_KIND_WORDS: Readonly<Record<string, string>> = {
6061 review: "Reviews",
6162 stopped: "Stopped",
6263 parked: "Parked",
64 assigned: "Assigned",
6365 };
6466
6567 /** The kinds a bulk action takes: a ceiling and a planner's decline are decided where they live. */
66 const BULK_KINDS: ReadonlySet<Decision["kind"]> = new Set(["look", "review", "stopped", "handover", "parked"]);
68 const BULK_KINDS: ReadonlySet<Decision["kind"]> = new Set(["look", "review", "stopped", "handover", "parked", "assigned"]);
6769
6870 /** A row's box for the bulk form, which sits apart (`form="asks-bulk"`): forms do not nest. */
6971 const pick = (d: Decision, picked: ReadonlySet<string>): Html | null =>
@@ -166,6 +168,7 @@ const KIND_LABEL: Readonly<Record<Decision["kind"], string>> = {
166168 parked: "Parked",
167169 declined: "Declined",
168170 paused: "Paused",
171 assigned: "Assigned",
169172 };
170173
171174 /**
@@ -374,10 +377,19 @@ export function needsYouSection(
374377 >
375378 <button type="submit" class="btn btn-sm btn-ghost">Listen again</button>
376379 </form>`;
380 const last = latestUndoable(ctx.app, user);
381 const undo =
382 last === undefined
383 ? null
384 : html`<form class="bar" method="post" action="/asks/bulk/${last.id}/undo" role="status">
385 <span class="small">${VERB_WORDS[last.verb] ?? last.verb}: ${last.rows.filter((r) => r.outcome === "ok").length} done</span>
386 ${btn("Undo", { size: "sm" })}
387 <span class="muted small">kept for a day</span>
388 </form>`;
377389 const count = rows.length + needs.length;
378390 if (count === 0 && top === undefined)
379391 return {
380 body: html`<h2 id="asks-sentence" class="sr-only">${askSentence(0)}</h2>${silencedNote}`,
392 body: html`<h2 id="asks-sentence" class="sr-only">${askSentence(0)}</h2>${silencedNote}${undo}`,
381393 scriptJs: "",
382394 };
383395 // The forge's own health first, then the few asks that matter most;
@@ -428,6 +440,7 @@ export function needsYouSection(
428440 ${reasonInput(top?.reason)} ${btn("Preview", { size: "sm" })}
429441 <span class="muted small">on the selected asks</span>
430442 </form>`}
443 ${silencedNote} ${undo}
431444 ${decisions.map((d) => decisionForm(d, ctx.url.pathname))}
432445 </section>`;
433446 return { body, scriptJs: SELECT_JS };
@@ -452,11 +465,8 @@ const VERB_WORDS: Readonly<Record<string, string>> = {
452465 replan: "Hand back to the planner",
453466 };
454467
455 /** What the asks below can be given in one move; mute is the On you card's. */
456 const ASK_VERBS = ["decline", "ship", "close", "replan"] as const;
457
458 /** What the On you card's set can be given. */
459 const CARD_VERBS = ["close", "mute", "ship"] as const;
468 /** What the asks below can be given in one move. */
469 const ASK_VERBS = ["decline", "ship", "close", "replan", "mute"] as const;
460470
461471 /** One reason, written on each pull or issue closed. */
462472 const reasonInput = (value = ""): Html =>
@@ -495,45 +505,6 @@ export function pickControls(
495505 </span>`;
496506 }
497507
498 /**
499 * The On you card's one form: a verb for the set, one reason, one request.
500 * `receipt` is the day's undo link for the last set acted on.
501 */
502 export function onYouBulk(
503 kinds: readonly { id: string; label: string }[],
504 repos: readonly { id: string; label: string }[],
505 receipt: { id: string; verb: string; done: number } | undefined,
506 withForm = true,
507 muted: readonly { id: string; label: string }[] = [],
508 ): Html {
509 return html`${muted.length === 0
510 ? null
511 : html`<form class="bar" method="post" action="/asks/listen">
512 ${muted.map((r) => html`<input type="hidden" name="repo" value="${r.id}" />`)}
513 <span class="muted small" title="${muted.map((r) => r.label).join(", ")}"
514 >${muted.length} ${muted.length === 1 ? "repository" : "repositories"} muted</span
515 >
516 <button type="submit" class="btn btn-sm btn-ghost">Listen again</button>
517 </form>`}
518 ${receipt === undefined
519 ? null
520 : html`<form class="bar" method="post" action="/asks/bulk/${receipt.id}/undo" role="status">
521 <span class="small">${VERB_WORDS[receipt.verb] ?? receipt.verb}: ${receipt.done} done</span>
522 ${btn("Undo", { size: "sm" })}
523 <span class="muted small">kept for a day</span>
524 </form>`}
525 ${withForm
526 ? html`<form id="onyou-bulk" method="post" action="/asks/bulk" class="bar" data-bulk>
527 <input type="hidden" name="apply" value="1" />
528 ${pickControls("onyou-bulk", kinds, repos)}
529 <select name="action" class="input" aria-label="What to do with the selected">
530 ${CARD_VERBS.map((v) => html`<option value="${v}">${VERB_WORDS[v]}</option>`)}
531 </select>
532 ${reasonInput()} ${btn("Do it", { size: "sm" })}
533 </form>`
534 : null}`;
535 }
536
537508 const shown = (v: FleetValue): string =>
538509 v === null ? "nobody" : Array.isArray(v) ? v.join(", ") : String(v);
539510
src/web/studio/feed.ts +1 −3
@@ -204,9 +204,7 @@ export function feedNote(): Html {
204204 export function feedRegion(user: User, ctx: Ctx): Html {
205205 // What needs you is pinned above the timeline (`needsYouSection`), so an
206206 // ask is never a second time a post below it; the feed API keeps them.
207 const items = readFeed(ctx.app.db, user, { limit: FEED_FIRST_PAGE }).items.filter(
208 (item) => item.kind !== "ask",
209 );
207 const items = readFeed(ctx.app.db, user, { limit: FEED_FIRST_PAGE, withoutAsks: true }).items;
210208 const thoughts = recentThoughts(ctx.app.db, user.id, THOUGHTS_SHOWN, new Date(Date.now() - THOUGHT_AGE_MS).toISOString());
211209 const placed = placementsOf(ctx.app.db, thoughts.map((t) => t.id));
212210 // Who each poster is, asked once for the page (`core/marks.ts`).
src/web/studio/home.ts +8 −5
@@ -40,7 +40,6 @@ import {
4040 } from "../ui.ts";
4141 import {
4242 downloadsCard,
43 onYouCard,
4443 orgsCard,
4544 terminalCard,
4645 } from "../pages/site.ts";
@@ -125,14 +124,19 @@ const appsRegion = (ctx: Ctx, user: User): Html =>
125124 ${yourApps(ctx, user)}
126125 </div>`;
127126
128 const onYouRegion = (ctx: Ctx, user: User, note?: string): Html =>
127 const onYouRegion = (
128 ctx: Ctx,
129 user: User,
130 note?: string,
131 section: Html = needsYouSection(ctx, user).body,
132 ): Html =>
129133 html`<div
130134 id="live-on-you"
131135 data-live="${ON_YOU_LIVE}"
132136 data-live-src="/live/on-you"
133137 >
134138 ${note === undefined ? null : html`<p class="small" role="status">${note}</p>`}
135 ${onYouCard(ctx, user) ?? null}
139 ${section}
136140 </div>`;
137141
138142 // GET /live/apps — your apps alone, for the region that shows them.
@@ -191,7 +195,7 @@ export async function studioHome(
191195 ${homeTabs("feed")}
192196 <div class="dash">
193197 <div class="dash-main stack">
194 ${needsYou.body} ${composer(ctx, user)}
198 ${onYouRegion(ctx, user, undefined, needsYou.body)} ${composer(ctx, user)}
195199 <div class="bar feed-head">
196200 <span class="spacer"></span>
197201 <a class="small muted" href="/asked">What you asked for</a>
@@ -207,7 +211,6 @@ export async function studioHome(
207211 user.isAdmin || appRepos.length > 0 ? crewKeyNote(ctx) : null
208212 }
209213 ${appsRegion(ctx, user)}
210 ${onYouRegion(ctx, user)}
211214 ${terminalCard(ctx)} ${downloadsCard(ctx, user)}
212215 ${orgsCard(ctx, user)}
213216 </aside>
test/asks-bulk.test.ts +13 −10
@@ -21,7 +21,7 @@ import { getAgentByName, setCrewRole } from "../src/core/agents.ts";
2121 import { getIssueById, listComments, type Issue } from "../src/core/issues.ts";
2222 import { assignIssue } from "../src/actions/issues.ts";
2323 import { mutedRepos, recordInteraction, removeMutes } from "../src/core/interactions.ts";
24 import { onYouCard } from "../src/web/pages/site.ts";
24 import { needsYouSection } from "../src/web/studio/asks_page.ts";
2525 import { getPull, type Pull } from "../src/core/pulls.ts";
2626 import type { Repo } from "../src/core/repos.ts";
2727 import { claimRun, createRun, finishRun } from "../src/core/runs.ts";
@@ -634,12 +634,14 @@ describe("acting on many asks at once", () => {
634634 const issue = getIssueById(app.db, pull.id)!;
635635 expect(assignIssue(app, alice, open, issue, alice).ok).toBe(true);
636636 }
637 const ctx = (user: User) => ({ app, auth: { user } }) as never;
638 const card = (user: User) => onYouCard(ctx(user), user)?.text ?? "";
637 const ctx = (user: User) => ({ app, auth: { user }, url: new URL("http://x/") }) as never;
638 const card = (user: User) => needsYouSection(ctx(user), user).body.text;
639639 expect(card(alice)).toContain("On you one");
640 // The card offers the set: a box each, the kinds, one form.
641 expect(card(alice)).toContain('form="onyou-bulk"');
642 expect(card(alice)).toContain('value="issue:' + a.id + '"');
640 // The list offers the set: a box each, the kinds, one form.
641 expect(card(alice)).toContain('form="asks-bulk"');
642 // A green pull assigned to alice is an ask: one row, under the ask's id.
643 expect(card(alice)).toContain('value="look:' + a.id + '"');
644 expect(card(alice)).not.toContain('value="assigned:' + a.id + '"');
643645 expect(card(alice)).toContain("data-pick");
644646 const done = await api(aliceRw, "/api/v1/asks/bulk", {
645647 action: "mute",
@@ -713,8 +715,9 @@ describe("acting on many asks at once", () => {
713715 const b = await greenPull(open, "Muted two");
714716 for (const pull of [a, b])
715717 expect(assignIssue(app, alice, open, getIssueById(app.db, pull.id)!, alice).ok).toBe(true);
716 const card = () => onYouCard({ app, auth: { user: alice } } as never, alice)?.text ?? "";
717 expect(card()).not.toContain("muted");
718 const card = () =>
719 needsYouSection({ app, auth: { user: alice }, url: new URL("http://x/") } as never, alice).body.text;
720 expect(card()).not.toContain("muted repositor");
718721 const done = await api(aliceRw, "/api/v1/asks/bulk", {
719722 action: "mute",
720723 items: [`issue:${a.id}`, `issue:${b.id}`],
@@ -722,7 +725,7 @@ describe("acting on many asks at once", () => {
722725 });
723726 expect(done.status).toBe(201);
724727 // Past the day's undo, the card still says it, and offers the way back.
725 expect(card()).toContain("1 repository muted");
728 expect(card()).toContain("1 muted repository still asks");
726729 expect(card()).toContain('action="/asks/listen"');
727730 const headers = { cookie: `${aliceCookie}; forge_mode=studio`, origin: servers.url };
728731 const res = await fetch(`${servers.url}/asks/listen`, {
@@ -734,7 +737,7 @@ describe("acting on many asks at once", () => {
734737 expect(res.status).toBe(303);
735738 expect(mutedRepos(app.db, alice.id).has(open.id)).toBe(false);
736739 expect(card()).toContain("Muted one");
737 expect(card()).not.toContain("repository muted");
740 expect(card()).not.toContain("muted repository still asks");
738741 });
739742 test("on the card, a refusal answers 422 with its message, and a partial set says what was not done", async () => {
740743 const a = await greenPull(open, "Refuse one");
test/asks-expiry.test.ts +4 −2
@@ -247,15 +247,17 @@ describe("asks that expire, hold and collapse", () => {
247247 ),
248248 ).toBe(false);
249249 expect(JSON.stringify(asksAnswer({ app, auth: { user: aliceUser } } as never, aliceUser))).not.toContain("is green");
250 // Assigned to alice, the home's On you says it conflicts, never ready.
250 // Assigned to alice, the home's one list says it conflicts, never ready.
251251 setAssignee(app.db, plums.id, aliceUser.id);
252252 const home = await get("/");
253 expect(home).toContain("Conflicts in 1 file");
253 expect(home).toContain("conflicts with main");
254 expect(askLinesFor(app.db, aliceUser).map((l) => l.waitingFor.word)).toEqual(["conflicts with main"]);
254255 // Its own page still says why it cannot ship.
255256 const change = await get(
256257 `/${repo.ownerName}/${repo.name}/pulls/${plums.number}`,
257258 );
258259 expect(change).toContain("README.md");
260 setAssignee(app.db, plums.id, null);
259261 });
260262 test("a row dismissed while a pull conflicted asks again when it merges again, with no new check", async () => {
261263 await tick();
test/asks-one-list.test.ts added +163
@@ -0,0 +1,163 @@
1 /**
2 * What is assigned to you and what asks you are one list (#1826): one row
3 * source, so the home, the count and the MCP's `asks` count the same rows,
4 * and a pull that is both is one 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 { openIssue } from "../src/actions/issues.ts";
13 import { openPull } from "../src/actions/pulls.ts";
14 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
15 import { recordInteraction, removeMutes } from "../src/core/interactions.ts";
16 import { setAssignee } from "../src/core/issues.ts";
17 import type { Repo } from "../src/core/repos.ts";
18 import { claimRun, createRun, finishRun } from "../src/core/runs.ts";
19 import { createToken } from "../src/core/tokens.ts";
20 import { createUser, type User } from "../src/core/users.ts";
21 import { serve, type Servers } from "../src/http/server.ts";
22 import { askCountFor, askLinesFor } from "../src/web/studio/asks.ts";
23 import { quietLogs } from "./helpers/globals.ts";
24
25 quietLogs();
26
27 describe("one list", () => {
28 let dataDir = "";
29 let app: App;
30 let servers: Servers;
31 let alice: User;
32 let repo: Repo;
33 let cookie = "";
34 let token = "";
35
36 beforeAll(async () => {
37 dataDir = await mkdtemp(join(tmpdir(), "forge-asks-one-list-"));
38 app = createApp({ dataDir, port: 0 });
39 servers = await serve(app);
40 const made = await createUser(app.db, {
41 trusted: true,
42 username: "alice",
43 email: "[email protected]",
44 password: "a-long-one-list-passphrase",
45 adminIfFirst: true,
46 });
47 if (!made.ok) throw new Error(made.error);
48 alice = made.value;
49 const res = await fetch(`${servers.url}/signin`, {
50 method: "POST",
51 body: new URLSearchParams({ username: "alice", password: "a-long-one-list-passphrase" }),
52 redirect: "manual",
53 });
54 cookie = `${(res.headers.get("set-cookie") ?? "").split(";")[0]!}; forge_mode=studio`;
55 token = createToken(app.db, alice.id, "ro", "ro").token;
56 const made2 = await createRepo(app, alice, { name: "one", visibility: "public" });
57 if (!made2.ok) throw new Error(String(made2.error));
58 repo = made2.value;
59 await commitToBranch(app, alice, repo, {
60 message: "seed",
61 files: [{ path: "README.md", content: "# one\n" }],
62 });
63 }, 30_000);
64
65 afterAll(async () => {
66 await servers.stop();
67 await rm(dataDir, { recursive: true, force: true });
68 });
69
70 /** The three doors' counts of the same rows. */
71 const counts = async () => {
72 const mcp = await fetch(`${servers.url}/mcp`, {
73 method: "POST",
74 headers: {
75 authorization: `Bearer ${token}`,
76 "content-type": "application/json",
77 accept: "application/json, text/event-stream",
78 },
79 body: JSON.stringify({
80 jsonrpc: "2.0",
81 id: 1,
82 method: "tools/call",
83 params: { name: "asks", arguments: {} },
84 }),
85 });
86 const body = JSON.parse(await mcp.text().then((t) => t.slice(t.indexOf("{")))) as {
87 result: { content: { text: string }[] };
88 };
89 const answer = JSON.parse(body.result.content[0]!.text) as { rows: unknown[]; forge: unknown[] };
90 const home = await (await fetch(`${servers.url}/live/on-you`, { headers: { cookie } })).text();
91 const said = /(\d+) things? needs? you/.exec(home);
92 return {
93 header: askCountFor({ app, auth: { user: alice } } as never, alice),
94 mcp: answer.rows.length + answer.forge.length,
95 home: said === null ? 0 : Number(said[1]),
96 html: home,
97 };
98 };
99
100 test("an issue assigned to you is a row that says so, and every door counts it", async () => {
101 const made = openIssue(app, alice, repo, { title: "Sweep <the> path", body: "" });
102 if (!made.ok) throw new Error(String(made.error));
103 const before = await counts();
104 setAssignee(app.db, made.value.id, alice.id);
105 const after = await counts();
106 expect(after.header).toBe(before.header + 1);
107 expect(after.mcp).toBe(after.header);
108 expect(after.home).toBe(after.header);
109 expect(after.html).toContain('data-waiting="assigned to you"');
110 expect(after.html).toContain("Sweep &lt;the&gt; path");
111 const row = askLinesFor(app.db, alice).find((l) => l.id === `assigned:${made.value.id}`);
112 expect(row?.waitingFor).toEqual({ word: "assigned to you", on: "you" });
113 // Mute silences it for this person; listening again brings it back.
114 recordInteraction(app.db, {
115 viewerId: alice.id,
116 itemId: `repo:${repo.id}`,
117 kind: "muted",
118 repoId: repo.id,
119 actorId: null,
120 });
121 expect(askLinesFor(app.db, alice).some((l) => l.id === `assigned:${made.value.id}`)).toBe(false);
122 expect((await counts()).header).toBe(before.header);
123 removeMutes(app.db, alice.id, [`repo:${repo.id}`]);
124 expect((await counts()).header).toBe(after.header);
125 setAssignee(app.db, made.value.id, null);
126 });
127
128 test("a green pull that is an ask and assigned to you counts once", async () => {
129 await commitToBranch(app, alice, repo, {
130 branch: "feat",
131 base: "main",
132 message: "Feature",
133 files: [{ path: "F.md", content: "f\n" }],
134 });
135 const pull = await openPull(app, alice, repo, {
136 title: "Feature",
137 body: "",
138 baseBranch: "main",
139 headBranch: "feat",
140 });
141 if (!pull.ok) throw new Error(String(pull.error));
142 const run = createRun(app.db, {
143 repoId: repo.id,
144 kind: "check",
145 issueId: pull.value.id,
146 env: `pull-${pull.value.number}`,
147 commitOid: pull.value.headOid,
148 reason: "pull",
149 });
150 claimRun(app.db, run.id);
151 finishRun(app.db, run.id, { state: "ok", summary: "green" });
152 const unassigned = await counts();
153 setAssignee(app.db, pull.value.id, alice.id);
154 const assigned = await counts();
155 expect(assigned.header).toBe(unassigned.header);
156 expect(assigned.mcp).toBe(assigned.header);
157 expect(assigned.home).toBe(assigned.header);
158 const ids = askLinesFor(app.db, alice).flatMap((l) => l.items);
159 expect(ids.filter((i) => i.endsWith(pull.value.id))).toEqual([`look:${pull.value.id}`]);
160 expect(assigned.html).toContain('data-waiting="ready to land"');
161 expect(assigned.html).not.toContain('data-waiting="assigned to you"');
162 });
163 });
test/home-feed.test.ts +8 −7
@@ -362,7 +362,7 @@ describe("home is the feed", () => {
362362 expect(second.items.map((i: any) => i.id)).toEqual(whole.slice(2, 4));
363363 });
364364
365 test("On you can be cleared in one move: a box each, select all, by kind and by repository, one form", async () => {
365 test("The one list can be cleared in one move: a box each, select all, by kind and by repository, one form", async () => {
366366 const one = openIssue(app, alice, garden, { title: "Sweep the path" });
367367 const two = openIssue(app, alice, vault, { title: "Oil the hinges" });
368368 if (!one.ok || !two.ok) throw new Error("issues");
@@ -370,14 +370,15 @@ 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");
374 expect(card).toContain(`value="issue:${one.value.id}"`);
375 expect(card).toContain(`value="issue:${two.value.id}"`);
376 expect((card.match(/form="onyou-bulk"/g) ?? []).length).toBeGreaterThanOrEqual(2);
373 expect(card).toContain("things need you");
374 expect(card).toContain("assigned to you");
375 expect(card).toContain(`value="assigned:${one.value.id}"`);
376 expect(card).toContain(`value="assigned:${two.value.id}"`);
377 expect((card.match(/form="asks-bulk"/g) ?? []).length).toBeGreaterThanOrEqual(2);
377378 expect(card).toContain('data-pick="all"');
378379 expect(card).toContain("data-pick-repo");
379380 expect(card).toContain('<option value="' + garden.id + '">alice/garden</option>');
380 expect(card).toContain('id="onyou-bulk"');
381 expect(card).toContain('id="asks-bulk"');
381382 expect(card).toContain('action="/asks/bulk"');
382383 expect(card).toContain('name="reason"');
383384 expect(card).toContain(">Mute repository<");
@@ -386,6 +387,6 @@ describe("home is the feed", () => {
386387 expect(text).toContain("data-pick");
387388 // Alone, a single row stays a plain link.
388389 const bobCard = await (await get("/", bobCookie)).text();
389 expect(bobCard).not.toContain('id="onyou-bulk"');
390 expect(bobCard).not.toContain('id="asks-bulk"');
390391 });
391392 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs