dsh-feishu-lark-notify 0.26.2 → 0.27.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 +8 -3
- package/README.zh.md +8 -4
- package/lib/index.js +39 -6
- package/lib/session-router.js +33 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -219,6 +219,7 @@ You can open a new session from Feishu, without touching the computer:
|
|
|
219
219
|
新建 → open a fresh session
|
|
220
220
|
新建 前端日报 → open one and remember the title "前端日报"
|
|
221
221
|
新建 实验台 跑一下冒烟 → open it and deliver the first command right away
|
|
222
|
+
新建@灵畿 测试 你好 → open it inside the 灵畿 workspace (so it joins that group)
|
|
222
223
|
```
|
|
223
224
|
|
|
224
225
|
Reply: `🆕 已创建「实验台」(#a1b2),第一条指令已投进去`; afterwards `@实验台 …` reaches it directly.
|
|
@@ -226,9 +227,13 @@ Reply: `🆕 已创建「实验台」(#a1b2),第一条指令已投进去`;
|
|
|
226
227
|
| Detail | Notes |
|
|
227
228
|
|---|---|
|
|
228
229
|
| Model | Borrowed from a **running** session's `agent.options`, so `{{model}}` is never empty |
|
|
229
|
-
| Directory |
|
|
230
|
-
|
|
|
231
|
-
|
|
|
230
|
+
| Directory | Defaults to the **anchor session's project directory** (so it joins the same workspace); `@group` uses that workspace's directory |
|
|
231
|
+
| Grouping | A group is a workspace, matched by title / folder name / full path; an unknown name returns the list of groups |
|
|
232
|
+
| Creating a group | Not possible from the plugin (the host only exposes a client API, no plugin service) — create the workspace in the GUI |
|
|
233
|
+
| Title | Really written to the session (`sessionTitle.rename`), not a model guess from the first message |
|
|
234
|
+
| Session id | Generated by the plugin as `session-<uuid>` so the host's auto-numbering cannot collide |
|
|
235
|
+
| Requires | Host support for `agents.create()`; older hosts reply "not supported" |
|
|
236
|
+
| Malformed | Text starting with `新建` that does not parse returns usage instead of being sent to another session |
|
|
232
237
|
|
|
233
238
|
**② Send `列表` (list) to get numbers**
|
|
234
239
|
|
package/README.zh.md
CHANGED
|
@@ -215,17 +215,21 @@ DSH 里同时开着一堆会话时,飞书里发一句话默认只交给「当
|
|
|
215
215
|
新建 → 开一个新会话
|
|
216
216
|
新建 前端日报 → 开一个,并记下标题「前端日报」
|
|
217
217
|
新建 实验台 跑一下冒烟 → 建完直接把第一条指令投进去
|
|
218
|
+
新建@灵畿 测试 你好 → 建在「灵畿」这个工作区的目录里(自动归到该组)
|
|
218
219
|
```
|
|
219
220
|
|
|
220
|
-
回执:`🆕 已创建「实验台」(#a1b2),第一条指令已投进去`,之后可以直接
|
|
221
|
-
`@实验台 内容`(标题在你没有额外设置时由模型生成,之前用你给的这个名字)。
|
|
221
|
+
回执:`🆕 已创建「实验台」(#a1b2),第一条指令已投进去`,之后可以直接 `@实验台 内容`。
|
|
222
222
|
|
|
223
223
|
| 说明 | 细节 |
|
|
224
224
|
|---|---|
|
|
225
225
|
| 模型 | 借用**当前运行中的会话**的模型配置(`agent.options`),不会出现 `{{model}}` 为空 |
|
|
226
|
-
| 目录 |
|
|
226
|
+
| 目录 | 默认用**当前会话的项目目录**(这样会归到同一个工作区);`@分组` 则用该工作区的目录 |
|
|
227
|
+
| 分组 | 分组就是工作区,按**标题 / 目录名 / 完整路径**匹配;找不到会回现有分组清单 |
|
|
228
|
+
| 新建分组 | 插件做不了(宿主只给客户端 API,没有插件服务)——在 GUI 里新建工作区即可 |
|
|
229
|
+
| 标题 | 真的写进会话(`sessionTitle.rename`),不是模型按第一句自动起名 |
|
|
230
|
+
| 会话 id | 插件自己生成 `session-<uuid>`,避免宿主自增 id 撞车 |
|
|
227
231
|
| 前提 | 宿主支持 `agents.create()`;老版本会直接回「不支持新建会话」 |
|
|
228
|
-
|
|
|
232
|
+
| 写错时 | 以 `新建` 开头但解析不出 → 回用法,**不会**当成普通指令投给别的会话 |
|
|
229
233
|
|
|
230
234
|
**② 发「列表」拿编号**
|
|
231
235
|
|
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.
|
|
40
|
+
export const VERSION = '0.27.0'
|
|
41
41
|
|
|
42
42
|
/** 内存日志上限。 */
|
|
43
43
|
const LOG_LIMIT = 200
|
|
@@ -1742,6 +1742,20 @@ export function apply(ctx, rawConfig) {
|
|
|
1742
1742
|
return { workspaces: readWorkspaces(file), archived: readArchivedIds(file) }
|
|
1743
1743
|
}
|
|
1744
1744
|
|
|
1745
|
+
/**
|
|
1746
|
+
* 按名字找作区:先比标题,再比目录名,最后比完整路径(都不区分大小写)。
|
|
1747
|
+
* @param name - 用户写的分组名。
|
|
1748
|
+
* @returns 工作区对象或 undefined。
|
|
1749
|
+
*/
|
|
1750
|
+
function findWorkspace(name) {
|
|
1751
|
+
const wanted = String(name ?? '').trim().toLowerCase()
|
|
1752
|
+
if (wanted === '') return undefined
|
|
1753
|
+
const list = workspaceInfo().workspaces
|
|
1754
|
+
return list.find((item) => (item.title ?? '').toLowerCase() === wanted)
|
|
1755
|
+
?? list.find((item) => path.basename(item.path ?? '').toLowerCase() === wanted)
|
|
1756
|
+
?? list.find((item) => (item.path ?? '').toLowerCase() === wanted)
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1745
1759
|
/**
|
|
1746
1760
|
* 把指令交给指定会话:运行中直接 followup;休眠的用 `agents.resume()` 唤醒。
|
|
1747
1761
|
*
|
|
@@ -1956,12 +1970,24 @@ export function apply(ctx, rawConfig) {
|
|
|
1956
1970
|
* @param options - title / text / message / via。
|
|
1957
1971
|
* @returns 结构化结果。
|
|
1958
1972
|
*/
|
|
1959
|
-
async function createSession({ title, text, message, via }) {
|
|
1973
|
+
async function createSession({ title, text, group, message, via }) {
|
|
1960
1974
|
const agents = ctx.get('agents')
|
|
1961
1975
|
if (agents === undefined || typeof agents.create !== 'function') {
|
|
1962
1976
|
void replyToChat(message.chatId, '这个宿主版本不支持新建会话(没有 agents.create)。')
|
|
1963
1977
|
return { ok: false, created: false, reason: 'unsupported' }
|
|
1964
1978
|
}
|
|
1979
|
+
|
|
1980
|
+
// 指定分组:分组就是工作区,按名字或目录名找它的 path 当 cwd
|
|
1981
|
+
let targetCwd = ''
|
|
1982
|
+
if (typeof group === 'string' && group !== '') {
|
|
1983
|
+
const hit = findWorkspace(group)
|
|
1984
|
+
if (hit === undefined) {
|
|
1985
|
+
const names = workspaceInfo().workspaces.map((item) => `· ${item.title || item.path}`).join('\n')
|
|
1986
|
+
void replyToChat(message.chatId, `没找到叫「${group}」的工作区。现有:\n${names || '(一个都没有)'}\n\n用法:\`新建@灵畿 标题 内容\``)
|
|
1987
|
+
return { ok: false, created: false, reason: 'no-workspace' }
|
|
1988
|
+
}
|
|
1989
|
+
targetCwd = hit.path
|
|
1990
|
+
}
|
|
1965
1991
|
// 借一个「活着的」agent 来取模型配置(liveSessions() 是投影对象,没有 options)
|
|
1966
1992
|
// 会话 id 自己生成,避免宿主用 session-1/session-2 这种会撞车的自增 id
|
|
1967
1993
|
const anchorAgent = (() => {
|
|
@@ -1984,7 +2010,8 @@ export function apply(ctx, rawConfig) {
|
|
|
1984
2010
|
}
|
|
1985
2011
|
// 目录一定要用**当前会话的项目目录**:用 processPath() 会落进 profile 目录,
|
|
1986
2012
|
// 新会话就会跑到「未分组」里去。
|
|
1987
|
-
|
|
2013
|
+
// 指定了分组就用那个工作区的目录,否则沿用当前会话的项目目录。
|
|
2014
|
+
const cwd = targetCwd !== '' ? targetCwd : sessionCwd(anchorAgent.session, stateFor(anchorAgent.session))
|
|
1988
2015
|
|
|
1989
2016
|
let handle
|
|
1990
2017
|
try {
|
|
@@ -2258,10 +2285,16 @@ export function apply(ctx, rawConfig) {
|
|
|
2258
2285
|
return applyControl({ control: bareControl, target, message, via })
|
|
2259
2286
|
}
|
|
2260
2287
|
|
|
2261
|
-
// 新建会话:`新建 [标题] [指令]`
|
|
2288
|
+
// 新建会话:`新建[@分组] [标题] [指令]`
|
|
2262
2289
|
const createCommand = parseCreate(command)
|
|
2263
2290
|
if (createCommand !== undefined) {
|
|
2264
|
-
return createSession({ title: createCommand.title, text: createCommand.text, message, via })
|
|
2291
|
+
return createSession({ title: createCommand.title, text: createCommand.text, group: createCommand.group, message, via })
|
|
2292
|
+
}
|
|
2293
|
+
// 长得像「新建」但没解析出来:给用法,别当成普通指令投给别的会话
|
|
2294
|
+
if (looksLikeCreate(command)) {
|
|
2295
|
+
log(`[${via}] 新建命令解析失败:${clip(command, 60)}`)
|
|
2296
|
+
void replyToChat(message.chatId, '这不是有效的「新建」写法。用法:\n· `新建 标题`\n· `新建 标题 内容`\n· `新建@工作区 标题 内容`')
|
|
2297
|
+
return { ok: true, created: false, reason: 'bad-create-syntax' }
|
|
2265
2298
|
}
|
|
2266
2299
|
|
|
2267
2300
|
const route = parseRoute(command)
|
package/lib/session-router.js
CHANGED
|
@@ -33,30 +33,58 @@ const STATUS_COMMANDS = new Set(['状态', '进度', '在干嘛', 'status', 'sta
|
|
|
33
33
|
const CREATE_WORDS = ['新建', '新会话', '开一个', '开个', 'new', 'create']
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
* 解析「新建」命令:`新建 [标题] [指令]`。
|
|
36
|
+
* 解析「新建」命令:`新建[@分组] [标题] [指令]`。
|
|
37
37
|
*
|
|
38
38
|
* - `新建` → 开一个没标题的会话
|
|
39
39
|
* - `新建 前端日报` → 标题设为「前端日报」
|
|
40
40
|
* - `新建 前端日报 帮我看下构建` → 建完直接投第一条指令
|
|
41
|
+
* - `新建@灵畿 前端日报 跑测试` → 建在「灵畿」那个工作区的目录下(自动归到该组)
|
|
41
42
|
*
|
|
42
43
|
* @param text - 指令正文。
|
|
43
|
-
* @returns `{ title, text }` 或 undefined(不是新建命令)。
|
|
44
|
+
* @returns `{ group, title, text }` 或 undefined(不是新建命令)。
|
|
45
|
+
* 注意 `group` 为空串表示没指定分组。
|
|
44
46
|
*/
|
|
45
47
|
export function parseCreate(text) {
|
|
46
48
|
if (typeof text !== 'string') return undefined
|
|
47
49
|
const value = text.trim()
|
|
48
50
|
if (value === '') return undefined
|
|
49
51
|
const lower = value.toLowerCase()
|
|
52
|
+
|
|
53
|
+
// 先认「新建@分组」:@ 与分组名之间允许空格,也认全角@
|
|
54
|
+
const grouped = value.match(/^(?:新建|新会话|new|create)\s*[@@]\s*([^\s]+)\s*([\s\S]*)$/i)
|
|
55
|
+
if (grouped !== null) {
|
|
56
|
+
return { group: grouped[1], ...splitTitleAndText(grouped[2].trim()) }
|
|
57
|
+
}
|
|
58
|
+
|
|
50
59
|
const word = CREATE_WORDS.find((item) => lower === item || lower.startsWith(`${item} `) || lower.startsWith(`${item} `))
|
|
51
60
|
if (word === undefined) return undefined
|
|
52
61
|
const rest = value.slice(word.length).trim()
|
|
53
|
-
if (rest === '') return { title: '', text: '' }
|
|
54
|
-
|
|
62
|
+
if (rest === '') return { group: '', title: '', text: '' }
|
|
63
|
+
return { group: '', ...splitTitleAndText(rest) }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 把「标题 指令」拆开:第一个空格前是标题,其余是内容。
|
|
68
|
+
* @param rest - 去掉命令词与分组后的剩余文本。
|
|
69
|
+
* @returns `{ title, text }`。
|
|
70
|
+
*/
|
|
71
|
+
function splitTitleAndText(rest) {
|
|
55
72
|
const match = rest.match(/^(\S+)\s+([\s\S]+)$/)
|
|
56
73
|
if (match === null) return { title: rest, text: '' }
|
|
57
74
|
return { title: match[1], text: match[2].trim() }
|
|
58
75
|
}
|
|
59
76
|
|
|
77
|
+
/**
|
|
78
|
+
* 判断一句话看起来像不像「新建」(用来给出用法提示,而不是把它当普通指令乱投)。
|
|
79
|
+
* @param text - 指令正文。
|
|
80
|
+
* @returns true 表示以新建命令词开头。
|
|
81
|
+
*/
|
|
82
|
+
export function looksLikeCreate(text) {
|
|
83
|
+
if (typeof text !== 'string') return false
|
|
84
|
+
const value = text.trim().toLowerCase()
|
|
85
|
+
return /^(新建|新会话|new|create)(\s|$|[@@])/.test(value)
|
|
86
|
+
}
|
|
87
|
+
|
|
60
88
|
/**
|
|
61
89
|
* 把「新建会话」的结果说成人话。
|
|
62
90
|
* @param options - title / id / sent(是否已经投递了第一条指令)。
|
|
@@ -227,6 +255,7 @@ export function formatHelp({ maxPerMinute, prefix } = {}) {
|
|
|
227
255
|
'· 发「列表」→ 收到正在跑的会话编号',
|
|
228
256
|
'· 发「2 帮我跑测试」→ 只交给第 2 个会话(编号 10 分钟内有效)',
|
|
229
257
|
'· 发「新建 前端日报」→ 开一个新会话;「新建 标题 内容」→ 建完直接投第一条指令',
|
|
258
|
+
'· 发「新建@灵畿 标题 内容」→ 建在「灵畿」那个工作区的目录里',
|
|
230
259
|
'· 发「状态」→ 看各会话在跑还是空闲;「停止」→ 中断当前这一轮(也能 @标题 停止)',
|
|
231
260
|
'',
|
|
232
261
|
'【审批】',
|