Phase 12 + 13: collocation coach + vocabulary garden

Phase 12 — collocation coach: a third suggestion family for gentle
"natives usually say…" hints on non-native word pairings, reusing the
existing runPass/pendingScope/rail machinery.
- llm/collocation.go (RunCollocation, 25s floor, reuses ParseCheckpoint)
  + collocationSystemPrompt/CollocationMessages (warm, Mandarin gloss,
  defers grammar/spelling to the grammar family)
- migration 0005 rebuilds the suggestions table to extend the type CHECK
  (SQLite can't ALTER a CHECK)
- collocationScope + CollocationLimit + POST /{id}/collocation
- fix: grammarScope was `type != 'voice'` and would wipe the new
  collocation flags; now `type NOT IN ('voice','collocation')`
- frontend: --color-blossom, "Make it sound natural 🌸" pill,
  collocating/runCollocation in useCheckpoint, StatusBar dot

Phase 13 — vocabulary garden: capture looked-up words and surface them
for gentle spaced repetition.
- new internal/vocab package: migration 0006 (vocab_words, SM-2-lite
  columns, doc_id ON DELETE SET NULL, UNIQUE(user_id,word)),
  scheduler.go (Leitner ladder 1/3/7/16/35 then geometric; gentle
  "again", no streak-shaming), handlers (capture-upsert/list/due/
  review/delete, owner-scoped, SQLite-side datetime math)
- auto-capture on word lookup (dictionary-known words only, captures
  the surrounding sentence + doc_id) + 🤍/💚 toggle on WordCard
- GardenPanel: blossom grid (bloom by reps), flashcard review (sentence
  blanked, flip, again/good/easy, recognition↔production), sleepy-kitten
  footer; opened from a global 🌷 header button

Tests: TestCollocationPassCoexists, vocab scheduler + handlers, db CHECK
extended. go build/vet/test + tsc + vite + vitest (51/51) clean;
migration verified against a copy of the live DB; live backend smoke
walked the full vocab lifecycle + the warm-502 collocation path.

Claude-Session: https://claude.ai/code/session_016Yr6jELuRc7hyzYLccQKZd
This commit is contained in:
prosolis
2026-06-26 15:50:25 -07:00
parent 20442d1356
commit 8aa437ec82
23 changed files with 1614 additions and 58 deletions

View File

@@ -260,6 +260,71 @@ END;
INSERT INTO documents_fts (doc_id, title, content_text)
SELECT id, title, content_text FROM documents;
`,
},
{
// Collocation coach (Phase 12). Adds a third suggestion family,
// 'collocation', for gentle "natives usually say…" hints on
// non-native word pairings. The `type` column carries a CHECK
// constraint and SQLite cannot ALTER one in place, so we rebuild the
// suggestions table with the extended CHECK, copy every row across,
// and recreate its index. Nothing references suggestions, so dropping
// the old table is safe; the new table keeps the same ON DELETE
// CASCADE to documents.
name: "0005_collocation_suggestion_type",
stmt: `
CREATE TABLE suggestions_new (
id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),
doc_id TEXT NOT NULL REFERENCES documents(id) ON DELETE CASCADE,
from_pos INTEGER NOT NULL,
to_pos INTEGER NOT NULL,
original TEXT NOT NULL,
replacement TEXT NOT NULL,
explanation TEXT NOT NULL,
type TEXT NOT NULL CHECK(type IN ('grammar','phrasing','idiom','clarity','voice','collocation')),
status TEXT NOT NULL DEFAULT 'pending' CHECK(status IN ('pending','accepted','rejected')),
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO suggestions_new (id, doc_id, from_pos, to_pos, original, replacement, explanation, type, status, created_at)
SELECT id, doc_id, from_pos, to_pos, original, replacement, explanation, type, status, created_at FROM suggestions;
DROP TABLE suggestions;
ALTER TABLE suggestions_new RENAME TO suggestions;
CREATE INDEX idx_suggestions_doc_id ON suggestions(doc_id);
`,
},
{
// Vocabulary garden (Phase 13). Every word the writer looks up is
// captured here and put on a gentle spaced-repetition schedule, turning
// passive lookups into real vocabulary. `example` holds the sentence the
// word appeared in (captured at lookup) for context during review;
// `doc_id` links back to where she met the word (nulled if that doc is
// deleted — the word stays in the garden). The SM-2-lite scheduling
// columns (due_at/interval_days/ease/reps/lapses/last_reviewed) drive a
// Leitner-style ladder (see internal/vocab/scheduler.go). UNIQUE on
// (user_id, word) makes capture an idempotent upsert.
name: "0006_vocab_garden",
stmt: `
CREATE TABLE vocab_words (
id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),
user_id TEXT NOT NULL REFERENCES users(id),
word TEXT NOT NULL,
gloss TEXT NOT NULL DEFAULT '',
phonetic TEXT NOT NULL DEFAULT '',
example TEXT NOT NULL DEFAULT '',
doc_id TEXT REFERENCES documents(id) ON DELETE SET NULL,
due_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
interval_days INTEGER NOT NULL DEFAULT 0,
ease REAL NOT NULL DEFAULT 2.5,
reps INTEGER NOT NULL DEFAULT 0,
lapses INTEGER NOT NULL DEFAULT 0,
last_reviewed DATETIME,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
UNIQUE(user_id, word)
);
CREATE INDEX idx_vocab_due ON vocab_words(user_id, due_at);
`,
},
}