CI / ci (push) Canceled after 0s
Spawn hermes acp -p museion over NDJSON JSON-RPC stdio via a hand-rolled thin client (no Swift SDK exists). The mentor debug pane streams replies, renders fix-card tool calls as structured cards (ADR-0006), cancels via session/cancel, tears down on quit (willTerminate), and surfaces a restart prompt on engine crash — never data loss. Version verify against state.json is advisory. Fake ACP server test double (zsh speaking real NDJSON) covers handshake, streaming + fix-card, drift, crash latch, cancel, teardown. 36/36 tests green; finish-audit fixes included (wired binaryPath, focus-loss teardown bug, double onCrash latch). Co-Authored-By: Claude <noreply@anthropic.com>
8.9 KiB
8.9 KiB
Museion (app target)
Purpose
The Museion application target: the native SwiftUI macOS app shell of the Agentic Writing Environment. Everything user-visible lives here.
Ownership
Owned by the root AGENTS.md contract. The .xcodeproj uses filesystem-synchronized groups — files on disk are the truth; add/move/delete sources here and Xcode follows. Never hand-edit project.pbxproj beyond plain build-setting values and the one sanctioned exception: the ref/writing skills folder reference into the Resources phase (#46 map decision — a folder reference can't be expressed through fs-sync groups).
Local Contracts
- Entry point:
MuseionApp.swift(@main,WindowGroupscene +aboutwindow;AppGateStateholds app-scoped gate state). AppMetadatais the single source for the displayed app name and tagline; members arenonisolated(default-MainActor project).- Swift language mode 6,
SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor; deployment target 26.5; bundle idcom.babylondreams.Museion. - App Sandbox is OFF (ADR-0009) — the engine gate spawns the user-installed
hermesbinary and provisioning writes outside any container; hardened runtime stays ON for Developer ID notarization. No.entitlementsfile. - No persistence layer yet — the SwiftData template was stripped; vault-vs-database gets an ADR when the need is real. Exception: the engine gate's
state.json(see below). - Tabs for indentation; SwiftFormat + SwiftLint must both stay clean.
Engine gate (launch gate, tickets #35–#41)
EngineGate.swift—EngineProbe(nonisolated): six-path probe order,acp --checkhealth (stdin closed, 5 s timeout, exit-status branching),acp --versionversion,state.jsonwriter/reader.EngineGateModel(@MainActor @Observable): phases for the UI,onPassseam (fires provisioning, #47),currentBinaryPathhanded to provisioning.execute(_:timeout:)/ProcessOutputare internal — shared child-process machinery.EngineGateView.swift— blocking sheet card: checking / pass (version + Start Writing) / fail (two install steps per #40, Re-check, Technical details disclosure).interactiveDismissDisabled; sheet never closes itself.state.jsonlives at~/Library/Application Support/Museion/— schemaVersion 1, wholesale-replaced after every completed check; fail records carry noengineVersion. Gate renders in-memory; About (AboutEngineViewinMuseionApp.swift) reads the file and never triggers a check.- Gate is app-scoped via
AppGateState(first window per app-launch only, ticket #41);EngineGateView.onEnginePassfires provisioning (#47) in parallel on pass. - Tests:
MuseionTests/EngineGateTests.swiftbuilds fakehermesshell scripts and exercises the real Process path — probe order, first-stderr reporting, timeout kill, state records.
Profile provisioning (S2.1, tickets #43–#48)
ProfileProvisioner.swift—ProfileProvisioner(nonisolated): one idempotent pass per gate pass. Create phase: dir-check first, spawnhermes profile create museion --no-alias --no-skillsonly when missing; exit 1 + "already exists" on stdout = success (#43); errors read from stdout; a nil binary path fails the create phase cleanly (no probe fallback — the gate's winner is always handed in). Seed phase:seed-manifest.txtin the payload root is the inclusion list (blank/#lines ignored; entries validated kebab-case at the trust boundary — a traversal-shaped entry fails the copy phase instead of escapingskills/); per-skill dir-check, copy to temp name + rename (atomic), never open or overwrite present skills; orphaned.-prefixed temp dirs from an interrupted copy are swept at pass start;.DS_Storepurged from copies. One os_log line per pass (seeded writing skills: <name> <version>, … (N copied, M present)) reading shipped versions from the bundled payload only; at most one os_log line per failure (phase + excerpt, #48).ProvisioningModel(@MainActor @Observable): runs the pass off-main, guards stacking, recordslastFailure(phase-named copy + excerpt); failure never re-raises the gate.- Provisioning failure UX (#48):
ProvisioningFailureCard(inEngineGateView.swift) — separate sheet from the gate, presented only after the gate sheet has fully dismissed (ContentView.failurePresented=hasFailure && gateDismissed, wheregateDismissedis set in the gate sheet'sonDismiss— keying on dismissal completion avoids macOS dropping a sheet presented during another's dismissal animation); phase rawValue is the title, excerpt behind Technical details; the card snapshots the failure into@Stateso a successful Retry doesn't blank it mid-dismiss. Retry re-runs the whole pass (idempotent), Not Now (deferFailure) defers to the next launch's silent retry; sheet is interactiveDismissDisabled. Provisioning writes nothing to the profile config — never anmcp_serversentry (#44 negative invariant, test-pinned). - Payload:
ref/writing skills/ships as a folder reference → plainResources/writing skills/directory (no zip, no compiled manifest). 11 mentor skills seeded;ste-writing/writing-for-agentsship but never seed. - Tests:
MuseionTests/ProfileProvisionerTests.swift— fake-binary Process harness (fake creates profile at<binaryDir>/profiles/<name>), injected profile/payload dirs, manifest ↔ payload correspondence against the bundled payload.
ACP bridge (S2.2, #14 map)
ACPEngineClient.swift—ACPEngineClient(nonisolated, @unchecked Sendable): hand-rolled thin NDJSON JSON-RPC stdio client forhermes acp -p museion(ponytail: no Swift SDK exists; revisit if one appears). Wire facts baked in (verified adapter 0.20.6 + acp SDK): one JSON message per\nline, stdout = wire, stderr = logs (never parsed for state);session/cancelis a notification (no response); responses camelCase; updates discriminate onupdate.sessionUpdate.JSONValue(nonisolated enum) is the decoded-wire value type. Serial queue confines all mutable state; requests time out (15 s default) — a hung engine surfaces as an error → restart prompt, never an eternal await; server→client requests get an auto-32601(M0 handles none — the deny option); crash/EOF fail pending requests and fireonCrashexactly once (latched — child-exit and stdout-EOF both arrive for one crash; never on explicitclose());close()= handlers-off → SIGTERM → 1 s grace → SIGKILL → reap (EngineProbe pattern); SIGPIPE ignored.MentorSessionModel.swift—MentorSessionModel(@MainActor @Observable): pane state machine (idle/starting/ready/crashed;isStreamingBool). Lazy lifecycle: spawns on firstopenSession()(skipped under hosted tests viaXCTestConfigurationFilePath), handshakeinitialize→ advisory version compare vs state.json (recordedVersionProviderinjectable; one os_log line + both versions in the pane, never blocks) →session/newcwd~.sendPromptstreamsagent_message_chunk/thoughtinto a buffer flushed on turn end; tool calls with fix-card-shapedrawInput(pattern+problem minimum) render asFixCard(ADR-0006 fields); every other update type a collapsible raw-JSON row. Cancel =session/cancelnotification, Stop button. Crash keeps transcript + last prompt; Restart re-spawns.clientRefmirror exists solely so nonisolated deinit can close the child.MentorPaneView.swift— the debug pane, post-gate main surface (replaces the content placeholder): header (running version + orange drift note), transcript (text rows, FixCardRow cards, RawUpdateRow disclosure), freeform input 1…4 lines + send + Stop while streaming, crash card (Restart, last prompt, stderr tail behind Technical details).- Wiring:
AppGateState.mentoris the app-scoped model ( ContentView rendersMentorPaneView(model:binaryPath:)oncegateModel.currentBinaryPathexists, handing the gate's winner tomentor.binaryPath— no re-probe); quit teardown onNSApplication.willTerminateNotification→mentor.shutdown()(idempotent; scenePhase.inactivewould fire on plain focus loss). - Tests:
MuseionTests/ACPClientTests.swift— fake ACP server (zsh speaking real NDJSON over the real Process path; mode file + base64 card payload beside the binary, self-locating per ProfileProvisionerTests convention). Covers handshake version, streamed updates + fix-card parse (model over the real client+fake path), advisory drift note, crash → onCrash exactly once, cancel fire-and-forget, teardown kills hung child.
Work Guidance
- Native SwiftUI only — no web-editor embedding, no Electron-style components (ADR-0001).
- Text editing gets built on TextKit 2 / SwiftUI directly; no CodeMirror/ProseMirror-class dependencies.
Verification
xcodebuild -project Museion.xcodeproj -scheme Museion -destination 'platform=macOS' buildxcodebuild -project Museion.xcodeproj -scheme Museion -destination 'platform=macOS' test
Child DOX Index
- None yet — add child docs when subdirectories with distinct responsibilities appear (e.g. editor, library, agent integration).