@kira905/dsh-memory-toolkit 0.0.0-stage → 0.1.1
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/CHANGELOG.md +42 -0
- package/LICENSE +661 -0
- package/README.en.md +110 -0
- package/README.md +102 -2
- package/dsh-memory-local/FORK-BASE.json +24 -0
- package/dsh-memory-local/README.md +113 -0
- package/dsh-memory-local/build.mjs +101 -0
- package/dsh-memory-local/cordis.patch.yml +20 -0
- package/dsh-memory-local/deploy.mjs +306 -0
- package/dsh-memory-local/entity-status.mjs +75 -0
- package/dsh-memory-local/lib/bridge.mjs +108 -0
- package/dsh-memory-local/lib/host-adapter.js +1171 -0
- package/dsh-memory-local/lib/index.d.ts +128 -0
- package/dsh-memory-local/lib/index.js +944 -0
- package/dsh-memory-local/lib/injector.mjs +400 -0
- package/dsh-memory-local/lib/memory-read.mjs +116 -0
- package/dsh-memory-local/lib/module-gate.mjs +68 -0
- package/dsh-memory-local/lib/pointer.mjs +152 -0
- package/dsh-memory-local/lib/prod-gate.mjs +121 -0
- package/dsh-memory-local/lib/recall-log.mjs +118 -0
- package/dsh-memory-local/lib/recall.mjs +192 -0
- package/dsh-memory-local/lib/schema-migrate.mjs +365 -0
- package/dsh-memory-local/lib/user-message.mjs +32 -0
- package/dsh-memory-local/lib/vectors-read.mjs +110 -0
- package/dsh-memory-local/package.json +51 -0
- package/dsh-memory-local/restore.mjs +259 -0
- package/dsh-memory-local/rollback-injector-fix.mjs +166 -0
- package/dsh-memory-local/src/bridge.mjs +108 -0
- package/dsh-memory-local/src/host-adapter.js +1171 -0
- package/dsh-memory-local/src/index.d.ts +128 -0
- package/dsh-memory-local/src/index.js +944 -0
- package/dsh-memory-local/src/injector.mjs +400 -0
- package/dsh-memory-local/src/memory-read.mjs +116 -0
- package/dsh-memory-local/src/module-gate.mjs +68 -0
- package/dsh-memory-local/src/pointer.mjs +152 -0
- package/dsh-memory-local/src/recall-log.mjs +118 -0
- package/dsh-memory-local/src/recall.mjs +192 -0
- package/dsh-memory-local/src/schema-migrate.mjs +365 -0
- package/dsh-memory-local/src/user-message.mjs +32 -0
- package/dsh-memory-local/src/vectors-read.mjs +110 -0
- package/dsh-memory-local/test/fixtures-s2b.mjs +216 -0
- package/dsh-memory-local/test/probe-entity.mjs +170 -0
- package/dsh-memory-local/test/regression.mjs +270 -0
- package/dsh-memory-local/test/s2b.test.mjs +568 -0
- package/dsh-memory-local/test/schema-migrate.test.mjs +334 -0
- package/dsh-memory-local/test/test-adapter-converge.mjs +127 -0
- package/dsh-memory-local/test/visible-injections.test.mjs +239 -0
- package/dsh-memory-local/verify-after-restart.mjs +181 -0
- package/lib/deploy-guard.mjs +391 -0
- package/lib/guard-http.mjs +93 -0
- package/lib/pitfall-form-map.mjs +130 -0
- package/lib/pitfall-score.mjs +185 -0
- package/lib/session-file-name.mjs +160 -0
- package/lib/zstd-frames.mjs +78 -0
- package/memory-db-tools/README.md +68 -0
- package/memory-db-tools/_test/test-memory-scope.mjs +302 -0
- package/memory-db-tools/audit-analyze.mjs +352 -0
- package/memory-db-tools/audit-dump-ids.mjs +245 -0
- package/memory-db-tools/audit-export.mjs +270 -0
- package/memory-db-tools/audit-hit-probe.mjs +227 -0
- package/memory-db-tools/audit-ledger-probe.mjs +236 -0
- package/memory-db-tools/audit-persona-overlap.mjs +277 -0
- package/memory-db-tools/audit-struct-probe.mjs +213 -0
- package/memory-db-tools/audit-verify-unchanged.mjs +276 -0
- package/memory-db-tools/check-memory-db.mjs +8 -0
- package/memory-db-tools/dump-memory-db.mjs +12 -0
- package/memory-db-tools/lib/memory-scope.mjs +446 -0
- package/memory-db-tools/list-memory-summary.mjs +477 -0
- package/memory-db-tools/memory-identity-check.mjs +101 -0
- package/memory-db-tools/memory-schema-migrate.mjs +290 -0
- package/memory-db-tools/memory-scope-fixture.mjs +197 -0
- package/memory-db-tools/read-memories.mjs +26 -0
- package/memory-db-tools/read-memory-db.mjs +20 -0
- package/memory-db-tools/refine-memories.mjs +247 -0
- package/memory-db-tools/show-mem-times.mjs +22 -0
- package/memory-engine/README.md +70 -0
- package/memory-engine/bench/bench.mjs +221 -0
- package/memory-engine/cli/distill-rollback.mjs +86 -0
- package/memory-engine/cli/distill.mjs +156 -0
- package/memory-engine/cli/doc-index-rebuild.mjs +155 -0
- package/memory-engine/cli/doc-index.mjs +48 -0
- package/memory-engine/cli/domain-tags.mjs +251 -0
- package/memory-engine/cli/pitfall-hook.mjs +91 -0
- package/memory-engine/cli/recall.mjs +132 -0
- package/memory-engine/cli/selfcheck.mjs +57 -0
- package/memory-engine/cli/serve-start.mjs +247 -0
- package/memory-engine/cli/sweep.mjs +58 -0
- package/memory-engine/cli/sync.mjs +69 -0
- package/memory-engine/lib/cli-util.mjs +197 -0
- package/memory-engine/lib/config.mjs +135 -0
- package/memory-engine/lib/dirty-ledger.mjs +174 -0
- package/memory-engine/lib/distill-rollback.mjs +178 -0
- package/memory-engine/lib/distill.mjs +898 -0
- package/memory-engine/lib/doc-index-store.mjs +325 -0
- package/memory-engine/lib/doc-index.mjs +529 -0
- package/memory-engine/lib/doc-scan.mjs +271 -0
- package/memory-engine/lib/doc-summarize.mjs +305 -0
- package/memory-engine/lib/domain-tags.mjs +429 -0
- package/memory-engine/lib/embedder.mjs +242 -0
- package/memory-engine/lib/hashes.mjs +12 -0
- package/memory-engine/lib/memory-source.mjs +127 -0
- package/memory-engine/lib/pitfall-source.mjs +170 -0
- package/memory-engine/lib/policy-source.mjs +371 -0
- package/memory-engine/lib/recall.mjs +331 -0
- package/memory-engine/lib/selfcheck.mjs +131 -0
- package/memory-engine/lib/sweep.mjs +159 -0
- package/memory-engine/lib/sync.mjs +180 -0
- package/memory-engine/lib/tick-hook.mjs +218 -0
- package/memory-engine/lib/vectors-store.mjs +292 -0
- package/memory-engine/package-lock.json +1086 -0
- package/memory-engine/package.json +22 -0
- package/memory-engine/serve.mjs +171 -0
- package/memory-engine/test/01-store.test.mjs +127 -0
- package/memory-engine/test/02-sync.test.mjs +196 -0
- package/memory-engine/test/03-sweep.test.mjs +145 -0
- package/memory-engine/test/04-recall.test.mjs +214 -0
- package/memory-engine/test/05-selfcheck.test.mjs +175 -0
- package/memory-engine/test/06-doc-index.test.mjs +928 -0
- package/memory-engine/test/07-domain-tags.test.mjs +298 -0
- package/memory-engine/test/08-distill.test.mjs +686 -0
- package/memory-engine/test/09-pitfall-source.test.mjs +365 -0
- package/memory-engine/test/10-tick-hook.test.mjs +252 -0
- package/memory-engine/test/11-policy-source.test.mjs +224 -0
- package/memory-engine/test/_tickhook-worker.mjs +56 -0
- package/memory-engine/test/fixtures.mjs +205 -0
- package/memory-engine/test/harness.mjs +73 -0
- package/memory-engine/test/run.mjs +35 -0
- package/memory-engine/tools/bridge-smoke.mjs +80 -0
- package/memory-engine/tools/fetch-model.mjs +128 -0
- package/memory-engine/tools/smoke-recall.mjs +76 -0
- package/package.json +53 -4
- package/persona-memory-audit.mjs +217 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// FORK-EDIT(2026-10-14): R1 解耦 —— 纯类型面一律 `import type`(编译期擦除,不绑运行时符号;
|
|
2
|
+
// 改前这两行是 R1 hard 的另一半)。
|
|
3
|
+
import type z from "@deepseek-ai/schemastery";
|
|
4
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
5
|
+
|
|
6
|
+
//#region src/store.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* SQLite-backed memory store: a plain `memories` table with an external-content
|
|
10
|
+
* FTS5 index kept in sync by triggers. Owned entirely by this package — the
|
|
11
|
+
* harness's own SQLite backends index sessions, not durable user facts.
|
|
12
|
+
* @module dsh-memory/store
|
|
13
|
+
*/
|
|
14
|
+
/** Monotonic on-disk schema version; a mismatch rebuilds the derived index. */
|
|
15
|
+
declare const SCHEMA_VERSION = 1;
|
|
16
|
+
/** One stored memory as tools and the prompt section see it. */
|
|
17
|
+
interface MemoryRecord {
|
|
18
|
+
id: number;
|
|
19
|
+
text: string;
|
|
20
|
+
/** Normalized, space-joined tag list; empty string when untagged. */
|
|
21
|
+
tags: string;
|
|
22
|
+
/** Pinned memories always render in the prompt section, ahead of recent ones. */
|
|
23
|
+
pinned: boolean;
|
|
24
|
+
createdAt: number;
|
|
25
|
+
updatedAt: number;
|
|
26
|
+
}
|
|
27
|
+
/** A search hit: the record plus its FTS rank (lower is a better match). */
|
|
28
|
+
interface MemoryMatch extends MemoryRecord {
|
|
29
|
+
rank: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Normalize a tag list to the lowercase, deduplicated, space-joined form the
|
|
33
|
+
* FTS index stores, so `Foo`, `foo`, and a repeated `foo` all match `foo`.
|
|
34
|
+
* @param tags - tags as supplied by the model or config.
|
|
35
|
+
* @returns the normalized space-joined list, empty when nothing survives.
|
|
36
|
+
*/
|
|
37
|
+
declare function normalizeTags(tags: readonly string[]): string;
|
|
38
|
+
/**
|
|
39
|
+
* Compile a free-text query into an FTS5 MATCH expression. Every token is
|
|
40
|
+
* quoted, so FTS5 operators a model happens to type (`OR`, `*`, `-`, `"`) are
|
|
41
|
+
* matched literally instead of changing the query's meaning or raising a
|
|
42
|
+
* syntax error mid-tool-call.
|
|
43
|
+
* @param query - the raw query text.
|
|
44
|
+
* @returns the MATCH expression, or undefined when the query has no usable token.
|
|
45
|
+
*/
|
|
46
|
+
declare function compileMatch(query: string): string | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* The durable memory store. One instance owns one SQLite connection; `close()`
|
|
49
|
+
* is idempotent and runs from the plugin's disposer.
|
|
50
|
+
*/
|
|
51
|
+
declare class MemoryStore {
|
|
52
|
+
#private;
|
|
53
|
+
/**
|
|
54
|
+
* Open (creating if absent) the store at `path`, applying the schema.
|
|
55
|
+
* @param path - database file path, or `:memory:` for an ephemeral store.
|
|
56
|
+
*/
|
|
57
|
+
constructor(path: string);
|
|
58
|
+
/**
|
|
59
|
+
* Store one memory.
|
|
60
|
+
* @param text - the fact to remember.
|
|
61
|
+
* @param tags - normalized tag list.
|
|
62
|
+
* @param pinned - whether it always renders in the prompt section.
|
|
63
|
+
* @returns the new record.
|
|
64
|
+
*/
|
|
65
|
+
write(text: string, tags: string, pinned: boolean): MemoryRecord;
|
|
66
|
+
/**
|
|
67
|
+
* Full-text search over memory text and tags, best match first.
|
|
68
|
+
* @param query - free-text query; FTS operators in it are matched literally.
|
|
69
|
+
* @param limit - maximum hits to return.
|
|
70
|
+
* @returns the ranked matches, empty when the query has no usable token.
|
|
71
|
+
*/
|
|
72
|
+
search(query: string, limit: number): MemoryMatch[];
|
|
73
|
+
/**
|
|
74
|
+
* The memories the prompt section renders: pinned first, then most recently
|
|
75
|
+
* updated, with no record repeated.
|
|
76
|
+
* @param recentCount - how many unpinned recent memories to include.
|
|
77
|
+
* @returns pinned records followed by recent ones.
|
|
78
|
+
*/
|
|
79
|
+
forPrompt(recentCount: number): MemoryRecord[];
|
|
80
|
+
/**
|
|
81
|
+
* Delete one memory.
|
|
82
|
+
* @param id - the record id.
|
|
83
|
+
* @returns whether a record was deleted.
|
|
84
|
+
*/
|
|
85
|
+
forget(id: number): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Total stored memories.
|
|
88
|
+
* @returns the row count.
|
|
89
|
+
*/
|
|
90
|
+
count(): number;
|
|
91
|
+
/** Close the connection; idempotent, so plugin disposal and tests may both call it. */
|
|
92
|
+
close(): void;
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/index.d.ts
|
|
96
|
+
declare const name = "memory";
|
|
97
|
+
declare const inject: string[];
|
|
98
|
+
/** Plugin config. Every bound is a field: none of these are safe to hardcode across deployments. */
|
|
99
|
+
interface Config {
|
|
100
|
+
/**
|
|
101
|
+
* SQLite file for this deployment's memories, or `:memory:` for an ephemeral
|
|
102
|
+
* store. Required: a code-side default would silently scatter durable user
|
|
103
|
+
* facts into whatever directory the harness happened to start in. The shipped
|
|
104
|
+
* bundle patch supplies `dshHomePath('memory/memory.db')`.
|
|
105
|
+
*/
|
|
106
|
+
path: string;
|
|
107
|
+
/** Unpinned recent memories rendered in the prompt section. */
|
|
108
|
+
promptRecentCount: number;
|
|
109
|
+
/** Cap on the rendered prompt section; memories past it are dropped, pinned ones first to survive. */
|
|
110
|
+
promptMaxChars: number;
|
|
111
|
+
/** Maximum characters accepted for one memory. */
|
|
112
|
+
maxTextChars: number;
|
|
113
|
+
/** Default `limit` for `memory_search` when the model omits it. */
|
|
114
|
+
searchLimitDefault: number;
|
|
115
|
+
/** Hard cap on `memory_search` results, whatever the model asks for. */
|
|
116
|
+
searchLimitMax: number;
|
|
117
|
+
/** Prompt-section order; `-100` is the harness identity and `0` the persona. */
|
|
118
|
+
promptOrder: number;
|
|
119
|
+
}
|
|
120
|
+
declare const Config: z<Config>;
|
|
121
|
+
/**
|
|
122
|
+
* Open the store, register the three tools, and contribute the recall section.
|
|
123
|
+
* @param ctx - plugin context; the store, tools, and section are disposed with it.
|
|
124
|
+
* @param config - validated {@link Config}.
|
|
125
|
+
*/
|
|
126
|
+
declare function apply(ctx: Context, config: Config): void;
|
|
127
|
+
//#endregion
|
|
128
|
+
export { Config, MemoryMatch, MemoryRecord, MemoryStore, SCHEMA_VERSION, apply, compileMatch, inject, name, normalizeTags };
|