@jungjaehoon/mama-core 1.1.1 → 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,83 @@
1
+ "use strict";
2
+ /**
3
+ * DebugLogger - Centralized logging for MAMA hooks
4
+ *
5
+ * CLAUDE.md Compliant:
6
+ * - NO console.log (use DebugLogger.info instead)
7
+ * - console.error/warn allowed but wrapped for consistency
8
+ *
9
+ * Features:
10
+ * - Log levels (DEBUG, INFO, WARN, ERROR)
11
+ * - Timestamp formatting
12
+ * - Environment-based filtering
13
+ * - Module/context tagging
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.error = exports.warn = exports.info = exports.debug = exports.DebugLogger = void 0;
17
+ const LOG_LEVELS = {
18
+ DEBUG: 0,
19
+ INFO: 1,
20
+ WARN: 2,
21
+ ERROR: 3,
22
+ NONE: 4,
23
+ };
24
+ class DebugLogger {
25
+ context;
26
+ level;
27
+ constructor(context = 'MAMA') {
28
+ this.context = context;
29
+ this.level = this._getLogLevel();
30
+ }
31
+ _getLogLevel() {
32
+ // Changed default from 'INFO' to 'ERROR' for cleaner output
33
+ // Users can override with MAMA_LOG_LEVEL env var
34
+ const env = (process.env.MAMA_LOG_LEVEL || 'ERROR').toUpperCase();
35
+ return LOG_LEVELS[env] ?? LOG_LEVELS.ERROR;
36
+ }
37
+ _shouldLog(level) {
38
+ return LOG_LEVELS[level] >= this.level;
39
+ }
40
+ _formatMessage(level, ...args) {
41
+ const timestamp = new Date().toISOString();
42
+ const prefix = `[${timestamp}] [${this.context}] [${level}]`;
43
+ return [prefix, ...args];
44
+ }
45
+ debug(...args) {
46
+ if (!this._shouldLog('DEBUG')) {
47
+ return;
48
+ }
49
+ console.error(...this._formatMessage('DEBUG', ...args));
50
+ }
51
+ info(...args) {
52
+ if (!this._shouldLog('INFO')) {
53
+ return;
54
+ }
55
+ console.error(...this._formatMessage('INFO', ...args));
56
+ }
57
+ warn(...args) {
58
+ if (!this._shouldLog('WARN')) {
59
+ return;
60
+ }
61
+ console.warn(...this._formatMessage('WARN', ...args));
62
+ }
63
+ error(...args) {
64
+ if (!this._shouldLog('ERROR')) {
65
+ return;
66
+ }
67
+ console.error(...this._formatMessage('ERROR', ...args));
68
+ }
69
+ }
70
+ exports.DebugLogger = DebugLogger;
71
+ // Export singleton with default context
72
+ const logger = new DebugLogger('MAMA');
73
+ // Export convenience functions
74
+ const debug = (...args) => logger.debug(...args);
75
+ exports.debug = debug;
76
+ const info = (...args) => logger.info(...args);
77
+ exports.info = info;
78
+ const warn = (...args) => logger.warn(...args);
79
+ exports.warn = warn;
80
+ const error = (...args) => logger.error(...args);
81
+ exports.error = error;
82
+ exports.default = logger;
83
+ //# sourceMappingURL=debug-logger.js.map
@@ -0,0 +1,172 @@
1
+ /**
2
+ * MAMA (Memory-Augmented MCP Architecture) - Decision Context Formatter
3
+ *
4
+ * Formats decision history with token budget enforcement and top-N selection
5
+ * Tasks: 6.1-6.6, 8.1-8.5 (Context formatting with top-N selection)
6
+ * AC #1: Context under 500 tokens
7
+ * AC #4: Rolling summary for large histories
8
+ * AC #5: Top-N selection with summary
9
+ *
10
+ * @module decision-formatter
11
+ * @version 2.0
12
+ * @date 2025-11-14
13
+ */
14
+ /**
15
+ * Decision object for formatting
16
+ */
17
+ export interface DecisionForFormat {
18
+ id?: string;
19
+ topic?: string;
20
+ decision: string;
21
+ reasoning?: string | null;
22
+ outcome?: string | null;
23
+ failure_reason?: string | null;
24
+ limitation?: string | null;
25
+ user_involvement?: string;
26
+ confidence?: number;
27
+ created_at: number | string;
28
+ updated_at?: number | string;
29
+ superseded_by?: string | null;
30
+ relevanceScore?: number;
31
+ similarity?: number;
32
+ recency_age_days?: number;
33
+ recency_score?: number;
34
+ final_score?: number;
35
+ trust_context?: TrustContext | string | null;
36
+ evidence?: string | string[] | unknown;
37
+ alternatives?: string | string[] | unknown;
38
+ risks?: string;
39
+ }
40
+ /**
41
+ * Trust context object
42
+ */
43
+ export interface TrustContext {
44
+ source?: {
45
+ file?: string;
46
+ line?: number;
47
+ author?: string;
48
+ timestamp?: number | string;
49
+ };
50
+ causality?: {
51
+ impact?: string;
52
+ };
53
+ verification?: {
54
+ test_file?: string;
55
+ result?: string;
56
+ };
57
+ context_match?: {
58
+ user_intent?: string;
59
+ };
60
+ track_record?: {
61
+ recent_successes?: unknown[];
62
+ recent_failures?: unknown[];
63
+ success_rate?: number;
64
+ sample_size?: number;
65
+ };
66
+ }
67
+ /**
68
+ * Semantic edges for related decisions
69
+ */
70
+ export interface SemanticEdges {
71
+ refines?: Array<{
72
+ topic: string;
73
+ decision: string;
74
+ }>;
75
+ refined_by?: Array<{
76
+ topic: string;
77
+ decision: string;
78
+ }>;
79
+ contradicts?: Array<{
80
+ topic: string;
81
+ decision: string;
82
+ }>;
83
+ contradicted_by?: Array<{
84
+ topic: string;
85
+ decision: string;
86
+ }>;
87
+ }
88
+ /**
89
+ * Formatting options
90
+ */
91
+ export interface FormatOptions {
92
+ maxTokens?: number;
93
+ useTopN?: boolean;
94
+ topN?: number;
95
+ useTeaser?: boolean;
96
+ limit?: number;
97
+ }
98
+ /**
99
+ * Format decision context for Claude injection with top-N selection
100
+ *
101
+ * Task 6.1-6.2, 8.1-8.5: Build context format template with top-N selection
102
+ * AC #1: Format decision history
103
+ * AC #4: Handle large histories with rolling summary
104
+ * AC #5: Top-N selection with summary (top 3 full detail, rest summarized)
105
+ *
106
+ * Story 014.7.10 - Task 5: Fallback Formatting
107
+ * Tries Instant Answer format first (if trust_context available), falls back to legacy
108
+ *
109
+ * @param decisions - Decision chain (sorted by relevance)
110
+ * @param options - Formatting options
111
+ * @returns Formatted context for injection
112
+ */
113
+ export declare function formatContext(decisions: DecisionForFormat[], options?: FormatOptions): string | null;
114
+ /**
115
+ * Format decisions using legacy format (no trust context)
116
+ *
117
+ * Story 014.7.10 - Task 5.1: Fallback formatting
118
+ * AC #3: Graceful degradation for decisions without trust_context
119
+ *
120
+ * @param decisions - Decision chain (sorted by relevance)
121
+ * @param options - Formatting options
122
+ * @returns Formatted context (legacy format)
123
+ */
124
+ export declare function formatLegacyContext(decisions: DecisionForFormat[], options?: FormatOptions): string | null;
125
+ /**
126
+ * Ensure token budget is enforced
127
+ *
128
+ * Task 6.3-6.5: Token budget enforcement
129
+ * AC #1: Context stays under 500 tokens
130
+ */
131
+ export declare function ensureTokenBudget(text: string, maxTokens: number): string;
132
+ /**
133
+ * Estimate token count from text
134
+ *
135
+ * Task 6.4: Simple token estimation
136
+ * Heuristic: ~1 token per 4 characters
137
+ */
138
+ export declare function estimateTokens(text: string): number;
139
+ /**
140
+ * Format context in Claude-friendly Instant Answer format
141
+ *
142
+ * Story 014.7.10: Claude-Friendly Context Formatting
143
+ * AC #1: Instant Answer format with trust components
144
+ */
145
+ export declare function formatInstantAnswer(decision: DecisionForFormat | null, options?: FormatOptions): string | null;
146
+ /**
147
+ * Extract quick answer from decision
148
+ */
149
+ export declare function extractQuickAnswer(decision: DecisionForFormat): string | null;
150
+ /**
151
+ * Extract code example from reasoning
152
+ */
153
+ export declare function extractCodeExample(decision: DecisionForFormat): string | null;
154
+ /**
155
+ * Format trust context section
156
+ *
157
+ * Story 014.7.10 AC #2: Trust Context display
158
+ */
159
+ export declare function formatTrustContext(trustCtx: TrustContext | null | undefined): string | null;
160
+ /**
161
+ * Format decision as curiosity-inducing teaser
162
+ */
163
+ export declare function formatTeaser(decision: DecisionForFormat | null): string | null;
164
+ /**
165
+ * Format mama.recall() results in readable format
166
+ */
167
+ export declare function formatRecall(decisions: DecisionForFormat[], semanticEdges?: SemanticEdges | null): string;
168
+ /**
169
+ * Format recent decisions list (all topics, chronological)
170
+ */
171
+ export declare function formatList(decisions: DecisionForFormat[], options?: FormatOptions): string;
172
+ //# sourceMappingURL=decision-formatter.d.ts.map