@jungjaehoon/mama-core 1.5.0 → 1.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.
Files changed (78) hide show
  1. package/README.md +48 -10
  2. package/db/migrations/032-add-memory-provenance-columns.sql +21 -0
  3. package/db/migrations/033-create-model-runs-and-tool-traces.sql +53 -0
  4. package/db/migrations/034-add-connector-event-scope-columns.sql +14 -0
  5. package/db/migrations/035-create-twin-edges.sql +63 -0
  6. package/db/migrations/036-create-agent-situation-packets.sql +61 -0
  7. package/dist/agent-graph/alias-write.d.ts +3 -0
  8. package/dist/agent-graph/alias-write.js +231 -0
  9. package/dist/agent-graph/entity-resolve.d.ts +3 -0
  10. package/dist/agent-graph/entity-resolve.js +275 -0
  11. package/dist/agent-graph/errors.d.ts +4 -0
  12. package/dist/agent-graph/errors.js +11 -0
  13. package/dist/agent-graph/graph-query.d.ts +5 -0
  14. package/dist/agent-graph/graph-query.js +359 -0
  15. package/dist/agent-graph/index.d.ts +6 -0
  16. package/dist/agent-graph/index.js +22 -0
  17. package/dist/agent-graph/types.d.ts +162 -0
  18. package/dist/agent-graph/types.js +3 -0
  19. package/dist/agent-situation/builder.d.ts +8 -0
  20. package/dist/agent-situation/builder.js +239 -0
  21. package/dist/agent-situation/cache-key.d.ts +4 -0
  22. package/dist/agent-situation/cache-key.js +64 -0
  23. package/dist/agent-situation/index.d.ts +7 -0
  24. package/dist/agent-situation/index.js +28 -0
  25. package/dist/agent-situation/packet-store.d.ts +27 -0
  26. package/dist/agent-situation/packet-store.js +228 -0
  27. package/dist/agent-situation/ranking-policy.d.ts +18 -0
  28. package/dist/agent-situation/ranking-policy.js +75 -0
  29. package/dist/agent-situation/source-readers.d.ts +52 -0
  30. package/dist/agent-situation/source-readers.js +300 -0
  31. package/dist/agent-situation/types.d.ts +195 -0
  32. package/dist/agent-situation/types.js +3 -0
  33. package/dist/cases/search-rollup.d.ts +4 -0
  34. package/dist/cases/search-rollup.js +84 -0
  35. package/dist/connectors/event-index.d.ts +1 -0
  36. package/dist/connectors/event-index.js +19 -4
  37. package/dist/connectors/raw-query.d.ts +18 -0
  38. package/dist/connectors/raw-query.js +305 -0
  39. package/dist/connectors/types.d.ts +40 -0
  40. package/dist/db-adapter/node-sqlite-adapter.d.ts +6 -0
  41. package/dist/db-adapter/node-sqlite-adapter.js +131 -0
  42. package/dist/db-manager.d.ts +8 -1
  43. package/dist/db-manager.js +53 -5
  44. package/dist/edges/ref-validation.d.ts +8 -0
  45. package/dist/edges/ref-validation.js +262 -0
  46. package/dist/edges/store.d.ts +10 -0
  47. package/dist/edges/store.js +343 -0
  48. package/dist/edges/types.d.ts +86 -0
  49. package/dist/edges/types.js +18 -0
  50. package/dist/embeddings.js +13 -0
  51. package/dist/index.d.ts +17 -3
  52. package/dist/index.js +53 -4
  53. package/dist/mama-api.d.ts +32 -35
  54. package/dist/mama-api.js +173 -22
  55. package/dist/memory/api.d.ts +17 -56
  56. package/dist/memory/api.js +494 -52
  57. package/dist/memory/event-store.d.ts +3 -0
  58. package/dist/memory/event-store.js +21 -2
  59. package/dist/memory/provenance-audit.d.ts +22 -0
  60. package/dist/memory/provenance-audit.js +112 -0
  61. package/dist/memory/provenance-query.d.ts +11 -0
  62. package/dist/memory/provenance-query.js +193 -0
  63. package/dist/memory/provenance.d.ts +29 -0
  64. package/dist/memory/provenance.js +136 -0
  65. package/dist/memory/scope-backfill.d.ts +17 -0
  66. package/dist/memory/scope-backfill.js +77 -0
  67. package/dist/memory/types.d.ts +86 -14
  68. package/dist/model-runs/store.d.ts +13 -0
  69. package/dist/model-runs/store.js +457 -0
  70. package/dist/model-runs/tool-trace-store.d.ts +4 -0
  71. package/dist/model-runs/tool-trace-store.js +114 -0
  72. package/dist/model-runs/types.d.ts +69 -0
  73. package/dist/model-runs/types.js +5 -0
  74. package/dist/runtime/trusted-provenance.d.ts +3 -0
  75. package/dist/runtime/trusted-provenance.js +6 -0
  76. package/dist/search/search-quality.d.ts +36 -0
  77. package/dist/search/search-quality.js +29 -0
  78. package/package.json +9 -2
package/dist/mama-api.js CHANGED
@@ -22,8 +22,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.listRecentMemoryEvents = exports.listOpenAuditFindings = exports.getChannelSummary = exports.upsertChannelSummary = exports.recordMemoryAudit = exports.createAuditAck = exports.buildMemoryBootstrap = exports.evolveMemory = exports.ingestMemory = exports.buildProfile = exports.recallMemory = exports.saveMemory = void 0;
25
+ exports.listToolTracesForRun = exports.appendToolTrace = exports.getModelRunInAdapter = exports.getModelRun = exports.failModelRunInAdapter = exports.failModelRun = exports.commitModelRunInAdapter = exports.commitModelRun = exports.beginModelRunInAdapter = exports.beginModelRun = exports.listRecentMemoryEvents = exports.listMemoryEventsForMemory = exports.listMemoriesByModelRunId = exports.listMemoriesByGatewayCallId = exports.listMemoriesByEnvelopeHash = exports.getMemoryProvenance = exports.listOpenAuditFindings = exports.getChannelSummary = exports.upsertChannelSummary = exports.recordMemoryAudit = exports.createAuditAck = exports.buildMemoryBootstrap = exports.evolveMemory = exports.ingestConversationWithTrustedProvenance = exports.ingestConversation = exports.ingestWithTrustedProvenance = exports.ingestMemory = exports.buildProfile = exports.recallMemory = exports.saveMemoryWithTrustedProvenance = exports.saveMemory = void 0;
26
26
  exports.save = save;
27
+ exports.saveWithTrustedProvenance = saveWithTrustedProvenance;
27
28
  exports.suggest = suggest;
28
29
  exports.list = listDecisions;
29
30
  exports.listCheckpoints = listCheckpoints;
@@ -50,6 +51,7 @@ exports.restoreLinkBackup = restoreLinkBackup;
50
51
  exports.verifyBackupExists = verifyBackupExists;
51
52
  exports.deleteAutoLinks = deleteAutoLinks;
52
53
  exports.validateCleanupResult = validateCleanupResult;
54
+ exports.expandWithGraph = expandWithGraph;
53
55
  // Node built-ins
54
56
  const fs_1 = __importDefault(require("fs"));
55
57
  const path_1 = __importDefault(require("path"));
@@ -67,9 +69,13 @@ const ollama_client_js_1 = require("./ollama-client.js");
67
69
  const debug_logger_js_1 = require("./debug-logger.js");
68
70
  const api_js_1 = require("./memory/api.js");
69
71
  Object.defineProperty(exports, "saveMemory", { enumerable: true, get: function () { return api_js_1.saveMemory; } });
72
+ Object.defineProperty(exports, "saveMemoryWithTrustedProvenance", { enumerable: true, get: function () { return api_js_1.saveMemoryWithTrustedProvenance; } });
70
73
  Object.defineProperty(exports, "recallMemory", { enumerable: true, get: function () { return api_js_1.recallMemory; } });
71
74
  Object.defineProperty(exports, "buildProfile", { enumerable: true, get: function () { return api_js_1.buildProfile; } });
72
75
  Object.defineProperty(exports, "ingestMemory", { enumerable: true, get: function () { return api_js_1.ingestMemory; } });
76
+ Object.defineProperty(exports, "ingestWithTrustedProvenance", { enumerable: true, get: function () { return api_js_1.ingestWithTrustedProvenance; } });
77
+ Object.defineProperty(exports, "ingestConversation", { enumerable: true, get: function () { return api_js_1.ingestConversation; } });
78
+ Object.defineProperty(exports, "ingestConversationWithTrustedProvenance", { enumerable: true, get: function () { return api_js_1.ingestConversationWithTrustedProvenance; } });
73
79
  Object.defineProperty(exports, "evolveMemory", { enumerable: true, get: function () { return api_js_1.evolveMemory; } });
74
80
  Object.defineProperty(exports, "buildMemoryBootstrap", { enumerable: true, get: function () { return api_js_1.buildMemoryBootstrap; } });
75
81
  Object.defineProperty(exports, "createAuditAck", { enumerable: true, get: function () { return api_js_1.createAuditAck; } });
@@ -79,10 +85,29 @@ Object.defineProperty(exports, "getChannelSummary", { enumerable: true, get: fun
79
85
  const finding_store_js_1 = require("./memory/finding-store.js");
80
86
  Object.defineProperty(exports, "listOpenAuditFindings", { enumerable: true, get: function () { return finding_store_js_1.listOpenAuditFindings; } });
81
87
  const event_store_js_1 = require("./memory/event-store.js");
88
+ Object.defineProperty(exports, "listMemoryEventsForMemory", { enumerable: true, get: function () { return event_store_js_1.listMemoryEventsForMemory; } });
82
89
  Object.defineProperty(exports, "listRecentMemoryEvents", { enumerable: true, get: function () { return event_store_js_1.listRecentMemoryEvents; } });
90
+ const provenance_query_js_1 = require("./memory/provenance-query.js");
91
+ Object.defineProperty(exports, "getMemoryProvenance", { enumerable: true, get: function () { return provenance_query_js_1.getMemoryProvenance; } });
92
+ Object.defineProperty(exports, "listMemoriesByEnvelopeHash", { enumerable: true, get: function () { return provenance_query_js_1.listMemoriesByEnvelopeHash; } });
93
+ Object.defineProperty(exports, "listMemoriesByGatewayCallId", { enumerable: true, get: function () { return provenance_query_js_1.listMemoriesByGatewayCallId; } });
94
+ Object.defineProperty(exports, "listMemoriesByModelRunId", { enumerable: true, get: function () { return provenance_query_js_1.listMemoriesByModelRunId; } });
95
+ const store_js_1 = require("./model-runs/store.js");
96
+ Object.defineProperty(exports, "beginModelRun", { enumerable: true, get: function () { return store_js_1.beginModelRun; } });
97
+ Object.defineProperty(exports, "beginModelRunInAdapter", { enumerable: true, get: function () { return store_js_1.beginModelRunInAdapter; } });
98
+ Object.defineProperty(exports, "commitModelRun", { enumerable: true, get: function () { return store_js_1.commitModelRun; } });
99
+ Object.defineProperty(exports, "commitModelRunInAdapter", { enumerable: true, get: function () { return store_js_1.commitModelRunInAdapter; } });
100
+ Object.defineProperty(exports, "failModelRun", { enumerable: true, get: function () { return store_js_1.failModelRun; } });
101
+ Object.defineProperty(exports, "failModelRunInAdapter", { enumerable: true, get: function () { return store_js_1.failModelRunInAdapter; } });
102
+ Object.defineProperty(exports, "getModelRun", { enumerable: true, get: function () { return store_js_1.getModelRun; } });
103
+ Object.defineProperty(exports, "getModelRunInAdapter", { enumerable: true, get: function () { return store_js_1.getModelRunInAdapter; } });
104
+ const tool_trace_store_js_1 = require("./model-runs/tool-trace-store.js");
105
+ Object.defineProperty(exports, "appendToolTrace", { enumerable: true, get: function () { return tool_trace_store_js_1.appendToolTrace; } });
106
+ Object.defineProperty(exports, "listToolTracesForRun", { enumerable: true, get: function () { return tool_trace_store_js_1.listToolTracesForRun; } });
83
107
  const search_rollup_js_1 = require("./cases/search-rollup.js");
84
108
  const ranker_rescore_js_1 = require("./search/ranker-rescore.js");
85
109
  const ranker_features_js_1 = require("./search/ranker-features.js");
110
+ const search_quality_js_1 = require("./search/search-quality.js");
86
111
  // Session-level warning cooldown cache (Story 1.1, 1.2)
87
112
  // Prevents spam by tracking warned topics per session
88
113
  const warnedTopicsCache = new Map();
@@ -114,7 +139,7 @@ const WARNING_COOLDOWN_MS = 5 * 60 * 1000; // 5 minutes
114
139
  * outcome: 'success'
115
140
  * });
116
141
  */
117
- async function save({ topic, decision, reasoning, confidence = 0.5, type = 'user_decision', outcome = 'pending', failure_reason = null, limitation = null, trust_context: _trust_context = null, is_static, scopes: inputScopes, event_date, timelineEvent, }) {
142
+ async function saveInternal({ topic, decision, reasoning, confidence = 0.5, type = 'user_decision', outcome = 'pending', failure_reason = null, limitation = null, trust_context: _trust_context = null, is_static, scopes: inputScopes, event_date, timelineEvent, }, options) {
118
143
  // Validate required fields
119
144
  if (!topic || typeof topic !== 'string') {
120
145
  throw new Error('mama.save() requires topic (string)');
@@ -164,20 +189,35 @@ async function save({ topic, decision, reasoning, confidence = 0.5, type = 'user
164
189
  // Future: Will use decision_type column for proper distinction
165
190
  const _userInvolvement = type === 'user_decision' ? 'approved' : null;
166
191
  (0, progress_indicator_js_1.logProgress)(`Saving decision: ${topic.substring(0, 30)}...`);
167
- const { id: decisionId, timeline_event_id: timelineEventId, timeline_event_ids: timelineEventIds, } = await (0, api_js_1.saveMemory)({
168
- topic,
169
- kind: is_static === 1 ? 'preference' : 'decision',
170
- summary: decision,
171
- details: reasoning,
172
- confidence,
173
- scopes: Array.isArray(inputScopes) && inputScopes.length > 0 ? inputScopes : [],
174
- source: {
175
- package: 'mama-core',
176
- source_type: 'legacy_save',
177
- },
178
- eventDate: event_date ?? undefined,
179
- timelineEvent,
180
- });
192
+ const { id: decisionId, timeline_event_id: timelineEventId, timeline_event_ids: timelineEventIds, } = options
193
+ ? await (0, api_js_1.saveMemoryWithTrustedProvenance)({
194
+ topic,
195
+ kind: is_static === 1 ? 'preference' : 'decision',
196
+ summary: decision,
197
+ details: reasoning,
198
+ confidence,
199
+ scopes: Array.isArray(inputScopes) && inputScopes.length > 0 ? inputScopes : [],
200
+ source: {
201
+ package: 'mama-core',
202
+ source_type: 'legacy_save',
203
+ },
204
+ eventDate: event_date ?? undefined,
205
+ timelineEvent,
206
+ }, options)
207
+ : await (0, api_js_1.saveMemory)({
208
+ topic,
209
+ kind: is_static === 1 ? 'preference' : 'decision',
210
+ summary: decision,
211
+ details: reasoning,
212
+ confidence,
213
+ scopes: Array.isArray(inputScopes) && inputScopes.length > 0 ? inputScopes : [],
214
+ source: {
215
+ package: 'mama-core',
216
+ source_type: 'legacy_save',
217
+ },
218
+ eventDate: event_date ?? undefined,
219
+ timelineEvent,
220
+ });
181
221
  (0, progress_indicator_js_1.logComplete)(`Decision saved: ${decisionId.substring(0, 20)}...`);
182
222
  // Update user_involvement, outcome, failure_reason, limitation
183
223
  // Note: learnDecision always sets 'requested', we need to override it
@@ -760,6 +800,7 @@ function confidenceValue(record, fallback) {
760
800
  }
761
801
  function mapRolledUpResult(result) {
762
802
  const record = resultRecord(result);
803
+ const retrievalDiagnostics = result.retrieval_diagnostics;
763
804
  const topic = stringOrNull(record.topic ?? record.title) ?? result.source_id;
764
805
  // For wiki_page leaves, prefer the markdown body (`content`) in `decision` so
765
806
  // downstream consumers see the meaningful body rather than the short title.
@@ -787,15 +828,25 @@ function mapRolledUpResult(result) {
787
828
  created_at: record.created_at ?? null,
788
829
  event_date: record.event_date ?? null,
789
830
  event_datetime: record.event_datetime ?? null,
790
- graph_source: 'primary',
831
+ graph_source: retrievalDiagnostics?.graph_source ?? 'primary',
791
832
  graph_rank: 1,
792
833
  related_to: null,
793
834
  edge_reason: null,
794
835
  case_id: result.case_id,
795
836
  source_type: result.source_type,
796
837
  contributing_leaves: result.contributing_leaves ?? null,
838
+ ...(result.contributing_leaf_diagnostics
839
+ ? { contributing_leaf_diagnostics: result.contributing_leaf_diagnostics }
840
+ : {}),
841
+ ...(retrievalDiagnostics ? { retrieval_diagnostics: retrievalDiagnostics } : {}),
797
842
  };
798
843
  }
844
+ async function save(params) {
845
+ return saveInternal(params);
846
+ }
847
+ async function saveWithTrustedProvenance(params, options) {
848
+ return saveInternal(params, options);
849
+ }
799
850
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
800
851
  async function suggest(userQuestion, options = {}) {
801
852
  if (!userQuestion || typeof userQuestion !== 'string') {
@@ -807,17 +858,66 @@ async function suggest(userQuestion, options = {}) {
807
858
  recencyScale = 7, // Days until recency score drops to 50%
808
859
  recencyDecay = 0.5, // Score at scale point (0.5 = 50%)
809
860
  disableRecency = false, // Set true to disable recency boosting entirely
810
- } = options;
861
+ strict, strictness, includeRelated, minLexicalSupport, diagnostics: includeDiagnostics, } = options;
862
+ const normalizedSearchOptions = (0, search_quality_js_1.normalizeSearchQualityOptions)({
863
+ threshold,
864
+ strict,
865
+ strictness,
866
+ disableRecency,
867
+ includeRelated,
868
+ topicPrefix: options.topicPrefix,
869
+ minLexicalSupport,
870
+ diagnostics: includeDiagnostics,
871
+ });
872
+ const memoryV2QualityContractRequested = threshold !== undefined ||
873
+ strict !== undefined ||
874
+ strictness !== undefined ||
875
+ includeRelated !== undefined ||
876
+ minLexicalSupport !== undefined ||
877
+ includeDiagnostics === true ||
878
+ options.topicPrefix !== undefined ||
879
+ options.scopes !== undefined;
811
880
  const rerankPoolLimit = rerankWithLearned ? Math.max(limit * 4, limit + 5) : limit;
812
881
  try {
813
882
  const bundle = await (0, api_js_1.recallMemory)(userQuestion, {
814
883
  includeProfile: false,
815
884
  topicPrefix: options.topicPrefix,
816
885
  limit: rerankPoolLimit,
886
+ threshold,
887
+ strict,
888
+ strictness,
889
+ disableRecency,
890
+ includeRelated,
891
+ minLexicalSupport,
892
+ diagnostics: includeDiagnostics,
817
893
  ...(options.scopes && { scopes: options.scopes }),
818
894
  });
819
- const fusedHits = bundle.fused_hits ?? [];
895
+ const diagnosticsByMemoryId = new Map(bundle.memories
896
+ .filter((memory) => memory.retrieval_diagnostics)
897
+ .map((memory) => [memory.id, memory.retrieval_diagnostics]));
898
+ const rawFusedHits = bundle.fused_hits ?? [];
899
+ const fusedHits = rawFusedHits.map((hit) => {
900
+ if (hit.source_type !== 'decision') {
901
+ return hit;
902
+ }
903
+ const recordDiagnostics = typeof hit.record === 'object' && hit.record !== null && !Array.isArray(hit.record)
904
+ ? hit.record.retrieval_diagnostics
905
+ : undefined;
906
+ const retrievalDiagnostics = diagnosticsByMemoryId.get(hit.source_id) ?? recordDiagnostics;
907
+ if (!retrievalDiagnostics) {
908
+ return hit;
909
+ }
910
+ const record = typeof hit.record === 'object' && hit.record !== null && !Array.isArray(hit.record)
911
+ ? { ...hit.record, retrieval_diagnostics: retrievalDiagnostics }
912
+ : hit.record;
913
+ return {
914
+ ...hit,
915
+ record,
916
+ retrieval_diagnostics: retrievalDiagnostics,
917
+ };
918
+ });
820
919
  const rolledUp = fusedHits.length > 0 ? (0, search_rollup_js_1.rollUpSearchHits)({ fusedHits, adapter: (0, memory_store_js_1.getAdapter)() }) : [];
920
+ const diagnosticsResponse = includeDiagnostics === true ? { diagnostics: bundle.search_meta.diagnostics ?? null } : {};
821
921
  // Phase 3 Task 33: compute base ranker meta once so every return path
822
922
  // (rolledUp, memories fallback, vector-search fallback) can attach it.
823
923
  // rerankWithLearned-driven rescoring still only applies to result arrays
@@ -901,10 +1001,11 @@ async function suggest(userQuestion, options = {}) {
901
1001
  return {
902
1002
  query: userQuestion,
903
1003
  results: limitedResults,
1004
+ ...diagnosticsResponse,
904
1005
  meta: {
905
1006
  count: limitedResults.length,
906
1007
  search_method: 'memory_v2',
907
- threshold: threshold || 'adaptive',
1008
+ threshold: normalizedSearchOptions.threshold,
908
1009
  recency_boost: disableRecency
909
1010
  ? null
910
1011
  : {
@@ -939,7 +1040,7 @@ async function suggest(userQuestion, options = {}) {
939
1040
  created_at: memory.created_at,
940
1041
  event_date: memory.event_date ?? null,
941
1042
  event_datetime: memory.event_datetime ?? null,
942
- graph_source: 'primary',
1043
+ graph_source: memory.retrieval_diagnostics?.graph_source ?? 'primary',
943
1044
  graph_rank: 1,
944
1045
  related_to: null,
945
1046
  edge_reason: null,
@@ -949,6 +1050,9 @@ async function suggest(userQuestion, options = {}) {
949
1050
  memory.source_type ??
950
1051
  memory.type ??
951
1052
  'decision',
1053
+ ...(memory.retrieval_diagnostics
1054
+ ? { retrieval_diagnostics: memory.retrieval_diagnostics }
1055
+ : {}),
952
1056
  }));
953
1057
  const { results: rankedRows, meta: rankerMeta } = applyLearnedRanker(baseRows);
954
1058
  const limitedRows = rankedRows.slice(0, limit);
@@ -961,10 +1065,11 @@ async function suggest(userQuestion, options = {}) {
961
1065
  return {
962
1066
  query: userQuestion,
963
1067
  results: limitedRows,
1068
+ ...diagnosticsResponse,
964
1069
  meta: {
965
1070
  count: limitedRows.length,
966
1071
  search_method: 'memory_v2',
967
- threshold: threshold || 'adaptive',
1072
+ threshold: normalizedSearchOptions.threshold,
968
1073
  recency_boost: disableRecency
969
1074
  ? null
970
1075
  : {
@@ -977,6 +1082,32 @@ async function suggest(userQuestion, options = {}) {
977
1082
  },
978
1083
  };
979
1084
  }
1085
+ if (memoryV2QualityContractRequested) {
1086
+ const emptyRows = [];
1087
+ const { meta: rankerMeta } = applyLearnedRanker(emptyRows);
1088
+ if (format === 'markdown') {
1089
+ return '🔍 Search method: memory_v2\n';
1090
+ }
1091
+ return {
1092
+ query: userQuestion,
1093
+ results: emptyRows,
1094
+ ...diagnosticsResponse,
1095
+ meta: {
1096
+ count: 0,
1097
+ search_method: 'memory_v2',
1098
+ threshold: normalizedSearchOptions.threshold,
1099
+ recency_boost: disableRecency
1100
+ ? null
1101
+ : {
1102
+ weight: recencyWeight,
1103
+ scale: recencyScale,
1104
+ decay: recencyDecay,
1105
+ },
1106
+ graph_expansion: summarizeGraphExpansion(emptyRows),
1107
+ ranker: rankerMeta,
1108
+ },
1109
+ };
1110
+ }
980
1111
  // 1. Try vector search first (if sqlite-vss is available)
981
1112
  // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-explicit-any
982
1113
  let results = [];
@@ -2567,14 +2698,19 @@ function formatQualityReportMarkdown(report) {
2567
2698
  const mama = {
2568
2699
  // Core functions (used by 4 MCP tools)
2569
2700
  save,
2701
+ saveWithTrustedProvenance,
2570
2702
  suggest,
2571
2703
  saveMemory: api_js_1.saveMemory,
2704
+ saveMemoryWithTrustedProvenance: api_js_1.saveMemoryWithTrustedProvenance,
2572
2705
  recallMemory: api_js_1.recallMemory,
2573
2706
  list: listDecisions,
2574
2707
  listCheckpoints,
2575
2708
  updateOutcome,
2576
2709
  buildProfile: api_js_1.buildProfile,
2577
2710
  ingestMemory: api_js_1.ingestMemory,
2711
+ ingestWithTrustedProvenance: api_js_1.ingestWithTrustedProvenance,
2712
+ ingestConversation: api_js_1.ingestConversation,
2713
+ ingestConversationWithTrustedProvenance: api_js_1.ingestConversationWithTrustedProvenance,
2578
2714
  evolveMemory: api_js_1.evolveMemory,
2579
2715
  buildMemoryBootstrap: api_js_1.buildMemoryBootstrap,
2580
2716
  createAuditAck: api_js_1.createAuditAck,
@@ -2582,7 +2718,22 @@ const mama = {
2582
2718
  upsertChannelSummary: api_js_1.upsertChannelSummary,
2583
2719
  getChannelSummary: api_js_1.getChannelSummary,
2584
2720
  listAuditFindings: finding_store_js_1.listOpenAuditFindings,
2721
+ getMemoryProvenance: provenance_query_js_1.getMemoryProvenance,
2722
+ listMemoriesByEnvelopeHash: provenance_query_js_1.listMemoriesByEnvelopeHash,
2723
+ listMemoriesByGatewayCallId: provenance_query_js_1.listMemoriesByGatewayCallId,
2724
+ listMemoriesByModelRunId: provenance_query_js_1.listMemoriesByModelRunId,
2725
+ listMemoryEventsForMemory: event_store_js_1.listMemoryEventsForMemory,
2585
2726
  listRecentMemoryEvents: event_store_js_1.listRecentMemoryEvents,
2727
+ beginModelRun: store_js_1.beginModelRun,
2728
+ beginModelRunInAdapter: store_js_1.beginModelRunInAdapter,
2729
+ commitModelRun: store_js_1.commitModelRun,
2730
+ commitModelRunInAdapter: store_js_1.commitModelRunInAdapter,
2731
+ failModelRun: store_js_1.failModelRun,
2732
+ failModelRunInAdapter: store_js_1.failModelRunInAdapter,
2733
+ getModelRun: store_js_1.getModelRun,
2734
+ getModelRunInAdapter: store_js_1.getModelRunInAdapter,
2735
+ appendToolTrace: tool_trace_store_js_1.appendToolTrace,
2736
+ listToolTracesForRun: tool_trace_store_js_1.listToolTracesForRun,
2586
2737
  saveCheckpoint,
2587
2738
  loadCheckpoint,
2588
2739
  // Legacy functions (retained for internal use, not exposed via MCP)
@@ -1,82 +1,42 @@
1
1
  import { type WikiPageIndexRecord } from '../cases/wiki-page-index.js';
2
2
  import { resolveMemoryEvolution } from './evolution-engine.js';
3
3
  import { getChannelSummary, upsertChannelSummary } from './channel-summary-store.js';
4
- import type { MemoryKind, MemoryAgentBootstrap, MemoryAuditAck, MemoryEdge, MemoryRecord, MemoryScopeRef, MemoryStatus, ProfileSnapshot, RecallBundle, IngestConversationInput, ExtractedMemoryUnit, IngestConversationResult } from './types.js';
5
- interface SaveMemoryInput {
6
- topic: string;
7
- kind: MemoryKind;
8
- summary: string;
9
- details: string;
10
- confidence?: number;
11
- status?: MemoryStatus;
12
- scopes: MemoryScopeRef[];
13
- source: {
14
- package: 'mama-core' | 'mcp-server' | 'standalone' | 'claude-code-plugin';
15
- source_type: string;
16
- user_id?: string;
17
- channel_id?: string;
18
- project_id?: string;
19
- };
20
- /** IDs to exclude from supersede candidates (e.g., sibling facts from same ingestion batch) */
21
- excludeIds?: string[];
22
- /**
23
- * ISO 8601 date string for when the event actually occurred (e.g. "2023-01-15").
24
- * Stored in the event_date column. Defaults to created_at if omitted.
25
- */
26
- eventDate?: string;
27
- /** Source event timestamp in milliseconds when known. */
28
- eventDateTime?: number;
29
- entityObservationIds?: string[];
30
- timelineEvent?: {
31
- id?: string;
32
- entity_id?: string;
33
- event_type: string;
34
- role?: string | null;
35
- valid_from?: number | null;
36
- valid_to?: number | null;
37
- observed_at?: number | null;
38
- source_ref?: string | null;
39
- summary: string;
40
- details?: string | null;
41
- };
42
- }
43
- interface RecallMemoryOptions {
44
- scopes?: MemoryScopeRef[];
45
- includeProfile?: boolean;
46
- includeHistory?: boolean;
47
- skipGraphExpansion?: boolean;
48
- topicPrefix?: string;
49
- limit?: number;
50
- }
51
- interface IngestMemoryInput {
52
- content: string;
53
- scopes?: MemoryScopeRef[];
54
- source: SaveMemoryInput['source'];
55
- eventDate?: string;
56
- eventDateTime?: number;
57
- }
4
+ import { type SearchHitDiagnostics } from '../search/search-quality.js';
5
+ import type { MemoryAgentBootstrap, MemoryAuditAck, MemoryEdge, MemoryRecord, MemoryScopeRef, ProfileSnapshot, PublicIngestMemoryInput, PublicSaveMemoryInput, RecallBundle, IngestConversationInput, ExtractedMemoryUnit, IngestConversationResult, RecallMemoryOptions } from './types.js';
6
+ import { type TrustedMemoryWriteOptions } from './provenance.js';
7
+ type SaveMemoryInput = PublicSaveMemoryInput;
8
+ type IngestMemoryInput = PublicIngestMemoryInput;
58
9
  export interface FusedHit {
59
10
  source_type: 'decision' | 'wiki_page';
60
11
  source_id: string;
61
12
  record: MemoryRecord | WikiPageIndexRecord;
62
13
  fused_rank_score: number;
14
+ page_type?: WikiPageIndexRecord['page_type'];
15
+ case_id?: string | null;
16
+ retrieval_diagnostics?: SearchHitDiagnostics;
63
17
  }
64
18
  export declare const LEXICAL_STOPWORDS: Set<string>;
65
19
  export declare function getLexicalQueryTokens(query: string): string[];
66
20
  export declare function loadEdgesForIds(ids: string[]): Promise<MemoryEdge[]>;
67
- export declare function saveMemory(input: SaveMemoryInput): Promise<{
21
+ type SaveMemoryResult = {
68
22
  success: boolean;
69
23
  id: string;
70
24
  saved_decision_id?: string;
71
25
  timeline_event_id?: string | null;
72
26
  timeline_event_ids?: string[];
73
- }>;
27
+ };
28
+ export declare function saveMemory(input: SaveMemoryInput): Promise<SaveMemoryResult>;
29
+ export declare function saveMemoryWithTrustedProvenance(input: SaveMemoryInput, options: TrustedMemoryWriteOptions): Promise<SaveMemoryResult>;
74
30
  export declare function buildProfile(scopes: MemoryScopeRef[]): Promise<ProfileSnapshot>;
75
31
  export declare function recallMemory(query: string, options?: RecallMemoryOptions): Promise<RecallBundle>;
76
32
  export declare function ingestMemory(input: IngestMemoryInput): Promise<{
77
33
  success: boolean;
78
34
  id: string;
79
35
  }>;
36
+ export declare function ingestWithTrustedProvenance(input: IngestMemoryInput, options: TrustedMemoryWriteOptions): Promise<{
37
+ success: boolean;
38
+ id: string;
39
+ }>;
80
40
  export declare function evolveMemory(input: Parameters<typeof resolveMemoryEvolution>[0]): Promise<import("./evolution-engine.js").EvolutionResult>;
81
41
  export declare function buildMemoryBootstrap(params: {
82
42
  scopes: MemoryScopeRef[];
@@ -104,5 +64,6 @@ export declare function recordMemoryAudit(input: {
104
64
  declare function callExtractionLLM(prompt: string, options: NonNullable<IngestConversationInput['extract']>): Promise<ExtractedMemoryUnit[]>;
105
65
  export declare function setExtractionFn(fn: typeof callExtractionLLM | null): void;
106
66
  export declare function ingestConversation(input: IngestConversationInput): Promise<IngestConversationResult>;
67
+ export declare function ingestConversationWithTrustedProvenance(input: IngestConversationInput, options: TrustedMemoryWriteOptions): Promise<IngestConversationResult>;
107
68
  export { upsertChannelSummary, getChannelSummary };
108
69
  //# sourceMappingURL=api.d.ts.map