mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
* feat(mobile): show only the open tab, with a tab count and a sheet of every tab The session bar shows the open tab at full width, then a tab count cell and a + cell. The count opens a sheet of every tab grouped Needs you / Working / Everything else; tapping the tab opens its actions; swiping it steps between tabs; + opens a new tab sheet with agents as tiles. The header subtitle shows the branch. Brings back #40592 on current main. * fix(mobile): don't switch tabs when a bar swipe is interrupted
123 lines
5.0 KiB
TypeScript
123 lines
5.0 KiB
TypeScript
import type { RuntimeWorktreeAgentRow } from '../../../src/shared/runtime-types'
|
||
import { isAgentStatusFresh } from '../../../src/shared/agent-status/contracts/agent-status-freshness'
|
||
import { agentVerdictDisplayMark } from '../../../src/shared/agent-status/lifecycle/agent-main-agent-verdict'
|
||
import { resolveDecayedAgentRowState } from '../../../src/shared/agent-status/presentation/agent-row-decay-state'
|
||
import { getAgentRowPrimaryText } from '../../../src/shared/agent-status/presentation/agent-row-primary-text'
|
||
import type { AgentListStatus } from '../../../src/shared/agent-status/presentation/agent-list-status'
|
||
import { translate } from '../i18n/mobile-i18n'
|
||
|
||
// Desktop AgentStateDot's vocabulary.
|
||
export type AgentDotState = AgentListStatus
|
||
|
||
// A session tab's AgentStatusEntry leaves `interrupted` optional; worktree rows always send it.
|
||
type AgentRowVerdictSource = Pick<RuntimeWorktreeAgentRow, 'state' | 'mainAgent'> & {
|
||
interrupted?: boolean
|
||
}
|
||
|
||
export function agentDotState(
|
||
row: AgentRowVerdictSource &
|
||
Pick<RuntimeWorktreeAgentRow, 'workingMode' | 'hasLivePty'> &
|
||
Parameters<typeof isAgentStatusFresh>[0],
|
||
now: number
|
||
): AgentDotState {
|
||
const mark = agentVerdictDisplayMark(row)
|
||
if (mark) {
|
||
return mark
|
||
}
|
||
if (row.state === 'done') {
|
||
return 'done'
|
||
}
|
||
// Decay stale active states like desktop: a live terminal can't prove the agent ended, so it reads unverifiable.
|
||
if (!isAgentStatusFresh(row, now)) {
|
||
return resolveDecayedAgentRowState(row, row.hasLivePty === true)
|
||
}
|
||
if (row.state === 'working') {
|
||
return row.workingMode === 'monitoring' ? 'monitoring' : 'working'
|
||
}
|
||
return row.state === 'blocked' || row.state === 'waiting' ? row.state : 'idle'
|
||
}
|
||
|
||
// Mirrors desktop agentStateLabel.
|
||
export function agentStateLabel(state: AgentDotState): string {
|
||
switch (state) {
|
||
case 'working':
|
||
return translate('worktree.agentRowDisplay.working', 'Working')
|
||
case 'monitoring':
|
||
return translate('worktree.agentRowDisplay.monitoring', 'Monitoring background tasks')
|
||
case 'blocked':
|
||
return translate('worktree.agentRowDisplay.blocked', 'Blocked')
|
||
case 'waiting':
|
||
return translate('worktree.agentRowDisplay.waiting', 'Waiting for input')
|
||
case 'interrupted':
|
||
return translate('worktree.agentRowDisplay.interrupted', 'Interrupted')
|
||
case 'failed':
|
||
return translate('worktree.agentRowDisplay.failed', 'Failed')
|
||
case 'unconfirmed':
|
||
return translate('worktree.agentRowDisplay.unconfirmed', 'Couldn’t confirm')
|
||
case 'done':
|
||
return translate('worktree.agentRowDisplay.done', 'Done')
|
||
case 'idle':
|
||
return translate('worktree.agentRowDisplay.idle', 'Idle')
|
||
case 'unverifiable':
|
||
return translate('worktree.agentRowDisplay.unverifiable', 'No recent update')
|
||
case 'permission':
|
||
return translate('worktree.agentRowDisplay.permission', 'Needs attention')
|
||
}
|
||
}
|
||
|
||
// Match desktop's compact row: name then message, else message → prompt → state; Stop leads while ending the turn.
|
||
export function agentDisplayLabel(row: RuntimeWorktreeAgentRow, now: number): string {
|
||
const name = row.conversationName?.trim()
|
||
const message = row.lastAssistantMessage?.trim()
|
||
if (row.state === 'working' && row.mainAgent?.stopping === true) {
|
||
const stopping = translate('worktree.agentRowDisplay.stopping', 'Stopping…')
|
||
return name ? `${stopping} · ${name}` : stopping
|
||
}
|
||
if (name) {
|
||
return message ? `${name} · ${message}` : name
|
||
}
|
||
if (message) {
|
||
return message
|
||
}
|
||
const prompt = getAgentRowPrimaryText({ prompt: row.prompt })
|
||
if (prompt) {
|
||
return prompt
|
||
}
|
||
return agentStateLabel(agentDotState(row, now))
|
||
}
|
||
|
||
// Mirror desktop lastEnteredDoneAt: date main-agent failures independently while subagents remain active.
|
||
export function agentRowTimeAt(
|
||
row: AgentRowVerdictSource & Pick<RuntimeWorktreeAgentRow, 'stateStartedAt'>
|
||
): number {
|
||
if (row.state !== 'done' && row.mainAgent && agentVerdictDisplayMark(row) === 'failed') {
|
||
return row.mainAgent.stateStartedAt
|
||
}
|
||
return row.stateStartedAt
|
||
}
|
||
|
||
export function formatTimeAgo(ts: number, now: number): string {
|
||
const delta = now - ts
|
||
if (delta < 60_000) {
|
||
return translate('worktree.agentRowDisplay.justNow', 'just now')
|
||
}
|
||
const minutes = Math.max(0, Math.floor(delta / 60_000))
|
||
if (minutes < 60) {
|
||
const count = minutes
|
||
return count === 1
|
||
? translate('worktree.agentRowDisplay.minutes_one', '{{count}}m', { count })
|
||
: translate('worktree.agentRowDisplay.minutes_other', '{{count}}m', { count })
|
||
}
|
||
const hours = Math.floor(minutes / 60)
|
||
if (hours < 24) {
|
||
const count = hours
|
||
return count === 1
|
||
? translate('worktree.agentRowDisplay.hours_one', '{{count}}h', { count })
|
||
: translate('worktree.agentRowDisplay.hours_other', '{{count}}h', { count })
|
||
}
|
||
const count = Math.floor(hours / 24)
|
||
return count === 1
|
||
? translate('worktree.agentRowDisplay.days_one', '{{count}}d', { count })
|
||
: translate('worktree.agentRowDisplay.days_other', '{{count}}d', { count })
|
||
}
|