@jungjaehoon/mama-core 1.1.2 → 1.1.3

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 (67) hide show
  1. package/dist/config-loader.d.ts +61 -0
  2. package/dist/config-loader.js +187 -0
  3. package/dist/db-adapter/base-adapter.d.ts +76 -0
  4. package/dist/db-adapter/base-adapter.js +11 -0
  5. package/dist/db-adapter/index.d.ts +24 -0
  6. package/dist/db-adapter/index.js +29 -0
  7. package/dist/db-adapter/sqlite-adapter.d.ts +73 -0
  8. package/dist/db-adapter/sqlite-adapter.js +330 -0
  9. package/dist/db-adapter/statement.d.ts +119 -0
  10. package/dist/db-adapter/statement.js +113 -0
  11. package/dist/db-manager.d.ts +252 -0
  12. package/dist/db-manager.js +622 -0
  13. package/dist/debug-logger.d.ts +32 -0
  14. package/dist/debug-logger.js +83 -0
  15. package/dist/decision-formatter.d.ts +172 -0
  16. package/dist/decision-formatter.js +894 -0
  17. package/dist/decision-tracker.d.ts +218 -0
  18. package/dist/decision-tracker.js +531 -0
  19. package/dist/embedding-cache.d.ts +83 -0
  20. package/dist/embedding-cache.js +182 -0
  21. package/dist/embedding-client.d.ts +43 -0
  22. package/dist/embedding-client.js +132 -0
  23. package/dist/embedding-server/index.d.ts +65 -0
  24. package/dist/embedding-server/index.js +397 -0
  25. package/dist/embedding-server/mobile/auth.d.ts +53 -0
  26. package/dist/embedding-server/mobile/auth.js +140 -0
  27. package/dist/embedding-server/mobile/daemon.d.ts +128 -0
  28. package/dist/embedding-server/mobile/daemon.js +303 -0
  29. package/dist/embedding-server/mobile/output-parser.d.ts +115 -0
  30. package/dist/embedding-server/mobile/output-parser.js +241 -0
  31. package/dist/embedding-server/mobile/session-api.d.ts +57 -0
  32. package/dist/embedding-server/mobile/session-api.js +261 -0
  33. package/dist/embedding-server/mobile/session-manager.d.ts +135 -0
  34. package/dist/embedding-server/mobile/session-manager.js +333 -0
  35. package/dist/embedding-server/mobile/websocket-handler.d.ts +127 -0
  36. package/dist/embedding-server/mobile/websocket-handler.js +435 -0
  37. package/dist/embeddings.d.ts +75 -0
  38. package/dist/embeddings.js +262 -0
  39. package/dist/errors.d.ts +131 -0
  40. package/dist/errors.js +225 -0
  41. package/dist/index.d.ts +32 -0
  42. package/dist/index.js +193 -0
  43. package/dist/mama-api.d.ts +954 -0
  44. package/dist/mama-api.js +2210 -0
  45. package/dist/memory-inject.d.ts +24 -0
  46. package/dist/memory-inject.js +116 -0
  47. package/dist/memory-store.d.ts +103 -0
  48. package/dist/memory-store.js +129 -0
  49. package/dist/notification-manager.d.ts +7 -0
  50. package/dist/notification-manager.js +12 -0
  51. package/dist/ollama-client.d.ts +51 -0
  52. package/dist/ollama-client.js +308 -0
  53. package/dist/outcome-tracker.d.ts +165 -0
  54. package/dist/outcome-tracker.js +315 -0
  55. package/dist/progress-indicator.d.ts +48 -0
  56. package/dist/progress-indicator.js +82 -0
  57. package/dist/query-intent.d.ts +27 -0
  58. package/dist/query-intent.js +144 -0
  59. package/dist/relevance-scorer.d.ts +124 -0
  60. package/dist/relevance-scorer.js +243 -0
  61. package/dist/test-utils.d.ts +66 -0
  62. package/dist/test-utils.js +166 -0
  63. package/dist/tier-validator.d.ts +55 -0
  64. package/dist/tier-validator.js +216 -0
  65. package/dist/time-formatter.d.ts +25 -0
  66. package/dist/time-formatter.js +93 -0
  67. package/package.json +3 -2
@@ -0,0 +1,218 @@
1
+ /**
2
+ * MAMA (Memory-Augmented MCP Architecture) - Decision Tracker
3
+ *
4
+ * Learn and store decisions with graph relationships
5
+ * Tasks: 3.1-3.9 (Learn decision, ID generation, supersedes edges, refinement, embeddings)
6
+ * AC #1: Decision stored with outcome=NULL, confidence from LLM
7
+ * AC #2: Supersedes relationship creation
8
+ * AC #5: Multi-parent refinement with confidence calculation
9
+ *
10
+ * Updated for PostgreSQL compatibility via db-manager
11
+ *
12
+ * @module decision-tracker
13
+ * @version 2.0
14
+ * @date 2025-11-17
15
+ */
16
+ import type { DecisionRecord } from './db-manager.js';
17
+ export type { DecisionRecord };
18
+ export declare const VALID_EDGE_TYPES: readonly ["supersedes", "refines", "contradicts", "builds_on", "debates", "synthesizes"];
19
+ export type EdgeType = (typeof VALID_EDGE_TYPES)[number];
20
+ /**
21
+ * Decision detection result from analysis
22
+ */
23
+ export interface DecisionDetection {
24
+ topic: string;
25
+ decision: string;
26
+ reasoning: string;
27
+ confidence: number;
28
+ type?: string;
29
+ trust_context?: Record<string, unknown>;
30
+ evidence?: string | string[];
31
+ alternatives?: string | string[];
32
+ risks?: string;
33
+ }
34
+ /**
35
+ * Tool execution context
36
+ */
37
+ export interface ToolExecution {
38
+ timestamp?: number;
39
+ tool_name?: string;
40
+ tool_input?: unknown;
41
+ exit_code?: number;
42
+ }
43
+ /**
44
+ * Session context for decision tracking
45
+ */
46
+ export interface SessionContext {
47
+ session_id?: string;
48
+ latest_user_message?: string;
49
+ recent_exchange?: string;
50
+ }
51
+ /**
52
+ * Learn decision result
53
+ */
54
+ export interface LearnDecisionResult {
55
+ decisionId: string;
56
+ notification: unknown | null;
57
+ }
58
+ /**
59
+ * Parsed relationship from reasoning
60
+ */
61
+ export interface ParsedRelationship {
62
+ type: string;
63
+ targetIds: string[];
64
+ }
65
+ /**
66
+ * Generate decision ID
67
+ *
68
+ * Task 3.2: Generate decision ID: `decision_${topic}_${timestamp}`
69
+ *
70
+ * @param topic - Decision topic
71
+ * @returns Decision ID
72
+ */
73
+ export declare function generateDecisionId(topic: string): string;
74
+ /**
75
+ * Check for previous decision on same topic
76
+ *
77
+ * Task 3.3: Query decisions table WHERE topic=? AND superseded_by IS NULL
78
+ * AC #2: Find previous decision to create supersedes relationship
79
+ *
80
+ * @param topic - Decision topic
81
+ * @returns Previous decision or null
82
+ */
83
+ export declare function getPreviousDecision(topic: string): Promise<DecisionRecord | null>;
84
+ /**
85
+ * Create a decision edge with specified relationship type
86
+ *
87
+ * Story 2.1: Generic edge creation supporting all relationship types
88
+ *
89
+ * @param fromId - Source decision ID
90
+ * @param toId - Target decision ID
91
+ * @param relationship - Edge type (supersedes, builds_on, debates, synthesizes, etc.)
92
+ * @param reason - Reason for the relationship
93
+ * @returns Success status
94
+ */
95
+ export declare function createEdge(fromId: string, toId: string, relationship: string, reason: string): Promise<boolean>;
96
+ /**
97
+ * Create supersedes edge
98
+ *
99
+ * Task 3.5: Create supersedes edge (INSERT INTO decision_edges)
100
+ * AC #2: Supersedes relationship creation
101
+ *
102
+ * @param fromId - New decision ID
103
+ * @param toId - Previous decision ID
104
+ * @param reason - Reason for superseding
105
+ */
106
+ export declare function createSupersedesEdge(fromId: string, toId: string, reason: string): Promise<boolean>;
107
+ /**
108
+ * Update previous decision's superseded_by field
109
+ *
110
+ * Task 3.5: Update previous decision's superseded_by field
111
+ * AC #2: Previous decision's superseded_by field updated
112
+ *
113
+ * @param previousId - Previous decision ID
114
+ * @param newId - New decision ID
115
+ */
116
+ export declare function markSuperseded(previousId: string, newId: string): Promise<void>;
117
+ /**
118
+ * Calculate combined confidence (Bayesian update)
119
+ *
120
+ * Task 3.6: Calculate combined confidence for multi-parent refinement
121
+ * AC #5: Confidence score calculated based on history
122
+ *
123
+ * @param prior - Prior confidence
124
+ * @param parents - Parent decisions
125
+ * @returns Updated confidence (0.0-1.0)
126
+ */
127
+ export declare function calculateCombinedConfidence(prior: number, parents: Array<{
128
+ confidence?: number;
129
+ }>): number;
130
+ /**
131
+ * Detect multi-parent refinement
132
+ *
133
+ * Task 3.6: Detect if new decision refines multiple previous decisions
134
+ * AC #5: Multi-parent refinement
135
+ *
136
+ * @param _detection - Decision detection result
137
+ * @param _sessionContext - Session context
138
+ * @returns Array of parent decision IDs or null
139
+ */
140
+ export declare function detectRefinement(_detection: DecisionDetection, _sessionContext: SessionContext): string[] | null;
141
+ /**
142
+ * Parse reasoning field for relationship references
143
+ *
144
+ * Story 2.2: Detect patterns like:
145
+ * - builds_on: <decision_id>
146
+ * - debates: <decision_id>
147
+ * - synthesizes: [id1, id2]
148
+ *
149
+ * @param reasoning - Decision reasoning text
150
+ * @returns Detected relationships
151
+ */
152
+ export declare function parseReasoningForRelationships(reasoning: string): ParsedRelationship[];
153
+ /**
154
+ * Create edges from parsed reasoning relationships
155
+ *
156
+ * Story 2.2: Auto-create edges when reasoning references other decisions
157
+ *
158
+ * @param fromId - Source decision ID
159
+ * @param reasoning - Decision reasoning text
160
+ * @returns Edge creation stats
161
+ */
162
+ export declare function createEdgesFromReasoning(fromId: string, reasoning: string): Promise<{
163
+ created: number;
164
+ failed: number;
165
+ }>;
166
+ /**
167
+ * Get supersedes chain depth for a topic
168
+ *
169
+ * Story 2.2: Calculate how many times a topic has been superseded
170
+ *
171
+ * @param topic - Decision topic
172
+ * @returns Chain depth and decision IDs
173
+ */
174
+ export declare function getSupersededChainDepth(topic: string): Promise<{
175
+ depth: number;
176
+ chain: string[];
177
+ }>;
178
+ /**
179
+ * Learn Decision Function (Main API)
180
+ *
181
+ * Task 3.1: Create Learn Decision Function
182
+ * Task 3.2: Generate decision ID
183
+ * Task 3.3: Check for previous decision on same topic
184
+ * Task 3.4: Insert new decision with outcome=NULL, confidence from LLM
185
+ * Task 3.5: If previous exists: Create supersedes edge, Update previous superseded_by
186
+ * Task 3.6: If multi-parent refinement: Store refined_from, Calculate combined confidence
187
+ * Task 3.7: Generate enhanced embedding
188
+ * Task 3.8: Store in vss_memories (link via rowid)
189
+ *
190
+ * AC #1: Decision stored with outcome=NULL, confidence from LLM
191
+ * AC #2: Supersedes relationship creation
192
+ * AC #5: Multi-parent refinement with confidence calculation
193
+ *
194
+ * @param detection - Decision detection result
195
+ * @param toolExecution - Tool execution data
196
+ * @param sessionContext - Session context
197
+ * @returns decisionId and notification
198
+ */
199
+ export declare function learnDecision(detection: DecisionDetection, toolExecution: ToolExecution, sessionContext: SessionContext): Promise<LearnDecisionResult>;
200
+ /**
201
+ * Evidence item for confidence updates
202
+ */
203
+ export interface EvidenceItem {
204
+ type: 'success' | 'failure' | 'partial';
205
+ impact: number;
206
+ }
207
+ /**
208
+ * Update confidence score
209
+ *
210
+ * Task 6: Confidence evolution (used in outcome tracking)
211
+ * AC #5: Confidence score calculated based on history
212
+ *
213
+ * @param prior - Prior confidence
214
+ * @param evidence - Evidence items
215
+ * @returns Updated confidence (0.0-1.0)
216
+ */
217
+ export declare function updateConfidence(prior: number, evidence: EvidenceItem[]): number;
218
+ //# sourceMappingURL=decision-tracker.d.ts.map