as

Projects / astack

astack

A Go CLI and TUI that runs coding CLIs already installed on the machine: claude, codex, gemini, opencode, and grok. No API key and no paid subscription. If the binary is not on the machine, astack does not fetch one.

Why

The useful part of a coding agent is often a CLI the person already logged into. Wrapping that CLI is easy until the prompt is large, the worker fails a test, or a second agent is supposed to look and not touch the repo. Shell argv limits truncate the task. A retry that only says “try again” forgets the compiler output. A “read-only” prompt is a suggestion, and the CLI can still write.

astack is the dispatcher for that. The person at the terminal sets the task. A local CLI implements it when that CLI is already installed. --agent auto uses the first installed name in agents.json order. Naming one that is absent exits 2 and stops. It does not fall through to a different agent. No worker at all exits 3, and the files stay for the person to edit.

Architecture

Dependencies point one way. app is the only package that defines commands. It calls agents (which binary, which args, which model flag), proc (start the process, put the prompt on disk, run the verify command), workspace (the workdir lock, isolated copies, diffs), platform (Windows, macOS, Linux paths), and tui. The TUI does not import app. It talks to a Backend. Adding a command changes app. It does not give the screen a second copy of dispatch.

One-way packages. The screen is a view. Workers are other processes.
entry CLI or TUI astack, astack tui, run.sh / run.ps1.

app owns every subcommand

agents registry Installed or absent. Model flags. Read-only args when the CLI has them.
proc runner Prompt file, process, verify command, failure tail.
workspace copies and diffs Throwaway repo for CLIs with no read-only mode. Arena diffs.
platform OS paths Homebrew, ~/.local/bin, Windows npm shims. GUI terminals have a short PATH.
tui screen Does not import app. Calls a Backend.

A worker is a process that was already installed

workers claude · codex · gemini · opencode · grok Prompt file on disk, then the CLI’s own auth. astack never asks for a key.

Diagrams

A solid outline is the path in the repo. A dashed outline is the alternative that shape is refusing.

app owns every subcommand. The prompt is a file, then an installed CLI runs, then --verify feeds a failure tail back to that same worker. The TUI calls a Backend and does not import app.

flowchart TD
  person[Person]
  app["internal/app"]
  proc["proc writes the prompt file"]
  worker["Installed CLI"]
  verify["verify command"]
  person --> app
  app --> proc
  proc --> worker
  worker -->|"exit 0"| verify
  verify -->|"failure tail, up to retries"| worker
  class app,proc,worker,verify chosen
          

The prompt is a file because argv limits truncate it. --agent auto uses the first installed name and does not fetch a CLI. A read-only panel uses the CLI’s own read-only flags, or a throwaway copy when the CLI has none.

flowchart TD
  prompt{A large task}
  prompt -->|"argv limits truncate it"| argv["Prompt on the command line"]
  prompt -->|"file in the workdir, then delete"| file["Prompt file"]
  agent{Which CLI runs}
  agent -->|"already on the machine, else exit"| local["Installed worker"]
  agent -->|"download one or ask for a key"| fetch["Fetch a worker"]
  look{A read-only panel}
  look -->|"the CLI has read-only flags"| flags["In place"]
  look -->|"no read-only mode"| copy["Throwaway copy"]
  look -->|"a prompt that says do not write"| hope["Same repo, no flag"]
  class file,local,flags,copy chosen
  class argv,fetch,hope rejected
          

Why this shape

The prompt is a file

Large tasks are written to .astack-prompt.<pid>.txt in the workdir and deleted after the worker exits. Windows cmd and Unix ARG_MAX both truncate argv. The file is gitignored (.astack-prompt*.txt), so a worker that commits the tree does not pick it up. The worker still runs inside that workdir, so it can read the file. That is the point.

Verify feeds the failure tail back

--verify runs a command in the workdir after the worker exits 0. On failure, the tail of that output goes back to the same worker, up to --retries (default 2). Still failing exits 5. The loop is not a new agent with new tools. It only returns the tail. The command is whatever was passed. astack does not decide that tests are the definition of done.

Read-only is a flag or a copy

review, why, explore, architect, and reflect run in parallel. A CLI with read_args in agents.json (claude, codex) runs in the real workdir with its own read-only mode. Any other CLI runs on a throwaway copy, so a prompt that says “do not edit” is not the safety boundary. review reads git diff HEAD plus untracked files. Two or more answers are merged by the synth role. Playbooks run one of these panels first, pass the answer to the implement step as notes, then run review. Review is advice. It does not fail the playbook.

Arena: verify first, then the smaller diff

astack arena runs the named agents. An arm that fails --verify loses before anyone judges it. Judges read the diffs of the arms that passed and vote. A tie goes to the smaller diff. The rule always finishes. It can also prefer a diff that deletes a test over a larger one that fixes it. Smaller is a tie-break, not a quality score.

A missing binary is not a suggestion

The dispatcher looks in Homebrew, ~/.local/bin, and Windows npm shim directories, then prepends what it found to the worker’s PATH, because a GUI terminal often has a thin PATH. It still will not install a CLI, and it will not reroute when the named one is absent. --list prints installed or absent.

Failure modes

In-place read-only trusts the CLI

The copy is the boundary for CLIs that have no read-only flag. Claude and Codex run in the repo you care about, with the flag their own binary documents. If that flag is missing from agents.json, or the CLI ignores it, the panel can write. The copy path is slower and is a second tree. It is the one that cannot touch the original.

The verify loop can thrash

The worker sees a tail, not the whole failure. A flaky test fails, the worker edits, the test fails differently, retries run out, exit 5. Nothing in the loop checks that the edit was related to the tail. Two retries is a cap, not a proof.

The tie-break prefers less change

When two arms pass verify and the judges tie, the smaller tree wins. A diff that removes the failing test is often smaller than a diff that fixes it. Verify only helps if the command would have caught that. A verify command that does not run the deleted test will bless the smaller arm.

Exit codes are the API

Exit 2 means the named agent is not installed. Exit 3 means no worker CLI is installed. Exit 5 means verify is still failing. Callers that treat every non-zero as “try a different agent” undo the rule. The dispatcher’s job in those cases is to stop.

Where to read it

The layout and the flags are in the astack README. internal/app is one command type per subcommand. internal/proc holds the prompt file and the verifier. internal/workspace holds the copies and the diffs.

Related: Hotwire, the other long Go writeup, and the rest of the small tools on Side projects.