Agents and ACP
hangar Engine phase (P2)
An agent is a program that can read your files, run commands, and write changes, driven over a protocol instead of a chat window. Acpilot’s native protocol is the Agent Client Protocol, the same one Zed uses. An agent written for ACP therefore works here without an adapter.
What the daemon does with an agent
Section titled “What the daemon does with an agent”sequenceDiagram
participant D as acpilotd
participant A as agent process
D->>A: initialize
A-->>D: capabilities, protocol version
D->>A: session/new
A-->>D: session id
D->>A: session/prompt
A-->>D: session/update — chunks, tool calls, plans
A->>D: session/request_permission
D-->>A: allow, ask a human, or deny
A-->>D: stopReason
D->>A: session/cancel
Three things make this more than a pipe:
- The permission broker sits in the middle.
session/request_permissiondoes not go to a UI as a toast. It becomes a pending record the daemon can audit, replay, and answer from policy. - The filesystem callbacks go through the host. When an agent asks to read a file, the daemon reads it from the host the workspace lives on: local, SSH, or WSL. It does not read from whatever machine the daemon happens to be on.
- Every update becomes a sequenced event. UIs render from the event stream, so a reconnecting client can replay and arrive at the same screen.
Capabilities, not assumptions
Section titled “Capabilities, not assumptions”Agents differ. The daemon records what each advertised during initialize, and
the UIs adapt. An agent with no plan support gets no plan panel, not an empty
one. The same goes for session/load. If an agent cannot resume, the daemon says
so rather than pretending a restart is a resume.
Model-backed agents
Section titled “Model-backed agents”A local model can be promoted into an ordinary agent. It reaches the workspace, terminals, and permissions only through the ACP callbacks above.
Which means the diagram on this page does not change. A model-backed agent is an ordinary agent with an unusual prompt: same supervisor, same broker, same transcript, same audit. That was the entire reason to build it that way.
An agent is an arbitrary program with your repository and your network. The first
time a command is run, the daemon hashes it and pins it. If the binary changes,
the agent shows as untrusted until you say otherwise. This is not paranoia.
It is the same reason your shell asks before running a downloaded script. The TUI
asks with it: Session → Select Agent… marks that row not approved and names
the pack it came from. Enter on it opens a card with the agent, the pack and
the exact command. y records the pin. n writes nothing and the command does
not run.
What is built today
Section titled “What is built today”The manifest and the process come first, because every later layer is built
against them. agents.toml is parsed and checked. Secrets are resolved when the
profile loads. The registry keeps one checked snapshot that a bad save cannot
half-replace. The supervisor starts an acp-stdio agent. It keeps stderr in a
bounded ring that is readable while the agent runs. It restarts the agent on a
crash when the manifest says on-crash. It ends the process tree, not only the
wrapper, when a session closes.
GET /v1/agents lists what the daemon was given, in declaration order, with
available or missing from a PATH lookup on the daemon’s host. That status
costs no process: listing agents cannot start one. A handshake-dependent
unhealthy is reported by the session routes rather than by this list. untrusted
is reported here, once the program no longer matches the pin a person recorded,
and POST /v1/agents/{id}/trust is the only thing that answers it.
A session is the client side of the protocol. It takes the supervisor’s two pipes
and speaks ACP over them, so the same code serves a child process, an SSH host,
or a test. initialize completes before the handle is returned. No caller holds
a session whose capabilities it has not seen. Every session/update becomes one
numbered event before it is broadcast, so a slow subscriber drops events but
cannot renumber them. One turn runs at a time: a second prompt is refused here
rather than left to whatever an agent does with two. session/cancel is a
notification, so it reaches an agent mid-turn.
A permission request is classified as file read, file write, terminal, tool, or
other. It goes to the broker, which answers from a rule, from the defaults, or by
asking a person. The agent’s own option ids are used for the answer, so an agent
that called its allow option yolo receives yolo. A decision the agent offered
no option for cancels the request rather than inventing an approval. A session
with no broker refuses everything with the agent’s own reject option. No grant
should be implied by a session that has no policy. Either way the answer is
recorded as a notice, so the transcript says what the agent was told. A request
for a method this build does not implement gets MethodNotFound naming the
method. That includes an fs/* call on a session with no workspace, and a
terminal/* call on one the daemon gave no registry. Not advertising a
capability does not stop an agent asking, and a request with no answer is a hang,
not a refusal. All of it is exercised against a mock agent that runs as a real
child process. The pipes, the handshake and the tree kill therefore run in CI
rather than only type-checked.
An agent does not open files. It asks its client to. A session is given a
workspace, and fs/read_text_file and fs/write_text_file are served from it
through the same host seam the daemon edits and runs processes through. The same
code therefore reads a laptop’s disk and, once the SFTP channel lands, an SSH
workspace’s.
The path an agent asks about is resolved on the host, with symlinks followed,
before it is compared with the workspace. Comparing the text that arrived would
miss workspace/link, which is a path that looks contained and points at /etc.
A relative path is refused rather than joined onto the workspace. The protocol
says absolute, and guessing a base directory turns an agent’s bug into a file in
an unexpected place.
Reads outside the workspace are refused by name. Writes outside it are not refused. They wait. The broker publishes a pending permission request, the turn blocks, and the file is untouched until somebody approves it. That is the whole point of calling it a shadow write: the old contents are still the contents while the decision is open. A diff can therefore be shown against a file that has not moved, and a crash leaves the disk as it was. Nothing is written speculatively and rolled back, because a file restored by a rollback is not the same inode the editor had open.
Two rules keep a blocked write from becoming a hang. If nothing is listening for pending requests, the write is refused immediately. An approval that nobody can give is not worth waiting for. A request nobody answers expires after five minutes. Either way the agent gets a denial, and the refusal is recorded as a notice, so the transcript shows what the agent was told.
A session without a workspace advertises no filesystem at all, and refuses a request that arrives anyway. The capability and the handler are one decision. Advertising something this client cannot serve is the same bug as refusing something it advertised.
Terminals
Section titled “Terminals”An agent does not run a command either. It asks its client to. terminal/create
arrives at the session. The daemon’s terminal registry starts a PTY for it
through the same host seam the file methods use. The command runs where the
workspace is: this machine today, an SSH host once P3-9 moves the seam. Output is
a one-mebibyte ring truncated on a character boundary. An agent pastes it back
into a message, and a String cannot hold half a character. A terminal
belongs to the session that asked for it. An id alone does not reach one, so two
agents in one workspace cannot read each other’s shell. terminal/release closes
it. A session that ends takes its terminals with it. One nobody has touched for
half an hour is killed by the daemon’s sweep. The release call is optional in
ACP, and a forgotten process is the normal case rather than the exception.
Permissions
Section titled “Permissions”The shipped policy is deliberately plain. Files inside the workspace are read and
written. A shell or an unrecognised tool is asked about. Anything outside is
asked about too. A rule (allow, ask or deny, optionally scoped by agent,
tool and path glob) is how a workspace narrows that. Every decision lands on the
broker’s audit log with the rule that made it. pty and http-jsonrpc agents are
accepted by the schema but refused by the supervisor until their phases land. The
diagram above is therefore still the target, not a full description of today’s
daemon.
Model-backed agents arrive in the models phase (P4.5), on top of the same layer. They inherit whatever the engine phase (P2) gets right, or wrong, without a second implementation to blame.
Vibecoded, on purpose. While I am a software developer, I lack the time to hand-code all my ideas, and as a result this project is vibecoded withFreebuff.