dsh-memu-memory 1.3.2 → 1.3.4
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/AGENTS.md +11 -3
- package/CHANGELOG.md +57 -3
- package/README.md +6 -11
- package/README.zh.md +6 -11
- package/assets/screenshots/drawer.jpg +0 -0
- package/assets/screenshots/mobile.jpg +0 -0
- package/assets/screenshots/relations.jpg +0 -0
- package/assets/screenshots/settings.jpg +0 -0
- package/assets/screenshots/stats.jpg +0 -0
- package/assets/screenshots/webui-dark.jpg +0 -0
- package/assets/screenshots/webui-memory.jpg +0 -0
- package/docs/client-conventions.md +21 -0
- package/docs/contributing.md +5 -2
- package/docs/memory-semantics.md +17 -0
- package/docs/troubleshooting.md +44 -0
- package/lib/binding-diagnostics.js +2 -2
- package/lib/client.js +125 -18
- package/lib/consolidation-snapshot.js +101 -5
- package/lib/consolidation-worker.js +1 -1
- package/lib/cycle.js +19 -1
- package/lib/index.js +83 -2
- package/lib/private.js +450 -165
- package/lib/rpc.js +14 -1
- package/lib/state.js +11 -1
- package/lib/turn-log.js +522 -0
- package/lib/webui/graph-view.bundle.js +1 -1
- package/lib/webui/graph-view.js +53 -25
- package/lib/webui/standalone.css +4 -29
- package/lib/worker-pool.js +741 -0
- package/package.json +1 -1
- package/scripts/acceptance-local.mjs +6 -5
- package/scripts/build-graph.mjs +32 -4
- package/scripts/check-all.mjs +2 -0
- package/scripts/check-idle-compositing.mjs +61 -0
- package/scripts/make-readme-shots.mjs +59 -0
- package/scripts/prune-turnlogs.mjs +30 -0
- package/tests/browser.test.mjs +27 -0
- package/tests/client-render.test.mjs +171 -0
- package/tests/consolidation-snapshot.test.mjs +89 -1
- package/tests/graph-view.test.mjs +60 -3
- package/tests/loader.mjs +2 -0
- package/tests/salience-domain.test.mjs +139 -0
- package/tests/settings-coverage.test.mjs +97 -0
- package/tests/stubs/dsh-session-query.js +26 -0
- package/tests/turn-log.test.mjs +474 -0
- package/tests/webui.test.mjs +19 -0
- package/tests/worker-lifecycle.test.mjs +1046 -0
- package/docs/recall-benchmark.md +0 -238
package/package.json
CHANGED
|
@@ -688,11 +688,12 @@ await auto('F-4', 'the activation log prints the settings the engine actually ra
|
|
|
688
688
|
assert.equal(Number(match[7]), settings.unpinBudgetPerSession)
|
|
689
689
|
assert.deepEqual(
|
|
690
690
|
handlers.filter((entry) => ['agent/pre-step', 'session/event'].includes(entry.event)).map((entry) => entry.event).sort(),
|
|
691
|
-
|
|
692
|
-
'
|
|
691
|
+
// 两个 session/event:注入管线一个 + 增量回合日志记录器一个(设计文档 §3.2,T0 起挂载)。
|
|
692
|
+
['agent/pre-step', 'session/event', 'session/event'],
|
|
693
|
+
'the same activation must wire the injection hooks and the turn-log recorder',
|
|
693
694
|
)
|
|
694
695
|
for (const dispose of disposers) { try { dispose() } catch {} }
|
|
695
|
-
return 'line matches live settings,
|
|
696
|
+
return 'line matches live settings, injection + turn-log hooks wired'
|
|
696
697
|
})
|
|
697
698
|
|
|
698
699
|
await auto('G-1', 'the kept docs exist and nothing points at a retired one', async () => {
|
|
@@ -717,8 +718,8 @@ await auto('G-1', 'the kept docs exist and nothing points at a retired one', asy
|
|
|
717
718
|
const ruleLead = (text) => text.split(String.fromCharCode(10)).filter((l) => /^[0-9]+[.] [*][*]/.test(l)).map((l) => { const end = l.indexOf('**', 5); return end < 0 ? l.slice(0, 40) : l.slice(0, end + 2) })
|
|
718
719
|
const inIndex = ruleLead(agents)
|
|
719
720
|
const inAppendix = ruleLead(appendix)
|
|
720
|
-
assert.
|
|
721
|
-
assert.equal(inAppendix.length, inIndex.length, 'the appendix carries the same
|
|
721
|
+
assert.ok(inIndex.length >= 10, 'the index carries at least ten hard rules, got ' + inIndex.length)
|
|
722
|
+
assert.equal(inAppendix.length, inIndex.length, 'the appendix carries the same hard rules')
|
|
722
723
|
for (const lead of inIndex) assert.ok(inAppendix.includes(lead), 'rule drifted between AGENTS.md and appendix E: ' + lead)
|
|
723
724
|
const pointers = agents.match(new RegExp('docs/[A-Za-z0-9._-]+[.]md', 'g')) || []
|
|
724
725
|
for (const rel of new Set(pointers)) {
|
package/scripts/build-graph.mjs
CHANGED
|
@@ -1,17 +1,45 @@
|
|
|
1
|
-
import { build } from 'esbuild'
|
|
2
1
|
import fs from 'node:fs'
|
|
3
2
|
import { fileURLToPath } from 'node:url'
|
|
4
3
|
|
|
5
4
|
// 引擎已改为自研力导向,bundle 里不再打包任何第三方运行时代码。
|
|
6
|
-
|
|
5
|
+
// esbuild 只在这里用,而且是 devDependency:静态 import 会让从 npm 装出来的插件
|
|
6
|
+
// 目录里的 `npm run check` 直接崩在模块解析,到不了下面的 skip 分支。
|
|
7
|
+
const target = fileURLToPath(new URL('../lib/webui/graph-view.bundle.js', import.meta.url))
|
|
8
|
+
const shared = {
|
|
7
9
|
entryPoints: [fileURLToPath(new URL('../lib/webui/graph-view.js', import.meta.url))],
|
|
8
|
-
outfile: fileURLToPath(new URL('../lib/webui/graph-view.bundle.js', import.meta.url)),
|
|
9
10
|
bundle: true,
|
|
10
11
|
format: 'iife',
|
|
11
12
|
globalName: 'DshMemuGraph',
|
|
12
13
|
target: ['es2020'],
|
|
13
14
|
minify: true,
|
|
14
15
|
banner: { js: '/* Generated by scripts/build-graph.mjs. Licenses: graph-LICENSE.txt */' },
|
|
15
|
-
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const esbuild = await (async () => {
|
|
19
|
+
try { return (await import('esbuild')).build } catch { return null }
|
|
20
|
+
})()
|
|
21
|
+
|
|
22
|
+
// `--check` 是防漂移闸门:改完引擎忘了重打包,浏览器加载的还是旧 bundle,
|
|
23
|
+
// 源码里的修复(比如最小缩放打架)在真实页面上根本不存在,测试却全绿。
|
|
24
|
+
if (process.argv.includes('--check')) {
|
|
25
|
+
if (!esbuild) {
|
|
26
|
+
console.log('skip graph bundle check: esbuild is not installed (production install has no devDependencies)')
|
|
27
|
+
process.exit(0)
|
|
28
|
+
}
|
|
29
|
+
// write:false:产物只在内存里比对,不在磁盘上留一份「看似 bundle」的副本。
|
|
30
|
+
const result = await esbuild({ ...shared, write: false })
|
|
31
|
+
const drifted = Buffer.from(result.outputFiles[0].text, 'utf8').equals(fs.readFileSync(target)) === false
|
|
32
|
+
if (drifted) {
|
|
33
|
+
console.error('lib/webui/graph-view.bundle.js does not match lib/webui/graph-view.js — run `npm run build:graph`')
|
|
34
|
+
process.exit(1)
|
|
35
|
+
}
|
|
36
|
+
process.exit(0)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!esbuild) {
|
|
40
|
+
console.error('esbuild is required to build the graph bundle: `npm ci` in the plugin directory first')
|
|
41
|
+
process.exit(1)
|
|
42
|
+
}
|
|
43
|
+
await esbuild({ ...shared, outfile: target })
|
|
16
44
|
fs.writeFileSync(new URL('../lib/webui/graph-LICENSE.txt', import.meta.url),
|
|
17
45
|
'graph-view.bundle.js: 本 bundle 无第三方运行时依赖(自研力导向引擎)。\n')
|
package/scripts/check-all.mjs
CHANGED
|
@@ -43,6 +43,8 @@ const budget = (rel, limit) => {
|
|
|
43
43
|
budget('AGENTS.md', 60000)
|
|
44
44
|
|
|
45
45
|
check('i18n', process.execPath, ['scripts/check-i18n.mjs'])
|
|
46
|
+
// 图谱引擎是唯一有产物的模块:浏览器加载的是 bundle,源码改了不重打包就等于没改。
|
|
47
|
+
check('graph bundle', process.execPath, ['scripts/build-graph.mjs', '--check'])
|
|
46
48
|
// npm silently de-duplicates `files` on pack, so a repeated entry only rots in
|
|
47
49
|
// source without any failing check. Pin the whitelist shape here instead.
|
|
48
50
|
check('package.json', process.execPath, ['-e', 'const p=JSON.parse(require("fs").readFileSync("package.json","utf8"));if(!Array.isArray(p.files)||new Set(p.files).size!==p.files.length)throw new Error("package.json: files must be an array with no duplicates")'])
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { chromium } from 'playwright'
|
|
4
|
+
|
|
5
|
+
// 空闲合成负载探针:WebUI 的 GPU 占用问题不是算力,是「空闲期仍在持续产帧」。
|
|
6
|
+
// 用 CDP screencast 数帧:页面没有视觉变化就不该有帧;无限 CSS 动画 / 常开 rAF /
|
|
7
|
+
// 全屏 backdrop-filter 都会让帧率钉在刷新率上。跑法:
|
|
8
|
+
// node --import ./tests/loader-register.mjs scripts/preview.mjs --port 7789
|
|
9
|
+
// node scripts/check-idle-compositing.mjs
|
|
10
|
+
// 只读本地预览(隔离示例数据),不写任何记忆库。
|
|
11
|
+
const base = process.argv[2] || 'http://127.0.0.1:7789/dsh-memu-memory/ui'
|
|
12
|
+
const seconds = Number(process.argv[3] || 6)
|
|
13
|
+
|
|
14
|
+
const chromeExe = ['chromium-1248/chrome-win64/chrome.exe', 'chromium-1194/chrome-win/chrome.exe', 'chromium-1117/chrome-win/chrome.exe']
|
|
15
|
+
.map(rel => path.join(process.env.LOCALAPPDATA || '', 'ms-playwright', rel))
|
|
16
|
+
.find(p => fs.existsSync(p))
|
|
17
|
+
if (!chromeExe) throw new Error('no chromium build under %LOCALAPPDATA%/ms-playwright — run `npx playwright install chromium`')
|
|
18
|
+
|
|
19
|
+
const browser = await chromium.launch({ headless: true, executablePath: chromeExe })
|
|
20
|
+
|
|
21
|
+
async function measure(label, setup) {
|
|
22
|
+
const context = await browser.newContext({ viewport: { width: 1440, height: 900 }, deviceScaleFactor: 1 })
|
|
23
|
+
const page = await context.newPage()
|
|
24
|
+
await page.goto(base + '#/settings/memories', { waitUntil: 'load' })
|
|
25
|
+
await page.waitForSelector('.dshm-wall-item', { timeout: 20000 })
|
|
26
|
+
await page.waitForTimeout(1500) // boot 遮罩 900ms 后移除,等它走完
|
|
27
|
+
if (setup) await setup(page)
|
|
28
|
+
await page.waitForTimeout(1200) // 让入场动画结束,只量「空闲」
|
|
29
|
+
const animations = await page.evaluate(() => document.getAnimations()
|
|
30
|
+
.filter(a => a.playState === 'running')
|
|
31
|
+
.map(a => ({ name: a.animationName || a.transitionProperty || a.constructor.name, target: String(a.effect?.target?.className || a.effect?.target?.tagName || '').slice(0, 40) })))
|
|
32
|
+
const cdp = await context.newCDPSession(page)
|
|
33
|
+
let frames = 0
|
|
34
|
+
cdp.on('Page.screencastFrame', async (event) => {
|
|
35
|
+
frames++
|
|
36
|
+
try { await cdp.send('Page.screencastFrameAck', { sessionId: event.sessionId }) } catch {}
|
|
37
|
+
})
|
|
38
|
+
await cdp.send('Page.startScreencast', { format: 'jpeg', quality: 20, everyNthFrame: 1 })
|
|
39
|
+
await page.waitForTimeout(seconds * 1000)
|
|
40
|
+
await cdp.send('Page.stopScreencast')
|
|
41
|
+
await context.close()
|
|
42
|
+
return { label, frames, fps: Number((frames / seconds).toFixed(1)), animations }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const results = []
|
|
46
|
+
results.push(await measure('wall idle', null))
|
|
47
|
+
results.push(await measure('drawer open', async (page) => { await page.click('.dshm-wall-item'); await page.waitForSelector('.dshm-drawer') }))
|
|
48
|
+
results.push(await measure('graph cooled', async (page) => {
|
|
49
|
+
await page.goto(base + '#/settings/graph', { waitUntil: 'load' })
|
|
50
|
+
await page.waitForSelector('canvas.dshm-graph-canvas', { timeout: 20000 })
|
|
51
|
+
await page.waitForTimeout(6000) // 等力导向冷下来
|
|
52
|
+
}))
|
|
53
|
+
await browser.close()
|
|
54
|
+
|
|
55
|
+
for (const r of results) {
|
|
56
|
+
console.log(`${r.label.padEnd(12)} frames=${String(r.frames).padStart(4)} fps=${String(r.fps).padStart(5)} running animations: ${r.animations.length ? JSON.stringify(r.animations) : 'none'}`)
|
|
57
|
+
}
|
|
58
|
+
const idle = results.filter(r => r.label !== 'graph cooled')
|
|
59
|
+
const bad = idle.some(r => r.fps > 2)
|
|
60
|
+
console.log(bad ? 'FAIL: 空闲期仍在持续产帧(合成器没睡)' : 'PASS: 空闲期合成器已睡')
|
|
61
|
+
process.exitCode = bad ? 1 : 0
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { chromium } from 'playwright'
|
|
4
|
+
import sharp from 'sharp'
|
|
5
|
+
|
|
6
|
+
// README 的七张图是**产物**:界面一改,它们就跟着过期(1.3.3 之前就漏了「关系图谱」这一页)。
|
|
7
|
+
// 跑法:先起预览,再跑本脚本。
|
|
8
|
+
// node --import ./tests/loader-register.mjs scripts/preview.mjs --port 7789
|
|
9
|
+
// node scripts/make-readme-shots.mjs
|
|
10
|
+
// 预览只在临时 DSH_MEMU_HOME 里造示例数据,不会碰任何真实记忆库。
|
|
11
|
+
const base = process.argv[2] || 'http://127.0.0.1:7789/dsh-memu-memory/ui'
|
|
12
|
+
const out = path.resolve(import.meta.dirname, '../assets/screenshots')
|
|
13
|
+
|
|
14
|
+
const shots = [
|
|
15
|
+
{ name: 'webui-memory', hash: '#/settings/memories', width: 1600, height: 1180, wait: '.dshm-wall-item' },
|
|
16
|
+
{ name: 'drawer', hash: '#/settings/memories', width: 1600, height: 1044, wait: '.dshm-wall-item', then: '.dshm-wall-item', opened: '.dshm-drawer' },
|
|
17
|
+
{ name: 'relations', hash: '#/settings/graph', width: 1440, height: 1293, wait: 'canvas', settle: 2600 },
|
|
18
|
+
{ name: 'settings', hash: '#/settings/settings', width: 1600, height: 1346, wait: '.dshm-card' },
|
|
19
|
+
{ name: 'stats', hash: '#/settings/stats', width: 1400, height: 1740, wait: '.dshm-card' },
|
|
20
|
+
{ name: 'webui-dark', hash: '#/settings/memories', width: 1600, height: 1044, wait: '.dshm-wall-item', dark: true },
|
|
21
|
+
{ name: 'mobile', hash: '#/settings/memories', width: 390, height: 844, wait: '.dshm-wall-item' },
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
// Playwright 想要 1248 号构建;机器上只有更早的构建时直接用那个可执行文件。
|
|
25
|
+
const chromeExe = ['chromium-1248/chrome-win64/chrome.exe', 'chromium-1194/chrome-win/chrome.exe', 'chromium-1117/chrome-win/chrome.exe']
|
|
26
|
+
.map(rel => path.join(process.env.LOCALAPPDATA || '', 'ms-playwright', rel))
|
|
27
|
+
.find(p => fs.existsSync(p))
|
|
28
|
+
if (!chromeExe) throw new Error('no chromium build under %LOCALAPPDATA%/ms-playwright — run `npx playwright install chromium`')
|
|
29
|
+
|
|
30
|
+
const browser = await chromium.launch({ headless: true, executablePath: chromeExe })
|
|
31
|
+
const written = []
|
|
32
|
+
try {
|
|
33
|
+
for (const shot of shots) {
|
|
34
|
+
// 每图一个新 context:主题、选中的库、滚动位置都存在 localStorage 里,
|
|
35
|
+
// 共用的话「深色」那张会把后面所有图都染黑。
|
|
36
|
+
const context = await browser.newContext({ viewport: { width: shot.width, height: shot.height }, deviceScaleFactor: 1 })
|
|
37
|
+
const page = await context.newPage()
|
|
38
|
+
const errors = []
|
|
39
|
+
page.on('pageerror', error => errors.push(String(error.message || error)))
|
|
40
|
+
await page.goto(base + shot.hash, { waitUntil: 'load' })
|
|
41
|
+
await page.waitForSelector('.dshm-root', { timeout: 20000 })
|
|
42
|
+
if (shot.wait) await page.waitForSelector(shot.wait, { timeout: 20000 })
|
|
43
|
+
if (shot.dark) await page.click('#theme')
|
|
44
|
+
if (shot.then) await page.click(shot.then)
|
|
45
|
+
if (shot.opened) await page.waitForSelector(shot.opened, { timeout: 10000 })
|
|
46
|
+
await page.waitForTimeout(shot.settle ?? 900)
|
|
47
|
+
if (errors.length) throw new Error(`${shot.name}: page errors ${errors.join(' | ')}`)
|
|
48
|
+
const png = await page.screenshot()
|
|
49
|
+
const image = await sharp(png).jpeg({ quality: 84, mozjpeg: true }).toBuffer()
|
|
50
|
+
const file = path.join(out, `${shot.name}.jpg`)
|
|
51
|
+
fs.writeFileSync(file, image)
|
|
52
|
+
const meta = await sharp(image).metadata()
|
|
53
|
+
written.push(`${shot.name}.jpg ${meta.width}x${meta.height} ${(image.length / 1024).toFixed(0)}KB`)
|
|
54
|
+
await context.close()
|
|
55
|
+
}
|
|
56
|
+
} finally {
|
|
57
|
+
await browser.close()
|
|
58
|
+
}
|
|
59
|
+
console.log(written.join('\n'))
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// 手动清理回合日志(设计文档 §3.4)。默认 dry-run:只列出将删的文件与理由;
|
|
3
|
+
// --apply 才真删;--days N 覆盖 30 天默认。与 prune-sessions / prune-vectors 同款纪律。
|
|
4
|
+
//
|
|
5
|
+
// 两个条件缺一不可(§3.4 休眠 GC 行):会话 ≥N 天无任何活动(lastTurnAt),且日志
|
|
6
|
+
// 无未结算增量(max seqEnd ≤ lastSleepSeq)——有未结算增量的日志是增量来源,删了
|
|
7
|
+
// 就得整段重建;没到 idle 期限的删了也是白删(复活成本一样)。
|
|
8
|
+
import { listSessionBindings } from '../lib/state.js'
|
|
9
|
+
import { gcTurnLogs, turnLogPath } from '../lib/turn-log.js'
|
|
10
|
+
|
|
11
|
+
const args = process.argv.slice(2)
|
|
12
|
+
const apply = args.includes('--apply')
|
|
13
|
+
const daysFlag = args.indexOf('--days')
|
|
14
|
+
const days = daysFlag >= 0 ? Number(args[daysFlag + 1]) : 30
|
|
15
|
+
// 0 used to mean "every log is old enough", which made this a wipe command with a
|
|
16
|
+
// harmless-looking flag. The log is a cache so deletion is recoverable, but the
|
|
17
|
+
// rebuild cost is real — refuse the footgun all the same.
|
|
18
|
+
if (!Number.isFinite(days) || days <= 0) {
|
|
19
|
+
console.error('prune-turnlogs: --days must be a positive number of days (0 is not "all")')
|
|
20
|
+
process.exit(2)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const result = gcTurnLogs(listSessionBindings(), { olderThanDays: days, dryRun: !apply })
|
|
24
|
+
for (const sessionId of result.deleted) {
|
|
25
|
+
console.log(`${apply ? 'deleted' : 'would delete'} ${turnLogPath(sessionId)}`)
|
|
26
|
+
}
|
|
27
|
+
for (const item of result.kept) {
|
|
28
|
+
console.log(`kept ${item.sessionId}: ${item.reason}`)
|
|
29
|
+
}
|
|
30
|
+
console.log(JSON.stringify({ dryRun: !apply, days, deleted: result.deleted, kept: result.kept }, null, 2))
|
package/tests/browser.test.mjs
CHANGED
|
@@ -314,6 +314,33 @@ test('the global curation picker hides archived and deleted conversations too',
|
|
|
314
314
|
assert.deepEqual(out.sessions.map((s) => s.id), ['global-visible'])
|
|
315
315
|
})
|
|
316
316
|
|
|
317
|
+
// 手动整理按钮按库找会话:listSessions 只多带一个只读 libraryId,
|
|
318
|
+
// 整理本身仍走会话维度的 generatePrivate(与侧边栏同一通道)。
|
|
319
|
+
test('listSessions reports the bound libraryId so a library can be consolidated', async () => {
|
|
320
|
+
const cwd = path.join(home, 'browser-lib-sessions')
|
|
321
|
+
const lib = createLibrary({ name: 'browser-lib-sessions', cwd })
|
|
322
|
+
setSessionBinding('sess-in-lib', { libraryId: lib.id })
|
|
323
|
+
setSessionBinding('sess-elsewhere', { libraryId: 'lib-other' })
|
|
324
|
+
const ctx = {
|
|
325
|
+
get(name) {
|
|
326
|
+
if (name !== 'sessionQuery') return null
|
|
327
|
+
return {
|
|
328
|
+
listSessions: async () => [
|
|
329
|
+
{ header: { id: 'sess-in-lib', cwd }, live: false, persisted: true },
|
|
330
|
+
{ header: { id: 'sess-elsewhere', cwd }, live: false, persisted: true },
|
|
331
|
+
{ header: { id: 'sess-unbound', cwd }, live: false, persisted: true },
|
|
332
|
+
],
|
|
333
|
+
readTitleSnapshots: async (ids) => ids.map((sessionId) => ({ sessionId, status: 'fulfilled', value: {} })),
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
}
|
|
337
|
+
const byId = Object.fromEntries((await dispatch(ctx, 'listSessions', { limit: 80 })).sessions
|
|
338
|
+
.map(row => [row.id, row.libraryId]))
|
|
339
|
+
assert.equal(byId['sess-in-lib'], lib.id, 'a bound conversation reports its library')
|
|
340
|
+
assert.equal(byId['sess-elsewhere'], 'lib-other', 'another library stays itself')
|
|
341
|
+
assert.equal(byId['sess-unbound'], null, 'an unbound conversation reports null, not undefined')
|
|
342
|
+
})
|
|
343
|
+
|
|
317
344
|
// ---- provenance in the browser, and the private review queue ----
|
|
318
345
|
|
|
319
346
|
test('the browser shows where a memory came from, and lets it be corrected', async () => {
|
|
@@ -230,6 +230,99 @@ test('the settings page renders every page instead of a blank panel', async () =
|
|
|
230
230
|
}
|
|
231
231
|
})
|
|
232
232
|
|
|
233
|
+
test('the immersive graph shell stays with the standalone WebUI', async () => {
|
|
234
|
+
// 点「关系图谱」把宿主页面的导航条掰成 158px 竖排,是 is-graph-wide 没分外壳造成的:
|
|
235
|
+
// 那套样式是为独立 WebUI 的全屏画布写的,宿主设置页只需要普通横排导航 + 一个入口按钮。
|
|
236
|
+
const ctx = fakeCtx()
|
|
237
|
+
globalThis.__dshMemuExports.apply(ctx)
|
|
238
|
+
const settings = registrations.filter((r) => r.slot === 'settings.section').pop()
|
|
239
|
+
assert.ok(settings?.component, 'settings.section was not registered')
|
|
240
|
+
const GRAPH_PAGE = 10
|
|
241
|
+
|
|
242
|
+
// The standalone shell resolves its page from the hash, so there is no
|
|
243
|
+
// numeric-zero page state to force on; the host shell has one.
|
|
244
|
+
const shell = async (props, { fromHash = false } = {}) => {
|
|
245
|
+
const first = await renderPage(settings.component, props, undefined, { remount: true })
|
|
246
|
+
if (!fromHash) collectPageHook()
|
|
247
|
+
for (const effect of first.effects) effect.fn()
|
|
248
|
+
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
249
|
+
return (await renderPage(settings.component, props, fromHash ? undefined : GRAPH_PAGE)).tree
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const inHost = await shell({ ctx, t: (key) => key })
|
|
253
|
+
assert.match(String(inHost.props?.className), /dshm-root/, 'the host graph page lost its shell')
|
|
254
|
+
assert.ok(!/is-graph-wide/.test(String(inHost.props?.className)),
|
|
255
|
+
`the host settings page must keep its horizontal rail, saw "${inHost.props?.className}"`)
|
|
256
|
+
const buttons = []
|
|
257
|
+
walkNodes(inHost, (node) => { if (node.type === 'button' && node.props?.children === 'openGraphStudio') buttons.push(node) })
|
|
258
|
+
assert.equal(buttons.length, 1, 'the host graph page should offer exactly one entry into the studio')
|
|
259
|
+
assert.equal(typeof buttons[0].props.onClick, 'function', 'the entry button has no handler')
|
|
260
|
+
|
|
261
|
+
const inWebUi = await withHash('#/settings/graph', () => shell({ ctx, t: (key) => key, standalone: true }, { fromHash: true }))
|
|
262
|
+
assert.match(String(inWebUi.props?.className), /is-graph-wide/, 'the standalone graph page lost its immersive shell')
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
test('the manual consolidation button rides the sidebar channel, not a new RPC', async () => {
|
|
266
|
+
// 「立即整理」刻意不新增方法:它查 listSessions 的库绑定,再对每个绑定会话调用
|
|
267
|
+
// 侧边栏同一个 generatePrivate。多一个只给 UI 用的整理方法,就等于多一条模型也能
|
|
268
|
+
// 调用的写路径。
|
|
269
|
+
const rpcCalls = []
|
|
270
|
+
const ctx = fakeCtx({
|
|
271
|
+
rpcCalls,
|
|
272
|
+
answers: {
|
|
273
|
+
getState: { ...RPC_ANSWERS.getState, libraries: [{ id: 'lib-1', name: 'L1', privateCount: 3, pinnedCount: 0, boundSessions: 2 }] },
|
|
274
|
+
getSettingsState: { ...RPC_ANSWERS.getSettingsState, libraries: [{ id: 'lib-1', name: 'L1', privateCount: 3, pinnedCount: 0, boundSessions: 2 }] },
|
|
275
|
+
listSessions: { sessions: [
|
|
276
|
+
{ id: 's1', libraryId: 'lib-1' }, { id: 's2', libraryId: 'lib-1' }, { id: 's3', libraryId: 'lib-2' },
|
|
277
|
+
] },
|
|
278
|
+
generatePrivate: { ok: true },
|
|
279
|
+
},
|
|
280
|
+
})
|
|
281
|
+
globalThis.__dshMemuExports.apply(ctx)
|
|
282
|
+
const settings = registrations.filter((r) => r.slot === 'settings.section').pop()
|
|
283
|
+
const props = { ctx, t: (key) => key }
|
|
284
|
+
const LIBRARIES_PAGE = 4
|
|
285
|
+
const render = async (page, remount = false) => renderPage(settings.component, props, page, { remount })
|
|
286
|
+
const first = await render(undefined, true)
|
|
287
|
+
collectPageHook()
|
|
288
|
+
for (const effect of first.effects) effect.fn()
|
|
289
|
+
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
290
|
+
const second = await render(LIBRARIES_PAGE)
|
|
291
|
+
for (const effect of second.effects) effect.fn()
|
|
292
|
+
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
293
|
+
const tree = (await render(LIBRARIES_PAGE)).tree
|
|
294
|
+
|
|
295
|
+
const buttons = []
|
|
296
|
+
walkNodes(tree, (node) => { if (node.type === 'button' && node.props?.children === 'consolidateNow') buttons.push(node) })
|
|
297
|
+
assert.equal(buttons.length, 1, 'the library row lost its 立即整理 button')
|
|
298
|
+
rpcCalls.length = 0
|
|
299
|
+
await buttons[0].props.onClick()
|
|
300
|
+
assert.deepEqual(rpcCalls, [], 'the first click must only arm the confirmation')
|
|
301
|
+
const armed = []
|
|
302
|
+
walkNodes((await render(LIBRARIES_PAGE)).tree, (node) => { if (node.type === 'button' && node.props?.children === 'confirmAction') armed.push(node) })
|
|
303
|
+
assert.equal(armed.length, 1, 'the arming state did not reach the button label')
|
|
304
|
+
await armed[0].props.onClick()
|
|
305
|
+
for (let i = 0; i < 4; i++) await new Promise((resolve) => setTimeout(resolve, 0))
|
|
306
|
+
assert.deepEqual(rpcCalls.map((c) => [c.endpoint, c.payload]), [
|
|
307
|
+
['listSessions', { limit: 200 }],
|
|
308
|
+
['generatePrivate', { sessionId: 's1' }],
|
|
309
|
+
['generatePrivate', { sessionId: 's2' }],
|
|
310
|
+
], 'consolidation must hit only the sessions bound to that library')
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
// The standalone shell reads `window.location.hash` to pick its page and rewrites
|
|
314
|
+
// it as the user navigates, which the host-side fixture never provides.
|
|
315
|
+
async function withHash(hash, run) {
|
|
316
|
+
const original = globalThis.window.location
|
|
317
|
+
const originalHistory = globalThis.window.history
|
|
318
|
+
globalThis.window.location = { ...original, hash }
|
|
319
|
+
globalThis.window.history = { ...originalHistory, replaceState: () => {} }
|
|
320
|
+
try { return await run() } finally {
|
|
321
|
+
globalThis.window.location = original
|
|
322
|
+
globalThis.window.history = originalHistory
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
233
326
|
test('the sidebar tab renders with the two-layer header', async () => {
|
|
234
327
|
const ctx = fakeCtx()
|
|
235
328
|
const tab = registrations.find((r) => r.slot === 'sidebar.right.pane.tab')
|
|
@@ -397,6 +490,84 @@ test('the memory browser badges what a memory is allowed to say', async () => {
|
|
|
397
490
|
}
|
|
398
491
|
})
|
|
399
492
|
|
|
493
|
+
test('the browse search box filters the loaded library in place', async () => {
|
|
494
|
+
// 搜索是纯前端的:它只过滤已经拉回来的那一页,不新发 RPC。库一切换就清空,
|
|
495
|
+
// 否则上一个库的关键词会把当前库筛成「空库」。
|
|
496
|
+
const originalGetState = RPC_ANSWERS.getState
|
|
497
|
+
const originalSettingsState = RPC_ANSWERS.getSettingsState
|
|
498
|
+
const loaded = { ...EMPTY_STATE, libraries: [{ id: 'lib-1', name: 'demo', scopeKey: '/proj/demo', privateCount: 2 }] }
|
|
499
|
+
RPC_ANSWERS.getState = loaded
|
|
500
|
+
RPC_ANSWERS.getSettingsState = loaded
|
|
501
|
+
RPC_ANSWERS.browseLibrary = {
|
|
502
|
+
source: 'engine',
|
|
503
|
+
files: [
|
|
504
|
+
{ id: 'mem-attic', title: 'the attic', content: 'he never told his brother', layer: 'long_term', status: 'active', decay: .5 },
|
|
505
|
+
{ id: 'mem-loud', title: 'shared fact', content: 'anything', layer: 'long_term', status: 'active', decay: .9 },
|
|
506
|
+
],
|
|
507
|
+
}
|
|
508
|
+
try {
|
|
509
|
+
const rpcCalls = []
|
|
510
|
+
const ctx = fakeCtx({ rpcCalls })
|
|
511
|
+
globalThis.__dshMemuExports.apply(ctx)
|
|
512
|
+
const settings = registrations.filter((r) => r.slot === 'settings.section').pop()
|
|
513
|
+
const props = { ctx, t: (key) => key }
|
|
514
|
+
const render = (page, remount = false) => renderPage(settings.component, props, page, { remount })
|
|
515
|
+
const first = await render(undefined, true)
|
|
516
|
+
collectPageHook()
|
|
517
|
+
for (const effect of first.effects) effect.fn()
|
|
518
|
+
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
519
|
+
let tree = (await render(5)).tree
|
|
520
|
+
const picker = []
|
|
521
|
+
walkNodes(tree, (node) => {
|
|
522
|
+
const options = Array.isArray(node.props?.children) ? node.props.children : []
|
|
523
|
+
if (node.type === 'select' && options.some((option) => option?.props?.value === 'lib-1')) picker.push(node)
|
|
524
|
+
})
|
|
525
|
+
picker[0].props.onChange({ target: { value: 'lib-1' } })
|
|
526
|
+
tree = (await render(5)).tree
|
|
527
|
+
const reload = []
|
|
528
|
+
walkNodes(tree, (node) => { if (node.type === 'button' && node.props?.children === 'reload') reload.push(node) })
|
|
529
|
+
reload[0].props.onClick()
|
|
530
|
+
for (let i = 0; i < 3; i++) await new Promise((resolve) => setTimeout(resolve, 0))
|
|
531
|
+
tree = (await render(5)).tree
|
|
532
|
+
|
|
533
|
+
// Rows carry their title in an editor input, so counting rendered values beats
|
|
534
|
+
// grepping the flattened tree.
|
|
535
|
+
const snapshot = (node) => {
|
|
536
|
+
const titles = []
|
|
537
|
+
let rows = 0
|
|
538
|
+
walkNodes(node, (n) => {
|
|
539
|
+
if (n.type === 'button' && n.props?.children === 'archive') rows++
|
|
540
|
+
if (n.type === 'input' && (n.props?.value === 'the attic' || n.props?.value === 'shared fact')) titles.push(n.props.value)
|
|
541
|
+
})
|
|
542
|
+
return { rows, titles }
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
const before = snapshot(tree)
|
|
546
|
+
assert.deepEqual(before, { rows: 2, titles: ['the attic', 'shared fact'] }, 'both rows render before filtering')
|
|
547
|
+
rpcCalls.length = 0
|
|
548
|
+
const box = []
|
|
549
|
+
walkNodes(tree, (node) => { if (node.type === 'input' && node.props?.placeholder === 'browseSearchPlaceholder') box.push(node) })
|
|
550
|
+
assert.equal(box.length, 1, 'no search box under 当前记忆库')
|
|
551
|
+
box[0].props.onChange({ target: { value: 'attic' } })
|
|
552
|
+
const filteredTree = (await render(5)).tree
|
|
553
|
+
assert.deepEqual(snapshot(filteredTree), { rows: 1, titles: ['the attic'] }, 'the filter keeps only the matching row')
|
|
554
|
+
assert.match(treeText(filteredTree), /1 \/ 2/, 'the counter says how much of the library the filter kept')
|
|
555
|
+
assert.match(treeText(filteredTree), /browseActiveTab \(1\)/, 'the tab counts follow the filter, not the whole library')
|
|
556
|
+
assert.deepEqual(rpcCalls, [], 'filtering an already loaded library must not re-fetch it')
|
|
557
|
+
box[0].props.onChange({ target: { value: 'no-such-memory' } })
|
|
558
|
+
assert.match(treeText((await render(5)).tree), /browseActiveTab \(0\)/, 'a query that matches nothing empties the tab counts')
|
|
559
|
+
const clear = []
|
|
560
|
+
walkNodes((await render(5)).tree, (node) => { if (node.type === 'button' && node.props?.children === 'browseSearchClear') clear.push(node) })
|
|
561
|
+
assert.equal(clear.length, 1, 'no way to clear the query')
|
|
562
|
+
clear[0].props.onClick()
|
|
563
|
+
assert.deepEqual(snapshot((await render(5)).tree), before, 'clearing the query brings the library back')
|
|
564
|
+
} finally {
|
|
565
|
+
RPC_ANSWERS.getState = originalGetState
|
|
566
|
+
RPC_ANSWERS.getSettingsState = originalSettingsState
|
|
567
|
+
delete RPC_ANSWERS.browseLibrary
|
|
568
|
+
}
|
|
569
|
+
})
|
|
570
|
+
|
|
400
571
|
test('the WebUI buttons open a new tab and never navigate this one', async () => {
|
|
401
572
|
const opened = []
|
|
402
573
|
const navigated = []
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import test from 'node:test'
|
|
2
2
|
import assert from 'node:assert/strict'
|
|
3
3
|
|
|
4
|
-
const { captureSessionSnapshot, safePrefix, toolPairing, lastClosedTurnSeq, snapshotHash } = await import('../lib/consolidation-snapshot.js')
|
|
4
|
+
const { captureSessionSnapshot, reconcilePersistedAhead, safePrefix, toolPairing, lastClosedTurnSeq, snapshotHash } = await import('../lib/consolidation-snapshot.js')
|
|
5
5
|
const { probeToolSurface, lastHeaderTools, buildWorkerBrief } = await import('../lib/consolidation-worker.js')
|
|
6
6
|
|
|
7
7
|
// C 包第 1、2 条:安全前缀必须可解释。这里逐条钉住「什么算完整」,
|
|
@@ -237,6 +237,94 @@ test('a failing observeSession is a retryable failure with the host message', as
|
|
|
237
237
|
assert.match(captured.error, /disk gone/)
|
|
238
238
|
})
|
|
239
239
|
|
|
240
|
+
// ---- 外部追加恢复:活视图落后于持久日志时改读冷日志(bench S1 冻结) ----
|
|
241
|
+
|
|
242
|
+
function coldAheadHost({ sessionId, liveEvents, coldEvents, coldHeader = null, liveHeader = null }) {
|
|
243
|
+
const rec = { coldReads: 0, disposed: 0 }
|
|
244
|
+
const ctx = {
|
|
245
|
+
rec,
|
|
246
|
+
on: () => () => {},
|
|
247
|
+
get: (name) => {
|
|
248
|
+
if (name === 'sessionQuery') {
|
|
249
|
+
return {
|
|
250
|
+
observeSession: async () => ({
|
|
251
|
+
source: 'live',
|
|
252
|
+
header: liveHeader || { id: sessionId, cwd: 'D:/proj', createdAt: 1 },
|
|
253
|
+
inheritedEventCount: 0,
|
|
254
|
+
events: liveEvents,
|
|
255
|
+
cursor: liveEvents.at(-1)?.seq ?? -1,
|
|
256
|
+
[Symbol.dispose]: () => { rec.disposed += 1 },
|
|
257
|
+
}),
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (name === 'sessionPersistence') return { open: async () => ({}) }
|
|
261
|
+
return undefined
|
|
262
|
+
},
|
|
263
|
+
}
|
|
264
|
+
const loadColdLogModule = async () => ({
|
|
265
|
+
readColdSessionLog: async () => {
|
|
266
|
+
rec.coldReads += 1
|
|
267
|
+
return {
|
|
268
|
+
header: coldHeader || { id: sessionId, cwd: 'D:/proj', createdAt: 1 },
|
|
269
|
+
inheritedEventCount: 0,
|
|
270
|
+
events: coldEvents,
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
assertSessionHeadersCompatible: (a, b) => {
|
|
274
|
+
if (a.id !== b.id || a.createdAt !== b.createdAt || a.cwd !== b.cwd) throw new Error('header conflict')
|
|
275
|
+
},
|
|
276
|
+
})
|
|
277
|
+
return { ctx, rec, loadColdLogModule }
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
test('a live observation behind the persisted log is replaced by the cold log', async () => {
|
|
281
|
+
const liveEvents = turn(1, 1) // seq 0-5
|
|
282
|
+
const coldEvents = [...turn(1, 1), ...closeTurn([], 2, 6)] // seq 0-10
|
|
283
|
+
const { ctx, rec, loadColdLogModule } = coldAheadHost({
|
|
284
|
+
sessionId: 'sess-ahead', liveEvents, coldEvents,
|
|
285
|
+
})
|
|
286
|
+
const captured = await captureSessionSnapshot(ctx, 'sess-ahead', { loadColdLogModule })
|
|
287
|
+
assert.equal(captured.ok, true)
|
|
288
|
+
assert.equal(captured.snapshot.source, 'persisted-ahead', 'the persisted log wins when it is ahead')
|
|
289
|
+
assert.equal(captured.snapshot.throughSeq, 10)
|
|
290
|
+
assert.equal(captured.snapshot.eventCount, coldEvents.length)
|
|
291
|
+
assert.equal(rec.coldReads, 1)
|
|
292
|
+
assert.equal(rec.disposed, 1, 'the original live lease is still released')
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
test('a live observation that is already the newest keeps the live cut', async () => {
|
|
296
|
+
const liveEvents = [...turn(1, 1), ...closeTurn([], 2, 6)]
|
|
297
|
+
const { ctx, rec, loadColdLogModule } = coldAheadHost({
|
|
298
|
+
sessionId: 'sess-live-wins', liveEvents, coldEvents: liveEvents,
|
|
299
|
+
})
|
|
300
|
+
const captured = await captureSessionSnapshot(ctx, 'sess-live-wins', { loadColdLogModule })
|
|
301
|
+
assert.equal(captured.ok, true)
|
|
302
|
+
assert.equal(captured.snapshot.source, 'lease-live')
|
|
303
|
+
assert.equal(captured.snapshot.throughSeq, 10)
|
|
304
|
+
assert.equal(rec.coldReads, 1, 'one probe is enough; the TTL cache skips the next few seconds')
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
test('a cold log with a conflicting header never replaces the live cut', async () => {
|
|
308
|
+
const liveEvents = turn(1, 1)
|
|
309
|
+
const coldEvents = [...turn(1, 1), ...closeTurn([], 2, 6)]
|
|
310
|
+
const { ctx, loadColdLogModule } = coldAheadHost({
|
|
311
|
+
sessionId: 'sess-conflict', liveEvents, coldEvents,
|
|
312
|
+
coldHeader: { id: 'sess-conflict', cwd: 'D:/elsewhere', createdAt: 1 },
|
|
313
|
+
})
|
|
314
|
+
const captured = await captureSessionSnapshot(ctx, 'sess-conflict', { loadColdLogModule })
|
|
315
|
+
assert.equal(captured.ok, true)
|
|
316
|
+
assert.equal(captured.snapshot.source, 'lease-live')
|
|
317
|
+
assert.equal(captured.snapshot.throughSeq, 5)
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
test('reconcilePersistedAhead degrades silently without persistence or the cold-read module', async () => {
|
|
321
|
+
assert.equal(await reconcilePersistedAhead({ persistence: null, sessionId: 'x', liveEvents: turn(1, 1) }), null)
|
|
322
|
+
assert.equal(await reconcilePersistedAhead({
|
|
323
|
+
persistence: { open: async () => ({}) }, sessionId: 'x', liveEvents: turn(1, 1),
|
|
324
|
+
loadModule: async () => { throw new Error('module missing') },
|
|
325
|
+
}), null)
|
|
326
|
+
})
|
|
327
|
+
|
|
240
328
|
// ---- 工具面:标准 / PTC / 未知 三种都要能分辨 ----
|
|
241
329
|
|
|
242
330
|
const MEMU_TOOLS = [
|