@gemies/sdk 10.3.0 → 10.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,65 @@
1
1
  # @gemies/sdk
2
2
 
3
+ ## 10.5.0
4
+
5
+ ### A coding agent's work, as one row, with a command's output
6
+
7
+ A turn in which a coding agent on the person's computer (Codex, Claude Code, OpenCode) used tools
8
+ now draws ONE work row, "Worked for 12s · 5 steps", closed until pressed (`AgentWork`; the pure
9
+ model is `buildAgentWork`, exported from `@gemies/sdk/model`). Open, each step is a line: its glyph,
10
+ what it is (the command, the path), where it stands (running, done, failed, declined, stopped) and
11
+ how long it took. Domain cards (weather, charts…) and a model's own tools draw as they did; only an
12
+ external agent's steps (`ext_…` call ids) are grouped.
13
+
14
+ A command's line opens to its output (`CommandOutput`): monospace, terminal escapes removed, tail
15
+ following with "Jump to latest" once the reader scrolls up, "Earlier output not shown" when it was
16
+ cut to its tail, and Copy. A running command's output is followed live on the new realtime topic
17
+ `step-output:<conversation>:<call>` (`useStepOutput`, the `step.output` signal) **only while its line
18
+ is open**; a closed line receives its status alone, and a finished command shows the output stored
19
+ with it, so it reads the same after a reload.
20
+
21
+ `useRealtimeTopic` takes the signal `type` it listens for (default `agent.activity`). Needs an API
22
+ that carries command output (this release's `@alia/api`); against an older API the steps are drawn
23
+ without output. New words: `work.*` (en, es).
24
+
25
+ An edit step whose call carries the files it changed opens the diff viewer (10.2.0) on that step's
26
+ files; the turn's "N files changed" chip stays, opening it on all of them.
27
+
28
+ ## 10.4.0
29
+
30
+ ### Richer answers to a coding CLI's permission questions
31
+
32
+ A coding CLI (ADR 0043 §5) asks to run something on the person's computer and the turn waits. The
33
+ question now offers more than allow and deny, and shows in two places that answer together.
34
+
35
+ - **Decisions.** `ApprovalDecision` is `allow`, `allow_session` (this tool on this exact path or
36
+ URL, for the rest of the conversation's session; offered only where the server can scope it, so
37
+ not for shell commands today), `deny` and `cancel` (deny, and stop the turn).
38
+ A denial can carry `feedback`, words the agent is told. When the agent supplies its own options
39
+ (`ApprovalOption`), their ids and labels are shown and sent back unchanged (`optionId`); the
40
+ built-in ones are named in English and Spanish (`chat.approval.option.*`). Every question can be
41
+ declined.
42
+ - **In the thread and above the composer.** The timeline's card lists the answers; the composer docks
43
+ a compact `ApprovalBar` (who is waiting, what they would run, the answers), and on web `Y` approves,
44
+ `A` allows for the session and `N` declines, once per press, only on the chat on screen and except
45
+ while typing. Both answer through
46
+ one `useApprovalActions`, so an answer is sent once however many places show the question.
47
+ - **A reply declines.** While a question waits, text typed in the composer and sent declines it and
48
+ goes to the agent as the feedback. The field's placeholder and the bar say so; Stop gives way to
49
+ send while there are words to send, and comes back when there are none.
50
+ - **Nothing stays open.** When a turn ends — answered, stopped, failed, the connection lost — every
51
+ question still waiting is settled (`ended`, or `cancel` when the person stopped it), so no card
52
+ stays pressable for a request nobody waits on. A question answered by the person's earlier
53
+ "allow for this session" reads as such (`auto`).
54
+ - **Host.** `onApprovalDecision(requestId, agentId, decision, details?)` takes the wider decision
55
+ and `{ optionId, feedback }`; it rejects with `ApprovalExpiredError` for a question no longer open
56
+ (a 404, or a 409 for one answered differently elsewhere). New optional `listApprovalGrants` and
57
+ `revokeApprovalGrant` let the thread list what was allowed for the session and take each back;
58
+ without them nothing is listed. A host written against 10.3 keeps compiling and carries the wider
59
+ decisions to Gemies as they are; it forwards no `details` until it takes them.
60
+ - `chat.approval.allow` and `chat.approval.deny` are gone (use `chat.approval.option.allow` and
61
+ `chat.approval.option.deny`); `stillPending` is gone, since a new turn starts with none.
62
+
3
63
  ## 10.3.0
4
64
 
5
65
  ### Chat streams resume after a dropped connection
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gemies/sdk",
3
- "version": "10.3.0",
3
+ "version": "10.5.0",
4
4
  "description": "The Gemies SDK: the conversation runtime, chat UI, voice calls and dictation for Oxy apps that talk to a gemie",
5
5
  "main": "src/index.ts",
6
6
  "react-native": "src/index.ts",
@@ -0,0 +1,131 @@
1
+ import { Button } from '@oxy.so/bloom/button';
2
+ import { createTokenStyles } from '@oxy.so/bloom/theme';
3
+ import { Text } from '@oxy.so/bloom/typography';
4
+ import React, { useMemo } from 'react';
5
+ import { Platform, View } from 'react-native';
6
+ import {
7
+ APPROVAL_SHORTCUT_KEYS,
8
+ type ApprovalShortcutActions,
9
+ useApprovalShortcuts,
10
+ } from '../hooks/useApprovalShortcuts';
11
+ import { useLabels } from '../lib/labels';
12
+ import {
13
+ approvalOptionLabel,
14
+ optionOfKind,
15
+ orderedApprovalOptions,
16
+ type ApprovalDecision,
17
+ } from '../runtime/approvals';
18
+ import type { ApprovalActions } from '../runtime/use-approval-actions';
19
+
20
+ const SHORTCUT_OF: Partial<Record<ApprovalDecision, string>> = {
21
+ allow: APPROVAL_SHORTCUT_KEYS.approve,
22
+ allow_session: APPROVAL_SHORTCUT_KEYS.approveForSession,
23
+ deny: APPROVAL_SHORTCUT_KEYS.decline,
24
+ };
25
+
26
+ /**
27
+ * The CLI's question, compact, above the composer where the person is about to type (ADR 0043 §5):
28
+ * who asks and what it would run, the answers, and — said plainly — that writing a reply below
29
+ * declines it and tells the agent why. On web the keys answer too (`useApprovalShortcuts`).
30
+ *
31
+ * The thread shows the same question as a card in the timeline; both answer through the same
32
+ * actions, so one answered here is answered there.
33
+ */
34
+ export const ApprovalBar = React.memo(function ApprovalBar({
35
+ approvals,
36
+ isFocused = true,
37
+ }: {
38
+ approvals: ApprovalActions;
39
+ /** False for a chat kept mounted under another screen: it must not hear the keyboard. */
40
+ isFocused?: boolean;
41
+ }) {
42
+ const { t } = useLabels();
43
+ const styles = useStyles();
44
+ const { pending: entry, decide, sending, failed, canAnswer } = approvals;
45
+ const busy = entry !== undefined && sending.has(entry.requestId);
46
+
47
+ const shortcuts = useMemo<ApprovalShortcutActions | undefined>(() => {
48
+ if (!entry || !canAnswer || busy || !isFocused) return undefined;
49
+ const answer = (kind: ApprovalDecision) => {
50
+ const option = optionOfKind(entry, kind);
51
+ return option ? () => void decide(entry, kind, { optionId: option.id }) : undefined;
52
+ };
53
+ return {
54
+ approve: answer('allow'),
55
+ approveForSession: answer('allow_session'),
56
+ // The way out is a no: declining, or stopping when that is all the question offers.
57
+ decline: answer('deny') ?? answer('cancel'),
58
+ };
59
+ }, [entry, canAnswer, busy, decide, isFocused]);
60
+ useApprovalShortcuts(shortcuts);
61
+
62
+ if (!entry) return null;
63
+ const waiting = approvals.entries.filter((e) => e.outcome === 'pending').length;
64
+ const hasKeys = Platform.OS === 'web' && isFocused;
65
+
66
+ return (
67
+ <View
68
+ style={styles.bar}
69
+ accessibilityRole="alert"
70
+ accessibilityLiveRegion="polite"
71
+ aria-live="polite"
72
+ >
73
+ <View style={styles.text}>
74
+ <Text style={styles.title} numberOfLines={1}>
75
+ {t('chat.approval.bar.title', { agent: approvals.agentName, tool: entry.tool })}
76
+ {waiting > 1 ? ` · ${t('chat.approval.bar.more', { count: waiting - 1 })}` : ''}
77
+ </Text>
78
+ {entry.summary ? (
79
+ <Text style={styles.summary} numberOfLines={2}>
80
+ {entry.summary}
81
+ </Text>
82
+ ) : null}
83
+ <Text style={styles.hint}>
84
+ {failed.has(entry.requestId)
85
+ ? t('chat.approval.sendFailed')
86
+ : t('chat.approval.bar.replyHint', { agent: approvals.agentName })}
87
+ </Text>
88
+ </View>
89
+ {canAnswer && !busy ? (
90
+ <View style={styles.actions}>
91
+ {orderedApprovalOptions(entry.options).map((option) => (
92
+ <Button
93
+ key={option.id}
94
+ size="xs"
95
+ appearance={option.kind === 'allow' ? 'solid' : 'subtle'}
96
+ tone={option.kind === 'cancel' ? 'danger' : undefined}
97
+ onPress={() => void decide(entry, option.kind, { optionId: option.id })}
98
+ trailing={
99
+ hasKeys && SHORTCUT_OF[option.kind] && option.label === undefined ? (
100
+ <Text style={styles.key}>{SHORTCUT_OF[option.kind]}</Text>
101
+ ) : undefined
102
+ }
103
+ >
104
+ {approvalOptionLabel(option, t)}
105
+ </Button>
106
+ ))}
107
+ </View>
108
+ ) : null}
109
+ </View>
110
+ );
111
+ });
112
+
113
+ const useStyles = createTokenStyles((t) => ({
114
+ bar: {
115
+ flexDirection: 'row',
116
+ flexWrap: 'wrap',
117
+ alignItems: 'center',
118
+ gap: 8,
119
+ marginBottom: 8,
120
+ paddingHorizontal: 12,
121
+ paddingVertical: 8,
122
+ borderRadius: 16,
123
+ backgroundColor: t.popover,
124
+ },
125
+ text: { flexGrow: 1, flexShrink: 1, flexBasis: 200, gap: 2 },
126
+ title: { fontSize: 14, fontWeight: 600, color: t.foreground, lineHeight: 20 },
127
+ summary: { fontSize: 13, color: t.foreground, lineHeight: 18, fontFamily: 'monospace' },
128
+ hint: { fontSize: 12, color: t.mutedForeground, lineHeight: 16 },
129
+ actions: { flexDirection: 'row', flexWrap: 'wrap', gap: 6 },
130
+ key: { fontSize: 11, color: t.mutedForeground, lineHeight: 14 },
131
+ }));
@@ -1,4 +1,7 @@
1
1
  import { useConversationActionApprovals } from '../runtime/action-approvals';
2
+ import { optionOfKind } from '../runtime/approvals';
3
+ import { useApprovalActions } from '../runtime/use-approval-actions';
4
+ import { ApprovalBar } from './ApprovalBar';
2
5
  /**
3
6
  * The conversation: header, thread and composer, with its voice call. The one screen of the
4
7
  * bottom sheet, `GemieChatScreen` and the Alia app — they are frames around this.
@@ -422,7 +425,7 @@ function GemieConversationView({
422
425
  suggestedNewConversation,
423
426
  dismissSuggestedNewConversation,
424
427
  agentRun,
425
- approvals,
428
+ approvals: approvalEntries,
426
429
  settleApproval,
427
430
  failedTurn,
428
431
  retryFailedTurn,
@@ -664,20 +667,43 @@ function GemieConversationView({
664
667
  );
665
668
 
666
669
  // A coding CLI's question to its own user (ADR 0043 §5): the host carries the answer to Gemies.
670
+ // The thread's card and the composer's bar answer through the same actions.
667
671
  const decideApproval = runtime.host.onApprovalDecision;
668
- const approvalCards = useMemo(
669
- () => ({
670
- entries: approvals,
671
- agentName: lead.name,
672
- onDecide:
673
- decideApproval === undefined
674
- ? undefined
675
- : (entry: (typeof approvals)[number], decision: 'allow' | 'deny') =>
676
- decideApproval(entry.requestId, entry.agentId, decision),
677
- onSettled: settleApproval,
678
- }),
679
- [approvals, lead.name, decideApproval, settleApproval],
680
- );
672
+ const stopTurn = useCallback(() => void stop(), [stop]);
673
+ const approvals = useApprovalActions({
674
+ entries: approvalEntries,
675
+ agentName: lead.name,
676
+ onDecide:
677
+ decideApproval === undefined
678
+ ? undefined
679
+ : (entry, decision, details) =>
680
+ decideApproval(entry.requestId, entry.agentId, decision, details),
681
+ onSettled: settleApproval,
682
+ onStopTurn: stopTurn,
683
+ grants: {
684
+ agentId,
685
+ conversationId,
686
+ list: runtime.host.listApprovalGrants,
687
+ revoke: runtime.host.revokeApprovalGrant,
688
+ },
689
+ });
690
+ // While a question waits, a reply typed in the composer is the answer: it declines the request
691
+ // and the words go to the agent. The composer says so, and sends instead of stopping.
692
+ const decliningOption =
693
+ approvals.canAnswer && approvals.pending !== undefined
694
+ ? optionOfKind(approvals.pending, 'deny')
695
+ : undefined;
696
+ const replyDeclines = decliningOption !== undefined && composer.text.trim() !== '';
697
+ const submitReply = useCallback(async () => {
698
+ const entry = approvals.pending;
699
+ const words = composer.text.trim();
700
+ if (!entry || !decliningOption || words === '') return;
701
+ const sent = await approvals.decide(entry, 'deny', {
702
+ optionId: decliningOption.id,
703
+ feedback: words,
704
+ });
705
+ if (sent) composer.setText('');
706
+ }, [approvals, composer, decliningOption]);
681
707
 
682
708
  // ── The chrome ──
683
709
  const latestMessages = useRef(messages);
@@ -760,8 +786,14 @@ function GemieConversationView({
760
786
  }}
761
787
  value={composer.text}
762
788
  onValueChange={composer.setText}
763
- onSubmit={() => void composer.submit(composer.text)}
764
- busy={isLoading}
789
+ onSubmit={() => void (replyDeclines ? submitReply() : composer.submit(composer.text))}
790
+ // Stop gives way to send while a reply would decline the question the agent waits on.
791
+ busy={isLoading && !replyDeclines}
792
+ approval={
793
+ approvals.pending === undefined ? undefined : (
794
+ <ApprovalBar approvals={approvals} isFocused={isFocused} />
795
+ )
796
+ }
765
797
  loaderPhase={composerPhase}
766
798
  disabled={closed || loading}
767
799
  onStop={stop}
@@ -778,9 +810,11 @@ function GemieConversationView({
778
810
  ? t('usageLimit.inputDisabledPlaceholder')
779
811
  : editing !== undefined
780
812
  ? t('composer.editPlaceholder')
781
- : group === undefined
782
- ? labels.placeholder(lead.name)
783
- : t('chat.groupPlaceholder')
813
+ : approvals.pending !== undefined && decliningOption !== undefined
814
+ ? t('chat.approval.replyPlaceholder', { agent: lead.name })
815
+ : group === undefined
816
+ ? labels.placeholder(lead.name)
817
+ : t('chat.groupPlaceholder')
784
818
  }
785
819
  status={status}
786
820
  // The mode selector is the power level: how much power this turn gets.
@@ -835,7 +869,7 @@ function GemieConversationView({
835
869
  onRegenerate={composer.regenerate}
836
870
  onStartEdit={edit.start}
837
871
  newConversationOffer={newConversationOffer}
838
- approvals={approvalCards}
872
+ approvals={approvals}
839
873
  actionApprovals={showsPast ? undefined : actionApprovals}
840
874
  agentActivity={agentRun === null ? null : agentActivity}
841
875
  call={voice.isActive ? { agentState: voice.agentState } : undefined}
@@ -106,6 +106,11 @@ export interface GemieComposerProps<T extends GemieSuggestion = GemieSuggestion>
106
106
  suggestions?: GemieComposerSuggestions<T>;
107
107
  /** What Alia is waiting on, docked above the composer. */
108
108
  questions?: GemieComposerQuestions;
109
+ /**
110
+ * A coding CLI's permission question (`ApprovalBar`), docked above the composer beside the
111
+ * questions: where the person is about to type the reply that declines it.
112
+ */
113
+ approval?: ReactNode;
109
114
  /** The tab on the card's top edge (`ComposerPanelStatusTab`). */
110
115
  status?: ReactNode;
111
116
  /** Drawn where send would be while there is nothing to send (voice mode). */
@@ -151,6 +156,7 @@ function GemieComposerBody<T extends GemieSuggestion>({
151
156
  attachmentKinds,
152
157
  suggestions,
153
158
  questions,
159
+ approval,
154
160
  status,
155
161
  emptyAction,
156
162
  accessory,
@@ -301,6 +307,7 @@ function GemieComposerBody<T extends GemieSuggestion>({
301
307
  {labels.dictationRemaining(remainingSeconds)}
302
308
  </Text>
303
309
  ) : null}
310
+ {approval}
304
311
  {questions && questions.items.length > 0 ? (
305
312
  // Beside the loader, not through the pill's `question` slot: the light traces the box it
306
313
  // wraps, so a question inside it would be ringed too.
@@ -0,0 +1,262 @@
1
+ import { Item } from '@oxy.so/bloom/item';
2
+ import { Loading } from '@oxy.so/bloom/loading';
3
+ import { RiArrowDownSLine } from '@oxy.so/bloom/icons/RiArrowDownSLine';
4
+ import { RiArrowRightSLine } from '@oxy.so/bloom/icons/RiArrowRightSLine';
5
+ import { RiCheckboxCircleLine } from '@oxy.so/bloom/icons/RiCheckboxCircleLine';
6
+ import { RiCloseCircleLine } from '@oxy.so/bloom/icons/RiCloseCircleLine';
7
+ import { RiEditLine } from '@oxy.so/bloom/icons/RiEditLine';
8
+ import { RiFileTextLine } from '@oxy.so/bloom/icons/RiFileTextLine';
9
+ import { RiForbidLine } from '@oxy.so/bloom/icons/RiForbidLine';
10
+ import { RiGlobalLine } from '@oxy.so/bloom/icons/RiGlobalLine';
11
+ import { RiSearchLine } from '@oxy.so/bloom/icons/RiSearchLine';
12
+ import { RiTerminalBoxLine } from '@oxy.so/bloom/icons/RiTerminalBoxLine';
13
+ import { RiToolsLine } from '@oxy.so/bloom/icons/RiToolsLine';
14
+ import { useTheme } from '@oxy.so/bloom/theme';
15
+ import { Muted } from '@oxy.so/bloom/typography';
16
+ import { useEffect, useState } from 'react';
17
+ import { StyleSheet, View } from 'react-native';
18
+ import { useLabels } from '../../lib/labels';
19
+ import {
20
+ type AgentStep,
21
+ type AgentStepKind,
22
+ type AgentWork as AgentWorkLog,
23
+ formatStepDuration,
24
+ workElapsedMs,
25
+ } from '../../runtime/thread/agent-work';
26
+ import { fileChangeTotals } from '../../runtime/thread/file-changes';
27
+ import { formatElapsed } from '../../runtime/thread/thought-utils';
28
+ import { useStepOutput } from '../../runtime/use-step-output';
29
+ import { FileChangesViewer } from '../diff/FileChangesViewer';
30
+ import { CommandOutput } from './CommandOutput';
31
+
32
+ const KIND_ICONS = {
33
+ command: RiTerminalBoxLine,
34
+ read: RiFileTextLine,
35
+ edit: RiEditLine,
36
+ search: RiSearchLine,
37
+ web: RiGlobalLine,
38
+ tool: RiToolsLine,
39
+ } satisfies Record<AgentStepKind, unknown>;
40
+
41
+ /** The clock a running log ticks on, once a second, only while something runs. */
42
+ function useNow(active: boolean): number {
43
+ const [now, setNow] = useState(() => Date.now());
44
+ useEffect(() => {
45
+ if (!active) return;
46
+ setNow(Date.now());
47
+ const timer = setInterval(() => setNow(Date.now()), 1000);
48
+ return () => clearInterval(timer);
49
+ }, [active]);
50
+ return now;
51
+ }
52
+
53
+ export interface AgentWorkProps {
54
+ work: AgentWorkLog;
55
+ /** The conversation the turn is in: a step's live output is followed on its topic. */
56
+ conversationId: string | null | undefined;
57
+ }
58
+
59
+ /**
60
+ * What a coding agent did in a turn, as ONE row: "Worked for 12s · 5 steps", closed until it is
61
+ * pressed. Open, each step is a line — its glyph, what it is (the command, the path), where it
62
+ * stands and how long it took — and a command's line opens to its output, an edit's line to the
63
+ * diff viewer on the files it changed.
64
+ *
65
+ * A step's output is followed live only while its line is open and its command still runs; a
66
+ * closed line costs nothing but the status the turn's own stream carries. A finished command shows
67
+ * the output that was stored with it, so it reads the same after a reload.
68
+ */
69
+ export function AgentWork({ work, conversationId }: AgentWorkProps) {
70
+ const { t } = useLabels();
71
+ const { colors } = useTheme();
72
+ const [open, setOpen] = useState(false);
73
+ const [openSteps, setOpenSteps] = useState<ReadonlySet<string>>(new Set());
74
+ const now = useNow(work.running > 0);
75
+
76
+ const elapsed = workElapsedMs(work, now);
77
+ const steps = t('work.steps', { count: work.steps.length });
78
+ const running = work.running > 0;
79
+ const title =
80
+ elapsed === undefined
81
+ ? t(running ? 'work.working' : 'work.worked', { steps })
82
+ : t(running ? 'work.workingFor' : 'work.workedFor', {
83
+ elapsed: formatElapsed(elapsed),
84
+ steps,
85
+ });
86
+ const Chevron = open ? RiArrowDownSLine : RiArrowRightSLine;
87
+ const toggleStep = (id: string) =>
88
+ setOpenSteps((current) => {
89
+ const next = new Set(current);
90
+ if (!next.delete(id)) next.add(id);
91
+ return next;
92
+ });
93
+
94
+ return (
95
+ <View>
96
+ <Item
97
+ density="compact"
98
+ leading={
99
+ running ? (
100
+ <Loading size="sm" iconSize={14} />
101
+ ) : work.failed > 0 ? (
102
+ <RiCloseCircleLine size="sm" fill={colors.error} />
103
+ ) : (
104
+ <RiCheckboxCircleLine size="sm" fill={colors.success} />
105
+ )
106
+ }
107
+ title={title}
108
+ trailing={
109
+ <View style={styles.trailing}>
110
+ {work.failed > 0 ? (
111
+ <Muted>{t('work.failedCount', { count: work.failed })}</Muted>
112
+ ) : null}
113
+ <Chevron size="sm" fill={colors.textSecondary} />
114
+ </View>
115
+ }
116
+ expanded={open}
117
+ onPress={() => setOpen((value) => !value)}
118
+ accessibilityLabel={title}
119
+ />
120
+ {open ? (
121
+ <View role="list" style={styles.steps}>
122
+ {work.steps.map((step) => (
123
+ <AgentStepRow
124
+ key={step.id}
125
+ step={step}
126
+ conversationId={conversationId}
127
+ now={now}
128
+ expanded={openSteps.has(step.id)}
129
+ onToggle={() => toggleStep(step.id)}
130
+ />
131
+ ))}
132
+ </View>
133
+ ) : null}
134
+ </View>
135
+ );
136
+ }
137
+
138
+ function AgentStepRow({
139
+ step,
140
+ conversationId,
141
+ now,
142
+ expanded,
143
+ onToggle,
144
+ }: {
145
+ step: AgentStep;
146
+ conversationId: string | null | undefined;
147
+ now: number;
148
+ expanded: boolean;
149
+ onToggle: () => void;
150
+ }) {
151
+ const { t } = useLabels();
152
+ const { colors } = useTheme();
153
+ const Icon = KIND_ICONS[step.kind];
154
+ const failed = step.status === 'failed';
155
+ const word =
156
+ step.status === 'failed'
157
+ ? t('work.failed')
158
+ : step.status === 'declined'
159
+ ? t('work.declined')
160
+ : step.status === 'interrupted'
161
+ ? t('work.interrupted')
162
+ : null;
163
+ const duration =
164
+ step.durationMs !== undefined
165
+ ? formatStepDuration(step.durationMs)
166
+ : step.status === 'running' && step.startedAt !== undefined
167
+ ? formatStepDuration(now - step.startedAt)
168
+ : null;
169
+ const title = step.target ?? step.tool;
170
+ // An edit that recorded its files opens the diff viewer on them; a command opens its output.
171
+ const [viewing, setViewing] = useState(false);
172
+ const totals = step.changes.length > 0 ? fileChangeTotals(step.changes) : null;
173
+ const press = totals !== null ? () => setViewing(true) : step.hasOutput ? onToggle : undefined;
174
+ const Chevron = expanded && totals === null ? RiArrowDownSLine : RiArrowRightSLine;
175
+ const label = [
176
+ title,
177
+ word,
178
+ totals === null
179
+ ? null
180
+ : t('chat.fileChanges.open', {
181
+ count: totals.files,
182
+ additions: totals.additions,
183
+ deletions: totals.deletions,
184
+ }),
185
+ ]
186
+ .filter((part) => part !== null)
187
+ .join(', ');
188
+
189
+ return (
190
+ <View role="listitem">
191
+ <Item
192
+ density="compact"
193
+ leading={
194
+ step.status === 'running' ? (
195
+ <Loading size="sm" iconSize={14} />
196
+ ) : step.status === 'declined' || step.status === 'interrupted' ? (
197
+ <RiForbidLine size="sm" fill={colors.textSecondary} />
198
+ ) : (
199
+ <Icon size="sm" fill={failed ? colors.error : colors.text} />
200
+ )
201
+ }
202
+ title={title}
203
+ subtitle={step.target === undefined ? undefined : step.tool}
204
+ destructive={failed}
205
+ trailing={
206
+ <View style={styles.trailing}>
207
+ {word === null ? null : <Muted>{word}</Muted>}
208
+ {totals === null ? null : <Muted>{`+${totals.additions} −${totals.deletions}`}</Muted>}
209
+ {duration === null ? null : <Muted>{duration}</Muted>}
210
+ {press === undefined ? null : <Chevron size="sm" fill={colors.textSecondary} />}
211
+ </View>
212
+ }
213
+ expanded={totals === null && step.hasOutput ? expanded : undefined}
214
+ onPress={press}
215
+ accessibilityLabel={label}
216
+ />
217
+ {totals === null && step.hasOutput && expanded ? (
218
+ <StepOutputPanel step={step} conversationId={conversationId} />
219
+ ) : null}
220
+ {viewing ? (
221
+ <FileChangesViewer
222
+ changes={step.changes}
223
+ open={viewing}
224
+ onClose={() => setViewing(false)}
225
+ />
226
+ ) : null}
227
+ </View>
228
+ );
229
+ }
230
+
231
+ /**
232
+ * An open command's output. Mounted only while the line is open, so the topic it follows is
233
+ * released the moment the line is closed.
234
+ */
235
+ function StepOutputPanel({
236
+ step,
237
+ conversationId,
238
+ }: {
239
+ step: AgentStep;
240
+ conversationId: string | null | undefined;
241
+ }) {
242
+ const { t } = useLabels();
243
+ const running = step.status === 'running';
244
+ const live = useStepOutput(conversationId, step.id, running);
245
+ return (
246
+ <View style={styles.output}>
247
+ <CommandOutput
248
+ output={running ? (live ?? step.output ?? null) : (step.output ?? null)}
249
+ running={running}
250
+ />
251
+ {step.exitCode !== undefined && step.exitCode !== 0 ? (
252
+ <Muted>{t('work.exitCode', { code: step.exitCode })}</Muted>
253
+ ) : null}
254
+ </View>
255
+ );
256
+ }
257
+
258
+ const styles = StyleSheet.create({
259
+ trailing: { flexDirection: 'row', alignItems: 'center', gap: 6 },
260
+ steps: { paddingLeft: 12 },
261
+ output: { paddingLeft: 12, paddingBottom: 8, gap: 4 },
262
+ });