interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / tools / window_lane_guard.sh

108 lines · 5851 bytes Raw Blame History
1#!/bin/bash
2# SPDX-License-Identifier: Apache-2.0
3# Copyright 2026 Drake Stapleton (AIEN / aien-dev)
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Window lane evidence guard (omega #315). Source this from a window ladder (cand<N>_ladder.sh):
18# . "$(dirname "$0")/window_lane_guard.sh" (or from tools/ in the omega worktree)
19# It keeps a lane's receipts from being lost when a later lane runs `make clean`
20# (tools/m19r_qualify.sh does, and removes build/ with every receipt in build/qual-runs).
21# tools/chipwait_campaign.sh (the chipwait lane) sources this file and calls wl_guard_build
22# before every campaign; a ladder exports WINDOW_LANE_OUT=<window dir> and archives its R11
23# receipts (wl_r11_archive / wl_r11_archive_all) first, or the campaign refuses (exit 2).
24#
25# wl_begin <out> <lane> declare that <lane> will produce receipts that must be archived
26# wl_archive <out> <lane> <file> <dir> copy <file> to <dir>/<stem>.<sha256>.<ext> (never overwrites,
27# verifies the copy), then mark <lane> archived
28# wl_no_receipt <out> <lane> mark <lane> archived when it produced no receipt (explicit, logged)
29# wl_r11_archive <out> <build_dir> the r11 lane: archive the newest R11 receipt written by this run
30# into <out>/R11-living/ under its sha256 name
31# wl_r11_archive_all <out> <build_dir> archive every R11 receipt under <build_dir>/qual-runs
32# wl_guard_build <out|""> <lane> <build_dir> wl_guard_clean plus: refuse while any R11 receipt in
33# <build_dir>/qual-runs is unarchived (chipwait_campaign.sh calls it)
34# wl_guard_clean <out> <lane> call before any lane that runs `make clean`: returns 2 and says
35# which lane while an earlier lane's receipt is still unarchived
36#
37# State lives in <out>/.lane-guard/{pending,archived}/<lane>. Nothing here deletes or edits an existing file.
38wl_begin() { mkdir -p "$1/.lane-guard/pending" "$1/.lane-guard/archived"; date -u +%FT%TZ > "$1/.lane-guard/pending/$2"; }
39
40wl_archive() { # out lane file dir
41 local out=$1 lane=$2 f=$3 dir=$4
42 [ -s "$f" ] || { echo "wl_archive: $lane has no receipt at $f" >&2; return 1; }
43 local sha base stem ext dest
44 sha=$(sha256sum "$f" | cut -c1-64); base=$(basename "$f")
45 stem=${base%.*}; ext=${base##*.}
46 mkdir -p "$dir" "$out/.lane-guard/archived"
47 dest="$dir/$stem.$sha.$ext"
48 if [ -e "$dest" ]; then
49 [ "$(sha256sum "$dest" | cut -c1-64)" = "$sha" ] || { echo "wl_archive: $dest exists with other content" >&2; return 1; }
50 else
51 cp "$f" "$dest" || return 1
52 [ "$(sha256sum "$dest" | cut -c1-64)" = "$sha" ] || { echo "wl_archive: copy of $f does not match" >&2; return 1; }
53 fi
54 echo "$dest" >> "$out/.lane-guard/archived/$lane"
55}
56
57wl_no_receipt() { mkdir -p "$1/.lane-guard/archived"; echo "no receipt produced" >> "$1/.lane-guard/archived/$2"; }
58
59wl_r11_archive() { # out build_dir
60 local out=$1 b=$2 f
61 f=$(ls -1t "$b"/qual-runs/*/R11/rx_aien_faculty_receipt.json 2>/dev/null | head -1)
62 [ -n "$f" ] || { echo "wl_r11_archive: no R11 receipt under $b/qual-runs" >&2; return 1; }
63 wl_archive "$out" r11 "$f" "$out/R11-living"
64}
65
66wl_guard_clean() { # out lane
67 local p lane bad=0
68 for p in "$1"/.lane-guard/pending/*; do
69 [ -e "$p" ] || continue
70 lane=$(basename "$p")
71 [ "$lane" = "$2" ] && continue
72 if [ ! -s "$1/.lane-guard/archived/$lane" ]; then
73 echo "REFUSED: lane $2 runs make clean while lane $lane has an unarchived receipt" >&2; bad=1
74 fi
75 done
76 [ "$bad" = 0 ] || return 2
77}
78
79# wl_r11_archive_all <out> <build_dir>: archive EVERY R11 receipt under <build_dir>/qual-runs
80# (the ladder lane's R16 rung and the r11 lane both write one) into <out>/R11-living/.
81wl_r11_archive_all() { # out build_dir
82 local out=$1 b=$2 f n=0
83 for f in "$b"/qual-runs/*/R11/rx_aien_faculty_receipt.json; do
84 [ -e "$f" ] || continue
85 wl_archive "$out" r11 "$f" "$out/R11-living" || return 1; n=$((n + 1))
86 done
87 [ "$n" -gt 0 ] || { echo "wl_r11_archive_all: no R11 receipt under $b/qual-runs" >&2; return 1; }
88}
89
90# wl_guard_build <out|""> <lane> <build_dir>: called by tools/chipwait_campaign.sh (whose
91# m19r_qualify.sh runs `make clean`) before anything is cleaned. Returns 2 when
92# * <out> is set and an earlier lane's receipt is unarchived (wl_guard_clean), or
93# * any R11 receipt under <build_dir>/qual-runs has no byte-identical copy under
94# <out>/R11-living/ (or <out> is empty): the clean would destroy R11 evidence.
95wl_guard_build() { # out lane build_dir
96 local out=$1 lane=$2 b=$3 f sha bad=0
97 if [ -n "$out" ]; then wl_guard_clean "$out" "$lane" || bad=1; fi
98 for f in "$b"/qual-runs/*/R11/rx_aien_faculty_receipt.json; do
99 [ -e "$f" ] || continue
100 sha=$(sha256sum "$f" | cut -c1-64)
101 if [ -z "$out" ] || [ ! -f "$out/R11-living/rx_aien_faculty_receipt.$sha.json" ]; then
102 echo "REFUSED: lane $lane would clean $b while R11 receipt $f (sha256 $sha) is unarchived;" \
103 "set WINDOW_LANE_OUT=<window dir> and run wl_r11_archive_all <window dir> $b first" >&2
104 bad=1
105 fi
106 done
107 [ "$bad" = 0 ] || return 2
108}