dsh-mnemon-strategy-default-three-tier 0.5.8 → 0.5.9

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 +46 -10
  2. package/package.json +2 -2
package/lib/index.js CHANGED
@@ -196,18 +196,23 @@ var ThreeTierTurn = class {
196
196
  const input = memoryInputRecord(request.input, "Documents search");
197
197
  const query = String(input.query).trim();
198
198
  const includeArchived = input.includeArchived === true;
199
+ if (this.state.documentSearchPending !== void 0) {
200
+ await Promise.allSettled([this.state.documentSearchPending]);
201
+ return this.documents(request, read);
202
+ }
199
203
  if (this.state.documentSearchClaimed) return {
200
204
  ...this.empty(request),
201
205
  output: {
202
206
  query,
203
207
  includeArchived,
204
208
  notRun: true,
209
+ budgetExhausted: true,
205
210
  results: [],
206
- hint: "This Agent turn already used its Documents search slot, so no second disk query ran. Use the admitted evidence, make one focused mnemon_recall only if exact durable history is still missing, or answer with appropriate uncertainty."
211
+ hint: "This query did not run: this Agent turn already used its Documents search. The empty list does not mean no document matches. Use the admitted evidence, make one focused mnemon_recall where it is offered only if exact durable history is still missing, or answer with appropriate uncertainty."
207
212
  }
208
213
  };
209
214
  this.state.documentSearchClaimed = true;
210
- const evidence = await read({
215
+ const pending = read({
211
216
  query,
212
217
  includeArchived,
213
218
  limit: Math.min(4, typeof input.limit === "number" ? Math.max(1, input.limit) : 4)
@@ -215,6 +220,16 @@ var ThreeTierTurn = class {
215
220
  maxResults: 4,
216
221
  maxCharacters: 6e3
217
222
  });
223
+ this.state.documentSearchPending = pending;
224
+ let evidence;
225
+ try {
226
+ evidence = await pending;
227
+ } catch (error) {
228
+ this.state.documentSearchClaimed = false;
229
+ throw error;
230
+ } finally {
231
+ if (this.state.documentSearchPending === pending) delete this.state.documentSearchPending;
232
+ }
218
233
  const metadata = optionalObject(evidence.metadata) ?? {};
219
234
  const results = evidence.items.filter((item) => optionalObject(item.provenance)?.kind !== "suggestion").map((item) => {
220
235
  const record = optionalObject(item.provenance) ?? {};
@@ -277,14 +292,19 @@ var ThreeTierTurn = class {
277
292
  };
278
293
  }
279
294
  if (retrieval.recallAttempts.length >= MODEL_RECALL_ATTEMPT_LIMIT) {
280
- const latest = retrieval.recallAttempts[retrieval.recallAttempts.length - 1];
281
- const last = latest?.result ?? await latest?.pending;
282
- const previous = last?.memoryEvidence?.sourceInstanceKey === authority.sourceInstanceKey ? last : void 0;
295
+ const inflight = retrieval.recallAttempts.flatMap((entry) => entry.pending === void 0 ? [] : [entry.pending]);
296
+ if (inflight.length > 0) {
297
+ await Promise.allSettled(inflight);
298
+ signal.throwIfAborted();
299
+ return this.recall(request, read, signal, authority);
300
+ }
283
301
  return {
284
- query: previous?.query ?? scoped.query,
285
- mode: previous?.mode ?? scoped.mode ?? "smart",
286
- ...replayEvidence(previous, scoped.memoryBodyIds, authority.sourceInstanceKey),
287
- hint: "The two-query turn Recall budget is exhausted. The Host replayed the latest admitted evidence without another Provider query; stop retrieval and answer from the evidence or state what remains unknown."
302
+ query: scoped.query,
303
+ mode: scoped.mode ?? "smart",
304
+ results: [],
305
+ notRun: true,
306
+ budgetExhausted: true,
307
+ hint: "The two-query turn Recall budget is exhausted, so this query did not run. It has no results; the empty list does not mean nothing matches. Answer from the evidence the other Recall calls returned, or state what remains unknown."
288
308
  };
289
309
  }
290
310
  const attemptIndex = retrieval.recallAttempts.length;
@@ -346,6 +366,7 @@ var ThreeTierTurn = class {
346
366
  query: `related:${id}`,
347
367
  mode: "related",
348
368
  results: [],
369
+ notRun: true,
349
370
  hint: "Related traversal requires an insight admitted by the current turn's direct Recall. No Provider query was made."
350
371
  };
351
372
  const digest = sha256(JSON.stringify({
@@ -356,13 +377,28 @@ var ThreeTierTurn = class {
356
377
  edge: options.edge ?? ""
357
378
  }));
358
379
  if (retrieval.relatedDigest !== void 0) {
380
+ if (retrieval.relatedDigest !== digest) {
381
+ if (retrieval.relatedPending !== void 0) {
382
+ await Promise.allSettled([retrieval.relatedPending]);
383
+ signal.throwIfAborted();
384
+ return this.related(id, memoryBodyId, read, signal, authority, options);
385
+ }
386
+ return {
387
+ query: `related:${id}`,
388
+ mode: "related",
389
+ results: [],
390
+ notRun: true,
391
+ budgetExhausted: true,
392
+ hint: "Related traversal is complete for this turn, so this one did not run. It has no results; the empty list does not mean nothing is related. Answer from the evidence the other calls returned."
393
+ };
394
+ }
359
395
  const last = retrieval.relatedResult ?? await retrieval.relatedPending;
360
396
  const previous = last?.memoryEvidence?.sourceInstanceKey === authority.sourceInstanceKey ? last : void 0;
361
397
  return {
362
398
  query: previous?.query ?? `related:${id}`,
363
399
  mode: previous?.mode ?? "related",
364
400
  ...replayEvidence(previous, [selected], authority.sourceInstanceKey),
365
- hint: retrieval.relatedDigest === digest ? "This exact Related traversal already ran. The Host replayed its admitted evidence without another Provider query; stop retrieval and answer from it." : "Related traversal is complete for this turn. The Host replayed the admitted evidence; stop retrieval and answer from it."
401
+ hint: "This exact Related traversal already ran. The Host replayed its admitted evidence without another Provider query; stop retrieval and answer from it."
366
402
  };
367
403
  }
368
404
  retrieval.relatedDigest = digest;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mnemon-strategy-default-three-tier",
3
- "version": "0.5.8",
3
+ "version": "0.5.9",
4
4
  "description": "Explicit three-tier View Strategy for Composable View Memory.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/node": "^22.0.0",
39
- "dsh-mnemon": "^0.5.25",
39
+ "dsh-mnemon": "^0.5.30",
40
40
  "tsdown": "^0.22.0",
41
41
  "typescript": "^5.9.0",
42
42
  "vitest": "^3.2.0"