@lmzhen/dsh-evolution-core 0.1.0-rc.46 → 0.1.0-rc.47

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.
Files changed (2) hide show
  1. package/lib/index.js +33 -13
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -1006,6 +1006,23 @@ const READ_GUARD_FACTOR = 10;
1006
1006
  * first refusal say "stop retrying".
1007
1007
  */
1008
1008
  const FAILURE_WINDOW_MS = 10 * 6e4;
1009
+ /**
1010
+ * Recoverable-error preview bounds (B-line G5, Hermes `_previews` parity):
1011
+ * failed replace/remove/batch calls echo the current entries so the model can
1012
+ * self-recover without re-reading the store. Bounded to five entries of eighty
1013
+ * characters each; package-private because it is an error-message shape, not a
1014
+ * behavior switch.
1015
+ */
1016
+ const ERROR_PREVIEW_ENTRIES = 5;
1017
+ const ERROR_PREVIEW_WIDTH = 80;
1018
+ function previewEntries(entries) {
1019
+ if (entries.length === 0) return "";
1020
+ const shown = entries.slice(0, ERROR_PREVIEW_ENTRIES).map((entry) => {
1021
+ return `- ${entry.length > ERROR_PREVIEW_WIDTH ? `${entry.slice(0, ERROR_PREVIEW_WIDTH)}…` : entry}`;
1022
+ });
1023
+ const more = entries.length > ERROR_PREVIEW_ENTRIES ? `\n (+${entries.length - ERROR_PREVIEW_ENTRIES} more)` : "";
1024
+ return `\n\nCurrent entries (preview):\n${shown.join("\n")}${more}`;
1025
+ }
1009
1026
  function memoryRoot(env = process.env) {
1010
1027
  return join(env.DSH_HOME ?? join(homedir(), ".dsh"), "memories");
1011
1028
  }
@@ -1075,14 +1092,14 @@ var MemoryStore = class {
1075
1092
  const chars = entries.join(ENTRY_DELIMITER).length;
1076
1093
  if (this.failureCount > this.maxFailures) return {
1077
1094
  ok: false,
1078
- message: `Memory consolidation failed ${this.failureCount} times this turn. Stop retrying memory calls and continue with the user's task.`,
1095
+ message: `Memory consolidation failed ${this.failureCount} times this turn. Stop retrying memory calls and continue with the user's task.${previewEntries(entries)}`,
1079
1096
  entries,
1080
1097
  chars,
1081
1098
  limit: this.limitFor(target)
1082
1099
  };
1083
1100
  return {
1084
1101
  ok: false,
1085
- message,
1102
+ message: `${message}${previewEntries(entries)}`,
1086
1103
  entries,
1087
1104
  chars,
1088
1105
  limit: this.limitFor(target)
@@ -1198,13 +1215,16 @@ var MemoryStore = class {
1198
1215
  }
1199
1216
  async mutate(target, oldText, action, facts) {
1200
1217
  const needle = oldText.trim();
1201
- if (!needle) return {
1202
- ok: false,
1203
- message: "old_text cannot be empty.",
1204
- entries: [],
1205
- chars: 0,
1206
- limit: this.limitFor(target)
1207
- };
1218
+ if (!needle) {
1219
+ const current = await this.read(target);
1220
+ return {
1221
+ ok: false,
1222
+ message: `old_text cannot be empty.${previewEntries(current)}`,
1223
+ entries: current,
1224
+ chars: current.join(ENTRY_DELIMITER).length,
1225
+ limit: this.limitFor(target)
1226
+ };
1227
+ }
1208
1228
  const refusal = await this.oversizedRefusal(target);
1209
1229
  if (refusal) return refusal;
1210
1230
  const content = action === "replace" ? (facts ?? "").trim() : "";
@@ -1293,7 +1313,7 @@ var MemoryStore = class {
1293
1313
  const body = (op.facts ?? "").trim();
1294
1314
  if (!body) return {
1295
1315
  ok: false,
1296
- message: `Operation ${position} (add): facts is required. No operations were applied.`,
1316
+ message: `Operation ${position} (add): facts is required. No operations were applied.${previewEntries(entries)}`,
1297
1317
  entries,
1298
1318
  chars: entries.join(ENTRY_DELIMITER).length,
1299
1319
  limit: this.limitFor(target)
@@ -1312,7 +1332,7 @@ var MemoryStore = class {
1312
1332
  const needle = (op.old_text ?? "").trim();
1313
1333
  if (!needle) return {
1314
1334
  ok: false,
1315
- message: `Operation ${position} (${op.action}): old_text is required. No operations were applied.`,
1335
+ message: `Operation ${position} (${op.action}): old_text is required. No operations were applied.${previewEntries(entries)}`,
1316
1336
  entries,
1317
1337
  chars: entries.join(ENTRY_DELIMITER).length,
1318
1338
  limit: this.limitFor(target)
@@ -1324,7 +1344,7 @@ var MemoryStore = class {
1324
1344
  if (matches.length === 0) return this.failure(target, `Operation ${position}: no entry matching "${needle}" found. No operations were applied.`, entries);
1325
1345
  if (new Set(matches.map((m) => m.entry)).size > 1) return {
1326
1346
  ok: false,
1327
- message: `Operation ${position}: "${needle}" matched multiple distinct entries. No operations were applied.`,
1347
+ message: `Operation ${position}: "${needle}" matched multiple distinct entries. No operations were applied.${previewEntries(entries)}`,
1328
1348
  entries,
1329
1349
  chars: entries.join(ENTRY_DELIMITER).length,
1330
1350
  limit: this.limitFor(target)
@@ -1335,7 +1355,7 @@ var MemoryStore = class {
1335
1355
  const body = (op.facts ?? "").trim();
1336
1356
  if (!body) return {
1337
1357
  ok: false,
1338
- message: `Operation ${position} (replace): facts is required.`,
1358
+ message: `Operation ${position} (replace): facts is required.${previewEntries(entries)}`,
1339
1359
  entries,
1340
1360
  chars: entries.join(ENTRY_DELIMITER).length,
1341
1361
  limit: this.limitFor(target)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lmzhen/dsh-evolution-core",
3
3
  "description": "Shared stores, prompts, signals and lifecycle logic for the dsh-evolution plugin family (community build)",
4
- "version": "0.1.0-rc.46",
4
+ "version": "0.1.0-rc.47",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },