Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 保留停止听写后的用户选区
DavidShen176555ecef4e
diff --git a/apps/mobile/app/sessions/new.tsx b/apps/mobile/app/sessions/new.tsxindex 1d6dd6b8a9..290db1807f 100644--- a/apps/mobile/app/sessions/new.tsx+++ b/apps/mobile/app/sessions/new.tsx@@ -3227,7 +3227,10 @@ export default function NewRemoteSessionScreen() {localVoiceInputHistory,readCurrentDraft: () => firstMessageRef.current,onDraftChanged: (text, selection) => {- if (selection) {+ // Once stopping starts, the user owns the native selection. The+ // final ASR/refinement callback must not move it back to the+ // dictation insertion point after the user has edited the draft.+ if (selection && !voiceStopInFlightRef.current) {firstMessageSelectionRef.current = selection;setFirstMessageSelection(selection);}diff --git a/apps/mobile/scripts/lib/android-simulator.mjs b/apps/mobile/scripts/lib/android-simulator.mjsindex 6fdd547258..9ef4b87644 100644--- a/apps/mobile/scripts/lib/android-simulator.mjs+++ b/apps/mobile/scripts/lib/android-simulator.mjs@@ -48,6 +48,7 @@ export function resolveAndroidSdkTools({env = process.env,platform = process.platform,exists = existsSync,+ requireTools = true,} = {}) {if (platform !== 'win32') return null;@@ -60,7 +61,7 @@ export function resolveAndroidSdkTools({for (const sdkRoot of [...new Set(candidates)]) {const adb = win32Path.join(sdkRoot, 'platform-tools', 'adb.exe');const emulator = win32Path.join(sdkRoot, 'emulator', 'emulator.exe');- if (exists(adb) && exists(emulator)) return { sdkRoot, adb, emulator };+ if (!requireTools || (exists(adb) && exists(emulator))) return { sdkRoot, adb, emulator };}throw new Error(diff --git a/apps/mobile/scripts/sim-metro.mjs b/apps/mobile/scripts/sim-metro.mjsindex a2b16a9e27..824052da6f 100644--- a/apps/mobile/scripts/sim-metro.mjs+++ b/apps/mobile/scripts/sim-metro.mjs@@ -106,7 +106,7 @@ export function probeMetroOwnership(port) {return {pid,launcherPid: Number.isInteger(owner.launcherPid) ? owner.launcherPid : owner.pid,- cwd: owner.worktreeRoot ?? null,+ cwd: owner.worktreeRoot ? join(owner.worktreeRoot, 'apps/mobile') : null,source: owner.source ?? null,};}diff --git a/apps/mobile/scripts/sim-rebuild.mjs b/apps/mobile/scripts/sim-rebuild.mjsindex c459931ffd..217822f0fb 100644--- a/apps/mobile/scripts/sim-rebuild.mjs+++ b/apps/mobile/scripts/sim-rebuild.mjs@@ -197,7 +197,11 @@ function ensureMetroOwnershipBeforeLaunch(packageName) {async function rebuildAndroidSimulator() {const androidTools = process.platform === 'win32'- ? resolveAndroidSdkTools({ env: devProcessEnv, platform: process.platform })+ ? resolveAndroidSdkTools({+ env: devProcessEnv,+ platform: process.platform,+ requireTools: !buildOnly,+ }): null;const emulator = buildOnly? { serial: null, adb: null, sdkRoot: androidTools?.sdkRoot }diff --git a/apps/mobile/src/__tests__/mobileAndroidSimulator.test.ts b/apps/mobile/src/__tests__/mobileAndroidSimulator.test.tsindex df9ba5f327..ca37402d5b 100644--- a/apps/mobile/src/__tests__/mobileAndroidSimulator.test.ts+++ b/apps/mobile/src/__tests__/mobileAndroidSimulator.test.ts@@ -67,6 +67,15 @@ describe('Android SDK 与 adb 输出解析', () => {});});+ it('build-only 可在缺少 emulator 时仍解析 SDK 根目录', () => {+ expect(resolveAndroidSdkTools({+ platform: 'win32',+ requireTools: false,+ env: { ANDROID_SDK_ROOT: 'D:\\Android\\Sdk' },+ exists: () => false,+ })).toMatchObject({ sdkRoot: 'D:\\Android\\Sdk' });+ });+it('只接受在线 emulator,并去掉 avd name 的 OK 尾行', () => {expect(parseAdbEmulatorSerials(['List of devices attached',diff --git a/apps/mobile/src/__tests__/mobileSimSource.test.ts b/apps/mobile/src/__tests__/mobileSimSource.test.tsindex 5aba2976fc..403a1a73af 100644--- a/apps/mobile/src/__tests__/mobileSimSource.test.ts+++ b/apps/mobile/src/__tests__/mobileSimSource.test.ts@@ -1,5 +1,5 @@import { describe, expect, it, vi } from 'vitest';-import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';+import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';import {@@ -126,6 +126,11 @@ describe('mobile simulator Metro takeover', () => {);});+ it('normalizes the Windows owner metadata cwd to the mobile directory', () => {+ const source = readFileSync(join(process.cwd(), 'scripts/sim-metro.mjs'), 'utf8');+ expect(source).toContain("cwd: owner.worktreeRoot ? join(owner.worktreeRoot, 'apps/mobile') : null");+ });+it('falls back to the listener PID when the group is unavailable', async () => {const run = vi.fn();const stopped = await terminateMetro(123, {diff --git a/apps/mobile/src/__tests__/newSession.test.ts b/apps/mobile/src/__tests__/newSession.test.tsindex 857d6ccfe4..7fda327461 100644--- a/apps/mobile/src/__tests__/newSession.test.ts+++ b/apps/mobile/src/__tests__/newSession.test.ts@@ -1821,6 +1821,7 @@ describe('new session composer surface', () => {expect(newSource).not.toContain('voiceDraftListeningText: {\n color: colors.statusReady,');expect(newSource).toContain('const voiceDraftShowsListeningPrompt = voiceIsListening && draft.firstMessage.length === 0;');expect(newSource).toContain('firstMessageInputRef.current?.setNativeProps({ selection: firstMessageSelectionRef.current });');+ expect(newSource).toContain('if (selection && !voiceStopInFlightRef.current) {');expect(newSource).toContain('voiceDraftScrollRef.current?.scrollTo({ y: voiceDraftCaretFrame.top, animated: false });');expect(newSource).toContain('draft.firstMessage.slice(0, firstMessageSelectionRef.current.end)');expect(newSource).toContain('draft.firstMessage.slice(firstMessageSelectionRef.current.end)');diff --git a/apps/mobile/src/__tests__/simRebuildScript.test.ts b/apps/mobile/src/__tests__/simRebuildScript.test.tsindex aca55d6dc1..3875f403a6 100644--- a/apps/mobile/src/__tests__/simRebuildScript.test.ts+++ b/apps/mobile/src/__tests__/simRebuildScript.test.ts@@ -65,6 +65,7 @@ describe('sim-rebuild script invariants', () => {expect(source).toContain('const ownership = probeMetroOwnership(8081);');expect(source).toContain("import { resolveJavaRuntimeEnv } from './java-runtime-env.mjs';");expect(source).toContain('const androidTools = process.platform === \'win32\'');+ expect(source).toContain('requireTools: !buildOnly');expect(source).toContain('ANDROID_SDK_ROOT: sdkRoot, ANDROID_HOME: sdkRoot');expect(source).toContain("if (process.platform === 'win32') {");expect(source).toContain('await rebuildAndroidSimulator();');