feat(chats): free Chats on a Repo, streamed in the App #6

Merged babariviere.com
targeting main from feat/chats-free-chats-on-a-repo-streamed-in-the-app
Merged opened by babariviere.com
targeting main from feat/chats-free-chats-on-a-repo-streamed-in-the-app

Summary #

The Owner starts a free Chat on a Repo, and talks with an agent about its code. It is the first real agent. Ticket: .scratch/v1-core-loop/issues/05-free-chat.md.

startChat { repo, text }startChat(role free-chat, cwd = clone)createConversation + submitreplied { created: id }followChat { chat: id }view changes (entries, pi.live, pi.inbox)chatStreamed { messages, working, failure }writeChat (while working)submit whenBusy: "steer"AppDaemon (chats.ts)harness hostPi DurableAppDaemon (chats.ts)harness hostPi Durable
 daemon/src/
+├── chats.ts        # pilot_chats, startChat / writeChat / followChat / removeChat
+├── roles.ts        # free Chat: its prompt, tools read + bash (no push, no pull request)
+├── store.ts        # Pilot's writes retry instead of blocking Pi Durable's write lock
 ├── harness-host.ts # + Chats in Pilot's words; prompt sections AGENTS.md, GLOSSARY.md
 └── server.ts       # + each command gets the connection that sent it
 app/
+├── chat.tsx        # the Chat Sheet: follows the open Chat, New Chat, Remove Chat
 └── pages.tsx       # Repo page: New Chat, the Repo's Chats
 ui/
+└── chat.tsx        # ChatPanel: virtualized, stays at its end while an answer streams, tool rows
  • A message sent while the agent works is a Pi Durable steer. The Chat shows "Waits for the agent's next step" until the agent reads it, and the agent is never stopped.
  • Protocol: startChat, writeChat, followChat, removeChat; chatsChanged, chatStreamed; chats in the snapshot; created in replied.
  • Free Chats run on one model (chatModel) until model picking (ticket 14), which now also lets the Owner pick the model of a new free Chat.
  • Fix found while checking by hand: Pilot's synchronous SQLite writes blocked the event loop while Pi Durable held the write lock across awaits, so two Chats started at once failed with "database is locked". store.ts now retries with the event loop free.

Evidence #

  • Before: no Chats. Two Chats started at once: Pilot's Daemon failed: database is locked. After: just test passes: 29 Daemon tests, 21 App tests, 15 gallery tests. just check and just lint are clean.
daemon/test/chats.test.ts (real Pi Durable, jj and bash; scripted model)
✔ the Owner starts a free Chat on a Repo and gets the agent's answer as it streams
    prompt has AGENTS.md + glossary; tools are exactly [bash, read]
✔ the agent runs its tools in Pilot's clone of the Repo, and the Chat shows their output
✔ a message sent while the agent works reaches it after its current step, and does not stop it
✔ a Chat goes on after a Daemon restart
✔ the Owner removes one Chat: its agent stops, and the Repo's other Chats stay
✔ two Chats that start at the same time both start   (failed before store.ts)
app/test/Chat.test.tsx (scripted Daemon): start, stream, queued message, refusal, reconnect, remove
  • Checked by hand in a macOS window against the scratch Daemon: New Chat on octocat/Hello-World, the Repo page lists it, the Sheet shows "No model could answer: Pilot is not signed in to Claude or OpenAI yet." (sign-in is ticket 06), and Remove Chat with its Dialog.

Merge Danger #

Door: two-way

New pilot_chats table and Pi Durable conversations in pilot.sqlite. Rolling back leaves them unused.

Blast Radius: Daemon

  • Every Pilot write now goes through store.ts (Repos too).
  • The free Chat has bash in the Repo's clone, so an agent could still change the clone. Only its prompt stops it, by the Owner's choice.
  • Until ticket 06, every real Chat ends with the sign-in line.
Commits 4

docs(tickets): deepen Repos, Repo removal and Store in ticket 09
docs(tickets): free Chat model picking in ticket 14, and ticket 30 for an Output style
feat(chats): remove one Chat, and let Pilot's writes wait for Pi Durable's
feat(chats): free Chats on a Repo, streamed in the App
Sign up or Sign in to add to the discussion.