@ryuu-64/dsh-session-tools 0.5.3 → 0.5.4
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 +5 -2
- package/lib/index.js +42 -13
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
|
|
29
29
|
默认发出即返回,返回只代表对方收到了、开始排队处理。消息来源标记为插件,不会被当成是你本人打的字。目标会话如果没开着,会被自动打开再把消息排进去。
|
|
30
30
|
|
|
31
|
-
填了 `wait` 就变成"发完等它做完",AI
|
|
31
|
+
填了 `wait` 就变成"发完等它做完",AI 拿到对方的回答之后可以接着往下办——比如让一个会话去跑测试,跑完再根据结果决定下一步。**等的是它处理完你刚发的这条消息**,不是"它现在不忙了"就算完。
|
|
32
32
|
|
|
33
33
|
## session_wait:等别的会话干完
|
|
34
34
|
|
|
@@ -57,7 +57,9 @@
|
|
|
57
57
|
| `idle` | 空闲,没在干活(开着或者躺着都算)。 |
|
|
58
58
|
| `archived` | 已归档,你把它从侧边栏收起来了。 |
|
|
59
59
|
|
|
60
|
-
子代理会话不会列出来(那是 AI
|
|
60
|
+
子代理会话不会列出来(那是 AI 自己派出去的活)。已归档的会话**会**列出来并标 `archived`——因为"已归档"只是你把它从侧边栏收起来了,它本身还在;AI 看到这个标记就知道那是你收起来的会话,可以据此决定要不要往里发消息。
|
|
61
|
+
|
|
62
|
+
`limit` 填得不合理会按合理值处理:填 0 或负数按 1 算,填超过 100 按 100 算,小数取整。
|
|
61
63
|
|
|
62
64
|
## 动手前会先问你
|
|
63
65
|
|
|
@@ -94,6 +96,7 @@ dsh plugin --profile desktop add link:C:\path\to\dsh-session-tools
|
|
|
94
96
|
|
|
95
97
|
- **不会顺手新建工作区**。`workspacePath` 必须是已经存在的那个工作区的路径;写错了它会报错,并把现有的工作区列出来给你挑。
|
|
96
98
|
- **不能给子代理发消息**。目标必须是普通会话;AI 派出去的子代理要用 `send_message`。也不能给当前这个会话自己发。
|
|
99
|
+
- **关掉的会话要有工作目录才能唤醒**。发消息时如果目标会话没开着,插件会把它重新打开;但如果那条会话没记录工作目录,就打不开、发不进去,会明确告诉你原因。
|
|
97
100
|
- **重启期间收不到**。新建会话是立刻生效的;发出去的消息要等对方会话被打开处理,所以 DSH 得开着。等待也一样,DSH 关了就没法等。
|
|
98
101
|
- **归属定了就不能改**。会话归到哪个工作区是记在账上的,建完之后没法在工作区之间搬。
|
|
99
102
|
- **需要桌面版**。工作区归属靠桌面版才挂载的那个工作区服务,插件把它列为必需依赖,所以命令行无界面模式(headless)下这个插件不会加载。
|
package/lib/index.js
CHANGED
|
@@ -177,6 +177,38 @@ function sessionState(ctx, sessionId) {
|
|
|
177
177
|
return ctx.agents.get(sessionId)?.status === "running" ? "running" : "idle";
|
|
178
178
|
}
|
|
179
179
|
/**
|
|
180
|
+
* Wait until a message this plugin queued has been handed to the driver. A
|
|
181
|
+
* session can still report `idle` the instant the message is queued, and a wait
|
|
182
|
+
* that accepts that would return the answer from the PREVIOUS turn — so the
|
|
183
|
+
* condition is "this message left the inbox AND the session is idle again".
|
|
184
|
+
*
|
|
185
|
+
* The inbox is public Agent surface: `inbox.nextTurn` is a readonly list of the
|
|
186
|
+
* messages still waiting, and each carries its own id.
|
|
187
|
+
* @param agent - the live target agent.
|
|
188
|
+
* @param messageId - the id of the message we just queued.
|
|
189
|
+
* @param budgetMs - how long to keep polling before giving up.
|
|
190
|
+
* @returns true when the message was taken, false on timeout.
|
|
191
|
+
*/
|
|
192
|
+
async function waitUntilConsumed(agent, messageId, budgetMs) {
|
|
193
|
+
const deadline = Date.now() + budgetMs;
|
|
194
|
+
const stillQueued = () => {
|
|
195
|
+
const pending = agent.inbox?.nextTurn;
|
|
196
|
+
// An unrecognisable inbox shape cannot prove anything; report a timeout
|
|
197
|
+
// rather than a completion we did not observe.
|
|
198
|
+
if (!Array.isArray(pending)) return undefined;
|
|
199
|
+
return pending.some((queued) => queued?.id === messageId);
|
|
200
|
+
};
|
|
201
|
+
for (;;) {
|
|
202
|
+
const queued = stillQueued();
|
|
203
|
+
if (queued === false && agent.status !== "running") return true;
|
|
204
|
+
if (queued === undefined) return false;
|
|
205
|
+
if (Date.now() >= deadline) return false;
|
|
206
|
+
await new Promise((resolve) => {
|
|
207
|
+
setTimeout(resolve, 25);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
180
212
|
* Get the live agent for a target session, opening the session again when it is
|
|
181
213
|
* not currently running. The session is reopened on the preset it was created
|
|
182
214
|
* with.
|
|
@@ -197,7 +229,7 @@ async function resolveTargetAgent(ctx, sessionId, callerAgent) {
|
|
|
197
229
|
throw new Error(`session_send cannot read ${JSON.stringify(sessionId)}: ${error instanceof Error ? error.message : String(error)}`);
|
|
198
230
|
}
|
|
199
231
|
if (record === void 0) throw new Error(`session_send cannot find session ${JSON.stringify(sessionId)}: no open or saved session has that id`);
|
|
200
|
-
if (record.header.cwd === void 0) throw new Error(`session_send cannot open ${JSON.stringify(sessionId)}:
|
|
232
|
+
if (record.header.cwd === void 0) throw new Error(`session_send cannot open ${JSON.stringify(sessionId)}: this saved session does not record a working directory, and reopening it needs one. Send to a session that has a directory, or ask the person to open that session once.`);
|
|
201
233
|
const agentPresets = ctx.get("agentPresets");
|
|
202
234
|
const presetId = record.header.agentPreset;
|
|
203
235
|
const setup = agentPresets === void 0 || presetId === void 0 ? void 0 : async (agentCtx) => {
|
|
@@ -419,7 +451,7 @@ function apply(ctx) {
|
|
|
419
451
|
// Ask before writing into another session: the person should see a message
|
|
420
452
|
// arrive in a conversation they are not looking at.
|
|
421
453
|
await requireApproval(ctx, exec, `send a message into session ${JSON.stringify(targetId)}: ${message.slice(0, 120)}`);
|
|
422
|
-
|
|
454
|
+
const sent = createUserMessage({
|
|
423
455
|
content: [{
|
|
424
456
|
type: "text",
|
|
425
457
|
text: message
|
|
@@ -428,28 +460,25 @@ function apply(ctx) {
|
|
|
428
460
|
kind: "plugin",
|
|
429
461
|
plugin: name
|
|
430
462
|
}
|
|
431
|
-
})
|
|
463
|
+
});
|
|
464
|
+
target.followup(sent);
|
|
432
465
|
if (args.wait !== true) return {
|
|
433
466
|
sessionId: targetId,
|
|
434
467
|
cwd: String(target.session.header.cwd ?? "")
|
|
435
468
|
};
|
|
436
|
-
//
|
|
437
|
-
//
|
|
438
|
-
//
|
|
469
|
+
// Waiting for our own message, not merely for quiet. The agent can still
|
|
470
|
+
// look idle the instant the message is queued, so an idle wait alone
|
|
471
|
+
// would return the PREVIOUS answer; wait until this message has left the
|
|
472
|
+
// inbox first. Both signals are public Agent surface.
|
|
439
473
|
const startedAt = Date.now();
|
|
440
474
|
const timeoutMs = waitBudgetMs(args.timeoutMs);
|
|
441
|
-
const
|
|
442
|
-
target.whenIdle().then(() => false),
|
|
443
|
-
new Promise((resolve) => {
|
|
444
|
-
setTimeout(() => resolve(true), timeoutMs);
|
|
445
|
-
})
|
|
446
|
-
]);
|
|
475
|
+
const consumed = await waitUntilConsumed(target, sent.id, timeoutMs);
|
|
447
476
|
const answer = await readFinalAnswer(ctx, targetId);
|
|
448
477
|
return {
|
|
449
478
|
sessionId: targetId,
|
|
450
479
|
cwd: String(target.session.header.cwd ?? ""),
|
|
451
480
|
waited: true,
|
|
452
|
-
completed:
|
|
481
|
+
completed: consumed,
|
|
453
482
|
elapsedMs: Date.now() - startedAt,
|
|
454
483
|
...answer === void 0 ? {} : { output: answer }
|
|
455
484
|
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ryuu-64/dsh-session-tools",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
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",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "node --test \"test/**/*.test.mjs\"",
|
|
9
|
+
"check": "node --check lib/index.js && node --check lib/client.js && npm test"
|
|
10
|
+
},
|
|
7
11
|
"keywords": [
|
|
8
12
|
"deepseek-harness",
|
|
9
13
|
"dsh",
|