The wheelhouse-side tripwire only REPORTS the memory-corpus size, so the corpus
re-trips red every few days and nothing has ever stopped the write that crossed
the line. This is the stop.
New config key `memories.budget-chars` (integer, default 0 = OFF), wired exactly
like `prime.max-memory-chars`: recognized in cmd/bd/config.go, routed to yaml in
internal/config YamlOnlyKeys (it is read through viper, so a DB-backed write
would be accepted and then never read), validated non-negative at set time, and
documented in docs/reference/configuration.md.
With the budget ON, `bd remember` measures the corpus as the sum over every
memory of len(key)+len(content) — BYTES, the same unit `bd prime`'s
--max-memory-chars counts in — projected to AFTER the write would apply. An
overwrite replaces that key's old content in the sum rather than adding to it,
so a memory near the ceiling can still be edited.
- over budget -> refused, nothing written, exit 1, one line on stderr
- over budget + --force -> written, and the crossing is still announced
- >= 80% and within -> written, then warned
- below 80%, or budget 0 -> silent; with the budget off the corpus is not even
read, so behavior is byte-identical to before
Every line goes to STDERR, so --json output is never corrupted; a --json refusal
additionally gets the normal machine-readable error object on stdout.
The whole decision is one pure function (rememberBudgetVerdict), which is what
lets the branches be pinned without a database.
Tests run (targeted, never ./...):
go build ./... rc 0
go vet ./cmd/bd/ ./internal/config/ rc 0
go test ./cmd/bd/ -run 'Memor|Remember|Prime|Budget' -count=1 rc 0
go test ./internal/config/ -count=1 rc 0
BEADS_TEST_EMBEDDED_DOLT=1 go test ./cmd/bd/ \
-run TestEmbeddedMemoryCorpusBudget -count=1 -v rc 0 (6/6 subtests)
golangci-lint run --config=.golangci.yml --build-tags=gms_pure_go \
./cmd/bd/... ./internal/config/... 0 issues in touched
files (one
pre-existing gosec
G304 in
internal/config/permissions_open_nonlinux.go)
New tests: cmd/bd/memory_budget_pure_test.go (byte unit incl. multibyte,
overwrite delta, budget-off silence, config read + negative clamp, the
at-budget/one-over boundary, --force, the 80% warn band and its edges,
unclamped percentage, single-line contract);
cmd/bd/memory_embedded_test.go TestEmbeddedMemoryCorpusBudget (the same five
spec points end to end against a real embedded-Dolt store, through
`bd config set`, asserting the exact stderr lines, the nonzero exit, and that a
refused write leaves the old content intact);
internal/config/yaml_config_test.go validation + yaml-only routing.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013XmKxqKuXTaKivDiCoBwBV