Skip to content

Commit cd3f401

Browse files
Jonathan D.A. Jewellhyperpolymath
authored andcommitted
ci+hooks: auto-bootstrap Lean for web sessions + consolidate CI onto the script
Future-dependability follow-through (both authorized): 1. SessionStart hook (.claude/hooks/session-start.sh + .claude/settings.json): web/remote sessions auto-install the pinned Lean toolchain via proofs/bootstrap-lean.sh before the agent loop starts, so the proofs can be built/verified out of the box. Synchronous; resilient (a bootstrap failure warns but does not block the session); a no-op outside Claude Code on the web. 2. lean-proofs.yml now installs the toolchain through proofs/bootstrap-lean.sh instead of a bespoke elan step — single source of truth, and CI gains the GitHub-asset fallback so it stays green if release.lean-lang.org is down. bootstrap-lean.sh: shellcheck-clean (SC2016 on the intentional literal $PATH in --print-path is annotated). Verified: hook is a no-op when not remote and bootstraps when remote; `lean Tangle.lean` still reports 0 errors. https://claude.ai/code/session_01PgHpCFzwYB7Qy9L6kmR8CE
1 parent 12782b0 commit cd3f401

4 files changed

Lines changed: 58 additions & 4 deletions

File tree

.claude/hooks/session-start.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
# SPDX-License-Identifier: MPL-2.0
3+
# SessionStart hook — make Lean available in Claude Code on the web so the
4+
# proofs in proofs/Tangle.lean can be built and verified (the repo's working
5+
# rule: "every edit ends with a Lean compile").
6+
#
7+
# Thin wrapper over proofs/bootstrap-lean.sh (the single source of truth for
8+
# toolchain setup). Synchronous: guarantees Lean is ready before the agent
9+
# loop starts, so it never races a build/verify against a half-installed
10+
# toolchain. Web/remote sessions only; local developers use their own Lean.
11+
set -euo pipefail
12+
13+
[ "${CLAUDE_CODE_REMOTE:-}" = "true" ] || exit 0
14+
15+
REPO="${CLAUDE_PROJECT_DIR:-$(pwd)}"
16+
BOOT="$REPO/proofs/bootstrap-lean.sh"
17+
if [ ! -x "$BOOT" ]; then
18+
echo "session-start: $BOOT not found or not executable; skipping Lean bootstrap."
19+
exit 0
20+
fi
21+
22+
# Install the pinned toolchain (idempotent; ~16s cold, instant when cached).
23+
# A failure must not block the whole session — Lean just won't be ready, and
24+
# the developer can run proofs/bootstrap-lean.sh by hand.
25+
if "$BOOT"; then
26+
# Persist `lean` on PATH for the rest of the session.
27+
if [ -n "${CLAUDE_ENV_FILE:-}" ]; then
28+
"$BOOT" --print-path >> "$CLAUDE_ENV_FILE"
29+
fi
30+
else
31+
echo "session-start: Lean bootstrap failed; continuing without Lean." \
32+
"Run proofs/bootstrap-lean.sh manually once network is available." >&2
33+
fi
34+
exit 0

.claude/settings.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"hooks": {
3+
"SessionStart": [
4+
{
5+
"hooks": [
6+
{
7+
"type": "command",
8+
"command": "$CLAUDE_PROJECT_DIR/.claude/hooks/session-start.sh"
9+
}
10+
]
11+
}
12+
]
13+
}
14+
}

.github/workflows/lean-proofs.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@ jobs:
4040
with:
4141
persist-credentials: false
4242

43-
- name: Install elan
43+
- name: Bootstrap Lean toolchain (pinned; GitHub-asset fallback)
4444
run: |
45-
curl -sSf https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh \
46-
| sh -s -- -y --default-toolchain none
45+
# Single source of truth for toolchain setup (proofs/bootstrap-lean.sh).
46+
# Uses the normal elan dist server on open networks (GitHub runners);
47+
# falls back to the GitHub release asset if release.lean-lang.org is
48+
# unreachable, so CI stays green through dist-server outages.
49+
bash proofs/bootstrap-lean.sh
4750
echo "$HOME/.elan/bin" >> "$GITHUB_PATH"
4851
49-
- name: Pin Lean toolchain from proofs/lean-toolchain
52+
- name: Show pinned Lean version
5053
working-directory: proofs
5154
run: |
5255
test -f lean-toolchain || { echo "::error::proofs/lean-toolchain missing"; exit 1; }

proofs/bootstrap-lean.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ TC_PATH="$ELAN_DIR/toolchains/$TC_NAME"
4545

4646
# --print-path mode: just emit the PATH export (for eval), do no work.
4747
if [ "$PRINT_PATH" -eq 1 ]; then
48+
# $PATH is intentionally literal — it must expand when this line is later
49+
# eval'd / sourced, not now. Only %s (= $ELAN_DIR) expands here.
50+
# shellcheck disable=SC2016
4851
printf 'export PATH="%s/bin:$PATH"\n' "$ELAN_DIR"
4952
exit 0
5053
fi

0 commit comments

Comments
 (0)