From fab2ac09df84564b1fdd85b5443a6a2f779e4563 Mon Sep 17 00:00:00 2001 From: Alexander Trousevich Date: Sun, 20 Sep 2026 09:57:20 +0100 Subject: [PATCH] feat: default worktree mode for new conversations (0.5.0) 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 --- README.md | 53 +++- README.zh.md | 37 ++- client/client.js | 401 +++++++++++++++++++++++-- client/client.js.map | 2 +- lib/index.d.ts | 4 + lib/index.js | 97 +++++- package-lock.json | 304 +++++++------------ package.json | 23 +- src/client/WorktreePanel.tsx | 39 ++- src/client/WorktreeSettings.module.css | 132 ++++++++ src/client/WorktreeSettingsCard.tsx | 127 ++++++++ src/client/index.ts | 24 ++ src/client/locales.ts | 22 +- src/client/worktreePrefs.ts | 205 +++++++++++++ src/client/worktreeStore.ts | 24 +- test/host.mjs | 243 +++++++++++++++ test/prefs.mjs | 158 ++++++++++ 17 files changed, 1640 insertions(+), 255 deletions(-) create mode 100644 src/client/WorktreeSettings.module.css create mode 100644 src/client/WorktreeSettingsCard.tsx create mode 100644 src/client/worktreePrefs.ts create mode 100644 test/host.mjs create mode 100644 test/prefs.mjs diff --git a/README.md b/README.md index debd1bb..b7a76e0 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,9 @@ It follows the design of Qoder's `Worktree` execution environment, Codex's `code ## How it works ``` -Blank conversation: pick "Worktree mode" in the dock dropdown (before the -conversation starts) → optional branch name (auto-prefixed "worktree/") +Blank conversation: the mode selector above the composer follows the configured +default (Settings → Plugins → Task worktree), or pick "Worktree mode" yourself + │ optional branch name (auto-prefixed "worktree/") │ send the first message → the host injects an instructions context block ▼ the model calls worktree_create on that same turn │ git worktree add -b worktree/ /.dsh-worktrees/worktree/worktree/ @@ -53,7 +54,9 @@ conversation starts) → optional branch name (auto-prefixed "worktree/") session, and the branch-name field is optional (typed names are auto-prefixed `worktree/`, blank lets the model propose one). The mode selector disappears once the conversation starts; the session-header badge - takes over the indication. + takes over the indication. Set the default mode once in + **Settings → Plugins → Task worktree** and every new conversation starts + that way (see [Settings](#settings)). 2. **Send your first message** — the host injects one `instructions` context block (shown as 上下文注入) right before your message: create the worktree with a `worktree/`-prefixed branch, work inside the checkout path, and at @@ -77,6 +80,41 @@ dsh plugin --profile web add dsh-task-worktree Requires: DeepSeek Harness `0.1.0-rc.7` package line, Git 2.31+, Node 20+. +## Settings + +The plugin registers the `task-worktree` settings namespace and ships its own +card in **Settings → Plugins → Plugin configuration**. One setting — the mode a +new conversation starts in — with three choices (they are exactly the three +states there are; a mode plus a separate "remember" switch would describe a +fourth one that means nothing): + +| Choice in the panel | Stored in `task-worktree` | Meaning | +| --- | --- | --- | +| Local mode | `defaultMode: local`, `rememberLastChoice: false` | Every new conversation starts in the main workspace. | +| Worktree mode | `defaultMode: worktree`, `rememberLastChoice: false` | Every new conversation is isolated: the host injects the worktree-creation instruction with the first genuine message, no selector trip needed. | +| Remember the last choice | `rememberLastChoice: true` | The mode you picked last above the composer wins; `defaultMode` holds that pick. | + +The default is **Local mode**. An installation that never opens the card keeps +behaving exactly as it did before this setting existed: new conversations start +in the main workspace, and a pick in the composer selector applies to its own +conversation only. + +The chosen mode applies to conversations that start empty. Picking **Local mode** +in the composer selector is an explicit answer for that conversation: the host +does not auto-arm it, whatever the setting says. + +Values live in the ordinary user-settings document, so they can also be set by +hand and take effect live: + +```yaml +task-worktree: + defaultMode: worktree + rememberLastChoice: false +``` + +On a host without the settings service the plugin keeps working with the +composed defaults (local mode), and the card simply does not appear. + ## Model tools | Tool | Purpose | @@ -112,10 +150,17 @@ Delivery and cleanup actions (finish / bring-back / remove) stay **human-only** ## Local development ```bash -npm test # smoke test: full lifecycle on a scratch repository +npm test # smoke (worktree lifecycle) + host half + browser prefs +npm run typecheck # client TypeScript +npm run build:client # rebuild client/client.js (tsdown + lightningcss) npm pack --dry-run # inspect the tarball before publishing ``` +The suites: `test/smoke.mjs` (git lifecycle on a scratch repository), +`test/host.mjs` (the real `apply()` on a fake cordis context: settings +namespace, arming policy, injection), `test/prefs.mjs` (the browser preference +store; needs Node 22.6+ and skips itself on older runtimes). + ## License MIT — see [LICENSE](LICENSE) \ No newline at end of file diff --git a/README.zh.md b/README.zh.md index 756665b..7be994c 100644 --- a/README.zh.md +++ b/README.zh.md @@ -31,7 +31,8 @@ ## 工作流 ``` -空白对话:发送前在下拉框选「Worktree模式」(分支名可选,自动加 worktree/ 前缀) +空白对话:输入框上方的模式选择器跟随「默认模式」设置(设置 → 插件 → 任务 Worktree), + 也可以自己选「Worktree模式」(分支名可选,自动加 worktree/ 前缀) │ 发送第一条消息 → 宿主注入一条「上下文注入」instructions 块 ▼ 模型在同一轮调用 worktree_create │ git worktree add -b worktree/<名称> <仓库>/.dsh-worktrees/worktree/worktree/<名称> @@ -44,7 +45,7 @@ (--force 连未提交改动一起删) ``` -1. **以 Worktree 模式开始**:空白对话、发送前,dock 选择器显示「分支名:」——选「Worktree模式」即武装会话;分支名可选(输入的会自动加 `worktree/` 前缀,留空由模型拟定)。**对话开始后选择器自动隐藏**,由会话头部徽标接管指示。 +1. **以 Worktree 模式开始**:空白对话、发送前,dock 选择器显示「分支名:」——选「Worktree模式」即武装会话;分支名可选(输入的会自动加 `worktree/` 前缀,留空由模型拟定)。**对话开始后选择器自动隐藏**,由会话头部徽标接管指示。在**设置 → 插件 → 任务 Worktree**里把默认模式设为 Worktree,之后每个新对话都直接以该模式开始。 2. **发送第一条消息** → 宿主在你消息前注入一条 `instructions` 上下文块(界面显示为「上下文注入」):创建 `worktree/` 前缀分支、在 checkout 路径内干活、任务结束时**给出可复制的收尾命令**(`bring-back` 或 `remove --force`)。 3. 或跳过模式,直接让 agent 隔离任务:**"用 worktree 隔离干活,任务叫 xxx"** —— 模型调用 `worktree_create`,name 同时作分支名与路径(支持斜杠)。 4. **不注册任何工作区**,侧边栏保持干净;worktree 模式下会话头部显示分支徽标。 @@ -58,6 +59,30 @@ dsh plugin --profile web add dsh-task-worktree 要求:DeepSeek Harness `0.1.0-rc.7` 包线、Git 2.31+、Node 20+。 +## 设置 + +插件注册 `task-worktree` 设置命名空间,并在**设置 → 插件 → Plugin configuration** 里提供自己的卡片。只有一项设置——新对话的默认模式——三个选项(本来就只有这三种状态;拆成「模式 + 记住上次选择」开关会多出一个毫无意义的组合): + +| 面板选项 | 存储在 `task-worktree` | 含义 | +| --- | --- | --- | +| 本地模式 | `defaultMode: local`、`rememberLastChoice: false` | 每个新对话都直接在主工作区开始。 | +| Worktree模式 | `defaultMode: worktree`、`rememberLastChoice: false` | 每个新对话都隔离:宿主在第一条真人消息到达时自动注入创建指引,不必再动手选。 | +| 记住上次选择 | `rememberLastChoice: true` | 以你在输入框上方最后选定的模式为准,`defaultMode` 保存该选择。 | + +默认是**本地模式**。从未打开过这张卡片的安装,行为与本设置存在之前完全一致:新对话从主工作区开始,输入框上方的选择只作用于当前对话。 + +所选模式只作用于「从空白开始」的对话。在输入框上方选**本地模式**即是对该对话的明确表态:无论设置是什么,宿主都不会为它自动武装。 + +设置存在普通的用户设置文档里,也可以直接手改并即时生效: + +```yaml +task-worktree: + defaultMode: worktree + rememberLastChoice: false +``` + +宿主没有设置服务时,插件继续用组合默认值(本地模式)工作,卡片不会出现。 + ## 模型工具 | 工具 | 作用 | @@ -93,10 +118,16 @@ dsh plugin --profile web add dsh-task-worktree ## 本地开发 ```bash -npm test # 冒烟测试:临时仓库全生命周期 +npm test # 冒烟(worktree 全生命周期)+ 宿主半 + 浏览器偏好 +npm run typecheck # 客户端 TypeScript 类型检查 +npm run build:client # 重新构建 client/client.js(tsdown + lightningcss) npm pack --dry-run # 发布前检查包内容 ``` +三个测试:`test/smoke.mjs`(临时仓库上的 git 全生命周期)、 +`test/host.mjs`(在假 cordis 上下文里跑真实 `apply()`:设置命名空间、武装策略、注入)、 +`test/prefs.mjs`(浏览器偏好 store;需 Node 22.6+,更低版本自动跳过)。 + ## License MIT — see [LICENSE](LICENSE) \ No newline at end of file diff --git a/client/client.js b/client/client.js index e7a116a..2ac2842 100644 --- a/client/client.js +++ b/client/client.js @@ -18,7 +18,17 @@ const zh = { badgeTooltip: "本对话使用的 worktree", badgeFallback: "worktree", heroStartLabel: "分支名:", - heroStartPlaceholder: "可选,留空由 AI 命名" + heroStartPlaceholder: "可选,留空由 AI 命名", + settingsCardTitle: "任务 Worktree", + settingsCardDesc: "新对话默认进入的执行环境", + settingsDefaultMode: "新对话默认模式", + settingsDefaultLocalHint: "空白对话直接在主工作区开始。", + settingsDefaultWorktreeHint: "空白对话以 worktree 模式开始:发出第一条消息时自动创建隔离的 worktree,无需再手动选择。", + settingsRemember: "记住上次选择", + settingsRememberHint: "空白对话沿用你在输入框上方最后选定的模式。", + settingsRememberedNow: "当前记住:", + settingsUnavailable: "当前宿主没有可写的设置存储,修改不会被保存。", + settingsSaveFailed: "保存失败" }; const en = { panelTitle: "Worktrees", @@ -29,7 +39,17 @@ const en = { badgeTooltip: "Worktree used by this conversation", badgeFallback: "worktree", heroStartLabel: "Branch: ", - heroStartPlaceholder: "optional; blank: AI proposes" + heroStartPlaceholder: "optional; blank: AI proposes", + settingsCardTitle: "Task worktree", + settingsCardDesc: "The execution environment new conversations start in", + settingsDefaultMode: "Default mode for new conversations", + settingsDefaultLocalHint: "A blank conversation starts directly in the main workspace.", + settingsDefaultWorktreeHint: "A blank conversation starts in worktree mode: the isolated worktree is created automatically with your first message.", + settingsRemember: "Remember the last choice", + settingsRememberHint: "A blank conversation starts with the mode you picked last above the composer.", + settingsRememberedNow: "Currently remembered: ", + settingsUnavailable: "This host has no writable settings storage, so changes cannot be saved.", + settingsSaveFailed: "Could not save" }; //#endregion @@ -60,13 +80,13 @@ function worktreeNameOfCwd(cwd) { //#endregion //#region \0dsh-css:src/client/WorktreePanel.module.css.mjs -const css = ".Y0CJ8q_root{z-index:8;box-sizing:border-box;width:min(var(--dsh-composer-card-max-width,780px), calc(100% - 32px));min-height:28px;color:var(--dsw-alias-label-primary,#1f1f1f);pointer-events:none;align-self:center;align-items:center;padding-left:8px;font-size:13px;display:flex;position:relative}.Y0CJ8q_trigger{min-height:28px;color:inherit;font:inherit;white-space:nowrap;cursor:pointer;pointer-events:auto;background:0 0;border:0;border-radius:6px;align-items:center;gap:5px;padding:4px 7px;font-weight:500;line-height:18px;display:inline-flex}.Y0CJ8q_trigger:hover,.Y0CJ8q_trigger[aria-expanded=true]{background:var(--dsw-alias-interactive-bg-hover,#0000000e)}.Y0CJ8q_trigger:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4f73ff);outline-offset:1px}.Y0CJ8q_menuItem:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4f73ff);outline-offset:1px}.Y0CJ8q_backButton:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4f73ff);outline-offset:1px}.Y0CJ8q_secondaryButton:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4f73ff);outline-offset:1px}.Y0CJ8q_primaryButton:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4f73ff);outline-offset:1px}.Y0CJ8q_nameInput:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4f73ff);outline-offset:1px}.Y0CJ8q_icon{color:var(--dsw-alias-label-secondary,#5f6368);flex:none}.Y0CJ8q_chevron{color:var(--dsw-alias-label-caption,#8a8f98);flex:none;transition:transform .14s}.Y0CJ8q_chevronOpen{transform:rotate(180deg)}.Y0CJ8q_popover{z-index:60;width:168px;color:var(--dsw-alias-label-primary,#1f1f1f);background:var(--dsw-alias-bg-base,#fff);border:1px solid var(--dsw-alias-border-l2,#0000001f);pointer-events:auto;border-radius:7px;padding:4px;position:absolute;top:calc(100% + 6px);left:8px;overflow:hidden;box-shadow:0 10px 28px #00000021,0 2px 8px #00000014}.Y0CJ8q_menuItem{width:100%;min-height:32px;color:inherit;font:inherit;text-align:left;cursor:pointer;background:0 0;border:0;border-radius:5px;grid-template-columns:16px minmax(0,1fr) 14px;align-items:center;gap:7px;padding:6px 8px;font-weight:400;line-height:18px;display:grid}.Y0CJ8q_menuItem>span{text-overflow:ellipsis;white-space:nowrap;grid-column:2;overflow:hidden}.Y0CJ8q_menuItem:hover,.Y0CJ8q_menuItem.Y0CJ8q_selected{background:var(--dsw-alias-interactive-bg-hover,#0000000e)}.Y0CJ8q_menuItem:disabled{cursor:default;opacity:.5}.Y0CJ8q_menuItem.Y0CJ8q_danger{color:var(--dsw-alias-state-error,#c93b3b)}.Y0CJ8q_menuItem.Y0CJ8q_danger .Y0CJ8q_icon{color:currentColor}.Y0CJ8q_trailingIcon{color:var(--dsw-alias-label-caption,#8a8f98);grid-column:3;justify-self:end}.Y0CJ8q_separator{background:var(--dsw-alias-border-l2,#0000001a);height:1px;margin:4px 6px}.Y0CJ8q_menuHeader{border-bottom:1px solid var(--dsw-alias-border-l2,#0000001a);align-items:center;gap:5px;min-height:32px;margin-bottom:4px;padding:4px 6px 5px 4px;font-weight:600;display:flex}.Y0CJ8q_backButton{width:24px;height:24px;color:var(--dsw-alias-label-secondary,#5f6368);cursor:pointer;background:0 0;border:0;border-radius:5px;flex:none;place-items:center;padding:0;display:inline-grid}.Y0CJ8q_backButton:hover{background:var(--dsw-alias-interactive-bg-hover,#0000000e)}.Y0CJ8q_createPanel{width:272px}.Y0CJ8q_popover:has(.Y0CJ8q_createPanel){width:280px}.Y0CJ8q_nameInput{box-sizing:border-box;width:calc(100% - 12px);height:34px;color:inherit;font:inherit;background:var(--dsw-alias-bg-base,#fff);border:1px solid var(--dsw-alias-border-l1,#0003);border-radius:6px;margin:7px 6px 9px;padding:6px 9px}.Y0CJ8q_nameInput::placeholder{color:var(--dsw-alias-label-caption,#8a8f98)}.Y0CJ8q_createActions{justify-content:flex-end;gap:6px;padding:0 6px 5px;display:flex}.Y0CJ8q_secondaryButton,.Y0CJ8q_primaryButton{min-height:28px;font:inherit;cursor:pointer;border-radius:6px;padding:4px 11px}.Y0CJ8q_secondaryButton{color:inherit;border:1px solid var(--dsw-alias-border-l2,#0000001f);background:0 0}.Y0CJ8q_secondaryButton:hover{background:var(--dsw-alias-interactive-bg-hover,#0000000e)}.Y0CJ8q_primaryButton{color:#fff;background:var(--dsw-alias-state-business-primary,#4f73ff);border:1px solid #0000}.Y0CJ8q_primaryButton:disabled{cursor:default;opacity:.45}.Y0CJ8q_notice{color:var(--dsw-alias-state-error,#c93b3b);white-space:nowrap;pointer-events:auto;margin-left:6px;font-size:12px}.Y0CJ8q_badge{max-width:200px;min-height:20px;color:var(--dsw-alias-label-secondary,#5f6368);white-space:nowrap;border:1px solid var(--dsw-alias-border-l2,#0000001a);border-radius:999px;align-items:center;gap:4px;padding:1px 7px;font-size:11px;line-height:16px;display:inline-flex;overflow:hidden}.Y0CJ8q_badge>span{text-overflow:ellipsis;overflow:hidden}.Y0CJ8q_badgeIcon{color:var(--dsw-alias-state-business-primary,#4f73ff);flex:none}.Y0CJ8q_heroStart{border:1px dashed var(--dsw-alias-border-l2,#00000029);pointer-events:auto;border-radius:7px;align-items:center;gap:6px;min-height:28px;margin-left:6px;padding:2px 6px 2px 4px;display:inline-flex}.Y0CJ8q_heroStartLabel{white-space:nowrap;font-weight:500}.Y0CJ8q_heroStartInput{box-sizing:border-box;width:230px;height:26px;color:inherit;font:inherit;background:var(--dsw-alias-bg-base,#fff);border:1px solid var(--dsw-alias-border-l1,#0003);border-radius:6px;padding:3px 8px}.Y0CJ8q_heroStartInput::placeholder{color:var(--dsw-alias-label-caption,#8a8f98)}.Y0CJ8q_heroStartButton{color:#fff;min-height:26px;font:inherit;cursor:pointer;background:var(--dsw-alias-state-business-primary,#4f73ff);border:1px solid #0000;border-radius:6px;padding:3px 12px;font-weight:500}.Y0CJ8q_heroStartButton:disabled{cursor:default;opacity:.45}.Y0CJ8q_armedCancel{min-height:26px;color:inherit;font:inherit;cursor:pointer;border:1px solid var(--dsw-alias-border-l2,#0000001f);background:0 0;border-radius:6px;padding:3px 12px}.Y0CJ8q_armedCancel:hover{background:var(--dsw-alias-interactive-bg-hover,#0000000e)}.Y0CJ8q_armedCancel:disabled{cursor:default;opacity:.45}.Y0CJ8q_commandRow{color:var(--dsw-alias-label-primary,#1f1f1f);flex-direction:column;gap:2px;padding:4px 0;font-size:12px;line-height:17px;display:flex}.Y0CJ8q_commandRowLine{word-break:break-all;font-family:ui-monospace,SFMono-Regular,Consolas,monospace;font-weight:600}.Y0CJ8q_commandRowOutcome{color:var(--dsw-alias-label-secondary,#5f6368);white-space:pre-wrap;word-break:break-word}.Y0CJ8q_commandRowError{color:var(--dsw-alias-state-error,#c93b3b)}[data-phase=hero] .Y0CJ8q_root{flex:none;align-self:flex-start;width:auto;max-width:calc(100% - 32px);padding-left:20px;display:inline-flex}[data-phase=hero] .Y0CJ8q_popover{left:20px}@media (max-width:720px){.Y0CJ8q_root{width:calc(100% - 20px);padding-left:0}.Y0CJ8q_popover{left:0}}"; -const tagId = "dsh-task-worktree/WorktreePanel.module.css"; -if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) { +const css$1 = ".Y0CJ8q_root{z-index:8;box-sizing:border-box;width:min(var(--dsh-composer-card-max-width,780px), calc(100% - 32px));min-height:28px;color:var(--dsw-alias-label-primary,#1f1f1f);pointer-events:none;align-self:center;align-items:center;padding-left:8px;font-size:13px;display:flex;position:relative}.Y0CJ8q_trigger{min-height:28px;color:inherit;font:inherit;white-space:nowrap;cursor:pointer;pointer-events:auto;background:0 0;border:0;border-radius:6px;align-items:center;gap:5px;padding:4px 7px;font-weight:500;line-height:18px;display:inline-flex}.Y0CJ8q_trigger:hover,.Y0CJ8q_trigger[aria-expanded=true]{background:var(--dsw-alias-interactive-bg-hover,#0000000e)}.Y0CJ8q_trigger:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4f73ff);outline-offset:1px}.Y0CJ8q_menuItem:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4f73ff);outline-offset:1px}.Y0CJ8q_backButton:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4f73ff);outline-offset:1px}.Y0CJ8q_secondaryButton:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4f73ff);outline-offset:1px}.Y0CJ8q_primaryButton:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4f73ff);outline-offset:1px}.Y0CJ8q_nameInput:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4f73ff);outline-offset:1px}.Y0CJ8q_icon{color:var(--dsw-alias-label-secondary,#5f6368);flex:none}.Y0CJ8q_chevron{color:var(--dsw-alias-label-caption,#8a8f98);flex:none;transition:transform .14s}.Y0CJ8q_chevronOpen{transform:rotate(180deg)}.Y0CJ8q_popover{z-index:60;width:168px;color:var(--dsw-alias-label-primary,#1f1f1f);background:var(--dsw-alias-bg-base,#fff);border:1px solid var(--dsw-alias-border-l2,#0000001f);pointer-events:auto;border-radius:7px;padding:4px;position:absolute;top:calc(100% + 6px);left:8px;overflow:hidden;box-shadow:0 10px 28px #00000021,0 2px 8px #00000014}.Y0CJ8q_menuItem{width:100%;min-height:32px;color:inherit;font:inherit;text-align:left;cursor:pointer;background:0 0;border:0;border-radius:5px;grid-template-columns:16px minmax(0,1fr) 14px;align-items:center;gap:7px;padding:6px 8px;font-weight:400;line-height:18px;display:grid}.Y0CJ8q_menuItem>span{text-overflow:ellipsis;white-space:nowrap;grid-column:2;overflow:hidden}.Y0CJ8q_menuItem:hover,.Y0CJ8q_menuItem.Y0CJ8q_selected{background:var(--dsw-alias-interactive-bg-hover,#0000000e)}.Y0CJ8q_menuItem:disabled{cursor:default;opacity:.5}.Y0CJ8q_menuItem.Y0CJ8q_danger{color:var(--dsw-alias-state-error,#c93b3b)}.Y0CJ8q_menuItem.Y0CJ8q_danger .Y0CJ8q_icon{color:currentColor}.Y0CJ8q_trailingIcon{color:var(--dsw-alias-label-caption,#8a8f98);grid-column:3;justify-self:end}.Y0CJ8q_separator{background:var(--dsw-alias-border-l2,#0000001a);height:1px;margin:4px 6px}.Y0CJ8q_menuHeader{border-bottom:1px solid var(--dsw-alias-border-l2,#0000001a);align-items:center;gap:5px;min-height:32px;margin-bottom:4px;padding:4px 6px 5px 4px;font-weight:600;display:flex}.Y0CJ8q_backButton{width:24px;height:24px;color:var(--dsw-alias-label-secondary,#5f6368);cursor:pointer;background:0 0;border:0;border-radius:5px;flex:none;place-items:center;padding:0;display:inline-grid}.Y0CJ8q_backButton:hover{background:var(--dsw-alias-interactive-bg-hover,#0000000e)}.Y0CJ8q_createPanel{width:272px}.Y0CJ8q_popover:has(.Y0CJ8q_createPanel){width:280px}.Y0CJ8q_nameInput{box-sizing:border-box;width:calc(100% - 12px);height:34px;color:inherit;font:inherit;background:var(--dsw-alias-bg-base,#fff);border:1px solid var(--dsw-alias-border-l1,#0003);border-radius:6px;margin:7px 6px 9px;padding:6px 9px}.Y0CJ8q_nameInput::placeholder{color:var(--dsw-alias-label-caption,#8a8f98)}.Y0CJ8q_createActions{justify-content:flex-end;gap:6px;padding:0 6px 5px;display:flex}.Y0CJ8q_secondaryButton,.Y0CJ8q_primaryButton{min-height:28px;font:inherit;cursor:pointer;border-radius:6px;padding:4px 11px}.Y0CJ8q_secondaryButton{color:inherit;border:1px solid var(--dsw-alias-border-l2,#0000001f);background:0 0}.Y0CJ8q_secondaryButton:hover{background:var(--dsw-alias-interactive-bg-hover,#0000000e)}.Y0CJ8q_primaryButton{color:#fff;background:var(--dsw-alias-state-business-primary,#4f73ff);border:1px solid #0000}.Y0CJ8q_primaryButton:disabled{cursor:default;opacity:.45}.Y0CJ8q_notice{color:var(--dsw-alias-state-error,#c93b3b);white-space:nowrap;pointer-events:auto;margin-left:6px;font-size:12px}.Y0CJ8q_badge{max-width:200px;min-height:20px;color:var(--dsw-alias-label-secondary,#5f6368);white-space:nowrap;border:1px solid var(--dsw-alias-border-l2,#0000001a);border-radius:999px;align-items:center;gap:4px;padding:1px 7px;font-size:11px;line-height:16px;display:inline-flex;overflow:hidden}.Y0CJ8q_badge>span{text-overflow:ellipsis;overflow:hidden}.Y0CJ8q_badgeIcon{color:var(--dsw-alias-state-business-primary,#4f73ff);flex:none}.Y0CJ8q_heroStart{border:1px dashed var(--dsw-alias-border-l2,#00000029);pointer-events:auto;border-radius:7px;align-items:center;gap:6px;min-height:28px;margin-left:6px;padding:2px 6px 2px 4px;display:inline-flex}.Y0CJ8q_heroStartLabel{white-space:nowrap;font-weight:500}.Y0CJ8q_heroStartInput{box-sizing:border-box;width:230px;height:26px;color:inherit;font:inherit;background:var(--dsw-alias-bg-base,#fff);border:1px solid var(--dsw-alias-border-l1,#0003);border-radius:6px;padding:3px 8px}.Y0CJ8q_heroStartInput::placeholder{color:var(--dsw-alias-label-caption,#8a8f98)}.Y0CJ8q_heroStartButton{color:#fff;min-height:26px;font:inherit;cursor:pointer;background:var(--dsw-alias-state-business-primary,#4f73ff);border:1px solid #0000;border-radius:6px;padding:3px 12px;font-weight:500}.Y0CJ8q_heroStartButton:disabled{cursor:default;opacity:.45}.Y0CJ8q_armedCancel{min-height:26px;color:inherit;font:inherit;cursor:pointer;border:1px solid var(--dsw-alias-border-l2,#0000001f);background:0 0;border-radius:6px;padding:3px 12px}.Y0CJ8q_armedCancel:hover{background:var(--dsw-alias-interactive-bg-hover,#0000000e)}.Y0CJ8q_armedCancel:disabled{cursor:default;opacity:.45}.Y0CJ8q_commandRow{color:var(--dsw-alias-label-primary,#1f1f1f);flex-direction:column;gap:2px;padding:4px 0;font-size:12px;line-height:17px;display:flex}.Y0CJ8q_commandRowLine{word-break:break-all;font-family:ui-monospace,SFMono-Regular,Consolas,monospace;font-weight:600}.Y0CJ8q_commandRowOutcome{color:var(--dsw-alias-label-secondary,#5f6368);white-space:pre-wrap;word-break:break-word}.Y0CJ8q_commandRowError{color:var(--dsw-alias-state-error,#c93b3b)}[data-phase=hero] .Y0CJ8q_root{flex:none;align-self:flex-start;width:auto;max-width:calc(100% - 32px);padding-left:20px;display:inline-flex}[data-phase=hero] .Y0CJ8q_popover{left:20px}@media (max-width:720px){.Y0CJ8q_root{width:calc(100% - 20px);padding-left:0}.Y0CJ8q_popover{left:0}}"; +const tagId$1 = "dsh-task-worktree/WorktreePanel.module.css"; +if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$1) + "]") === null) { const tag = document.createElement("style"); tag.dataset.plugin = "dsh-task-worktree"; - tag.dataset.pluginCss = tagId; - tag.textContent = css; + tag.dataset.pluginCss = tagId$1; + tag.textContent = css$1; document.head.appendChild(tag); } var WorktreePanel_module_css_default = { @@ -149,6 +169,13 @@ function WorktreeBadge(props) { * next user message); the revealed strip optionally takes a name (Enter to * apply). Selecting Local mode disarms. Management commands (/worktree * list/status/...) stay available from the composer directly. +* +* On a blank conversation the selector reflects the configured default mode +* (`task-worktree` settings namespace): with the default set to worktree the +* strip is pre-armed and the host injects the creation instruction with the +* first message. Picking a mode is always an explicit answer for THIS +* conversation, and — when "remember the last choice" is on — it also updates +* the default. */ const WORKTREE_PATH = /[\\/]\.dsh-worktrees[\\/]worktree[\\/]/u; function currentMode(injected) { @@ -166,10 +193,13 @@ function WorktreePanel(props) { /** Last raw name actually sent to the host (dedup guard for re-arms). */ const lastAppliedRef = (0, react.useRef)(""); (0, react.useSyncExternalStore)(store.subscribe, store.getVersion); + const prefs = (0, react.useSyncExternalStore)(props.prefs.subscribe, props.prefs.getSnapshot); const sessionId = sessionIdOf(); const declared = store.stateOf(sessionId); const hero = props.currentBlank(); - const mode = declared.worktree || currentMode(props) === "worktree" ? "worktree" : "local"; + const defaultWorktree = hero && !declared.explicit && prefs.defaultMode === "worktree"; + const preArmed = defaultWorktree && !declared.worktree; + const mode = declared.worktree || defaultWorktree || currentMode(props) === "worktree" ? "worktree" : "local"; (0, react.useEffect)(() => { setName(declared.name ?? ""); }, [declared.name]); @@ -180,7 +210,9 @@ function WorktreePanel(props) { sessionId, mode, hero, - declaredWorktree: declared.worktree + declaredWorktree: declared.worktree, + defaultMode: prefs.defaultMode, + explicit: declared.explicit }; (0, react.useLayoutEffect)(() => { const root = rootRef.current; @@ -237,6 +269,10 @@ function WorktreePanel(props) { setNotice(t("fail")); window.setTimeout(() => setNotice(null), 1800); }; + /** Persist a mode the user picked as the default for future conversations. */ + const remember = (choice) => { + if (prefs.rememberLastChoice) props.prefs.setDefaultMode(choice); + }; /** Legacy: leave a session actually running inside a worktree checkout. */ const switchLocal = () => { if (busy !== null) return; @@ -259,7 +295,8 @@ function WorktreePanel(props) { /** 本地模式 radio: disarm the declared worktree mode, or leave a legacy checkout session. */ const selectLocal = () => { if (busy !== null) return; - if (declared.worktree) { + if (declared.worktree || preArmed) { + remember("local"); disarmMode(); closeMenu(); return; @@ -327,7 +364,7 @@ function WorktreePanel(props) { }) ] }), - declared.worktree && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { + (declared.worktree || preArmed) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { className: WorktreePanel_module_css_default.heroStart, "data-testid": "worktree-mode-start", children: [ @@ -371,6 +408,7 @@ function WorktreePanel(props) { className: `${WorktreePanel_module_css_default.menuItem} ${mode === "worktree" ? WorktreePanel_module_css_default.selected : ""}`, disabled: busy !== null, onClick: () => { + remember("worktree"); if (!declared.worktree) props.armWorktreeMode(void 0).catch(() => showFailure()); closeMenu(); }, @@ -391,6 +429,11 @@ function WorktreePanel(props) { //#endregion //#region src/client/worktreeStore.ts +const UNDECIDED = { + name: void 0, + worktree: false, + explicit: false +}; function createWorktreeStore() { let byId = /* @__PURE__ */ new Map(); let version = 0; @@ -409,37 +452,335 @@ function createWorktreeStore() { return version; }, stateOf(sessionId) { - if (sessionId === void 0) return { - name: void 0, - worktree: false - }; - return byId.get(sessionId) ?? { - name: void 0, - worktree: false - }; + if (sessionId === void 0) return UNDECIDED; + return byId.get(sessionId) ?? UNDECIDED; }, declare(sessionId, name$1) { if (sessionId === void 0) return; const current = byId.get(sessionId); const next = { name: name$1 ?? void 0, - worktree: true + worktree: true, + explicit: true }; - if (current !== void 0 && current.name === next.name && current.worktree === next.worktree) return; + if (current !== void 0 && current.name === next.name && current.worktree && current.explicit) return; const cloned = new Map(byId); cloned.set(sessionId, next); bump(cloned); }, clear(sessionId) { if (sessionId === void 0) return; - if (!byId.has(sessionId)) return; + const current = byId.get(sessionId); + if (current !== void 0 && !current.worktree && current.explicit) return; const cloned = new Map(byId); - cloned.delete(sessionId); + cloned.set(sessionId, { + name: void 0, + worktree: false, + explicit: true + }); bump(cloned); } }; } +//#endregion +//#region src/client/worktreePrefs.ts +/** +* Durable preferences of dsh-task-worktree, read and written through the +* client settings scope (`ctx.settingsScope`, provided by +* `@deepseek-ai/dsh-client-ui-settings`). +* +* The host half registers the `task-worktree` settings namespace; this store is +* the browser mirror of it. It keeps a plain observable snapshot so slot +* components can read it through `useSyncExternalStore`, and it routes every +* user choice through the scope's revision-fenced writes. +* +* The settings transport is reached structurally rather than by importing its +* types: this external package must stay free of monorepo-internal type +* dependencies, and a host without the service simply never binds (the store +* then reports `available: false` and the controls render disabled). +*/ +/** Settings namespace owned by the host half; keep in sync with `lib/index.js`. */ +const SETTINGS_NS = "task-worktree"; +/** Read the three-way panel choice out of a resolved section. */ +function choiceOf(prefs) { + return prefs.rememberLastChoice ? "last" : prefs.defaultMode; +} +/** Snapshot used before any settings service answers (the schema defaults). */ +const PREFS_FALLBACK = Object.freeze({ + defaultMode: "local", + rememberLastChoice: false, + status: "loading", + available: false +}); +/** +* Narrow one wire section to the section this plugin owns. +* +* The host resolves the schema before the value reaches the browser, so this +* stays defensive rather than validating: an unexpected section keeps the last +* accepted value (returning undefined). Both fields fall back to the schema +* default (local, no remembering) rather than to a truthy guess. +*/ +function decode(section) { + if (typeof section !== "object" || section === null || Array.isArray(section)) return void 0; + const raw = section; + return { + defaultMode: raw.defaultMode === "worktree" ? "worktree" : "local", + rememberLastChoice: raw.rememberLastChoice === true + }; +} +function createPrefsStore() { + let snapshot = PREFS_FALLBACK; + let scope; + const listeners = /* @__PURE__ */ new Set(); + const publish = (next) => { + if (snapshot.defaultMode === next.defaultMode && snapshot.rememberLastChoice === next.rememberLastChoice && snapshot.status === next.status && snapshot.available === next.available) return; + snapshot = next; + for (const listener of listeners) listener(); + }; + /** Fold the scope's latest accepted section into the local snapshot. */ + const adopt = () => { + if (scope === void 0) return; + const current = scope.getSnapshot(); + const value = current.value; + publish({ + defaultMode: value?.defaultMode === "worktree" ? "worktree" : "local", + rememberLastChoice: value?.rememberLastChoice !== false, + status: current.status, + available: current.status === "ready" && current.writable + }); + }; + /** + * Apply ordered writes and confirm acceptance by re-reading the scope. + * + * The transport RESOLVES even when the host refuses a write, so the resolved + * promise proves nothing; the documented way to detect refusal is to read the + * section back (a rejected write triggers the scope's recovery read first). + * A host without `mutate` falls back to per-field `set`, which is the same + * sequence without the atomicity fence. + */ + const apply$1 = async (ops) => { + if (scope === void 0) return false; + try { + if (typeof scope.mutate === "function") await scope.mutate(ops); + else for (const op of ops) if (op.op === "set") await scope.set(op.path[0], op.value); + } catch (error) { + console.warn(`[dsh-task-worktree] settings write failed: ${error instanceof Error ? error.message : String(error)}`); + return false; + } + const current = scope.getSnapshot(); + const section = current.value; + if (current.status !== "ready" || section === void 0) return false; + const accepted = ops.every((op) => op.op !== "set" || section[op.path[0]] === op.value); + adopt(); + return accepted; + }; + return { + subscribe(listener) { + listeners.add(listener); + return () => listeners.delete(listener); + }, + getSnapshot() { + return snapshot; + }, + bind(binder) { + scope = binder.bind({ + namespace: SETTINGS_NS, + decode + }); + adopt(); + return scope.subscribe(adopt); + }, + setDefaultMode(mode) { + return apply$1([{ + op: "set", + path: ["defaultMode"], + value: mode + }]); + }, + setNewConversationChoice(choice) { + if (choice === "last") return apply$1([{ + op: "set", + path: ["rememberLastChoice"], + value: true + }]); + return apply$1([{ + op: "set", + path: ["defaultMode"], + value: choice + }, { + op: "set", + path: ["rememberLastChoice"], + value: false + }]); + } + }; +} + +//#endregion +//#region \0dsh-css:src/client/WorktreeSettings.module.css.mjs +const css = ".sqfP6G_card{border:.5px solid var(--dsw-alias-border-l4,#ffffff24);background:var(--dsw-alias-bg-layer-3,#26262b);border-radius:16px;list-style:none;transition:border-color .16s,background .16s}.sqfP6G_card:hover{border-color:var(--dsw-alias-label-dimmed,#ffffff57)}.sqfP6G_cardOpen{background:var(--dsw-alias-bg-layer-2,#1f1f24);border-color:var(--dsw-alias-label-dimmed,#ffffff57)}.sqfP6G_header{width:100%;color:inherit;font:inherit;text-align:left;cursor:pointer;-webkit-appearance:none;appearance:none;background:0 0;border:0;border-radius:12px;align-items:center;gap:12px;padding:14px 16px;display:flex}.sqfP6G_header:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f73ff);outline-offset:-2px}.sqfP6G_headText{flex-direction:column;flex:1;gap:4px;min-width:0;display:flex}.sqfP6G_name{color:var(--dsw-alias-label-primary,#fff);font-size:15px;font-weight:600;line-height:1.4}.sqfP6G_description{color:var(--dsw-alias-label-tertiary,#8a8f98);font-size:13px;line-height:1.5}.sqfP6G_chevron{color:var(--dsw-alias-label-tertiary,#8a8f98);flex:none;transition:transform .16s}.sqfP6G_chevronOpen{transform:rotate(180deg)}.sqfP6G_body{border-top:.5px solid var(--dsw-alias-border-l2,#ffffff14);margin:0 16px;padding-bottom:8px}.sqfP6G_field{flex-direction:column;gap:6px;padding:12px 0;display:flex}.sqfP6G_head{align-items:center;gap:8px;display:flex}.sqfP6G_label{min-width:0;color:var(--dsw-alias-label-primary,#fff);flex:1;font-size:13px;font-weight:500;line-height:1.5}.sqfP6G_controlIcon{flex:none}.sqfP6G_hint{color:var(--dsw-alias-label-tertiary,#8a8f98);margin:0;font-size:12px;line-height:1.5}.sqfP6G_readOnly,.sqfP6G_failed{margin:12px 0 0;font-size:12px;line-height:1.5}.sqfP6G_readOnly{color:var(--dsw-alias-label-tertiary,#8a8f98)}.sqfP6G_failed{color:var(--dsw-alias-label-error,#e06c6c)}"; +const tagId = "dsh-task-worktree/WorktreeSettings.module.css"; +if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) { + const tag = document.createElement("style"); + tag.dataset.plugin = "dsh-task-worktree"; + tag.dataset.pluginCss = tagId; + tag.textContent = css; + document.head.appendChild(tag); +} +var WorktreeSettings_module_css_default = { + "body": "sqfP6G_body", + "card": "sqfP6G_card", + "cardOpen": "sqfP6G_cardOpen", + "chevron": "sqfP6G_chevron", + "chevronOpen": "sqfP6G_chevronOpen", + "controlIcon": "sqfP6G_controlIcon", + "description": "sqfP6G_description", + "failed": "sqfP6G_failed", + "field": "sqfP6G_field", + "head": "sqfP6G_head", + "headText": "sqfP6G_headText", + "header": "sqfP6G_header", + "hint": "sqfP6G_hint", + "label": "sqfP6G_label", + "name": "sqfP6G_name", + "readOnly": "sqfP6G_readOnly" +}; + +//#endregion +//#region src/client/WorktreeSettingsCard.tsx +/** +* The plugin's card on the Plugins → Plugin configuration settings page. +* +* It owns the `task-worktree` settings namespace through ONE three-way choice: +* pin local mode, pin worktree mode, or let the composer's picker decide and +* remember it. Two controls (a mode plus a "remember" switch) would describe +* the same three states with a fourth combination that means nothing, which is +* why this is a single choice. +* +* Everything interactive is a host primitive: the trigger is the host `Button` +* and the list is the host `Menu` — the same pair the Permission row uses for +* its own "choose one" setting. What this module styles is only the card chrome +* and the field typography, which the host does not export for plugin-owned +* cards (`ui-settings-plugins` exports `apply`/`inject` and types only). +* +* Writes go through the client settings scope (revision-fenced, persisted by +* the host), so the value is live and survives restarts. The card is dispatched +* by the Plugins section under the settings namespace this plugin's host half +* registers, so it appears only where that namespace is actually served. +*/ +function WorktreeSettingsCard({ prefs, t }) { + const snapshot = (0, react.useSyncExternalStore)(prefs.subscribe, prefs.getSnapshot); + const [open, setOpen] = (0, react.useState)(false); + const [menuOpen, setMenuOpen] = (0, react.useState)(false); + const [busy, setBusy] = (0, react.useState)(false); + const [failed, setFailed] = (0, react.useState)(false); + const disabled = !snapshot.available || busy; + const choice = choiceOf(snapshot); + const remembered = snapshot.defaultMode === "worktree" ? t("worktreeMode") : t("localMode"); + const hint = choice === "last" ? `${t("settingsRememberHint")} ${t("settingsRememberedNow")}${remembered}` : choice === "worktree" ? t("settingsDefaultWorktreeHint") : t("settingsDefaultLocalHint"); + const options = [ + { + id: "local", + label: t("localMode") + }, + { + id: "worktree", + label: t("worktreeMode") + }, + { + id: "last", + label: t("settingsRemember") + } + ]; + const selected = options.find((option) => option.id === choice) ?? options[0]; + const choose = (next) => { + setMenuOpen(false); + if (disabled || next === choice) return; + setBusy(true); + setFailed(false); + prefs.setNewConversationChoice(next).then((ok) => { + if (!ok) setFailed(true); + }).finally(() => { + setBusy(false); + }); + }; + return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { + className: open ? `${WorktreeSettings_module_css_default.card} ${WorktreeSettings_module_css_default.cardOpen}` : WorktreeSettings_module_css_default.card, + "data-testid": "worktree-settings-card", + children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", { + type: "button", + className: WorktreeSettings_module_css_default.header, + "aria-expanded": open, + onClick: () => { + setOpen(!open); + }, + children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { + className: WorktreeSettings_module_css_default.headText, + children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { + className: WorktreeSettings_module_css_default.name, + children: t("settingsCardTitle") + }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { + className: WorktreeSettings_module_css_default.description, + children: t("settingsCardDesc") + })] + }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { + className: open ? `${WorktreeSettings_module_css_default.chevron} ${WorktreeSettings_module_css_default.chevronOpen}` : WorktreeSettings_module_css_default.chevron, + children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__deepseek_ai_dsh_client_ui_primitives.IconChevronDownOutlineRegular, { size: 14 }) + })] + }), open && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { + className: WorktreeSettings_module_css_default.body, + children: [ + /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { + className: WorktreeSettings_module_css_default.field, + children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { + className: WorktreeSettings_module_css_default.head, + children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { + className: WorktreeSettings_module_css_default.label, + children: t("settingsDefaultMode") + }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__deepseek_ai_dsh_client_ui_primitives.Menu, { + open: menuOpen, + onClose: () => { + setMenuOpen(false); + }, + items: options, + selectedId: choice, + onSelect: choose, + align: "end", + portal: true, + anchor: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__deepseek_ai_dsh_client_ui_primitives.Button, { + variant: "toolbar", + "aria-haspopup": "menu", + "aria-expanded": menuOpen, + disabled, + onClick: () => { + setMenuOpen((value) => !value); + }, + children: [selected.label, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__deepseek_ai_dsh_client_ui_primitives.IconChevronDownOutlineRegular, { + size: 14, + className: WorktreeSettings_module_css_default.controlIcon + })] + }) + })] + }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { + className: WorktreeSettings_module_css_default.hint, + children: hint + })] + }), + snapshot.status === "unavailable" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { + className: WorktreeSettings_module_css_default.readOnly, + children: t("settingsUnavailable") + }), + failed && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { + className: WorktreeSettings_module_css_default.failed, + role: "alert", + children: t("settingsSaveFailed") + }) + ] + })] + }); +} + //#endregion //#region src/client/index.ts /** @@ -479,6 +820,19 @@ function apply(ctx) { const t = (key) => ctx.locale.bind(NS)(key); /** Reactive store for worktree-mode declarations. */ const store = createWorktreeStore(); + /** Durable preferences: default mode for new conversations + last-choice memory. */ + const prefs = createPrefsStore(); + ctx.inject(["settingsScope"], (scoped) => { + scoped.effect(() => prefs.bind(scoped.settingsScope), `${NS}: settings scope`); + scoped.slots.inject("settings.plugin.item", () => scoped.slots.register({ + name: "settings.plugin.item", + key: SETTINGS_NS, + locale: NS + }, () => (0, react.createElement)(WorktreeSettingsCard, { + prefs, + t + }))); + }); /** Resolve the current session face through the current selection id. */ const currentSession = () => { const current = ctx.sessions.list.getSnapshot().current; @@ -546,6 +900,7 @@ function apply(ctx) { armWorktreeMode, disarmWorktreeMode, store, + prefs, sessionIdOf: currentSessionId, t }))); diff --git a/client/client.js.map b/client/client.js.map index 6ebc8f5..c2654c0 100644 --- a/client/client.js.map +++ b/client/client.js.map @@ -1 +1 @@ -{"version":3,"file":"client.js","names":["WORKTREE_PATH","name","css","IconBranchOutlineRegular","name","css","IconBranchOutlineRegular","IconFolderOpenOutlineRegular","IconChevronDownOutlineRegular","name","name"],"sources":["../src/client/locales.ts","../src/client/worktreeLedger.ts","../src/client/WorktreeBadge.tsx","../src/client/WorktreePanel.tsx","../src/client/worktreeStore.ts","../src/client/index.ts"],"sourcesContent":["/**\n * Locale dictionaries for the dsh-task-worktree client half.\n * Product copy is Chinese; the English side exists for parity.\n */\n\nexport const zh = {\n panelTitle: '工作树',\n localMode: '本地模式',\n worktreeMode: 'Worktree模式',\n switching: '正在切换…',\n fail: '命令未执行成功',\n badgeTooltip: '本对话使用的 worktree',\n badgeFallback: 'worktree',\n heroStartLabel: '分支名:',\n heroStartPlaceholder: '可选,留空由 AI 命名',\n}\n\nexport const en = {\n panelTitle: 'Worktrees',\n localMode: 'Local mode',\n worktreeMode: 'Worktree mode',\n switching: 'Switching…',\n fail: 'Command failed',\n badgeTooltip: 'Worktree used by this conversation',\n badgeFallback: 'worktree',\n heroStartLabel: 'Branch: ',\n heroStartPlaceholder: 'optional; blank: AI proposes',\n}\n\nexport type WorktreeKey = typeof zh","/**\n * Client-side worktree recognition helpers.\n *\n * The plugin no longer registers a workspace per worktree (that cluttered the\n * sidebar); each conversation is *labelled* instead. The label comes from the\n * worktree declaration store (armed via start-in-worktree-mode) or from the\n * session cwd when it runs inside a managed checkout.\n *\n * dsh 0.1.2 note: the transcript-scanning helper (`worktreeNameOfSnapshot`)\n * was removed — `@deepseek-ai/dsh-client-runtime` and its ConversationNode\n * model no longer exist; the badge derives the label from the store plus cwd.\n */\n\n/** Registry path marker: /.dsh-worktrees/worktree/. */\nconst WORKTREE_PATH = /[\\\\/]\\.dsh-worktrees[\\\\/]worktree[\\\\/](.+)$/u\n\n/**\n * Derive the worktree name from a session cwd running inside a managed\n * checkout, or undefined for a local session.\n */\nexport function worktreeNameOfCwd(cwd: string | undefined): string | undefined {\n if (typeof cwd !== 'string' || cwd === '') return undefined\n const match = WORKTREE_PATH.exec(cwd)\n return match === null ? undefined : match[1].replace(/[\\\\/]+$/u, '')\n}","/**\n * Conversation-header worktree badge: renders a branch icon next to the\n * session title when this conversation is in worktree mode — declared via\n * start-in-worktree-mode (store) or running inside a checkout (cwd). Marks\n * the conversation in the Qoder style without consuming a workspace entry.\n */\nimport { useSyncExternalStore } from 'react'\nimport type { ReactNode } from 'react'\nimport { IconBranchOutlineRegular } from '@deepseek-ai/dsh-client-ui-primitives'\nimport { worktreeNameOfCwd } from './worktreeLedger.ts'\nimport type { WorktreeStore } from './worktreeStore.ts'\nimport css from './WorktreePanel.module.css'\n\n/** Props: registrant inject only (components never see ctx). */\nexport interface WorktreeBadgeProps {\n /** Resolve the staged session id (the conversation whose header we sit in). */\n sessionIdOf(): string | undefined\n /** Current session cwd (immutable per session; one-shot read is enough). */\n currentCwd(): string | undefined\n /** The declared-worktree store. */\n store: WorktreeStore\n /** Locale string binder. */\n t(key: string): string\n}\n\n/** Minimal console/debug hook exposed for in-GUI diagnosis. */\ndeclare global {\n interface Window {\n __dshTaskWorktreeDebug?: {\n sessionId: string | undefined\n declared: string | undefined\n declaredWorktree: boolean\n cwd: string | undefined\n label: string | undefined\n }\n }\n}\n\n/** Render the branch badge; nothing when the staged conversation has no worktree. */\nexport function WorktreeBadge(props: WorktreeBadgeProps): ReactNode {\n const { currentCwd, store, t } = props\n useSyncExternalStore(store.subscribe, store.getVersion)\n const sessionId = props.sessionIdOf()\n const cwdName = worktreeNameOfCwd(currentCwd())\n const declared = store.stateOf(sessionId)\n // Badge switches on once worktree mode is selected/armed (or the session\n // runs inside a checkout); a declared mode with no name shows the fallback.\n const fallback = declared.worktree ? t('badgeFallback') : undefined\n const name = declared.name ?? cwdName ?? fallback\n\n window.__dshTaskWorktreeDebug = {\n sessionId,\n declared: declared.name,\n declaredWorktree: declared.worktree,\n cwd: cwdName,\n label: name,\n }\n\n if (name === undefined) return null\n return (\n \n \n {name}\n \n )\n}","/**\n * Compact local/worktree mode selector mounted above the composer.\n *\n * Selecting Worktree mode arms the host (the creation instruction rides the\n * next user message); the revealed strip optionally takes a name (Enter to\n * apply). Selecting Local mode disarms. Management commands (/worktree\n * list/status/...) stay available from the composer directly.\n */\nimport { useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from 'react'\nimport type { ReactNode } from 'react'\nimport type { SessionFace } from '@deepseek-ai/dsh-api-session-controller/client'\nimport {\n // dsh-client-ui-primitives 0.1.7 renamed the icon sizes: Regular (1px\n // stroke) replaces the numbered 14/16 artwork words.\n IconBranchOutlineRegular,\n IconChevronDownOutlineRegular,\n IconFolderOpenOutlineRegular,\n} from '@deepseek-ai/dsh-client-ui-primitives'\nimport type { WorktreeKey } from './locales.ts'\nimport type { WorktreeStore } from './worktreeStore.ts'\nimport css from './WorktreePanel.module.css'\n\nconst WORKTREE_PATH = /[\\\\/]\\.dsh-worktrees[\\\\/]worktree[\\\\/]/u\n\n/** Minimal console/debug hook exposed for in-GUI diagnosis. */\ndeclare global {\n interface Window {\n __dshTaskWorktreePanelDebug?: {\n sessionId: string | undefined\n mode: string\n hero: boolean\n declaredWorktree: boolean\n }\n }\n}\n\n/** Injected callbacks (from the plugin apply closure — components never see ctx). */\nexport interface WorktreePanelInjected {\n /** Resolve the current session face (or undefined when absent). */\n currentSession(): SessionFace | undefined\n /** Resolve the current session's workspace cwd from the session-list summary. */\n currentCwd(): string | undefined\n /** Whether the staged session is a blank (empty-log) conversation. */\n currentBlank(): boolean\n /** Open a fresh session in the local workspace that owns the current worktree (legacy checkout sessions). */\n openLocalWorkspace(): Promise\n /** Arm worktree mode: the host injects the creation instruction with the next user message (optional name). */\n armWorktreeMode(name: string | undefined): Promise\n /** Disarm worktree mode. */\n disarmWorktreeMode(): Promise\n}\n\nexport interface WorktreePanelProps extends WorktreePanelInjected {\n /** Locale-bound strings for the action labels. */\n t: (key: keyof WorktreeKey) => string\n /** The declared-worktree store. */\n store: WorktreeStore\n /** Resolve the staged session id. */\n sessionIdOf(): string | undefined\n}\n\nfunction currentMode(injected: WorktreePanelInjected): 'local' | 'worktree' {\n const cwd = injected.currentCwd()\n return typeof cwd === 'string' && WORKTREE_PATH.test(cwd) ? 'worktree' : 'local'\n}\n\nexport function WorktreePanel(props: WorktreePanelProps): ReactNode {\n const { t, store, sessionIdOf } = props\n const rootRef = useRef(null)\n const [open, setOpen] = useState(false)\n const [name, setName] = useState('')\n const [busy, setBusy] = useState(null)\n const [notice, setNotice] = useState(null)\n const nameTimer = useRef(undefined)\n /** Last raw name actually sent to the host (dedup guard for re-arms). */\n const lastAppliedRef = useRef('')\n useSyncExternalStore(store.subscribe, store.getVersion)\n const sessionId = sessionIdOf()\n const declared = store.stateOf(sessionId)\n // Blank-hero bit still tracked for layout/debugging; the strip itself is\n // driven purely by the mode dropdown selection.\n const hero = props.currentBlank()\n // A conversation declared (or runs inside) a worktree shows worktree mode.\n const mode = declared.worktree || currentMode(props) === 'worktree' ? 'worktree' : 'local'\n\n // Keep the name input in sync with the committed worktree name.\n useEffect(() => {\n setName(declared.name ?? '')\n }, [declared.name])\n\n // Clear the pending name-apply timer on unmount.\n useEffect(() => () => {\n if (nameTimer.current !== undefined) window.clearTimeout(nameTimer.current)\n }, [])\n\n window.__dshTaskWorktreePanelDebug = {\n sessionId,\n mode,\n hero,\n declaredWorktree: declared.worktree,\n }\n\n useLayoutEffect(() => {\n const root = rootRef.current\n const heroRow = root?.parentElement?.previousElementSibling\n if (root === null || root === undefined || !(heroRow instanceof HTMLElement) || root.closest('[data-phase=\"hero\"]') === null) {\n root?.style.removeProperty('--worktree-hero-inset')\n return\n }\n\n const updateInset = (): void => {\n const rootRect = root.getBoundingClientRect()\n const rightEdge = Array.from(heroRow.querySelectorAll('*')).reduce((right, element) => {\n const rect = element.getBoundingClientRect()\n return rect.width > 0 && rect.height > 0 ? Math.max(right, rect.right) : right\n }, rootRect.left)\n const inset = Math.max(0, Math.ceil(rightEdge - rootRect.left + 6))\n root.style.setProperty('--worktree-hero-inset', `${inset}px`)\n }\n\n updateInset()\n const resizeObserver = new ResizeObserver(updateInset)\n const mutationObserver = new MutationObserver(updateInset)\n resizeObserver.observe(heroRow)\n mutationObserver.observe(heroRow, { childList: true, subtree: true, characterData: true })\n window.addEventListener('resize', updateInset)\n return () => {\n resizeObserver.disconnect()\n mutationObserver.disconnect()\n window.removeEventListener('resize', updateInset)\n }\n }, [])\n\n const closeMenu = (): void => {\n setOpen(false)\n setName('')\n }\n\n useEffect(() => {\n if (!open) return\n const onPointerDown = (event: PointerEvent): void => {\n if (rootRef.current?.contains(event.target as Node) !== true) closeMenu()\n }\n const onKeyDown = (event: KeyboardEvent): void => {\n if (event.key === 'Escape') closeMenu()\n }\n document.addEventListener('pointerdown', onPointerDown, true)\n document.addEventListener('keydown', onKeyDown)\n return () => {\n document.removeEventListener('pointerdown', onPointerDown, true)\n document.removeEventListener('keydown', onKeyDown)\n }\n }, [open])\n\n const showFailure = (): void => {\n setNotice(t('fail'))\n window.setTimeout(() => setNotice(null), 1800)\n }\n\n /** Legacy: leave a session actually running inside a worktree checkout. */\n const switchLocal = (): void => {\n if (busy !== null) return\n if (mode === 'local') {\n closeMenu()\n return\n }\n setBusy('local')\n void props.openLocalWorkspace().then(() => {\n closeMenu()\n }).catch(() => {\n showFailure()\n }).finally(() => {\n setBusy(null)\n })\n }\n\n const toggleMenu = (): void => {\n setOpen(value => !value)\n }\n\n /** 本地模式 radio: disarm the declared worktree mode, or leave a legacy checkout session. */\n const selectLocal = (): void => {\n if (busy !== null) return\n if (declared.worktree) {\n disarmMode()\n closeMenu()\n return\n }\n if (mode === 'worktree') {\n switchLocal()\n return\n }\n closeMenu()\n }\n\n /** Commit the typed worktree name: re-arms the host with that name (mode-on\n * is idempotent; the pending name simply updates). Debounced at 900ms and\n * deduplicated against the previously applied value — a single typing run\n * produces at most ONE command row in the conversation, not one per pause. */\n const applyName = (value: string): void => {\n setName(value)\n const trimmed = value.trim()\n if (trimmed === lastAppliedRef.current) return\n if (nameTimer.current !== undefined) window.clearTimeout(nameTimer.current)\n nameTimer.current = window.setTimeout(() => {\n nameTimer.current = undefined\n if (busy !== null) return\n lastAppliedRef.current = trimmed\n void props.armWorktreeMode(trimmed === '' ? undefined : trimmed).catch(() => {\n lastAppliedRef.current = ''\n showFailure()\n })\n }, 900)\n }\n\n const disarmMode = (): void => {\n if (busy !== null) return\n setBusy('disarmMode')\n void props.disarmWorktreeMode().catch(() => {\n showFailure()\n }).finally(() => {\n setBusy(null)\n })\n }\n\n // The mode selector only matters before the conversation starts; after the\n // first message the header badge carries the mode indication instead.\n if (!hero) return null\n\n return (\n \n \n {mode === 'worktree'\n ? \n : }\n {mode === 'worktree' ? t('worktreeMode') : t('localMode')}\n \n \n\n {declared.worktree && (\n
\n \n {t('heroStartLabel')}\n applyName(event.target.value)}\n placeholder={t('heroStartPlaceholder')}\n aria-label={t('heroStartPlaceholder')}\n disabled={busy !== null}\n />\n
\n )}\n\n {open && (\n
\n \n \n {busy === 'local' ? t('switching') : t('localMode')}\n \n {\n // Selecting worktree mode arms the host immediately (the\n // creation instruction rides the next message); the strip\n // lets you set a name with Enter.\n if (!declared.worktree) {\n void props.armWorktreeMode(undefined).catch(() => showFailure())\n }\n closeMenu()\n }}\n >\n \n {t('worktreeMode')}\n \n
\n )}\n\n {notice !== null && {notice}}\n \n )\n}","/**\n * Reactive per-session worktree mode store.\n *\n * Selecting Worktree mode in the mode dropdown arms the host immediately\n * (`/worktree mode-on`); the store mirrors that with the optional declared\n * name. Slot components read it through useSyncExternalStore.\n */\n/** State the components need for the current session. */\nexport interface WorktreeSessionState {\n /** Declared worktree name (arm-worktree-mode), or undefined. */\n name: string | undefined\n /** Worktree mode selected/armed (badge + strip on). */\n worktree: boolean\n}\n\n/** Plain observable store keyed by session id. */\nexport interface WorktreeStore {\n subscribe(listener: () => void): () => void\n getVersion(): number\n stateOf(sessionId: string | undefined): WorktreeSessionState\n /** Arm the host: worktree mode + optional name. */\n declare(sessionId: string | undefined, name: string | undefined): void\n clear(sessionId: string | undefined): void\n}\n\nexport function createWorktreeStore(): WorktreeStore {\n let byId = new Map()\n let version = 0\n const listeners = new Set<() => void>()\n\n const bump = (next: Map): void => {\n byId = next\n version += 1\n for (const listener of listeners) listener()\n }\n\n return {\n subscribe(listener) {\n listeners.add(listener)\n return () => listeners.delete(listener)\n },\n getVersion() {\n return version\n },\n stateOf(sessionId) {\n if (sessionId === undefined) return { name: undefined, worktree: false }\n return byId.get(sessionId) ?? { name: undefined, worktree: false }\n },\n declare(sessionId, name) {\n if (sessionId === undefined) return\n const current = byId.get(sessionId)\n const next = { name: name ?? undefined, worktree: true }\n if (current !== undefined && current.name === next.name && current.worktree === next.worktree) return\n const cloned = new Map(byId)\n cloned.set(sessionId, next)\n bump(cloned)\n },\n clear(sessionId) {\n if (sessionId === undefined) return\n if (!byId.has(sessionId)) return\n const cloned = new Map(byId)\n cloned.delete(sessionId)\n bump(cloned)\n },\n }\n}","/**\n * dsh-task-worktree browser half.\n *\n * Mounts a compact worktree action bar into `conversation.input.dock`, a\n * worktree recognition badge into `conversation.session.header.actions`, and\n * a \"start in worktree mode\" strip on blank conversations.\n *\n * Workspace discipline: creating a worktree NEVER registers a workspace and\n * NEVER switches the conversation — work continues in-place.\n *\n * Data channels: the strip's blank-hero detection reads the host session\n * list (`blank` flag and cwd — window-independent); the badge reads the\n * worktree declaration store (set by start-in-worktree-mode) plus the session\n * cwd. Note: framework session standard props (useSession / useInput) are NOT\n * injected into slot components in the current shell, so nothing depends on\n * them.\n *\n * Built by tsdown into the __ModuleLoader__ factory bundle at\n * client/client.js; the only externals are the loader module table's react\n * entries.\n */\nimport { createElement as h } from 'react'\n// dsh 0.1.2 removed `@deepseek-ai/dsh-client-runtime`; the browser faces now\n// live on the API-controller/client packages (type-only imports — erased from\n// the tsdown bundle, so nothing here needs a module-table entry).\nimport type { ISessions, SessionFace } from '@deepseek-ai/dsh-api-session-controller/client'\nimport type { IWorkspaces } from '@deepseek-ai/dsh-api-workspace-controller/client'\nimport type { SessionId } from '@deepseek-ai/dsh-api-remotes/client'\nimport { en, zh } from './locales.ts'\nimport { WorktreeBadge } from './WorktreeBadge.tsx'\nimport { WorktreePanel } from './WorktreePanel.tsx'\nimport { createWorktreeStore } from './worktreeStore.ts'\n\nconst NS = 'dsh-task-worktree'\n\n/** The subset of the slots service this plugin touches (structural typing keeps\n * this external package free of monorepo-internal type dependencies). */\ninterface SlotsService {\n inject(slot: string, register: () => unknown): void\n register(meta: Record, component: () => unknown): unknown\n}\n\n/** The subset of the locale service this plugin touches. */\ninterface LocaleService {\n register(namespace: string, dicts: { zh: Record; en: Record }): unknown\n bind(namespace: string): (key: string) => string\n}\n\n/** The client cordis context shape this plugin relies on. */\ninterface WorktreeClientContext {\n effect(callback: () => unknown, label?: string): void\n locale: LocaleService\n slots: SlotsService\n sessions: ISessions\n workspaces: IWorkspaces\n}\n\nexport const name = 'dsh-task-worktree'\nexport const inject = ['slots', 'locale', 'sessions', 'workspaces']\n\nexport function apply(ctx: WorktreeClientContext): void {\n ctx.effect(() => ctx.locale.register(NS, { zh, en }), `${NS}: dictionaries`)\n\n const t = (key: string): string => ctx.locale.bind(NS)(key)\n\n /** Reactive store for worktree-mode declarations. */\n const store = createWorktreeStore()\n\n /** Resolve the current session face through the current selection id. */\n const currentSession = (): SessionFace | undefined => {\n const current = ctx.sessions.list.getSnapshot().current\n if (current === undefined) return undefined\n const binding = ctx.sessions.binding(current)\n return binding?.session\n }\n\n /** Resolve the current selection id (the staged conversation). */\n const currentSessionId = (): SessionId | undefined => ctx.sessions.list.getSnapshot().current\n\n /** Resolve the current cwd from the list summary (the outward session face intentionally omits it). */\n const currentCwd = (): string | undefined => {\n const snapshot = ctx.sessions.list.getSnapshot()\n return snapshot.current !== undefined ? snapshot.byId[snapshot.current]?.cwd : undefined\n }\n\n /** Whether the staged session is still blank (host-computed empty-log bit). */\n const currentBlank = (): boolean => {\n const snapshot = ctx.sessions.list.getSnapshot()\n return snapshot.current !== undefined && snapshot.byId[snapshot.current]?.blank === true\n }\n\n /** Open the local workspace that owns the current worktree checkout. */\n const openLocalWorkspace = async (): Promise => {\n const cwd = currentCwd()\n if (typeof cwd !== 'string' || cwd === '') {\n throw new Error('无法确定当前工作区路径')\n }\n const marker = /[\\\\/]\\.dsh-worktrees[\\\\/]worktree[\\\\/]/u.exec(cwd)\n const localPath = marker !== null ? cwd.slice(0, marker.index) : cwd\n // dsh 0.1.7: client-owned current-session selection moved to the view\n // owners; `ISessions.open` is gone. The capability keeps its guarantees:\n // the host registers (or adopts) the workspace and catalogues a session\n // inside it — the new session then appears in the session list.\n const workspace = await ctx.workspaces.create({ path: localPath })\n await ctx.sessions.create({ workspaceId: workspace.workspaceId })\n }\n\n /**\n * Arm this conversation for worktree mode: the host injects the creation\n * instruction with the NEXT genuine user message (no separate prompt, no\n * workspace registration). Name from the caller when given, otherwise the\n * model proposes one. On success the session is declared worktree-mode in\n * the store (the badge switches on immediately).\n */\n const armWorktreeMode = async (rawName: string | undefined): Promise => {\n const sessionId = currentSessionId()\n const session = currentSession()\n if (session === undefined || sessionId === undefined) throw new Error('当前没有可注入的对话')\n // Branch convention: every managed branch starts with \"worktree/\".\n const trimmed = rawName?.trim() ?? ''\n const name = trimmed === '' ? undefined : (trimmed.startsWith('worktree/') ? trimmed : `worktree/${trimmed}`)\n const line = name !== undefined ? `/worktree mode-on ${name}` : '/worktree mode-on'\n const result = await session.command(line)\n if (!result.ok || result.value.matched !== true) throw new Error('指令未执行成功')\n store.declare(sessionId, name)\n }\n\n /** Disarm worktree mode for the current conversation. */\n const disarmWorktreeMode = async (): Promise => {\n const sessionId = currentSessionId()\n const session = currentSession()\n if (session === undefined || sessionId === undefined) throw new Error('当前没有可注入的对话')\n const result = await session.command('/worktree mode-off')\n if (!result.ok || result.value.matched !== true) throw new Error('指令未执行成功')\n store.clear(sessionId)\n }\n\n // ── Slots ──────────────────────────────────────────────────────────────\n ctx.slots.inject('conversation.input.dock', () => ctx.slots.register({\n name: 'conversation.input.dock',\n id: 'worktree',\n order: 10,\n locale: NS,\n }, () => h(WorktreePanel, {\n currentSession,\n currentCwd,\n currentBlank,\n openLocalWorkspace,\n armWorktreeMode,\n disarmWorktreeMode,\n store,\n sessionIdOf: currentSessionId,\n t,\n })))\n\n ctx.slots.inject('conversation.session.header.actions', () => ctx.slots.register({\n name: 'conversation.session.header.actions',\n id: 'worktree-badge',\n // Negative order: static session context precedes interactive actions.\n order: -30,\n locale: NS,\n }, () => h(WorktreeBadge, {\n store,\n sessionIdOf: currentSessionId,\n currentCwd,\n t,\n })))\n}"],"mappings":";;;;;;;;;;;AAKA,MAAa,KAAK;CAChB,YAAY;CACZ,WAAW;CACX,cAAc;CACd,WAAW;CACX,MAAM;CACN,cAAc;CACd,eAAe;CACf,gBAAgB;CAChB,sBAAsB;CACvB;AAED,MAAa,KAAK;CAChB,YAAY;CACZ,WAAW;CACX,cAAc;CACd,WAAW;CACX,MAAM;CACN,cAAc;CACd,eAAe;CACf,gBAAgB;CAChB,sBAAsB;CACvB;;;;;;;;;;;;;;;;;ACbD,MAAMA,kBAAgB;;;;;AAMtB,SAAgB,kBAAkB,KAA6C;AAC7E,KAAI,OAAO,QAAQ,YAAY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,KAAI,MAAM,OAAO,iCAAiC,IAAI,MAAM,SAAS;EACnE,MAAM;EACN,IAAI;EACJ,OAAO;EACP,QAAQ;EACT,iCAAU,eAAe;EACxB;EACA;EACA;EACA;EACA;EACA;EACA;EACA,aAAa;EACb;EACD,CAAC,CAAC,CAAC;AAEJ,KAAI,MAAM,OAAO,6CAA6C,IAAI,MAAM,SAAS;EAC/E,MAAM;EACN,IAAI;EAEJ,OAAO;EACP,QAAQ;EACT,iCAAU,eAAe;EACxB;EACA,aAAa;EACb;EACA;EACD,CAAC,CAAC,CAAC"} \ No newline at end of file +{"version":3,"file":"client.js","names":["WORKTREE_PATH","name","css","IconBranchOutlineRegular","name","css","IconBranchOutlineRegular","IconFolderOpenOutlineRegular","IconChevronDownOutlineRegular","UNDECIDED: WorktreeSessionState","name","PREFS_FALLBACK: WorktreePrefsSnapshot","snapshot: WorktreePrefsSnapshot","scope: SettingsScopeLike | undefined","apply","options: { id: NewConversationChoice; label: string }[]","css","IconChevronDownOutlineRegular","Menu","Button","name"],"sources":["../src/client/locales.ts","../src/client/worktreeLedger.ts","../src/client/WorktreeBadge.tsx","../src/client/WorktreePanel.tsx","../src/client/worktreeStore.ts","../src/client/worktreePrefs.ts","../src/client/WorktreeSettingsCard.tsx","../src/client/index.ts"],"sourcesContent":["/**\n * Locale dictionaries for the dsh-task-worktree client half.\n * Product copy is Chinese; the English side exists for parity.\n */\n\nexport const zh = {\n panelTitle: '工作树',\n localMode: '本地模式',\n worktreeMode: 'Worktree模式',\n switching: '正在切换…',\n fail: '命令未执行成功',\n badgeTooltip: '本对话使用的 worktree',\n badgeFallback: 'worktree',\n heroStartLabel: '分支名:',\n heroStartPlaceholder: '可选,留空由 AI 命名',\n settingsCardTitle: '任务 Worktree',\n settingsCardDesc: '新对话默认进入的执行环境',\n settingsDefaultMode: '新对话默认模式',\n settingsDefaultLocalHint: '空白对话直接在主工作区开始。',\n settingsDefaultWorktreeHint: '空白对话以 worktree 模式开始:发出第一条消息时自动创建隔离的 worktree,无需再手动选择。',\n settingsRemember: '记住上次选择',\n settingsRememberHint: '空白对话沿用你在输入框上方最后选定的模式。',\n settingsRememberedNow: '当前记住:',\n settingsUnavailable: '当前宿主没有可写的设置存储,修改不会被保存。',\n settingsSaveFailed: '保存失败',\n}\n\nexport const en = {\n panelTitle: 'Worktrees',\n localMode: 'Local mode',\n worktreeMode: 'Worktree mode',\n switching: 'Switching…',\n fail: 'Command failed',\n badgeTooltip: 'Worktree used by this conversation',\n badgeFallback: 'worktree',\n heroStartLabel: 'Branch: ',\n heroStartPlaceholder: 'optional; blank: AI proposes',\n settingsCardTitle: 'Task worktree',\n settingsCardDesc: 'The execution environment new conversations start in',\n settingsDefaultMode: 'Default mode for new conversations',\n settingsDefaultLocalHint: 'A blank conversation starts directly in the main workspace.',\n settingsDefaultWorktreeHint: 'A blank conversation starts in worktree mode: the isolated worktree is created automatically with your first message.',\n settingsRemember: 'Remember the last choice',\n settingsRememberHint: 'A blank conversation starts with the mode you picked last above the composer.',\n settingsRememberedNow: 'Currently remembered: ',\n settingsUnavailable: 'This host has no writable settings storage, so changes cannot be saved.',\n settingsSaveFailed: 'Could not save',\n}\n\nexport type WorktreeKey = typeof zh\n","/**\n * Client-side worktree recognition helpers.\n *\n * The plugin no longer registers a workspace per worktree (that cluttered the\n * sidebar); each conversation is *labelled* instead. The label comes from the\n * worktree declaration store (armed via start-in-worktree-mode) or from the\n * session cwd when it runs inside a managed checkout.\n *\n * dsh 0.1.2 note: the transcript-scanning helper (`worktreeNameOfSnapshot`)\n * was removed — `@deepseek-ai/dsh-client-runtime` and its ConversationNode\n * model no longer exist; the badge derives the label from the store plus cwd.\n */\n\n/** Registry path marker: /.dsh-worktrees/worktree/. */\nconst WORKTREE_PATH = /[\\\\/]\\.dsh-worktrees[\\\\/]worktree[\\\\/](.+)$/u\n\n/**\n * Derive the worktree name from a session cwd running inside a managed\n * checkout, or undefined for a local session.\n */\nexport function worktreeNameOfCwd(cwd: string | undefined): string | undefined {\n if (typeof cwd !== 'string' || cwd === '') return undefined\n const match = WORKTREE_PATH.exec(cwd)\n return match === null ? undefined : match[1].replace(/[\\\\/]+$/u, '')\n}","/**\n * Conversation-header worktree badge: renders a branch icon next to the\n * session title when this conversation is in worktree mode — declared via\n * start-in-worktree-mode (store) or running inside a checkout (cwd). Marks\n * the conversation in the Qoder style without consuming a workspace entry.\n */\nimport { useSyncExternalStore } from 'react'\nimport type { ReactNode } from 'react'\nimport { IconBranchOutlineRegular } from '@deepseek-ai/dsh-client-ui-primitives'\nimport { worktreeNameOfCwd } from './worktreeLedger.ts'\nimport type { WorktreeStore } from './worktreeStore.ts'\nimport css from './WorktreePanel.module.css'\n\n/** Props: registrant inject only (components never see ctx). */\nexport interface WorktreeBadgeProps {\n /** Resolve the staged session id (the conversation whose header we sit in). */\n sessionIdOf(): string | undefined\n /** Current session cwd (immutable per session; one-shot read is enough). */\n currentCwd(): string | undefined\n /** The declared-worktree store. */\n store: WorktreeStore\n /** Locale string binder. */\n t(key: string): string\n}\n\n/** Minimal console/debug hook exposed for in-GUI diagnosis. */\ndeclare global {\n interface Window {\n __dshTaskWorktreeDebug?: {\n sessionId: string | undefined\n declared: string | undefined\n declaredWorktree: boolean\n cwd: string | undefined\n label: string | undefined\n }\n }\n}\n\n/** Render the branch badge; nothing when the staged conversation has no worktree. */\nexport function WorktreeBadge(props: WorktreeBadgeProps): ReactNode {\n const { currentCwd, store, t } = props\n useSyncExternalStore(store.subscribe, store.getVersion)\n const sessionId = props.sessionIdOf()\n const cwdName = worktreeNameOfCwd(currentCwd())\n const declared = store.stateOf(sessionId)\n // Badge switches on once worktree mode is selected/armed (or the session\n // runs inside a checkout); a declared mode with no name shows the fallback.\n const fallback = declared.worktree ? t('badgeFallback') : undefined\n const name = declared.name ?? cwdName ?? fallback\n\n window.__dshTaskWorktreeDebug = {\n sessionId,\n declared: declared.name,\n declaredWorktree: declared.worktree,\n cwd: cwdName,\n label: name,\n }\n\n if (name === undefined) return null\n return (\n \n \n {name}\n \n )\n}","/**\n * Compact local/worktree mode selector mounted above the composer.\n *\n * Selecting Worktree mode arms the host (the creation instruction rides the\n * next user message); the revealed strip optionally takes a name (Enter to\n * apply). Selecting Local mode disarms. Management commands (/worktree\n * list/status/...) stay available from the composer directly.\n *\n * On a blank conversation the selector reflects the configured default mode\n * (`task-worktree` settings namespace): with the default set to worktree the\n * strip is pre-armed and the host injects the creation instruction with the\n * first message. Picking a mode is always an explicit answer for THIS\n * conversation, and — when \"remember the last choice\" is on — it also updates\n * the default.\n */\nimport { useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from 'react'\nimport type { ReactNode } from 'react'\nimport type { SessionFace } from '@deepseek-ai/dsh-api-session-controller/client'\nimport {\n // dsh-client-ui-primitives 0.1.7 renamed the icon sizes: Regular (1px\n // stroke) replaces the numbered 14/16 artwork words.\n IconBranchOutlineRegular,\n IconChevronDownOutlineRegular,\n IconFolderOpenOutlineRegular,\n} from '@deepseek-ai/dsh-client-ui-primitives'\nimport type { WorktreeKey } from './locales.ts'\nimport type { WorktreePrefsStore } from './worktreePrefs.ts'\nimport type { WorktreeStore } from './worktreeStore.ts'\nimport css from './WorktreePanel.module.css'\n\nconst WORKTREE_PATH = /[\\\\/]\\.dsh-worktrees[\\\\/]worktree[\\\\/]/u\n\n/** Minimal console/debug hook exposed for in-GUI diagnosis. */\ndeclare global {\n interface Window {\n __dshTaskWorktreePanelDebug?: {\n sessionId: string | undefined\n mode: string\n hero: boolean\n declaredWorktree: boolean\n defaultMode: string\n explicit: boolean\n }\n }\n}\n\n/** Injected callbacks (from the plugin apply closure — components never see ctx). */\nexport interface WorktreePanelInjected {\n /** Resolve the current session face (or undefined when absent). */\n currentSession(): SessionFace | undefined\n /** Resolve the current session's workspace cwd from the session-list summary. */\n currentCwd(): string | undefined\n /** Whether the staged session is a blank (empty-log) conversation. */\n currentBlank(): boolean\n /** Open a fresh session in the local workspace that owns the current worktree (legacy checkout sessions). */\n openLocalWorkspace(): Promise\n /** Arm worktree mode: the host injects the creation instruction with the next user message (optional name). */\n armWorktreeMode(name: string | undefined): Promise\n /** Disarm worktree mode. */\n disarmWorktreeMode(): Promise\n}\n\nexport interface WorktreePanelProps extends WorktreePanelInjected {\n /** Locale-bound strings for the action labels. */\n t: (key: keyof WorktreeKey) => string\n /** The declared-worktree store. */\n store: WorktreeStore\n /** The durable preferences store (default mode + last-choice memory). */\n prefs: WorktreePrefsStore\n /** Resolve the staged session id. */\n sessionIdOf(): string | undefined\n}\n\nfunction currentMode(injected: WorktreePanelInjected): 'local' | 'worktree' {\n const cwd = injected.currentCwd()\n return typeof cwd === 'string' && WORKTREE_PATH.test(cwd) ? 'worktree' : 'local'\n}\n\nexport function WorktreePanel(props: WorktreePanelProps): ReactNode {\n const { t, store, sessionIdOf } = props\n const rootRef = useRef(null)\n const [open, setOpen] = useState(false)\n const [name, setName] = useState('')\n const [busy, setBusy] = useState(null)\n const [notice, setNotice] = useState(null)\n const nameTimer = useRef(undefined)\n /** Last raw name actually sent to the host (dedup guard for re-arms). */\n const lastAppliedRef = useRef('')\n useSyncExternalStore(store.subscribe, store.getVersion)\n const prefs = useSyncExternalStore(props.prefs.subscribe, props.prefs.getSnapshot)\n const sessionId = sessionIdOf()\n const declared = store.stateOf(sessionId)\n // Blank-hero bit still tracked for layout/debugging; the strip itself is\n // driven purely by the mode dropdown selection.\n const hero = props.currentBlank()\n // The configured default governs a blank conversation the user has not\n // answered for yet; the host arms it when the first message arrives.\n const defaultWorktree = hero && !declared.explicit && prefs.defaultMode === 'worktree'\n const preArmed = defaultWorktree && !declared.worktree\n // A conversation declared (or running inside) a worktree shows worktree mode.\n const mode = declared.worktree || defaultWorktree || currentMode(props) === 'worktree' ? 'worktree' : 'local'\n\n // Keep the name input in sync with the committed worktree name.\n useEffect(() => {\n setName(declared.name ?? '')\n }, [declared.name])\n\n // Clear the pending name-apply timer on unmount.\n useEffect(() => () => {\n if (nameTimer.current !== undefined) window.clearTimeout(nameTimer.current)\n }, [])\n\n window.__dshTaskWorktreePanelDebug = {\n sessionId,\n mode,\n hero,\n declaredWorktree: declared.worktree,\n defaultMode: prefs.defaultMode,\n explicit: declared.explicit,\n }\n\n useLayoutEffect(() => {\n const root = rootRef.current\n const heroRow = root?.parentElement?.previousElementSibling\n if (root === null || root === undefined || !(heroRow instanceof HTMLElement) || root.closest('[data-phase=\"hero\"]') === null) {\n root?.style.removeProperty('--worktree-hero-inset')\n return\n }\n\n const updateInset = (): void => {\n const rootRect = root.getBoundingClientRect()\n const rightEdge = Array.from(heroRow.querySelectorAll('*')).reduce((right, element) => {\n const rect = element.getBoundingClientRect()\n return rect.width > 0 && rect.height > 0 ? Math.max(right, rect.right) : right\n }, rootRect.left)\n const inset = Math.max(0, Math.ceil(rightEdge - rootRect.left + 6))\n root.style.setProperty('--worktree-hero-inset', `${inset}px`)\n }\n\n updateInset()\n const resizeObserver = new ResizeObserver(updateInset)\n const mutationObserver = new MutationObserver(updateInset)\n resizeObserver.observe(heroRow)\n mutationObserver.observe(heroRow, { childList: true, subtree: true, characterData: true })\n window.addEventListener('resize', updateInset)\n return () => {\n resizeObserver.disconnect()\n mutationObserver.disconnect()\n window.removeEventListener('resize', updateInset)\n }\n }, [])\n\n const closeMenu = (): void => {\n setOpen(false)\n setName('')\n }\n\n useEffect(() => {\n if (!open) return\n const onPointerDown = (event: PointerEvent): void => {\n if (rootRef.current?.contains(event.target as Node) !== true) closeMenu()\n }\n const onKeyDown = (event: KeyboardEvent): void => {\n if (event.key === 'Escape') closeMenu()\n }\n document.addEventListener('pointerdown', onPointerDown, true)\n document.addEventListener('keydown', onKeyDown)\n return () => {\n document.removeEventListener('pointerdown', onPointerDown, true)\n document.removeEventListener('keydown', onKeyDown)\n }\n }, [open])\n\n const showFailure = (): void => {\n setNotice(t('fail'))\n window.setTimeout(() => setNotice(null), 1800)\n }\n\n /** Persist a mode the user picked as the default for future conversations. */\n const remember = (choice: 'local' | 'worktree'): void => {\n if (prefs.rememberLastChoice) void props.prefs.setDefaultMode(choice)\n }\n\n /** Legacy: leave a session actually running inside a worktree checkout. */\n const switchLocal = (): void => {\n if (busy !== null) return\n if (mode === 'local') {\n closeMenu()\n return\n }\n setBusy('local')\n void props.openLocalWorkspace().then(() => {\n closeMenu()\n }).catch(() => {\n showFailure()\n }).finally(() => {\n setBusy(null)\n })\n }\n\n const toggleMenu = (): void => {\n setOpen(value => !value)\n }\n\n /** 本地模式 radio: disarm the declared worktree mode, or leave a legacy checkout session. */\n const selectLocal = (): void => {\n if (busy !== null) return\n if (declared.worktree || preArmed) {\n // An explicit local answer for this conversation: disarm the host, which\n // also suppresses the configured default for it.\n remember('local')\n disarmMode()\n closeMenu()\n return\n }\n if (mode === 'worktree') {\n switchLocal()\n return\n }\n closeMenu()\n }\n\n /** Commit the typed worktree name: re-arms the host with that name (mode-on\n * is idempotent; the pending name simply updates). Debounced at 900ms and\n * deduplicated against the previously applied value — a single typing run\n * produces at most ONE command row in the conversation, not one per pause. */\n const applyName = (value: string): void => {\n setName(value)\n const trimmed = value.trim()\n if (trimmed === lastAppliedRef.current) return\n if (nameTimer.current !== undefined) window.clearTimeout(nameTimer.current)\n nameTimer.current = window.setTimeout(() => {\n nameTimer.current = undefined\n if (busy !== null) return\n lastAppliedRef.current = trimmed\n void props.armWorktreeMode(trimmed === '' ? undefined : trimmed).catch(() => {\n lastAppliedRef.current = ''\n showFailure()\n })\n }, 900)\n }\n\n const disarmMode = (): void => {\n if (busy !== null) return\n setBusy('disarmMode')\n void props.disarmWorktreeMode().catch(() => {\n showFailure()\n }).finally(() => {\n setBusy(null)\n })\n }\n\n // The mode selector only matters before the conversation starts; after the\n // first message the header badge carries the mode indication instead.\n if (!hero) return null\n\n return (\n \n \n {mode === 'worktree'\n ? \n : }\n {mode === 'worktree' ? t('worktreeMode') : t('localMode')}\n \n \n\n {(declared.worktree || preArmed) && (\n
\n \n {t('heroStartLabel')}\n applyName(event.target.value)}\n placeholder={t('heroStartPlaceholder')}\n aria-label={t('heroStartPlaceholder')}\n disabled={busy !== null}\n />\n
\n )}\n\n {open && (\n
\n \n \n {busy === 'local' ? t('switching') : t('localMode')}\n \n {\n // Selecting worktree mode arms the host immediately (the\n // creation instruction rides the next message); the strip\n // lets you set a name with Enter. It is also an explicit\n // answer, so it can be remembered as the new default.\n remember('worktree')\n if (!declared.worktree) {\n void props.armWorktreeMode(undefined).catch(() => showFailure())\n }\n closeMenu()\n }}\n >\n \n {t('worktreeMode')}\n \n
\n )}\n\n {notice !== null && {notice}}\n \n )\n}","/**\n * Reactive per-session worktree mode store.\n *\n * Selecting Worktree mode in the mode dropdown arms the host immediately\n * (`/worktree mode-on`); the store mirrors that with the optional declared\n * name. Slot components read it through useSyncExternalStore.\n *\n * `explicit` records that the user answered for THIS conversation (worktree or\n * local). It is what keeps a configured default from overriding a deliberate\n * local choice: without it, \"local\" and \"not decided yet\" would look alike.\n */\n/** State the components need for the current session. */\nexport interface WorktreeSessionState {\n /** Declared worktree name (arm-worktree-mode), or undefined. */\n name: string | undefined\n /** Worktree mode selected/armed (badge + strip on). */\n worktree: boolean\n /** The user chose a mode for this conversation (either one). */\n explicit: boolean\n}\n\n/** Plain observable store keyed by session id. */\nexport interface WorktreeStore {\n subscribe(listener: () => void): () => void\n getVersion(): number\n stateOf(sessionId: string | undefined): WorktreeSessionState\n /** Arm the host: worktree mode + optional name. */\n declare(sessionId: string | undefined, name: string | undefined): void\n /** Record a deliberate local choice for this conversation. */\n clear(sessionId: string | undefined): void\n}\n\nconst UNDECIDED: WorktreeSessionState = { name: undefined, worktree: false, explicit: false }\n\nexport function createWorktreeStore(): WorktreeStore {\n let byId = new Map()\n let version = 0\n const listeners = new Set<() => void>()\n\n const bump = (next: Map): void => {\n byId = next\n version += 1\n for (const listener of listeners) listener()\n }\n\n return {\n subscribe(listener) {\n listeners.add(listener)\n return () => listeners.delete(listener)\n },\n getVersion() {\n return version\n },\n stateOf(sessionId) {\n if (sessionId === undefined) return UNDECIDED\n return byId.get(sessionId) ?? UNDECIDED\n },\n declare(sessionId, name) {\n if (sessionId === undefined) return\n const current = byId.get(sessionId)\n const next = { name: name ?? undefined, worktree: true, explicit: true }\n if (current !== undefined && current.name === next.name && current.worktree && current.explicit) return\n const cloned = new Map(byId)\n cloned.set(sessionId, next)\n bump(cloned)\n },\n clear(sessionId) {\n if (sessionId === undefined) return\n const current = byId.get(sessionId)\n if (current !== undefined && !current.worktree && current.explicit) return\n const cloned = new Map(byId)\n cloned.set(sessionId, { name: undefined, worktree: false, explicit: true })\n bump(cloned)\n },\n }\n}\n","/**\n * Durable preferences of dsh-task-worktree, read and written through the\n * client settings scope (`ctx.settingsScope`, provided by\n * `@deepseek-ai/dsh-client-ui-settings`).\n *\n * The host half registers the `task-worktree` settings namespace; this store is\n * the browser mirror of it. It keeps a plain observable snapshot so slot\n * components can read it through `useSyncExternalStore`, and it routes every\n * user choice through the scope's revision-fenced writes.\n *\n * The settings transport is reached structurally rather than by importing its\n * types: this external package must stay free of monorepo-internal type\n * dependencies, and a host without the service simply never binds (the store\n * then reports `available: false` and the controls render disabled).\n */\n\n/** Settings namespace owned by the host half; keep in sync with `lib/index.js`. */\nexport const SETTINGS_NS = 'task-worktree'\n\n/** Mode a conversation can start in. */\nexport type DefaultMode = 'local' | 'worktree'\n\n/**\n * The choice a user makes in the settings panel.\n *\n * Three states, because there are only three: pin local, pin worktree, or let\n * the composer decide and remember it. The first two map to\n * `{ defaultMode, rememberLastChoice: false }`, the third to\n * `rememberLastChoice: true` with `defaultMode` holding whatever was picked\n * last.\n */\nexport type NewConversationChoice = DefaultMode | 'last'\n\n/** The user-editable section of the settings namespace. */\nexport interface WorktreePreferences {\n /** Mode a blank conversation starts in (the remembered pick under `last`). */\n defaultMode: DefaultMode\n /** Composer choices write `defaultMode` back, so the next conversation matches. */\n rememberLastChoice: boolean\n}\n\n/** Read the three-way panel choice out of a resolved section. */\nexport function choiceOf(prefs: Pick): NewConversationChoice {\n return prefs.rememberLastChoice ? 'last' : prefs.defaultMode\n}\n\n/** Snapshot the components subscribe to. */\nexport interface WorktreePrefsSnapshot extends WorktreePreferences {\n /** Sync state of the settings transport (`loading` until the first answer). */\n status: 'loading' | 'ready' | 'unavailable'\n /** Whether a writable settings scope is bound (false: edits cannot persist). */\n available: boolean\n}\n\n/** One ordered write inside the settings namespace section. */\nexport interface SettingsFieldOp {\n op: 'set' | 'unset'\n path: string[]\n value?: unknown\n}\n\n/** The subset of the client settings scope this plugin touches. */\ninterface SettingsScopeLike {\n getSnapshot(): {\n status: 'loading' | 'ready' | 'unavailable'\n value: T | undefined\n writable: boolean\n }\n subscribe(listener: () => void): () => void\n set(field: string, value: unknown): Promise\n /** Atomic multi-field write; every host in the supported line exposes it. */\n mutate?(ops: readonly SettingsFieldOp[], expectedRevision?: number): Promise\n}\n\n/** The subset of `ctx.settingsScope` this plugin touches. */\nexport interface SettingsScopeBinder {\n bind(spec: { namespace: string; decode?: (section: unknown) => T | undefined }): SettingsScopeLike\n}\n\n/** Observable preference store consumed by the panel and the settings card. */\nexport interface WorktreePrefsStore {\n subscribe(listener: () => void): () => void\n getSnapshot(): WorktreePrefsSnapshot\n /** Bind the durable scope; returns the unsubscribe function (an effect body). */\n bind(binder: SettingsScopeBinder): () => void\n /** Write the mode a conversation just started with (composer \"remember\" path). */\n setDefaultMode(mode: DefaultMode): Promise\n /** Write the panel's three-way choice, atomically. */\n setNewConversationChoice(choice: NewConversationChoice): Promise\n}\n\n/** Snapshot used before any settings service answers (the schema defaults). */\nexport const PREFS_FALLBACK: WorktreePrefsSnapshot = Object.freeze({\n defaultMode: 'local' as DefaultMode,\n rememberLastChoice: false,\n status: 'loading' as const,\n available: false,\n})\n\n/**\n * Narrow one wire section to the section this plugin owns.\n *\n * The host resolves the schema before the value reaches the browser, so this\n * stays defensive rather than validating: an unexpected section keeps the last\n * accepted value (returning undefined). Both fields fall back to the schema\n * default (local, no remembering) rather than to a truthy guess.\n */\nfunction decode(section: unknown): WorktreePreferences | undefined {\n if (typeof section !== 'object' || section === null || Array.isArray(section)) return undefined\n const raw = section as { defaultMode?: unknown; rememberLastChoice?: unknown }\n return {\n defaultMode: raw.defaultMode === 'worktree' ? 'worktree' : 'local',\n rememberLastChoice: raw.rememberLastChoice === true,\n }\n}\n\nexport function createPrefsStore(): WorktreePrefsStore {\n let snapshot: WorktreePrefsSnapshot = PREFS_FALLBACK\n let scope: SettingsScopeLike | undefined\n const listeners = new Set<() => void>()\n\n const publish = (next: WorktreePrefsSnapshot): void => {\n if (\n snapshot.defaultMode === next.defaultMode\n && snapshot.rememberLastChoice === next.rememberLastChoice\n && snapshot.status === next.status\n && snapshot.available === next.available\n ) return\n snapshot = next\n for (const listener of listeners) listener()\n }\n\n /** Fold the scope's latest accepted section into the local snapshot. */\n const adopt = (): void => {\n if (scope === undefined) return\n const current = scope.getSnapshot()\n const value = current.value\n publish({\n defaultMode: value?.defaultMode === 'worktree' ? 'worktree' : 'local',\n rememberLastChoice: value?.rememberLastChoice !== false,\n status: current.status,\n available: current.status === 'ready' && current.writable,\n })\n }\n\n /**\n * Apply ordered writes and confirm acceptance by re-reading the scope.\n *\n * The transport RESOLVES even when the host refuses a write, so the resolved\n * promise proves nothing; the documented way to detect refusal is to read the\n * section back (a rejected write triggers the scope's recovery read first).\n * A host without `mutate` falls back to per-field `set`, which is the same\n * sequence without the atomicity fence.\n */\n const apply = async (ops: readonly SettingsFieldOp[]): Promise => {\n if (scope === undefined) return false\n try {\n if (typeof scope.mutate === 'function') {\n await scope.mutate(ops)\n } else {\n for (const op of ops) {\n if (op.op === 'set') await scope.set(op.path[0], op.value)\n }\n }\n } catch (error) {\n console.warn(`[dsh-task-worktree] settings write failed: ${error instanceof Error ? error.message : String(error)}`)\n return false\n }\n const current = scope.getSnapshot()\n const section = current.value as Record | undefined\n if (current.status !== 'ready' || section === undefined) return false\n const accepted = ops.every((op) => op.op !== 'set' || section[op.path[0]] === op.value)\n // Fold what the host accepted into our own snapshot now, rather than\n // waiting for the scope's change notification.\n adopt()\n return accepted\n }\n\n return {\n subscribe(listener) {\n listeners.add(listener)\n return () => listeners.delete(listener)\n },\n getSnapshot() {\n return snapshot\n },\n bind(binder) {\n scope = binder.bind({ namespace: SETTINGS_NS, decode })\n adopt()\n return scope.subscribe(adopt)\n },\n setDefaultMode(mode) {\n return apply([{ op: 'set', path: ['defaultMode'], value: mode }])\n },\n setNewConversationChoice(choice) {\n if (choice === 'last') {\n return apply([{ op: 'set', path: ['rememberLastChoice'], value: true }])\n }\n return apply([\n { op: 'set', path: ['defaultMode'], value: choice },\n { op: 'set', path: ['rememberLastChoice'], value: false },\n ])\n },\n }\n}\n","/**\n * The plugin's card on the Plugins → Plugin configuration settings page.\n *\n * It owns the `task-worktree` settings namespace through ONE three-way choice:\n * pin local mode, pin worktree mode, or let the composer's picker decide and\n * remember it. Two controls (a mode plus a \"remember\" switch) would describe\n * the same three states with a fourth combination that means nothing, which is\n * why this is a single choice.\n *\n * Everything interactive is a host primitive: the trigger is the host `Button`\n * and the list is the host `Menu` — the same pair the Permission row uses for\n * its own \"choose one\" setting. What this module styles is only the card chrome\n * and the field typography, which the host does not export for plugin-owned\n * cards (`ui-settings-plugins` exports `apply`/`inject` and types only).\n *\n * Writes go through the client settings scope (revision-fenced, persisted by\n * the host), so the value is live and survives restarts. The card is dispatched\n * by the Plugins section under the settings namespace this plugin's host half\n * registers, so it appears only where that namespace is actually served.\n */\nimport { useState, useSyncExternalStore } from 'react'\nimport type { ReactNode } from 'react'\nimport {\n Button,\n IconChevronDownOutlineRegular,\n Menu,\n} from '@deepseek-ai/dsh-client-ui-primitives'\nimport type { WorktreeKey } from './locales.ts'\nimport { choiceOf } from './worktreePrefs.ts'\nimport type { NewConversationChoice, WorktreePrefsStore } from './worktreePrefs.ts'\nimport css from './WorktreeSettings.module.css'\n\nexport interface WorktreeSettingsCardProps {\n /** Durable preferences (settings namespace `task-worktree`). */\n prefs: WorktreePrefsStore\n /** Locale-bound strings for the card copy. */\n t: (key: keyof WorktreeKey) => string\n}\n\nexport function WorktreeSettingsCard({ prefs, t }: WorktreeSettingsCardProps): ReactNode {\n const snapshot = useSyncExternalStore(prefs.subscribe, prefs.getSnapshot)\n const [open, setOpen] = useState(false)\n const [menuOpen, setMenuOpen] = useState(false)\n const [busy, setBusy] = useState(false)\n const [failed, setFailed] = useState(false)\n const disabled = !snapshot.available || busy\n const choice = choiceOf(snapshot)\n // Under `last` the remembered pick is what actually happens, so the hint\n // says which mode that currently is.\n const remembered = snapshot.defaultMode === 'worktree' ? t('worktreeMode') : t('localMode')\n const hint = choice === 'last'\n ? `${t('settingsRememberHint')} ${t('settingsRememberedNow')}${remembered}`\n : choice === 'worktree'\n ? t('settingsDefaultWorktreeHint')\n : t('settingsDefaultLocalHint')\n\n const options: { id: NewConversationChoice; label: string }[] = [\n { id: 'local', label: t('localMode') },\n { id: 'worktree', label: t('worktreeMode') },\n { id: 'last', label: t('settingsRemember') },\n ]\n const selected = options.find(option => option.id === choice) ?? options[0]\n\n const choose = (next: string): void => {\n setMenuOpen(false)\n if (disabled || next === choice) return\n setBusy(true)\n setFailed(false)\n void prefs.setNewConversationChoice(next as NewConversationChoice).then(ok => {\n if (!ok) setFailed(true)\n }).finally(() => {\n setBusy(false)\n })\n }\n\n return (\n
\n { setOpen(!open) }}\n >\n
\n
{t('settingsCardTitle')}
\n
{t('settingsCardDesc')}
\n
\n \n \n \n \n {open && (\n
\n
\n
\n {t('settingsDefaultMode')}\n { setMenuOpen(false) }}\n items={options}\n selectedId={choice}\n onSelect={choose}\n align=\"end\"\n portal\n anchor={(\n { setMenuOpen(value => !value) }}\n >\n {selected.label}\n \n \n )}\n />\n
\n

{hint}

\n
\n {snapshot.status === 'unavailable' &&

{t('settingsUnavailable')}

}\n {failed &&

{t('settingsSaveFailed')}

}\n
\n )}\n
\n )\n}\n","/**\n * dsh-task-worktree browser half.\n *\n * Mounts a compact worktree action bar into `conversation.input.dock`, a\n * worktree recognition badge into `conversation.session.header.actions`, and\n * a \"start in worktree mode\" strip on blank conversations.\n *\n * Workspace discipline: creating a worktree NEVER registers a workspace and\n * NEVER switches the conversation — work continues in-place.\n *\n * Data channels: the strip's blank-hero detection reads the host session\n * list (`blank` flag and cwd — window-independent); the badge reads the\n * worktree declaration store (set by start-in-worktree-mode) plus the session\n * cwd. Note: framework session standard props (useSession / useInput) are NOT\n * injected into slot components in the current shell, so nothing depends on\n * them.\n *\n * Built by tsdown into the __ModuleLoader__ factory bundle at\n * client/client.js; the only externals are the loader module table's react\n * entries.\n */\nimport { createElement as h } from 'react'\n// dsh 0.1.2 removed `@deepseek-ai/dsh-client-runtime`; the browser faces now\n// live on the API-controller/client packages (type-only imports — erased from\n// the tsdown bundle, so nothing here needs a module-table entry).\nimport type { ISessions, SessionFace } from '@deepseek-ai/dsh-api-session-controller/client'\nimport type { IWorkspaces } from '@deepseek-ai/dsh-api-workspace-controller/client'\nimport type { SessionId } from '@deepseek-ai/dsh-api-remotes/client'\nimport { en, zh } from './locales.ts'\nimport { WorktreeBadge } from './WorktreeBadge.tsx'\nimport { WorktreePanel } from './WorktreePanel.tsx'\nimport { createWorktreeStore } from './worktreeStore.ts'\nimport { createPrefsStore, SETTINGS_NS } from './worktreePrefs.ts'\nimport type { SettingsScopeBinder } from './worktreePrefs.ts'\nimport { WorktreeSettingsCard } from './WorktreeSettingsCard.tsx'\n\nconst NS = 'dsh-task-worktree'\n\n/** The subset of the slots service this plugin touches (structural typing keeps\n * this external package free of monorepo-internal type dependencies). */\ninterface SlotsService {\n inject(slot: string, register: () => unknown): void\n register(meta: Record, component: () => unknown): unknown\n}\n\n/** The subset of the locale service this plugin touches. */\ninterface LocaleService {\n register(namespace: string, dicts: { zh: Record; en: Record }): unknown\n bind(namespace: string): (key: string) => string\n}\n\n/** The client cordis context shape this plugin relies on. */\ninterface WorktreeClientContext {\n effect(callback: () => unknown, label?: string): void\n locale: LocaleService\n slots: SlotsService\n sessions: ISessions\n workspaces: IWorkspaces\n /** Nested service injection (used to stay mounted on hosts without settings). */\n inject(services: string[], callback: (scoped: WorktreeClientContext & { settingsScope: SettingsScopeBinder }) => void): void\n}\n\nexport const name = 'dsh-task-worktree'\nexport const inject = ['slots', 'locale', 'sessions', 'workspaces']\n\nexport function apply(ctx: WorktreeClientContext): void {\n ctx.effect(() => ctx.locale.register(NS, { zh, en }), `${NS}: dictionaries`)\n\n const t = (key: string): string => ctx.locale.bind(NS)(key)\n\n /** Reactive store for worktree-mode declarations. */\n const store = createWorktreeStore()\n\n /** Durable preferences: default mode for new conversations + last-choice memory. */\n const prefs = createPrefsStore()\n\n // The settings card and the scope that feeds it are registered through a\n // NESTED inject: naming `settingsScope` in the module-level `inject` would\n // keep this whole plugin unmounted on a host without the settings domain,\n // losing the composer selector to gain a card such a host cannot render.\n ctx.inject(['settingsScope'], (scoped) => {\n scoped.effect(() => prefs.bind(scoped.settingsScope), `${NS}: settings scope`)\n scoped.slots.inject('settings.plugin.item', () => scoped.slots.register({\n name: 'settings.plugin.item',\n // Keyed by the SETTINGS NAMESPACE: the Plugins page dispatches one card\n // per namespace the host serves, so this must match lib/index.js.\n key: SETTINGS_NS,\n locale: NS,\n }, () => h(WorktreeSettingsCard, { prefs, t })))\n })\n\n /** Resolve the current session face through the current selection id. */\n const currentSession = (): SessionFace | undefined => {\n const current = ctx.sessions.list.getSnapshot().current\n if (current === undefined) return undefined\n const binding = ctx.sessions.binding(current)\n return binding?.session\n }\n\n /** Resolve the current selection id (the staged conversation). */\n const currentSessionId = (): SessionId | undefined => ctx.sessions.list.getSnapshot().current\n\n /** Resolve the current cwd from the list summary (the outward session face intentionally omits it). */\n const currentCwd = (): string | undefined => {\n const snapshot = ctx.sessions.list.getSnapshot()\n return snapshot.current !== undefined ? snapshot.byId[snapshot.current]?.cwd : undefined\n }\n\n /** Whether the staged session is still blank (host-computed empty-log bit). */\n const currentBlank = (): boolean => {\n const snapshot = ctx.sessions.list.getSnapshot()\n return snapshot.current !== undefined && snapshot.byId[snapshot.current]?.blank === true\n }\n\n /** Open the local workspace that owns the current worktree checkout. */\n const openLocalWorkspace = async (): Promise => {\n const cwd = currentCwd()\n if (typeof cwd !== 'string' || cwd === '') {\n throw new Error('无法确定当前工作区路径')\n }\n const marker = /[\\\\/]\\.dsh-worktrees[\\\\/]worktree[\\\\/]/u.exec(cwd)\n const localPath = marker !== null ? cwd.slice(0, marker.index) : cwd\n // dsh 0.1.7: client-owned current-session selection moved to the view\n // owners; `ISessions.open` is gone. The capability keeps its guarantees:\n // the host registers (or adopts) the workspace and catalogues a session\n // inside it — the new session then appears in the session list.\n const workspace = await ctx.workspaces.create({ path: localPath })\n await ctx.sessions.create({ workspaceId: workspace.workspaceId })\n }\n\n /**\n * Arm this conversation for worktree mode: the host injects the creation\n * instruction with the NEXT genuine user message (no separate prompt, no\n * workspace registration). Name from the caller when given, otherwise the\n * model proposes one. On success the session is declared worktree-mode in\n * the store (the badge switches on immediately).\n */\n const armWorktreeMode = async (rawName: string | undefined): Promise => {\n const sessionId = currentSessionId()\n const session = currentSession()\n if (session === undefined || sessionId === undefined) throw new Error('当前没有可注入的对话')\n // Branch convention: every managed branch starts with \"worktree/\".\n const trimmed = rawName?.trim() ?? ''\n const name = trimmed === '' ? undefined : (trimmed.startsWith('worktree/') ? trimmed : `worktree/${trimmed}`)\n const line = name !== undefined ? `/worktree mode-on ${name}` : '/worktree mode-on'\n const result = await session.command(line)\n if (!result.ok || result.value.matched !== true) throw new Error('指令未执行成功')\n store.declare(sessionId, name)\n }\n\n /** Disarm worktree mode for the current conversation. */\n const disarmWorktreeMode = async (): Promise => {\n const sessionId = currentSessionId()\n const session = currentSession()\n if (session === undefined || sessionId === undefined) throw new Error('当前没有可注入的对话')\n const result = await session.command('/worktree mode-off')\n if (!result.ok || result.value.matched !== true) throw new Error('指令未执行成功')\n store.clear(sessionId)\n }\n\n // ── Slots ──────────────────────────────────────────────────────────────\n ctx.slots.inject('conversation.input.dock', () => ctx.slots.register({\n name: 'conversation.input.dock',\n id: 'worktree',\n order: 10,\n locale: NS,\n }, () => h(WorktreePanel, {\n currentSession,\n currentCwd,\n currentBlank,\n openLocalWorkspace,\n armWorktreeMode,\n disarmWorktreeMode,\n store,\n prefs,\n sessionIdOf: currentSessionId,\n t,\n })))\n\n ctx.slots.inject('conversation.session.header.actions', () => ctx.slots.register({\n name: 'conversation.session.header.actions',\n id: 'worktree-badge',\n // Negative order: static session context precedes interactive actions.\n order: -30,\n locale: NS,\n }, () => h(WorktreeBadge, {\n store,\n sessionIdOf: currentSessionId,\n currentCwd,\n t,\n })))\n}"],"mappings":";;;;;;;;;;;AAKA,MAAa,KAAK;CAChB,YAAY;CACZ,WAAW;CACX,cAAc;CACd,WAAW;CACX,MAAM;CACN,cAAc;CACd,eAAe;CACf,gBAAgB;CAChB,sBAAsB;CACtB,mBAAmB;CACnB,kBAAkB;CAClB,qBAAqB;CACrB,0BAA0B;CAC1B,6BAA6B;CAC7B,kBAAkB;CAClB,sBAAsB;CACtB,uBAAuB;CACvB,qBAAqB;CACrB,oBAAoB;CACrB;AAED,MAAa,KAAK;CAChB,YAAY;CACZ,WAAW;CACX,cAAc;CACd,WAAW;CACX,MAAM;CACN,cAAc;CACd,eAAe;CACf,gBAAgB;CAChB,sBAAsB;CACtB,mBAAmB;CACnB,kBAAkB;CAClB,qBAAqB;CACrB,0BAA0B;CAC1B,6BAA6B;CAC7B,kBAAkB;CAClB,sBAAsB;CACtB,uBAAuB;CACvB,qBAAqB;CACrB,oBAAoB;CACrB;;;;;;;;;;;;;;;;;ACjCD,MAAMA,kBAAgB;;;;;AAMtB,SAAgB,kBAAkB,KAA6C;AAC7E,KAAI,OAAO,QAAQ,YAAY,QAAQ,GAAI,QAAO;CAClD,MAAM,QAAQA,gBAAc,KAAK,IAAI;AACrC,QAAO,UAAU,OAAO,SAAY,MAAM,GAAG,QAAQ,YAAY,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACgBtE,SAAgB,cAAc,OAAsC;CAClE,MAAM,EAAE,YAAY,OAAO,MAAM;AACjC,i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AAO,iCAAiC,IAAI,MAAM,SAAS;EACnE,MAAM;EACN,IAAI;EACJ,OAAO;EACP,QAAQ;EACT,iCAAU,eAAe;EACxB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,aAAa;EACb;EACD,CAAC,CAAC,CAAC;AAEJ,KAAI,MAAM,OAAO,6CAA6C,IAAI,MAAM,SAAS;EAC/E,MAAM;EACN,IAAI;EAEJ,OAAO;EACP,QAAQ;EACT,iCAAU,eAAe;EACxB;EACA,aAAa;EACb;EACA;EACD,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/index.d.ts b/lib/index.d.ts index 8680b57..856916b 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -8,6 +8,10 @@ export const name: 'task-worktree' /** Services this plugin declares through cordis fiber injection. */ export const inject: ('tools' | 'commands' | 'subprocess')[] +/** Settings namespace owned by this plugin (the browser card keys to it). */ +export const SETTINGS_NS: 'task-worktree' +/** Schemastery schema of the plugin settings namespace. */ +export const WorktreeSettings: (value?: unknown) => { defaultMode: 'local' | 'worktree'; rememberLastChoice: boolean } /** Mount the plugin. */ export declare function apply(ctx: any, config?: { dirName?: string }): void \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index 5192fae..41f6392 100644 --- a/lib/index.js +++ b/lib/index.js @@ -11,11 +11,17 @@ * - human command: /worktree create|list|status|finish|bring-back|remove|prune; * - worktree mode: `/worktree mode-on [name]` arms a session; the first * genuine user message then carries an injected instruction (a plugin - * `instructions` context block) so the model creates the worktree inline. + * `instructions` context block) so the model creates the worktree inline; + * - settings namespace `task-worktree`: the default mode for NEW conversations + * plus whether the composer selector remembers the last choice. A + * conversation that starts while the default is worktree mode arms itself on + * its first genuine user message — unless the user explicitly picked local + * mode for that conversation. * * @module dsh-task-worktree */ import { createUserMessage } from '@deepseek-ai/dsh-llm' +import z from '@deepseek-ai/schemastery' import { registerWorktreeCommand } from './commands.js' import { createSubprocessRunner } from './git.js' import { createWorktreeManager } from './manager.js' @@ -27,6 +33,29 @@ export const inject = ['tools', 'commands', 'subprocess'] const DEFAULT_DIR_NAME = '.dsh-worktrees' const PLUGIN_ID = 'dsh-task-worktree' +/** Settings namespace owned by this plugin; the browser settings card keys to it. */ +export const SETTINGS_NS = 'task-worktree' + +/** + * Runtime-editable settings of this plugin. + * + * - `defaultMode`: the mode a blank conversation starts in. `worktree` makes + * the host inject the creation instruction with the first genuine user + * message, so a new task is isolated without touching the dock selector. + * - `rememberLastChoice`: the composer selector writes the mode the user picks + * back into `defaultMode`, so the next conversation starts the same way. + * Off by default, so an untouched installation keeps behaving exactly as it + * did before this setting existed: local mode, and a pick in the selector + * applies to its own conversation only. + */ +export const WorktreeSettings = z.object({ + defaultMode: z.union([z.const('local'), z.const('worktree')]).default('local'), + rememberLastChoice: z.boolean().default(false), +}) + +/** Composed fallback, used until (and unless) a settings provider resolves. */ +const SETTINGS_DEFAULTS = Object.freeze({ defaultMode: 'local', rememberLastChoice: false }) + /** The instruction injected with the first user message of an armed session. */ function buildModeInstruction(name) { const named = name !== undefined && name !== '' @@ -46,31 +75,79 @@ export function apply(ctx, config = {}) { const manager = createWorktreeManager({ git: runner, dirName }) registerTools(ctx, manager) + // ── Settings: the new-conversation default mode, live-editable ── + // Registered through a nested inject: on a host with no settings service the + // callback never runs and the composed defaults above stand, exactly as the + // profile configured them. + let readSettings = () => SETTINGS_DEFAULTS + ctx.inject(['settings'], (scoped) => { + const scope = scoped.settings.register(SETTINGS_NS, WorktreeSettings, { base: { ...SETTINGS_DEFAULTS } }) + readSettings = () => scope.get() + scoped.effect(() => () => { + readSettings = () => SETTINGS_DEFAULTS + }) + }) + // ── Worktree mode: armed sessions inject an instruction with their first user message ── + /** Sessions armed by an explicit mode-on, with the optional branch name. */ const armed = new Map() + /** Sessions whose mode decision is already made (armed, or taken from the default). */ + const decided = new Set() + /** Sessions the user explicitly put in local mode: the default must not re-arm them. */ + const suppressed = new Set() + /** Sessions that started empty in this process (auto-default candidates). */ + const fresh = new Set() const actions = { arm(sessionId, name) { + suppressed.delete(sessionId) armed.set(sessionId, { name: name?.trim() || undefined }) }, disarm(sessionId) { armed.delete(sessionId) + suppressed.add(sessionId) }, } - ctx.on('agent/inbox/inserted', ({ agent, message }) => { - const pending = armed.get(agent.id) - if (pending === undefined) return - // Only a genuine human prompt rides the injection; never re-arm on - // producer-supplied context or tool results. - if (message?.source?.kind !== 'user') return - const instruction = buildModeInstruction(pending.name) + const injectInstruction = (agent, name) => { agent.inject(createUserMessage({ - content: [{ type: 'text', text: instruction }], + content: [{ type: 'text', text: buildModeInstruction(name) }], source: { kind: 'plugin', plugin: PLUGIN_ID, form: 'instructions' }, })) - armed.delete(agent.id) + } + ctx.on('agent/session-start', ({ agent, source }) => { + // Only a conversation that starts empty can be auto-armed; a resumed one + // already has a history and a mode of its own. + if (source !== 'startup' && source !== 'clear') return + if (!decided.has(agent.id)) fresh.add(agent.id) + }) + ctx.on('agent/inbox/inserted', ({ agent, message }) => { + // Only a genuine human prompt rides an injection; never re-arm on + // producer-supplied context or tool results. + if (message?.source?.kind !== 'user') return + const pending = armed.get(agent.id) + if (pending !== undefined) { + armed.delete(agent.id) + decided.add(agent.id) + fresh.delete(agent.id) + injectInstruction(agent, pending.name) + return + } + if (decided.has(agent.id)) return + // The first genuine prompt of a conversation with no history: the + // configured default decides. `session.seq === 0` is the fallback for an + // agent whose session-start beacon has not been observed yet. + const untouched = fresh.has(agent.id) || agent.session?.seq === 0 + if (!untouched) return + decided.add(agent.id) + fresh.delete(agent.id) + if (suppressed.has(agent.id)) return + if (readSettings().defaultMode !== 'worktree') return + injectInstruction(agent, undefined) }) ctx.on('agent/disposed', ({ agent }) => { armed.delete(agent.id) + decided.delete(agent.id) + suppressed.delete(agent.id) + fresh.delete(agent.id) }) registerWorktreeCommand(ctx, manager, actions) diff --git a/package-lock.json b/package-lock.json index c9870a5..e50bc36 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,23 +1,27 @@ { "name": "dsh-task-worktree", - "version": "0.4.6", + "version": "0.5.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "dsh-task-worktree", - "version": "0.4.6", + "version": "0.5.0", "license": "MIT", "devDependencies": { + "@deepseek-ai/cordis": "~4.0.6-alpha.1", "@deepseek-ai/dsh-api-remotes": "0.2.2-alpha.2", "@deepseek-ai/dsh-api-session-controller": "0.2.2-alpha.2", "@deepseek-ai/dsh-api-workspace-controller": "0.2.2-alpha.2", "@deepseek-ai/dsh-client-locale": "0.2.2-alpha.2", "@deepseek-ai/dsh-client-ui-conversation": "0.2.2-alpha.2", "@deepseek-ai/dsh-client-ui-primitives": "0.2.2-alpha.2", + "@deepseek-ai/dsh-llm": "0.2.2-alpha.2", + "@deepseek-ai/dsh-scope": "^0.2.2-alpha.2", "@deepseek-ai/dsh-session": "0.2.2-alpha.2", "@deepseek-ai/dsh-subprocess": "0.2.2-alpha.2", "@deepseek-ai/dsh-tools": "0.2.2-alpha.2", + "@deepseek-ai/schemastery": "~3.18.6-alpha.1", "@types/react": "~18.3.1", "lightningcss": "^1.25.0", "react": "^18.2.0", @@ -31,8 +35,18 @@ "@deepseek-ai/cordis": "~4.0.5 || ~4.0.6-alpha.1", "@deepseek-ai/dsh-llm": "^0.2.1-rc.4 || ^0.2.2-alpha.2", "@deepseek-ai/dsh-session": "^0.2.1-rc.4 || ^0.2.2-alpha.2", + "@deepseek-ai/dsh-settings": "^0.2.1-rc.4 || ^0.2.2-alpha.2", "@deepseek-ai/dsh-subprocess": "^0.2.1-rc.4 || ^0.2.2-alpha.2", - "@deepseek-ai/dsh-tools": "^0.2.1-rc.4 || ^0.2.2-alpha.2" + "@deepseek-ai/dsh-tools": "^0.2.1-rc.4 || ^0.2.2-alpha.2", + "@deepseek-ai/schemastery": "^3.18.0 || ~3.18.6-alpha.1" + }, + "peerDependenciesMeta": { + "@deepseek-ai/dsh-settings": { + "optional": true + }, + "@deepseek-ai/schemastery": { + "optional": true + } } }, "node_modules/@babel/generator": { @@ -102,6 +116,39 @@ "node": ">=6.9.0" } }, + "node_modules/@deepseek-ai/cordis": { + "version": "4.0.6-alpha.1", + "resolved": "https://registry.npmjs.org/@deepseek-ai/cordis/-/cordis-4.0.6-alpha.1.tgz", + "integrity": "sha512-GgUFYPkAERAhjq/H7ASM9G2tWu07bY6XOD/q16jUXqsj/arawh0EIZKB+PjTXLjC7vgG3XptSvJ/8dZkkIWsfQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@deepseek-ai/cosmokit": "~1.8.7-alpha.1", + "@standard-schema/spec": "^1.1.0" + }, + "bin": { + "cordis": "bin.js" + }, + "peerDependencies": { + "@deepseek-ai/cordis-plugin-include": "~1.0.11-alpha.1", + "@deepseek-ai/cordis-plugin-loader": "~1.0.7-alpha.1" + }, + "peerDependenciesMeta": { + "@deepseek-ai/cordis-plugin-include": { + "optional": true + }, + "@deepseek-ai/cordis-plugin-loader": { + "optional": true + } + } + }, + "node_modules/@deepseek-ai/cosmokit": { + "version": "1.8.7-alpha.1", + "resolved": "https://registry.npmjs.org/@deepseek-ai/cosmokit/-/cosmokit-1.8.7-alpha.1.tgz", + "integrity": "sha512-+R+9sx+SJbkyeidV3s+fvgsqCMZAfx2Z00YCQNhc5RsTen1SnvIYWM8neQah/1SxjlsXRo9jxX9U58Wk68JjvA==", + "dev": true, + "license": "MIT" + }, "node_modules/@deepseek-ai/dsh-api-remotes": { "version": "0.2.2-alpha.2", "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-api-remotes/-/dsh-api-remotes-0.2.2-alpha.2.tgz", @@ -127,16 +174,6 @@ "@deepseek-ai/cordis": "~4.0.6-alpha.1" } }, - "node_modules/@deepseek-ai/dsh-api-remotes/node_modules/@deepseek-ai/dsh-util-values": { - "version": "0.2.2-alpha.2", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-util-values/-/dsh-util-values-0.2.2-alpha.2.tgz", - "integrity": "sha512-g5Qrz9cEENcnNEzXjiR+saN0aV4G/8w3FP57wlew+SwZPm3bW5K2cj3iA4Rjg5BS3FGZvnqS95RMOPrxNdulig==", - "dev": true, - "license": "MIT", - "peerDependencies": { - "@deepseek-ai/cordis": "~4.0.6-alpha.1" - } - }, "node_modules/@deepseek-ai/dsh-api-session-controller": { "version": "0.2.2-alpha.2", "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-api-session-controller/-/dsh-api-session-controller-0.2.2-alpha.2.tgz", @@ -196,23 +233,6 @@ } } }, - "node_modules/@deepseek-ai/dsh-api-session-controller/node_modules/@deepseek-ai/cosmokit": { - "version": "1.8.7-alpha.1", - "resolved": "https://registry.npmjs.org/@deepseek-ai/cosmokit/-/cosmokit-1.8.7-alpha.1.tgz", - "integrity": "sha512-+R+9sx+SJbkyeidV3s+fvgsqCMZAfx2Z00YCQNhc5RsTen1SnvIYWM8neQah/1SxjlsXRo9jxX9U58Wk68JjvA==", - "dev": true, - "license": "MIT" - }, - "node_modules/@deepseek-ai/dsh-api-session-controller/node_modules/@deepseek-ai/dsh-brand": { - "version": "0.2.2-alpha.2", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-brand/-/dsh-brand-0.2.2-alpha.2.tgz", - "integrity": "sha512-VFHjxHZbfQRjaQHC9fO6oSeCZcHQeA54nThij/WB2Q6Qv8VBdJkitbVzYNLr54gmVDxQXfdK/yYJzHAQade6lg==", - "dev": true, - "license": "MIT", - "peerDependencies": { - "@deepseek-ai/cordis": "~4.0.6-alpha.1" - } - }, "node_modules/@deepseek-ai/dsh-api-session-controller/node_modules/@deepseek-ai/dsh-deque": { "version": "0.2.2-alpha.2", "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-deque/-/dsh-deque-0.2.2-alpha.2.tgz", @@ -223,27 +243,6 @@ "@deepseek-ai/cordis": "~4.0.6-alpha.1" } }, - "node_modules/@deepseek-ai/dsh-api-session-controller/node_modules/@deepseek-ai/dsh-timeout": { - "version": "0.2.2-alpha.2", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-timeout/-/dsh-timeout-0.2.2-alpha.2.tgz", - "integrity": "sha512-Rn5+DsqeUpytiSIOiN8Rdw6vAvMBG8CZTG8W2l0zXstHt0w0UiFQxv6UI21uFHjWL2fUVPvP6KLamv+nE72nmw==", - "dev": true, - "license": "MIT", - "peerDependencies": { - "@deepseek-ai/cordis": "~4.0.6-alpha.1" - } - }, - "node_modules/@deepseek-ai/dsh-api-session-controller/node_modules/@deepseek-ai/schemastery": { - "version": "3.18.6-alpha.1", - "resolved": "https://registry.npmjs.org/@deepseek-ai/schemastery/-/schemastery-3.18.6-alpha.1.tgz", - "integrity": "sha512-ID5DKpWa0BnrcNdZ3ofWkhOoRLQ3MsFr1FdRVHBiALeE9egaCm4QatuCvQK0Cd/haRBcEvefacz2JEYYMFAEnw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@deepseek-ai/cosmokit": "~1.8.7-alpha.1", - "@standard-schema/spec": "^1.1.0" - } - }, "node_modules/@deepseek-ai/dsh-api-workspace-controller": { "version": "0.2.2-alpha.2", "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-api-workspace-controller/-/dsh-api-workspace-controller-0.2.2-alpha.2.tgz", @@ -267,13 +266,6 @@ "@deepseek-ai/dsh-workspace": "0.2.2-alpha.2" } }, - "node_modules/@deepseek-ai/dsh-api-workspace-controller/node_modules/@deepseek-ai/cosmokit": { - "version": "1.8.7-alpha.1", - "resolved": "https://registry.npmjs.org/@deepseek-ai/cosmokit/-/cosmokit-1.8.7-alpha.1.tgz", - "integrity": "sha512-+R+9sx+SJbkyeidV3s+fvgsqCMZAfx2Z00YCQNhc5RsTen1SnvIYWM8neQah/1SxjlsXRo9jxX9U58Wk68JjvA==", - "dev": true, - "license": "MIT" - }, "node_modules/@deepseek-ai/dsh-api-workspace-controller/node_modules/@deepseek-ai/dsh-deque": { "version": "0.2.2-alpha.2", "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-deque/-/dsh-deque-0.2.2-alpha.2.tgz", @@ -284,15 +276,14 @@ "@deepseek-ai/cordis": "~4.0.6-alpha.1" } }, - "node_modules/@deepseek-ai/dsh-api-workspace-controller/node_modules/@deepseek-ai/schemastery": { - "version": "3.18.6-alpha.1", - "resolved": "https://registry.npmjs.org/@deepseek-ai/schemastery/-/schemastery-3.18.6-alpha.1.tgz", - "integrity": "sha512-ID5DKpWa0BnrcNdZ3ofWkhOoRLQ3MsFr1FdRVHBiALeE9egaCm4QatuCvQK0Cd/haRBcEvefacz2JEYYMFAEnw==", + "node_modules/@deepseek-ai/dsh-brand": { + "version": "0.2.2-alpha.2", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-brand/-/dsh-brand-0.2.2-alpha.2.tgz", + "integrity": "sha512-VFHjxHZbfQRjaQHC9fO6oSeCZcHQeA54nThij/WB2Q6Qv8VBdJkitbVzYNLr54gmVDxQXfdK/yYJzHAQade6lg==", "dev": true, "license": "MIT", - "dependencies": { - "@deepseek-ai/cosmokit": "~1.8.7-alpha.1", - "@standard-schema/spec": "^1.1.0" + "peerDependencies": { + "@deepseek-ai/cordis": "~4.0.6-alpha.1" } }, "node_modules/@deepseek-ai/dsh-client-locale": { @@ -308,24 +299,6 @@ "@deepseek-ai/cordis": "~4.0.6-alpha.1" } }, - "node_modules/@deepseek-ai/dsh-client-locale/node_modules/@deepseek-ai/cosmokit": { - "version": "1.8.7-alpha.1", - "resolved": "https://registry.npmjs.org/@deepseek-ai/cosmokit/-/cosmokit-1.8.7-alpha.1.tgz", - "integrity": "sha512-+R+9sx+SJbkyeidV3s+fvgsqCMZAfx2Z00YCQNhc5RsTen1SnvIYWM8neQah/1SxjlsXRo9jxX9U58Wk68JjvA==", - "dev": true, - "license": "MIT" - }, - "node_modules/@deepseek-ai/dsh-client-locale/node_modules/@deepseek-ai/schemastery": { - "version": "3.18.6-alpha.1", - "resolved": "https://registry.npmjs.org/@deepseek-ai/schemastery/-/schemastery-3.18.6-alpha.1.tgz", - "integrity": "sha512-ID5DKpWa0BnrcNdZ3ofWkhOoRLQ3MsFr1FdRVHBiALeE9egaCm4QatuCvQK0Cd/haRBcEvefacz2JEYYMFAEnw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@deepseek-ai/cosmokit": "~1.8.7-alpha.1", - "@standard-schema/spec": "^1.1.0" - } - }, "node_modules/@deepseek-ai/dsh-client-ui-conversation": { "version": "0.2.2-alpha.2", "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-client-ui-conversation/-/dsh-client-ui-conversation-0.2.2-alpha.2.tgz", @@ -339,24 +312,6 @@ "@deepseek-ai/cordis": "~4.0.6-alpha.1" } }, - "node_modules/@deepseek-ai/dsh-client-ui-conversation/node_modules/@deepseek-ai/cosmokit": { - "version": "1.8.7-alpha.1", - "resolved": "https://registry.npmjs.org/@deepseek-ai/cosmokit/-/cosmokit-1.8.7-alpha.1.tgz", - "integrity": "sha512-+R+9sx+SJbkyeidV3s+fvgsqCMZAfx2Z00YCQNhc5RsTen1SnvIYWM8neQah/1SxjlsXRo9jxX9U58Wk68JjvA==", - "dev": true, - "license": "MIT" - }, - "node_modules/@deepseek-ai/dsh-client-ui-conversation/node_modules/@deepseek-ai/schemastery": { - "version": "3.18.6-alpha.1", - "resolved": "https://registry.npmjs.org/@deepseek-ai/schemastery/-/schemastery-3.18.6-alpha.1.tgz", - "integrity": "sha512-ID5DKpWa0BnrcNdZ3ofWkhOoRLQ3MsFr1FdRVHBiALeE9egaCm4QatuCvQK0Cd/haRBcEvefacz2JEYYMFAEnw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@deepseek-ai/cosmokit": "~1.8.7-alpha.1", - "@standard-schema/spec": "^1.1.0" - } - }, "node_modules/@deepseek-ai/dsh-client-ui-primitives": { "version": "0.2.2-alpha.2", "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-client-ui-primitives/-/dsh-client-ui-primitives-0.2.2-alpha.2.tgz", @@ -367,50 +322,7 @@ "@deepseek-ai/cordis": "~4.0.6-alpha.1" } }, - "node_modules/@deepseek-ai/dsh-native-command": { - "version": "0.2.2-alpha.2", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-native-command/-/dsh-native-command-0.2.2-alpha.2.tgz", - "integrity": "sha512-7jHBQEZtHZ/IpePxlA2KQo9pQyi861H7XbSywJRO6JQ8IOqMZmOaDSHt+8cdCXk/GKDxACz7k+IHQAgS0iklrw==", - "dev": true, - "license": "MIT", - "peerDependencies": { - "@deepseek-ai/cordis": "~4.0.6-alpha.1" - } - }, - "node_modules/@deepseek-ai/dsh-session": { - "version": "0.2.2-alpha.2", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-session/-/dsh-session-0.2.2-alpha.2.tgz", - "integrity": "sha512-EvZBQIcxQCdz1gdUCgbUJMqTXSGQlnQpCYnogkNHyiuya7JWL8ye8ieqLBHRtqWarjSWxJWFtfHuun8EL81+jA==", - "dev": true, - "license": "MIT", - "dependencies": { - "@deepseek-ai/dsh-brand": "0.2.2-alpha.2", - "@deepseek-ai/dsh-llm": "0.2.2-alpha.2", - "@deepseek-ai/dsh-util-values": "0.2.2-alpha.2" - }, - "peerDependencies": { - "@deepseek-ai/cordis": "~4.0.6-alpha.1", - "@deepseek-ai/dsh-scope": "0.2.2-alpha.2" - } - }, - "node_modules/@deepseek-ai/dsh-session/node_modules/@deepseek-ai/cosmokit": { - "version": "1.8.7-alpha.1", - "resolved": "https://registry.npmjs.org/@deepseek-ai/cosmokit/-/cosmokit-1.8.7-alpha.1.tgz", - "integrity": "sha512-+R+9sx+SJbkyeidV3s+fvgsqCMZAfx2Z00YCQNhc5RsTen1SnvIYWM8neQah/1SxjlsXRo9jxX9U58Wk68JjvA==", - "dev": true, - "license": "MIT" - }, - "node_modules/@deepseek-ai/dsh-session/node_modules/@deepseek-ai/dsh-brand": { - "version": "0.2.2-alpha.2", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-brand/-/dsh-brand-0.2.2-alpha.2.tgz", - "integrity": "sha512-VFHjxHZbfQRjaQHC9fO6oSeCZcHQeA54nThij/WB2Q6Qv8VBdJkitbVzYNLr54gmVDxQXfdK/yYJzHAQade6lg==", - "dev": true, - "license": "MIT", - "peerDependencies": { - "@deepseek-ai/cordis": "~4.0.6-alpha.1" - } - }, - "node_modules/@deepseek-ai/dsh-session/node_modules/@deepseek-ai/dsh-llm": { + "node_modules/@deepseek-ai/dsh-llm": { "version": "0.2.2-alpha.2", "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-llm/-/dsh-llm-0.2.2-alpha.2.tgz", "integrity": "sha512-AwlZx8DW4e0xg/xB/YzvORSHKKQWMyhJgFXT4J9+5QV3x3BI2M35kHxRD4LoBQ2wRO1tImgaCgA4tH1haMw6IQ==", @@ -429,70 +341,61 @@ "@deepseek-ai/cordis": "~4.0.6-alpha.1" } }, - "node_modules/@deepseek-ai/dsh-session/node_modules/@deepseek-ai/dsh-timeout": { + "node_modules/@deepseek-ai/dsh-native-command": { "version": "0.2.2-alpha.2", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-timeout/-/dsh-timeout-0.2.2-alpha.2.tgz", - "integrity": "sha512-Rn5+DsqeUpytiSIOiN8Rdw6vAvMBG8CZTG8W2l0zXstHt0w0UiFQxv6UI21uFHjWL2fUVPvP6KLamv+nE72nmw==", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-native-command/-/dsh-native-command-0.2.2-alpha.2.tgz", + "integrity": "sha512-7jHBQEZtHZ/IpePxlA2KQo9pQyi861H7XbSywJRO6JQ8IOqMZmOaDSHt+8cdCXk/GKDxACz7k+IHQAgS0iklrw==", "dev": true, "license": "MIT", "peerDependencies": { "@deepseek-ai/cordis": "~4.0.6-alpha.1" } }, - "node_modules/@deepseek-ai/dsh-session/node_modules/@deepseek-ai/dsh-typert-protocol": { + "node_modules/@deepseek-ai/dsh-scope": { "version": "0.2.2-alpha.2", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-typert-protocol/-/dsh-typert-protocol-0.2.2-alpha.2.tgz", - "integrity": "sha512-jFA+ub/v6jBwhmrdZtcVHKV6taJ731O2fzC9PXdIVOnOQ9bYds1kIdYsbhgBL7YFd40xWwV/LlJnE5L52v0jFw==", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-scope/-/dsh-scope-0.2.2-alpha.2.tgz", + "integrity": "sha512-BiniiKjbLL7bRzzqCcq2ldVqi6ZnFKOTWhCvooyl/r2CDhstZfV6x2Z1hxSe4z/Gi5Vk7/sRjpPrO30bGBEYfw==", "dev": true, "license": "MIT", - "dependencies": { - "@deepseek-ai/dsh-brand": "0.2.2-alpha.2", - "zod": "^4.4.3" - }, "peerDependencies": { "@deepseek-ai/cordis": "~4.0.6-alpha.1" } }, - "node_modules/@deepseek-ai/dsh-session/node_modules/@deepseek-ai/dsh-util-crypto": { + "node_modules/@deepseek-ai/dsh-session": { "version": "0.2.2-alpha.2", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-util-crypto/-/dsh-util-crypto-0.2.2-alpha.2.tgz", - "integrity": "sha512-Hmx7FvW7ok8iSEuaw4kQK/RWsHZnL6MFeyiOin46hfV9imA+pfZFT48/wrkUWwBzuuvpw0O1MwiLD3shqtb6lA==", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-session/-/dsh-session-0.2.2-alpha.2.tgz", + "integrity": "sha512-EvZBQIcxQCdz1gdUCgbUJMqTXSGQlnQpCYnogkNHyiuya7JWL8ye8ieqLBHRtqWarjSWxJWFtfHuun8EL81+jA==", "dev": true, "license": "MIT", + "dependencies": { + "@deepseek-ai/dsh-brand": "0.2.2-alpha.2", + "@deepseek-ai/dsh-llm": "0.2.2-alpha.2", + "@deepseek-ai/dsh-util-values": "0.2.2-alpha.2" + }, "peerDependencies": { - "@deepseek-ai/cordis": "~4.0.6-alpha.1" + "@deepseek-ai/cordis": "~4.0.6-alpha.1", + "@deepseek-ai/dsh-scope": "0.2.2-alpha.2" } }, - "node_modules/@deepseek-ai/dsh-session/node_modules/@deepseek-ai/dsh-util-values": { + "node_modules/@deepseek-ai/dsh-subprocess": { "version": "0.2.2-alpha.2", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-util-values/-/dsh-util-values-0.2.2-alpha.2.tgz", - "integrity": "sha512-g5Qrz9cEENcnNEzXjiR+saN0aV4G/8w3FP57wlew+SwZPm3bW5K2cj3iA4Rjg5BS3FGZvnqS95RMOPrxNdulig==", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-subprocess/-/dsh-subprocess-0.2.2-alpha.2.tgz", + "integrity": "sha512-rZHXZaeZWwKz6mFPVeuBL3vDgNrWrVppyBHdFR+CeOSmPvLi0tbjXZctuhWPCSLfn2kLZGFGPnRFimMdsjVWBQ==", "dev": true, "license": "MIT", "peerDependencies": { - "@deepseek-ai/cordis": "~4.0.6-alpha.1" - } - }, - "node_modules/@deepseek-ai/dsh-session/node_modules/@deepseek-ai/schemastery": { - "version": "3.18.6-alpha.1", - "resolved": "https://registry.npmjs.org/@deepseek-ai/schemastery/-/schemastery-3.18.6-alpha.1.tgz", - "integrity": "sha512-ID5DKpWa0BnrcNdZ3ofWkhOoRLQ3MsFr1FdRVHBiALeE9egaCm4QatuCvQK0Cd/haRBcEvefacz2JEYYMFAEnw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@deepseek-ai/cosmokit": "~1.8.7-alpha.1", - "@standard-schema/spec": "^1.1.0" + "@deepseek-ai/cordis": "~4.0.6-alpha.1", + "@deepseek-ai/dsh-http-proxy": "0.2.2-alpha.2" } }, - "node_modules/@deepseek-ai/dsh-subprocess": { + "node_modules/@deepseek-ai/dsh-timeout": { "version": "0.2.2-alpha.2", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-subprocess/-/dsh-subprocess-0.2.2-alpha.2.tgz", - "integrity": "sha512-rZHXZaeZWwKz6mFPVeuBL3vDgNrWrVppyBHdFR+CeOSmPvLi0tbjXZctuhWPCSLfn2kLZGFGPnRFimMdsjVWBQ==", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-timeout/-/dsh-timeout-0.2.2-alpha.2.tgz", + "integrity": "sha512-Rn5+DsqeUpytiSIOiN8Rdw6vAvMBG8CZTG8W2l0zXstHt0w0UiFQxv6UI21uFHjWL2fUVPvP6KLamv+nE72nmw==", "dev": true, "license": "MIT", "peerDependencies": { - "@deepseek-ai/cordis": "~4.0.6-alpha.1", - "@deepseek-ai/dsh-http-proxy": "0.2.2-alpha.2" + "@deepseek-ai/cordis": "~4.0.6-alpha.1" } }, "node_modules/@deepseek-ai/dsh-tools": { @@ -516,24 +419,31 @@ "@deepseek-ai/dsh-user-approval": "0.2.2-alpha.2" } }, - "node_modules/@deepseek-ai/dsh-tools/node_modules/@deepseek-ai/cosmokit": { - "version": "1.8.7-alpha.1", - "resolved": "https://registry.npmjs.org/@deepseek-ai/cosmokit/-/cosmokit-1.8.7-alpha.1.tgz", - "integrity": "sha512-+R+9sx+SJbkyeidV3s+fvgsqCMZAfx2Z00YCQNhc5RsTen1SnvIYWM8neQah/1SxjlsXRo9jxX9U58Wk68JjvA==", + "node_modules/@deepseek-ai/dsh-typert-protocol": { + "version": "0.2.2-alpha.2", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-typert-protocol/-/dsh-typert-protocol-0.2.2-alpha.2.tgz", + "integrity": "sha512-jFA+ub/v6jBwhmrdZtcVHKV6taJ731O2fzC9PXdIVOnOQ9bYds1kIdYsbhgBL7YFd40xWwV/LlJnE5L52v0jFw==", "dev": true, - "license": "MIT" + "license": "MIT", + "dependencies": { + "@deepseek-ai/dsh-brand": "0.2.2-alpha.2", + "zod": "^4.4.3" + }, + "peerDependencies": { + "@deepseek-ai/cordis": "~4.0.6-alpha.1" + } }, - "node_modules/@deepseek-ai/dsh-tools/node_modules/@deepseek-ai/dsh-brand": { + "node_modules/@deepseek-ai/dsh-util-crypto": { "version": "0.2.2-alpha.2", - "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-brand/-/dsh-brand-0.2.2-alpha.2.tgz", - "integrity": "sha512-VFHjxHZbfQRjaQHC9fO6oSeCZcHQeA54nThij/WB2Q6Qv8VBdJkitbVzYNLr54gmVDxQXfdK/yYJzHAQade6lg==", + "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-util-crypto/-/dsh-util-crypto-0.2.2-alpha.2.tgz", + "integrity": "sha512-Hmx7FvW7ok8iSEuaw4kQK/RWsHZnL6MFeyiOin46hfV9imA+pfZFT48/wrkUWwBzuuvpw0O1MwiLD3shqtb6lA==", "dev": true, "license": "MIT", "peerDependencies": { "@deepseek-ai/cordis": "~4.0.6-alpha.1" } }, - "node_modules/@deepseek-ai/dsh-tools/node_modules/@deepseek-ai/dsh-util-values": { + "node_modules/@deepseek-ai/dsh-util-values": { "version": "0.2.2-alpha.2", "resolved": "https://registry.npmjs.org/@deepseek-ai/dsh-util-values/-/dsh-util-values-0.2.2-alpha.2.tgz", "integrity": "sha512-g5Qrz9cEENcnNEzXjiR+saN0aV4G/8w3FP57wlew+SwZPm3bW5K2cj3iA4Rjg5BS3FGZvnqS95RMOPrxNdulig==", @@ -543,7 +453,7 @@ "@deepseek-ai/cordis": "~4.0.6-alpha.1" } }, - "node_modules/@deepseek-ai/dsh-tools/node_modules/@deepseek-ai/schemastery": { + "node_modules/@deepseek-ai/schemastery": { "version": "3.18.6-alpha.1", "resolved": "https://registry.npmjs.org/@deepseek-ai/schemastery/-/schemastery-3.18.6-alpha.1.tgz", "integrity": "sha512-ID5DKpWa0BnrcNdZ3ofWkhOoRLQ3MsFr1FdRVHBiALeE9egaCm4QatuCvQK0Cd/haRBcEvefacz2JEYYMFAEnw==", @@ -628,9 +538,9 @@ } }, "node_modules/@napi-rs/wasm-runtime": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.2.3.tgz", - "integrity": "sha512-UMduMbqO5s5zF2NkNacMT/yK5Y5QiKvWr2+50bzIIxFDwVJ2h49b+oyjaCGPhJxd2/gC2x39EHv/gHVuu36x2Q==", + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.2.6.tgz", + "integrity": "sha512-mRyDmEw9/fCDXCGfL1sbgIw/GUK0PVxRW4YwgPN61F3LQ+fSyoBFarJVzgGyhF6kRzEQZ0FejDqm4WLXSeqQmw==", "dev": true, "license": "MIT", "optional": true, @@ -645,8 +555,8 @@ "url": "https://github.com/sponsors/Brooooooklyn" }, "peerDependencies": { - "@emnapi/core": "^1.7.1 || ^2.0.0-alpha.4", - "@emnapi/runtime": "^1.7.1 || ^2.0.0-alpha.4" + "@emnapi/core": "^1.7.1 || 2.0.0-beta.2", + "@emnapi/runtime": "^1.7.1 || 2.0.0-beta.2" } }, "node_modules/@oxc-project/types": { @@ -960,9 +870,9 @@ "license": "MIT" }, "node_modules/@tybys/wasm-util": { - "version": "0.10.3", - "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.3.tgz", - "integrity": "sha512-F3fo1MYrRJYL3zER0OUOmkutjr1Vp23m7OsSgp7nq4SP6OqX6C/56XFIPAl5bt3zaBRjmW7SGz3u/6LwFpYcOg==", + "version": "0.10.4", + "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.4.tgz", + "integrity": "sha512-W3c4gRigFS0T/Ma4qIYF3GDAc5AQdHb1yL5znJT1Zv1YaD9Kitx656wBjvr19qbiosmZT8lWDM5BEMynUqX65A==", "dev": true, "license": "MIT", "optional": true, diff --git a/package.json b/package.json index 2e09a41..5f55370 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dsh-task-worktree", - "version": "0.4.6", + "version": "0.5.0", "description": "Complete Git worktree support for DeepSeek Harness: task-scoped isolated worktrees with per-repo manifests, workspace registration, bring-back to main, direct commit, and durable state. Reference: Qoder / Codex / Claude Code worktrees.", "author": "Letter2025", "repository": { @@ -52,7 +52,8 @@ "@deepseek-ai/dsh-api-session-controller", "@deepseek-ai/dsh-api-workspace-controller", "@deepseek-ai/dsh-client-locale", - "@deepseek-ai/dsh-client-ui-conversation" + "@deepseek-ai/dsh-client-ui-conversation", + "@deepseek-ai/dsh-client-ui-settings" ], "platform": "web" } @@ -61,27 +62,41 @@ "@deepseek-ai/cordis": "~4.0.5 || ~4.0.6-alpha.1", "@deepseek-ai/dsh-llm": "^0.2.1-rc.4 || ^0.2.2-alpha.2", "@deepseek-ai/dsh-session": "^0.2.1-rc.4 || ^0.2.2-alpha.2", + "@deepseek-ai/dsh-settings": "^0.2.1-rc.4 || ^0.2.2-alpha.2", "@deepseek-ai/dsh-subprocess": "^0.2.1-rc.4 || ^0.2.2-alpha.2", - "@deepseek-ai/dsh-tools": "^0.2.1-rc.4 || ^0.2.2-alpha.2" + "@deepseek-ai/dsh-tools": "^0.2.1-rc.4 || ^0.2.2-alpha.2", + "@deepseek-ai/schemastery": "^3.18.0 || ~3.18.6-alpha.1" + }, + "peerDependenciesMeta": { + "@deepseek-ai/dsh-settings": { + "optional": true + }, + "@deepseek-ai/schemastery": { + "optional": true + } }, "scripts": { "build:client": "tsdown && node scripts/normalize-sourcemap.mjs", "typecheck": "tsc -p tsconfig.client.json --noEmit", - "test": "node test/smoke.mjs", + "test": "node test/smoke.mjs && node test/host.mjs && node test/prefs.mjs", "release:check": "node scripts/publish.mjs --dry-run", "release": "node scripts/publish.mjs", "prepublishOnly": "npm test && npm run build:client" }, "devDependencies": { + "@deepseek-ai/cordis": "~4.0.6-alpha.1", "@deepseek-ai/dsh-api-remotes": "0.2.2-alpha.2", "@deepseek-ai/dsh-api-session-controller": "0.2.2-alpha.2", "@deepseek-ai/dsh-api-workspace-controller": "0.2.2-alpha.2", "@deepseek-ai/dsh-client-locale": "0.2.2-alpha.2", "@deepseek-ai/dsh-client-ui-conversation": "0.2.2-alpha.2", "@deepseek-ai/dsh-client-ui-primitives": "0.2.2-alpha.2", + "@deepseek-ai/dsh-llm": "0.2.2-alpha.2", + "@deepseek-ai/dsh-scope": "^0.2.2-alpha.2", "@deepseek-ai/dsh-session": "0.2.2-alpha.2", "@deepseek-ai/dsh-subprocess": "0.2.2-alpha.2", "@deepseek-ai/dsh-tools": "0.2.2-alpha.2", + "@deepseek-ai/schemastery": "~3.18.6-alpha.1", "@types/react": "~18.3.1", "lightningcss": "^1.25.0", "react": "^18.2.0", diff --git a/src/client/WorktreePanel.tsx b/src/client/WorktreePanel.tsx index 59509a9..dcf4f3e 100644 --- a/src/client/WorktreePanel.tsx +++ b/src/client/WorktreePanel.tsx @@ -5,6 +5,13 @@ * next user message); the revealed strip optionally takes a name (Enter to * apply). Selecting Local mode disarms. Management commands (/worktree * list/status/...) stay available from the composer directly. + * + * On a blank conversation the selector reflects the configured default mode + * (`task-worktree` settings namespace): with the default set to worktree the + * strip is pre-armed and the host injects the creation instruction with the + * first message. Picking a mode is always an explicit answer for THIS + * conversation, and — when "remember the last choice" is on — it also updates + * the default. */ import { useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from 'react' import type { ReactNode } from 'react' @@ -17,6 +24,7 @@ import { IconFolderOpenOutlineRegular, } from '@deepseek-ai/dsh-client-ui-primitives' import type { WorktreeKey } from './locales.ts' +import type { WorktreePrefsStore } from './worktreePrefs.ts' import type { WorktreeStore } from './worktreeStore.ts' import css from './WorktreePanel.module.css' @@ -30,6 +38,8 @@ declare global { mode: string hero: boolean declaredWorktree: boolean + defaultMode: string + explicit: boolean } } } @@ -55,6 +65,8 @@ export interface WorktreePanelProps extends WorktreePanelInjected { t: (key: keyof WorktreeKey) => string /** The declared-worktree store. */ store: WorktreeStore + /** The durable preferences store (default mode + last-choice memory). */ + prefs: WorktreePrefsStore /** Resolve the staged session id. */ sessionIdOf(): string | undefined } @@ -75,13 +87,18 @@ export function WorktreePanel(props: WorktreePanelProps): ReactNode { /** Last raw name actually sent to the host (dedup guard for re-arms). */ const lastAppliedRef = useRef('') useSyncExternalStore(store.subscribe, store.getVersion) + const prefs = useSyncExternalStore(props.prefs.subscribe, props.prefs.getSnapshot) const sessionId = sessionIdOf() const declared = store.stateOf(sessionId) // Blank-hero bit still tracked for layout/debugging; the strip itself is // driven purely by the mode dropdown selection. const hero = props.currentBlank() - // A conversation declared (or runs inside) a worktree shows worktree mode. - const mode = declared.worktree || currentMode(props) === 'worktree' ? 'worktree' : 'local' + // The configured default governs a blank conversation the user has not + // answered for yet; the host arms it when the first message arrives. + const defaultWorktree = hero && !declared.explicit && prefs.defaultMode === 'worktree' + const preArmed = defaultWorktree && !declared.worktree + // A conversation declared (or running inside) a worktree shows worktree mode. + const mode = declared.worktree || defaultWorktree || currentMode(props) === 'worktree' ? 'worktree' : 'local' // Keep the name input in sync with the committed worktree name. useEffect(() => { @@ -98,6 +115,8 @@ export function WorktreePanel(props: WorktreePanelProps): ReactNode { mode, hero, declaredWorktree: declared.worktree, + defaultMode: prefs.defaultMode, + explicit: declared.explicit, } useLayoutEffect(() => { @@ -157,6 +176,11 @@ export function WorktreePanel(props: WorktreePanelProps): ReactNode { window.setTimeout(() => setNotice(null), 1800) } + /** Persist a mode the user picked as the default for future conversations. */ + const remember = (choice: 'local' | 'worktree'): void => { + if (prefs.rememberLastChoice) void props.prefs.setDefaultMode(choice) + } + /** Legacy: leave a session actually running inside a worktree checkout. */ const switchLocal = (): void => { if (busy !== null) return @@ -181,7 +205,10 @@ export function WorktreePanel(props: WorktreePanelProps): ReactNode { /** 本地模式 radio: disarm the declared worktree mode, or leave a legacy checkout session. */ const selectLocal = (): void => { if (busy !== null) return - if (declared.worktree) { + if (declared.worktree || preArmed) { + // An explicit local answer for this conversation: disarm the host, which + // also suppresses the configured default for it. + remember('local') disarmMode() closeMenu() return @@ -252,7 +279,7 @@ export function WorktreePanel(props: WorktreePanelProps): ReactNode { /> - {declared.worktree && ( + {(declared.worktree || preArmed) && (
{t('heroStartLabel')} @@ -289,7 +316,9 @@ export function WorktreePanel(props: WorktreePanelProps): ReactNode { onClick={() => { // Selecting worktree mode arms the host immediately (the // creation instruction rides the next message); the strip - // lets you set a name with Enter. + // lets you set a name with Enter. It is also an explicit + // answer, so it can be remembered as the new default. + remember('worktree') if (!declared.worktree) { void props.armWorktreeMode(undefined).catch(() => showFailure()) } diff --git a/src/client/WorktreeSettings.module.css b/src/client/WorktreeSettings.module.css new file mode 100644 index 0000000..adb1b82 --- /dev/null +++ b/src/client/WorktreeSettings.module.css @@ -0,0 +1,132 @@ +/* Only the chrome the host does not hand out. + The host exports no reusable settings card (`ui-settings-plugins` exports + `apply`/`inject` plus types only) and its own packages already duplicate + these row/card rules across package boundaries, so a card that lives in the + Plugins section is drawn by its owner. Values below are taken from: + - card chrome/header/body: ui-settings-plugins PluginCard.module.css + - field/label/hint: ui-settings-plugins fields.module.css + The control itself is the host `Button` + `Menu` primitives — no styles. */ + +.card { + border: 0.5px solid var(--dsw-alias-border-l4, rgba(255, 255, 255, 0.14)); + background: var(--dsw-alias-bg-layer-3, #26262b); + border-radius: 16px; + list-style: none; + transition: border-color 0.16s, background 0.16s; +} + +.card:hover { + border-color: var(--dsw-alias-label-dimmed, rgba(255, 255, 255, 0.34)); +} + +.cardOpen { + background: var(--dsw-alias-bg-layer-2, #1f1f24); + border-color: var(--dsw-alias-label-dimmed, rgba(255, 255, 255, 0.34)); +} + +.header { + display: flex; + align-items: center; + gap: 12px; + width: 100%; + padding: 14px 16px; + color: inherit; + font: inherit; + text-align: left; + cursor: pointer; + appearance: none; + background: 0 0; + border: 0; + border-radius: 12px; +} + +.header:focus-visible { + outline: 2px solid var(--dsw-alias-brand-primary, #4f73ff); + outline-offset: -2px; +} + +.headText { + display: flex; + flex: 1; + flex-direction: column; + gap: 4px; + min-width: 0; +} + +.name { + color: var(--dsw-alias-label-primary, #fff); + font-size: 15px; + font-weight: 600; + line-height: 1.4; +} + +.description { + color: var(--dsw-alias-label-tertiary, #8a8f98); + font-size: 13px; + line-height: 1.5; +} + +.chevron { + flex: none; + color: var(--dsw-alias-label-tertiary, #8a8f98); + transition: transform 0.16s; +} + +.chevronOpen { + transform: rotate(180deg); +} + +.body { + margin: 0 16px; + padding-bottom: 8px; + border-top: 0.5px solid var(--dsw-alias-border-l2, rgba(255, 255, 255, 0.08)); +} + +.field { + display: flex; + flex-direction: column; + gap: 6px; + padding: 12px 0; +} + +.head { + display: flex; + align-items: center; + gap: 8px; +} + +.label { + flex: 1; + min-width: 0; + color: var(--dsw-alias-label-primary, #fff); + font-size: 13px; + font-weight: 500; + line-height: 1.5; +} + +.controlIcon { + flex: none; +} + +.hint { + margin: 0; + color: var(--dsw-alias-label-tertiary, #8a8f98); + font-size: 12px; + line-height: 1.5; +} + +/* PluginCard.module.css `.readOnly` / `.failed`. */ +.readOnly, +.failed { + margin: 12px 0 0; + font-size: 12px; + line-height: 1.5; +} + +.readOnly { + color: var(--dsw-alias-label-tertiary, #8a8f98); +} + +.failed { + color: var(--dsw-alias-label-error, #e06c6c); +} diff --git a/src/client/WorktreeSettingsCard.tsx b/src/client/WorktreeSettingsCard.tsx new file mode 100644 index 0000000..5b97547 --- /dev/null +++ b/src/client/WorktreeSettingsCard.tsx @@ -0,0 +1,127 @@ +/** + * The plugin's card on the Plugins → Plugin configuration settings page. + * + * It owns the `task-worktree` settings namespace through ONE three-way choice: + * pin local mode, pin worktree mode, or let the composer's picker decide and + * remember it. Two controls (a mode plus a "remember" switch) would describe + * the same three states with a fourth combination that means nothing, which is + * why this is a single choice. + * + * Everything interactive is a host primitive: the trigger is the host `Button` + * and the list is the host `Menu` — the same pair the Permission row uses for + * its own "choose one" setting. What this module styles is only the card chrome + * and the field typography, which the host does not export for plugin-owned + * cards (`ui-settings-plugins` exports `apply`/`inject` and types only). + * + * Writes go through the client settings scope (revision-fenced, persisted by + * the host), so the value is live and survives restarts. The card is dispatched + * by the Plugins section under the settings namespace this plugin's host half + * registers, so it appears only where that namespace is actually served. + */ +import { useState, useSyncExternalStore } from 'react' +import type { ReactNode } from 'react' +import { + Button, + IconChevronDownOutlineRegular, + Menu, +} from '@deepseek-ai/dsh-client-ui-primitives' +import type { WorktreeKey } from './locales.ts' +import { choiceOf } from './worktreePrefs.ts' +import type { NewConversationChoice, WorktreePrefsStore } from './worktreePrefs.ts' +import css from './WorktreeSettings.module.css' + +export interface WorktreeSettingsCardProps { + /** Durable preferences (settings namespace `task-worktree`). */ + prefs: WorktreePrefsStore + /** Locale-bound strings for the card copy. */ + t: (key: keyof WorktreeKey) => string +} + +export function WorktreeSettingsCard({ prefs, t }: WorktreeSettingsCardProps): ReactNode { + const snapshot = useSyncExternalStore(prefs.subscribe, prefs.getSnapshot) + const [open, setOpen] = useState(false) + const [menuOpen, setMenuOpen] = useState(false) + const [busy, setBusy] = useState(false) + const [failed, setFailed] = useState(false) + const disabled = !snapshot.available || busy + const choice = choiceOf(snapshot) + // Under `last` the remembered pick is what actually happens, so the hint + // says which mode that currently is. + const remembered = snapshot.defaultMode === 'worktree' ? t('worktreeMode') : t('localMode') + const hint = choice === 'last' + ? `${t('settingsRememberHint')} ${t('settingsRememberedNow')}${remembered}` + : choice === 'worktree' + ? t('settingsDefaultWorktreeHint') + : t('settingsDefaultLocalHint') + + const options: { id: NewConversationChoice; label: string }[] = [ + { id: 'local', label: t('localMode') }, + { id: 'worktree', label: t('worktreeMode') }, + { id: 'last', label: t('settingsRemember') }, + ] + const selected = options.find(option => option.id === choice) ?? options[0] + + const choose = (next: string): void => { + setMenuOpen(false) + if (disabled || next === choice) return + setBusy(true) + setFailed(false) + void prefs.setNewConversationChoice(next as NewConversationChoice).then(ok => { + if (!ok) setFailed(true) + }).finally(() => { + setBusy(false) + }) + } + + return ( +
+ + {open && ( +
+
+
+ {t('settingsDefaultMode')} + { setMenuOpen(false) }} + items={options} + selectedId={choice} + onSelect={choose} + align="end" + portal + anchor={( + + )} + /> +
+

{hint}

+
+ {snapshot.status === 'unavailable' &&

{t('settingsUnavailable')}

} + {failed &&

{t('settingsSaveFailed')}

} +
+ )} +
+ ) +} diff --git a/src/client/index.ts b/src/client/index.ts index 1f2ad14..70cd86d 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -30,6 +30,9 @@ import { en, zh } from './locales.ts' import { WorktreeBadge } from './WorktreeBadge.tsx' import { WorktreePanel } from './WorktreePanel.tsx' import { createWorktreeStore } from './worktreeStore.ts' +import { createPrefsStore, SETTINGS_NS } from './worktreePrefs.ts' +import type { SettingsScopeBinder } from './worktreePrefs.ts' +import { WorktreeSettingsCard } from './WorktreeSettingsCard.tsx' const NS = 'dsh-task-worktree' @@ -53,6 +56,8 @@ interface WorktreeClientContext { slots: SlotsService sessions: ISessions workspaces: IWorkspaces + /** Nested service injection (used to stay mounted on hosts without settings). */ + inject(services: string[], callback: (scoped: WorktreeClientContext & { settingsScope: SettingsScopeBinder }) => void): void } export const name = 'dsh-task-worktree' @@ -66,6 +71,24 @@ export function apply(ctx: WorktreeClientContext): void { /** Reactive store for worktree-mode declarations. */ const store = createWorktreeStore() + /** Durable preferences: default mode for new conversations + last-choice memory. */ + const prefs = createPrefsStore() + + // The settings card and the scope that feeds it are registered through a + // NESTED inject: naming `settingsScope` in the module-level `inject` would + // keep this whole plugin unmounted on a host without the settings domain, + // losing the composer selector to gain a card such a host cannot render. + ctx.inject(['settingsScope'], (scoped) => { + scoped.effect(() => prefs.bind(scoped.settingsScope), `${NS}: settings scope`) + scoped.slots.inject('settings.plugin.item', () => scoped.slots.register({ + name: 'settings.plugin.item', + // Keyed by the SETTINGS NAMESPACE: the Plugins page dispatches one card + // per namespace the host serves, so this must match lib/index.js. + key: SETTINGS_NS, + locale: NS, + }, () => h(WorktreeSettingsCard, { prefs, t }))) + }) + /** Resolve the current session face through the current selection id. */ const currentSession = (): SessionFace | undefined => { const current = ctx.sessions.list.getSnapshot().current @@ -149,6 +172,7 @@ export function apply(ctx: WorktreeClientContext): void { armWorktreeMode, disarmWorktreeMode, store, + prefs, sessionIdOf: currentSessionId, t, }))) diff --git a/src/client/locales.ts b/src/client/locales.ts index 79dc2d2..a406ecd 100644 --- a/src/client/locales.ts +++ b/src/client/locales.ts @@ -13,6 +13,16 @@ export const zh = { badgeFallback: 'worktree', heroStartLabel: '分支名:', heroStartPlaceholder: '可选,留空由 AI 命名', + settingsCardTitle: '任务 Worktree', + settingsCardDesc: '新对话默认进入的执行环境', + settingsDefaultMode: '新对话默认模式', + settingsDefaultLocalHint: '空白对话直接在主工作区开始。', + settingsDefaultWorktreeHint: '空白对话以 worktree 模式开始:发出第一条消息时自动创建隔离的 worktree,无需再手动选择。', + settingsRemember: '记住上次选择', + settingsRememberHint: '空白对话沿用你在输入框上方最后选定的模式。', + settingsRememberedNow: '当前记住:', + settingsUnavailable: '当前宿主没有可写的设置存储,修改不会被保存。', + settingsSaveFailed: '保存失败', } export const en = { @@ -25,6 +35,16 @@ export const en = { badgeFallback: 'worktree', heroStartLabel: 'Branch: ', heroStartPlaceholder: 'optional; blank: AI proposes', + settingsCardTitle: 'Task worktree', + settingsCardDesc: 'The execution environment new conversations start in', + settingsDefaultMode: 'Default mode for new conversations', + settingsDefaultLocalHint: 'A blank conversation starts directly in the main workspace.', + settingsDefaultWorktreeHint: 'A blank conversation starts in worktree mode: the isolated worktree is created automatically with your first message.', + settingsRemember: 'Remember the last choice', + settingsRememberHint: 'A blank conversation starts with the mode you picked last above the composer.', + settingsRememberedNow: 'Currently remembered: ', + settingsUnavailable: 'This host has no writable settings storage, so changes cannot be saved.', + settingsSaveFailed: 'Could not save', } -export type WorktreeKey = typeof zh \ No newline at end of file +export type WorktreeKey = typeof zh diff --git a/src/client/worktreePrefs.ts b/src/client/worktreePrefs.ts new file mode 100644 index 0000000..8b490b2 --- /dev/null +++ b/src/client/worktreePrefs.ts @@ -0,0 +1,205 @@ +/** + * Durable preferences of dsh-task-worktree, read and written through the + * client settings scope (`ctx.settingsScope`, provided by + * `@deepseek-ai/dsh-client-ui-settings`). + * + * The host half registers the `task-worktree` settings namespace; this store is + * the browser mirror of it. It keeps a plain observable snapshot so slot + * components can read it through `useSyncExternalStore`, and it routes every + * user choice through the scope's revision-fenced writes. + * + * The settings transport is reached structurally rather than by importing its + * types: this external package must stay free of monorepo-internal type + * dependencies, and a host without the service simply never binds (the store + * then reports `available: false` and the controls render disabled). + */ + +/** Settings namespace owned by the host half; keep in sync with `lib/index.js`. */ +export const SETTINGS_NS = 'task-worktree' + +/** Mode a conversation can start in. */ +export type DefaultMode = 'local' | 'worktree' + +/** + * The choice a user makes in the settings panel. + * + * Three states, because there are only three: pin local, pin worktree, or let + * the composer decide and remember it. The first two map to + * `{ defaultMode, rememberLastChoice: false }`, the third to + * `rememberLastChoice: true` with `defaultMode` holding whatever was picked + * last. + */ +export type NewConversationChoice = DefaultMode | 'last' + +/** The user-editable section of the settings namespace. */ +export interface WorktreePreferences { + /** Mode a blank conversation starts in (the remembered pick under `last`). */ + defaultMode: DefaultMode + /** Composer choices write `defaultMode` back, so the next conversation matches. */ + rememberLastChoice: boolean +} + +/** Read the three-way panel choice out of a resolved section. */ +export function choiceOf(prefs: Pick): NewConversationChoice { + return prefs.rememberLastChoice ? 'last' : prefs.defaultMode +} + +/** Snapshot the components subscribe to. */ +export interface WorktreePrefsSnapshot extends WorktreePreferences { + /** Sync state of the settings transport (`loading` until the first answer). */ + status: 'loading' | 'ready' | 'unavailable' + /** Whether a writable settings scope is bound (false: edits cannot persist). */ + available: boolean +} + +/** One ordered write inside the settings namespace section. */ +export interface SettingsFieldOp { + op: 'set' | 'unset' + path: string[] + value?: unknown +} + +/** The subset of the client settings scope this plugin touches. */ +interface SettingsScopeLike { + getSnapshot(): { + status: 'loading' | 'ready' | 'unavailable' + value: T | undefined + writable: boolean + } + subscribe(listener: () => void): () => void + set(field: string, value: unknown): Promise + /** Atomic multi-field write; every host in the supported line exposes it. */ + mutate?(ops: readonly SettingsFieldOp[], expectedRevision?: number): Promise +} + +/** The subset of `ctx.settingsScope` this plugin touches. */ +export interface SettingsScopeBinder { + bind(spec: { namespace: string; decode?: (section: unknown) => T | undefined }): SettingsScopeLike +} + +/** Observable preference store consumed by the panel and the settings card. */ +export interface WorktreePrefsStore { + subscribe(listener: () => void): () => void + getSnapshot(): WorktreePrefsSnapshot + /** Bind the durable scope; returns the unsubscribe function (an effect body). */ + bind(binder: SettingsScopeBinder): () => void + /** Write the mode a conversation just started with (composer "remember" path). */ + setDefaultMode(mode: DefaultMode): Promise + /** Write the panel's three-way choice, atomically. */ + setNewConversationChoice(choice: NewConversationChoice): Promise +} + +/** Snapshot used before any settings service answers (the schema defaults). */ +export const PREFS_FALLBACK: WorktreePrefsSnapshot = Object.freeze({ + defaultMode: 'local' as DefaultMode, + rememberLastChoice: false, + status: 'loading' as const, + available: false, +}) + +/** + * Narrow one wire section to the section this plugin owns. + * + * The host resolves the schema before the value reaches the browser, so this + * stays defensive rather than validating: an unexpected section keeps the last + * accepted value (returning undefined). Both fields fall back to the schema + * default (local, no remembering) rather than to a truthy guess. + */ +function decode(section: unknown): WorktreePreferences | undefined { + if (typeof section !== 'object' || section === null || Array.isArray(section)) return undefined + const raw = section as { defaultMode?: unknown; rememberLastChoice?: unknown } + return { + defaultMode: raw.defaultMode === 'worktree' ? 'worktree' : 'local', + rememberLastChoice: raw.rememberLastChoice === true, + } +} + +export function createPrefsStore(): WorktreePrefsStore { + let snapshot: WorktreePrefsSnapshot = PREFS_FALLBACK + let scope: SettingsScopeLike | undefined + const listeners = new Set<() => void>() + + const publish = (next: WorktreePrefsSnapshot): void => { + if ( + snapshot.defaultMode === next.defaultMode + && snapshot.rememberLastChoice === next.rememberLastChoice + && snapshot.status === next.status + && snapshot.available === next.available + ) return + snapshot = next + for (const listener of listeners) listener() + } + + /** Fold the scope's latest accepted section into the local snapshot. */ + const adopt = (): void => { + if (scope === undefined) return + const current = scope.getSnapshot() + const value = current.value + publish({ + defaultMode: value?.defaultMode === 'worktree' ? 'worktree' : 'local', + rememberLastChoice: value?.rememberLastChoice !== false, + status: current.status, + available: current.status === 'ready' && current.writable, + }) + } + + /** + * Apply ordered writes and confirm acceptance by re-reading the scope. + * + * The transport RESOLVES even when the host refuses a write, so the resolved + * promise proves nothing; the documented way to detect refusal is to read the + * section back (a rejected write triggers the scope's recovery read first). + * A host without `mutate` falls back to per-field `set`, which is the same + * sequence without the atomicity fence. + */ + const apply = async (ops: readonly SettingsFieldOp[]): Promise => { + if (scope === undefined) return false + try { + if (typeof scope.mutate === 'function') { + await scope.mutate(ops) + } else { + for (const op of ops) { + if (op.op === 'set') await scope.set(op.path[0], op.value) + } + } + } catch (error) { + console.warn(`[dsh-task-worktree] settings write failed: ${error instanceof Error ? error.message : String(error)}`) + return false + } + const current = scope.getSnapshot() + const section = current.value as Record | undefined + if (current.status !== 'ready' || section === undefined) return false + const accepted = ops.every((op) => op.op !== 'set' || section[op.path[0]] === op.value) + // Fold what the host accepted into our own snapshot now, rather than + // waiting for the scope's change notification. + adopt() + return accepted + } + + return { + subscribe(listener) { + listeners.add(listener) + return () => listeners.delete(listener) + }, + getSnapshot() { + return snapshot + }, + bind(binder) { + scope = binder.bind({ namespace: SETTINGS_NS, decode }) + adopt() + return scope.subscribe(adopt) + }, + setDefaultMode(mode) { + return apply([{ op: 'set', path: ['defaultMode'], value: mode }]) + }, + setNewConversationChoice(choice) { + if (choice === 'last') { + return apply([{ op: 'set', path: ['rememberLastChoice'], value: true }]) + } + return apply([ + { op: 'set', path: ['defaultMode'], value: choice }, + { op: 'set', path: ['rememberLastChoice'], value: false }, + ]) + }, + } +} diff --git a/src/client/worktreeStore.ts b/src/client/worktreeStore.ts index cd15252..2aaa348 100644 --- a/src/client/worktreeStore.ts +++ b/src/client/worktreeStore.ts @@ -4,6 +4,10 @@ * Selecting Worktree mode in the mode dropdown arms the host immediately * (`/worktree mode-on`); the store mirrors that with the optional declared * name. Slot components read it through useSyncExternalStore. + * + * `explicit` records that the user answered for THIS conversation (worktree or + * local). It is what keeps a configured default from overriding a deliberate + * local choice: without it, "local" and "not decided yet" would look alike. */ /** State the components need for the current session. */ export interface WorktreeSessionState { @@ -11,6 +15,8 @@ export interface WorktreeSessionState { name: string | undefined /** Worktree mode selected/armed (badge + strip on). */ worktree: boolean + /** The user chose a mode for this conversation (either one). */ + explicit: boolean } /** Plain observable store keyed by session id. */ @@ -20,9 +26,12 @@ export interface WorktreeStore { stateOf(sessionId: string | undefined): WorktreeSessionState /** Arm the host: worktree mode + optional name. */ declare(sessionId: string | undefined, name: string | undefined): void + /** Record a deliberate local choice for this conversation. */ clear(sessionId: string | undefined): void } +const UNDECIDED: WorktreeSessionState = { name: undefined, worktree: false, explicit: false } + export function createWorktreeStore(): WorktreeStore { let byId = new Map() let version = 0 @@ -43,24 +52,25 @@ export function createWorktreeStore(): WorktreeStore { return version }, stateOf(sessionId) { - if (sessionId === undefined) return { name: undefined, worktree: false } - return byId.get(sessionId) ?? { name: undefined, worktree: false } + if (sessionId === undefined) return UNDECIDED + return byId.get(sessionId) ?? UNDECIDED }, declare(sessionId, name) { if (sessionId === undefined) return const current = byId.get(sessionId) - const next = { name: name ?? undefined, worktree: true } - if (current !== undefined && current.name === next.name && current.worktree === next.worktree) return + const next = { name: name ?? undefined, worktree: true, explicit: true } + if (current !== undefined && current.name === next.name && current.worktree && current.explicit) return const cloned = new Map(byId) cloned.set(sessionId, next) bump(cloned) }, clear(sessionId) { if (sessionId === undefined) return - if (!byId.has(sessionId)) return + const current = byId.get(sessionId) + if (current !== undefined && !current.worktree && current.explicit) return const cloned = new Map(byId) - cloned.delete(sessionId) + cloned.set(sessionId, { name: undefined, worktree: false, explicit: true }) bump(cloned) }, } -} \ No newline at end of file +} diff --git a/test/host.mjs b/test/host.mjs new file mode 100644 index 0000000..3541205 --- /dev/null +++ b/test/host.mjs @@ -0,0 +1,243 @@ +/** + * Host-half test for dsh-task-worktree (no harness boot). + * + * Mounts the real plugin `apply()` on a minimal fake cordis context and + * asserts the two things the settings feature depends on: + * - the `task-worktree` settings namespace is registered with the expected + * schema and composed defaults; + * - the worktree-creation instruction is injected with the first genuine user + * message of a conversation that starts under the worktree default, and NOT + * when the user answered "local" for that conversation. + * + * Run: node test/host.mjs + */ +import { apply, SETTINGS_NS, WorktreeSettings } from '../lib/index.js' + +let failed = 0 +function check(label, condition, detail = '') { + if (condition) { + console.log(` ok ${label}`) + } else { + failed += 1 + console.error(`FAIL ${label}${detail ? ` — ${detail}` : ''}`) + } +} + +/** Minimal cordis-like context that records what the plugin registers. */ +function fakeContext() { + const handlers = new Map() + const registrations = { tools: [], commands: [], settings: [], effects: [] } + const resolved = { defaultMode: 'local', rememberLastChoice: false } + const ctx = { + registrations, + resolved, + __handlers: handlers, + get(name) { + if (name === 'subprocess') return { spawn: () => { throw new Error('not used in this test') } } + return undefined + }, + on(event, handler) { + const list = handlers.get(event) ?? [] + list.push(handler) + handlers.set(event, list) + return () => {} + }, + effect(callback) { + registrations.effects.push(callback) + const dispose = callback() + return () => { if (typeof dispose === 'function') dispose() } + }, + inject(services, callback) { + if (Array.isArray(services) && services.includes('settings')) callback(ctx) + }, + tools: { register: (tool) => { registrations.tools.push(tool) } }, + commands: { register: (command) => { registrations.commands.push(command) } }, + settings: { + register(ns, schema, options) { + registrations.settings.push({ ns, schema, options }) + return { get: () => ({ ...resolved }), watch: () => () => {} } + }, + }, + } + return ctx +} + +/** Fire one harness event at the mounted plugin. */ +function emit(ctx, event, payload) { + for (const handler of ctx.__handlers.get(event) ?? []) handler(payload) +} + +/** A fake agent: records injected messages. */ +function agentWith(id, seq = 0) { + const injected = [] + return { id, session: { seq }, injected, inject: (message) => { injected.push(message) } } +} + +const textOf = (message) => message?.content?.[0]?.text ?? '' + +console.log('settings namespace registration') +{ + const ctx = fakeContext() + apply(ctx) + const entry = ctx.registrations.settings[0] + check('namespace is task-worktree', entry?.ns === SETTINGS_NS, JSON.stringify(entry?.ns)) + check('composed defaults are the base', entry?.options?.base?.defaultMode === 'local' && entry?.options?.base?.rememberLastChoice === false, JSON.stringify(entry?.options?.base)) + const resolved = entry.schema({}) + check('schema defaults to local, without remembering', resolved.defaultMode === 'local' && resolved.rememberLastChoice === false, JSON.stringify(resolved)) + const worktree = entry.schema({ defaultMode: 'worktree' }) + check('schema accepts worktree', worktree.defaultMode === 'worktree') + let rejected = false + try { entry.schema({ defaultMode: 'nonsense' }) } catch { rejected = true } + check('schema rejects an unknown mode', rejected) +} + +console.log('tools and command still mount') +{ + const ctx = fakeContext() + apply(ctx) + const toolNames = ctx.registrations.tools.map((tool) => tool.name) + check('three model tools registered', toolNames.length === 3 && toolNames.includes('worktree_create'), JSON.stringify(toolNames)) + check('the /worktree command is registered', ctx.registrations.commands.some((command) => command.name === 'worktree')) +} + +console.log('default worktree: first message of a blank conversation') +{ + const ctx = fakeContext() + ctx.resolved.defaultMode = 'worktree' + apply(ctx) + const agent = agentWith('s1') + emit(ctx, 'agent/session-start', { agent, source: 'startup' }) + emit(ctx, 'agent/inbox/inserted', { agent, message: { source: { kind: 'user' } } }) + check('exactly one instruction injected', agent.injected.length === 1, String(agent.injected.length)) + check('the instruction asks for worktree_create', textOf(agent.injected[0]).includes('worktree_create')) + check('it is a plugin-sourced instruction block', agent.injected[0]?.source?.plugin === 'dsh-task-worktree' && agent.injected[0]?.source?.form === 'instructions') + emit(ctx, 'agent/inbox/inserted', { agent, message: { source: { kind: 'user' } } }) + check('the next message adds nothing', agent.injected.length === 1) +} + +console.log('default worktree: a resumed conversation is left alone') +{ + const ctx = fakeContext() + ctx.resolved.defaultMode = 'worktree' + apply(ctx) + const agent = agentWith('s1', 12) + emit(ctx, 'agent/session-start', { agent, source: 'resume' }) + emit(ctx, 'agent/inbox/inserted', { agent, message: { source: { kind: 'user' } } }) + check('no injection on resume', agent.injected.length === 0) +} + +console.log('default worktree: a late session-start beacon cannot double-inject') +{ + const ctx = fakeContext() + ctx.resolved.defaultMode = 'worktree' + apply(ctx) + // The message is observed before the lifecycle beacon (an agent created by + // the send): the seq===0 fallback decides, and the late beacon must not + // re-add the session as a fresh candidate. + const agent = agentWith('s1', 0) + emit(ctx, 'agent/inbox/inserted', { agent, message: { source: { kind: 'user' } } }) + emit(ctx, 'agent/session-start', { agent, source: 'startup' }) + emit(ctx, 'agent/inbox/inserted', { agent, message: { source: { kind: 'user' } } }) + check('exactly one injection', agent.injected.length === 1, String(agent.injected.length)) +} + +console.log('default worktree: a default switched before the first message is honoured') +{ + const ctx = fakeContext() + ctx.resolved.defaultMode = 'worktree' + apply(ctx) + const agent = agentWith('s1') + emit(ctx, 'agent/session-start', { agent, source: 'startup' }) + ctx.resolved.defaultMode = 'local' + emit(ctx, 'agent/inbox/inserted', { agent, message: { source: { kind: 'user' } } }) + check('nothing is injected', agent.injected.length === 0) +} + +console.log('plugin-produced messages never ride an injection') +{ + const ctx = fakeContext() + ctx.resolved.defaultMode = 'worktree' + apply(ctx) + const agent = agentWith('s1') + emit(ctx, 'agent/session-start', { agent, source: 'startup' }) + emit(ctx, 'agent/inbox/inserted', { agent, message: { source: { kind: 'plugin', plugin: 'other' } } }) + check('a plugin message is ignored', agent.injected.length === 0) +} + +console.log('default worktree: explicit local mode wins') +{ + const ctx = fakeContext() + ctx.resolved.defaultMode = 'worktree' + apply(ctx) + const agent = agentWith('s1') + emit(ctx, 'agent/session-start', { agent, source: 'startup' }) + const command = ctx.registrations.commands.find((candidate) => candidate.name === 'worktree') + // The browser selector runs `/worktree mode-off` through the command service. + const invocation = { rawInput: 'mode-off', agent: { session: { id: 's1' } } } + await command.handler(invocation) + emit(ctx, 'agent/inbox/inserted', { agent, message: { source: { kind: 'user' } } }) + check('mode-off suppresses the configured default', agent.injected.length === 0) +} + +console.log('mode-on after an explicit local choice') +{ + const ctx = fakeContext() + ctx.resolved.defaultMode = 'worktree' + apply(ctx) + const agent = agentWith('s1') + emit(ctx, 'agent/session-start', { agent, source: 'startup' }) + const command = ctx.registrations.commands.find((candidate) => candidate.name === 'worktree') + const invocation = (rawInput) => ({ rawInput, agent: { session: { id: 's1' } } }) + await command.handler(invocation('mode-off')) + await command.handler(invocation('mode-on worktree/login')) + emit(ctx, 'agent/inbox/inserted', { agent, message: { source: { kind: 'user' } } }) + check('the armed name is injected', agent.injected.length === 1 && textOf(agent.injected[0]).includes('worktree/login'), JSON.stringify(agent.injected.map(textOf))) +} + +console.log('an explicit mode-on needs no history and no default') +{ + const ctx = fakeContext() + apply(ctx) + // seq > 0: a conversation already under way, as `/worktree mode-on` allows. + const agent = agentWith('s1', 7) + const command = ctx.registrations.commands.find((candidate) => candidate.name === 'worktree') + await command.handler({ rawInput: 'mode-on', agent: { session: { id: 's1' } } }) + emit(ctx, 'agent/inbox/inserted', { agent, message: { source: { kind: 'user' } } }) + check('the instruction rides the next message', agent.injected.length === 1 && !textOf(agent.injected[0]).includes('分支名为')) +} + +console.log('disposal forgets the session, so a reused id starts clean') +{ + const ctx = fakeContext() + ctx.resolved.defaultMode = 'worktree' + apply(ctx) + const first = agentWith('s1') + emit(ctx, 'agent/session-start', { agent: first, source: 'startup' }) + const command = ctx.registrations.commands.find((candidate) => candidate.name === 'worktree') + await command.handler({ rawInput: 'mode-off', agent: { session: { id: 's1' } } }) + emit(ctx, 'agent/disposed', { agent: first }) + const second = agentWith('s1') + emit(ctx, 'agent/session-start', { agent: second, source: 'startup' }) + emit(ctx, 'agent/inbox/inserted', { agent: second, message: { source: { kind: 'user' } } }) + check('the old suppression is gone', second.injected.length === 1) + check('the first agent was never injected', first.injected.length === 0) +} + +console.log('default local: nothing is injected') +{ + const ctx = fakeContext() + apply(ctx) + const agent = agentWith('s1') + emit(ctx, 'agent/session-start', { agent, source: 'startup' }) + emit(ctx, 'agent/inbox/inserted', { agent, message: { source: { kind: 'user' } } }) + check('no injection', agent.injected.length === 0) +} + +console.log('schema is exported for the browser half to mirror') +{ + check('SETTINGS_NS matches the browser key', SETTINGS_NS === 'task-worktree') + check('WorktreeSettings is a rehydratable schema', typeof WorktreeSettings === 'function' && WorktreeSettings({}).defaultMode === 'local') +} + +console.log(failed === 0 ? '\nHOST OK — all checks passed' : `\nHOST FAILED — ${failed} check(s) failed`) +process.exit(failed === 0 ? 0 : 1) diff --git a/test/prefs.mjs b/test/prefs.mjs new file mode 100644 index 0000000..d5cfe3d --- /dev/null +++ b/test/prefs.mjs @@ -0,0 +1,158 @@ +/** + * Unit test for the browser preference store (no DOM, no harness). + * The client half is TypeScript, so this relies on Node's native type + * stripping (Node 22.6+/24); on an older runtime the suite skips itself rather + * than failing the build. + * Run: node test/prefs.mjs + */ +let createPrefsStore, choiceOf, PREFS_FALLBACK, SETTINGS_NS +try { + ({ createPrefsStore, choiceOf, PREFS_FALLBACK, SETTINGS_NS } = await import('../src/client/worktreePrefs.ts')) +} catch (error) { + console.log(`SKIP prefs — this Node cannot import TypeScript sources (${error.code ?? error.message}); requires Node 22.6+`) + process.exit(0) +} + +let failed = 0 +function check(label, condition, detail = '') { + if (condition) { + console.log(` ok ${label}`) + } else { + failed += 1 + console.error(`FAIL ${label}${detail ? ` — ${detail}` : ''}`) + } +} + +/** + * A stand-in for the client settings scope. + * @param behavior - `accept` folds a write into the snapshot, `refuse` leaves it + * unchanged (the transport resolves either way — that is the whole point). + */ +function fakeBinder(section, behavior = 'accept') { + const listeners = new Set() + const writes = [] + let spec + let snapshot = { + status: 'ready', + value: section, + writable: true, + } + const applyOps = (ops) => { + for (const op of ops) { + writes.push({ op: op.op, field: op.path[0], value: op.value }) + if (behavior !== 'accept' || op.op !== 'set') continue + snapshot = { ...snapshot, value: { ...snapshot.value, [op.path[0]]: op.value } } + } + } + const scope = { + getSnapshot: () => snapshot, + subscribe(listener) { + listeners.add(listener) + return () => listeners.delete(listener) + }, + async set(field, value) { + applyOps([{ op: 'set', path: [field], value }]) + }, + async mutate(ops) { + applyOps(ops) + }, + } + return { + binder: { bind: (bound) => { spec = bound; return scope } }, + writes, + getSpec: () => spec, + publish(next) { + snapshot = next + for (const listener of listeners) listener() + }, + } +} + +console.log('binding') +{ + const fake = fakeBinder({ defaultMode: 'worktree', rememberLastChoice: false }) + const store = createPrefsStore() + const unsubscribe = store.bind(fake.binder) + check('binds the plugin namespace', fake.getSpec().namespace === SETTINGS_NS, fake.getSpec().namespace) + check('declares a decoder', typeof fake.getSpec().decode === 'function') + check('adopts the accepted section', store.getSnapshot().defaultMode === 'worktree' && store.getSnapshot().rememberLastChoice === false, JSON.stringify(store.getSnapshot())) + check('reports the scope as available', store.getSnapshot().available === true) + check('the decoder narrows known values', JSON.stringify(fake.getSpec().decode({ defaultMode: 'worktree', rememberLastChoice: true })) === JSON.stringify({ defaultMode: 'worktree', rememberLastChoice: true })) + check('an absent or non-boolean remember flag means off', fake.getSpec().decode({ defaultMode: 'worktree', rememberLastChoice: 'yes' }).rememberLastChoice === false && fake.getSpec().decode({ defaultMode: 'worktree' }).rememberLastChoice === false) + check('the decoder rejects a non-object section', fake.getSpec().decode(undefined) === undefined && fake.getSpec().decode('nonsense') === undefined) + check('unbinding is a function', typeof unsubscribe === 'function') + unsubscribe() +} + +console.log('reactivity') +{ + const fake = fakeBinder({ defaultMode: 'local', rememberLastChoice: true }) + const store = createPrefsStore() + store.bind(fake.binder) + let notified = 0 + const unsubscribe = store.subscribe(() => { notified += 1 }) + fake.publish({ status: 'ready', value: { defaultMode: 'worktree', rememberLastChoice: true }, writable: true }) + check('a committed change notifies once', notified === 1 && store.getSnapshot().defaultMode === 'worktree', `${notified} / ${JSON.stringify(store.getSnapshot())}`) + fake.publish({ status: 'ready', value: { defaultMode: 'worktree', rememberLastChoice: true }, writable: true }) + check('an equal snapshot does not notify', notified === 1) + unsubscribe() +} + +console.log('the three-way panel choice') +{ + check('pinned local reads as local', choiceOf({ defaultMode: 'local', rememberLastChoice: false }) === 'local') + check('pinned worktree reads as worktree', choiceOf({ defaultMode: 'worktree', rememberLastChoice: false }) === 'worktree') + check('remembering reads as last, whatever is remembered', choiceOf({ defaultMode: 'local', rememberLastChoice: true }) === 'last' && choiceOf({ defaultMode: 'worktree', rememberLastChoice: true }) === 'last') +} + +console.log('writes') +{ + const fake = fakeBinder({ defaultMode: 'local', rememberLastChoice: true }) + const store = createPrefsStore() + store.bind(fake.binder) + + const accepted = await store.setDefaultMode('worktree') + check('an accepted write reports true', accepted === true, JSON.stringify(store.getSnapshot())) + check('the remembered pick only touches defaultMode', JSON.stringify(fake.writes) === JSON.stringify([{ op: 'set', field: 'defaultMode', value: 'worktree' }]), JSON.stringify(fake.writes)) + check('remembering stays on', store.getSnapshot().rememberLastChoice === true && choiceOf(store.getSnapshot()) === 'last') + + fake.writes.length = 0 + check('pinning worktree is one atomic mutation', (await store.setNewConversationChoice('worktree')) === true) + check('it writes both fields', JSON.stringify(fake.writes) === JSON.stringify([ + { op: 'set', field: 'defaultMode', value: 'worktree' }, + { op: 'set', field: 'rememberLastChoice', value: false }, + ]), JSON.stringify(fake.writes)) + check('the panel now reads pinned worktree', choiceOf(store.getSnapshot()) === 'worktree') + + fake.writes.length = 0 + check('choosing "remember" writes only the flag', (await store.setNewConversationChoice('last')) === true) + check('and keeps the last mode as the value', JSON.stringify(fake.writes) === JSON.stringify([{ op: 'set', field: 'rememberLastChoice', value: true }]) && store.getSnapshot().defaultMode === 'worktree', JSON.stringify(fake.writes)) + + const refusing = fakeBinder({ defaultMode: 'local', rememberLastChoice: true }, 'refuse') + const refused = createPrefsStore() + refused.bind(refusing.binder) + check('a transport that resolves while the host refuses reports false', (await refused.setNewConversationChoice('worktree')) === false) +} + +console.log('without a bound scope') +{ + const store = createPrefsStore() + check('the fallback is local, without remembering, unavailable', store.getSnapshot().defaultMode === 'local' && store.getSnapshot().rememberLastChoice === false && store.getSnapshot().available === false, JSON.stringify(store.getSnapshot())) + check('the fallback reads as the pinned local choice', choiceOf(store.getSnapshot()) === 'local') + check('the fallback reports loading, not unavailable', store.getSnapshot().status === 'loading') + check('the exported fallback matches', store.getSnapshot().defaultMode === PREFS_FALLBACK.defaultMode && store.getSnapshot().available === PREFS_FALLBACK.available) + check('a write without a scope reports false', (await store.setDefaultMode('worktree')) === false) +} + +console.log('unavailable / unwritable scope') +{ + const fake = fakeBinder({ defaultMode: 'worktree', rememberLastChoice: true }) + const store = createPrefsStore() + store.bind(fake.binder) + fake.publish({ status: 'unavailable', value: undefined, writable: false }) + check('reports unavailable', store.getSnapshot().available === false && store.getSnapshot().status === 'unavailable') + check('falls back to local while unavailable', store.getSnapshot().defaultMode === 'local', JSON.stringify(store.getSnapshot())) +} + +console.log(failed === 0 ? '\nPREFS OK — all checks passed' : `\nPREFS FAILED — ${failed} check(s) failed`) +process.exit(failed === 0 ? 0 : 1)