Public: anyone can read this; the crew can change it.
One keymap (d): /next, the space and /system take their keys from the map; no page chooses a key of its own #17138
Merged 40h 34m ago, live in production
keymap-d → main 0 commits 1 thread · 1 unresolved
19 files
changed +230
−101
- docs/features/keymap.md
- docs/features/next-up.md
- src/tui/screens/cockpit.ts
- src/tui/screens/next.ts
- src/web/keymap.ts
- src/web/pages/next.ts
- src/web/pages/next_keys.ts
- src/web/pages/system.ts
- src/web/space_client.ts
- src/web/system-live.ts
- test/cockpit.test.ts
- test/keymap-terminal.test.ts
- test/keymap.test.ts
- test/next-keys.test.ts
- test/next-up.test.ts
- test/system-btop.test.ts
- test/system-stream.test.ts
- test/tui-next-up.test.ts
- test/week-doors.test.ts
docs/features/keymap.md +2 −1
| @@ -18,6 +18,7 @@ The owner, after the bridge: "tying together all the keybinds is really what im | ||
| 18 | 18 | - **A repository's tabs** are its own `g` jumps (`REPO_TABS`): `g c` code, `g i` issues, `g p` pulls, `g a` map, `g m` commits, `g b` branches, `g f` forks, `g r` runs, `g s` settings. Inside a repository `g f` and `g s` are its own, by design; the forge-wide Front page and Settings are a step away through `:` and Cmd/Ctrl K. A file's Propose a change is `e`. |
| 19 | 19 | - **A quick second key** finds its button: `j` then `m` within a second merges, as `m` alone does (never after `g`, whose letter is a jump). |
| 20 | 20 | |
| 21 | Coming: /boards, /flow and Talk, and the pages that still bind their own keys (/next's `t` `u` `d` `l`, the space's `n`, /system's `c` and `m`), listed in the test with that pull. | |
| 21 | - **Ranked lists, the space and /system:** /next's rows move with `T` top, `K` up, `J` down and `p` not now (the terminal's Next up keeps `l` for not now, since `p` pauses its planner); the space's canvas zooms with `+` and `-`, fits with `0`, jumps to now with `n` and steps bodies with `]` and `[`; /system's process table toggles CPU and memory with `S`. The terminal's cockpit puts a card off with `p` (later, the keymap's park), not `l`. Their old keys (`t` `u` `d` `l`, `c` `m`, the cockpit's `l`) say the new one until 2026-12-15. | |
| 22 | - **/boards, /flow and Talk** bind no keys of their own: they answer the shell's moves and nothing fires while typing in Talk's box. The test now has no page left that chooses a key. | |
| 22 | 23 | |
| 23 | 24 | Proof: `test/keymap.test.ts`, `test/bridge.test.ts`. |
docs/features/next-up.md +3 −3
| @@ -7,7 +7,7 @@ row: Next up | ||
| 7 | 7 | `/:owner/:name/next` is the one ranked list the crew builds from (#8694). It reads as one numbered queue in the dispatcher's order (#11619): each row has its position, title, who is on it (or "next"), and one word of state: building, checking, in review, landing, waiting on #N, held or ready. A pull that is open on the issue sets building, checking or in review. Three native folds hold the rows, each with a count: "Up next" (the first ten, open), "After" (the rest) and "Later" (behind the Later gate). There is no script for the folds and no `?all=1`; the folds are keyboard and screen-reader reachable at any width. The terminal's Next up screen shows the same numbers and state words. |
| 8 | 8 | |
| 9 | 9 | - **Role:** each row is tagged *Blocker* (it holds other open work up: "finishing it frees N") or *Enabler* (it holds nothing up; its line says what it serves, else that the owner ranked it). The tag is a label only: it never changes the order the picker takes work in. |
| 10 | - **Move:** `Top` (`t`), `Up` (`u`), `Down` (`d`) and `Not now` (`l`) are forms on each row, with the key shown beside each (Shift+J/K or Alt+↓/↑ also move down and up; Alt+Shift combos do nothing); `j`/`k` choose the row, and a row can be dragged. Each is one `POST /:owner/:name/next` (`number`, `to` = `top`, `not-now` or `after:<number>`) and saves at once. Writers only; the same-origin check applies. | |
| 10 | - **Move:** `Top` (`T`), `Up` (`K`), `Down` (`J`) and `Not now` (`p`, park) are forms on each row, with the key shown beside each, from the forge's one keymap (`docs/features/keymap.md`); Alt+↓/↑ also move down and up, and Alt+Shift combos do nothing; until 2026-12-15 the old `t`, `u`, `d` and `l` say the new key; `j`/`k` choose the row, and a row can be dragged. Each is one `POST /:owner/:name/next` (`number`, `to` = `top`, `not-now` or `after:<number>`) and saves at once. Writers only; the same-origin check applies. | |
| 11 | 11 | - **Top lifts the gate:** `Top` on a deferred issue removes its `wait_for` edge to the Later gate (and the Later umbrella's edge to it) in the same action. Work that only deferred work needs stays deferred, and the refusal says so. |
| 12 | 12 | - **Owner's pick:** a row a person placed (page, terminal or MCP) is marked "Owner's pick" on the page and in the terminal. Automatic ranking leaves it at its place and orders only the other rows around it; only a person's move changes it, and `Not now` clears it along with the rank. A move of another row does not mark the rows the planner placed. Nothing calls the automatic mode yet (`writeOrder` with `owner: false`): the guarantee is in place and tested, ahead of its first caller. |
| 13 | 13 | - **Not now** links the issue to wait for the open Later gate and drops its rank. |
| @@ -15,9 +15,9 @@ row: Next up | ||
| 15 | 15 | - **MCP:** `next_up { app, issue?, to?, all? }` reads the list, or moves one issue with the same words. |
| 16 | 16 | - A rank is cleared when the issue closes. Dependencies order within the list and are shown, never edited here. |
| 17 | 17 | |
| 18 | **Terminal:** the palette's "Next up in a repository" opens the same list; `t`, `u`, `d` and `l` are Top, Up, Down and Not now on the row under the cursor, through the same action as the page and MCP. A reader sees the order and the keys do nothing; a move made anywhere reorders an open screen live. At most 200 issues are ranked; a move past that is refused and says so. | |
| 18 | **Terminal:** the palette's "Next up in a repository" opens the same list; `T`, `K`, `J` and `l` are Top, Up, Down and Not now on the row under the cursor (`l`, not `p`, since `p` pauses the planner there; the keymap says so), through the same action as the page and MCP. A reader sees the order and the keys do nothing; a move made anywhere reorders an open screen live. At most 200 issues are ranked; a move past that is refused and says so. | |
| 19 | 19 | |
| 20 | **Filter (#11867):** a plain GET form above the list narrows `/next` to one pillar (`?pillar=P7` or `Later`, typed in a box) and/or a word (`?q=cache`, matched without regard to case, shown as typed, at most 80 characters). A filter only hides rows: each keeps its real place in the whole ranking, the cut line stays where the whole list puts it (drawn only between shown rows), and a move made under a filter moves in the whole order and returns to the same filter. A line says "N of M shown", and that the week's capacity bar is left out while filtered. An unknown or malformed pillar shows an empty list that says so. **Terminal:** `/` asks for a pillar and/or a word (`P7 cache`); an empty answer clears it; ranks, `t` `u` `d` `l` and the header count behave as on the page. | |
| 20 | **Filter (#11867):** a plain GET form above the list narrows `/next` to one pillar (`?pillar=P7` or `Later`, typed in a box) and/or a word (`?q=cache`, matched without regard to case, shown as typed, at most 80 characters). A filter only hides rows: each keeps its real place in the whole ranking, the cut line stays where the whole list puts it (drawn only between shown rows), and a move made under a filter moves in the whole order and returns to the same filter. A line says "N of M shown", and that the week's capacity bar is left out while filtered. An unknown or malformed pillar shows an empty list that says so. **Terminal:** `/` asks for a pillar and/or a word (`P7 cache`); an empty answer clears it; ranks, `T` `K` `J` (top, up, down) and `l` (not now; `p` pauses the planner on this screen) and the header count behave as on the page. | |
| 21 | 21 | |
| 22 | 22 | **The chapter line (#12681):** under the title, once the repository has chapters, `Ranked for <open chapter>: <progress sentence>` (linked), or "No chapter is open" with a link to draft one; a repository that never drafted a chapter shows no line. **Terminal:** the screen prints the same line under the title, from the same function (`chapterLineParts` in `core/chapters.ts`), wrapped to the width and never cut (#13254, #12991). |
| 23 | 23 |
src/tui/screens/cockpit.ts +9 −3
| @@ -8,7 +8,7 @@ | ||
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | import { actOnProposal } from "../../actions/proposals.ts"; |
| 11 | import { keyOf } from "../../web/keymap.ts"; | |
| 11 | import { keyOf, oldKeys } from "../../web/keymap.ts"; | |
| 12 | 12 | import { decideAsk } from "../../actions/asks_decide.ts"; |
| 13 | 13 | import { cockpitFor, type Cockpit, type CockpitAction } from "../../web/studio/cockpit.ts"; |
| 14 | 14 | import type { Ctx, Screen } from "../app/app.ts"; |
| @@ -71,7 +71,7 @@ export function cockpitScreen(f: Session, ctx: Ctx): Screen { | ||
| 71 | 71 | }; |
| 72 | 72 | return { |
| 73 | 73 | title: "Cockpit", |
| 74 | keys: [binding(["j", "k"], "move"), binding(["enter"], "do"), binding(["l"], "later"), binding(["o"], "web"), binding([keyOf("reread")], "refresh")], | |
| 74 | keys: [binding(["j", "k"], "move"), binding(["enter"], "do"), binding([keyOf("park")], "later"), binding(["o"], "web"), binding([keyOf("reread")], "refresh")], | |
| 75 | 75 | load: async () => read(), |
| 76 | 76 | render(area, s) { |
| 77 | 77 | const c = ctx.theme.c; |
| @@ -86,7 +86,13 @@ export function cockpitScreen(f: Session, ctx: Ctx): Screen { | ||
| 86 | 86 | open(state.index); |
| 87 | 87 | return true; |
| 88 | 88 | } |
| 89 | if (e.key === "l" || e.key === "o") { | |
| 89 | // Later is the forge's one keymap's park (web/keymap.ts), p; the old l says so for two weeks. | |
| 90 | const moved = oldKeys("cockpit").find((o) => o.was === e.key); | |
| 91 | if (moved !== undefined) { | |
| 92 | ctx.toast(moved.says); | |
| 93 | return true; | |
| 94 | } | |
| 95 | if (e.key === keyOf("park") || e.key === "o") { | |
| 90 | 96 | const line = lines[state.index]; |
| 91 | 97 | if (line !== undefined) { |
| 92 | 98 | if (e.key === "o") openOnWeb(f, ctx, line.path, "That"); |
src/tui/screens/next.ts +17 −9
| @@ -13,6 +13,7 @@ | ||
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | 15 | import { rankedWords, rankIssue, stepTo, type Place, placeOf } from "../../actions/next.ts"; |
| 16 | import { keyOf, oldKeys, VERBS } from "../../web/keymap.ts"; | |
| 16 | 17 | import { listChapters, itemsOf, chapterLineWords, chapterNames } from "../../core/chapters.ts"; |
| 17 | 18 | import { takeOrder } from "../../crew/take_order.ts"; |
| 18 | 19 | import { nextAll, type NextGroup } from "../../core/next_all.ts"; |
| @@ -214,6 +215,7 @@ export function nextScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 214 | 215 | }; |
| 215 | 216 | }); |
| 216 | 217 | |
| 218 | const NOT_NOW = VERBS.park.terminal.key; | |
| 217 | 219 | const screen: Screen = { |
| 218 | 220 | title: "Next up", |
| 219 | 221 | get keys() { |
| @@ -221,10 +223,12 @@ export function nextScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 221 | 223 | return [ |
| 222 | 224 | binding(["j", "k"], "move cursor"), |
| 223 | 225 | binding(["enter"], "open"), |
| 224 | binding(["t"], "top", { disabled: !on || rows.indexOf(current()!) === 0 }), | |
| 225 | binding(["u"], "up", { disabled: !on || rows.indexOf(current()!) === 0 }), | |
| 226 | binding(["d"], "down", { disabled: !on || rows.indexOf(current()!) >= rows.length - 1 }), | |
| 227 | binding(["l"], "not now", { disabled: !on }), | |
| 226 | // The forge's one keymap (web/keymap.ts): T, K and J as on the page; not now is l here, | |
| 227 | // since p pauses the planner on this screen (the map says so). | |
| 228 | binding([keyOf("top")], "top", { disabled: !on || rows.indexOf(current()!) === 0 }), | |
| 229 | binding([keyOf("raise")], "up", { disabled: !on || rows.indexOf(current()!) === 0 }), | |
| 230 | binding([keyOf("lower")], "down", { disabled: !on || rows.indexOf(current()!) >= rows.length - 1 }), | |
| 231 | binding([NOT_NOW], "not now", { disabled: !on }), | |
| 228 | 232 | binding(["x"], "tick", { disabled: !on }), |
| 229 | 233 | binding(["s"], "snooze", { disabled: !may() || ticked.size === 0 }), |
| 230 | 234 | binding(["z"], "undo", { disabled: !may() || lastBatch.length === 0 }), |
| @@ -258,16 +262,20 @@ export function nextScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 258 | 262 | key(e) { |
| 259 | 263 | if (state.key(e, shown.length)) return true; |
| 260 | 264 | if (e.ctrl || e.alt) return false; |
| 261 | if (e.key === "enter") open(); | |
| 262 | else if (e.key === "t") rank({ to: "top" }); | |
| 263 | else if (e.key === "u") step(-1); | |
| 264 | else if (e.key === "d") step(1); | |
| 265 | // The old t, u and d say where they went, for two weeks (keymap.ts OLD_KEYS); l is still not | |
| 266 | // now. | |
| 267 | const moved = oldKeys("next").find((o) => o.was === e.key && o.was !== NOT_NOW); | |
| 268 | if (moved !== undefined) ctx.toast(moved.says); | |
| 269 | else if (e.key === "enter") open(); | |
| 270 | else if (e.key === keyOf("top")) rank({ to: "top" }); | |
| 271 | else if (e.key === keyOf("raise")) step(-1); | |
| 272 | else if (e.key === keyOf("lower")) step(1); | |
| 265 | 273 | else if (e.key === "x") tickRow(); |
| 266 | 274 | else if (e.key === "s") batch(false); |
| 267 | 275 | else if (e.key === "z") batch(true); |
| 268 | 276 | else if (e.key === "/") ask(); |
| 269 | 277 | else if (e.key === "p") pause(); |
| 270 | else if (e.key === "l") rank({ to: "not_now" }); | |
| 278 | else if (e.key === NOT_NOW) rank({ to: "not_now" }); | |
| 271 | 279 | else return false; |
| 272 | 280 | return true; |
| 273 | 281 | }, |
src/web/keymap.ts +29 −6
| @@ -16,7 +16,7 @@ import { GO_PAGES } from "./go_pages.ts"; | ||
| 16 | 16 | const go = (href: string): string => `g ${GO_PAGES.find((p) => p.href === href)?.key ?? ""}`; |
| 17 | 17 | |
| 18 | 18 | /** What a key acts on: a verb means one thing per kind, and a move works anywhere. */ |
| 19 | export type KeyKind = "any" | "pull" | "issue" | "run" | "figure" | "card" | "file"; | |
| 19 | export type KeyKind = "any" | "pull" | "issue" | "run" | "figure" | "card" | "file" | "rank" | "space" | "table"; | |
| 20 | 20 | |
| 21 | 21 | export interface KeyDef { |
| 22 | 22 | /** The `KeyboardEvent.key` it answers; a sequence is written with a space ("g h"). */ |
| @@ -65,7 +65,16 @@ export const VERBS = { | ||
| 65 | 65 | approve: { key: "a", label: "Approve", what: "Approve it", kinds: ["pull"] }, |
| 66 | 66 | assign: { key: "a", label: "Assign", what: "Give it to someone", kinds: ["issue"] }, |
| 67 | 67 | sharpen: { key: "e", label: "Sharpen", what: "Have the planner plan it again", kinds: ["issue"] }, |
| 68 | park: { key: "p", label: "Park", what: "Park it behind the Later gate", kinds: ["issue"] }, | |
| 68 | park: { | |
| 69 | key: "p", | |
| 70 | label: "Park", | |
| 71 | what: "Park it behind the Later gate", | |
| 72 | kinds: ["issue", "rank"], | |
| 73 | terminal: { key: "l", reason: "the terminal's Next up screen pauses the planner on p for the repository's owner, a key that screen has had since before the map" }, | |
| 74 | }, | |
| 75 | top: { key: "T", label: "Top", what: "Move it to the top of the list", kinds: ["rank"] }, | |
| 76 | raise: { key: "K", label: "Up", what: "Move it one place up (Alt+↑ too)", kinds: ["rank"] }, | |
| 77 | lower: { key: "J", label: "Down", what: "Move it one place down (Alt+↓ too)", kinds: ["rank"] }, | |
| 69 | 78 | stop: { key: "s", label: "Stop", what: "Stop the run", kinds: ["run"] }, |
| 70 | 79 | requeue: { |
| 71 | 80 | key: "r", |
| @@ -75,8 +84,13 @@ export const VERBS = { | ||
| 75 | 84 | }, |
| 76 | 85 | watch: { key: "w", label: "Watch live", what: "Watch the run live", kinds: ["run"] }, |
| 77 | 86 | wheel: { key: "i", label: "Take the wheel", what: "Take the wheel: steer the running agent", kinds: ["run"] }, |
| 78 | fewer: { key: "-", label: "Fewer", what: "Turn the figure down", kinds: ["figure"] }, | |
| 79 | more: { key: "+", label: "More", what: "Turn the figure up", kinds: ["figure"] }, | |
| 87 | fewer: { key: "-", label: "Fewer", what: "Turn the figure down, or zoom out", kinds: ["figure", "space"] }, | |
| 88 | more: { key: "+", label: "More", what: "Turn the figure up, or zoom in", kinds: ["figure", "space"] }, | |
| 89 | fit: { key: "0", label: "Fit", what: "Fit the whole space in view", kinds: ["space"] }, | |
| 90 | now: { key: "n", label: "Now", what: "Jump to now", kinds: ["space"] }, | |
| 91 | nextBody: { key: "]", label: "Next", what: "Go to the next body", kinds: ["space"] }, | |
| 92 | prevBody: { key: "[", label: "Previous", what: "Go to the previous body", kinds: ["space"] }, | |
| 93 | sort: { key: "S", label: "Sort", what: "Sort the table by the other measure (CPU, memory)", kinds: ["table"] }, | |
| 80 | 94 | set: { key: "Enter", label: "Set", what: "Set the figure to what it shows", kinds: ["figure"] }, |
| 81 | 95 | undo: { key: "z", label: "Undo", what: "Put back what was just done", kinds: ["any"] }, |
| 82 | 96 | edit: { key: "e", label: "Propose a change", what: "Propose a change to the file", kinds: ["file"] }, |
| @@ -109,9 +123,11 @@ export const OLD_KEYS_UNTIL = "2026-12-15T00:00:00Z"; | ||
| 109 | 123 | export interface OldKey { |
| 110 | 124 | /** |
| 111 | 125 | * Where it was: "pull" for the Files page's verdicts, "review" for /review's rows, "files" for a |
| 112 | * repository's files, "runs" for the terminal's run list, "terminal" for every terminal screen. | |
| 126 | * repository's files, "runs" for the terminal's run list, "terminal" for every terminal screen, | |
| 127 | * "next" for /next's rows, "system" for /system's process table, "cockpit" for the terminal's | |
| 128 | * cockpit. | |
| 113 | 129 | */ |
| 114 | readonly page: "pull" | "review" | "files" | "runs" | "terminal"; | |
| 130 | readonly page: "pull" | "review" | "files" | "runs" | "terminal" | "next" | "system" | "cockpit"; | |
| 115 | 131 | readonly was: string; |
| 116 | 132 | readonly now: KeyId; |
| 117 | 133 | /** The word a person reads for what the key does there, when the map's label is not it. */ |
| @@ -128,6 +144,13 @@ export const OLD_KEYS: readonly OldKey[] = [ | ||
| 128 | 144 | { page: "runs", was: "S", now: "wheel" }, |
| 129 | 145 | { page: "runs", was: "a", now: "requeue" }, |
| 130 | 146 | { page: "terminal", was: "r", now: "reread" }, |
| 147 | { page: "next", was: "t", now: "top" }, | |
| 148 | { page: "next", was: "u", now: "raise" }, | |
| 149 | { page: "next", was: "d", now: "lower" }, | |
| 150 | { page: "next", was: "l", now: "park" }, | |
| 151 | { page: "system", was: "c", now: "sort" }, | |
| 152 | { page: "system", was: "m", now: "sort" }, | |
| 153 | { page: "cockpit", was: "l", now: "park", word: "later" }, | |
| 131 | 154 | ]; |
| 132 | 155 | |
| 133 | 156 | /** |
src/web/pages/next.ts +19 −10
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | * beside each action (`j`/`k` choose the row), which post the same form. |
| 8 | 8 | */ |
| 9 | 9 | import { keyStep } from "./next_keys.ts"; |
| 10 | import { keyOf, oldKeys } from "../keymap.ts"; | |
| 10 | 11 | import { DEFAULT_DECLINE, decideOffer, decideOutsider, decisionOf, outsiderShelf } from "../../actions/outsider_decision.ts"; |
| 11 | 12 | import { REASON_MAX } from "../../core/reports.ts"; |
| 12 | 13 | import { placeOf, rankIssue, rankedWords, stepTo, type Place } from "../../actions/next.ts"; |
| @@ -55,9 +56,15 @@ export const NEXT_CSS = `[data-next] { overflow-wrap: anywhere; } | ||
| 55 | 56 | [data-next] .form-actions > .input { flex: 1 1 10rem; min-width: 0; min-height: 44px; } |
| 56 | 57 | [data-next] .form-actions > .btn, [data-next] .form-actions > a { min-height: 44px; display: inline-flex; align-items: center; }`; |
| 57 | 58 | |
| 58 | export const KEYS_JS = ` | |
| 59 | /** | |
| 60 | * The page's key script, read at each render: the old keys' hints end on their date (keymap.ts). | |
| 61 | */ | |
| 62 | export const keysJs = (): string => ` | |
| 59 | 63 | (() => { |
| 60 | 64 | ${keyStep.toString()} |
| 65 | // The keymap's (keymap.ts): Top, Up, Down and Not now; the old t, u, d and l say so for two weeks. | |
| 66 | const KEYS = ${JSON.stringify({ up: keyOf("raise"), down: keyOf("lower") })}; | |
| 67 | const OLD = ${JSON.stringify(Object.fromEntries(oldKeys("next").map((o) => [o.was, o.says])))}; | |
| 61 | 68 | const list = document.getElementById("next-list"); |
| 62 | 69 | const remembered = sessionStorage.getItem("next-focus"); |
| 63 | 70 | if (remembered) { |
| @@ -79,17 +86,19 @@ export const KEYS_JS = ` | ||
| 79 | 86 | location.reload(); |
| 80 | 87 | return true; |
| 81 | 88 | }; |
| 82 | // One key, one action, on the row that has focus: the key is shown on the button. | |
| 89 | // One key, one action, on the row that has focus: the key is shown on the button. Read in capture, | |
| 90 | // so an old key's hint is said before the shell's own t (Tell the crew) or l can act. | |
| 83 | 91 | document.addEventListener("keydown", (e) => { |
| 84 | 92 | if (e.metaKey || e.ctrlKey || e.target.closest("input, textarea, select, [contenteditable]")) return; |
| 85 | const step = keyStep(e); | |
| 86 | if (!step) return; | |
| 87 | 93 | const row = document.activeElement && document.activeElement.closest("li[data-number]"); |
| 94 | if (row && !e.altKey && OLD[e.key]) { e.preventDefault(); e.stopImmediatePropagation(); if (window.forgeSay) window.forgeSay(OLD[e.key]); return; } | |
| 95 | const step = keyStep(e, KEYS); | |
| 96 | if (!step) return; | |
| 88 | 97 | const form = row && row.querySelector('form[data-key="' + step + '"]'); |
| 89 | 98 | if (!form) return; |
| 90 | 99 | e.preventDefault(); |
| 91 | 100 | send(new FormData(form), row.dataset.number); |
| 92 | }); | |
| 101 | }, true); | |
| 93 | 102 | if (!list) return; |
| 94 | 103 | ${FIT_COUNT_JS} |
| 95 | 104 | const usd = list.dataset.capacity === undefined ? NaN : Number(list.dataset.capacity); |
| @@ -180,11 +189,11 @@ function line( | ||
| 180 | 189 | const up = stepTo(numbers, at, -1); |
| 181 | 190 | const down = stepTo(numbers, at, 1); |
| 182 | 191 | const controls = writer |
| 183 | ? html`${away ? null : tick(n)}${at > 0 || away ? move(base, n, "top", "Top", "t", back) : null}${away | |
| 192 | ? html`${away ? null : tick(n)}${at > 0 || away ? move(base, n, "top", "Top", keyOf("top"), back) : null}${away | |
| 184 | 193 | ? null |
| 185 | : html`${up === undefined ? null : move(base, n, up, "Up", "u", back)}${down === undefined | |
| 194 | : html`${up === undefined ? null : move(base, n, up, "Up", keyOf("raise"), back)}${down === undefined | |
| 186 | 195 | ? null |
| 187 | : move(base, n, down, "Down", "d", back)}${move(base, n, "not-now", "Not now", "l", back)}`}` | |
| 196 | : move(base, n, down, "Down", keyOf("lower"), back)}${move(base, n, "not-now", "Not now", keyOf("park"), back)}`}` | |
| 188 | 197 | : null; |
| 189 | 198 | return row({ |
| 190 | 199 | href: `${base}/issues/${n}`, |
| @@ -335,7 +344,7 @@ export function nextPage(ctx: Ctx): Response { | ||
| 335 | 344 | ${first.length > 0 ? section(isFiltered ? "Matching" : "Up next", first, true, "next-list") : null}${rest.length > 0 ? section("After", rest, false) : null}`} |
| 336 | 345 | ${chaptersSection(ctx, repo, back, chapters, itemsFor)} |
| 337 | 346 | <p class="muted small mt" id="next-week">${sentence} <a href="${base}/week">The week</a>${writer |
| 338 | ? " · Drag a row. Keys: t top · l Later · Shift+J/K or Alt+↓/↑ down/up · j/k choose a row." | |
| 347 | ? ` · Drag a row. Keys: ${keyOf("top")} top · ${keyOf("park")} Later · ${keyOf("lower")}/${keyOf("raise")} or Alt+↓/↑ down/up · j/k choose a row.` | |
| 339 | 348 | : null}</p> |
| 340 | 349 | ${walletRow(ctx, repo, base)} |
| 341 | 350 | ${parked.length > 0 |
| @@ -354,7 +363,7 @@ export function nextPage(ctx: Ctx): Response { | ||
| 354 | 363 | palette: repoPalette(ctx, repo), |
| 355 | 364 | body, |
| 356 | 365 | styleCss: NEXT_CSS, |
| 357 | ...(writer ? { scriptJs: KEYS_JS } : {}), | |
| 366 | ...(writer ? { scriptJs: keysJs() } : {}), | |
| 358 | 367 | }); |
| 359 | 368 | notePhase(ctx.request, "render", performance.now() - rendering); |
| 360 | 369 | return response; |
src/web/pages/next_keys.ts +5 −6
| @@ -1,12 +1,11 @@ | ||
| 1 | 1 | /** The /next key mapping as one pure function: a key event in, the form key (data-key) it |
| 2 | 2 | * presses out. */ |
| 3 | 3 | |
| 4 | /** Plain keys press their own form; Shift+J/K and Alt+arrows are Down and Up; Alt+Shift combos do | |
| 5 | * nothing. Self-contained and untyped: it is shipped to the browser as its own source. */ | |
| 6 | export function keyStep(e: { key: string; shiftKey: boolean; altKey: boolean }): string | undefined { | |
| 7 | const table: Record<string, Record<string, string>> = { shift: { J: "d", K: "u" }, alt: { ArrowUp: "u", ArrowDown: "d" } }; | |
| 4 | /** A key presses the form of the same key (the keymap's T, K, J and p: keys.ts passes them); Alt+↑ | |
| 5 | * and Alt+↓ are Up and Down too; Alt+Shift combos do nothing. Self-contained and untyped: it is | |
| 6 | * shipped to the browser as its own source. */ | |
| 7 | export function keyStep(e: { key: string; shiftKey: boolean; altKey: boolean }, keys: { up: string; down: string }): string | undefined { | |
| 8 | 8 | if (e.altKey && e.shiftKey) return undefined; |
| 9 | if (e.altKey) return table.alt![e.key]; | |
| 10 | if (e.shiftKey) return table.shift![e.key]; | |
| 9 | if (e.altKey) return e.key === "ArrowUp" ? keys.up : e.key === "ArrowDown" ? keys.down : undefined; | |
| 11 | 10 | return e.key; |
| 12 | 11 | } |
src/web/pages/system.ts +4 −3
| @@ -22,6 +22,7 @@ | ||
| 22 | 22 | * against its size (#10853, `spawn/usage.ts`). |
| 23 | 23 | */ |
| 24 | 24 | import { askingOf, type Asker } from "../../perf/asking.ts"; |
| 25 | import { keyOf } from "../keymap.ts"; | |
| 25 | 26 | import { emptyNote } from "../empty_words.ts"; |
| 26 | 27 | import { sentinelRepoPath, withheldFindings, type WithheldFinding } from "../../crew/sentinel.ts"; |
| 27 | 28 | import { ownRepoRate, rateLine, RATE_MIN, type Rate } from "../../checks/deepsec_rate.ts"; |
| @@ -829,8 +830,8 @@ export async function systemPage(ctx: Ctx, patterns: () => readonly string[]): P | ||
| 829 | 830 | ${largestDirsSection(largestUnder)} |
| 830 | 831 | ${dbSizeSection(dbNow)} |
| 831 | 832 | <section class="settings-block"><h2>Processes</h2> |
| 832 | <div class="js-only small muted">Sort by <button class="btn" data-size="sm" type="button" data-sort="cpu" aria-pressed="true"><kbd>c</kbd> CPU</button> | |
| 833 | <button class="btn" data-size="sm" type="button" data-sort="mem" aria-pressed="false"><kbd>m</kbd> memory</button></div> | |
| 833 | <div class="js-only small muted">Sort by <button class="btn" data-size="sm" type="button" data-sort="cpu" aria-pressed="true">CPU</button> | |
| 834 | <button class="btn" data-size="sm" type="button" data-sort="mem" aria-pressed="false">memory</button> <kbd>${keyOf("sort")}</kbd> toggles</div> | |
| 834 | 835 | <div id="sys-procs" data-live-hold>${at("sys-procs")}</div></section> |
| 835 | 836 | ${routeUseSection(timePhase(ctx.request, "routes", () => { |
| 836 | 837 | return leastUsed(routeUsage(ctx.app.db, patterns(), new Date())); |
| @@ -851,7 +852,7 @@ export async function systemPage(ctx: Ctx, patterns: () => readonly string[]): P | ||
| 851 | 852 | ${memory} |
| 852 | 853 | ${owner ? timePhase(ctx.request, "census", () => { const r = censusReport(ctx.app.db); return heapCensusSection(r.censuses, r.grew); }) : html``} |
| 853 | 854 | ${stalePullsSection(ctx, false)}`; |
| 854 | const response = page({ ctx, title: "System", body, wide: true, scriptJs: systemLiveJs }); | |
| 855 | const response = page({ ctx, title: "System", body, wide: true, scriptJs: systemLiveJs() }); | |
| 855 | 856 | notePhase(ctx.request, "render", performance.now() - rendering); |
| 856 | 857 | return response; |
| 857 | 858 | } |
src/web/space_client.ts +9 −6
| @@ -12,6 +12,7 @@ | ||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | import { STATES, STATE_INK } from "./space_model.ts"; |
| 15 | import { keyOf } from "./keymap.ts"; | |
| 15 | 16 | import { viewJs } from "./space_view.ts"; |
| 16 | 17 | |
| 17 | 18 | /** |
| @@ -70,6 +71,8 @@ export const spaceJs = /* js */ ` | ||
| 70 | 71 | ${legendJs} |
| 71 | 72 | (function () { |
| 72 | 73 | ${viewJs} |
| 74 | // The canvas's keys are the forge's one keymap's (keymap.ts), for the space. | |
| 75 | var SK = ${JSON.stringify({ more: keyOf("more"), fewer: keyOf("fewer"), fit: keyOf("fit"), now: keyOf("now"), next: keyOf("nextBody"), prev: keyOf("prevBody") })}; | |
| 73 | 76 | var root = document.getElementById('space'); |
| 74 | 77 | var cv = document.getElementById('space-cv'); |
| 75 | 78 | if (!root || !cv || !cv.getContext) return; |
| @@ -360,12 +363,12 @@ ${viewJs} | ||
| 360 | 363 | }, { passive: false }); |
| 361 | 364 | cv.addEventListener('keydown', function (e) { |
| 362 | 365 | var step = 80 / view.k, mod = e.metaKey || e.ctrlKey, key = e.key; |
| 363 | if (key === '+' || key === '=') zoomAt(W / 2, H / 2, 1.4); | |
| 364 | else if (key === '-' || key === '_') zoomAt(W / 2, H / 2, 1 / 1.4); | |
| 365 | else if (!mod && key === '0') fit(); | |
| 366 | else if (!mod && key === 'n') goNow(); | |
| 367 | else if (key === ']') stepBody(1); | |
| 368 | else if (key === '[') stepBody(-1); | |
| 366 | if (key === SK.more || key === '=') zoomAt(W / 2, H / 2, 1.4); | |
| 367 | else if (key === SK.fewer || key === '_') zoomAt(W / 2, H / 2, 1 / 1.4); | |
| 368 | else if (!mod && key === SK.fit) fit(); | |
| 369 | else if (!mod && key === SK.now) goNow(); | |
| 370 | else if (key === SK.next) stepBody(1); | |
| 371 | else if (key === SK.prev) stepBody(-1); | |
| 369 | 372 | else if (key === 'Enter' && picked && picked.kind === 'issue') location.href = base + '/issues/' + picked.number; |
| 370 | 373 | else if (key === 'Escape' && picked) closeCard(); |
| 371 | 374 | else if (key === 'ArrowLeft') view.x -= step; |
src/web/system-live.ts +13 −8
| @@ -1,10 +1,11 @@ | ||
| 1 | 1 | /** |
| 2 | * /system's client: sorting the process table by CPU or memory (`c`, `m`, or the buttons) and one EventSource, each pushed sample patched into the | |
| 3 | * element of the id it names. No reload, no timer, no polling; EventSource | |
| 4 | * itself reconnects after a roll (the stream's `retry:` hint) and the first | |
| 5 | * frame of the new stream is the latest sample. `?pause` opens nothing. | |
| 6 | * The markup comes from our own server, escaped there, so it is set as HTML. | |
| 2 | * /system's client: sorting the process table by CPU or memory (the keymap's `S` toggles them, or | |
| 3 | * the buttons) and one EventSource, each pushed sample patched into the element of the id it names. | |
| 4 | * No reload, no timer, no polling; EventSource itself reconnects after a roll (the stream's | |
| 5 | * `retry:` hint) and the first frame of the new stream is the latest sample. `?pause` opens | |
| 6 | * nothing. The markup comes from our own server, escaped there, so it is set as HTML. | |
| 7 | 7 | */ |
| 8 | import { keyOf, oldKeys } from "./keymap.ts"; | |
| 8 | 9 | /** |
| 9 | 10 | * The ordering of the process table, apart from the page so a test can run it: |
| 10 | 11 | * `rank(items, key, kinds)` is a new array in kind order (as `kinds` lists |
| @@ -21,8 +22,11 @@ function rank(items, key, kinds) { | ||
| 21 | 22 | } |
| 22 | 23 | `; |
| 23 | 24 | |
| 24 | export const systemLiveJs = /* js */ ` | |
| 25 | /** The page's script, read at each render: the old c and m hints end on their date (keymap.ts). */ | |
| 26 | export const systemLiveJs = (): string => /* js */ ` | |
| 25 | 27 | (function () { |
| 28 | var SORT_KEY = ${JSON.stringify(keyOf("sort"))}; | |
| 29 | var OLD_SORT = ${JSON.stringify(Object.fromEntries(oldKeys("system").map((o) => [o.was, o.says])))}; | |
| 26 | 30 | ${procSortJs} |
| 27 | 31 | var KINDS = ['forge', 'crew', 'check', 'app', 'host'], key = 'cpu'; |
| 28 | 32 | function read(el) { |
| @@ -50,8 +54,9 @@ export const systemLiveJs = /* js */ ` | ||
| 50 | 54 | var t = e.target, tag = t && t.tagName; |
| 51 | 55 | if (e.ctrlKey || e.metaKey || e.altKey || tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT' || (t && t.isContentEditable)) return; |
| 52 | 56 | if ((tag === 'BUTTON' || tag === 'A') && !(t.hasAttribute && t.hasAttribute('data-sort'))) return; |
| 53 | if (e.key === 'c') pick('cpu'); else if (e.key === 'm') pick('mem'); | |
| 54 | }); | |
| 57 | if (e.key === SORT_KEY) pick(key === 'cpu' ? 'mem' : 'cpu'); | |
| 58 | else if (OLD_SORT[e.key] && window.forgeSay) { e.preventDefault(); e.stopImmediatePropagation(); window.forgeSay(OLD_SORT[e.key]); } | |
| 59 | }, true); | |
| 55 | 60 | // A region marked data-live-hold keeps the reader's place across a swap: the scroll of |
| 56 | 61 | // its table box and of itself, and the focused element, found again by a stable key |
| 57 | 62 | // (the kind and the row's first cell, the tag, its place among that tag in the row). |
test/cockpit.test.ts +15 −3
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | * own cards in the page's own order. |
| 6 | 6 | */ |
| 7 | 7 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; |
| 8 | import { OLD_KEYS_UNTIL, provideOldKeysClockForTest } from "../src/web/keymap.ts"; | |
| 8 | 9 | import { mkdtemp, rm } from "node:fs/promises"; |
| 9 | 10 | import { tmpdir } from "node:os"; |
| 10 | 11 | import { join } from "node:path"; |
| @@ -196,7 +197,7 @@ describe("the cockpit", () => { | ||
| 196 | 197 | if (!made.ok) throw new Error(JSON.stringify(made.error)); |
| 197 | 198 | return made.value.id; |
| 198 | 199 | }; |
| 199 | const drive = async (id: string, key: string): Promise<void> => { | |
| 200 | const drive = async (id: string, key: string, until = "Done."): Promise<void> => { | |
| 200 | 201 | const terminal = headlessTerminal(120, 30); |
| 201 | 202 | const { app: tui } = createForgeApp(app, { sshUsername: alice.username, remoteAddress: "127.0.0.1", fingerprint: "SHA256:test", user: alice }, { terminal, exitHooks: false }); |
| 202 | 203 | tui.start(); |
| @@ -214,15 +215,26 @@ describe("the cockpit", () => { | ||
| 214 | 215 | await settleApp(tui); |
| 215 | 216 | } |
| 216 | 217 | terminal.feed(key); |
| 217 | await settleUntil(tui, "Done."); | |
| 218 | await settleUntil(tui, until); | |
| 218 | 219 | tui.stop(); |
| 219 | 220 | }; |
| 220 | 221 | const yes = mk("Yes one"); |
| 221 | 222 | await drive(yes, "\r"); |
| 222 | 223 | expect(getProposal(app.db, yes)?.state).toBe("approved"); |
| 223 | 224 | const later = mk("Later one"); |
| 224 | await drive(later, "l"); | |
| 225 | // Later is the keymap's park, p (keymap.ts). | |
| 226 | await drive(later, "p"); | |
| 225 | 227 | expect(getProposal(app.db, later)?.state).toBe("later"); |
| 228 | // The old l, for two weeks, says p is later now and moves nothing (the clock pinned before the | |
| 229 | // date). | |
| 230 | const kept = mk("Kept one"); | |
| 231 | provideOldKeysClockForTest(new Date(Date.parse(OLD_KEYS_UNTIL) - 86_400_000)); | |
| 232 | try { | |
| 233 | await drive(kept, "l", "p is later now"); | |
| 234 | } finally { | |
| 235 | provideOldKeysClockForTest(undefined); | |
| 236 | } | |
| 237 | expect(getProposal(app.db, kept)?.state).not.toBe("later"); | |
| 226 | 238 | }); |
| 227 | 239 | |
| 228 | 240 | test("the kiosk leaves out a card that wants typed words, and keeps every other kind", () => { |
test/keymap-terminal.test.ts +1
| @@ -38,6 +38,7 @@ const OWN_R: Record<string, string> = { | ||
| 38 | 38 | "src/tui/screens/forges.ts": "restore", |
| 39 | 39 | "src/tui/screens/games.ts": "restart", |
| 40 | 40 | "src/tui/screens/hooks.ts": "redeliver", |
| 41 | "src/tui/screens/infra.ts": "restore a snapshot", | |
| 41 | 42 | "src/tui/screens/interrupted_out.ts": "try again", |
| 42 | 43 | "src/tui/screens/limbs.ts": "raise", |
| 43 | 44 | "src/tui/screens/mirror.ts": "retry", |
test/keymap.test.ts +20 −6
| @@ -5,6 +5,8 @@ | ||
| 5 | 5 | * map's moves, no key fires while typing, and the bridge is handed its verbs from the map. |
| 6 | 6 | */ |
| 7 | 7 | import { expect, test } from "bun:test"; |
| 8 | import { spaceJs } from "../src/web/space_client.ts"; | |
| 9 | import { systemLiveJs } from "../src/web/system-live.ts"; | |
| 8 | 10 | import { finderButton } from "../src/web/pages/explorer.ts"; |
| 9 | 11 | import { readdirSync, readFileSync, statSync } from "node:fs"; |
| 10 | 12 | import { join, relative } from "node:path"; |
| @@ -21,9 +23,6 @@ const ROOT = join(import.meta.dir, ".."); | ||
| 21 | 23 | * the map. This list only shrinks; a file here that no longer has a literal must leave it. |
| 22 | 24 | */ |
| 23 | 25 | const PENDING: Record<string, string> = { |
| 24 | "src/web/pages/next.ts": "(d): Top, Up, Down and Not now are t, u, d and l, which Tell, Update and Right own", | |
| 25 | "src/web/space_client.ts": "(d): n jumps the space to now", | |
| 26 | "src/web/system-live.ts": "(d): c and m pick CPU and memory, which Write and Merge own", | |
| 27 | 26 | }; |
| 28 | 27 | |
| 29 | 28 | /** |
| @@ -89,6 +88,7 @@ test("a moved key says where it went for two weeks, then nothing: the date is in | ||
| 89 | 88 | expect(oldKeys("review", before).map((o) => [o.was, o.key])).toEqual([["c", "x"], ["r", "b"]]); |
| 90 | 89 | expect(oldKeys("pull", new Date(OLD_KEYS_UNTIL))).toEqual([]); |
| 91 | 90 | expect(oldKeys("files", before)).toEqual([{ was: "t", key: "f", says: "f is go to file now" }]); |
| 91 | expect(oldKeys("cockpit", before)).toEqual([{ was: "l", key: "p", says: "p is later now" }]); | |
| 92 | 92 | expect(oldKeys("runs", before).map((o) => [o.was, o.key])).toEqual([["x", "s"], ["S", "i"], ["a", "r"]]); |
| 93 | 93 | expect(oldKeys("review", new Date(Date.parse(OLD_KEYS_UNTIL) + 86_400_000))).toEqual([]); |
| 94 | 94 | // Two weeks from the change, not a standing alias. |
| @@ -110,6 +110,21 @@ test("Go to file is the keymap's f on a repository's files, and t, for two weeks | ||
| 110 | 110 | expect(after).not.toContain("data-was="); |
| 111 | 111 | }); |
| 112 | 112 | |
| 113 | test("the space's canvas and /system's sort take their keys from the map; /system's c and m say S for two weeks", () => { | |
| 114 | expect(spaceJs).toContain('var SK = {"more":"+","fewer":"-","fit":"0","now":"n","next":"]","prev":"["};'); | |
| 115 | provideOldKeysClockForTest(new Date(Date.parse(OLD_KEYS_UNTIL) - 86_400_000)); | |
| 116 | const sys = systemLiveJs(); | |
| 117 | provideOldKeysClockForTest(new Date(OLD_KEYS_UNTIL)); | |
| 118 | const sysAfter = systemLiveJs(); | |
| 119 | provideOldKeysClockForTest(undefined); | |
| 120 | expect(sys).toContain('var SORT_KEY = "S";'); | |
| 121 | expect(sys).toContain('"c":"S is sort now","m":"S is sort now"'); | |
| 122 | expect(sysAfter).toContain("var OLD_SORT = {};"); | |
| 123 | // Read in capture, so the hint is said before the shell's own c can act. | |
| 124 | expect(sys).toContain("e.stopImmediatePropagation(); window.forgeSay(OLD_SORT[e.key]); }\n }, true);"); | |
| 125 | expect(oldKeys("next", new Date(Date.parse(OLD_KEYS_UNTIL) - 1)).map((o) => [o.was, o.key])).toEqual([["t", "T"], ["u", "K"], ["d", "J"], ["l", "p"]]); | |
| 126 | }); | |
| 127 | ||
| 113 | 128 | test("a repository's tabs are g jumps of their own, and shadow a forge-wide one only where the map says", () => { |
| 114 | 129 | const tabs = Object.values(REPO_TABS); |
| 115 | 130 | expect(new Set(tabs).size).toBe(tabs.length); |
| @@ -125,9 +140,8 @@ test("the shell says where a moved key went, and a quick second key still finds | ||
| 125 | 140 | |
| 126 | 141 | test("both doors share one meaning per key: R refreshes a terminal screen, / filters or searches, r queues a run again", () => { |
| 127 | 142 | expect([keyOf("reread"), keyOf("search"), keyOf("requeue"), keyOf("stop"), keyOf("wheel")]).toEqual(["R", "/", "r", "s", "i"]); |
| 128 | // No terminal key differs from the web's here: the run cards on the issue and pull screens steer | |
| 129 | // on i, as the run list does. | |
| 130 | expect((Object.entries(KEYMAP) as [string, KeyDef][]).filter(([, d]) => d.terminal !== undefined).map(([id]) => id)).toEqual([]); | |
| 143 | // The only terminal key that differs is listed with why: not now on the Next up screen. | |
| 144 | expect((Object.entries(KEYMAP) as [string, KeyDef][]).filter(([, d]) => d.terminal !== undefined).map(([id]) => id)).toEqual(["park"]); | |
| 131 | 145 | expect(oldKeys("terminal", new Date(Date.parse(OLD_KEYS_UNTIL) - 1))).toEqual([{ was: "r", key: "R", says: "R is refresh now" }]); |
| 132 | 146 | }); |
| 133 | 147 |
test/next-keys.test.ts +60 −22
| @@ -12,7 +12,10 @@ import { createSession } from "../src/core/sessions.ts"; | ||
| 12 | 12 | import { createUser } from "../src/core/users.ts"; |
| 13 | 13 | import { serve, type Servers } from "../src/http/server.ts"; |
| 14 | 14 | import { keyStep } from "../src/web/pages/next_keys.ts"; |
| 15 | import { KEYS_JS } from "../src/web/pages/next.ts"; | |
| 15 | import { keysJs } from "../src/web/pages/next.ts"; | |
| 16 | import { OLD_KEYS_UNTIL, provideOldKeysClockForTest } from "../src/web/keymap.ts"; | |
| 17 | import { findChromium } from "../src/looks/capture.ts"; | |
| 18 | import { chromiumRuns, evaluateLoaded } from "./helpers/chrome.ts"; | |
| 16 | 19 | |
| 17 | 20 | let dir: string; |
| 18 | 21 | let app: App; |
| @@ -68,40 +71,75 @@ const press = async (number: number, key: string) => { | ||
| 68 | 71 | test("the page carries the key hooks and lists them in its help", async () => { |
| 69 | 72 | const html = await page(); |
| 70 | 73 | const row = new RegExp(`<li[^>]*data-number="${numbers[1]}"[\\s\\S]*?</li>`).exec(html)![0]; |
| 71 | for (const k of ["t", "u", "d", "l"]) expect(row).toContain(`data-key="${k}"`); | |
| 72 | expect(html).toContain("t top · l Later"); | |
| 73 | expect(html).toContain("Shift+J"); | |
| 74 | expect(html).toContain("Alt+"); | |
| 75 | expect(KEYS_JS).toContain("next-focus"); | |
| 74 | // The keymap's Top, Up, Down and Not now (keymap.ts): T, K, J and p. | |
| 75 | for (const k of ["T", "K", "J", "p"]) expect(row).toContain(`data-key="${k}"`); | |
| 76 | expect(html).toContain("T top · p Later · J/K or Alt+↓/↑ down/up"); | |
| 77 | expect(keysJs()).toContain("next-focus"); | |
| 78 | // The old t, u, d and l say the new key for two weeks, then the script carries none. | |
| 79 | provideOldKeysClockForTest(new Date(Date.parse(OLD_KEYS_UNTIL) - 86_400_000)); | |
| 80 | const hinted = keysJs(); | |
| 81 | provideOldKeysClockForTest(new Date(OLD_KEYS_UNTIL)); | |
| 82 | const after = keysJs(); | |
| 83 | provideOldKeysClockForTest(undefined); | |
| 84 | expect(hinted).toContain('"t":"T is top now"'); | |
| 85 | expect(after).toContain("const OLD = {};"); | |
| 76 | 86 | }); |
| 77 | 87 | |
| 78 | 88 | test("each key submits the existing form and the order follows", async () => { |
| 79 | 89 | const [a, b, c, d] = numbers as [number, number, number, number]; |
| 80 | await press(c, "t"); // t: to the top | |
| 90 | await press(c, "T"); // T: to the top | |
| 81 | 91 | expect(order()).toEqual([c, a, b, d]); |
| 82 | await press(c, "d"); // Shift+J / Alt+Down: one place down | |
| 92 | await press(c, "J"); // J / Alt+Down: one place down | |
| 83 | 93 | expect(order()).toEqual([a, c, b, d]); |
| 84 | await press(d, "u"); // Shift+K / Alt+Up: one place up | |
| 94 | await press(d, "K"); // K / Alt+Up: one place up | |
| 85 | 95 | expect(order()).toEqual([a, c, d, b]); |
| 86 | await press(a, "l"); // l: behind the Later gate | |
| 96 | await press(a, "p"); // p: behind the Later gate (park) | |
| 87 | 97 | expect(order()).toEqual([c, d, b]); |
| 88 | 98 | }); |
| 89 | 99 | |
| 90 | 100 | const ev = (key: string, mods: { shiftKey?: boolean; altKey?: boolean } = {}) => ({ key, shiftKey: false, altKey: false, ...mods }); |
| 91 | 101 | |
| 92 | test("keyStep maps modifiers to the form keys", () => { | |
| 93 | expect(keyStep(ev("t"))).toBe("t"); | |
| 94 | expect(keyStep(ev("l"))).toBe("l"); | |
| 95 | expect(keyStep(ev("J", { shiftKey: true }))).toBe("d"); | |
| 96 | expect(keyStep(ev("K", { shiftKey: true }))).toBe("u"); | |
| 97 | expect(keyStep(ev("ArrowDown", { altKey: true }))).toBe("d"); | |
| 98 | expect(keyStep(ev("ArrowUp", { altKey: true }))).toBe("u"); | |
| 99 | expect(keyStep(ev("ArrowUp"))).toBe("ArrowUp"); // plain arrows have no form: no row lookup matches | |
| 100 | expect(keyStep(ev("J", { altKey: true }))).toBeUndefined(); | |
| 101 | expect(keyStep(ev("T", { shiftKey: true }))).toBeUndefined(); | |
| 102 | expect(keyStep(ev("ArrowDown", { altKey: true, shiftKey: true }))).toBeUndefined(); | |
| 102 | test("keyStep: a key presses its own form, and Alt+arrows are Up and Down", () => { | |
| 103 | const keys = { up: "K", down: "J" }; | |
| 104 | expect(keyStep(ev("T", { shiftKey: true }), keys)).toBe("T"); | |
| 105 | expect(keyStep(ev("p"), keys)).toBe("p"); | |
| 106 | expect(keyStep(ev("J", { shiftKey: true }), keys)).toBe("J"); | |
| 107 | expect(keyStep(ev("K", { shiftKey: true }), keys)).toBe("K"); | |
| 108 | expect(keyStep(ev("ArrowDown", { altKey: true }), keys)).toBe("J"); | |
| 109 | expect(keyStep(ev("ArrowUp", { altKey: true }), keys)).toBe("K"); | |
| 110 | expect(keyStep(ev("ArrowUp"), keys)).toBe("ArrowUp"); // plain arrows have no form: no row lookup matches | |
| 111 | expect(keyStep(ev("J", { altKey: true }), keys)).toBeUndefined(); | |
| 112 | expect(keyStep(ev("ArrowDown", { altKey: true, shiftKey: true }), keys)).toBeUndefined(); | |
| 103 | 113 | }); |
| 104 | 114 | |
| 105 | 115 | test("the shipped script carries the same function", () => { |
| 106 | expect(KEYS_JS).toContain(keyStep.toString()); | |
| 116 | expect(keysJs()).toContain(keyStep.toString()); | |
| 107 | 117 | }); |
| 118 | ||
| 119 | const found = findChromium(); | |
| 120 | const chromium = found !== undefined && chromiumRuns(found) ? found : undefined; | |
| 121 | const noBrowser = chromium === undefined && (process.env["FORGE_CHECK"] ?? "") === ""; | |
| 122 | if (noBrowser) console.log("SKIPPING: no chromium that starts on this machine, so /next's keys are not pressed"); | |
| 123 | ||
| 124 | test.skipIf(noBrowser)("in a browser, the old t on a focused row says T is top now, moves nothing, and the shell's t (Tell the crew) never takes the focus", async () => { | |
| 125 | if (chromium === undefined) throw new Error("no Chromium starts in this check, so /next's keys are not pressed: the check's image must carry one (FORGE_CHROMIUM)"); | |
| 126 | const before = order(); | |
| 127 | provideOldKeysClockForTest(new Date(Date.parse(OLD_KEYS_UNTIL) - 86_400_000)); | |
| 128 | try { | |
| 129 | const [name, value] = cookie.split("=") as [string, string]; | |
| 130 | const out = JSON.parse(await evaluateLoaded(chromium, `${servers.url}/alice/keys/next`, { width: 1280, height: 900 }, [{ name, value }], `(async () => { | |
| 131 | const row = document.querySelectorAll('li[data-number]')[1]; | |
| 132 | const link = row.querySelector('a'); | |
| 133 | link.focus(); | |
| 134 | link.dispatchEvent(new KeyboardEvent('keydown', { key: 't', bubbles: true, cancelable: true })); | |
| 135 | await new Promise((r) => requestAnimationFrame(r)); | |
| 136 | return JSON.stringify({ said: document.querySelector('.toast[data-key-says]')?.textContent.trim() ?? null, focusInRow: row.contains(document.activeElement), path: location.pathname }); | |
| 137 | })()`)) as { said: string | null; focusInRow: boolean; path: string }; | |
| 138 | expect(out.said).toBe("T is top now"); | |
| 139 | expect(out.focusInRow).toBe(true); | |
| 140 | expect(out.path).toBe("/alice/keys/next"); | |
| 141 | expect(order()).toEqual(before); | |
| 142 | } finally { | |
| 143 | provideOldKeysClockForTest(undefined); | |
| 144 | } | |
| 145 | }, 30_000); |
test/next-up.test.ts +2 −2
| @@ -180,8 +180,8 @@ describe("Next up", () => { | ||
| 180 | 180 | expect(writer).toContain(`value="${n.b}"`); |
| 181 | 181 | expect(writer).toContain("Not now"); |
| 182 | 182 | // The key is shown beside each action, and the rows take j/k. |
| 183 | for (const key of ["t", "u", "d", "l"]) expect(writer).toContain(`data-key="${key}"`); | |
| 184 | expect(writer).toContain("<kbd>t</kbd>"); | |
| 183 | for (const key of ["T", "K", "J", "p"]) expect(writer).toContain(`data-key="${key}"`); | |
| 184 | expect(writer).toContain("<kbd>T</kbd>"); | |
| 185 | 185 | expect(writer).toContain("data-nav"); |
| 186 | 186 | expect(writer).toContain("Blocker"); |
| 187 | 187 | expect(writer).toContain("Enabler"); |
test/system-btop.test.ts +1 −1
| @@ -158,7 +158,7 @@ describe("/system as btop", () => { | ||
| 158 | 158 | }); |
| 159 | 159 | |
| 160 | 160 | test("hotkeys are ignored on a focused button or link, except the sort buttons", () => { |
| 161 | expect(systemLiveJs).toContain("(tag === 'BUTTON' || tag === 'A') && !(t.hasAttribute && t.hasAttribute('data-sort'))"); | |
| 161 | expect(systemLiveJs()).toContain("(tag === 'BUTTON' || tag === 'A') && !(t.hasAttribute && t.hasAttribute('data-sort'))"); | |
| 162 | 162 | }); |
| 163 | 163 | |
| 164 | 164 | test("the terminal's System view has the cores with history, swap, rates and the top processes", () => { |
test/system-stream.test.ts +1 −1
| @@ -188,7 +188,7 @@ describe("/system's process table holds the reader's place", () => { | ||
| 188 | 188 | class FakeSource { |
| 189 | 189 | addEventListener(_: string, fn: typeof listener) { listener = fn; } |
| 190 | 190 | } |
| 191 | new Function("document", "EventSource", "location", systemLiveJs)(doc, FakeSource, { search: "" }); | |
| 191 | new Function("document", "EventSource", "location", systemLiveJs())(doc, FakeSource, { search: "" }); | |
| 192 | 192 | const push = (regions: Record<string, string>) => listener({ data: JSON.stringify({ regions }) }); |
| 193 | 193 | return { doc, push }; |
| 194 | 194 | } |
test/tui-next-up.test.ts +16 −7
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * hears it. |
| 7 | 7 | */ |
| 8 | 8 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; |
| 9 | import { OLD_KEYS_UNTIL, provideOldKeysClockForTest } from "../src/web/keymap.ts"; | |
| 9 | 10 | import { mkdtemp, rm } from "node:fs/promises"; |
| 10 | 11 | import { tmpdir } from "node:os"; |
| 11 | 12 | import { join } from "node:path"; |
| @@ -108,11 +109,19 @@ describe("next up in the terminal", () => { | ||
| 108 | 109 | const before = order(); |
| 109 | 110 | expect(before).toEqual([n.a!, n.b!]); |
| 110 | 111 | |
| 111 | // Down, then Top on the row the cursor followed. | |
| 112 | // The old d, for two weeks, says the new key and moves nothing (keymap.ts OLD_KEYS). | |
| 113 | provideOldKeysClockForTest(new Date(Date.parse(OLD_KEYS_UNTIL) - 86_400_000)); | |
| 112 | 114 | await h.press("d"); |
| 115 | provideOldKeysClockForTest(undefined); | |
| 116 | expect(order()).toEqual(before); | |
| 117 | expect(heard).toHaveLength(0); | |
| 118 | expect(h.text()).toContain("J is down now"); | |
| 119 | ||
| 120 | // Down, then Top on the row the cursor followed. | |
| 121 | await h.press("J"); | |
| 113 | 122 | expect(order()[1]).toBe(before[0]!); |
| 114 | 123 | expect(heard).toHaveLength(1); |
| 115 | await h.press("t"); | |
| 124 | await h.press("T"); | |
| 116 | 125 | expect(order()[0]).toBe(before[0]!); |
| 117 | 126 | expect(heard).toHaveLength(2); |
| 118 | 127 | |
| @@ -161,13 +170,13 @@ describe("next up in the terminal", () => { | ||
| 161 | 170 | // Down from the top, then Top again: the order of the rows that can start stays in step with the screen. |
| 162 | 171 | const startable = (): number[] => nextUp(forge.db, repo).rows.filter((r) => r.state === "ready").map((r) => r.issue.number); |
| 163 | 172 | const before = startable(); |
| 164 | await h.press("d"); | |
| 173 | await h.press("J"); | |
| 165 | 174 | expect(startable()).toEqual([before[1]!, before[0]!]); |
| 166 | await h.press("t"); | |
| 175 | await h.press("T"); | |
| 167 | 176 | expect(startable()).toEqual(before); |
| 168 | 177 | expect(order().at(-1)).toBe(waiting); |
| 169 | 178 | // The blocked row itself can be lifted to the top: it is ranked, and still waits. |
| 170 | await h.press("j", "j", "t"); | |
| 179 | await h.press("j", "j", "T"); | |
| 171 | 180 | const row = nextUp(forge.db, repo).rows[0]!; |
| 172 | 181 | expect(row.issue.number).toBe(waiting); |
| 173 | 182 | expect(row.state).toBe("blocked"); |
| @@ -180,7 +189,7 @@ describe("next up in the terminal", () => { | ||
| 180 | 189 | await h.toNext("alice/plan"); |
| 181 | 190 | expect(h.text()).toContain("you can read this order, not change it"); |
| 182 | 191 | const before = order(); |
| 183 | await h.press("j", "t", "l", "d"); | |
| 192 | await h.press("j", "T", "l", "J"); | |
| 184 | 193 | expect(order()).toEqual(before); |
| 185 | 194 | h.stop(); |
| 186 | 195 | }); |
| @@ -206,7 +215,7 @@ describe("next up in the terminal", () => { | ||
| 206 | 215 | expect(text).not.toContain("Work a"); |
| 207 | 216 | expect(text).toContain(`${before.indexOf(n.b!) + 1}. #` + n.b); // its place in the whole ranking |
| 208 | 217 | // Top moves the row under the cursor in the whole order, not in the shown one. |
| 209 | await h.press("t"); | |
| 218 | await h.press("T"); | |
| 210 | 219 | expect(order()[0]).toBe(n.b!); |
| 211 | 220 | expect(order()).toHaveLength(before.length); |
| 212 | 221 | // Clear: empty submit. |
test/week-doors.test.ts +4 −4
| @@ -28,7 +28,7 @@ import { createUser, getUserByName, type User } from "../src/core/users.ts"; | ||
| 28 | 28 | import { latestRetro, takenOf, tickWeeks, failureClass } from "../src/flow/retro.ts"; |
| 29 | 29 | import { CUT_TOP_WORDS, cutLine, cutWords, FIT_COUNT_JS, rowCosts, weekView } from "../src/flow/week.ts"; |
| 30 | 30 | import { serve, type Servers } from "../src/http/server.ts"; |
| 31 | import { KEYS_JS } from "../src/web/pages/next.ts"; | |
| 31 | import { keysJs } from "../src/web/pages/next.ts"; | |
| 32 | 32 | import { Window } from "happy-dom"; |
| 33 | 33 | import { createForgeApp } from "../src/tui/forge.ts"; |
| 34 | 34 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; |
| @@ -180,8 +180,8 @@ describe("the week's doors", () => { | ||
| 180 | 180 | const without = page.replace(/ data-capacity="[^"]*"/, ""); |
| 181 | 181 | expect(without).not.toContain("data-capacity"); |
| 182 | 182 | // The server and the script say the same sentences. |
| 183 | expect(KEYS_JS).toContain(JSON.stringify(CUT_TOP_WORDS)); | |
| 184 | expect(KEYS_JS).toContain(JSON.stringify(cutWords("{n}"))); | |
| 183 | expect(keysJs()).toContain(JSON.stringify(CUT_TOP_WORDS)); | |
| 184 | expect(keysJs()).toContain(JSON.stringify(cutWords("{n}"))); | |
| 185 | 185 | }); |
| 186 | 186 | |
| 187 | 187 | test("dragging a row moves the line before any save, and a refusal puts it back", async () => { |
| @@ -201,7 +201,7 @@ describe("the week's doors", () => { | ||
| 201 | 201 | }; |
| 202 | 202 | const location = { pathname: "/alice/plan/next", reload: () => { reloaded = true; } }; |
| 203 | 203 | const store = { getItem: () => null, setItem: () => {}, removeItem: () => {} }; |
| 204 | new Function("document", "sessionStorage", "fetch", "location", "FormData", KEYS_JS)(doc, store, fetcher, location, window.FormData); | |
| 204 | new Function("document", "sessionStorage", "fetch", "location", "FormData", keysJs())(doc, store, fetcher, location, window.FormData); | |
| 205 | 205 | const lis = [...list.querySelectorAll("li[data-number]")]; |
| 206 | 206 | const fire = (el: { dispatchEvent(e: unknown): boolean }, type: string) => el.dispatchEvent(new window.Event(type, { bubbles: true, cancelable: true })); |
| 207 | 207 | fire(lis[0]!, "dragstart"); |
new above
offline
Stray extra blank line before
Proof:; remove one.