Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

feat(spaces-macos): run conversation timeline in the SwiftUI app (CUA-1413) (#5028)

Francesco Bonacci75a81cf81629
diff --git a/apps/cua-spaces-macos/README.md b/apps/cua-spaces-macos/README.md
index 8ad8801484..36a74794c7 100644
--- a/apps/cua-spaces-macos/README.md
+++ b/apps/cua-spaces-macos/README.md
@@ -60,7 +60,7 @@ UI tests (XCUITest) need Xcode: `xcodegen generate` (project.yml), then
Environment (debug builds only; release builds ignore every `CUA_SPACES_*` hook):
`CUA_SPACES_FIXTURES=1` runs on fixtures (no daemon, no Space, an in-memory login item whose status `CUA_SPACES_LOGIN_ITEM` sets: `enabled`, `notRegistered`, `requiresApproval`, `notFound`);
`CUA_SPACES_START_VIEW` opens `new-space`, `keyvault`, `approval`, `settings-devices`, `settings-about`, `device-approval` (with `CUA_SPACES_APPROVE_CODE`), `device-enroll`, `device-enroll-code`,
-`onboarding`, `stream` (the Space detail at its Stream section), `window-pip` (the same, with the first window popped out), `teleport-picker` (the Space's teleport picker; set `CUA_TELEPORT_APP_ROOTS` to fixture apps for images) or a notch state (`notch-open`, which springs
+`onboarding`, `stream` (the Space detail at its Stream section), `window-pip` (the same, with the first window popped out), `teleport-picker` (the Space's teleport picker; set `CUA_TELEPORT_APP_ROOTS` to fixture apps for images), `run-timeline` (an agent run's conversation from the Space's Agents section; fixtures give `local:aurora` two runs) or a notch state (`notch-open`, which springs
open 1.5 s after launch, `notch-hover`, `notch-permission`,
`notch-drag-target`, `notch-drop`); `CUA_SPACES_SELECT`
selects a Space; `CUA_SPACES_CREATE=<image>[,<name>]` creates one on this
diff --git a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/AppEnvironment.swift b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/AppEnvironment.swift
index 78ff3a893d..692b2d6bc1 100644
--- a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/AppEnvironment.swift
+++ b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/AppEnvironment.swift
@@ -69,7 +69,15 @@ public enum AppEnvironment {
// until then the window shows the launch, on stand-ins that wait
// for them. Nothing here reads the keychain or waits on the daemon.
let gate = LiveGate<LiveServices>()
- let backend: SpacesBackend = fixtures ? FixtureSpacesBackend(rows: FixtureSpacesBackend.rows(environment: env)) : PendingSpacesBackend(gate: gate)
+ let backend: SpacesBackend
+ if fixtures {
+ let fixture = FixtureSpacesBackend(rows: FixtureSpacesBackend.rows(environment: env))
+ fixture.fixtureRuns["local:aurora"] = FixtureSpacesBackend.sampleRuns
+ fixture.fixtureEvents = FixtureSpacesBackend.sampleEvents
+ backend = fixture
+ } else {
+ backend = PendingSpacesBackend(gate: gate)
+ }
let keyvault = KeyvaultModel(client: fixtures ? nil : KeyvaultClient(cuaHome: nil))
if !fixtures {
// Icons: caches survive restarts; fixtures never resolve apps or
diff --git a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/AppStartup.swift b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/AppStartup.swift
index 0497cf742c..a7a2f6f7e7 100644
--- a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/AppStartup.swift
+++ b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/AppStartup.swift
@@ -640,6 +640,9 @@ public final class PendingSpacesBackend: SpacesBackend, AgentsToolRunning, Cloud
try await b().sendFiles(id: id, paths: paths)
}
public func agentRuns(id: String) async throws -> [AppSpaceAgentRun] { try await b().agentRuns(id: id) }
+ public func agentEvents(id: String, runId: String, cursor: UInt64) async throws -> String {
+ try await b().agentEvents(id: id, runId: runId, cursor: cursor)
+ }
public func thumbnail(id: String, maxAgeMs: UInt64?) async -> SpaceThumbnailData? {
await b().thumbnail(id: id, maxAgeMs: maxAgeMs)
}
diff --git a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/FixtureAgentRuns.swift b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/FixtureAgentRuns.swift
new file mode 100644
index 0000000000..fadcd63fbc
--- /dev/null
+++ b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/FixtureAgentRuns.swift
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: FSL-1.1-MIT
+// Copyright (c) 2026 Cua AI, Inc.
+
+import Foundation
+
+/// The fixture Space's coding-agent runs and what they wrote
+/// (`CUA_SPACES_FIXTURES=1`): the Agents section and a run's conversation.
+extension FixtureSpacesBackend {
+ /// `agent_list` records for `local:aurora`.
+ public static let sampleRuns = [
+ #"{"run_id":"run-ada-7","harness":"claude-code","status":"running","phase":"tool","reason":"a turn is running","turn":2,"accepts_message":false,"meta":{"run_id":"run-ada-7","harness":"claude-code","prompt":"Fix the flaky login test in the web app","cwd":"/home/cua/app","created_at":1791800000.0}}"#,
+ #"{"run_id":"run-codex-2","harness":"openai-codex","status":"failed","phase":"failed","reason":"auth failed","turn":1,"accepts_message":false,"meta":{"run_id":"run-codex-2","harness":"openai-codex","prompt":"Triage the open issues","cwd":"/home/cua","created_at":1791790000.0}}"#,
+ ]
+
+ /// `agent_events` pages per run id: every event, caught up.
+ public static let sampleEvents: [String: String] = [
+ "run-ada-7": page(runId: "run-ada-7", status: "running", phase: "tool", events: [
+ ["kind": "turn_started", "turn": 1, "text": "Fix the flaky login test in the web app"],
+ ["kind": "thought", "turn": 1, "text": "The test waits on a fixed timeout.\nLook at the spec first."],
+ ["kind": "tool_call", "turn": 1, "tool_id": "t1", "tool_title": "rg -n \"login\" tests/", "tool_kind": "execute"],
+ ["kind": "tool_update", "turn": 1, "tool_id": "t1", "tool_status": "completed"],
+ ["kind": "tool_call", "turn": 1, "tool_id": "t2", "tool_title": "Read tests/login.spec.ts", "tool_kind": "read"],
+ ["kind": "tool_update", "turn": 1, "tool_id": "t2", "tool_status": "completed"],
+ ["kind": "tool_call", "turn": 1, "tool_id": "t3", "tool_title": "pnpm test login", "tool_kind": "execute"],
+ ["kind": "tool_update", "turn": 1, "tool_id": "t3", "tool_status": "failed", "text": "1 failed: timed out after 5000 ms"],
+ ["kind": "message", "turn": 1, "text": "The login test waits a fixed **5 s** for the redirect. "],
+ ["kind": "message", "turn": 1, "text": "I replaced it with `waitForURL`, so it waits exactly as long as the redirect takes."],
+ ["kind": "turn_ended", "turn": 1, "stop_reason": "end_turn"],
+ ["kind": "turn_started", "turn": 2, "text": "Run the whole suite to be sure"],
+ ["kind": "tool_call", "turn": 2, "tool_id": "t4", "tool_title": "pnpm test", "tool_kind": "execute"],
+ ["kind": "tool_update", "turn": 2, "tool_id": "t4", "tool_status": "in_progress"],
+ ]),
+ "run-codex-2": page(runId: "run-codex-2", status: "failed", phase: "failed", events: [
+ ["kind": "turn_started", "turn": 1, "text": "Triage the open issues"],
+ ["kind": "error", "turn": 1, "text": "auth failed: no OpenAI key"],
+ ["kind": "exited", "turn": 1, "text": "exit status 1"],
+ ]),
+ ]
+
+ private static func page(runId: String, status: String, phase: String, events: [[String: Any]]) -> String {
+ let t0: UInt64 = 1_791_800_000_000
+ let numbered = events.enumerated().map { i, e in
+ e.merging(["seq": i + 1, "ts_ms": t0 + UInt64(i) * 4000]) { a, _ in a }
+ }
+ let page: [String: Any] = ["run_id": runId, "status": status, "phase": phase, "events": numbered,
+ "cursor": numbered.count, "caught_up": true]
+ let data = (try? JSONSerialization.data(withJSONObject: page, options: [.sortedKeys])) ?? Data()
+ return String(decoding: data, as: UTF8.self)
+ }
+}
diff --git a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/RunTimelineModel.swift b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/RunTimelineModel.swift
new file mode 100644
index 0000000000..d6975a726d
--- /dev/null
+++ b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/RunTimelineModel.swift
@@ -0,0 +1,104 @@
+// SPDX-License-Identifier: FSL-1.1-MIT
+// Copyright (c) 2026 Cua AI, Inc.
+
+import CuaSDK
+import CuaSpacesFFI
+import Foundation
+import Observation
+
+/// One run's conversation as it streams in: `agent_events` pages folded by
+/// the SDK's `AgentTranscript` (cua-agents' `Transcript`, the rule the web
+/// UI's `transcript.ts` mirrors), so both UIs show the same items and labels.
+@MainActor
+@Observable
+public final class RunTimelineModel: Identifiable {
+ public private(set) var items: [AgentTranscriptItem] = []
+ /// The run's status from its latest page; the run row's until then.
+ public private(set) var status: AppAgentStatus
+ /// `responding`, `tool`, ... while a turn runs.
+ public private(set) var phase: String
+ public private(set) var loading = true
+ /// The last read failed (items read before it stay).
+ public private(set) var error: String?
+
+ let backend: SpacesBackend
+ let spaceId: String
+ public let run: AppSpaceAgentRun
+ private let transcript = AgentTranscript()
+ private var cursor: UInt64 = 0
+
+ /// Pages read per poll before waiting, as the web UI's store.
+ static let maxPages = 20
+
+ public init(backend: SpacesBackend, spaceId: String, run: AppSpaceAgentRun) {
+ self.backend = backend
+ self.spaceId = spaceId
+ self.run = run
+ self.status = run.status
+ self.phase = run.phase
+ }
+
+ public var live: Bool { status == .running }
+
+ /// Reads every page written since the last read.
+ public func refresh() async {
+ do {
+ for _ in 0..<Self.maxPages {
+ let json = try await backend.agentEvents(id: spaceId, runId: run.runId, cursor: cursor)
+ if let c = try transcript.absorbJson(json: json) { cursor = max(cursor, c) }
+ let page = (try? JSONSerialization.jsonObject(with: Data(json.utf8))) as? [String: Any] ?? [:]
+ if let s = page["status"] as? String { status = Self.status(s) }
+ if let p = page["phase"] as? String { phase = p }
+ if page["caught_up"] as? Bool ?? true { break }
+ }
+ items = transcript.items()
+ error = nil
+ } catch {
+ items = transcript.items()
+ self.error = LiveSpacesBackend.words(error)
+ }
+ loading = false
+ }
+
+ /// Reads while the view is open: every half second while a turn runs,
+ /// every 4 s otherwise (the web UI's intervals).
+ public func poll() async {
+ while !Task.isCancelled {
+ await refresh()
+ try? await Task.sleep(for: .milliseconds(live ? 500 : 4000))
+ }
+ }
+
+ static func status(_ s: String) -> AppAgentStatus {
+ switch s {
+ case "running": .running
+ case "idle": .idle
+ case "failed": .failed
+ case "crashed": .crashed
+ default: .unknown
+ }
+ }
+
+ /// The line under the last item: what the run is doing now (the web
+ /// UI's `RunFooter`), or nil.
+ public var footer: (text: String, failed: Bool)? {
+ switch status {
+ case .running:
+ return (phase == "responding" ? "Writing" : phase == "tool" ? "Using tools" : "Working", false)
+ case .failed, .crashed:
+ let label = appAgentStatusLabel(status: status)
+ return (run.reason.isEmpty ? label : "\(label): \(run.reason)", true)
+ case .idle:
+ return ("Waiting for a follow-up.", false)
+ case .unknown:
+ return nil
+ }
+ }
+
+ /// The activity group that stays open while its turn runs: the newest
+ /// one of the last item's turn.
+ public var openActivity: Int? {
+ guard live, let lastTurn = items.last?.turn else { return nil }
+ return items.indices.last { items[$0].kind == "activity" && items[$0].turn == lastTurn }
+ }
+}
diff --git a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/SpacesBackend.swift b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/SpacesBackend.swift
index 6e68b9d9a3..6e7f43e88c 100644
--- a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/SpacesBackend.swift
+++ b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/SpacesBackend.swift
@@ -77,6 +77,9 @@ public protocol SpacesBackend: AnyObject, Sendable {
/// The Space's coding-agent runs as rows (the app core's mapping of the
/// SDK's run records, attention first).
func agentRuns(id: String) async throws -> [AppSpaceAgentRun]
+ /// One run's events after `cursor`, as the `agent_events` JSON
+ /// (`events`, `cursor`, `caught_up`, `status`, `phase`).
+ func agentEvents(id: String, runId: String, cursor: UInt64) async throws -> String
/// The Space's latest thumbnail from the SDK's shared cache (the cua
/// daemon's): no older than `maxAgeMs` (nil: any age), captured fresh
/// when the cache is older; `nil` when there is none and the Space
@@ -113,6 +116,9 @@ public extension SpacesBackend {
func shares(id: String) async throws -> [AppShareEntryInput] { [] }
func share(id: String, who: String, role: String) async throws -> [AppShareEntryInput] { [] }
func unshare(id: String, who: String) async throws -> [AppShareEntryInput] { [] }
+ func agentEvents(id: String, runId: String, cursor: UInt64) async throws -> String {
+ throw FixtureError(message: "This Space's runs can't be read here")
+ }
func lumeSource() async -> String? { nil }
func runningMacosVms() async -> Int? { nil }
func setLumeSource(_ value: String) async throws {}
@@ -437,6 +443,10 @@ public final class LiveSpacesBackend: SpacesBackend, @unchecked Sendable {
return appAgentRows(runsJson: runs.map(\.json))
}
+ public func agentEvents(id: String, runId: String, cursor: UInt64) async throws -> String {
+ try await cua.spaces().space(space: id).agentEvents(runId: runId, cursor: cursor, max: nil)
+ }
+
public func thumbnail(id: String, maxAgeMs: UInt64?) async -> SpaceThumbnailData? {
let result = await withTimeout(seconds: 5) { [cua] in
try await cua.spaces().space(space: id).thumbnail(maxAgeMs: maxAgeMs)
@@ -888,6 +898,13 @@ public final class FixtureSpacesBackend: SpacesBackend, @unchecked Sendable {
if let error { throw error }
return appAgentRows(runsJson: runs)
}
+ /// `agent_events` pages, per run id: the whole run, caught up.
+ public var fixtureEvents: [String: String] = [:]
+ public func agentEvents(id: String, runId: String, cursor: UInt64) async throws -> String {
+ let page = await MainActor.run { fixtureEvents[runId] }
+ guard let page else { throw FixtureError(message: "no run \(runId) in \(id)") }
+ return page
+ }
public private(set) var sent: [String] = []
public func sendFiles(id: String, paths: [String]) async throws -> [AppSentFileInfo] {
await MainActor.run { sent += paths }
diff --git a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Views/RunTimelineView.swift b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Views/RunTimelineView.swift
new file mode 100644
index 0000000000..45b1ff3038
--- /dev/null
+++ b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Views/RunTimelineView.swift
@@ -0,0 +1,164 @@
+// SPDX-License-Identifier: FSL-1.1-MIT
+// Copyright (c) 2026 Cua AI, Inc.
+
+import CuaSDK
+import CuaSpacesFFI
+import SwiftUI
+
+/// A run's conversation, as the web UI's `Timeline`: the prompt as a bubble
+/// on the right, the agent's prose, and each stretch of activity as a muted
+/// group that shows its summary and last step until opened. It follows the
+/// end while the run writes; scrolled up, a pill brings the reader back.
+struct RunTimelineView: View {
+ let timeline: RunTimelineModel
+ @Environment(\.dismiss) private var dismiss
+ /// Activity groups the reader opened or closed (by item index).
+ @State private var toggled: Set<Int> = []
+ @State private var position = ScrollPosition(edge: .bottom)
+ @State private var atEnd = true
+
+ var body: some View {
+ VStack(spacing: 0) {
+ header
+ Divider()
+ content.frame(maxWidth: .infinity, maxHeight: .infinity)
+ }
+ .frame(minWidth: 560, idealWidth: 720, minHeight: 420, idealHeight: 640)
+ .task { await timeline.poll() }
+ }
+
+ private var header: some View {
+ HStack(spacing: 12) {
+ VStack(alignment: .leading, spacing: 2) {
+ Text(appAgentName(agent: timeline.run.agent)).font(.headline)
+ Text(appAgentSubtitle(run: timeline.run))
+ .font(.caption).foregroundStyle(.secondary).lineLimit(1).truncationMode(.tail)
+ }
+ Spacer(minLength: 8)
+ Text(appAgentStatusLabel(status: timeline.status)).font(.caption).foregroundStyle(.secondary)
+ Button("Done") { dismiss() }.keyboardShortcut(.defaultAction)
+ }
+ .padding(.horizontal, 20)
+ .padding(.vertical, 12)
+ }
+
+ @ViewBuilder private var content: some View {
+ if timeline.items.isEmpty, let error = timeline.error {
+ centered("Couldn't read this run", error)
+ } else if timeline.items.isEmpty, timeline.loading {
+ ProgressView().controlSize(.small)
+ } else {
+ ZStack(alignment: .bottom) {
+ ScrollView {
+ LazyVStack(alignment: .leading, spacing: 4) {
+ ForEach(Array(timeline.items.enumerated()), id: \.offset) { i, item in
+ row(i, item).frame(maxWidth: 720, alignment: .leading)
+ }
+ if let footer = timeline.footer {
+ Text(footer.text)
+ .font(.caption)
+ .foregroundStyle(footer.failed ? AnyShapeStyle(.red) : AnyShapeStyle(.secondary))
+ .padding(.top, 4)
+ .frame(maxWidth: 720, alignment: .leading)
+ .accessibilityIdentifier("run-timeline-footer")
+ }
+ }
+ .padding(.horizontal, 32)
+ .padding(.vertical, 24)
+ .frame(maxWidth: .infinity)
+ }
+ .scrollPosition($position)
+ .defaultScrollAnchor(.bottom, for: .sizeChanges)
+ .onScrollGeometryChange(for: Bool.self) { g in
+ g.contentOffset.y + g.containerSize.height >= g.contentSize.height - 32
+ } action: { _, now in
+ atEnd = now
+ }
+ if !atEnd {
+ Button {
+ withAnimation { position.scrollTo(edge: .bottom) }
+ } label: {
+ Label(timeline.live ? "Follow the run" : "Jump to latest", systemImage: "arrow.down")
+ }
+ .buttonBorderShape(.capsule)
+ .controlSize(.small)
+ .padding(.bottom, 16)
+ }
+ }
+ .accessibilityIdentifier("run-timeline")
+ }
+ }
+
+ @ViewBuilder private func row(_ i: Int, _ item: AgentTranscriptItem) -> some View {
+ switch item.kind {
+ case "user":
+ HStack {
+ Spacer(minLength: 80)
+ Text(item.text)
+ .textSelection(.enabled)
+ .padding(.horizontal, 14)
+ .padding(.vertical, 8)
+ .background(.quaternary, in: UnevenRoundedRectangle(topLeadingRadius: 16, bottomLeadingRadius: 16,
+ bottomTrailingRadius: 6, topTrailingRadius: 16))
+ }
+ .padding(.vertical, 4)
+ case "message":
+ Text(Self.markdown(item.text))
+ .textSelection(.enabled)
+ .padding(.vertical, 4)
+ default:
+ activity(i, item).padding(.vertical, 2)
+ }
+ }
+
+ private func activity(_ i: Int, _ item: AgentTranscriptItem) -> some View {
+ let open = (i == timeline.openActivity) != toggled.contains(i)
+ return VStack(alignment: .leading, spacing: 4) {
+ Button {
+ if toggled.contains(i) { toggled.remove(i) } else { toggled.insert(i) }
+ } label: {
+ HStack(spacing: 6) {
+ Image(systemName: "chevron.right")
+ .font(.system(size: 9, weight: .semibold))
+ .rotationEffect(.degrees(open ? 90 : 0))
+ Text(item.text).fontWeight(.medium)
+ if !open, let last = item.steps.last {
+ Text(last).foregroundStyle(.tertiary).lineLimit(1).truncationMode(.tail)
+ }
+ }
+ .contentShape(Rectangle())
+ }
+ .buttonStyle(.plain)
+ .accessibilityValue(open ? "expanded" : "collapsed")
+ if open {
+ VStack(alignment: .leading, spacing: 2) {
+ ForEach(Array(item.steps.enumerated()), id: \.offset) { _, step in
+ Text(step)
+ .font(.system(size: 11.5, design: .monospaced))
+ .lineLimit(1).truncationMode(.tail)
+ .help(step)
+ }
+ }
+ .padding(.leading, 14)
+ .overlay(alignment: .leading) { Rectangle().fill(.separator).frame(width: 1).padding(.leading, 5) }
+ }
+ }
+ .font(.caption)
+ .foregroundStyle(.secondary)
+ }
+
+ private func centered(_ title: String, _ detail: String) -> some View {
+ VStack(spacing: 6) {
+ Text(title).font(.headline)
+ Text(detail).font(.callout).foregroundStyle(.secondary).multilineTextAlignment(.center)
+ }
+ .frame(maxWidth: 360)
+ .padding(32)
+ }
+
+ /// The agent's Markdown, inline styles and links; blocks keep their lines.
+ static func markdown(_ text: String) -> AttributedString {
+ (try? AttributedString(markdown: text, options: .init(interpretedSyntax: .inlineOnlyPreservingWhitespace)))
+ ?? AttributedString(text)
+ }
+}
diff --git a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Views/SpaceDetailView.swift b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Views/SpaceDetailView.swift
index 5f00919ae7..9002b417e2 100644
--- a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Views/SpaceDetailView.swift
+++ b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Views/SpaceDetailView.swift
@@ -22,6 +22,8 @@ struct SpaceDetailView: View {
@State private var teleport: TeleportModel?
@State private var dropStatus: TeleportDropZone.Status?
@State private var agents: AgentRunsModel?
+ /// The run whose conversation is open (a sheet).
+ @State private var openRun: RunTimelineModel?
@State private var sharing: ShareModel?
/// Connect (or Try again) was pressed: the stream opens even with
/// "Connect to the desktop automatically" off.
@@ -68,7 +70,7 @@ struct SpaceDetailView: View {
switch title {
case "Stream": streamRows
case "Agents":
- if let agents { AgentRows(agents: agents, copy: copy) } else { Text(copy.agentsLoading).foregroundStyle(.secondary) }
+ if let agents { AgentRows(agents: agents, copy: copy, open: open) } else { Text(copy.agentsLoading).foregroundStyle(.secondary) }
default: teleportRow
}
}
@@ -114,6 +116,18 @@ struct SpaceDetailView: View {
agents = model
await model.poll()
}
+ .sheet(item: $openRun) { RunTimelineView(timeline: $0) }
+ .task(id: space.id) {
+ // Captures: an agent run's conversation open (a running one first).
+ guard DevHooks.value("CUA_SPACES_START_VIEW") == "run-timeline" else { return }
+ for _ in 0..<40 {
+ if case .ready(let runs) = agents?.load, let run = runs.first(where: { $0.status == .running }) ?? runs.first {
+ open(run)
+ return
+ }
+ try? await Task.sleep(for: .milliseconds(250))
+ }
+ }
.task(id: space.id) {
// Captures: this Space's own window (its live desktop, with the
// other participants' cursors), as Open does.
@@ -204,6 +218,10 @@ struct SpaceDetailView: View {
}
/// Keeps the stream's last frame as the Space's preview.
+ private func open(_ run: AppSpaceAgentRun) {
+ openRun = RunTimelineModel(backend: model.backend, spaceId: space.id, run: run)
+ }
+
private func keepLastFrame() {
guard let frame = session?.frame, let image = SpaceThumbnails.image(frame) else { return }
model.thumbnails.set(space.id, image)
@@ -611,10 +629,12 @@ struct StreamRowList: View {
}
/// The Agents section: one line per run (the agent and what it was asked),
-/// its status on the right, the reason as the tooltip.
+/// its status on the right, the reason as the tooltip. A run opens its
+/// conversation.
struct AgentRows: View {
let agents: AgentRunsModel
let copy: AppDetailCopy
+ var open: (AppSpaceAgentRun) -> Void = { _ in }
var body: some View {
switch agents.load {
@@ -626,11 +646,15 @@ struct AgentRows: View {
Text(copy.agentsEmpty).foregroundStyle(.secondary)
case .ready(let runs):
ForEach(runs, id: \.runId) { run in
- LabeledContent {
- Text(AgentRunsModel.status(run)).foregroundStyle(.secondary)
- } label: {
- Text(AgentRunsModel.line(run)).lineLimit(1).truncationMode(.tail)
+ Button { open(run) } label: {
+ LabeledContent {
+ Text(AgentRunsModel.status(run)).foregroundStyle(.secondary)
+ } label: {
+ Text(AgentRunsModel.line(run)).lineLimit(1).truncationMode(.tail)
+ }
+ .contentShape(Rectangle())
}
+ .buttonStyle(.plain)
.help(run.reason)
.accessibilityIdentifier("agent-run-\(run.runId)")
}
diff --git a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/RunTimelineTests.swift b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/RunTimelineTests.swift
new file mode 100644
index 0000000000..79672c180a
--- /dev/null
+++ b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/RunTimelineTests.swift
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: FSL-1.1-MIT
+// Copyright (c) 2026 Cua AI, Inc.
+
+import CuaSDK
+import CuaSpacesFFI
+@testable import CuaSpacesMacKit
+import Foundation
+import Testing
+
+@MainActor
+@Suite("Run timeline")
+struct RunTimelineTests {
+ func timeline(_ runId: String) async -> RunTimelineModel {
+ let backend = FixtureSpacesBackend()
+ backend.fixtureRuns["local:aurora"] = FixtureSpacesBackend.sampleRuns
+ backend.fixtureEvents = FixtureSpacesBackend.sampleEvents
+ let runs = try! await backend.agentRuns(id: "local:aurora")
+ let run = runs.first { $0.runId == runId }!
+ let model = RunTimelineModel(backend: backend, spaceId: "local:aurora", run: run)
+ await model.refresh()
+ return model
+ }
+
+ /// The items and labels the web UI's transcript.ts gives the same events.
+ @Test func aRunningRunFoldsLikeTheWebUI() async {
+ let t = await timeline("run-ada-7")
+ #expect(t.items.map(\.kind) == ["user", "activity", "message", "activity", "user", "activity"])
+ #expect(t.items[0].text == "Fix the flaky login test in the web app")
+ // A tool's update rewrites its own step; only `error` events count as errors.
+ #expect(t.items[1].text == "4 steps")
+ #expect(t.items[1].steps == [
+ "Thinking: The test waits on a fixed timeout.",
+ "Tool rg -n \"login\" tests/ completed",
+ "Tool Read tests/login.spec.ts completed",
+ "Tool pnpm test login failed: 1 failed: timed out after 5000 ms",
+ ])
+ // Message chunks of a turn join into one item.
+ #expect(t.items[2].text == "The login test waits a fixed **5 s** for the redirect. I replaced it with `waitForURL`, so it waits exactly as long as the redirect takes.")
+ #expect(t.items[3].steps == ["Turn 1 ended (end_turn)"])
+ #expect(t.items[5].text == "1 step")
+ #expect(t.items[5].steps == ["Tool pnpm test in_progress"])
+ // The newest group stays open while its turn runs.
+ #expect(t.openActivity == 5)
+ #expect(t.footer?.text == "Using tools")
+ #expect(t.error == nil)
+ }
+
+ @Test func aFailedRunCountsItsErrorAndSaysWhy() async {
+ let t = await timeline("run-codex-2")
+ #expect(t.items.map(\.kind) == ["user", "activity"])
+ #expect(t.items[1].text == "2 steps, 1 error")
+ #expect(t.items[1].steps == ["Error: auth failed: no OpenAI key", "Exited: exit status 1"])
+ #expect(t.openActivity == nil)
+ #expect(t.footer?.text == "Failed: auth failed")
+ #expect(t.footer?.failed == true)
+ }
+
+ @Test func readingAgainAddsNothing() async {
+ let t = await timeline("run-ada-7")
+ let before = t.items
+ await t.refresh()
+ #expect(t.items == before)
+ }
+
+ @Test func aFailedReadIsAnError() async {
+ let backend = FixtureSpacesBackend()
+ backend.fixtureRuns["local:aurora"] = FixtureSpacesBackend.sampleRuns
+ let run = try! await backend.agentRuns(id: "local:aurora")[0]
+ let t = RunTimelineModel(backend: backend, spaceId: "local:aurora", run: run)
+ await t.refresh()
+ #expect(t.items.isEmpty)
+ #expect(t.error != nil)
+ #expect(!t.loading)
+ }
+}