Public: anyone can read this; the crew can change it.
The terminal dashboard and MCP `feed` show the same three digest lines as home #6683
scout/forge:scout/5803-the-terminal-dashboard-and-mcp-feed-show → main 2 commits fork
8 files
changed +127
−13
README.md +1
| @@ -589,6 +589,7 @@ work here. | ||
| 589 | 589 | default branches (force-push and deletion refused, honest fast-forwards |
| 590 | 590 | allowed). |
| 591 | 591 | - **System memory** — `/system`, for a forge admin who is a person (anyone else gets 403): the forge's RSS beside its JS heap (`heapStats()` from bun:jsc), hourly mean and max for the last 24 h, drawn on the server. Sampled once a minute into `memory_hour` in `app.db` (a week kept). RSS rising while the heap stays flat is native memory growth. In the terminal the same admin has a **System memory** command in the palette: the last 24 hours as text rows (hour, RSS mean/max, heap mean/max in MiB), read-only. The account menu links `/system` for that admin. |
| 592 | - **The day's digest** — at most three lines (one per repository, biggest change first, each with its evidence link) from `homeDigest` in `src/feed/home_digest.ts`: on home above the feed, on the terminal dashboard under the figures, and in MCP `feed` as the `digest` array of `{ repo, says, href }`. | |
| 592 | 593 | - **Flow alarms** — a firing alarm (red main, a stuck approved pull, an idle crew, no release for 90 min) shows as one linked line above home's feed and on `/boards` (admin), under the vitals line of the terminal's Flow dialog and home, as one phone notification when it starts (not repeated while it stands), and in the `flow` tool's `alarms` (MCP, `/api/v1/telemetry/flow`; an agent's cut to public repositories). Nothing firing draws nothing. |
| 593 | 594 | - **Boards** — `/boards` also shows the pipeline (a row per stage, the bottleneck named) and the held counts (why each autonomous repository's ready issues wait; private repositories included), for the same admin who is a person; they sit as two cards under the board list, not as panels of a board, because they are not saved queries. The terminal's Boards screen does not draw them: its door to the same rows is the **Flow** dialog. `/boards/data`, for a forge admin who is a person (anyone else |
| 594 | 595 | gets a 404 on the page): the query is the URL (`?source=runs&aggregate=count&by=day&fcolumn=state&fvalue=failed`), |
docs/MCP.md +1 −1
| @@ -69,7 +69,7 @@ for a tunnel and a forge that sleeps. | ||
| 69 | 69 | | `events` | `{ repo, limit?, cursor? }`: the repository's events, newest first, as you may see them (a webhook's URL and an app's variable names are the admins'): `{ items, next_cursor }`, `limit` 1 to 200 (default 50), `cursor` from `next_cursor` | | |
| 70 | 70 | | `explore` | `{ query? }`: the apps and people you can see, ranked by forks, ships, use and freshness, with their numbers; `kind:` `sort:` and words in one line | | |
| 71 | 71 | | `family` | the forge that sent this one and, for a site admin, those it sent, with state and version | | |
| 72 | | `feed` | `{ limit?, cursor? }`: your home timeline — tells, replies, runs, changes and looks — ranked, with who, what, why and a link; the same items as `GET /api/v1/feed`; `quietRuns` counts agent runs of the last 24 h that pushed, opened or said nothing, which the timeline leaves out | | | |
| 72 | | `feed` | `{ limit?, cursor? }`: your home timeline — tells, replies, runs, changes and looks — ranked, with who, what, why and a link; the same items as `GET /api/v1/feed`; `digest` is the last day in at most three `{ repo, says, href }` lines, the same as home; `quietRuns` counts agent runs of the last 24 h that pushed, opened or said nothing, which the timeline leaves out | | | |
| 73 | 73 | | `feed_chips` | `{ kind?, value?, hidden? }`: the feed chips you switched off, which `feed` and `asks` leave out; with `kind` (`kind` or `person`), `value` and `hidden` it switches one off or on | yes | |
| 74 | 74 | | `flag_set` | `{ name, value?, clear? }`: set a declared flag's live value (`value` is `{ forge?, users?, roles?, percent? }`) or `clear` it to its default, with the Flags page's checks and refusals; a forge admin's (never an agent), an admin token; answers `{ name, value, says }` | yes | |
| 75 | 75 | | `flow` | the forge's pipeline (a forge admin's, or an agent the owner granted `telemetry:read`; private repositories cut out): per stage counts, `oldestWaiting`, `capacity`, the bottleneck, the merge `queue` and what each reviewer has `reviewing` | | |
src/feed/feed.ts +1 −1
| @@ -94,7 +94,7 @@ export function quietRunCount( | ||
| 94 | 94 | return cache.get(key, stamp, count); |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | function viewerCandidates( | |
| 97 | export function viewerCandidates( | |
| 98 | 98 | db: Database, |
| 99 | 99 | viewer: User, |
| 100 | 100 | now: number, |
src/feed/home_digest.ts added +33
| @@ -0,0 +1,33 @@ | ||
| 1 | /** | |
| 2 | * The day's digest for one viewer: the feed's candidates, as `digest` events. | |
| 3 | * Home, the terminal dashboard and MCP `feed` all call this one function, so | |
| 4 | * they cannot say different things. A viewer sees only what their feed shows. | |
| 5 | */ | |
| 6 | ||
| 7 | import type { Database } from "bun:sqlite"; | |
| 8 | import { chipsOf } from "../core/feed_chips.ts"; | |
| 9 | import type { User } from "../core/users.ts"; | |
| 10 | import { digest, type DigestEvent, type DigestKind, type DigestLine } from "./digest.ts"; | |
| 11 | import { viewerCandidates } from "./feed.ts"; | |
| 12 | import type { Candidate } from "./items.ts"; | |
| 13 | ||
| 14 | const WEIGHT: Record<DigestKind, number> = { landed: 3, released: 2, failed: 2, decided: 1 }; | |
| 15 | ||
| 16 | function kindOf(c: Candidate): DigestKind | undefined { | |
| 17 | if (c.kind === "pull" && c.what.startsWith("merged")) return "landed"; | |
| 18 | if (c.kind === "release") return "released"; | |
| 19 | if (c.kind === "run" && c.urgency >= 4) return "failed"; | |
| 20 | if (c.kind === "decision") return "decided"; | |
| 21 | return undefined; | |
| 22 | } | |
| 23 | ||
| 24 | export function homeDigest(db: Database, viewer: User, now: number = Date.now()): DigestLine[] { | |
| 25 | const events: DigestEvent[] = []; | |
| 26 | for (const c of viewerCandidates(db, viewer, now, chipsOf(db, viewer.id), false)) { | |
| 27 | const kind = kindOf(c); | |
| 28 | const at = Date.parse(c.at); | |
| 29 | if (kind === undefined || !Number.isFinite(at)) continue; | |
| 30 | events.push({ repo: c.app, kind, at, href: c.link, weight: WEIGHT[kind] }); | |
| 31 | } | |
| 32 | return digest(events, now); | |
| 33 | } |
src/http/mcp/tools/feed.ts +8 −8
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | import { FEED_LIMIT_DEFAULT, FEED_LIMIT_MAX, parseCursor, readFeed } from "../../../feed/feed.ts"; |
| 2 | import { homeDigest } from "../../../feed/home_digest.ts"; | |
| 2 | 3 | import { good, bad, type Tool, CHIP_ARGS, chipArgs, str } from "../shared.ts"; |
| 3 | 4 | |
| 4 | 5 | export const tool: Tool = { |
| 5 | 6 | name: "feed", |
| 6 | doc: "`{ limit?, cursor? }`: your home timeline — tells, replies, runs, changes and looks — ranked, with who, what, why and a link; the same items as `GET /api/v1/feed`; `quietRuns` counts agent runs of the last 24 h that pushed, opened or said nothing, which the timeline leaves out", | |
| 7 | doc: "`{ limit?, cursor? }`: your home timeline — tells, replies, runs, changes and looks — ranked, with who, what, why and a link; the same items as `GET /api/v1/feed`; `digest` is the last day in at most three `{ repo, says, href }` lines, the same as home; `quietRuns` counts agent runs of the last 24 h that pushed, opened or said nothing, which the timeline leaves out", | |
| 7 | 8 | description: |
| 8 | 9 | "Your ranked home timeline; `cursor` pages; saved filter applies.", |
| 9 | 10 | inputSchema: { |
| @@ -26,12 +27,11 @@ export const tool: Tool = { | ||
| 26 | 27 | const cursor = given === undefined ? undefined : parseCursor(str(given)); |
| 27 | 28 | if (given !== undefined && cursor === undefined) |
| 28 | 29 | return bad("invalid", "that cursor was not issued here"); |
| 29 | return good( | |
| 30 | readFeed(ctx.app.db, user, { | |
| 31 | limit, | |
| 32 | ...(chips === undefined ? {} : { chips }), | |
| 33 | ...(cursor === undefined ? {} : { cursor }), | |
| 34 | }), | |
| 35 | ); | |
| 30 | const page = readFeed(ctx.app.db, user, { | |
| 31 | limit, | |
| 32 | ...(chips === undefined ? {} : { chips }), | |
| 33 | ...(cursor === undefined ? {} : { cursor }), | |
| 34 | }); | |
| 35 | return good({ ...page, digest: homeDigest(ctx.app.db, user) }); | |
| 36 | 36 | }, |
| 37 | 37 | }; |
src/tui/screens/dashboard.ts +6 −1
| @@ -94,6 +94,7 @@ import { | ||
| 94 | 94 | linkScreen, |
| 95 | 95 | } from "./common.ts"; |
| 96 | 96 | import { readVitals, vitalsLine } from "../../flow/vitals.ts"; |
| 97 | import { homeDigest } from "../../feed/home_digest.ts"; | |
| 97 | 98 | import { readKpis } from "../../flow/kpis.ts"; |
| 98 | 99 | import { kpiLines } from "../../flow/kpi_words.ts"; |
| 99 | 100 | import { BOOTED } from "../../release/gate.ts"; |
| @@ -193,6 +194,8 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 193 | 194 | let decider: string | null = null; |
| 194 | 195 | /** Home's three figures, as the web's row says them; empty unless an admin looks (they count every repository). */ |
| 195 | 196 | let figures: string[] = []; |
| 197 | /** The day's digest, from the function home calls; drawn under the figures. */ | |
| 198 | let digestLines: string[] = []; | |
| 196 | 199 | /** One line per fired flow alarm; an admin reads every repository, anyone else public ones alone. */ |
| 197 | 200 | let alarms: string[] = []; |
| 198 | 201 | /** The panels this admin pinned to the web home, by title and board, in their order. */ |
| @@ -211,6 +214,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 211 | 214 | if (!f.user || (await nextStepsFor(f.app, f.user)) === undefined) return; |
| 212 | 215 | // A client's home never carries the forge-wide figures, on either door. |
| 213 | 216 | figures = []; |
| 217 | digestLines = []; | |
| 214 | 218 | const apps = await clientAppRows(f.app, f.user); |
| 215 | 219 | clientRepoIds = new Set(apps.map((a) => a.repo.id)); |
| 216 | 220 | clientLive = new Map(apps.flatMap((a) => (a.live === undefined ? [] : [[a.repo.id, a.live] as const]))); |
| @@ -288,6 +292,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 288 | 292 | waits = ownerWaits(f.db, all.filter((r) => facts.has(r.id))).map(waitLine); |
| 289 | 293 | lane = forgeLane(f.app, f.user); |
| 290 | 294 | decider = deciderLine(f.app, f.user); |
| 295 | digestLines = f.user === undefined ? [] : homeDigest(f.db, f.user, now.getTime()).map((l) => l.says); | |
| 291 | 296 | const commit = running().commit; |
| 292 | 297 | figures = |
| 293 | 298 | f.user?.isAdmin !== true |
| @@ -911,7 +916,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen { | ||
| 911 | 916 | body = rest!; |
| 912 | 917 | } |
| 913 | 918 | // A short terminal drops the last figures before it drops the list. |
| 914 | const shown = figures.slice(0, Math.max(0, body.h - FIGURES_ROOM)); | |
| 919 | const shown = [...figures, ...digestLines].slice(0, Math.max(0, body.h - FIGURES_ROOM)); | |
| 915 | 920 | if (shown.length > 0) { |
| 916 | 921 | const [strip, rest] = split(body, "v", [len(shown.length), fill(1)]); |
| 917 | 922 | shown.forEach((line, i) => |
src/web/studio/feed.ts +5 −2
| @@ -15,6 +15,7 @@ import type { Ctx } from "../../http/context.ts"; | ||
| 15 | 15 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; |
| 16 | 16 | import { placementsOf, type Placement } from "../../core/placements.ts"; |
| 17 | 17 | import { recentThoughts, type Thought } from "../../core/thoughts.ts"; |
| 18 | import { homeDigest } from "../../feed/home_digest.ts"; | |
| 18 | 19 | import { parseCursor, readFeedPage } from "../../feed/feed.ts"; |
| 19 | 20 | import type { FeedItem } from "../../feed/rank.ts"; |
| 20 | 21 | import { getAppByRepo } from "../../core/apps.ts"; |
| @@ -314,7 +315,8 @@ function readRegion(user: User, ctx: Ctx) { | ||
| 314 | 315 | const quiet = page.quiet; |
| 315 | 316 | const quietRepo = quiet.repoId === null ? undefined : getRepoById(ctx.app.db, quiet.repoId); |
| 316 | 317 | const quietLink = quietRepo === undefined ? "/explore" : `/${quietRepo.ownerName}/${quietRepo.name}/runs?kind=agent`; |
| 317 | return { items, next: page.next_cursor, cursor, lastDayOnPage, thoughts, placed, marks, pictures: picturesFor(ctx, items), quiet: quiet.count, quietLink }; | |
| 318 | const digest = cursor === undefined ? homeDigest(ctx.app.db, user) : []; | |
| 319 | return { digest, items, next: page.next_cursor, cursor, lastDayOnPage, thoughts, placed, marks, pictures: picturesFor(ctx, items), quiet: quiet.count, quietLink }; | |
| 318 | 320 | } |
| 319 | 321 | |
| 320 | 322 | /** The region: cards, or one line saying there is nothing to do. */ |
| @@ -342,7 +344,7 @@ export function caughtUp(items: readonly FeedItem[], next: string | null, cursor | ||
| 342 | 344 | } |
| 343 | 345 | |
| 344 | 346 | function drawRegion(user: User, ctx: Ctx, read: ReturnType<typeof readRegion>): Html { |
| 345 | const { items, next, cursor, lastDayOnPage, thoughts, placed, marks, pictures, quiet, quietLink } = read; | |
| 347 | const { digest, items, next, cursor, lastDayOnPage, thoughts, placed, marks, pictures, quiet, quietLink } = read; | |
| 346 | 348 | const now = new Date(); |
| 347 | 349 | // One divider per change of day between neighbours, in the order the feed already has. |
| 348 | 350 | const posts: Html[] = []; |
| @@ -364,6 +366,7 @@ function drawRegion(user: User, ctx: Ctx, read: ReturnType<typeof readRegion>): | ||
| 364 | 366 | data-live="${FEED_LIVE}" |
| 365 | 367 | data-live-src="/live/feed${liveQuery === "" ? "" : `?${liveQuery}`}" |
| 366 | 368 | > |
| 369 | ${digest.length === 0 ? "" : html`<ul class="small" aria-label="Since yesterday" data-digest>${digest.map((l) => html`<li><a href="${l.href}">${l.says}</a></li>`)}</ul>`} | |
| 367 | 370 | ${chipsBar(user, ctx, items)} |
| 368 | 371 | ${thoughts.map((t) => thoughtCard(t, user.username, placed.get(t.id)))} |
| 369 | 372 | ${items.length === 0 && thoughts.length === 0 |
test/digest-doors.test.ts added +72
| @@ -0,0 +1,72 @@ | ||
| 1 | /** The day's digest says the same lines on the web home, the terminal dashboard and MCP `feed` (#5803). */ | |
| 2 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 3 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { createApp, type App } from "../src/app.ts"; | |
| 7 | import { createRepo } from "../src/actions/repos.ts"; | |
| 8 | import { createSession } from "../src/core/sessions.ts"; | |
| 9 | import { createToken } from "../src/core/tokens.ts"; | |
| 10 | import { createUser, type User } from "../src/core/users.ts"; | |
| 11 | import { homeDigest } from "../src/feed/home_digest.ts"; | |
| 12 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 13 | import { createForgeApp } from "../src/tui/forge.ts"; | |
| 14 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; | |
| 15 | import { quietLogs } from "./helpers/globals.ts"; | |
| 16 | import { settleApp } from "./helpers/tui.ts"; | |
| 17 | import { promote } from "./helpers/members.ts"; | |
| 18 | ||
| 19 | quietLogs(); | |
| 20 | ||
| 21 | let dir: string; | |
| 22 | let app: App; | |
| 23 | let servers: Servers; | |
| 24 | let alice: User; | |
| 25 | ||
| 26 | beforeAll(async () => { | |
| 27 | dir = await mkdtemp(join(tmpdir(), "forge-digest-doors-")); | |
| 28 | app = createApp({ dataDir: dir, port: 0 }); | |
| 29 | servers = await serve(app); | |
| 30 | const r = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 31 | if (!r.ok) throw new Error(r.error); | |
| 32 | alice = r.value; | |
| 33 | promote(app.db, alice); | |
| 34 | const g = await createRepo(app, alice, { name: "garden", visibility: "public" }); | |
| 35 | if (!g.ok) throw new Error("repo"); | |
| 36 | app.bus.append({ kind: "app.serving", repoId: g.value.id, payload: { app: "garden", env: "production", commitOid: "a".repeat(40), version: "1.2.3" } }); | |
| 37 | }); | |
| 38 | ||
| 39 | afterAll(async () => { | |
| 40 | servers.stop?.(); | |
| 41 | app.close(); | |
| 42 | await rm(dir, { recursive: true, force: true }); | |
| 43 | }); | |
| 44 | ||
| 45 | test("web, terminal and MCP give identical digest lines for one seeded forge", async () => { | |
| 46 | const lines = homeDigest(app.db, alice); | |
| 47 | expect(lines.length).toBeGreaterThan(0); | |
| 48 | expect(lines[0]!.says).toBe("alice/garden: 1 released"); | |
| 49 | ||
| 50 | const cookie = `forge_session=${createSession(app.db, alice.id).token}; forge_mode=studio`; | |
| 51 | const page = await fetch(`${servers.url}/`, { headers: { cookie } }).then((r) => r.text()); | |
| 52 | for (const l of lines) { | |
| 53 | expect(page).toContain(`<a href="${l.href}">${l.says}</a>`); | |
| 54 | } | |
| 55 | ||
| 56 | const token = createToken(app.db, alice.id, "digest", "ro").token; | |
| 57 | const res = await fetch(`${servers.url}/mcp`, { | |
| 58 | method: "POST", | |
| 59 | headers: { "content-type": "application/json", accept: "application/json, text/event-stream", authorization: `Bearer ${token}` }, | |
| 60 | body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "feed", arguments: {} } }), | |
| 61 | }); | |
| 62 | const body = JSON.parse(((await res.json()) as any).result.content[0].text); | |
| 63 | expect(body.digest).toEqual(lines); | |
| 64 | ||
| 65 | const terminal = headlessTerminal(200, 32); | |
| 66 | const { app: tui } = createForgeApp(app, { sshUsername: "alice", remoteAddress: "127.0.0.1", fingerprint: "SHA256:t", user: alice }, { terminal, exitHooks: false }); | |
| 67 | tui.start(); | |
| 68 | await settleApp(tui); | |
| 69 | const text = tui.screen.toText(); | |
| 70 | tui.stop(); | |
| 71 | for (const l of lines) expect(text).toContain(l.says); | |
| 72 | }); |
new above
offline