@ryuu-64/dsh-session-tools 0.5.4 → 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,102 +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
-
18
- 做完返回新会话的名字和 id,你在左侧列表里就能看到它。如果中途失败,会把建了一半的东西清理掉,不留垃圾。
19
-
20
- ## session_send:给别的会话发消息
21
-
22
- | 参数 | 是否必填 | 说明 |
23
- |---|---|---|
24
- | `sessionId` | 必填 | 目标会话的 id,形如 `session-9311a0fb-65c7-4b04-b142-1444642a627e`。 |
25
- | `message` | 必填 | 要发的内容。对方看不到当前这个会话,所以要写清楚。 |
26
- | `wait` | 可选 | 默认不等:发出去就返回。填 `true` 就等对方把这条消息处理完,并把它的回答带回来。 |
27
- | `timeoutMs` | 可选 | 等多久(毫秒)。默认 60000(一分钟),最多 300000(五分钟)。等超了不报错,只告诉你"它还在忙"。 |
28
-
29
- 默认发出即返回,返回只代表对方收到了、开始排队处理。消息来源标记为插件,不会被当成是你本人打的字。目标会话如果没开着,会被自动打开再把消息排进去。
30
-
31
- 填了 `wait` 就变成"发完等它做完",AI 拿到对方的回答之后可以接着往下办——比如让一个会话去跑测试,跑完再根据结果决定下一步。**等的是它处理完你刚发的这条消息**,不是"它现在不忙了"就算完。
32
-
33
- ## session_wait:等别的会话干完
34
-
35
- 如果消息已经发出去了,或者那个会话本来就在忙,用这个等它收尾。
7
+ ## 安装
36
8
 
37
- | 参数 | 是否必填 | 说明 |
38
- |---|---|---|
39
- | `sessionId` | 必填 | 目标会话的 id。 |
40
- | `timeoutMs` | 可选 | 等多久(毫秒),默认 60000,最多 300000。 |
9
+ 需要已能正常使用的 DSH 和模型配置,以及 **Node.js 22.19+(22 系列)或 24.x**。`dsh plugin` 使用 pnpm 管理插件;请确保它在命令行中可用。
41
10
 
42
- 它只负责等和看,不去动那个会话:不会打开它、不会改它、也不会打断它。对方本来就没在忙的话,立刻返回,把最后一条回答给你。等超了就说一句"还在忙",不算失败——你可以过会儿再问一次。
11
+ 安装前请查看[兼容说明](https://github.com/Ryuu-64/dsh-session-tools/blob/main/docs/compatibility.md),确认当前 DSH 和宿主配置受支持。
43
12
 
44
- ## list_sessions:先看看有哪些会话
13
+ 在终端中安装到你使用的宿主配置(profile),下面以 `web` 为例:
45
14
 
46
- 不用记 id。当你要说的是"发给那个讨论发布的会话",AI 可以先列出会话(名字、目录、哪个是当前会话、现在在干什么),你说清是哪一个,它再发。
15
+ ```sh
16
+ dsh plugin --profile web add @ryuu-64/dsh-session-tools@0.7.0
17
+ ```
47
18
 
48
- | 参数 | 是否必填 | 说明 |
49
- |---|---|---|
50
- | `limit` | 可选 | 最多列几个,默认 20,按最近活动排序。 |
19
+ 安装后重启对应的 DSH 宿主。插件没有额外配置项;自定义宿主配置还需满足[服务要求](https://github.com/Ryuu-64/dsh-session-tools/blob/main/docs/compatibility.md)。
51
20
 
52
- 每条会带一个状态,就是侧边栏上显示的那个东西:
21
+ ## 开始使用
53
22
 
54
- | 状态 | 意思 |
55
- |---|---|
56
- | `running` | 进行中,正忙着。 |
57
- | `idle` | 空闲,没在干活(开着或者躺着都算)。 |
58
- | `archived` | 已归档,你把它从侧边栏收起来了。 |
23
+ 在 DSH 对话中直接说你想做什么,无需自己填写工具参数。例如:
59
24
 
60
- 子代理会话不会列出来(那是 AI 自己派出去的活)。已归档的会话**会**列出来并标 `archived`——因为"已归档"只是你把它从侧边栏收起来了,它本身还在;AI 看到这个标记就知道那是你收起来的会话,可以据此决定要不要往里发消息。
25
+ > 帮我新建一个叫「方案比较」的会话,比较 SQLite 和 PostgreSQL 在本地单人记账应用中的优缺点,给出推荐和理由。等它回答后,把结果告诉我。
61
26
 
62
- `limit` 填得不合理会按合理值处理:填 0 或负数按 1 算,填超过 100 按 100 算,小数取整。
27
+ 1. AI 准备好任务,并请求新建会话的确认。
28
+ 2. 允许后,新会话开始处理任务。点「已创建会话」卡片上的按钮,就能打开它。
29
+ 3. AI 可以等待这次消息的结果,再回到当前对话中继续回答。一次等待默认 60 秒、最多 5 分钟;超时后可以接着查,不必重新派任务。
63
30
 
64
- ## 动手前会先问你
31
+ 想接着做之前的任务,先找对会话:
65
32
 
66
- 新建会话、或者往别的会话发消息,**都会先弹一个确认卡**,写清它要干什么,比如:
33
+ > 先找标题含「方案比较」的会话,列出标题和状态;如果还有结果,继续列下一页。先不要发消息。
67
34
 
68
- > 允许一次:在工作区 `E:\Users\Ryuu\Desktop` 新建会话,内容是「查一下某件事」
35
+ 确认目标后,可以继续:
69
36
 
70
- 你点了"允许一次"它才动手;拒绝或没应答,它就什么都不做。你自己完全关掉审批(切到完全权限模式)时,它不再打扰你——那是你的选择,不是它擅自跳过。
37
+ > 让刚才找到的「方案比较」会话补充数据导出的注意事项,等它回答后把结果告诉我。
71
38
 
72
- 只是等一个会话做完、或者列一下有哪些会话,不会弹卡:这两件事不往任何地方写东西。
39
+ **把任务背景写完整。** 插件不会自动把当前对话复制给目标会话;对方需要的背景、文件路径和预期结果都应写进任务。
73
40
 
74
- ## 建好的会话,卡片上点一下就能过去
41
+ ## 能做什么
75
42
 
76
- 做完之后,对话里那张卡片会变成「已创建会话」加一个按钮——**点一下直接跳到新建的那个会话**,不用去左侧列表里找。
43
+ | 你想做的事 | AI 使用的工具 |
44
+ | --- | --- |
45
+ | 新建一个可独立继续对话的会话,可放入已有工作区 | `session_create` |
46
+ | 给另一个普通会话发送新消息 | `session_send` |
47
+ | 按标题或工作区筛选、按最近活动分页列出会话 | `list_sessions` |
48
+ | 查询某次消息的结果,或查看会话概况 | `session_wait` |
77
49
 
78
- (这一部分由插件的浏览器端负责渲染,所以旧的对话记录也会跟着变成可点。)
50
+ 创建时可指定标题;不指定时,从首条任务生成固定标题,不额外调用模型。之后你仍可手动改名。
79
51
 
80
- ## 安装
52
+ ## 权限与限制
81
53
 
82
- ```
83
- dsh plugin --profile desktop add @ryuu-64/dsh-session-tools@0.5.3
84
- ```
54
+ - **新建和发送通常需要确认。** 只有宿主明确同时启用完全访问权限与免审批时才跳过确认;宿主的拒绝规则仍然生效。列出和等待是只读操作。
55
+ - **等待超时不等于失败。** 取消等待也不会取消目标任务。继续查询同一次消息要同时使用回执里的 `sessionId` 和 `messageId`,不要自动重发。轮次正常结束也不保证任务本身做成功。
56
+ - **只操作普通会话。** 不能向当前会话自己发消息,也不能向子代理发消息。列表包含已归档的普通会话,并标明归档状态。
57
+ - **工作区必须已存在。** 插件不会创建工作区,也不提供会话创建后跨工作区搬移的功能。
58
+ - **目标仍依赖 DSH 运行。** 发送消息可重新打开已关闭的会话,但它必须保存过工作目录;只读等待不会唤醒目标。插件不提供宿主关闭后的后台执行服务。
85
59
 
86
- 从源码装:
60
+ 更多参数、状态和出错处理见[工具参考](https://github.com/Ryuu-64/dsh-session-tools/blob/main/docs/tool-reference.md)。
87
61
 
88
- ```
89
- git clone https://github.com/Ryuu-64/dsh-session-tools.git
90
- dsh plugin --profile desktop add link:C:\path\to\dsh-session-tools
91
- ```
62
+ ## 支持与交流
92
63
 
93
- 装完重启 DSH 就能用,不需要其它设置。用 `link:` 方式装的,改完源码要重启应用才生效。
64
+ 遇到问题或有建议,请[提交 Issue](https://github.com/Ryuu-64/dsh-session-tools/issues)。请附上 DSH、Node.js 和插件版本、安装方式,以及可复现的步骤;不要贴 API 密钥或私密对话。
94
65
 
95
- ## 使用限制
66
+ QQ 交流群:`1129212995`。群聊用于使用交流和社区互助;需要持续跟踪的问题请先提交 Issue,再把 Issue 链接发到群里。群聊不替代 Issue 中可检索的正式记录。
96
67
 
97
- - **不会顺手新建工作区**。`workspacePath` 必须是已经存在的那个工作区的路径;写错了它会报错,并把现有的工作区列出来给你挑。
98
- - **不能给子代理发消息**。目标必须是普通会话;AI 派出去的子代理要用 `send_message`。也不能给当前这个会话自己发。
99
- - **关掉的会话要有工作目录才能唤醒**。发消息时如果目标会话没开着,插件会把它重新打开;但如果那条会话没记录工作目录,就打不开、发不进去,会明确告诉你原因。
100
- - **重启期间收不到**。新建会话是立刻生效的;发出去的消息要等对方会话被打开处理,所以 DSH 得开着。等待也一样,DSH 关了就没法等。
101
- - **归属定了就不能改**。会话归到哪个工作区是记在账上的,建完之后没法在工作区之间搬。
102
- - **需要桌面版**。工作区归属靠桌面版才挂载的那个工作区服务,插件把它列为必需依赖,所以命令行无界面模式(headless)下这个插件不会加载。
68
+ 由 [Ryuu-64](https://github.com/Ryuu-64) 维护,采用 [MIT 许可证](LICENSE)。
package/lib/client.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Browser half: render the `session_create` tool card as something the person
3
- * can act on. The host half prints a receipt; this half turns the session that
4
- * receipt names into a button that opens it.
3
+ * can act on. The host half persists an explicit target in presentationMeta;
4
+ * this half uses that durable identity, never an id guessed from the receipt.
5
5
  *
6
6
  * Loaded by the browser module table as a CJS closure factory; `require` resolves
7
7
  * only platform seeds and other registered bundles.
@@ -18,9 +18,6 @@ window.__ModuleLoader__.load({
18
18
  /** Slots this client half needs before it can register anything. */
19
19
  const inject = ["slots", "sessions"];
20
20
 
21
- /** Diagnostics stay behind one switch so a quiet console stays quiet. */
22
- const DEBUG = false;
23
-
24
21
  /**
25
22
  * Flatten a settled result's content blocks, mirroring how `ui-tool` reads
26
23
  * them: text blocks verbatim, anything else as JSON.
@@ -37,35 +34,18 @@ window.__ModuleLoader__.load({
37
34
  }
38
35
 
39
36
  /**
40
- * Read the created session out of a settled tool result.
41
- *
42
- * The result node's `content` blocks are the form the host half guarantees,
43
- * so they are the first source; a structured value is used when present.
44
- * Both are read defensively: this half must never break the transcript when
45
- * a shape changes underneath it.
46
- * @param block - the settled tool call block handed to the slot.
47
- * @param output - the owner's rendered result text, when it passes one.
37
+ * Read only the successful ToolResultNode's durable presentation metadata.
38
+ * rc.2 projects event.data.meta here; canonical value is not persisted.
39
+ * Old receipts cannot prove identity, even when only one id is visible.
40
+ * @param block - the running or settled tool call block handed to the slot.
48
41
  * @returns the session id and optional title, or undefined.
49
42
  */
50
- function readCreatedSession(block, output) {
51
- if (block === null || typeof block !== "object") return undefined;
52
- // Settled results expose `content` directly; a raw event nests them under `result`.
53
- const settled = Array.isArray(block.content) ? block : block.result ?? block;
54
- if (DEBUG) {
55
- try {
56
- console.log("[session-tools] block:", Object.keys(block), "settled:", Object.keys(settled), "output:", String(output ?? "").slice(0, 160));
57
- } catch {}
58
- }
59
- for (const candidate of [settled.value, settled.output, block.value, block.output]) {
60
- if (candidate !== null && typeof candidate === "object" && typeof candidate.sessionId === "string") {
61
- return { sessionId: candidate.sessionId, title: typeof candidate.title === "string" ? candidate.title : undefined };
62
- }
63
- }
64
- const text = [resultText(settled), typeof output === "string" ? output : ""].filter((part) => part !== "").join("\n");
65
- const id = /session-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/u.exec(text)?.[0];
66
- if (id === undefined) return undefined;
67
- const title = /Created session:\s*(.+?)\s+·\s+session-/u.exec(text)?.[1];
68
- return { sessionId: id, title };
43
+ function readCreatedSession(block) {
44
+ if (block === null || typeof block !== "object" || block.kind !== "tool-result" || block.isError !== false) return undefined;
45
+ const meta = block.meta;
46
+ if (meta === null || typeof meta !== "object" || Array.isArray(meta)) return undefined;
47
+ if (typeof meta.sessionId !== "string" || !/^session-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/u.test(meta.sessionId)) return undefined;
48
+ return { sessionId: meta.sessionId, title: typeof meta.title === "string" ? meta.title : undefined };
69
49
  }
70
50
 
71
51
  /**
@@ -76,11 +56,16 @@ window.__ModuleLoader__.load({
76
56
  */
77
57
  function SessionCreateRow(props) {
78
58
  const openSession = props.openSession ?? props.slot?.injected?.openSession;
79
- // The owner hands over the raw result node; `output` is its rendered text.
80
- // Reading both makes the row survive a shape change on either side.
81
- const created = readCreatedSession(props.block, props.output);
82
- const title = created?.title === undefined || created.title === "" ? "会话" : created.title;
83
- const canOpen = created !== undefined && typeof openSession === "function";
59
+ const created = readCreatedSession(props.block);
60
+ if (created === undefined) {
61
+ // Keep errors and legacy receipts readable, without claiming a
62
+ // successful creation or inventing a clickable navigation target.
63
+ const text = resultText(props.block);
64
+ const fallback = props.block?.kind === "tool-result" ? "没有可用的会话创建结果" : "正在创建会话…";
65
+ return react.createElement("div", { style: { whiteSpace: "pre-wrap", overflowWrap: "anywhere" } }, text || fallback);
66
+ }
67
+ const title = created.title === undefined || created.title === "" ? "会话" : created.title;
68
+ const canOpen = typeof openSession === "function";
84
69
  const onOpen = () => {
85
70
  if (!canOpen) return;
86
71
  try {
@@ -107,7 +92,7 @@ window.__ModuleLoader__.load({
107
92
  type: "button",
108
93
  onClick: onOpen,
109
94
  disabled: !canOpen,
110
- title: created?.sessionId ?? "没有读到会话 id",
95
+ title: created.sessionId,
111
96
  style: {
112
97
  border: "1px solid var(--dsh-border, #3a4150)",
113
98
  background: "transparent",
@@ -121,8 +106,7 @@ window.__ModuleLoader__.load({
121
106
  },
122
107
  title,
123
108
  ),
124
- created === undefined ? react.createElement("span", { style: { opacity: 0.6 } }, "(结果里没有会话信息)") : null,
125
- created === undefined ? null : react.createElement("span", { style: { opacity: 0.55, fontFamily: "ui-monospace, monospace", fontSize: "11px" } }, created.sessionId),
109
+ react.createElement("span", { style: { opacity: 0.55, fontFamily: "ui-monospace, monospace", fontSize: "11px" } }, created.sessionId),
126
110
  );
127
111
  }
128
112
 
@@ -132,14 +116,26 @@ window.__ModuleLoader__.load({
132
116
  * @param ctx - the browser plugin context.
133
117
  */
134
118
  function apply(ctx) {
135
- ctx.slots.inject("tool.call.toolview", () => ctx.slots.register(
119
+ const register = (scope, openSession) => scope.slots.inject("tool.call.toolview", () => scope.slots.register(
136
120
  {
137
121
  name: "tool.call.toolview",
138
122
  key: "session_create",
139
- inject: () => ({ openSession: (sessionId) => ctx.sessions.open(sessionId) }),
123
+ inject: () => ({ openSession }),
140
124
  },
141
125
  SessionCreateRow,
142
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
+ }
143
139
  }
144
140
 
145
141
  exports.apply = apply;