Group thinking and tools and avoid stale host lookups

This commit is contained in:
QQ 2026-11-28 15:07:30 +08:00
parent 4d071ffa66
commit e49b514685
9 changed files with 74 additions and 23 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

@ -41,8 +41,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 }: {
hidden: boolean; instant: boolean; motion: boolean; rowKey: string; children: ReactNode; summary?: boolean;
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;
}) {
const ref = useRef<HTMLDivElement>(null);
useSummaryLane(ref, summary);
@ -94,7 +94,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}
return <div ref={ref} className={css.flowCell} data-flow-key={rowKey} data-flow-summary={summary || undefined} data-flow-process={process || undefined}
hidden={hidden && !present} aria-hidden={hidden || undefined} {...(hidden ? { inert: '' } : {})}>
{present && <div className={css.flowCellInner}>{children}</div>}
</div>;
@ -229,7 +229,8 @@ export function ChoreographedFlow({ frame, motion, enabled, urgent, open, onOpen
</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}>
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'}>
{renderStep(row.step, !!row.foldKey)}
</FlowCell>;
})}

View File

@ -25,7 +25,7 @@ const useToolDisclosure: UseDisclosure = () => {
export function OfficialTool({ official, block, toolName, cwd, openFile, fallback }: BlockRenderProps & {
official: NonNullable<BlockRenderProps['official']>; block: ToolCallBlock; toolName: string; fallback: ReactNode;
}) {
const home = useSyncExternalStore(official.officialHost.subscribe, official.officialHost.getSnapshot).home;
const home = useSyncExternalStore(official.officialHostHome.subscribe, official.officialHostHome.getSnapshot);
return <div data-reader-tool-official>
{(official.renderSlot as (key: string, owner: object, options: object) => ReactNode)(OFFICIAL_SEATS.tools, {
callId: block.callId, toolName,

View File

@ -567,6 +567,30 @@
.flowCellInner { display: flex; flex-direction: column; min-width: 0; padding-bottom: 16px; }
/* 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 {
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 {
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 {
border-top: 0;
border-start-start-radius: 0;
border-start-end-radius: 0;
}
.flowCell[data-flow-process] :is(.reasonCard, .toolActivity:not(.toolChildren .toolActivity)) {
border: 0;
background: transparent;
}
.root[data-reader-glass] .flowCell[data-flow-process] > .flowCellInner { background: transparent; }
.choreographedFlow[data-reader-transition=collapse] .flowCell * { animation-play-state: paused !important; }
.numberRollExit, .numberRollEnter { animation-duration: 160ms; }
/* A flex item's intrinsic width must include its real label and chevron.

View File

@ -540,8 +540,8 @@ const TurnGroup = memo(function TurnGroup({ group, motion, autoFold, pinnedKeys,
renderSlot: props.renderSlot, renderSlotChain: props.renderSlotChain,
officialImageLoader: props.officialImageLoader, officialFileMentions: props.officialFileMentions,
officialPreviewFile: props.officialPreviewFile,
officialHost: props.officialHost, openView: props.openView,
}), [props.renderSlot, props.renderSlotChain, props.officialImageLoader, props.officialFileMentions, props.officialPreviewFile, props.officialHost, props.openView]);
officialHostHome: props.officialHostHome, openView: props.openView,
}), [props.renderSlot, props.renderSlotChain, props.officialImageLoader, props.officialFileMentions, props.officialPreviewFile, props.officialHostHome, props.openView]);
const cwd = props.useSessions(state => state.byId[props.sessionId]?.cwd);
const runMs = turn?.start && turn?.end ? Math.max(0, turn.end.time - turn.start.time) : undefined;
const metrics = useMemo(() => ({

View File

@ -1,4 +1,5 @@
import type { Context } from '@deepseek-ai/cordis';
import { createSnapshotStore } from '@deepseek-ai/dsh-client-store';
import type {} from '@deepseek-ai/dsh-api-remotes/client';
import type {} from '@deepseek-ai/dsh-api-session-controller/client';
import type {} from '@deepseek-ai/dsh-client-connection/client';
@ -72,6 +73,14 @@ export function apply(ctx: Context, options: { chatPrefs?: ChatPrefs } = {}): vo
const restoreTextTransform = installTextTransformRegistry(textTransform);
ctx.provide(TEXT_TRANSFORM_SERVICE, textTransform);
ctx.effect(() => restoreTextTransform);
const officialHostHome = createSnapshotStore<string | undefined>(undefined);
ctx.effect(() => {
// A retiring tool card can still render after this Cordis context closes.
// React reads the store only, while the active plugin refreshes its value.
const updateHome = () => officialHostHome.set(ctx.remote.$host?.home);
updateHome();
return ctx.on('connection/reset', updateHome);
}, 'better-chat: host home snapshot');
const store = createReaderStore();
// conversation.view is session-scoped, so session persist keys are
// `dsh.reader.v1.<sessionId>`. One root instance keeps glass, fold
@ -118,10 +127,7 @@ export function apply(ctx: Context, options: { chatPrefs?: ChatPrefs } = {}): vo
if (!sidebar?.openResource) throw new Error('文件预览面板不可用。');
sidebar.openResource((officialFileAddressFor ?? fileAddressFor)(sessionId, cwd, path));
},
officialHost: {
getSnapshot: () => ctx.remote.$host,
subscribe: listener => ctx.on('connection/reset', listener),
},
officialHostHome,
loadOlder: async () => { await session().loadOlder(); },
loadImage: async attachment => {
const receipt = await session().readAttachment(attachment.attachmentId);

View File

@ -56,7 +56,7 @@ export interface ReaderInjected {
officialImageLoader: MessageImageLoader;
officialFileMentions: (owner: TurnTailOwnerProps) => MarkdownFileMentions | undefined;
officialPreviewFile: (path: string) => void;
officialHost: { getSnapshot: () => { home?: string }; subscribe: (listener: () => void) => () => void };
officialHostHome: { getSnapshot: () => string | undefined; subscribe: (listener: () => void) => () => void };
/** Root-scoped Better Display prefs (`dsh.reader.v1`), shared with Settings. */
openPrefs?: {
getSnapshot: () => {
@ -87,7 +87,7 @@ export type ReaderProps = PropsRuntime<'conversation.view'>
& PropsStore<ReturnType<typeof createReaderStore>>
& ReaderInjected;
export type BlockRenderProps = Pick<ReaderProps, 'renderSlotChain' | 'loadImage' | 'fillComposer'> & {
official?: Pick<ReaderProps, 'renderSlot' | 'renderSlotChain' | 'officialImageLoader' | 'officialFileMentions' | 'officialPreviewFile' | 'officialHost' | 'openView'>;
official?: Pick<ReaderProps, 'renderSlot' | 'renderSlotChain' | 'officialImageLoader' | 'officialFileMentions' | 'officialPreviewFile' | 'officialHostHome' | 'openView'>;
cwd?: string;
openFile?: (path: string, options?: OpenFileOptions) => Promise<void> | void;
revealFile?: (path: string) => Promise<void> | void;

View File

@ -11,6 +11,8 @@ import { test } from 'vitest';
const source = await readFile(new URL('../src/client/reader-plugin.tsx', import.meta.url), 'utf8');
const seat = await readFile(new URL('../src/client/chat-view-seat.ts', import.meta.url), 'utf8');
const reader = await readFile(new URL('../src/client/Reader.tsx', import.meta.url), 'utf8');
const flow = await readFile(new URL('../src/client/ChoreographedFlow.tsx', import.meta.url), 'utf8');
const official = await readFile(new URL('../src/client/OfficialContent.tsx', import.meta.url), 'utf8');
const blocks = await readFile(new URL('../src/client/Blocks.tsx', import.meta.url), 'utf8');
const readerCss = await readFile(new URL('../src/client/Reader.module.css', import.meta.url), 'utf8');
const markdown = await readFile(new URL('../src/client/markdown/MarkdownText.tsx', import.meta.url), 'utf8');
@ -71,3 +73,16 @@ test('process summary wraps between labels and keeps the last counter visible',
assert.doesNotMatch(rules[0] ?? '', /overflow: hidden|text-overflow/u);
assert.match(readerCss, /\.foldSummaryPart \{[^}]*white-space: nowrap/u);
});
test('tool rendering reads a snapshot that survives the plugin context', () => {
assert.match(source, /const officialHostHome = createSnapshotStore<string \| undefined>\(undefined\)/u);
assert.match(source, /ctx\.on\('connection\/reset', updateHome\)/u);
assert.doesNotMatch(source, /getSnapshot:\s*\(\)\s*=>\s*ctx\.remote/u);
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);
});