diff --git a/core/src/saved.rs b/core/src/saved.rs index 6fc360af..21b58ce7 100644 --- a/core/src/saved.rs +++ b/core/src/saved.rs @@ -7,10 +7,11 @@ use crate::Studio; use std::{cell::Cell, collections::BTreeMap, fmt}; -/// The saved state's format. Bump it when a saved field changes meaning or a field the pane's JSON -/// leaves out is added, so an older file is not read as the new shape: a field the old file lacks -/// makes it unreadable anyway, unless it has a default. -const FORMAT: u32 = 10; +/// The saved state's format. Bump it when a saved field changes meaning, the replay makes a saved +/// field differently (11: a pasted prompt's turn line, #824), or a field the pane's JSON leaves out +/// is added, so an older file is not read as the new shape and the first launch replays the whole +/// log: a field the old file lacks makes it unreadable anyway, unless it has a default. +const FORMAT: u32 = 11; thread_local! { static SAVING: Cell = const { Cell::new(false) }; diff --git a/core/src/session.rs b/core/src/session.rs index 060bad55..258a6dc2 100644 --- a/core/src/session.rs +++ b/core/src/session.rs @@ -1324,13 +1324,7 @@ impl Session { let line = match &prompt.sender { // From the wake-up's own task: a queued one's turn starts after the row's `returned` may be cleared. Sender::WakeUp(task_id) => format!("worker {} returned", self.agent_name(task_id)), - _ => prompt - .text - .lines() - .map(str::trim) - .find(|l| !l.is_empty()) - .unwrap_or_default() - .into(), + _ => prompt_line(&prompt.text), }; if let Some(turn) = self.turns.last_mut().filter(|t| t.prompt.is_empty()) { turn.prompt = line; @@ -1682,3 +1676,41 @@ pub(crate) fn card_time(id: &str) -> u64 { pub(crate) fn short(id: &str, n: usize) -> &str { id.get(..n).unwrap_or(id) } + +/// A prompt's line in the feed: its first non-empty line once every `` and +/// `` tag is removed, wherever it sits (#824), and `Pasted text` for a +/// prompt whose paste holds no text. +fn prompt_line(text: &str) -> String { + let mut kept = String::with_capacity(text.len()); + let mut pasted = false; + let mut rest = text; + while let Some(at) = rest.find("<") { + kept.push_str(&rest[..at]); + let tag = &rest[at..]; + match pasted_tag_len(tag) { + Some(len) => { + pasted = true; + rest = &tag[len..]; + } + None => { + kept.push('<'); + rest = &tag[1..]; + } + } + } + kept.push_str(rest); + match kept.lines().map(str::trim).find(|l| !l.is_empty()) { + Some(line) => line.into(), + None if pasted => "Pasted text".into(), + None => String::new(), + } +} + +/// The length of the pasted-content tag `text` starts with, opening or closing, if it starts with one. +fn pasted_tag_len(text: &str) -> Option { + let after = (text.strip_prefix("")?; + (digits > 0).then(|| text.len() - close.len()) +} diff --git a/core/tests/saved.rs b/core/tests/saved.rs index c1831b8d..df0902ed 100644 --- a/core/tests/saved.rs +++ b/core/tests/saved.rs @@ -91,9 +91,12 @@ fn saved_state_of_another_format_or_beside_a_shorter_log_is_ignored() { }; let newline = saved.iter().position(|b| *b == b'\n').unwrap(); - let mut other_format = b"studio-state 0".to_vec(); - other_format.extend(&saved[newline..]); - again(&other_format, log.len() as u64); + // Format 10 is the build's before #824, whose turns kept a pasted prompt's tag as their line. + for format in ["studio-state 0", "studio-state 10"] { + let mut other_format = format.as_bytes().to_vec(); + other_format.extend(&saved[newline..]); + again(&other_format, log.len() as u64); + } again(&with_terminals(&saved), log.len() as u64); again(&saved, log.len() as u64 - 1); again(&saved[..saved.len() / 2], log.len() as u64); diff --git a/core/tests/turns.rs b/core/tests/turns.rs index 1f656c83..8326b603 100644 --- a/core/tests/turns.rs +++ b/core/tests/turns.rs @@ -178,24 +178,68 @@ fn opened(log: &str) -> Vec<(String, bool)> { } /// danielrispler/plotkeeper#675: a queued prompt's turn is marked by who sent it, a wake-up's or -/// Daniel's, as a prompt that opens its turn is. +/// Daniel's, as a prompt that opens its turn is. Daniel's is named by its prompt's first line once +/// every pasted-content tag is removed (#824), a wake-up's by the worker that returned. #[test] -fn a_queued_wake_up_marks_the_turn_it_starts_and_daniels_queued_prompt_does_not() { - let wake_up = r#"…"#; +fn a_queued_prompt_marks_and_names_the_turn_it_starts() { let queued = r#"…"#; - let woken = QUEUED.replacen(queued, wake_up, 1); - assert_ne!(woken, QUEUED); + let rows = [ + // The fixture's own prompt. + ("a one-line paste", queued, "…", false), + ( + "a paste over several lines", + r#"\n\n First pasted line\nsecond\n"#, + "First pasted line", + false, + ), + ( + "typed text before the paste", + r#"\nLook at this:\npasted"#, + "Look at this:", + false, + ), + ( + "a paste inside a typed line", + r#"Fix the bug now"#, + "Fix the bug now", + false, + ), + ( + "an empty paste", + r#""#, + "Pasted text", + false, + ), + ( + "a paste of blank lines", + r#"\n \n"#, + "Pasted text", + false, + ), + ( + "a wake-up", + r#"…"#, + "worker ", + true, + ), + ]; + for (case, prompt, line, woken) in rows { + let log = QUEUED.replacen(queued, prompt, 1); + assert!(log.contains(prompt), "{case}"); - let daniels = opened(QUEUED); - let wakes = opened(&woken); + let turns = opened(&log); - // The turn before has no prompt in the cut; the wake-up turn is marked either way. - assert_eq!(daniels.len(), 3); - assert_eq!((daniels[1].1, wakes[1].1), (true, true)); - // The turn the queued prompt starts, which its text names. - assert_eq!(daniels[2], (queued.replace('\\', ""), false)); - assert!(wakes[2].1, "{wakes:?}"); - assert!(wakes[2].0.starts_with("worker "), "{wakes:?}"); + // The turn before has no prompt in the cut; the wake-up turn is marked either way. + assert_eq!(turns.len(), 3, "{case}"); + assert!(turns[1].1, "{case}"); + // The turn the queued prompt starts. + assert_eq!(turns[2].1, woken, "{case}"); + if woken { + assert!(turns[2].0.starts_with(line), "{case}: {turns:?}"); + } else { + assert_eq!(turns[2].0, line, "{case}"); + } + } } /// danielrispler/plotkeeper#675: a queued wake-up's turn names the worker that returned even when the running turn's own step diff --git a/docs/studio/behaviour/map.md b/docs/studio/behaviour/map.md index d9111b71..93097cfd 100644 --- a/docs/studio/behaviour/map.md +++ b/docs/studio/behaviour/map.md @@ -336,7 +336,7 @@ The window's Map view (`ui/map.ts`, `server/src/map.rs`) draws a project's map o - **No map.** A project without the file shows a calm empty state, and shows the drafting prompt to give to a session in the project, with a copy icon beside it (`ui/copy-button.ts`, the PR brief's): a press puts the prompt on the clipboard and the copy toast says "Prompt copied", or holds the prompt to copy by hand when the clipboard refuses. The page starts no session. - **Fog** (`server/src/fog.rs`). The first time the view opens a project, the server records the default branch's tip, so every part starts clear. After that it walks the new first-parent commits and files each part's changes in `map-state.json`: **thick** when a law on the part, a link at it (its id or ends), a flow through it or its `paths` changed, or the part was added; **thin** when files it owns changed (placed by the union of the commit's map and its parent's, so a moved file touches both parts) or only its name, caption, purpose or held items (their paths included) did, or the `kind` or `reason` of a link at it; nothing for `zone`, `ignored` or `tier`. A removed part leaves the live map. Each entry keeps its commit, its strength, the PR its subject names (`Title (#N)`, else none) and why it fogs the part (#495, `fog::Change`): "added", "paths", `law `, `link ` and `flow ` for each law, link or flow whose say on the part changed (a link's kind or reason too), each of the part's own words that changed (`name`, `caption`, `purpose`, `holds`), and the count of its files changed (`3 files`). An entry filed before #495 has neither PR nor why. What shows is by Daniel's effective tier: a Black box part never, an Interface-only part only thick. Strength is never a count. **Reading a brief clears it** (#342): a chapter is complete when its last step was seen (`watchSeen`) and its check was answered, right or wrong, when it holds one; a single story is one chapter over all its lit parts. Once every chapter of a PR's brief that lights a part is complete, that PR's entries leave that part at once and the mist lifts; a part no chapter lights keeps its fog, and leaving mid-chapter clears nothing. Completion is kept as "read at head X" per chapter in `map-state.json` (`fog.reads`). A PR read before it merges files fog at merge only for the parts touched by the diff from X to the squash commit, limited to the paths the squash commit itself changes (so main merged into the branch fogs nothing), at the strength that diff earns; none when nothing was pushed after the read. A read carried over to a new head (a pure rebase, or a push that fogs nothing; [Since you read](pr-briefs.md#ready-detection)) counts as read at that head, so fog at merge runs from it and a rebase does not pull main's edits into the PR's fog. "I know this" still clears a whole part, and so does reading its [part catch-up](pr-briefs.md#part-catch-ups) to the end, for the entries it covered. - **Mist.** A fogged plate has a cool-grey mist around it (#455): dense beyond the plate's edges and at its rim, thinning to nothing over its name, caption and marks, so they read at full contrast (4.5:1, measured by snap's contrast pass); the caption is not dimmed. Thin and thick still read apart: thick is denser, with a rim and a slow drift. "I know this" on the part's sheet clears that part's fog and lifts the mist (no motion under reduced motion), and is logged as its own event (Stop rules). -- **The part sheet** (`ui/map-sheet.ts`) opens over the map's top right, in the left panel's glass, on a click that was not a drag (a press on a session badge opens its list instead, and a press in that list never reaches the plate). First, under its name and caption, why its plate carries its marks (#495, `sheetMarks` in `ui/map-model.ts`), from this case's facts and only for the marks it carries: its fog as the newest thick entry (else the newest) with its PR (else its commit) and why, then "+N more" for the other entries, or an older entry's strength and commit alone; its staleness band's line (below); and a broken law's line (below). A past commit's sheet shows none. Then the catch-up card: for a fogged part, how many changes landed, the waiting [part catch-up](pr-briefs.md#part-catch-ups)'s outline and its main button (or the one PR brief chapter that lights it) with "I know this" as the quiet second; on a part with no fog, "Caught up" and the refresher (below). Then the purpose, clamped to two lines with "More" (shown only when it runs longer; "Less" clamps it again), and a row of chips (the tier, the laws, the links, and CI when the sheet shows CI), each opening its section and bringing it into view (#637). Then the sections, each a fold that opens on its own and shows a short value beside its title (none for History, whose rows load later), in this order: **Laws** (backed by a check or on trust), **Talks to** (every link at either end of the part, in the map's order: an arrow, → when the link runs from this part and ← when it runs to it, the other end, the link's kind and its reason when it has one; the sheet has no other list of links; "No link at this part" when there is none), **This session here** (below), **Holds** (the held items, each its name, its sentence and its key files, its `paths` as written; an item without paths is a note, its name in italics followed by "· note", then its sentence, so it never reads as a heading, #525; none when the part holds nothing), **Tier** (Core, Interface-only, Black box; changed in place and kept in `map-state.json`), **CI on main** (below, whenever the sheet shows CI) and **History** (the history strip, below). When a run on main breaks one of the part's laws, CI on main comes first, open. The folds Daniel opened stay open in this browser (`map-sheet-folds`, beside the sheet's width); a browser that keeps nothing starts with all folded. The first Esc closes it; the next closes the left panel, if open. × (named "Close") closes it too, and so does a click on the empty map (#445): a press on the background that moves 4 px or less between down and up closes the sheet and its drawer, while one that moves further pans and keeps them. A click on another part switches the sheet to that part. The not placed line, the sheet, the drawer under it and the background runs are one column at most the map's height less its insets, the line first, so it keeps the map's top right and an open sheet never pushes it down over a part (#466). The not placed line is one line of fixed height, and while a sheet is open its slot keeps that height even with no line in it, so sessions starting and stopping to need Daniel never move the sheet (#472, #694; in the event log the list changed about every 30 s while agents ran). The column scrolls as one: the sheet and the drawer never scroll on their own (a drawer's code block keeps its own short scroll), and a scroll past its end never moves the map. The sheet is 360 px wide at first; dragging its left edge resizes it between 300 px and half the map, and so do the left and right arrow keys while that edge has the focus. The width is kept in this browser, and a double-click on the edge puts it back to 360 px. **The sheet explains itself** (spec #520, #522): while the page-wide `explanations` setting is on (the default), each fold (Laws, Talks to, This session here, Holds, Tier, CI on main, History) has one muted line first in its body, shown when it is open, and the catch-up card one under its eyebrow; the selected tier's meaning sits under the tier buttons, and every tier button's hint is its meaning; in Talks to, a link kind's line follows only the first link of that kind, and "Not yet ratified"'s only the first unratified link; a fogged part has one line under its fog buttons saying what the buttons shown do: Part catch-up and I know this, the PR brief chapter's button and I know this, or I know this alone, each button described by it. Each fold's summary and the selected tier carry `aria-describedby` to their line; while off, no line is drawn and no attribute points at one. A `?` toggle beside the × (named "Explanations", with `aria-pressed`; hint "Hide explanations" or "Show explanations"; filled when on, a muted ring when off) flips the setting through the server's settings write (`set_explanations`), and so does the palette's `studio::ToggleExplanations`; the open sheet draws again at once, and a `?` that had the focus keeps it. A flip while a write is in flight waits for its reply, so a double click ends where it started and no write is refused as stale. Every text is in `ui/explanations.ts`, worded to "you", at most 12 words each. **This session here** (spec #549, #561): while a session's story is open in the left panel beside the sheet, a fold, third after Laws and Talks to, lists the open session's turns of the last 7 days (the page's cut: a turn's end, or its start if it never ended) that changed the part, Workers' files included, newest first, each its number in the story (from 1), its Headline (else its prompt's first line) and its age (minutes, hours, then days). With none it says "No turn of this session changed this part in the last 7 days", but nothing while `map_place` has yet to answer for a file of those turns; the section, and the newest turn's "Show on map", follow a new answer when it lands, and "Turns older than 7 days aren't listed" shows under it only when the session has older turns. Pressing a row scrolls the story to the turn, unfolds it, moves the focus to its line and flashes its outline once in the warm ring (held still for that second under reduced motion), then pans the turn's parts clear of the panel and the sheet (`revealParts`). The section follows the story as it changes, keeps a focused row's focus, and is not drawn for a subagent's view or on a past commit's sheet. Below 1007 px the sheet takes the panel's place, so the section never shows there, and no session is remembered for it. +- **The part sheet** (`ui/map-sheet.ts`) opens over the map's top right, in the left panel's glass, on a click that was not a drag (a press on a session badge opens its list instead, and a press in that list never reaches the plate). First, under its name and caption, why its plate carries its marks (#495, `sheetMarks` in `ui/map-model.ts`), from this case's facts and only for the marks it carries: its fog as the newest thick entry (else the newest) with its PR (else its commit) and why, then "+N more" for the other entries, or an older entry's strength and commit alone; its staleness band's line (below); and a broken law's line (below). A past commit's sheet shows none. Then the catch-up card: for a fogged part, how many changes landed, the waiting [part catch-up](pr-briefs.md#part-catch-ups)'s outline and its main button (or the one PR brief chapter that lights it) with "I know this" as the quiet second; on a part with no fog, "Caught up" and the refresher (below). Then the purpose, which draws a backtick span as code (a plate's hover text shows no backtick), clamped to two lines with "More" (shown only when it runs longer; "Less" clamps it again), and a row of chips (the tier, the laws, the links, and CI when the sheet shows CI), each opening its section and bringing it into view (#637). Then the sections, each a fold that opens on its own and shows a short value beside its title (none for History, whose rows load later), in this order: **Laws** (backed by a check or on trust), **Talks to** (every link at either end of the part, in the map's order: an arrow, → when the link runs from this part and ← when it runs to it, the other end, the link's kind and its reason when it has one; the sheet has no other list of links; "No link at this part" when there is none), **This session here** (below), **Holds** (the held items, each its name, its sentence and its key files, its `paths` as written; an item without paths is a note, its name in italics followed by "· note", then its sentence, so it never reads as a heading, #525; none when the part holds nothing), **Tier** (Core, Interface-only, Black box; changed in place and kept in `map-state.json`), **CI on main** (below, whenever the sheet shows CI) and **History** (the history strip, below). When a run on main breaks one of the part's laws, CI on main comes first, open. The folds Daniel opened stay open in this browser (`map-sheet-folds`, beside the sheet's width); a browser that keeps nothing starts with all folded. The first Esc closes it; the next closes the left panel, if open. × (named "Close") closes it too, and so does a click on the empty map (#445): a press on the background that moves 4 px or less between down and up closes the sheet and its drawer, while one that moves further pans and keeps them. A click on another part switches the sheet to that part. The not placed line, the sheet, the drawer under it and the background runs are one column at most the map's height less its insets, the line first, so it keeps the map's top right and an open sheet never pushes it down over a part (#466). The not placed line is one line of fixed height, and while a sheet is open its slot keeps that height even with no line in it, so sessions starting and stopping to need Daniel never move the sheet (#472, #694; in the event log the list changed about every 30 s while agents ran). The column scrolls as one: the sheet and the drawer never scroll on their own, except the two that keep a short scroll of their own: a drawer's code block and the History strip (which can hold thousands of pixels of commits); no drawer text gives the column a sideways scroll, and a scroll past its end never moves the map. The sheet is 360 px wide at first; dragging its left edge resizes it between 300 px and half the map, and so do the left and right arrow keys while that edge has the focus. The width is kept in this browser, and a double-click on the edge puts it back to 360 px. **The sheet explains itself** (spec #520, #522): while the page-wide `explanations` setting is on (the default), each fold (Laws, Talks to, This session here, Holds, Tier, CI on main, History) has one muted line first in its body, shown when it is open, and the catch-up card one under its eyebrow; the selected tier's meaning sits under the tier buttons, and every tier button's hint is its meaning; in Talks to, a link kind's line follows only the first link of that kind, and "Not yet ratified"'s only the first unratified link; a fogged part has one line under its fog buttons saying what the buttons shown do: Part catch-up and I know this, the PR brief chapter's button and I know this, or I know this alone, each button described by it. Each fold's summary and the selected tier carry `aria-describedby` to their line; while off, no line is drawn and no attribute points at one. A `?` toggle beside the × (named "Explanations", with `aria-pressed`; hint "Hide explanations" or "Show explanations"; filled when on, a muted ring when off) flips the setting through the server's settings write (`set_explanations`), and so does the palette's `studio::ToggleExplanations`; the open sheet draws again at once, and a `?` that had the focus keeps it. A flip while a write is in flight waits for its reply, so a double click ends where it started and no write is refused as stale. Every text is in `ui/explanations.ts`, worded to "you", at most 12 words each. **This session here** (spec #549, #561): while a session's story is open in the left panel beside the sheet, a fold, third after Laws and Talks to, lists the open session's turns of the last 7 days (the page's cut: a turn's end, or its start if it never ended) that changed the part, Workers' files included, newest first, each its number in the story (from 1), its Headline (else its prompt's first line) and its age (minutes, hours, then days). With none it says "No turn of this session changed this part in the last 7 days", but nothing while `map_place` has yet to answer for a file of those turns; the section, and the newest turn's "Show on map", follow a new answer when it lands, and "Turns older than 7 days aren't listed" shows under it only when the session has older turns. Pressing a row scrolls the story to the turn, unfolds it, moves the focus to its line and flashes its outline once in the warm ring (held still for that second under reduced motion), then pans the turn's parts clear of the panel and the sheet (`revealParts`). The section follows the story as it changes, keeps a focused row's focus, and is not drawn for a subagent's view or on a past commit's sheet. Below 1007 px the sheet takes the panel's place, so the section never shows there, and no session is remembered for it. - **Keyboard** (#460). Each plate holds an open button over its name and caption, named by them, beside its session badge rather than around it. Tab reaches a part's button and then its badge (Enter or Space opens the badge's list and moves the focus into it; Esc closes it and puts the focus back on the badge), the parts in the map's reading order (top to bottom, then left to right; a plate within half a plate's height of a row's highest plate reads on that row; `readingOrder` in `ui/map-model.ts`), set when the map draws; a redraw keeps the focus on the same part's button, or on its new badge, also when the badges come after the map (a new commit asks `map_place` again); a focused badge that a spotlit chip replaces (its list's row opened that session's story) leaves the focus on its part's button. Enter or Space opens the part's sheet, as a click does, and the page's focus ring marks the part; in a brief's order question the same press counts as a tap. Actors take no focus, since a click on them does nothing. Plates cannot be moved from the keyboard, nor the camera panned or zoomed: placement is Daniel's own arrangement, and every action the map offers stays reachable without it (#452). - **Staleness bands** (`server/src/staleness.rs`, `ui/map-stale.ts`, #392). A part whose effective tier is Core carries a mild band along its plate's foot, in the muted text tone and firmer with each band, once Daniel has not engaged with it for 3 weeks (band 1), 6 (band 2) or 12 (band 3); its plate's hint adds "You last engaged with this part 3 weeks or more ago" (6, 12), and the top of its sheet gives the band with the UTC date of the last engagement, "6 weeks or more since you last engaged with this part, on ", or, with no engagement since tracking began (the baseline, or the part's first commit when later), "6 weeks or more: not engaged since tracking began on ". The server words that line (`staleness::lines`, `MapState.stale_why`). Interface-only and Black box parts never band; a past commit's map shows none. Staleness is the time since his last entered activity on the part, never since its last commit: a brief chapter read to its end that lights it (read from `fog.reads`, so a chapter read before staleness shipped counts, and kept in `staleness.parts` too as it is read, since a brief rewritten to light its parts differently clears its `fog.reads`), a part catch-up, the refresher, or "I know this". Any of them clears the band at once. A part's baseline is the first time this build showed the project's map (`staleness.since` in `map-state.json`) or, when later, the committer time of the first first-parent commit on the default branch whose `system-map.json` lists the part's id, so nothing is stale on day one and a part added to the map, a split's new parts included, starts with no band; a newer activity beats either. That time is read from git's history of the map file once per project and part while the server runs and is never stored (`staleness::births`, `history::part_births`); the other activities are kept there per part (`staleness.parts`, the last one's time and kind). The bands show on the map, on the part's sheet and at pre-flight only (`MapState.stale`, the band of each stale part), never anywhere else. - **The refresher** (#392). A part's sheet with no fog offers **Refresher** in its catch-up card: the part as the map has it now, drawn by code from the map file at once, never a writer call. The sheet already shows its caption, purpose, held items, laws with their backing and links; the refresher opens inside the catch-up card, under "Caught up", and adds the flows through the part (each flow's hops on a link at the part, in order), or "No flow of the map crosses this part". Entering it is an activity on the part (`map_refresher`), so its band clears, and is logged (Stop rules). diff --git a/docs/studio/behaviour/rail.md b/docs/studio/behaviour/rail.md index baf60919..75c30cf9 100644 --- a/docs/studio/behaviour/rail.md +++ b/docs/studio/behaviour/rail.md @@ -11,7 +11,7 @@ The rail, on the window's left, tells the selected session's story, ranked by wh - Running: "You asked" with your prompt, then the intention, boxed, with its age and the step line. The intention is the latest thing the agent wrote in its own words; it shows only while the session runs, and small, as "Why it asks", while it needs you. At your turn the Headline says what happened, and the turn-end intention is the final response's first line, never the summary's. While it runs, the box's last line, under the step and set apart by a hair line, is a **Wait tip** (#523, spec #520): "Tip: …", muted and small, one line ending in "…" when cut, its full text scrolling into view on hover. It teaches one feature, naming its palette action with the key your keymap binds it to now ("in the palette" when unbound). One tip shows per Running stretch and stays for it; it is gone at Needs you, Your turn and Idle. Among the tips whose context holds (the shown project has a map, a PR brief waits in the tray, the agent records each turn's files) that have shown fewer than 5 times and are out of cooldown, the one shown longest ago, or never, wins. The cooldown is `max(1, min(4, eligible − 1))` Running stretches, counted at the start of every stretch while tips are on, so a tip never shows twice in a row and a lone eligible tip shows every other stretch. The list is in `ui/tips.ts`; the show history (the stretch counter and each tip's count and last stretch) is in the page's `localStorage`, so clearing it starts tips again. `"tips": false` in `settings.json` turns them off ([Settings files](../settings.md)). - Needs you: the docked question, plan or permission, then "Why it asks" and "So far this turn", the facts the hooks recorded. -- Your turn, idle or ended: "You asked", the **Headline**, the evidence line, the Body lines, one line for each subagent and its checks, and "Full response", folded. A session returned to after a while opens on "Where we were" (see [The Brief and Where we were](brief.md)). +- Your turn, idle or ended: "You asked", the **Headline**, the evidence line, the Body lines, one line for each subagent (a chip whose status, running, done or failed, always shows at its natural width, while its purpose and kind line take the rest and end in "…") and its checks, and "Full response", folded. A session returned to after a while opens on "Where we were" (see [The Brief and Where we were](brief.md)). **Full response** (spec #661) is the turn's whole reply: the newest turn's texts from the transcript, an earlier turn's final reply fetched when its fold first opens. When the Headline is the reply's first line (no stored Headline), that line is left out, so the fold never opens on the sentence the Headline already shows; a stored Headline, a writer's or one read from an older summary, leaves the reply whole. The newest turn has no Full response when nothing is left, and an earlier turn's fold, whose reply is not on hand until it opens, says "The reply was only its Headline." @@ -37,7 +37,7 @@ A failed check's row opens its exit code and the last 40 lines of its output. A **Real code.** A file row opens its real hunk between the turn's trees, in place, at most about 40 lines; a capped hunk's "N more lines" opens the turn's whole diff, . The palette's "studio::OpenFullDiff" opens the whole diff of the newest turn that has files, in the centre column's place, one fold per file with its hunk read whole, and a button to go back. The page has no editor to open a file in. -**Earlier turns** fold to one line each: your prompt, the Headline and a mark for a check that ended failed. A turn a wake-up opened reads "Woken by" in place of "You asked", and its line's prompt is the returning task after a muted "Woken by" (#675). A click opens the turn's block under it and folds it again. Opening or closing the evidence line, a hunk or a folded turn changes only that node: the rail's others are kept, the scroll position does not move, and what is open stays open when the studio's state refreshes. +**Earlier turns** fold to one line each: your prompt, the Headline and a mark for a check that ended failed. The Headline draws its Markdown inline, as the newest turn's does, with code as code and bold as bold, but a link shows as its text, so a press anywhere on the line folds or unfolds the turn (#820). A turn a wake-up opened reads "Woken by" in place of "You asked", and its line's prompt is the returning task after a muted "Woken by" (#675). A turn's prompt, after "You asked" and in its folded line, is the prompt's first non-empty line once every `` and `` tag is removed, wherever it sits on a line: a pasted prompt reads its first pasted line, or the first line typed before the paste, and a paste holding no text reads "Pasted text" (#824). A click opens the turn's block under it and folds it again. Opening or closing the evidence line, a hunk or a folded turn changes only that node: the rail's others are kept, the scroll position does not move, and what is open stays open when the studio's state refreshes. **The story is patched in place** (spec #661). The rail is drawn again on each change of the selected session, its cards or a turn's summary, and "now", the banner and the feed are each drawn through the keyed patch the session list uses: an element whose key is the same is the node it was, so a press lands where it was aimed, and the scroll position, the focus, a text selection and an open fold stay. A turn's key is its session, its index, whether it is the newest or a past row, and a stamp of what its handlers read: its id, prompt, reply, summary and files. A turn whose stamp changed, as when its summary arrives, is drawn anew, and the others are kept. A fold, an Ask box (with what is typed in it and its answer), the banner's Brief, a subagent's line, a file's or a failed check's row and a citation each have their own key; an Ask box is the same node, what is typed in it and its answer included, while it stays in its turn. When its turn is drawn anew, it leaves the page for a moment with the old turn's node, and the patch gives the focus back to it once it is in the new one. A counting time (a check's) keeps one key for the thing it counts, so it is kept and goes on counting. The dock, the Brief under the feed and the decision history are drawn again only when what they show changed. diff --git a/docs/studio/behaviour/sessions.md b/docs/studio/behaviour/sessions.md index 919b5470..c5009fba 100644 --- a/docs/studio/behaviour/sessions.md +++ b/docs/studio/behaviour/sessions.md @@ -4,7 +4,7 @@ On the right, the session list: every session (Claude Code, agy and Codex), one line each with the agent's logo, its name and its state, grouped by its project, and, inside a repository, by state with "needs you" first. The list holds what Home showed (#382): a row that needs you adds a second line, the open question's first line, else who asks (a plan, a permission, or a subagent: its name and "asks"); a running row its Intention, or its current step until the Intention is known; an unseen row (your turn or idle, not landed) its last turn's Headline, which updates when the turn's summary is stored. No other row has a second line. A second line is one line, muted, at 11.5 px, cut with an ellipsis. **Cut text reads in full in place** (spec #582): a row's name, token and second line, like every text the layout cuts, keep their whole text in the page (find-in-page, copy and screen readers get all of it), and on hover, or focus on the control that holds them, the cut line scrolls its hidden end into view inside its own box (`cut()` in `ui/dom.ts`, the `.cut` class). A line that fits stays still, and with reduced motion asked for nothing moves. A text the layout shortens (a path) or that can be very long (a prompt) has a hint holding it whole instead. A prompt-named session's name has a hint of its own, its full name and its identity; the row's hint reads its name and state, as every row's does. The selected row adds how long it has waited ("Bash cargo test · 3m"); a session whose last step is a wake-up reads "worker … returned" until its next step. The agent's logo is 12 px in one muted tone; colour in the list is the "Needs you" pill only. **The brief mark** (#630): a live session whose PR has a waiting PR brief (the rail's "PR brief ready" row's rule, `briefs_waiting`; [The rail](rail.md)) carries one quiet mark on its row, the project dot's mist with no colour, in its own 24 px button beside the row's delete, as a button holds no button. Its hint reads "PR #N · brief waiting", and pressing it opens the Map view on that brief, as the rail's row does, without selecting the row (`briefMarkFor` in `ui/rail-brief.ts`). It goes once the brief is read to its end at the PR's head and comes back after a push; an ended session is in History, not the list, and has none, so the Map view's tray stays its way in; the strip has none. Hovering a session's row makes it the spotlit session on the map: its footprint, its chip on its latest turn's parts, and the other session badges dimmed ([The Map view](map.md), "Session badges"). A session row, like every button and link of the session list and the top bar, explains itself in a **hint** (spec #582), a styled hover that replaces the native `title`: it shows when the pointer rests on the control for half a second, or when Tab reaches it, at once while another hint is open, anywhere on the page; it sits above the control and flips below when the window's top is in the way, except in the session list and its strip, where it opens to the control's left, level with it, so it covers no row above or below (spec #658; `hint(trigger, text, "start")`, flipping to the right when the window's edge is in the way); it stays open while the pointer is on it, and closes on Esc. A row's hint reads its name and state, and adds that it touched no part in the last 7 days when it did not; it is built when the row is drawn, and the sidebar is drawn again when the map places the sessions. A hint that adds to the control's name is its accessible description; one that only repeats it adds nothing. `hint(trigger, text)` in `ui/dom.ts` makes one. A fold-out header (``), an input or a select, which the browser's own hint wiring cannot reach, shows its hint the same way, by the helper's own pointer and focus listeners (the same delays, the pointer may rest on the hint, Esc and leaving close it, focus never moves into it); a click on a fold-out header still folds it. A button that cannot be used right now (Ask while it waits for its answer, the question card's Send before every question has a choice, a micro-world's "Building…") is `aria-disabled="true"`, not `disabled`: it stays focusable, is announced as unavailable, ignores a click and Enter, and its hint says why. **Marks and dots** (a row's check mark and id mark, a project's mist dot, an agent's logo, a part's law marks and broken-law mark, the sheet's law marks, a stale part's band, a link's law mark, the story's failed-check mark and a clock) show their hint on the pointer alone (`mark()` in `ui/dom.ts`, and `hint()` on a span or an SVG shape): each is `role="img"` with an `aria-label` carrying its meaning, and none takes the Tab order, so what a mark says also stays reachable without a pointer, in the part sheet's law list and the row's own words. **No native `title` is left on the page** outside the terminal, an SVG `` included; the micro-world's frame is named by its `aria-label`. The snap pages keep it so: the hover rule (`scripts/snap/hover.mjs`, #220, rewritten by spec #582) runs after every snap page and fails on a control (`button`, `summary`, `a[href]`, `[role=button]`, the toasts, the spine) with no hint of its own (an ancestor's hover no longer counts), on any `title` attribute or SVG `<title>`, on a hint that only repeats its control's label, and on a hinted element the pointer cannot reach. -**The list holds its order under the pointer** (spec #659). While the pointer is in the list (the full list, the list open over the map, its strip, or the project "⋯" menu), the project groups and the rows in each keep the places of the last draw before it came in, and the strip's buttons theirs: a session that goes from running to needs you keeps its row and its state group, and only its glyph, second line and counts change, as do a header's rollup and dot. A session that starts meanwhile joins the end of its project's group (a new project the end of the groups, a session new to the strip its end), and one no longer listed leaves at once, so a row pressed is always a listed session. A row held in the folded Idle group stays in it, and a strip button whose session went idle stays, until the pointer leaves. When it leaves, the list and the strip are drawn once in the real order. The server's sort and sends are unchanged: the hold is the page's (`holdGroups` in `ui/projects.ts`, `holdList` in `ui/list.ts`). ⌘] and ⌘[, ⌘J and the jump to an unseen session step through the order on screen, held or not, as ↑ and ↓ do; a session Clear landed hid is not in it. The strip's buttons follow the sidebar's order, project by project and by state, held or not, never the server's, so ⌘] and ⌘[ at the strip's width step through them as they show. A hint of something in the list (a row's, a project dot's, which opens over the rows) is drawn outside `.list`, and the pointer on it is still in the list: the hold ends when it leaves the hint for somewhere else, also once the hint's row is gone (its session ended under it). The keyboard in the list holds nothing. The snap `listHeld` checks it with synthetic pointer events. +**The list holds its order under the pointer** (spec #659). While the pointer is in the list (the full list, the list open over the map, its strip, or the project "⋯" menu), the project groups and the rows in each keep the places of the last draw before it came in, and the strip's buttons theirs: a session that goes from running to needs you keeps its row and its state group, and only its glyph, second line and counts change, as do a header's rollup and dot. A session that starts meanwhile joins the end of its project's group (a new project the end of the groups, a session new to the strip its end), and one no longer listed leaves at once, so a row pressed is always a listed session. A row held in the folded Idle group stays in it, and a strip button whose session went idle stays, until the pointer leaves. The subagent rows under each session hold the same way (spec #820, item F): a subagent the list did not know when the pointer came in waits until it leaves, except one that needs you or failed unopened, which shows at once under its spawn, as a collapsed row shows those, and may move the rows below it; one that fades leaves at once, as a gone session does. When it leaves, the list and the strip are drawn once in the real order. The server's sort and sends are unchanged: the hold is the page's (`holdGroups` in `ui/projects.ts`, `holdList` in `ui/list.ts`, `heldAgents` in `ui/list-model.ts`). ⌘] and ⌘[, ⌘J and the jump to an unseen session step through the order on screen, held or not, as ↑ and ↓ do; a session Clear landed hid is not in it. ↑ and ↓ also step through the subagent rows as they show, and ⌘] and ⌘[ through sessions only. The strip's buttons follow the sidebar's order, project by project and by state, held or not, never the server's, so ⌘] and ⌘[ at the strip's width step through them as they show. A hint of something in the list (a row's, a project dot's, which opens over the rows) is drawn outside `.list`, and the pointer on it is still in the list: the hold ends when it leaves the hint for somewhere else, also once the hint's row is gone (its session ended under it). The keyboard in the list holds nothing. The snap `listHeld` checks it with synthetic pointer events. "Clear landed", quiet under "History · N", shows only while a landed session is in the list (#244, #382). It hides every landed row at once, ended ones included, from the list and the strip, and shows a toast, "Cleared N landed", with Undo for 8 seconds. Undo brings the rows back and nothing was deleted. When the 8 seconds pass, or the app quits inside them, each hidden session goes through Delete: its row drops, and its cards stay. The rows stay hidden until the sessions leave the list, so they never flash back before the delete lands, and a Clear in that gap does not commit them twice; a delete that fails brings its row back. A reload of the page forgets a pending clear. A session that stops being landed inside the window is left alone. The server hears each session until its delete is written, so a quit while the deletes are in flight still commits them. A second Clear inside the window adds its rows and restarts the 8 seconds. diff --git a/scripts/snap/fixtures-map.ts b/scripts/snap/fixtures-map.ts index 017e9e99..0fabcb99 100644 --- a/scripts/snap/fixtures-map.ts +++ b/scripts/snap/fixtures-map.ts @@ -573,6 +573,8 @@ export const mapBroken = (open: "none" | "sheet" | "proof" | "log"): Fixture => if (!code || !code.textContent.includes("@law: wire-types-agree")) return log("snap:fail the proof drawer does not show the tag"); const jumps = [...document.querySelectorAll("#map-drawer .drawer-jump")].map((b) => b.textContent); if (jumps.length) log("snap:fail the proof has jumps out of the page: " + jumps); + const side = document.querySelector(".map-side"); + if (side.scrollWidth > side.clientWidth) log("snap:fail the side column scrolls sideways: " + side.scrollWidth + " > " + side.clientWidth); document.dispatchEvent(new KeyboardEvent("keydown", { code: "Escape", key: "Escape", bubbles: true })); await wait(100); if (document.querySelector("#map-drawer .drawer") || !document.querySelector("#map-sheet .sheet")) log("snap:fail the first Esc did not close the drawer alone"); @@ -600,7 +602,7 @@ export const mapBroken = (open: "none" | "sheet" | "proof" | "log"): Fixture => log("broken " + marked.join());`, { map_state: mapState({ ci: brokenCi }), map_place: busyPlace(), - map_proof: [{ file: "workbench/tests/wire.rs", line: 11, test: "wire_types_match", first: 11, snippet: "// @law: wire-types-agree\n#[test]\nfn wire_types_match() {\n studio_test_support::assert_wire_types_agree();\n}" }], + map_proof: [{ file: "workbench/tests/wire.rs", line: 11, test: "studio_workbench::wire::the_wire_types_the_server_sends_match_the_types_the_page_reads_for_every_command", first: 11, snippet: "// @law: wire-types-agree\n#[test]\nfn wire_types_match() {\n studio_test_support::assert_wire_types_agree();\n}" }], }); return { ...f, sessions, selected: { session: sessions[6], agent: null } }; }; diff --git a/scripts/snap/fixtures-page.ts b/scripts/snap/fixtures-page.ts index 3a0fd77b..dc02b697 100644 --- a/scripts/snap/fixtures-page.ts +++ b/scripts/snap/fixtures-page.ts @@ -730,16 +730,19 @@ export const cutTextStill = (): Fixture => ({ * The held order (spec #659): while the pointer is in the list, a session that changed state keeps its row, with its new glyph, its group * keeps its place, a new session joins the end of its project's group, and the strip holds the same way; ⌘] and ↓ follow the order on * screen. The strip's flat list reads the sidebar's order, held or not. The pointer on a hint of the list's, which opens outside `.list`, - * is still in the list, also once the hint's row is gone; when it leaves the hint for the map, the list and the strip take the real order. The pointer's moves are synthetic - * events on `.list` and the hint. + * is still in the list, also once the hint's row is gone; when it leaves the hint for the map, the list and the strip take the real order. A + * subagent that starts under a session while held waits, so the row below it keeps its place, and shows once the pointer leaves (spec #820, + * item F). The pointer's moves are synthetic events on `.list` and the hint. */ export const listHeld = (): Fixture => { const plotkeeper = { cwd: "/w/plotkeeper", project: "/w/plotkeeper" }; const timburr = { cwd: "/w/timburr", project: "/w/timburr", folder_name: "timburr" }; + // s2 runs one subagent from the start; a second starts under it once the pointer is back in the list. + const docs = { ...plotkeeper, agents: [subagent("w1", "Read the docs")] }; const sessions = [ session("s1", "Fix the hook", "running", plotkeeper), session("s3", "Running tracker", "running", timburr), - session("s2", "Write the docs", "your_turn", plotkeeper), + session("s2", "Write the docs", "your_turn", docs), ]; // s3 and s2 now need you and s4 started: unheld, timburr's group goes first and s2 above s1. In the server's order, which is not the // sidebar's, so the strip shows which one it reads. @@ -747,8 +750,11 @@ export const listHeld = (): Fixture => { session("s3", "Running tracker", "needs_you", timburr), session("s1", "Fix the hook", "running", plotkeeper), session("s4", "Review the PR", "running", plotkeeper), - session("s2", "Write the docs", "needs_you", plotkeeper), + session("s2", "Write the docs", "needs_you", docs), ]; + const spawned = later + .filter(({ id }) => id !== "s1") + .map((s) => (s.id === "s2" ? { ...s, agents: [...s.agents, subagent("w2", "Check the links")] } : s)); return { ...base, sessions, @@ -800,6 +806,20 @@ export const listHeld = (): Fixture => { expect("the rows once the pointer left", rows(), "s3,s2,s4"); expect("the headers once the pointer left", heads(), "timburr,plotkeeper"); expect("the strip once the pointer left", strip(), "s3,s2,s4"); + // Held again, w2 starts under s2: it waits, so s4, the row below s2's subagents, stays where it is; it shows once the pointer leaves. + const agents = () => [...document.querySelectorAll("#groups .row:not(.session-row)")].map((row) => row.dataset.key.trim()).join(); + const top = () => document.querySelector('#groups .session-row[data-key="s4 "]')?.getBoundingClientRect().top; + expect("the subagents before", agents(), "s2 w1"); + list.dispatchEvent(new PointerEvent("pointerenter")); + const before = top(); + window.__snapEmit("sessions", ${JSON.stringify(spawned)}); + await wait(200); + expect("the subagents while held", agents(), "s2 w1"); + expect("s4's top once w2 started under the pointer", top(), before); + list.dispatchEvent(new PointerEvent("pointerleave")); + await wait(200); + expect("the subagents once the pointer left", agents(), "s2 w1,s2 w2"); + if (!(top() > before)) log("snap:fail s4 did not move below w2 once the pointer left: " + top() + ", " + before); log("held ok");`, snapDone: "held ok", }; diff --git a/scripts/snap/rail-fixtures.ts b/scripts/snap/rail-fixtures.ts index edc7e8e1..10c48ac3 100644 --- a/scripts/snap/rail-fixtures.ts +++ b/scripts/snap/rail-fixtures.ts @@ -224,6 +224,8 @@ const barScript = ` if (box.right > room + 0.5) log("snap:fail the bar cuts #" + item.id + " at " + innerWidth); if (item.scrollWidth > item.clientWidth + 1 && item.id !== "bar-project") log("snap:fail #" + item.id + " is clipped at " + innerWidth); } + const gear = document.getElementById("settings-button").getBoundingClientRect(); + if (gear.width < 24 || gear.height < 24) log("snap:fail the Settings button is " + gear.width + " x " + gear.height + ", under 24 x 24"); if (document.getElementById("bar-project").hidden) log("snap:fail the project's name is missing"); log("bar at " + innerWidth + ": " + [...top.children].filter((i) => !i.hidden && i.id).map((i) => i.id).join(" "));`; @@ -530,8 +532,33 @@ const tipScript = ` if (tip.getBoundingClientRect().height >= 2 * parseFloat(style.fontSize) + parseFloat(style.paddingTop)) log("snap:fail the tip takes more than one line"); log("tip: " + tip.textContent);`; +// #825: a subagent's chip keeps its status at its natural width, its purpose and kind line cut, and the chip stays inside its card. +const chipScript = ` + await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve))); + // Unfold the past turns, so a3's chip, in a past turn, is drawn. + const lines = document.querySelectorAll(".turn.past .turn-line"); + for (const line of lines) line.click(); + for (let i = 0; i < 3; i++) await new Promise((resolve) => requestAnimationFrame(resolve)); + const chips = [...document.querySelectorAll(".turn .subagents button")]; + const long = chips.filter((b) => b.dataset.key?.endsWith("-a1") || b.dataset.key?.endsWith("-a3")); + // a1 (the newest turn's) has no asked line, three children, its status running; a3 (a past turn's) has one, four, its result a long line. (More than 3 frames after the click stalls snap's page time.) + if (long.map((b) => b.children.length).sort().join() !== "3,4") return log("snap:fail the long-named chips are " + long.length + " with children " + long.map((b) => b.children.length)); + for (const chip of long) { + const status = chip.children[chip.children.length - 2]; + if (!status.textContent || status.getBoundingClientRect().width < 20 || (status.textContent === "running" && status.scrollWidth > status.clientWidth + 1)) log("snap:fail the status " + JSON.stringify(status.textContent) + " is squeezed to " + status.getBoundingClientRect().width + "px in a chip of " + chip.children.length); + if (chip.scrollWidth > chip.clientWidth + 1) log("snap:fail the chip overflows: " + chip.scrollWidth + " > " + chip.clientWidth); + if (chip.getBoundingClientRect().right > chip.closest(".turn").getBoundingClientRect().right + 0.5) log("snap:fail the chip leaves its card"); + log("chip: " + [...chip.children].map((c) => Math.round(c.getBoundingClientRect().width)).join(" ")); + }`; +const withLongChip = () => { + const fixture = build("running"); + for (const agent of fixture.selected.session.agents) if (agent.id === "a1" || agent.id === "a3") agent.name = "Review the whole diff on this branch against every token rule in the stylesheet and the tests that cover them"; + return { ...fixture, snapScript: chipScript }; +}; + export const railFixtures = { readmeTurn, + railSubagentChip: withLongChip, readmeWhere, railPlain: () => build("your_turn"), railDiff: () => ({ ...build("your_turn"), snapScript: diffScript }), diff --git a/ui/index.html b/ui/index.html index 98b9ae16..329f11ed 100644 --- a/ui/index.html +++ b/ui/index.html @@ -25,7 +25,7 @@ <h1 class="visually-hidden">plotkeeper</h1> <!-- How many sessions need Daniel (danielrispler/Falinks#572), anywhere, shown whenever any do; it selects the first. --> <button id="needs-you" class="btn small chip" type="button" hidden></button> <!-- Settings (#385): a quiet gear that opens the Settings panel over the map, which holds the writer section (#387); the palette's `studio::ShowSettings` does too. --> - <button id="settings-button" class="btn quiet small gear" type="button" aria-label="Settings" aria-pressed="false"><svg viewBox="0 0 16 16" aria-hidden="true"><circle cx="8" cy="8" r="2.2"/><path d="M8 1.8v1.6M8 12.6v1.6M1.8 8h1.6M12.6 8h1.6M3.6 3.6l1.1 1.1M11.3 11.3l1.1 1.1M3.6 12.4l1.1-1.1M11.3 4.7l1.1-1.1"/></svg></button> + <button id="settings-button" class="btn quiet small gear" type="button" aria-label="Settings" aria-pressed="false"><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M6.7 2.9L7.0 1.1L9.0 1.1L9.3 2.9L10.7 3.5L12.2 2.4L13.6 3.8L12.5 5.3L13.1 6.7L14.9 7.0L14.9 9.0L13.1 9.3L12.5 10.7L13.6 12.2L12.2 13.6L10.7 12.5L9.3 13.1L9.0 14.9L7.0 14.9L6.7 13.1L5.3 12.5L3.8 13.6L2.4 12.2L3.5 10.7L2.9 9.3L1.1 9.0L1.1 7.0L2.9 6.7L3.5 5.3L2.4 3.8L3.8 2.4L5.3 3.5Z" stroke-linejoin="round"/><circle cx="8" cy="8" r="2.2"/></svg></button> </header> <nav class="list" aria-label="Sessions"> diff --git a/ui/list-model.ts b/ui/list-model.ts index bb8ba9dd..f131cf0c 100644 --- a/ui/list-model.ts +++ b/ui/list-model.ts @@ -121,6 +121,20 @@ const standsOut = (session: Pick<Session, "asker">, agent: Subagent) => session.asker?.agent === agent.id || (agent.failed && !agent.opened); +/** + * The subagents the held list draws from (spec #659, spec #820 item F): those `known` when the pointer came into the list, and each that + * stands out, with the agents it spawned from, so it shows at once under its spawn. The rest wait until the pointer leaves. One that faded + * is still given, so `drawn` leaves it out at once. + */ +export function heldAgents(session: Pick<Session, "asker" | "agents">, known: (agent: Subagent) => boolean): Subagent[] { + const byId = new Map(session.agents.map((agent) => [agent.id, agent])); + const kept = new Set(session.agents.filter(known)); + for (const agent of session.agents.filter((agent) => standsOut(session, agent))) { + for (let at: Subagent | undefined = agent; at && !kept.has(at); at = byId.get(typeof at.parent === "string" ? at.parent : at.parent.agent)) kept.add(at); + } + return session.agents.filter((agent) => kept.has(agent)); +} + export type Folded = { has(id: string): boolean }; /** diff --git a/ui/list.ts b/ui/list.ts index 7022bcc6..95d0d20e 100644 --- a/ui/list.ts +++ b/ui/list.ts @@ -29,6 +29,7 @@ import { doneCount, drawn, folds, + heldAgents, landedToClear, rowMark, rowText, @@ -303,9 +304,13 @@ export function deleting(session: Session): HTMLElement | null { // A session's row, then its subagents under the agent that spawned them, at any depth, and those // with no known spawn under "Unattached". A faded subagent is not drawn, and its parent's line counts // it, unless anything below it is drawn: then it keeps its line, so its children stay under it. A -// collapsed row hides its subagents, but not one that needs Daniel or failed unopened. +// collapsed row hides its subagents, but not one that needs Daniel or failed unopened. While the list is held, a subagent it did not +// know when the pointer came in waits, but one that stands out shows at once, as under a collapsed row (`heldAgents`); one drawn meanwhile +// stays known. function tree(session: Session, token: string | null): HTMLElement[] { - const children = childrenOf(session); + const agents = holding ? heldAgents(session, (agent) => knownAgents.has(`${session.id} ${agent.id}`)) : session.agents; + if (holding) for (const agent of agents) knownAgents.add(`${session.id} ${agent.id}`); + const children = childrenOf({ agents }); const shut = foldedIn(session); const rows = (parent: string, depth: number, under: boolean) => drawn(session, children, parent, depth, shut, under).map(({ agent, depth }) => @@ -468,10 +473,13 @@ function projectNode(group: ProjectGroup<Session>): HTMLElement { // The held order (spec #659): while the pointer is in the list (the full list, the list open over the map or the strip), the groups, the rows // and the strip's buttons keep the places of the last draw before it came in (`holdGroups`), and their states and lines still update; when -// it leaves, the list and the strip are drawn once in the real order. `shownGroups` and `stripped` are the last draw's, held or not. +// it leaves, the list and the strip are drawn once in the real order. `shownGroups` and `stripped` are the last draw's, held or not. The +// subagent rows hold too (spec #820, item F): `knownAgents`, by session id then a subagent's id, are the subagents of the last draw before +// the pointer came in, and those drawn since. let holding = false; let shownGroups: ProjectGroup<Session>[] = []; let stripped: string[] = []; +let knownAgents = new Set<string>(); /** The pointer came into the list or left it, from `main.ts`. */ export function holdList(held: boolean) { @@ -491,6 +499,7 @@ export function drawSidebar() { if (marksStale && studio.projects.length) readDots().catch(failure("map_marks")); const groups = projectGroups(studio.listed, studio.projects, landedClear.hidden); shownGroups = holding ? holdGroups(shownGroups, groups) : groups; + if (!holding) knownAgents = new Set(studio.listed.flatMap((session) => session.agents.map((agent) => `${session.id} ${agent.id}`))); patch(element("groups"), shownGroups.map(projectNode)); patch(element("history-link"), [...historyLink(studio.listed), ...clearLanded(landedToClear(studio.listed, landedClear.hidden))]); } diff --git a/ui/map-model.ts b/ui/map-model.ts index e8632343..4daf71c3 100644 --- a/ui/map-model.ts +++ b/ui/map-model.ts @@ -340,8 +340,8 @@ export function linkLines(links: MapLink[]): LinkLine[] { return [...lines.values()]; } -/** A plate's hover text: its name, caption and purpose, never the held items, so a glance stays a glance. */ -export const plateTitle = (part: Part): string => [part.name, part.caption, part.purpose].filter(Boolean).join("\n\n"); +/** A plate's hover text: its name, caption and purpose, never the held items, so a glance stays a glance. A hint is plain text, so backticks go. */ +export const plateTitle = (part: Part): string => [part.name, part.caption, part.purpose].filter(Boolean).join("\n\n").replaceAll("`", ""); /** * Broken laws and the drawer (ticket #312). The drawer is read-only and holds any content a ticket gives it: blocks of code or text and diff --git a/ui/map-sheet-folds.ts b/ui/map-sheet-folds.ts index 965c3892..bd1e9392 100644 --- a/ui/map-sheet-folds.ts +++ b/ui/map-sheet-folds.ts @@ -3,7 +3,7 @@ // side by side) with a short value beside its title. Which folds are open is kept in this browser's page store, as the sheet's width is; // a browser that keeps nothing starts with all folded and keeps them for as long as the page lives. `map-sheet.ts` fills each fold. -import { hint, pageStore, pressable, text } from "./dom.js"; +import { hint, pageStore, pressable, prose, text } from "./dom.js"; import { explainLine, SHEET_FOLDS } from "./explanations.js"; import { type FoldKey, foldTitles } from "./map-model.js"; @@ -82,7 +82,8 @@ export function chip(label: string, target: Fold, bad = false): HTMLElement { * sheet is in the page). */ export function purposeNodes(purpose: string, open: boolean, flipped: (open: boolean) => void): HTMLElement[] { - const words = text("p", purpose, "sheet-purpose"); + const words = prose("p", purpose); + words.className = "sheet-purpose"; words.id = "sheet-purpose"; const more = pressable(text("button", "", "btn quiet sheet-more"), null); more.setAttribute("aria-controls", words.id); diff --git a/ui/markdown.ts b/ui/markdown.ts index 4f783bd3..2abb73b9 100644 --- a/ui/markdown.ts +++ b/ui/markdown.ts @@ -1,6 +1,7 @@ // Responses render as Markdown (danielrispler/Falinks#525, decision 21): tables, lists, code and links. The text is // untrusted and the page can call the server, so raw HTML stays text, only `http(s)` links -// become links, and an image shows its alt text. marked loads as a plain script from `vendor/`. +// become links, and an image shows its alt text. A line that is itself pressed (an earlier turn's folded line) renders inline, with +// every link its text. marked loads as a plain script from `vendor/`. import { hint } from "./dom.js"; @@ -12,8 +13,8 @@ const escapeHtml = (text: string) => text.replace(/[&<>"']/g, (c) => entities[c] // A link's hover names its target (#220): the page has no status bar to show it. `rendered` gives each link its hint. const opens = (target: string) => `Open ${target} in a new tab`; -// Built at first use, so modules that import this one load where marked is not (the UI tests). -const create = () => +// Built at first use, so modules that import this one load where marked is not (the UI tests). `links` false makes every link its text. +const create = (links: boolean) => new marked.Marked({ gfm: true, renderer: { @@ -22,18 +23,26 @@ const create = () => // An `http(s)` link opens in a new tab; any other link, a file's included, is its text: the page has no editor to open it in. link({ href, tokens }) { const inner = this.parser.parseInline(tokens); - return /^https?:\/\//i.test(href) ? `<a href="${escapeHtml(href)}" target="_blank" rel="noopener noreferrer">${inner}</a>` : inner; + return links && /^https?:\/\//i.test(href) ? `<a href="${escapeHtml(href)}" target="_blank" rel="noopener noreferrer">${inner}</a>` : inner; }, }, }); let renderer: ReturnType<typeof create> | undefined; +let inlineRenderer: ReturnType<typeof create> | undefined; // `text` as safe HTML. export const markdown = (text: string) => { - renderer ??= create(); + renderer ??= create(true); return renderer.parse(text, { async: false }); }; +// `text` as safe inline HTML (#820, item E): code, emphasis and the rest of one line's marks, under the same rules, with every link its +// text, for a line that is itself pressed, as an earlier turn's folded line is. +export const inlineMarkdown = (text: string) => { + inlineRenderer ??= create(false); + return inlineRenderer.parseInline(text, { async: false }); +}; + // An element showing `text` rendered; its links open in a new tab. export function rendered(tag: string, text: string, className = ""): HTMLElement { const node = document.createElement(tag); @@ -43,3 +52,11 @@ export function rendered(tag: string, text: string, className = ""): HTMLElement for (const link of node.querySelectorAll("a[href]")) hint(link as HTMLElement, opens(link.getAttribute("href") ?? "")); return node; } + +// An element showing `text` rendered inline, with no links. +export function renderedInline<K extends keyof HTMLElementTagNameMap>(tag: K, text: string, className = ""): HTMLElementTagNameMap[K] { + const node = document.createElement(tag); + node.className = className; + node.innerHTML = inlineMarkdown(text); + return node; +} diff --git a/ui/story.ts b/ui/story.ts index 9d3329da..9a37366a 100644 --- a/ui/story.ts +++ b/ui/story.ts @@ -10,7 +10,7 @@ import { logo, logoKey, noContextNote } from "./logos.js"; import { age, code, cut, element, failure, glyphOnly, hint, invoke, keepOnly, keyed, patch, pressable, prose, revealsOnOpen, text, unhint, unseenWords } from "./dom.js"; import { askAnchor, asked } from "./ask.js"; import { askFor, openDecision } from "./answer.js"; -import { rendered } from "./markdown.js"; +import { rendered, renderedInline } from "./markdown.js"; import { drawSidebar } from "./list.js"; import { agentState, sessionName, showsLanded } from "./list-model.js"; import { briefNodes, briefSlots } from "./cards.js"; @@ -652,7 +652,8 @@ export function foldedTurn(session: Session, block: FeedTurn): HTMLElement { first.setAttribute("data-key", `turn-${key}`); button.append( hint(first, turn.prompt.trim() || line.prompt), - cut(text("span", line.headline ?? "", "headline-text")), + // The Headline's Markdown, inline and with no link, so a press on it only folds or unfolds (#820, item E). + cut(renderedInline("span", line.headline ?? "", "headline-text")), // The ✕ is for the eye; assistive tech hears "failed" once (#456). ...(line.failed ? [hint(keyed(glyphOnly("✕", "mark check-failed"), `failed-${key}`), "A check ended failed"), unseenWords("failed")] : []), ); diff --git a/ui/style.css b/ui/style.css index 26ea188f..4faf80c7 100644 --- a/ui/style.css +++ b/ui/style.css @@ -459,7 +459,9 @@ h1 { margin: 0 0 var(--sp-4); } .turn-line .headline-text { flex: 1 1 0; min-width: 0; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: var(--size-small); } .turn-line .mark { flex: none; font-size: var(--size-small); color: var(--muted); } .turn .subagents button { flex-direction: row; align-items: baseline; gap: var(--sp-4); white-space: nowrap; overflow: hidden; } -.turn .subagents button > :nth-child(2) { overflow: hidden; text-overflow: ellipsis; min-width: 0; } +/* A chip's status (its second-to-last child, an asked line or not) keeps its natural width; the rest take what is left and end in an ellipsis; a result longer than half the chip is cut too (#825). */ +.turn .subagents button > * { overflow: hidden; text-overflow: ellipsis; min-width: 0; } +.turn .subagents button > :nth-last-child(2) { flex: none; max-width: 50%; } /* The evidence line (#113): one line of recorded facts that opens in place. */ .evidence { margin: 0 0 var(--sp-4); font-size: var(--size-small); } @@ -637,6 +639,7 @@ body.resizing { -webkit-user-select: none; user-select: none; cursor: col-resize /* The PR brief alone dims the map, and both panels with it (#385): what they hold, not their glass, which still covers the dimmed plates under it. */ body.brief-open .map-panel > *, body.brief-open .map-side > * > * { opacity: var(--brief-dim); transition: opacity var(--motion); } /* The gear (#385): quiet, in the top bar, pressed while Settings shows. */ +.gear { display: inline-grid; place-items: center; min-width: var(--control); min-height: var(--control); } .gear svg { display: block; width: var(--icon); height: var(--icon); fill: none; stroke: currentColor; stroke-width: 1.3; } /* Ready for review (#336): the way into a PR brief, over the map's foot on the left. */ /* On the sheet's glass, as the runs (#567), since the map pans under it (#571). */ @@ -847,6 +850,7 @@ body.narrow .map-scan-panel { max-block-size: 50vh; padding-inline: var(--map-gu .brief-also-title + .explain { margin: var(--sp-1) 0 0; } .ratify-row > .explain-link { grid-column: 1 / -1; margin: var(--sp-1) 0 0; } .sheet-caption { margin: 0; font-size: var(--size-small); color: var(--muted); } +.sheet-purpose code { white-space: normal; overflow-wrap: anywhere; } .sheet-purpose { margin: var(--sp-3) 0 0; font-size: var(--size-read); line-height: 1.5; text-wrap: pretty; } /* Under the catch-up card (#637): the purpose in two lines until More shows it whole, then the chips, the part's shape at a glance, each opening its fold, then the folds. */ @@ -994,10 +998,11 @@ body.narrow .map-scan-panel { max-block-size: 50vh; padding-inline: var(--map-gu .plate.broken, .plate.broken.open { box-shadow: inset 0 0 0 var(--hair) var(--conflict), var(--shadow); } .map-legend .law-broken { margin-inline: var(--sp-2); vertical-align: middle; } /* The drawer (#312): read-only code and text under the part sheet, with its jumps out. */ -.drawer { position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: var(--sp-3); } +.drawer { position: relative; min-width: 0; max-width: 100%; display: flex; flex-direction: column; align-items: flex-start; gap: var(--sp-3); } +.drawer-title, .drawer-note, .drawer-label { overflow-wrap: anywhere; } .drawer-title { margin: 0; font-size: var(--size-read); font-weight: 600; padding-right: var(--sp-7); } .drawer-note, .drawer-label { margin: 0; font-size: var(--size-xs); color: var(--faint); } -.drawer-block { display: flex; flex-direction: column; align-items: flex-start; gap: var(--sp-3); align-self: stretch; } +.drawer-block { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: var(--sp-3); align-self: stretch; } .drawer-code { margin: 0; align-self: stretch; max-height: var(--drawer-code); overflow: auto; padding: var(--sp-4) var(--sp-5); border-radius: var(--radius-small); background: var(--raised); font: var(--size-xs)/1.5 var(--mono); white-space: pre; user-select: text; } /* A jump out of the drawer is a link that looks like the quiet button it was (#462). */ diff --git a/ui/tests/dom.mjs b/ui/tests/dom.mjs index 6445511f..d179bcc7 100644 --- a/ui/tests/dom.mjs +++ b/ui/tests/dom.mjs @@ -12,6 +12,16 @@ class TextNode { } } +// What an element's `innerHTML` was set to (no parser here): one child holding the markup, whose text is the markup's, tags dropped and +// entities read, so the text a browser would show is the element's `textContent`, and moving the child moves the markup with it. +const decoded = { "<": "<", ">": ">", """: '"', "'": "'", "&": "&" }; +class MarkupNode extends TextNode { + constructor(html) { + super(html.replace(/<[^>]*>/g, "").replace(/&(lt|gt|quot|#39|amp);/g, (entity) => decoded[entity])); + this.html = html; + } +} + const node = (item) => (typeof item === "string" ? new TextNode(item) : item); // Whether `el` fits `selector`: a comma list of compounds, each a tag or `*`, then any `.class`, `[name]`, `[name="value"]` and @@ -169,6 +179,14 @@ class StandIn { set textContent(value) { this.childNodes = [new TextNode(value)]; } + // The markup this element holds, as it was set; undefined while it holds none. + get innerHTML() { + const markup = this.childNodes.filter((c) => c instanceof MarkupNode); + return markup.length ? markup.map((c) => c.html).join("") : undefined; + } + set innerHTML(html) { + this.replaceChildren(new MarkupNode(html)); + } get text() { return this.childNodes.map((c) => c.text).join(""); } diff --git a/ui/tests/full-text.test.mjs b/ui/tests/full-text.test.mjs index 38d0b4a5..b3710210 100644 --- a/ui/tests/full-text.test.mjs +++ b/ui/tests/full-text.test.mjs @@ -4,6 +4,7 @@ import { test } from "node:test"; import assert from "node:assert/strict"; import fs from "node:fs"; +import { createRequire } from "node:module"; import { El, fakeDocument } from "./dom.mjs"; import { row, projectHead } from "../../dist/list.js"; import * as dom from "../../dist/dom.js"; @@ -11,6 +12,8 @@ import { hintOf } from "../../dist/dom.js"; import { showPalette } from "../../dist/palette.js"; import { showToast } from "../../dist/toast.js"; import { checkElement, foldedTurn } from "../../dist/story.js"; +// The window loads marked as a plain script from `vendor/`; a folded line draws its Headline with it. +globalThis.marked = createRequire(import.meta.url)("marked"); import { studio } from "../../dist/state.js"; // The stand-in page: elements by id, as the shell's index.html has them. @@ -179,7 +182,7 @@ const covered = { ".turn .prompt": "story.ts: the prompt's title", ".turn-line .headline-text": "story.ts: the Headline's title", ".turn .subagents button": "story.ts: the button's title holds its lines", - ".turn .subagents button > :nth-child(2)": "story.ts: the button's title holds it", + ".turn .subagents button > *": "story.ts: the button's title holds it", ".answered-card > summary": "cards.ts: the summary's title", ".unseen-card > summary": "cards.ts: the summary's title", ".subagent-log .log-title": "log.ts: the title's title", diff --git a/ui/tests/map-sheet-folds.test.mjs b/ui/tests/map-sheet-folds.test.mjs index aaca9ff9..3dd0d4cc 100644 --- a/ui/tests/map-sheet-folds.test.mjs +++ b/ui/tests/map-sheet-folds.test.mjs @@ -234,3 +234,14 @@ test("the purpose sits under the card clamped to two lines with More, which show classed(again, "sheet-more")[0].listeners.click(); assert.ok(classed(sheetCard(view(), store).card, "sheet-purpose")[0].className.includes("clamped"), "Less clamps it again"); }); + +test("the purpose draws a backtick span as code, with no backtick left, and keeps its clamp and More", () => { + explanations(false); + const ticked = { ...store, purpose: "Serves the page that `plotkeeper` starts." }; + const { card } = sheetCard(view(), ticked); + const purpose = classed(card, "sheet-purpose")[0]; + assert.equal(all(purpose).filter((each) => each.nodeName === "CODE").map((each) => each.text).join(), "plotkeeper"); + assert.ok(!purpose.text.includes("`")); + assert.ok(purpose.className.includes("clamped")); + assert.equal(classed(card, "sheet-more")[0].text, "More"); +}); diff --git a/ui/tests/map.test.mjs b/ui/tests/map.test.mjs index 6ecc1b34..a73eb97d 100644 --- a/ui/tests/map.test.mjs +++ b/ui/tests/map.test.mjs @@ -207,6 +207,7 @@ test("a part's sheet gives its purpose, then each held item with its key files, { name: "Rules", text: "What must hold.", files: [] }, ]); assert.equal(plateTitle(core), "Core\n\nEvents to state\n\nPlain Rust."); + assert.equal(plateTitle(part("x", { name: "`X`", caption: "A `c`", purpose: "Runs `plotkeeper`." })), "X\n\nA c\n\nRuns plotkeeper."); }); test("a part's sheet names it, lists its laws by backing, and offers the three tiers with the effective one pressed", () => { diff --git a/ui/tests/markdown.test.mjs b/ui/tests/markdown.test.mjs index fe70749b..f743f28e 100644 --- a/ui/tests/markdown.test.mjs +++ b/ui/tests/markdown.test.mjs @@ -5,7 +5,7 @@ import { createRequire } from "node:module"; // The window loads marked as a plain script from `vendor/`, so it is a global there too. globalThis.marked = createRequire(import.meta.url)("marked"); -const { markdown } = await import("../../dist/markdown.js"); +const { inlineMarkdown, markdown } = await import("../../dist/markdown.js"); test("a table, a list, code and an http(s) link render", () => { const html = markdown( @@ -59,3 +59,17 @@ test("inline code inside a Markdown link stays in the one link (danielrispler/Fa assert.equal(html.match(/<a\b/g)?.length, 1, html); assert.match(html, /<a href="https:\/\/x.com" target="_blank" rel="noopener noreferrer"><code>src\/a.rs<\/code><\/a>/); }); + +// A folded turn's line (#820, item E) draws its Headline inline, under the same trust rules, and a link is its text, so pressing the line only unfolds it. +test("the inline rendering escapes raw HTML, makes a link its text and an image its alt text", () => { + const rows = [ + ["**#806** in `ui/story.ts`", "<strong>#806</strong> in <code>ui/story.ts</code>"], + ["a < b & `c<d`", "a < b & <code>c<d</code>"], + ['hi <b onclick="x()">b</b> <script>alert(1)</script>', "hi <b onclick="x()">b</b> <script>alert(1)</script>"], + ["[docs](https://e.com) [`a.rs`](https://x.com) [f](src/a.rs) <https://e.org> www.e.net", "docs <code>a.rs</code> f https://e.org www.e.net"], + ["[x](javascript:alert(1))", "x"], + ['![a plot](https://e.com/p.png "t") ![<i>](x.png)', "a plot <i>"], + ["# Not a heading", "# Not a heading"], + ]; + for (const [text, html] of rows) assert.equal(inlineMarkdown(text), html, text); +}); diff --git a/ui/tests/rail.test.mjs b/ui/tests/rail.test.mjs index 53a23aa5..6fbe9ad7 100644 --- a/ui/tests/rail.test.mjs +++ b/ui/tests/rail.test.mjs @@ -159,6 +159,25 @@ test("a folded turn's line holds the prompt and Headline, and a mark for a faile assert.equal(foldedLine({ prompt: "", checks: [] }, null).prompt, "No prompt"); }); +// #820, item E: the folded line draws its Headline's Markdown, code as code and bold as bold, and a link as its text, so pressing the +// line only unfolds the turn. +test("a folded turn's line draws its Headline's Markdown, with no link", () => { + studio.selection = null; + const rows = [ + { headline: "**#806** merged; `ui/story.ts` changed", words: "#806 merged; ui/story.ts changed", marks: ["<strong>#806</strong>", "<code>ui/story.ts</code>"] }, + { headline: "Opened [the PR](https://e.com/pr/1) for `a.rs`", words: "Opened the PR for a.rs", marks: ["<code>a.rs</code>"] }, + ]; + for (const { headline, words, marks } of rows) { + const turn = { id: null, prompt: "Fix it", message: headline, checks: [] }; + const node = foldedTurn(/** @type {import("../../dist/types.js").Session} */ ({ id: "s" }), /** @type {import("../../dist/story.js").FeedTurn} */ (/** @type {unknown} */ ({ index: 0, turn, cards: [] }))); + const line = node.querySelector(".headline-text"); + const markup = every(line).map((each) => each.innerHTML ?? "").join(""); + assert.equal(line.textContent, words, headline); + for (const mark of marks) assert.ok(markup.includes(mark), `${headline} draws ${mark}`); + assert.doesNotMatch(markup, /<a\b/, headline); + } +}); + // A session as the server sends it, with two turns: an older one, folded, and the newest, at your turn. const NOW = 1_800_000_000_000; const ended = (n, fields = {}) => ({ started_at: NOW - (10 - n) * 60e3, ended_at: NOW - (9 - n) * 60e3, prompt: `Prompt ${n}`, id: `t${n}`, message: `Reply ${n}.\nMore of reply ${n}.`, checks: [], listed: [], files: { files: [], merged: 0 }, ...fields }); diff --git a/ui/tests/subagents.test.mjs b/ui/tests/subagents.test.mjs index 02630de3..1c6db906 100644 --- a/ui/tests/subagents.test.mjs +++ b/ui/tests/subagents.test.mjs @@ -1,7 +1,7 @@ // Finished subagents leave the list; the rail keeps their history (danielrispler/Falinks#535). Run: `npm test`. import { test } from "node:test"; import assert from "node:assert/strict"; -import { agentLine, childrenOf, doneCount, drawn, folds, hidden } from "../../dist/list-model.js"; +import { agentLine, childrenOf, doneCount, drawn, folds, heldAgents, hidden } from "../../dist/list-model.js"; import { subagentHistory } from "../../dist/story.js"; test("a subagent row has a second line only while it runs or needs you (danielrispler/Falinks#572)", () => { @@ -99,3 +99,24 @@ test("a row folds only when it has subagents drawn under it", () => { assert.deepEqual(folds(tree, childrenOf(tree), ["w1"], new Set()), { open: true, hiding: 0 }); assert.equal(folds(tree, childrenOf(tree), ["w2"], new Set()), null); }); + +// The held list (spec #659, spec #820 item F): while the pointer is in the list, a subagent the list did not know when the pointer came in +// waits until it leaves, but one that needs you or failed unopened shows at once, under its spawn, and one that fades leaves at once. +const heldRows = (session, known) => + drawn(session, childrenOf({ agents: heldAgents(session, (a) => known.includes(a.id)) }), "session", 1, new Set()).map(({ agent, depth }) => `${agent.id}@${depth}`); +const held = [ + ["a new subagent waits", { asker: null, agents: [agent("w1"), agent("w2")] }, ["w1"], ["w1@1"]], + ["a new subagent that needs you shows", { asker: { agent: "w2", since: 0 }, agents: [agent("w1"), agent("w2")] }, ["w1"], ["w1@1", "w2@1"]], + ["a new subagent that failed unopened shows", { asker: null, agents: [agent("w1"), agent("w2", { status: "killed", failed: true })] }, ["w1"], ["w1@1", "w2@1"]], + ["a new subagent that failed and was opened waits", { asker: null, agents: [agent("w1"), agent("w2", { status: "killed", failed: true, opened: true })] }, ["w1"], ["w1@1"]], + [ + "a new helper that needs you shows under its new worker", + { asker: { agent: "h1", since: 0 }, agents: [agent("w1"), agent("w2"), agent("h1", { kind: "helper", parent: { agent: "w2" } }), agent("h2", { kind: "helper", parent: { agent: "w2" } })] }, + ["w1"], + ["w1@1", "w2@1", "h1@2"], + ], + ["a known subagent that fades leaves at once", { asker: null, agents: [agent("w1", { status: "completed", faded: true }), agent("w2")] }, ["w1", "w2"], ["w2@1"]], +]; +for (const [name, session, known, want] of held) { + test(`while the list is held, ${name}`, () => assert.deepEqual(heldRows(session, known), want)); +}