@intrect/openswarm 0.17.2 → 0.17.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.
- package/README.md +21 -5
- package/config.example.yaml +18 -0
- package/dist/adapters/agenticLoop.d.ts +2 -0
- package/dist/adapters/agenticLoop.d.ts.map +1 -1
- package/dist/adapters/agenticLoop.js +6 -3
- package/dist/adapters/agenticLoop.js.map +1 -1
- package/dist/adapters/base.d.ts.map +1 -1
- package/dist/adapters/base.js +9 -0
- package/dist/adapters/base.js.map +1 -1
- package/dist/adapters/claude.d.ts.map +1 -1
- package/dist/adapters/claude.js +6 -3
- package/dist/adapters/claude.js.map +1 -1
- package/dist/adapters/codex.d.ts.map +1 -1
- package/dist/adapters/codex.js +3 -2
- package/dist/adapters/codex.js.map +1 -1
- package/dist/adapters/codexResponses.d.ts +2 -1
- package/dist/adapters/codexResponses.d.ts.map +1 -1
- package/dist/adapters/codexResponses.js +34 -30
- package/dist/adapters/codexResponses.js.map +1 -1
- package/dist/adapters/errorClassification.d.ts +11 -0
- package/dist/adapters/errorClassification.d.ts.map +1 -1
- package/dist/adapters/errorClassification.js +21 -0
- package/dist/adapters/errorClassification.js.map +1 -1
- package/dist/adapters/gpt.d.ts.map +1 -1
- package/dist/adapters/gpt.js +1 -0
- package/dist/adapters/gpt.js.map +1 -1
- package/dist/adapters/local.d.ts.map +1 -1
- package/dist/adapters/local.js +1 -0
- package/dist/adapters/local.js.map +1 -1
- package/dist/adapters/openrouter.d.ts.map +1 -1
- package/dist/adapters/openrouter.js +1 -0
- package/dist/adapters/openrouter.js.map +1 -1
- package/dist/adapters/processRegistry.d.ts.map +1 -1
- package/dist/adapters/processRegistry.js +8 -0
- package/dist/adapters/processRegistry.js.map +1 -1
- package/dist/adapters/types.d.ts +2 -0
- package/dist/adapters/types.d.ts.map +1 -1
- package/dist/agents/pairPipeline.d.ts +10 -139
- package/dist/agents/pairPipeline.d.ts.map +1 -1
- package/dist/agents/pairPipeline.js +127 -35
- package/dist/agents/pairPipeline.js.map +1 -1
- package/dist/agents/pairPipelineTypes.d.ts +109 -0
- package/dist/agents/pairPipelineTypes.d.ts.map +1 -0
- package/dist/agents/pairPipelineTypes.js +2 -0
- package/dist/agents/pairPipelineTypes.js.map +1 -0
- package/dist/agents/pipelineGuards.d.ts.map +1 -1
- package/dist/agents/pipelineGuards.js +346 -0
- package/dist/agents/pipelineGuards.js.map +1 -1
- package/dist/agents/pipelineTaskPrefix.d.ts +3 -0
- package/dist/agents/pipelineTaskPrefix.d.ts.map +1 -0
- package/dist/agents/pipelineTaskPrefix.js +16 -0
- package/dist/agents/pipelineTaskPrefix.js.map +1 -0
- package/dist/agents/reflection.d.ts +1 -1
- package/dist/agents/reflection.d.ts.map +1 -1
- package/dist/agents/reflection.js +3 -1
- package/dist/agents/reflection.js.map +1 -1
- package/dist/agents/reviewer.d.ts +6 -0
- package/dist/agents/reviewer.d.ts.map +1 -1
- package/dist/agents/reviewer.js +4 -1
- package/dist/agents/reviewer.js.map +1 -1
- package/dist/agents/stageErrorClassification.d.ts +16 -0
- package/dist/agents/stageErrorClassification.d.ts.map +1 -0
- package/dist/agents/stageErrorClassification.js +38 -0
- package/dist/agents/stageErrorClassification.js.map +1 -0
- package/dist/agents/stageModelResolver.d.ts +8 -0
- package/dist/agents/stageModelResolver.d.ts.map +1 -0
- package/dist/agents/stageModelResolver.js +22 -0
- package/dist/agents/stageModelResolver.js.map +1 -0
- package/dist/agents/worker.d.ts +33 -0
- package/dist/agents/worker.d.ts.map +1 -1
- package/dist/agents/worker.js +59 -4
- package/dist/agents/worker.js.map +1 -1
- package/dist/agents/workerFanout.d.ts +38 -0
- package/dist/agents/workerFanout.d.ts.map +1 -0
- package/dist/agents/workerFanout.js +277 -0
- package/dist/agents/workerFanout.js.map +1 -0
- package/dist/agents/workerFanoutGate.d.ts +48 -0
- package/dist/agents/workerFanoutGate.d.ts.map +1 -0
- package/dist/agents/workerFanoutGate.js +146 -0
- package/dist/agents/workerFanoutGate.js.map +1 -0
- package/dist/agents/workerValidationEvidence.d.ts +5 -0
- package/dist/agents/workerValidationEvidence.d.ts.map +1 -0
- package/dist/agents/workerValidationEvidence.js +75 -0
- package/dist/agents/workerValidationEvidence.js.map +1 -0
- package/dist/automation/autonomousRunner.d.ts +18 -6
- package/dist/automation/autonomousRunner.d.ts.map +1 -1
- package/dist/automation/autonomousRunner.js +209 -39
- package/dist/automation/autonomousRunner.js.map +1 -1
- package/dist/automation/backlogGrooming.d.ts +52 -0
- package/dist/automation/backlogGrooming.d.ts.map +1 -0
- package/dist/automation/backlogGrooming.js +231 -0
- package/dist/automation/backlogGrooming.js.map +1 -0
- package/dist/automation/runnerExecution.d.ts +1 -1
- package/dist/automation/runnerExecution.d.ts.map +1 -1
- package/dist/automation/runnerExecution.js +31 -9
- package/dist/automation/runnerExecution.js.map +1 -1
- package/dist/automation/runnerTypes.d.ts +3 -1
- package/dist/automation/runnerTypes.d.ts.map +1 -1
- package/dist/automation/taskSource.d.ts +6 -3
- package/dist/automation/taskSource.d.ts.map +1 -1
- package/dist/automation/taskSource.js +5 -0
- package/dist/automation/taskSource.js.map +1 -1
- package/dist/cli/daemon.d.ts +20 -3
- package/dist/cli/daemon.d.ts.map +1 -1
- package/dist/cli/daemon.js +42 -2
- package/dist/cli/daemon.js.map +1 -1
- package/dist/cli/fixBoard.d.ts +14 -0
- package/dist/cli/fixBoard.d.ts.map +1 -0
- package/dist/cli/fixBoard.js +32 -0
- package/dist/cli/fixBoard.js.map +1 -0
- package/dist/cli/fixCommand.d.ts +8 -0
- package/dist/cli/fixCommand.d.ts.map +1 -1
- package/dist/cli/fixCommand.js +47 -8
- package/dist/cli/fixCommand.js.map +1 -1
- package/dist/cli/memoryCommand.d.ts +37 -0
- package/dist/cli/memoryCommand.d.ts.map +1 -0
- package/dist/cli/memoryCommand.js +156 -0
- package/dist/cli/memoryCommand.js.map +1 -0
- package/dist/cli/reviewAudit.d.ts +68 -0
- package/dist/cli/reviewAudit.d.ts.map +1 -1
- package/dist/cli/reviewAudit.js +147 -4
- package/dist/cli/reviewAudit.js.map +1 -1
- package/dist/cli/reviewMaxCommand.d.ts +2 -0
- package/dist/cli/reviewMaxCommand.d.ts.map +1 -1
- package/dist/cli/reviewMaxCommand.js +61 -36
- package/dist/cli/reviewMaxCommand.js.map +1 -1
- package/dist/cli.js +68 -13
- package/dist/cli.js.map +1 -1
- package/dist/core/config.d.ts +413 -0
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +51 -5
- package/dist/core/config.js.map +1 -1
- package/dist/core/eventHub.d.ts +22 -0
- package/dist/core/eventHub.d.ts.map +1 -1
- package/dist/core/eventHub.js +1 -0
- package/dist/core/eventHub.js.map +1 -1
- package/dist/core/providerOverride.d.ts +9 -0
- package/dist/core/providerOverride.d.ts.map +1 -1
- package/dist/core/providerOverride.js +12 -0
- package/dist/core/providerOverride.js.map +1 -1
- package/dist/core/service.d.ts.map +1 -1
- package/dist/core/service.js +8 -2
- package/dist/core/service.js.map +1 -1
- package/dist/core/types.d.ts +61 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/linear/linear.d.ts +2 -1
- package/dist/linear/linear.d.ts.map +1 -1
- package/dist/linear/linear.js +16 -6
- package/dist/linear/linear.js.map +1 -1
- package/dist/locale/prompts/en.d.ts.map +1 -1
- package/dist/locale/prompts/en.js +11 -1
- package/dist/locale/prompts/en.js.map +1 -1
- package/dist/locale/prompts/ko.d.ts.map +1 -1
- package/dist/locale/prompts/ko.js +11 -1
- package/dist/locale/prompts/ko.js.map +1 -1
- package/dist/memory/compaction.d.ts +2 -2
- package/dist/memory/compaction.d.ts.map +1 -1
- package/dist/memory/compaction.js +22 -17
- package/dist/memory/compaction.js.map +1 -1
- package/dist/memory/index.d.ts +3 -3
- package/dist/memory/index.js +3 -3
- package/dist/memory/memoryCore.d.ts +15 -27
- package/dist/memory/memoryCore.d.ts.map +1 -1
- package/dist/memory/memoryCore.js +112 -97
- package/dist/memory/memoryCore.js.map +1 -1
- package/dist/memory/memoryFilters.d.ts +8 -0
- package/dist/memory/memoryFilters.d.ts.map +1 -0
- package/dist/memory/memoryFilters.js +26 -0
- package/dist/memory/memoryFilters.js.map +1 -0
- package/dist/memory/memoryOps.d.ts +7 -23
- package/dist/memory/memoryOps.d.ts.map +1 -1
- package/dist/memory/memoryOps.js +49 -109
- package/dist/memory/memoryOps.js.map +1 -1
- package/dist/memory/repoKnowledge.d.ts.map +1 -1
- package/dist/memory/repoKnowledge.js +48 -3
- package/dist/memory/repoKnowledge.js.map +1 -1
- package/dist/orchestration/conflictDetector.d.ts.map +1 -1
- package/dist/orchestration/conflictDetector.js +26 -7
- package/dist/orchestration/conflictDetector.js.map +1 -1
- package/dist/orchestration/taskScheduler.d.ts +5 -0
- package/dist/orchestration/taskScheduler.d.ts.map +1 -1
- package/dist/orchestration/taskScheduler.js +36 -12
- package/dist/orchestration/taskScheduler.js.map +1 -1
- package/dist/registry/memoryBridge.js +4 -4
- package/dist/registry/memoryBridge.js.map +1 -1
- package/dist/support/chatMemory.js +1 -1
- package/dist/support/chatMemory.js.map +1 -1
- package/dist/support/dashboardHtml.d.ts +1 -1
- package/dist/support/dashboardHtml.d.ts.map +1 -1
- package/dist/support/dashboardHtml.js +12 -0
- package/dist/support/dashboardHtml.js.map +1 -1
- package/dist/support/gitTracker.d.ts +30 -3
- package/dist/support/gitTracker.d.ts.map +1 -1
- package/dist/support/gitTracker.js +108 -29
- package/dist/support/gitTracker.js.map +1 -1
- package/dist/support/repoMetadata.d.ts +10 -0
- package/dist/support/repoMetadata.d.ts.map +1 -1
- package/dist/support/repoMetadata.js +31 -0
- package/dist/support/repoMetadata.js.map +1 -1
- package/dist/support/updateNotifier.d.ts +12 -0
- package/dist/support/updateNotifier.d.ts.map +1 -1
- package/dist/support/updateNotifier.js +71 -0
- package/dist/support/updateNotifier.js.map +1 -1
- package/dist/support/web.d.ts.map +1 -1
- package/dist/support/web.js +5 -3
- package/dist/support/web.js.map +1 -1
- package/dist/support/worktreeManager.d.ts +33 -0
- package/dist/support/worktreeManager.d.ts.map +1 -1
- package/dist/support/worktreeManager.js +172 -2
- package/dist/support/worktreeManager.js.map +1 -1
- package/dist/tui/App.js +1 -1
- package/dist/tui/App.js.map +1 -1
- package/dist/tui/components/AuditBoard.d.ts +3 -2
- package/dist/tui/components/AuditBoard.d.ts.map +1 -1
- package/dist/tui/components/AuditBoard.js +13 -4
- package/dist/tui/components/AuditBoard.js.map +1 -1
- package/dist/tui/components/DataTable.d.ts +3 -1
- package/dist/tui/components/DataTable.d.ts.map +1 -1
- package/dist/tui/components/DataTable.js +22 -5
- package/dist/tui/components/DataTable.js.map +1 -1
- package/dist/tui/components/StageTimeline.d.ts +1 -1
- package/dist/tui/components/StageTimeline.d.ts.map +1 -1
- package/dist/tui/components/StageTimeline.js +5 -2
- package/dist/tui/components/StageTimeline.js.map +1 -1
- package/dist/tui/components/SubagentTree.d.ts +6 -6
- package/dist/tui/components/SubagentTree.d.ts.map +1 -1
- package/dist/tui/components/SubagentTree.js +33 -5
- package/dist/tui/components/SubagentTree.js.map +1 -1
- package/dist/tui/eventCoalescer.d.ts +29 -0
- package/dist/tui/eventCoalescer.d.ts.map +1 -0
- package/dist/tui/eventCoalescer.js +56 -0
- package/dist/tui/eventCoalescer.js.map +1 -0
- package/dist/tui/hooks/usePipelineEvents.d.ts +1 -1
- package/dist/tui/hooks/usePipelineEvents.d.ts.map +1 -1
- package/dist/tui/hooks/usePipelineEvents.js +18 -4
- package/dist/tui/hooks/usePipelineEvents.js.map +1 -1
- package/dist/tui/monitorRows.d.ts +41 -2
- package/dist/tui/monitorRows.d.ts.map +1 -1
- package/dist/tui/monitorRows.js +86 -7
- package/dist/tui/monitorRows.js.map +1 -1
- package/dist/tui/panels/MonitorPanel.d.ts +2 -1
- package/dist/tui/panels/MonitorPanel.d.ts.map +1 -1
- package/dist/tui/panels/MonitorPanel.js +2 -2
- package/dist/tui/panels/MonitorPanel.js.map +1 -1
- package/dist/tui/panels/PipelinePanel.d.ts.map +1 -1
- package/dist/tui/panels/PipelinePanel.js +6 -1
- package/dist/tui/panels/PipelinePanel.js.map +1 -1
- package/dist/tui/pipelineEvents.d.ts +14 -0
- package/dist/tui/pipelineEvents.d.ts.map +1 -1
- package/dist/tui/pipelineEvents.js +89 -1
- package/dist/tui/pipelineEvents.js.map +1 -1
- package/dist/tui/subagentTree.d.ts +26 -3
- package/dist/tui/subagentTree.d.ts.map +1 -1
- package/dist/tui/subagentTree.js +89 -14
- package/dist/tui/subagentTree.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Persistent Cognitive Memory Module
|
|
2
|
+
* Persistent Cognitive Memory Module v3.0 - Core
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* High-level operations (revision, formatting, background) are in memoryOps.ts.
|
|
4
|
+
* Lean repo memory: embedding, storage, save, search.
|
|
6
5
|
*/
|
|
7
6
|
import { Table, Connection } from '@lancedb/lancedb';
|
|
8
7
|
export declare const EMBEDDING_DIM = 768;
|
|
9
8
|
export declare const PERMANENT_EXPIRY: number;
|
|
10
9
|
/**
|
|
11
|
-
* Normalize records before LanceDB createTable
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* Normalize records before LanceDB createTable.
|
|
11
|
+
*
|
|
12
|
+
* v3 keeps only fields that are actively used by save/search/recall. Older
|
|
13
|
+
* v2 columns such as revisionCount/decay/stability/contradicts/supports are
|
|
14
|
+
* intentionally not copied so compaction can rewrite the table to the lean
|
|
15
|
+
* schema.
|
|
14
16
|
*/
|
|
15
17
|
export declare function normalizeRecords(records: any[]): CognitiveMemoryRecord[];
|
|
16
18
|
export declare function clamp01(value: unknown, fallback: number): number;
|
|
@@ -18,7 +20,6 @@ export declare function safeParseMetadata(value: unknown): Record<string, unknow
|
|
|
18
20
|
export type CognitiveMemoryType = 'belief' | 'strategy' | 'user_model' | 'system_pattern' | 'constraint';
|
|
19
21
|
export type LegacyMemoryType = 'decision' | 'repomap' | 'journal' | 'fact';
|
|
20
22
|
export type MemoryType = CognitiveMemoryType | LegacyMemoryType;
|
|
21
|
-
export type StabilityLevel = 'low' | 'medium' | 'high';
|
|
22
23
|
export interface CognitiveMemoryRecord {
|
|
23
24
|
[key: string]: unknown;
|
|
24
25
|
id: string;
|
|
@@ -30,11 +31,6 @@ export interface CognitiveMemoryRecord {
|
|
|
30
31
|
createdAt: number;
|
|
31
32
|
lastUpdated: number;
|
|
32
33
|
lastAccessed: number;
|
|
33
|
-
revisionCount: number;
|
|
34
|
-
decay: number;
|
|
35
|
-
stability: StabilityLevel;
|
|
36
|
-
contradicts: string;
|
|
37
|
-
supports: string;
|
|
38
34
|
derivedFrom: string;
|
|
39
35
|
repo: string;
|
|
40
36
|
title: string;
|
|
@@ -58,9 +54,7 @@ export interface MemorySearchResult {
|
|
|
58
54
|
freshness: number;
|
|
59
55
|
importance: number;
|
|
60
56
|
confidence: number;
|
|
61
|
-
|
|
62
|
-
revisionCount: number;
|
|
63
|
-
decay: number;
|
|
57
|
+
derivedFrom: string;
|
|
64
58
|
similarityScore: number;
|
|
65
59
|
}
|
|
66
60
|
export interface SearchOptions {
|
|
@@ -87,7 +81,7 @@ export declare function setTable(t: Table | null): void;
|
|
|
87
81
|
*/
|
|
88
82
|
export declare function getEmbedding(text: string): Promise<number[]>;
|
|
89
83
|
/**
|
|
90
|
-
* Distillation
|
|
84
|
+
* Distillation quality test
|
|
91
85
|
* "Would future reasoning performance degrade if this memory disappeared?"
|
|
92
86
|
*/
|
|
93
87
|
interface DistillationResult {
|
|
@@ -106,7 +100,7 @@ export declare function distillContent(content: string, context?: {
|
|
|
106
100
|
source?: string;
|
|
107
101
|
}): DistillationResult;
|
|
108
102
|
/**
|
|
109
|
-
* Calculate importance score
|
|
103
|
+
* Calculate importance score.
|
|
110
104
|
*/
|
|
111
105
|
export declare function calculateImportance(type: MemoryType, options?: {
|
|
112
106
|
isRepeated?: boolean;
|
|
@@ -114,10 +108,6 @@ export declare function calculateImportance(type: MemoryType, options?: {
|
|
|
114
108
|
age?: number;
|
|
115
109
|
hasContradiction?: boolean;
|
|
116
110
|
}): number;
|
|
117
|
-
/**
|
|
118
|
-
* Determine stability based on revision history
|
|
119
|
-
*/
|
|
120
|
-
export declare function calculateStability(revisionCount: number, age: number): StabilityLevel;
|
|
121
111
|
/**
|
|
122
112
|
* Initialize database
|
|
123
113
|
*/
|
|
@@ -127,7 +117,7 @@ export declare function initDatabase(): Promise<void>;
|
|
|
127
117
|
*/
|
|
128
118
|
export declare function calculateFreshness(createdAt: number, halfLifeDays?: number): number;
|
|
129
119
|
/**
|
|
130
|
-
* Save memory
|
|
120
|
+
* Save memory with distillation.
|
|
131
121
|
*/
|
|
132
122
|
export declare function saveMemory(type: MemoryType, repo: string, title: string, content: string, options?: {
|
|
133
123
|
metadata?: Record<string, unknown>;
|
|
@@ -141,14 +131,12 @@ export declare function saveMemory(type: MemoryType, repo: string, title: string
|
|
|
141
131
|
derivedFrom?: string;
|
|
142
132
|
}): Promise<string | null>;
|
|
143
133
|
/**
|
|
144
|
-
* Save cognitive memory directly
|
|
134
|
+
* Save cognitive memory directly.
|
|
145
135
|
*/
|
|
146
136
|
export declare function saveCognitiveMemory(type: CognitiveMemoryType, content: string, options?: {
|
|
147
137
|
importance?: number;
|
|
148
138
|
confidence?: number;
|
|
149
139
|
derivedFrom?: string;
|
|
150
|
-
supports?: string[];
|
|
151
|
-
contradicts?: string[];
|
|
152
140
|
/** Repo scope for the record. Defaults to 'cognitive' (unscoped) for back-compat. */
|
|
153
141
|
repo?: string;
|
|
154
142
|
}): Promise<string | null>;
|
|
@@ -175,12 +163,12 @@ export declare function logWork(repo: string, summary: string, details: string,
|
|
|
175
163
|
*/
|
|
176
164
|
export declare function recordFact(repo: string, title: string, content: string, category: 'version' | 'build' | 'deploy' | 'constraint' | 'other'): Promise<string>;
|
|
177
165
|
/**
|
|
178
|
-
* Search memory
|
|
166
|
+
* Search memory with hybrid retrieval - safe version.
|
|
179
167
|
* Distinguishes between errors and empty results
|
|
180
168
|
*/
|
|
181
169
|
export declare function searchMemorySafe(query: string, options?: SearchOptions): Promise<SearchResult>;
|
|
182
170
|
/**
|
|
183
|
-
* Search memory
|
|
171
|
+
* Search memory - legacy compatible.
|
|
184
172
|
* @deprecated Use searchMemorySafe instead
|
|
185
173
|
*/
|
|
186
174
|
export declare function searchMemory(query: string, options?: SearchOptions): Promise<MemorySearchResult[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memoryCore.d.ts","sourceRoot":"","sources":["../../src/memory/memoryCore.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"memoryCore.d.ts","sourceRoot":"","sources":["../../src/memory/memoryCore.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAW,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAW9D,eAAO,MAAM,aAAa,MAAM,CAAC;AAajC,eAAO,MAAM,gBAAgB,QAA6C,CAAC;AAE3E;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,qBAAqB,EAAE,CAqBxE;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAOhE;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAYzE;AAaD,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,UAAU,GAAG,YAAY,GAAG,gBAAgB,GAAG,YAAY,CAAC;AAGzG,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC;AAG3E,MAAM,MAAM,UAAU,GAAG,mBAAmB,GAAG,gBAAgB,CAAC;AAIhE,MAAM,WAAW,qBAAqB;IACpC,CAAC,GAAG,EAAE,MAAM,GA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3
|
*
|
|
4
|
-
*
|
|
5
|
-
* High-level operations (revision, formatting, background) are in memoryOps.ts.
|
|
4
|
+
* Lean repo memory: embedding, storage, save, search.
|
|
6
5
|
*/
|
|
7
6
|
import { connect } from '@lancedb/lancedb';
|
|
8
7
|
import { pipeline } from '@xenova/transformers';
|
|
9
8
|
import { resolve } from 'path';
|
|
10
9
|
import { homedir } from 'os';
|
|
10
|
+
import { c, status } from '../support/colors.js';
|
|
11
11
|
// Memory storage path
|
|
12
12
|
const MEMORY_DIR = resolve(homedir(), '.openswarm/memory');
|
|
13
13
|
// Xenova embedding config (runs locally, no external dependencies)
|
|
@@ -24,9 +24,12 @@ const TTL_REPOMAP = 30 * 24 * 60 * 60 * 1000; // 30 days
|
|
|
24
24
|
// Permanent retention sentinel (year 9999) - used instead of null (LanceDB schema inference compat)
|
|
25
25
|
export const PERMANENT_EXPIRY = new Date('9999-12-31T23:59:59Z').getTime();
|
|
26
26
|
/**
|
|
27
|
-
* Normalize records before LanceDB createTable
|
|
28
|
-
*
|
|
29
|
-
*
|
|
27
|
+
* Normalize records before LanceDB createTable.
|
|
28
|
+
*
|
|
29
|
+
* v3 keeps only fields that are actively used by save/search/recall. Older
|
|
30
|
+
* v2 columns such as revisionCount/decay/stability/contradicts/supports are
|
|
31
|
+
* intentionally not copied so compaction can rewrite the table to the lean
|
|
32
|
+
* schema.
|
|
30
33
|
*/
|
|
31
34
|
export function normalizeRecords(records) {
|
|
32
35
|
const now = Date.now();
|
|
@@ -40,11 +43,6 @@ export function normalizeRecords(records) {
|
|
|
40
43
|
createdAt: Number(r.createdAt) || now,
|
|
41
44
|
lastUpdated: Number(r.lastUpdated) || now,
|
|
42
45
|
lastAccessed: Number(r.lastAccessed) || now,
|
|
43
|
-
revisionCount: Number(r.revisionCount) || 0,
|
|
44
|
-
decay: clamp01(r.decay, 0),
|
|
45
|
-
stability: r.stability || 'low',
|
|
46
|
-
contradicts: typeof r.contradicts === 'string' ? r.contradicts : JSON.stringify(r.contradicts || []),
|
|
47
|
-
supports: typeof r.supports === 'string' ? r.supports : JSON.stringify(r.supports || []),
|
|
48
46
|
derivedFrom: String(r.derivedFrom || 'unknown'),
|
|
49
47
|
repo: String(r.repo || 'unknown'),
|
|
50
48
|
title: String(r.title || ''),
|
|
@@ -57,6 +55,10 @@ export function clamp01(value, fallback) {
|
|
|
57
55
|
const n = Number(value);
|
|
58
56
|
if (!Number.isFinite(n))
|
|
59
57
|
return fallback;
|
|
58
|
+
// Legacy callers used a 1-10 scale. Preserve intent instead of saturating
|
|
59
|
+
// everything above 1 to 1.00.
|
|
60
|
+
if (n > 1 && n <= 10)
|
|
61
|
+
return n / 10;
|
|
60
62
|
return Math.max(0, Math.min(1, n));
|
|
61
63
|
}
|
|
62
64
|
export function safeParseMetadata(value) {
|
|
@@ -85,28 +87,75 @@ function normalizedL2DistanceToSimilarity(distance) {
|
|
|
85
87
|
return 0;
|
|
86
88
|
return Math.max(-1, Math.min(1, 1 - d / 2));
|
|
87
89
|
}
|
|
88
|
-
// Importance
|
|
90
|
+
// Importance score by type
|
|
89
91
|
export const BASE_IMPORTANCE = {
|
|
90
|
-
constraint: 0.
|
|
91
|
-
user_model: 0.
|
|
92
|
-
strategy: 0.
|
|
93
|
-
belief: 0.
|
|
94
|
-
system_pattern: 0.
|
|
92
|
+
constraint: 0.85,
|
|
93
|
+
user_model: 0.82,
|
|
94
|
+
strategy: 0.78,
|
|
95
|
+
belief: 0.65,
|
|
96
|
+
system_pattern: 0.72,
|
|
95
97
|
};
|
|
96
98
|
// Legacy type importance (mapped to similar cognitive types)
|
|
97
99
|
const LEGACY_IMPORTANCE = {
|
|
98
|
-
decision: 0.
|
|
99
|
-
fact: 0.
|
|
100
|
+
decision: 0.75, // similar to strategy
|
|
101
|
+
fact: 0.78, // similar to constraint
|
|
100
102
|
repomap: 0.6, // lower, structural info
|
|
101
103
|
journal: 0.4, // temporary insight
|
|
102
104
|
};
|
|
103
105
|
// Singleton connection
|
|
104
106
|
let db = null;
|
|
105
107
|
let table = null;
|
|
108
|
+
const LEGACY_SCHEMA_COLUMNS = new Set(['revisionCount', 'decay', 'stability', 'contradicts', 'supports']);
|
|
106
109
|
// Singleton accessors (for memoryOps)
|
|
107
110
|
export function getDb() { return db; }
|
|
108
111
|
export function getTable() { return table; }
|
|
109
112
|
export function setTable(t) { table = t; }
|
|
113
|
+
async function hasLegacySchemaColumns(t) {
|
|
114
|
+
const schema = await t.schema();
|
|
115
|
+
return schema.fields.some(field => LEGACY_SCHEMA_COLUMNS.has(field.name));
|
|
116
|
+
}
|
|
117
|
+
async function migrateLeanSchemaIfNeeded(database, current) {
|
|
118
|
+
if (!(await hasLegacySchemaColumns(current)))
|
|
119
|
+
return current;
|
|
120
|
+
const tableName = current.name;
|
|
121
|
+
console.log(`${status.info('[Memory]')} ${c.dim('migrating')} ${c.cyan(tableName)} ${c.dim('to v3 lean schema')}`);
|
|
122
|
+
const rows = await current.query().limit(100_000).toArray();
|
|
123
|
+
let normalized = normalizeRecords(rows);
|
|
124
|
+
if (normalized.length === 0) {
|
|
125
|
+
const now = Date.now();
|
|
126
|
+
normalized = [{
|
|
127
|
+
id: 'init',
|
|
128
|
+
type: 'system_pattern',
|
|
129
|
+
content: 'Cognitive memory system initialized with v3 lean schema',
|
|
130
|
+
vector: Array.from({ length: EMBEDDING_DIM }, () => 0),
|
|
131
|
+
importance: 0.5,
|
|
132
|
+
confidence: 1.0,
|
|
133
|
+
createdAt: now,
|
|
134
|
+
lastUpdated: now,
|
|
135
|
+
lastAccessed: now,
|
|
136
|
+
derivedFrom: 'system_init',
|
|
137
|
+
repo: 'system',
|
|
138
|
+
title: 'Memory system initialized',
|
|
139
|
+
metadata: '{}',
|
|
140
|
+
trust: 1.0,
|
|
141
|
+
expiresAt: PERMANENT_EXPIRY,
|
|
142
|
+
}];
|
|
143
|
+
}
|
|
144
|
+
const tempTableName = `${tableName}_v3_${Date.now()}`;
|
|
145
|
+
await database.createTable(tempTableName, normalized);
|
|
146
|
+
try {
|
|
147
|
+
await database.createTable(tableName, normalized, { mode: 'overwrite' });
|
|
148
|
+
return await database.openTable(tableName);
|
|
149
|
+
}
|
|
150
|
+
finally {
|
|
151
|
+
try {
|
|
152
|
+
await database.dropTable(tempTableName);
|
|
153
|
+
}
|
|
154
|
+
catch (cleanupError) {
|
|
155
|
+
console.warn(`[Memory] Failed to drop temporary migration table ${tempTableName}:`, cleanupError);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
110
159
|
/**
|
|
111
160
|
* Initialize embedding pipeline (Promise-based, prevents race conditions)
|
|
112
161
|
*/
|
|
@@ -128,14 +177,14 @@ async function initEmbeddingPipeline() {
|
|
|
128
177
|
// Start new initialization
|
|
129
178
|
pipelineInitPromise = (async () => {
|
|
130
179
|
try {
|
|
131
|
-
console.log('[Memory]
|
|
180
|
+
console.log(`${status.info('[Memory]')} ${c.dim('loading embedding model')} ${c.yellow('(first time may take a while)')}`);
|
|
132
181
|
const loadedPipeline = await pipeline('feature-extraction', EMBEDDING_MODEL, {
|
|
133
182
|
quantized: true,
|
|
134
183
|
});
|
|
135
184
|
embeddingPipeline = loadedPipeline;
|
|
136
185
|
pipelineInitFailed = false;
|
|
137
186
|
pipelineInitError = null;
|
|
138
|
-
console.log('[Memory]
|
|
187
|
+
console.log(`${status.ok('[Memory] embedding model loaded')} ${c.cyan(EMBEDDING_MODEL)}`);
|
|
139
188
|
return loadedPipeline;
|
|
140
189
|
}
|
|
141
190
|
catch (error) {
|
|
@@ -170,14 +219,14 @@ export async function getEmbedding(text) {
|
|
|
170
219
|
}
|
|
171
220
|
return vector;
|
|
172
221
|
}
|
|
173
|
-
// Rejection patterns
|
|
222
|
+
// Rejection patterns: never store
|
|
174
223
|
const REJECTION_PATTERNS = [
|
|
175
224
|
/^(안녕|ㅎㅇ|ㅋㅋ|ㅎㅎ|오케이|넵|확인|감사)/, // Chit-chat
|
|
176
225
|
/^(좋아|싫어|화나|슬퍼)/, // Ephemeral emotions
|
|
177
226
|
/(어떻게 생각|뭐가 나을까|선택해|골라)/, // Context-dependent questions
|
|
178
227
|
/^(test|테스트|asdf|qwer)/i, // Test data
|
|
179
228
|
];
|
|
180
|
-
// Extraction target patterns
|
|
229
|
+
// Extraction target patterns
|
|
181
230
|
const EXTRACTION_PATTERNS = [
|
|
182
231
|
// Constraints (highest priority)
|
|
183
232
|
{ pattern: /(절대|반드시|금지|필수|MUST|NEVER|ALWAYS)/i, type: 'constraint', baseImportance: 0.9 },
|
|
@@ -265,20 +314,19 @@ export function distillContent(content, context) {
|
|
|
265
314
|
};
|
|
266
315
|
}
|
|
267
316
|
/**
|
|
268
|
-
* Calculate importance score
|
|
317
|
+
* Calculate importance score.
|
|
269
318
|
*/
|
|
270
319
|
export function calculateImportance(type, options) {
|
|
271
320
|
// Base importance by type
|
|
272
321
|
let importance = (BASE_IMPORTANCE[type] ??
|
|
273
322
|
LEGACY_IMPORTANCE[type] ?? 0.5);
|
|
274
|
-
// Increase: repeated appearance
|
|
323
|
+
// Increase: repeated appearance. Keep this small so repeated broad audit
|
|
324
|
+
// summaries do not flatten the score distribution.
|
|
275
325
|
if (options?.isRepeated) {
|
|
276
|
-
importance = Math.min(
|
|
277
|
-
}
|
|
278
|
-
// Increase: verified in practice
|
|
279
|
-
if (options?.isVerified) {
|
|
280
|
-
importance = Math.min(1, importance + 0.1);
|
|
326
|
+
importance = Math.min(0.95, importance + 0.05);
|
|
281
327
|
}
|
|
328
|
+
// Verification should raise confidence at the call site, not force every
|
|
329
|
+
// verified item to maximum importance.
|
|
282
330
|
// Decrease: aged (subtract 0.1 if older than 30 days)
|
|
283
331
|
if (options?.age && options.age > 30 * 24 * 60 * 60 * 1000) {
|
|
284
332
|
importance = Math.max(0.3, importance - 0.1);
|
|
@@ -289,19 +337,6 @@ export function calculateImportance(type, options) {
|
|
|
289
337
|
}
|
|
290
338
|
return importance;
|
|
291
339
|
}
|
|
292
|
-
/**
|
|
293
|
-
* Determine stability based on revision history
|
|
294
|
-
*/
|
|
295
|
-
export function calculateStability(revisionCount, age) {
|
|
296
|
-
const ageInDays = age / (24 * 60 * 60 * 1000);
|
|
297
|
-
// Old with no revisions = high
|
|
298
|
-
if (ageInDays > 7 && revisionCount === 0)
|
|
299
|
-
return 'high';
|
|
300
|
-
// Recently created or frequently revised = low
|
|
301
|
-
if (ageInDays < 1 || revisionCount > 3)
|
|
302
|
-
return 'low';
|
|
303
|
-
return 'medium';
|
|
304
|
-
}
|
|
305
340
|
/**
|
|
306
341
|
* Initialize database
|
|
307
342
|
*/
|
|
@@ -313,38 +348,32 @@ export async function initDatabase() {
|
|
|
313
348
|
await fs.mkdir(MEMORY_DIR, { recursive: true });
|
|
314
349
|
db = await connect(MEMORY_DIR);
|
|
315
350
|
const tableNames = await db.tableNames();
|
|
316
|
-
//
|
|
351
|
+
// v3.0: lean cognitive memory table. Existing v2 tables are read
|
|
352
|
+
// compatibly and rewritten by compaction.
|
|
317
353
|
if (tableNames.includes('cognitive_memory')) {
|
|
318
354
|
table = await db.openTable('cognitive_memory');
|
|
319
|
-
|
|
355
|
+
table = await migrateLeanSchemaIfNeeded(db, table);
|
|
356
|
+
console.log(`${status.info('[Memory]')} ${c.dim('loaded table')} ${c.cyan('cognitive_memory v3.0')}`);
|
|
320
357
|
}
|
|
321
358
|
else if (tableNames.includes('devmemory')) {
|
|
322
359
|
// Legacy table - will migrate later
|
|
323
360
|
table = await db.openTable('devmemory');
|
|
324
|
-
console.log('[Memory]
|
|
361
|
+
console.log(`${status.warn('[Memory] loaded legacy table')} ${c.cyan('devmemory')}`);
|
|
325
362
|
}
|
|
326
363
|
else {
|
|
327
|
-
// Create new table (
|
|
364
|
+
// Create new table (v3.0 schema)
|
|
328
365
|
const now = Date.now();
|
|
329
366
|
const initialRecord = {
|
|
330
367
|
id: 'init',
|
|
331
368
|
type: 'system_pattern',
|
|
332
|
-
content: 'Cognitive memory system initialized with
|
|
369
|
+
content: 'Cognitive memory system initialized with v3 lean schema',
|
|
333
370
|
vector: await getEmbedding('Cognitive memory system initialized'),
|
|
334
|
-
// PRD Mandatory Fields
|
|
335
371
|
importance: 0.5,
|
|
336
372
|
confidence: 1.0,
|
|
337
373
|
createdAt: now,
|
|
338
374
|
lastUpdated: now,
|
|
339
375
|
lastAccessed: now,
|
|
340
|
-
revisionCount: 0,
|
|
341
|
-
decay: 0,
|
|
342
|
-
// PRD Extensions
|
|
343
|
-
stability: 'high',
|
|
344
|
-
contradicts: '[]',
|
|
345
|
-
supports: '[]',
|
|
346
376
|
derivedFrom: 'system_init',
|
|
347
|
-
// Legacy compatibility
|
|
348
377
|
repo: 'system',
|
|
349
378
|
title: 'Memory system initialized',
|
|
350
379
|
metadata: '{}',
|
|
@@ -352,7 +381,7 @@ export async function initDatabase() {
|
|
|
352
381
|
expiresAt: PERMANENT_EXPIRY,
|
|
353
382
|
};
|
|
354
383
|
table = await db.createTable('cognitive_memory', [initialRecord]);
|
|
355
|
-
console.log('[Memory]
|
|
384
|
+
console.log(`${status.ok('[Memory] created table')} ${c.cyan('cognitive_memory v3.0')}`);
|
|
356
385
|
}
|
|
357
386
|
}
|
|
358
387
|
catch (error) {
|
|
@@ -369,20 +398,20 @@ export function calculateFreshness(createdAt, halfLifeDays = 7) {
|
|
|
369
398
|
return Math.exp(-ageMs / halfLifeMs);
|
|
370
399
|
}
|
|
371
400
|
/**
|
|
372
|
-
* Save memory
|
|
401
|
+
* Save memory with distillation.
|
|
373
402
|
*/
|
|
374
403
|
export async function saveMemory(type, repo, title, content, options) {
|
|
375
404
|
await initDatabase();
|
|
376
405
|
if (!table)
|
|
377
406
|
throw new Error('Table not initialized');
|
|
378
|
-
//
|
|
407
|
+
// Semantic distillation (unless bypassed)
|
|
379
408
|
if (!options?.skipDistillation) {
|
|
380
409
|
const distillation = distillContent(content, {
|
|
381
410
|
isRepeated: options?.isRepeated,
|
|
382
411
|
isVerified: options?.isVerified,
|
|
383
412
|
});
|
|
384
413
|
if (!distillation.shouldStore) {
|
|
385
|
-
console.log(
|
|
414
|
+
console.log(`${status.warn('[Memory] rejected by distillation')} ${distillation.reason}`);
|
|
386
415
|
return null;
|
|
387
416
|
}
|
|
388
417
|
// Distillation may refine the type for UNVERIFIED content — a best-effort
|
|
@@ -393,7 +422,7 @@ export async function saveMemory(type, repo, title, content, options) {
|
|
|
393
422
|
// caller that didn't know the flag (see repoKnowledge.ts). Contract: explicit
|
|
394
423
|
// type + isVerified wins; unverified content is still auto-refined.
|
|
395
424
|
if (!options?.isVerified && distillation.type !== type && isCognitiveType(distillation.type)) {
|
|
396
|
-
console.log(
|
|
425
|
+
console.log(`${status.info('[Memory] type adjusted by distillation')} ${c.yellow(type)} → ${c.yellow(distillation.type)}`);
|
|
397
426
|
type = distillation.type;
|
|
398
427
|
}
|
|
399
428
|
}
|
|
@@ -419,18 +448,11 @@ export async function saveMemory(type, repo, title, content, options) {
|
|
|
419
448
|
type,
|
|
420
449
|
content,
|
|
421
450
|
vector: await getEmbedding(`${title}\n${content}`),
|
|
422
|
-
// PRD Mandatory Fields
|
|
423
451
|
importance,
|
|
424
452
|
confidence,
|
|
425
453
|
createdAt: now,
|
|
426
454
|
lastUpdated: now,
|
|
427
455
|
lastAccessed: now,
|
|
428
|
-
revisionCount: 0,
|
|
429
|
-
decay: 0,
|
|
430
|
-
// PRD Extensions
|
|
431
|
-
stability: 'low', // Newly created starts as low
|
|
432
|
-
contradicts: '[]',
|
|
433
|
-
supports: '[]',
|
|
434
456
|
derivedFrom: options?.derivedFrom || 'unknown',
|
|
435
457
|
// Legacy compatibility
|
|
436
458
|
repo,
|
|
@@ -440,7 +462,7 @@ export async function saveMemory(type, repo, title, content, options) {
|
|
|
440
462
|
expiresAt,
|
|
441
463
|
};
|
|
442
464
|
await table.add([record]);
|
|
443
|
-
console.log(`[Memory]
|
|
465
|
+
console.log(`${status.ok(`[Memory] saved ${type}`)} ${c.yellow(`importance: ${importance.toFixed(2)}`)} ${c.dim('repo:')} ${c.cyan(repo)} ${c.dim('title:')} ${title}`);
|
|
444
466
|
return id;
|
|
445
467
|
}
|
|
446
468
|
/**
|
|
@@ -450,7 +472,7 @@ function isCognitiveType(type) {
|
|
|
450
472
|
return ['belief', 'strategy', 'user_model', 'system_pattern', 'constraint'].includes(type);
|
|
451
473
|
}
|
|
452
474
|
/**
|
|
453
|
-
* Save cognitive memory directly
|
|
475
|
+
* Save cognitive memory directly.
|
|
454
476
|
*/
|
|
455
477
|
export async function saveCognitiveMemory(type, content, options) {
|
|
456
478
|
await initDatabase();
|
|
@@ -470,11 +492,6 @@ export async function saveCognitiveMemory(type, content, options) {
|
|
|
470
492
|
createdAt: now,
|
|
471
493
|
lastUpdated: now,
|
|
472
494
|
lastAccessed: now,
|
|
473
|
-
revisionCount: 0,
|
|
474
|
-
decay: 0,
|
|
475
|
-
stability: 'low',
|
|
476
|
-
contradicts: JSON.stringify(options?.contradicts || []),
|
|
477
|
-
supports: JSON.stringify(options?.supports || []),
|
|
478
495
|
derivedFrom: options?.derivedFrom || 'unknown',
|
|
479
496
|
// Legacy fields (minimal)
|
|
480
497
|
repo: options?.repo ?? 'cognitive',
|
|
@@ -484,7 +501,7 @@ export async function saveCognitiveMemory(type, content, options) {
|
|
|
484
501
|
expiresAt: PERMANENT_EXPIRY,
|
|
485
502
|
};
|
|
486
503
|
await table.add([record]);
|
|
487
|
-
console.log(`[Memory]
|
|
504
|
+
console.log(`${status.ok(`[Memory] saved cognitive ${type}`)} ${c.yellow(`importance: ${importance.toFixed(2)}`)} ${content.slice(0, 50)}...`);
|
|
488
505
|
return id;
|
|
489
506
|
}
|
|
490
507
|
/**
|
|
@@ -556,20 +573,19 @@ export async function recordFact(repo, title, content, category) {
|
|
|
556
573
|
});
|
|
557
574
|
return id;
|
|
558
575
|
}
|
|
559
|
-
// Hybrid
|
|
576
|
+
// Hybrid retrieval
|
|
560
577
|
/**
|
|
561
|
-
*
|
|
562
|
-
*
|
|
578
|
+
* Hybrid score: semantic relevance first, then curated importance and recency.
|
|
579
|
+
* Removed access frequency/decay inputs because the table never maintained
|
|
580
|
+
* meaningful values for them.
|
|
563
581
|
*/
|
|
564
|
-
function calculateHybridScore(similarity, importance, recency
|
|
565
|
-
return (0.
|
|
566
|
-
0.
|
|
567
|
-
0.15 * recency
|
|
568
|
-
0.10 * Math.min(1, accessFrequency / 10) // normalize frequency
|
|
569
|
-
);
|
|
582
|
+
function calculateHybridScore(similarity, importance, recency) {
|
|
583
|
+
return (0.60 * similarity +
|
|
584
|
+
0.25 * importance +
|
|
585
|
+
0.15 * recency);
|
|
570
586
|
}
|
|
571
587
|
/**
|
|
572
|
-
* Search memory
|
|
588
|
+
* Search memory with hybrid retrieval - safe version.
|
|
573
589
|
* Distinguishes between errors and empty results
|
|
574
590
|
*/
|
|
575
591
|
export async function searchMemorySafe(query, options = {}) {
|
|
@@ -605,7 +621,10 @@ export async function searchMemorySafe(query, options = {}) {
|
|
|
605
621
|
predicates.push(`repo IN (${[repo, 'system', 'cognitive'].map(sqlString).join(', ')})`);
|
|
606
622
|
}
|
|
607
623
|
if (!includeExpired) {
|
|
608
|
-
|
|
624
|
+
// Lance/DataFusion normalizes unquoted identifiers to lowercase. This
|
|
625
|
+
// column is camelCase in the Arrow schema, so quote it or vector search
|
|
626
|
+
// fails with "No field named expiresat".
|
|
627
|
+
predicates.push(`("expiresAt" IS NULL OR "expiresAt" >= ${now} OR "expiresAt" >= ${PERMANENT_EXPIRY})`);
|
|
609
628
|
}
|
|
610
629
|
if (minTrust > 0) {
|
|
611
630
|
predicates.push(`(confidence >= ${minTrust} OR (confidence IS NULL AND trust >= ${minTrust}))`);
|
|
@@ -619,7 +638,7 @@ export async function searchMemorySafe(query, options = {}) {
|
|
|
619
638
|
vectorQuery = vectorQuery.where(predicates.join(' AND '));
|
|
620
639
|
}
|
|
621
640
|
const results = await vectorQuery.limit(resultWindow).toArray();
|
|
622
|
-
// Hybrid
|
|
641
|
+
// Hybrid retrieval scoring
|
|
623
642
|
const scored = results
|
|
624
643
|
.filter((r) => {
|
|
625
644
|
if (r.id === 'init')
|
|
@@ -642,10 +661,8 @@ export async function searchMemorySafe(query, options = {}) {
|
|
|
642
661
|
const similarity = normalizedL2DistanceToSimilarity(r._distance);
|
|
643
662
|
const recency = calculateFreshness(r.createdAt);
|
|
644
663
|
const importance = r.importance ?? calculateImportance(r.type);
|
|
645
|
-
const
|
|
646
|
-
|
|
647
|
-
const hybridScore = calculateHybridScore(similarity, effectiveImportance, recency, accessCount);
|
|
648
|
-
return { record: r, similarity, recency, importance: effectiveImportance, hybridScore };
|
|
664
|
+
const hybridScore = calculateHybridScore(similarity, importance, recency);
|
|
665
|
+
return { record: r, similarity, recency, importance, hybridScore };
|
|
649
666
|
})
|
|
650
667
|
.filter(item => item.recency >= minFreshness)
|
|
651
668
|
.sort((a, b) => b.hybridScore - a.hybridScore)
|
|
@@ -664,12 +681,10 @@ export async function searchMemorySafe(query, options = {}) {
|
|
|
664
681
|
freshness: recency,
|
|
665
682
|
importance,
|
|
666
683
|
confidence: r.confidence ?? r.trust ?? 0.7,
|
|
667
|
-
|
|
668
|
-
revisionCount: r.revisionCount ?? 0,
|
|
669
|
-
decay: r.decay ?? 0,
|
|
684
|
+
derivedFrom: r.derivedFrom ?? 'unknown',
|
|
670
685
|
similarityScore: similarity,
|
|
671
686
|
}));
|
|
672
|
-
console.log(`[Memory]
|
|
687
|
+
console.log(`${status.info(`[Memory] found ${formatted.length} memories`)} ${c.dim('hybrid retrieval')} ${c.dim(`query: "${query.slice(0, 30)}..."`)}`);
|
|
673
688
|
return { success: true, memories: formatted };
|
|
674
689
|
}
|
|
675
690
|
catch (error) {
|
|
@@ -684,7 +699,7 @@ export async function searchMemorySafe(query, options = {}) {
|
|
|
684
699
|
}
|
|
685
700
|
}
|
|
686
701
|
/**
|
|
687
|
-
* Search memory
|
|
702
|
+
* Search memory - legacy compatible.
|
|
688
703
|
* @deprecated Use searchMemorySafe instead
|
|
689
704
|
*/
|
|
690
705
|
export async function searchMemory(query, options = {}) {
|