style(lib): reflow reconcile.sh and memory-commit.sh under 80 bytes

Comment reflow and line breaks only; `declare -f` output identical
except two hand-reviewed string splits with identical output. Also
refreshes two stale reconcile.sh comments (status source on v1 vs v2,
`## ID` headings only).
This commit is contained in:
bchanot committed 2026-11-01 11:39:58 +01:00
1 parent e4fb8f7670
commit 48ade8f405
2 files changed
+80 -48

No files matched your search

+15 -11
View File
@@ -12,8 +12,9 @@
# # 5 commit rejected, 6 check refused # # 5 commit rejected, 6 check refused
# #
# Output contract for `commit`: diagnostics go to stderr; on a real commit the # Output contract for `commit`: diagnostics go to stderr; on a real commit the
# short hash of the MEMORY commit is the ONLY thing on stdout (empty on no-op or # short hash of the MEMORY commit is the ONLY thing on stdout (empty on no-op
# unsafe), so callers can capture it: `mem_hash=$(memory-commit.sh commit "msg")`. # or unsafe), so callers can capture it:
# `mem_hash=$(memory-commit.sh commit "msg")`.
# #
# Sourceable: `commit_memory`. # Sourceable: `commit_memory`.
@@ -64,7 +65,8 @@ _partial_stages() {
} }
# Surgical commit of the scoped paths only. Returns 0 (ok or no-op), 3 (unsafe). # Surgical commit of the scoped paths only. Returns 0 (ok or no-op), 3 (unsafe).
# On a real commit, prints the memory-commit short hash to stdout (stderr = diag). # On a real commit, prints the memory-commit short hash to stdout (stderr =
# diag).
commit_memory() { commit_memory() {
local msg="${1:?commit message required}" local msg="${1:?commit message required}"
_in_git_repo || { _in_git_repo || {
@@ -72,7 +74,8 @@ commit_memory() {
return 3 return 3
} }
if _unsafe_state; then if _unsafe_state; then
echo "memory-commit: detached HEAD or merge/rebase in progress — skip (no commit)" >&2 echo "memory-commit: detached HEAD or merge/rebase in progress —" \
"skip (no commit)" >&2
return 3 return 3
fi fi
local changed partial local changed partial
@@ -81,9 +84,9 @@ commit_memory() {
echo "memory-commit: nothing pending — no-op" >&2 echo "memory-commit: nothing pending — no-op" >&2
return 0 return 0
fi fi
# Re-stage working-tree content of the scoped paths over any stale index entry, # Re-stage working-tree content of the scoped paths over any stale index
# then commit ONLY those paths. The pathspec on `git commit` makes it a partial # entry, then commit ONLY those paths. The pathspec on `git commit` makes
# commit: other staged files (dangling code) are not recorded. # it a partial commit: other staged files (dangling code) are not recorded.
partial="$(_partial_stages "${changed[@]}")" partial="$(_partial_stages "${changed[@]}")"
git add -- "${changed[@]}" git add -- "${changed[@]}"
# Chokepoint (BDR-125 phase 4a): a staged v2 registry may only grow and # Chokepoint (BDR-125 phase 4a): a staged v2 registry may only grow and
@@ -105,10 +108,11 @@ commit_memory() {
# Contract: diagnostics go to stderr; on success ONLY the memory-commit short # Contract: diagnostics go to stderr; on success ONLY the memory-commit short
# hash goes to stdout, so a caller can do `mem_hash=$(... commit "msg")`. # hash goes to stdout, so a caller can do `mem_hash=$(... commit "msg")`.
# FAIL-LOUD on the commit itself. With `set -uo pipefail` (no -e), a rejected # FAIL-LOUD on the commit itself. With `set -uo pipefail` (no -e), a rejected
# commit (pre-commit hook on a protected branch, signing failure, …) would NOT # commit (pre-commit hook on a protected branch, signing failure, …) would
# abort: the line below would falsely claim "committed" and rev-parse would # NOT abort: the line below would falsely claim "committed" and rev-parse
# emit the PREVIOUS HEAD's hash with exit 0 — a silent masked failure. Reject # would emit the PREVIOUS HEAD's hash with exit 0 — a silent masked
# → loud, NO hash on stdout, exit 5 (mirrors doc-commit.sh's rc 5). # failure. Reject → loud, NO hash on stdout, exit 5 (mirrors doc-commit.sh's
# rc 5).
if ! git commit -q -m "$msg" -- "${changed[@]}"; then if ! git commit -q -m "$msg" -- "${changed[@]}"; then
{ {
echo "memory-commit: COMMIT REJECTED — git commit exited non-zero" \ echo "memory-commit: COMMIT REJECTED — git commit exited non-zero" \
+65 -37
View File
@@ -1,63 +1,83 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# reconcile.sh — deterministic engine for /reconcile. # reconcile.sh — deterministic engine for /reconcile.
# #
# Confronts DECLARATIVE sources (TODO checkboxes, registry statuses) against REAL # Confronts DECLARATIVE sources (TODO checkboxes, registry statuses) against
# state (git, fs, registry BODY). It is the engine behind the /reconcile skill; # REAL state (git, fs, registry BODY). It is the engine behind the /reconcile
# the skill orchestrates + gates, this file holds the mechanical truth-probes. # skill; the skill orchestrates + gates, this file holds the mechanical
# truth-probes.
# #
# FOUNDING PRINCIPLE — recursive coherence (LRN-055): a reconciler must NEVER trust # FOUNDING PRINCIPLE — recursive coherence (LRN-055): a reconciler must NEVER
# a declarative source as an oracle. So this engine NEVER reads the `## Index` table # trust a declarative source as an oracle. So this engine NEVER reads the
# nor believes a `[x]`/`[ ]` checkbox; it enumerates registry entries from the BODY # `## Index` table nor believes a `[x]`/`[ ]` checkbox; it enumerates registry
# `## ID —` headings and decides "done/stale" from git/fs only. It practices what it # entries from the BODY `## ID —` headings and decides "done/stale" from
# preaches — the recursive-coherence test (run-reconcile.sh T1) reds if this is broken. # git/fs only. It practices what it preaches — the recursive-coherence test
# (run-reconcile.sh T1) reds if this is broken.
# v2 registries carry no Index at all (lib/memory.sh); v1 ones still may. # v2 registries carry no Index at all (lib/memory.sh); v1 ones still may.
# #
# HONEST LIMITS (graven, do not over-read): # HONEST LIMITS (graven, do not over-read):
# - Deferral detection is LEXICAL (reconcile_deferrals): it catches deferrals MARKED # - Deferral detection is LEXICAL (reconcile_deferrals): it catches
# by a keyword, misses ones phrased without one ("à reprendre quand X"). Deterministic # deferrals MARKED by a keyword, misses ones phrased without one ("à
# on the detectable; the skill SURFACES the ambiguous for human review, never asserts. # reprendre quand X"). Deterministic on the detectable; the skill
# - Contradiction detection surfaces CANDIDATES (token overlap), never asserts a verdict. # SURFACES the ambiguous for human review, never asserts.
# - Contradiction detection surfaces CANDIDATES (token overlap), never
# asserts a verdict.
# #
# Layers: # Layers:
# reconcile_enumerate_ids — body-only ID enumeration (recursive-coherence core) # reconcile_enumerate_ids — body-only `## ID` heading enumeration
# reconcile_oracle_* — live git/fs truth probes # (recursive-coherence core); v1 `###` entries
# reconcile_blk_current_status — registry status, LAST block wins (compound/UPDATE/FINAL) # are invisible to it
# reconcile_blk_open — blockers whose CURRENT status is not resolved # reconcile_oracle_* — live git/fs truth probes
# reconcile_verdict — pure kernel: declared checkbox × real fact → verdict # reconcile_blk_current_status — registry status: lib/memory.sh shared
# reconcile_deferrals — lexical deferral sweep (honest limit) # parser on v2, legacy lexical reader on v1
# reconcile_contradiction_candidates — accepted-BDR ⇄ open-chantier token overlap (surface) # reconcile_blk_open — blockers whose CURRENT status is not closed
# (resolved | superseded | deprecated on v2)
# reconcile_verdict — pure kernel: declared checkbox × real fact
# → verdict
# reconcile_deferrals — lexical deferral sweep (honest limit)
# reconcile_contradiction_candidates — accepted-BDR ⇄ open-chantier token
# overlap (surface)
set -uo pipefail set -uo pipefail
RECONCILE_GREP="${RECONCILE_GREP:-/usr/bin/grep}" # LRN-074: pin grep, never assume GNU flags # LRN-074: pin grep, never assume GNU flags
RECONCILE_GREP="${RECONCILE_GREP:-/usr/bin/grep}"
# the status parser and classifier are shared with lib/memory.sh (BDR-125 4a) # the status parser and classifier are shared with lib/memory.sh (BDR-125 4a)
# shellcheck source=/dev/null # shellcheck source=/dev/null
. "$(dirname "${BASH_SOURCE[0]}")/memory.sh" . "$(dirname "${BASH_SOURCE[0]}")/memory.sh"
# markers that LEXICALLY signal a deferral/follow-up (honest limit: marked-only) # markers that LEXICALLY signal a deferral/follow-up (honest limit: marked-only)
RECONCILE_DEFER_RE='[Dd]efer|[Ff]ollow-?up|[Oo]ut.of.scope|OUT-OF-SCOPE|[Rr]econsider|[Rr]evisit|2e passage|won.t.do|optional\)|one-line ticket' RECONCILE_DEFER_RE='[Dd]efer|[Ff]ollow-?up|[Oo]ut.of.scope|OUT-OF-SCOPE'
RECONCILE_DEFER_RE+='|[Rr]econsider|[Rr]evisit|2e passage|won.t.do'
RECONCILE_DEFER_RE+='|optional\)|one-line ticket'
# --- recursive coherence: enumerate IDs from the BODY, never the ## Index --- # --- recursive coherence: enumerate IDs from the BODY, never the ## Index ---
# $1 registry file, $2 prefix (BDR|LRN|BLK|EVAL). Emits one id per line, unique. # $1 registry file, $2 prefix (BDR|LRN|BLK|EVAL). Emits one id per line, unique.
reconcile_enumerate_ids() { reconcile_enumerate_ids() {
"$RECONCILE_GREP" -oE "^## ${2}-[0-9]+" "$1" | "$RECONCILE_GREP" -oE "${2}-[0-9]+" | sort -u "$RECONCILE_GREP" -oE "^## ${2}-[0-9]+" "$1" \
| "$RECONCILE_GREP" -oE "${2}-[0-9]+" | sort -u
} }
# --- live truth probes (query the REAL repo/fs; this is the "verify, don't believe" core) --- # --- live truth probes (query the REAL repo/fs; the "verify, don't believe"
# core) ---
reconcile_oracle_tree_clean() { # rc 0 = working tree clean reconcile_oracle_tree_clean() { # rc 0 = working tree clean
[ -z "$(git -C "${1:-.}" status --porcelain 2>/dev/null)" ] [ -z "$(git -C "${1:-.}" status --porcelain 2>/dev/null)" ]
} }
reconcile_oracle_merge_done() { # $1 repo, $2 branch fragment → rc 0 if a merge commit exists # $1 repo, $2 branch fragment → rc 0 if a merge commit exists
reconcile_oracle_merge_done() {
[ -n "$(git -C "${1:-.}" log --oneline --grep "Merge .*$2" -1 2>/dev/null)" ] [ -n "$(git -C "${1:-.}" log --oneline --grep "Merge .*$2" -1 2>/dev/null)" ]
} }
reconcile_oracle_pushed() { # $1 repo, $2 branch → rc 0 if nothing unpushed vs origin # $1 repo, $2 branch → rc 0 if nothing unpushed vs origin
reconcile_oracle_pushed() {
[ -z "$(git -C "${1:-.}" rev-list "origin/$2..$2" 2>/dev/null)" ] [ -z "$(git -C "${1:-.}" rev-list "origin/$2..$2" 2>/dev/null)" ]
} }
reconcile_oracle_sha_exists() { # $1 repo, $2 sha → rc 0 if the commit object exists # $1 repo, $2 sha → rc 0 if the commit object exists
reconcile_oracle_sha_exists() {
git -C "${1:-.}" cat-file -e "${2}^{commit}" 2>/dev/null git -C "${1:-.}" cat-file -e "${2}^{commit}" 2>/dev/null
} }
reconcile_oracle_msg_committed() { # $1 repo, $2 grep → rc 0 if a commit message matches # $1 repo, $2 grep → rc 0 if a commit message matches
reconcile_oracle_msg_committed() {
[ -n "$(git -C "${1:-.}" log --oneline --grep "$2" -1 2>/dev/null)" ] [ -n "$(git -C "${1:-.}" log --oneline --grep "$2" -1 2>/dev/null)" ]
} }
reconcile_oracle_path_present() { [ -e "${1:?}" ]; } # $1 path → rc 0 if it still exists on disk # $1 path → rc 0 if it still exists on disk
reconcile_oracle_path_present() { [ -e "${1:?}" ]; }
# --- registry status: LAST candidate wins (the BLK-008 trap A fell into) --- # --- registry status: LAST candidate wins (the BLK-008 trap A fell into) ---
# $1 blockers file, $2 id. A v2 registry (lib/memory.sh): the entry's own # $1 blockers file, $2 id. A v2 registry (lib/memory.sh): the entry's own
@@ -86,7 +106,8 @@ reconcile_blk_open() {
done done
} }
# --- pure reconciliation kernel: declared checkbox × real fact → verdict (no git, fully testable) --- # --- pure reconciliation kernel: declared checkbox × real fact → verdict
# (no git, fully testable) ---
# $1 checkbox char (x| |~), $2 real_done (true|false). # $1 checkbox char (x| |~), $2 real_done (true|false).
reconcile_verdict() { reconcile_verdict() {
case "$1:$2" in case "$1:$2" in
@@ -97,20 +118,27 @@ reconcile_verdict() {
esac esac
} }
# --- lexical deferral sweep (HONEST LIMIT: marked-only) → "src<TAB>line<TAB>text" --- # --- lexical deferral sweep (HONEST LIMIT: marked-only)
# → "src<TAB>line<TAB>text" ---
reconcile_deferrals() { reconcile_deferrals() {
[ -f "$1" ] && "$RECONCILE_GREP" -nE "$RECONCILE_DEFER_RE" "$1" 2>/dev/null | sed 's/^/TODO\t/' [ -f "$1" ] && "$RECONCILE_GREP" -nE "$RECONCILE_DEFER_RE" "$1" 2>/dev/null \
[ -f "$2" ] && "$RECONCILE_GREP" -nE "$RECONCILE_DEFER_RE" "$2" 2>/dev/null | sed 's/^/BDR\t/' | sed 's/^/TODO\t/'
[ -f "$2" ] && "$RECONCILE_GREP" -nE "$RECONCILE_DEFER_RE" "$2" 2>/dev/null \
| sed 's/^/BDR\t/'
return 0 return 0
} }
# --- contradiction CANDIDATES (surface, never assert): CLI-flag token shared by a BDR + the TODO --- # --- contradiction CANDIDATES (surface, never assert): CLI-flag token shared
# $1 decisions file, $2 todo file. CLI-flag-like tokens are distinctive enough to flag for review. # by a BDR + the TODO ---
# $1 decisions file, $2 todo file. CLI-flag-like tokens are distinctive enough
# to flag for review.
reconcile_contradiction_candidates() { reconcile_contradiction_candidates() {
local tok local tok why=' in a BDR title and an open TODO chantier'
for tok in $("$RECONCILE_GREP" -oE '\-\-[a-z][a-z-]+' "$1" 2>/dev/null | sort -u); do why+=' — review for contradiction'
for tok in $("$RECONCILE_GREP" -oE '\-\-[a-z][a-z-]+' "$1" 2>/dev/null \
| sort -u); do
"$RECONCILE_GREP" -qF -- "$tok" "$2" 2>/dev/null \ "$RECONCILE_GREP" -qF -- "$tok" "$2" 2>/dev/null \
&& printf 'CANDIDATE\t%s\tflag "%s" in a BDR title and an open TODO chantier — review for contradiction\n' "$tok" "$tok" && printf 'CANDIDATE\t%s\tflag "%s"%s\n' "$tok" "$tok" "$why"
done done
return 0 return 0
} }