Unify the live process frame and clear it on completion

This commit is contained in:
QQ 2026-11-28 15:14:00 +08:00
parent e49b514685
commit 268f4c427c
8 changed files with 106 additions and 29 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -3,14 +3,15 @@ import type { ReactNode } from 'react';
import type { ChatSnapshot } from '@deepseek-ai/dsh-client-ui-chat/client';
import type { ReaderProps } from './types.js';
import type { LiveStep, LiveTurnItem } from './live-turn.js';
import { collapseRows, containsNewUser, flowRows, FOLD_TIMING, retiringKeys } from './fold-choreography.js';
import type { FoldPhase } from './fold-choreography.js';
import { collapseRows, containsNewUser, flowRows, FOLD_TIMING, processFrames, retiringKeys } from './fold-choreography.js';
import type { FoldPhase, ProcessFrame } from './fold-choreography.js';
import { Disclosure } from './motion.js';
import { FoldSummaryText } from './LiveFold.js';
import { DiffStat } from './DiffPanel.js';
import { StreamMotionContext } from './streaming.js';
import css from './Reader.module.css';
import { useSummaryLane } from './StickyLane.js';
import { isProcessRecord } from './projection.js';
const FlowSnapshot = createContext<ChatSnapshot | null>(null);
/** Public projection only. Descendants cannot leak live data through a frozen frame. */
@ -41,8 +42,8 @@ function Summary({ item, open, onChange, motion }: {
}
/** Manual disclosure shares the measured-size path; children survive until finish. */
function FlowCell({ hidden, instant, motion, rowKey, children, summary = false, process = false }: {
hidden: boolean; instant: boolean; motion: boolean; rowKey: string; children: ReactNode; summary?: boolean; process?: boolean;
function FlowCell({ hidden, instant, motion, rowKey, children, summary = false, processFrame }: {
hidden: boolean; instant: boolean; motion: boolean; rowKey: string; children: ReactNode; summary?: boolean; processFrame?: ProcessFrame | undefined;
}) {
const ref = useRef<HTMLDivElement>(null);
useSummaryLane(ref, summary);
@ -94,7 +95,7 @@ function FlowCell({ hidden, instant, motion, rowKey, children, summary = false,
// applied, which is the only moment the fill can be dropped safely. Without
// it the animation was never cancelled at all and every folded cell kept one.
}, [hidden, instant, motion, present]);
return <div ref={ref} className={css.flowCell} data-flow-key={rowKey} data-flow-summary={summary || undefined} data-flow-process={process || undefined}
return <div ref={ref} className={css.flowCell} data-flow-key={rowKey} data-flow-summary={summary || undefined} data-flow-process={processFrame}
hidden={hidden && !present} aria-hidden={hidden || undefined} {...(hidden ? { inert: '' } : {})}>
{present && <div className={css.flowCellInner}>{children}</div>}
</div>;
@ -220,17 +221,26 @@ export function ChoreographedFlow({ frame, motion, enabled, urgent, open, onOpen
const blocked = state.phase === 'collapse' || state.phase === 'count' || state.phase === 'settle';
const source = state.phase === 'idle' || state.phase === 'collapse' ? state.shown : state.target;
const rows = state.phase === 'collapse' ? collapseRows(state.shown.items, state.target.items) : flowRows(source.items);
const cells = rows.map(row => {
if (row.kind === 'summary') return { row, key: row.key, hidden: false, process: true };
const process = row.step.kind === 'reasoning' || row.step.kind === 'tool'
|| (row.step.kind === 'other' && isProcessRecord(source.snapshot.nodes.get(row.step.nodeKey)));
const hidden = !!row.foldKey && (!processOpen || !open[row.foldKey])
|| (blocked && state.phase !== 'collapse' && !state.beforeKeys.has(row.key));
return { row, key: row.key, hidden, process: processOpen && process };
});
const frames = processFrames(cells);
return <FlowSnapshot.Provider value={source.snapshot}>
<StreamMotionContext.Provider value={{ ...stream, paused: state.phase !== 'idle', resumed: state.phase === 'reveal' }}>
<div id={id} ref={root} className={css.choreographedFlow} data-reader-flow data-reader-transition={state.phase} data-ud-motion="fold-choreography">
{rows.map(row => {
if (row.kind === 'summary') return <FlowCell key={row.key} rowKey={row.key} hidden={false} instant motion={motion} summary>
{cells.map(({ row, hidden }) => {
const processFrame = frames.get(row.key);
if (row.kind === 'summary') return <FlowCell key={row.key} rowKey={row.key} hidden={false} instant motion={motion} summary processFrame={processFrame}>
<Summary item={row.item} open={processOpen && !!open[row.key]} onChange={value => onOpenChange(row.key, value)} motion={motion && state.phase !== 'collapse'} />
</FlowCell>;
const hidden = !!row.foldKey && (!processOpen || !open[row.foldKey]) || (blocked && state.phase !== 'collapse' && !state.beforeKeys.has(row.key));
// Keep retiring child props unchanged until it has actually shrunk.
return <FlowCell key={row.key} rowKey={row.key} hidden={hidden} instant={state.phase !== 'idle'} motion={motion}
process={row.step.kind === 'reasoning' || row.step.kind === 'tool'}>
processFrame={processFrame}>
{renderStep(row.step, !!row.foldKey)}
</FlowCell>;
})}

View File

@ -568,25 +568,25 @@
/* A null-rendered ProcessFragment must contribute no cumulative row spacing. */
.flowCellInner:empty { padding-bottom: 0; }
/* Join contiguous process cells visually so each step keeps its render key and animation. */
.flowCell[data-flow-process] > .flowCellInner {
.flowCell[data-flow-process] > .flowCellInner:not(:empty) {
margin-bottom: 16px;
padding: 4px 8px;
border: 1px solid var(--dsw-alias-border-l2);
border-radius: 12px;
background: var(--dsw-alias-bg-module-platform);
}
.flowCell[data-flow-process]:has(+ [data-flow-process]:not([hidden])) > .flowCellInner {
.flowCell:is([data-flow-process=start], [data-flow-process=middle]) > .flowCellInner:not(:empty) {
margin-bottom: 0;
border-bottom: 0;
border-end-start-radius: 0;
border-end-end-radius: 0;
}
.flowCell[data-flow-process]:not([hidden]) + [data-flow-process] > .flowCellInner {
.flowCell:is([data-flow-process=middle], [data-flow-process=end]) > .flowCellInner:not(:empty) {
border-top: 0;
border-start-start-radius: 0;
border-start-end-radius: 0;
}
.flowCell[data-flow-process] :is(.reasonCard, .toolActivity:not(.toolChildren .toolActivity)) {
.flowCell[data-flow-process] :is(.reasonCard, .toolActivity) {
border: 0;
background: transparent;
}
@ -639,7 +639,9 @@
.foldControl { display: inline-flex; align-items: center; gap: 0; padding: 2px; border-radius: 8px; background: var(--dsw-alias-bg-module-platform); }
.foldStop { border: 0; background: transparent; color: var(--dsw-alias-label-secondary); padding: 2px 8px; border-radius: 6px; white-space: nowrap; font: inherit; font-size: 12px; line-height: 18px; cursor: pointer; }
.foldStop[data-on] { background: var(--dsw-alias-bg-base); color: var(--dsw-alias-label-primary); }
.flowCell[data-flow-summary] > .flowCellInner { padding-bottom: 0; }
.flowCell[data-flow-summary]:not([data-flow-process]) > .flowCellInner { padding-bottom: 0; }
.flowCell[data-flow-summary][data-flow-process] { padding-block: 0; box-shadow: none; }
.root[data-reader-glass] .flowCell[data-flow-summary][data-flow-process] { border-left: 0; padding-left: 0; }
.flowCell[data-flow-summary] .disclosureButton, .closedProcessSummary .disclosureButton { width: auto; max-width: 100%; }
.disclosureButton:has([data-reader-fold-summary]),
.turnProcessSticky > .disclosure > .disclosureButton {

View File

@ -24,6 +24,21 @@ export type FlowRow =
| { kind: 'summary'; key: string; item: Extract<LiveTurnItem, { kind: 'fold' }> }
| { kind: 'step'; key: string; step: LiveStep; foldKey?: string };
export type ProcessFrame = 'single' | 'start' | 'middle' | 'end';
/** Hidden cells are kept in the flow for animation but do not divide a visible frame. */
export function processFrames(rows: readonly { key: string; hidden: boolean; process: boolean }[]): Map<string, ProcessFrame> {
const visible = rows.filter(row => !row.hidden);
const frames = new Map<string, ProcessFrame>();
visible.forEach((row, index) => {
if (!row.process) return;
const previous = visible[index - 1]?.process;
const next = visible[index + 1]?.process;
frames.set(row.key, previous ? (next ? 'middle' : 'end') : (next ? 'start' : 'single'));
});
return frames;
}
/** A step always has the same parent and React key, even when its membership changes. */
export function flowRows(items: readonly LiveTurnItem[]): FlowRow[] {
return items.flatMap((item): FlowRow[] => item.kind === 'fold'

View File

@ -69,7 +69,12 @@ export function hasProcessContent(node: ChatConversationViewNode | undefined, _b
const data = node.data as AssistantChatData;
return data.blocks.some(block => block.kind === 'reasoning' && block.text.trim() !== '');
}
return node.kind === 'context' || node.kind === 'model-retry' || node.kind === 'system-prompt' || node.kind === 'turn-process'
return node.kind === 'turn-process' || isProcessRecord(node);
}
export function isProcessRecord(node: ChatConversationViewNode | undefined): boolean {
if (!node || node.visibility === 'hidden') return false;
return node.kind === 'context' || node.kind === 'model-retry' || node.kind === 'system-prompt'
|| node.kind === 'command' || node.kind === 'manual-compaction' || node.kind === 'compaction';
}

View File

@ -1,6 +1,6 @@
import { test } from 'vitest';
import assert from 'node:assert/strict';
import { collapseRows, containsNewUser, flowRows, FOLD_TIMING, retiringKeys } from '../src/client/fold-choreography.js';
import { collapseRows, containsNewUser, flowRows, FOLD_TIMING, processFrames, retiringKeys } from '../src/client/fold-choreography.js';
import { presentLiveTurn } from '../src/client/live-turn.js';
import type { LiveStep } from '../src/client/live-turn.js';
const reasoning = (n: number): LiveStep => ({ kind: 'reasoning', key: `r${n}`, nodeKey: `n${n}`, start: 0, blocks: [], step: n });
@ -76,3 +76,14 @@ test('every phase has a bounded budget and a watchdog strictly beyond it', () =>
assert.ok(budget + FOLD_TIMING.watchdogSlack < 1000, phase + ' must not read as a stall');
}
});
test('one frame joins the summary, thought and tool across hidden members', () => {
assert.deepEqual([...processFrames([
{ key: 'summary', process: true, hidden: false },
{ key: 'folded-record', process: true, hidden: true },
{ key: 'thought', process: true, hidden: false },
{ key: 'tool', process: true, hidden: false },
{ key: 'answer', process: false, hidden: false },
{ key: 'next-thought', process: true, hidden: false },
])], [['summary', 'start'], ['thought', 'middle'], ['tool', 'end'], ['next-thought', 'single']]);
});

View File

@ -81,8 +81,9 @@ test('tool rendering reads a snapshot that survives the plugin context', () => {
assert.match(official, /useSyncExternalStore\(official\.officialHostHome\.subscribe, official\.officialHostHome\.getSnapshot\)/u);
});
test('adjacent reasoning and tool cells share their frame without reparenting', () => {
assert.match(flow, /process=\{row\.step\.kind === 'reasoning' \|\| row\.step\.kind === 'tool'\}/u);
assert.match(readerCss, /\[data-flow-process\]:has\(\+ \[data-flow-process\]:not\(\[hidden\]\)\)[^{}]*\{[^}]*border-bottom: 0/u);
assert.match(readerCss, /\[data-flow-process\]:not\(\[hidden\]\) \+ \[data-flow-process\][^{}]*\{[^}]*border-top: 0/u);
test('live summaries and visible work share a frame that is removed when folded', () => {
assert.match(flow, /row.kind === 'summary'\) return \{ row, key: row.key, hidden: false, process: true \}/u);
assert.match(flow, /hidden, process: processOpen && process/u);
assert.match(readerCss, /\[data-flow-process\] > \.flowCellInner:not\(:empty\)/u);
assert.match(reader, /const expanded = !autoFold \|\| holdingSelection \|\| processExpanded\(expansionChoice, boundary\)/u);
});