AGENTS.md@server · git:20260708.9cca7fe · 2026-07-08 · sha256 7f15ce9a1a91494d
AGENTS.md@server git:20260708.9cca7feA
Immutable. This exact content is served forever at /api/v1/blob/7f15ce9a1a91494d.
Bun server on port 13337. Serves the client at `/`, upgrades `/ws` to WebSocket.
- `web.ts` owns the Bun fullstack surface only: the SPA HTML shell (dev bundler + HMR / prebuilt `dist/`), the two WebSocket channels (`/ws` chat, `/api/workspaces/ws` live events), and graceful shutdown. Every HTTP API request is delegated to the Hono app via `fetch`.
- `api.ts` is the Hono REST API (all `/api/*` routes). `withWorkspace` middleware resolves `:id` → workspace (404 if missing) and stashes it on the context, so handlers read `c.get('ws')`. Its catch-all serves the prebuilt client from `dist/` in prod via Hono's `serveStatic` (cached, traversal-safe).
- `static.ts` exposes the `dist/` location (`DIST_DIR`), the `prebuilt` flag, and the prod SPA `distShell`. `events.ts` holds `publishEvent` (server→client live-event broadcast over `/api/workspaces/ws`) decoupled from `web.ts` to avoid an import cycle; `web.ts` wires it via `setEventServer`.
- `state.ts` holds global mutable state (messages, session, connected clients). `record()` appends, persists, and broadcasts.
- `agent.ts` sends prompts to Claude via `query()` from the agent SDK. Streams responses back as typed messages. Sessions are resumable.
- WebSocket protocol: server sends `ServerMessage`, client sends `ClientMessage` — both defined in `lib/types.ts`.
- Agent runs in `workspace/` with bypass permissions. Chat history persisted to `workspace/messages.json`.