dsh-workspace-order 0.0.0-stage → 0.1.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 hesixian
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,210 @@
1
- # Temporary Holding Version
1
+ # DSH Workspace Order
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ DSH(DeepSeek Harness)Web 侧栏的**工作区排序管理器**:在一个大面板里拖拽排序几十个工作区、给同名目录批量加「父目录/」前缀、按项目族上色;顺序直接写回 Host registry,原生侧栏立即跟随。
4
+
5
+ 零构建、零运行时依赖——`lib/` 就是源码。
6
+
7
+ ## 为什么需要它
8
+
9
+ DSH 原生侧栏的工作区行只显示 `title`(默认等于目录 basename),调整顺序只有「在窄侧栏里盲拖」这一条路。一个人同时开几十个项目时,这条路走不通:
10
+
11
+ - 列表长,拖一次要滚半天,没有「置顶 / 移到顶部 / 移到末尾」这类快捷操作;
12
+ - 同名目录彻底分不清——运维/业务模块高度相似,到处都叫 `service`、`psgs-server`。
13
+
14
+ 实测一台开发机的 `~/.dsh/storages/workspace.json`:**48 个工作区、40 个唯一 basename、48/48 的 `title` 等于目录名**,其中 `psgs-server` × 7、`ewater-ms` × 3 —— 侧栏里就是 7 行一模一样的 `psgs-server`。
15
+
16
+ ## 功能
17
+
18
+ | 能力 | 说明 |
19
+ |---|---|
20
+ | 大面板拖拽排序 | 平铺列表,48 行一次拖到位;落点按行高中线判定,不只是「拖进分组」 |
21
+ | ★ 置顶区 | 置顶的工作区固定在列表最上方,同时被推到 Host 顺序的前面,原生侧栏一致 |
22
+ | 快捷移动 | 每行悬停给出「置顶 / 上移 / 下移 / 移到顶部 / 移到末尾」 |
23
+ | 重名治理 | 一键把重名的标题改成 `父目录/目录名`;**幂等**,重复点不会套娃;原名记录在案可撤回 |
24
+ | 族色 | 族 = 路径的父目录名(`D:\code\滨州\psgs-server` → `滨州`),按族名稳定 hash 取色,零配置;面板里可覆盖 |
25
+ | 搜索 | 按路径 / 标题 / 族过滤 |
26
+ | 撤回别名 | 逐条还原,撞名的跳过并在提示条汇总(原因见「已知限制」) |
27
+
28
+ ## 工作原理
29
+
30
+ **顺序只有一份真相:Host 的 workspace registry。** 插件不保存第二份顺序,所有变更都换算成
31
+ `ctx.workspaceController.insertBefore()` 调用来落盘,所以原生侧栏、刷新后的页面、重开的浏览器看到的都是同一个顺序。
32
+
33
+ 插件自己只持久化 Host 没有概念的三样东西:置顶集合、别名记录、族色。
34
+
35
+ ```
36
+ 浏览器 (lib/client.js)
37
+ 面板 UI ──fetch──▶ /plugins/workspace-order/api/*
38
+ │
39
+ Host (lib/index.js, 纯 ESM)
40
+ ctx.webServer.register ├── GET /state
41
+ ctx.workspaceController ├── PUT /config
42
+ ├── POST /order 完整 id 序列 → insertBefore(LIS 最少步)
43
+ └── POST /titles 批量 rename(事务:失败即回滚)
44
+ │
45
+ ~/.dsh/storages/workspace-order.json(原子写:temp + rename)
46
+ ```
47
+
48
+ ### HTTP 路由
49
+
50
+ 根前缀(Host 注册用的绝对 pathname):`/plugins/workspace-order/api`
51
+ 浏览器侧用 document-relative(页面 `<base href="./">` 下去掉开头斜杠):`plugins/workspace-order/api/...`
52
+
53
+ | 方法 | 路径 | 请求体 | 成功响应 |
54
+ |---|---|---|---|
55
+ | GET | `/state` | — | `200 { workspaces: [{ id, path, title, family, sessionCount }], config }` |
56
+ | PUT | `/config` | `{ pinned, aliases, familyColors }` | `200 { config }` |
57
+ | POST | `/order` | `{ order: [id...] }` | `200 { order: [id...] }`(Host 应用后的真实顺序) |
58
+ | POST | `/titles` | `{ updates: [{ workspaceId, title }], aliases? }` | `200 { updated: n, aliases? }` |
59
+
60
+ 错误体一律 `{ "error": { "code": "...", "message": "..." } }` 配 4xx/5xx。code 取值:
61
+ `invalid-request`(400)、`method-not-allowed`(405)、`body-too-large`(413)、
62
+ `title-update-failed`(409)、`aliases-write-failed`(500)、`controller-unavailable`(503)、`internal-error`(500)。
63
+
64
+ `POST /titles` 是**事务**:任意一条 rename 失败,已改的标题逐条改回去,配置文件一字不写,返回 `409` 并在
65
+ message 里说清成功条数与回滚结果。`aliases` 只有在全部 rename 成功后才合并落盘。
66
+
67
+ ## 安装
68
+
69
+ ### 从 npm(推荐)
70
+
71
+ ```bash
72
+ dsh plugin --profile web add dsh-workspace-order
73
+ ```
74
+
75
+ 再把 `dsh-workspace-order` 加进 `~/.dsh/profiles/web/package.json` 的 `dsh.profile.bundles` 数组。
76
+
77
+ 也可以在 DSH 的**插件市场**里搜 `workspace-order` 直接安装(市场的安装名取自本仓库名,两者一致)。
78
+
79
+ ### 从本地源码(`link:`)
80
+
81
+ ```bash
82
+ dsh plugin --profile web add link:D:/code/dsh-workspace-order
83
+ ```
84
+
85
+ 再把包名加进 `~/.dsh/profiles/web/package.json` 的 `dsh.profile.bundles` 数组:
86
+
87
+ ```json
88
+ "dsh-workspace-order"
89
+ ```
90
+
91
+ ### 从 GitHub
92
+
93
+ ```bash
94
+ dsh plugin --profile web add github:hesixian/dsh-workspace-order
95
+ ```
96
+
97
+ 同样需要把包名加进 `dsh.profile.bundles`。
98
+
99
+ ### 生效
100
+
101
+ bundle patch 里的那一行(`- id: workspace-order`)只在 `dsh web` **启动时装配**,所以改完 profile 要重启 `dsh web`。
102
+ 想先确认有没有进组合树,不必重启:
103
+
104
+ ```bash
105
+ dsh --profile web --dump-config | grep -A2 workspace-order
106
+ ```
107
+
108
+ ## 使用
109
+
110
+ 1. 侧栏出现「工作区」图标,点进去是主面板。
111
+ 2. 拖拽行、或用行内按钮调整顺序——顺序立刻写回 Host,原生侧栏同步变化。
112
+ 3. 点「重名治理(n)」把重名标题改成 `父目录/目录名`;再点一次不会有任何变化(幂等)。
113
+ 4. 点「撤回别名(n)」把它们改回去。
114
+ 5. 面板顶部有搜索框和「刷新」。
115
+
116
+ ### 配置文件
117
+
118
+ `~/.dsh/storages/workspace-order.json`
119
+
120
+ ```json
121
+ {
122
+ "version": 1,
123
+ "pinned": ["workspace-xxxx"],
124
+ "aliases": { "workspace-xxxx": { "original": "psgs-server", "current": "滨州/psgs-server" } },
125
+ "familyColors": { "滨州": "#7c5cff" }
126
+ }
127
+ ```
128
+
129
+ 坏 JSON 或字段缺失时回退默认值,面板不会因此打崩。
130
+
131
+ ### 命令行修复脚本
132
+
133
+ 面板不可用时,可以用脚本逐条撤回别名(撞名的跳过,保留 `pinned` / `familyColors`):
134
+
135
+ ```bash
136
+ node scripts/revert-titles.mjs --dry # 先看会发生什么
137
+ node scripts/revert-titles.mjs
138
+ ```
139
+
140
+ ## 开发
141
+
142
+ ```bash
143
+ node --test # 41 个用例
144
+ ```
145
+
146
+ - `test/host.test.mjs`:重排最小步数(全排列穷举 + 独立 LIS 交叉验证)、族提取与配色稳定性、
147
+ 配置原子写与损坏回退、假 ctx 驱动四条路由的状态码与响应体。
148
+ - `test/client.test.mjs`:用手写的最小 React 运行时真跑 `lib/client.js`,配假 Host,
149
+ 钉住「撤回撞名只跳过那一条」与「重名治理幂等」两条曾经出问题的路径。
150
+
151
+ 客户端 bundle 没有构建步骤:它是一个手写的
152
+
153
+ ```js
154
+ window.__ModuleLoader__.load({ id: '<包名>', factory: (require) => { /* ... */ return module.exports } })
155
+ ```
156
+
157
+ `require("react")` 走宿主共享模块表,所以不能用 JSX,组件一律 `React.createElement`。
158
+
159
+ ## 发版
160
+
161
+ 首次发布必须由人完成(npm 规定首次发布要 2FA):
162
+
163
+ ```bash
164
+ npm login
165
+ npm publish
166
+ ```
167
+
168
+ 之后由 `.github/workflows/publish.yml` 走 npm 的 **trusted publishing(OIDC)**,无需任何 token:
169
+
170
+ ```bash
171
+ # 改好 package.json 的 version,提交后
172
+ git tag v0.1.1 && git push origin v0.1.1
173
+ ```
174
+
175
+ 前提是在 npm 包页 → Settings → Trusted publishing 里登记本仓库与 `publish.yml`(一次性)。
176
+
177
+ ## 目录结构
178
+
179
+ ```
180
+ lib/index.js Host 入口:name / inject / API_PREFIX / makeRoutes / apply
181
+ lib/order.js 期望顺序 → 最少 insertBefore 序列(LIS)
182
+ lib/family.js 路径 → 族名、族名 → 稳定配色(与客户端调色板逐字一致)
183
+ lib/store.js 配置读写:原子写 + 损坏回退
184
+ lib/client.js 浏览器半侧:侧栏图标 + 主面板(手写 module wrapper,无构建)
185
+ cordis.patch.yml bundle patch:插入 id 为 workspace-order 的 Host 行
186
+ scripts/ 命令行修复脚本
187
+ test/ node --test 用例
188
+ docs/ 设计文档
189
+ .github/ CI(Node 20/22/24 × 三平台)与 OIDC 发版 workflow
190
+ ```
191
+
192
+ ## 已知限制
193
+
194
+ - **撤回只能部分还原**。Host 的 `rename` 强制标题唯一,而重名工作区的原名本来就不唯一
195
+ (7 个 `psgs-server`):能还原的还原,撞名的保留 `父目录/目录名` 形式,并在提示条里写清楚还剩几个。
196
+ 再点一次「重名治理」可以把这些重新整理回不撞名的形式,所以是可来回收敛的。
197
+ - **需要重启 Host**。插件行只在 `dsh web` 启动时装配,改完 profile 不重启不会生效。
198
+ - **触屏不友好**。行内按钮靠 `:hover` / `:focus-within` 显示,桌面 Web 与桌面端为主。
199
+ - 只管理**工作区**,不涉及会话排序;不做树视图与跨层级拖拽(原生侧栏已支持同级拖拽)。
200
+
201
+ ## 开发期修掉的坑
202
+
203
+ - 重名治理不幂等:目标名曾从**当前标题**推导,且撞名集合包含自身,第二次点会给每条标题追加 `" (2)"`。
204
+ 现在目标名从**路径**推导,并排除本次要改的项。
205
+ - 撤回别名整批事务在真实数据上必然失败(原名不唯一 + 标题唯一约束),改为**逐条提交、撞名跳过**。
206
+ - 重名检测曾按标题**末段**比较,治理完成后按钮仍亮着,改为按**完整标题**比较。
207
+
208
+ ## 许可证
209
+
210
+ MIT
@@ -0,0 +1,6 @@
1
+ # 工作区排序插件的 bundle patch:一条 Host 行,持有 /plugins/workspace-order/api 路由。
2
+ # 行 id 只用本包自己的命名空间——loader 全局一 id 一行(later wins),撞 id 会静默丢行;
3
+ # 行 name 与包名逐字一致。
4
+ - insert:
5
+ - id: workspace-order
6
+ name: 'dsh-workspace-order'
@@ -0,0 +1,88 @@
1
+ # 工作区排序插件设计(dsh-plugin-workspace-order)
2
+
3
+ 日期:2026-11-23
4
+ 状态:设计已获用户批准(Q1 A / Q2 AD / Q3 AC / Q4 A / Q5 A / Q6 A)
5
+
6
+ ## 问题
7
+
8
+ DSH 原生侧栏虽然有工作区拖拽排序,但只用窄侧栏盲拖这一个入口,且行上只显示 `title`(默认等于目录 basename)。
9
+
10
+ 实测本机 `~/.dsh/storages/workspace.json`:48 个工作区、40 个唯一 basename、48/48 的 `title === basename`,
11
+ 其中 `psgs-server` × 7、`ewater-ms` × 3 —— 原生侧栏实际显示 7 行完全相同的 `psgs-server`。
12
+
13
+ ## 约束(已查证)
14
+
15
+ - 侧栏 `sidebar.workspaces` 是 **single 槽位**(ui-workspace 独占),第三方插件无法改造原生列表 → 只能新增主面板 + 侧栏图标。
16
+ - Host 侧 `workspaceController.insertBefore` / `rename` 是顺序与标题的唯一真相;不要维护第二份顺序。
17
+ - 客户端 bundle 必须是 `window.__ModuleLoader__.load({ id, factory })` 包裹形式;`factory` 里 `require("react")` 走共享模块表。
18
+ - 已装第三方样板:`@linxin666/dsh-agents`(`src/client/panel.tsx` 注册 `sidebar.panellist` + `main` 槽;host 半侧用 `ctx.webServer.register`)。
19
+
20
+ ## 架构
21
+
22
+ ```
23
+ 浏览器 (lib/client.js, 手写 wrapper, 无构建)
24
+ 面板 UI ──fetch──> /plugins/workspace-order/api/*
25
+ │
26
+ Host (lib/index.js, 纯 ESM)
27
+ ctx.webServer.register ├── GET /state 工作区快照 + 插件配置
28
+ ctx.workspaceController ├── PUT /config 置顶 / 别名 / 族色
29
+ ├── POST /order 完整 id 序列 → insertBefore
30
+ └── POST /titles 批量 rename
31
+ │
32
+ ~/.dsh/storages/workspace-order.json(原子写)
33
+ ```
34
+
35
+ 顺序只有一份真相(Host registry)。插件只持久化 Host 没有概念的东西:置顶集合、别名映射、族色。
36
+
37
+ ## 数据
38
+
39
+ `~/.dsh/storages/workspace-order.json`
40
+
41
+ ```json
42
+ { "version": 1,
43
+ "pinned": ["workspace-xxx"],
44
+ "aliases": { "workspace-xxx": { "original": "psgs-server", "current": "滨州/psgs-server" } },
45
+ "familyColors": { "滨州": "#7c5cff" } }
46
+ ```
47
+
48
+ 族 = 规范化路径的父目录名(`D:\\code\\滨州\\psgs-server` → `滨州`);已在配置里的族色优先,否则按族名 hash 取固定调色板。
49
+
50
+ ## 路由契约
51
+
52
+ 前缀 `/plugins/workspace-order/api`。
53
+
54
+ | 方法 | 路径 | 请求 | 响应 |
55
+ |---|---|---|---|
56
+ | GET | `/state` | — | `{ workspaces: [{id,path,title,family,sessionCount}], config }` |
57
+ | PUT | `/config` | `{ pinned, aliases, familyColors }` | `{ config }` |
58
+ | POST | `/order` | `{ order: [id...] }` | `{ order: [id...] }`(应用后的真实顺序) |
59
+ | POST | `/titles` | `{ updates: [{workspaceId,title}] }` | `{ updated: n }` |
60
+
61
+ 错误体:`{ "error": { "code": "...", "message": "..." } }` + 4xx/5xx。
62
+
63
+ ## 面板行为
64
+
65
+ - 侧栏图标「工作区」→ 主面板 `workspace-order`(`sidebar.panellist` order 40 + layout `main`)。
66
+ - `★ 置顶区` 在上,`其余` 在下;每行:拖拽手柄、序号、族色点、title、尾部路径片段、悬停按钮(置顶/上移/下移/到顶/到底)。
67
+ - 搜索框按路径/title/族过滤。
68
+ - 顶部动作:「重名治理」(仅当存在重名 basename 时可点,批量把重名 title 改成 `父目录/名字` 并记录别名)、「撤回别名」、「刷新」。
69
+ - 变更一律乐观更新 → 调路由 → 失败时重拉 `/state` 并在面板顶部显示一行错误。
70
+
71
+ ## 明确不做(YAGNI)
72
+
73
+ 树视图、跨层级嵌套拖拽、会话排序、多用户权限、动效精修、i18n 字典(中文硬编码)。
74
+
75
+ ## 验收
76
+
77
+ 1. 面板改序后原生侧栏顺序同步变化
78
+ 2. 刷新页面顺序不变
79
+ 3. 关闭浏览器重开顺序不变
80
+ 4. 7 个 `psgs-server`「重名治理」后原生侧栏可区分,「撤回别名」后复原
81
+ 5. 置顶项重启后仍在顶部
82
+ 6. 单测覆盖:重排最小步数、族提取、配色 hash、配置读写与迁移
83
+
84
+ ## 分工
85
+
86
+ - Host 半侧 + 单测 → 子代理 A
87
+ - Client 面板 → 子代理 B
88
+ - 安装、真机验收 → 调度方