9.1 KiB
9.1 KiB
PLAN — memory-sh-residuals (phase 4a leftovers + BUGS-FOUND memory.sh items, block H2) r1
Scope: lib/memory.sh, lib/tests/memory.test.sh, lib/reconcile.sh (:117 one call).
- (a)
memory_legacy_status <file> <ID> [<end>] [<re>]: 4th positional replaces${MEM_LEGACY_RE:-…};RE="${4:-$_MEM_LEGACY_RE}". reconcile.sh:117 passes"$RECONCILE_BDR_RE"as $4 and drops the env assignment. No other setter exists (grep). Comment "callers may widen the selector" updated. - (b) one range reader: the default (no ) path becomes the awk path with
END_RE='^##* *BLK-[0-9]'(any heading level of another BLK ends the range; a same-ID###sub-heading continues it, unread, as today in the form). Both forms also stop at ANY level-2 heading that is not the entry itself (!fence && /^## / && on && $0 !~ "^## " id " "→ on=0): a trailing## Indexor section is never read (BUGS-FOUND :38). The sed/grep path andMEM_GREPuse in this function go away; reconcile.sh:97 keeps calling without (behaviour: a### BLK-entry no longer leaks into the##entry above, BUGS-FOUND :22). - (c) stderr echoes of a v1 line (
_mem_repair_one:726-731, and any other${v1:0:100}site) go through_mem_printable <text>=printf '%s' "${1//[![:print:]]/?}"(locale-safe: run under the script's existing locale; tabs become?too, accepted). One helper, ≤ 5 lines. - (d)
_mem_journal_locked: on rc 1, prepend\nonly when the file is non-empty and its last line is not blank:[ -s "$1" ] && [ -n "$(tail -c1 "$1")" ] || sep=''is wrong (a trailing newline is normal); usetail -n1 "$1"non-empty →sep=$'\n', elsesep='';printf '%s## %s\n%s\n' "$sep" "$2" "$3" >> "$1". - (e)
_mem_upgrade_textflush: whenst[cur] == ""and the entry body holds a v1 status label line (_mem_v1_wordofmemory_legacy_status <old> <ID> <end for the prefix>gives a word), treat that word asstsomem_wantkeeps the body and prints "kept body , dropped Index " (BDR-129: Index never wins over a body label). Implementation: the rows file passed as ARGV[1] gains a 4th column = v1 body word per ID (computed in the caller loop over_mem_heading_ids), read asv1w[r[1]] = r[4]; flush usesst[cur] != "" ? st[cur] : v1w[cur]. If memory.sh's existing structure makes this > 25 logic lines, split a helper_mem_v1_words <old> <PREFIX>printingID<TAB>word. - (f) lib/tests/memory.test.sh: new cases (labels after the last existing T-label):
### BLK-after## BLK-on a v1 file → the##entry stays open (legacy status not leaked); v1 decisions file with a trailing## Indexafter the last BDR →memory_legacy_status … '^##* *BDR-[0-9]'returns nothing from the Index;MEM_LEGACY_RE=openexported in the test env does NOT change the result; control chars (\x1b[31m) in a v1 line → stderr shows?not the raw byte; journal on a file ending with a blank line → exactly one blank line before the new heading; upgrade fixture: Index cellresolved, body**Statut** : open→ body kept, stderr "kept body open, dropped Index resolved", no(…, upgrade)line written; upgrade fixture whose v1 line isStatus: resolvedwith strict reader open → stderr "wrote upgrade status resolved" and the dated line present; fixture with a dated- **Status (2026-…)**:line → stderr "dated status line kept". - Not done, justified: the real-data replay oracle (
up4a/realdata.sh, session scratchpad) is gone; the fixture suite above replaces it (TODO line removal says so). - Disposition: honors BDR-129 (one status parser, Index never a status source), BDR-125 phase 4a;
make testruns memory.test.sh (bun needed for T18 only).
r2 (correctness FATAL(4), robustness CONCERNS(3), simplicity FATAL(3); all folded) — r2 WINS over r1
- (a) signature
memory_legacy_status <file> <ID> [<re>]:<end>DERIVED inside ="^##* *${2%%-*}-[0-9]"; 3rd positional = label selector, default$_MEM_LEGACY_RE; new_MEM_LEGACY_BDR_RE="$_MEM_LEGACY_RE|statut|superseded|deprecated"hosted in memory.sh (reconcile.sh:55 reuses it). Callers: memory.sh :669/:685/:722 drop the literal end; reconcile.sh:97 →memory_legacy_status "$1" "$2", :117-118 →memory_legacy_status "$1" "$2" "$_MEM_LEGACY_BDR_RE"; bothMEM_GREP="$RECONCILE_GREP"prefixes deleted (dead). No env read. - (b) ONE awk reader (sed path gone), fence-aware (named change: a fenced
## BLK-no longer ends a range; v1 registries on disk hold no fence, 0 diffs measured by the robustness lens). Range ends at the next^##* *<PREFIX>-[0-9]heading of another ID (a same-ID###sub-heading continues, unread) OR at$0 == "## Index"(BUGS-FOUND :38) — NOT at every##heading (an in-entry## Updatesection must stay readable by the lexical reader so the oracle still sees its disagreement with the strict one). Rule placed after the same-IDnextrule. - (c) in place, no helper:
_mem_repair_oneafterword=$(_mem_v1_word "$v1"):v1=${v1//[![:print:]]/?}; awk side :612-613gsub(/[[:cntrl:]]/, "?", col[cur]). Accepted and stated in a comment: under a C locale UTF-8 bytes print as?. Remaining raw sinks (reconcile.sh:141 stdout, check "heading shape") listed in the TODO removal note, not fixed here. - (d)
_mem_journal_locked:sep=$'\n';[ -s "$1" ] || sep='';[ -z "$(tail -c1 "$1")" ] || sep=$'\n\n'(no final newline → terminate + blank);[ -z "$(tail -n1 "$1")" ] && sep=''(already blank-ended). Thenprintf '%s## %s\n%s\n' "$sep" "$2" "$3" >> "$1". - (e) ONE effective status, three consumers. New
_mem_v1_words <old> <PREFIX>→ID<TAB>word|mixedfor every ID with an Index cell whose strict word is "" : word =_mem_v1_wordofmemory_legacy_status <old> <ID> <re>(re =_MEM_LEGACY_BDR_REfor BDR, default for BLK; LRN/EVAL: none), label accepted only anchored (^(- )?(\*\*)?[Ss]tatu[st]or after·/|),mixedwhen a label line exists but_mem_v1_wordgives nothing. Fed as an extra ARGV input to_mem_upgrade_text,_mem_index_statedand_mem_upgrade_oracle: effectivest = strict != "" ? strict : v1w. Flush: strict "" + v1w word → WRITE- **Status (<today>, upgrade)**: <v1w>(the body label made readable) and, when the Index word differs, stderr "kept body , dropped Index ";mixed→ not Index-stated, falls to the existing name-and-refuse path. Index-stated = IDs wheremem_want(p, col, effective st) != "". Oraclewant=mem_word(mem_want(p, col, effective st)), else effective st. - (f) tests (memory.test.sh): T15-probed gains an
opensetcheck (###leak); new v1 decisions fixture with a trailing## Index→ nothing read from it; control chars viarefused()fixture →?on stderr; T14l extended to three journal endings (none,\n,\n\n→ exactly one blank line before the heading); upgrade fixtures: BLK Indexopen+ body- **Statut** : resolved→ rc 0, strict word resolved, stderr "kept body resolved, dropped Index open"; BLK Indexresolved+ body- **Statut** : resolved→ stays resolved; BDR Indexaccepted+ body**Statut** : proposed→ rc 0, strict proposed; BLK Indexopen+ mixed- **Statut** : resolved (x), open (y)→ refused, named (as T15-mixed-statut-refused); "wrote upgrade status" / "dated status line kept" asserted by capturing stderr of T15-statut / T15-datestatus / T15-remedy-roundtrip (not new fixtures; the r1Status: resolvedwording is a strict candidate and cannot fire). T15-reconcile-grep repointed atreconcile_blk_open(its enumerator still greps). Fixtures use- **Statut** :/date: … · status:dialects. - CHANGELOG (doc sync): Removed line for the
MEM_LEGACY_REenv override advertised in 3.0.0; Fixed line for the rest.
r3 (confirmation CONCERNS(2), folded; FINAL, no further challenge)
- (e) flush ORDER kept:
s = mem_want(p, col, est)first (est = strict != "" ? strict : v1w, wheremixedcounts as ""); non-empty s → write s (superseded/deprecated Index still wins, as today). Only when s == "" AND strict == "" AND v1w is a word → write- **Status (<today>, upgrade)**: <v1w>(+ stderr "kept body , dropped Index " when the Index word differs).mixed= "" for flush and oracle (today's Index path); it is EXCLUDED from Index-stated only, so a BLK mixed case reaches the verdict-diff refusal and a BDR mixed case keeps the Index word with rc 0. _mem_v1_words "$1" "$2"reads the ORIGINAL file for all three consumers (build included;$srchas rewritten###headings).memory_legacy_statusroutes$1through_mem_path_safe(awk operand-assignment class, T19).- Every flush print of
col[cur]appliesgsub(/[[:cntrl:]]/, "?", …)(mawk-safe). - Named behaviour changes of (b) for reconcile's v1 BLK path: fence-aware; a same-ID
### BLK-x UPDATE … RESOLVEDheading line is no longer itself a status candidate (0 on disk). BUGS-FOUND :38 marked PARTIALLY fixed: a trailing non-Index##section is still read (kept so## Updatestays readable). - Extra fixtures: BDR Index
superseded by BDR-004+ body**Statut** : accepted→ rc 0, strict superseded; BDR mixed label + Indexaccepted→ rc 0, strict accepted; BLK unknown word- **Status**: closed+ Indexresolved→ strict resolved kept.