Source index · Technical reference · Home

UNRELEASED DEVELOPMENT SNAPSHOT · READ-ONLY EXCERPT

bin/li-review-read

This is the cited technical source at local revision 275a354, inspected on 22 September 2026. It differs from the public release. This reference publishes only the cited sections, not an installable release or the development branch.

Line numbers refer to the complete recorded file. Uncited lines are omitted. Full-file SHA-256: 8af11e50968e4ffbcdcc59364ff44a71704fd73eb16e1fe84d96d90df4a9d218.

1#!/usr/bin/env bash
2# bin/li-review-read — native review-log reader for the release gate
3#
4# The release gate's "Review readiness check" calls this. It reads Lintel's own
5# audit log at .claude/runtime/audit/reviews.jsonl (with a global ~/.lintel/audit/
6# fallback for un-migrated repos) and emits the verdict shape the release gate
7# expects: whether an Eng Review is CLEAR within 7 days for the current commit.
8# First-party by design — no external binary on the read path.
9#
10# Grace-window cleanup (until 2026-09-12): any legacy review records written
11# before this remediation (${GSTACK_HOME:-$HOME/.gstack}/projects/<slug>/<branch>-reviews.jsonl)
12# are imported ONCE into the native reviews.jsonl, idempotently — a marker prevents
13# re-import — after which this reader reads only the native file. Historical entries
14# still count toward the gate; the legacy path stops being on the read path.
16# Usage:
… omitted uncited lines …
75HEAD_SHORT="$(git rev-parse --short HEAD 2>/dev/null || echo unknown)"
77# ── Derive the legacy review path (slug + branch) for the one-time import ──
78# Mirrors the historical slug derivation: sanitized to [a-zA-Z0-9._-]. Used only
79# by the grace-window import below, not on the steady-state read path.
80_legacy_review_file() {
81 local slug branch remote raw
82 remote="$(git remote get-url origin 2>/dev/null || echo "")"
83 if [ -n "$remote" ]; then
84 raw="$(printf '%s' "$remote" | sed 's|.*[:/]\([^/]*/[^/]*\)\.git$|\1|;s|.*[:/]\([^/]*/[^/]*\)$|\1|' | tr '/' '-')"
85 slug="$(printf '%s' "$raw" | tr -cd 'a-zA-Z0-9._-')"
86 fi
87 slug="${slug:-$(basename "$PWD" | tr -cd 'a-zA-Z0-9._-')}"
88 branch="$(git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -cd 'a-zA-Z0-9._-')"
89 branch="${branch:-unknown}"
90 printf '%s/projects/%s/%s-reviews.jsonl' "${GSTACK_HOME:-$HOME/.gstack}" "$slug" "$branch"
92LEGACY_LOG="$(_legacy_review_file)"
94# ── One-time grace-window import of legacy records into the native log ──
95# If a legacy review file exists and has not been imported yet, fold each of its
96# records into the native log exactly once — via audit_log() (the single sanctioned
97# JSONL writer), NOT a raw append, so the audit-writes-via-helper contract holds.
98# A marker (a plain state file, no .jsonl in its name) guards re-import. After this
99# the legacy path is no longer read; only the native file is. Removable after 2026-09-12.
100IMPORTED=0
101REVIEWS_DIR="$(dirname "$REVIEWS_LOG")"
102MARKER="$REVIEWS_DIR/reviews-legacy-import.done"
103if [ -f "$LEGACY_LOG" ] && command -v audit_log >/dev/null 2>&1; then
104 # Marker records which legacy file was already folded in (path keys the import).
105 if ! { [ -f "$MARKER" ] && grep -Fxq "$LEGACY_LOG" "$MARKER" 2>/dev/null; }; then
106 mkdir -p "$REVIEWS_DIR" 2>/dev/null || true
107 while IFS= read -r legacy_line; do
108 [ -z "$legacy_line" ] && continue
109 # Mirror li-review-log's record shape: preserve the legacy payload verbatim
110 # under "raw" (the verdict awk matches the escaped "skill" inside it) plus the
111 # parsed status/commit/review_ts when present.
112 l_skill="$(printf '%s' "$legacy_line" | sed -n 's/.*"skill"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p')"
113 l_status="$(printf '%s' "$legacy_line" | sed -n 's/.*"status"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p')"
114 l_commit="$(printf '%s' "$legacy_line" | sed -n 's/.*"commit"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p')"
115 l_ts="$(printf '%s' "$legacy_line" | sed -n 's/.*"timestamp"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p')"
116 audit_log reviews "${l_skill:-unknown}" \
117 "status=$l_status" "commit=$l_commit" "review_ts=$l_ts" "raw=$legacy_line"
118 IMPORTED=1
119 done < "$LEGACY_LOG"
120 # Append the imported legacy path to the marker (plain state file, not a log).
121 printf '%s\n' "$LEGACY_LOG" >> "$MARKER" 2>/dev/null || true