Files
gochat/backend/internal/service
rogee 6d8eda28b5 Phase 3.4: Context window optimization — token estimation + sliding window
- token_estimator.go (new): TokenEstimator with ~4 chars/token heuristic,
  EstimateText/EstimateMessages methods, TruncateMessages sliding window
  that drops oldest messages to fit token budget, BuildContextWindow
  entry point that converts conversation messages to LLM format with
  token-budgeted truncation (default 4096 tokens)
- copilot_context_service.go: fetch up to 100 messages (was 20), then
  apply BuildContextWindow truncation to fit within 4096 token budget;
  log how many messages were dropped

Verified: go build + go vet + go test all pass
Semantic search route reaches handler (times out on LLM call without API key,
confirming route + service wiring is correct)
2026-07-08 15:38:08 +08:00
..