From: Jakub Czajka Date: Mon, 6 Jul 2026 09:43:07 +0000 (+0200) Subject: [ai] Move ask-build-queue from hooks/ to scripts/. X-Git-Url: https://git.ekhem.eu.org/?a=commitdiff_plain;h=bd309d49e31546a25e6fcfea469f6d8a5005e110;p=guix.git [ai] Move ask-build-queue from hooks/ to scripts/. Relocates the build-queue dialog from the hooks directory to the scripts directory, reflecting its role as a manually-invoked helper rather than an automatic hook. Also adds branch-awareness: the script now asks about builds on non-main branches and reconfigures on main. --- diff --git a/.claude/hooks/ask-build-queue b/.claude/hooks/ask-build-queue deleted file mode 100755 index 91089f8..0000000 --- a/.claude/hooks/ask-build-queue +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh -# Copyright (c) 2026 Jakub Czajka -# License: GPL-3.0 or later. -# -# ask-build-queue — Prompt the user to select Makefile targets and write a -# per-session build queue file. - -# Don't prompt again if the queue is already populated. -QUEUE_FILE="$CLAUDE_PROJECT_DIR/.claude/.build-queue.$CLAUDE_CODE_SESSION_ID" -if [ -f "$QUEUE_FILE" ]; then - exit 0 -fi - -MAKEFILE="$CLAUDE_PROJECT_DIR/Makefile" - -# Print space-separated Makefile targets whose recipe mentions -# guix reconfigure. -build_targets() { - $GUIX_BIN/sed --regexp-extended --quiet \ - '/^([a-zA-Z_-][a-zA-Z0-9_-]*):/h - /guix.*reconfigure/{g;s/^([a-zA-Z_-][a-zA-Z0-9_-]*):.*/\1/p}' \ - "$1" | $GUIX_BIN/tr '\n' ' ' -} - - -$GUIX_BIN/mkdir --parents "$CLAUDE_PROJECT_DIR/.claude" - -exec 1>&2 -echo "First, use AskUserQuestion (single-select) to ask whether to build at " -echo "all. Options: [Build targets, Skip build]." -echo "" -echo "If Build, use AskUserQuestion (multiSelect, max 4) with these targets: " -echo "$(build_targets "$MAKEFILE")." -echo "" -echo "Write selected targets to ${QUEUE_FILE} (one per line), then stop so the " -echo "build begins." -echo "" -echo "If Skip: write an empty file (touch ${QUEUE_FILE})." diff --git a/.claude/hooks/guix-build b/.claude/hooks/guix-build index 9c5a6b1..59ab6b4 100755 --- a/.claude/hooks/guix-build +++ b/.claude/hooks/guix-build @@ -46,7 +46,7 @@ QUEUE_FILE="$CLAUDE_PROJECT_DIR/.claude/.build-queue.$CLAUDE_CODE_SESSION_ID" # No queue file yet. if [ ! -f "$QUEUE_FILE" ]; then - "$CLAUDE_PROJECT_DIR/.claude/hooks/ask-build-queue" + "$CLAUDE_PROJECT_DIR/.claude/scripts/ask-build-queue" exit 2 fi @@ -77,4 +77,4 @@ fi # Queue is empty — we are finished. $GUIX_BIN/echo '{"systemMessage":"✅ Queue finished."}' $GUIX_BIN/rm --force "$QUEUE_FILE" -exit 0 + diff --git a/.claude/scripts/ask-build-queue b/.claude/scripts/ask-build-queue new file mode 100755 index 0000000..46d5783 --- /dev/null +++ b/.claude/scripts/ask-build-queue @@ -0,0 +1,43 @@ +#!/bin/sh +# Copyright (c) 2026 Jakub Czajka +# License: GPL-3.0 or later. +# +# ask-build-queue — Prompt the user to select Makefile targets and write a +# per-session build queue file. + +# Don't prompt again if the queue is already populated. +QUEUE_FILE="$CLAUDE_PROJECT_DIR/.claude/.build-queue.$CLAUDE_CODE_SESSION_ID" +[ -f "$QUEUE_FILE" ] && exit 0 + +# Print space-separated Makefile targets whose recipe matches the +# branch-appropriate guix command: reconfigure on main, build elsewhere. +build_targets() { + if [ "$2" = "main" ]; then + pattern="guix.*reconfigure" + else + pattern="guix.*build" + fi + $GUIX_BIN/sed --regexp-extended --quiet \ + "/^([a-zA-Z_-][a-zA-Z0-9_-]*):/h + /$pattern/{g;s/^([a-zA-Z_-][a-zA-Z0-9_-]*):.*/\1/p}" \ + "$1" | $GUIX_BIN/tr '\n' ' ' +} + +$GUIX_BIN/mkdir --parents "$CLAUDE_PROJECT_DIR/.claude" + +MAKEFILE="$CLAUDE_PROJECT_DIR/Makefile" + +branch=$($HOME/.guix-home/profile/bin/git -C "$CLAUDE_PROJECT_DIR" \ + branch --show-current 2>/dev/null || $GUIX_BIN/echo "unknown") + +exec 1>&2 +echo "First, use AskUserQuestion (single-select) to ask whether to build at " +echo "all. Options: [Build targets, Skip build]." +echo "" +echo "If Build, use AskUserQuestion (multiSelect, max 4) with these targets: " +echo "$(build_targets "$MAKEFILE" "$branch")." +echo "" +echo "Write selected targets to ${QUEUE_FILE} (one per line), then stop so the " +echo "build begins." +echo "" +echo "If Skip: write an empty file (touch ${QUEUE_FILE})." diff --git a/CLAUDE.md b/CLAUDE.md index 882e842..1457a51 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -45,4 +45,4 @@ Core service types: Populate the build queue early to avoid an extra dialog at Stop time. If the prompt looks like it will modify code (e.g. "add", "fix", "change", "implement", "refactor", "update", "create", "remove") and the build queue does not exist, -run .claude/hooks/ask-build-queue to queue build targets before making changes. +run .claude/scripts/ask-build-queue to queue build targets before any changes.