#!/usr/bin/env bash # The plugin root: the variable when the platform sets it (hooks), else this file's own place. PLUGIN_ROOT="${CLAUDE_PLUGIN_ROOT:-$(cd "$(dirname "$0")/../../.." && pwd -P)}" export CLAUDE_PLUGIN_ROOT="$PLUGIN_ROOT" # review-actions.sh: the deterministic half of the review skill (ideal/review.md). # # The skill body holds the conversation. This script holds the deterministic half: it reads what # implementation handed over, writes the diff once, runs every command the two recipes declare over # the changed files at the final commit, assembles the architecture reviewer's brief, records what # that reviewer found, runs the surfaces and records the acceptance verifier's evidence, and closes # the review with one verdict and its warnings. It never judges whether a criterion is met by reading # code, and it starts no fixer: the record goes to the person. # # One review record, at /review/review.json (scripts/review-schema.json). It lives in # its own folder beside research/, design/ and implementation/, because implementation's `redo` # and `drop` move an order's records out of implementation/ into an archive folder beside it, and # a review has nothing to do with them. # # Usage: # review-actions.sh read # review-actions.sh checks [--recipe =]... # [--check-recipe =]... # [--lookup-failed =]... # [--catalog-recipe =]... # [--catalog-check-recipe =]... # [--value =]... # review-actions.sh brief writes /review/brief.json # review-actions.sh findings [--findings ] # review-actions.sh acceptance [--evidence] # [--accept-baseline ]... # [--value =]... # review-actions.sh close [--row =met|unmet]... # [--row =wrong|deferred]... # review-actions.sh audit the checks, and how each verdict came about # review-actions.sh archive moves a closed pass aside, so review runs again # review-actions.sh step [--part ] # # `--recipe` names the `test-execution` recipe, for its `## Test commands` block, which carries the # suite row and the mutation row. `--check-recipe` names the `review` recipe, for its # `## Check commands` block and its `## Surface commands` block. Every framework the project # declares needs one of the two, or a `--lookup-failed` saying which way its lookup failed. The # three reasons stay apart: no-recipe, listing-unreachable, fetch-failed. Only the first says # anything about the framework; the other two mean nobody looked. # # Every action prints a summary of `key: value` lines and nothing else: no record body, no diff, no # command output, no research text. Each line that a person may want in full names the path that holds # it, which is /review/review.json for the record, review/diff.patch for the diff and # review/brief.json for the reviewer's brief. The one body any action prints is `read`'s checklist # rows, because the person answering them has to read them verbatim. # # `acceptance` takes no recipe flag. It reads the review recipe path `checks` recorded, so the surface # block is read from the same file the tool rows came from and review keeps its two lookups. Its # `--value base-url=
` is exported as PLAYWRIGHT_BASE_URL for every row, and nothing stores # an address (ideal/surfaces.md). Its `--evidence` reads the rows the acceptance verifier wrote to # /records/evidence.json, which git ignores, and the review record keeps them. The files the # rows name stay under /review/evidence/, where git keeps text and no image. # # `step` prints one of this skill's own step files, from # ${CLAUDE_PLUGIN_ROOT}/skills/review/references/.md. The skill reads them through this action # rather than with Read: the documentation mirror scopes ${CLAUDE_PLUGIN_ROOT} substitution in # `allowed-tools` to Bash rules, so a Read rule naming that variable never matches and every # step-file read raises a prompt an unattended run cannot answer. # # Exit codes, each one and only one meaning, and every meaning is the one implementation gave it: # 0 did what was asked. For `read`, this includes an honest report that nothing has run yet. # 1 the given path does not exist, is not a folder, or holds no task.json: not a task folder. # 3 the script could not do its job: a missing or unrecognized argument, jq or git not on PATH, # the plugin root or a library that could not be resolved, a project or task folder that could # not be resolved, a record or a frozen file that is present but unreadable, a record that does # not match scripts/review-schema.json, a framework nothing was said about, a criterion the # live contract changed after the freeze, or a code # repository whose HEAD is not the commit implementation's own range ends at, or that commit # with the files `task environment up` added removed. # 5 the recorded codePath exists and is not a git repository. # 14 the project's own project.json exists and is not valid JSON. # 15 the recorded codePath does not exist on disk. # 51 on an autonomous run only: the code path moved, or went dirty, since `checks` ran, or a text # the reviewer read changed since `brief` ran. With a person present each is a warning. # 52 the findings file could not be read as a findings file, or it answers a done-when clause no # order routed to review. Or the evidence file could not be read as the verifier's rows, or it # leaves a criterion with no row. # 61 the code repository's tree is dirty. # 62 a step ran out of order, and what it depends on recorded nothing. # 63 the previous record could not be archived, so the write was refused. # 66 implementation has not finished, so there is no finished.json. # 70 a person's answer was passed on a run with nobody present. # 73 the check recipe resolved now is not the one the baseline was taken with. # 77 the project records no framework. # 79 the action was run from outside the task's own worktree; every stage action but `read` runs there. # 124 `checks` found a frozen test or support file of some order that no longer matches the hash # its freeze recorded. The message names each order and file. Nothing is written. # # Codes 5, 14, 15, 52, 70, 72 and 73 arrive from scripts/lib/recipes.sh, which both stages source, and # they carry exactly the meanings implement-actions.sh's own table gives them. ideal/review.md lists # eight of these; the rest come with the shared helpers, and giving them new numbers here would make # one number mean two things. # # Depends on, shipped by other builders of this same project and never edited here: # ${CLAUDE_PLUGIN_ROOT}/scripts/lib/recipes.sh sourced. The recipe block parsers, the # resolver, the command runner, the clean-tree # refusal, the code-path loader, the findings # file reader. Nothing here carries a second # copy of any of them. # ${CLAUDE_PLUGIN_ROOT}/scripts/lib/records-hash.sh sourced, for the one decision about which # sha256 tool exists. # ${CLAUDE_PLUGIN_ROOT}/scripts/lib/task-helpers.sh sourced, for resolve_task_folder, # write_atomic, looks_like_flag, is_blank, # distill_stale and distill_stamp. # ${CLAUDE_PLUGIN_ROOT}/scripts/lib/schema-check.sh sourced. Every record write is compared # against review-schema.json before it lands. # ${CLAUDE_PLUGIN_ROOT}/scripts/lib/surfaces.sh sourced. The surface file reader the # surfaces skill's writer is proved by. # ${CLAUDE_PLUGIN_ROOT}/scripts/lib/proof.sh sourced, for br_order_facts and # br_proof_facts: what a proof kind means # for a check about to answer, per order # and over the whole snapshot. Also # BR_HARNESS_JQ, for the mutation row. # ${CLAUDE_PLUGIN_ROOT}/scripts/lib/paths.sh sourced, for resolve_against, which # sf_surface_path joins a relative registryPath # through. # ${CLAUDE_PLUGIN_ROOT}/scripts/review-schema.json the shape of the record this script writes. # # Portability: bash 3.2+ and zsh. No mapfile, no associative arrays, no GNU-only flag, no awk, no # regular-expression interval quantifier. The five zsh traps implement-actions.sh's header lists # hold here too: never a variable named `path` or `fpath`, no reliance on word splitting an unquoted # expansion, no variable used as a case pattern without GLOB_SUBST scoped to a subshell, no # `local a b="$a"` statement, and no `local` inside a loop body. set -uo pipefail # not -e: several branches test a command's exit code on purpose. trap '' PIPE # a closed pipe must not kill the writes after a print; research-actions.sh says why if [ -n "${ZSH_VERSION:-}" ]; then setopt KSH_ARRAYS 2>/dev/null fi if [ -n "${ZSH_VERSION:-}" ]; then SCRIPT_SOURCE="$0" else SCRIPT_SOURCE="${BASH_SOURCE[0]}" fi PLUGIN_ROOT="${CLAUDE_PLUGIN_ROOT:-$(cd -- "$(dirname -- "$SCRIPT_SOURCE")/../../.." >/dev/null 2>&1 && pwd -P)}" if [ -z "$PLUGIN_ROOT" ] || [ ! -d "$PLUGIN_ROOT" ]; then printf 'review-actions: could not resolve the plugin root (CLAUDE_PLUGIN_ROOT is not set and the script'"'"'s own location could not be resolved)\n' >&2 exit 3 fi STEPS_DIR="${PLUGIN_ROOT}/skills/review/references" RECORDS_HASH_LIB="${PLUGIN_ROOT}/scripts/lib/records-hash.sh" RECIPES_LIB="${PLUGIN_ROOT}/scripts/lib/recipes.sh" TASK_HELPERS_LIB="${PLUGIN_ROOT}/scripts/lib/task-helpers.sh" SCHEMA_CHECK_LIB="${PLUGIN_ROOT}/scripts/lib/schema-check.sh" SURFACES_LIB="${PLUGIN_ROOT}/scripts/lib/surfaces.sh" PATHS_LIB="${PLUGIN_ROOT}/scripts/lib/paths.sh" PROOF_LIB="${PLUGIN_ROOT}/scripts/lib/proof.sh" REVIEW_SCHEMA="${PLUGIN_ROOT}/scripts/review-schema.json" command -v jq >/dev/null 2>&1 || { printf 'review-actions: jq is required and was not found on PATH\n' >&2; exit 3; } command -v git >/dev/null 2>&1 || { printf 'review-actions: git is required and was not found on PATH\n' >&2; exit 3; } # An answer task_answer_find held is marked refused before the exit (task-helpers.sh). die() { ! command -v task_answer_refused >/dev/null 2>&1 || task_answer_refused "$1"; printf 'review-actions: %s\n' "$2" >&2; exit "$1"; } # One refusal function, one exit code as its first argument. The table above is the only place a # number gets a meaning, and nothing here mints one that table does not carry. # task-helpers.sh takes these three from its caller, so a refusal still says which script refused. # shellcheck disable=SC2329 # called by functions in scripts/lib/task-helpers.sh die1() { die 1 "$1"; } # shellcheck disable=SC2329 # called by functions in scripts/lib/task-helpers.sh die3() { die 3 "$1"; } # shellcheck disable=SC2329 # called by functions in scripts/lib/task-helpers.sh die79() { die 79 "$1"; } for lib_name in "$RECORDS_HASH_LIB" "$TASK_HELPERS_LIB" "$SCHEMA_CHECK_LIB" "$RECIPES_LIB" "$SURFACES_LIB" "$PATHS_LIB" "$PROOF_LIB"; do [ -f "$lib_name" ] || die 3 "cannot find the library at $lib_name" # shellcheck source=/dev/null source "$lib_name" || die 3 "the library failed to load: $lib_name" done [ -f "$REVIEW_SCHEMA" ] || die 3 "cannot find the record shape at $REVIEW_SCHEMA" # The eight lenses one dispatch carries. The words are fixed here, in agents/architecture-reviewer.md # and in the step file, and each of checks 2, 9, 10, 11, 12 and 16 reads its verdict off its own # lens. The purpose lens is check 3's reviewer half, and it merges into the script half's row. A # word this list does not hold would leave its check reading met on a findings file that is not # empty, so a finding naming one is refused rather than recorded. LENS_WORDS="non-goals solid dry architecture guides practices mutation purpose" # The words a close --row takes, by the kind of row its id names. The refusal of a wrong word and # the list of waiting rows both read this one definition (gap row 279, live-run row 430). RW_ROW_WORDS_JQ='def row_words: if (startswith("decision-") and endswith("-departure")) then ["keep", "rebuild"] elif (startswith("decision-") and (endswith("-non-goal") or endswith("-criterion"))) then ["accept", "reject"] elif startswith("decision-") then ["wrong", "deferred", "load-bearing", "test-wrong"] elif test("^f[1-9][0-9]*$") then ["wrong", "deferred", "test-wrong", "contract-wrong", "fix"] else ["met", "unmet"] end; def or_list: if length < 2 then join("") else (.[0:-1] | join(", ")) + " or " + .[-1] end;' # The words that rule a finding at close. contract-wrong carries the corrected text after a colon. RW_RULING_WORDS='["wrong", "deferred", "test-wrong", "contract-wrong", "fix"]' # The search review records, through research-actions.sh record, when no guide body is on disk: # current practice for the stack, found by the outward searcher (gap row 364). It is a research # file, so the brief carries it with the others, and findings reads it by this name. PRACTICE_SEARCH="review-practices" # The sixteen checks, by the id each one carries in the record. The tool rows a recipe declares # beyond coding-standards, static-analysis and security carry their own row ids, because the check # commands block is a floor and never the list. CHECK_EVERY_CRITERION="every-criterion" CHECK_SERVES="serves-a-criterion" CHECK_TEST_MUTATION="test-and-mutation" CHECK_SUITE="suite" CHECK_E2E="e2e" CHECK_VR="visual-regression" CHECK_PARITY="visual-parity" usage() { cat <<'EOF' >&2 usage: review-actions.sh read review-actions.sh checks [--recipe =]... [--check-recipe =]... [--lookup-failed =]... [--catalog-recipe =]... [--catalog-check-recipe =]... [--value =]... review-actions.sh brief review-actions.sh findings [--findings ] review-actions.sh acceptance [--evidence] [--accept-baseline ]... [--value =]... review-actions.sh close [--row =met|unmet]... [--row =wrong|deferred]... review-actions.sh audit review-actions.sh archive review-actions.sh step [--part ] EOF } # ------------------------------------------------------------------------------------------------ # The files this stage reads and the one it writes. # ------------------------------------------------------------------------------------------------ IMPL_DIR=""; REVIEW_DIR=""; RECORD_FILE=""; DIFF_FILE="" FINISHED_FILE=""; SNAPSHOT_FILE=""; BASELINE_FILE=""; ALIGNMENT_FILE="" FINDINGS_TARGET=""; BRIEF_FILE=""; LEDGER_FILE=""; EVIDENCE_FILE="" # $1 the action's own name, $2 the task folder as given. Sets TASK_PATH and every path above. rw_paths() { local who="$1" arg="$2" resolve_rc TASK_PATH="$(resolve_task_folder "$arg" "$who")" resolve_rc=$? [ "$resolve_rc" -eq 0 ] || exit "$resolve_rc" IMPL_DIR="$TASK_PATH/implementation" REVIEW_DIR="$TASK_PATH/review" RECORD_FILE="$REVIEW_DIR/review.json" DIFF_FILE="$REVIEW_DIR/diff.patch" FINDINGS_TARGET="$REVIEW_DIR/findings.json" BRIEF_FILE="$REVIEW_DIR/brief.json" EVIDENCE_FILE="$TASK_PATH/records/evidence.json" FINISHED_FILE="$IMPL_DIR/finished.json" SNAPSHOT_FILE="$IMPL_DIR/snapshot.json" LEDGER_FILE="$IMPL_DIR/ledger.json" BASELINE_FILE="$IMPL_DIR/baseline.json" ALIGNMENT_FILE="$TASK_PATH/alignment.json" } RW_FINISHED_DOC=""; RW_SNAPSHOT_DOC=""; RW_RECORD_DOC="" RW_RUN_MODE="interactive"; RW_PROJECT_DOC=""; RW_TASK_ID=""; RW_TASK_STATE="" # What the snapshot's proof kinds mean for a check about to answer, from br_proof_facts. A check # reads one of these two and never re-derives a proof kind of its own. RW_COMMITS_IN_CODE="yes"; RW_OWNS_IN_CODE="yes" # Exit 66. Implementation has not finished, so there is nothing to review. rw_require_finished() { local who="$1" case "$(json_file_state "$FINISHED_FILE")" in missing) die 66 "$who: $FINISHED_FILE not found, so implementation has not finished for this task. Run the implement skill's finish step first; review reads the record it writes." ;; unreadable) die 3 "$who: $FINISHED_FILE exists but could not be read as JSON. Repair or remove it by hand before running this again." ;; esac RW_FINISHED_DOC="$(jq -c '.' "$FINISHED_FILE")" } # The run mode, from the task for this stage, and the snapshot, for the frozen contract and the # frozen orders. The mode is read from task.json through task_run_mode and not from the ledger's # copy: the ledger records the mode the build ran under, and a person who sets the task's mode # after the build, or scopes it to the build alone, means review to obey the task (nyc defect 20). # The snapshot exists whenever finished.json does, so its absence is a tree this script reports # rather than repairs. rw_require_frozen() { local who="$1" RW_RUN_MODE="$(task_run_mode "$TASK_PATH" review)" case "$(json_file_state "$SNAPSHOT_FILE")" in missing) die 3 "$who: $SNAPSHOT_FILE not found, though $FINISHED_FILE exists. The frozen contract and the frozen orders are what review judges against." ;; unreadable) die 3 "$who: $SNAPSHOT_FILE exists but could not be read as JSON. Repair or remove it by hand before running this again." ;; esac RW_SNAPSHOT_DOC="$(jq -c '.' "$SNAPSHOT_FILE")" RW_TASK_ID="$(jq -r '.id // empty' "$TASK_PATH/task.json" 2>/dev/null)" [ -n "$RW_TASK_ID" ] || die 3 "$who: $TASK_PATH/task.json has no usable id field." RW_TASK_STATE="$(jq -r '.state // ""' "$TASK_PATH/task.json" 2>/dev/null)" local facts facts="$(br_proof_facts "$RW_SNAPSHOT_DOC")" RW_COMMITS_IN_CODE="${facts%% *}" RW_OWNS_IN_CODE="${facts##* }" [ -n "$RW_COMMITS_IN_CODE" ] && [ -n "$RW_OWNS_IN_CODE" ] \ || die 3 "$who: the proof kinds in $SNAPSHOT_FILE could not be read, so no check here knows whether this task has code to look at." } # The project record, for the frameworks and the two surface fields. rv_load_codepath has already # said the file is valid JSON by the time this runs. rw_load_project() { RW_PROJECT_DOC="$(jq -c '.' "$RV_PROJECT_FOLDER/project.json" 2>/dev/null)" [ -n "$RW_PROJECT_DOC" ] || die 14 "$1: $RV_PROJECT_FOLDER/project.json could not be read as JSON." } # Sets RW_RECORD_DOC to the record on disk, or the empty string when there is none. $1 the action. rw_load_record() { local who="$1" RW_RECORD_DOC="" case "$(json_file_state "$RECORD_FILE")" in ok) RW_RECORD_DOC="$(jq -c '.' "$RECORD_FILE")" ;; unreadable) die 3 "$who: $RECORD_FILE exists but could not be read as JSON. Move it aside by hand; review refuses to write over a record it cannot read." ;; esac } # True when the record holds a check row with id $1. rw_record_has_check() { [ -n "$RW_RECORD_DOC" ] || return 1 printf '%s' "$RW_RECORD_DOC" | jq -e --arg id "$1" '[ (.checks // [])[] | select(.id == $id) ] | length > 0' >/dev/null 2>&1 } # Exit 62. A step whose input recorded nothing has nothing to act on, and a review that carried on # would record a verdict read off a file that is not there. $1 the action, $2 the check id that # proves the earlier step ran, $3 what to run instead. rw_require_step() { local who="$1" marker="$2" advice="$3" rw_record_has_check "$marker" && return 0 die 62 "$who: $RECORD_FILE records no $marker row, so the step before this one recorded nothing. Run $advice first." } # Which step this task is at, as one word the `read` report prints: checks, reviewer, acceptance, # close or done. Read off the record's own rows, because each action writes rows nothing else # writes; there is no separate state field, and a fourth place to keep one would be a fourth thing # to keep in step. rw_step_now() { if [ -z "$RW_RECORD_DOC" ]; then printf 'checks'; return; fi if printf '%s' "$RW_RECORD_DOC" | jq -e 'has("verdict")' >/dev/null 2>&1; then printf 'done'; return; fi if printf '%s' "$RW_RECORD_DOC" | jq -e 'has("evidence")' >/dev/null 2>&1; then printf 'close'; return; fi if rw_record_has_check "solid"; then printf 'acceptance'; return; fi if rw_record_has_check "$CHECK_SERVES"; then printf 'reviewer'; return; fi printf 'checks' } # Exit 63. Moves each file named after $3 that exists to --.json, with $2 the # commit. One suffix serves every file: the first of -, then -2, -3 and on, that no # file takes, so two passes on one commit in one day both keep their files. $1 the action. rw_archive_files() { local who="$1" short="$2" today suffix n file target taken shift 2 today="$(date -u +%Y-%m-%d)" suffix="$today-$short"; n=1 while :; do taken="" for file in "$@"; do [ -e "$file" ] && [ -e "${file%.json}-$suffix.json" ] && taken="yes" done [ -n "$taken" ] || break n=$((n + 1)); suffix="$today-$short-$n" done for file in "$@"; do [ -e "$file" ] || continue target="${file%.json}-$suffix.json" mv "$file" "$target" \ || die 63 "$who: could not move $file to $target, so the write was refused. The record of the previous pass is still at $RECORD_FILE." echo "$(printf '%s' "$who" | tr '[:lower:]' '[:upper:]'): the previous $(basename "$file") moved to $target" >&2 done } # The commit of the record loaded, cut to seven characters, for an archive name. rw_record_short() { local short short="$(printf '%s' "$RW_RECORD_DOC" | jq -r '.reviewedAt // ""' 2>/dev/null | cut -c1-7)" printf '%s' "${short:-unknown}" } # A re-run archives the record a previous pass closed. Version 5 ran four review passes on one task, # each overwriting the last, and pass three found a defect pass four's record does not mention. A # record with no verdict is a pass still in flight and is updated in place: nothing in it has been # concluded yet. The name reuses the shape `redo` and `drop` write. The pass's findings file and brief go # with it: the next brief names the same findings path, and a fresh reviewer that finds a file there # starts from the previous reviewer's conclusions (gap row 276). The record moves last. $1 the action. rw_archive_closed_record() { local who="$1" [ -n "$RW_RECORD_DOC" ] || return 0 printf '%s' "$RW_RECORD_DOC" | jq -e 'has("verdict")' >/dev/null 2>&1 || return 0 rw_archive_files "$who" "$(rw_record_short)" "$FINDINGS_TARGET" "$BRIEF_FILE" "$RECORD_FILE" RW_RECORD_DOC="" } # Compares $2, the record as text, against scripts/review-schema.json through the same library # check-project.sh and check-task.sh use, then writes it. A field the schema requires and the record # does not hold, or one whose type or constraint the schema refuses, stops the write: a record this # stage cannot read back is worse than no record. A field the schema marks optional may be absent, # and `verdict` is the one that matters, because it is absent until `close`. $1 the action. rw_write_record() { local who="$1" doc="$2" tmp result missing_required unreadable_fields mkdir -p "$REVIEW_DIR" || die 3 "$who: could not create $REVIEW_DIR" tmp="$(mktemp "$REVIEW_DIR/.review-candidate.XXXXXX")" \ || die 3 "$who: could not create a temporary file in $REVIEW_DIR" printf '%s\n' "$doc" >"$tmp" || { rm -f "$tmp"; die 3 "$who: could not write $tmp"; } result="$(schema_check_compare "$REVIEW_SCHEMA" "$tmp")" if [ -z "$result" ]; then rm -f "$tmp" die 3 "$who: the record could not be compared against $REVIEW_SCHEMA." fi missing_required="$(jq -r --slurpfile schema "$REVIEW_SCHEMA" ' ($schema[0].required // []) as $req | [ (.missing // [])[] | select(.field as $f | $req | index($f)) | .field ] | join(", ")' </dev/null)" [ -n "$current" ] \ || die 3 "$who: could not capture the current commit (git rev-parse HEAD failed in $RV_CODEPATH)." [ "$recorded" = "$current" ] \ || rw_pass_moved "$who" "$RV_CODEPATH is at $current, and the checks were run at $recorded, so what this step records is about code that is no longer there." [ "$how" = "clean" ] || return 0 dirty="$(git -C "$RV_CODEPATH" status --porcelain 2>/dev/null)" [ -z "$dirty" ] \ || rw_pass_moved "$who" "the working tree at $RV_CODEPATH is dirty, and the reviewer may write nothing but its own findings file. What changed: $(printf '%s' "$dirty" | tr '\n' ' ')" } # The rows a close still waits on, each with the words it takes, in one line (live-run row 430). # $1 the review record, $2 the person criteria that wait, as a JSON list of ids, $3 the findings a # person may rule, as a JSON list of ids. A finding already ruled and a check already answered do # not wait. A low follow-up finding may take fix, but it holds back nothing, so it does not wait. rw_rows_waiting() { printf '%s' "$1" | jq -r --argjson criteria "$2" --argjson rf "$3" "$RW_ROW_WORDS_JQ"' [ $criteria[] ] + [ (.findings // [])[] | select(.id as $i | ($rf | index($i)) != null) | select((.ruling // "") == "") | select(.disposition == "criterion" or .severity != "low") | .id ] + [ (.checks // [])[] | select(.verdict == "unknown" and ((.id | startswith("decision-")) or .answeredBy == "nobody")) | .id ] | map(. + " takes " + (row_words | or_list)) | join("; ")' } # ------------------------------------------------------------------------------------------------ # Reading the frozen records. # ------------------------------------------------------------------------------------------------ # The frozen contract, as an object. rw_alignment() { printf '%s' "$RW_SNAPSHOT_DOC" | jq -c '.alignment // {}'; } # Each criterion and non-goal whose text the live contract changed after the freeze, as one JSON # array of {kind, id, frozen, live}: live null for one removed, frozen null for one added (gap row # 410). A build may prove a non-goal's wording wrong, and only a redo and the start after it reach # the frozen text. # A live contract that cannot be read changes nothing. rw_contract_changes() { local live='{}' [ "$(json_file_state "$ALIGNMENT_FILE")" != ok ] || live="$(jq -c '.' "$ALIGNMENT_FILE")" printf '%s' "$RW_SNAPSHOT_DOC" | jq -c --argjson live "$live" ' def changes($kind; $frozen; $now): [ $frozen[] | . as $f | ([ $now[] | select(.id == $f.id) ][0]) as $l | select($l == null or $l.text != $f.text) | {kind: $kind, id: $f.id, frozen: $f.text, live: ($l.text // null)} ] + [ $now[] | . as $l | select(([ $frozen[] | select(.id == $l.id) ] | length) == 0) | {kind: $kind, id: $l.id, frozen: null, live: $l.text} ]; changes("criterion"; .alignment.criteria // []; $live.criteria // []) + changes("non-goal"; .alignment.nonGoals // []; $live.nonGoals // [])' } # The frozen tests that name a criterion, each as path::name. Its input is the criterion id. RW_FROZEN_TESTS_JQ='def frozen_tests($rows): . as $id | [ $rows[] | select(.criterion == $id) | (.tests // [])[] | .path + "::" + .name ];' # Each change the person accepts or rejects at close, as {kind, id, frozen, live}: every non-goal # change, and each criterion whose text changed while no frozen test names it (gap row 506). The # freeze stops a builder changing what it is judged by, and only a frozen test is open to that. The # reviewer judges the live text, and close holds the verdict until the person answers each change. # On an unattended run that answer is the record the main session writes, so the guard is as strong # as that record and no stronger (gap row 357). Reads RW_TEST_ROWS, so it runs after # rw_dropped_criteria, and it never refuses. rw_person_changes() { rw_contract_changes | jq -c --argjson rows "$RW_TEST_ROWS" "$RW_FROZEN_TESTS_JQ"' [ .[] | select(.kind == "non-goal" or (.frozen != null and .live != null and (.id | frozen_tests($rows)) == [])) ]' } # Each criterion the live contract removed, sorted by what still stands on it (gap row 498). A # dropped one is on RW_DROPPED, as {id, text, orders: [{id, because}]}: a dropped order served or # owned it, no other order does, and no frozen test names it. So nothing is left to prove the frozen # text. RW_REMOVED_HELD names every other removed id, with what holds it, for the refusal. A live # contract that cannot be read drops nothing. Leaves RW_TEST_ROWS loaded. $1 the action. RW_DROPPED="[]"; RW_REMOVED_HELD="" rw_dropped_criteria() { local removed rw_load_test_rows "$1" removed="$(jq_files -cn --argjson changes "$(rw_contract_changes)" --argjson snap "$RW_SNAPSHOT_DOC" \ --argjson finished "$RW_FINISHED_DOC" --argjson rows "$RW_TEST_ROWS" "$RW_FROZEN_TESTS_JQ"' ($finished.dropped // []) as $gone | ([ $gone[].id ]) as $goneIds | [ $changes[] | select(.kind == "criterion" and .live == null) | . as $c | ([ ($snap.workOrders // [])[] | select(((.criteriaServed // []) + (.criteriaOwned // [])) | index($c.id) != null) | .id ]) as $servers | {id: $c.id, text: $c.frozen, orders: [ $gone[] | select(.id as $i | $servers | index($i) != null) | {id, because} ], held: ([ $servers[] | select(. as $i | $goneIds | index($i) | not) ] + ($c.id | frozen_tests($rows)))} ]')" [ "$(json_file_state "$ALIGNMENT_FILE")" = ok ] || removed="$(printf '%s' "$removed" | jq -c 'map(.orders = [])')" RW_DROPPED="$(printf '%s' "$removed" | jq -c '[ .[] | select((.orders | length) > 0 and (.held | length) == 0) | del(.held) ]')" RW_REMOVED_HELD="$(printf '%s' "$removed" | jq -r '[ .[] | select((.orders | length) == 0 or (.held | length) > 0) | .id + " (" + (if (.held | length) == 0 then "none" else .held | join(", ") end) + ")" ] | join("; ")')" } # Exit 3 when the live contract changed a criterion that a frozen test names, or added one, after # the freeze. That test proves the frozen text, so no answer at close can make it prove another one, # and no order was built for an added criterion (gap row 506). Any other changed criterion waits # for the person at close (rw_person_changes). A dropped criterion passes. $1 the action. rw_refuse_changed_criteria() { local held rw_dropped_criteria "$1" held="$(rw_contract_changes | jq -r --argjson rows "$RW_TEST_ROWS" "$RW_FROZEN_TESTS_JQ"' [ .[] | select(.kind == "criterion" and .live != null) | (.id | frozen_tests($rows)) as $t | select(.frozen == null or $t != []) | .id + " (" + (if .frozen == null then "added" else $t | join(", ") end) + ")" ] | join("; ")')" [ -z "$held" ] \ || die 3 "$1: the live contract changed these criteria after the freeze: $held. A frozen test proves each frozen text, and no order was built for an added criterion, so review cannot judge them. Put the frozen text back with scope update, or remove an added criterion with scope remove. Or redo the orders that serve them in the implement skill, so their tests freeze again." [ -z "$RW_REMOVED_HELD" ] \ || die 3 "$1: \`scope remove\` retired these criteria, so scope cannot put them back. These orders still serve them, or these frozen tests still name them: $RW_REMOVED_HELD. Take each id out of each order with design \`update\`, or remove the order with design \`remove\` when no other criterion needs it. Close design and run \`start\`. Then \`drop\` a removed order, or \`redo\` a changed one. Then run \`finish\`." } # A criterion removed or put back since brief ran changes what the reviewer judged (gap row 498). # Without this, a removal after a failed close would flip the record with no fresh pass. $1 the action. rw_dropped_since_brief() { rw_dropped_criteria "$1" [ ! -f "$BRIEF_FILE" ] \ || [ "$(jq -c '[ (.droppedCriteria // [])[].id ]' "$BRIEF_FILE" 2>/dev/null)" = "$(printf '%s' "$RW_DROPPED" | jq -c '[ .[].id ]')" ] \ || rw_pass_moved "$1" "$ALIGNMENT_FILE removed a criterion or put one back since brief ran, so the reviewer judged another list." } # Every work order's ownedFiles, as one JSON array with duplicates removed. rw_owned_files() { printf '%s' "$RW_SNAPSHOT_DOC" | jq -c '[ (.workOrders // [])[] | (.ownedFiles // [])[] ] | unique' } # Every frozen test row, across every order's own tests-.json merged with its repairs' # records, as one JSON array, and every support file those records froze, with its sha256, as # another. The merge drops a test a later record replaced or retired, so a retired test no longer # counts (gap row 475). Walked with `find` and a while loop rather than a glob, so a task with no # frozen record at all reads as an empty list instead of a literal pattern. $1 the action. RW_TEST_ROWS="[]"; RW_TEST_SUPPORT="[]" rw_load_test_rows() { local who="$1" list one doc RW_TEST_ROWS='[]'; RW_TEST_SUPPORT='[]' list="$(find "$IMPL_DIR" -maxdepth 1 -type f -name 'tests-*.json' 2>/dev/null | sort)" while IFS= read -r one; do [ -n "$one" ] || continue case "$one" in *-repair-*.json) continue ;; esac one="$(basename "$one" .json)" tf_with_repair_tests "$who" "${one#tests-}" doc="$TF_REPAIR_TESTS_DOC" RW_TEST_ROWS="$(jq -nc --argjson have "$RW_TEST_ROWS" --argjson doc "$doc" \ '$have + [ ($doc.rows // [])[] | . + {unit: ($doc.unit // "")} ]')" RW_TEST_SUPPORT="$(jq -nc --argjson have "$RW_TEST_SUPPORT" --argjson doc "$doc" '$have + [ ($doc.support // [])[] | {path, sha256} ]')" done </dev/null)" [ -n "$code_state" ] || code_state="none" RV_PROJECT_FOLDER="$(resolve_project_folder "$TASK_PATH")" || RV_PROJECT_FOLDER="" if [ -n "$RV_PROJECT_FOLDER" ] && [ "$(json_file_state "$RV_PROJECT_FOLDER/project.json")" = "ok" ]; then RW_PROJECT_DOC="$(jq -c '.' "$RV_PROJECT_FOLDER/project.json")" frameworks_json="$(printf '%s' "$RW_PROJECT_DOC" | jq -c '.frameworks // []')" e2e_enabled="$(printf '%s' "$RW_PROJECT_DOC" | jq -r 'if (.surfaces // null) == null then "not-set-up" elif (.surfaces.e2e.enabled // false) then "on" else "off" end')" vr_enabled="$(printf '%s' "$RW_PROJECT_DOC" | jq -r 'if (.surfaces // null) == null then "not-set-up" elif (.surfaces.visualRegression.enabled // false) then "on" else "off" end')" # The recorded worktree when this task has one, the project's own code path otherwise, the # same tree the acceptance action joins a relative registryPath to (row 32 of # audit/14-live-run-gaps.md); read never makes a worktree, so it never calls rv_load_codepath. registry_path="$(sf_surface_path "$(printf '%s' "$RW_PROJECT_DOC" | jq -r '.surfaces.registryPath // ""')" \ "$([ "$code_state" != "none" ] && printf '%s' "$code_state" || printf '%s' "$RW_PROJECT_DOC" | jq -r '.codePath // ""')")" fi rw_load_record "read" report="$(jq -n \ --arg task "$(basename -- "$TASK_PATH")" \ --arg finished "$finished_state" --arg range "$range" --arg final "$final_commit" \ --arg runMode "$RW_RUN_MODE" \ --argjson machine "$machine_count" --argjson person "$person_count" \ --argjson checklistRows "$checklists_json" \ --argjson frameworks "$frameworks_json" \ --arg e2e "$e2e_enabled" --arg vr "$vr_enabled" --arg registry "$registry_path" \ --arg codePath "$code_state" \ --arg recordState "$record_state" --arg step "$(rw_step_now)" \ --argjson warnings "$(jq -c '.warnings // []' "$TASK_PATH/task.json" 2>/dev/null || printf '[]')" \ --slurpfile record "$([ -n "$RW_RECORD_DOC" ] && printf '%s' "$RECORD_FILE" || printf '/dev/null')" ' $record[0] as $record | {task: $task, finished: $finished, reviewedRange: $range, finalCommit: $final, runMode: $runMode, runModeSource: "task.json, for the review stage; the ledger keeps the mode the build ran under", criteria: {machineVerified: $machine, personVerified: $person, checklistRows: ($checklistRows | length)}, checklists: $checklistRows, frameworks: $frameworks, codePath: $codePath, surfaces: {e2e: $e2e, visualRegression: $vr, registryPath: $registry}, warnings: $warnings, record: ({state: $recordState} + (($record // {}) | {checks: ((.checks // []) | length), findings: ((.findings // []) | length), surfaces: ((.surfaces // []) | length), verdict: (.verdict // "")})), nextStep: $step}')" [ -n "$report" ] || die 3 "read: could not assemble the report for $TASK_PATH." printf '%s\n' "$report" if [ "$finished_state" != "ok" ]; then echo "READ: implementation has not finished for this task. There is no $FINISHED_FILE, so there is nothing to review yet." >&2 fi exit 0 } # ------------------------------------------------------------------------------------------------ # `checks`: the diff once, every command the recipes declare, and checks 3 to 8. # ------------------------------------------------------------------------------------------------ # The verdict a framework whose lookup failed contributes to every commanded check, and the line # that says so. Two words, kept apart on purpose: a framework with no recipe answered, and a # listing or a fetch that failed means nobody looked. Collapsing them writes a false finding # nothing can tell from a true one. Sets RW_LOOKUP_FLOOR and RW_LOOKUP_NOTE. RW_LOOKUP_FLOOR=""; RW_LOOKUP_NOTE="" # What a block the parser could not read contributes to every check that reads it. `unparseable` is # the heading being there while its key never opens under it, which is nobody having looked rather # than a framework that declared nothing, so the word is unknown, a warning at close. A block # that is simply absent stays undeclared, because a framework with no such block has answered. RW_CHECK_FLOOR=""; RW_TEST_FLOOR=""; RW_BLOCK_NOTE="" rw_lookup_floor() { local failures="$1" line fw reason RW_LOOKUP_FLOOR=""; RW_LOOKUP_NOTE="" while IFS= read -r line; do [ -n "$line" ] || continue fw="${line%% *}" reason="${line#* }" case "$reason" in no-recipe) [ -n "$RW_LOOKUP_FLOOR" ] || RW_LOOKUP_FLOOR="undeclared" RW_LOOKUP_NOTE="$RW_LOOKUP_NOTE $fw declares no recipe for this point." ;; *) RW_LOOKUP_FLOOR="unknown" RW_LOOKUP_NOTE="$RW_LOOKUP_NOTE Nobody looked for $fw's recipe ($reason)." ;; esac done </dev/null \ || RW_DIFF_BASE="$trunk_base" RW_CHANGED_JSON="$( { git -C "$RV_CODEPATH" diff --no-renames --name-only "$1" "$2" 2>/dev/null [ "$RW_DIFF_BASE" = "$1" ] || git -C "$RV_CODEPATH" diff --no-renames --name-only "$RW_DIFF_BASE" "$2" 2>/dev/null; } \ | jq -Rsc --argjson both "$([ "$RW_DIFF_BASE" = "$1" ] && echo 1 || echo 2)" \ 'split("\n") | map(select(length > 0)) | group_by(.) | map(select(length == $both) | .[0])')" [ -n "$RW_CHANGED_JSON" ] || RW_CHANGED_JSON='[]' RW_CHANGED_COUNT="$(printf '%s' "$RW_CHANGED_JSON" | jq 'length')" RW_PRESENT_JSON="$(git -C "$RV_CODEPATH" diff --no-renames --name-only --diff-filter=D "$1" "$2" 2>/dev/null \ | jq -Rsc --argjson changed "$RW_CHANGED_JSON" '(split("\n") | map(select(length > 0))) as $gone | $changed - $gone')" [ -n "$RW_PRESENT_JSON" ] || RW_PRESENT_JSON='[]' RW_PRESENT_COUNT="$(printf '%s' "$RW_PRESENT_JSON" | jq 'length')" } # One catalog note. Review writes nothing to the catalog: it records what it saw and names the count # at close, and a person decides whether a note becomes a proposal. rw_catalog_note() { RW_CATALOG_NOTES="$(jq -nc --argjson have "$RW_CATALOG_NOTES" --arg seen "$1" --arg where "$2" \ '$have + [{seen: $seen, where: $where}]')" } # One commanded row's own run, in one place. Four callers repeat the same ladder otherwise: the # temporary file, br_run_resolved, the two fields it prints, and the faults that decide nothing. # $1 the argv array, $2 the JSON array a {paths} or {file} token expands to, $3 the tab-separated # --value list, $4 the row's own `signal` or the empty string. # # Sets RW_RUN_KIND (UNRESOLVED, EMPTY or RAN), RW_RUN_PAYLOAD, RW_RUN_RC, RW_RUN_OUTPUT, # RW_RUN_STDOUT_LEN and RW_RUN_OUTFILE. A caller reads its own verdict off those, calls rw_run_fault # for the faults every caller words alike, and calls rw_run_done when it has finished with the file. RW_RUN_KIND=""; RW_RUN_PAYLOAD=""; RW_RUN_RC=""; RW_RUN_OUTPUT="" RW_RUN_STDOUT_LEN=0; RW_RUN_OUTFILE=""; RW_RUN_ERRFILE="" RW_RUN_VERDICT=""; RW_RUN_DETAIL="" # The seconds one tool row may run before it is stopped (BR_RUN_LIMIT in recipes.sh), so a tool # that hangs reads unknown instead of holding the review. RW_TOOL_LIMIT=600 # The surfaces a person accepted a baseline for and the accept rows that ran for them. Both are read # back after every kind has answered: a surface nothing accepted refuses, and a row that already # answered is not reported twice. RW_ACCEPTED_DONE=""; RW_ACCEPTED_ROWS="" rw_run_row() { local argv_json="$1" paths_json="$2" values="$3" signal="$4" result RW_RUN_KIND=""; RW_RUN_PAYLOAD=""; RW_RUN_RC=""; RW_RUN_OUTPUT=""; RW_RUN_STDOUT_LEN=0 RW_RUN_OUTFILE="$(mktemp)" || die 3 "a temporary file for the command's output could not be created" RW_RUN_ERRFILE="" if [ -n "$signal" ]; then RW_RUN_ERRFILE="$(mktemp)" || die 3 "a temporary file for the command's standard error could not be created" result="$(br_run_resolved "$argv_json" "$RV_CODEPATH" "$RW_RUN_OUTFILE" "$paths_json" "$values" "$RW_RUN_ERRFILE")" else result="$(br_run_resolved "$argv_json" "$RV_CODEPATH" "$RW_RUN_OUTFILE" "$paths_json" "$values")" fi RW_RUN_KIND="$(printf '%s' "$result" | cut -f1)" RW_RUN_PAYLOAD="$(printf '%s' "$result" | cut -f2-)" [ "$RW_RUN_KIND" = "RAN" ] || return 0 RW_RUN_RC="$RW_RUN_PAYLOAD" if [ -n "$signal" ]; then RW_RUN_STDOUT_LEN="$(wc -c <"$RW_RUN_OUTFILE" 2>/dev/null | tr -d '[:space:]')" case "$RW_RUN_STDOUT_LEN" in ''|*[!0-9]*) RW_RUN_STDOUT_LEN=0 ;; esac # The baseline joined the two streams the same way, standard output first, so the file a row # records and subtracts is the joined one. cat "$RW_RUN_ERRFILE" >>"$RW_RUN_OUTFILE" 2>/dev/null fi RW_RUN_OUTPUT="$(cat "$RW_RUN_OUTFILE" 2>/dev/null)" } rw_run_done() { [ -z "$RW_RUN_OUTFILE" ] || rm -f "$RW_RUN_OUTFILE" [ -z "$RW_RUN_ERRFILE" ] || rm -f "$RW_RUN_ERRFILE" RW_RUN_OUTFILE=""; RW_RUN_ERRFILE="" } # The verdict and the detail for a run that decided nothing, worded once for every caller: a # placeholder nothing supplied a value for, an argv with no token, a command that is not there, and # an argv list that came out empty. Sets RW_RUN_VERDICT and RW_RUN_DETAIL, and clears both when the # exit status is the caller's own to read. $1 the row's own label, $2 the framework of a # test-execution row or a check row, whose preconditions record may hold its tool as absent at the # end of the task (gap row 328), $3 the install advice for exit 127 when no recipe supplies one. rw_run_fault() { local label="$1" fw="${2:-}" said known install named rp RW_RUN_VERDICT=""; RW_RUN_DETAIL="" case "$RW_RUN_KIND" in UNRESOLVED) RW_RUN_VERDICT="unknown" RW_RUN_DETAIL="the token {$RW_RUN_PAYLOAD} in the $label command has no supplied value; pass --value $RW_RUN_PAYLOAD=." return 0 ;; EMPTY) RW_RUN_VERDICT="unknown" RW_RUN_DETAIL="the $label command came out with no token at all, so nothing ran and nothing was decided." return 0 ;; esac case "$RW_RUN_RC" in 124) [ -n "$BR_RUN_LIMIT" ] || return 0 RW_RUN_VERDICT="unknown" RW_RUN_DETAIL="the $label command ran past its time limit of $BR_RUN_LIMIT seconds and was stopped, so nothing was decided." ;; 127) RW_RUN_VERDICT="unknown" # A command not found is this project's install, not the recipe, so no catalog note is raised # (gap row 271). The shell's own line names the program it could not find. said="$(printf '%s\n' "$RW_RUN_OUTPUT" | grep -m1 '[^[:space:]]')" install="The tool it runs is not installed in this project: install it with the tool skill, as the recipe's setup says." [ -z "${3:-}" ] || install="$3" # A record with no requires_tooling result for the framework, neither a condition nor an # end-of-task tool, is one the tool check never ran on, as before 6.0.11 (gap row 284). It is # named, not repaired: running require here would run each tool, and a tool may reach a site. # The recipe the record names must list a tool, or there was nothing to check. known=""; named="" rp="$(jq -r --arg fw "$fw" '[ (.frameworks // [])[] | select(.framework == $fw) ][0].recipePath // empty' \ "$TASK_PATH/implementation/preconditions.json" 2>/dev/null)" [ -z "$rp" ] || [ ! -f "$rp" ] \ || named="$(recipe_requires_tooling_of "$rp" 2>/dev/null; recipe_requires_tooling_of "$rp" requires_tooling_with_tests 2>/dev/null)" [ -z "$fw" ] || known="$(jq -r --arg fw "$fw" --arg row "$label" --arg install "$install" --arg named "$named" '. as $d | [ (.frameworks // [])[] | select(.framework == $fw) ][0] as $f | [ ($f.endOfTaskToolsAbsent // [])[] | select((.rows // []) | index($row)) | .tool ] | if length > 0 then "Preconditions recorded \(join(", ")) absent on \($d.takenAt // "an earlier day"), before the build started, so this is known and not a fault this task introduced. Install it with the tool skill to run this row." elif $f != null and $named != "" and $f.verdict != "not-needed" and ($f.endOfTaskToolsAbsent // []) == [] and ([ ($f.entries // [])[] | select((.id // "") | startswith("requires_tooling")) ] | length) == 0 then $install + " The preconditions record of \($d.takenAt // "an earlier day") holds no result for the tools the test-execution recipe names under requires_tooling. So nothing checked those tools for this task, as with any record written before aida 6.0.11. To check them, run the tool skill'"'"'s require on \($f.recipePath // "the test-execution recipe")." else "" end' \ "$TASK_PATH/implementation/preconditions.json" 2>/dev/null)" RW_RUN_DETAIL="the $label command could not be found (exit 127), so nothing ran and nothing was decided. It printed: ${said:-nothing}. ${known:-$install}" ;; 126) RW_RUN_VERDICT="unknown" RW_RUN_DETAIL="the $label command was found and could not run (exit 126, permission denied), so nothing was decided. A script without the execute bit gives this." ;; esac } # The changed files `task environment up` recorded, still as it recorded them at the range end, as # one JSON array. Check 3 sets them aside (gap row 256). The brief names them to the purpose lens, # and findings records no purpose finding on one (gap row 469). Reads RW_RANGE and RW_CHANGED_JSON. rw_env_aside() { local one out='[]' while IFS= read -r one; do [ -n "$one" ] || continue task_env_recipe_change "$TASK_PATH" "$one" "$RV_CODEPATH" "${RW_RANGE##*..}" \ && out="$(printf '%s' "$out" | jq -c --arg p "$one" '. + [$p]')" done </dev/null | "${RECORDS_HASH_SHA256_CMD[@]}" | cut -d' ' -f1)" if printf '%s\n' "$frozen" | grep -qxF -- "$sha"; then support_aside="$support_aside$one, "; continue fi fi unmatched="$unmatched$one, " done </dev/null \ | sed -n 's/^unattributed: //p' | grep -vx none | paste -sd ';' - | sed 's/;/; /g')" [ -z "$hand" ] || aside_line="$aside_line These commits lie outside every order's records, so no order's review read them, and a person says whether each belongs: $hand." # Before gap row 334 a light run committed its compromises log on the task branch, at any stage, # so the whole branch from its fork point is read. The commit subject tells AIDA's log from a # project's own file of that name. A branch that no longer holds the file is repaired. local fork old_log="" fork="$(task_fork_point "$TASK_PATH" "$RV_CODEPATH")" if [ -n "$fork" ] && git -C "$RV_CODEPATH" cat-file -e "${RW_RANGE##*..}:$COMPROMISES_FILE" 2>/dev/null \ && git -C "$RV_CODEPATH" log --format=%s "$fork..${RW_RANGE##*..}" -- "$COMPROMISES_FILE" 2>/dev/null \ | grep -q '^Log a light-run compromise:'; then old_log=" $COMPROMISES_FILE on this branch is a compromises log an earlier AIDA committed. The log now lives in $TASK_PATH/$COMPROMISES_FILE: move its rows there, then remove the file from this branch." fi if [ -z "$unmatched" ] && [ -n "$old_log" ]; then rw_check_row "$CHECK_SERVES" "unmet" "every changed file in $RW_RANGE matches some order's own ownedFiles.$old_log$aside_line" elif [ -n "$unmatched" ]; then extra="$old_log$aside_line$(task_env_rerun_step "$TASK_PATH" "${unmatched%, }")" [ -z "$extra" ] || extra=".$extra" rw_check_row "$CHECK_SERVES" "unmet" "these changed files match no work order's own ownedFiles, so nothing in the design asked for them: ${unmatched%, }$extra" elif [ -n "$aside_line" ]; then rw_check_row "$CHECK_SERVES" "met" "every other changed file in $RW_RANGE matches some order's own ownedFiles.$aside_line" else rw_check_row "$CHECK_SERVES" "met" "every one of the $RW_CHANGED_COUNT changed files in $RW_RANGE matches some order's own ownedFiles." fi } # Check 4's script half: every criterion is covered by a frozen test naming it or by a checklist a # person reads. A criterion covered by neither was signed off on nothing. # # A criterion owned by an order whose proof is gate, record or observe is covered by the judgement # `close` wrote onto the ledger: from a gate order's configuration-gate check, or from the run # lines of a record or observe order. No test names such a criterion, and reading it as covered by # nothing said "each was signed off on nothing" about a criterion somebody had signed off # (live-run row 167). A look judges no machine criterion, so the observed record covers none. # # A criterion owned by an order whose proof is confirm is covered by the checklist rows `finish` # wrote from that order's done-when rows. The task has no automated tests, and the person answers # the criterion from those rows at close (gap row 196). rw_check_coverage_verdict() { local criteria count i cid covered uncovered="" judged_owner criteria="$(rw_alignment | jq -c '.criteria // []')" count="$(printf '%s' "$criteria" | jq 'length')" i=0; cid=""; covered=""; judged_owner="" while [ "$i" -lt "$count" ]; do cid="$(printf '%s' "$criteria" | jq -r --argjson i "$i" '.[$i].id')" covered="$(jq -nr --argjson rows "$RW_TEST_ROWS" --arg id "$cid" ' [ $rows[] | select(.criterion == $id) | select(((.kind == "machine") and (((.tests // []) | length) > 0)) or ((.kind == "person") and ((.checklist // "") != ""))) ] | length > 0')" if [ "$covered" != "true" ]; then covered="$(printf '%s' "$RW_FINISHED_DOC" | jq -r --arg id "$cid" '[ (.checklists // [])[] | select(.criterion == $id) ] | length > 0')" fi if [ "$covered" != "true" ]; then judged_owner="$(printf '%s' "$RW_SNAPSHOT_DOC" | jq -r --arg id "$cid" "$BR_ORDER_FACTS_JQ"' [ (.workOrders // [])[] | orderFacts.slot as $slot | select($slot == "configuration-gate" or $slot == "done-when" or $slot == "observed") | select((.criteriaOwned // []) | index($id) != null) | .id ][0] // ""')" [ -n "$judged_owner" ] \ && covered="$(jq -r --arg id "$cid" --arg unit "$judged_owner" ' [ (.criteria // [])[] | select(.id == $id) | (.judgements // [])[] | select(.unit == $unit) ] | length > 0' "$LEDGER_FILE" 2>/dev/null)" fi [ "$covered" = "true" ] || uncovered="$uncovered$cid, " i=$((i + 1)) done if [ "$count" -eq 0 ]; then printf 'unknown\tthe frozen contract holds no criterion, so there is nothing a test could cover.' return 0 fi if [ -n "$uncovered" ]; then printf 'unmet\tthese criteria are covered by no frozen test, no checklist row and no judgement on the ledger, so each was signed off on nothing: %s' "${uncovered%, }" else printf 'met\tevery one of the %s criteria carries a frozen test naming it, a checklist row a person reads, or the judgement its owning order left on the ledger.' "$count" fi } # The mutation row, run over the changed files. The score is the tool's own line, verbatim, never a # number parsed out of it. No key in a recipe row declares the shape a score is printed in, and the # tools print different shapes. No tool prints the word "score", so the line is chosen by the tool # the row names, from the shapes the catalog observed in each recipe's own `trap:`. Infection # prints `Metrics:` lines, gremlins a `Test efficacy:` line, and mutmut a count per outcome in the # last carriage-return segment that holds them (gap row 508). A survivor is a line of that output # naming one of the changed files, which is a string comparison and not a guess. mutmut prints none, # and its survivors are recorded as not readable rather than as none. # Sets RW_MUTATION. RW_MUTATION="" rw_run_mutation() { local fw_count fwi fw_obj fw row outfile rc tool has_paths stopped local detail output survivors score combined mut_file verdict=""; detail=""; output=""; survivors='[]'; score=""; combined=""; tool=""; has_paths=false # Mutation testing is opt in per project. The project skill's set-mutation writes the field, and # an absent field reads off, so check 4 is the coverage half alone and the command never runs. if [ "$(printf '%s' "$RW_PROJECT_DOC" | jq -r '.review.mutation // false')" != "true" ]; then RW_MUTATION="$(jq -n '{verdict: "undeclared", score: "", survivors: [], off: true, detail: "the project has not opted in to mutation testing: project.json sets no review.mutation, so the mutation command was not run. The project skill set-mutation turns it on."}')" return 0 fi # A task with no automated tests has no test for a mutant to fail, so the row does not apply and # the command never runs, the way the build reads its suite row (gap row 246). if [ "$(printf '%s' "$RW_SNAPSHOT_DOC" | jq -r "$BR_HARNESS_JQ noAutomatedTests")" = "true" ]; then RW_MUTATION="$(jq -n '{verdict: "undeclared", score: "", survivors: [], detail: "this task has no automated tests, so no test exists for a mutant to fail, and the mutation command was not run."}')" return 0 fi # The output of the last framework that ran, kept by file for the record (rw_check_row). mut_file="$(mktemp)" || die 3 "a temporary file for the mutation output could not be created" fw_count="$(printf '%s' "$CR_DOC" | jq '(.frameworks // []) | length')" case "$fw_count" in ''|*[!0-9]*) fw_count=0 ;; esac fwi=0 while [ "$fwi" -lt "$fw_count" ]; do fw_obj="$(printf '%s' "$CR_DOC" | jq -c --argjson i "$fwi" '.frameworks[$i]')" fw="$(printf '%s' "$fw_obj" | jq -r '.framework')" row="$(cr_row_command "$(printf '%s' "$fw_obj" | jq -c '.testCommandsRows // []')" "mutation" "mutation")" if [ "$(printf '%s' "$row" | jq -r 'has("argv")')" != "true" ]; then combined="$(rw_worse "$combined" "undeclared")" detail="$detail $fw: $(printf '%s' "$row" | jq -r '.absent // .missing')" fwi=$((fwi + 1)) continue fi # A path placeholder over zero changed files expands to zero arguments, and the tool then reads # that as its own default scope and mutates the whole repository. The survivors are matched # against zero file names, so nothing matches and the row reads met on exit 0: a full mutation # run paid for and a pass that proves nothing (live-run row 167). The tool rows answer this # same question above, and this row answers it the same way. has_paths=false br_argv_takes_paths "$(printf '%s' "$row" | jq -c '.argv')" && has_paths=true # A command with no path placeholder runs over the tool's own default scope on every review, # whatever the change, and nothing here can tie that scope to the change. `mutmut run` mutated a # whole package for three hours (gap row 400). So the row does not apply until the recipe states # a scoped form. Undeclared, the word an absent row reads, so no review blocks on the recipe. if [ "$has_paths" != "true" ]; then combined="$(rw_worse "$combined" "undeclared")" detail="$detail $fw: the mutation command of the test-execution recipe for $fw, \`$(printf '%s' "$row" | jq -r '.argv | join(" ")')\`, takes no changed-file path, so it would run over the tool's whole default scope and was not run. The row needs a scoped form." rw_catalog_note "the mutation command the recipe declares takes no changed-file path, so it cannot be scoped to a change" "the test-execution recipe for $fw" fwi=$((fwi + 1)) continue fi if [ "$RW_PRESENT_COUNT" -eq 0 ]; then if [ "$RW_COMMITS_IN_CODE" = "no" ]; then combined="$(rw_worse "$combined" "undeclared")" detail="$detail $fw: no order in this task commits in the code repository, so the mutation command has no changed file to run over and the row does not apply to it." else combined="$(rw_worse "$combined" "unknown")" detail="$detail $fw: the mutation command holds a path placeholder, and $RW_RANGE left no changed file in the tree, so the command would run over the whole repository and answer about code this task did not touch." fi fwi=$((fwi + 1)) continue fi rw_run_row "$(printf '%s' "$row" | jq -c '.argv')" "$RW_PRESENT_JSON" "$RW_VALUES" "" rw_run_fault "mutation" "$fw" if [ -n "$RW_RUN_VERDICT" ]; then combined="$(rw_worse "$combined" "$RW_RUN_VERDICT")" detail="$detail $fw: $RW_RUN_DETAIL" rw_run_done fwi=$((fwi + 1)) continue fi rc="$RW_RUN_RC" output="$RW_RUN_OUTPUT" outfile="$RW_RUN_OUTFILE" cat "$outfile" >"$mut_file" tool="" case "$(printf '%s' "$row" | jq -r '.argv | join(" ")')" in *infection*) tool="infection"; score="$(printf '%s' "$output" | grep -E 'MSI|Mutation Code Coverage')" ;; *gremlins*) tool="gremlins"; score="$(printf '%s' "$output" | grep 'Test efficacy:' | head -1)" ;; # A mutant's result line holds one outcome emoji, so the counts are the segment that holds both # the killed and the survived one. Bytes in the C locale, so no locale setting decides a match. *mutmut*) tool="mutmut"; score="$(printf '%s\n' "$output" | tr '\r' '\n' \ | LC_ALL=C grep -F "$(printf '\360\237\216\211')" | LC_ALL=C grep -F "$(printf '\360\237\231\201')" | tail -1)" ;; *) score="$(printf '%s' "$output" | grep -i 'score' | head -1)" ;; esac # Infection prints its score lines only once a mutant ran. Without them its last words, an error # or the paths it found no source in, name the files it was handed, and those lines are not # survivors (gap row 392). A mutmut run that draws no counts ran no mutant either (gap row 508). stopped="" if { [ "$tool" = "infection" ] || [ "$tool" = "mutmut" ]; } && [ -z "$score" ]; then stopped=" Its last line: $(pc_trim "$(printf '%s\n' "$output" | sed "s/$(printf '\033')\\[[0-9;]*m//g" | grep '[^[:space:]]' | tail -1)")" fi # The criterion a survivor belongs to, by exact path: the frozen test records say which test file # belongs to which criterion, and the frozen orders say which source file belongs to which order # and what that order serves. A survivor no path attaches is still recorded, because the # reviewer reads the whole list and a survivor nobody can attach is a fact rather than a finding. survivors="$(jq_files -Rn --argjson changed "$RW_CHANGED_JSON" --argjson rows "$RW_TEST_ROWS" \ --argjson orders "$(printf '%s' "$RW_SNAPSHOT_DOC" | jq -c '.workOrders // []')" \ --rawfile out "$outfile" ' [ ($out | split("\n"))[] | . as $line | ($changed[]) as $f | select($line | contains($f)) | {text: $line, file: $f, criterion: (([ $rows[] | select([ (.tests // [])[] | .path ] | index($f)) | .criterion ][0]) // ([ $orders[] | select((.ownedFiles // []) | index($f)) | ((.criteriaOwned // []) + (.criteriaServed // []))[] ][0]) // "")} ] | unique_by(.text)')" [ -n "$survivors" ] || survivors='[]' # `mutmut run` names no file, so a progress line naming a source file is not a survivor. The # survivors come from a second command, `mutmut results`, as dotted mutant names nothing here # maps to a path. So they are recorded as not readable. The row still reads met on exit 0: the # coverage half and the score with its survived count were read, and only the list was not # (references/checks.md, "A check answers unknown only when nothing it reads could be read"). [ "$tool" != "mutmut" ] || survivors='[]' [ -z "$stopped" ] || survivors='[]' if [ "$(printf '%s' "$survivors" | jq 'length')" -gt 0 ]; then combined="$(rw_worse "$combined" "unmet")" detail="$detail $fw: the mutation command reported $(printf '%s' "$survivors" | jq 'length') line(s) naming a changed file, and a surviving mutant is a test nothing can fail." elif [ "$rc" = "0" ] && [ "$tool" = "mutmut" ] && [ -z "$stopped" ]; then combined="$(rw_worse "$combined" "met")" detail="$detail $fw: mutmut run exited 0 and prints no survivor by file. The survivors come from mutmut results as dotted mutant names, which nothing here maps to a path, so they are recorded as not readable. The outcome counts are in the score." elif [ "$rc" = "0" ] && [ -n "$stopped" ]; then combined="$(rw_worse "$combined" "met")" detail="$detail $fw: the mutation command exited 0 and printed no score line, so no mutant ran over this change.$stopped" elif [ "$rc" = "0" ]; then combined="$(rw_worse "$combined" "met")" detail="$detail $fw: the mutation command exited 0 and named no changed file, so it reported no survivor in this change." else combined="$(rw_worse "$combined" "unknown")" if [ -n "$stopped" ]; then detail="$detail $fw: the mutation command exited $rc and printed no score line, so no mutant ran and no survivor was counted.$stopped" else detail="$detail $fw: the mutation command exited $rc and named no changed file, so nothing here can tell a failed run from a clean one." fi rw_catalog_note "the mutation command the recipe declares exited $rc" "the test-execution recipe for $fw" fi rw_run_done fwi=$((fwi + 1)) done [ -n "$combined" ] || { combined="undeclared"; detail=" no framework recipe was resolved, so no mutation row was read."; } combined="$(rw_worse "$combined" "$RW_LOOKUP_FLOOR")" combined="$(rw_worse "$combined" "$RW_TEST_FLOOR")" detail="$detail $RW_LOOKUP_NOTE $RW_BLOCK_NOTE" RW_MUTATION="$(jq -n --arg verdict "$combined" --arg detail "$(pc_trim "$detail")" \ --arg score "$score" --argjson survivors "$survivors" --rawfile output "$mut_file" ' {verdict: $verdict, detail: $detail, score: $score, survivors: $survivors} + (if $output == "" then {} else {output: $output} end)')" rm -f "$mut_file" } # One tool row from the check commands block, run over the changed files. Every row the recipe # declares is run, whatever its id. Prints the check row. # # The command, its `signal` and its `extensions` all come from the resolved recipe, never from a # flag: a caller retyping a row drops a key, and a dropped `signal` turns a tool that cannot fail by # exit status into a check that always passes. A failure is compared against the baseline step two # took, because a finding that predates this build is not this task's, and blocking on it blocks # every task forever. br_judge_tool_run decides it, the same rule the freeze's coding-standards run # applies. # # $2 `frozen` runs the row over the frozen tests alone and prints nothing when the change touched # none. The caller turns that row into a follow-up finding, never a check, so it blocks nothing. rw_tool_row_check() { local row="$1" only_frozen="${2:-}" row_id framework argv signal exts scoped scoped_count has_paths local frozen left_out left_note rc verdict detail new_json new_count row_id="$(printf '%s' "$row" | jq -r '.id')" framework="$(printf '%s' "$row" | jq -r '.framework // ""')" verdict=""; detail=""; rc=""; new_json="[]"; new_count=0 if [ "$(printf '%s' "$row" | jq -r '.absent // false')" = "true" ]; then rw_check_row "$row_id" "undeclared" "$(printf '%s' "$row" | jq -r '.absentReason // "the recipe declares this row absent"')" "" "" "$framework" "absent" return 0 fi if [ "$(printf '%s' "$row" | jq -r 'has("missing")')" = "true" ]; then rw_check_row "$row_id" "undeclared" "$(printf '%s' "$row" | jq -r '.missing')" "" "" "$framework" return 0 fi argv="$(printf '%s' "$row" | jq -c '.argv // []')" signal="$(printf '%s' "$row" | jq -r '.signal // ""')" exts="$(printf '%s' "$row" | jq -c 'if has("extensions") then .extensions else empty end')" has_paths=false br_argv_takes_paths "$argv" && has_paths=true # The frozen tests are the reference this stage judges against, and no role after the freeze may # write them. So they come out first. A # static analyser reads a test's guard as always true once the guarded code exists, and nobody # could repair that (gap row 270). The tests step ran the coding-standards row over them. frozen="$(br_frozen_test_paths "$RW_TEST_ROWS")" left_out="$(jq -cn --argjson changed "$RW_PRESENT_JSON" --argjson frozen "$frozen" \ '[ $changed[] | select(. as $p | $frozen | index($p) != null) ]')" scoped="$(jq -cn --argjson changed "$RW_PRESENT_JSON" --argjson frozen "$frozen" \ '[ $changed[] | select(. as $p | $frozen | index($p) == null) ]')" [ -z "$exts" ] || scoped="$(br_filter_extensions "$scoped" "$exts")" scoped_count="$(printf '%s' "$scoped" | jq 'length')" left_note="" [ "$has_paths" = "false" ] || [ "$left_out" = "[]" ] \ || left_note=" The frozen tests were left out: $(printf '%s' "$left_out" | jq -r 'join(", ")')." if [ "$only_frozen" = "frozen" ]; then scoped="$left_out" [ -z "$exts" ] || scoped="$(br_filter_extensions "$scoped" "$exts")" scoped_count="$(printf '%s' "$scoped" | jq 'length')" [ "$has_paths" = "true" ] && [ "$scoped_count" -gt 0 ] || return 0 left_note=" This run read the frozen tests alone: $(printf '%s' "$scoped" | jq -r 'join(", ")')." fi if [ "$has_paths" = "true" ] && [ "$RW_PRESENT_COUNT" -eq 0 ] && [ "$RW_OWNS_IN_CODE" = "no" ]; then # No order owns a file in the code repository, so no file this tool reads was ever going to be # here. Undeclared, never unknown: unknown failed a task that legitimately touched no code # (live-run row 167). rw_check_row "$row_id" "undeclared" "no order in this task owns a file in the code repository, so the $row_id command would read no file this task wrote, and the row does not apply to it." "" "" "$framework" return 0 fi if [ "$has_paths" = "true" ] && [ "$RW_PRESENT_COUNT" -eq 0 ]; then rw_check_row "$row_id" "unknown" "the $row_id command holds a path placeholder, and $RW_RANGE left no changed file in the tree, so the command would run over no path at all and answer about the whole repository." "" "" "$framework" return 0 fi if [ "$has_paths" = "true" ] && [ -n "$exts" ] && [ "$scoped_count" -eq 0 ]; then rw_check_row "$row_id" "undeclared" "the $row_id command reads only $(printf '%s' "$exts" | jq -r 'join(", ")'), and this change touches no file with one of those extensions outside its frozen tests, so the row does not apply to it.$left_note" "" "" "$framework" return 0 fi if [ "$has_paths" = "true" ] && [ "$scoped_count" -eq 0 ]; then rw_check_row "$row_id" "undeclared" "every file this change touches is a frozen test, so the row does not apply to it.$left_note" "" "" "$framework" return 0 fi [ "$only_frozen" = "frozen" ] || RW_TOOL_READ="yes" BR_RUN_LIMIT="$RW_TOOL_LIMIT" rw_run_row "$argv" "$scoped" "$RW_VALUES" "$signal" rw_run_fault "$row_id" "$framework" BR_RUN_LIMIT="" verdict="$RW_RUN_VERDICT"; detail="$RW_RUN_DETAIL" if [ -z "$verdict" ]; then rc="$RW_RUN_RC" # A command with no {paths} reads the whole repository, so no path list is handed over. br_judge_tool_run "$row_id" "$rc" "$signal" "$RW_RUN_STDOUT_LEN" "$RW_RUN_OUTFILE" "$BASELINE_FILE" \ "$([ "$has_paths" = "true" ] && printf '%s' "$scoped" || printf '[]')" "$RV_CODEPATH" "this task" verdict="$BR_SUB_VERDICT"; detail="$BR_SUB_DETAIL" new_json="$BR_SUB_NEW"; new_count="$BR_SUB_COUNT" fi verdict="$(rw_worse "$verdict" "$RW_LOOKUP_FLOOR")" verdict="$(rw_worse "$verdict" "$RW_CHECK_FLOOR")" detail="$detail$left_note $RW_LOOKUP_NOTE $RW_BLOCK_NOTE" rw_check_row "$row_id" "$verdict" "$(pc_trim "$detail")" "$rc" "$RW_RUN_OUTFILE" "$framework" "" "$new_json" "$new_count" rw_run_done } # Check 8: the whole suite, at the final commit. finish ran it once at this same commit (do_checks # refuses any other HEAD), so this row reads that result from finished.json and runs nothing (nyc # defect 18). finish refuses a test newly broken there, so its verdict is never unmet. It is met, # also when a person recorded each new failure as not caused by this task, undeclared or # not-needed. It can be unknown or warned, which finish records as a warning. The sidecar is # inlined, and the record names each framework's failure_line selector. rw_check_suite() { local finished_suite combined detail outfile selectors finished_suite="$(printf '%s' "$RW_FINISHED_DOC" | jq -c '.suite // {}')" combined="$(printf '%s' "$finished_suite" | jq -r '.verdict // "unknown"')" detail="finish ran the suite once at this commit: $(printf '%s' "$finished_suite" | jq -r '.detail // "finished.json holds no suite result"')" combined="$(rw_worse "$combined" "$RW_LOOKUP_FLOOR")" combined="$(rw_worse "$combined" "$RW_TEST_FLOOR")" detail="$detail $RW_LOOKUP_NOTE $RW_BLOCK_NOTE" outfile="$(printf '%s' "$finished_suite" | jq -r 'if .outputFile == null then "" else .outputFile end')" [ -z "$outfile" ] || outfile="$IMPL_DIR/$outfile" selectors="$(printf '%s' "$finished_suite" | jq -r '[ (.runs // [])[] | select(.failureLine != null) | .framework + ": " + .failureLine ] | join("\n")')" rw_check_row "$CHECK_SUITE" "$combined" "$(pc_trim "$detail")" \ "$(printf '%s' "$finished_suite" | jq -r '.exitCode // ""')" "${outfile:-/dev/null}" "" "" "[]" 0 "$selectors" } do_checks() { local task_arg="" recipes="" check_recipes="" failures="" values="" catalog_recipes="" local catalog_check_recipes="" local frameworks fw lookup recipes_json rows_file parts_file catalog stale local range base head_end head_now end_commit tab said restored past coverage cov_verdict cov_detail local mut_verdict tool_count ti one frozen_row frozen_findings mutation_file record_json today floor_id local upstream empty_range unread while [ "$#" -gt 0 ]; do cr_take_flag "checks" "--recipe=recipes --check-recipe=check_recipes --lookup-failed=failures --catalog-recipe=catalog_recipes --catalog-check-recipe=catalog_check_recipes --value=values" "$@" || { shift "$?"; continue; } case "$1" in -*) die 3 "checks: unrecognized argument: $1" ;; *) [ -z "$task_arg" ] || die 3 "checks: more than one task folder given" task_arg="$1"; shift ;; esac done rw_paths "checks" "$task_arg" rw_require_finished "checks" rw_require_frozen "checks" rv_load_codepath "checks" rw_load_project "checks" # The range is a claim about what the repository holds, and uncommitted work makes it a claim # about something else. `finish` refuses this way already, and this is that same refusal. br_require_clean_tree "checks" "$RV_CODEPATH" frameworks="$(printf '%s' "$RW_PROJECT_DOC" | jq -r '.frameworks // [] | .[]')" [ -n "$frameworks" ] \ || die 77 "checks: $RV_PROJECT_FOLDER/project.json is valid and records no framework, so no recipe can be chosen for this project. Exit 14 is the separate fact that the file is not valid JSON." # A framework nobody answered for either way is a caller that did not look. Guessing here would # turn a lookup nobody ran into a recipe that declared nothing. recipes_json='[]' lookup="" while IFS= read -r fw; do [ -n "$fw" ] || continue lookup="$(cr_lookup "$failures" "$fw")" if [ -n "$(cr_lookup "$recipes" "$fw")" ] || [ -n "$(cr_lookup "$check_recipes" "$fw")" ]; then [ -z "$lookup" ] \ || die 3 "checks: framework $fw was given both a recipe and a --lookup-failed ($lookup). One of the two is wrong, and nothing here may choose." lookup="resolved" fi [ -n "$lookup" ] \ || die 3 "checks: nothing was said about the recipes for framework $fw; pass --recipe and --check-recipe for it, or --lookup-failed with the reason its lookup failed." recipes_json="$(jq -nc --argjson have "$recipes_json" --arg fw "$fw" --arg lookup "$lookup" \ --arg test "$(cr_lookup "$recipes" "$fw")" --arg check "$(cr_lookup "$check_recipes" "$fw")" \ '$have + [{framework: $fw, testRecipe: $test, checkRecipe: $check, lookup: $lookup}]')" done </dev/null)"; then echo "CHECKS: $fit_file could not be read, so no recipe fit verdict was taken from it." >&2 continue fi [ -z "$fit_json" ] || rw_catalog_note "$fit_stage judged the recipe it followed does not fit this task: $(printf '%s' "$fit_json" | jq -r '.reason')" "$(printf '%s' "$fit_json" | jq -r '.path')" done </dev/null | sort) $TASK_PATH/design-closed.json RW_FIT # Gap row 300. A departure an order's review-record recorded not-applicable, because the task has # no automated tests, is a catalog note: nothing else shows a person an edited or deleted assertion. # The answer goes out raw, never through @tsv, which writes a backslash as two (gap row 387). local rv_file rv_ref rv_words while IFS= read -r rv_file; do case "$rv_file" in ""|*-findings.json) continue ;; esac while IFS="$(printf '\t')" read -r rv_ref rv_words; do [ -z "$rv_ref" ] || rw_catalog_note "review-record recorded the recipe not-applicable for $(basename "$rv_file" .json | sed 's/^review-//'), because the task has no automated tests; the reviewer answered departed: $rv_words" "$rv_ref" done </dev/null) RW_NA done </dev/null | sort) RW_REVIEWS # --- the change set, read and never derived ----------------------------------------------------- range="$(printf '%s' "$RW_FINISHED_DOC" | jq -r '.commitRange // ""')" case "$range" in *..*) ;; *) die 3 "checks: $FINISHED_FILE holds no usable commitRange ('$range'). That field is the change set, and review computes none of its own." ;; esac base="${range%%..*}" head_end="${range##*..}" git -C "$RV_CODEPATH" rev-parse --verify "$base^{commit}" >/dev/null 2>&1 \ || die 3 "checks: the commit $base, the left end of the range in $FINISHED_FILE, is not a commit in $RV_CODEPATH." git -C "$RV_CODEPATH" rev-parse --verify "$head_end^{commit}" >/dev/null 2>&1 \ || die 3 "checks: the commit $head_end, the right end of the range in $FINISHED_FILE, is not a commit in $RV_CODEPATH." head_now="$(git -C "$RV_CODEPATH" rev-parse HEAD 2>/dev/null)" [ -n "$head_now" ] \ || die 3 "checks: could not capture the current commit (git rev-parse HEAD failed in $RV_CODEPATH)." end_commit="$(git -C "$RV_CODEPATH" rev-parse "$head_end^{commit}" 2>/dev/null)" # Gap row 325. Before a merge, the files `task environment up` changed go back to their fork point # content, by completion or by a person first. A head past the range by that restore alone holds # the same task code. So git decides: the head descends from the range end, and every file changed # since then is one task_env_restore_commit reads as back. When one of them is a file the fork # point has, the check rows' site commands can reach the main checkout's site, so checks refuses. if [ "$head_now" != "$end_commit" ]; then tab="$(printf '\t')" said="$(task_env_restore_commit "$TASK_PATH" "$RV_CODEPATH")" \ && die 3 "checks: $RV_CODEPATH holds the files \`task environment up\` changed at their content where the branch started: ${said#*"$tab"}. A site command a check row runs now can reach the main checkout's site through the name that content puts back. Nothing was written. Run git revert ${said%%"$tab"*} in $RV_CODEPATH, run checks again, and put the files back after the review." restored="$(printf '%s' "${said#*"$tab"}" | awk '{ gsub(/, /, "\n"); print }')" past="$(git -C "$RV_CODEPATH" diff --no-renames --name-only "$end_commit" HEAD 2>/dev/null \ | grep -vxF -- "$restored")" git -C "$RV_CODEPATH" merge-base --is-ancestor "$end_commit" HEAD 2>/dev/null && [ -z "$past" ] \ || die 3 "checks: $RV_CODEPATH is at $head_now, and the range in $FINISHED_FILE ends at $head_end. Checks 5 to 8 run over the files on disk, so a tree that is not the final commit would answer about different code than the diff describes. Only a commit that puts back the files \`task environment up\` changed may follow the range. Check that commit out, or run the implement skill's finish step again." fi RW_RANGE="$range" # Exit 124. build-record and fix-record hash only their own order's frozen files, and check 3 # passes a changed file an order owns, test files included. So a test edited after its order's # last record reached review unchecked (gap row 390). Every order's frozen files are hashed # again here, before anything is written. The tree is clean and holds the range's end, so the # files on disk are that commit's. A repair's record holds a test it froze again to its newer # hash, so each order is read with its repairs (gap row 449). rw_load_test_rows "checks" records_hash__resolve_sha256_cmd \ || die 3 "checks: neither sha256sum nor 'shasum -a 256' was found on PATH" local tests_rec tests_doc frozen_changed="" tests_unit while IFS= read -r tests_rec; do [ -n "$tests_rec" ] || continue case "$tests_rec" in *-repair-*.json) continue ;; esac tests_unit="$(basename "$tests_rec" .json)" tf_with_repair_tests "checks" "${tests_unit#tests-}" tests_doc="$TF_REPAIR_TESTS_DOC" tf_frozen_changed "$tests_doc" "$RV_CODEPATH" [ -z "$TF_FROZEN_CHANGED" ] || frozen_changed="$frozen_changed$(printf '%s' "$tests_doc" \ | jq -r '"\(.unit), frozen at \(.commit)"'): ${TF_FROZEN_CHANGED%, }; " done </dev/null | sort) RW_TESTS_RECORDS [ -z "$frozen_changed" ] \ || die 124 "checks: these frozen test or support files no longer match the hash their order's freeze recorded: ${frozen_changed%; }. Nobody changes a frozen test, so review stops here. Nothing was written. A person puts each file back as its freeze commit holds it, commits that, and runs finish and review again. The main session may not write a frozen file." # A task marked complete by hand before its review is reviewed as it stands. Review moves no # task state, so the task stays complete and close names no completion (gap row 324). [ "$RW_TASK_STATE" = complete ] \ || mark_task_in_progress "$TASK_PATH" "review started" review mkdir -p "$REVIEW_DIR" || die 3 "checks: could not create $REVIEW_DIR" rw_load_changed "$base" "$head_end" if [ "$RW_DIFF_BASE" = "$base" ]; then git -C "$RV_CODEPATH" diff --no-renames "$base" "$head_end" >"$DIFF_FILE" 2>/dev/null elif [ "$RW_CHANGED_COUNT" -eq 0 ]; then : >"$DIFF_FILE" else printf '%s' "$RW_CHANGED_JSON" | jq -r '.[]' | tr '\n' '\0' \ | xargs -0 git -C "$RV_CODEPATH" diff --no-renames "$RW_DIFF_BASE" "$head_end" -- >"$DIFF_FILE" 2>/dev/null fi || die 3 "checks: could not write the diff for $range to $DIFF_FILE" empty_range="no" [ "$base" = "$head_end" ] && empty_range="yes" upstream="$(git -C "$RV_CODEPATH" rev-parse --abbrev-ref --symbolic-full-name '@{upstream}' 2>/dev/null)" # --- the checks a script decides ---------------------------------------------------------------- parts_file="$(mktemp)" || die 3 "checks: could not create a temporary file" rw_check_serves >>"$parts_file" coverage="$(rw_check_coverage_verdict)" cov_verdict="$(printf '%s' "$coverage" | cut -f1)" cov_detail="$(printf '%s' "$coverage" | cut -f2-)" rw_run_mutation mut_verdict="$(printf '%s' "$RW_MUTATION" | jq -r '.verdict')" rw_check_row "$CHECK_TEST_MUTATION" "$(rw_worse "$cov_verdict" "$mut_verdict")" \ "$cov_detail The mutation row: $(printf '%s' "$RW_MUTATION" | jq -r '.detail')" >>"$parts_file" tool_count="$(printf '%s' "$CR_DOC" | jq '(.tools // []) | length')" case "$tool_count" in ''|*[!0-9]*) tool_count=0 ;; esac ti=0; one=""; frozen_row=""; frozen_findings="[]"; RW_TOOL_READ="" while [ "$ti" -lt "$tool_count" ]; do one="$(printf '%s' "$CR_DOC" | jq -c --argjson i "$ti" '.tools[$i]')" rw_tool_row_check "$one" >>"$parts_file" # The project's own analyser runs its test rules over the tests after the merge. So the frozen # tests get one more static-analysis run here, and a finding goes to completion as a follow-up # for the test author (gap row 270). if [ "$(printf '%s' "$one" | jq -r '.id')" = "static-analysis" ]; then frozen_row="$(rw_tool_row_check "$one" frozen)" [ -z "$frozen_row" ] || frozen_findings="$(jq -nc --argjson have "$frozen_findings" --argjson r "$frozen_row" ' if ($r.verdict == "unmet" or $r.verdict == "unknown") then $have + [{id: "f1", lens: "frozen-tests", severity: "low", file: "", lines: "", linkedTo: "", disposition: "follow-up", evidence: ($r.detail + (if (($r.newLines // []) | length) > 0 then "\n" + ($r.newLines | join("\n")) else "\n" + (($r.output // "") | .[-2000:]) end))}] else $have end')" fi ti=$((ti + 1)) done # Gap row 353. When no tool row read a file this change touched, every tool row reads undeclared, # and those words hide that no tool checked the change at all. One catalog note names the files. unread="$(jq -cn --argjson changed "$RW_PRESENT_JSON" --argjson frozen "$(br_frozen_test_paths "$RW_TEST_ROWS")" \ '[ $changed[] | select(. as $p | $frozen | index($p) == null) ]')" if [ -z "$RW_TOOL_READ" ] && [ "$unread" != "[]" ]; then rw_catalog_note "no check commands row reads a file this change touched, so no tool checked $(printf '%s' "$unread" | jq -r '.[0:10] | join(", ")')$(printf '%s' "$unread" | jq -r 'if length > 10 then " and \(length - 10) more" else "" end'). A project adds a tool for these files as a row with its own id and extensions in its own copy of the review recipe, and a task past preconditions adopts that copy with implement-actions.sh recipe-refresh --check-recipe." \ "$(printf '%s' "$CR_DOC" | jq -r '[ (.frameworks // [])[] | select(.checkRecipe != "") | .checkRecipe ] | if length == 0 then "no check recipe was resolved" else join(", ") end')" fi # The three ids below are a floor the recipe may add to and never a list it may shorten, so each one # no row declared still gets a row of its own. A check with no row at all is a check a reader cannot # see was never answered, and version 5 printed that four times. for floor_id in coding-standards static-analysis security; do if [ "$(printf '%s' "$CR_DOC" | jq --arg id "$floor_id" '[ (.tools // [])[] | select(.id == $id) ] | length')" -eq 0 ]; then rw_check_row "$floor_id" \ "$(rw_worse "$(rw_worse "undeclared" "$RW_LOOKUP_FLOOR")" "$RW_CHECK_FLOOR")" \ "$(pc_trim "no resolved review recipe carries a check commands row with this id, so this tool did not run. The three tool ids are a floor, never a list a recipe may shorten. $RW_LOOKUP_NOTE $RW_BLOCK_NOTE")" >>"$parts_file" fi done rw_check_suite >>"$parts_file" # A re-review archives the record the previous pass closed before anything is written. rw_load_record "checks" rw_archive_closed_record "checks" # The rows and the mutation object carry whole outputs, so both reach the record by file. mutation_file="$(mktemp)" || die 3 "checks: could not create a temporary file" printf '%s' "$RW_MUTATION" >"$mutation_file" today="$(date -u +%Y-%m-%d)" record_json="$(jq -n --arg takenAt "$today" --arg task "$RW_TASK_ID" \ --arg range "$range" --arg commit "$head_now" --arg runMode "$RW_RUN_MODE" \ --argjson hasUpstream "$([ -n "$upstream" ] && echo true || echo false)" \ --argjson recipes "$recipes_json" --slurpfile checks "$parts_file" \ --arg serves "$CHECK_SERVES" --arg testMutation "$CHECK_TEST_MUTATION" \ --argjson resolved "$CR_DOC" \ --slurpfile mutation "$mutation_file" --argjson notes "$RW_CATALOG_NOTES" \ --argjson frozenFindings "$frozen_findings" ' $mutation[0] as $mutation | {schemaVersion: 1, takenAt: $takenAt, task: $task, reviewedRange: $range, reviewedAt: $commit, hasUpstream: $hasUpstream, runMode: $runMode, # The sha of each recipe this run read sits beside its path, the way the baseline records its # own, so a reader can compare the two files rather than take a refusal'"'"'s word for it. recipes: [ $recipes[] | . as $row | ([ ($resolved.frameworks // [])[] | select(.framework == $row.framework) ][0]) as $fw | $row + {checkRecipeSha256: ($fw.checkRecipeSha256 // ""), testRecipeSha256: ($fw.testRecipeSha256 // "")} ], # Checks 3 and 4 keep their script half apart, so findings applies its lens half to the # script half every time it runs, and never to an earlier lens reading (gap row 277). checks: [ $checks[] | if .id == $serves or .id == $testMutation then .scriptHalf = {verdict, detail} else . end ], criteria: [], findings: $frozenFindings, surfaces: [], mutation: $mutation, catalogNotes: $notes}')" rm -f "$parts_file" "$mutation_file" [ -n "$record_json" ] || die 3 "checks: could not assemble the review record for $RW_TASK_ID." rw_write_record "checks" "$record_json" rw_print_summary "$record_json" "checks" printf 'changedFiles: %s\n' "$RW_CHANGED_COUNT" printf 'diff: %s\n' "$DIFF_FILE" echo "CHECKS: the diff for $range is at $DIFF_FILE ($RW_CHANGED_COUNT changed files)." >&2 if [ "$empty_range" = "yes" ]; then echo "CHECKS: the range $range holds no commit. It resolved, and the two ends are the same commit, so this task committed nothing." >&2 fi if [ -z "$upstream" ]; then echo "CHECKS: the branch checked out in $RV_CODEPATH has no upstream, so this work is on one machine only." >&2 fi [ -z "$RW_LOOKUP_NOTE" ] || echo "CHECKS: $RW_LOOKUP_NOTE" >&2 exit 0 } # ------------------------------------------------------------------------------------------------ # `brief`: everything the architecture reviewer may see, and nothing else. # ------------------------------------------------------------------------------------------------ do_brief() { [ "$#" -ge 1 ] || die 3 "brief: a task folder is required" [ "$#" -le 1 ] || die 3 "brief: unrecognized extra argument: $2" rw_paths "brief" "$1" rw_require_finished "brief" rw_require_frozen "brief" # The reviewer reads the code at the final commit where a lens needs more than the diff, so the # brief names the repository it may read. rv_load_codepath "brief" rw_refuse_changed_criteria "brief" rw_load_record "brief" rw_require_step "brief" "$CHECK_SERVES" "checks" rw_load_absence_clauses "brief" RW_RANGE="$(printf '%s' "$RW_RECORD_DOC" | jq -r '.reviewedRange')" rw_load_changed "${RW_RANGE%%..*}" "${RW_RANGE##*..}" local research_json list one doc brief_json research_json='[]' list="$(find "$TASK_PATH/research" -maxdepth 1 -type f -name '*.json' 2>/dev/null | sort)" while IFS= read -r one; do [ -n "$one" ] || continue doc="$(jq -c '.' "$one" 2>/dev/null)" [ -n "$doc" ] \ || die 3 "brief: $one exists but could not be read as JSON. Repair or remove it by hand before running this again." research_json="$(jq_files -nc --argjson have "$research_json" --argjson doc "$doc" --arg file "$one" ' $have + [{file: $file, search: ($doc.search // ""), searchedFor: ($doc.searchedFor // ""), findings: [ ($doc.findings // [])[] | {text, source, lookedAt, criteriaServed: (.criteriaServed // [])} ]}]')" done <#, counted from 1; findings reads these and never recounts them. local practice_json practice_json="$(printf '%s' "$research_json" | jq -c --arg ps "$PRACTICE_SEARCH" ' [ .[] | select(.search == $ps) ][0] | if . == null then null else ([ .findings | to_entries[] | select((.value.urls | length) > 0) | select((.value.text + " " + .value.source) | test("fetch-failed|searched and empty") | not) | "\($ps)#\(.key + 1)" ]) as $refs | {file, findings: (.findings | length), sourced: ($refs | length), sourcedRefs: $refs} end')" # The guide bodies design opened. Research names a guide and never opens it, so design's read # is the only record of a guide body, and the guides lens opens these (live-run row 272). local guide_bodies='[]' guide_path if [ -f "$TASK_PATH/design-guides-read.json" ]; then while IFS= read -r guide_path; do [ -n "$guide_path" ] || continue guide_bodies="$(jq -nc --argjson have "$guide_bodies" --arg p "$guide_path" \ --arg name "$(jq -r --arg p "$guide_path" '[ (.guides // [])[] | select(.path == $p) | (.name // "") ][0]' "$TASK_PATH/design-guides-read.json")" \ --argjson on "$([ -f "$guide_path" ] && echo true || echo false)" \ '$have + [{path: $p, name: $name, onDisk: $on}]')" done </dev/null) RW_GUIDES fi brief_json="$(jq_files -n --arg task "$RW_TASK_ID" --arg diff "$DIFF_FILE" \ --arg findings "$FINDINGS_TARGET" --arg codePath "$RV_CODEPATH" \ --argjson alignment "$(rw_alignment)" --argjson snap "$RW_SNAPSHOT_DOC" --argjson droppedCriteria "$RW_DROPPED" \ --argjson changes "$(rw_person_changes)" \ --slurpfile record "$RECORD_FILE" --argjson research "$research_json" \ --argjson guideBodies "$guide_bodies" --argjson practiceSearch "$practice_json" \ --argjson finished "$RW_FINISHED_DOC" --arg lenses "$LENS_WORDS" \ --argjson absenceClauses "$RW_ABSENCE_CLAUSES" --argjson setAside "$(rw_env_aside)" \ --argjson playbooksPath "$(playbooks_path_json "$TASK_PATH")" "$REASONING_JQ"' $record[0] as $record | [ $changes[] | select(.kind == "non-goal") | del(.kind) ] as $nonGoalChanges | [ $changes[] | select(.kind == "criterion") | del(.kind) ] as $criterionChanges | {task: $task, setAside: $setAside, codePath: $codePath, playbooksPath: $playbooksPath, reviewedRange: $record.reviewedRange, reviewedAt: $record.reviewedAt, runMode: $record.runMode, diffPath: $diff, findingsPath: $findings, lenses: ($lenses | split(" ")), criteria: [ ($alignment.criteria // [])[] | select(.id as $i | [ $droppedCriteria[].id ] | index($i) | not) | . as $k | .text = ([ $criterionChanges[] | select(.id == $k.id) | .live ][0] // .text) | {id, text, verification, verifiedBy} ], criterionChanges: $criterionChanges, droppedCriteria: $droppedCriteria, nonGoals: ([ ($alignment.nonGoals // [])[] | . as $n | ([ $nonGoalChanges[] | select(.id == $n.id) ][0]) as $c | if $c == null then $n elif $c.live == null then empty else $n | .text = $c.live end ] + [ $nonGoalChanges[] | select(.frozen == null) | {id, text: .live} ]), nonGoalChanges: $nonGoalChanges, workOrders: [ ($snap.workOrders // [])[] | .reasoning = liveReasoning ], absenceClauses: $absenceClauses, research: $research, guideBodies: $guideBodies, practiceSearch: $practiceSearch, deferredFindings: ($finished.deferred // []), pendingDecisions: ($finished.pendingDecisions // []), droppedOrders: ($finished.dropped // []), checks: [ ($record.checks // [])[] | select(.id != "serves-a-criterion") | {id, verdict, detail, framework: (.framework // ""), output: (.output // "")} ], mutation: $record.mutation}')" [ -n "$brief_json" ] || die 3 "brief: could not assemble the brief for $RW_TASK_ID." mkdir -p "$REVIEW_DIR" || die 3 "brief: could not create $REVIEW_DIR" # The brief is a file the dispatch names, never text printed through this conversation: it carries # the contract, every order and every research finding, and printing it would spend the reviewer's # own context twice over. # A findings file already at the path is an earlier reviewer's, from a pass re-run before its # verdict, and the reviewer this brief serves must not start from it (gap row 276). rw_archive_files "brief" "$(rw_record_short)" "$FINDINGS_TARGET" write_atomic "$BRIEF_FILE" "$brief_json" printf '%s' "$brief_json" | jq -r --arg brief "$BRIEF_FILE" --arg findings "$FINDINGS_TARGET" \ --arg diff "$DIFF_FILE" --arg code "$RV_CODEPATH" ' def line($k; $v): "\($k): \($v)"; [ line("action"; "brief"), line("brief"; $brief), line("findingsPath"; $findings), line("diff"; $diff), line("codePath"; $code), line("criteria"; (.criteria | length)), line("nonGoals"; (.nonGoals | length)), line("nonGoalChanges"; ([ .nonGoalChanges[].id ] | if length == 0 then "none" else join(" ") end)), line("workOrders"; (.workOrders | length)), line("absenceClauses"; (.absenceClauses | length)), line("lenses"; (.lenses | join(" "))), line("playbooksPath"; (.playbooksPath // "none: records/playbooks.json is absent")), line("researchFiles"; (.research | length)), line("researchPaths(onDisk)"; ([ .research[].findings[].paths[] | select(.onDisk) | .path ] | unique | length)), line("researchPaths(notOnDisk)"; ([ .research[].findings[].paths[] | select(.onDisk | not) | .path ] | unique | length)), line("researchUrls"; ([ .research[].findings[].urls[] ] | unique | length)), line("guideBodies(onDisk)"; ([ .guideBodies[] | select(.onDisk) ] | length)), line("guideBodies(notOnDisk)"; ([ .guideBodies[] | select(.onDisk | not) ] | length)), line("practiceSearch"; (if .practiceSearch == null then "none" else "\(.practiceSearch.sourced) sourced finding(s) in \(.practiceSearch.file)" end)), line("deferredFindings"; (.deferredFindings | length)), line("pendingDecisions"; (.pendingDecisions | length)), line("droppedOrders"; ([ .droppedOrders[] | .id ] | if length == 0 then "none" else join(" ") end)), line("droppedCriteria"; ([ .droppedCriteria[].id ] | if length == 0 then "none" else join(" ") end)) ] | .[]' printf '%s' "$brief_json" | jq -r '[ .nonGoalChanges[].id, .criterionChanges[].id ] | select(length > 0) | "BRIEF: the live contract changed these non-goals and criteria after the freeze: \(join(" ")). The brief carries the live text. close gives no verdict until a person accepts or rejects each change."' >&2 local skip_reason skip_reason="$(rw_reviewer_skip_reason)" if [ -n "$skip_reason" ]; then printf 'reviewer: skip | %s\n' "$skip_reason" echo "BRIEF: do not dispatch the reviewer. Run findings with no --findings; the record keeps the reason." >&2 else # No guide body on disk and no practice search yet: the review looks before the reviewer runs, # since a missing guide is a reason to look, never to skip the check (gap row 364). A task with # no commit in the code repository reads both checks undeclared whatever was found, so it waits # for nothing. if [ "$practice_json" = "null" ] && [ "$RW_COMMITS_IN_CODE" = "yes" ] \ && [ "$(printf '%s' "$guide_bodies" | jq '[ .[] | select(.onDisk) ] | length')" = "0" ]; then printf 'practice-search: dispatch\n' printf 'reviewer: wait | practice search first\n' echo "BRIEF: no guide body is on disk. Dispatch outward-searcher for current practice, record each finding with research-actions.sh record --search $PRACTICE_SEARCH, then run brief again. Do not dispatch the reviewer on this brief." >&2 else printf 'reviewer: dispatch\n' echo "BRIEF: give the reviewer $BRIEF_FILE, and tell it to write its findings to $FINDINGS_TARGET and nowhere else." >&2 fi fi exit 0 } # ------------------------------------------------------------------------------------------------ # `findings`: what the reviewer found, and the six checks that read their verdict off a lens. # ------------------------------------------------------------------------------------------------ # The check each lens answers. One word in, one check id out, and nothing else maps the two. rw_check_for_lens() { case "$1" in non-goals) printf 'non-goals' ;; solid) printf 'solid' ;; dry) printf 'dry' ;; architecture) printf 'architecture-fit' ;; guides) printf 'guides' ;; practices) printf 'framework-practices' ;; mutation) printf 'test-and-mutation' ;; purpose) printf 'serves-a-criterion' ;; *) printf '' ;; esac } # The findings one lens raised, as one line. A purpose finding keeps its file and lines, because # check 3's script half cites files alone. $1 the lens, $2 the findings array. rw_lens_hits() { printf '%s' "$2" | jq -r --arg l "$1" '[ .[] | select(.lens == $l) | (.id + " (" + .severity + ")" + (if $l == "purpose" then " at " + .file + ":" + .lines else "" end) + " cites " + (if .linkedTo == "" then "nothing" else .linkedTo end) + (if has("ruling") then ", ruled " + .ruling + " by the person" else "" end)) ] | join(", ")' } # One lens's reading of its check, as one check row, or nothing when the lens raised no finding. # A medium or high finding reads unmet. Only low findings read met: they stay follow-up, and # completion offers each as a task. A finding a person ruled at close counts as low here, because # the person already answered it (gap row 329). A finding ruled fix counts as unmet whatever its # severity, because the person wants it fixed in this task (gap row 479). $1 the lens, $2 the # check id, $3 the findings array. rw_lens_row() { local lens_word="$1" check_id="$2" hits low_only hits="$(rw_lens_hits "$lens_word" "$3")" [ -n "$hits" ] || return 0 low_only="$(printf '%s' "$3" | jq -r --arg l "$lens_word" '[ .[] | select(.lens == $l) | select((has("ruling") | not) or .ruling == "fix") | if .ruling == "fix" then "fix" else .severity end ] | all(. == "low")')" if [ "$low_only" = "true" ]; then rw_check_row "$check_id" "met" "every finding the $lens_word lens raised is low or ruled by the person, so each stays follow-up: $hits." else rw_check_row "$check_id" "unmet" "the $lens_word lens raised these findings: $hits" fi } # The mutation lens is check 4's other half and the purpose lens is check 3's, each one more # reading of the same check, never a check of its own. On a met script half the lens decides, by # the same reading as the six lens checks (gap row 277). Otherwise the script half decides, and a # medium or high finding still turns a script half that could not look into unmet. The detail # names the half that decided, and an unmet check never carries the met half's sentence. # $1 the record, $2 mutation or purpose. Prints the record with that check read again. rw_lens_with_half() { local check_id lens_row lens_hits findings check_id="$(rw_check_for_lens "$2")" findings="$(printf '%s' "$1" | jq -c '.findings // []')" lens_row="$(rw_lens_row "$2" "$check_id" "$findings")" [ -n "$lens_row" ] || lens_row="null" lens_hits="$(rw_lens_hits "$2" "$findings")" printf '%s' "$1" | jq -c --argjson r "$lens_row" --arg id "$check_id" --arg l "$2" --arg hits "$lens_hits" ' .checks = [ .checks[] | if .id != $id then . else .scriptHalf as $s | del(.answeredBy) | .verdict = $s.verdict | .detail = $s.detail | if $r == null then . elif .verdict == "met" then . + $r | .detail = "the script half read met, so the \($l) lens decides this check: \($r.detail)" elif .verdict == "unmet" then .detail += " The script half decides this check. The \($l) lens also raised \($hits)." elif $r.verdict == "unmet" then .verdict = "unmet" | .detail += " The \($l) lens decides this check: \($r.detail)." else .detail += " The \($l) lens raised only low findings, which stay follow-up: \($hits)." end end ]' } do_findings() { local task_arg="" findings_path="" while [ "$#" -gt 0 ]; do case "$1" in --findings) [ "$#" -ge 2 ] || die 3 "findings: --findings needs a path to the file the reviewer wrote" looks_like_flag "$2" && die 3 "findings: --findings was given another flag, not a path: $2" findings_path="$2"; shift 2 ;; -*) die 3 "findings: unrecognized argument: $1" ;; *) [ -z "$task_arg" ] || die 3 "findings: more than one task folder given" task_arg="$1"; shift ;; esac done [ -n "$task_arg" ] || die 3 "findings: a task folder is required" rw_paths "findings" "$task_arg" rw_require_finished "findings" rw_require_frozen "findings" rv_load_codepath "findings" rw_load_project "findings" rw_load_record "findings" rw_require_step "findings" "$CHECK_SERVES" "checks" rw_refuse_moved_code "findings" "clean" rw_load_absence_clauses "findings" # A findings file given is read, even where the dispatch could be skipped. With none, the skip # reason is the one thing that stands in for it. local skip_reason="" [ -n "$findings_path" ] || skip_reason="$(rw_reviewer_skip_reason)" [ -n "$findings_path" ] || [ -n "$skip_reason" ] \ || die 3 "findings: --findings is required. An absent findings file is never a clean review." # A practice finding recorded after brief ran is one the reviewer never saw (gap row 364). local practice_disk practice_brief practice_disk="none" [ ! -f "$TASK_PATH/research/$PRACTICE_SEARCH.json" ] \ || practice_disk="$(jq -r '(.findings // []) | length' "$TASK_PATH/research/$PRACTICE_SEARCH.json" 2>/dev/null)" if [ -f "$BRIEF_FILE" ]; then practice_brief="$(jq -r '.practiceSearch.findings // "none"' "$BRIEF_FILE" 2>/dev/null)" [ "$practice_disk" = "$practice_brief" ] \ || rw_pass_moved "findings" "$TASK_PATH/research/$PRACTICE_SEARCH.json holds $practice_disk finding(s), and the brief the reviewer read holds $practice_brief, so the reviewer did not see them." fi # A text changed after brief ran is one the reviewer never judged (gap rows 410 and 506). rw_dropped_since_brief "findings" local person_changes person_changes="$(rw_person_changes)" [ ! -f "$BRIEF_FILE" ] \ || [ "$(jq -c '[ (.nonGoalChanges // []), (.criterionChanges // []) ]' "$BRIEF_FILE" 2>/dev/null)" \ = "$(printf '%s' "$person_changes" | jq -c '[ ("non-goal", "criterion") as $k | [ .[] | select(.kind == $k) | del(.kind) ] ]')" ] \ || rw_pass_moved "findings" "$ALIGNMENT_FILE changed a non-goal or a criterion since brief ran, so the reviewer judged another text." local raw count i one lens cid linked severity disposition built findings_json alignment raw='[]' if [ -n "$findings_path" ]; then rv_read_findings_array "$findings_path" "findings" "findings" raw="$RV_FINDINGS_ARRAY" fi # A non-goal added live after the freeze is one the brief carried, so a finding may cite it. A # dropped criterion is one it did not, so a finding that cites it is a follow-up. alignment="$(rw_alignment | jq -c --argjson c "$person_changes" --argjson d "$RW_DROPPED" '.nonGoals = ((.nonGoals // []) + [ $c[] | select(.kind == "non-goal" and .frozen == null) | {id, text: .live} ]) | .criteria = [ (.criteria // [])[] | select(.id as $i | [ $d[].id ] | index($i) | not) ]')" findings_json='[]' count="$(printf '%s' "$raw" | jq 'length')" i=0; lens=""; linked=""; severity=""; disposition=""; built=""; cid="" while [ "$i" -lt "$count" ]; do one="$(printf '%s' "$raw" | jq -c --argjson i "$i" '.[$i]')" cid="$(printf '%s' "$one" | jq -r '.id')" lens="$(printf '%s' "$one" | jq -r '.lens // ""')" case " $LENS_WORDS " in *" $lens "*) ;; *) die 52 "findings: finding $cid in $findings_path names the lens '$lens'. The eight lens words are $LENS_WORDS, and each of six checks reads its verdict off its own lens, so a word outside that list would leave a check reading met on a findings file that is not empty." ;; esac linked="$(printf '%s' "$one" | jq -r '.linkedTo // ""')" severity="$(printf '%s' "$one" | jq -r '.severity // ""')" # A low finding is follow-up whatever it cites. The reviewer chooses both the severity and the # link, and nothing checks the link, so a nit routed through a criterion would fail it (gap # row 274). `close` reads this disposition and nothing else. disposition="$(jq -nr --argjson a "$alignment" --arg l "$linked" --arg s "$severity" ' if $l == "" then "follow-up" elif (($a.criteria // []) | map(.id) | index($l)) != null then (if $s == "low" then "follow-up" else "criterion" end) elif (($a.nonGoals // []) | map(.id) | index($l)) != null then "non-goal" else "follow-up" end')" built="$(printf '%s' "$one" | jq -c --arg disposition "$disposition" ' {id, lens, severity, file: (.file // ""), lines: (.lines // ""), linkedTo: (.linkedTo // ""), evidence, disposition: $disposition}')" findings_json="$(jq_files -nc --argjson have "$findings_json" --argjson one "$built" '$have + [$one]')" i=$((i + 1)) done # A finding keeps its id across passes while its content is the same (gap row 472). The reviewer # numbers each pass from f1, so a row a person prepared from an earlier pass could rule another # finding. A finding whose lens, file, lines and evidence match one an archived pass recorded # takes that id. Every other finding takes a fresh id above every id any pass used, so a stale # row names no finding, and close drops it with a warning. # The same content keeps a fix ruling too, when fix is the one ruling any archived pass gave it, # so the next pass sends it to its order again (gap row 479). A later wrong or deferred stops it. local archived_findings archived_findings="$(find "$REVIEW_DIR" -maxdepth 1 -type f -name 'review-*.json' -exec cat {} + 2>/dev/null \ | jq -cs '[ .[] | (.findings // [])[] | select(.lens != "frozen-tests") | {id, k: [.lens, .file, .lines, .evidence], ruling} ]' 2>/dev/null)" [ -n "$archived_findings" ] || archived_findings='[]' findings_json="$(printf '%s' "$findings_json" | jq -c --argjson old "$archived_findings" ' ([ $old[] | .id[1:] | tonumber ] | max // 0) as $top | reduce .[] as $f ({out: [], used: [], next: ($top + 1)}; . as $s | ([ $old[] | select(.k == [$f.lens, $f.file, $f.lines, $f.evidence]) ]) as $match | ([ $match[] | .id ] | map(select(. as $i | $s.used | index($i) | not)) | .[0]) as $same | (if ([ $match[] | .ruling // empty ] | unique) == ["fix"] then {ruling: "fix", disposition: "criterion"} else {} end) as $carry | if $same != null then .out += [$f + {id: $same} + $carry] | .used += [$same] elif $top == 0 then .out += [$f] else .out += [$f + {id: ("f" + (.next | tostring))}] | .next += 1 end) | .out')" # A purpose finding on a file `task environment up` wrote judges no order's work: no order owns # the file, and check 3 sets it aside (gap row 469). It is named and not recorded. local env_aside env_dropped RW_RANGE="$(printf '%s' "$RW_RECORD_DOC" | jq -r '.reviewedRange')" rw_load_changed "${RW_RANGE%%..*}" "${RW_RANGE##*..}" env_aside="$(rw_env_aside)" env_dropped="$(printf '%s' "$findings_json" | jq -r --argjson a "$env_aside" \ '[ .[] | select(.lens == "purpose" and (.file as $f | $a | index($f)) != null) | .id + " on " + .file ] | join(", ")')" findings_json="$(printf '%s' "$findings_json" | jq -c --argjson a "$env_aside" \ '[ .[] | select((.lens == "purpose" and (.file as $f | $a | index($f)) != null) | not) ]')" [ -z "$env_dropped" ] \ || echo "FINDINGS: these purpose findings name files \`task environment up\` wrote for the worktree's site, which no order owns, so none is recorded: $env_dropped" >&2 # Each check reads its verdict off its own lens: met when that lens returned nothing, unmet when # it returned a finding. An absent verdict is never a clean one, and version 5 paid for that four # times, which is why every one of the six is written here rather than left out. # Check 16's floor, before its lens verdict. The practices lens reads the plays research loaded # into records/playbooks.json, so a missing load is a lens that did not run, never a lens that # found nothing to follow. The floor applies only when something was there to load: the project # subscribes to a set, holds a playbook.md, or declares a folder as a source of playbooks, or the # person has their own playbook file. Then it reads unknown when the record is absent, or when # no source in it is loaded. A folder and nothing else: the loader reads folder sources only, and # `add-source playbooks catalog` writes a catalog entry the loader skips, so counting that entry would hold the check # at unknown for ever with a repair that cannot clear it. With nothing to load, an absent record # and a record whose sources all read absent say the same thing, so the lens verdict stands # (gap row 329). A person never runs the load, so the repair names the stage that does. local playbooks_record playbooks_floor playbooks_record="$(playbooks_record_path "$TASK_PATH")" playbooks_floor="" if [ "$(printf '%s' "$RW_PROJECT_DOC" | jq -r '[ (.playbookSubscriptions // {})[] | .[] ] | length')" != "0" ] \ || [ "$(printf '%s' "$RW_PROJECT_DOC" | jq -r '[ (.sources // [])[] | select(.locationType == "folder") | select((.provides // []) | index("playbooks")) ] | length')" != "0" ] \ || [ -f "$RV_PROJECT_FOLDER/playbook.md" ] || [ -f "$(playbooks_person_path)" ]; then if [ ! -f "$playbooks_record" ]; then playbooks_floor="playbooks not loaded: $playbooks_record is absent, while the project subscribes to a set, declares a folder of plays, or holds playbook.md, or the person has $(playbooks_person_path). So the practices lens read no play. Run /aida:research on this task again; it loads the plays at its start." elif [ "$(jq -r '[ (.sources // [])[] | select(.state == "loaded") ] | length' "$playbooks_record" 2>/dev/null)" = "0" ]; then playbooks_floor="playbooks not loaded: every source in $playbooks_record reads absent, empty or unreachable, while the project subscribes to a set, declares a folder of plays, or holds playbook.md, or the person has $(playbooks_person_path). Run /aida:research on this task again; it loads the plays at its start." fi fi # The floor the guides lens and the practices lens share, before either verdict. Both read the # research records and nothing else: check 12 asks whether a guide research cited was followed, # and check 16 whether a practice research grounded was applied. A lens with no source to read # judged nothing, and met said it had (live-run row 154). # # Two facts, kept apart. No research record at all is nobody having looked, which is unknown and # is a warning. Records that cite no source is research that looked and grounded nothing, # which is undeclared and passes in its own word. Which of a cited source is a guide and which is # an agentic recipe is a sentence inside the finding's own text, so no script decides it and both # lenses read the same count (ideal/review.md, check 16). local research_count research_sources one_research found_here research_count=0; research_sources=0; one_research=""; found_here=0 while IFS= read -r one_research; do [ -n "$one_research" ] || continue [ "${one_research##*/}" != "$PRACTICE_SEARCH.json" ] || continue research_count=$((research_count + 1)) found_here="$(jq -r '[ (.findings // [])[] | select((.source // "") != "") ] | length' "$one_research" 2>/dev/null)" case "$found_here" in ''|*[!0-9]*) found_here=0 ;; esac research_sources=$((research_sources + found_here)) done </dev/null | sort) RW_RESEARCH_FILES # Review's own practice search is no research record, so it never stands in for research that # was not run. Each practice it found with a source is a source the two lenses read, though. local practice_sourced practice_file practice_sourced="$(jq -r '.practiceSearch.sourced // 0' "$BRIEF_FILE" 2>/dev/null)" case "$practice_sourced" in ''|*[!0-9]*) practice_sourced=0 ;; esac practice_file="$(jq -r '.practiceSearch.file // empty' "$BRIEF_FILE" 2>/dev/null)" research_sources=$((research_sources + practice_sourced)) local source_floor source_note source_floor=""; source_note="" if [ "$research_count" -eq 0 ]; then source_floor="unknown" source_note="research recorded nothing: $TASK_PATH/research holds no record, so this lens read no source and judged nothing. Run the research stage on this task." elif [ "$research_sources" -eq 0 ]; then source_floor="undeclared" source_note="research recorded $research_count search(es) and none of them cites a source, so this lens had no guide and no accepted practice to judge the diff against." fi # Every lens judges the whole-task diff, and that diff is the code repository's. No order commits # there, so it holds nothing this task produced. The deliverables are documents in the project # folder, and this stage's brief does not name them: `ideal/review.md` records that as a gap and # says it is not built. So the lens read an empty diff, and `met` said it had judged the work # (live-run row 154). local diff_floor diff_floor="" [ "$RW_COMMITS_IN_CODE" = "yes" ] \ || diff_floor="no order in this task commits in the code repository, so the diff this lens reads holds nothing the task produced. Each deliverable is a document in the project folder, which this stage does not hand the reviewer." # A guide body is one design opened, listed in design-guides-read.json, which the brief marks on # disk or not. Research never opens a guide, and a code file research cites is no guide. With no # guide body on disk the guides lens judged the finding text alone, and met would say it judged # a guide (live-run row 272). The brief decides this, not the reviewer's report. The practices # lens reads the same bodies, since design opens the agentic recipes too, and also the playbook # record, so a loaded source there is a body it opened. # # With no guide body, review's own practice search is the body (gap row 364). The check reads met # only when the reviewer's practiceJudged names, for that lens, a sourced finding of that search. # Otherwise it reads unknown, a warning the person reads at close, never a ruling close waits for. local body_floor practices_body bodies_on_disk practice_refs judged body_floor=""; practices_body=""; judged="" practice_refs="$(jq -c '.practiceSearch.sourcedRefs // []' "$BRIEF_FILE" 2>/dev/null)" [ -n "$practice_refs" ] || practice_refs='[]' bodies_on_disk="$(jq -r '[ (.guideBodies // [])[] | select(.onDisk == true) ] | length' "$BRIEF_FILE" 2>/dev/null)" if [ "${bodies_on_disk:-0}" = "0" ]; then body_floor="no guide body is on disk: $BRIEF_FILE lists none from $TASK_PATH/design-guides-read.json, so this lens judged the research finding text alone. Design records each guide body it opens with design-actions.sh read-guide; once one is recorded and on disk, run brief and findings again." if [ -z "$practice_file" ]; then body_floor="$body_floor The review's own search for current practice is not recorded either: brief prints practice-search: dispatch, and its findings go to research-actions.sh record --search $PRACTICE_SEARCH." elif [ "$practice_sourced" -eq 0 ]; then body_floor="$body_floor The review's own search, $practice_file, found no current practice with a source." fi fi [ ! -f "$playbooks_record" ] \ || [ "$(jq -r '[ (.sources // [])[] | select(.state == "loaded") ] | length' "$playbooks_record" 2>/dev/null)" = "0" ] \ || practices_body="loaded" local rows_file lens_word check_id lens_row updated lens_note rows_file="$(mktemp)" || die 3 "findings: could not create a temporary file" for lens_word in non-goals solid dry architecture guides practices; do check_id="$(rw_check_for_lens "$lens_word")" # Met when this lens returned nothing, and the finding's reading otherwise. An absent verdict is # never a clean one, which is why every one of the six is written whatever the file held. A # finding beats both floors below it: a lens that raised one judged something. lens_row="$(rw_lens_row "$lens_word" "$check_id" "$findings_json")" if [ "$lens_word" = "practices" ] && [ -n "$playbooks_floor" ]; then rw_check_row "$check_id" "unknown" "$playbooks_floor" >>"$rows_file" elif [ -n "$lens_row" ]; then printf '%s\n' "$lens_row" >>"$rows_file" elif [ -n "$source_floor" ] && { [ "$lens_word" = "guides" ] || [ "$lens_word" = "practices" ]; }; then rw_check_row "$check_id" "$source_floor" "$source_note" >>"$rows_file" elif [ -n "$diff_floor" ]; then rw_check_row "$check_id" "undeclared" "$diff_floor" >>"$rows_file" elif [ -n "$body_floor" ] && { [ "$lens_word" = "guides" ] || { [ "$lens_word" = "practices" ] && [ -z "$practices_body" ]; }; }; then judged=""; lens_note="" if [ "$practice_sourced" -gt 0 ]; then [ -z "$findings_path" ] || judged="$(jq -r --arg l "$lens_word" --argjson refs "$practice_refs" ' [ (.practiceJudged // [])[] | select(.lens == $l) | (.findings // [])[] | select(. as $f | $refs | index($f)) ] | unique | join(", ")' "$findings_path" 2>/dev/null)" lens_note=" The reviewer's findings file names no sourced finding of $practice_file under practiceJudged for the $lens_word lens, so nothing shows the diff was judged against that search." fi if [ -n "$judged" ]; then rw_check_row "$check_id" "met" "the $lens_word lens returned no finding over the diff of $(printf '%s' "$RW_RECORD_DOC" | jq -r '.reviewedRange'). No guide body is on disk; the reviewer's practiceJudged names judging the diff against $judged in $practice_file." >>"$rows_file" else rw_check_row "$check_id" "unknown" "$body_floor$lens_note" >>"$rows_file" fi else rw_check_row "$check_id" "met" "the $lens_word lens returned no finding over the diff of $(printf '%s' "$RW_RECORD_DOC" | jq -r '.reviewedRange')." >>"$rows_file" fi done # What a build left for a person, one check each, which reads unknown until the # person answers it with close --row (gap row 279). Nobody present leaves it unknown. printf '%s' "$RW_FINISHED_DOC" | jq -c '(.pendingDecisions // [])[] | ("decision-" + .unit + "-" + (.finding // "departure")) as $id | {id: $id, verdict: "unknown", answeredBy: "nobody", detail: ((if .kind == "ruling" then .unit + " finding " + .finding + " (" + .severity + ") waits for a ruling, because " + (.because // "its fix scope is empty") + ", and nobody was present: " + .text + ". The person rules it with --row " + $id + "=wrong|deferred|load-bearing|test-wrong." else .unit + " departs from the design, and nobody has ruled on it yet: " + .text + ". The person answers with --row " + $id + "=keep|rebuild." end))}' >>"$rows_file" # Each change the person accepts at close: a non-goal changed, removed or added after the # freeze, or a criterion changed that no frozen test names. The row holds both texts. printf '%s' "$person_changes" | jq -c '.[] | ("decision-" + .id + "-" + .kind) as $id | {id: $id, verdict: "unknown", answeredBy: "nobody", frozenText: .frozen, liveText: .live, detail: (.id + (if .live == null then " was removed from the live contract after the freeze, so the brief no longer carries it." elif .frozen == null then " was added to the live contract after the freeze, and the brief carries it." else " was changed in the live contract after the freeze, and the brief carries the live text." end) + " The person answers with --row " + $id + "=accept|reject.")}' >>"$rows_file" # --- the done-when clauses the tests step routed here, one verdict each ------------------------ # Such a clause asserts the change added nothing of a named kind, and no test of it can be watched # failing, so the reviewer judges it against the diff (live-run row 184). The verdicts ride in the # findings file beside catalogNotes, and they land here as one row per routed clause and one check # row, so the verdict rules already applied at close decide what an unjudged clause does. # # Three readings become unknown, and none of them becomes met. A clause the reviewer left out. A # verdict outside the three words. A verdict with nothing to read beside it, the same rule # `tests-freeze` applies to a `--row`. An absence nobody judged is never a pass. # # The reviewer also says whether a test could have watched the clause fail. The freeze's word # test is a floor: "the form shows no legacy field" carries `no`, routes, and a test could have # proved it. The reviewer holds the done-when and the diff, so it is the role that can ask. # `testable` is yes, no, or unknown when the reviewer gave neither word. A yes reads unmet: the # route skipped a red run the clause could have had, and the reviewer answered, so it is no # unknown. A missing answer reads unknown, by the rule above. Both are warnings at close. local absence_given='' absence_rows absence_unrouted absence_twice [ -z "$findings_path" ] || absence_given="$(jq -c 'if ((.absenceVerdicts // []) | type) == "array" then [ (.absenceVerdicts // [])[] | {order: (.order // ""), clause: (.clause // ""), verdict: (.verdict // ""), note: (.note // ""), testable: (if (.testable // "") == "yes" or (.testable // "") == "no" then .testable else "unknown" end)} ] else [] end' "$findings_path" 2>/dev/null)" [ -n "$absence_given" ] || absence_given='[]' absence_unrouted="$(jq -nr --argjson routed "$RW_ABSENCE_CLAUSES" --argjson given "$absence_given" ' [ $given[] | . as $g | select(([ $routed[] | select(.order == $g.order and .clause == $g.clause) ] | length) == 0) | (.order + ": " + .clause) ] | unique | join("; ")')" [ -z "$absence_unrouted" ] \ || die 52 "findings: $findings_path answers a done-when clause no order routed to review: $absence_unrouted. The reviewer answers the clauses the brief carries under absenceClauses, verbatim, and it invents none. A verdict on a clause nobody routed answers a question nobody asked." # Two verdicts for one clause are two answers nothing can tell apart, and the pairing below reads # only the first. This is the rule the findings list already gets for two findings under one id. absence_twice="$(printf '%s' "$absence_given" | jq -r ' [ group_by([.order, .clause])[] | select(length > 1) | .[0] | (.order + ": " + .clause) ] | join("; ")')" [ -z "$absence_twice" ] \ || die 52 "findings: $findings_path answers these done-when clauses more than once: $absence_twice. One clause takes one verdict. A clause answered unmet would otherwise pass on the strength of a met written beside it." absence_rows="$(jq -nc --argjson routed "$RW_ABSENCE_CLAUSES" --argjson given "$absence_given" ' [ $routed[] | . as $r | ([ $given[] | select(.order == $r.order and .clause == $r.clause) ][0]) as $g | if $g == null then ($r + {verdict: "unknown", note: "the reviewer returned no verdict on this clause.", testable: "unknown"}) elif ((["met", "unmet", "unknown"]) | index($g.verdict)) == null then ($r + {verdict: "unknown", testable: $g.testable, note: ("the reviewer answered \"" + $g.verdict + "\", and the three words are met, unmet and unknown.")}) elif $g.note == "" then ($r + {verdict: "unknown", testable: $g.testable, note: ("the reviewer answered " + $g.verdict + " and wrote nothing beside it; a verdict with nothing to read is not a verdict.")}) else ($r + {verdict: $g.verdict, note: $g.note, testable: $g.testable}) end ]')" [ -n "$absence_rows" ] || die 3 "findings: could not pair the routed done-when clauses with the reviewer's verdicts." rw_absence_check_row "$absence_rows" >>"$rows_file" # The reviewer adds a catalog note the same way the script does: a guide the code contradicts, a # recipe whose command no longer runs, a pattern the framework wants and no guide names. Review # writes nothing to the catalog, so a note is kept as evidence and named at close. A findings file # with no such key adds none, which is the ordinary case. local reviewer_notes='' [ -z "$findings_path" ] || reviewer_notes="$(jq -c 'if ((.catalogNotes // []) | type) == "array" then [ (.catalogNotes // [])[] | select((.seen // "") != "" and (.where // "") != "") | {seen: .seen, where: .where} ] else [] end' "$findings_path" 2>/dev/null)" [ -n "$reviewer_notes" ] || reviewer_notes='[]' # The checks step's frozen-test findings stay, numbered after the reviewer's own. No lens check reads # the frozen-tests lens, so they block nothing. findings_json="$(printf '%s' "$RW_RECORD_DOC" | jq_files -c --argjson mine "$findings_json" ' ([ $mine[] | .id[1:] | tonumber ] | max // 0) as $top | $mine + ([ (.findings // [])[] | select(.lens == "frozen-tests") ] | to_entries | map(.value + {id: ("f" + (($top + .key + 1) | tostring))}))')" updated="$(jq_files -s -c --slurpfile record "$RECORD_FILE" --argjson findings "$findings_json" \ --argjson notes "$reviewer_notes" --argjson absences "$absence_rows" --arg skip "$skip_reason" ' . as $rows | $record[0] | (if $skip == "" then del(.reviewerSkipped) else .reviewerSkipped = $skip end) | .findings = $findings | .absences = $absences | .catalogNotes = ((.catalogNotes // []) + $notes) | .checks = ((.checks | map(. as $c | select(([ $rows[] | .id ] | index($c.id)) == null))) + $rows)' "$rows_file")" rm -f "$rows_file" [ -n "$updated" ] || die 3 "findings: could not update the record with what the reviewer found." # A record checks wrote before gap row 277 holds no script half, and its row may already carry # an earlier lens reading. Findings cannot tell the two apart, so it sends the caller back. local no_half no_half="$(printf '%s' "$updated" | jq -r --arg a "$CHECK_SERVES" --arg b "$CHECK_TEST_MUTATION" \ '[ .checks[] | select((.id == $a or .id == $b) and (has("scriptHalf") | not)) | .id ] | join(", ")')" [ -z "$no_half" ] \ || die 62 "findings: $RECORD_FILE holds no script half for $no_half, because checks wrote it before the script half was kept apart. Run checks again, then brief and findings." for lens_word in mutation purpose; do updated="$(rw_lens_with_half "$updated" "$lens_word")" done rw_write_record "findings" "$updated" rw_print_summary "$updated" "findings" printf 'findingsRead: %s\n' "${findings_path:-none, the reviewer was not dispatched}" local follow_up high_security follow_up="$(printf '%s' "$findings_json" | jq -r '[ .[] | select(.disposition == "follow-up") | .id ] | join(", ")')" high_security="$(printf '%s' "$findings_json" | jq -r '[ .[] | select(.disposition == "follow-up" and .severity == "high") | .id ] | join(", ")')" [ -z "$follow_up" ] \ || echo "FINDINGS: these findings cite no non-goal, and no criterion at medium or high severity, so they are recorded as follow-up work nobody has a task for: $follow_up. A person who wants one fixed in this task rules it fix at close." >&2 [ -z "$high_security" ] \ || echo "FINDINGS: these follow-up findings are high severity and go to the person now, because leaving one queued ships it: $high_security" >&2 exit 0 } # ------------------------------------------------------------------------------------------------ # `acceptance`: checks 13 to 15, the registry, and the acceptance verifier's evidence. # ------------------------------------------------------------------------------------------------ # The surface rows the review recipe declares, across every framework the record resolved one for, # each tagged with its framework. One surface row carries a command from one framework only, the # same rule cr_resolve applies to a tool row: where two frameworks command one row, the first in # project.json runs it, the other's row is dropped, and the task record gets a warning. Sets # RW_SURFACE_ROWS and RW_SURFACE_BLOCK_STATE. RW_SURFACE_ROWS="[]"; RW_SURFACE_BLOCK_STATE="undeclared" rw_load_surface_rows() { local who="$1" count i fw recipe_file rows_file all one_id commanded RW_SURFACE_ROWS='[]'; RW_SURFACE_BLOCK_STATE="undeclared" count="$(printf '%s' "$RW_RECORD_DOC" | jq '(.recipes // []) | length')" case "$count" in ''|*[!0-9]*) count=0 ;; esac rows_file="$(mktemp)" || die 3 "$who: could not create a temporary file" i=0; fw=""; recipe_file="" while [ "$i" -lt "$count" ]; do fw="$(printf '%s' "$RW_RECORD_DOC" | jq -r --argjson i "$i" '.recipes[$i].framework')" recipe_file="$(printf '%s' "$RW_RECORD_DOC" | jq -r --argjson i "$i" '.recipes[$i].checkRecipe')" if [ -n "$recipe_file" ] && [ -f "$recipe_file" ]; then : >"$rows_file.one" cc_parse_recipe "$recipe_file" "Surface commands" "surface_commands" "$rows_file.one" [ "$RECIPE_STATE" = "undeclared" ] || RW_SURFACE_BLOCK_STATE="$RECIPE_STATE" jq -c --arg fw "$fw" '. + {framework: $fw}' "$rows_file.one" >>"$rows_file" 2>/dev/null rm -f "$rows_file.one" fi i=$((i + 1)) done all="$(jq -s '.' "$rows_file" 2>/dev/null)" || all='[]' rm -f "$rows_file" one_id="" while IFS= read -r one_id; do [ -n "$one_id" ] || continue commanded="$(printf '%s' "$all" | jq -c --arg id "$one_id" \ '[ .[] | select(.id == $id and (has("argv")) and (((.unreadable // []) | index("argv")) == null)) ]')" if [ "$(printf '%s' "$commanded" | jq 'length')" -gt 1 ]; then commanded="$(cr_by_project_order "$commanded" "$(resolve_project_folder "$TASK_PATH")/project.json")" task_warn "$TASK_PATH" "$who" "" "$(printf '%s' "$commanded" | jq -r --arg t "$one_id" \ '"\([ .[].framework ] | join(" and ")) each declare a \($t) surface command. \(.[0].framework) runs it, the first in project.json"')" all="$(printf '%s' "$all" | jq -c --arg id "$one_id" --arg fw "$(printf '%s' "$commanded" | jq -r '.[0].framework')" \ '[ .[] | select(.id != $id or .framework == $fw) ]')" fi i=0 done <>"$surfaces_out" mine="$(printf '%s' "$SF_SURFACES" | jq -c --arg g "$gate" '[ .[] | select((.kinds | index($g)) and .enabled) ]')" count="$(printf '%s' "$mine" | jq 'length')" row="$(printf '%s' "$RW_SURFACE_ROWS" | jq -c --arg id "$row_id" '[ .[] | select(.id == $id) ][0] // null')" if [ "$enabled" = "unavailable" ]; then # Visual parity has no recipe row, no project field to switch it on and no harness, so version 6 # records it as unavailable rather than reporting a check that passed. A recipe that does command # the row reaches the ordinary path below instead. rw_check_row "$check_id" "undeclared" "visual parity has no recipe row, no project field and no harness in version 6, so nothing ran and nothing is claimed. It is recorded as unavailable." >>"$checks_out" return 0 fi if [ "$enabled" = "on with its surface file on a branch" ]; then rw_check_row "$check_id" "undeclared" "the project record says $gate is on, and the surface file is $SF_STATE in this tree. Branch $RW_SURFACE_BRANCH holds it, and the file reaches this task once that branch lands on the trunk. Until then it reads as off here, and review ran nothing for it. If that branch is abandoned, deleting it, local and remote, brings the setup offer back." >>"$checks_out" return 0 fi if [ "$enabled" = "on with no surface file" ]; then rw_check_row "$check_id" "undeclared" "the project record says $gate is on, and the surface file is $SF_STATE in this tree and on every branch, so it reads as off. Review ran nothing for it." >>"$checks_out" return 0 fi if [ "$enabled" != "on" ]; then rw_check_row "$check_id" "undeclared" "the project record says $gate is $enabled, so review ran nothing for it. Review runs nothing that is off." >>"$checks_out" return 0 fi # The changed list is the one checks read, derived again for the range the record holds. [ -n "$RW_RANGE" ] || { RW_RANGE="$(printf '%s' "$RW_RECORD_DOC" | jq -r '.reviewedRange // ""')"; rw_load_changed "${RW_RANGE%%..*}" "${RW_RANGE##*..}"; } if [ "$(printf '%s' "$mine" | jq '[ .[] | select(has("command")) ] | length')" -gt 0 ]; then rw_command_surfaces "$check_id" "$mine" "$off" "$checks_out" "$surfaces_out" return 0 fi if [ "$RW_SURFACE_BLOCK_STATE" = "unparseable" ]; then # The heading is there and the key never opens under it. Nobody looked, rather than a framework # that declared nothing, so the word is unknown, a warning at close. rw_check_row "$check_id" "unknown" "the surface commands block in the review recipe could not be read: the heading is there and its key never opens under it. Nothing ran, and nothing here can tell what the recipe meant to declare." >>"$checks_out" return 0 fi if [ "$RW_SURFACE_BLOCK_STATE" != "ok" ] || [ "$row" = "null" ]; then rw_check_row "$check_id" "undeclared" "the review recipe declares no $row_id surface row (the surface commands block reads $RW_SURFACE_BLOCK_STATE), so there is no command to run. Every command waits for the recipe." >>"$checks_out" return 0 fi if [ "$(printf '%s' "$row" | jq -r '.absent // false')" = "true" ]; then rw_check_row "$check_id" "undeclared" "$(printf '%s' "$row" | jq -r '.absentReason // "the recipe declares this surface row absent"')" "" "" "$(printf '%s' "$row" | jq -r '.framework // ""')" "absent" >>"$checks_out" return 0 fi if [ "$SF_STATE" != "ok" ]; then detail="the recipe commands a $row_id run and the surface file is $SF_STATE, so nobody could say which surfaces to answer about." if [ "$SF_STATE" != "unreadable" ]; then detail="$detail Nobody was present to take the setup offer. /aida:surfaces $gate writes the file." fi rw_check_row "$check_id" "unknown" "$detail" >>"$checks_out" return 0 fi if [ "$count" -eq 0 ]; then rw_check_row "$check_id" "undeclared" "the surface file holds no enabled surface carrying the $gate kind, so this project has nothing for this check to run. Disabled and not run: $(printf '%s' "$off" | jq -r '[ .[].id ] | join(", ")')" >>"$checks_out" return 0 fi # Narrowing: the person who registered a surface declared the paths that render it, and review # runs the surface when the diff touched one of them, when it is critical, or when it declares # none. No agent guesses. The rest get their own row, not run, and the detail says why. run='[]'; unaffected='[]' i=0 while [ "$i" -lt "$count" ]; do one="$(printf '%s' "$mine" | jq -c --argjson i "$i" '.[$i]')" if rw_surface_affected "$one" "$accepted"; then run="$(printf '%s' "$run" | jq -c --argjson s "$one" '. + [$s]')" else unaffected="$(printf '%s' "$unaffected" | jq -c --argjson s "$one" '. + [$s]')"; fi i=$((i + 1)) done if [ "$unaffected" != "[]" ]; then if [ "$(printf '%s' "$row" | jq '.argv | index("{surfaces}")')" = "null" ]; then # A row that takes no id list runs the whole set, and the sentence tells the catalog # maintainer what to add. narrow_note=" The $row_id row carries no {surfaces} token, so narrowing did not apply to this run. The diff at $RW_RANGE touched no declared path of: $(printf '%s' "$unaffected" | jq -r '[ .[].id ] | join(", ")')." run="$mine" else printf '%s' "$unaffected" | jq -c "$not_run" >>"$surfaces_out" narrow_note=" Not run, because the diff at $RW_RANGE touched none of their declared paths: $(printf '%s' "$unaffected" | jq -r '[ .[].id ] | join(", ")')." if [ "$run" = "[]" ]; then detail="every enabled $gate surface declares paths, and the diff at $RW_RANGE touched none of them, so nothing ran.$narrow_note" [ "$off" = "[]" ] || detail="$detail Disabled and not run: $(printf '%s' "$off" | jq -r '[ .[].id ] | join(", ")')." rw_check_row "$check_id" "met" "$detail" >>"$checks_out" return 0 fi fi fi mine="$run"; count="$(printf '%s' "$mine" | jq 'length')" # {surfaces} fills with the ids that run, joined by |, the way the accept row is filled. A row # without the token never reads the value. values="$(printf 'surfaces\t%s\n%s' "$(printf '%s' "$mine" | jq -r '[ .[].id ] | join("|")')" "$RW_VALUES")" # The e2e-preflight row runs before the e2e suite. A non-zero exit records it unmet and the e2e # check unknown, and the suite does not run (ideal/surfaces.md, the reading rule). if [ "$row_id" = "e2e" ]; then pre_row="$(printf '%s' "$RW_SURFACE_ROWS" | jq -c '[ .[] | select(.id == "e2e-preflight" and (has("argv")) and ((.absent // false) == false)) ][0] // null')" if [ "$pre_row" != "null" ]; then rw_surface_row_check "$pre_row" "e2e-preflight" "ran before the e2e suite" >>"$checks_out" if [ -n "$RW_RUN_VERDICT" ] || [ "$RW_RUN_RC" != "0" ]; then rw_check_row "$check_id" "unknown" "the e2e-preflight row did not exit 0, so the e2e suite did not run and nothing here can say what it would have found." >>"$checks_out" printf '%s' "$mine" | jq -c '.[] | {id, verdict: "unknown", ran: false, looked: false, reportPath: ""}' >>"$surfaces_out" return 0 fi fi fi # A person accepted a new baseline for one of this kind's own surfaces, so the row that writes one # runs. The accept row is a second id, never a new key, which is what the recipe ask declares. A # kind with no accept row declared does nothing here, and the caller refuses for the surface. accept_here="" i=0 while [ "$i" -lt "$count" ]; do sid="$(printf '%s' "$mine" | jq -r --argjson i "$i" '.[$i].id')" case " $accepted " in *" $sid "*) accept_here="$accept_here $sid" ;; esac i=$((i + 1)) done if [ -n "$accept_here" ]; then accept_row="$(printf '%s' "$RW_SURFACE_ROWS" | jq -c --arg id "$row_id-accept" \ '[ .[] | select(.id == $id and (has("argv")) and ((.absent // false) == false)) ][0] // null')" if [ "$accept_row" != "null" ]; then RW_ACCEPTED_ROWS="$RW_ACCEPTED_ROWS $row_id-accept" # {surfaces} fills with the accepted ids joined by |, so the row rewrites those baselines and no other. rw_surface_row_check "$accept_row" "$row_id-accept" "ran over the surfaces a person accepted,${accept_here}," \ "$(printf 'surfaces\t%s\n%s' "$(printf '%s' "$accept_here" | sed 's/^ *//' | tr ' ' '|')" "$RW_VALUES")" >>"$checks_out" if [ -z "$RW_RUN_VERDICT" ] && [ "$RW_RUN_RC" = "0" ]; then RW_ACCEPTED_DONE="$RW_ACCEPTED_DONE$accept_here" fi fi fi # {paths} expands to nothing here on purpose: the surfaces that run are named through {surfaces} # above, never through the changed files, so a row ending in {paths} runs the whole set. rw_run_row "$(printf '%s' "$row" | jq -c '.argv')" '[]' "$values" "" rw_run_fault "$row_id" ran=false; rc=""; row_verdict="$RW_RUN_VERDICT"; detail="$RW_RUN_DETAIL" if [ -z "$row_verdict" ]; then ran=true rc="$RW_RUN_RC" # The row's own silent-pass markers, read before the exit status: a suite that selected # nothing and exited 0 decided nothing. marker="$(jq -rn --argjson m "$(printf '%s' "$row" | jq -c '.silentPass // []')" \ --rawfile out "$RW_RUN_OUTFILE" '[ $m[] as $one | select($out | contains($one)) | $one ][0] // ""')" if [ -n "$marker" ]; then row_verdict="unknown" detail="the $row_id output holds the row's own silent-pass marker ('$marker'), so an exit status cannot decide a run that selected nothing." elif [ "$rc" = "0" ]; then row_verdict="met" detail="the $row_id command exited 0." else row_verdict="unmet" detail="the $row_id command exited $rc." fi fi [ "$off" = "[]" ] || detail="$detail Disabled and not run: $(printf '%s' "$off" | jq -r '[ .[].id ] | join(", ")')." detail="$detail$narrow_note" # One row per registered surface of this kind, in one pass. A surface the run said nothing about # reads unmet rather than borrowing the run's own verdict: a gate that cannot notice its subject # going absent cannot inform. rows="$(jq -nc --argjson mine "$mine" --rawfile out "$RW_RUN_OUTFILE" --arg v "$row_verdict" \ --argjson ran "$ran" --arg accepted " $RW_ACCEPTED_DONE " ' [ $mine[] | .id as $sid | {id: $sid, verdict: (if $ran and (($out | contains($sid)) | not) then "unmet" else $v end), ran: $ran, looked: false, reportPath: ""} + (if ($accepted | contains(" " + $sid + " ")) then {baselineAccepted: true} else {} end) ]')" printf '%s' "$rows" | jq -c '.[]' >>"$surfaces_out" worst="" while IFS= read -r verdict; do [ -n "$verdict" ] || continue worst="$(rw_worse "$worst" "$verdict")" done <>"$checks_out" rw_run_done } # The e2e surfaces that carry their own command, for a project with no page to drive (gap row 289). # Each command runs in the task's tree through the runner every recipe row uses, never a shell, and # only exit 0 reads met. No recipe row and no walk apply, since the exit status is the whole answer. # The command and its scripts live in the tree under review, so the build could weaken what judges # it. A command that differs from the same id at the range base, carries a shell character, or names # a path whose files the range deleted or made non-executable reads unknown and does not run. # Register refuses a page surface beside a command one. A hand-edited file that holds both reads # unknown for the page, since nothing here runs the recipe's suite. $1 the check id, $2 the enabled # surfaces of the kind, $3 the disabled ones, $4 the check rows file, $5 the surface rows file. rw_command_surfaces() { local check_id="$1" mine="$2" off="$3" checks_out="$4" surfaces_out="$5" local count i one sid verdict ran worst="" detail="" rc="" outfile="" base head rel base_doc cmd was tok scopes touched base="${RW_RANGE%%..*}"; head="${RW_RANGE##*..}" rel="$(printf '%s' "$RW_PROJECT_DOC" | jq -r '.surfaces.registryPath // ""')" base_doc="$(git -C "$RV_CODEPATH" show "$base:$rel" 2>/dev/null)" count="$(printf '%s' "$mine" | jq 'length')" i=0 while [ "$i" -lt "$count" ]; do one="$(printf '%s' "$mine" | jq -c --argjson i "$i" '.[$i]')" sid="$(printf '%s' "$one" | jq -r '.id')" cmd="$(printf '%s' "$one" | jq -c '.command // empty')" i=$((i + 1)) ran=false; verdict="" # A surface absent at the base was registered in this range, and there is nothing to compare. was="$(printf '%s' "$base_doc" | jq -c --arg id "$sid" '[ (.surfaces // [])[] | select(.id == $id) ][0].command // empty' 2>/dev/null)" scopes="" for tok in $(printf '%s' "$cmd" | jq -r '.[]' 2>/dev/null); do case "$tok" in -*|/*|*..*) continue ;; esac [ -e "$RV_CODEPATH/$tok" ] || git -C "$RV_CODEPATH" cat-file -e "$base:$tok" 2>/dev/null || continue scopes="$scopes $tok" [ -d "$RV_CODEPATH/$tok" ] || [ "$(dirname "$tok")" = "." ] || scopes="$scopes $(dirname "$tok")" done touched="" # A command substitution splits in bash and zsh alike; each scope is one argv token, so one word. # shellcheck disable=SC2046 [ -z "$scopes" ] || touched="$(git -C "$RV_CODEPATH" diff --raw --no-renames "$base" "$head" -- $(printf '%s' "$scopes") 2>/dev/null \ | awk -F'\t' '{ split($1, m, " "); if (m[5] == "D" || (m[5] == "M" && substr(m[1], 2) != m[2])) print $2 }' | sort -u | tr '\n' ' ')" if [ -z "$cmd" ]; then verdict="unknown"; detail="$detail The $sid surface is a page beside command surfaces, so it did not run." elif [ -n "$was" ] && [ "$was" != "$cmd" ]; then verdict="unknown"; detail="$detail The $sid command is $cmd here and was $was at $base, so this range changed what judges it, and it did not run." elif ! refuse_if_unsafe review-actions "the surface file" "$(printf '%s' "$cmd" | jq -r 'join(" ")')" 2>/dev/null; then verdict="unknown"; detail="$detail The $sid command $cmd carries a shell character, which register refuses, so it did not run." elif [ -n "$touched" ]; then verdict="unknown"; detail="$detail The range deleted files under the $sid command's paths, or changed their mode, so it did not run: ${touched% }." else rw_run_row "$cmd" '[]' "$RW_VALUES" "" rw_run_fault "$sid" "" "A command surface has no recipe to install it from. Name a program inside this tree, or put it on the session's PATH." verdict="$RW_RUN_VERDICT" if [ -n "$verdict" ]; then detail="$detail $RW_RUN_DETAIL" else ran=true if [ "$RW_RUN_RC" = "0" ]; then verdict="met"; else verdict="unmet"; fi detail="$detail The $sid command exited $RW_RUN_RC in $RV_CODEPATH." # With one command, the record keeps its exit code and output, as for any other row. [ "$count" -ne 1 ] || { rc="$RW_RUN_RC"; outfile="$(mktemp)" && cp "$RW_RUN_OUTFILE" "$outfile"; } fi # Nothing records which program a name reached, so a failure says where it looked. [ "$verdict" = "met" ] || detail="$detail It ran with the session's PATH from $RV_CODEPATH, so a program it names may be an installed copy rather than this tree's build." rw_run_done fi jq -nc --arg id "$sid" --arg v "$verdict" --argjson ran "$ran" \ '{id: $id, verdict: $v, ran: $ran, looked: false, reportPath: ""}' >>"$surfaces_out" worst="$(rw_worse "$worst" "$verdict")" done [ "$off" = "[]" ] || detail="$detail Disabled and not run: $(printf '%s' "$off" | jq -r '[ .[].id ] | join(", ")')." rw_check_row "$check_id" "$worst" "${detail# }" "$rc" "$outfile" >>"$checks_out" [ -z "$outfile" ] || rm -f "$outfile" } # Runs one surface row and prints its check row: the wording rw_run_fault gives a run that decided # nothing, met on exit 0, unmet on anything else. $1 the row, $2 the id to record it under, $3 what # the detail says the row did, $4 the tab-separated --value list, RW_VALUES when absent. The caller # reads RW_RUN_VERDICT and RW_RUN_RC afterwards when it needs to know whether the command really ran. rw_surface_row_check() { local one="$1" id="$2" did="$3" fw fw="$(printf '%s' "$one" | jq -r '.framework // ""')" rw_run_row "$(printf '%s' "$one" | jq -c '.argv // []')" '[]' "${4:-$RW_VALUES}" "" rw_run_fault "$id" if [ -n "$RW_RUN_VERDICT" ]; then rw_check_row "$id" "$RW_RUN_VERDICT" "$RW_RUN_DETAIL" "" "" "$fw" elif [ "$RW_RUN_RC" = "0" ]; then rw_check_row "$id" "met" "the $id command $did and exited 0." "$RW_RUN_RC" "$RW_RUN_OUTFILE" "$fw" else rw_check_row "$id" "unmet" "the $id command $did and exited $RW_RUN_RC." "$RW_RUN_RC" "$RW_RUN_OUTFILE" "$fw" fi rw_run_done } # Every surface row the recipe declares that no kind above answered. The check commands block gets # this treatment already: the ids are a floor and never the list, so a row a framework invents is run # and recorded rather than dropped in silence. $1 the check rows file, $2 the ids already answered. # # An accept row is the one exception. It writes a new baseline, so it runs only when a person accepts # one, and a row nobody asked for is recorded as not run rather than run unasked. rw_surface_extra_rows() { local checks_out="$1" answered="$2" count i one row_id count="$(printf '%s' "$RW_SURFACE_ROWS" | jq 'length')" case "$count" in ''|*[!0-9]*) count=0 ;; esac i=0; one=""; row_id="" while [ "$i" -lt "$count" ]; do one="$(printf '%s' "$RW_SURFACE_ROWS" | jq -c --argjson i "$i" '.[$i]')" row_id="$(printf '%s' "$one" | jq -r '.id')" i=$((i + 1)) case " $answered " in *" $row_id "*) continue ;; esac case "$row_id" in *-accept) rw_check_row "$row_id" "undeclared" "this row writes a new baseline, so it runs only when a person accepts one. Nobody accepted one in this review, and it was not run." >>"$checks_out" continue ;; esac if [ "$(printf '%s' "$one" | jq -r '.absent // false')" = "true" ]; then rw_check_row "$row_id" "undeclared" "$(printf '%s' "$one" | jq -r '.absentReason // "the recipe declares this surface row absent"')" "" "" "$(printf '%s' "$one" | jq -r '.framework // ""')" "absent" >>"$checks_out" continue fi rw_surface_row_check "$one" "$row_id" "ran as the recipe declares it" >>"$checks_out" done } # The rows the acceptance verifier wrote, as a JSON array, into RW_EVIDENCE. Exit 52 when the file # is not the verifier's rows: a row of the wrong shape, a criterion the frozen contract does not # hold, a surface the surface file does not register, a viewport it does not list, a criterion with # no row, or a file the row names that is not on disk. A dropped criterion needs no row, and a row # that names one is left out, so no finding comes from it. A row's path is joined to review/evidence/ # when it is relative, and refused when it lies outside that folder, which is the one folder the # verifier writes files in. A row's `file` is the code file a bug it saw lives in, joined to the # code path. A row for a criterion changed after the freeze carries its live text, the text the # verifier judged and the person accepts (gap row 506). Reads SF_SURFACES and the viewports in $1. RW_EVIDENCE="[]" rw_load_evidence() { local viewports="$1" bad missing one abs i resolved='[]' evidence_dir="$REVIEW_DIR/evidence" [ "$(json_file_state "$EVIDENCE_FILE")" = "ok" ] \ || die 52 "acceptance: --evidence reads $EVIDENCE_FILE, and it is $(json_file_state "$EVIDENCE_FILE"). The acceptance verifier writes it. Dispatch the verifier, then run this again." RW_EVIDENCE="$(jq -c '.rows' "$EVIDENCE_FILE")" bad="$(printf '%s' "$RW_EVIDENCE" | jq -r --argjson criteria "$(rw_alignment | jq -c '[ (.criteria // [])[].id ]')" \ --argjson surfaces "$(printf '%s' "$SF_SURFACES" | jq -c '[ .[].id ]')" --argjson viewports "$viewports" ' if type != "array" then "the file holds no rows list" else [ .[] | tostring as $t | select((type != "object") or ((.sentence | type) != "string") or (.sentence == "") or ((.path | type) != "string") or ((.note | type) != "string") or ((.verdict as $w | ["met", "unmet", "unknown"] | index($w)) == null) or ((has("criterion") or has("surface")) | not) or (has("criterion") and (.criterion as $c | $criteria | index($c)) == null) or (has("surface") and (.surface as $s | $surfaces | index($s)) == null) or (has("viewport") and ((has("surface") | not) or (($viewports | length) > 0 and (.viewport as $v | $viewports | index($v)) == null))) or (has("file") and (((.file | type) != "string") or (.file == "") or (has("criterion") | not))) or ((keys - ["criterion", "sentence", "surface", "viewport", "path", "file", "verdict", "note"]) != [])) | $t ] | join("; ") end' 2>/dev/null)" \ || die 52 "acceptance: $EVIDENCE_FILE could not be read as the verifier's rows." [ -z "$bad" ] \ || die 52 "acceptance: $EVIDENCE_FILE holds rows that are not evidence rows (scripts/review-schema.json, evidenceRow). Or they name a criterion, surface or viewport this task does not hold: $bad. Nothing was written." bad="" # Each path is read by its index: a list read through $(...) loses an empty last path. for i in $(printf '%s' "$RW_EVIDENCE" | jq -r 'keys[]'); do one="$(printf '%s' "$RW_EVIDENCE" | jq -r --argjson i "$i" '.[$i].path')" abs="" if [ -n "$one" ]; then abs="$(normalize_abs "$(resolve_against "$one" "$evidence_dir")")" is_under "$abs" "$evidence_dir" || bad="$bad $one (outside $evidence_dir)" [ -e "$abs" ] || bad="$bad $one (not on disk)" fi resolved="$(jq -nc --argjson have "$resolved" --arg p "$abs" '$have + [$p]')" done while IFS= read -r one; do [ -z "$one" ] || [ -e "$(resolve_against "$one" "$RV_CODEPATH")" ] || bad="$bad $one (no such code file)" done </dev/null)" || viewports='[]' if [ -n "$evidence_given" ]; then rw_record_has_check "$CHECK_E2E" \ || die 62 "acceptance: $RECORD_FILE records no surface checks, so there is no run for the verifier's rows to join. Run acceptance without --evidence first." rw_load_evidence "$viewports" else RW_EVIDENCE="$(printf '%s' "$RW_RECORD_DOC" | jq -c '.evidence // []')"; fi looked="$(printf '%s' "$SF_SURFACES" | jq -c --argjson e "$RW_EVIDENCE" --argjson v "$viewports" ' [ .[] | select(has("command") | not) | .id as $s | ([ $e[] | select(.surface == $s) | (.viewport // "") ]) as $seen | select(($seen | length) > 0 and all($v[]; . as $one | $seen | index($one))) | $s ]')" # With --evidence the surface runs recorded before stand. Only the look, the checks it changes and # the findings the rows name are written, so no suite runs twice. if [ -n "$evidence_given" ]; then updated="$(printf '%s' "$RW_RECORD_DOC" | jq -c --argjson e "$RW_EVIDENCE" --argjson looked "$looked" \ "$RW_LOOK_JQ"' .evidence = $e | apply_look($e; $looked)')" [ -n "$updated" ] || die 3 "acceptance: could not apply the verifier's rows to $RECORD_FILE." rw_write_record "acceptance" "$updated" rw_print_summary "$updated" "acceptance" echo "ACCEPTANCE: the verifier's rows are recorded over the surface runs already in $RECORD_FILE." >&2 exit 0 fi # A kind marked on with no surface file was set up by half (gap row 275). When another branch holds # the file, it is often another task's unfinished work, and a merge would put that work into this # task (gap row 278). The file reaches this task through the trunk, so in both run modes the kind # reads as off, and nothing offers a setup that would collide with it. Unknown would fail every # review until that branch lands, with no answer in this task that repairs it. With no branch and a # person present, the kind reads as off and gets the off kind's offer. Unattended, nobody takes # that offer, so the check stays unknown and names the route. The surfaces skill writes the # project record's field. RW_SURFACE_BRANCH="" case "$SF_STATE" in missing|absent) RW_SURFACE_BRANCH="$(sf_branch_with "$RV_CODEPATH" "$(printf '%s' "$RW_PROJECT_DOC" | jq -r '.surfaces.registryPath // ""')")" if [ -n "$RW_SURFACE_BRANCH" ]; then on_word="on with its surface file on a branch" elif [ "$RW_RUN_MODE" = "interactive" ]; then on_word="on with no surface file"; fi if [ -n "$on_word" ]; then [ "$e2e_on" != "on" ] || e2e_on="$on_word" [ "$vr_on" != "on" ] || vr_on="$on_word" fi ;; esac # Per kind: off, not declined, not answered "not this task" on this task, and the recipe carries # its surface row. Rows that are not absent are how review knows the framework has that kind at # all. The two are separate capabilities, so declining one never silences the other's offer. A # surface file on another branch silences both: one file serves every kind, so any setup collides. e2e_declined="$(printf '%s' "$RW_PROJECT_DOC" | jq -r '.surfaces.e2e.declined // false')" vr_declined="$(printf '%s' "$RW_PROJECT_DOC" | jq -r '.surfaces.visualRegression.declined // false')" task_deferred=" $(jq -r '(.surfacesDeferred // []) | join(" ")' "$TASK_PATH/task.json" 2>/dev/null) " open_kinds=""; relevant_off=""; deferred_kinds="" if [ "$e2e_on" != "on" ] && [ "$(printf '%s' "$RW_SURFACE_ROWS" | jq '[ .[] | select(.id == "e2e" and (.absent // false) == false) ] | length')" -gt 0 ]; then relevant_off="yes" if [ "$e2e_declined" = "true" ] || [ -n "$RW_SURFACE_BRANCH" ]; then : elif [ "${task_deferred#* e2e }" != "$task_deferred" ]; then deferred_kinds="end to end" else open_kinds="end to end"; fi fi if [ "$vr_on" != "on" ] && [ "$(printf '%s' "$RW_SURFACE_ROWS" | jq '[ .[] | select(.id == "visual-regression" and (.absent // false) == false) ] | length')" -gt 0 ]; then relevant_off="yes" if [ "$vr_declined" = "true" ] || [ -n "$RW_SURFACE_BRANCH" ]; then : elif [ "${task_deferred#* visual-regression }" != "$task_deferred" ]; then deferred_kinds="${deferred_kinds:+$deferred_kinds and }visual regression" else open_kinds="${open_kinds:+$open_kinds and }visual regression"; fi fi # The offer, which the skill makes and this action only records what it can decide. if [ -n "$open_kinds" ]; then if [ "$RW_RUN_MODE" = "autonomous" ]; then setup="not-offered-autonomous"; else setup="available"; fi elif [ "$SF_STATE" = "ok" ]; then setup="registered" elif [ -n "$RW_SURFACE_BRANCH" ]; then setup="file-on-another-branch" elif [ -n "$deferred_kinds" ]; then setup="not-this-task" elif [ -n "$relevant_off" ]; then setup="declined" else setup="not-applicable" fi checks_file="$(mktemp)" || die 3 "acceptance: could not create a temporary file" surfaces_file="$(mktemp)" || die 3 "acceptance: could not create a temporary file" # Visual parity has no project field, so the recipe is the only thing that can say whether it runs: # a commanded row reaches the ordinary path, and anything else reads unavailable. parity_on="unavailable" [ "$(printf '%s' "$RW_SURFACE_ROWS" | jq --arg id "visual-parity" '[ .[] | select(.id == $id and (has("argv")) and ((.absent // false) == false)) ] | length')" -gt 0 ] \ && parity_on="on" # A light task runs its registered demo-path script like any end to end surface. A missing # script is not a failure: the verifier's evidence is the light task's acceptance (audit/24). rw_surface_kind "$CHECK_E2E" "e2e" "e2e" "$e2e_on" "$accepted" "$checks_file" "$surfaces_file" # A light task runs no visual regression. Implementation's start logged the skip (gap row 197). if [ "${vr_on%% *}" = "on" ] && task_is_light "$TASK_PATH"; then rw_check_row "$CHECK_VR" "undeclared" "a light run skips visual regression, so review ran nothing for it. $COMPROMISES_FILE in the task folder records the skip." >>"$checks_file" else rw_surface_kind "$CHECK_VR" "visual-regression" "visual-regression" "$vr_on" "$accepted" "$checks_file" "$surfaces_file" fi rw_surface_kind "$CHECK_PARITY" "visual-parity" "visual-parity" "$parity_on" "$accepted" "$checks_file" "$surfaces_file" rw_surface_extra_rows "$checks_file" "e2e e2e-preflight visual-regression visual-parity$RW_ACCEPTED_ROWS" # A person accepted a baseline for a surface whose kinds declare no accept row. Recording a boolean # and writing nothing would say a baseline was replaced when none was. while IFS= read -r one_accept; do [ -n "$one_accept" ] || continue case " $RW_ACCEPTED_DONE " in *" $one_accept "*) ;; *) die 3 "acceptance: --accept-baseline named $one_accept, and no surface row the review recipe declares writes a baseline for the kinds that surface carries. The recipe needs a row whose id is the kind's own id with -accept after it. Nothing was written." ;; esac done <&2 [ -z "$RW_SURFACE_BRANCH" ] \ || echo "ACCEPTANCE: branch $RW_SURFACE_BRANCH holds the surface file. It reaches this task once that branch lands on the trunk. Until then a kind marked on reads as off here. Offer no setup, and do not tell the person to bring that branch into this task." >&2 [ -z "$deferred_kinds" ] \ || echo "ACCEPTANCE: this task answered not this task for $deferred_kinds, so the offer is not made again." >&2 case "$setup" in available) echo "ACCEPTANCE: $open_kinds still open, with surface rows in the recipe and no decline recorded. Offer setup here, once, for $open_kinds." >&2 ;; declined) echo "ACCEPTANCE: every kind that is off has been declined, and none of them is offered again." >&2 ;; not-offered-autonomous) echo "ACCEPTANCE: $open_kinds still open, with surface rows in the recipe and no decline recorded. Nobody is present, so the offer was not made." >&2 ;; esac exit 0 } # ------------------------------------------------------------------------------------------------ # `close`: check 1, the criterion verdicts, the contract write and the verdict. # ------------------------------------------------------------------------------------------------ do_close() { local task_arg="" rows="" rows_raw="" corrected="" arg cid value while [ "$#" -gt 0 ]; do case "$1" in --row) [ "$#" -ge 2 ] || die 3 "close: --row needs =met|unmet" case "$2" in *=*) ;; *) die 3 "close: --row takes =met|unmet, got: $2" ;; esac cid="${2%%=*}"; value="${2#*=}" [ -n "$cid" ] || die 3 "close: --row was given no criterion id: $2" # A criterion whose wording is wrong: the ruling keeps the corrected text beside the frozen # one, and completion hands it to scope as a follow-up (gap row 450). case "$value" in contract-wrong:*) is_blank "${value#contract-wrong:}" || corrected="$corrected$(printf '%s\t%s' "$cid" "${value#contract-wrong:}") " value="contract-wrong" ;; esac # The word is held to its own kind of row once the record is read, and a wrong one is # named and dropped (live-run row 430). rows="$rows$(printf '%s\t%s' "$cid" "$value") " rows_raw="$rows_raw$2 " shift 2 ;; -*) die 3 "close: unrecognized argument: $1" ;; *) [ -z "$task_arg" ] || die 3 "close: more than one task folder given" task_arg="$1"; shift ;; esac done rw_paths "close" "$task_arg" rw_require_finished "close" rw_require_frozen "close" rv_load_codepath "close" rw_load_record "close" printf '%s' "$RW_RECORD_DOC" | jq -e 'has("evidence")' >/dev/null 2>&1 \ || die 62 "close: $RECORD_FILE records no evidence rows, so the acceptance step recorded nothing a person can answer from. Run acceptance, dispatch the acceptance verifier, then run acceptance --evidence first." rw_refuse_moved_code "close" "commit-only" rw_refuse_changed_criteria "close" # The texts each changed-text row records are the ones the reviewer was given. A change since # then is one nobody judged, and an accept must not record it (gap rows 410 and 506). [ "$(printf '%s' "$RW_RECORD_DOC" | jq -cS '[ (.checks // [])[] | select(has("frozenText")) | (.id | ltrimstr("decision-") | capture("^(?.*)-(?non-goal|criterion)$")) + {frozen: .frozenText, live: .liveText} ] | sort_by(.kind, .id)')" \ = "$(rw_person_changes | jq -cS 'sort_by(.kind, .id)')" ] \ || rw_pass_moved "close" "$ALIGNMENT_FILE changed a non-goal or a criterion since brief ran, so the reviewer judged another text." rw_dropped_since_brief "close" [ -z "$rows" ] || task_require_person 70 close "--row, a person's judgement of a checklist row," "$TASK_PATH" review "review close" "" "$rows_raw" # A person rules a finding that fails a criterion (gap row 329). wrong: the reviewer was mistaken, # so the criterion reads its own answer. deferred: the finding is real and waits, so it becomes # follow-up and completion offers it as a task. test-wrong: a frozen test is wrong, so `reopen` # sends the finding to the test author of the order that froze it (gap row 449). # contract-wrong: the criterion's wording is wrong, so the finding is follow-up with the corrected # text beside it, and completion hands it to scope (gap row 450). fix: the person wants it fixed # in this task, so it fails its criterion and `reopen` sends it to the order that owns its file # (gap row 479). The finding stays in the record either way, and `ruling` holds the person's # word. A medium or high finding that cites no criterion fails its lens check, so the person may # rule it the same way (gap row 337). Any finding of a reviewer lens may take a ruling, so a low # one can take fix. A frozen-tests finding decides no check. # fix and test-wrong depend on the finding's file. A file a frozen record holds takes test-wrong # and not fix. Any other file takes fix and not test-wrong, because no test author can change it. local rulable_findings ruled person_owned person_checks dropped rulable_findings="$(printf '%s' "$RW_RECORD_DOC" | jq -c --arg lenses "$LENS_WORDS" '[ (.findings // [])[] | . as $f | select(.disposition == "criterion" or has("ruling") or (($lenses | split(" ") | index($f.lens)) != null)) | .id ]')" # A finding's file is resolved against the code path, as reopen resolves it, so a ./ or an # absolute path names the same frozen test. local in_frozen_tests='[]' frozen_paths f_id f_file f_abs rw_load_test_rows "close" frozen_paths="$(printf '%s' "$RW_TEST_ROWS" | jq -c '[ .[] | (.tests // [])[] | .path ]')" while IFS=' ' read -r f_id f_file; do [ -n "$f_file" ] || continue f_abs="$(normalize_abs "$(resolve_against "$f_file" "$RV_CODEPATH")")" if [ "$(printf '%s' "$frozen_paths" | jq --arg p "${f_abs#"$RV_CODEPATH"/}" 'index($p) != null')" = true ]; then in_frozen_tests="$(printf '%s' "$in_frozen_tests" | jq -c --arg i "$f_id" '. + [$i]')" fi done < 0))')" dropped="$(jq -Rrn --argjson po "$person_owned" --argjson pc "$person_checks" --argjson pf "$rulable_findings" \ --argjson texted "$texted" --argjson ff "$in_frozen_tests" --rawfile given /dev/stdin "$RW_ROW_WORDS_JQ"' [ ($given | split("\n"))[] | split("\t") | select(length == 2) | . as [$id, $w] | if ($po | index($id)) == null and ($pc | index($id)) == null and ($pf | index($id)) == null then $id + "=" + $w + " (no such row waits)" elif ($id | row_words | index($w)) == null then $id + "=" + $w + " (it takes " + ($id | row_words | or_list) + ")" elif $w == "contract-wrong" and ($texted | index($id)) == null then $id + "=" + $w + " (it takes the corrected text after a colon)" elif $w == "fix" and ($ff | index($id)) != null then $id + "=" + $w + " (its file is a frozen test, so rule it test-wrong)" elif $w == "test-wrong" and ($pf | index($id)) != null and ($ff | index($id)) == null then $id + "=" + $w + " (no frozen record holds its file)" else empty end ] | join(", ")' <[\\\\^$.|?*+()\\[\\]{}-])"; "\\\(.c)")) as $n | select($out | test("(^|[^A-Za-z0-9_])" + $n + "($|[^A-Za-z0-9_])")) ] | length > 0')" case "$suite_verdict" in # not-needed reads the row state the same way met does. No order in the snapshot runs a # test, so no suite was ever going to name this criterion, and the row state two lines up # already says the build confirmed it. Falling through to unanswered read "no sign off" # over a record that says the opposite (live-run row 167). met|not-needed) case "$state" in confirmed) verdict="met" ;; rejected) verdict="unmet" ;; *) verdict="unanswered" ;; esac ;; unmet) if [ "$hit" = "true" ]; then verdict="unmet"; else verdict="unanswered"; fi ;; *) verdict="unanswered" ;; esac fi # A finding `findings` recorded with disposition criterion fails the criterion it cites, however # the row above answered (gap row 274), until a person rules it wrong (gap row 329). failed_by="$(printf '%s' "$RW_RECORD_DOC" | jq -r --arg id "$cid" \ '[ (.findings // [])[] | select(.disposition == "criterion" and .linkedTo == $id and .ruling != "wrong") | .id ] | join(", ")')" if [ -n "$failed_by" ]; then verdict="unmet"; answered="script"; cited_by="$cited_by $cid on $failed_by;" fi case "$verdict" in unanswered) unanswered=$((unanswered + 1)) ;; unmet) unmet_count=$((unmet_count + 1)) ;; esac jq -nc --arg id "$cid" --arg verifiedBy "$kind" --arg verdict "$verdict" --arg answeredBy "$answered" \ '{id: $id, verifiedBy: $verifiedBy, verdict: $verdict, answeredBy: $answeredBy}' >>"$rows_out" i=$((i + 1)) done criteria_json="$(jq -s '.' "$rows_out")" || die 3 "close: could not assemble the criterion rows" rm -f "$rows_out" # A record `findings` wrote before gap row 274 routed low findings through criteria. Close does # not judge severity, so it names them and sends the person back to the producer. A low finding # a person ruled carries disposition criterion by that ruling, so it is not named. stale_low="$(printf '%s' "$RW_RECORD_DOC" | jq -r \ '[ (.findings // [])[] | select(.disposition == "criterion" and .severity == "low" and (.ruling // "") == "") | .id ] | join(", ")')" local check_one_verdict check_one_detail if [ "$unmet_count" -gt 0 ]; then check_one_verdict="unmet" check_one_detail="$unmet_count criterion row(s) read unmet, so the task is not done.${cited_by:+ A finding fails each of these:${cited_by%;}.}${stale_low:+ These low findings carry disposition criterion from an older findings step, so run findings again: $stale_low.}" elif [ "$unanswered" -gt 0 ]; then check_one_verdict="unknown" check_one_detail="$unanswered criterion row(s) read unanswered, and a criterion nobody could reach is never a pass." else check_one_verdict="met" check_one_detail="every criterion in the frozen contract reads met." fi ruled="$(printf '%s' "$RW_RECORD_DOC" | jq -r '[ (.findings // [])[] | select(has("ruling")) | .id + " " + .ruling ] | join(", ")')" check_one_detail="$check_one_detail${ruled:+ The person ruled these findings: $ruled.}" local dropped_words dropped_words="$(printf '%s' "$RW_DROPPED" | jq -r '[ .[] | .id + " with " + ([ .orders[].id ] | join(", ")) ] | join("; ")')" check_one_detail="$check_one_detail${dropped_words:+ A person dropped $dropped_words.}" local updated verdict_word failing updated="$(printf '%s' "$RW_RECORD_DOC" | jq -c --argjson criteria "$criteria_json" --argjson dropped "$RW_DROPPED" \ --argjson one "$(rw_check_row "$CHECK_EVERY_CRITERION" "$check_one_verdict" "$check_one_detail")" ' .criteria = $criteria | if $dropped == [] then del(.droppedCriteria) else .droppedCriteria = $dropped end | .checks = ([$one] + (.checks | map(select(.id != "every-criterion"))))')" # A decision an unattended build left takes the person's --row (gap row 279), and so do rows the # acceptance verifier judged not met. local check_rows check_rows="$(jq -Rcn --argjson pc "$person_checks" --rawfile given /dev/stdin ' [ ($given | split("\n"))[] | split("\t") | select(length == 2) | select(($pc | index(.[0])) != null) | .[1] as $w | {id: .[0], word: $w, verdict: (if (["met", "wrong", "deferred", "keep", "accept"] | index($w)) != null then "met" else "unmet" end)} ]' </dev/null 2>&1; then keep_dir="$(mktemp -d)" || die 3 "close: could not create a temporary folder" for one_kept in "$FINDINGS_TARGET" "$BRIEF_FILE"; do [ ! -e "$one_kept" ] || cp -p "$one_kept" "$keep_dir/" || die 63 "close: could not copy $one_kept aside, so the write was refused." done rw_archive_files "close" "$(rw_record_short)" "$FINDINGS_TARGET" "$BRIEF_FILE" "$RECORD_FILE" for one_kept in "$FINDINGS_TARGET" "$BRIEF_FILE"; do [ ! -e "$keep_dir/$(basename "$one_kept")" ] || mv "$keep_dir/$(basename "$one_kept")" "$one_kept" \ || die 63 "close: could not put $one_kept back from $keep_dir." done rmdir "$keep_dir" fi # A decision an unattended build left, still unanswered, holds the verdict back (gap row 279). # The record keeps every row without one, so a later close answers it with --row, no fresh pass. # A criterion only a person answers, such as one checked after a gated push, reads unanswered # until the person answers it. The route is a later close at this commit (gap row 378). # Every row that waits is named once, with the words it takes (live-run row 430). A person # criterion waits when this call gave it no row. Once any row waits, the later close needs every # person criterion again, because a close keeps no earlier answer for one. local waiting waiting_rows person_line="" waiting_rows="$(rw_rows_waiting "$updated" \ "$(printf '%s' "$person_owned" | jq -c --arg given "$rows" '([ ($given | split("\n"))[] | split("\t")[0] ]) as $g | map(select(. as $i | $g | index($i) | not))')" \ "$rulable_findings")" [ -z "$waiting_rows" ] || waiting_rows="$(rw_rows_waiting "$updated" "$person_owned" "$rulable_findings")" [ -z "$waiting_rows" ] \ || person_line="CLOSE: these rows wait for the person, with the words each takes: $waiting_rows. When the person answers, run close again at this commit with one --row = each. A light or autonomous run takes the rows from the task's answer record, step review close, which person-answer.sh writes." waiting="$(printf '%s' "$updated" | jq -r '[ (.checks // [])[] | select((.id | startswith("decision-")) and .verdict == "unknown") | .id ] | join(", ")')" if [ -n "$waiting" ]; then rw_write_record "close" "$(printf '%s' "$updated" | jq -c 'del(.verdict)')" rw_print_summary "$updated" "close" echo "CLOSE: no verdict yet, because these decisions wait for the person: $waiting." >&2 echo "$person_line" >&2 exit 0 fi # The verdict rules. A criterion reading unmet fails the review: the contract is not met. Every # other check reading unmet or unknown, and a criterion reading unanswered, is a warning. The # person reads the warnings at this close, and completion stops on them when nobody is present. failing="$(printf '%s' "$updated" | jq -r '[ (.criteria // [])[] | select(.verdict == "unmet") | (.id + " reads unmet") ] | join("; ")')" if [ -n "$failing" ]; then verdict_word="failed"; else verdict_word="passed"; fi updated="$(printf '%s' "$updated" | jq -c --arg v "$verdict_word" --arg pv "$(plugin_version)" --arg every "$CHECK_EVERY_CRITERION" ' .verdict = $v | .pluginVersion = $pv | .warnings = ([ (.checks // [])[] | select(.id != $every and (.verdict == "unmet" or .verdict == "unknown")) | {id, verdict} ] + [ (.criteria // [])[] | select(.verdict == "unanswered") | {id, verdict} ] + [ (.findings // [])[] | select(.ruling == "test-wrong") | {id, verdict: "unmet"} ])')" rw_write_record "close" "$updated" # The one field review writes into the contract. The hash covers the whole file, but `start` # compares the contract without verdicts, so this write stops no order (gap row 319). # A scope sidecar that read current before this write keeps its stamp (gap row 313). local live_state written missing_ids new_alignment scope_stale written=0; missing_ids="" scope_stale="$(distill_stale "$TASK_PATH" scope)" || exit $? live_state="$(json_file_state "$ALIGNMENT_FILE")" if [ "$live_state" = "ok" ]; then new_alignment="$(jq -c --argjson rows "$criteria_json" ' .criteria = [ (.criteria // [])[] | . as $c | ([ $rows[] | select(.id == $c.id) ][0]) as $row | if $row == null then $c else ($c | .verdict = $row.verdict) end ]' "$ALIGNMENT_FILE")" if [ -n "$new_alignment" ]; then write_atomic "$ALIGNMENT_FILE" "$new_alignment" written="$(printf '%s' "$new_alignment" | jq '[ (.criteria // [])[] ] | length')" if [ "$scope_stale" = no ] && [ -f "$TASK_PATH/records/scope-distill.json" ]; then distill_stamp "$TASK_PATH" scope fi fi missing_ids="$(jq -nr --argjson rows "$criteria_json" --slurpfile live "$ALIGNMENT_FILE" ' [ $rows[] | . as $r | select(((($live[0].criteria // []) | map(.id)) | index($r.id)) == null) | .id ] | join(", ")')" fi # The stage boundary: the task folder is committed, the record and the contract's verdicts # together, with the verdict word as the reason and, on a failure, what caused it. commit_stage_close "$TASK_PATH" review "Close review for $(jq -r '.id' "$TASK_PATH/task.json")" \ "the review $verdict_word${failing:+: $failing}" rw_print_summary "$updated" "close" printf 'contract: %s\n' "$ALIGNMENT_FILE" local undeclared_list unknown_list awaiting_list note_count undeclared_list="$(printf '%s' "$updated" | jq -r '[ (.checks // [])[] | select(.verdict == "undeclared") | .id ] | join(", ")')" unknown_list="$(printf '%s' "$updated" | jq -r '[ (.checks // [])[] | select(.verdict == "unknown" and .answeredBy != "nobody") | .id ] | join(", ")')" awaiting_list="$(printf '%s' "$updated" | jq -r '[ (.checks // [])[] | select(.verdict == "unknown" and .answeredBy == "nobody") | .id ] | join(", ")')" note_count="$(printf '%s' "$updated" | jq '(.catalogNotes // []) | length')" echo "CLOSE: the review $verdict_word. ${failing:+What caused it: $failing.} Warnings: $(printf '%s' "$updated" | jq -r '[ .warnings[] | .id + " reads " + .verdict ] | if length == 0 then "none" else join(", ") end'). Checks nothing declared: ${undeclared_list:-none}. Checks nobody could read: ${unknown_list:-none}. Checks awaiting the person: ${awaiting_list:-none}. Criteria reading unanswered: $unanswered. Catalog notes: $note_count." >&2 [ -z "$person_line" ] || echo "$person_line" >&2 case "$live_state" in ok) echo "CLOSE: review wrote one verdict per criterion into $ALIGNMENT_FILE, across $written criteria. That write moves the contract hash, but start compares the contract without verdicts, so it stops no order.${missing_ids:+ These criteria are in the frozen contract and not in the live one, so nothing was written for them: $missing_ids.}" >&2 ;; *) echo "CLOSE: $ALIGNMENT_FILE is $live_state, so no criterion verdict was written into the contract. The record holds them." >&2 ;; esac [ "$RW_TASK_STATE" != complete ] \ || echo "CLOSE: $RW_TASK_ID was marked complete before this review, and it stays complete. The verdict is in $RECORD_FILE, beside the completion in task.md. Completion does not run, and follow-ups still makes one task per follow up finding." >&2 exit 0 } # ------------------------------------------------------------------------------------------------ # `audit`: which checks fired or were bypassed, read off the record and nothing else. # ------------------------------------------------------------------------------------------------ # One line per check, in the record's order, with the word for how its verdict came about. `ran`: a # command or a lens ran and returned it. `read`: a record field decided it and nothing ran. `off`: # the project turned the thing off, a kind disabled, a row the recipe declares absent, an accept # row nobody asked for, a check reading not-needed. `could-not-look`: a recipe, a row, a file or a # tool was absent. Then one # line per surface row, run or not, with the reason: disabled, unaffected, or no harness when the # run itself did not happen. Then the counts per word over the checks. # # The row's own fields decide where they can: exitCode, absent, the id, the verdict, and the # mutation object's output, which is the one field a mutation run leaves, and its off, which a # project that has not opted in leaves. Three sets of rows write the same fields for different reasons, and there the # detail's fixed wording decides: a tool row undeclared with no command, a surface check undeclared # with no command, and a surface row not run. The wording is this script's own, and a field on # the row saying why nothing ran would make each a field read. Nothing here changes a verdict. # archive: the closed pass moves aside the way a re-run moves it, and nothing else changes. # implement's `start` calls it when a corrected verify clause reaches the snapshot after the review # closed, because that verdict judged the old clause (gap row 375). A pass with no verdict stays. do_archive() { [ "$#" -eq 1 ] || die 3 "archive: a task folder is required, and nothing else" rw_paths "archive" "$1" rw_load_record "archive" rw_archive_closed_record "archive" echo "action: archive" echo "record: $RECORD_FILE" } do_audit() { [ "$#" -ge 1 ] || die 3 "audit: a task folder is required" [ "$#" -le 1 ] || die 3 "audit: unrecognized extra argument: $2" rw_paths "audit" "$1" rw_load_record "audit" [ -n "$RW_RECORD_DOC" ] || die 3 "audit: $RECORD_FILE not found, so no review has run for this task and there is nothing to audit. Run checks first." printf '%s' "$RW_RECORD_DOC" | jq -r --arg lenses " non-goals solid dry architecture-fit guides framework-practices " ' . as $r | def how: .id as $id | .verdict as $v | .detail as $d | if has("exitCode") then "ran" elif (.absent // false) then "off" # A lens reading undeclared had no source and no diff to judge, so it looked at nothing. # Calling that `ran` contradicted the floors this stage applies before a lens verdict, and # completion prints these lines into the pull request body (live-run row 154). # A lens check holding only low findings waits for the person at close (gap row 274). elif $v == "unknown" and .answeredBy == "nobody" then "awaiting-person" # A decision an unattended build left reads as answered once a person gives it (gap row 279). elif ($id | startswith("decision-")) then "read" elif ($lenses | contains(" " + $id + " ")) then (if $v == "unknown" or $v == "undeclared" then "could-not-look" else "ran" end) elif $id == "every-criterion" or $id == "serves-a-criterion" then "read" elif $id == "test-and-mutation" then (if ($r.mutation | has("output")) then "ran" elif ($r.mutation.off // false) then "off" elif $v == "unknown" then "could-not-look" else "read" end) # The routed done-when clauses are answered by the reviewer, so a verdict on them is one it # returned. not-needed is no order routing a clause, and unknown is a clause nobody judged. elif $id == "absence-clauses" then (if $v == "not-needed" then "off" elif $v == "unknown" then "could-not-look" else "ran" end) elif ($id | endswith("-accept")) then "off" # A check no order asked for was turned off by the design, not missed by a reader. Without # this arm the suite row of a task built from document orders read could-not-look, which # completion then printed into the pull request body (live-run row 167). elif $v == "not-needed" then "off" elif $v == "met" then "read" elif ($d | test("the project record says|holds no enabled surface|declares its suite row absent")) then "off" elif ($d | test("does not apply to it|left no changed file")) then "read" else "could-not-look" end; # The two lists a surface check names in its detail, one id each, across every surface check. def named($lead): [ $r.checks[] | .detail | scan($lead + "[^.]*") | sub($lead; "") | split(", ") ] | add // []; (named("Disabled and not run: ")) as $disabled | (named("touched none of their declared paths: ")) as $unaffected # A check a person answered, or one nobody was present to answer, carries its detail here, # because completion prints these lines into the pull request body (gap row 274). So does a # surface check whose file another branch holds, so the body names that branch (gap row 278). # The body cuts the detail of a decision row, which quotes what a role wrote, so a row stays one # line whatever the detail holds (gap row 495). | ([ .checks[] | {id, verdict, how: how, note: ((if has("answeredBy") then " answeredBy=" + .answeredBy + ": " + .detail elif (.detail | test("Branch [^ ]+ holds it")) then ": " + .detail else "" end) | gsub("[\r\n]+"; " "))} ]) as $rows | [ $rows[] | "check(\(.id)): \(.verdict) \(.how)\(.note)" ] + [ .surfaces[] | .id as $sid | "surface(\($sid)): " + (if .ran then "run" elif ($disabled | index($sid)) != null then "not run: disabled" elif ($unaffected | index($sid)) != null then "not run: unaffected" else "not run: no harness" end) ] + [ "audit: " + ([ "ran", "read", "could-not-look", "awaiting-person", "off" ] | map(. as $w | $w + "=" + ([ $rows[] | select(.how == $w) ] | length | tostring)) | join(" ")) ] | .[]' || die 3 "audit: $RECORD_FILE could not be read as a review record." exit 0 } # ------------------------------------------------------------------------------------------------ # `step`: print one step file. # ------------------------------------------------------------------------------------------------ do_step() { local names part=1 names="$(md_basenames_in "$STEPS_DIR")" [ "$#" -ge 1 ] || die 3 "step: a step name is required. The steps are: $names" if [ "$#" -eq 3 ] && [ "$2" = "--part" ]; then part="$3"; set -- "$1"; fi [ "$#" -le 1 ] || die 3 "step: unrecognized extra argument: $2" case "$1" in */*|.|..|'') die 3 "step: a step name is one name and never a path; got: $1. The steps are: $names" ;; esac [ -f "$STEPS_DIR/$1.md" ] \ || die 3 "step: this skill ships no step file named $1. The steps are: $names" step_part "$STEPS_DIR" "$1" "$part" "$PLUGIN_ROOT/skills/review/scripts/review-actions.sh" case "$?" in 0) exit 0 ;; 2) die 3 "step: $1 has no part $part. Run step $1 to see the first part and the count of parts." ;; *) die 3 "step: $STEPS_DIR/$1.md could not be read." ;; esac } # ------------------------------------------------------------------------------------------------ # Dispatch # ------------------------------------------------------------------------------------------------ ACTION="${1:-}" if [ "$ACTION" = "-h" ] || [ "$ACTION" = "--help" ]; then usage exit 0 fi [ -n "$ACTION" ] || { usage; die 3 "no action given"; } shift case "$ACTION" in read) do_read "$@" ;; checks) do_checks "$@" ;; brief) do_brief "$@" ;; findings) do_findings "$@" ;; acceptance) do_acceptance "$@" ;; close) do_close "$@" ;; audit) do_audit "$@" ;; archive) do_archive "$@" ;; step) do_step "$@" ;; *) usage; die 3 "unknown action: $ACTION" ;; esac