fix: address v0.5.0 review findings

- Add --to/--test-cmd mutual exclusivity guard in rollback script
- Convert all jq string interpolation to --arg (cmd_extract, cmd_inject, cmd_forget)
- Fix CRITICAL/WARNING grep to match table rows only (not prose)
- Add thorough+cycle-1 guard to fast-path bash snippet in check-phase
- Clarify prev_run_id selection comment (tail -1 = most recent non-current)
This commit is contained in:
2026-04-04 08:44:06 +02:00
parent c3f5df8161
commit 362fb9ada9
3 changed files with 31 additions and 22 deletions

View File

@@ -141,14 +141,14 @@ cmd_extract() {
if [[ "$overlap" -ge 50 ]]; then
# Match found — update existing lesson
local tmp_file="${LESSONS_FILE}.tmp"
jq -c "
if .id == \"$lesson_id\" then
jq -c --arg lid "$lesson_id" --arg ts "$(now_ts)" --arg rid "$run_id" '
if .id == $lid then
.frequency += 1 |
.ts = \"$(now_ts)\" |
.last_seen_run = \"$run_id\" |
.ts = $ts |
.last_seen_run = $rid |
.runs_since_last_seen = 0
else . end
" "$LESSONS_FILE" > "$tmp_file"
' "$LESSONS_FILE" > "$tmp_file"
mv "$tmp_file" "$LESSONS_FILE"
matched=true
updated=$((updated + 1))
@@ -224,25 +224,25 @@ cmd_inject() {
# - Filter by domain (match or "general") and archetype (if provided)
# - Sort by frequency desc, cap at 10
local lessons
lessons=$(jq -c "
lessons=$(jq -c --arg domain "$domain" --arg archetype "$archetype" '
select(
(.type == \"preference\") or
(.type == "preference") or
(.frequency >= 5) or
(
(.frequency >= 2) and
(
(\"$domain\" == \"\") or
(.domain == \"$domain\") or
(.domain == \"general\")
($domain == "") or
(.domain == $domain) or
(.domain == "general")
) and
(
(\"$archetype\" == \"\") or
($archetype == "") or
(.archetype == null) or
(.archetype == \"$archetype\")
(.archetype == $archetype)
)
)
)
" "$LESSONS_FILE" 2>/dev/null | jq -sc 'sort_by(-.frequency) | .[:10][]' 2>/dev/null || true)
' "$LESSONS_FILE" 2>/dev/null | jq -sc 'sort_by(-.frequency) | .[:10][]' 2>/dev/null || true)
if [[ -z "$lessons" ]]; then
return 0
@@ -382,7 +382,9 @@ cmd_regression_check() {
fi
local prev_run_id
# Get the most recent run that is not the current one (index is append-newest-last)
prev_run_id=$(jq -r --arg rid "$run_id" 'select(.run_id != $rid) | .run_id' "$INDEX_FILE" 2>/dev/null | tail -1)
# Note: tail -1 gives the last non-current entry, which is the most recent previous run
if [[ -z "$prev_run_id" ]]; then
echo "[archeflow-memory] No previous run found — skipping regression check." >&2
@@ -555,17 +557,17 @@ cmd_forget() {
ensure_dir
# Check if the lesson exists
if ! jq -e "select(.id == \"$target_id\")" "$LESSONS_FILE" > /dev/null 2>&1; then
if ! jq -e --arg tid "$target_id" 'select(.id == $tid)' "$LESSONS_FILE" > /dev/null 2>&1; then
echo "Error: lesson $target_id not found." >&2
exit 1
fi
# Archive the lesson
jq -c "select(.id == \"$target_id\")" "$LESSONS_FILE" >> "$ARCHIVE_FILE"
jq -c --arg tid "$target_id" 'select(.id == $tid)' "$LESSONS_FILE" >> "$ARCHIVE_FILE"
# Remove from lessons
local tmp_file="${LESSONS_FILE}.tmp"
jq -c "select(.id != \"$target_id\")" "$LESSONS_FILE" > "$tmp_file"
jq -c --arg tid "$target_id" 'select(.id != $tid)' "$LESSONS_FILE" > "$tmp_file"
mv "$tmp_file" "$LESSONS_FILE"
echo "[archeflow-memory] Forgot lesson $target_id (moved to archive)" >&2