compact-module

31 beliefs (22 IN, 9 OUT)

The compact module is the subsystem responsible for distilling a belief network into a budget-constrained markdown string suitable for inclusion in context-limited pipelines. It operates as a pure function with no side effects, no I/O, and no mutation of the underlying network (compact-is-pure-function, compact-pure-function), and it is designed to be infallible, gracefully handling edge cases like empty networks, zero budgets, and missing metadata without raising exceptions (compact-is-infallible). The module's output is organized into three priority-ordered sections — nogoods first, then OUT (retracted) nodes, then IN (active) nodes — where earlier sections are never displaced by later ones (compact-priority-order, compact-priority-order-is-nogoods-out-in, compact-three-sections). Within the IN section, nodes are sorted by descending dependent count so that structurally important beliefs survive budget truncation (compact-in-nodes-ordered-by-dependents). A footer reporting token usage is pre-reserved before any section begins filling, guaranteeing auditability metadata always appears (compact-footer-pre-reserved, compact-self-reports-tokens).

Budget enforcement relies on an efficient but approximate strategy. Token estimation uses a simple chars/4 heuristic rather than word counting or an external tokenizer (compact-estimate-tokens-chars-div-4), and per-line budget checks run in O(1) time via a running character count (compact-char-tracking-o1, compact-budget-tracking-is-efficient-and-approximate). Crucially, the budget is a soft cap, not a hard guarantee — structural overhead such as section headers and truncation messages can cause actual output to overshoot the specified budget by up to roughly 25% (compact-budget-is-soft-cap, compact-budget-soft-ceiling). An earlier belief (compact-never-exceeds-budget) asserts a strict guarantee, creating a tension with the soft-cap beliefs that the network has not fully resolved. Additional features include summary-node elision, where IN nodes covered by a summary node are hidden from output to reduce redundancy, provided the summary itself remains IN (compact-summary-nodes-hide-covered, compact-summary-hiding-requires-in), and surfacing of stale-reason metadata on OUT nodes (compact-surfaces-stale-reason-metadata). The Postgres-backed API layer wraps this with access-tag filtering via visible_to (pg-compact-generates-budget-constrained-markdown).

The retracted beliefs tell an important story about how understanding of the module evolved. Several ambitious composite claims — that compact is simultaneously deterministic, bounded, and structurally complete (compact-is-deterministic-pure-and-bounded, compact-is-efficient-deterministic-and-bounded, compact-is-predictable-bounded-distillation, compact-output-is-structurally-complete-and-predictably-bounded) — were retracted because the "bounded" component turned out to be only approximately true. The discovery that structural overhead can cause meaningful budget overshoot invalidated any claim of hard guarantees. Similarly, compact-token-estimate-is-word-count was retracted once the actual chars/4 mechanism was identified. The broader system-level claim (system-output-is-complete-bounded-and-ci-ready) fell for the same reason. What survives is a more honest characterization: the compact module is pure, deterministic, priority-ordered, and infallible, with budget enforcement that is computationally efficient and practically effective but approximate rather than mathematically strict. The network also contains a few acknowledged duplicates (compact-sorts-by-dependents, compact-sorts-in-nodes-by-dependents-descending) that mirror compact-in-nodes-ordered-by-dependents.