Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions plugins/genui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and

## [Unreleased]

### Added
- **Tufte style**, a setting that is on by default, shows data with less ink, after Edward Tufte.
- Line, area and bar charts get range frames instead of gridlines: an axis only as long as the data, labeled at its ends and at a round value or two between. A chart with two to six lines names each line at its end instead of in a legend. A pie is drawn as bars sorted by size, each with its share. A single series is drawn in ink with one accent on its latest point, and sparklines ring their lowest and highest points.
- Gauges and progress bars become thin bullet bars. Tables right-align numbers written as text and set rows closer. Badges, callouts, lists, cards, segmented bars and treemaps drop washes, tiles, icons and hues that only decorated, and keep colour where it means something.
- Agents get a short Tufte style section: numbers in context, labels on the graphic, small multiples, a lone number in the sentence, ink only for data, a source for every figure.
- Turn it off (`bb plugin config genui set tufteStyle false`) to draw everything exactly as before and send no style guidance.
- Agents are told to show shares as a SegmentedBar or a sorted bar instead of a pie, and many series as a Grid of small Charts.

### Fixed
- PullRequest() and the pull request column of Environments() work again on BB 0.49. BB moved pull request status out of its SDK (`environments.pullRequest`) into the built-in GitHub PR Status plugin, so both showed "t.environments.pullRequest is not a function"; they now read it from that plugin's `pullRequests` RPC, and still use the old SDK call on a BB that has it. A workspace that isn't a git repository now shows no pull request instead of that error ([#39](https://github.com/ComicBit/bb-plugin-genui/issues/39)).
- Environments() reads the pull requests of the rows it shows together, in one call, and a pull request with a field genui can't show says which field instead of breaking the row.
Expand Down
19 changes: 19 additions & 0 deletions plugins/genui/docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,25 @@ a place without `day` stays on the previous one's day, which sets the
numbering, the list, each day's route and the tour, whose pace is
`tourStep` in `mapMath.ts` (six seconds over the stops, 300–1500 ms each).

The `tufteStyle` setting (*Tufte style*, on by default) is declared beside
`animations` in `server.ts`. The page reads it the same way, with
`useSettings` and the off state kept in `localStorage`
(`ui/components/tufte.tsx`). On, line, area and bar charts draw range frames
instead of gridlines (`rangeTicks`, `frameLabelIndices`), two to six lines
are named at their ends instead of in a legend (`spreadLabels` keeps the
names apart), a pie is drawn as bars sorted by size, one series is drawn in
ink with the accent on its latest point, and sparklines ring their lowest and
highest points. Gauge and Progress draw a bullet bar (`BulletBar`); Table,
Badge, Callout, Card, List, SegmentedBar and Treemap drop fills, tiles, icons
and hues that carry no data. Each component asks `useTufteStyle()` only where
the two styles differ; off, it draws exactly what it drew before the setting
existed, which `Chart.test.tsx` and `tufteStyle.test.tsx` check against markup
saved then. The server reads the setting too: on, sessions that get the
instructions also get `TUFTE_INSTRUCTIONS` after the code-work section, and
the rules come as `AGENT_INSTRUCTIONS_TUFTE`, with the lines that section
refines swapped (`TUFTE_SWAPS`); the `/ui` skill carries the section behind a
check of the setting.

What the user changes inside a component without a `$state` (weights,
unchecked steps, filters) is kept per block with `ui/usePersistedState.ts`,
so it survives BB remounting the row as the user scrolls. `ui_examples`
Expand Down
27 changes: 26 additions & 1 deletion plugins/genui/instructions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ import { ACTIONS, COMPONENTS } from "./core/catalog";
import { collectLoads, compile, dataKey, evaluate, formatDiagnostics, initialState, type LoadedData } from "./core";
import {
AGENT_INSTRUCTIONS,
AGENT_INSTRUCTIONS_TUFTE,
AGENT_INSTRUCTIONS_TUFTE_WEB_OFF,
AGENT_INSTRUCTIONS_WEB_OFF,
CODE_WORK_INSTRUCTIONS,
TUFTE_INSTRUCTIONS,
TUFTE_SKILL_NOTE,
TUFTE_SWAPS,
UI_REFERENCE,
UI_REFERENCE_MORE,
WEB_LOOKUPS_OFF,
Expand All @@ -16,6 +21,8 @@ describe("agent instructions", () => {
const skill = readFileSync(new URL("./skills/ui/SKILL.md", import.meta.url), "utf8");
expect(skill).toMatch(/^---\nname: ui\ndescription: Use only when/);
expect(skill).toContain(`${UI_REFERENCE}\n\n${UI_REFERENCE_MORE}\n\n${CODE_WORK_INSTRUCTIONS}\n\n${AGENT_INSTRUCTIONS}\n`);
// The skill can't read the Tufte style setting: it carries the section behind the condition.
expect(skill).toContain(`${AGENT_INSTRUCTIONS}\n\n${TUFTE_SKILL_NOTE}\n\n${TUFTE_INSTRUCTIONS}\n`);
expect(skill).toContain("bb plugin config genui");
});

Expand All @@ -24,10 +31,14 @@ describe("agent instructions", () => {
it("fit BB's instruction caps", () => {
expect(AGENT_INSTRUCTIONS.length).toBeLessThanOrEqual(4096);
expect(AGENT_INSTRUCTIONS_WEB_OFF.length).toBeLessThanOrEqual(4096);
expect(AGENT_INSTRUCTIONS_TUFTE.length).toBeLessThanOrEqual(4096);
expect(AGENT_INSTRUCTIONS_TUFTE_WEB_OFF.length).toBeLessThanOrEqual(4096);
// Paid on every session: kept to about half a cap.
expect(TUFTE_INSTRUCTIONS.length).toBeLessThanOrEqual(2000);
expect(CODE_WORK_INSTRUCTIONS.length).toBeLessThanOrEqual(4096);
expect(UI_REFERENCE.length).toBeLessThanOrEqual(4096);
expect(UI_REFERENCE_MORE.length).toBeLessThanOrEqual(4096);
expect(`${UI_REFERENCE}\n\n${UI_REFERENCE_MORE}\n\n${CODE_WORK_INSTRUCTIONS}`.length).toBeLessThanOrEqual(32768);
expect(`${UI_REFERENCE}\n\n${UI_REFERENCE_MORE}\n\n${CODE_WORK_INSTRUCTIONS}\n\n${TUFTE_INSTRUCTIONS}`.length).toBeLessThanOrEqual(32768);
});

// A replace that silently matches nothing would keep teaching Map while lookups are off.
Expand All @@ -36,6 +47,20 @@ describe("agent instructions", () => {
expect(AGENT_INSTRUCTIONS_WEB_OFF).not.toContain("Map(");
});

// A swap that silently matches nothing would leave a rule the Tufte section contradicts.
it("swap each line the Tufte style section refines, in both web variants", () => {
for (const [from, to] of TUFTE_SWAPS) {
for (const [rules, tufte] of [
[AGENT_INSTRUCTIONS, AGENT_INSTRUCTIONS_TUFTE],
[AGENT_INSTRUCTIONS_WEB_OFF, AGENT_INSTRUCTIONS_TUFTE_WEB_OFF],
]) {
expect(rules.split(from), from).toHaveLength(2);
expect(tufte, from).not.toContain(from);
expect(tufte, from).toContain(to);
}
}
});

// The Evidence group's signatures ride on the code-work section, which every session that gets the references also gets.
it("list every component and action the parser accepts", () => {
const reference = `${UI_REFERENCE}\n${UI_REFERENCE_MORE}\n${CODE_WORK_INSTRUCTIONS}`;
Expand Down
78 changes: 70 additions & 8 deletions plugins/genui/instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
// conversation: when to write UI, and worked examples. Examples here are the
// strongest lever on what models write; moved to the earlier section, the
// same calculator example stopped being followed.
// - TUFTE_INSTRUCTIONS, with the tufteStyle setting on, is contributed after
// the code-work section, right before AGENT_INSTRUCTIONS, whose lines it
// would contradict are swapped (AGENT_INSTRUCTIONS_TUFTE).
// BB refuses a tool whose instructions pass 4096 characters and truncates the
// configure section there; instructions.test.ts holds all three.
// configure section there; instructions.test.ts holds every section and variant.
import { ACTIONS, callSignature, COMPONENTS, componentSignature, type ComponentGroup, type ComponentName, type ComponentSpec } from "./core/catalog";

/**
Expand Down Expand Up @@ -111,7 +114,10 @@ Card("Which queue?", [Decision([{name: "pg-boss", scores: [4, 5], pros: ["Uses o
* - "Read in BB, not a terminal" answers Claude Code's own system prompt,
* which says replies are shown as markdown in a terminal.
* - The shape list names a component for every kind of content; components
* named or shown here are the ones agents reach for.
* named or shown here are the ones agents reach for. Its first line also
* steers charts after Tufte: many series as a Grid of small Charts, shares
* as a SegmentedBar or a sorted bar, never a pie. The section was ten
* characters under the cap, so the list's articles went to make room.
* The old text's "the UI carries the rest, so never restate it" made replies
* one sentence over a card; the prose rule replaces it.
*/
Expand All @@ -120,14 +126,14 @@ This chat renders \`\`\`ui and \`\`\`app blocks as live UI; your reply is read i
Skip the block only when the whole reply is a few sentences with nothing to see: a definition, a yes/no, a short status, tests that all passed, or when the user asks for brevity. Simple is not a reason for prose: a recommendation still shows its options, a calculation its live calculator, a history its Timeline, a file's results their component. In doubt, add the block.
Only the message that ends your turn may hold a block. While you are still working, and in thinking, files, commits, PR text and tool input, write plain text; don't ask the user to decide anything mid-turn.
Pick the component the content calls for:
- a series → Chart; shares of a whole → SegmentedBar; a level against a limit → Gauge or Progress; key figures → Metric; activity per day → CalendarHeatmap; sizes → Treemap
- series → Chart, many → Grid of small Charts; shares → SegmentedBar or sorted bar, no pie; level vs limit → Gauge or Progress; key figures → Metric; daily activity → CalendarHeatmap; sizes → Treemap
- a calculation or what-if → Slider or Stepper for the user's numbers, a result that recomputes live; items with amounts → EditableTable
- options against criteria → Decision; work to approve first → Plan; items on several attributes → Table; products, places, people → Entity cards in a Grid
- a flow, lifecycle or architecture → Diagram, details on key nodes; steps to follow → Walkthrough or Steps; dated events → Timeline; a schedule → Calendar; phases → Roadmap
- code → Snippet(path, from, to), never pasted; a change → Changes or Diff; a file tree → Tree; JSON → Json; fields → KeyValue
- options vs criteria → Decision; work to approve first → Plan; items on several attributes → Table; products, places, people → Entity cards in a Grid
- flow, lifecycle or architecture → Diagram, details on key nodes; steps to follow → Walkthrough or Steps; dated events → Timeline; schedule → Calendar; phases → Roadmap
- code → Snippet(path, from, to), never pasted; change → Changes or Diff; file tree → Tree; JSON → Json; fields → KeyValue
- tool output → its component (see code work)
- places or a route → Map; an image → Image, Hotspots on its parts, Compare for before/after; what no file shows → ImageSearch; pages you read → Sources
- learning → Walkthrough, Quiz, Flashcards; colours → Swatches; a countdown → Timer; 3D → Scene
- places or route → Map; image → Image, Hotspots on its parts, Compare for before/after; what no file shows → ImageSearch; pages you read → Sources
- learning → Walkthrough, Quiz, Flashcards; colours → Swatches; countdown → Timer; 3D → Scene
Questions: only when you stop and wait. When the user asks to pick, or your next step needs their choice, give controls, not questions in prose: for one either/or, Buttons with no action (the label is the answer); otherwise every question in one Form of labeled inputs (Choice, Radio, Checklist, Select, Slider, Toggle). Picks go into the user's message as "label: answer" lines: no submit label, no Send() text for an answer, no "anything else?" field. A Plan or Decision is already the question. If next steps are questions the user may ask, end with FollowUps.
Wrap each block in one Card. Examples:
\`\`\`ui
Expand Down Expand Up @@ -161,3 +167,59 @@ export const WEB_LOOKUPS_OFF =
"Web lookups are off in the plugin's settings: ImageSearch, Map, Gallery {query} and https images won't load; use local files.";

export const AGENT_INSTRUCTIONS_WEB_OFF = AGENT_INSTRUCTIONS.replace(MAP_EXAMPLE, WEB_LOOKUPS_OFF);

/**
* Tufte style (the tufteStyle setting, on by default): how to show data, as a
* section of its own, contributed after the code-work section and so right
* before the Inline UI rules it refines. It is paid on every session, so it
* holds only what changes what agents write: comparisons in a number's note,
* labels on the graphic, small multiples, a lone number left in the sentence,
* ink only for data, sources and mechanisms. What the rules already say
* (prose that doesn't repeat the block's numbers, no pies) is not repeated.
*/
export const TUFTE_INSTRUCTIONS = `# Inline UI: Tufte style
Tufte style is on: show data the way Edward Tufte would. This refines the Inline UI section.
- Context: compare every number with something (prior period, target, peer). Put the comparison in the Metric's note ("+12% vs May", "target 99.9%") or a Sparkline beside it.
- Label the graphic, not a key: units on every value, series named, and a note on the point that matters, so the block reads without the prose.
- Small multiples: several entities or series → a Grid of small Charts, one each, or a Table with a Sparkline per row, never one crowded Chart.
- Density: a lone number belongs in the sentence, not in a Metric. Several facts about one thing → one Table or KeyValue, not a Card each.
- Ink only for data: no decorative Icon or Badge; a tone only where it means good, bad or over a limit.
- Every Chart, Table and Metric says where its numbers came from: Load(path) or source:.
- Mechanism: when the user asks why, show what causes the number in a Diagram, not only the number.`;

/**
* Lines of the Inline UI rules that the Tufte style section would otherwise
* contradict or repeat, and what replaces them while it is on. Same-length or
* shorter in sum, so every variant stays under BB's cap:
* - "add the block" became one block: density over several thin ones.
* - each Card's title states the finding, so words and graphic go together.
* - the small-multiples clause of the shape list, which the section says in full.
*/
export const TUFTE_SWAPS: readonly (readonly [from: string, to: string])[] = [
["In doubt, add the block.", "In doubt, add one block."],
["Wrap each block in one Card.", "Wrap each block in one Card, titled with its finding."],
["- series → Chart, many → Grid of small Charts;", "- series → Chart;"],
];

function tufteVariant(rules: string): string {
return TUFTE_SWAPS.reduce((text, [from, to]) => text.replace(from, to), rules);
}

export const AGENT_INSTRUCTIONS_TUFTE = tufteVariant(AGENT_INSTRUCTIONS);
export const AGENT_INSTRUCTIONS_TUFTE_WEB_OFF = tufteVariant(AGENT_INSTRUCTIONS_WEB_OFF);

/** The Inline UI rules for a session: Tufte style or not, web lookups on or off. */
export function agentInstructions({ tufte, web }: { tufte: boolean; web: boolean }): string {
if (tufte) return web ? AGENT_INSTRUCTIONS_TUFTE : AGENT_INSTRUCTIONS_TUFTE_WEB_OFF;
return web ? AGENT_INSTRUCTIONS : AGENT_INSTRUCTIONS_WEB_OFF;
}

/**
* The /ui skill can't ask the setting, so it carries the section behind this
* condition, with the swaps that change behaviour spelled out (the third
* only drops a clause the section repeats).
*/
export const TUFTE_SKILL_NOTE = `If \`bb plugin config genui\` shows tufteStyle = true (the default), also follow the section below, with these lines of the Inline UI section changed:
${TUFTE_SWAPS.slice(0, 2)
.map(([from, to]) => `- "${from}" → "${to}"`)
.join("\n")}`;
Loading