Skip to content
Open
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
1 change: 1 addition & 0 deletions changes/459.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**Chat shows which actions are waiting for your approval.** The file or browser step shows what Sentient would do and updates when it finishes. Declined, failed and interrupted steps show their own status.
32 changes: 15 additions & 17 deletions desktop/src/features/chat/ToolCallCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IconAlertTriangle, IconCheck, IconChevronRight, IconClockHour4, IconHandFinger, IconShieldQuestion, IconX } from '@tabler/icons-react'
import { IconAlertTriangle, IconChevronRight, IconClockHour4, IconHandFinger } from '@tabler/icons-react'
import { AnimatePresence, motion } from 'motion/react'
import { useState } from 'react'
import { JsonView, Spinner } from '@/components/ui'
import { JsonView } from '@/components/ui'
import type { ApprovalView, ToolCallView } from '@/lib/chatFold'
import type { ApprovalDecision } from '@/lib/types'
import { cn, formatDuration } from '@/lib/utils'
Expand All @@ -14,7 +14,7 @@ import { TerminalCard } from './cards/TerminalCard'
import { asHandOff, HandOffCard } from './HandOffCard'
import { UndoCard } from './UndoCard'
import { IMAGE_FILE_RE, openOutputFile, outputPath } from './files'
import { argsPreview, toolMeta } from './toolMeta'
import { argsPreview, toolMeta, toolStatusLabel } from './toolMeta'

function GenericToolCard({
tool,
Expand All @@ -33,9 +33,15 @@ function GenericToolCard({
const running = tool.status === 'running'
const failed = tool.status === 'error'
const denied = tool.status === 'denied'
const preview = argsPreview(tool.arguments)
const fileName = tool.status === 'awaiting_approval' && tool.name === 'file_write' && typeof tool.arguments?.name === 'string'
? tool.arguments.name.trim()
: ''
const preview = fileName || argsPreview(tool.arguments)
const hasResult = tool.result !== undefined && tool.result !== null && tool.result !== ''
const handOff = asHandOff(tool.result)
const label = fileName
? 'Would write'
: toolStatusLabel(tool.name, tool.status) ?? (running ? meta.running : handOff ? 'Prepared for you' : meta.done)

return (
<div className="space-y-2">
Expand All @@ -60,7 +66,7 @@ function GenericToolCard({
) : (
<>
<span className={cn('shrink-0 font-medium', running ? 'text-fg-muted' : 'text-fg')}>
{running ? meta.running : handOff ? 'Prepared for you' : meta.done}
{label}
</span>
{preview && <span className="min-w-0 flex-1 truncate font-mono text-xs text-fg-subtle">{preview}</span>}
{!preview && <span className="flex-1" />}
Expand All @@ -72,22 +78,14 @@ function GenericToolCard({
<span className="flex size-4 shrink-0 items-center justify-center">
{running && tool.undo?.status === 'waiting' ? (
<IconClockHour4 size={14} className="text-accent" />
) : running ? (
<Spinner size={13} className="text-fg-subtle" />
) : tool.status === 'awaiting_approval' ? (
<IconShieldQuestion size={14} className="text-warning" />
) : failed ? (
<IconX size={14} className="text-danger" />
) : denied ? (
<StatusGlyph status="denied" />
) : handOff ? (
) : tool.status === 'done' && handOff ? (
<IconHandFinger size={14} className="text-accent" />
) : problem ? (
) : tool.status === 'done' && problem ? (
<span title={problem} className="flex">
<IconAlertTriangle size={14} className="text-warning" />
</span>
) : (
<IconCheck size={14} className="text-success" />
<StatusGlyph status={tool.status} />
)}
</span>
<IconChevronRight size={14} className={cn('shrink-0 text-fg-faint transition-transform duration-150', open && 'rotate-90')} />
Expand Down Expand Up @@ -116,7 +114,7 @@ function GenericToolCard({
<div className={cn('mb-1 text-2xs font-medium uppercase tracking-wide', failed ? 'text-danger' : 'text-fg-subtle')}>
{failed ? 'Error' : 'Result'}
</div>
{running ? (
{running || tool.status === 'awaiting_result' ? (
<div className="text-xs text-fg-subtle">Waiting for result…</div>
) : !hasResult ? (
<div className="text-xs text-fg-subtle">No result</div>
Expand Down
20 changes: 13 additions & 7 deletions desktop/src/features/chat/cards/BrowserCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { api } from '@/lib/api'
import type { ApprovalView, ToolCallView } from '@/lib/chatFold'
import { cn, truncate } from '@/lib/utils'
import { outputPath } from '../files'
import { toolMeta } from '../toolMeta'
import { asRecord, DeclinedText, hostOf, prettyUrl, refLabel, Shimmer, StatusGlyph } from './bits'
import { toolMeta, toolStatusLabel } from '../toolMeta'
import { actionTarget, asRecord, DeclinedText, hostOf, prettyUrl, refLabel, Shimmer, StatusGlyph } from './bits'

export const isBrowserTool = (name: string) => name.startsWith('browser_')

Expand All @@ -18,7 +18,12 @@ interface BrowserResult {
element?: string
}

function stepLabel(t: ToolCallView): string {
function stepLabel(t: ToolCallView, approval?: ApprovalView): string {
const label = toolStatusLabel(t.name, t.status)
if (label) {
const target = t.status === 'awaiting_approval' && t.name === 'browser_click' ? actionTarget(t, approval) : null
return target ? `${label} “${truncate(target, 48)}”` : label
}
const a = t.arguments as Record<string, unknown>
const r = asRecord<BrowserResult>(t.result)
const running = t.status === 'running'
Expand Down Expand Up @@ -50,7 +55,7 @@ function stepLabel(t: ToolCallView): string {
export function BrowserCard({ tools, approvals = [] }: { tools: ToolCallView[]; approvals?: ApprovalView[] }) {
const liveFrame = useBrowserView((s) => s.frame)
const running = tools.some((t) => t.status === 'running' || t.status === 'awaiting_approval')
const allDeclined = tools.length > 0 && tools.every((t) => t.status === 'denied')
const used = tools.some((t) => t.status === 'done')
const results = tools.map((t) => asRecord<BrowserResult>(t.result))
const progressFrame = [...tools].reverse().find((t) => t.progress?.frame)?.progress?.frame
const shot = [...results].reverse().find((r) => r?.file)?.file
Expand Down Expand Up @@ -96,7 +101,7 @@ export function BrowserCard({ tools, approvals = [] }: { tools: ToolCallView[];
<div className="flex min-w-0 flex-1 flex-col py-0.5">
<div className="flex items-center gap-2">
<span className="text-sm font-medium text-fg">
{running ? <Shimmer>Using the browser</Shimmer> : allDeclined ? 'Browser step not done' : 'Used the browser'}
{running ? <Shimmer>Using the browser</Shimmer> : used ? 'Used the browser' : 'Browser'}
</span>
<span className="text-2xs text-fg-faint">
{tools.length} {tools.length === 1 ? 'step' : 'steps'}
Expand All @@ -112,13 +117,14 @@ export function BrowserCard({ tools, approvals = [] }: { tools: ToolCallView[];
{hidden > 0 && <li className="pl-5 text-2xs text-fg-faint">{hidden} earlier steps</li>}
{steps.map((t) => {
const meta = toolMeta(t.name)
const approval = approvals.find((a) => a.callId === t.callId)
return (
<li key={t.callId} className="flex items-center gap-2 text-xs">
<meta.icon size={13} className={cn('shrink-0', t.status === 'error' ? 'text-danger' : t.status === 'denied' ? 'text-warning' : 'text-fg-subtle')} />
{t.status === 'denied' ? (
<DeclinedText tool={t} approval={approvals.find((a) => a.callId === t.callId)} className="min-w-0 flex-1" />
<DeclinedText tool={t} approval={approval} className="min-w-0 flex-1" />
) : (
<span className={cn('min-w-0 flex-1 truncate', t.status === 'running' ? 'text-fg' : 'text-fg-muted')}>{stepLabel(t)}</span>
<span className={cn('min-w-0 flex-1 truncate', t.status === 'running' ? 'text-fg' : 'text-fg-muted')}>{stepLabel(t, approval)}</span>
)}
<StatusGlyph status={t.status} size={12} />
</li>
Expand Down
5 changes: 3 additions & 2 deletions desktop/src/features/chat/cards/CodeRunCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { wasDenied, type ToolCallView } from '@/lib/chatFold'
import type { SandboxResult } from '@/lib/types'
import { cn, formatDuration } from '@/lib/utils'
import { fileBase, IMAGE_FILE_RE, openOutputFile, outputPath } from '../files'
import { toolStatusLabel } from '../toolMeta'
import { asRecord, DeclinedText, Shimmer, StatTiles, StatusGlyph } from './bits'

/** `execute_code` (§11): purpose, live output, result, created files, and the code folded away. */
Expand All @@ -31,7 +32,7 @@ export function CodeRunCard({ tool }: { tool: ToolCallView }) {
if (running && output.current) output.current.scrollTop = output.current.scrollHeight
}, [running, stdout, stderr])

const title = args.purpose?.trim() || 'Ran some code'
const title = args.purpose?.trim() || (tool.status === 'done' ? 'Ran some code' : 'Code')
const subline = waiting
? 'Waiting for your OK before running'
: running
Expand All @@ -40,7 +41,7 @@ export function CodeRunCard({ tool }: { tool: ToolCallView }) {
? 'Not run, so nothing changed'
: failed
? `Stopped with a problem${duration ? ` after ${formatDuration(duration)}` : ''}`
: `Finished${duration ? ` in ${formatDuration(duration)}` : ''}`
: toolStatusLabel(tool.name, tool.status) ?? `Finished${duration ? ` in ${formatDuration(duration)}` : ''}`
const backend = res?.backend
const hasResult = res && res.result !== null && res.result !== undefined && res.result !== ''
const showOutput = !!(stdout || stderr)
Expand Down
18 changes: 12 additions & 6 deletions desktop/src/features/chat/cards/SubagentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ import { asRecord, DeclinedText, Shimmer, StatusGlyph } from './bits'

export const isSubagentTool = (name: string) => name === 'delegate_task' || name === 'delegate_tasks'

function statusFromTool(tool: ToolCallView): SubagentStatus {
type HelperStatus = SubagentStatus | 'awaiting_result'

function statusFromTool(tool: ToolCallView): HelperStatus {
if (tool.status === 'running' || tool.status === 'awaiting_approval') return 'running'
if (tool.status === 'awaiting_result') return 'awaiting_result'
if (tool.status === 'error') return 'error'
if (tool.status === 'denied') return 'cancelled'
if (tool.status === 'denied' || tool.status === 'cancelled') return 'cancelled'
return 'completed'
}

Expand Down Expand Up @@ -66,7 +69,7 @@ function HelperRow({
goal: string
background: boolean
subagentId?: string
status: SubagentStatus
status: HelperStatus
summary: string | null
error: string | null
messages: string[]
Expand All @@ -90,7 +93,9 @@ function HelperRow({
? `Done${steps ? ` after ${steps} ${steps === 1 ? 'step' : 'steps'}` : ''}`
: status === 'cancelled'
? 'Stopped'
: (sub.data?.error ?? error ?? 'Ran into a problem')
: status === 'awaiting_result'
? 'Waiting for result'
: (sub.data?.error ?? error ?? 'Ran into a problem')

return (
<div className={cn(!nested && 'overflow-hidden rounded-xl border border-border bg-surface')}>
Expand Down Expand Up @@ -168,6 +173,7 @@ function SubagentGroup({ tool }: { tool: ToolCallView }) {
? ((raw as { results: DelegateResult[] }).results)
: []
const fallback = statusFromTool(tool)
const finished = fallback === 'completed'
const done = list.filter((r) => r?.status === 'completed').length
return (
<div className="overflow-hidden rounded-xl border border-border bg-surface">
Expand All @@ -177,9 +183,9 @@ function SubagentGroup({ tool }: { tool: ToolCallView }) {
</div>
<div className="min-w-0 flex-1">
<div className="text-sm font-medium text-fg">
{fallback === 'running' ? <Shimmer>{`${tasks.length} helpers working in parallel`}</Shimmer> : `${tasks.length} helpers worked in parallel`}
{fallback === 'running' ? <Shimmer>{`${tasks.length} helpers working in parallel`}</Shimmer> : `${tasks.length} helpers${finished ? ' worked in parallel' : ''}`}
</div>
{fallback !== 'running' && <div className="text-xs text-fg-subtle">{done || tasks.length} finished</div>}
{finished && <div className="text-xs text-fg-subtle">{done || tasks.length} finished</div>}
</div>
</div>
<div className="divide-y divide-border border-t border-border">
Expand Down
3 changes: 2 additions & 1 deletion desktop/src/features/chat/cards/TerminalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { wasDenied, type ToolCallView } from '@/lib/chatFold'
import type { TerminalResult } from '@/lib/types'
import { cn, formatDuration } from '@/lib/utils'
import { openOutputFile } from '../files'
import { toolStatusLabel } from '../toolMeta'
import { asRecord, DeclinedText, Shimmer, StatusGlyph } from './bits'

/** `terminal_run` (§18): the command, its folder, live output, exit code and a Stop button while it runs. */
Expand Down Expand Up @@ -50,7 +51,7 @@ export function TerminalCard({ tool }: { tool: ToolCallView }) {
? 'Stopped because it took too long'
: res && res.exit_code !== null
? `${res.exit_code === 0 ? 'Finished' : `Finished with exit code ${res.exit_code}`}${duration ? ` in ${formatDuration(duration)}` : ''}`
: null
: toolStatusLabel(tool.name, tool.status)

return (
<div className={cn('overflow-hidden rounded-xl border bg-surface', failed ? 'border-danger/30' : 'border-border')}>
Expand Down
5 changes: 3 additions & 2 deletions desktop/src/features/chat/cards/bits.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IconCheck, IconHandStop, IconShieldQuestion, IconX } from '@tabler/icons-react'
import { IconCheck, IconClockHour4, IconHandStop, IconShieldQuestion, IconX } from '@tabler/icons-react'
import type { ReactNode } from 'react'
import { Spinner } from '@/components/ui'
import { wasUndone, type ToolCallView, type ToolStatus } from '@/lib/chatFold'
Expand Down Expand Up @@ -80,9 +80,10 @@ export function Shimmer({ children, className }: { children: ReactNode; classNam
)
}

export function StatusGlyph({ status, size = 14 }: { status: ToolStatus | 'cancelled'; size?: number }) {
export function StatusGlyph({ status, size = 14 }: { status: ToolStatus; size?: number }) {
if (status === 'running') return <Spinner size={size - 1} className="text-fg-subtle" />
if (status === 'awaiting_approval') return <IconShieldQuestion size={size} className="text-warning" />
if (status === 'awaiting_result') return <IconClockHour4 size={size} className="text-fg-subtle" />
if (status === 'error') return <IconX size={size} className="text-danger" />
if (status === 'denied') return <IconHandStop size={size} className="text-warning" />
if (status === 'cancelled') return <IconX size={size} className="text-fg-subtle" />
Expand Down
9 changes: 9 additions & 0 deletions desktop/src/features/chat/toolMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
IconWorld,
type Icon
} from '@tabler/icons-react'
import type { ToolStatus } from '@/lib/chatFold'
import { humanize, truncate } from '@/lib/utils'

interface ToolMeta {
Expand Down Expand Up @@ -145,6 +146,14 @@ export function askingLabel(name: string): string | null {
return KNOWN[name] && !KNOWN[name].would ? null : wouldLabel(name)
}

/** Wording for steps waiting for an answer or ending without success. */
export function toolStatusLabel(name: string, status: ToolStatus): string | undefined {
if (status === 'awaiting_approval') return askingLabel(name) ?? 'Waiting for your answer'
if (status === 'awaiting_result') return 'Waiting for result'
if (status === 'error') return 'Step failed'
if (status === 'cancelled') return 'Step interrupted'
}

export function toolMeta(name: string): ToolMeta {
const known = KNOWN[name]
if (known) return known
Expand Down
Loading
Loading