[CLAUDE] Workflow: adopt presence-not-age selector guardrail + rec-3 hmw.js STOP-HARD (S115)
All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 5m23s

Adopt AI_INFRA 2026-07-13 broadcast ab6c387e (presence-not-age selector,
type=update) + directed 6c32df89 rec-3, via /fable-clone 5-lane reviewer
ensemble (wf_b621aac4-f0b) -> spec -> /fable-real deep-pass (PASS-WITH-FIXES,
M1+M2 applied) -> HMW execute (em-main solo; governance single-writer D9).

D2 (hmw.js): unknown-role fail-soft-WARN -> up-front STOP-HARD throw (before
  parallel; preserves null/'' role-less inherit-lead path). node --check + stub
  7/7. Doc-sync 5 live lines (ultra-on/README/harness-11-engine/runbook).
D3 (memory-archive-gate.ps1): value_protect advisory-flag -> pre-selection
  HARD-SKIP (value-primary; heading-only spans; non-contiguous byte accum) +
  value-floor WARN. Fault-inject ALL PASS + real regression A7 242/242. DRY-RUN.
D1 (reinject-ledger.md): presence re-verify stamp + 3 honest-notes + BUILD-GAP.

Re-verify: reinject (i) + MFE age-band (iii) already COMPLIANT; only the
archive-gate age-trace needed hardening. D3 = defense-in-depth codify, NOT
leak-closure (9-token grep unchanged; em-main value-scan stays the guarantee).

adap-report + email AI_INFRA (8b9dc5165d5a); inbox STAGE-2 processed. No new
User-Mark (codify-only). #53 garble x1 (lane-4) recovered from disk, 0 loss.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
pqhuy1987
2026-07-13 12:25:24 +07:00
parent de3536d47e
commit 81b59f0389
21 changed files with 1081 additions and 47 deletions

View File

@ -134,60 +134,83 @@ foreach ($d in $subDirs) {
$anyOver = $true
# --- A4 hysteresis + A5 keep-floor : how many OLDEST entries to move? ---
# Move oldest entries one-by-one; estimate bytes-after by cutting at the
# marker line of the FIRST entry we keep. Stop when est < lowMark, but never
# let kept-entries drop below keepFloor.
# --- D3 (DIRECTED 6c32df89 REC-3, 2026-07-13): value-PRIMARY drain (was A4/A5 oldest-first) ---
# CORRECTED per fable-real M2: value-protected LOGICAL entries are HARD-SKIPPED (partitioned
# OUT of the movable pool) BEFORE the size-drain, then bytes are accumulated over the chosen
# INDIVIDUAL (non-contiguous) low-value entries -- NOT a contiguous top-prefix (a naive
# "skip" on the old prefix-cut left the protected entry ABOVE the cut = silent inversion).
# value_protect is now a PRE-SELECTION hard-skip, not an advisory post-hoc flag.
# LOGICAL entries = HEADING markers ONLY (^#{2,3}\s) -- NOT the '---' separators that
# Get-EntryMarkerLineNumbers also counts (else a value token after a '---' flags the wrong
# pseudo-span). keep_floor / DRY-RUN / strike-gating all preserved.
$moveCount = 0
$afterEst = $bytes
$warnFloor = $false
$warnValue = $false
if ($entryCount -le $keepFloor) {
# Already at/under floor but still over cap => cannot auto-drain.
# (1) logical-entry heads + per-entry byte size + value-protected flag (whole span, age-blind)
$headIdx = @()
for ($hi = 0; $hi -lt $lines.Count; $hi++) { if ($lines[$hi] -match '^#{2,3}\s') { $headIdx += $hi } }
$logCount = $headIdx.Count
$entBytes = @()
$entProt = @()
for ($k = 0; $k -lt $logCount; $k++) {
$start = $headIdx[$k]
if ($k -lt $logCount - 1) { $end = $headIdx[$k + 1] - 1 } else { $end = $lines.Count - 1 }
$b = 0
$p = $false
for ($li = $start; $li -le $end; $li++) {
$b += ($lines[$li].Length + 2) # +2 ~ CRLF est (mirror legacy)
if ((-not $p) -and ($valPatterns.Count -gt 0)) {
foreach ($vp in $valPatterns) { if ($lines[$li] -like "*$vp*") { $p = $true; break } }
}
}
$entBytes += $b
$entProt += $p
}
if ($logCount -le $keepFloor) {
# At/under keep-floor but still over cap => cannot auto-drain by size.
$warnFloor = $true
$afterEst = $bytes
} else {
# markers[k] = line index where entry (k) starts. Keeping entries
# [k..end] means the kept region begins at byte offset of markers[k].
# Bytes-after = total - (bytes before markers[k]).
for ($move = 1; $move -le ($entryCount - $keepFloor); $move++) {
$cutLine = $markers[$move] # first KEPT entry starts here (0-based line idx)
# bytes of the moved prefix = sum of (line length + 1 newline) for lines [0..cutLine-1]
$prefixBytes = 0
for ($li = 0; $li -lt $cutLine; $li++) { $prefixBytes += ($lines[$li].Length + 2) } # +2 ~ CRLF est
$est = $bytes - $prefixBytes
$moveCount = $move
$afterEst = $est
if ($est -lt $lowMark) { break }
# (2) keep_floor = newest-N logical entries (bottom = newest, append-to-end convention)
$floorStart = $logCount - $keepFloor
# (3)+(4) NON-CONTIGUOUS size-drain: position-order walk BUT hard-skip value-protected;
# accumulate INDIVIDUAL chosen low-value bytes (never a top-prefix).
$movedBytes = 0
for ($k = 0; $k -lt $floorStart; $k++) {
if ($entProt[$k]) { continue } # value-primary hard-skip (age-blind, any position)
$moveCount++
$movedBytes += $entBytes[$k]
$afterEst = $bytes - $movedBytes
if ($afterEst -lt $lowMark) { break }
}
# If we exhausted the movable range and still >= lowMark, floor was hit.
if ($afterEst -ge $cap -and $moveCount -eq ($entryCount - $keepFloor)) { $warnFloor = $true }
}
# --- H15 B(b) value-protect: scan the MOVED prefix for high-value markers ---
$valHits = @()
if ($moveCount -gt 0 -and $valPatterns.Count -gt 0) {
$cutLine = $markers[$moveCount] # first KEPT line; moved region = lines [0..cutLine-1]
for ($vli = 0; $vli -lt $cutLine; $vli++) {
foreach ($vp in $valPatterns) {
if ($lines[$vli] -like "*$vp*") { $valHits += $vp; break }
}
# (5) low-value pool exhausted and still over cap? distinguish value-floor vs keep-floor
if ($afterEst -ge $cap) {
$anyProt = $false
for ($k = 0; $k -lt $floorStart; $k++) { if ($entProt[$k]) { $anyProt = $true; break } }
if ($anyProt) { $warnValue = $true } else { $warnFloor = $true }
}
}
# --- A6 gate the resolution wording on the strike count ---
if ($warnFloor) {
if ($warnValue) {
$resolve = "WARN value-floor hit: over-cap but every drainable entry is value-protected/keep-floor - condense high-value BY HAND (do NOT age-archive)"
} elseif ($warnFloor) {
$resolve = "WARN keep-floor hit ($keepFloor); cannot auto-drain - SPLIT/condense entries by hand"
} elseif ($cur -ge $strikeNeed) {
$resolve = "PROPOSE archive (strike $cur>=$strikeNeed): move $moveCount oldest -> curate L1->L2 by hand"
$resolve = "PROPOSE archive (strike $cur>=$strikeNeed): move $moveCount lowest-value (position tiebreak) -> curate L1->L2 by hand"
} else {
$resolve = "WATCH (strike $cur<$strikeNeed): re-run; propose only after $strikeNeed consecutive over-cap"
}
Write-Output ("{0,-24} {1,9} {2,5} {3,10} {4,7} {5,12} {6}" -f $sub, $bytes, 'YES', $entryCount, $cur, "~$afterEst", $resolve)
if ($valHits.Count -gt 0) {
$uniqHits = ($valHits | Select-Object -Unique) -join ', '
Write-Output (" [H15 B(b) VALUE-PROTECT] move-set has high-value marker(s): $uniqHits -> KEEP in L1 regardless of age (do NOT age-archive); em-main decides")
Write-Output ("{0,-24} {1,9} {2,5} {3,10} {4,7} {5,12} {6}" -f $sub, $bytes, 'YES', $logCount, $cur, "~$afterEst", $resolve)
# D3 value-gate: protected entries are EXCLUDED from the move-set (hard-skip), not merely flagged.
$protCount = 0
for ($k = 0; $k -lt $logCount; $k++) { if ($entProt[$k]) { $protCount++ } }
if ($protCount -gt 0) {
Write-Output (" [D3 value-gate] $protCount value-protected logical entr(y/ies) HARD-SKIPPED from the drain set (kept regardless of position/age); move-set = lowest-value only. NOTE: 9-token grep = lower-bound; em-main must value-scan the WHOLE proposed set (paraphrase/spine leak remains).")
}
}