@fabianactor/dsh-lil-whale-group 1.12.1 → 1.12.3
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/lib/index.js +9 -4
- package/lib/log-format-core.js +66 -4
- package/lib/roster-audit-core.js +11 -5
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1851,7 +1851,10 @@ function recordCodeFpHistory() {
|
|
|
1851
1851
|
function bootLog(record) {
|
|
1852
1852
|
try {
|
|
1853
1853
|
mkdirSync(dirname(BOOT_LOG), { recursive: true })
|
|
1854
|
-
|
|
1854
|
+
// 2026-11-19 fi-0002(小鱼丸,群第 2263 行):`at` 原来在 bootLog 与镜像写入处各生成一次,
|
|
1855
|
+
// 同进程同一次启动的两本账能差 1–2ms —— "at+pid join" 只在同毫秒时成立。
|
|
1856
|
+
// 现在 `at` 由调用方一次拼进 record(bootRecordWithNote 里有),两处共用;调用方没给才补一次。
|
|
1857
|
+
appendFileSync(BOOT_LOG, JSON.stringify({ at: record.at ?? new Date().toISOString(), ...record }) + '\n', 'utf8')
|
|
1855
1858
|
} catch {}
|
|
1856
1859
|
}
|
|
1857
1860
|
|
|
@@ -1966,7 +1969,8 @@ function apply(ctx) {
|
|
|
1966
1969
|
// 小鱼丸/小满 #1670–#1672(2026-11-18):镜像到 pool\group\plugin.log 的那一行原来 spread 的是
|
|
1967
1970
|
// bootRecord,而 note 只临时贴在 bootLog 的参数里 ⇒ 同一批 boot 行在群里那本没有 note。
|
|
1968
1971
|
// 修法不是补一个词,而是"一次拼好、两处都用同一个对象":以后 bootRecord 加字段,镜像自动跟上。
|
|
1969
|
-
|
|
1972
|
+
// 2026-11-19 fi-0002:`at` 在这里生成一次,两本账共用(bootLog 与下面的镜像写都读它)。
|
|
1973
|
+
const bootRecordWithNote = { at: new Date().toISOString(), note: 'boot', ...bootRecord }
|
|
1970
1974
|
bootLog(bootRecordWithNote)
|
|
1971
1975
|
// 小鱼丸私聊第 53 行(2026-11-19):boot 行只留了一个时刻的指纹,
|
|
1972
1976
|
// 回答不了“改过没有”;在值变化时补一行,账上有历史值才判得动。
|
|
@@ -1979,6 +1983,7 @@ function apply(ctx) {
|
|
|
1979
1983
|
const repoInPondLayout = basename(CFG.repoRoot) === 'app'
|
|
1980
1984
|
if (!CFG._exists && !repoInPondLayout) {
|
|
1981
1985
|
const layoutWarn = {
|
|
1986
|
+
at: new Date().toISOString(),
|
|
1982
1987
|
note: 'layout-warning',
|
|
1983
1988
|
why: 'no-config-and-not-pond-layout',
|
|
1984
1989
|
repoRoot: CFG.repoRoot,
|
|
@@ -1987,11 +1992,11 @@ function apply(ctx) {
|
|
|
1987
1992
|
}
|
|
1988
1993
|
bootLog(layoutWarn)
|
|
1989
1994
|
try {
|
|
1990
|
-
appendFileSync(join(GROUP_DIR, 'plugin.log'), JSON.stringify({
|
|
1995
|
+
appendFileSync(join(GROUP_DIR, 'plugin.log'), JSON.stringify({ ...layoutWarn }) + '\n', 'utf8')
|
|
1991
1996
|
} catch {}
|
|
1992
1997
|
}
|
|
1993
1998
|
try {
|
|
1994
|
-
appendFileSync(join(GROUP_DIR, 'plugin.log'), JSON.stringify({
|
|
1999
|
+
appendFileSync(join(GROUP_DIR, 'plugin.log'), JSON.stringify({ ...bootRecordWithNote }) + '\n', 'utf8')
|
|
1995
2000
|
} catch {}
|
|
1996
2001
|
|
|
1997
2002
|
// 无人值守:成员进程把自己那段会话挂上(工具要经过 session-controller 才挂得上)
|
package/lib/log-format-core.js
CHANGED
|
@@ -17,18 +17,28 @@
|
|
|
17
17
|
// 2. key 的顺序不再是签名的一部分:比较的是"每个 key 的值",不是拼好的字符串。
|
|
18
18
|
// (小鱼丸:"签名的相等是按字符串比的,顺序不同就算变了"——重排常量会让每次启动多一行。)
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
// 2026-11-19 fi-0001(小满,群第 2260 行):`changed=` 声明的是"格式变过的事件",
|
|
21
|
+
// 不是"这本账里所有 kind"——于是 `error`(1129 行)从来没被任何声明覆盖,声明和检查器
|
|
22
|
+
// 两格都看不见它。声明写漏是常态,所以补两件事:
|
|
23
|
+
// 1. `kinds=` 把代码会写的 kind 列成完整清单(这张表就是声明;加一个 kind 必须改它);
|
|
24
|
+
// 2. `auditKinds()` 拿账上出现过的 kind 跟它对,报"未声明的 kind 有几行"。
|
|
25
|
+
// 判据(小满):「声明描述它想管的 kind,检查器该报它不管的 kind 有几行」。
|
|
26
|
+
// 2026-11-19 fi-0001 小满复验 #2269:`kinds=` 声明的是**正文事件**;`log-format` 是表头这一行自己的 kind,
|
|
27
|
+
// 不属于正文清单(否则每本带新表头的账都会把自己报成未声明)。所以这里不收它,对账时也不数它。
|
|
28
|
+
export const LOG_KINDS = ['deliver', 'error', 'note', 'resumed', 'skip', 'started', 'stopped', 'wake', 'wake-caps', 'wake-skip', 'wake-try', 'woke']
|
|
29
|
+
|
|
30
|
+
export const LOG_FORMAT_SIG = `fmt=3 changed=skip,wake-skip,deliver fields=deny,note,reason field-since=codeFp:r255,member:r292,note:r293 kinds=${LOG_KINDS.join(',')}`
|
|
21
31
|
|
|
22
32
|
const MARK = ' | log-format | '
|
|
23
33
|
// 参与指纹的 key(顺序固定输出,但比较时按 key 取值——顺序不进指纹)。
|
|
24
|
-
const KEYS = ['fmt', 'changed', 'fields', 'field-since']
|
|
34
|
+
const KEYS = ['fmt', 'changed', 'fields', 'field-since', 'kinds']
|
|
25
35
|
export const LOG_FORMAT_KEYS = KEYS
|
|
26
36
|
|
|
27
37
|
// 从 detail 里按 ` (^|空格)key=值` 取每个 key 的值。
|
|
28
38
|
// 值里夹着别的 key 的字面量不会影响:这里只认"空白之后"的 key。
|
|
29
39
|
function parseDetail(detail) {
|
|
30
40
|
const map = {}
|
|
31
|
-
const re = /(?:^|\s)(fmt|changed|fields|field-since)=(\S*)/g
|
|
41
|
+
const re = /(?:^|\s)(fmt|changed|fields|field-since|kinds)=(\S*)/g
|
|
32
42
|
let m = re.exec(detail)
|
|
33
43
|
while (m) {
|
|
34
44
|
map[m[1]] = m[2]
|
|
@@ -48,7 +58,7 @@ function listCanonical(value) {
|
|
|
48
58
|
return value.split(',').map((part) => part.trim()).filter(Boolean).sort().join(',')
|
|
49
59
|
}
|
|
50
60
|
|
|
51
|
-
const LIST_KEYS = new Set(['changed', 'fields', 'field-since'])
|
|
61
|
+
const LIST_KEYS = new Set(['changed', 'fields', 'field-since', 'kinds'])
|
|
52
62
|
|
|
53
63
|
function canonicalOf(map) {
|
|
54
64
|
const out = {}
|
|
@@ -101,3 +111,55 @@ export function buildLogFormatDetail({ signature = LOG_FORMAT_SIG, since, pid, t
|
|
|
101
111
|
const who = to ? ` to=${to}` : ''
|
|
102
112
|
return `${signature} since=${at} pid=${pid}${who}`
|
|
103
113
|
}
|
|
114
|
+
|
|
115
|
+
// 账上一行是 `<日期> <时间> | kind | 正文`。取出 kind;不是这个形状返回 ''。
|
|
116
|
+
// 2026-11-19 fi-0001:对账要知道"账上到底出现过哪些 kind",不能只信声明。
|
|
117
|
+
export function kindOfLine(line) {
|
|
118
|
+
const m = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \| ([A-Za-z0-9_-]+) \|/.exec(String(line || ''))
|
|
119
|
+
return m ? m[1] : ''
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// 从最后一行 log-format 取声明的 kind 清单;账上还没有带 kinds= 的表头时返回 null。
|
|
123
|
+
// null 与空数组是两件事:老账是"这版代码之前没有这项声明",不是"声明了空清单"。
|
|
124
|
+
export function declaredKindsOf(lines) {
|
|
125
|
+
const last = findLastLogFormatLine(lines)
|
|
126
|
+
if (!last) return null
|
|
127
|
+
const map = parseDetail(detailOf(last))
|
|
128
|
+
if (typeof map.kinds !== 'string' || map.kinds === '') return null
|
|
129
|
+
return map.kinds.split(',').map((part) => part.trim()).filter(Boolean)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// 对账:账上出现过的 kind 逐类计数,跟声明比。
|
|
133
|
+
// declared:真正拿来对照的清单(表头的 kinds=,或老账时用 fallbackKinds=代码里的 LOG_KINDS)
|
|
134
|
+
// declaredSource:'header'(账自己声明的)| 'code'(账太老、按代码清单对照)| 'none'(没有对照)
|
|
135
|
+
// seen: [{ kind, count }] 按 kind 排序
|
|
136
|
+
// undeclared:账上有、声明里没有(这才是 fi-0001 要报的那一类)
|
|
137
|
+
// missing:声明里有、账上还没出现(用来区分"声明了但没用过")
|
|
138
|
+
// 2026-11-19 小满复验 #2269 指出:老账没有 kinds= 时若直接判"不知道",
|
|
139
|
+
// `bogus-kind` 这类整类隐形的 kind 在老账里依然报不出来 ⇒ 默认用代码清单对照('code'),
|
|
140
|
+
// 只有调用方明确不给 fallback 才是 'none'("判不了")。
|
|
141
|
+
export function auditKinds(lines, fallbackKinds = null) {
|
|
142
|
+
const list = Array.isArray(lines) ? lines : []
|
|
143
|
+
const seenMap = new Map()
|
|
144
|
+
for (const row of list) {
|
|
145
|
+
const kind = kindOfLine(row)
|
|
146
|
+
// 表头行自己的 kind 不进正文清单(fi-0001,小满 #2269)。
|
|
147
|
+
if (!kind || kind === 'log-format') continue
|
|
148
|
+
seenMap.set(kind, (seenMap.get(kind) ?? 0) + 1)
|
|
149
|
+
}
|
|
150
|
+
const seen = [...seenMap.entries()]
|
|
151
|
+
.map(([kind, count]) => ({ kind, count }))
|
|
152
|
+
.sort((a, b) => (a.kind < b.kind ? -1 : a.kind > b.kind ? 1 : 0))
|
|
153
|
+
const headerKinds = declaredKindsOf(list)
|
|
154
|
+
const declared = headerKinds ?? (Array.isArray(fallbackKinds) ? fallbackKinds : null)
|
|
155
|
+
const declaredSource = headerKinds !== null ? 'header' : declared !== null ? 'code' : 'none'
|
|
156
|
+
if (declared === null) return { declared: null, declaredSource, seen, undeclared: [], missing: [] }
|
|
157
|
+
const declaredSet = new Set(declared)
|
|
158
|
+
return {
|
|
159
|
+
declared,
|
|
160
|
+
declaredSource,
|
|
161
|
+
seen,
|
|
162
|
+
undeclared: seen.filter((item) => !declaredSet.has(item.kind)),
|
|
163
|
+
missing: [...declaredSet].filter((kind) => !seenMap.has(kind)).sort(),
|
|
164
|
+
}
|
|
165
|
+
}
|
package/lib/roster-audit-core.js
CHANGED
|
@@ -22,12 +22,18 @@
|
|
|
22
22
|
* `other` 列出非鱼家目录,`skip` 的说明也改成"角色 + 真正的家"。
|
|
23
23
|
*
|
|
24
24
|
* `fmt=5`(2026-11-18 19:5x,第三条鱼私信):末尾加一格 `media=`,把共享视频缓存的现状挂在这条
|
|
25
|
-
* 周期行上——`media=files:3 bytes:18117679 oldest:11-15`(没有目录 `media=no-dir`,空目录
|
|
26
|
-
* `oldest:none`)。原因是 prune 事件行"没东西可删就不写",于是"机制没跑"和"跑了但没东西"同形;
|
|
25
|
+
* 周期行上——`media=files:3 bytes:18117679 oldest-used:11-15`(没有目录 `media=no-dir`,空目录
|
|
26
|
+
* `oldest-used:none`)。原因是 prune 事件行"没东西可删就不写",于是"机制没跑"和"跑了但没东西"同形;
|
|
27
27
|
* 这一格让"它看过目录"有凭据,而不必每小时写一条事件。
|
|
28
|
+
*
|
|
29
|
+
* `fmt=6`(2026-11-19,小鱼丸核缓存时发现):把 `oldest:` 改名 `oldest-used:`。这一格取的是
|
|
30
|
+
* 文件的 `mtime`,而 bili-eyes 命中缓存时会 `utimesSync(file, now, now)`("还有人用"就把时间
|
|
31
|
+
* 拨到现在),所以它答的是"最久没被用到的那份,最近一次被用到是何时",不是"哪天下的"。
|
|
32
|
+
* prune 按 `mtime` 判 7 天本来就是 LRU 语义(还有人在用就不清),机制不动,只把名字改成它
|
|
33
|
+
* 真正在答的问题。
|
|
28
34
|
*/
|
|
29
35
|
|
|
30
|
-
const FMT =
|
|
36
|
+
const FMT = 6
|
|
31
37
|
|
|
32
38
|
function namesOf(list) {
|
|
33
39
|
return list && list.length ? list.join(',') : 'none'
|
|
@@ -78,7 +84,7 @@ export function rosterAuditCounts({ rosterKeys = [], fishEntries = [], humanKeys
|
|
|
78
84
|
* 拼一行。`problems` 非空时事件名是 `roster-mismatch`,否则 `roster-audit` 并以 `ok` 收尾。
|
|
79
85
|
*
|
|
80
86
|
* `media`(可选):`mediaCacheStats()` 的结果。三种状态三句话,不共用缺省:
|
|
81
|
-
* - 给了且读到了 ⇒ `media=files:… bytes:… oldest:…`;
|
|
87
|
+
* - 给了且读到了 ⇒ `media=files:… bytes:… oldest-used:…`;
|
|
82
88
|
* - 父目录在、缓存目录还没建 ⇒ `media=no-dir`(正常:还没下过);
|
|
83
89
|
* - 试过、失败了 ⇒ `media=unknown:<原因>`(`EACCES`=读不到、`ENOENT`=父目录也不在、别的写码)。
|
|
84
90
|
* "`unknown` 不带原因"等于把"没记"和"试过、失败了"混成一句(第三条鱼 2026-11-18 私信)。
|
|
@@ -97,7 +103,7 @@ export function buildRosterAuditLine({ ts, counts, problems = [], media = null }
|
|
|
97
103
|
: media.error
|
|
98
104
|
? `media=unknown:${media.error}`
|
|
99
105
|
: media.existed
|
|
100
|
-
? `media=files:${media.files} bytes:${media.bytes} oldest:${media.oldestMs === null ? 'none' : dateOf(media.oldestMs)}`
|
|
106
|
+
? `media=files:${media.files} bytes:${media.bytes} oldest-used:${media.oldestMs === null ? 'none' : dateOf(media.oldestMs)}`
|
|
101
107
|
: 'media=no-dir'
|
|
102
108
|
const parts = [
|
|
103
109
|
`members=${counts.fishKeys.length}(fish;keys=${counts.rosterKeys.length};not-fish=${namesOf(counts.humanKeys)})`,
|