cortex-mcp 2.7.6 → 2.9.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/CHANGELOG.md +305 -58
- package/README.md +394 -224
- package/dist/cli/setup.js +58 -60
- package/dist/cli/setup.js.map +1 -1
- package/dist/config/config.js +2 -2
- package/dist/config/config.js.map +1 -1
- package/dist/db/database.d.ts +8 -0
- package/dist/db/database.d.ts.map +1 -1
- package/dist/db/database.js +35 -54
- package/dist/db/database.js.map +1 -1
- package/dist/db/event-log.d.ts +4 -0
- package/dist/db/event-log.d.ts.map +1 -1
- package/dist/db/event-log.js +14 -10
- package/dist/db/event-log.js.map +1 -1
- package/dist/db/memory-store.d.ts +30 -3
- package/dist/db/memory-store.d.ts.map +1 -1
- package/dist/db/memory-store.js +153 -55
- package/dist/db/memory-store.js.map +1 -1
- package/dist/embedding-worker.js +1 -1
- package/dist/embedding-worker.js.map +1 -1
- package/dist/hooks/git-capture.js +3 -3
- package/dist/hooks/git-hooks.js +5 -2
- package/dist/mcp-stdio.js +39 -5
- package/dist/mcp-stdio.js.map +1 -1
- package/dist/memory/access-pattern-tracker.d.ts +51 -0
- package/dist/memory/access-pattern-tracker.d.ts.map +1 -0
- package/dist/memory/access-pattern-tracker.js +92 -0
- package/dist/memory/access-pattern-tracker.js.map +1 -0
- package/dist/memory/anticipation-engine.d.ts.map +1 -1
- package/dist/memory/anticipation-engine.js +18 -10
- package/dist/memory/anticipation-engine.js.map +1 -1
- package/dist/memory/auto-learner.d.ts.map +1 -1
- package/dist/memory/auto-learner.js +192 -45
- package/dist/memory/auto-learner.js.map +1 -1
- package/dist/memory/completion-resolver.d.ts +38 -0
- package/dist/memory/completion-resolver.d.ts.map +1 -0
- package/dist/memory/completion-resolver.js +127 -0
- package/dist/memory/completion-resolver.js.map +1 -0
- package/dist/memory/confidence-decay.d.ts.map +1 -1
- package/dist/memory/confidence-decay.js +13 -9
- package/dist/memory/confidence-decay.js.map +1 -1
- package/dist/memory/convention-detector.d.ts +11 -0
- package/dist/memory/convention-detector.d.ts.map +1 -0
- package/dist/memory/convention-detector.js +294 -0
- package/dist/memory/convention-detector.js.map +1 -0
- package/dist/memory/correction-detector.d.ts +33 -0
- package/dist/memory/correction-detector.d.ts.map +1 -0
- package/dist/memory/correction-detector.js +129 -0
- package/dist/memory/correction-detector.js.map +1 -0
- package/dist/memory/cross-memory-linker.d.ts +18 -0
- package/dist/memory/cross-memory-linker.d.ts.map +1 -0
- package/dist/memory/cross-memory-linker.js +115 -0
- package/dist/memory/cross-memory-linker.js.map +1 -0
- package/dist/memory/daily-diary.d.ts +30 -0
- package/dist/memory/daily-diary.d.ts.map +1 -0
- package/dist/memory/daily-diary.js +159 -0
- package/dist/memory/daily-diary.js.map +1 -0
- package/dist/memory/embedding-cache.d.ts +32 -0
- package/dist/memory/embedding-cache.d.ts.map +1 -0
- package/dist/memory/embedding-cache.js +76 -0
- package/dist/memory/embedding-cache.js.map +1 -0
- package/dist/memory/embedding-manager.d.ts.map +1 -1
- package/dist/memory/embedding-manager.js +6 -4
- package/dist/memory/embedding-manager.js.map +1 -1
- package/dist/memory/error-learner.d.ts +26 -0
- package/dist/memory/error-learner.d.ts.map +1 -0
- package/dist/memory/error-learner.js +145 -0
- package/dist/memory/error-learner.js.map +1 -0
- package/dist/memory/export-import.js +2 -2
- package/dist/memory/export-import.js.map +1 -1
- package/dist/memory/file-relationships.d.ts +47 -0
- package/dist/memory/file-relationships.d.ts.map +1 -0
- package/dist/memory/file-relationships.js +130 -0
- package/dist/memory/file-relationships.js.map +1 -0
- package/dist/memory/git-memory.d.ts.map +1 -1
- package/dist/memory/git-memory.js +20 -26
- package/dist/memory/git-memory.js.map +1 -1
- package/dist/memory/impact-analyzer.d.ts +16 -0
- package/dist/memory/impact-analyzer.d.ts.map +1 -0
- package/dist/memory/impact-analyzer.js +189 -0
- package/dist/memory/impact-analyzer.js.map +1 -0
- package/dist/memory/instructions-generator.d.ts +30 -0
- package/dist/memory/instructions-generator.d.ts.map +1 -0
- package/dist/memory/instructions-generator.js +117 -0
- package/dist/memory/instructions-generator.js.map +1 -0
- package/dist/memory/learning-rate.js +8 -7
- package/dist/memory/learning-rate.js.map +1 -1
- package/dist/memory/llm-enhancer.d.ts +2 -14
- package/dist/memory/llm-enhancer.d.ts.map +1 -1
- package/dist/memory/llm-enhancer.js +66 -46
- package/dist/memory/llm-enhancer.js.map +1 -1
- package/dist/memory/memory-cache.d.ts.map +1 -1
- package/dist/memory/memory-cache.js +10 -0
- package/dist/memory/memory-cache.js.map +1 -1
- package/dist/memory/memory-consolidator.d.ts.map +1 -1
- package/dist/memory/memory-consolidator.js +20 -14
- package/dist/memory/memory-consolidator.js.map +1 -1
- package/dist/memory/memory-decay.d.ts.map +1 -1
- package/dist/memory/memory-decay.js +82 -52
- package/dist/memory/memory-decay.js.map +1 -1
- package/dist/memory/memory-export-md.d.ts +12 -0
- package/dist/memory/memory-export-md.d.ts.map +1 -0
- package/dist/memory/memory-export-md.js +188 -0
- package/dist/memory/memory-export-md.js.map +1 -0
- package/dist/memory/memory-quality.d.ts +1 -1
- package/dist/memory/memory-quality.d.ts.map +1 -1
- package/dist/memory/memory-quality.js +9 -6
- package/dist/memory/memory-quality.js.map +1 -1
- package/dist/memory/memory-ranker.d.ts.map +1 -1
- package/dist/memory/memory-ranker.js +12 -3
- package/dist/memory/memory-ranker.js.map +1 -1
- package/dist/memory/meta-memory.js +3 -3
- package/dist/memory/meta-memory.js.map +1 -1
- package/dist/memory/mmr-reranker.d.ts +39 -0
- package/dist/memory/mmr-reranker.d.ts.map +1 -0
- package/dist/memory/mmr-reranker.js +115 -0
- package/dist/memory/mmr-reranker.js.map +1 -0
- package/dist/memory/pre-flight.d.ts +24 -0
- package/dist/memory/pre-flight.d.ts.map +1 -0
- package/dist/memory/pre-flight.js +121 -0
- package/dist/memory/pre-flight.js.map +1 -0
- package/dist/memory/preference-learner.d.ts +28 -0
- package/dist/memory/preference-learner.d.ts.map +1 -0
- package/dist/memory/preference-learner.js +144 -0
- package/dist/memory/preference-learner.js.map +1 -0
- package/dist/memory/query-expansion.d.ts +28 -0
- package/dist/memory/query-expansion.d.ts.map +1 -0
- package/dist/memory/query-expansion.js +140 -0
- package/dist/memory/query-expansion.js.map +1 -0
- package/dist/memory/regression-guard.d.ts +35 -0
- package/dist/memory/regression-guard.d.ts.map +1 -0
- package/dist/memory/regression-guard.js +90 -0
- package/dist/memory/regression-guard.js.map +1 -0
- package/dist/memory/resume-work.d.ts +37 -0
- package/dist/memory/resume-work.d.ts.map +1 -0
- package/dist/memory/resume-work.js +141 -0
- package/dist/memory/resume-work.js.map +1 -0
- package/dist/memory/session-tracker.d.ts +2 -0
- package/dist/memory/session-tracker.d.ts.map +1 -1
- package/dist/memory/session-tracker.js +26 -8
- package/dist/memory/session-tracker.js.map +1 -1
- package/dist/memory/soul-manager.d.ts +30 -0
- package/dist/memory/soul-manager.d.ts.map +1 -0
- package/dist/memory/soul-manager.js +171 -0
- package/dist/memory/soul-manager.js.map +1 -0
- package/dist/memory/success-tracker.d.ts +33 -0
- package/dist/memory/success-tracker.d.ts.map +1 -0
- package/dist/memory/success-tracker.js +75 -0
- package/dist/memory/success-tracker.js.map +1 -0
- package/dist/memory/temporal-engine.d.ts.map +1 -1
- package/dist/memory/temporal-engine.js +9 -13
- package/dist/memory/temporal-engine.js.map +1 -1
- package/dist/memory/tool-recommender.d.ts +29 -0
- package/dist/memory/tool-recommender.d.ts.map +1 -0
- package/dist/memory/tool-recommender.js +117 -0
- package/dist/memory/tool-recommender.js.map +1 -0
- package/dist/memory/usage-stats.d.ts +98 -0
- package/dist/memory/usage-stats.d.ts.map +1 -0
- package/dist/memory/usage-stats.js +345 -0
- package/dist/memory/usage-stats.js.map +1 -0
- package/dist/retrieval/hybrid-retriever.d.ts +0 -2
- package/dist/retrieval/hybrid-retriever.d.ts.map +1 -1
- package/dist/retrieval/hybrid-retriever.js +3 -13
- package/dist/retrieval/hybrid-retriever.js.map +1 -1
- package/dist/scanners/architecture-graph.js +2 -2
- package/dist/scanners/architecture-graph.js.map +1 -1
- package/dist/scanners/code-verifier.d.ts +1 -0
- package/dist/scanners/code-verifier.d.ts.map +1 -1
- package/dist/scanners/code-verifier.js +14 -14
- package/dist/scanners/code-verifier.js.map +1 -1
- package/dist/scanners/context-builder.d.ts.map +1 -1
- package/dist/scanners/context-builder.js +33 -45
- package/dist/scanners/context-builder.js.map +1 -1
- package/dist/scanners/export-map.js +2 -2
- package/dist/scanners/export-map.js.map +1 -1
- package/dist/scanners/project-scanner.js +2 -2
- package/dist/scanners/project-scanner.js.map +1 -1
- package/dist/security/encryption.js +1 -1
- package/dist/security/encryption.js.map +1 -1
- package/dist/security/feature-gate.d.ts.map +1 -1
- package/dist/security/feature-gate.js +62 -20
- package/dist/security/feature-gate.js.map +1 -1
- package/dist/security/license.js +282 -35
- package/dist/security/license.js.map +1 -1
- package/dist/security/rate-limiter.d.ts +4 -3
- package/dist/security/rate-limiter.d.ts.map +1 -1
- package/dist/security/rate-limiter.js +11 -29
- package/dist/security/rate-limiter.js.map +1 -1
- package/dist/server/dashboard.js +166 -327
- package/dist/server/dashboard.js.map +1 -1
- package/dist/server/mcp-handler.d.ts.map +1 -1
- package/dist/server/mcp-handler.js +1000 -792
- package/dist/server/mcp-handler.js.map +1 -1
- package/dist/utils/extract-tags.d.ts +16 -0
- package/dist/utils/extract-tags.d.ts.map +1 -0
- package/dist/utils/extract-tags.js +40 -0
- package/dist/utils/extract-tags.js.map +1 -0
- package/package.json +18 -8
- package/dist/core/event-bus.d.ts +0 -19
- package/dist/core/event-bus.d.ts.map +0 -1
- package/dist/core/event-bus.js +0 -51
- package/dist/core/event-bus.js.map +0 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.detectPreferences = detectPreferences;
|
|
4
|
+
exports.getStoredPreferences = getStoredPreferences;
|
|
5
|
+
// ─── Preference Detection Patterns ───────────────────────────────────────────
|
|
6
|
+
const PREFERENCE_PATTERNS = [
|
|
7
|
+
// Communication style
|
|
8
|
+
{
|
|
9
|
+
category: 'communication',
|
|
10
|
+
signals: [
|
|
11
|
+
/\b(keep it short|be (more )?(brief|concise)|too (long|verbose)|shorter|less (text|detail))\b/gi,
|
|
12
|
+
/\b(tldr|tl;dr|just the (code|answer)|skip the explanation)\b/gi,
|
|
13
|
+
],
|
|
14
|
+
preference: 'User prefers concise, short responses — skip long explanations',
|
|
15
|
+
confidence: 0.85,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
category: 'communication',
|
|
19
|
+
signals: [
|
|
20
|
+
/\b(explain (more|why|how)|tell me (more|why)|what does .{3,20} mean|I don'?t understand)\b/gi,
|
|
21
|
+
/\b(more detail|elaborate|walk me through|step by step)\b/gi,
|
|
22
|
+
],
|
|
23
|
+
preference: 'User prefers detailed explanations — explain reasoning and steps',
|
|
24
|
+
confidence: 0.80,
|
|
25
|
+
},
|
|
26
|
+
// Workflow style
|
|
27
|
+
{
|
|
28
|
+
category: 'workflow',
|
|
29
|
+
signals: [
|
|
30
|
+
/\b(just (do|fix|change|build) it|don'?t ask|stop asking|go ahead)\b/gi,
|
|
31
|
+
/\b(you decide|your (call|choice)|whatever you think|I trust you)\b/gi,
|
|
32
|
+
],
|
|
33
|
+
preference: 'User prefers autonomous execution — do it without asking for approval',
|
|
34
|
+
confidence: 0.85,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
category: 'workflow',
|
|
38
|
+
signals: [
|
|
39
|
+
/\b(ask (me|first)|check with me|don'?t (change|modify) (without|until)|show me (first|before))\b/gi,
|
|
40
|
+
/\b(let me (review|see|approve)|wait for (my|approval))\b/gi,
|
|
41
|
+
],
|
|
42
|
+
preference: 'User prefers to review before changes — always ask before modifying',
|
|
43
|
+
confidence: 0.85,
|
|
44
|
+
},
|
|
45
|
+
// Coding style
|
|
46
|
+
{
|
|
47
|
+
category: 'coding',
|
|
48
|
+
signals: [
|
|
49
|
+
/\b(use (typescript|ts)|type(d|safe|safety)|add types|interface|generic)\b/gi,
|
|
50
|
+
],
|
|
51
|
+
preference: 'User values TypeScript strict typing — always add types and interfaces',
|
|
52
|
+
confidence: 0.70,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
category: 'coding',
|
|
56
|
+
signals: [
|
|
57
|
+
/\b(add (tests|test)|test (first|coverage)|write (a )?test|unit test|spec)\b/gi,
|
|
58
|
+
],
|
|
59
|
+
preference: 'User values testing — write tests alongside code',
|
|
60
|
+
confidence: 0.75,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
category: 'coding',
|
|
64
|
+
signals: [
|
|
65
|
+
/\b(no (comments|documentation)|don'?t add comments|too many comments|over.?comment)\b/gi,
|
|
66
|
+
],
|
|
67
|
+
preference: 'User prefers minimal comments — code should be self-documenting',
|
|
68
|
+
confidence: 0.75,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
category: 'coding',
|
|
72
|
+
signals: [
|
|
73
|
+
/\b(add comments|document|jsdoc|explain the code|comment the|well.?documented)\b/gi,
|
|
74
|
+
],
|
|
75
|
+
preference: 'User values code documentation — add comments and JSDoc',
|
|
76
|
+
confidence: 0.75,
|
|
77
|
+
},
|
|
78
|
+
// Style preferences
|
|
79
|
+
{
|
|
80
|
+
category: 'style',
|
|
81
|
+
signals: [
|
|
82
|
+
/\b(dark (mode|theme)|prefer dark|use dark)\b/gi,
|
|
83
|
+
],
|
|
84
|
+
preference: 'User prefers dark mode/theme',
|
|
85
|
+
confidence: 0.80,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
category: 'style',
|
|
89
|
+
signals: [
|
|
90
|
+
/\b(simple|minimal|minimalist|clean|no (fancy|animation|effect))\b/gi,
|
|
91
|
+
],
|
|
92
|
+
preference: 'User prefers simple, minimalist design — avoid complex UI effects',
|
|
93
|
+
confidence: 0.70,
|
|
94
|
+
},
|
|
95
|
+
];
|
|
96
|
+
// ─── Main Detector ───────────────────────────────────────────────────────────
|
|
97
|
+
/**
|
|
98
|
+
* Detect user preferences from their message text.
|
|
99
|
+
* Call this from auto_learn when context is provided.
|
|
100
|
+
*/
|
|
101
|
+
function detectPreferences(userText) {
|
|
102
|
+
if (!userText || userText.length < 10)
|
|
103
|
+
return [];
|
|
104
|
+
const results = [];
|
|
105
|
+
const seen = new Set();
|
|
106
|
+
for (const pattern of PREFERENCE_PATTERNS) {
|
|
107
|
+
for (const signal of pattern.signals) {
|
|
108
|
+
signal.lastIndex = 0;
|
|
109
|
+
const match = signal.exec(userText);
|
|
110
|
+
if (match && !seen.has(pattern.preference)) {
|
|
111
|
+
seen.add(pattern.preference);
|
|
112
|
+
results.push({
|
|
113
|
+
category: pattern.category,
|
|
114
|
+
preference: pattern.preference,
|
|
115
|
+
confidence: pattern.confidence,
|
|
116
|
+
evidence: match[0].trim().slice(0, 100),
|
|
117
|
+
});
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return results;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Get all stored preferences for injection into force_recall.
|
|
126
|
+
*/
|
|
127
|
+
function getStoredPreferences(memoryStore) {
|
|
128
|
+
// Search for preference-tagged memories
|
|
129
|
+
try {
|
|
130
|
+
const results = memoryStore.searchFTS('preference', 10);
|
|
131
|
+
const prefs = results.filter(r => r.memory.tags?.includes('preference') || r.memory.type === 'CONVENTION');
|
|
132
|
+
if (prefs.length === 0)
|
|
133
|
+
return '';
|
|
134
|
+
const lines = ['## 👤 User Preferences'];
|
|
135
|
+
for (const p of prefs.slice(0, 5)) {
|
|
136
|
+
lines.push(`- ${p.memory.intent}`);
|
|
137
|
+
}
|
|
138
|
+
return lines.join('\n');
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return '';
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=preference-learner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preference-learner.js","sourceRoot":"","sources":["../../src/memory/preference-learner.ts"],"names":[],"mappings":";;AA+HA,8CAwBC;AAKD,oDAkBC;AA1JD,gFAAgF;AAEhF,MAAM,mBAAmB,GAKpB;IACD,sBAAsB;IACtB;QACI,QAAQ,EAAE,eAAe;QACzB,OAAO,EAAE;YACL,gGAAgG;YAChG,gEAAgE;SACnE;QACD,UAAU,EAAE,gEAAgE;QAC5E,UAAU,EAAE,IAAI;KACnB;IACD;QACI,QAAQ,EAAE,eAAe;QACzB,OAAO,EAAE;YACL,8FAA8F;YAC9F,4DAA4D;SAC/D;QACD,UAAU,EAAE,kEAAkE;QAC9E,UAAU,EAAE,IAAI;KACnB;IAED,iBAAiB;IACjB;QACI,QAAQ,EAAE,UAAU;QACpB,OAAO,EAAE;YACL,uEAAuE;YACvE,sEAAsE;SACzE;QACD,UAAU,EAAE,uEAAuE;QACnF,UAAU,EAAE,IAAI;KACnB;IACD;QACI,QAAQ,EAAE,UAAU;QACpB,OAAO,EAAE;YACL,oGAAoG;YACpG,4DAA4D;SAC/D;QACD,UAAU,EAAE,qEAAqE;QACjF,UAAU,EAAE,IAAI;KACnB;IAED,eAAe;IACf;QACI,QAAQ,EAAE,QAAQ;QAClB,OAAO,EAAE;YACL,6EAA6E;SAChF;QACD,UAAU,EAAE,wEAAwE;QACpF,UAAU,EAAE,IAAI;KACnB;IACD;QACI,QAAQ,EAAE,QAAQ;QAClB,OAAO,EAAE;YACL,+EAA+E;SAClF;QACD,UAAU,EAAE,kDAAkD;QAC9D,UAAU,EAAE,IAAI;KACnB;IACD;QACI,QAAQ,EAAE,QAAQ;QAClB,OAAO,EAAE;YACL,yFAAyF;SAC5F;QACD,UAAU,EAAE,iEAAiE;QAC7E,UAAU,EAAE,IAAI;KACnB;IACD;QACI,QAAQ,EAAE,QAAQ;QAClB,OAAO,EAAE;YACL,mFAAmF;SACtF;QACD,UAAU,EAAE,yDAAyD;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IAED,OAAO,OAAO,CAAC;AACnB,CAAC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAAC,WAAwB;IACzD,wCAAwC;IACxC,IAAI,CAAC;QACD,MAAM,OAAO,GAAG,WAAW,CAAC,SAAS,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QACxD,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAC7B,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,YAAY,CAAC,IAAK,CAAC,CAAC,MAAM,CAAC,IAAe,KAAK,YAAY,CACtF,CAAC;QAEF,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,EAAE,CAAC;QAElC,MAAM,KAAK,GAAa,CAAC,wBAAwB,CAAC,CAAC;QACnD,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;YAChC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;QACvC,CAAC;QACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,EAAE,CAAC;IACd,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query Expansion — Smarter search like OpenClaw's query-expansion.ts.
|
|
3
|
+
*
|
|
4
|
+
* Problem: User searches for "authentication bug" but the memory
|
|
5
|
+
* says "login issue with JWT tokens." Raw search misses it.
|
|
6
|
+
*
|
|
7
|
+
* Solution: Expand the query with synonyms and related terms:
|
|
8
|
+
* "authentication bug" → "authentication auth login bug error issue fix"
|
|
9
|
+
*
|
|
10
|
+
* This is OpenClaw's approach — extract keywords and add related terms
|
|
11
|
+
* so both FTS and vector search find more relevant results.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Expand a query with synonyms and related programming terms.
|
|
15
|
+
* Returns the original query plus expanded terms.
|
|
16
|
+
*/
|
|
17
|
+
export declare function expandQuery(query: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Extract key technical terms from a query for targeted search.
|
|
20
|
+
* Filters out stop words and generic terms, keeping only meaningful tokens.
|
|
21
|
+
*/
|
|
22
|
+
export declare function extractKeyTerms(query: string): string[];
|
|
23
|
+
/**
|
|
24
|
+
* Generate alternative search queries for better recall.
|
|
25
|
+
* Returns the original plus 1-2 reformulated queries.
|
|
26
|
+
*/
|
|
27
|
+
export declare function generateAlternativeQueries(query: string): string[];
|
|
28
|
+
//# sourceMappingURL=query-expansion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-expansion.d.ts","sourceRoot":"","sources":["../../src/memory/query-expansion.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAcjD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAKvD;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAsBlE"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Query Expansion — Smarter search like OpenClaw's query-expansion.ts.
|
|
4
|
+
*
|
|
5
|
+
* Problem: User searches for "authentication bug" but the memory
|
|
6
|
+
* says "login issue with JWT tokens." Raw search misses it.
|
|
7
|
+
*
|
|
8
|
+
* Solution: Expand the query with synonyms and related terms:
|
|
9
|
+
* "authentication bug" → "authentication auth login bug error issue fix"
|
|
10
|
+
*
|
|
11
|
+
* This is OpenClaw's approach — extract keywords and add related terms
|
|
12
|
+
* so both FTS and vector search find more relevant results.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.expandQuery = expandQuery;
|
|
16
|
+
exports.extractKeyTerms = extractKeyTerms;
|
|
17
|
+
exports.generateAlternativeQueries = generateAlternativeQueries;
|
|
18
|
+
/**
|
|
19
|
+
* Expand a query with synonyms and related programming terms.
|
|
20
|
+
* Returns the original query plus expanded terms.
|
|
21
|
+
*/
|
|
22
|
+
function expandQuery(query) {
|
|
23
|
+
const words = query.toLowerCase().split(/\s+/).filter(w => w.length > 1);
|
|
24
|
+
const expanded = new Set(words);
|
|
25
|
+
for (const word of words) {
|
|
26
|
+
const synonyms = SYNONYM_MAP[word];
|
|
27
|
+
if (synonyms) {
|
|
28
|
+
for (const syn of synonyms) {
|
|
29
|
+
expanded.add(syn);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return Array.from(expanded).join(' ');
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Extract key technical terms from a query for targeted search.
|
|
37
|
+
* Filters out stop words and generic terms, keeping only meaningful tokens.
|
|
38
|
+
*/
|
|
39
|
+
function extractKeyTerms(query) {
|
|
40
|
+
return query.toLowerCase()
|
|
41
|
+
.replace(/[^a-z0-9\s_-]/g, ' ')
|
|
42
|
+
.split(/\s+/)
|
|
43
|
+
.filter(w => w.length > 2 && !STOP_WORDS.has(w));
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Generate alternative search queries for better recall.
|
|
47
|
+
* Returns the original plus 1-2 reformulated queries.
|
|
48
|
+
*/
|
|
49
|
+
function generateAlternativeQueries(query) {
|
|
50
|
+
const queries = [query];
|
|
51
|
+
const lower = query.toLowerCase();
|
|
52
|
+
// If asking "how to X" → also search for "X implementation"
|
|
53
|
+
const howToMatch = lower.match(/how\s+to\s+(.+)/);
|
|
54
|
+
if (howToMatch) {
|
|
55
|
+
queries.push(`${howToMatch[1]} implementation`);
|
|
56
|
+
queries.push(`${howToMatch[1]} pattern`);
|
|
57
|
+
}
|
|
58
|
+
// If asking about "error" → also search for "bug fix"
|
|
59
|
+
if (lower.includes('error') || lower.includes('bug')) {
|
|
60
|
+
queries.push(lower.replace(/error|bug/g, 'fix correction'));
|
|
61
|
+
}
|
|
62
|
+
// If asking about "why" → search for decisions
|
|
63
|
+
if (lower.startsWith('why')) {
|
|
64
|
+
queries.push(lower.replace('why', 'decision reason'));
|
|
65
|
+
}
|
|
66
|
+
return queries.slice(0, 3); // Max 3 alternatives
|
|
67
|
+
}
|
|
68
|
+
// ─── Synonym Map for Programming Terms ──────────────────────────────────────
|
|
69
|
+
const SYNONYM_MAP = {
|
|
70
|
+
// Authentication
|
|
71
|
+
'auth': ['authentication', 'login', 'signin', 'jwt', 'token', 'session'],
|
|
72
|
+
'authentication': ['auth', 'login', 'signin', 'jwt'],
|
|
73
|
+
'login': ['auth', 'authentication', 'signin'],
|
|
74
|
+
'logout': ['signout', 'session'],
|
|
75
|
+
// Database
|
|
76
|
+
'database': ['db', 'sql', 'query', 'schema', 'migration'],
|
|
77
|
+
'db': ['database', 'sql', 'query'],
|
|
78
|
+
'sql': ['database', 'query', 'schema'],
|
|
79
|
+
'migration': ['database', 'schema', 'alter'],
|
|
80
|
+
'schema': ['database', 'model', 'table'],
|
|
81
|
+
// API
|
|
82
|
+
'api': ['endpoint', 'route', 'rest', 'request', 'response'],
|
|
83
|
+
'endpoint': ['api', 'route', 'handler'],
|
|
84
|
+
'route': ['api', 'endpoint', 'path', 'handler'],
|
|
85
|
+
'request': ['req', 'http', 'fetch'],
|
|
86
|
+
'response': ['res', 'http', 'reply'],
|
|
87
|
+
// Errors & Debugging
|
|
88
|
+
'error': ['bug', 'issue', 'exception', 'crash', 'failure', 'fix'],
|
|
89
|
+
'bug': ['error', 'issue', 'defect', 'fix', 'correction'],
|
|
90
|
+
'fix': ['repair', 'correction', 'patch', 'resolve'],
|
|
91
|
+
'crash': ['error', 'exception', 'failure', 'abort'],
|
|
92
|
+
'debug': ['troubleshoot', 'diagnose', 'inspect', 'trace'],
|
|
93
|
+
// Testing
|
|
94
|
+
'test': ['testing', 'spec', 'unit', 'jest', 'mocha', 'vitest'],
|
|
95
|
+
'testing': ['test', 'spec', 'assertion', 'mock'],
|
|
96
|
+
'mock': ['stub', 'fake', 'spy', 'test'],
|
|
97
|
+
// Architecture
|
|
98
|
+
'component': ['module', 'widget', 'element'],
|
|
99
|
+
'module': ['component', 'package', 'library'],
|
|
100
|
+
'pattern': ['architecture', 'design', 'structure'],
|
|
101
|
+
'refactor': ['restructure', 'cleanup', 'reorganize'],
|
|
102
|
+
// Frontend
|
|
103
|
+
'style': ['css', 'styling', 'theme', 'design'],
|
|
104
|
+
'css': ['style', 'stylesheet', 'tailwind'],
|
|
105
|
+
'ui': ['interface', 'frontend', 'view', 'component'],
|
|
106
|
+
'layout': ['grid', 'flex', 'responsive', 'design'],
|
|
107
|
+
// State
|
|
108
|
+
'state': ['store', 'context', 'redux', 'zustand'],
|
|
109
|
+
'cache': ['memo', 'memoize', 'store', 'buffer'],
|
|
110
|
+
// Config
|
|
111
|
+
'config': ['configuration', 'settings', 'options', 'env'],
|
|
112
|
+
'env': ['environment', 'config', 'dotenv', 'variable'],
|
|
113
|
+
// Performance
|
|
114
|
+
'performance': ['speed', 'optimize', 'fast', 'slow', 'latency'],
|
|
115
|
+
'optimize': ['performance', 'improve', 'speed', 'efficient'],
|
|
116
|
+
'slow': ['performance', 'latency', 'bottleneck', 'optimize'],
|
|
117
|
+
// Security
|
|
118
|
+
'security': ['auth', 'encryption', 'vulnerability', 'xss', 'csrf'],
|
|
119
|
+
'encrypt': ['hash', 'security', 'cipher', 'bcrypt'],
|
|
120
|
+
// TypeScript
|
|
121
|
+
'type': ['interface', 'typescript', 'generic', 'typing'],
|
|
122
|
+
'interface': ['type', 'contract', 'shape', 'typescript'],
|
|
123
|
+
'generic': ['type', 'template', 'parameterized'],
|
|
124
|
+
// Deployment
|
|
125
|
+
'deploy': ['deployment', 'release', 'publish', 'ship'],
|
|
126
|
+
'ci': ['pipeline', 'github-actions', 'workflow', 'build'],
|
|
127
|
+
};
|
|
128
|
+
const STOP_WORDS = new Set([
|
|
129
|
+
'the', 'a', 'an', 'is', 'are', 'was', 'were', 'be', 'been', 'being',
|
|
130
|
+
'have', 'has', 'had', 'do', 'does', 'did', 'will', 'would', 'could',
|
|
131
|
+
'should', 'may', 'might', 'can', 'shall', 'to', 'of', 'in', 'for',
|
|
132
|
+
'on', 'with', 'at', 'by', 'from', 'as', 'into', 'through', 'during',
|
|
133
|
+
'this', 'that', 'these', 'those', 'it', 'its', 'not', 'no', 'but',
|
|
134
|
+
'or', 'and', 'if', 'then', 'else', 'when', 'up', 'out', 'about',
|
|
135
|
+
'so', 'all', 'each', 'every', 'both', 'few', 'more', 'most', 'other',
|
|
136
|
+
'some', 'such', 'only', 'own', 'same', 'than', 'too', 'very',
|
|
137
|
+
'just', 'because', 'before', 'after', 'above', 'below', 'between',
|
|
138
|
+
'what', 'which', 'who', 'whom', 'how', 'where', 'there', 'here',
|
|
139
|
+
]);
|
|
140
|
+
//# sourceMappingURL=query-expansion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-expansion.js","sourceRoot":"","sources":["../../src/memory/query-expansion.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;AAMH,kCAcC;AAMD,0CAKC;AAMD,gEAsBC;AAzDD;;;GAGG;AACH,SAAgB,WAAW,CAAC,KAAa;IACrC,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACzE,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;IAEhC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACvB,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;QACnC,IAAI,QAAQ,E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
* it didn't regress. Next time a similar issue appears, the AI has to
|
|
7
|
+
* figure out testing from scratch.
|
|
8
|
+
*
|
|
9
|
+
* This module:
|
|
10
|
+
* 1. Attaches verification steps to BUG_FIX memories
|
|
11
|
+
* 2. When a similar bug appears, surfaces both the fix AND the test
|
|
12
|
+
* 3. Tracks which fixes have been verified vs unverified
|
|
13
|
+
*/
|
|
14
|
+
import { MemoryStore } from '../db/memory-store';
|
|
15
|
+
export interface VerificationStep {
|
|
16
|
+
command?: string;
|
|
17
|
+
check?: string;
|
|
18
|
+
file?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Extract verification steps from AI text.
|
|
22
|
+
* Looks for build/test commands and their expected outcomes.
|
|
23
|
+
*/
|
|
24
|
+
export declare function extractVerificationSteps(text: string): VerificationStep[];
|
|
25
|
+
/**
|
|
26
|
+
* Find verification steps for similar past bugs.
|
|
27
|
+
* When a new bug appears, search for related fixes and their verification.
|
|
28
|
+
*/
|
|
29
|
+
export declare function findRelatedVerification(memoryStore: MemoryStore, bugDescription: string): string[];
|
|
30
|
+
/**
|
|
31
|
+
* Attach verification steps to a bug fix description.
|
|
32
|
+
* Returns enhanced text with verification section appended.
|
|
33
|
+
*/
|
|
34
|
+
export declare function attachVerification(fixDescription: string, steps: VerificationStep[]): string;
|
|
35
|
+
//# sourceMappingURL=regression-guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regression-guard.d.ts","sourceRoot":"","sources":["../../src/memory/regression-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,MAAM,WAAW,gBAAgB;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAsCzE;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,EAAE,CAiBlG;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAkB5F"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractVerificationSteps = extractVerificationSteps;
|
|
4
|
+
exports.findRelatedVerification = findRelatedVerification;
|
|
5
|
+
exports.attachVerification = attachVerification;
|
|
6
|
+
const types_1 = require("../types");
|
|
7
|
+
/**
|
|
8
|
+
* Extract verification steps from AI text.
|
|
9
|
+
* Looks for build/test commands and their expected outcomes.
|
|
10
|
+
*/
|
|
11
|
+
function extractVerificationSteps(text) {
|
|
12
|
+
const steps = [];
|
|
13
|
+
const seen = new Set();
|
|
14
|
+
// 1. npm commands
|
|
15
|
+
const npmRegex = /npm\s+(?:run\s+)?(\w+)/gi;
|
|
16
|
+
let match;
|
|
17
|
+
while ((match = npmRegex.exec(text)) !== null) {
|
|
18
|
+
const cmd = match[0];
|
|
19
|
+
if (seen.has(cmd))
|
|
20
|
+
continue;
|
|
21
|
+
seen.add(cmd);
|
|
22
|
+
// Look for expected result near the command
|
|
23
|
+
const nearText = text.slice(Math.max(0, match.index - 100), match.index + 200);
|
|
24
|
+
let check = '';
|
|
25
|
+
if (/0\s+error|no\s+error|pass|success/i.test(nearText)) {
|
|
26
|
+
check = 'Should succeed with 0 errors';
|
|
27
|
+
}
|
|
28
|
+
else if (/fail|error|broke/i.test(nearText)) {
|
|
29
|
+
check = 'Was failing — verify it passes now';
|
|
30
|
+
}
|
|
31
|
+
steps.push({ command: cmd, check: check || `Run ${cmd} and verify output` });
|
|
32
|
+
}
|
|
33
|
+
// 2. Test file references
|
|
34
|
+
const testRegex = /(\w+\.(?:test|spec)\.\w+)/gi;
|
|
35
|
+
while ((match = testRegex.exec(text)) !== null) {
|
|
36
|
+
if (seen.has(match[1]))
|
|
37
|
+
continue;
|
|
38
|
+
seen.add(match[1]);
|
|
39
|
+
steps.push({ file: match[1], check: `Run tests in ${match[1]}` });
|
|
40
|
+
}
|
|
41
|
+
// 3. Build verification
|
|
42
|
+
if (/tsc|compile|typescript/i.test(text) && !seen.has('build')) {
|
|
43
|
+
steps.push({ command: 'npm run build', check: 'TypeScript compilation should have 0 errors' });
|
|
44
|
+
}
|
|
45
|
+
return steps.slice(0, 5);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Find verification steps for similar past bugs.
|
|
49
|
+
* When a new bug appears, search for related fixes and their verification.
|
|
50
|
+
*/
|
|
51
|
+
function findRelatedVerification(memoryStore, bugDescription) {
|
|
52
|
+
const verifications = [];
|
|
53
|
+
try {
|
|
54
|
+
const results = memoryStore.searchFTS(bugDescription, 10);
|
|
55
|
+
for (const r of results) {
|
|
56
|
+
if (r.memory.type === types_1.MemoryType.BUG_FIX && r.memory.action) {
|
|
57
|
+
// Check if action contains verification info
|
|
58
|
+
const action = r.memory.action;
|
|
59
|
+
if (/verify|test|check|build|npm|command/i.test(action)) {
|
|
60
|
+
verifications.push(`📋 For "${r.memory.intent.slice(0, 60)}": ${action.slice(0, 150)}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch { /* non-fatal */ }
|
|
66
|
+
return verifications.slice(0, 5);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Attach verification steps to a bug fix description.
|
|
70
|
+
* Returns enhanced text with verification section appended.
|
|
71
|
+
*/
|
|
72
|
+
function attachVerification(fixDescription, steps) {
|
|
73
|
+
if (steps.length === 0)
|
|
74
|
+
return fixDescription;
|
|
75
|
+
let enhanced = fixDescription;
|
|
76
|
+
enhanced += '\n\n--- Verification ---';
|
|
77
|
+
for (const step of steps) {
|
|
78
|
+
if (step.command) {
|
|
79
|
+
enhanced += `\nRun: ${step.command}`;
|
|
80
|
+
}
|
|
81
|
+
if (step.file) {
|
|
82
|
+
enhanced += `\nCheck: ${step.file}`;
|
|
83
|
+
}
|
|
84
|
+
if (step.check) {
|
|
85
|
+
enhanced += ` → ${step.check}`;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return enhanced;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=regression-guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regression-guard.js","sourceRoot":"","sources":["../../src/memory/regression-guard.ts"],"names":[],"mappings":";;AA0BA,4DAsCC;AAMD,0DAiBC;AAMD,gDAkBC;AAjGD,oCAAsC;AAQtC;;;GAGG;AACH,SAAgB,wBAAwB,CAAC,IAAY;IACjD,MAAM,KAAK,GAAuB,EAAE,CAAC;IACrC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAE/B,kBAAkB;IAClB,MAAM,QAAQ,GAAG,0BAA0B,CAAC;IAC5C,IAAI,KAAK,CAAC;IACV,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QAC5C,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACrB,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,SAAS;QAC5B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAEd,4CAA4C;QAC5C,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,EAAE,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC;QAC/E,IAAI,KAAK,GAAG,EAAE,CAAC;QACf,IAAI,oCAAoC,CAAC,IAAI,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AAM,IAAI,CAAC,KAAK,EAAE,CAAC;QACnC,CAAC;IACL,CAAC;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resume Work — Context recovery after conversation truncation.
|
|
3
|
+
*
|
|
4
|
+
* When a long conversation gets cut off, the AI loses context.
|
|
5
|
+
* This module surfaces: what was the last session about, what changed,
|
|
6
|
+
* what was in progress, and what's still remaining.
|
|
7
|
+
*
|
|
8
|
+
* Like opening your notebook and seeing "stopped at step 3 of 7".
|
|
9
|
+
*/
|
|
10
|
+
import { MemoryStore } from '../db/memory-store';
|
|
11
|
+
export interface ResumeContext {
|
|
12
|
+
lastSession: string | null;
|
|
13
|
+
recentMemories: Array<{
|
|
14
|
+
type: string;
|
|
15
|
+
intent: string;
|
|
16
|
+
age: string;
|
|
17
|
+
}>;
|
|
18
|
+
currentTasks: Array<{
|
|
19
|
+
intent: string;
|
|
20
|
+
age: string;
|
|
21
|
+
}>;
|
|
22
|
+
recentCorrections: Array<{
|
|
23
|
+
intent: string;
|
|
24
|
+
age: string;
|
|
25
|
+
}>;
|
|
26
|
+
recentDecisions: Array<{
|
|
27
|
+
intent: string;
|
|
28
|
+
age: string;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Build context for resuming work after a conversation break.
|
|
33
|
+
*/
|
|
34
|
+
export declare function buildResumeContext(memoryStore: MemoryStore): ResumeContext;
|
|
35
|
+
/** Format resume context for AI consumption */
|
|
36
|
+
export declare function formatResumeContext(ctx: ResumeContext): string;
|
|
37
|
+
//# sourceMappingURL=resume-work.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resume-work.d.ts","sourceRoot":"","sources":["../../src/memory/resume-work.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,MAAM,WAAW,aAAa;IAC1B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,cAAc,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACrE,YAAY,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACrD,iBAAiB,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC1D,eAAe,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC3D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,WAAW,GAAG,aAAa,CAmF1E;AAED,+CAA+C;AAC/C,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAgD9D"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildResumeContext = buildResumeContext;
|
|
4
|
+
exports.formatResumeContext = formatResumeContext;
|
|
5
|
+
const session_tracker_1 = require("./session-tracker");
|
|
6
|
+
/**
|
|
7
|
+
* Build context for resuming work after a conversation break.
|
|
8
|
+
*/
|
|
9
|
+
function buildResumeContext(memoryStore) {
|
|
10
|
+
const result = {
|
|
11
|
+
lastSession: null,
|
|
12
|
+
recentMemories: [],
|
|
13
|
+
currentTasks: [],
|
|
14
|
+
recentCorrections: [],
|
|
15
|
+
recentDecisions: [],
|
|
16
|
+
};
|
|
17
|
+
// 1. Get last session summary
|
|
18
|
+
try {
|
|
19
|
+
const sessions = (0, session_tracker_1.getRecentSessions)(memoryStore, 3);
|
|
20
|
+
if (sessions && sessions.length > 0) {
|
|
21
|
+
const last = sessions[0];
|
|
22
|
+
result.lastSession = typeof last === 'string' ? last :
|
|
23
|
+
typeof last === 'object' ? (last.summary || last.topic ||
|
|
24
|
+
JSON.stringify(last).slice(0, 200)) : String(last);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch { /* session tracking might not have data */ }
|
|
28
|
+
// 2. Recent memories (last 24 hours)
|
|
29
|
+
const dayAgo = Date.now() - 24 * 60 * 60 * 1000;
|
|
30
|
+
try {
|
|
31
|
+
const all = memoryStore.getActive(50);
|
|
32
|
+
const recent = all.filter(m => m.timestamp >= dayAgo);
|
|
33
|
+
result.recentMemories = recent.slice(0, 20).map(m => ({
|
|
34
|
+
type: m.type,
|
|
35
|
+
intent: m.intent,
|
|
36
|
+
age: formatAge(m.timestamp),
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
catch { /* */ }
|
|
40
|
+
// 3. Current tasks (CURRENT_TASK type memories)
|
|
41
|
+
try {
|
|
42
|
+
const tasks = memoryStore.getByType('CURRENT_TASK', 10);
|
|
43
|
+
result.currentTasks = tasks
|
|
44
|
+
.filter(t => Date.now() - t.timestamp < 7 * 24 * 60 * 60 * 1000) // Last 7 days
|
|
45
|
+
.map(t => ({
|
|
46
|
+
intent: t.intent,
|
|
47
|
+
age: formatAge(t.timestamp),
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
catch { /* type might not exist yet */ }
|
|
51
|
+
// 4. Recent corrections (most valuable for not repeating mistakes)
|
|
52
|
+
try {
|
|
53
|
+
const corrections = memoryStore.getByType('CORRECTION', 10);
|
|
54
|
+
result.recentCorrections = corrections
|
|
55
|
+
.filter(c => Date.now() - c.timestamp < 3 * 24 * 60 * 60 * 1000) // Last 3 days
|
|
56
|
+
.map(c => ({
|
|
57
|
+
intent: c.intent,
|
|
58
|
+
age: formatAge(c.timestamp),
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
catch { /* */ }
|
|
62
|
+
// 5. Recent decisions
|
|
63
|
+
try {
|
|
64
|
+
const decisions = memoryStore.getByType('DECISION', 10);
|
|
65
|
+
result.recentDecisions = decisions
|
|
66
|
+
.filter(d => Date.now() - d.timestamp < 7 * 24 * 60 * 60 * 1000) // Last 7 days
|
|
67
|
+
.map(d => ({
|
|
68
|
+
intent: d.intent,
|
|
69
|
+
age: formatAge(d.timestamp),
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
catch { /* */ }
|
|
73
|
+
// 6. Recent git commits (what changed since last session)
|
|
74
|
+
try {
|
|
75
|
+
const { execSync } = require('child_process');
|
|
76
|
+
const gitLog = execSync('git log --oneline --since="24 hours ago" -10', { encoding: 'utf-8', timeout: 5000, cwd: process.cwd(), stdio: ['pipe', 'pipe', 'pipe'] }).trim();
|
|
77
|
+
if (gitLog) {
|
|
78
|
+
const commits = gitLog.split('\n').filter((l) => l.trim());
|
|
79
|
+
if (commits.length > 0) {
|
|
80
|
+
result.recentCommits = commits.map((c) => c.trim());
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch { /* git not available or no commits */ }
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
/** Format resume context for AI consumption */
|
|
88
|
+
function formatResumeContext(ctx) {
|
|
89
|
+
const lines = ['# 🔄 Resume Work — Where We Left Off\n'];
|
|
90
|
+
if (ctx.lastSession) {
|
|
91
|
+
lines.push(`## Last Session\n${ctx.lastSession}\n`);
|
|
92
|
+
}
|
|
93
|
+
if (ctx.currentTasks.length > 0) {
|
|
94
|
+
lines.push('## 📋 Current Tasks');
|
|
95
|
+
ctx.currentTasks.forEach(t => lines.push(`- ${t.intent} _(${t.age})_`));
|
|
96
|
+
lines.push('');
|
|
97
|
+
}
|
|
98
|
+
if (ctx.recentCorrections.length > 0) {
|
|
99
|
+
lines.push('## 🔴 Recent Corrections (DON\'T repeat)');
|
|
100
|
+
ctx.recentCorrections.forEach(c => lines.push(`- ${c.intent} _(${c.age})_`));
|
|
101
|
+
lines.push('');
|
|
102
|
+
}
|
|
103
|
+
if (ctx.recentDecisions.length > 0) {
|
|
104
|
+
lines.push('## 📌 Recent Decisions');
|
|
105
|
+
ctx.recentDecisions.forEach(d => lines.push(`- ${d.intent} _(${d.age})_`));
|
|
106
|
+
lines.push('');
|
|
107
|
+
}
|
|
108
|
+
if (ctx.recentMemories.length > 0) {
|
|
109
|
+
lines.push(`## 🧠 Recent Activity (${ctx.recentMemories.length} memories in last 24h)`);
|
|
110
|
+
const byType = {};
|
|
111
|
+
ctx.recentMemories.forEach(m => { byType[m.type] = (byType[m.type] || 0) + 1; });
|
|
112
|
+
Object.entries(byType).forEach(([type, count]) => {
|
|
113
|
+
lines.push(`- ${type}: ${count}`);
|
|
114
|
+
});
|
|
115
|
+
lines.push('');
|
|
116
|
+
}
|
|
117
|
+
// Git commits (what happened since you left)
|
|
118
|
+
const commits = ctx.recentCommits;
|
|
119
|
+
if (commits && commits.length > 0) {
|
|
120
|
+
lines.push('## 📝 Recent Commits (last 24h)');
|
|
121
|
+
commits.forEach((c) => lines.push(`- \`${c}\``));
|
|
122
|
+
lines.push('');
|
|
123
|
+
}
|
|
124
|
+
if (lines.length <= 1) {
|
|
125
|
+
lines.push('No recent activity found. This may be a fresh session.');
|
|
126
|
+
}
|
|
127
|
+
return lines.join('\n');
|
|
128
|
+
}
|
|
129
|
+
// ─── Helper ──────────────────────────────────────────────────────────────────
|
|
130
|
+
function formatAge(timestamp) {
|
|
131
|
+
const diff = Date.now() - timestamp;
|
|
132
|
+
const mins = Math.floor(diff / 60000);
|
|
133
|
+
if (mins < 60)
|
|
134
|
+
return `${mins}m ago`;
|
|
135
|
+
const hours = Math.floor(mins / 60);
|
|
136
|
+
if (hours < 24)
|
|
137
|
+
return `${hours}h ago`;
|
|
138
|
+
const days = Math.floor(hours / 24);
|
|
139
|
+
return `${days}d ago`;
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=resume-work.js.map
|