From d305f822aa8bce074302a4196200e80eddaaf8ba Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Thu, 5 Nov 2026 14:34:51 +0100 Subject: [PATCH] =?UTF-8?q?fix(app):=20replace=20stock=20new-window=20item?= =?UTF-8?q?=20so=20=E2=8C=98N=20fires=20new=20post=20alone?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CommandGroup(after: .newItem) left the WindowGroup's stock File ▸ New Window item in place with its ⌘N, so both actions fired — a second Museion window AND a new post. Switching to replacing: .newItem kills the stock item: the app stays single-window and ⌘N belongs to New Post alone. Update the AGENTS.md contract, NewPostButton doc, and the kiosk ⌘W/⌘N key-swallow comments to match the new menu reality. --- Museion/AGENTS.md | 2 +- Museion/MuseionApp.swift | 14 ++++++++------ Museion/WritingLockState.swift | 5 +++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Museion/AGENTS.md b/Museion/AGENTS.md index ab660be..258984d 100644 --- a/Museion/AGENTS.md +++ b/Museion/AGENTS.md @@ -10,7 +10,7 @@ Owned by the root AGENTS.md contract. The `.xcodeproj` uses **filesystem-synchro ## Local Contracts -- Entry point: `MuseionApp.swift` (`WindowGroup` scene + `about` window; `AppGateState` holds app-scoped state; #151 gateless — `ContentView.task` fires `startLaunchCheck`, the async engine check + auto-fire chain). **#23:** no `@main` here — `MuseionLauncher` (MCPServer.swift) is the `@main` entry: `--serve-mcp` in argv runs the headless `museion-tools` MCP server (never touches AppKit), anything else runs `MuseionApp.main()`. One binary, two roles (ADR-0008). **#22:** File ▸ Open… (⌘O) + Import… (⇧⌘O) via `CommandGroup(after: .newItem)` — `OpenExternalButton` / `ImportFilesButton` over one shared `pickMarkdown` NSOpenPanel helper (.md/.markdown via `PostStore.openableTypes`); never `CommandMenu("File")` (#84 trap). `FocusModeToggle` arms for the external guest too. **#162 (Cold Turkey S2):** `WritingLockAppDelegate` rides `@NSApplicationDelegateAdaptor` (quit refused while a block holds); the View group gains Start Cold Turkey… (focus-gated, disabled on outline/no piece — the #160 second path behind the dot) and the lock refusals — Toggle Focus Mode, Toggle Reading Mode, and every File entry that would swap the editor surface (New Post/Outline/Project, Open…, Import…) disable while locked; ⌘W is swallowed by the kiosk's key monitor (WritingLockState.swift). **#108:** the same group leads with New Post ⌘N (`NewPostButton`, the library + button's draft path), New Outline ⇧⌘N (#109: `NewOutlineButton` → `PostsModel.newOutline()` — same draft path, outline type) and New Project… ⌥⌘N (`NewProjectButton` → `PostsModel.stageNewProject()`; WorkspaceView presents the `NewProjectSheet` — commands can't present sheets, the pendingImportURLs pattern: create succeeds → `newProjectPending` sets the draft's target project + opens the draft; failure keeps the sheet up with the reason inline; note ⌘N may be swallowed by the stock new-window item on some builds — the menu item always fires). +- Entry point: `MuseionApp.swift` (`WindowGroup` scene + `about` window; `AppGateState` holds app-scoped state; #151 gateless — `ContentView.task` fires `startLaunchCheck`, the async engine check + auto-fire chain). **#23:** no `@main` here — `MuseionLauncher` (MCPServer.swift) is the `@main` entry: `--serve-mcp` in argv runs the headless `museion-tools` MCP server (never touches AppKit), anything else runs `MuseionApp.main()`. One binary, two roles (ADR-0008). **#22:** File ▸ Open… (⌘O) + Import… (⇧⌘O) ride the same `CommandGroup(replacing: .newItem)` — `replacing` is load-bearing (single-window dogfood ruling 2026-11-05): with `after`, the stock File ▸ New Window item the WindowGroup owns kept its ⌘N and BOTH fired — a new window AND a new post; replacing kills the stock item, so ⌘N is New Post alone and a second Museion window cannot open from the menu. One shared `pickMarkdown` NSOpenPanel helper (.md/.markdown via `PostStore.openableTypes`); never `CommandMenu("File")` (#84 trap). `FocusModeToggle` arms for the external guest too. **#162 (Cold Turkey S2):** `WritingLockAppDelegate` rides `@NSApplicationDelegateAdaptor` (quit refused while a block holds); the View group gains Start Cold Turkey… (focus-gated, disabled on outline/no piece — the #160 second path behind the dot) and the lock refusals — Toggle Focus Mode, Toggle Reading Mode, and every File entry that would swap the editor surface (New Post/Outline/Project, Open…, Import…) disable while locked; ⌘W is swallowed by the kiosk's key monitor (WritingLockState.swift). **#108:** the same group leads with New Post ⌘N (`NewPostButton`, the library + button's draft path), New Outline ⇧⌘N (#109: `NewOutlineButton` → `PostsModel.newOutline()` — same draft path, outline type) and New Project… ⌥⌘N (`NewProjectButton` → `PostsModel.stageNewProject()`; WorkspaceView presents the `NewProjectSheet` — commands can't present sheets, the pendingImportURLs pattern: create succeeds → `newProjectPending` sets the draft's target project + opens the draft; failure keeps the sheet up with the reason inline; the stock New Window item is REPLACED — ⌘N is New Post alone, no second window). - `AppMetadata` is the single source for the displayed app name and tagline; members are `nonisolated` (default-MainActor project). - Swift language mode 6, `SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor`; deployment target 27.0 (bumped from 26.5 with the Xcode 27 settings pass — all six project configs, tests included, stay aligned or the test targets can't link the app module); bundle id `com.babylondreams.Museion`. - App Sandbox is OFF (ADR-0009) — the engine gate spawns the user-installed `hermes` binary and provisioning writes outside any container; hardened runtime stays ON for Developer ID notarization. No `.entitlements` file. diff --git a/Museion/MuseionApp.swift b/Museion/MuseionApp.swift index d2834aa..2d0e971 100644 --- a/Museion/MuseionApp.swift +++ b/Museion/MuseionApp.swift @@ -156,10 +156,12 @@ struct MuseionApp: App { CommandGroup(replacing: .appInfo) { OpenAboutButton() } - // #91/#94: File ▸ Open… (⌘O) and Import… (⇧⌘O) join the system - // File menu after New — never CommandMenu("File"), which doubles - // it (#84 trap). - CommandGroup(after: .newItem) { + // Single-window app: `replacing` kills the stock File ▸ New + // Window item the WindowGroup owns — with `after`, its ⌘N + // fired alongside New Post's (new window AND new post). + // #91/#94: Open…/Import… ride the group — never + // CommandMenu("File"), which doubles it (#84 trap). + CommandGroup(replacing: .newItem) { // #108/#109: New Post / New Outline / New Project… go FIRST in // the group — the menu reads New Post / New Outline / // New Project… / Open… / Import… @@ -252,8 +254,8 @@ private struct FocusModeToggle: View { } /// #108: File ▸ New Post (⌘N) — same draft path as the library's + button. -/// The stock new-window item may swallow or duplicate ⌘N in some macOS -/// builds; the action still fires from the menu either way. +/// The stock New Window item is REPLACED above — ⌘N belongs to this item +/// alone (single-window app; no second Museion window). private struct NewPostButton: View { let gate: AppGateState diff --git a/Museion/WritingLockState.swift b/Museion/WritingLockState.swift index 8fecedf..9291cf3 100644 --- a/Museion/WritingLockState.swift +++ b/Museion/WritingLockState.swift @@ -281,8 +281,9 @@ enum WritingLockKiosk { /// dependent — a Cyrillic ⌘W or a caps-on "W" slipped past while the /// stock Close still fired, wedging a windowless kiosk. 13 = /// kVK_ANSI_W (⌘W close), 3 = kVK_ANSI_F (⌃⌘F fullscreen), 45 = - /// kVK_ANSI_N (⌘N — the stock File ▸ New Window item SwiftUI owns - /// stays enabled mid-lock; a second window would strand the count). + /// kVK_ANSI_N (⌘N — New Post; the stock New Window item is replaced + /// and New Post disables mid-lock, the swallow keeps the kiosk + /// absolute regardless of menu state). nonisolated static func refusesKey(keyCode: UInt16, characters: String?, modifiers: NSEvent.ModifierFlags) -> Bool { let exact = modifiers.intersection([.command, .control, .option, .shift]) let key = characters?.lowercased()