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
scout/forge:scout/1083-milestones-at-the-front-door-how-close-t → main 1 commit fork
7 files
changed +172
−2
src/core/milestones.ts +2
| @@ -561,6 +561,8 @@ function weightJson(weight: Weight): Record<string, unknown> { | ||
| 561 | 561 | open: weight.open, |
| 562 | 562 | building: weight.building, |
| 563 | 563 | 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, | |
| 564 | 566 | lastMovement: weight.last, |
| 565 | 567 | ...(weight.spentUsd === undefined ? {} : { spentUsd: weight.spentUsd }), |
| 566 | 568 | }; |
src/http/mcp.ts +1 −1
| @@ -1162,7 +1162,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 1162 | 1162 | { |
| 1163 | 1163 | name: "milestones", |
| 1164 | 1164 | 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.", | |
| 1166 | 1166 | inputSchema: { |
| 1167 | 1167 | type: "object", |
| 1168 | 1168 | properties: { |
src/http/server.ts +6
| @@ -158,6 +158,10 @@ import { | ||
| 158 | 158 | milestonesPage, |
| 159 | 159 | milestoneWatch, |
| 160 | 160 | } from "../web/pages/milestones.ts"; |
| 161 | import { | |
| 162 | appMilestonesFragment, | |
| 163 | liveMilestonesFragment, | |
| 164 | } from "../web/studio/milestone_lines.ts"; | |
| 161 | 165 | import { |
| 162 | 166 | limbPreviewPage, |
| 163 | 167 | limbReceiptPage, |
| @@ -594,6 +598,7 @@ export function buildRouter(): Router<Handler> { | ||
| 594 | 598 | router.add("GET", "/live/apps", liveAppsFragment); |
| 595 | 599 | router.add("GET", "/live/on-you", liveOnYouFragment); |
| 596 | 600 | router.add("GET", "/live/feed", liveFeedFragment); |
| 601 | router.add("GET", "/live/milestones", liveMilestonesFragment); | |
| 597 | 602 | // Whether a hostname is an app's verified domain — what Caddy's |
| 598 | 603 | // `on_demand_tls { ask … }` asks before it fetches a certificate for a |
| 599 | 604 | // name it has never seen (docs/EXTRACT.md). 200 says yes, 404 says no, |
| @@ -951,6 +956,7 @@ export function buildRouter(): Router<Handler> { | ||
| 951 | 956 | router.add("GET", "/:owner/:name/app/state", appStateFragment); |
| 952 | 957 | // "Now" on the same page, alone: the region's own address. |
| 953 | 958 | router.add("GET", "/:owner/:name/app/now", appNowFragment); |
| 959 | router.add("GET", "/:owner/:name/app/milestones", appMilestonesFragment); | |
| 954 | 960 | router.add("GET", "/:owner/:name/app/:env/open", appOpen); |
| 955 | 961 | // Where a private app sends a person who arrived by its link. |
| 956 | 962 | router.add("GET", "/apps/open", appsOpen); |
src/web/studio/app.ts +3
| @@ -46,6 +46,7 @@ import { | ||
| 46 | 46 | } from "../ui.ts"; |
| 47 | 47 | import { changesHref, tellsHref } from "./nouns.ts"; |
| 48 | 48 | import { nowCard, nowRegion } from "./now.ts"; |
| 49 | import { appMilestones, milestoneLinesCss } from "./milestone_lines.ts"; | |
| 49 | 50 | import { appPanels } from "./previews.ts"; |
| 50 | 51 | import { noCrewLine, servingHistory, type WordCtx } from "./words.ts"; |
| 51 | 52 | import { crewKeyNote } from "./crew.ts"; |
| @@ -461,6 +462,7 @@ export async function studioApp( | ||
| 461 | 462 | ${tell} |
| 462 | 463 | <div id="app-previews">${previews}</div> |
| 463 | 464 | ${nowRegion(repo, now)} |
| 465 | ${appMilestones(ctx, repo)} | |
| 464 | 466 | </div> |
| 465 | 467 | <aside class="dash-rail stack"> |
| 466 | 468 | ${crewCard} ${weekCard} ${ownCard} ${more} |
| @@ -473,6 +475,7 @@ export async function studioApp( | ||
| 473 | 475 | crumbs: crumbsFor(repo), |
| 474 | 476 | palette: repoPalette(ctx, repo), |
| 475 | 477 | body, |
| 478 | styleCss: milestoneLinesCss, | |
| 476 | 479 | scriptJs: `${liveClientJs}\n${liveRegionsJs}\n${appTailJs}`, |
| 477 | 480 | // The no-script half of the tail: while the crew's run goes, the page |
| 478 | 481 | // 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"; | ||
| 29 | 29 | import { html, when, type Html } from "../html.ts"; |
| 30 | 30 | import { fragment, page, redirect } from "../layout.ts"; |
| 31 | 31 | import { liveClientJs } from "../live.ts"; |
| 32 | import { homeMilestones, milestoneLinesCss } from "./milestone_lines.ts"; | |
| 32 | 33 | import { |
| 33 | 34 | btn, |
| 34 | 35 | card, |
| @@ -196,6 +197,7 @@ export async function studioHome( | ||
| 196 | 197 | // on a phone. |
| 197 | 198 | user.isAdmin || appRepos.length > 0 ? crewKeyNote(ctx) : null |
| 198 | 199 | } |
| 200 | ${homeMilestones(ctx)} | |
| 199 | 201 | ${appsRegion(ctx, user)} |
| 200 | 202 | ${onYouRegion(ctx, user)} |
| 201 | 203 | ${terminalCard(ctx)} ${downloadsCard(ctx, user)} |
| @@ -206,6 +208,7 @@ export async function studioHome( | ||
| 206 | 208 | ctx, |
| 207 | 209 | title: "Home", |
| 208 | 210 | body, |
| 211 | styleCss: milestoneLinesCss, | |
| 209 | 212 | scriptJs: `${liveClientJs}\n${liveRegionsJs}\n${feedJs}\n${needsYou.scriptJs}`, |
| 210 | 213 | }); |
| 211 | 214 | } |
| @@ -434,6 +437,7 @@ export function studioDoor(ctx: Ctx): Response { | ||
| 434 | 437 | </p>`, |
| 435 | 438 | )} |
| 436 | 439 | </section> |
| 440 | <div class="mt">${homeMilestones(ctx)}</div> | |
| 437 | 441 | ${when(front.featured, (f) => html`<div class="mt">${featuredCard(f)}</div>`)} |
| 438 | 442 | ${tiles.length > 0 |
| 439 | 443 | ? html`<div class="mt app-shelf">${tiles}</div> |
| @@ -454,7 +458,13 @@ export function studioDoor(ctx: Ctx): Response { | ||
| 454 | 458 | </div>` |
| 455 | 459 | : null} |
| 456 | 460 | ${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 | }); | |
| 458 | 468 | } |
| 459 | 469 | |
| 460 | 470 | /** 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", () => { | ||
| 515 | 515 | expect(page).toMatch(/<b>0<\/b> of 2 done/); |
| 516 | 516 | expect(page).toContain("A profit slider"); |
| 517 | 517 | }); |
| 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 | }); | |
| 518 | 546 | }); |
new above
offline