Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

feat(mobile): pick remote and shared providers when creating a task

MagicLizia5a7ba35b633
diff --git a/apps/mobile/app/sessions/new.tsx b/apps/mobile/app/sessions/new.tsx
index 2977e328af..95db0b0e74 100644
--- a/apps/mobile/app/sessions/new.tsx
+++ b/apps/mobile/app/sessions/new.tsx
@@ -7,6 +7,7 @@ import { retainOutboxFile, durableOutboxUploadUri, removeRetainedOutboxFiles, ou
import { buildOutboxItem, createOutboxClientId } from '@/session/sessionOutbox';
import type { DurableOutboxRecord } from '@/session/durableOutbox';
import { stripTrailingPathSeparators } from '@cindy/maker-shared/path-text';
+import { isSharedTaskPeer } from '@cindy/device-link';
import { takeRefinementContextTail } from '@cindy/voice-input-core';
import { Stack, useIsFocused, useLocalSearchParams, useNavigation, useRouter } from 'expo-router';
import { NewTaskSelectionSheet } from '@/session/NewTaskSelectionSheet';
@@ -183,6 +184,7 @@ import {
} from '@/session/composerPalette';
import {
type StoredAgentRestoreState,
+ applyRemoteAgentPick,
DEFAULT_NEW_SESSION_DRAFT,
NEW_SESSION_AGENT_OPTIONS,
availableNewSessionAgentOptions,
@@ -213,6 +215,7 @@ import {
type NewSessionAgentKind,
type NewSessionDraft,
type NewSessionDeviceOption,
+ type NewSessionRemoteAgentPick,
type NewSessionStoredPreferences,
} from '@/session/newSession';
import { isDefaultDraftSessionTitle } from '@cindy/maker-shared/session-title';
@@ -379,6 +382,7 @@ import { mobileAgentLabel, mobileAgentVendor } from '@/session/sessionAgentSwitc
import { MobileModelIconMark } from '@/session/MobileProviderMark';
import { draftModelMemoryFor, hydrateDraftModelMemory } from '@/session/draftModelMemory';
import { effortLabelFromRuntime, rowFastEditable } from '@/session/modelPickerRows';
+import { useRemoteAgentCatalogs } from '@/session/useRemoteAgentCatalogs';
import { useTheme, useThemedStyles, type ThemeColors } from '@/theme';
import { fontWeight, iconSize, iconStroke, lineHeight, navigationChrome, radius, spacing, typeScale } from '@/theme/tokens';
@@ -611,7 +615,21 @@ export default function NewRemoteSessionScreen() {
workingDir: draft.workingDir || null,
remoteHostId: null,
}), [draft.workingDir, draft.workspaceKind]);
- const collabEligible = isOrcaCollabEligible(collabTarget);
+ // 远程 Agent / 供应商分享(与已建任务、桌面新建同一套):选中另一台电脑或分享来的模型 = Agent
+ // 在那里运行。单独存,不进草稿:草稿的模型 / 来源一直按被控电脑的目录校准,创建时再整体覆盖。
+ const [remoteAgentChoice, setRemoteAgentChoice] = useState<{
+ controlledDeviceId: string;
+ pick: NewSessionRemoteAgentPick;
+ } | null>(null);
+ // 只对选它时的那台被控电脑与那个 Agent 成立:换了电脑、在别处换了 Agent 就不再生效(按条件
+ // 判,不靠 effect 清——恢复草稿时电脑与草稿同一轮写入,effect 会把刚恢复的选择误清)。
+ const remoteAgentPick = remoteAgentChoice
+ && remoteAgentChoice.controlledDeviceId === selectedDeviceId
+ && remoteAgentChoice.pick.agentKind === draft.agentKind
+ ? remoteAgentChoice.pick
+ : null;
+ // 协同首个 Worker 的模型从被控电脑的目录里选,与 Agent 在另一台电脑运行还对不上:两者先互斥。
+ const collabEligible = isOrcaCollabEligible(collabTarget) && remoteAgentPick === null;
// 换设备 / 换工作区后,草稿里的协同设置属于旧目标:丢弃,避免在新目标上静默开启。
// 按草稿武装时的目标比对(而不是「目标一变就清」):返回编辑恢复草稿时目标与草稿一起回填,
// 不会被这里误清。
@@ -750,7 +768,19 @@ export default function NewRemoteSessionScreen() {
// (创建期间发出的消息可能超出单条上限,装不下的只能丢,但不能静默丢,review P1)。
// 声明在 attachmentError 之后:notice 就落在附件错误行上。
const outboxRecoveryRef = useRef<DurableOutboxRecord | null>(null);
- const restoreCreationDraft = useCallback((recovered: NewSessionDraft, files: RemoteSerializedAttachment[], plan?: { enabled: boolean; restorePermissionMode: string | null }) => {
+ const restoreCreationDraft = useCallback((
+ saved: NewSessionDraft,
+ files: RemoteSerializedAttachment[],
+ plan?: { enabled: boolean; restorePermissionMode: string | null },
+ controlledDeviceId?: string,
+ ) => {
+ // 存下来的草稿里 Agent 在另一台电脑时,模型属于那台:拆回远程选择,草稿本身回到被控电脑。
+ const { agentDeviceId, ...recovered } = saved;
+ setRemoteAgentChoice(agentDeviceId && controlledDeviceId ? {
+ controlledDeviceId,
+ pick: { deviceId: agentDeviceId, agentKind: saved.agentKind, model: saved.model,
+ providerId: saved.providerId, effort: saved.effort, fastMode: saved.fastMode },
+ } : null);
userTouchedWorkspaceRef.current = true;
userTouchedRuntimeRef.current = true;
appliedPermissionMemoryRef.current = true;
@@ -789,7 +819,8 @@ export default function NewRemoteSessionScreen() {
userTouchedDeviceRef.current = true;
restoreCreationDraft(record.creation.draft,
record.item.attachmentSlots.filter((a): a is RemoteSerializedAttachment => a !== null),
- { enabled: record.creation.planModeArm, restorePermissionMode: record.creation.restorePermissionMode });
+ { enabled: record.creation.planModeArm, restorePermissionMode: record.creation.restorePermissionMode },
+ record.deviceId);
setSelectedDeviceId(record.deviceId);
setSelectedDeviceName(record.creation.deviceName);
};
@@ -800,7 +831,7 @@ export default function NewRemoteSessionScreen() {
useEffect(() => {
const stashed = drainStashedNewSessionDraft();
if (!stashed) return;
- restoreCreationDraft(stashed.draft, [...stashed.attachments]);
+ restoreCreationDraft(stashed.draft, [...stashed.attachments], undefined, stashed.deviceId || undefined);
if (stashed.notice) setAttachmentError(stashed.notice);
if (stashed.collabDraft && stashed.deviceId) {
collabDraftTargetRef.current = orcaCollabDraftTargetKey(
@@ -1035,6 +1066,39 @@ export default function NewRemoteSessionScreen() {
// 旧目录快照绕过终检)。
const modelRowsRef = useRef(modelRows);
modelRowsRef.current = modelRows;
+ // 被控电脑认得新建时的 agentDeviceId 才提供远程模型:它的目录带「允许被远程调用」标记
+ // (与远程 Agent 同一版加入)。共享任务访客读到的是自己账号的设备,与这台电脑无关。
+ const remoteAgentSupported = !!selectedDeviceId
+ && !isSharedTaskPeer(selectedDeviceId)
+ && deviceProviders.providers.some(
+ (provider) => typeof (provider as { remoteInvocationEnabled?: unknown }).remoteInvocationEnabled === 'boolean',
+ );
+ const remoteAgentKeepDeviceIds = useMemo(
+ () => (remoteAgentPick ? [remoteAgentPick.deviceId] : []),
+ [remoteAgentPick],
+ );
+ const remoteAgentCatalogs = useRemoteAgentCatalogs({
+ // 选择器打开时读其他电脑与分享;已选远程模型时还要按那份目录显示模型药丸。
+ enabled: remoteAgentSupported && (modelSheetOpen || remoteAgentPick !== null),
+ controlledDeviceId: selectedDeviceId,
+ keepDeviceIds: remoteAgentKeepDeviceIds,
+ keepOnly: !modelSheetOpen,
+ });
+ const remoteAgentCatalog = remoteAgentPick
+ ? remoteAgentCatalogs.find((catalog) => catalog.deviceId === remoteAgentPick.deviceId) ?? null
+ : null;
+ // 药丸用那台电脑目录里的来源与模型名;目录还没读到时退回模型 id、不画来源标。
+ const remoteAgentPillProvider = useMemo(() => {
+ if (!remoteAgentPick || !remoteAgentCatalog) return null;
+ const sourceId = remoteAgentPick.providerId ?? buildMobileModelSections({
+ providers: remoteAgentCatalog.providers,
+ agentKind: remoteAgentPick.agentKind,
+ selectedModelId: remoteAgentPick.model,
+ selectedProviderId: null,
+ visibilityOverrides: remoteAgentCatalog.modelVisibilityOverrides,
+ }).activeSourceId;
+ return remoteAgentCatalog.providers.find((provider) => provider.id === sourceId) ?? null;
+ }, [remoteAgentCatalog, remoteAgentPick]);
const catalogReadyRef = useRef(deviceProviders.ready);
catalogReadyRef.current = deviceProviders.ready;
// 供应商目录本身的渲染期镜像:异步回调(权限确认 .then)提交时用它现场重建目标
@@ -1044,14 +1108,15 @@ export default function NewRemoteSessionScreen() {
deviceProvidersRef.current = deviceProviders;
// 发送前鉴权门禁(对齐桌面 useVendorAuthGate):选中 agent 在被控端没有已连接
// 供应商时提前提示 + 拦截创建,不让用户发出注定失败的首条消息。unknown 不拦截。
+ // 选了另一台电脑的模型时不按被控电脑判:那一行来自那台已连接的供应商,登录由那台核对。
const agentAuthVerdict = useMemo(
- () => agentAuthGateVerdict({
+ () => remoteAgentPick ? 'ready' as const : agentAuthGateVerdict({
providers: deviceProviders.providers,
loading: deviceProviders.loading,
error: deviceProviders.error,
agentKind: draft.agentKind,
}),
- [deviceProviders.providers, deviceProviders.loading, deviceProviders.error, draft.agentKind],
+ [deviceProviders.providers, deviceProviders.loading, deviceProviders.error, draft.agentKind, remoteAgentPick],
);
// 创建前的 fresh 鉴权确认(绕过缓存现拉):true = 确认无已连接供应商,应拦截。
// 空目录 / 拉取失败(旧被控端 / 瞬断)与 agentAuthGateVerdict 的 unknown 同语义,
@@ -1394,6 +1459,19 @@ export default function NewRemoteSessionScreen() {
// effort / 权限标签按 app 语言解析,切换语言时必须重算,否则停留在上一语言。
[draft, runtimeOptions, i18nInstance.language],
);
+ // 选了另一台电脑的模型:药丸写那台目录里的模型名与档位,读屏一并读出电脑名(与已建任务同口径)。
+ const remoteAgentModelName = remoteAgentPick && remoteAgentPillProvider
+ ? getModel(remoteAgentPillProvider, remoteAgentPick.model, remoteAgentPick.agentKind)?.name ?? null
+ : null;
+ const pillModelSummary = remoteAgentPick
+ ? [
+ remoteAgentModelName || remoteAgentPick.model,
+ effortLabelFromRuntime({ currentModel: null, effortOptions: runtimeOptions.effortOptions }, remoteAgentPick.effort),
+ ].filter(Boolean).join(' · ')
+ : runtimeSummary.modelSummary;
+ const pillAccessibilityModel = remoteAgentCatalog?.name
+ ? [pillModelSummary, remoteAgentCatalog.name].join(', ')
+ : pillModelSummary;
// 权限按钮 / 权限下拉不体现 plan(对齐桌面 PR#494 / Cursor):计划模式激活时展示
// 进入前的底层权限档(无记录时回退首个非 plan 档),激活态由 composer 的 PlanModeChip 表达。
const displayPermissionMode = draft.permissionMode === 'plan'
@@ -2505,6 +2583,7 @@ export default function NewRemoteSessionScreen() {
const selectProviderModelRow = useCallback((row: ProviderModelRow) => {
userTouchedRuntimeRef.current = true; // 用户手动选了模型 → 不再自动覆盖运行配置
runtimeActionSeqRef.current += 1; // 使在途的切 agent/恢复回调失效(最新者胜)
+ setRemoteAgentChoice(null);
setDraft((current) => {
const next = resolveRowSelection({
row,
@@ -2529,8 +2608,13 @@ export default function NewRemoteSessionScreen() {
setModelSheetOpen(false);
}, [capabilities, draftMemory]);
- const selectUnifiedModel = useCallback(async (config: MobileModelConfiguration): Promise<boolean> => {
+ // source.deviceId 非空 = 选的是另一台电脑(或分享来的)目录里的行:Agent 在那里运行。
+ const selectUnifiedModel = useCallback(async (
+ config: MobileModelConfiguration,
+ source?: { deviceId: string | null },
+ ): Promise<boolean> => {
if (creating || !selectedDeviceId) return false;
+ const remoteDeviceId = source?.deviceId ?? null;
const deviceAtStart = selectedDeviceId;
const sequence = ++runtimeActionSeqRef.current;
const targetCapabilities = normalizeMobileAgentCapabilities(await maker.getCapabilities(config.agent));
@@ -2543,10 +2627,21 @@ export default function NewRemoteSessionScreen() {
})) return false;
if (deviceAtStart !== selectedDeviceRef.current || sequence !== runtimeActionSeqRef.current) return false;
userTouchedRuntimeRef.current = true;
- explicitProviderModelSelectionRef.current = config.modelId;
const fastMode = targetCapabilities.hasFastMode === true && config.fast;
- setDraft(current => ({ ...current, agentKind: config.agent, model: config.modelId,
- providerId: config.providerId, effort: config.effort, fastMode, permissionMode: permission }));
+ if (remoteDeviceId) {
+ // 模型与来源属于那台电脑:单独记,草稿只跟着换 Agent 与权限(权限仍在被控电脑上生效)。
+ setRemoteAgentChoice({
+ controlledDeviceId: deviceAtStart,
+ pick: { deviceId: remoteDeviceId, agentKind: config.agent, model: config.modelId,
+ providerId: config.providerId, effort: config.effort, fastMode },
+ });
+ setDraft(current => ({ ...current, agentKind: config.agent, permissionMode: permission }));
+ } else {
+ explicitProviderModelSelectionRef.current = config.modelId;
+ setRemoteAgentChoice(null);
+ setDraft(current => ({ ...current, agentKind: config.agent, model: config.modelId,
+ providerId: config.providerId, effort: config.effort, fastMode, permissionMode: permission }));
+ }
void saveNewSessionPreferences({ agentKind: config.agent });
return true;
}, [creating, selectedDeviceId, maker, newSessionPreferences, draft.agentKind, draft.permissionMode]);
@@ -2555,6 +2650,7 @@ export default function NewRemoteSessionScreen() {
const selectFlatModel = useCallback((option: MobileModelOption) => {
userTouchedRuntimeRef.current = true; // 用户手动选了模型 → 不再自动覆盖运行配置
runtimeActionSeqRef.current += 1; // 使在途的切 agent/恢复回调失效(最新者胜)
+ setRemoteAgentChoice(null);
explicitProviderModelSelectionRef.current = null;
setDraft((current) =>
reconcileRuntimeDraftWithCapabilities({ ...current, model: option.id, providerId: null }, capabilities));
@@ -3849,7 +3945,7 @@ export default function NewRemoteSessionScreen() {
/>
) : null}
<Pressable
- accessibilityLabel={t('session.new.modelAccessibility', { model: runtimeSummary.modelSummary })}
+ accessibilityLabel={t('session.new.modelAccessibility', { model: pillAccessibilityModel })}
accessibilityRole="button"
accessibilityState={{ expanded: modelSheetOpen || undefined }}
hitSlop={10}
@@ -3857,7 +3953,20 @@ export default function NewRemoteSessionScreen() {
style={({ pressed }) => [styles.modelPill, pressed && styles.pressed]}
testID="newSession.modelIndicator"
>
- {activeSourceProvider ? (
+ {remoteAgentPick ? (
+ // 另一台电脑上的模型:那台目录里的来源标,带远程标记。
+ remoteAgentPillProvider ? (
+ <MobileModelIconMark
+ color={colors.textSecondary}
+ icon={getModel(remoteAgentPillProvider, remoteAgentPick.model, remoteAgentPick.agentKind)?.icon}
+ name={remoteAgentPillProvider.name}
+ providerId={remoteAgentPillProvider.id}
+ routing={remoteAgentPillProvider.routing}
+ logoKind={remoteAgentPillProvider.logoKind}
+ remote
+ />
+ ) : null
+ ) : activeSourceProvider ? (
// 图标统一规则(桌面同源):模型条目 icon(AI Gateway 设定)优先,缺省回落来源标。
<MobileModelIconMark
color={colors.textSecondary}
@@ -3868,8 +3977,10 @@ export default function NewRemoteSessionScreen() {
logoKind={activeSourceProvider.logoKind}
/>
) : null}
- <Text style={styles.modelPillText} numberOfLines={1}>{runtimeSummary.modelSummary}</Text>
- {triggerFastOn ? <Zap color={colors.textTertiary} size={iconSize.sm} strokeWidth={iconStroke.regular} /> : null}
+ <Text style={styles.modelPillText} numberOfLines={1}>{pillModelSummary}</Text>
+ {(remoteAgentPick ? remoteAgentPick.fastMode : triggerFastOn)
+ ? <Zap color={colors.textTertiary} size={iconSize.sm} strokeWidth={iconStroke.regular} />
+ : null}
<ChevronDown color={colors.textTertiary} size={iconSize.sm} strokeWidth={iconStroke.regular} />
</Pressable>
</ComposerToolbarLeftGroup>
@@ -4337,7 +4448,7 @@ export default function NewRemoteSessionScreen() {
setError(t('session.menu.aiRenameOffline'));
return;
}
- if (deviceProvidersRef.current.ready && modelNeedsReselection(
+ if (!remoteAgentPick && deviceProvidersRef.current.ready && modelNeedsReselection(
deviceProvidersRef.current.modelVisibilityOverrides, draft.agentKind, draft.model, draft.providerId,
)) {
setError(t('session.common.modelHiddenReselect', { model: draft.model }));
@@ -4371,7 +4482,8 @@ export default function NewRemoteSessionScreen() {
);
try {
if (!isCurrentOwner()) return;
- let effectiveDraft = draft;
+ // 选了另一台电脑的模型:模型 / 来源 / 档位与 Agent 所在电脑一起落进要创建的草稿。
+ let effectiveDraft = applyRemoteAgentPick(draft, remoteAgentPick);
// ㉙ 设备守卫全程化(独立 review P1-1/P1-2):设备快照必须取自**闭包**
// selectedDeviceId(真正会创建会话的目标设备)——selectedDeviceRef 是渲染后
// 的最新值,若用户在渲染与点击之间切了设备,ref 已属新设备而闭包 maker/目录
@@ -4384,7 +4496,7 @@ export default function NewRemoteSessionScreen() {
if (!isCurrentOwner()) return;
if (!ensureDeviceAlive()) return;
if (latestDraftText === null) return;
- effectiveDraft = { ...draft, firstMessage: latestDraftText };
+ effectiveDraft = { ...effectiveDraft, firstMessage: latestDraftText };
}
// 拍照 / 选图后立刻点创建是常见路径:等在途图片上传落定(乐观托盘)。
// 有失败就中止创建——错误文案已由上传回调写入 attachmentError,让用户处理;
@@ -4754,7 +4866,10 @@ export default function NewRemoteSessionScreen() {
model: effectiveDraft.model,
providerId: effectiveDraft.providerId,
});
- const runGuard = () => resolveSubmitGuardCatalog({
+ // Agent 在另一台电脑运行:模型属于那台的目录,不按被控电脑的目录校准(由那台在运行时核对)。
+ const runGuard = () => effectiveDraft.agentDeviceId ? Promise.resolve({
+ rows: [] as readonly ProviderModelRow[], catalogKnown: false, genAt: getDeviceProvidersGen(guardDeviceId),
+ }) : resolveSubmitGuardCatalog({
deferRefreshToCreation: true,
cached: () => getCachedDeviceProviders(guardDeviceId),
gen: () => getDeviceProvidersGen(guardDeviceId),
@@ -4854,7 +4969,10 @@ export default function NewRemoteSessionScreen() {
// 表单内预检放行(新来源已连接/空响应/瞬断)后还要经历 worktree、目录
// guard、建链、订阅多个 await,期间来源可能再变——verdict 分支若把管线
// fresh 替换成 null 会绕过最后的联合终检。
- confirmUnauthenticated: () => confirmAgentUnauthenticated(agentKindSnapshot, deviceIdSnapshot),
+ // Agent 在另一台电脑运行时,被控电脑上没有这个 Agent 的登录也照样能建:登录在那台。
+ confirmUnauthenticated: effectiveDraft.agentDeviceId
+ ? async () => ({ unauthenticated: false, fresh: null })
+ : () => confirmAgentUnauthenticated(agentKindSnapshot, deviceIdSnapshot),
// 鉴权 fresh 之后联合校验 (model, providerId)(codex review P2):建链/鉴权
// 期间工作站可能已替换 provider——patch 覆盖本次创建,不再向已删除来源发。
revalidateDraftAfterAuth: async (fresh) => {
@@ -4958,6 +5076,7 @@ export default function NewRemoteSessionScreen() {
selectedDeviceId,
selectedDeviceName,
draft,
+ remoteAgentPick,
finishVoiceRecording,
leaveForeignOutboxRecovery,
getPresenceAvailability,
@@ -5003,7 +5122,7 @@ export default function NewRemoteSessionScreen() {
setGoalError(t('session.new.enterModel'));
return;
}
- if (deviceProvidersRef.current.ready && modelNeedsReselection(
+ if (!remoteAgentPick && deviceProvidersRef.current.ready && modelNeedsReselection(
deviceProvidersRef.current.modelVisibilityOverrides, draft.agentKind, draft.model, draft.providerId,
)) {
setGoalError(t('session.common.modelHiddenReselect', { model: draft.model }));
@@ -5088,8 +5207,9 @@ export default function NewRemoteSessionScreen() {
if (!ensureDeviceAlive()) return;
evictDeviceProviders(selectedDeviceId);
}
+ // Agent 在另一台电脑运行时登录在那台:不按被控电脑的登录拦(agentAuthVerdict 此时恒为 ready)。
const freshAuth: Promise<{ unauthenticated: boolean; fresh: DeviceProvidersPayload | null }> =
- agentAuthVerdict === 'unauthenticated'
+ agentAuthVerdict === 'unauthenticated' || remoteAgentPick
? Promise.resolve({ unauthenticated: false, fresh: null })
: confirmAgentUnauthenticated(draft.agentKind, selectedDeviceId);
if (!isCurrentOwner()) return;
@@ -5156,7 +5276,8 @@ export default function NewRemoteSessionScreen() {
}
sessionId = createNewSessionId();
- let effectiveDraft = draft;
+ // 选了另一台电脑的模型:与普通创建同一份覆盖(模型、来源、档位与 Agent 所在电脑)。
+ let effectiveDraft = applyRemoteAgentPick(draft, remoteAgentPick);
if (
worktreeIntent.applicable
&& worktreeIntent.enabled
@@ -5257,7 +5378,7 @@ export default function NewRemoteSessionScreen() {
if (!isCurrentOwner()) return;
// ㉙ 远端目录已产生 → 切设备走 ledger 补偿。
if (await abortIfDeviceSwitched()) return;
- effectiveDraft = { ...draft, workingDir: response.meta.path };
+ effectiveDraft = { ...effectiveDraft, workingDir: response.meta.path };
} catch {
if (!isCurrentOwner()) return;
// create 回包前工作端可能已经完成副作用;reservation 保留给下一次
@@ -5285,7 +5406,10 @@ export default function NewRemoteSessionScreen() {
model: effectiveDraft.model,
providerId: effectiveDraft.providerId,
});
- const runGuard = () => resolveSubmitGuardCatalog({
+ // Agent 在另一台电脑运行:不按被控电脑的目录校准,也不按它的来源判登录(同 create())。
+ const runGuard = () => effectiveDraft.agentDeviceId ? Promise.resolve({
+ rows: [] as readonly ProviderModelRow[], catalogKnown: false, genAt: getDeviceProvidersGen(guardDeviceId),
+ }) : resolveSubmitGuardCatalog({
cached: () => getCachedDeviceProviders(guardDeviceId),
gen: () => getDeviceProvidersGen(guardDeviceId),
// 强制刷新(同 create() 口径,codex review P2):revalidate 必须访问工作站。
@@ -5738,6 +5862,7 @@ export default function NewRemoteSessionScreen() {
deviceProviders.providers,
confirmAgentUnauthenticated,
draft,
+ remoteAgentPick,
goalBusy,
leaveForeignOutboxRecovery,
maker,
@@ -6655,8 +6780,13 @@ export default function NewRemoteSessionScreen() {
return result;
},
onSelect: selectUnifiedModel,
+ // 远程 Agent / 供应商分享:其他电脑开放了远程调用的供应商与别人分享给这台电脑的供应商接在
+ // 后面,每个供应商一段、标题带电脑名。协同草稿与它们互斥(见 collabEligible)。
+ ...(remoteAgentSupported && !collabDraft
+ ? { remote: { catalogs: remoteAgentCatalogs, selectedDeviceId: remoteAgentPick?.deviceId ?? null } }
+ : {}),
}}
- activeModelId={draft.model}
+ activeModelId={remoteAgentPick?.model ?? draft.model}
activePermissionMode={displayPermissionMode}
agentKind={draft.agentKind}
apiKeyStatus={deviceApiKeyStatus}
@@ -6683,9 +6813,9 @@ export default function NewRemoteSessionScreen() {
permissionOptions={runtimeOptions.permissionOptions}
pricing={deviceModelPricing}
providers={deviceProviders.providers}
- selectedEffort={draft.effort}
- selectedFastMode={draft.fastMode}
- selectedProviderId={draft.providerId}
+ selectedEffort={remoteAgentPick?.effort ?? draft.effort}
+ selectedFastMode={remoteAgentPick?.fastMode ?? draft.fastMode}
+ selectedProviderId={remoteAgentPick ? remoteAgentPick.providerId : draft.providerId}
testID="newSession.modelSheet"
visible={modelSheetOpen}
/>
diff --git a/apps/mobile/src/__tests__/newSession.test.ts b/apps/mobile/src/__tests__/newSession.test.ts
index ba44e41034..a55a818e90 100644
--- a/apps/mobile/src/__tests__/newSession.test.ts
+++ b/apps/mobile/src/__tests__/newSession.test.ts
@@ -14,6 +14,7 @@ import {
type StoredAgentRestoreState,
buildNewSessionCreatePreview,
buildRecentWorkspaceOptions,
+ applyRemoteAgentPick,
buildRemoteCreateSessionOptions,
filterRemoteDirectoryEntries,
isCurrentRemoteBrowseRequest,
@@ -1267,6 +1268,25 @@ describe('new session model', () => {
});
});
+ it('runs the Agent on the picked remote computer or share', () => {
+ const draft = { ...DEFAULT_NEW_SESSION_DRAFT, workingDir: '/repo/app', firstMessage: 'hi' };
+ expect(applyRemoteAgentPick(draft, null)).toBe(draft);
+ const remote = applyRemoteAgentPick(draft, {
+ deviceId: 'share:s1', agentKind: 'codex', model: 'gpt-5.5', providerId: 'openai', effort: 'high', fastMode: true,
+ });
+ expect(remote).toMatchObject({
+ agentKind: 'codex', model: 'gpt-5.5', providerId: 'openai', effort: 'high', fastMode: true,
+ agentDeviceId: 'share:s1', workingDir: '/repo/app', firstMessage: 'hi',
+ });
+ expect(buildRemoteCreateSessionOptions(remote)).toMatchObject({
+ agentKind: 'codex', model: 'gpt-5.5', providerId: 'openai', agentDeviceId: 'share:s1',
+ });
+ expect(buildRemoteCreateSessionOptions(draft)).not.toHaveProperty('agentDeviceId');
+ // 乐观会话行一开始就带上 Agent 所在电脑,会话页按那台的目录显示模型。
+ expect(sessionFromCreateResult({ sessionId: 's' }, remote).agentDeviceId).toBe('share:s1');
+ expect(sessionFromCreateResult({ sessionId: 's' }, draft)).not.toHaveProperty('agentDeviceId');
+ });
+
it('builds folderless dialogue create-session args for controlled-side cwd allocation', () => {
expect(buildRemoteCreateSessionOptions({
...DEFAULT_NEW_SESSION_DRAFT,
@@ -1865,7 +1885,7 @@ describe('new session composer surface', () => {
expect(restoreSource).toContain('firstMessageRef.current = recovered.firstMessage;');
expect(restoreSource).toContain('firstMessageSelectionRef.current = selection;');
expect(restoreSource).toContain('setFirstMessageSelection(selection);');
- expect(newSource).toContain('restoreCreationDraft(stashed.draft, [...stashed.attachments]);');
+ expect(newSource).toContain('restoreCreationDraft(stashed.draft, [...stashed.attachments], undefined, stashed.deviceId || undefined);');
expect(newSource).toContain('restoreCreationDraft(record.creation.draft,');
});
@@ -2145,7 +2165,7 @@ describe('new session composer surface', () => {
expect(createSource).toContain('creatingRef.current = true;');
expect(createSource.indexOf('creatingRef.current = true;')).toBeLessThan(createSource.indexOf('const latestDraftText = await finishVoiceRecording();'));
expect(createSource).toContain('const latestDraftText = await finishVoiceRecording();');
- expect(createSource).toContain('effectiveDraft = { ...draft, firstMessage: latestDraftText };');
+ expect(createSource).toContain('effectiveDraft = { ...effectiveDraft, firstMessage: latestDraftText };');
expect(createSource).toContain('creatingRef.current = false;');
expect(createButtonSource).toContain('busy: creating');
expect(createButtonSource).toContain('|| worktreeBranchPreferenceSaving');
@@ -2378,7 +2398,7 @@ describe('new session worktree wiring (source locks)', () => {
expect(worktreeCreate).toBeGreaterThan(gate);
expect(sessionCreate).toBeGreaterThan(worktreeCreate);
expect(goalBody).toContain('id: sessionId,');
- expect(goalBody).toContain('effectiveDraft = { ...draft, workingDir: response.meta.path };');
+ expect(goalBody).toContain('effectiveDraft = { ...effectiveDraft, workingDir: response.meta.path };');
expect(goalBody).toContain('sessionId: precreatedWorktree!.sessionId');
expect(goalBody).toContain('sessionId: precreatedWorktree.sessionId');
});
diff --git a/apps/mobile/src/__tests__/newSessionDraftRecovery.test.ts b/apps/mobile/src/__tests__/newSessionDraftRecovery.test.ts
index fd4f483479..03578bb8c5 100644
--- a/apps/mobile/src/__tests__/newSessionDraftRecovery.test.ts
+++ b/apps/mobile/src/__tests__/newSessionDraftRecovery.test.ts
@@ -25,6 +25,7 @@ function fixture() {
setAttachments: (value: unknown[]) => { state.files = value; },
setPlanModeDraftOn: (value: boolean) => { state.plan = value; },
setDraft: vi.fn((value: typeof state.draft) => { state.draft = value; }),
+ setRemoteAgentChoice: vi.fn(),
};
const compiled = ts.transpileModule(`const apply = ${expression.getText(source)};`, { compilerOptions: { target: ts.ScriptTarget.ES2022 } }).outputText;
const apply = new Function(...Object.keys(bindings), `${compiled}\nreturn apply;`)(...Object.values(bindings));
@@ -51,6 +52,20 @@ it.each([true, false])('restores Plan=%s and makes recovered text immediately av
expect(f.runtimeActionSeqRef.current).not.toBe(10);
});
+it('splits a saved remote Agent back into the remote choice and leaves the draft local', () => {
+ const f = fixture();
+ const saved = { ...DEFAULT_NEW_SESSION_DRAFT, firstMessage: 'hi', agentKind: 'codex' as const, model: 'gpt-5.5',
+ providerId: 'openai', effort: 'high', fastMode: true, agentDeviceId: 'share:s1' };
+ f.apply(saved, [], undefined, 'controlled-a');
+ expect(f.state.draft).not.toHaveProperty('agentDeviceId');
+ expect(f.setRemoteAgentChoice).toHaveBeenCalledWith({
+ controlledDeviceId: 'controlled-a',
+ pick: { deviceId: 'share:s1', agentKind: 'codex', model: 'gpt-5.5', providerId: 'openai', effort: 'high', fastMode: true },
+ });
+ f.apply({ ...DEFAULT_NEW_SESSION_DRAFT, firstMessage: 'local' }, []);
+ expect(f.setRemoteAgentChoice).toHaveBeenLastCalledWith(null);
+});
+
it('uses the same text recovery without inventing a Plan snapshot for legacy stashes', () => {
const f = fixture();
f.state.plan = true;
diff --git a/apps/mobile/src/__tests__/newSessionWorkspaceEffects.test.tsx b/apps/mobile/src/__tests__/newSessionWorkspaceEffects.test.tsx
index 12f60842fe..4a1013f62c 100644
--- a/apps/mobile/src/__tests__/newSessionWorkspaceEffects.test.tsx
+++ b/apps/mobile/src/__tests__/newSessionWorkspaceEffects.test.tsx
@@ -34,7 +34,7 @@ const declarations = new Set([
'selectRecentProject', 'openProjectBrowse',
'firstMessageRef', 'firstMessageSelectionRef', 'firstMessageSelection',
'restoreCreationDraft', 'userTouchedRuntimeRef', 'appliedPermissionMemoryRef',
- 'runtimeActionSeqRef', 'attachments', 'attachmentsRef', 'planModeDraftOn', 'prePlanPermissionModeRef',
+ 'runtimeActionSeqRef', 'attachments', 'attachmentsRef', 'planModeDraftOn', 'prePlanPermissionModeRef', 'remoteAgentChoice',
]);
const effectMarkers = new Set([
'drainStashedNewSessionDraft', 'readNewSessionPreferences',
diff --git a/apps/mobile/src/__tests__/sessionAgentSwitchWiring.test.ts b/apps/mobile/src/__tests__/sessionAgentSwitchWiring.test.ts
index 406513eac2..f9cc872d2f 100644
--- a/apps/mobile/src/__tests__/sessionAgentSwitchWiring.test.ts
+++ b/apps/mobile/src/__tests__/sessionAgentSwitchWiring.test.ts
@@ -6,6 +6,29 @@ function readSource(relativePath: string): string {
return readFileSync(resolve(process.cwd(), relativePath), 'utf8').replace(/\r\n/g, '\n');
}
+describe('new task remote Agent wiring', () => {
+ it('lists remote and shared providers and creates the task with the Agent there', () => {
+ const source = readSource('app/sessions/new.tsx');
+ // 被控电脑支持远程 Agent 时,模型列表接上其他电脑与分享的供应商;协同草稿与之互斥。
+ expect(source).toContain('const remoteAgentCatalogs = useRemoteAgentCatalogs({');
+ expect(source).toContain('...(remoteAgentSupported && !collabDraft');
+ expect(source).toContain('remote: { catalogs: remoteAgentCatalogs, selectedDeviceId: remoteAgentPick?.deviceId ?? null }');
+ expect(source).toContain('const collabEligible = isOrcaCollabEligible(collabTarget) && remoteAgentPick === null;');
+ // 选中远程行单独记;选本机行清掉。
+ const select = source.slice(source.indexOf('const selectUnifiedModel = useCallback'), source.indexOf('const selectFlatModel'));
+ expect(select).toContain('const remoteDeviceId = source?.deviceId ?? null;');
+ expect(select).toContain('setRemoteAgentChoice({');
+ expect(select).toContain('setRemoteAgentChoice(null);');
+ // 普通创建与目标模式都把远程选择落进草稿,且不按被控电脑的目录 / 登录拦。
+ expect(source.split('applyRemoteAgentPick(draft, remoteAgentPick)')).toHaveLength(3);
+ expect(source.split('const runGuard = () => effectiveDraft.agentDeviceId ? Promise.resolve({')).toHaveLength(3);
+ expect(source).toContain('confirmUnauthenticated: effectiveDraft.agentDeviceId');
+ expect(source).toContain("agentAuthVerdict === 'unauthenticated' || remoteAgentPick");
+ // 恢复草稿时把 Agent 所在电脑拆回远程选择。
+ expect(source).toContain('const { agentDeviceId, ...recovered } = saved;');
+ });
+});
+
describe('session Agent switch UI wiring', () => {
it('keeps pending intent separate from the persisted session fields and rehydrates it', () => {
const source = readSource('app/sessions/[sessionId].tsx');
diff --git a/apps/mobile/src/session/newSession.ts b/apps/mobile/src/session/newSession.ts
index e179102c76..d30e12e25d 100644
--- a/apps/mobile/src/session/newSession.ts
+++ b/apps/mobile/src/session/newSession.ts
@@ -56,6 +56,42 @@ export interface NewSessionDraft {
fastMode: boolean;
firstMessage: string;
extraDirs?: string[];
+ /**
+ * 远程 Agent:Agent 在哪台电脑运行——同账号另一台电脑的 deviceId,或别人分享给被控电脑的
+ * 供应商(`share:<shareId>`)。缺省 / null = 被控电脑自己。只在创建时由选中的远程模型写入
+ * (见 applyRemoteAgentPick),模型与来源随之属于那台电脑的目录。
+ */
+ agentDeviceId?: string | null;
+}
+
+/**
+ * 新建任务里选中的另一台电脑上的模型(同账号远程供应商或分享来的供应商)。与草稿分开存:
+ * 草稿的模型 / 来源一直按被控电脑的目录校准,这份不受那些校准影响,创建时整体覆盖进草稿。
+ */
+export interface NewSessionRemoteAgentPick {
+ deviceId: string;
+ agentKind: NewSessionAgentKind;
+ model: string;
+ providerId: string | null;
+ effort: string;
+ fastMode: boolean;
+}
+
+/** 把选中的远程模型落进要创建的草稿;没选时原样返回。 */
+export function applyRemoteAgentPick(
+ draft: NewSessionDraft,
+ pick: NewSessionRemoteAgentPick | null,
+): NewSessionDraft {
+ if (!pick) return draft;
+ return {
+ ...draft,
+ agentKind: pick.agentKind,
+ model: pick.model,
+ providerId: pick.providerId,
+ effort: pick.effort,
+ fastMode: pick.fastMode,
+ agentDeviceId: pick.deviceId,
+ };
}
export interface CreateSessionResult {
@@ -975,6 +1011,8 @@ export function buildRemoteCreateSessionOptions(draft: NewSessionDraft): CreateS
...(effort ? { effort } : {}),
// 仅显式选了非空来源才带 providerId(空 = NULL = 被控端默认路由,对齐桌面 deviceLinkCreateArgs)。
...(providerId ? { providerId } : {}),
+ // Agent 在另一台电脑运行:与桌面新建任务同一个参数,被控电脑记进任务并经那台运行 Agent。
+ ...(draft.agentDeviceId ? { agentDeviceId: draft.agentDeviceId } : {}),
};
if (draft.workspaceKind === 'dialogue') return base;
return {
@@ -1000,7 +1038,7 @@ export function normalizeCreateSessionResult(value: unknown): CreateSessionResul
export function sessionFromCreateResult(
result: CreateSessionResult,
- fallback: Pick<NewSessionDraft, 'agentKind' | 'workspaceKind' | 'model' | 'effort' | 'permissionMode' | 'fastMode' | 'workingDir' | 'providerId'> & {
+ fallback: Pick<NewSessionDraft, 'agentKind' | 'workspaceKind' | 'model' | 'effort' | 'permissionMode' | 'fastMode' | 'workingDir' | 'providerId' | 'agentDeviceId'> & {
firstMessage?: string;
attachments?: readonly { name?: string; originalName?: string; path?: string; category?: string }[];
},
@@ -1036,6 +1074,8 @@ export function sessionFromCreateResult(
// 兜底/乐观会话必须带出来源:buildQueuedTextMessage 从这里复制 providerId 进
// createOpts,缺了它,创建确认前排队的首条消息会丢来源路由(codex review P1)。
providerId: fallback.providerId ?? null,
+ // 乐观行就带上 Agent 所在电脑:会话页的模型药丸与目录从一开始就按那台显示。
+ ...(fallback.agentDeviceId ? { agentDeviceId: fallback.agentDeviceId } : {}),
_count: { messages: 0 },
};
}
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index fe241be04e..e3cadd3d06 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -561,6 +561,10 @@ handler 无 sender 依赖;不加入共享任务访客白名单,不进入自
模型列表:A 自己的供应商之外,另列其他同账号电脑已开放远程调用的供应商(Mobile 直接经 device-link 读那台的
`maker:provider:list`,不新增 A 侧 channel);同一台电脑内换模型不带位置,换到另一台电脑先二次确认、再带
`agentDeviceId`(null = A)。共享任务访客不能换电脑。
+ Mobile 新建任务(2026-10-08)同样列出这些供应商与分享来的供应商,选中后 `maker:create-session` 带
+ `agentDeviceId`(与桌面新建同一参数,A 已接受);只有 A 的 `maker:provider:list` 带 `remoteInvocationEnabled`
+ 布尔标记时才提供(该标记与远程 Agent 同一版加入,旧 A 不列)。手机不按 A 的目录与登录校准这份选择,由运行 Agent
+ 的那台在首条消息时核对;协同草稿与之互斥。
- **供应商分享(另一个账号用 B 的供应商)**:契约见 `docs/provider-sharing-contract.md`,产品规则见
`docs/product-rules/provider-sharing.md`。relay 新增 `Envelope.providerShare` 范围与能力 `provider-share-v1`
(`packages/device-link-protocol/src/providerShare.ts`,两仓同文件),与 `sharedTask` 并列、同一帧不能同时带两种范围;
diff --git a/docs/provider-sharing-implementation-plan.md b/docs/provider-sharing-implementation-plan.md
index 8238ef7701..6ca257b291 100644
--- a/docs/provider-sharing-implementation-plan.md
+++ b/docs/provider-sharing-implementation-plan.md
@@ -41,6 +41,7 @@
- **P2 Mobile**:手机经被控电脑的同账号 channel `maker:provider-share:received-catalogs` 读取「分享给这台电脑的供应商」
并接入模型列表(标题带「来自 X 的分享」);暂停或分享者离线的分享与同账号电脑一致不列出(任务当前所在的保留);
分享链接在手机上只显示「请在电脑上打开」,口令不进路由状态与日志。只改 JS,运行时指纹不变。
+ 2026-10-08 起手机新建任务的模型列表也列出自己其他电脑的远程供应商与分享来的供应商(此前只在已建任务里能选)。
- **已知与交互稿的差异(待补)**:已暂停或分享者离线的分享在模型选择器里不显示(与同账号离线电脑一致),没有交互稿
第 6 屏的置灰分组与说明条;发送时由主进程给出「已暂停 / 已不可用 / 暂时不可用」的具体原因,用户可换模型。
受邀者草稿选中的分享不会因已收到列表暂时不完整而被自动改回本机。