docs(06): auto-generated context (lab advisor)

This commit is contained in:
Mikkel Georgsen 2026-04-10 07:23:51 +00:00
parent 78b1dbb6ba
commit ef20f8e83f

View file

@ -0,0 +1,82 @@
# Phase 6: Lab Advisor - Context
**Gathered:** 2026-04-10
**Status:** Ready for planning
**Mode:** Auto-generated (autonomous mode)
<domain>
## Phase Boundary
Users can ask strategic homelab questions and receive streaming answers from Claude Opus with full inventory context, with conversation history persisted across sessions. This phase delivers the chat interface, NetBox inventory context assembly, OpenRouter Opus integration with SSE streaming, and PostgreSQL-backed chat history.
</domain>
<decisions>
## Implementation Decisions
### Chat Architecture
- Backend: AdvisorHandler with POST /api/advisor/chat (streaming) and GET /api/advisor/conversations
- Frontend: AdvisorPage at /advisor route with chat UI
- Server-Sent Events for streaming response tokens
- Use existing AIClient interface (Phase 2) with Opus model via OpenRouter
### Context Assembly
- On each new chat, fetch full inventory summary from NetBox
- Compress to compact text format: count by category, recent items, key specs
- Include in system prompt to Opus
### Conversation History
- Store in PostgreSQL (already running at 10.5.0.109)
- Tables: conversations (id, started_at, model), messages (id, conversation_id, role, content, created_at)
- Use database/sql + pgx driver
- GET /api/advisor/conversations returns list, GET /api/advisor/conversations/:id returns full thread
### Model Selection
- Default: anthropic/claude-opus-4 via OpenRouter
- Configurable via dropdown — list available OpenRouter models
- Store selection in conversation record
### OpenRouter Integration
- Existing TierClient pattern from Phase 2 — just need to add streaming support
- Use go-openai's CreateChatCompletionStream
</decisions>
<code_context>
## Existing Code Insights
### Reusable Assets
- internal/ai/client.go — AIClient interface, TierClient
- internal/ai/orchestrator.go — pattern for tier3 advisor
- internal/netbox/client.go — ListDevices for inventory context
- internal/api/router.go
- web/src/lib/api.ts
- web/src/components/layout/AppShell.tsx
### Integration Points
- Add internal/advisor/ package
- Add internal/store/ package for PostgreSQL access (or extend config)
- Add internal/api/handlers/advisor.go
- Add web/src/pages/AdvisorPage.tsx
- Wire /advisor route
</code_context>
<specifics>
## Specific Ideas
- pgx driver: github.com/jackc/pgx/v5
- Conversation list in left sidebar, current chat in main panel
- Streaming via EventSource on frontend
- Inventory snapshot cached for 60s to avoid hammering NetBox
</specifics>
<deferred>
## Deferred Ideas
- Multi-turn conversation editing
- Export conversations
- Voice input
</deferred>