Repository navigation
feat: chat threads over ACP, with agent modes and plugin embeds - #166
Merged
Merged
Conversation
An ACP session id is the agent's own string, not a UUID, and the thread's conversation column already holds it (decision 54). The newtype validates instead: not empty, at most 256 bytes, no control character.
A thread's link says what runs its program: a pty, or the agent's own ACP connection. The store gains one column whose default keeps every existing row a terminal thread; Run and Thread carry the field, so Get and List report it.
A program's end was written in the terminal path only. The turn it leaves open, the events it records and the status it leaves behind now live in thread::finish, so an agent that speaks over its own pipes reuses them instead of copying them.
The turn that a program leaves behind was read from the stop reason inside waiting. The caller that knows the outcome now passes it, so an agent that answers on its own pipes ends a turn with the outcome its answer names.
An ACP thread starts its agent with the agent's own ACP subcommand through kg-process, frames the protocol on two std threads and feeds the crate's channel transport, so turns, Stop, Cancel and the process tree behave as they do for a terminal thread. The agent's updates become the thread's events, and the prompt's response ends the turn exactly. Start again opens a new session and says so in a notice. A recorded fake agent proves it: messages stream in, Cancel ends the turn and keeps the agent, Stop ends the process tree, Screen and Resize are refused, and Start again names a new session.
A thread whose link is ACP opens in a chat instead of a terminal: its events are the transcript, drawn as named parts (a message, a notice) so a plugin can replace one later, and the prompt box sends with Enter or Send and offers Cancel while the agent answers. Escape cancels the reply, bound in the chat's own context. The new-thread form offers Run as: Terminal | Chat for an agent that answers ACP, Chat first.
The ACP tests re-run the test binary as the agent with KG_FAKE_ACP_DIR set, the same pattern the other self-starting tests use.
An agent that ended on its own left its connection in the run, so the thread still looked live: a prompt opened a turn, then found the command channel closed, and left the turn open with a message never sent. The connection now goes when the agent does, and the task that writes the log is kept on the run rather than inside the connection.
CONTEXT gives Session and Chat their meaning, behaviour.md records Run --link, Cancel, the ACP turn and the chat in the window, and decision 279 carries the size budget's cost line.
A person's message is a raised block with the accent spine; the agent's is its name, the time and the words with Copy on hover, and no box. The prompt box is one bordered field with Send or Cancel in its own bar and one hint line under it. The part table names message, thought, work, bundle, plan, approval and notice, and slice 1 draws the first and the last of them.
…lugin's thread fixture
An agent killed by a signal, or one kagan ended after its grace, read as a completed turn and an idle thread, because the exit code was all kagan kept and a signal has none. exit_status now returns kg_terminal::Exit and the ACP link uses the terminal exit_end mapping, so a signal is a failure. A non-clean exit also dropped the agent's stderr, the only words it has for why. The tail is now attached to any exit that is not a clean zero. Two transport faults made both reports late and lossy: the reader thread's channel had no bound and its pump kept the connection's input open, so every exit waited out the grace, and a line that was not UTF-8 silently ended the stream. The reader caps a line, replaces invalid bytes, and shares one body across unix and windows; the queue is bounded; a disconnect closes the frames so the run reports the exit at once. The connection cannot be woken from the reader thread: GPUI's test scheduler refuses a wake from another thread. The pump stays, and backs off to 250 ms while the agent is quiet.
finish::ended returned early unless the thread was Active or Stopping, so an agent that died before session/new (a crash in initialize, an opencode without the acp subcommand) left the thread on Starting forever with no reason on screen. It accepts Starting now: a terminal is Active before its watcher can report an exit, so only the agent link can arrive that early. The fake agent gains fail_init, which exits 3 with a stderr line before it answers initialize; the test fails without the accepted status.
The starting branch of Stop removed the thread's task and left the run's connection and consumer untouched, so the agent kept running: it later named its session and flipped the thread back to Active, and Start was refused because the program was still live, while an agent that hung on initialize had no other way out. One release(run) now ends what a run owns, for both the starting and the running path. A fresh start clears the stop reason so a later natural turn is not read as interrupted. Stop also no longer sends a cancel the dropped connection can never read: it ends the process tree at once, and the docs, decision 279 and the plan say so. A prompt response is applied only on an Active thread, so one left in the queue cannot write a turn or a wait on a stopped thread.
Nothing bounded initialize or session/new, so an agent that never answered left the thread on Starting with no message and no way out but a restart. Both requests share one 30 s deadline on the executor's timer, and a miss is reported as plain words: the thread goes to error with the reason, and the agent that never answered is ended.
A refused send left a user message and an open turn behind, so the thread showed a spinner with nothing able to end it. The send is synchronous, so recording the message and the turn after it costs nothing.
`kagan/chat`, granted by `areas: ["chat"]`: `items` and `waitItem` read a chat thread's transcript from its log, `send` and `cancel` are `thread input` and `thread cancel`, and `draft`/`setDraft` reach the prompt box of the chat on screen through `HostUiEvent::ChatDraft`. A call is refused for a terminal thread, an archived one and one the person cannot see. The transcript maps message, work, notice, turn and approval; a page is capped at 200 items and 256 KiB, and the open approvals follow every page so paging to the end never hides one.
`"prompt": true` is one more placement key on a command, like `header` and `menu`: a small ghost button in the chat's prompt row, before Send, at most four a manifest and four in the window. It needs `when: "thread"`. The prompt row is `header::row`, so a prompt button and a header button share one body: no icon, one height, one width cap.
`Slot::Chat` mounts on a thread whose link is `acp` and lets go when the person shows a terminal, a start screen or nothing. `ChatView::render_with` takes the body as a parameter, so the plugin draws the transcript only: the prompt box, its hint, the strip, the ended line, focus and Send stay kagan's. Switching from one chat to another keeps one mount; every refresh wakes the chosen chat plugin the way the sidebar's is woken, and `secondary-alt-n` takes the transcript back. A body that throws returns the built-in, writes why and saves `slot.chat = kagan`.
A chat's body mounts and lets go, `draft`/`setDraft` reach the box of the chat on screen only, a thrown body falls back with a reason, and the built-in key works while the plugin holds focus. A prompt button draws before Send, runs for the shown thread, and the window draws four at most.
The chat labelled replies with the whole program line, so a thread started as /opt/bin/opencode --model x showed that path on every message. The title code already had the name people know; move it to kg-domain and use it in both places, so one function answers what a program is called.
Each chunk of a reply was its own event row, database write and render, so a long answer was hundreds of writes. Join the chunks the agent already sent for the same message behind the first one. An update or request slice 1 does not serve was dropped without a word; it is now named once per connection, and a dropped request is still answered by the protocol itself. The refusal for a program with no ACP command lists the table, not a second hard-coded name.
The chat scrolled to the bottom on every event, pulled a person reading earlier text away from it; it drew a live event the load had already read, twice and out of order; its Escape ran twice and raised an error when no reply was open; its focus handle belonged to nothing, so Enter and Escape needed a click first; and its prompt claimed to be disabled while it took typing. The hint now says what to do in this state, a message's name says who and when, and the transcript scrolls only when the person is at its end.
The size budget says what this branch actually adds, with the two files the fixes grew named in it. A thread no longer avoids the word chat, and Input says what an ACP thread answers when its agent has ended.
The stop-reason table had no test, so a swapped arm would pass; the message id on a chunk was never checked; and the fake agent could not echo a prompt or ask for permission. It can now, so the tests cover the echo being dropped, the permission being answered cancelled, the id being kept, and a stop reason kagan does not know saying so. The launch helper is named for what it does.
The stopped line and the notice cut on a word instead of running past the box, and the text area clips at the box's edge. A full chat in a 320-point right panel no longer paints over the window.
The card, the fold and the box moved across the chat's modules, so the embed's 10000 place, its CancelTurn and Start again are re-applied on the new shape: the box's focus return is the embed's one skip, and the decision and budget counts are measured against the newer base.
Only the full form asks for the panel's frame; a compact card is two lines wherever it is put.
…n names it A mode the answer listed in `modes` changes through `session/set_mode`, which ACP serves only for the modes the agent advertised; every option from `configOptions`, a mode among them, goes through `session/set_config_option`. The options now remember which ids the answer gave in `configOptions`, so an agent that never advertised modes (opencode) is never sent the mode call. Start again writes an info notice naming the mode it restores, because the agent's own first mode is not the person's choice. The fake agent answers a config call with the options it changed, so the new test can tell the two calls apart.
opencode offers 82 models, so the chip's menu scrolls inside a bounded height instead of running off the window. A refusal says which option did not change; it said "the mode" for every one. The box's notice keeps its accessibility label, which the menu tests read.
This was referenced Nov 30, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #168
What
An ACP thread starts its agent over ACP instead of a pty and shows it as a chat: transcript, tool rows, plan, approvals, one box, and a modes chip. A plugin can embed that chat in full or compact. Terminal threads are unchanged.
Why
A terminal shows output only, so what the agent asks stayed in scrollback, and a plugin showed no thread.
How
The link is a stored column;
ACP_COMMANDSis the only per-agent fact. The chat extends the existing model throughslot.chat,kagan/chatandThreadChat; Start again reloads the stored session.Notes
Decisions 279-288. Product Rust: 84147 to 91967 (+7820); the ceiling matches. Known gap: no test drives Escape in a busy embed.
Test plan
smoke.shhere.proof/).