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(desktop,mobile): worktree 勾选状态只属于用户 + 分支/worktree 联合控件

Kafeifei244bc72a5738
diff --git a/apps/desktop/src/renderer/__tests__/branchPick.test.ts b/apps/desktop/src/renderer/__tests__/branchPick.test.ts
index 37c40c4e28..cdad1a990c 100644
--- a/apps/desktop/src/renderer/__tests__/branchPick.test.ts
+++ b/apps/desktop/src/renderer/__tests__/branchPick.test.ts
@@ -1,10 +1,12 @@
/**
- * branchPick.test.ts — 分支 chip 点选语义(纯函数)回归。
+ * branchPick.test.ts — 分支区点选语义(纯函数)回归。
*
- * 语义契约(与 WorktreeChipsRow 的 BranchChip 配合):
+ * 语义契约(2026-07-29 用户裁决,与 WorktreeChipsRow 的联合控件配合):
+ * - worktree 勾选状态只属于用户,分支选择永不隐式改动它
+ * (effect 种类里没有 enable-worktree,这是硬性回归线)
* - worktree ON:选分支 = 改源分支;选当前源分支 no-op
- * - worktree OFF:选当前 HEAD 分支 no-op;选其它分支 = 自动开 worktree 从该分支启动
- * - 永远不产生"checkout 用户 checkout"的效果(effect 种类里根本没有这个选项)
+ * - worktree OFF:分支区只读;防御性触达一律 no-op
+ * - 永远不产生"checkout 用户 checkout"的效果
*/
import { describe, expect, it } from 'vitest';
@@ -29,32 +31,26 @@ describe('resolveBranchPick', () => {
).toEqual({ kind: 'noop' });
});
- it('worktree OFF: picking the repo HEAD branch is a no-op', () => {
+ it('worktree OFF: any pick is a no-op — selection must never flip the checkbox', () => {
+ // 用户裁决:勾选状态只有用户本人能改。旧的「OFF 选其它分支自动开 worktree」
+ // 已删除;OFF 时分支区只读,防御性触达也绝不产生状态副作用。
expect(
resolveBranchPick(
{ worktreeEnabled: false, currentBranch: 'main', sourceBranch: '' },
'main',
),
).toEqual({ kind: 'noop' });
- });
-
- it('worktree OFF: picking another branch enables worktree from it', () => {
expect(
resolveBranchPick(
{ worktreeEnabled: false, currentBranch: 'main', sourceBranch: '' },
'feat/x',
),
- ).toEqual({ kind: 'enable-worktree', branch: 'feat/x' });
- });
-
- it('worktree OFF with unknown HEAD (detached): any pick enables worktree', () => {
- // detached HEAD 时 currentBranch 为 null,没有"就是当前分支"可言,
- // 任何选择都按隔离启动处理。
+ ).toEqual({ kind: 'noop' });
expect(
resolveBranchPick(
{ worktreeEnabled: false, currentBranch: null, sourceBranch: '' },
'main',
),
- ).toEqual({ kind: 'enable-worktree', branch: 'main' });
+ ).toEqual({ kind: 'noop' });
});
});
diff --git a/apps/desktop/src/renderer/__tests__/newMakerProjectPicker.test.ts b/apps/desktop/src/renderer/__tests__/newMakerProjectPicker.test.ts
index 8fcd961e6b..5a2e95eab3 100644
--- a/apps/desktop/src/renderer/__tests__/newMakerProjectPicker.test.ts
+++ b/apps/desktop/src/renderer/__tests__/newMakerProjectPicker.test.ts
@@ -22,6 +22,11 @@ const worktreeChipsSource = readFileSync(
'utf8',
);
+const branchPickSource = readFileSync(
+ resolve(__dirname, '..', 'components', 'new-chat', 'branchPick.ts'),
+ 'utf8',
+);
+
const folderPickerPopoverSource = readFileSync(
resolve(__dirname, '..', 'components', 'new-chat', 'FolderPickerPopover.tsx'),
'utf8',
@@ -129,33 +134,43 @@ describe('Shared create project picker', () => {
it('hides worktree controls for pure-dialogue drafts without a selected project', () => {
// advancedHidden 把 "project 模式 + 无 cwd" 归到 dialogue 上下文,
- // 让 worktree chip / worktree state effect / effectiveWorktreeEnabled 用同一个 flag 拦掉。
- // 自动关闭必须走 handleAutoDisable(只关 UI、不写工作端勾选记忆),
- // 不得回退成直接调 onEnabledChange(那会把环境因素当用户显式切换持久化)。
+ // 让联合控件 / effectiveWorktreeEnabled 用同一个 flag 拦掉。
expect(worktreeChipsSource).toContain(
"const advancedHidden = folderPickerMode === 'project' && !cwd",
);
- expect(worktreeChipsSource).toContain('if (advancedHidden && enabled) handleAutoDisable()');
- expect(worktreeChipsSource).toContain('{!advancedHidden && (');
expect(worktreeChipsSource).toContain(
'const effectiveWorktreeEnabled = enabled && !advancedHidden && !worktreeDisabled',
);
});
- it('persists the worktree preference only on explicit chip toggles (three-tier semantics)', () => {
- // 2026-07-28「勾选状态保存在工作端」三档语义:
- // chip 点击(source='chip')= 显式表态 → 写工作端记忆(本地 patchDraft / 远程写穿);
- // 分支菜单 enable-worktree(source='branch-pick')= 本次草稿流程副作用 → 不落偏好;
- // 资格自动关闭(handleAutoDisable)= 仅 UI。
- expect(worktreeChipsSource).toContain("onToggle(!checked, 'chip')");
- expect(worktreeChipsSource).toContain("onEnabledChange(true, 'branch-pick')");
- expect(newMakerDraftRouteSource).toContain("if (source !== 'chip') return;");
+ it('keeps the worktree checkbox owned by the user alone (2026-07-29 invariant)', () => {
+ // 用户裁决:勾选状态只属于用户——
+ // 1) 组件内不存在任何自动改写 enabled 的 effect(资格变化只禁用、不改状态);
+ // 2) 分支选择不承担隐式开关语义(branchPick 无 enable-worktree effect);
+ // 3) 用户点击 checkbox 是唯一改动路径,且必写穿工作端记忆(本地 patchDraft /
+ // device-link 远程 apply-new-maker-worktree-pref);
+ // 4) checkbox 原样直出记忆(播种无 baseRepo 点亮门槛),发送侧按
+ // 「勾选 && baseRepo 就绪」静默降级,不报错拦截。
+ expect(worktreeChipsSource).not.toMatch(/onEnabledChange\(false\)/);
+ expect(worktreeChipsSource).not.toContain('handleAutoDisable');
+ expect(worktreeChipsSource).toContain('onToggle(!checked)');
+ expect(branchPickSource).not.toContain('enable-worktree');
expect(newMakerDraftRouteSource).toContain("'maker:apply-new-maker-worktree-pref'");
- // 播种点亮门槛:enabled=true 必须蕴含 detect 已回填 baseRepo,
- // 否则「偏好 ON + 挂载后立即发送」会撞 handleSend 的 worktreeMissingRepo 硬错误。
- expect(newMakerDraftRouteSource).toContain(
- 'setWtEnabled(effectiveWorkingDir != null && wtBaseRepo != null && worktreePref)',
+ expect(newMakerDraftRouteSource).toContain('setWtEnabled(worktreePref)');
+ expect(newMakerDraftRouteSource).toContain('wt.enabled && wt.baseRepo');
+ expect(newMakerDraftRouteSource).not.toContain('worktreeMissingRepo');
+ });
+
+ it('merges branch and worktree into a single joined pill (Claude Code style)', () => {
+ // 2026-07-29 用户裁决:[⎇ 分支 │ ☑ worktree] 是一个 pill、两个点击区。
+ // 未勾时分支区只读(菜单不可开);已勾时分支菜单 = worktree 源分支选择器。
+ expect(worktreeChipsSource).toContain('function BranchWorktreeChip');
+ expect(worktreeChipsSource).toContain('data-testid="create-agent-branch-worktree"');
+ expect(worktreeChipsSource).toContain(
+ 'const branchInteractive = !disabled && effectiveWorktreeEnabled',
);
+ expect(worktreeChipsSource).not.toContain('function BranchChip');
+ expect(worktreeChipsSource).not.toContain('function WorktreeChip(');
});
it('keeps remote project drafts out of local workspace probes', () => {
diff --git a/apps/desktop/src/renderer/components/new-chat/WorktreeChipsRow.tsx b/apps/desktop/src/renderer/components/new-chat/WorktreeChipsRow.tsx
index 3ce3d757b6..16fec23431 100644
--- a/apps/desktop/src/renderer/components/new-chat/WorktreeChipsRow.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/WorktreeChipsRow.tsx
@@ -1,19 +1,20 @@
/**
- * WorktreeChipsRow — folder chip + 分支 chip + worktree 勾选 chip。
+ * WorktreeChipsRow — folder chip + [分支 │ ☑ worktree] 联合控件。
*
* 2026-07(分支外显,Codex 风格)把 Branch 从齿轮 popover 提到独立 chip;
- * 2026-07-28 再把 worktree 开关本身也提为一级勾选 chip,齿轮 Advanced popover
- * 整体移除(popover 里只剩它一项,藏一层纯属多余):
- * - folder chip 是主操作;分支 chip 常态显示仓库当前 HEAD 分支,
- * worktree ON 时显示 worktree 源分支(带主色提示,与 worktree chip 同款)
- * - 点分支 chip 弹分支列表:worktree ON 时改源分支;OFF 时选非当前分支
- * 自动开启 worktree(语义见 branchPick.ts —— 绝不 checkout 用户的 checkout)
- * - worktree chip 点击即切换;不可用(非 git 仓库等)时禁用并以 tooltip 说明原因
+ * 2026-07-28 把 worktree 开关提为一级勾选 chip、齿轮 Advanced popover 移除;
+ * 2026-07-29 用户裁决(对齐 Claude Code):分支与 worktree 合并为**一个** pill——
+ * 左半分支区、竖分隔线、右半 checkbox + "worktree",两个点击区各管各的。
*
- * 勾选状态的持久化语义(2026-07-28):onEnabledChange 只承载**用户显式切换**
- * (chip 点击 / 分支菜单触发的 enable-worktree),上层据此写工作端勾选记忆;
- * 资格不满足触发的自动关闭走 onAutoDisable,只关 UI、绝不写穿偏好——
- * 环境因素(切到非 git 目录)不该抹掉用户的选择。
+ * 状态不变量(2026-07-29 用户裁决,最高优先):**勾选状态只属于用户**——
+ * - checkbox 原样直出工作端勾选记忆;选分支 / 切项目 / 资格变化都不改它;
+ * - 唯一改动路径 = 用户点击 checkbox 本体(onEnabledChange,上层必持久化);
+ * - 旧的「选非当前分支自动开 worktree」「资格不满足自动关」全部删除;
+ * - 环境不合格(已在 worktree 内 / SSH / 探测中)只是禁用 checkbox + tooltip,
+ * 发送时由上层按「勾选 && 合格」静默降级,记忆永不被抹。
+ *
+ * 分支区语义:未勾 = 只读展示仓库当前 HEAD(会话就跑在它上面);已勾 = worktree
+ * 源分支选择器(默认当前分支,点开可换;见 branchPick.ts)。
*
* worktree 名称 **自动生成**(不暴露 UI),由 useSuggestName 拉取后透传给上层。
*/
@@ -57,17 +58,10 @@ export interface WorktreeChipsRowProps {
emptyProjectLabel?: string;
enabled: boolean;
/**
- * 用户切换 worktree。source 区分意图强度,供上层决定是否写工作端勾选记忆:
- * - 'chip':点 worktree chip 本体,是对「默认启用 worktree」的显式表态 → 持久化;
- * - 'branch-pick':分支菜单选非当前分支的自动开启,是本次草稿的流程副作用 →
- * 只改本次 UI,不该悄悄改掉全局默认(防误操作口径)。
- */
- onEnabledChange: (v: boolean, source: 'chip' | 'branch-pick') => void;
- /**
- * 系统强制关闭(资格不满足 / 入口隐藏 / SSH 禁用)。只应关 UI 态,不写偏好。
- * 缺省回落 onEnabledChange(false)(兼容旧调用方,但会把自动关闭当显式切换持久化)。
+ * 用户点击 checkbox 本体切换 worktree——**唯一**的状态改动路径,上层必持久化
+ * (写工作端勾选记忆)。系统任何路径都不得调用它替用户翻状态。
*/
- onAutoDisable?: () => void;
+ onEnabledChange: (v: boolean) => void;
sourceBranch: string;
onSourceBranchChange: (v: string) => void;
onBaseRepoChange?: (baseRepo: string | null) => void;
@@ -100,7 +94,6 @@ export function WorktreeChipsRow({
emptyProjectLabel,
enabled,
onEnabledChange,
- onAutoDisable,
sourceBranch,
onSourceBranchChange,
onBaseRepoChange,
@@ -134,25 +127,8 @@ export function WorktreeChipsRow({
const switchDisabled = disabled || worktreeDisabled || !!cantUseReason || detect.loading || !cwd;
- // 自动关闭统一走 onAutoDisable(只关 UI、不持久化);旧调用方未传时回落 onEnabledChange
- // (branch-pick 档,同样不该被当成显式表态)。
- const handleAutoDisable = useCallback(() => {
- if (onAutoDisable) onAutoDisable();
- else onEnabledChange(false, 'branch-pick');
- }, [onAutoDisable, onEnabledChange]);
-
- useEffect(() => {
- if (detect.loading) return;
- if (cantUseReason && enabled) handleAutoDisable();
- }, [cantUseReason, enabled, handleAutoDisable, detect.loading]);
-
- useEffect(() => {
- if (advancedHidden && enabled) handleAutoDisable();
- }, [advancedHidden, enabled, handleAutoDisable]);
-
- useEffect(() => {
- if (worktreeDisabled && enabled) handleAutoDisable();
- }, [worktreeDisabled, enabled, handleAutoDisable]);
+ // 状态不变量:这里**没有**任何自动改写 enabled 的 effect——勾选状态只属于用户,
+ // 资格不满足只体现为 checkbox 禁用(switchDisabled)+发送侧「勾选 && 合格」降级。
const effectiveWorktreeEnabled = enabled && !advancedHidden && !worktreeDisabled;
// 分支列表懒加载 latch:worktree 未开时不预拉,首次点开分支 chip 菜单才拉,
@@ -206,8 +182,9 @@ export function WorktreeChipsRow({
? sourceBranch || branches.current || 'main'
: (currentBranch ?? '');
const showBranchChip = !advancedHidden && !!detect.data?.isGitRepo && branchLabel !== '';
- // 只读场景:worktree 开不了(已在 worktree 内 / 探测中)时 chip 仅展示不弹菜单。
- const branchChipInteractive = !disabled && (effectiveWorktreeEnabled || !switchDisabled);
+ // 分支菜单只在 worktree 已勾时可交互(= 源分支选择器);未勾时分支区只读展示当前
+ // HEAD——选分支不再承担任何隐式开关语义(状态不变量,见文件头)。
+ const branchInteractive = !disabled && effectiveWorktreeEnabled;
const handleBranchPick = useCallback(
(picked: string) => {
@@ -215,53 +192,38 @@ export function WorktreeChipsRow({
{ worktreeEnabled: effectiveWorktreeEnabled, currentBranch, sourceBranch: branchLabel },
picked,
);
- if (effect.kind === 'set-source') {
- onSourceBranchChange(effect.branch);
- } else if (effect.kind === 'enable-worktree') {
- // 同帧一起写:sourceBranch 非空会让"worktree 开启后回填 current"的
- // effect 自然跳过,不会覆盖用户的选择。
- onEnabledChange(true, 'branch-pick');
- onSourceBranchChange(effect.branch);
- }
+ if (effect.kind === 'set-source') onSourceBranchChange(effect.branch);
},
- [effectiveWorktreeEnabled, currentBranch, branchLabel, onSourceBranchChange, onEnabledChange],
+ [effectiveWorktreeEnabled, currentBranch, branchLabel, onSourceBranchChange],
);
- const branchChip = showBranchChip ? (
- <BranchChip
- label={branchLabel}
+ const branchWorktree = showBranchChip ? (
+ <BranchWorktreeChip
+ branchLabel={branchLabel}
branches={branches.branches}
- loading={branches.loading}
- failed={branches.failed}
- onRetry={branches.refetch}
- worktreeEnabled={effectiveWorktreeEnabled}
- interactive={branchChipInteractive}
+ branchesLoading={branches.loading}
+ branchesFailed={branches.failed}
+ onRetryBranches={branches.refetch}
+ checked={enabled}
+ branchInteractive={branchInteractive}
+ checkboxDisabled={switchDisabled}
+ cantUseReason={cantUseReason ?? undefined}
onPick={handleBranchPick}
onOpenRequested={() => {
setBranchListWanted(true);
// 上次拉取失败的话,重新打开菜单就自动重试一次,不逼用户去点重试项。
if (branches.failed && !branches.loading) branches.refetch();
}}
+ onToggle={onEnabledChange}
compact={compact}
/>
) : null;
- // advancedOnly:项目选择交给页面自己的 pill,这里出 [分支 chip][worktree chip]
- // (cwd 为空时随 advancedHidden 整体不渲染,与 full 变体同一套隐藏/清状态 effect)。
+ // advancedOnly:项目选择交给页面自己的 pill,这里出 [分支 │ ☑ worktree] 联合控件
+ // (cwd 为空 / 非 git 仓库时整体不渲染)。
if (variant === 'advancedOnly') {
if (advancedHidden) return null;
- return (
- <>
- {branchChip}
- <WorktreeChip
- checked={enabled}
- onToggle={onEnabledChange}
- switchDisabled={switchDisabled}
- cantUseReason={cantUseReason ?? undefined}
- compact={compact}
- />
- </>
- );
+ return branchWorktree;
}
return (
@@ -287,16 +249,7 @@ export function WorktreeChipsRow({
onOpenChange={onFolderPickerOpenChange}
disabled={disabled}
/>
- {branchChip}
- {!advancedHidden && (
- <WorktreeChip
- checked={enabled}
- onToggle={onEnabledChange}
- switchDisabled={switchDisabled}
- cantUseReason={cantUseReason ?? undefined}
- compact={compact}
- />
- )}
+ {branchWorktree}
</div>
);
}
@@ -391,107 +344,114 @@ function FolderChipBig({
);
}
-// ── 分支 chip:常显当前/源分支,点开选分支 ──────────────────
+// ── [分支 │ ☑ worktree] 联合控件(对齐 Claude Code,2026-07-29 用户裁决) ──────
-function BranchChip({
- label,
+function BranchWorktreeChip({
+ branchLabel,
branches,
- loading,
- failed,
- onRetry,
- worktreeEnabled,
- interactive,
+ branchesLoading,
+ branchesFailed,
+ onRetryBranches,
+ checked,
+ branchInteractive,
+ checkboxDisabled,
+ cantUseReason,
onPick,
onOpenRequested,
+ onToggle,
compact,
}: {
- label: string;
+ branchLabel: string;
branches: string[];
- loading: boolean;
+ branchesLoading: boolean;
/** 上次分支列表请求失败(区分于"仓库没分支"),菜单给重试入口。 */
- failed: boolean;
- onRetry: () => void;
- worktreeEnabled: boolean;
- interactive: boolean;
+ branchesFailed: boolean;
+ onRetryBranches: () => void;
+ /** worktree 勾选状态(工作端记忆原样直出;禁用时也照常显示,不做视觉造假)。 */
+ checked: boolean;
+ /** 分支菜单是否可开(仅已勾时 = 源分支选择器;未勾只读展示当前 HEAD)。 */
+ branchInteractive: boolean;
+ checkboxDisabled?: boolean;
+ cantUseReason?: string;
onPick: (branch: string) => void;
/** 菜单打开时通知上层解锁分支列表懒加载(失败态由上层顺带自动重试)。 */
onOpenRequested: () => void;
+ /** 用户点击 checkbox——唯一的状态改动路径(上层持久化到工作端)。 */
+ onToggle: (v: boolean) => void;
compact?: boolean;
}) {
const { t } = useTranslation();
- const trigger = (
+ const branchSegment = (
<button
type="button"
- disabled={!interactive}
+ disabled={!branchInteractive}
data-testid="create-agent-branch-chip"
className={cn(
- 'inline-flex items-center rounded-full border transition-colors',
+ 'inline-flex h-full min-w-0 items-center transition-colors',
// 只读态不弹菜单但也不该像 disabled 一样淡出 —— 分支信息本身是有效展示。
- !interactive && 'cursor-default',
+ !branchInteractive && 'cursor-default',
compact
- ? 'h-[30px] max-w-[220px] gap-1.5 border-[var(--create-agent-control-border)] bg-[var(--create-agent-control-bg)] px-3 text-[12px] font-medium leading-[14px] text-[var(--create-agent-control-text)]'
- : 'h-[42px] max-w-[260px] gap-2.5 border-border bg-[var(--chat-input-bg)] px-[18px] text-[14px] font-medium text-foreground',
- interactive &&
+ ? 'max-w-[180px] gap-1.5 pl-3 pr-2 text-[12px] font-medium leading-[14px]'
+ : 'max-w-[220px] gap-2.5 pl-[18px] pr-2.5 text-[14px] font-medium',
+ branchInteractive &&
(compact
? 'hover:bg-[var(--create-agent-control-bg-hover)] active:bg-[var(--create-agent-control-bg-pressed)]'
: 'hover:bg-sidebar-item-hover'),
- // worktree ON 时与齿轮同款主色提示:一眼看出"这是隔离启动的源分支"。
- worktreeEnabled && 'border-primary/50 text-primary',
- worktreeEnabled && interactive && 'hover:bg-primary/10',
+ // 勾选时主色提示与容器边框呼应:一眼看出"这是隔离启动的源分支"。
+ checked && 'text-primary',
+ checked && branchInteractive && 'hover:bg-primary/10',
)}
aria-label={t('newChat.branchChip.label')}
>
<GitBranch size={compact ? 12 : 15} className="shrink-0" />
- <span className="min-w-0 truncate">{label}</span>
- {interactive && (
+ <span className="min-w-0 truncate">{branchLabel}</span>
+ {branchInteractive && (
<ChevronDown
size={12}
- className={cn('shrink-0', worktreeEnabled ? 'text-primary' : 'text-muted-foreground')}
+ className={cn('shrink-0', checked ? 'text-primary' : 'text-muted-foreground')}
/>
)}
</button>
);
- const tipped = (
+ const branchTipped = (
<Tip
text={
- worktreeEnabled
+ checked
? t('newChat.branchChip.sourceTooltip')
: t('newChat.branchChip.currentTooltip')
}
>
- {trigger}
+ {branchSegment}
</Tip>
);
- if (!interactive) return tipped;
-
- return (
+ const branchArea = branchInteractive ? (
<DropdownMenu
onOpenChange={(open) => {
if (open) onOpenRequested();
}}
>
- <DropdownMenuTrigger asChild>{tipped}</DropdownMenuTrigger>
+ <DropdownMenuTrigger asChild>{branchTipped}</DropdownMenuTrigger>
<DropdownMenuContent
align="end"
sideOffset={4}
className="max-h-[280px] min-w-[200px] overflow-y-auto rounded-xl border border-border bg-popover p-1 shadow-lg"
>
- {loading ? (
+ {branchesLoading ? (
<div className="px-3 py-1.5 text-[13px] text-muted-foreground">
{t('newChat.branchChip.loading')}
</div>
- ) : failed || branches.length === 0 ? (
+ ) : branchesFailed || branches.length === 0 ? (
/* 失败与空列表都给重试入口(空列表也可能是隧道/瞬时问题);
onSelect 阻止默认关闭,重试期间菜单留在原地显示 loading。 */
<DropdownMenuItem
onSelect={(e) => {
e.preventDefault();
- onRetry();
+ onRetryBranches();
}}
- className="cursor-pointer rounded-md px-3 py-1.5 text-[13px] text-muted-foreground focus:bg-accent focus:text-accent-foreground"
+ className="cursor-pointer rounded-[8px] px-3 py-1.5 text-[13px] text-muted-foreground focus:bg-accent focus:text-accent-foreground"
>
{t('newChat.branchChip.loadFailed')}
</DropdownMenuItem>
@@ -501,67 +461,42 @@ function BranchChip({
key={b}
onSelect={() => onPick(b)}
className={cn(
- 'cursor-pointer rounded-md px-3 py-1.5 text-[13px] text-foreground',
+ 'cursor-pointer rounded-[8px] px-3 py-1.5 text-[13px] text-foreground',
'focus:bg-accent focus:text-accent-foreground',
- b === label && 'bg-accent/60',
+ b === branchLabel && 'bg-accent/60',
)}
>
{b}
</DropdownMenuItem>
))
)}
- {/* worktree OFF 时说明点选语义:不动当前 checkout,以 worktree 隔离启动。 */}
- {!worktreeEnabled && (
- <div className="mt-1 border-t border-border px-3 pb-1 pt-1.5 text-[11px] leading-snug text-muted-foreground">
- {t('newChat.branchChip.worktreeHint')}
- </div>
- )}
</DropdownMenuContent>
</DropdownMenu>
+ ) : (
+ branchTipped
);
-}
-// ── worktree 勾选 chip:一级入口,点击即切换(原齿轮 Advanced popover 已移除) ──────
-
-function WorktreeChip({
- checked,
- onToggle,
- switchDisabled,
- cantUseReason,
- compact,
-}: {
- checked: boolean;
- /** 用户显式切换(source='chip',上层持久化偏好);disabled 态不触发。 */
- onToggle: (v: boolean, source: 'chip') => void;
- switchDisabled?: boolean;
- cantUseReason?: string;
- compact?: boolean;
-}) {
- const { t } = useTranslation();
-
- const btn = (
+ const checkboxSegment = (
<button
type="button"
- onClick={() => !switchDisabled && onToggle(!checked, 'chip')}
- disabled={switchDisabled}
+ onClick={() => !checkboxDisabled && onToggle(!checked)}
+ disabled={checkboxDisabled}
data-testid="create-agent-worktree-chip"
+ aria-pressed={checked}
+ aria-label={t('newChat.worktree.toggleAria')}
className={cn(
- 'inline-flex items-center rounded-full border transition-colors',
+ 'inline-flex h-full items-center transition-colors',
'disabled:cursor-not-allowed disabled:opacity-50',
- // compact:30px 紧凑版,取 create-agent 控件 token 与新建页 mode pill / 分支 chip 同排同调
compact
- ? 'h-[30px] gap-1.5 border-[var(--create-agent-control-border)] bg-[var(--create-agent-control-bg)] px-3 text-[12px] font-medium leading-[14px] text-[var(--create-agent-control-text)]'
- : 'h-[42px] gap-2.5 border-border bg-[var(--chat-input-bg)] px-[18px] text-[14px] font-medium text-foreground',
- !switchDisabled &&
+ ? 'gap-1.5 pl-2 pr-3 text-[12px] font-medium leading-[14px]'
+ : 'gap-2.5 pl-2.5 pr-[18px] text-[14px] font-medium',
+ !checkboxDisabled &&
(compact
? 'hover:bg-[var(--create-agent-control-bg-hover)] active:bg-[var(--create-agent-control-bg-pressed)]'
: 'hover:bg-sidebar-item-hover'),
- // ON 时与分支 chip 同款主色提示:一眼看出"这次对话将以 worktree 隔离启动"。
- checked && 'border-primary/50 text-primary',
- checked && !switchDisabled && 'hover:bg-primary/10',
+ checked && 'text-primary',
+ checked && !checkboxDisabled && 'hover:bg-primary/10',
)}
- aria-pressed={checked}
- aria-label={t('newChat.worktree.toggleAria')}
>
<span
className={cn(
@@ -592,22 +527,45 @@ function WorktreeChip({
</button>
);
- // 不可用时以 tooltip 说明原因(替代旧 popover 内的行内禁用提示);
- // 可用时 tooltip 解释语义,与分支 chip 的 tooltip 口径一致。
- if (switchDisabled && cantUseReason) {
- return (
+ // 不可用时 tooltip 说明原因;可用时解释语义。禁用只针对 checkbox 半区,
+ // 分支信息照常展示——环境不合格不该把整条控件打成灰。
+ const checkboxArea =
+ checkboxDisabled && cantUseReason ? (
<Tooltip.Root>
<Tooltip.Trigger asChild>
- <span className="inline-flex" tabIndex={0}>
- {btn}
+ <span className="inline-flex h-full" tabIndex={0}>
+ {checkboxSegment}
</span>
</Tooltip.Trigger>
<Tooltip.Content side="top">{cantUseReason}</Tooltip.Content>
</Tooltip.Root>
+ ) : checkboxDisabled ? (
+ checkboxSegment
+ ) : (
+ <Tip text={t('newChat.worktree.chipTooltip')}>{checkboxSegment}</Tip>
);
- }
-
- if (switchDisabled) return btn;
- return <Tip text={t('newChat.worktree.chipTooltip')}>{btn}</Tip>;
+ return (
+ <div
+ data-testid="create-agent-branch-worktree"
+ className={cn(
+ 'inline-flex items-stretch overflow-hidden rounded-full border transition-colors',
+ compact
+ ? 'h-[30px] border-[var(--create-agent-control-border)] bg-[var(--create-agent-control-bg)] text-[var(--create-agent-control-text)]'
+ : 'h-[42px] border-border bg-[var(--chat-input-bg)] text-foreground',
+ // 勾选时与旧分支 chip 同款主色边框提示。
+ checked && 'border-primary/50',
+ )}
+ >
+ {branchArea}
+ <span
+ aria-hidden
+ className={cn(
+ 'w-px shrink-0 self-center',
+ compact ? 'h-[14px] bg-[var(--create-agent-control-border)]' : 'h-[18px] bg-border',
+ )}
+ />
+ {checkboxArea}
+ </div>
+ );
}
diff --git a/apps/desktop/src/renderer/components/new-chat/branchPick.ts b/apps/desktop/src/renderer/components/new-chat/branchPick.ts
index a87e482d2c..c80b13aeb7 100644
--- a/apps/desktop/src/renderer/components/new-chat/branchPick.ts
+++ b/apps/desktop/src/renderer/components/new-chat/branchPick.ts
@@ -1,15 +1,16 @@
/**
- * branchPick — 分支 chip 点选语义的纯函数(与 UI 解耦,便于单测)。
+ * branchPick — 分支区点选语义的纯函数(与 UI 解耦,便于单测)。
*
- * 语义(Codex 风格「选分支 = 从该分支启动」):
- * - worktree 已开:选中的分支就是 worktree 源分支,选当前源分支为 no-op;
- * - worktree 未开:选中仓库当前分支为 no-op(会话本来就跑在它上面);
- * 选其它分支 → 自动开启 worktree 并以该分支为源 —— 绝不 checkout 用户的
- * checkout(可能有脏改动),隔离启动是唯一安全语义。
+ * 2026-07-29 用户裁决(worktree 勾选状态只属于用户,系统永不隐式改动):
+ * - worktree 已勾:分支菜单 = worktree 源分支选择器,选当前源分支为 no-op;
+ * - worktree 未勾:分支区只读展示当前 HEAD,菜单不打开——旧的「选其它分支
+ * 自动开启 worktree」隐式联动已删除,任何路径都不再替用户翻动勾选状态。
+ * 想从别的分支启动 = 先勾 worktree、再选源分支(全部显式)。
+ * - 永远不产生"checkout 用户 checkout"的效果(effect 种类里根本没有这个选项)。
*/
export interface BranchPickState {
- /** worktree 开关当前是否开启(effective,即未被 advancedHidden 等禁用)。 */
+ /** worktree 勾选状态(用户记忆原样直出;未勾时分支区只读,不应触达本函数)。 */
worktreeEnabled: boolean;
/** 仓库当前 HEAD 分支;detached / 未知时为 null。 */
currentBranch: string | null;
@@ -19,14 +20,11 @@ export interface BranchPickState {
export type BranchPickEffect =
| { kind: 'noop' }
- | { kind: 'set-source'; branch: string }
- | { kind: 'enable-worktree'; branch: string };
+ | { kind: 'set-source'; branch: string };
export function resolveBranchPick(state: BranchPickState, picked: string): BranchPickEffect {
- if (state.worktreeEnabled) {
- if (picked === state.sourceBranch) return { kind: 'noop' };
- return { kind: 'set-source', branch: picked };
- }
- if (state.currentBranch !== null && picked === state.currentBranch) return { kind: 'noop' };
- return { kind: 'enable-worktree', branch: picked };
+ // 未勾时分支区只读(UI 不开菜单);防御性兜底:即使被触达也绝不改勾选状态。
+ if (!state.worktreeEnabled) return { kind: 'noop' };
+ if (picked === state.sourceBranch) return { kind: 'noop' };
+ return { kind: 'set-source', branch: picked };
}
diff --git a/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsx b/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsx
index 4f5e41a00e..4215b02b14 100644
--- a/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsx
@@ -713,21 +713,18 @@ export function NewMakerDraftRoute() {
});
}, [isDeviceLinkDraft, effectiveDeviceLinkDeviceId, capabilityAgentKind, capabilities]);
- // ── worktree 勾选播种:UI 态 = 工作端勾选记忆 ──────────────────────────────
+ // ── worktree 勾选 = 工作端记忆的镜像(2026-07-29 用户裁决:状态只属于用户) ────
// 本地草稿读本地 draft.worktreeEnabled;device-link 远程草稿读被控端镜像
// (remoteDraftState.value.worktreeEnabled,vendor 无关根字段,拉取完成前保持关,
- // 不闪开)。切项目 / 设备 / 偏好回流时重播种;资格不满足时 WorktreeChipsRow 经
- // onAutoDisable 只关 UI(不写偏好),偏好保留,下次切到合格仓库自动恢复勾选。
- // 额外用 wtBaseRepo 做点亮门槛:enabled=true 必须蕴含 detect 已回填 repoRoot——
- // 改造前该不变量由「开关在探测期禁用」保证,播种若在 detect 在途时先置 true,
- // 「偏好 ON + 挂载后立即发送」会撞 handleSend 的 worktreeMissingRepo 硬错误
- // (远程隧道探测窗口达数百毫秒)。detect 回填后本 effect 随 wtBaseRepo 变化再点亮。
+ // 不闪开)。checkbox **原样直出**记忆——不做 baseRepo/资格点亮门槛、没有任何
+ // 自动开关;环境合格性只影响 checkbox 禁用态与发送时是否真的走 worktree
+ // (handleSend 按「勾选 && baseRepo 就绪」静默降级,绝不报错拦截、绝不改记忆)。
const worktreePref = isDeviceLinkDraft
? remoteDraftState.loaded && remoteDraftState.value?.worktreeEnabled === true
: draft.worktreeEnabled;
useEffect(() => {
- setWtEnabled(effectiveWorkingDir != null && wtBaseRepo != null && worktreePref);
- }, [isDeviceLinkDraft, effectiveDeviceLinkDeviceId, effectiveWorkingDir, worktreePref, wtBaseRepo]);
+ setWtEnabled(worktreePref);
+ }, [isDeviceLinkDraft, effectiveDeviceLinkDeviceId, worktreePref]);
// modelMemoryOverride:非选中行读镜像、改动经隧道写穿被控端(active=false)。providerId 由
// ModelSelector 按行传入(每行各自的供应商)。写失败(旧版被控端 / 离线)静默吞 —— 乐观本地镜像
@@ -895,10 +892,9 @@ export function NewMakerDraftRoute() {
dlSeedKeyRef.current = `${target.deviceId}:${capabilityAgentKind}`;
setDlSel(resolveDeviceLinkDraftDefaults(freshCaps, freshDefaults, undefined, capabilityAgentKind));
setRemoteDraftState({ loaded: true, value: freshDefaults });
- // worktree 勾选先复位:新项目的 detect 经隧道回填 baseRepo 后,播种 effect
- // (worktreePref × wtBaseRepo 门槛)再按被控端记忆点亮——不在探测在途时先亮,
- // 避免「已勾但 baseRepo 未就绪」状态下发送撞 worktreeMissingRepo。
- setWtEnabled(false);
+ // worktree 勾选镜像被控端记忆原样直出(状态只属于用户,不做点亮门槛);
+ // baseRepo / 源分支等新项目的 detect 经隧道回填。
+ setWtEnabled(freshDefaults?.worktreeEnabled === true);
setWtBaseRepo(null);
setWtSourceBranch('');
// patchDraft 会改 effectiveDeviceLinkDeviceId → 触发 defaults effect 重拉;
@@ -1198,14 +1194,12 @@ export function NewMakerDraftRoute() {
[handleWorkingDirChange],
);
- // 用户切换 worktree:更新 UI 态;只有点 chip 本体(source='chip')才写穿「工作端
- // 勾选记忆」——本地草稿写本地 newMakerDraft 根字段;device-link 远程草稿把状态写到
+ // 用户点击 checkbox——**唯一**的勾选状态改动路径(2026-07-29 裁决),必写穿「工作端
+ // 勾选记忆」:本地草稿写本地 newMakerDraft 根字段;device-link 远程草稿把状态写到
// 被控端(状态归工作端所有,控制端只是远程操作器,与手机端同语义)。
- // 分支菜单 enable-worktree(source='branch-pick')是本次草稿的流程副作用,不改全局默认;
- // 资格不满足触发的自动关闭走 handleWtAutoDisable,同样只关 UI、不落偏好。
- const handleWtEnabledChange = useCallback((enabled: boolean, source: 'chip' | 'branch-pick') => {
+ // 旧的 source 分档已随「分支菜单不再隐式开 worktree」删除。
+ const handleWtEnabledChange = useCallback((enabled: boolean) => {
setWtEnabled(enabled);
- if (source !== 'chip') return;
if (isDeviceLinkDraft && effectiveDeviceLinkDeviceId) {
window.electronAPI.deviceLink
.invoke(effectiveDeviceLinkDeviceId, 'maker:apply-new-maker-worktree-pref', [
@@ -1219,9 +1213,6 @@ export function NewMakerDraftRoute() {
}
patchDraft({ worktreeEnabled: enabled });
}, [isDeviceLinkDraft, effectiveDeviceLinkDeviceId]);
- const handleWtAutoDisable = useCallback(() => {
- setWtEnabled(false);
- }, []);
const handleWtSourceBranchChange = useCallback((sourceBranch: string) => {
setWtSourceBranch(sourceBranch);
}, []);
@@ -1341,17 +1332,11 @@ export function NewMakerDraftRoute() {
const wt = wtRef.current;
let remoteWorkingDir = effectiveWorkingDir;
let presetSessionId: string | undefined;
- if (wt.enabled) {
- // baseRepo 来自被控端 worktree:detect-cwd 的 repoRoot(hooks 已按 deviceId 路由)。
+ // 生效条件 = 勾选 && baseRepo 已就绪(被控端 detect-cwd 的 repoRoot)。
+ // 勾选但环境不合格 / 探测未回时**静默按普通方式启动**,不报错不改勾选记忆
+ // ——状态只属于用户,合格性只影响这一次是否真的走 worktree(2026-07-29 裁决)。
+ if (wt.enabled && wt.baseRepo) {
const baseRepo = wt.baseRepo;
- if (!baseRepo) {
- showWorktreeError({
- kind: 'unknown',
- message: t('ccAgent.draft.worktreeMissingRepo'),
- hint: t('ccAgent.draft.worktreeRepoHint'),
- });
- return;
- }
let name = wt.name.trim();
if (!name) name = `auto-${Date.now().toString(36).slice(-6)}`;
presetSessionId = makeDraftSessionId();
@@ -1481,16 +1466,10 @@ export function NewMakerDraftRoute() {
const sessionId = makeDraftSessionId();
const workingDir = selectedWorkingDir;
const wt = wtRef.current;
- if (!isRemoteProjectDraft && wt.enabled) {
+ // 生效条件 = 勾选 && baseRepo 已就绪;不合格时静默普通启动(同 device-link 分支,
+ // 见 2026-07-29 状态不变量:勾选记忆永不因环境被改动或报错拦截)。
+ if (!isRemoteProjectDraft && wt.enabled && wt.baseRepo) {
const baseRepo = wt.baseRepo;
- if (!baseRepo) {
- showWorktreeError({
- kind: 'unknown',
- message: t('ccAgent.draft.worktreeMissingRepo'),
- hint: t('ccAgent.draft.worktreeRepoHint'),
- });
- return;
- }
let name = wt.name.trim();
if (!name) {
@@ -2287,7 +2266,6 @@ export function NewMakerDraftRoute() {
projectOptions={projectPickerOptions}
enabled={wtEnabled}
onEnabledChange={handleWtEnabledChange}
- onAutoDisable={handleWtAutoDisable}
sourceBranch={wtSourceBranch}
onSourceBranchChange={handleWtSourceBranchChange}
onBaseRepoChange={handleWtBaseRepoChange}
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 3197f6e750..20df9932d5 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -4040,8 +4040,7 @@
"loading": "Loading branches…",
"loadFailed": "Failed to load branches — tap to retry",
"currentTooltip": "Current branch",
- "sourceTooltip": "Worktree source branch",
- "worktreeHint": "Picking another branch starts in an isolated worktree"
+ "sourceTooltip": "Worktree source branch"
},
"folderPicker": {
"selectFolder": "Select folder",
@@ -5055,8 +5054,6 @@
"draft": {
"createSessionFailed": "Failed to create session, please retry",
"deviceStillLoading": "Remote device is still loading, please wait",
- "worktreeMissingRepo": "Cannot create worktree: missing repository root for the current directory",
- "worktreeRepoHint": "Try re-selecting the working directory and wait for the folder badge to refresh, then retry",
"sessionInactive": "Session is no longer active",
"remoteProjectBanner": "New session in {{project}} on {{device}}"
},
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index 92eb4143a8..bdaeeed0db 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -4039,8 +4039,7 @@
"loading": "ブランチを読み込み中…",
"loadFailed": "ブランチの読み込みに失敗しました。タップして再試行",
"currentTooltip": "現在のブランチ",
- "sourceTooltip": "worktree のソースブランチ",
- "worktreeHint": "別のブランチを選択すると worktree 分離で開始します"
+ "sourceTooltip": "worktree のソースブランチ"
},
"folderPicker": {
"selectFolder": "フォルダを選択",
@@ -5045,8 +5044,6 @@
"draft": {
"createSessionFailed": "セッションの作成に失敗しました。再試行してください",
"deviceStillLoading": "リモートデバイスの読み込み中です。しばらくお待ちください",
- "worktreeMissingRepo": "worktree を作成できません:現在のディレクトリのリポジトリルートがありません",
- "worktreeRepoHint": "作業ディレクトリを再選択し、右下のフォルダ表示が更新されてから再試行してください",
"sessionInactive": "セッションはすでにアクティブではありません",
"remoteProjectBanner": "{{device}} の {{project}} で新しいセッションを作成"
},
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index 111f28157c..03c9855995 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -4039,8 +4039,7 @@
"loading": "브랜치 불러오는 중…",
"loadFailed": "브랜치를 불러오지 못했습니다. 눌러서 다시 시도",
"currentTooltip": "현재 브랜치",
- "sourceTooltip": "worktree 소스 브랜치",
- "worktreeHint": "다른 브랜치를 선택하면 worktree 격리로 시작됩니다"
+ "sourceTooltip": "worktree 소스 브랜치"
},
"folderPicker": {
"selectFolder": "폴더 선택",
@@ -5045,8 +5044,6 @@
"draft": {
"createSessionFailed": "세션 생성에 실패했습니다. 다시 시도하세요",
"deviceStillLoading": "원격 기기가 아직 로딩 중입니다. 잠시 기다려 주세요",
- "worktreeMissingRepo": "worktree를 만들 수 없음: 현재 디렉터리의 리포지토리 루트가 없습니다",
- "worktreeRepoHint": "작업 디렉터리를 다시 선택하고 우측 하단의 폴더 표시가 갱신된 후 다시 시도하세요",
"sessionInactive": "세션이 더 이상 활성 상태가 아닙니다",
"remoteProjectBanner": "{{device}}의 {{project}}에서 새 세션 만들기"
},
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index 6dfc297bf5..8a0957fa4f 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -4039,8 +4039,7 @@
"loading": "加载分支中…",
"loadFailed": "分支列表加载失败,点此重试",
"currentTooltip": "当前分支",
- "sourceTooltip": "worktree 源分支",
- "worktreeHint": "选择其他分支将以 worktree 隔离启动"
+ "sourceTooltip": "worktree 源分支"
},
"folderPicker": {
"selectFolder": "选择文件夹",
@@ -5045,8 +5044,6 @@
"draft": {
"createSessionFailed": "创建对话失败,请重试",
"deviceStillLoading": "远程设备仍在加载中,请稍候",
- "worktreeMissingRepo": "无法开 worktree:缺少当前目录的仓库根",
- "worktreeRepoHint": "可尝试重新选一次工作目录,等右下角文件夹标识刷新后再试",
"sessionInactive": "对话已不再处于活跃状态",
"remoteProjectBanner": "在 {{device}} 的 {{project}} 中新建对话"
},
diff --git a/apps/mobile/app/sessions/new.tsx b/apps/mobile/app/sessions/new.tsx
index 318b4c2d10..5e877bdc1f 100644
--- a/apps/mobile/app/sessions/new.tsx
+++ b/apps/mobile/app/sessions/new.tsx
@@ -775,9 +775,9 @@ export default function NewRemoteSessionScreen() {
eligibility: worktreeEligibility,
});
const worktreeToggleDisabled = creating || worktreeEligibility.status !== 'eligible';
- // 勾选展示 = 用户偏好 × 资格通过:资格不满足时不显示已勾(不误导「会用 worktree」),
- // 偏好值本身保留 —— 环境因素不抹掉用户选择,换回合格目录即恢复。
- const worktreeChecked = worktreeEnabled && worktreeEligibility.status === 'eligible';
+ // 勾选展示 = 工作端记忆**原样直出**(2026-07-29 用户裁决:状态只属于用户,系统不做
+ // 视觉折叠);资格不满足只体现为禁用 + caption,创建时按「勾选 && 合格」静默降级。
+ const worktreeChecked = worktreeEnabled;
const worktreeCaptionKey = worktreeEligibilityCaptionKey(worktreeEligibility);
const createValidation = useMemo(
() => validateNewSessionDraft(draft, draftContent),