refactor(profiles): one layout + config-set rail
CI / ci (push) Canceled after 0s

#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
This commit is contained in:
AlexKucera committed 2026-11-10 11:32:47 +01:00
1 parent f49e4b6ca0
commit a8b158ca26
14 files changed
+484 -113

No files matched your search

+5 -5
View File
@@ -54,19 +54,19 @@ nonisolated enum ProfileBackup {
/// hasn't landed yet) is simply absent from the stamp; only NO profile
/// at all skips.
/// - Parameters:
/// - profileRoot: profiles base dir (tests inject; default `~/.hermes/profiles`).
/// - profileRoot: profiles base dir (tests inject; default the layout's root).
/// - backupsRoot: snapshots base dir (tests inject; default Museion's
/// Application Support / Backups).
/// - now: clock injection for the age check (tests pass fixed dates).
static func perform(
profileRoot: String = ("~/.hermes/profiles" as NSString).expandingTildeInPath,
profileRoot: String = ProfileLayout.defaultRoot,
backupsRoot: String = defaultBackupsRoot(),
now: Date = Date(),
psScan: () -> Bool = psContainsMuseion,
) -> Outcome {
let fileManager = FileManager.default
let sources = ProfileSurface.allCases
.map { (profileRoot as NSString).appendingPathComponent($0.profileName) }
.map { ProfileLayout.profileDir($0.profileName, root: profileRoot) }
.filter { fileManager.fileExists(atPath: $0) }
guard !sources.isEmpty else {
logInfo("skipped — no profile found")
@@ -174,7 +174,7 @@ nonisolated enum ProfileBackup {
/// the ps scan is global (one scan answers for every surface profile),
/// so the caller evaluates it once.
private static func idleProfileDir(_ profileDir: String) -> Bool {
let pidPath = (profileDir as NSString).appendingPathComponent("gateway.pid")
let pidPath = ProfileLayout.gatewayPID(in: profileDir)
if let pid = parsePID(fromFile: pidPath), kill(pid, 0) == 0 {
return false
}
@@ -311,7 +311,7 @@ final class BackupModel {
guard !running else { return }
running = true
defer { running = false }
let profileRoot = profileRoot ?? ("~/.hermes/profiles" as NSString).expandingTildeInPath
let profileRoot = profileRoot ?? ProfileLayout.defaultRoot
let backupsRoot = backupsRoot ?? ProfileBackup.defaultBackupsRoot()
lastOutcome = await Task.detached(priority: .utility) {
ProfileBackup.perform(profileRoot: profileRoot, backupsRoot: backupsRoot)