Repository-level guidance for coding agents and contributors.
This app is a localhost research interface that orchestrates a local OpenCode instance. Primary goal: keep the local query flow stable and transparent.
- Primary dashboard route:
src/app/page.tsx - Settings/admin route:
src/app/settings/page.tsx - Shared monitor UI shell:
src/components/opencode-monitor-shell.tsx - Global theme tokens + shell styling:
src/app/globals.css - Reusable UI primitives (shadcn-style):
src/components/ui/* - Shared class utility:
src/lib/utils.ts - Monitor page shared modules:
src/lib/opencode-monitor/* - Query API:
src/app/api/query/route.ts - Engine status API:
src/app/api/opencode/status/route.ts - Session monitor API:
src/app/api/opencode/sessions/route.ts - Event stream bridge API:
src/app/api/opencode/events/route.ts - Typed action API:
src/app/api/opencode/action/route.ts - Session timeline API:
src/app/api/opencode/session/[sessionId]/timeline/route.ts - Session transcript API:
src/app/api/opencode/session/[sessionId]/transcript/route.ts - OpenCode manager/client glue:
src/lib/opencode.ts
- Keep the app local-first.
- Do not remove automatic OpenCode startup on research requests.
- Do not switch
queryAPI runtime away from Node (runtime = 'nodejs'), because it spawns processes. - Avoid destructive git commands unless explicitly requested.
- Maintain the solid, high-contrast, no-gradient design system. Do not introduce glassmorphism or low-contrast elements.
- Keep
/(dashboard) focused on the core research loop:- engine/session visibility
- composer + prompt send flow
- session timeline/transcript/message inspection
- event/debug visibility needed during active research
- Move advanced/administrative controls to
/settingswhen possible:- theme/scheme customization
- provider auth + model/agent configuration
- MCP controls
- project/worktree/config editors
- PTY terminal controls
- permission/question queues
- TUI shortcut execution
- raw OpenCode API explorer and high-impact mutation tools
- Avoid duplicating complex control surfaces across both pages unless there is a clear workflow reason.
- Default startup path is
opencode serve --hostname 127.0.0.1 --port 4096. - Do not assume
opencode servesupports browser/CORS flags on every version. - If startup fails, preserve and expose logs through status endpoint.
- Prefer env-driven overrides (
OPENCODE_COMMAND,OPENCODE_API_URL) over hardcoding. - Session monitoring should use OpenCode HTTP APIs (
GET /session,GET /session/:id,GET /session/:id/message) viasrc/lib/opencode.ts. - Keep monitor reads non-destructive; do not mutate/delete sessions from the monitor endpoint.
- Preserve SSE bridge behavior:
GET /api/opencode/eventssupportsscope=instance|global|bothandautostart=0|1.- Bridge emits normalized event envelopes with monotonic
seq.
- Keep TypeScript strict-compatible.
- Keep UI mobile-safe and desktop-safe.
- Prefer dashboard simplification over adding new advanced cards to
/. - If adding admin/operator controls, place them in
/settingsfirst unless they are required in the primary research loop. - Keep the frontend token-driven:
- Semantic tokens are defined in
src/app/globals.css(surface/text/border/status/interactive variables). - Runtime theme definitions are in
src/components/opencode-monitor-shell.tsx.
- Semantic tokens are defined in
- When introducing new UI controls, prefer primitives in
src/components/ui/*instead of ad-hoc styled elements. - Preserve result contract used by frontend:
id,query,status,sessionId,answer,sources,metadata,timestamp
- Preserve monitor contracts used by frontend:
- List mode:
running,host,port,started,count,sessions - Detail mode:
running,host,port,started,session,messages,messageCount,latestMessageAt,activeToolCalls - Detail mode optional additions:
todo,diff,children
- List mode:
- Preserve monitor include behavior:
GET /api/opencode/monitorsupportsinclude=CSV.- Optional include blocks are additive (
mcp,lsp,formatter,projects,config).
- Preserve sessions passthrough query behavior:
GET /api/opencode/sessionssupportsroots,start,search,limit.
- Keep typed action envelopes stable:
POST /api/opencode/actionvalidation/action-resolution errors use{ ok: false, error: { code, message, details } }.
- If you change API payload shape, update both API route and UI types in the same change.
Run after meaningful changes:
npm run lint
npm run build -- --webpackOptional live smoke test:
- Start app:
npm run dev - Check status:
GET /api/opencode/status - Check sessions:
GET /api/opencode/sessions - Check monitor:
GET /api/opencode/monitor - Check events stream:
GET /api/opencode/events?scope=both - Check timeline:
GET /api/opencode/session/<id>/timeline - Check transcript:
GET /api/opencode/session/<id>/transcript - Submit query:
POST /api/query - Confirm
metadata.opencode.startedbehavior and returnedsources - Confirm new session and messages appear in
/api/opencode/sessions?sessionId=<id>
When changing behavior, update README.md in the same PR/commit.
Use update-api-plan.md to track all updates and feature work in a checklist format.
The following repositories are cloned in /reference for code/inspiration reference:
opencode(anomalyco/opencode)CodexMonitor(Dimillian/CodexMonitor)