============================================================
 crystallized-backfill.ps1  -  measure-then-fill (DRY planner)
 tier        : lead
 budget.json : D:\Dropbox\CONG_VIEC\SOLUTION\SOLUTION_ERP\.claude\agent-memory\memory-budget.json
 cb config   : present (target + hotload_sources read LIVE)
============================================================

### hot-load sources (LIVE byte-measure, UTF8)

source                                            bytes    state
-------------------------------------------- ---------- --------
docs/STATUS.md                                   256351       ok
docs/HANDOFF.md                                  246513       ok
.claude/governance/ACTIVE-MARKS.md                36153       ok
docs/changelog/migration-todos.md                 90161       ok
docs/gotchas.md                                  137768       ok
.claude/agents/README.md                          63637       ok
TOTAL                                            830583         

### budget numbers (Upgrade-1) - ALL live-read, 0 hardcoded

Tran tong (live cap)   : 380000 tok
hotload measured       : 830583 bytes
tok RANGE [low..high]  : [207646 .. 276861] tok  (bytes/4 .. bytes/3.0)
measured_headroom      : 103139 tok  (cap - tok_high, worst-case)
target (owner)         : 210000 tok
expected_backfill      : 103139 tok  (min(target,headroom)=headroom => headroom binds (target exceeds room))

### value-gated backfill source-order (planner / DRY - no pour)

  precondition MET (target>0 AND headroom>0): would pull up to 103139 tok in order:
    1. gist             archive/*.gist.md (4-field distilled)
    2. value-marked     archive lines carrying gotcha# / anti-pattern / root-cause
    3. curated RAG      search_memory high-value hits
    (each stage DEDUP vs the hot-load sources above; stop at expected_backfill)

------------------------------------------------------------
 HONEST CAVEAT
   char/4 is NOT a real token count; VN-diacritic hot-memory ~3.0-3.5 byte/tok.
   Headroom is a RANGE [bytes/4 .. bytes/3.0]; this planner uses bytes/3.0 (worst).
   backfill defaults to 0 = TAT until the OWNER sets target>0 AND measured headroom>0.
   Every budget number is the OWNER's authority; this script is READ-ONLY (never tunes/writes).
   HEADROOM is measured over a STABLE FILE-FLOOR (the configured hotload_sources) = an UPPER BOUND.
   The PEAK hot-feed also loads session-variable task-context NOT in this list; real headroom is SMALLER.
------------------------------------------------------------
