feat(mentor): per-surface engine lifecycle (#137)
CI / ci (push) Canceled after 0s

Profiles S4: passes run on their OWN one-shot engines —
`hermes acp -p museion-passN` spawns per pass run and tears down at
the verdict, so a model switch costs nothing (the next spawn reads
fresh config). The verdict streams into a TRANSIENT unrostered
transcript (#129's ruling: one Sessions surface over the chat
engine; a rostered pass session would be unresumable by the chat
engine). `beginPassSession` died with it — passes never mint
sessions; the #28 roster pins flipped to the transient posture.

The chat engine stays resident (adopted museion profile): a Chat
model change in Settings fires onChatSurfaceWrite after a
successful chat-surface write only, wired to requestRestart —
re-spawn in place when idle (resuming the pre-restart active
session), deferred to turn end while any turn streams (#129).

Missing-key posture (#132): refreshPassReadiness reads both pass
profiles' providers and their .env keys at pane entry; Run Pass
disables naming the provider with an Open Settings link, .unknown
never blocks, and the guard refuses before anything touches disk.

Finish-audit (ponytail/security/general fanout) applied: the
general reviewer's Medium — a session/new/load/fork completing
mid-pass stole the active surface and lost the Cancel to the wrong
engine — fixed with ONE claimActive gate across the post-await
activation writers, pinned deterministically via the fake's
loadReplayHold park + a mode-file flip (flip-verified: guard off
fails on the steal observables and the misrouted-cancel hang).
Also fixed: a spawn-window cancel loss in stopStreaming (keyed on
the transient entry, not the late-arriving wire id), and a
PRE-EXISTING rescan bug where a stale scan snapshot "vanished" a
just-opened piece and killed its session, cancelling the edit
debounce — the vanish-kill now re-checks disk and the watched
home. Ponytail cut ~59 lines of test duplication; the app target's
only force-unwrap is gone.

Suite 477 (was 472): EngineLifecycleTests new (own-engine
end-to-end, held-pass cancel, idle + deferred restart ordering,
readiness, steal pin), +3 Settings hook pins, one duplicate pin
deduplicated. swiftformat clean, swiftlint at HEAD baseline.

Closes #137
This commit is contained in:
AlexKucera committed 2026-10-28 17:26:40 +01:00
1 parent a4ea914690
commit 1c697440d8
19 files changed
+1034 -162

No files matched your search

+61 -10
View File
@@ -21,6 +21,9 @@ struct MentorPaneView: View {
var posts: PostsModel?
/// #24 (S3.1): the Home passes run against.
var home: URL?
/// #137 (S4): opens Settings — the missing-key line's way out (nil =
/// previews; PostsPaneView threads WorkspaceView's pane hop).
var onOpenSettings: (() -> Void)?
/// #24 (S3.1): the segmented surface — Pass 1 | Pass 2 | Chat. Pass
/// modes carry the pass bar; Chat is the freeform surface alone.
private enum Mode: Hashable { case pass1, pass2, chat }
@@ -30,11 +33,18 @@ struct MentorPaneView: View {
/// either way (debug history intact; the toggle flips instantly).
@AppStorage("mentorDebugRows") private var debugRows = false
init(model: MentorSessionModel, binaryPath: String?, posts: PostsModel? = nil, home: URL? = nil) {
init(
model: MentorSessionModel,
binaryPath: String?,
posts: PostsModel? = nil,
home: URL? = nil,
onOpenSettings: (() -> Void)? = nil,
) {
_model = State(initialValue: model)
self.binaryPath = binaryPath
self.posts = posts
self.home = home
self.onOpenSettings = onOpenSettings
}
var body: some View {
@@ -48,7 +58,7 @@ struct MentorPaneView: View {
case .ready:
modePicker
if let kind = passKind {
PassBarView(kind: kind, posts: posts, home: home, model: model)
PassBarView(kind: kind, posts: posts, home: home, model: model, onOpenSettings: onOpenSettings)
Divider()
}
if let posts, !posts.openPieceCards.isEmpty {
@@ -85,6 +95,10 @@ struct MentorPaneView: View {
if let binaryPath {
model.binaryPath = binaryPath
}
// #137: the Run Pass posture over the pass profiles' keys —
// a no-op without a binaryPath; pane re-entry re-fires this
// task, so a key added in Settings re-enables Run Pass.
await model.refreshPassReadiness()
// Hosted unit tests run this app as their runner — never spawn a
// real engine child there (it outlives the test session and kills
// the runner).
@@ -113,7 +127,9 @@ struct MentorPaneView: View {
.help(note)
}
Spacer()
if case .ready = model.phase, let sessionId = model.activeEntry?.sessionId {
// #137: the transient pass transcript carries no session id — the
// chip stays hidden while a pass run owns the active surface.
if case .ready = model.phase, let sessionId = model.activeEntry?.sessionId, sessionId != MentorSessionModel.passTranscriptKey {
Text("session \(sessionId.prefix(8))")
.font(.caption2)
.foregroundStyle(.tertiary)
@@ -210,6 +226,8 @@ private struct PassBarView: View {
let posts: PostsModel?
let home: URL?
let model: MentorSessionModel
/// #137 (S4): the missing-key line's way out — WorkspaceView's pane hop.
let onOpenSettings: (() -> Void)?
var body: some View {
VStack(alignment: .leading, spacing: 8) {
@@ -224,11 +242,34 @@ private struct PassBarView: View {
Spacer()
actions
}
// #137: the pass profile's provider has no key — name it and
// offer the way out. A readable-but-keyed profile shows nothing.
if let label = missingKeyLabel {
HStack(spacing: 4) {
Text("Missing \(label) key —")
Button("Open Settings") {
onOpenSettings?()
}
.buttonStyle(.borderless)
.foregroundStyle(DesignTokens.accent)
}
.font(.system(size: 11, design: DesignTokens.mono))
.foregroundStyle(DesignTokens.muted)
}
}
.padding(.horizontal, 12)
.padding(.bottom, 10)
}
/// #137: nil unless the pass profile's provider is readable AND unkeyed
/// (.unknown never blocks — the spawn's honest failure owns that path).
private var missingKeyLabel: String? {
if case let .missingKey(label) = model.readiness(for: kind) {
return label
}
return nil
}
/// What the pass does + the predictable cost — or the honest ask when
/// no piece is open.
private var description: String {
@@ -248,7 +289,8 @@ private struct PassBarView: View {
}
/// Cancel while a pass runs; Run otherwise — disabled with no open
/// piece or while the engine can't take the turn.
/// piece, while the engine can't take the turn, or (#137) while the
/// pass profile's provider has no key (the help names it).
@ViewBuilder
private var actions: some View {
if posts?.runningPass != nil {
@@ -256,15 +298,24 @@ private struct PassBarView: View {
posts?.cancelPass(mentor: model)
}
.buttonStyle(.bordered)
} else if let label = missingKeyLabel {
runPassButton
.disabled(true)
.help("\(kind.rawValue) needs a \(label) API key — add it in Settings → Provider Keys.")
} else {
Button("Run \(kind.rawValue)") {
guard let posts, let home else { return }
Task { await posts.runPass(kind, home: home, mentor: model) }
}
.buttonStyle(.borderedProminent)
.disabled(posts?.session?.postID == nil || !model.phase.isReady || model.isStreaming)
runPassButton
.disabled(posts?.session?.postID == nil || !model.phase.isReady || model.isStreaming)
}
}
/// The Run button core — shared by the ready and missing-key branches.
private var runPassButton: some View {
Button("Run \(kind.rawValue)") {
guard let posts, let home else { return }
Task { await posts.runPass(kind, home: home, mentor: model) }
}
.buttonStyle(.borderedProminent)
}
}
#Preview {