# Build S2: Cold Turkey WritingLock — kiosk, chrome integration, unbroken typing > **Date:** 2026-11-04 > **Type:** issue > **Reference:** [#162](https://git.babylondreams.de/AlexKucera/museion/issues/162) (map [#158](https://git.babylondreams.de/AlexKucera/museion/issues/158), work issue [#140](https://git.babylondreams.de/AlexKucera/museion/issues/140)) ## Goal The integration slice: wire the S1 goal engine (#161) and the #160 contract render into the app — `WritingLockState` (lock ⇒ focus invariant), the kiosk per the #159 factsheet, the arm-bar/readout/dot/note chrome, the refusals (⌥⌘F, focus exit, quit, ⌘W, new-buffer paths), and the hard AC: typing is never interrupted by the unlock transition. ## What Was Done - **`Museion/WritingLockState.swift`** (new) — the machine (`WritingLockState`: start/feed/tick/complete, 1 s ticker, `completionNote` fading ~6 s, `static weak active` for the delegate), the kiosk (`WritingLockKiosk`: 6-option recipe + `.disableScreenCornerInteractions`, already-fullscreen handling, hosted-test no-op), and `WritingLockAppDelegate` (`applicationShouldTerminate → .terminateCancel` while locked). - **`FocusChrome.swift`** grows the chrome lineage (map settle 6): `ColdTurkeySeat` (one bottom-center seat: arm-bar | readout | note), `ColdTurkeyArmBar` (bare mono, selector/steppers/Start, Esc via hidden `.cancelAction` button), `ColdTurkeyReadout` (numerals + 2 px hairline, terracotta @80 % inside the last 20 %), `ColdTurkeyNote`, `ColdTurkeyDot` (bottom-right pip, hover label). - **`MuseionApp.swift`** — `@NSApplicationDelegateAdaptor(WritingLockAppDelegate.self)`; View ▸ Start Cold Turkey… (focus-gated, second path per #160); disabled-while-locked: Toggle Focus Mode (the refusal IS the lock), Toggle Reading Mode, New Post/Outline/Project, Open…, Import…; `AppGateState.writingLock` + `startWritingLock(goal:)` (settles the lock ⇒ focus invariant, baseline = `posts.editorBodyText`). - **`WorkspaceView.swift`** — left-edge focus overlay suppressed while locked; window drop destination refuses while locked. - **`PostsPaneView.swift`** — mentor hover reveal suppressed while locked; CT chrome mounted as overlays on the focused ZStack ONLY (lock transitions never restructure `editorColumn` — the #87 remount hazard); leaving focus drops a stale arm-bar. - **`PostEditorView.swift`** — `ProseTextView.onTextChange` (both modes) feeds `gate.writingLock.feed(text:)` per keystroke. - **`PostsModel.swift`** — `canArmWritingLock` (mirrors the editor branch's outline routing: prose drafts, the guest, prose posts; outline pieces never) + `editorBodyText` (live whole-document text of the surface being shown). - **`GLOSSARY.md`** — the Cold Turkey entry (settle 7: glossary + UI). - **`MuseionTests/WritingLockTests.swift`** (new) — 16 pins: machine transitions, contract shapes (readout/clock/near-goal/note/arm scales), the 7-bit kiosk recipe, the canArm mirror over `makeModelHome`, the guest pins, the lock ⇒ focus invariant. - DOX pass: `Museion/AGENTS.md` (entry point, focus-mode, WorkspaceView/PostsPaneView/PostsModel bullets, WritingLockState bullet) + `MuseionTests/AGENTS.md`. ## Decisions & Rationale | Decision | Rationale | |----------|-----------| | ⌘W refusal = NSEvent local monitor, not a menu replacement | `CommandGroupPlacement` has NO `.closeItem` on macOS SwiftUI (compile error, verified against the 27.2 swiftinterface) and SwiftUI owns the stock window delegate, so the #159 `windowShouldClose` delegate approach is unreachable. A local keyDown monitor (the OutlineDrag pattern — monitors run before menu key equivalents) swallows ⌘W only while locked; quiet, no dialog. | | Quit refusal via `@NSApplicationDelegateAdaptor` | Every quit path (⌘Q, Quit menu, AppleEvents) routes through `applicationShouldTerminate` — the factsheet's exact claim, now in SwiftUI's world. The delegate reads `WritingLockState.active` (weak static set in init) instead of holding app-state wiring. | | Chrome mounts as overlays on the focused ZStack only | Lock ⇒ focus never flips `isFocused`, so the branch structure under the editor column is FROZEN during lock/unlock — combined with the probe-verified fullscreen round trip (first-responder identity holds), the typing-continuity AC holds by construction, not by deferral machinery. | | Feed = `ProseTextView.onTextChange`, baseline = `PostsModel.editorBodyText` | One keystroke, one rail: the coordinator already sees every edit (session + draft modes); the model already holds the live text. No new observation machinery (`withObservationTracking` avoided). | | External guest CAN arm | "Posts + drafts, not Outline" settles the outline exclusion; the guest is a prose editing surface the engine counts fine — excluded, it would surprise mid-flow. Calibration gate can flip it with one guard. | | Already-fullscreen windows enter the lock in place | `enter()` records whether WE toggled fullscreen; `exit()` replays only what entry toggled — arming from a fullscreen focus session neither exits nor double-toggles. | | Menu item plain in the View group, not a Focus submenu | A one-item submenu is UI noise; the settle's "Focus ▸ Start Cold Turkey…" reads as a path, the render's caption language. One-line change if Alexander wants nesting. | ## Gotchas & Fixes | Problem | Root Cause | Fix | |---------|------------|-----| | `CommandGroup(replacing: .closeItem)` failed to compile | No such placement in macOS SwiftUI 27.2 | Local key monitor (see decisions) | | `nonisolated enum ArmScale` with stored properties | Enums can't have stored properties | `nonisolated struct` with static instances | | deinit couldn't cancel `ticker`/`noteFade` | Swift 6 deinit is nonisolated; the props are MainActor | Deleted the deinit — the tasks hold `weak self` and self-terminate on the next guard | | Switch-expression form tripped `#NoUsage` warnings | New-diagnostic pedantry on tuple/string cases | Plain `switch` + `return` statements | | Test build failed on `.hideDock` statics | MemberImportVisibility — test file lacked `import AppKit` | Added the import | | `lockOptions` unreadable from nonisolated test context | The enum is `@MainActor` | `nonisolated static let` (immutable Sendable data) | | 1 test failure: `words.clamp(4999) == 5000` | MY expectation was wrong — 4999 is in-range; clamp is identity there (steppers stay on the 50-grid) | Fixed the pin: `clamp(4999) == 4999`, added `clamp(5001) == 5000` | | swiftlint error: variable `s` | identifier_name min length in `clockString` | Renamed `total` | ## Files Changed | File | Change Summary | |------|---------------| | `Museion/WritingLockState.swift` | NEW — lock machine, kiosk recipe, quit-refusal delegate | | `Museion/FocusChrome.swift` | The CT chrome lineage (seat/arm-bar/readout/note/dot) | | `Museion/MuseionApp.swift` | Delegate adaptor, CT menu item, locked-state refusals, `startWritingLock` | | `Museion/WorkspaceView.swift` | Overlay + drop-destination lock suppression | | `Museion/PostsPaneView.swift` | Mentor-overlay suppression, CT chrome mounts | | `Museion/PostEditorView.swift` | `onTextChange` feed through both editor modes | | `Museion/PostsModel.swift` | `canArmWritingLock` + `editorBodyText` | | `GLOSSARY.md` | Cold Turkey entry | | `MuseionTests/WritingLockTests.swift` | NEW — 16 pins | | `Museion/AGENTS.md`, `MuseionTests/AGENTS.md` | DOX pass | | `MuseionTests/ACPClientTests.swift` | swiftformat-only import reorder (repo-wide pass caught a pre-existing drift) | ## Verification - Build: `xcodebuild … build` — **SUCCEEDED**. - Suite: `xcodebuild … test` — **617 executed / 617 passed / 0 failed**, counted in the xcresult (`Test-Museion-2026.11.04_13-14-24-+0100.xcresult`), never the banner. Baseline was 601 (#161) — +16 new tests. - swiftformat 0 files dirty; swiftlint 0 errors in `Museion/` + `MuseionTests/` (the remaining error-level findings are pre-existing `spike/` territory). - GitNexus: impact analysis ran before edits (all touched symbols roll up to `WorkspaceView.paneContent`, LOW risk); `detect_changes` after — only the intended files. ## Open Items & Next Steps - [ ] [#163 Calibration gate](https://git.babylondreams.de/AlexKucera/museion/issues/163) — now unblocked: does the lock rule calm? Live dogfood needed (fullscreen entry/exit, ⌘Tab/⌘Q/⌘W refusals, typing through unlock, the readout's near-goal shift) — the unpinnable-window surfaces. - [ ] Landing: the slice sits as an uncommitted working tree (map rule — no autonomous commits); landing on `main` needs Alexander's go. - [ ] Fog (map #158): preset chips + keyboard arming stay post-calibration; the S5.1 auto-capture tie-in revisits after the gate. - [ ] Accepted edge: the Fix Cards palette window (if open when the lock starts) is a separate space — not covered by the kiosk; the calibration gate can flag it if it ever matters. --- *Log written by write-log skill* ## Amendment — same day, live dogfood ruling Alexander ran the arm-bar and ruled (screenshot `media_9rFtnT7oxx`): the bare seat let the document text show through and obscure the controls. Three changes: 1. The arm-bar carries a **blending chip** — the focus ground's own color, the faintest token hairline (`DesignTokens.border`), no shadow. Ruling 1 of #160 corrected for the arm-bar only; readout + note stay bare (judged at #163). 2. The arm value is **directly typeable** (plain `TextField`, parsed + clamped at every read — Start, steppers, submit — so garbage or unsubmitted text can never arm an out-of-range block); ± steppers stay for coarse moves. 3. Defaults amended: **250 words / 5 minutes** (were 500/30). Recorded: comment on #160 (the ruling's home), map #158's decision line amended, arm-scales pin updated. ## Amendment 2 — same day, second dogfood round 1. **Ranges**: what's typed is what arms — words 1…1000, minutes 1…60 (were floors 50/5, ceilings 5000/180; the clamp had bumped a typed 10 up to 50). Floor 1; empty/garbage falls to the default. 2. **The "escape" trap**: mid-block ⌃⌘F toggled fullscreen off — the kiosk options hold even windowed (#159's own finding), leaving a windowed kiosk (no menu bar, ⌘W/⌘Q refused) that reads as "escaped" while the block still runs. Fix: the refusal monitor now swallows ⌃⌘F while locked too — fullscreen leaves only via completion. Remaining open doctrine (flagged to #163): a words block that outlives intent has NO exit — quit is refused by design; minutes blocks self-complete ≤ 60 min. 3. **Readout + completion note** carry the arm-bar's blending chip (same occlusion over document text). 617/617 green (xcresult `Test-Museion-2026.11.04_14-36-55`), lint clean. ## Amendment 3 — the quit valve (#163 ruling, same day) ⌘Q mid-block now asks once (Alexander's pick from three options): a modal "Walk away from the block?" — Walk Away clears the kiosk and terminates (the block dies quietly, nothing kept); Keep Writing cancels. Unlocked quits pass through untouched. Pinned: the delegate's unlocked path returns `.terminateNow` (the locked branch is a modal — unpinnable headless). 618/618 green (xcresult `Test-Museion-2026.11.04_14-41-55`). ## Finish audit (same day) Three-reviewer fanout (ponytail / security / general) over the session tree. Accepted and landed: - **Key-match predicate** (converged MEDIUM, both reviewers): `charactersIgnoringModifiers == "w"` missed Caps-Lock ("W") and non-Latin layouts while AppKit's menus still fired the stock Close → windowless kiosk. Now `refusesKey(keyCode:characters:modifiers:)` matches by physical key code (13/3/45 = W/F/N) with the exact modifier intersection, plus a lowercased character net; ⌘N added (the stock New Window item SwiftUI owns stays enabled mid-lock). Pinned ×9, flip-verified. - **Ticker flake** (general MEDIUM): machine tests pass `spawnsTicker: false` — the real 1 s ticker could complete a met words goal before the injected tick under a main-actor stall. - **Ponytail**: `blendingChip()` dedup (3 sites), model-side `withAnimation` dropped (double fade curve). - **General LOWs**: pane change clears a pending arm-bar (WorkspaceView `onChange(of: selection)`); kiosk captures the ENTERED window for exit; `ArmScale.parse` extracted + pinned (garbage/empty/overflow → default); the #111 mixed-outline guard hold pinned as a canArm disarm. Deferred: ⌘Q modal re-entrancy oddity (idempotent by construction, both reviewers concur); `active` last-wins (latent, fail-open — a DEBUG assert would fire in hosted tests); `DraftStats.words` lowercased-array alloc per keystroke while locked (#161 committed code, out of scope — noted for #163 dogfood). Verification: 620/620 (xcresult `Test-Museion-2026.11.04_15-14-07`, +2 suites), flip cycle failed each pin on its own guard exactly, swiftformat/swiftlint clean.