dsh-quick-phrases 0.0.0-stage → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ # dsh-quick-phrases bundle patch: inserts one client plugin row.
2
+ # Install the containing directory with plugin_manager install_bundle.
3
+ - insert:
4
+ - id: quick-phrases
5
+ name: 'dsh-quick-phrases'
6
+ config: {}
@@ -0,0 +1,99 @@
1
+ # 实现说明
2
+
3
+ 这份文档写给要继续改 `client.js` 的人:它怎么挂进 DSH、数据放在哪、以及哪些约束不能碰。
4
+
5
+ ## 插件形态
6
+
7
+ DSH 的插件是「bundle」:一个 npm 包 + 一行 Cordis patch。本仓库的 Host 侧是空壳,所有能力都在客户端:
8
+
9
+ | 文件 | 作用 |
10
+ | --- | --- |
11
+ | `index.js` | `export function apply() {}` —— Host 侧不注册任何东西 |
12
+ | `cordis.patch.yml` | 把 `dsh-quick-phrases` 插入到 bundle 列表 |
13
+ | `client.js` | 客户端插件:`window.__ModuleLoader__.load({ id, factory })` |
14
+ | `locale/{zh,en}.json` | 插件管理器详情页的标题 / 描述 / 详情文档路径 |
15
+ | `icon.svg` | 插件列表图标 |
16
+
17
+ `package.json` 里声明 `dsh.client.platform = "web"`、`immediately: true`、`inject: ["@deepseek-ai/dsh-client-ui-conversation"]`;`dsh.bundle.patch` 指向 patch 文件。没有构建步骤,改完 `client.js` 让渲染进程重载即可。
18
+
19
+ ## 客户端入口
20
+
21
+ `factory(require)` 返回一个 Cordis 风格的插件对象:
22
+
23
+ ```js
24
+ return {
25
+ inject: ['slots', 'locale'],
26
+ apply(ctx) {
27
+ ctx.effect(() => ctx.locale.register(NS, DICTS)) // 中英文字典,返回清理函数
28
+ ctx.slots.inject('conversation.composer.dock', () => ctx.slots.register({...}, Component))
29
+ ...
30
+ },
31
+ }
32
+ ```
33
+
34
+ - `require('react')` 取的是 DSH 浏览器端的 React,不需要打包。
35
+ - 所有注册都放进 `apply`,用 `ctx.slots.inject` 等待插槽出现;插槽消失时框架会自动调用注册返回的清理函数。
36
+ - 组件不能往 `document.body` 追加东西,也不能读别的插件的 DOM。
37
+
38
+ ## 插槽
39
+
40
+ | 插槽 | 用途 | 注册参数 |
41
+ | --- | --- | --- |
42
+ | `conversation.composer.dock` | 输入卡片下方一整行(默认位置) | `id: quick-phrases-dock`、`order: 5` |
43
+ | `conversation.input.dock` | 输入卡片上方一整行 | `id: quick-phrases-top`、`order: -10`(排在排队条、待办面板之上) |
44
+ | `conversation.input.right` | 工具行右侧紧凑控件 | `id: quick-phrases-tool`、`order: -5` |
45
+ | `settings.section` | 设置页里的「快捷短语」 | `id: quick-phrases`、`order: 26`、`label: () => t('section.title')` |
46
+ | `settings.section.icon` | 设置侧栏字形 | 与 section 同 `id`,可选 |
47
+
48
+ 三个短语行**都会注册**,但组件先跑完所有 hook、再判断「当前选中的是不是我」,不是就 `return null`。这样切位置只是一次重渲染,hook 顺序也保持稳定。
49
+
50
+ `conversation.*` 作用域的组件会拿到框架给的标准 props:`inputActions`(`setDraft` / `insertText` / `submit` …)、`useInput`、`sessionId` 等。`settings.section` 的组件拿到 `ownerProps.close`。`locale: NS` 会给组件合成一个 `t` prop;如果 locale 座位缺失(比如别的宿主版本),`resolveT()` 会退回内置字典,避免整条插槽崩掉。
51
+
52
+ ## 数据层
53
+
54
+ 三个 store 都是模块级状态 + `localStorage`,不经过 Host:
55
+
56
+ | store | 存储键 | 读写 |
57
+ | --- | --- | --- |
58
+ | 短语列表 | `dsh.quick-phrases.v1` | `normalize()` 清洗 → `persist()` 写回 → `emit()` 通知订阅者 |
59
+ | 显示位置 | `dsh.quick-phrases.placement.v1` | 校验非法值,坏值回落默认 |
60
+ | 点按行为 | `dsh.quick-phrases.click.v1` | 同上 |
61
+
62
+ `usePhrases()` / `usePlacement()` / `useClickMode()` 是 `useState` + `subscribe` 的小包装,同时监听 `storage` 事件,多窗口之间也能同步。首次使用时按当前界面语言写入四条默认短语。
63
+
64
+ 点按逻辑在 `DockChips` 里:
65
+
66
+ 1. 取当前会话的 `useInput` 快照,看草稿是否为空、有没有附件;
67
+ 2. 草稿非空或带附件 → `inputActions.insertText(text, inputActions.captureInsertion())`,插到光标处;
68
+ 3. 否则按点按行为:`setDraft(text)` + `submit()`,或只 `setDraft(text)`。
69
+
70
+ ## 样式
71
+
72
+ 每个组件自带一段 `<style>`,随组件卸载消失,不污染全局。所有颜色、圆角、焦点环都走宿主 token:
73
+
74
+ - 文字:`--dsw-alias-label-primary` / `-secondary` / `-tertiary` / `-caption`
75
+ - 背景与边框:`--dsw-alias-bg-base` / `bg-layer-*`、`--dsw-alias-border-l*`、`settings-card-fill`、`interactive-bg-hover`
76
+ - 主按钮:`--dsw-alias-button-primary-fill` + `--dsw-alias-label-primary-foreground`(与宿主 `Button` 的 primary 变体一致,深浅主题都对得上)
77
+ - 焦点:`--dsw-focus-ring-width` / `--dsw-focus-ring-color`
78
+
79
+ 不要写死颜色,也不要用 `prefers-color-scheme` 判断主题——DSH 用 `data-ds-dark-theme` 切换,硬编码会两边都对不上。
80
+
81
+ 「输入框上方」的位置需要复制宿主 dock 的几何,否则会贴在会话栏左缘:
82
+
83
+ ```css
84
+ width: calc(100% - 2 * var(--dsh-composer-side-clearance) - 2 * var(--dsh-composer-dock-inset));
85
+ max-width: calc(var(--dsh-composer-card-max-width) - 2 * var(--dsh-composer-dock-inset));
86
+ margin: 0 auto;
87
+ ```
88
+
89
+ ## 测试
90
+
91
+ `test/smoke.mjs` 把真实的 `client.js` 放进 `vm` 沙箱,用最小假 React(按组件名分配 hook 单元)和假 ModuleLoader 跑起来,直接调组件自己的 `onClick` / `onChange`,断言落在 `localStorage` 和渲染树上的结果。改行为时先改这里——它是唯一能在没有宿主的情况下验证「显示与发送分离」「位置切换」「拖动排序」是否还成立的护栏。
92
+
93
+ `test/preview.mjs` 把组件渲染成静态 HTML,拼上宿主主题 CSS,可用无头 Chromium 截图,用来肉眼核对深浅两套主题。
94
+
95
+ ## 兼容性注意
96
+
97
+ - 插件只依赖 `slots` / `locale` 两个宿主服务,以及会话组件自带的标准 props;宿主升级时优先检查这两个契约。
98
+ - 存储结构一旦变更要升版本键(`…v1` → `…v2`)并写迁移,别原地改字段含义。
99
+ - 组件文案必须走字典(`DICTS.zh` / `DICTS.en`),中文英文键要一一对称;测试会读到 `t` 座位缺失的情况。
@@ -0,0 +1,64 @@
1
+ # Quick phrases
2
+
3
+ ## What it does
4
+
5
+ Adds a row of phrase buttons (`继续`, `提交`, `推送`, `发版` …) next to the composer. Clicking one sends that phrase's **text** right away; the button shows only its **label**. The two are edited separately, so a button can stay short while the message it sends is a full sentence.
6
+
7
+ **The click behaviour is configurable** (default: send right away):
8
+
9
+ - **Send right away (default)**: one click sends the phrase while the composer is empty and holds no attachments.
10
+ - **Fill the composer**: only writes the text into the draft; sending stays your call.
11
+
12
+ In both modes, if the composer already holds text you were writing or attachments, a click never replaces it — the phrase is inserted at the caret instead.
13
+
14
+ ## Where the row lives
15
+
16
+ The row can be moved at any time from the settings page; the switch applies immediately:
17
+
18
+ | Position | Slot | Notes |
19
+ | --- | --- | --- |
20
+ | Below the composer (default) | `conversation.composer.dock` | A full row under the input card; the roomiest, best for many phrases. |
21
+ | Above the composer | `conversation.input.dock` | A full row above the input card. Its width and centering follow the host dock-card geometry (`--dsh-composer-card-max-width` / `--dsh-composer-side-clearance` / `--dsh-composer-dock-inset`), so it lines up with the card's inner edges; it is also ordered above the queue strip and todo panel so it never splits them from the card. |
22
+ | Right of the tool row | `conversation.input.right` | Inside the composer's tool row (`+`, access, model picker), for when the chips should sit next to the caret; space is tight, so the row scrolls horizontally. |
23
+
24
+ All three rows stay registered, but only the selected one renders — switching is a re-render, not a page reload.
25
+
26
+ ## Managing phrases
27
+
28
+ Open **Settings → Quick phrases**. The page has two layers: behaviour options on top, the phrase list below.
29
+
30
+ **Behaviour options** (two dropdowns, applied on selection):
31
+
32
+ - **Position**: switch between the three positions above.
33
+ - **On click**: pick "Send right away" or "Fill the composer"; the default is sending right away.
34
+
35
+ **Phrase list** (one card per phrase):
36
+
37
+ - **Drag to reorder**: grab the handle on the left and drop the card where it belongs; the **↑ / ↓** buttons move it one step at a time. The list order is the left-to-right order in the row.
38
+ - **Label**: the top line of the card is the button caption — edit it in place.
39
+ - **Text**: the large field below, multi-line.
40
+ - **Chip preview**: each card shows the resulting chip and its character count, so a too-wide label is obvious before you send anything.
41
+ - **✕**: the first click only arms the delete ("Confirm"), a second click within four seconds removes the phrase.
42
+ - **Add phrase** appends an empty card and focuses its caption; **Restore defaults** arms on the first click and restores the four built-in phrases on the second.
43
+
44
+ Changes save and apply immediately, no restart. The list lives in local browser storage (`localStorage` key `dsh.quick-phrases.v1`; the position is `dsh.quick-phrases.placement.v1`, the click behaviour `dsh.quick-phrases.click.v1`), scoped to the DSH Web origin — a different machine or cleared site data loses it.
45
+
46
+ ## Opening it from the composer
47
+
48
+ The **Manage** chip at the end of the row jumps to the same settings page. If the settings entry is not mounted in this UI yet, it says "请在『设置 — 快捷短语』中管理" instead.
49
+
50
+ ## Styling
51
+
52
+ Chips, fields and cards use the host's semantic tokens (`--dsw-alias-*`, `--dsw-radius-*`, `--dsw-focus-*`), so they follow DSH's dark and light themes. The primary button's foreground uses `--dsw-alias-label-primary-foreground`, matching the host Button's primary variant, so contrast holds in both themes.
53
+
54
+ ## Boundaries
55
+
56
+ - Phrases are plain text: no variables, no commands.
57
+ - The row only appears around the session composer; background and scheduled tasks are untouched.
58
+ - Text follows the DSH UI language (Chinese / English), including the four defaults.
59
+
60
+ ## More
61
+
62
+ - Implementation notes (slots, stores, styling, tests): [docs/ARCHITECTURE.md](ARCHITECTURE.md)
63
+ - Contributing: [CONTRIBUTING.md](../CONTRIBUTING.md)
64
+ - Security reports: [SECURITY.md](../SECURITY.md)
package/docs/DETAIL.md ADDED
@@ -0,0 +1,64 @@
1
+ # 快捷短语
2
+
3
+ ## 它做什么
4
+
5
+ 在会话输入框附近加一排短语按钮(`继续`、`提交`、`推送`、`发版` …)。点一下按钮就把这条短语的**发送内容**直接发出去;按钮上显示的是**显示名称**。两者分开,所以按钮可以很短,真正发出去的话可以很长。
6
+
7
+ **点按行为可以改**(默认是「直接发送」):
8
+
9
+ - **直接发送(默认)**:输入框为空、也没有附件时,一次点按就发出这条短语。
10
+ - **填入输入框**:只把内容写进草稿,发不发由你决定。
11
+
12
+ 两种模式下,如果输入框里**已经有你正在写的内容或附件**,点按都不会覆盖它——改为把短语插到光标处。
13
+
14
+ ## 放在哪里
15
+
16
+ 短语行的位置可以在设置页里随时切换,切换立即生效:
17
+
18
+ | 位置 | 插槽 | 说明 |
19
+ | --- | --- | --- |
20
+ | 输入框下方(默认) | `conversation.composer.dock` | 常驻在输入卡片下方的一整行,最宽松,适合放多条。 |
21
+ | 输入框上方 | `conversation.input.dock` | 输入卡片上方的一整行。宽度与居中按宿主 dock 卡的几何(`--dsh-composer-card-max-width` / `--dsh-composer-side-clearance` / `--dsh-composer-dock-inset`)计算,左右和卡片的文字内边对齐;也排在排队条、待办面板之上,不会把它们和卡片拆开。 |
22
+ | 工具行右侧 | `conversation.input.right` | 挤进输入框底部的工具行(`+`、权限、模型选择那一行),只为把按钮贴近光标;空间有限,超出的短语横向滚动。 |
23
+
24
+ 三条短语行都会注册,但同一时刻只渲染选中的那一条,切换是一次重渲染,不需要重载页面。
25
+
26
+ ## 管理短语
27
+
28
+ 打开 **设置 → 快捷短语**。页面分两层:上面是两项行为设置,下面是短语列表。
29
+
30
+ **行为设置**(两个下拉框,选中即生效):
31
+
32
+ - **显示位置**:在上面三个位置之间切换。
33
+ - **点按短语时**:选择「直接发送」或「填入输入框」。默认直接发送。
34
+
35
+ **短语列表**(一条短语一张卡片):
36
+
37
+ - **拖动排序**:按住左侧的手柄上下拖动,松手即落到新位置;也可以用卡片右侧的 **↑ / ↓** 一格一格挪。列表顺序就是短语行里按钮的从左到右顺序。
38
+ - **显示名称**:卡片顶部那行就是按钮文字,直接点进去改(例如 `提交`)。
39
+ - **发送内容**:下面的大输入框,支持多行。
40
+ - **按钮预览**:每张卡片底部实时显示这个按钮长什么样、会发送多少字,方便检查名称是否太宽。
41
+ - **✕**:第一次点击只是把按钮变成「确认」,4 秒内再点一次才真正删除,避免误删。
42
+ - **新增短语**:追加一条空卡片并自动把光标放到名称上;**恢复默认**点一次进入确认态,再点一次恢复为内置的四条短语。
43
+
44
+ 改动即时保存、即时生效,无需重启。短语保存在本机浏览器存储里(`localStorage` 键 `dsh.quick-phrases.v1`,位置存在 `dsh.quick-phrases.placement.v1`,点按行为存在 `dsh.quick-phrases.click.v1`),按 DSH 的 Web 端存储隔离,换机器或清空站点数据会丢失。
45
+
46
+ ## 在输入框旁直接打开
47
+
48
+ 短语行最右侧的 **管理** 会跳到同一页设置。如果当前界面还没装上设置入口,会提示「请在『设置 — 快捷短语』中管理」。
49
+
50
+ ## 样式
51
+
52
+ 按钮、输入框、卡片全部使用宿主的语义色 token(`--dsw-alias-*`、`--dsw-radius-*`、`--dsw-focus-*`),跟随 DSH 的深色 / 浅色主题;主按钮的前景色取 `--dsw-alias-label-primary-foreground`,与宿主 Button 的 primary 变体一致,两种主题下都保证对比度。
53
+
54
+ ## 边界
55
+
56
+ - 短语是纯文本;不解析变量、不执行命令。
57
+ - 只在会话输入框附近出现,不影响后台任务和计划任务。
58
+ - 语言跟随 DSH 界面语言(中文 / English),默认四条短语也按语言生成本地化文本。
59
+
60
+ ## 更多
61
+
62
+ - 实现细节(插槽、数据层、样式与测试):[docs/ARCHITECTURE.md](ARCHITECTURE.md)
63
+ - 参与开发:[CONTRIBUTING.md](../CONTRIBUTING.md)
64
+ - 安全报告:[SECURITY.md](../SECURITY.md)
Binary file
Binary file
Binary file
package/icon.svg ADDED
@@ -0,0 +1,19 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64" role="img" aria-label="Quick phrases">
2
+ <defs>
3
+ <linearGradient id="dqp-bg" x1="0" y1="0" x2="64" y2="64" gradientUnits="userSpaceOnUse">
4
+ <stop offset="0" stop-color="#4C6FFF"/>
5
+ <stop offset="1" stop-color="#6E4CFF"/>
6
+ </linearGradient>
7
+ </defs>
8
+ <rect width="64" height="64" rx="16" fill="url(#dqp-bg)"/>
9
+ <g fill="#FFFFFF">
10
+ <rect x="14" y="18" width="20" height="9" rx="4.5" opacity="0.95"/>
11
+ <rect x="38" y="18" width="12" height="9" rx="4.5" opacity="0.6"/>
12
+ <rect x="14" y="31" width="12" height="9" rx="4.5" opacity="0.6"/>
13
+ <rect x="30" y="31" width="20" height="9" rx="4.5" opacity="0.95"/>
14
+ </g>
15
+ <g stroke="#FFFFFF" stroke-width="3.2" stroke-linecap="round" opacity="0.95">
16
+ <path d="M42 45v9"/>
17
+ <path d="M37.5 49.5h9"/>
18
+ </g>
19
+ </svg>
package/index.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Host half of dsh-quick-phrases.
3
+ *
4
+ * The feature is entirely client-side (phrase chips under the composer plus a
5
+ * Settings section that edits them), so the Host row only has to exist for the
6
+ * bundle to activate. See client.js for the UI.
7
+ */
8
+ export function apply() {}
package/locale/en.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "meta": {
3
+ "title": "Quick phrases",
4
+ "description": "A row of phrase chips under the composer that fill the draft on click, with a managed list where the display name and the sent text are edited separately.",
5
+ "detail": "docs/DETAIL.en.md"
6
+ }
7
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "meta": {
3
+ "title": "快捷短语",
4
+ "description": "在输入框下方放一排快捷短语按钮,点按即写入草稿;显示名称与发送内容分开编辑,支持增删和排序。",
5
+ "detail": "docs/DETAIL.md"
6
+ }
7
+ }
package/package.json CHANGED
@@ -1,6 +1,63 @@
1
1
  {
2
2
  "name": "dsh-quick-phrases",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.3.3",
4
+ "description": "DSH 快捷短语:输入框旁一排短语按钮,点按即发送;管理页可增删改、拖动排序,显示名称与发送内容分离,显示位置可选。",
5
+ "license": "MIT",
6
+ "author": {
7
+ "name": "pengtang1024",
8
+ "email": "pengtang1024@qq.com"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/pengtang1024/dsh-quick-phrases.git"
13
+ },
14
+ "homepage": "https://github.com/pengtang1024/dsh-quick-phrases#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/pengtang1024/dsh-quick-phrases/issues"
17
+ },
18
+ "keywords": [
19
+ "dsh",
20
+ "dsh-plugin",
21
+ "deepseek-harness",
22
+ "quick-phrases",
23
+ "quick-reply",
24
+ "canned-responses",
25
+ "productivity"
26
+ ],
27
+ "engines": {
28
+ "node": ">=20",
29
+ "dsh": "^0.2.2-rc.3"
30
+ },
31
+ "type": "module",
32
+ "exports": {
33
+ ".": "./index.js",
34
+ "./client": "./client.js",
35
+ "./locale/*.json": "./locale/*.json",
36
+ "./icon": "./icon.svg"
37
+ },
38
+ "files": [
39
+ "index.js",
40
+ "client.js",
41
+ "cordis.patch.yml",
42
+ "locale/*.json",
43
+ "docs",
44
+ "icon.svg"
45
+ ],
46
+ "dsh": {
47
+ "manifestVersion": 1,
48
+ "bundle": {
49
+ "patch": "./cordis.patch.yml"
50
+ },
51
+ "client": {
52
+ "platform": "web",
53
+ "immediately": true,
54
+ "inject": [
55
+ "@deepseek-ai/dsh-client-ui-conversation"
56
+ ]
57
+ }
58
+ },
59
+ "publishConfig": {
60
+ "registry": "https://registry.npmjs.org",
61
+ "access": "public"
62
+ }
63
+ }