From 5be0df99bd989a67fa613e6c3518746a033e2801 Mon Sep 17 00:00:00 2001 From: Josui Date: Wed, 18 Nov 2026 00:25:48 +0000 Subject: [PATCH 1/2] feat: ship the ashigaru CLI and Desk hooks; sdlc runs .sdlc/bin/sdlc (a244) - Install ashigaru from the 3.x release RPM, ASHIGARU_VERSION=3.0.0. - Managed hooks call /usr/libexec/developer/ashigaru-hook beside seat-state; it is a silent no-op until ASHIGARU_URL and a key are staged. - /usr/local/bin/sdlc execs a converted repo's .sdlc/bin/sdlc instead of exiting 2 for want of a pinned rev. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01R7Y1jg3ZJ6BsAEfhrPWFRh --- .github/workflows/container.yml | 3 + CHANGELOG.md | 14 +++ Containerfile | 16 +++- README.md | 9 +- .../managed-settings.d/40-developer-seat.json | 25 ++++++ rootfs/usr/libexec/developer/ashigaru-hook | 36 ++++++++ rootfs/usr/local/bin/sdlc | 13 ++- tests/test_ashigaru_hook.py | 88 +++++++++++++++++++ tests/test_sdlc_wrapper.py | 13 +++ tests/test_seat_state.py | 12 +-- 10 files changed, 221 insertions(+), 8 deletions(-) create mode 100755 rootfs/usr/libexec/developer/ashigaru-hook create mode 100644 tests/test_ashigaru_hook.py diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index e0da5fa..b2be153 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -57,6 +57,9 @@ jobs: bash -n /usr/local/bin/developer-worker-claude test -x /usr/local/bin/developer-worker-claude test -x /usr/libexec/developer/seat-state + test -x /usr/libexec/developer/ashigaru-hook + ashigaru --help > /dev/null + echo "{}" | /usr/libexec/developer/ashigaru-hook stop python3 -m json.tool /etc/claude-code/managed-settings.d/40-developer-seat.json > /dev/null ' secrets: diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a630a3..4300a05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,20 @@ All notable changes to this project are documented here. The format follows ## [Unreleased] +### Added +- The `ashigaru` CLI, from the Ashigaru 3.x release RPM (`ASHIGARU_VERSION`, + pinned to 3.0.0). +- Managed hooks run `/usr/libexec/developer/ashigaru-hook` beside seat-state + on SessionStart, UserPromptSubmit, Stop, StopFailure and the idle_prompt + Notification, reporting the seat's turn and task to the Desk through + `ashigaru hook`. It does nothing until the seat has `ASHIGARU_URL` and a key + (`ASHIGARU_API_KEY_FILE` or `ASHIGARU_API_KEY`). seat-state stays until the + cutover. + +### Fixed +- `sdlc` runs a converted repo's own `.sdlc/bin/sdlc` instead of exiting 2 + for want of a pinned python-sdlc `rev:`. + ## [1.14.1] - 2026-11-17 ### Fixed diff --git a/Containerfile b/Containerfile index 9ca52cd..ffd2e6d 100644 --- a/Containerfile +++ b/Containerfile @@ -68,6 +68,11 @@ LABEL description="developer - a crunchtools development agent: Claude Code with # bump both files together, by hand. ARG CLAUDE_CODE_VERSION=2.1.304 ARG CLAUDE_AGENT_VERSION=1.2.0 +# The Ashigaru CLI, whose `ashigaru hook` reports this seat to the Desk. 3.x +# is a Python package shipped as an RPM on each GitHub release, built on +# fedora:43 and centos:stream10; the fc43 build is noarch against Python 3.14, +# which is this base's too. A bump is this one line. +ARG ASHIGARU_VERSION=3.0.0 USER 0 @@ -113,6 +118,15 @@ RUN dnf -y upgrade && \ python3 -c 'import sys; assert sys.version_info[:2] >= (3, 14), sys.version' && \ uv --version && tmux -V && podman --version +# Straight from the release over TLS, not from a dnf repository: the +# crunchtools repo does not carry ashigaru, and a release that has no RPM +# attached fails the build here rather than shipping a seat without the CLI. +RUN dnf -y install --setopt=install_weak_deps=0 \ + "https://github.com/crunchtools/ashigaru/releases/download/v${ASHIGARU_VERSION}/ashigaru-${ASHIGARU_VERSION}-1.fc43.noarch.rpm" && \ + dnf -y clean all && \ + rm -rf /var/cache/dnf && \ + ashigaru --help > /dev/null + # uid 1000 is the base's own `podman` user, with the subuid ranges that make # nesting work. It is NOT renamed to josui: that layout is the reason this # base was chosen, and HOME follows it instead. @@ -123,7 +137,7 @@ COPY rootfs/ / RUN chmod 0755 /usr/local/bin/developer-entrypoint /usr/local/bin/developer-worker-claude \ /usr/local/bin/developer-skills-sync \ - /usr/libexec/developer/seat-state && \ + /usr/libexec/developer/seat-state /usr/libexec/developer/ashigaru-hook && \ bash -n /usr/local/bin/developer-entrypoint # HOME is a volume: the Claude login, sessions, git identity and the agent's diff --git a/README.md b/README.md index 5588322..030b229 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,11 @@ task's result starts a turn like a typed prompt does, but leaves `state`, for about a minute, until Claude Code's idle notification ends it; if someone types in that minute, it stays `active` until the next turn ends. +The same events also go to the Ashigaru Desk through `ashigaru hook`, which +applies the same rules. That hook does nothing until the seat is given +`ASHIGARU_URL` and a key (`ASHIGARU_API_KEY_FILE`, or `ASHIGARU_API_KEY`); both +run until the cutover retires seat-state.json. + A worker with `JOSUI_MATRIX_HOMESERVER` set is held by `claude-agent run` instead: one session that the Matrix bridge texts into, Remote Control reaches and `claude-agent send` prompts. claude-agent keeps it in tmux on a server of @@ -109,7 +114,9 @@ The point of this image is that `sdlc push` runs here in minutes instead of a CI round trip. Measured on a trentina clone, 2026-11-06: **293s in a seat against 416s on the laptop** for the same tier, the same night. -`sdlc` is on `PATH`. It reads the `rev:` the repo pins for python-sdlc in +`sdlc` is on `PATH`. In a converted repo, one carrying `.sdlc/bin/sdlc`, it +runs that file, as the repo's hooks and CI do. Otherwise it reads the `rev:` +the repo pins for python-sdlc in `.pre-commit-config.yaml`, clones that exact tag once into `~/.cache/crunchtools-sdlc`, and execs its launcher — so a gate run by hand and the same gate in CI are the same tool. It never guesses a version: python-sdlc's diff --git a/rootfs/etc/claude-code/managed-settings.d/40-developer-seat.json b/rootfs/etc/claude-code/managed-settings.d/40-developer-seat.json index 95c6261..bb22e41 100644 --- a/rootfs/etc/claude-code/managed-settings.d/40-developer-seat.json +++ b/rootfs/etc/claude-code/managed-settings.d/40-developer-seat.json @@ -8,6 +8,11 @@ "type": "command", "command": "/usr/libexec/developer/seat-state prompt", "timeout": 10 + }, + { + "type": "command", + "command": "/usr/libexec/developer/ashigaru-hook prompt-submit", + "timeout": 10 } ] } @@ -19,6 +24,11 @@ "type": "command", "command": "/usr/libexec/developer/seat-state start", "timeout": 10 + }, + { + "type": "command", + "command": "/usr/libexec/developer/ashigaru-hook session-start", + "timeout": 10 } ] } @@ -30,6 +40,11 @@ "type": "command", "command": "/usr/libexec/developer/seat-state stop", "timeout": 10 + }, + { + "type": "command", + "command": "/usr/libexec/developer/ashigaru-hook stop", + "timeout": 10 } ] } @@ -41,6 +56,11 @@ "type": "command", "command": "/usr/libexec/developer/seat-state stop", "timeout": 10 + }, + { + "type": "command", + "command": "/usr/libexec/developer/ashigaru-hook stop", + "timeout": 10 } ] } @@ -53,6 +73,11 @@ "type": "command", "command": "/usr/libexec/developer/seat-state stop", "timeout": 10 + }, + { + "type": "command", + "command": "/usr/libexec/developer/ashigaru-hook stop", + "timeout": 10 } ] } diff --git a/rootfs/usr/libexec/developer/ashigaru-hook b/rootfs/usr/libexec/developer/ashigaru-hook new file mode 100755 index 0000000..a960689 --- /dev/null +++ b/rootfs/usr/libexec/developer/ashigaru-hook @@ -0,0 +1,36 @@ +#!/bin/sh +# Report this seat's turn and task to the Ashigaru Desk, or do nothing. +# +# Run by Claude Code's managed hooks (40-developer-seat.json) beside +# seat-state, which keeps ~/.claude/seat-state.json until the Desk cutover: +# +# ashigaru-hook session-start | prompt-submit | stop +# +# A seat learns where its Desk is from ASHIGARU_URL, and its key from +# ASHIGARU_API_KEY_FILE (a mounted file) or ASHIGARU_API_KEY. Until both are +# staged for a seat, this exits 0 having read the event and said nothing: the +# image ships ahead of the keys, and a seat without them is not misconfigured, +# only not yet cut over. With both, `ashigaru hook` does the work and owns the +# rules, including its own time bound and an exit that is always 0. +# +# Nothing goes to stdout here, which UserPromptSubmit would add to the +# conversation. + +skip() { + # Read the event anyway, so Claude Code never writes into a closed pipe. + cat > /dev/null + exit 0 +} + +[ -n "${ASHIGARU_URL:-}" ] || skip +if [ -n "${ASHIGARU_API_KEY_FILE:-}" ]; then + [ -r "$ASHIGARU_API_KEY_FILE" ] || skip +elif [ -z "${ASHIGARU_API_KEY:-}" ]; then + skip +fi + +if ! command -v ashigaru > /dev/null 2>&1; then + echo "ashigaru-hook: the Desk is configured but ashigaru is not installed" >&2 + skip +fi +exec ashigaru hook "$@" diff --git a/rootfs/usr/local/bin/sdlc b/rootfs/usr/local/bin/sdlc index 6673097..da72ba0 100755 --- a/rootfs/usr/local/bin/sdlc +++ b/rootfs/usr/local/bin/sdlc @@ -1,5 +1,9 @@ #!/bin/bash -# Run the python-sdlc this repository pins, from an interactive shell. +# Run the python-sdlc this repository uses, from an interactive shell. +# +# A converted repo (.sdlc/bin/sdlc) is run through that file, exactly as its +# hooks and CI run it. The rest of this script is for a repo that still pins +# python-sdlc with a `rev:` in .pre-commit-config.yaml. # # The pre-push hook finds `sdlc` because pre-commit manages its own cache; a # person typing in a seat's terminal does not, and `sdlc push` is the whole @@ -24,6 +28,13 @@ die() { root=$(git rev-parse --show-toplevel 2>/dev/null) || die "not inside a git repository, so there is no pinned python-sdlc to run" +# A converted repo carries python-sdlc's bootstrap as .sdlc/bin/sdlc and pins +# no rev: its hooks and its CI job run that file, which takes the launcher +# from the image. Run it too, or this gate and theirs are different tools. +if [ -x "$root/.sdlc/bin/sdlc" ]; then + exec "$root/.sdlc/bin/sdlc" "$@" +fi + config="$root/.pre-commit-config.yaml" [ -f "$config" ] || die "$config does not exist, so this repo pins no python-sdlc" diff --git a/tests/test_ashigaru_hook.py b/tests/test_ashigaru_hook.py new file mode 100644 index 0000000..e372dc7 --- /dev/null +++ b/tests/test_ashigaru_hook.py @@ -0,0 +1,88 @@ +"""ashigaru-hook: `ashigaru hook` once the Desk is configured, nothing before.""" + +from __future__ import annotations + +import os +import shutil +import subprocess +import tempfile +import unittest +from pathlib import Path + +HOOK = Path(__file__).resolve().parent.parent / "rootfs/usr/libexec/developer/ashigaru-hook" +EVENT = '{"hook_event_name": "UserPromptSubmit", "prompt": "hi"}' + + +class AshigaruHookTest(unittest.TestCase): + def setUp(self) -> None: + tmp = tempfile.TemporaryDirectory() + self.addCleanup(tmp.cleanup) + self.root = Path(tmp.name) + # A stand-in ashigaru that records its argv and what it read. + bin_dir = self.root / "bin" + bin_dir.mkdir() + self.calls = self.root / "calls" + stub = bin_dir / "ashigaru" + stub.write_text(f'#!/bin/sh\necho "$*" >> {self.calls}\ncat >> {self.calls}\n') + stub.chmod(0o755) + self.key = self.root / "key" + self.key.write_text("secret\n") + self.path = f"{bin_dir}:{os.environ['PATH']}" + + def run_hook(self, env: dict[str, str], *args: str) -> subprocess.CompletedProcess[str]: + return subprocess.run( + ["sh", str(HOOK), *args], + input=EVENT, + env={"PATH": self.path, "HOME": str(self.root), **env}, + capture_output=True, + text=True, + check=False, + ) + + def assert_skipped(self, result: subprocess.CompletedProcess[str]) -> None: + self.assertEqual(result.returncode, 0) + self.assertEqual(result.stdout, "") + self.assertEqual(result.stderr, "") + self.assertFalse(self.calls.exists()) + + def test_it_runs_ashigaru_hook_with_the_event(self) -> None: + env = {"ASHIGARU_URL": "https://desk.example", "ASHIGARU_API_KEY_FILE": str(self.key)} + result = self.run_hook(env, "prompt-submit") + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(self.calls.read_text(), f"hook prompt-submit\n{EVENT}") + + def test_a_key_in_the_environment_is_a_key(self) -> None: + env = {"ASHIGARU_URL": "https://desk.example", "ASHIGARU_API_KEY": "secret"} + self.assertEqual(self.run_hook(env, "stop").returncode, 0) + self.assertTrue(self.calls.read_text().startswith("hook stop\n")) + + def test_without_a_url_it_does_nothing(self) -> None: + self.assert_skipped(self.run_hook({"ASHIGARU_API_KEY_FILE": str(self.key)}, "stop")) + + def test_without_a_key_it_does_nothing(self) -> None: + self.assert_skipped(self.run_hook({"ASHIGARU_URL": "https://desk.example"}, "stop")) + + def test_a_key_file_not_yet_staged_is_no_key(self) -> None: + env = {"ASHIGARU_URL": "https://desk.example", "ASHIGARU_API_KEY_FILE": str(self.root / "nope")} + self.assert_skipped(self.run_hook(env, "stop")) + + def test_configured_without_the_cli_says_so_and_exits_0(self) -> None: + # A PATH with cat and nothing else, so an ashigaru on this host is not found. + bare = self.root / "bare" + bare.mkdir() + (bare / "cat").symlink_to(shutil.which("cat") or "/bin/cat") + env = {"ASHIGARU_URL": "https://desk.example", "ASHIGARU_API_KEY": "secret"} + result = subprocess.run( + [shutil.which("sh") or "/bin/sh", str(HOOK), "stop"], + input=EVENT, + env={"PATH": str(bare), "HOME": str(self.root), **env}, + capture_output=True, + text=True, + check=False, + ) + self.assertEqual(result.returncode, 0) + self.assertEqual(result.stdout, "") + self.assertIn("not installed", result.stderr) + + def test_it_is_executable(self) -> None: + self.assertTrue(HOOK.stat().st_mode & 0o111) diff --git a/tests/test_sdlc_wrapper.py b/tests/test_sdlc_wrapper.py index a480aaa..b9b0f74 100644 --- a/tests/test_sdlc_wrapper.py +++ b/tests/test_sdlc_wrapper.py @@ -122,6 +122,19 @@ def test_a_dot_dot_rev_cannot_escape_the_cache(self) -> None: self.assertIn("not a plain tag", result.stderr) self.assertFalse((self.root / "escaped").exists()) + def test_a_converted_repo_runs_its_own_launcher(self) -> None: + # No `rev:` at all: the repo's hooks and CI run .sdlc/bin/sdlc. + (self.repo / ".pre-commit-config.yaml").write_text("repos:\n - repo: local\n") + launcher = self.repo / ".sdlc/bin/sdlc" + launcher.parent.mkdir(parents=True) + launcher.write_text('#!/bin/sh\necho "repo launcher got: $*"\n') + launcher.chmod(0o755) + (self.repo / "sub").mkdir() + result = self.run_wrapper("push", "--flag", cwd=self.repo / "sub") + self.assertEqual(result.returncode, 0, result.stderr) + self.assertIn("repo launcher got: push --flag", result.stdout) + self.assertFalse((self.root / "cache").exists()) + def test_an_unreachable_rev_is_a_could_not_run(self) -> None: self.write_config(rev="v0.0.0-nope") result = self.run_wrapper("push") diff --git a/tests/test_seat_state.py b/tests/test_seat_state.py index 8139f44..871580d 100644 --- a/tests/test_seat_state.py +++ b/tests/test_seat_state.py @@ -326,10 +326,12 @@ def test_hooks_run_seat_state_from_the_image(self) -> None: event: [h["command"] for group in hooks[event] for h in group["hooks"]] for event in ("UserPromptSubmit", "Stop", "StopFailure", "Notification", "SessionStart") } - self.assertEqual(commands["UserPromptSubmit"], ["/usr/libexec/developer/seat-state prompt"]) - self.assertEqual(commands["Stop"], ["/usr/libexec/developer/seat-state stop"]) - self.assertEqual(commands["StopFailure"], ["/usr/libexec/developer/seat-state stop"]) - self.assertEqual(commands["Notification"], ["/usr/libexec/developer/seat-state stop"]) + state, desk = "/usr/libexec/developer/seat-state", "/usr/libexec/developer/ashigaru-hook" + # Both until the Desk cutover: seat-state.json and the Desk. + self.assertEqual(commands["UserPromptSubmit"], [f"{state} prompt", f"{desk} prompt-submit"]) + self.assertEqual(commands["Stop"], [f"{state} stop", f"{desk} stop"]) + self.assertEqual(commands["StopFailure"], [f"{state} stop", f"{desk} stop"]) + self.assertEqual(commands["Notification"], [f"{state} stop", f"{desk} stop"]) self.assertEqual([group.get("matcher") for group in hooks["Notification"]], ["idle_prompt"]) - self.assertEqual(commands["SessionStart"], ["/usr/libexec/developer/seat-state start"]) + self.assertEqual(commands["SessionStart"], [f"{state} start", f"{desk} session-start"]) self.assertTrue(SEAT_STATE.stat().st_mode & 0o111) From e4a7d89bf1961e9454359453e21cc30f74379986 Mon Sep 17 00:00:00 2001 From: Josui Date: Wed, 18 Nov 2026 01:05:27 +0000 Subject: [PATCH 2/2] build: verify the ashigaru RPM against a pinned sha256 (a244) The release asset is unsigned and rpm.yml uploads with --clobber, so the build downloads it, checks ASHIGARU_SHA256 with sha256sum -c --strict and installs only the checked file. Pinned to ashigaru-3.0.0-1.fc43.noarch.rpm, hashed here and matching both Josui Prime's hash and GitHub's asset digest. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01R7Y1jg3ZJ6BsAEfhrPWFRh --- CHANGELOG.md | 2 +- Containerfile | 21 +++++++++++++++------ tests/test_containerfile.py | 10 ++++++++++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4300a05..8bfc438 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ All notable changes to this project are documented here. The format follows ### Added - The `ashigaru` CLI, from the Ashigaru 3.x release RPM (`ASHIGARU_VERSION`, - pinned to 3.0.0). + pinned to 3.0.0), checked against `ASHIGARU_SHA256` before it is installed. - Managed hooks run `/usr/libexec/developer/ashigaru-hook` beside seat-state on SessionStart, UserPromptSubmit, Stop, StopFailure and the idle_prompt Notification, reporting the seat's turn and task to the Desk through diff --git a/Containerfile b/Containerfile index ffd2e6d..816ece2 100644 --- a/Containerfile +++ b/Containerfile @@ -71,8 +71,11 @@ ARG CLAUDE_AGENT_VERSION=1.2.0 # The Ashigaru CLI, whose `ashigaru hook` reports this seat to the Desk. 3.x # is a Python package shipped as an RPM on each GitHub release, built on # fedora:43 and centos:stream10; the fc43 build is noarch against Python 3.14, -# which is this base's too. A bump is this one line. +# which is this base's too. A bump is these two lines: the version and the +# sha256 of that release's fc43 RPM. Only one RPM is installed (noarch, one +# dist), so one hash covers it. ARG ASHIGARU_VERSION=3.0.0 +ARG ASHIGARU_SHA256=6c493397db5867f3de1c9d3156fa438d4196db406cabd51563be127465129758 USER 0 @@ -118,11 +121,17 @@ RUN dnf -y upgrade && \ python3 -c 'import sys; assert sys.version_info[:2] >= (3, 14), sys.version' && \ uv --version && tmux -V && podman --version -# Straight from the release over TLS, not from a dnf repository: the -# crunchtools repo does not carry ashigaru, and a release that has no RPM -# attached fails the build here rather than shipping a seat without the CLI. -RUN dnf -y install --setopt=install_weak_deps=0 \ - "https://github.com/crunchtools/ashigaru/releases/download/v${ASHIGARU_VERSION}/ashigaru-${ASHIGARU_VERSION}-1.fc43.noarch.rpm" && \ +# Straight from the release, not from a dnf repository: the crunchtools repo +# does not carry ashigaru, and a release that has no RPM attached fails the +# build here rather than shipping a seat without the CLI. The RPM is unsigned +# and rpm.yml uploads with --clobber, so the asset at that URL can be replaced: +# the pinned hash, not TLS, is what says this is the file that was reviewed. +RUN rpm=/tmp/ashigaru-${ASHIGARU_VERSION}-1.fc43.noarch.rpm && \ + curl -fsSL -o "$rpm" \ + "https://github.com/crunchtools/ashigaru/releases/download/v${ASHIGARU_VERSION}/${rpm##*/}" && \ + echo "${ASHIGARU_SHA256} $rpm" | sha256sum -c --strict - && \ + dnf -y install --setopt=install_weak_deps=0 "$rpm" && \ + rm -f "$rpm" && \ dnf -y clean all && \ rm -rf /var/cache/dnf && \ ashigaru --help > /dev/null diff --git a/tests/test_containerfile.py b/tests/test_containerfile.py index 25de9e3..6467aa9 100644 --- a/tests/test_containerfile.py +++ b/tests/test_containerfile.py @@ -16,3 +16,13 @@ def test_the_oci_version_label_is_this_release(self) -> None: labels = dict(re.findall(r'^LABEL ([\w.]+)="([^"]*)"', CONTAINERFILE.read_text(), re.M)) self.assertRegex(labels["version"], r"^\d+\.\d+\.\d+$") self.assertEqual(labels.get("org.opencontainers.image.version"), labels["version"]) + + +class AshigaruPinTest(unittest.TestCase): + # The release asset can be replaced (rpm.yml uploads with --clobber), so + # the build installs only an RPM whose hash is pinned here. + def test_the_rpm_is_pinned_by_sha256(self) -> None: + args = dict(re.findall(r"^ARG (ASHIGARU_\w+)=(\S*)$", CONTAINERFILE.read_text(), re.M)) + self.assertRegex(args["ASHIGARU_VERSION"], r"^\d+\.\d+\.\d+$") + self.assertRegex(args["ASHIGARU_SHA256"], r"^[0-9a-f]{64}$") + self.assertIn("sha256sum -c --strict", CONTAINERFILE.read_text())