Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(i18n): 避免语言切换重载预览目录
david70a6077016e0
diff --git a/apps/mobile/app/files/preview/[sessionId].tsx b/apps/mobile/app/files/preview/[sessionId].tsxindex 9cdc524656..c6fed9b54f 100644--- a/apps/mobile/app/files/preview/[sessionId].tsx+++ b/apps/mobile/app/files/preview/[sessionId].tsx@@ -70,6 +70,7 @@ import {normalizeRemoteOpDirEntries,parentRelPath,type FileBrowserGridItem,+ type FileBrowserRemoteOpEntry,type FileBrowserSortMode,} from '@/session/fileBrowserGrid';import { useFileThumbnail } from '@/session/fileThumbnails';@@ -98,6 +99,11 @@ type TextPreviewState =*/type RichTextKind = 'markdown' | 'html';+interface SiblingListing {+ key: string;+ entries: FileBrowserRemoteOpEntry[];+}+/*** **入参必须是 `item.relPath`(真实路径),不能是 `item.name`(展示名)。***@@ -165,6 +171,7 @@ export default function RemoteFilePreviewScreen() {const workdir = session?.workingDir ?? '';const [siblings, setSiblings] = useState<FileBrowserGridItem[] | null>(null);+ const [siblingListing, setSiblingListing] = useState<SiblingListing | null>(null);const [pageIndex, setPageIndex] = useState(0);// 屏级焦点(HTML 可执行 WebView 的挂载门之一,见 renderItem 的 visible)。// 本屏被压栈(点「发送到会话」→ router.navigate 把会话页推到根 Stack 上)时@@ -250,55 +257,73 @@ export default function RemoteFilePreviewScreen() {setPageIndex(0);}, [singleAbsPath]);- // 同目录 pager:列父目录 → 文件项按浏览页同款排序;失败时退化为单文件。- // 重建列表时锚定「当前可见文件」而非固定 initialRelPath(review P1):恢复- // 重列 / 排序切换发生在用户已翻页之后时,重置回初始文件会让 FlatList 的- // 原生滚动位置与 pageIndex(标题 / 分享 / 下载的目标)指向两个不同文件。- // setPageIndex 后再显式 scrollToOffset 重锚一次(initialScrollIndex 只在- // 首挂载生效,items key 变化不会重置 contentOffset)。+ // 同目录 pager 远端数据:只在目录来源或恢复代数变化时重列。语言 / 排序变化+ // 只消费下面缓存的原始目录项重建展示模型,不能为翻译重新请求设备。useEffect(() => {if (!deviceId || !workdir || !initialRelPath) return undefined;let cancelled = false;const dirRel = parentRelPath(initialRelPath) ?? '';- const anchorRelPath = currentRelPathRef.current ?? initialRelPath;- const anchorTo = (index: number): void => {- setPageIndex(index);- requestAnimationFrame(() => {- if (!cancelled) {- pagerRef.current?.scrollToOffset({ animated: false, offset: index * pageWidthRef.current });- }- });- };+ const listingKey = `${deviceId}\u0000${workdir}\u0000${dirRel}`;void withTransientRemoteRetry(async () => {await openLink(deviceId);return maker.fileBrowser.listDir(workdir, dirRel);}).then((raw) => {if (cancelled) return;- // 图片已统一走浏览页的 ImageLightbox,翻页器只装非图片文件;- // 仅当直接以图片路径进入(旧链路兜底)时保留该图片单页。- const files = buildFileBrowserGridItems(normalizeRemoteOpDirEntries(raw), sortMode, Date.now())- .filter((item) => item.kind === 'file')- .filter((item) => item.thumb !== 'image' || item.relPath === initialRelPath);- let index = files.findIndex((item) => item.relPath === anchorRelPath);- if (index < 0) index = files.findIndex((item) => item.relPath === initialRelPath);- if (files.length === 0 || index < 0) {- setSiblings([fallbackItem(initialRelPath)]);- anchorTo(0);- return;- }- setSiblings(files);- anchorTo(index);+ setSiblingListing({ key: listingKey, entries: normalizeRemoteOpDirEntries(raw) });}).catch(() => {if (cancelled) return;+ setSiblingListing(null);setSiblings([fallbackItem(initialRelPath)]);- anchorTo(0);+ setPageIndex(0);+ requestAnimationFrame(() => {+ if (!cancelled) pagerRef.current?.scrollToOffset({ animated: false, offset: 0 });+ });+ });+ return () => {+ cancelled = true;+ };+ }, [deviceId, initialRelPath, maker, openLink, recoveryEpoch, workdir]);++ // 同目录 pager 展示投影:语言 / 排序变化只在本地重建 metaLabel 与顺序。+ // 重建时锚定「当前可见文件」而非固定 initialRelPath(review P1):用户已翻页后,+ // 重置回初始文件会让 FlatList 的原生滚动位置与 pageIndex(标题 / 分享 / 下载+ // 的目标)指向两个不同文件。setPageIndex 后再显式重锚一次(initialScrollIndex+ // 只在首挂载生效,items key 变化不会重置 contentOffset)。+ useEffect(() => {+ if (!deviceId || !workdir || !initialRelPath || !siblingListing) return undefined;+ const dirRel = parentRelPath(initialRelPath) ?? '';+ const listingKey = `${deviceId}\u0000${workdir}\u0000${dirRel}`;+ if (siblingListing.key !== listingKey) return undefined;+ let cancelled = false;+ const anchorRelPath = currentRelPathRef.current ?? initialRelPath;+ const anchorTo = (index: number): void => {+ setPageIndex(index);+ requestAnimationFrame(() => {+ if (!cancelled) {+ pagerRef.current?.scrollToOffset({ animated: false, offset: index * pageWidthRef.current });+ }});+ };+ // 图片已统一走浏览页的 ImageLightbox,翻页器只装非图片文件;+ // 仅当直接以图片路径进入(旧链路兜底)时保留该图片单页。+ const files = buildFileBrowserGridItems(siblingListing.entries, sortMode, Date.now())+ .filter((item) => item.kind === 'file')+ .filter((item) => item.thumb !== 'image' || item.relPath === initialRelPath);+ let index = files.findIndex((item) => item.relPath === anchorRelPath);+ if (index < 0) index = files.findIndex((item) => item.relPath === initialRelPath);+ if (files.length === 0 || index < 0) {+ setSiblings([fallbackItem(initialRelPath)]);+ anchorTo(0);+ } else {+ setSiblings(files);+ anchorTo(index);+ }return () => {cancelled = true;};- }, [deviceId, i18nInstance.language, initialRelPath, maker, openLink, recoveryEpoch, sortMode, workdir]);+ }, [deviceId, i18nInstance.language, initialRelPath, siblingListing, sortMode, workdir]);const current = siblings?.[pageIndex] ?? null;const pagerRef = useRef<FlatList<FileBrowserGridItem>>(null);diff --git a/apps/mobile/src/__tests__/mobilePresentationRefresh.test.ts b/apps/mobile/src/__tests__/mobilePresentationRefresh.test.tsindex 529ed222a5..41df961477 100644--- a/apps/mobile/src/__tests__/mobilePresentationRefresh.test.ts+++ b/apps/mobile/src/__tests__/mobilePresentationRefresh.test.ts@@ -107,11 +107,16 @@ describe('mobile localized presentation refresh', () => {it('rebuilds preview-page file metadata when the language changes', () => {const source = read('app/files/preview/[sessionId].tsx');+ const directoryRequest = source.slice(+ source.indexOf('// 同目录 pager 远端数据:'),+ source.indexOf('// 同目录 pager 展示投影:'),+ );const siblingProjection = source.slice(- source.indexOf('// 同目录 pager:'),+ source.indexOf('// 同目录 pager 展示投影:'),source.indexOf('const current = siblings?.[pageIndex] ?? null'),);+ expect(directoryRequest).not.toContain('i18nInstance.language');expect(siblingProjection).toContain('i18nInstance.language');});diff --git a/packages/maker-core/src/agents/pi/__tests__/cindySubagentRunner.test.ts b/packages/maker-core/src/agents/pi/__tests__/cindySubagentRunner.test.tsindex 160d2d64a6..a078903b44 100644--- a/packages/maker-core/src/agents/pi/__tests__/cindySubagentRunner.test.ts+++ b/packages/maker-core/src/agents/pi/__tests__/cindySubagentRunner.test.ts@@ -823,13 +823,10 @@ describe('Cindy durable PI Subagent runner', () => {(outcome) => outcome.status === 'fulfilled' && typeof outcome.value === 'string',);// Mutual exclusion is the claim under test, and it is asserted without- // assuming *which* racer wins. Either may now finish: the containment- // guard resolves both sides canonically, so a symlinked root is no longer- // rejected as an escape. Asserting "exactly one fulfilled" instead would- // still be a coin flip on which racer got there first.- // Windows CI saw this set come back empty, which no local ordering- // reproduces. Dump both outcomes verbatim so the next run names the cause- // instead of only reporting the count.+ // assuming *which* racer wins. The containment guard resolves both roots+ // canonically, so the invariant is exactly one started resume and exactly+ // one refused resume. Dump both outcomes verbatim so a platform-specific+ // failure names the cause instead of only reporting the count.const describeOutcomes = (): string => JSON.stringify(settled.map((outcome) => (outcome.status === 'fulfilled'? { fulfilled: outcome.value }@@ -847,9 +844,8 @@ describe('Cindy durable PI Subagent runner', () => {&& !/already resuming this Subagent generation/i.test(String(outcome.reason?.message ?? ''))));expect(unexpectedRejections, `resume outcomes: ${describeOutcomes()}`).toHaveLength(0);- expect(refusedTheResume.length, `resume outcomes: ${describeOutcomes()}`).toBeGreaterThanOrEqual(1);- expect(started.length).toBeLessThanOrEqual(1);- expect(refusedTheResume.length + started.length, `resume outcomes: ${describeOutcomes()}`).toBe(2);+ expect(started, `resume outcomes: ${describeOutcomes()}`).toHaveLength(1);+ expect(refusedTheResume, `resume outcomes: ${describeOutcomes()}`).toHaveLength(1);// Whoever got through, there is never a second live generation over the// same PI child session — that is what a lost claim has to prevent.const runs = await listPiSubagentRuns(fixture.root);