dsh-memvault 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -25
- package/README.zh.md +71 -35
- package/cordis.patch.yml +23 -0
- package/docs/CORE-DESIGN.md +10 -1
- package/docs/DEVLOG.md +658 -0
- package/docs/PLAN-0.11.md +421 -0
- package/docs/domains/game-dev.md +67 -0
- package/lib/blocks.js +34 -8
- package/lib/client.js +631 -12
- package/lib/config.js +207 -0
- package/lib/core/block-write.js +70 -17
- package/lib/core/host.js +15 -4
- package/lib/core/knowledge.js +332 -0
- package/lib/core/pipeline.js +13 -4
- package/lib/core/promotion.js +155 -0
- package/lib/core/proposals.js +508 -0
- package/lib/core/schema.js +159 -1
- package/lib/core/store.js +160 -3
- package/lib/core/tools.js +155 -4
- package/lib/domain-host.js +490 -0
- package/lib/domain.js +483 -0
- package/lib/gate.js +201 -0
- package/lib/index.js +412 -7
- package/lib/panel.js +209 -3
- package/package.json +2 -2
- package/scripts/seed-domains.mjs +171 -0
- package/scripts/smoke-package.mjs +23 -6
- package/scripts/smoke-panel.mjs +200 -14
- package/src/client/index.js +629 -10
package/scripts/smoke-panel.mjs
CHANGED
|
@@ -31,6 +31,10 @@ import {
|
|
|
31
31
|
MEMORY_PATH,
|
|
32
32
|
REFRESH_PATH,
|
|
33
33
|
REPLAY_PATH,
|
|
34
|
+
DOMAIN_PATH,
|
|
35
|
+
KNOWLEDGE_PATH,
|
|
36
|
+
TIMELINE_PATH,
|
|
37
|
+
PROPOSALS_PATH,
|
|
34
38
|
REVIEW_PATH,
|
|
35
39
|
STATUS_PATH,
|
|
36
40
|
STRUCTURE_PATH,
|
|
@@ -62,6 +66,7 @@ import { PRODUCED_TEXT_CLAMP, shapeProduced } from '../lib/extract.js'
|
|
|
62
66
|
import { countRetyped, readMemories as readCoreMemories } from '../lib/core/panel-read.js'
|
|
63
67
|
import { CoreStore } from '../lib/core/store.js'
|
|
64
68
|
import { buildStructure } from '../lib/structure.js'
|
|
69
|
+
import { propose } from '../lib/core/proposals.js'
|
|
65
70
|
import {
|
|
66
71
|
BLOCK_LABEL_MAX,
|
|
67
72
|
BLOCK_VALUE_MAX,
|
|
@@ -367,13 +372,18 @@ try {
|
|
|
367
372
|
})
|
|
368
373
|
|
|
369
374
|
check('plugin name matches the package', hostName === 'dsh-memvault', hostName)
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
375
|
+
// Two contributions now: the human-approved core blocks (order 210) and the
|
|
376
|
+
// workspace-dependent domain segment (215). Both are functions, not strings.
|
|
377
|
+
check('both runtime contexts are registered, core first',
|
|
378
|
+
contexts.length === 2
|
|
379
|
+
&& contexts[0].name === 'memvault:core' && contexts[0].order === 210
|
|
380
|
+
&& contexts[1].name === 'memvault:domain' && contexts[1].order === 215
|
|
381
|
+
&& contexts.every((c) => typeof c.text === 'function'),
|
|
382
|
+
contexts.map((c) => `\${'$'}{c.name}@\${'$'}{c.order}`).join(','))
|
|
373
383
|
// Memory text is arbitrary prose and code: interpolation must be off or a
|
|
374
384
|
// {{name}} inside a memory throws during assemble() and fails the request.
|
|
375
|
-
check('
|
|
376
|
-
contexts
|
|
385
|
+
check('neither runtime context interpolates prompt variables',
|
|
386
|
+
contexts.every((c) => c.interpolate === false && c.required === true),
|
|
377
387
|
JSON.stringify({ interpolate: contexts[0].interpolate, required: contexts[0].required }))
|
|
378
388
|
const injected = contexts[0].text()
|
|
379
389
|
check('the injected text carries both blocks and the attribution header',
|
|
@@ -396,9 +406,28 @@ try {
|
|
|
396
406
|
effect(fn) { return fn() },
|
|
397
407
|
tools: { register(definition) { registeredTools.push(definition.name); return () => {} } },
|
|
398
408
|
})
|
|
399
|
-
check('
|
|
409
|
+
check('all four memory tools register on the store', registeredTools.join(',') === 'memory_search,memory_add,memory_propose,memory_pending',
|
|
400
410
|
registeredTools.join(','))
|
|
401
411
|
|
|
412
|
+
// The domain half is a second child on the same service: four tools plus the one
|
|
413
|
+
// guard. The guard is the only part of this plugin that can refuse a call, so its
|
|
414
|
+
// presence is asserted on its own rather than inferred from the tool list.
|
|
415
|
+
const domainChild = children.filter((child) => child.deps.join(',') === 'tools')[1]
|
|
416
|
+
const domainTools = []
|
|
417
|
+
const guards = []
|
|
418
|
+
domainChild?.callback({
|
|
419
|
+
effect(fn) { return fn() },
|
|
420
|
+
tools: {
|
|
421
|
+
register(definition) { domainTools.push(definition.name); return () => {} },
|
|
422
|
+
guard(fn) { guards.push(fn); return () => {} },
|
|
423
|
+
},
|
|
424
|
+
})
|
|
425
|
+
check('five domain tools and exactly one guard register',
|
|
426
|
+
domainTools.join(',') === 'domain_activate,domain_deactivate,domain_detail,domain_gate,domain_draft' && guards.length === 1,
|
|
427
|
+
`${domainTools.join(',')} guards=${guards.length}`)
|
|
428
|
+
check('a guard with no computed gate allows the call (cold state fails open)',
|
|
429
|
+
guards[0]?.({ name: 'write', arguments: { path: 'x' } }) === undefined)
|
|
430
|
+
|
|
402
431
|
// A closed session is the one moment "this conversation is over" is known, so its
|
|
403
432
|
// window is handed over then instead of waiting for an idle timer it may never get.
|
|
404
433
|
const disposedHandler = handlers.find((entry) => entry.event === 'session/disposed')?.handler
|
|
@@ -422,19 +451,20 @@ try {
|
|
|
422
451
|
extract: { enabled: false, statePath, projectDir: DEFAULT_EXTRACT.projectDir },
|
|
423
452
|
})
|
|
424
453
|
check('extraction off still registers the injection, the panel and the tools',
|
|
425
|
-
gateContexts.length ===
|
|
426
|
-
&& gateChildren.
|
|
454
|
+
gateContexts.length === 2
|
|
455
|
+
&& gateChildren.filter((child) => child.deps.join(',') === 'tools').length >= 1
|
|
427
456
|
&& gateChildren.some((child) => child.deps.join(',') === 'webServer'),
|
|
428
457
|
JSON.stringify(gateChildren.map((c) => c.deps)))
|
|
429
458
|
check('extraction off registers no session observers',
|
|
430
459
|
gateHandlers.length === 0, gateHandlers.map((h) => h.event).join(','))
|
|
431
460
|
|
|
432
461
|
webChild.callback(childCtx)
|
|
433
|
-
check('all
|
|
462
|
+
check('all fifteen exact routes are registered',
|
|
434
463
|
routes.has(STATUS_PATH) && routes.has(REFRESH_PATH) && routes.has(BLOCKS_PATH)
|
|
435
464
|
&& routes.has(FLUSH_PATH) && routes.has(MEMORIES_PATH) && routes.has(MEMORY_PATH)
|
|
436
465
|
&& routes.has(FLAG_PATH) && routes.has(REVIEW_PATH) && routes.has(REPLAY_PATH)
|
|
437
|
-
&& routes.has(STRUCTURE_PATH)
|
|
466
|
+
&& routes.has(STRUCTURE_PATH) && routes.has(PROPOSALS_PATH) && routes.has(DOMAIN_PATH)
|
|
467
|
+
&& routes.has(KNOWLEDGE_PATH) && routes.has(TIMELINE_PATH),
|
|
438
468
|
[...routes.keys()].join(', '))
|
|
439
469
|
|
|
440
470
|
const call = async (path, method = 'GET', body = null, headers = { host: '127.0.0.1:19387' }) => {
|
|
@@ -448,10 +478,18 @@ try {
|
|
|
448
478
|
if (event === 'end') handler()
|
|
449
479
|
},
|
|
450
480
|
}
|
|
451
|
-
|
|
481
|
+
// The route map is keyed by pathname; a caller may append a query string.
|
|
482
|
+
await routes.get(path.split('?')[0]).handler(req, res)
|
|
452
483
|
return out
|
|
453
484
|
}
|
|
454
485
|
|
|
486
|
+
// The store file exists from the seeding above but nothing has opened it in this
|
|
487
|
+
// process yet — which is exactly the state after a DSH restart. The queue has to
|
|
488
|
+
// be readable then, or the panel shows an empty tab while proposals sit on disk.
|
|
489
|
+
const firstQueue = await call(`${PROPOSALS_PATH}?status=all`)
|
|
490
|
+
check('an existing store makes the queue readable before anything opens it',
|
|
491
|
+
firstQueue.code === 200 && firstQueue.body.unavailable !== true,
|
|
492
|
+
`unavailable=${firstQueue.body.unavailable}`)
|
|
455
493
|
const first = await call(STATUS_PATH)
|
|
456
494
|
check('GET status returns ok with real blocks',
|
|
457
495
|
first.code === 200 && first.body.ok === true && first.body.read.blockCount === 2,
|
|
@@ -501,6 +539,11 @@ try {
|
|
|
501
539
|
`blocks=${forced.body.read.blockCount}`)
|
|
502
540
|
check('the refreshed text is what the prompt will inject next',
|
|
503
541
|
contexts[0].text().includes('[user/lenovo/persona]'))
|
|
542
|
+
// A block that exists but did not fit the character budget used to be
|
|
543
|
+
// invisible outside the rendered string. The status now names it.
|
|
544
|
+
check('status reports how many blocks the budget dropped',
|
|
545
|
+
forced.body.read.droppedBlocks === 0,
|
|
546
|
+
`dropped=${forced.body.read.droppedBlocks}`)
|
|
504
547
|
|
|
505
548
|
// ── the write route, end to end ────────────────────────────────────────────
|
|
506
549
|
const untrustedWrite = await call(BLOCKS_PATH, 'POST', { action: 'set' }, { host: 'evil.example' })
|
|
@@ -558,6 +601,123 @@ try {
|
|
|
558
601
|
})
|
|
559
602
|
check('delete refuses a value', deleteWithValue.code === 400, deleteWithValue.body.error)
|
|
560
603
|
|
|
604
|
+
// ── the proposal queue: the only route that can change a block without a human
|
|
605
|
+
// typing the new value ─────────────────────────────────────────────────────
|
|
606
|
+
const proposalList = await call(`${PROPOSALS_PATH}?status=all`)
|
|
607
|
+
check('the proposal route lists a queue', proposalList.code === 200
|
|
608
|
+
&& Array.isArray(proposalList.body.items) && proposalList.body.summary?.pending === 0,
|
|
609
|
+
`items=${proposalList.body.items?.length}`)
|
|
610
|
+
|
|
611
|
+
const unknownDecision = await call(PROPOSALS_PATH, 'POST', { id: 'prop_doesnotexist', action: 'approve' })
|
|
612
|
+
check('deciding an unknown proposal is a 404', unknownDecision.code === 404, unknownDecision.body.error)
|
|
613
|
+
|
|
614
|
+
const badDecision = await call(PROPOSALS_PATH, 'POST', { id: 'x', action: 'apply' })
|
|
615
|
+
check('the route refuses an action that is not approve/reject/rollback',
|
|
616
|
+
badDecision.code === 400, badDecision.body.error)
|
|
617
|
+
|
|
618
|
+
// A proposal written by the other half (same file, second connection) must be
|
|
619
|
+
// visible through the panel and approvable through it — this is the round trip
|
|
620
|
+
// the model relies on: propose via tool, approve via panel.
|
|
621
|
+
const proposer = new CoreStore(dbPath)
|
|
622
|
+
proposer.setBlock({ scopeType: 'user', scopeId: 'lenovo', label: 'proposed-block', value: '旧值。' })
|
|
623
|
+
const queued = propose(proposer, {
|
|
624
|
+
scope_type: 'user', scope_id: 'lenovo', label: 'proposed-block',
|
|
625
|
+
change_kind: 'rewrite', value: '新值。', proposer: 'manual', confidence: 0.9,
|
|
626
|
+
})
|
|
627
|
+
proposer.close()
|
|
628
|
+
check('a queued proposal is listed as pending',
|
|
629
|
+
queued.ok === true && (await call(`${PROPOSALS_PATH}?status=pending`)).body.summary.pending === 1,
|
|
630
|
+
queued.error ?? queued.id)
|
|
631
|
+
|
|
632
|
+
const approved = await call(PROPOSALS_PATH, 'POST', { id: queued.id, action: 'approve' })
|
|
633
|
+
const afterApprove = await call(STATUS_PATH)
|
|
634
|
+
check('approving applies the value and the prompt text picks it up',
|
|
635
|
+
approved.code === 200 && approved.body.proposal?.status === 'applied'
|
|
636
|
+
&& afterApprove.body.blocks.some((b) => b.label === 'proposed-block' && b.value === '新值。'),
|
|
637
|
+
approved.body.error ?? approved.body.proposal?.status)
|
|
638
|
+
check('the applied block reaches the injection text',
|
|
639
|
+
contexts[0].text().includes('新值。'), 'injection text still shows the old value')
|
|
640
|
+
|
|
641
|
+
const rolledBack = await call(PROPOSALS_PATH, 'POST', { id: queued.id, action: 'rollback' })
|
|
642
|
+
const afterRollback = await call(STATUS_PATH)
|
|
643
|
+
check('rollback restores the previous value',
|
|
644
|
+
rolledBack.code === 200 && afterRollback.body.blocks.some((b) => b.label === 'proposed-block' && b.value === '旧值。'),
|
|
645
|
+
rolledBack.body.error ?? rolledBack.body.proposal?.status)
|
|
646
|
+
|
|
647
|
+
// ── domain packs ──────────────────────────────────────────────────────────
|
|
648
|
+
const emptyShelf = await call(DOMAIN_PATH)
|
|
649
|
+
check('the domain route lists an empty shelf before anything is authored',
|
|
650
|
+
emptyShelf.code === 200 && Array.isArray(emptyShelf.body.domains) && emptyShelf.body.domains.length === 0,
|
|
651
|
+
`domains=${emptyShelf.body.domains?.length}`)
|
|
652
|
+
// The whole point of a separate segment: no packs, no bytes. This is what keeps
|
|
653
|
+
// the injection byte-identical to 0.10 on an install that never uses domains.
|
|
654
|
+
check('with no packs the domain segment is empty', contexts[1].text() === '',
|
|
655
|
+
JSON.stringify(contexts[1].text()))
|
|
656
|
+
check('status carries the domain summary',
|
|
657
|
+
(await call(STATUS_PATH)).body.domain !== null, 'domain summary missing')
|
|
658
|
+
|
|
659
|
+
const noSource = await call(DOMAIN_PATH, 'POST', {
|
|
660
|
+
action: 'upsert',
|
|
661
|
+
domain_id: 'game',
|
|
662
|
+
index_text: '游戏机制前先查引擎文档',
|
|
663
|
+
status: 'active',
|
|
664
|
+
})
|
|
665
|
+
check('a pack cannot be born active without a source', noSource.code === 400, noSource.body.error)
|
|
666
|
+
|
|
667
|
+
const drafted = await call(DOMAIN_PATH, 'POST', {
|
|
668
|
+
action: 'upsert',
|
|
669
|
+
domain_id: 'game',
|
|
670
|
+
name: '游戏',
|
|
671
|
+
index_text: '游戏机制前先查引擎文档',
|
|
672
|
+
status: 'draft',
|
|
673
|
+
signals: { keywords: ['游戏'], fileMarkers: ['project.godot'], pathGlobs: ['games'] },
|
|
674
|
+
})
|
|
675
|
+
check('a draft can be written without a source', drafted.code === 200 && drafted.body.domain?.status === 'draft',
|
|
676
|
+
drafted.body.error ?? drafted.body.domain?.status)
|
|
677
|
+
|
|
678
|
+
const activated = await call(DOMAIN_PATH, 'POST', {
|
|
679
|
+
action: 'status', domain_id: 'game', status: 'active',
|
|
680
|
+
})
|
|
681
|
+
check('approving a pack still needs a source', activated.code === 400, activated.body.error)
|
|
682
|
+
|
|
683
|
+
await call(DOMAIN_PATH, 'POST', {
|
|
684
|
+
action: 'upsert',
|
|
685
|
+
domain_id: 'game',
|
|
686
|
+
name: '游戏',
|
|
687
|
+
index_text: '游戏机制前先查引擎文档',
|
|
688
|
+
status: 'draft',
|
|
689
|
+
sources: [{ title: 'engine docs' }],
|
|
690
|
+
signals: { keywords: ['游戏'], fileMarkers: ['project.godot'], pathGlobs: ['games'] },
|
|
691
|
+
})
|
|
692
|
+
const packApproved = await call(DOMAIN_PATH, 'POST', { action: 'status', domain_id: 'game', status: 'active' })
|
|
693
|
+
check('a sourced pack can be approved', packApproved.code === 200 && packApproved.body.domain?.status === 'active',
|
|
694
|
+
packApproved.body.error ?? packApproved.body.domain?.status)
|
|
695
|
+
|
|
696
|
+
const shelf = await call(DOMAIN_PATH)
|
|
697
|
+
check('the approved pack appears on the shelf',
|
|
698
|
+
shelf.body.domains.some((pack) => pack.domainId === 'game' && pack.status === 'active'))
|
|
699
|
+
|
|
700
|
+
// ── knowledge health ──────────────────────────────────────────────────────
|
|
701
|
+
const health = await call(KNOWLEDGE_PATH)
|
|
702
|
+
check('the knowledge route reports an empty plane before anything was captured',
|
|
703
|
+
health.code === 200 && Array.isArray(health.body.kinds) && health.body.kinds.length === 0
|
|
704
|
+
&& health.body.evidence === 0,
|
|
705
|
+
`kinds=${health.body.kinds?.length} evidence=${health.body.evidence}`)
|
|
706
|
+
check('the health payload carries retrieval rates and promotion counters',
|
|
707
|
+
typeof health.body.retrievals === 'object' && health.body.retrievals !== null
|
|
708
|
+
&& typeof health.body.eligible === 'number' && typeof health.body.promotions === 'number',
|
|
709
|
+
JSON.stringify(health.body.retrievals))
|
|
710
|
+
const knowledgeWrite = await call(KNOWLEDGE_PATH, 'POST', {})
|
|
711
|
+
check('the knowledge plane is read-only', knowledgeWrite.code === 405, knowledgeWrite.body.error)
|
|
712
|
+
|
|
713
|
+
// ── flow timeline ─────────────────────────────────────────────────────────
|
|
714
|
+
const timeline = await call(TIMELINE_PATH)
|
|
715
|
+
check('the timeline merges real events from the store',
|
|
716
|
+
timeline.code === 200 && Array.isArray(timeline.body.events),
|
|
717
|
+
`events=${timeline.body.events?.length}`)
|
|
718
|
+
const timelineWrite = await call(TIMELINE_PATH, 'POST', {})
|
|
719
|
+
check('the timeline is read-only', timelineWrite.code === 405, timelineWrite.body.error)
|
|
720
|
+
|
|
561
721
|
// A read-only panel: the plugin keeps `writeBlock: null`, so the route 403s.
|
|
562
722
|
const readOnlyChildren = []
|
|
563
723
|
applyHost({ ...ctx, inject: (deps, cb) => readOnlyChildren.push({ deps, cb }) }, {
|
|
@@ -581,6 +741,23 @@ try {
|
|
|
581
741
|
{ writeHead(code) { readOnlyStatus.code = code }, end(payload) { readOnlyStatus.body = JSON.parse(payload) } },
|
|
582
742
|
)
|
|
583
743
|
check('the status payload tells the panel it is read-only', readOnlyStatus.body.writable === false)
|
|
744
|
+
// Approving writes a block, so a read-only panel must refuse the decision — and
|
|
745
|
+
// say why — rather than accept one it cannot apply.
|
|
746
|
+
const readOnlyProposal = { code: null, body: null }
|
|
747
|
+
await readOnlyRoutes.get(PROPOSALS_PATH).handler(
|
|
748
|
+
{
|
|
749
|
+
headers: { host: '127.0.0.1:19387' },
|
|
750
|
+
method: 'POST',
|
|
751
|
+
on(event, handler) {
|
|
752
|
+
if (event === 'data') handler(JSON.stringify({ id: 'prop_1', action: 'approve' }))
|
|
753
|
+
if (event === 'end') handler()
|
|
754
|
+
},
|
|
755
|
+
},
|
|
756
|
+
{ writeHead(code) { readOnlyProposal.code = code }, end(payload) { readOnlyProposal.body = JSON.parse(payload) } },
|
|
757
|
+
)
|
|
758
|
+
check('panel.writes:false refuses to approve a proposal',
|
|
759
|
+
readOnlyProposal.code === 403 && /write half/.test(readOnlyProposal.body.error),
|
|
760
|
+
readOnlyProposal.body.error)
|
|
584
761
|
const readOnlyFlush = { code: null, body: null }
|
|
585
762
|
await readOnlyRoutes.get(FLUSH_PATH).handler(
|
|
586
763
|
{ headers: { host: '127.0.0.1:19387' }, method: 'POST' },
|
|
@@ -745,14 +922,22 @@ try {
|
|
|
745
922
|
|
|
746
923
|
const deadline = Date.now() + 90_000
|
|
747
924
|
let diagnostic = null
|
|
925
|
+
let knowledgeDiagnostic = null
|
|
748
926
|
while (Date.now() < deadline) {
|
|
749
|
-
const
|
|
750
|
-
|
|
927
|
+
const list = loadState(windowState).diagnostics ?? []
|
|
928
|
+
// The knowledge channel appends its own entry after the fact run, so the fact
|
|
929
|
+
// outcome is no longer necessarily the last one; scan for each by kind.
|
|
930
|
+
const fact = list.findLast?.((entry) => Number(entry.turns) === 2 && String(entry.outcome).startsWith('ok'))
|
|
931
|
+
const knowledge = list.findLast?.((entry) => String(entry.outcome).startsWith('knowledge'))
|
|
932
|
+
if (fact && knowledge) { diagnostic = fact; knowledgeDiagnostic = knowledge; break }
|
|
751
933
|
await new Promise((resolve) => setTimeout(resolve, 500))
|
|
752
934
|
}
|
|
753
935
|
check('the window was extracted as ONE call covering both turns',
|
|
754
936
|
diagnostic !== null && String(diagnostic.outcome).startsWith('ok'),
|
|
755
937
|
JSON.stringify(diagnostic))
|
|
938
|
+
check('the knowledge channel reports its own outcome for the same window',
|
|
939
|
+
knowledgeDiagnostic !== null && /knowledge (added=\d+|skipped:)/.test(String(knowledgeDiagnostic.outcome)),
|
|
940
|
+
JSON.stringify(knowledgeDiagnostic))
|
|
756
941
|
check('the window is cleared and the watermark advanced past both turns',
|
|
757
942
|
Object.keys(loadState(windowState).pending).length === 0
|
|
758
943
|
&& loadState(windowState).watermarks.get('sess-window') === 4,
|
|
@@ -1249,7 +1434,8 @@ try {
|
|
|
1249
1434
|
check('closing an armed session extracts its window and empties it',
|
|
1250
1435
|
!afterClose.extract.window.pending.some((entry) => entry.sessionId === 'sess-close-test')
|
|
1251
1436
|
&& afterClose.extract.diagnostics.length > beforeClose
|
|
1252
|
-
|
|
1437
|
+
// The knowledge channel adds a second entry with the same turn count, so the
|
|
1438
|
+
&& afterClose.extract.diagnostics.some((entry) => /^(ok|skipped)/.test(String(entry.outcome ?? ''))),
|
|
1253
1439
|
JSON.stringify(afterClose.extract.diagnostics[0] ?? null))
|
|
1254
1440
|
|
|
1255
1441
|
if (previousDb === undefined) delete process.env.DSH_MEMVAULT_CORE_DB
|