Public: anyone can read this; the crew can change it.
The terminal home shows pinned panels #8810
torque/forge:torque/8758-the-terminal-home-shows-pinned-panels → main 2 commits fork
5 files
changed +154
−1
docs/features/pinned-panels.md added +9
| @@ -0,0 +1,9 @@ | ||
| 1 | # Pinned panels in the terminal (#8758) | |
| 2 | ||
| 3 | A forge admin who is a person sees the panels pinned to the web home in the terminal, and can unpin and reorder them there. Agents, other members and guests have no door and no rows. | |
| 4 | ||
| 5 | - **Terminal:** palette > Pinned panels (`src/tui/screens/panelpins.ts`). `j`/`k` move the cursor, `x` unpins the row, `<` and `>` move it one step in the home order. | |
| 6 | - **Web:** the pin, unpin and move forms on a board page (`src/web/pages/boards-edit.ts`) and `/api/v1/boards/pins`. | |
| 7 | - **MCP:** `board_pins` with `op` = `pin`, `unpin` or `move` (`by` -1 or 1); no `op` lists. | |
| 8 | - **One path:** all four call `actions/board-pins.ts`, which forgets the viewer's remembered `panels` region on every write, so the web home redraws the next time it is read. `test/tui-boards.test.ts` holds that for the terminal. | |
| 9 | - **Not done:** pinning a panel stays on the Boards screen (`p`); the pins screen only lists, unpins and moves. |
src/tui/screens/entries.ts +2
| @@ -30,6 +30,7 @@ import { entry as orgTeams } from "./orgteams.ts"; | ||
| 30 | 30 | import { entry as owner } from "./owner.ts"; |
| 31 | 31 | import { entry as people } from "./people.ts"; |
| 32 | 32 | import { entry as pinned } from "./pinned.ts"; |
| 33 | import { entry as panelpins } from "./panelpins.ts"; | |
| 33 | 34 | import { entry as profile } from "./profile.ts"; |
| 34 | 35 | import { entry as quotas } from "./quotas.ts"; |
| 35 | 36 | import { entry as resilience } from "./resilience.ts"; |
| @@ -84,6 +85,7 @@ export const ENTRIES: readonly PaletteEntry[] = [ | ||
| 84 | 85 | subscriptions, |
| 85 | 86 | cloud, |
| 86 | 87 | pinned, |
| 88 | panelpins, | |
| 87 | 89 | connections, |
| 88 | 90 | domains, |
| 89 | 91 | feed, |
src/tui/screens/panelpins.ts added +82
| @@ -0,0 +1,82 @@ | ||
| 1 | /** | |
| 2 | * The panels pinned to the web home, in the terminal: a forge admin who is a | |
| 3 | * person lists them in their home order, `x` unpins the one under the cursor, | |
| 4 | * `<` and `>` move it one step, as the board_pins MCP tool and the web forms | |
| 5 | * do, all through `actions/board-pins.ts`. Pinning a panel is done on its | |
| 6 | * board (`p` in the boards screen). Anyone else has no door and no rows. | |
| 7 | */ | |
| 8 | import { listPinned, movePinned, unpinPanel, type PinError, type Pinned } from "../../actions/board-pins.ts"; | |
| 9 | import type { Ctx, Screen } from "../app/app.ts"; | |
| 10 | import { binding } from "../app/keys.ts"; | |
| 11 | import type { Session } from "../session.ts"; | |
| 12 | import { style } from "../term/style.ts"; | |
| 13 | import { truncate } from "../term/width.ts"; | |
| 14 | import { fill, len, split } from "../ui/layout.ts"; | |
| 15 | import { plain } from "./boards.ts"; | |
| 16 | import { ListState, drawList, runAsync, type ListRow } from "./common.ts"; | |
| 17 | import type { PaletteEntry } from "./entries.ts"; | |
| 18 | ||
| 19 | /** The rows of the pinned panels, one per pin, in the home order. */ | |
| 20 | export const pinRows = (pins: readonly Pinned[]): ListRow[] => | |
| 21 | pins.map((p) => ({ title: plain(p.panel.title), secondary: `${plain(p.board.title)} · ${p.panel.chart}` })); | |
| 22 | ||
| 23 | /** A refusal in words, by its error: a demoted admin is told so, not that the panel is unpinned. */ | |
| 24 | const said = (e: PinError): string => | |
| 25 | e === "not_found" ? "that panel is not pinned, or pins are not yours to change" : e === "too_many" ? "too many pins" : "that pin is not valid"; | |
| 26 | ||
| 27 | export function panelPinsScreen(f: Session, ctx: Ctx): Screen { | |
| 28 | const state = new ListState(); | |
| 29 | let pins: Pinned[] = []; | |
| 30 | let shown = false; | |
| 31 | const read = async (): Promise<void> => { | |
| 32 | const listed = await listPinned(f.app, f.user); | |
| 33 | pins = listed.ok ? listed.value : []; | |
| 34 | shown = listed.ok; | |
| 35 | state.clamp(pins.length); | |
| 36 | ctx.invalidate(); | |
| 37 | }; | |
| 38 | const act = (by?: -1 | 1): void => { | |
| 39 | const p = pins[state.index]; | |
| 40 | if (p === undefined) return; | |
| 41 | runAsync(ctx, async () => { | |
| 42 | const done = by === undefined ? unpinPanel(f.app, f.user, p.slug, p.title) : movePinned(f.app, f.user, p.slug, p.title, by); | |
| 43 | ctx.toast(done.ok ? (by === undefined ? "unpinned" : "moved on home") : said(done.error), done.ok ? "success" : "danger"); | |
| 44 | await read(); | |
| 45 | if (done.ok && by !== undefined) { | |
| 46 | const at = pins.findIndex((x) => x.slug === p.slug && x.title === p.title); | |
| 47 | if (at >= 0) state.index = at; | |
| 48 | } | |
| 49 | }); | |
| 50 | }; | |
| 51 | return { | |
| 52 | title: "Pinned panels", | |
| 53 | keys: [binding(["j", "k"], "move cursor"), binding(["<", ">"], "move on home"), binding(["x"], "unpin")], | |
| 54 | load: () => read(), | |
| 55 | render(area, s) { | |
| 56 | const c = ctx.theme.c; | |
| 57 | const [head, list] = split(area, "v", [len(1), fill(1)]); | |
| 58 | const text = !shown ? "Pinned panels are a forge admin's." : pins.length === 0 ? "Nothing pinned. Press p on a panel in Boards to pin it to home." : `${pins.length} on home, in this order`; | |
| 59 | s.text(head!.x, head!.y, truncate(text, head!.w), style(c.mutedFg, c.bg), head!.x + head!.w); | |
| 60 | drawList(s, list!, c, state, pinRows(pins)); | |
| 61 | }, | |
| 62 | key(e) { | |
| 63 | if (state.key(e, pins.length)) return true; | |
| 64 | if (e.ctrl || e.alt || !shown) return false; | |
| 65 | if (e.key === "x") act(); | |
| 66 | else if (e.key === "<") act(-1); | |
| 67 | else if (e.key === ">") act(1); | |
| 68 | else return false; | |
| 69 | return true; | |
| 70 | }, | |
| 71 | }; | |
| 72 | } | |
| 73 | ||
| 74 | /** The pinned panels, gated as `listPinned` gates them: a site admin who is a person, never an agent. */ | |
| 75 | export const entry: PaletteEntry = { | |
| 76 | id: "panelpins", | |
| 77 | title: "Pinned panels", | |
| 78 | hint: "the panels on your web home: unpin and reorder", | |
| 79 | after: ["boards"], | |
| 80 | offered: (session) => session.user?.isAdmin === true && session.user.kind !== "agent", | |
| 81 | run: (session, ctx) => ctx.push(panelPinsScreen(session, ctx)), | |
| 82 | }; |
test/palette-roster.test.ts +1
| @@ -72,6 +72,7 @@ test("a site-admin person is offered the whole roster", () => { | ||
| 72 | 72 | ["signins", "Signed in", "your browsers and tokens; d signs a browser out"], |
| 73 | 73 | ["sentinel", "Sentinel", "the forge's open faults"], |
| 74 | 74 | ["boards", "Boards", "the forge's boards and their panels"], |
| 75 | ["panelpins", "Pinned panels", "the panels on your web home: unpin and reorder"], | |
| 75 | 76 | ["origin-apps", "Origin apps", "your OAuth apps for connecting origins; a adds, d removes"], |
| 76 | 77 | ["system-memory", "System memory", "RSS beside the JS heap, hourly for 24 h"], |
| 77 | 78 | ["flow", "Flow", "the pipeline's bottleneck and throughput"], |
test/tui-boards.test.ts +60 −1
| @@ -3,7 +3,7 @@ | ||
| 3 | 3 | * a forge admin who is a person lists boards and reads their panels as text, |
| 4 | 4 | * and an agent, a member or a guest has neither the door nor the rows. |
| 5 | 5 | */ |
| 6 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 6 | import { afterAll, afterEach, beforeAll, describe, expect, test } from "bun:test"; | |
| 7 | 7 | import { mkdtemp, rm } from "node:fs/promises"; |
| 8 | 8 | import { tmpdir } from "node:os"; |
| 9 | 9 | import { join } from "node:path"; |
| @@ -11,10 +11,12 @@ import { listPinned, pinPanel, unpinPanel } from "../src/actions/board-pins.ts"; | ||
| 11 | 11 | import { deleteBoard, listAllBoards, writeBoard } from "../src/actions/boards.ts"; |
| 12 | 12 | import { createAgent } from "../src/actions/crew.ts"; |
| 13 | 13 | import { createApp, type App } from "../src/app.ts"; |
| 14 | import { recall, remember } from "../src/core/region_memory.ts"; | |
| 14 | 15 | import { createUser, type User } from "../src/core/users.ts"; |
| 15 | 16 | import { createForgeApp, forgeCommands, Session } from "../src/tui/forge.ts"; |
| 16 | 17 | import { dashboardScreen } from "../src/tui/screens/dashboard.ts"; |
| 17 | 18 | import { boardRows, boardsScreen, dataLine, refusal, stepWords } from "../src/tui/screens/boards.ts"; |
| 19 | import { panelPinsScreen } from "../src/tui/screens/panelpins.ts"; | |
| 18 | 20 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; |
| 19 | 21 | import { quietLogs } from "./helpers/globals.ts"; |
| 20 | 22 | import { settleApp } from "./helpers/tui.ts"; |
| @@ -235,3 +237,60 @@ describe("tui boards", () => { | ||
| 235 | 237 | expect(refusal({ refused: "bad\u001b[2J" })).toBe("That was refused: bad [2J."); |
| 236 | 238 | }); |
| 237 | 239 | }); |
| 240 | ||
| 241 | describe("tui pinned panels screen", () => { | |
| 242 | const view = async (user: User | undefined, keys = "") => { | |
| 243 | const terminal = headlessTerminal(120, 30); | |
| 244 | const { app: tui, session } = createForgeApp(app, identity(user), { terminal, exitHooks: false }); | |
| 245 | tui.start(); | |
| 246 | tui.ctx.push(panelPinsScreen(session, tui.ctx)); | |
| 247 | await settleApp(tui); | |
| 248 | for (const key of keys) { | |
| 249 | terminal.feed(key); | |
| 250 | await settleApp(tui); | |
| 251 | } | |
| 252 | const text = tui.screen.toText(); | |
| 253 | tui.stop?.(); | |
| 254 | return text; | |
| 255 | }; | |
| 256 | const order = async () => { | |
| 257 | const listed = await listPinned(app, carol); | |
| 258 | return listed.ok ? listed.value.map((p) => p.title) : []; | |
| 259 | }; | |
| 260 | afterEach(() => { | |
| 261 | for (const title of ["Failed runs", "Slow runs"]) unpinPanel(app, carol, "runs", title); | |
| 262 | }); | |
| 263 | ||
| 264 | test("lists pins in home order, < > move the one under the cursor, x unpins it", async () => { | |
| 265 | await pinPanel(app, carol, "runs", "Failed runs"); | |
| 266 | await pinPanel(app, carol, "runs", "Slow runs"); | |
| 267 | const text = await view(carol); | |
| 268 | expect(text).toContain("Failed runs"); | |
| 269 | expect(text).toContain("Slow runs"); | |
| 270 | await view(carol, ">"); | |
| 271 | expect(await order()).toEqual(["Slow runs", "Failed runs"]); | |
| 272 | await view(carol, "x"); | |
| 273 | expect(await order()).toEqual(["Failed runs"]); | |
| 274 | }); | |
| 275 | ||
| 276 | test("a write from the terminal drops what the web home remembered, as the web form's does", async () => { | |
| 277 | await pinPanel(app, carol, "runs", "Failed runs"); | |
| 278 | await pinPanel(app, carol, "runs", "Slow runs"); | |
| 279 | for (const key of [">", "x"]) { | |
| 280 | remember(app.db, carol.id, "panels", "home", "<p>old</p>", undefined, "a"); | |
| 281 | expect(recall(app.db, carol.id, "panels", "home", "a")).toBeDefined(); | |
| 282 | await view(carol, key); | |
| 283 | expect(recall(app.db, carol.id, "panels", "home", "a")).toBeUndefined(); | |
| 284 | } | |
| 285 | }); | |
| 286 | ||
| 287 | test("nobody else has the door or the rows", async () => { | |
| 288 | await pinPanel(app, carol, "runs", "Failed runs"); | |
| 289 | for (const who of [bob, bot, undefined]) { | |
| 290 | expect(doors(who)).not.toContain("panelpins"); | |
| 291 | expect(await view(who, "x")).not.toContain("Failed runs"); | |
| 292 | } | |
| 293 | expect(doors(carol)).toContain("panelpins"); | |
| 294 | expect(await order()).toEqual(["Failed runs"]); | |
| 295 | }); | |
| 296 | }); |
new above
offline