-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCockpitData.swift
More file actions
461 lines (433 loc) · 14.7 KB
/
CockpitData.swift
File metadata and controls
461 lines (433 loc) · 14.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
import Foundation
enum CockpitWorkerAction: String, CaseIterable, Codable, Sendable, Equatable, Identifiable {
case start
case pause
case resume
case cancel
var id: String { self.rawValue }
var title: String {
switch self {
case .start: "Start"
case .pause: "Pause"
case .resume: "Resume"
case .cancel: "Cancel"
}
}
var systemImage: String {
switch self {
case .start: "play.fill"
case .pause: "pause.fill"
case .resume: "playpause.fill"
case .cancel: "xmark.circle.fill"
}
}
}
enum CockpitGatewayMode: String, Codable, Sendable, Equatable {
case local
case remote
case unconfigured
}
enum CockpitGatewayConnectionState: String, Codable, Sendable, Equatable {
case ready
case connecting
case unavailable
}
struct CockpitGatewayStatus: Codable, Sendable, Equatable {
let mode: CockpitGatewayMode
let state: CockpitGatewayConnectionState
let endpointLabel: String?
let detail: String?
var isRemote: Bool {
self.mode == .remote
}
var headline: String {
switch (self.mode, self.state) {
case (.remote, .ready):
"Remote workers active"
case (.remote, .connecting):
"Connecting to remote gateway"
case (.remote, .unavailable):
"Remote gateway unavailable"
case (.local, .ready):
"Local gateway active"
case (.local, .connecting):
"Connecting to local gateway"
case (.local, .unavailable):
"Local gateway unavailable"
case (.unconfigured, _):
"Gateway not configured"
}
}
var detailText: String {
if let detail, !detail.isEmpty {
return detail
}
switch (self.mode, self.state) {
case (.remote, .ready):
if let endpointLabel, !endpointLabel.isEmpty {
return "Workers are running through \(endpointLabel). This keeps execution and RAM pressure off your Mac."
}
return "Workers are running off this Mac through the remote gateway."
case (.remote, .connecting):
return "Cockpit is waiting for the remote gateway or tunnel so worker execution can stay off-machine."
case (.remote, .unavailable):
return "Reconnect the remote gateway to keep worker execution off your Mac."
case (.local, .ready):
return "Workers are running on this Mac. Switch to Remote mode to offload the runtime and reduce RAM usage."
case (.local, .connecting):
return "Cockpit is waiting for the local gateway."
case (.local, .unavailable):
return "Start or reconnect the local gateway before running workers."
case (.unconfigured, _):
return "Configure a local or remote gateway before using Cockpit."
}
}
}
struct CockpitTotals: Codable, Sendable {
let tasks: Int
let workers: Int
let reviews: Int
let decisions: Int
let contextSnapshots: Int
let runs: Int
}
struct CockpitTaskSummary: Codable, Identifiable, Sendable {
let id: String
let title: String
let status: String
let priority: String?
let repoRoot: String?
let updatedAt: String
}
struct CockpitWorkerSummary: Codable, Identifiable, Sendable {
let id: String
let taskId: String
let name: String
let status: String
let lane: String
let repoRoot: String?
let worktreePath: String?
let branch: String?
let backendId: String?
let activeRunId: String?
let updatedAt: String
}
struct CockpitReviewSummary: Codable, Identifiable, Sendable {
let id: String
let taskId: String
let workerId: String?
let title: String
let status: String
let summary: String?
let updatedAt: String
}
struct CockpitRunSummary: Codable, Identifiable, Sendable {
let id: String
let taskId: String?
let workerId: String?
let status: String
let summary: String?
let backendId: String?
let threadId: String?
let startedAt: String?
let finishedAt: String?
let terminationReason: String?
let updatedAt: String
}
struct CockpitLaneSummary: Codable, Identifiable, Sendable {
let taskId: String
let taskTitle: String
let workerId: String
let workerName: String
let lane: String
let status: String
let repoRoot: String?
let worktreePath: String?
let branch: String?
let objective: String?
let backendId: String?
let activeRunId: String?
let updatedAt: String
let latestRun: CockpitRunSummary?
let pendingReview: CockpitReviewSummary?
var id: String { self.workerId }
var availableWorkerActions: [CockpitWorkerAction] {
switch self.status {
case "queued", "failed", "cancelled", "awaiting_review":
[.start]
case "running":
[.pause, .cancel]
case "awaiting_approval":
[.cancel]
case "paused":
[.resume, .cancel]
case "completed":
[]
default:
[]
}
}
}
struct CockpitTerminalLane: Codable, Identifiable, Sendable {
let id: String
let repoRoot: String
let worktreePath: String?
let backendProfile: String?
let workerId: String?
let status: String
let title: String?
let createdAt: String
let updatedAt: String
}
struct CockpitWorkerLogs: Codable, Sendable {
let workerId: String
let latestRun: CockpitRunSummary?
let stdoutTail: String
let stderrTail: String
}
struct CockpitSupervisorTickResult: Codable, Sendable {
let action: String
let reason: String?
let task: CockpitTaskSummary?
let worker: CockpitWorkerSummary?
let run: CockpitRunSummary?
}
struct CockpitWorkspaceSummary: Codable, Sendable {
let storePath: String
let generatedAt: String
let totals: CockpitTotals
let taskStatusCounts: [String: Int]
let workerStatusCounts: [String: Int]
let reviewStatusCounts: [String: Int]
let recentTasks: [CockpitTaskSummary]
let recentWorkers: [CockpitWorkerSummary]
let pendingReviews: [CockpitReviewSummary]
let recentRuns: [CockpitRunSummary]
let activeLanes: [CockpitLaneSummary]
let terminalLanes: [CockpitTerminalLane]
}
extension CockpitGatewayStatus {
static let previewLocal = CockpitGatewayStatus(
mode: .local,
state: .ready,
endpointLabel: "127.0.0.1:18789",
detail: nil)
static func from(endpointState: GatewayEndpointState) -> CockpitGatewayStatus {
switch endpointState {
case let .ready(mode, url, _, _):
return CockpitGatewayStatus(
mode: Self.mode(from: mode),
state: .ready,
endpointLabel: Self.endpointLabel(from: url),
detail: nil)
case let .connecting(mode, detail):
return CockpitGatewayStatus(
mode: Self.mode(from: mode),
state: .connecting,
endpointLabel: nil,
detail: detail)
case let .unavailable(mode, reason):
return CockpitGatewayStatus(
mode: Self.mode(from: mode),
state: .unavailable,
endpointLabel: nil,
detail: reason)
}
}
private static func mode(from mode: AppState.ConnectionMode) -> CockpitGatewayMode {
switch mode {
case .local:
.local
case .remote:
.remote
case .unconfigured:
.unconfigured
}
}
private static func endpointLabel(from url: URL) -> String {
let host = url.host ?? url.absoluteString
if let port = url.port {
return "\(host):\(port)"
}
return host
}
}
extension CockpitWorkspaceSummary {
static let preview = CockpitWorkspaceSummary(
storePath: "/Users/tessaro/.openclaw/code/cockpit.json",
generatedAt: "2026-03-19T13:00:00.000Z",
totals: CockpitTotals(
tasks: 3,
workers: 4,
reviews: 2,
decisions: 5,
contextSnapshots: 3,
runs: 7),
taskStatusCounts: [
"queued": 0,
"planning": 1,
"in_progress": 2,
"review": 0,
"blocked": 0,
"done": 0,
"cancelled": 0,
],
workerStatusCounts: [
"queued": 0,
"running": 2,
"awaiting_review": 1,
"awaiting_approval": 0,
"paused": 1,
"completed": 0,
"failed": 0,
"cancelled": 0,
],
reviewStatusCounts: [
"pending": 2,
"approved": 0,
"changes_requested": 0,
"dismissed": 0,
],
recentTasks: [
CockpitTaskSummary(
id: "task_shell",
title: "Ship the cockpit shell",
status: "in_progress",
priority: "high",
repoRoot: "/Users/tessaro/openclaw",
updatedAt: "2026-03-19T12:58:00.000Z"),
CockpitTaskSummary(
id: "task_review",
title: "Tighten review lane",
status: "planning",
priority: "normal",
repoRoot: "/Users/tessaro/openclaw",
updatedAt: "2026-03-19T12:54:00.000Z"),
],
recentWorkers: [
CockpitWorkerSummary(
id: "worker_shell",
taskId: "task_shell",
name: "shell-lane",
status: "running",
lane: "worker",
repoRoot: "/Users/tessaro/openclaw",
worktreePath: "/Users/tessaro/openclaw/.worktrees/code/shell-lane",
branch: "code/task_shell/shell-lane",
backendId: "codex-cli",
activeRunId: "run_shell",
updatedAt: "2026-03-19T12:58:00.000Z"),
],
pendingReviews: [
CockpitReviewSummary(
id: "review_shell",
taskId: "task_shell",
workerId: "worker_shell",
title: "Review cockpit shell",
status: "pending",
summary: "Ready for diff and smoke test review.",
updatedAt: "2026-03-19T12:59:00.000Z"),
],
recentRuns: [
CockpitRunSummary(
id: "run_shell",
taskId: "task_shell",
workerId: "worker_shell",
status: "running",
summary: "Rendering native cockpit panels",
backendId: "codex-cli",
threadId: "thread_shell",
startedAt: "2026-03-19T12:57:00.000Z",
finishedAt: nil,
terminationReason: nil,
updatedAt: "2026-03-19T12:58:00.000Z"),
],
activeLanes: [
CockpitLaneSummary(
taskId: "task_shell",
taskTitle: "Ship the cockpit shell",
workerId: "worker_shell",
workerName: "shell-lane",
lane: "worker",
status: "running",
repoRoot: "/Users/tessaro/openclaw",
worktreePath: "/Users/tessaro/openclaw/.worktrees/code/shell-lane",
branch: "code/task_shell/shell-lane",
objective: "Render native cockpit panels and menu entry.",
backendId: "codex-cli",
activeRunId: "run_shell",
updatedAt: "2026-03-19T12:58:00.000Z",
latestRun: CockpitRunSummary(
id: "run_shell",
taskId: "task_shell",
workerId: "worker_shell",
status: "running",
summary: "Rendering native cockpit panels",
backendId: "codex-cli",
threadId: "thread_shell",
startedAt: "2026-03-19T12:57:00.000Z",
finishedAt: nil,
terminationReason: nil,
updatedAt: "2026-03-19T12:58:00.000Z"),
pendingReview: CockpitReviewSummary(
id: "review_shell",
taskId: "task_shell",
workerId: "worker_shell",
title: "Review cockpit shell",
status: "pending",
summary: "Ready for diff and smoke test review.",
updatedAt: "2026-03-19T12:59:00.000Z")),
CockpitLaneSummary(
taskId: "task_review",
taskTitle: "Tighten review lane",
workerId: "worker_review",
workerName: "review-lane",
lane: "review",
status: "paused",
repoRoot: "/Users/tessaro/openclaw",
worktreePath: "/Users/tessaro/openclaw/.worktrees/code/review-lane",
branch: "code/task_review/review-lane",
objective: "Validate recent diffs and smoke tests.",
backendId: "codex-cli",
activeRunId: nil,
updatedAt: "2026-03-19T12:52:00.000Z",
latestRun: CockpitRunSummary(
id: "run_review",
taskId: "task_review",
workerId: "worker_review",
status: "cancelled",
summary: "Paused for operator guidance",
backendId: "codex-cli",
threadId: "thread_review",
startedAt: "2026-03-19T12:48:00.000Z",
finishedAt: "2026-03-19T12:50:00.000Z",
terminationReason: "paused",
updatedAt: "2026-03-19T12:50:00.000Z"),
pendingReview: nil),
],
terminalLanes: [
CockpitTerminalLane(
id: "tl_shell",
repoRoot: "/Users/tessaro/openclaw",
worktreePath: "/Users/tessaro/openclaw/.worktrees/code/shell-lane",
backendProfile: "codex-cli",
workerId: "worker_shell",
status: "open",
title: "shell-lane",
createdAt: "2026-03-19T12:56:00.000Z",
updatedAt: "2026-03-19T12:58:00.000Z"),
])
}
extension CockpitWorkerLogs {
static func preview(workerId: String) -> CockpitWorkerLogs {
CockpitWorkerLogs(
workerId: workerId,
latestRun: CockpitWorkspaceSummary.preview.activeLanes.first(where: { $0.workerId == workerId })?.latestRun,
stdoutTail: """
> codex worker \(workerId)
Rendering cockpit controls…
Worker state refreshed.
""",
stderrTail: "")
}
}