Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ to run it.
| **`UserPromptSubmit` / `PreCompact`** | Re-injects the last verdict so the agent always knows the sync state. |
| **`PreToolUse`** (Bash `git push`/`git commit`) | Runs `sync` synchronously and **blocks only on a broken requirement** (`specViolation`). Every other verdict is advisory (warn, don't block), and a sync that does not run never blocks — the gate says why. Before that, a `git commit` that would carry spec pages the analysis inferred (staged, or added by a `git add -A` in the same command) is refused with each page named and how to leave it out (`predictable staged-inferred-pages`): they belong to Predictable's database, never to the code's branch. |
| **`Stop` / `SubagentStop`** | Advisory turn-end `sync` (skipped if one is already running) so the agent keeps working toward an in-sync state. |
| **`Stop`** (inside a `predictable fix` session) | The fix gate (`scripts/fix-gate.sh`): the agent may not end its turn until `predictable fix-check` reads `gone` for the finding being fixed — no longer reported, and the project left with fewer findings than the fix started from. It is released when nothing changed since its last block (the `predictable fix` driver then decides whether the loop is stuck) and never traps a session whose check cannot run. |
| **`Stop`** (inside a `predictable fix` session) | The fix gate (`scripts/fix-gate.sh`): the agent may not end its turn until `predictable fix-check` reads `gone` for the finding being fixed — no longer reported, and the project left with fewer findings than the fix started from. It is released when nothing changed since its last block (the `predictable fix` driver then decides whether the loop is stuck), and when the agent showed the finding is not a defect and `predictable report --kind false-positive` accepted its report (a claim under the database's `fixes/false-positives/`; the driver then ends the fix `false-positive` on its own evidence). It never traps a session whose check cannot run. |

Edits do **not** trigger a sync: the skill runs its own `predictable sync` after
changing code, and two syncs on one project at once are never allowed — every hook
Expand Down
55 changes: 55 additions & 0 deletions scripts/fix-gate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,59 @@
#
# It never traps a session:
# - a check that cannot run (no binary, no answer) lets the turn end — the driver decides;
# - a finding the agent showed is NOT a defect lets the turn end once `predictable report --kind
# false-positive` ACCEPTED its report (#3360): the analysis still reports it, by design, and the
# driver — not this gate — ends the fix `false-positive` on its own evidence (the accepted claim
# and the code left as it was). The claim is the file `predictable report` writes under the
# database root's `fixes/false-positives/`, matched here by the finding it names;
# - a second stop with NOTHING changed since the last block lets the turn end — the agent has
# nothing new to try in this turn, and the driver's own rule decides whether it is stuck.

self_dir=$(cd -- "$(dirname -- "$0")" >/dev/null 2>&1 && pwd)
# shellcheck source=scripts/lib.sh
. "$self_dir/lib.sh"

# The database root the fix's state lives in, as the CLI decides it (`StateLayout.databaseRootOf`):
# for `<repo>/.predictable-code/<branch>/.predictable-code`, the first `.predictable-code`; for any
# other state directory, the directory itself. Without PREDICTABLE_FIX_PATH, the project's own.
pc_fix_database_root() {
base="${PREDICTABLE_FIX_PATH:-}"
if [ -z "$base" ]; then
printf '%s/.predictable-code' "$(pc_project_dir)"
return
fi
case "$base" in
/*) ;;
*) base="$(pc_project_dir)/$base" ;;
esac
base="${base%/}"
case "$base" in
*/.predictable-code/*/.predictable-code)
printf '%s/.predictable-code' "${base%%/.predictable-code/*}"
;;
*) printf '%s' "$base" ;;
esac
}

# Whether `predictable report` accepted a false-positive report about this finding (#3360): a claim
# under `fixes/false-positives/` naming its fqn and its tag (the vc, else the category — the CLI's
# key rule, which matches a tag given as either).
pc_false_positive_claimed() {
claims="$(pc_fix_database_root)/fixes/false-positives"
[ -d "$claims" ] || return 1
for claim in "$claims"/*.json; do
[ -f "$claim" ] || continue
if jq -e --arg fqn "$1" --arg vc "$2" --arg cat "$3" '
(.finding.fqn == $fqn) and
((.finding.vc // .finding.category // "") as $tag
| $tag != "" and ($tag == $vc or $tag == $cat))
' "$claim" >/dev/null 2>&1; then
return 0
fi
done
return 1
}

stdin_json=$(mktemp 2>/dev/null || echo "/tmp/pc-fix-gate.$$")
cat >"$stdin_json"
cleanup() { rm -f "$stdin_json" 2>/dev/null || true; }
Expand Down Expand Up @@ -77,6 +123,15 @@ if [ "$verdict" = "gone" ]; then
cleanup
exit 0
fi
# THE AGENT SHOWED IT IS NOT A DEFECT, and Predictable accepted the report: nothing to fix, so the
# turn ends here and the driver decides. Only for a finding still reported — a regression is the
# agent's own change, which a report about the original finding does not answer.
if [ "$verdict" = "reported" ] && pc_false_positive_claimed "$fqn" "$vc" "$category"; then
rm -f "$last_digest_file" 2>/dev/null || true
pc_log Stop fix-gate released-false-positive
cleanup
exit 0
fi
# Blocked before and nothing changed since: let the turn end rather than spin on the same tree.
if [ "$active" = "true" ] && [ -n "$digest" ] && [ -f "$last_digest_file" ] &&
[ "$(cat "$last_digest_file" 2>/dev/null)" = "$digest" ]; then
Expand Down
45 changes: 45 additions & 0 deletions tests/run-hooks-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,51 @@ run_hook fix-gate.sh stop-hook-active.json
contains "$OUT" '"decision": "block"'
check "fix-gate blocked before but the code changed -> blocks again" $?

# A FALSE POSITIVE THE AGENT REPORTED (#3360): `predictable report` accepted it and left a claim
# under the database root, so the still-reported finding no longer holds the turn.
fp_claim() { # dir fqn vc
mkdir -p "$1"
printf '{"finding":{"fqn":"%s","vc":"%s","category":null},"title":"t","why":"w","digest":"d","state":"recorded","number":null,"url":null,"payload":null}' \
"$2" "$3" >"$1/c1.json"
}

fresh_data
fix_target
reported reported "a complete sync still reports it" d1
fp_claim "$CLAUDE_PROJECT_DIR/.predictable-code/fixes/false-positives" Code.cards.totalUnits il1.null-dereference
run_hook fix-gate.sh stop.json
rc=1
[ -z "$OUT" ] && [ "$CODE" -eq 0 ] && rc=0
check "fix-gate reported, its false positive accepted -> the turn may end" "$rc" "got: $OUT"

fresh_data
fix_target
reported reported "a complete sync still reports it" d1
fp_claim "$CLAUDE_PROJECT_DIR/.predictable-code/fixes/false-positives" Code.cards.other il1.null-dereference
run_hook fix-gate.sh stop.json
contains "$OUT" '"decision": "block"'
check "fix-gate: a claim about ANOTHER finding releases nothing" $?

fresh_data
fix_target
reported regressed "gone, but introduced others" d1 '"Code.cards.lastUnits|il1.x"'
fp_claim "$CLAUDE_PROJECT_DIR/.predictable-code/fixes/false-positives" Code.cards.totalUnits il1.null-dereference
run_hook fix-gate.sh stop.json
contains "$OUT" '"decision": "block"'
check "fix-gate: a regression still blocks, whatever was reported" $?

fresh_data
fix_target
reported reported "a complete sync still reports it" d1
PREDICTABLE_FIX_PATH="$CLAUDE_PROJECT_DIR/.predictable-code/main/.predictable-code"
export PREDICTABLE_FIX_PATH
fp_claim "$CLAUDE_PROJECT_DIR/.predictable-code/fixes/false-positives" Code.cards.totalUnits il1.null-dereference
run_hook fix-gate.sh stop.json
rc=1
[ -z "$OUT" ] && [ "$CODE" -eq 0 ] && rc=0
check "fix-gate finds the claim at the database root of a branch's state dir" "$rc" "got: $OUT"
unset PREDICTABLE_FIX_PATH

fresh_data
fix_target
STUB_FAIL=1 run_hook fix-gate.sh stop.json
Expand Down
Loading