@fabianactor/dsh-lil-whale-group 1.12.2 → 1.13.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/lib/cursor-core.js +85 -0
- package/lib/index.js +450 -108
- package/lib/members-core.js +20 -0
- package/lib/mention-core.js +137 -0
- package/lib/note-core.js +37 -0
- package/lib/say-core.js +7 -2
- package/lib/stall-core.js +68 -0
- package/lib/wake-preview-core.js +27 -12
- package/package.json +47 -47
package/lib/index.js
CHANGED
|
@@ -8,9 +8,14 @@
|
|
|
8
8
|
// 身份优先按**钉住的 sessionId** 认(2026-11-09 起):同一目录下可能有两段会话,
|
|
9
9
|
// 按 cwd 会叫错人。cwd 只作退路,并在 plugin.log 留一行痕迹。
|
|
10
10
|
|
|
11
|
-
import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
11
|
+
import { appendFileSync, copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
12
12
|
import { printableText } from './text-clean.js'
|
|
13
13
|
import { sayProblemOf, channelProblemOf } from './say-core.js'
|
|
14
|
+
import { noteCodeOf, intentNoteTextOf, watchmanSkipLineOf } from './note-core.js'
|
|
15
|
+
import { classifyStall, stallSentenceOf } from './stall-core.js'
|
|
16
|
+
import { classifyCursorRead, countsKnownOf, heldTrustedOf } from './cursor-core.js'
|
|
17
|
+
import { membersWithKeys } from './members-core.js'
|
|
18
|
+
import { MENTION_ALL, normalizeMention, wantsWake, mentionTextOf, mentionDisplayOf, bumpHeld, heldOf, clearHeld, heldSentenceOf } from './mention-core.js'
|
|
14
19
|
import { codeFingerprint } from './code-fp.js'
|
|
15
20
|
import { codeFpChangeOf, codeFpHistoryLine, codeFpLedgerOf, CODE_FP_LEDGER } from './code-fp-history-core.js'
|
|
16
21
|
import { join, dirname, basename } from 'node:path'
|
|
@@ -1006,6 +1011,11 @@ function watchmanLog(result, why) {
|
|
|
1006
1011
|
const pad = (n) => String(n).padStart(2, '0')
|
|
1007
1012
|
const ts = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
|
|
1008
1013
|
const streakSuffix = result === 'error' ? ` streak=${++errorStreak}` : ''
|
|
1014
|
+
if ((result === 'note' || result === 'hint') && !String(why).includes('=')) {
|
|
1015
|
+
// fi-0012(r417):共享账里不允许裸散文行——读端没有 key= 可抓,只能进 blind。
|
|
1016
|
+
// 不改调用点,先在写端兜住:没带 key= 的自由文本,自动降格成 note=unkeyed detail=…。
|
|
1017
|
+
why = 'note=unkeyed detail=' + String(why).replace(/\s+/g, ' ').trim()
|
|
1018
|
+
}
|
|
1009
1019
|
if (result === 'error') bumpOwnError()
|
|
1010
1020
|
if (result !== 'error' && result !== 'started') errorStreak = 0
|
|
1011
1021
|
appendFileSync(WATCHMAN_LOG, `${ts} | ${result} | ${why}${streakSuffix}\n`, 'utf8')
|
|
@@ -1208,7 +1218,7 @@ function buildMembers() {
|
|
|
1208
1218
|
logLine({ note: 'roster-fallback', source: 'builtin', members: Object.keys(out).length })
|
|
1209
1219
|
} catch {}
|
|
1210
1220
|
}
|
|
1211
|
-
return out
|
|
1221
|
+
return membersWithKeys(out)
|
|
1212
1222
|
}
|
|
1213
1223
|
try {
|
|
1214
1224
|
const raw = JSON.parse(readFileSync(file, 'utf8'))
|
|
@@ -1228,9 +1238,10 @@ function buildMembers() {
|
|
|
1228
1238
|
logLine({ note: 'members-unreadable', file, why: String(error?.message ?? error).slice(0, 120) })
|
|
1229
1239
|
} catch {}
|
|
1230
1240
|
}
|
|
1231
|
-
return out
|
|
1241
|
+
return membersWithKeys(out)
|
|
1232
1242
|
}
|
|
1233
1243
|
|
|
1244
|
+
// 值对象都带自己的 key:planDue/noteOnce 拼 to= 时要用(fi-0010,r404)。
|
|
1234
1245
|
const MEMBERS = buildMembers()
|
|
1235
1246
|
|
|
1236
1247
|
/**
|
|
@@ -1468,10 +1479,8 @@ function ensureParent(file) {
|
|
|
1468
1479
|
}
|
|
1469
1480
|
}
|
|
1470
1481
|
|
|
1471
|
-
/**
|
|
1472
|
-
function
|
|
1473
|
-
const own = readJson(cursorFileOf(member), null)
|
|
1474
|
-
if (own !== null && typeof own === 'object' && !Array.isArray(own)) return own
|
|
1482
|
+
/** 第一次读不到自己的游标文件时,从整体 cursor.json 里摘出属于他的键(迁移期用)。 */
|
|
1483
|
+
function seededCursorsOf(member) {
|
|
1475
1484
|
const seeded = {}
|
|
1476
1485
|
for (const [key, value] of Object.entries(readJson(LEGACY_CURSOR, {}) ?? {})) {
|
|
1477
1486
|
if (key === member || key.startsWith(`${member}@`)) seeded[key] = value
|
|
@@ -1479,6 +1488,112 @@ function readCursors(member) {
|
|
|
1479
1488
|
return seeded
|
|
1480
1489
|
}
|
|
1481
1490
|
|
|
1491
|
+
/** 读这个成员的游标(旧调用口;新代码用 readCursorState 拿来源)。 */
|
|
1492
|
+
function readCursors(member) {
|
|
1493
|
+
const own = readJson(cursorFileOf(member), null)
|
|
1494
|
+
if (own !== null && typeof own === 'object' && !Array.isArray(own)) return own
|
|
1495
|
+
return seededCursorsOf(member)
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
// 2026-11-23(fi-0013):读游标也要能回答"从哪儿读到的"。
|
|
1499
|
+
// 旧代码里三件事全变成 0:文件里没有这一格 / 文件不见了 / 文件坏了 ——
|
|
1500
|
+
// 于是"第一次读"和"进度丢了"长得一样,唤醒词还替人编条数(fi-0015)。
|
|
1501
|
+
// 这里只区分来源,起点怎么算交给 cursor-core.classifyCursorRead。
|
|
1502
|
+
function readCursorState(member) {
|
|
1503
|
+
const file = cursorFileOf(member)
|
|
1504
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
1505
|
+
let text
|
|
1506
|
+
try {
|
|
1507
|
+
text = readFileSync(file, 'utf8')
|
|
1508
|
+
} catch (error) {
|
|
1509
|
+
if (error?.code === 'ENOENT') {
|
|
1510
|
+
// 2026-11-23(LeeaCP 验收 B):文件不在时,先看 meta 能不能把各通道补回来;
|
|
1511
|
+
// 补不回来才退回"读到哪儿算哪儿"。重建一个复合文件不许顺手丢掉没坏的键。
|
|
1512
|
+
const recovered = recoveredCursorsOf(member)
|
|
1513
|
+
if (recovered !== null) return { cursors: recovered, source: 'recovered' }
|
|
1514
|
+
const seeded = seededCursorsOf(member)
|
|
1515
|
+
return { cursors: seeded, source: Object.keys(seeded).length === 0 ? 'missing' : 'legacy' }
|
|
1516
|
+
}
|
|
1517
|
+
continue
|
|
1518
|
+
}
|
|
1519
|
+
try {
|
|
1520
|
+
const json = JSON.parse(text)
|
|
1521
|
+
if (json !== null && typeof json === 'object' && !Array.isArray(json)) {
|
|
1522
|
+
return { cursors: json, source: 'file' }
|
|
1523
|
+
}
|
|
1524
|
+
} catch {
|
|
1525
|
+
// 读坏了:可能是半截写入,再试一次;三次都不行就当 unknown。
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
// 2026-11-23(LeeaCP 验收 C):坏过一次要留下痕迹——自愈过的和从没坏过的不能同形。
|
|
1529
|
+
quarantineCursorFile(member)
|
|
1530
|
+
const recovered = recoveredCursorsOf(member)
|
|
1531
|
+
if (recovered !== null) return { cursors: recovered, source: 'recovered' }
|
|
1532
|
+
return { cursors: {}, source: 'unknown' }
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1535
|
+
/** 坏文件先复制一份带时刻的副本,再记一行账。副本只留证,不参与读。 */
|
|
1536
|
+
function quarantineCursorFile(member) {
|
|
1537
|
+
const file = cursorFileOf(member)
|
|
1538
|
+
try {
|
|
1539
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, '-').replace('T', '-').replace('Z', '')
|
|
1540
|
+
const dest = `${file}.corrupt-${stamp}`
|
|
1541
|
+
copyFileSync(file, dest)
|
|
1542
|
+
logLine({ note: 'cursor-corrupt', member, backup: basename(dest) })
|
|
1543
|
+
} catch (error) {
|
|
1544
|
+
logLine({ note: 'cursor-corrupt', member, backup: 'save-failed', error: String(error?.message ?? error).slice(0, 80) })
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
/** 从 meta(上一次真递到的行号)重建各通道的游标;没有 meta 就返回 null。 */
|
|
1549
|
+
function recoveredCursorsOf(member) {
|
|
1550
|
+
const channels = readCursorMeta(member).channels ?? {}
|
|
1551
|
+
const own = {}
|
|
1552
|
+
for (const [key, value] of Object.entries(channels)) {
|
|
1553
|
+
const delivered = value?.delivered
|
|
1554
|
+
if (typeof delivered === 'number' && Number.isFinite(delivered) && delivered >= 0) own[key] = delivered
|
|
1555
|
+
}
|
|
1556
|
+
if (Object.keys(own).length === 0) return null
|
|
1557
|
+
// 2026-11-23(r434,LeeaCP 验收):重建要连座位影子一起补,否则座位那份只记住"这次走到的通道",
|
|
1558
|
+
// 另外几格空着 —— 看起来像重建了一半,下次活动还会从 0 扫(held 把已读也算进去)。
|
|
1559
|
+
const out = { [member]: { ...own } }
|
|
1560
|
+
for (const sid of pinnedSessions(member)) {
|
|
1561
|
+
const seat = sid.replace(/^session-/, '').slice(0, 6)
|
|
1562
|
+
if (seat === '') continue
|
|
1563
|
+
out[`${member}@${seat}`] = { ...own }
|
|
1564
|
+
}
|
|
1565
|
+
return out
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
// 2026-11-23(fi-0013/0014):上一次**真的递到**第几行。
|
|
1569
|
+
// 游标文件被写过、删过、退回 0 时,拿它当底线:stored < last-delivered ⇒ 不重放。
|
|
1570
|
+
// 按成员存一盒(钥匙是通道),不再多一个文件/成员。
|
|
1571
|
+
const CURSOR_META_DIR = join(POOL_STATE, 'cursor-meta')
|
|
1572
|
+
function cursorMetaFileOf(member) {
|
|
1573
|
+
return join(CURSOR_META_DIR, `${member}.json`)
|
|
1574
|
+
}
|
|
1575
|
+
function readCursorMeta(member) {
|
|
1576
|
+
const raw = readJson(cursorMetaFileOf(member), null)
|
|
1577
|
+
const channels = raw !== null && typeof raw === 'object' && raw.channels !== null && typeof raw.channels === 'object'
|
|
1578
|
+
? raw.channels
|
|
1579
|
+
: {}
|
|
1580
|
+
return { fmt: 1, channels }
|
|
1581
|
+
}
|
|
1582
|
+
function lastDeliveredOf(member, channelKey) {
|
|
1583
|
+
const n = readCursorMeta(member).channels?.[channelKey]?.delivered
|
|
1584
|
+
return typeof n === 'number' && Number.isFinite(n) ? n : null
|
|
1585
|
+
}
|
|
1586
|
+
function noteDelivered(member, channelKey, delivered) {
|
|
1587
|
+
try {
|
|
1588
|
+
const meta = readCursorMeta(member)
|
|
1589
|
+
meta.channels[channelKey] = { delivered, at: new Date().toISOString() }
|
|
1590
|
+
mkdirSync(CURSOR_META_DIR, { recursive: true })
|
|
1591
|
+
writeJson(cursorMetaFileOf(member), meta)
|
|
1592
|
+
} catch (error) {
|
|
1593
|
+
logLine({ note: 'cursor-meta-write-failed', member, channel: channelKey, error: String(error?.message ?? error).slice(0, 80) })
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1482
1597
|
/**
|
|
1483
1598
|
* 写游标前顺手剪掉"让出去的椅子"的影子游标:座位号已经不在 pins.json 里的,那一格不该再留着。
|
|
1484
1599
|
* (她 2026-11-11 17:01 的观察:`lee@e17c3c` 停在 102,人已经不在群里了,账还挂着。)
|
|
@@ -1524,6 +1639,17 @@ function writeCursors(member, cursors) {
|
|
|
1524
1639
|
}
|
|
1525
1640
|
}
|
|
1526
1641
|
ensureParent(cursorFileOf(member))
|
|
1642
|
+
// 写前自检:座位影子的通道键集合应与主键一致(缺键 = 半份)。
|
|
1643
|
+
const mainKeys = Object.keys(kept[member] ?? {}).sort().join(',')
|
|
1644
|
+
for (const key of Object.keys(kept)) {
|
|
1645
|
+
if (key === member) continue
|
|
1646
|
+
const seatKeys = Object.keys(kept[key] ?? {}).sort().join(',')
|
|
1647
|
+
if (seatKeys === mainKeys) continue
|
|
1648
|
+
if (!cursorShapeLogged.has(key)) {
|
|
1649
|
+
cursorShapeLogged.add(key)
|
|
1650
|
+
logLine({ note: 'cursor-shape-mismatch', member, key, main: mainKeys, seat: seatKeys })
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1527
1653
|
writeJson(cursorFileOf(member), kept)
|
|
1528
1654
|
}
|
|
1529
1655
|
|
|
@@ -1598,6 +1724,8 @@ function stamp() {
|
|
|
1598
1724
|
}
|
|
1599
1725
|
|
|
1600
1726
|
function labelOf(who) {
|
|
1727
|
+
// 系统行不是人,也不是鱼:它自己署名(2026-11-23,fi-0016)。
|
|
1728
|
+
if (who === 'system') return '系统'
|
|
1601
1729
|
return MEMBERS[who]?.label ?? who
|
|
1602
1730
|
}
|
|
1603
1731
|
|
|
@@ -1757,7 +1885,7 @@ function sayPrivate(from, to, text, image = null, images = null) {
|
|
|
1757
1885
|
return record
|
|
1758
1886
|
}
|
|
1759
1887
|
|
|
1760
|
-
function say(from, to, text, channel = 'group', s = '', toSeat = '', image = null, images = null) {
|
|
1888
|
+
function say(from, to, text, channel = 'group', s = '', toSeat = '', image = null, images = null, mention = undefined) {
|
|
1761
1889
|
// 2026-11-17 r243:地址在执行时自己检查。
|
|
1762
1890
|
// 起因:裸 spec 路径下 `parameters.enum` 只是文档(宿主只校验 required/type),
|
|
1763
1891
|
// 第三条鱼实测 `group_say(to="group")` 成功入账 —— 写进一个没人读的地址,还不报错。
|
|
@@ -1783,21 +1911,25 @@ function say(from, to, text, channel = 'group', s = '', toSeat = '', image = nul
|
|
|
1783
1911
|
// channel = 屋里还有没有别人(group 默认 / dm 只有对象一个人)
|
|
1784
1912
|
// 所以 `to:"fabian"` + 默认 group = 群里公开对他说;私聊要显式 `channel:"dm"`。
|
|
1785
1913
|
const isDm = channel === 'dm'
|
|
1914
|
+
// mention(2026-11-22 r413):这条叫醒谁。没写就是 [] —— 谁都不叫醒(人和鱼同一套)。
|
|
1915
|
+
// 叫醒名单只存在 mention 里;群消息不再写 to(它只留给私聊与老记录)。
|
|
1916
|
+
const mentions = isDm
|
|
1917
|
+
? undefined
|
|
1918
|
+
: (mention === undefined ? [] : normalizeMention(mention, Object.keys(MEMBERS)))
|
|
1786
1919
|
if (isDm) return { ...sayPrivate(from, toKey, body, null, list), channel: 'dm' }
|
|
1787
1920
|
const record = {
|
|
1788
|
-
ts: new Date().toISOString(), from,
|
|
1921
|
+
ts: new Date().toISOString(), from, text: body, kind: 'say', channel: 'group',
|
|
1789
1922
|
...(s === '' ? {} : { s }),
|
|
1790
|
-
//
|
|
1791
|
-
|
|
1792
|
-
...(toSeat === '' ? {} : { toSeat }),
|
|
1923
|
+
// 叫醒谁(2026-11-22 r413):空数组 = 谁都不叫醒。群消息不再写 to / toSeat。
|
|
1924
|
+
mention: mentions,
|
|
1793
1925
|
// 图片(可选):只记定位信息,字节在 images\ 下。1 张写 image、多张写 images。
|
|
1794
1926
|
...(list.length === 0 ? {} : (list.length === 1 ? { image: list[0] } : { images: list })),
|
|
1795
1927
|
}
|
|
1796
1928
|
appendFileSync(MESSAGES, JSON.stringify(record) + '\n', 'utf8')
|
|
1797
|
-
//
|
|
1798
|
-
//
|
|
1799
|
-
const
|
|
1800
|
-
appendFileSync(READABLE, `**${stamp()} · ${labelOf(from)}${provenanceOf(s)}${
|
|
1929
|
+
// 投影里写「提到了:谁」(2026-11-22 r413,替掉原来的 `→ 收信人`):
|
|
1930
|
+
// 空名单就什么都不写。读记录的人从这一节看出这条点了谁的名字。
|
|
1931
|
+
const mentionLabel = mentionDisplayOf({ mention: mentions }, labelOf)
|
|
1932
|
+
appendFileSync(READABLE, `**${stamp()} · ${labelOf(from)}${provenanceOf(s)}${mentionLabel}**\n\n${readableBodyOf(body, list)}\n\n`, 'utf8')
|
|
1801
1933
|
return { ...record, channel: 'group' }
|
|
1802
1934
|
}
|
|
1803
1935
|
|
|
@@ -1817,6 +1949,120 @@ function setCursor(cursors, member, key, value) {
|
|
|
1817
1949
|
box[key] = value
|
|
1818
1950
|
cursors[member] = box
|
|
1819
1951
|
}
|
|
1952
|
+
|
|
1953
|
+
// ---------- 没叫醒的也要有账(2026-11-22) ----------
|
|
1954
|
+
// 游标会往前走(否则每轮都要重扫整段历史),但"你不在的时候群里还积着几条没点你的话"
|
|
1955
|
+
// 得能回答。状态按 (成员, 通道) 记在 pool\state\held\<成员>.json —— 不推游标的做法会让
|
|
1956
|
+
// 这些消息下次混进预览,看起来像是它们在叫醒你。
|
|
1957
|
+
const HELD_DIR = join(POOL_STATE, 'held')
|
|
1958
|
+
function heldFileOf(member) {
|
|
1959
|
+
return join(HELD_DIR, `${member}.json`)
|
|
1960
|
+
}
|
|
1961
|
+
function noteHeld(member, channelKey, count, line, ts) {
|
|
1962
|
+
try {
|
|
1963
|
+
mkdirSync(HELD_DIR, { recursive: true })
|
|
1964
|
+
writeJson(heldFileOf(member), bumpHeld(readJson(heldFileOf(member), null), channelKey, { count, line, ts }))
|
|
1965
|
+
} catch (error) {
|
|
1966
|
+
logLine({ note: 'held-write-failed', member, channel: channelKey, error: String(error?.message ?? error).replace(/\s+/g, ' ').slice(0, 120) })
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
function heldCountOf(member, channelKey) {
|
|
1970
|
+
try {
|
|
1971
|
+
return heldOf(readJson(heldFileOf(member), null), channelKey)
|
|
1972
|
+
} catch {
|
|
1973
|
+
return 0
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
function clearHeldOf(member, channelKey) {
|
|
1977
|
+
try {
|
|
1978
|
+
const prev = readJson(heldFileOf(member), null)
|
|
1979
|
+
if (prev === null) return
|
|
1980
|
+
writeJson(heldFileOf(member), clearHeld(prev, channelKey))
|
|
1981
|
+
} catch (error) {
|
|
1982
|
+
logLine({ note: 'held-clear-failed', member, channel: channelKey, error: String(error?.message ?? error).replace(/\s+/g, ' ').slice(0, 120) })
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
// ---------- 卡住要说话(2026-11-23,fi-0016 / GitHub #1) ----------
|
|
1986
|
+
// 只做「通道里看得见」这一档:投递之后 N 分钟还没有新写入、且这一轮还忙,
|
|
1987
|
+
// 就在私聊里落一条系统行。判据是启发式,措辞必须带「可能」;不碰审批本身。
|
|
1988
|
+
const STALL_DIR = join(POOL_STATE, 'stalls')
|
|
1989
|
+
const lastDeliveries = new Map() // member -> { at, ts }
|
|
1990
|
+
const stallNotified = new Map() // member -> deliveredAt(同一次投递只报一次)
|
|
1991
|
+
function stallFileOf(member) {
|
|
1992
|
+
return join(STALL_DIR, `${member}.json`)
|
|
1993
|
+
}
|
|
1994
|
+
function clearStallFile(member) {
|
|
1995
|
+
try { rmSync(stallFileOf(member), { force: true }) } catch {}
|
|
1996
|
+
}
|
|
1997
|
+
function sessionLogMtimeOf(member) {
|
|
1998
|
+
const info = MEMBERS[member]
|
|
1999
|
+
const sid = pinnedSession(member)
|
|
2000
|
+
if (!info?.dshHome || !sid) return null
|
|
2001
|
+
const root = join(info.dshHome, 'sessions')
|
|
2002
|
+
try {
|
|
2003
|
+
for (const project of readdirSync(root)) {
|
|
2004
|
+
const file = join(root, project, sid, 'session.v4.jsonl.zstd')
|
|
2005
|
+
if (existsSync(file)) return statSync(file).mtimeMs
|
|
2006
|
+
}
|
|
2007
|
+
} catch {}
|
|
2008
|
+
return null
|
|
2009
|
+
}
|
|
2010
|
+
function ownAgentStatusOf(ctx) {
|
|
2011
|
+
const agents = ctx.get('agents')
|
|
2012
|
+
const me = ownMember()
|
|
2013
|
+
const sid = pinnedSession(me)
|
|
2014
|
+
if (!agents || !sid) return null
|
|
2015
|
+
for (const agent of agents.list()) {
|
|
2016
|
+
if (sessionIdOf(agent) === sid) return agent.status ?? null
|
|
2017
|
+
}
|
|
2018
|
+
return null
|
|
2019
|
+
}
|
|
2020
|
+
/** 往「她 ↔ 人」这条私聊里追加一条系统行(不是她说的,也不叫醒谁)。 */
|
|
2021
|
+
function saySystemToDm(member, text) {
|
|
2022
|
+
mkdirSync(DM_DIR, { recursive: true })
|
|
2023
|
+
const human = humanKey()
|
|
2024
|
+
const record = { ts: new Date().toISOString(), from: 'system', to: member, text, kind: 'system', channel: 'dm' }
|
|
2025
|
+
appendFileSync(dmFileOf(member, human), JSON.stringify(record) + '\n', 'utf8')
|
|
2026
|
+
const readable = dmReadableOf(member, human)
|
|
2027
|
+
if (!existsSync(readable)) {
|
|
2028
|
+
writeFileSync(readable, `# 私聊 · ${labelOf(member)} / ${labelOf(human)}\n\n`, 'utf8')
|
|
2029
|
+
}
|
|
2030
|
+
appendFileSync(readable, `**${stamp()} · ${labelOf('system')}**\n\n${text}\n\n`, 'utf8')
|
|
2031
|
+
return record
|
|
2032
|
+
}
|
|
2033
|
+
function checkOwnStall(ctx) {
|
|
2034
|
+
const me = ownMember()
|
|
2035
|
+
if (me === null) return
|
|
2036
|
+
const delivery = lastDeliveries.get(me)
|
|
2037
|
+
if (!delivery) return
|
|
2038
|
+
const verdict = classifyStall({
|
|
2039
|
+
now: Date.now(),
|
|
2040
|
+
deliveredAt: delivery.at,
|
|
2041
|
+
sessionMtime: sessionLogMtimeOf(me),
|
|
2042
|
+
agentStatus: ownAgentStatusOf(ctx),
|
|
2043
|
+
})
|
|
2044
|
+
if (verdict.kind === 'working') { clearStallFile(me); return }
|
|
2045
|
+
if (verdict.kind !== 'stalled') return
|
|
2046
|
+
if (stallNotified.get(me) === delivery.at) return
|
|
2047
|
+
stallNotified.set(me, delivery.at)
|
|
2048
|
+
const text = stallSentenceOf({ label: labelOf(me), port: MEMBERS[me]?.port ?? '', since: verdict.lastAt ?? delivery.at })
|
|
2049
|
+
try {
|
|
2050
|
+
saySystemToDm(me, text)
|
|
2051
|
+
mkdirSync(STALL_DIR, { recursive: true })
|
|
2052
|
+
writeJson(stallFileOf(me), {
|
|
2053
|
+
fmt: 2,
|
|
2054
|
+
member: me,
|
|
2055
|
+
since: new Date(verdict.lastAt ?? delivery.at).toISOString(),
|
|
2056
|
+
deliveredAt: new Date(delivery.at).toISOString(),
|
|
2057
|
+
quietSec: verdict.quietSec,
|
|
2058
|
+
url: `http://127.0.0.1:${MEMBERS[me]?.port ?? ''}/`,
|
|
2059
|
+
at: new Date().toISOString(),
|
|
2060
|
+
})
|
|
2061
|
+
logLine({ note: 'stall-notified', member: me, quietSec: verdict.quietSec })
|
|
2062
|
+
} catch (error) {
|
|
2063
|
+
logLine({ note: 'stall-notify-failed', member: me, error: String(error?.message ?? error).replace(/\s+/g, ' ').slice(0, 120) })
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
1820
2066
|
/** 往 plugin.log 追一行(自检用,别让它影响主流程)。 */
|
|
1821
2067
|
function logLine(record) {
|
|
1822
2068
|
try {
|
|
@@ -2017,27 +2263,26 @@ function apply(ctx) {
|
|
|
2017
2263
|
const buildTool = hostOk && defineTool !== null ? defineTool : (options) => options
|
|
2018
2264
|
ctx.tools.register(buildTool({
|
|
2019
2265
|
name: 'group_say',
|
|
2020
|
-
description: '
|
|
2266
|
+
description: '说一句话。默认在群里说(群里的人都看得见;叫醒谁看 mention——不写就谁都不叫醒)。channel 给 dm 才是私下只对 to 那一个人说(不进群记录)。mention 是"叫醒谁",channel 是"还有没有别人在场"。发出即返回,不等对方回复。',
|
|
2021
2267
|
parameters: {
|
|
2022
|
-
|
|
2268
|
+
text: {
|
|
2023
2269
|
type: 'string',
|
|
2024
2270
|
required: true,
|
|
2025
|
-
|
|
2026
|
-
|
|
2271
|
+
description: '说的话。短一点,像人说话,不要写小作文',
|
|
2272
|
+
},
|
|
2273
|
+
mention: {
|
|
2274
|
+
type: 'string',
|
|
2275
|
+
description: '可选。叫醒谁:all = 叫醒所有醒着的鱼;写成员 id(多个用逗号或顿号隔开)只叫醒他们;不写 = 谁都不叫醒(消息仍然在群里,谁都翻得到)。正文里写 @ 名字只是字,不会叫醒任何人。',
|
|
2027
2276
|
},
|
|
2028
2277
|
channel: {
|
|
2029
2278
|
type: 'string',
|
|
2030
2279
|
enum: ['group', 'dm'],
|
|
2031
2280
|
description: 'group(默认)= 在群里说,三个人都看得见;dm = 私下只对 to 那一个人说,写进你俩那段对话的文件,不进群记录。',
|
|
2032
2281
|
},
|
|
2033
|
-
|
|
2034
|
-
type: 'string',
|
|
2035
|
-
required: true,
|
|
2036
|
-
description: '说的话。短一点,像人说话,不要写小作文',
|
|
2037
|
-
},
|
|
2038
|
-
seat: {
|
|
2282
|
+
to: {
|
|
2039
2283
|
type: 'string',
|
|
2040
|
-
|
|
2284
|
+
enum: ['all', ...Object.keys(MEMBERS)],
|
|
2285
|
+
description: '只有 channel=dm 时用:私下跟谁说(写成员 id)。群里说话不用它——消息照样全群可见,叫醒谁看 mention。',
|
|
2041
2286
|
},
|
|
2042
2287
|
image: {
|
|
2043
2288
|
type: 'string',
|
|
@@ -2055,34 +2300,33 @@ function apply(ctx) {
|
|
|
2055
2300
|
queued: { type: 'boolean' },
|
|
2056
2301
|
channel: { type: 'string' },
|
|
2057
2302
|
to: { type: 'string' },
|
|
2303
|
+
// from / mention 也要声明:宿主的 output schema 是 additionalProperties:false,
|
|
2304
|
+
// 2026-11-22 实机第一次调用就被它拒了("value.from is not a declared property")。
|
|
2305
|
+
from: { type: 'string' },
|
|
2306
|
+
// mention 在记录里是 'all' 或数组;输出里压成字符串(all / 逗号分隔 / 空串),
|
|
2307
|
+
// 因为宿主的 schema 子集没有 oneOf,声明数组就漏掉字符串那种形状。
|
|
2308
|
+
mention: { type: 'string' },
|
|
2058
2309
|
image: { type: 'string' },
|
|
2059
2310
|
},
|
|
2060
2311
|
},
|
|
2061
|
-
//
|
|
2062
|
-
// 2026-11-12 补:还要说清"**谁会收到通知**" —— `to` 是叫醒谁,不是谁看得见。
|
|
2063
|
-
// 小肥鱼 19:18 把一条该给大肥鱼的汇报发成了 to=all,所有人都被叫醒;
|
|
2064
|
-
// 机制没错,是纸面上没写清楚(她的环境.md 只写了"三个房间",没写 to 的这一层)。
|
|
2312
|
+
// 回执要说清两件事:这句话去了哪间屋、会叫醒谁(2026-11-22 r413 起只看 mention)。
|
|
2065
2313
|
render: (args, value) => {
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
for (const [key, m] of Object.entries(MEMBERS)) {
|
|
2069
|
-
if (key === value.from) continue
|
|
2070
|
-
const label = m?.label
|
|
2071
|
-
if (label && text.includes(`@${label}`)) mentioned.push(label)
|
|
2314
|
+
if (value.channel === 'dm') {
|
|
2315
|
+
return [{ type: 'text', text: `已写进私聊(${value.ts}):只有 ${labelOf(value.to)} 看得见,群里不会出现这句。` }]
|
|
2072
2316
|
}
|
|
2073
|
-
|
|
2074
|
-
const
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
const
|
|
2083
|
-
?
|
|
2317
|
+
// 记录里的 mention 是 'all' 或数组;这里压成字符串再返回(见 output.schema 的说明)。
|
|
2318
|
+
const m = typeof value.mention === 'string' ? value.mention : ''
|
|
2319
|
+
const wakes = m === 'all' ? '所有人' : m === '' ? '不叫醒任何人' : mentionTextOf(m.split(','), labelOf)
|
|
2320
|
+
const heads = m === 'all'
|
|
2321
|
+
? '群里的人都看得见,**醒着的都会被叫醒**'
|
|
2322
|
+
: m === ''
|
|
2323
|
+
? '群里的人都看得见,**不叫醒任何人**'
|
|
2324
|
+
: `群里的人都看得见,**只叫醒 ${wakes}**`
|
|
2325
|
+
const text = typeof args?.text === 'string' ? args.text : ''
|
|
2326
|
+
const quiet = m === '' && text.includes('@')
|
|
2327
|
+
? '\n\n提示:正文里的 @ 只是字,不会叫醒任何人;要叫醒谁就把 mention 写出来。'
|
|
2084
2328
|
: ''
|
|
2085
|
-
return [{ type: 'text', text:
|
|
2329
|
+
return [{ type: 'text', text: `已入群(${value.ts}):${heads}。${quiet}` }]
|
|
2086
2330
|
},
|
|
2087
2331
|
},
|
|
2088
2332
|
execute(args, exec) {
|
|
@@ -2107,30 +2351,12 @@ function apply(ctx) {
|
|
|
2107
2351
|
const channelProblem = channelProblemOf(args.channel)
|
|
2108
2352
|
if (channelProblem !== null) throw new Error(channelProblem)
|
|
2109
2353
|
const channel = args.channel === 'dm' ? 'dm' : 'group'
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
const toSeat = typeof args.seat === 'string' ? args.seat.trim().replace(/^@/, '') : ''
|
|
2117
|
-
if (toSeat !== '' && !/^[0-9a-f]{6}$/.test(toSeat)) {
|
|
2118
|
-
throw new Error('seat 要填会话 id 的前 6 位(例如 ae4daa),或者干脆不填——不填就是叫这个人。')
|
|
2119
|
-
}
|
|
2120
|
-
// 2026-11-12 栽过一次:seat 填成"自己这段"的前缀,收件人对不上任何座位,
|
|
2121
|
-
// 消息进了文件却谁也不会被叫醒(游标照常前进)——发的人以为送出去了。
|
|
2122
|
-
// 座位在发送时校验,别让它变成一个只在收件人那边才失败的地址。
|
|
2123
|
-
if (toSeat !== '' && args.to === 'all') {
|
|
2124
|
-
throw new Error('seat 是"指名某一段会话",不能和 to=all 一起用——要么点名,要么广播。')
|
|
2125
|
-
}
|
|
2126
|
-
if (toSeat !== '') {
|
|
2127
|
-
const liveSeats = pinnedSessions(args.to).map((id) => seatOfSession(id))
|
|
2128
|
-
if (!liveSeats.includes(toSeat)) {
|
|
2129
|
-
throw new Error(
|
|
2130
|
-
`seat 填错了:${toSeat} 不是 ${labelOf(args.to)} 名下的会话(名下现在是 ${
|
|
2131
|
-
liveSeats.length === 0 ? '一个都没登记' : liveSeats.join(' / ')
|
|
2132
|
-
})。不填 seat 就是"叫这个人,谁空谁应"。`,
|
|
2133
|
-
)
|
|
2354
|
+
// 2026-11-22 r413:群里说话不再有 to / seat —— 叫醒谁只看 mention。
|
|
2355
|
+
// to 只剩一个用途:dm 时指定私下跟谁说。
|
|
2356
|
+
if (channel === 'dm') {
|
|
2357
|
+
const peer = typeof args.to === 'string' ? args.to.trim() : ''
|
|
2358
|
+
if (peer === '' || peer === MENTION_ALL) {
|
|
2359
|
+
throw new Error('私下说话得指名对象:channel=dm 时 to 要写成员 id(不能是 all)。')
|
|
2134
2360
|
}
|
|
2135
2361
|
}
|
|
2136
2362
|
// 图片:工具参数给的是路径,落盘后消息里只留 id/ext/bytes/month。
|
|
@@ -2139,12 +2365,21 @@ function apply(ctx) {
|
|
|
2139
2365
|
image = storeImageFromPath(args.image)
|
|
2140
2366
|
logLine({ note: 'group_say-image', id: image.id, ext: image.ext, bytes: image.bytes })
|
|
2141
2367
|
}
|
|
2368
|
+
// mention(2026-11-22):叫醒谁。不写就交给 say() 推默认值。
|
|
2369
|
+
const mention = normalizeMention(args.mention, Object.keys(MEMBERS))
|
|
2142
2370
|
const record = say(
|
|
2143
|
-
member, args.to, args.text, channel,
|
|
2144
|
-
sid === null ? '' : sid.replace(/^session-/, '').slice(0, 6),
|
|
2371
|
+
member, channel === 'dm' ? String(args.to ?? '').trim() : '', args.text, channel,
|
|
2372
|
+
sid === null ? '' : sid.replace(/^session-/, '').slice(0, 6), '', image, null, mention,
|
|
2145
2373
|
)
|
|
2146
2374
|
// channel 让发言的人一眼知道这句话去了哪:group = 大家都看得见;dm = 只有对方看得见,且不会叫醒谁。
|
|
2147
|
-
|
|
2375
|
+
// mention/from 也要带出来:回执靠它说“会叫醒谁”,漏了会读成“(未写,按 to 推)”。
|
|
2376
|
+
return {
|
|
2377
|
+
ts: record.ts, queued: true, channel: record.channel,
|
|
2378
|
+
...(record.to === undefined ? {} : { to: record.to }),
|
|
2379
|
+
from: record.from,
|
|
2380
|
+
mention: record.mention === 'all' ? 'all' : (record.mention ?? []).join(','),
|
|
2381
|
+
image: image === null ? '' : `${image.id}.${image.ext}`,
|
|
2382
|
+
}
|
|
2148
2383
|
},
|
|
2149
2384
|
presentCall: (args) => ({
|
|
2150
2385
|
card: 'generic',
|
|
@@ -2396,7 +2631,7 @@ function apply(ctx) {
|
|
|
2396
2631
|
}
|
|
2397
2632
|
// 自动播报:称呼变了,别人得知道(他 2026-11-14 点头要的)。
|
|
2398
2633
|
try {
|
|
2399
|
-
say(member, 'all', renameAnnouncement(result.from, result.to), 'group')
|
|
2634
|
+
say(member, 'all', renameAnnouncement(result.from, result.to), 'group', '', '', null, null, 'all')
|
|
2400
2635
|
} catch (error) {
|
|
2401
2636
|
logLine({ note: 'rename-announce-failed', why: String(error?.message ?? error) })
|
|
2402
2637
|
}
|
|
@@ -2449,6 +2684,20 @@ function apply(ctx) {
|
|
|
2449
2684
|
instanceGuard.unregister()
|
|
2450
2685
|
})
|
|
2451
2686
|
|
|
2687
|
+
// 2.4 卡住要说话(fi-0016):投递后仍忙、会话文件却不再长,
|
|
2688
|
+
// 就在私聊里落一条「可能在等审批或等回答」的系统行。启发式,带「可能」。
|
|
2689
|
+
const stallTimer = setInterval(() => {
|
|
2690
|
+
if (!stillPrimary()) return
|
|
2691
|
+
try {
|
|
2692
|
+
checkOwnStall(ctx)
|
|
2693
|
+
} catch (error) {
|
|
2694
|
+
logLine({ note: 'stall-check-failed', error: String(error?.message ?? error).replace(/\s+/g, ' ').slice(0, 120) })
|
|
2695
|
+
}
|
|
2696
|
+
}, 60_000)
|
|
2697
|
+
stallTimer.unref?.()
|
|
2698
|
+
instanceGuard.addTimer(stallTimer)
|
|
2699
|
+
ctx.on('dispose', () => { clearInterval(stallTimer) })
|
|
2700
|
+
|
|
2452
2701
|
// 2.5 自己的闹钟:读自己家的 plan,自己递自己(2026-11-13 review 的建议 B)。
|
|
2453
2702
|
// 巡守不在也照样响;claim 文件保证和巡守那边不会各递一次。
|
|
2454
2703
|
if (!isMainProcess()) {
|
|
@@ -2696,7 +2945,7 @@ async function tick(ctx) {
|
|
|
2696
2945
|
if (agent.status !== 'idle') continue // 正在跑就先别插嘴,下个 tick 再说
|
|
2697
2946
|
|
|
2698
2947
|
// 记账按成员分开读:这段进程只管它自己那几个成员,别再攥着别人的旧快照
|
|
2699
|
-
const
|
|
2948
|
+
const cursorState = readCursorState(member)
|
|
2700
2949
|
const wakes = readWakes(member)
|
|
2701
2950
|
|
|
2702
2951
|
// 两条通道分别记账:群一条,私聊每一段对话一条。
|
|
@@ -2710,7 +2959,7 @@ async function tick(ctx) {
|
|
|
2710
2959
|
|
|
2711
2960
|
// 一次只唤醒一件事:这条通道叫醒了,别的下个 tick 再说。
|
|
2712
2961
|
for (const channel of channels) {
|
|
2713
|
-
const woke = handleChannel({ agent, member, seat: seatOfSession(sessionIdOf(agent)), channel,
|
|
2962
|
+
const woke = handleChannel({ agent, member, seat: seatOfSession(sessionIdOf(agent)), channel, cursorState, wakes })
|
|
2714
2963
|
if (woke) {
|
|
2715
2964
|
try {
|
|
2716
2965
|
const v = ctx.get('tools')?.view?.(agent)
|
|
@@ -2734,8 +2983,14 @@ const clampLogged = new Set()
|
|
|
2734
2983
|
// 不是"永远一次"** —— Set 不落盘,巡守重启后游标若还丢着,同一通道会再记一条;
|
|
2735
2984
|
// 连续证据看 wake-deliver.log 每行的 cursor-state=lost。
|
|
2736
2985
|
const cursorLostLogged = new Set()
|
|
2737
|
-
|
|
2738
|
-
|
|
2986
|
+
// 来源不明/回退/夹边界:同一成员同一通道每进程只记一行。
|
|
2987
|
+
const cursorSourceLogged = new Set()
|
|
2988
|
+
// 2026-11-23(r435,LeeaCP):主键与座位键"两支必须同形"——半份比空着更糟,看着像全的。
|
|
2989
|
+
// 同一条座位键只报一次,免得写游标这条热路径刷账。
|
|
2990
|
+
const cursorShapeLogged = new Set()
|
|
2991
|
+
|
|
2992
|
+
function handleChannel({ agent, member, seat, channel, cursorState, wakes }) {
|
|
2993
|
+
const cursors = cursorState?.cursors ?? {}
|
|
2739
2994
|
const lines = readLinesOf(channel.file)
|
|
2740
2995
|
if (lines.length === 0) return false
|
|
2741
2996
|
|
|
@@ -2748,9 +3003,40 @@ function handleChannel({ agent, member, seat, channel, cursors, wakes }) {
|
|
|
2748
3003
|
// 私信就是这么丢的:dm 游标停在第 14 行,而消息正好是第 14 行)。
|
|
2749
3004
|
// 判据:读的时候把游标夹到 lines.length 以内;真夹了要留痕 —— 错的时候跟对的时候不能长得一样。
|
|
2750
3005
|
const sharedSeenStored = cursorOf(cursors, member, channel.key)
|
|
3006
|
+
const keyPresent = Object.prototype.hasOwnProperty.call(cursors?.[member] ?? {}, channel.key)
|
|
2751
3007
|
const seatSeenStored = cursorOf(cursors, seatKey, channel.key)
|
|
2752
|
-
|
|
2753
|
-
|
|
3008
|
+
// 2026-11-23(fi-0013/0014/0015):起点不再由"0 或文件里那个数"直接决定。
|
|
3009
|
+
// file/legacy = 读到了,照常走;
|
|
3010
|
+
// missing/unknown = 没读到(不是 0),只看最近一小段,且不声称知道条数;
|
|
3011
|
+
// capped = 游标比文件还长,夹到文件尾(旧行为,留痕);
|
|
3012
|
+
// regressed = 比"上一次真递到的地方"还小 ⇒ 不重放,从那里接着走。
|
|
3013
|
+
const read = classifyCursorRead({
|
|
3014
|
+
source: cursorState?.source ?? 'file',
|
|
3015
|
+
stored: sharedSeenStored,
|
|
3016
|
+
lastDelivered: lastDeliveredOf(member, channel.key),
|
|
3017
|
+
lines: lines.length,
|
|
3018
|
+
present: keyPresent,
|
|
3019
|
+
})
|
|
3020
|
+
// 2026-11-24(fi-0019):起点不可信时,held 不数、不报、顺手清掉旧值。
|
|
3021
|
+
const heldTrusted = heldTrustedOf(read)
|
|
3022
|
+
const sharedSeen = Math.min(read.start, lines.length)
|
|
3023
|
+
// 读不到进度 / 回退时,座位游标也不可信:跟同一条起点走;正常时各算各的。
|
|
3024
|
+
let seatSeen = read.unknown || read.regressed ? sharedSeen : Math.min(seatSeenStored, lines.length)
|
|
3025
|
+
// 2026-11-23(r434,LeeaCP 验收):主游标读过、座位那一格却是 0,不该让扫描起点回到 0。
|
|
3026
|
+
// 座位是"老记录的影子":主游标都走过去了,从 0 扫只会把已读消息再数一遍(held 胀成 1782 的来源)。
|
|
3027
|
+
if (seatSeen === 0 && sharedSeen > 0) seatSeen = sharedSeen
|
|
3028
|
+
if (read.src !== 'file' && !cursorSourceLogged.has(`${member}:${channel.key}`)) {
|
|
3029
|
+
cursorSourceLogged.add(`${member}:${channel.key}`)
|
|
3030
|
+
logLine({
|
|
3031
|
+
note: 'cursor-source', member, channel: channel.key, src: read.src,
|
|
3032
|
+
stored: read.stored, start: read.start, lastDelivered: read.lastDelivered,
|
|
3033
|
+
capped: read.capped ? 'yes' : 'no', regressed: read.regressed ? 'yes' : 'no',
|
|
3034
|
+
counts: countsKnownOf(read) ? 'known' : 'unknown', lines: lines.length,
|
|
3035
|
+
})
|
|
3036
|
+
if (read.regressed) {
|
|
3037
|
+
logLine({ note: 'cursor-regress', member, channel: channel.key, stored: read.stored, lastDelivered: read.lastDelivered, start: read.start })
|
|
3038
|
+
}
|
|
3039
|
+
}
|
|
2754
3040
|
// 2026-11-15 20:3x:游标这一格是 0、但工程账上有过投递 —— 那不是新生,是丢了。
|
|
2755
3041
|
// 去重用的 Set 在模块层(上面),同一通道只记一次。
|
|
2756
3042
|
const clampKey = `${member}:${channel.key}`
|
|
@@ -2764,6 +3050,10 @@ function handleChannel({ agent, member, seat, channel, cursors, wakes }) {
|
|
|
2764
3050
|
// 记下"最后递出去的那条"在文件里的绝对行号(1 基)。小肥鱼 2026-11-12 的判据:
|
|
2765
3051
|
// 只有时间戳的话,两条隔 3 秒的重复仍然只能猜;有行号才能说"同一行递了两次"。
|
|
2766
3052
|
let lastIncomingIndex = -1
|
|
3053
|
+
// 这条通道里"没叫醒"的消息也要记一笔(2026-11-22):少叫醒,不等于悄悄丢消息。
|
|
3054
|
+
let heldDelta = 0
|
|
3055
|
+
let heldLastLine = -1
|
|
3056
|
+
let heldLastTs = null
|
|
2767
3057
|
for (let index = Math.min(sharedSeen, seatSeen); index < lines.length; index += 1) {
|
|
2768
3058
|
let record
|
|
2769
3059
|
try {
|
|
@@ -2791,7 +3081,17 @@ function handleChannel({ agent, member, seat, channel, cursors, wakes }) {
|
|
|
2791
3081
|
continue
|
|
2792
3082
|
}
|
|
2793
3083
|
if (channel.kind === 'group') {
|
|
2794
|
-
|
|
3084
|
+
// 2026-11-22:叫不叫醒看 mention,不看 to。to 只回答"这话对谁说"。
|
|
3085
|
+
// 老记录没有 mention 字段,wantsWake 按老规则读(to=all 叫醒所有人、to=某人叫他)。
|
|
3086
|
+
if (!wantsWake(record, member)) {
|
|
3087
|
+
// 2026-11-24(fi-0019):起点可信才数。游标丢了/回退时这一段里混着早已读过的消息。
|
|
3088
|
+
if (heldTrusted) {
|
|
3089
|
+
heldDelta += 1
|
|
3090
|
+
heldLastLine = index
|
|
3091
|
+
heldLastTs = record.ts ?? null
|
|
3092
|
+
}
|
|
3093
|
+
continue
|
|
3094
|
+
}
|
|
2795
3095
|
} else if (record.to !== member) {
|
|
2796
3096
|
continue
|
|
2797
3097
|
}
|
|
@@ -2801,11 +3101,15 @@ function handleChannel({ agent, member, seat, channel, cursors, wakes }) {
|
|
|
2801
3101
|
lastIncomingIndex = index
|
|
2802
3102
|
}
|
|
2803
3103
|
|
|
3104
|
+
// 读不到进度时,扫到的这一小段里大部分是旧的;当成"没叫醒的"去数,等于换个地方编数。
|
|
3105
|
+
if (heldDelta > 0 && heldTrusted) noteHeld(member, channel.key, heldDelta, heldLastLine + 1, heldLastTs)
|
|
3106
|
+
|
|
2804
3107
|
// 没有写给我的,也把游标推过去,免得下次重复扫
|
|
2805
3108
|
if (incoming.length === 0) {
|
|
2806
3109
|
setCursor(cursors, member, channel.key, lines.length)
|
|
2807
3110
|
setCursor(cursors, seatKey, channel.key, lines.length)
|
|
2808
3111
|
writeCursors(member, cursors)
|
|
3112
|
+
noteDelivered(member, channel.key, lines.length)
|
|
2809
3113
|
return false
|
|
2810
3114
|
}
|
|
2811
3115
|
|
|
@@ -2864,7 +3168,7 @@ function handleChannel({ agent, member, seat, channel, cursors, wakes }) {
|
|
|
2864
3168
|
// 判据用"递之前游标是不是 0":0 = 头一回读这个通道;否则 = 离开过一段时间再回来。
|
|
2865
3169
|
// 用词也别替她断言原因:窗关着、睡着、刚出生,在投递层看来是同一件事。
|
|
2866
3170
|
const firstRead = sharedSeenStored === 0
|
|
2867
|
-
const cursorLost = firstRead && hadPriorDelivery(member, channel.key)
|
|
3171
|
+
const cursorLost = !read.unknown && firstRead && hadPriorDelivery(member, channel.key)
|
|
2868
3172
|
if (cursorLost && !cursorLostLogged.has(`${member}:${channel.key}`)) {
|
|
2869
3173
|
cursorLostLogged.add(`${member}:${channel.key}`)
|
|
2870
3174
|
logLine({ note: 'cursor-lost', member, channel: channel.key, lines: lines.length })
|
|
@@ -2879,15 +3183,31 @@ function handleChannel({ agent, member, seat, channel, cursors, wakes }) {
|
|
|
2879
3183
|
firstRead,
|
|
2880
3184
|
cursorLost,
|
|
2881
3185
|
backlog,
|
|
3186
|
+
// 2026-11-22 r413:这一批是不是"点了你名字"才来的。老记录(无 mention)按老话说"新的"。
|
|
3187
|
+
woken: incoming.every((record) => record.mention !== undefined) ? 'mention' : 'legacy',
|
|
3188
|
+
// 2026-11-23(fi-0015):读不到进度时,文案不许报具体条数。
|
|
3189
|
+
src: read.src,
|
|
2882
3190
|
})
|
|
2883
3191
|
const target = channel.kind === 'dm' ? channel.file : READABLE
|
|
3192
|
+
// 没叫醒你的那些话,也要在预览里露一次头(2026-11-22)。
|
|
3193
|
+
// 2026-11-24(fi-0019):起点不可信时不报数(那是旧账重算),顺手清掉攒下来的旧值。
|
|
3194
|
+
let heldCount = channel.kind === 'group' && heldTrusted ? heldCountOf(member, channel.key) : 0
|
|
3195
|
+
if (channel.kind === 'group' && !heldTrusted) {
|
|
3196
|
+
const stale = heldCountOf(member, channel.key)
|
|
3197
|
+
if (stale > 0) {
|
|
3198
|
+
logLine({ note: 'held-untrusted', member, channel: channel.key, stored: stale, src: read.src })
|
|
3199
|
+
clearHeldOf(member, channel.key)
|
|
3200
|
+
}
|
|
3201
|
+
heldCount = 0
|
|
3202
|
+
}
|
|
3203
|
+
const heldSentence = heldSentenceOf(heldCount)
|
|
2884
3204
|
|
|
2885
3205
|
// 护栏:宿主构造器没解析到、或造出来的东西没有 id,就别往会话里塞。
|
|
2886
3206
|
// 宁可这一轮不叫醒(游标不动,下个 tick 再试),也不能写进去一条让整份日志打不开的事件。
|
|
2887
3207
|
const built = buildUserMessage({
|
|
2888
3208
|
content: [{
|
|
2889
3209
|
type: 'text',
|
|
2890
|
-
text: `${head}${where}。\n\n${preview}\n\n去 ${target} ${tailHint}回不回、说什么,你自己定。`,
|
|
3210
|
+
text: `${head}${where}。\n\n${heldSentence === '' ? '' : `${heldSentence}\n\n`}${preview}\n\n去 ${target} ${tailHint}回不回、说什么,你自己定。`,
|
|
2891
3211
|
}],
|
|
2892
3212
|
source: { kind: channel.kind === 'dm' ? 'dm' : 'group', form: 'signal' },
|
|
2893
3213
|
})
|
|
@@ -2905,7 +3225,13 @@ function handleChannel({ agent, member, seat, channel, cursors, wakes }) {
|
|
|
2905
3225
|
// `id` 是构造出来的 user message id,用来跟会话日志对账(见 wakeDeliverLog 的注释);
|
|
2906
3226
|
// `last-line` 是那条消息在通道文件里的绝对行号(1 基),`last-from` 是它谁写的。
|
|
2907
3227
|
// 有这两个字段,"同一条被递了两次"和"我们自己叫了两次"才分得开 —— 只看时间戳分不开。
|
|
2908
|
-
const
|
|
3228
|
+
const lastRecord = incoming[incoming.length - 1]
|
|
3229
|
+
const mentionTag = lastRecord?.mention === 'all'
|
|
3230
|
+
? 'all'
|
|
3231
|
+
: Array.isArray(lastRecord?.mention)
|
|
3232
|
+
? (lastRecord.mention.length === 0 ? 'none' : lastRecord.mention.join('+'))
|
|
3233
|
+
: 'legacy'
|
|
3234
|
+
const deliveryNote = `id=${built.id} member=${member} mention=${mentionTag} held-since-wake=${heldTrusted ? heldCount : "unknown"} channel=${channel.key} seat=${seat === '' ? '-' : seat} pending=${incoming.length} last-line=${lastIncomingIndex + 1} last-from=${incoming[incoming.length - 1]?.from ?? '-'} last-ts=${lastTs || 0} cursor=${lines.length} prior-cursor=${sharedSeenStored} cursor-state=${read.unknown ? "unknown" : cursorLost ? "lost" : firstRead ? "first" : "resumed"} src=${read.src} start=${cursorLost || read.unknown ? "unknown" : read.start} counts=${cursorLost || read.unknown ? "unknown" : "known"} tpl=${tpl} n=${incoming.length} tail=${tailTpl} wtext8=${wtext8} human=${humanIncoming ? 'yes' : 'no'} pkg=${PKG_VERSION}`
|
|
2909
3235
|
try {
|
|
2910
3236
|
agent.followup(built)
|
|
2911
3237
|
} catch (error) {
|
|
@@ -2914,16 +3240,22 @@ function handleChannel({ agent, member, seat, channel, cursors, wakes }) {
|
|
|
2914
3240
|
return false
|
|
2915
3241
|
}
|
|
2916
3242
|
wakeDeliverLog('delivered', deliveryNote)
|
|
3243
|
+
// 投递之后开始数「有没有新动静」(fi-0016):同一次投递只报一次。
|
|
3244
|
+
lastDeliveries.set(member, { at: Date.now(), ts: lastRecord?.ts ?? null })
|
|
3245
|
+
clearStallFile(member)
|
|
3246
|
+
// 这些没叫醒的话已经在预览里说过一次了;清掉,别让下一轮的"还有 N 条"重复计数。
|
|
3247
|
+
if (channel.kind === 'group') clearHeldOf(member, channel.key)
|
|
2917
3248
|
// 小肥鱼 #1627(2026-11-18):通道交付也是一次"被叫醒",但过去的 `woke` 行只记推门那几类,
|
|
2918
3249
|
// 于是"最频繁的群交付"在 watchman.log 里一次都看不见。不改旧行的意思,只把这一类也记进来:
|
|
2919
3250
|
// trigger=channel。此前的行没有它,只代表当时不记,不代表当时没有通道唤醒(append-only,补不回去)。
|
|
2920
|
-
watchmanLog('woke', `trigger=channel to=${member} channel=${channel.key} pending=${incoming.length} last-line=${lastIncomingIndex + 1} human=${humanIncoming ? 'yes' : 'no'}`)
|
|
3251
|
+
watchmanLog('woke', `trigger=channel to=${member} channel=${channel.key} pending=${incoming.length} last-line=${lastIncomingIndex + 1} human=${humanIncoming ? 'yes' : 'no'} src=${read.src} start=${cursorLost || read.unknown ? 'unknown' : read.start} counts=${cursorLost || read.unknown ? 'unknown' : 'known'} held-since-wake=${heldTrusted ? heldCount : 'unknown'}`)
|
|
2921
3252
|
markWakeMarker(member, channel.kind)
|
|
2922
3253
|
markWake(member, channel.kind)
|
|
2923
3254
|
|
|
2924
3255
|
setCursor(cursors, member, channel.key, lines.length)
|
|
2925
3256
|
setCursor(cursors, seatKey, channel.key, lines.length)
|
|
2926
3257
|
writeCursors(member, cursors)
|
|
3258
|
+
noteDelivered(member, channel.key, lines.length)
|
|
2927
3259
|
recordWake(wakes, member)
|
|
2928
3260
|
pending.delete(pendingKey)
|
|
2929
3261
|
console.log(`[${name}] 唤醒 ${labelOf(member)}(${seat}):${channel.key} ${incoming.length} 条`)
|
|
@@ -3022,31 +3354,39 @@ const planNotes = new Map()
|
|
|
3022
3354
|
// 原去重键是「日期 + 成员 + 文案」⇒ 一整天里同一个错只记一次,第二次静默。
|
|
3023
3355
|
// 改成 5 分钟窗口:窗口内重复只留一行 note-suppressed(count=1,之后同窗口不重复记),
|
|
3024
3356
|
// 窗口过去后再犯就正常记一行。这样“反复出同一个问题”至少会留两次痕迹。
|
|
3357
|
+
// r403(fi-0008)起:watchman.log 只留 `to=` / `code=` / `see=intent.log`,
|
|
3358
|
+
// 整句只写进她自己的 <家>\logs\intent.log——共享账不做第二本正文的副本。
|
|
3025
3359
|
const NOTE_DEDUPE_MS = 5 * 60_000
|
|
3026
3360
|
|
|
3027
|
-
function noteOnce(member, msg) {
|
|
3028
|
-
|
|
3361
|
+
function noteOnce(member, msg, by = '') {
|
|
3362
|
+
// fi-0011(r416):一行要能看出是哪个写者写的。默认取本进程自己的成员键——
|
|
3363
|
+
// 鱼的进程写 by=鱼键,巡守进程写 by=lee;两个写者各有各的 5 分钟窗口,别让读者把两行读成两次。
|
|
3364
|
+
const writer = by || ownMember()?.key || ''
|
|
3365
|
+
const key = `${todayKey(new Date())}|${writer}|${member.key}|${msg}`
|
|
3029
3366
|
const now = Date.now()
|
|
3030
3367
|
const prev = planNotes.get(key)
|
|
3368
|
+
const body = String(msg ?? '').replace(/\s+/g, ' ').trim()
|
|
3031
3369
|
if (prev && now - prev.at < NOTE_DEDUPE_MS) {
|
|
3032
3370
|
prev.suppressed += 1
|
|
3033
3371
|
// 2026-11-16 小鱼丸:「去重的记录不能再被去重。」
|
|
3034
3372
|
// 被压次数要能一直涨,但同一条 key 最多一分钟记一行(免得每拍都刷)。
|
|
3035
3373
|
if (now - (prev.lastSuppressedAt ?? 0) >= 60_000) {
|
|
3036
3374
|
prev.lastSuppressedAt = now
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3375
|
+
// 2026-11-20 09:06 分工(fi-0008,r403):共享账只留机器码与指路,正文只进她自己的账。
|
|
3376
|
+
// 另一条边界(小鱼丸 09:11):截断必须发生在拼串处,所以正文在这里保持完整、不 slice。
|
|
3377
|
+
watchmanLog('skip', watchmanSkipLineOf(member.key, { suppressed: prev.suppressed, by: writer }))
|
|
3378
|
+
memberNote(member, intentNoteTextOf(body, { suppressed: prev.suppressed }))
|
|
3040
3379
|
}
|
|
3041
3380
|
return
|
|
3042
3381
|
}
|
|
3043
3382
|
planNotes.set(key, { at: now, suppressed: 0, lastSuppressedAt: 0 })
|
|
3044
|
-
watchmanLog('skip',
|
|
3045
|
-
memberNote(member,
|
|
3383
|
+
watchmanLog('skip', watchmanSkipLineOf(member.key, { code: noteCodeOf(body), by: writer }))
|
|
3384
|
+
memberNote(member, body)
|
|
3046
3385
|
}
|
|
3047
3386
|
|
|
3048
|
-
/**
|
|
3049
|
-
* 2026-11-16 小鱼丸:"to=fishball 写在别人看不见的账里"等于静默。
|
|
3387
|
+
/** 条件表的问题写进**她自己的**日志:巡守的账她不一定知道去哪翻,正文也放这里。
|
|
3388
|
+
* 2026-11-16 小鱼丸:"to=fishball 写在别人看不见的账里"等于静默。
|
|
3389
|
+
* r403 起(fi-0008):这一本是**唯一**收正文的地方;共享账只有 code= 与 see=intent.log。 */
|
|
3050
3390
|
function memberNote(member, msg) {
|
|
3051
3391
|
try {
|
|
3052
3392
|
const dir = join(member.home, 'logs')
|
|
@@ -3057,7 +3397,7 @@ function memberNote(member, msg) {
|
|
|
3057
3397
|
}
|
|
3058
3398
|
}
|
|
3059
3399
|
|
|
3060
|
-
function planDue(member, st, now, graceMin = 1) {
|
|
3400
|
+
function planDue(member, st, now, graceMin = 1, by = '') {
|
|
3061
3401
|
return planDueCore({
|
|
3062
3402
|
member,
|
|
3063
3403
|
st,
|
|
@@ -3065,7 +3405,7 @@ function planDue(member, st, now, graceMin = 1) {
|
|
|
3065
3405
|
graceMin,
|
|
3066
3406
|
homeRoot: SELF_HOME,
|
|
3067
3407
|
maxItems: PLAN_MAX,
|
|
3068
|
-
onNote: (msg) => noteOnce(member, msg),
|
|
3408
|
+
onNote: (msg) => noteOnce(member, msg, by),
|
|
3069
3409
|
})
|
|
3070
3410
|
}
|
|
3071
3411
|
/** 闹钟递的那句话。开着的窗直接用;刚被推开的窗也递进去,等她起来自己读到。
|
|
@@ -3129,6 +3469,8 @@ function planDueMs(at) {
|
|
|
3129
3469
|
function selfPlanTick(ctx) {
|
|
3130
3470
|
if (isMainProcess()) return
|
|
3131
3471
|
const self = ownMember()
|
|
3472
|
+
// fi-0010(r404):这里曾取到没有 key 的名册值,日志写成 to=undefined。
|
|
3473
|
+
// 现在 buildMembers() 保证每个值都带 key,这里照旧取即可。
|
|
3132
3474
|
const member = MEMBERS[self]
|
|
3133
3475
|
if (!member || member.role === 'watcher') return
|
|
3134
3476
|
const now = new Date()
|
|
@@ -3143,7 +3485,7 @@ function selfPlanTick(ctx) {
|
|
|
3143
3485
|
}
|
|
3144
3486
|
let due = []
|
|
3145
3487
|
try {
|
|
3146
|
-
due = planDue(member, { planFired: {} }, now, SELF_PLAN_GRACE_MIN)
|
|
3488
|
+
due = planDue(member, { planFired: {} }, now, SELF_PLAN_GRACE_MIN, self)
|
|
3147
3489
|
} catch (error) {
|
|
3148
3490
|
watchmanLog('error', `note=self-plan-read-failed to=${self} detail=${String(error?.message ?? error).replace(/\s+/g, ' ').slice(0, 120)}`)
|
|
3149
3491
|
return
|
|
@@ -3161,7 +3503,7 @@ function selfPlanTick(ctx) {
|
|
|
3161
3503
|
if (privateResult) {
|
|
3162
3504
|
watchmanLog('deliver', `reason=self-plan-private to=${self} plan=${item.id}${privateResult === 'queued' ? ' queued=1' : ''}`)
|
|
3163
3505
|
} else {
|
|
3164
|
-
say(watcherKey(), self, planDeliveryPublicText(job))
|
|
3506
|
+
say(watcherKey(), self, planDeliveryPublicText(job), 'group', '', '', null, null, [self])
|
|
3165
3507
|
watchmanLog('deliver', `reason=self-plan-public-fallback to=${self} plan=${item.id}`)
|
|
3166
3508
|
}
|
|
3167
3509
|
// 与巡守触发的账同形状(wid / lag / inserted 都要有):
|
|
@@ -3406,7 +3748,7 @@ async function intentTick(member, st, now) {
|
|
|
3406
3748
|
`wid=${wid} kind=intent reason=intent:${spec.id} to=${member.key} gate=pass(hour=${counts.hour}/${WAKE.perHour},day=${counts.day}/${WAKE.perDay}) hb-age=${hbAge === null ? 'none' : `${hbAge}s`} deliver=msg at=${localStampOf(s.happenedAt ?? s.firstTrueAt)} atfmt=2`,
|
|
3407
3749
|
)
|
|
3408
3750
|
try {
|
|
3409
|
-
say(watcherKey(), member.key, intentDeliveryPublicText(spec, probe.evidence))
|
|
3751
|
+
say(watcherKey(), member.key, intentDeliveryPublicText(spec, probe.evidence), 'group', '', '', null, null, [member.key])
|
|
3410
3752
|
// lag = 发现比发生晚了多少(事情发生的时刻 → 递出去的时刻),不是"决定→插入"。
|
|
3411
3753
|
const happenedMs = Date.parse(String(s.happenedAt ?? s.firstTrueAt ?? ''))
|
|
3412
3754
|
const lagSec = Number.isFinite(happenedMs) ? Math.max(0, Math.round((now.getTime() - happenedMs) / 1000)) : null
|
|
@@ -3478,7 +3820,7 @@ async function watchOne(member, st) {
|
|
|
3478
3820
|
for (const t of dueTasks(member, now)) {
|
|
3479
3821
|
jobs.push({ key: t.id, tag: `task=${t.id} scheduled=${new Date(t.at).toISOString()}`, why: 'due-and-closed', from: 'schedule' })
|
|
3480
3822
|
}
|
|
3481
|
-
for (const p of planDue(member, st, new Date())) {
|
|
3823
|
+
for (const p of planDue(member, st, new Date(), 1, watcherKey())) {
|
|
3482
3824
|
jobs.push({ key: p.id, tag: `plan=${p.id} at=${p.at}`, why: 'plan', from: 'plan', itemWhy: p.why, at: p.at })
|
|
3483
3825
|
}
|
|
3484
3826
|
// 第三种触发源:她自己写下的条件(只由巡守探测)。放在 jobs 判空之前 ——
|
|
@@ -3548,7 +3890,7 @@ async function watchOne(member, st) {
|
|
|
3548
3890
|
// 2026-11-16:公共记录只留"到点了",理由不进记录(进她自己表)。
|
|
3549
3891
|
const text = planDeliveryPublicText(job)
|
|
3550
3892
|
try {
|
|
3551
|
-
say(watcherKey(), member.key, text)
|
|
3893
|
+
say(watcherKey(), member.key, text, 'group', '', '', null, null, [member.key])
|
|
3552
3894
|
watchmanLog(
|
|
3553
3895
|
'woke',
|
|
3554
3896
|
dueAt === null
|
|
@@ -3589,7 +3931,7 @@ async function watchOne(member, st) {
|
|
|
3589
3931
|
)
|
|
3590
3932
|
markWake(member.key, 'plan')
|
|
3591
3933
|
try {
|
|
3592
|
-
say(watcherKey(), member.key, planDeliveryPublicText(job))
|
|
3934
|
+
say(watcherKey(), member.key, planDeliveryPublicText(job), 'group', '', '', null, null, [member.key])
|
|
3593
3935
|
watchmanLog('deliver', `reason=plan-after-wake ${job.tag}(窗是推开的,话已递进去)`)
|
|
3594
3936
|
} catch (error) {
|
|
3595
3937
|
watchmanLog(
|
|
@@ -3636,7 +3978,7 @@ async function watchOne(member, st) {
|
|
|
3636
3978
|
// (selfPlanTick)会在宽限期内再递一次。声明一下,两边只留一条。
|
|
3637
3979
|
if (claimPlanDelivery(member, job.key)) {
|
|
3638
3980
|
try {
|
|
3639
|
-
say(watcherKey(), member.key, planDeliveryPublicText(job))
|
|
3981
|
+
say(watcherKey(), member.key, planDeliveryPublicText(job), 'group', '', '', null, null, [member.key])
|
|
3640
3982
|
watchmanLog('deliver', `reason=plan-after-wake ${job.tag}(窗是推开的,话已递进去)`)
|
|
3641
3983
|
} catch (error) {
|
|
3642
3984
|
watchmanLog('error', `note=plan-deliver-failed detail=${String(error?.message ?? error).replace(/\s+/g, ' ').slice(0, 120)} ${job.tag}`)
|
|
@@ -3797,7 +4139,7 @@ function auditRoster(now = new Date()) {
|
|
|
3797
4139
|
watchmanLog('error', `note=roster-mismatch ${problems.join(' ')}`)
|
|
3798
4140
|
// 只告诉人(fabian):名册外的鱼叫不动,能看见这件事的只有人。
|
|
3799
4141
|
try {
|
|
3800
|
-
say(watcherKey(), humanKey(), `巡守自检:名册和家对不上(${problems.join(';')}
|
|
4142
|
+
say(watcherKey(), humanKey(), `巡守自检:名册和家对不上(${problems.join(';')})。这条是巡守自己发现的,不是谁在说话。`, 'group', '', '', null, null, [humanKey()])
|
|
3801
4143
|
} catch { /* 递不出去也还有日志 */ }
|
|
3802
4144
|
}
|
|
3803
4145
|
|
|
@@ -3834,7 +4176,7 @@ async function crashNotify() {
|
|
|
3834
4176
|
continue
|
|
3835
4177
|
}
|
|
3836
4178
|
try {
|
|
3837
|
-
say(watcherKey(), humanKey(), `巡守:${labelOf(member.key)} 上次没正常退出(最后记录 ${at},没写 stopped
|
|
4179
|
+
say(watcherKey(), humanKey(), `巡守:${labelOf(member.key)} 上次没正常退出(最后记录 ${at},没写 stopped)。它现在起没起来,鱼塘里能看到。`, 'group', '', '', null, null, [humanKey()])
|
|
3838
4180
|
watchmanLog('note', `note=crash-notified member=${member.key} at=${at}`)
|
|
3839
4181
|
} catch (error) {
|
|
3840
4182
|
watchmanLog('error', `note=crash-notify-failed member=${member.key} detail=${String(error?.message ?? error).replace(/\s+/g, ' ').slice(0, 80)}`)
|