@remnic/core 9.6.30 → 9.6.31

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 (74) hide show
  1. package/dist/access-admin-ops-surface.d.ts +1 -0
  2. package/dist/access-boundary.d.ts +1 -0
  3. package/dist/access-cli.js +9 -9
  4. package/dist/access-http.d.ts +1 -0
  5. package/dist/access-identity-continuity-surface.d.ts +1 -0
  6. package/dist/access-lcm-surface.d.ts +1 -0
  7. package/dist/access-mcp.d.ts +1 -0
  8. package/dist/access-observe-write-surface.d.ts +1 -0
  9. package/dist/access-operations.d.ts +1 -0
  10. package/dist/access-recall-surface.d.ts +1 -0
  11. package/dist/access-service.d.ts +1 -0
  12. package/dist/access-surface-catalog.d.ts +1 -0
  13. package/dist/bootstrap.d.ts +1 -0
  14. package/dist/causal-behavior.d.ts +1 -0
  15. package/dist/{chunk-XGSOXFD4.js → chunk-6TCXIRP5.js} +2 -2
  16. package/dist/{chunk-7O2JL5RY.js → chunk-DEOYTFA6.js} +2 -2
  17. package/dist/{chunk-R26WO46Z.js → chunk-DGFU5MSX.js} +16 -1
  18. package/dist/chunk-DGFU5MSX.js.map +1 -0
  19. package/dist/{chunk-BFU7H32D.js → chunk-OH7QLI6W.js} +2 -2
  20. package/dist/{chunk-IRMLYBMU.js → chunk-T67LUYCR.js} +2 -2
  21. package/dist/{chunk-77UPM7P3.js → chunk-TVIVY7KU.js} +160 -61
  22. package/dist/chunk-TVIVY7KU.js.map +1 -0
  23. package/dist/{chunk-KCYE2MZM.js → chunk-UXPUUL3G.js} +29 -8
  24. package/dist/chunk-UXPUUL3G.js.map +1 -0
  25. package/dist/{chunk-3VSTTB74.js → chunk-WSOEYOHN.js} +7 -7
  26. package/dist/{chunk-5AJIDEFT.js → chunk-XFTPUXCE.js} +11 -7
  27. package/dist/chunk-XFTPUXCE.js.map +1 -0
  28. package/dist/cli.d.ts +1 -0
  29. package/dist/compounding/preference-consolidator.d.ts +1 -0
  30. package/dist/event-order-recall.d.ts +1 -0
  31. package/dist/event-order-recall.js +2 -2
  32. package/dist/evidence-pack.d.ts +16 -1
  33. package/dist/evidence-pack.js +1 -1
  34. package/dist/explicit-capture.d.ts +1 -0
  35. package/dist/explicit-cue-recall.d.ts +16 -1
  36. package/dist/explicit-cue-recall.js +2 -2
  37. package/dist/focused-list-recall.d.ts +1 -0
  38. package/dist/focused-list-recall.js +2 -2
  39. package/dist/index.d.ts +3 -2
  40. package/dist/index.js +9 -9
  41. package/dist/lcm/engine.d.ts +3 -0
  42. package/dist/lcm/engine.js +2 -2
  43. package/dist/lcm/index.d.ts +1 -1
  44. package/dist/lcm/index.js +5 -3
  45. package/dist/lcm/recall.d.ts +15 -1
  46. package/dist/lcm/recall.js +5 -3
  47. package/dist/lcm/tools.d.ts +1 -0
  48. package/dist/mcp-memory-inspector-app.d.ts +1 -0
  49. package/dist/orchestrator.d.ts +1 -0
  50. package/dist/orchestrator.js +9 -9
  51. package/dist/response-guidance-recall.d.ts +1 -0
  52. package/dist/response-guidance-recall.js +2 -2
  53. package/dist/targeted-fact-recall.d.ts +1 -0
  54. package/dist/targeted-fact-recall.js +2 -2
  55. package/package.json +2 -2
  56. package/src/evidence-pack.test.ts +66 -1
  57. package/src/evidence-pack.ts +39 -0
  58. package/src/explicit-cue-recall.ts +224 -67
  59. package/src/index.ts +3 -0
  60. package/src/lcm/engine.ts +17 -5
  61. package/src/lcm/index.ts +6 -1
  62. package/src/lcm/recall.ts +48 -5
  63. package/src/lcm-engine.test.ts +46 -0
  64. package/src/lcm-recall.test.ts +48 -1
  65. package/src/recall-trace-receipts.test.ts +380 -0
  66. package/dist/chunk-5AJIDEFT.js.map +0 -1
  67. package/dist/chunk-77UPM7P3.js.map +0 -1
  68. package/dist/chunk-KCYE2MZM.js.map +0 -1
  69. package/dist/chunk-R26WO46Z.js.map +0 -1
  70. /package/dist/{chunk-XGSOXFD4.js.map → chunk-6TCXIRP5.js.map} +0 -0
  71. /package/dist/{chunk-7O2JL5RY.js.map → chunk-DEOYTFA6.js.map} +0 -0
  72. /package/dist/{chunk-BFU7H32D.js.map → chunk-OH7QLI6W.js.map} +0 -0
  73. /package/dist/{chunk-IRMLYBMU.js.map → chunk-T67LUYCR.js.map} +0 -0
  74. /package/dist/{chunk-3VSTTB74.js.map → chunk-WSOEYOHN.js.map} +0 -0
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-LUPVCGYK.js";
8
8
  import {
9
9
  buildEvidencePack
10
- } from "./chunk-R26WO46Z.js";
10
+ } from "./chunk-DGFU5MSX.js";
11
11
  import {
12
12
  lcmArchiveRowId,
13
13
  lcmEvidenceIdentity
@@ -343,7 +343,8 @@ async function buildExplicitCueRecallSection(options) {
343
343
  maxItemChars: normalizePositiveInteger(
344
344
  options.maxItemChars,
345
345
  DEFAULT_MAX_ITEM_CHARS
346
- )
346
+ ),
347
+ ...options.onEvidenceSelected ? { onSelection: options.onEvidenceSelected } : {}
347
348
  });
348
349
  }
349
350
  function buildEvidenceFocusQuery(query, options) {
@@ -392,8 +393,29 @@ async function buildTrajectoryAnalysisRecallSection(options) {
392
393
  return "";
393
394
  }
394
395
  const clipped = truncateTrajectoryAnalysisLines(lines, bodyBudget);
395
- return clipped.length === 0 ? "" : `${header}
396
- ${clipped.join("\n")}`;
396
+ if (clipped.length === 0) return "";
397
+ const text = `${header}
398
+ ${clipped.map((line) => line.text).join("\n")}`;
399
+ if (options.onLineSelected) {
400
+ let lineStart = header.length + 1;
401
+ for (const line of clipped) {
402
+ const lineEnd = lineStart + line.text.length;
403
+ options.onLineSelected({
404
+ lineStart,
405
+ lineEnd,
406
+ lineageStatus: line.lineageStatus,
407
+ actionArchiveRowIds: [...line.actionArchiveRowIds],
408
+ observationArchiveRowIds: [...line.observationArchiveRowIds]
409
+ });
410
+ lineStart = lineEnd + 1;
411
+ }
412
+ }
413
+ return text;
414
+ }
415
+ function uniqueSortedArchiveRowIds(values) {
416
+ return [...new Set(values.filter(
417
+ (value) => typeof value === "number" && Number.isSafeInteger(value) && value > 0
418
+ ))].sort((left, right) => left - right);
397
419
  }
398
420
  async function collectTurnReferenceEvidence(options) {
399
421
  if (!options.sessionId) {
@@ -846,6 +868,40 @@ async function collectLexicalCueEvidence(options) {
846
868
  }
847
869
  }
848
870
  }
871
+ var TrajectoryAnalysisLines = class extends Array {
872
+ sources = /* @__PURE__ */ new Map();
873
+ pushWithSources(text, actionSteps = [], observationSteps = []) {
874
+ const index = this.length;
875
+ const length = super.push(text);
876
+ const hasUnavailableSource = actionSteps.some(
877
+ (step) => lcmArchiveRowId({ id: step.actionArchiveRowId }) === void 0
878
+ ) || observationSteps.some(
879
+ (step) => lcmArchiveRowId({ id: step.observationArchiveRowId }) === void 0
880
+ );
881
+ this.sources.set(index, {
882
+ lineageStatus: hasUnavailableSource ? "unavailable" : "exact",
883
+ actionArchiveRowIds: hasUnavailableSource ? [] : uniqueSortedArchiveRowIds(
884
+ actionSteps.map((step) => step.actionArchiveRowId)
885
+ ),
886
+ observationArchiveRowIds: hasUnavailableSource ? [] : uniqueSortedArchiveRowIds(
887
+ observationSteps.map((step) => step.observationArchiveRowId)
888
+ )
889
+ });
890
+ return length;
891
+ }
892
+ sourceAt(index) {
893
+ const source = this.sources.get(index);
894
+ return source ? {
895
+ lineageStatus: source.lineageStatus,
896
+ actionArchiveRowIds: [...source.actionArchiveRowIds],
897
+ observationArchiveRowIds: [...source.observationArchiveRowIds]
898
+ } : {
899
+ lineageStatus: "unavailable",
900
+ actionArchiveRowIds: [],
901
+ observationArchiveRowIds: []
902
+ };
903
+ }
904
+ };
849
905
  function hasTrajectoryAnalysisIntent(query) {
850
906
  const normalized = normalizeTrajectoryQuery(query);
851
907
  if (collectExplicitTurnReferences(query).length > 0) {
@@ -968,9 +1024,10 @@ function inferTrajectoryBounds(query, trajectory) {
968
1024
  function buildTrajectoryAnalysisLines(query, trajectory, bounds) {
969
1025
  const normalized = normalizeTrajectoryQuery(query);
970
1026
  const explicitReferences = collectExplicitTurnReferences(query);
971
- const lines = [
1027
+ const lines = new TrajectoryAnalysisLines();
1028
+ lines.pushWithSources(
972
1029
  `Analyzed labeled action/observation transcript window: steps ${bounds.start}-${bounds.end} (${bounds.reason}).`
973
- ];
1030
+ );
974
1031
  const hasQuotedObservationPair = extractQuotedObservations(query).length >= 2;
975
1032
  const transition = findObservationTransition(query, trajectory);
976
1033
  const entities = extractNumberedEntities(query);
@@ -983,8 +1040,14 @@ function buildTrajectoryAnalysisLines(query, trajectory, bounds) {
983
1040
  const asksEntityState = /\bstate\b/.test(normalized) || /\bchanges?\s+history\b/.test(normalized) || /\bwhole\s+changes?\s+history\b/.test(normalized);
984
1041
  const asksResultingObservation = /\bresulting\s+state\b/.test(normalized) || /\bprovide\s+the\s+full\s+observation\b/.test(normalized) || /\bwhat\s+will\s+be\s+the\s+resulting\b/.test(normalized);
985
1042
  if (transition) {
986
- lines.push(
987
- `Matched quoted observations: Observation ${transition.fromStep} -> Observation ${transition.toStep}.`
1043
+ const fromStep = trajectory.find((step) => step.step === transition.fromStep);
1044
+ const toStep = trajectory.find((step) => step.step === transition.toStep);
1045
+ lines.pushWithSources(
1046
+ `Matched quoted observations: Observation ${transition.fromStep} -> Observation ${transition.toStep}.`,
1047
+ [],
1048
+ [fromStep, toStep].filter(
1049
+ (step) => step !== void 0
1050
+ )
988
1051
  );
989
1052
  appendActionSequenceSummary(
990
1053
  lines,
@@ -1048,7 +1111,7 @@ function buildTrajectoryAnalysisLines(query, trajectory, bounds) {
1048
1111
  });
1049
1112
  }
1050
1113
  }
1051
- return lines.length === 1 ? [] : lines;
1114
+ return lines.length === 1 ? new TrajectoryAnalysisLines() : lines;
1052
1115
  }
1053
1116
  function appendReferencedTrajectoryLines(lines, trajectory, references, options) {
1054
1117
  const byStep = new Map(trajectory.map((step) => [step.step, step]));
@@ -1056,13 +1119,17 @@ function appendReferencedTrajectoryLines(lines, trajectory, references, options)
1056
1119
  if (window.length === 0) {
1057
1120
  return;
1058
1121
  }
1059
- lines.push(options.heading);
1122
+ lines.pushWithSources(options.heading);
1060
1123
  for (const step of window) {
1061
1124
  if (step.action) {
1062
- lines.push(`[Action ${step.step}]: ${step.action}`);
1125
+ lines.pushWithSources(`[Action ${step.step}]: ${step.action}`, [step]);
1063
1126
  }
1064
1127
  if (options.includeObservations && step.observation) {
1065
- lines.push(`[Observation ${step.step}]: ${oneLine(step.observation)}`);
1128
+ lines.pushWithSources(
1129
+ `[Observation ${step.step}]: ${oneLine(step.observation)}`,
1130
+ [],
1131
+ [step]
1132
+ );
1066
1133
  }
1067
1134
  }
1068
1135
  }
@@ -1077,31 +1144,40 @@ function appendActionRangeLines(lines, trajectory, start, end, options) {
1077
1144
  if (window.length === 0) {
1078
1145
  return;
1079
1146
  }
1080
- lines.push(options.heading);
1147
+ lines.pushWithSources(options.heading);
1081
1148
  for (const step of window) {
1082
1149
  if (step.action) {
1083
- lines.push(`[Action ${step.step}]: ${step.action}`);
1150
+ lines.pushWithSources(`[Action ${step.step}]: ${step.action}`, [step]);
1084
1151
  }
1085
1152
  if (options.includeObservations && step.observation) {
1086
- lines.push(`[Observation ${step.step}]: ${oneLine(step.observation)}`);
1153
+ lines.pushWithSources(
1154
+ `[Observation ${step.step}]: ${oneLine(step.observation)}`,
1155
+ [],
1156
+ [step]
1157
+ );
1087
1158
  }
1088
1159
  }
1089
1160
  }
1090
1161
  function appendActionSequenceSummary(lines, trajectory, start, end, heading) {
1091
1162
  const low = Math.min(start, end);
1092
1163
  const high = Math.max(start, end);
1093
- const actions = trajectory.filter((step) => step.step >= low && step.step <= high && step.action).map((step) => `step ${step.step}: ${step.action}`);
1164
+ const actionSteps = trajectory.filter((step) => step.step >= low && step.step <= high && step.action);
1165
+ const actions = actionSteps.map((step) => `step ${step.step}: ${step.action}`);
1094
1166
  if (actions.length === 0) {
1095
1167
  return;
1096
1168
  }
1097
- lines.push(`${heading} ${actions.join("; ")}.`);
1169
+ lines.pushWithSources(`${heading} ${actions.join("; ")}.`, actionSteps);
1098
1170
  }
1099
1171
  function appendResultingObservationLine(lines, trajectory, stepNumber) {
1100
1172
  const step = trajectory.find((candidate) => candidate.step === stepNumber);
1101
1173
  if (!step?.observation) {
1102
1174
  return;
1103
1175
  }
1104
- lines.push(`Resulting observation after Action ${step.step}: ${oneLine(step.observation)}`);
1176
+ lines.pushWithSources(
1177
+ `Resulting observation after Action ${step.step}: ${oneLine(step.observation)}`,
1178
+ [],
1179
+ [step]
1180
+ );
1105
1181
  }
1106
1182
  function appendSpatialTrajectoryInferenceLines(lines, query, trajectory, bounds) {
1107
1183
  const normalized = normalizeTrajectoryQuery(query);
@@ -1119,22 +1195,22 @@ function appendSpatialTrajectoryInferenceLines(lines, query, trajectory, bounds)
1119
1195
  const window = spatialTrajectoryWindowForQuery(query, trajectory, bounds);
1120
1196
  const counterfactualContactLines = collectCounterfactualContactLines(query, trajectory, normalized);
1121
1197
  if (counterfactualContactLines.length > 0) {
1122
- lines.push("Counterfactual contact cues:");
1198
+ lines.pushWithSources("Counterfactual contact cues:");
1123
1199
  lines.push(...counterfactualContactLines);
1124
1200
  }
1125
1201
  const selfReversingLines = collectSelfReversingProgressLines(query, window, normalized);
1126
1202
  if (selfReversingLines.length > 0) {
1127
- lines.push("Self-reversing sequence cues:");
1203
+ lines.pushWithSources("Self-reversing sequence cues:");
1128
1204
  lines.push(...selfReversingLines);
1129
1205
  }
1130
1206
  const onlyEffectiveActionLines = collectOnlyEffectiveActionLines(window, normalized);
1131
1207
  if (onlyEffectiveActionLines.length > 0) {
1132
- lines.push("Only-effective action cues:");
1208
+ lines.pushWithSources("Only-effective action cues:");
1133
1209
  lines.push(...onlyEffectiveActionLines);
1134
1210
  }
1135
1211
  const pushedPhraseGroupLines = collectPushedPhraseGroupShiftLines(query, window, normalized);
1136
1212
  if (pushedPhraseGroupLines.length > 0) {
1137
- lines.push("Pushed phrase-group shift cues:");
1213
+ lines.pushWithSources("Pushed phrase-group shift cues:");
1138
1214
  lines.push(...pushedPhraseGroupLines);
1139
1215
  }
1140
1216
  const suppressMovementProgressEvidence = onlyEffectiveActionLines.length > 0 || selfReversingLines.some(
@@ -1142,12 +1218,12 @@ function appendSpatialTrajectoryInferenceLines(lines, query, trajectory, bounds)
1142
1218
  ) || pushedPhraseGroupLines.length > 0;
1143
1219
  const actionMovementLines = suppressMovementProgressEvidence ? [] : collectActionMovementSummaryLines(query, window, bounds);
1144
1220
  if (actionMovementLines.length > 0) {
1145
- lines.push("Action movement summary cues:");
1221
+ lines.pushWithSources("Action movement summary cues:");
1146
1222
  lines.push(...actionMovementLines);
1147
1223
  }
1148
1224
  const movementLines = suppressMovementProgressEvidence ? [] : collectMovementDeltaLines(query, window);
1149
1225
  if (movementLines.length > 0) {
1150
- lines.push("Relative-position movement cues:");
1226
+ lines.pushWithSources("Relative-position movement cues:");
1151
1227
  lines.push(...movementLines);
1152
1228
  }
1153
1229
  const objectAlignmentWindow = objectAlignmentWindowForQuery(query, trajectory, bounds);
@@ -1157,77 +1233,77 @@ function appendSpatialTrajectoryInferenceLines(lines, query, trajectory, bounds)
1157
1233
  normalized
1158
1234
  );
1159
1235
  if (objectAlignmentLines.length > 0) {
1160
- lines.push("Object alignment cues:");
1236
+ lines.pushWithSources("Object alignment cues:");
1161
1237
  lines.push(...objectAlignmentLines);
1162
1238
  }
1163
1239
  const alternativeActionLines = collectAlternativeActionLines(query, trajectory);
1164
1240
  if (alternativeActionLines.length > 0) {
1165
- lines.push("Counterfactual action cues:");
1241
+ lines.pushWithSources("Counterfactual action cues:");
1166
1242
  lines.push(...alternativeActionLines);
1167
1243
  }
1168
1244
  const adjacentRuleSetupLines = collectAdjacentRuleSetupLines(window, normalized);
1169
1245
  if (adjacentRuleSetupLines.length > 0) {
1170
- lines.push("Adjacent rule-block setup cues:");
1246
+ lines.pushWithSources("Adjacent rule-block setup cues:");
1171
1247
  lines.push(...adjacentRuleSetupLines);
1172
1248
  }
1173
1249
  const blockedMoveLines = collectBlockedMoveLines(query, window, normalized);
1174
1250
  if (blockedMoveLines.length > 0) {
1175
- lines.push("Blocked-move cues:");
1251
+ lines.pushWithSources("Blocked-move cues:");
1176
1252
  lines.push(...blockedMoveLines);
1177
1253
  }
1178
1254
  const failedEscapeLines = collectFailedEscapeLines(query, trajectory, normalized);
1179
1255
  if (failedEscapeLines.length > 0) {
1180
- lines.push("Failed-move escape cues:");
1256
+ lines.pushWithSources("Failed-move escape cues:");
1181
1257
  lines.push(...failedEscapeLines);
1182
1258
  }
1183
1259
  const sameRelativeTextPushLines = collectSameRelativeTextPushLines(window, normalized);
1184
1260
  if (sameRelativeTextPushLines.length > 0) {
1185
- lines.push("Same-relative text-push cues:");
1261
+ lines.pushWithSources("Same-relative text-push cues:");
1186
1262
  lines.push(...sameRelativeTextPushLines);
1187
1263
  }
1188
1264
  const failedContactLines = sameRelativeTextPushLines.length > 0 ? [] : collectFailedContactBoundaryLines(window, normalized);
1189
1265
  if (failedContactLines.length > 0) {
1190
- lines.push("Failed-push boundary cues:");
1266
+ lines.pushWithSources("Failed-push boundary cues:");
1191
1267
  lines.push(...failedContactLines);
1192
1268
  }
1193
1269
  const transformationLines = collectTemporaryRuleTransformationLines(window, normalized);
1194
1270
  if (transformationLines.length > 0) {
1195
- lines.push("Temporary transformation cues:");
1271
+ lines.pushWithSources("Temporary transformation cues:");
1196
1272
  lines.push(...transformationLines);
1197
1273
  }
1198
1274
  const wholeConfigurationShiftLines = collectWholeConfigurationShiftLines(window, normalized);
1199
1275
  if (wholeConfigurationShiftLines.length > 0) {
1200
- lines.push("Whole-configuration shift cues:");
1276
+ lines.pushWithSources("Whole-configuration shift cues:");
1201
1277
  lines.push(...wholeConfigurationShiftLines);
1202
1278
  }
1203
1279
  const ruleInterventionLines = collectRuleInterventionStrategyLines(window, normalized);
1204
1280
  if (ruleInterventionLines.length > 0) {
1205
- lines.push("Rule-intervention strategy cues:");
1281
+ lines.pushWithSources("Rule-intervention strategy cues:");
1206
1282
  lines.push(...ruleInterventionLines);
1207
1283
  }
1208
1284
  const missingPushTargetLines = collectMissingPushTargetLines(window, normalized);
1209
1285
  if (missingPushTargetLines.length > 0) {
1210
- lines.push("Missing-interaction cues:");
1286
+ lines.pushWithSources("Missing-interaction cues:");
1211
1287
  lines.push(...missingPushTargetLines);
1212
1288
  }
1213
1289
  const rulePhraseAlignmentLines = collectRulePhraseAlignmentLines(window, normalized);
1214
1290
  if (rulePhraseAlignmentLines.length > 0) {
1215
- lines.push("Rule-phrase alignment cues:");
1291
+ lines.pushWithSources("Rule-phrase alignment cues:");
1216
1292
  lines.push(...rulePhraseAlignmentLines);
1217
1293
  }
1218
1294
  const controlRuleInteractionLines = collectControlRuleInteractionLines(window, normalized);
1219
1295
  if (controlRuleInteractionLines.length > 0) {
1220
- lines.push("Control-rule interaction cues:");
1296
+ lines.pushWithSources("Control-rule interaction cues:");
1221
1297
  lines.push(...controlRuleInteractionLines);
1222
1298
  }
1223
1299
  const ruleTextPositionLines = suppressMovementProgressEvidence ? [] : collectRuleTextPositionLines(window, normalized);
1224
1300
  if (ruleTextPositionLines.length > 0) {
1225
- lines.push("Rule-text positioning cues:");
1301
+ lines.pushWithSources("Rule-text positioning cues:");
1226
1302
  lines.push(...ruleTextPositionLines);
1227
1303
  }
1228
1304
  const ruleLines = collectRuleStateLines(window, normalized);
1229
1305
  if (ruleLines.length > 0) {
1230
- lines.push("Rule-state cues:");
1306
+ lines.pushWithSources("Rule-state cues:");
1231
1307
  lines.push(...ruleLines);
1232
1308
  }
1233
1309
  }
@@ -2527,8 +2603,11 @@ function uniqueLines(lines) {
2527
2603
  return [...new Set(lines)];
2528
2604
  }
2529
2605
  function appendActionFrequencyLines(lines, trajectory, bounds) {
2606
+ const actionSteps = boundedTrajectory(trajectory, bounds).filter(
2607
+ (step) => step.action !== void 0
2608
+ );
2530
2609
  const counts = /* @__PURE__ */ new Map();
2531
- for (const step of boundedTrajectory(trajectory, bounds)) {
2610
+ for (const step of actionSteps) {
2532
2611
  if (!step.action) continue;
2533
2612
  const verb = normalizeActionVerb(step.action);
2534
2613
  if (!verb) continue;
@@ -2540,8 +2619,9 @@ function appendActionFrequencyLines(lines, trajectory, bounds) {
2540
2619
  const frequencies = [...counts.entries()].sort(
2541
2620
  (left, right) => right[1] - left[1] || left[0].localeCompare(right[0])
2542
2621
  );
2543
- lines.push(
2544
- `Action frequency through requested window: ${frequencies.map(([verb, count]) => `${verb}=${count}`).join(", ")}.`
2622
+ lines.pushWithSources(
2623
+ `Action frequency through requested window: ${frequencies.map(([verb, count]) => `${verb}=${count}`).join(", ")}.`,
2624
+ actionSteps
2545
2625
  );
2546
2626
  }
2547
2627
  function appendInventoryChangeLines(lines, trajectory, bounds) {
@@ -2557,13 +2637,16 @@ function appendInventoryChangeLines(lines, trajectory, bounds) {
2557
2637
  if (changes.length === 0) {
2558
2638
  return;
2559
2639
  }
2560
- lines.push("Inventory changes from action transcript:");
2640
+ const changeSteps = changes.map((change) => trajectory.find((step) => step.step === change.step)).filter((step) => step !== void 0);
2641
+ lines.pushWithSources("Inventory changes from action transcript:");
2561
2642
  if (changes.length > 5) {
2562
- lines.push(
2563
- `First five inventory changes: ${formatInventoryChangeSummary(changes.slice(0, 5))}.`
2643
+ lines.pushWithSources(
2644
+ `First five inventory changes: ${formatInventoryChangeSummary(changes.slice(0, 5))}.`,
2645
+ changeSteps.slice(0, 5)
2564
2646
  );
2565
- lines.push(
2566
- `Complete inventory changes: ${formatInventoryChangeSummary(changes)}.`
2647
+ lines.pushWithSources(
2648
+ `Complete inventory changes: ${formatInventoryChangeSummary(changes)}.`,
2649
+ changeSteps
2567
2650
  );
2568
2651
  }
2569
2652
  for (const change of changes) {
@@ -2589,9 +2672,13 @@ function appendContainerStateChangeLines(lines, trajectory, bounds) {
2589
2672
  if (changes.length === 0) {
2590
2673
  return;
2591
2674
  }
2592
- lines.push("Container open/close state changes:");
2675
+ lines.pushWithSources("Container open/close state changes:");
2593
2676
  for (const change of changes) {
2594
- lines.push(`[Action ${change.step}]: ${change.action} => ${change.entity} ${change.state}`);
2677
+ const step = trajectory.find((candidate) => candidate.step === change.step);
2678
+ lines.pushWithSources(
2679
+ `[Action ${change.step}]: ${change.action} => ${change.entity} ${change.state}`,
2680
+ step ? [step] : []
2681
+ );
2595
2682
  }
2596
2683
  }
2597
2684
  function appendEntityTimelineLines(lines, trajectory, bounds, entities, options) {
@@ -2609,26 +2696,33 @@ function appendEntityTimelineLines(lines, trajectory, bounds, entities, options)
2609
2696
  if (directActions.length === 0 && stateChanges.length === 0 && objectTransfers.length === 0) {
2610
2697
  continue;
2611
2698
  }
2612
- lines.push(`Timeline for ${entity}:`);
2699
+ lines.pushWithSources(`Timeline for ${entity}:`);
2613
2700
  for (const step of directActions) {
2614
- lines.push(`[Action ${step.step}]: ${step.action}`);
2701
+ lines.pushWithSources(`[Action ${step.step}]: ${step.action}`, [step]);
2615
2702
  }
2616
2703
  if (objectTransfers.length > 0) {
2617
- lines.push(`Object transfers involving ${entity}:`);
2704
+ lines.pushWithSources(`Object transfers involving ${entity}:`);
2618
2705
  for (const transfer of objectTransfers) {
2619
- lines.push(`[Action ${transfer.step}]: ${transfer.action} => ${formatContainerTransfer(transfer)}`);
2706
+ const step = trajectory.find((candidate) => candidate.step === transfer.step);
2707
+ lines.pushWithSources(
2708
+ `[Action ${transfer.step}]: ${transfer.action} => ${formatContainerTransfer(transfer)}`,
2709
+ step ? [step] : []
2710
+ );
2620
2711
  }
2621
2712
  }
2622
2713
  const inferredLocation = inferEntityLocation(trajectory, bounds, entity);
2623
2714
  if (inferredLocation) {
2624
- lines.push(
2625
- `Inferred ${entity} location at step ${bounds.end}: ${inferredLocation}.`
2715
+ lines.pushWithSources(
2716
+ `Inferred ${entity} location at step ${bounds.end}: ${inferredLocation.location}.`,
2717
+ [inferredLocation.sourceStep]
2626
2718
  );
2627
2719
  }
2628
2720
  if (stateChanges.length > 0) {
2629
2721
  const latest = stateChanges[stateChanges.length - 1];
2630
- lines.push(
2631
- `Latest ${entity} state at step ${bounds.end}: ${latest.state}; state changes: ${stateChanges.map((change) => `${change.step}:${change.state}`).join(", ")}.`
2722
+ const stateSteps = stateChanges.map((change) => trajectory.find((step) => step.step === change.step)).filter((step) => step !== void 0);
2723
+ lines.pushWithSources(
2724
+ `Latest ${entity} state at step ${bounds.end}: ${latest.state}; state changes: ${stateChanges.map((change) => `${change.step}:${change.state}`).join(", ")}.`,
2725
+ stateSteps
2632
2726
  );
2633
2727
  }
2634
2728
  }
@@ -2887,12 +2981,14 @@ function isLikelyContainerEntity(entity) {
2887
2981
  function inferEntityLocation(trajectory, bounds, entity) {
2888
2982
  const normalizedEntity = normalizeEntity(entity);
2889
2983
  let location;
2984
+ let sourceStep;
2890
2985
  for (const step of boundedTrajectory(trajectory, bounds)) {
2891
2986
  if (!step.action) continue;
2892
2987
  const action = step.action.trim();
2893
2988
  const take = /^take\s+(.+?)\s+from\s+(.+)$/i.exec(action);
2894
2989
  if (take && normalizeEntity(take[1]) === normalizedEntity) {
2895
2990
  location = "inventory";
2991
+ sourceStep = step;
2896
2992
  continue;
2897
2993
  }
2898
2994
  const move = /^(?:move|put|place|insert)\s+(.+?)\s+(?:to|in|into|on)\s+(.+)$/i.exec(
@@ -2900,9 +2996,10 @@ function inferEntityLocation(trajectory, bounds, entity) {
2900
2996
  );
2901
2997
  if (move && normalizeEntity(move[1]) === normalizedEntity) {
2902
2998
  location = move[2].trim();
2999
+ sourceStep = step;
2903
3000
  }
2904
3001
  }
2905
- return location;
3002
+ return location && sourceStep ? { location, sourceStep } : void 0;
2906
3003
  }
2907
3004
  function normalizeActionVerb(action) {
2908
3005
  const match = /^([a-z][a-z0-9_-]*)\b/i.exec(action.trim());
@@ -2931,7 +3028,9 @@ function normalizeTurnExpansionEnd(stats) {
2931
3028
  function truncateTrajectoryAnalysisLines(lines, maxChars) {
2932
3029
  const result = [];
2933
3030
  let used = 0;
2934
- for (const line of lines.slice(0, TRAJECTORY_ANALYSIS_MAX_LINES)) {
3031
+ const limit = Math.min(lines.length, TRAJECTORY_ANALYSIS_MAX_LINES);
3032
+ for (let index = 0; index < limit; index += 1) {
3033
+ const line = lines[index];
2935
3034
  const separator = result.length === 0 ? 0 : 1;
2936
3035
  const remaining = maxChars - used - separator;
2937
3036
  if (remaining <= 0) {
@@ -2941,7 +3040,7 @@ function truncateTrajectoryAnalysisLines(lines, maxChars) {
2941
3040
  if (clipped.length === 0) {
2942
3041
  break;
2943
3042
  }
2944
- result.push(clipped);
3043
+ result.push({ text: clipped, ...lines.sourceAt(index) });
2945
3044
  used += separator + clipped.length;
2946
3045
  }
2947
3046
  return result;
@@ -4159,4 +4258,4 @@ export {
4159
4258
  collectStructuredPlanCues,
4160
4259
  collectTemporalLexicalCues
4161
4260
  };
4162
- //# sourceMappingURL=chunk-77UPM7P3.js.map
4261
+ //# sourceMappingURL=chunk-TVIVY7KU.js.map