Build S1: Cold Turkey goal engine — net-words delta + countdown #161

Closed
opened 2026-11-04 11:01:59 +01:00 by AlexKucera · 1 comment
Owner

Question

Build the pure logic slice the lock consumes — no chrome, no UI:

  • WritingGoal model: words(Int) | minutes(Int) — one goal per block, fixed at arm time.
  • Net-words counter: baseline word count at arm; live net-new-words on text change (deleting costs — net, not gross; a 2000-word paste counts, gaming yourself is your business). A tiny struct beside DraftStats.swift; word-boundary semantics pinned by tests and consistent with whatever DraftStats counts (cite it — headings are body text, frontmatter is not).
  • Countdown: minutes goal = deadline at arm + minutes; never pauses (idle, app hidden, lock refusals — nothing pauses it).
  • Tests: word-delta math (type/delete/paste/undo), timer boundaries, goal-met transitions.

AC: pure Swift, no UI, no engine dependency; suite green — count executed tests in the xcresult, never trust the banner (#31, #134).

Part of #158

[Generated by AI]

## Question Build the pure logic slice the lock consumes — no chrome, no UI: - `WritingGoal` model: `words(Int) | minutes(Int)` — one goal per block, fixed at arm time. - Net-words counter: baseline word count at arm; live net-new-words on text change (deleting costs — net, not gross; a 2000-word paste counts, gaming yourself is your business). A tiny struct beside `DraftStats.swift`; word-boundary semantics pinned by tests and consistent with whatever DraftStats counts (cite it — headings are body text, frontmatter is not). - Countdown: minutes goal = deadline at arm + minutes; never pauses (idle, app hidden, lock refusals — nothing pauses it). - Tests: word-delta math (type/delete/paste/undo), timer boundaries, goal-met transitions. AC: pure Swift, no UI, no engine dependency; suite green — count executed tests in the xcresult, never trust the banner (#31, #134). Part of #158 [Generated by AI]
AlexKucera added the wayfinder:task label 2026-11-04 11:01:59 +01:00
AlexKucera self-assigned this 2026-11-04 11:55:45 +01:00
Author
Owner

Resolution — S1 built, suite green (601/601)

Landed (uncommitted working tree per the map's standing rule):

  • Museion/WritingGoal.swift — WritingGoal (words(Int) | minutes(Int), one goal per block, fixed at arm) + WritingGoalRun: the armed block carrying goal + armedAt + baseline/current word counts. API S2 consumes: update(text:) (whole-document text), netNewWords (deleting costs; a big paste counts), secondsRemaining(now:), isMet(now:), progress(now:) (0…1 clamped — the readout hairline's number).
  • Museion/DraftStats.swift — internal words(in:) added: the one word-count rail. Cold Turkey net-words counts through the SAME tokenizer as the first-draft stats, so the two can never drift (the ticket's "cite DraftStats" demand, answered structurally: "writer's" = 2 words, headings are body text, frontmatter never reaches the editor body).
  • MuseionTests/WritingGoalTests.swift — 10 pins: word-delta math (type/delete/paste/undo), timer boundaries (−1 s ≠ met, on-the-second = met), goal-met transitions, tokenizer parity, progress fractions.

Key design fact for S2: the engine owns no clock — now is injected into every call, so "never pauses" holds by construction (no pause API exists). WritingLockState owns the ticker and polls isMet(now:); isMet is live truth, unlatched (deleting below target un-mets — complete on the first true tick). Named WritingGoalRun per charting decision 7 (writingLock stays S2's state machine name).

Verification: definitive full run on the settled tree, counted from the xcresult (not the banner): 601 executed / 601 passed / 0 failed, all 10 WritingGoalTests cases in the executed tree. swiftformat + swiftlint clean on the three touched files; GitNexus impact on DraftStats ran HIGH-fan-out but the edit is purely additive (new member, zero existing call sites touched).

Two facts for the record:

  1. This repo's swiftformat strips a BARE @Suite attribute but keeps @Suite("Name") — every suite must carry the string argument (now noted in MuseionTests/AGENTS.md).
  2. One transient EditorSessionTests/debounce flushes… failure under the added parallel suite (the #147 load-flake class) — isolated run 8/8 green, green in the definitive run; no code change. If it recurs as suites grow, its wait window needs the #147 treatment.

Devlog: docs/devlog/20261104-issue161-cold-turkey-goal-engine_log.md. Fog unchanged — S5.1 tie-in and preset chips stay post-calibration; nothing graduates from this slice.

[Generated by AI]

## Resolution — S1 built, suite green (601/601) **Landed** (uncommitted working tree per the map's standing rule): - `Museion/WritingGoal.swift` — `WritingGoal` (`words(Int)` | `minutes(Int)`, one goal per block, fixed at arm) + `WritingGoalRun`: the armed block carrying goal + `armedAt` + baseline/current word counts. API S2 consumes: `update(text:)` (whole-document text), `netNewWords` (deleting costs; a big paste counts), `secondsRemaining(now:)`, `isMet(now:)`, `progress(now:)` (0…1 clamped — the readout hairline's number). - `Museion/DraftStats.swift` — internal `words(in:)` added: the one word-count rail. Cold Turkey net-words counts through the SAME tokenizer as the first-draft stats, so the two can never drift (the ticket's "cite DraftStats" demand, answered structurally: "writer's" = 2 words, headings are body text, frontmatter never reaches the editor body). - `MuseionTests/WritingGoalTests.swift` — 10 pins: word-delta math (type/delete/paste/undo), timer boundaries (−1 s ≠ met, on-the-second = met), goal-met transitions, tokenizer parity, progress fractions. **Key design fact for S2**: the engine owns no clock — `now` is injected into every call, so "never pauses" holds by construction (no pause API exists). `WritingLockState` owns the ticker and polls `isMet(now:)`; `isMet` is live truth, unlatched (deleting below target un-mets — complete on the first true tick). Named `WritingGoalRun` per charting decision 7 (`writingLock` stays S2's state machine name). **Verification**: definitive full run on the settled tree, counted from the xcresult (not the banner): **601 executed / 601 passed / 0 failed**, all 10 WritingGoalTests cases in the executed tree. swiftformat + swiftlint clean on the three touched files; GitNexus impact on `DraftStats` ran HIGH-fan-out but the edit is purely additive (new member, zero existing call sites touched). **Two facts for the record**: 1. This repo's swiftformat strips a BARE `@Suite` attribute but keeps `@Suite("Name")` — every suite must carry the string argument (now noted in MuseionTests/AGENTS.md). 2. One transient `EditorSessionTests/debounce flushes…` failure under the added parallel suite (the #147 load-flake class) — isolated run 8/8 green, green in the definitive run; no code change. If it recurs as suites grow, its wait window needs the #147 treatment. Devlog: `docs/devlog/20261104-issue161-cold-turkey-goal-engine_log.md`. Fog unchanged — S5.1 tie-in and preset chips stay post-calibration; nothing graduates from this slice. [Generated by AI]
Sign in to join this conversation.