dsh-im-lark 0.1.5 → 0.1.6

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.en.md CHANGED
@@ -93,7 +93,7 @@ Static config lives in the profile patch; restart to apply:
93
93
  maxText: 2000 # max characters per message; longer text is split automatically
94
94
  typingIndicator: true # Get on receipt; DONE on the original message after delivery (Get is never removed)
95
95
  replyStatus: false # append model, elapsed time and tokens to the answer
96
- directBusyMode: steer # a message arriving mid-turn in standalone mode: steer / queue (legacy interrupt migrates to steer)
96
+ directBusyMode: steer # all standalone sends while the target turn is running: steer / queue (legacy interrupt migrates to steer; /queue always queues)
97
97
  directWorkspaceId: '' # workspace id for standalone sessions; empty uses the auto-created default
98
98
  questionReminders: true # standalone: send a Feishu reminder when a question or approval is waiting
99
99
  questionDelayMinutes: 5 # how long to wait before reminding (0–120): answering in the Web UI within this window avoids it
@@ -115,9 +115,10 @@ Items editable in the panel are written to `$DSH_HOME/.dsh-im-lark/config.json`
115
115
  | `/status` | Current session and runtime state |
116
116
  | `/stop` | Abort the running turn |
117
117
  | `/trace` | Model and elapsed time of the last answer |
118
- | `/send <index, 0, or session id> <text>` | Send to that session; its answer comes back here. `0` is the front session. Images allowed |
118
+ | `/send <index, 0, or session id> <text>` | Send to that session; its answer comes back here. `0` is the front session. Images allowed; mid-turn behavior follows the steer setting |
119
+ | `/queue <index, 0, or session id> <text>` | Same as `/send`, but always queues until the target's current turn ends |
119
120
 
120
- `/send` is queued, so it does not interrupt the target session's running turn; sending to the current session behaves like a normal message. A `/switch` binding and its prefix survive restarts and are cleared by `/new`; after switching to a non-front session, replies are prefixed with `**session name>**`, and returning to the front session (index `0`) drops it. The front session is always index `0` and is omitted from `/sessions`, so returning to it does not produce a self-referential list. Switching is refused while that session still has a `/send` waiting for its answer. If an older `direct.json` has no front-session record, `/switch 0` asks you to start a new session with `/new`.
121
+ `/send` behaves like a normal message: while the target session is running a turn, the panel's steer setting decides whether it joins that turn or queues. `/queue` takes the same arguments but always queues until the current turn ends, regardless of the setting. A `/switch` binding and its prefix survive restarts and are cleared by `/new`; after switching to a non-front session, replies are prefixed with `**session name>**`, and returning to the front session (index `0`) drops it. The front session is always index `0` and is omitted from `/sessions`, so returning to it does not produce a self-referential list. Switching is refused while a delivery is still waiting for its answer. If an older `direct.json` has no front-session record, `/switch 0` asks you to start a new session with `/new`.
121
122
 
122
123
  ## CLI and slash command
123
124
 
package/README.md CHANGED
@@ -104,7 +104,7 @@ dsh plugin --profile web add file:/绝对路径/dsh-im-lark
104
104
  maxText: 2000 # 单条消息字符上限,超出自动切段
105
105
  typingIndicator: true # 收到打 Get;回答送达后原消息追加 DONE(Get 不撤)
106
106
  replyStatus: false # 回答末尾附加模型、耗时、token
107
- directBusyMode: steer # 独立会话里回合进行中又来消息:steer 插话 / queue 排队(旧值 interrupt 会迁移成 steer)
107
+ directBusyMode: steer # 独立模式所有发送在目标回合进行中:steer 插话 / queue 排队(旧值 interrupt 迁移成 steer;/queue 固定排队)
108
108
  directWorkspaceId: '' # 独立会话的工作区 id;留空用自动创建的默认工作区
109
109
  questionReminders: true # 独立模式下有问题/授权在等时发飞书提醒
110
110
  questionDelayMinutes: 5 # 提醒前等多久(0–120):这段时间在 Web 端答完就不打扰
@@ -126,9 +126,10 @@ dsh plugin --profile web add file:/绝对路径/dsh-im-lark
126
126
  | `/status` | 当前会话与运行状态 |
127
127
  | `/stop` | 中止正在跑的回合 |
128
128
  | `/trace` | 查看上一条回答的模型与耗时 |
129
- | `/send <序号、0 或会话 id> <内容>` | 发到指定会话,那一轮的回答回到这里;`0` 是前台会话;可附图 |
129
+ | `/send <序号、0 或会话 id> <内容>` | 发到指定会话,那一轮的回答回到这里;`0` 是前台会话;可附图;回合正在跑时按「回合内插话」设置处理 |
130
+ | `/queue <序号、0 或会话 id> <内容>` | 与 `/send` 相同,但始终排队到目标当前回合之后 |
130
131
 
131
- `/send` 用排队提交,不打断目标会话正在跑的回合;目标是当前会话时与直接发消息一致。`/switch` 的换绑与前缀会跨重启保留,`/new` 会清掉;切到非前台会话后,回复前会加 `**会话名>**`,切回前台(序号 `0`)后前缀消失。前台会话固定为序号 `0`,不出现在 `/sessions` 里,避免回到前台后列表里又套一个自己。目标会话还有 `/send` 在等回答时不允许切换。旧版 `direct.json` 没有前台记录时,`/switch 0` 会提示用 `/new` 重新建会话。
132
+ `/send` 与普通消息一样,在目标会话正在跑回合时按面板的「回合内插话」设置决定插进当前回合还是排队;`/queue` 参数相同,但始终排队到当前回合之后,不受该设置影响。`/switch` 的换绑与前缀会跨重启保留,`/new` 会清掉;切到非前台会话后,回复前会加 `**会话名>**`,切回前台(序号 `0`)后前缀消失。前台会话固定为序号 `0`,不出现在 `/sessions` 里,避免回到前台后列表里又套一个自己。目标会话还有投递在等回答时不允许切换。旧版 `direct.json` 没有前台记录时,`/switch 0` 会提示用 `/new` 重新建会话。
132
133
 
133
134
  ## 命令行与斜杠命令
134
135
 
@@ -1,5 +1,7 @@
1
1
  # 0008 独立模式 /send 按会话序号投递
2
2
 
3
+ > 提交模式部分已被 [0011](0011-独立模式send遵循插话设置与queue命令.md) 取代:`/send` 现在遵循「回合内插话」,固定排队用 `/queue`。序号快照、回答回收与超时等决定仍有效。
4
+
3
5
  ## 背景
4
6
 
5
7
  独立模式最初的 `/send <文本>` 只是把文本回显到当前聊天,与核心模式的
@@ -0,0 +1,29 @@
1
+ # 0011 独立模式 /send 遵循插话设置与 /queue 固定排队
2
+
3
+ ## 背景
4
+
5
+ 0008 让 `/send` 固定用 `queue` 提交,面板的「回合内插话」只影响普通消息和发到当前会话的 `/send`。主人希望同一个开关覆盖所有发送,同时保留一个明确不打断目标回合的投递方式。
6
+
7
+ ## 决策
8
+
9
+ - 「回合内插话」作用于独立模式的所有发送:普通消息、`/send` 到当前会话、`/send` 到其它会话。目标回合正在跑时,`steer` 插进当前回合,`queue` 排到下一轮。
10
+ - 新增 `/queue <序号、0 或会话 id> <内容>`,参数与 `/send` 相同,固定用 `queue`,不受面板设置影响。
11
+ - `/send` 与 `/queue` 共用会话定位、图片、回答观察与 `DONE` 对齐,只有提交模式不同。排队且目标正在跑时跳过上一轮的 `turn/end`;插话时当前 `turn/end` 就是这一条的回答。
12
+ - 排队一律按「先跳过目标当前那一轮」对齐(不看列表快照是否说在跑):目标要么先发 `turn/start`,要么这一轮 `turn/end` 直接被跳过,快照过期也不会把别人的回答当成自己的。
13
+ - 当前绑定会话的「正在跑」以 `turn/start`/`turn/end` 维护的状态为准(比列表快照新):排队消息在提交时已知目标在跑,就不随那一轮打 `DONE`,等它自己那轮结束再补。
14
+ - 面板提示写明 `/queue` 始终排队;两个命令在等回答时都拒绝同目标的第二条投递与 `/switch`。
15
+
16
+ ## 后果
17
+
18
+ - 已知限制一:`steer` 的判断依赖提交前一刻的运行状态;列表说空闲、提交时目标已在跑(Web 端刚发起)时,这一条仍可能被并进别人的回合,回答与 `DONE` 归属只能靠事件顺序推断。宿主事件没有可对账的 prompt id(`turn/start` 只有 `{turn}`),这一层无法消除。
19
+ - 已知限制二:排队消息的 `waiting` 是提交前读到「正在跑」时打的一次性标记。若那一轮恰好在提交等待期间结束,标记会留到它自己那轮结束时才被清掉,表现为这条漏打 `DONE`(漏打优于误打);根治可用事件里已有的 `turn` 号对账(`turn/start` 与 `turn/end` 的 data 都带 `turn`),当前实现未用。
20
+
21
+ - 默认 `steer` 下,`/send` 到正在跑的其它会话也会插话,可能改变目标当前回合;需要不打断时用 `/queue`。
22
+ - `/queue` 保留 0008 的固定排队语义;0008 关于序号快照、回答回收、超时的其余决定继续有效。
23
+ - 主人可以用命令显式选择是否排队,不必先改面板设置。
24
+
25
+ ## 备选
26
+
27
+ - 保留 `/send` 固定 `queue`,只把设置扩到普通消息:不满足「所有发送」。
28
+ - 用 `/send --queue` 参数:与「第一个空白前是会话引用」的解析冲突,也不直观。
29
+ - 新增一个独立的 `/queue` 会话命令:参数与 `/send` 重复,未采用。
@@ -15,6 +15,7 @@
15
15
  | [0008](0008-独立模式send按会话序号投递.md) | 独立模式 `/send` 按会话序号投递 | 已接受 |
16
16
  | [0009](0009-独立模式switch切换并标记回复来源.md) | 独立模式 `/switch` 切换会话并标记回复来源 | 已接受 |
17
17
  | [0010](0010-独立模式前台会话与switch-0.md) | 独立模式的前台会话与 `/switch 0` | 已接受 |
18
+ | [0011](0011-独立模式send遵循插话设置与queue命令.md) | 独立模式 `/send` 遵循插话设置,新增 `/queue` | 已接受 |
18
19
 
19
20
  新增决策时:编号连续、标题用「做了什么」而不是「为什么」、状态只有
20
21
  `提议 / 已接受 / 已废弃 / 被 NNNN 取代`。改主意不要改旧 ADR 的结论,追加新的一条
package/lib/client.js CHANGED
@@ -147,7 +147,7 @@ var en_default = {
147
147
  "direct.summaryCore": "Switched to the super agent; these settings no longer apply",
148
148
  "direct.groupSession": "Session",
149
149
  "direct.steer": "Steer the running turn",
150
- "direct.steerHint": "A message sent mid-turn joins the current turn; off means it queues until the turn ends.",
150
+ "direct.steerHint": "Regular messages and /send join a running turn; turn this off to queue until the turn ends. /queue always queues and ignores this switch.",
151
151
  "direct.workspace": "Session workspace",
152
152
  "direct.workspaceHint": "Where new sessions are created; send /new to apply.",
153
153
  "direct.workspaceDefault": "Default (Lark session)",
@@ -259,7 +259,7 @@ var zh_default = {
259
259
  "direct.summaryCore": "\u5DF2\u5207\u6362\u5230\u8D85\u7EA7\u52A9\u7406\uFF0C\u6B64\u5904\u914D\u7F6E\u4E0D\u518D\u751F\u6548",
260
260
  "direct.groupSession": "\u4F1A\u8BDD",
261
261
  "direct.steer": "\u56DE\u5408\u5185\u63D2\u8BDD",
262
- "direct.steerHint": "\u56DE\u5408\u6B63\u5728\u8DD1\u65F6\u53C8\u53D1\u6D88\u606F\uFF0C\u76F4\u63A5\u63D2\u8FDB\u5F53\u524D\u56DE\u5408\uFF1B\u5173\u6389\u5219\u6392\u961F\u7B49\u8FD9\u4E00\u8F6E\u7ED3\u675F\u3002",
262
+ "direct.steerHint": "\u666E\u901A\u6D88\u606F\u4E0E /send \u5728\u76EE\u6807\u56DE\u5408\u6B63\u5728\u8DD1\u65F6\u76F4\u63A5\u63D2\u8FDB\u5F53\u524D\u56DE\u5408\uFF1B\u5173\u6389\u5219\u6392\u961F\u7B49\u8FD9\u4E00\u8F6E\u7ED3\u675F\u3002/queue \u59CB\u7EC8\u6392\u961F\uFF0C\u4E0D\u53D7\u6B64\u5F00\u5173\u5F71\u54CD\u3002",
263
263
  "direct.workspace": "\u4F1A\u8BDD\u5DE5\u4F5C\u533A",
264
264
  "direct.workspaceHint": "\u65B0\u4F1A\u8BDD\u5EFA\u5728\u54EA\u4E2A\u5DE5\u4F5C\u533A\uFF1B\u6539\u5B8C\u53D1 /new \u751F\u6548\u3002",
265
265
  "direct.workspaceDefault": "\u9ED8\u8BA4\uFF08\u98DE\u4E66\u4F1A\u8BDD\uFF09",
@@ -14,7 +14,7 @@ import { DEFAULT_MAX_TEXT_CHARS } from "../shared/limits.js";
14
14
  import { readJsonIfPresent, writePrivateFile } from "./state/files.js";
15
15
  import { resolveDataDir } from "./state/paths.js";
16
16
  import { DEFAULT_LONG_TASK_MINUTES, normalizeLongTaskMinutes } from "./long-tasks.js";
17
- /** 默认插话:主人发消息通常是想马上纠正方向,排队会让这条消息过时。 */
17
+ /** 默认插话:主人发消息通常是想马上纠正方向,排队会让这条消息过时;`/queue` 不受此设置影响。 */
18
18
  export const DEFAULT_DIRECT_BUSY_MODE = 'steer';
19
19
  /** 问题与审批提醒:默认开。 */
20
20
  export const DEFAULT_QUESTION_REMINDERS = true;
@@ -1,25 +1,29 @@
1
1
  export class DoneAlign {
2
2
  /** 已提交、尚无定论的消息,按提交顺序。 */
3
3
  #pending = [];
4
- /** 提交成功(已入会话)后登记。 */
5
- push(messageId, mode) {
6
- this.#pending.push({ messageId, mode });
4
+ /** 提交成功(已入会话)后登记。`waiting` 表示它排在别人正跑的那一轮之后。 */
5
+ push(messageId, mode, waiting = false) {
6
+ this.#pending.push({ messageId, mode, waiting: waiting && mode === 'queue' });
7
7
  }
8
8
  /**
9
9
  * 一轮结束:出队本轮应答的消息(平台消息 id)。
10
10
  * 交付失败时调用方仍要结算(这一轮已经消耗掉它们),只是不盖完成标记。
11
11
  */
12
12
  settle() {
13
- const head = this.#pending.shift();
13
+ const head = this.#pending[0];
14
14
  if (head === undefined)
15
15
  return [];
16
- const settled = [head.messageId];
17
- // 队头之后、连续提交的 steer 消息已被这一轮在步骤边界吸收。
18
- while (this.#pending[0]?.mode === 'steer') {
19
- const absorbed = this.#pending.shift();
20
- if (absorbed !== undefined)
21
- settled.push(absorbed.messageId);
16
+ if (head.waiting) {
17
+ // 这一轮是队头排的那一轮,不是它自己:它现在才轮到,只结算被本轮吸收的 steer。
18
+ head.waiting = false;
19
+ return this.#takeAbsorbed(1);
22
20
  }
21
+ this.#pending.shift();
22
+ const settled = [head.messageId, ...this.#takeAbsorbed()];
23
+ // 队头这一轮结束后,紧随的排队消息自己的一轮随即开始,不再等别人的 `turn/end`。
24
+ const next = this.#pending[0];
25
+ if (next?.mode === 'queue')
26
+ next.waiting = false;
23
27
  return settled;
24
28
  }
25
29
  /**
@@ -29,4 +33,17 @@ export class DoneAlign {
29
33
  clear() {
30
34
  this.#pending.length = 0;
31
35
  }
36
+ /**
37
+ * 取走 `start` 起连续提交的 steer 条目:它们已被刚结束的这一轮在步骤边界吸收。
38
+ * 默认从队头扫;`waiting` 分支队头要留下,就从它的下一条开始。
39
+ */
40
+ #takeAbsorbed(start = 0) {
41
+ const settled = [];
42
+ while (this.#pending[start]?.mode === 'steer') {
43
+ const absorbed = this.#pending.splice(start, 1)[0];
44
+ if (absorbed !== undefined)
45
+ settled.push(absorbed.messageId);
46
+ }
47
+ return settled;
48
+ }
32
49
  }
@@ -12,7 +12,8 @@ export const SESSION_PAGE_SIZE = 10;
12
12
  const TITLE_MAX = 32;
13
13
  const ID_SHOWN = 8;
14
14
  const SESSION_PREFIX = 'session-';
15
- export const SEND_USAGE = '用法:`/send <序号、0 或会话 id> <内容>`。先发 `/sessions` 看序号(`0` 是前台会话)。';
15
+ export const SEND_USAGE = '用法:`/send <序号、0 或会话 id> <内容>`。先发 `/sessions` 看序号(`0` 是前台会话);回合正在跑时按「回合内插话」设置决定插话或排队。';
16
+ export const QUEUE_USAGE = '用法:`/queue <序号、0 或会话 id> <内容>`。与 `/send` 相同,但始终排队到目标当前回合之后。';
16
17
  export const SWITCH_USAGE = '用法:`/switch <序号、0、front 或会话 id>`;`0` 与 `front` 回到前台会话。';
17
18
  /** 没有前台会话时的提示:有绑定说明是旧记录丢了,不能再让人发消息等新建。 */
18
19
  export function frontMissingHint(hasBinding) {
@@ -92,7 +93,7 @@ export function renderSessionList(view) {
92
93
  if (view.page < view.pages)
93
94
  lines.push(`发 \`/sessions ${view.page + 1}\` 看下一页。`, '');
94
95
  const frontTip = view.hasFront === true ? '`/switch 0` 回到前台会话,`/send 0` 发到前台;' : '';
95
- lines.push(`发 \`/switch <序号>\` 切换会话,${frontTip}\`/send <序号>\` 发到某个会话,那一轮的回答回到这里。序号在下次发 \`/sessions\` 之前不变。`);
96
+ lines.push(`发 \`/switch <序号>\` 切换会话,${frontTip}\`/send <序号>\` 发到某个会话(\`/queue\` 始终排队),那一轮的回答回到这里。序号在下次发 \`/sessions\` 之前不变。`);
96
97
  return lines.join('\n');
97
98
  }
98
99
  /**
@@ -1,11 +1,11 @@
1
1
  /**
2
- * `/send` 的回答观察者:盯住目标会话的这一轮,结束后把回答发回飞书。
2
+ * `/send` 与 `/queue` 的回答观察者:盯住目标会话的这一轮,结束后把回答发回飞书。
3
3
  *
4
4
  * 事件来自宿主的 `session/event`(一个监听器覆盖所有会话,不为每个会话单独订阅)。
5
5
  * 回调里只做状态折叠(同步、不抛),发送放进按会话串行的队列:同一会话先结束的
6
6
  * 回合先发,不乱序。
7
7
  *
8
- * 目标会话正在跑时用排队提交:先到的 `turn/end` 属于上一轮,不能当成这一轮的回答。
8
+ * 排队且目标会话正在跑时,先到的 `turn/end` 属于上一轮,不能当成这一轮的回答。
9
9
  */
10
10
  import { asRecord, textFromAssistantMessage } from "./session-text.js";
11
11
  const SEND_TIMEOUT_MS = 30 * 60_000;
@@ -41,7 +41,7 @@ export class SendWatcher {
41
41
  this.#setTimer = options.setTimer ?? defaultSetTimer;
42
42
  this.#clearTimer = options.clearTimer ?? defaultClearTimer;
43
43
  }
44
- /** 受理一次 `/send`:`queued` 表示目标会话正在跑、这一条排在后面。 */
44
+ /** 受理一次投递:`queued` 表示目标会话正在跑、这一条排在后面。 */
45
45
  track(sessionId, title, target, queued = false) {
46
46
  if (this.#watches.has(sessionId))
47
47
  return 'busy';
@@ -53,7 +53,7 @@ export class SendWatcher {
53
53
  this.#turns.set(sessionId, { answer: '' });
54
54
  return 'ok';
55
55
  }
56
- /** 这个会话是否还有 `/send` 在等回答(切换前要拦)。 */
56
+ /** 这个会话是否还有投递在等回答(切换前要拦)。 */
57
57
  has(sessionId) {
58
58
  return this.#watches.has(sessionId);
59
59
  }
@@ -72,7 +72,7 @@ export class SendWatcher {
72
72
  this.#apply(sessionId, asRecord(event));
73
73
  }
74
74
  catch (error) {
75
- this.#logger?.warn?.('独立模式 /send 事件处理失败', error instanceof Error ? error.message : String(error));
75
+ this.#logger?.warn?.('独立模式投递事件处理失败', error instanceof Error ? error.message : String(error));
76
76
  }
77
77
  }
78
78
  /** 停机:只收定时器;没发完的推送不再等。 */
@@ -144,7 +144,7 @@ export class SendWatcher {
144
144
  else
145
145
  text = `来自会话「${title}」:\n\n${answer}`;
146
146
  const sent = await this.#deliver(watch.target, text).catch((error) => {
147
- this.#logger?.warn?.('独立模式 /send 推送失败', error instanceof Error ? error.message : String(error));
147
+ this.#logger?.warn?.('独立模式投递推送失败', error instanceof Error ? error.message : String(error));
148
148
  return false;
149
149
  });
150
150
  // 只有正常收尾且真的发出了回答才补 DONE;失败/中止/无文本都不给假信号。
@@ -161,7 +161,7 @@ export class SendWatcher {
161
161
  const minutes = Math.round(this.#timeoutMs / 60_000);
162
162
  this.#enqueue(sessionId, async () => {
163
163
  await this.#deliver(watch.target, `「${watch.title || UNTITLED}」这一轮没有在 ${minutes} 分钟内结束,不再等它了。`).catch((error) => {
164
- this.#logger?.warn?.('独立模式 /send 超时提示发送失败', error instanceof Error ? error.message : String(error));
164
+ this.#logger?.warn?.('独立模式投递超时提示发送失败', error instanceof Error ? error.message : String(error));
165
165
  return false;
166
166
  });
167
167
  });
@@ -170,7 +170,7 @@ export class SendWatcher {
170
170
  #enqueue(sessionId, task) {
171
171
  const previous = this.#queues.get(sessionId) ?? Promise.resolve();
172
172
  const next = previous.then(task).catch((error) => {
173
- this.#logger?.warn?.('独立模式 /send 推送失败', error instanceof Error ? error.message : String(error));
173
+ this.#logger?.warn?.('独立模式投递推送失败', error instanceof Error ? error.message : String(error));
174
174
  });
175
175
  this.#queues.set(sessionId, next);
176
176
  void next.finally(() => {
@@ -4,8 +4,8 @@
4
4
  * 纯函数、不碰会话状态,与 `standalone.ts` 的会话编排分开——命令表会随功能长,
5
5
  * 编排代码读起来才不用来回翻命令分支。
6
6
  *
7
- * `/send` 的参数按「第一个空白前是会话引用、后面全是内容」解析,内容里的换行与
8
- * 连续空格原样保留:发给目标会话的是主人写的那段话,不是压平后的一行。
7
+ * `/send` 与 `/queue` 的参数按「第一个空白前是会话引用、后面全是内容」解析,内容里的
8
+ * 换行与连续空格原样保留:发给目标会话的是主人写的那段话,不是压平后的一行。
9
9
  */
10
10
  // 命令名后面必须是空白或结尾:`/sendabc` 不会被当成 `/send`,会落到未知命令。
11
11
  const COMMAND_PATTERN = /^\/([a-z][\w-]*)(?:\s+([\s\S]*))?$/i;
@@ -31,7 +31,9 @@ export function parseCommand(input) {
31
31
  case 'trace':
32
32
  return { kind: 'trace' };
33
33
  case 'send':
34
- return parseSend(rest);
34
+ return parseDelivery('send', rest);
35
+ case 'queue':
36
+ return parseDelivery('queue', rest);
35
37
  case 'sessions':
36
38
  return parseSessions(rest);
37
39
  case 'switch':
@@ -40,13 +42,13 @@ export function parseCommand(input) {
40
42
  return { kind: 'unknown', name };
41
43
  }
42
44
  }
43
- function parseSend(rest) {
45
+ function parseDelivery(kind, rest) {
44
46
  if (rest === '')
45
- return { kind: 'send', ref: '', text: '' };
47
+ return { kind, ref: '', text: '' };
46
48
  const space = rest.search(/\s/);
47
49
  if (space < 0)
48
- return { kind: 'send', ref: rest, text: '' };
49
- return { kind: 'send', ref: rest.slice(0, space), text: rest.slice(space + 1).trim() };
50
+ return { kind, ref: rest, text: '' };
51
+ return { kind, ref: rest.slice(0, space), text: rest.slice(space + 1).trim() };
50
52
  }
51
53
  function parseSessions(rest) {
52
54
  if (rest === '')
@@ -64,7 +66,8 @@ export const HELP_TEXT = [
64
66
  '`/new` 开新会话',
65
67
  '`/sessions [页码]` 列出最近会话与序号(不含前台会话)',
66
68
  '`/switch <序号、0、front 或会话 id>` 切换当前会话;`0` 与 `front` 回到前台会话',
67
- '`/send <序号、0 或会话 id> <内容>` 发到指定会话,那一轮的回答回到这里',
69
+ '`/send <序号、0 或会话 id> <内容>` 发到指定会话;目标回合正在跑时按「回合内插话」设置处理',
70
+ '`/queue <序号、0 或会话 id> <内容>` 与 `/send` 相同,但始终排队到目标当前回合之后',
68
71
  '`/status` 当前会话与连接状态',
69
72
  '`/stop` 中止正在跑的回合',
70
73
  '`/trace` 上一条回答的模型与耗时',
@@ -1,25 +1,28 @@
1
1
  /**
2
- * `/send` 的编排:定位会话、分流当前会话、提交并登记回答观察。
2
+ * `/send` 与 `/queue` 的编排:定位会话、分流当前会话、提交并登记回答观察。
3
3
  *
4
4
  * 与 `standalone.ts` 分开,避免会话编排被命令细节撑大;这里只通过端口拿状态与
5
5
  * 发消息,不自己持有任何字段。
6
6
  */
7
7
  import { randomUUID } from 'node:crypto';
8
8
  import { buildContent } from "./prompt-content.js";
9
- import { SEND_USAGE, frontMissingHint, isFrontRef, loadSessionCatalog, resolveSessionRef, sessionLabel, } from "./session-list.js";
9
+ import { QUEUE_USAGE, SEND_USAGE, frontMissingHint, isFrontRef, loadSessionCatalog, resolveSessionRef, sessionLabel, } from "./session-list.js";
10
10
  import { frontSessionOf } from "./state/direct.js";
11
11
  /**
12
- * 执行 `/send`;返回 `true` 表示还有一轮回答在路上(先别给命令消息补 `DONE`)。
12
+ * 执行 `/send` 或 `/queue`;返回 `true` 表示还有一轮回答在路上(先别给命令消息补 `DONE`)。
13
13
  *
14
14
  * 目标是当前会话时走普通提交,回答由绑定会话的回合逻辑发回;目标是其它会话时
15
15
  * 登记观察者,等它 `turn/end` 再发回来。两条路都不切换绑定。
16
16
  */
17
17
  export async function handleSendCommand(command, messageId, draft, host) {
18
+ const forceQueue = command.kind === 'queue';
18
19
  const images = draft.images ?? [];
19
20
  if (command.ref === '' || (command.text === '' && images.length === 0)) {
20
- await host.reply(SEND_USAGE);
21
+ await host.reply(forceQueue ? QUEUE_USAGE : SEND_USAGE);
21
22
  return false;
22
23
  }
24
+ // `/queue` 固定排队;`/send` 与普通消息一样遵循面板设置。
25
+ const mode = forceQueue ? 'queue' : host.busyMode();
23
26
  const controller = host.controller();
24
27
  if (controller === null) {
25
28
  await host.reply('独立模式不可用:宿主没有会话控制器。');
@@ -52,22 +55,28 @@ export async function handleSendCommand(command, messageId, draft, host) {
52
55
  }
53
56
  picked = resolved;
54
57
  }
58
+ // 当前绑定会话的回合状态由事件维护,比列表快照准;提交前先取,免得被这一轮的 turn/start 覆盖。
55
59
  if (binding !== null && binding.sessionId === picked.sessionId) {
56
- const error = await host.submitCurrent(command.text, draft);
60
+ const running = host.isRunning();
61
+ const error = await host.submitCurrent(command.text, draft, mode);
57
62
  if (error !== null) {
58
63
  await host.reply(error);
59
64
  return false;
60
65
  }
61
- host.pushAlign(messageId);
62
- await host.reply(`已交给当前会话「${picked.title || '未命名会话'}」,回答照常发回这里。`);
66
+ // 排队且目标正忙时,下一个 turn/end 属于它排在后面的那一轮,不能提前结算。
67
+ host.pushAlign(messageId, mode, mode === 'queue' && running);
68
+ await host.reply(`已交给当前会话「${picked.title || '未命名会话'}」${waitNote(running, mode)},回答照常发回这里。`);
63
69
  return true;
64
70
  }
65
- // 列表里刚读到过它:运行中就走排队,先到的 turn/end 属于上一轮。
66
- const busy = catalog.sessions.find((row) => row.sessionId === picked.sessionId)?.running === true;
67
- const tracked = host.watcher.track(picked.sessionId, picked.title, { chatId: host.chatId, replyTo: messageId, platformMessageId: messageId }, busy);
71
+ // 其它会话只能看列表快照,提示按它写;DONE 对齐不依赖它。
72
+ const running = catalog.sessions.find((row) => row.sessionId === picked.sessionId)?.running === true;
73
+ // 排队时先用 watcher 的 pendingStart 跳过目标当前那一轮;turn/start 会清掉它,
74
+ // 所以这里不依赖快照的 running(快照可能已经过期)。插话进入当前回合,不跳过。
75
+ const queued = mode === 'queue';
76
+ const tracked = host.watcher.track(picked.sessionId, picked.title, { chatId: host.chatId, replyTo: messageId, platformMessageId: messageId }, queued);
68
77
  if (tracked !== 'ok') {
69
78
  await host.reply(tracked === 'busy'
70
- ? `已经有一个 /send 在等「${picked.title || '未命名会话'}」的回答,等它回来再发。`
79
+ ? `已经有一条投递在等「${picked.title || '未命名会话'}」的回答,等它回来再发。`
71
80
  : '同时等待的会话太多,等几条回答回来再发。');
72
81
  return false;
73
82
  }
@@ -76,7 +85,7 @@ export async function handleSendCommand(command, messageId, draft, host) {
76
85
  const accepted = await controller.prompt({
77
86
  requestId: randomUUID(),
78
87
  sessionId: picked.sessionId,
79
- mode: 'queue',
88
+ mode,
80
89
  content,
81
90
  clientTimeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
82
91
  }, AbortSignal.timeout(host.submitTimeoutMs));
@@ -86,12 +95,17 @@ export async function handleSendCommand(command, messageId, draft, host) {
86
95
  catch (error) {
87
96
  host.watcher.remove(picked.sessionId);
88
97
  const detail = error instanceof Error ? error.message : String(error);
89
- host.logger.warn?.('独立模式 /send 提交失败', detail);
98
+ host.logger.warn?.('独立模式投递提交失败', detail);
90
99
  await host.reply(`没能把消息交给会话:${detail}`);
91
100
  return false;
92
101
  }
93
- const queued = busy ? ',它正在运行,排在当前这一轮之后' : '';
94
102
  const dropped = (draft.files?.length ?? 0) > 0 ? ';文件没有转发' : '';
95
- await host.reply(`已交给会话「${picked.title || '未命名会话'}」${queued}${dropped},这一轮结束后把回答发给你。`);
103
+ await host.reply(`已交给会话「${picked.title || '未命名会话'}」${waitNote(running, mode)}${dropped},这一轮结束后把回答发给你。`);
96
104
  return true;
97
105
  }
106
+ /** 目标正在跑时的提示:排队说等下一轮,插话说进当前回合。 */
107
+ function waitNote(running, mode) {
108
+ if (!running)
109
+ return '';
110
+ return mode === 'queue' ? ',它正在运行,排在当前这一轮之后' : ',它正在运行,这条会插进当前回合';
111
+ }
@@ -48,7 +48,7 @@ export async function handleSwitchCommand(ref, host) {
48
48
  return;
49
49
  }
50
50
  if (host.watcher.has(picked.sessionId)) {
51
- await host.reply(`「${sessionLabel(picked.title)}」还有一条 /send 在等回答,等它回来再切换。`);
51
+ await host.reply(`「${sessionLabel(picked.title)}」还有一条投递在等回答,等它回来再切换。`);
52
52
  return;
53
53
  }
54
54
  const live = catalog.sessions.find((row) => row.sessionId === picked.sessionId);
@@ -110,7 +110,7 @@ async function switchToFront(controller, front, binding, host, catalog) {
110
110
  return;
111
111
  }
112
112
  if (host.watcher.has(front.sessionId)) {
113
- await host.reply(`「${sessionLabel(front.title)}」还有一条 /send 在等回答,等它回来再切换。`);
113
+ await host.reply(`「${sessionLabel(front.title)}」还有一条投递在等回答,等它回来再切换。`);
114
114
  return;
115
115
  }
116
116
  const title = (live?.title ?? '').trim() || front.title;
@@ -5,7 +5,7 @@
5
5
  * 只有核心不在/开关关掉时才会走到这里。所以这里不再判断「要不要让位」,只负责
6
6
  * 把消息变成会话输入、把回合结果发回飞书。
7
7
  *
8
- * 命令自己解析:`/help /new /sessions /switch /status /stop /send /trace`。不进
8
+ * 命令自己解析:`/help /new /sessions /switch /status /stop /send /queue /trace`。不进
9
9
  * 模型,也不写进会话历史。
10
10
  */
11
11
  import { randomUUID } from 'node:crypto';
@@ -96,20 +96,23 @@ export class StandaloneChat {
96
96
  const text = draft.text.trim();
97
97
  const command = parseCommand(text);
98
98
  if (command !== null) {
99
- // `/send` 要等目标会话那一轮结束才算处理完;其余命令当场就答完了。
99
+ // `/send`、`/queue` 要等目标会话那一轮结束才算处理完;其余命令当场就答完了。
100
100
  const awaiting = await this.#runCommand(command, message.messageId, draft);
101
101
  if (!awaiting)
102
102
  this.#markDone?.(message.messageId);
103
103
  return;
104
104
  }
105
- const showNotice = await this.#submit(text, draft);
105
+ // 提交前先记下「有没有别人的一轮在跑」:排队消息要等这一轮结束才是它的回合。
106
+ const mode = this.#busyMode();
107
+ const behindRunning = mode === 'queue' && this.#running;
108
+ const showNotice = await this.#submit(text, draft, mode);
106
109
  // 提交失败的通知不是完成:只留「收到」,不盖 DONE;回答要等回合结束。
107
110
  if (showNotice !== null)
108
111
  await this.#reply(showNotice);
109
112
  else
110
- this.#align.push(message.messageId, this.#busyMode());
113
+ this.#align.push(message.messageId, mode, behindRunning);
111
114
  }
112
- /** `session/event`:`/send` 的目标会话与绑定会话各走一条路。 */
115
+ /** `session/event`:投递目标会话与绑定会话各走一条路。 */
113
116
  handleEvent(sessionId, event) {
114
117
  this.#watcher.handleEvent(sessionId, event);
115
118
  const entry = asRecord(event);
@@ -208,14 +211,13 @@ export class StandaloneChat {
208
211
  this.#logger.info?.('独立模式:已把第一位私聊用户认作主人', message.senderOpenId);
209
212
  return true;
210
213
  }
211
- async #submit(text, draft) {
214
+ async #submit(text, draft, mode = this.#busyMode()) {
212
215
  const controller = this.#controller();
213
216
  if (controller === null)
214
217
  return '独立模式不可用:宿主没有会话控制器。消息没有进会话。';
215
218
  try {
216
219
  const sessionId = await this.#ensureSession(controller);
217
220
  const content = buildContent(text, draft);
218
- const mode = this.#busyMode();
219
221
  const accepted = await controller.prompt({ requestId: randomUUID(), sessionId, mode, content, clientTimeZone: Intl.DateTimeFormat().resolvedOptions().timeZone }, AbortSignal.timeout(this.#submitTimeoutMs));
220
222
  if (accepted.accepted === false)
221
223
  return '会话没有接受这条消息(可能已停止或已关闭)。';
@@ -285,6 +287,7 @@ export class StandaloneChat {
285
287
  : `上一条回答:模型 ${this.#lastTrace.model === '' ? '未知' : this.#lastTrace.model},耗时 ${formatDuration(this.#lastTrace.durationMs)}。`);
286
288
  return false;
287
289
  case 'send':
290
+ case 'queue':
288
291
  return handleSendCommand(command, messageId, draft, {
289
292
  controller: () => this.#controller(),
290
293
  listing: this.#listing,
@@ -293,8 +296,10 @@ export class StandaloneChat {
293
296
  chatId: this.#chatId,
294
297
  submitTimeoutMs: this.#submitTimeoutMs,
295
298
  logger: this.#logger,
296
- submitCurrent: (text, value) => this.#submit(text, value),
297
- pushAlign: (id) => this.#align.push(id, this.#busyMode()),
299
+ submitCurrent: (text, value, mode) => this.#submit(text, value, mode),
300
+ pushAlign: (id, mode, waiting) => this.#align.push(id, mode, waiting),
301
+ busyMode: () => this.#busyMode(),
302
+ isRunning: () => this.#running,
298
303
  reply: (text) => this.#reply(text),
299
304
  });
300
305
  case 'sessions':
@@ -332,7 +337,7 @@ export class StandaloneChat {
332
337
  '',
333
338
  `会话:${binding === null ? '还没有(发一条消息就会建)' : binding.title ?? binding.sessionId}`,
334
339
  `运行中:${this.#running ? '是' : '否'}`,
335
- `回合提交:${mode === 'queue' ? '排队' : '插话'}`,
340
+ `回合提交:${mode === 'queue' ? '排队' : '插话'}(\`/queue\` 固定排队)`,
336
341
  `控制器:${this.#controller() === null ? '不可用' : '就绪'}`,
337
342
  ].join('\n');
338
343
  }
@@ -355,7 +360,7 @@ export class StandaloneChat {
355
360
  return body;
356
361
  return `**${markLabel(sessionLabel(binding.title))}>**\n\n${body}`;
357
362
  }
358
- /** 发到指定会话;`/send` 的回答要回到发命令的那个聊天,不能跟着当前会话走。 */
363
+ /** 发到指定会话;`/send` 与 `/queue` 的回答要回到发命令的那个聊天,不能跟着当前会话走。 */
359
364
  async #deliverTo(chatId, text, replyTo) {
360
365
  if (chatId === '') {
361
366
  this.#logger.warn?.('独立模式回复没有目标会话,已丢弃');
@@ -373,11 +378,11 @@ export class StandaloneChat {
373
378
  }
374
379
  return true;
375
380
  }
376
- /** 停机:收掉 `/send` 的等待定时器。 */
381
+ /** 停机:收掉投递的等待定时器。 */
377
382
  stop() {
378
383
  this.#watcher.stop();
379
384
  }
380
- /** 等 `/send` 的推送与绑定写入落盘(测试与停机对齐用)。 */
385
+ /** 等投递的推送与绑定写入落盘(测试与停机对齐用)。 */
381
386
  async drain() {
382
387
  await this.#watcher.drain();
383
388
  await this.#bindings.drain();
@@ -5,7 +5,7 @@
5
5
  * 发布时三处同步——package.json、锁文件(`npm version --no-git-tag-version`)、
6
6
  * 这里。
7
7
  */
8
- export const PLUGIN_VERSION = '0.1.5';
8
+ export const PLUGIN_VERSION = '0.1.6';
9
9
  /** 传输层实现版本:协议客户端行为变化时递增,与插件版本解耦。 */
10
10
  export const CHANNEL_VERSION = '1';
11
11
  /**
package/locale/en.json CHANGED
@@ -78,7 +78,7 @@
78
78
  "direct.summaryCore": "Switched to the super agent; these settings no longer apply",
79
79
  "direct.groupSession": "Session",
80
80
  "direct.steer": "Steer the running turn",
81
- "direct.steerHint": "A message sent mid-turn joins the current turn; off means it queues until the turn ends.",
81
+ "direct.steerHint": "Regular messages and /send join a running turn; turn this off to queue until the turn ends. /queue always queues and ignores this switch.",
82
82
  "direct.workspace": "Session workspace",
83
83
  "direct.workspaceHint": "Where new sessions are created; send /new to apply.",
84
84
  "direct.workspaceDefault": "Default (Lark session)",
package/locale/zh.json CHANGED
@@ -78,7 +78,7 @@
78
78
  "direct.summaryCore": "已切换到超级助理,此处配置不再生效",
79
79
  "direct.groupSession": "会话",
80
80
  "direct.steer": "回合内插话",
81
- "direct.steerHint": "回合正在跑时又发消息,直接插进当前回合;关掉则排队等这一轮结束。",
81
+ "direct.steerHint": "普通消息与 /send 在目标回合正在跑时直接插进当前回合;关掉则排队等这一轮结束。/queue 始终排队,不受此开关影响。",
82
82
  "direct.workspace": "会话工作区",
83
83
  "direct.workspaceHint": "新会话建在哪个工作区;改完发 /new 生效。",
84
84
  "direct.workspaceDefault": "默认(飞书会话)",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-im-lark",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "description": "把飞书(Lark)接入 DeepSeek Harness 的 IM 桥插件",
6
6
  "license": "MIT",