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

Milestones at the front door: how close the big things are, what moved this week, and the wave that moved them #1096

Closed opened this in answer to
Closed without merging

scout/forge:scout/1083-milestones-at-the-front-door-how-close-t → main 1 commit fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
7 files changed +172 −2
src/core/milestones.ts +2
@@ -561,6 +561,8 @@ function weightJson(weight: Weight): Record<string, unknown> {
561561 open: weight.open,
562562 building: weight.building,
563563 mergedInDays: { days: PILLAR_DAYS, merged: weight.merged },
564 // What landed in the last 7 days, named for who asks "what moved".
565 movedThisWeek: weight.merged,
564566 lastMovement: weight.last,
565567 ...(weight.spentUsd === undefined ? {} : { spentUsd: weight.spentUsd }),
566568 };
src/http/mcp.ts +1 −1
@@ -1162,7 +1162,7 @@ const TOOLS: readonly Tool[] = [
11621162 {
11631163 name: "milestones",
11641164 description:
1165 "How far each thing asked for is, read from the dependency tree. With `app` alone: the plan's top-level limbs (the pillars and Later, or the plan's roots), each with done and total, open issues beneath it, how many are building, pulls merged in the last 7 days, its last movement, spend when you may see it, and `trim` when it is a candidate to trim. With `issue`: that milestone opened — who is building what, what is blocked and on what, what merged, an estimate from this week's pace, its own limbs and its leaves. The same numbers as the milestones pages.",
1165 "How far each thing asked for is, read from the dependency tree. With `app` alone: the plan's top-level limbs (the pillars and Later, or the plan's roots), each with done and total, open issues beneath it, how many are building, pulls merged in the last 7 days (`movedThisWeek`), its last movement, spend when you may see it, and `trim` when it is a candidate to trim. With `issue`: that milestone opened — who is building what, what is blocked and on what, what merged, an estimate from this week's pace, its own limbs and its leaves. The same numbers as the milestones pages.",
11661166 inputSchema: {
11671167 type: "object",
11681168 properties: {
src/http/server.ts +6
@@ -158,6 +158,10 @@ import {
158158 milestonesPage,
159159 milestoneWatch,
160160 } from "../web/pages/milestones.ts";
161 import {
162 appMilestonesFragment,
163 liveMilestonesFragment,
164 } from "../web/studio/milestone_lines.ts";
161165 import {
162166 limbPreviewPage,
163167 limbReceiptPage,
@@ -594,6 +598,7 @@ export function buildRouter(): Router<Handler> {
594598 router.add("GET", "/live/apps", liveAppsFragment);
595599 router.add("GET", "/live/on-you", liveOnYouFragment);
596600 router.add("GET", "/live/feed", liveFeedFragment);
601 router.add("GET", "/live/milestones", liveMilestonesFragment);
597602 // Whether a hostname is an app's verified domain — what Caddy's
598603 // `on_demand_tls { ask … }` asks before it fetches a certificate for a
599604 // name it has never seen (docs/EXTRACT.md). 200 says yes, 404 says no,
@@ -951,6 +956,7 @@ export function buildRouter(): Router<Handler> {
951956 router.add("GET", "/:owner/:name/app/state", appStateFragment);
952957 // "Now" on the same page, alone: the region's own address.
953958 router.add("GET", "/:owner/:name/app/now", appNowFragment);
959 router.add("GET", "/:owner/:name/app/milestones", appMilestonesFragment);
954960 router.add("GET", "/:owner/:name/app/:env/open", appOpen);
955961 // Where a private app sends a person who arrived by its link.
956962 router.add("GET", "/apps/open", appsOpen);
src/web/studio/app.ts +3
@@ -46,6 +46,7 @@ import {
4646 } from "../ui.ts";
4747 import { changesHref, tellsHref } from "./nouns.ts";
4848 import { nowCard, nowRegion } from "./now.ts";
49 import { appMilestones, milestoneLinesCss } from "./milestone_lines.ts";
4950 import { appPanels } from "./previews.ts";
5051 import { noCrewLine, servingHistory, type WordCtx } from "./words.ts";
5152 import { crewKeyNote } from "./crew.ts";
@@ -461,6 +462,7 @@ export async function studioApp(
461462 ${tell}
462463 <div id="app-previews">${previews}</div>
463464 ${nowRegion(repo, now)}
465 ${appMilestones(ctx, repo)}
464466 </div>
465467 <aside class="dash-rail stack">
466468 ${crewCard} ${weekCard} ${ownCard} ${more}
@@ -473,6 +475,7 @@ export async function studioApp(
473475 crumbs: crumbsFor(repo),
474476 palette: repoPalette(ctx, repo),
475477 body,
478 styleCss: milestoneLinesCss,
476479 scriptJs: `${liveClientJs}\n${liveRegionsJs}\n${appTailJs}`,
477480 // The no-script half of the tail: while the crew's run goes, the page
478481 // refreshes itself, the way the run's own page does; the script above
src/web/studio/home.ts +11 −1
@@ -29,6 +29,7 @@ import { liveRegionsJs } from "../client.ts";
2929 import { html, when, type Html } from "../html.ts";
3030 import { fragment, page, redirect } from "../layout.ts";
3131 import { liveClientJs } from "../live.ts";
32 import { homeMilestones, milestoneLinesCss } from "./milestone_lines.ts";
3233 import {
3334 btn,
3435 card,
@@ -196,6 +197,7 @@ export async function studioHome(
196197 // on a phone.
197198 user.isAdmin || appRepos.length > 0 ? crewKeyNote(ctx) : null
198199 }
200 ${homeMilestones(ctx)}
199201 ${appsRegion(ctx, user)}
200202 ${onYouRegion(ctx, user)}
201203 ${terminalCard(ctx)} ${downloadsCard(ctx, user)}
@@ -206,6 +208,7 @@ export async function studioHome(
206208 ctx,
207209 title: "Home",
208210 body,
211 styleCss: milestoneLinesCss,
209212 scriptJs: `${liveClientJs}\n${liveRegionsJs}\n${feedJs}\n${needsYou.scriptJs}`,
210213 });
211214 }
@@ -434,6 +437,7 @@ export function studioDoor(ctx: Ctx): Response {
434437 </p>`,
435438 )}
436439 </section>
440 <div class="mt">${homeMilestones(ctx)}</div>
437441 ${when(front.featured, (f) => html`<div class="mt">${featuredCard(f)}</div>`)}
438442 ${tiles.length > 0
439443 ? html`<div class="mt app-shelf">${tiles}</div>
@@ -454,7 +458,13 @@ export function studioDoor(ctx: Ctx): Response {
454458 </div>`
455459 : null}
456460 ${when(admin, () => html`<div class="mt front-admin">${frontControls(ctx, front)}</div>`)}`;
457 return page({ ctx, title: "forge", body });
461 return page({
462 ctx,
463 title: "forge",
464 body,
465 styleCss: milestoneLinesCss,
466 scriptJs: `${liveClientJs}\n${liveRegionsJs}`,
467 });
458468 }
459469
460470 /** What one `/front` form asks for, applied to what is set now. */
src/web/studio/milestone_lines.ts added +121
@@ -0,0 +1,121 @@
1 /**
2 * Milestones at the front door (#1083): the few biggest open milestones as
3 * quiet lines — name, done of total, what landed this week, the estimate —
4 * on the home and on an app's page. Read from `core/milestones.ts`, the
5 * same numbers as the milestones pages; never spend, which is the owner's
6 * and has its own page. A region that has nothing moved paints nothing.
7 */
8
9 import { readPlan, type Limb } from "../../core/milestones.ts";
10 import type { Repo } from "../../core/repos.ts";
11 import { PILLAR_DAYS } from "../../core/pillars.ts";
12 import type { Ctx } from "../../http/context.ts";
13 import { fragment } from "../layout.ts";
14 import { loadRepo, repoBase } from "../chrome.ts";
15 import { html, type Html } from "../html.ts";
16 import { milestoneHref } from "../pages/milestones.ts";
17 import { appsOf, writableAppsOf } from "./asks.ts";
18
19 /** How many milestones the front door names. */
20 export const FRONT_MILESTONES = 3;
21 /** How many apps the home reads plans of, newest first: a bound on the work. */
22 const REPOS_READ = 30;
23 /** The events that can move a milestone. */
24 const MILESTONE_LIVE = "issue.*,pull.merged,pull.closed";
25
26 interface Line {
27 readonly repo: Repo;
28 readonly limb: Limb;
29 readonly estimate: string;
30 }
31
32 /** The biggest open milestones of these repositories, by open work beneath them. */
33 export function biggestMilestones(
34 ctx: Ctx,
35 repos: readonly Repo[],
36 count = FRONT_MILESTONES,
37 ): Line[] {
38 const all: { repo: Repo; limb: Limb; plan: ReturnType<typeof readPlan> }[] = [];
39 for (const repo of repos.slice(0, REPOS_READ)) {
40 // Spend is never read here: the front door shows no owner facts.
41 const plan = readPlan(ctx.app.db, repo, { spend: false });
42 for (const limb of plan.limbs)
43 if (!limb.deferred && limb.issue.state === "open" && limb.weight.open > 0)
44 all.push({ repo, limb, plan });
45 }
46 all.sort(
47 (a, b) =>
48 b.limb.weight.open - a.limb.weight.open ||
49 a.limb.issue.number - b.limb.issue.number,
50 );
51 return all.slice(0, count).map(({ repo, limb, plan }) => ({
52 repo,
53 limb,
54 estimate: plan.milestone(limb.issue.number)?.estimate ?? "",
55 }));
56 }
57
58 /** The lines: nothing at all when nothing among them moved this week. */
59 function lines(rows: readonly Line[], scoped: boolean): Html | null {
60 if (!rows.some((r) => r.limb.weight.merged > 0)) return null;
61 return html`<ul class="ms-front small">
62 ${rows.map((r) => {
63 const w = r.limb.weight;
64 return html`<li>
65 <a href="${milestoneHref(repoBase(r.repo), r.limb.issue.number)}"
66 >${r.limb.name}</a
67 >
68 ${scoped ? null : html`<span class="muted">${r.repo.name}</span>`}
69 <span><b>${w.done}</b> of ${w.total} done</span>
70 <span class="muted"
71 >${w.merged > 0
72 ? `${w.merged} landed in ${PILLAR_DAYS} days`
73 : "quiet this week"}
74 · ${r.estimate}</span
75 >
76 </li>`;
77 })}
78 </ul>`;
79 }
80
81 /** The home's region: the viewer's apps, or the public ones for a visitor. */
82 export function homeMilestones(ctx: Ctx): Html {
83 const user = ctx.auth.user;
84 const { repos } = user ? writableAppsOf(ctx, user) : appsOf(ctx, undefined);
85 return html`<div
86 id="live-milestones"
87 data-live="${MILESTONE_LIVE}"
88 data-live-src="/live/milestones"
89 >
90 ${lines(biggestMilestones(ctx, repos), false)}
91 </div>`;
92 }
93
94 /** An app's region: its own milestones, for whoever may read it. */
95 export function appMilestones(ctx: Ctx, repo: Repo): Html {
96 return html`<div
97 id="live-milestones"
98 data-live="${MILESTONE_LIVE}"
99 data-live-repo="${repo.ownerName}/${repo.name}"
100 data-live-src="${repoBase(repo)}/app/milestones"
101 >
102 ${lines(biggestMilestones(ctx, [repo]), true)}
103 </div>`;
104 }
105
106 // GET /live/milestones — the home's lines alone.
107 export function liveMilestonesFragment(ctx: Ctx): Response {
108 return fragment(homeMilestones(ctx), { request: ctx.request });
109 }
110
111 // GET /:owner/:name/app/milestones — an app's lines alone.
112 export function appMilestonesFragment(ctx: Ctx): Response {
113 const repo = loadRepo(ctx);
114 if (!repo) return fragment(html``, { status: 404 });
115 return fragment(appMilestones(ctx, repo), { request: ctx.request });
116 }
117
118 export const milestoneLinesCss = /* css */ `
119 .ms-front { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
120 .ms-front li { display: flex; flex-wrap: wrap; gap: 0 var(--s2, 8px); }
121 `;
test/milestones.test.ts +28
@@ -515,4 +515,32 @@ describe("milestones", () => {
515515 expect(page).toMatch(/<b>0<\/b> of 2 done/);
516516 expect(page).toContain("A profit slider");
517517 });
518 test("the front door: the biggest milestones as live lines, for a visitor too; nothing in an app with nothing moved", async () => {
519 const anon = await (await fetch(`${base}/`)).text();
520 expect(anon).toContain('id="live-milestones"');
521 expect(anon).toContain('data-live-src="/live/milestones"');
522 expect(anon).toMatch(/of \d+ done/);
523 expect(anon).not.toMatch(/\$\d/);
524 const home = await (await get("alice", "/")).text();
525 expect(home).toContain('data-live-src="/live/milestones"');
526 expect(home).toMatch(/landed in 7 days/);
527 const lines = await get("alice", "/live/milestones");
528 expect(lines.status).toBe(200);
529 expect(await lines.text()).toContain("/alice/engine/milestones/");
530 // An app whose plan moved nothing paints an empty region.
531 const quiet = await (await get("bob", "/alice/plain/app/milestones")).text();
532 expect(quiet).toContain('data-live-src="/alice/plain/app/milestones"');
533 expect(quiet).not.toContain("ms-front");
534 const app = await (await get("bob", "/alice/engine/app/milestones")).text();
535 expect(app).toContain("ms-front");
536 expect((await get("bob", "/nobody/none/app/milestones")).status).toBe(404);
537 });
538
539 test("the data says what moved this week", async () => {
540 const m = (await (await api("/api/v1/repos/alice/engine/milestones")).json()) as {
541 limbs: { movedThisWeek: number; mergedInDays: { merged: number } }[];
542 };
543 for (const l of m.limbs) expect(l.movedThisWeek).toBe(l.mergedInDays.merged);
544 expect(m.limbs.some((l) => l.movedThisWeek > 0)).toBe(true);
545 });
518546 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs