dsh-feishu-lark-notify 0.25.1 → 0.26.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 +19 -0
- package/README.zh.md +20 -0
- package/docs/troubleshooting.md +24 -0
- package/lib/index.js +140 -3
- package/lib/patch-guard.js +87 -0
- package/lib/session-router.js +41 -0
- package/lib/settings-page.js +5 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -211,6 +211,25 @@ Feishu is not only an input channel — it can intervene:
|
|
|
211
211
|
Stop uses the host's `agent.cancel({ kind: 'user' })`, identical to pressing stop in the UI, and only
|
|
212
212
|
acts on **running** sessions (a stop command never wakes a dormant one).
|
|
213
213
|
|
|
214
|
+
### Create a session
|
|
215
|
+
|
|
216
|
+
You can open a new session from Feishu, without touching the computer:
|
|
217
|
+
|
|
218
|
+
```
|
|
219
|
+
新建 → open a fresh session
|
|
220
|
+
新建 前端日报 → open one and remember the title "前端日报"
|
|
221
|
+
新建 实验台 跑一下冒烟 → open it and deliver the first command right away
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Reply: `🆕 已创建「实验台」(#a1b2),第一条指令已投进去`; afterwards `@实验台 …` reaches it directly.
|
|
225
|
+
|
|
226
|
+
| Detail | Notes |
|
|
227
|
+
|---|---|
|
|
228
|
+
| 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 |
|
|
232
|
+
|
|
214
233
|
**② Send `列表` (list) to get numbers**
|
|
215
234
|
|
|
216
235
|
```
|
package/README.zh.md
CHANGED
|
@@ -207,6 +207,26 @@ DSH 里同时开着一堆会话时,飞书里发一句话默认只交给「当
|
|
|
207
207
|
停止走的是宿主的 `agent.cancel({ kind: 'user' })`,和你在界面上按停止等价;
|
|
208
208
|
只对**正在运行**的会话有效(不会为了一句「停止」把休眠会话唤醒)。
|
|
209
209
|
|
|
210
|
+
### 新建会话
|
|
211
|
+
|
|
212
|
+
飞书里也能**开新会话**,不用跑回电脑:
|
|
213
|
+
|
|
214
|
+
```
|
|
215
|
+
新建 → 开一个新会话
|
|
216
|
+
新建 前端日报 → 开一个,并记下标题「前端日报」
|
|
217
|
+
新建 实验台 跑一下冒烟 → 建完直接把第一条指令投进去
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
回执:`🆕 已创建「实验台」(#a1b2),第一条指令已投进去`,之后可以直接
|
|
221
|
+
`@实验台 内容`(标题在你没有额外设置时由模型生成,之前用你给的这个名字)。
|
|
222
|
+
|
|
223
|
+
| 说明 | 细节 |
|
|
224
|
+
|---|---|
|
|
225
|
+
| 模型 | 借用**当前运行中的会话**的模型配置(`agent.options`),不会出现 `{{model}}` 为空 |
|
|
226
|
+
| 目录 | 用当前项目的目录 |
|
|
227
|
+
| 前提 | 宿主支持 `agents.create()`;老版本会直接回「不支持新建会话」 |
|
|
228
|
+
| 失败 | 原样回宿主错误,并记进「最近一次失败」 |
|
|
229
|
+
|
|
210
230
|
**② 发「列表」拿编号**
|
|
211
231
|
|
|
212
232
|
```
|
package/docs/troubleshooting.md
CHANGED
|
@@ -53,10 +53,34 @@ compat: {"plugin":"0.1.1","node":"v24.21.0","listens":"session/event → turn/en
|
|
|
53
53
|
## 配置页打不开(404)
|
|
54
54
|
|
|
55
55
|
- 确认已安装并启用:`cordis.patch.yml` 里有 `id: feishu-notify` 的条目。
|
|
56
|
+
- **最常见:条目被保存操作整体覆盖掉了。** 插件在 profile 里需要**两段**——
|
|
57
|
+
`insert:` 里的挂载行(负责让它加载)+ 顶层同 id 的配置行(负责选项)。少了挂载行,
|
|
58
|
+
代码和配置都还在,但插件就是不加载:
|
|
59
|
+
|
|
60
|
+
```yaml
|
|
61
|
+
- insert:
|
|
62
|
+
- id: feishu-notify
|
|
63
|
+
name: 'dsh-feishu-lark-notify' # 或 file:///…/lib/index.js
|
|
64
|
+
|
|
65
|
+
- id: feishu-notify
|
|
66
|
+
name: 'dsh-feishu-lark-notify'
|
|
67
|
+
config:
|
|
68
|
+
channels: { feishu: { … } }
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
检查命令:`grep -n 'feishu-notify' ~/.dsh/profiles/<profile>/cordis.patch.yml`,
|
|
72
|
+
数一下 `insert:` 下面有没有出现一次。恢复:从同目录的
|
|
73
|
+
`cordis.patch.yml.bak-<时间戳>` 里把这两段贴回来,再重启。
|
|
74
|
+
|
|
75
|
+
插件在保存后会**自检**这一点:如果发现条目结构不完整,页面不会自动刷新,而是直接
|
|
76
|
+
用红字告诉你缺哪一段(并写进「最近一次失败」)。
|
|
56
77
|
- 确认 profile 挂载了 web 宿主(`webServer`)。headless / 纯 CLI profile 不提供 HTTP 服务,属于预期行为。
|
|
57
78
|
- 查看插件日志是否写了 `配置页: /plugins/feishu-notify(仅本机)`;若写了 `注册配置页失败: duplicate prefix route`,说明上一次注册没释放,重启 DSH。
|
|
58
79
|
- 用了自定义 `uiPrefix` 时路径会变(例如 `/plugins/notify`)。
|
|
59
80
|
|
|
81
|
+
> 端口每次重启 DSH 都会变,404 也可能是你开着旧标签页。用当前 GUI 的地址加
|
|
82
|
+
> `/plugins/feishu-notify`,或直接问助手拿最新端口。
|
|
83
|
+
|
|
60
84
|
## 页面能打开,但「保存并生效」报错
|
|
61
85
|
|
|
62
86
|
| 报错 | 原因 | 处理 |
|
package/lib/index.js
CHANGED
|
@@ -26,9 +26,10 @@ 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, matchByLabel, formatSessionList, formatStatus, formatHelp, createSessionRoster } from './session-router.js'
|
|
29
|
+
import { parseRoute, parseAtCommand, parseControl, parseCreate, 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
|
+
import { verifyAfterSave, inspectPatch } from './patch-guard.js'
|
|
32
33
|
import { parseCallbackPayload, extractMessage, extractCommand, isAttachmentMessage, authorize, createRateLimiter, computeSignature, signatureCandidates, signatureValid, MESSAGE_EVENT, CARD_ACTION_EVENT } from './inbound.js'
|
|
33
34
|
import { startWsInbound } from './inbound-ws.js'
|
|
34
35
|
|
|
@@ -36,7 +37,7 @@ import { startWsInbound } from './inbound-ws.js'
|
|
|
36
37
|
export const name = 'feishu-notify'
|
|
37
38
|
|
|
38
39
|
/** 版本号(与 package.json 保持一致,单测会校验)。 */
|
|
39
|
-
export const VERSION = '0.
|
|
40
|
+
export const VERSION = '0.26.0'
|
|
40
41
|
|
|
41
42
|
/** 内存日志上限。 */
|
|
42
43
|
const LOG_LIMIT = 200
|
|
@@ -97,6 +98,8 @@ export function apply(ctx, rawConfig) {
|
|
|
97
98
|
let lastRoutedSessionId = ''
|
|
98
99
|
/** 最近一次投递的时间(状态 里显示「几分钟前」)。 */
|
|
99
100
|
let lastRoutedAt = 0
|
|
101
|
+
/** 飞书里「新建」时定的标题:模型还没生成标题前,路由按它找 */
|
|
102
|
+
const createdTitles = new Map()
|
|
100
103
|
/** 存活探针:定时探一次飞书 API,把断线暴露出来。 */
|
|
101
104
|
let liveness
|
|
102
105
|
|
|
@@ -962,13 +965,32 @@ export function apply(ctx, rawConfig) {
|
|
|
962
965
|
if (active.length === 0) log('没有任何可用渠道:插件将空转,只在配置页可见')
|
|
963
966
|
const saved = await persist(rawFrom(next))
|
|
964
967
|
log(`配置已保存(${saved.mode}${saved.path ? `: ${saved.path}` : ''}),渠道=${active.join(',') || '无'}${skipped.length > 0 ? `,跳过 ${skipped.length} 个 env 字段` : ''}`)
|
|
968
|
+
|
|
969
|
+
// 保存后自检:确认本插件的挂载条目还在,否则重启后插件就不加载了
|
|
970
|
+
let guardWarning = ''
|
|
971
|
+
try {
|
|
972
|
+
const patchFile = saved.path ?? resolvePatchPath({ configEditor: ctx.get('configEditor'), profileContext: ctx.get('profileContext') })
|
|
973
|
+
if (patchFile !== undefined) {
|
|
974
|
+
const check = verifyAfterSave(patchFile)
|
|
975
|
+
if (!check.ok) {
|
|
976
|
+
guardWarning = check.message
|
|
977
|
+
noteFailure('保存后自检', check.message)
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
} catch (error) {
|
|
981
|
+
log(`保存后自检异常: ${error?.message ?? error}`)
|
|
982
|
+
}
|
|
983
|
+
|
|
965
984
|
sendJson(res, 200, {
|
|
966
985
|
ok: true,
|
|
967
986
|
mode: saved.mode,
|
|
968
987
|
config: publicConfig(effective),
|
|
969
988
|
activeChannels: active,
|
|
970
989
|
skippedEnvFields: skipped,
|
|
971
|
-
note:
|
|
990
|
+
note: guardWarning !== ''
|
|
991
|
+
? guardWarning
|
|
992
|
+
: skipped.length > 0 ? '已保存;由 .env 提供的字段不会被写入 YAML' : '保存成功,页面会自动刷新',
|
|
993
|
+
warning: guardWarning !== '' ? guardWarning : undefined,
|
|
972
994
|
})
|
|
973
995
|
} catch (error) {
|
|
974
996
|
log(`保存失败: ${error?.message ?? error}`)
|
|
@@ -1599,6 +1621,8 @@ export function apply(ctx, rawConfig) {
|
|
|
1599
1621
|
}
|
|
1600
1622
|
const state = states.get(id)
|
|
1601
1623
|
if (typeof state?.lastUser === 'string' && state.lastUser.trim() !== '') return clip(state.lastUser.trim(), 30)
|
|
1624
|
+
// 飞书里「新建」时给的名字:模型还没生成标题前先顶用
|
|
1625
|
+
if (createdTitles.has(id)) return clip(createdTitles.get(id), 40)
|
|
1602
1626
|
return ''
|
|
1603
1627
|
}
|
|
1604
1628
|
|
|
@@ -1888,6 +1912,113 @@ export function apply(ctx, rawConfig) {
|
|
|
1888
1912
|
return { ok: true, path: filePath, prompt, kindLabel }
|
|
1889
1913
|
}
|
|
1890
1914
|
|
|
1915
|
+
/**
|
|
1916
|
+
* 新建会话时借一个模型配置。
|
|
1917
|
+
*
|
|
1918
|
+
* 优先用宿主给活会话的 `agent.options`(最准,不读磁盘),
|
|
1919
|
+
* 再退回会话索引里的 `modelSelection.lastUsed`,最后借其它活会话的。
|
|
1920
|
+
* @param agent - 借用的活会话。
|
|
1921
|
+
* @returns `{ provider, model, reasoningEffort? }` 或 undefined。
|
|
1922
|
+
*/
|
|
1923
|
+
function modelForCreate(agent) {
|
|
1924
|
+
const options = agent?.options
|
|
1925
|
+
if (typeof options?.provider === 'string' && options.provider !== ''
|
|
1926
|
+
&& typeof options?.model === 'string' && options.model !== '') {
|
|
1927
|
+
return {
|
|
1928
|
+
provider: options.provider,
|
|
1929
|
+
model: options.model,
|
|
1930
|
+
...(typeof options.reasoningEffort === 'string' ? { reasoningEffort: options.reasoningEffort } : {}),
|
|
1931
|
+
}
|
|
1932
|
+
}
|
|
1933
|
+
const fromIndex = sessionModelFor(agent?.id ?? '')
|
|
1934
|
+
if (fromIndex !== undefined) return fromIndex
|
|
1935
|
+
for (const item of liveSessions()) {
|
|
1936
|
+
if (item.id === agent?.id) continue
|
|
1937
|
+
const other = sessionModelFor(item.id)
|
|
1938
|
+
if (other !== undefined) return other
|
|
1939
|
+
}
|
|
1940
|
+
return undefined
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
/**
|
|
1944
|
+
* 新建一个会话(`新建 [标题] [指令]`)。
|
|
1945
|
+
*
|
|
1946
|
+
* 宿主签名:`agents.create({ agentOptions, meta: { cwd } })` → `AgentHandle { agent, dispose }`。
|
|
1947
|
+
* handle 必须留着,否则会被回收;模型用「当前运行中会话」的,避免又踩 `{{model}}` 为空。
|
|
1948
|
+
* @param options - title / text / message / via。
|
|
1949
|
+
* @returns 结构化结果。
|
|
1950
|
+
*/
|
|
1951
|
+
async function createSession({ title, text, message, via }) {
|
|
1952
|
+
const agents = ctx.get('agents')
|
|
1953
|
+
if (agents === undefined || typeof agents.create !== 'function') {
|
|
1954
|
+
void replyToChat(message.chatId, '这个宿主版本不支持新建会话(没有 agents.create)。')
|
|
1955
|
+
return { ok: false, created: false, reason: 'unsupported' }
|
|
1956
|
+
}
|
|
1957
|
+
// 借一个「活着的」agent 来取模型配置(liveSessions() 是投影对象,没有 options)
|
|
1958
|
+
const anchorAgent = (() => {
|
|
1959
|
+
try {
|
|
1960
|
+
const roots = ctx.get('agents')?.roots?.() ?? []
|
|
1961
|
+
return Array.isArray(roots) ? roots[0] : undefined
|
|
1962
|
+
} catch {
|
|
1963
|
+
return undefined
|
|
1964
|
+
}
|
|
1965
|
+
})()
|
|
1966
|
+
if (anchorAgent === undefined) {
|
|
1967
|
+
void replyToChat(message.chatId, '现在没有运行中的会话可以借用模型配置,先在 DSH 里打开一个再试。')
|
|
1968
|
+
return { ok: false, created: false, reason: 'no-model-anchor' }
|
|
1969
|
+
}
|
|
1970
|
+
const anchor = { label: sessionLabel(anchorAgent), id: anchorAgent.id }
|
|
1971
|
+
const model = modelForCreate(anchorAgent)
|
|
1972
|
+
if (model === undefined) {
|
|
1973
|
+
void replyToChat(message.chatId, `借不到模型配置(${anchor.label || anchor.id.slice(-6)} 没有 modelSelection),先在 DSH 里给它选个模型。`)
|
|
1974
|
+
return { ok: false, created: false, reason: 'no-model' }
|
|
1975
|
+
}
|
|
1976
|
+
|
|
1977
|
+
let handle
|
|
1978
|
+
try {
|
|
1979
|
+
handle = await agents.create({
|
|
1980
|
+
agentOptions: {
|
|
1981
|
+
provider: model.provider,
|
|
1982
|
+
model: model.model,
|
|
1983
|
+
...(model.reasoningEffort === undefined ? {} : { reasoningEffort: model.reasoningEffort }),
|
|
1984
|
+
},
|
|
1985
|
+
meta: { cwd: projectRoot() },
|
|
1986
|
+
})
|
|
1987
|
+
} catch (error) {
|
|
1988
|
+
const detail = String(error?.message ?? error)
|
|
1989
|
+
log(`[${via}] 新建会话失败:${detail}`)
|
|
1990
|
+
noteFailure('新建会话', detail)
|
|
1991
|
+
void replyToChat(message.chatId, `❌ 新建失败:${detail}`)
|
|
1992
|
+
return { ok: false, created: false, error: detail }
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1995
|
+
const agent = handle?.agent
|
|
1996
|
+
if (agent === undefined || agent === null) {
|
|
1997
|
+
void replyToChat(message.chatId, '宿主返回了空 handle,新建失败。')
|
|
1998
|
+
return { ok: false, created: false, reason: 'empty-handle' }
|
|
1999
|
+
}
|
|
2000
|
+
revivedHandles.set(agent.id, handle)
|
|
2001
|
+
|
|
2002
|
+
// 记下标题,页面上新会话还没有模型标题时,路由也能按名字找到它
|
|
2003
|
+
if (typeof title === 'string' && title !== '') {
|
|
2004
|
+
createdTitles.set(agent.id, title)
|
|
2005
|
+
sessionRoster.remember([{ id: agent.id, label: title, status: 'running', live: true }, ...rosterSessions()])
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
let sent = false
|
|
2009
|
+
if (typeof text === 'string' && text !== '') {
|
|
2010
|
+
try {
|
|
2011
|
+
await enqueue(text, { chatId: message.chatId, userId: message.userId, via }, agent)
|
|
2012
|
+
sent = true
|
|
2013
|
+
} catch (error) {
|
|
2014
|
+
log(`[${via}] 新会话投递失败:${error?.message ?? error}`)
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
log(`[${via}] 新建会话 ${agent.id}${title ? `(${title})` : ''}${sent ? ',已投递第一条指令' : ''}`)
|
|
2018
|
+
void replyToChat(message.chatId, formatCreated({ title, id: agent.id, sent }))
|
|
2019
|
+
return { ok: true, created: true, session: agent.id, sent, title }
|
|
2020
|
+
}
|
|
2021
|
+
|
|
1891
2022
|
/**
|
|
1892
2023
|
* 执行控制命令(`停止` / `状态`),目标会话由调用方解析好。
|
|
1893
2024
|
* @param options - control / target / message / via。
|
|
@@ -2100,6 +2231,12 @@ export function apply(ctx, rawConfig) {
|
|
|
2100
2231
|
return applyControl({ control: bareControl, target, message, via })
|
|
2101
2232
|
}
|
|
2102
2233
|
|
|
2234
|
+
// 新建会话:`新建 [标题] [指令]`
|
|
2235
|
+
const createCommand = parseCreate(command)
|
|
2236
|
+
if (createCommand !== undefined) {
|
|
2237
|
+
return createSession({ title: createCommand.title, text: createCommand.text, message, via })
|
|
2238
|
+
}
|
|
2239
|
+
|
|
2103
2240
|
const route = parseRoute(command)
|
|
2104
2241
|
if (route !== undefined && route.kind === 'help') {
|
|
2105
2242
|
log(`[${via}] 路由:发送用法说明`)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 保存后的自检:确认「插件自己的条目还在 patch 里」。
|
|
3
|
+
*
|
|
4
|
+
* 踩过的坑:配置页保存会重写 `cordis.patch.yml`,一旦写的方式是整体覆盖,
|
|
5
|
+
* 本插件的**挂载条目**(`insert:` 里的那一行)就会一起消失——表现是插件突然
|
|
6
|
+
* 不再加载(配置页 404、飞书完全没反应),而代码和配置文件都看着正常。
|
|
7
|
+
*
|
|
8
|
+
* 这里只做「读 + 判断」,把结论交给调用方决定是报错还是还原。
|
|
9
|
+
*
|
|
10
|
+
* @module dsh-feishu-notify/patch-guard
|
|
11
|
+
*/
|
|
12
|
+
import fs from 'node:fs'
|
|
13
|
+
|
|
14
|
+
/** 本插件在 profile 里的固定 id。 */
|
|
15
|
+
export const ENTRY_ID = 'feishu-notify'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 检查 patch 文件里本插件的结构是否完整。
|
|
19
|
+
* @param file - `cordis.patch.yml` 路径。
|
|
20
|
+
* @param id - 条目 id,默认 `feishu-notify`。
|
|
21
|
+
* @returns `{ ok, mounts, configs, reason }`
|
|
22
|
+
* - `mounts`:`insert:` 里挂载了几次(正常应为 1)
|
|
23
|
+
* - `configs`:顶层同 id 的配置覆盖行数(正常应为 1)
|
|
24
|
+
* - `ok`:两者都 ≥ 1
|
|
25
|
+
*/
|
|
26
|
+
export function inspectPatch(file, id = ENTRY_ID) {
|
|
27
|
+
const empty = { ok: false, mounts: 0, configs: 0, reason: '读不到 patch 文件' }
|
|
28
|
+
let text
|
|
29
|
+
try {
|
|
30
|
+
text = fs.readFileSync(file, 'utf8')
|
|
31
|
+
} catch {
|
|
32
|
+
return empty
|
|
33
|
+
}
|
|
34
|
+
const lines = text.split(/\r?\n/)
|
|
35
|
+
let mounts = 0
|
|
36
|
+
let configs = 0
|
|
37
|
+
let inInsert = false
|
|
38
|
+
let insertIndent = 0
|
|
39
|
+
|
|
40
|
+
for (const line of lines) {
|
|
41
|
+
if (line.trim() === '' || line.trim().startsWith('#')) continue
|
|
42
|
+
const indent = line.length - line.trimStart().length
|
|
43
|
+
|
|
44
|
+
// 进入 / 离开 insert 块(insert 里的 id 是挂载,缩进更深)
|
|
45
|
+
if (/^-\s*insert:\s*$/.test(line)) {
|
|
46
|
+
inInsert = true
|
|
47
|
+
insertIndent = indent
|
|
48
|
+
continue
|
|
49
|
+
}
|
|
50
|
+
if (inInsert && indent <= insertIndent && /^-\s*/.test(line)) {
|
|
51
|
+
inInsert = false
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const match = line.match(/^\s*-?\s*id:\s*['"]?([\w.-]+)['"]?\s*$/)
|
|
55
|
+
if (match === null || match[1] !== id) continue
|
|
56
|
+
if (inInsert) mounts += 1
|
|
57
|
+
else if (/^\s*-\s*id:/.test(line)) configs += 1
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const ok = mounts >= 1 && configs >= 1
|
|
61
|
+
const reason = ok
|
|
62
|
+
? ''
|
|
63
|
+
: mounts === 0 && configs === 0
|
|
64
|
+
? '插件的挂载与配置条目都不见了(保存时被整体覆盖)'
|
|
65
|
+
: mounts === 0
|
|
66
|
+
? '插件的挂载条目(insert 里的 id)不见了,插件将不再加载'
|
|
67
|
+
: '插件的配置条目不见了'
|
|
68
|
+
return { ok, mounts, configs, reason }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 保存后自检:给不完整的 patch 准备一句能直接给用户看的话。
|
|
73
|
+
* @param file - patch 路径。
|
|
74
|
+
* @param options - id / backup(可选:备份文件路径,用于提示怎么恢复)。
|
|
75
|
+
* @returns `{ ok, message }`
|
|
76
|
+
*/
|
|
77
|
+
export function verifyAfterSave(file, { id = ENTRY_ID, backup } = {}) {
|
|
78
|
+
const state = inspectPatch(file, id)
|
|
79
|
+
if (state.ok) return { ok: true, message: '' }
|
|
80
|
+
const suffix = typeof backup === 'string' && backup !== '' ? `\n可以从备份恢复:${backup}` : ''
|
|
81
|
+
return {
|
|
82
|
+
ok: false,
|
|
83
|
+
message: `⚠️ 配置已保存,但 ${id} 的条目结构不完整:${state.reason}${suffix}\n` +
|
|
84
|
+
'请在 profile 的 cordis.patch.yml 末尾补回,否则重启后插件不会加载。',
|
|
85
|
+
state,
|
|
86
|
+
}
|
|
87
|
+
}
|
package/lib/session-router.js
CHANGED
|
@@ -29,6 +29,46 @@ const STOP_COMMANDS = new Set(['停止', '停', '中断', '打住', 'stop', 'can
|
|
|
29
29
|
/** 控制命令:看状态。 */
|
|
30
30
|
const STATUS_COMMANDS = new Set(['状态', '进度', '在干嘛', 'status', 'state'])
|
|
31
31
|
|
|
32
|
+
/** 新建会话的命令前缀词。 */
|
|
33
|
+
const CREATE_WORDS = ['新建', '新会话', '开一个', '开个', 'new', 'create']
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 解析「新建」命令:`新建 [标题] [指令]`。
|
|
37
|
+
*
|
|
38
|
+
* - `新建` → 开一个没标题的会话
|
|
39
|
+
* - `新建 前端日报` → 标题设为「前端日报」
|
|
40
|
+
* - `新建 前端日报 帮我看下构建` → 建完直接投第一条指令
|
|
41
|
+
*
|
|
42
|
+
* @param text - 指令正文。
|
|
43
|
+
* @returns `{ title, text }` 或 undefined(不是新建命令)。
|
|
44
|
+
*/
|
|
45
|
+
export function parseCreate(text) {
|
|
46
|
+
if (typeof text !== 'string') return undefined
|
|
47
|
+
const value = text.trim()
|
|
48
|
+
if (value === '') return undefined
|
|
49
|
+
const lower = value.toLowerCase()
|
|
50
|
+
const word = CREATE_WORDS.find((item) => lower === item || lower.startsWith(`${item} `) || lower.startsWith(`${item} `))
|
|
51
|
+
if (word === undefined) return undefined
|
|
52
|
+
const rest = value.slice(word.length).trim()
|
|
53
|
+
if (rest === '') return { title: '', text: '' }
|
|
54
|
+
// 第一个空格前是标题,后面全是指令;标题里允许没有空格(整段都当标题)
|
|
55
|
+
const match = rest.match(/^(\S+)\s+([\s\S]+)$/)
|
|
56
|
+
if (match === null) return { title: rest, text: '' }
|
|
57
|
+
return { title: match[1], text: match[2].trim() }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 把「新建会话」的结果说成人话。
|
|
62
|
+
* @param options - title / id / sent(是否已经投递了第一条指令)。
|
|
63
|
+
* @returns 纯文本。
|
|
64
|
+
*/
|
|
65
|
+
export function formatCreated({ title, id, sent } = {}) {
|
|
66
|
+
const name = typeof title === 'string' && title !== '' ? `「${title}」` : '新会话'
|
|
67
|
+
const shortId = typeof id === 'string' && id !== '' ? `(#${id.slice(-4)})` : ''
|
|
68
|
+
const tail = sent === true ? ',第一条指令已投进去' : ',等你发第一条指令'
|
|
69
|
+
return `🆕 已创建${name}${shortId}${tail}\n之后可以直接「@${title !== undefined && title !== '' ? title : '它的标题'} 内容」,或发「列表」挑编号。`
|
|
70
|
+
}
|
|
71
|
+
|
|
32
72
|
/**
|
|
33
73
|
* 解析控制命令(可单独发,也可以跟在 `@标题` 后面)。
|
|
34
74
|
* @param text - 指令正文。
|
|
@@ -186,6 +226,7 @@ export function formatHelp({ maxPerMinute, prefix } = {}) {
|
|
|
186
226
|
'· 发「@最近 帮我跑测试」→ 交给上次那个会话',
|
|
187
227
|
'· 发「列表」→ 收到正在跑的会话编号',
|
|
188
228
|
'· 发「2 帮我跑测试」→ 只交给第 2 个会话(编号 10 分钟内有效)',
|
|
229
|
+
'· 发「新建 前端日报」→ 开一个新会话;「新建 标题 内容」→ 建完直接投第一条指令',
|
|
189
230
|
'· 发「状态」→ 看各会话在跑还是空闲;「停止」→ 中断当前这一轮(也能 @标题 停止)',
|
|
190
231
|
'',
|
|
191
232
|
'【审批】',
|
package/lib/settings-page.js
CHANGED
|
@@ -800,6 +800,11 @@ const SCRIPT = `
|
|
|
800
800
|
postJson(base + '/api/save', readForm())
|
|
801
801
|
.then(function (result) {
|
|
802
802
|
if (!result.ok) throw new Error(result.data.error || ('HTTP ' + (result.data.status || '')));
|
|
803
|
+
// 后端保存后会自检「插件的挂载条目还在不在」;不在就别自动刷新,把警告摆出来
|
|
804
|
+
if (result.data.warning) {
|
|
805
|
+
setStatus(result.data.warning, 'bad');
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
803
808
|
setStatus('已保存,配置正在热重载,页面即将刷新…', 'ok');
|
|
804
809
|
setTimeout(function () { location.reload(); }, 900);
|
|
805
810
|
})
|