graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Reuse checksum-pinned CI tool executables
justrachd02a2927dd93
diff --git a/.github/actions/setup-nanocompile-binary/action.yml b/.github/actions/setup-nanocompile-binary/action.ymlnew file mode 100644index 00000000..95c54bb7--- /dev/null+++ b/.github/actions/setup-nanocompile-binary/action.yml@@ -0,0 +1,40 @@+name: Setup pinned nanocompile binary+description: Restore a checksum-pinned executable or build its pinned source+inputs:+ binary-base-url:+ description: Optional HTTPS object-store base URL for pinned tool binaries+ default: ''+outputs:+ restored:+ description: Whether the checksum-pinned executable was downloaded+ value: ${{ steps.binary.outputs.restored }}+runs:+ using: composite+ steps:+ - name: Restore pinned executable+ id: binary+ shell: bash+ env:+ NANOCOMPILE_BINARY_BASE_URL: ${{ inputs.binary-base-url }}+ run: python3 scripts/install-nanocompile-ci.py++ - name: Checkout pinned nanocompile source+ if: steps.binary.outputs.restored != 'true'+ uses: actions/checkout@v7+ with:+ repository: justrach/nanocompile+ ref: dec24ac64b2c810cca247f850ed1784830362df5+ path: .nanocompile-source+ persist-credentials: false++ - name: Build pinned nanocompile source+ if: steps.binary.outputs.restored != 'true'+ shell: bash+ working-directory: .nanocompile-source+ run: zig build -Doptimize=ReleaseFast --prefix "$GITHUB_WORKSPACE/.nanocompile-tools"++ - name: Export pinned executable+ shell: bash+ run: |+ echo "NANOCOMPILE_EXE=$GITHUB_WORKSPACE/.nanocompile-tools/bin/nanocompile" >> "$GITHUB_ENV"+ echo "NANOCOMPILE_DIR=$GITHUB_WORKSPACE/.nanocompile-cache" >> "$GITHUB_ENV"diff --git a/.github/actions/setup-nanocompile/action.yml b/.github/actions/setup-nanocompile/action.ymlindex 2f271435..28ed6fba 100644--- a/.github/actions/setup-nanocompile/action.yml+++ b/.github/actions/setup-nanocompile/action.yml@@ -1,25 +1,18 @@name: Setup nanocompile release cache-description: Build a pinned nanocompile and restore the target's declared-task cache+description: Restore a pinned nanocompile and the target's declared-task cacheinputs:target:description: Release-matrix targetrequired: true+ binary-base-url:+ description: Optional HTTPS object-store base URL for pinned tool binaries+ default: ''runs:using: compositesteps:- - uses: actions/checkout@v7+ - uses: ./.github/actions/setup-nanocompile-binarywith:- repository: justrach/nanocompile- ref: dec24ac64b2c810cca247f850ed1784830362df5- path: .nanocompile-source- persist-credentials: false- - name: Build pinned nanocompile- shell: bash- working-directory: .nanocompile-source- run: |- zig build -Doptimize=ReleaseFast --prefix "$GITHUB_WORKSPACE/.nanocompile-tools"- echo "NANOCOMPILE_EXE=$GITHUB_WORKSPACE/.nanocompile-tools/bin/nanocompile" >> "$GITHUB_ENV"- echo "NANOCOMPILE_DIR=$GITHUB_WORKSPACE/.nanocompile-cache" >> "$GITHUB_ENV"+ binary-base-url: ${{ inputs.binary-base-url }}- name: Restore nanocompile task artifactsuses: actions/cache@v6with:diff --git a/.github/workflows/beta-release.yml b/.github/workflows/beta-release.ymlindex 49462b9a..5a21ff3b 100644--- a/.github/workflows/beta-release.yml+++ b/.github/workflows/beta-release.yml@@ -53,6 +53,7 @@ jobs:- uses: ./.github/actions/setup-nanocompilewith:target: ${{ matrix.target }}+ binary-base-url: ${{ secrets.NANOCOMPILE_BINARY_BASE_URL }}- name: Cross-compile beta CLI (${{ matrix.target }})env:BETA_VERSION: ${{ needs.plan.outputs.version }}diff --git a/.github/workflows/release-cache-benchmark.yml b/.github/workflows/release-cache-benchmark.ymlindex 5cafc0e8..6fcea1aa 100644--- a/.github/workflows/release-cache-benchmark.yml+++ b/.github/workflows/release-cache-benchmark.yml@@ -25,21 +25,18 @@ jobs:- name: Install pinned Zig without build cachesrun: python3 scripts/install-zig-ci.py- - name: Checkout pinned nanocompile+ - name: Setup pinned nanocompileif: matrix.mode == 'nano'- uses: actions/checkout@v7+ id: nanocompile+ uses: ./.github/actions/setup-nanocompile-binarywith:- repository: justrach/nanocompile- ref: dec24ac64b2c810cca247f850ed1784830362df5- path: .nanocompile-source- persist-credentials: false+ binary-base-url: ${{ secrets.NANOCOMPILE_BINARY_BASE_URL }}- - name: Build pinned nanocompile+ - name: Require the object-store binary for this experimentif: matrix.mode == 'nano'- working-directory: .nanocompile-source- run: |- zig build -Doptimize=ReleaseFast --prefix "$GITHUB_WORKSPACE/.nanocompile-tools"- echo "NANOCOMPILE_EXE=$GITHUB_WORKSPACE/.nanocompile-tools/bin/nanocompile" >> "$GITHUB_ENV"+ env:+ RESTORED: ${{ steps.nanocompile.outputs.restored }}+ run: test "$RESTORED" = true- name: Cold buildrun: python3 scripts/benchmark-release-cache.py --target '${{ matrix.target }}' --mode '${{ matrix.mode }}' --phase cold@@ -79,21 +76,18 @@ jobs:- name: Install pinned Zig without build cachesrun: python3 scripts/install-zig-ci.py- - name: Checkout pinned nanocompile+ - name: Setup pinned nanocompileif: matrix.mode == 'nano'- uses: actions/checkout@v7+ id: nanocompile+ uses: ./.github/actions/setup-nanocompile-binarywith:- repository: justrach/nanocompile- ref: dec24ac64b2c810cca247f850ed1784830362df5- path: .nanocompile-source- persist-credentials: false+ binary-base-url: ${{ secrets.NANOCOMPILE_BINARY_BASE_URL }}- - name: Build pinned nanocompile+ - name: Require the object-store binary for this experimentif: matrix.mode == 'nano'- working-directory: .nanocompile-source- run: |- zig build -Doptimize=ReleaseFast --prefix "$GITHUB_WORKSPACE/.nanocompile-tools"- echo "NANOCOMPILE_EXE=$GITHUB_WORKSPACE/.nanocompile-tools/bin/nanocompile" >> "$GITHUB_ENV"+ env:+ RESTORED: ${{ steps.nanocompile.outputs.restored }}+ run: test "$RESTORED" = true- name: Restore measured build cachesuses: actions/cache/restore@v6diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex fbc00713..3f06bf71 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -49,6 +49,7 @@ jobs:- uses: ./.github/actions/setup-nanocompilewith:target: ${{ matrix.target }}+ binary-base-url: ${{ secrets.NANOCOMPILE_BINARY_BASE_URL }}- name: Cross-compile (${{ matrix.target }})env:diff --git a/docs/adr/0293-ci-reuses-checksum-pinned-tool-binaries.md b/docs/adr/0293-ci-reuses-checksum-pinned-tool-binaries.mdnew file mode 100644index 00000000..0edc4e24--- /dev/null+++ b/docs/adr/0293-ci-reuses-checksum-pinned-tool-binaries.md@@ -0,0 +1,33 @@+# 0293: CI reuses checksum-pinned tool binaries++## Context++Building a cache tool in every release job adds work before it can reuse any+artifacts. The tool executable is independent of the release target: the Linux+matrix needs one host executable, not one build for every output architecture.++## Decision++Allow CI to download a prebuilt nanocompile executable from an optional HTTPS+object-store base URL supplied through repository configuration. Keep the+storage location out of source. Identify an object by source revision, Zig+version, host target, and SHA-256; verify the checked-in digest before making+it executable. A digest mismatch fails setup rather than trusting the store.++The initial host artifact uses the pinned source and Zig compiler, Linux+x86-64 baseline CPU features, static musl linking, and stripped debug data.+No local build paths or credentials belong in the uploaded artifact. Seeding+uploads only the executable; CI requires no write credentials for the store.++An unavailable object, unset location, unsupported host, or different Zig+version uses the existing pinned-source build. Release task caching and its+byte-identical restore verification remain unchanged. The benchmark requires+the downloaded executable so a silent source-build fallback cannot be reported+as a successful measurement of binary reuse.++## Consequences++Tool updates require building and checking a new artifact, publishing it under+its digest-qualified key, and reviewing the new pin together. An object-store+compromise alone cannot replace the executable accepted by CI. The source+fallback preserves availability but does not promise equivalent setup cost.diff --git a/docs/adr/README.md b/docs/adr/README.mdindex a73e8294..56652dd4 100644--- a/docs/adr/README.md+++ b/docs/adr/README.md@@ -309,6 +309,7 @@ record only when you need the evidence or the edge cases.| [0291](0291-release-builds-use-declared-task-caching.md) | Pin nanocompile and cache complete release build tasks with explicit inputs, tool resources, and a verified byte-identical restore before packaging. || [0292](0292-sol-subscription-context-is-500k.md) | GPT-6.1 Sol uses a 500k subscription window on Codex and ChatGPT sign-in; smaller catalog windows still win, other models retain their conservative caps, and API maxima do not widen subscription defaults. |+| [0293](0293-ci-reuses-checksum-pinned-tool-binaries.md) | Restore pinned CI executables from optional object storage only after checking a reviewed SHA-256; unavailable artifacts retain the pinned-source fallback. |## When to write onediff --git a/scripts/install-nanocompile-ci.py b/scripts/install-nanocompile-ci.pynew file mode 100644index 00000000..d4b67efa--- /dev/null+++ b/scripts/install-nanocompile-ci.py@@ -0,0 +1,77 @@+#!/usr/bin/env python3+"""Restore a pinned CI tool; never execute unchecked object-store bytes."""+import argparse+import hashlib+import os+from pathlib import Path+import platform+import subprocess+import urllib.error+import urllib.parse+import urllib.request+++REVISION = "dec24ac64b2c810cca247f850ed1784830362df5"+ZIG_VERSION = "0.17.0"+TARGET = "x86_64-linux-musl"+SHA256 = "8f7943e71444caf00a5c2563e69f360d6b32ad97f368e829cbb6f7c449e3bf45"+ROOT = Path(__file__).resolve().parents[1]+++def object_key():+ return f"ci-tools/nanocompile/{REVISION}/zig-{ZIG_VERSION}/{TARGET}/{SHA256}/nanocompile"+++def restore(base_url, destination):+ if not base_url or platform.system() != "Linux" or platform.machine().lower() not in ("x86_64", "amd64"):+ return False+ if subprocess.check_output(["zig", "version"], text=True).strip() != ZIG_VERSION:+ return False+ parsed = urllib.parse.urlsplit(base_url)+ if parsed.scheme != "https" or not parsed.netloc or parsed.username or parsed.password or parsed.query or parsed.fragment:+ raise RuntimeError("The tool-store base URL must be a credential-free HTTPS URL")+ destination.parent.mkdir(parents=True, exist_ok=True)+ partial = destination.with_suffix(".download")+ request = urllib.request.Request(base_url.rstrip("/") + "/" + object_key(),+ headers={"User-Agent": "nanocompile-ci-installer/1"})+ try:+ digest = hashlib.sha256()+ total = 0+ try:+ with urllib.request.urlopen(request, timeout=60) as response, partial.open("wb") as output:+ while chunk := response.read(1024 * 1024):+ total += len(chunk)+ if total > 64 * 1024 * 1024:+ raise RuntimeError("Pinned tool download exceeds its size limit")+ digest.update(chunk)+ output.write(chunk)+ except (urllib.error.URLError, TimeoutError, OSError):+ print("Pinned executable unavailable; building pinned source instead")+ return False+ if digest.hexdigest() != SHA256:+ raise RuntimeError("Pinned nanocompile executable failed SHA-256 verification")+ partial.chmod(0o755)+ partial.replace(destination)+ print("Restored checksum-verified pinned nanocompile executable")+ return True+ finally:+ partial.unlink(missing_ok=True)+++def main():+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument("--print-key", action="store_true")+ args = parser.parse_args()+ if args.print_key:+ print(object_key())+ return+ restored = restore(os.environ.get("NANOCOMPILE_BINARY_BASE_URL", ""),+ ROOT / ".nanocompile-tools/bin/nanocompile")+ if not restored:+ print("Using pinned source-build fallback")+ with open(os.environ["GITHUB_OUTPUT"], "a") as output:+ output.write("restored=" + str(restored).lower() + "\n")+++if __name__ == "__main__":+ main()