feat(settings): sidebar + detail Settings page (#135)
CI / ci (push) Canceled after 0s

Profiles S2 over the variant C verdict (#130): Settings becomes a
sidebar + detail shell — Content (the #17 Home control, unchanged) ·
Pass 1 · Pass 2 · Chat ('· Sessions' rides it) · Provider Keys. Each
surface page edits its model block in memory: provider menu, an
NSComboBox sourcing hermes' registry cache with first-class free text
(the #132 seed claude-sonnet-5-5 is NOT in the cache — custom is the
default state, pinned), per-provider effort menus led by
'unset · provider default' (zai low/high/max; OpenAI + Anthropic the
five-rung ladder), variant B's current-model headline, and a
user-requested Restore Defaults back to the seed. Provider Keys carries
endpoint, the z.ai key-type toggle swapping the endpoint family
(paas/v4 ↔ coding/paas/v4 — a custom endpoint survives), and masked
keys with reveal; no Keychain (#131).

Persistence is S3's job: every change routes through an injectable
SettingsWriting seam whose implementer contract is frozen now (MUST
debounce — the key field fires per keystroke; secrets via stdin/env,
never argv; error text redacted before it renders). Write failures
surface in an orange strip, cleared by the next success.

Dogfood fix, log-observed via os_log probes on the live app:
comboBoxSelectionDidChange fires BEFORE stringValue updates — the pick
is read from objectValueOfSelectedItem and the box re-synced by hand,
or the model never learns a dropdown pick. Two blind fixes failed
before the probe round settled it; pinned against the stale-string
fixture and filed to the swift wiki.

Finish-audit fanout (ponytail/security/general): Ship/SHIP/APPROVE —
applied the SettingsWriting contract, an inlined one-caller wrapper,
a corrected registry-leniency comment, and a seed-provider pin;
declined deleting the hydration clamp (trust-boundary validation for
S3's config.yaml reads); deferred endpoint scheme validation to S3's
write boundary. Suite: 432 passed / 432 (xcresult-verified). DOX:
Museion/AGENTS.md, MuseionTests/AGENTS.md, CHANGELOG, session log.

Closes #135
This commit is contained in:
AlexKucera committed 2026-10-27 11:52:39 +01:00
1 parent 610f8789bd
commit 42a27cc8a3
12 files changed
+1315 -32

No files matched your search

+105
View File
@@ -0,0 +1,105 @@
//
// ModelComboBox.swift
// Museion
//
// #135 (Profiles S2): the model picker as a proper macOS combobox — free
// text is first-class (the #132 seed claude-sonnet-5-5 isn't in the
// registry), the registry list rides the dropdown + autocompletion. The
// prototype #130's Custom… ↩ two-state dance collapsed into this one
// control.
//
import AppKit
import SwiftUI
struct ModelComboBox: NSViewRepresentable {
/// The committed model id (the model's truth; the box echoes it).
var value: String
/// The provider's registry list — dropdown + completion source.
var items: [String]
/// Commit: Enter, blur (end editing), or a list pick.
var onCommit: (String) -> Void
func makeCoordinator() -> Coordinator {
Coordinator(onCommit: onCommit)
}
func makeNSView(context: Context) -> NSComboBox {
let box = NSComboBox()
box.usesDataSource = false
box.completes = true
box.numberOfVisibleItems = 12
box.font = .monospacedSystemFont(ofSize: 11.5, weight: .regular)
box.stringValue = value
box.delegate = context.coordinator
box.target = context.coordinator
box.action = #selector(Coordinator.picked(_:))
box.setAccessibilityLabel("Model")
context.coordinator.syncItems(box, items: items)
context.coordinator.lastLocalValue = value
return box
}
func updateNSView(_ box: NSComboBox, context: Context) {
context.coordinator.onCommit = onCommit
context.coordinator.syncItems(box, items: items)
// Echo guard, OutlineRowTextView pattern: our own commits round-trip
// byte-equal through the model, so only adopt when the model's value
// differs from what this box last emitted — a provider switch. Never
// clobber in-flight editing; commits arrive via the delegate.
if value != context.coordinator.lastLocalValue, box.currentEditor() == nil {
box.stringValue = value
context.coordinator.lastLocalValue = value
}
}
@MainActor
final class Coordinator: NSObject, NSComboBoxDelegate {
var onCommit: (String) -> Void
var lastLocalValue = ""
init(onCommit: @escaping (String) -> Void) {
self.onCommit = onCommit
}
/// Only rebuild the item list when it actually changed — an unrelated
/// state tick (effort menu, reveal toggle) must not close an open
/// dropdown.
func syncItems(_ box: NSComboBox, items: [String]) {
guard (box.objectValues as? [String]) != items else { return }
box.removeAllItems()
box.addItems(withObjectValues: items)
}
private func commit(_ box: NSComboBox, value: String? = nil) {
let trimmed = (value ?? box.stringValue).trimmingCharacters(in: .whitespacesAndNewlines)
guard !trimmed.isEmpty, trimmed != lastLocalValue else { return }
lastLocalValue = trimmed
onCommit(trimmed)
}
/// Return (NSComboBox's action).
@objc func picked(_ sender: NSComboBox) {
commit(sender)
}
/// A list pick (#135 dogfood, log-observed): the notification fires
/// BEFORE stringValue updates — the picked item must come from the
/// selection index; reading stringValue here commits the STALE value
/// and the model never learns the pick. The box is re-synced by hand
/// because this no-field-editor path never produces a follow-up event.
func comboBoxSelectionDidChange(_ notification: Notification) {
guard let box = notification.object as? NSComboBox else { return }
// nil when nothing is selected (indexOfSelectedItem < 0).
guard let picked = box.objectValueOfSelectedItem as? String else { return }
commit(box, value: picked)
box.stringValue = picked
}
/// Blur / Enter through the field editor.
func controlTextDidEndEditing(_ obj: Notification) {
guard let box = obj.object as? NSComboBox else { return }
commit(box)
}
}
}