@cooper-zhuang/dsh-workspace-sort 0.2.0 → 0.2.2
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/README.md +25 -16
- package/cordis.patch.yml +16 -10
- package/index.js +87 -18
- package/lib/client.js +328 -58
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @cooper-zhuang/dsh-workspace-sort
|
|
2
2
|
|
|
3
|
-
DSH(DeepSeek Harness)Web
|
|
3
|
+
DSH(DeepSeek Harness)Web 插件:给左侧「工作区」那一层补排序能力——按最近一次人工提问自动排、正在等你输入的排最前、置顶几个常驻、运行中的排前面,并提供一个只看排序的小面板。
|
|
4
4
|
|
|
5
5
|
官方侧栏的「视图选项 → 最近更新」排的是**每个工作区内部的会话**,从不排工作区本身;工作区顺序只由宿主保存的拖拽顺序决定。所以那个选项看起来「没生效」——它本来就不管工作区。
|
|
6
6
|
|
|
@@ -9,19 +9,21 @@ DSH(DeepSeek Harness)Web 插件:给左侧「工作区」那一层补排序
|
|
|
9
9
|
## 功能
|
|
10
10
|
|
|
11
11
|
- **按最近提问自动排序**:每个工作区取最新一条「你发出的提问」的时间(会话摘要的 `updatedAt`)。打开会话、助手回复、后台任务跑完都不算活动,不会让顺序跳动。
|
|
12
|
+
- **等你输入优先**:工作区里有会话正等你回答(审批、计划审阅、提问三种)就排到未置顶区最前,压过「运行中」。判据是内核的 `ctx.uiSession.pendingInteractions`,与侧栏自己显示等待标记的规则一致;其他 kind 不算。
|
|
12
13
|
- **容器目录按子树汇总**:`~/Documents/Code/Mubea` 这类只用来分组的目录自己没有会话,按整个子树的最新活动参与排序,否则这个分组会沉到底部。
|
|
13
14
|
- **置顶**:把几个常驻工作区钉在列表最前,按你钉的顺序排列,不参与活动排序。
|
|
14
15
|
- **运行中的排前面**:可选。某个工作区里有会话正在跑,就排在未置顶区的前面,长任务不会沉出视野。
|
|
15
|
-
-
|
|
16
|
-
-
|
|
16
|
+
- **面板**(插件页里本组合包页面的卡片上点「打开排序面板」;侧栏不放图标):列出全部工作区,显示会话数、等待输入数、运行中会话数、最近活动相对时间;支持按名称筛选、点图钉置顶、开关上面两条规则、点「立即整理」立刻重排一次。
|
|
17
|
+
- **手动拖拽优先**:你用鼠标拖过之后,插件停手,直到下一次提问、某个会话开始等你输入,或你点「立即整理」。
|
|
17
18
|
- **无变化不写盘**:算出来的顺序和当前一致时,一个字节都不写。
|
|
18
19
|
|
|
19
20
|
## 实现要点
|
|
20
21
|
|
|
21
22
|
- 顺序只通过官方 `workspaces.insertBefore` 写入(与拖拽同一个命令),落在 `$DSH_HOME/storages/workspace.json` 的持久顺序里,刷新、换窗口、重启都保留。
|
|
22
23
|
- 置顶与两个开关存在宿主侧 `$DSH_HOME/workspace-sort/prefs.json`(原子写:tmp 后 rename)。**不用 localStorage**:桌面端 Web 服务绑定的是随机端口(`port: 0`),页面 origin 每次重启都变,localStorage 会跟着丢。
|
|
23
|
-
-
|
|
24
|
-
-
|
|
24
|
+
- 三个配置键是宿主 `Config` 上的 `.volatile()` 字段:宿主拿到活的 `{ get() }` 引用,浏览器半边拿到同一份值的 `SyncedConfig` 引用。改配置即时生效,不重启、不重载页面;启动时也不再 GET 配置,宿主路由不可达只影响置顶的持久化,不会把排序整个关掉。
|
|
25
|
+
- 宿主半边只有两条回环路由:`GET /dsh-workspace-sort/api/state`(置顶 + 最后一次重排决策,`config` 段仅用于 curl 诊断)和 `POST /dsh-workspace-sort/api/prefs`(保存置顶与开关)。没有文件系统操作、没有子进程、没有会话操作。
|
|
26
|
+
- 面板与入口都用官方 Slot:`plugins.bundle.config`(插件页本组合包的卡片)和 `shell.overlay`(面板),不查 DOM 类名;侧栏不占任何位置。
|
|
25
27
|
|
|
26
28
|
## 安装
|
|
27
29
|
|
|
@@ -31,17 +33,23 @@ dsh plugin --profile desktop add /path/to/packages/dsh-workspace-sort
|
|
|
31
33
|
|
|
32
34
|
生效条件:
|
|
33
35
|
|
|
34
|
-
- 第一次安装 / 改了 `index.js
|
|
35
|
-
-
|
|
36
|
+
- 第一次安装 / 改了 `index.js` 或 `lib/client.js`(插件代码):重启一次宿主。
|
|
37
|
+
- 改配置(插件页的配置卡片,或 `cordis.patch.yml` 的 `config` 块):即时生效,不重启、不重载页面。
|
|
38
|
+
- 只重载界面:菜单「DSH Desktop Beta → 重新加载界面」。
|
|
39
|
+
|
|
40
|
+
## 内核要求
|
|
41
|
+
|
|
42
|
+
- 配置即时生效需要 DSH **0.2.2-rc.3+**:该版本起 Host 的 `.volatile()` Config 字段会同步给浏览器半边,`apply(ctx, config)` 收到 `SyncedConfig` 引用;插件页的 `plugins.bundle.config` 槽位也要求同一条版本线。
|
|
43
|
+
- 更老的内核(`engines.dsh` 仍允许的 0.2.1):配置退回内置默认值,改配置要重启宿主;`ctx.uiSession` 不存在时插件退化为纯活动排序,不显示等待徽标。
|
|
36
44
|
|
|
37
45
|
## 配置
|
|
38
46
|
|
|
39
|
-
配置在插件的 load 行(profile 的 `cordis.patch.yml
|
|
47
|
+
配置在插件的 load 行(profile 的 `cordis.patch.yml`)里,也可以直接在插件页本行的配置卡片里改;两边都即时生效:
|
|
40
48
|
|
|
41
49
|
```yaml
|
|
42
50
|
- id: workspace-sort
|
|
43
51
|
config:
|
|
44
|
-
enabled: true # false =
|
|
52
|
+
enabled: true # false = 浏览器半边停手,顺序不动;宿主路由仍在,置顶照常读写
|
|
45
53
|
aggregate: true # false = 容器目录只按自己的会话算(不含子树)
|
|
46
54
|
initialSort: true # false = 页面加载时不排,等下一次提问或手动整理
|
|
47
55
|
```
|
|
@@ -51,8 +59,8 @@ dsh plugin --profile desktop add /path/to/packages/dsh-workspace-sort
|
|
|
51
59
|
## 数据与副作用
|
|
52
60
|
|
|
53
61
|
- 顺序是**宿主持久状态**,写在 `$DSH_HOME/storages/workspace.json` 的 `global.workspaceIds`,和其他窗口一致。
|
|
54
|
-
- 活动来自会话列表的 `updatedAt
|
|
55
|
-
- 每次实际重排宿主写一行日志;`GET /dsh-workspace-sort/api/state` 返回最后一次重排的 `current` / `desired` / `moves` / `newest`。
|
|
62
|
+
- 活动来自会话列表的 `updatedAt`(持久化的最后一条人类提问时间);空白新会话(草稿)与子代理会话不计入。等待状态来自 `ctx.uiSession.pendingInteractions`,不落盘。
|
|
63
|
+
- 每次实际重排宿主写一行日志;`GET /dsh-workspace-sort/api/state` 返回最后一次重排的 `current` / `desired` / `moves` / `newest` / `waiting`。
|
|
56
64
|
- 不联网(除了本机回环路由),不读写你的项目文件。
|
|
57
65
|
|
|
58
66
|
## 与社区插件的差别
|
|
@@ -60,7 +68,7 @@ dsh plugin --profile desktop add /path/to/packages/dsh-workspace-sort
|
|
|
60
68
|
| 能力 | 本插件 | 社区 `dsh-workspace-manager` |
|
|
61
69
|
|---|---|---|
|
|
62
70
|
| 按活动排序 / 置顶 / 面板 | 有 | 有(活动规则是「升到第一个非运行工作区之上」) |
|
|
63
|
-
| 入口位置 |
|
|
71
|
+
| 入口位置 | 插件页本组合包卡片(官方 Slot) | 侧栏标题行插 DOM(依赖 CSS Module 类名) |
|
|
64
72
|
| 路径迁移(改登记 / 搬目录 / 迁会话) | **没有** | 有(`rename` / `cp` / `rm` + 会话 fork) |
|
|
65
73
|
| 移除工作区 / 清理空工作区 | **没有** | 有(删注册表项,会话进「未分组」) |
|
|
66
74
|
| 打开工作区目录 | **没有** | 有(宿主起系统命令) |
|
|
@@ -68,18 +76,19 @@ dsh plugin --profile desktop add /path/to/packages/dsh-workspace-sort
|
|
|
68
76
|
## 已知限制
|
|
69
77
|
|
|
70
78
|
- 置顶存在本机 `prefs.json`,不随 DSH 跨机同步。
|
|
71
|
-
- 「按工作区」(非树形)分组下,容器空行会浮在它最活跃的子项目上方;不想要就把 `aggregate` 设成 `false
|
|
72
|
-
-
|
|
79
|
+
- 「按工作区」(非树形)分组下,容器空行会浮在它最活跃的子项目上方;不想要就把 `aggregate` 设成 `false`(这一项同时决定子会话「等你输入」会不会抬起容器)。
|
|
80
|
+
- 「等你输入」只认 `approval` / `plan-review` / `question` 三种 kind,与内核侧栏的可见等待标记一致;其他 kind 不排前。
|
|
81
|
+
- 依赖客户端服务的内部形状(`ctx.workspaces.list`、`ctx.sessions.list.byId` 的 `updatedAt` / `running` / `blank`、`ctx.uiSession.pendingInteractions`)。DSH 改这些时插件要跟着改,`engines.dsh` 只声明到 0.2.x 就是这个意思。
|
|
73
82
|
- 顺序写进宿主,是全局行为,不是某个窗口的视图偏好。
|
|
74
83
|
|
|
75
84
|
## 开发
|
|
76
85
|
|
|
77
86
|
```sh
|
|
78
87
|
npm run build # src/sort.js 内联进 src/client.js → lib/client.js
|
|
79
|
-
npm test # node --test
|
|
88
|
+
npm test # node --test:纯规则 13 例 + 浏览器半边等待排序 5 例
|
|
80
89
|
```
|
|
81
90
|
|
|
82
|
-
`src/sort.js` 是纯函数(可测);`src/client.js` 是浏览器半边(引擎 + 两个 Slot 组件);`index.js`
|
|
91
|
+
`src/sort.js` 是纯函数(可测);`src/client.js` 是浏览器半边(引擎 + 两个 Slot 组件);`index.js` 是宿主半边(Config、prefs 文件、两条路由、日志)。没有打包器。`lib/client.js` 是跟踪的构建产物,改 `src/client.js` 或 `src/sort.js` 后要重建再提交。
|
|
83
92
|
|
|
84
93
|
## 许可
|
|
85
94
|
|
package/cordis.patch.yml
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
# The dsh-workspace-sort bundle patch: one row over the profile root.
|
|
2
2
|
#
|
|
3
|
-
# The row carries both halves. The Host half
|
|
4
|
-
#
|
|
5
|
-
# plus the two rule switches on `/dsh-workspace-sort/api/prefs` into
|
|
3
|
+
# The row carries both halves. The Host half persists the pins plus the two rule
|
|
4
|
+
# switches on `/dsh-workspace-sort/api/prefs` into
|
|
6
5
|
# `$DSH_HOME/workspace-sort/prefs.json` (never localStorage: the desktop Web
|
|
7
|
-
# server binds an ephemeral port, so the page origin changes on every restart)
|
|
6
|
+
# server binds an ephemeral port, so the page origin changes on every restart),
|
|
7
|
+
# and keeps the last reorder report on `/dsh-workspace-sort/api/state` for
|
|
8
|
+
# `curl` diagnostics.
|
|
9
|
+
#
|
|
8
10
|
# The browser half
|
|
9
11
|
# (`dsh.client.platform: web`) sorts the sidebar Workspaces by their newest
|
|
10
|
-
# human prompt
|
|
11
|
-
# `workspaces.insertBefore` command, so
|
|
12
|
-
# drag.
|
|
12
|
+
# human prompt, puts a Workspace that is waiting for the user's input first, and
|
|
13
|
+
# writes that order through the official `workspaces.insertBefore` command, so
|
|
14
|
+
# the order is Host-durable exactly like a drag.
|
|
13
15
|
#
|
|
14
|
-
# Every knob is optional and lives here, not in the browser bundle
|
|
15
|
-
#
|
|
16
|
-
#
|
|
16
|
+
# Every knob is optional and lives here, not in the browser bundle. All three
|
|
17
|
+
# are `.volatile()` Host Config fields: the Host reads them through live
|
|
18
|
+
# `{ get() }` references and the browser half through `SyncedConfig` refs, so a
|
|
19
|
+
# change applies without a restart or a page reload.
|
|
20
|
+
# enabled false stops the browser half from sorting; the order is left
|
|
21
|
+
# exactly as it is. Both Host routes stay mounted, so the pins keep
|
|
22
|
+
# working and the switch can be turned back on live.
|
|
17
23
|
# aggregate true (default) ranks a container Workspace by its whole subtree;
|
|
18
24
|
# false ranks it by its own Sessions only, which makes container
|
|
19
25
|
# folders such as Code/Mubea sink to the bottom.
|
package/index.js
CHANGED
|
@@ -4,11 +4,9 @@
|
|
|
4
4
|
* The ordering itself is a Client job: only the browser holds both the
|
|
5
5
|
* Workspace order (`ctx.workspaces.list`) and the Session summaries whose
|
|
6
6
|
* `updatedAt` is the last human prompt, and only the browser can call the
|
|
7
|
-
* durable `workspaces.insertBefore`. The Host owes the browser
|
|
7
|
+
* durable `workspaces.insertBefore`. The Host owes the browser two things and
|
|
8
8
|
* nothing else:
|
|
9
9
|
*
|
|
10
|
-
* * the resolved knobs (`GET /dsh-workspace-sort/api/state`), so defaults live
|
|
11
|
-
* in the profile instead of the bundle;
|
|
12
10
|
* * the user's pins and rule switches, persisted as plain JSON under
|
|
13
11
|
* `$DSH_HOME/workspace-sort/prefs.json` (`GET` on the state route,
|
|
14
12
|
* `POST /dsh-workspace-sort/api/prefs` to write). They are stored here
|
|
@@ -18,14 +16,23 @@
|
|
|
18
16
|
* * an audit trail: the last reorder decision is kept in memory for `GET`, and
|
|
19
17
|
* every applied reorder logs one line.
|
|
20
18
|
*
|
|
19
|
+
* The sorting knobs are not a route: they are this package's {@link Config},
|
|
20
|
+
* whose fields are all `.volatile()`. The Loader hands `apply` live `{ get() }`
|
|
21
|
+
* references and gives the browser face the same values as `SyncedConfig` refs,
|
|
22
|
+
* so a change made in the plugin page applies without a restart or a reload.
|
|
23
|
+
* The state route still echoes the resolved knobs for `curl` diagnostics, but
|
|
24
|
+
* the browser never depends on it for configuration.
|
|
25
|
+
*
|
|
21
26
|
* Deliberately absent: file moves, directory renames, Workspace removal,
|
|
22
27
|
* session migration, process spawning. This plugin changes ordering state only.
|
|
23
28
|
*
|
|
24
|
-
* `enabled: false`
|
|
25
|
-
*
|
|
29
|
+
* `enabled: false` leaves the order untouched: the browser half stops sorting.
|
|
30
|
+
* Both routes stay mounted, so the pins remain readable and writable while the
|
|
31
|
+
* switch is off and toggling it back on is itself a live config change.
|
|
26
32
|
*
|
|
27
33
|
* @module dsh-workspace-sort
|
|
28
34
|
*/
|
|
35
|
+
import z from '@deepseek-ai/schemastery'
|
|
29
36
|
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises'
|
|
30
37
|
import { homedir } from 'node:os'
|
|
31
38
|
import { dirname, join } from 'node:path'
|
|
@@ -34,6 +41,30 @@ import { dirname, join } from 'node:path'
|
|
|
34
41
|
export const STATE_ROUTE = '/dsh-workspace-sort/api/state'
|
|
35
42
|
export const PREFS_ROUTE = '/dsh-workspace-sort/api/prefs'
|
|
36
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Plugin config, edited live in the plugin page.
|
|
46
|
+
*
|
|
47
|
+
* Every field is `.volatile()` on purpose: the Loader then keeps the running
|
|
48
|
+
* references stable and commits new values in place, so changing a knob neither
|
|
49
|
+
* remounts this half nor reloads the page. Descriptions are the form labels.
|
|
50
|
+
*/
|
|
51
|
+
export const Config = z.object({
|
|
52
|
+
/** Sort at all; false stops the browser half and leaves the Host order exactly as it is. */
|
|
53
|
+
enabled: z.boolean().default(true).description('启用排序。关掉后浏览器半边停手,工作区顺序保持原样。').volatile(),
|
|
54
|
+
/** Rank a container Workspace by its whole subtree instead of its own Sessions. */
|
|
55
|
+
aggregate: z
|
|
56
|
+
.boolean()
|
|
57
|
+
.default(true)
|
|
58
|
+
.description('容器目录按整个子树汇总(默认开);关掉后只按目录自己的会话算。')
|
|
59
|
+
.volatile(),
|
|
60
|
+
/** Apply the order as soon as a page loads instead of waiting for the next prompt. */
|
|
61
|
+
initialSort: z
|
|
62
|
+
.boolean()
|
|
63
|
+
.default(true)
|
|
64
|
+
.description('页面加载时立即排序(默认开);关掉后等下一次提问或手动整理。')
|
|
65
|
+
.volatile(),
|
|
66
|
+
})
|
|
67
|
+
|
|
37
68
|
/** A reorder report or a pin set is small; anything larger is not this request. */
|
|
38
69
|
const MAX_BODY_BYTES = 64 * 1024
|
|
39
70
|
|
|
@@ -46,10 +77,16 @@ const DEFAULT_PREFS = { auto: true, runningFirst: false, pins: [] }
|
|
|
46
77
|
/**
|
|
47
78
|
* The part of the profile row's `config` block this plugin reads.
|
|
48
79
|
*
|
|
80
|
+
* A `.volatile()` field arrives as a live `{ get() }` reference; a plain
|
|
81
|
+
* boolean is also accepted, see {@link readFlag}.
|
|
82
|
+
*
|
|
83
|
+
* @typedef {object} VolatileFlag
|
|
84
|
+
* @property {() => boolean | undefined} get - the current value.
|
|
85
|
+
*
|
|
49
86
|
* @typedef {object} WorkspaceSortConfig
|
|
50
|
-
* @property {boolean} [enabled]
|
|
51
|
-
* @property {boolean} [aggregate] Rank a container by its whole subtree (default true).
|
|
52
|
-
* @property {boolean} [initialSort] Apply the order as soon as a page loads (default true).
|
|
87
|
+
* @property {VolatileFlag | boolean} [enabled] Sort at all; false leaves the order untouched.
|
|
88
|
+
* @property {VolatileFlag | boolean} [aggregate] Rank a container by its whole subtree (default true).
|
|
89
|
+
* @property {VolatileFlag | boolean} [initialSort] Apply the order as soon as a page loads (default true).
|
|
53
90
|
*/
|
|
54
91
|
|
|
55
92
|
/**
|
|
@@ -72,16 +109,21 @@ const DEFAULT_PREFS = { auto: true, runningFirst: false, pins: [] }
|
|
|
72
109
|
|
|
73
110
|
/**
|
|
74
111
|
* @param {HostContext} ctx - the plugin's Cordis context.
|
|
75
|
-
* @param {WorkspaceSortConfig} [config] - the
|
|
112
|
+
* @param {WorkspaceSortConfig} [config] - the row's `config` block; volatile
|
|
113
|
+
* fields arrive as live `{ get() }` references.
|
|
76
114
|
*/
|
|
77
115
|
export function apply(ctx, config = {}) {
|
|
78
116
|
if (config === null || typeof config !== 'object') config = {}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
117
|
+
/**
|
|
118
|
+
* The knobs as they are right now. Read on every use instead of once at
|
|
119
|
+
* mount: with `.volatile()` fields the Loader commits new values into the
|
|
120
|
+
* same references, so a cached copy would go stale.
|
|
121
|
+
*/
|
|
122
|
+
const resolvedConfig = () => ({
|
|
123
|
+
enabled: readFlag(config.enabled, true),
|
|
124
|
+
aggregate: readFlag(config.aggregate, true),
|
|
125
|
+
initialSort: readFlag(config.initialSort, true),
|
|
126
|
+
})
|
|
85
127
|
|
|
86
128
|
let prefs = { ...DEFAULT_PREFS }
|
|
87
129
|
let lastReport
|
|
@@ -92,6 +134,8 @@ export function apply(ctx, config = {}) {
|
|
|
92
134
|
|
|
93
135
|
/**
|
|
94
136
|
* Answer one request on the state route: knobs, prefs, and the last decision.
|
|
137
|
+
* The knobs are echoed for diagnostics only; the browser half gets them from
|
|
138
|
+
* its `SyncedConfig`.
|
|
95
139
|
*
|
|
96
140
|
* @param {import('node:http').IncomingMessage} request - the route request.
|
|
97
141
|
* @param {import('node:http').ServerResponse} response - the route response.
|
|
@@ -103,7 +147,7 @@ export function apply(ctx, config = {}) {
|
|
|
103
147
|
}
|
|
104
148
|
if (request.method === 'GET' || request.method === 'HEAD') {
|
|
105
149
|
await ready
|
|
106
|
-
sendJson(response, 200, { ok: true, config:
|
|
150
|
+
sendJson(response, 200, { ok: true, config: resolvedConfig(), prefs, lastReport })
|
|
107
151
|
return
|
|
108
152
|
}
|
|
109
153
|
if (request.method !== 'POST') {
|
|
@@ -125,7 +169,8 @@ export function apply(ctx, config = {}) {
|
|
|
125
169
|
if (body.hello === true) {
|
|
126
170
|
const options = body.options !== null && typeof body.options === 'object' ? body.options : {}
|
|
127
171
|
ctx.logger?.info?.(
|
|
128
|
-
'dsh-workspace-sort: client attached (aggregate=%s, initialSort=%s)',
|
|
172
|
+
'dsh-workspace-sort: client attached (enabled=%s, aggregate=%s, initialSort=%s)',
|
|
173
|
+
options.enabled !== false,
|
|
129
174
|
options.aggregate !== false,
|
|
130
175
|
options.initialSort !== false,
|
|
131
176
|
)
|
|
@@ -134,10 +179,11 @@ export function apply(ctx, config = {}) {
|
|
|
134
179
|
}
|
|
135
180
|
const moves = Array.isArray(body.moves) ? body.moves : []
|
|
136
181
|
ctx.logger?.info?.(
|
|
137
|
-
'dsh-workspace-sort: reordered %d workspace(s), newest activity %s%s',
|
|
182
|
+
'dsh-workspace-sort: reordered %d workspace(s), newest activity %s%s, %d waiting on you',
|
|
138
183
|
moves.length,
|
|
139
184
|
typeof body.newest === 'number' && body.newest > 0 ? new Date(body.newest).toISOString() : 'none',
|
|
140
185
|
body.manual === true ? ' (manual)' : '',
|
|
186
|
+
typeof body.waiting === 'number' && body.waiting > 0 ? body.waiting : 0,
|
|
141
187
|
)
|
|
142
188
|
sendJson(response, 200, { ok: true })
|
|
143
189
|
}
|
|
@@ -189,6 +235,29 @@ export function apply(ctx, config = {}) {
|
|
|
189
235
|
})
|
|
190
236
|
}
|
|
191
237
|
|
|
238
|
+
/**
|
|
239
|
+
* Read one config field.
|
|
240
|
+
*
|
|
241
|
+
* A `.volatile()` field is handed to `apply` as a live `{ get() }` reference
|
|
242
|
+
* whose value may still be absent; a plain boolean is accepted too so a direct
|
|
243
|
+
* `apply(ctx, {...})` (a test, or a Host that does not mark it volatile) reads
|
|
244
|
+
* the same way. Anything unusable falls back to the field default.
|
|
245
|
+
*
|
|
246
|
+
* @param field - the config field as received.
|
|
247
|
+
* @param fallback - the documented default.
|
|
248
|
+
* @returns the effective boolean.
|
|
249
|
+
*/
|
|
250
|
+
function readFlag(field, fallback) {
|
|
251
|
+
if (field === undefined || field === null) return fallback
|
|
252
|
+
let value
|
|
253
|
+
try {
|
|
254
|
+
value = typeof field.get === 'function' ? field.get() : field
|
|
255
|
+
} catch {
|
|
256
|
+
return fallback
|
|
257
|
+
}
|
|
258
|
+
return typeof value === 'boolean' ? value : fallback
|
|
259
|
+
}
|
|
260
|
+
|
|
192
261
|
/**
|
|
193
262
|
* Where this plugin keeps its own small state file.
|
|
194
263
|
*
|
package/lib/client.js
CHANGED
|
@@ -8,10 +8,12 @@
|
|
|
8
8
|
* every filesystem and destructive operation out of scope:
|
|
9
9
|
*
|
|
10
10
|
* * automatic order by each Workspace's newest human prompt (`updatedAt` on a
|
|
11
|
-
* non-blank Session),
|
|
11
|
+
* non-blank Session), with a Workspace waiting for your input ahead of the
|
|
12
|
+
* rest and — optionally — running Workspaces next;
|
|
12
13
|
* * pins that keep chosen Workspaces at the front, in pin order;
|
|
13
|
-
* * a
|
|
14
|
-
* last activity,
|
|
14
|
+
* * a card on this bundle's page in the Plugins view that opens a panel with
|
|
15
|
+
* session/running/waiting counts, the last activity, a name filter, the two
|
|
16
|
+
* rule switches and a "tidy now" button (the sidebar itself gets no icon);
|
|
15
17
|
* * every write goes through `ctx.workspaces.insertBefore`, the same durable
|
|
16
18
|
* command a Workspace drag uses.
|
|
17
19
|
*
|
|
@@ -22,10 +24,11 @@
|
|
|
22
24
|
* Guard rails:
|
|
23
25
|
*
|
|
24
26
|
* * only a human prompt (or an explicit button) starts a pass;
|
|
25
|
-
* * a manual drag wins until the next prompt;
|
|
27
|
+
* * a manual drag wins until the next prompt or a Session starts waiting;
|
|
26
28
|
* * one pass at a time, and a pass that finds the order in place writes nothing;
|
|
27
|
-
* * the
|
|
28
|
-
*
|
|
29
|
+
* * the knobs arrive as Host-synced `SyncedConfig` refs and are re-read live,
|
|
30
|
+
* so a config change stops or restarts the engine without a page reload;
|
|
31
|
+
* * `ctx.uiSession.pendingInteractions` is the authority for "waiting on you".
|
|
29
32
|
*
|
|
30
33
|
* `src/sort.js` (inlined by `scripts/build-client.mjs`) holds the pure rules.
|
|
31
34
|
*/
|
|
@@ -53,6 +56,10 @@ window.__ModuleLoader__.load({
|
|
|
53
56
|
* * a Session summary carries `updatedAt` = the persisted last *human* prompt
|
|
54
57
|
* time (opening a Session or an assistant reply never advances it) and
|
|
55
58
|
* `blank` = the unsent New Session draft, which is not activity;
|
|
59
|
+
* * a Session can be **waiting for you**: `ctx.uiSession.pendingInteractions`
|
|
60
|
+
* reports the highest-precedence request (approval, plan review, question)
|
|
61
|
+
* that only a human can answer. A waiting Workspace outranks a running one,
|
|
62
|
+
* because it is the one that stops making progress until you look;
|
|
56
63
|
* * under **Group by → Workspace tree** the sidebar nests a Workspace below
|
|
57
64
|
* its nearest registered ancestor path and nothing else — nesting is
|
|
58
65
|
* derived from paths, so reordering the flat Host order reorders siblings.
|
|
@@ -117,10 +124,28 @@ function ownActivity(workspace, byId) {
|
|
|
117
124
|
* @returns Workspace id to activity timestamp; every input Workspace is present.
|
|
118
125
|
*/
|
|
119
126
|
function activityByWorkspace(workspaces, byId, options = {}) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
127
|
+
return bySubtree(workspaces, (workspace) => ownActivity(workspace, byId), Math.max, 0, options)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Fold one per-Workspace value over the Workspace's whole subtree.
|
|
132
|
+
*
|
|
133
|
+
* This is the shared shape behind both sort keys: activity takes the newest
|
|
134
|
+
* stamp of the subtree, waiting takes the number of waiting Sessions. With
|
|
135
|
+
* `aggregate: false` a container keeps its own value, so a descendant never
|
|
136
|
+
* lifts it.
|
|
137
|
+
*
|
|
138
|
+
* @param workspaces - Workspaces in Host order.
|
|
139
|
+
* @param own - the Workspace's own value.
|
|
140
|
+
* @param merge - combines a folded value with one child's folded value.
|
|
141
|
+
* @param empty - the accumulator before any value is merged.
|
|
142
|
+
* @param options - `aggregate: false` disables the subtree fold.
|
|
143
|
+
* @returns Workspace id to folded value; every input Workspace is present.
|
|
144
|
+
*/
|
|
145
|
+
function bySubtree(workspaces, own, merge, empty, options = {}) {
|
|
146
|
+
const values = new Map()
|
|
147
|
+
for (const workspace of workspaces) values.set(workspace.workspaceId, own(workspace))
|
|
148
|
+
if (options.aggregate === false) return values
|
|
124
149
|
|
|
125
150
|
const paths = workspaces.map((workspace) => workspace.path)
|
|
126
151
|
const children = new Map()
|
|
@@ -136,13 +161,13 @@ function activityByWorkspace(workspaces, byId, options = {}) {
|
|
|
136
161
|
const cached = memo.get(workspace.workspaceId)
|
|
137
162
|
if (cached !== undefined) return cached
|
|
138
163
|
// No cycle is possible: a parent path is strictly shorter than its child's.
|
|
139
|
-
let
|
|
140
|
-
for (const child of children.get(workspace.path) ?? [])
|
|
141
|
-
memo.set(workspace.workspaceId,
|
|
142
|
-
return
|
|
164
|
+
let value = values.get(workspace.workspaceId) ?? empty
|
|
165
|
+
for (const child of children.get(workspace.path) ?? []) value = merge(value, subtree(child))
|
|
166
|
+
memo.set(workspace.workspaceId, value)
|
|
167
|
+
return value
|
|
143
168
|
}
|
|
144
|
-
for (const workspace of workspaces)
|
|
145
|
-
return
|
|
169
|
+
for (const workspace of workspaces) values.set(workspace.workspaceId, subtree(workspace))
|
|
170
|
+
return values
|
|
146
171
|
}
|
|
147
172
|
|
|
148
173
|
/**
|
|
@@ -158,24 +183,92 @@ function isRunning(workspace, byId) {
|
|
|
158
183
|
return false
|
|
159
184
|
}
|
|
160
185
|
|
|
186
|
+
/**
|
|
187
|
+
* Pending-interaction kinds that mean "this Session is waiting for your input".
|
|
188
|
+
*
|
|
189
|
+
* Mirrors the shipped sidebar's `visiblePendingKind`: only these three kinds get
|
|
190
|
+
* a visible waiting marker. A domain may publish other kinds, such as a plan
|
|
191
|
+
* that is still being generated, which are not the user's turn to act on.
|
|
192
|
+
*/
|
|
193
|
+
const WAITING_KINDS = Object.freeze(['approval', 'plan-review', 'question'])
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Whether one pending-interaction kind is the user's turn to act.
|
|
197
|
+
*
|
|
198
|
+
* @param kind - the domain-owned `kind` string.
|
|
199
|
+
* @returns true for {@link WAITING_KINDS}.
|
|
200
|
+
*/
|
|
201
|
+
function isWaitingKind(kind) {
|
|
202
|
+
return typeof kind === 'string' && WAITING_KINDS.includes(kind)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* The pending interaction for one Session, accepting the Map the Client publishes
|
|
207
|
+
* and a plain object for callers that do not have a Map.
|
|
208
|
+
*
|
|
209
|
+
* @param pending - `ctx.uiSession.pendingInteractions` snapshot.
|
|
210
|
+
* @param sessionId - the Session id to look up.
|
|
211
|
+
* @returns the interaction, or undefined.
|
|
212
|
+
*/
|
|
213
|
+
function pendingOf(pending, sessionId) {
|
|
214
|
+
if (pending === undefined || pending === null) return undefined
|
|
215
|
+
if (typeof pending.get === 'function') return pending.get(sessionId)
|
|
216
|
+
return pending[sessionId]
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* How many of this Workspace's own Sessions are waiting for the user.
|
|
221
|
+
*
|
|
222
|
+
* @param workspace - the Workspace row.
|
|
223
|
+
* @param pending - `ctx.uiSession.pendingInteractions` snapshot.
|
|
224
|
+
* @returns the number of member Sessions whose pending kind is visible.
|
|
225
|
+
*/
|
|
226
|
+
function ownWaitingCount(workspace, pending) {
|
|
227
|
+
const ids = Array.isArray(workspace?.sessionIds) ? workspace.sessionIds : []
|
|
228
|
+
let count = 0
|
|
229
|
+
for (const id of ids) if (isWaitingKind(pendingOf(pending, id)?.kind)) count += 1
|
|
230
|
+
return count
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Waiting Sessions per Workspace, optionally aggregated over descendants.
|
|
235
|
+
*
|
|
236
|
+
* A container folder that holds a waiting Session lifts with its subtree, for
|
|
237
|
+
* the same reason activity does: it is the group a user would look under. With
|
|
238
|
+
* `aggregate: false` only a Workspace's own Sessions count.
|
|
239
|
+
*
|
|
240
|
+
* @param workspaces - Workspaces in Host order.
|
|
241
|
+
* @param pending - `ctx.uiSession.pendingInteractions` snapshot.
|
|
242
|
+
* @param options - `aggregate: false` disables the subtree fold.
|
|
243
|
+
* @returns Workspace id to waiting count; every input Workspace is present.
|
|
244
|
+
*/
|
|
245
|
+
function waitingByWorkspace(workspaces, pending, options = {}) {
|
|
246
|
+
return bySubtree(workspaces, (workspace) => ownWaitingCount(workspace, pending), (left, right) => left + right, 0, options)
|
|
247
|
+
}
|
|
248
|
+
|
|
161
249
|
/**
|
|
162
250
|
* The Workspace ids in display order.
|
|
163
251
|
*
|
|
164
|
-
* Pinned Workspaces keep their pin order at the front
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
252
|
+
* Pinned Workspaces keep their pin order at the front. The unpinned remainder is
|
|
253
|
+
* ranked by, in order: a Session waiting for the user, a running Session (only
|
|
254
|
+
* with `runningFirst`), the newest prompt, then the current index. A waiting
|
|
255
|
+
* Workspace therefore outranks a merely busy one: an approval prompt is the
|
|
256
|
+
* thing that actually needs a click. `waitingFirst: false` disables the first
|
|
257
|
+
* key. Ties keep the current relative order, which is what keeps an untouched
|
|
258
|
+
* Workspace from wandering between two runs.
|
|
169
259
|
*
|
|
170
260
|
* @param workspaces - Workspaces in Host order.
|
|
171
261
|
* @param byId - Session summaries keyed by Session id.
|
|
172
|
-
* @param options - `aggregate` (forwarded), `pins` in pin order, `runningFirst
|
|
262
|
+
* @param options - `aggregate` (forwarded), `pins` in pin order, `runningFirst`,
|
|
263
|
+
* `waitingFirst`, `pending`.
|
|
173
264
|
* @returns Workspace ids sorted for display.
|
|
174
265
|
*/
|
|
175
266
|
function desiredOrder(workspaces, byId, options = {}) {
|
|
176
267
|
const activity = activityByWorkspace(workspaces, byId, options)
|
|
268
|
+
const waiting = waitingByWorkspace(workspaces, options.pending, options)
|
|
177
269
|
const pins = Array.isArray(options.pins) ? options.pins : []
|
|
178
270
|
const runningFirst = options.runningFirst === true
|
|
271
|
+
const waitingFirst = options.waitingFirst !== false
|
|
179
272
|
const known = new Map(workspaces.map((workspace) => [workspace.workspaceId, workspace]))
|
|
180
273
|
const pinnedRows = pins.map((id) => known.get(id)).filter((workspace) => workspace !== undefined)
|
|
181
274
|
const pinnedIds = new Set(pinnedRows.map((workspace) => workspace.workspaceId))
|
|
@@ -184,12 +277,16 @@ function desiredOrder(workspaces, byId, options = {}) {
|
|
|
184
277
|
workspace,
|
|
185
278
|
index,
|
|
186
279
|
score: activity.get(workspace.workspaceId) ?? 0,
|
|
280
|
+
waiting: waitingFirst && (waiting.get(workspace.workspaceId) ?? 0) > 0,
|
|
187
281
|
running: runningFirst && isRunning(workspace, byId),
|
|
188
282
|
}))
|
|
189
283
|
.filter((row) => !pinnedIds.has(row.workspace.workspaceId))
|
|
190
284
|
.sort(
|
|
191
285
|
(left, right) =>
|
|
192
|
-
Number(right.
|
|
286
|
+
Number(right.waiting) - Number(left.waiting) ||
|
|
287
|
+
Number(right.running) - Number(left.running) ||
|
|
288
|
+
right.score - left.score ||
|
|
289
|
+
left.index - right.index,
|
|
193
290
|
)
|
|
194
291
|
return [...pinnedRows.map((workspace) => workspace.workspaceId), ...rest.map((row) => row.workspace.workspaceId)]
|
|
195
292
|
}
|
|
@@ -271,6 +368,68 @@ function newestActivity(activity) {
|
|
|
271
368
|
|
|
272
369
|
const DEFAULT_PREFS = { auto: true, runningFirst: false, pins: [] }
|
|
273
370
|
|
|
371
|
+
/**
|
|
372
|
+
* One Host-synced config field, as `@deepseek-ai/dsh-client-config` defines
|
|
373
|
+
* it: the plugin may read it at any time, the value may still be absent, and
|
|
374
|
+
* the Host never remounts the plugin to change it. Declared locally so this
|
|
375
|
+
* bundle carries no extra dependency.
|
|
376
|
+
*
|
|
377
|
+
* @template T
|
|
378
|
+
* @typedef {object} SyncedConfigRef
|
|
379
|
+
* @property {() => T | undefined} get - the current frozen value.
|
|
380
|
+
* @property {((listener: () => void) => () => void)} [subscribe] - change observer.
|
|
381
|
+
*
|
|
382
|
+
* @typedef {object} SyncedConfig
|
|
383
|
+
* @property {SyncedConfigRef<boolean>} [enabled]
|
|
384
|
+
* @property {SyncedConfigRef<boolean>} [aggregate]
|
|
385
|
+
* @property {SyncedConfigRef<boolean>} [initialSort]
|
|
386
|
+
*/
|
|
387
|
+
|
|
388
|
+
/** Stand-in when the shell did not mount `uiSession` (nothing can be waiting). */
|
|
389
|
+
const NO_PENDING = Object.freeze({
|
|
390
|
+
getSnapshot: () => new Map(),
|
|
391
|
+
subscribe: () => () => {},
|
|
392
|
+
})
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Read one config field, falling back when the Host sent no value.
|
|
396
|
+
*
|
|
397
|
+
* @param {SyncedConfigRef<boolean> | boolean | undefined} ref - the field.
|
|
398
|
+
* @param {boolean} fallback - the bundle default.
|
|
399
|
+
* @returns {boolean} the effective knob.
|
|
400
|
+
*/
|
|
401
|
+
function readConfigFlag(ref, fallback) {
|
|
402
|
+
if (ref === undefined || ref === null) return fallback
|
|
403
|
+
try {
|
|
404
|
+
const value = typeof ref.get === 'function' ? ref.get() : ref
|
|
405
|
+
return typeof value === 'boolean' ? value : fallback
|
|
406
|
+
} catch {
|
|
407
|
+
return fallback
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* The knobs as the Host has them right now.
|
|
413
|
+
*
|
|
414
|
+
* @param {SyncedConfig | undefined} config - the second `apply` argument.
|
|
415
|
+
* @returns {{enabled: boolean, aggregate: boolean, initialSort: boolean}} the knobs.
|
|
416
|
+
*/
|
|
417
|
+
function readOptions(config) {
|
|
418
|
+
return {
|
|
419
|
+
enabled: readConfigFlag(config?.enabled, DEFAULTS.enabled),
|
|
420
|
+
aggregate: readConfigFlag(config?.aggregate, DEFAULTS.aggregate),
|
|
421
|
+
initialSort: readConfigFlag(config?.initialSort, DEFAULTS.initialSort),
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/** Whether the pending-interaction snapshot holds a kind that needs the user. */
|
|
426
|
+
function hasWaiting(pending) {
|
|
427
|
+
if (pending === undefined || pending === null) return false
|
|
428
|
+
const values = typeof pending.values === 'function' ? pending.values() : Object.values(pending)
|
|
429
|
+
for (const interaction of values) if (isWaitingKind(interaction?.kind)) return true
|
|
430
|
+
return false
|
|
431
|
+
}
|
|
432
|
+
|
|
274
433
|
const DICT = {
|
|
275
434
|
zh: {
|
|
276
435
|
button: '工作区排序',
|
|
@@ -286,6 +445,7 @@ function newestActivity(activity) {
|
|
|
286
445
|
pinnedTag: '置顶',
|
|
287
446
|
sessions: '{n} 会话',
|
|
288
447
|
running: '{n} 运行中',
|
|
448
|
+
waiting: '{n} 等你输入',
|
|
289
449
|
idle: '无会话',
|
|
290
450
|
never: '从没用过',
|
|
291
451
|
minutes: '{n} 分钟前',
|
|
@@ -294,6 +454,12 @@ function newestActivity(activity) {
|
|
|
294
454
|
note: '只改侧栏顺序,不动文件与会话',
|
|
295
455
|
disabled: '宿主配置已停用自动排序,只能点「立即整理」',
|
|
296
456
|
ephemeral: '本次会话内的置顶与开关不会保存:宿主是旧版插件,重启一次宿主后即可落盘',
|
|
457
|
+
cardIntro: '侧栏不放入口图标;排序、置顶与规则开关都在这张卡片打开的面板里。',
|
|
458
|
+
openPanel: '打开排序面板',
|
|
459
|
+
autoOn: '自动排序已开',
|
|
460
|
+
autoOff: '自动排序已关',
|
|
461
|
+
runningOn: '运行中优先',
|
|
462
|
+
pinnedCount: '{n} 个置顶',
|
|
297
463
|
},
|
|
298
464
|
en: {
|
|
299
465
|
button: 'Workspace order',
|
|
@@ -309,6 +475,7 @@ function newestActivity(activity) {
|
|
|
309
475
|
pinnedTag: 'Pinned',
|
|
310
476
|
sessions: '{n} sessions',
|
|
311
477
|
running: '{n} running',
|
|
478
|
+
waiting: '{n} waiting on you',
|
|
312
479
|
idle: 'No sessions',
|
|
313
480
|
never: 'Never used',
|
|
314
481
|
minutes: '{n} min ago',
|
|
@@ -317,6 +484,12 @@ function newestActivity(activity) {
|
|
|
317
484
|
note: 'Reorders the sidebar only; it never touches files or sessions',
|
|
318
485
|
disabled: 'Disabled in the Host config; only "Tidy now" works',
|
|
319
486
|
ephemeral: 'Pins and switches are session-only here: the Host runs the previous build, restart it once to persist them',
|
|
487
|
+
cardIntro: 'No sidebar icon: open the panel from this card to sort, pin and switch the rules.',
|
|
488
|
+
openPanel: 'Open the sorting panel',
|
|
489
|
+
autoOn: 'Auto-sort on',
|
|
490
|
+
autoOff: 'Auto-sort off',
|
|
491
|
+
runningOn: 'Running first',
|
|
492
|
+
pinnedCount: '{n} pinned',
|
|
320
493
|
},
|
|
321
494
|
}
|
|
322
495
|
|
|
@@ -345,6 +518,13 @@ function newestActivity(activity) {
|
|
|
345
518
|
.wss-action:hover{background:var(--dsw-alias-interactive-bg-hover)}
|
|
346
519
|
.wss-note{padding:8px 2px 0;color:var(--dsw-alias-label-secondary);font-size:11px;line-height:16px}
|
|
347
520
|
.wss-warn{color:var(--dsw-alias-state-warn-primary)}
|
|
521
|
+
.wss-card{display:flex;align-items:flex-start;gap:12px;justify-content:space-between;box-sizing:border-box;padding:12px 14px;margin:0 0 12px;border:1px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-lg,10px);background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary)}
|
|
522
|
+
.wss-card-text{min-width:0}
|
|
523
|
+
.wss-card-title{font-size:13.5px;font-weight:600;margin:0 0 4px}
|
|
524
|
+
.wss-card-note{font-size:12px;line-height:1.55;color:var(--dsw-alias-label-secondary)}
|
|
525
|
+
.wss-card-rules{margin-top:6px;font-size:11.5px;color:var(--dsw-alias-label-secondary)}
|
|
526
|
+
.wss-card-btn{display:inline-flex;align-items:center;gap:6px;height:30px;padding:0 12px;flex:none;border:1px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-sm,6px);background:transparent;color:var(--dsw-alias-label-primary);font-size:12.5px;cursor:pointer}
|
|
527
|
+
.wss-card-btn:hover{background:var(--dsw-alias-interactive-bg-hover)}
|
|
348
528
|
`
|
|
349
529
|
|
|
350
530
|
/**
|
|
@@ -462,9 +642,12 @@ function newestActivity(activity) {
|
|
|
462
642
|
}
|
|
463
643
|
|
|
464
644
|
return {
|
|
465
|
-
inject: ['workspaces', 'sessions', 'locale', 'slots'],
|
|
466
|
-
|
|
467
|
-
|
|
645
|
+
inject: ['workspaces', 'sessions', 'locale', 'slots', 'uiSession'],
|
|
646
|
+
/**
|
|
647
|
+
* @param ctx - the Client Cordis context.
|
|
648
|
+
* @param {SyncedConfig} [config] - the Host-synced knobs; one ref per field.
|
|
649
|
+
*/
|
|
650
|
+
apply(ctx, config) {
|
|
468
651
|
let timer
|
|
469
652
|
let disposed = false
|
|
470
653
|
/** Timestamp of our own last durable write, to recognise its echo. */
|
|
@@ -485,11 +668,31 @@ function newestActivity(activity) {
|
|
|
485
668
|
let knownIds = []
|
|
486
669
|
|
|
487
670
|
const prefs = createStore({ ...DEFAULT_PREFS })
|
|
671
|
+
/**
|
|
672
|
+
* The live knobs. A Host-synced config field is a reference that mutates
|
|
673
|
+
* in place, so this store is what makes React re-render after a change
|
|
674
|
+
* and what `pass()` reads at operation time.
|
|
675
|
+
*/
|
|
676
|
+
const settings = createStore(readOptions(config))
|
|
488
677
|
/** Whether this Host half exposes the prefs route; an older build does not. */
|
|
489
678
|
const capabilities = createStore({ persist: false })
|
|
490
679
|
const panel = createStore({ open: false })
|
|
491
680
|
const t = () => ctx.locale.bind(NS)
|
|
492
681
|
|
|
682
|
+
/**
|
|
683
|
+
* The pending-interaction snapshot, or an empty one when the shell did
|
|
684
|
+
* not mount `uiSession`.
|
|
685
|
+
*
|
|
686
|
+
* @returns {ReadonlyMap<string, {kind?: string}>} the snapshot.
|
|
687
|
+
*/
|
|
688
|
+
const readPending = () => {
|
|
689
|
+
try {
|
|
690
|
+
return ctx.uiSession?.pendingInteractions?.getSnapshot?.() ?? NO_PENDING.getSnapshot()
|
|
691
|
+
} catch {
|
|
692
|
+
return NO_PENDING.getSnapshot()
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
|
|
493
696
|
const readItems = () => {
|
|
494
697
|
try {
|
|
495
698
|
const snapshot = ctx.workspaces?.list?.getSnapshot?.()
|
|
@@ -608,6 +811,7 @@ function newestActivity(activity) {
|
|
|
608
811
|
* @returns true when this pass wrote a durable order.
|
|
609
812
|
*/
|
|
610
813
|
const pass = async (manual) => {
|
|
814
|
+
const options = settings.get()
|
|
611
815
|
if (disposed || options.enabled === false) return false
|
|
612
816
|
const items = readItems()
|
|
613
817
|
if (items.length < 2) return false
|
|
@@ -616,16 +820,23 @@ function newestActivity(activity) {
|
|
|
616
820
|
const state = prefs.get()
|
|
617
821
|
if (!manual && !state.auto) return false
|
|
618
822
|
|
|
823
|
+
const pending = readPending()
|
|
619
824
|
const shared = {
|
|
620
825
|
aggregate: options.aggregate !== false,
|
|
621
826
|
pins: state.pins,
|
|
622
827
|
runningFirst: state.runningFirst,
|
|
828
|
+
pending,
|
|
623
829
|
}
|
|
624
830
|
const current = items.map((workspace) => workspace.workspaceId)
|
|
625
831
|
prunePins(current)
|
|
626
832
|
const desired = desiredOrder(items, byId, shared)
|
|
627
833
|
const newest = newestActivity(activityByWorkspace(items, byId, shared))
|
|
628
|
-
|
|
834
|
+
// Waiting Workspaces have no activity of their own to report: a Session
|
|
835
|
+
// that asks for approval may never have prompted at all, or only did so
|
|
836
|
+
// long ago, so the waiting count has to keep the pass alive here.
|
|
837
|
+
let waiting = 0
|
|
838
|
+
for (const count of waitingByWorkspace(items, pending, shared).values()) waiting += count
|
|
839
|
+
if (newest === 0 && waiting === 0) {
|
|
629
840
|
// Before the baseline pass the summary store may still be filling in;
|
|
630
841
|
// an all-zero ranking would only reproduce the current index order.
|
|
631
842
|
return false
|
|
@@ -643,12 +854,14 @@ function newestActivity(activity) {
|
|
|
643
854
|
return false
|
|
644
855
|
}
|
|
645
856
|
for (const move of moves) {
|
|
857
|
+
// A config change can stop the engine mid-pass; do not keep writing.
|
|
858
|
+
if (disposed || settings.get().enabled === false) return false
|
|
646
859
|
selfWriteAt = Date.now()
|
|
647
860
|
await ctx.workspaces.insertBefore(move.id, move.before)
|
|
648
861
|
}
|
|
649
862
|
sorted = true
|
|
650
863
|
manualHold = false
|
|
651
|
-
report({ current, desired, moves, newest, manual: manual === true })
|
|
864
|
+
report({ current, desired, moves, newest, waiting, manual: manual === true })
|
|
652
865
|
return true
|
|
653
866
|
}
|
|
654
867
|
|
|
@@ -694,7 +907,13 @@ function newestActivity(activity) {
|
|
|
694
907
|
}
|
|
695
908
|
|
|
696
909
|
/**
|
|
697
|
-
* Read
|
|
910
|
+
* Read the persisted prefs from the Host half.
|
|
911
|
+
*
|
|
912
|
+
* The knobs do NOT come from this route any more: they arrive as
|
|
913
|
+
* `SyncedConfig` refs in `apply`. A Host that cannot be reached costs the
|
|
914
|
+
* persisted pins, not the sorting itself — the bundle keeps its defaults
|
|
915
|
+
* and in-memory prefs instead of going inert, which is what the old
|
|
916
|
+
* startup handshake did.
|
|
698
917
|
*/
|
|
699
918
|
const start = async () => {
|
|
700
919
|
let body
|
|
@@ -702,25 +921,19 @@ function newestActivity(activity) {
|
|
|
702
921
|
const response = await fetch(STATE_ROUTE, { headers: { accept: 'application/json' } })
|
|
703
922
|
body = response.ok ? await response.json() : undefined
|
|
704
923
|
} catch (error) {
|
|
705
|
-
warn('host half unreachable;
|
|
706
|
-
options = { ...options, enabled: false }
|
|
924
|
+
warn('host half unreachable; keeping pins in memory', error)
|
|
707
925
|
return
|
|
708
926
|
}
|
|
709
|
-
if (body === undefined || body === null || body.ok !== true
|
|
710
|
-
warn('host half did not answer;
|
|
711
|
-
options = { ...options, enabled: false }
|
|
927
|
+
if (body === undefined || body === null || body.ok !== true) {
|
|
928
|
+
warn('host half did not answer; keeping pins in memory')
|
|
712
929
|
return
|
|
713
930
|
}
|
|
714
|
-
options = { ...DEFAULTS, ...body.config }
|
|
715
|
-
if (disposed || options.enabled === false) return
|
|
716
|
-
// An older Host half answers without `prefs`; keep pins in memory then,
|
|
717
|
-
// instead of posting to a route that does not exist yet.
|
|
718
931
|
if (body.prefs !== undefined && body.prefs !== null) {
|
|
719
932
|
prefs.set(sanitizePrefs(body.prefs))
|
|
720
933
|
capabilities.set({ persist: true })
|
|
721
934
|
}
|
|
722
|
-
report({ hello: true, options })
|
|
723
|
-
if (
|
|
935
|
+
report({ hello: true, options: settings.get() })
|
|
936
|
+
if (settings.get().enabled && settings.get().initialSort) schedule(0)
|
|
724
937
|
}
|
|
725
938
|
|
|
726
939
|
// ------------------------------------------------------------ styles
|
|
@@ -775,6 +988,42 @@ function newestActivity(activity) {
|
|
|
775
988
|
)
|
|
776
989
|
// A pin or a rule toggle changes the target order: re-sort at once.
|
|
777
990
|
offs.push(prefs.subscribe(() => request(true)))
|
|
991
|
+
// The authoritative "waiting on you" source. Both entering and
|
|
992
|
+
// leaving the state re-sort; the debounce absorbs a request being
|
|
993
|
+
// replaced by the next one. A waiting Session outranks the user's
|
|
994
|
+
// last manual drag, so that hold is released on entry.
|
|
995
|
+
if (typeof ctx.uiSession?.pendingInteractions?.subscribe === 'function') {
|
|
996
|
+
offs.push(
|
|
997
|
+
ctx.uiSession.pendingInteractions.subscribe(() => {
|
|
998
|
+
if (hasWaiting(readPending())) manualHold = false
|
|
999
|
+
schedule()
|
|
1000
|
+
}),
|
|
1001
|
+
)
|
|
1002
|
+
}
|
|
1003
|
+
// Host-synced knobs change live: a disable stops the engine, any
|
|
1004
|
+
// other change re-runs the pass. No remount or page reload.
|
|
1005
|
+
for (const field of ['enabled', 'aggregate', 'initialSort']) {
|
|
1006
|
+
const ref = config?.[field]
|
|
1007
|
+
if (ref === undefined || ref === null || typeof ref.subscribe !== 'function') continue
|
|
1008
|
+
offs.push(
|
|
1009
|
+
ref.subscribe(() => {
|
|
1010
|
+
const before = settings.get()
|
|
1011
|
+
const next = readOptions(config)
|
|
1012
|
+
settings.set(next)
|
|
1013
|
+
if (next.enabled === false) {
|
|
1014
|
+
wanted = false
|
|
1015
|
+
forced = false
|
|
1016
|
+
if (timer !== undefined) clearTimeout(timer)
|
|
1017
|
+
timer = undefined
|
|
1018
|
+
return
|
|
1019
|
+
}
|
|
1020
|
+
if (!before.enabled || before.aggregate !== next.aggregate) {
|
|
1021
|
+
manualHold = false
|
|
1022
|
+
schedule()
|
|
1023
|
+
}
|
|
1024
|
+
}),
|
|
1025
|
+
)
|
|
1026
|
+
}
|
|
778
1027
|
} catch (error) {
|
|
779
1028
|
warn('could not follow the sidebar stores', error)
|
|
780
1029
|
}
|
|
@@ -797,10 +1046,10 @@ function newestActivity(activity) {
|
|
|
797
1046
|
/**
|
|
798
1047
|
* One Workspace row: pin toggle, name, and its activity summary.
|
|
799
1048
|
*
|
|
800
|
-
* @param props - `{workspace, byId, pinned}` plus the resolved `t`.
|
|
1049
|
+
* @param props - `{workspace, byId, pending, pinned}` plus the resolved `t`.
|
|
801
1050
|
* @returns the row element.
|
|
802
1051
|
*/
|
|
803
|
-
function Row({ workspace, byId, pinned, tr }) {
|
|
1052
|
+
function Row({ workspace, byId, pending, pinned, tr }) {
|
|
804
1053
|
const members = Array.isArray(workspace.sessionIds) ? workspace.sessionIds : []
|
|
805
1054
|
let running = 0
|
|
806
1055
|
let last = 0
|
|
@@ -810,6 +1059,7 @@ function newestActivity(activity) {
|
|
|
810
1059
|
if (summary.running === true) running += 1
|
|
811
1060
|
if (summary.blank !== true && typeof summary.updatedAt === 'number' && summary.updatedAt > last) last = summary.updatedAt
|
|
812
1061
|
}
|
|
1062
|
+
const waiting = ownWaitingCount(workspace, pending)
|
|
813
1063
|
const meta = members.length === 0 ? tr('idle') : tr('sessions', { n: members.length })
|
|
814
1064
|
const when = last === 0 ? tr('never') : relativeTime(last, tr)
|
|
815
1065
|
return h(
|
|
@@ -834,6 +1084,7 @@ function newestActivity(activity) {
|
|
|
834
1084
|
h(PinIcon, { pinned }),
|
|
835
1085
|
),
|
|
836
1086
|
h('span', { className: 'wss-name', title: workspace.path }, workspace.title || workspace.path),
|
|
1087
|
+
waiting > 0 ? h('span', { className: 'wss-tag' }, tr('waiting', { n: waiting })) : null,
|
|
837
1088
|
running > 0 ? h('span', { className: 'wss-tag' }, tr('running', { n: running })) : null,
|
|
838
1089
|
h('span', { className: 'wss-meta', title: when }, `${meta} · ${when}`),
|
|
839
1090
|
)
|
|
@@ -847,8 +1098,10 @@ function newestActivity(activity) {
|
|
|
847
1098
|
const state = useStore(panel)
|
|
848
1099
|
const statePrefs = useStore(prefs)
|
|
849
1100
|
const capability = useStore(capabilities)
|
|
1101
|
+
const options = useStore(settings)
|
|
850
1102
|
const workspaceSnapshot = useSnapshot(ctx.workspaces.list)
|
|
851
1103
|
const sessionSnapshot = useSnapshot(ctx.sessions.list)
|
|
1104
|
+
const pendingSnapshot = useSnapshot(ctx.uiSession?.pendingInteractions ?? NO_PENDING)
|
|
852
1105
|
const [filter, setFilter] = React.useState('')
|
|
853
1106
|
React.useEffect(() => {
|
|
854
1107
|
if (!state.open) return undefined
|
|
@@ -927,6 +1180,7 @@ function newestActivity(activity) {
|
|
|
927
1180
|
key: workspace.workspaceId,
|
|
928
1181
|
workspace,
|
|
929
1182
|
byId: sessionSnapshot.byId ?? {},
|
|
1183
|
+
pending: pendingSnapshot,
|
|
930
1184
|
pinned: statePrefs.pins.includes(workspace.workspaceId),
|
|
931
1185
|
tr,
|
|
932
1186
|
}),
|
|
@@ -938,27 +1192,43 @@ function newestActivity(activity) {
|
|
|
938
1192
|
)
|
|
939
1193
|
}
|
|
940
1194
|
|
|
941
|
-
/**
|
|
942
|
-
|
|
943
|
-
|
|
1195
|
+
/**
|
|
1196
|
+
* The card on this bundle's page in the Plugins view, and the only entry
|
|
1197
|
+
* point to the panel — the sidebar deliberately gets no footer icon.
|
|
1198
|
+
*
|
|
1199
|
+
* `plugins.bundle.config` hands no form in; the card reads the shared
|
|
1200
|
+
* client stores directly.
|
|
1201
|
+
*/
|
|
1202
|
+
function BundleCard() {
|
|
1203
|
+
const tr = t()
|
|
1204
|
+
const statePrefs = useStore(prefs)
|
|
1205
|
+
const rules = []
|
|
1206
|
+
rules.push(statePrefs.auto ? tr('autoOn') : tr('autoOff'))
|
|
1207
|
+
if (statePrefs.runningFirst) rules.push(tr('runningOn'))
|
|
1208
|
+
if (statePrefs.pins.length > 0) rules.push(tr('pinnedCount', { n: statePrefs.pins.length }))
|
|
944
1209
|
return h(
|
|
945
|
-
'
|
|
946
|
-
{
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
'
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
h(
|
|
1210
|
+
'div',
|
|
1211
|
+
{ className: 'wss-card' },
|
|
1212
|
+
h(
|
|
1213
|
+
'div',
|
|
1214
|
+
{ className: 'wss-card-text' },
|
|
1215
|
+
h('div', { className: 'wss-card-title' }, tr('title')),
|
|
1216
|
+
h('div', { className: 'wss-card-note' }, tr('cardIntro')),
|
|
1217
|
+
h('div', { className: 'wss-card-rules' }, rules.join(' · ')),
|
|
1218
|
+
),
|
|
1219
|
+
h(
|
|
1220
|
+
'button',
|
|
1221
|
+
{ type: 'button', className: 'wss-card-btn', onClick: () => panel.set({ open: true }) },
|
|
1222
|
+
h(SortIcon, null),
|
|
1223
|
+
tr('openPanel'),
|
|
1224
|
+
),
|
|
955
1225
|
)
|
|
956
1226
|
}
|
|
957
1227
|
|
|
958
|
-
ctx.slots.inject('
|
|
1228
|
+
ctx.slots.inject('plugins.bundle.config', () =>
|
|
959
1229
|
ctx.slots.register(
|
|
960
|
-
{ name: '
|
|
961
|
-
|
|
1230
|
+
{ name: 'plugins.bundle.config', key: '@cooper-zhuang/dsh-workspace-sort', inject: () => ({}) },
|
|
1231
|
+
BundleCard,
|
|
962
1232
|
),
|
|
963
1233
|
)
|
|
964
1234
|
ctx.slots.inject('shell.overlay', () =>
|
package/locale/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Workspace activity sort",
|
|
4
|
-
"description": "Reorders the sidebar workspaces by their most recent human prompt,
|
|
4
|
+
"description": "Reorders the sidebar workspaces by their most recent human prompt, puts workspaces waiting for your input first, aggregates a container folder over its whole subtree, and writes the order to the host."
|
|
5
5
|
}
|
|
6
6
|
}
|
package/locale/zh.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cooper-zhuang/dsh-workspace-sort",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"engines": {
|
|
32
32
|
"node": ">=20",
|
|
33
|
-
"dsh": "^0.2.1-0 || ^0.2.2-0"
|
|
33
|
+
"dsh": "^0.2.1-0 || ^0.2.2-0 || ^0.2.3-0"
|
|
34
34
|
},
|
|
35
35
|
"keywords": [
|
|
36
36
|
"dsh",
|
|
@@ -61,5 +61,11 @@
|
|
|
61
61
|
"@deepseek-ai/dsh-client-ui-session"
|
|
62
62
|
]
|
|
63
63
|
}
|
|
64
|
+
},
|
|
65
|
+
"dependencies": {
|
|
66
|
+
"@deepseek-ai/schemastery": "^3.18.5"
|
|
67
|
+
},
|
|
68
|
+
"peerDependencies": {
|
|
69
|
+
"@deepseek-ai/schemastery": "^3.18.5"
|
|
64
70
|
}
|
|
65
|
-
}
|
|
71
|
+
}
|