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

The cockpit: board and map as one screen, driven by four keys, readable from a TV, with nothing that needs you that a rule could answer #16844

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

torque/forge:torque/1152-the-cockpit-board-and-map-as-one-screen → main 0 commits fork 4 threads · 4 unresolved

  • Merged. torque/1152-the-cockpit-board-and-map-as-one-screen was merged into main as 2b7a2cb.

Review

Sign in to review this change.
19 files changed +910 −108
docs/design/areas/cockpit.md added +8
@@ -0,0 +1,8 @@
1 # Cockpit (one screen, four keys)
2
3 `/cockpit` (`src/web/pages/cockpit.ts`) adds no class: it is `[data-cockpit]` and the attributes inside it.
4 `[data-section]` is a region (today, needs, waves), `[data-item]` one row of one: a card or a wave, focusable
5 (`tabindex`), with a 6px outline for 3 m and large type (`clamp`, up to 2rem). A row is plain space with a hairline under it, never a box; there is no colour of its own: a card that needs you is
6 semibold, and the only accent is the interaction (focus, buttons). `[data-label]` is a muted line, not a heading: the
7 page's one h1 is its sentence. `[data-acts]` holds its buttons: the ordinary `.btn`, taller. `[data-kiosk]` is the same
8 screen under a bare page (no top bar, dark theme).
docs/design/audit.md +1
@@ -55,6 +55,7 @@ Machine routes are not pages and have no entry: `/audit.csv`,
5555 - `/templates` — `pages/templates.ts` · the templates a new forge starts from, one button each to New forge with it chosen, public · `/forges/new` · none seen.
5656 - `/terms` — `pages/terms.ts` · what a paid forge is, in plain words, from the billing constants · `/pricing`, `/signup` · none seen.
5757 - `/explore` — `studio/explore.ts` · browse what the forge holds · `/search`, `/apps` · colours 2.
58 - `/cockpit` — `pages/cockpit.ts` · board and map as one screen: Today lines, what needs me (five cards at most), waves toward milestones; four keys, readable at 3 m, `?kiosk=1` · `/board`, `/asks`, `/` · colours 4 (one per meaning), sizes 3. Styles in `docs/design/areas/cockpit.md`.
5859 - `/board` — `pages/board.ts` (1,231 lines) · every app the viewer can see, with a wall mode · `/boards` (saved queries as panels), `/flow`, `/` · colour 1, sizes 6.
5960 - `/home` — `pages/home_flow.ts` (`homeRedirect`) · an old address: goes to `/`, keeping the view and the filters · `/` · none seen.
6061 - `/board/returns` — `pages/returns.ts` · what the window's dollars bought · `/settings/subscriptions` spend tables, `/settings/usage` · none seen.
docs/features/cockpit.md added +24
@@ -0,0 +1,24 @@
1 ---
2 topic: Tell the crew
3 row: The cockpit, one screen with four keys
4 ---
5 # The cockpit
6
7 One screen for a TV, a Pi with four buttons or a phone's thumb (#1152): `/cockpit`, and `/board?kiosk=1` for a
8 screen nobody types at. In the terminal it is the palette's **Cockpit** (`src/tui/screens/cockpit.ts`).
9
10 - Top: what happened since you last looked (the Today lines).
11 - Middle: what needs you, at most five cards, one sentence each, at most three actions. A proposed plan says
12 **Yes** or **Later** with one press, and a stuck hand-over says **Let the decider**; every other card opens where it is answered. A repository you muted has no card.
13 - Bottom: the waves toward milestones, one row each: what landed, what is left.
14
15 Four keys: up and down move the focus, Enter takes the first action, back (Escape, Backspace or left) goes up a
16 level (item, section, front page). `j` and `k` also move.
17 In the terminal, `j`/`k` move, Enter does the first action itself (Yes, Let the decider; a link opens on the web),
18 `l` puts a plan aside, `o` opens the item on the web, `r` reads again. The page re-reads when something moves; the focus stays.
19
20 The kiosk (`?kiosk=1`) hides the top bar, uses the dark theme, and leaves out a card that wants typed words
21 (what to try, how to answer the planner), because four keys cannot answer it.
22
23 MCP: `asks` with `{ cockpit: true }` answers `{ today, sentence, cards, more, waves }`, the page's own words in the
24 page's own order (`src/web/studio/cockpit.ts`). There is no colour: state is in the words and the weight.
forge.json +2 −2
@@ -25,8 +25,8 @@
2525 { "name": "heartbeat", "cron": "5 7 * * *", "timezone": "UTC", "path": "/jobs/heartbeat", "timeout": 120, "retries": 3, "catchUp": "6h" }
2626 ],
2727 "app": {
28 "looks": ["/", "/docs", "/explore", "/board", "/notes", "/review", "/changelog", "/apps", "/security", "/system", "/admin/limits", "/maintenance", "/talk", "/flow", "/resilience", "/boards?help", "/settings/crew", "/settings/crew?help", "/settings/captain", "/settings/security/controls", "/settings/grants", "/preview-admin/sample", "/preview-admin/sample/drop", "/preview-admin/sample/data-move", "/preview-admin/sample/cut-over", "/preview-admin/sample/pulls/3", "/preview-admin/sample/next?pick", "/preview-admin/sample/bets", "/preview-admin/sample/waves", "/preview-admin/sample/space", "/looks/missing", "/looks/failed"],
29 "looksAsOwner": ["/", "/board", "/flow", "/boards?help", "/settings/crew", "/settings/crew?help", "/settings/captain", "/settings/security/controls", "/settings/grants", "/talk", "/system", "/admin/limits", "/maintenance", "/resilience", "/preview-admin/sample", "/preview-admin/sample/drop", "/preview-admin/sample/data-move", "/preview-admin/sample/cut-over", "/preview-admin/sample/pulls/3", "/preview-admin/sample/next?pick", "/preview-admin/sample/bets", "/preview-admin/sample/waves", "/preview-admin/sample/space"],
28 "looks": ["/", "/docs", "/explore", "/board", "/cockpit", "/notes", "/review", "/changelog", "/apps", "/security", "/system", "/admin/limits", "/maintenance", "/talk", "/flow", "/resilience", "/boards?help", "/settings/crew", "/settings/crew?help", "/settings/captain", "/settings/security/controls", "/settings/grants", "/preview-admin/sample", "/preview-admin/sample/drop", "/preview-admin/sample/data-move", "/preview-admin/sample/cut-over", "/preview-admin/sample/pulls/3", "/preview-admin/sample/next?pick", "/preview-admin/sample/bets", "/preview-admin/sample/waves", "/looks/missing", "/looks/failed"],
29 "looksAsOwner": ["/", "/board", "/cockpit", "/flow", "/boards?help", "/settings/crew", "/settings/crew?help", "/settings/captain", "/settings/security/controls", "/settings/grants", "/talk", "/system", "/admin/limits", "/maintenance", "/resilience", "/preview-admin/sample", "/preview-admin/sample/drop", "/preview-admin/sample/data-move", "/preview-admin/sample/cut-over", "/preview-admin/sample/pulls/3", "/preview-admin/sample/next?pick", "/preview-admin/sample/bets", "/preview-admin/sample/waves"],
3030 "run": "bun run src/main.ts",
3131 "install": "",
3232 "health": "/healthz",
src/core/reserved.ts +1
@@ -77,6 +77,7 @@ export const SYSTEM_NAMES: readonly string[] = [
7777 "desk",
7878 "boards",
7979 "broker",
80 "cockpit",
8081 "contribute",
8182 "csp-report",
8283 "deploy-to",
src/generated/marks.ts +105 −103
@@ -95,109 +95,110 @@ import k90 from "../http/marks/changelog.atom.json";
9595 import k91 from "../http/marks/changelog.json";
9696 import k92 from "../http/marks/claim.json";
9797 import k93 from "../http/marks/cloud.json";
98 import k94 from "../http/marks/contract.json";
99 import k95 from "../http/marks/contribute.json";
100 import k96 from "../http/marks/csp-report.json";
101 import k97 from "../http/marks/dash.json";
102 import k98 from "../http/marks/data.json";
103 import k99 from "../http/marks/dataset.json";
104 import k100 from "../http/marks/deploy-to.json";
105 import k101 from "../http/marks/design.json";
106 import k102 from "../http/marks/desk.json";
107 import k103 from "../http/marks/displays.json";
108 import k104 from "../http/marks/docs.json";
109 import k105 from "../http/marks/edge.json";
110 import k106 from "../http/marks/edition.json";
111 import k107 from "../http/marks/events.json";
112 import k108 from "../http/marks/explore.atom.json";
113 import k109 from "../http/marks/explore.json";
114 import k110 from "../http/marks/explore.json.json";
115 import k111 from "../http/marks/family.json";
116 import k112 from "../http/marks/favicon.ico.json";
117 import k113 from "../http/marks/feed.json";
118 import k114 from "../http/marks/feed.json.json";
119 import k115 from "../http/marks/first-admin.json";
120 import k116 from "../http/marks/fleet.json";
121 import k117 from "../http/marks/flow.json";
122 import k118 from "../http/marks/forge.json";
123 import k119 from "../http/marks/forges.json";
124 import k120 from "../http/marks/front.json";
125 import k121 from "../http/marks/funnel.json";
126 import k122 from "../http/marks/games.json";
127 import k123 from "../http/marks/go.json";
128 import k124 from "../http/marks/health.json";
129 import k125 from "../http/marks/home.json";
130 import k126 from "../http/marks/hooks.json";
131 import k127 from "../http/marks/icons.json";
132 import k128 from "../http/marks/infra.json";
133 import k129 from "../http/marks/join.json";
134 import k130 from "../http/marks/live.json";
135 import k131 from "../http/marks/llms-full.txt.json";
136 import k132 from "../http/marks/llms.txt.json";
137 import k133 from "../http/marks/login.json";
138 import k134 from "../http/marks/logout.json";
139 import k135 from "../http/marks/maintenance-json.json";
140 import k136 from "../http/marks/maintenance.json";
141 import k137 from "../http/marks/manifest.webmanifest.json";
142 import k138 from "../http/marks/map.json";
143 import k139 from "../http/marks/mcp.json";
144 import k140 from "../http/marks/measure.json";
145 import k141 from "../http/marks/metrics.json";
146 import k142 from "../http/marks/migrate.json";
147 import k143 from "../http/marks/new.json";
148 import k144 from "../http/marks/next.json";
149 import k145 from "../http/marks/notes.json";
150 import k146 from "../http/marks/now.json";
151 import k147 from "../http/marks/oauth.json";
152 import k148 from "../http/marks/oembed.json";
153 import k149 from "../http/marks/offers.json";
154 import k150 from "../http/marks/offline.json";
155 import k151 from "../http/marks/og.json";
156 import k152 from "../http/marks/openapi.json.json";
157 import k153 from "../http/marks/opensearch.xml.json";
158 import k154 from "../http/marks/organizations.json";
159 import k155 from "../http/marks/origins.json";
160 import k156 from "../http/marks/owner.atom.json";
161 import k157 from "../http/marks/owner.json";
162 import k158 from "../http/marks/packs.json";
163 import k159 from "../http/marks/peek.json";
164 import k160 from "../http/marks/pinned.json";
165 import k161 from "../http/marks/pipeline.json";
166 import k162 from "../http/marks/plugins.json";
167 import k163 from "../http/marks/pricing.json";
168 import k164 from "../http/marks/privacy.json";
169 import k165 from "../http/marks/r.json";
170 import k166 from "../http/marks/recover.json";
171 import k167 from "../http/marks/releases.json";
172 import k168 from "../http/marks/releases.json.json";
173 import k169 from "../http/marks/repos.json";
174 import k170 from "../http/marks/resilience.json";
175 import k171 from "../http/marks/review.json";
176 import k172 from "../http/marks/robots.txt.json";
177 import k173 from "../http/marks/root.json";
178 import k174 from "../http/marks/runs.json";
179 import k175 from "../http/marks/script-error.json";
180 import k176 from "../http/marks/search.json";
181 import k177 from "../http/marks/security.json";
182 import k178 from "../http/marks/settings.json";
183 import k179 from "../http/marks/sign-in.json";
184 import k180 from "../http/marks/signin.json";
185 import k181 from "../http/marks/signup.json";
186 import k182 from "../http/marks/sitemap.xml.json";
187 import k183 from "../http/marks/status.json";
188 import k184 from "../http/marks/sw.js.json";
189 import k185 from "../http/marks/system.json";
190 import k186 from "../http/marks/talk.json";
191 import k187 from "../http/marks/tell.json";
192 import k188 from "../http/marks/templates.json";
193 import k189 from "../http/marks/templates.json.json";
194 import k190 from "../http/marks/terms.json";
195 import k191 from "../http/marks/theme.json";
196 import k192 from "../http/marks/toolbar-lab.js.json";
197 import k193 from "../http/marks/toolbar-lab.json";
198 import k194 from "../http/marks/verify.json";
199 import k195 from "../http/marks/welcome.json";
200 import k196 from "../http/marks/well-known.json";
98 import k94 from "../http/marks/cockpit.json";
99 import k95 from "../http/marks/contract.json";
100 import k96 from "../http/marks/contribute.json";
101 import k97 from "../http/marks/csp-report.json";
102 import k98 from "../http/marks/dash.json";
103 import k99 from "../http/marks/data.json";
104 import k100 from "../http/marks/dataset.json";
105 import k101 from "../http/marks/deploy-to.json";
106 import k102 from "../http/marks/design.json";
107 import k103 from "../http/marks/desk.json";
108 import k104 from "../http/marks/displays.json";
109 import k105 from "../http/marks/docs.json";
110 import k106 from "../http/marks/edge.json";
111 import k107 from "../http/marks/edition.json";
112 import k108 from "../http/marks/events.json";
113 import k109 from "../http/marks/explore.atom.json";
114 import k110 from "../http/marks/explore.json";
115 import k111 from "../http/marks/explore.json.json";
116 import k112 from "../http/marks/family.json";
117 import k113 from "../http/marks/favicon.ico.json";
118 import k114 from "../http/marks/feed.json";
119 import k115 from "../http/marks/feed.json.json";
120 import k116 from "../http/marks/first-admin.json";
121 import k117 from "../http/marks/fleet.json";
122 import k118 from "../http/marks/flow.json";
123 import k119 from "../http/marks/forge.json";
124 import k120 from "../http/marks/forges.json";
125 import k121 from "../http/marks/front.json";
126 import k122 from "../http/marks/funnel.json";
127 import k123 from "../http/marks/games.json";
128 import k124 from "../http/marks/go.json";
129 import k125 from "../http/marks/health.json";
130 import k126 from "../http/marks/home.json";
131 import k127 from "../http/marks/hooks.json";
132 import k128 from "../http/marks/icons.json";
133 import k129 from "../http/marks/infra.json";
134 import k130 from "../http/marks/join.json";
135 import k131 from "../http/marks/live.json";
136 import k132 from "../http/marks/llms-full.txt.json";
137 import k133 from "../http/marks/llms.txt.json";
138 import k134 from "../http/marks/login.json";
139 import k135 from "../http/marks/logout.json";
140 import k136 from "../http/marks/maintenance-json.json";
141 import k137 from "../http/marks/maintenance.json";
142 import k138 from "../http/marks/manifest.webmanifest.json";
143 import k139 from "../http/marks/map.json";
144 import k140 from "../http/marks/mcp.json";
145 import k141 from "../http/marks/measure.json";
146 import k142 from "../http/marks/metrics.json";
147 import k143 from "../http/marks/migrate.json";
148 import k144 from "../http/marks/new.json";
149 import k145 from "../http/marks/next.json";
150 import k146 from "../http/marks/notes.json";
151 import k147 from "../http/marks/now.json";
152 import k148 from "../http/marks/oauth.json";
153 import k149 from "../http/marks/oembed.json";
154 import k150 from "../http/marks/offers.json";
155 import k151 from "../http/marks/offline.json";
156 import k152 from "../http/marks/og.json";
157 import k153 from "../http/marks/openapi.json.json";
158 import k154 from "../http/marks/opensearch.xml.json";
159 import k155 from "../http/marks/organizations.json";
160 import k156 from "../http/marks/origins.json";
161 import k157 from "../http/marks/owner.atom.json";
162 import k158 from "../http/marks/owner.json";
163 import k159 from "../http/marks/packs.json";
164 import k160 from "../http/marks/peek.json";
165 import k161 from "../http/marks/pinned.json";
166 import k162 from "../http/marks/pipeline.json";
167 import k163 from "../http/marks/plugins.json";
168 import k164 from "../http/marks/pricing.json";
169 import k165 from "../http/marks/privacy.json";
170 import k166 from "../http/marks/r.json";
171 import k167 from "../http/marks/recover.json";
172 import k168 from "../http/marks/releases.json";
173 import k169 from "../http/marks/releases.json.json";
174 import k170 from "../http/marks/repos.json";
175 import k171 from "../http/marks/resilience.json";
176 import k172 from "../http/marks/review.json";
177 import k173 from "../http/marks/robots.txt.json";
178 import k174 from "../http/marks/root.json";
179 import k175 from "../http/marks/runs.json";
180 import k176 from "../http/marks/script-error.json";
181 import k177 from "../http/marks/search.json";
182 import k178 from "../http/marks/security.json";
183 import k179 from "../http/marks/settings.json";
184 import k180 from "../http/marks/sign-in.json";
185 import k181 from "../http/marks/signin.json";
186 import k182 from "../http/marks/signup.json";
187 import k183 from "../http/marks/sitemap.xml.json";
188 import k184 from "../http/marks/status.json";
189 import k185 from "../http/marks/sw.js.json";
190 import k186 from "../http/marks/system.json";
191 import k187 from "../http/marks/talk.json";
192 import k188 from "../http/marks/tell.json";
193 import k189 from "../http/marks/templates.json";
194 import k190 from "../http/marks/templates.json.json";
195 import k191 from "../http/marks/terms.json";
196 import k192 from "../http/marks/theme.json";
197 import k193 from "../http/marks/toolbar-lab.js.json";
198 import k194 from "../http/marks/toolbar-lab.json";
199 import k195 from "../http/marks/verify.json";
200 import k196 from "../http/marks/welcome.json";
201 import k197 from "../http/marks/well-known.json";
201202
202203 /** Each file of `http/marks/`, parsed, in name order. */
203204 export const MARK_FILES: readonly unknown[] = [
@@ -398,4 +399,5 @@ export const MARK_FILES: readonly unknown[] = [
398399 k194,
399400 k195,
400401 k196,
402 k197,
401403 ];
src/http/marks/cockpit.json added +4
@@ -0,0 +1,4 @@
1 {
2 "head": "/cockpit",
3 "mark": "open"
4 }
src/http/mcp/tools/asks.ts +6 −2
@@ -1,12 +1,13 @@
11 import { applyAskFilter, ASK_FILTER_DOS, isAskFilterDo, type AskFilterChange } from "../../../actions/ask_filter.ts";
22 import { ASK_KINDS, HIDE_APP_DAY_WORDS, HIDE_KIND_WORDS, isAskKind, SHOW_ALL_WORDS } from "../../../core/ask_filters.ts";
3 import { cockpitFor } from "../../../web/studio/cockpit.ts";
34 import { asksAnswer } from "../../../web/studio/asks.ts";
45 import { good, bad, type Tool, CHIP_ARGS, chipArgs, APP_ARG, repoArg, isAnswer } from "../shared.ts";
56
67 export const tool: Tool = {
78 name: "asks",
89 description:
9 "What waits on you, most important first; saved filter applies; `filter` sets or clears one",
10 "What waits on you, most important first; saved filter applies; `filter` sets or clears one; `cockpit`: the TV screen",
1011 inputSchema: {
1112 type: "object",
1213 properties: {
@@ -14,13 +15,16 @@ export const tool: Tool = {
1415 filter: { type: "string", enum: [...ASK_FILTER_DOS] },
1516 app: APP_ARG,
1617 kind: { type: "string", enum: [...ASK_KINDS] },
18 cockpit: { type: "boolean" },
1719 },
1820 },
1921 doc:
20 `\`{ hide_kinds?, hide_people?, filter?, app?, kind? }\`: what waits on you, most important first; your saved filter applies unless a chip argument overrides it. \`filter\` (\`hide_app_day\` is "${HIDE_APP_DAY_WORDS}", \`hide_app\`, \`show_app\` with \`app\`; \`hide_kind\` is "${HIDE_KIND_WORDS}", \`show_kind\` with \`kind\`; \`clear\` is "${SHOW_ALL_WORDS}") sets your ask filters, the same as the page and terminal: nothing hidden is lost, a hide for a day ends by itself, a security ask always shows; the answer says how many are hidden`,
22 `\`{ hide_kinds?, hide_people?, filter?, app?, kind?, cockpit? }\`: with \`cockpit: true\`, the cockpit screen as \`{ today, sentence, cards, more, waves }\` in the page's own words and order (never the filters). what waits on you, most important first; your saved filter applies unless a chip argument overrides it. \`filter\` (\`hide_app_day\` is "${HIDE_APP_DAY_WORDS}", \`hide_app\`, \`show_app\` with \`app\`; \`hide_kind\` is "${HIDE_KIND_WORDS}", \`show_kind\` with \`kind\`; \`clear\` is "${SHOW_ALL_WORDS}") sets your ask filters, the same as the page and terminal: nothing hidden is lost, a hide for a day ends by itself, a security ask always shows; the answer says how many are hidden`,
2123 writes: true,
2224 readsWithout: "filter",
2325 run(ctx, user, args) {
26 // The cockpit screen's own object, so the car hears what the TV shows (#1152).
27 if (args["cockpit"] === true) return good(cockpitFor(ctx.app, user));
2428 const chips = chipArgs(ctx, args);
2529 if (chips && "error" in chips) return bad("invalid", chips.error);
2630 const db = ctx.app.db;
src/http/server.ts +3
@@ -5,6 +5,7 @@
55 * verdict. Auth is resolved once per request and handed to handlers as data.
66 */
77
8 import { cockpitPage } from "../web/pages/cockpit.ts";
89 import { registryItem } from "../registry/serve.ts";
910 import { forgeTemplateUpdate } from "../web/pages/forge-template-setting.ts";
1011 import { gamesRoutes } from "./games_routes.ts";
@@ -1071,6 +1072,8 @@ export function buildRouter(): Router<Handler> {
10711072 router.add("POST", "/theme", themeSubmit);
10721073 // The board: a live wall of the crews at work, for a second monitor.
10731074 router.add("GET", "/board", boardPage);
1075 // One screen, four keys (#1152); `/board?kiosk=1` lands here too.
1076 router.add("GET", "/cockpit", (ctx) => cockpitPage(ctx));
10741077 // The board's tokens line, opened: what the spend bought (core/returns.ts).
10751078 router.add("GET", "/board/returns", returnsPage);
10761079 // One screen for "is everything fine?": what asks the viewer (docs/STUDIO.md).
src/tui/forge.ts +9
@@ -61,6 +61,7 @@ import {
6161 } from "./screens/common.ts";
6262 import { chainScreen } from "./screens/chain.ts";
6363 import { canSeeMemory } from "../boards/memory.ts";
64 import { cockpitScreen } from "./screens/cockpit.ts";
6465 import { notesScreen } from "./screens/thoughtnotes.ts";
6566 import { deciderScreen } from "./screens/decider.ts";
6667 import { familyScreen, withForkCount } from "./screens/family.ts";
@@ -436,6 +437,14 @@ export function forgeCommands(session: Session): (ctx: Ctx) => Command[] {
436437 hint: "spawn a client's forge and get its claim link",
437438 run: () => ctx.push(newForgeScreen(session, ctx)),
438439 });
440 // One screen, four keys: what happened, what needs you, the waves (#1152).
441 if (session.signedIn)
442 commands.push({
443 id: "cockpit",
444 title: "Cockpit",
445 hint: "what needs you, what happened, the waves under way",
446 run: () => ctx.push(cockpitScreen(session, ctx)),
447 });
439448 // One box to write an idea in, each note with its live state; /notes' own door (#8696).
440449 if (session.signedIn)
441450 commands.push({
src/tui/screens/cockpit.ts added +107
@@ -0,0 +1,107 @@
1 /**
2 * The cockpit in the terminal (#1152): the web page's own object (`web/studio/cockpit.ts`), so the
3 * words and the order are the page's and MCP's. One list, in the order it is read: what happened,
4 * what needs you, the waves. `j`/`k` or the arrows move, `enter` does the item's first action
5 * (Yes on a plan, Let the decider on a stuck hand-over, through the same actions the /asks routes
6 * call; a link opens on the web), `l` puts a plan aside, `o` opens the item on the web, `r` reads
7 * again.
8 */
9
10 import { actOnProposal } from "../../actions/proposals.ts";
11 import { decideAsk } from "../../actions/asks_decide.ts";
12 import { cockpitFor, type Cockpit, type CockpitAction } from "../../web/studio/cockpit.ts";
13 import type { Ctx, Screen } from "../app/app.ts";
14 import { binding } from "../app/keys.ts";
15 import type { Session } from "../session.ts";
16 import { style } from "../term/style.ts";
17 import { truncate } from "../term/width.ts";
18 import { fill, len, split } from "../ui/layout.ts";
19 import { ListState, drawList, hitList, openOnWeb, runAsync, type ListRow } from "./common.ts";
20
21 export interface CockpitLine extends ListRow {
22 /** The web path `enter` opens. */
23 readonly path: string;
24 /** What a card can do, first is `enter`. */
25 readonly acts: readonly CockpitAction[];
26 }
27
28 /** The cockpit's items as lines, in the page's order. */
29 export function cockpitLines(c: Cockpit): CockpitLine[] {
30 return [
31 ...(c.today?.lines ?? []).map((l): CockpitLine => ({ title: l.says, path: l.href, acts: [] })),
32 ...c.cards.map((x): CockpitLine => ({
33 title: x.says,
34 tone: "attn",
35 meta: x.actions.map((a) => a.word).join(" · "),
36 acts: x.actions,
37 path: x.actions[0]?.method === "get" ? x.actions[0].href : "/cockpit",
38 })),
39 ...c.waves.map((w): CockpitLine => ({ title: `${w.name}: ${w.says}`, ...(w.tone === "done" ? { tone: "success" as const } : {}), path: w.href, acts: [] })),
40 ];
41 }
42
43 export function cockpitScreen(f: Session, ctx: Ctx): Screen {
44 const state = new ListState();
45 let cockpit: Cockpit | undefined;
46 let lines: CockpitLine[] = [];
47 const read = (): void => {
48 if (f.user === undefined) return;
outdated

The terminal can only open the web here. Yes, Later and Let the decider must be done in the terminal as on the page.

49 cockpit = cockpitFor(f.app, f.user);
50 lines = cockpitLines(cockpit);
51 state.clamp(lines.length);
52 };
53 /**
54 * One action of the card under the cursor: a post through the action the web calls, a link on the
55 * web.
56 */
57 const act = (a: CockpitAction | undefined, line: CockpitLine): void => {
58 if (a === undefined || a.method === "get" || a.does === undefined) return openOnWeb(f, ctx, a?.method === "get" ? a.href : line.path, "That");
59 const does = a.does;
60 runAsync(ctx, async () => {
61 const done = "proposal" in does ? actOnProposal(f.app, f.user, does.verb, does.proposal) : await decideAsk(f.app, f.user, does.decide);
62 read();
63 ctx.invalidate();
64 ctx.toast(done.ok ? "Done." : done.error.message, done.ok ? "success" : "danger");
65 });
66 };
67 const open = (i: number): void => {
68 const line = lines[i];
69 if (line !== undefined) act(line.acts[0], line);
70 };
71 return {
72 title: "Cockpit",
73 keys: [binding(["j", "k"], "move"), binding(["enter"], "do"), binding(["l"], "later"), binding(["o"], "web"), binding(["r"], "refresh")],
74 load: async () => read(),
75 render(area, s) {
76 const c = ctx.theme.c;
77 const [head, body] = split(area, "v", [len(1), fill(1)]);
78 s.text(head!.x, head!.y, truncate(cockpit?.sentence ?? "Sign in to see it.", head!.w), style(c.mutedFg, c.bg), head!.x + head!.w);
79 drawList(s, body!, c, state, lines);
80 hitList(ctx, body!, state, lines.length, { open });
81 },
82 key(e) {
83 if (state.key(e, lines.length)) return true;
84 if (e.key === "enter") {
85 open(state.index);
86 return true;
87 }
88 if (e.key === "l" || e.key === "o") {
89 const line = lines[state.index];
90 if (line !== undefined) {
91 if (e.key === "o") openOnWeb(f, ctx, line.path, "That");
92 else {
93 const later = line.acts.find((a) => a.word === "Later");
94 if (later !== undefined) act(later, line);
95 }
96 }
97 return true;
98 }
99 if (e.key === "r") {
100 read();
101 ctx.invalidate();
102 return true;
103 }
104 return false;
105 },
106 };
107 }
src/web/cockpit_screen_keys.ts added +66
@@ -0,0 +1,66 @@
1 /**
2 * The cockpit's four keys (#1152), for a TV remote, a Pi with four buttons or a thumb: up and down
3 * move the focus through every item on the screen in the order it is read, Enter takes the focused
4 * item's first action, back (Escape, Backspace or left) goes up a level: from an item to its
5 * section, from a section to the front page. Items are `[data-item]`, sections `[data-section]`;
6 * an item's first action is its `[data-first]`. A page swapped by the live regions keeps the focus
7 * on the same `data-id`. Kept out of `client.ts`, which has a size ceiling of its own.
8 */
9 export const cockpitScreenKeysJs = /* js */ `
10 (function () {
11 var root = document.querySelector('[data-cockpit]');
12 if (!root) return;
13 var doc = document;
14 function items() { return Array.prototype.slice.call(root.querySelectorAll('[data-item]')); }
15 function sections() { return Array.prototype.slice.call(root.querySelectorAll('[data-section]')); }
16 function nav() { return Array.prototype.slice.call(root.querySelectorAll('[data-item], [data-section]')); }
17 function at() { var a = doc.activeElement; return a && root.contains(a) ? a.closest('[data-item], [data-section]') : null; }
18 function put(el) { if (el) { el.focus({ preventScroll: true }); el.scrollIntoView({ block: 'center' }); } }
19 var remembered = null;
20 function move(step) {
21 var all = items();
22 if (all.length === 0) return;
23 var here = at();
24 if (here && here.hasAttribute('data-section')) {
25 var inside = here.querySelector('[data-item]');
26 put(step > 0 && inside ? inside : all[step > 0 ? 0 : all.length - 1]);
27 return;
28 }
29 var i = here ? all.indexOf(here) : -1;
30 put(all[Math.max(0, Math.min(all.length - 1, i < 0 ? (step > 0 ? 0 : all.length - 1) : i + step))]);
31 }
32 function enter() {
33 var here = at();
34 if (!here) { move(1); return; }
35 if (here.hasAttribute('data-section')) { move(1); return; }
36 var first = here.querySelector('[data-first]');
37 if (first) first.click();
38 }
39 function back() {
40 var here = at();
41 if (here && here.hasAttribute('data-item')) { put(here.closest('[data-section]')); return; }
42 if (here) { doc.activeElement.blur(); window.scrollTo(0, 0); return; }
43 location.assign('/');
44 }
45 doc.addEventListener('keydown', function (e) {
46 if (e.metaKey || e.ctrlKey || e.altKey || e.defaultPrevented) return;
47 var t = e.target;
48 if (t && t.closest && t.closest('dialog[open]')) return;
49 if (t && t.matches && t.matches('input, textarea, select, [contenteditable]')) return;
50 var k = e.key;
51 if (k === 'ArrowDown' || k === 'j') { e.preventDefault(); move(1); }
52 else if (k === 'ArrowUp' || k === 'k') { e.preventDefault(); move(-1); }
53 else if (k === 'Enter' && t && !t.closest('a, button')) { e.preventDefault(); enter(); }
54 else if (k === 'Escape' || k === 'Backspace' || k === 'ArrowLeft') { e.preventDefault(); back(); }
55 });
56 doc.addEventListener('focusin', function () { var h = at(); remembered = h ? h.getAttribute('data-id') : null; });
57 // A swapped region loses the focus with its old markup: put it back on the same item.
58 doc.addEventListener('forge:swapped', function () {
59 if (remembered === null) return;
60 var again = nav().filter(function (n) { return n.getAttribute('data-id') === remembered; })[0];
61 if (again && doc.activeElement !== again) again.focus({ preventScroll: true });
62 });
63 // The first thing on screen is focused, so a remote has somewhere to start.
64 if (sections().length > 0 && !at()) { var s = items()[0]; if (s) s.focus({ preventScroll: true }); }
65 })();
66 `;
src/web/pages/board.ts +3
@@ -18,6 +18,7 @@
1818 * pointer. The old big view (`/big`, every address it had) lands here.
1919 */
2020
21 import { cockpitPage } from "./cockpit.ts";
2122 import { weekCardRows } from "../../crew/week.ts";
2223 import { hoursSpan, readThroughput } from "../../flow/throughput.ts";
2324 import { usd } from "../../core/money.ts";
@@ -237,6 +238,8 @@ function boardScope(
237238
238239 /** GET /board — signed in; every app the viewer can see, or `?apps=` some; `?wall` for the wall mode. */
239240 export async function boardPage(ctx: Ctx): Promise<Response> {
241 // The kiosk is the cockpit (#1152): one screen, four keys, no top bar.
242 if (ctx.url.searchParams.has("kiosk")) return cockpitPage(ctx, true);
240243 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
241244 const user = ctx.auth.user;
242245 if (!user) return signInFirst(ctx);
src/web/pages/cockpit.ts added +107
@@ -0,0 +1,107 @@
1 /**
2 * The cockpit (#1152): one screen, readable from across a room and driven with four keys
3 * (`cockpit_screen_keys.ts`). Top, what happened since the person last looked; middle, what needs
4 * them, at most five cards; bottom, the waves toward milestones. Everything is read from
5 * `studio/cockpit.ts`, the object MCP's `asks` with `cockpit: true` returns, so the page and the
6 * car say the same words in the same order. `/cockpit`, and `/board?kiosk=1` for a screen nobody
7 * types at: the top bar goes, and a card that wants typed words is left out. Live: each region
8 * re-reads when a matching event lands (`liveRegionsJs`).
9 */
10
11 import type { Ctx } from "../../http/context.ts";
12 import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts";
13 import { signInFirst } from "../chrome.ts";
14 import { cockpitScreenKeysJs } from "../cockpit_screen_keys.ts";
15 import { liveRegionsJs } from "../client.ts";
16 import { html, type Html } from "../html.ts";
17 import { page } from "../layout.ts";
18 import { meter } from "../ui.ts";
19 import { cockpitFor, type Cockpit, type CockpitAction, type CockpitCard, type CockpitWave } from "../studio/cockpit.ts";
20
21 /** The events that can move a region. */
22 const LIVE = "run.*,issue.*,pull.*,release.*";
23
24 /** The page's path with its mode, so an action lands back on the same screen. */
25 const hereOf = (kiosk: boolean): string => (kiosk ? "/cockpit?kiosk=1" : "/cockpit");
26
27 /**
28 * The cockpit's own look: attribute selectors only, scoped to `[data-cockpit]`
29 * (docs/design/areas/cockpit.md).
30 */
31 export const cockpitCss = /* css */ `
32 @layer components {
33 [data-cockpit] { display: grid; gap: clamp(24px, 4vh, 48px); padding: clamp(16px, 3vw, 48px); font-size: clamp(1.25rem, 2.4vw, 2rem); line-height: 1.35; }
34 [data-cockpit] h1 { font-size: clamp(2rem, 4.5vw, 3.5rem); margin: 0; }
35 [data-cockpit] [data-section] { display: grid; align-content: start; }
36 [data-cockpit] [data-label] { margin: 0 0 8px; color: var(--muted-fg); }
37 [data-cockpit] [data-item] { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; padding-block: 16px; border-block-end: 1px solid var(--border); }
outdated

Principles 6 and 7: each item is a padded, rounded box with a thick border, which is a card. Use a plain row with space between rows.

38 [data-cockpit] [data-item] > :first-child { flex: 1 1 24ch; min-width: 0; overflow-wrap: anywhere; }
39 [data-cockpit] [data-item][data-tone="needs-you"] > :first-child { font-weight: 600; }
40 [data-cockpit] [data-item]:focus-visible, [data-cockpit] [data-section]:focus-visible { outline: var(--ring); outline-offset: var(--ring-offset); }
41 [data-cockpit] [data-acts] { display: flex; gap: 12px; margin: 0; }
outdated

Principle 5: --accent for state, plus --attn, --success and --danger on the lines below, makes four colours. Keep one accent, for interaction alone.

42 [data-cockpit] [data-acts] .btn { font-size: inherit; min-height: 56px; padding-inline: 24px; }
43 @media (forced-colors: active) { [data-cockpit] [data-item]:focus-visible, [data-cockpit] [data-section]:focus-visible { outline: 6px solid Highlight; } }
44 [data-cockpit] meter { width: 100%; height: 12px; }
45 }
46 `;
47
48 function action(a: CockpitAction, first: boolean, here: string): Html {
49 const mark = first ? html`data-first` : null;
50 if (a.method === "get") return html`<a class="btn" href="${a.href}" ${mark} data-variant="${first ? "primary" : "secondary"}">${a.word}</a>`;
51 return html`<form method="post" action="${a.href}" data-acts-form>
52 <input type="hidden" name="back" value="${here}" />${Object.entries(a.fields ?? {}).map(([k, v]) => html`<input type="hidden" name="${k}" value="${v}" />`)}
53 <button type="submit" class="btn" ${mark} data-variant="${first ? "primary" : "secondary"}">${a.word}</button>
54 </form>`;
55 }
56
57 function card(c: CockpitCard, here: string): Html {
58 return html`<article tabindex="0" data-item data-id="${c.id}" data-tone="${c.tone}">
59 <span>${c.says}</span>
60 <span data-acts>${c.actions.map((a, i) => action(a, i === 0, here))}</span>
61 </article>`;
62 }
63
64 function wave(w: CockpitWave): Html {
65 return html`<article tabindex="0" data-item data-id="wave-${w.href}">
66 <span><a href="${w.href}" data-first>${w.name}</a><br />${w.says}</span>
67 ${meter(w.percent, `${w.name}: share landed`)}
68 </article>`;
69 }
70
71 /** The three regions, from one read. */
72 export function cockpitBody(c: Cockpit, kiosk: boolean): Html {
73 const here = hereOf(kiosk);
74 return html`<div data-cockpit ${kiosk ? html`data-kiosk` : null}>
75 <h1 id="cockpit-sentence">${c.sentence}</h1>
76 <section id="cockpit-today" tabindex="-1" data-section data-id="today" data-live="${LIVE}" aria-label="What happened">
77 <p data-label>${c.today === null ? "Nothing new since you looked." : c.today.heading}</p>
78 ${(c.today?.lines ?? []).map((l) => html`<article tabindex="0" data-item data-id="today-${l.href}"><a href="${l.href}" data-first>${l.says}</a></article>`)}
79 </section>
80 <section id="cockpit-needs" tabindex="-1" data-section data-id="needs" data-live="${LIVE}" aria-label="Waiting for you">
81 ${c.cards.map((x) => card(x, here))}
82 ${c.more > 0 ? html`<p data-label>${c.more} more ${c.more === 1 ? "waits" : "wait"} behind these.</p>` : null}
83 </section>
84 <section id="cockpit-waves" tabindex="-1" data-section data-id="waves" data-live="${LIVE}" aria-label="Waves under way">
85 <p data-label>${c.waves.length === 0 ? "No waves under way." : "Waves under way"}</p>
86 ${c.waves.map(wave)}
87 </section>
88 </div>`;
89 }
90
91 // GET /cockpit and GET /board?kiosk=1 — signed in.
92 export function cockpitPage(ctx: Ctx, kioskMode = ctx.url.searchParams.has("kiosk")): Response {
93 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
94 const user = ctx.auth.user;
95 if (!user) return signInFirst(ctx);
96 const c = timePhase(ctx.request, "cockpit", () => cockpitFor(ctx.app, user, { kiosk: kioskMode }));
97 return timePhase(ctx.request, "render", () =>
98 page({
99 ctx,
100 title: "Cockpit",
101 body: cockpitBody(c, kioskMode),
102 scriptJs: `${liveRegionsJs}\n${cockpitScreenKeysJs}`,
103 styleCss: cockpitCss,
104 ...(kioskMode ? { bare: true, theme: "dark" as const } : {}),
105 }),
106 );
107 }
src/web/studio/cockpit.ts added +156
@@ -0,0 +1,156 @@
1 /**
2 * The cockpit's data (#1152), plain and in the order it is read: what happened since the person
3 * last looked (the Today lines, `feed/digest.ts`), what needs them as at most five cards of one
4 * sentence and at most three actions, and the waves toward milestones, one row each. The page
5 * (`pages/cockpit.ts`), the terminal screen and MCP's `asks` with `cockpit: true` all read this one
6 * object, so a TV and a car say the same words in the same order.
7 *
8 * Words: no jargon. A crew member is "the crew", a pull is "a change", a count is a sentence
9 * ("3 changes wait for you"). A repository the viewer muted never has a card (the asks'
10 * own read); in kiosk mode a card that wants typed words is left out, because four keys cannot
11 * answer it.
12 */
13
14 import type { App } from "../../app.ts";
15 import type { AskKind } from "../../core/ask_filters.ts";
16 import { biggestOf, landedPercent, landedWords } from "../../core/milestone_front.ts";
17 import type { User } from "../../core/users.ts";
18 import { feedDigest } from "./since.ts";
19 import { askLinesFor, writableAppsOf } from "./asks.ts";
20 import { milestoneHref, planFor } from "../pages/milestones.ts";
21 import { repoBase } from "../chrome.ts";
22
23 /** At most this many cards: more is a list, and a list is not a cockpit. */
24 export const MAX_CARDS = 5;
25 /** At most this many waves, the biggest first. */
26 export const MAX_WAVES = 5;
27
28 /**
29 * The kinds that ask for typed words (what to try, how to answer the planner): four keys cannot.
30 */
31 const TYPED: ReadonlySet<AskKind> = new Set(["stopped", "handover", "declined"]);
32
33 /** Whether four keys can answer a card of this kind. */
34 export const keysCanAnswer = (kind: AskKind): boolean => !TYPED.has(kind);
35
36 export interface CockpitAction {
37 /** What the button says: `Yes`, `Later` or `Open it`. */
38 readonly word: string;
39 /** A link to open, or a form to post. */
40 readonly method: "get" | "post";
41 readonly href: string;
42 /** The form's hidden fields, for a post. */
43 readonly fields?: Readonly<Record<string, string>>;
44 /** What a post does, for a door that makes it without a form (the terminal). */
45 readonly does?: { readonly proposal: string; readonly verb: "approve" | "later" } | { readonly decide: string };
46 }
47
48 export interface CockpitCard {
49 readonly id: string;
50 /** One sentence. */
51 readonly says: string;
52 /** The first one is what Enter takes. At most three. */
53 readonly actions: readonly CockpitAction[];
54 /** What it is, for the one colour: always "needs you" here. */
55 readonly tone: "needs-you";
56 }
57
58 export interface CockpitWave {
59 readonly name: string;
60 /** "12 of 20 landed, 8 to go". */
61 readonly says: string;
62 readonly percent: number;
63 readonly href: string;
64 readonly tone: "working" | "done" | "quiet";
65 }
66
67 export interface Cockpit {
68 /** "Since you were here · 2 days" and its lines; null when nothing happened. */
69 readonly today: { readonly heading: string; readonly lines: readonly { readonly says: string; readonly href: string }[] } | null;
70 /** The sentence over the cards: "3 things need you", or "Nothing needs you." */
71 readonly sentence: string;
72 readonly cards: readonly CockpitCard[];
73 /** How many more wait behind the cards. */
74 readonly more: number;
75 readonly waves: readonly CockpitWave[];
76 }
77
78 const plural = (n: number, one: string, many: string): string => (n === 1 ? one : many);
79
80 /** One card's sentence, from its kind and how many it holds. */
81 export function cardSentence(kind: AskKind, app: string, n: number, title?: string): string {
82 switch (kind) {
83 case "look":
84 case "review":
85 return n === 1 ? `A change in ${app} is ready for your look.` : `${n} changes in ${app} wait for your look.`;
86 case "waiting":
87 return n === 1 ? `A change in ${app} has waited a day for you.` : `${n} changes in ${app} have waited a day for you.`;
88 case "assigned":
89 return n === 1 ? `Something in ${app} is yours to do.` : `${n} things in ${app} are yours to do.`;
90 case "stopped":
91 return `The crew stopped in ${app}: it cannot get past its checks.`;
92 case "parked":
93 return `The crew is stuck in ${app}.`;
94 case "handover":
95 return `The crew handed a change in ${app} over to you.`;
96 case "declined":
97 return `The crew wants your direction for ${app}.`;
98 case "paused":
99 return `The crew in ${app} stopped: today's budget is spent.`;
100 case "proposal":
101 return title === undefined || title === "" ? `The crew proposes a plan for ${app}.` : `The crew proposes a plan for ${app}: ${title}`;
102 }
103 }
104
105 /** The actions of one row, at most three: what a key can do, then the way in. */
106 function actionsOf(row: ReturnType<typeof askLinesFor>[number]): CockpitAction[] {
107 const open: CockpitAction = { word: "Open it", method: "get", href: row.link };
108 if (row.kind === "proposal" && row.proposal !== undefined)
109 return [
110 { word: "Yes", method: "post", href: `/asks/proposal/${row.proposal.id}/approve`, does: { proposal: row.proposal.id, verb: "approve" } },
111 { word: "Later", method: "post", href: `/asks/proposal/${row.proposal.id}/later`, does: { proposal: row.proposal.id, verb: "later" } },
112 open,
113 ];
114 if (row.kind === "parked" && row.items[0] !== undefined)
115 return [{ word: "Let the decider", method: "post", href: "/asks/decide", fields: { ask: row.items[0] }, does: { decide: row.items[0] } }, open];
116 return [open];
117 }
118
119 export interface CockpitOptions {
120 /** A screen nobody types at: only cards four keys can answer. */
121 readonly kiosk?: boolean;
122 readonly now?: number;
123 }
124
125 /** The cockpit for `user`: read-only, nothing is noted as seen. */
126 export function cockpitFor(app: App, user: User, opts: CockpitOptions = {}): Cockpit {
127 const now = opts.now ?? Date.now();
128 const rows = askLinesFor(app.db, user).filter((r) => opts.kiosk !== true || keysCanAnswer(r.kind));
129 const cards: CockpitCard[] = rows.slice(0, MAX_CARDS).map((r) => ({
130 id: r.id,
131 says: cardSentence(r.kind, r.repo.slice(r.repo.indexOf("/") + 1), r.items.length, r.proposal?.title),
132 actions: actionsOf(r),
133 tone: "needs-you",
134 }));
135 const more = rows.length - cards.length;
136 const digest = feedDigest(app.db, user, now);
137 const ctx = { app };
138 const repos = writableAppsOf(ctx, user).repos;
139 const waves = biggestOf(repos, MAX_WAVES, (repo) => planFor(ctx, repo, false, new Date(now), false)).map((l): CockpitWave => {
140 const w = l.limb.weight;
141 return {
142 name: l.limb.name,
143 says: landedWords(w, l.limb.issue),
144 percent: landedPercent(w),
145 href: milestoneHref(repoBase(l.repo), l.limb.issue.number),
146 tone: w.open === 0 ? "done" : w.merged > 0 ? "working" : "quiet",
147 };
148 });
149 return {
150 today: digest === null ? null : { heading: digest.heading, lines: digest.lines.map((l) => ({ says: l.says, href: l.href })) },
151 sentence: rows.length === 0 ? "Nothing needs you." : `${rows.length} ${plural(rows.length, "thing needs", "things need")} you.`,
152 cards,
153 more,
154 waves,
155 };
156 }
test/behaviors-rule.test.ts +1
@@ -38,6 +38,7 @@ const OWN_SCRIPT = new Set([
3838 "src/web/pages/browse.ts",
3939 "src/web/pages/builds.ts",
4040 "src/web/pages/changelog.ts",
41 "src/web/pages/cockpit.ts",
4142 "src/web/pages/claim.ts",
4243 "src/web/pages/commits.ts",
4344 "src/web/pages/display.ts",
test/cockpit.test.ts added +303
@@ -0,0 +1,303 @@
1 /**
2 * The cockpit (#1152): one page, three regions, at most five cards, none from a muted repository,
3 * no words outside the plain list, four keys that reach every action, the kiosk without a top bar
4 * and without a card that wants typing, and MCP's `asks` with `cockpit: true` answering the page's
5 * own cards in the page's own order.
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 { addToCrew, createAgent } from "../src/actions/crew.ts";
13 import { assignIssue } from "../src/actions/issues.ts";
14 import { openPull } from "../src/actions/pulls.ts";
15 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
16 import { getIssueById, setIssueState } from "../src/core/issues.ts";
17 import { createApp as createAppRecord } from "../src/core/apps.ts";
18 import { muteRepo } from "../src/core/interactions.ts";
19 import type { Repo } from "../src/core/repos.ts";
20 import { claimRun, createRun, finishRun } from "../src/core/runs.ts";
21 import { createSession } from "../src/core/sessions.ts";
22 import { createToken } from "../src/core/tokens.ts";
23 import { createUser, getUserByName, type User } from "../src/core/users.ts";
24 import { serve, type Servers } from "../src/http/server.ts";
25 import { cardSentence, cockpitFor, keysCanAnswer, MAX_CARDS, type Cockpit } from "../src/web/studio/cockpit.ts";
26 import { cockpitBody } from "../src/web/pages/cockpit.ts";
27 import { cockpitScreenKeysJs } from "../src/web/cockpit_screen_keys.ts";
28 import { cockpitLines } from "../src/tui/screens/cockpit.ts";
29 import { quietLogs } from "./helpers/globals.ts";
30 import { mcpTool } from "./helpers/mcp.ts";
31 import { linkIssue } from "../src/actions/dependencies.ts";
32 import { proposePlan } from "../src/actions/plan.ts";
33 import { getRepoById } from "../src/core/repos.ts";
34 import { getProposal } from "../src/core/proposals.ts";
35 import { createForgeApp } from "../src/tui/forge.ts";
36 import { headlessTerminal } from "../src/tui/term/terminal.ts";
37 import { settleApp, settlePalette, settleUntil } from "./helpers/tui.ts";
38 import { askIssue } from "./helpers/ask-issue.ts";
39 import { ASK_KINDS } from "../src/core/ask_filters.ts";
40
41 quietLogs();
42
43 /** Words a person on a TV should never read (the studio's own words are the only ones allowed). */
44 const NERDY = /\b(pull requests?|pulls?|merge[ds]?|commits?|branch(es)?|repos?|repositor(y|ies)|agents?|planner|reviewer|builder|sentinel|webhook|token|MCP|SSE|CI)\b/i;
45
46 describe("the cockpit", () => {
47 let dataDir = "";
48 let app: App;
49 let servers: Servers;
50 let alice: User;
51 let cookie = "";
52 let repo: Repo;
53 let quiet: Repo;
54
55 const get = (path: string) => fetch(`${servers.url}${path}`, { headers: { cookie }, redirect: "manual" });
56 /** What a person reads of the cockpit itself, not of the forge's chrome around it. */
57 const visible = (html: string): string =>
58 (html.split("<div data-cockpit")[1] ?? "").split("</main>")[0]!.replace(/<(script|style)[\s\S]*?<\/\1>/g, " ").replace(/<[^>]+>/g, " ").replace(/&#39;/g, "'").replace(/\s+/g, " ");
59
60 async function seedPull(name: string, title: string): Promise<Repo> {
61 const made = await createRepo(app, alice, { name, visibility: "public" });
62 if (!made.ok) throw new Error(String(made.error));
63 const r = made.value;
64 await commitToBranch(app, alice, r, { message: "seed", files: [{ path: "README.md", content: `# ${name}\n` }] });
65 addToCrew(app, alice, r, "bot");
66 await commitToBranch(app, alice, r, { branch: "bot/1", base: "main", message: title, files: [{ path: "F.md", content: "1\n" }] });
67 const opened = await openPull(app, getUserByName(app.db, "bot")!, r, { title, body: "", baseBranch: "main", headBranch: "bot/1" });
68 if (!opened.ok) throw new Error(String(opened.error));
69 const run = createRun(app.db, { repoId: r.id, kind: "check", issueId: opened.value.id, env: `pull-${opened.value.number}`, commitOid: opened.value.headOid, reason: "pull" });
70 claimRun(app.db, run.id);
71 finishRun(app.db, run.id, { state: "ok", summary: "ok" });
72 expect(assignIssue(app, alice, r, getIssueById(app.db, opened.value.id)!, alice).ok).toBe(true);
73 return r;
74 }
75
76 beforeAll(async () => {
77 dataDir = await mkdtemp(join(tmpdir(), "forge-cockpit-"));
78 app = createApp({ dataDir, port: 0, disk: () => ({ freeBytes: 500e9, totalBytes: 1000e9 }) });
79 servers = await serve(app);
80 const made = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-long-cockpit-passphrase", adminIfFirst: true });
81 if (!made.ok) throw new Error(made.error);
82 alice = made.value;
83 cookie = `forge_session=${createSession(app.db, alice.id).token}`;
84 await createAgent(app, alice, { username: "bot" });
85 repo = await seedPull("tower", "Tower work");
86 expect(createAppRecord(app.db, { repoId: repo.id, slug: "tower", access: "public" }).ok).toBe(true);
87 quiet = await seedPull("hush", "Hush work");
88 });
89
90 afterAll(async () => {
91 servers.stop();
92 app.close();
93 await rm(dataDir, { recursive: true, force: true });
94 });
95
96 test("signed out, it asks to sign in; signed in, three regions and a sentence", async () => {
97 expect((await fetch(`${servers.url}/cockpit`, { redirect: "manual" })).status).toBeGreaterThanOrEqual(300);
98 const res = await get("/cockpit");
99 expect(res.status).toBe(200);
100 const html = await res.text();
101 for (const id of ["cockpit-today", "cockpit-needs", "cockpit-waves"]) expect(html).toContain(`id="${id}"`);
102 expect(html).toContain("things need you.");
103 expect(html).toContain("data-first");
104 });
105
106 test("no word outside the plain list, on the page and in every sentence", async () => {
107 const text = visible(await (await get("/cockpit")).text());
108 expect(text).not.toMatch(NERDY);
109 for (const kind of ASK_KINDS) expect(cardSentence(kind, "tower", 3, "A plan")).not.toMatch(NERDY);
110 expect(cardSentence("look", "tower", 3)).toBe("3 changes in tower wait for your look.");
111 });
112
113 test("a muted repository's card does not appear, on the page or in MCP", async () => {
114 const before = cockpitFor(app, alice);
115 expect(before.cards.map((c) => c.says).join(" ")).toContain("hush");
116 muteRepo(app.db, alice.id, quiet.id);
117 const after = cockpitFor(app, alice);
118 expect(after.cards.map((c) => c.says).join(" ")).not.toContain("hush");
119 expect(after.cards.map((c) => c.says).join(" ")).toContain("tower");
120 expect(visible(await (await get("/cockpit")).text())).not.toContain("hush");
121 });
122
123 test("at most five cards, at most three actions each, and the rest counted", () => {
124 const c = cockpitFor(app, alice);
125 expect(c.cards.length).toBeLessThanOrEqual(MAX_CARDS);
126 for (const card of c.cards) {
127 expect(card.actions.length).toBeGreaterThan(0);
128 expect(card.actions.length).toBeLessThanOrEqual(3);
129 }
130 expect(c.sentence).toBe(c.cards.length === 1 && c.more === 0 ? "1 thing needs you." : c.sentence);
131 });
132
133 test("the kiosk has no top bar and still answers; /board?kiosk=1 is the same screen", async () => {
134 const kiosk = await (await get("/cockpit?kiosk=1")).text();
135 const board = await (await get("/board?kiosk=1")).text();
136 const normal = await (await get("/cockpit")).text();
137 expect(kiosk).toContain("data-kiosk");
138 expect(kiosk).not.toContain('class="topbar');
139 expect(normal).toContain('class="topbar');
140 expect(visible(board)).toBe(visible(kiosk));
141 });
142
143 test("MCP's cockpit is the page's cards and waves in the same words and order", async () => {
144 const token = createToken(app.db, alice.id, "ro", "ro").token;
145 const answer = (await mcpTool(servers.url, token, "asks", { cockpit: true })).value as { sentence: string; cards: { says: string }[]; waves: { name: string }[] };
146 const own = cockpitFor(app, alice);
147 expect(answer.cards.map((c) => c.says)).toEqual(own.cards.map((c) => c.says));
148 expect(answer.sentence).toBe(own.sentence);
149 expect(answer.waves).toEqual(JSON.parse(JSON.stringify(own.waves)));
150 const page = visible(await (await get("/cockpit")).text());
151 let from = 0;
152 for (const c of answer.cards) {
153 const at = page.indexOf(c.says, from);
154 expect(at).toBeGreaterThanOrEqual(from);
155 from = at;
156 }
157 expect(answer.sentence).toBe(visible(await (await get("/cockpit")).text()).match(/\d+ things? needs? you\.|Nothing needs you\./)![0]);
158 });
159
160 test("a wave is one row: what landed and what is left, in the page's words", async () => {
161 const fresh = () => getRepoById(app.db, repo.id)!;
162 const goal = askIssue(app, alice, fresh(), "Open the tower");
163 for (let i = 0; i < 4; i++) {
164 const part = askIssue(app, alice, fresh(), `Floor ${i}`);
165 linkIssue(app, alice, fresh(), getIssueById(app.db, goal.id)!, getIssueById(app.db, part.id)!);
166 if (i < 1) setIssueState(app.db, part.id, "closed", "done");
167 }
168 const c = cockpitFor(app, alice);
169 const w = c.waves.find((x) => x.name === "Open the tower");
170 expect(w?.says).toBe("1 of 4 landed, 3 to go");
171 expect(w?.percent).toBe(25);
172 expect(visible(await (await get("/cockpit")).text())).toContain("1 of 4 landed, 3 to go");
173 });
174
175 test("a proposal's card says yes and later with a form each; the kiosk keeps it, and escapes its title", async () => {
176 const made = proposePlan(app, alice, repo, [{ key: "a", title: "First", body: "", blockedBy: [] }], { title: "Paint <b>the</b> tower", why: "w" });
177 if (!made.ok) throw new Error(JSON.stringify(made.error));
178 const c = cockpitFor(app, alice, { kiosk: true });
179 const card = c.cards.find((x) => x.says.includes("proposes"))!;
180 expect(card.actions.map((a) => a.word)).toEqual(["Yes", "Later", "Open it"]);
181 expect(card.actions[0]).toMatchObject({ method: "post", href: `/asks/proposal/${made.value.id}/approve` });
182 const html = await (await get("/cockpit?kiosk=1")).text();
183 expect(html).toContain(`action="/asks/proposal/${made.value.id}/later"`);
184 expect(html).toContain("Paint &lt;b&gt;the&lt;/b&gt; tower");
185 expect(html).not.toContain("<b>the</b>");
186 // Yes is the first action, so Enter takes it: it posts here and the card leaves.
187 const yes = await fetch(`${servers.url}/asks/proposal/${made.value.id}/approve`, { method: "POST", headers: { cookie, origin: servers.url }, body: new URLSearchParams({ back: "/cockpit?kiosk=1" }), redirect: "manual" });
188 expect(yes.status).toBe(303);
189 expect(yes.headers.get("location")).toBe("/cockpit?kiosk=1");
190 expect(cockpitFor(app, alice).cards.some((x) => x.says.includes("proposes"))).toBe(false);
191 });
192
193 test("the terminal answers a plan itself: enter says Yes, l says Later, through the actions the web calls", async () => {
194 const mk = (title: string) => {
195 const made = proposePlan(app, alice, repo, [{ key: "a", title: "First", body: "", blockedBy: [] }], { title, why: "w" });
196 if (!made.ok) throw new Error(JSON.stringify(made.error));
197 return made.value.id;
198 };
199 const drive = async (id: string, key: string): Promise<void> => {
200 const terminal = headlessTerminal(120, 30);
201 const { app: tui } = createForgeApp(app, { sshUsername: alice.username, remoteAddress: "127.0.0.1", fingerprint: "SHA256:test", user: alice }, { terminal, exitHooks: false });
202 tui.start();
203 await settleApp(tui);
204 terminal.feed("\x0b");
205 for (const ch of "Cockpit") terminal.feed(ch);
206 await settlePalette(tui);
207 terminal.feed("\r");
208 await settleApp(tui);
209 const lines = cockpitLines(cockpitFor(app, alice));
210 const at = lines.findIndex((l) => l.acts.some((a) => a.does !== undefined && "proposal" in a.does && a.does.proposal === id));
211 expect(at).toBeGreaterThanOrEqual(0);
212 for (let i = 0; i < at; i++) {
213 terminal.feed("j");
214 await settleApp(tui);
215 }
216 terminal.feed(key);
217 await settleUntil(tui, "Done.");
218 tui.stop();
219 };
220 const yes = mk("Yes one");
221 await drive(yes, "\r");
222 expect(getProposal(app.db, yes)?.state).toBe("approved");
223 const later = mk("Later one");
224 await drive(later, "l");
225 expect(getProposal(app.db, later)?.state).toBe("later");
226 });
227
228 test("the kiosk leaves out a card that wants typed words, and keeps every other kind", () => {
229 const typed = ASK_KINDS.filter((k) => !keysCanAnswer(k));
230 expect([...typed].sort()).toEqual(["declined", "handover", "stopped"]);
231 });
232
233 test("the terminal's lines are the same cards, then the waves", () => {
234 const c = cockpitFor(app, alice);
235 const lines = cockpitLines(c).map((l) => l.title);
236 for (const card of c.cards) expect(lines).toContain(card.says);
237 });
238 });
239
240 type HtmlEl = { getAttribute(n: string): string | null };
241
242 describe("the four keys, in a real DOM", () => {
243 /**
244 * The page's own markup for one card, one today line and one wave, with the keys script run on
245 * it.
246 */
247 async function run() {
248 const { Window } = await import("happy-dom");
249 const win = new Window({ url: "http://forge.test/cockpit" });
250 const doc = win.document;
251 const c: Cockpit = {
252 today: { heading: "Since you were here", lines: [{ says: "A change landed.", href: "/a" }] },
253 sentence: "1 thing needs you.",
254 cards: [{ id: "k1", says: "A change in app is ready for your look.", tone: "needs-you", actions: [{ word: "Open it", method: "get", href: "/k1" }] }],
255 more: 0,
256 waves: [{ name: "Wave", says: "1 of 4 landed, 3 to go", percent: 25, href: "/w", tone: "working" }],
257 };
258 doc.body.innerHTML = cockpitBody(c, false).toString();
259 const clicked: string[] = [];
260 doc.addEventListener("click", (e: { preventDefault(): void; target: unknown }) => {
261 e.preventDefault();
262 clicked.push((e.target as HtmlEl).getAttribute("href") ?? "");
263 });
264 new Function("document", "window", "location", cockpitScreenKeysJs)(doc, win, { assign: (u: string) => clicked.push(`go:${u}`) });
265 // A key goes to the focused element, as a browser sends it, and bubbles up to the page's
266 // listener.
267 const press = (key: string) => (doc.activeElement ?? doc.body).dispatchEvent(new win.KeyboardEvent("keydown", { key, bubbles: true, cancelable: true }));
268 const at = () => (doc.activeElement as HtmlEl | null)?.getAttribute("data-id") ?? null;
269 return { press, at, clicked, doc };
270 }
271
272 test("the first item is focused, down and up walk every item and stop at the ends", async () => {
273 const { press, at } = await run();
274 expect(at()).toBe("today-/a");
275 press("ArrowDown");
276 expect(at()).toBe("k1");
277 press("ArrowDown");
278 expect(at()).toBe("wave-/w");
279 press("ArrowDown");
280 expect(at()).toBe("wave-/w");
281 press("ArrowUp");
282 expect(at()).toBe("k1");
283 });
284
285 test("Enter takes the focused item's first action", async () => {
286 const { press, clicked } = await run();
287 press("ArrowDown");
288 press("Enter");
289 expect(clicked).toEqual(["/k1"]);
290 });
291
292 test("back goes up a level: item to section, section let go, then the front page", async () => {
293 const { press, at, clicked, doc } = await run();
294 press("ArrowDown");
295 press("Escape");
296 expect((doc.activeElement as HtmlEl).getAttribute("data-id")).toBe("needs");
297 press("Escape");
298 expect(at()).toBeNull();
299 expect(clicked).toEqual([]);
300 press("Escape");
301 expect(clicked).toEqual(["go:/"]);
302 });
303 });
test/looks-owner.test.ts +1 −1
@@ -322,7 +322,7 @@ describe("the forge's own owner looks, over the preview seed", () => {
322322 test("forge.json takes the seed's other pages as the owner, and the seed's pull is the one the named list pictures", () => {
323323 const manifest = parseManifest(readFileSync(join(import.meta.dir, "..", "forge.json"), "utf8"), undefined);
324324 if (!manifest.ok) throw new Error(JSON.stringify(manifest.error));
325 for (const page of ["next", "bets", "waves", "space"].map((p) => `${repoHome}/${p === "next" ? "next?pick" : p}`)) { // milestones left for the space page (the cap of 24 is spent); the preview's owner list still pictures it (test/milestones-fit.test.ts). The next page is pictured with its first row chosen
325 for (const page of ["next", "bets", "waves"].map((p) => `${repoHome}/${p === "next" ? "next?pick" : p}`)) { // milestones left for the space page (the cap of 24 is spent); the preview's owner list still pictures it (test/milestones-fit.test.ts). The next page is pictured with its first row chosen
326326 expect(manifest.value.looks).toContain(page);
327327 expect(manifest.value.looksAsOwner).toContain(page);
328328 }
test/palette-roster.test.ts +3
@@ -102,6 +102,7 @@ test("a site-admin person is offered the whole roster", () => {
102102 ["migrate", "Migrate a repository", "bring one in from an origin or a URL, pick its branch, put a crew on it"],
103103 ["inventory", "What is left to bring over", "every repository on your connected accounts, what it holds, where its move stands"],
104104 ["new-forge", "New forge", "spawn a client's forge and get its claim link"],
105 ["cockpit", "Cockpit", "what needs you, what happened, the waves under way"],
105106 ["thought-notes", "Notes", "write an idea and watch it become shipped work"],
106107 ["decider", "Decider", "what it closed, deferred and asked you about today"],
107108 ["shells", "Your shells", "the machine shells you hold, live then ended"],
@@ -302,6 +303,7 @@ test("a site-admin agent is offered the roster without the person-only entries",
302303 ["migrate", "Migrate a repository", "bring one in from an origin or a URL, pick its branch, put a crew on it"],
303304 ["inventory", "What is left to bring over", "every repository on your connected accounts, what it holds, where its move stands"],
304305 ["new-forge", "New forge", "spawn a client's forge and get its claim link"],
306 ["cockpit", "Cockpit", "what needs you, what happened, the waves under way"],
305307 ["thought-notes", "Notes", "write an idea and watch it become shipped work"],
306308 ["decider", "Decider", "what it closed, deferred and asked you about today"],
307309 ["fetch-page", "Read a web page", "paste an https link; the page as Markdown, as Talk's agent reads it"],
@@ -423,6 +425,7 @@ test("a member person is offered the signed-in roster without the admin entries"
423425 ["migrate", "Migrate a repository", "bring one in from an origin or a URL, pick its branch, put a crew on it"],
424426 ["inventory", "What is left to bring over", "every repository on your connected accounts, what it holds, where its move stands"],
425427 ["new-forge", "New forge", "spawn a client's forge and get its claim link"],
428 ["cockpit", "Cockpit", "what needs you, what happened, the waves under way"],
426429 ["thought-notes", "Notes", "write an idea and watch it become shipped work"],
427430 ["decider", "Decider", "what it closed, deferred and asked you about today"],
428431 ["shells", "Your shells", "the machine shells you hold, live then ended"],

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs