mirror of
https://github.com/awizemann/scarf.git
synced 2026-05-10 18:44:45 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cedee04f2a |
@@ -1,34 +0,0 @@
|
|||||||
import Foundation
|
|
||||||
|
|
||||||
/// Errors thrown by `CuratorService`. Each case carries enough detail
|
|
||||||
/// to render a user-actionable message — the view model surfaces these
|
|
||||||
/// inline as a banner above the leaderboard rather than blocking with a
|
|
||||||
/// modal alert.
|
|
||||||
public enum CuratorError: Error, LocalizedError, Sendable {
|
|
||||||
/// `hermes` binary couldn't be located.
|
|
||||||
case cliMissing
|
|
||||||
/// Subprocess returned non-zero exit. `stderr` may carry a synthetic
|
|
||||||
/// message when the transport itself failed.
|
|
||||||
case nonZeroExit(verb: String, code: Int32, stderr: String)
|
|
||||||
/// JSON decoding failed. Underlying message wrapped for diagnostics.
|
|
||||||
case decoding(verb: String, message: String)
|
|
||||||
/// Generic transport error — process couldn't start, IO failed, etc.
|
|
||||||
case transport(message: String)
|
|
||||||
|
|
||||||
public var errorDescription: String? {
|
|
||||||
switch self {
|
|
||||||
case .cliMissing:
|
|
||||||
return "Hermes CLI couldn't be found. Install Hermes v0.13+ and ensure it's on your PATH."
|
|
||||||
case .nonZeroExit(let verb, let code, let stderr):
|
|
||||||
let trimmed = stderr.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
||||||
if trimmed.isEmpty {
|
|
||||||
return "`hermes curator \(verb)` exited with code \(code)."
|
|
||||||
}
|
|
||||||
return trimmed
|
|
||||||
case .decoding(let verb, let message):
|
|
||||||
return "Couldn't decode `hermes curator \(verb)` output: \(message)"
|
|
||||||
case .transport(let message):
|
|
||||||
return message
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
import Foundation
|
|
||||||
|
|
||||||
/// One entry in the `hermes curator list-archived` output. Decoded
|
|
||||||
/// tolerantly via `decodeIfPresent` so a stripped-down host (or a future
|
|
||||||
/// Hermes that drops one of the optional columns) doesn't crash the view.
|
|
||||||
///
|
|
||||||
/// Only `name` is required — every other field is optional and the
|
|
||||||
/// computed `*Label` accessors render `"—"` for missing values.
|
|
||||||
public struct HermesCuratorArchivedSkill: Sendable, Equatable, Identifiable, Codable {
|
|
||||||
public var id: String { name }
|
|
||||||
public let name: String
|
|
||||||
public let category: String?
|
|
||||||
public let archivedAt: String?
|
|
||||||
public let reason: String?
|
|
||||||
public let sizeBytes: Int?
|
|
||||||
public let path: String?
|
|
||||||
|
|
||||||
public init(
|
|
||||||
name: String,
|
|
||||||
category: String? = nil,
|
|
||||||
archivedAt: String? = nil,
|
|
||||||
reason: String? = nil,
|
|
||||||
sizeBytes: Int? = nil,
|
|
||||||
path: String? = nil
|
|
||||||
) {
|
|
||||||
self.name = name
|
|
||||||
self.category = category
|
|
||||||
self.archivedAt = archivedAt
|
|
||||||
self.reason = reason
|
|
||||||
self.sizeBytes = sizeBytes
|
|
||||||
self.path = path
|
|
||||||
}
|
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
|
||||||
case name
|
|
||||||
case category
|
|
||||||
case archivedAt = "archived_at"
|
|
||||||
case reason
|
|
||||||
case sizeBytes = "size_bytes"
|
|
||||||
case path
|
|
||||||
}
|
|
||||||
|
|
||||||
public init(from decoder: Decoder) throws {
|
|
||||||
let c = try decoder.container(keyedBy: CodingKeys.self)
|
|
||||||
self.name = try c.decode(String.self, forKey: .name)
|
|
||||||
self.category = try c.decodeIfPresent(String.self, forKey: .category)
|
|
||||||
self.archivedAt = try c.decodeIfPresent(String.self, forKey: .archivedAt)
|
|
||||||
self.reason = try c.decodeIfPresent(String.self, forKey: .reason)
|
|
||||||
self.sizeBytes = try c.decodeIfPresent(Int.self, forKey: .sizeBytes)
|
|
||||||
self.path = try c.decodeIfPresent(String.self, forKey: .path)
|
|
||||||
}
|
|
||||||
|
|
||||||
public func encode(to encoder: Encoder) throws {
|
|
||||||
var c = encoder.container(keyedBy: CodingKeys.self)
|
|
||||||
try c.encode(name, forKey: .name)
|
|
||||||
try c.encodeIfPresent(category, forKey: .category)
|
|
||||||
try c.encodeIfPresent(archivedAt, forKey: .archivedAt)
|
|
||||||
try c.encodeIfPresent(reason, forKey: .reason)
|
|
||||||
try c.encodeIfPresent(sizeBytes, forKey: .sizeBytes)
|
|
||||||
try c.encodeIfPresent(path, forKey: .path)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// "4.4 KB" / "1.2 MB" / "—" for nil. Uses the SI byte formatter so
|
|
||||||
/// the labels match what Finder shows.
|
|
||||||
public var sizeLabel: String {
|
|
||||||
guard let bytes = sizeBytes else { return "—" }
|
|
||||||
let formatter = ByteCountFormatter()
|
|
||||||
formatter.allowedUnits = [.useAll]
|
|
||||||
formatter.countStyle = .file
|
|
||||||
return formatter.string(fromByteCount: Int64(bytes))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `2026-04-22` (ISO date prefix) / "—". Hermes returns full ISO
|
|
||||||
/// timestamps with seconds + Z; the date prefix is what the user
|
|
||||||
/// actually wants in the archived list.
|
|
||||||
public var archivedAtLabel: String {
|
|
||||||
guard let iso = archivedAt, !iso.isEmpty else { return "—" }
|
|
||||||
// Trim to date prefix if it looks like a full ISO timestamp.
|
|
||||||
if let tIdx = iso.firstIndex(of: "T") {
|
|
||||||
return String(iso[..<tIdx])
|
|
||||||
}
|
|
||||||
return iso
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Result of `hermes curator prune --dry-run` — what would be removed
|
|
||||||
/// if the user confirms. The view derives `totalCount` from
|
|
||||||
/// `wouldRemove.count` so the wire shape stays flat.
|
|
||||||
public struct CuratorPruneSummary: Sendable, Equatable, Codable {
|
|
||||||
public let wouldRemove: [HermesCuratorArchivedSkill]
|
|
||||||
public let totalBytes: Int
|
|
||||||
public var totalCount: Int { wouldRemove.count }
|
|
||||||
|
|
||||||
public init(wouldRemove: [HermesCuratorArchivedSkill], totalBytes: Int) {
|
|
||||||
self.wouldRemove = wouldRemove
|
|
||||||
self.totalBytes = totalBytes
|
|
||||||
}
|
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
|
||||||
case wouldRemove = "would_remove"
|
|
||||||
case totalBytes = "total_bytes"
|
|
||||||
}
|
|
||||||
|
|
||||||
public init(from decoder: Decoder) throws {
|
|
||||||
let c = try decoder.container(keyedBy: CodingKeys.self)
|
|
||||||
self.wouldRemove = try c.decodeIfPresent([HermesCuratorArchivedSkill].self, forKey: .wouldRemove) ?? []
|
|
||||||
self.totalBytes = try c.decodeIfPresent(Int.self, forKey: .totalBytes) ?? 0
|
|
||||||
}
|
|
||||||
|
|
||||||
public func encode(to encoder: Encoder) throws {
|
|
||||||
var c = encoder.container(keyedBy: CodingKeys.self)
|
|
||||||
try c.encode(wouldRemove, forKey: .wouldRemove)
|
|
||||||
try c.encode(totalBytes, forKey: .totalBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// "12.3 KB" / "—" for empty. Convenience for the confirm sheet header.
|
|
||||||
public var totalBytesLabel: String {
|
|
||||||
guard totalBytes > 0 else { return "—" }
|
|
||||||
let formatter = ByteCountFormatter()
|
|
||||||
formatter.allowedUnits = [.useAll]
|
|
||||||
formatter.countStyle = .file
|
|
||||||
return formatter.string(fromByteCount: Int64(totalBytes))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
/// A structured signal Hermes emits when it observes worker / task
|
||||||
|
/// distress. Hermes v0.13 introduced a generic diagnostics engine that
|
||||||
|
/// attaches these to a task (cross-run signals) and/or a run (per-attempt
|
||||||
|
/// signals). Pre-v0.13 hosts never emit diagnostics so the array decodes
|
||||||
|
/// empty and downstream UI no-ops.
|
||||||
|
///
|
||||||
|
/// **Wire shape (best inference from release notes — verify against live
|
||||||
|
/// JSON during integration):** an array of objects with `kind`, optional
|
||||||
|
/// `message`, optional `detected_at` (ISO-8601 string OR Unix integer,
|
||||||
|
/// matching the rest of `HermesKanbanTask`'s timestamp tolerance).
|
||||||
|
///
|
||||||
|
/// **Forward compat:** `kind` stays a `String` so a future Hermes can
|
||||||
|
/// add new diagnostic kinds without a Scarf release. `KanbanDiagnosticKind`
|
||||||
|
/// is the typed mirror — it falls back to `.unknown` for unrecognized
|
||||||
|
/// kinds and renders the raw string verbatim.
|
||||||
|
public struct HermesKanbanDiagnostic: Sendable, Equatable, Identifiable, Codable {
|
||||||
|
/// Synthetic id — not on the wire. Lets SwiftUI `ForEach` over a
|
||||||
|
/// diagnostic array without forcing a deterministic id from the
|
||||||
|
/// server (Hermes doesn't currently mint one).
|
||||||
|
public let id: UUID
|
||||||
|
/// Wire-side `kind` string. Compared case-insensitively via
|
||||||
|
/// `KanbanDiagnosticKind.from(_:)`.
|
||||||
|
public let kind: String
|
||||||
|
/// Human-friendly elaboration ("no heartbeat for 4m20s", "exit code
|
||||||
|
/// 0 with no complete call", etc.). May be nil; render the raw
|
||||||
|
/// `kind` then.
|
||||||
|
public let message: String?
|
||||||
|
/// ISO-8601 string. Decoder accepts Unix integer seconds (Hermes's
|
||||||
|
/// SQLite-backed shape) and converts to ISO-8601 so consumers see
|
||||||
|
/// one type — same pattern as `HermesKanbanTask.decodeFlexibleTimestamp`.
|
||||||
|
public let detectedAt: String?
|
||||||
|
|
||||||
|
public init(
|
||||||
|
kind: String,
|
||||||
|
message: String? = nil,
|
||||||
|
detectedAt: String? = nil
|
||||||
|
) {
|
||||||
|
self.id = UUID()
|
||||||
|
self.kind = kind
|
||||||
|
self.message = message
|
||||||
|
self.detectedAt = detectedAt
|
||||||
|
}
|
||||||
|
|
||||||
|
enum CodingKeys: String, CodingKey {
|
||||||
|
case kind
|
||||||
|
case message
|
||||||
|
case detectedAt = "detected_at"
|
||||||
|
}
|
||||||
|
|
||||||
|
public init(from decoder: any Decoder) throws {
|
||||||
|
let c = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
self.id = UUID()
|
||||||
|
self.kind = try c.decodeIfPresent(String.self, forKey: .kind) ?? "unknown"
|
||||||
|
self.message = try c.decodeIfPresent(String.self, forKey: .message)
|
||||||
|
// Flexible timestamp decode mirrors HermesKanbanTask's pattern.
|
||||||
|
if !c.contains(.detectedAt) {
|
||||||
|
self.detectedAt = nil
|
||||||
|
} else if let unix = try? c.decodeIfPresent(Double.self, forKey: .detectedAt) {
|
||||||
|
let date = Date(timeIntervalSince1970: unix)
|
||||||
|
self.detectedAt = Self.isoFormatter.string(from: date)
|
||||||
|
} else {
|
||||||
|
self.detectedAt = try c.decodeIfPresent(String.self, forKey: .detectedAt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public func encode(to encoder: any Encoder) throws {
|
||||||
|
var c = encoder.container(keyedBy: CodingKeys.self)
|
||||||
|
try c.encode(kind, forKey: .kind)
|
||||||
|
try c.encodeIfPresent(message, forKey: .message)
|
||||||
|
try c.encodeIfPresent(detectedAt, forKey: .detectedAt)
|
||||||
|
}
|
||||||
|
|
||||||
|
public static func == (lhs: HermesKanbanDiagnostic, rhs: HermesKanbanDiagnostic) -> Bool {
|
||||||
|
// Compare on wire fields, not synthetic id — round-trip decoding
|
||||||
|
// mints fresh ids.
|
||||||
|
lhs.kind == rhs.kind
|
||||||
|
&& lhs.message == rhs.message
|
||||||
|
&& lhs.detectedAt == rhs.detectedAt
|
||||||
|
}
|
||||||
|
|
||||||
|
private static let isoFormatter: ISO8601DateFormatter = {
|
||||||
|
let f = ISO8601DateFormatter()
|
||||||
|
f.formatOptions = [.withInternetDateTime]
|
||||||
|
return f
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Typed mirror
|
||||||
|
|
||||||
|
/// Typed view of `HermesKanbanDiagnostic.kind`. Models keep the raw
|
||||||
|
/// string for forward compatibility; UI helpers read this enum to pick
|
||||||
|
/// the right glyph + tint without string-matching at every callsite.
|
||||||
|
///
|
||||||
|
/// `unknown` is the fallback for any kind a future Hermes adds that
|
||||||
|
/// Scarf doesn't recognize. Views render the raw string verbatim in
|
||||||
|
/// that case so the user still sees what Hermes flagged.
|
||||||
|
// TODO(WS-3-Q5): The exact `kind` string for darwin-zombie detection is
|
||||||
|
// inferred from the v0.13 release notes ("Detect darwin zombie workers");
|
||||||
|
// confirm against live `hermes kanban show --json` output during
|
||||||
|
// integration. Same for `worker_exit_no_complete` and the heartbeat-stalled
|
||||||
|
// kinds — typed mirror falls through to `.unknown` if the wire string
|
||||||
|
// drifts, and the raw string is still rendered.
|
||||||
|
public enum KanbanDiagnosticKind: String, Sendable, CaseIterable {
|
||||||
|
case heartbeatStalled = "heartbeat_stalled"
|
||||||
|
case toolErrorLoop = "tool_error_loop"
|
||||||
|
case retryCapHit = "retry_cap_hit"
|
||||||
|
case unboundedRetry = "unbounded_retry"
|
||||||
|
case darwinZombieDetected = "darwin_zombie_detected"
|
||||||
|
case spawnFailure = "spawn_failure"
|
||||||
|
case workerExitNoComplete = "worker_exit_no_complete"
|
||||||
|
case unknown
|
||||||
|
|
||||||
|
/// Map a wire string (case-insensitive) to a typed kind. Unknown
|
||||||
|
/// values fall through to `.unknown` so callers can still surface
|
||||||
|
/// the raw string.
|
||||||
|
public static func from(_ raw: String) -> KanbanDiagnosticKind {
|
||||||
|
KanbanDiagnosticKind(rawValue: raw.lowercased()) ?? .unknown
|
||||||
|
}
|
||||||
|
|
||||||
|
/// SF Symbol name to render alongside the diagnostic. View code
|
||||||
|
/// reaches through the typed enum so glyph choices live in one
|
||||||
|
/// place.
|
||||||
|
public var glyphName: String {
|
||||||
|
switch self {
|
||||||
|
case .heartbeatStalled: return "waveform.path.badge.minus"
|
||||||
|
case .toolErrorLoop: return "arrow.triangle.2.circlepath.exclamationmark"
|
||||||
|
case .retryCapHit: return "nosign"
|
||||||
|
case .unboundedRetry: return "arrow.clockwise.circle.fill"
|
||||||
|
case .darwinZombieDetected: return "apple.logo"
|
||||||
|
case .spawnFailure: return "bolt.slash"
|
||||||
|
case .workerExitNoComplete: return "figure.walk.departure"
|
||||||
|
case .unknown: return "stethoscope"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Severity tier for this kind — drives badge tint. `.danger` for
|
||||||
|
/// terminal-class signals (retry cap hit, zombie, spawn failure);
|
||||||
|
/// `.warning` for recoverable signals (heartbeat stalled, tool
|
||||||
|
/// error loop); `.neutral` only for unknown / forward-compat kinds.
|
||||||
|
public var severity: DiagnosticSeverity {
|
||||||
|
switch self {
|
||||||
|
case .retryCapHit, .darwinZombieDetected, .spawnFailure:
|
||||||
|
return .danger
|
||||||
|
case .heartbeatStalled, .toolErrorLoop, .unboundedRetry, .workerExitNoComplete:
|
||||||
|
return .warning
|
||||||
|
case .unknown:
|
||||||
|
return .neutral
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum DiagnosticSeverity: Sendable {
|
||||||
|
case warning
|
||||||
|
case danger
|
||||||
|
case neutral
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,6 +24,19 @@ public struct HermesKanbanRun: Sendable, Equatable, Identifiable, Codable {
|
|||||||
/// raw string so we don't lock the typed shape.
|
/// raw string so we don't lock the typed shape.
|
||||||
public let metadataJSON: String?
|
public let metadataJSON: String?
|
||||||
|
|
||||||
|
// v0.13 (v2026.5.7) fields. Both Optional / empty-default so a v0.12
|
||||||
|
// host's run row decodes without error.
|
||||||
|
/// Per-attempt distress signals. Cross-run signals (retry cap hit,
|
||||||
|
/// etc.) hang off `HermesKanbanTask.diagnostics`; in-flight signals
|
||||||
|
/// (heartbeat stalled, darwin zombie detected) attach here.
|
||||||
|
public let diagnostics: [HermesKanbanDiagnostic]
|
||||||
|
/// Server-side unified failure counter (renamed from three separate
|
||||||
|
/// spawn / timeout / crash counters in v0.13). Optional — when nil,
|
||||||
|
/// callers fall back to counting failed runs in the runs array.
|
||||||
|
// TODO(WS-3-Q4): Verify whether v0.13 exposes this field on the per-run
|
||||||
|
// shape OR only at the task level. Tolerant decode handles either.
|
||||||
|
public let failureCount: Int?
|
||||||
|
|
||||||
public init(
|
public init(
|
||||||
id: Int,
|
id: Int,
|
||||||
taskId: String,
|
taskId: String,
|
||||||
@@ -40,7 +53,9 @@ public struct HermesKanbanRun: Sendable, Equatable, Identifiable, Codable {
|
|||||||
outcome: String? = nil,
|
outcome: String? = nil,
|
||||||
summary: String? = nil,
|
summary: String? = nil,
|
||||||
error: String? = nil,
|
error: String? = nil,
|
||||||
metadataJSON: String? = nil
|
metadataJSON: String? = nil,
|
||||||
|
diagnostics: [HermesKanbanDiagnostic] = [],
|
||||||
|
failureCount: Int? = nil
|
||||||
) {
|
) {
|
||||||
self.id = id
|
self.id = id
|
||||||
self.taskId = taskId
|
self.taskId = taskId
|
||||||
@@ -58,6 +73,8 @@ public struct HermesKanbanRun: Sendable, Equatable, Identifiable, Codable {
|
|||||||
self.summary = summary
|
self.summary = summary
|
||||||
self.error = error
|
self.error = error
|
||||||
self.metadataJSON = metadataJSON
|
self.metadataJSON = metadataJSON
|
||||||
|
self.diagnostics = diagnostics
|
||||||
|
self.failureCount = failureCount
|
||||||
}
|
}
|
||||||
|
|
||||||
enum CodingKeys: String, CodingKey {
|
enum CodingKeys: String, CodingKey {
|
||||||
@@ -77,6 +94,8 @@ public struct HermesKanbanRun: Sendable, Equatable, Identifiable, Codable {
|
|||||||
case summary
|
case summary
|
||||||
case error
|
case error
|
||||||
case metadata
|
case metadata
|
||||||
|
case diagnostics
|
||||||
|
case failureCount = "failure_count"
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(from decoder: any Decoder) throws {
|
public init(from decoder: any Decoder) throws {
|
||||||
@@ -120,6 +139,11 @@ public struct HermesKanbanRun: Sendable, Equatable, Identifiable, Codable {
|
|||||||
} else {
|
} else {
|
||||||
self.metadataJSON = nil
|
self.metadataJSON = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// v0.13 diagnostics array — `try?` so a malformed entry doesn't
|
||||||
|
// poison the whole run row. Empty default for pre-v0.13 hosts.
|
||||||
|
self.diagnostics = (try? c.decodeIfPresent([HermesKanbanDiagnostic].self, forKey: .diagnostics)) ?? []
|
||||||
|
self.failureCount = try c.decodeIfPresent(Int.self, forKey: .failureCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func encode(to encoder: any Encoder) throws {
|
public func encode(to encoder: any Encoder) throws {
|
||||||
@@ -140,5 +164,7 @@ public struct HermesKanbanRun: Sendable, Equatable, Identifiable, Codable {
|
|||||||
try c.encodeIfPresent(summary, forKey: .summary)
|
try c.encodeIfPresent(summary, forKey: .summary)
|
||||||
try c.encodeIfPresent(error, forKey: .error)
|
try c.encodeIfPresent(error, forKey: .error)
|
||||||
try c.encodeIfPresent(metadataJSON, forKey: .metadata)
|
try c.encodeIfPresent(metadataJSON, forKey: .metadata)
|
||||||
|
try c.encode(diagnostics, forKey: .diagnostics)
|
||||||
|
try c.encodeIfPresent(failureCount, forKey: .failureCount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,9 @@ import Foundation
|
|||||||
/// `link`/`unlink`, `comment`, `dispatch`).
|
/// `link`/`unlink`, `comment`, `dispatch`).
|
||||||
///
|
///
|
||||||
/// Hermes has no `update` verb — `priority` / `title` / `body` /
|
/// Hermes has no `update` verb — `priority` / `title` / `body` /
|
||||||
/// `tenant` are write-once at create time. Mutations after that are
|
/// `tenant` / `max_retries` are write-once at create time. Mutations
|
||||||
/// expressed as state transitions (status, assignee) or new comments.
|
/// after that are expressed as state transitions (status, assignee) or
|
||||||
|
/// new comments.
|
||||||
public struct HermesKanbanTask: Sendable, Equatable, Identifiable, Codable {
|
public struct HermesKanbanTask: Sendable, Equatable, Identifiable, Codable {
|
||||||
public let id: String
|
public let id: String
|
||||||
public let title: String
|
public let title: String
|
||||||
@@ -34,6 +35,29 @@ public struct HermesKanbanTask: Sendable, Equatable, Identifiable, Codable {
|
|||||||
public let maxRuntimeSeconds: Int?
|
public let maxRuntimeSeconds: Int?
|
||||||
public let currentRunId: Int?
|
public let currentRunId: Int?
|
||||||
|
|
||||||
|
// v0.13 (v2026.5.7) reliability + recovery fields. All Optional with
|
||||||
|
// `nil` decoded for pre-v0.13 hosts so the v2.7.5 surface keeps
|
||||||
|
// rendering unchanged when the connected Hermes hasn't shipped them.
|
||||||
|
/// Per-task retry budget set at create time via `--max-retries N`.
|
||||||
|
/// Hermes pattern is write-once — no `set_max_retries` verb. Scarf
|
||||||
|
/// surfaces this read-only on the inspector header.
|
||||||
|
public let maxRetries: Int?
|
||||||
|
/// Server-supplied reason a task was auto-blocked (e.g. "worker
|
||||||
|
/// exited (code 0) without calling `kanban complete`"). Surfaced
|
||||||
|
/// verbatim in the inspector banner.
|
||||||
|
public let autoBlockedReason: String?
|
||||||
|
/// `pending` / `verified` / `rejected` / nil. Pending means a worker
|
||||||
|
/// claimed it created this card but Hermes hasn't confirmed the
|
||||||
|
/// underlying work exists. Read through `KanbanHallucinationGate.from`
|
||||||
|
/// to map to a typed mirror — kept as a String at the wire level so
|
||||||
|
/// Hermes can add new gate states (e.g. `quarantined`) without a
|
||||||
|
/// Scarf release.
|
||||||
|
public let hallucinationGateStatus: String?
|
||||||
|
/// Cross-run distress signals (retry cap hit, etc.). Per-run signals
|
||||||
|
/// hang off `HermesKanbanRun.diagnostics`. Empty array for pre-v0.13
|
||||||
|
/// hosts AND for tasks the diagnostics engine hasn't flagged.
|
||||||
|
public let diagnostics: [HermesKanbanDiagnostic]
|
||||||
|
|
||||||
public init(
|
public init(
|
||||||
id: String,
|
id: String,
|
||||||
title: String,
|
title: String,
|
||||||
@@ -53,7 +77,11 @@ public struct HermesKanbanTask: Sendable, Equatable, Identifiable, Codable {
|
|||||||
idempotencyKey: String? = nil,
|
idempotencyKey: String? = nil,
|
||||||
lastHeartbeatAt: String? = nil,
|
lastHeartbeatAt: String? = nil,
|
||||||
maxRuntimeSeconds: Int? = nil,
|
maxRuntimeSeconds: Int? = nil,
|
||||||
currentRunId: Int? = nil
|
currentRunId: Int? = nil,
|
||||||
|
maxRetries: Int? = nil,
|
||||||
|
autoBlockedReason: String? = nil,
|
||||||
|
hallucinationGateStatus: String? = nil,
|
||||||
|
diagnostics: [HermesKanbanDiagnostic] = []
|
||||||
) {
|
) {
|
||||||
self.id = id
|
self.id = id
|
||||||
self.title = title
|
self.title = title
|
||||||
@@ -74,6 +102,10 @@ public struct HermesKanbanTask: Sendable, Equatable, Identifiable, Codable {
|
|||||||
self.lastHeartbeatAt = lastHeartbeatAt
|
self.lastHeartbeatAt = lastHeartbeatAt
|
||||||
self.maxRuntimeSeconds = maxRuntimeSeconds
|
self.maxRuntimeSeconds = maxRuntimeSeconds
|
||||||
self.currentRunId = currentRunId
|
self.currentRunId = currentRunId
|
||||||
|
self.maxRetries = maxRetries
|
||||||
|
self.autoBlockedReason = autoBlockedReason
|
||||||
|
self.hallucinationGateStatus = hallucinationGateStatus
|
||||||
|
self.diagnostics = diagnostics
|
||||||
}
|
}
|
||||||
|
|
||||||
enum CodingKeys: String, CodingKey {
|
enum CodingKeys: String, CodingKey {
|
||||||
@@ -89,6 +121,10 @@ public struct HermesKanbanTask: Sendable, Equatable, Identifiable, Codable {
|
|||||||
case lastHeartbeatAt = "last_heartbeat_at"
|
case lastHeartbeatAt = "last_heartbeat_at"
|
||||||
case maxRuntimeSeconds = "max_runtime_seconds"
|
case maxRuntimeSeconds = "max_runtime_seconds"
|
||||||
case currentRunId = "current_run_id"
|
case currentRunId = "current_run_id"
|
||||||
|
case maxRetries = "max_retries"
|
||||||
|
case autoBlockedReason = "auto_blocked_reason"
|
||||||
|
case hallucinationGateStatus = "hallucination_gate_status"
|
||||||
|
case diagnostics
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(from decoder: any Decoder) throws {
|
public init(from decoder: any Decoder) throws {
|
||||||
@@ -117,6 +153,17 @@ public struct HermesKanbanTask: Sendable, Equatable, Identifiable, Codable {
|
|||||||
self.lastHeartbeatAt = try Self.decodeFlexibleTimestamp(c, forKey: .lastHeartbeatAt)
|
self.lastHeartbeatAt = try Self.decodeFlexibleTimestamp(c, forKey: .lastHeartbeatAt)
|
||||||
self.maxRuntimeSeconds = try c.decodeIfPresent(Int.self, forKey: .maxRuntimeSeconds)
|
self.maxRuntimeSeconds = try c.decodeIfPresent(Int.self, forKey: .maxRuntimeSeconds)
|
||||||
self.currentRunId = try c.decodeIfPresent(Int.self, forKey: .currentRunId)
|
self.currentRunId = try c.decodeIfPresent(Int.self, forKey: .currentRunId)
|
||||||
|
// v0.13 fields — every one is `decodeIfPresent` so a v0.12 host's
|
||||||
|
// task row decodes successfully with these all nil/empty. The
|
||||||
|
// tolerant-decode contract is pinned by KanbanModelsTests.
|
||||||
|
self.maxRetries = try c.decodeIfPresent(Int.self, forKey: .maxRetries)
|
||||||
|
self.autoBlockedReason = try c.decodeIfPresent(String.self, forKey: .autoBlockedReason)
|
||||||
|
self.hallucinationGateStatus = try c.decodeIfPresent(String.self, forKey: .hallucinationGateStatus)
|
||||||
|
// Wrap diagnostics decode in `try?` so a single malformed entry
|
||||||
|
// (or the whole array being the wrong shape) doesn't poison the
|
||||||
|
// task row — the rest of the decoder still produces a usable
|
||||||
|
// task. Empty default matches the `skills` pattern.
|
||||||
|
self.diagnostics = (try? c.decodeIfPresent([HermesKanbanDiagnostic].self, forKey: .diagnostics)) ?? []
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Decode a timestamp that may arrive as a Unix integer or an
|
/// Decode a timestamp that may arrive as a Unix integer or an
|
||||||
@@ -209,3 +256,27 @@ public enum KanbanBoardColumn: String, Sendable, CaseIterable, Identifiable {
|
|||||||
.triage, .upNext, .running, .blocked, .done
|
.triage, .upNext, .running, .blocked, .done
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Hallucination gate (v0.13)
|
||||||
|
|
||||||
|
/// Typed mirror of Hermes v0.13's hallucination-gate state. Worker-created
|
||||||
|
/// cards land in `pending` until something verifies the underlying work
|
||||||
|
/// exists; Scarf surfaces a Verify / Reject UX above the task body so the
|
||||||
|
/// user can act as the verification gate.
|
||||||
|
///
|
||||||
|
/// Kept separate from `KanbanStatus` because hallucination state is
|
||||||
|
/// orthogonal to the lifecycle — a card can be `ready` *and* `pending`,
|
||||||
|
/// for example.
|
||||||
|
public enum KanbanHallucinationGate: String, Sendable, CaseIterable {
|
||||||
|
case pending
|
||||||
|
case verified
|
||||||
|
case rejected
|
||||||
|
|
||||||
|
/// Map a raw `hallucination_gate_status` string (case-insensitive) to
|
||||||
|
/// a typed gate. Returns nil for empty/nil/unknown values so callers
|
||||||
|
/// can short-circuit "no gate" branches with `if let gate = …`.
|
||||||
|
public static func from(_ raw: String?) -> KanbanHallucinationGate? {
|
||||||
|
guard let raw, !raw.isEmpty else { return nil }
|
||||||
|
return KanbanHallucinationGate(rawValue: raw.lowercased())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,17 +12,27 @@ public struct HermesKanbanTaskDetail: Sendable, Equatable, Codable {
|
|||||||
/// to the worker as upstream context; surfacing them in the
|
/// to the worker as upstream context; surfacing them in the
|
||||||
/// inspector is useful for understanding why a task started.
|
/// inspector is useful for understanding why a task started.
|
||||||
public let parentResults: [String: String]
|
public let parentResults: [String: String]
|
||||||
|
/// Envelope-level diagnostics array (sibling to `task`, not nested
|
||||||
|
/// inside it). Defensive — Hermes v0.13's wire shape may attach
|
||||||
|
/// diagnostics to the task itself OR to the envelope.
|
||||||
|
/// `allDiagnostics` dedupes both sources by `(kind, detected_at)`.
|
||||||
|
// TODO(WS-3-Q2): Confirm against live `hermes kanban show --json`
|
||||||
|
// whether diagnostics live on the task envelope, the inner task, or
|
||||||
|
// both. Current decode is tolerant of either.
|
||||||
|
public let envelopeDiagnostics: [HermesKanbanDiagnostic]?
|
||||||
|
|
||||||
public init(
|
public init(
|
||||||
task: HermesKanbanTask,
|
task: HermesKanbanTask,
|
||||||
comments: [HermesKanbanComment] = [],
|
comments: [HermesKanbanComment] = [],
|
||||||
events: [HermesKanbanEvent] = [],
|
events: [HermesKanbanEvent] = [],
|
||||||
parentResults: [String: String] = [:]
|
parentResults: [String: String] = [:],
|
||||||
|
envelopeDiagnostics: [HermesKanbanDiagnostic]? = nil
|
||||||
) {
|
) {
|
||||||
self.task = task
|
self.task = task
|
||||||
self.comments = comments
|
self.comments = comments
|
||||||
self.events = events
|
self.events = events
|
||||||
self.parentResults = parentResults
|
self.parentResults = parentResults
|
||||||
|
self.envelopeDiagnostics = envelopeDiagnostics
|
||||||
}
|
}
|
||||||
|
|
||||||
enum CodingKeys: String, CodingKey {
|
enum CodingKeys: String, CodingKey {
|
||||||
@@ -30,6 +40,7 @@ public struct HermesKanbanTaskDetail: Sendable, Equatable, Codable {
|
|||||||
case comments
|
case comments
|
||||||
case events
|
case events
|
||||||
case parentResults = "parent_results"
|
case parentResults = "parent_results"
|
||||||
|
case envelopeDiagnostics = "diagnostics"
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(from decoder: any Decoder) throws {
|
public init(from decoder: any Decoder) throws {
|
||||||
@@ -48,6 +59,9 @@ public struct HermesKanbanTaskDetail: Sendable, Equatable, Codable {
|
|||||||
self.comments = (try? container.decodeIfPresent([HermesKanbanComment].self, forKey: .comments)) ?? []
|
self.comments = (try? container.decodeIfPresent([HermesKanbanComment].self, forKey: .comments)) ?? []
|
||||||
self.events = (try? container.decodeIfPresent([HermesKanbanEvent].self, forKey: .events)) ?? []
|
self.events = (try? container.decodeIfPresent([HermesKanbanEvent].self, forKey: .events)) ?? []
|
||||||
self.parentResults = (try? container.decodeIfPresent([String: String].self, forKey: .parentResults)) ?? [:]
|
self.parentResults = (try? container.decodeIfPresent([String: String].self, forKey: .parentResults)) ?? [:]
|
||||||
|
// Same `try?` shield as the rest — a malformed envelope
|
||||||
|
// diagnostics array shouldn't reject the whole show response.
|
||||||
|
self.envelopeDiagnostics = try? container.decodeIfPresent([HermesKanbanDiagnostic].self, forKey: .envelopeDiagnostics)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func encode(to encoder: any Encoder) throws {
|
public func encode(to encoder: any Encoder) throws {
|
||||||
@@ -56,5 +70,20 @@ public struct HermesKanbanTaskDetail: Sendable, Equatable, Codable {
|
|||||||
try c.encode(comments, forKey: .comments)
|
try c.encode(comments, forKey: .comments)
|
||||||
try c.encode(events, forKey: .events)
|
try c.encode(events, forKey: .events)
|
||||||
try c.encode(parentResults, forKey: .parentResults)
|
try c.encode(parentResults, forKey: .parentResults)
|
||||||
|
try c.encodeIfPresent(envelopeDiagnostics, forKey: .envelopeDiagnostics)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Unified diagnostics view for the inspector. Combines `task.diagnostics`
|
||||||
|
/// with envelope-level diagnostics (when present) and dedupes on the
|
||||||
|
/// `(kind, detectedAt)` tuple. Wire-side dupes are unlikely but cheap to
|
||||||
|
/// filter. Empty for pre-v0.13 hosts.
|
||||||
|
public var allDiagnostics: [HermesKanbanDiagnostic] {
|
||||||
|
let onTask = task.diagnostics
|
||||||
|
let onEnvelope = envelopeDiagnostics ?? []
|
||||||
|
var seen = Set<String>()
|
||||||
|
return (onTask + onEnvelope).filter { diag in
|
||||||
|
let key = "\(diag.kind)|\(diag.detectedAt ?? "")"
|
||||||
|
return seen.insert(key).inserted
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,15 @@ public struct KanbanCreateRequest: Sendable, Equatable {
|
|||||||
public var maxRuntimeSeconds: Int?
|
public var maxRuntimeSeconds: Int?
|
||||||
public var createdBy: String?
|
public var createdBy: String?
|
||||||
public var skills: [String]
|
public var skills: [String]
|
||||||
|
/// v0.13: per-task retry budget. `--max-retries N` is write-once at
|
||||||
|
/// create time — no `set_max_retries` verb. Pass `nil` to let Hermes
|
||||||
|
/// pick its built-in default (3 as of v0.13.0). Capability-gated in
|
||||||
|
/// the create sheet on `hasKanbanDiagnostics`.
|
||||||
|
// TODO(WS-3-Q6): Confirm Hermes's global default for `max_retries`
|
||||||
|
// (v0.13 release notes don't enumerate it). The create sheet defaults
|
||||||
|
// the field to 3; if Hermes config exposes a different default, mirror
|
||||||
|
// it.
|
||||||
|
public var maxRetries: Int?
|
||||||
|
|
||||||
public init(
|
public init(
|
||||||
title: String,
|
title: String,
|
||||||
@@ -30,7 +39,8 @@ public struct KanbanCreateRequest: Sendable, Equatable {
|
|||||||
idempotencyKey: String? = nil,
|
idempotencyKey: String? = nil,
|
||||||
maxRuntimeSeconds: Int? = nil,
|
maxRuntimeSeconds: Int? = nil,
|
||||||
createdBy: String? = nil,
|
createdBy: String? = nil,
|
||||||
skills: [String] = []
|
skills: [String] = [],
|
||||||
|
maxRetries: Int? = nil
|
||||||
) {
|
) {
|
||||||
self.title = title
|
self.title = title
|
||||||
self.body = body
|
self.body = body
|
||||||
@@ -44,6 +54,7 @@ public struct KanbanCreateRequest: Sendable, Equatable {
|
|||||||
self.maxRuntimeSeconds = maxRuntimeSeconds
|
self.maxRuntimeSeconds = maxRuntimeSeconds
|
||||||
self.createdBy = createdBy
|
self.createdBy = createdBy
|
||||||
self.skills = skills
|
self.skills = skills
|
||||||
|
self.maxRetries = maxRetries
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build the argv suffix this request maps to (everything after
|
/// Build the argv suffix this request maps to (everything after
|
||||||
@@ -78,6 +89,9 @@ public struct KanbanCreateRequest: Sendable, Equatable {
|
|||||||
if let maxRuntimeSeconds {
|
if let maxRuntimeSeconds {
|
||||||
args.append(contentsOf: ["--max-runtime", "\(maxRuntimeSeconds)s"])
|
args.append(contentsOf: ["--max-runtime", "\(maxRuntimeSeconds)s"])
|
||||||
}
|
}
|
||||||
|
if let maxRetries {
|
||||||
|
args.append(contentsOf: ["--max-retries", String(maxRetries)])
|
||||||
|
}
|
||||||
if let createdBy, !createdBy.isEmpty {
|
if let createdBy, !createdBy.isEmpty {
|
||||||
args.append(contentsOf: ["--created-by", createdBy])
|
args.append(contentsOf: ["--created-by", createdBy])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,358 +0,0 @@
|
|||||||
import Foundation
|
|
||||||
#if canImport(os)
|
|
||||||
import os
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// Async, transport-aware client for `hermes curator …`. Wraps the v0.12
|
|
||||||
/// verbs (`status / run / pause / resume / pin / unpin / restore`) plus
|
|
||||||
/// the v0.13 archive surface (`archive / prune / list-archived` and a
|
|
||||||
/// synchronous-blocking `run`).
|
|
||||||
///
|
|
||||||
/// **Concurrency.** Pure-I/O `actor` — no UI state. View models hold a
|
|
||||||
/// service reference and `await` methods. Each public method dispatches
|
|
||||||
/// the underlying CLI invocation through `Task.detached(priority:
|
|
||||||
/// .utility)` so two concurrent reads from the VM don't queue end-to-end
|
|
||||||
/// on a single thread. Mirrors `KanbanService` shape exactly.
|
|
||||||
///
|
|
||||||
/// **Capability gating happens at the call site, not in the service.**
|
|
||||||
/// `runNow(synchronous:timeout:)` takes a flag from the VM (the VM reads
|
|
||||||
/// `HermesCapabilities.hasCuratorArchive` to decide). The service stays
|
|
||||||
/// version-agnostic — only the timeout differs in practice.
|
|
||||||
public actor CuratorService {
|
|
||||||
#if canImport(os)
|
|
||||||
private static let logger = Logger(subsystem: "com.scarf", category: "CuratorService")
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private let context: ServerContext
|
|
||||||
|
|
||||||
public init(context: ServerContext) {
|
|
||||||
self.context = context
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Reads
|
|
||||||
|
|
||||||
/// Run `hermes curator status` and parse stdout via
|
|
||||||
/// `HermesCuratorStatusParser`. Combines the text output with the
|
|
||||||
/// on-disk `.curator_state` JSON for richer last-run metadata.
|
|
||||||
/// Never throws — a transport failure resolves to `.empty` so the
|
|
||||||
/// view always has something to render.
|
|
||||||
public func status() async -> HermesCuratorStatus {
|
|
||||||
let context = self.context
|
|
||||||
return await Task.detached(priority: .utility) { () -> HermesCuratorStatus in
|
|
||||||
let textResult = Self.runHermesSync(context: context, args: ["curator", "status"], timeout: 30)
|
|
||||||
let stateData = context.readData(context.paths.curatorStateFile)
|
|
||||||
return HermesCuratorStatusParser.parse(text: textResult.output, stateFileJSON: stateData)
|
|
||||||
}.value
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `hermes curator list-archived [--json]`. Prefers JSON; falls back
|
|
||||||
/// to a defensive text parser. Empty / "no archived skills" sentinel
|
|
||||||
/// folds to `[]`.
|
|
||||||
public func listArchived() async throws -> [HermesCuratorArchivedSkill] {
|
|
||||||
// TODO(WS-4-Q2): confirm `--json` is supported on v0.13
|
|
||||||
// `list-archived`. If not, drop the flag and rely on the text
|
|
||||||
// parser path. Until then we pass `--json` and parse the output
|
|
||||||
// tolerantly.
|
|
||||||
let args = ["curator", "list-archived", "--json"]
|
|
||||||
let (code, stdout, stderr) = await runHermes(args: args, timeout: 30)
|
|
||||||
|
|
||||||
// If --json isn't recognized, the CLI typically emits
|
|
||||||
// "unrecognized arguments: --json" or similar to stderr and
|
|
||||||
// exits non-zero. Retry without the flag and parse text.
|
|
||||||
if code != 0 {
|
|
||||||
let lower = (stderr + stdout).lowercased()
|
|
||||||
if lower.contains("unrecognized") || lower.contains("unknown") || lower.contains("no such option") {
|
|
||||||
let (c2, out2, err2) = await runHermes(args: ["curator", "list-archived"], timeout: 30)
|
|
||||||
try ensureSuccess(code: c2, stdout: out2, stderr: err2, verb: "list-archived")
|
|
||||||
return Self.parseListArchivedText(out2)
|
|
||||||
}
|
|
||||||
try ensureSuccess(code: code, stdout: stdout, stderr: stderr, verb: "list-archived")
|
|
||||||
}
|
|
||||||
|
|
||||||
let trimmed = stdout.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
||||||
if trimmed.isEmpty || trimmed.lowercased().contains("no archived skills") {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
// Try JSON first — may also be a text dump if Hermes ignored `--json`.
|
|
||||||
if let data = trimmed.data(using: .utf8),
|
|
||||||
let arr = try? JSONDecoder().decode([HermesCuratorArchivedSkill].self, from: data) {
|
|
||||||
return arr
|
|
||||||
}
|
|
||||||
// Some builds wrap in `{"archived": [...]}` envelope.
|
|
||||||
struct Wrapper: Decodable { let archived: [HermesCuratorArchivedSkill] }
|
|
||||||
if let data = trimmed.data(using: .utf8),
|
|
||||||
let wrapped = try? JSONDecoder().decode(Wrapper.self, from: data) {
|
|
||||||
return wrapped.archived
|
|
||||||
}
|
|
||||||
// Text fallback — defensive parse.
|
|
||||||
return Self.parseListArchivedText(stdout)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Writes (legacy v0.12 verbs; service form)
|
|
||||||
|
|
||||||
public func runNow(synchronous: Bool, timeout: TimeInterval) async throws {
|
|
||||||
// TODO(WS-4-Q4): default 600s for v0.13 sync runs. No Cancel
|
|
||||||
// button in v2.8 (transport.cancel parity not guaranteed across
|
|
||||||
// LocalTransport / SSHTransport).
|
|
||||||
let resolvedTimeout = synchronous ? timeout : 30
|
|
||||||
let (code, stdout, stderr) = await runHermes(args: ["curator", "run"], timeout: resolvedTimeout)
|
|
||||||
try ensureSuccess(code: code, stdout: stdout, stderr: stderr, verb: "run")
|
|
||||||
}
|
|
||||||
|
|
||||||
public func pause() async throws {
|
|
||||||
let (code, stdout, stderr) = await runHermes(args: ["curator", "pause"], timeout: 15)
|
|
||||||
try ensureSuccess(code: code, stdout: stdout, stderr: stderr, verb: "pause")
|
|
||||||
}
|
|
||||||
|
|
||||||
public func resume() async throws {
|
|
||||||
let (code, stdout, stderr) = await runHermes(args: ["curator", "resume"], timeout: 15)
|
|
||||||
try ensureSuccess(code: code, stdout: stdout, stderr: stderr, verb: "resume")
|
|
||||||
}
|
|
||||||
|
|
||||||
public func pin(_ name: String) async throws {
|
|
||||||
let (code, stdout, stderr) = await runHermes(args: ["curator", "pin", name], timeout: 15)
|
|
||||||
try ensureSuccess(code: code, stdout: stdout, stderr: stderr, verb: "pin")
|
|
||||||
}
|
|
||||||
|
|
||||||
public func unpin(_ name: String) async throws {
|
|
||||||
let (code, stdout, stderr) = await runHermes(args: ["curator", "unpin", name], timeout: 15)
|
|
||||||
try ensureSuccess(code: code, stdout: stdout, stderr: stderr, verb: "unpin")
|
|
||||||
}
|
|
||||||
|
|
||||||
public func restore(_ name: String) async throws {
|
|
||||||
let (code, stdout, stderr) = await runHermes(args: ["curator", "restore", name], timeout: 30)
|
|
||||||
try ensureSuccess(code: code, stdout: stdout, stderr: stderr, verb: "restore")
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Writes (new in v0.13)
|
|
||||||
|
|
||||||
/// `hermes curator archive <name>` — non-destructive; moves the
|
|
||||||
/// skill from the active set to the archived set. No `--json` is
|
|
||||||
/// expected; the verb's success channel is the exit code.
|
|
||||||
public func archive(_ name: String) async throws {
|
|
||||||
let (code, stdout, stderr) = await runHermes(args: ["curator", "archive", name], timeout: 30)
|
|
||||||
try ensureSuccess(code: code, stdout: stdout, stderr: stderr, verb: "archive")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `hermes curator prune [--dry-run]`. Destructive when `dryRun`
|
|
||||||
/// is `false` — removes everything currently archived from disk.
|
|
||||||
/// Returns a `CuratorPruneSummary` describing what was (or would be)
|
|
||||||
/// removed. On `dryRun=false`, the wire shape may not include the
|
|
||||||
/// `would_remove` list — the caller should not depend on it; the
|
|
||||||
/// archived list is empty after a successful destructive prune.
|
|
||||||
@discardableResult
|
|
||||||
public func prune(dryRun: Bool) async throws -> CuratorPruneSummary {
|
|
||||||
// TODO(WS-4-Q1): confirm v0.13 ships `--dry-run`. If not, fall
|
|
||||||
// back to enumerating via `list-archived` and treat any prune
|
|
||||||
// call as destructive. The retry-without-flag path below covers
|
|
||||||
// the "unrecognized argument" case automatically.
|
|
||||||
var args = ["curator", "prune"]
|
|
||||||
if dryRun { args.append("--dry-run") }
|
|
||||||
// `--json` requested for the dry-run path so we can parse the
|
|
||||||
// would-remove list. Destructive mode runs without --json since
|
|
||||||
// we only need the exit code.
|
|
||||||
if dryRun { args.append("--json") }
|
|
||||||
|
|
||||||
let (code, stdout, stderr) = await runHermes(args: args, timeout: 60)
|
|
||||||
|
|
||||||
// Detect "unrecognized --dry-run" / "unknown --json" gracefully.
|
|
||||||
if code != 0 {
|
|
||||||
let lower = (stderr + stdout).lowercased()
|
|
||||||
let unrecognized = lower.contains("unrecognized") || lower.contains("unknown") || lower.contains("no such option")
|
|
||||||
if dryRun && unrecognized {
|
|
||||||
// Q1 fallback: enumerate via list-archived. Caller still
|
|
||||||
// uses this summary for confirm-sheet display.
|
|
||||||
let archived = try await listArchived()
|
|
||||||
let total = archived.compactMap { $0.sizeBytes }.reduce(0, +)
|
|
||||||
return CuratorPruneSummary(wouldRemove: archived, totalBytes: total)
|
|
||||||
}
|
|
||||||
try ensureSuccess(code: code, stdout: stdout, stderr: stderr, verb: "prune")
|
|
||||||
}
|
|
||||||
|
|
||||||
if dryRun {
|
|
||||||
return Self.parsePruneDryRun(stdout)
|
|
||||||
}
|
|
||||||
return CuratorPruneSummary(wouldRemove: [], totalBytes: 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Pure parsers (nonisolated; safe to call from VMs without awaits)
|
|
||||||
|
|
||||||
/// Parse a `list-archived --json` payload. Tolerates the bare-array
|
|
||||||
/// shape, the `{"archived": [...]}` envelope, and "no archived
|
|
||||||
/// skills" / empty-string sentinels. Returns `[]` for any of the
|
|
||||||
/// empty cases. Throws `CuratorError.decoding` only when the input
|
|
||||||
/// is non-empty and clearly not JSON.
|
|
||||||
public nonisolated static func parseListArchived(stdout: String) throws -> [HermesCuratorArchivedSkill] {
|
|
||||||
let trimmed = stdout.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
||||||
if trimmed.isEmpty || trimmed.lowercased().contains("no archived skills") {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
guard let data = trimmed.data(using: .utf8) else {
|
|
||||||
throw CuratorError.decoding(verb: "list-archived", message: "non-UTF8 stdout")
|
|
||||||
}
|
|
||||||
if let arr = try? JSONDecoder().decode([HermesCuratorArchivedSkill].self, from: data) {
|
|
||||||
return arr
|
|
||||||
}
|
|
||||||
struct Wrapper: Decodable { let archived: [HermesCuratorArchivedSkill] }
|
|
||||||
if let wrapped = try? JSONDecoder().decode(Wrapper.self, from: data) {
|
|
||||||
return wrapped.archived
|
|
||||||
}
|
|
||||||
// Last resort: text fallback.
|
|
||||||
let parsed = parseListArchivedText(stdout)
|
|
||||||
if !parsed.isEmpty {
|
|
||||||
return parsed
|
|
||||||
}
|
|
||||||
throw CuratorError.decoding(verb: "list-archived", message: "stdout was neither JSON nor a recognised text list")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Defensive text parser for `list-archived` output when `--json`
|
|
||||||
/// isn't supported. Format inferred from `curator status`: one row
|
|
||||||
/// per non-blank line, leading whitespace, name in column 1, then
|
|
||||||
/// optional `archived=YYYY-MM-DD`, `size=NNNN`, `reason=...` k/v
|
|
||||||
/// pairs. Blank lines, header lines, and the empty-state sentinel
|
|
||||||
/// are skipped.
|
|
||||||
public nonisolated static func parseListArchivedText(_ text: String) -> [HermesCuratorArchivedSkill] {
|
|
||||||
var rows: [HermesCuratorArchivedSkill] = []
|
|
||||||
for raw in text.split(separator: "\n") {
|
|
||||||
let line = raw.trimmingCharacters(in: .whitespaces)
|
|
||||||
if line.isEmpty { continue }
|
|
||||||
let lower = line.lowercased()
|
|
||||||
// Skip header / sentinel lines.
|
|
||||||
if lower.hasPrefix("name") && lower.contains("archived") { continue }
|
|
||||||
if lower.contains("no archived skills") { continue }
|
|
||||||
if line.unicodeScalars.allSatisfy({ $0.value == 0x2500 || $0.properties.isWhitespace }) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Skip lines that look like JSON / non-row chrome — `{`,
|
|
||||||
// `}`, `[`, `]` at the start or quotes / colons mean we're
|
|
||||||
// parsing a malformed JSON dump, not a row table.
|
|
||||||
if let first = line.first, "{[}]\":,".contains(first) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Find the first whitespace-separated token as the name; if
|
|
||||||
// the name carries an `=` it's a header chip we should skip.
|
|
||||||
let parts = line.split(whereSeparator: { $0 == "\t" || $0 == " " }).map(String.init)
|
|
||||||
guard let name = parts.first, !name.contains("=") else { continue }
|
|
||||||
// Reject names that look like punctuation / JSON fragments.
|
|
||||||
if name.contains("\"") || name.contains(":") || name.contains("{") || name.contains("}") || name.contains("[") || name.contains("]") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Pull k=v pairs from the remainder.
|
|
||||||
var archivedAt: String?
|
|
||||||
var sizeBytes: Int?
|
|
||||||
var reason: String?
|
|
||||||
var category: String?
|
|
||||||
var path: String?
|
|
||||||
for token in parts.dropFirst() {
|
|
||||||
guard let eq = token.firstIndex(of: "=") else { continue }
|
|
||||||
let key = String(token[..<eq])
|
|
||||||
let value = String(token[token.index(after: eq)...])
|
|
||||||
switch key {
|
|
||||||
case "archived", "archived_at":
|
|
||||||
archivedAt = value
|
|
||||||
case "size", "size_bytes":
|
|
||||||
sizeBytes = Int(value)
|
|
||||||
case "reason":
|
|
||||||
reason = value
|
|
||||||
case "category":
|
|
||||||
category = value
|
|
||||||
case "path":
|
|
||||||
path = value
|
|
||||||
default:
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rows.append(
|
|
||||||
HermesCuratorArchivedSkill(
|
|
||||||
name: name,
|
|
||||||
category: category,
|
|
||||||
archivedAt: archivedAt,
|
|
||||||
reason: reason,
|
|
||||||
sizeBytes: sizeBytes,
|
|
||||||
path: path
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return rows
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parse a `prune --dry-run --json` payload. Tolerates an empty
|
|
||||||
/// payload (returns a zero summary) and the `{would_remove: [],
|
|
||||||
/// total_bytes: N}` shape.
|
|
||||||
public nonisolated static func parsePruneDryRun(_ stdout: String) -> CuratorPruneSummary {
|
|
||||||
let trimmed = stdout.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
||||||
guard !trimmed.isEmpty else {
|
|
||||||
return CuratorPruneSummary(wouldRemove: [], totalBytes: 0)
|
|
||||||
}
|
|
||||||
if let data = trimmed.data(using: .utf8),
|
|
||||||
let summary = try? JSONDecoder().decode(CuratorPruneSummary.self, from: data) {
|
|
||||||
return summary
|
|
||||||
}
|
|
||||||
// Tolerate a bare-array fallback (some Hermes builds may print
|
|
||||||
// just the would-remove list when --json is missing the wrapper).
|
|
||||||
if let data = trimmed.data(using: .utf8),
|
|
||||||
let arr = try? JSONDecoder().decode([HermesCuratorArchivedSkill].self, from: data) {
|
|
||||||
let total = arr.compactMap { $0.sizeBytes }.reduce(0, +)
|
|
||||||
return CuratorPruneSummary(wouldRemove: arr, totalBytes: total)
|
|
||||||
}
|
|
||||||
// Last-resort text parse for "would remove N skills (X bytes)".
|
|
||||||
return CuratorPruneSummary(wouldRemove: [], totalBytes: 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - CLI invocation
|
|
||||||
|
|
||||||
private nonisolated func runHermes(
|
|
||||||
args: [String],
|
|
||||||
timeout: TimeInterval
|
|
||||||
) async -> (exitCode: Int32, stdout: String, stderr: String) {
|
|
||||||
let context = self.context
|
|
||||||
return await Task.detached(priority: .utility) { () -> (Int32, String, String) in
|
|
||||||
let result = Self.runHermesSync(context: context, args: args, timeout: timeout)
|
|
||||||
return (result.exitCode, result.output, result.stderr)
|
|
||||||
}.value
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Synchronous, transport-level invocation. `output` is stdout; the
|
|
||||||
/// caller usually only reads `output` for parser input but sometimes
|
|
||||||
/// needs `stderr` (e.g. to detect "unrecognized argument" patterns).
|
|
||||||
private nonisolated static func runHermesSync(
|
|
||||||
context: ServerContext,
|
|
||||||
args: [String],
|
|
||||||
timeout: TimeInterval
|
|
||||||
) -> (exitCode: Int32, output: String, stderr: String) {
|
|
||||||
let transport = context.makeTransport()
|
|
||||||
do {
|
|
||||||
let result = try transport.runProcess(
|
|
||||||
executable: context.paths.hermesBinary,
|
|
||||||
args: args,
|
|
||||||
stdin: nil,
|
|
||||||
timeout: timeout
|
|
||||||
)
|
|
||||||
return (result.exitCode, result.stdoutString, result.stderrString)
|
|
||||||
} catch let error as TransportError {
|
|
||||||
let message = error.diagnosticStderr.isEmpty
|
|
||||||
? (error.errorDescription ?? "transport error")
|
|
||||||
: error.diagnosticStderr
|
|
||||||
return (-1, "", message)
|
|
||||||
} catch {
|
|
||||||
return (-1, "", error.localizedDescription)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private nonisolated func ensureSuccess(
|
|
||||||
code: Int32,
|
|
||||||
stdout: String,
|
|
||||||
stderr: String,
|
|
||||||
verb: String
|
|
||||||
) throws {
|
|
||||||
guard code != 0 else { return }
|
|
||||||
if code == -1 && stderr.lowercased().contains("hermes binary not found") {
|
|
||||||
throw CuratorError.cliMissing
|
|
||||||
}
|
|
||||||
let combined = stderr.isEmpty ? stdout : stderr
|
|
||||||
#if canImport(os)
|
|
||||||
Self.logger.warning("curator \(verb) exit=\(code, privacy: .public) stderr=\(combined, privacy: .public)")
|
|
||||||
#endif
|
|
||||||
throw CuratorError.nonZeroExit(verb: verb, code: code, stderr: combined)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -321,6 +321,61 @@ public actor KanbanService {
|
|||||||
try ensureSuccess(code: code, stdout: "", stderr: stderr, verb: "unlink")
|
try ensureSuccess(code: code, stdout: "", stderr: stderr, verb: "unlink")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Hallucination gate (v0.13)
|
||||||
|
|
||||||
|
/// Mark a worker-created card as user-verified — flips
|
||||||
|
/// `hallucination_gate_status` from `pending` to `verified` so the
|
||||||
|
/// dispatcher can pick it up. The polling loop picks up the new
|
||||||
|
/// state on the next tick (and the VM optimistically clears the
|
||||||
|
/// pending banner immediately on the click).
|
||||||
|
///
|
||||||
|
/// **Pre-v0.13 hosts:** the verb doesn't exist; callers MUST gate
|
||||||
|
/// on `HermesCapabilities.hasKanbanDiagnostics` before invoking this.
|
||||||
|
/// A pre-v0.13 binary will surface the failure as
|
||||||
|
/// `KanbanError.nonZeroExit` with stderr containing "unknown command".
|
||||||
|
// TODO(WS-3-Q1): Confirm the exact CLI verb name for the
|
||||||
|
// hallucination-gate verify path against a v0.13 binary (`hermes
|
||||||
|
// kanban --help`). The v0.13 release notes describe "hallucination
|
||||||
|
// gate + recovery UX" but don't enumerate the verb name. This
|
||||||
|
// implementation assumes `hermes kanban verify <id>`. If Hermes ships
|
||||||
|
// it as `hermes kanban gate verify <id>`, `hermes kanban hallucination
|
||||||
|
// verify <id>`, or another name, update the args here. The Reject
|
||||||
|
// path does NOT depend on this verb (it routes through
|
||||||
|
// `archive` + a comment), so the recovery UX stays functional even
|
||||||
|
// if Verify is a stub for an early v0.13.x.
|
||||||
|
public func verify(taskId: String) async throws {
|
||||||
|
let args = ["kanban", "verify", taskId]
|
||||||
|
let (code, _, stderr) = await runHermes(args: args, timeout: 15)
|
||||||
|
try ensureSuccess(code: code, stdout: "", stderr: stderr, verb: "verify")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Reject a worker-created card as a hallucinated reference. There
|
||||||
|
/// is no dedicated `kanban reject` verb in v0.13; the right action
|
||||||
|
/// per the v0.13 release notes is to archive the card (the work
|
||||||
|
/// doesn't exist) with a comment recording the rejection reason for
|
||||||
|
/// the audit trail. Routing this through the existing `comment` +
|
||||||
|
/// `archive` verbs keeps the wire shape stable across versions.
|
||||||
|
///
|
||||||
|
/// If a future Hermes adds a dedicated `kanban reject` verb, swap
|
||||||
|
/// the body here — the public surface stays "reject" returning Void.
|
||||||
|
public func rejectHallucinated(taskId: String) async throws {
|
||||||
|
// Best-effort comment first so the audit trail records the
|
||||||
|
// rejection. A failure here shouldn't block the archive — log
|
||||||
|
// and continue.
|
||||||
|
do {
|
||||||
|
try await comment(
|
||||||
|
taskId: taskId,
|
||||||
|
text: "Rejected as hallucinated (no underlying work).",
|
||||||
|
author: nil
|
||||||
|
)
|
||||||
|
} catch {
|
||||||
|
#if canImport(os)
|
||||||
|
Self.logger.warning("kanban reject: comment failed, proceeding to archive (\(error.localizedDescription, privacy: .public))")
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
try await archive(taskIds: [taskId])
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Drag-drop transition mapper
|
// MARK: - Drag-drop transition mapper
|
||||||
|
|
||||||
/// Map a board-level column transition to the right Hermes verb call.
|
/// Map a board-level column transition to the right Hermes verb call.
|
||||||
|
|||||||
@@ -4,19 +4,17 @@ import Observation
|
|||||||
import os
|
import os
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// Mac + iOS view model for the Curator surface (v0.12 base + v0.13
|
/// Mac + iOS view model for the v0.12 Curator surface.
|
||||||
/// archive/prune additions).
|
|
||||||
///
|
///
|
||||||
/// Drives `hermes curator status / run / pause / resume / pin / unpin /
|
/// Drives `hermes curator status / run / pause / resume / pin / unpin /
|
||||||
/// restore` plus (v0.13+) `archive`, `prune`, `list-archived`. All CLI
|
/// restore` plus a parsed view of `~/.hermes/skills/.curator_state`
|
||||||
/// invocations route through `CuratorService` (the actor) so polling
|
/// JSON. The CLI doesn't ship a `--json` flag for `status`, so we
|
||||||
/// and writes share the same concurrency model and a single error path.
|
/// text-parse stdout (HermesCuratorStatusParser) and use the state
|
||||||
|
/// file for richer last-run metadata.
|
||||||
///
|
///
|
||||||
/// Capability-gated: callers should construct this only when
|
/// Capability-gated: callers should construct this only when
|
||||||
/// `HermesCapabilities.hasCurator` is true. Archive-aware UI surfaces
|
/// `HermesCapabilities.hasCurator` is true. The view model does not
|
||||||
/// (Archive button, Archived section, Prune…) gate independently on
|
/// gate itself — the gate happens at sidebar/tab routing time.
|
||||||
/// `hasCuratorArchive`. The view model itself doesn't gate — it exposes
|
|
||||||
/// every method and the View decides what to render.
|
|
||||||
@Observable
|
@Observable
|
||||||
@MainActor
|
@MainActor
|
||||||
public final class CuratorViewModel {
|
public final class CuratorViewModel {
|
||||||
@@ -29,50 +27,20 @@ public final class CuratorViewModel {
|
|||||||
public private(set) var status: HermesCuratorStatus = .empty
|
public private(set) var status: HermesCuratorStatus = .empty
|
||||||
public private(set) var isLoading = false
|
public private(set) var isLoading = false
|
||||||
public private(set) var lastReportMarkdown: String?
|
public private(set) var lastReportMarkdown: String?
|
||||||
|
|
||||||
// Archive state (v0.13+ only — populated by `loadArchive()` on hosts
|
|
||||||
// where `hasCuratorArchive` is true).
|
|
||||||
public private(set) var archivedSkills: [HermesCuratorArchivedSkill] = []
|
|
||||||
public private(set) var isLoadingArchive = false
|
|
||||||
|
|
||||||
// Prune state — `pruneSummary` non-nil while the confirm sheet is
|
|
||||||
// mid-flight; `isPruning` flips during the destructive step.
|
|
||||||
public private(set) var pruneSummary: CuratorPruneSummary?
|
|
||||||
public private(set) var isPruning = false
|
|
||||||
|
|
||||||
// Track which active-skill row is currently being archived so the
|
|
||||||
// row chrome can show an inline spinner without blocking the rest.
|
|
||||||
public private(set) var pendingArchiveName: String?
|
|
||||||
|
|
||||||
/// Happy-path success toast ("Pinned X", "Resumed", "Archived
|
|
||||||
/// legacy-helper"). Auto-clears 3s after assignment.
|
|
||||||
public var transientMessage: String?
|
public var transientMessage: String?
|
||||||
|
|
||||||
/// Failure path — populated by every CLI verb when it throws. Shown
|
|
||||||
/// as an inline yellow banner above the status summary so users
|
|
||||||
/// don't have to dismiss a modal alert during a high-frequency
|
|
||||||
/// surface like the leaderboard. Manually dismissed via the View's
|
|
||||||
/// "x" button (sets to nil).
|
|
||||||
public var errorMessage: String?
|
|
||||||
|
|
||||||
@ObservationIgnored
|
|
||||||
private let service: CuratorService
|
|
||||||
|
|
||||||
public init(context: ServerContext) {
|
public init(context: ServerContext) {
|
||||||
self.context = context
|
self.context = context
|
||||||
self.service = CuratorService(context: context)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Loads
|
|
||||||
|
|
||||||
public func load() async {
|
public func load() async {
|
||||||
isLoading = true
|
isLoading = true
|
||||||
defer { isLoading = false }
|
defer { isLoading = false }
|
||||||
let context = self.context
|
let context = self.context
|
||||||
// v2.8 — instrumented. Curator load fires `hermes curator
|
// v2.8 — instrumented. Curator load fires `hermes curator
|
||||||
// status` (CLI subprocess) plus 1-2 file reads; on remote each
|
// status` (CLI subprocess) plus 1-2 file reads; on remote
|
||||||
// is a separate SSH RTT. Visibility lets future captures show
|
// each is a separate SSH RTT. Visibility lets future captures
|
||||||
// how often the report file is missing or oversized.
|
// show how often the report file is missing or oversized.
|
||||||
let parsed = await ScarfMon.measureAsync(.diskIO, "curator.load") {
|
let parsed = await ScarfMon.measureAsync(.diskIO, "curator.load") {
|
||||||
await Task.detached(priority: .userInitiated) { () -> (HermesCuratorStatus, String?) in
|
await Task.detached(priority: .userInitiated) { () -> (HermesCuratorStatus, String?) in
|
||||||
let textResult = Self.runCuratorStatus(context: context)
|
let textResult = Self.runCuratorStatus(context: context)
|
||||||
@@ -101,156 +69,46 @@ public final class CuratorViewModel {
|
|||||||
self.lastReportMarkdown = parsed.1
|
self.lastReportMarkdown = parsed.1
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Refresh the archived-skills list. No-op on hosts without
|
public func runNow() async {
|
||||||
/// `hasCuratorArchive` — the caller gates the call.
|
await runAndReload(args: ["curator", "run"], successMessage: "Curator run started")
|
||||||
public func loadArchive() async {
|
|
||||||
isLoadingArchive = true
|
|
||||||
defer { isLoadingArchive = false }
|
|
||||||
do {
|
|
||||||
archivedSkills = try await service.listArchived()
|
|
||||||
} catch {
|
|
||||||
archivedSkills = []
|
|
||||||
errorMessage = (error as? LocalizedError)?.errorDescription
|
|
||||||
?? error.localizedDescription
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Writes (v0.12)
|
|
||||||
|
|
||||||
/// Run the curator manually. On v0.13+ hosts this blocks for the
|
|
||||||
/// duration of the run (default 600s timeout); pre-v0.13 returns
|
|
||||||
/// immediately. Caller passes the capability-decided flag.
|
|
||||||
public func runNow(synchronous: Bool, timeout: TimeInterval = 600) async {
|
|
||||||
await runWithReload(
|
|
||||||
verb: "run",
|
|
||||||
successMessage: synchronous ? "Curator run complete" : "Curator run started"
|
|
||||||
) {
|
|
||||||
try await self.service.runNow(synchronous: synchronous, timeout: timeout)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func pause() async {
|
public func pause() async {
|
||||||
await runWithReload(verb: "pause", successMessage: "Curator paused") {
|
await runAndReload(args: ["curator", "pause"], successMessage: "Curator paused")
|
||||||
try await self.service.pause()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func resume() async {
|
public func resume() async {
|
||||||
await runWithReload(verb: "resume", successMessage: "Curator resumed") {
|
await runAndReload(args: ["curator", "resume"], successMessage: "Curator resumed")
|
||||||
try await self.service.resume()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func pin(_ skill: String) async {
|
public func pin(_ skill: String) async {
|
||||||
await runWithReload(verb: "pin", successMessage: "Pinned \(skill)") {
|
await runAndReload(args: ["curator", "pin", skill], successMessage: "Pinned \(skill)")
|
||||||
try await self.service.pin(skill)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func unpin(_ skill: String) async {
|
public func unpin(_ skill: String) async {
|
||||||
await runWithReload(verb: "unpin", successMessage: "Unpinned \(skill)") {
|
await runAndReload(args: ["curator", "unpin", skill], successMessage: "Unpinned \(skill)")
|
||||||
try await self.service.unpin(skill)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func restore(_ skill: String) async {
|
public func restore(_ skill: String) async {
|
||||||
await runWithReload(verb: "restore", successMessage: "Restored \(skill)") {
|
await runAndReload(args: ["curator", "restore", skill], successMessage: "Restored \(skill)")
|
||||||
try await self.service.restore(skill)
|
|
||||||
}
|
|
||||||
// Restore drops the entry from the archived list — refresh it
|
|
||||||
// so the row disappears immediately.
|
|
||||||
await loadArchive()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Writes (v0.13)
|
private func runAndReload(args: [String], successMessage: String) async {
|
||||||
|
let context = self.context
|
||||||
public func archive(_ skill: String) async {
|
let exitCode = await Task.detached(priority: .userInitiated) {
|
||||||
pendingArchiveName = skill
|
Self.runHermes(context: context, args: args).exitCode
|
||||||
await runWithReload(verb: "archive", successMessage: "Archived \(skill)") {
|
}.value
|
||||||
try await self.service.archive(skill)
|
transientMessage = exitCode == 0 ? successMessage : "Command failed"
|
||||||
}
|
|
||||||
pendingArchiveName = nil
|
|
||||||
await loadArchive()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Stage 1 of the bulk-prune flow. Calls `prune --dry-run` and
|
|
||||||
/// populates `pruneSummary`; the View binds its confirm sheet to
|
|
||||||
/// the non-nil presence of this property.
|
|
||||||
public func planPrune() async {
|
|
||||||
do {
|
|
||||||
pruneSummary = try await service.prune(dryRun: true)
|
|
||||||
} catch {
|
|
||||||
errorMessage = (error as? LocalizedError)?.errorDescription
|
|
||||||
?? error.localizedDescription
|
|
||||||
pruneSummary = nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Stage 2 of the bulk-prune flow. Destructive — removes everything
|
|
||||||
/// currently archived. Clears `pruneSummary` regardless of outcome
|
|
||||||
/// so the confirm sheet dismisses.
|
|
||||||
public func confirmPrune() async {
|
|
||||||
isPruning = true
|
|
||||||
do {
|
|
||||||
_ = try await service.prune(dryRun: false)
|
|
||||||
transientMessage = "Pruned archived skills"
|
|
||||||
errorMessage = nil
|
|
||||||
await loadArchive()
|
|
||||||
await load()
|
await load()
|
||||||
scheduleTransientClear()
|
// Auto-clear toast after 3s.
|
||||||
} catch {
|
|
||||||
errorMessage = (error as? LocalizedError)?.errorDescription
|
|
||||||
?? error.localizedDescription
|
|
||||||
}
|
|
||||||
isPruning = false
|
|
||||||
pruneSummary = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Cancel the in-flight prune-confirm flow without running.
|
|
||||||
public func cancelPrune() {
|
|
||||||
pruneSummary = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
/// User-driven dismissal of the inline error banner.
|
|
||||||
public func dismissError() {
|
|
||||||
errorMessage = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Helpers
|
|
||||||
|
|
||||||
/// Run a service call, route success → `transientMessage`, failure
|
|
||||||
/// → `errorMessage`, and reload `status` either way. Mirrors the
|
|
||||||
/// previous `runAndReload` helper but goes through the typed
|
|
||||||
/// service surface.
|
|
||||||
private func runWithReload(
|
|
||||||
verb: String,
|
|
||||||
successMessage: String,
|
|
||||||
body: @escaping @Sendable () async throws -> Void
|
|
||||||
) async {
|
|
||||||
do {
|
|
||||||
try await body()
|
|
||||||
transientMessage = successMessage
|
|
||||||
errorMessage = nil
|
|
||||||
await load()
|
|
||||||
scheduleTransientClear()
|
|
||||||
} catch {
|
|
||||||
let message = (error as? LocalizedError)?.errorDescription
|
|
||||||
?? error.localizedDescription
|
|
||||||
errorMessage = message
|
|
||||||
transientMessage = nil
|
|
||||||
await load()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private func scheduleTransientClear() {
|
|
||||||
Task { @MainActor [weak self] in
|
Task { @MainActor [weak self] in
|
||||||
try? await Task.sleep(nanoseconds: 3_000_000_000)
|
try? await Task.sleep(nanoseconds: 3_000_000_000)
|
||||||
self?.transientMessage = nil
|
self?.transientMessage = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Legacy sync helpers (kept for `load`'s detached path)
|
/// Wrap the transport-level `runProcess` so the call sites don't
|
||||||
|
/// have to reach for it directly. Combined stdout+stderr.
|
||||||
nonisolated private static func runHermes(
|
nonisolated private static func runHermes(
|
||||||
context: ServerContext,
|
context: ServerContext,
|
||||||
args: [String]
|
args: [String]
|
||||||
|
|||||||
@@ -151,169 +151,4 @@ import Foundation
|
|||||||
#expect(parsed?.patchCount == 2)
|
#expect(parsed?.patchCount == 2)
|
||||||
#expect(parsed?.lastActivityLabel == "2026-04-25")
|
#expect(parsed?.lastActivityLabel == "2026-04-25")
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - v0.13 list-archived / prune fixtures (WS-4)
|
|
||||||
|
|
||||||
/// Empty JSON array → `[]`. Locks in the happy-path no-archives shape.
|
|
||||||
@Test func listArchivedEmpty() throws {
|
|
||||||
let result = try CuratorService.parseListArchived(stdout: "[]")
|
|
||||||
#expect(result.isEmpty)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Three archives with full optional fields. Asserts each
|
|
||||||
/// optional value decodes through `decodeIfPresent` and that
|
|
||||||
/// the computed labels resolve.
|
|
||||||
@Test func listArchivedThreeSkills() throws {
|
|
||||||
let json = """
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"name": "legacy-helper",
|
|
||||||
"category": "templates",
|
|
||||||
"archived_at": "2026-04-22T03:14:09Z",
|
|
||||||
"reason": "stale: 91d unused",
|
|
||||||
"size_bytes": 4521,
|
|
||||||
"path": "/Users/u/.hermes/skills/.archived/legacy-helper"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "old-translator",
|
|
||||||
"category": "user",
|
|
||||||
"archived_at": "2026-04-23T10:00:00Z",
|
|
||||||
"reason": "consolidated with translator",
|
|
||||||
"size_bytes": 8192
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "minimal"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
"""
|
|
||||||
let result = try CuratorService.parseListArchived(stdout: json)
|
|
||||||
#expect(result.count == 3)
|
|
||||||
#expect(result[0].name == "legacy-helper")
|
|
||||||
#expect(result[0].category == "templates")
|
|
||||||
#expect(result[0].reason == "stale: 91d unused")
|
|
||||||
#expect(result[0].sizeBytes == 4521)
|
|
||||||
#expect(result[0].archivedAtLabel == "2026-04-22")
|
|
||||||
#expect(result[0].path == "/Users/u/.hermes/skills/.archived/legacy-helper")
|
|
||||||
|
|
||||||
// Tolerant: only `name` set on the third row.
|
|
||||||
#expect(result[2].name == "minimal")
|
|
||||||
#expect(result[2].category == nil)
|
|
||||||
#expect(result[2].reason == nil)
|
|
||||||
#expect(result[2].archivedAtLabel == "—")
|
|
||||||
#expect(result[2].sizeLabel == "—")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `{"archived": [...]}` envelope is also accepted.
|
|
||||||
@Test func listArchivedEnvelope() throws {
|
|
||||||
let json = """
|
|
||||||
{"archived": [
|
|
||||||
{"name": "envelope-skill", "size_bytes": 1024}
|
|
||||||
]}
|
|
||||||
"""
|
|
||||||
let result = try CuratorService.parseListArchived(stdout: json)
|
|
||||||
#expect(result.count == 1)
|
|
||||||
#expect(result[0].name == "envelope-skill")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Text fallback when `--json` isn't supported. Each row carries
|
|
||||||
/// the name in column 1 plus k=v chips for the optional fields.
|
|
||||||
@Test func listArchivedTextFallback() {
|
|
||||||
let text = """
|
|
||||||
legacy-helper archived=2026-04-22 size=4521 reason=stale
|
|
||||||
old-translator archived=2026-04-23 size=8192
|
|
||||||
minimal-row
|
|
||||||
"""
|
|
||||||
let result = CuratorService.parseListArchivedText(text)
|
|
||||||
#expect(result.count == 3)
|
|
||||||
#expect(result[0].name == "legacy-helper")
|
|
||||||
#expect(result[0].archivedAt == "2026-04-22")
|
|
||||||
#expect(result[0].sizeBytes == 4521)
|
|
||||||
#expect(result[0].reason == "stale")
|
|
||||||
#expect(result[2].name == "minimal-row")
|
|
||||||
#expect(result[2].sizeBytes == nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Empty-state sentinel folds to `[]` (parallel to KanbanService's
|
|
||||||
/// `"no matching tasks"` handling).
|
|
||||||
@Test func listArchivedNoArchivedSentinel() throws {
|
|
||||||
let result = try CuratorService.parseListArchived(stdout: "no archived skills\n")
|
|
||||||
#expect(result.isEmpty)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whitespace-only stdout also folds to empty.
|
|
||||||
@Test func listArchivedWhitespaceFoldsToEmpty() throws {
|
|
||||||
let result = try CuratorService.parseListArchived(stdout: " \n\n")
|
|
||||||
#expect(result.isEmpty)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Decode failure (clearly non-JSON, non-text) throws. We accept
|
|
||||||
/// JSON, the envelope, the empty sentinel, or text rows; anything
|
|
||||||
/// else surfaces as a `CuratorError.decoding`.
|
|
||||||
@Test func listArchivedNonsenseThrows() throws {
|
|
||||||
do {
|
|
||||||
_ = try CuratorService.parseListArchived(stdout: "{garbage")
|
|
||||||
Issue.record("expected decoding throw")
|
|
||||||
} catch let error as CuratorError {
|
|
||||||
if case .decoding = error {
|
|
||||||
// expected
|
|
||||||
} else {
|
|
||||||
Issue.record("unexpected error \(error)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Prune-dry-run JSON with `would_remove` + `total_bytes`.
|
|
||||||
@Test func pruneDryRunHappyPath() {
|
|
||||||
let json = """
|
|
||||||
{
|
|
||||||
"would_remove": [
|
|
||||||
{"name": "stale-a", "size_bytes": 1000},
|
|
||||||
{"name": "stale-b", "size_bytes": 2000}
|
|
||||||
],
|
|
||||||
"total_bytes": 3000
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
let summary = CuratorService.parsePruneDryRun(json)
|
|
||||||
#expect(summary.totalCount == 2)
|
|
||||||
#expect(summary.totalBytes == 3000)
|
|
||||||
#expect(summary.wouldRemove.first?.name == "stale-a")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Zero-skill prune is a valid dry-run (no archives).
|
|
||||||
@Test func pruneDryRunZeroSkills() {
|
|
||||||
let json = """
|
|
||||||
{"would_remove": [], "total_bytes": 0}
|
|
||||||
"""
|
|
||||||
let summary = CuratorService.parsePruneDryRun(json)
|
|
||||||
#expect(summary.totalCount == 0)
|
|
||||||
#expect(summary.totalBytes == 0)
|
|
||||||
#expect(summary.totalBytesLabel == "—")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Bare-array fallback: some Hermes builds may print just the
|
|
||||||
/// would-remove list when the wrapper is missing.
|
|
||||||
@Test func pruneDryRunBareArrayFallback() {
|
|
||||||
let json = """
|
|
||||||
[{"name": "lonely", "size_bytes": 500}]
|
|
||||||
"""
|
|
||||||
let summary = CuratorService.parsePruneDryRun(json)
|
|
||||||
#expect(summary.totalCount == 1)
|
|
||||||
#expect(summary.totalBytes == 500)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Empty / whitespace stdout → zero summary (no decoding throw).
|
|
||||||
@Test func pruneDryRunEmptyStaysSafe() {
|
|
||||||
let summary = CuratorService.parsePruneDryRun(" \n")
|
|
||||||
#expect(summary.totalCount == 0)
|
|
||||||
#expect(summary.totalBytes == 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Verify the size label uses the byte formatter (not raw bytes).
|
|
||||||
@Test func archivedSkillSizeLabelFormats() {
|
|
||||||
let big = HermesCuratorArchivedSkill(name: "x", sizeBytes: 1_500_000)
|
|
||||||
// ByteCountFormatter produces a localized label; just verify
|
|
||||||
// it's non-empty and not raw "1500000".
|
|
||||||
#expect(!big.sizeLabel.isEmpty)
|
|
||||||
#expect(big.sizeLabel != "1500000")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -327,4 +327,196 @@ import Foundation
|
|||||||
#expect(stats.glanceString.isEmpty)
|
#expect(stats.glanceString.isEmpty)
|
||||||
#expect(stats.activeCount == 0)
|
#expect(stats.activeCount == 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - v0.13 (Hermes 2026.5.7) tolerant decode
|
||||||
|
//
|
||||||
|
// The contract these tests pin: a v0.13 host's task / run / detail
|
||||||
|
// JSON decodes successfully WITH the new fields populated, AND a
|
||||||
|
// pre-v0.13 (v0.12) host's task / run / detail JSON decodes
|
||||||
|
// successfully WITHOUT the new fields (everything resolves to nil
|
||||||
|
// or empty). Drift from this pair = a regression that bites every
|
||||||
|
// user not yet on Hermes v0.13.
|
||||||
|
|
||||||
|
@Test func decodeV013TaskFields() throws {
|
||||||
|
let json = """
|
||||||
|
{
|
||||||
|
"id": "t_v013",
|
||||||
|
"title": "v0.13 task",
|
||||||
|
"status": "blocked",
|
||||||
|
"max_retries": 5,
|
||||||
|
"auto_blocked_reason": "worker exited without `kanban complete`",
|
||||||
|
"hallucination_gate_status": "pending",
|
||||||
|
"diagnostics": [
|
||||||
|
{"kind": "worker_exit_no_complete", "message": "exit code 0 with no complete call", "detected_at": 1778160614},
|
||||||
|
{"kind": "darwin_zombie_detected", "detected_at": "2026-05-09T12:00:00Z"}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
let task = try JSONDecoder().decode(HermesKanbanTask.self, from: Data(json.utf8))
|
||||||
|
#expect(task.maxRetries == 5)
|
||||||
|
#expect(task.autoBlockedReason?.contains("kanban complete") == true)
|
||||||
|
#expect(task.hallucinationGateStatus == "pending")
|
||||||
|
#expect(task.diagnostics.count == 2)
|
||||||
|
#expect(task.diagnostics.first?.kind == "worker_exit_no_complete")
|
||||||
|
#expect(task.diagnostics.last?.detectedAt?.contains("2026") == true)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func decodeV012TaskHasNoNewFields() throws {
|
||||||
|
// The most damaging failure mode is a v0.12 user upgrading Scarf
|
||||||
|
// and having the board stop loading because a v0.13-only field
|
||||||
|
// is required. Pin the contract.
|
||||||
|
let json = """
|
||||||
|
{"id": "t_legacy", "title": "v0.12 task", "status": "ready"}
|
||||||
|
"""
|
||||||
|
let task = try JSONDecoder().decode(HermesKanbanTask.self, from: Data(json.utf8))
|
||||||
|
#expect(task.maxRetries == nil)
|
||||||
|
#expect(task.autoBlockedReason == nil)
|
||||||
|
#expect(task.hallucinationGateStatus == nil)
|
||||||
|
#expect(task.diagnostics.isEmpty)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func decodeMalformedDiagnosticTolerated() throws {
|
||||||
|
// If Hermes emits a malformed diagnostics value, the rest of the
|
||||||
|
// task should still decode. We use try? on the diagnostics decode
|
||||||
|
// so a single bad entry doesn't reject the whole row.
|
||||||
|
let json = """
|
||||||
|
{
|
||||||
|
"id": "t_x",
|
||||||
|
"title": "x",
|
||||||
|
"status": "ready",
|
||||||
|
"diagnostics": "not-an-array"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
let task = try JSONDecoder().decode(HermesKanbanTask.self, from: Data(json.utf8))
|
||||||
|
#expect(task.id == "t_x")
|
||||||
|
// Diagnostics field couldn't decode — treat as empty.
|
||||||
|
#expect(task.diagnostics.isEmpty)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func hallucinationGateMirrorMapsKnownValues() {
|
||||||
|
#expect(KanbanHallucinationGate.from("pending") == .pending)
|
||||||
|
#expect(KanbanHallucinationGate.from("verified") == .verified)
|
||||||
|
#expect(KanbanHallucinationGate.from("REJECTED") == .rejected) // case-insensitive
|
||||||
|
#expect(KanbanHallucinationGate.from(nil) == nil)
|
||||||
|
#expect(KanbanHallucinationGate.from("") == nil)
|
||||||
|
// Unknown wire values fall through to nil so the banner stays
|
||||||
|
// hidden; future Hermes versions can add `quarantined` etc.
|
||||||
|
// without a Scarf release.
|
||||||
|
#expect(KanbanHallucinationGate.from("quarantined") == nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func diagnosticKindMirrorMapsKnownValues() {
|
||||||
|
#expect(KanbanDiagnosticKind.from("heartbeat_stalled") == .heartbeatStalled)
|
||||||
|
#expect(KanbanDiagnosticKind.from("DARWIN_ZOMBIE_DETECTED") == .darwinZombieDetected)
|
||||||
|
// Unknown kinds fall through to .unknown so views can render
|
||||||
|
// the raw string verbatim.
|
||||||
|
#expect(KanbanDiagnosticKind.from("future_kind_v014") == .unknown)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func diagnosticSeverityMapping() {
|
||||||
|
#expect(KanbanDiagnosticKind.retryCapHit.severity == .danger)
|
||||||
|
#expect(KanbanDiagnosticKind.darwinZombieDetected.severity == .danger)
|
||||||
|
#expect(KanbanDiagnosticKind.heartbeatStalled.severity == .warning)
|
||||||
|
#expect(KanbanDiagnosticKind.workerExitNoComplete.severity == .warning)
|
||||||
|
#expect(KanbanDiagnosticKind.unknown.severity == .neutral)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func createRequestArgvIncludesMaxRetries() {
|
||||||
|
let req = KanbanCreateRequest(title: "t", maxRetries: 5)
|
||||||
|
let argv = req.argv()
|
||||||
|
#expect(argv.contains("--max-retries"))
|
||||||
|
#expect(argv.contains("5"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func createRequestArgvOmitsMaxRetriesWhenAbsent() {
|
||||||
|
let req = KanbanCreateRequest(title: "t")
|
||||||
|
let argv = req.argv()
|
||||||
|
#expect(!argv.contains("--max-retries"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func decodeRunWithDiagnostics() throws {
|
||||||
|
let json = """
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"task_id": "t_x",
|
||||||
|
"status": "failed",
|
||||||
|
"started_at": 1778160000,
|
||||||
|
"ended_at": 1778160300,
|
||||||
|
"outcome": "crashed",
|
||||||
|
"error": "OOM",
|
||||||
|
"diagnostics": [
|
||||||
|
{"kind": "retry_cap_hit", "message": "3/3 retries exhausted"}
|
||||||
|
],
|
||||||
|
"failure_count": 3
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
let run = try JSONDecoder().decode(HermesKanbanRun.self, from: Data(json.utf8))
|
||||||
|
#expect(run.diagnostics.count == 1)
|
||||||
|
#expect(run.diagnostics.first?.kind == "retry_cap_hit")
|
||||||
|
#expect(run.failureCount == 3)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func decodeRunWithoutDiagnostics() throws {
|
||||||
|
// v0.12 run row — no diagnostics, no failure_count, must still
|
||||||
|
// decode cleanly.
|
||||||
|
let json = """
|
||||||
|
{"id": 1, "task_id": "t_x", "status": "running", "started_at": 1778160000}
|
||||||
|
"""
|
||||||
|
let run = try JSONDecoder().decode(HermesKanbanRun.self, from: Data(json.utf8))
|
||||||
|
#expect(run.diagnostics.isEmpty)
|
||||||
|
#expect(run.failureCount == nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func taskDetailMergesEnvelopeAndTaskDiagnostics() throws {
|
||||||
|
// Hermes's wire shape may put diagnostics on the task envelope OR
|
||||||
|
// on the inner task. `allDiagnostics` dedupes by (kind, detected_at)
|
||||||
|
// so a server emitting both sides doesn't surface dupes.
|
||||||
|
let json = """
|
||||||
|
{
|
||||||
|
"task": {
|
||||||
|
"id": "t_y",
|
||||||
|
"title": "y",
|
||||||
|
"status": "blocked",
|
||||||
|
"diagnostics": [
|
||||||
|
{"kind": "heartbeat_stalled", "detected_at": "2026-05-09T12:00:00Z"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"comments": [],
|
||||||
|
"events": [],
|
||||||
|
"diagnostics": [
|
||||||
|
{"kind": "heartbeat_stalled", "detected_at": "2026-05-09T12:00:00Z"},
|
||||||
|
{"kind": "retry_cap_hit"}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
let detail = try JSONDecoder().decode(HermesKanbanTaskDetail.self, from: Data(json.utf8))
|
||||||
|
let merged = detail.allDiagnostics
|
||||||
|
#expect(merged.count == 2)
|
||||||
|
#expect(merged.contains(where: { $0.kind == "heartbeat_stalled" }))
|
||||||
|
#expect(merged.contains(where: { $0.kind == "retry_cap_hit" }))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func taskDetailWithoutEnvelopeDiagnosticsDecodes() throws {
|
||||||
|
// Pre-v0.13 task detail — no envelope diagnostics. Must decode.
|
||||||
|
let json = """
|
||||||
|
{
|
||||||
|
"task": {"id": "t_z", "title": "z", "status": "ready"},
|
||||||
|
"comments": [],
|
||||||
|
"events": []
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
let detail = try JSONDecoder().decode(HermesKanbanTaskDetail.self, from: Data(json.utf8))
|
||||||
|
#expect(detail.envelopeDiagnostics == nil)
|
||||||
|
#expect(detail.allDiagnostics.isEmpty)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func diagnosticDecodesUnixTimestamp() throws {
|
||||||
|
let json = """
|
||||||
|
{"kind": "spawn_failure", "detected_at": 1778160614}
|
||||||
|
"""
|
||||||
|
let diag = try JSONDecoder().decode(HermesKanbanDiagnostic.self, from: Data(json.utf8))
|
||||||
|
#expect(diag.kind == "spawn_failure")
|
||||||
|
// Decoder normalizes Unix int → ISO-8601 string.
|
||||||
|
#expect(diag.detectedAt?.contains("2026") == true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,24 +13,11 @@ import ScarfDesign
|
|||||||
/// `HermesCapabilities.hasCurator` is true.
|
/// `HermesCapabilities.hasCurator` is true.
|
||||||
struct CuratorView: View {
|
struct CuratorView: View {
|
||||||
@State private var viewModel: CuratorViewModel
|
@State private var viewModel: CuratorViewModel
|
||||||
@Environment(\.hermesCapabilities) private var capabilitiesStore
|
|
||||||
|
|
||||||
// TODO(WS-9): add a read-only "Archived" section mirroring the Mac
|
|
||||||
// surface (no per-row Restore/Prune mutations on iOS in this
|
|
||||||
// release). Gate on `capabilitiesStore?.capabilities.hasCuratorArchive`.
|
|
||||||
|
|
||||||
init(context: ServerContext) {
|
init(context: ServerContext) {
|
||||||
_viewModel = State(initialValue: CuratorViewModel(context: context))
|
_viewModel = State(initialValue: CuratorViewModel(context: context))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether the connected host runs curator synchronously. Threaded
|
|
||||||
/// into `runNow` so v0.13+ hosts block-with-spinner; pre-v0.13 fire
|
|
||||||
/// and forget. WS-9 will surface a richer iOS progress affordance
|
|
||||||
/// alongside the read-only Archived section.
|
|
||||||
private var archiveAvailable: Bool {
|
|
||||||
capabilitiesStore?.capabilities.hasCuratorArchive ?? false
|
|
||||||
}
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
List {
|
List {
|
||||||
Section {
|
Section {
|
||||||
@@ -128,7 +115,7 @@ struct CuratorView: View {
|
|||||||
private var actionFooter: some View {
|
private var actionFooter: some View {
|
||||||
HStack(spacing: 8) {
|
HStack(spacing: 8) {
|
||||||
Button {
|
Button {
|
||||||
Task { await viewModel.runNow(synchronous: archiveAvailable, timeout: 600) }
|
Task { await viewModel.runNow() }
|
||||||
} label: {
|
} label: {
|
||||||
Label("Run now", systemImage: "play.fill")
|
Label("Run now", systemImage: "play.fill")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,122 +0,0 @@
|
|||||||
import SwiftUI
|
|
||||||
import ScarfCore
|
|
||||||
import ScarfDesign
|
|
||||||
|
|
||||||
/// Mac sub-view rendered between the active-skill leaderboards and the
|
|
||||||
/// last-report block on Hermes v0.13+ hosts. Lists everything currently
|
|
||||||
/// archived (`hermes curator list-archived`) with per-row Restore + a
|
|
||||||
/// bulk Prune affordance routed through the parent's confirm sheet.
|
|
||||||
///
|
|
||||||
/// Empty-state copy explains what archive means — useful when the
|
|
||||||
/// curator hasn't run yet on a fresh install (no archives ≠ a problem).
|
|
||||||
struct CuratorArchivedSection: View {
|
|
||||||
let archived: [HermesCuratorArchivedSkill]
|
|
||||||
let isLoading: Bool
|
|
||||||
let onRestore: (String) -> Void
|
|
||||||
let onPruneAll: () -> Void
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
ScarfCard {
|
|
||||||
VStack(alignment: .leading, spacing: ScarfSpace.s2) {
|
|
||||||
header
|
|
||||||
if isLoading && archived.isEmpty {
|
|
||||||
loadingRow
|
|
||||||
} else if archived.isEmpty {
|
|
||||||
emptyState
|
|
||||||
} else {
|
|
||||||
rows
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private var header: some View {
|
|
||||||
HStack(alignment: .firstTextBaseline) {
|
|
||||||
ScarfSectionHeader("Archived")
|
|
||||||
Spacer()
|
|
||||||
Text("\(archived.count) skill\(archived.count == 1 ? "" : "s")")
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundMuted)
|
|
||||||
if !archived.isEmpty {
|
|
||||||
Button("Prune All…") {
|
|
||||||
onPruneAll()
|
|
||||||
}
|
|
||||||
.buttonStyle(ScarfDestructiveButton())
|
|
||||||
.help("Remove every archived skill from disk. Cannot be undone.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private var loadingRow: some View {
|
|
||||||
HStack(spacing: ScarfSpace.s2) {
|
|
||||||
ProgressView().controlSize(.small)
|
|
||||||
Text("Loading archived skills…")
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundMuted)
|
|
||||||
Spacer()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private var emptyState: some View {
|
|
||||||
VStack(alignment: .leading, spacing: ScarfSpace.s1) {
|
|
||||||
Text("No archived skills.")
|
|
||||||
.scarfStyle(.body)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundMuted)
|
|
||||||
Text("The curator moves stale or redundant skills here on its weekly review. Until then, this list stays empty.")
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundFaint)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private var rows: some View {
|
|
||||||
VStack(alignment: .leading, spacing: ScarfSpace.s1) {
|
|
||||||
ForEach(archived) { skill in
|
|
||||||
ArchivedSkillRow(
|
|
||||||
skill: skill,
|
|
||||||
onRestore: { onRestore(skill.name) }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private struct ArchivedSkillRow: View {
|
|
||||||
let skill: HermesCuratorArchivedSkill
|
|
||||||
let onRestore: () -> Void
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
HStack(alignment: .center, spacing: ScarfSpace.s2) {
|
|
||||||
Image(systemName: "archivebox.fill")
|
|
||||||
.font(.system(size: 12))
|
|
||||||
.foregroundStyle(ScarfColor.foregroundFaint)
|
|
||||||
VStack(alignment: .leading, spacing: 2) {
|
|
||||||
Text(skill.name)
|
|
||||||
.scarfStyle(.body)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundPrimary)
|
|
||||||
.lineLimit(1)
|
|
||||||
if let reason = skill.reason, !reason.isEmpty {
|
|
||||||
Text(reason)
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundMuted)
|
|
||||||
.lineLimit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
|
||||||
Text(skill.archivedAtLabel)
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundFaint)
|
|
||||||
.frame(width: 96, alignment: .trailing)
|
|
||||||
Text(skill.sizeLabel)
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundFaint)
|
|
||||||
.frame(width: 72, alignment: .trailing)
|
|
||||||
Button("Restore") {
|
|
||||||
onRestore()
|
|
||||||
}
|
|
||||||
.buttonStyle(ScarfPrimaryButton())
|
|
||||||
.controlSize(.small)
|
|
||||||
.help("Restore \(skill.name) to the active skill set")
|
|
||||||
}
|
|
||||||
.padding(.vertical, 2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,123 +0,0 @@
|
|||||||
import SwiftUI
|
|
||||||
import ScarfCore
|
|
||||||
import ScarfDesign
|
|
||||||
|
|
||||||
/// Destructive-confirm sheet for `hermes curator prune` (bulk).
|
|
||||||
///
|
|
||||||
/// Pattern matches `TemplateUninstallSheet`: enumerate every entry that
|
|
||||||
/// will be removed, surface the total count + bytes, and require an
|
|
||||||
/// explicit click on a red `ScarfDestructiveButton` ("Prune
|
|
||||||
/// permanently") before kicking off the destructive call. Cancel owns
|
|
||||||
/// the keyboard default action so an accidental Enter-press doesn't
|
|
||||||
/// nuke the archive.
|
|
||||||
struct CuratorPruneConfirmSheet: View {
|
|
||||||
@Environment(\.dismiss) private var dismiss
|
|
||||||
let summary: CuratorPruneSummary
|
|
||||||
let isPruning: Bool
|
|
||||||
let onConfirm: () -> Void
|
|
||||||
let onCancel: () -> Void
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
VStack(alignment: .leading, spacing: 0) {
|
|
||||||
header
|
|
||||||
.padding(.bottom, ScarfSpace.s2)
|
|
||||||
ScarfDivider()
|
|
||||||
ScrollView {
|
|
||||||
VStack(alignment: .leading, spacing: ScarfSpace.s2) {
|
|
||||||
ForEach(summary.wouldRemove) { skill in
|
|
||||||
row(skill: skill)
|
|
||||||
}
|
|
||||||
if summary.wouldRemove.isEmpty {
|
|
||||||
Text("Nothing currently archived. Nothing to prune.")
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundMuted)
|
|
||||||
.padding(.vertical, ScarfSpace.s2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding(.vertical, ScarfSpace.s2)
|
|
||||||
}
|
|
||||||
ScarfDivider()
|
|
||||||
footer
|
|
||||||
.padding(.top, ScarfSpace.s2)
|
|
||||||
}
|
|
||||||
.frame(minWidth: 520, minHeight: 380)
|
|
||||||
.padding(ScarfSpace.s4)
|
|
||||||
}
|
|
||||||
|
|
||||||
private var header: some View {
|
|
||||||
VStack(alignment: .leading, spacing: ScarfSpace.s1) {
|
|
||||||
HStack(alignment: .firstTextBaseline) {
|
|
||||||
Text("Prune Archived Skills")
|
|
||||||
.scarfStyle(.title2)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundPrimary)
|
|
||||||
Spacer()
|
|
||||||
if summary.totalCount > 0 {
|
|
||||||
ScarfBadge("\(summary.totalCount)", kind: .danger)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Text("This permanently deletes every archived skill from disk. Restoring an archived skill is no longer possible after pruning.")
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundMuted)
|
|
||||||
.fixedSize(horizontal: false, vertical: true)
|
|
||||||
if summary.totalBytes > 0 {
|
|
||||||
Text("Total to remove: \(summary.totalBytesLabel)")
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundFaint)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private func row(skill: HermesCuratorArchivedSkill) -> some View {
|
|
||||||
HStack(spacing: ScarfSpace.s2) {
|
|
||||||
Image(systemName: "minus.circle")
|
|
||||||
.foregroundStyle(ScarfColor.danger)
|
|
||||||
.font(.caption)
|
|
||||||
VStack(alignment: .leading, spacing: 2) {
|
|
||||||
Text(skill.name)
|
|
||||||
.scarfStyle(.body)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundPrimary)
|
|
||||||
.lineLimit(1)
|
|
||||||
if let reason = skill.reason, !reason.isEmpty {
|
|
||||||
Text(reason)
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundMuted)
|
|
||||||
.lineLimit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Spacer()
|
|
||||||
Text(skill.archivedAtLabel)
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundFaint)
|
|
||||||
.frame(width: 96, alignment: .trailing)
|
|
||||||
Text(skill.sizeLabel)
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundFaint)
|
|
||||||
.frame(width: 72, alignment: .trailing)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private var footer: some View {
|
|
||||||
HStack {
|
|
||||||
Button("Cancel") {
|
|
||||||
onCancel()
|
|
||||||
dismiss()
|
|
||||||
}
|
|
||||||
.buttonStyle(ScarfGhostButton())
|
|
||||||
// Cancel owns .defaultAction so accidental Enter-presses
|
|
||||||
// don't trigger the destructive button (template-uninstall
|
|
||||||
// pattern recommended in the WS-4 plan).
|
|
||||||
.keyboardShortcut(.defaultAction)
|
|
||||||
.disabled(isPruning)
|
|
||||||
Spacer()
|
|
||||||
if isPruning {
|
|
||||||
ProgressView().controlSize(.small)
|
|
||||||
}
|
|
||||||
Button("Prune permanently") {
|
|
||||||
onConfirm()
|
|
||||||
}
|
|
||||||
.buttonStyle(ScarfDestructiveButton())
|
|
||||||
.disabled(isPruning || summary.wouldRemove.isEmpty)
|
|
||||||
.accessibilityIdentifier("curatorPrune.confirm")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,16 +2,18 @@ import SwiftUI
|
|||||||
import ScarfCore
|
import ScarfCore
|
||||||
import ScarfDesign
|
import ScarfDesign
|
||||||
|
|
||||||
/// Legacy v0.12 fallback for restoring an archived skill by typed
|
/// Modal that lists archived skills (state ≠ active) and exposes a
|
||||||
/// name. Hermes v0.12 didn't ship `curator list-archived`, so the only
|
/// one-click "Restore" action per row. v0.12 archives are recoverable —
|
||||||
/// way to restore was to remember the skill name and pass it through
|
/// `hermes curator restore <name>` brings the skill back into
|
||||||
/// `hermes curator restore <name>`.
|
/// `~/.hermes/skills/<category>/<name>/` and re-marks it active.
|
||||||
///
|
///
|
||||||
/// **v0.13+ flow (preferred):** `CuratorArchivedSection` renders a
|
/// The Curator's `status` text doesn't enumerate archived skills with
|
||||||
/// per-skill list with a one-click Restore button per row — no typing
|
/// names; we surface what's available (counts + pinned list) and rely
|
||||||
/// required. This sheet stays reachable from the overflow menu only on
|
/// on the user knowing the names. Hermes ergo does an interactive
|
||||||
/// pre-v0.13 hosts (gated by `!hasCuratorArchive`). Don't delete this
|
/// `--name` arg if missing — but Scarf prefers explicit selection so
|
||||||
/// file even after WS-4 ships; v0.12 hosts still depend on it.
|
/// users don't have to remember names. For v2.6 we render a free-form
|
||||||
|
/// text field; once Hermes ships a `curator list-archived` (tracked
|
||||||
|
/// upstream), swap to a pickable list.
|
||||||
struct CuratorRestoreSheet: View {
|
struct CuratorRestoreSheet: View {
|
||||||
let viewModel: CuratorViewModel
|
let viewModel: CuratorViewModel
|
||||||
|
|
||||||
|
|||||||
@@ -2,52 +2,57 @@ import SwiftUI
|
|||||||
import ScarfCore
|
import ScarfCore
|
||||||
import ScarfDesign
|
import ScarfDesign
|
||||||
|
|
||||||
/// Mac UI for Hermes's autonomous skill curator (v0.12 base + v0.13
|
/// Mac UI for Hermes v0.12's autonomous skill curator.
|
||||||
/// archive/prune surface).
|
|
||||||
///
|
///
|
||||||
/// Surfaces the running state (enabled / paused / disabled), last-run
|
/// Surfaces the running state (enabled / paused / disabled), last-run
|
||||||
/// metadata, agent-created skill counts, the most/least-active /
|
/// metadata, agent-created skill counts, and the most/least-active /
|
||||||
/// least-recently-active leaderboards, and on v0.13+ hosts the new
|
/// least-recently-active leaderboards. Pin-and-restore actions hit
|
||||||
/// archived-skills section + per-row Archive button on each leaderboard
|
/// `hermes curator pin/unpin/restore` via CuratorViewModel.
|
||||||
/// entry. Pin / unpin / restore / archive / prune route through
|
|
||||||
/// CuratorViewModel → CuratorService.
|
|
||||||
///
|
///
|
||||||
/// Capability-gated upstream: AppCoordinator only wires the sidebar
|
/// Capability-gated upstream: AppCoordinator only wires the sidebar
|
||||||
/// item when `HermesCapabilities.hasCurator` is true. Archive surfaces
|
/// item when `HermesCapabilities.hasCurator` is true. This view assumes
|
||||||
/// gate independently on `hasCuratorArchive`; pre-v0.13 hosts see the
|
/// it's reachable on a v0.12+ host.
|
||||||
/// v2.7.x layout unchanged (legacy `CuratorRestoreSheet` reachable from
|
|
||||||
/// the overflow menu, no Archive section, fire-and-forget Run Now).
|
|
||||||
struct CuratorView: View {
|
struct CuratorView: View {
|
||||||
@State private var viewModel: CuratorViewModel
|
@State private var viewModel: CuratorViewModel
|
||||||
@State private var showRestoreSheet = false
|
@State private var showRestoreSheet = false
|
||||||
|
|
||||||
@Environment(\.hermesCapabilities) private var capabilitiesStore
|
|
||||||
|
|
||||||
init(context: ServerContext) {
|
init(context: ServerContext) {
|
||||||
_viewModel = State(initialValue: CuratorViewModel(context: context))
|
_viewModel = State(initialValue: CuratorViewModel(context: context))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Single source of truth for "v0.13 archive surface visible". Read
|
|
||||||
/// once in `body` and threaded into sub-views. Defensive default to
|
|
||||||
/// `false` so previews / smoke tests behave like a pre-v0.13 host.
|
|
||||||
private var archiveAvailable: Bool {
|
|
||||||
capabilitiesStore?.capabilities.hasCuratorArchive ?? false
|
|
||||||
}
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ScrollView {
|
ScrollView {
|
||||||
VStack(alignment: .leading, spacing: ScarfSpace.s4) {
|
VStack(alignment: .leading, spacing: ScarfSpace.s4) {
|
||||||
ScarfPageHeader(
|
ScarfPageHeader(
|
||||||
"Curator",
|
"Curator",
|
||||||
subtitle: archiveAvailable
|
subtitle: "Autonomous skill maintenance — Hermes v0.12+"
|
||||||
? "Autonomous skill maintenance — archive, prune, restore"
|
|
||||||
: "Autonomous skill maintenance — Hermes v0.12+"
|
|
||||||
) {
|
) {
|
||||||
headerActions
|
HStack(spacing: ScarfSpace.s2) {
|
||||||
|
if viewModel.isLoading {
|
||||||
|
ProgressView().controlSize(.small)
|
||||||
|
}
|
||||||
|
Button("Run Now") {
|
||||||
|
Task { await viewModel.runNow() }
|
||||||
|
}
|
||||||
|
.buttonStyle(ScarfPrimaryButton())
|
||||||
|
.disabled(viewModel.isLoading)
|
||||||
|
Menu {
|
||||||
|
switch viewModel.status.state {
|
||||||
|
case .paused:
|
||||||
|
Button("Resume") { Task { await viewModel.resume() } }
|
||||||
|
case .enabled:
|
||||||
|
Button("Pause") { Task { await viewModel.pause() } }
|
||||||
|
default:
|
||||||
|
EmptyView()
|
||||||
|
}
|
||||||
|
Button("Restore Archived…") {
|
||||||
|
showRestoreSheet = true
|
||||||
|
}
|
||||||
|
.disabled(viewModel.status.archivedSkills == 0)
|
||||||
|
} label: {
|
||||||
|
Image(systemName: "ellipsis.circle")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let errorMessage = viewModel.errorMessage {
|
|
||||||
errorBanner(errorMessage)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let toast = viewModel.transientMessage {
|
if let toast = viewModel.transientMessage {
|
||||||
@@ -59,19 +64,6 @@ struct CuratorView: View {
|
|||||||
pinnedSection
|
pinnedSection
|
||||||
activityTables
|
activityTables
|
||||||
|
|
||||||
if archiveAvailable {
|
|
||||||
CuratorArchivedSection(
|
|
||||||
archived: viewModel.archivedSkills,
|
|
||||||
isLoading: viewModel.isLoadingArchive,
|
|
||||||
onRestore: { name in
|
|
||||||
Task { await viewModel.restore(name) }
|
|
||||||
},
|
|
||||||
onPruneAll: {
|
|
||||||
Task { await viewModel.planPrune() }
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if let report = viewModel.lastReportMarkdown {
|
if let report = viewModel.lastReportMarkdown {
|
||||||
lastReportSection(markdown: report)
|
lastReportSection(markdown: report)
|
||||||
}
|
}
|
||||||
@@ -79,84 +71,10 @@ struct CuratorView: View {
|
|||||||
.padding(ScarfSpace.s4)
|
.padding(ScarfSpace.s4)
|
||||||
}
|
}
|
||||||
.background(ScarfColor.backgroundPrimary)
|
.background(ScarfColor.backgroundPrimary)
|
||||||
.task {
|
.task { await viewModel.load() }
|
||||||
await viewModel.load()
|
|
||||||
if archiveAvailable {
|
|
||||||
await viewModel.loadArchive()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.sheet(isPresented: $showRestoreSheet) {
|
.sheet(isPresented: $showRestoreSheet) {
|
||||||
CuratorRestoreSheet(viewModel: viewModel)
|
CuratorRestoreSheet(viewModel: viewModel)
|
||||||
}
|
}
|
||||||
.sheet(
|
|
||||||
isPresented: Binding(
|
|
||||||
get: { viewModel.pruneSummary != nil },
|
|
||||||
set: { isShown in
|
|
||||||
if !isShown { viewModel.cancelPrune() }
|
|
||||||
}
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
if let summary = viewModel.pruneSummary {
|
|
||||||
CuratorPruneConfirmSheet(
|
|
||||||
summary: summary,
|
|
||||||
isPruning: viewModel.isPruning,
|
|
||||||
onConfirm: {
|
|
||||||
Task { await viewModel.confirmPrune() }
|
|
||||||
},
|
|
||||||
onCancel: {
|
|
||||||
viewModel.cancelPrune()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ViewBuilder
|
|
||||||
private var headerActions: some View {
|
|
||||||
HStack(spacing: ScarfSpace.s2) {
|
|
||||||
if viewModel.isLoading {
|
|
||||||
ProgressView().controlSize(.small)
|
|
||||||
}
|
|
||||||
Button("Run Now") {
|
|
||||||
Task {
|
|
||||||
await viewModel.runNow(
|
|
||||||
synchronous: archiveAvailable,
|
|
||||||
timeout: 600
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.buttonStyle(ScarfPrimaryButton())
|
|
||||||
.disabled(viewModel.isLoading)
|
|
||||||
.help(archiveAvailable
|
|
||||||
? "Curator runs synchronously on Hermes v0.13+. Usually 10–90s."
|
|
||||||
: "Trigger a curator run. Returns immediately on pre-v0.13 hosts.")
|
|
||||||
|
|
||||||
Menu {
|
|
||||||
switch viewModel.status.state {
|
|
||||||
case .paused:
|
|
||||||
Button("Resume") { Task { await viewModel.resume() } }
|
|
||||||
case .enabled:
|
|
||||||
Button("Pause") { Task { await viewModel.pause() } }
|
|
||||||
default:
|
|
||||||
EmptyView()
|
|
||||||
}
|
|
||||||
|
|
||||||
if archiveAvailable {
|
|
||||||
Divider()
|
|
||||||
Button("Prune Archived…", role: .destructive) {
|
|
||||||
Task { await viewModel.planPrune() }
|
|
||||||
}
|
|
||||||
.disabled(viewModel.archivedSkills.isEmpty && !viewModel.isLoadingArchive)
|
|
||||||
} else {
|
|
||||||
Button("Restore Archived…") {
|
|
||||||
showRestoreSheet = true
|
|
||||||
}
|
|
||||||
.disabled(viewModel.status.archivedSkills == 0)
|
|
||||||
}
|
|
||||||
} label: {
|
|
||||||
Image(systemName: "ellipsis.circle")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var statusSummary: some View {
|
private var statusSummary: some View {
|
||||||
@@ -288,10 +206,6 @@ struct CuratorView: View {
|
|||||||
}
|
}
|
||||||
.buttonStyle(.plain)
|
.buttonStyle(.plain)
|
||||||
.help(viewModel.status.pinnedNames.contains(row.name) ? "Pinned" : "Pin skill")
|
.help(viewModel.status.pinnedNames.contains(row.name) ? "Pinned" : "Pin skill")
|
||||||
|
|
||||||
if archiveAvailable {
|
|
||||||
archiveButton(for: row.name)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.padding(.vertical, 2)
|
.padding(.vertical, 2)
|
||||||
}
|
}
|
||||||
@@ -299,25 +213,6 @@ struct CuratorView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
|
||||||
private func archiveButton(for name: String) -> some View {
|
|
||||||
if viewModel.pendingArchiveName == name {
|
|
||||||
ProgressView()
|
|
||||||
.controlSize(.small)
|
|
||||||
.frame(width: 14, height: 14)
|
|
||||||
} else {
|
|
||||||
Button {
|
|
||||||
Task { await viewModel.archive(name) }
|
|
||||||
} label: {
|
|
||||||
Image(systemName: "archivebox")
|
|
||||||
.font(.system(size: 12))
|
|
||||||
}
|
|
||||||
.buttonStyle(.plain)
|
|
||||||
.help("Archive (move out of active set)")
|
|
||||||
.disabled(viewModel.pendingArchiveName != nil)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private func counterChip(label: String, value: Int) -> some View {
|
private func counterChip(label: String, value: Int) -> some View {
|
||||||
Text("\(label) \(value)")
|
Text("\(label) \(value)")
|
||||||
.font(ScarfFont.monoSmall)
|
.font(ScarfFont.monoSmall)
|
||||||
@@ -382,35 +277,6 @@ struct CuratorView: View {
|
|||||||
.background(ScarfColor.accentTint)
|
.background(ScarfColor.accentTint)
|
||||||
.clipShape(RoundedRectangle(cornerRadius: ScarfRadius.md))
|
.clipShape(RoundedRectangle(cornerRadius: ScarfRadius.md))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Inline yellow banner for CLI failures. Non-blocking — sits above
|
|
||||||
/// the status summary and dismisses with the "x" so users can keep
|
|
||||||
/// interacting with the leaderboard. Mirrors the pattern in
|
|
||||||
/// KanbanBoardView.
|
|
||||||
private func errorBanner(_ message: String) -> some View {
|
|
||||||
HStack(alignment: .top, spacing: ScarfSpace.s2) {
|
|
||||||
Image(systemName: "exclamationmark.triangle.fill")
|
|
||||||
.foregroundStyle(ScarfColor.warning)
|
|
||||||
Text(message)
|
|
||||||
.scarfStyle(.caption)
|
|
||||||
.foregroundStyle(ScarfColor.foregroundPrimary)
|
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
|
||||||
Button {
|
|
||||||
viewModel.dismissError()
|
|
||||||
} label: {
|
|
||||||
Image(systemName: "xmark.circle.fill")
|
|
||||||
.foregroundStyle(ScarfColor.foregroundMuted)
|
|
||||||
}
|
|
||||||
.buttonStyle(.plain)
|
|
||||||
.help("Dismiss")
|
|
||||||
}
|
|
||||||
.padding(.horizontal, ScarfSpace.s3)
|
|
||||||
.padding(.vertical, ScarfSpace.s2)
|
|
||||||
.background(
|
|
||||||
RoundedRectangle(cornerRadius: ScarfRadius.md)
|
|
||||||
.fill(ScarfColor.warning.opacity(0.12))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Simple `FlowLayout` for the pinned-skill chips. Custom layout
|
/// Simple `FlowLayout` for the pinned-skill chips. Custom layout
|
||||||
|
|||||||
@@ -55,9 +55,22 @@ final class KanbanBoardViewModel {
|
|||||||
var assigneeFilter: String? // nil = all assignees
|
var assigneeFilter: String? // nil = all assignees
|
||||||
var showArchived: Bool = false
|
var showArchived: Bool = false
|
||||||
|
|
||||||
/// Optimistic moves keyed by task id; cleared when the polled
|
/// Optimistic in-flight overrides keyed by task id; cleared when the
|
||||||
/// response includes the same status the optimistic move set.
|
/// polled response confirms the new state.
|
||||||
private var optimisticOverrides: [String: String] = [:]
|
/// - Status side: drag-drop column moves.
|
||||||
|
/// - Hallucination-gate side (v0.13): Verify clicks flip `pending` →
|
||||||
|
/// `verified` locally so the banner disappears immediately.
|
||||||
|
/// The override entry is dropped from the dictionary entirely once
|
||||||
|
/// both sides are nil (no override needed).
|
||||||
|
private struct OptimisticOverride {
|
||||||
|
var status: String?
|
||||||
|
var hallucinationGate: KanbanHallucinationGate?
|
||||||
|
|
||||||
|
var isEmpty: Bool {
|
||||||
|
status == nil && hallucinationGate == nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private var optimisticOverrides: [String: OptimisticOverride] = [:]
|
||||||
/// Tasks dropped into invalid columns produce a transient "denied"
|
/// Tasks dropped into invalid columns produce a transient "denied"
|
||||||
/// banner. Stored as an explicit error to support the Cmd-Z style
|
/// banner. Stored as an explicit error to support the Cmd-Z style
|
||||||
/// undo we don't ship in v2.7.5 but want to leave room for.
|
/// undo we don't ship in v2.7.5 but want to leave room for.
|
||||||
@@ -177,8 +190,10 @@ final class KanbanBoardViewModel {
|
|||||||
// Optimistic mutation — flip the local row's status to a
|
// Optimistic mutation — flip the local row's status to a
|
||||||
// value within the destination column's range. We pick a
|
// value within the destination column's range. We pick a
|
||||||
// representative status per column.
|
// representative status per column.
|
||||||
let optimisticStatus = optimisticStatus(for: destination)
|
let optimisticStatusValue = optimisticStatus(for: destination)
|
||||||
optimisticOverrides[taskId] = optimisticStatus
|
var override = optimisticOverrides[taskId] ?? OptimisticOverride()
|
||||||
|
override.status = optimisticStatusValue
|
||||||
|
optimisticOverrides[taskId] = override
|
||||||
|
|
||||||
let svc = service
|
let svc = service
|
||||||
Task {
|
Task {
|
||||||
@@ -190,11 +205,11 @@ final class KanbanBoardViewModel {
|
|||||||
// without waiting for the 5s tick.
|
// without waiting for the 5s tick.
|
||||||
await refresh()
|
await refresh()
|
||||||
} catch let err as KanbanError {
|
} catch let err as KanbanError {
|
||||||
optimisticOverrides.removeValue(forKey: taskId)
|
clearStatusOverride(for: taskId)
|
||||||
lastError = err.errorDescription
|
lastError = err.errorDescription
|
||||||
logger.warning("kanban move failed: \(err.errorDescription ?? "", privacy: .public)")
|
logger.warning("kanban move failed: \(err.errorDescription ?? "", privacy: .public)")
|
||||||
} catch {
|
} catch {
|
||||||
optimisticOverrides.removeValue(forKey: taskId)
|
clearStatusOverride(for: taskId)
|
||||||
lastError = error.localizedDescription
|
lastError = error.localizedDescription
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -269,6 +284,48 @@ final class KanbanBoardViewModel {
|
|||||||
return task
|
return task
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Hallucination gate (v0.13)
|
||||||
|
|
||||||
|
/// User confirmed the worker-created card is real. Optimistically
|
||||||
|
/// flip the gate to `verified` so the banner disappears immediately;
|
||||||
|
/// the polling loop confirms the new state on the next tick. On
|
||||||
|
/// failure (e.g. the verb name is wrong on this v0.13.x build), the
|
||||||
|
/// override is cleared and the error surfaces in `lastError`.
|
||||||
|
func verifyHallucination(taskId: String) {
|
||||||
|
var override = optimisticOverrides[taskId] ?? OptimisticOverride()
|
||||||
|
override.hallucinationGate = .verified
|
||||||
|
optimisticOverrides[taskId] = override
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
try await service.verify(taskId: taskId)
|
||||||
|
await refresh()
|
||||||
|
} catch let err as KanbanError {
|
||||||
|
clearHallucinationOverride(for: taskId)
|
||||||
|
lastError = err.errorDescription
|
||||||
|
logger.warning("kanban verify failed: \(err.errorDescription ?? "", privacy: .public)")
|
||||||
|
} catch {
|
||||||
|
clearHallucinationOverride(for: taskId)
|
||||||
|
lastError = error.localizedDescription
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// User rejected the worker-created card as a hallucinated reference.
|
||||||
|
/// Routes through `comment` + `archive` per `KanbanService.rejectHallucinated`
|
||||||
|
/// so there's an audit trail for why the card disappeared.
|
||||||
|
func rejectHallucination(taskId: String) {
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
try await service.rejectHallucinated(taskId: taskId)
|
||||||
|
await refresh()
|
||||||
|
} catch let err as KanbanError {
|
||||||
|
lastError = err.errorDescription
|
||||||
|
} catch {
|
||||||
|
lastError = error.localizedDescription
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Private helpers
|
// MARK: - Private helpers
|
||||||
|
|
||||||
private func mergePolledTasks(_ polled: [HermesKanbanTask]) {
|
private func mergePolledTasks(_ polled: [HermesKanbanTask]) {
|
||||||
@@ -282,25 +339,75 @@ final class KanbanBoardViewModel {
|
|||||||
filtered = polled
|
filtered = polled
|
||||||
}
|
}
|
||||||
let presentIds = Set(filtered.map(\.id))
|
let presentIds = Set(filtered.map(\.id))
|
||||||
// Drop optimistic overrides for tasks Hermes confirmed.
|
// Drop optimistic overrides for tasks Hermes confirmed. Two
|
||||||
for (id, optimistic) in optimisticOverrides {
|
// independent sides — clear them separately so a Verify click
|
||||||
if let row = filtered.first(where: { $0.id == id }) {
|
// still in-flight survives a status-side poll confirmation, and
|
||||||
if columnFromStatus(optimistic) == columnFromStatus(row.status) {
|
// vice versa.
|
||||||
|
for (id, override) in optimisticOverrides {
|
||||||
|
guard let row = filtered.first(where: { $0.id == id }) else {
|
||||||
|
if !presentIds.contains(id) {
|
||||||
|
// Task no longer in the polled set (archived, deleted,
|
||||||
|
// or filtered out). Drop the override entirely.
|
||||||
optimisticOverrides.removeValue(forKey: id)
|
optimisticOverrides.removeValue(forKey: id)
|
||||||
}
|
}
|
||||||
} else if !presentIds.contains(id) {
|
continue
|
||||||
// Task no longer in the polled set (archived, deleted,
|
}
|
||||||
// or filtered out). Drop the optimistic entry.
|
// Status side — optimistic move confirmed.
|
||||||
|
if let optStatus = override.status,
|
||||||
|
columnFromStatus(optStatus) == columnFromStatus(row.status) {
|
||||||
|
optimisticOverrides[id]?.status = nil
|
||||||
|
}
|
||||||
|
// Hallucination-gate side — optimistic verify/reject confirmed.
|
||||||
|
if let optGate = override.hallucinationGate,
|
||||||
|
KanbanHallucinationGate.from(row.hallucinationGateStatus) == optGate {
|
||||||
|
optimisticOverrides[id]?.hallucinationGate = nil
|
||||||
|
}
|
||||||
|
if optimisticOverrides[id]?.isEmpty ?? true {
|
||||||
optimisticOverrides.removeValue(forKey: id)
|
optimisticOverrides.removeValue(forKey: id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tasks = filtered
|
tasks = filtered
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Drop the status side of a task's override (preserving any
|
||||||
|
/// in-flight hallucination-gate optimistic state).
|
||||||
|
private func clearStatusOverride(for taskId: String) {
|
||||||
|
guard var override = optimisticOverrides[taskId] else { return }
|
||||||
|
override.status = nil
|
||||||
|
if override.isEmpty {
|
||||||
|
optimisticOverrides.removeValue(forKey: taskId)
|
||||||
|
} else {
|
||||||
|
optimisticOverrides[taskId] = override
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Drop the hallucination-gate side of a task's override (preserving
|
||||||
|
/// any in-flight status-side drag-drop).
|
||||||
|
private func clearHallucinationOverride(for taskId: String) {
|
||||||
|
guard var override = optimisticOverrides[taskId] else { return }
|
||||||
|
override.hallucinationGate = nil
|
||||||
|
if override.isEmpty {
|
||||||
|
optimisticOverrides.removeValue(forKey: taskId)
|
||||||
|
} else {
|
||||||
|
optimisticOverrides[taskId] = override
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Effective hallucination gate for a task — the optimistic override
|
||||||
|
/// wins if one is in flight; otherwise the polled value. View code
|
||||||
|
/// reads through this so the banner / dim state matches the moment-
|
||||||
|
/// after-click experience.
|
||||||
|
func effectiveHallucinationGate(_ task: HermesKanbanTask) -> KanbanHallucinationGate? {
|
||||||
|
if let override = optimisticOverrides[task.id]?.hallucinationGate {
|
||||||
|
return override
|
||||||
|
}
|
||||||
|
return KanbanHallucinationGate.from(task.hallucinationGateStatus)
|
||||||
|
}
|
||||||
|
|
||||||
/// Return the effective board column for a task — the optimistic
|
/// Return the effective board column for a task — the optimistic
|
||||||
/// override wins if one is in flight; otherwise the polled status.
|
/// override wins if one is in flight; otherwise the polled status.
|
||||||
private func effectiveColumn(_ task: HermesKanbanTask) -> KanbanBoardColumn {
|
private func effectiveColumn(_ task: HermesKanbanTask) -> KanbanBoardColumn {
|
||||||
if let overrideStatus = optimisticOverrides[task.id] {
|
if let overrideStatus = optimisticOverrides[task.id]?.status {
|
||||||
return columnFromStatus(overrideStatus)
|
return columnFromStatus(overrideStatus)
|
||||||
}
|
}
|
||||||
return columnFromStatus(task.status)
|
return columnFromStatus(task.status)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import ScarfDesign
|
|||||||
/// tenant.
|
/// tenant.
|
||||||
struct KanbanBoardView: View {
|
struct KanbanBoardView: View {
|
||||||
@State private var viewModel: KanbanBoardViewModel
|
@State private var viewModel: KanbanBoardViewModel
|
||||||
|
@Environment(\.hermesCapabilities) private var capabilitiesStore
|
||||||
|
|
||||||
/// When non-nil, a project board hosts this view. Drives header
|
/// When non-nil, a project board hosts this view. Drives header
|
||||||
/// chrome (subtitle, hidden tenant filter) and create-sheet
|
/// chrome (subtitle, hidden tenant filter) and create-sheet
|
||||||
@@ -33,6 +34,15 @@ struct KanbanBoardView: View {
|
|||||||
self.projectName = projectName
|
self.projectName = projectName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convenience read for the v0.13 diagnostics flag — gates the
|
||||||
|
/// max_retries field, hallucination banner, diagnostics rendering,
|
||||||
|
/// and the auto-blocked reason banner. Pre-v0.13 hosts get the
|
||||||
|
/// v2.7.5 surface unchanged. Treats a missing store as "off" so
|
||||||
|
/// harness contexts (Previews) don't accidentally surface gated UI.
|
||||||
|
private var supportsKanbanDiagnostics: Bool {
|
||||||
|
capabilitiesStore?.capabilities.hasKanbanDiagnostics ?? false
|
||||||
|
}
|
||||||
|
|
||||||
@State private var inspectorTaskId: String?
|
@State private var inspectorTaskId: String?
|
||||||
@State private var showingCreateSheet = false
|
@State private var showingCreateSheet = false
|
||||||
@State private var blockSheetTaskId: String?
|
@State private var blockSheetTaskId: String?
|
||||||
@@ -71,7 +81,8 @@ struct KanbanBoardView: View {
|
|||||||
KanbanCreateSheet(
|
KanbanCreateSheet(
|
||||||
assignees: viewModel.assignees,
|
assignees: viewModel.assignees,
|
||||||
tenantPrefill: viewModel.tenantFilter,
|
tenantPrefill: viewModel.tenantFilter,
|
||||||
projectWorkspacePath: viewModel.projectPath
|
projectWorkspacePath: viewModel.projectPath,
|
||||||
|
supportsKanbanDiagnostics: supportsKanbanDiagnostics
|
||||||
) { request in
|
) { request in
|
||||||
_ = try await viewModel.createTask(request)
|
_ = try await viewModel.createTask(request)
|
||||||
}
|
}
|
||||||
@@ -188,7 +199,9 @@ struct KanbanBoardView: View {
|
|||||||
onDrop: { ref in
|
onDrop: { ref in
|
||||||
handleDrop(ref.id, on: column)
|
handleDrop(ref.id, on: column)
|
||||||
},
|
},
|
||||||
canCreate: column == .upNext || column == .triage
|
canCreate: column == .upNext || column == .triage,
|
||||||
|
supportsKanbanDiagnostics: supportsKanbanDiagnostics,
|
||||||
|
effectiveHallucinationGate: { viewModel.effectiveHallucinationGate($0) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Spacer(minLength: ScarfSpace.s4)
|
Spacer(minLength: ScarfSpace.s4)
|
||||||
@@ -208,6 +221,8 @@ struct KanbanBoardView: View {
|
|||||||
service: viewModel.service,
|
service: viewModel.service,
|
||||||
taskId: taskId,
|
taskId: taskId,
|
||||||
availableAssignees: viewModel.assignees,
|
availableAssignees: viewModel.assignees,
|
||||||
|
supportsKanbanDiagnostics: supportsKanbanDiagnostics,
|
||||||
|
effectiveHallucinationGate: { viewModel.effectiveHallucinationGate($0) },
|
||||||
onClose: { inspectorTaskId = nil },
|
onClose: { inspectorTaskId = nil },
|
||||||
onClaim: {
|
onClaim: {
|
||||||
viewModel.attemptMove(taskId: taskId, to: .running)
|
viewModel.attemptMove(taskId: taskId, to: .running)
|
||||||
@@ -232,6 +247,15 @@ struct KanbanBoardView: View {
|
|||||||
},
|
},
|
||||||
onReassign: { profile in
|
onReassign: { profile in
|
||||||
viewModel.reassignTask(taskId: taskId, to: profile)
|
viewModel.reassignTask(taskId: taskId, to: profile)
|
||||||
|
},
|
||||||
|
onVerifyHallucination: {
|
||||||
|
viewModel.verifyHallucination(taskId: taskId)
|
||||||
|
},
|
||||||
|
onRejectHallucination: {
|
||||||
|
viewModel.rejectHallucination(taskId: taskId)
|
||||||
|
// Card vanishes from active board after archive — close
|
||||||
|
// the inspector so it doesn't dangle on a deleted task.
|
||||||
|
inspectorTaskId = nil
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,12 +24,40 @@ struct KanbanTaskRef: Transferable {
|
|||||||
/// - **Running** gets a blue left-edge accent + live shimmer
|
/// - **Running** gets a blue left-edge accent + live shimmer
|
||||||
/// - **Blocked** gets a warning left-edge accent + ⚠ glyph
|
/// - **Blocked** gets a warning left-edge accent + ⚠ glyph
|
||||||
/// - **Done** dims to 0.7 opacity (0.55 in dark mode)
|
/// - **Done** dims to 0.7 opacity (0.55 in dark mode)
|
||||||
|
/// - **Hallucination-gate pending** (v0.13+) dims to 0.6 + ⚠ glyph and
|
||||||
|
/// shows a one-line auto-blocked reason in the footer when present.
|
||||||
struct KanbanCardView: View {
|
struct KanbanCardView: View {
|
||||||
let task: HermesKanbanTask
|
let task: HermesKanbanTask
|
||||||
let onTap: () -> Void
|
let onTap: () -> Void
|
||||||
|
/// True when the connected Hermes is on v0.13+ — gates the
|
||||||
|
/// hallucination dim/glyph, auto-block sub-line, and diagnostics
|
||||||
|
/// dot on the card. Pre-v0.13 hosts see the v2.7.5 chrome unchanged.
|
||||||
|
let supportsKanbanDiagnostics: Bool
|
||||||
|
/// Optimistic-aware accessor. Pre-v0.13 always nil. Otherwise delegates
|
||||||
|
/// to the board VM so a Verify click un-dims the card immediately.
|
||||||
|
let effectiveHallucinationGate: (HermesKanbanTask) -> KanbanHallucinationGate?
|
||||||
|
|
||||||
|
init(
|
||||||
|
task: HermesKanbanTask,
|
||||||
|
supportsKanbanDiagnostics: Bool = false,
|
||||||
|
effectiveHallucinationGate: @escaping (HermesKanbanTask) -> KanbanHallucinationGate? = { _ in nil },
|
||||||
|
onTap: @escaping () -> Void
|
||||||
|
) {
|
||||||
|
self.task = task
|
||||||
|
self.supportsKanbanDiagnostics = supportsKanbanDiagnostics
|
||||||
|
self.effectiveHallucinationGate = effectiveHallucinationGate
|
||||||
|
self.onTap = onTap
|
||||||
|
}
|
||||||
|
|
||||||
@Environment(\.colorScheme) private var colorScheme
|
@Environment(\.colorScheme) private var colorScheme
|
||||||
|
|
||||||
|
/// Cached gate read — derived once per body eval rather than recomputed
|
||||||
|
/// in each subview helper.
|
||||||
|
private var hallucinationGate: KanbanHallucinationGate? {
|
||||||
|
guard supportsKanbanDiagnostics else { return nil }
|
||||||
|
return effectiveHallucinationGate(task)
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Button(action: onTap) {
|
Button(action: onTap) {
|
||||||
VStack(alignment: .leading, spacing: ScarfSpace.s2) {
|
VStack(alignment: .leading, spacing: ScarfSpace.s2) {
|
||||||
@@ -66,13 +94,22 @@ struct KanbanCardView: View {
|
|||||||
}
|
}
|
||||||
.buttonStyle(.plain)
|
.buttonStyle(.plain)
|
||||||
.scarfShadow(.sm)
|
.scarfShadow(.sm)
|
||||||
.opacity(task.isDone ? doneOpacity : 1.0)
|
// v0.13: hallucination-pending cards dim to 0.6 to signal "needs
|
||||||
|
// verification before running" without making them unreadable.
|
||||||
|
// Done cards stay at the established doneOpacity (0.7 / 0.55).
|
||||||
|
.opacity(cardOpacity)
|
||||||
.draggable(KanbanTaskRef(id: task.id)) {
|
.draggable(KanbanTaskRef(id: task.id)) {
|
||||||
// Drag preview — the live card with a heavier shadow.
|
// Drag preview — the live card with a heavier shadow.
|
||||||
self.dragPreview
|
self.dragPreview
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var cardOpacity: Double {
|
||||||
|
if task.isDone { return doneOpacity }
|
||||||
|
if hallucinationGate == .pending { return 0.6 }
|
||||||
|
return 1.0
|
||||||
|
}
|
||||||
|
|
||||||
private var titleRow: some View {
|
private var titleRow: some View {
|
||||||
HStack(alignment: .top, spacing: ScarfSpace.s2) {
|
HStack(alignment: .top, spacing: ScarfSpace.s2) {
|
||||||
statusGlyph
|
statusGlyph
|
||||||
@@ -82,7 +119,15 @@ struct KanbanCardView: View {
|
|||||||
.lineLimit(2)
|
.lineLimit(2)
|
||||||
.multilineTextAlignment(.leading)
|
.multilineTextAlignment(.leading)
|
||||||
Spacer(minLength: 0)
|
Spacer(minLength: 0)
|
||||||
if needsAssignmentWarning {
|
// v0.13 hallucination glyph takes precedence over the
|
||||||
|
// unassigned glyph — the hallucination state is the more
|
||||||
|
// specific signal (a worker created this card; verify it).
|
||||||
|
if hallucinationGate == .pending {
|
||||||
|
Image(systemName: "questionmark.diamond.fill")
|
||||||
|
.foregroundStyle(ScarfColor.warning)
|
||||||
|
.font(.system(size: 11, weight: .semibold))
|
||||||
|
.help("Worker-created — verify before running")
|
||||||
|
} else if needsAssignmentWarning {
|
||||||
Image(systemName: "exclamationmark.triangle.fill")
|
Image(systemName: "exclamationmark.triangle.fill")
|
||||||
.foregroundStyle(ScarfColor.warning)
|
.foregroundStyle(ScarfColor.warning)
|
||||||
.font(.system(size: 11, weight: .semibold))
|
.font(.system(size: 11, weight: .semibold))
|
||||||
@@ -186,16 +231,40 @@ struct KanbanCardView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private var footerRow: some View {
|
private var footerRow: some View {
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
// v0.13: server-supplied auto-blocked reason. Renders verbatim
|
||||||
|
// (truncated to one line; full reason in the inspector).
|
||||||
|
// Pre-v0.13 hosts always have task.autoBlockedReason == nil.
|
||||||
|
if supportsKanbanDiagnostics,
|
||||||
|
KanbanStatus.from(task.status) == .blocked,
|
||||||
|
let reason = task.autoBlockedReason, !reason.isEmpty {
|
||||||
|
Text(reason)
|
||||||
|
.scarfStyle(.caption)
|
||||||
|
.foregroundStyle(ScarfColor.danger)
|
||||||
|
.lineLimit(1)
|
||||||
|
.truncationMode(.tail)
|
||||||
|
.help(reason)
|
||||||
|
}
|
||||||
HStack(spacing: ScarfSpace.s2) {
|
HStack(spacing: ScarfSpace.s2) {
|
||||||
Text(relativeTimeLabel)
|
Text(relativeTimeLabel)
|
||||||
.scarfStyle(.caption)
|
.scarfStyle(.caption)
|
||||||
.foregroundStyle(ScarfColor.foregroundFaint)
|
.foregroundStyle(ScarfColor.foregroundFaint)
|
||||||
Spacer(minLength: 0)
|
Spacer(minLength: 0)
|
||||||
|
// v0.13: diagnostics dot — small stethoscope glyph when
|
||||||
|
// any cross-run distress signal is attached. Matches the
|
||||||
|
// chip count in the inspector.
|
||||||
|
if supportsKanbanDiagnostics, !task.diagnostics.isEmpty {
|
||||||
|
Image(systemName: "stethoscope")
|
||||||
|
.font(.system(size: 9))
|
||||||
|
.foregroundStyle(ScarfColor.warning)
|
||||||
|
.help("\(task.diagnostics.count) diagnostic signal\(task.diagnostics.count == 1 ? "" : "s")")
|
||||||
|
}
|
||||||
if let priority = task.priority, priority >= 70 {
|
if let priority = task.priority, priority >= 70 {
|
||||||
priorityIndicator(priority)
|
priorityIndicator(priority)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func priorityIndicator(_ priority: Int) -> some View {
|
private func priorityIndicator(_ priority: Int) -> some View {
|
||||||
let color: Color = priority >= 90 ? ScarfColor.danger : ScarfColor.warning
|
let color: Color = priority >= 90 ? ScarfColor.danger : ScarfColor.warning
|
||||||
|
|||||||
@@ -17,6 +17,38 @@ struct KanbanColumnView: View {
|
|||||||
let onCreate: () -> Void
|
let onCreate: () -> Void
|
||||||
let onDrop: (KanbanTaskRef) -> Void
|
let onDrop: (KanbanTaskRef) -> Void
|
||||||
let canCreate: Bool
|
let canCreate: Bool
|
||||||
|
/// True when the connected Hermes is on v0.13+. Forwarded to each
|
||||||
|
/// `KanbanCardView` so the hallucination dim/glyph + diagnostics dot
|
||||||
|
/// + auto-block sub-line gate uniformly.
|
||||||
|
let supportsKanbanDiagnostics: Bool
|
||||||
|
/// Optimistic-aware accessor forwarded to cards. Default is
|
||||||
|
/// "no override" so Previews and harness contexts still render
|
||||||
|
/// without wiring up a board VM.
|
||||||
|
let effectiveHallucinationGate: (HermesKanbanTask) -> KanbanHallucinationGate?
|
||||||
|
|
||||||
|
init(
|
||||||
|
column: KanbanBoardColumn,
|
||||||
|
tasks: [HermesKanbanTask],
|
||||||
|
isLive: Bool,
|
||||||
|
readyPillCount: Int,
|
||||||
|
onTaskTap: @escaping (HermesKanbanTask) -> Void,
|
||||||
|
onCreate: @escaping () -> Void,
|
||||||
|
onDrop: @escaping (KanbanTaskRef) -> Void,
|
||||||
|
canCreate: Bool,
|
||||||
|
supportsKanbanDiagnostics: Bool = false,
|
||||||
|
effectiveHallucinationGate: @escaping (HermesKanbanTask) -> KanbanHallucinationGate? = { _ in nil }
|
||||||
|
) {
|
||||||
|
self.column = column
|
||||||
|
self.tasks = tasks
|
||||||
|
self.isLive = isLive
|
||||||
|
self.readyPillCount = readyPillCount
|
||||||
|
self.onTaskTap = onTaskTap
|
||||||
|
self.onCreate = onCreate
|
||||||
|
self.onDrop = onDrop
|
||||||
|
self.canCreate = canCreate
|
||||||
|
self.supportsKanbanDiagnostics = supportsKanbanDiagnostics
|
||||||
|
self.effectiveHallucinationGate = effectiveHallucinationGate
|
||||||
|
}
|
||||||
|
|
||||||
@State private var isTargeted = false
|
@State private var isTargeted = false
|
||||||
|
|
||||||
@@ -36,7 +68,11 @@ struct KanbanColumnView: View {
|
|||||||
.padding(.top, ScarfSpace.s4)
|
.padding(.top, ScarfSpace.s4)
|
||||||
} else {
|
} else {
|
||||||
ForEach(tasks) { task in
|
ForEach(tasks) { task in
|
||||||
KanbanCardView(task: task) {
|
KanbanCardView(
|
||||||
|
task: task,
|
||||||
|
supportsKanbanDiagnostics: supportsKanbanDiagnostics,
|
||||||
|
effectiveHallucinationGate: effectiveHallucinationGate
|
||||||
|
) {
|
||||||
onTaskTap(task)
|
onTaskTap(task)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,12 @@ struct KanbanCreateSheet: View {
|
|||||||
/// Pre-filled project workspace path on per-project boards. When
|
/// Pre-filled project workspace path on per-project boards. When
|
||||||
/// non-nil, the workspace picker is locked to "Project Dir".
|
/// non-nil, the workspace picker is locked to "Project Dir".
|
||||||
let projectWorkspacePath: String?
|
let projectWorkspacePath: String?
|
||||||
|
/// True when the connected Hermes is on v0.13+ — gates the
|
||||||
|
/// `--max-retries` field and decides whether to strip newlines from
|
||||||
|
/// the title at submit time. Pre-v0.13 hosts may truncate at the
|
||||||
|
/// first `\n`; we keep the multi-line input rendering on either way
|
||||||
|
/// since a taller `TextField` is harmless on v0.12.
|
||||||
|
let supportsKanbanDiagnostics: Bool
|
||||||
/// Closure invoked when the user submits — VM owner constructs the
|
/// Closure invoked when the user submits — VM owner constructs the
|
||||||
/// `KanbanService.create` call.
|
/// `KanbanService.create` call.
|
||||||
let onSubmit: (KanbanCreateRequest) async throws -> Void
|
let onSubmit: (KanbanCreateRequest) async throws -> Void
|
||||||
@@ -33,6 +39,11 @@ struct KanbanCreateSheet: View {
|
|||||||
@State private var skillsInput: String = ""
|
@State private var skillsInput: String = ""
|
||||||
@State private var tenant: String = ""
|
@State private var tenant: String = ""
|
||||||
@State private var sendToTriage: Bool = false
|
@State private var sendToTriage: Bool = false
|
||||||
|
/// v0.13: per-task retry budget. Toggle-gated so the user can opt
|
||||||
|
/// into "send the flag" vs. "let Hermes pick its default" (the
|
||||||
|
/// release notes default to 3 — see TODO in KanbanCreateRequest).
|
||||||
|
@State private var maxRetriesEnabled: Bool = false
|
||||||
|
@State private var maxRetries: Int = 3
|
||||||
@State private var isSubmitting: Bool = false
|
@State private var isSubmitting: Bool = false
|
||||||
@State private var submitError: String?
|
@State private var submitError: String?
|
||||||
@FocusState private var titleFocused: Bool
|
@FocusState private var titleFocused: Bool
|
||||||
@@ -62,6 +73,9 @@ struct KanbanCreateSheet: View {
|
|||||||
assigneePicker
|
assigneePicker
|
||||||
workspaceField
|
workspaceField
|
||||||
priorityField
|
priorityField
|
||||||
|
if supportsKanbanDiagnostics {
|
||||||
|
maxRetriesField
|
||||||
|
}
|
||||||
skillsField
|
skillsField
|
||||||
if projectWorkspacePath == nil {
|
if projectWorkspacePath == nil {
|
||||||
tenantField
|
tenantField
|
||||||
@@ -114,13 +128,63 @@ struct KanbanCreateSheet: View {
|
|||||||
// MARK: - Fields
|
// MARK: - Fields
|
||||||
|
|
||||||
private var titleField: some View {
|
private var titleField: some View {
|
||||||
|
// v0.13 server tolerates multi-line titles. We keep the
|
||||||
|
// multi-line input rendering on for ALL versions of Hermes —
|
||||||
|
// visually a taller TextField is harmless on v0.12 — and decide
|
||||||
|
// at submit time whether to strip newlines (see `makeRequest`).
|
||||||
VStack(alignment: .leading, spacing: 4) {
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
ScarfSectionHeader("Title")
|
ScarfSectionHeader("Title")
|
||||||
ScarfTextField("What needs doing?", text: $title)
|
TextField(
|
||||||
|
"What needs doing?",
|
||||||
|
text: $title,
|
||||||
|
axis: .vertical
|
||||||
|
)
|
||||||
|
.lineLimit(1...4)
|
||||||
|
.textFieldStyle(.plain)
|
||||||
|
.scarfStyle(.body)
|
||||||
|
.padding(.horizontal, ScarfSpace.s3)
|
||||||
|
.padding(.vertical, ScarfSpace.s2)
|
||||||
|
.background(
|
||||||
|
RoundedRectangle(cornerRadius: ScarfRadius.md, style: .continuous)
|
||||||
|
.fill(ScarfColor.backgroundSecondary)
|
||||||
|
)
|
||||||
|
.overlay(
|
||||||
|
RoundedRectangle(cornerRadius: ScarfRadius.md, style: .continuous)
|
||||||
|
.strokeBorder(ScarfColor.borderStrong, lineWidth: 1)
|
||||||
|
)
|
||||||
.focused($titleFocused)
|
.focused($titleFocused)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// v0.13: per-task retry budget. Toggle gates whether `--max-retries`
|
||||||
|
/// is sent at all so the user can preserve "let Hermes pick the
|
||||||
|
/// default" semantics by leaving the toggle off.
|
||||||
|
private var maxRetriesField: some View {
|
||||||
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
ScarfSectionHeader(
|
||||||
|
"Max retries",
|
||||||
|
subtitle: "0 = no retries. Defaults to 3."
|
||||||
|
)
|
||||||
|
HStack(spacing: ScarfSpace.s3) {
|
||||||
|
Toggle("Override default", isOn: $maxRetriesEnabled)
|
||||||
|
.toggleStyle(.switch)
|
||||||
|
.labelsHidden()
|
||||||
|
Stepper(value: $maxRetries, in: 0...20) {
|
||||||
|
Text("\(maxRetries)")
|
||||||
|
.scarfStyle(.bodyEmph)
|
||||||
|
.frame(minWidth: 24, alignment: .trailing)
|
||||||
|
.foregroundStyle(
|
||||||
|
maxRetriesEnabled
|
||||||
|
? ScarfColor.foregroundPrimary
|
||||||
|
: ScarfColor.foregroundFaint
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.disabled(!maxRetriesEnabled)
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private var descriptionField: some View {
|
private var descriptionField: some View {
|
||||||
VStack(alignment: .leading, spacing: 4) {
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
ScarfSectionHeader("Description", subtitle: "Markdown supported")
|
ScarfSectionHeader("Description", subtitle: "Markdown supported")
|
||||||
@@ -307,7 +371,14 @@ struct KanbanCreateSheet: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func makeRequest() -> KanbanCreateRequest {
|
private func makeRequest() -> KanbanCreateRequest {
|
||||||
let trimmedTitle = title.trimmingCharacters(in: .whitespacesAndNewlines)
|
var trimmedTitle = title.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
|
// Pre-v0.13 hosts may truncate titles at the first `\n`. Strip
|
||||||
|
// newlines client-side when we know the connected Hermes hasn't
|
||||||
|
// shipped multi-line title support — replace with a space to
|
||||||
|
// keep the user's intent visible. v0.13+ keeps newlines verbatim.
|
||||||
|
if !supportsKanbanDiagnostics {
|
||||||
|
trimmedTitle = trimmedTitle.replacingOccurrences(of: "\n", with: " ")
|
||||||
|
}
|
||||||
let trimmedBody = bodyText.trimmingCharacters(in: .whitespacesAndNewlines)
|
let trimmedBody = bodyText.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
let trimmedAssignee = assignee.trimmingCharacters(in: .whitespacesAndNewlines)
|
let trimmedAssignee = assignee.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
let trimmedTenant = tenant.trimmingCharacters(in: .whitespacesAndNewlines)
|
let trimmedTenant = tenant.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
@@ -330,6 +401,14 @@ struct KanbanCreateSheet: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Belt-and-suspenders: the `maxRetriesField` is only rendered
|
||||||
|
// when `supportsKanbanDiagnostics` is true, but gate again here
|
||||||
|
// so a programmatic state change can't smuggle the flag onto a
|
||||||
|
// pre-v0.13 host (where the verb would error).
|
||||||
|
let resolvedMaxRetries: Int? = (supportsKanbanDiagnostics && maxRetriesEnabled)
|
||||||
|
? maxRetries
|
||||||
|
: nil
|
||||||
|
|
||||||
return KanbanCreateRequest(
|
return KanbanCreateRequest(
|
||||||
title: trimmedTitle,
|
title: trimmedTitle,
|
||||||
body: trimmedBody.isEmpty ? nil : trimmedBody,
|
body: trimmedBody.isEmpty ? nil : trimmedBody,
|
||||||
@@ -342,7 +421,8 @@ struct KanbanCreateSheet: View {
|
|||||||
idempotencyKey: nil,
|
idempotencyKey: nil,
|
||||||
maxRuntimeSeconds: nil,
|
maxRuntimeSeconds: nil,
|
||||||
createdBy: nil,
|
createdBy: nil,
|
||||||
skills: parsedSkills
|
skills: parsedSkills,
|
||||||
|
maxRetries: resolvedMaxRetries
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,16 @@ import ScarfDesign
|
|||||||
struct KanbanInspectorPane: View {
|
struct KanbanInspectorPane: View {
|
||||||
@State private var viewModel: KanbanTaskDetailViewModel
|
@State private var viewModel: KanbanTaskDetailViewModel
|
||||||
let availableAssignees: [HermesKanbanAssignee]
|
let availableAssignees: [HermesKanbanAssignee]
|
||||||
|
/// True when the connected Hermes is on v0.13+ — gates the
|
||||||
|
/// hallucination banner, max_retries chip, diagnostics block,
|
||||||
|
/// and auto-blocked reason banner. Pre-v0.13 hosts see the v2.7.5
|
||||||
|
/// inspector unchanged.
|
||||||
|
let supportsKanbanDiagnostics: Bool
|
||||||
|
/// Resolves an effective hallucination gate — the board VM owns the
|
||||||
|
/// optimistic-override merge so the banner disappears immediately on
|
||||||
|
/// Verify before the polled state confirms the new gate. Falls back
|
||||||
|
/// to the wire-level value when no override is in flight.
|
||||||
|
let effectiveHallucinationGate: (HermesKanbanTask) -> KanbanHallucinationGate?
|
||||||
let onClose: () -> Void
|
let onClose: () -> Void
|
||||||
let onClaim: () -> Void
|
let onClaim: () -> Void
|
||||||
let onComplete: () -> Void
|
let onComplete: () -> Void
|
||||||
@@ -15,6 +25,8 @@ struct KanbanInspectorPane: View {
|
|||||||
let onUnblock: () -> Void
|
let onUnblock: () -> Void
|
||||||
let onArchive: () -> Void
|
let onArchive: () -> Void
|
||||||
let onReassign: (String?) -> Void
|
let onReassign: (String?) -> Void
|
||||||
|
let onVerifyHallucination: () -> Void
|
||||||
|
let onRejectHallucination: () -> Void
|
||||||
|
|
||||||
@State private var selectedTab: DetailTab = .comments
|
@State private var selectedTab: DetailTab = .comments
|
||||||
|
|
||||||
@@ -30,16 +42,22 @@ struct KanbanInspectorPane: View {
|
|||||||
service: KanbanService,
|
service: KanbanService,
|
||||||
taskId: String,
|
taskId: String,
|
||||||
availableAssignees: [HermesKanbanAssignee] = [],
|
availableAssignees: [HermesKanbanAssignee] = [],
|
||||||
|
supportsKanbanDiagnostics: Bool = false,
|
||||||
|
effectiveHallucinationGate: @escaping (HermesKanbanTask) -> KanbanHallucinationGate? = { _ in nil },
|
||||||
onClose: @escaping () -> Void,
|
onClose: @escaping () -> Void,
|
||||||
onClaim: @escaping () -> Void,
|
onClaim: @escaping () -> Void,
|
||||||
onComplete: @escaping () -> Void,
|
onComplete: @escaping () -> Void,
|
||||||
onBlock: @escaping () -> Void,
|
onBlock: @escaping () -> Void,
|
||||||
onUnblock: @escaping () -> Void,
|
onUnblock: @escaping () -> Void,
|
||||||
onArchive: @escaping () -> Void,
|
onArchive: @escaping () -> Void,
|
||||||
onReassign: @escaping (String?) -> Void = { _ in }
|
onReassign: @escaping (String?) -> Void = { _ in },
|
||||||
|
onVerifyHallucination: @escaping () -> Void = {},
|
||||||
|
onRejectHallucination: @escaping () -> Void = {}
|
||||||
) {
|
) {
|
||||||
_viewModel = State(initialValue: KanbanTaskDetailViewModel(service: service, taskId: taskId))
|
_viewModel = State(initialValue: KanbanTaskDetailViewModel(service: service, taskId: taskId))
|
||||||
self.availableAssignees = availableAssignees
|
self.availableAssignees = availableAssignees
|
||||||
|
self.supportsKanbanDiagnostics = supportsKanbanDiagnostics
|
||||||
|
self.effectiveHallucinationGate = effectiveHallucinationGate
|
||||||
self.onClose = onClose
|
self.onClose = onClose
|
||||||
self.onClaim = onClaim
|
self.onClaim = onClaim
|
||||||
self.onComplete = onComplete
|
self.onComplete = onComplete
|
||||||
@@ -47,6 +65,8 @@ struct KanbanInspectorPane: View {
|
|||||||
self.onUnblock = onUnblock
|
self.onUnblock = onUnblock
|
||||||
self.onArchive = onArchive
|
self.onArchive = onArchive
|
||||||
self.onReassign = onReassign
|
self.onReassign = onReassign
|
||||||
|
self.onVerifyHallucination = onVerifyHallucination
|
||||||
|
self.onRejectHallucination = onRejectHallucination
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@@ -159,6 +179,16 @@ struct KanbanInspectorPane: View {
|
|||||||
ScarfBadge(workspace, kind: .neutral)
|
ScarfBadge(workspace, kind: .neutral)
|
||||||
.fixedSize()
|
.fixedSize()
|
||||||
}
|
}
|
||||||
|
// v0.13: max_retries chip. Read-only — Hermes
|
||||||
|
// has no `update --max-retries` verb. The
|
||||||
|
// `if let` guards pre-v0.13 hosts (always nil)
|
||||||
|
// and the explicit capability gate adds
|
||||||
|
// belt-and-suspenders.
|
||||||
|
if supportsKanbanDiagnostics, let maxRetries = task.maxRetries {
|
||||||
|
ScarfBadge("retries: \(maxRetries)", kind: .neutral)
|
||||||
|
.fixedSize()
|
||||||
|
.help("Max retries set at create time. Hermes has no update verb — re-create the task to change this.")
|
||||||
|
}
|
||||||
if let tenant = task.tenant, !tenant.isEmpty {
|
if let tenant = task.tenant, !tenant.isEmpty {
|
||||||
ScarfBadge(tenant, kind: .brand)
|
ScarfBadge(tenant, kind: .brand)
|
||||||
.fixedSize()
|
.fixedSize()
|
||||||
@@ -251,13 +281,18 @@ struct KanbanInspectorPane: View {
|
|||||||
// MARK: - Body
|
// MARK: - Body
|
||||||
|
|
||||||
/// Inline health banner shown above the task body when something
|
/// Inline health banner shown above the task body when something
|
||||||
/// requires user attention. Two conditions trigger today:
|
/// requires user attention. Stack vertically (multiple can apply at
|
||||||
/// 1. Task is in `ready`/`todo` with no assignee — explains that
|
/// once on a v0.13 task — e.g. unassigned + hallucination pending +
|
||||||
/// the dispatcher silently skips unassigned tasks.
|
/// last-run-blocked).
|
||||||
/// 2. The most recent run ended in a non-success outcome
|
/// Order top-to-bottom:
|
||||||
/// (`stale_lock`/`crashed`/`gave_up`/`timed_out`/`spawn_failed`/
|
/// 1. **Hallucination gate (v0.13+)** — pending worker-created card.
|
||||||
/// `reclaimed`/`failed`) — surfaces the error so the user
|
/// User must verify or reject before any other action makes sense.
|
||||||
/// doesn't have to dig into the Runs tab to discover it.
|
/// 2. **Auto-blocked reason (v0.13+)** — server-supplied reason
|
||||||
|
/// overrides the generic "Last run: blocked" banner.
|
||||||
|
/// 3. Task is in `ready`/`todo` with no assignee — explains that the
|
||||||
|
/// dispatcher silently skips unassigned tasks.
|
||||||
|
/// 4. The most recent run ended in a non-success outcome — surfaces
|
||||||
|
/// the error so the user doesn't have to dig into the Runs tab.
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
private func healthBanner(for task: HermesKanbanTask) -> some View {
|
private func healthBanner(for task: HermesKanbanTask) -> some View {
|
||||||
let status = KanbanStatus.from(task.status)
|
let status = KanbanStatus.from(task.status)
|
||||||
@@ -292,6 +327,38 @@ struct KanbanInspectorPane: View {
|
|||||||
// Also suppress for `done` (terminal success).
|
// Also suppress for `done` (terminal success).
|
||||||
let suppressFailureBanner = (status == .running) || (status == .done)
|
let suppressFailureBanner = (status == .running) || (status == .done)
|
||||||
|
|
||||||
|
// v0.13: hallucination-gate state. Read through the VM's
|
||||||
|
// optimistic-aware accessor so a Verify click takes effect
|
||||||
|
// before the polled state confirms. Belt-and-suspenders gate
|
||||||
|
// on capability flag.
|
||||||
|
let hallucination: KanbanHallucinationGate? = supportsKanbanDiagnostics
|
||||||
|
? effectiveHallucinationGate(task)
|
||||||
|
: nil
|
||||||
|
// v0.13: structured auto-blocked reason. Renders the server's
|
||||||
|
// string verbatim; takes precedence over the generic "Last run:
|
||||||
|
// blocked" banner.
|
||||||
|
let autoBlockedReason: String? = (supportsKanbanDiagnostics
|
||||||
|
&& status == .blocked
|
||||||
|
&& (task.autoBlockedReason?.isEmpty == false))
|
||||||
|
? task.autoBlockedReason
|
||||||
|
: nil
|
||||||
|
// Suppress the generic last-run banner when the more specific
|
||||||
|
// server-side reason supersedes it.
|
||||||
|
let suppressGenericFailure = autoBlockedReason != nil
|
||||||
|
|
||||||
|
VStack(alignment: .leading, spacing: ScarfSpace.s2) {
|
||||||
|
if hallucination == .pending {
|
||||||
|
hallucinationBanner
|
||||||
|
}
|
||||||
|
if let reason = autoBlockedReason {
|
||||||
|
bannerRow(
|
||||||
|
icon: "exclamationmark.octagon.fill",
|
||||||
|
tint: ScarfColor.danger,
|
||||||
|
title: "Auto-blocked",
|
||||||
|
// Verbatim — Hermes-side message is the source of truth.
|
||||||
|
message: reason
|
||||||
|
)
|
||||||
|
}
|
||||||
if needsAssignee {
|
if needsAssignee {
|
||||||
bannerRow(
|
bannerRow(
|
||||||
icon: "exclamationmark.triangle.fill",
|
icon: "exclamationmark.triangle.fill",
|
||||||
@@ -299,7 +366,9 @@ struct KanbanInspectorPane: View {
|
|||||||
title: "Won't run automatically",
|
title: "Won't run automatically",
|
||||||
message: "Unassigned tasks are silently skipped by Hermes's dispatcher. Add an assignee to get this scheduled."
|
message: "Unassigned tasks are silently skipped by Hermes's dispatcher. Add an assignee to get this scheduled."
|
||||||
)
|
)
|
||||||
} else if hadFailedEndedRun, let lastEndedRun, !suppressFailureBanner {
|
}
|
||||||
|
if hadFailedEndedRun, let lastEndedRun,
|
||||||
|
!suppressFailureBanner, !suppressGenericFailure {
|
||||||
let label = (lastEndedRun.outcome ?? lastEndedRun.status).lowercased()
|
let label = (lastEndedRun.outcome ?? lastEndedRun.status).lowercased()
|
||||||
let detail = lastEndedRun.error ?? lastEndedRun.summary ?? "no details"
|
let detail = lastEndedRun.error ?? lastEndedRun.summary ?? "no details"
|
||||||
bannerRow(
|
bannerRow(
|
||||||
@@ -309,6 +378,84 @@ struct KanbanInspectorPane: View {
|
|||||||
message: detail
|
message: detail
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
// v0.13: cross-run diagnostics on the task header.
|
||||||
|
if supportsKanbanDiagnostics, !task.diagnostics.isEmpty {
|
||||||
|
diagnosticsBlock(task.diagnostics)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// v0.13 hallucination-gate banner — Verify / Reject affordances for
|
||||||
|
/// worker-created cards waiting on user verification.
|
||||||
|
private var hallucinationBanner: some View {
|
||||||
|
HStack(alignment: .top, spacing: ScarfSpace.s2) {
|
||||||
|
Image(systemName: "questionmark.diamond.fill")
|
||||||
|
.foregroundStyle(ScarfColor.warning)
|
||||||
|
.font(.system(size: 13, weight: .semibold))
|
||||||
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
Text("Created by a worker — verify before running")
|
||||||
|
.scarfStyle(.captionStrong)
|
||||||
|
.foregroundStyle(ScarfColor.foregroundPrimary)
|
||||||
|
Text("A worker claimed it created this card; Hermes hasn't confirmed the underlying work exists. Verify the card matches a real follow-up, or reject if it's a hallucinated reference.")
|
||||||
|
.scarfStyle(.caption)
|
||||||
|
.foregroundStyle(ScarfColor.foregroundMuted)
|
||||||
|
HStack(spacing: ScarfSpace.s2) {
|
||||||
|
Button("Verify", action: onVerifyHallucination)
|
||||||
|
.buttonStyle(ScarfPrimaryButton())
|
||||||
|
Button("Reject", action: onRejectHallucination)
|
||||||
|
.buttonStyle(ScarfDestructiveButton())
|
||||||
|
}
|
||||||
|
.padding(.top, 2)
|
||||||
|
}
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
}
|
||||||
|
.padding(ScarfSpace.s2)
|
||||||
|
.background(
|
||||||
|
RoundedRectangle(cornerRadius: ScarfRadius.md, style: .continuous)
|
||||||
|
.fill(ScarfColor.warning.opacity(0.10))
|
||||||
|
)
|
||||||
|
.overlay(
|
||||||
|
RoundedRectangle(cornerRadius: ScarfRadius.md, style: .continuous)
|
||||||
|
.strokeBorder(ScarfColor.warning.opacity(0.4), lineWidth: 1)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// v0.13 diagnostics block — renders a list of distress signals.
|
||||||
|
/// Used both at the task-header level (cross-run signals) and per
|
||||||
|
/// run on the Runs tab (in-flight signals). Wraps in a horizontal
|
||||||
|
/// scroll so a long diag list doesn't blow out inspector width.
|
||||||
|
private func diagnosticsBlock(_ diags: [HermesKanbanDiagnostic]) -> some View {
|
||||||
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
Text("Diagnostics")
|
||||||
|
.scarfStyle(.captionUppercase)
|
||||||
|
.foregroundStyle(ScarfColor.foregroundFaint)
|
||||||
|
ScrollView(.horizontal, showsIndicators: false) {
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
ForEach(diags) { diag in
|
||||||
|
diagnosticBadge(diag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(.top, 4)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private func diagnosticBadge(_ diag: HermesKanbanDiagnostic) -> some View {
|
||||||
|
let kind = KanbanDiagnosticKind.from(diag.kind)
|
||||||
|
let badgeKind: ScarfBadgeKind = {
|
||||||
|
switch kind.severity {
|
||||||
|
case .danger: return .danger
|
||||||
|
case .warning: return .warning
|
||||||
|
case .neutral: return .neutral
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
// Render the raw kind string — view code stays in sync with
|
||||||
|
// whatever future kinds Hermes ships. The typed mirror picks
|
||||||
|
// the badge tint and tooltip glyph; the verbatim wire string
|
||||||
|
// is the user-facing label.
|
||||||
|
ScarfBadge(diag.kind, kind: badgeKind)
|
||||||
|
.help(diag.message ?? diag.kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func bannerRow(
|
private func bannerRow(
|
||||||
@@ -562,6 +709,9 @@ struct KanbanInspectorPane: View {
|
|||||||
private func runRow(_ run: HermesKanbanRun) -> some View {
|
private func runRow(_ run: HermesKanbanRun) -> some View {
|
||||||
VStack(alignment: .leading, spacing: 2) {
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
HStack(spacing: ScarfSpace.s2) {
|
HStack(spacing: ScarfSpace.s2) {
|
||||||
|
// Render the wire-side outcome / status string verbatim so
|
||||||
|
// v0.13's richer outcome strings ("zombied — reclaimed by
|
||||||
|
// reaper", etc.) surface unchanged.
|
||||||
ScarfBadge(run.outcome ?? run.status, kind: outcomeKind(run.outcome ?? run.status))
|
ScarfBadge(run.outcome ?? run.status, kind: outcomeKind(run.outcome ?? run.status))
|
||||||
if let profile = run.profile {
|
if let profile = run.profile {
|
||||||
Text(profile)
|
Text(profile)
|
||||||
@@ -585,6 +735,12 @@ struct KanbanInspectorPane: View {
|
|||||||
.foregroundStyle(ScarfColor.danger)
|
.foregroundStyle(ScarfColor.danger)
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
}
|
}
|
||||||
|
// v0.13: per-run diagnostics. Gated on capability so a future
|
||||||
|
// server-side change can't accidentally surface partial UX
|
||||||
|
// on a pre-v0.13 host.
|
||||||
|
if supportsKanbanDiagnostics, !run.diagnostics.isEmpty {
|
||||||
|
diagnosticsBlock(run.diagnostics)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.padding(ScarfSpace.s2)
|
.padding(ScarfSpace.s2)
|
||||||
.background(
|
.background(
|
||||||
@@ -619,6 +775,14 @@ struct KanbanInspectorPane: View {
|
|||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
private var primaryAction: some View {
|
private var primaryAction: some View {
|
||||||
if let task = viewModel.detail?.task {
|
if let task = viewModel.detail?.task {
|
||||||
|
// v0.13: when the hallucination gate is pending, suppress the
|
||||||
|
// primary action — the banner provides Verify / Reject as the
|
||||||
|
// gate. Showing "Start" alongside the banner would let the
|
||||||
|
// user dispatch a card Hermes hasn't confirmed exists.
|
||||||
|
if supportsKanbanDiagnostics,
|
||||||
|
effectiveHallucinationGate(task) == .pending {
|
||||||
|
EmptyView()
|
||||||
|
} else {
|
||||||
switch KanbanStatus.from(task.status) {
|
switch KanbanStatus.from(task.status) {
|
||||||
case .ready, .todo:
|
case .ready, .todo:
|
||||||
Button("Start", action: onClaim)
|
Button("Start", action: onClaim)
|
||||||
@@ -639,6 +803,7 @@ struct KanbanInspectorPane: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
private var secondaryActions: some View {
|
private var secondaryActions: some View {
|
||||||
|
|||||||
Reference in New Issue
Block a user