Repository navigation
feat: ashigaru CLI and Desk hooks; sdlc runs .sdlc/bin/sdlc (a244) #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| 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 "$@" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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_KEYorASHIGARU_API_KEY_FILEintroduces 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:
There was a problem hiding this comment.
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.