dsh-feishu-lark-notify 0.26.2 → 0.28.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
@@ -197,6 +197,23 @@ is not stolen by `日报`; order is exact → startsWith → includes.
197
197
  - Several matches → the candidates are listed, you refine it; **it never guesses**
198
198
  - Don't want to remember titles → `@最近 内容` (also `@上一个` / `@上次` / `@last`) goes to whatever received last
199
199
 
200
+ ### Sticky target: stop repeating the number
201
+
202
+ Once you have named a target with @title or a number, **plain messages keep going there**:
203
+
204
+ `
205
+ @前端日报 帮我跑下构建 → remembers 前端日报
206
+ 再跑一下测试 → still 前端日报
207
+ 2 换个会话做事 → switches to #2 and sticks to it
208
+ 放开 → releases it
209
+ `
210
+
211
+ | Detail | Notes |
212
+ |---|---|
213
+ | Basis | The session that last received a command (lastRoutedSessionId) |
214
+ | Expiry | If it is closed or reclaimed the route falls back automatically |
215
+ | Disable | inbound.stickyTarget: false (env DSH_NOTIFY_INBOUND_STICKY=false) |
216
+
200
217
  ### Control: stop and status
201
218
 
202
219
  Feishu is not only an input channel — it can intervene:
@@ -219,6 +236,7 @@ You can open a new session from Feishu, without touching the computer:
219
236
  新建 → open a fresh session
220
237
  新建 前端日报 → open one and remember the title "前端日报"
221
238
  新建 实验台 跑一下冒烟 → open it and deliver the first command right away
239
+ 新建@灵畿 测试 你好 → open it inside the 灵畿 workspace (so it joins that group)
222
240
  ```
223
241
 
224
242
  Reply: `🆕 已创建「实验台」(#a1b2),第一条指令已投进去`; afterwards `@实验台 …` reaches it directly.
@@ -226,9 +244,13 @@ Reply: `🆕 已创建「实验台」(#a1b2),第一条指令已投进去`;
226
244
  | Detail | Notes |
227
245
  |---|---|
228
246
  | Model | Borrowed from a **running** session's `agent.options`, so `{{model}}` is never empty |
229
- | Directory | The current project's directory |
230
- | Requires | Host support for `agents.create()`; older hosts reply "not supported" instead of failing oddly |
231
- | Errors | The host's message is echoed back and recorded as the last failure |
247
+ | Directory | Defaults to the **anchor session's project directory** (so it joins the same workspace); `@group` uses that workspace's directory |
248
+ | Grouping | A group is a workspace, matched by title / folder name / full path; an unknown name returns the list of groups |
249
+ | Creating a group | Not possible from the plugin (the host only exposes a client API, no plugin service) — create the workspace in the GUI |
250
+ | Title | Really written to the session (`sessionTitle.rename`), not a model guess from the first message |
251
+ | Session id | Generated by the plugin as `session-<uuid>` so the host's auto-numbering cannot collide |
252
+ | Requires | Host support for `agents.create()`; older hosts reply "not supported" |
253
+ | Malformed | Text starting with `新建` that does not parse returns usage instead of being sent to another session |
232
254
 
233
255
  **② Send `列表` (list) to get numbers**
234
256
 
@@ -256,7 +278,7 @@ The bot replies with **non-archived** sessions, running ones first:
256
278
 
257
279
  | Case | Behaviour |
258
280
  |---|---|
259
- | No number | Goes to the session chosen on the page, else the most recent one |
281
+ | No number | Goes to **the session you last targeted explicitly** (sticky); with no history it falls back to the page selection / most recent root |
260
282
  | Number points at a **dormant** session | Woken with `agents.resume` (plus the model that session last used), then delivered |
261
283
  | Wake-up fails | The host's original error is echoed back — nothing is dropped silently |
262
284
  | More than 10 minutes since `列表` | Numbers expire; send `列表` again. They are pinned to the order you received, so re-listing beats misdelivering |
package/README.zh.md CHANGED
@@ -193,6 +193,23 @@ DSH 里同时开着一堆会话时,飞书里发一句话默认只交给「当
193
193
  - 不想记标题 → `@最近 内容`(也认 `@上一个` / `@上次` / `@last`)交给**上次那个**会话
194
194
  - 只 `@` 了标题没写内容 → 提示补上内容
195
195
 
196
+ ### 粘性目标:不用每次都带编号
197
+
198
+ 一旦你用 @标题 或编号指定过目标,**之后不带任何前缀的普通消息继续发给它**:
199
+
200
+ `
201
+ @前端日报 帮我跑下构建 → 记住「前端日报」
202
+ 再跑一下测试 → 还是「前端日报」,不用再写一遍
203
+ 2 换个会话做事 → 切到编号 2,并粘住它
204
+ 放开 → 解除粘性,回到「配置页选定 / 最近根会话」
205
+ `
206
+
207
+ | 说明 | 细节 |
208
+ |---|---|
209
+ | 依据 | 上次真的投递成功的会话(lastRoutedSessionId) |
210
+ | 失效 | 那个会话被关掉/回收后自动退回,不会投进死目标 |
211
+ | 关闭 | inbound.stickyTarget: false(或环境变量 DSH_NOTIFY_INBOUND_STICKY=false) |
212
+
196
213
  ### 控制:停止 / 状态
197
214
 
198
215
  飞书不只是能「下指令」,也能**插手**:
@@ -215,17 +232,21 @@ DSH 里同时开着一堆会话时,飞书里发一句话默认只交给「当
215
232
  新建 → 开一个新会话
216
233
  新建 前端日报 → 开一个,并记下标题「前端日报」
217
234
  新建 实验台 跑一下冒烟 → 建完直接把第一条指令投进去
235
+ 新建@灵畿 测试 你好 → 建在「灵畿」这个工作区的目录里(自动归到该组)
218
236
  ```
219
237
 
220
- 回执:`🆕 已创建「实验台」(#a1b2),第一条指令已投进去`,之后可以直接
221
- `@实验台 内容`(标题在你没有额外设置时由模型生成,之前用你给的这个名字)。
238
+ 回执:`🆕 已创建「实验台」(#a1b2),第一条指令已投进去`,之后可以直接 `@实验台 内容`。
222
239
 
223
240
  | 说明 | 细节 |
224
241
  |---|---|
225
242
  | 模型 | 借用**当前运行中的会话**的模型配置(`agent.options`),不会出现 `{{model}}` 为空 |
226
- | 目录 | 用当前项目的目录 |
243
+ | 目录 | 默认用**当前会话的项目目录**(这样会归到同一个工作区);`@分组` 则用该工作区的目录 |
244
+ | 分组 | 分组就是工作区,按**标题 / 目录名 / 完整路径**匹配;找不到会回现有分组清单 |
245
+ | 新建分组 | 插件做不了(宿主只给客户端 API,没有插件服务)——在 GUI 里新建工作区即可 |
246
+ | 标题 | 真的写进会话(`sessionTitle.rename`),不是模型按第一句自动起名 |
247
+ | 会话 id | 插件自己生成 `session-<uuid>`,避免宿主自增 id 撞车 |
227
248
  | 前提 | 宿主支持 `agents.create()`;老版本会直接回「不支持新建会话」 |
228
- | 失败 | 原样回宿主错误,并记进「最近一次失败」 |
249
+ | 写错时 | 以 `新建` 开头但解析不出 → 回用法,**不会**当成普通指令投给别的会话 |
229
250
 
230
251
  **② 发「列表」拿编号**
231
252
 
@@ -289,7 +310,7 @@ DSH 里同时开着一堆会话时,飞书里发一句话默认只交给「当
289
310
 
290
311
  | 情况 | 行为 |
291
312
  |---|---|
292
- | 不带编号 | 交给配置页选定的默认会话;没选就交给最近一个 |
313
+ | 不带编号 | 交给**上次你显式指定的会话**(粘性目标);没有历史时退回配置页选定的 / 最近的根会话 |
293
314
  | 编号指向**休眠**会话 | 自动唤醒(`agents.resume` + 该会话上次用的模型),唤醒后照常投递 |
294
315
  | 唤醒失败 | 回执里带上**宿主的原始错误**,不会静默丢消息 |
295
316
  | 距上次「列表」超过 10 分钟 | 编号失效,提示重新发「列表」——编号绑定的是发清单那一刻的顺序,过期重发比投错安全 |
@@ -143,6 +143,7 @@
143
143
  | `commandPrefix` | `#dsh` | 指令前缀,默认 `#dsh` | `DSH_NOTIFY_INBOUND_PREFIX` |
144
144
  | `maxPerMinute` | `6` | 每个会话独立的 60 秒窗口;`0` = 不限制,最大 600 | `DSH_NOTIFY_INBOUND_MAX_PER_MINUTE` |
145
145
  | `sessionId` | `''` | 指令交给哪个会话;空 = 最近一个根会话 | `DSH_NOTIFY_INBOUND_SESSION_ID` |
146
+ | `stickyTarget` | `true` | 普通消息发给「上次显式指定的会话」(`@标题` / 编号 / 新建);关掉则退回「最近的根会话」 | `DSH_NOTIFY_INBOUND_STICKY` |
146
147
  | `requireMentionInGroups` | `true` | 群里要 @ 机器人才响应(私聊永远不需要);关掉则群里任何消息都处理 | `DSH_NOTIFY_INBOUND_REQUIRE_MENTION` |
147
148
 
148
149
  ## 在飞书里直接批准(`interactive`)
@@ -250,6 +251,7 @@ content:
250
251
  | `DSH_NOTIFY_INBOUND_MAX_PER_MINUTE` | `inbound.maxPerMinute` | 数字 |
251
252
  | `DSH_NOTIFY_INBOUND_SESSION_ID` | `inbound.sessionId` | string |
252
253
  | `DSH_NOTIFY_INBOUND_REQUIRE_MENTION` | `inbound.requireMentionInGroups` | bool |
254
+ | `DSH_NOTIFY_INBOUND_STICKY` | `inbound.stickyTarget` | bool |
253
255
  | `DSH_NOTIFY_INTERACTIVE_ENABLED` | `interactive.enabled` | bool |
254
256
  | `DSH_NOTIFY_INTERACTIVE_TIMEOUT_MS` | `interactive.timeoutMs` | 数字 |
255
257
  | `DSH_NOTIFY_INTERACTIVE_ALLOW_USERS` | `interactive.allowFromUsers` | 列表 |
package/lib/config.js CHANGED
@@ -122,6 +122,8 @@ export const DEFAULTS = {
122
122
  commandPrefix: '#dsh',
123
123
  maxPerMinute: 6,
124
124
  sessionId: '',
125
+ // 普通消息发给「上次显式指定的会话」;关掉则退回「最近的根会话」
126
+ stickyTarget: true,
125
127
  // 群里要 @ 机器人才响应(私聊不需要)
126
128
  requireMentionInGroups: true,
127
129
  },
@@ -278,6 +280,7 @@ export function resolveInbound(raw) {
278
280
  sessionId: typeof source.sessionId === 'string' ? source.sessionId.trim() : '',
279
281
  // 群里必须 @ 机器人才响应(私聊永远不需要);默认开,避免在群里抢话
280
282
  requireMentionInGroups: source.requireMentionInGroups !== false,
283
+ stickyTarget: source.stickyTarget !== false,
281
284
  }
282
285
  }
283
286
 
package/lib/env.js CHANGED
@@ -89,6 +89,8 @@ export const ENV_BINDINGS = [
89
89
  { name: 'DSH_NOTIFY_INBOUND_SESSION_ID', inbound: 'sessionId', kind: 'string' },
90
90
  // 群里必须 @ 机器人才响应;私聊不受影响
91
91
  { name: 'DSH_NOTIFY_INBOUND_REQUIRE_MENTION', inbound: 'requireMentionInGroups', kind: 'bool' },
92
+ // 普通消息发给「上次显式指定的会话」;false 则退回「最近的根会话」
93
+ { name: 'DSH_NOTIFY_INBOUND_STICKY', inbound: 'stickyTarget', kind: 'bool' },
92
94
 
93
95
  // 「在飞书里直接批准」:把工具审批发成带按钮的卡片
94
96
  { name: 'DSH_NOTIFY_INTERACTIVE_ENABLED', interactive: 'enabled', kind: 'bool' },
package/lib/index.js CHANGED
@@ -26,7 +26,7 @@ import { resolvePatchPath, writePatchRow } from './persist.js'
26
26
  import { loadEnvSources, applyEnv, renderEnvTemplate, resolveHome } from './env.js'
27
27
  import { listBotChats, getBotChat, listChatMembers, loadChatStore, saveChatStore, rememberChat, describeChatsError } from './chats.js'
28
28
  import { listSessionIndex, readArchivedIds, readWorkspaces, readSessionModel, normalizeSessionId } from './session-index.js'
29
- import { parseRoute, parseAtCommand, parseControl, parseCreate, matchByLabel, formatSessionList, formatStatus, formatCreated, formatHelp, createSessionRoster } from './session-router.js'
29
+ import { parseRoute, parseAtCommand, parseControl, parseCreate, looksLikeCreate, matchByLabel, formatSessionList, formatStatus, formatCreated, formatHelp, createSessionRoster } from './session-router.js'
30
30
  import { appendLogLine } from './logfile.js'
31
31
  import { createLiveness, describeLiveness } from './liveness.js'
32
32
  import { verifyAfterSave, inspectPatch } from './patch-guard.js'
@@ -37,7 +37,7 @@ import { startWsInbound } from './inbound-ws.js'
37
37
  export const name = 'feishu-notify'
38
38
 
39
39
  /** 版本号(与 package.json 保持一致,单测会校验)。 */
40
- export const VERSION = '0.26.2'
40
+ export const VERSION = '0.28.0'
41
41
 
42
42
  /** 内存日志上限。 */
43
43
  const LOG_LIMIT = 200
@@ -1508,11 +1508,35 @@ export function apply(ctx, rawConfig) {
1508
1508
  //#endregion
1509
1509
 
1510
1510
  /** 用已配置的 webhook 渠道回一句(可选,失败不影响主流程)。 */
1511
- async function acknowledge(text) {
1511
+ /**
1512
+ * 给用户回一句「收到了」。
1513
+ *
1514
+ * 之前的实现只在 **webhook 模式**下发回执(`webhooks.length === 0` 直接 return),
1515
+ * 于是用应用机器人的场景(绝大多数人)**一条回执都没有**——用户以为消息没被收到。
1516
+ * 现在应用机器人走 `sendRaw` 发文本,webhook 模式保持原样。
1517
+ * @param text - 回执正文。
1518
+ * @param chatId - 发到哪个会话;省略则用第一个推送目标。
1519
+ */
1520
+ async function acknowledge(text, chatId) {
1512
1521
  const channel = config.channels.feishu
1513
- if (channel?.enabled !== true || channel.webhooks.length === 0) return
1514
- const summary = { title: '📥 DSH 收到指令', head: [text], body: '', footer: '', color: 'blue', plain: text }
1522
+ if (channel?.enabled !== true) return
1523
+ const target = typeof chatId === 'string' && chatId !== ''
1524
+ ? chatId
1525
+ : (Array.isArray(channel.receiveChatIds) && channel.receiveChatIds.length > 0 ? channel.receiveChatIds[0] : '')
1515
1526
  try {
1527
+ if (channel.useAppBot === true && channel.appId !== '' && channel.appSecret !== '') {
1528
+ const results = await feishuChannel.sendRaw(
1529
+ channel,
1530
+ { msg_type: 'text', content: { text } },
1531
+ { chatIds: target === '' ? channel.receiveChatIds : [target], timeoutMs: config.timeoutMs },
1532
+ )
1533
+ if (!results.some((item) => item.ok)) {
1534
+ log(`回执发送失败: ${results.map((item) => item.error).filter(Boolean).join('; ')}`)
1535
+ }
1536
+ return
1537
+ }
1538
+ if (!Array.isArray(channel.webhooks) || channel.webhooks.length === 0) return
1539
+ const summary = { title: '📥 DSH 收到指令', head: [text], body: '', footer: '', color: 'blue', plain: text }
1516
1540
  await feishuChannel.deliver(channel, summary, { style: 'text', timeoutMs: config.timeoutMs })
1517
1541
  } catch (error) {
1518
1542
  log(`回执发送失败: ${error?.message ?? error}`)
@@ -1633,7 +1657,14 @@ export function apply(ctx, rawConfig) {
1633
1657
  function resolveTargetAgent() {
1634
1658
  const agents = ctx.get('agents')
1635
1659
  if (agents === undefined) return undefined
1660
+ // ① 粘性:上次显式指定的会话(@标题 / 编号 / 新建)还活着,就用它
1661
+ if (config.inbound.stickyTarget !== false && lastRoutedSessionId !== '') {
1662
+ const sticky = typeof agents.get === 'function' ? agents.get(lastRoutedSessionId) : undefined
1663
+ if (sticky !== undefined && sticky !== null) return sticky
1664
+ }
1665
+ // ② 配置页固定
1636
1666
  if (config.inbound.sessionId !== '') return agents.get(config.inbound.sessionId)
1667
+ // ③ 最近的根会话(原行为)
1637
1668
  const roots = typeof agents.roots === 'function' ? agents.roots() : []
1638
1669
  return roots[roots.length - 1]
1639
1670
  }
@@ -1662,6 +1693,7 @@ export function apply(ctx, rawConfig) {
1662
1693
  lastRoutedSessionId = agent.id
1663
1694
  lastRoutedAt = Date.now()
1664
1695
  log(`${meta.via ?? 'inbound'}:已提交指令到会话 ${agent.id}(来自 ${meta.chatId}/${meta.userId})`)
1696
+ return { id: agent.id, label: sessionLabel(agent) }
1665
1697
  }
1666
1698
 
1667
1699
  /** 机器人自己的身份(群里判断有没有 @ 我),取一次就缓存。 */
@@ -1742,6 +1774,20 @@ export function apply(ctx, rawConfig) {
1742
1774
  return { workspaces: readWorkspaces(file), archived: readArchivedIds(file) }
1743
1775
  }
1744
1776
 
1777
+ /**
1778
+ * 按名字找作区:先比标题,再比目录名,最后比完整路径(都不区分大小写)。
1779
+ * @param name - 用户写的分组名。
1780
+ * @returns 工作区对象或 undefined。
1781
+ */
1782
+ function findWorkspace(name) {
1783
+ const wanted = String(name ?? '').trim().toLowerCase()
1784
+ if (wanted === '') return undefined
1785
+ const list = workspaceInfo().workspaces
1786
+ return list.find((item) => (item.title ?? '').toLowerCase() === wanted)
1787
+ ?? list.find((item) => path.basename(item.path ?? '').toLowerCase() === wanted)
1788
+ ?? list.find((item) => (item.path ?? '').toLowerCase() === wanted)
1789
+ }
1790
+
1745
1791
  /**
1746
1792
  * 把指令交给指定会话:运行中直接 followup;休眠的用 `agents.resume()` 唤醒。
1747
1793
  *
@@ -1956,12 +2002,24 @@ export function apply(ctx, rawConfig) {
1956
2002
  * @param options - title / text / message / via。
1957
2003
  * @returns 结构化结果。
1958
2004
  */
1959
- async function createSession({ title, text, message, via }) {
2005
+ async function createSession({ title, text, group, message, via }) {
1960
2006
  const agents = ctx.get('agents')
1961
2007
  if (agents === undefined || typeof agents.create !== 'function') {
1962
2008
  void replyToChat(message.chatId, '这个宿主版本不支持新建会话(没有 agents.create)。')
1963
2009
  return { ok: false, created: false, reason: 'unsupported' }
1964
2010
  }
2011
+
2012
+ // 指定分组:分组就是工作区,按名字或目录名找它的 path 当 cwd
2013
+ let targetCwd = ''
2014
+ if (typeof group === 'string' && group !== '') {
2015
+ const hit = findWorkspace(group)
2016
+ if (hit === undefined) {
2017
+ const names = workspaceInfo().workspaces.map((item) => `· ${item.title || item.path}`).join('\n')
2018
+ void replyToChat(message.chatId, `没找到叫「${group}」的工作区。现有:\n${names || '(一个都没有)'}\n\n用法:\`新建@灵畿 标题 内容\``)
2019
+ return { ok: false, created: false, reason: 'no-workspace' }
2020
+ }
2021
+ targetCwd = hit.path
2022
+ }
1965
2023
  // 借一个「活着的」agent 来取模型配置(liveSessions() 是投影对象,没有 options)
1966
2024
  // 会话 id 自己生成,避免宿主用 session-1/session-2 这种会撞车的自增 id
1967
2025
  const anchorAgent = (() => {
@@ -1984,7 +2042,8 @@ export function apply(ctx, rawConfig) {
1984
2042
  }
1985
2043
  // 目录一定要用**当前会话的项目目录**:用 processPath() 会落进 profile 目录,
1986
2044
  // 新会话就会跑到「未分组」里去。
1987
- const cwd = sessionCwd(anchorAgent.session, stateFor(anchorAgent.session))
2045
+ // 指定了分组就用那个工作区的目录,否则沿用当前会话的项目目录。
2046
+ const cwd = targetCwd !== '' ? targetCwd : sessionCwd(anchorAgent.session, stateFor(anchorAgent.session))
1988
2047
 
1989
2048
  let handle
1990
2049
  try {
@@ -2052,6 +2111,15 @@ export function apply(ctx, rawConfig) {
2052
2111
  * @returns 结构化结果。
2053
2112
  */
2054
2113
  async function applyControl({ control, target, message, via }) {
2114
+ if (control.kind === 'release') {
2115
+ const previous = lastRoutedSessionId
2116
+ lastRoutedSessionId = ''
2117
+ log(`[${via}] 控制:已解除粘性目标(原 ${previous || '无'})`)
2118
+ void replyToChat(message.chatId, previous === ''
2119
+ ? '本来就没有固定目标。'
2120
+ : '🔓 已解除,之后普通消息回到「配置页选定 / 最近的根会话」。')
2121
+ return { ok: true, control: 'release' }
2122
+ }
2055
2123
  if (control.kind === 'status') {
2056
2124
  const text = formatStatus(rosterSessions(), {
2057
2125
  currentId: config.inbound.sessionId !== '' ? config.inbound.sessionId : lastRoutedSessionId,
@@ -2258,10 +2326,16 @@ export function apply(ctx, rawConfig) {
2258
2326
  return applyControl({ control: bareControl, target, message, via })
2259
2327
  }
2260
2328
 
2261
- // 新建会话:`新建 [标题] [指令]`
2329
+ // 新建会话:`新建[@分组] [标题] [指令]`
2262
2330
  const createCommand = parseCreate(command)
2263
2331
  if (createCommand !== undefined) {
2264
- return createSession({ title: createCommand.title, text: createCommand.text, message, via })
2332
+ return createSession({ title: createCommand.title, text: createCommand.text, group: createCommand.group, message, via })
2333
+ }
2334
+ // 长得像「新建」但没解析出来:给用法,别当成普通指令投给别的会话
2335
+ if (looksLikeCreate(command)) {
2336
+ log(`[${via}] 新建命令解析失败:${clip(command, 60)}`)
2337
+ void replyToChat(message.chatId, '这不是有效的「新建」写法。用法:\n· `新建 标题`\n· `新建 标题 内容`\n· `新建@工作区 标题 内容`')
2338
+ return { ok: true, created: false, reason: 'bad-create-syntax' }
2265
2339
  }
2266
2340
 
2267
2341
  const route = parseRoute(command)
@@ -2304,8 +2378,9 @@ export function apply(ctx, rawConfig) {
2304
2378
  }
2305
2379
 
2306
2380
  try {
2307
- await enqueue(command, { chatId: message.chatId, userId: message.userId, via })
2308
- void acknowledge(`✅ 已提交:${clip(command, 600)}`, message.chatId)
2381
+ const delivered = await enqueue(command, { chatId: message.chatId, userId: message.userId, via })
2382
+ const targetName = delivered?.label || (delivered?.id ? delivered.id.slice(-6) : '会话')
2383
+ void acknowledge(`✅ 已收到,交给「${targetName}」:${clip(command, 300)}`, message.chatId)
2309
2384
  return { ok: true, accepted: true }
2310
2385
  } catch (error) {
2311
2386
  log(`[${via}] 提交失败 ${error?.message ?? error}`)
@@ -29,34 +29,65 @@ const STOP_COMMANDS = new Set(['停止', '停', '中断', '打住', 'stop', 'can
29
29
  /** 控制命令:看状态。 */
30
30
  const STATUS_COMMANDS = new Set(['状态', '进度', '在干嘛', 'status', 'state'])
31
31
 
32
+ /** 控制命令:解除粘性目标。 */
33
+ const RELEASE_COMMANDS = new Set(['放开', '取消默认', '不粘了', 'release'])
34
+
32
35
  /** 新建会话的命令前缀词。 */
33
36
  const CREATE_WORDS = ['新建', '新会话', '开一个', '开个', 'new', 'create']
34
37
 
35
38
  /**
36
- * 解析「新建」命令:`新建 [标题] [指令]`。
39
+ * 解析「新建」命令:`新建[@分组] [标题] [指令]`。
37
40
  *
38
41
  * - `新建` → 开一个没标题的会话
39
42
  * - `新建 前端日报` → 标题设为「前端日报」
40
43
  * - `新建 前端日报 帮我看下构建` → 建完直接投第一条指令
44
+ * - `新建@灵畿 前端日报 跑测试` → 建在「灵畿」那个工作区的目录下(自动归到该组)
41
45
  *
42
46
  * @param text - 指令正文。
43
- * @returns `{ title, text }` 或 undefined(不是新建命令)。
47
+ * @returns `{ group, title, text }` 或 undefined(不是新建命令)。
48
+ * 注意 `group` 为空串表示没指定分组。
44
49
  */
45
50
  export function parseCreate(text) {
46
51
  if (typeof text !== 'string') return undefined
47
52
  const value = text.trim()
48
53
  if (value === '') return undefined
49
54
  const lower = value.toLowerCase()
55
+
56
+ // 先认「新建@分组」:@ 与分组名之间允许空格,也认全角@
57
+ const grouped = value.match(/^(?:新建|新会话|new|create)\s*[@@]\s*([^\s]+)\s*([\s\S]*)$/i)
58
+ if (grouped !== null) {
59
+ return { group: grouped[1], ...splitTitleAndText(grouped[2].trim()) }
60
+ }
61
+
50
62
  const word = CREATE_WORDS.find((item) => lower === item || lower.startsWith(`${item} `) || lower.startsWith(`${item} `))
51
63
  if (word === undefined) return undefined
52
64
  const rest = value.slice(word.length).trim()
53
- if (rest === '') return { title: '', text: '' }
54
- // 第一个空格前是标题,后面全是指令;标题里允许没有空格(整段都当标题)
65
+ if (rest === '') return { group: '', title: '', text: '' }
66
+ return { group: '', ...splitTitleAndText(rest) }
67
+ }
68
+
69
+ /**
70
+ * 把「标题 指令」拆开:第一个空格前是标题,其余是内容。
71
+ * @param rest - 去掉命令词与分组后的剩余文本。
72
+ * @returns `{ title, text }`。
73
+ */
74
+ function splitTitleAndText(rest) {
55
75
  const match = rest.match(/^(\S+)\s+([\s\S]+)$/)
56
76
  if (match === null) return { title: rest, text: '' }
57
77
  return { title: match[1], text: match[2].trim() }
58
78
  }
59
79
 
80
+ /**
81
+ * 判断一句话看起来像不像「新建」(用来给出用法提示,而不是把它当普通指令乱投)。
82
+ * @param text - 指令正文。
83
+ * @returns true 表示以新建命令词开头。
84
+ */
85
+ export function looksLikeCreate(text) {
86
+ if (typeof text !== 'string') return false
87
+ const value = text.trim().toLowerCase()
88
+ return /^(新建|新会话|new|create)(\s|$|[@@])/.test(value)
89
+ }
90
+
60
91
  /**
61
92
  * 把「新建会话」的结果说成人话。
62
93
  * @param options - title / id / sent(是否已经投递了第一条指令)。
@@ -80,6 +111,7 @@ export function parseControl(text) {
80
111
  if (value === '') return undefined
81
112
  if (STOP_COMMANDS.has(value)) return { kind: 'stop' }
82
113
  if (STATUS_COMMANDS.has(value)) return { kind: 'status' }
114
+ if (RELEASE_COMMANDS.has(value)) return { kind: 'release' }
83
115
  return undefined
84
116
  }
85
117
 
@@ -227,6 +259,8 @@ export function formatHelp({ maxPerMinute, prefix } = {}) {
227
259
  '· 发「列表」→ 收到正在跑的会话编号',
228
260
  '· 发「2 帮我跑测试」→ 只交给第 2 个会话(编号 10 分钟内有效)',
229
261
  '· 发「新建 前端日报」→ 开一个新会话;「新建 标题 内容」→ 建完直接投第一条指令',
262
+ '· 发「新建@灵畿 标题 内容」→ 建在「灵畿」那个工作区的目录里',
263
+ '· 不带编号 → 继续发给「上次你指定的会话」;发「放开」解除',
230
264
  '· 发「状态」→ 看各会话在跑还是空闲;「停止」→ 中断当前这一轮(也能 @标题 停止)',
231
265
  '',
232
266
  '【审批】',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-feishu-lark-notify",
3
- "version": "0.26.2",
3
+ "version": "0.28.0",
4
4
  "description": "把 DSH 的任务完成 / 需要你处理的通知推到飞书(Lark):在飞书里点审批、答选择题、按标题把指令交给指定会话,也能收发图片和文件。自带可视化配置页。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -61,6 +61,7 @@ const INBOUND_NOTES = {
61
61
  maxPerMinute: '每个会话独立的 60 秒窗口;`0` = 不限制,最大 600',
62
62
  sessionId: '指令交给哪个会话;空 = 最近一个根会话',
63
63
  requireMentionInGroups: '群里要 @ 机器人才响应(私聊永远不需要);关掉则群里任何消息都处理',
64
+ stickyTarget: '普通消息发给「上次显式指定的会话」(`@标题` / 编号 / 新建);关掉则退回「最近的根会话」',
64
65
  }
65
66
 
66
67
  /** 「在飞书里直接批准」字段的中文说明。 */