Let the garden keep what she was given, not only what she sought

Two halves of the same idea, both read out of work Petal already
records.

Planting: an accepted collocation is a learnable chunk, so it becomes a
phrase card. The scheduler didn't need to know — a three-word chunk
climbs the ladder exactly like a looked-up word. What needed care was
deciding what *isn't* a chunk (single words are word choice; a
six-word-plus "collocation" is a rewritten sentence, and sentences make
miserable flashcards), and that the example must be the *corrected*
sentence — the stored draft still holds the phrasing she just left
behind. Re-accepting the same chunk leaves the existing card alone
rather than resetting a schedule it has been climbing. The whole thing
is best-effort: accepting an edit must never fail because a flashcard
couldn't be made.

The growth journal: kept this month beside kept the month before, the
phrasing that stuck, the patterns that faded. The queries were the easy
part; the honesty is the feature. "Stuck" needs the phrase in a *second*
document, because one document is just the edit where she left it.
"Faded" says nothing at all unless she has been writing lately —
otherwise a month away from Petal comes back to her as progress, which
is the one way this could lie. And a suggestion had to start recording
when she *decided* it, not when the model proposed it, so 0012 adds
resolved_at and backfills the old rows to their created_at.

It lives as a second tab in the garden, and it feeds the kitten: after
an accept she now sometimes hears something true of her alone, once per
line, half the time, never waited for.

Claude-Session: https://claude.ai/code/session_016y6gyuHkQXPiEuW8RGQyua
This commit is contained in:
prosolis
2026-07-27 14:16:59 -07:00
parent 7b845644be
commit e9b8595456
19 changed files with 1328 additions and 5 deletions
@@ -0,0 +1,76 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
const growth = vi.fn()
vi.mock('../../api/client', () => ({ api: { growth: () => growth() } }))
import { personalCheer, resetPersonalCheersForTests, warmPersonalCheers } from './journalCheers'
import { resetPackForTests, setPackLang } from '../../i18n'
const journal = {
kept: 4,
kept_before: 2,
stuck: [{ phrase: 'make a decision', docs: 3 }],
faded: [{ pattern: '在 the morning', times: 2 }],
}
// Let the warm-up promise settle.
const settle = () => new Promise((r) => setTimeout(r, 0))
describe('personal cheers', () => {
beforeEach(() => {
resetPersonalCheersForTests()
resetPackForTests()
growth.mockReset()
})
it('says nothing before the journal has arrived — the cheer never waits', () => {
growth.mockResolvedValue(journal)
warmPersonalCheers()
expect(personalCheer()).toBeNull()
})
it('serves each personal line once, then falls silent', async () => {
growth.mockResolvedValue(journal)
warmPersonalCheers()
await settle()
const first = personalCheer()
const second = personalCheer()
expect(first).not.toBeNull()
expect(second).not.toBeNull()
expect(first!.en).not.toBe(second!.en)
// Both lines used: personal praise repeated is wallpaper, so the caller is
// handed back to the generic pool instead.
expect(personalCheer()).toBeNull()
})
it('fetches once however often it is warmed', async () => {
growth.mockResolvedValue(journal)
warmPersonalCheers()
warmPersonalCheers()
await settle()
warmPersonalCheers()
expect(growth).toHaveBeenCalledTimes(1)
})
it('is silent when the journal fails, rather than failing visibly', async () => {
growth.mockRejectedValue(new Error('offline'))
warmPersonalCheers()
await settle()
expect(personalCheer()).toBeNull()
})
it('speaks the pair the writer is in, resolved at call time', async () => {
growth.mockResolvedValue({ ...journal, faded: [] })
warmPersonalCheers()
await settle()
setPackLang('pt-PT')
const line = personalCheer()
expect(line).not.toBeNull()
expect(line!.native).toContain('make a decision')
expect(line!.native).not.toBe(line!.en)
// The English half is the same sentence in every pack.
expect(line!.en).toContain('make a decision')
})
})
@@ -0,0 +1,62 @@
// Personal material for the companion, drawn from the growth journal.
//
// The kitten's cheers are warm but generic — they'd be the same words for
// anybody. The journal already knows things that are true of *this* writer and
// nobody else ("you're using 'make a decision' on your own now"), and that is a
// far better thing to hear after accepting an edit. §5a's own example.
//
// Three rules keep it from wearing out:
// * A given line is served once per session. Personal praise repeated is
// wallpaper, and wallpaper is worse than the generic cheer it replaced.
// * The journal is fetched lazily, on the first accept, and never awaited —
// the first cheer of a session is generic, and that's fine.
// * Lines are built at call time from the pack, like every other companion
// line, so a bubble composed after /api/me is in the right language.
import { api, type GrowthJournal } from '../../api/client'
import { pack, type Line } from '../../i18n'
let journal: GrowthJournal | null = null
let inFlight = false
let served = new Set<string>()
// warmPersonalCheers starts the one fetch this module ever needs. Safe to call
// often; a failure is silent and simply leaves the companion with its generic
// pool, which is exactly the pre-journal behaviour.
export function warmPersonalCheers(): void {
if (journal || inFlight) return
inFlight = true
api
.growth()
.then((j) => {
journal = j
})
.catch(() => {
/* no journal, no personal cheer — never a visible failure */
})
.finally(() => {
inFlight = false
})
}
// personalCheer returns an unserved line about her own writing, or null when
// there is none — the caller falls back to the generic pool.
export function personalCheer(): Line | null {
if (!journal) return null
const t = pack()
const candidates = [
...journal.stuck.map((s) => ({ key: `stuck:${s.phrase}`, line: () => t.journal.cheerStuck(s.phrase) })),
...journal.faded.map((f) => ({ key: `faded:${f.pattern}`, line: () => t.journal.cheerFaded(f.pattern) })),
].filter((c) => !served.has(c.key))
if (candidates.length === 0) return null
const chosen = candidates[Math.floor(Math.random() * candidates.length)]
served.add(chosen.key)
return chosen.line()
}
// Test seam, matching resetPackForTests: module state is per-session by design.
export function resetPersonalCheersForTests(): void {
journal = null
inFlight = false
served = new Set()
}
+8 -1
View File
@@ -14,6 +14,7 @@ import {
type Line,
} from './tips'
import { analyzeProse } from './prose'
import { personalCheer, warmPersonalCheers } from './journalCheers'
import { playPop, playSound, type SoundName } from '../../audio/sounds'
import { isBedtime } from '../../lib/night'
@@ -197,7 +198,13 @@ export function useCompanion({ wordCount, saveStatus, llmDown, editTick, acceptT
firstAccept.current = false
return
}
say({ ...pick(encouragements()), tone: 'cheer' }, { celebrate: true })
// Prefer something true of her own writing over a line that would fit
// anybody — but only sometimes, so the personal ones stay a small surprise
// rather than the new default. The journal is fetched on this first accept
// and never awaited: the cheer goes out now, personal or not.
warmPersonalCheers()
const personal = Math.random() < 0.5 ? personalCheer() : null
say({ ...(personal ?? pick(encouragements())), tone: 'cheer' }, { celebrate: true })
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [acceptTick])