macro-memory 0.9.1 → 0.26.8
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 +157 -268
- package/bin/macro-memory.mjs +524 -5
- package/docs/CHANGELOG.md +1101 -0
- package/docs/MAC.md +44 -6
- package/lib/core/client.js +56 -22
- package/lib/core/config.js +15 -2
- package/lib/core/daemon.js +336 -0
- package/lib/core/engine.js +7 -6
- package/lib/core/fence.js +1 -1
- package/lib/core/serve.js +37 -14
- package/lib/core/trust.js +6 -2
- package/lib/index.js +209 -3
- package/lib/macro/contract.js +31 -1
- package/lib/macro/defs/admin.js +4 -4
- package/lib/macro/defs/link.js +96 -9
- package/lib/macro/defs/read.js +11 -1
- package/lib/macro/defs/remember.js +89 -1
- package/lib/macro/defs/search.js +157 -6
- package/lib/macro/dreamledger.js +6 -1
- package/lib/macro/evidence.js +84 -0
- package/lib/macro/fakesites.js +93 -0
- package/lib/macro/fusion.js +16 -2
- package/lib/macro/linkflow.js +130 -5
- package/lib/macro/links.js +69 -0
- package/lib/macro/platform.js +74 -0
- package/lib/macro/portability.js +737 -0
- package/lib/macro/prompt.js +6 -6
- package/lib/macro/revisions.js +3 -13
- package/lib/macro/slots.js +252 -0
- package/lib/macro/snapshot.js +309 -1
- package/lib/macro/tools.js +49 -4
- package/lib/macro/topicpages.js +300 -0
- package/lib/rerank/download.js +68 -0
- package/lib/rerank/provider.js +507 -0
- package/lib/rerank/runtime.js +246 -0
- package/lib/rerank/tokenizer.js +183 -0
- package/lib/semantic/download.js +68 -0
- package/lib/semantic/provider.js +205 -0
- package/lib/semantic/runtime.js +175 -0
- package/lib/semantic/tokenizer.js +169 -0
- package/package.json +1 -1
- package/vendor/VENDOR.json +4 -4
- package/vendor/dsh-memory-nebula/lib/host/adapters/meow.js +7 -1
- package/vendor/dsh-memory-nebula/lib/host/graph.js +183 -3
- package/vendor/dsh-memory-nebula/lib/index.js +75 -3
- package/vendor/dsh-memory-nebula/lib/web/app.js +5 -0
- package/vendor/dsh-memory-nebula/lib/web/i18n.js +1 -0
- package/vendor/meow-memory/lib/index.js +3205 -167
- package/vendor/meow-memory/lib/prompts/en/labels.md +2 -0
- package/vendor/meow-memory/lib/prompts/en/tools.md +1 -0
- package/vendor/meow-memory/lib/prompts/pt-br/labels.md +2 -0
- package/vendor/meow-memory/lib/prompts/pt-br/tools.md +1 -0
- package/vendor/meow-memory/lib/prompts/zh/labels.md +2 -0
- package/vendor/meow-memory/lib/prompts/zh/tools.md +1 -0
|
@@ -1224,6 +1224,20 @@ const DAY = 86400000
|
|
|
1224
1224
|
|
|
1225
1225
|
export const HYGIENE_META = {
|
|
1226
1226
|
dup: { label: '疑似重复', hint: '两条记忆几乎在说同一件事,留着会各写一半、互相打脸' },
|
|
1227
|
+
// [0.26.8] 与 dup 是两把尺子:dup 量「逐字相近」(稀有词签名 Jaccard ≥0.86),
|
|
1228
|
+
// 这一条量「一条的整段正文原样躺在另一条里」——同一件事写了三版、后两版只共享前一段时,
|
|
1229
|
+
// 逐字相似度常常只有三四成,dup 看不见,但读的人会连着读到三份。
|
|
1230
|
+
contain: {
|
|
1231
|
+
label: '同题旧账',
|
|
1232
|
+
hint: '一条的整段正文原样包含在另一条里(同层、较短一条 ≥60 字):0.26.7 起新写入会自动换代,这些是更早写下的旧账;同项目同版本的可以合并,跨项目或版本号不同的当初就是刻意分开的,别动',
|
|
1233
|
+
},
|
|
1234
|
+
// [macro-fusion 0.26.2] 跨工作区副本:同一个 uid 同时躺在两个工作区库里,内容逐字相同。
|
|
1235
|
+
// 它不是「两条记忆该合并」——它们是同一份被复制过去的(换过库位置、导入过、拷过目录)。
|
|
1236
|
+
// 照着「疑似重复」去归档任何一条,另一边那个工作区的检索就直接空了,而这边看起来「整理干净了」。
|
|
1237
|
+
mirror: {
|
|
1238
|
+
label: '跨工作区副本',
|
|
1239
|
+
hint: '同一个 id 在两个工作区库里各存一份、内容逐字相同:同一份记忆被复制过去,不是两条该合并的;先定「哪个工作区该留着它」,别在这边归档',
|
|
1240
|
+
},
|
|
1227
1241
|
oversize: { label: '超重', hint: '单条正文超过 4000 字,读它一次就吃掉一大截上下文' },
|
|
1228
1242
|
stale: { label: '该更新了', hint: '还挂着 active,但同一项目里有更新、更重要的记忆覆盖了它' },
|
|
1229
1243
|
unread: { label: '没人读过', hint: '写下一周以上、一次都没被检索命中过' },
|
|
@@ -1243,6 +1257,12 @@ export const HYGIENE_META = {
|
|
|
1243
1257
|
label: '写得多收得少',
|
|
1244
1258
|
hint: '近 30 天 fact 层条数增速是结论层(rules / lesson)的 3 倍以上:原子事实在堆,没人把它收成结论',
|
|
1245
1259
|
},
|
|
1260
|
+
// [0.22.3] 与 selfecho 互补:那条问「关键词是不是正文的复读」,这条问「关键词是不是全库的复读」。
|
|
1261
|
+
// 泛词不靠黑名单定(词表永远漏),按文档频率现算——词出现在 20% 以上条目里就不是特征词,是背景音。
|
|
1262
|
+
plainkw: {
|
|
1263
|
+
label: '关键词夹泛词',
|
|
1264
|
+
hint: 'keywords 里有词在 20% 以上的记忆里都出现(「用户」「项目」「问题」这类):它对这个库没有区分力,只占掉一个额度',
|
|
1265
|
+
},
|
|
1246
1266
|
}
|
|
1247
1267
|
|
|
1248
1268
|
const HY_MAX = 40
|
|
@@ -1505,6 +1525,110 @@ export function* auditHygieneSteps({ nodes, edges, nodeIds = null, tokensById =
|
|
|
1505
1525
|
}
|
|
1506
1526
|
mark('dup-count')
|
|
1507
1527
|
|
|
1528
|
+
// [0.26.8] 同题旧账:一条的整段正文原样躺在另一条里。
|
|
1529
|
+
// 为什么必须在面板上单列一类:0.26.7 让写侧的「旧版被新版整段包含」就地换代,但那只管新写入;
|
|
1530
|
+
// 更早的库没人回补,而这类账在「疑似重复」里是看不见的——dup 量的是稀有词签名 Jaccard(≥0.86),
|
|
1531
|
+
// 同一件事写成 178 / 491 / 1,116 字三版时,后两版只共享开头,签名相似度掉到三四成。
|
|
1532
|
+
// 真库实测(2,225 条 active):195 对、冗余 51,683 字,其中 192 对就是「新版以旧版开头」。
|
|
1533
|
+
//
|
|
1534
|
+
// 候选直接复用上面那张共享签名表:整段被包含必然共享大量稀有词,不必再 O(n²) 扫一遍。
|
|
1535
|
+
// 采样上限与 dup 同源(每个词最多进 60 条倒排);判据与写侧同源:同层、较短一条 ≥60 字。
|
|
1536
|
+
const CONTAIN_MIN = 60
|
|
1537
|
+
const stripOf = (s) => String(s || '').replace(/\s+/g, '')
|
|
1538
|
+
const containPairs = []
|
|
1539
|
+
const containSeen = new Set()
|
|
1540
|
+
for (const key of shared.keys()) {
|
|
1541
|
+
const ia = Math.floor(key / base)
|
|
1542
|
+
const ib = key - ia * base
|
|
1543
|
+
const na = memories[ia]
|
|
1544
|
+
const nb = memories[ib]
|
|
1545
|
+
if (!na || !nb || na.level !== nb.level) continue
|
|
1546
|
+
if (na.status !== 'active' || nb.status !== 'active') continue
|
|
1547
|
+
const ca = stripOf(na.content)
|
|
1548
|
+
const cb = stripOf(nb.content)
|
|
1549
|
+
if (ca.length < CONTAIN_MIN || cb.length < CONTAIN_MIN) continue
|
|
1550
|
+
const [s, l, ns, nl] = ca.length <= cb.length ? [ca, cb, na, nb] : [cb, ca, nb, na]
|
|
1551
|
+
if (!l.includes(s)) continue
|
|
1552
|
+
const pk = ns.id < nl.id ? `${ns.id}\u0000${nl.id}` : `${nl.id}\u0000${ns.id}`
|
|
1553
|
+
if (containSeen.has(pk)) continue
|
|
1554
|
+
containSeen.add(pk)
|
|
1555
|
+
containPairs.push({ s: ns, l: nl, short: s.length, long: l.length })
|
|
1556
|
+
if ((++slice & 1023) === 0) yield 'contain'
|
|
1557
|
+
}
|
|
1558
|
+
mark('contain')
|
|
1559
|
+
// 上面的签名候选有一个方向性盲点:同一件事的三版里,**更长的那版**签名会被后补的尾巴占满
|
|
1560
|
+
// (尾巴里的词在库里更稀有),于是一页都不与短版重叠——短版整段躺在它里面,候选却没生成。
|
|
1561
|
+
// 真库 195 对里有 192 对是「新版以旧版开头」,所以再按首 32 / 末 32 字建一张锚点表:
|
|
1562
|
+
// 首字锚抓「追加在后」,末字锚抓「补在前面」,两边都是 O(n) 建表 + 组内比对。
|
|
1563
|
+
// 中间插入的情形仍靠签名候选(尾巴没把签名占满时);两处都没命中的,等下次写入再换代也不迟。
|
|
1564
|
+
const anchors = new Map()
|
|
1565
|
+
const addAnchor = (k, i) => {
|
|
1566
|
+
let arr = anchors.get(k)
|
|
1567
|
+
if (!arr) anchors.set(k, (arr = []))
|
|
1568
|
+
if (arr.length < 60) arr.push(i)
|
|
1569
|
+
}
|
|
1570
|
+
for (let i = 0; i < memories.length; i++) {
|
|
1571
|
+
const n = memories[i]
|
|
1572
|
+
if (n.status !== 'active') continue
|
|
1573
|
+
const t = stripOf(n.content)
|
|
1574
|
+
if (t.length < CONTAIN_MIN) continue
|
|
1575
|
+
addAnchor(`h\u0000${t.slice(0, 32)}`, i)
|
|
1576
|
+
addAnchor(`t\u0000${t.slice(-32)}`, i)
|
|
1577
|
+
if ((++slice & 2047) === 0) yield 'contain'
|
|
1578
|
+
}
|
|
1579
|
+
for (const ids of anchors.values()) {
|
|
1580
|
+
for (let x = 0; x < ids.length; x++) {
|
|
1581
|
+
for (let y = x + 1; y < ids.length; y++) {
|
|
1582
|
+
const na = memories[ids[x]]
|
|
1583
|
+
const nb = memories[ids[y]]
|
|
1584
|
+
if (!na || !nb || na.level !== nb.level) continue
|
|
1585
|
+
if (na.status !== 'active' || nb.status !== 'active') continue
|
|
1586
|
+
const ca = stripOf(na.content)
|
|
1587
|
+
const cb = stripOf(nb.content)
|
|
1588
|
+
if (ca.length < CONTAIN_MIN || cb.length < CONTAIN_MIN) continue
|
|
1589
|
+
const [s, l, ns, nl] = ca.length <= cb.length ? [ca, cb, na, nb] : [cb, ca, nb, na]
|
|
1590
|
+
if (!l.includes(s)) continue
|
|
1591
|
+
const pk = ns.id < nl.id ? `${ns.id}\u0000${nl.id}` : `${nl.id}\u0000${ns.id}`
|
|
1592
|
+
if (containSeen.has(pk)) continue
|
|
1593
|
+
containSeen.add(pk)
|
|
1594
|
+
containPairs.push({ s: ns, l: nl, short: s.length, long: l.length })
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
if ((++slice & 511) === 0) yield 'contain'
|
|
1598
|
+
}
|
|
1599
|
+
mark('contain-anchor')
|
|
1600
|
+
// 处置方向按写侧的判据分三档:同项目同版本才是「可以合并」;跨项目 / 版本号不同当初就是
|
|
1601
|
+
// 刻意分开的(版本沿革各存一条是 0.19.0 的既定行为),照面板去合并等于合并两次不同的事。
|
|
1602
|
+
const semverOf = (t) => {
|
|
1603
|
+
const out = new Set()
|
|
1604
|
+
for (const m of String(t || '').matchAll(/\b\d+\.\d+\.\d+\b/g)) out.add(m[0])
|
|
1605
|
+
return out
|
|
1606
|
+
}
|
|
1607
|
+
const versionClash = (a, b) => {
|
|
1608
|
+
const va = semverOf(a)
|
|
1609
|
+
const vb = semverOf(b)
|
|
1610
|
+
if (!va.size || !vb.size) return false
|
|
1611
|
+
for (const v of va) if (!vb.has(v)) return true
|
|
1612
|
+
for (const v of vb) if (!va.has(v)) return true
|
|
1613
|
+
return false
|
|
1614
|
+
}
|
|
1615
|
+
for (const p of containPairs) {
|
|
1616
|
+
p.same = String(p.s.project || '') === String(p.l.project || '')
|
|
1617
|
+
p.clash = versionClash(p.s.content, p.l.content)
|
|
1618
|
+
}
|
|
1619
|
+
containPairs.sort((a, b) => b.short - a.short)
|
|
1620
|
+
const contain = containPairs.slice(0, HY_MAX).map((p) => ({
|
|
1621
|
+
id: p.s.id,
|
|
1622
|
+
label: p.s.label,
|
|
1623
|
+
ws: p.s.wsTitle,
|
|
1624
|
+
level: p.s.level,
|
|
1625
|
+
other: p.l.id,
|
|
1626
|
+
otherLabel: p.l.label,
|
|
1627
|
+
short: p.short,
|
|
1628
|
+
long: p.long,
|
|
1629
|
+
why: p.same && !p.clash ? 'mergeable' : p.same ? 'version' : 'project',
|
|
1630
|
+
}))
|
|
1631
|
+
|
|
1508
1632
|
const dupPairs = []
|
|
1509
1633
|
for (const key of exact) {
|
|
1510
1634
|
const ia = Math.floor(key / base)
|
|
@@ -1663,7 +1787,30 @@ export function* auditHygieneSteps({ nodes, edges, nodeIds = null, tokensById =
|
|
|
1663
1787
|
.slice(0, HY_MAX)
|
|
1664
1788
|
.map((n) => ({ id: n.id, label: n.label, ws: n.wsTitle, level: n.level, importance: n.importance || 0 }))
|
|
1665
1789
|
|
|
1666
|
-
|
|
1790
|
+
// [macro-fusion 0.26.2] 先按「是不是同一份被复制过去的」把重复对拆开:
|
|
1791
|
+
// uid + level 相同、只差 store(工作区库)→ 跨工作区副本,不是两条语义重复的记忆。
|
|
1792
|
+
// 判据只看节点自己带的字段(uid / level / storeId),不解析 id 字符串——id 的拼法
|
|
1793
|
+
// 是适配器的内部约定,解析字符串等于把两份代码绑死在一起。
|
|
1794
|
+
const mirrorPairs = []
|
|
1795
|
+
const dupOnly = []
|
|
1796
|
+
for (const p of dupPairs) {
|
|
1797
|
+
const na = byId.get(p.a)
|
|
1798
|
+
const nb = byId.get(p.b)
|
|
1799
|
+
const mirror = Boolean(
|
|
1800
|
+
na && nb
|
|
1801
|
+
&& typeof na.uid === 'string' && na.uid !== '' && na.uid === nb.uid
|
|
1802
|
+
&& na.level === nb.level
|
|
1803
|
+
&& na.storeId !== nb.storeId,
|
|
1804
|
+
)
|
|
1805
|
+
;(mirror ? mirrorPairs : dupOnly).push(mirror ? { ...p, mirror: true } : p)
|
|
1806
|
+
}
|
|
1807
|
+
mark('dup-split')
|
|
1808
|
+
const dup = dupOnly.slice(0, HY_MAX).map((p) => ({
|
|
1809
|
+
a: { id: p.a, label: byId.get(p.a)?.label || '', ws: byId.get(p.a)?.wsTitle || '' },
|
|
1810
|
+
b: { id: p.b, label: byId.get(p.b)?.label || '', ws: byId.get(p.b)?.wsTitle || '' },
|
|
1811
|
+
sim: Number(p.j.toFixed(3)),
|
|
1812
|
+
}))
|
|
1813
|
+
const mirror = mirrorPairs.slice(0, HY_MAX).map((p) => ({
|
|
1667
1814
|
a: { id: p.a, label: byId.get(p.a)?.label || '', ws: byId.get(p.a)?.wsTitle || '' },
|
|
1668
1815
|
b: { id: p.b, label: byId.get(p.b)?.label || '', ws: byId.get(p.b)?.wsTitle || '' },
|
|
1669
1816
|
sim: Number(p.j.toFixed(3)),
|
|
@@ -1693,6 +1840,36 @@ export function* auditHygieneSteps({ nodes, edges, nodeIds = null, tokensById =
|
|
|
1693
1840
|
const selfechoTotal = selfechoAll.length
|
|
1694
1841
|
const selfecho = selfechoAll.slice(0, HY_MAX)
|
|
1695
1842
|
|
|
1843
|
+
// 「关键词夹泛词」:一条记忆的关键词里,有几个词是「全库哪儿都在用」的。
|
|
1844
|
+
// 为什么现算而不查黑名单:黑名单永远漏(今天漏「这块」,明天漏「那边」)。文档频率是现成的,
|
|
1845
|
+
// 词只要出现在 ≤20% 的条目里才算对这个库有区分力;超过就已经是背景音,摆在 keywords 里
|
|
1846
|
+
// 不扩召回面,只占额度(8–13 个位子很贵)。
|
|
1847
|
+
// 与 selfecho 互补:selfecho 看「词是不是正文的复读机」,这一条看「词是不是全库的复读机」。
|
|
1848
|
+
const PLAIN_DF_RATE = 0.2
|
|
1849
|
+
const PLAIN_DF_MIN = 4
|
|
1850
|
+
const PLAIN_KW_MIN = 3
|
|
1851
|
+
const PLAIN_HIT_MIN = 3 // 至少 3 个泛词才报:只剩 2 个时还留着 2 个特征词,额度没被占满,报出来全是噪音
|
|
1852
|
+
const memN = memories.length
|
|
1853
|
+
const kwDF = new Map()
|
|
1854
|
+
for (const n of memories) for (const k of kwOf(n)) kwDF.set(k, (kwDF.get(k) || 0) + 1)
|
|
1855
|
+
const plainAll = []
|
|
1856
|
+
for (const n of memories) {
|
|
1857
|
+
const kws = kwOf(n)
|
|
1858
|
+
// 只有 1–2 个关键词的条目,一个词就占一半,比例不是信号。
|
|
1859
|
+
if (kws.length < PLAIN_KW_MIN) continue
|
|
1860
|
+
const plain = []
|
|
1861
|
+
for (const k of kws) {
|
|
1862
|
+
const df = kwDF.get(k) || 0
|
|
1863
|
+
if (df >= PLAIN_DF_MIN && df / memN >= PLAIN_DF_RATE) plain.push({ k, df, rate: Number((df / memN).toFixed(2)) })
|
|
1864
|
+
}
|
|
1865
|
+
if (plain.length < PLAIN_HIT_MIN) continue
|
|
1866
|
+
plain.sort((a, b) => b.df - a.df)
|
|
1867
|
+
plainAll.push({ id: n.id, label: n.label, ws: n.wsTitle, level: n.level, words: plain.slice(0, 4), n: plain.length, kws: kws.length })
|
|
1868
|
+
}
|
|
1869
|
+
plainAll.sort((a, b) => b.n / b.kws - a.n / a.kws || b.n - a.n)
|
|
1870
|
+
const plainkwTotal = plainAll.length
|
|
1871
|
+
const plainkw = plainAll.slice(0, HY_MAX)
|
|
1872
|
+
|
|
1696
1873
|
// 「召回过没人读」:命中过(排进过候选)却一次都没被 memory_read 打开。
|
|
1697
1874
|
// 只对真记了 read_count 的源成立(meow 从 0.4.0 起);别的适配器没这个数就不参与,
|
|
1698
1875
|
// 否则 hits 一有就全部假阳。老库这一格偏大是必然的——以前的读没被记过。
|
|
@@ -1733,10 +1910,12 @@ export function* auditHygieneSteps({ nodes, edges, nodeIds = null, tokensById =
|
|
|
1733
1910
|
]
|
|
1734
1911
|
: []
|
|
1735
1912
|
|
|
1736
|
-
const items = { dup, oversize, stale, unread, thin, orphan, selfecho, unused, inflate }
|
|
1913
|
+
const items = { dup, contain, mirror, oversize, stale, unread, thin, orphan, selfecho, unused, inflate, plainkw }
|
|
1737
1914
|
// 计数用「全部命中」,列表只留前 HY_MAX 条:payload 有上限,数字不失真。
|
|
1738
1915
|
const full = {
|
|
1739
|
-
dup:
|
|
1916
|
+
dup: dupOnly.length,
|
|
1917
|
+
contain: containPairs.length,
|
|
1918
|
+
mirror: mirrorPairs.length,
|
|
1740
1919
|
oversize: oversizeAll.length,
|
|
1741
1920
|
stale: staleTotal,
|
|
1742
1921
|
unread: unreadAll.length,
|
|
@@ -1745,6 +1924,7 @@ export function* auditHygieneSteps({ nodes, edges, nodeIds = null, tokensById =
|
|
|
1745
1924
|
selfecho: selfechoTotal,
|
|
1746
1925
|
unused: unusedTotal,
|
|
1747
1926
|
inflate: inflateTotal,
|
|
1927
|
+
plainkw: plainkwTotal,
|
|
1748
1928
|
}
|
|
1749
1929
|
const counts = {}
|
|
1750
1930
|
const shown = {}
|
|
@@ -324,6 +324,11 @@ export function apply(ctx) {
|
|
|
324
324
|
const a = String(args.a || '').trim()
|
|
325
325
|
const b = String(args.b || '').trim()
|
|
326
326
|
if (!a || !b) return '需要 a 和 b 两条记忆 id。'
|
|
327
|
+
// [macro-fusion 0.18.0 · W4-B] 引擎刚起来时 liveFacade 还没绑上实例:
|
|
328
|
+
// 这时候除了 refresh/ensure 之外读任何属性都是 undefined,直接调 nebula.link
|
|
329
|
+
// 会抛「nebula.link is not a function」——一句话把使用者引到「版本不对」的错方向上。
|
|
330
|
+
// 跟 nebula_recall/nebula_stats 一样,先等一轮建图再判断。
|
|
331
|
+
if (!nebula.graph || nebula.graph.nodes.length === 0) await nebula.refresh()
|
|
327
332
|
try {
|
|
328
333
|
if (action === 'link') {
|
|
329
334
|
const r = nebula.link(a, b, String(args.note || ''))
|
|
@@ -375,6 +380,9 @@ export function apply(ctx) {
|
|
|
375
380
|
const a = String(args.a || '').trim()
|
|
376
381
|
const b = String(args.b || '').trim()
|
|
377
382
|
if (!a || !b) return '需要 a 和 b 两个 id。'
|
|
383
|
+
// [macro-fusion 0.18.0 · W4-B] 同 nebula_link:先等建图,别让 facade 的空门面
|
|
384
|
+
// 被读成「 nebula.path is not a function」。
|
|
385
|
+
if (!nebula.graph || nebula.graph.nodes.length === 0) await nebula.refresh()
|
|
378
386
|
const pMh = numParam('maxHops', args.maxHops, { min: 1, max: 12, def: 6 })
|
|
379
387
|
const r = await nebula.path(a, b, { maxHops: pMh.value })
|
|
380
388
|
if (!r || !r.found) {
|
|
@@ -424,6 +432,14 @@ export function apply(ctx) {
|
|
|
424
432
|
// [macro-fusion 0.2.75] 上限只剩一个数(HUB_CAP):夹参数、正文尾注、这句描述都读它。
|
|
425
433
|
// 再写成字面量,就等于又把同一个上限抄了一遍——改一处漏两处。
|
|
426
434
|
hubs: { type: 'number', description: `列多少个枢纽,默认 10,上限 ${HUB_CAP};没列完的会在正文说清「这一段列了几条、够格参评的有几条」。` },
|
|
435
|
+
// [macro-memory 0.19.0 · W5 F14] 命中行要说清「凭什么在这儿」,其中一条是「这条记忆跟别的东西连着几条」。
|
|
436
|
+
// 一次问一批而不是一条一发:命中一屏 10 条,逐条 nebula_inspect 就是 10 次往返,
|
|
437
|
+
// 而这里要的只是一个整数。回执形状固定成 `- <id> · 连接 N`,宏层按行解析(与 graphNodesOf 同一套做法)。
|
|
438
|
+
ids: {
|
|
439
|
+
type: 'array',
|
|
440
|
+
items: { type: 'string' },
|
|
441
|
+
description: '只报这几条记忆的连接数(一次问一批,最多 40 条);给这个参数时不打印星图概况。',
|
|
442
|
+
},
|
|
427
443
|
},
|
|
428
444
|
required: [],
|
|
429
445
|
additionalProperties: false,
|
|
@@ -431,6 +447,32 @@ export function apply(ctx) {
|
|
|
431
447
|
output: out,
|
|
432
448
|
async execute(args = {}) {
|
|
433
449
|
if (!nebula.graph || nebula.graph.nodes.length === 0) await nebula.refresh()
|
|
450
|
+
// [macro-memory 0.19.0 · W5 F14] 点名的连接数走最早的分支:它要的是「这几条各连了几个」,
|
|
451
|
+
// 与「星图整体长什么样」无关,把概况一起印出来只会让解析器多认几行。
|
|
452
|
+
const askedIds = Array.isArray(args.ids) ? args.ids.map((x) => String(x ?? '').trim()).filter((x) => x !== '').slice(0, 40) : []
|
|
453
|
+
if (askedIds.length > 0) {
|
|
454
|
+
const lines = [`# 这批记忆的连接数(点名 ${askedIds.length} 条)`]
|
|
455
|
+
let known = 0
|
|
456
|
+
for (const id of askedIds) {
|
|
457
|
+
const d = nebula.detail(id)
|
|
458
|
+
if (!d) {
|
|
459
|
+
// 不在图里 ≠ 没有连接:可能是刚写还没入图(约 12s 一轮),也可能 id 不对。
|
|
460
|
+
// 这一行必须说清是「图里没有」,宏层据此不印证据数(把「没算」印成 0 是在编数字)。
|
|
461
|
+
lines.push(`- ${id} · 图里没有这条`)
|
|
462
|
+
continue
|
|
463
|
+
}
|
|
464
|
+
known += 1
|
|
465
|
+
const deg = Number(d.degree ?? (d.neighbors || []).length) || 0
|
|
466
|
+
lines.push(`- ${d.id || id} · 连接 ${deg}`)
|
|
467
|
+
}
|
|
468
|
+
if (known === 0) {
|
|
469
|
+
const total = nebula.graph?.nodes?.length ?? 0
|
|
470
|
+
lines.push('', total === 0 ? '星图现在还是空的(还没建完),这批连接数一条都没算——不是「它们都没有连接」。' : `图里现有 ${total} 条节点,但一个都没对上:id 给前 12 位就够。`)
|
|
471
|
+
} else {
|
|
472
|
+
lines.push('', '(连接数 = 星图里与这条记忆相连的条数;0 表示它现在还是孤立的,不等于它没用。)')
|
|
473
|
+
}
|
|
474
|
+
return lines.join('\n')
|
|
475
|
+
}
|
|
434
476
|
// [macro-fusion 0.2.71] hubs 先算完再取概览:以前 `slice(0, 12)` 写死,
|
|
435
477
|
// 给 20 也只出 12 条,且正文不说到没说完——「枢纽就这几个」是读者自己补的结论。
|
|
436
478
|
// [macro-fusion 0.2.75] 夹参数的一个数、正文里那句上限、schema 里那句上限原来各写一遍,
|
|
@@ -491,13 +533,13 @@ export function apply(ctx) {
|
|
|
491
533
|
ctx.tools.register({
|
|
492
534
|
name: 'nebula_hygiene',
|
|
493
535
|
description:
|
|
494
|
-
'
|
|
536
|
+
'记忆体检:把十一类失效模式查出来给你——疑似重复、同题旧账、该更新了、关系是凑的、超重、没人读过、孤立、关键词自证、召回过没人读、写得多收得少、关键词夹泛词。只诊断不改任何记忆;要不要合并、删掉、补连接由你或主人决定。',
|
|
495
537
|
parameters: {
|
|
496
538
|
type: 'object',
|
|
497
539
|
properties: {
|
|
498
540
|
kind: {
|
|
499
541
|
type: 'string',
|
|
500
|
-
enum: ['dup', 'stale', 'thin', 'oversize', 'unread', 'orphan'],
|
|
542
|
+
enum: ['dup', 'contain', 'stale', 'thin', 'oversize', 'unread', 'orphan', 'selfecho', 'unused', 'inflate', 'plainkw'],
|
|
501
543
|
description: '只看某一类;不传就返回全部概览。',
|
|
502
544
|
},
|
|
503
545
|
limit: { type: 'number', description: '每类最多列多少条,默认 6。' },
|
|
@@ -519,6 +561,8 @@ export function apply(ctx) {
|
|
|
519
561
|
const limit = pLim.value
|
|
520
562
|
const NAME = {
|
|
521
563
|
dup: '疑似重复',
|
|
564
|
+
contain: '同题旧账',
|
|
565
|
+
mirror: '跨工作区副本',
|
|
522
566
|
stale: '该更新了',
|
|
523
567
|
thin: '关系是凑的',
|
|
524
568
|
oversize: '超重',
|
|
@@ -546,7 +590,35 @@ export function apply(ctx) {
|
|
|
546
590
|
// 真正的「列了几条 / 还剩几条」由 listTail() 统一说。
|
|
547
591
|
const printed = Math.min(limit, arr.length)
|
|
548
592
|
lines.push('', `${labelOf(k)}(${n})`)
|
|
593
|
+
// [macro-fusion 0.26.2] 跨工作区副本不是「两条记忆」,处置方向也相反:
|
|
594
|
+
// 合并/归档是错的(另一边会空),要做的是定「哪个工作区该留着它」。
|
|
595
|
+
if (k === 'mirror' && n > 0) {
|
|
596
|
+
lines.push('(同一个 id 在两个工作区库里各存一份、内容逐字相同——是同一份被复制过去,不是两条该合并的记忆。别在这边归档:归档这边,另一边那个工作区的检索会直接空掉;要收就收重复的那一边。)')
|
|
597
|
+
}
|
|
598
|
+
// [0.26.8] 同题旧账:处置方向跟着 why 走,不能一律「合并」。
|
|
599
|
+
if (k === 'contain' && n > 0) {
|
|
600
|
+
lines.push('(一条的整段正文原样包含在另一条里。标「可合并」的是同项目同版本,按 id 合并;标「版本不同」「跨项目」的是当初就该各存一条的,别动——合并了两边都少一份。)')
|
|
601
|
+
}
|
|
549
602
|
for (const it of arr.slice(0, printed)) {
|
|
603
|
+
if (k === 'contain') {
|
|
604
|
+
const why = it.why === 'mergeable' ? '可合并' : it.why === 'version' ? '版本不同' : '跨项目'
|
|
605
|
+
lines.push(`- [${it.level || ''}] 短 ${String(it.short)} 字 ⊂ 长 ${String(it.long)} 字 · ${why}|${cut(it.label || '', 30)} → ${cut(it.otherLabel || '', 30)}`)
|
|
606
|
+
lines.push(` A: ${it.id}`)
|
|
607
|
+
lines.push(` B: ${it.other}`)
|
|
608
|
+
continue
|
|
609
|
+
}
|
|
610
|
+
if (k === 'plainkw' && Array.isArray(it.words)) {
|
|
611
|
+
const ws = it.words.map((w) => `${String(w.k)}(${String(Math.round(Number(w.rate) * 100))}%)`).join('、')
|
|
612
|
+
lines.push(`- [${it.level || ''}] ${cut(it.label || '', 40)} · ${ws}(${String(it.n)}/${String(it.kws)} 个词没区分力)`)
|
|
613
|
+
lines.push(` ${it.id}`)
|
|
614
|
+
continue
|
|
615
|
+
}
|
|
616
|
+
if (k === 'mirror' && it.a && it.b) {
|
|
617
|
+
lines.push(`- ${cut(it.a.label || '', 40)} · ${it.a.ws || ''} ⇄ ${it.b.ws || ''}(逐字重复度 ${it.sim})`)
|
|
618
|
+
lines.push(` A: ${it.a.id}`)
|
|
619
|
+
lines.push(` B: ${it.b.id}`)
|
|
620
|
+
continue
|
|
621
|
+
}
|
|
550
622
|
if (k === 'dup' && it.a && it.b) {
|
|
551
623
|
lines.push(`- ${cut(it.a.label || '', 40)} ⇄ ${cut(it.b.label || '', 40)}(相似 ${it.sim})`)
|
|
552
624
|
lines.push(` A: ${it.a.id}`)
|
|
@@ -560,7 +632,7 @@ export function apply(ctx) {
|
|
|
560
632
|
const tail = listTail(n, printed, limit)
|
|
561
633
|
if (tail) lines.push(tail)
|
|
562
634
|
}
|
|
563
|
-
lines.push('', '要动手就按 id
|
|
635
|
+
lines.push('', '要动手就按 id 来:合并走 memory_remember 带 supersedes=[旧 id] 写一条新的(旧条自动标 stale,正文留取代句);改写走 memory_update;这两条都动主人的记忆库,先问一声。星图这边只提供 nebula_link(action="mute") 断掉错误关联。')
|
|
564
636
|
if (pLim.note) lines.push('', pLim.note)
|
|
565
637
|
return lines.join('\n')
|
|
566
638
|
},
|
|
@@ -818,6 +818,10 @@
|
|
|
818
818
|
if (k === 'dup') {
|
|
819
819
|
text = (it.a.label || '').slice(0, 22) + ' ⇄ ' + (it.b.label || '').slice(0, 22) + ' · ' + it.sim
|
|
820
820
|
jump = it.a.id
|
|
821
|
+
} else if (k === 'mirror') {
|
|
822
|
+
// 跨工作区副本:重点是「哪两个工作区各有一份」,标题只是方便认人。
|
|
823
|
+
text = (it.a.ws || '') + ' ⇄ ' + (it.b.ws || '') + ' · ' + (it.a.label || '').slice(0, 18)
|
|
824
|
+
jump = it.a.id
|
|
821
825
|
} else if (k === 'stale') {
|
|
822
826
|
text = (it.label || '').slice(0, 26) + ' · ' + it.days + T(' 天')
|
|
823
827
|
jump = it.id
|
|
@@ -882,6 +886,7 @@
|
|
|
882
886
|
|
|
883
887
|
const HY_NAME = {
|
|
884
888
|
dup: T('疑似重复'),
|
|
889
|
+
mirror: T('跨工作区副本'),
|
|
885
890
|
oversize: T('太长'),
|
|
886
891
|
stale: T('该更新'),
|
|
887
892
|
unread: T('没人读'),
|