@ryuu-64/dsh-session-tools 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ryuu-64
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # dsh-session-tools
2
+
3
+ 让对话里的 AI 能做两件事:**新建一个会话**,或者**给别的会话发一条消息**。
4
+
5
+ 两个工具,`session_create` 和 `session_send`。新会话会出现在左侧会话列表里,和手动新建的完全一样;想让它归到某个工作区下面也可以。
6
+
7
+ 典型用法:你说"帮我开一个会话去查一下这件事"——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
+
27
+ 发出即返回,返回只代表对方收到了、开始排队处理。消息来源标记为插件,不会被当成是你本人打的字。
28
+
29
+ ## 安装
30
+
31
+ ```
32
+ dsh plugin --profile desktop add @ryuu-64/dsh-session-tools@0.4.1
33
+ ```
34
+
35
+ 从源码装:
36
+
37
+ ```
38
+ git clone https://github.com/Ryuu-64/dsh-session-tools.git
39
+ dsh plugin --profile desktop add link:C:\path\to\dsh-session-tools
40
+ ```
41
+
42
+ 装完重启 DSH 就能用,不需要其它设置。用 `link:` 方式装的,改完源码要重启应用才生效。
43
+
44
+ ## 使用限制
45
+
46
+ - **不会顺手新建工作区**。`workspacePath` 必须是已经存在的那个工作区的路径;写错了它会报错,并把现有的工作区列出来给你挑。
47
+ - **不能给子代理发消息**。目标必须是普通会话;AI 派出去的子代理要用 `send_message`。也不能给当前这个会话自己发。
48
+ - **重启期间收不到**。新建会话是立刻生效的;发出去的消息要等对方会话被打开处理,所以 DSH 得开着。
49
+ - **归属定了就不能改**。会话归到哪个工作区是记在账上的,建完之后没法在工作区之间搬。
50
+ - **桌面版可用**。命令行无界面模式(headless)默认不带工作区功能,要用得自己加一行配置。
@@ -0,0 +1,4 @@
1
+ # dsh bundle patch: inserts this plugin into a profile's layer stack.
2
+ - insert:
3
+ - id: session-tools-bundle
4
+ name: '@ryuu-64/dsh-session-tools'
package/lib/index.js ADDED
@@ -0,0 +1,292 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { isAbsolute } from "node:path";
3
+ import z from "@deepseek-ai/schemastery";
4
+ import { defineTool } from "@deepseek-ai/dsh-tools";
5
+ import { createUserMessage } from "@deepseek-ai/dsh-llm";
6
+ import { brandString } from "@deepseek-ai/dsh-brand";
7
+
8
+ /** Stable Loader identity. */
9
+ const name = "tool-session";
10
+ /** Nothing to configure. */
11
+ const Config = z.object({});
12
+ /** Host services this tool needs: where it registers tools, and what it creates a session with. */
13
+ const inject = [
14
+ "tools",
15
+ "agents",
16
+ "sessionTitle",
17
+ "workspaceRegistry",
18
+ "agentDefaultModel"
19
+ ];
20
+ /** List the existing workspaces, so a rejected path tells the caller what to use instead. */
21
+ function workspaceCatalogue(registry) {
22
+ const items = registry.list();
23
+ return items.map((workspace) => `${workspace.title} (${workspace.path})`).join("; ");
24
+ }
25
+ /**
26
+ * Give the new session the same model as this one: read the model the calling
27
+ * session is using, and fall back to the default when it has not chosen one.
28
+ */
29
+ function currentSelection(ctx, agent) {
30
+ const projections = ctx.get("sessionProjections");
31
+ let inherited;
32
+ if (projections !== void 0) try {
33
+ const state = projections.stateOf(agent.session, "modelSelection");
34
+ inherited = state?.pending ?? state?.lastUsed ?? void 0;
35
+ } catch {}
36
+ if (inherited !== void 0) return {
37
+ provider: inherited.provider,
38
+ model: inherited.model,
39
+ ...inherited.reasoningEffort === void 0 ? {} : { reasoningEffort: inherited.reasoningEffort }
40
+ };
41
+ const selected = ctx.agentDefaultModel.currentSelection();
42
+ return {
43
+ provider: selected.provider,
44
+ model: selected.model
45
+ };
46
+ }
47
+ /**
48
+ * Find the agent preset the new session should start on: the one this session
49
+ * uses, or the default preset when this session has none. A new session without
50
+ * a preset gets no tools, so it would sit in the list unable to do anything.
51
+ * @param ctx - services of the calling agent.
52
+ * @param agent - the calling agent.
53
+ * @param presets - the preset registry, when one is composed.
54
+ * @returns the preset id to use, or undefined when there is none.
55
+ */
56
+ async function resolvePreset(ctx, agent, presets) {
57
+ const projections = ctx.get("sessionProjections");
58
+ if (projections !== void 0) try {
59
+ const current = projections.stateOf(agent.session, "agentPreset");
60
+ if (current !== void 0) return current;
61
+ } catch {}
62
+ if (presets === void 0) return void 0;
63
+ try {
64
+ return (await presets.resolve(void 0)).id;
65
+ } catch {
66
+ return void 0;
67
+ }
68
+ }
69
+ /**
70
+ * Get the live agent for a target session, opening the session again when it is
71
+ * not currently running. The session is reopened on the preset it was created
72
+ * with.
73
+ * @param ctx - services of the calling agent.
74
+ * @param sessionId - the target session.
75
+ * @param callerAgent - the calling agent, whose model the reopened session inherits.
76
+ * @returns the live or resumed Agent.
77
+ */
78
+ async function resolveTargetAgent(ctx, sessionId, callerAgent) {
79
+ const live = ctx.agents.get(sessionId);
80
+ if (live !== void 0) return live;
81
+ const query = ctx.get("sessionQuery");
82
+ if (query === void 0) throw new Error(`session_send cannot open ${JSON.stringify(sessionId)}: this DSH does not offer session lookup`);
83
+ let record;
84
+ try {
85
+ record = (await query.listSessions()).find((entry) => String(entry.header.id) === sessionId);
86
+ } catch (error) {
87
+ throw new Error(`session_send cannot read ${JSON.stringify(sessionId)}: ${error instanceof Error ? error.message : String(error)}`);
88
+ }
89
+ if (record === void 0) throw new Error(`session_send cannot find session ${JSON.stringify(sessionId)}: no open or saved session has that id`);
90
+ if (record.header.cwd === void 0) throw new Error(`session_send cannot open ${JSON.stringify(sessionId)}: the saved session records no working directory`);
91
+ const agentPresets = ctx.get("agentPresets");
92
+ const presetId = record.header.agentPreset;
93
+ const setup = agentPresets === void 0 || presetId === void 0 ? void 0 : async (agentCtx) => {
94
+ await agentPresets.mount(agentCtx, presetId);
95
+ };
96
+ const resumed = await ctx.agents.resume({
97
+ resumeSessionId: sessionId,
98
+ agentOptions: currentSelection(ctx, callerAgent),
99
+ ...setup === void 0 ? {} : { setup }
100
+ });
101
+ return resumed.agent;
102
+ }
103
+ /**
104
+ * Register `session_create` and `session_send`.
105
+ * @param ctx - services of the agent this plugin was loaded for.
106
+ */
107
+ function apply(ctx) {
108
+ ctx.tools.register(defineTool({
109
+ name: "session_create",
110
+ description: "Start a new chat session the person can see in the session list. The new session runs its own first turn and keeps going on its own; this call returns as soon as it exists. Pass workspacePath to put it under that workspace, or leave it out to leave it ungrouped. Use this when the work deserves its own session the person can open and continue; use a subagent instead when the work should stay inside this conversation.",
111
+ parameters: {
112
+ prompt: {
113
+ type: "string",
114
+ required: true,
115
+ description: "The new session's first user message. Write it self-contained: the new session cannot see this conversation."
116
+ },
117
+ workspacePath: {
118
+ type: "string",
119
+ description: "Full path of a workspace that already exists (for example \"E:\\\\Users\\\\Ryuu\\\\Desktop\"). Leave it out to leave the new session ungrouped. This tool never creates a workspace, so an unknown path fails with the list of existing ones."
120
+ },
121
+ title: {
122
+ type: "string",
123
+ description: "Optional title. Leave it out and the title is generated from the first message, exactly like a session the person creates by hand."
124
+ },
125
+ wait: {
126
+ type: "boolean",
127
+ description: "Wait for the new session's first turn to finish before returning. Defaults to false."
128
+ }
129
+ },
130
+ output: {
131
+ schema: {
132
+ type: "object",
133
+ additionalProperties: false,
134
+ properties: {
135
+ sessionId: {
136
+ type: "string",
137
+ required: true
138
+ },
139
+ grouped: {
140
+ type: "boolean",
141
+ required: true
142
+ },
143
+ cwd: {
144
+ type: "string",
145
+ required: true
146
+ },
147
+ workspaceId: { type: "string" },
148
+ workspacePath: { type: "string" }
149
+ }
150
+ },
151
+ render: (_args, value) => [{
152
+ type: "text",
153
+ text: value.grouped ? `Created session ${value.sessionId} in workspace ${value.workspacePath}` : `Created session ${value.sessionId}, ungrouped`
154
+ }]
155
+ },
156
+ async execute(args, exec) {
157
+ if (exec.agent === void 0) throw new Error("session_create must run inside a session");
158
+ const prompt = args.prompt.trim();
159
+ if (prompt === "") throw new Error("session_create needs a prompt: it becomes the new session's first user message");
160
+ let workspace;
161
+ let cwd;
162
+ if (args.workspacePath !== void 0) {
163
+ const requested = args.workspacePath.trim();
164
+ if (!isAbsolute(requested)) throw new Error(`session_create needs a full workspace path, got ${JSON.stringify(args.workspacePath)}`);
165
+ workspace = await ctx.workspaceRegistry.resolveByPath(requested);
166
+ if (workspace === void 0) {
167
+ throw new Error(`session_create cannot use ${JSON.stringify(requested)}: no workspace has that path, and this tool does not create workspaces. Existing workspaces: ${workspaceCatalogue(ctx.workspaceRegistry)}. Use one of those paths, or leave workspacePath out to create the session under Ungrouped.`);
168
+ }
169
+ cwd = workspace.path;
170
+ } else {
171
+ cwd = exec.agent.session.header.cwd;
172
+ if (cwd === void 0) throw new Error("session_create needs a working directory, and this session has none");
173
+ }
174
+ const agentOptions = currentSelection(ctx, exec.agent);
175
+ const agentPresets = ctx.get("agentPresets");
176
+ const presetId = await resolvePreset(ctx, exec.agent, agentPresets);
177
+ const sessionId = brandString(`session-${randomUUID()}`);
178
+ let handle;
179
+ let attached = false;
180
+ try {
181
+ handle = await ctx.agents.create({
182
+ sessionId,
183
+ agentOptions,
184
+ meta: {
185
+ cwd,
186
+ ...presetId === void 0 ? {} : { agentPreset: presetId }
187
+ },
188
+ ...agentPresets === void 0 || presetId === void 0 ? {} : { setup: async (agentCtx) => {
189
+ await agentPresets.mount(agentCtx, presetId);
190
+ } }
191
+ });
192
+ if (workspace !== void 0) {
193
+ await workspace.attachSession(sessionId);
194
+ attached = true;
195
+ }
196
+ const title = args.title === void 0 ? void 0 : args.title.trim();
197
+ if (title !== void 0 && title !== "") ctx.sessionTitle.rename(handle.agent.session, title);
198
+ handle.agent.followup(createUserMessage({
199
+ content: [{
200
+ type: "text",
201
+ text: prompt
202
+ }],
203
+ source: {
204
+ kind: "plugin",
205
+ plugin: name
206
+ }
207
+ }));
208
+ if (args.wait === true) await handle.agent.whenIdle();
209
+ } catch (error) {
210
+ if (attached) try {
211
+ await workspace.detachSession(sessionId);
212
+ } catch {}
213
+ if (handle !== void 0) try {
214
+ await handle.dispose();
215
+ } catch {}
216
+ throw error;
217
+ }
218
+ return {
219
+ sessionId: String(sessionId),
220
+ grouped: workspace !== void 0,
221
+ cwd,
222
+ ...workspace === void 0 ? {} : {
223
+ workspaceId: String(workspace.id),
224
+ workspacePath: workspace.path
225
+ }
226
+ };
227
+ }
228
+ }));
229
+ ctx.tools.register(defineTool({
230
+ name: "session_send",
231
+ description: "Send a message to an existing chat session so that session continues on its own — including one this session started earlier. It cannot send to itself, cannot send to a subagent the agent spawned (use send_message for those), and never rewrites past messages. Sending returns right away; the target handles the message when it can.",
232
+ parameters: {
233
+ sessionId: {
234
+ type: "string",
235
+ required: true,
236
+ description: "Target Session id, for example \"session-2330bd36-fe62-4621-8d42-c7e04566f447\"."
237
+ },
238
+ message: {
239
+ type: "string",
240
+ required: true,
241
+ description: "Message text. Write it self-contained: the target cannot see this conversation unless the person linked the two."
242
+ }
243
+ },
244
+ output: {
245
+ schema: {
246
+ type: "object",
247
+ additionalProperties: false,
248
+ properties: {
249
+ sessionId: {
250
+ type: "string",
251
+ required: true
252
+ },
253
+ cwd: {
254
+ type: "string",
255
+ required: true
256
+ }
257
+ }
258
+ },
259
+ render: (_args, value) => [{
260
+ type: "text",
261
+ text: `Delivered to session ${value.sessionId}`
262
+ }]
263
+ },
264
+ async execute(args, exec) {
265
+ if (exec.agent === void 0) throw new Error("session_send must run inside a session");
266
+ const requested = args.sessionId.trim();
267
+ if (requested === "") throw new Error("session_send needs a session id");
268
+ const message = args.message.trim();
269
+ if (message === "") throw new Error("session_send needs a message");
270
+ const target = await resolveTargetAgent(ctx, requested, exec.agent);
271
+ const targetId = String(target.id);
272
+ if (targetId === String(exec.agent.id)) throw new Error("session_send cannot send to its own session: use the current conversation instead");
273
+ const depth = target.session.header.delegationDepth ?? 0;
274
+ if (depth > 0) throw new Error(`session_send cannot send to ${JSON.stringify(targetId)}: that is a subagent session, not a regular one. Use send_message for it.`);
275
+ target.followup(createUserMessage({
276
+ content: [{
277
+ type: "text",
278
+ text: message
279
+ }],
280
+ source: {
281
+ kind: "plugin",
282
+ plugin: name
283
+ }
284
+ }));
285
+ return {
286
+ sessionId: targetId,
287
+ cwd: String(target.session.header.cwd ?? "")
288
+ };
289
+ }
290
+ }));
291
+ }
292
+ export { Config, apply, inject, name };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@ryuu-64/dsh-session-tools",
3
+ "version": "0.4.1",
4
+ "description": "Let the agent start a new chat session, or send a message to another one.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "keywords": [
8
+ "deepseek-harness",
9
+ "dsh",
10
+ "dsh-plugin",
11
+ "sessions",
12
+ "tools"
13
+ ],
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/Ryuu-64/dsh-session-tools.git"
17
+ },
18
+ "main": "lib/index.js",
19
+ "exports": {
20
+ ".": "./lib/index.js",
21
+ "./package.json": "./package.json"
22
+ },
23
+ "dsh": {
24
+ "bundle": {
25
+ "patch": "./cordis.patch.yml"
26
+ }
27
+ },
28
+ "publishConfig": {
29
+ "access": "public",
30
+ "registry": "https://registry.npmjs.org/"
31
+ },
32
+ "peerDependencies": {
33
+ "@deepseek-ai/cordis": "^4.0.2",
34
+ "@deepseek-ai/dsh-agent": ">=0.1.5-rc.2 <0.1.6-0 || >=0.1.6-0 <0.2.0-0",
35
+ "@deepseek-ai/dsh-agent-default-model": ">=0.1.5-rc.2 <0.1.6-0 || >=0.1.6-0 <0.2.0-0",
36
+ "@deepseek-ai/dsh-brand": ">=0.1.5-rc.2 <0.1.6-0 || >=0.1.6-0 <0.2.0-0",
37
+ "@deepseek-ai/dsh-llm": ">=0.1.5-rc.2 <0.1.6-0 || >=0.1.6-0 <0.2.0-0",
38
+ "@deepseek-ai/dsh-session-title": ">=0.1.5-rc.2 <0.1.6-0 || >=0.1.6-0 <0.2.0-0",
39
+ "@deepseek-ai/dsh-tools": ">=0.1.5-rc.2 <0.1.6-0 || >=0.1.6-0 <0.2.0-0",
40
+ "@deepseek-ai/dsh-workspace": ">=0.1.5-rc.2 <0.1.6-0 || >=0.1.6-0 <0.2.0-0",
41
+ "@deepseek-ai/schemastery": "^3.18.2"
42
+ },
43
+ "files": [
44
+ "lib",
45
+ "cordis.patch.yml",
46
+ "README.md"
47
+ ]
48
+ }