From 140f24c0014a6ff7c155534a48398a3a2d604bdd Mon Sep 17 00:00:00 2001 From: Alex Gorischek Date: Mon, 30 Nov 2026 21:59:57 -0800 Subject: [PATCH 1/3] Summary: a kind can count its items by a key A renderer's nouns may now give a kind a SummaryKindCount, {noun, distinct}, so items that share a key count once (a tool's several schemas are one tool): distinct keys on After, with the keys that arrived, left, or stayed with changed items. The docs now say plainly that false hides a kind's count. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- docs/guides/renderer-kit-components.md | 14 ++-- docs/reference/renderer-kit.md | 15 +++-- docs/reference/renderer-sdk.md | 24 +++++-- .../renderers/sdk/src/summary-distinct.ts | 65 +++++++++++++++++++ packages/renderers/sdk/src/summary.ts | 21 +++--- packages/renderers/sdk/test/summary.test.mjs | 34 ++++++++++ 6 files changed, 149 insertions(+), 24 deletions(-) create mode 100644 packages/renderers/sdk/src/summary-distinct.ts diff --git a/docs/guides/renderer-kit-components.md b/docs/guides/renderer-kit-components.md index 4f12f6355..08c893208 100644 --- a/docs/guides/renderer-kit-components.md +++ b/docs/guides/renderer-kit-components.md @@ -55,11 +55,15 @@ 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 - workspaces in the dependency graph), call + (`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`). When wording depends + on document contents (such as workspaces in the dependency graph), call `useSummaryNouns(props.declareNouns, nouns)`. Unnamed kinds fall back to `humanizeKind`. - **Facts:** `facts(context)` (`MountOptions.facts`) computes findings that no diff --git a/docs/reference/renderer-kit.md b/docs/reference/renderer-kit.md index 5934bb18d..05078f1dc 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. @@ -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,7 +4770,7 @@ 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: diff --git a/docs/reference/renderer-sdk.md b/docs/reference/renderer-sdk.md index bf5b0dc57..4f7c8bbce 100644 --- a/docs/reference/renderer-sdk.md +++ b/docs/reference/renderer-sdk.md @@ -1461,20 +1461,36 @@ 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` (`distinctCounts`). 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. + +| 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/renderers/sdk/src/summary-distinct.ts b/packages/renderers/sdk/src/summary-distinct.ts new file mode 100644 index 000000000..e8f37991b --- /dev/null +++ b/packages/renderers/sdk/src/summary-distinct.ts @@ -0,0 +1,65 @@ +import type {Entity, Extraction, Relationship} from '@githubnext/projections-schemas' +import type {SummaryNoun} from './protocol.js' +import type {SummaryCount, SummarySubject} from './summary.js' + +/** + * 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. + */ +export interface SummaryKindCount { + /** The kind's words; the host's words (`humanizeKind`) when absent. */ + noun?: SummaryNoun + /** The key an item of the kind counts by; `undefined` leaves the item out of the count. */ + distinct: (item: Entity | Relationship) => string | undefined +} + +/** Whether a `SummaryNouns` entry counts its kind by key. */ +export function isKindCount(entry: SummaryNoun | SummaryKindCount | false | undefined): entry is SummaryKindCount { + return typeof entry === 'object' && 'distinct' in entry && typeof entry.distinct === 'function' +} + +/** + * A kind's counts by key: the distinct keys of its items in the extraction (in `after` for a comparison) and, for a + * comparison, the keys only `after` has (`added`), the keys only `before` has (`removed`) and the keys both have whose + * items the comparison changed (`modified`). + */ +export function distinctCounts(subject: SummarySubject, count: SummaryCount, distinct: SummaryKindCount['distinct']): SummaryCount { + const keys = (extraction: Extraction) => { + const found = new Map() + for (const item of extraction[count.collection] as (Entity | Relationship)[]) { + if (item.kind !== count.kind) continue + const key = distinct(item) + if (key !== undefined) found.set(item.id, key) + } + return found + } + if (subject.mode === 'extraction') { + return {collection: count.collection, kind: count.kind, count: new Set(keys(subject.extraction).values()).size} + } + const before = keys(subject.before) + const after = keys(subject.after) + const was = new Set(before.values()) + const now = new Set(after.values()) + const changed = new Set() + for (const change of subject.comparison.changes) { + if (change.status === 'unchanged' || change.collection !== count.collection) continue + for (const id of change.before) { + const key = before.get(id) + if (key !== undefined && now.has(key)) changed.add(key) + } + for (const id of change.after) { + const key = after.get(id) + if (key !== undefined && was.has(key)) changed.add(key) + } + } + const added = [...now].filter(key => !was.has(key)).length + const removed = [...was].filter(key => !now.has(key)).length + return { + collection: count.collection, + kind: count.kind, + count: now.size, + ...(added ? {added} : {}), + ...(removed ? {removed} : {}), + ...(changed.size ? {modified: changed.size} : {}), + } +} diff --git a/packages/renderers/sdk/src/summary.ts b/packages/renderers/sdk/src/summary.ts index f2ee3ef9b..c25bfdd14 100644 --- a/packages/renderers/sdk/src/summary.ts +++ b/packages/renderers/sdk/src/summary.ts @@ -1,8 +1,10 @@ import type {Comparison, Entity, Extraction, Relationship} from '@githubnext/projections-schemas' import {rendererLimits, type SummaryCountItem, type SummaryNoun} from './protocol.js' import {humanizeKind} from './kind-nouns.js' +import {distinctCounts, isKindCount, type SummaryKindCount} from './summary-distinct.js' export {adjectivalKind, humanizeKind, kindWords, pluralWord, sentenceCase} from './kind-nouns.js' +export type {SummaryKindCount} from './summary-distinct.js' /** What a summary counts: one extraction, or a comparison of two (the shape of `InitPayload` and the host's subject). */ export type SummarySubject = @@ -31,13 +33,14 @@ export interface SummaryCount { } /** - * 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. */ export type SummaryNouns = - | Readonly> - | ((kind: string, collection: 'entities' | 'relationships') => SummaryNoun | false | undefined) + | Readonly> + | ((kind: string, collection: 'entities' | 'relationships') => SummaryNoun | SummaryKindCount | false | undefined) type Collection = 'entities' | 'relationships' @@ -93,7 +96,8 @@ const clip = (text: string) => (text.length <= rendererLimits.summaryNoun ? text /** * 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` (`distinctCounts`). The kinds an * object of nouns lists come first, in its order. At most `rendererLimits.summaryItems` figures. */ export function summaryItems(subject: SummarySubject, nouns?: SummaryNouns): SummaryCountItem[] { @@ -111,10 +115,11 @@ export function summaryItems(subject: SummarySubject, nouns?: SummaryNouns): Sum } const items: SummaryCountItem[] = [] for (const count of counts) { - const noun = lookup(count) - if (noun === false || count.kind.length > rendererLimits.summaryKind) continue - const words = noun ?? humanizeKind(count.kind) - items.push({type: 'count', ...count, noun: {singular: clip(words.singular), plural: clip(words.plural)}}) + const entry = lookup(count) + if (entry === false || count.kind.length > rendererLimits.summaryKind) continue + const counted = isKindCount(entry) ? distinctCounts(subject, count, entry.distinct) : count + const words = (isKindCount(entry) ? entry.noun : entry) ?? humanizeKind(count.kind) + items.push({type: 'count', ...counted, noun: {singular: clip(words.singular), plural: clip(words.plural)}}) if (items.length === rendererLimits.summaryItems) break } return items diff --git a/packages/renderers/sdk/test/summary.test.mjs b/packages/renderers/sdk/test/summary.test.mjs index c22dc8814..c0133d8e7 100644 --- a/packages/renderers/sdk/test/summary.test.mjs +++ b/packages/renderers/sdk/test/summary.test.mjs @@ -187,3 +187,37 @@ test('sentence case capitalizes a label, but not a name written in lowercase', ( assert.equal(sentenceCase('npmrc files'), 'Npmrc files') assert.equal(sentenceCase(''), '') }) + +test('a kind counts by key, so items sharing one count once, and false hides a kind', () => { + const schema = (id, name) => ({id, kind: 'tool-schema', label: id, data: {name}}) + const was = extraction([schema('s1', 'bash'), schema('s2', 'bash'), schema('s3', 'grep'), schema('s4', 'push'), entity('x', 'note')]) + const now = extraction([schema('s1', 'bash'), schema('s5', 'bash'), schema('s3', 'grep'), schema('s6', 'ls'), entity('x', 'note')]) + const changes = { + protocolVersion: 0, + changes: [ + change('c2', 'removed', 'entities', ['s2'], []), + change('c5', 'added', 'entities', [], ['s5']), + change('c4', 'removed', 'entities', ['s4'], []), + change('c6', 'added', 'entities', [], ['s6']), + ], + } + const nouns = {'tool-schema': {noun: {singular: 'tool', plural: 'tools'}, distinct: item => item.data?.name}, note: false} + // bash, grep and ls on After; ls arrived and push left; bash stayed but one of its schemas changed. + assert.deepEqual(summaryItems({mode: 'comparison', before: was, after: now, comparison: changes}, nouns), [ + { + type: 'count', + collection: 'entities', + kind: 'tool-schema', + count: 3, + added: 1, + removed: 1, + modified: 1, + noun: {singular: 'tool', plural: 'tools'}, + }, + ]) + // One extraction counts distinct keys; a function may count by key too, keeping the host's words. + assert.deepEqual( + summaryItems({mode: 'extraction', extraction: was}, kind => (kind === 'note' ? false : {distinct: item => item.data?.name})), + [{type: 'count', collection: 'entities', kind: 'tool-schema', count: 3, noun: {singular: 'tool schema', plural: 'tool schemas'}}], + ) +}) From e81455b37ba461d6d6f2cbeea940c22d628d5983 Mon Sep 17 00:00:00 2001 From: Alex Gorischek Date: Mon, 30 Nov 2026 22:14:46 -0800 Subject: [PATCH 2/3] Agent guide: counting by key, in the skill template it is generated from Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- docs/agents/create-projection.md | 6 ++++-- packages/cli/templates/SKILL.md | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) 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/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 From 765194df4933cd04f238598ea3f687532baec573 Mon Sep 17 00:00:00 2001 From: Alex Gorischek Date: Mon, 30 Nov 2026 22:19:30 -0800 Subject: [PATCH 3/3] Summary: a kind counted by key is a fact in the kind's place The host counts kinds itself and keeps a renderer's numbers only for facts, so a kind counted by key now goes out as a fact (kind::) in the kind's place, filtering to the items it counts. Definition nouns leave it in the renderer's words. useSummaryNouns tells nouns with another key function apart, so a changed grouping is declared again. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- docs/guides/renderer-kit-components.md | 6 ++- docs/reference/renderer-kit.md | 4 +- docs/reference/renderer-sdk.md | 7 +-- packages/host/core/test/summary.test.mjs | 23 +++++++++ packages/renderers/kit/src/react/summary.ts | 22 +++++++- packages/renderers/kit/src/summary.ts | 6 ++- packages/renderers/kit/test/summary.test.mjs | 10 ++++ .../renderers/sdk/src/summary-distinct.ts | 51 ++++++++++++------- packages/renderers/sdk/src/summary.ts | 18 ++++--- packages/renderers/sdk/test/summary.test.mjs | 21 +++++--- 10 files changed, 125 insertions(+), 43 deletions(-) diff --git a/docs/guides/renderer-kit-components.md b/docs/guides/renderer-kit-components.md index 08c893208..8cd29b3af 100644 --- a/docs/guides/renderer-kit-components.md +++ b/docs/guides/renderer-kit-components.md @@ -62,8 +62,10 @@ not have to reinvent change emphasis, legends, summary bars, or styling rules: 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`). When wording depends - on document contents (such as workspaces in the dependency graph), call + (`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`. - **Facts:** `facts(context)` (`MountOptions.facts`) computes findings that no diff --git a/docs/reference/renderer-kit.md b/docs/reference/renderer-kit.md index 05078f1dc..f76db70e1 100644 --- a/docs/reference/renderer-kit.md +++ b/docs/reference/renderer-kit.md @@ -3608,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 @@ -4774,7 +4774,7 @@ useSummaryNouns(declare: { (nouns: Readonly> | undefined | { (kind: string, collection: "entities" | "relationships"): SummaryKindCount | 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` and counting by key -the kinds it maps to a `SummaryKindCount` (`distinctCounts`). The kinds an +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` @@ -1476,7 +1476,8 @@ 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. +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 | |---|---|---| 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"[^>]*>.*?