Compare commits

..

1 Commits

Author SHA1 Message Date
Alan Wizemann 4757b5ae49 feat(curator): archive + prune + list-archived (WS-4)
Catches the Curator surface up to Hermes v0.13's new write-side verbs
(`archive <skill>`, `prune`, `list-archived`, synchronous `run`). Adds
a new `CuratorService` actor in ScarfCore mirroring `KanbanService`'s
pattern (Sendable, pure I/O, `Task.detached(priority: .utility)` per
verb), tolerantly-decoded `HermesCuratorArchivedSkill` /
`CuratorPruneSummary` models, and `CuratorError` for inline-banner
surfacing.

Mac UX gains an "Archived" section between the leaderboards and the
last-report block (per-row Restore button), an "archivebox" button on
every active-skill leaderboard row to manually archive, a destructive
"Prune Archived…" confirm sheet enumerating each skill (template-
uninstall pattern — Cancel owns `.defaultAction`, Prune is on the red
`ScarfDestructiveButton`), and a synchronous-with-progress "Run Now"
on v0.13+ hosts (600s timeout, `ProgressView` while in-flight).
Failure path routes through a yellow inline error banner instead of a
modal alert. The legacy `CuratorRestoreSheet` stays accessible from
the overflow menu but only on pre-v0.13 hosts; on v0.13+ the per-row
Restore in the new Archived section replaces it.

All new surfaces gate on `HermesCapabilities.hasCuratorArchive` —
pre-v0.13 hosts see the v2.7.x layout unchanged. iOS picks up the new
`runNow(synchronous:)` signature with the v0.13 capability flag; the
read-only Archived section + WS-9 marker is left for the next stream.
14 new parser tests in `HermesCuratorParserTests` cover the JSON
happy path, the `{"archived": [...]}` envelope, the text fallback
(`--json` not supported), `"no archived skills"` sentinel folding,
prune-dry-run with both wrapper + bare-array shapes, and zero-skill
prune. All 369 ScarfCore tests pass; `xcodebuild` for the `scarf`
scheme succeeds.

Wire-shape unknowns (CLI flag presence on real v0.13) carry
`// TODO(WS-4-Q<N>)` markers in `CuratorService` and fall back
defensively when a flag isn't recognized. Implements WS-4 of Scarf
v2.8.0 (Hermes v0.13.0 catch-up). Plan:
scarf/docs/v2.8/WS-4-curator-archive-plan.md (on
coordination/v2.8.0-plans).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 19:03:13 +02:00
28 changed files with 1314 additions and 497 deletions
@@ -0,0 +1,34 @@
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
}
}
}
@@ -666,18 +666,6 @@ public struct HermesConfig: Sendable {
/// final reply (provider/model/cost/turn count). Off by default; /// final reply (provider/model/cost/turn count). Off by default;
/// useful for cost auditing and screen-recording demos. /// useful for cost auditing and screen-recording demos.
public var runtimeMetadataFooter: Bool public var runtimeMetadataFooter: Bool
/// Pre-v0.13: single combined Web Tools backend at `web_tools.backend`.
/// v0.13 split this into per-capability keys (see below). Kept readable
/// for round-trip compatibility on hosts that never migrated; v0.13+
/// hosts ignore this scalar and read the split keys instead.
public var webToolsBackend: String
/// v0.13+: `web_tools.search.backend`. SearXNG is search-only and
/// can land here. Pre-v0.13 hosts default to the same value as the
/// combined backend.
public var webToolsSearchBackend: String
/// v0.13+: `web_tools.extract.backend`. Pre-v0.13 hosts default to
/// the same value as the combined backend.
public var webToolsExtractBackend: String
// Grouped blocks // Grouped blocks
public var display: DisplaySettings public var display: DisplaySettings
@@ -759,17 +747,11 @@ public struct HermesConfig: Sendable {
homeAssistant: HomeAssistantSettings, homeAssistant: HomeAssistantSettings,
cacheTTL: String = "5m", cacheTTL: String = "5m",
redactionEnabled: Bool = false, redactionEnabled: Bool = false,
runtimeMetadataFooter: Bool = false, runtimeMetadataFooter: Bool = false
webToolsBackend: String = "duckduckgo",
webToolsSearchBackend: String = "duckduckgo",
webToolsExtractBackend: String = "reader"
) { ) {
self.cacheTTL = cacheTTL self.cacheTTL = cacheTTL
self.redactionEnabled = redactionEnabled self.redactionEnabled = redactionEnabled
self.runtimeMetadataFooter = runtimeMetadataFooter self.runtimeMetadataFooter = runtimeMetadataFooter
self.webToolsBackend = webToolsBackend
self.webToolsSearchBackend = webToolsSearchBackend
self.webToolsExtractBackend = webToolsExtractBackend
self.model = model self.model = model
self.provider = provider self.provider = provider
self.maxTurns = maxTurns self.maxTurns = maxTurns
@@ -28,12 +28,6 @@ public struct HermesCronJob: Identifiable, Sendable, Codable {
/// job's prompt. YAML-only field today (no `--context-from` CLI /// job's prompt. YAML-only field today (no `--context-from` CLI
/// flag yet) Scarf displays it but doesn't write it. /// flag yet) Scarf displays it but doesn't write it.
public nonisolated let contextFrom: [String]? public nonisolated let contextFrom: [String]?
/// Hermes v0.13+ script-only watchdog mode. When `true` the
/// pre-run script runs but the AI turn is skipped. `nil` means the
/// jobs.json file is pre-v0.13 (treat as `false`); `false` is the
/// explicit v0.13+ default. Capability-gated on `hasCronNoAgent`
/// at all write call sites.
public nonisolated let noAgent: Bool?
public enum CodingKeys: String, CodingKey { public enum CodingKeys: String, CodingKey {
case id, name, prompt, skills, model, schedule, enabled, state, deliver, silent case id, name, prompt, skills, model, schedule, enabled, state, deliver, silent
@@ -47,7 +41,6 @@ public struct HermesCronJob: Identifiable, Sendable, Codable {
case timeoutSeconds = "timeout_seconds" case timeoutSeconds = "timeout_seconds"
case workdir case workdir
case contextFrom = "context_from" case contextFrom = "context_from"
case noAgent = "no_agent"
} }
/// Memberwise init. Swift doesn't synthesize one for us because /// Memberwise init. Swift doesn't synthesize one for us because
@@ -73,8 +66,7 @@ public struct HermesCronJob: Identifiable, Sendable, Codable {
timeoutSeconds: Int? = nil, timeoutSeconds: Int? = nil,
silent: Bool? = nil, silent: Bool? = nil,
workdir: String? = nil, workdir: String? = nil,
contextFrom: [String]? = nil, contextFrom: [String]? = nil
noAgent: Bool? = nil
) { ) {
self.id = id self.id = id
self.name = name self.name = name
@@ -96,7 +88,6 @@ public struct HermesCronJob: Identifiable, Sendable, Codable {
self.silent = silent self.silent = silent
self.workdir = workdir self.workdir = workdir
self.contextFrom = contextFrom self.contextFrom = contextFrom
self.noAgent = noAgent
} }
public nonisolated init(from decoder: any Decoder) throws { public nonisolated init(from decoder: any Decoder) throws {
@@ -121,7 +112,6 @@ public struct HermesCronJob: Identifiable, Sendable, Codable {
self.silent = try c.decodeIfPresent(Bool.self, forKey: .silent) self.silent = try c.decodeIfPresent(Bool.self, forKey: .silent)
self.workdir = try c.decodeIfPresent(String.self, forKey: .workdir) self.workdir = try c.decodeIfPresent(String.self, forKey: .workdir)
self.contextFrom = try c.decodeIfPresent([String].self, forKey: .contextFrom) self.contextFrom = try c.decodeIfPresent([String].self, forKey: .contextFrom)
self.noAgent = try c.decodeIfPresent(Bool.self, forKey: .noAgent)
} }
public nonisolated func encode(to encoder: any Encoder) throws { public nonisolated func encode(to encoder: any Encoder) throws {
@@ -146,7 +136,6 @@ public struct HermesCronJob: Identifiable, Sendable, Codable {
try c.encodeIfPresent(silent, forKey: .silent) try c.encodeIfPresent(silent, forKey: .silent)
try c.encodeIfPresent(workdir, forKey: .workdir) try c.encodeIfPresent(workdir, forKey: .workdir)
try c.encodeIfPresent(contextFrom, forKey: .contextFrom) try c.encodeIfPresent(contextFrom, forKey: .contextFrom)
try c.encodeIfPresent(noAgent, forKey: .noAgent)
} }
public nonisolated var stateIcon: String { public nonisolated var stateIcon: String {
@@ -0,0 +1,124 @@
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))
}
}
@@ -3,10 +3,6 @@ import Foundation
public enum MCPTransport: String, Sendable, Equatable, CaseIterable, Identifiable { public enum MCPTransport: String, Sendable, Equatable, CaseIterable, Identifiable {
case stdio case stdio
case http case http
/// Server-Sent Events transport. Hermes v0.13+ only.
// TODO(WS-7-Q1): Verify Hermes uses the literal `sse` transport name
// (vs. `streamable-http`/`http-sse`/etc.) once a v0.13 host is on hand.
case sse
public var id: String { rawValue } public var id: String { rawValue }
@@ -15,7 +11,6 @@ public enum MCPTransport: String, Sendable, Equatable, CaseIterable, Identifiabl
switch self { switch self {
case .stdio: return "Local (stdio)" case .stdio: return "Local (stdio)"
case .http: return "Remote (HTTP)" case .http: return "Remote (HTTP)"
case .sse: return "Remote (SSE)"
} }
} }
#endif #endif
@@ -38,12 +33,6 @@ public struct HermesMCPServer: Identifiable, Sendable, Equatable {
public let resourcesEnabled: Bool public let resourcesEnabled: Bool
public let promptsEnabled: Bool public let promptsEnabled: Bool
public let hasOAuthToken: Bool public let hasOAuthToken: Bool
/// Hermes-side keepalive interval (seconds) for SSE transport. `nil`
/// when the YAML doesn't specify `sse_read_timeout` (Hermes default
/// applies). Pre-v0.13 hosts always have this as `nil`.
// TODO(WS-7-Q2): Default is assumed to be 300s per WS-7 plan; placeholder
// copy uses that. Verify against `~/.hermes/hermes-agent/hermes_cli/mcp.py`.
public let sseReadTimeout: Int?
public init( public init(
@@ -62,8 +51,7 @@ public struct HermesMCPServer: Identifiable, Sendable, Equatable {
toolsExclude: [String], toolsExclude: [String],
resourcesEnabled: Bool, resourcesEnabled: Bool,
promptsEnabled: Bool, promptsEnabled: Bool,
hasOAuthToken: Bool, hasOAuthToken: Bool
sseReadTimeout: Int? = nil
) { ) {
self.name = name self.name = name
self.transport = transport self.transport = transport
@@ -81,7 +69,6 @@ public struct HermesMCPServer: Identifiable, Sendable, Equatable {
self.resourcesEnabled = resourcesEnabled self.resourcesEnabled = resourcesEnabled
self.promptsEnabled = promptsEnabled self.promptsEnabled = promptsEnabled
self.hasOAuthToken = hasOAuthToken self.hasOAuthToken = hasOAuthToken
self.sseReadTimeout = sseReadTimeout
} }
public var id: String { name } public var id: String { name }
@@ -92,8 +79,6 @@ public struct HermesMCPServer: Identifiable, Sendable, Equatable {
return (command ?? "") + argString return (command ?? "") + argString
case .http: case .http:
return url ?? "" return url ?? ""
case .sse:
return url ?? ""
} }
} }
} }
@@ -284,14 +284,7 @@ public extension HermesConfig {
homeAssistant: homeAssistant, homeAssistant: homeAssistant,
cacheTTL: str("prompt_caching.cache_ttl", default: "5m"), cacheTTL: str("prompt_caching.cache_ttl", default: "5m"),
redactionEnabled: bool("redaction.enabled", default: false), redactionEnabled: bool("redaction.enabled", default: false),
runtimeMetadataFooter: bool("agent.runtime_metadata_footer", default: false), runtimeMetadataFooter: bool("agent.runtime_metadata_footer", default: false)
// Pre-v0.13 hosts wrote a single `web_tools.backend`. v0.13 split
// it into per-capability keys. Read all three so the round-trip
// never loses a value the user already set; the WebTools tab
// chooses which to render based on `hasWebToolsBackendSplit`.
webToolsBackend: str("web_tools.backend", default: "duckduckgo"),
webToolsSearchBackend: str("web_tools.search.backend", default: "duckduckgo"),
webToolsExtractBackend: str("web_tools.extract.backend", default: "reader")
) )
} }
} }
@@ -0,0 +1,358 @@
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)
}
}
@@ -4,17 +4,19 @@ import Observation
import os import os
#endif #endif
/// Mac + iOS view model for the v0.12 Curator surface. /// Mac + iOS view model for the Curator surface (v0.12 base + v0.13
/// archive/prune additions).
/// ///
/// Drives `hermes curator status / run / pause / resume / pin / unpin / /// Drives `hermes curator status / run / pause / resume / pin / unpin /
/// restore` plus a parsed view of `~/.hermes/skills/.curator_state` /// restore` plus (v0.13+) `archive`, `prune`, `list-archived`. All CLI
/// JSON. The CLI doesn't ship a `--json` flag for `status`, so we /// invocations route through `CuratorService` (the actor) so polling
/// text-parse stdout (HermesCuratorStatusParser) and use the state /// and writes share the same concurrency model and a single error path.
/// 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. The view model does not /// `HermesCapabilities.hasCurator` is true. Archive-aware UI surfaces
/// gate itself the gate happens at sidebar/tab routing time. /// (Archive button, Archived section, Prune) gate independently on
/// `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 {
@@ -27,20 +29,50 @@ 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 // status` (CLI subprocess) plus 1-2 file reads; on remote each
// each is a separate SSH RTT. Visibility lets future captures // is a separate SSH RTT. Visibility lets future captures show
// show how often the report file is missing or oversized. // 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)
@@ -69,46 +101,156 @@ public final class CuratorViewModel {
self.lastReportMarkdown = parsed.1 self.lastReportMarkdown = parsed.1
} }
public func runNow() async { /// Refresh the archived-skills list. No-op on hosts without
await runAndReload(args: ["curator", "run"], successMessage: "Curator run started") /// `hasCuratorArchive` the caller gates the call.
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 runAndReload(args: ["curator", "pause"], successMessage: "Curator paused") await runWithReload(verb: "pause", successMessage: "Curator paused") {
try await self.service.pause()
}
} }
public func resume() async { public func resume() async {
await runAndReload(args: ["curator", "resume"], successMessage: "Curator resumed") await runWithReload(verb: "resume", successMessage: "Curator resumed") {
try await self.service.resume()
}
} }
public func pin(_ skill: String) async { public func pin(_ skill: String) async {
await runAndReload(args: ["curator", "pin", skill], successMessage: "Pinned \(skill)") await runWithReload(verb: "pin", successMessage: "Pinned \(skill)") {
try await self.service.pin(skill)
}
} }
public func unpin(_ skill: String) async { public func unpin(_ skill: String) async {
await runAndReload(args: ["curator", "unpin", skill], successMessage: "Unpinned \(skill)") await runWithReload(verb: "unpin", successMessage: "Unpinned \(skill)") {
try await self.service.unpin(skill)
}
} }
public func restore(_ skill: String) async { public func restore(_ skill: String) async {
await runAndReload(args: ["curator", "restore", skill], successMessage: "Restored \(skill)") await runWithReload(verb: "restore", 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()
} }
private func runAndReload(args: [String], successMessage: String) async { // MARK: - Writes (v0.13)
let context = self.context
let exitCode = await Task.detached(priority: .userInitiated) { public func archive(_ skill: String) async {
Self.runHermes(context: context, args: args).exitCode pendingArchiveName = skill
}.value await runWithReload(verb: "archive", successMessage: "Archived \(skill)") {
transientMessage = exitCode == 0 ? successMessage : "Command failed" try await self.service.archive(skill)
await load() }
// Auto-clear toast after 3s. 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()
scheduleTransientClear()
} 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
} }
} }
/// Wrap the transport-level `runProcess` so the call sites don't // MARK: - Legacy sync helpers (kept for `load`'s detached path)
/// 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]
@@ -151,4 +151,169 @@ 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")
}
} }
+14 -1
View File
@@ -13,11 +13,24 @@ 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 {
@@ -115,7 +128,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() } Task { await viewModel.runNow(synchronous: archiveAvailable, timeout: 600) }
} label: { } label: {
Label("Run now", systemImage: "play.fill") Label("Run now", systemImage: "play.fill")
} }
@@ -599,8 +599,7 @@ struct HermesFileService: Sendable {
toolsExclude: server.toolsExclude, toolsExclude: server.toolsExclude,
resourcesEnabled: server.resourcesEnabled, resourcesEnabled: server.resourcesEnabled,
promptsEnabled: server.promptsEnabled, promptsEnabled: server.promptsEnabled,
hasOAuthToken: hasToken, hasOAuthToken: hasToken
sseReadTimeout: server.sseReadTimeout
) )
} }
} }
@@ -631,37 +630,6 @@ struct HermesFileService: Sendable {
return runHermesCLI(args: cliArgs, timeout: 45, stdinInput: "y\ny\ny\n") return runHermesCLI(args: cliArgs, timeout: 45, stdinInput: "y\ny\ny\n")
} }
/// Adds an SSE-transport MCP server. v0.13+ only caller is responsible
/// for capability-gating; pre-v0.13 hosts will reject the `--transport`
/// flag at argparse time. The optional `sseReadTimeout` is passed via
/// `--sse-read-timeout <int>` and persisted as `sse_read_timeout: <int>`
/// in the YAML entry.
// TODO(WS-7-Q3): Verify exact CLI flag spelling against `hermes mcp add --help`
// on a v0.13 install. Plan assumes `--transport sse` + `--sse-read-timeout`;
// alternatives could be `--sse` (boolean) + `--read-timeout`.
@discardableResult
nonisolated func addMCPServerSSE(name: String, url: String, sseReadTimeout: Int?) -> (exitCode: Int32, output: String) {
var cliArgs: [String] = ["mcp", "add", name, "--url", url, "--transport", "sse"]
if let timeout = sseReadTimeout {
cliArgs.append(contentsOf: ["--sse-read-timeout", String(timeout)])
}
return runHermesCLI(args: cliArgs, timeout: 45, stdinInput: "y\ny\ny\n")
}
/// Updates the `sse_read_timeout` scalar in-place via the same surgical
/// patcher used by `setMCPServerTimeouts`. Pass `nil` to remove the
/// scalar entirely (Hermes default applies).
@discardableResult
nonisolated func setMCPServerSSETimeout(name: String, sseReadTimeout: Int?) -> Bool {
patchMCPServerField(name: name) { entryLines in
if let timeout = sseReadTimeout {
Self.replaceOrInsertScalar(key: "sse_read_timeout", value: String(timeout), in: &entryLines)
} else {
Self.removeScalar(key: "sse_read_timeout", in: &entryLines)
}
}
}
@discardableResult @discardableResult
nonisolated func setMCPServerArgs(name: String, args: [String]) -> Bool { nonisolated func setMCPServerArgs(name: String, args: [String]) -> Bool {
patchMCPServerField(name: name) { entryLines in patchMCPServerField(name: name) { entryLines in
@@ -844,23 +812,11 @@ struct HermesFileService: Sendable {
func flush() { func flush() {
guard let name = currentName else { return } guard let name = currentName else { return }
// 3-way transport discriminator: an explicit `transport: sse` scalar let transport: MCPTransport = fields["url"] != nil ? .http : .stdio
// wins (Hermes v0.13+ emits it for SSE servers); otherwise URL-bearing
// entries fall back to .http (v0.12 shape) and command-bearing entries
// to .stdio. This preserves byte-for-byte round-trip on existing files
// pre-v0.13 entries have no `transport:` key so they parse identically.
// TODO(WS-7-Q1): Verify Hermes v0.13 actually emits `transport: sse`
// (vs. inferring from the schema/url shape) once a v0.13 host is on hand.
let transport: MCPTransport = {
if fields["transport"]?.lowercased() == "sse" { return .sse }
if fields["url"] != nil { return .http }
return .stdio
}()
let enabledStr = fields["enabled"]?.lowercased() let enabledStr = fields["enabled"]?.lowercased()
let enabled = enabledStr != "false" let enabled = enabledStr != "false"
let timeout = fields["timeout"].flatMap(Int.init) let timeout = fields["timeout"].flatMap(Int.init)
let connectTimeout = fields["connect_timeout"].flatMap(Int.init) let connectTimeout = fields["connect_timeout"].flatMap(Int.init)
let sseReadTimeout = fields["sse_read_timeout"].flatMap(Int.init)
let server = HermesMCPServer( let server = HermesMCPServer(
name: name, name: name,
transport: transport, transport: transport,
@@ -877,8 +833,7 @@ struct HermesFileService: Sendable {
toolsExclude: excludeList, toolsExclude: excludeList,
resourcesEnabled: resources, resourcesEnabled: resources,
promptsEnabled: prompts, promptsEnabled: prompts,
hasOAuthToken: false, hasOAuthToken: false
sseReadTimeout: sseReadTimeout
) )
servers.append(server) servers.append(server)
@@ -146,7 +146,7 @@ final class CronViewModel {
} }
} }
func createJob(schedule: String, prompt: String, name: String, deliver: String, skills: [String], script: String, repeatCount: String, workdir: String = "", noAgent: Bool = false) { func createJob(schedule: String, prompt: String, name: String, deliver: String, skills: [String], script: String, repeatCount: String, workdir: String = "") {
var args = ["cron", "create"] var args = ["cron", "create"]
if !name.isEmpty { args += ["--name", name] } if !name.isEmpty { args += ["--name", name] }
if !deliver.isEmpty { args += ["--deliver", deliver] } if !deliver.isEmpty { args += ["--deliver", deliver] }
@@ -158,25 +158,12 @@ final class CronViewModel {
// know the flag argparse rejects unknown args, so the form // know the flag argparse rejects unknown args, so the form
// omits the flag when the field is empty. // omits the flag when the field is empty.
if !workdir.isEmpty { args += ["--workdir", workdir] } if !workdir.isEmpty { args += ["--workdir", workdir] }
// v0.13+: --no-agent runs the pre-run script and skips the AI turn.
// Caller (CronView) strips this on pre-v0.13 hosts so the flag is
// never emitted to a Hermes that can't parse it.
if noAgent { args.append("--no-agent") }
args.append(schedule) args.append(schedule)
// TODO(WS-7-Q5): When --no-agent is set Hermes ignores the prompt arg, if !prompt.isEmpty { args.append(prompt) }
// but argparse still wants positional args to line up with the
// schedule. The plan recommends passing an empty string explicitly so
// the positional parser doesn't treat the prompt as missing verify
// this behaviour against `hermes cron create --help` on a v0.13 host.
if noAgent {
args.append("")
} else if !prompt.isEmpty {
args.append(prompt)
}
runAndReload(args, success: "Job created") runAndReload(args, success: "Job created")
} }
func updateJob(id: String, schedule: String?, prompt: String?, name: String?, deliver: String?, repeatCount: String?, newSkills: [String]?, clearSkills: Bool, script: String?, workdir: String? = nil, noAgent: Bool? = nil) { func updateJob(id: String, schedule: String?, prompt: String?, name: String?, deliver: String?, repeatCount: String?, newSkills: [String]?, clearSkills: Bool, script: String?, workdir: String? = nil) {
var args = ["cron", "edit", id] var args = ["cron", "edit", id]
if let schedule, !schedule.isEmpty { args += ["--schedule", schedule] } if let schedule, !schedule.isEmpty { args += ["--schedule", schedule] }
if let prompt, !prompt.isEmpty { args += ["--prompt", prompt] } if let prompt, !prompt.isEmpty { args += ["--prompt", prompt] }
@@ -193,16 +180,6 @@ final class CronViewModel {
// = user cleared an existing workdir; Hermes documents `--workdir ""` // = user cleared an existing workdir; Hermes documents `--workdir ""`
// on edit as the explicit clear gesture, mirroring the `--script` shape. // on edit as the explicit clear gesture, mirroring the `--script` shape.
if let workdir { args += ["--workdir", workdir] } if let workdir { args += ["--workdir", workdir] }
// TODO(WS-7-Q4): The toggle-off shape of `--no-agent` on edit is
// unverified. Plan assumes Hermes accepts `--agent` to flip the flag
// back; if the CLI is one-way (`--no-agent` only), the edit-mode
// toggle should disable itself with a tooltip explaining the
// limitation. Send the flag in the assumed shape for now and adjust
// post-integration.
if let noAgent {
if noAgent { args.append("--no-agent") }
else { args.append("--agent") }
}
runAndReload(args, success: "Updated") runAndReload(args, success: "Updated")
} }
+4 -37
View File
@@ -25,10 +25,6 @@ struct CronView: View {
capabilitiesStore?.capabilities.hasCronWorkdir ?? false capabilitiesStore?.capabilities.hasCronWorkdir ?? false
} }
private var hasCronNoAgent: Bool {
capabilitiesStore?.capabilities.hasCronNoAgent ?? false
}
var body: some View { var body: some View {
VStack(spacing: 0) { VStack(spacing: 0) {
pageHeader pageHeader
@@ -51,7 +47,7 @@ struct CronView: View {
// polling timer. Same wiring ActivityView uses. // polling timer. Same wiring ActivityView uses.
.onChange(of: fileWatcher.lastChangeDate) { viewModel.load() } .onChange(of: fileWatcher.lastChangeDate) { viewModel.load() }
.sheet(isPresented: $viewModel.showCreateSheet) { .sheet(isPresented: $viewModel.showCreateSheet) {
CronJobEditor(mode: .create, availableSkills: viewModel.availableSkills, supportsWorkdir: hasCronWorkdir, supportsNoAgent: hasCronNoAgent) { form in CronJobEditor(mode: .create, availableSkills: viewModel.availableSkills, supportsWorkdir: hasCronWorkdir) { form in
viewModel.createJob( viewModel.createJob(
schedule: form.schedule, schedule: form.schedule,
prompt: form.prompt, prompt: form.prompt,
@@ -60,12 +56,7 @@ struct CronView: View {
skills: form.skills, skills: form.skills,
script: form.script, script: form.script,
repeatCount: form.repeatCount, repeatCount: form.repeatCount,
workdir: hasCronWorkdir ? form.workdir : "", workdir: hasCronWorkdir ? form.workdir : ""
// Mirrors the workdir strip-on-pre-version pattern: pre-v0.13
// hosts get a hard `false`, so a stale form value (or a
// hand-edited jobs.json round-tripped through edit-mode)
// can't sneak `--no-agent` into a CLI that doesn't grok it.
noAgent: hasCronNoAgent ? form.noAgent : false
) )
viewModel.showCreateSheet = false viewModel.showCreateSheet = false
} onCancel: { } onCancel: {
@@ -73,7 +64,7 @@ struct CronView: View {
} }
} }
.sheet(item: $viewModel.editingJob) { job in .sheet(item: $viewModel.editingJob) { job in
CronJobEditor(mode: .edit(job), availableSkills: viewModel.availableSkills, supportsWorkdir: hasCronWorkdir, supportsNoAgent: hasCronNoAgent) { form in CronJobEditor(mode: .edit(job), availableSkills: viewModel.availableSkills, supportsWorkdir: hasCronWorkdir) { form in
viewModel.updateJob( viewModel.updateJob(
id: job.id, id: job.id,
schedule: form.schedule, schedule: form.schedule,
@@ -84,8 +75,7 @@ struct CronView: View {
newSkills: form.skills, newSkills: form.skills,
clearSkills: form.clearSkills, clearSkills: form.clearSkills,
script: form.script, script: form.script,
workdir: hasCronWorkdir ? form.workdir : nil, workdir: hasCronWorkdir ? form.workdir : nil
noAgent: hasCronNoAgent ? form.noAgent : nil
) )
viewModel.editingJob = nil viewModel.editingJob = nil
} onCancel: { } onCancel: {
@@ -653,9 +643,6 @@ struct CronJobEditor: View {
/// v0.12+ workdir flag fills `--workdir <path>`. Empty string /// v0.12+ workdir flag fills `--workdir <path>`. Empty string
/// preserves the v0.11 behaviour of running with no cwd hint. /// preserves the v0.11 behaviour of running with no cwd hint.
var workdir: String = "" var workdir: String = ""
/// v0.13+ `--no-agent` flag script-only watchdog mode. Hermes
/// runs the pre-run script and skips the AI turn.
var noAgent: Bool = false
} }
let mode: Mode let mode: Mode
@@ -663,10 +650,6 @@ struct CronJobEditor: View {
/// Pass `false` on pre-v0.12 hosts; the `--workdir` field is hidden and /// Pass `false` on pre-v0.12 hosts; the `--workdir` field is hidden and
/// the form's value is dropped when the parent calls `createJob`/`updateJob`. /// the form's value is dropped when the parent calls `createJob`/`updateJob`.
let supportsWorkdir: Bool let supportsWorkdir: Bool
/// Pass `false` on pre-v0.13 hosts; the `--no-agent` toggle is hidden
/// and the parent strips the form's value before calling
/// `createJob`/`updateJob`. Mirrors the `supportsWorkdir` pattern.
let supportsNoAgent: Bool
let onSave: (FormState) -> Void let onSave: (FormState) -> Void
let onCancel: () -> Void let onCancel: () -> Void
@@ -698,25 +681,12 @@ struct CronJobEditor: View {
) )
.scrollContentBackground(.hidden) .scrollContentBackground(.hidden)
} }
.opacity(form.noAgent ? 0.4 : 1.0)
.disabled(form.noAgent)
formField("Deliver", text: $form.deliver, placeholder: "origin | local | discord:CHANNEL | telegram:CHAT", mono: true) formField("Deliver", text: $form.deliver, placeholder: "origin | local | discord:CHANNEL | telegram:CHAT", mono: true)
formField("Repeat", text: $form.repeatCount, placeholder: "Optional count") formField("Repeat", text: $form.repeatCount, placeholder: "Optional count")
formField("Script path", text: $form.script, placeholder: "Python script whose stdout is injected", mono: true) formField("Script path", text: $form.script, placeholder: "Python script whose stdout is injected", mono: true)
if supportsWorkdir { if supportsWorkdir {
formField("Workdir", text: $form.workdir, placeholder: "Absolute path; pulls AGENTS.md/CLAUDE.md context", mono: true) formField("Workdir", text: $form.workdir, placeholder: "Absolute path; pulls AGENTS.md/CLAUDE.md context", mono: true)
} }
if supportsNoAgent {
Toggle("Run script only (no agent call)", isOn: $form.noAgent)
.scarfStyle(.body)
.tint(ScarfColor.accent)
if form.noAgent {
Text("Watchdog mode — Hermes runs the pre-run script and skips the AI turn. Prompt + skills are ignored.")
.scarfStyle(.caption)
.foregroundStyle(ScarfColor.foregroundMuted)
.padding(.leading, ScarfSpace.s3)
}
}
if !availableSkills.isEmpty { if !availableSkills.isEmpty {
VStack(alignment: .leading, spacing: 4) { VStack(alignment: .leading, spacing: 4) {
Text("Skills") Text("Skills")
@@ -753,8 +723,6 @@ struct CronJobEditor: View {
.tint(ScarfColor.accent) .tint(ScarfColor.accent)
} }
} }
.opacity(form.noAgent ? 0.4 : 1.0)
.disabled(form.noAgent)
} }
HStack { HStack {
Spacer() Spacer()
@@ -778,7 +746,6 @@ struct CronJobEditor: View {
form.skills = job.skills ?? [] form.skills = job.skills ?? []
form.script = job.preRunScript ?? "" form.script = job.preRunScript ?? ""
form.workdir = job.workdir ?? "" form.workdir = job.workdir ?? ""
form.noAgent = job.noAgent ?? false
} }
} }
} }
@@ -0,0 +1,122 @@
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)
}
}
@@ -0,0 +1,123 @@
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,18 +2,16 @@ import SwiftUI
import ScarfCore import ScarfCore
import ScarfDesign import ScarfDesign
/// Modal that lists archived skills (state active) and exposes a /// Legacy v0.12 fallback for restoring an archived skill by typed
/// one-click "Restore" action per row. v0.12 archives are recoverable /// name. Hermes v0.12 didn't ship `curator list-archived`, so the only
/// `hermes curator restore <name>` brings the skill back into /// way to restore was to remember the skill name and pass it through
/// `~/.hermes/skills/<category>/<name>/` and re-marks it active. /// `hermes curator restore <name>`.
/// ///
/// The Curator's `status` text doesn't enumerate archived skills with /// **v0.13+ flow (preferred):** `CuratorArchivedSection` renders a
/// names; we surface what's available (counts + pinned list) and rely /// per-skill list with a one-click Restore button per row no typing
/// on the user knowing the names. Hermes ergo does an interactive /// required. This sheet stays reachable from the overflow menu only on
/// `--name` arg if missing but Scarf prefers explicit selection so /// pre-v0.13 hosts (gated by `!hasCuratorArchive`). Don't delete this
/// users don't have to remember names. For v2.6 we render a free-form /// file even after WS-4 ships; v0.12 hosts still depend on it.
/// 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,57 +2,52 @@ import SwiftUI
import ScarfCore import ScarfCore
import ScarfDesign import ScarfDesign
/// Mac UI for Hermes v0.12's autonomous skill curator. /// Mac UI for Hermes's autonomous skill curator (v0.12 base + v0.13
/// 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, and the most/least-active / /// metadata, agent-created skill counts, the most/least-active /
/// least-recently-active leaderboards. Pin-and-restore actions hit /// least-recently-active leaderboards, and on v0.13+ hosts the new
/// `hermes curator pin/unpin/restore` via CuratorViewModel. /// archived-skills section + per-row Archive button on each leaderboard
/// 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. This view assumes /// item when `HermesCapabilities.hasCurator` is true. Archive surfaces
/// it's reachable on a v0.12+ host. /// gate independently on `hasCuratorArchive`; pre-v0.13 hosts see the
/// 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: "Autonomous skill maintenance — Hermes v0.12+" subtitle: archiveAvailable
? "Autonomous skill maintenance — archive, prune, restore"
: "Autonomous skill maintenance — Hermes v0.12+"
) { ) {
HStack(spacing: ScarfSpace.s2) { headerActions
if viewModel.isLoading { }
ProgressView().controlSize(.small)
} if let errorMessage = viewModel.errorMessage {
Button("Run Now") { errorBanner(errorMessage)
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 toast = viewModel.transientMessage { if let toast = viewModel.transientMessage {
@@ -64,6 +59,19 @@ 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)
} }
@@ -71,10 +79,84 @@ struct CuratorView: View {
.padding(ScarfSpace.s4) .padding(ScarfSpace.s4)
} }
.background(ScarfColor.backgroundPrimary) .background(ScarfColor.backgroundPrimary)
.task { await viewModel.load() } .task {
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 1090s."
: "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 {
@@ -206,6 +288,10 @@ 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)
} }
@@ -213,6 +299,25 @@ 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)
@@ -277,6 +382,35 @@ 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
@@ -21,9 +21,6 @@ final class MCPServerEditorViewModel {
var promptsEnabled: Bool var promptsEnabled: Bool
var timeoutDraft: String var timeoutDraft: String
var connectTimeoutDraft: String var connectTimeoutDraft: String
/// SSE-only renders as a third numeric on `.sse` servers. Empty string
/// means "use Hermes default" (writer drops the scalar).
var sseReadTimeoutDraft: String
var showSecrets: Bool = false var showSecrets: Bool = false
var isSaving: Bool = false var isSaving: Bool = false
var saveError: String? var saveError: String?
@@ -40,7 +37,6 @@ final class MCPServerEditorViewModel {
self.promptsEnabled = server.promptsEnabled self.promptsEnabled = server.promptsEnabled
self.timeoutDraft = server.timeout.map { String($0) } ?? "" self.timeoutDraft = server.timeout.map { String($0) } ?? ""
self.connectTimeoutDraft = server.connectTimeout.map { String($0) } ?? "" self.connectTimeoutDraft = server.connectTimeout.map { String($0) } ?? ""
self.sseReadTimeoutDraft = server.sseReadTimeout.map { String($0) } ?? ""
} }
func appendEnvRow() { func appendEnvRow() {
@@ -73,8 +69,6 @@ final class MCPServerEditorViewModel {
let exclude = excludeDraft.split(separator: ",").map { $0.trimmingCharacters(in: .whitespaces) }.filter { !$0.isEmpty } let exclude = excludeDraft.split(separator: ",").map { $0.trimmingCharacters(in: .whitespaces) }.filter { !$0.isEmpty }
let timeoutValue = Int(timeoutDraft.trimmingCharacters(in: .whitespaces)) let timeoutValue = Int(timeoutDraft.trimmingCharacters(in: .whitespaces))
let connectValue = Int(connectTimeoutDraft.trimmingCharacters(in: .whitespaces)) let connectValue = Int(connectTimeoutDraft.trimmingCharacters(in: .whitespaces))
let trimmedSSE = sseReadTimeoutDraft.trimmingCharacters(in: .whitespaces)
let sseTimeoutValue: Int? = trimmedSSE.isEmpty ? nil : Int(trimmedSSE)
let service = fileService let service = fileService
let transport = server.transport let transport = server.transport
@@ -93,11 +87,6 @@ final class MCPServerEditorViewModel {
if !service.setMCPServerEnv(name: name, env: envMap) { ok = false } if !service.setMCPServerEnv(name: name, env: envMap) { ok = false }
case .http: case .http:
if !service.setMCPServerHeaders(name: name, headers: headerMap) { ok = false } if !service.setMCPServerHeaders(name: name, headers: headerMap) { ok = false }
case .sse:
// SSE servers carry headers like .http does, plus an
// optional sse_read_timeout written below.
if !service.setMCPServerHeaders(name: name, headers: headerMap) { ok = false }
if !service.setMCPServerSSETimeout(name: name, sseReadTimeout: sseTimeoutValue) { ok = false }
} }
if !service.updateMCPToolFilters( if !service.updateMCPToolFilters(
name: name, name: name,
@@ -42,10 +42,6 @@ final class MCPServersViewModel {
filteredServers.filter { $0.transport == .http } filteredServers.filter { $0.transport == .http }
} }
var sseServers: [HermesMCPServer] {
filteredServers.filter { $0.transport == .sse }
}
var selectedServer: HermesMCPServer? { var selectedServer: HermesMCPServer? {
guard let name = selectedServerName else { return nil } guard let name = selectedServerName else { return nil }
return servers.first(where: { $0.name == name }) return servers.first(where: { $0.name == name })
@@ -171,11 +167,6 @@ final class MCPServersViewModel {
url: preset.url ?? "", url: preset.url ?? "",
auth: preset.auth auth: preset.auth
) )
case .sse:
// No SSE-transport presets ship today; the preset picker
// only surfaces stdio/http servers. Treat as a no-op
// failure if a preset somehow declares .sse.
addResult = (exitCode: 1, output: "SSE-transport presets are not supported.")
} }
guard addResult.exitCode == 0 else { guard addResult.exitCode == 0 else {
await MainActor.run { await MainActor.run {
@@ -205,11 +196,6 @@ final class MCPServersViewModel {
result = fileService.addMCPServerStdio(name: name, command: command, args: args) result = fileService.addMCPServerStdio(name: name, command: command, args: args)
case .http: case .http:
result = fileService.addMCPServerHTTP(name: name, url: url, auth: auth) result = fileService.addMCPServerHTTP(name: name, url: url, auth: auth)
case .sse:
// Routed through addCustomSSE; this branch is unreachable from
// the add-server form (which dispatches per-transport in submit())
// but kept so the switch is exhaustive without `@unknown default`.
result = (exitCode: 1, output: "SSE servers must be added via addCustomSSE.")
} }
await MainActor.run { await MainActor.run {
if result.exitCode == 0 { if result.exitCode == 0 {
@@ -225,28 +211,6 @@ final class MCPServersViewModel {
} }
} }
/// v0.13+ SSE-transport server creation. Caller is responsible for
/// capability-gating; the form filters `.sse` out of `availableTransports`
/// when `hasMCPSSETransport` is false, so this method is unreachable
/// from the UI on pre-v0.13 hosts.
func addCustomSSE(name: String, url: String, sseReadTimeout: Int?) {
let fileService = self.fileService
Task.detached {
let result = fileService.addMCPServerSSE(name: name, url: url, sseReadTimeout: sseReadTimeout)
await MainActor.run {
if result.exitCode == 0 {
self.flashStatus("Added \(name)")
self.load()
self.selectedServerName = name
self.showRestartBanner = true
self.showAddCustom = false
} else {
self.activeError = "Add failed: \(result.output)"
}
}
}
}
func restartGateway() { func restartGateway() {
let fileService = self.fileService let fileService = self.fileService
Task.detached { Task.detached {
@@ -6,26 +6,12 @@ struct MCPServerAddCustomView: View {
let viewModel: MCPServersViewModel let viewModel: MCPServersViewModel
@Environment(\.dismiss) private var dismiss @Environment(\.dismiss) private var dismiss
@Environment(\.hermesCapabilities) private var capabilitiesStore
@State private var name: String = "" @State private var name: String = ""
@State private var transport: MCPTransport = .stdio @State private var transport: MCPTransport = .stdio
@State private var command: String = "npx" @State private var command: String = "npx"
@State private var argsText: String = "" @State private var argsText: String = ""
@State private var url: String = "" @State private var url: String = ""
@State private var auth: String = "none" @State private var auth: String = "none"
@State private var sseReadTimeout: String = ""
/// `.sse` is a v0.13+ surface; pre-v0.13 hosts only see stdio + http.
/// Iterating `MCPTransport.allCases` directly would render the SSE
/// segment unconditionally and Hermes would reject the resulting CLI
/// invocation at argparse time.
private var availableTransports: [MCPTransport] {
var t: [MCPTransport] = [.stdio, .http]
if capabilitiesStore?.capabilities.hasMCPSSETransport ?? false {
t.append(.sse)
}
return t
}
var body: some View { var body: some View {
VStack(spacing: 0) { VStack(spacing: 0) {
@@ -58,20 +44,17 @@ struct MCPServerAddCustomView: View {
} }
sectionBox(title: "Transport") { sectionBox(title: "Transport") {
Picker("", selection: $transport) { Picker("", selection: $transport) {
ForEach(availableTransports) { t in ForEach(MCPTransport.allCases) { t in
Text(t.displayName).tag(t) Text(t.displayName).tag(t)
} }
} }
.pickerStyle(.segmented) .pickerStyle(.segmented)
.labelsHidden() .labelsHidden()
} }
switch transport { if transport == .stdio {
case .stdio:
stdioSection stdioSection
case .http: } else {
httpSection httpSection
case .sse:
sseSection
} }
Text("Env vars, headers, and tool filters can be edited after the server is added.") Text("Env vars, headers, and tool filters can be edited after the server is added.")
.font(.caption) .font(.caption)
@@ -129,28 +112,6 @@ struct MCPServerAddCustomView: View {
} }
} }
private var sseSection: some View {
sectionBox(title: "Endpoint (SSE)") {
VStack(alignment: .leading, spacing: 8) {
VStack(alignment: .leading, spacing: 4) {
Text("URL").font(.caption.bold())
TextField("https://.../sse", text: $url)
.textFieldStyle(.roundedBorder)
.font(.system(.body, design: .monospaced))
}
VStack(alignment: .leading, spacing: 4) {
Text("SSE Read Timeout (seconds)").font(.caption.bold())
TextField("default 300", text: $sseReadTimeout)
.textFieldStyle(.roundedBorder)
.frame(maxWidth: 140)
Text("Hermes-side keepalive interval. Leave blank to use the default.")
.font(.caption2)
.foregroundStyle(.secondary)
}
}
}
}
private var canSubmit: Bool { private var canSubmit: Bool {
let trimmedName = name.trimmingCharacters(in: .whitespaces) let trimmedName = name.trimmingCharacters(in: .whitespaces)
guard !trimmedName.isEmpty else { return false } guard !trimmedName.isEmpty else { return false }
@@ -159,8 +120,6 @@ struct MCPServerAddCustomView: View {
return !command.trimmingCharacters(in: .whitespaces).isEmpty return !command.trimmingCharacters(in: .whitespaces).isEmpty
case .http: case .http:
return !url.trimmingCharacters(in: .whitespaces).isEmpty return !url.trimmingCharacters(in: .whitespaces).isEmpty
case .sse:
return !url.trimmingCharacters(in: .whitespaces).isEmpty
} }
} }
@@ -171,25 +130,14 @@ struct MCPServerAddCustomView: View {
.map { $0.trimmingCharacters(in: .whitespaces) } .map { $0.trimmingCharacters(in: .whitespaces) }
.filter { !$0.isEmpty } .filter { !$0.isEmpty }
let resolvedAuth: String? = (auth == "none") ? nil : auth let resolvedAuth: String? = (auth == "none") ? nil : auth
switch transport { viewModel.addCustom(
case .stdio, .http: name: trimmedName,
viewModel.addCustom( transport: transport,
name: trimmedName, command: command.trimmingCharacters(in: .whitespaces),
transport: transport, args: args,
command: command.trimmingCharacters(in: .whitespaces), url: url.trimmingCharacters(in: .whitespaces),
args: args, auth: resolvedAuth
url: url.trimmingCharacters(in: .whitespaces), )
auth: resolvedAuth
)
case .sse:
let trimmedTimeout = sseReadTimeout.trimmingCharacters(in: .whitespaces)
let parsedTimeout: Int? = trimmedTimeout.isEmpty ? nil : Int(trimmedTimeout)
viewModel.addCustomSSE(
name: trimmedName,
url: url.trimmingCharacters(in: .whitespaces),
sseReadTimeout: parsedTimeout
)
}
dismiss() dismiss()
} }
@@ -127,11 +127,6 @@ struct MCPServerDetailView: View {
if let auth = server.auth, !auth.isEmpty { if let auth = server.auth, !auth.isEmpty {
summaryRow(label: "Auth", value: auth) summaryRow(label: "Auth", value: auth)
} }
case .sse:
summaryRow(label: "URL", value: server.url ?? "")
if let timeout = server.sseReadTimeout {
summaryRow(label: "Read TO", value: "\(timeout)s")
}
} }
} }
.padding(ScarfSpace.s3) .padding(ScarfSpace.s3)
@@ -186,16 +186,6 @@ struct MCPServerEditorView: View {
.textFieldStyle(.roundedBorder) .textFieldStyle(.roundedBorder)
.frame(maxWidth: 140) .frame(maxWidth: 140)
} }
if viewModel.server.transport == .sse {
VStack(alignment: .leading, spacing: 4) {
Text("SSE read timeout")
.font(.caption)
.foregroundStyle(.secondary)
TextField("default 300", text: $viewModel.sseReadTimeoutDraft)
.textFieldStyle(.roundedBorder)
.frame(maxWidth: 140)
}
}
Spacer() Spacer()
} }
} }
@@ -132,14 +132,6 @@ struct MCPServersView: View {
} }
} }
} }
if !viewModel.sseServers.isEmpty {
Section("Remote (SSE)") {
ForEach(viewModel.sseServers) { server in
serverRow(server)
.tag(server.name as String?)
}
}
}
if viewModel.servers.isEmpty && !viewModel.isLoading { if viewModel.servers.isEmpty && !viewModel.isLoading {
Section { Section {
Text("No servers configured yet") Text("No servers configured yet")
@@ -112,17 +112,10 @@ final class ProfilesViewModel {
} }
} }
func create(name: String, cloneConfig: Bool, cloneAll: Bool, noSkills: Bool = false) { func create(name: String, cloneConfig: Bool, cloneAll: Bool) {
var args = ["profile", "create", name] var args = ["profile", "create", name]
if cloneAll { args.append("--clone-all") } if cloneAll { args.append("--clone-all") }
else if cloneConfig { args.append("--clone") } else if cloneConfig { args.append("--clone") }
// v0.13+: Empty-profile creation. The wire is independent of
// --clone / --clone-all per the v0.13 release notes the user
// can stack `--clone --no-skills` to clone config but skip
// skills, which is a plausible workflow. The UI still disables
// the toggle under --clone-all (Decision H, see ProfilesView)
// but the wire is permissive.
if noSkills { args.append("--no-skills") }
runAndReload(args, success: "Profile '\(name)' created") runAndReload(args, success: "Profile '\(name)' created")
} }
@@ -11,12 +11,7 @@ struct ProfilesView: View {
@State private var createName = "" @State private var createName = ""
@State private var createCloneConfig = true @State private var createCloneConfig = true
@State private var createCloneAll = false @State private var createCloneAll = false
/// v0.13+ `--no-skills` toggle. Mutually exclusive with `--clone-all`
/// at the UX layer (Decision H from the WS-7 plan): a full clone
/// copies skills wholesale `--no-skills` would be a contradiction.
@State private var createNoSkills = false
@State private var showRename = false @State private var showRename = false
@Environment(\.hermesCapabilities) private var capabilitiesStore
init(context: ServerContext) { init(context: ServerContext) {
_viewModel = State(initialValue: ProfilesViewModel(context: context)) _viewModel = State(initialValue: ProfilesViewModel(context: context))
@@ -128,7 +123,7 @@ struct ProfilesView: View {
} }
Spacer() Spacer()
Button { Button {
createName = ""; createCloneConfig = true; createCloneAll = false; createNoSkills = false createName = ""; createCloneConfig = true; createCloneAll = false
showCreate = true showCreate = true
} label: { } label: {
Label("Create", systemImage: "plus") Label("Create", systemImage: "plus")
@@ -305,31 +300,11 @@ struct ProfilesView: View {
Toggle("Clone config, .env, SOUL.md from active profile", isOn: $createCloneConfig) Toggle("Clone config, .env, SOUL.md from active profile", isOn: $createCloneConfig)
.disabled(createCloneAll) .disabled(createCloneAll)
Toggle("Full copy of active profile (all state)", isOn: $createCloneAll) Toggle("Full copy of active profile (all state)", isOn: $createCloneAll)
// TODO(WS-7-Q8): Decision H disable --no-skills when --clone-all
// is on. A full clone copies skills wholesale; --no-skills would
// be a contradiction. Verify Hermes's behaviour with both flags
// (argparse mutual exclusion vs. last-flag-wins vs. clone-but-
// skip-skills) and relax the disabled state if Hermes does
// something useful with the combination.
if capabilitiesStore?.capabilities.hasProfileNoSkills ?? false {
Toggle("Empty profile (no skills)", isOn: $createNoSkills)
.disabled(createCloneAll)
}
HStack { HStack {
Spacer() Spacer()
Button("Cancel") { showCreate = false } Button("Cancel") { showCreate = false }
Button("Create") { Button("Create") {
viewModel.create( viewModel.create(name: createName, cloneConfig: createCloneConfig, cloneAll: createCloneAll)
name: createName,
cloneConfig: createCloneConfig,
cloneAll: createCloneAll,
// Defensive: if the toggle isn't visible (pre-v0.13)
// the state is always `false`, but read it through
// the capability gate anyway so a stale state value
// can't sneak `--no-skills` to a CLI that doesn't
// know it.
noSkills: (capabilitiesStore?.capabilities.hasProfileNoSkills ?? false) ? createNoSkills : false
)
showCreate = false showCreate = false
} }
.buttonStyle(.borderedProminent) .buttonStyle(.borderedProminent)
@@ -143,16 +143,6 @@ final class SettingsViewModel {
func setBrowserAllowPrivateURLs(_ value: Bool) { setSetting("browser.allow_private_urls", value: value ? "true" : "false") } func setBrowserAllowPrivateURLs(_ value: Bool) { setSetting("browser.allow_private_urls", value: value ? "true" : "false") }
func setCamofoxManagedPersistence(_ value: Bool) { setSetting("browser.camofox.managed_persistence", value: value ? "true" : "false") } func setCamofoxManagedPersistence(_ value: Bool) { setSetting("browser.camofox.managed_persistence", value: value ? "true" : "false") }
// MARK: - Web Tools
/// Pre-v0.13 combined backend. Pre-v0.13 hosts read this; v0.13+
/// hosts read it for back-compat but the WebToolsTab gates writes
/// on `hasWebToolsBackendSplit` so the tab only writes the split
/// keys on v0.13.
func setWebToolsBackend(_ value: String) { setSetting("web_tools.backend", value: value) }
func setWebToolsSearchBackend(_ value: String) { setSetting("web_tools.search.backend", value: value) }
func setWebToolsExtractBackend(_ value: String) { setSetting("web_tools.extract.backend", value: value) }
// MARK: - Voice / TTS / STT // MARK: - Voice / TTS / STT
func setAutoTTS(_ value: Bool) { setSetting("voice.auto_tts", value: value ? "true" : "false") } func setAutoTTS(_ value: Bool) { setSetting("voice.auto_tts", value: value ? "true" : "false") }
@@ -26,7 +26,6 @@ struct SettingsView: View {
case agent = "Agent" case agent = "Agent"
case terminal = "Terminal" case terminal = "Terminal"
case browser = "Browser" case browser = "Browser"
case webTools = "Web Tools"
case voice = "Voice" case voice = "Voice"
case memory = "Memory" case memory = "Memory"
case auxiliary = "Aux Models" case auxiliary = "Aux Models"
@@ -42,7 +41,6 @@ struct SettingsView: View {
case .agent: return "Agent" case .agent: return "Agent"
case .terminal: return "Terminal" case .terminal: return "Terminal"
case .browser: return "Browser" case .browser: return "Browser"
case .webTools: return "Web Tools"
case .voice: return "Voice" case .voice: return "Voice"
case .memory: return "Memory" case .memory: return "Memory"
case .auxiliary: return "Aux Models" case .auxiliary: return "Aux Models"
@@ -58,7 +56,6 @@ struct SettingsView: View {
case .agent: return "brain.head.profile" case .agent: return "brain.head.profile"
case .terminal: return "terminal" case .terminal: return "terminal"
case .browser: return "globe" case .browser: return "globe"
case .webTools: return "globe.americas"
case .voice: return "mic" case .voice: return "mic"
case .memory: return "memorychip" case .memory: return "memorychip"
case .auxiliary: return "sparkles.rectangle.stack" case .auxiliary: return "sparkles.rectangle.stack"
@@ -174,7 +171,6 @@ struct SettingsView: View {
case .agent: AgentTab(viewModel: viewModel) case .agent: AgentTab(viewModel: viewModel)
case .terminal: TerminalTab(viewModel: viewModel) case .terminal: TerminalTab(viewModel: viewModel)
case .browser: BrowserTab(viewModel: viewModel) case .browser: BrowserTab(viewModel: viewModel)
case .webTools: WebToolsTab(viewModel: viewModel)
case .voice: VoiceTab(viewModel: viewModel) case .voice: VoiceTab(viewModel: viewModel)
case .memory: MemoryTab(viewModel: viewModel) case .memory: MemoryTab(viewModel: viewModel)
case .auxiliary: AuxiliaryTab(viewModel: viewModel) case .auxiliary: AuxiliaryTab(viewModel: viewModel)
@@ -1,76 +0,0 @@
import SwiftUI
import ScarfCore
import ScarfDesign
/// Web Tools tab search + extract backend pickers. Pre-v0.13 hosts
/// see a single "Combined backend" row writing to the legacy
/// `web_tools.backend` key. v0.13+ hosts see two rows writing to the
/// per-capability split keys (`web_tools.search.backend` +
/// `web_tools.extract.backend`); SearXNG appears in the search picker
/// only because Hermes registers it as a search-only backend.
struct WebToolsTab: View {
@Bindable var viewModel: SettingsViewModel
@Environment(\.hermesCapabilities) private var capabilitiesStore
private var split: Bool {
capabilitiesStore?.capabilities.hasWebToolsBackendSplit ?? false
}
// TODO(WS-7-Q6): Backend lists are curated inline based on the v0.13
// release notes ("SearXNG joined search-only"). The exact dispatch
// table lives in `~/.hermes/hermes-agent/hermes_cli/web_tools.py`
// verify during integration. A wrong entry just produces a
// `hermes config set` failure on save (recoverable, not silent).
private static let searchBackends: [String] = [
"duckduckgo", "tavily", "brave", "exa", "you", "searxng"
]
private static let extractBackends: [String] = [
"reader", "browserless", "trafilatura", "firecrawl"
]
/// v0.12 combined-backend list superset of the v0.13 search list
/// minus SearXNG (which only dispatches as search) plus the v0.13
/// extract-only entries that pre-v0.13 hosts handled under the
/// combined key.
private static let combinedBackends: [String] = [
"duckduckgo", "tavily", "brave", "exa", "you",
"reader", "browserless", "trafilatura", "firecrawl"
]
var body: some View {
if split {
SettingsSection(title: "Web Tools", icon: "globe.americas") {
PickerRow(
label: "Search backend",
selection: viewModel.config.webToolsSearchBackend,
options: Self.searchBackends
) { viewModel.setWebToolsSearchBackend($0) }
PickerRow(
label: "Extract backend",
selection: viewModel.config.webToolsExtractBackend,
options: Self.extractBackends
) { viewModel.setWebToolsExtractBackend($0) }
}
Text("SearXNG joined v0.13 as a search-only backend. Backend-specific tuning (host URLs, API keys) lives in the raw YAML editor for now.")
.scarfStyle(.caption)
.foregroundStyle(ScarfColor.foregroundMuted)
.padding(.horizontal, ScarfSpace.s4)
} else {
// TODO(WS-7-Q7): Pre-v0.13 hosts fall back to the legacy single
// backend. v0.13 may or may not honour `web_tools.backend` as a
// fallback when the split keys are absent verify with Hermes
// and consider a one-time migration prompt in a follow-up if
// upgrading from v0.12 silently resets the user's backend.
SettingsSection(title: "Web Tools", icon: "globe.americas") {
PickerRow(
label: "Backend",
selection: viewModel.config.webToolsBackend,
options: Self.combinedBackends
) { viewModel.setWebToolsBackend($0) }
}
Text("Hermes v0.13 splits search and extract into separate backends. Update Hermes to access the per-capability picker.")
.scarfStyle(.caption)
.foregroundStyle(ScarfColor.foregroundFaint)
.padding(.horizontal, ScarfSpace.s4)
}
}
}