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。

fix(shared-task): 仅允许房主修改模型和推理设置

davidffc592c03806
diff --git a/apps/desktop/src/main/device-link/__tests__/sharedTaskDispatch.test.ts b/apps/desktop/src/main/device-link/__tests__/sharedTaskDispatch.test.ts
index f25118613a..72754970e3 100644
--- a/apps/desktop/src/main/device-link/__tests__/sharedTaskDispatch.test.ts
+++ b/apps/desktop/src/main/device-link/__tests__/sharedTaskDispatch.test.ts
@@ -1,4 +1,4 @@
-import { sharedTaskGuestPeer } from '@cindy/device-link';
+import { authorizeSharedTaskOperation, sharedTaskGuestPeer } from '@cindy/device-link';
import { afterEach, describe, expect, it } from 'vitest';
import { assertSharedTaskInteractionResolveCurrent, assertSharedTaskInvoke, assertSharedTaskReferences, captureSharedTaskPush, setSharedTaskInteractionReader, setSharedTaskQueueReader, type SharedTaskInteractionCapture, type SharedTaskPeerCapture } from '../sharedTaskDispatch.js';
@@ -6,7 +6,11 @@ function capture(): SharedTaskPeerCapture {
return {
author: { sharedTaskId: 'sharedTask', sessionId: 'task', memberId: 'member', accountId: 'guest', displayName: 'Guest' },
isCurrent: () => true,
- authorize: (operation, item) => operation !== 'input.edit' && operation !== 'input.withdraw' || item?.authorAccountId === 'guest',
+ authorize: (operation, item) => authorizeSharedTaskOperation({
+ sharedTaskId: 'sharedTask', sessionId: 'task', ownerAccountId: 'owner', hostDeviceId: 'host',
+ status: 'active', revision: 1,
+ guests: [{ memberId: 'member', accountId: 'guest', version: 1, deviceIds: ['phone'] }],
+ }, { accountId: 'guest', deviceId: 'phone' }, 'task', operation, item).allowed,
};
}
afterEach(() => { setSharedTaskQueueReader(null); setSharedTaskInteractionReader(null); });
@@ -39,12 +43,23 @@ describe('sharedTask dispatch scope', () => {
}
expect(() => assertSharedTaskInvoke(capture(), { channel: 'device-link:subscribe', args: [{ topics: ['session:task'] }] })).not.toThrow();
});
- it('allows shared task history and Agent settings, rejecting another task', () => {
- for (const channel of ['local-db:messages:list', 'maker:set-model', 'maker:set-effort', 'maker:input:stop']) {
+ it('allows shared task history and stopping the Agent, rejecting another task', () => {
+ for (const channel of ['local-db:messages:list', 'maker:input:stop']) {
expect(() => assertSharedTaskInvoke(capture(), { channel, args: ['task'] })).not.toThrow();
expect(() => assertSharedTaskInvoke(capture(), { channel, args: ['other'] })).toThrow();
}
});
+ it.each([
+ ['maker:set-model', ['task', 'gpt-6-sol', 'openai', undefined, { effort: 'high', fastMode: true }]],
+ ['maker:set-effort', ['task', 'high']],
+ ['maker:set-fast-mode', ['task', true]],
+ ['maker:set-thinking-enabled', ['task', true]],
+ ['maker:switch-session-agent', ['task', 'codex', 'gpt-6-sol', 'openai']],
+ ])('rejects guest model settings through %s before execution or result replay', (channel, args) => {
+ for (const phase of ['invoke', 'result'] as const) {
+ expect(() => assertSharedTaskInvoke(capture(), { channel, args }, undefined, phase)).toThrow('PERMISSION_DENIED');
+ }
+ });
it('allows guests to resolve generic Agent interaction cards for the shared task', () => {
const permissionSuggestion = { type: 'addRules', behavior: 'allow', destination: 'session', rules: [{ toolName: 'Bash', ruleContent: 'git status' }] };
const interactions: Record<string, SharedTaskInteractionCapture> = {
diff --git a/apps/desktop/src/main/device-link/sharedTaskDispatch.ts b/apps/desktop/src/main/device-link/sharedTaskDispatch.ts
index df966bd63f..7e2ad3e1db 100644
--- a/apps/desktop/src/main/device-link/sharedTaskDispatch.ts
+++ b/apps/desktop/src/main/device-link/sharedTaskDispatch.ts
@@ -71,7 +71,7 @@ const sessionReads = new Set([
'maker:get-pending-interactions', 'maker:get-session-agent-switch-intent',
]);
const inputEdits = new Set(['maker:input:update-text', 'maker:input:update-content', 'maker:input:set-edit-lock']);
-const agentSettings = new Set(['maker:set-model', 'maker:set-effort', 'maker:set-fast-mode', 'maker:set-thinking-enabled', 'maker:switch-session-agent']);
+// Model, Agent and reasoning changes belong to the owner, including result replay.
const interactionDecisionKinds = new Set(['permission', 'ask_user_question', 'plan_review']);
function record(value: unknown): Record<string, unknown> | null {
@@ -235,8 +235,7 @@ export function assertSharedTaskInvoke(
: ['maker:input:enqueue', 'maker:input:steer', 'maker:input:resume', 'maker:input:set-expanded'].includes(channel) ? 'input.send'
: channel === 'maker:input:stop' ? 'agent.stop'
: channel === 'maker:input:remove' ? 'input.withdraw'
- : inputEdits.has(channel) ? 'input.edit'
- : agentSettings.has(channel) ? 'agent.configure' : null;
+ : inputEdits.has(channel) ? 'input.edit' : null;
if (!operation) deny();
if (phase === 'result') {
if (!capture.authorize('history.read')) deny();
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/sharedTaskInput.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/sharedTaskInput.test.ts
index c7c00073c5..b1c2bfaf61 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/sharedTaskInput.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/sharedTaskInput.test.ts
@@ -19,6 +19,8 @@ describe('sharedTask input uses the task Agent authority', () => {
expect(result.createOpts).toEqual(task);
expect(result.permissionMode).toBe(permissionMode);
expect(result.workingDir).toBe('host-workdir');
+ expect(result.model).toBe('host-model');
+ expect(result.effort).toBe('');
expect(result).not.toHaveProperty('vendorOptions');
expect(result).not.toHaveProperty('turnPermissionPolicy');
expect(result.sharedTaskAuthor).toEqual(author);
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/sharedTaskSetting.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/sharedTaskSetting.test.ts
index b52d01987d..19cbb8588c 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/sharedTaskSetting.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/sharedTaskSetting.test.ts
@@ -1,4 +1,5 @@
import { describe, expect, it, vi } from 'vitest';
+import { authorizeSharedTaskOperation } from '@cindy/device-link';
import { createSharedTaskSettingGuard } from '../sharedTaskSetting.js';
import { applyRuntimeSetModelChange } from '../runtimeSetModel.js';
import { commitRuntimeAxisAfterPersistence } from '../runtimeSelectionAxes.js';
@@ -13,6 +14,31 @@ function harness() {
return { guard, transaction, revoke() { current = false; } };
}
describe('sharedTask setting admission', () => {
+ it('rejects an active guest at the model mutation boundary using the real permission policy', async () => {
+ const transaction = { admitted: false };
+ const guard = createSharedTaskSettingGuard({
+ author: { sharedTaskId: 'sharedTask', sessionId: 'task', memberId: 'guest', accountId: 'account', displayName: 'Guest' },
+ isCurrent: () => true,
+ authorize: (operation) => authorizeSharedTaskOperation({
+ sharedTaskId: 'sharedTask', sessionId: 'task', ownerAccountId: 'owner', hostDeviceId: 'host',
+ status: 'active', revision: 1,
+ guests: [{ memberId: 'guest', accountId: 'account', version: 1, deviceIds: ['phone'] }],
+ }, { accountId: 'account', deviceId: 'phone' }, 'task', operation).allowed,
+ }, 'task', transaction);
+ const setModel = vi.fn();
+ const closeSession = vi.fn();
+ const session = { agentKind: 'claude-code' as const, model: 'host-model', setModel };
+
+ await expect(applyRuntimeSetModelChange({
+ maker: { getSession: () => session, listActiveSessions: () => [], closeSession },
+ sessionId: 'task', model: 'guest-model', admit: guard.admit,
+ })).rejects.toThrow('PERMISSION_DENIED');
+
+ expect(transaction.admitted).toBe(false);
+ expect(setModel).not.toHaveBeenCalled();
+ expect(closeSession).not.toHaveBeenCalled();
+ expect(session.model).toBe('host-model');
+ });
it('rechecks membership after async model preflight, before any runtime change', async () => {
const h = harness();
const setModel = vi.fn();
diff --git a/apps/desktop/src/renderer/__tests__/sessionAgentSwitchRemoteRouting.test.ts b/apps/desktop/src/renderer/__tests__/sessionAgentSwitchRemoteRouting.test.ts
index 1f69418ed1..e099c16dad 100644
--- a/apps/desktop/src/renderer/__tests__/sessionAgentSwitchRemoteRouting.test.ts
+++ b/apps/desktop/src/renderer/__tests__/sessionAgentSwitchRemoteRouting.test.ts
@@ -1148,8 +1148,8 @@ describe('ChatInput 的入口门控与调用路由', () => {
);
// 签名显式声明 Promise<boolean> —— 返回值是契约的一部分,不靠推断。
expect(body).toContain('): Promise<boolean> => {');
- // 「没落地」的四个出口:无会话 / pending send 拒绝 / 会话已切走 / ack 被超车。
- expect(body).toContain('if (!sessionId) return false;');
+ // 「没落地」的出口:无会话或设置只读 / pending send 拒绝 / 会话已切走 / ack 被超车。
+ expect(body).toContain('if (!sessionId || settingsLocked) return false;');
expect(body).toContain('if (hasPendingAgentSendDispatch(sessionId)) return false;');
expect(body).toContain("if (ackAction === 'discard') return false;");
// 同引擎重选被修订号守卫拒下 = 没落地。
diff --git a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
index 52076e5262..869e3a3683 100644
--- a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx
@@ -1194,7 +1194,7 @@ export function ChatInput({
onFastModeChange,
onWorkingDirChange,
disabled,
- settingsLocked = false,
+ settingsLocked: settingsLockedProp = false,
isStreaming = false,
isAgentBusy,
onStop,
@@ -1261,6 +1261,8 @@ export function ChatInput({
// 预测守卫用原始值区分 null vs undefined,下游通路继续用 ?? undefined 归一化。
const deviceLinkDeviceId = _deviceLinkDeviceId;
const sharedGuest = isSharedTaskPeer(deviceLinkDeviceId ?? '');
+ // The host owns model, Agent and reasoning settings; guests can still send input.
+ const settingsLocked = settingsLockedProp || sharedGuest;
const selfDeviceId = useOptionalAuthDeviceId();
/**
* 远程控制的被控电脑上的任务(已建任务,或建到被控电脑的新任务草稿),Agent 同样可以在第三台电脑
@@ -6701,7 +6703,7 @@ export function ChatInput({
// 分支末尾的 isAgentSwitchEchoConfigConsistent)同样返 false —— 三元组落了不等于
// 这份完整配置落了,调用方挂在 true 上的持久化收尾(清 override / 提交・删除收藏
// 编辑 / 写收藏锚点)一律不做。只有完整配置原样成为权威意图 / 已应用才返 true。
- if (!sessionId) return false;
+ if (!sessionId || settingsLocked) return false;
// 发送的引用水合 / 预检也可能 await。以同步登记的 session 级发送 token 为准,
// 防止「先点发送、后选引擎」被异步准备反转成先登记切换再 maker:send。
if (hasPendingAgentSendDispatch(sessionId)) return false;
@@ -7012,6 +7014,7 @@ export function ChatInput({
},
[
sessionId,
+ settingsLocked,
activeEffort,
resolveModelEfforts,
getRememberedEffort,
@@ -9235,6 +9238,7 @@ export function ChatInput({
: true
}
onThinkingChange={async (enabled) => {
+ if (settingsLocked) return;
if (currentModelAgentKind && effectiveSourceId) {
if (modelMemory?.setThinking) {
modelMemory.setThinking(
diff --git a/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputModelLoading.test.tsx b/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputModelLoading.test.tsx
index 806455825b..ae383401f6 100644
--- a/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputModelLoading.test.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputModelLoading.test.tsx
@@ -4,6 +4,7 @@ import { afterEach, beforeEach, expect, it, vi } from 'vitest';
import { useState, type ComponentProps, type ReactNode } from 'react';
import type { Editor } from '@tiptap/react';
import type { ProviderView } from '@cindy/model-providers';
+import { sharedTaskHostPeer } from '@cindy/device-link';
import { sshNativeCodexProvider, sshModel } from '@/features/cc-agent/__tests__/sshModelFixtures';
import { ChatInput } from '../ChatInput';
import * as providerMemory from '@/state/providerModelMemory';
@@ -37,9 +38,9 @@ vi.mock('@/components/sidebar/SortableList', () => ({
</div>
),
}));
-vi.mock('../ModelSelector', async (original) => ({ ...await original<typeof import('../ModelSelector')>(), ModelSelector: ({ modelId, onModelChange }: { modelId: string; onModelChange: typeof h.selectModel }) => {
+vi.mock('../ModelSelector', async (original) => ({ ...await original<typeof import('../ModelSelector')>(), ModelSelector: ({ modelId, onModelChange, disabled }: { modelId: string; onModelChange: typeof h.selectModel; disabled?: boolean }) => {
h.selectModel = onModelChange;
- return <span data-testid="model-selector">{modelId}</span>;
+ return <button data-testid="model-selector" disabled={disabled}>{modelId}</button>;
} }));
vi.mock('@/hooks/useSshCodexProviders', () => ({ useSshCodexProviders: () => ({ providers: h.remoteProviders, status: h.remoteStatus, refresh: () => {} }) }));
vi.mock('../ExtraDirsButton', () => ({ ExtraDirsButton: () => null }));
@@ -96,6 +97,21 @@ const props = {
hideRuntimeControls: true, showFolderPicker: false, disableAutofocus: true,
};
+it('keeps the shared guest model visible but locks selection without locking message input', async () => {
+ const onSend = vi.fn().mockResolvedValue(undefined);
+ const inputProps = { ...props, hideRuntimeControls: false, initialModel: 'gpt-6-sol', onSend };
+ const view = render(<ChatInput {...inputProps} deviceLinkDeviceId={sharedTaskHostPeer('shared', 'host')} />);
+ const selector = () => screen.getByTestId('model-selector') as HTMLButtonElement;
+ expect(selector().textContent).toBe('gpt-6-sol');
+ expect(selector().disabled).toBe(true);
+ await act(async () => { expect(await h.selectModel?.('other-model')).toBe(false); });
+ expect(h.setModel).not.toHaveBeenCalled();
+ expect(h.editor?.isEditable).toBe(true);
+
+ await act(async () => { view.rerender(<ChatInput {...inputProps} deviceLinkDeviceId="host" />); });
+ expect(selector().disabled).toBe(false);
+});
+
const queuedMessage = {
clientId: 'queue-edit-test',
text: 'Queued message',
diff --git a/apps/mobile/app/sessions/[sessionId].tsx b/apps/mobile/app/sessions/[sessionId].tsx
index 1e8e8efae9..c518d9c95a 100644
--- a/apps/mobile/app/sessions/[sessionId].tsx
+++ b/apps/mobile/app/sessions/[sessionId].tsx
@@ -2518,6 +2518,9 @@ export default function SessionScreen() {
const canUseRemoteSessionControls = canUseComposer
&& !sessionSettingsLocked
&& !remoteRealtimeControlsUnavailable;
+ const canConfigureSessionModel = canUseRemoteSessionControls
+ && !sessionManagedByHost
+ && !isSharedTaskPeer(deviceId);
// 共享模型自造的那两条禁发理由是中文直出,而它会经 composer 与队列行的
// accessibility hint 读给用户 —— 按 locale 翻译后再用,否则读屏在 en / ja / ko
// 下念混语(#530 review)。调用方自己传进去的理由(离线 / 只读 / 同步中)已本地化,
@@ -3237,6 +3240,10 @@ export default function SessionScreen() {
setPermissionSheetOpen(false);
}, [canUseRemoteSessionControls]);
+ useEffect(() => {
+ if (!canConfigureSessionModel) setModelSheetOpen(false);
+ }, [canConfigureSessionModel]);
+
useEffect(() => {
if (!sessionManagedByHost) return;
setSettingsOpen(false);
@@ -6967,7 +6974,7 @@ export default function SessionScreen() {
) : null}
{!sessionManagedByHost && composerRuntimeSummary ? (
<ComposerRuntimePill
- disabled={sessionManagedByHost || controlBusy || !canUseRemoteSessionControls}
+ disabled={controlBusy || !canConfigureSessionModel}
accessibilityLabel={composerRuntimeAccessibilityLabel}
fastOn={composerPillFastOn}
label={composerRuntimeLabel}
@@ -7780,7 +7787,7 @@ export default function SessionScreen() {
const writeSessionAgentSwitchIntent = useCallback(async (
nextIntent: NonNullable<RemoteSession['agentSwitchIntent']>,
): Promise<boolean> => {
- if (!deviceId || controlBusy) return false;
+ if (!deviceId || controlBusy || isSharedTaskPeer(deviceId)) return false;
// 会话未建成或明确断线时不写切换意图。这里是全部 agent-switch 写入的唯一出口,
// 门放在这里而不是各调用点,新增入口不会漏。
if (!canUseRemoteSessionControls) return false;
@@ -8138,6 +8145,7 @@ export default function SessionScreen() {
targetContextWindow?: number;
selection?: { effort: string | null; fastMode: boolean };
}): Promise<boolean> => {
+ if (!canConfigureSessionModel) return false;
if (shouldBlockLegacyRemoteModelWindowSwitch({
hostGuardSupported: modelSheetCapabilities?.supportsModelWindowSwitchGuard === true,
agentKind: sessionAgentKind,
@@ -8166,6 +8174,7 @@ export default function SessionScreen() {
return false;
}
}, [
+ canConfigureSessionModel,
currentSession?.contextTokens,
currentSession?.contextWindow,
maker,
@@ -8389,6 +8398,7 @@ export default function SessionScreen() {
return true;
}, [agentSwitchIntent, modelSheetAgentKind, sessionAgentKind, sessionAgentSwitchSupported]);
const changeComposerSelectedEffort = useCallback((effort: string) => {
+ if (!canConfigureSessionModel) return;
// 跨引擎 intent,或已登记「改回被控电脑」的同引擎 intent:改 intent 本身(带着位置),
// 否则 setEffort 的值会在发送时被 intent 里的旧值盖回。
if (
@@ -8401,8 +8411,9 @@ export default function SessionScreen() {
if (modelSheetAgentKind === sessionAgentKind) {
void runControlAction(() => maker.setEffort(sessionId, effort), { effort });
}
- }, [agentSwitchIntent, maker, modelSheetAgentKind, runControlAction, sessionAgentKind, sessionId, writeSessionAgentSwitchIntent]);
+ }, [agentSwitchIntent, canConfigureSessionModel, maker, modelSheetAgentKind, runControlAction, sessionAgentKind, sessionId, writeSessionAgentSwitchIntent]);
const changeComposerSelectedFastMode = useCallback((enabled: boolean) => {
+ if (!canConfigureSessionModel) return;
if (
(modelSheetAgentKind !== sessionAgentKind || intentChangesAgentLocation(agentSwitchIntent))
&& agentSwitchIntent?.targetAgentKind === modelSheetAgentKind
@@ -8413,9 +8424,9 @@ export default function SessionScreen() {
if (modelSheetAgentKind === sessionAgentKind) {
void runControlAction(() => maker.setFastMode(sessionId, enabled), { fastMode: enabled });
}
- }, [agentSwitchIntent, maker, modelSheetAgentKind, runControlAction, sessionAgentKind, sessionId, writeSessionAgentSwitchIntent]);
+ }, [agentSwitchIntent, canConfigureSessionModel, maker, modelSheetAgentKind, runControlAction, sessionAgentKind, sessionId, writeSessionAgentSwitchIntent]);
const toggleComposerModelPicker = useCallback(() => {
- if (sessionManagedByHost || !canUseRemoteSessionControls) {
+ if (!canConfigureSessionModel) {
setModelSheetOpen(false);
return;
}
@@ -8425,7 +8436,7 @@ export default function SessionScreen() {
}
setModelSheetAgentKind(agentSwitchIntent?.targetAgentKind ?? sessionAgentKind);
setModelSheetOpen(true);
- }, [agentSwitchIntent, canUseRemoteSessionControls, modelSheetOpen, sessionAgentKind, sessionManagedByHost]);
+ }, [agentSwitchIntent, canConfigureSessionModel, modelSheetOpen, sessionAgentKind]);
// 账号限额按需拉取(会话信息面板打开时):优先走 Codex app-server 权威控制面,
// 同时拿窗口和 reset credits。老被控端没有新通道时回退既有只读 usage channel;
@@ -9586,8 +9597,8 @@ export default function SessionScreen() {
)}
</ContextSheet>
)}</MountOnFirstOpen>
- <MountOnFirstOpen open={modelSheetOpen && canUseRemoteSessionControls}>{() => (
- currentSession && !sessionManagedByHost && runtimeOptions && modelSheetSelection && modelSheetRuntimeOptions ? (
+ <MountOnFirstOpen open={modelSheetOpen && canConfigureSessionModel}>{() => (
+ currentSession && canConfigureSessionModel && runtimeOptions && modelSheetSelection && modelSheetRuntimeOptions ? (
<ModelPickerSheet
unified={{
currentSelection: { agentKind: sessionAgentKind, activeModelId: currentSession.model, selectedProviderId: currentSession.providerId ?? null, selectedEffort: currentSession.effort ?? '', selectedFastMode: !!currentSession.fastMode },
@@ -9646,7 +9657,7 @@ export default function SessionScreen() {
selectedFastMode={modelSheetSelection.fastMode}
selectedProviderId={modelSheetSelection.providerId}
testID="session.modelSheet"
- visible={modelSheetOpen && canUseRemoteSessionControls}
+ visible={modelSheetOpen && canConfigureSessionModel}
/>
) : null
)}</MountOnFirstOpen>
diff --git a/apps/mobile/src/__tests__/sessionAgentSwitchWiring.test.ts b/apps/mobile/src/__tests__/sessionAgentSwitchWiring.test.ts
index f9cc872d2f..807e6f140e 100644
--- a/apps/mobile/src/__tests__/sessionAgentSwitchWiring.test.ts
+++ b/apps/mobile/src/__tests__/sessionAgentSwitchWiring.test.ts
@@ -30,6 +30,30 @@ describe('new task remote Agent wiring', () => {
});
describe('session Agent switch UI wiring', () => {
+ it('locks guest model controls while preserving message and stop controls', () => {
+ const source = readSource('app/sessions/[sessionId].tsx');
+ const modelAccess = source.slice(source.indexOf('const canConfigureSessionModel'), source.indexOf('// 共享模型自造'));
+ expect(modelAccess).toContain('canUseRemoteSessionControls');
+ expect(modelAccess).toContain('!sessionManagedByHost');
+ expect(modelAccess).toContain('!isSharedTaskPeer(deviceId)');
+ expect(source).toContain('disabled={controlBusy || !canConfigureSessionModel}');
+ expect(source).toContain('visible={modelSheetOpen && canConfigureSessionModel}');
+ expect(source).toContain('if (!canConfigureSessionModel) setModelSheetOpen(false);');
+ for (const [start, end] of [
+ ['const setComposerModel', '// 选行 = 原子切'],
+ ['const changeComposerSelectedEffort', 'const changeComposerSelectedFastMode'],
+ ['const changeComposerSelectedFastMode', 'const toggleComposerModelPicker'],
+ ['const toggleComposerModelPicker', '// 账号限额按需拉取'],
+ ]) {
+ const handler = source.slice(source.indexOf(start), source.indexOf(end, source.indexOf(start)));
+ expect(handler).toContain('if (!canConfigureSessionModel)');
+ }
+ const writer = source.slice(source.indexOf('const writeSessionAgentSwitchIntent'), source.indexOf('const setComposerModel'));
+ expect(writer).toContain('if (!deviceId || controlBusy || isSharedTaskPeer(deviceId)) return false;');
+ const controls = source.slice(source.indexOf('const canUseComposer ='), source.indexOf('const canConfigureSessionModel'));
+ expect(controls).not.toContain('isSharedTaskPeer');
+ });
+
it('keeps pending intent separate from the persisted session fields and rehydrates it', () => {
const source = readSource('app/sessions/[sessionId].tsx');
expect(source).toContain('maker.getSessionAgentSwitchIntent(sessionId)');
@@ -201,7 +225,8 @@ describe('session Agent switch UI wiring', () => {
expect(alertHelper).toContain(
"{ text: t('models.contextWindowSwitch.cancel'), style: 'cancel' }",
);
- expect(helper.match(/return false;/g)).toHaveLength(2);
+ // Read-only guest guard plus the two legacy window-switch rejection paths.
+ expect(helper.match(/return false;/g)).toHaveLength(3);
expect(helper).not.toContain('setError(');
expect(controlAction).toContain('applied === false && rollbackPatch && deviceId');
expect(controlAction).toContain('setError(formatRemoteError(err));');
diff --git a/docs/product-rules/shared-task-mode.md b/docs/product-rules/shared-task-mode.md
index f3cfea44f8..cb20575668 100644
--- a/docs/product-rules/shared-task-mode.md
+++ b/docs/product-rules/shared-task-mode.md
@@ -1,6 +1,6 @@
# 共享任务:远程连接的多人版本
-> 产品裁决更新:2026-09-29。实现与验证进度见文末;本文不代表已上线。
+> 产品裁决更新:2026-10-10。实现与验证进度见文末;本文不代表已上线。
> 产品、代码、协议与存储统一使用“共享任务 / SharedTask”,开发期旧协议不保留兼容别名。
## 定位
@@ -35,7 +35,7 @@
## 权限与顺序
- 任务由原桌面运行,模型费用沿用房主连接;同账号远控行为不变。
-- 访客可发消息、使用附件和语音输入、修改 Agent/模型/推理设置、停止 Agent。
+- 访客可发消息、使用附件和语音输入、停止 Agent;Agent、模型和推理设置仅房主可修改(2026-10-10 用户裁决)。桌面与手机访客保留当前模型展示,但不可打开修改入口;房主端同时校验请求权限,旧版访客也不能绕过。
- Agent 工具、shell、已有插件/MCP 沿用任务现有权限,Full Access 语义不变;任务内 Agent 的 permission、ask_user_question、plan_review 交互由房主和协作者都可决策,其他房主管理确认仍由房主处理。不添加访客专属沙箱、per-turn 权限或工具审批。邀请意味着房主信任访客使用该任务的 Agent 能力。
- 房主保留共享管理、归档/删除/导出/分支、权限模式、工作目录、插件/MCP 配置和后台/定时任务管理权限。
- 访客通过客户端接口只能直接访问共享任务及其资源,不能调用全局凭证、其他任务或任意主机文件接口。Agent 原生工具不承诺工作目录硬隔离。
@@ -65,6 +65,7 @@
- 同时校验 invoke、push、历史、附件、嵌套引用、离线补发与结果缓存的任务及成员归属。
- 共享附件使用 `cindy/device-link/shared-task/<sharedTaskId>/<uploaderAccountId>/<uuid.ext>`,复用既有中转前缀的 OSS 授权与生命周期;共享路径仍按任务和当前成员校验,不回退为同账号对象权限。客户端与服务端同步升级,不保留未发布开发版顶层 `cindy/shared-task/` 路径别名;普通远控附件路径不变。
- Desktop 与 Mobile 复用现有任务页面;房主在手机上通过既有同账号远控管理共享。网页端和匿名访客不在范围内。
+- Agent/模型/推理设置的房主专属限制由房主 Desktop 执行,生效需要房主升级;新版访客界面也禁用修改入口。旧访客连接新版房主时,设置请求沿用现有权限错误返回;不修改 wire 格式、同账号 allowlist 或服务端成员关系。
- 新协议以能力协商开放;缺少能力提示升级。两区域独立,不默认跨区域加入。
- 关闭记录必须落入原 profile 的 journal 后才能释放数据库;本地同步撤权,服务端失败下次恢复重试。
- 同一 profile 的非 relay 持有实例归档/删除任务,也必须写入该 profile 的共享关闭记录,并以操作开始时捕获的账号凭证尝试关闭服务端共享。Host 在既有 5 秒刷新周期先消化本地关闭记录、使现有授权捕获失效,再查询服务端;relay 离线或服务端读取失败不能跳过本地撤权。此机制只关闭对应共享,不重启 relay 或影响其他任务。
@@ -184,7 +185,7 @@
启动参数、端点与端口以 [Desktop 开发规则](../dev-rules/desktop-development.md) 为准;包装脚本会停止当前 checkout 的旧开发实例,因此不要在同一个 checkout 连续执行两次来模拟双客户端。也可用 Desktop 房主加 Mobile 访客;手机端点必须是手机可达的测试服务地址。
3. 房主打开已有任务,开启共享并复制邀请。访客从菜单加入,确认无需审批即可进入普通任务页,能够查看加入前的消息、工具结果和附件。
4. 同时发送不同内容,确认两个客户端看到同一 Agent 输出及正确作者。Agent 忙时编辑或撤回自己的待发送消息;修改其他成员的待发送消息应失败。编辑带图片的消息,保留旧附件并增加新附件,确认发送后和重载后都可打开。
-5. 分别验证切换 Agent、模型和推理设置、停止 Agent、普通权限与 Full Access。任务内 Agent 弹出的 permission、ask_user_question、plan_review 交互由房主或访客选择后继续执行。
+5. 分别验证只有房主(含同账号远控)能切换 Agent、模型和推理设置,访客界面与直接请求均不可修改;访客仍可停止 Agent。普通权限与 Full Access 保持原有语义;任务内 Agent 弹出的 permission、ask_user_question、plan_review 交互由房主或访客选择后继续执行。
6. 访客断网后重连,确认有效共享与历史恢复。房主断线后 60 秒内重连保留共享;持续离线超过宽限后共享关闭、旧邀请失效,上线后需重新开启。房主主动关闭或退出账号立即关闭共享。单个访客断线时,另一个访客及同账号远控继续工作。
7. 验证移除、退出、停止共享、归档和登出。旧邀请不能恢复已退出或移除的身份,新邀请可以重新加入;未共享任务与主机全局设置不可经访客客户端访问。
8. 验证本地工作区及 SSH 工作区的图片、音频、视频,检查 Light/Dark 和小屏。旧服务端或旧客户端应提示升级,不得退化成全设备控制。
@@ -247,3 +248,12 @@
- CN Android 模拟器连接 dev 服务,使用真实跨账号共享验证:手动输入旧邀请码后直接进入任务;成员使用账号昵称;取消退出保留原页签;房主取消共享后显示结束态,返回任务列表。
- 已目检浅色、深色的真实“我加入的”列表与浅色空状态;此模拟器账号无自己发起的共享,有内容的“我发起的”列表和 iOS 未实机目检,不能以组件测试替代。
- Mobile 全量单测 7,525 项通过、11 项按条件跳过;后续空状态调整的定向回归 37 项通过。Desktop、Mobile 类型检查、i18n key 一致性和术语检查通过。测试共享已取消,原有其他共享保留。
+
+### 模型修改权限验收(2026-10-10)
+
+- 基于 `da77ac386` 主干与本次修复,启动两个独立 checkout、独立 userData 的 CN Electron dev,使用两个真实账号完成开启共享、复制邀请与加入。
+- 访客显示当前模型但选择按钮禁用;访客正常发送消息并收到真实 Agent 回复。房主通过模型选择器选择 GPT-6.1-Sol,按既有“下条消息”行为发送后生效,访客同步显示新模型且仍不可修改。
+- 从真实访客客户端绕过界面,经 device-link 分别调用 `maker:set-model`、`maker:set-effort`、`maker:set-fast-mode`、`maker:set-thinking-enabled`、`maker:switch-session-agent`,五项均返回 `PERMISSION_DENIED`;前后读取房主任务配置,模型、Agent、effort、fastMode 均未改变。
+- 已目检真实访客任务页的 Light/Dark 模型展示与禁用状态,截图:[Light](../verification/shared-task-model-permissions/guest-light.png)、[Dark](../verification/shared-task-model-permissions/guest-dark.png)。Desktop 定向测试 315 项(含提交前新增的实际模型变更入口回归)、Mobile 定向测试 58 项、device-link 权限测试 35 项及三个相关 package 类型检查通过。
+- 本轮未进行 Mobile 实机、旧版访客或同账号远控实机验收;不以双 Desktop 结果替代这些验证。
+- 验收结束后已取消本次测试共享,确认访客共享列表不再包含该任务,并恢复访客原有主题设置;隔离沙盒与测试任务记录保留。
diff --git a/docs/verification/shared-task-model-permissions/guest-dark.png b/docs/verification/shared-task-model-permissions/guest-dark.png
new file mode 100644
index 0000000000..c7b62a80ff
Binary files /dev/null and b/docs/verification/shared-task-model-permissions/guest-dark.png differ
diff --git a/docs/verification/shared-task-model-permissions/guest-light.png b/docs/verification/shared-task-model-permissions/guest-light.png
new file mode 100644
index 0000000000..013d8202a4
Binary files /dev/null and b/docs/verification/shared-task-model-permissions/guest-light.png differ
diff --git a/packages/device-link/src/__tests__/sharedTask.test.ts b/packages/device-link/src/__tests__/sharedTask.test.ts
index 1e1ddff625..a7a71e0c29 100644
--- a/packages/device-link/src/__tests__/sharedTask.test.ts
+++ b/packages/device-link/src/__tests__/sharedTask.test.ts
@@ -48,14 +48,14 @@ describe('sharedTask authorization', () => {
}
expect(isSharedTaskAttachment('file:///private/file.png', 'shared')).toBe(false);
});
- it.each(['history.read', 'attachment.read', 'attachment.upload', 'input.send', 'agent.configure', 'agent.stop', 'approval.resolve'])(
+ it.each(['history.read', 'attachment.read', 'attachment.upload', 'input.send', 'agent.stop', 'approval.resolve'])(
'lets an approved guest %s without treating them as the owner', (operation) => {
expect(authorize(parse(snapshot()), guest, 'session-1', operation)).toMatchObject({ allowed: true, role: 'guest', memberId: 'member-a' });
},
);
- it.each(['permission.configure', 'workdir.configure', 'plugins.configure',
+ it.each(['agent.configure', 'permission.configure', 'workdir.configure', 'plugins.configure',
'history.delete', 'session.archive', 'session.export', 'session.fork', 'background.create', 'schedule.create', 'sharedTask.manage'])(
- 'requires the owner for %s even when a guest can configure the model', (operation) => {
+ 'requires the owner for %s', (operation) => {
expect(authorize(parse(snapshot()), guest, 'session-1', operation)).toEqual({ allowed: false, reason: 'owner-required' });
expect(authorize(parse(snapshot()), owner, 'session-1', operation)).toMatchObject({ allowed: true, role: 'host' });
},
diff --git a/packages/device-link/src/sharedTask.ts b/packages/device-link/src/sharedTask.ts
index ba8248b1d8..2a45d339bd 100644
--- a/packages/device-link/src/sharedTask.ts
+++ b/packages/device-link/src/sharedTask.ts
@@ -81,10 +81,10 @@ export type SharedTaskDecision =
const sharedOperations: ReadonlySet<string> = new Set<SharedTaskOperation>([
'history.read', 'events.subscribe', 'attachment.read', 'attachment.upload',
- 'file.read', 'input.send', 'agent.stop', 'agent.configure', 'approval.resolve',
+ 'file.read', 'input.send', 'agent.stop', 'approval.resolve',
]);
const ownerOperations: ReadonlySet<string> = new Set<SharedTaskOperation>([
- 'permission.configure', 'workdir.configure', 'plugins.configure',
+ 'agent.configure', 'permission.configure', 'workdir.configure', 'plugins.configure',
'history.delete', 'session.archive', 'session.export', 'session.fork',
'background.create', 'schedule.create', 'sharedTask.manage',
]);