feat(cold-turkey): the writing lock (#162)
CI / ci (push) Canceled after 0s

Wires #161's goal engine and #160's contract into the app: armed
from a corner dot or View ▸ Start Cold Turkey…, enforced by the
macOS app-kiosk (7-option presentation combo + fullscreen, restored
on completion), readout with hairline + near-goal terracotta, and
a completion note fading back into focus. While held: focus exit,
reading, new buffers, ⌘W/⌃⌘F/⌘N refused (key-code-matched monitor
— character matching is layout/Caps-blind; no .closeItem placement
exists), ⌘Q asks once per #163's ruling. Typing continuity holds by
construction — lock ⇒ focus freezes the branch under the editor and
chrome mounts as overlays only. Arm values type directly (1…1000
words / 1…60 min, defaults 250/5). Nothing persists.

Wayfinder map #158 Build S2; suite 620, flip-verified pins.
This commit is contained in:
AlexKucera committed 2026-11-04 15:58:47 +01:00
1 parent 7b6abb5d65
commit a9e199fce4
16 files changed
+1167 -19

No files matched your search

+41
View File
@@ -39,6 +39,11 @@ final class AppGateState {
/// rail/library/mentor and the editor toolbar; overlay panes return on
/// edge hover.
var isFocused = false
/// #162 (Cold Turkey S2, map #158): the writing lock — armed from the
/// focus-mode arm-bar, held while the goal runs. Lock ⇒ focus: while
/// locked, `isFocused` cannot leave true (the ⌥⌘F refusal IS the
/// lock), hover-reveal zones stay suppressed, and the kiosk holds.
let writingLock = WritingLockState()
/// #17: the Museion Home — repoint-only (ADR-0004). Defaults to
/// `~/Documents/Museion`; UserDefaults is the persistence floor: a Home is
/// a plain folder, nothing app-owned to put in a database. Non-file URLs
@@ -74,6 +79,15 @@ final class AppGateState {
await gateModel.beginAutomaticCheck()
}
/// #162: Start Cold Turkey — the arm-bar's single commit. The lock ⇒
/// focus invariant is settled here (arming is focus-gated anyway;
/// this is the belt), and the baseline body is the live editor text.
func startWritingLock(goal: WritingGoal) {
guard !writingLock.isLocked else { return }
isFocused = true
writingLock.start(goal: goal, body: posts.editorBodyText ?? "")
}
/// The auto-fire chain — the exact onEnginePass body from the gate era,
/// moved verbatim: provisioning (#47, idempotent — re-fires per passing
/// Re-check are no-ops), then the daily backup (#50 — a failed
@@ -92,6 +106,9 @@ final class AppGateState {
/// between the app and the headless `--serve-mcp` tool server.
struct MuseionApp: App {
@State private var gate = AppGateState()
/// #162: the quit refusal while a Cold Turkey block holds (#159
/// delegate-level coverage — every quit path routes through here).
@NSApplicationDelegateAdaptor(WritingLockAppDelegate.self) private var appDelegate
var body: some Scene {
WindowGroup {
@@ -149,12 +166,25 @@ struct MuseionApp: App {
NotificationCenter.default.post(name: .toggleReadingMode, object: nil)
}
.keyboardShortcut("r", modifiers: .command)
// #162: the editor is the only surface while locked — the
// reading swap would interrupt typing mid-block.
.disabled(gate.writingLock.isLocked)
// #21: focus mode — beside reading, same posture (system View
// menu + shortcut). Transient like reading: no persistence, no
// Esc exit (rejected at charting) — the toggle is the only way.
// ⌥⌘F — ⇧⌘F is taken by a system-wide shortcut on this machine,
// ⌃F shadows the editor's Emacs caret-forward binding.
// #162: disabled while a Cold Turkey block holds — the refusal
// IS the lock (#158 settle 6: completion drops back to focus).
FocusModeToggle(gate: gate)
.disabled(gate.writingLock.isLocked)
// #162 (#160 ruling 6): the second arming path — dot-first,
// menu second. Focus-mode-gated; nothing prose to lock or a
// block already running disables it.
Button("Start Cold Turkey…") {
gate.writingLock.showsArmBar = true
}
.disabled(!gate.isFocused || gate.writingLock.isLocked || !gate.posts.canArmWritingLock)
}
// #50: reveal the snapshots folder in Finder (restore = manual
// copy-back, documented in the bundled help doc).
@@ -215,6 +245,9 @@ private struct NewPostButton: View {
var body: some View {
Button("New Post") { gate.posts.newPost() }
.keyboardShortcut("n", modifiers: .command)
// #162: the open Piece stays stable for counting while a
// Cold Turkey block holds.
.disabled(gate.writingLock.isLocked)
}
}
@@ -226,6 +259,8 @@ private struct NewOutlineButton: View {
var body: some View {
Button("New Outline") { gate.posts.newOutline() }
.keyboardShortcut("n", modifiers: [.command, .shift])
// #162: piece stability while a block holds.
.disabled(gate.writingLock.isLocked)
}
}
@@ -237,6 +272,8 @@ private struct NewProjectButton: View {
var body: some View {
Button("New Project…") { gate.posts.stageNewProject() }
.keyboardShortcut("n", modifiers: [.command, .option])
// #162: piece stability while a block holds.
.disabled(gate.writingLock.isLocked)
}
}
@@ -252,6 +289,8 @@ private struct OpenExternalButton: View {
}
}
.keyboardShortcut("o", modifiers: .command)
// #162: piece stability while a block holds.
.disabled(gate.writingLock.isLocked)
}
}
@@ -268,6 +307,8 @@ private struct ImportFilesButton: View {
}
}
.keyboardShortcut("o", modifiers: [.command, .shift])
// #162: piece stability while a block holds.
.disabled(gate.writingLock.isLocked)
}
}