dsh-feishu-lark-notify 0.25.1 → 0.25.2

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.
@@ -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
@@ -29,6 +29,7 @@ import { listSessionIndex, readArchivedIds, readWorkspaces, readSessionModel, no
29
29
  import { parseRoute, parseAtCommand, parseControl, matchByLabel, formatSessionList, formatStatus, 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.25.1'
40
+ export const VERSION = '0.25.2'
40
41
 
41
42
  /** 内存日志上限。 */
42
43
  const LOG_LIMIT = 200
@@ -962,13 +963,32 @@ export function apply(ctx, rawConfig) {
962
963
  if (active.length === 0) log('没有任何可用渠道:插件将空转,只在配置页可见')
963
964
  const saved = await persist(rawFrom(next))
964
965
  log(`配置已保存(${saved.mode}${saved.path ? `: ${saved.path}` : ''}),渠道=${active.join(',') || '无'}${skipped.length > 0 ? `,跳过 ${skipped.length} 个 env 字段` : ''}`)
966
+
967
+ // 保存后自检:确认本插件的挂载条目还在,否则重启后插件就不加载了
968
+ let guardWarning = ''
969
+ try {
970
+ const patchFile = saved.path ?? resolvePatchPath({ configEditor: ctx.get('configEditor'), profileContext: ctx.get('profileContext') })
971
+ if (patchFile !== undefined) {
972
+ const check = verifyAfterSave(patchFile)
973
+ if (!check.ok) {
974
+ guardWarning = check.message
975
+ noteFailure('保存后自检', check.message)
976
+ }
977
+ }
978
+ } catch (error) {
979
+ log(`保存后自检异常: ${error?.message ?? error}`)
980
+ }
981
+
965
982
  sendJson(res, 200, {
966
983
  ok: true,
967
984
  mode: saved.mode,
968
985
  config: publicConfig(effective),
969
986
  activeChannels: active,
970
987
  skippedEnvFields: skipped,
971
- note: skipped.length > 0 ? '已保存;由 .env 提供的字段不会被写入 YAML' : '保存成功,页面会自动刷新',
988
+ note: guardWarning !== ''
989
+ ? guardWarning
990
+ : skipped.length > 0 ? '已保存;由 .env 提供的字段不会被写入 YAML' : '保存成功,页面会自动刷新',
991
+ warning: guardWarning !== '' ? guardWarning : undefined,
972
992
  })
973
993
  } catch (error) {
974
994
  log(`保存失败: ${error?.message ?? error}`)
@@ -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
+ }
@@ -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
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-feishu-lark-notify",
3
- "version": "0.25.1",
3
+ "version": "0.25.2",
4
4
  "description": "把 DSH 的任务完成 / 需要你处理的通知推到飞书(Lark):在飞书里点审批、答选择题、按标题把指令交给指定会话,也能收发图片和文件。自带可视化配置页。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",