@jungjaehoon/mama-core 1.3.3 → 1.4.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.
- package/README.md +67 -19
- package/db/migrations/001-initial-decision-graph.sql +5 -0
- package/db/migrations/014-add-is-static-column.sql +5 -0
- package/db/migrations/015-add-fts5-search.sql +34 -0
- package/db/migrations/016-add-memory-v2-columns.sql +14 -0
- package/db/migrations/017-create-memory-scopes.sql +10 -0
- package/db/migrations/018-create-memory-scope-bindings.sql +15 -0
- package/db/migrations/019-create-memory-events.sql +18 -0
- package/db/migrations/020-create-audit-findings.sql +18 -0
- package/db/migrations/021-create-memory-truth.sql +20 -0
- package/db/migrations/022-create-channel-summaries.sql +9 -0
- package/db/migrations/023-create-channel-summary-state.sql +9 -0
- package/db/migrations/024-add-event-date.sql +9 -0
- package/dist/db-adapter/base-adapter.d.ts +1 -1
- package/dist/db-adapter/index.js +2 -8
- package/dist/db-adapter/node-sqlite-adapter.d.ts +6 -1
- package/dist/db-adapter/node-sqlite-adapter.js +99 -45
- package/dist/db-manager.d.ts +30 -2
- package/dist/db-manager.js +131 -6
- package/dist/decision-formatter.d.ts +2 -0
- package/dist/embedding-server/mobile/session-manager.js +22 -7
- package/dist/index.d.ts +5 -1
- package/dist/index.js +31 -3
- package/dist/mama-api.d.ts +67 -2
- package/dist/mama-api.js +295 -80
- package/dist/memory/api.d.ts +81 -0
- package/dist/memory/api.js +972 -0
- package/dist/memory/bootstrap-builder.d.ts +10 -0
- package/dist/memory/bootstrap-builder.js +66 -0
- package/dist/memory/channel-summary-state-store.d.ts +19 -0
- package/dist/memory/channel-summary-state-store.js +223 -0
- package/dist/memory/channel-summary-store.d.ts +8 -0
- package/dist/memory/channel-summary-store.js +41 -0
- package/dist/memory/event-store.d.ts +5 -0
- package/dist/memory/event-store.js +72 -0
- package/dist/memory/evolution-engine.d.ts +22 -0
- package/dist/memory/evolution-engine.js +133 -0
- package/dist/memory/extraction-prompt.d.ts +4 -0
- package/dist/memory/extraction-prompt.js +89 -0
- package/dist/memory/finding-store.d.ts +5 -0
- package/dist/memory/finding-store.js +75 -0
- package/dist/memory/profile-builder.d.ts +3 -0
- package/dist/memory/profile-builder.js +23 -0
- package/dist/memory/scope-store.d.ts +5 -0
- package/dist/memory/scope-store.js +13 -0
- package/dist/memory/truth-store.d.ts +11 -0
- package/dist/memory/truth-store.js +102 -0
- package/dist/memory/types.d.ts +267 -0
- package/dist/memory/types.js +74 -0
- package/package.json +4 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildExtractionPrompt = buildExtractionPrompt;
|
|
4
|
+
exports.parseExtractionResponse = parseExtractionResponse;
|
|
5
|
+
const types_js_1 = require("./types.js");
|
|
6
|
+
const VALID_KINDS = new Set(types_js_1.MEMORY_KINDS);
|
|
7
|
+
function buildExtractionPrompt(messages, existingTopics) {
|
|
8
|
+
const conversationText = messages.map((m) => `${m.role}: ${m.content}`).join('\n');
|
|
9
|
+
const hasExistingTopics = existingTopics && existingTopics.length > 0;
|
|
10
|
+
const topicHint = hasExistingTopics
|
|
11
|
+
? `\nExisting topics (REUSE these when the subject matches instead of creating new ones):\n${existingTopics.map((t) => t.replace(/[`$\\]/g, '')).join(', ')}\n`
|
|
12
|
+
: '';
|
|
13
|
+
const topicRule = hasExistingTopics
|
|
14
|
+
? '- topic: lowercase_snake_case, prefer reusing an existing topic above when the subject matches'
|
|
15
|
+
: '- topic: lowercase_snake_case';
|
|
16
|
+
return `You are extracting structured memory units from a conversation about a user's life.
|
|
17
|
+
|
|
18
|
+
Read the conversation and identify every distinct piece of personal information worth remembering.
|
|
19
|
+
Classify each as one of: preference, fact, decision, lesson, constraint.
|
|
20
|
+
${topicHint}
|
|
21
|
+
Rules:
|
|
22
|
+
${topicRule}
|
|
23
|
+
- summary: concise (<200 chars). MUST include ALL of these when mentioned:
|
|
24
|
+
• Names (people, pets, brands, stores, apps, services)
|
|
25
|
+
• Dates and times ("bought on February 15", "every Tuesday", "3 weeks ago")
|
|
26
|
+
• Numbers and amounts ("$5 coupon", "4 hours", "45 minutes each way", "3 weddings")
|
|
27
|
+
• Places ("at Target", "from IKEA", "in Chicago")
|
|
28
|
+
Example: "User redeemed a $5 coupon on coffee creamer at Target on March 3" NOT "User used a coupon"
|
|
29
|
+
- details: quote the exact sentence(s) from the conversation that contain this information
|
|
30
|
+
- confidence: 0.0-1.0 based on how explicitly stated the information is
|
|
31
|
+
- For preferences: state what IS preferred and what is NOT (if mentioned)
|
|
32
|
+
- For countable facts: enumerate items explicitly (e.g., "Weddings attended: 1. Rachel & Mike, 2. Emily & Sarah, 3. Jen & Tom")
|
|
33
|
+
- IMPORTANT: do NOT merge unrelated facts. Each distinct event, purchase, person, or activity is a separate unit
|
|
34
|
+
- Skip small talk, meta-conversation, and assistant's general knowledge responses
|
|
35
|
+
|
|
36
|
+
Return ONLY a JSON array:
|
|
37
|
+
[{"kind":"...","topic":"...","summary":"...","details":"...","confidence":0.9}]
|
|
38
|
+
|
|
39
|
+
Conversation:
|
|
40
|
+
${conversationText}`;
|
|
41
|
+
}
|
|
42
|
+
function parseExtractionResponse(response) {
|
|
43
|
+
if (!response || response.trim().length === 0) {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
let jsonStr = response;
|
|
47
|
+
// Try extracting from markdown code fences
|
|
48
|
+
const fenceMatch = response.match(/```(?:json)?\s*\n?([\s\S]*?)\n?```/);
|
|
49
|
+
if (fenceMatch) {
|
|
50
|
+
jsonStr = fenceMatch[1];
|
|
51
|
+
}
|
|
52
|
+
// Try extracting bare JSON array
|
|
53
|
+
if (!jsonStr.trimStart().startsWith('[')) {
|
|
54
|
+
const arrayMatch = jsonStr.match(/\[[\s\S]*\]/);
|
|
55
|
+
if (arrayMatch) {
|
|
56
|
+
jsonStr = arrayMatch[0];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
let parsed;
|
|
60
|
+
try {
|
|
61
|
+
parsed = JSON.parse(jsonStr.trim());
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
if (!Array.isArray(parsed)) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
return parsed
|
|
70
|
+
.filter((item) => {
|
|
71
|
+
if (typeof item !== 'object' || item === null)
|
|
72
|
+
return false;
|
|
73
|
+
const obj = item;
|
|
74
|
+
return (typeof obj.kind === 'string' &&
|
|
75
|
+
VALID_KINDS.has(obj.kind) &&
|
|
76
|
+
typeof obj.topic === 'string' &&
|
|
77
|
+
obj.topic.length > 0 &&
|
|
78
|
+
typeof obj.summary === 'string' &&
|
|
79
|
+
obj.summary.length > 0);
|
|
80
|
+
})
|
|
81
|
+
.map((item) => ({
|
|
82
|
+
kind: item.kind,
|
|
83
|
+
topic: String(item.topic),
|
|
84
|
+
summary: String(item.summary).slice(0, 200),
|
|
85
|
+
details: typeof item.details === 'string' ? String(item.details) : String(item.summary),
|
|
86
|
+
confidence: Math.max(0, Math.min(1, Number(item.confidence) || 0.5)),
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=extraction-prompt.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AuditFindingRecord } from './types.js';
|
|
2
|
+
export declare function createAuditFinding(input: Omit<AuditFindingRecord, 'finding_id' | 'status' | 'created_at' | 'resolved_at'>): Promise<string>;
|
|
3
|
+
export declare function listOpenAuditFindings(): Promise<AuditFindingRecord[]>;
|
|
4
|
+
export declare function resolveAuditFinding(findingId: string, status: 'resolved' | 'dismissed'): Promise<void>;
|
|
5
|
+
//# sourceMappingURL=finding-store.d.ts.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createAuditFinding = createAuditFinding;
|
|
7
|
+
exports.listOpenAuditFindings = listOpenAuditFindings;
|
|
8
|
+
exports.resolveAuditFinding = resolveAuditFinding;
|
|
9
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
10
|
+
const db_manager_js_1 = require("../db-manager.js");
|
|
11
|
+
function safeParseJsonArray(value) {
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(String(value));
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function deserializeFinding(row) {
|
|
20
|
+
return {
|
|
21
|
+
finding_id: String(row.finding_id),
|
|
22
|
+
kind: row.kind,
|
|
23
|
+
severity: row.severity,
|
|
24
|
+
summary: String(row.summary),
|
|
25
|
+
evidence_refs: safeParseJsonArray(row.evidence_refs),
|
|
26
|
+
affected_memory_ids: safeParseJsonArray(row.affected_memory_ids),
|
|
27
|
+
recommended_action: String(row.recommended_action),
|
|
28
|
+
status: row.status,
|
|
29
|
+
created_at: Number(row.created_at),
|
|
30
|
+
resolved_at: row.resolved_at === null || row.resolved_at === undefined
|
|
31
|
+
? undefined
|
|
32
|
+
: Number(row.resolved_at),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async function createAuditFinding(input) {
|
|
36
|
+
await (0, db_manager_js_1.initDB)();
|
|
37
|
+
const adapter = (0, db_manager_js_1.getAdapter)();
|
|
38
|
+
const findingId = `finding_${node_crypto_1.default.randomUUID().replace(/-/g, '')}`;
|
|
39
|
+
adapter
|
|
40
|
+
.prepare(`
|
|
41
|
+
INSERT INTO audit_findings (
|
|
42
|
+
finding_id, kind, severity, summary, evidence_refs, affected_memory_ids,
|
|
43
|
+
recommended_action, status, created_at
|
|
44
|
+
)
|
|
45
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, 'open', ?)
|
|
46
|
+
`)
|
|
47
|
+
.run(findingId, input.kind, input.severity, input.summary, JSON.stringify(input.evidence_refs), JSON.stringify(input.affected_memory_ids), input.recommended_action, Date.now());
|
|
48
|
+
return findingId;
|
|
49
|
+
}
|
|
50
|
+
async function listOpenAuditFindings() {
|
|
51
|
+
await (0, db_manager_js_1.initDB)();
|
|
52
|
+
const adapter = (0, db_manager_js_1.getAdapter)();
|
|
53
|
+
const rows = adapter
|
|
54
|
+
.prepare(`
|
|
55
|
+
SELECT finding_id, kind, severity, summary, evidence_refs, affected_memory_ids,
|
|
56
|
+
recommended_action, status, created_at, resolved_at
|
|
57
|
+
FROM audit_findings
|
|
58
|
+
WHERE status = 'open'
|
|
59
|
+
ORDER BY created_at DESC
|
|
60
|
+
`)
|
|
61
|
+
.all();
|
|
62
|
+
return rows.map(deserializeFinding);
|
|
63
|
+
}
|
|
64
|
+
async function resolveAuditFinding(findingId, status) {
|
|
65
|
+
await (0, db_manager_js_1.initDB)();
|
|
66
|
+
const adapter = (0, db_manager_js_1.getAdapter)();
|
|
67
|
+
adapter
|
|
68
|
+
.prepare(`
|
|
69
|
+
UPDATE audit_findings
|
|
70
|
+
SET status = ?, resolved_at = ?
|
|
71
|
+
WHERE finding_id = ?
|
|
72
|
+
`)
|
|
73
|
+
.run(status, Date.now(), findingId);
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=finding-store.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.classifyProfileEntries = classifyProfileEntries;
|
|
4
|
+
function isStaticMemory(record) {
|
|
5
|
+
return record.kind === 'preference' || record.kind === 'constraint';
|
|
6
|
+
}
|
|
7
|
+
function classifyProfileEntries(records) {
|
|
8
|
+
const active = records.filter((record) => record.status === 'active');
|
|
9
|
+
const staticEntries = active.filter(isStaticMemory);
|
|
10
|
+
const dynamicEntries = active.filter((record) => !isStaticMemory(record));
|
|
11
|
+
return {
|
|
12
|
+
static: staticEntries,
|
|
13
|
+
dynamic: dynamicEntries,
|
|
14
|
+
evidence: active.map((record) => ({
|
|
15
|
+
memory_id: record.id,
|
|
16
|
+
topic: record.topic,
|
|
17
|
+
why_included: isStaticMemory(record)
|
|
18
|
+
? 'Long-term preference or constraint'
|
|
19
|
+
: 'Current active context',
|
|
20
|
+
})),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=profile-builder.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { MemoryScopeKind, MemoryScopeRef } from './types.js';
|
|
2
|
+
export declare const PRIORITY_SCOPE_ORDER: MemoryScopeKind[];
|
|
3
|
+
export declare function sortScopesByPriority(scopes: MemoryScopeRef[]): MemoryScopeRef[];
|
|
4
|
+
export declare function getPrimaryScope(scopes: MemoryScopeRef[]): MemoryScopeRef | null;
|
|
5
|
+
//# sourceMappingURL=scope-store.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PRIORITY_SCOPE_ORDER = void 0;
|
|
4
|
+
exports.sortScopesByPriority = sortScopesByPriority;
|
|
5
|
+
exports.getPrimaryScope = getPrimaryScope;
|
|
6
|
+
exports.PRIORITY_SCOPE_ORDER = ['project', 'channel', 'user', 'global'];
|
|
7
|
+
function sortScopesByPriority(scopes) {
|
|
8
|
+
return [...scopes].sort((left, right) => exports.PRIORITY_SCOPE_ORDER.indexOf(left.kind) - exports.PRIORITY_SCOPE_ORDER.indexOf(right.kind));
|
|
9
|
+
}
|
|
10
|
+
function getPrimaryScope(scopes) {
|
|
11
|
+
return sortScopesByPriority(scopes)[0] ?? null;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=scope-store.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MemoryScopeRef, MemoryTruthRow } from './types.js';
|
|
2
|
+
export declare function projectMemoryTruth(row: MemoryTruthRow): Promise<void>;
|
|
3
|
+
export declare function queryTruthByTopic(topic: string, options?: {
|
|
4
|
+
includeHistory?: boolean;
|
|
5
|
+
}): Promise<MemoryTruthRow[]>;
|
|
6
|
+
export declare function queryRelevantTruth(params: {
|
|
7
|
+
query: string;
|
|
8
|
+
scopes: MemoryScopeRef[];
|
|
9
|
+
includeHistory?: boolean;
|
|
10
|
+
}): Promise<MemoryTruthRow[]>;
|
|
11
|
+
//# sourceMappingURL=truth-store.d.ts.map
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.projectMemoryTruth = projectMemoryTruth;
|
|
4
|
+
exports.queryTruthByTopic = queryTruthByTopic;
|
|
5
|
+
exports.queryRelevantTruth = queryRelevantTruth;
|
|
6
|
+
const db_manager_js_1 = require("../db-manager.js");
|
|
7
|
+
function deserializeTruthRow(row) {
|
|
8
|
+
return {
|
|
9
|
+
memory_id: String(row.memory_id),
|
|
10
|
+
topic: String(row.topic),
|
|
11
|
+
truth_status: row.truth_status,
|
|
12
|
+
effective_summary: String(row.effective_summary),
|
|
13
|
+
effective_details: String(row.effective_details),
|
|
14
|
+
trust_score: Number(row.trust_score),
|
|
15
|
+
scope_refs: JSON.parse(String(row.scope_refs)),
|
|
16
|
+
supporting_event_ids: JSON.parse(String(row.supporting_event_ids)),
|
|
17
|
+
superseded_by: typeof row.superseded_by === 'string' ? row.superseded_by : undefined,
|
|
18
|
+
contradicted_by: typeof row.contradicted_by === 'string'
|
|
19
|
+
? JSON.parse(row.contradicted_by)
|
|
20
|
+
: undefined,
|
|
21
|
+
created_at: typeof row.created_at === 'number' ? row.created_at : undefined,
|
|
22
|
+
updated_at: typeof row.updated_at === 'number' ? row.updated_at : undefined,
|
|
23
|
+
kind: typeof row.kind === 'string' ? row.kind : undefined,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function matchesScopes(row, scopes) {
|
|
27
|
+
if (scopes.length === 0) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return row.scope_refs.some((scopeRef) => scopes.some((scope) => scope.kind === scopeRef.kind && scope.id === scopeRef.id));
|
|
31
|
+
}
|
|
32
|
+
function matchesQuery(row, query) {
|
|
33
|
+
const tokens = query
|
|
34
|
+
.toLowerCase()
|
|
35
|
+
.split(/[\s,.!?;:()[\]{}"']+/)
|
|
36
|
+
.filter((token) => token.length > 1);
|
|
37
|
+
const haystack = [row.topic, row.effective_summary, row.effective_details]
|
|
38
|
+
.join(' ')
|
|
39
|
+
.toLowerCase();
|
|
40
|
+
return tokens.length === 0
|
|
41
|
+
? haystack.includes(query.toLowerCase())
|
|
42
|
+
: tokens.some((token) => haystack.includes(token));
|
|
43
|
+
}
|
|
44
|
+
async function projectMemoryTruth(row) {
|
|
45
|
+
await (0, db_manager_js_1.initDB)();
|
|
46
|
+
const adapter = (0, db_manager_js_1.getAdapter)();
|
|
47
|
+
const now = Date.now();
|
|
48
|
+
adapter
|
|
49
|
+
.prepare(`
|
|
50
|
+
INSERT OR REPLACE INTO memory_truth (
|
|
51
|
+
memory_id, topic, truth_status, effective_summary, effective_details, trust_score,
|
|
52
|
+
scope_refs, supporting_event_ids, superseded_by, contradicted_by, created_at, updated_at
|
|
53
|
+
)
|
|
54
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, COALESCE((SELECT created_at FROM memory_truth WHERE memory_id = ?), ?), ?)
|
|
55
|
+
`)
|
|
56
|
+
.run(row.memory_id, row.topic, row.truth_status, row.effective_summary, row.effective_details, row.trust_score, JSON.stringify(row.scope_refs), JSON.stringify(row.supporting_event_ids), row.superseded_by ?? null, row.contradicted_by ? JSON.stringify(row.contradicted_by) : null, row.memory_id, now, now);
|
|
57
|
+
}
|
|
58
|
+
async function queryTruthByTopic(topic, options = {}) {
|
|
59
|
+
await (0, db_manager_js_1.initDB)();
|
|
60
|
+
const adapter = (0, db_manager_js_1.getAdapter)();
|
|
61
|
+
const rows = adapter
|
|
62
|
+
.prepare(`
|
|
63
|
+
SELECT mt.memory_id, mt.topic, mt.truth_status, mt.effective_summary, mt.effective_details, mt.trust_score,
|
|
64
|
+
mt.scope_refs, mt.supporting_event_ids, mt.superseded_by, mt.contradicted_by, mt.created_at, mt.updated_at,
|
|
65
|
+
d.kind
|
|
66
|
+
FROM memory_truth mt
|
|
67
|
+
LEFT JOIN decisions d ON d.id = mt.memory_id
|
|
68
|
+
WHERE mt.topic = ?
|
|
69
|
+
ORDER BY mt.updated_at DESC
|
|
70
|
+
`)
|
|
71
|
+
.all(topic);
|
|
72
|
+
return rows
|
|
73
|
+
.map(deserializeTruthRow)
|
|
74
|
+
.filter((row) => options.includeHistory === true ||
|
|
75
|
+
(row.truth_status !== 'quarantined' &&
|
|
76
|
+
row.truth_status !== 'superseded' &&
|
|
77
|
+
row.truth_status !== 'contradicted'));
|
|
78
|
+
}
|
|
79
|
+
async function queryRelevantTruth(params) {
|
|
80
|
+
await (0, db_manager_js_1.initDB)();
|
|
81
|
+
const adapter = (0, db_manager_js_1.getAdapter)();
|
|
82
|
+
const rows = adapter
|
|
83
|
+
.prepare(`
|
|
84
|
+
SELECT mt.memory_id, mt.topic, mt.truth_status, mt.effective_summary, mt.effective_details, mt.trust_score,
|
|
85
|
+
mt.scope_refs, mt.supporting_event_ids, mt.superseded_by, mt.contradicted_by, mt.created_at, mt.updated_at,
|
|
86
|
+
d.kind
|
|
87
|
+
FROM memory_truth mt
|
|
88
|
+
LEFT JOIN decisions d ON d.id = mt.memory_id
|
|
89
|
+
ORDER BY mt.updated_at DESC
|
|
90
|
+
`)
|
|
91
|
+
.all();
|
|
92
|
+
return rows
|
|
93
|
+
.map(deserializeTruthRow)
|
|
94
|
+
.filter((row) => matchesScopes(row, params.scopes))
|
|
95
|
+
.filter((row) => matchesQuery(row, params.query))
|
|
96
|
+
.filter((row) => params.includeHistory === true ||
|
|
97
|
+
(row.truth_status !== 'quarantined' &&
|
|
98
|
+
row.truth_status !== 'superseded' &&
|
|
99
|
+
row.truth_status !== 'contradicted'))
|
|
100
|
+
.sort((left, right) => right.trust_score - left.trust_score);
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=truth-store.js.map
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
export declare const MEMORY_SCOPE_KINDS: readonly ["global", "user", "channel", "project"];
|
|
2
|
+
export type MemoryScopeKind = (typeof MEMORY_SCOPE_KINDS)[number];
|
|
3
|
+
export declare const MEMORY_KINDS: readonly ["decision", "preference", "constraint", "lesson", "fact"];
|
|
4
|
+
export type MemoryKind = (typeof MEMORY_KINDS)[number];
|
|
5
|
+
export declare const MEMORY_STATUSES: readonly ["active", "superseded", "contradicted", "stale"];
|
|
6
|
+
export type MemoryStatus = (typeof MEMORY_STATUSES)[number];
|
|
7
|
+
export declare const MEMORY_TRUTH_STATUSES: readonly ["active", "superseded", "contradicted", "stale", "quarantined"];
|
|
8
|
+
export type MemoryTruthStatus = (typeof MEMORY_TRUTH_STATUSES)[number];
|
|
9
|
+
export declare const MEMORY_EDGE_TYPES: readonly ["supersedes", "builds_on", "synthesizes", "contradicts"];
|
|
10
|
+
export type MemoryEdgeType = (typeof MEMORY_EDGE_TYPES)[number];
|
|
11
|
+
export declare const MEMORY_AGENT_ACTIONS: readonly ["save", "supersede", "contradict", "mark_stale", "quarantine", "no_op"];
|
|
12
|
+
export type MemoryAgentAction = (typeof MEMORY_AGENT_ACTIONS)[number];
|
|
13
|
+
export declare const MEMORY_CONSULT_INTENTS: readonly ["bootstrap_session", "validate_claim", "get_relevant_truth", "check_conflicts", "explain_history"];
|
|
14
|
+
export type MemoryConsultIntent = (typeof MEMORY_CONSULT_INTENTS)[number];
|
|
15
|
+
export declare const MEMORY_AUDIT_ACK_STATUSES: readonly ["applied", "skipped", "failed"];
|
|
16
|
+
export type MemoryAuditAckStatus = (typeof MEMORY_AUDIT_ACK_STATUSES)[number];
|
|
17
|
+
export interface MemoryScopeRef {
|
|
18
|
+
kind: MemoryScopeKind;
|
|
19
|
+
id: string;
|
|
20
|
+
}
|
|
21
|
+
export interface MemoryRecord {
|
|
22
|
+
id: string;
|
|
23
|
+
topic: string;
|
|
24
|
+
kind: MemoryKind;
|
|
25
|
+
summary: string;
|
|
26
|
+
details: string;
|
|
27
|
+
confidence: number;
|
|
28
|
+
status: MemoryStatus;
|
|
29
|
+
scopes: MemoryScopeRef[];
|
|
30
|
+
source: {
|
|
31
|
+
package: 'mama-core' | 'mcp-server' | 'standalone' | 'claude-code-plugin';
|
|
32
|
+
source_type: string;
|
|
33
|
+
user_id?: string;
|
|
34
|
+
channel_id?: string;
|
|
35
|
+
project_id?: string;
|
|
36
|
+
};
|
|
37
|
+
created_at: number | string;
|
|
38
|
+
updated_at: number | string;
|
|
39
|
+
/** ISO 8601 date when the event actually occurred (e.g. "2023-01-15"). Null if not set. */
|
|
40
|
+
event_date?: string | null;
|
|
41
|
+
}
|
|
42
|
+
export interface MemoryEdge {
|
|
43
|
+
from_id: string;
|
|
44
|
+
to_id: string;
|
|
45
|
+
type: MemoryEdgeType;
|
|
46
|
+
reason?: string;
|
|
47
|
+
}
|
|
48
|
+
export interface ProfileSnapshot {
|
|
49
|
+
static: MemoryRecord[];
|
|
50
|
+
dynamic: MemoryRecord[];
|
|
51
|
+
evidence: Array<{
|
|
52
|
+
memory_id: string;
|
|
53
|
+
topic: string;
|
|
54
|
+
why_included: string;
|
|
55
|
+
}>;
|
|
56
|
+
}
|
|
57
|
+
export interface RecallBundle {
|
|
58
|
+
profile: ProfileSnapshot;
|
|
59
|
+
memories: MemoryRecord[];
|
|
60
|
+
graph_context: {
|
|
61
|
+
primary: MemoryRecord[];
|
|
62
|
+
expanded: MemoryRecord[];
|
|
63
|
+
edges: MemoryEdge[];
|
|
64
|
+
};
|
|
65
|
+
search_meta: {
|
|
66
|
+
query: string;
|
|
67
|
+
scope_order: MemoryScopeKind[];
|
|
68
|
+
retrieval_sources: string[];
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export interface MemoryEventRecord {
|
|
72
|
+
event_id: string;
|
|
73
|
+
event_type: 'observed_conversation' | 'save' | 'supersede' | 'contradict' | 'mark_stale' | 'quarantine' | 'no_op' | 'audit_failed' | 'notice_sent';
|
|
74
|
+
actor: 'memory_agent' | 'main_agent' | 'user' | 'system';
|
|
75
|
+
source_turn_id?: string;
|
|
76
|
+
memory_id?: string;
|
|
77
|
+
topic?: string;
|
|
78
|
+
scope_refs: MemoryScopeRef[];
|
|
79
|
+
evidence_refs?: string[];
|
|
80
|
+
reason?: string;
|
|
81
|
+
created_at: number;
|
|
82
|
+
}
|
|
83
|
+
export interface AuditFindingRecord {
|
|
84
|
+
finding_id: string;
|
|
85
|
+
kind: 'wrong_direction' | 'memory_conflict' | 'stale_memory' | 'unsupported_claim';
|
|
86
|
+
severity: 'low' | 'medium' | 'high';
|
|
87
|
+
summary: string;
|
|
88
|
+
evidence_refs: string[];
|
|
89
|
+
affected_memory_ids: string[];
|
|
90
|
+
recommended_action: string;
|
|
91
|
+
status: 'open' | 'notified' | 'resolved' | 'dismissed';
|
|
92
|
+
created_at: number;
|
|
93
|
+
resolved_at?: number;
|
|
94
|
+
}
|
|
95
|
+
export interface MemoryAuditAck {
|
|
96
|
+
status: MemoryAuditAckStatus;
|
|
97
|
+
action: MemoryAgentAction;
|
|
98
|
+
event_ids: string[];
|
|
99
|
+
reason?: string;
|
|
100
|
+
}
|
|
101
|
+
export interface AuditNotice {
|
|
102
|
+
type: 'direction_alert' | 'truth_conflict' | 'truth_update' | 'memory_warning';
|
|
103
|
+
severity: 'low' | 'medium' | 'high';
|
|
104
|
+
summary: string;
|
|
105
|
+
evidence: Array<{
|
|
106
|
+
type: 'conversation' | 'memory' | 'event';
|
|
107
|
+
ref: string;
|
|
108
|
+
excerpt?: string;
|
|
109
|
+
}>;
|
|
110
|
+
recommended_action: 'recheck' | 'consult_memory' | 'avoid_claim' | 'use_truth_snapshot';
|
|
111
|
+
relevant_memories: Array<{
|
|
112
|
+
id: string;
|
|
113
|
+
topic: string;
|
|
114
|
+
summary: string;
|
|
115
|
+
}>;
|
|
116
|
+
}
|
|
117
|
+
export interface MemoryConsultResult {
|
|
118
|
+
status: 'ok' | 'conflict' | 'uncertain' | 'no_relevant_memory';
|
|
119
|
+
summary: string;
|
|
120
|
+
evidence: Array<{
|
|
121
|
+
type: 'memory' | 'event';
|
|
122
|
+
ref: string;
|
|
123
|
+
excerpt?: string;
|
|
124
|
+
}>;
|
|
125
|
+
truth_snapshot?: Array<{
|
|
126
|
+
id: string;
|
|
127
|
+
topic: string;
|
|
128
|
+
summary: string;
|
|
129
|
+
status: string;
|
|
130
|
+
}>;
|
|
131
|
+
recommended_action?: string;
|
|
132
|
+
}
|
|
133
|
+
export interface MemoryAgentBootstrap {
|
|
134
|
+
current_goal?: string;
|
|
135
|
+
scope_context: MemoryScopeRef[];
|
|
136
|
+
channel_summary_markdown?: string;
|
|
137
|
+
truth_snapshot: Array<{
|
|
138
|
+
id: string;
|
|
139
|
+
topic: string;
|
|
140
|
+
summary: string;
|
|
141
|
+
trust_score: number;
|
|
142
|
+
}>;
|
|
143
|
+
open_audit_findings: Array<{
|
|
144
|
+
id: string;
|
|
145
|
+
kind: string;
|
|
146
|
+
severity: string;
|
|
147
|
+
summary: string;
|
|
148
|
+
}>;
|
|
149
|
+
recent_memory_events: Array<{
|
|
150
|
+
id: string;
|
|
151
|
+
type: string;
|
|
152
|
+
topic?: string;
|
|
153
|
+
created_at: number;
|
|
154
|
+
}>;
|
|
155
|
+
profile_snapshot?: {
|
|
156
|
+
static: Array<{
|
|
157
|
+
id: string;
|
|
158
|
+
summary: string;
|
|
159
|
+
}>;
|
|
160
|
+
dynamic: Array<{
|
|
161
|
+
id: string;
|
|
162
|
+
summary: string;
|
|
163
|
+
}>;
|
|
164
|
+
};
|
|
165
|
+
main_agent_state?: {
|
|
166
|
+
active_goal?: string;
|
|
167
|
+
active_channel?: string;
|
|
168
|
+
active_user?: string;
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
export interface MemoryTruthRow {
|
|
172
|
+
memory_id: string;
|
|
173
|
+
topic: string;
|
|
174
|
+
kind?: MemoryKind;
|
|
175
|
+
truth_status: MemoryTruthStatus;
|
|
176
|
+
effective_summary: string;
|
|
177
|
+
effective_details: string;
|
|
178
|
+
trust_score: number;
|
|
179
|
+
scope_refs: MemoryScopeRef[];
|
|
180
|
+
supporting_event_ids: string[];
|
|
181
|
+
superseded_by?: string;
|
|
182
|
+
contradicted_by?: string[];
|
|
183
|
+
created_at?: number;
|
|
184
|
+
updated_at?: number;
|
|
185
|
+
}
|
|
186
|
+
export interface ChannelSummaryRecord {
|
|
187
|
+
channel_key: string;
|
|
188
|
+
summary_markdown: string;
|
|
189
|
+
delta_hash?: string;
|
|
190
|
+
updated_at: number;
|
|
191
|
+
}
|
|
192
|
+
export interface ChannelSummaryStateDecision {
|
|
193
|
+
memory_id: string;
|
|
194
|
+
topic: string;
|
|
195
|
+
summary: string;
|
|
196
|
+
updated_at: number;
|
|
197
|
+
}
|
|
198
|
+
export interface ChannelSummaryStateMilestone {
|
|
199
|
+
topic: string;
|
|
200
|
+
action: MemoryAgentAction;
|
|
201
|
+
summary: string;
|
|
202
|
+
timestamp: number;
|
|
203
|
+
memory_id?: string;
|
|
204
|
+
}
|
|
205
|
+
export interface ChannelSummaryAuditOutcome {
|
|
206
|
+
topic: string;
|
|
207
|
+
status: MemoryAuditAckStatus;
|
|
208
|
+
reason?: string;
|
|
209
|
+
timestamp: number;
|
|
210
|
+
}
|
|
211
|
+
export interface ChannelSummaryStateRecord {
|
|
212
|
+
channel_key: string;
|
|
213
|
+
active_topic?: string;
|
|
214
|
+
active_decisions: ChannelSummaryStateDecision[];
|
|
215
|
+
recent_milestones: ChannelSummaryStateMilestone[];
|
|
216
|
+
recent_audit_outcomes: ChannelSummaryAuditOutcome[];
|
|
217
|
+
state_hash: string;
|
|
218
|
+
updated_at: number;
|
|
219
|
+
}
|
|
220
|
+
export declare function createEmptyRecallBundle(query: string): RecallBundle;
|
|
221
|
+
export declare function createEmptyMemoryAgentBootstrap(input: Pick<MemoryAgentBootstrap, 'scope_context'> & Partial<Omit<MemoryAgentBootstrap, 'scope_context'>>): MemoryAgentBootstrap;
|
|
222
|
+
export declare function createMemoryAuditAck(input: Pick<MemoryAuditAck, 'status' | 'action' | 'event_ids'> & Partial<MemoryAuditAck>): MemoryAuditAck;
|
|
223
|
+
export interface ConversationMessage {
|
|
224
|
+
role: 'user' | 'assistant' | 'system';
|
|
225
|
+
content: string;
|
|
226
|
+
}
|
|
227
|
+
export interface IngestConversationInput {
|
|
228
|
+
messages: ConversationMessage[];
|
|
229
|
+
scopes: MemoryScopeRef[];
|
|
230
|
+
source: {
|
|
231
|
+
package: 'mama-core' | 'mcp-server' | 'standalone' | 'claude-code-plugin';
|
|
232
|
+
source_type: string;
|
|
233
|
+
user_id?: string;
|
|
234
|
+
channel_id?: string;
|
|
235
|
+
project_id?: string;
|
|
236
|
+
};
|
|
237
|
+
extract?: {
|
|
238
|
+
enabled: boolean;
|
|
239
|
+
model?: string;
|
|
240
|
+
apiKey?: string;
|
|
241
|
+
baseUrl?: string;
|
|
242
|
+
};
|
|
243
|
+
/** Prefix for all topics created by this ingestion (e.g. "bench_questionId_") for data isolation */
|
|
244
|
+
topicPrefix?: string;
|
|
245
|
+
/**
|
|
246
|
+
* ISO 8601 date string (e.g. "2023-01-15") representing when the conversation actually occurred.
|
|
247
|
+
* When provided, all memories extracted from this ingestion will have their event_date set to this value.
|
|
248
|
+
* Defaults to created_at (ingestion time) if omitted.
|
|
249
|
+
*/
|
|
250
|
+
sessionDate?: string;
|
|
251
|
+
}
|
|
252
|
+
export interface ExtractedMemoryUnit {
|
|
253
|
+
kind: MemoryKind;
|
|
254
|
+
topic: string;
|
|
255
|
+
summary: string;
|
|
256
|
+
details: string;
|
|
257
|
+
confidence: number;
|
|
258
|
+
}
|
|
259
|
+
export interface IngestConversationResult {
|
|
260
|
+
rawId: string;
|
|
261
|
+
extractedMemories: Array<{
|
|
262
|
+
id: string;
|
|
263
|
+
kind: MemoryKind;
|
|
264
|
+
topic: string;
|
|
265
|
+
}>;
|
|
266
|
+
}
|
|
267
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MEMORY_AUDIT_ACK_STATUSES = exports.MEMORY_CONSULT_INTENTS = exports.MEMORY_AGENT_ACTIONS = exports.MEMORY_EDGE_TYPES = exports.MEMORY_TRUTH_STATUSES = exports.MEMORY_STATUSES = exports.MEMORY_KINDS = exports.MEMORY_SCOPE_KINDS = void 0;
|
|
4
|
+
exports.createEmptyRecallBundle = createEmptyRecallBundle;
|
|
5
|
+
exports.createEmptyMemoryAgentBootstrap = createEmptyMemoryAgentBootstrap;
|
|
6
|
+
exports.createMemoryAuditAck = createMemoryAuditAck;
|
|
7
|
+
exports.MEMORY_SCOPE_KINDS = ['global', 'user', 'channel', 'project'];
|
|
8
|
+
exports.MEMORY_KINDS = ['decision', 'preference', 'constraint', 'lesson', 'fact'];
|
|
9
|
+
exports.MEMORY_STATUSES = ['active', 'superseded', 'contradicted', 'stale'];
|
|
10
|
+
exports.MEMORY_TRUTH_STATUSES = [
|
|
11
|
+
'active',
|
|
12
|
+
'superseded',
|
|
13
|
+
'contradicted',
|
|
14
|
+
'stale',
|
|
15
|
+
'quarantined',
|
|
16
|
+
];
|
|
17
|
+
exports.MEMORY_EDGE_TYPES = ['supersedes', 'builds_on', 'synthesizes', 'contradicts'];
|
|
18
|
+
exports.MEMORY_AGENT_ACTIONS = [
|
|
19
|
+
'save',
|
|
20
|
+
'supersede',
|
|
21
|
+
'contradict',
|
|
22
|
+
'mark_stale',
|
|
23
|
+
'quarantine',
|
|
24
|
+
'no_op',
|
|
25
|
+
];
|
|
26
|
+
exports.MEMORY_CONSULT_INTENTS = [
|
|
27
|
+
'bootstrap_session',
|
|
28
|
+
'validate_claim',
|
|
29
|
+
'get_relevant_truth',
|
|
30
|
+
'check_conflicts',
|
|
31
|
+
'explain_history',
|
|
32
|
+
];
|
|
33
|
+
exports.MEMORY_AUDIT_ACK_STATUSES = ['applied', 'skipped', 'failed'];
|
|
34
|
+
function createEmptyRecallBundle(query) {
|
|
35
|
+
return {
|
|
36
|
+
profile: {
|
|
37
|
+
static: [],
|
|
38
|
+
dynamic: [],
|
|
39
|
+
evidence: [],
|
|
40
|
+
},
|
|
41
|
+
memories: [],
|
|
42
|
+
graph_context: {
|
|
43
|
+
primary: [],
|
|
44
|
+
expanded: [],
|
|
45
|
+
edges: [],
|
|
46
|
+
},
|
|
47
|
+
search_meta: {
|
|
48
|
+
query,
|
|
49
|
+
scope_order: ['project'],
|
|
50
|
+
retrieval_sources: ['vector'],
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function createEmptyMemoryAgentBootstrap(input) {
|
|
55
|
+
return {
|
|
56
|
+
current_goal: input.current_goal,
|
|
57
|
+
scope_context: input.scope_context,
|
|
58
|
+
channel_summary_markdown: input.channel_summary_markdown,
|
|
59
|
+
truth_snapshot: input.truth_snapshot ?? [],
|
|
60
|
+
open_audit_findings: input.open_audit_findings ?? [],
|
|
61
|
+
recent_memory_events: input.recent_memory_events ?? [],
|
|
62
|
+
profile_snapshot: input.profile_snapshot,
|
|
63
|
+
main_agent_state: input.main_agent_state,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function createMemoryAuditAck(input) {
|
|
67
|
+
return {
|
|
68
|
+
status: input.status,
|
|
69
|
+
action: input.action,
|
|
70
|
+
event_ids: input.event_ids,
|
|
71
|
+
reason: input.reason,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=types.js.map
|