diff --git a/CHANGELOG.md b/CHANGELOG.md index 156242c8..00da3cf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,11 @@ - 🧪 守护:`tests/market-manifest.spec.ts` 同时校验仓库清单与 `pnpm pack` 后的发布清单,dependencies 必须恰好是 `ws` / `yaml`,且 `src` 仍在 `files` 里。 +- ✨ **划选操作可配置**:统一文件编辑/预览与线索正文/评论的划选菜单;支持总开关、逐项开关、主菜单及改写类型排序、内置提示词编辑/恢复和自定义操作。改写收进二级菜单(扩写 / 去 AI 味 / 缩短 / 续写),默认在新的侧边会话立即执行,也可先填草稿。 + - **改写直接更新原资源**:本地文件直接编辑原路径;远程正文沿用来源保存能力。只读内容、评论和当前有未保存编辑的表面不提供改写。 + - **独立翻译**:直接调用宿主 LLM,不创建会话、不修改原文;译文留在划选浮层,可复制与重试。模型可独立配置,目标语言默认跟随当前界面语言。 + - **明确插入目标**:「插入主会话 / 插入到侧边」仅填写草稿并保留来源,不发送;划选打开的侧边会话在宽屏浮动,手机窄屏以 Tab 打开。文件标签页恢复为与「本地文件」一致的文件夹图标。 + - ✨ **侧栏细节改进**:内容加载使用居中的环形动画,尊重减少动态效果偏好;转为浮窗后移除原标签页,草稿与滚动位置不变;浮窗边缘稍加粗,文件预览与线索收集使用更清晰的独立图标。 - **选区保留来源**:线索正文或评论的「选择并插入」同时携带稳定 `dsh-clue` 引用和选区原文,模型能识别来源;保存引用失败时保留选区供重试,不发送消息。 - **设置入口对齐**:标签页、文件预览开关旁始终保留设置按钮;无设置项时禁用,有设置项时即使功能关闭也可配置。开始页「更多」新增「侧边栏设置」。 diff --git a/CHANGELOG_EN.md b/CHANGELOG_EN.md index be954463..ad781ef3 100644 --- a/CHANGELOG_EN.md +++ b/CHANGELOG_EN.md @@ -71,6 +71,11 @@ - 🧪 `tests/market-manifest.spec.ts` checks both the repo and the `pnpm pack` manifest: dependencies must be exactly `ws` / `yaml`, and `src` must stay in `files`. +- ✨ **Configurable selection actions**: one menu across file editing/previews and clue bodies/comments, with overall/per-action switches, menu and rewrite ordering, editable/resettable prompts and custom actions. Rewrite opens a submenu (expand / naturalize / shorten / continue) and runs in a fresh side chat by default, with an optional draft-first mode. + - **Rewrite the original source**: local actions edit the original path; remote bodies use the existing source save flow. Read-only content, comments and surfaces with unsaved edits do not offer rewriting. + - **Standalone translation**: call the host LLM directly, without creating a session or changing the source. Results stay in the popup with copy/retry. Configure a separate model; the target language follows the UI by default. + - **Explicit insertion targets**: insert into main or side chat only fills a draft and preserves provenance. Selection side chats float on wide screens and open as tabs on narrow screens. The Files tab again matches the Local files folder icon. + - ✨ **Sidebar polish**: content loading uses a centered ring animation with reduced-motion support. Floating a window removes its former tab while preserving drafts and scroll position; floating edges are slightly stronger, and file preview and Clues have distinct, clearer icons. - **Selection provenance**: inserting a clue body or comment selection carries both a stable `dsh-clue` reference and the exact excerpt. Failed reference preparation keeps the selection available for retry and never sends a message. - **Aligned settings actions**: tab and viewer switches always reserve a settings button, disabled only when no settings exist. Existing configuration stays accessible even when its feature is off. Start-page More now includes Sidebar settings. diff --git a/docs/external-plugin-guide.md b/docs/external-plugin-guide.md index d272785d..e1d4657f 100644 --- a/docs/external-plugin-guide.md +++ b/docs/external-plugin-guide.md @@ -1085,7 +1085,13 @@ registerSidechatSurfaceAdapter(adapter: SidechatSurfaceAdapter): () => void ### 7.2 划选「添加到对话」的引用 chip(v0.30.0+) -在内置编辑器(`code` / `markdown` / `jsonl` 的 CodeMirror 面,以及 markdown 预览)里划选一段文字,弹窗「添加到对话」会往主会话 composer 落一枚 chip。此处记录它用到的契约与降级,第三方插件若想复刻同一套交互可以照抄。 +内置编辑器(`code` / `markdown` / `jsonl` 的 CodeMirror 面,以及 markdown 预览)、线索正文和评论共用划选浮层。底部「插入主会话 / 插入到侧边」只写草稿,不发送:主会话 composer 使用引用 chip,侧边 composer 使用保留来源的原文。其他动作与设置见下。此处记录引用 chip 的契约与降级,第三方插件可复用。 + +设置页「划选操作」复用原设置文档,配置存入 `pluginSettings.clues.selection`:`enabled`、`autoRun`、`disabled`(逐项禁用 map)、`menuOrder`(rewrite / translate)、`rewriteOrder`、`prompts`、`customActions`(id / name / prompt)、`translationLanguage`、`translationModel`(provider/model;空为跟随主会话)。两级排序独立,插入保留底部一组;空目标语言跟随实际 UI locale(由 page bridge 跨 lazy editor bundle 传递),不是浏览器语言。 + +改写(扩写 / 去 AI 味 / 缩短 / 续写 / 自定义)固定进入新侧边会话;默认立即发送,关闭 `autoRun` 只准备指令并填写侧边草稿。本地文件直接操作原路径;远程正文仍用来源已有的草稿提交与并发保存流程。只读正文、评论和当前存在未保存编辑的表面不提供改写。宽度 `<768px` 使用原生 sidechat Tab,否则使用仅浮动窗口;打开后不因 resize 自动换面。关闭浮窗不归档历史,也不取消已准入操作。 + +翻译走正常认证的 `selection.translate` 路由和宿主 LLM service;仅传选区、目标语言、会话模型路由及可选独立模型,不建立 Agent、侧边会话、资源草稿或写盘。译文在原浮层显示;失败/截断不当作成功,关闭取消请求。没有独立 API Key 配置或流式新通道。 线索详情的正文和评论选区另有来源要求:显式插入前,未持久化的候选先调用 `clues.ensure` 取得稳定 ID;已存线索复用现有 ID。随后用内置 `reference` chip 携带 `[[dsh-clue:]]`、空行和选区原文,发送时两者一起展开;不改用只序列化 token 的线索 codec,以免丢失选区。纯文本降级也保留两者。失败时保留菜单,插入本身不发送消息。 @@ -1262,7 +1268,7 @@ if (ctx.betterSidebar.features.includes('tabActions')) { `ctx.betterSidebar.windows.open(options)` 按稳定 `id` 打开窗口,返回 `WindowHandle`;重复打开只聚焦现有实例,不替换其草稿或导航栈。内容既可浮动,也可通过 `surface: 'sidebar'` 停靠到打开时所属会话的原生标签页。 -- `handle.dock?.()` 将同一份内容移到原会话的侧栏;不可停靠时返回 `false`。 +- `handle.dock?.()` 将同一份内容移到原会话的侧栏;不可停靠时返回 `false`。可用 `dockable: false` 声明仅浮动的任务窗口(不显示停靠控件,`dock()` 返回 `false`),适合不支持隐藏态的实时组件。 - `handle.float?.()` 先移动原内容,再关闭原生标签页,不保留浮窗提示页;草稿、导航栈和滚动位置继续由同一个实例持有。这不是关闭内容,不运行 `onBeforeClose`。 - `handle.close()` 才运行 `onBeforeClose`;拒绝关闭会保留内容。`update()` 不会重置用户放置的几何。 - 浮窗边缘使用更强的 `--dsw-alias-border-l4`,宽度为 2px;停靠后不绘制这条浮窗外框。全部视觉值继续走宿主令牌。 diff --git a/src/client/SelectionSettings.tsx b/src/client/SelectionSettings.tsx new file mode 100644 index 00000000..568e4013 --- /dev/null +++ b/src/client/SelectionSettings.tsx @@ -0,0 +1,105 @@ +import { useEffect, useId, useState } from 'react' +import { REWRITE_ACTIONS, REWRITE_PROMPTS, selectionPrompt, type SelectionSettings, type RewriteAction } from '../selection-settings.ts' +import { api, type GitModelCatalog } from './api.ts' +import { t } from './locales.ts' +import { ActionButton, Notice, SettingRow, TextArea, TextInput, ToggleSwitch } from './ui/index.ts' +import css from './selection-settings.module.css' + +const labels = { + rewrite: 'clueSelectionRewrite', translate: 'clueSelectionTranslate', + expand: 'clueSelectionExpand', humanize: 'selectionHumanize', shorten: 'clueSelectionShorten', continue: 'clueSelectionContinue', + insertMain: 'selectionInsertMain', insertSide: 'selectionInsertSide', +} as const + +/** The settings document uses the same revision-guarded writer as the other groups. */ +export function SelectionSettingsPanel({ value, sessionId, onChange }: { + value: SelectionSettings; sessionId?: string; onChange(value: SelectionSettings): void +}) { + const [catalog, setCatalog] = useState(null) + const [error, setError] = useState(null) + const [name, setName] = useState('') + const [prompt, setPrompt] = useState('') + const listId = useId() + useEffect(() => { + if (sessionId === undefined) return + let active = true + api.gitModels({ sessionId }).then(result => { if (active) setCatalog(result) }, cause => { if (active) setError(String(cause)) }) + return () => { active = false } + }, [sessionId]) + const patch = (changes: Partial): void => { onChange({ ...value, ...changes }) } + const label = (id: string): string => value.customActions.find(action => action.id === id)?.name ?? t(labels[id as keyof typeof labels]) + const toggle = (id: string): React.ReactNode => { patch({ disabled: { ...value.disabled, [id]: !enabled } }) }} /> + const move = (ids: string[], id: string, delta: number): string[] => { + const next = [...ids] + const index = next.indexOf(id) + const target = index + delta + ;[next[index], next[target]] = [next[target]!, next[index]!] + return next + } + const orderButtons = (id: string, ids: string[], onOrder: (order: string[]) => void): React.ReactNode => <> + { onOrder(move(ids, id, -1)) }}>↑ + { onOrder(move(ids, id, 1)) }}>↓ + + return
+

{t('selectionSettings')}

+

{t('selectionSettingsDesc')}

+ { patch({ enabled }) }} /> + + { patch({ autoRun }) }} /> + + {value.menuOrder.map(id => + {orderButtons(id, value.menuOrder, menuOrder => { patch({ menuOrder: menuOrder as SelectionSettings['menuOrder'] }) })}{toggle(id)} + )} + {(['insertMain', 'insertSide'] as const).map(id => {toggle(id)})} +

{t('clueSelectionRewrite')}

+ {value.rewriteOrder.map(id =>
+ + {orderButtons(id, value.rewriteOrder, rewriteOrder => { patch({ rewriteOrder }) })}{toggle(id)} + +
{t('selectionPrompt')} + {!REWRITE_ACTIONS.includes(id as typeof REWRITE_ACTIONS[number]) && { + const nextName = event.target.value.trim() + if (nextName !== '') patch({ customActions: value.customActions.map(action => action.id === id ? { ...action, name: nextName } : action) }) + }} />} +