interplane.Get Omega
Read in your language

omega-mcp

aien-dev/omega-mcp

Brought by drakestapleton

branch main Branches Tags History

omega-mcp / build.sh

108 lines · 5541 bytes Raw Blame History
1#!/bin/sh
2# Build omega-mcp with the pinned Omega compiler.
3# OMEGA_SRC=/path/to/omega-mv ./build.sh (a git clone of omega-mv that contains the PIN revision; default ../omega-mv)
4# OMC=/path/to/omc OMEGA_SRC=... ./build.sh (use this omc binary instead of the one at the PIN revision)
5# PIN is the only file that names the pin: `omega-mv REV` and `omc-sha256 SHA`. Everything else is derived:
6# build/omc REV:seed/out/omc from OMEGA_SRC (or $OMC); refused (exit 2) unless its sha256 is SHA
7# build/omega-mv/ the units src/UNITS names as `omega-mv:PATH`, read from REV in OMEGA_SRC at every build
8# (no copy of them is tracked here; exit 2 names a PATH that REV does not hold)
9# data/ rewritten by tools/gen-reference.py from the source at REV (citation lines, keyword ids,
10# the keyword total); it stops the build (exit 1) when a cited quote is missing or repeated
11# at REV. data/ is committed, so after a repin `git diff data/` is the reviewable change
12# build/pin.om the texts kpin (SHA) and kmv (REV, 8 characters) the server units use: the start-up check
13# compares the compiler beside the server with kpin; initialize and compile report them
14# build/pincheck gates/pincheck.om, run over `git ls-files`: a tracked file that restates the pin or names
15# another hash fails the build (exit 1), so no copy of the pin can drift from PIN
16# build/agent-maintenance-mcp the separate agent-file maintenance server, built from maintenance/UNITS the
17# same way as the compiler server (same pinned omc, same omega-mv units); gates/maintenance-cases.sh
18# build/agent-qa-mcp the agent Q&A server, built from qa/UNITS the same way; gates/qa-cases.sh
19# Output: build/omega-mcp, build/agent-maintenance-mcp, build/agent-qa-mcp, build/omc, build/data/,
20# build/pincheck; data/ regenerated.
21# The server unit is the concatenation listed in src/UNITS: the sha256 unit first (its `layout` must precede
22# every fn; `export fn` becomes `fn` because a program unit has a `fn main`), then the JSON units, the
23# generated pin unit and the server units. The leading `om2` line opts the whole unit into profile OM-2.
24set -eu
25cd "$(dirname "$0")"
26die() { echo "build.sh: $2" >&2; exit "$1"; }
27[ -f PIN ] || die 2 "PIN is missing"
28set -- $(cat PIN)
29[ $# -eq 4 ] && [ "$1" = omega-mv ] && [ "$3" = omc-sha256 ] || die 2 "PIN must be two lines: omega-mv REV, omc-sha256 SHA"
30rev=$2 sha=$4
31case $rev$sha in *[!0-9a-f]*) die 2 "PIN: REV and SHA must be lowercase hex" ;; esac
32[ ${#rev} -eq 40 ] && [ ${#sha} -eq 64 ] || die 2 "PIN: REV must have 40 hex digits and SHA 64"
33src=${OMEGA_SRC:-../omega-mv}
34git -C "$src" cat-file -e "$rev^{commit}" 2>/dev/null || die 2 "$src is not a git clone of omega-mv containing $rev (set OMEGA_SRC)"
35git rev-parse --is-inside-work-tree >/dev/null 2>&1 || die 2 "the pin check needs a git checkout of omega-mcp (git ls-files)"
36mkdir -p build
37rm -f build/omc.new build/omega-mcp.new build/agent-maintenance-mcp.new build/agent-qa-mcp.new build/pincheck.new
38if [ -n "${OMC:-}" ]; then
39 cp "$OMC" build/omc.new
40else
41 git -C "$src" cat-file blob "$rev:seed/out/omc" > build/omc.new || die 2 "omega-mv $rev has no seed/out/omc"
42fi
43chmod 755 build/omc.new
44got=$(sha256sum build/omc.new | cut -d' ' -f1)
45if [ "$got" != "$sha" ]; then
46 rm -f build/omc.new
47 die 2 "${OMC:-omega-mv $rev:seed/out/omc} has sha256 $got, not the PIN omc-sha256 $sha"
48fi
49rm -rf build/omega-mv
50for u in src/UNITS maintenance/UNITS qa/UNITS; do
51 for f in $(sed -n 's/^omega-mv://p' "$u"); do
52 mkdir -p "build/omega-mv/$(dirname "$f")"
53 git -C "$src" cat-file blob "$rev:$f" > "build/omega-mv/$f" 2>/dev/null ||
54 die 2 "omega-mv $rev has no $f ($u names it as omega-mv:$f)"
55 done
56done
57python3 tools/gen-reference.py --omega-src "$src" > build/gen.out 2>&1 || {
58 cat build/gen.out >&2; die 1 "tools/gen-reference.py could not write data/ from omega-mv $rev"; }
59{
60 echo "note generated by build.sh from PIN; edit PIN, never this file"
61 echo "text kpin \"$sha\""
62 echo "text kmv \"$(echo "$rev" | cut -c1-8)\""
63} > build/pin.om
64concat() {
65 {
66 printf 'om2\n'
67 first=1
68 while read -r f; do
69 case "$f" in ''|'#'*) continue ;; omega-mv:*) f=build/omega-mv/${f#omega-mv:} ;; esac
70 if [ $first = 1 ]; then
71 sed 's/^export fn /fn /' "$f" | grep -v '^om2$'
72 first=0
73 else
74 cat "$f"
75 fi
76 done < "$1"
77 } > "$2"
78}
79unit=build/omega-mcp.om
80concat src/UNITS "$unit"
81munit=build/agent-maintenance-mcp.om
82concat maintenance/UNITS "$munit"
83qunit=build/agent-qa-mcp.om
84concat qa/UNITS "$qunit"
85compile() {
86 rc=0
87 build/omc.new < "$1" > "$2" 2> build/omc.err || rc=$?
88 if [ $rc -ne 0 ]; then
89 cat build/omc.err >&2
90 rm -f "$2"
91 die 1 "omc refused $1 (exit $rc); line numbers refer to $1"
92 fi
93 chmod 755 "$2"
94}
95compile "$unit" build/omega-mcp.new
96compile "$munit" build/agent-maintenance-mcp.new
97compile "$qunit" build/agent-qa-mcp.new
98compile gates/pincheck.om build/pincheck.new
99rc=0
100git ls-files | build/pincheck.new >&2 || rc=$?
101[ $rc -eq 0 ] || die 1 "pin check failed (exit $rc): see the findings above"
102mv build/pincheck.new build/pincheck
103mv build/omega-mcp.new build/omega-mcp
104mv build/agent-maintenance-mcp.new build/agent-maintenance-mcp
105mv build/agent-qa-mcp.new build/agent-qa-mcp
106mv build/omc.new build/omc
107rm -rf build/data && cp -R data build/data
108sha256sum build/omega-mcp build/agent-maintenance-mcp build/agent-qa-mcp build/omc