dsh-memvault 0.10.1 → 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 +60 -24
- package/README.zh.md +70 -34
- package/cordis.patch.yml +23 -0
- package/docs/CORE-DESIGN.md +9 -0
- package/docs/DEVLOG.md +607 -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 +1 -1
- package/scripts/seed-domains.mjs +171 -0
- package/scripts/smoke-panel.mjs +200 -14
- package/src/client/index.js +629 -10
package/lib/config.js
CHANGED
|
@@ -18,6 +18,7 @@ import { statSync } from 'node:fs'
|
|
|
18
18
|
import { homedir } from 'node:os'
|
|
19
19
|
import { fileURLToPath } from 'node:url'
|
|
20
20
|
import { DEFAULT_SCOPES } from './blocks.js'
|
|
21
|
+
import { DEFAULT_GATED_TOOLS } from './gate.js'
|
|
21
22
|
import { DEFAULT_STATE_PATH } from './extract.js'
|
|
22
23
|
|
|
23
24
|
/** This package's own root — used as one place to look for a sibling checkout. */
|
|
@@ -240,6 +241,71 @@ export const CONFIG_SPEC = {
|
|
|
240
241
|
default: false,
|
|
241
242
|
description: 'Ship tool calls and results too. Off by default: they eat the budget and carry little user signal.',
|
|
242
243
|
},
|
|
244
|
+
knowledge: {
|
|
245
|
+
kind: 'object',
|
|
246
|
+
default: {},
|
|
247
|
+
description: 'The six tacit-knowledge classes (rationale/contract/failure/dependency/solution/persona): '
|
|
248
|
+
+ 'its own prompt, its own budget, its own tables. Off leaves fact extraction untouched.',
|
|
249
|
+
fields: {
|
|
250
|
+
enabled: {
|
|
251
|
+
kind: 'boolean',
|
|
252
|
+
default: true,
|
|
253
|
+
description: 'Run the knowledge channel on each extraction window.',
|
|
254
|
+
},
|
|
255
|
+
includeAssistant: {
|
|
256
|
+
kind: 'boolean',
|
|
257
|
+
default: true,
|
|
258
|
+
description: 'Read assistant prose. This is the only place the reasons and abandoned options are written down; '
|
|
259
|
+
+ 'the fact channel keeps it off for the opposite reason.',
|
|
260
|
+
},
|
|
261
|
+
includeTools: {
|
|
262
|
+
kind: 'boolean',
|
|
263
|
+
default: true,
|
|
264
|
+
description: 'Read tool calls and results: failure modes, fix paths and couplings live there.',
|
|
265
|
+
},
|
|
266
|
+
maxInputChars: {
|
|
267
|
+
kind: 'number',
|
|
268
|
+
integer: true,
|
|
269
|
+
min: 1000,
|
|
270
|
+
max: 20_000,
|
|
271
|
+
step: 500,
|
|
272
|
+
role: 'slider',
|
|
273
|
+
default: 8000,
|
|
274
|
+
description: 'Budget for the knowledge transcript, independent of the fact channel’s.',
|
|
275
|
+
},
|
|
276
|
+
promotion: {
|
|
277
|
+
kind: 'object',
|
|
278
|
+
default: {},
|
|
279
|
+
description: 'When a retrieved piece of knowledge earns a proposal for the always-injected block. '
|
|
280
|
+
+ 'Promotion never writes: it produces a proposal a human must approve.',
|
|
281
|
+
fields: {
|
|
282
|
+
enabled: {
|
|
283
|
+
kind: 'boolean',
|
|
284
|
+
default: true,
|
|
285
|
+
description: 'Look for promotion candidates after each extraction window.',
|
|
286
|
+
},
|
|
287
|
+
minUsed: {
|
|
288
|
+
kind: 'number',
|
|
289
|
+
integer: true,
|
|
290
|
+
min: 1,
|
|
291
|
+
max: 100,
|
|
292
|
+
step: 1,
|
|
293
|
+
default: 3,
|
|
294
|
+
description: 'How often it must have been retrieved before it can be promoted.',
|
|
295
|
+
},
|
|
296
|
+
minEvidence: {
|
|
297
|
+
kind: 'number',
|
|
298
|
+
integer: true,
|
|
299
|
+
min: 1,
|
|
300
|
+
max: 20,
|
|
301
|
+
step: 1,
|
|
302
|
+
default: 2,
|
|
303
|
+
description: 'How many independent pieces of evidence it needs.',
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
},
|
|
243
309
|
maxInputChars: {
|
|
244
310
|
kind: 'number',
|
|
245
311
|
integer: true,
|
|
@@ -285,6 +351,147 @@ export const CONFIG_SPEC = {
|
|
|
285
351
|
},
|
|
286
352
|
},
|
|
287
353
|
},
|
|
354
|
+
domain: {
|
|
355
|
+
kind: 'object',
|
|
356
|
+
default: {},
|
|
357
|
+
description: 'Vertical domain packs: background knowledge loaded only while a pack applies. '
|
|
358
|
+
+ 'Packs live in the store; this block governs activation and the segment budget.',
|
|
359
|
+
fields: {
|
|
360
|
+
enabled: {
|
|
361
|
+
kind: 'boolean',
|
|
362
|
+
default: true,
|
|
363
|
+
description: 'Inject the second context segment while a pack is active. Off leaves core-block injection untouched.',
|
|
364
|
+
},
|
|
365
|
+
name: {
|
|
366
|
+
kind: 'string',
|
|
367
|
+
default: 'memvault:domain',
|
|
368
|
+
description: 'Name of the domain context contribution.',
|
|
369
|
+
},
|
|
370
|
+
order: {
|
|
371
|
+
kind: 'number',
|
|
372
|
+
integer: true,
|
|
373
|
+
default: 215,
|
|
374
|
+
description: 'Order after the core blocks (210) so the core stays first in the snapshot.',
|
|
375
|
+
},
|
|
376
|
+
maxDomains: {
|
|
377
|
+
kind: 'number',
|
|
378
|
+
integer: true,
|
|
379
|
+
min: 1,
|
|
380
|
+
max: 4,
|
|
381
|
+
default: 2,
|
|
382
|
+
description: 'How many packs may be injected at once. Two is what a person can hold; more reads as a manual.',
|
|
383
|
+
},
|
|
384
|
+
indexChars: {
|
|
385
|
+
kind: 'number',
|
|
386
|
+
integer: true,
|
|
387
|
+
min: 100,
|
|
388
|
+
max: 600,
|
|
389
|
+
default: 480,
|
|
390
|
+
description: 'Per-pack budget for the injected index line. Detail stays out and is read on demand.',
|
|
391
|
+
},
|
|
392
|
+
maxChars: {
|
|
393
|
+
kind: 'number',
|
|
394
|
+
integer: true,
|
|
395
|
+
min: 120,
|
|
396
|
+
max: 2000,
|
|
397
|
+
default: 1000,
|
|
398
|
+
description: 'Budget for the whole domain segment, header included.',
|
|
399
|
+
},
|
|
400
|
+
probeDir: {
|
|
401
|
+
kind: 'string',
|
|
402
|
+
default: '',
|
|
403
|
+
description: 'Workspace directory whose marker files and package.json are probed. '
|
|
404
|
+
+ 'Empty disables file evidence: only keywords, tool arguments and explicit activation apply.',
|
|
405
|
+
},
|
|
406
|
+
thresholdPct: {
|
|
407
|
+
kind: 'number',
|
|
408
|
+
integer: true,
|
|
409
|
+
min: 0,
|
|
410
|
+
max: 500,
|
|
411
|
+
step: 5,
|
|
412
|
+
role: 'slider',
|
|
413
|
+
default: 100,
|
|
414
|
+
description: 'Score at which a pack activates automatically, in percent (100 = 1.0). '
|
|
415
|
+
+ 'A wrong pack injects wrong rules, so this is high on purpose; path + one marker file scores 110.',
|
|
416
|
+
},
|
|
417
|
+
refreshMs: {
|
|
418
|
+
kind: 'number',
|
|
419
|
+
integer: true,
|
|
420
|
+
min: 0,
|
|
421
|
+
step: 1000,
|
|
422
|
+
default: 10_000,
|
|
423
|
+
description: 'TTL of the activation decision. Shorter than the core TTL because the workspace can change mid-session.',
|
|
424
|
+
},
|
|
425
|
+
draftHint: {
|
|
426
|
+
kind: 'boolean',
|
|
427
|
+
default: true,
|
|
428
|
+
description: 'Append one line to the domain segment telling the model it may draft a pack with domain_draft. '
|
|
429
|
+
+ 'Off keeps the segment purely informational; the line is omitted anyway when the shelf is full or nothing is injected.',
|
|
430
|
+
},
|
|
431
|
+
maxPacks: {
|
|
432
|
+
kind: 'number',
|
|
433
|
+
integer: true,
|
|
434
|
+
min: 1,
|
|
435
|
+
max: 200,
|
|
436
|
+
step: 1,
|
|
437
|
+
default: 20,
|
|
438
|
+
description: 'How many packs may exist before the model may no longer draft new ones. A full shelf means a human should review what is there.',
|
|
439
|
+
},
|
|
440
|
+
gate: {
|
|
441
|
+
kind: 'object',
|
|
442
|
+
default: {},
|
|
443
|
+
description: 'Gates: preconditions a pack declares for action tools, enforced with ctx.tools.guard(). '
|
|
444
|
+
+ 'This is the only part of the plugin that can refuse a call rather than ask for it.',
|
|
445
|
+
fields: {
|
|
446
|
+
enabled: {
|
|
447
|
+
kind: 'boolean',
|
|
448
|
+
default: true,
|
|
449
|
+
description: 'Register the synchronous guard. Off turns gates back into advisory text.',
|
|
450
|
+
},
|
|
451
|
+
tools: {
|
|
452
|
+
kind: 'array',
|
|
453
|
+
default: DEFAULT_GATED_TOOLS,
|
|
454
|
+
description: 'Tools refused while a gate is open. Read-only tools must not be listed, '
|
|
455
|
+
+ 'or the gate blocks the research it asks for.',
|
|
456
|
+
of: { kind: 'string' },
|
|
457
|
+
},
|
|
458
|
+
blockBashWrites: {
|
|
459
|
+
kind: 'boolean',
|
|
460
|
+
default: true,
|
|
461
|
+
description: 'Also refuse a guarded bash call when the command looks like a write '
|
|
462
|
+
+ '(redirection, tee, rm, npm install, git commit…). Reads stay allowed.',
|
|
463
|
+
},
|
|
464
|
+
minQuote: {
|
|
465
|
+
kind: 'number',
|
|
466
|
+
integer: true,
|
|
467
|
+
min: 0,
|
|
468
|
+
max: 2000,
|
|
469
|
+
step: 10,
|
|
470
|
+
default: 40,
|
|
471
|
+
description: 'Shortest acceptable evidence quote, in characters. Long enough that it had to come from a document.',
|
|
472
|
+
},
|
|
473
|
+
maxAgeHours: {
|
|
474
|
+
kind: 'number',
|
|
475
|
+
integer: true,
|
|
476
|
+
min: 1,
|
|
477
|
+
max: 8760,
|
|
478
|
+
step: 1,
|
|
479
|
+
default: 24,
|
|
480
|
+
description: 'How long a piece of evidence stays valid before it has to be re-checked.',
|
|
481
|
+
},
|
|
482
|
+
noticeChars: {
|
|
483
|
+
kind: 'number',
|
|
484
|
+
integer: true,
|
|
485
|
+
min: 80,
|
|
486
|
+
max: 800,
|
|
487
|
+
step: 20,
|
|
488
|
+
default: 240,
|
|
489
|
+
description: 'Budget for the one-line gate notice inside the domain segment.',
|
|
490
|
+
},
|
|
491
|
+
},
|
|
492
|
+
},
|
|
493
|
+
},
|
|
494
|
+
},
|
|
288
495
|
}
|
|
289
496
|
|
|
290
497
|
/** The default for one spec node: leaves return their default, objects recurse. */
|
package/lib/core/block-write.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Core block writes
|
|
2
|
+
* Core block writes: the one function that changes `blocks`.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
4
|
+
* Two callers — the panel's direct edit and an approved proposal — must be
|
|
5
|
+
* indistinguishable in what they leave behind: the new value, one history row
|
|
6
|
+
* with the before-image, and nothing else. Two writers would mean two audit
|
|
7
|
+
* trails and, eventually, a block whose history has a gap.
|
|
8
|
+
*
|
|
9
|
+
* The write also carries the *reason* it happened (`actor`) and, for approvals,
|
|
10
|
+
* the proposal it came from, because "who changed this and why" is the whole
|
|
11
|
+
* point of keeping a history table at all.
|
|
10
12
|
*/
|
|
11
|
-
|
|
12
13
|
/** Hard cap on a block value. */
|
|
13
14
|
export const BLOCK_VALUE_MAX = 8000
|
|
14
15
|
|
|
@@ -63,23 +64,75 @@ export function validateBlockAction(input = {}) {
|
|
|
63
64
|
return { ok: true, action, type, id, label, value, limit }
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Apply one block change and record it. The only writer of `blocks` in the plugin.
|
|
69
|
+
*
|
|
70
|
+
* @param {object} options
|
|
71
|
+
* @param {object} options.store - an open `CoreStore`.
|
|
72
|
+
* @param {string} options.scopeType - `user` | `agent`.
|
|
73
|
+
* @param {string} options.scopeId
|
|
74
|
+
* @param {string} options.label
|
|
75
|
+
* @param {'set'|'delete'} options.action
|
|
76
|
+
* @param {string} [options.value] - required for `set`.
|
|
77
|
+
* @param {number} [options.valueLimit]
|
|
78
|
+
* @param {number} [options.position] - preserved on rollback so ordering survives.
|
|
79
|
+
* @param {string} [options.actor] - `panel` | `human:approve` | `human:rollback`.
|
|
80
|
+
* @param {string|null} [options.proposalId]
|
|
81
|
+
* @returns `{ ok, action, before, after, row }`.
|
|
82
|
+
*/
|
|
83
|
+
export function commitBlock({
|
|
84
|
+
store,
|
|
85
|
+
scopeType,
|
|
86
|
+
scopeId,
|
|
87
|
+
label,
|
|
88
|
+
action,
|
|
89
|
+
value = '',
|
|
90
|
+
valueLimit = 2000,
|
|
91
|
+
position = 0,
|
|
92
|
+
actor = 'panel',
|
|
93
|
+
proposalId = null,
|
|
94
|
+
historyAction = null,
|
|
95
|
+
at = null,
|
|
96
|
+
} = {}) {
|
|
97
|
+
if (!store) throw new Error('commitBlock needs a store')
|
|
98
|
+
const before = store.getBlock({ scopeType, scopeId, label }) ?? null
|
|
99
|
+
|
|
100
|
+
return store.transaction(() => {
|
|
101
|
+
let row = null
|
|
102
|
+
if (action === 'delete') {
|
|
103
|
+
store.db.prepare('DELETE FROM blocks WHERE scope_type = ? AND scope_id = ? AND label = ?')
|
|
104
|
+
.run(scopeType, scopeId, label)
|
|
105
|
+
} else {
|
|
106
|
+
row = store.setBlock({ scopeType, scopeId, label, value, valueLimit, position })
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// `set` means "there was nothing here", `update` means "this replaced a
|
|
110
|
+
// value". The distinction is what lets a reviewer see a creation apart from
|
|
111
|
+
// an edit without diffing two snapshots. A rollback looks like an update but
|
|
112
|
+
// must read as `rollback`, or the history cannot answer "was this undone?".
|
|
113
|
+
const recordedAction = historyAction ?? (action === 'delete' ? 'delete' : (before ? 'update' : 'set'))
|
|
114
|
+
store.appendBlockHistory({ before, after: row ?? undefined, action: recordedAction, actor, proposalId, at })
|
|
115
|
+
|
|
116
|
+
return { ok: true, action, before, after: row ?? undefined, row }
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
|
|
66
120
|
export async function runBlockActionCore({ store, input } = {}) {
|
|
67
121
|
const valid = validateBlockAction(input)
|
|
68
122
|
if (!valid.ok) return { ok: false, status: 400, error: valid.error }
|
|
69
123
|
|
|
70
|
-
|
|
71
|
-
store
|
|
72
|
-
'DELETE FROM blocks WHERE scope_type = ? AND scope_id = ? AND label = ?',
|
|
73
|
-
).run(valid.type, valid.id, valid.label)
|
|
74
|
-
return { ok: true, status: 200, action: 'delete', result: { deleted: true } }
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const block = store.setBlock({
|
|
124
|
+
const out = commitBlock({
|
|
125
|
+
store,
|
|
78
126
|
scopeType: valid.type,
|
|
79
127
|
scopeId: valid.id,
|
|
80
128
|
label: valid.label,
|
|
129
|
+
action: valid.action,
|
|
81
130
|
value: valid.value,
|
|
82
131
|
valueLimit: valid.limit ?? 2000,
|
|
132
|
+
actor: 'panel',
|
|
83
133
|
})
|
|
84
|
-
|
|
134
|
+
if (valid.action === 'delete') {
|
|
135
|
+
return { ok: true, status: 200, action: 'delete', result: { deleted: true } }
|
|
136
|
+
}
|
|
137
|
+
return { ok: true, status: 200, action: 'set', result: out.row }
|
|
85
138
|
}
|
package/lib/core/host.js
CHANGED
|
@@ -20,19 +20,25 @@ import { registerTools } from './tools.js'
|
|
|
20
20
|
/**
|
|
21
21
|
* Default location of the in-plugin store: the same database the prompt reads
|
|
22
22
|
* (`blocks.js`), so "what is injected" and "what the tools search" cannot drift.
|
|
23
|
-
* `
|
|
23
|
+
* One resolution lives in `blocks.js` now; this is an alias so existing imports
|
|
24
|
+
* and the documented `DSH_MEMVAULT_CORE_DB` override keep working.
|
|
24
25
|
*/
|
|
25
|
-
export const DEFAULT_CORE_DB =
|
|
26
|
+
export const DEFAULT_CORE_DB = DEFAULT_DB_PATH
|
|
26
27
|
|
|
27
28
|
export function attachMemoryTools(ctx, {
|
|
28
|
-
storePath =
|
|
29
|
+
storePath = DEFAULT_CORE_DB,
|
|
29
30
|
projectDir = '',
|
|
30
31
|
logger = null,
|
|
31
32
|
// Resolved the same way the Python engine resolved it: the project `.env`
|
|
32
33
|
// selects the OpenAI-compatible endpoint when a key is present, otherwise the
|
|
33
34
|
// offline hashing embedder keeps a fresh install working with no key.
|
|
35
|
+
// `index.js` passes the pipeline's embedder in, so extraction and `memory_add`
|
|
36
|
+
// cannot end up writing two different `model` rows for the same vector space.
|
|
34
37
|
embedder = null,
|
|
35
38
|
adjudicator = null,
|
|
39
|
+
// Reads the text currently injected for the prompt. The search tool uses it to
|
|
40
|
+
// record whether the memory it returned was already in front of the model.
|
|
41
|
+
injectedText = null,
|
|
36
42
|
} = {}) {
|
|
37
43
|
if (!ctx || (typeof ctx.inject !== 'function' && typeof ctx.get !== 'function')) {
|
|
38
44
|
throw new Error('ctx.inject or ctx.get is required')
|
|
@@ -53,7 +59,12 @@ export function attachMemoryTools(ctx, {
|
|
|
53
59
|
toolCtx.effect(() => {
|
|
54
60
|
let dispose = null
|
|
55
61
|
try {
|
|
56
|
-
dispose = registerTools(tools, store, {
|
|
62
|
+
dispose = registerTools(tools, store, {
|
|
63
|
+
logger,
|
|
64
|
+
embedder: effectiveEmbedder,
|
|
65
|
+
adjudicator: effectiveAdjudicator,
|
|
66
|
+
injectedText,
|
|
67
|
+
})
|
|
57
68
|
} catch (error) {
|
|
58
69
|
logger?.warn?.('dsh-memvault: memory tools could not be registered', error)
|
|
59
70
|
}
|