Skip to content

Summary: a kind can count its items by a key - #226

Open
agorischek wants to merge 1 commit into
mainfrom
agorischek/summary-distinct
Open

agorischek wants to merge 1 commit into
mainfrom
agorischek/summary-distinct

Conversation

@agorischek

Copy link
Copy Markdown
Collaborator

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 140f24c0014a6ff7c155534a48398a3a2d604bdd

Dimension Assessment Rationale
Change confidence 9/10 ↑ Opt-in: existing nouns (a SummaryNoun or false) take the same path as before.
↑ SDK test covers count, added, removed and modified by key, the function form, and hiding a kind; kit and every renderer that declares nouns type-check.
↓ No built-in counts by key yet, so there's no browser coverage.

Superego feedback item 23: summary counts.

  • Count distinct items by key. A kind's entry in SummaryNouns may be a SummaryKindCount, {noun?, distinct: item => key}, so items that share a key count once. For example, {'tool-schema': {noun: {singular: 'tool', plural: 'tools'}, distinct: item => item.data?.name}} counts a tool's several schemas as one tool. The figure counts:

    • distinct keys on After;
    • added: keys only After has;
    • removed: keys only Before has;
    • modified: keys both have whose items the comparison changed.

    It works in the object and function forms of SummaryNouns, and keeps the host's words when noun is left out.

  • Hide a kind's count. This already works: false leaves a kind out of the summary. The docs now say so plainly ("false hides a kind's count"), where before they described it only as a way to omit structural kinds.

Documented in the components guide (Summary bar, Kinds) and the agent authoring guide.

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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Host aggregation and renderer checks do not preserve distinct-counting semantics, producing incorrect totals, and noun change detection ignores replacement grouping callbacks.

2 open issues
What changed in this PR

Adds opt-in distinct-key counting to the renderer SDK’s summary API, allowing several items of a kind to represent one logical item.

Changes:

  • Extends SummaryNouns with SummaryKindCount, including optional custom wording.
  • Computes distinct totals and added, removed and modified key counts, with SDK test coverage.
  • Documents keyed counting and clarifies that false hides a kind’s count.
File Description
packages/​renderers/​sdk/​test/​summary.test.mjs Tests keyed counts, function-form configuration and hidden kinds.
packages/​renderers/​sdk/​src/​summary.ts Integrates keyed counting into summary generation.
packages/​renderers/​sdk/​src/​summary-distinct.ts Defines keyed-count options and calculates distinct totals and changes.
docs/​reference/​renderer-sdk.md Updates SDK signatures and documents SummaryKindCount.
docs/​reference/​renderer-kit.md Updates kit API signatures to accept keyed-count options.
docs/​guides/​renderer-kit-components.md Adds a keyed-count example and clarifies count visibility.

Review effort: Balanced

Comment on lines +120 to +122
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)}})
export type SummaryNouns =
| Readonly<Record<string, SummaryNoun | false>>
| ((kind: string, collection: 'entities' | 'relationships') => SummaryNoun | false | undefined)
| Readonly<Record<string, SummaryNoun | SummaryKindCount | false>>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants