oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1#if DEBUG
2import SwiftUI
3#if os(macOS)
4import AppKit
5#endif
6
7/// Offline visual fixture. Only compiled into Debug builds; never touches a
8/// saved account, keychain or network. Launch with EQUIPO_STOPPED_FIXTURE.
9public struct StoppedWorkFixture: View {
10 @State private var session: EquipoSession
11 public init() { session = Self.makeSession() }
12 public static func makeSession() -> EquipoSession {
13 let transport = StoppedFixtureTransport()
14 var account = DeviceAccount.new(origin: transport.origin, label: "Fixture")
15 account.credential = DeviceCredential(id: "fixture", token: "fixture", audience: "equipo.person.v1", instanceId: "fixture", expiresAt: .distantFuture)
16 return EquipoSession(account: account, accounts: DeviceAccounts(store: MemorySecretStore()), transport: transport)
17 }
18 public var body: some View {
19 NavigationStack {
20 TaskScreen(session: session, taskID: "fixture")
21 .navigationTitle(EquipoStrings.text("task.title"))
22 }
23 .modifier(SettingsSheetPresenter(session: session))
24 .task {
25 await session.refresh()
26 #if os(macOS)
27 // Capture this app's own native window when desktop recording is
28 // unavailable. No other app or screen is read.
29 if let path = ProcessInfo.processInfo.environment["EQUIPO_FIXTURE_CAPTURE"] {
30 try? await Task.sleep(for: .seconds(2))
31 if let window = NSApp.windows.first(where: { $0.isVisible && !$0.isSheet }), let view = window.contentView {
32 window.setContentSize(NSSize(width: 800, height: 850))
33 view.layoutSubtreeIfNeeded()
34 window.displayIfNeeded()
35 if let bitmap = view.bitmapImageRepForCachingDisplay(in: view.bounds) {
36 view.cacheDisplay(in: view.bounds, to: bitmap)
37 if let data = bitmap.representation(using: .png, properties: [:]) {
38 _ = FileManager.default.createFile(atPath: path, contents: data)
39 }
40 }
41 }
42 }
43 #endif
44 }
45 }
46}
47
48private struct StoppedFixtureTransport: EquipoTransport {
49 let origin = URL(string: "https://fixture.invalid")!
50 private var resume: Bool { ProcessInfo.processInfo.environment["EQUIPO_STOPPED_FIXTURE"] == "conversation-resume" }
51 private var paused: Bool { ProcessInfo.processInfo.environment["EQUIPO_STOPPED_FIXTURE"] == "paused" }
52 func send(_ request: APIRequest) async throws -> APIResponse {
53 let data: Data
54 switch request.path {
55 case "/snapshot":
56 data = try JSONSerialization.data(withJSONObject: ["me": ["id": "fixture", "address": "paul@example.com", "role": "owner", "team_id": "fixture", "team_name": "Oficina", "revision": 1], "cursor": 1, "tasks": [task], "messages": messages, "turns": [], "cards": cards, "projects": []])
57 case "/needs-you" where paused: data = Data(#"{"items":[]}"#.utf8)
58 case "/tasks", "/needs-you": data = try JSONSerialization.data(withJSONObject: ["items": [task]])
59 case "/tasks/fixture": data = try JSONSerialization.data(withJSONObject: task)
60 case "/steps/failed/log": data = try JSONSerialization.data(withJSONObject: ["step_id": "failed", "attempt": 1, "tail": "git push amadan equipo/needs-badge-sign-out\nremote: HTTP 429 Too Many Requests\nfatal: the remote end hung up unexpectedly\nexit status 128"])
61 case "/connections":
62 try await Task.sleep(for: .milliseconds(1500))
63 data = Data(#"{"items":[{"id":"cn_fixture","runner_id":"runner","local_id":"codex-1","provider":"codex","spend":{"unknown":true,"pause_revision":7}}]}"#.utf8)
64 case "/tasks/fixture/retry": return APIResponse(status: 500, data: Data())
65 case "/projects": data = Data(#"{"items":[]}"#.utf8)
66 default: data = Data("{}".utf8)
67 }
68 return APIResponse(status: 200, data: data)
69 }
70 func lines(_ request: APIRequest) async throws -> AsyncThrowingStream<String, Error> { AsyncThrowingStream { $0.finish() } }
71 private var cards: [[String: Any]] {
72 guard ProcessInfo.processInfo.environment["EQUIPO_STOPPED_FIXTURE"]?.hasPrefix("conversation-") == true else { return [] }
73 return [["id": "report", "revision": 1, "kind": "task", "state": "open", "turn_id": "", "project_id": "project", "name": "", "question": "", "choice": "", "task_id": "fixture", "created_at": "2026-11-25T10:42:00Z", "updated_at": "2026-11-25T10:42:00Z"]]
74 }
75 private var messages: [[String: Any]] {
76 guard !cards.isEmpty else { return [] }
77 return [["id": "followup", "revision": 1, "role": "person", "text": "Please keep the current branch.", "turn_id": "", "created_at": "2026-11-25T10:43:00Z"]]
78 }
79 private var task: [String: Any] {
80 let calendar = Calendar.current
81 let today = calendar.startOfDay(for: Date())
82 let stop = calendar.date(byAdding: .minute, value: 10 * 60 + 42, to: today)!
83 let resetToday = calendar.date(byAdding: .hour, value: 21, to: today)!
84 let reset = resetToday > Date() ? resetToday : calendar.date(byAdding: .day, value: 1, to: resetToday)!
85 let iso = ISO8601DateFormatter()
86 var step: [String: Any] = ["id": "failed", "specialist": "engineering", "state": "failed", "reason": "push_failed", "terminated": true, "headline": "Push the branch", "summary": "", "verdict": "", "review_label": "", "checks": "", "gate": "", "finished_at": iso.string(from: stop)]
87 if paused {
88 step["state"] = "queued"; step["reason"] = ""; step["headline"] = ""; step.removeValue(forKey: "finished_at")
89 step["hold"] = ["reason": "headroom", "provider": "claude", "connection": "claude-1", "step_revision": 4, "resets_at": iso.string(from: reset)]
90 step["paused"] = ["since": iso.string(from: stop), "used_percent": 100, "run_now": ["connection": "codex-1", "name": "Codex", "provider": "codex", "billing": "subscription"]]
91 }
92 if resume {
93 step["state"] = "queued"; step["reason"] = ""; step["runner_id"] = "runner"
94 step["hold"] = ["reason": "spend_unknown", "provider": "codex", "connection": "codex-1", "step_revision": 4]
95 }
96 return ["id": "fixture", "revision": 1, "project_id": "project", "project": "Equipo", "title": paused ? "Show the stop reason on the native task view" : "Fix the Needs you badge after sign-out", "brief": "", "stage": "in_progress", "branch": "equipo/needs-badge-sign-out", "url": "", "candidate_sha": "3f9c2a1", "checks": "", "checks_reason": "", "verdict": "", "review_label": "", "needs_you": resume ? "held" : paused ? "" : "retry", "creator": "paul@example.com", "created_at": iso.string(from: stop), "updated_at": iso.string(from: stop), "steps": [step]]
97 }
98}
99#endif
100