@chenhw7/dsh-memory 0.9.0 → 0.9.2
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.i18n.yaml +2 -2
- package/README.md +70 -20
- package/README.zh.md +70 -20
- package/cordis.patch.yml +11 -4
- package/lib/benchmark/index.d.ts +1 -1
- package/lib/benchmark/index.d.ts.map +1 -1
- package/lib/client/index.js +388 -58
- package/lib/context/index.d.ts +93 -18
- package/lib/context/index.d.ts.map +1 -1
- package/lib/context/index.js +331 -71
- package/lib/context/index.js.map +1 -1
- package/lib/context/policy.d.ts +72 -11
- package/lib/context/policy.d.ts.map +1 -1
- package/lib/context/policy.js +250 -16
- package/lib/context/policy.js.map +1 -1
- package/lib/identity/index.d.ts +74 -0
- package/lib/identity/index.d.ts.map +1 -0
- package/lib/identity/index.js +150 -0
- package/lib/identity/index.js.map +1 -0
- package/lib/identity/seeds.d.ts +52 -0
- package/lib/identity/seeds.d.ts.map +1 -0
- package/lib/identity/seeds.js +130 -0
- package/lib/identity/seeds.js.map +1 -0
- package/lib/identity/settings.d.ts +32 -0
- package/lib/identity/settings.d.ts.map +1 -0
- package/lib/identity/settings.js +33 -0
- package/lib/identity/settings.js.map +1 -0
- package/lib/index.d.ts +53 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +62 -1
- package/lib/index.js.map +1 -1
- package/lib/notes/index.d.ts +5 -2
- package/lib/notes/index.d.ts.map +1 -1
- package/lib/notes/index.js +26 -14
- package/lib/notes/index.js.map +1 -1
- package/lib/notes/render.d.ts +15 -3
- package/lib/notes/render.d.ts.map +1 -1
- package/lib/notes/render.js +110 -27
- package/lib/notes/render.js.map +1 -1
- package/lib/notes/settings.d.ts +27 -14
- package/lib/notes/settings.d.ts.map +1 -1
- package/lib/notes/settings.js +42 -13
- package/lib/notes/settings.js.map +1 -1
- package/lib/remote/index.d.ts +83 -1
- package/lib/remote/index.d.ts.map +1 -1
- package/lib/remote/index.js +93 -2
- package/lib/remote/index.js.map +1 -1
- package/lib/remote/typert.remote-client.d.ts +29 -1
- package/lib/remote/typert.remote-client.js +19 -0
- package/lib/remote/types.d.ts +1 -1
- package/lib/remote/types.d.ts.map +1 -1
- package/lib/review/extract.d.ts +12 -1
- package/lib/review/extract.d.ts.map +1 -1
- package/lib/review/extract.js +72 -2
- package/lib/review/extract.js.map +1 -1
- package/lib/store/identity-util.d.ts +12 -0
- package/lib/store/identity-util.d.ts.map +1 -0
- package/lib/store/identity-util.js +19 -0
- package/lib/store/identity-util.js.map +1 -0
- package/lib/store/index.d.ts +64 -13
- package/lib/store/index.d.ts.map +1 -1
- package/lib/store/index.js +262 -28
- package/lib/store/index.js.map +1 -1
- package/lib/store/sqlite.d.ts +24 -7
- package/lib/store/sqlite.d.ts.map +1 -1
- package/lib/store/sqlite.js +181 -13
- package/lib/store/sqlite.js.map +1 -1
- package/lib/tool/index.d.ts +4 -11
- package/lib/tool/index.d.ts.map +1 -1
- package/lib/tool/index.js +117 -3
- package/lib/tool/index.js.map +1 -1
- package/lib/types.d.ts +90 -2
- package/lib/types.d.ts.map +1 -1
- package/package.json +5 -1
package/lib/context/index.d.ts
CHANGED
|
@@ -1,17 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* System-prompt memory context injection and the `memory` settings namespace.
|
|
3
3
|
*
|
|
4
|
-
* This function plugin contributes
|
|
5
|
-
*
|
|
4
|
+
* This function plugin contributes four system-prompt sections: `memory` at
|
|
5
|
+
* order 6000 and `project-notes` at 6001 — after the host's tool guidance
|
|
6
|
+
* (SECTION_ORDERS TOOL_* 1000–2900, TOOLS_SDK 5000) and before
|
|
7
|
+
* DELIVERABLE_FILE_REFERENCES (9000), so a compaction re-freeze that changes
|
|
8
|
+
* the memory/notes text no longer invalidates the prefix cache of every tool
|
|
9
|
+
* section behind it (the OpenClaw CONTEXT_FILE_ORDER lesson: most-volatile
|
|
10
|
+
* data last, closest to the cache boundary) — and — when the identity layer
|
|
11
|
+
* is enabled — `soul` at 80 and `user-profile` at 81 (after the host's
|
|
12
|
+
* deployment persona at order 0). On `session/created` it reads a frozen
|
|
6
13
|
* snapshot of recalled memory from the optional `ctx.memory` store (global,
|
|
7
14
|
* project, and user scopes) and freezes it per session so a running session
|
|
8
15
|
* reuses the same recalled content across steps, preserving KV-cache prefix
|
|
9
16
|
* stability. The section text is rebuilt at each assembly from the live
|
|
10
17
|
* settings mode and the session's frozen snapshot.
|
|
11
18
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
19
|
+
* In `digest` mode (the default) the sections carry only frozen guidance;
|
|
20
|
+
* the data rides as step-tail messages: a one-time `<memory-digest>` store
|
|
21
|
+
* inventory appended to the session's first pre-step (re-appended once after
|
|
22
|
+
* compaction) and, when auto recall is on, per-step `<recalled-memory>`
|
|
23
|
+
* fences of BM25 hits — both merged into at most one plugin message per step,
|
|
24
|
+
* so the frozen prefix itself never changes mid-session.
|
|
25
|
+
*
|
|
26
|
+
* The memory-family settings namespaces are registered through `ctx.settings`,
|
|
27
|
+
* one per plugin-configuration card (`memory`, `memory-notes`,
|
|
28
|
+
* `memory-autorecall`, `memory-identity`): the harness's plugins tab dispatches
|
|
29
|
+
* a card only when its slot key names a namespace the Host serves, so each
|
|
30
|
+
* card's key IS its namespace here. All are `applies: 'live'` — a change takes
|
|
31
|
+
* effect on the next assembly without a restart. The composition config stays
|
|
32
|
+
* one full shape, and each namespace's base layer projects its slice from it.
|
|
15
33
|
*
|
|
16
34
|
* @module @chenhw7/dsh-memory/context
|
|
17
35
|
*/
|
|
@@ -20,26 +38,42 @@ import z from '@deepseek-ai/schemastery';
|
|
|
20
38
|
import type { MemoryEntry, MemoryId } from '../types.ts';
|
|
21
39
|
import type { MemoryStore } from '../index.ts';
|
|
22
40
|
import { type MemoryMode } from './policy.ts';
|
|
23
|
-
export { buildMemorySectionText, buildAutoRecallBlock, renderMemoryIndex, MEMORY_POLICY_TEXT, MEMORY_CONTEXT_NOTE, MEMORY_INDEX_NOTE, AUTO_RECALL_NOTE } from './policy.ts';
|
|
24
|
-
export { buildNotesSectionText, PROJECT_NOTES_NOTE } from './policy.ts';
|
|
41
|
+
export { buildMemorySectionText, buildAutoRecallBlock, buildMemoryDigestText, renderMemoryIndex, MEMORY_POLICY_TEXT, MEMORY_DIGEST_POLICY_HINT, MEMORY_CONTEXT_NOTE, MEMORY_INDEX_NOTE, AUTO_RECALL_NOTE } from './policy.ts';
|
|
42
|
+
export { buildNotesSectionText, buildSoulSectionText, buildUserProfileSectionText, PROJECT_NOTES_NOTE, SOUL_NOTE, USER_PROFILE_NOTE } from './policy.ts';
|
|
25
43
|
export type { MemoryMode, IndexEntry } from './policy.ts';
|
|
26
44
|
/** Cordis plugin name. */
|
|
27
45
|
export declare const name = "memory-context";
|
|
28
46
|
/** The prompt registry is required; settings and memory are optional. */
|
|
29
47
|
export declare const inject: string[];
|
|
30
48
|
/**
|
|
31
|
-
* The
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* and the user settings
|
|
49
|
+
* The memory-family settings shape, validated by the same-named schemastery
|
|
50
|
+
* schemas and doubling as the plugin's `cordis.yml` config. The composition
|
|
51
|
+
* config stays ONE full shape; the four settings namespaces project their
|
|
52
|
+
* slices from it as each namespace's `base` layer, and the user settings
|
|
53
|
+
* document overlays each slice in its own section. Every field is optional in
|
|
54
|
+
* yml; the schema defaults supply the rest.
|
|
55
|
+
*
|
|
56
|
+
* The split follows the host's plugin-card contract (one card per served
|
|
57
|
+
* namespace), so the slice boundaries are the card boundaries:
|
|
58
|
+
* `MemoryInjectionConfig` → the curated memory card / `memory` namespace,
|
|
59
|
+
* `MemoryNotesConfig` → the Project Notes card / `memory-notes`,
|
|
60
|
+
* `MemoryAutoRecallConfig` → the Auto Recall card / `memory-autorecall`,
|
|
61
|
+
* `MemoryIdentityConfig` → the Identity card / `memory-identity`.
|
|
35
62
|
*/
|
|
36
|
-
export interface
|
|
37
|
-
/** How recalled memory reaches the system prompt; defaults to `
|
|
63
|
+
export interface MemoryInjectionConfig {
|
|
64
|
+
/** How recalled memory reaches the system prompt; defaults to `digest` (a one-time inventory message + per-step recall fences, nothing resident). */
|
|
38
65
|
memoryMode: MemoryMode;
|
|
39
66
|
/** User-supplied custom policy text, used only when `memoryMode` is `custom`. */
|
|
40
67
|
memoryPolicyCustomText?: string;
|
|
41
68
|
/** Character budget for the frozen memory content snapshot; defaults to `5000`. */
|
|
42
69
|
memoryCharLimit: number;
|
|
70
|
+
/**
|
|
71
|
+
* Character budget for the one-time `<memory-digest>` inventory message in
|
|
72
|
+
* `digest` mode (≈250 tokens at the 4-chars/token estimate; CJK topics run
|
|
73
|
+
* higher). `0` disables the digest message while keeping the mode's section
|
|
74
|
+
* guidance. Defaults to `800`.
|
|
75
|
+
*/
|
|
76
|
+
memoryDigestCharLimit: number;
|
|
43
77
|
/**
|
|
44
78
|
* Maximum number of entries injected into the memory snapshot regardless of
|
|
45
79
|
* the character budget (P0-6). Entries beyond this count are rolled up into
|
|
@@ -50,13 +84,33 @@ export interface MemoryConfig {
|
|
|
50
84
|
maxSearchResults: number;
|
|
51
85
|
/** Days without recall before a project-scoped entry is decayed by the janitor. `0` = disabled. Defaults to `30`. */
|
|
52
86
|
decayDays: number;
|
|
87
|
+
}
|
|
88
|
+
export interface MemoryNotesConfig {
|
|
53
89
|
/** Enable the `project-notes` prompt section; defaults to `true`. */
|
|
54
90
|
notesEnabled: boolean;
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Character budget for the rendered conventions half of the notes section.
|
|
93
|
+
* Absent inherits the resolver default (`1600`); the deprecated combined
|
|
94
|
+
* `notesCharLimit` derives it (60%) when it is the only key set.
|
|
95
|
+
*/
|
|
96
|
+
notesConventionsCharLimit?: number;
|
|
97
|
+
/**
|
|
98
|
+
* Character budget for the rendered pitfalls half of the notes section.
|
|
99
|
+
* Absent inherits the resolver default (`800`); the deprecated combined
|
|
100
|
+
* `notesCharLimit` derives it (40%) when it is the only key set.
|
|
101
|
+
*/
|
|
102
|
+
notesPitfallsCharLimit?: number;
|
|
103
|
+
/** Max entries selected into the notes section (the rest fold into count lines); defaults to `100`. */
|
|
58
104
|
notesMaxEntriesPerFile: number;
|
|
59
|
-
|
|
105
|
+
}
|
|
106
|
+
export interface MemoryAutoRecallConfig {
|
|
107
|
+
/**
|
|
108
|
+
* Append a fenced auto-recall block to each step's messages (BM25 over the
|
|
109
|
+
* store). Defaults to `true` — the digest-mode complement: the digest says
|
|
110
|
+
* WHAT is stored (once per session), the fence recalls WHAT it says (per
|
|
111
|
+
* step, at the step tail). Fence hits stamp `lastRecalledAt` only, never
|
|
112
|
+
* `accessCount`.
|
|
113
|
+
*/
|
|
60
114
|
autoRecallEnabled: boolean;
|
|
61
115
|
/** Max entries in one auto-recall fence; defaults to `5`. */
|
|
62
116
|
autoRecallLimit: number;
|
|
@@ -78,7 +132,28 @@ export interface MemoryConfig {
|
|
|
78
132
|
*/
|
|
79
133
|
hitSignalThreshold: number;
|
|
80
134
|
}
|
|
81
|
-
|
|
135
|
+
export interface MemoryIdentityConfig {
|
|
136
|
+
/**
|
|
137
|
+
* Enable the identity layer: the `soul` and `user-profile` prompt sections
|
|
138
|
+
* plus the `identity_update` agent tool's write surface. Opt-in; defaults
|
|
139
|
+
* to `false`.
|
|
140
|
+
*/
|
|
141
|
+
identityEnabled: boolean;
|
|
142
|
+
/** Character budget for the injected soul section; defaults to `2000`. */
|
|
143
|
+
soulCharLimit: number;
|
|
144
|
+
/** Character budget for the injected user-profile section; defaults to `3000`. */
|
|
145
|
+
userCharLimit: number;
|
|
146
|
+
/**
|
|
147
|
+
* Optional directory holding custom identity seed files (`SOUL.md` /
|
|
148
|
+
* `USER.md`); empty uses the builtin Chinese seeds. Validated loudly at
|
|
149
|
+
* load when identity is enabled; a missing file for one kind keeps that
|
|
150
|
+
* kind's builtin seed (partial override).
|
|
151
|
+
*/
|
|
152
|
+
identitySeedDir?: string;
|
|
153
|
+
}
|
|
154
|
+
/** The full memory-family settings shape: the composition config and the merged runtime view. */
|
|
155
|
+
export type MemoryConfig = MemoryInjectionConfig & MemoryNotesConfig & MemoryAutoRecallConfig & MemoryIdentityConfig;
|
|
156
|
+
/** Runtime schema for the composition config: the union of the four namespace slices. */
|
|
82
157
|
export declare const Config: z<MemoryConfig>;
|
|
83
158
|
/**
|
|
84
159
|
* Rough estimate of the token count for a text blob (P0-6). Uses the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAKxC,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAe,MAAM,aAAa,CAAA;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAoC9C,OAAO,EAAuN,KAAK,UAAU,EAAmB,MAAM,aAAa,CAAA;AAEnR,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC7N,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACxJ,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAEzD,0BAA0B;AAC1B,eAAO,MAAM,IAAI,mBAAmB,CAAA;AAEpC,yEAAyE;AACzE,eAAO,MAAM,MAAM,UAAmB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