* feat(prime): cap injected memories with count/char budgets and a visible elision banner
bd prime injects every persistent memory, whole, in alphabetical key
order, with no cap. Hook hosts cap what they ingest from SessionStart
(Claude Code persists ~25K tokens and previews far less), so a large
memory set silently loses everything past the cut -- and because the
order is alphabetical, whether a memory survives is an accident of its
key's first letter, unrelated to importance. On a real workspace with
102 memories (~160KB, ~40K tokens) roughly 80% of memories were never
ingested on any session start, which surfaced as agents "forgetting"
in-flight work after every compaction.
Add two opt-in caps, resolved flag-over-config so hook commands or
repos can adopt them without touching every hook line:
--max-memories N / prime.max-memories
--max-memory-chars N / prime.max-memory-chars
Caps apply at whole-memory boundaries and at least one memory is
always emitted, so a single oversized memory can exceed the char
budget rather than vanish. When entries are elided, a banner ahead of
the entries -- where host truncation cannot hide it -- reports how
many were cut and points at bd memories for the rest: a capped prime
never silently drops context. An explicit flag value of 0 forces
unlimited over a configured cap. Defaults leave output byte-identical
to today.
Keys stay in sorted order because the memory store keeps no
timestamps; recency- or pin-aware selection needs sidecar metadata and
is left as follow-up.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix(prime): validate cap config keys, banner names only the binding cap
Maintainer follow-ups from review of #4569, kept on the contributor
branch so the PR can merge as-is:
- validateYamlConfigValue gains non-negative-integer cases for
prime.max-memories / prime.max-memory-chars. Without them a typo like
`bd config set prime.max-memory-chars 25k` reported success while
viper's GetInt coerced the value to 0 = uncapped, silently disabling
the cap the user believed was active - the exact failure this feature
exists to prevent.
- The elision banner now names only the cap that actually fired. With
both caps configured and only one binding, it previously listed both,
producing self-contradictory output ("showing 3 of 10 ... capped by
max-memories=50") and steering users to the wrong knob.
- Flag help and doc comments now say the char cap counts bytes of the
memory entries only (header and banner excluded), matching the
implementation; document the keys in docs/CONFIG.md alongside their
peers.
- gofmt alignment in recognizedConfigKeys; reuse existing sortedKeys()
and truncate() helpers instead of inline re-implementations.
Agent-Signature: claude-fable-5-high on behalf of matt wilkie
* docs(cli): regenerate CLI reference for prime memory-cap flags
Regenerated with scripts/generate-cli-docs.sh (pinned pure-Go build) so
the check-doc-flags CI job passes; #4569 added two bd prime flags
without refreshing the generated docs.
Agent-Signature: claude-fable-5-high on behalf of matt wilkie
---------
Co-authored-by: Charlie Coutts <240021994+Wldc4rd@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: CI Bot <ci@beads.test>