@ryuu-64/dsh-session-tools 0.6.0 → 0.7.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/README.md CHANGED
@@ -1,206 +1,68 @@
1
1
  # dsh-session-tools
2
2
 
3
- 让对话里的 AI 能**新建会话**、**给别的会话发消息**、**看看有哪些会话**,以及**等别的会话干完活**。
3
+ 让 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 中的 AI 新建会话、给其他会话派任务,并把结果带回来。
4
4
 
5
- 四个工具,`session_create`、`session_send`、`list_sessions`、`session_wait`。新会话会出现在左侧会话列表里,你可以打开并继续对话;想让它归到某个工作区下面也可以。
5
+ 适合把独立的调查或整理工作交给另一个会话,省去手动新建、复制背景、来回转述。新会话会出现在侧边栏,你可以随时打开,直接继续对话。
6
6
 
7
- 典型用法:你说"帮我开一个会话去查一下这件事"——AI 直接建好,不用你自己新建再复制粘贴。或者你已经有一个会话在跑,说"等它弄完把结果告诉我",AI 把活派过去,等它做完了再回来接着讲。
8
-
9
- ## session_create:新建会话
10
-
11
- | 参数 | 是否必填 | 说明 |
12
- |---|---|---|
13
- | `prompt` | 必填 | 新会话要做的第一件事。**新会话看不到当前这个会话**,所以要把背景写全。 |
14
- | `workspacePath` | 可选 | 工作区的完整路径。填了,新会话就归到这个工作区下面;不填就是未分组。 |
15
- | `title` | 可选 | 创建时固定的会话标题。优先使用非空标题;省略或只含空白时,从首条任务截取简短标题。 |
16
- | `wait` | 可选 | 默认不等。只有一种情况需要等:你要在新建的那个会话跑完第一轮之后才继续。 |
17
- | `timeoutMs` | 可选 | `wait=true` 的等待预算(毫秒),默认 60000,最多 300000。 |
18
-
19
- 做完返回新会话的名字、`sessionId` 和首条消息的 `messageId` 回执,你在左侧列表里就能看到它。投递成功后,等待超时、取消或读取错误都不会删除或停止独立目标会话。
20
-
21
- 新建或首次消息投递失败时,插件会尝试清理:如果已经确认附加到工作区,就调用 `detachSession` 解除归属;如果已经取得 Agent 句柄,就调用 `dispose` 释放它。清理中的异常会被忽略,工具仍返回最初的错误。
22
-
23
- DSH `0.1.5-rc.2` 的 [`dispose`](https://github.com/deepseek-ai/deepseek-harness/blob/fb2c4b9e698e30edb738bca4cf0618587db7d203/packages/core/agent-loop/src/index.ts#L576-L617) 尝试停止 Agent、关闭持久化句柄并移除运行时注册;[关闭句柄](https://github.com/deepseek-ai/deepseek-harness/blob/fb2c4b9e698e30edb738bca4cf0618587db7d203/packages/session/session-persistence/src/handle.ts#L111-L116)负责完成待写入数据并释放写所有权,不是删除持久化记录。因此,失败后不能保证完全回滚或不留记录,也不表示每种失败都会留下记录。插件不会为此额外删除会话数据。
24
-
25
- 缺省标题使用宿主公开的 `fallbackSessionTitle` 规范化和截取规则:清理控制字符、合并空白,再取前 5 个以空白分隔的词,最多 40 个 UTF-8 字节,不截断 Unicode 码点(中文同样按字节上限截取)。这两个上限来自官方 `dsh-base@0.1.5-rc.2` 标准配置。显式标题仍由宿主规范化,并受宿主的标题长度上限约束;若选定标题清理后没有可见内容,创建失败,不投递消息。
26
-
27
- 标题在首条消息投递前通过公开的重命名接口写入会话日志并固定,不额外调用模型;首条消息仍标记为 `source.kind=plugin`。后续对话不会自动改名,即使宿主启用了自动标题提供器。用户仍可手动改名;显式刷新标题则遵循宿主自己的刷新规则。
28
-
29
- ## session_send:给别的会话发消息
30
-
31
- | 参数 | 是否必填 | 说明 |
32
- |---|---|---|
33
- | `sessionId` | 必填 | 目标会话的 id,形如 `session-9311a0fb-65c7-4b04-b142-1444642a627e`。 |
34
- | `message` | 必填 | 要发的内容。对方看不到当前这个会话,所以要写清楚。 |
35
- | `wait` | 可选 | 默认不等:发出去就返回。填 `true` 就等对方把这条消息处理完,并把它的回答带回来。 |
36
- | `timeoutMs` | 可选 | 等多久(毫秒)。默认 60000(一分钟),最多 300000(五分钟)。等超了返回等待超时和同一回执,不猜测任务是否成功。 |
37
-
38
- 默认发出即返回 `sessionId` 与 `messageId`;`messageStatus` 区分仍在排队和已被轮次领取。它不表示已经执行成功。消息来源标记为插件,不会被当成是你本人打的字。目标会话如果没开着,会被自动打开再把消息排进去。
39
-
40
- 填了 `wait` 就观察这条消息的回执:根据宿主公开的持久 inbox 事件、消息接纳记录和 `turn/end` 关联到具体轮次,只读取那一轮的输出。A、B 分别进入两轮时,各自保留自己的回答;同一轮接纳多条消息时,共用该轮结果。会话空闲、消息离开队列、出现新的回答,都不能单独证明本条消息成功。
41
-
42
- ## session_wait:等别的会话干完
43
-
44
- 如果消息已经发出去了,或者那个会话本来就在忙,用这个等它收尾。
45
-
46
- | 参数 | 是否必填 | 说明 |
47
- |---|---|---|
48
- | `sessionId` | 必填 | 回执中的目标会话 id。 |
49
- | `messageId` | 可选 | `session_create` 或 `session_send` 返回的消息 id。要查询本次消息结果时必须一起传入。 |
50
- | `timeoutMs` | 可选 | 等多久(毫秒),默认 60000,最多 300000。 |
51
-
52
- 它只负责等和看:不会恢复会话、重发消息或打断目标。传入 `sessionId` 和 `messageId` 时返回 `scope=message`;目标关闭时从 JSONL 重建回执。如果保存的记录还只有排队或领取状态,立即如实返回,不替你启动目标。只传 `sessionId` 时返回 `scope=sessionOverview`,明确标为会话概况;其中的最新回答不是任何特定消息的结果。
53
-
54
- ### 等待结果与取消
55
-
56
- 三个等待入口统一默认 60 秒、最多 300 秒;省略或非正数使用默认值;类型不符及非有限数由参数校验拒绝。正的小数至少为 1 毫秒。预算从开始观察起计算,包括只读查询和结果读取,不包括审批或创建阶段。
57
-
58
- - `waitStatus=completed`:本次观察/读取已返回。还要看 `messageStatus`,它不等于消息成功
59
- - `waitStatus=timedOut`:等待预算耗尽
60
- - `waitStatus=callerCancelled`:调用方取消本次等待;不是目标轮次被取消
61
- - 后两种情况 `completed=false`,保留 `sessionId` 和 `messageId`,不自动重发、不取消目标,也不返回可能过时的答案。稍后把这两个字段一起传给 `session_wait`
62
-
63
- 消息回执的 `messageStatus`:
64
-
65
- | 状态 | 含义 |
66
- |---|---|
67
- | `queued` | 消息仍在收件队列中 |
68
- | `delivered` | 已被具体轮次领取,尚未记录该轮的终态;不保证模型已经接纳 |
69
- | `turnCompleted` | 同一消息已被模型接纳,且其所属轮次以 `completed` 结束;此时 `completed=true` |
70
- | `discarded` | 消息在队列中被删除、替换或清空,没有执行完成 |
71
- | `cancelled` | 所属轮次以 `aborted` 结束 |
72
- | `blocked` / `failed` | 所属轮次被阻止 / 执行出错 |
73
- | `interrupted` / `incomplete` | 宿主已记录中断修复 / 输出达到 token 上限 |
74
- | `unknown` | 缺少可靠归属证据、消息被改写而未接纳、身份复用或日志不能可靠解码 |
75
-
76
- `turnCompleted` 仅证明宿主轮次正常结束,**不证明业务任务成功**;例如测试是否通过仍需阅读结果。空文本可以是有效的空结果。输出采用 rc.2 的选择规则:所属轮次最后一个非空 assistant 内容;没有时才回退到该轮持久化 message/attempt 的流式文本,不读取后续轮次或旧答案。
77
-
78
- 回执投影通过公开 `sessionProjections` 注册,宿主可以保存其检查点;缓存不是新的事实来源。冷读始终从完整持久事件重建。宿主尚未 flush 就崩溃时可能丢失日志尾部;缺少记录只能返回 `unknown`,不能保证凭回执恢复尚未落盘的事实。插件不创造私有 `message → result` API,也不会为尚未闭合的崩溃日志猜一个成功结局:在宿主正式恢复并记录 `interrupted` 前,只能报告已有领取状态。`session_send` 的回执同时保存在工具结果元数据中;创建回执写入持久结果文本,现有创建卡片仍使用原有的会话身份元数据。
79
-
80
- 每次等待结束都会清理自己的计时器和取消监听器。真实 rc.2 持久化冷读使用只读句柄并传入取消信号,结束时关闭句柄;仅提供旧查询服务的兼容宿主,其不可取消读取由宿主自行管理,但不会延长本次等待预算。按消息等待使用可取消观察;会话概况仍使用 rc.2 的 `whenIdle()`(不接受取消信号),只停止观察,不对目标调用 `cancel` 或 `dispose`。
81
-
82
- ## list_sessions:先看看有哪些会话
83
-
84
- 不用记 id。当你要说的是"发给那个讨论发布的会话",AI 可以先列出会话(名字、目录、哪个是当前会话、现在在干什么),你说清是哪一个,它再发。
85
-
86
- | 参数 | 是否必填 | 说明 |
87
- |---|---|---|
88
- | `limit` | 可选 | 最多列几个,默认 20,按最近活动排序。 |
89
-
90
- 最近活动取会话自身日志中以下记录的最大时间:
91
-
92
- - 新消息加入收件箱,以及 `user/message` 用户消息
93
- - `assistant/message` 模型输出,以及 `assistant/attempt` 模型尝试
94
- - `turn/start` 轮次开始、`step/start` 步骤开始、`tool/call` 工具调用开始
95
- - `turn/end` 的 `completed`、`aborted`、`blocked`、`error`、`max-tokens` 结束状态;正常完成、用户取消、被阻止和执行失败都计入
96
-
97
- 单独改标题、读取或重新打开会话不算新活动;分叉继承的父会话记录也不算子会话的新活动。没有以上记录时使用创建时间。先对所有普通会话排序,再取 `limit`;时间相同时保留宿主原来的顺序。
98
-
99
- `step/end`、`tool/result` 和 `turn/end interrupted` 不独立推进活动时间。宿主恢复崩溃日志时也会补写这些结束记录;其中步骤结束记录可能与真正执行产生的记录完全相同,旧日志无法证明其来源。这里不尝试凭时间或字段猜测来源。因此,工具或步骤刚结束、但还没有下一条上述明确记录时,排序时间暂不更新;后续模型输出、新执行开始或真实轮次结束会正常更新时间。单独改名或恢复不会改变排序,保存后和重启后的读取使用同一定义。
100
-
101
- 开着的会话读取内存日志,关闭的会话只读持久日志,**不会为了排序恢复 Agent 或执行任务**。同一个工具实例最多同时做 4 次活动读取;按内存日志长度或持久化服务的日志版本缓存活动时间,不保存完整日志,每次关闭读句柄。宿主未提供版本信息时不复用冷读结果;日志读取失败则报告错误,不把“读不到”当成“没有活动”。
102
-
103
- 首次调用(或插件重载后)需要扫描所有普通会话的旧日志,因此 `limit=1` 也不能省略这些读取。开销随总日志量增长;后续调用仍需要列出会话、检查日志版本和读取选中会话的标题,但未改变的日志不重复扫描活动。真实 rc.2 JSONL 合成回归中,24 个会话、9600 条事件、约 258 KB 存储的在 Linux、Node 24.19.0 测试环境中的单次测量为首次约 151 ms、再次约 33 ms;活动扫描分别读取 24 和 0 个日志,另各读 1 次选中标题,最多 4 个读句柄。这里只是小规模测试样本,不是用户大日志库的耗时保证。
104
-
105
- 每条会带一个状态,就是侧边栏上显示的那个东西:
106
-
107
- | 状态 | 意思 |
108
- |---|---|
109
- | `running` | 进行中,正忙着。 |
110
- | `idle` | 空闲,没在干活(开着或者躺着都算)。 |
111
- | `archived` | 已归档,你把它从侧边栏收起来了。 |
112
-
113
- 子代理会话不会列出来(那是 AI 自己派出去的活)。已归档的会话**会**列出来并标 `archived`——因为"已归档"只是你把它从侧边栏收起来了,它本身还在;AI 看到这个标记就知道那是你收起来的会话,可以据此决定要不要往里发消息。
114
-
115
- `limit` 填得不合理会按合理值处理:填 0 或负数按 1 算,填超过 100 按 100 算,小数取整。
116
-
117
- ## 动手前会先问你
118
-
119
- 新建会话、或者往别的会话发消息,通常会先请求确认,写清它要干什么,比如:
120
-
121
- > 允许一次:在工作区 `E:\Users\Ryuu\Desktop` 新建会话,内容是「查一下某件事」
122
-
123
- 只有本次明确返回“允许一次”才放行;拒绝、取消、没应答、服务缺失或无法判断权限时停止。仅当宿主公开权限接口明确返回 `sandbox=danger-full-access` 且 `approval=never` 时免确认。`never` 单独表示审批请求自动拒绝;例如 `workspace-write + never` 不会放行。宿主在工具执行前已有的拒绝规则仍然生效。
124
-
125
- 目标会话没开着时,确认前只读查询并检查目标;获准后重新检查,再恢复会话、发送消息。审批拒绝或取消不会激活目标。
126
-
127
- 只是等一个会话做完、或者列一下有哪些会话,不会弹卡:这两件事不往任何地方写东西。
128
-
129
- ## 建好的会话,卡片上点一下就能过去
130
-
131
- 做完之后,对话里那张卡片会变成「已创建会话」加一个按钮——**点一下直接跳到新建的那个会话**,不用去左侧列表里找。
132
-
133
- (这一部分由插件的浏览器端负责渲染,所以旧的对话记录也会跟着变成可点。)
134
-
135
- ## 0.6.0 升级说明
136
-
137
- 从 0.5.4 升级时,请检查以下兼容边界:
138
-
139
- - Node 支持范围为 `^22.19.0 || ^24.0.0`,宿主回归基线仍是 DSH `0.1.5-rc.2`
140
- - `session_create` / `session_send` 返回消息回执。要继续查询同一次消息,请保存并一起传入 `sessionId` 和 `messageId`;只传会话 id 的 `session_wait` 返回会话概况
141
- - 判断消息结果时同时检查 `waitStatus` 和 `messageStatus`。`turnCompleted` 只表示所属轮次正常结束,业务是否成功仍需阅读结果;超时或调用方取消后不要自动重发
142
- - 未指定的会话标题现在由首条任务生成并固定,不额外调用模型,后续对话不会自动改名
7
+ ## 安装
143
8
 
144
- 此版本包含审批、消息结果归属、等待取消与资源清理、会话卡片、标题、最近活动排序及文档修正。测试范围和已知限制见下方对应章节。
9
+ 需要已能正常使用的 DSH 和模型配置,以及 **Node.js 22.19+(22 系列)或 24.x**。`dsh plugin` 使用 pnpm 管理插件;请确保它在命令行中可用。
145
10
 
146
- ## 安装
11
+ 安装前请查看[兼容说明](https://github.com/Ryuu-64/dsh-session-tools/blob/main/docs/compatibility.md),确认当前 DSH 和宿主配置受支持。
147
12
 
148
- 下面以 `desktop` profile(宿主配置)为例,将插件安装到该配置中:
13
+ 在终端中安装到你使用的宿主配置(profile),下面以 `web` 为例:
149
14
 
150
- ```
151
- dsh plugin --profile desktop add @ryuu-64/dsh-session-tools
15
+ ```sh
16
+ dsh plugin --profile web add @ryuu-64/dsh-session-tools@0.7.0
152
17
  ```
153
18
 
154
- 从源码装:
19
+ 安装后重启对应的 DSH 宿主。插件没有额外配置项;自定义宿主配置还需满足[服务要求](https://github.com/Ryuu-64/dsh-session-tools/blob/main/docs/compatibility.md)。
155
20
 
156
- ```
157
- git clone https://github.com/Ryuu-64/dsh-session-tools.git
158
- dsh plugin --profile desktop add link:C:\path\to\dsh-session-tools
159
- ```
21
+ ## 开始使用
160
22
 
161
- 装完后重启对应的 DSH 宿主。插件本身没有额外配置项,但宿主仍须满足下列服务条件。用 `link:` 方式装的,改完源码要重启应用才生效。
23
+ 在 DSH 对话中直接说你想做什么,无需自己填写工具参数。例如:
162
24
 
163
- ## 宿主要求与验收范围
25
+ > 帮我新建一个叫「方案比较」的会话,比较 SQLite 和 PostgreSQL 在本地单人记账应用中的优缺点,给出推荐和理由。等它回答后,把结果告诉我。
164
26
 
165
- 本节以 DSH `0.1.5-rc.2` 为基线。能否加载取决于宿主提供的服务,不能只按“桌面版”或“无界面”判断。
27
+ 1. AI 准备好任务,并请求新建会话的确认。
28
+ 2. 允许后,新会话开始处理任务。点「已创建会话」卡片上的按钮,就能打开它。
29
+ 3. AI 可以等待这次消息的结果,再回到当前对话中继续回答。一次等待默认 60 秒、最多 5 分钟;超时后可以接着查,不必重新派任务。
166
30
 
167
- - **加载必需服务**:`tools`、`agents`、`sessionTitle`、`workspaceRegistry`、`agentDefaultModel`,见[插件的注入声明](lib/index.js)。即使不填 `workspacePath`,也不能省略 `workspaceRegistry`
168
- - **执行时还需要的能力**:新建和发送会话消息需要 `approval`、`sandboxPolicy` 的公开权限接口;缺失时停止。列出会话和查找已关闭的发送目标需要 `sessionQuery`;关闭会话的日志读取使用 `sessionPersistence`,或兼容宿主提供的 `sessionQuery.readSession`
169
- - **官方配置证据**:同版本的 [Web 组合加载 workspace](https://github.com/deepseek-ai/deepseek-harness/blob/fb2c4b9e698e30edb738bca4cf0618587db7d203/packages/bundle/web-app/cordis.patch.yml#L75-L76),[Desktop 复用 Web 组合](https://github.com/deepseek-ai/deepseek-harness/blob/fb2c4b9e698e30edb738bca4cf0618587db7d203/apps/desktop-host/config/desktop.cordis.patch.yml#L1-L6)。workspace 并非桌面版独有。缺少该服务的 headless 配置无法加载本插件;不能据此宣布所有 headless 配置可用
170
- - **已运行的宿主回归**:使用仓库的[临时 Loader 配置](test/helpers/real-host.mjs)和[可重启 JSONL 配置](test/helpers/message-receipts-host.mjs),加载真实 rc.2 宿主组件;最近活动排序测试另加载真实 `sessionQuery`。这些是测试专用配置,模型请求与人工审批答复使用脚本替代,不是完整的官方 Web 或 Desktop profile 验收
31
+ 想接着做之前的任务,先找对会话:
171
32
 
172
- 服务出现在官方配置中,与本插件已在该完整配置中通过验收,是两件事。下方测试结果不覆盖完整 Web 浏览器或 Desktop UI 的端到端使用,也不构成其他宿主配置或 DSH 0.2 的兼容承诺。
33
+ > 先找标题含「方案比较」的会话,列出标题和状态;如果还有结果,继续列下一页。先不要发消息。
173
34
 
174
- ## 使用限制
35
+ 确认目标后,可以继续:
175
36
 
176
- - **不会顺手新建工作区**。`workspacePath` 必须是已经存在的那个工作区的路径;写错了它会报错,并把现有的工作区列出来给你挑。
177
- - **不能给子代理发消息**。目标必须是普通会话;AI 派出去的子代理要用 `send_message`。也不能给当前这个会话自己发。
178
- - **关掉的会话要有工作目录才能唤醒**。发消息时如果目标会话没开着,插件会把它重新打开;但如果那条会话没记录工作目录,就打不开、发不进去,会明确告诉你原因。
179
- - **重启期间收不到**。新建会话是立刻生效的;发出去的消息要等对方会话被打开处理,所以 DSH 得开着。等待也一样,DSH 关了就没法等。
180
- - **归属定了就不能改**。会话归到哪个工作区是记在账上的,建完之后没法在工作区之间搬。
37
+ > 让刚才找到的「方案比较」会话补充数据导出的注意事项,等它回答后把结果告诉我。
181
38
 
182
- ## 开发与回归检查
39
+ **把任务背景写完整。** 插件不会自动把当前对话复制给目标会话;对方需要的背景、文件路径和预期结果都应写进任务。
183
40
 
184
- 测试基线固定为 DSH `0.1.5-rc.2`。使用 Node `22.19.0`(22 系列最低支持版本)或 Node `24`:
41
+ ## 能做什么
185
42
 
186
- ```sh
187
- npm ci --ignore-scripts --no-audit --no-fund
188
- npm run check
189
- ```
43
+ | 你想做的事 | AI 使用的工具 |
44
+ | --- | --- |
45
+ | 新建一个可独立继续对话的会话,可放入已有工作区 | `session_create` |
46
+ | 给另一个普通会话发送新消息 | `session_send` |
47
+ | 按标题或工作区筛选、按最近活动分页列出会话 | `list_sessions` |
48
+ | 查询某次消息的结果,或查看会话概况 | `session_wait` |
49
+
50
+ 创建时可指定标题;不指定时,从首条任务生成固定标题,不额外调用模型。之后你仍可手动改名。
190
51
 
191
- `package-lock.json` 固定完整依赖图;开发依赖和 `overrides` 把宿主组件固定在同一 rc.2 基线,避免上游宽松 peer 范围混入其他预发布版本。安装无需生命周期脚本,仓库 `.npmrc` 也将其禁用。CI 在 Node 22.19.0 和 24 上各自执行干净安装、完整测试和语法检查,某一版本失败不会取消另一版本。
52
+ ## 权限与限制
192
53
 
193
- 消息回执增加真实收件箱、轮次终态、JSONL 冷读、投影检查点、宿主重新加载和恢复修复回归;模型内容仍是脚本边界。
54
+ - **新建和发送通常需要确认。** 只有宿主明确同时启用完全访问权限与免审批时才跳过确认;宿主的拒绝规则仍然生效。列出和等待是只读操作。
55
+ - **等待超时不等于失败。** 取消等待也不会取消目标任务。继续查询同一次消息要同时使用回执里的 `sessionId` 和 `messageId`,不要自动重发。轮次正常结束也不保证任务本身做成功。
56
+ - **只操作普通会话。** 不能向当前会话自己发消息,也不能向子代理发消息。列表包含已归档的普通会话,并标明归档状态。
57
+ - **工作区必须已存在。** 插件不会创建工作区,也不提供会话创建后跨工作区搬移的功能。
58
+ - **目标仍依赖 DSH 运行。** 发送消息可重新打开已关闭的会话,但它必须保存过工作目录;只读等待不会唤醒目标。插件不提供宿主关闭后的后台执行服务。
194
59
 
195
- 会话排序回归覆盖真实 `sessionQuery` 的创建时间顺序与对话时间顺序不同、仅改标题、稳定同值排序、`limit=1`、崩溃恢复与真实取消、重启冷读、日志追加/缩短/替换/不完整尾部、缓存失效和读句柄清理。`node --test test/session-activity*.test.mjs` 可单独运行;旧日志开销测试会输出本次环境的实际耗时和读取次数。
60
+ 更多参数、状态和出错处理见[工具参考](https://github.com/Ryuu-64/dsh-session-tools/blob/main/docs/tool-reference.md)。
196
61
 
197
- 测试分层:
62
+ ## 支持与交流
198
63
 
199
- - 策略和边界单元测试:用小型服务替身覆盖输入校验、权限组合、并发和取消时序
200
- - 真实宿主集成:临时配置经官方 Cordis Loader 加载真实工具运行时、AgentLoop、审批、工作区和 JSONL 持久化;仅模型请求和人工审批答复使用脚本边界,不发送真实网络请求或用户消息
201
- - 发布物回归:运行 `npm pack`,从解包后的入口经 Loader 加载插件;读取磁盘中的创建结果,用打包的客户端、官方 SlotCore 与真实 React 验证卡片文字和导航回调。这是无浏览器渲染测试,不宣称覆盖完整桌面 UI
202
- - 资源清理:测试拥有并关闭临时目录、Agent、读句柄和计时器;默认等待预算还通过独立子进程正常退出回归,不能依赖强制结束进程来通过
64
+ 遇到问题或有建议,请[提交 Issue](https://github.com/Ryuu-64/dsh-session-tools/issues)。请附上 DSH、Node.js 和插件版本、安装方式,以及可复现的步骤;不要贴 API 密钥或私密对话。
203
65
 
204
- 首次消息投递前的取消回归用服务替身检查 `detachSession` / `dispose` 调用;真实宿主还覆盖了标题清理后没有可见内容、因而创建失败且未投递消息的路径。这些测试没有覆盖真实持久化写入或关闭失败的故障注入,不能证明所有失败都会完全回滚。
66
+ QQ 交流群:`1129212995`。群聊用于使用交流和社区互助;需要持续跟踪的问题请先提交 Issue,再把 Issue 链接发到群里。群聊不替代 Issue 中可检索的正式记录。
205
67
 
206
- 目前没有把上述结果外推为 DSH 0.2 兼容承诺;升级宿主基线需要另行验收。
68
+ 由 [Ryuu-64](https://github.com/Ryuu-64) 维护,采用 [MIT 许可证](LICENSE)。
package/lib/client.js CHANGED
@@ -116,14 +116,26 @@ window.__ModuleLoader__.load({
116
116
  * @param ctx - the browser plugin context.
117
117
  */
118
118
  function apply(ctx) {
119
- ctx.slots.inject("tool.call.toolview", () => ctx.slots.register(
119
+ const register = (scope, openSession) => scope.slots.inject("tool.call.toolview", () => scope.slots.register(
120
120
  {
121
121
  name: "tool.call.toolview",
122
122
  key: "session_create",
123
- inject: () => ({ openSession: (sessionId) => ctx.sessions.open(sessionId) }),
123
+ inject: () => ({ openSession }),
124
124
  },
125
125
  SessionCreateRow,
126
126
  ));
127
+ // Pre-0.2 hosts put UI selection on sessions. In 0.2 the Session
128
+ // Controller only owns data/references; UIWorkspace owns mainView
129
+ // retention, selection, panel reveal and release. Do not retain a
130
+ // second reference here or await a history load before navigating.
131
+ if (typeof ctx.sessions.open === "function") {
132
+ register(ctx, (sessionId) => ctx.sessions.open(sessionId));
133
+ } else {
134
+ // Package client.inject is not a startup-order guarantee. Wait for
135
+ // the actual service and bind the row to that service's lifetime.
136
+ ctx.inject(["uiWorkspace"], (scope) => register(scope,
137
+ (sessionId) => scope.uiWorkspace.openSession(sessionId)));
138
+ }
127
139
  }
128
140
 
129
141
  exports.apply = apply;
package/lib/index.js CHANGED
@@ -8,9 +8,10 @@ import { brandString } from "@deepseek-ai/dsh-brand";
8
8
  import { symbols } from "@deepseek-ai/cordis";
9
9
  import { fallbackSessionTitle } from "@deepseek-ai/dsh-session-title";
10
10
  import { receiptProjection, receiptProjectionKey, foldReceipts, messageReceipt } from "./message-receipts.js";
11
- import { createActivitySorter } from "./session-activity.js";
11
+ import { createActivitySorter, readSlots } from "./session-activity.js";
12
+ import { createSessionDiscovery } from "./session-discovery.js";
12
13
 
13
- /** Stable Loader identity. */
14
+ /** Stable Loader identity and producer-owned message source (V3 and V4). */
14
15
  const name = "tool-session";
15
16
  /** Nothing to configure. */
16
17
  const Config = z.object({});
@@ -409,7 +410,9 @@ async function resolveTargetAgent(ctx, sessionId, exec) {
409
410
  * @param ctx - services of the agent this plugin was loaded for.
410
411
  */
411
412
  function apply(ctx) {
412
- const sortByActivity = createActivitySorter(ctx);
413
+ const inSlot = readSlots();
414
+ const sortByActivity = createActivitySorter(ctx, inSlot);
415
+ const listSessions = createSessionDiscovery(ctx, sortByActivity, inSlot, sessionState);
413
416
  // Optional capability; the same pure fold also works over a read-only full log.
414
417
  if (typeof ctx.inject === "function") ctx.inject(["sessionProjections"], scope => {
415
418
  scope.sessionProjections.register(receiptProjection);
@@ -542,8 +545,8 @@ function apply(ctx) {
542
545
  text: prompt
543
546
  }],
544
547
  source: {
545
- kind: "plugin",
546
- plugin: name
548
+ kind: name,
549
+ form: "relay"
547
550
  }
548
551
  });
549
552
  handle.agent.followup(sent);
@@ -647,8 +650,8 @@ function apply(ctx) {
647
650
  text: message
648
651
  }],
649
652
  source: {
650
- kind: "plugin",
651
- plugin: name
653
+ kind: name,
654
+ form: "relay"
652
655
  }
653
656
  });
654
657
  target.followup(sent);
@@ -672,9 +675,13 @@ function apply(ctx) {
672
675
  name: "list_sessions",
673
676
  description: "List the sessions the person can see, most recent conversation activity first, with each id and current state (working, waiting, or put away). New input, model output/attempts, execution starts and non-recovery turn endings count. Bare step/tool completion, title-only changes and recovery do not advance activity. Sessions without conversation activity use creation time; ties keep the host's order. Use it before session_send when the target is described by name rather than by id.",
674
677
  parameters: {
678
+ titleQuery: { type: "string", description: "Literal title substring, NFC/whitespace normalized and case-insensitive; at most 1024 UTF-8 bytes. Applied before limit. A failed title read fails the complete query." },
679
+ workspaceId: { type: "string", description: "Existing workspace ID (at most 256 UTF-8 bytes); mutually exclusive with workspacePath. Uses actual workspace membership." },
680
+ workspacePath: { type: "string", description: "Absolute path of an existing registered workspace (at most 4096 UTF-8 bytes); mutually exclusive with workspaceId." },
681
+ cursor: { type: "string", description: "Opaque nextCursor from this caller's previous page. Omit filters to inherit them; explicit filters must match. Expires after 5 minutes; no cursor starts a fresh query." },
675
682
  limit: {
676
683
  type: "number",
677
- description: "How many sessions to list, most recently active first. Defaults to 20."
684
+ description: "How many sessions to list, most recently active first. Defaults to 20, capped at 100. May change between pages."
678
685
  }
679
686
  },
680
687
  output: {
@@ -706,6 +713,13 @@ function apply(ctx) {
706
713
  }
707
714
  }
708
715
  },
716
+ matchedTotal: { type: "number", required: true, description: "Ordinary sessions matching the initial successful scan, before limit; frozen across pages." },
717
+ nextCursor: { type: "string" },
718
+ resultSetCreatedAt: { type: "number", description: "Result set creation time in Unix milliseconds; not an atomic database snapshot." },
719
+ resultSetExpiresAt: { type: "number", description: "Fixed expiration time in Unix milliseconds." },
720
+ paginationUnavailable: { type: "string" },
721
+ workspaceId: { type: "string" },
722
+ workspacePath: { type: "string" },
709
723
  total: {
710
724
  type: "number",
711
725
  required: true
@@ -714,8 +728,8 @@ function apply(ctx) {
714
728
  },
715
729
  render: (_args, value) => [{
716
730
  type: "text",
717
- text: value.total === 0
718
- ? "No other sessions."
731
+ text: value.sessions.length === 0
732
+ ? "No matching sessions."
719
733
  : [
720
734
  value.sessions.map((entry) => [
721
735
  sessionReference(entry.title, entry.sessionId),
@@ -725,41 +739,13 @@ function apply(ctx) {
725
739
  entry.state === "archived" ? "(put away)" : undefined,
726
740
  entry.cwd
727
741
  ].filter((part) => part !== undefined).join(" · ")).join("\n"),
728
- value.sessions.some((entry) => entry.state === "archived") ? "Sessions marked (put away) are archived: they are hidden from the sidebar but still listed here." : undefined
742
+ value.sessions.some((entry) => entry.state === "archived") ? "Sessions marked (put away) are archived: they are hidden from the sidebar but still listed here." : undefined,
743
+ value.nextCursor ? `More matching sessions: use nextCursor ${value.nextCursor} before ${new Date(value.resultSetExpiresAt).toISOString()}.` : undefined,
744
+ value.paginationUnavailable
729
745
  ].filter((part) => part !== undefined).join("\n")
730
746
  }]
731
747
  },
732
- async execute(args, exec) {
733
- const query = ctx.get("sessionQuery");
734
- if (query === void 0) throw new Error("list_sessions needs session lookup, which this DSH does not offer");
735
- const requested = args.limit === void 0 ? 20 : Math.trunc(args.limit);
736
- const limit = requested < 1 ? 1 : requested > 100 ? 100 : requested;
737
- const self = exec.agent === void 0 ? undefined : String(exec.agent.id);
738
- const records = await query.listSessions(exec.signal);
739
- const visible = records.filter(({ header }) => (header.delegationDepth ?? 0) <= 0 && header.origin !== "subagent");
740
- const ordered = await sortByActivity(visible, exec.signal);
741
- const listed = [];
742
- for (const record of ordered.slice(0, limit)) {
743
- exec.signal?.throwIfAborted();
744
- const header = record.header;
745
- const sessionId = String(header.id);
746
- let title;
747
- try {
748
- // Title reads return a snapshot, not a string: the text lives on
749
- // `.title`, exactly like the title service the create path uses.
750
- title = (await query.readTitle(sessionId, exec.signal))?.title;
751
- } catch {}
752
- exec.signal?.throwIfAborted();
753
- listed.push({
754
- sessionId,
755
- ...title === void 0 || title === "" ? {} : { title: String(title) },
756
- ...header.cwd === void 0 ? {} : { cwd: String(header.cwd) },
757
- state: sessionState(ctx, sessionId),
758
- ...sessionId === self ? { current: true } : {}
759
- });
760
- }
761
- return { sessions: listed, total: records.length };
762
- }
748
+ execute: listSessions
763
749
  }));
764
750
  ctx.tools.register(defineTool({
765
751
  name: "session_wait",
@@ -21,30 +21,38 @@ export function conversationActivity(events, createdAt, inheritedEventCount = 0)
21
21
  return latest ?? (Number.isFinite(createdAt) ? createdAt : 0);
22
22
  }
23
23
 
24
- /** Four active observations, shared by overlapping calls to this tool instance. */
25
- function readSlots() {
24
+ /** Four shared permits. A title batch takes all four atomically, never partial permits. */
25
+ export function readSlots() {
26
26
  let active = 0;
27
27
  const waiting = [];
28
- return async (read, signal) => {
28
+ const pump = () => {
29
+ while (waiting.length && active + waiting[0].weight <= 4) {
30
+ const entry = waiting.shift();
31
+ active += entry.weight;
32
+ entry.start();
33
+ }
34
+ };
35
+ return async (read, signal, weight = 1) => {
36
+ if (!Number.isInteger(weight) || weight < 1 || weight > 4) throw new Error("invalid read permit weight");
29
37
  signal?.throwIfAborted();
30
- if (active < 4) active++;
31
- else await new Promise((resolve, reject) => {
32
- const entry = { resolve: () => { signal?.removeEventListener("abort", abort); resolve(); } };
38
+ await new Promise((resolve, reject) => {
39
+ const entry = { weight, start: () => { signal?.removeEventListener("abort", abort); resolve(); } };
33
40
  const abort = () => {
34
41
  const index = waiting.indexOf(entry);
35
42
  if (index >= 0) waiting.splice(index, 1);
36
43
  reject(signal.reason);
44
+ pump();
37
45
  };
38
46
  waiting.push(entry);
39
47
  signal?.addEventListener("abort", abort, { once: true });
48
+ pump();
40
49
  });
41
50
  try {
42
51
  signal?.throwIfAborted();
43
52
  return await read();
44
53
  } finally {
45
- const next = waiting.shift();
46
- if (next) next.resolve();
47
- else active--;
54
+ active -= weight;
55
+ pump();
48
56
  }
49
57
  };
50
58
  }
@@ -52,10 +60,9 @@ function readSlots() {
52
60
  const identity = service => service?.[symbols.original] ?? service;
53
61
 
54
62
  /** Cache only the derived number, never a log, a read handle, or an Agent. */
55
- export function createActivitySorter(ctx) {
63
+ export function createActivitySorter(ctx, inSlot = readSlots()) {
56
64
  const cache = new Map();
57
65
  const liveCache = new WeakMap();
58
- const inSlot = readSlots();
59
66
  async function activity(record, signal) {
60
67
  const id = String(record.header.id);
61
68
  const live = ctx.get("sessions")?.get(id) ?? ctx.agents.get(id)?.session;
@@ -94,10 +101,9 @@ export function createActivitySorter(ctx) {
94
101
  signal?.throwIfAborted();
95
102
  return conversationActivity(log.events, record.header.createdAt, log.inheritedEventCount);
96
103
  }
97
- return async (records, signal) => {
104
+ const sort = async (records, signal, directory = records) => {
98
105
  signal?.throwIfAborted();
99
- const ids = new Set(records.map(record => String(record.header.id)));
100
- for (const id of cache.keys()) if (!ids.has(id)) cache.delete(id);
106
+ sort.prune(directory);
101
107
  // Wait for every observation to close, including after an error/abort.
102
108
  const ordered = [];
103
109
  let next = 0;
@@ -120,4 +126,10 @@ export function createActivitySorter(ctx) {
120
126
  .sort((a, b) => b.time - a.time || a.index - b.index)
121
127
  .map(({ record }) => record);
122
128
  };
129
+ // A filtered workspace is not the directory: never prune other workspaces.
130
+ sort.prune = (records) => {
131
+ const ids = new Set(records.map(record => String(record.header.id)));
132
+ for (const id of cache.keys()) if (!ids.has(id)) cache.delete(id);
133
+ };
134
+ return sort;
123
135
  }
@@ -0,0 +1,204 @@
1
+ import { createHmac, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
2
+ import { isAbsolute } from "node:path";
3
+ import { symbols } from "@deepseek-ai/cordis";
4
+
5
+ // Resource guards, not measured throughput promises. No event/log/Agent is retained.
6
+ const TTL = 5 * 60_000;
7
+ const MAX_SETS = 16;
8
+ const MAX_SET_IDS = 10_000;
9
+ const MAX_IDS = 50_000;
10
+ const MAX_BYTES = 8 * 1024 * 1024;
11
+ const TITLE_BATCH_IDS = 64;
12
+ const identity = service => service?.[symbols.original] ?? service;
13
+ const ordinary = ({ header }) => (header.delegationDepth ?? 0) <= 0 && header.origin !== "subagent";
14
+ const normalizeTitle = value => value.normalize("NFC").trim().replace(/\s+/gu, " ").toLowerCase();
15
+ const fail = message => new Error(`list_sessions: ${message}`);
16
+
17
+ function optionalText(value, name, bytes) {
18
+ if (value === undefined) return undefined;
19
+ if (typeof value !== "string" || !value.trim() || Buffer.byteLength(value) > bytes) {
20
+ throw fail(`${name} must be a nonempty string of at most ${bytes} UTF-8 bytes`);
21
+ }
22
+ return value;
23
+ }
24
+ function filters(args) {
25
+ const title = optionalText(args.titleQuery, "titleQuery", 1024);
26
+ const workspaceId = optionalText(args.workspaceId, "workspaceId", 256);
27
+ const workspacePath = optionalText(args.workspacePath, "workspacePath", 4096);
28
+ if (workspaceId !== undefined && workspacePath !== undefined) throw fail("workspaceId and workspacePath are mutually exclusive");
29
+ if (workspacePath !== undefined && !isAbsolute(workspacePath)) throw fail("workspacePath must be absolute");
30
+ return { titleQuery: title === undefined ? undefined : normalizeTitle(title), workspaceId, workspacePath };
31
+ }
32
+
33
+ /** One plugin instance owns these short-lived result sets. Tokens never authorize a read. */
34
+ export function createSessionDiscovery(ctx, sortByActivity, inSlot, sessionState) {
35
+ const sets = new Map();
36
+ const key = randomBytes(32);
37
+ let sources;
38
+ let disposed = false;
39
+ let count = 0, bytes = 0, expiryTimer;
40
+ const remove = id => {
41
+ const set = sets.get(id);
42
+ if (!set) return;
43
+ count -= set.rows.length; bytes -= set.bytes; sets.delete(id);
44
+ };
45
+ const clear = () => { clearTimeout(expiryTimer); expiryTimer = undefined; sets.clear(); count = 0; bytes = 0; };
46
+ ctx.on?.("dispose", () => { disposed = true; clear(); });
47
+ const services = () => ["sessionQuery", "sessionPersistence", "workspaceRegistry", "sessions"].map(name => identity(ctx.get(name))).concat(identity(ctx.agents));
48
+ const equalSources = (a, b) => a.length === b.length && a.every((value, i) => value === b[i]);
49
+ const sweep = () => { for (const [id, set] of sets) if (Date.now() >= set.expiresAt) remove(id); };
50
+ const scheduleExpiry = () => {
51
+ clearTimeout(expiryTimer);
52
+ expiryTimer = undefined;
53
+ if (!sets.size) return;
54
+ const expiresAt = Math.min(...Array.from(sets.values(), set => set.expiresAt));
55
+ expiryTimer = setTimeout(() => { sweep(); scheduleExpiry(); }, Math.max(1, expiresAt - Date.now()));
56
+ expiryTimer.unref();
57
+ };
58
+ function token(id, offset) {
59
+ const body = Buffer.from(JSON.stringify([id, offset])).toString("base64url");
60
+ return `${body}.${createHmac("sha256", key).update(body).digest("base64url")}`;
61
+ }
62
+ function decode(value) {
63
+ optionalText(value, "cursor", 512);
64
+ try {
65
+ const [body, signature, extra] = value.split(".");
66
+ if (extra !== undefined) throw Error();
67
+ const expected = createHmac("sha256", key).update(body).digest();
68
+ const actual = Buffer.from(signature, "base64url");
69
+ if (actual.length !== expected.length || !timingSafeEqual(actual, expected)) throw Error();
70
+ const [id, offset] = JSON.parse(Buffer.from(body, "base64url").toString());
71
+ if (typeof id !== "string" || !Number.isSafeInteger(offset) || offset < 1) throw Error();
72
+ return { id, offset };
73
+ } catch { throw fail("invalid cursor; start a new query without cursor"); }
74
+ }
75
+ async function workspace(filter, signal) {
76
+ if (filter.workspaceId === undefined && filter.workspacePath === undefined) return undefined;
77
+ const registry = ctx.get("workspaceRegistry");
78
+ let result;
79
+ if (filter.workspaceId !== undefined) {
80
+ if (typeof registry?.get !== "function") throw fail("this host cannot look up workspace IDs");
81
+ result = registry.get(filter.workspaceId);
82
+ } else {
83
+ if (typeof registry?.resolveByPath !== "function") throw fail("this host cannot resolve workspace paths");
84
+ try { result = await registry.resolveByPath(filter.workspacePath); }
85
+ catch (cause) { throw fail(`workspacePath could not be resolved (${cause.message}); use an existing registered workspace`); }
86
+ }
87
+ signal?.throwIfAborted();
88
+ if (!result) throw fail("workspace is not registered; use an existing workspace ID or path");
89
+ return { id: String(result.id), path: String(result.path), ids: new Set(result.sessionIds.map(String)) };
90
+ }
91
+ async function matchingTitles(query, records, text, signal) {
92
+ if (typeof query.readTitleSnapshots !== "function") throw fail("titleQuery needs the host's readTitleSnapshots API");
93
+ const titles = new Map();
94
+ for (let start = 0; start < records.length; start += TITLE_BATCH_IDS) {
95
+ const ids = records.slice(start, start + TITLE_BATCH_IDS).map(record => String(record.header.id));
96
+ // One corpus listing per batch. Reserve all permits atomically so no other
97
+ // plugin activity/title read overlaps this batch. The provider owns its
98
+ // internal concurrency (default 4); at most 64 requested IDs can be active.
99
+ const result = await inSlot(() => query.readTitleSnapshots(ids, signal), signal, 4);
100
+ signal?.throwIfAborted();
101
+ if (!Array.isArray(result) || result.length !== ids.length) throw fail("incomplete title batch; no complete matching result is available");
102
+ for (let index = 0; index < ids.length; index++) {
103
+ const id = ids[index], observation = result[index];
104
+ if (observation?.sessionId !== id || observation.status !== "fulfilled" || String(observation.value?.session?.id) !== id) {
105
+ throw fail(`could not read the title of ${id}; no complete matching result is available`);
106
+ }
107
+ // The same read may observe a newer header than the directory scan.
108
+ if (!ordinary({ header: observation.value.session })) throw fail("session visibility changed during title scan; start a new query");
109
+ const title = observation.value.title?.title;
110
+ if (title !== undefined && typeof title !== "string") throw fail(`invalid title snapshot for ${id}`);
111
+ if (title !== undefined && normalizeTitle(title).includes(text)) titles.set(id, title);
112
+ }
113
+ }
114
+ return titles;
115
+ }
116
+ return async (args, exec) => {
117
+ exec.signal?.throwIfAborted();
118
+ if (disposed) throw fail("plugin was unloaded; start a new query");
119
+ const currentSources = services();
120
+ if (sources && !equalSources(sources, currentSources)) clear();
121
+ sources = currentSources;
122
+ sweep();
123
+ const query = ctx.get("sessionQuery");
124
+ if (query === undefined) throw fail("needs session lookup, which this DSH does not offer");
125
+ if (args.limit !== undefined && (typeof args.limit !== "number" || !Number.isFinite(args.limit))) throw fail("limit must be a finite number");
126
+ const limit = Math.max(1, Math.min(100, Math.trunc(args.limit ?? 20)));
127
+ // Agent.id is the existing public tool-execution identity; arguments cannot supply it.
128
+ const owner = typeof exec.agent?.id === "string" && exec.agent.id ? exec.agent.id : undefined;
129
+ let filter = filters(args), set, offset = 0, setId;
130
+ if (args.cursor !== undefined) {
131
+ ({ id: setId, offset } = decode(args.cursor));
132
+ set = sets.get(setId);
133
+ if (!set) throw fail("cursor expired, was evicted, or belongs to another plugin/host; start a new query without cursor");
134
+ if (!owner || owner !== set.owner) throw fail("cursor belongs to a different calling session");
135
+ if (offset >= set.rows.length) throw fail("invalid cursor offset");
136
+ if (filter.titleQuery !== undefined && filter.titleQuery !== set.filter.titleQuery) throw fail("cursor titleQuery does not match its original query");
137
+ filter = { ...set.filter, ...(filter.workspaceId !== undefined || filter.workspacePath !== undefined ? { workspaceId: filter.workspaceId, workspacePath: filter.workspacePath } : {}) };
138
+ }
139
+ const selected = await workspace(filter, exec.signal);
140
+ if (set && (selected?.id !== set.workspaceId || selected?.path !== set.workspacePath)) throw fail("cursor workspace does not match its original query");
141
+ const records = await query.listSessions(exec.signal);
142
+ exec.signal?.throwIfAborted();
143
+ sortByActivity.prune(records);
144
+ let candidates = records.filter(record => ordinary(record) && (!selected || selected.ids.has(String(record.header.id))));
145
+ const byId = new Map(candidates.map(record => [String(record.header.id), record]));
146
+ if (set) {
147
+ // Recheck the entire frozen range, not just the requested slice. Never silently skip.
148
+ if (set.rows.some(row => !byId.has(row.id))) {
149
+ remove(setId);
150
+ throw fail("result set contains a session no longer visible or in this workspace; start a new query");
151
+ }
152
+ } else {
153
+ if ((owner || filter.titleQuery !== undefined) && candidates.length > MAX_SET_IDS) throw fail(`candidate set exceeds ${MAX_SET_IDS} sessions; narrow the workspace filter`);
154
+ const titles = filter.titleQuery === undefined ? undefined : await matchingTitles(query, candidates, filter.titleQuery, exec.signal);
155
+ if (titles) candidates = candidates.filter(record => titles.has(String(record.header.id)));
156
+ const ordered = await sortByActivity(candidates, exec.signal, records);
157
+ const rows = ordered.map(record => ({ id: String(record.header.id), ...(titles ? { title: titles.get(String(record.header.id)) } : {}) }));
158
+ set = { owner, filter: { titleQuery: filter.titleQuery, workspaceId: selected?.id }, rows, workspaceId: selected?.id, workspacePath: selected?.path, createdAt: Date.now() };
159
+ set.expiresAt = set.createdAt + TTL;
160
+ set.bytes = Buffer.byteLength(JSON.stringify(set));
161
+ if (owner && rows.length > limit && set.bytes > MAX_BYTES) throw fail("result set exceeds the 8 MiB metadata budget; narrow the query");
162
+ }
163
+ const listed = [];
164
+ for (const row of set.rows.slice(offset, offset + limit)) {
165
+ exec.signal?.throwIfAborted();
166
+ const header = byId.get(row.id).header;
167
+ let title = row.title;
168
+ if (set.filter.titleQuery === undefined) try {
169
+ // Legacy no-query listing keeps best-effort titles and reads only this page.
170
+ title = (await inSlot(() => query.readTitle(row.id, exec.signal), exec.signal))?.title;
171
+ } catch {}
172
+ exec.signal?.throwIfAborted();
173
+ listed.push({ sessionId: row.id,
174
+ ...title === undefined || title === "" ? {} : { title: String(title) },
175
+ ...header.cwd === undefined ? {} : { cwd: String(header.cwd) },
176
+ state: sessionState(ctx, row.id), ...row.id === owner ? { current: true } : {},
177
+ });
178
+ }
179
+ exec.signal?.throwIfAborted();
180
+ if (disposed) throw fail("plugin was unloaded; start a new query");
181
+ const hasMore = offset + listed.length < set.rows.length;
182
+ if (setId || (hasMore && owner)) {
183
+ if (!equalSources(currentSources, services())) { clear(); throw fail("host services changed; start a new query"); }
184
+ if (Date.now() >= set.expiresAt) { if (setId) remove(setId); throw fail("cursor expired while reading; start a new query"); }
185
+ if (!setId) {
186
+ sweep();
187
+ while (sets.size >= MAX_SETS || count + set.rows.length > MAX_IDS || bytes + set.bytes > MAX_BYTES) remove(sets.keys().next().value);
188
+ setId = randomUUID(); count += set.rows.length; bytes += set.bytes;
189
+ } else {
190
+ // An overlapping call may have evicted this set while this page was read.
191
+ if (sets.get(setId) !== set) throw fail("cursor was evicted while reading; start a new query");
192
+ sets.delete(setId);
193
+ }
194
+ sets.set(setId, set);
195
+ scheduleExpiry();
196
+ }
197
+ return { sessions: listed, total: records.length, matchedTotal: set.rows.length,
198
+ ...(setId ? { resultSetCreatedAt: set.createdAt, resultSetExpiresAt: set.expiresAt,
199
+ ...(hasMore ? { nextCursor: token(setId, offset + listed.length) } : {}) } : {}),
200
+ ...(hasMore && !owner ? { paginationUnavailable: "A calling Agent identity is required to continue; run list_sessions through the host tool runtime." } : {}),
201
+ ...(selected ? { workspaceId: selected.id, workspacePath: selected.path } : {}),
202
+ };
203
+ };
204
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ryuu-64/dsh-session-tools",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Let the agent start a new chat session, send a message to another one, or wait for it to finish.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -32,9 +32,9 @@
32
32
  "client": {
33
33
  "platform": "web",
34
34
  "inject": [
35
- "@deepseek-ai/dsh-client-runtime",
36
35
  "@deepseek-ai/dsh-client-ui-slots",
37
- "@deepseek-ai/dsh-client-ui-tool"
36
+ "@deepseek-ai/dsh-client-ui-tool",
37
+ "@deepseek-ai/dsh-client-ui-workspace"
38
38
  ]
39
39
  }
40
40
  },
@@ -44,13 +44,13 @@
44
44
  },
45
45
  "peerDependencies": {
46
46
  "@deepseek-ai/cordis": "^4.0.2",
47
- "@deepseek-ai/dsh-agent": ">=0.1.5-rc.2 <0.1.6-0 || >=0.1.6-0 <0.2.0-0",
48
- "@deepseek-ai/dsh-agent-default-model": ">=0.1.5-rc.2 <0.1.6-0 || >=0.1.6-0 <0.2.0-0",
49
- "@deepseek-ai/dsh-brand": ">=0.1.5-rc.2 <0.1.6-0 || >=0.1.6-0 <0.2.0-0",
50
- "@deepseek-ai/dsh-llm": ">=0.1.5-rc.2 <0.1.6-0 || >=0.1.6-0 <0.2.0-0",
51
- "@deepseek-ai/dsh-session-title": ">=0.1.5-rc.2 <0.1.6-0 || >=0.1.6-0 <0.2.0-0",
52
- "@deepseek-ai/dsh-tools": ">=0.1.5-rc.2 <0.1.6-0 || >=0.1.6-0 <0.2.0-0",
53
- "@deepseek-ai/dsh-workspace": ">=0.1.5-rc.2 <0.1.6-0 || >=0.1.6-0 <0.2.0-0",
47
+ "@deepseek-ai/dsh-agent": ">=0.1.5-rc.2 <0.1.6-0 || >=0.1.6-0 <0.2.0-0 || 0.2.0-rc.2",
48
+ "@deepseek-ai/dsh-agent-default-model": ">=0.1.5-rc.2 <0.1.6-0 || >=0.1.6-0 <0.2.0-0 || 0.2.0-rc.2",
49
+ "@deepseek-ai/dsh-brand": ">=0.1.5-rc.2 <0.1.6-0 || >=0.1.6-0 <0.2.0-0 || 0.2.0-rc.2",
50
+ "@deepseek-ai/dsh-llm": ">=0.1.5-rc.2 <0.1.6-0 || >=0.1.6-0 <0.2.0-0 || 0.2.0-rc.2",
51
+ "@deepseek-ai/dsh-session-title": ">=0.1.5-rc.2 <0.1.6-0 || >=0.1.6-0 <0.2.0-0 || 0.2.0-rc.2",
52
+ "@deepseek-ai/dsh-tools": ">=0.1.5-rc.2 <0.1.6-0 || >=0.1.6-0 <0.2.0-0 || 0.2.0-rc.2",
53
+ "@deepseek-ai/dsh-workspace": ">=0.1.5-rc.2 <0.1.6-0 || >=0.1.6-0 <0.2.0-0 || 0.2.0-rc.2",
54
54
  "@deepseek-ai/schemastery": "^3.18.2",
55
55
  "react": ">=18 <20"
56
56
  },
@@ -63,74 +63,86 @@
63
63
  "node": "^22.19.0 || ^24.0.0"
64
64
  },
65
65
  "devDependencies": {
66
- "@deepseek-ai/cordis": "4.0.2",
67
- "@deepseek-ai/dsh-agent": "0.1.5-rc.2",
68
- "@deepseek-ai/dsh-agent-default-model": "0.1.5-rc.2",
69
- "@deepseek-ai/dsh-brand": "0.1.5-rc.2",
70
- "@deepseek-ai/dsh-llm": "0.1.5-rc.2",
71
- "@deepseek-ai/dsh-session-title": "0.1.5-rc.2",
72
- "@deepseek-ai/dsh-tools": "0.1.5-rc.2",
73
- "@deepseek-ai/dsh-workspace": "0.1.5-rc.2",
74
- "@deepseek-ai/schemastery": "3.18.2",
75
- "react": "19.2.0",
76
- "@deepseek-ai/dsh-session": "0.1.5-rc.2",
77
- "@deepseek-ai/dsh-agent-loop": "0.1.5-rc.2",
78
- "@deepseek-ai/cordis-plugin-loader": "1.0.3",
79
- "@deepseek-ai/dsh-session-persistence": "0.1.5-rc.2",
80
- "@deepseek-ai/dsh-session-persistence-jsonl": "0.1.5-rc.2",
81
- "@deepseek-ai/dsh-storage-json": "0.1.5-rc.2",
82
- "@deepseek-ai/dsh-sandbox-policy": "0.1.5-rc.2",
83
- "@deepseek-ai/dsh-user-approval": "0.1.5-rc.2",
84
- "@deepseek-ai/dsh-system-prompt": "0.1.5-rc.2",
85
- "@deepseek-ai/dsh-session-projection": "0.1.5-rc.2",
86
- "@deepseek-ai/dsh-storage-domain": "0.1.5-rc.2",
87
- "@deepseek-ai/dsh-storage": "0.1.5-rc.2",
66
+ "@deepseek-ai/cordis": "4.0.4",
67
+ "@deepseek-ai/cordis-plugin-loader": "1.0.5",
68
+ "@deepseek-ai/dsh-agent": "0.2.0-rc.2",
69
+ "@deepseek-ai/dsh-agent-default-model": "0.2.0-rc.2",
70
+ "@deepseek-ai/dsh-agent-loop": "0.2.0-rc.2",
71
+ "@deepseek-ai/dsh-api-session-controller": "0.2.0-rc.2",
72
+ "@deepseek-ai/dsh-brand": "0.2.0-rc.2",
73
+ "@deepseek-ai/dsh-client-store": "0.2.0-rc.2",
74
+ "@deepseek-ai/dsh-client-ui-layout": "0.2.0-rc.2",
75
+ "@deepseek-ai/dsh-client-ui-renderer": "0.2.0-rc.2",
76
+ "@deepseek-ai/dsh-client-ui-slots": "0.2.0-rc.2",
77
+ "@deepseek-ai/dsh-client-ui-workspace": "0.2.0-rc.2",
78
+ "@deepseek-ai/dsh-llm": "0.2.0-rc.2",
79
+ "@deepseek-ai/dsh-sandbox-policy": "0.2.0-rc.2",
80
+ "@deepseek-ai/dsh-session": "0.2.0-rc.2",
81
+ "@deepseek-ai/dsh-session-persistence": "0.2.0-rc.2",
82
+ "@deepseek-ai/dsh-session-persistence-jsonl": "0.2.0-rc.2",
83
+ "@deepseek-ai/dsh-session-projection": "0.2.0-rc.2",
84
+ "@deepseek-ai/dsh-session-query": "0.2.0-rc.2",
85
+ "@deepseek-ai/dsh-session-title": "0.2.0-rc.2",
86
+ "@deepseek-ai/dsh-session-title-first-prompt-llm": "0.2.0-rc.2",
87
+ "@deepseek-ai/dsh-session-title-llm": "0.2.0-rc.2",
88
+ "@deepseek-ai/dsh-storage": "0.2.0-rc.2",
89
+ "@deepseek-ai/dsh-storage-domain": "0.2.0-rc.2",
90
+ "@deepseek-ai/dsh-storage-json": "0.2.0-rc.2",
91
+ "@deepseek-ai/dsh-system-prompt": "0.2.0-rc.2",
92
+ "@deepseek-ai/dsh-tools": "0.2.0-rc.2",
93
+ "@deepseek-ai/dsh-user-approval": "0.2.0-rc.2",
94
+ "@deepseek-ai/dsh-workspace": "0.2.0-rc.2",
95
+ "@deepseek-ai/schemastery": "3.18.4",
96
+ "immer": "10.1.1",
97
+ "react": "18.3.1",
98
+ "react-dom": "18.3.1",
88
99
  "yaml": "2.9.0",
89
- "@deepseek-ai/dsh-client-ui-slots": "0.1.5-rc.2",
90
- "react-dom": "19.2.0",
91
- "@deepseek-ai/dsh-session-title-first-prompt-llm": "0.1.5-rc.2",
92
- "@deepseek-ai/dsh-session-title-llm": "0.1.5-rc.2",
93
- "@deepseek-ai/dsh-session-query": "0.1.5-rc.2"
100
+ "zustand": "4.4.7"
94
101
  },
95
102
  "overrides": {
96
- "@deepseek-ai/dsh-scope": "0.1.5-rc.2",
97
- "@deepseek-ai/dsh-invariants": "0.1.5-rc.2",
98
- "@deepseek-ai/dsh-util-values": "0.1.5-rc.2",
99
- "@deepseek-ai/dsh-system-prompt": "0.1.5-rc.2",
100
- "@deepseek-ai/dsh-typert-protocol": "0.1.5-rc.2",
101
- "@deepseek-ai/dsh-session-projection": "0.1.5-rc.2",
102
- "@deepseek-ai/dsh-brand": "0.1.5-rc.2",
103
- "@deepseek-ai/dsh-timeout": "0.1.5-rc.2",
104
- "@deepseek-ai/dsh-util-crypto": "0.1.5-rc.2",
105
- "@deepseek-ai/dsh-session": "0.1.5-rc.2",
106
- "@deepseek-ai/dsh-llm": "0.1.5-rc.2",
107
- "@deepseek-ai/dsh-agent": "0.1.5-rc.2",
108
- "@deepseek-ai/dsh-tools": "0.1.5-rc.2",
109
- "@deepseek-ai/dsh-workspace": "0.1.5-rc.2",
110
- "@deepseek-ai/dsh-agent-default-model": "0.1.5-rc.2",
111
- "@deepseek-ai/dsh-session-title": "0.1.5-rc.2",
112
- "@deepseek-ai/dsh-agent-loop": "0.1.5-rc.2",
113
- "@deepseek-ai/dsh-session-persistence": "0.1.5-rc.2",
114
- "@deepseek-ai/dsh-code-runtime": "0.1.5-rc.2",
115
- "@deepseek-ai/dsh-user-approval": "0.1.5-rc.2",
116
- "@deepseek-ai/dsh-storage": "0.1.5-rc.2",
117
- "@deepseek-ai/dsh-settings": "0.1.5-rc.2",
118
- "@deepseek-ai/dsh-storage-domain": "0.1.5-rc.2",
119
- "@deepseek-ai/dsh-session-persistence-jsonl": "0.1.5-rc.2",
120
- "@deepseek-ai/dsh-session-format-v2-to-v3": "0.1.5-rc.2",
121
- "@deepseek-ai/dsh-session-format-v1-to-v2": "0.1.5-rc.2",
122
- "@deepseek-ai/dsh-session-format-v0-to-v1": "0.1.5-rc.2",
123
- "@deepseek-ai/dsh-session-format": "0.1.5-rc.2",
124
- "@deepseek-ai/dsh-session-format-catalog": "0.1.5-rc.2",
125
- "@deepseek-ai/dsh-storage-json": "0.1.5-rc.2",
126
- "@deepseek-ai/dsh-sandbox-policy": "0.1.5-rc.2",
127
- "@deepseek-ai/dsh-sandbox": "0.1.5-rc.2",
128
- "@deepseek-ai/dsh-client-ui-slots": "0.1.5-rc.2",
129
- "@deepseek-ai/dsh-session-title-first-prompt-llm": "0.1.5-rc.2",
130
- "@deepseek-ai/dsh-session-title-llm": "0.1.5-rc.2",
131
- "@deepseek-ai/dsh-session-query": "0.1.5-rc.2",
132
- "@deepseek-ai/dsh-tool-todo": "0.1.5-rc.2",
133
- "@deepseek-ai/dsh-session-projection-cache": "0.1.5-rc.2"
103
+ "@deepseek-ai/dsh-scope": "0.2.0-rc.2",
104
+ "@deepseek-ai/dsh-invariants": "0.2.0-rc.2",
105
+ "@deepseek-ai/dsh-util-values": "0.2.0-rc.2",
106
+ "@deepseek-ai/dsh-system-prompt": "0.2.0-rc.2",
107
+ "@deepseek-ai/dsh-typert-protocol": "0.2.0-rc.2",
108
+ "@deepseek-ai/dsh-session-projection": "0.2.0-rc.2",
109
+ "@deepseek-ai/dsh-brand": "0.2.0-rc.2",
110
+ "@deepseek-ai/dsh-timeout": "0.2.0-rc.2",
111
+ "@deepseek-ai/dsh-util-crypto": "0.2.0-rc.2",
112
+ "@deepseek-ai/dsh-session": "0.2.0-rc.2",
113
+ "@deepseek-ai/dsh-llm": "0.2.0-rc.2",
114
+ "@deepseek-ai/dsh-agent": "0.2.0-rc.2",
115
+ "@deepseek-ai/dsh-tools": "0.2.0-rc.2",
116
+ "@deepseek-ai/dsh-workspace": "0.2.0-rc.2",
117
+ "@deepseek-ai/dsh-agent-default-model": "0.2.0-rc.2",
118
+ "@deepseek-ai/dsh-session-title": "0.2.0-rc.2",
119
+ "@deepseek-ai/dsh-agent-loop": "0.2.0-rc.2",
120
+ "@deepseek-ai/dsh-session-persistence": "0.2.0-rc.2",
121
+ "@deepseek-ai/dsh-code-runtime": "0.2.0-rc.2",
122
+ "@deepseek-ai/dsh-user-approval": "0.2.0-rc.2",
123
+ "@deepseek-ai/dsh-storage": "0.2.0-rc.2",
124
+ "@deepseek-ai/dsh-settings": "0.2.0-rc.2",
125
+ "@deepseek-ai/dsh-storage-domain": "0.2.0-rc.2",
126
+ "@deepseek-ai/dsh-session-persistence-jsonl": "0.2.0-rc.2",
127
+ "@deepseek-ai/dsh-session-format-v2-to-v3": "0.2.0-rc.2",
128
+ "@deepseek-ai/dsh-session-format-v1-to-v2": "0.2.0-rc.2",
129
+ "@deepseek-ai/dsh-session-format-v0-to-v1": "0.2.0-rc.2",
130
+ "@deepseek-ai/dsh-session-format": "0.2.0-rc.2",
131
+ "@deepseek-ai/dsh-session-format-catalog": "0.2.0-rc.2",
132
+ "@deepseek-ai/dsh-storage-json": "0.2.0-rc.2",
133
+ "@deepseek-ai/dsh-sandbox-policy": "0.2.0-rc.2",
134
+ "@deepseek-ai/dsh-sandbox": "0.2.0-rc.2",
135
+ "@deepseek-ai/dsh-client-ui-slots": "0.2.0-rc.2",
136
+ "@deepseek-ai/dsh-session-title-first-prompt-llm": "0.2.0-rc.2",
137
+ "@deepseek-ai/dsh-session-title-llm": "0.2.0-rc.2",
138
+ "@deepseek-ai/dsh-session-query": "0.2.0-rc.2",
139
+ "@deepseek-ai/dsh-tool-todo": "0.2.0-rc.2",
140
+ "@deepseek-ai/dsh-session-projection-cache": "0.2.0-rc.2",
141
+ "@deepseek-ai/dsh-client-ui-workspace": "0.2.0-rc.2",
142
+ "@deepseek-ai/dsh-client-store": "0.2.0-rc.2",
143
+ "@deepseek-ai/dsh-api-session-controller": "0.2.0-rc.2",
144
+ "@deepseek-ai/dsh-client-ui-renderer": "0.2.0-rc.2",
145
+ "@deepseek-ai/dsh-client-ui-layout": "0.2.0-rc.2"
134
146
  },
135
147
  "dependencies": {
136
148
  "zod": "4.6.5"