Files
museion/Museion/ProfileLayout.swift
T
AlexKucera a8b158ca26
CI / ci (push) Canceled after 0s
refactor(profiles): one layout + config-set rail
#182: ProfileLayout owns the profile root default and every per-profile
path (dir, .env, configured marker, gateway pid, skills dir) — the five
scattered profile-root literals are gone; the provisioner, the settings
writer, and backup/restore derive paths only through it, pinned once in
ProfileLayoutTests. RESTORE.md prose and the ps-scan grep keep their
literal text deliberately (doc text and argv matching, not paths).

HermesConfigRail owns the config set/unset contract once: argv shape
(+--force), provider-first hoisting (switching providers clears a stale
inherited base_url — a caller can no longer order it wrong), ✓-line
verification, unset-idempotence. The provisioner seeds provider/default/
max_tokens; the writer edits provider/default/effort/base_url — each
keeps its own key list, only the mechanism and ordering rule unify. The
rail's Failure carries key/profile/excerpt for both error surfaces.

Audit hardenings folded in: a leading-dash value refuses before any
spawn (free-text model/endpoint fields cannot reach the child CLI as
options), whitespace-only endpoints read as empty at both writer gates,
the deliberate 500-char excerpt cap is pinned not just commented, and
the failed-unset branch is pinned (the fake hermes grew a
config-unset-fails knob).

Full suite 684 passed / 0 failed; dash + whitespace pins flip-verified.

Closes #182
2026-11-10 11:32:47 +01:00

49 lines
1.9 KiB
Swift

//
// ProfileLayout.swift
// Museion
//
// #182: the ONE owner of the Hermes profile layout — the root default and
// every per-profile path derivation. The provisioner, the settings writer,
// and backup/restore build paths only through here; no literal
// profile-root string lives outside this module (pinned in
// ProfileLayoutTests — a layout change is this module + that one suite).
//
// Deliberately NOT layout-owned: the RESTORE.md copy names
// `~/.hermes/profiles` as prose (static text that must outlive the app),
// and the backup ps scan greps argv text, not filesystem paths.
//
import Foundation
nonisolated enum ProfileLayout {
/// The profiles base dir (`~/.hermes/profiles`; tests inject their own root).
static let defaultRoot = ("~/.hermes/profiles" as NSString).expandingTildeInPath
/// `<root>/<profileName>` — the profile's home dir.
static func profileDir(_ profile: String, root: String) -> String {
(root as NSString).appendingPathComponent(profile)
}
/// The profile's `.env` — provider keys (the writer's fan-out surface).
static func envFile(in profileDir: String) -> String {
(profileDir as NSString).appendingPathComponent(".env")
}
/// The configured marker — written by the provisioner after the config
/// rail completes; marker-gating keeps a re-pass from stomping a user's
/// later Settings change.
static func configuredMarker(in profileDir: String) -> String {
(profileDir as NSString).appendingPathComponent(".museion-provisioned")
}
/// The engine gateway's pid file (the backup liveness gate reads it).
static func gatewayPID(in profileDir: String) -> String {
(profileDir as NSString).appendingPathComponent("gateway.pid")
}
/// The profile's skills dir — the symlink farm into the ONE master copy.
static func skillsDir(in profileDir: String) -> String {
(profileDir as NSString).appendingPathComponent("skills")
}
}