Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(sharing): explain invitation and connection failures
DavidShen2e219afcb28d
diff --git a/apps/desktop/src/main/__tests__/worktreePiSubagentReferences.test.ts b/apps/desktop/src/main/__tests__/worktreePiSubagentReferences.test.tsindex 860c590ac7..69707c6f87 100644--- a/apps/desktop/src/main/__tests__/worktreePiSubagentReferences.test.ts+++ b/apps/desktop/src/main/__tests__/worktreePiSubagentReferences.test.ts@@ -139,8 +139,12 @@ describe('detached Pi Subagent worktree references', () => {await fs.mkdir(entry);} else {const target = path.join(state.root, 'link-target');- await fs.writeFile(target, '{}');- await fs.symlink(target, entry, process.platform === 'win32' ? 'file' : undefined);+ // Junctions need no Windows file-symlink privilege; lstat rejects both+ // before reading the target. Keep file-symlink coverage on POSIX.+ if (process.platform === 'win32') await fs.mkdir(target);+ else await fs.writeFile(target, '{}');+ await fs.symlink(target, entry, process.platform === 'win32' ? 'junction' : 'file');+ expect((await fs.lstat(entry)).isSymbolicLink()).toBe(true);}expect(await livePaths()).toBeNull();});diff --git a/apps/desktop/src/main/device-link/__tests__/sharedTaskApi.test.ts b/apps/desktop/src/main/device-link/__tests__/sharedTaskApi.test.tsindex b5ed5e474b..a3042f6838 100644--- a/apps/desktop/src/main/device-link/__tests__/sharedTaskApi.test.ts+++ b/apps/desktop/src/main/device-link/__tests__/sharedTaskApi.test.ts@@ -15,6 +15,15 @@ beforeEach(() => {http.mockReset();});describe('sharedTask Main HTTP adapter', () => {+ it.each([['NOT_FOUND', 'NOT_FOUND'], ['PERMISSION_DENIED', 'PERMISSION_DENIED'],+ ['INVALID_PARAMS', 'INVALID_PARAMS'], ['NETWORK_ERROR', 'DEVICE_LINK_NOT_CONNECTED']])(+ 'retains actionable %s across the Electron boundary without leaking details', async (code, ipcCode) => {+ http.mockRejectedValue(Object.assign(new Error('private invitation details'), { code }));+ const error = await sharedTaskApi.join('x'.repeat(43), 'Guest').catch((error: Error) => error);+ expect(error).toBeInstanceOf(Error);+ expect((error as Error).message).toContain('[' + ipcCode + ']');+ expect((error as Error).message).not.toContain('private invitation details');+ });it.each(['SHARED_TASK_HOST_LIMIT', 'SHARED_TASK_JOIN_LIMIT', 'SHARED_TASK_GUEST_LIMIT'])('preserves %s through redaction and Electron error serialization', async (code) => {http.mockImplementation(async (_path, options) => {diff --git a/apps/desktop/src/main/device-link/sharedTaskApi.ts b/apps/desktop/src/main/device-link/sharedTaskApi.tsindex 1d7f5d2bb8..68a9b9a401 100644--- a/apps/desktop/src/main/device-link/sharedTaskApi.ts+++ b/apps/desktop/src/main/device-link/sharedTaskApi.ts@@ -36,6 +36,12 @@ export const sharedTaskApi = createSharedTaskApi({if (code === 'SHARED_TASK_HOST_LIMIT' || code === 'SHARED_TASK_JOIN_LIMIT' || code === 'SHARED_TASK_GUEST_LIMIT') {throwIpcError(code, 'Shared task limit reached');}+ // Error properties do not survive Electron serialization. Preserve only+ // actionable codes, never the server response or invitation details.+ if (code === 'NOT_FOUND' || code === 'PERMISSION_DENIED' || code === 'INVALID_PARAMS') {+ throwIpcError(code, 'Shared task request rejected');+ }+ if (code === 'NETWORK_ERROR') throwIpcError('DEVICE_LINK_NOT_CONNECTED', 'Shared task service unreachable');throw error;}},diff --git a/apps/desktop/src/renderer/features/device-link/JoinSharedTaskDialog.tsx b/apps/desktop/src/renderer/features/device-link/JoinSharedTaskDialog.tsxindex 331823a40a..dc23d4efb0 100644--- a/apps/desktop/src/renderer/features/device-link/JoinSharedTaskDialog.tsx+++ b/apps/desktop/src/renderer/features/device-link/JoinSharedTaskDialog.tsx@@ -76,7 +76,13 @@ export function JoinSharedTaskDialog({ open, onOpenChange }: { open: boolean; on}setError(false);void run(async (current) => {- const result = await window.electronAPI.sharedTask.account({ action: 'join', invitation: invitation.trim(), displayName: displayName.trim() }) as NonNullable<typeof request>;+ let result: NonNullable<typeof request>;+ try {+ result = await window.electronAPI.sharedTask.account({ action: 'join', invitation: invitation.trim(), displayName: displayName.trim() }) as NonNullable<typeof request>;+ } catch (error) {+ if (current()) toast.error(t(sharedTaskErrorKey(error, 'join')));+ return;+ }if (current()) { setInvitation(''); setRequest(result); }if (!current()) return;const detail = await window.electronAPI.sharedTask.account({ action: 'get', sharedTaskId: result.sharedTaskId }) as SharedTaskDetail;diff --git a/apps/desktop/src/renderer/features/device-link/__tests__/JoinSharedTaskDialog.test.tsx b/apps/desktop/src/renderer/features/device-link/__tests__/JoinSharedTaskDialog.test.tsxindex 3809014f53..2cd32f72f8 100644--- a/apps/desktop/src/renderer/features/device-link/__tests__/JoinSharedTaskDialog.test.tsx+++ b/apps/desktop/src/renderer/features/device-link/__tests__/JoinSharedTaskDialog.test.tsx@@ -6,6 +6,7 @@ import { MemoryRouter } from 'react-router-dom';import { afterEach, beforeEach, expect, it, vi } from 'vitest';import { JoinSharedTaskDialog } from '../JoinSharedTaskDialog';import { setDataOwnerGeneration } from '@/contexts/dataOwnerGeneration';+import { toast } from '@/lib/toast';const state = vi.hoisted(() => ({ account: vi.fn(), openLink: vi.fn(), invoke: vi.fn(), setSessions: vi.fn(), bind: vi.fn() }));vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string, args?: { title?: string }) => key + (args?.title ? ':' + args.title : '') }) }));vi.mock('@/contexts/AuthContext', () => ({ useAuth: () => ({ dataOwnerId: 'guest', isAuthenticated: true }) }));@@ -30,6 +31,17 @@ function fill() {fireEvent.change(screen.getByLabelText('sharedTask.joinNickname'), { target: { value: 'Guest' } });fireEvent.click(screen.getByRole('button', { name: 'sharedTask.join' }));}+it.each([['NOT_FOUND', 'sharedTask.invitationUnavailable'], ['PERMISSION_DENIED', 'sharedTask.invitationRenew']])(+ 'explains a rejected %s invitation while preserving the form', async (code, key) => {+ state.account.mockImplementation(async ({ action }) => {+ if (action === 'join') throw new Error('[' + code + '] rejected');+ return [];+ });+ open(); fill();+ await waitFor(() => expect(toast.error).toHaveBeenCalledWith(key));+ expect((screen.getByLabelText('sharedTask.invitation') as HTMLTextAreaElement).value).toBe('A'.repeat(43));+ expect(state.openLink).not.toHaveBeenCalled();+ });it('uses a multiline invitation form and focuses invalid input without sending', async () => {open();await act(async () => {});diff --git a/apps/desktop/src/renderer/features/device-link/__tests__/SharedTaskButton.test.tsx b/apps/desktop/src/renderer/features/device-link/__tests__/SharedTaskButton.test.tsxindex 81e9fc9177..2ee6c06971 100644--- a/apps/desktop/src/renderer/features/device-link/__tests__/SharedTaskButton.test.tsx+++ b/apps/desktop/src/renderer/features/device-link/__tests__/SharedTaskButton.test.tsx@@ -78,7 +78,7 @@ it('keeps invitation request failures distinct and does not attempt to copy', as? Promise.reject(new Error('[DEVICE_LINK_TIMEOUT] timed out')) : Promise.resolve({ available: true, detail }));const body = await openWindow(ownerSession);fireEvent.click(within(body).getByRole('button', { name: 'sharedTask.invite' }));- await waitFor(() => expect(toast.error).toHaveBeenCalledWith('sharedTask.retry'));+ await waitFor(() => expect(toast.error).toHaveBeenCalledWith('sharedTask.requestTimedOut'));expect(copy).not.toHaveBeenCalled();});it('ignores a late unsupported response after the data owner changes', async () => {diff --git a/apps/desktop/src/renderer/features/device-link/__tests__/sharedTaskCompatibility.test.ts b/apps/desktop/src/renderer/features/device-link/__tests__/sharedTaskCompatibility.test.tsindex 326cf93368..0aa481eac9 100644--- a/apps/desktop/src/renderer/features/device-link/__tests__/sharedTaskCompatibility.test.ts+++ b/apps/desktop/src/renderer/features/device-link/__tests__/sharedTaskCompatibility.test.ts@@ -12,8 +12,17 @@ describe('shared-task compatibility errors', () => {expect(sharedTaskErrorKey(Object.assign(new Error('unsupported'), { code }))).toBe('sharedTask.upgrade');expect(sharedTaskErrorKey(new Error(`Error invoking remote method 'device-link:invoke': Error: [${code}] unsupported`))).toBe('sharedTask.upgrade');});- it.each(['DEVICE_LINK_NOT_CONNECTED', 'DEVICE_LINK_TIMEOUT', 'DEVICE_LINK_ACCESS_REVOKED', 'NOT_FOUND'])(- 'does not turn %s into an upgrade requirement', (code) => {- expect(sharedTaskErrorKey(new Error(`[${code}] DEVICE_LINK_CHANNEL_NOT_ALLOWED`))).toBe('sharedTask.retry');+ it.each([['DEVICE_LINK_NOT_CONNECTED', 'sharedTask.connectionFailed'], ['DEVICE_LINK_TIMEOUT', 'sharedTask.requestTimedOut'],+ ['DEVICE_LINK_ACCESS_REVOKED', 'sharedTask.unavailable'], ['NOT_FOUND', 'sharedTask.unavailable'],+ ['PERMISSION_DENIED', 'sharedTask.permissionDenied']])(+ 'explains %s without trusting the error body', (code, key) => {+ expect(sharedTaskErrorKey(new Error(`[${code}] DEVICE_LINK_CHANNEL_NOT_ALLOWED`))).toBe(key);});+ it.each([['NOT_FOUND', 'sharedTask.invitationUnavailable'], ['PERMISSION_DENIED', 'sharedTask.invitationRenew']])(+ 'gives a new-invitation action for joining with %s', (code, key) => {+ expect(sharedTaskErrorKey(new Error(`Error invoking remote method 'shared-task:account': Error: [${code}] rejected`), 'join')).toBe(key);+ });+ it('does not infer a cause from arbitrary error text', () => {+ expect(sharedTaskErrorKey(new Error('NOT_FOUND NETWORK_ERROR'))).toBe('sharedTask.retry');+ });});diff --git a/apps/desktop/src/renderer/features/device-link/sharedTaskCompatibility.ts b/apps/desktop/src/renderer/features/device-link/sharedTaskCompatibility.tsindex 1255eb6355..953f9a1c62 100644--- a/apps/desktop/src/renderer/features/device-link/sharedTaskCompatibility.ts+++ b/apps/desktop/src/renderer/features/device-link/sharedTaskCompatibility.ts@@ -1,8 +1,13 @@import { extractIpcError } from '@/utils/ipcError';/** Only explicit capability failures imply an upgrade; offline is retryable. */-export function sharedTaskErrorKey(error: unknown) {+export function sharedTaskErrorKey(error: unknown, context: 'join' | 'operation' = 'operation') {const code = extractIpcError(error)?.code;+ if (code === 'NOT_FOUND') return context === 'join' ? 'sharedTask.invitationUnavailable' : 'sharedTask.unavailable';+ if (code === 'PERMISSION_DENIED') return context === 'join' ? 'sharedTask.invitationRenew' : 'sharedTask.permissionDenied';+ if (code === 'DEVICE_LINK_ACCESS_REVOKED') return 'sharedTask.unavailable';+ if (code === 'DEVICE_LINK_NOT_CONNECTED') return 'sharedTask.connectionFailed';+ if (code === 'DEVICE_LINK_TIMEOUT') return 'sharedTask.requestTimedOut';if (code === 'SHARED_TASK_HOST_LIMIT') return 'sharedTask.hostLimit';if (code === 'SHARED_TASK_JOIN_LIMIT') return 'sharedTask.joinLimit';if (code === 'SHARED_TASK_GUEST_LIMIT') return 'sharedTask.guestLimit';diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.jsonindex 631a9f5174..4ff3ce6301 100644--- a/apps/desktop/src/renderer/i18n/locales/en/common.json+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json@@ -50,7 +50,13 @@"hostLimit": "You can host up to 2 shared tasks at a time. Close one before trying again.","joinLimit": "You can join up to 2 shared tasks at a time. Leave one before trying again.","guestLimit": "This shared task already has 2 guests. You cannot join it yet.",- "retry": "Could not update sharing. Check your connection and retry.",+ "invitationUnavailable": "This invitation is invalid or no longer valid. Ask the host for a new invitation.",+ "invitationRenew": "This old invitation cannot be used to rejoin. Ask the host for a new invitation.",+ "unavailable": "Sharing has ended or you no longer have access. Ask the host for a new invitation.",+ "permissionDenied": "You do not have permission for this action. Contact the host.",+ "connectionFailed": "Cannot connect to the sharing service or the host computer. Check your network and try again.",+ "requestTimedOut": "The request timed out. Check your network and the host computer’s connection, then try again.",+ "retry": "The action could not be completed. Try again later, or reopen the shared task if it keeps failing.","upgrade": "Sharing requires updated clients and server.","sharing": "Guests can read all task content and use the Agent with this task’s permissions. Existing approvals stay with the owner.","open": "Start Sharing",diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.jsonindex 7c443745bd..bb214d3ddb 100644--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json@@ -50,7 +50,13 @@"hostLimit": "同時に共有できるタスクは 2 件までです。共有を 1 件終了してから再試行してください。","joinLimit": "同時に参加できる共有タスクは 2 件までです。1 件から退出してから再試行してください。","guestLimit": "この共有タスクにはすでにゲストが 2 人いるため、参加できません。",- "retry": "共有状態を更新できませんでした。接続を確認して再試行してください。",+ "invitationUnavailable": "この招待は無効になっています。ホストに新しい招待を依頼してください。",+ "invitationRenew": "以前の招待では再参加できません。ホストに新しい招待を依頼してください。",+ "unavailable": "共有が終了したか、アクセス権がありません。ホストに新しい招待を依頼してください。",+ "permissionDenied": "この操作を行う権限がありません。ホストに連絡してください。",+ "connectionFailed": "共有サービスまたはホストのコンピューターに接続できません。ネットワークを確認して再試行してください。",+ "requestTimedOut": "リクエストがタイムアウトしました。ネットワークとホストのコンピューターの接続を確認して再試行してください。",+ "retry": "操作を完了できませんでした。しばらくしてから再試行してください。解決しない場合は共有タスクを開き直してください。","upgrade": "共有にはクライアントとサーバーの更新が必要です。","sharing": "参加者はすべての内容を閲覧し、このセッションの権限で Agent を使用できます。既存の承認は所有者が行います。","open": "共有を開始",diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.jsonindex be66c9eb4e..935a53a36a 100644--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json@@ -50,7 +50,13 @@"hostLimit": "동시에 공유할 수 있는 작업은 최대 2개입니다. 하나를 닫은 후 다시 시도하세요.","joinLimit": "동시에 참여할 수 있는 공유 작업은 최대 2개입니다. 하나에서 나간 후 다시 시도하세요.","guestLimit": "이 공유 작업에는 이미 게스트가 2명 있어 참여할 수 없습니다.",- "retry": "공유 상태를 업데이트하지 못했습니다. 연결을 확인한 후 다시 시도하세요.",+ "invitationUnavailable": "유효하지 않거나 만료된 초대입니다. 호스트에게 새 초대를 요청하세요.",+ "invitationRenew": "이전 초대로는 다시 참여할 수 없습니다. 호스트에게 새 초대를 요청하세요.",+ "unavailable": "공유가 종료되었거나 접근 권한이 없습니다. 호스트에게 새 초대를 요청하세요.",+ "permissionDenied": "이 작업을 수행할 권한이 없습니다. 호스트에게 문의하세요.",+ "connectionFailed": "공유 서비스 또는 호스트 컴퓨터에 연결할 수 없습니다. 네트워크를 확인한 후 다시 시도하세요.",+ "requestTimedOut": "요청 시간이 초과되었습니다. 네트워크와 호스트 컴퓨터의 연결을 확인한 후 다시 시도하세요.",+ "retry": "작업을 완료하지 못했습니다. 잠시 후 다시 시도하고, 계속 실패하면 공유 작업을 다시 여세요.","upgrade": "공유하려면 클라이언트와 서버를 업데이트해야 합니다.","sharing": "참여자는 모든 내용을 보고 이 세션의 권한으로 Agent를 사용할 수 있습니다. 기존 승인은 소유자가 처리합니다.","open": "공유 시작",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.jsonindex e3d23d5a3e..97a7ea1e20 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json@@ -50,7 +50,13 @@"hostLimit": "你最多同时开启 2 个共享任务,请先关闭一个再试。","joinLimit": "你最多同时加入 2 个共享任务,请先退出一个再试。","guestLimit": "此共享任务已有 2 名访客,暂时无法加入。",- "retry": "未能更新共享状态,请检查连接后重试",+ "invitationUnavailable": "邀请无效或已失效,请向房主获取新邀请",+ "invitationRenew": "旧邀请无法再次加入,请向房主获取新邀请",+ "unavailable": "共享已结束或你已无权访问,请向房主获取新邀请",+ "permissionDenied": "你没有权限执行此操作,请联系房主",+ "connectionFailed": "无法连接共享服务或房主电脑,请检查网络后重试",+ "requestTimedOut": "请求超时,请检查网络和房主电脑的连接后重试",+ "retry": "操作未完成,请稍后重试;如果仍失败,请重新打开共享任务","upgrade": "共享任务需要更新客户端和服务器。","sharing": "访客可以查看任务的全部内容,并按该任务现有权限使用 Agent。已有审批仍由房主处理。","open": "开启共享",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.jsonindex ef6d00ebab..afa3338ddf 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json@@ -50,7 +50,13 @@"hostLimit": "你最多同時開啟 2 個共享任務,請先關閉一個再試。","joinLimit": "你最多同時加入 2 個共享任務,請先退出一個再試。","guestLimit": "此共享任務已有 2 名訪客,暫時無法加入。",- "retry": "無法更新共享狀態,請檢查連線後重試",+ "invitationUnavailable": "邀請無效或已失效,請向房主取得新邀請",+ "invitationRenew": "舊邀請無法再次加入,請向房主取得新邀請",+ "unavailable": "共享已結束或你已無權存取,請向房主取得新邀請",+ "permissionDenied": "你沒有權限執行此操作,請聯絡房主",+ "connectionFailed": "無法連接共享服務或房主電腦,請檢查網路後重試",+ "requestTimedOut": "請求逾時,請檢查網路和房主電腦的連線後重試",+ "retry": "操作未完成,請稍後重試;若仍失敗,請重新開啟共享任務","upgrade": "共享任務需要更新客戶端與伺服器。","sharing": "訪客可以查看任務的全部內容,並按該任務現有權限使用 Agent。既有審批仍由房主處理。","open": "開啟共享",diff --git a/apps/mobile/app/shared-session.tsx b/apps/mobile/app/shared-session.tsxindex 8bd1ba70ce..95abe18bf7 100644--- a/apps/mobile/app/shared-session.tsx+++ b/apps/mobile/app/shared-session.tsx@@ -138,7 +138,7 @@ export default function SharedSessionScreen() {const timer = setInterval(() => void poll(), 5_000);return () => { disposed = true; clearInterval(timer); };}, [accountGeneration, load, sessionId, t]));- const run = async (work: (current: () => boolean) => Promise<void>, reload = true) => {+ const run = async (work: (current: () => boolean) => Promise<void>, reload = true, context: 'join' | 'operation' = 'operation') => {if (pending.current) return;pending.current = true; setBusy(true); setNotice('');const owner = getMobileAuthOwner();@@ -152,7 +152,7 @@ export default function SharedSessionScreen() {} catch (error) {if (current()) {if (guestId && isSharedTaskGone(error)) endAccess();- else setNotice(t(sharedTaskErrorKey(error)));+ else setNotice(t(sharedTaskErrorKey(error, context)));}} finally { if (captured === epoch.current) { pending.current = false; setBusy(false); } }};@@ -271,7 +271,7 @@ export default function SharedSessionScreen() {const joined = await api.join(invitation.trim(), name.trim());if (!current()) return;Keyboard.dismiss(); setInvitation(''); setJoinedId(joined.sharedTaskId);- }, false) }} /></View>+ }, false, 'join') }} /></View>{tasks.map((task) => <MainWindowRowButton key={task.sharedTaskId} accessibilityLabel={task.title} disabled={busy} onPress={() => { setNotice(''); setJoinedId(task.sharedTaskId); }}><Text style={styles.taskTitle}>{task.title}</Text></MainWindowRowButton>)}</>}</>}diff --git a/apps/mobile/src/__tests__/sharedSessionCompatibility.test.tsx b/apps/mobile/src/__tests__/sharedSessionCompatibility.test.tsxindex 6dd99f8944..7413bca86a 100644--- a/apps/mobile/src/__tests__/sharedSessionCompatibility.test.tsx+++ b/apps/mobile/src/__tests__/sharedSessionCompatibility.test.tsx@@ -77,6 +77,6 @@ it('does not query an old relay and does not mislabel disconnected as old', asyn});it('does not convert a timeout into an upgrade requirement', async () => {state.link.invoke.mockRejectedValue({ code: 'INVOKE_TIMEOUT' }); await render();- expect(host.textContent).toContain('sharedTask.retry');+ expect(host.textContent).toContain('sharedTask.requestTimedOut');expect(host.textContent).not.toContain('sharedTask.upgrade');});diff --git a/apps/mobile/src/__tests__/sharedTaskCompatibility.test.ts b/apps/mobile/src/__tests__/sharedTaskCompatibility.test.tsindex ce29e08fb8..cdbc0936a8 100644--- a/apps/mobile/src/__tests__/sharedTaskCompatibility.test.ts+++ b/apps/mobile/src/__tests__/sharedTaskCompatibility.test.ts@@ -12,9 +12,17 @@ describe('shared-task compatibility errors', () => {expect(sharedTaskErrorKey({ code })).toBe('sharedTask.upgrade');expect(sharedTaskErrorKey(Object.assign(new Error(`[${code}] unsupported`), { code: 'IPC_ERROR' }))).toBe('sharedTask.upgrade');});- it.each(['NOT_CONNECTED', 'INVOKE_TIMEOUT', 'ACCESS_REVOKED', 'NOT_FOUND'])(- 'does not turn %s into an upgrade requirement', (code) => {- expect(sharedTaskErrorKey(Object.assign(new Error('[CHANNEL_NOT_ALLOWED]'), { code }))).toBe('sharedTask.retry');+ it.each([['NOT_CONNECTED', 'sharedTask.connectionFailed'], ['NETWORK_ERROR', 'sharedTask.connectionFailed'],+ ['INVOKE_TIMEOUT', 'sharedTask.requestTimedOut'], ['REQUEST_TIMEOUT', 'sharedTask.requestTimedOut'],+ ['ACCESS_REVOKED', 'sharedTask.unavailable'], ['NOT_FOUND', 'sharedTask.unavailable'],+ ['PERMISSION_DENIED', 'sharedTask.permissionDenied']])(+ 'explains %s without trusting the error body', (code, key) => {+ expect(sharedTaskErrorKey(Object.assign(new Error('[CHANNEL_NOT_ALLOWED]'), { code }))).toBe(key);+ });+ it.each([['NOT_FOUND', 'sharedTask.invitationUnavailable'], ['PERMISSION_DENIED', 'sharedTask.invitationRenew']])(+ 'gives a new-invitation action for joining with %s', (code, key) => {+ expect(sharedTaskErrorKey({ code }, 'join')).toBe(key);+ expect(sharedTaskErrorKey(new Error(`[${code}] rejected`), 'join')).toBe(key);});it('does not match capability names inside unrelated error text', () => {expect(sharedTaskErrorKey(new Error('[INTERNAL] CHANNEL_NOT_ALLOWED'))).toBe('sharedTask.retry');diff --git a/apps/mobile/src/__tests__/sharedTaskFlow.test.tsx b/apps/mobile/src/__tests__/sharedTaskFlow.test.tsxindex 5b6be9d337..6ddc25cc8f 100644--- a/apps/mobile/src/__tests__/sharedTaskFlow.test.tsx+++ b/apps/mobile/src/__tests__/sharedTaskFlow.test.tsx@@ -85,6 +85,16 @@ beforeEach(() => {element = document.createElement('div'); root = createRoot(element);});afterEach(async () => { await act(async () => root.unmount()); vi.useRealTimers(); });+it.each([['NOT_FOUND', 'sharedTask.invitationUnavailable'], ['PERMISSION_DENIED', 'sharedTask.invitationRenew']])(+ 'keeps the invitation form and explains joining failure %s', async (code, key) => {+ h.api.join.mockRejectedValue({ code });+ await render();+ await fill('sharedTask.invitation', 'a'.repeat(43)); await fill('sharedTask.joinNickname', 'Guest');+ await click('sharedTask.join');+ expect(element.textContent).toContain(key);+ expect(element.querySelector('textarea')?.value).toBe('a'.repeat(43));+ expect(h.link.openLink).not.toHaveBeenCalled();+ });it('uses a multiline invitation and stops at the joined screen before opening the task', async () => {await render();expect(element.querySelector('textarea')).not.toBeNull();diff --git a/apps/mobile/src/device-link/sharedTaskCompatibility.ts b/apps/mobile/src/device-link/sharedTaskCompatibility.tsindex 59d699ed74..ff4ba49d58 100644--- a/apps/mobile/src/device-link/sharedTaskCompatibility.ts+++ b/apps/mobile/src/device-link/sharedTaskCompatibility.ts@@ -1,10 +1,15 @@/** Transport codes and anchored serialized host IPC codes, never arbitrary text. */-export function sharedTaskErrorKey(error: unknown) {+export function sharedTaskErrorKey(error: unknown, context: 'join' | 'operation' = 'operation') {let code = error && typeof error === 'object' ? (error as { code?: unknown }).code : undefined;if (code === undefined || code === 'IPC_ERROR') {const message = error instanceof Error ? error.message : '';code = /^(?:Error invoking remote method '[^']+': Error: )?\[([A-Z0-9_]+)\]/.exec(message)?.[1];}+ if (code === 'NOT_FOUND') return context === 'join' ? 'sharedTask.invitationUnavailable' : 'sharedTask.unavailable';+ if (code === 'PERMISSION_DENIED') return context === 'join' ? 'sharedTask.invitationRenew' : 'sharedTask.permissionDenied';+ if (code === 'ACCESS_REVOKED' || code === 'DEVICE_LINK_ACCESS_REVOKED') return 'sharedTask.unavailable';+ if (code === 'NETWORK_ERROR' || code === 'NOT_CONNECTED' || code === 'DEVICE_LINK_NOT_CONNECTED') return 'sharedTask.connectionFailed';+ if (code === 'REQUEST_TIMEOUT' || code === 'INVOKE_TIMEOUT' || code === 'DEVICE_LINK_TIMEOUT') return 'sharedTask.requestTimedOut';if (code === 'SHARED_TASK_HOST_LIMIT') return 'sharedTask.hostLimit';if (code === 'SHARED_TASK_JOIN_LIMIT') return 'sharedTask.joinLimit';if (code === 'SHARED_TASK_GUEST_LIMIT') return 'sharedTask.guestLimit';diff --git a/apps/mobile/src/i18n/locales/en/sharedTask.json b/apps/mobile/src/i18n/locales/en/sharedTask.jsonindex 54688e0b4e..95cf40e31b 100644--- a/apps/mobile/src/i18n/locales/en/sharedTask.json+++ b/apps/mobile/src/i18n/locales/en/sharedTask.json@@ -14,7 +14,13 @@"hostLimit": "You can host up to 2 shared tasks at a time. Close one before trying again.","joinLimit": "You can join up to 2 shared tasks at a time. Leave one before trying again.","guestLimit": "This shared task already has 2 guests. You cannot join it yet.",- "retry": "Could not update sharing. Check your connection and retry.",+ "invitationUnavailable": "This invitation is invalid or no longer valid. Ask the host for a new invitation.",+ "invitationRenew": "This old invitation cannot be used to rejoin. Ask the host for a new invitation.",+ "unavailable": "Sharing has ended or you no longer have access. Ask the host for a new invitation.",+ "permissionDenied": "You do not have permission for this action. Contact the host.",+ "connectionFailed": "Cannot connect to the sharing service or the host computer. Check your network and try again.",+ "requestTimedOut": "The request timed out. Check your network and the host computer’s connection, then try again.",+ "retry": "The action could not be completed. Try again later, or reopen the shared task if it keeps failing.","upgrade": "Sharing requires updated clients and server.","sharing": "Guests can read all task content and use the Agent with this task’s permissions. Existing approvals stay with the owner.","open": "Start Sharing",diff --git a/apps/mobile/src/i18n/locales/ja/sharedTask.json b/apps/mobile/src/i18n/locales/ja/sharedTask.jsonindex 3de6631dff..e13bac513c 100644--- a/apps/mobile/src/i18n/locales/ja/sharedTask.json+++ b/apps/mobile/src/i18n/locales/ja/sharedTask.json@@ -14,7 +14,13 @@"hostLimit": "同時に共有できるタスクは 2 件までです。共有を 1 件終了してから再試行してください。","joinLimit": "同時に参加できる共有タスクは 2 件までです。1 件から退出してから再試行してください。","guestLimit": "この共有タスクにはすでにゲストが 2 人いるため、参加できません。",- "retry": "共有状態を更新できませんでした。接続を確認して再試行してください。",+ "invitationUnavailable": "この招待は無効になっています。ホストに新しい招待を依頼してください。",+ "invitationRenew": "以前の招待では再参加できません。ホストに新しい招待を依頼してください。",+ "unavailable": "共有が終了したか、アクセス権がありません。ホストに新しい招待を依頼してください。",+ "permissionDenied": "この操作を行う権限がありません。ホストに連絡してください。",+ "connectionFailed": "共有サービスまたはホストのコンピューターに接続できません。ネットワークを確認して再試行してください。",+ "requestTimedOut": "リクエストがタイムアウトしました。ネットワークとホストのコンピューターの接続を確認して再試行してください。",+ "retry": "操作を完了できませんでした。しばらくしてから再試行してください。解決しない場合は共有タスクを開き直してください。","upgrade": "共有にはクライアントとサーバーの更新が必要です。","sharing": "参加者はすべての内容を閲覧し、このセッションの権限で Agent を使用できます。既存の承認は所有者が行います。","open": "共有を開始",diff --git a/apps/mobile/src/i18n/locales/ko/sharedTask.json b/apps/mobile/src/i18n/locales/ko/sharedTask.jsonindex 79fc1de613..4670ed529a 100644--- a/apps/mobile/src/i18n/locales/ko/sharedTask.json+++ b/apps/mobile/src/i18n/locales/ko/sharedTask.json@@ -14,7 +14,13 @@"hostLimit": "동시에 공유할 수 있는 작업은 최대 2개입니다. 하나를 닫은 후 다시 시도하세요.","joinLimit": "동시에 참여할 수 있는 공유 작업은 최대 2개입니다. 하나에서 나간 후 다시 시도하세요.","guestLimit": "이 공유 작업에는 이미 게스트가 2명 있어 참여할 수 없습니다.",- "retry": "공유 상태를 업데이트하지 못했습니다. 연결을 확인한 후 다시 시도하세요.",+ "invitationUnavailable": "유효하지 않거나 만료된 초대입니다. 호스트에게 새 초대를 요청하세요.",+ "invitationRenew": "이전 초대로는 다시 참여할 수 없습니다. 호스트에게 새 초대를 요청하세요.",+ "unavailable": "공유가 종료되었거나 접근 권한이 없습니다. 호스트에게 새 초대를 요청하세요.",+ "permissionDenied": "이 작업을 수행할 권한이 없습니다. 호스트에게 문의하세요.",+ "connectionFailed": "공유 서비스 또는 호스트 컴퓨터에 연결할 수 없습니다. 네트워크를 확인한 후 다시 시도하세요.",+ "requestTimedOut": "요청 시간이 초과되었습니다. 네트워크와 호스트 컴퓨터의 연결을 확인한 후 다시 시도하세요.",+ "retry": "작업을 완료하지 못했습니다. 잠시 후 다시 시도하고, 계속 실패하면 공유 작업을 다시 여세요.","upgrade": "공유하려면 클라이언트와 서버를 업데이트해야 합니다.","sharing": "참여자는 모든 내용을 보고 이 세션의 권한으로 Agent를 사용할 수 있습니다. 기존 승인은 소유자가 처리합니다.","open": "공유 시작",diff --git a/apps/mobile/src/i18n/locales/zh-CN/sharedTask.json b/apps/mobile/src/i18n/locales/zh-CN/sharedTask.jsonindex 8fa589ee55..3b33eaf385 100644--- a/apps/mobile/src/i18n/locales/zh-CN/sharedTask.json+++ b/apps/mobile/src/i18n/locales/zh-CN/sharedTask.json@@ -14,7 +14,13 @@"hostLimit": "你最多同时开启 2 个共享任务,请先关闭一个再试。","joinLimit": "你最多同时加入 2 个共享任务,请先退出一个再试。","guestLimit": "此共享任务已有 2 名访客,暂时无法加入。",- "retry": "未能更新共享状态,请检查连接后重试",+ "invitationUnavailable": "邀请无效或已失效,请向房主获取新邀请",+ "invitationRenew": "旧邀请无法再次加入,请向房主获取新邀请",+ "unavailable": "共享已结束或你已无权访问,请向房主获取新邀请",+ "permissionDenied": "你没有权限执行此操作,请联系房主",+ "connectionFailed": "无法连接共享服务或房主电脑,请检查网络后重试",+ "requestTimedOut": "请求超时,请检查网络和房主电脑的连接后重试",+ "retry": "操作未完成,请稍后重试;如果仍失败,请重新打开共享任务","upgrade": "共享任务需要更新客户端和服务器。","sharing": "访客可以查看任务的全部内容,并按该任务现有权限使用 Agent。已有审批仍由房主处理。","open": "开启共享",diff --git a/apps/mobile/src/i18n/locales/zh-TW/sharedTask.json b/apps/mobile/src/i18n/locales/zh-TW/sharedTask.jsonindex d06cb17be6..142e18d1e0 100644--- a/apps/mobile/src/i18n/locales/zh-TW/sharedTask.json+++ b/apps/mobile/src/i18n/locales/zh-TW/sharedTask.json@@ -14,7 +14,13 @@"hostLimit": "你最多同時開啟 2 個共享任務,請先關閉一個再試。","joinLimit": "你最多同時加入 2 個共享任務,請先退出一個再試。","guestLimit": "此共享任務已有 2 名訪客,暫時無法加入。",- "retry": "無法更新共享狀態,請檢查連線後重試",+ "invitationUnavailable": "邀請無效或已失效,請向房主取得新邀請",+ "invitationRenew": "舊邀請無法再次加入,請向房主取得新邀請",+ "unavailable": "共享已結束或你已無權存取,請向房主取得新邀請",+ "permissionDenied": "你沒有權限執行此操作,請聯絡房主",+ "connectionFailed": "無法連接共享服務或房主電腦,請檢查網路後重試",+ "requestTimedOut": "請求逾時,請檢查網路和房主電腦的連線後重試",+ "retry": "操作未完成,請稍後重試;若仍失敗,請重新開啟共享任務","upgrade": "共享任務需要更新客戶端與伺服器。","sharing": "訪客可以查看任務的全部內容,並按該任務現有權限使用 Agent。既有審批仍由房主處理。","open": "開啟共享",