mirror of
https://github.com/awizemann/scarf.git
synced 2026-05-10 18:44:45 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0f78856e6e | |||
| 5877bf6519 | |||
| f19f19cd56 |
@@ -311,6 +311,14 @@ public actor ACPClient {
|
|||||||
let result = try await sendRequest(method: "session/prompt", params: params)
|
let result = try await sendRequest(method: "session/prompt", params: params)
|
||||||
let dict = result?.dictValue ?? [:]
|
let dict = result?.dictValue ?? [:]
|
||||||
let usage = dict["usage"] as? [String: Any] ?? [:]
|
let usage = dict["usage"] as? [String: Any] ?? [:]
|
||||||
|
// TODO(WS-8-Q1): Confirm wire field name once v0.13 Hermes is
|
||||||
|
// available. We tolerate camelCase + snake_case to match the rest
|
||||||
|
// of the ACP payload's mixed conventions; if Hermes routes the
|
||||||
|
// count through a `session/update` notification instead, this
|
||||||
|
// decode is a no-op and the ACPEvent path takes over.
|
||||||
|
let compression = (usage["compressionCount"] as? Int)
|
||||||
|
?? (usage["compression_count"] as? Int)
|
||||||
|
?? 0
|
||||||
|
|
||||||
statusMessage = "Ready"
|
statusMessage = "Ready"
|
||||||
return ACPPromptResult(
|
return ACPPromptResult(
|
||||||
@@ -318,7 +326,8 @@ public actor ACPClient {
|
|||||||
inputTokens: usage["inputTokens"] as? Int ?? 0,
|
inputTokens: usage["inputTokens"] as? Int ?? 0,
|
||||||
outputTokens: usage["outputTokens"] as? Int ?? 0,
|
outputTokens: usage["outputTokens"] as? Int ?? 0,
|
||||||
thoughtTokens: usage["thoughtTokens"] as? Int ?? 0,
|
thoughtTokens: usage["thoughtTokens"] as? Int ?? 0,
|
||||||
cachedReadTokens: usage["cachedReadTokens"] as? Int ?? 0
|
cachedReadTokens: usage["cachedReadTokens"] as? Int ?? 0,
|
||||||
|
compressionCount: compression
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -243,19 +243,32 @@ public struct ACPPromptResult: Sendable {
|
|||||||
public let outputTokens: Int
|
public let outputTokens: Int
|
||||||
public let thoughtTokens: Int
|
public let thoughtTokens: Int
|
||||||
public let cachedReadTokens: Int
|
public let cachedReadTokens: Int
|
||||||
|
/// Number of automatic context compactions Hermes has performed on this
|
||||||
|
/// session so far. v0.13+ — older Hermes hosts always return 0, which
|
||||||
|
/// the chat status bar treats as "hide chip". Optional in the wire
|
||||||
|
/// payload; folded into a non-optional `Int` here with a 0 default so
|
||||||
|
/// the rest of the pipeline doesn't need to nil-check.
|
||||||
|
// TODO(WS-8-Q1): Verify that v0.13 Hermes emits the count on
|
||||||
|
// `session/prompt`'s `usage` blob (assumed here). If it lands on a
|
||||||
|
// separate `session/update` notification instead, this becomes a new
|
||||||
|
// ACPEvent case + a branch in RichChatViewModel.handleACPEvent — wire
|
||||||
|
// shape is documented in the WS-8 plan as the bigger fix path.
|
||||||
|
public let compressionCount: Int
|
||||||
|
|
||||||
public init(
|
public init(
|
||||||
stopReason: String,
|
stopReason: String,
|
||||||
inputTokens: Int,
|
inputTokens: Int,
|
||||||
outputTokens: Int,
|
outputTokens: Int,
|
||||||
thoughtTokens: Int,
|
thoughtTokens: Int,
|
||||||
cachedReadTokens: Int
|
cachedReadTokens: Int,
|
||||||
|
compressionCount: Int = 0
|
||||||
) {
|
) {
|
||||||
self.stopReason = stopReason
|
self.stopReason = stopReason
|
||||||
self.inputTokens = inputTokens
|
self.inputTokens = inputTokens
|
||||||
self.outputTokens = outputTokens
|
self.outputTokens = outputTokens
|
||||||
self.thoughtTokens = thoughtTokens
|
self.thoughtTokens = thoughtTokens
|
||||||
self.cachedReadTokens = cachedReadTokens
|
self.cachedReadTokens = cachedReadTokens
|
||||||
|
self.compressionCount = compressionCount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
import Foundation
|
|
||||||
|
|
||||||
/// Errors thrown by `CuratorService`. Each case carries enough detail
|
|
||||||
/// to render a user-actionable message — the view model surfaces these
|
|
||||||
/// inline as a banner above the leaderboard rather than blocking with a
|
|
||||||
/// modal alert.
|
|
||||||
public enum CuratorError: Error, LocalizedError, Sendable {
|
|
||||||
/// `hermes` binary couldn't be located.
|
|
||||||
case cliMissing
|
|
||||||
/// Subprocess returned non-zero exit. `stderr` may carry a synthetic
|
|
||||||
/// message when the transport itself failed.
|
|
||||||
case nonZeroExit(verb: String, code: Int32, stderr: String)
|
|
||||||
/// JSON decoding failed. Underlying message wrapped for diagnostics.
|
|
||||||
case decoding(verb: String, message: String)
|
|
||||||
/// Generic transport error — process couldn't start, IO failed, etc.
|
|
||||||
case transport(message: String)
|
|
||||||
|
|
||||||
public var errorDescription: String? {
|
|
||||||
switch self {
|
|
||||||
case .cliMissing:
|
|
||||||
return "Hermes CLI couldn't be found. Install Hermes v0.13+ and ensure it's on your PATH."
|
|
||||||
case .nonZeroExit(let verb, let code, let stderr):
|
|
||||||
let trimmed = stderr.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
||||||
if trimmed.isEmpty {
|
|
||||||
return "`hermes curator \(verb)` exited with code \(code)."
|
|
||||||
}
|
|
||||||
return trimmed
|
|
||||||
case .decoding(let verb, let message):
|
|
||||||
return "Couldn't decode `hermes curator \(verb)` output: \(message)"
|
|
||||||
case .transport(let message):
|
|
||||||
return message
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -36,6 +36,13 @@ public struct DisplaySettings: Sendable, Equatable {
|
|||||||
public var toolProgressCommand: Bool
|
public var toolProgressCommand: Bool
|
||||||
public var toolPreviewLength: Int
|
public var toolPreviewLength: Int
|
||||||
public var busyInputMode: String // e.g. "interrupt"
|
public var busyInputMode: String // e.g. "interrupt"
|
||||||
|
/// Static-message translation language. v0.13+. Empty string means
|
||||||
|
/// "follow Hermes default" — the picker collapses both empty-string
|
||||||
|
/// and `"en"` to "English" in display, but only writes a value when
|
||||||
|
/// the user explicitly picks one. Persisted via
|
||||||
|
/// `hermes config set display.language <code>`. Supported values per
|
||||||
|
/// v0.13 release notes: `en`, `zh`, `ja`, `de`, `es`, `fr`, `uk`, `tr`.
|
||||||
|
public var language: String
|
||||||
|
|
||||||
|
|
||||||
public init(
|
public init(
|
||||||
@@ -46,7 +53,8 @@ public struct DisplaySettings: Sendable, Equatable {
|
|||||||
inlineDiffs: Bool,
|
inlineDiffs: Bool,
|
||||||
toolProgressCommand: Bool,
|
toolProgressCommand: Bool,
|
||||||
toolPreviewLength: Int,
|
toolPreviewLength: Int,
|
||||||
busyInputMode: String
|
busyInputMode: String,
|
||||||
|
language: String = ""
|
||||||
) {
|
) {
|
||||||
self.skin = skin
|
self.skin = skin
|
||||||
self.compact = compact
|
self.compact = compact
|
||||||
@@ -56,6 +64,7 @@ public struct DisplaySettings: Sendable, Equatable {
|
|||||||
self.toolProgressCommand = toolProgressCommand
|
self.toolProgressCommand = toolProgressCommand
|
||||||
self.toolPreviewLength = toolPreviewLength
|
self.toolPreviewLength = toolPreviewLength
|
||||||
self.busyInputMode = busyInputMode
|
self.busyInputMode = busyInputMode
|
||||||
|
self.language = language
|
||||||
}
|
}
|
||||||
public nonisolated static let empty = DisplaySettings(
|
public nonisolated static let empty = DisplaySettings(
|
||||||
skin: "default",
|
skin: "default",
|
||||||
@@ -65,7 +74,8 @@ public struct DisplaySettings: Sendable, Equatable {
|
|||||||
inlineDiffs: true,
|
inlineDiffs: true,
|
||||||
toolProgressCommand: false,
|
toolProgressCommand: false,
|
||||||
toolPreviewLength: 0,
|
toolPreviewLength: 0,
|
||||||
busyInputMode: "interrupt"
|
busyInputMode: "interrupt",
|
||||||
|
language: ""
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,6 +200,15 @@ public struct VoiceSettings: Sendable, Equatable {
|
|||||||
public var ttsOpenAIVoice: String
|
public var ttsOpenAIVoice: String
|
||||||
public var ttsNeuTTSModel: String
|
public var ttsNeuTTSModel: String
|
||||||
public var ttsNeuTTSDevice: String
|
public var ttsNeuTTSDevice: String
|
||||||
|
/// xAI TTS voice identifier. v0.13+ — xAI shipped TTS earlier but the
|
||||||
|
/// custom-voice / cloning surface is the v0.13 add-on.
|
||||||
|
// TODO(WS-8-Q2): Confirm key name vs `tts.xai.voice` /
|
||||||
|
// `tts.xai.voice_id` / a top-level `tts.xai_voice` once a v0.13
|
||||||
|
// host is on hand. The setter / YAML reader follow whatever this
|
||||||
|
// field name implies.
|
||||||
|
public var ttsXAIVoiceID: String
|
||||||
|
/// xAI TTS model identifier. v0.13+. Mirrors the elevenlabs shape.
|
||||||
|
public var ttsXAIModel: String
|
||||||
|
|
||||||
// STT
|
// STT
|
||||||
public var sttEnabled: Bool
|
public var sttEnabled: Bool
|
||||||
@@ -217,7 +236,9 @@ public struct VoiceSettings: Sendable, Equatable {
|
|||||||
sttLocalModel: String,
|
sttLocalModel: String,
|
||||||
sttLocalLanguage: String,
|
sttLocalLanguage: String,
|
||||||
sttOpenAIModel: String,
|
sttOpenAIModel: String,
|
||||||
sttMistralModel: String
|
sttMistralModel: String,
|
||||||
|
ttsXAIVoiceID: String = "",
|
||||||
|
ttsXAIModel: String = ""
|
||||||
) {
|
) {
|
||||||
self.recordKey = recordKey
|
self.recordKey = recordKey
|
||||||
self.maxRecordingSeconds = maxRecordingSeconds
|
self.maxRecordingSeconds = maxRecordingSeconds
|
||||||
@@ -230,6 +251,8 @@ public struct VoiceSettings: Sendable, Equatable {
|
|||||||
self.ttsOpenAIVoice = ttsOpenAIVoice
|
self.ttsOpenAIVoice = ttsOpenAIVoice
|
||||||
self.ttsNeuTTSModel = ttsNeuTTSModel
|
self.ttsNeuTTSModel = ttsNeuTTSModel
|
||||||
self.ttsNeuTTSDevice = ttsNeuTTSDevice
|
self.ttsNeuTTSDevice = ttsNeuTTSDevice
|
||||||
|
self.ttsXAIVoiceID = ttsXAIVoiceID
|
||||||
|
self.ttsXAIModel = ttsXAIModel
|
||||||
self.sttEnabled = sttEnabled
|
self.sttEnabled = sttEnabled
|
||||||
self.sttProvider = sttProvider
|
self.sttProvider = sttProvider
|
||||||
self.sttLocalModel = sttLocalModel
|
self.sttLocalModel = sttLocalModel
|
||||||
@@ -254,7 +277,9 @@ public struct VoiceSettings: Sendable, Equatable {
|
|||||||
sttLocalModel: "base",
|
sttLocalModel: "base",
|
||||||
sttLocalLanguage: "",
|
sttLocalLanguage: "",
|
||||||
sttOpenAIModel: "whisper-1",
|
sttOpenAIModel: "whisper-1",
|
||||||
sttMistralModel: "voxtral-mini-latest"
|
sttMistralModel: "voxtral-mini-latest",
|
||||||
|
ttsXAIVoiceID: "",
|
||||||
|
ttsXAIModel: ""
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,124 +0,0 @@
|
|||||||
import Foundation
|
|
||||||
|
|
||||||
/// One entry in the `hermes curator list-archived` output. Decoded
|
|
||||||
/// tolerantly via `decodeIfPresent` so a stripped-down host (or a future
|
|
||||||
/// Hermes that drops one of the optional columns) doesn't crash the view.
|
|
||||||
///
|
|
||||||
/// Only `name` is required — every other field is optional and the
|
|
||||||
/// computed `*Label` accessors render `"—"` for missing values.
|
|
||||||
public struct HermesCuratorArchivedSkill: Sendable, Equatable, Identifiable, Codable {
|
|
||||||
public var id: String { name }
|
|
||||||
public let name: String
|
|
||||||
public let category: String?
|
|
||||||
public let archivedAt: String?
|
|
||||||
public let reason: String?
|
|
||||||
public let sizeBytes: Int?
|
|
||||||
public let path: String?
|
|
||||||
|
|
||||||
public init(
|
|
||||||
name: String,
|
|
||||||
category: String? = nil,
|
|
||||||
archivedAt: String? = nil,
|
|
||||||
reason: String? = nil,
|
|
||||||
sizeBytes: Int? = nil,
|
|
||||||
path: String? = nil
|
|
||||||
) {
|
|
||||||
self.name = name
|
|
||||||
self.category = category
|
|
||||||
self.archivedAt = archivedAt
|
|
||||||
self.reason = reason
|
|
||||||
self.sizeBytes = sizeBytes
|
|
||||||
self.path = path
|
|
||||||
}
|
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
|
||||||
case name
|
|
||||||
case category
|
|
||||||
case archivedAt = "archived_at"
|
|
||||||
case reason
|
|
||||||
case sizeBytes = "size_bytes"
|
|
||||||
case path
|
|
||||||
}
|
|
||||||
|
|
||||||
public init(from decoder: Decoder) throws {
|
|
||||||
let c = try decoder.container(keyedBy: CodingKeys.self)
|
|
||||||
self.name = try c.decode(String.self, forKey: .name)
|
|
||||||
self.category = try c.decodeIfPresent(String.self, forKey: .category)
|
|
||||||
self.archivedAt = try c.decodeIfPresent(String.self, forKey: .archivedAt)
|
|
||||||
self.reason = try c.decodeIfPresent(String.self, forKey: .reason)
|
|
||||||
self.sizeBytes = try c.decodeIfPresent(Int.self, forKey: .sizeBytes)
|
|
||||||
self.path = try c.decodeIfPresent(String.self, forKey: .path)
|
|
||||||
}
|
|
||||||
|
|
||||||
public func encode(to encoder: Encoder) throws {
|
|
||||||
var c = encoder.container(keyedBy: CodingKeys.self)
|
|
||||||
try c.encode(name, forKey: .name)
|
|
||||||
try c.encodeIfPresent(category, forKey: .category)
|
|
||||||
try c.encodeIfPresent(archivedAt, forKey: .archivedAt)
|
|
||||||
try c.encodeIfPresent(reason, forKey: .reason)
|
|
||||||
try c.encodeIfPresent(sizeBytes, forKey: .sizeBytes)
|
|
||||||
try c.encodeIfPresent(path, forKey: .path)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// "4.4 KB" / "1.2 MB" / "—" for nil. Uses the SI byte formatter so
|
|
||||||
/// the labels match what Finder shows.
|
|
||||||
public var sizeLabel: String {
|
|
||||||
guard let bytes = sizeBytes else { return "—" }
|
|
||||||
let formatter = ByteCountFormatter()
|
|
||||||
formatter.allowedUnits = [.useAll]
|
|
||||||
formatter.countStyle = .file
|
|
||||||
return formatter.string(fromByteCount: Int64(bytes))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `2026-04-22` (ISO date prefix) / "—". Hermes returns full ISO
|
|
||||||
/// timestamps with seconds + Z; the date prefix is what the user
|
|
||||||
/// actually wants in the archived list.
|
|
||||||
public var archivedAtLabel: String {
|
|
||||||
guard let iso = archivedAt, !iso.isEmpty else { return "—" }
|
|
||||||
// Trim to date prefix if it looks like a full ISO timestamp.
|
|
||||||
if let tIdx = iso.firstIndex(of: "T") {
|
|
||||||
return String(iso[..<tIdx])
|
|
||||||
}
|
|
||||||
return iso
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Result of `hermes curator prune --dry-run` — what would be removed
|
|
||||||
/// if the user confirms. The view derives `totalCount` from
|
|
||||||
/// `wouldRemove.count` so the wire shape stays flat.
|
|
||||||
public struct CuratorPruneSummary: Sendable, Equatable, Codable {
|
|
||||||
public let wouldRemove: [HermesCuratorArchivedSkill]
|
|
||||||
public let totalBytes: Int
|
|
||||||
public var totalCount: Int { wouldRemove.count }
|
|
||||||
|
|
||||||
public init(wouldRemove: [HermesCuratorArchivedSkill], totalBytes: Int) {
|
|
||||||
self.wouldRemove = wouldRemove
|
|
||||||
self.totalBytes = totalBytes
|
|
||||||
}
|
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
|
||||||
case wouldRemove = "would_remove"
|
|
||||||
case totalBytes = "total_bytes"
|
|
||||||
}
|
|
||||||
|
|
||||||
public init(from decoder: Decoder) throws {
|
|
||||||
let c = try decoder.container(keyedBy: CodingKeys.self)
|
|
||||||
self.wouldRemove = try c.decodeIfPresent([HermesCuratorArchivedSkill].self, forKey: .wouldRemove) ?? []
|
|
||||||
self.totalBytes = try c.decodeIfPresent(Int.self, forKey: .totalBytes) ?? 0
|
|
||||||
}
|
|
||||||
|
|
||||||
public func encode(to encoder: Encoder) throws {
|
|
||||||
var c = encoder.container(keyedBy: CodingKeys.self)
|
|
||||||
try c.encode(wouldRemove, forKey: .wouldRemove)
|
|
||||||
try c.encode(totalBytes, forKey: .totalBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// "12.3 KB" / "—" for empty. Convenience for the confirm sheet header.
|
|
||||||
public var totalBytesLabel: String {
|
|
||||||
guard totalBytes > 0 else { return "—" }
|
|
||||||
let formatter = ByteCountFormatter()
|
|
||||||
formatter.allowedUnits = [.useAll]
|
|
||||||
formatter.countStyle = .file
|
|
||||||
return formatter.string(fromByteCount: Int64(totalBytes))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,358 +0,0 @@
|
|||||||
import Foundation
|
|
||||||
#if canImport(os)
|
|
||||||
import os
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// Async, transport-aware client for `hermes curator …`. Wraps the v0.12
|
|
||||||
/// verbs (`status / run / pause / resume / pin / unpin / restore`) plus
|
|
||||||
/// the v0.13 archive surface (`archive / prune / list-archived` and a
|
|
||||||
/// synchronous-blocking `run`).
|
|
||||||
///
|
|
||||||
/// **Concurrency.** Pure-I/O `actor` — no UI state. View models hold a
|
|
||||||
/// service reference and `await` methods. Each public method dispatches
|
|
||||||
/// the underlying CLI invocation through `Task.detached(priority:
|
|
||||||
/// .utility)` so two concurrent reads from the VM don't queue end-to-end
|
|
||||||
/// on a single thread. Mirrors `KanbanService` shape exactly.
|
|
||||||
///
|
|
||||||
/// **Capability gating happens at the call site, not in the service.**
|
|
||||||
/// `runNow(synchronous:timeout:)` takes a flag from the VM (the VM reads
|
|
||||||
/// `HermesCapabilities.hasCuratorArchive` to decide). The service stays
|
|
||||||
/// version-agnostic — only the timeout differs in practice.
|
|
||||||
public actor CuratorService {
|
|
||||||
#if canImport(os)
|
|
||||||
private static let logger = Logger(subsystem: "com.scarf", category: "CuratorService")
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private let context: ServerContext
|
|
||||||
|
|
||||||
public init(context: ServerContext) {
|
|
||||||
self.context = context
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Reads
|
|
||||||
|
|
||||||
/// Run `hermes curator status` and parse stdout via
|
|
||||||
/// `HermesCuratorStatusParser`. Combines the text output with the
|
|
||||||
/// on-disk `.curator_state` JSON for richer last-run metadata.
|
|
||||||
/// Never throws — a transport failure resolves to `.empty` so the
|
|
||||||
/// view always has something to render.
|
|
||||||
public func status() async -> HermesCuratorStatus {
|
|
||||||
let context = self.context
|
|
||||||
return await Task.detached(priority: .utility) { () -> HermesCuratorStatus in
|
|
||||||
let textResult = Self.runHermesSync(context: context, args: ["curator", "status"], timeout: 30)
|
|
||||||
let stateData = context.readData(context.paths.curatorStateFile)
|
|
||||||
return HermesCuratorStatusParser.parse(text: textResult.output, stateFileJSON: stateData)
|
|
||||||
}.value
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `hermes curator list-archived [--json]`. Prefers JSON; falls back
|
|
||||||
/// to a defensive text parser. Empty / "no archived skills" sentinel
|
|
||||||
/// folds to `[]`.
|
|
||||||
public func listArchived() async throws -> [HermesCuratorArchivedSkill] {
|
|
||||||
// TODO(WS-4-Q2): confirm `--json` is supported on v0.13
|
|
||||||
// `list-archived`. If not, drop the flag and rely on the text
|
|
||||||
// parser path. Until then we pass `--json` and parse the output
|
|
||||||
// tolerantly.
|
|
||||||
let args = ["curator", "list-archived", "--json"]
|
|
||||||
let (code, stdout, stderr) = await runHermes(args: args, timeout: 30)
|
|
||||||
|
|
||||||
// If --json isn't recognized, the CLI typically emits
|
|
||||||
// "unrecognized arguments: --json" or similar to stderr and
|
|
||||||
// exits non-zero. Retry without the flag and parse text.
|
|
||||||
if code != 0 {
|
|
||||||
let lower = (stderr + stdout).lowercased()
|
|
||||||
if lower.contains("unrecognized") || lower.contains("unknown") || lower.contains("no such option") {
|
|
||||||
let (c2, out2, err2) = await runHermes(args: ["curator", "list-archived"], timeout: 30)
|
|
||||||
try ensureSuccess(code: c2, stdout: out2, stderr: err2, verb: "list-archived")
|
|
||||||
return Self.parseListArchivedText(out2)
|
|
||||||
}
|
|
||||||
try ensureSuccess(code: code, stdout: stdout, stderr: stderr, verb: "list-archived")
|
|
||||||
}
|
|
||||||
|
|
||||||
let trimmed = stdout.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
||||||
if trimmed.isEmpty || trimmed.lowercased().contains("no archived skills") {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
// Try JSON first — may also be a text dump if Hermes ignored `--json`.
|
|
||||||
if let data = trimmed.data(using: .utf8),
|
|
||||||
let arr = try? JSONDecoder().decode([HermesCuratorArchivedSkill].self, from: data) {
|
|
||||||
return arr
|
|
||||||
}
|
|
||||||
// Some builds wrap in `{"archived": [...]}` envelope.
|
|
||||||
struct Wrapper: Decodable { let archived: [HermesCuratorArchivedSkill] }
|
|
||||||
if let data = trimmed.data(using: .utf8),
|
|
||||||
let wrapped = try? JSONDecoder().decode(Wrapper.self, from: data) {
|
|
||||||
return wrapped.archived
|
|
||||||
}
|
|
||||||
// Text fallback — defensive parse.
|
|
||||||
return Self.parseListArchivedText(stdout)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Writes (legacy v0.12 verbs; service form)
|
|
||||||
|
|
||||||
public func runNow(synchronous: Bool, timeout: TimeInterval) async throws {
|
|
||||||
// TODO(WS-4-Q4): default 600s for v0.13 sync runs. No Cancel
|
|
||||||
// button in v2.8 (transport.cancel parity not guaranteed across
|
|
||||||
// LocalTransport / SSHTransport).
|
|
||||||
let resolvedTimeout = synchronous ? timeout : 30
|
|
||||||
let (code, stdout, stderr) = await runHermes(args: ["curator", "run"], timeout: resolvedTimeout)
|
|
||||||
try ensureSuccess(code: code, stdout: stdout, stderr: stderr, verb: "run")
|
|
||||||
}
|
|
||||||
|
|
||||||
public func pause() async throws {
|
|
||||||
let (code, stdout, stderr) = await runHermes(args: ["curator", "pause"], timeout: 15)
|
|
||||||
try ensureSuccess(code: code, stdout: stdout, stderr: stderr, verb: "pause")
|
|
||||||
}
|
|
||||||
|
|
||||||
public func resume() async throws {
|
|
||||||
let (code, stdout, stderr) = await runHermes(args: ["curator", "resume"], timeout: 15)
|
|
||||||
try ensureSuccess(code: code, stdout: stdout, stderr: stderr, verb: "resume")
|
|
||||||
}
|
|
||||||
|
|
||||||
public func pin(_ name: String) async throws {
|
|
||||||
let (code, stdout, stderr) = await runHermes(args: ["curator", "pin", name], timeout: 15)
|
|
||||||
try ensureSuccess(code: code, stdout: stdout, stderr: stderr, verb: "pin")
|
|
||||||
}
|
|
||||||
|
|
||||||
public func unpin(_ name: String) async throws {
|
|
||||||
let (code, stdout, stderr) = await runHermes(args: ["curator", "unpin", name], timeout: 15)
|
|
||||||
try ensureSuccess(code: code, stdout: stdout, stderr: stderr, verb: "unpin")
|
|
||||||
}
|
|
||||||
|
|
||||||
public func restore(_ name: String) async throws {
|
|
||||||
let (code, stdout, stderr) = await runHermes(args: ["curator", "restore", name], timeout: 30)
|
|
||||||
try ensureSuccess(code: code, stdout: stdout, stderr: stderr, verb: "restore")
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Writes (new in v0.13)
|
|
||||||
|
|
||||||
/// `hermes curator archive <name>` — non-destructive; moves the
|
|
||||||
/// skill from the active set to the archived set. No `--json` is
|
|
||||||
/// expected; the verb's success channel is the exit code.
|
|
||||||
public func archive(_ name: String) async throws {
|
|
||||||
let (code, stdout, stderr) = await runHermes(args: ["curator", "archive", name], timeout: 30)
|
|
||||||
try ensureSuccess(code: code, stdout: stdout, stderr: stderr, verb: "archive")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `hermes curator prune [--dry-run]`. Destructive when `dryRun`
|
|
||||||
/// is `false` — removes everything currently archived from disk.
|
|
||||||
/// Returns a `CuratorPruneSummary` describing what was (or would be)
|
|
||||||
/// removed. On `dryRun=false`, the wire shape may not include the
|
|
||||||
/// `would_remove` list — the caller should not depend on it; the
|
|
||||||
/// archived list is empty after a successful destructive prune.
|
|
||||||
@discardableResult
|
|
||||||
public func prune(dryRun: Bool) async throws -> CuratorPruneSummary {
|
|
||||||
// TODO(WS-4-Q1): confirm v0.13 ships `--dry-run`. If not, fall
|
|
||||||
// back to enumerating via `list-archived` and treat any prune
|
|
||||||
// call as destructive. The retry-without-flag path below covers
|
|
||||||
// the "unrecognized argument" case automatically.
|
|
||||||
var args = ["curator", "prune"]
|
|
||||||
if dryRun { args.append("--dry-run") }
|
|
||||||
// `--json` requested for the dry-run path so we can parse the
|
|
||||||
// would-remove list. Destructive mode runs without --json since
|
|
||||||
// we only need the exit code.
|
|
||||||
if dryRun { args.append("--json") }
|
|
||||||
|
|
||||||
let (code, stdout, stderr) = await runHermes(args: args, timeout: 60)
|
|
||||||
|
|
||||||
// Detect "unrecognized --dry-run" / "unknown --json" gracefully.
|
|
||||||
if code != 0 {
|
|
||||||
let lower = (stderr + stdout).lowercased()
|
|
||||||
let unrecognized = lower.contains("unrecognized") || lower.contains("unknown") || lower.contains("no such option")
|
|
||||||
if dryRun && unrecognized {
|
|
||||||
// Q1 fallback: enumerate via list-archived. Caller still
|
|
||||||
// uses this summary for confirm-sheet display.
|
|
||||||
let archived = try await listArchived()
|
|
||||||
let total = archived.compactMap { $0.sizeBytes }.reduce(0, +)
|
|
||||||
return CuratorPruneSummary(wouldRemove: archived, totalBytes: total)
|
|
||||||
}
|
|
||||||
try ensureSuccess(code: code, stdout: stdout, stderr: stderr, verb: "prune")
|
|
||||||
}
|
|
||||||
|
|
||||||
if dryRun {
|
|
||||||
return Self.parsePruneDryRun(stdout)
|
|
||||||
}
|
|
||||||
return CuratorPruneSummary(wouldRemove: [], totalBytes: 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Pure parsers (nonisolated; safe to call from VMs without awaits)
|
|
||||||
|
|
||||||
/// Parse a `list-archived --json` payload. Tolerates the bare-array
|
|
||||||
/// shape, the `{"archived": [...]}` envelope, and "no archived
|
|
||||||
/// skills" / empty-string sentinels. Returns `[]` for any of the
|
|
||||||
/// empty cases. Throws `CuratorError.decoding` only when the input
|
|
||||||
/// is non-empty and clearly not JSON.
|
|
||||||
public nonisolated static func parseListArchived(stdout: String) throws -> [HermesCuratorArchivedSkill] {
|
|
||||||
let trimmed = stdout.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
||||||
if trimmed.isEmpty || trimmed.lowercased().contains("no archived skills") {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
guard let data = trimmed.data(using: .utf8) else {
|
|
||||||
throw CuratorError.decoding(verb: "list-archived", message: "non-UTF8 stdout")
|
|
||||||
}
|
|
||||||
if let arr = try? JSONDecoder().decode([HermesCuratorArchivedSkill].self, from: data) {
|
|
||||||
return arr
|
|
||||||
}
|
|
||||||
struct Wrapper: Decodable { let archived: [HermesCuratorArchivedSkill] }
|
|
||||||
if let wrapped = try? JSONDecoder().decode(Wrapper.self, from: data) {
|
|
||||||
return wrapped.archived
|
|
||||||
}
|
|
||||||
// Last resort: text fallback.
|
|
||||||
let parsed = parseListArchivedText(stdout)
|
|
||||||
if !parsed.isEmpty {
|
|
||||||
return parsed
|
|
||||||
}
|
|
||||||
throw CuratorError.decoding(verb: "list-archived", message: "stdout was neither JSON nor a recognised text list")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Defensive text parser for `list-archived` output when `--json`
|
|
||||||
/// isn't supported. Format inferred from `curator status`: one row
|
|
||||||
/// per non-blank line, leading whitespace, name in column 1, then
|
|
||||||
/// optional `archived=YYYY-MM-DD`, `size=NNNN`, `reason=...` k/v
|
|
||||||
/// pairs. Blank lines, header lines, and the empty-state sentinel
|
|
||||||
/// are skipped.
|
|
||||||
public nonisolated static func parseListArchivedText(_ text: String) -> [HermesCuratorArchivedSkill] {
|
|
||||||
var rows: [HermesCuratorArchivedSkill] = []
|
|
||||||
for raw in text.split(separator: "\n") {
|
|
||||||
let line = raw.trimmingCharacters(in: .whitespaces)
|
|
||||||
if line.isEmpty { continue }
|
|
||||||
let lower = line.lowercased()
|
|
||||||
// Skip header / sentinel lines.
|
|
||||||
if lower.hasPrefix("name") && lower.contains("archived") { continue }
|
|
||||||
if lower.contains("no archived skills") { continue }
|
|
||||||
if line.unicodeScalars.allSatisfy({ $0.value == 0x2500 || $0.properties.isWhitespace }) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Skip lines that look like JSON / non-row chrome — `{`,
|
|
||||||
// `}`, `[`, `]` at the start or quotes / colons mean we're
|
|
||||||
// parsing a malformed JSON dump, not a row table.
|
|
||||||
if let first = line.first, "{[}]\":,".contains(first) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Find the first whitespace-separated token as the name; if
|
|
||||||
// the name carries an `=` it's a header chip we should skip.
|
|
||||||
let parts = line.split(whereSeparator: { $0 == "\t" || $0 == " " }).map(String.init)
|
|
||||||
guard let name = parts.first, !name.contains("=") else { continue }
|
|
||||||
// Reject names that look like punctuation / JSON fragments.
|
|
||||||
if name.contains("\"") || name.contains(":") || name.contains("{") || name.contains("}") || name.contains("[") || name.contains("]") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Pull k=v pairs from the remainder.
|
|
||||||
var archivedAt: String?
|
|
||||||
var sizeBytes: Int?
|
|
||||||
var reason: String?
|
|
||||||
var category: String?
|
|
||||||
var path: String?
|
|
||||||
for token in parts.dropFirst() {
|
|
||||||
guard let eq = token.firstIndex(of: "=") else { continue }
|
|
||||||
let key = String(token[..<eq])
|
|
||||||
let value = String(token[token.index(after: eq)...])
|
|
||||||
switch key {
|
|
||||||
case "archived", "archived_at":
|
|
||||||
archivedAt = value
|
|
||||||
case "size", "size_bytes":
|
|
||||||
sizeBytes = Int(value)
|
|
||||||
case "reason":
|
|
||||||
reason = value
|
|
||||||
case "category":
|
|
||||||
category = value
|
|
||||||
case "path":
|
|
||||||
path = value
|
|
||||||
default:
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rows.append(
|
|
||||||
HermesCuratorArchivedSkill(
|
|
||||||
name: name,
|
|
||||||
category: category,
|
|
||||||
archivedAt: archivedAt,
|
|
||||||
reason: reason,
|
|
||||||
sizeBytes: sizeBytes,
|
|
||||||
path: path
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return rows
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parse a `prune --dry-run --json` payload. Tolerates an empty
|
|
||||||
/// payload (returns a zero summary) and the `{would_remove: [],
|
|
||||||
/// total_bytes: N}` shape.
|
|
||||||
public nonisolated static func parsePruneDryRun(_ stdout: String) -> CuratorPruneSummary {
|
|
||||||
let trimmed = stdout.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
||||||
guard !trimmed.isEmpty else {
|
|
||||||
return CuratorPruneSummary(wouldRemove: [], totalBytes: 0)
|
|
||||||
}
|
|
||||||
if let data = trimmed.data(using: .utf8),
|
|
||||||
let summary = try? JSONDecoder().decode(CuratorPruneSummary.self, from: data) {
|
|
||||||
return summary
|
|
||||||
}
|
|
||||||
// Tolerate a bare-array fallback (some Hermes builds may print
|
|
||||||
// just the would-remove list when --json is missing the wrapper).
|
|
||||||
if let data = trimmed.data(using: .utf8),
|
|
||||||
let arr = try? JSONDecoder().decode([HermesCuratorArchivedSkill].self, from: data) {
|
|
||||||
let total = arr.compactMap { $0.sizeBytes }.reduce(0, +)
|
|
||||||
return CuratorPruneSummary(wouldRemove: arr, totalBytes: total)
|
|
||||||
}
|
|
||||||
// Last-resort text parse for "would remove N skills (X bytes)".
|
|
||||||
return CuratorPruneSummary(wouldRemove: [], totalBytes: 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - CLI invocation
|
|
||||||
|
|
||||||
private nonisolated func runHermes(
|
|
||||||
args: [String],
|
|
||||||
timeout: TimeInterval
|
|
||||||
) async -> (exitCode: Int32, stdout: String, stderr: String) {
|
|
||||||
let context = self.context
|
|
||||||
return await Task.detached(priority: .utility) { () -> (Int32, String, String) in
|
|
||||||
let result = Self.runHermesSync(context: context, args: args, timeout: timeout)
|
|
||||||
return (result.exitCode, result.output, result.stderr)
|
|
||||||
}.value
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Synchronous, transport-level invocation. `output` is stdout; the
|
|
||||||
/// caller usually only reads `output` for parser input but sometimes
|
|
||||||
/// needs `stderr` (e.g. to detect "unrecognized argument" patterns).
|
|
||||||
private nonisolated static func runHermesSync(
|
|
||||||
context: ServerContext,
|
|
||||||
args: [String],
|
|
||||||
timeout: TimeInterval
|
|
||||||
) -> (exitCode: Int32, output: String, stderr: String) {
|
|
||||||
let transport = context.makeTransport()
|
|
||||||
do {
|
|
||||||
let result = try transport.runProcess(
|
|
||||||
executable: context.paths.hermesBinary,
|
|
||||||
args: args,
|
|
||||||
stdin: nil,
|
|
||||||
timeout: timeout
|
|
||||||
)
|
|
||||||
return (result.exitCode, result.stdoutString, result.stderrString)
|
|
||||||
} catch let error as TransportError {
|
|
||||||
let message = error.diagnosticStderr.isEmpty
|
|
||||||
? (error.errorDescription ?? "transport error")
|
|
||||||
: error.diagnosticStderr
|
|
||||||
return (-1, "", message)
|
|
||||||
} catch {
|
|
||||||
return (-1, "", error.localizedDescription)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private nonisolated func ensureSuccess(
|
|
||||||
code: Int32,
|
|
||||||
stdout: String,
|
|
||||||
stderr: String,
|
|
||||||
verb: String
|
|
||||||
) throws {
|
|
||||||
guard code != 0 else { return }
|
|
||||||
if code == -1 && stderr.lowercased().contains("hermes binary not found") {
|
|
||||||
throw CuratorError.cliMissing
|
|
||||||
}
|
|
||||||
let combined = stderr.isEmpty ? stdout : stderr
|
|
||||||
#if canImport(os)
|
|
||||||
Self.logger.warning("curator \(verb) exit=\(code, privacy: .public) stderr=\(combined, privacy: .public)")
|
|
||||||
#endif
|
|
||||||
throw CuratorError.nonZeroExit(verb: verb, code: code, stderr: combined)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
/// Pure helpers that build argv arrays for `hermes update` invocations.
|
||||||
|
///
|
||||||
|
/// Lives in ScarfCore so the eventual UI surface (Mac / iOS / remote)
|
||||||
|
/// shares flag selection. There is no in-app "Update Hermes" affordance
|
||||||
|
/// in v2.7.5 — Sparkle handles Scarf-self-update and `hermes update` is
|
||||||
|
/// invoked by users in their terminal — but capability-gated flag logic
|
||||||
|
/// is forward-compat plumbing that the future affordance will call. Each
|
||||||
|
/// helper is a `nonisolated static` pure function: no transport, no
|
||||||
|
/// MainActor, no mocking surface required.
|
||||||
|
public enum HermesUpdaterCommandBuilder {
|
||||||
|
/// Argv for an `hermes update` invocation, capability-gated.
|
||||||
|
///
|
||||||
|
/// Pre-v0.12 hosts only had `update` (no flags). v0.12+ accepts
|
||||||
|
/// `--check` for preflight. v0.13+ accepts `--yes` / `-y` for
|
||||||
|
/// unattended runs (skips the interactive confirmation prompt).
|
||||||
|
/// Flags are silently dropped when the connected host can't honor
|
||||||
|
/// them so callers don't need to branch on capabilities themselves.
|
||||||
|
public static func updateArgv(
|
||||||
|
capabilities: HermesCapabilities,
|
||||||
|
unattended: Bool,
|
||||||
|
checkOnly: Bool
|
||||||
|
) -> [String] {
|
||||||
|
var args: [String] = ["update"]
|
||||||
|
if checkOnly && capabilities.hasUpdateCheck {
|
||||||
|
args.append("--check")
|
||||||
|
}
|
||||||
|
if unattended && capabilities.hasUpdateNonInteractive {
|
||||||
|
args.append("--yes")
|
||||||
|
}
|
||||||
|
return args
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,19 +4,17 @@ import Observation
|
|||||||
import os
|
import os
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// Mac + iOS view model for the Curator surface (v0.12 base + v0.13
|
/// Mac + iOS view model for the v0.12 Curator surface.
|
||||||
/// archive/prune additions).
|
|
||||||
///
|
///
|
||||||
/// Drives `hermes curator status / run / pause / resume / pin / unpin /
|
/// Drives `hermes curator status / run / pause / resume / pin / unpin /
|
||||||
/// restore` plus (v0.13+) `archive`, `prune`, `list-archived`. All CLI
|
/// restore` plus a parsed view of `~/.hermes/skills/.curator_state`
|
||||||
/// invocations route through `CuratorService` (the actor) so polling
|
/// JSON. The CLI doesn't ship a `--json` flag for `status`, so we
|
||||||
/// and writes share the same concurrency model and a single error path.
|
/// text-parse stdout (HermesCuratorStatusParser) and use the state
|
||||||
|
/// file for richer last-run metadata.
|
||||||
///
|
///
|
||||||
/// Capability-gated: callers should construct this only when
|
/// Capability-gated: callers should construct this only when
|
||||||
/// `HermesCapabilities.hasCurator` is true. Archive-aware UI surfaces
|
/// `HermesCapabilities.hasCurator` is true. The view model does not
|
||||||
/// (Archive button, Archived section, Prune…) gate independently on
|
/// gate itself — the gate happens at sidebar/tab routing time.
|
||||||
/// `hasCuratorArchive`. The view model itself doesn't gate — it exposes
|
|
||||||
/// every method and the View decides what to render.
|
|
||||||
@Observable
|
@Observable
|
||||||
@MainActor
|
@MainActor
|
||||||
public final class CuratorViewModel {
|
public final class CuratorViewModel {
|
||||||
@@ -29,50 +27,20 @@ public final class CuratorViewModel {
|
|||||||
public private(set) var status: HermesCuratorStatus = .empty
|
public private(set) var status: HermesCuratorStatus = .empty
|
||||||
public private(set) var isLoading = false
|
public private(set) var isLoading = false
|
||||||
public private(set) var lastReportMarkdown: String?
|
public private(set) var lastReportMarkdown: String?
|
||||||
|
|
||||||
// Archive state (v0.13+ only — populated by `loadArchive()` on hosts
|
|
||||||
// where `hasCuratorArchive` is true).
|
|
||||||
public private(set) var archivedSkills: [HermesCuratorArchivedSkill] = []
|
|
||||||
public private(set) var isLoadingArchive = false
|
|
||||||
|
|
||||||
// Prune state — `pruneSummary` non-nil while the confirm sheet is
|
|
||||||
// mid-flight; `isPruning` flips during the destructive step.
|
|
||||||
public private(set) var pruneSummary: CuratorPruneSummary?
|
|
||||||
public private(set) var isPruning = false
|
|
||||||
|
|
||||||
// Track which active-skill row is currently being archived so the
|
|
||||||
// row chrome can show an inline spinner without blocking the rest.
|
|
||||||
public private(set) var pendingArchiveName: String?
|
|
||||||
|
|
||||||
/// Happy-path success toast ("Pinned X", "Resumed", "Archived
|
|
||||||
/// legacy-helper"). Auto-clears 3s after assignment.
|
|
||||||
public var transientMessage: String?
|
public var transientMessage: String?
|
||||||
|
|
||||||
/// Failure path — populated by every CLI verb when it throws. Shown
|
|
||||||
/// as an inline yellow banner above the status summary so users
|
|
||||||
/// don't have to dismiss a modal alert during a high-frequency
|
|
||||||
/// surface like the leaderboard. Manually dismissed via the View's
|
|
||||||
/// "x" button (sets to nil).
|
|
||||||
public var errorMessage: String?
|
|
||||||
|
|
||||||
@ObservationIgnored
|
|
||||||
private let service: CuratorService
|
|
||||||
|
|
||||||
public init(context: ServerContext) {
|
public init(context: ServerContext) {
|
||||||
self.context = context
|
self.context = context
|
||||||
self.service = CuratorService(context: context)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Loads
|
|
||||||
|
|
||||||
public func load() async {
|
public func load() async {
|
||||||
isLoading = true
|
isLoading = true
|
||||||
defer { isLoading = false }
|
defer { isLoading = false }
|
||||||
let context = self.context
|
let context = self.context
|
||||||
// v2.8 — instrumented. Curator load fires `hermes curator
|
// v2.8 — instrumented. Curator load fires `hermes curator
|
||||||
// status` (CLI subprocess) plus 1-2 file reads; on remote each
|
// status` (CLI subprocess) plus 1-2 file reads; on remote
|
||||||
// is a separate SSH RTT. Visibility lets future captures show
|
// each is a separate SSH RTT. Visibility lets future captures
|
||||||
// how often the report file is missing or oversized.
|
// show how often the report file is missing or oversized.
|
||||||
let parsed = await ScarfMon.measureAsync(.diskIO, "curator.load") {
|
let parsed = await ScarfMon.measureAsync(.diskIO, "curator.load") {
|
||||||
await Task.detached(priority: .userInitiated) { () -> (HermesCuratorStatus, String?) in
|
await Task.detached(priority: .userInitiated) { () -> (HermesCuratorStatus, String?) in
|
||||||
let textResult = Self.runCuratorStatus(context: context)
|
let textResult = Self.runCuratorStatus(context: context)
|
||||||
@@ -101,156 +69,46 @@ public final class CuratorViewModel {
|
|||||||
self.lastReportMarkdown = parsed.1
|
self.lastReportMarkdown = parsed.1
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Refresh the archived-skills list. No-op on hosts without
|
public func runNow() async {
|
||||||
/// `hasCuratorArchive` — the caller gates the call.
|
await runAndReload(args: ["curator", "run"], successMessage: "Curator run started")
|
||||||
public func loadArchive() async {
|
|
||||||
isLoadingArchive = true
|
|
||||||
defer { isLoadingArchive = false }
|
|
||||||
do {
|
|
||||||
archivedSkills = try await service.listArchived()
|
|
||||||
} catch {
|
|
||||||
archivedSkills = []
|
|
||||||
errorMessage = (error as? LocalizedError)?.errorDescription
|
|
||||||
?? error.localizedDescription
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Writes (v0.12)
|
|
||||||
|
|
||||||
/// Run the curator manually. On v0.13+ hosts this blocks for the
|
|
||||||
/// duration of the run (default 600s timeout); pre-v0.13 returns
|
|
||||||
/// immediately. Caller passes the capability-decided flag.
|
|
||||||
public func runNow(synchronous: Bool, timeout: TimeInterval = 600) async {
|
|
||||||
await runWithReload(
|
|
||||||
verb: "run",
|
|
||||||
successMessage: synchronous ? "Curator run complete" : "Curator run started"
|
|
||||||
) {
|
|
||||||
try await self.service.runNow(synchronous: synchronous, timeout: timeout)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func pause() async {
|
public func pause() async {
|
||||||
await runWithReload(verb: "pause", successMessage: "Curator paused") {
|
await runAndReload(args: ["curator", "pause"], successMessage: "Curator paused")
|
||||||
try await self.service.pause()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func resume() async {
|
public func resume() async {
|
||||||
await runWithReload(verb: "resume", successMessage: "Curator resumed") {
|
await runAndReload(args: ["curator", "resume"], successMessage: "Curator resumed")
|
||||||
try await self.service.resume()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func pin(_ skill: String) async {
|
public func pin(_ skill: String) async {
|
||||||
await runWithReload(verb: "pin", successMessage: "Pinned \(skill)") {
|
await runAndReload(args: ["curator", "pin", skill], successMessage: "Pinned \(skill)")
|
||||||
try await self.service.pin(skill)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func unpin(_ skill: String) async {
|
public func unpin(_ skill: String) async {
|
||||||
await runWithReload(verb: "unpin", successMessage: "Unpinned \(skill)") {
|
await runAndReload(args: ["curator", "unpin", skill], successMessage: "Unpinned \(skill)")
|
||||||
try await self.service.unpin(skill)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func restore(_ skill: String) async {
|
public func restore(_ skill: String) async {
|
||||||
await runWithReload(verb: "restore", successMessage: "Restored \(skill)") {
|
await runAndReload(args: ["curator", "restore", skill], successMessage: "Restored \(skill)")
|
||||||
try await self.service.restore(skill)
|
|
||||||
}
|
|
||||||
// Restore drops the entry from the archived list — refresh it
|
|
||||||
// so the row disappears immediately.
|
|
||||||
await loadArchive()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Writes (v0.13)
|
private func runAndReload(args: [String], successMessage: String) async {
|
||||||
|
let context = self.context
|
||||||
public func archive(_ skill: String) async {
|
let exitCode = await Task.detached(priority: .userInitiated) {
|
||||||
pendingArchiveName = skill
|
Self.runHermes(context: context, args: args).exitCode
|
||||||
await runWithReload(verb: "archive", successMessage: "Archived \(skill)") {
|
}.value
|
||||||
try await self.service.archive(skill)
|
transientMessage = exitCode == 0 ? successMessage : "Command failed"
|
||||||
}
|
|
||||||
pendingArchiveName = nil
|
|
||||||
await loadArchive()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Stage 1 of the bulk-prune flow. Calls `prune --dry-run` and
|
|
||||||
/// populates `pruneSummary`; the View binds its confirm sheet to
|
|
||||||
/// the non-nil presence of this property.
|
|
||||||
public func planPrune() async {
|
|
||||||
do {
|
|
||||||
pruneSummary = try await service.prune(dryRun: true)
|
|
||||||
} catch {
|
|
||||||
errorMessage = (error as? LocalizedError)?.errorDescription
|
|
||||||
?? error.localizedDescription
|
|
||||||
pruneSummary = nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Stage 2 of the bulk-prune flow. Destructive — removes everything
|
|
||||||
/// currently archived. Clears `pruneSummary` regardless of outcome
|
|
||||||
/// so the confirm sheet dismisses.
|
|
||||||
public func confirmPrune() async {
|
|
||||||
isPruning = true
|
|
||||||
do {
|
|
||||||
_ = try await service.prune(dryRun: false)
|
|
||||||
transientMessage = "Pruned archived skills"
|
|
||||||
errorMessage = nil
|
|
||||||
await loadArchive()
|
|
||||||
await load()
|
await load()
|
||||||
scheduleTransientClear()
|
// Auto-clear toast after 3s.
|
||||||
} catch {
|
|
||||||
errorMessage = (error as? LocalizedError)?.errorDescription
|
|
||||||
?? error.localizedDescription
|
|
||||||
}
|
|
||||||
isPruning = false
|
|
||||||
pruneSummary = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Cancel the in-flight prune-confirm flow without running.
|
|
||||||
public func cancelPrune() {
|
|
||||||
pruneSummary = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
/// User-driven dismissal of the inline error banner.
|
|
||||||
public func dismissError() {
|
|
||||||
errorMessage = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Helpers
|
|
||||||
|
|
||||||
/// Run a service call, route success → `transientMessage`, failure
|
|
||||||
/// → `errorMessage`, and reload `status` either way. Mirrors the
|
|
||||||
/// previous `runAndReload` helper but goes through the typed
|
|
||||||
/// service surface.
|
|
||||||
private func runWithReload(
|
|
||||||
verb: String,
|
|
||||||
successMessage: String,
|
|
||||||
body: @escaping @Sendable () async throws -> Void
|
|
||||||
) async {
|
|
||||||
do {
|
|
||||||
try await body()
|
|
||||||
transientMessage = successMessage
|
|
||||||
errorMessage = nil
|
|
||||||
await load()
|
|
||||||
scheduleTransientClear()
|
|
||||||
} catch {
|
|
||||||
let message = (error as? LocalizedError)?.errorDescription
|
|
||||||
?? error.localizedDescription
|
|
||||||
errorMessage = message
|
|
||||||
transientMessage = nil
|
|
||||||
await load()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private func scheduleTransientClear() {
|
|
||||||
Task { @MainActor [weak self] in
|
Task { @MainActor [weak self] in
|
||||||
try? await Task.sleep(nanoseconds: 3_000_000_000)
|
try? await Task.sleep(nanoseconds: 3_000_000_000)
|
||||||
self?.transientMessage = nil
|
self?.transientMessage = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Legacy sync helpers (kept for `load`'s detached path)
|
/// Wrap the transport-level `runProcess` so the call sites don't
|
||||||
|
/// have to reach for it directly. Combined stdout+stderr.
|
||||||
nonisolated private static func runHermes(
|
nonisolated private static func runHermes(
|
||||||
context: ServerContext,
|
context: ServerContext,
|
||||||
args: [String]
|
args: [String]
|
||||||
|
|||||||
@@ -229,6 +229,12 @@ public final class RichChatViewModel {
|
|||||||
public private(set) var acpOutputTokens = 0
|
public private(set) var acpOutputTokens = 0
|
||||||
public private(set) var acpThoughtTokens = 0
|
public private(set) var acpThoughtTokens = 0
|
||||||
public private(set) var acpCachedReadTokens = 0
|
public private(set) var acpCachedReadTokens = 0
|
||||||
|
/// Running count of context compactions Hermes has performed on this
|
||||||
|
/// session. Surfaced as the `🗜 ×N` chip in `SessionInfoBar` when > 0
|
||||||
|
/// and `HermesCapabilities.hasContextCompressionCount` is true. Each
|
||||||
|
/// `session/prompt` response carries the latest server-side total, so
|
||||||
|
/// we replace (with a `max` guard) rather than accumulate.
|
||||||
|
public private(set) var acpCompressionCount = 0
|
||||||
|
|
||||||
/// Slash commands advertised by the ACP server via `available_commands_update`.
|
/// Slash commands advertised by the ACP server via `available_commands_update`.
|
||||||
public private(set) var acpCommands: [HermesSlashCommand] = []
|
public private(set) var acpCommands: [HermesSlashCommand] = []
|
||||||
@@ -468,6 +474,7 @@ public final class RichChatViewModel {
|
|||||||
acpErrorHint = nil
|
acpErrorHint = nil
|
||||||
acpErrorDetails = nil
|
acpErrorDetails = nil
|
||||||
acpCachedReadTokens = 0
|
acpCachedReadTokens = 0
|
||||||
|
acpCompressionCount = 0
|
||||||
acpCommands = []
|
acpCommands = []
|
||||||
projectScopedCommands = []
|
projectScopedCommands = []
|
||||||
currentTurnStart = nil
|
currentTurnStart = nil
|
||||||
@@ -811,6 +818,13 @@ public final class RichChatViewModel {
|
|||||||
acpOutputTokens += response.outputTokens
|
acpOutputTokens += response.outputTokens
|
||||||
acpThoughtTokens += response.thoughtTokens
|
acpThoughtTokens += response.thoughtTokens
|
||||||
acpCachedReadTokens += response.cachedReadTokens
|
acpCachedReadTokens += response.cachedReadTokens
|
||||||
|
// Compression count is a session-wide running total emitted by
|
||||||
|
// Hermes; each prompt response carries the latest value, so we
|
||||||
|
// replace rather than accumulate. The `max` guard tolerates
|
||||||
|
// pre-v0.13 hosts (which emit 0) being upgraded server-side
|
||||||
|
// mid-session — once a real number lands the count resumes from
|
||||||
|
// there rather than snapping back to 0.
|
||||||
|
acpCompressionCount = max(acpCompressionCount, response.compressionCount)
|
||||||
isAgentWorking = false
|
isAgentWorking = false
|
||||||
buildMessageGroups()
|
buildMessageGroups()
|
||||||
// Final position after the prompt settles. Catches fast responses
|
// Final position after the prompt settles. Catches fast responses
|
||||||
|
|||||||
@@ -151,169 +151,4 @@ import Foundation
|
|||||||
#expect(parsed?.patchCount == 2)
|
#expect(parsed?.patchCount == 2)
|
||||||
#expect(parsed?.lastActivityLabel == "2026-04-25")
|
#expect(parsed?.lastActivityLabel == "2026-04-25")
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - v0.13 list-archived / prune fixtures (WS-4)
|
|
||||||
|
|
||||||
/// Empty JSON array → `[]`. Locks in the happy-path no-archives shape.
|
|
||||||
@Test func listArchivedEmpty() throws {
|
|
||||||
let result = try CuratorService.parseListArchived(stdout: "[]")
|
|
||||||
#expect(result.isEmpty)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Three archives with full optional fields. Asserts each
|
|
||||||
/// optional value decodes through `decodeIfPresent` and that
|
|
||||||
/// the computed labels resolve.
|
|
||||||
@Test func listArchivedThreeSkills() throws {
|
|
||||||
let json = """
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"name": "legacy-helper",
|
|
||||||
"category": "templates",
|
|
||||||
"archived_at": "2026-04-22T03:14:09Z",
|
|
||||||
"reason": "stale: 91d unused",
|
|
||||||
"size_bytes": 4521,
|
|
||||||
"path": "/Users/u/.hermes/skills/.archived/legacy-helper"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "old-translator",
|
|
||||||
"category": "user",
|
|
||||||
"archived_at": "2026-04-23T10:00:00Z",
|
|
||||||
"reason": "consolidated with translator",
|
|
||||||
"size_bytes": 8192
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "minimal"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
"""
|
|
||||||
let result = try CuratorService.parseListArchived(stdout: json)
|
|
||||||
#expect(result.count == 3)
|
|
||||||
#expect(result[0].name == "legacy-helper")
|
|
||||||
#expect(result[0].category == "templates")
|
|
||||||
#expect(result[0].reason == "stale: 91d unused")
|
|
||||||
#expect(result[0].sizeBytes == 4521)
|
|
||||||
#expect(result[0].archivedAtLabel == "2026-04-22")
|
|
||||||
#expect(result[0].path == "/Users/u/.hermes/skills/.archived/legacy-helper")
|
|
||||||
|
|
||||||
// Tolerant: only `name` set on the third row.
|
|
||||||
#expect(result[2].name == "minimal")
|
|
||||||
#expect(result[2].category == nil)
|
|
||||||
#expect(result[2].reason == nil)
|
|
||||||
#expect(result[2].archivedAtLabel == "—")
|
|
||||||
#expect(result[2].sizeLabel == "—")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `{"archived": [...]}` envelope is also accepted.
|
|
||||||
@Test func listArchivedEnvelope() throws {
|
|
||||||
let json = """
|
|
||||||
{"archived": [
|
|
||||||
{"name": "envelope-skill", "size_bytes": 1024}
|
|
||||||
]}
|
|
||||||
"""
|
|
||||||
let result = try CuratorService.parseListArchived(stdout: json)
|
|
||||||
#expect(result.count == 1)
|
|
||||||
#expect(result[0].name == "envelope-skill")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Text fallback when `--json` isn't supported. Each row carries
|
|
||||||
/// the name in column 1 plus k=v chips for the optional fields.
|
|
||||||
@Test func listArchivedTextFallback() {
|
|
||||||
let text = """
|
|
||||||
legacy-helper archived=2026-04-22 size=4521 reason=stale
|
|
||||||
old-translator archived=2026-04-23 size=8192
|
|
||||||
minimal-row
|
|
||||||
"""
|
|
||||||
let result = CuratorService.parseListArchivedText(text)
|
|
||||||
#expect(result.count == 3)
|
|
||||||
#expect(result[0].name == "legacy-helper")
|
|
||||||
#expect(result[0].archivedAt == "2026-04-22")
|
|
||||||
#expect(result[0].sizeBytes == 4521)
|
|
||||||
#expect(result[0].reason == "stale")
|
|
||||||
#expect(result[2].name == "minimal-row")
|
|
||||||
#expect(result[2].sizeBytes == nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Empty-state sentinel folds to `[]` (parallel to KanbanService's
|
|
||||||
/// `"no matching tasks"` handling).
|
|
||||||
@Test func listArchivedNoArchivedSentinel() throws {
|
|
||||||
let result = try CuratorService.parseListArchived(stdout: "no archived skills\n")
|
|
||||||
#expect(result.isEmpty)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whitespace-only stdout also folds to empty.
|
|
||||||
@Test func listArchivedWhitespaceFoldsToEmpty() throws {
|
|
||||||
let result = try CuratorService.parseListArchived(stdout: " \n\n")
|
|
||||||
#expect(result.isEmpty)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Decode failure (clearly non-JSON, non-text) throws. We accept
|
|
||||||
/// JSON, the envelope, the empty sentinel, or text rows; anything
|
|
||||||
/// else surfaces as a `CuratorError.decoding`.
|
|
||||||
@Test func listArchivedNonsenseThrows() throws {
|
|
||||||
do {
|
|
||||||
_ = try CuratorService.parseListArchived(stdout: "{garbage")
|
|
||||||
Issue.record("expected decoding throw")
|
|
||||||
} catch let error as CuratorError {
|
|
||||||
if case .decoding = error {
|
|
||||||
// expected
|
|
||||||
} else {
|
|
||||||
Issue.record("unexpected error \(error)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Prune-dry-run JSON with `would_remove` + `total_bytes`.
|
|
||||||
@Test func pruneDryRunHappyPath() {
|
|
||||||
let json = """
|
|
||||||
{
|
|
||||||
"would_remove": [
|
|
||||||
{"name": "stale-a", "size_bytes": 1000},
|
|
||||||
{"name": "stale-b", "size_bytes": 2000}
|
|
||||||
],
|
|
||||||
"total_bytes": 3000
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
let summary = CuratorService.parsePruneDryRun(json)
|
|
||||||
#expect(summary.totalCount == 2)
|
|
||||||
#expect(summary.totalBytes == 3000)
|
|
||||||
#expect(summary.wouldRemove.first?.name == "stale-a")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Zero-skill prune is a valid dry-run (no archives).
|
|
||||||
@Test func pruneDryRunZeroSkills() {
|
|
||||||
let json = """
|
|
||||||
{"would_remove": [], "total_bytes": 0}
|
|
||||||
"""
|
|
||||||
let summary = CuratorService.parsePruneDryRun(json)
|
|
||||||
#expect(summary.totalCount == 0)
|
|
||||||
#expect(summary.totalBytes == 0)
|
|
||||||
#expect(summary.totalBytesLabel == "—")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Bare-array fallback: some Hermes builds may print just the
|
|
||||||
/// would-remove list when the wrapper is missing.
|
|
||||||
@Test func pruneDryRunBareArrayFallback() {
|
|
||||||
let json = """
|
|
||||||
[{"name": "lonely", "size_bytes": 500}]
|
|
||||||
"""
|
|
||||||
let summary = CuratorService.parsePruneDryRun(json)
|
|
||||||
#expect(summary.totalCount == 1)
|
|
||||||
#expect(summary.totalBytes == 500)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Empty / whitespace stdout → zero summary (no decoding throw).
|
|
||||||
@Test func pruneDryRunEmptyStaysSafe() {
|
|
||||||
let summary = CuratorService.parsePruneDryRun(" \n")
|
|
||||||
#expect(summary.totalCount == 0)
|
|
||||||
#expect(summary.totalBytes == 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Verify the size label uses the byte formatter (not raw bytes).
|
|
||||||
@Test func archivedSkillSizeLabelFormats() {
|
|
||||||
let big = HermesCuratorArchivedSkill(name: "x", sizeBytes: 1_500_000)
|
|
||||||
// ByteCountFormatter produces a localized label; just verify
|
|
||||||
// it's non-empty and not raw "1500000".
|
|
||||||
#expect(!big.sizeLabel.isEmpty)
|
|
||||||
#expect(big.sizeLabel != "1500000")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,6 +162,47 @@ import Foundation
|
|||||||
// start → false.
|
// start → false.
|
||||||
#expect(vm.supportsCompress == false)
|
#expect(vm.supportsCompress == false)
|
||||||
#expect(vm.hasBroaderCommandMenu == false)
|
#expect(vm.hasBroaderCommandMenu == false)
|
||||||
|
// v0.13: compression count starts at 0 so the SessionInfoBar chip
|
||||||
|
// stays hidden on fresh sessions.
|
||||||
|
#expect(vm.acpCompressionCount == 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test @MainActor func richChatTracksCompressionCountFromPromptResults() {
|
||||||
|
let vm = RichChatViewModel(context: .local)
|
||||||
|
let response = ACPPromptResult(
|
||||||
|
stopReason: "end_turn",
|
||||||
|
inputTokens: 100, outputTokens: 50,
|
||||||
|
thoughtTokens: 20, cachedReadTokens: 10,
|
||||||
|
compressionCount: 3
|
||||||
|
)
|
||||||
|
vm.handleACPEvent(.promptComplete(sessionId: "s", response: response))
|
||||||
|
#expect(vm.acpCompressionCount == 3)
|
||||||
|
|
||||||
|
// Subsequent prompts overwrite (with a max guard) — the server
|
||||||
|
// emits a session-wide running total, not a per-prompt delta.
|
||||||
|
let next = ACPPromptResult(
|
||||||
|
stopReason: "end_turn",
|
||||||
|
inputTokens: 0, outputTokens: 0,
|
||||||
|
thoughtTokens: 0, cachedReadTokens: 0,
|
||||||
|
compressionCount: 5
|
||||||
|
)
|
||||||
|
vm.handleACPEvent(.promptComplete(sessionId: "s", response: next))
|
||||||
|
#expect(vm.acpCompressionCount == 5)
|
||||||
|
|
||||||
|
// A pre-v0.13 host mid-session emits 0; the max-guard keeps the
|
||||||
|
// last real value rather than snapping back.
|
||||||
|
let stale = ACPPromptResult(
|
||||||
|
stopReason: "end_turn",
|
||||||
|
inputTokens: 0, outputTokens: 0,
|
||||||
|
thoughtTokens: 0, cachedReadTokens: 0,
|
||||||
|
compressionCount: 0
|
||||||
|
)
|
||||||
|
vm.handleACPEvent(.promptComplete(sessionId: "s", response: stale))
|
||||||
|
#expect(vm.acpCompressionCount == 5)
|
||||||
|
|
||||||
|
// reset() clears the counter so a fresh session starts clean.
|
||||||
|
vm.reset()
|
||||||
|
#expect(vm.acpCompressionCount == 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test @MainActor func messageGroupDerivedProperties() {
|
@Test @MainActor func messageGroupDerivedProperties() {
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
import Testing
|
||||||
|
import Foundation
|
||||||
|
@testable import ScarfCore
|
||||||
|
|
||||||
|
/// Pure-function matrix for `HermesUpdaterCommandBuilder.updateArgv`. The
|
||||||
|
/// builder degrades flags silently when the connected host can't honor
|
||||||
|
/// them, so the "is the right flag emitted on the right version?" matrix
|
||||||
|
/// is the meaningful test surface.
|
||||||
|
@Suite struct M0eUpdaterTests {
|
||||||
|
|
||||||
|
// MARK: - Helpers
|
||||||
|
|
||||||
|
private func caps(_ versionLine: String?) -> HermesCapabilities {
|
||||||
|
guard let line = versionLine else { return .empty }
|
||||||
|
return HermesCapabilities.parseLine(line)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Pre-v0.12 (no flags supported)
|
||||||
|
|
||||||
|
@Test func preV012_returnsBareUpdateRegardlessOfFlags() {
|
||||||
|
let pre = caps("Hermes Agent v0.11.0 (2026.4.23)")
|
||||||
|
#expect(HermesUpdaterCommandBuilder.updateArgv(
|
||||||
|
capabilities: pre, unattended: false, checkOnly: false
|
||||||
|
) == ["update"])
|
||||||
|
#expect(HermesUpdaterCommandBuilder.updateArgv(
|
||||||
|
capabilities: pre, unattended: true, checkOnly: false
|
||||||
|
) == ["update"])
|
||||||
|
#expect(HermesUpdaterCommandBuilder.updateArgv(
|
||||||
|
capabilities: pre, unattended: true, checkOnly: true
|
||||||
|
) == ["update"])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func unknownVersion_returnsBareUpdate() {
|
||||||
|
// No detected version means we can't guarantee any flag is
|
||||||
|
// honored; defensively emit the bare verb.
|
||||||
|
#expect(HermesUpdaterCommandBuilder.updateArgv(
|
||||||
|
capabilities: .empty, unattended: true, checkOnly: true
|
||||||
|
) == ["update"])
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - v0.12 (--check supported, --yes is not)
|
||||||
|
|
||||||
|
@Test func v012_checkOnly_emitsCheckFlag() {
|
||||||
|
let v012 = caps("Hermes Agent v0.12.0 (2026.4.30)")
|
||||||
|
#expect(HermesUpdaterCommandBuilder.updateArgv(
|
||||||
|
capabilities: v012, unattended: false, checkOnly: true
|
||||||
|
) == ["update", "--check"])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func v012_unattended_dropsYesFlag() {
|
||||||
|
// v0.12 doesn't honor --yes; the helper degrades silently.
|
||||||
|
let v012 = caps("Hermes Agent v0.12.0 (2026.4.30)")
|
||||||
|
#expect(HermesUpdaterCommandBuilder.updateArgv(
|
||||||
|
capabilities: v012, unattended: true, checkOnly: false
|
||||||
|
) == ["update"])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func v012_checkOnlyAndUnattended_emitsOnlyCheck() {
|
||||||
|
let v012 = caps("Hermes Agent v0.12.0 (2026.4.30)")
|
||||||
|
#expect(HermesUpdaterCommandBuilder.updateArgv(
|
||||||
|
capabilities: v012, unattended: true, checkOnly: true
|
||||||
|
) == ["update", "--check"])
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - v0.13 (full flag support)
|
||||||
|
|
||||||
|
@Test func v013_unattended_emitsYesFlag() {
|
||||||
|
let v013 = caps("Hermes Agent v0.13.0 (2026.5.7)")
|
||||||
|
#expect(HermesUpdaterCommandBuilder.updateArgv(
|
||||||
|
capabilities: v013, unattended: true, checkOnly: false
|
||||||
|
) == ["update", "--yes"])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func v013_checkOnlyAndUnattended_emitsBothFlags() {
|
||||||
|
let v013 = caps("Hermes Agent v0.13.0 (2026.5.7)")
|
||||||
|
#expect(HermesUpdaterCommandBuilder.updateArgv(
|
||||||
|
capabilities: v013, unattended: true, checkOnly: true
|
||||||
|
) == ["update", "--check", "--yes"])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func v013_neither_emitsBareUpdate() {
|
||||||
|
let v013 = caps("Hermes Agent v0.13.0 (2026.5.7)")
|
||||||
|
#expect(HermesUpdaterCommandBuilder.updateArgv(
|
||||||
|
capabilities: v013, unattended: false, checkOnly: false
|
||||||
|
) == ["update"])
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -242,6 +242,15 @@ import Foundation
|
|||||||
thoughtTokens: 20, cachedReadTokens: 10
|
thoughtTokens: 20, cachedReadTokens: 10
|
||||||
)
|
)
|
||||||
#expect(prompt.stopReason == "end_turn")
|
#expect(prompt.stopReason == "end_turn")
|
||||||
|
// v0.13: compressionCount has a 0 default for legacy callers.
|
||||||
|
#expect(prompt.compressionCount == 0)
|
||||||
|
|
||||||
|
let v013Prompt = ACPPromptResult(
|
||||||
|
stopReason: "end_turn", inputTokens: 0, outputTokens: 0,
|
||||||
|
thoughtTokens: 0, cachedReadTokens: 0,
|
||||||
|
compressionCount: 7
|
||||||
|
)
|
||||||
|
#expect(v013Prompt.compressionCount == 7)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test func projectDashboardInitChain() {
|
@Test func projectDashboardInitChain() {
|
||||||
|
|||||||
@@ -13,24 +13,11 @@ import ScarfDesign
|
|||||||
/// `HermesCapabilities.hasCurator` is true.
|
/// `HermesCapabilities.hasCurator` is true.
|
||||||
struct CuratorView: View {
|
struct CuratorView: View {
|
||||||
@State private var viewModel: CuratorViewModel
|
@State private var viewModel: CuratorViewModel
|
||||||
@Environment(\.hermesCapabilities) private var capabilitiesStore
|
|
||||||
|
|
||||||
// TODO(WS-9): add a read-only "Archived" section mirroring the Mac
|
|
||||||
// surface (no per-row Restore/Prune mutations on iOS in this
|
|
||||||
// release). Gate on `capabilitiesStore?.capabilities.hasCuratorArchive`.
|
|
||||||
|
|
||||||
init(context: ServerContext) {
|
init(context: ServerContext) {
|
||||||
_viewModel = State(initialValue: CuratorViewModel(context: context))
|
_viewModel = State(initialValue: CuratorViewModel(context: context))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether the connected host runs curator synchronously. Threaded
|
|
||||||
/// into `runNow` so v0.13+ hosts block-with-spinner; pre-v0.13 fire
|
|
||||||
/// and forget. WS-9 will surface a richer iOS progress affordance
|
|
||||||
/// alongside the read-only Archived section.
|
|
||||||
private var archiveAvailable: Bool {
|
|
||||||
capabilitiesStore?.capabilities.hasCuratorArchive ?? false
|
|
||||||
}
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
List {
|
List {
|
||||||
Section {
|
Section {
|
||||||
@@ -128,7 +115,7 @@ struct CuratorView: View {
|
|||||||
private var actionFooter: some View {
|
private var actionFooter: some View {
|
||||||
HStack(spacing: 8) {
|
HStack(spacing: 8) {
|
||||||
Button {
|
Button {
|
||||||
Task { await viewModel.runNow(synchronous: archiveAvailable, timeout: 600) }
|
Task { await viewModel.runNow() }
|
||||||
} label: {
|
} label: {
|
||||||
Label("Run now", systemImage: "play.fill")
|
Label("Run now", systemImage: "play.fill")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,7 +84,11 @@ struct HermesFileService: Sendable {
|
|||||||
inlineDiffs: bool("display.inline_diffs", default: true),
|
inlineDiffs: bool("display.inline_diffs", default: true),
|
||||||
toolProgressCommand: bool("display.tool_progress_command", default: false),
|
toolProgressCommand: bool("display.tool_progress_command", default: false),
|
||||||
toolPreviewLength: int("display.tool_preview_length", default: 0),
|
toolPreviewLength: int("display.tool_preview_length", default: 0),
|
||||||
busyInputMode: str("display.busy_input_mode", default: "interrupt")
|
busyInputMode: str("display.busy_input_mode", default: "interrupt"),
|
||||||
|
// v0.13: empty default means "key absent — agent uses its own
|
||||||
|
// default" (English). The picker writes a real value when the
|
||||||
|
// user explicitly chooses one.
|
||||||
|
language: str("display.language", default: "")
|
||||||
)
|
)
|
||||||
|
|
||||||
let terminal = TerminalSettings(
|
let terminal = TerminalSettings(
|
||||||
@@ -131,7 +135,12 @@ struct HermesFileService: Sendable {
|
|||||||
sttLocalModel: str("stt.local.model", default: "base"),
|
sttLocalModel: str("stt.local.model", default: "base"),
|
||||||
sttLocalLanguage: str("stt.local.language"),
|
sttLocalLanguage: str("stt.local.language"),
|
||||||
sttOpenAIModel: str("stt.openai.model", default: "whisper-1"),
|
sttOpenAIModel: str("stt.openai.model", default: "whisper-1"),
|
||||||
sttMistralModel: str("stt.mistral.model", default: "voxtral-mini-latest")
|
sttMistralModel: str("stt.mistral.model", default: "voxtral-mini-latest"),
|
||||||
|
// TODO(WS-8-Q2): Verify key names. Mirroring the elevenlabs
|
||||||
|
// shape (`<provider>.voice_id` + `<provider>.model`); v0.13
|
||||||
|
// source might use `tts.xai.voice` or `tts.xai.model_id`.
|
||||||
|
ttsXAIVoiceID: str("tts.xai.voice_id"),
|
||||||
|
ttsXAIModel: str("tts.xai.model")
|
||||||
)
|
)
|
||||||
|
|
||||||
func aux(_ name: String) -> AuxiliaryModel {
|
func aux(_ name: String) -> AuxiliaryModel {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ struct ChatTranscriptPane: View {
|
|||||||
@Bindable var chatViewModel: ChatViewModel
|
@Bindable var chatViewModel: ChatViewModel
|
||||||
var onSend: (String, [ChatImageAttachment]) -> Void
|
var onSend: (String, [ChatImageAttachment]) -> Void
|
||||||
var isEnabled: Bool
|
var isEnabled: Bool
|
||||||
|
@Environment(\.hermesCapabilities) private var capabilitiesStore
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(spacing: 0) {
|
VStack(spacing: 0) {
|
||||||
@@ -20,8 +21,10 @@ struct ChatTranscriptPane: View {
|
|||||||
acpInputTokens: richChat.acpInputTokens,
|
acpInputTokens: richChat.acpInputTokens,
|
||||||
acpOutputTokens: richChat.acpOutputTokens,
|
acpOutputTokens: richChat.acpOutputTokens,
|
||||||
acpThoughtTokens: richChat.acpThoughtTokens,
|
acpThoughtTokens: richChat.acpThoughtTokens,
|
||||||
|
acpCompressionCount: richChat.acpCompressionCount,
|
||||||
projectName: chatViewModel.currentProjectName,
|
projectName: chatViewModel.currentProjectName,
|
||||||
gitBranch: chatViewModel.currentGitBranch
|
gitBranch: chatViewModel.currentGitBranch,
|
||||||
|
capabilities: capabilitiesStore?.capabilities ?? .empty
|
||||||
)
|
)
|
||||||
Divider()
|
Divider()
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,11 @@ struct SessionInfoBar: View {
|
|||||||
var acpInputTokens: Int = 0
|
var acpInputTokens: Int = 0
|
||||||
var acpOutputTokens: Int = 0
|
var acpOutputTokens: Int = 0
|
||||||
var acpThoughtTokens: Int = 0
|
var acpThoughtTokens: Int = 0
|
||||||
|
/// Number of context compactions Hermes has run on this session. v0.13+
|
||||||
|
/// surface — capability-gated by the bar so pre-v0.13 hosts never see
|
||||||
|
/// the chip even if a stale value somehow trickles through. Defaults
|
||||||
|
/// to 0 so existing callers and previews don't need to be updated.
|
||||||
|
var acpCompressionCount: Int = 0
|
||||||
/// Name of the Scarf project this session is attributed to, when
|
/// Name of the Scarf project this session is attributed to, when
|
||||||
/// applicable. Nil for plain global chats. Drives the folder-chip
|
/// applicable. Nil for plain global chats. Drives the folder-chip
|
||||||
/// indicator rendered before the session title. Resolved by
|
/// indicator rendered before the session title. Resolved by
|
||||||
@@ -20,6 +25,11 @@ struct SessionInfoBar: View {
|
|||||||
/// name. Nil for non-project chats and for projects that aren't
|
/// name. Nil for non-project chats and for projects that aren't
|
||||||
/// git repos.
|
/// git repos.
|
||||||
var gitBranch: String? = nil
|
var gitBranch: String? = nil
|
||||||
|
/// Capability snapshot for v0.13+ surfaces. Defaulted so previews and
|
||||||
|
/// pre-v0.13 hosts render the v2.7.5 layout unchanged. Coordinated
|
||||||
|
/// with WS-2 — both WSes add `capabilities` to this view; whichever
|
||||||
|
/// lands first establishes the prop.
|
||||||
|
var capabilities: HermesCapabilities = .empty
|
||||||
|
|
||||||
/// Active Hermes profile name (issue #50). Resolved on each body
|
/// Active Hermes profile name (issue #50). Resolved on each body
|
||||||
/// re-evaluation; the resolver caches for 5s so this is cheap.
|
/// re-evaluation; the resolver caches for 5s so this is cheap.
|
||||||
@@ -96,6 +106,21 @@ struct SessionInfoBar: View {
|
|||||||
Label("\(formatTokens(reasonToks)) reasoning", systemImage: "brain")
|
Label("\(formatTokens(reasonToks)) reasoning", systemImage: "brain")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// v0.13: Hermes surfaces a running count of automatic
|
||||||
|
// context compactions. Render only when the host is on
|
||||||
|
// v0.13+ AND the count is non-zero, so a pre-v0.13 host
|
||||||
|
// (which always reports 0) sees no chip, and a v0.13 host
|
||||||
|
// sees the chip the first time the agent compacts.
|
||||||
|
if capabilities.hasContextCompressionCount && acpCompressionCount > 0 {
|
||||||
|
Label(
|
||||||
|
"×\(acpCompressionCount)",
|
||||||
|
systemImage: "arrow.down.right.and.arrow.up.left"
|
||||||
|
)
|
||||||
|
.scarfStyle(.caption)
|
||||||
|
.foregroundStyle(ScarfColor.foregroundMuted)
|
||||||
|
.help("Hermes auto-compacted this session's context \(acpCompressionCount) time\(acpCompressionCount == 1 ? "" : "s")")
|
||||||
|
}
|
||||||
|
|
||||||
if let cost = session.displayCostUSD {
|
if let cost = session.displayCostUSD {
|
||||||
let formattedCost = cost.formatted(.currency(code: "USD").precision(.fractionLength(4)))
|
let formattedCost = cost.formatted(.currency(code: "USD").precision(.fractionLength(4)))
|
||||||
Label(session.costIsActual ? formattedCost : "\(formattedCost) est.", systemImage: "dollarsign.circle")
|
Label(session.costIsActual ? formattedCost : "\(formattedCost) est.", systemImage: "dollarsign.circle")
|
||||||
|
|||||||
@@ -87,7 +87,16 @@ private struct SlashCommandRow: View {
|
|||||||
.fontWeight(.semibold)
|
.fontWeight(.semibold)
|
||||||
.foregroundStyle(isSelected ? ScarfColor.accentActive : ScarfColor.foregroundPrimary)
|
.foregroundStyle(isSelected ? ScarfColor.accentActive : ScarfColor.foregroundPrimary)
|
||||||
if let hint = command.argumentHint {
|
if let hint = command.argumentHint {
|
||||||
Text("<\(hint)>")
|
// v0.13: Hermes may emit hints already wrapped in
|
||||||
|
// brackets (e.g. `[name]` for the optional `/new
|
||||||
|
// <name>` argument exposed by `hasNewWithSessionName`).
|
||||||
|
// Avoid double-wrapping — bracketed hints pass through
|
||||||
|
// verbatim while older `guidance`-style hints (no
|
||||||
|
// brackets) still render as `<guidance>`.
|
||||||
|
let display = hint.hasPrefix("<") || hint.hasPrefix("[")
|
||||||
|
? hint
|
||||||
|
: "<\(hint)>"
|
||||||
|
Text(display)
|
||||||
.font(ScarfFont.monoSmall)
|
.font(ScarfFont.monoSmall)
|
||||||
.foregroundStyle(ScarfColor.foregroundFaint)
|
.foregroundStyle(ScarfColor.foregroundFaint)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,122 +0,0 @@
|
|||||||
import SwiftUI
|
|
||||||
import ScarfCore
|
|
||||||
import ScarfDesign
|
|
||||||
|
|
||||||
/// Mac sub-view rendered between the active-skill leaderboards and the
|
|
||||||
/// last-report block on Hermes v0.13+ hosts. Lists everything currently
|
|
||||||
/// archived (`hermes curator list-archived`) with per-row Restore + a
|
|
||||||
/// bulk Prune affordance routed through the parent's confirm sheet.
|
|
||||||
///
|
|
||||||
/// Empty-state copy explains what archive means — useful when the
|
|
||||||
/// curator hasn't run yet on a fresh install (no archives ≠ a problem).
|
|
||||||
struct CuratorArchivedSection: View {
|
|
||||||
let archived: [HermesCuratorArchivedSkill]
|
|
||||||
let isLoading: Bool
|
|
||||||
let onRestore: (String) -> Void
|
|
||||||
let onPruneAll: () -> Void
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
ScarfCard {
|
|
||||||
VStack(alignment: .leading, spacing: ScarfSpace.s2) {
|
|
||||||
header
|
|
||||||
if isLoading && archived.isEmpty {
|
|
||||||
loadingRow
|
|
||||||
} else if archived.isEmpty {
|
|
||||||
emptyState
|
|
||||||
} else {
|
|
||||||
rows
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private var header: some View {
|
|
||||||
HStack(alignment: .firstTextBaseline) {
|
|
||||||
ScarfSectionHeader("Archived")
|
|
||||||
Spacer()
|
|
||||||
Text("\(archived.count) skill\(archived.count == 1 ? "" : "s")")
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundMuted)
|
|
||||||
if !archived.isEmpty {
|
|
||||||
Button("Prune All…") {
|
|
||||||
onPruneAll()
|
|
||||||
}
|
|
||||||
.buttonStyle(ScarfDestructiveButton())
|
|
||||||
.help("Remove every archived skill from disk. Cannot be undone.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private var loadingRow: some View {
|
|
||||||
HStack(spacing: ScarfSpace.s2) {
|
|
||||||
ProgressView().controlSize(.small)
|
|
||||||
Text("Loading archived skills…")
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundMuted)
|
|
||||||
Spacer()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private var emptyState: some View {
|
|
||||||
VStack(alignment: .leading, spacing: ScarfSpace.s1) {
|
|
||||||
Text("No archived skills.")
|
|
||||||
.scarfStyle(.body)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundMuted)
|
|
||||||
Text("The curator moves stale or redundant skills here on its weekly review. Until then, this list stays empty.")
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundFaint)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private var rows: some View {
|
|
||||||
VStack(alignment: .leading, spacing: ScarfSpace.s1) {
|
|
||||||
ForEach(archived) { skill in
|
|
||||||
ArchivedSkillRow(
|
|
||||||
skill: skill,
|
|
||||||
onRestore: { onRestore(skill.name) }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private struct ArchivedSkillRow: View {
|
|
||||||
let skill: HermesCuratorArchivedSkill
|
|
||||||
let onRestore: () -> Void
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
HStack(alignment: .center, spacing: ScarfSpace.s2) {
|
|
||||||
Image(systemName: "archivebox.fill")
|
|
||||||
.font(.system(size: 12))
|
|
||||||
.foregroundStyle(ScarfColor.foregroundFaint)
|
|
||||||
VStack(alignment: .leading, spacing: 2) {
|
|
||||||
Text(skill.name)
|
|
||||||
.scarfStyle(.body)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundPrimary)
|
|
||||||
.lineLimit(1)
|
|
||||||
if let reason = skill.reason, !reason.isEmpty {
|
|
||||||
Text(reason)
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundMuted)
|
|
||||||
.lineLimit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
|
||||||
Text(skill.archivedAtLabel)
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundFaint)
|
|
||||||
.frame(width: 96, alignment: .trailing)
|
|
||||||
Text(skill.sizeLabel)
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundFaint)
|
|
||||||
.frame(width: 72, alignment: .trailing)
|
|
||||||
Button("Restore") {
|
|
||||||
onRestore()
|
|
||||||
}
|
|
||||||
.buttonStyle(ScarfPrimaryButton())
|
|
||||||
.controlSize(.small)
|
|
||||||
.help("Restore \(skill.name) to the active skill set")
|
|
||||||
}
|
|
||||||
.padding(.vertical, 2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,123 +0,0 @@
|
|||||||
import SwiftUI
|
|
||||||
import ScarfCore
|
|
||||||
import ScarfDesign
|
|
||||||
|
|
||||||
/// Destructive-confirm sheet for `hermes curator prune` (bulk).
|
|
||||||
///
|
|
||||||
/// Pattern matches `TemplateUninstallSheet`: enumerate every entry that
|
|
||||||
/// will be removed, surface the total count + bytes, and require an
|
|
||||||
/// explicit click on a red `ScarfDestructiveButton` ("Prune
|
|
||||||
/// permanently") before kicking off the destructive call. Cancel owns
|
|
||||||
/// the keyboard default action so an accidental Enter-press doesn't
|
|
||||||
/// nuke the archive.
|
|
||||||
struct CuratorPruneConfirmSheet: View {
|
|
||||||
@Environment(\.dismiss) private var dismiss
|
|
||||||
let summary: CuratorPruneSummary
|
|
||||||
let isPruning: Bool
|
|
||||||
let onConfirm: () -> Void
|
|
||||||
let onCancel: () -> Void
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
VStack(alignment: .leading, spacing: 0) {
|
|
||||||
header
|
|
||||||
.padding(.bottom, ScarfSpace.s2)
|
|
||||||
ScarfDivider()
|
|
||||||
ScrollView {
|
|
||||||
VStack(alignment: .leading, spacing: ScarfSpace.s2) {
|
|
||||||
ForEach(summary.wouldRemove) { skill in
|
|
||||||
row(skill: skill)
|
|
||||||
}
|
|
||||||
if summary.wouldRemove.isEmpty {
|
|
||||||
Text("Nothing currently archived. Nothing to prune.")
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundMuted)
|
|
||||||
.padding(.vertical, ScarfSpace.s2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding(.vertical, ScarfSpace.s2)
|
|
||||||
}
|
|
||||||
ScarfDivider()
|
|
||||||
footer
|
|
||||||
.padding(.top, ScarfSpace.s2)
|
|
||||||
}
|
|
||||||
.frame(minWidth: 520, minHeight: 380)
|
|
||||||
.padding(ScarfSpace.s4)
|
|
||||||
}
|
|
||||||
|
|
||||||
private var header: some View {
|
|
||||||
VStack(alignment: .leading, spacing: ScarfSpace.s1) {
|
|
||||||
HStack(alignment: .firstTextBaseline) {
|
|
||||||
Text("Prune Archived Skills")
|
|
||||||
.scarfStyle(.title2)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundPrimary)
|
|
||||||
Spacer()
|
|
||||||
if summary.totalCount > 0 {
|
|
||||||
ScarfBadge("\(summary.totalCount)", kind: .danger)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Text("This permanently deletes every archived skill from disk. Restoring an archived skill is no longer possible after pruning.")
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundMuted)
|
|
||||||
.fixedSize(horizontal: false, vertical: true)
|
|
||||||
if summary.totalBytes > 0 {
|
|
||||||
Text("Total to remove: \(summary.totalBytesLabel)")
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundFaint)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private func row(skill: HermesCuratorArchivedSkill) -> some View {
|
|
||||||
HStack(spacing: ScarfSpace.s2) {
|
|
||||||
Image(systemName: "minus.circle")
|
|
||||||
.foregroundStyle(ScarfColor.danger)
|
|
||||||
.font(.caption)
|
|
||||||
VStack(alignment: .leading, spacing: 2) {
|
|
||||||
Text(skill.name)
|
|
||||||
.scarfStyle(.body)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundPrimary)
|
|
||||||
.lineLimit(1)
|
|
||||||
if let reason = skill.reason, !reason.isEmpty {
|
|
||||||
Text(reason)
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundMuted)
|
|
||||||
.lineLimit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Spacer()
|
|
||||||
Text(skill.archivedAtLabel)
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundFaint)
|
|
||||||
.frame(width: 96, alignment: .trailing)
|
|
||||||
Text(skill.sizeLabel)
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundFaint)
|
|
||||||
.frame(width: 72, alignment: .trailing)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private var footer: some View {
|
|
||||||
HStack {
|
|
||||||
Button("Cancel") {
|
|
||||||
onCancel()
|
|
||||||
dismiss()
|
|
||||||
}
|
|
||||||
.buttonStyle(ScarfGhostButton())
|
|
||||||
// Cancel owns .defaultAction so accidental Enter-presses
|
|
||||||
// don't trigger the destructive button (template-uninstall
|
|
||||||
// pattern recommended in the WS-4 plan).
|
|
||||||
.keyboardShortcut(.defaultAction)
|
|
||||||
.disabled(isPruning)
|
|
||||||
Spacer()
|
|
||||||
if isPruning {
|
|
||||||
ProgressView().controlSize(.small)
|
|
||||||
}
|
|
||||||
Button("Prune permanently") {
|
|
||||||
onConfirm()
|
|
||||||
}
|
|
||||||
.buttonStyle(ScarfDestructiveButton())
|
|
||||||
.disabled(isPruning || summary.wouldRemove.isEmpty)
|
|
||||||
.accessibilityIdentifier("curatorPrune.confirm")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,16 +2,18 @@ import SwiftUI
|
|||||||
import ScarfCore
|
import ScarfCore
|
||||||
import ScarfDesign
|
import ScarfDesign
|
||||||
|
|
||||||
/// Legacy v0.12 fallback for restoring an archived skill by typed
|
/// Modal that lists archived skills (state ≠ active) and exposes a
|
||||||
/// name. Hermes v0.12 didn't ship `curator list-archived`, so the only
|
/// one-click "Restore" action per row. v0.12 archives are recoverable —
|
||||||
/// way to restore was to remember the skill name and pass it through
|
/// `hermes curator restore <name>` brings the skill back into
|
||||||
/// `hermes curator restore <name>`.
|
/// `~/.hermes/skills/<category>/<name>/` and re-marks it active.
|
||||||
///
|
///
|
||||||
/// **v0.13+ flow (preferred):** `CuratorArchivedSection` renders a
|
/// The Curator's `status` text doesn't enumerate archived skills with
|
||||||
/// per-skill list with a one-click Restore button per row — no typing
|
/// names; we surface what's available (counts + pinned list) and rely
|
||||||
/// required. This sheet stays reachable from the overflow menu only on
|
/// on the user knowing the names. Hermes ergo does an interactive
|
||||||
/// pre-v0.13 hosts (gated by `!hasCuratorArchive`). Don't delete this
|
/// `--name` arg if missing — but Scarf prefers explicit selection so
|
||||||
/// file even after WS-4 ships; v0.12 hosts still depend on it.
|
/// users don't have to remember names. For v2.6 we render a free-form
|
||||||
|
/// text field; once Hermes ships a `curator list-archived` (tracked
|
||||||
|
/// upstream), swap to a pickable list.
|
||||||
struct CuratorRestoreSheet: View {
|
struct CuratorRestoreSheet: View {
|
||||||
let viewModel: CuratorViewModel
|
let viewModel: CuratorViewModel
|
||||||
|
|
||||||
|
|||||||
@@ -2,52 +2,57 @@ import SwiftUI
|
|||||||
import ScarfCore
|
import ScarfCore
|
||||||
import ScarfDesign
|
import ScarfDesign
|
||||||
|
|
||||||
/// Mac UI for Hermes's autonomous skill curator (v0.12 base + v0.13
|
/// Mac UI for Hermes v0.12's autonomous skill curator.
|
||||||
/// archive/prune surface).
|
|
||||||
///
|
///
|
||||||
/// Surfaces the running state (enabled / paused / disabled), last-run
|
/// Surfaces the running state (enabled / paused / disabled), last-run
|
||||||
/// metadata, agent-created skill counts, the most/least-active /
|
/// metadata, agent-created skill counts, and the most/least-active /
|
||||||
/// least-recently-active leaderboards, and on v0.13+ hosts the new
|
/// least-recently-active leaderboards. Pin-and-restore actions hit
|
||||||
/// archived-skills section + per-row Archive button on each leaderboard
|
/// `hermes curator pin/unpin/restore` via CuratorViewModel.
|
||||||
/// entry. Pin / unpin / restore / archive / prune route through
|
|
||||||
/// CuratorViewModel → CuratorService.
|
|
||||||
///
|
///
|
||||||
/// Capability-gated upstream: AppCoordinator only wires the sidebar
|
/// Capability-gated upstream: AppCoordinator only wires the sidebar
|
||||||
/// item when `HermesCapabilities.hasCurator` is true. Archive surfaces
|
/// item when `HermesCapabilities.hasCurator` is true. This view assumes
|
||||||
/// gate independently on `hasCuratorArchive`; pre-v0.13 hosts see the
|
/// it's reachable on a v0.12+ host.
|
||||||
/// v2.7.x layout unchanged (legacy `CuratorRestoreSheet` reachable from
|
|
||||||
/// the overflow menu, no Archive section, fire-and-forget Run Now).
|
|
||||||
struct CuratorView: View {
|
struct CuratorView: View {
|
||||||
@State private var viewModel: CuratorViewModel
|
@State private var viewModel: CuratorViewModel
|
||||||
@State private var showRestoreSheet = false
|
@State private var showRestoreSheet = false
|
||||||
|
|
||||||
@Environment(\.hermesCapabilities) private var capabilitiesStore
|
|
||||||
|
|
||||||
init(context: ServerContext) {
|
init(context: ServerContext) {
|
||||||
_viewModel = State(initialValue: CuratorViewModel(context: context))
|
_viewModel = State(initialValue: CuratorViewModel(context: context))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Single source of truth for "v0.13 archive surface visible". Read
|
|
||||||
/// once in `body` and threaded into sub-views. Defensive default to
|
|
||||||
/// `false` so previews / smoke tests behave like a pre-v0.13 host.
|
|
||||||
private var archiveAvailable: Bool {
|
|
||||||
capabilitiesStore?.capabilities.hasCuratorArchive ?? false
|
|
||||||
}
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ScrollView {
|
ScrollView {
|
||||||
VStack(alignment: .leading, spacing: ScarfSpace.s4) {
|
VStack(alignment: .leading, spacing: ScarfSpace.s4) {
|
||||||
ScarfPageHeader(
|
ScarfPageHeader(
|
||||||
"Curator",
|
"Curator",
|
||||||
subtitle: archiveAvailable
|
subtitle: "Autonomous skill maintenance — Hermes v0.12+"
|
||||||
? "Autonomous skill maintenance — archive, prune, restore"
|
|
||||||
: "Autonomous skill maintenance — Hermes v0.12+"
|
|
||||||
) {
|
) {
|
||||||
headerActions
|
HStack(spacing: ScarfSpace.s2) {
|
||||||
|
if viewModel.isLoading {
|
||||||
|
ProgressView().controlSize(.small)
|
||||||
|
}
|
||||||
|
Button("Run Now") {
|
||||||
|
Task { await viewModel.runNow() }
|
||||||
|
}
|
||||||
|
.buttonStyle(ScarfPrimaryButton())
|
||||||
|
.disabled(viewModel.isLoading)
|
||||||
|
Menu {
|
||||||
|
switch viewModel.status.state {
|
||||||
|
case .paused:
|
||||||
|
Button("Resume") { Task { await viewModel.resume() } }
|
||||||
|
case .enabled:
|
||||||
|
Button("Pause") { Task { await viewModel.pause() } }
|
||||||
|
default:
|
||||||
|
EmptyView()
|
||||||
|
}
|
||||||
|
Button("Restore Archived…") {
|
||||||
|
showRestoreSheet = true
|
||||||
|
}
|
||||||
|
.disabled(viewModel.status.archivedSkills == 0)
|
||||||
|
} label: {
|
||||||
|
Image(systemName: "ellipsis.circle")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let errorMessage = viewModel.errorMessage {
|
|
||||||
errorBanner(errorMessage)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let toast = viewModel.transientMessage {
|
if let toast = viewModel.transientMessage {
|
||||||
@@ -59,19 +64,6 @@ struct CuratorView: View {
|
|||||||
pinnedSection
|
pinnedSection
|
||||||
activityTables
|
activityTables
|
||||||
|
|
||||||
if archiveAvailable {
|
|
||||||
CuratorArchivedSection(
|
|
||||||
archived: viewModel.archivedSkills,
|
|
||||||
isLoading: viewModel.isLoadingArchive,
|
|
||||||
onRestore: { name in
|
|
||||||
Task { await viewModel.restore(name) }
|
|
||||||
},
|
|
||||||
onPruneAll: {
|
|
||||||
Task { await viewModel.planPrune() }
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if let report = viewModel.lastReportMarkdown {
|
if let report = viewModel.lastReportMarkdown {
|
||||||
lastReportSection(markdown: report)
|
lastReportSection(markdown: report)
|
||||||
}
|
}
|
||||||
@@ -79,84 +71,10 @@ struct CuratorView: View {
|
|||||||
.padding(ScarfSpace.s4)
|
.padding(ScarfSpace.s4)
|
||||||
}
|
}
|
||||||
.background(ScarfColor.backgroundPrimary)
|
.background(ScarfColor.backgroundPrimary)
|
||||||
.task {
|
.task { await viewModel.load() }
|
||||||
await viewModel.load()
|
|
||||||
if archiveAvailable {
|
|
||||||
await viewModel.loadArchive()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.sheet(isPresented: $showRestoreSheet) {
|
.sheet(isPresented: $showRestoreSheet) {
|
||||||
CuratorRestoreSheet(viewModel: viewModel)
|
CuratorRestoreSheet(viewModel: viewModel)
|
||||||
}
|
}
|
||||||
.sheet(
|
|
||||||
isPresented: Binding(
|
|
||||||
get: { viewModel.pruneSummary != nil },
|
|
||||||
set: { isShown in
|
|
||||||
if !isShown { viewModel.cancelPrune() }
|
|
||||||
}
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
if let summary = viewModel.pruneSummary {
|
|
||||||
CuratorPruneConfirmSheet(
|
|
||||||
summary: summary,
|
|
||||||
isPruning: viewModel.isPruning,
|
|
||||||
onConfirm: {
|
|
||||||
Task { await viewModel.confirmPrune() }
|
|
||||||
},
|
|
||||||
onCancel: {
|
|
||||||
viewModel.cancelPrune()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ViewBuilder
|
|
||||||
private var headerActions: some View {
|
|
||||||
HStack(spacing: ScarfSpace.s2) {
|
|
||||||
if viewModel.isLoading {
|
|
||||||
ProgressView().controlSize(.small)
|
|
||||||
}
|
|
||||||
Button("Run Now") {
|
|
||||||
Task {
|
|
||||||
await viewModel.runNow(
|
|
||||||
synchronous: archiveAvailable,
|
|
||||||
timeout: 600
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.buttonStyle(ScarfPrimaryButton())
|
|
||||||
.disabled(viewModel.isLoading)
|
|
||||||
.help(archiveAvailable
|
|
||||||
? "Curator runs synchronously on Hermes v0.13+. Usually 10–90s."
|
|
||||||
: "Trigger a curator run. Returns immediately on pre-v0.13 hosts.")
|
|
||||||
|
|
||||||
Menu {
|
|
||||||
switch viewModel.status.state {
|
|
||||||
case .paused:
|
|
||||||
Button("Resume") { Task { await viewModel.resume() } }
|
|
||||||
case .enabled:
|
|
||||||
Button("Pause") { Task { await viewModel.pause() } }
|
|
||||||
default:
|
|
||||||
EmptyView()
|
|
||||||
}
|
|
||||||
|
|
||||||
if archiveAvailable {
|
|
||||||
Divider()
|
|
||||||
Button("Prune Archived…", role: .destructive) {
|
|
||||||
Task { await viewModel.planPrune() }
|
|
||||||
}
|
|
||||||
.disabled(viewModel.archivedSkills.isEmpty && !viewModel.isLoadingArchive)
|
|
||||||
} else {
|
|
||||||
Button("Restore Archived…") {
|
|
||||||
showRestoreSheet = true
|
|
||||||
}
|
|
||||||
.disabled(viewModel.status.archivedSkills == 0)
|
|
||||||
}
|
|
||||||
} label: {
|
|
||||||
Image(systemName: "ellipsis.circle")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var statusSummary: some View {
|
private var statusSummary: some View {
|
||||||
@@ -288,10 +206,6 @@ struct CuratorView: View {
|
|||||||
}
|
}
|
||||||
.buttonStyle(.plain)
|
.buttonStyle(.plain)
|
||||||
.help(viewModel.status.pinnedNames.contains(row.name) ? "Pinned" : "Pin skill")
|
.help(viewModel.status.pinnedNames.contains(row.name) ? "Pinned" : "Pin skill")
|
||||||
|
|
||||||
if archiveAvailable {
|
|
||||||
archiveButton(for: row.name)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.padding(.vertical, 2)
|
.padding(.vertical, 2)
|
||||||
}
|
}
|
||||||
@@ -299,25 +213,6 @@ struct CuratorView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
|
||||||
private func archiveButton(for name: String) -> some View {
|
|
||||||
if viewModel.pendingArchiveName == name {
|
|
||||||
ProgressView()
|
|
||||||
.controlSize(.small)
|
|
||||||
.frame(width: 14, height: 14)
|
|
||||||
} else {
|
|
||||||
Button {
|
|
||||||
Task { await viewModel.archive(name) }
|
|
||||||
} label: {
|
|
||||||
Image(systemName: "archivebox")
|
|
||||||
.font(.system(size: 12))
|
|
||||||
}
|
|
||||||
.buttonStyle(.plain)
|
|
||||||
.help("Archive (move out of active set)")
|
|
||||||
.disabled(viewModel.pendingArchiveName != nil)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private func counterChip(label: String, value: Int) -> some View {
|
private func counterChip(label: String, value: Int) -> some View {
|
||||||
Text("\(label) \(value)")
|
Text("\(label) \(value)")
|
||||||
.font(ScarfFont.monoSmall)
|
.font(ScarfFont.monoSmall)
|
||||||
@@ -382,35 +277,6 @@ struct CuratorView: View {
|
|||||||
.background(ScarfColor.accentTint)
|
.background(ScarfColor.accentTint)
|
||||||
.clipShape(RoundedRectangle(cornerRadius: ScarfRadius.md))
|
.clipShape(RoundedRectangle(cornerRadius: ScarfRadius.md))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Inline yellow banner for CLI failures. Non-blocking — sits above
|
|
||||||
/// the status summary and dismisses with the "x" so users can keep
|
|
||||||
/// interacting with the leaderboard. Mirrors the pattern in
|
|
||||||
/// KanbanBoardView.
|
|
||||||
private func errorBanner(_ message: String) -> some View {
|
|
||||||
HStack(alignment: .top, spacing: ScarfSpace.s2) {
|
|
||||||
Image(systemName: "exclamationmark.triangle.fill")
|
|
||||||
.foregroundStyle(ScarfColor.warning)
|
|
||||||
Text(message)
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundPrimary)
|
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
|
||||||
Button {
|
|
||||||
viewModel.dismissError()
|
|
||||||
} label: {
|
|
||||||
Image(systemName: "xmark.circle.fill")
|
|
||||||
.foregroundStyle(ScarfColor.foregroundMuted)
|
|
||||||
}
|
|
||||||
.buttonStyle(.plain)
|
|
||||||
.help("Dismiss")
|
|
||||||
}
|
|
||||||
.padding(.horizontal, ScarfSpace.s3)
|
|
||||||
.padding(.vertical, ScarfSpace.s2)
|
|
||||||
.background(
|
|
||||||
RoundedRectangle(cornerRadius: ScarfRadius.md)
|
|
||||||
.fill(ScarfColor.warning.opacity(0.12))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Simple `FlowLayout` for the pinned-skill chips. Custom layout
|
/// Simple `FlowLayout` for the pinned-skill chips. Custom layout
|
||||||
|
|||||||
@@ -29,8 +29,31 @@ final class SettingsViewModel {
|
|||||||
// that no-ops on older hosts is low compared to gating overhead.
|
// that no-ops on older hosts is low compared to gating overhead.
|
||||||
var terminalBackends = ["local", "docker", "singularity", "modal", "daytona", "ssh", "vercel"]
|
var terminalBackends = ["local", "docker", "singularity", "modal", "daytona", "ssh", "vercel"]
|
||||||
var browserBackends = ["browseruse", "firecrawl", "local"]
|
var browserBackends = ["browseruse", "firecrawl", "local"]
|
||||||
var ttsProviders = ["edge", "elevenlabs", "openai", "minimax", "mistral", "neutts", "piper"]
|
// v0.13: `xai` joins the TTS provider list. xAI shipped TTS earlier
|
||||||
|
// (v0.12) but the v0.13 add-on is custom voice cloning — see
|
||||||
|
// `HermesCapabilities.hasXAIVoiceCloning` and the badge in VoiceTab.
|
||||||
|
// The provider option itself is ungated so pre-v0.13 hosts with xAI
|
||||||
|
// keys can still pick it.
|
||||||
|
var ttsProviders = ["edge", "elevenlabs", "openai", "minimax", "mistral", "neutts", "piper", "xai"]
|
||||||
var sttProviders = ["local", "groq", "openai", "mistral"]
|
var sttProviders = ["local", "groq", "openai", "mistral"]
|
||||||
|
/// Static-message translation languages honored by Hermes v0.13's
|
||||||
|
/// `display.language` key. The first row's empty value writes no
|
||||||
|
/// key — equivalent to "Hermes default" — while explicit `en` writes
|
||||||
|
/// the code so users who care about determinism can pin it. Keep the
|
||||||
|
/// label list in sync with the Hermes v0.13 release notes; new
|
||||||
|
/// languages should be appended in alphabetical order by display
|
||||||
|
/// label so the picker stays scannable.
|
||||||
|
var displayLanguages: [(code: String, label: String)] = [
|
||||||
|
("", "English (default)"),
|
||||||
|
("en", "English"),
|
||||||
|
("zh", "中文 (Chinese)"),
|
||||||
|
("ja", "日本語 (Japanese)"),
|
||||||
|
("de", "Deutsch (German)"),
|
||||||
|
("es", "Español (Spanish)"),
|
||||||
|
("fr", "Français (French)"),
|
||||||
|
("uk", "Українська (Ukrainian)"),
|
||||||
|
("tr", "Türkçe (Turkish)"),
|
||||||
|
]
|
||||||
var memoryProviders = ["", "honcho", "openviking", "mem0", "hindsight", "holographic", "retaindb", "byterover", "supermemory"]
|
var memoryProviders = ["", "honcho", "openviking", "mem0", "hindsight", "holographic", "retaindb", "byterover", "supermemory"]
|
||||||
var saveMessage: String?
|
var saveMessage: String?
|
||||||
var isLoading = false
|
var isLoading = false
|
||||||
@@ -104,6 +127,10 @@ final class SettingsViewModel {
|
|||||||
func setToolProgressCommand(_ value: Bool) { setSetting("display.tool_progress_command", value: value ? "true" : "false") }
|
func setToolProgressCommand(_ value: Bool) { setSetting("display.tool_progress_command", value: value ? "true" : "false") }
|
||||||
func setToolPreviewLength(_ value: Int) { setSetting("display.tool_preview_length", value: String(value)) }
|
func setToolPreviewLength(_ value: Int) { setSetting("display.tool_preview_length", value: String(value)) }
|
||||||
func setBusyInputMode(_ value: String) { setSetting("display.busy_input_mode", value: value) }
|
func setBusyInputMode(_ value: String) { setSetting("display.busy_input_mode", value: value) }
|
||||||
|
/// v0.13: `display.language` for static-message translations. Empty
|
||||||
|
/// string writes "" via `hermes config set` which Hermes treats as
|
||||||
|
/// "use default"; explicit codes pin the language.
|
||||||
|
func setDisplayLanguage(_ value: String) { setSetting("display.language", value: value) }
|
||||||
|
|
||||||
// MARK: - Agent
|
// MARK: - Agent
|
||||||
|
|
||||||
@@ -158,6 +185,10 @@ final class SettingsViewModel {
|
|||||||
func setTTSOpenAIVoice(_ value: String) { setSetting("tts.openai.voice", value: value) }
|
func setTTSOpenAIVoice(_ value: String) { setSetting("tts.openai.voice", value: value) }
|
||||||
func setTTSNeuTTSModel(_ value: String) { setSetting("tts.neutts.model", value: value) }
|
func setTTSNeuTTSModel(_ value: String) { setSetting("tts.neutts.model", value: value) }
|
||||||
func setTTSNeuTTSDevice(_ value: String) { setSetting("tts.neutts.device", value: value) }
|
func setTTSNeuTTSDevice(_ value: String) { setSetting("tts.neutts.device", value: value) }
|
||||||
|
// v0.13: xAI TTS / Custom Voices. TODO(WS-8-Q2): grep-verify key
|
||||||
|
// names against `~/.hermes/hermes-agent/hermes_cli/voice/tts.py`.
|
||||||
|
func setTTSXAIVoiceID(_ value: String) { setSetting("tts.xai.voice_id", value: value) }
|
||||||
|
func setTTSXAIModel(_ value: String) { setSetting("tts.xai.model", value: value) }
|
||||||
func setSTTEnabled(_ value: Bool) { setSetting("stt.enabled", value: value ? "true" : "false") }
|
func setSTTEnabled(_ value: Bool) { setSetting("stt.enabled", value: value ? "true" : "false") }
|
||||||
func setSTTProvider(_ value: String) { setSetting("stt.provider", value: value) }
|
func setSTTProvider(_ value: String) { setSetting("stt.provider", value: value) }
|
||||||
func setSTTLocalModel(_ value: String) { setSetting("stt.local.model", value: value) }
|
func setSTTLocalModel(_ value: String) { setSetting("stt.local.model", value: value) }
|
||||||
|
|||||||
@@ -152,8 +152,23 @@ struct PickerRow: View {
|
|||||||
let label: String
|
let label: String
|
||||||
let selection: String
|
let selection: String
|
||||||
let options: [String]
|
let options: [String]
|
||||||
|
let optionLabel: ((String) -> String)?
|
||||||
let onChange: (String) -> Void
|
let onChange: (String) -> Void
|
||||||
|
|
||||||
|
init(
|
||||||
|
label: String,
|
||||||
|
selection: String,
|
||||||
|
options: [String],
|
||||||
|
optionLabel: ((String) -> String)? = nil,
|
||||||
|
onChange: @escaping (String) -> Void
|
||||||
|
) {
|
||||||
|
self.label = label
|
||||||
|
self.selection = selection
|
||||||
|
self.options = options
|
||||||
|
self.optionLabel = optionLabel
|
||||||
|
self.onChange = onChange
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
HStack {
|
HStack {
|
||||||
SettingsRowLabel(label: label)
|
SettingsRowLabel(label: label)
|
||||||
@@ -162,7 +177,7 @@ struct PickerRow: View {
|
|||||||
set: { onChange($0) }
|
set: { onChange($0) }
|
||||||
)) {
|
)) {
|
||||||
ForEach(options, id: \.self) { option in
|
ForEach(options, id: \.self) { option in
|
||||||
Text(option.isEmpty ? "(none)" : option).tag(option)
|
Text(displayLabel(for: option)).tag(option)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.frame(maxWidth: 250)
|
.frame(maxWidth: 250)
|
||||||
@@ -170,6 +185,13 @@ struct PickerRow: View {
|
|||||||
}
|
}
|
||||||
.settingsRowChrome()
|
.settingsRowChrome()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func displayLabel(for option: String) -> String {
|
||||||
|
if let mapper = optionLabel {
|
||||||
|
return mapper(option)
|
||||||
|
}
|
||||||
|
return option.isEmpty ? "(none)" : option
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ToggleRow: View {
|
struct ToggleRow: View {
|
||||||
|
|||||||
@@ -131,6 +131,8 @@ struct AdvancedTab: View {
|
|||||||
isOn: viewModel.config.redactionEnabled
|
isOn: viewModel.config.redactionEnabled
|
||||||
) { viewModel.setSetting("redaction.enabled", value: $0 ? "true" : "false") }
|
) { viewModel.setSetting("redaction.enabled", value: $0 ? "true" : "false") }
|
||||||
|
|
||||||
|
redactionDefaultsHint
|
||||||
|
|
||||||
ToggleRow(
|
ToggleRow(
|
||||||
label: "Runtime metadata footer",
|
label: "Runtime metadata footer",
|
||||||
isOn: viewModel.config.runtimeMetadataFooter
|
isOn: viewModel.config.runtimeMetadataFooter
|
||||||
@@ -138,6 +140,30 @@ struct AdvancedTab: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Inline hint below the redaction toggle. The server-side default
|
||||||
|
/// flipped from OFF (v0.12) to ON (v0.13), but Scarf's parser still
|
||||||
|
/// reads "absent key" as `false` — meaning a v0.13 host with no
|
||||||
|
/// explicit key in `config.yaml` shows the toggle OFF while the
|
||||||
|
/// agent treats redaction as ON. Hint copy disambiguates so users
|
||||||
|
/// can tell what's actually happening server-side.
|
||||||
|
@ViewBuilder
|
||||||
|
private var redactionDefaultsHint: some View {
|
||||||
|
let isV013 = capabilitiesStore?.capabilities.isV013OrLater ?? false
|
||||||
|
HStack {
|
||||||
|
Text("")
|
||||||
|
.font(.caption)
|
||||||
|
.frame(width: 160, alignment: .trailing)
|
||||||
|
Text(isV013
|
||||||
|
? "Recommended: ON. Hermes v0.13+ defaults to redacting secrets unless you opt out."
|
||||||
|
: "Default OFF in Hermes v0.12. Toggle ON to redact secrets in logs and shares.")
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 12)
|
||||||
|
.padding(.vertical, 4)
|
||||||
|
}
|
||||||
|
|
||||||
private var backupSection: some View {
|
private var backupSection: some View {
|
||||||
SettingsSection(title: "Backup & Restore", icon: "externaldrive") {
|
SettingsSection(title: "Backup & Restore", icon: "externaldrive") {
|
||||||
HStack {
|
HStack {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import ScarfCore
|
|||||||
struct GeneralTab: View {
|
struct GeneralTab: View {
|
||||||
@Bindable var viewModel: SettingsViewModel
|
@Bindable var viewModel: SettingsViewModel
|
||||||
@Environment(AppCoordinator.self) private var coordinator
|
@Environment(AppCoordinator.self) private var coordinator
|
||||||
|
@Environment(\.hermesCapabilities) private var capabilitiesStore
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
SettingsSection(title: "Model", icon: "cpu") {
|
SettingsSection(title: "Model", icon: "cpu") {
|
||||||
@@ -39,6 +40,20 @@ struct GeneralTab: View {
|
|||||||
|
|
||||||
SettingsSection(title: "Locale", icon: "globe.americas") {
|
SettingsSection(title: "Locale", icon: "globe.americas") {
|
||||||
EditableTextField(label: "Timezone (IANA)", value: viewModel.config.timezone) { viewModel.setTimezone($0) }
|
EditableTextField(label: "Timezone (IANA)", value: viewModel.config.timezone) { viewModel.setTimezone($0) }
|
||||||
|
// v0.13: `display.language` picker. Hidden on pre-v0.13 hosts
|
||||||
|
// because writing the key would no-op silently. Two "English"
|
||||||
|
// entries by design — empty string preserves "no key" semantics
|
||||||
|
// (Hermes-default), explicit `en` pins it.
|
||||||
|
if capabilitiesStore?.capabilities.hasDisplayLanguage == true {
|
||||||
|
PickerRow(
|
||||||
|
label: "Display language",
|
||||||
|
selection: viewModel.config.display.language,
|
||||||
|
options: viewModel.displayLanguages.map(\.code),
|
||||||
|
optionLabel: { code in
|
||||||
|
viewModel.displayLanguages.first { $0.code == code }?.label ?? code
|
||||||
|
}
|
||||||
|
) { viewModel.setDisplayLanguage($0) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdatesSection()
|
UpdatesSection()
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
import ScarfCore
|
import ScarfCore
|
||||||
|
import ScarfDesign
|
||||||
|
|
||||||
/// Voice tab — push-to-talk + TTS + STT provider settings.
|
/// Voice tab — push-to-talk + TTS + STT provider settings.
|
||||||
struct VoiceTab: View {
|
struct VoiceTab: View {
|
||||||
@Bindable var viewModel: SettingsViewModel
|
@Bindable var viewModel: SettingsViewModel
|
||||||
|
@Environment(\.hermesCapabilities) private var capabilitiesStore
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
SettingsSection(title: "Push-to-Talk", icon: "mic") {
|
SettingsSection(title: "Push-to-Talk", icon: "mic") {
|
||||||
@@ -28,6 +30,16 @@ struct VoiceTab: View {
|
|||||||
case "neutts":
|
case "neutts":
|
||||||
EditableTextField(label: "Model", value: viewModel.config.voice.ttsNeuTTSModel) { viewModel.setTTSNeuTTSModel($0) }
|
EditableTextField(label: "Model", value: viewModel.config.voice.ttsNeuTTSModel) { viewModel.setTTSNeuTTSModel($0) }
|
||||||
PickerRow(label: "Device", selection: viewModel.config.voice.ttsNeuTTSDevice, options: ["cpu", "cuda"]) { viewModel.setTTSNeuTTSDevice($0) }
|
PickerRow(label: "Device", selection: viewModel.config.voice.ttsNeuTTSDevice, options: ["cpu", "cuda"]) { viewModel.setTTSNeuTTSDevice($0) }
|
||||||
|
case "xai":
|
||||||
|
// v0.13: xAI TTS surface. Voice ID + Model are always
|
||||||
|
// visible (xAI TTS shipped earlier); the cloning-supported
|
||||||
|
// badge is gated on `hasXAIVoiceCloning` so pre-v0.13 hosts
|
||||||
|
// see the input rows but no cloning advertisement.
|
||||||
|
EditableTextField(label: "Voice ID", value: viewModel.config.voice.ttsXAIVoiceID) { viewModel.setTTSXAIVoiceID($0) }
|
||||||
|
EditableTextField(label: "Model", value: viewModel.config.voice.ttsXAIModel) { viewModel.setTTSXAIModel($0) }
|
||||||
|
if capabilitiesStore?.capabilities.hasXAIVoiceCloning == true {
|
||||||
|
xaiCloningBadge
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
EmptyView()
|
EmptyView()
|
||||||
}
|
}
|
||||||
@@ -49,4 +61,24 @@ struct VoiceTab: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Inline hint chip+caption shown below xAI's Voice ID + Model fields
|
||||||
|
/// on v0.13+. References `hermes voice` because Scarf doesn't manage
|
||||||
|
/// cloned voices in-app yet — the badge is discovery-only. Out-of-scope
|
||||||
|
/// for v2.8: an in-app cloned-voice manager (would be its own feature).
|
||||||
|
@ViewBuilder
|
||||||
|
private var xaiCloningBadge: some View {
|
||||||
|
HStack(alignment: .center, spacing: 8) {
|
||||||
|
Text("")
|
||||||
|
.font(.caption)
|
||||||
|
.frame(width: 160, alignment: .trailing)
|
||||||
|
ScarfBadge("Cloning supported", kind: .info)
|
||||||
|
Text("Manage cloned voices in your terminal: `hermes voice` (xAI subcommands).")
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 12)
|
||||||
|
.padding(.vertical, 4)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user