Skip to content

Add amber setup:agent: Claude Code and Codex hooks for the Crystal agent loop - #43

Merged
crimson-knight merged 2 commits into
mainfrom
sol/setup-agent
Oct 6, 2026
Merged

crimson-knight merged 2 commits into
mainfrom
sol/setup-agent

Conversation

@crimson-knight

Copy link
Copy Markdown
Member

Adds amber setup:agent (alias amber agent), which installs the agent feedback loop into an Amber V2 project. Until now this loop only existed as personal scripts on the maintainer's machine.

What it writes (idempotent; existing settings and hooks are kept):

  • .claude/settings.json and .codex/hooks.json:
    • PreToolUse bin/amber-agent-hook pre holds the watcher while the agent edits.
    • PostToolUse bin/amber-agent-hook post runs per edited file: crystal-alpha tool format plus amber-lsp --check. It's fast and never runs a full build.
    • Stop bin/amber-agent-hook stop releases the hold and runs crystal-alpha watch build. Without a watcher it falls back to build --no-codegen <main>. Errors exit 2 so the agent sees them.
  • bin/amber-agent-hook: a POSIX sh script for Linux and macOS with no jq, ruby or python. It handles Claude's file_path and Codex's apply_patch payloads. Compiler order: $CRYSTAL_ALPHA, crystal-alpha, acrystal, then stock crystal with a warning.
  • An "Agent loop" block in CLAUDE.md and AGENTS.md (marker comments, idempotent), and the .lsp.json from setup:lsp.
  • amber-lsp --check FILE: a one-shot diagnostics mode for hooks.
  • setup:lsp: removes the hardcoded ~/open_source_coding_projects/amber_cli lookup and uses the same compiler resolution instead of bare crystal.
  • amber new prints a tip to run amber setup:agent.

Works with today's compiler: the hook probes watch status once. The installed crystal-alpha (1.21.0-incremental-1) has no watch hold/build and exits 1, so the hook skips coordination and type-checks directly. The ported compiler (crimson-knight/crystal#10) exits 0 or 2, so it holds and releases the watcher. If amber-lsp is missing, the hook warns without blocking; formatting and syntax errors still block.

Tests: setup_agent, setup_lsp and new_command specs: 167 examples, 0 failures. amber_lsp specs: 16, 0 failures. shellcheck and dash -n pass. Manually verified in a fixture project against both the installed crystal-alpha and the ported compiler: a clean project exits 0; puts 1 + "x" makes stop exit 2 with the compiler error. With the ported compiler, pre runs watch hold (exit 0).

Not verified: a live session against a running crystal-alpha watch (needs #10 released), and Codex end to end in a real repo.

@crimson-knight
crimson-knight merged commit 2099826 into main Oct 6, 2026
6 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant