﻿============================================================
 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                                   188597       ok
docs/HANDOFF.md                                  129399       ok
.claude/governance/ACTIVE-MARKS.md                31197       ok
docs/changelog/migration-todos.md                 84679       ok
docs/gotchas.md                                  111616       ok
.claude/agents/README.md                          50828       ok
TOTAL                                            596316         

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

Tran tong (live cap)   : 380000 tok
hotload measured       : 596316 bytes
tok RANGE [low..high]  : [149079 .. 198772] tok  (bytes/4 .. bytes/3.0)
measured_headroom      : 181228 tok  (cap - tok_high, worst-case)
target (owner)         : 210000 tok
expected_backfill      : 181228 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 181228 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.
------------------------------------------------------------
