diff --git a/docs/agents/create-projection.md b/docs/agents/create-projection.md index 68a1550ef..6c54f21bc 100644 --- a/docs/agents/create-projection.md +++ b/docs/agents/create-projection.md @@ -595,8 +595,10 @@ animated from the same view if time allows. The starter does this: (old struck through, then new). - Draw no summary line in any mode: the host's summary bar, along the bottom of the view, counts each kind with its changes. Name the kinds in your - domain's words with `nouns` in `src/view.tsx`'s `options` (`false` leaves - out structure, such as containment drawn as boundaries), and state what + domain's words with `nouns` in `src/view.tsx`'s `options` (`false` hides a + kind's count, such as containment drawn as boundaries; + `{noun, distinct: item => key}` counts items that share a key once, such as + a tool's several schemas), and state what counts can't say (`2 breaking changes`, `1 newly enforced`) as `facts` computed from the document, each with the IDs it filters to. - Say every change in words too (`ChangeFooter`, `sr-only` text), and let the diff --git a/docs/guides/renderer-kit-components.md b/docs/guides/renderer-kit-components.md index 4f12f6355..8cd29b3af 100644 --- a/docs/guides/renderer-kit-components.md +++ b/docs/guides/renderer-kit-components.md @@ -55,10 +55,16 @@ not have to reinvent change emphasis, legends, summary bars, or styling rules: `summary` automatically (`rendererSummary`), renderers never draw their own summary or statistics row—just name your kinds and provide any domain facts: - **Kinds:** pass `nouns` in view `options` or `mountRenderer` - (`MountOptions.nouns`: `{kind: {singular, plural}}`, `false` to omit - structural kinds like `contains`, or `relationships:kind` for a single - collection; listed kinds come first in order, and kinds with identical names - merge into one figure). When wording depends on document contents (such as + (`MountOptions.nouns`: `{kind: {singular, plural}}`, `false` to hide a + kind's count (structural kinds like `contains`), or `relationships:kind` for + a single collection; listed kinds come first in order, and kinds with + identical names merge into one figure). To count a kind's items by a key, so + items that share one count once, give it a `SummaryKindCount`: + `{'tool-schema': {noun: {singular: 'tool', plural: 'tools'}, distinct: item => item.data?.name}}` + counts distinct names on After, with names that arrived (`added`), left + (`removed`) or stayed with changed items (`modified`). The host counts kinds + itself, so the kit sends such a kind as a fact in its place, filtering to + the items it counts. When wording depends on document contents (such as workspaces in the dependency graph), call `useSummaryNouns(props.declareNouns, nouns)`. Unnamed kinds fall back to `humanizeKind`. diff --git a/docs/reference/renderer-kit.md b/docs/reference/renderer-kit.md index 5934bb18d..f76db70e1 100644 --- a/docs/reference/renderer-kit.md +++ b/docs/reference/renderer-kit.md @@ -2483,7 +2483,7 @@ A renderer's legend: an optional title and its items; no items clears it. ### `rendererSummary` ```ts -rendererSummary(init: RendererEnvironment & { "focus"?: RendererFocus; "projection": RendererProjection } & { "after": Extraction; "before": Extraction; "comparison": Comparison; "comparisonMode"?: "animated" | "diff" | "side-by-side" | "swipe"; "mode": "comparison" } | RendererEnvironment & { "focus"?: RendererFocus; "projection": RendererProjection } & { "extraction": Extraction; "mode": "extraction" }, nouns?: Readonly> | undefined | { (kind: string, collection: "entities" | "relationships"): SummaryNoun | false | undefined }, facts?: Array): RendererSummary +rendererSummary(init: RendererEnvironment & { "focus"?: RendererFocus; "projection": RendererProjection } & { "after": Extraction; "before": Extraction; "comparison": Comparison; "comparisonMode"?: "animated" | "diff" | "side-by-side" | "swipe"; "mode": "comparison" } | RendererEnvironment & { "focus"?: RendererFocus; "projection": RendererProjection } & { "extraction": Extraction; "mode": "extraction" }, nouns?: Readonly> | undefined | { (kind: string, collection: "entities" | "relationships"): SummaryKindCount | SummaryNoun | false | undefined }, facts?: Array): RendererSummary ``` The summary a kit renderer posts for a document: a figure per extraction kind with its counts, worded with the @@ -3272,10 +3272,11 @@ A noun of the renderer's domain, for one item and for any other count: `{singula ### `SummaryNouns` ```ts -type SummaryNouns = Readonly> | { (kind: string, collection: "entities" | "relationships"): SummaryNoun | false | undefined } +type SummaryNouns = Readonly> | { (kind: string, collection: "entities" | "relationships"): SummaryKindCount | SummaryNoun | false | undefined } ``` -A renderer's words for kinds: a noun per kind, or `false` to leave a kind out of the summary. A key may name one +A renderer's words for kinds: a noun per kind, `false` to hide a kind's count (leave it out of the summary), or a +`SummaryKindCount` to count a kind's items by a key, so items that share one count once. A key may name one collection's kind (`relationships:index`), which wins over the bare kind. As an object, the kinds it lists come first, in its order; as a function (given the kind and its collection), `undefined` keeps the host's words. @@ -3607,7 +3608,7 @@ A span of progress, centred on `time` and reaching `radius` either side: `[time ### `withDefinitionNouns` ```ts -withDefinitionNouns(items: Array, kinds: Record | undefined): Array +withDefinitionNouns(items: Array, kinds: Record | undefined): Array ``` Count figures worded with the definition's nouns (`presentation.kinds..noun`, sent as @@ -4042,7 +4043,7 @@ Everything but the renderer props is optional; the defaults draw every entity as | `compound` | `"compound"?: Array \| false \| true` | Group containment-only entities into boundaries: `true` for modules (architecture), or the kinds that may become boundaries. | | `controls` | `"controls": Record` | The value of every declared control (from `MountOptions.controls` or `declareControls`), defaults filled in. The host draws the controls and sends their values; renderers draw no settings controls of their own. | | `declareControls` | `"declareControls": { (controls: Array; "default": string; "type": "choice" } \| ControlBase & { "default": false \| true; "type": "toggle" } \| ControlBase & { "default": number; "max": number; "min": number; "step": number; "type": "range"; "unit"?: string } \| ControlBase & { "icon"?: "collapse" \| "download" \| "expand" \| "filter" \| "fit" \| "next" \| "previous" \| "reset" \| "search" \| "settings" \| "zoom-in" \| "zoom-out"; "type": "action" }>): void }` | Replaces the declared controls, for controls that depend on the document (for example a filter listing its kinds). Repeated identical declarations are ignored. | -| `declareNouns` | `"declareNouns": { (nouns: Readonly> \| undefined \| { (kind: string, collection: "entities" \| "relationships"): SummaryNoun \| false \| undefined }): void }` | Names the document's kinds in the host's summary bar, replacing `MountOptions.nouns` (see `useSummaryNouns`). The shell counts every kind and posts the summary itself; without nouns, the host words kinds from their names. | +| `declareNouns` | `"declareNouns": { (nouns: Readonly> \| undefined \| { (kind: string, collection: "entities" \| "relationships"): SummaryKindCount \| SummaryNoun \| false \| undefined }): void }` | Names the document's kinds in the host's summary bar, replacing `MountOptions.nouns` (see `useSummaryNouns`). The shell counts every kind and posts the summary itself; without nouns, the host words kinds from their names. | | `describeStatus` | `"describeStatus"?: undefined \| { (node: TransitionNode): Array \| undefined }` | The domain's wording of a row's change in its status footer and accessible name (see `StatusPart`). | | `detail` | `"detail"?: undefined \| { (entity: Entity): string \| undefined }` | A short code identifier drawn in monospace at the right of a card's kind line, such as a package version. When it differs between revisions, the two crossfade with the card's own step. | | `diff` | `"diff": false \| true` | Whether the host presents this comparison in `diff` mode: one static frame showing both subjects, with no progress (`progress` stays 1 and `schedule` is empty). Draw the renderer's own static comparison; `highlighting` is the host's change emphasis for it (1 unless the host turned highlighting off). | @@ -4204,7 +4205,7 @@ How `mountRenderer` connects a renderer component to its host. | `facts` | `"facts"?: SummaryFacts` | The renderer's domain facts for the host's summary bar (`SummaryFacts`), computed from the document and the control values whenever either changes, and posted after the kind counts. A renderer draws no summary line of its own: what it would count goes here. | | `interactions` | `"interactions"?: false` | Hover, anchors, scroll mirroring, the host's filter and annotation badges through `connectInteractions` over elements carrying `data-entity-id` (default on). `false` opts out and declares none of the interaction capabilities. | | `name` | `"name": string` | Bundle name, used for `data-renderer` on the root element. | -| `nouns` | `"nouns"?: Readonly> \| { (kind: string, collection: "entities" \| "relationships"): SummaryNoun \| false \| undefined }` | The renderer's words for extraction kinds in the host's summary bar (`SummaryNouns`), for every document; see `declareNouns` for words that depend on the document. | +| `nouns` | `"nouns"?: Readonly> \| { (kind: string, collection: "entities" \| "relationships"): SummaryKindCount \| SummaryNoun \| false \| undefined }` | The renderer's words for extraction kinds in the host's summary bar (`SummaryNouns`), for every document; see `declareNouns` for words that depend on the document. | | `scope` | `"scope"?: { "context"?: { (all: ComparisonModel, changes: ReadonlySet, renderer: string): Iterable }; "layout": "subset"; "parts"?: "fold" \| "omit" \| "whole" } \| { "layout": "fold" }` | How the Changes scope reaches the renderer. `fold` (the default): `model` holds every item and the renderer folds what `scope` leaves out, as a list does. `subset`: `model` holds only what the scope shows (`scopedModel`), with the shown entities' `parts` left out, kept whole or folded, so a canvas lays out only that; `scope.all` holds every item. A subset renderer that needs more to place a change than its relationships' endpoints and containers (a package's path from the workspace, a selector's probe and hook) returns those items' row IDs from `context`, given every item, the changes in scope and its renderer name; they show as context. | | `steps` | `"steps"?: "manual" \| "schedule"` | `schedule` (default) reports the end of each scheduled step to the host; `manual` leaves it to the component through `reportSteps`. | @@ -4343,7 +4344,7 @@ Everything a kit renderer component receives for one host state. | `comparisonMode` | `"comparisonMode": "animated" \| "diff" \| "side-by-side" \| "swipe" \| undefined` | The comparison mode the host announced in `init`, if any. | | `controls` | `"controls": Record` | The value of every declared control (from `MountOptions.controls` or `declareControls`), defaults filled in. The host draws the controls and sends their values; renderers draw no settings controls of their own. | | `declareControls` | `"declareControls": { (controls: Array; "default": string; "type": "choice" } \| ControlBase & { "default": false \| true; "type": "toggle" } \| ControlBase & { "default": number; "max": number; "min": number; "step": number; "type": "range"; "unit"?: string } \| ControlBase & { "icon"?: "collapse" \| "download" \| "expand" \| "filter" \| "fit" \| "next" \| "previous" \| "reset" \| "search" \| "settings" \| "zoom-in" \| "zoom-out"; "type": "action" }>): void }` | Replaces the declared controls, for controls that depend on the document (for example a filter listing its kinds). Repeated identical declarations are ignored. | -| `declareNouns` | `"declareNouns": { (nouns: Readonly> \| undefined \| { (kind: string, collection: "entities" \| "relationships"): SummaryNoun \| false \| undefined }): void }` | Names the document's kinds in the host's summary bar, replacing `MountOptions.nouns` (see `useSummaryNouns`). The shell counts every kind and posts the summary itself; without nouns, the host words kinds from their names. | +| `declareNouns` | `"declareNouns": { (nouns: Readonly> \| undefined \| { (kind: string, collection: "entities" \| "relationships"): SummaryKindCount \| SummaryNoun \| false \| undefined }): void }` | Names the document's kinds in the host's summary bar, replacing `MountOptions.nouns` (see `useSummaryNouns`). The shell counts every kind and posts the summary itself; without nouns, the host words kinds from their names. | | `diff` | `"diff": false \| true` | Whether the host presents this comparison in `diff` mode: one static frame showing both subjects, with no progress (`progress` stays 1 and `schedule` is empty). Draw the renderer's own static comparison; `highlighting` is the host's change emphasis for it (1 unless the host turned highlighting off). | | `direction` | `"direction": -1 \| 1` | The host's playback direction (`ProgressPayload.direction`): 1 toward After, -1 back toward Before. Always 1 for an extraction and in diff mode. `schedule` is already ordered for the direction the transition presents. | | `emphasis` | `"emphasis": EmphasisOf` | A change's emphasis now: 0 until its comparison step begins, then the host's highlighting; in a held pane, the host's highlighting (see `stepEmphasis`). Pass the row ID as the second argument when the object passed has none. | @@ -4769,11 +4770,11 @@ zoom multiple of the new fit. ### `useSummaryNouns` ```ts -useSummaryNouns(declare: { (nouns: Readonly> | undefined | { (kind: string, collection: "entities" | "relationships"): SummaryNoun | false | undefined }): void }, nouns: Readonly> | undefined | { (kind: string, collection: "entities" | "relationships"): SummaryNoun | false | undefined }): void +useSummaryNouns(declare: { (nouns: Readonly> | undefined | { (kind: string, collection: "entities" | "relationships"): SummaryKindCount | SummaryNoun | false | undefined }): void }, nouns: Readonly> | undefined | { (kind: string, collection: "entities" | "relationships"): SummaryKindCount | SummaryNoun | false | undefined }): void ``` Names the renderer's kinds in the host's summary bar (`RendererProps.declareNouns`): `{package: {singular: -'workspace', plural: 'workspaces'}}`, `false` to leave a kind out. The kinds an object lists come first, in its +'workspace', plural: 'workspaces'}}`, `false` to leave a kind out, `{noun, distinct}` to count it by key. The kinds an object lists come first, in its order. Pass a stable value (memoize a function); `undefined` returns to `MountOptions.nouns`. ### `useTableProps` diff --git a/docs/reference/renderer-sdk.md b/docs/reference/renderer-sdk.md index bf5b0dc57..3b281cce9 100644 --- a/docs/reference/renderer-sdk.md +++ b/docs/reference/renderer-sdk.md @@ -1461,20 +1461,37 @@ A change count in words, for accessible names: `2 added`, `1 removed`, `3 modifi ### `summaryItems` ```ts -summaryItems(subject: { "after": Extraction; "before": Extraction; "comparison": Comparison; "mode": "comparison" } | { "extraction": Extraction; "mode": "extraction" }, nouns?: Readonly> | undefined | { (kind: string, collection: "entities" | "relationships"): SummaryNoun | false | undefined }): Array +summaryItems(subject: { "after": Extraction; "before": Extraction; "comparison": Comparison; "mode": "comparison" } | { "extraction": Extraction; "mode": "extraction" }, nouns?: Readonly> | undefined | { (kind: string, collection: "entities" | "relationships"): SummaryKindCount | SummaryNoun | false | undefined }): Array ``` A subject's summary, as a renderer posts it: a count figure (`type: 'count'`) per kind and collection (`summaryCounts`), worded with `nouns` where it gives -a noun and the host's words (`humanizeKind`) otherwise, leaving out the kinds it maps to `false`. The kinds an +a noun and the host's words (`humanizeKind`) otherwise, leaving out the kinds it maps to `false` and counting by key +the kinds it maps to a `SummaryKindCount` as a fact in the kind's place (`keyedFact`). The kinds an object of nouns lists come first, in its order. At most `rendererLimits.summaryItems` figures. +### `SummaryKindCount` + +```ts +interface SummaryKindCount +``` + +A kind counted by a key rather than item by item (see `SummaryNouns`): items that share a key count once, so a +tool's several schemas, say, are one tool. Its words are `noun`, or the host's. The host counts kinds itself, so a +kind counted by key is sent as a fact (`keyedFact`) in the kind's place, filtering to the items it counts. + +| Member | Signature | Description | +|---|---|---| +| `distinct` | `"distinct": { (item: Entity \| Relationship): string \| undefined }` | The key an item of the kind counts by; `undefined` leaves the item out of the count. | +| `noun` | `"noun"?: SummaryNoun` | The kind's words; the host's words (`humanizeKind`) when absent. | + ### `SummaryNouns` ```ts -type SummaryNouns = Readonly> | { (kind: string, collection: "entities" | "relationships"): SummaryNoun | false | undefined } +type SummaryNouns = Readonly> | { (kind: string, collection: "entities" | "relationships"): SummaryKindCount | SummaryNoun | false | undefined } ``` -A renderer's words for kinds: a noun per kind, or `false` to leave a kind out of the summary. A key may name one +A renderer's words for kinds: a noun per kind, `false` to hide a kind's count (leave it out of the summary), or a +`SummaryKindCount` to count a kind's items by a key, so items that share one count once. A key may name one collection's kind (`relationships:index`), which wins over the bare kind. As an object, the kinds it lists come first, in its order; as a function (given the kind and its collection), `undefined` keeps the host's words. diff --git a/packages/cli/templates/SKILL.md b/packages/cli/templates/SKILL.md index c62839ae6..ef791b947 100644 --- a/packages/cli/templates/SKILL.md +++ b/packages/cli/templates/SKILL.md @@ -568,8 +568,10 @@ animated from the same view if time allows. The starter does this: (old struck through, then new). - Draw no summary line in any mode: the host's summary bar, along the bottom of the view, counts each kind with its changes. Name the kinds in your - domain's words with `nouns` in `src/view.tsx`'s `options` (`false` leaves - out structure, such as containment drawn as boundaries), and state what + domain's words with `nouns` in `src/view.tsx`'s `options` (`false` hides a + kind's count, such as containment drawn as boundaries; + `{noun, distinct: item => key}` counts items that share a key once, such as + a tool's several schemas), and state what counts can't say (`2 breaking changes`, `1 newly enforced`) as `facts` computed from the document, each with the IDs it filters to. - Say every change in words too (`ChangeFooter`, `sr-only` text), and let the diff --git a/packages/host/core/test/summary.test.mjs b/packages/host/core/test/summary.test.mjs index ee2f29b06..7a45a0dc0 100644 --- a/packages/host/core/test/summary.test.mjs +++ b/packages/host/core/test/summary.test.mjs @@ -14,6 +14,7 @@ import { useProjection, } from '../dist/index.js' import {SummaryBar} from '../dist/ui/index.js' +import {summaryItems} from '@githubnext/projections-renderer-sdk/presentation' const entity = (id, kind) => ({id, kind, label: id}) const relationship = (id, kind, from, to) => ({id, kind, from, to}) @@ -221,3 +222,25 @@ test('a fact carries its changes and a description: the bar draws the changes as /]*aria-describedby="([^"]+)"[^>]*title="Classified by the shared rules\nShow only the breaking changes"[^>]*>.*?