fix(swift-ios): distinguish monitoring from working
This commit is contained in:
10 files changed
+98
-31
No files matched your search
@@ -3298,15 +3298,16 @@ final class NativeFeatureClient: FeatureClient, FeatureDeviceManaging,
|
||||
return
|
||||
}
|
||||
|
||||
let backgroundWorkIsActive = shellThread.backgroundLiveness == .working
|
||||
let backgroundLiveness = shellThread.backgroundLiveness
|
||||
let backgroundWorkIsActive = backgroundLiveness == .working
|
||||
let sessionIsLive = shellThread.session?.status == "starting"
|
||||
|| shellThread.session?.status == "running"
|
||||
detail.thread.state = mapThreadState(
|
||||
detail.thread.state = Self.resolveThreadState(
|
||||
latestTurn: shellThread.latestTurn,
|
||||
session: shellThread.session,
|
||||
hasApprovals: !detail.approvals.isEmpty,
|
||||
hasUserInput: !detail.userInputs.isEmpty,
|
||||
backgroundWorkIsActive: backgroundWorkIsActive
|
||||
backgroundLiveness: backgroundLiveness
|
||||
)
|
||||
detail.thread.workingStartedAt = workingStartedAt(
|
||||
latestTurn: shellThread.latestTurn,
|
||||
@@ -3662,7 +3663,8 @@ final class NativeFeatureClient: FeatureClient, FeatureDeviceManaging,
|
||||
_ thread: OrchestrationThreadShell,
|
||||
environment: Environment
|
||||
) -> FeatureThread {
|
||||
let backgroundWorkIsActive = thread.backgroundLiveness == .working
|
||||
let backgroundLiveness = thread.backgroundLiveness
|
||||
let backgroundWorkIsActive = backgroundLiveness == .working
|
||||
return FeatureThread(
|
||||
id: FeatureScopedID.thread(environmentID: environment.id, wireID: thread.id),
|
||||
wireID: thread.id,
|
||||
@@ -3677,12 +3679,12 @@ final class NativeFeatureClient: FeatureClient, FeatureDeviceManaging,
|
||||
worktreePath: thread.worktreePath,
|
||||
createdAt: parseDate(thread.createdAt),
|
||||
updatedAt: parseDate(thread.updatedAt),
|
||||
state: mapThreadState(
|
||||
state: Self.resolveThreadState(
|
||||
latestTurn: thread.latestTurn,
|
||||
session: thread.session,
|
||||
hasApprovals: thread.hasPendingApprovals,
|
||||
hasUserInput: thread.hasPendingUserInput,
|
||||
backgroundWorkIsActive: backgroundWorkIsActive
|
||||
backgroundLiveness: backgroundLiveness
|
||||
),
|
||||
providerID: thread.modelSelection.instanceId,
|
||||
providerName: threadProviderName(
|
||||
@@ -3726,10 +3728,11 @@ final class NativeFeatureClient: FeatureClient, FeatureDeviceManaging,
|
||||
_ thread: OrchestrationThread,
|
||||
environment: Environment
|
||||
) -> FeatureThread {
|
||||
let backgroundWorkIsActive = backgroundLiveness(
|
||||
let backgroundLiveness = backgroundLiveness(
|
||||
threadID: thread.id,
|
||||
environmentID: environment.id
|
||||
) == .working
|
||||
)
|
||||
let backgroundWorkIsActive = backgroundLiveness == .working
|
||||
return FeatureThread(
|
||||
id: FeatureScopedID.thread(environmentID: environment.id, wireID: thread.id),
|
||||
wireID: thread.id,
|
||||
@@ -3745,12 +3748,12 @@ final class NativeFeatureClient: FeatureClient, FeatureDeviceManaging,
|
||||
worktreePath: thread.worktreePath,
|
||||
createdAt: parseDate(thread.createdAt),
|
||||
updatedAt: parseDate(thread.updatedAt),
|
||||
state: mapThreadState(
|
||||
state: Self.resolveThreadState(
|
||||
latestTurn: thread.latestTurn,
|
||||
session: thread.session,
|
||||
hasApprovals: false,
|
||||
hasUserInput: false,
|
||||
backgroundWorkIsActive: backgroundWorkIsActive
|
||||
backgroundLiveness: backgroundLiveness
|
||||
),
|
||||
providerID: thread.modelSelection.instanceId,
|
||||
providerName: threadProviderName(
|
||||
@@ -3839,18 +3842,19 @@ final class NativeFeatureClient: FeatureClient, FeatureDeviceManaging,
|
||||
}
|
||||
|
||||
var mappedThread = mapThread(thread, environment: environment)
|
||||
let backgroundWorkIsActive = backgroundLiveness(
|
||||
let backgroundLiveness = backgroundLiveness(
|
||||
threadID: thread.id,
|
||||
environmentID: environment.id
|
||||
) == .working
|
||||
)
|
||||
let backgroundWorkIsActive = backgroundLiveness == .working
|
||||
let sessionIsLive = thread.session?.status == "starting"
|
||||
|| thread.session?.status == "running"
|
||||
mappedThread.state = mapThreadState(
|
||||
mappedThread.state = Self.resolveThreadState(
|
||||
latestTurn: thread.latestTurn,
|
||||
session: thread.session,
|
||||
hasApprovals: !cache.approvals.isEmpty,
|
||||
hasUserInput: !cache.userInputs.isEmpty,
|
||||
backgroundWorkIsActive: backgroundWorkIsActive
|
||||
backgroundLiveness: backgroundLiveness
|
||||
)
|
||||
return FeatureThreadDetail(
|
||||
thread: mappedThread,
|
||||
@@ -4457,19 +4461,20 @@ final class NativeFeatureClient: FeatureClient, FeatureDeviceManaging,
|
||||
}
|
||||
}
|
||||
|
||||
private func mapThreadState(
|
||||
nonisolated static func resolveThreadState(
|
||||
latestTurn: OrchestrationLatestTurn?,
|
||||
session: OrchestrationSession?,
|
||||
hasApprovals: Bool,
|
||||
hasUserInput: Bool,
|
||||
backgroundWorkIsActive: Bool
|
||||
backgroundLiveness: OrchestrationBackgroundLiveness?
|
||||
) -> FeatureThreadState {
|
||||
if hasApprovals { return .waitingForApproval }
|
||||
if hasUserInput { return .waitingForInput }
|
||||
if session?.status == "starting" { return .queued }
|
||||
if session?.status == "running" || latestTurn?.state == "running" { return .working }
|
||||
if session?.status == "error" || latestTurn?.state == "error" { return .failed }
|
||||
if backgroundWorkIsActive { return .working }
|
||||
if backgroundLiveness == .working { return .working }
|
||||
if backgroundLiveness == .monitoring { return .monitoring }
|
||||
if latestTurn?.state == "completed" { return .completed }
|
||||
return .idle
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ enum PlatformAgentAwarenessProjection {
|
||||
|
||||
private static func isActive(_ state: FeatureThreadState) -> Bool {
|
||||
switch state {
|
||||
case .queued, .working, .waitingForApproval, .waitingForInput:
|
||||
case .queued, .working, .monitoring, .waitingForApproval, .waitingForInput:
|
||||
true
|
||||
case .idle, .failed, .completed:
|
||||
false
|
||||
@@ -110,6 +110,7 @@ enum PlatformAgentAwarenessProjection {
|
||||
switch state {
|
||||
case .queued: .starting
|
||||
case .working: .running
|
||||
case .monitoring: .running
|
||||
case .waitingForApproval: .waitingForApproval
|
||||
case .waitingForInput: .waitingForInput
|
||||
case .failed: .failed
|
||||
@@ -122,6 +123,7 @@ enum PlatformAgentAwarenessProjection {
|
||||
switch state {
|
||||
case .queued: "Starting"
|
||||
case .working: "Working"
|
||||
case .monitoring: "Monitoring"
|
||||
case .waitingForApproval: "Approval"
|
||||
case .waitingForInput: "Input"
|
||||
case .failed: "Failed"
|
||||
|
||||
@@ -27,7 +27,9 @@ enum PlatformThreadTransitionClassifier {
|
||||
.warning
|
||||
case .failed:
|
||||
.error
|
||||
case .completed where oldState == .working || oldState == .queued:
|
||||
case .completed where oldState == .working
|
||||
|| oldState == .queued
|
||||
|| oldState == .monitoring:
|
||||
.success
|
||||
default:
|
||||
nil
|
||||
|
||||
@@ -291,13 +291,14 @@ public struct ThreadDetailView: View {
|
||||
case .working: "circle.dotted"
|
||||
case .done: "checkmark.circle"
|
||||
case .failed: "exclamationmark.circle"
|
||||
case .approval, .input, .ready: nil
|
||||
case .approval, .input, .monitoring, .ready: nil
|
||||
}
|
||||
}
|
||||
|
||||
private var headerStatusColor: Color {
|
||||
switch currentThread.homeStatus {
|
||||
case .working: T3Colors.statusRunning
|
||||
case .monitoring: T3Colors.statusRunning
|
||||
case .approval: T3Colors.warning
|
||||
case .input: T3Colors.statusInput
|
||||
case .failed: T3Colors.danger
|
||||
@@ -307,7 +308,9 @@ public struct ThreadDetailView: View {
|
||||
}
|
||||
|
||||
private func timeline(_ detail: FeatureThreadDetail) -> some View {
|
||||
let isWorking = detail.thread.state == .working || detail.thread.state == .queued
|
||||
let isWorking = detail.thread.state == .working
|
||||
|| detail.thread.state == .queued
|
||||
|| detail.thread.state == .monitoring
|
||||
return Group {
|
||||
if detail.messages.isEmpty, !isWorking {
|
||||
ContentUnavailableView(
|
||||
@@ -325,6 +328,7 @@ public struct ThreadDetailView: View {
|
||||
isWorking: isWorking,
|
||||
activeSubagentCount: detail.activeSubagentCount,
|
||||
backgroundWorkIsActive: detail.backgroundWorkIsActive,
|
||||
isMonitoring: detail.thread.state == .monitoring,
|
||||
canLoadEarlier: detail.page?.hasMore == true,
|
||||
isLoadingEarlier: detail.page?.isLoading == true,
|
||||
onLoadEarlier: {
|
||||
@@ -636,6 +640,7 @@ private struct FeatureTranscriptCollectionView: UIViewRepresentable {
|
||||
let isWorking: Bool
|
||||
let activeSubagentCount: Int
|
||||
let backgroundWorkIsActive: Bool
|
||||
let isMonitoring: Bool
|
||||
let canLoadEarlier: Bool
|
||||
let isLoadingEarlier: Bool
|
||||
let onLoadEarlier: () -> Void
|
||||
@@ -670,6 +675,7 @@ private struct FeatureTranscriptCollectionView: UIViewRepresentable {
|
||||
isWorking: isWorking,
|
||||
activeSubagentCount: activeSubagentCount,
|
||||
backgroundWorkIsActive: backgroundWorkIsActive,
|
||||
isMonitoring: isMonitoring,
|
||||
canLoadEarlier: canLoadEarlier,
|
||||
isLoadingEarlier: isLoadingEarlier,
|
||||
onLoadEarlier: onLoadEarlier,
|
||||
@@ -719,6 +725,7 @@ private struct FeatureTranscriptCollectionView: UIViewRepresentable {
|
||||
private var currentIsWorking = false
|
||||
private var currentActiveSubagentCount = 0
|
||||
private var currentBackgroundWorkIsActive = false
|
||||
private var currentIsMonitoring = false
|
||||
private var currentCanLoadEarlier = false
|
||||
private var currentIsLoadingEarlier = false
|
||||
private var markdownPrefetches: [String: MarkdownPrefetch] = [:]
|
||||
@@ -748,7 +755,8 @@ private struct FeatureTranscriptCollectionView: UIViewRepresentable {
|
||||
cell.contentConfiguration = UIHostingConfiguration {
|
||||
FeatureThreadWorkingIndicator(
|
||||
activeSubagentCount: self?.currentActiveSubagentCount ?? 0,
|
||||
backgroundWorkIsActive: self?.currentBackgroundWorkIsActive == true
|
||||
backgroundWorkIsActive: self?.currentBackgroundWorkIsActive == true,
|
||||
isMonitoring: self?.currentIsMonitoring == true
|
||||
)
|
||||
}
|
||||
.margins(.all, 0)
|
||||
@@ -791,6 +799,7 @@ private struct FeatureTranscriptCollectionView: UIViewRepresentable {
|
||||
isWorking: Bool,
|
||||
activeSubagentCount: Int,
|
||||
backgroundWorkIsActive: Bool,
|
||||
isMonitoring: Bool,
|
||||
canLoadEarlier: Bool,
|
||||
isLoadingEarlier: Bool,
|
||||
onLoadEarlier: @escaping () -> Void,
|
||||
@@ -807,6 +816,7 @@ private struct FeatureTranscriptCollectionView: UIViewRepresentable {
|
||||
let workingChanged = currentIsWorking != isWorking
|
||||
let workingDetailChanged = currentActiveSubagentCount != activeSubagentCount
|
||||
|| currentBackgroundWorkIsActive != backgroundWorkIsActive
|
||||
|| currentIsMonitoring != isMonitoring
|
||||
let loadEarlierChanged = currentCanLoadEarlier != canLoadEarlier
|
||||
|| currentIsLoadingEarlier != isLoadingEarlier
|
||||
guard threadChanged || typeSizeChanged || revisionChanged || workingChanged
|
||||
@@ -827,6 +837,7 @@ private struct FeatureTranscriptCollectionView: UIViewRepresentable {
|
||||
currentIsWorking = isWorking
|
||||
currentActiveSubagentCount = activeSubagentCount
|
||||
currentBackgroundWorkIsActive = backgroundWorkIsActive
|
||||
currentIsMonitoring = isMonitoring
|
||||
currentCanLoadEarlier = canLoadEarlier
|
||||
currentIsLoadingEarlier = isLoadingEarlier
|
||||
guard threadChanged || idsChanged || !changedIDs.isEmpty || workingChanged
|
||||
@@ -1193,8 +1204,12 @@ private struct FeatureLoadEarlierTurnsButton: View {
|
||||
private struct FeatureThreadWorkingIndicator: View {
|
||||
let activeSubagentCount: Int
|
||||
let backgroundWorkIsActive: Bool
|
||||
let isMonitoring: Bool
|
||||
|
||||
private var title: String {
|
||||
if isMonitoring {
|
||||
return "Monitoring in the background"
|
||||
}
|
||||
if activeSubagentCount == 1 {
|
||||
return "1 subagent is working"
|
||||
}
|
||||
@@ -1205,7 +1220,7 @@ private struct FeatureThreadWorkingIndicator: View {
|
||||
}
|
||||
|
||||
private var detail: String? {
|
||||
backgroundWorkIsActive ? nil : "New output will appear here"
|
||||
backgroundWorkIsActive || isMonitoring ? nil : "New output will appear here"
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
|
||||
@@ -115,6 +115,7 @@ public enum FeatureThreadState: String, Sendable, Codable {
|
||||
case idle
|
||||
case queued
|
||||
case working
|
||||
case monitoring
|
||||
case waitingForApproval
|
||||
case waitingForInput
|
||||
case failed
|
||||
|
||||
@@ -517,7 +517,7 @@ enum DailyUXSidebarRefresh {
|
||||
switch thread.state {
|
||||
case .idle, .failed, .completed:
|
||||
break
|
||||
case .queued, .working, .waitingForApproval, .waitingForInput:
|
||||
case .queued, .working, .monitoring, .waitingForApproval, .waitingForInput:
|
||||
return nil
|
||||
}
|
||||
let boundary = lastActivityAt.addingTimeInterval(3 * 24 * 60 * 60)
|
||||
@@ -571,6 +571,7 @@ enum HomeThreadStatus: String, Sendable, Equatable {
|
||||
case approval
|
||||
case input
|
||||
case working
|
||||
case monitoring
|
||||
case failed
|
||||
case done
|
||||
case ready
|
||||
@@ -591,6 +592,8 @@ extension FeatureThread {
|
||||
switch state {
|
||||
case .queued, .working:
|
||||
.working
|
||||
case .monitoring:
|
||||
.monitoring
|
||||
case .waitingForApproval:
|
||||
.approval
|
||||
case .waitingForInput:
|
||||
@@ -609,6 +612,7 @@ extension FeatureThread {
|
||||
case .approval: "Approval"
|
||||
case .input: "Input"
|
||||
case .working: "Working"
|
||||
case .monitoring: "Monitoring"
|
||||
case .failed: "Failed"
|
||||
case .done: "Done"
|
||||
case .ready: nil
|
||||
@@ -652,7 +656,7 @@ extension FeatureThread {
|
||||
|
||||
func isEffectivelySettled(at now: Date) -> Bool {
|
||||
switch state {
|
||||
case .queued, .working, .waitingForApproval, .waitingForInput:
|
||||
case .queued, .working, .monitoring, .waitingForApproval, .waitingForInput:
|
||||
return false
|
||||
case .idle, .failed, .completed:
|
||||
break
|
||||
|
||||
@@ -1026,13 +1026,14 @@ struct FeatureThreadRow: View {
|
||||
case .working: "circle.dotted"
|
||||
case .done: "checkmark.circle"
|
||||
case .failed: "exclamationmark.circle"
|
||||
case .approval, .input, .ready: nil
|
||||
case .approval, .input, .monitoring, .ready: nil
|
||||
}
|
||||
}
|
||||
|
||||
private var statusColor: Color {
|
||||
switch thread.homeStatus {
|
||||
case .working: T3Colors.statusRunning
|
||||
case .monitoring: T3Colors.statusRunning
|
||||
case .approval: T3Colors.warning
|
||||
case .input: T3Colors.statusInput
|
||||
case .failed: T3Colors.danger
|
||||
|
||||
@@ -12,6 +12,7 @@ struct HomeThreadMetadataTests {
|
||||
(.idle, .ready, nil),
|
||||
(.queued, .working, "Working"),
|
||||
(.working, .working, "Working"),
|
||||
(.monitoring, .monitoring, "Monitoring"),
|
||||
(.waitingForApproval, .approval, "Approval"),
|
||||
(.waitingForInput, .input, "Input"),
|
||||
(.failed, .failed, "Failed"),
|
||||
@@ -53,10 +54,18 @@ struct HomeThreadMetadataTests {
|
||||
state: .idle,
|
||||
workingStartedAt: now.addingTimeInterval(-10)
|
||||
)
|
||||
let monitoring = FeatureThread(
|
||||
id: "monitoring",
|
||||
projectID: "project",
|
||||
title: "Watch",
|
||||
state: .monitoring,
|
||||
workingStartedAt: now.addingTimeInterval(-10)
|
||||
)
|
||||
|
||||
#expect(thread.homeWorkingDuration(at: now) == "1h 31m")
|
||||
#expect(future.homeWorkingDuration(at: now) == "0s")
|
||||
#expect(idle.homeWorkingDuration(at: now) == nil)
|
||||
#expect(monitoring.homeWorkingDuration(at: now) == nil)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -80,7 +80,33 @@ struct SubagentStatusTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
func threadShellDecodesBackgroundLiveness() throws {
|
||||
func monitoringRemainsDistinctFromActiveAgentWork() {
|
||||
let working = NativeFeatureClient.resolveThreadState(
|
||||
latestTurn: nil,
|
||||
session: nil,
|
||||
hasApprovals: false,
|
||||
hasUserInput: false,
|
||||
backgroundLiveness: .working
|
||||
)
|
||||
let monitoring = NativeFeatureClient.resolveThreadState(
|
||||
latestTurn: nil,
|
||||
session: nil,
|
||||
hasApprovals: false,
|
||||
hasUserInput: false,
|
||||
backgroundLiveness: .monitoring
|
||||
)
|
||||
|
||||
#expect(working == .working)
|
||||
#expect(monitoring == .monitoring)
|
||||
}
|
||||
|
||||
@Test(arguments: [
|
||||
OrchestrationBackgroundLiveness.working,
|
||||
OrchestrationBackgroundLiveness.monitoring,
|
||||
])
|
||||
func threadShellDecodesBackgroundLiveness(
|
||||
_ backgroundLiveness: OrchestrationBackgroundLiveness
|
||||
) throws {
|
||||
let shell = OrchestrationThreadShell(
|
||||
id: "thread-1",
|
||||
projectId: "project-1",
|
||||
@@ -104,7 +130,7 @@ struct SubagentStatusTests {
|
||||
hasPendingApprovals: false,
|
||||
hasPendingUserInput: false,
|
||||
hasActionableProposedPlan: false,
|
||||
backgroundLiveness: .working
|
||||
backgroundLiveness: backgroundLiveness
|
||||
)
|
||||
|
||||
let decoded = try JSONDecoder.t3.decode(
|
||||
@@ -112,7 +138,7 @@ struct SubagentStatusTests {
|
||||
from: JSONEncoder.t3.encode(shell)
|
||||
)
|
||||
|
||||
#expect(decoded.backgroundLiveness == .working)
|
||||
#expect(decoded.backgroundLiveness == backgroundLiveness)
|
||||
}
|
||||
|
||||
private func activity(
|
||||
|
||||
@@ -17,19 +17,21 @@ struct PlatformFeedbackTests {
|
||||
"approval": .working,
|
||||
"failure": .working,
|
||||
"complete": .working,
|
||||
"monitor-complete": .monitoring,
|
||||
"idle-complete": .idle,
|
||||
]
|
||||
let current = [
|
||||
thread(id: "approval", state: .waitingForApproval),
|
||||
thread(id: "failure", state: .failed),
|
||||
thread(id: "complete", state: .completed),
|
||||
thread(id: "monitor-complete", state: .completed),
|
||||
thread(id: "idle-complete", state: .completed),
|
||||
]
|
||||
|
||||
let signals = PlatformThreadTransitionClassifier.signals(previous: previous, current: current)
|
||||
|
||||
#expect(signals.map(\.thread.id) == ["approval", "failure", "complete"])
|
||||
#expect(signals.map(\.kind) == [.warning, .error, .success])
|
||||
#expect(signals.map(\.thread.id) == ["approval", "failure", "complete", "monitor-complete"])
|
||||
#expect(signals.map(\.kind) == [.warning, .error, .success, .success])
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user