Skip to content

Latest commit

 

History

History
132 lines (101 loc) · 6.55 KB

precheck_pack.md

File metadata and controls

132 lines (101 loc) · 6.55 KB

precheck_pack.sh

Revision: 1 Last modified: 2026-12-04T19:00:00Z

Overview

precheck_pack.sh runs the machine pre-check pack (DEC-33) against a clean checkout of a review batch and emits a PreCheckReport.

It is the machine half of code review. Before a human or an agent reads a diff, this tool answers the questions that do not need judgement: does the tree build, do the touched shell scripts lint clean, are the claimed diffs real, is the checkout actually clean. Findings that a machine can settle are settled here so the reviewer's attention goes to judgment-class findings instead — and so that a reviewer cannot file a mechanical finding the machine would have caught (review_record.py later classifies each finding into exactly that closed set).

Run it on a clean checkout (--clean-checkout), because a pre-check against a dirty tree can pass on work that is not the change under review.

Prerequisites

  • sh, python3, shellcheck.
  • lib/precheck_pack_run.py beside it.
  • A review batch JSON (--batch) and a batch config (--config).
  • A clean checkout directory (--clean-checkout) — a real directory, not a worktree of the live tree.

No environment variables are read by this script. It is git-env-hermetic: before doing anything it unsets the caller's repository-locating git variables (GIT_DIR, GIT_WORK_TREE, GIT_INDEX_FILE, GIT_PREFIX, GIT_COMMON_DIR, GIT_OBJECT_DIRECTORY, GIT_ALTERNATE_OBJECT_DIRECTORIES, GIT_NAMESPACE, GIT_SHALLOW_FILE, GIT_GRAFT_FILE, GIT_REPLACE_REF_BASE, GIT_NO_REPLACE_OBJECTS, GIT_QUARANTINE_PATH, GIT_INTERNAL_SUPER_PREFIX) so that a caller who is inside a repository cannot silently redirect the checks at the wrong tree.

Usage examples

# the ordinary run
sh scripts/fastcycle/review/precheck_pack.sh \
  --config review.config.yaml \
  --batch batch.json \
  --clean-checkout /tmp/review-wt \
  --out precheck.json

# compare against a baseline repository, mapping a checkout prefix
sh scripts/fastcycle/review/precheck_pack.sh \
  --config review.config.yaml --batch batch.json \
  --clean-checkout /tmp/review-wt --out precheck.json \
  --baseline-repo /abs/path/to/baseline --baseline-ref origin/main

# bound the linter, and pin the reviewed commit
sh scripts/fastcycle/review/precheck_pack.sh \
  --config review.config.yaml --batch batch.json \
  --clean-checkout /tmp/review-wt --out precheck.json \
  --head-sha "$(git rev-parse HEAD)" \
  --shellcheck-timeout 300 --shellcheck-memory-cap-mib 2048 --shellcheck-max-lines 20000

Exit codes

Code Meaning
0 All checks pass.
1 At least one check FAILs.
2 Usage or configuration error: missing/unreadable --batch, bad arguments, a relative --baseline-repo, or --baseline-ref without --baseline-repo.
4 Clean checkout unavailable: --clean-checkout is missing or is not a directory.

Exit 4 is kept distinct from 2 deliberately — it is the one clause the contract states explicitly for this tool, and "you gave me no clean tree" is a different operator action from "your arguments are wrong".

The shellcheck check: whole-file strict with a severity floor

The rule is touch a file, own its shellcheck findings, and it is implemented as follows.

Which files. Every shell script the batch touches — by file extension, by shebang (including versioned shells and busybox/toybox multicalls), or because its base blob was a shell script. That last clause closes the obvious hole: renaming a .sh to a non-shell extension does not exempt it.

How. Each file is linted whole with shellcheck --norc -e SC1090,SC1091, fed on stdin, from an empty cwd and a scrubbed environment. Linting whole rather than only the changed hunk is what makes "own its findings" true; a scrubbed environment and empty cwd stop a caller's shell state from changing the result.

What fails. Every error- and warning-level finding fails, and every finding in the closed info set SC2086, SC2030, SC2031, SC2162, SC2059. Any other info/style finding is listed as advisory and does not fail. The floor is closed on purpose: an open-ended "all info fails" rule would make the gate fire on unrelated style drift, and a closed set keeps every failure explainable.

Edge cases

  • --baseline-repo relative. Exit 2; it must be an absolute repository toplevel. A PREFIX=PATH form maps a checkout under a prefix, which is how a batch built in a different layout is compared.
  • --baseline-ref without --baseline-repo. Exit 2.
  • --clean-checkout absent or not a directory. Exit 4 — never a silent run against the live tree.
  • shellcheck too slow or too large. Bounded by --shellcheck-timeout, --shellcheck-max-lines and --shellcheck-memory-cap-mib; a per-exception timeout is available via --shellcheck-exception-timeout.
  • An exception TSV. --shellcheck-exceptions <tsv> allows reviewed, justified carve-outs. Without a TSV, nothing is exempted.
  • --determinism-check. Runs the pack twice and compares, for when a check's stability is in doubt.
  • /system/bin/sh scripts. Recognised by shebang, so a device-shell script is linted as shell rather than skipped.

Internal behaviour

  1. Unsets the git-locating environment variables (see Prerequisites).
  2. Validates arguments; exit 2 on usage/config problems, exit 4 if the clean checkout is unusable.
  3. Delegates to lib/precheck_pack_run.py, which reads the batch and config, enumerates the touched shell scripts by the rules above, and runs each check.
  4. Aggregates per-check results into a PreCheckReport and writes --out.
  5. Exits 0 all pass, 1 any check FAIL.

Related scripts

Called by scripts/fastcycle/review/precheck_pack_build.sh (the one-shot wrapper that builds a pack and then runs this).

Calls scripts/fastcycle/review/lib/precheck_pack_run.py, which in turn reaches scripts/fastcycle/gates/io_trace.sh and scripts/fastcycle/lib/host_guard.sh.

Guarded by scripts/fastcycle/tests/test_precheck_slicer_red.sh (T061). Contract: specs/004-fast-dev-cycles/contracts/review-batch-and-precheck.md (RB-002); data-model #10.3.

See also docs/scripts/precheck_pack_build.sh.md (automates the whole sequence), docs/scripts/review_record.py.md (consumes precheck.json to classify findings) and docs/scripts/tower_detector.sh.md.

Last verified

2026-12-04 — bash -n scripts/fastcycle/review/precheck_pack.sh → exit 0. sh scripts/fastcycle/review/precheck_pack.sh with no arguments exits 2 with a usage message.