prosolis 3c5f3ecb96 Phase 4: Ask Petal SSE chat
Conversational follow-up on a suggestion, streamed token-by-token.

Backend (interface-only; handlers never touch a concrete LLM client):
- internal/llm/chat.go: StreamAskPetal with conversational sampling
  (max_tokens 512, temp 0.7, rep 1.15, top_p 0.92, stop "\n\n\n"),
  reusing AskPetalSystemPrompt + TrimHistory.
- internal/suggestions/chat.go: POST /api/suggestions/:id/chat. One
  user-scoped join loads the suggestion + parent content_text;
  surroundingParagraph extracts the \n\n-bounded paragraph at from_pos
  (whole-doc fallback when unlocated) and injects it server-side.
  Streams event: token / event: done SSE frames with JSON-encoded data
  so token newlines can't break framing; real http.Flusher per chunk.
  LLM-unreachable -> 502 before SSE headers; unknown suggestion -> 404.

Frontend:
- streamSuggestionChat: fetch + ReadableStream SSE parser (not
  EventSource, needs POST), abortable.
- AskPetal.tsx: whole conversation in component state (no persistence,
  cleared on close), Petal's first bubble pre-seeded with the
  explanation, rose/lavender bubbles, CJK font stack on the bubbles
  only (Note #17), streaming caret.
- SuggestionCard "Ask Petal" pill pins the card open while chatting
  (hover-close suppressed, click-away closes) and widens it to 340px.

Tests: chat_test.go covers streamed-text concat + done event,
server-side context injection on the system message, sampling params,
404, and surroundingParagraph. go build/vet/test clean, tsc clean,
vite build OK. Live SSE smoke-tested against a fake streaming vLLM:
tokens flushed individually through the chi middleware stack, done
terminator, 502 on LLM-down, 404 on unknown suggestion.

Claude-Session: https://claude.ai/code/session_016Yr6jELuRc7hyzYLccQKZd
2026-06-25 21:05:39 -07:00
2026-06-25 21:05:39 -07:00
2026-06-25 21:05:39 -07:00
2026-06-25 20:20:04 -07:00
2026-06-25 20:20:04 -07:00
2026-06-25 21:05:39 -07:00
2026-06-25 20:20:04 -07:00
2026-06-25 20:20:04 -07:00

🌸 Petal

A self-hosted, privacy-first writing editor with warm bubbly design, auto-save, and local-LLM grammar/ESL suggestions. See petal-spec.md for the full design spec and BUILD_PLAN.md for build progress.

Stack

Go + chi backend · SQLite (modernc, pure Go) · React + Vite + Tiptap + Tailwind v4 frontend · local vLLM/Ollama for AI suggestions. Single-binary deployment (frontend embedded via go:embed).

Local development

Two processes during development:

# 1. Backend (serves /api on :8080)
go run ./cmd/server

# 2. Frontend dev server (HMR on :5173, proxies /api → :8080)
cd web && npm install && npm run dev

Open http://localhost:5173 while developing.

Production build (single binary)

cd web && npm run build      # emits web/dist (embedded by the Go binary)
cd .. && go build -o petal ./cmd/server
./petal                      # serves UI + API on :8080

Configuration is via environment variables — copy .env.example to .env.

Status

Early build, multi-session. Auth (Authentik), Copyleaks plagiarism, and Docker/Traefik deployment are deferred — see BUILD_PLAN.md.

Description
Petal is a self-hosted, privacy-first writing editor for an ESL user. It replaces Grammarly with a warm, bubbly web app that combines Tiptap rich text editing, auto-save cloud storage, and periodic AI-powered grammar/ESL suggestions backed by a local vLLM inference endpoint.
Readme 14 MiB
Languages
TypeScript 54.8%
Go 39.8%
CSS 3.1%
Python 2%
Shell 0.2%
Other 0.1%