@lmzhen/dsh-memory-files 0.4.1 → 0.6.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 CHANGED
@@ -12,6 +12,11 @@ Local layered memory provider: registers the `files` provider into `ctx.memory`
12
12
 
13
13
  - `providerName` (default `files`): the registered name.
14
14
  - `memoryCharLimit` / `userCharLimit` (`2200` / `1375`) the budget the STORE enforces per target.
15
+ Deprecated names (G0/S0.3): the canonical ids are the policy row's `memoryChars` /
16
+ `userChars` (what the review planner reads). The two sides are not
17
+ auto-synchronised — `/evolution doctor` reports the divergence (`budgetIssues`).
18
+ Reading the legacy names still works; writing them is refused, and both are
19
+ removed in 0.7.0.
15
20
  - `root`: directory override; `''` means `$DSH_HOME/memories`.
16
21
  - `addDatePrefix` / `maxConsolidationFailures` (`false` / `3`) date prefixes on entries; consolidation failures one turn tolerates.
17
22
  - `threatExemptLabels` (default `[]`): benign threat labels for the MEMORY store (per-site rule in `evolution-threat`).
package/lib/index.js CHANGED
@@ -1,12 +1,18 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { resolve } from "node:path";
3
3
  import z from "@deepseek-ai/schemastery";
4
- import { DEFAULT_CONSOLIDATION_FAILURES, DEFAULT_MEMORY_CHAR_LIMIT, DEFAULT_USER_CHAR_LIMIT, MemoryStore, clampedNumber, evolutionIoAdapter, makeSerialQueue } from "@lmzhen/dsh-evolution-core";
4
+ import { DEFAULT_CONSOLIDATION_FAILURES, DEFAULT_MEMORY_CHAR_LIMIT, DEFAULT_USER_CHAR_LIMIT, MemoryStore, PARAM_NAMESPACES, clampedNumber, evolutionIoAdapter, installParamSection, makeSerialQueue } from "@lmzhen/dsh-evolution-core";
5
5
  //#region lib/types/index.js
6
6
  /**
7
7
  * Local layered memory provider for `ctx.memory`.
8
8
  * @module @lmzhen/dsh-memory-files
9
9
  */
10
+ const MEMORY_SETTINGS_SCHEMA = z.object({
11
+ memoryChars: z.number().min(1).default(DEFAULT_MEMORY_CHAR_LIMIT),
12
+ userChars: z.number().min(1).default(DEFAULT_USER_CHAR_LIMIT),
13
+ addDatePrefix: z.boolean().default(false),
14
+ maxConsolidationFailures: z.number().min(1).default(DEFAULT_CONSOLIDATION_FAILURES)
15
+ });
10
16
  const name = "memory-files";
11
17
  const inject = ["memory", "evolutionIo"];
12
18
  const Config = z.object({
@@ -48,15 +54,30 @@ function apply(ctx, rawConfig = {}) {
48
54
  const serializedWrite = makeSerialQueue();
49
55
  const trimmedRoot = (config.root || "").trim();
50
56
  const resolvedRoot = trimmedRoot === "" ? "" : resolve(trimmedRoot);
51
- const store = new MemoryStore({
52
- memoryCharLimit: config.memoryCharLimit,
53
- userCharLimit: config.userCharLimit,
54
- addDatePrefix: config.addDatePrefix,
55
- maxConsolidationFailures: config.maxConsolidationFailures,
57
+ const section = {};
58
+ const buildStore = () => new MemoryStore({
59
+ memoryCharLimit: section.overrides?.get("memoryChars") ?? config.memoryCharLimit,
60
+ userCharLimit: section.overrides?.get("userChars") ?? config.userCharLimit,
61
+ addDatePrefix: section.overrides?.get("addDatePrefix") ?? config.addDatePrefix,
62
+ maxConsolidationFailures: section.overrides?.get("maxConsolidationFailures") ?? config.maxConsolidationFailures,
56
63
  threatExemptLabels: config.threatExemptLabels,
57
64
  ...resolvedRoot !== "" ? { root: resolvedRoot } : {},
58
65
  io
59
66
  });
67
+ let store = buildStore();
68
+ section.overrides = installParamSection(ctx, PARAM_NAMESPACES["memory-files"] ?? "evolution-memory", MEMORY_SETTINGS_SCHEMA, {
69
+ memoryChars: config.memoryCharLimit,
70
+ userChars: config.userCharLimit,
71
+ addDatePrefix: config.addDatePrefix,
72
+ maxConsolidationFailures: config.maxConsolidationFailures
73
+ }, {
74
+ warn: (message) => {
75
+ ctx.logger.warn("memory-files: " + message);
76
+ },
77
+ onChange: () => {
78
+ store = buildStore();
79
+ }
80
+ });
60
81
  const provider = {
61
82
  name: config.providerName,
62
83
  read: (target) => store.read(target),
@@ -80,15 +101,28 @@ function apply(ctx, rawConfig = {}) {
80
101
  },
81
102
  renderContext: () => serializedWrite(() => store.renderContext())
82
103
  };
104
+ const limitSource = (name, explicit, policyValue) => {
105
+ if (section.overrides?.get(name) !== void 0) return "user";
106
+ if (explicit) return "config";
107
+ return policyValue === void 0 ? "default" : "policy";
108
+ };
83
109
  ctx.provide("evolutionMemoryBudget", {
84
- memoryCharLimit: config.memoryCharLimit,
85
- userCharLimit: config.userCharLimit,
86
- memorySource: explicitLimit("memoryCharLimit") ? "config" : budget.memory === void 0 ? "default" : "policy",
87
- userSource: explicitLimit("userCharLimit") ? "config" : budget.user === void 0 ? "default" : "policy",
110
+ get memoryCharLimit() {
111
+ return section.overrides?.get("memoryChars") ?? config.memoryCharLimit;
112
+ },
113
+ get userCharLimit() {
114
+ return section.overrides?.get("userChars") ?? config.userCharLimit;
115
+ },
116
+ get memorySource() {
117
+ return limitSource("memoryChars", explicitLimit("memoryCharLimit"), budget.memory);
118
+ },
119
+ get userSource() {
120
+ return limitSource("userChars", explicitLimit("userCharLimit"), budget.user);
121
+ },
88
122
  policyMemoryChars: budget.memory,
89
123
  policyUserChars: budget.user
90
124
  });
91
125
  ctx.effect(() => ctx.memory.registerProvider(provider), "memory-files.provider");
92
126
  }
93
127
  //#endregion
94
- export { Config, apply, inject, name };
128
+ export { Config, MEMORY_SETTINGS_SCHEMA, apply, inject, name };
@@ -4,11 +4,34 @@
4
4
  */
5
5
  import type { Context } from '@deepseek-ai/cordis';
6
6
  import z from '@deepseek-ai/schemastery';
7
+ /** G3/S3.2: the memory section's schema. Field names are the CANONICAL ids from
8
+ * the parameter registry (`memoryChars`/`userChars` are the policy-side names the
9
+ * review planner reads too), so the settings document, the params output, the
10
+ * doctor report and the cards spell one name. */
11
+ export interface MemorySettings {
12
+ /** Character budget the store enforces for MEMORY.md. */
13
+ memoryChars: number;
14
+ /** Character budget the store enforces for USER.md. */
15
+ userChars: number;
16
+ /** Prefix stored entries with their date heading. */
17
+ addDatePrefix: boolean;
18
+ /** Consolidation failures one turn tolerates before the tool stops retrying. */
19
+ maxConsolidationFailures: number;
20
+ }
21
+ export declare const MEMORY_SETTINGS_SCHEMA: z<MemorySettings>;
7
22
  export declare const name = "memory-files";
8
23
  export declare const inject: string[];
9
24
  export interface Config {
10
25
  providerName?: string;
26
+ /** Store-enforced character budget for MEMORY.md. The policy row's
27
+ * `memoryChars` is the same semantic on the review-planner side and is the
28
+ * canonical id (G0/S0.2); the two are NOT auto-synchronised —
29
+ * `/evolution doctor` reports the divergence (budgetIssues). Deprecated alias
30
+ * (G0/S0.3): still readable, refused by writes; removed in 0.7.0. */
11
31
  memoryCharLimit?: number;
32
+ /** Store-enforced character budget for USER.md; the canonical id is the policy
33
+ * row's `userChars`. Divergence is reported by `/evolution doctor`. Deprecated
34
+ * alias (G0/S0.3): still readable, refused by writes; removed in 0.7.0. */
12
35
  userCharLimit?: number;
13
36
  addDatePrefix?: boolean;
14
37
  root?: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lmzhen/dsh-memory-files",
3
3
  "description": "Local layered memory provider (community build)",
4
- "version": "0.4.1",
4
+ "version": "0.6.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -27,16 +27,16 @@
27
27
  "license": "MIT",
28
28
  "dependencies": {
29
29
  "@deepseek-ai/schemastery": "^3.18.1",
30
- "@lmzhen/dsh-evolution-core": "^0.4.1"
30
+ "@lmzhen/dsh-evolution-core": "^0.6.0"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "@deepseek-ai/cordis": "^4.0.1",
34
- "@lmzhen/dsh-evolution-io": "^0.4.1",
35
- "@lmzhen/dsh-memory": "^0.4.1"
34
+ "@lmzhen/dsh-evolution-io": "^0.6.0",
35
+ "@lmzhen/dsh-memory": "^0.6.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@lmzhen/dsh-evolution-core": "^0.4.1",
39
- "@lmzhen/dsh-evolution-io": "^0.4.1",
40
- "@lmzhen/dsh-memory": "^0.4.1"
38
+ "@lmzhen/dsh-evolution-core": "^0.6.0",
39
+ "@lmzhen/dsh-evolution-io": "^0.6.0",
40
+ "@lmzhen/dsh-memory": "^0.6.0"
41
41
  }
42
42
  }