feat(profiles): registry + provisioning ×3
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
Profiles S1 (#134, ADR-0014): one gate pass provisions all three surface profiles — museion adopted in place (never reconfigured; its glm-5.3-max stays the user's), museion-pass1/-pass2 created fresh with the #132 sonnet defaults + 24k budget via the hermes 'config set' CLI rail, marker-gated so a re-pass is a no-op and Settings changes survive; a failed provision names the profile on the #48 card. Skills move to ONE master copy under Application Support, symlinked per profile per the #133 allocation (P1 9 · P2 8 · Chat 10); copy-era dirs migrate on byte-match (.DS_Store-tolerant, symlink-refusing), diverged dirs stay copies, user skills untouched (G3a). Backup widens to one three-subdir stamp, any-live-skip-all; RESTORE.md names the three folders. Two review rounds (standards+spec, then finish-audit ponytail/ security/general) caught and fixed: the dead .DS_Store leniency in treesByteMatch, exit-code-only config-set trust, the swallowed marker write (defaults-stomp re-arm), symlink-following in the untrusted tree, and a fixture-skewed count pin. Suite: 412 passed / 414 (fork flake green in isolation 16/16; UI launch = pre-existing testmanagerd flake, failed identically pre-change). DOX: Museion/AGENTS.md, MuseionTests/AGENTS.md, ref/writing skills/AGENTS.md rewritten. Closes #134
This commit is contained in:
1 parent
2032534305
commit
610f8789bd
15 files changed
+1292
-232
No files matched your search
+45
-20
@@ -4,6 +4,10 @@
|
||||
//
|
||||
// S2.6 daily profile backup (#50): liveness-gated, once-a-day FileManager
|
||||
// copy of the museion profile into timestamped snapshots, last 7 kept.
|
||||
// #134 (Profiles S1, #129): one stamp carries all three surface profiles
|
||||
// as subdirs — museion, museion-pass1, museion-pass2. Any live engine
|
||||
// skips the WHOLE stamp; never the profiles root (non-Museion profiles
|
||||
// are not ours to back up).
|
||||
//
|
||||
|
||||
import Foundation
|
||||
@@ -43,8 +47,12 @@ nonisolated enum ProfileBackup {
|
||||
case failed
|
||||
}
|
||||
|
||||
/// One backup pass. Runs on gate pass, sequenced after the provisioning
|
||||
/// pass finishes (success or failure — a failed provision doesn't skip it).
|
||||
/// One backup pass over the three surface profiles (#129/#134): one
|
||||
/// stamp, three subdirs. Runs on gate pass, sequenced after the
|
||||
/// provisioning pass finishes (success or failure — a failed provision
|
||||
/// doesn't skip it). A profile dir that doesn't exist (provisioning
|
||||
/// 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`).
|
||||
/// - backupsRoot: snapshots base dir (tests inject; default Museion's
|
||||
@@ -57,12 +65,19 @@ nonisolated enum ProfileBackup {
|
||||
psScan: () -> Bool = psContainsMuseion,
|
||||
) -> Outcome {
|
||||
let fileManager = FileManager.default
|
||||
let source = (profileRoot as NSString).appendingPathComponent("museion")
|
||||
guard fileManager.fileExists(atPath: source) else {
|
||||
logInfo("skipped — museion profile missing")
|
||||
let sources = ProfileSurface.allCases
|
||||
.map { (profileRoot as NSString).appendingPathComponent($0.profileName) }
|
||||
.filter { fileManager.fileExists(atPath: $0) }
|
||||
guard !sources.isEmpty else {
|
||||
logInfo("skipped — no profile found")
|
||||
return .skippedProfileMissing
|
||||
}
|
||||
guard engineIdle(profileDir: source, psScan: psScan) else {
|
||||
// Any-live-skip-all (#129): one stamp = one consistent point in time.
|
||||
// The ps scan already substring-matches the pass profiles
|
||||
// (`profiles/museion` / `-p museion`), so ONE scan answers for all
|
||||
// (finish-audit: hoisted — per-dir evaluation spawned it up to 3×);
|
||||
// the pid check stays per dir.
|
||||
guard !psScan(), sources.allSatisfy({ idleProfileDir($0) }) else {
|
||||
logInfo("skipped — engine running (liveness gate)")
|
||||
return .skippedEngineRunning
|
||||
}
|
||||
@@ -82,15 +97,18 @@ nonisolated enum ProfileBackup {
|
||||
try fileManager.createDirectory(atPath: backupsRoot, withIntermediateDirectories: true)
|
||||
writeRestoreDocIfMissing(into: backupsRoot)
|
||||
try fileManager.createDirectory(atPath: tempDir, withIntermediateDirectories: true)
|
||||
// Snapshot layout: <stamp>/museion/<profile contents> — the folder
|
||||
// name travels with the snapshot, so restore is one copy-back.
|
||||
let payloadDir = (tempDir as NSString).appendingPathComponent("museion")
|
||||
try fileManager.createDirectory(atPath: payloadDir, withIntermediateDirectories: true)
|
||||
try copyTree(from: source, to: payloadDir)
|
||||
// Snapshot layout (#129): <stamp>/{museion, museion-pass1,
|
||||
// museion-pass2}/<profile contents> — the folder name travels with
|
||||
// the snapshot, so restore is one copy-back.
|
||||
for source in sources {
|
||||
let payloadDir = (tempDir as NSString).appendingPathComponent((source as NSString).lastPathComponent)
|
||||
try fileManager.createDirectory(atPath: payloadDir, withIntermediateDirectories: true)
|
||||
try copyTree(from: source, to: payloadDir)
|
||||
}
|
||||
// Atomic install (seed-phase pattern): rename into place, then prune.
|
||||
try fileManager.moveItem(atPath: tempDir, toPath: finalDir)
|
||||
prune(backupsRoot: backupsRoot)
|
||||
logInfo("snapshot complete: \(stamp)")
|
||||
logInfo("snapshot complete: \(stamp) (\(sources.count) profiles)")
|
||||
return .snapshotted(stamp: stamp)
|
||||
} catch {
|
||||
try? fileManager.removeItem(atPath: tempDir)
|
||||
@@ -112,19 +130,19 @@ nonisolated enum ProfileBackup {
|
||||
let path = (backupsRoot as NSString).appendingPathComponent("RESTORE.md")
|
||||
guard !FileManager.default.fileExists(atPath: path) else { return }
|
||||
let doc = """
|
||||
# Restoring the writing profile
|
||||
# Restoring the writing profiles
|
||||
|
||||
Each folder here is a full snapshot of the writing profile \
|
||||
(`~/.hermes/profiles/museion`), taken once a day when Museion launches.\
|
||||
The 7 most recent are kept.
|
||||
Each folder here is a full snapshot of Museion's writing profiles \
|
||||
(`~/.hermes/profiles/museion`, `museion-pass1`, and `museion-pass2`),\
|
||||
taken once a day when Museion launches. The 7 most recent are kept.
|
||||
|
||||
## Restore (manual, v1)
|
||||
|
||||
1. Quit Museion (and any running Hermes engine).
|
||||
2. Pick the newest healthy snapshot folder.
|
||||
3. Copy the `museion` folder inside it back to `~/.hermes/profiles/`,\
|
||||
replacing the damaged one (rename the old one aside first if you want\
|
||||
it kept).
|
||||
3. Copy the profile folders inside it back to `~/.hermes/profiles/`,\
|
||||
replacing the damaged ones (rename the old ones aside first if you\
|
||||
want them kept).
|
||||
4. Relaunch Museion.
|
||||
|
||||
Note: logs, caches, and lock files are excluded from snapshots by\
|
||||
@@ -149,11 +167,18 @@ nonisolated enum ProfileBackup {
|
||||
/// the file can be stale) + `ps ax -o command=` scan for `profiles/museion`
|
||||
/// or `-p museion`. Either signal live → the engine is running.
|
||||
static func engineIdle(profileDir: String, psScan: () -> Bool = psContainsMuseion) -> Bool {
|
||||
idleProfileDir(profileDir) && !psScan()
|
||||
}
|
||||
|
||||
/// The per-dir half of the liveness gate: gateway.pid liveness only —
|
||||
/// 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")
|
||||
if let pid = parsePID(fromFile: pidPath), kill(pid, 0) == 0 {
|
||||
return false
|
||||
}
|
||||
return !psScan()
|
||||
return true
|
||||
}
|
||||
|
||||
/// The gateway's pid file is a JSON line (`{"pid":…, "hermes_home":"…"}` —
|
||||
|
||||
Reference in new issue
Block a user