Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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), 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
`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
Expand Down
25 changes: 24 additions & 1 deletion Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ 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 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

Expand Down Expand Up @@ -113,6 +121,21 @@ 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, 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

# 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.
Expand All @@ -123,7 +146,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
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions rootfs/etc/claude-code/managed-settings.d/40-developer-seat.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
Expand All @@ -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
}
]
}
Expand All @@ -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
}
]
}
Expand All @@ -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
}
]
}
Expand All @@ -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
}
]
}
Expand Down
36 changes: 36 additions & 0 deletions rootfs/usr/libexec/developer/ashigaru-hook
Original file line number Diff line number Diff line change
@@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HIGH (Constitution): This adds an Ashigaru API key as another credential available to the agent. The constitution says the agent needs one credential—the gateway bearer token—and identifies the OpenRouter key as a second credential that is being removed. Accepting ASHIGARU_API_KEY or ASHIGARU_API_KEY_FILE introduces a further credential outside that stated model.

Suggestion: Keep Desk authentication within the gateway credential model, or amend the constitution to explicitly authorize and define the handling, scope, and revocation of this additional credential.

Evidence:

if [ -n "${ASHIGARU_API_KEY_FILE:-}" ]; then
  [ -r "$ASHIGARU_API_KEY_FILE" ] || skip
elif [ -z "${ASHIGARU_API_KEY:-}" ]; then
  skip
fi

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deferred: #75

The per-seat Desk key belongs to the cutover design (a242 stages it), and it is not this image's call. Issue #75 asks for one of two things: amend Layer 5 to name the key, or put the Desk behind a gateway route that uses the seat's own token. Until a key is staged, the hook does nothing.

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 "$@"
13 changes: 12 additions & 1 deletion rootfs/usr/local/bin/sdlc
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"

Expand Down
88 changes: 88 additions & 0 deletions tests/test_ashigaru_hook.py
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 10 additions & 0 deletions tests/test_containerfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
13 changes: 13 additions & 0 deletions tests/test_sdlc_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 7 additions & 5 deletions tests/test_seat_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading