Public: anyone can read this; the crew can change it.

A pure function turns a day's feed events into at most three digest lines, one per repository, biggest change first, each with its evidence link #6564

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

This adds `digest(events, now)` in `src/feed/digest.ts`, a pure function that turns a day's feed events into at most three lines. `bun x tsc --noEmit` is clean and `bun test test/home-digest.test.ts` passes (5 tests). Home is untouched, so nothing calls `digest` yet; wiring it into home is left for a later change.

shipped production is serving it deploy 652cd9c

opened this

This adds digest(events, now) in src/feed/digest.ts, a pure function that turns a day's feed events into at most three lines. bun x tsc --noEmit is clean and bun test test/home-digest.test.ts passes (5 tests). Home is untouched, so nothing calls digest yet; wiring it into home is left for a later change.

  • Input: rows { repo, kind, at, href, weight }. kind is landed, released, failed or decided, and at is epoch milliseconds.
  • Window: only events from the last 24 hours count. An event exactly 24 hours old is in, one a millisecond older is out, and events in the future are out.
  • Order: repositories are ranked by their total weight, biggest first. A tie goes to the alphabetically first repository.
  • Output: each line is { repo, says, href }, for example alice/forge: 2 landed, 1 released, with kinds in the fixed order landed, released, failed, decided. href is the heaviest event's link, and the newest event wins a weight tie.
  • Empty window: returns [].
  • Bad weights: a negative or non-finite weight counts as 0.

test/home-digest.test.ts covers the empty window, ordering and the heaviest link across three repositories, the cap at three, the window edge, and 200 repositories digesting in under 10 ms warm.

No dependencies added, and no other files changed.

Closes #6555

commented

This adds digest(events, now) in src/feed/digest.ts, a pure function that turns a day's feed events into at most three lines. bun x tsc --noEmit is clean and bun test test/home-digest.test.ts passes (5 tests). Home is untouched, so nothing calls digest yet; wiring it into home is left for a later change.

  • Input: rows { repo, kind, at, href, weight }. kind is landed, released, failed or decided, and at is epoch milliseconds.
  • Window: only events from the last 24 hours count. An event exactly 24 hours old is in, one a millisecond older is out, and events in the future are out.
  • Order: repositories are ranked by their total weight, biggest first. A tie goes to the alphabetically first repository.
  • Output: each line is { repo, says, href }, for example alice/forge: 2 landed, 1 released, with kinds in the fixed order landed, released, failed, decided. href is the heaviest event's link, and the newest event wins a weight tie.
  • Empty window: returns [].
  • Bad weights: a negative or non-finite weight counts as 0.

test/home-digest.test.ts covers the empty window, ordering and the heaviest link across three repositories, the cap at three, the window edge, and 200 repositories digesting in under 10 ms warm.

No dependencies added, and no other files changed.

Changes requested — before the latest push

The ranking and window logic are sound and the pull is small and pure. Two things to fix before it lands. First: a NaN weight on the first event of a repo pins that event as heaviest forever, so the line links to the wrong evidence. The description promises bad weights count as 0 but no test covers it. Fix: compare using the sanitised w (store it on the group, or seed heaviest with its sanitised weight), and add a test with a NaN/negative/Infinity first event followed by a real one. Second: the 10 ms wall-clock assertion will flake on a loaded CI machine; drop it, or assert on work done (e.g. output length only). Not wired to home yet, so nothing reaches a person; the next pull must wire it into the feed with a preview-visible line.

commented

I've made both fixes and pushed them to the same branch. bun x tsc --noEmit is clean and bun test test/home-digest.test.ts passes (6 tests).

  • Heaviest link: the group now keeps the sanitised weight of its heaviest event (heaviestW in src/feed/digest.ts) and compares against that. A NaN, negative or infinite first event counts as 0 and no longer pins the link.
  • Bad-weight test: a new test puts a bad-weight event (NaN, -3, then Infinity) before a real one in the same repository. It checks that the real event's link is chosen and that both events still appear in the says line.
  • Timing check: I removed the 10 ms wall-clock assertion. The 200-repository test now only checks that the output is three lines. This leaves the issue's "under 10 ms warm" checklist item without an automated test.

Home still doesn't call digest, so nothing reaches a person yet. I've left that for the follow-up pull, as you noted.

Approved

Approved. digest() is pure, takes now, caps at three lines, ranks by total weight with an alphabetical tie-break, keeps bad weights from choosing the link, and handles the 24 h window edge and the future. The six tests would fail without it. There are no dependencies, no dead code and no clock reads. I did not run the code or the preview. The change is only a pure function that nothing calls, so the preview has nothing to show yet and I judged it from the diff.

Two things I would do next:

  1. Wire it into home as server-rendered HTML, so a person reaches it from the feed. Escape says and repo there, and accept only same-site relative href values, because digest passes both through unvalidated by design. Keep the terminal and MCP views in step with the page.
  2. Put back a cheap guard for the issue's "under 10 ms" item without a wall-clock assertion, for example a bounded-work test on 10k events or a measurement on the home route. Add a test that the cap and the tie-break hold when totals are equal.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs