DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
refactor(chat): one disclosure vocabulary for the folded working-out
Bingxi Zhao (Frank)3f706e9844cd
diff --git a/web/components/activity/ActivityFold.tsx b/web/components/activity/ActivityFold.tsxnew file mode 100644index 000000000..90b99299b--- /dev/null+++ b/web/components/activity/ActivityFold.tsx@@ -0,0 +1,62 @@+"use client";++import type { ReactNode } from "react";+import { ChevronRight } from "lucide-react";++/**+ * One curve and one duration for every disclosure in the activity+ * vocabulary, so a header and the fold hanging from it settle on the same+ * beat. The curve is the fast-out/long-settle shape the sidebar's "More"+ * disclosure uses — crisper than `ease-out` at this size.+ *+ * Reduced motion needs no opt-out here: `globals.css` shortens every+ * transition to a near-imperceptible duration under that setting.+ */+export const FOLD_EASE = "duration-[220ms] ease-[cubic-bezier(0.32,0.72,0,1)]";++/**+ * The caret that says a line is a disclosure.+ *+ * Kept at the same weight as the metadata beside it ("· 33s · 4 tool calls"):+ * on a line that is mostly read and occasionally clicked, the caret is there+ * to promise the content is recoverable, not to ask to be pressed. It lifts+ * to full contrast with the rest of the line on hover.+ */+export function FoldCaret({ open }: { open: boolean }) {+ return (+ <ChevronRight+ aria-hidden+ className={`size-3 shrink-0 text-[var(--muted-foreground)]/45 transition-[transform,color] group-hover/act:text-current ${FOLD_EASE} ${+ open ? "rotate-90" : ""+ }`}+ />+ );+}++/**+ * Content that folds away without being unmounted.+ *+ * Animates on `grid-template-rows` between `0fr` and `1fr`, which is the one+ * way to transition to a height the content decides — no measuring, no+ * `max-height` guess that either clips a long trace or makes a short one+ * crawl open.+ */+export function ActivityFold({+ open,+ children,+ className = "",+}: {+ open: boolean;+ children: ReactNode;+ className?: string;+}) {+ return (+ <div+ className={`grid transition-[grid-template-rows,opacity] ${FOLD_EASE} ${+ open ? "grid-rows-[1fr] opacity-100" : "grid-rows-[0fr] opacity-0"+ } ${className}`}+ >+ <div className="overflow-hidden">{children}</div>+ </div>+ );+}diff --git a/web/components/activity/ActivityHeader.tsx b/web/components/activity/ActivityHeader.tsxindex 0a7ee839d..c78c1eb42 100644--- a/web/components/activity/ActivityHeader.tsx+++ b/web/components/activity/ActivityHeader.tsx@@ -2,6 +2,7 @@import type { ReactNode } from "react";+import { FoldCaret } from "./ActivityFold";import { ActivityOrb, type OrbState } from "./ActivityOrb";/**@@ -12,9 +13,12 @@ import { ActivityOrb, type OrbState } from "./ActivityOrb";* a single one. That contrast is what carries the hierarchy, which is why the* stack needs neither an indent nor a rule to belong to this line.*- * Doubles as the stack's disclosure control when `expandable`, with no- * chevron: the row's hover colour shift is the only affordance, because a- * permanent chevron on a line that is mostly read, not clicked, is noise.+ * Doubles as the stack's disclosure control when `expandable`, and then ends+ * in a caret. Once a settled turn folds its whole working-out behind this one+ * line, the caret is the only thing saying that working-out still exists —+ * without it the process reads as discarded rather than put away. It is kept+ * at the weight of the metadata beside it so the line still reads as a status+ * first and a control second.*/export function ActivityHeader({orb,@@ -37,9 +41,10 @@ export function ActivityHeader({/** Elapsed time, already formatted. */duration?: string | null;/**- * What the folded stack below holds ("2 tool calls"), shown only while it- * is closed. A line that says nothing about what it hides gives the reader- * no reason to open it — and once open, the rows say it better themselves.+ * What the stack below holds ("2 tool calls"). Shown in both states: closed+ * it is the reason to open, and open it is still the count — a line that+ * changes its own shape depending on a disclosure reads as two different+ * lines rather than one thing being revealed.*/summary?: ReactNode;/** Stop breathing the label and dim it: the work is over. */@@ -65,11 +70,12 @@ export function ActivityHeader({· {duration}</span>) : null}- {summary && expandable && !expanded ? (+ {summary ? (<span className="text-[12px] font-medium text-[var(--muted-foreground)]/55">· {summary}</span>) : null}+ {expandable ? <FoldCaret open={expanded} /> : null}</>);diff --git a/web/components/activity/index.ts b/web/components/activity/index.tsindex 9b093317d..24cdb4e22 100644--- a/web/components/activity/index.ts+++ b/web/components/activity/index.ts@@ -9,6 +9,7 @@* ActivityStack the rows under it, aligned to the orb's column* ActivityDivider a labelled break between groups of rows* ActivityRow one action, with its specifics folded away+ * ActivityFold the content a header folds away, on the shared curve* ActivityDetailGrid the label/value layout inside level two* ActivityMark a list row's mark, for lists with no header orb above*@@ -19,6 +20,7 @@*/export { ActivityHeader } from "./ActivityHeader";+export { ActivityFold, FoldCaret, FOLD_EASE } from "./ActivityFold";export {ActivityDetailGrid,argumentRows,diff --git a/web/features/chat/messages/ChatMessageList.tsx b/web/features/chat/messages/ChatMessageList.tsxindex f36e8af83..26d19b299 100644--- a/web/features/chat/messages/ChatMessageList.tsx+++ b/web/features/chat/messages/ChatMessageList.tsx@@ -37,6 +37,7 @@ import {import { useTranslation } from "react-i18next";import type { SelectedHistorySession } from "@/components/chat/HistorySessionPicker";import type { SelectedQuestionEntry } from "@/components/chat/QuestionBankPicker";+import { ActivityFold, FoldCaret } from "@/components/activity";import AssistantResponse from "@/components/common/AssistantResponse";import {InlineFileCardProvider,@@ -185,34 +186,28 @@ function ProcessFold({const { t } = useTranslation();const [userOpen, setUserOpen] = useState<boolean | null>(null);const open = userOpen ?? !settled;- const { toolCalls, notes } = summariseProcess(segments);- const parts = [- toolCalls > 0 ? t("{{count}} tool calls", { count: toolCalls }) : null,- notes > 0 ? t("{{count}} notes", { count: notes }) : null,- ].filter(Boolean);+ const toolCalls = countProcessToolCalls(segments);return (<div className="mb-3">+ {/* Same shape as the activity header this fold echoes: the label first,+ the caret after it. The header has an orb holding the left column,+ so a leading caret here would make the two controls read as two+ different kinds of thing. */}<buttontype="button"onClick={() => setUserOpen(!open)}aria-expanded={open}- className="flex w-full items-center gap-1.5 text-left text-[12px] font-medium text-[var(--muted-foreground)]/55 transition-colors hover:text-[var(--foreground)]"+ className="group/act flex items-center gap-2 text-left text-[12px] font-medium text-[var(--muted-foreground)]/55 transition-colors hover:text-[var(--foreground)]">- <ChevronRight- className={`size-3 transition-transform ${open ? "rotate-90" : ""}`}- />- {parts.length ? parts.join(" · ") : t("Working notes")}+ {toolCalls > 0+ ? t("{{count}} tool calls", { count: toolCalls })+ : t("Working notes")}+ <FoldCaret open={open} /></button>- <div- className={`grid transition-[grid-template-rows,opacity] duration-300 ease-out ${- open ? "grid-rows-[1fr] opacity-100" : "grid-rows-[0fr] opacity-0"- }`}- >- <div className="overflow-hidden">- <div className="pt-1">{children}</div>- </div>- </div>+ <ActivityFold open={open}>+ <div className="pt-1">{children}</div>+ </ActivityFold></div>);}@@ -260,24 +255,22 @@ function buildMessageBlocks(return blocks;}-/** What a folded run of working-out holds, for the line that stands in for it. */-function summariseProcess(segments: MessageSegment[]): {- toolCalls: number;- notes: number;-} {+/**+ * How many steps a run of working-out took, for the line that names it.+ *+ * Steps only. Counting the paragraphs of commentary alongside them read as a+ * measure of how much was said rather than how much was done, which is the+ * thing a reader is deciding whether to open.+ */+function countProcessToolCalls(segments: MessageSegment[]): number {let toolCalls = 0;- let notes = 0;for (const segment of segments) {- if (segment.kind === "text") {- if (segment.text.trim()) notes += 1;- continue;- }if (segment.kind !== "trace") continue;for (const event of segment.events) {if (event.type === "tool_call") toolCalls += 1;}}- return { toolCalls, notes };+ return toolCalls;}export function getModeBadgeLabel(capability?: string | null): string {@@ -827,12 +820,10 @@ export const AssistantMessage = memo(function AssistantMessage({);const headerProcessSummary = useMemo(() => {if (!headerProcess) return undefined;- const { toolCalls, notes } = summariseProcess(headerProcess.segments);- const parts = [- toolCalls > 0 ? t("{{count}} tool calls", { count: toolCalls }) : null,- notes > 0 ? t("{{count}} notes", { count: notes }) : null,- ].filter(Boolean);- return parts.length ? parts.join(" · ") : undefined;+ const toolCalls = countProcessToolCalls(headerProcess.segments);+ return toolCalls > 0+ ? t("{{count}} tool calls", { count: toolCalls })+ : undefined;}, [headerProcess, t]);const researchInProgress =diff --git a/web/features/chat/trace/TracePresentation.tsx b/web/features/chat/trace/TracePresentation.tsxindex 8d7349b9b..02b2dd66c 100644--- a/web/features/chat/trace/TracePresentation.tsx+++ b/web/features/chat/trace/TracePresentation.tsx@@ -16,6 +16,7 @@ import type { StreamEvent } from "@/features/chat/model/protocol";import {ActivityDetailGrid,ActivityDivider,+ ActivityFold,ActivityHeader,ActivityRow,ActivityStack,@@ -1839,30 +1840,25 @@ export function AssistantActivity({traceBounds={traceBounds}/>{expandable ? (- <div- className={`grid transition-[grid-template-rows,opacity] duration-300 ease-out ${- open ? "grid-rows-[1fr] opacity-100" : "grid-rows-[0fr] opacity-0"- }`}- >- <div className="overflow-hidden">- {/* The process hangs from a faint guide line aligned under the- header's activity mark, so it reads as "nested below" the- status (the elbow/tree language used elsewhere). pt-2 = gap- below the header when open; [&>div]:mb-0 strips- CallTracePanel's own bottom margin so the single gap to the- body comes from this block's outer ``mb-3`` in both states. */}- {hasProcess ? (- <div className="pt-2">{processContent}</div>- ) : hasTrace ? (- <NestedTraceFlow- events={shownTraceEvents}- isStreaming={isStreaming}- />- ) : (- <TraceLoadingRow />- )}- </div>- </div>+ <ActivityFold open={open}>+ {/* The process hangs from a faint guide line on the header's own+ left edge — where the activity mark sits — with its content+ indented past it, so the working-out reads as nested inside the+ turn while the answer below stays at the top level. pt-2 = gap+ below the header when open; [&>div]:mb-0 strips CallTracePanel's+ own bottom margin so the single gap to the body comes from this+ block's outer ``mb-3`` in both states. */}+ {hasProcess ? (+ <div className="pt-2">{processContent}</div>+ ) : hasTrace ? (+ <NestedTraceFlow+ events={shownTraceEvents}+ isStreaming={isStreaming}+ />+ ) : (+ <TraceLoadingRow />+ )}+ </ActivityFold>) : null}</div>);diff --git a/web/locales/en/app.json b/web/locales/en/app.jsonindex b0d456fef..e0f692efc 100644--- a/web/locales/en/app.json+++ b/web/locales/en/app.json@@ -4046,6 +4046,5 @@"The account could not be connected. Please start a new connection.": "The account could not be connected. Please start a new connection.","Sign in with your Invidious account, then approve read-only access to return here. Your DeepTutor login is separate.": "Sign in with your Invidious account, then approve read-only access to return here. Your DeepTutor login is separate.","{{count}} tool calls": "{{count}} tool calls",- "{{count}} notes": "{{count}} notes","Working notes": "Working notes"}diff --git a/web/locales/zh/app.json b/web/locales/zh/app.jsonindex d39f0e9f0..5d88d4076 100644--- a/web/locales/zh/app.json+++ b/web/locales/zh/app.json@@ -4046,6 +4046,5 @@"The account could not be connected. Please start a new connection.": "账号关联失败,请重新发起关联。","Sign in with your Invidious account, then approve read-only access to return here. Your DeepTutor login is separate.": "请使用 Invidious 账号登录,确认只读授权后会自动返回此页。DeepTutor 与 Invidious 使用各自的登录账号。","{{count}} tool calls": "{{count}} 次工具调用",- "{{count}} notes": "{{count}} 条说明","Working notes": "过程记录"}