From eda5259500c941deb9d2b2f6e2f940b5bfd12603 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 18 Jun 2026 15:03:08 +0000 Subject: [PATCH] chore: SessionStart hook to install polyglot toolchains Ephemeral web containers lose installed tools on restart. Add an idempotent, non-fatal SessionStart hook that (re)installs GNAT+gprbuild+GnuCOBOL (apt), ponyc (ponyup), and Alire alr 2.1.1 when missing, and ensures ponyc is on PATH. Appended alongside the existing R/Octave session-start hook. User-authorized. Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_015hmgREHNsxYCuim33yUF2c --- .claude/hooks/install-toolchains.sh | 81 +++++++++++++++++++++++++++++ .claude/settings.json | 4 ++ 2 files changed, 85 insertions(+) create mode 100755 .claude/hooks/install-toolchains.sh diff --git a/.claude/hooks/install-toolchains.sh b/.claude/hooks/install-toolchains.sh new file mode 100755 index 0000000..bd2fe1d --- /dev/null +++ b/.claude/hooks/install-toolchains.sh @@ -0,0 +1,81 @@ +#!/bin/bash +# SessionStart hook — install the polyglot build toolchains for this repo. +# +# Claude Code on the web runs in an ephemeral container: anything installed +# outside the cached project tree vanishes on restart. This hook reinstalls the +# toolchains the project depends on at the start of every session: +# * GNAT + gprbuild + GnuCOBOL (apt: gnat gprbuild gnucobol) +# * Pony (ponyc) via ponyup +# * Alire (alr) 2.1.1 (prebuilt release zip) +# +# Design rules: +# * IDEMPOTENT — each tool is skipped if it is already on PATH (command -v). +# * NON-FATAL — a failed download/install must NOT break the session. We never +# run `set -e`; every step is guarded and the script always exits 0. +# * Warnings (not errors) are logged so failures are visible in the session log. + +log() { echo "[install-toolchains] $*"; } +warn() { echo "[install-toolchains] WARNING: $*" >&2; } + +export DEBIAN_FRONTEND=noninteractive + +# --------------------------------------------------------------------------- +# GNAT + gprbuild + GnuCOBOL (apt) +# --------------------------------------------------------------------------- +if command -v gnatmake >/dev/null 2>&1 && command -v cobc >/dev/null 2>&1; then + log "GNAT/gprbuild/GnuCOBOL already present; skipping apt install." +else + log "Installing gnat gprbuild gnucobol via apt-get ..." + if ! sudo apt-get install -y gnat gprbuild gnucobol; then + warn "apt-get install of gnat/gprbuild/gnucobol failed; continuing." + fi +fi + +# --------------------------------------------------------------------------- +# Pony (ponyc) via ponyup +# --------------------------------------------------------------------------- +if command -v ponyc >/dev/null 2>&1; then + log "ponyc already present; skipping ponyup install." +else + log "Installing ponyc via ponyup ..." + if sh -c "$(curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/ponylang/ponyup/latest-release/ponyup-init.sh)"; then + if ! /root/.local/share/ponyup/bin/ponyup update ponyc release; then + warn "ponyup update ponyc release failed; continuing." + fi + else + warn "ponyup-init.sh download/run failed; continuing." + fi +fi + +# --------------------------------------------------------------------------- +# Alire (alr) 2.1.1 +# --------------------------------------------------------------------------- +if command -v alr >/dev/null 2>&1; then + log "alr already present; skipping Alire install." +else + log "Installing Alire (alr) 2.1.1 ..." + if curl -sSL -o /tmp/alr.zip https://github.com/alire-project/alire/releases/download/v2.1.1/alr-2.1.1-bin-x86_64-linux.zip; then + if ( cd /tmp && unzip -o -q alr.zip && sudo cp bin/alr /usr/local/bin/alr && chmod +x /usr/local/bin/alr ); then + log "alr installed to /usr/local/bin/alr" + else + warn "Alire unzip/copy failed; continuing." + fi + else + warn "Alire download failed; continuing." + fi +fi + +# --------------------------------------------------------------------------- +# Ensure ponyc is on PATH for future shells. +# --------------------------------------------------------------------------- +PONY_PATH_LINE='export PATH=/root/.local/share/ponyup/bin:$PATH' +if [ -f "$HOME/.bashrc" ] && grep -qF "$PONY_PATH_LINE" "$HOME/.bashrc"; then + log "ponyup PATH line already in ~/.bashrc; skipping." +else + log "Appending ponyup PATH line to ~/.bashrc" + echo "$PONY_PATH_LINE" >> "$HOME/.bashrc" || warn "Could not append to ~/.bashrc; continuing." +fi + +log "Done." +# Never fail the session, regardless of what happened above. +exit 0 diff --git a/.claude/settings.json b/.claude/settings.json index e06b033..c035985 100644 --- a/.claude/settings.json +++ b/.claude/settings.json @@ -6,6 +6,10 @@ { "type": "command", "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/session-start.sh" + }, + { + "type": "command", + "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/install-toolchains.sh" } ] }