Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions mobile/src/components/AgentSpinner.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useEffect, useRef } from 'react'
import { Radio } from 'lucide-react-native'
import { Animated, Easing, StyleSheet, View } from 'react-native'
import type { AgentWorkingMode } from '../../../src/shared/agent-status-types'

type WorktreeStatus = 'working' | 'active' | 'permission' | 'done' | 'inactive'

Expand All @@ -17,11 +19,18 @@ const STATUS_COLORS: Record<WorktreeStatus, string> = {
inactive: 'rgba(115,115,115,0.4)'
}

export function AgentSpinner({ status }: { status: WorktreeStatus }) {
export function AgentSpinner({
status,
workingMode
}: {
status: WorktreeStatus
workingMode?: AgentWorkingMode
}) {
const spinValue = useRef(new Animated.Value(0)).current
const monitoring = status === 'working' && workingMode === 'monitoring'

useEffect(() => {
if (status === 'working') {
if (status === 'working' && !monitoring) {
const animation = Animated.loop(
Animated.timing(spinValue, {
toValue: 1,
Expand All @@ -34,10 +43,18 @@ export function AgentSpinner({ status }: { status: WorktreeStatus }) {
return () => animation.stop()
}
spinValue.setValue(0)
}, [status, spinValue])
}, [monitoring, status, spinValue])

const color = STATUS_COLORS[status] ?? STATUS_COLORS.inactive

if (monitoring) {
return (
<View style={styles.wrapper} accessibilityLabel="Monitoring background tasks">
<Radio size={12} color={STATUS_COLORS.working} />
</View>
)
Comment on lines +50 to +55

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- AgentSpinner.tsx ---'
sed -n '1,120p' mobile/src/components/AgentSpinner.tsx

printf '%s\n' '--- AgentStateDot.tsx ---'
sed -n '1,120p' mobile/src/components/AgentStateDot.tsx

printf '%s\n' '--- related tests ---'
rg -n -i -C 3 'AgentSpinner|AgentStateDot|Monitoring background tasks|accessible' mobile --glob '*.{test,spec}.{ts,tsx,js,jsx}' --glob '!*node_modules*' || true

printf '%s\n' '--- accessibility props and package versions ---'
rg -n -C 2 'accessibilityLabel|accessible' mobile/src mobile/package.json package.json 2>/dev/null || true

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- indicator tests ---'
sed -n '1,150p' mobile/src/components/agent-monitoring-indicators.test.ts

printf '%s\n' '--- React Native package declarations ---'
rg -n '"react-native"|react-native' mobile/package.json package.json pnpm-lock.yaml yarn.lock package-lock.json 2>/dev/null | head -40 || true

printf '%s\n' '--- exact indicator accessibility declarations ---'
rg -n -C 2 'accessibilityLabel|accessible' mobile/src/components/AgentSpinner.tsx mobile/src/components/AgentStateDot.tsx mobile/src/components/agent-monitoring-indicators.test.ts

Repository: stablyai/orca

Length of output: 5542


🌐 Web query:

React Native accessibility View accessibilityLabel accessible prop documentation

💡 Result:

In React Native, the accessible and accessibilityLabel props are fundamental accessibility controls used to make components discoverable and understandable by assistive technologies like screen readers [1][2]. accessible Prop When set to true, this prop indicates that a view is an accessibility element, making it discoverable by assistive technologies such as screen readers and hardware keyboards [1][3]. - Default Behavior: By default, all touchable elements (such as TouchableOpacity) are accessible [1][4]. - Platform Mapping: On Android, this translates to native focusable; on iOS, it translates to isAccessibilityElement [1][5]. - Important Note: Setting accessible={true} does not guarantee that the element will be focused by VoiceOver or TalkBack, as assistive technologies may override this for various reasons, such as grouping or hierarchy management [1][6]. accessibilityLabel Prop This prop provides a custom string that screen readers will verbalize when the element is selected [1][5]. - Best Practice: It is considered good practice to set an accessibilityLabel on any element marked as accessible to ensure users understand the purpose of the element [1]. - Default Behavior: If no accessibilityLabel is provided, React Native automatically constructs one by traversing the element's children and concatenating all Text node children, separated by spaces [1][3]. Example Usage Press me! In this example, the accessibilityLabel explicitly provides the text "Tap me!" for the screen reader, overriding the default behavior that would have used the text "Press me!" [1][6].

Citations:


Mark monitoring indicators as accessible.

Set accessible={true} on the AgentSpinner monitoring wrapper and accessible={state === 'monitoring'} on the AgentStateDot wrapper. Assert these props in agent-monitoring-indicators.test.ts.

📍 Affects 2 files
  • mobile/src/components/AgentSpinner.tsx#L50-L57 (this comment)
  • mobile/src/components/AgentStateDot.tsx#L50-L56

Source: MCP tools

}

if (status === 'working') {
const rotate = spinValue.interpolate({
inputRange: [0, 1],
Expand Down
14 changes: 12 additions & 2 deletions mobile/src/components/AgentStateDot.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect, useRef } from 'react'
import { Radio } from 'lucide-react-native'
import { Animated, Easing, StyleSheet, View } from 'react-native'
import type { AgentDotState } from '../worktree/agent-row-display'

Expand All @@ -7,13 +8,14 @@ import type { AgentDotState } from '../worktree/agent-row-display'
// emerald for 'done', red for blocked/waiting/interrupted (attention), neutral
// for idle. Distinct from the worktree-level AgentSpinner, which collapses the
// agent vocabulary into the 5-state rollup the sidebar dot uses.
const DOT_COLORS: Record<Exclude<AgentDotState, 'working'>, string> = {
const DOT_COLORS: Record<Exclude<AgentDotState, 'working' | 'monitoring'>, string> = {
done: '#10b981',
blocked: '#ef4444',
waiting: '#ef4444',
interrupted: '#ef4444',
idle: 'rgba(115,115,115,0.4)'
}
const WORKING_COLOR = '#eab308'

export function AgentStateDot({ state }: { state: AgentDotState }) {
const spinValue = useRef(new Animated.Value(0)).current
Expand Down Expand Up @@ -44,6 +46,14 @@ export function AgentStateDot({ state }: { state: AgentDotState }) {
)
}

if (state === 'monitoring') {
return (
<View style={styles.wrapper} accessibilityLabel="Monitoring background tasks">
<Radio size={10} color={WORKING_COLOR} />
</View>
)
}

return (
<View style={styles.wrapper}>
<View style={[styles.dot, { backgroundColor: DOT_COLORS[state] }]} />
Expand All @@ -59,7 +69,7 @@ const styles = StyleSheet.create({
height: 6,
borderRadius: 3,
borderWidth: 1.5,
borderColor: '#eab308',
borderColor: WORKING_COLOR,
borderTopColor: 'transparent'
}
})
19 changes: 18 additions & 1 deletion mobile/src/components/WorktreeListRow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,30 @@ describe('memoized worktree rows', () => {
await act(async () => {
renderer!.update(
createElement(WorktreeAgentRow, {
agent: agent({ state: 'done', updatedAt: 2_000 }),
agent: agent({ state: 'working', workingMode: 'monitoring', updatedAt: 2_000 }),
depth: 0,
now: 2_000,
unvisited: false
})
)
})
expect(agentStateDotRender).toHaveBeenCalledTimes(2)
expect(agentStateDotRender).toHaveBeenLastCalledWith({ state: 'monitoring' })
})

it('passes workspace monitoring mode to the status indicator', async () => {
await act(async () => {
renderer = create(
createElement(ListRowHarness, {
item: { ...baseItem, status: 'working', workingMode: 'monitoring' },
now: 2_000
})
)
})

expect(agentSpinnerRender).toHaveBeenLastCalledWith({
status: 'working',
workingMode: 'monitoring'
})
})
})
4 changes: 3 additions & 1 deletion mobile/src/components/WorktreeListRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { memo } from 'react'
import { Bell, ChevronDown, ChevronRight, GitBranch, GitPullRequest } from 'lucide-react-native'
import { Pressable, StyleSheet, Text, View } from 'react-native'
import type { RepoIcon } from '../../../src/shared/repo-icon'
import type { AgentWorkingMode } from '../../../src/shared/agent-status-types'
import type { RuntimeWorktreeAgentRow } from '../../../src/shared/runtime-types'
import { triggerMediumImpact } from '../platform/haptics'
import { colors, radii, spacing, typography } from '../theme/mobile-theme'
Expand Down Expand Up @@ -39,6 +40,7 @@ export type WorktreeListRowItem = {
lineageChildCount?: number
lineageCollapsed?: boolean
agents?: RuntimeWorktreeAgentRow[]
workingMode?: AgentWorkingMode
}

type WorktreeRollupStatus = 'working' | 'active' | 'permission' | 'done' | 'inactive'
Expand Down Expand Up @@ -97,7 +99,7 @@ function WorktreeListRowComponent<T extends WorktreeListRowItem>({
delayLongPress={400}
>
<View style={styles.indicatorCol}>
<AgentSpinner status={status} />
<AgentSpinner status={status} workingMode={item.workingMode} />
{item.unread && (
<Bell
size={10}
Expand Down
87 changes: 87 additions & 0 deletions mobile/src/components/agent-monitoring-indicators.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { createElement } from 'react'
import { act, create } from 'react-test-renderer'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { AgentSpinner } from './AgentSpinner'
import { AgentStateDot } from './AgentStateDot'

const DESKTOP_WORKING_COLOR = '#eab308'

type MonitoringTestRenderer = {
readonly root: {
findByType(type: string): { props: Record<string, unknown> }
}
unmount(): void
}

const { animationLoop, animationTiming, setValue } = vi.hoisted(() => ({
animationLoop: vi.fn(() => ({ start: vi.fn(), stop: vi.fn() })),
animationTiming: vi.fn(() => ({})),
setValue: vi.fn()
}))

vi.mock('lucide-react-native', () => ({ Radio: 'Radio' }))
vi.mock('react-native', () => ({
Animated: {
Value: function Value() {
return { interpolate: vi.fn(() => 'rotation'), setValue }
},
View: 'AnimatedView',
loop: animationLoop,
timing: animationTiming
},
Easing: { linear: 'linear' },
StyleSheet: { create: <T>(styles: T) => styles },
View: 'View'
}))

describe('mobile monitoring indicators', () => {
let renderer: MonitoringTestRenderer | null = null

beforeEach(() => {
animationLoop.mockClear()
animationTiming.mockClear()
setValue.mockClear()
})

afterEach(() => {
act(() => renderer?.unmount())
renderer = null
})

it('renders a static Radio for a monitoring agent', async () => {
await act(async () => {
renderer = create(createElement(AgentStateDot, { state: 'monitoring' }))
})

expect(renderer?.root.findByType('Radio').props).toMatchObject({
color: DESKTOP_WORKING_COLOR,
size: 10
})
expect(animationTiming).not.toHaveBeenCalled()
expect(animationLoop).not.toHaveBeenCalled()
})

it('renders a static Radio for an all-monitoring workspace', async () => {
await act(async () => {
renderer = create(
createElement(AgentSpinner, { status: 'working', workingMode: 'monitoring' })
)
})

expect(renderer?.root.findByType('Radio').props).toMatchObject({
color: DESKTOP_WORKING_COLOR,
size: 12
})
expect(animationTiming).not.toHaveBeenCalled()
expect(animationLoop).not.toHaveBeenCalled()
})

it('keeps the spinner fallback when workingMode is absent', async () => {
await act(async () => {
renderer = create(createElement(AgentSpinner, { status: 'working' }))
})

expect(animationTiming).toHaveBeenCalledOnce()
expect(animationLoop).toHaveBeenCalledOnce()
})
})
14 changes: 14 additions & 0 deletions mobile/src/session/use-mobile-native-chat-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,9 @@ describe('useMobileNativeChatController streaming scope', () => {
launchAgent: 'claude',
agentStatus: {
state: 'working',
workingMode: undefined as 'monitoring' | undefined,
agentType: 'claude',
lastAssistantMessage: 'Partial reply',
providerSession: { id: 'session-1' }
},
isActive: true
Expand All @@ -723,6 +725,7 @@ describe('useMobileNativeChatController streaming scope', () => {

beforeEach(() => {
viewMode.isTabChatView = () => true
workingTab.agentStatus.workingMode = undefined
act(() => {
renderer = create(createElement(Harness))
})
Expand All @@ -737,6 +740,7 @@ describe('useMobileNativeChatController streaming scope', () => {

it('holds the stream scope and liveness while the user peeks at the terminal', () => {
expect(controller?.showNativeChat).toBe(true)
expect(controller?.nativeChatAgentWorking).toBe(true)
const scopeKey = controller?.nativeChatStreamScopeKey
expect(scopeKey).toContain('session-1')
expect(controller?.nativeChatStreamLive).toBe(true)
Expand All @@ -750,6 +754,16 @@ describe('useMobileNativeChatController streaming scope', () => {
expect(controller?.nativeChatStreamLive).toBe(true)
})

it('treats passive monitoring as outside the foreground turn', () => {
workingTab.agentStatus.workingMode = 'monitoring'
act(() => renderer?.update(createElement(Harness)))

expect(controller?.nativeChatAgentWorking).toBe(false)
expect(controller?.nativeChatStreamLive).toBe(false)
expect(controller?.nativeChatStreamingText).toBeUndefined()
expect(controller?.nativeChatSessionOptions?.isWorking).toBe(false)
})

it('keeps the delayed-send route guard view-gated, unlike the stream scope', () => {
const before = answerSendArgs.at(-1)?.streamIdentity
expect(before).toBe(controller?.nativeChatStreamScopeKey)
Expand Down
9 changes: 6 additions & 3 deletions mobile/src/session/use-mobile-native-chat-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,14 @@ export function useMobileNativeChatController(args: {
transcriptSettled: nativeChatSession.status === 'ready'
})

const nativeChatStatus = activeChatResolution ? activeSessionTab?.agentStatus : null
const nativeChatAgentWorking = nativeChatStatus?.state === 'working'
const activeTabStatus = activeSessionTab?.agentStatus
const activeTabAgentWorking =
activeTabStatus?.state === 'working' && activeTabStatus.workingMode !== 'monitoring'
const nativeChatStatus = activeChatResolution ? activeTabStatus : null
const nativeChatAgentWorking = activeChatResolution != null && activeTabAgentWorking
// Deliberately not gated on the chat view being visible: the streaming gate
// has to tell "hidden mid-turn" from "the turn ended".
const nativeChatStreamLive = activeSessionTab?.agentStatus?.state === 'working'
const nativeChatStreamLive = activeTabAgentWorking
// Throttle the streaming bubble: OpenCode emits a status frame per streamed
// part, and each one re-renders and re-parses the whole accumulated markdown.
const nativeChatStreamingText = useThrottledLatestValue(
Expand Down
9 changes: 9 additions & 0 deletions mobile/src/worktree/agent-row-display.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ function row(overrides: Partial<RuntimeWorktreeAgentRow> = {}): RuntimeWorktreeA
describe('agentDotState', () => {
it('maps known states through and unknown to idle', () => {
expect(agentDotState(row({ state: 'working', updatedAt: 0 }), 0)).toBe('working')
expect(
agentDotState(row({ state: 'working', workingMode: 'monitoring', updatedAt: 0 }), 0)
).toBe('monitoring')
expect(agentDotState(row({ state: 'blocked', updatedAt: 0 }), 0)).toBe('blocked')
expect(agentDotState(row({ state: 'waiting', updatedAt: 0 }), 0)).toBe('waiting')
expect(agentDotState(row({ state: 'done', updatedAt: 0 }), 0)).toBe('done')
Expand Down Expand Up @@ -65,6 +68,12 @@ describe('agentDisplayLabel', () => {
expect(agentDisplayLabel(row({ state: 'working', prompt: '', updatedAt: 0 }), 0)).toBe(
'Working'
)
expect(
agentDisplayLabel(
row({ state: 'working', workingMode: 'monitoring', prompt: '', updatedAt: 0 }),
0
)
).toBe('Monitoring background tasks')
})

it('falls back to the decayed state label when stale', () => {
Expand Down
19 changes: 16 additions & 3 deletions mobile/src/worktree/agent-row-display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,34 @@ export const AGENT_STATUS_STALE_AFTER_MS = 30 * 60 * 1000
// Mirrors the desktop AgentStateDot vocabulary. The wire `state` is the agent
// status state; 'blocked'/'waiting' read as attention states, 'done' as
// complete, everything else idle.
export type AgentDotState = 'working' | 'blocked' | 'waiting' | 'done' | 'idle' | 'interrupted'
export type AgentDotState =
| 'working'
| 'monitoring'
| 'blocked'
| 'waiting'
| 'done'
| 'idle'
| 'interrupted'

export function agentDotState(
row: Pick<RuntimeWorktreeAgentRow, 'state' | 'interrupted' | 'updatedAt'>,
row: Pick<RuntimeWorktreeAgentRow, 'state' | 'workingMode' | 'interrupted' | 'updatedAt'>,
now: number
): AgentDotState {
if (row.interrupted) {
return 'interrupted'
}
switch (row.state) {
case 'working':
case 'blocked':
case 'waiting':
// Why: an agent that exits without a final report would otherwise read as
// active forever. Decay a stale active state to idle, matching desktop's
// renderer-side staleness decay (worktree-agent-rows.ts).
return now - row.updatedAt > AGENT_STATUS_STALE_AFTER_MS ? 'idle' : row.state
case 'working':
if (now - row.updatedAt > AGENT_STATUS_STALE_AFTER_MS) {
return 'idle'
}
return row.workingMode === 'monitoring' ? 'monitoring' : 'working'
case 'done':
return 'done'
}
Expand All @@ -37,6 +48,8 @@ export function agentStateLabel(state: AgentDotState): string {
switch (state) {
case 'working':
return 'Working'
case 'monitoring':
return 'Monitoring background tasks'
case 'blocked':
return 'Blocked'
case 'waiting':
Expand Down
2 changes: 2 additions & 0 deletions mobile/src/worktree/workspace-list-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ExecutionHostId } from '../../../src/shared/execution-host'
import type { AgentWorkingMode } from '../../../src/shared/agent-status-types'
import type { RuntimeWorktreeAgentRow } from '../../../src/shared/runtime-types'

export type Worktree = {
Expand Down Expand Up @@ -45,6 +46,7 @@ export type Worktree = {
linkedGitLabIssue?: number | null
comment?: string
status?: 'working' | 'active' | 'permission' | 'done' | 'inactive'
workingMode?: AgentWorkingMode
agents?: RuntimeWorktreeAgentRow[]
}

Expand Down
Loading