refactor(settings): provider facts as data
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
#181: ModelProvider is the provider-descriptor table — label, effort ladder, flagship, endpoint, env var joined by wire dialect (chat/models paths + the SSE decoder selector), auth mode (Bearer vs Anthropic's header pair), keyless (nous rides the Portal login), and the ONE trailing-slash endpoint trim. The probe's URL builders, auth headers, and stream-decoder picks select by data; the per-dialect bodies and decoders stay separate functions, not switch clothing. ProviderCredential.resolve is the ONE credential rail (provider key, else the shared Portal session key for keyless providers — official endpoint ONLY, never a user-set URL). Settings' Test Connection and the new PassReadiness module both call it; the twice-implemented #175 fallback can no longer drift. One deliberate tightening, reviewer- blessed: a nous pass profile on a custom base_url with no pasted key now reads missingKey where the old session-model fallback said ready — the old copy had no endpoint gate at all. Pass readiness leaves the session model (PassReadiness.swift maps each pass surface to ready/missingKey/unknown over the descriptor; MentorSessionModel stores the verdicts and reads no keys or auth files). runPass and blindRead run their guards through one shared rail (guardOpenPieceRun) — identical refusal strings, blockers named honestly. No app-side model-settings store (ADR-0014 red line). Rider: the #179 mid-pass repoint pin polls the rig's hasHeldPrompt before releasing the held turn — runningPass flips before the one-shot engine parks its prompt, so firing into that window false-failed under parallel-suite load. Full suite 668/668 (xcresult executed count). Finish-audit: three reviewers (ponytail/security/general), zero findings above LOW; two ponytail trims and one pin tightening applied. Closes #181
This commit is contained in:
1 parent
218e2db397
commit
f49e4b6ca0
15 files changed
+506
-184
No files matched your search
@@ -282,13 +282,17 @@ final class MentorSessionModel {
|
||||
/// (firePendingScopeIfRequested); an in-flight transcript is never
|
||||
/// torn down mid-stream.
|
||||
private var pendingScopePieceTitle: String?
|
||||
/// #137: per-pass readiness (refreshPassReadiness, same-file #137
|
||||
/// extension) + the injectable read seam (tests). Stored in the class
|
||||
/// body — extensions carry no stored state.
|
||||
/// #137: per-pass readiness — refreshed at pane entry (re-entry
|
||||
/// re-fires the pane's .task — the key-added-in-Settings re-enable
|
||||
/// path). #181: computed in the PassReadiness module over the provider
|
||||
/// descriptor (the model reads no keys and no auth files); stored here
|
||||
/// because the pane observes it. `passReadinessWriter` is the
|
||||
/// injectable read seam (tests).
|
||||
private(set) var passReadiness: [PassKind: PassReadiness] = [:]
|
||||
var passReadinessWriter: (any SettingsWriting)?
|
||||
/// #175: the shared Portal auth store for the nous keyless readiness
|
||||
/// fallback — injectable so tests never read the machine's real login.
|
||||
/// #175: the shared Portal auth store — handed to the readiness
|
||||
/// module's credential resolution; injectable so tests never read the
|
||||
/// machine's real login.
|
||||
var portalAuthPath: String = PortalAuth.defaultAuthPath
|
||||
|
||||
/// The gate's winning binary path (no re-probe — map decision). Set by
|
||||
@@ -713,69 +717,26 @@ extension MentorSessionModel {
|
||||
host.isOneShotRunning
|
||||
}
|
||||
|
||||
/// #137 (S4): the Run Pass posture — is the pass profile's provider
|
||||
/// keyed? .unknown NEVER blocks (our own read failure — the spawn's
|
||||
/// honest failure row owns that path); .missingKey names the provider
|
||||
/// so the pane can say what's missing and link to Settings.
|
||||
enum PassReadiness: Equatable {
|
||||
case ready
|
||||
case missingKey(providerLabel: String)
|
||||
case unknown
|
||||
}
|
||||
|
||||
// Per-pass readiness (stored in the class body), refreshed at pane
|
||||
// entry (re-entry re-fires the pane's .task — the key-added-in-
|
||||
// Settings re-enable path). `passReadinessWriter` is the injectable
|
||||
// read seam; nil at refresh time → an ad-hoc HermesSettingsWriter
|
||||
// over the gate's binary (profileRoot default).
|
||||
// #137 (S4): the Run Pass posture — is the pass profile's provider
|
||||
// keyed? .unknown NEVER blocks (our own read failure — the spawn's
|
||||
// honest failure row owns that path); .missingKey names the provider
|
||||
// so the pane can say what's missing and link to Settings.
|
||||
// #181: the enum and the refresh live in the PassReadiness module.
|
||||
|
||||
func readiness(for kind: PassKind) -> PassReadiness {
|
||||
passReadiness[kind] ?? .unknown
|
||||
}
|
||||
|
||||
/// Read each pass profile's provider (readSurface, one task group),
|
||||
/// then each DISTINCT provider's key (readProviderKey). A surface we
|
||||
/// can't read maps .unknown; a non-empty key maps .ready; no key maps
|
||||
/// .missingKey with the provider's label. No binaryPath and no
|
||||
/// injected writer → readiness stays empty (.unknown everywhere).
|
||||
/// #181: thin delegate — the reads and the keyless fallback live in
|
||||
/// the PassReadiness module over the provider descriptor. No
|
||||
/// binaryPath and no injected writer → readiness stays empty
|
||||
/// (.unknown everywhere).
|
||||
func refreshPassReadiness() async {
|
||||
guard let writer = passReadinessWriter ?? binaryPath.map({ HermesSettingsWriter(hermesBinary: $0) }) else { return }
|
||||
var providers: [ProfileSurface: ModelProvider] = [:]
|
||||
await withTaskGroup(of: (ProfileSurface, (config: SurfaceModelConfig, baseURL: String?)?).self) { group in
|
||||
for surface in [ProfileSurface.pass1, .pass2] {
|
||||
group.addTask { await (surface, try? writer.readSurface(surface)) }
|
||||
}
|
||||
for await (surface, read) in group {
|
||||
providers[surface] = read?.config.provider
|
||||
}
|
||||
}
|
||||
var keys: [ModelProvider: String] = [:]
|
||||
for provider in Set(providers.values.compactMap(\.self)) {
|
||||
var key = await (try? writer.readProviderKey(provider: provider)) ?? ""
|
||||
// #175: nous runs on the shared Portal login — an empty `.env`
|
||||
// key is not a blocker when the session's agent_key exists (the
|
||||
// engine's own credential; API key and subscription bill the
|
||||
// same account credits).
|
||||
if provider == .nous, key.isEmpty {
|
||||
let path = portalAuthPath
|
||||
key = await Task.detached(priority: .utility) {
|
||||
PortalAuth.sessionKey(authJSONPath: path) ?? ""
|
||||
}.value
|
||||
}
|
||||
keys[provider] = key
|
||||
}
|
||||
for surface in [ProfileSurface.pass1, .pass2] {
|
||||
let kind: PassKind = surface == .pass1 ? .pass1 : .pass2
|
||||
guard let provider = providers[surface] else {
|
||||
passReadiness[kind] = .unknown
|
||||
continue
|
||||
}
|
||||
if let key = keys[provider], !key.isEmpty {
|
||||
passReadiness[kind] = .ready
|
||||
} else {
|
||||
passReadiness[kind] = .missingKey(providerLabel: provider.label)
|
||||
}
|
||||
}
|
||||
passReadiness = await PassReadiness.refresh(
|
||||
writer: writer,
|
||||
portalAuthPath: portalAuthPath,
|
||||
)
|
||||
}
|
||||
|
||||
/// Send a prompt and stream the reply into the ACTIVE session's
|
||||
|
||||
Reference in new issue
Block a user