diff --git a/.claude/memory/journal.md b/.claude/memory/journal.md index f74c712..3955f48 100644 --- a/.claude/memory/journal.md +++ b/.claude/memory/journal.md @@ -737,3 +737,4 @@ rules: - /feat design-hook-removal (block E1): hooks/design-toolchain-reminder.sh + test + UserPromptSubmit entry deleted (9c038fd), T7c → T8i synthetic fixture, docs 19ec5b7 (CHANGELOG Removed wording = doc-syncer draft, user asked no mid-run questions). BDR-148. Gates 0 MET / 1 four oracles MET / 2 PASS, make test all green. Open sessions log one non-blocking hook error per prompt until restart. - /feat skill-routing-descriptions (block E2): CLAUDE.global.md § Skill routing 311 → 306 lines, 6 lines dropped into bugfix/ship-feature descriptions (3b30153, docs 88b67ab). Feater died mid-run (API 403 Cloudflare) after the 3 edits: gates proved the diff, no re-dispatch. Verifier caught a contract ledger bug: 1b. row absorbed by gates.sh → LRN-284, row renumbered 6. BDR-149. - /bugfix cc-oom-score-adj (block G): BLK-044 root cause = sshd drop-in OOMScoreAdjust=-1000 inherited; lib/cc.sh raises oom_score_adj to 500 raise-only (6c10d3a, T7-oom, docs f5ce4ae). Gates 0 MET / 1 two rounds (80-col + redirect order) / 2 PASS, make test green. Live proof needs a fresh cc session (user). LRN-285. +- /bugfix project-rules-residuals (block H1, phase 0 leftovers): emit via _rules_out_path_ok + write guard, extract keeps tmp+out on rewrite failure, physical parent check (9d5530a, T9h + T9z3-z13, docs cd90080). 3 lenses: BLOCKER silent refusal on a file parent (T9w2), MAJOR section's last copy deleted by r1; callers onboarder/scaffolder stop on rc 2 ≠ exists. LRN-286. diff --git a/.claude/memory/learnings.md b/.claude/memory/learnings.md index 6611273..4ada86e 100644 --- a/.claude/memory/learnings.md +++ b/.claude/memory/learnings.md @@ -2077,3 +2077,8 @@ Rule: when editing a doctrine file under structure locks, grep the test's lock s - **Context**: BLK-044 (block G 2026-11-13): claude via `cc` at oom_score_adj -1000, origin "unknown" for weeks. - **Pattern**: oom_score_adj is inherited across fork/exec; a service-level `OOMScoreAdjust=` (here sshd's drop-in `/etc/systemd/system/ssh.service.d/override.conf`) leaks into every interactive descendant (tmux server → shell → dtach → claude). Trace = walk `/proc//oom_score_adj` up the parent chain, then `systemctl cat` the first unit. `systemd-run --scope -p OOMScoreAdjust=…` fails ("Unknown assignment": scopes take no exec-context properties). Raising one's own value needs no privilege; lowering does. - **Apply**: a per-session fix = write `/proc/self/oom_score_adj` in the shell that `exec`s the target (raise-only guard `-lt N`, stderr silenced BEFORE the `>` open so a failed open stays quiet). Proof = `/proc//oom_score_adj` of a fresh session; a running session never reflects the fix. `choom -n N -- cmd` (util-linux) is the equivalent binary. + +## LRN-286 — Physical under-the-project path check in bash: walk -d ancestors, CDPATH='' cd -P, pwd -P both sides; a post-truncation failure keeps every copy (2026-11-13) +- **Context**: lib/project-rules.sh `_rules_out_path_ok` (phase 0 leftover, block H1 2026-11-13), 3 challengers + 1 confirmation. +- **Pattern**: a "stays under the project" check for a path that may not exist yet = walk `dirname` up while `[ ! -d ]` (skip file/dangling-link ancestors so `mkdir -p` keeps naming them), then `CDPATH='' cd -P -- "./$parent" && pwd -P` vs `pwd -P` (never `$PWD`: `-C` does a logical cd); prefix pattern `"${here%/}"|"${here%/}"/*`. `CDPATH= cd` trips shellcheck SC1007; `cd -P` of a relative name consults CDPATH and prints the dir. +- **Apply**: a failure branch after an O_TRUNC write must keep every copy and name them (the "keep $tmp" ask alone would drop the only copy of the moved section); a caller mapping "rc 2 = exists" must learn the new rc-2 causes in the same change; a `1b.`-style test idea often duplicates an existing case: check labels before adding. diff --git a/.claude/tasks/TODO.md b/.claude/tasks/TODO.md index 1eb7b37..c12cc78 100644 --- a/.claude/tasks/TODO.md +++ b/.claude/tasks/TODO.md @@ -52,10 +52,7 @@ Shared rules for every phase: ### BDR-125 residuals (after 3.0.0) Open children of the shipped phases (History 2026-11-12), text verbatim. -- Phase 0 / 0b leftovers (extract-hardening 14a93e3, lib/project-rules.sh): - - [ ] `emit`: reuse `_rules_out_path_ok` (today `-e` only, a dangling link at the target is followed) and check the `mkdir -p` and `> "$2"` rc (today "emitted" rc 0 on a failed write). - - [ ] `extract` rewrite failure mid-`cat` (ENOSPC/EIO after the truncation of `$src`): keep `$tmp` and name it on stderr instead of `rm -f` (today "$src not rewritten" can be false, the two copies gone; onboarder S1 rollback covers the split path, not direct lib use). - - [ ] shortcut `_rules_out_path_ok`: the `..` check is lexical, a symlinked parent component (`.claude` or `.claude/rules` pointing elsewhere) is not resolved; upgrade = `cd -P` on the parent dir, compare with `$PWD` (no portable `realpath -m`). +- Phase 0 / 0b leftovers: done 2026-11-13 (block H1, bugfix/project-rules-residuals 9d5530a, LRN-286): emit via `_rules_out_path_ok` + mkdir/write rc, extract keeps `$tmp` and `$out` on a rewrite failure, physical parent check (`cd -P`, `pwd -P`). - Phase 4a leftovers: - [ ] faunosteo: NOT upgraded (V1-2 active in another session's worktree; user: no write to develop or the V1-2 worktree). Patch prepared off-repo from V1-2 587cbb2 (rc 0, 520 lines, open BLK-008/009 unchanged); at integration re-run `memory.sh -C upgrade` on the branch the user names rather than applying the stale patch. Stale clone `/home/bchanot/faunosteo` (main, 2026-07-01): left alone, user to decide. - [ ] BLK-038 residuals (gates 2026-10-30, non-blocking): v1 line echoed on stderr unfiltered (CWE-150 LOW, terminal control chars from a foreign registry; same as existing "upgrade lost" path); no fixture asserts the "wrote upgrade status" / "dated status line kept" messages; the real-data replay oracle lives in the session scratchpad (`up4a/realdata.sh`), not re-runnable: port to a `make` target over fixture copies if the upgrade is touched again; `memory.sh journal` leaves two blank lines before a new date heading on files ending with a blank line (commit-changer note). diff --git a/.claude/tasks/contracts/2026-11-13-project-rules-residuals-1300.md b/.claude/tasks/contracts/2026-11-13-project-rules-residuals-1300.md new file mode 100644 index 0000000..1dca8fc --- /dev/null +++ b/.claude/tasks/contracts/2026-11-13-project-rules-residuals-1300.md @@ -0,0 +1,40 @@ +# CONTRACT — project-rules-residuals (phase 0 leftovers, block H1) +- date: 2026-11-13 | flow: bugfix | branch: bugfix/project-rules-residuals (off develop) +- status: active + +## REQUEST (verbatim — IMMUTABLE) +Phase 0 / 0b leftovers (extract-hardening 14a93e3, lib/project-rules.sh): `emit`: reuse `_rules_out_path_ok` (today `-e` only, a dangling link at the target is followed) and check the `mkdir -p` and `> "$2"` rc (today "emitted" rc 0 on a failed write). `extract` rewrite failure mid-`cat` (ENOSPC/EIO after the truncation of `$src`): keep `$tmp` and name it on stderr instead of `rm -f` (today "$src not rewritten" can be false, the two copies gone; onboarder S1 rollback covers the split path, not direct lib use). shortcut `_rules_out_path_ok`: the `..` check is lexical, a symlinked parent component (`.claude` or `.claude/rules` pointing elsewhere) is not resolved; upgrade = `cd -P` on the parent dir, compare with `$PWD` (no portable `realpath -m`). + +## CLARIFICATIONS +- [gated 2026-11-13, challenge r2] the cat-failure branch keeps BOTH `$tmp` and `$out` (the request's "keep $tmp" alone would drop the section's last copy); callers onboarder.md:144 / scaffolder.md:86-89 read an rc 2 not ending in ` exists` as STOP. Compare with `pwd -P` on both sides (the request's `$PWD` is logical under `-C`). Plan: .claude/tasks/plans/2026-11-13-project-rules-residuals-1300.md § r2. + +## ACCEPTANCE CRITERIA +1. Physical parent check present; `$PWD` never used; CDPATH neutralized. + CHECK: cd /home/bchanot/Documents/claude && echo $(grep -c "CDPATH='' cd -P" lib/project-rules.sh)$(grep -c '\$PWD' lib/project-rules.sh)$(grep -c 'must stay under the project' lib/project-rules.sh) + EXPECT: 101 + EVIDENCE: MET exit=0 marker-found :: 101 +2. emit routes through `_rules_out_path_ok` and checks the write; extract's cat-failure branch keeps both files. + CHECK: cd /home/bchanot/Documents/claude && echo $(grep -c '_rules_out_path_ok' lib/project-rules.sh)$(grep -c 'not written' lib/project-rules.sh)$(grep -c 'rewrite failed' lib/project-rules.sh) + EXPECT: 321 + EVIDENCE: MET exit=0 marker-found :: 321 +3. Suite green with the new cases (escape refused for extract and emit, `-C ` accepted, emit write failure named, T9h re-asserted). + CHECK: cd /home/bchanot/Documents/claude && bash lib/tests/project-rules.test.sh 2>&1 | tail -1 + EXPECT: FAIL=0 + EVIDENCE: MET exit=0 marker-found :: PASS=153 FAIL=0 +4. New cases exist. + CHECK: cd /home/bchanot/Documents/claude && grep -c 'must stay under the project\|link-esc\|cannot create' lib/tests/project-rules.test.sh | grep -c '^[3-9]' + EXPECT: 1 + EVIDENCE: MET exit=0 marker-found :: 1 +5. Callers patched. + CHECK: cd /home/bchanot/Documents/claude && grep -c 'any other rc 2 → STOP' agents/onboarder.md agents/scaffolder.md | grep -c ':1$' + EXPECT: 2 + EVIDENCE: MET exit=0 marker-found :: 2 +6. shellcheck -x clean on lib/project-rules.sh and lib/tests/project-rules.test.sh; new/changed lines ≤ 80 cols; `_rules_out_path_ok` ≤ 25 logic lines. + CHECK: cd /home/bchanot/Documents/claude && shellcheck -x lib/project-rules.sh lib/tests/project-rules.test.sh && echo SC-OK + EXPECT: SC-OK + EVIDENCE: MET exit=0 marker-found :: SC-OK +7. make test green (manual, bun on PATH). + (manual: run 2026-11-13 on the bugfixer diff, `PATH=$HOME/.bun/bin:$PATH make test` → "SUITE: all GREEN / all suites green", rc=0) + +## FILE SCOPE +lib/project-rules.sh, lib/tests/project-rules.test.sh, agents/onboarder.md (:144 one line), agents/scaffolder.md (:86-89 one line). TODO phase 0 lines → STEP 8. diff --git a/.claude/tasks/plans/2026-11-13-project-rules-residuals-1300.md b/.claude/tasks/plans/2026-11-13-project-rules-residuals-1300.md new file mode 100644 index 0000000..5580c41 --- /dev/null +++ b/.claude/tasks/plans/2026-11-13-project-rules-residuals-1300.md @@ -0,0 +1,26 @@ +# PLAN — project-rules-residuals (phase 0 leftovers, block H1) r1 +Scope: lib/project-rules.sh (:189-241), lib/tests/project-rules.test.sh. +- `_rules_out_path_ok ` (:189): keep the lexical cases; then `parent=$(dirname "$out")`; walk up (`while [ ! -e "$parent" ]; do parent=$(dirname "$parent"); done`, stops at `.`); `phys=$(cd -P "$parent" 2>/dev/null && pwd -P) || return 2`; `case "$phys" in "$PWD"|"$PWD"/*) ;; *) echo "project-rules: out must stay under the project: $out" >&2; return 2;; esac`. `$PWD` is the physical cwd? No: use `here=$(pwd -P)` for both sides. Drop the `shortcut:` comment (shortcut upgraded). +- `project_rules_emit` (:228): replace `[ -e "$2" ] && …` with `_rules_out_path_ok "$2" || return 2`; `mkdir -p "$(dirname "$2")" || { echo "project-rules: cannot create $(dirname "$2")" >&2; return 2; }`; the brace group `> "$2" || { rm -f "$2"; echo "project-rules: $2 not written" >&2; return 2; }`. +- `project_rules_extract` (:217-223): two steps. `_rules_without_section "$src" "$hline" > "$tmp" || { rm -f "$tmp" "$out"; echo "project-rules: $src untouched, $out removed" >&2; return 2; }` then `cat "$tmp" > "$src" || { rm -f "$out"; echo "project-rules: $src may be truncated, full copy kept at $tmp; $out removed" >&2; return 2; }`. Success path unchanged (`rm -f "$tmp"`, "moved" line). +- Tests (follow T7-T9 idiom, sandbox cwd): T10 `.claude/rules` → symlink to a dir outside the sandbox: extract and emit both rc 2 with "must stay under the project"; the link's target untouched. T11 emit onto a dangling symlink → rc 2 "exists". T12 emit with `dirname "$2"` = an existing regular file → rc 2 "cannot create", no output file. T13 extract on a read-only `$src` (chmod 444; skip with a SKIP line when running as root): rc 2, stderr names a path that exists and holds the rewritten text, `$src` byte-identical, `$out` absent; test removes that tmp. +- Limits: `_rules_out_path_ok` stays ≤ 25 logic lines (walk-up loop + case); if not, a helper `_rules_phys_parent ` prints the physical first-existing ancestor. +- Disposition: honors BDR-125 phase 0 (extract-hardening 14a93e3 scope), the "shortcut → TODO" rule (the lexical shortcut upgraded, comment dropped). + +## r2 (correctness FATAL(2), robustness CONCERNS(3), simplicity CONCERNS(3); all folded) — r2 WINS over r1 where they differ +- `_rules_out_path_ok ` FINAL body: lexical cases kept; the `[ -e ] || [ -L ]` "exists" block KEPT (last-component symlink); then + `here=$(pwd -P) && [ -n "$here" ] || { echo "project-rules: cannot resolve cwd" >&2; return 2; }`; + `parent=$(dirname "$out"); while [ ! -d "$parent" ]; do parent=$(dirname "$parent"); done` (a regular-file or dangling-link ancestor is skipped so mkdir keeps naming "cannot create"; ends at `.`); + `phys=$(CDPATH= cd -P -- "./$parent" 2>/dev/null && pwd -P) || { echo "project-rules: cannot resolve $parent" >&2; return 2; }`; + `case "$phys" in "$here"|"$here"/*) ;; *) echo "project-rules: out must stay under the project: $out" >&2; return 2;; esac`. Never `$PWD`. Drop the `shortcut:` comment. +- New helper `_rules_mkdir_parent ` = `mkdir -p "$(dirname "$1")" 2>/dev/null || { echo "project-rules: cannot create $(dirname "$1")" >&2; return 2; }`, used by extract (:210-211 replaced) and emit (one copy of the message). +- emit: `_rules_out_path_ok "$2" || return 2` replaces the `-e` test; `_rules_mkdir_parent "$2" || return 2`; the brace group `> "$2" || { rm -f "$2"; echo "project-rules: $2 not written" >&2; return 2; }`. +- extract step 2 (cat failure): REMOVE NOTHING. `echo "project-rules: $src rewrite failed: rewritten text at $tmp, section at $out (restore $src from git, or cat $tmp > $src to complete)" >&2; return 2`. Step 1 (`_rules_without_section` failure) unchanged: rm tmp + out, "$src untouched, $out removed". +- Callers (scope +2): agents/onboarder.md:144 and agents/scaffolder.md:86-89 → "rc 2 whose stderr line ends with ` exists` → keep the file; any other rc 2 → STOP, relay the lib's line". +- Tests (labels = suffixes after the LAST existing T9*/T12* label, never T10-T13): T9 escape: project at `$FIX/p-esc` (cwd), `.claude/rules` → symlink to `$FIX/out-esc`: extract rc 2 + "must stay under the project", emit (T12's skeleton + matching fixture, copied) rc 2 same line, `$FIX/out-esc` empty. T9 positive: emit via `-C "$FIX/link-esc"` (symlink to a sandbox project) rc 0. T12 write failure: emit with `dirname "$2"` = existing regular file → rc 2 + "cannot create", no file. T9h (read-only src) RE-ASSERTED to the new semantics: run with `TMPDIR="$FIX/tmp"`; rc 2; stderr names a path under `$FIX/tmp` that exists and holds the rewritten text; `$out` present; `$src` byte-identical. No new root SKIP (existing chmod tests fail as root today; out of scope, noted). + +## r3 (confirmation CONCERNS(3), folded; FINAL, no further challenge) +- `_rules_out_path_ok`: `local out="$1" here parent phys`; `CDPATH='' cd -P -- "./$parent"` (SC1007-clean, repo form lib/gstack-links.sh:68); case pattern `"${here%/}"|"${here%/}"/*`; header comment :189 → "rc 2 when absolute, has a .. part, exists, or resolves outside cwd". +- Step-2 message: `project-rules: $src rewrite failed: rewritten text at $tmp, section at $out. Complete with: cat $tmp > $src; or abort: rm $out when $src is intact` (no git hint). +- onboarder.md S1 rollback (:251-255) gains one clause: a row that failed at the rewrite step leaves `.claude/rules/.md` and a tmp named on stderr: delete both too (scope: still agents/onboarder.md). +- Tests: T9h re-assertion runs with `mkdir -p "$FIX/tmp"` first and ends with `rm -f .claude/rules/beta.md "$FIX"/tmp/tmp.*` (T9x2-x4 unchanged). New emit write-failure case: emit onto `.claude/rules/x.md/` (trailing slash: passes the exists check, open fails ENOTDIR) → rc 2, stderr `not written`, `[ -e .claude/rules/x.md ]` = no (this exercises the `> "$2"` guard; the regular-file-parent case keeps proving "cannot create").