@remnic/core 9.3.736 → 9.3.737

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 (148) hide show
  1. package/dist/access-boundary.d.ts +17 -6
  2. package/dist/access-cli.js +1 -1
  3. package/dist/access-http.d.ts +17 -6
  4. package/dist/access-mcp.d.ts +17 -6
  5. package/dist/access-operations.d.ts +17 -6
  6. package/dist/{access-service-CdC0q4pr.d.ts → access-service-DwQ6BIQw.d.ts} +3 -3
  7. package/dist/access-service.d.ts +16 -5
  8. package/dist/access-surface-catalog.d.ts +17 -6
  9. package/dist/action-confidence.d.ts +1 -1
  10. package/dist/active-memory-bridge.d.ts +1 -1
  11. package/dist/active-recall.d.ts +1 -1
  12. package/dist/behavior-learner.d.ts +1 -1
  13. package/dist/behavior-signals.d.ts +1 -1
  14. package/dist/bootstrap.d.ts +16 -4
  15. package/dist/briefing.d.ts +1 -1
  16. package/dist/buffer-surprise-report.d.ts +1 -1
  17. package/dist/buffer.d.ts +1 -1
  18. package/dist/calibration.d.ts +1 -1
  19. package/dist/capabilities.d.ts +1 -1
  20. package/dist/{catalog-D2NLDg4S.d.ts → catalog-_Bap6vfD.d.ts} +1 -1
  21. package/dist/causal-behavior.d.ts +1 -1
  22. package/dist/causal-consolidation.d.ts +1 -1
  23. package/dist/causal-trajectory-graph.d.ts +1 -1
  24. package/dist/{chunk-AE2HPUP7.js → chunk-PB5YON2G.js} +352 -297
  25. package/dist/chunk-PB5YON2G.js.map +1 -0
  26. package/dist/{cli-BHy6Bo6u.d.ts → cli-BlEIWDQw.d.ts} +3 -3
  27. package/dist/cli.d.ts +9 -7
  28. package/dist/compounding/engine.d.ts +1 -1
  29. package/dist/compounding/preference-consolidator.d.ts +1 -1
  30. package/dist/compression-optimizer.d.ts +1 -1
  31. package/dist/config.d.ts +1 -1
  32. package/dist/connectors/codex-materialize-runner.d.ts +1 -1
  33. package/dist/connectors/codex-materialize.d.ts +1 -1
  34. package/dist/connectors/index.d.ts +1 -1
  35. package/dist/consolidation-provenance-check.d.ts +1 -1
  36. package/dist/consolidation-undo.d.ts +1 -1
  37. package/dist/contradiction/index.d.ts +1 -1
  38. package/dist/conversation-index/backend.d.ts +1 -1
  39. package/dist/conversation-index/chunker.d.ts +1 -1
  40. package/dist/conversation-index/faiss-adapter.d.ts +1 -1
  41. package/dist/conversation-index/indexer.d.ts +1 -1
  42. package/dist/conversation-index/search.d.ts +1 -1
  43. package/dist/day-summary.d.ts +1 -1
  44. package/dist/delinearize.d.ts +1 -1
  45. package/dist/direct-answer-wiring.d.ts +1 -1
  46. package/dist/direct-answer.d.ts +1 -1
  47. package/dist/embedding-fallback.d.ts +1 -1
  48. package/dist/enrichment/index.d.ts +1 -1
  49. package/dist/entity-retrieval.d.ts +1 -1
  50. package/dist/entity-schema.d.ts +1 -1
  51. package/dist/explicit-capture.d.ts +16 -4
  52. package/dist/extraction-faithfulness.d.ts +1 -1
  53. package/dist/extraction-judge-telemetry.d.ts +1 -1
  54. package/dist/extraction-judge-training.d.ts +1 -1
  55. package/dist/extraction-judge.d.ts +1 -1
  56. package/dist/extraction.d.ts +1 -1
  57. package/dist/fallback-llm.d.ts +1 -1
  58. package/dist/graph-dashboard-diff.d.ts +1 -1
  59. package/dist/graph-dashboard-key.d.ts +1 -1
  60. package/dist/graph-dashboard-parser.d.ts +1 -1
  61. package/dist/graph-edge-reinforcement.d.ts +1 -1
  62. package/dist/graph-snapshot.d.ts +1 -1
  63. package/dist/graph.d.ts +1 -1
  64. package/dist/identity-continuity.d.ts +1 -1
  65. package/dist/importance.d.ts +1 -1
  66. package/dist/index.d.ts +20 -18
  67. package/dist/index.js +1 -1
  68. package/dist/intent.d.ts +1 -1
  69. package/dist/lcm/engine.d.ts +1 -1
  70. package/dist/lcm/index.d.ts +1 -1
  71. package/dist/lcm/tools.d.ts +1 -1
  72. package/dist/lifecycle.d.ts +1 -1
  73. package/dist/live-connectors-runner.d.ts +1 -1
  74. package/dist/local-llm.d.ts +1 -1
  75. package/dist/local-model-endpoint.d.ts +1 -1
  76. package/dist/maintenance/memory-governance.d.ts +1 -1
  77. package/dist/mcp-memory-inspector-app.d.ts +17 -6
  78. package/dist/memory-action-policy.d.ts +1 -1
  79. package/dist/memory-cache.d.ts +1 -1
  80. package/dist/memory-lifecycle-ledger-utils.d.ts +1 -1
  81. package/dist/memory-projection-store.d.ts +1 -1
  82. package/dist/memory-provenance.d.ts +1 -1
  83. package/dist/memory-worth-outcomes.d.ts +1 -1
  84. package/dist/models-json.d.ts +1 -1
  85. package/dist/namespaces/migrate.d.ts +2 -2
  86. package/dist/namespaces/principal.d.ts +1 -1
  87. package/dist/namespaces/search.d.ts +1 -1
  88. package/dist/namespaces/storage.d.ts +2 -2
  89. package/dist/native-knowledge.d.ts +1 -1
  90. package/dist/operator-toolkit.d.ts +1 -1
  91. package/dist/orchestration/compression-guideline-coordinator.d.ts +1 -1
  92. package/dist/orchestration/maintenance.d.ts +2 -2
  93. package/dist/{orchestrator-C-xp_rtZ.d.ts → orchestrator-CJZ21ZiB.d.ts} +78 -12
  94. package/dist/orchestrator.d.ts +16 -4
  95. package/dist/orchestrator.js +1 -1
  96. package/dist/patterns-cli.d.ts +1 -1
  97. package/dist/policy-runtime.d.ts +1 -1
  98. package/dist/provenance.d.ts +1 -1
  99. package/dist/qmd-recall-cache.d.ts +1 -1
  100. package/dist/qmd.d.ts +1 -1
  101. package/dist/recall-disclosure-escalation.d.ts +1 -1
  102. package/dist/recall-explain-renderer.d.ts +1 -1
  103. package/dist/recall-planner-llm.d.ts +1 -1
  104. package/dist/recall-state.d.ts +1 -1
  105. package/dist/recall-tag-filter.d.ts +1 -1
  106. package/dist/recall-xray-cli.d.ts +1 -1
  107. package/dist/recall-xray-renderer.d.ts +1 -1
  108. package/dist/recall-xray.d.ts +1 -1
  109. package/dist/resolve-auth-token.d.ts +1 -1
  110. package/dist/retrieval-agents.d.ts +1 -1
  111. package/dist/retrieval-tiers.d.ts +1 -1
  112. package/dist/routing/engine.d.ts +1 -1
  113. package/dist/routing/store.d.ts +1 -1
  114. package/dist/search/embed-helper.d.ts +1 -1
  115. package/dist/search/factory.d.ts +1 -1
  116. package/dist/search/index.d.ts +1 -1
  117. package/dist/search/lancedb-backend.d.ts +1 -1
  118. package/dist/search/meilisearch-backend.d.ts +1 -1
  119. package/dist/search/noop-backend.d.ts +1 -1
  120. package/dist/search/orama-backend.d.ts +1 -1
  121. package/dist/search/port.d.ts +1 -1
  122. package/dist/search/remote-backend.d.ts +1 -1
  123. package/dist/{semantic-consolidation-COdwU-me.d.ts → semantic-consolidation-DsIEiCka.d.ts} +1 -1
  124. package/dist/semantic-consolidation.d.ts +2 -2
  125. package/dist/semantic-rule-verifier.d.ts +1 -1
  126. package/dist/session-observer-bands.d.ts +1 -1
  127. package/dist/session-observer-state.d.ts +1 -1
  128. package/dist/shared-context/manager.d.ts +1 -1
  129. package/dist/signal.d.ts +1 -1
  130. package/dist/storage.d.ts +1 -1
  131. package/dist/summarizer.d.ts +1 -1
  132. package/dist/summary-snapshot.d.ts +1 -1
  133. package/dist/temporal-supersession.d.ts +1 -1
  134. package/dist/temporal-validity.d.ts +1 -1
  135. package/dist/threading.d.ts +1 -1
  136. package/dist/tier-migration.d.ts +1 -1
  137. package/dist/tier-routing.d.ts +1 -1
  138. package/dist/topics.d.ts +1 -1
  139. package/dist/transcript.d.ts +1 -1
  140. package/dist/trust-score-stage.d.ts +2 -2
  141. package/dist/trust-score.d.ts +1 -1
  142. package/dist/{types-w3Y232yi.d.ts → types-CglNn2V-.d.ts} +1 -1
  143. package/dist/types.d.ts +1 -1
  144. package/dist/utility-runtime.d.ts +1 -1
  145. package/package.json +2 -2
  146. package/src/orchestration/recall-result-formatter.ts +438 -0
  147. package/src/orchestrator.ts +22 -305
  148. package/dist/chunk-AE2HPUP7.js.map +0 -1
@@ -1626,6 +1626,319 @@ ${evidenceText}`
1626
1626
  }
1627
1627
  };
1628
1628
 
1629
+ // src/orchestration/recall-result-formatter.ts
1630
+ function hasIdentityRecoveryIntent(prompt) {
1631
+ const text = typeof prompt === "string" ? prompt.toLowerCase() : "";
1632
+ if (!text) return false;
1633
+ return /\b(identity|continuity|recover(?:y|ing|ed)?|incident|drift|restore|regress(?:ion|ed|ing)?)\b/i.test(
1634
+ text
1635
+ );
1636
+ }
1637
+ function resolveEffectiveIdentityInjectionMode(options) {
1638
+ if (options.configuredMode === "recovery_only" && !hasIdentityRecoveryIntent(options.prompt)) {
1639
+ return { mode: "recovery_only", shouldInject: false };
1640
+ }
1641
+ if (options.recallMode === "minimal" && options.configuredMode === "full") {
1642
+ return { mode: "minimal", shouldInject: true };
1643
+ }
1644
+ return { mode: options.configuredMode, shouldInject: true };
1645
+ }
1646
+ var RecallResultFormatter = class {
1647
+ constructor(config) {
1648
+ this.config = config;
1649
+ }
1650
+ config;
1651
+ // ── QMD results (memory handles + epistemic hedge) ──────────────────────
1652
+ formatQmdResults(title, results, sessionKey, trustByPath) {
1653
+ const handleByIndex = buildHandleIndexForResults(
1654
+ results,
1655
+ this.config.recallMemoryHandles === true && sessionKey != null
1656
+ );
1657
+ const renderHedge = this.config.trustScoreEpistemicRendering && trustByPath !== null && trustByPath !== void 0;
1658
+ const hedgeMap = renderHedge ? trustByPath : null;
1659
+ const lines = results.map((r, i) => {
1660
+ const snippet = r.snippet ? r.snippet.slice(0, 500).replace(/\n/g, " ") : "(no preview)";
1661
+ const source = typeof r.line === "number" ? `${r.path}:${r.line}` : r.path;
1662
+ const head = `[${i + 1}] ${source} (score: ${r.score.toFixed(3)})
1663
+ ${snippet}`;
1664
+ const handle = handleByIndex.get(i);
1665
+ const hedged = head.replace(/\s+$/, "");
1666
+ const withHandle = handle ? `${hedged} ${handle}` : hedged;
1667
+ if (hedgeMap) {
1668
+ const item = hedgeMap.get(r.path);
1669
+ if (item) {
1670
+ const hedge = renderEpistemicHedge(item.trust);
1671
+ if (hedge.length > 0) return `${withHandle} ${hedge}`;
1672
+ }
1673
+ }
1674
+ return withHandle;
1675
+ });
1676
+ return `## ${title}
1677
+
1678
+ ${lines.join("\n\n")}`;
1679
+ }
1680
+ // ── Specialized recall result formatters ────────────────────────────────
1681
+ formatObjectiveStateResults(results) {
1682
+ const lines = results.map(({ snapshot }, index) => {
1683
+ const parts = [
1684
+ snapshot.recordedAt.replace("T", " ").slice(0, 16),
1685
+ `${snapshot.kind}/${snapshot.changeKind}`
1686
+ ];
1687
+ if (snapshot.outcome) parts.push(snapshot.outcome);
1688
+ const header = `[${index + 1}] ${parts.join(" | ")} | ${snapshot.scope}`;
1689
+ const detailParts = [snapshot.summary];
1690
+ if (snapshot.command) detailParts.push(`command: ${snapshot.command}`);
1691
+ else if (snapshot.toolName)
1692
+ detailParts.push(`tool: ${snapshot.toolName}`);
1693
+ return `${header}
1694
+ ${detailParts.join(" | ")}`;
1695
+ });
1696
+ return `## Objective State
1697
+
1698
+ ${lines.join("\n\n")}`;
1699
+ }
1700
+ formatCausalTrajectoryResults(results) {
1701
+ const lines = results.map(({ record, matchedFields }, index) => {
1702
+ const header = [
1703
+ `[${index + 1}] ${record.recordedAt.replace("T", " ").slice(0, 16)}`,
1704
+ record.outcomeKind
1705
+ ].join(" | ");
1706
+ const details = [
1707
+ `goal: ${record.goal}`,
1708
+ `action: ${record.actionSummary}`,
1709
+ `observation: ${record.observationSummary}`,
1710
+ `outcome: ${record.outcomeSummary}`
1711
+ ];
1712
+ if (record.followUpSummary)
1713
+ details.push(`follow-up: ${record.followUpSummary}`);
1714
+ if (matchedFields.length > 0)
1715
+ details.push(`matched: ${matchedFields.join(", ")}`);
1716
+ return `${header}
1717
+ ${details.join("\n")}`;
1718
+ });
1719
+ return `## Causal Trajectories
1720
+
1721
+ ${lines.join("\n\n")}`;
1722
+ }
1723
+ formatTrustZoneResults(results) {
1724
+ const lines = results.map(({ record, matchedFields }, index) => {
1725
+ const header = [
1726
+ `[${index + 1}] ${record.recordedAt.replace("T", " ").slice(0, 16)}`,
1727
+ record.zone,
1728
+ record.kind
1729
+ ].join(" | ");
1730
+ const details = [
1731
+ record.summary,
1732
+ `provenance: ${record.provenance.sourceClass}`
1733
+ ];
1734
+ if (record.entityRefs && record.entityRefs.length > 0) {
1735
+ details.push(`entities: ${record.entityRefs.join(", ")}`);
1736
+ }
1737
+ if (record.tags && record.tags.length > 0) {
1738
+ details.push(`tags: ${record.tags.join(", ")}`);
1739
+ }
1740
+ if (matchedFields.length > 0) {
1741
+ details.push(`matched: ${matchedFields.join(", ")}`);
1742
+ }
1743
+ return `${header}
1744
+ ${details.join("\n")}`;
1745
+ });
1746
+ return `## Trust Zones
1747
+
1748
+ ${lines.join("\n\n")}`;
1749
+ }
1750
+ formatHarmonicRetrievalResults(results) {
1751
+ const lines = results.map(
1752
+ ({ node, matchedAnchors, matchedFields, nodeScore, anchorScore }, index) => {
1753
+ const header = [
1754
+ `[${index + 1}] ${node.recordedAt.replace("T", " ").slice(0, 16)}`,
1755
+ `${node.kind}/${node.abstractionLevel}`,
1756
+ node.sessionKey
1757
+ ].join(" | ");
1758
+ const details = [
1759
+ node.title,
1760
+ node.summary,
1761
+ `scores: node=${nodeScore.toFixed(1)} anchor=${anchorScore.toFixed(1)}`
1762
+ ];
1763
+ if (matchedAnchors.length > 0) {
1764
+ details.push(
1765
+ `anchors: ${matchedAnchors.map((anchor) => `${anchor.anchorType}:${anchor.anchorValue}`).join("; ")}`
1766
+ );
1767
+ }
1768
+ if (matchedFields.length > 0) {
1769
+ details.push(`matched: ${matchedFields.join(", ")}`);
1770
+ }
1771
+ return `${header}
1772
+ ${details.join("\n")}`;
1773
+ }
1774
+ );
1775
+ return `## Harmonic Retrieval
1776
+
1777
+ ${lines.join("\n\n")}`;
1778
+ }
1779
+ formatWorkProductResults(results) {
1780
+ const lines = results.map(({ entry, matchedFields }, index) => {
1781
+ const header = [
1782
+ `[${index + 1}] ${entry.recordedAt.replace("T", " ").slice(0, 16)}`,
1783
+ `${entry.kind}/${entry.action}`,
1784
+ entry.sessionKey
1785
+ ].join(" | ");
1786
+ const details = [entry.summary, `scope: ${entry.scope}`];
1787
+ if (entry.artifactPath) details.push(`artifact: ${entry.artifactPath}`);
1788
+ if (entry.tags && entry.tags.length > 0)
1789
+ details.push(`tags: ${entry.tags.join(", ")}`);
1790
+ if (matchedFields.length > 0)
1791
+ details.push(`matched: ${matchedFields.join(", ")}`);
1792
+ return `${header}
1793
+ ${details.join("\n")}`;
1794
+ });
1795
+ return `## Work Products
1796
+
1797
+ ${lines.join("\n\n")}`;
1798
+ }
1799
+ formatVerifiedEpisodeResults(results) {
1800
+ const lines = results.map(
1801
+ ({ box, verifiedEpisodeCount, matchedFields }, index) => {
1802
+ const header = [
1803
+ `[${index + 1}] ${box.sealedAt.replace("T", " ").slice(0, 16)}`,
1804
+ box.traceId ? `trace:${box.traceId.slice(0, 12)}` : "trace:none"
1805
+ ].join(" | ");
1806
+ const details = [
1807
+ box.goal ?? `topics: ${box.topics.join(", ")}`,
1808
+ `verified episodes: ${verifiedEpisodeCount}`
1809
+ ];
1810
+ if (box.toolsUsed && box.toolsUsed.length > 0) {
1811
+ details.push(`tools: ${box.toolsUsed.join(", ")}`);
1812
+ }
1813
+ if (matchedFields.length > 0) {
1814
+ details.push(`matched: ${matchedFields.join(", ")}`);
1815
+ }
1816
+ return `${header}
1817
+ ${details.join("\n")}`;
1818
+ }
1819
+ );
1820
+ return `## Verified Episodes
1821
+
1822
+ ${lines.join("\n\n")}`;
1823
+ }
1824
+ formatVerifiedSemanticRuleResults(results) {
1825
+ const lines = results.map(
1826
+ ({
1827
+ rule,
1828
+ sourceMemoryId,
1829
+ verificationStatus,
1830
+ effectiveConfidence,
1831
+ matchedFields
1832
+ }, index) => {
1833
+ const header = [
1834
+ `[${index + 1}] ${rule.frontmatter.updated.replace("T", " ").slice(0, 16)}`,
1835
+ verificationStatus,
1836
+ `confidence:${effectiveConfidence.toFixed(2)}`
1837
+ ].join(" | ");
1838
+ const details = [rule.content, `source memory: ${sourceMemoryId}`];
1839
+ if (matchedFields.length > 0) {
1840
+ details.push(`matched: ${matchedFields.join(", ")}`);
1841
+ }
1842
+ return `${header}
1843
+ ${details.join("\n")}`;
1844
+ }
1845
+ );
1846
+ return `## Verified Rules
1847
+
1848
+ ${lines.join("\n\n")}`;
1849
+ }
1850
+ // ── Identity continuity helpers ─────────────────────────────────────────
1851
+ summarizeIdentityText(raw, maxLines, maxChars) {
1852
+ const lines = raw.replace(/\r/g, "").split("\n").map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("#"));
1853
+ const compact = lines.slice(0, Math.max(1, maxLines)).join(" ");
1854
+ if (compact.length <= maxChars) return compact;
1855
+ return `${compact.slice(0, Math.max(0, maxChars - 1))}\u2026`;
1856
+ }
1857
+ formatOpenIncidentLine(incident, includeDetails) {
1858
+ const base = `[${incident.id}] ${incident.symptom.trim()}`;
1859
+ if (!includeDetails) return `- ${base}`;
1860
+ const parts = [base];
1861
+ if (incident.suspectedCause)
1862
+ parts.push(`cause: ${incident.suspectedCause.trim()}`);
1863
+ if (incident.triggerWindow)
1864
+ parts.push(`window: ${incident.triggerWindow.trim()}`);
1865
+ return `- ${parts.join(" | ")}`;
1866
+ }
1867
+ trimIdentitySection(content, maxChars) {
1868
+ if (maxChars <= 0) return { text: "", truncated: false };
1869
+ if (content.length <= maxChars) return { text: content, truncated: false };
1870
+ const suffix = "\n\n...(identity continuity trimmed)";
1871
+ if (maxChars <= suffix.length) {
1872
+ return { text: content.slice(0, maxChars), truncated: true };
1873
+ }
1874
+ const headroom = Math.max(0, maxChars - suffix.length);
1875
+ return { text: `${content.slice(0, headroom)}${suffix}`, truncated: true };
1876
+ }
1877
+ async buildIdentityContinuitySection(options) {
1878
+ if (!resolveIdentityContinuityCapabilities(this.config).identityContinuity) return null;
1879
+ if (this.config.identityMaxInjectChars <= 0) return null;
1880
+ const resolved = resolveEffectiveIdentityInjectionMode({
1881
+ configuredMode: this.config.identityInjectionMode,
1882
+ recallMode: options.recallMode,
1883
+ prompt: options.prompt
1884
+ });
1885
+ if (!resolved.shouldInject) return null;
1886
+ const [anchorRaw, loopsRaw, incidents] = await Promise.all([
1887
+ options.storage.readIdentityAnchor(),
1888
+ options.storage.readIdentityImprovementLoops(),
1889
+ options.storage.readContinuityIncidents(200)
1890
+ ]);
1891
+ const openIncidents = incidents.filter(
1892
+ (incident) => incident.state === "open"
1893
+ );
1894
+ const lines = [];
1895
+ if (resolved.mode === "full") {
1896
+ lines.push("## Identity Continuity");
1897
+ if (anchorRaw && anchorRaw.trim().length > 0) {
1898
+ lines.push("", "### Anchor", "", anchorRaw.trim());
1899
+ }
1900
+ if (loopsRaw && loopsRaw.trim().length > 0) {
1901
+ lines.push("", "### Improvement Loops", "", loopsRaw.trim());
1902
+ }
1903
+ lines.push("", "### Open Incidents", "");
1904
+ if (openIncidents.length === 0) {
1905
+ lines.push("- none");
1906
+ } else {
1907
+ lines.push(
1908
+ ...openIncidents.slice(0, 5).map((incident) => this.formatOpenIncidentLine(incident, true))
1909
+ );
1910
+ }
1911
+ } else {
1912
+ const anchorSummary = anchorRaw ? this.summarizeIdentityText(anchorRaw, 3, 320) : "";
1913
+ const loopsSummary = loopsRaw ? this.summarizeIdentityText(loopsRaw, 2, 240) : "";
1914
+ lines.push("## Identity Continuity Signals", "");
1915
+ if (anchorSummary) lines.push(`- anchor: ${anchorSummary}`);
1916
+ if (loopsSummary) lines.push(`- loops: ${loopsSummary}`);
1917
+ if (openIncidents.length === 0) {
1918
+ lines.push("- incidents: 0 open");
1919
+ } else {
1920
+ lines.push(`- incidents: ${openIncidents.length} open`);
1921
+ lines.push(
1922
+ ...openIncidents.slice(0, 2).map((incident) => this.formatOpenIncidentLine(incident, false))
1923
+ );
1924
+ }
1925
+ }
1926
+ const body = lines.join("\n").trim();
1927
+ if (!body) return null;
1928
+ const { text, truncated } = this.trimIdentitySection(
1929
+ body,
1930
+ this.config.identityMaxInjectChars
1931
+ );
1932
+ if (!text) return null;
1933
+ return {
1934
+ section: text,
1935
+ mode: resolved.mode,
1936
+ injectedChars: text.length,
1937
+ truncated
1938
+ };
1939
+ }
1940
+ };
1941
+
1629
1942
  // src/maintenance/pattern-reinforcement.ts
1630
1943
  function patternReinforcementKey(content) {
1631
1944
  return content.trim().toLowerCase().replace(/\s+/g, " ").slice(0, 200);
@@ -3411,22 +3724,6 @@ async function resolveRecallModeDecisionAsync(options) {
3411
3724
  plannerHeuristicMode: planned.heuristicMode
3412
3725
  };
3413
3726
  }
3414
- function hasIdentityRecoveryIntent(prompt) {
3415
- const text = typeof prompt === "string" ? prompt.toLowerCase() : "";
3416
- if (!text) return false;
3417
- return /\b(identity|continuity|recover(?:y|ing|ed)?|incident|drift|restore|regress(?:ion|ed|ing)?)\b/i.test(
3418
- text
3419
- );
3420
- }
3421
- function resolveEffectiveIdentityInjectionMode(options) {
3422
- if (options.configuredMode === "recovery_only" && !hasIdentityRecoveryIntent(options.prompt)) {
3423
- return { mode: "recovery_only", shouldInject: false };
3424
- }
3425
- if (options.recallMode === "minimal" && options.configuredMode === "full") {
3426
- return { mode: "minimal", shouldInject: true };
3427
- }
3428
- return { mode: options.configuredMode, shouldInject: true };
3429
- }
3430
3727
  function computeArtifactCandidateFetchLimit(targetCount) {
3431
3728
  const cappedTarget = Math.max(0, targetCount);
3432
3729
  if (cappedTarget === 0) return 0;
@@ -3811,6 +4108,11 @@ var Orchestrator = class _Orchestrator {
3811
4108
  * hands it to `enqueue`.
3812
4109
  */
3813
4110
  extractionQueueCoordinator;
4111
+ /**
4112
+ * Issue #1526: recall result formatting + identity continuity section moved
4113
+ * to RecallResultFormatter.
4114
+ */
4115
+ recallResultFormatter;
3814
4116
  heartbeatObserverChains = /* @__PURE__ */ new Map();
3815
4117
  recentExtractionFingerprints = /* @__PURE__ */ new Map();
3816
4118
  consolidationObservers = /* @__PURE__ */ new Set();
@@ -4516,6 +4818,7 @@ var Orchestrator = class _Orchestrator {
4516
4818
  namespaceCatalog: this.namespaceCatalog
4517
4819
  });
4518
4820
  this.extractionQueueCoordinator = new ExtractionQueueCoordinator();
4821
+ this.recallResultFormatter = new RecallResultFormatter(this.config);
4519
4822
  const conversationIndexRuntime = createConversationIndexRuntime(config, {
4520
4823
  getQmd: () => this.conversationQmd,
4521
4824
  getFaiss: () => this.conversationFaiss
@@ -14361,306 +14664,58 @@ ${reflectionsContent.trim()}
14361
14664
  const patternsSection = [
14362
14665
  "## Learned Patterns (consolidated from reflections, " + (/* @__PURE__ */ new Date()).toISOString().slice(0, 10) + ")",
14363
14666
  "",
14364
- ...result.learnedPatterns.map((p) => `- ${p}`),
14365
- ""
14366
- ].join("\n");
14367
- const newContent = staticHeader + "\n\n" + patternsSection + "\n";
14368
- await storage.writeIdentity(
14369
- this.config.workspaceDir,
14370
- newContent,
14371
- identityNamespace
14372
- );
14373
- await storage.writeIdentityReflections("");
14374
- log.info(
14375
- `IDENTITY(${namespace}) consolidated: ${identityContent.length} \u2192 ${newContent.length} chars, ${result.learnedPatterns.length} patterns`
14376
- );
14377
- }
14378
- }
14379
- formatQmdResults(title, results, sessionKey, trustByPath) {
14380
- const handleByIndex = buildHandleIndexForResults(
14381
- results,
14382
- this.config.recallMemoryHandles === true && sessionKey != null
14383
- );
14384
- const renderHedge = this.config.trustScoreEpistemicRendering && trustByPath !== null && trustByPath !== void 0;
14385
- const hedgeMap = renderHedge ? trustByPath : null;
14386
- const lines = results.map((r, i) => {
14387
- const snippet = r.snippet ? r.snippet.slice(0, 500).replace(/\n/g, " ") : "(no preview)";
14388
- const source = typeof r.line === "number" ? `${r.path}:${r.line}` : r.path;
14389
- const head = `[${i + 1}] ${source} (score: ${r.score.toFixed(3)})
14390
- ${snippet}`;
14391
- const handle = handleByIndex.get(i);
14392
- const hedged = head.replace(/\s+$/, "");
14393
- const withHandle = handle ? `${hedged} ${handle}` : hedged;
14394
- if (hedgeMap) {
14395
- const item = hedgeMap.get(r.path);
14396
- if (item) {
14397
- const hedge = renderEpistemicHedge(item.trust);
14398
- if (hedge.length > 0) return `${withHandle} ${hedge}`;
14399
- }
14400
- }
14401
- return withHandle;
14402
- });
14403
- return `## ${title}
14404
-
14405
- ${lines.join("\n\n")}`;
14667
+ ...result.learnedPatterns.map((p) => `- ${p}`),
14668
+ ""
14669
+ ].join("\n");
14670
+ const newContent = staticHeader + "\n\n" + patternsSection + "\n";
14671
+ await storage.writeIdentity(
14672
+ this.config.workspaceDir,
14673
+ newContent,
14674
+ identityNamespace
14675
+ );
14676
+ await storage.writeIdentityReflections("");
14677
+ log.info(
14678
+ `IDENTITY(${namespace}) consolidated: ${identityContent.length} \u2192 ${newContent.length} chars, ${result.learnedPatterns.length} patterns`
14679
+ );
14680
+ }
14681
+ }
14682
+ // Issue #1526: recall result formatting moved to RecallResultFormatter. Thin
14683
+ // delegation keeps the private API stable for callers + tests.
14684
+ formatQmdResults(title, results, sessionKey, trustByPath) {
14685
+ return this.recallResultFormatter.formatQmdResults(title, results, sessionKey, trustByPath);
14406
14686
  }
14407
14687
  formatObjectiveStateResults(results) {
14408
- const lines = results.map(({ snapshot }, index) => {
14409
- const parts = [
14410
- snapshot.recordedAt.replace("T", " ").slice(0, 16),
14411
- `${snapshot.kind}/${snapshot.changeKind}`
14412
- ];
14413
- if (snapshot.outcome) parts.push(snapshot.outcome);
14414
- const header = `[${index + 1}] ${parts.join(" | ")} | ${snapshot.scope}`;
14415
- const detailParts = [snapshot.summary];
14416
- if (snapshot.command) detailParts.push(`command: ${snapshot.command}`);
14417
- else if (snapshot.toolName)
14418
- detailParts.push(`tool: ${snapshot.toolName}`);
14419
- return `${header}
14420
- ${detailParts.join(" | ")}`;
14421
- });
14422
- return `## Objective State
14423
-
14424
- ${lines.join("\n\n")}`;
14688
+ return this.recallResultFormatter.formatObjectiveStateResults(results);
14425
14689
  }
14426
14690
  formatCausalTrajectoryResults(results) {
14427
- const lines = results.map(({ record, matchedFields }, index) => {
14428
- const header = [
14429
- `[${index + 1}] ${record.recordedAt.replace("T", " ").slice(0, 16)}`,
14430
- record.outcomeKind
14431
- ].join(" | ");
14432
- const details = [
14433
- `goal: ${record.goal}`,
14434
- `action: ${record.actionSummary}`,
14435
- `observation: ${record.observationSummary}`,
14436
- `outcome: ${record.outcomeSummary}`
14437
- ];
14438
- if (record.followUpSummary)
14439
- details.push(`follow-up: ${record.followUpSummary}`);
14440
- if (matchedFields.length > 0)
14441
- details.push(`matched: ${matchedFields.join(", ")}`);
14442
- return `${header}
14443
- ${details.join("\n")}`;
14444
- });
14445
- return `## Causal Trajectories
14446
-
14447
- ${lines.join("\n\n")}`;
14691
+ return this.recallResultFormatter.formatCausalTrajectoryResults(results);
14448
14692
  }
14449
14693
  formatTrustZoneResults(results) {
14450
- const lines = results.map(({ record, matchedFields }, index) => {
14451
- const header = [
14452
- `[${index + 1}] ${record.recordedAt.replace("T", " ").slice(0, 16)}`,
14453
- record.zone,
14454
- record.kind
14455
- ].join(" | ");
14456
- const details = [
14457
- record.summary,
14458
- `provenance: ${record.provenance.sourceClass}`
14459
- ];
14460
- if (record.entityRefs && record.entityRefs.length > 0) {
14461
- details.push(`entities: ${record.entityRefs.join(", ")}`);
14462
- }
14463
- if (record.tags && record.tags.length > 0) {
14464
- details.push(`tags: ${record.tags.join(", ")}`);
14465
- }
14466
- if (matchedFields.length > 0) {
14467
- details.push(`matched: ${matchedFields.join(", ")}`);
14468
- }
14469
- return `${header}
14470
- ${details.join("\n")}`;
14471
- });
14472
- return `## Trust Zones
14473
-
14474
- ${lines.join("\n\n")}`;
14694
+ return this.recallResultFormatter.formatTrustZoneResults(results);
14475
14695
  }
14476
14696
  formatHarmonicRetrievalResults(results) {
14477
- const lines = results.map(
14478
- ({ node, matchedAnchors, matchedFields, nodeScore, anchorScore }, index) => {
14479
- const header = [
14480
- `[${index + 1}] ${node.recordedAt.replace("T", " ").slice(0, 16)}`,
14481
- `${node.kind}/${node.abstractionLevel}`,
14482
- node.sessionKey
14483
- ].join(" | ");
14484
- const details = [
14485
- node.title,
14486
- node.summary,
14487
- `scores: node=${nodeScore.toFixed(1)} anchor=${anchorScore.toFixed(1)}`
14488
- ];
14489
- if (matchedAnchors.length > 0) {
14490
- details.push(
14491
- `anchors: ${matchedAnchors.map((anchor) => `${anchor.anchorType}:${anchor.anchorValue}`).join("; ")}`
14492
- );
14493
- }
14494
- if (matchedFields.length > 0) {
14495
- details.push(`matched: ${matchedFields.join(", ")}`);
14496
- }
14497
- return `${header}
14498
- ${details.join("\n")}`;
14499
- }
14500
- );
14501
- return `## Harmonic Retrieval
14502
-
14503
- ${lines.join("\n\n")}`;
14697
+ return this.recallResultFormatter.formatHarmonicRetrievalResults(results);
14504
14698
  }
14505
14699
  formatWorkProductResults(results) {
14506
- const lines = results.map(({ entry, matchedFields }, index) => {
14507
- const header = [
14508
- `[${index + 1}] ${entry.recordedAt.replace("T", " ").slice(0, 16)}`,
14509
- `${entry.kind}/${entry.action}`,
14510
- entry.sessionKey
14511
- ].join(" | ");
14512
- const details = [entry.summary, `scope: ${entry.scope}`];
14513
- if (entry.artifactPath) details.push(`artifact: ${entry.artifactPath}`);
14514
- if (entry.tags && entry.tags.length > 0)
14515
- details.push(`tags: ${entry.tags.join(", ")}`);
14516
- if (matchedFields.length > 0)
14517
- details.push(`matched: ${matchedFields.join(", ")}`);
14518
- return `${header}
14519
- ${details.join("\n")}`;
14520
- });
14521
- return `## Work Products
14522
-
14523
- ${lines.join("\n\n")}`;
14700
+ return this.recallResultFormatter.formatWorkProductResults(results);
14524
14701
  }
14525
14702
  formatVerifiedEpisodeResults(results) {
14526
- const lines = results.map(
14527
- ({ box, verifiedEpisodeCount, matchedFields }, index) => {
14528
- const header = [
14529
- `[${index + 1}] ${box.sealedAt.replace("T", " ").slice(0, 16)}`,
14530
- box.traceId ? `trace:${box.traceId.slice(0, 12)}` : "trace:none"
14531
- ].join(" | ");
14532
- const details = [
14533
- box.goal ?? `topics: ${box.topics.join(", ")}`,
14534
- `verified episodes: ${verifiedEpisodeCount}`
14535
- ];
14536
- if (box.toolsUsed && box.toolsUsed.length > 0) {
14537
- details.push(`tools: ${box.toolsUsed.join(", ")}`);
14538
- }
14539
- if (matchedFields.length > 0) {
14540
- details.push(`matched: ${matchedFields.join(", ")}`);
14541
- }
14542
- return `${header}
14543
- ${details.join("\n")}`;
14544
- }
14545
- );
14546
- return `## Verified Episodes
14547
-
14548
- ${lines.join("\n\n")}`;
14703
+ return this.recallResultFormatter.formatVerifiedEpisodeResults(results);
14549
14704
  }
14550
14705
  formatVerifiedSemanticRuleResults(results) {
14551
- const lines = results.map(
14552
- ({
14553
- rule,
14554
- sourceMemoryId,
14555
- verificationStatus,
14556
- effectiveConfidence,
14557
- matchedFields
14558
- }, index) => {
14559
- const header = [
14560
- `[${index + 1}] ${rule.frontmatter.updated.replace("T", " ").slice(0, 16)}`,
14561
- verificationStatus,
14562
- `confidence:${effectiveConfidence.toFixed(2)}`
14563
- ].join(" | ");
14564
- const details = [rule.content, `source memory: ${sourceMemoryId}`];
14565
- if (matchedFields.length > 0) {
14566
- details.push(`matched: ${matchedFields.join(", ")}`);
14567
- }
14568
- return `${header}
14569
- ${details.join("\n")}`;
14570
- }
14571
- );
14572
- return `## Verified Rules
14573
-
14574
- ${lines.join("\n\n")}`;
14706
+ return this.recallResultFormatter.formatVerifiedSemanticRuleResults(results);
14575
14707
  }
14576
14708
  summarizeIdentityText(raw, maxLines, maxChars) {
14577
- const lines = raw.replace(/\r/g, "").split("\n").map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("#"));
14578
- const compact = lines.slice(0, Math.max(1, maxLines)).join(" ");
14579
- if (compact.length <= maxChars) return compact;
14580
- return `${compact.slice(0, Math.max(0, maxChars - 1))}\u2026`;
14709
+ return this.recallResultFormatter.summarizeIdentityText(raw, maxLines, maxChars);
14581
14710
  }
14582
14711
  formatOpenIncidentLine(incident, includeDetails) {
14583
- const base = `[${incident.id}] ${incident.symptom.trim()}`;
14584
- if (!includeDetails) return `- ${base}`;
14585
- const parts = [base];
14586
- if (incident.suspectedCause)
14587
- parts.push(`cause: ${incident.suspectedCause.trim()}`);
14588
- if (incident.triggerWindow)
14589
- parts.push(`window: ${incident.triggerWindow.trim()}`);
14590
- return `- ${parts.join(" | ")}`;
14712
+ return this.recallResultFormatter.formatOpenIncidentLine(incident, includeDetails);
14591
14713
  }
14592
14714
  trimIdentitySection(content, maxChars) {
14593
- if (maxChars <= 0) return { text: "", truncated: false };
14594
- if (content.length <= maxChars) return { text: content, truncated: false };
14595
- const suffix = "\n\n...(identity continuity trimmed)";
14596
- if (maxChars <= suffix.length) {
14597
- return { text: content.slice(0, maxChars), truncated: true };
14598
- }
14599
- const headroom = Math.max(0, maxChars - suffix.length);
14600
- return { text: `${content.slice(0, headroom)}${suffix}`, truncated: true };
14715
+ return this.recallResultFormatter.trimIdentitySection(content, maxChars);
14601
14716
  }
14602
14717
  async buildIdentityContinuitySection(options) {
14603
- if (!resolveIdentityContinuityCapabilities(this.config).identityContinuity) return null;
14604
- if (this.config.identityMaxInjectChars <= 0) return null;
14605
- const resolved = resolveEffectiveIdentityInjectionMode({
14606
- configuredMode: this.config.identityInjectionMode,
14607
- recallMode: options.recallMode,
14608
- prompt: options.prompt
14609
- });
14610
- if (!resolved.shouldInject) return null;
14611
- const [anchorRaw, loopsRaw, incidents] = await Promise.all([
14612
- options.storage.readIdentityAnchor(),
14613
- options.storage.readIdentityImprovementLoops(),
14614
- options.storage.readContinuityIncidents(200)
14615
- ]);
14616
- const openIncidents = incidents.filter(
14617
- (incident) => incident.state === "open"
14618
- );
14619
- const lines = [];
14620
- if (resolved.mode === "full") {
14621
- lines.push("## Identity Continuity");
14622
- if (anchorRaw && anchorRaw.trim().length > 0) {
14623
- lines.push("", "### Anchor", "", anchorRaw.trim());
14624
- }
14625
- if (loopsRaw && loopsRaw.trim().length > 0) {
14626
- lines.push("", "### Improvement Loops", "", loopsRaw.trim());
14627
- }
14628
- lines.push("", "### Open Incidents", "");
14629
- if (openIncidents.length === 0) {
14630
- lines.push("- none");
14631
- } else {
14632
- lines.push(
14633
- ...openIncidents.slice(0, 5).map((incident) => this.formatOpenIncidentLine(incident, true))
14634
- );
14635
- }
14636
- } else {
14637
- const anchorSummary = anchorRaw ? this.summarizeIdentityText(anchorRaw, 3, 320) : "";
14638
- const loopsSummary = loopsRaw ? this.summarizeIdentityText(loopsRaw, 2, 240) : "";
14639
- lines.push("## Identity Continuity Signals", "");
14640
- if (anchorSummary) lines.push(`- anchor: ${anchorSummary}`);
14641
- if (loopsSummary) lines.push(`- loops: ${loopsSummary}`);
14642
- if (openIncidents.length === 0) {
14643
- lines.push("- incidents: 0 open");
14644
- } else {
14645
- lines.push(`- incidents: ${openIncidents.length} open`);
14646
- lines.push(
14647
- ...openIncidents.slice(0, 2).map((incident) => this.formatOpenIncidentLine(incident, false))
14648
- );
14649
- }
14650
- }
14651
- const body = lines.join("\n").trim();
14652
- if (!body) return null;
14653
- const { text, truncated } = this.trimIdentitySection(
14654
- body,
14655
- this.config.identityMaxInjectChars
14656
- );
14657
- if (!text) return null;
14658
- return {
14659
- section: text,
14660
- mode: resolved.mode,
14661
- injectedChars: text.length,
14662
- truncated
14663
- };
14718
+ return this.recallResultFormatter.buildIdentityContinuitySection(options);
14664
14719
  }
14665
14720
  emitTrace(event) {
14666
14721
  try {
@@ -16339,6 +16394,8 @@ ${lines.join("\n\n")}`;
16339
16394
 
16340
16395
  export {
16341
16396
  buildProcedureRecallSection,
16397
+ hasIdentityRecoveryIntent,
16398
+ resolveEffectiveIdentityInjectionMode,
16342
16399
  decideSemanticDedup,
16343
16400
  DEFAULT_TAXONOMY,
16344
16401
  generateResolverDocument,
@@ -16368,8 +16425,6 @@ export {
16368
16425
  resolveEffectiveRecallMode,
16369
16426
  resolveRecallModeDecision,
16370
16427
  resolveRecallModeDecisionAsync,
16371
- hasIdentityRecoveryIntent,
16372
- resolveEffectiveIdentityInjectionMode,
16373
16428
  computeArtifactCandidateFetchLimit,
16374
16429
  computeQmdHybridFetchLimit,
16375
16430
  mergeGraphExpandedResults,
@@ -16383,4 +16438,4 @@ export {
16383
16438
  resolvePersistedMemoryRelativePath,
16384
16439
  Orchestrator
16385
16440
  };
16386
- //# sourceMappingURL=chunk-AE2HPUP7.js.map
16441
+ //# sourceMappingURL=chunk-PB5YON2G.js.map