chore: single-source working state from agent events

This commit is contained in:
Peter Steinberger
2025-12-09 01:17:01 +01:00
parent 5b5a79b90b
commit f965e1c3ff
5 changed files with 28 additions and 73 deletions

View File

@@ -14,12 +14,6 @@ actor AgentRPC {
let reason: String?
}
struct JobStateEvent: Codable {
let id: String
let state: String
let durationMs: Double?
}
static let heartbeatNotification = Notification.Name("clawdis.rpc.heartbeat")
private var process: Process?
@@ -202,8 +196,6 @@ actor AgentRPC {
}
continue
}
if self.parseJobStateEvent(from: line) != nil { continue }
if let waiter = waiters.first {
self.waiters.removeFirst()
waiter.resume(returning: line)
@@ -229,24 +221,6 @@ actor AgentRPC {
return try? decoder.decode(HeartbeatEvent.self, from: payloadData)
}
private func parseJobStateEvent(from line: String) -> JobStateEvent? {
guard let data = line.data(using: .utf8) else { return nil }
guard
let obj = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
let type = obj["type"] as? String,
type == "event",
let evt = obj["event"] as? String,
evt == "job-state",
let payload = obj["payload"] as? [String: Any]
else {
return nil
}
let decoder = JSONDecoder()
guard let payloadData = try? JSONSerialization.data(withJSONObject: payload) else { return nil }
return try? decoder.decode(JobStateEvent.self, from: payloadData)
}
private func nextLine() async throws -> String {
try await withCheckedThrowingContinuation { (cont: CheckedContinuation<String, Error>) in
self.waiters.append(cont)