]> git.ekhem.eu.org Git - guix.git/commitdiff
[ai] Extract build-queue dialog to standalone ask-build-queue script.
authorJakub Czajka <jakub@ekhem.eu.org>
Tue, 23 Jun 2026 20:49:10 +0000 (22:49 +0200)
committerJakub Czajka <jakub@ekhem.eu.org>
Tue, 7 Jul 2026 21:36:27 +0000 (23:36 +0200)
Move the AskUserQuestion dialog out of the guix-build Stop hook into
a separate script so it can be invoked proactively (before code changes
begin) rather than only at Stop time.

- ask-build-queue: new script with the build-target selection dialog.
  Exits early if a queue file already exists for the session.
- guix-build: simplified to use $CLAUDE_CODE_SESSION_ID directly
  instead of JSON parsing.  Delegates the no-queue case to
  ask-build-queue.
- CLAUDE.md: instructs to run ask-build-queue before any prompt that
  looks like it will modify code.

Co-Authored-By: Claude <noreply@anthropic.com>
.claude/hooks/ask-build-queue [new file with mode: 0755]
.claude/hooks/guix-build
CLAUDE.md

diff --git a/.claude/hooks/ask-build-queue b/.claude/hooks/ask-build-queue
new file mode 100755 (executable)
index 0000000..91089f8
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/sh
+# Copyright (c) 2026 Jakub Czajka <jakub@ekhem.eu.org>
+# 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})."
index 72f1ba12caed0b27078885d07470d4f1cf83b420..9c5a6b1d738698fca92a8fc6fab1539dd4ba86ef 100755 (executable)
 #   └─ success ──► remove from queue ──► exit 2
 #                                        build next on re-stop
 
-# Print space-separated Makefile targets with guix reconfigure.
 MAKEFILE="$CLAUDE_PROJECT_DIR/Makefile"
-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' ' '
-}
 
 if [ -z "$($HOME/.guix-home/profile/bin/git -C "$CLAUDE_PROJECT_DIR" \
      status --porcelain --untracked-files=no)" ]; then
@@ -51,19 +44,9 @@ fi
 $GUIX_BIN/mkdir --parents "$CLAUDE_PROJECT_DIR/.claude"
 QUEUE_FILE="$CLAUDE_PROJECT_DIR/.claude/.build-queue.$CLAUDE_CODE_SESSION_ID"
 
-# No queue file yet — ask the user which targets to build.
+# No queue file yet.
 if [ ! -f "$QUEUE_FILE" ]; then
-    exec 1>&2
-    $GUIX_BIN/echo "First, use AskUserQuestion (single-select) to ask whether"
-    $GUIX_BIN/echo "to build at all. Options: [Build targets, Skip build]."
-    $GUIX_BIN/echo ""
-    $GUIX_BIN/echo "If Build, use AskUserQuestion (multiSelect, max 4) with"
-    $GUIX_BIN/echo "these targets: $(build_targets "$MAKEFILE")."
-    $GUIX_BIN/echo ""
-    $GUIX_BIN/echo "Write selected targets to ${QUEUE_FILE} (one per line),"
-    $GUIX_BIN/echo "then stop so the build begins."
-    $GUIX_BIN/echo ""
-    $GUIX_BIN/echo "If Skip: write an empty file (touch ${QUEUE_FILE})."
+    "$CLAUDE_PROJECT_DIR/.claude/hooks/ask-build-queue"
     exit 2
 fi
 
index 5fd7a4fefc31080d981e2639027f04a0d6ce7881..882e84241b7c8a93e65d79a794d8d91e446ed9ab 100644 (file)
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -39,3 +39,10 @@ Core service types:
 - home-symlink-service-type (conf/home/symlink.scm) — symlinks files into the
   home directory. Strips the first path component of each dotfile to derive its
   $HOME-relative target.
+
+# Build Queue
+
+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.