Skip to content

Commit 70f2db6

Browse files
tylerslatonclaude
andauthored
OpenBot Mobile: a Bot's steps read as the web app's, never as what the tool answered (#2760)
* OpenBot Mobile: a Bot's steps read as the web app's, never as what the tool answered Opened, "Took N steps" listed each step read back over REST by its text, and a `tool` message's text is the tool's whole answer: a fetched article, with its markdown and escapes. The web app lists one line a step, in its words for the tool, with what the step was done to beside it (the search, the site, the app, the command, the file), and keeps the answer behind a second tap. The phone now does the same (mobile/src/run-steps.ts). A step read back has no name, so it is named from the calls the conversation's socket carried, the replay's ended runs included: by the message its answer came in, by the call's id, or by the answer itself. One whose call was never seen reads "Used a tool". A reply that only called tools is no longer counted again beside its own steps, and a question's answer is no step, since its card is drawn. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * OpenBot Mobile: a Bot's steps have their icons and say what they did in one phrase The folded line says what the steps did, counted by kind as the web app's does ("Searched the web and read 2 pages"), in place of "Took 4 steps". Each step has its kind's icon (the web app's: search, page, browser, app, command, file, folder, saved file, subtask, tool), and opened, the steps hang from the line on a thin branch, the last one closing it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 4afb3c7 commit 70f2db6

7 files changed

Lines changed: 752 additions & 40 deletions

File tree

‎docs/app-guidelines.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,9 @@ Native's, and builds its own only when neither fits. The development build shows
273273
- **A Bot's work shows as it happens, as in the web app.** From the moment a message is sent there
274274
is one row under it that says what the Bot is doing and only changes its words: "Thinking…",
275275
then each step in the web app's own words while it runs ("Search the web…"), then what the steps
276-
were once they are over ("Took 2 steps"). The reply is written under it as it comes, as markdown,
276+
did once they are over, in one phrase counted by kind as the web app's folded line says it
277+
("Searched the web and read 2 pages"). Opened, each step is a line after its kind's icon, on a thin
278+
branch from that row, and never what the tool answered (`mobile/src/run-steps.ts`). The reply is written under it as it comes, as markdown,
277279
with what is half written closed or held back so no symbols show. Nothing is added to the page and
278280
taken away again, and a reply never steps back to a shorter reading of itself: a run that ended
279281
stays drawn from what the socket carried until the messages read back hold it in full

‎mobile/app/conversation.tsx‎

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ import {
107107
} from "../src/live-run";
108108
import { conversationOf, showConversation } from "../src/on-screen";
109109
import { measure, useOrbFlight, type ViewHandle } from "../src/orb-flight";
110+
import {
111+
type KnownCalls,
112+
knownCalls,
113+
NO_CALLS,
114+
stepLines,
115+
} from "../src/run-steps";
110116
import { connectAiRouteFor } from "../src/setup";
111117
import { shownMessages } from "../src/shown-messages";
112118
import { useLoad } from "../src/use-load";
@@ -128,16 +134,22 @@ type Item =
128134
| { kind: "day"; key: string; label: string }
129135
| { kind: "message"; key: string; message: ConversationMessage }
130136
// `going` is the step of a live run that is still under way, in the present tense: "Searching the web".
131-
| { kind: "steps"; key: string; steps: string[]; going?: string }
137+
| {
138+
kind: "steps";
139+
key: string;
140+
steps: ConversationMessage[];
141+
going?: string;
142+
}
132143
| { kind: "approval"; key: string; request: Approval };
133144

134145
/**
135146
* A step a Bot took rather than something it said: a tool's own line, or a finished reply that only
136-
* called tools. A run of them folds into one line, as the web app's transcript folds them. A reply
137-
* that drew cards is not a step: its cards are drawn.
147+
* called tools. A run of them folds into one line, as the web app's transcript folds them, and is
148+
* said in its words when it is drawn (`stepLines`). A reply that drew cards is not a step: its cards
149+
* are drawn.
138150
*/
139-
function stepWords(message: ConversationMessage): string[] | null {
140-
if (message.role === "tool") return [message.text || "Used a tool."];
151+
function stepsOf(message: ConversationMessage): ConversationMessage[] | null {
152+
if (message.role === "tool") return [message];
141153
if (drawable(message).length > 0) return null;
142154
if (
143155
message.role === "bot" &&
@@ -147,9 +159,7 @@ function stepWords(message: ConversationMessage): string[] | null {
147159
message.status !== "waiting" &&
148160
message.status !== "failed"
149161
)
150-
return message.toolCalls && message.toolCalls > 1
151-
? [`Used ${message.toolCalls} tools.`]
152-
: ["Used a tool."];
162+
return [message];
153163
return null;
154164
}
155165

@@ -270,6 +280,13 @@ export function Conversation({
270280
const liveNow = useRef(live);
271281
liveNow.current = live;
272282
const watcher = useRef<{ reconnect(): void } | null>(null);
283+
/*
284+
* Every tool call the socket carried here, the replay's runs that ended included, kept after their runs go: the
285+
* messages read back hold a step as the tool's answer with no name, and it is named from these as the web app
286+
* names it (../src/run-steps.ts).
287+
*/
288+
const [calls, setCalls] = useState<KnownCalls>(NO_CALLS);
289+
useEffect(() => setCalls((held) => knownCalls(held, live)), [live]);
273290
// Whether the socket has gone quiet on a live run: true until it carries an event, and QUIET_MS after its last.
274291
const [quiet, setQuiet] = useState(true);
275292
// The runs Stop was pressed for: they are ending on the server, and the button waits for them.
@@ -284,6 +301,7 @@ export function Conversation({
284301
useEffect(() => {
285302
if (!channelId || !person) return;
286303
setLive([]);
304+
setCalls(NO_CALLS);
287305
setDelivered(null);
288306
setAwaiting(null);
289307
setStopAsked(new Set());
@@ -325,7 +343,10 @@ export function Conversation({
325343
ended();
326344
},
327345
onCaughtUp(runId) {
328-
setLive(caughtUp(replay ?? liveNow.current, runId));
346+
const replayed = replay ?? liveNow.current;
347+
// The runs that ended go from what is drawn live, but their steps are still named by what they called.
348+
setCalls((held) => knownCalls(held, replayed));
349+
setLive(caughtUp(replayed, runId));
329350
replay = null;
330351
// Whatever ended while the socket was away is in the messages now.
331352
void refreshHistory();
@@ -584,7 +605,7 @@ export function Conversation({
584605
label: dayAndTime(message.createdAt),
585606
});
586607
if (!Number.isNaN(at)) previous = at;
587-
const steps = stepWords(message);
608+
const steps = stepsOf(message);
588609
// A step of a live run that is still going is said as what the Bot is doing, under the ones that are over.
589610
const going = liveStep(message) === "running" ? message.text : undefined;
590611
const last = out[out.length - 1];
@@ -751,6 +772,8 @@ export function Conversation({
751772
className="flex-1"
752773
inverted
753774
data={items}
775+
// A run of steps is said in the words of the calls the socket carried, which can come after its messages.
776+
extraData={calls}
754777
keyExtractor={(item) => item.key}
755778
keyboardDismissMode="interactive"
756779
keyboardShouldPersistTaps="handled"
@@ -800,7 +823,7 @@ export function Conversation({
800823
label={`${item.going}…`}
801824
/>
802825
) : (
803-
<StepsLine steps={item.steps} />
826+
<StepsLine steps={stepLines(item.steps, calls)} />
804827
)
805828
) : item.kind === "approval" ? (
806829
<ApprovalHere

‎mobile/src/components/transcript.tsx‎

Lines changed: 102 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,104 @@
11
import { Button } from "heroui-native/button";
22
import { useState } from "react";
33
import { Pressable, View } from "react-native";
4-
import { IconChevronDown, IconChevronRight, IconTool } from "../icons";
4+
import {
5+
IconChevronDown,
6+
IconChevronRight,
7+
IconFilePlus,
8+
IconFileText,
9+
IconFolder,
10+
IconPlug,
11+
IconSearch,
12+
IconSubtask,
13+
IconTerminal2,
14+
IconTool,
15+
IconWorld,
16+
type TablerIcon,
17+
} from "../icons";
18+
import { type StepKind, type StepLine, summarise } from "../run-steps";
19+
import { cn } from "./cn";
520
import { Icon } from "./icon";
621
import { Text } from "./text";
722

23+
/** Each kind of step's icon, the web app's (`KIND_ICONS` in tool-activity.tsx). */
24+
const KIND_ICONS: Record<StepKind, TablerIcon> = {
25+
search: IconSearch,
26+
fetch: IconFileText,
27+
browser: IconWorld,
28+
connector: IconPlug,
29+
tool: IconTool,
30+
file: IconFileText,
31+
directory: IconFolder,
32+
command: IconTerminal2,
33+
saved: IconFilePlus,
34+
subtask: IconSubtask,
35+
};
36+
37+
/** A step as text: what was done, and what it was done to after it, muted. */
38+
function StepText({ step, quiet }: { step: StepLine; quiet?: boolean }) {
39+
return (
40+
<Text
41+
tone={quiet ? "muted" : undefined}
42+
numberOfLines={1}
43+
className="flex-1 text-sm leading-5"
44+
>
45+
{step.label}
46+
{step.detail ? (
47+
<Text
48+
tone="muted"
49+
className={cn("text-sm leading-5", quiet && "opacity-70")}
50+
>{` ${step.detail}`}</Text>
51+
) : null}
52+
</Text>
53+
);
54+
}
55+
856
/**
957
* What a Bot did between two things it said, folded into one quiet line, as the web app's transcript
10-
* folds a run of steps: "Took 3 steps", which opens to each one. A single step is its own line. The
11-
* transcript keeps the Bot's words and the person's in front, and the working out behind a tap.
58+
* folds a run of steps: what they did, in one phrase ("Searched the web and read 2 pages"), which opens
59+
* to each one. A single step is its own line. The transcript keeps the Bot's words and the person's in
60+
* front, and the working out behind a tap.
61+
*
62+
* Each step is a line in the web app's words (../run-steps.ts), after its kind's icon: what was done,
63+
* and what it was done to after it, muted, cut short at the end of the line. Never what the tool
64+
* answered. Opened, the steps hang from the line on a thin branch, the last one closing it.
1265
*/
13-
export function StepsLine({ steps }: { steps: string[] }) {
66+
export function StepsLine({ steps }: { steps: StepLine[] }) {
1467
const [open, setOpen] = useState(false);
68+
const [only] = steps;
69+
if (!only) return null;
1570
// As tall as a Bot's working row and set in as far (`MessageWorking`), which this row takes the place of when a
1671
// run's steps are over: the words change, and nothing on the page moves.
1772
if (steps.length === 1)
1873
return (
1974
<View className="min-h-6 flex-row items-start gap-2 py-0.5">
2075
<View className="w-5 items-center pt-[3px]">
21-
<Icon icon={IconTool} size={14} color="accent-muted" />
76+
<Icon icon={KIND_ICONS[only.kind]} size={14} color="accent-muted" />
2277
</View>
23-
<Text tone="muted" className="flex-1 text-sm leading-5">
24-
{steps[0]}
25-
</Text>
78+
<StepText step={only} quiet />
2679
</View>
2780
);
81+
const summary = summarise(steps);
2882
return (
2983
<View>
3084
<Pressable
3185
accessibilityRole="button"
3286
accessibilityState={{ expanded: open }}
33-
accessibilityLabel={`Took ${steps.length} steps`}
34-
accessibilityHint={open ? "Hides them" : "Shows each one"}
87+
accessibilityLabel={summary}
88+
accessibilityHint={open ? "Hides each step" : "Shows each step"}
3589
hitSlop={8}
3690
onPress={() => setOpen((now) => !now)}
37-
className="min-h-6 flex-row items-center gap-2 self-start active:opacity-60"
91+
className="min-h-6 max-w-full flex-row items-center gap-2 self-start active:opacity-60"
3892
>
3993
<View className="w-5 items-center">
40-
<Icon icon={IconTool} size={14} color="accent-muted" />
94+
<Icon icon={KIND_ICONS[only.kind]} size={14} color="accent-muted" />
4195
</View>
42-
<Text tone="muted" className="text-sm leading-5">
43-
Took {steps.length} steps
96+
<Text
97+
tone="muted"
98+
numberOfLines={1}
99+
className="shrink text-sm leading-5"
100+
>
101+
{summary}
44102
</Text>
45103
<Icon
46104
icon={open ? IconChevronDown : IconChevronRight}
@@ -49,17 +107,36 @@ export function StepsLine({ steps }: { steps: string[] }) {
49107
/>
50108
</Pressable>
51109
{open ? (
52-
<View className="mt-2 ml-2.5 gap-1.5 border-border border-l pl-[17px]">
53-
{steps.map((step, index) => (
54-
<Text
55-
// biome-ignore lint/suspicious/noArrayIndexKey: the steps of one run, in their order
56-
key={index}
57-
tone="muted"
58-
className="text-sm leading-5"
59-
>
60-
{step}
61-
</Text>
62-
))}
110+
<View className="mt-1 ml-2.5">
111+
{steps.map((step, index) => {
112+
const last = index === steps.length - 1;
113+
return (
114+
<View
115+
// biome-ignore lint/suspicious/noArrayIndexKey: the steps of one run, in their order
116+
key={index}
117+
className="min-h-7 flex-row items-center"
118+
>
119+
{/* The branch: down past every step but the last, which it turns into and ends at. */}
120+
<View className="w-4 self-stretch">
121+
<View
122+
className={cn(
123+
"absolute top-0 left-0 w-px bg-border",
124+
last ? "h-1/2" : "bottom-0",
125+
)}
126+
/>
127+
<View className="absolute top-1/2 left-0 h-px w-3 bg-border" />
128+
</View>
129+
<View className="flex-1 flex-row items-center gap-2 py-1">
130+
<Icon
131+
icon={KIND_ICONS[step.kind]}
132+
size={14}
133+
color="accent-muted"
134+
/>
135+
<StepText step={step} />
136+
</View>
137+
</View>
138+
);
139+
})}
63140
</View>
64141
) : null}
65142
</View>

‎mobile/src/icons.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export { default as IconAlertCircle } from "@tabler/icons-react-native/IconAlert
88
export { default as IconAlertTriangle } from "@tabler/icons-react-native/IconAlertTriangle";
99
export { default as IconArchive } from "@tabler/icons-react-native/IconArchive";
1010
export { default as IconArrowLeft } from "@tabler/icons-react-native/IconArrowLeft";
11-
export { default as IconArrowsExchange } from "@tabler/icons-react-native/IconArrowsExchange";
1211
export { default as IconArrowUp } from "@tabler/icons-react-native/IconArrowUp";
12+
export { default as IconArrowsExchange } from "@tabler/icons-react-native/IconArrowsExchange";
1313
export { default as IconBell } from "@tabler/icons-react-native/IconBell";
1414
export { default as IconBook } from "@tabler/icons-react-native/IconBook";
1515
export { default as IconBrain } from "@tabler/icons-react-native/IconBrain";
@@ -37,6 +37,9 @@ export { default as IconEdit } from "@tabler/icons-react-native/IconEdit";
3737
export { default as IconEye } from "@tabler/icons-react-native/IconEye";
3838
export { default as IconEyeOff } from "@tabler/icons-react-native/IconEyeOff";
3939
export { default as IconFile } from "@tabler/icons-react-native/IconFile";
40+
export { default as IconFilePlus } from "@tabler/icons-react-native/IconFilePlus";
41+
export { default as IconFileText } from "@tabler/icons-react-native/IconFileText";
42+
export { default as IconFolder } from "@tabler/icons-react-native/IconFolder";
4043
export { default as IconHistory } from "@tabler/icons-react-native/IconHistory";
4144
export { default as IconInfoCircle } from "@tabler/icons-react-native/IconInfoCircle";
4245
export { default as IconKey } from "@tabler/icons-react-native/IconKey";
@@ -63,7 +66,10 @@ export { default as IconSelector } from "@tabler/icons-react-native/IconSelector
6366
export { default as IconSettings } from "@tabler/icons-react-native/IconSettings";
6467
export { default as IconShieldLock } from "@tabler/icons-react-native/IconShieldLock";
6568
export { default as IconSparkles } from "@tabler/icons-react-native/IconSparkles";
69+
export { default as IconSubtask } from "@tabler/icons-react-native/IconSubtask";
70+
export { default as IconTerminal2 } from "@tabler/icons-react-native/IconTerminal2";
6671
export { default as IconTool } from "@tabler/icons-react-native/IconTool";
6772
export { default as IconTrash } from "@tabler/icons-react-native/IconTrash";
6873
export { default as IconUsersGroup } from "@tabler/icons-react-native/IconUsersGroup";
74+
export { default as IconWorld } from "@tabler/icons-react-native/IconWorld";
6975
export { default as IconX } from "@tabler/icons-react-native/IconX";

‎mobile/src/live-run.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ type LiveTool = {
3434
answered: boolean;
3535
/** What the call answered, for a question the person was asked. */
3636
result?: string;
37+
/** The message the answer came in: the id the conversation's messages read the answer back by. */
38+
resultId?: string;
3739
};
3840

3941
/** A step's id as a message's, so a row keeps its place from the step's start to its end. */
@@ -266,11 +268,13 @@ export function reduce(runs: LiveRuns, event: LiveEvent): LiveRuns {
266268
return withTool(runs, event, (tool) => ({ ...tool, done: true }));
267269
case "TOOL_CALL_RESULT": {
268270
const content = event.content;
271+
const resultId = messageOf(event);
269272
return withTool(runs, event, (tool) => ({
270273
...tool,
271274
done: true,
272275
answered: true,
273276
...(typeof content === "string" ? { result: content } : {}),
277+
...(resultId ? { resultId } : {}),
274278
}));
275279
}
276280
default:
@@ -327,6 +331,15 @@ export function liveStep(
327331
return message.status === "running" ? "running" : "over";
328332
}
329333

334+
/** The tool call one of a live run's steps stands for, by its id; null for any other message. */
335+
export function liveStepCall(
336+
message: Pick<ConversationMessage, "id" | "role">,
337+
): string | null {
338+
return message.role === "tool" && message.id.startsWith(STEP)
339+
? message.id.slice(STEP.length)
340+
: null;
341+
}
342+
330343
/** What the person answered the questions a live run asked, by tool call. */
331344
export function liveAnswers(runs: LiveRuns): Map<string, Answer> {
332345
const out = new Map<string, Answer>();
@@ -415,8 +428,9 @@ export function sentAgain(runs: LiveRuns): LiveRuns {
415428
*
416429
* Each step the Bot takes follows the message it is part of, as a `tool` message in the web app's words for it
417430
* (./shared-copy/tool-name.js): `running` while it is going and said as what it is doing, then over and said as what
418-
* it did ({@link liveStep}). The read messages hold a step by the server's words for it and nothing else, so as
419-
* many of the steps that are over are left out as the read messages hold since the person last spoke. After a step that is over, with nothing written yet, the Bot
431+
* it did ({@link liveStep}). The read messages hold a step as the tool's answer and nothing else, which
432+
* ./run-steps.ts says in the same words as here, so as many of the steps that are over are left out as the read
433+
* messages hold since the person last spoke. After a step that is over, with nothing written yet, the Bot
420434
* is thinking again, which is said as one more step under way ({@link THINKING}), on the same row.
421435
*/
422436
export function asMessages(

0 commit comments

Comments
 (0)