Skip to content

feat: 新对话的默认模式与记住上次选择 / default mode for new conversations (0.5.0) - #1

Merged
Letter2025 merged 1 commit into
Letter2025:mainfrom
trousev:feat/default-mode-settings
Oct 29, 2026
Merged

Letter2025 merged 1 commit into
Letter2025:mainfrom
trousev:feat/default-mode-settings

Conversation

@trousev

@trousev trousev commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

⚠️ 说明:作者使用英文,下面的中文由英文原文翻译而来。如果翻译不准确或用词不当,敬请见谅,也欢迎直接指出。

为什么(Why)

每个新对话都以本地模式开始,并且会忘记你在上一个对话里选过的模式——于是习惯用 worktree 的人每开一个新任务都要重新选一次,而且没有任何设置可以改变这一点。

怎么做(How)

  • 宿主:注册 task-worktree 设置命名空间(defaultMode、rememberLastChoice,两者的默认值都等于现在的行为:本地模式、不记忆);当默认为 worktree 模式时,在空白对话的第一条真人消息上注入创建指引。
  • 客户端:在「设置 → 插件 → Plugin configuration」里新增一张卡片,只有一个三选一——本地模式 / Worktree模式 / 记住上次选择;控件使用宿主自带的 Button + Menu 原语,输入框上方的选择器现在会跟随这个默认值。
  • 在输入框上方明确选择本地模式,即是对该对话的明确表态(默认值不会为它自动武装);被恢复的对话不会被自动武装;每个对话只判定一次,迟到的 session-start 也不会二次武装。

在用户没有动过这张卡片之前,已有安装的行为完全不变:schema 默认值为 defaultMode: local、rememberLastChoice: false,与本次改动之前完全一致。

截图(Screenshots)

卡片展开后的样子,当前选中的是默认值(行为保持不变):

设置 → 插件 里的 Task worktree 卡片

默认设为 Worktree模式 时的新对话:选择器已预先武装,分支名输入框也已出现,发送第一条消息就会创建 worktree:

输入框上方预先选中 Worktree模式

审阅提示(Notes for review)

  • 卡片外壳的样式值取自 ui-settings-plugins 的 PluginCard/fields:该包只导出类型(exports.apply / exports.inject),插件自有的卡片必须自己绘制外壳;所有可交互控件都使用宿主原语,没有新增控件样式。
  • 测试:test/host.mjs 在假的 cordis 上下文上运行真实的 apply()(设置命名空间、武装策略、注入),test/prefs.mjs 覆盖浏览器偏好 store。npm test、npm run typecheck 与客户端 bundle 漂移检查全部通过。

English (original)

Note: the author speaks English — the Chinese above is a translation of this text. Apologies for any inaccuracy or awkward wording; corrections are welcome.

Why

Every new conversation starts in Local mode and forgets the mode picked in the previous one, so anyone working worktree-first has to re-arm the same choice at the start of every task — and there is no setting to say otherwise.

How

  • Host registers the task-worktree settings namespace (defaultMode, rememberLastChoice, both defaulting to today's behaviour: local mode, no remembering) and, when the default says worktree, injects the creation instruction with the first genuine user message of an empty conversation.
  • Client adds one card to Settings → Plugins → Plugin configuration with a single three-way choice — Local mode / Worktree mode / Remember the last choice — built from the host Button + Menu primitives; the composer selector above the input now follows that default.
  • An explicit Local mode pick stays an explicit answer for that conversation (the default never re-arms it), resumed conversations are never auto-armed, and the decision is made once per conversation — a late session-start beacon cannot re-arm it.

Existing installations are unaffected until the card is touched: the schema default is defaultMode: local, rememberLastChoice: false, which is exactly the pre-PR behaviour.

Screenshots

The card, expanded, with the default (unchanged) selection:

Task worktree card in Settings → Plugins

A new conversation with the default set to Worktree mode: the selector is pre-armed and the branch-name field is already there, so the first message creates the worktree:

Composer showing Worktree mode preselected

Notes for review

  • The card chrome reproduces ui-settings-plugins's PluginCard/fields values because that package exports only types (exports.apply/exports.inject) — a plugin-owned card has to draw its own chrome. Everything interactive is a host primitive, so no new control styling is introduced.
  • Tests: test/host.mjs mounts the real apply() on a fake cordis context (namespace, arming policy, injection), test/prefs.mjs covers the browser preference store. npm test, npm run typecheck and the client-bundle drift check all pass.

@Letter2025

Copy link
Copy Markdown
Owner

Thanks Alexander — the shape of this is right: a settings namespace the host registers, a card that only shows up once that registration exists, and the "decide once per session, an explicit local choice counts as an answer, restored sessions are not armed again" rule. I'll do a full review once it is rebased.

Right now GitHub reports CONFLICTING. Merging main into your branch locally, the conflicts are only in metadata and build outputs:

client/client.js.map
package-lock.json
package.json

Everything else auto-merges (client/client.js, src/client/*, test/*). main moved to 0.4.5 since this PR opened, so please:

  1. git fetch origin && git rebase origin/main (a merge is fine too).
  2. Resolve package.json by hand — and please keep peerDependencies on main's ^0.2.1-rc.2 line. The version number itself I will settle at merge time, so leaving 0.5.0 in the diff is fine.
  3. npm install to regenerate package-lock.json against that package.json — the lock should not be hand-merged.
  4. npm run build:client — it runs tsdown for both lib/ and client/ — and let the normalizer rewrite client/client.js.map. Regenerating is the only way the committed build outputs (lib/index.js, lib/index.d.ts, client/client.js, client/client.js.map) stay honest; hand-merging a sourcemap produces a file that no longer matches src/.
  5. npm run typecheck and npm test green.

Two things I would like spelled out in the PR description when you push:

  • No behaviour change for existing users. defaultMode defaulting to local and rememberLastChoice defaulting to off must leave a fresh install behaving exactly like 0.4.x. Could you say explicitly what happens on a profile that has never written the setting, and on a profile restored from an older config?
  • Where the remembered values live. The settings namespace only, or also in browser storage? The card renders in the web client, so I want to be sure two browser tabs — or the desktop app and the web UI at once — cannot disagree about which mode the next conversation gets.

Rebased onto main and adapted to the 0.2.1-rc.4 / 0.2.2-alpha.2 host line:
- peerDependencies follow the current host line (^0.2.1-rc.4 || ^0.2.2-alpha.2,
  cordis ~4.0.5 || ~4.0.6-alpha.1, schemastery ^3.18.0 || ~3.18.6-alpha.1);
  dsh-settings and schemastery stay optional peers
- devDependencies pinned to 0.2.2-alpha.2, plus cordis and dsh-scope so the host
  tests resolve the runtime peer chain
- package-lock.json, lib/ and client/ regenerated from source
  (npm install --legacy-peer-deps; npm run build:client)
- IconChevronDownOutline14 replaced by IconChevronDownOutlineRegular, the name
  the current client primitives export

Co-authored-by: DeepSeek <noreply@deepseek.com>
@Letter2025
Letter2025 force-pushed the feat/default-mode-settings branch from bf3c6b5 to fab2ac0 Compare October 29, 2026 02:22
@Letter2025

Copy link
Copy Markdown
Owner

Rebase 完成,署名保留(commit fab2ac0,author 仍是 Alexander Trousevich),已推回你的 feat/default-mode-settings 分支。冲突只在三个派生物,全部按重新生成处理:

package.json(手工合并语义,不是取一边)

  • peerDependencies 跟 main 的当前宿主线:^0.2.1-rc.4 || ^0.2.2-alpha.2、@deepseek-ai/cordis: ~4.0.5 || ~4.0.6-alpha.1、@deepseek-ai/schemastery: ^3.18.0 || ~3.18.6-alpha.1
  • 你新增的 @deepseek-ai/dsh-settings、@deepseek-ai/schemastery 两个 peer 保留,并保持 optional(peerDependenciesMeta);dsh-settings 的版本线也一并换成宿主线
  • devDependencies 钉到 0.2.2-alpha.2,另外补了 @deepseek-ai/cordis 和 @deepseek-ai/dsh-scope——新宿主线的 dsh-tools 运行期要 dsh-scope,dsh-typert-protocol 要 cordis,缺了 host 测试直接 ERR_MODULE_NOT_FOUND
  • version 取 0.5.0

package-lock.json:npm install --legacy-peer-deps 重新生成(不手并)。
lib/、client/client.js、client/client.js.map:npm run build:client 重新生成;重新构建后 git status 干净,说明产物与源码一致(确定性构建)。

一处源码改动:IconChevronDownOutline14 → IconChevronDownOutlineRegular。client primitives 已经换了命名(现在是 IconChevronDownOutlineRegular 1px / IconChevronDownOutlineMedium 1.3px),14 这个尺寸名不存在了;size={14} 原样保留,三处引用都改了。

验证(本地全绿):npm run typecheck 干净;npm test → SMOKE OK、HOST OK、PREFS OK。

顺便把你描述里我 review 时问的两点按代码回答,免得你再等一轮:

  1. 对已有用户零行为变化:确认成立。宿主默认 defaultMode: 'local'、rememberLastChoice: false,注入逻辑有 if (readSettings().defaultMode !== 'worktree') return 兜底,所以默认配置下不注入任何指令;测试用例 default local: nothing is injected、an absent or non-boolean remember flag means off 覆盖了这两条。
  2. 记忆值存放位置:只存宿主 settings 命名空间 task-worktree(客户端经 ctx.settingsScope 绑定、revision-fenced 写入并回读确认),不落浏览器 localStorage/sessionStorage。因此多标签页、桌面端 + Web 端共用同一份值,不会出现"下一个会话用什么模式"的分歧。

合入后我会在真实 profile 里装一遍 0.5.0 再发布 npm;有问题欢迎继续在这个 PR 或新 issue 里说。感谢这个 PR——设置卡片和"仅首条真人消息判定一次"的规则都做得很干净。

@Letter2025
Letter2025 merged commit d9c9c85 into Letter2025:main Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants