dsh-memu-memory 1.4.3 → 1.4.5
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 +3 -1
- package/CHANGELOG.md +15 -0
- package/README.md +34 -15
- package/README.zh.md +35 -13
- package/assets/screenshots/drawer.jpg +0 -0
- package/assets/screenshots/libraries.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/webui-dark.jpg +0 -0
- package/assets/screenshots/webui-memory.jpg +0 -0
- package/docs/client-conventions.md +19 -3
- package/docs/contributing.md +4 -2
- package/docs/env-and-commands.md +9 -1
- package/docs/graph-scale.md +214 -0
- package/docs/lexicon-recall.md +100 -0
- package/docs/mcp-porting.md +8 -6
- package/docs/memory-semantics.md +35 -3
- package/docs/pending-work.md +3 -1
- package/docs/retention.md +83 -0
- package/docs/rt-index.md +452 -0
- package/docs/scale-performance.md +101 -0
- package/docs/token-budget.md +92 -0
- package/docs/troubleshooting.md +50 -11
- package/lib/auto-link/apply.js +7 -2
- package/lib/auto-link/candidates.js +32 -10
- package/lib/backup.js +67 -32
- package/lib/binding-diagnostics.js +1 -1
- package/lib/bounded-cache.js +80 -0
- package/lib/client.js +2096 -409
- package/lib/consolidation-ledger.js +21 -4
- package/lib/consolidation-worker.js +14 -1
- package/lib/cycle.js +16 -11
- package/lib/diagnostic-context.js +372 -0
- package/lib/diagnostics.js +147 -61
- package/lib/embedding-download.js +7 -8
- package/lib/engine-sources.js +286 -0
- package/lib/engine.js +23 -10
- package/lib/entity-repair.js +43 -13
- package/lib/entity-review.js +64 -0
- package/lib/environment-check.js +348 -36
- package/lib/feedback.js +25 -0
- package/lib/global-graph.js +46 -2
- package/lib/graph-adjacency-index.js +525 -0
- package/lib/graph-overview.js +293 -0
- package/lib/graph.js +658 -105
- package/lib/inbound.js +44 -15
- package/lib/index-pages.js +57 -0
- package/lib/index.js +44 -6
- package/lib/inject.js +119 -50
- package/lib/lexicon-rt-source.js +25 -0
- package/lib/lexicon-rt-worker.js +26 -0
- package/lib/lexicon-rt.js +224 -0
- package/lib/lexicon-scope.js +56 -5
- package/lib/lexicon.js +143 -54
- package/lib/local-vector-service.js +3 -0
- package/lib/maintenance-ledger.js +542 -12
- package/lib/managed-runtime.js +260 -80
- package/lib/media.js +1 -1
- package/lib/memory.js +564 -131
- package/lib/port-surface.js +96 -11
- package/lib/preset-mount.js +13 -7
- package/lib/private.js +47 -21
- package/lib/recall-cache.js +20 -34
- package/lib/retention.js +173 -0
- package/lib/rpc.js +135 -52
- package/lib/rt-index/builder.js +209 -0
- package/lib/rt-index/format.js +231 -0
- package/lib/rt-index/manifest.js +105 -0
- package/lib/rt-index/reader.js +673 -0
- package/lib/rt-index-retention.js +151 -0
- package/lib/rt-index-service.js +283 -0
- package/lib/rt-index-worker.js +21 -0
- package/lib/salient-wake.js +55 -4
- package/lib/state.js +195 -24
- package/lib/temporal.js +39 -13
- package/lib/token-measurement.js +126 -0
- package/lib/tools.js +101 -6
- package/lib/turn-log.js +108 -3
- package/lib/webui/graph-layout-worker.js +68 -0
- package/lib/webui/graph-local-physics.js +390 -0
- package/lib/webui/graph-spatial-grid.js +64 -0
- package/lib/webui/graph-view.bundle.js +6 -1
- package/lib/webui/graph-view.js +478 -135
- package/lib/webui/graph-webgl-renderer.js +74 -0
- package/lib/webui/standalone.js +1 -1
- package/lib/worker-pool.js +38 -7
- package/package.json +3 -2
- package/scripts/acceptance-local.mjs +4 -10
- package/scripts/bench-all-libraries.mjs +47 -0
- package/scripts/check-classic-graph-browser.mjs +189 -0
- package/scripts/check-client-browser.mjs +929 -0
- package/scripts/check-graph-browser.mjs +6 -0
- package/scripts/check-graph-elastic-browser.mjs +139 -0
- package/scripts/check-memory-review-browser.mjs +124 -0
- package/scripts/entity-dedupe.mjs +19 -3
- package/scripts/graph-artifact-provenance.mjs +30 -0
- package/scripts/graph-freeze-manifest.mjs +129 -0
- package/scripts/graph-geometry-fixture.mjs +40 -0
- package/scripts/graph-physics-bench.mjs +218 -0
- package/scripts/graph-scale-bench.mjs +213 -0
- package/scripts/graph-scale-memory.mjs +48 -0
- package/scripts/graph-service-bench.mjs +72 -0
- package/scripts/make-readme-shots.mjs +17 -5
- package/scripts/preview.mjs +1 -0
- package/scripts/rebuild-rt.mjs +18 -0
- package/scripts/scale-bench.mjs +183 -0
- package/scripts/simulate-injection.mjs +47 -8
- package/scripts/verify-host-fixtures.mjs +108 -0
- package/scripts/verify-host-recovery.mjs +565 -0
- package/scripts/verify-vector-recovery.mjs +740 -0
- package/tests/auto-link-candidates.test.mjs +20 -0
- package/tests/browser.test.mjs +16 -2
- package/tests/client-export.test.mjs +16 -1
- package/tests/client-pagination.test.mjs +1495 -0
- package/tests/client-render.test.mjs +223 -28
- package/tests/consolidation-fork.test.mjs +97 -13
- package/tests/consolidation-ledger.test.mjs +17 -1
- package/tests/diagnostic-entity-candidates.test.mjs +54 -0
- package/tests/diagnostic-report.test.mjs +429 -0
- package/tests/diagnostic-wiring.test.mjs +88 -0
- package/tests/diagnostics.test.mjs +27 -0
- package/tests/embedding-download.test.mjs +44 -0
- package/tests/engine-source-settings.test.mjs +69 -0
- package/tests/engine-sources.test.mjs +145 -0
- package/tests/entity-dedupe.test.mjs +143 -0
- package/tests/entity-merge-review.test.mjs +363 -0
- package/tests/entity-merge.test.mjs +12 -4
- package/tests/entity-review.test.mjs +87 -0
- package/tests/environment-check.test.mjs +51 -1
- package/tests/feedback.test.mjs +95 -0
- package/tests/graph-adjacency-index.test.mjs +536 -0
- package/tests/graph-cascade.test.mjs +229 -0
- package/tests/graph-import-diagnostic.test.mjs +25 -0
- package/tests/graph-overview.test.mjs +709 -0
- package/tests/graph-session-authorization.test.mjs +419 -0
- package/tests/graph-view-geometry.test.mjs +426 -0
- package/tests/graph-view-scale.test.mjs +88 -0
- package/tests/graph-view.test.mjs +444 -5
- package/tests/graph.test.mjs +43 -0
- package/tests/help-page.test.mjs +128 -54
- package/tests/inbound.test.mjs +19 -0
- package/tests/index-pagination.test.mjs +113 -0
- package/tests/index-read-view.test.mjs +212 -0
- package/tests/inject-guide.test.mjs +9 -0
- package/tests/injection-dedupe.test.mjs +213 -0
- package/tests/lexicon-recall.test.mjs +641 -0
- package/tests/lexicon-rt-lifecycle.test.mjs +196 -0
- package/tests/lexicon-rt.test.mjs +468 -0
- package/tests/local-embedding-worker.test.mjs +38 -0
- package/tests/local-vector-service.test.mjs +32 -3
- package/tests/maintenance-compat.test.mjs +128 -0
- package/tests/maintenance-settlement.test.mjs +1003 -0
- package/tests/managed-memory.test.mjs +39 -11
- package/tests/managed-runtime.test.mjs +109 -0
- package/tests/memory-fields.test.mjs +24 -12
- package/tests/observed-evidence.test.mjs +52 -0
- package/tests/port-surface.test.mjs +93 -1
- package/tests/preset-mount.test.mjs +12 -4
- package/tests/recall-cache.test.mjs +56 -3
- package/tests/recall-dedup.test.mjs +63 -2
- package/tests/retention.test.mjs +260 -0
- package/tests/rt-index-cross-library.test.mjs +230 -0
- package/tests/rt-index-integration.test.mjs +194 -0
- package/tests/rt-index-retention.test.mjs +552 -0
- package/tests/rt-index-scale.test.mjs +204 -0
- package/tests/rt-index.test.mjs +705 -0
- package/tests/salient-date-boundaries.test.mjs +121 -0
- package/tests/salient-wake.test.mjs +29 -0
- package/tests/scale-bench.test.mjs +53 -0
- package/tests/settings-plumbing.test.mjs +25 -0
- package/tests/simulate-injection.test.mjs +15 -1
- package/tests/standalone-navigation.test.mjs +44 -0
- package/tests/state.test.mjs +51 -0
- package/tests/temporal-precision.test.mjs +102 -0
- package/tests/temporal.test.mjs +10 -6
- package/tests/token-measurement.test.mjs +98 -0
- package/tests/tool-schema.test.mjs +41 -5
- package/tests/tools.test.mjs +6 -3
- package/tests/turn-token-budget.test.mjs +149 -0
- package/tests/webui-auth.test.mjs +57 -1
- package/tests/webui.test.mjs +40 -15
- package/tests/worker-lifecycle.test.mjs +2 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/** Optional offscreen WebGL2 layer; the public canvas stays 2D for snapshots. */
|
|
2
|
+
export function createWebGLRenderer(document, onLost = () => {}) {
|
|
3
|
+
if (!document?.createElement) return null
|
|
4
|
+
let canvas, gl, program, buffer, vao
|
|
5
|
+
const shaders = []
|
|
6
|
+
let lost = false, disposed = false
|
|
7
|
+
const dispose = () => {
|
|
8
|
+
if (disposed) return
|
|
9
|
+
disposed = true
|
|
10
|
+
canvas?.removeEventListener('webglcontextlost', contextLost)
|
|
11
|
+
if (gl) {
|
|
12
|
+
if (buffer) gl.deleteBuffer(buffer)
|
|
13
|
+
if (vao) gl.deleteVertexArray(vao)
|
|
14
|
+
if (program) gl.deleteProgram(program)
|
|
15
|
+
for (const shader of shaders) gl.deleteShader(shader)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const contextLost = event => { event.preventDefault(); lost = true; onLost() }
|
|
19
|
+
try {
|
|
20
|
+
canvas = document.createElement('canvas')
|
|
21
|
+
gl = canvas.getContext('webgl2', { alpha: true, antialias: false, preserveDrawingBuffer: true })
|
|
22
|
+
if (!gl) return null
|
|
23
|
+
const compile = (type, source) => {
|
|
24
|
+
const shader = gl.createShader(type)
|
|
25
|
+
shaders.push(shader); gl.shaderSource(shader, source); gl.compileShader(shader)
|
|
26
|
+
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) throw new Error('graph shader compilation failed')
|
|
27
|
+
return shader
|
|
28
|
+
}
|
|
29
|
+
const vertex = compile(gl.VERTEX_SHADER, `#version 300 es
|
|
30
|
+
in vec2 position; in float radius; in vec4 color;
|
|
31
|
+
uniform vec2 resolution; uniform float ratio; out vec4 tint;
|
|
32
|
+
void main(){vec2 p=position/resolution*2.0-1.0;gl_Position=vec4(p.x,-p.y,0,1);gl_PointSize=radius*ratio*2.0;tint=color;}`)
|
|
33
|
+
const fragment = compile(gl.FRAGMENT_SHADER, `#version 300 es
|
|
34
|
+
precision mediump float; in vec4 tint; out vec4 outputColor;
|
|
35
|
+
void main(){if(distance(gl_PointCoord,vec2(0.5))>0.5)discard;outputColor=tint;}`)
|
|
36
|
+
program = gl.createProgram(); gl.attachShader(program, vertex); gl.attachShader(program, fragment); gl.linkProgram(program)
|
|
37
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) throw new Error('graph shader linking failed')
|
|
38
|
+
buffer = gl.createBuffer(); vao = gl.createVertexArray()
|
|
39
|
+
gl.bindVertexArray(vao); gl.bindBuffer(gl.ARRAY_BUFFER, buffer)
|
|
40
|
+
for (const [name, count, offset] of [['position', 2, 0], ['radius', 1, 8], ['color', 4, 12]]) {
|
|
41
|
+
const location = gl.getAttribLocation(program, name)
|
|
42
|
+
gl.enableVertexAttribArray(location); gl.vertexAttribPointer(location, count, gl.FLOAT, false, 28, offset); gl.vertexAttribDivisor(location, 1)
|
|
43
|
+
}
|
|
44
|
+
const resolution = gl.getUniformLocation(program, 'resolution'), ratioLocation = gl.getUniformLocation(program, 'ratio')
|
|
45
|
+
canvas.addEventListener('webglcontextlost', contextLost)
|
|
46
|
+
let data = new Float32Array(0)
|
|
47
|
+
return {
|
|
48
|
+
draw(points, width, height, ratio, colorOf, faded) {
|
|
49
|
+
if (lost || disposed) return null
|
|
50
|
+
try {
|
|
51
|
+
const needed = points.length * 7
|
|
52
|
+
if (data.length < needed) data = new Float32Array(Math.max(needed, data.length * 2))
|
|
53
|
+
points.forEach((point, i) => {
|
|
54
|
+
const color = Number.parseInt(colorOf(point.node).slice(1), 16), at = i * 7
|
|
55
|
+
data[at] = point.x; data[at + 1] = point.y; data[at + 2] = point.r
|
|
56
|
+
data[at + 3] = (color >>> 16 & 255) / 255; data[at + 4] = (color >>> 8 & 255) / 255
|
|
57
|
+
data[at + 5] = (color & 255) / 255; data[at + 6] = faded(point.node) ? .22 : 1
|
|
58
|
+
})
|
|
59
|
+
const w = Math.max(1, Math.round(width * ratio)), h = Math.max(1, Math.round(height * ratio))
|
|
60
|
+
if (canvas.width !== w || canvas.height !== h) { canvas.width = w; canvas.height = h }
|
|
61
|
+
gl.viewport(0, 0, w, h); gl.clearColor(0, 0, 0, 0); gl.clear(gl.COLOR_BUFFER_BIT)
|
|
62
|
+
gl.useProgram(program); gl.bindVertexArray(vao); gl.bindBuffer(gl.ARRAY_BUFFER, buffer)
|
|
63
|
+
gl.bufferData(gl.ARRAY_BUFFER, data.subarray(0, needed), gl.DYNAMIC_DRAW)
|
|
64
|
+
gl.uniform2f(resolution, width, height); gl.uniform1f(ratioLocation, ratio)
|
|
65
|
+
gl.enable(gl.BLEND); gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
|
|
66
|
+
gl.drawArraysInstanced(gl.POINTS, 0, 1, points.length)
|
|
67
|
+
if (gl.getError() !== gl.NO_ERROR) { lost = true; onLost(); return null }
|
|
68
|
+
return canvas
|
|
69
|
+
} catch { lost = true; onLost(); return null }
|
|
70
|
+
},
|
|
71
|
+
dispose,
|
|
72
|
+
}
|
|
73
|
+
} catch { dispose(); return null }
|
|
74
|
+
}
|
package/lib/webui/standalone.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
}
|
|
24
24
|
// 页序只留这一份 slug 清单;PAGE_NAMES 的键由 check-i18n.mjs 与
|
|
25
25
|
// client.js 的 SETTINGS_PAGES 对齐校验,避免第三份清单漂移。
|
|
26
|
-
var SETTINGS_PAGES = ['engine', 'connection', 'settings', 'folders', 'libraries', 'browser', 'global', 'prompts', 'stats', 'memories', 'graph', 'logs', 'lexicon', 'help']
|
|
26
|
+
var SETTINGS_PAGES = ['engine', 'connection', 'settings', 'folders', 'libraries', 'browser', 'global', 'prompts', 'stats', 'memories', 'graph', 'logs', 'lexicon', 'help', 'diagnostics']
|
|
27
27
|
var PAGE_NAMES = {
|
|
28
28
|
zh: {
|
|
29
29
|
engine: '引擎与连接', connection: '连接与向量', settings: '记忆设置', folders: '文件夹', libraries: '记忆库',
|
package/lib/worker-pool.js
CHANGED
|
@@ -12,6 +12,7 @@ import { getSessionBinding, getSettings, setSessionBinding, deleteSessionBinding
|
|
|
12
12
|
import fs from 'node:fs'
|
|
13
13
|
import { warn, shortHash, dataDir } from './paths.js'
|
|
14
14
|
import { estTokens } from './budget.js'
|
|
15
|
+
import { createDomainOutputFactors, WORKER_FACTOR_DEFAULT } from './token-measurement.js'
|
|
15
16
|
import { record } from './activity-log.js'
|
|
16
17
|
import { loadLedger, scopeGenerationOf } from './consolidation-ledger.js'
|
|
17
18
|
import { presetSetupFor, resolveConsolidationPreset } from './preset-mount.js'
|
|
@@ -33,9 +34,12 @@ export const WORKER_EPOCH_TIERS = Object.freeze([
|
|
|
33
34
|
Object.freeze({ maxContext: 262_144, charLimit: 200_000, maxWindows: 16 }),
|
|
34
35
|
Object.freeze({ maxContext: Number.MAX_SAFE_INTEGER, charLimit: 200_000, maxWindows: 16 }),
|
|
35
36
|
])
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
|
|
37
|
+
// Cold start remains 3. Complete observed windows feed a bounded per-domain
|
|
38
|
+
// sliding factor (2..4), using input and retained visible output in CHARACTERS.
|
|
39
|
+
// Hidden reasoning has no character attribution and is explicitly unverified.
|
|
40
|
+
export const WORKER_OUTPUT_FACTOR = WORKER_FACTOR_DEFAULT
|
|
41
|
+
const domainOutputFactors = createDomainOutputFactors()
|
|
42
|
+
export function workerOutputFactor(domain = 'general') { return domainOutputFactors.snapshot(domain) }
|
|
39
43
|
// 条件 4(§4.5):距上一窗 whenIdle 完成超过缓存 TTL 即换新。只在 acquire 时检查,
|
|
40
44
|
// 不做后台定时退役;TTL 是保守方向的启发式——早换新永不吃亏。
|
|
41
45
|
export const WORKER_EPOCH_IDLE_TTL_MS = 30 * 60_000
|
|
@@ -67,7 +71,8 @@ export function epochBudget(binding, settings = null) {
|
|
|
67
71
|
export function budgetFit(epoch, incrementChars, settings = null) {
|
|
68
72
|
const chars = Number(epoch?.chars) || 0
|
|
69
73
|
const increment = Math.max(0, Number(incrementChars) || 0)
|
|
70
|
-
|
|
74
|
+
const factor = workerOutputFactor(epoch?.outputFactorDomain).factor
|
|
75
|
+
return chars + increment * factor <= epochBudget({ workerEpoch: epoch }, settings).charLimit
|
|
71
76
|
}
|
|
72
77
|
|
|
73
78
|
/** Never repair a user's path or change host permissions; only select a usable cwd. */
|
|
@@ -452,8 +457,27 @@ export function recordEpochProgress(binding, { measurement = null, incrementChar
|
|
|
452
457
|
? null : (usage[key] ?? 0) + measurement.usage[key]
|
|
453
458
|
}
|
|
454
459
|
}
|
|
460
|
+
const outputFactorDomain = epoch.outputFactorDomain || current.domainOverride || current.domain || 'general'
|
|
461
|
+
const observedKeys = ['outputTextChars', 'toolArgumentsChars', 'toolResultsChars']
|
|
462
|
+
// Real callers report progress first and settlement later. Keep only numeric
|
|
463
|
+
// provisional evidence; commit it once the window settles, discard on timeout.
|
|
464
|
+
let outputFactorPending = epoch.outputFactorPending || null
|
|
465
|
+
if (progress && countWindow) {
|
|
466
|
+
outputFactorPending = !usageTotals && measurement && measurement.serializationErrors === 0
|
|
467
|
+
&& Number.isSafeInteger(inputChars) && inputChars > 0
|
|
468
|
+
&& observedKeys.every(key => Number.isSafeInteger(measurement.observed[key]) && measurement.observed[key] >= 0)
|
|
469
|
+
? { inputChars, outputChars } : null
|
|
470
|
+
}
|
|
471
|
+
if (timeout) outputFactorPending = null
|
|
472
|
+
if (settled && !timeout && outputFactorPending) {
|
|
473
|
+
domainOutputFactors.observe(outputFactorDomain, outputFactorPending.inputChars, outputFactorPending.outputChars)
|
|
474
|
+
outputFactorPending = null
|
|
475
|
+
}
|
|
455
476
|
const next = {
|
|
456
477
|
...epoch,
|
|
478
|
+
outputFactorDomain,
|
|
479
|
+
outputFactorPending,
|
|
480
|
+
outputFactor: workerOutputFactor(outputFactorDomain),
|
|
457
481
|
chars: Math.max(0, Number(epoch.chars) || 0)
|
|
458
482
|
+ (progress ? Math.max(0, Number(inputChars) || 0) + Math.max(0, Number(outputChars) || 0) : 0),
|
|
459
483
|
// Legacy callers/unknown serialization must never certify a partially measured epoch.
|
|
@@ -570,9 +594,14 @@ export async function acquireWorker(ctx, binding, {
|
|
|
570
594
|
if (handle && resumed) {
|
|
571
595
|
// Resume does not promise to rerun create.setup. Reapply through the same
|
|
572
596
|
// public mount API, or retire when the resumed context cannot be verified.
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
597
|
+
let mounted = null
|
|
598
|
+
if (handle.agent.ctx || presetSelection.presetId === null) {
|
|
599
|
+
await presetSetupFor(ctx, {
|
|
600
|
+
selection: presetSelection,
|
|
601
|
+
onResolved: result => { mounted = result },
|
|
602
|
+
log: presetLog,
|
|
603
|
+
})(handle.agent.ctx, handle.agent)
|
|
604
|
+
}
|
|
576
605
|
if (!mounted?.confirmed) {
|
|
577
606
|
try { resumeAbort?.abort() } catch {}
|
|
578
607
|
const result = await retireWorker(ctx, epoch.forkSessionId, 'preset-unverified', { handoff: false, now, idleWaitMs })
|
|
@@ -723,6 +752,8 @@ export async function acquireWorker(ctx, binding, {
|
|
|
723
752
|
timeouts: 0,
|
|
724
753
|
scopeGeneration: scopeGenerationOf(liveBinding),
|
|
725
754
|
parentSession: sessionId,
|
|
755
|
+
outputFactorDomain: liveBinding.domainOverride || liveBinding.domain || 'general',
|
|
756
|
+
outputFactor: workerOutputFactor(liveBinding.domainOverride || liveBinding.domain || 'general'),
|
|
726
757
|
modelMaxContext: modelMaxContext || null,
|
|
727
758
|
lastIdleAt: null,
|
|
728
759
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-memu-memory",
|
|
3
3
|
"icon": "./assets/icon.png",
|
|
4
|
-
"version": "1.4.
|
|
4
|
+
"version": "1.4.5",
|
|
5
5
|
"description": "面向长篇 RP 与陪伴对话的 DeepSeek Harness 记忆插件:三层记忆、逐轮召回、来源标注、关系图、图片附件与独立 WebUI。",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"deepseek-harness",
|
|
@@ -65,7 +65,8 @@
|
|
|
65
65
|
"test": "node --import ./tests/loader-register.mjs --test tests/*.test.mjs",
|
|
66
66
|
"test:chain": "node scripts/chain-matrix.mjs",
|
|
67
67
|
"replay": "node --import ./tests/loader-register.mjs scripts/replay.mjs",
|
|
68
|
-
"simulate:injection": "node scripts/simulate-injection.mjs"
|
|
68
|
+
"simulate:injection": "node scripts/simulate-injection.mjs",
|
|
69
|
+
"bench:scale": "node --import ./tests/loader-register.mjs scripts/scale-bench.mjs"
|
|
69
70
|
},
|
|
70
71
|
"engines": {
|
|
71
72
|
"node": ">=20.9.0",
|
|
@@ -478,16 +478,10 @@ await auto('E-1', 'both folder switches off: no library, no injection, no prompt
|
|
|
478
478
|
return 'unbound, no library, no injection'
|
|
479
479
|
})
|
|
480
480
|
|
|
481
|
-
await auto('E-2', '
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
bindSession('sess-e2', { cwd, libraryId: lib.id })
|
|
486
|
-
const sidebar = await dispatch({}, 'getSidebarState', { sessionId: 'sess-e2' })
|
|
487
|
-
const text = JSON.stringify(sidebar)
|
|
488
|
-
assert.ok(!text.includes(home.split(path.sep).join('/')), 'the temp home path does not leak')
|
|
489
|
-
assert.ok(!/[A-Za-z]:\\|\.\/lib\//.test(text), 'no drive letters or repo-relative paths either')
|
|
490
|
-
return 'two levels, no paths in ' + text.length + ' bytes of sidebar state'
|
|
481
|
+
await auto('E-2', 'sidebar folder labels and tooltips omit full paths on either platform', async () => {
|
|
482
|
+
// scopeKey is internal routing metadata. The UI contract is about rendered
|
|
483
|
+
// folder text and tooltips, tested against Windows, POSIX and UNC spellings.
|
|
484
|
+
return runTestFile('tests/client-render.test.mjs')
|
|
491
485
|
})
|
|
492
486
|
|
|
493
487
|
await auto('E-3', 'a switch the folder forbids snaps back instead of silently winning', async () => {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import os from 'node:os'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import { performance } from 'node:perf_hooks'
|
|
5
|
+
|
|
6
|
+
const home = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-all-graph-bench-'))
|
|
7
|
+
process.env.DSH_MEMU_HOME = home
|
|
8
|
+
process.env.DSH_MEMU_MEMORY_HOME = home
|
|
9
|
+
const state = await import('../lib/state.js')
|
|
10
|
+
const { getGraphOverview } = await import('../lib/graph.js')
|
|
11
|
+
const { graphAdjacencyDiagnostics } = await import('../lib/graph-adjacency-index.js')
|
|
12
|
+
const firstPage = Number(process.argv[2]) || 3000
|
|
13
|
+
const libraries = []
|
|
14
|
+
try {
|
|
15
|
+
for (let b = 0; b < 10; b++) {
|
|
16
|
+
const library = state.createLibrary({ name: 'Benchmark ' + b, cwd: path.join(home, String(b)) })
|
|
17
|
+
const entries = {}
|
|
18
|
+
for (let i = 0; i < 3405; i++) entries['m-' + i] = {
|
|
19
|
+
title: 'Synthetic memory ' + i, content: 'Isolated graph benchmark.', status: 'active',
|
|
20
|
+
layer: 'long_term', domain: 'general', visibility: 'shared', strength: .7,
|
|
21
|
+
links: i ? [{ to: 'm-' + (i - 1), kind: 'relation', source: 'manual' }] : [],
|
|
22
|
+
}
|
|
23
|
+
state.savePrivateIndex(library.id, { entries })
|
|
24
|
+
libraries.push(library.id)
|
|
25
|
+
}
|
|
26
|
+
const runs = []
|
|
27
|
+
for (const phase of ['cold', 'warm', 'warm-repeat']) {
|
|
28
|
+
const started = performance.now()
|
|
29
|
+
let calls = 0, nodes = 0, edges = 0
|
|
30
|
+
const cursors = libraries.map(libraryId => ({ libraryId, offset: 0, limit: firstPage, done: false }))
|
|
31
|
+
while (cursors.some(cursor => !cursor.done)) for (const cursor of cursors) {
|
|
32
|
+
if (cursor.done) continue
|
|
33
|
+
const page = getGraphOverview({ libraryId: cursor.libraryId, overview: true, layout: 'classic',
|
|
34
|
+
offset: cursor.offset, limit: cursor.limit })
|
|
35
|
+
calls++; nodes += page.nodes.length; edges += page.edges.length
|
|
36
|
+
cursor.done = !Number.isInteger(page.nextOffset)
|
|
37
|
+
cursor.offset = page.nextOffset
|
|
38
|
+
cursor.limit = 3000
|
|
39
|
+
}
|
|
40
|
+
runs.push({ phase, ms: Math.round((performance.now() - started) * 100) / 100, calls, nodes, edges })
|
|
41
|
+
}
|
|
42
|
+
console.log(JSON.stringify({ libraries: libraries.length, perLibrary: 3405, firstPage, runs,
|
|
43
|
+
adjacency: graphAdjacencyDiagnostics() }, null, 2))
|
|
44
|
+
} finally {
|
|
45
|
+
state.flushState()
|
|
46
|
+
if (path.dirname(home) === path.resolve(os.tmpdir()) && path.basename(home).startsWith('dsh-all-graph-bench-')) fs.rmSync(home, { recursive: true, force: true })
|
|
47
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import assert from 'node:assert/strict'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import http from 'node:http'
|
|
4
|
+
import os from 'node:os'
|
|
5
|
+
import path from 'node:path'
|
|
6
|
+
import { chromium } from 'playwright'
|
|
7
|
+
|
|
8
|
+
// Real RPC and shipped browser bundle, using only a disposable synthetic library.
|
|
9
|
+
// Run: node --import ./tests/loader-register.mjs scripts/check-classic-graph-browser.mjs
|
|
10
|
+
const home = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-classic-graph-'))
|
|
11
|
+
process.env.DSH_MEMU_HOME = home
|
|
12
|
+
process.env.DSH_MEMU_MEMORY_HOME = home
|
|
13
|
+
process.env.MEMU_CONFIG = path.join(home, 'config.env')
|
|
14
|
+
const state = await import('../lib/state.js')
|
|
15
|
+
const graph = await import('../lib/graph.js')
|
|
16
|
+
const { registerRpc } = await import('../lib/rpc.js')
|
|
17
|
+
state.updateSettings({ autoInstallEngine: false, sleepConsolidation: false, memoryMode: 'local' })
|
|
18
|
+
const book = state.createLibrary({ name: 'Classic ring fixture', cwd: home })
|
|
19
|
+
const id = i => 'mem-classic-' + String(i).padStart(6, '0')
|
|
20
|
+
const entries = {}, roots = []
|
|
21
|
+
let start = 0, edgeCount = 0
|
|
22
|
+
for (const count of [1000, 600, 500, 400, 300, 250, 200, 150]) {
|
|
23
|
+
roots.push(start)
|
|
24
|
+
for (let local = 0; local < count; local++) {
|
|
25
|
+
const index = start + local
|
|
26
|
+
const links = local ? [{ to: id(start + Math.floor((local - 1) / 5)), kind: 'relation', source: 'manual' }] : []
|
|
27
|
+
edgeCount += links.length
|
|
28
|
+
entries[id(index)] = { title: 'Fixture memory ' + String(index).padStart(6, '0'), content: 'Synthetic graph verification.',
|
|
29
|
+
status: 'active', visibility: 'shared', domain: 'rp', layer: 'long_term', source: 'user_said', strength: .7, links }
|
|
30
|
+
}
|
|
31
|
+
start += count
|
|
32
|
+
}
|
|
33
|
+
for (let i = 0; i < 5; i++) {
|
|
34
|
+
const entity = graph.createEntity({ libraryId: book.id, name: 'Fixture person ' + i, status: 'confirmed' })
|
|
35
|
+
entries[id(roots[i])].links.push({ to: entity.id, kind: 'person', source: 'auto', confidence: .9 })
|
|
36
|
+
edgeCount++
|
|
37
|
+
}
|
|
38
|
+
state.savePrivateIndex(book.id, { version: 1, entries })
|
|
39
|
+
const otherBooks = Array.from({ length: 9 }, (_, n) => {
|
|
40
|
+
const library = state.createLibrary({ name: 'Other library ' + n, cwd: path.join(home, 'other-' + n) })
|
|
41
|
+
const rows = {}
|
|
42
|
+
for (let i = 0; i < 205; i++) rows[id(i)] = { title: 'Other memory ' + i, content: 'Isolated multi-library fixture.',
|
|
43
|
+
status: 'active', domain: 'rp', layer: 'long_term', visibility: 'shared', strength: .7,
|
|
44
|
+
links: i ? [{ to: id(i - 1), kind: 'relation', source: 'manual' }] : [] }
|
|
45
|
+
state.savePrivateIndex(library.id, { entries: rows })
|
|
46
|
+
return library
|
|
47
|
+
})
|
|
48
|
+
state.flushState()
|
|
49
|
+
let handler, server, browser
|
|
50
|
+
registerRpc({ get: () => undefined, logger: console,
|
|
51
|
+
inject: (_dependencies, callback) => callback({ effect: fn => fn(), logger: console,
|
|
52
|
+
connection: { requestRejection: req => req.headers.origin && req.headers.origin !== `http://${req.headers.host}` ? 403 : undefined,
|
|
53
|
+
authorizeLibrary: async (_req, target) => !target.libraryId || [book, ...otherBooks].some(library => library.id === target.libraryId) },
|
|
54
|
+
webServer: { register: route => { if (route.path === '/dsh-memu-memory') handler = route.handler; return () => {} } } }) })
|
|
55
|
+
assert.equal(typeof handler, 'function')
|
|
56
|
+
const output = path.resolve('logs'), report = { scenarios: [], screenshots: [], errors: [] }
|
|
57
|
+
fs.mkdirSync(output, { recursive: true })
|
|
58
|
+
const snapshot = page => page.locator('canvas.dshm-graph-canvas').evaluate(canvas => canvas.__dshmGraphView.snapshot())
|
|
59
|
+
const pause = ms => new Promise(resolve => setTimeout(resolve, ms))
|
|
60
|
+
async function capture(page, name) {
|
|
61
|
+
const file = path.join(output, `classic-graph-${name}.png`)
|
|
62
|
+
await page.screenshot({ path: file })
|
|
63
|
+
report.screenshots.push(file)
|
|
64
|
+
}
|
|
65
|
+
async function framed(page) {
|
|
66
|
+
return page.locator('canvas.dshm-graph-canvas').evaluate(canvas => {
|
|
67
|
+
const rect = canvas.getBoundingClientRect(), nodes = canvas.__dshmGraphView.snapshot()
|
|
68
|
+
return nodes.every(node => node.x - node.r >= 0 && node.x + node.r <= rect.width
|
|
69
|
+
&& node.y - node.r >= 0 && node.y + node.r <= rect.height)
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
server = http.createServer((req, res) => { void handler(req, res).catch(error => {
|
|
74
|
+
report.errors.push(String(error)); if (!res.headersSent) res.writeHead(500); res.end('fixture failure')
|
|
75
|
+
}) })
|
|
76
|
+
await new Promise(resolve => server.listen(0, '127.0.0.1', resolve))
|
|
77
|
+
const base = `http://127.0.0.1:${server.address().port}/dsh-memu-memory/ui?libraryId=${encodeURIComponent(book.id)}`
|
|
78
|
+
browser = await chromium.launch({ headless: true, channel: process.env.UI_BROWSER_CHANNEL || 'msedge' })
|
|
79
|
+
for (const viewport of [{ width: 1440, height: 1000 }, { width: 390, height: 844 }]) {
|
|
80
|
+
const context = await browser.newContext({ viewport, locale: 'zh-CN', reducedMotion: 'reduce' })
|
|
81
|
+
await context.addInitScript(() => {
|
|
82
|
+
for (const name of ['clearRect', 'arc', 'roundRect']) {
|
|
83
|
+
const original = CanvasRenderingContext2D.prototype[name]
|
|
84
|
+
if (!original) continue
|
|
85
|
+
CanvasRenderingContext2D.prototype[name] = function (...args) {
|
|
86
|
+
if (this.canvas.classList.contains('dshm-graph-canvas')) {
|
|
87
|
+
if (name === 'clearRect') this.canvas.__classicShapes = { circles: 0, squares: 0 }
|
|
88
|
+
else if (this.canvas.__classicShapes) this.canvas.__classicShapes[name === 'arc' ? 'circles' : 'squares']++
|
|
89
|
+
}
|
|
90
|
+
return original.apply(this, args)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
const page = await context.newPage(), calls = [], replies = []
|
|
95
|
+
page.setDefaultTimeout(20000)
|
|
96
|
+
page.on('pageerror', error => report.errors.push(String(error)))
|
|
97
|
+
await page.route('**/dsh-memu-memory/getGraph', async route => {
|
|
98
|
+
const args = route.request().postDataJSON().payload
|
|
99
|
+
calls.push(args)
|
|
100
|
+
const response = await route.fetch(), body = await response.json()
|
|
101
|
+
replies.push({ args, result: body.result })
|
|
102
|
+
await route.fulfill({ response, json: body })
|
|
103
|
+
})
|
|
104
|
+
await page.goto(base + '#/settings/graph')
|
|
105
|
+
await page.locator('#boot').waitFor({ state: 'hidden' })
|
|
106
|
+
await page.waitForFunction(() => document.querySelector('canvas.dshm-graph-canvas')?.__dshmGraphView?.snapshot().length === 3405)
|
|
107
|
+
await pause(350)
|
|
108
|
+
assert.deepEqual(calls.map(args => args.offset), [0, 3000])
|
|
109
|
+
assert.ok(calls.every(args => args.layout === 'classic' && args.libraryId === book.id))
|
|
110
|
+
assert.ok(replies.every(reply => reply.result.ok && reply.result.value.mode === 'classic'))
|
|
111
|
+
assert.equal(replies.reduce((sum, reply) => sum + reply.result.value.edges.length, 0), edgeCount)
|
|
112
|
+
const original = await snapshot(page)
|
|
113
|
+
const fittedZoom = await page.locator('canvas.dshm-graph-canvas').evaluate(canvas => canvas.__dshmGraphView.viewport().zoom)
|
|
114
|
+
assert.equal(new Set(original.map(node => node.id)).size, 3405)
|
|
115
|
+
assert.ok(new Set(original.map(node => node.worldX)).size > 1000, 'flower positions cannot form a rectangular grid')
|
|
116
|
+
assert.equal(await framed(page), true, 'fit must include the complete graph')
|
|
117
|
+
await capture(page, `${viewport.width}-fit`)
|
|
118
|
+
const beforeZoom = calls.length
|
|
119
|
+
await page.locator('canvas.dshm-graph-canvas').evaluate(canvas => canvas.__dshmGraphView.zoom(1e-9))
|
|
120
|
+
await pause(450)
|
|
121
|
+
assert.equal(calls.length, beforeZoom, 'minimum zoom cannot replace the complete graph with a viewport page')
|
|
122
|
+
assert.equal(await framed(page), true)
|
|
123
|
+
const painted = await page.locator('canvas.dshm-graph-canvas').evaluate(canvas => {
|
|
124
|
+
const bytes = canvas.getContext('2d').getImageData(0, 0, canvas.width, canvas.height).data
|
|
125
|
+
let colored = 0
|
|
126
|
+
for (let i = 0; i < bytes.length; i += 4) if (bytes[i + 3] && Math.max(bytes[i], bytes[i + 1], bytes[i + 2]) - Math.min(bytes[i], bytes[i + 1], bytes[i + 2]) > 30) colored++
|
|
127
|
+
return { ...canvas.__classicShapes, colored, zoom: canvas.__dshmGraphView.viewport().zoom,
|
|
128
|
+
diagnostics: canvas.__dshmGraphView.diagnostics() }
|
|
129
|
+
})
|
|
130
|
+
assert.equal(painted.circles, 3405); assert.equal(painted.squares, 0); assert.ok(painted.colored > 100)
|
|
131
|
+
assert.equal(painted.diagnostics.workerPending, false)
|
|
132
|
+
assert.equal(painted.diagnostics.workerUsed, false)
|
|
133
|
+
assert.deepEqual((await snapshot(page)).map(node => [node.worldX, node.worldY]), original.map(node => [node.worldX, node.worldY]))
|
|
134
|
+
await capture(page, `${viewport.width}-minimum`)
|
|
135
|
+
const camera = await page.locator('canvas.dshm-graph-canvas').evaluate(canvas => canvas.__dshmGraphView.viewport())
|
|
136
|
+
const search = page.locator('.dshm-gs-topbar input[aria-label="搜索节点 / 证据…"]')
|
|
137
|
+
await search.fill('Fixture memory 003399')
|
|
138
|
+
await page.waitForFunction(() => document.querySelector('canvas.dshm-graph-canvas')?.__dshmGraphView.snapshot().length === 1)
|
|
139
|
+
assert.equal((await snapshot(page))[0].id, id(3399))
|
|
140
|
+
await search.fill('')
|
|
141
|
+
await page.waitForFunction(() => document.querySelector('canvas.dshm-graph-canvas')?.__dshmGraphView.snapshot().length === 3405)
|
|
142
|
+
assert.deepEqual(await page.locator('canvas.dshm-graph-canvas').evaluate(canvas => canvas.__dshmGraphView.viewport()), camera,
|
|
143
|
+
'clearing search must restore the actual minimum-zoom camera')
|
|
144
|
+
const beforeRefresh = calls.length
|
|
145
|
+
await Promise.all([
|
|
146
|
+
page.waitForResponse(response => response.url().endsWith('/getGraph')
|
|
147
|
+
&& !response.request().postDataJSON().payload.query && response.request().postDataJSON().payload.offset === 3000),
|
|
148
|
+
page.getByRole('button', { name: '总览', exact: true }).click(),
|
|
149
|
+
])
|
|
150
|
+
await page.waitForFunction(expected => {
|
|
151
|
+
const view = document.querySelector('canvas.dshm-graph-canvas')?.__dshmGraphView
|
|
152
|
+
return view?.snapshot().length === 3405 && Math.abs(view.viewport().zoom - expected) < 1e-8
|
|
153
|
+
}, fittedZoom)
|
|
154
|
+
assert.equal(calls.length, beforeRefresh + 2)
|
|
155
|
+
assert.equal(await framed(page), true)
|
|
156
|
+
assert.deepEqual((await snapshot(page)).map(node => [node.worldX, node.worldY]), original.map(node => [node.worldX, node.worldY]))
|
|
157
|
+
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth), false)
|
|
158
|
+
const beforeAll = calls.length, allStarted = Date.now()
|
|
159
|
+
await page.locator('select[aria-label="当前记忆库"]').selectOption('__global__')
|
|
160
|
+
await page.waitForFunction(() => document.querySelector('canvas.dshm-graph-canvas')?.__dshmGraphView?.snapshot().length === 5250)
|
|
161
|
+
const aggregateMs = Date.now() - allStarted
|
|
162
|
+
const aggregate = await snapshot(page), allCalls = calls.slice(beforeAll)
|
|
163
|
+
assert.equal(allCalls.length, 11, 'ten complete libraries require two pages for the large library and one each for the rest')
|
|
164
|
+
assert.ok(allCalls.every(args => args.sessionId === undefined && args.layout === 'classic'))
|
|
165
|
+
assert.equal(new Set(aggregate.map(node => node.id)).size, 5250, 'same raw IDs in different libraries stay distinct')
|
|
166
|
+
assert.equal(await framed(page), true)
|
|
167
|
+
await capture(page, `${viewport.width}-all-libraries`)
|
|
168
|
+
report.scenarios.push({ viewport, nodes: 3405, edges: edgeCount, pages: [3000, 405],
|
|
169
|
+
allFramed: true, searchRestoresCamera: true, refreshPreservesPositions: true, minimum: painted,
|
|
170
|
+
allLibraries: { libraries: 10, nodes: 5250, calls: allCalls.length, ms: aggregateMs, allFramed: true } })
|
|
171
|
+
await context.close()
|
|
172
|
+
}
|
|
173
|
+
assert.deepEqual(report.errors, [])
|
|
174
|
+
console.log(JSON.stringify(report, null, 2))
|
|
175
|
+
} catch (error) {
|
|
176
|
+
report.error = String(error.stack || error)
|
|
177
|
+
if (browser) for (const context of browser.contexts()) for (const page of context.pages()) {
|
|
178
|
+
try { await capture(page, `failure-${Date.now()}`) } catch {}
|
|
179
|
+
}
|
|
180
|
+
console.error(error)
|
|
181
|
+
process.exitCode = 1
|
|
182
|
+
} finally {
|
|
183
|
+
await browser?.close()
|
|
184
|
+
if (server) await new Promise(resolve => server.close(resolve))
|
|
185
|
+
state.flushState()
|
|
186
|
+
// Delete only this process's verified temporary fixture directory.
|
|
187
|
+
if (path.dirname(home) === path.resolve(os.tmpdir()) && path.basename(home).startsWith('dsh-classic-graph-')) fs.rmSync(home, { recursive: true, force: true })
|
|
188
|
+
fs.writeFileSync(path.join(output, 'classic-graph-browser-report.json'), JSON.stringify(report, null, 2))
|
|
189
|
+
}
|