@monoes/memory 1.0.4 → 1.0.6
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 +72 -840
- package/dist/atomic-file.d.ts +17 -0
- package/dist/atomic-file.d.ts.map +1 -0
- package/dist/atomic-file.js +27 -0
- package/dist/atomic-file.js.map +1 -0
- package/dist/cache-manager.d.ts +0 -0
- package/dist/cache-manager.d.ts.map +1 -1
- package/dist/cache-manager.js +0 -0
- package/dist/cache-manager.js.map +1 -1
- package/dist/checkpointer.d.ts +13 -0
- package/dist/checkpointer.d.ts.map +1 -1
- package/dist/checkpointer.js +69 -6
- package/dist/checkpointer.js.map +1 -1
- package/dist/controller-registry.d.ts +2 -8
- package/dist/controller-registry.d.ts.map +1 -1
- package/dist/controller-registry.js +4 -49
- package/dist/controller-registry.js.map +1 -1
- package/dist/database-provider.d.ts +0 -0
- package/dist/database-provider.d.ts.map +0 -0
- package/dist/database-provider.js +0 -0
- package/dist/database-provider.js.map +1 -1
- package/dist/hnsw-index.d.ts +0 -0
- package/dist/hnsw-index.d.ts.map +1 -1
- package/dist/hnsw-index.js +0 -0
- package/dist/hnsw-index.js.map +1 -1
- package/dist/index.d.ts +0 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -19
- package/dist/index.js.map +1 -1
- package/dist/knowledge/document-chunker.d.ts +0 -0
- package/dist/knowledge/document-chunker.d.ts.map +0 -0
- package/dist/knowledge/document-chunker.js +0 -0
- package/dist/knowledge/document-chunker.js.map +1 -1
- package/dist/knowledge/index.d.ts +0 -0
- package/dist/knowledge/index.d.ts.map +0 -0
- package/dist/knowledge/index.js +0 -0
- package/dist/knowledge/index.js.map +0 -0
- package/dist/knowledge/knowledge-retriever.d.ts +0 -0
- package/dist/knowledge/knowledge-retriever.d.ts.map +1 -1
- package/dist/knowledge/knowledge-retriever.js +0 -0
- package/dist/knowledge/knowledge-retriever.js.map +1 -1
- package/dist/knowledge/knowledge-store.d.ts +0 -0
- package/dist/knowledge/knowledge-store.d.ts.map +1 -1
- package/dist/knowledge/knowledge-store.js +0 -0
- package/dist/knowledge/knowledge-store.js.map +0 -0
- package/dist/lancedb-backend.d.ts +5 -0
- package/dist/lancedb-backend.d.ts.map +1 -1
- package/dist/lancedb-backend.js +70 -12
- package/dist/lancedb-backend.js.map +1 -1
- package/dist/math-utils.d.ts +0 -0
- package/dist/math-utils.d.ts.map +0 -0
- package/dist/math-utils.js +0 -0
- package/dist/math-utils.js.map +0 -0
- package/dist/migration.d.ts +1 -0
- package/dist/migration.d.ts.map +1 -1
- package/dist/migration.js +50 -21
- package/dist/migration.js.map +1 -1
- package/dist/prompt-version-store.d.ts +0 -0
- package/dist/prompt-version-store.d.ts.map +1 -1
- package/dist/prompt-version-store.js +0 -0
- package/dist/prompt-version-store.js.map +0 -0
- package/dist/query-builder.d.ts +0 -0
- package/dist/query-builder.d.ts.map +1 -1
- package/dist/query-builder.js +0 -0
- package/dist/query-builder.js.map +1 -1
- package/dist/sqlite-backend.d.ts +0 -0
- package/dist/sqlite-backend.d.ts.map +1 -1
- package/dist/sqlite-backend.js +38 -9
- package/dist/sqlite-backend.js.map +1 -1
- package/dist/sqljs-backend.d.ts +1 -0
- package/dist/sqljs-backend.d.ts.map +1 -1
- package/dist/sqljs-backend.js +64 -13
- package/dist/sqljs-backend.js.map +1 -1
- package/dist/types/checkpoint.d.ts +0 -0
- package/dist/types/checkpoint.d.ts.map +0 -0
- package/dist/types/checkpoint.js +0 -0
- package/dist/types/checkpoint.js.map +0 -0
- package/dist/types.d.ts +1 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -0
- package/dist/types.js.map +1 -1
- package/package.json +12 -13
- package/dist/agent-memory-scope.d.ts +0 -131
- package/dist/agent-memory-scope.d.ts.map +0 -1
- package/dist/agent-memory-scope.js +0 -230
- package/dist/agent-memory-scope.js.map +0 -1
- package/dist/auto-memory-bridge.d.ts +0 -230
- package/dist/auto-memory-bridge.d.ts.map +0 -1
- package/dist/auto-memory-bridge.js +0 -736
- package/dist/auto-memory-bridge.js.map +0 -1
- package/dist/diskann-backend.d.ts +0 -126
- package/dist/diskann-backend.d.ts.map +0 -1
- package/dist/diskann-backend.js +0 -336
- package/dist/diskann-backend.js.map +0 -1
- package/dist/episodic-store.d.ts +0 -58
- package/dist/episodic-store.d.ts.map +0 -1
- package/dist/episodic-store.js +0 -160
- package/dist/episodic-store.js.map +0 -1
- package/dist/learning-bridge.d.ts +0 -180
- package/dist/learning-bridge.d.ts.map +0 -1
- package/dist/learning-bridge.js +0 -566
- package/dist/learning-bridge.js.map +0 -1
- package/dist/memory-graph.d.ts +0 -125
- package/dist/memory-graph.d.ts.map +0 -1
- package/dist/memory-graph.js +0 -429
- package/dist/memory-graph.js.map +0 -1
- package/dist/partitioned-hnsw.d.ts +0 -65
- package/dist/partitioned-hnsw.d.ts.map +0 -1
- package/dist/partitioned-hnsw.js +0 -209
- package/dist/partitioned-hnsw.js.map +0 -1
- package/dist/procedural/action-record.d.ts +0 -19
- package/dist/procedural/action-record.d.ts.map +0 -1
- package/dist/procedural/action-record.js +0 -51
- package/dist/procedural/action-record.js.map +0 -1
- package/dist/procedural/action-sequence-extractor.d.ts +0 -25
- package/dist/procedural/action-sequence-extractor.d.ts.map +0 -1
- package/dist/procedural/action-sequence-extractor.js +0 -91
- package/dist/procedural/action-sequence-extractor.js.map +0 -1
- package/dist/procedural/index.d.ts +0 -14
- package/dist/procedural/index.d.ts.map +0 -1
- package/dist/procedural/index.js +0 -13
- package/dist/procedural/index.js.map +0 -1
- package/dist/procedural/learned-skill.d.ts +0 -17
- package/dist/procedural/learned-skill.d.ts.map +0 -1
- package/dist/procedural/learned-skill.js +0 -73
- package/dist/procedural/learned-skill.js.map +0 -1
- package/dist/procedural/skill-registry.d.ts +0 -25
- package/dist/procedural/skill-registry.d.ts.map +0 -1
- package/dist/procedural/skill-registry.js +0 -56
- package/dist/procedural/skill-registry.js.map +0 -1
- package/dist/procedural/types.d.ts +0 -67
- package/dist/procedural/types.d.ts.map +0 -1
- package/dist/procedural/types.js +0 -15
- package/dist/procedural/types.js.map +0 -1
- package/dist/tier-manager.d.ts +0 -79
- package/dist/tier-manager.d.ts.map +0 -1
- package/dist/tier-manager.js +0 -173
- package/dist/tier-manager.js.map +0 -1
- package/dist/tiers/contextual.d.ts +0 -45
- package/dist/tiers/contextual.d.ts.map +0 -1
- package/dist/tiers/contextual.js +0 -109
- package/dist/tiers/contextual.js.map +0 -1
- package/dist/tiers/entity.d.ts +0 -46
- package/dist/tiers/entity.d.ts.map +0 -1
- package/dist/tiers/entity.js +0 -106
- package/dist/tiers/entity.js.map +0 -1
- package/dist/tiers/index.d.ts +0 -4
- package/dist/tiers/index.d.ts.map +0 -1
- package/dist/tiers/index.js +0 -4
- package/dist/tiers/index.js.map +0 -1
- package/dist/tiers/short-term.d.ts +0 -42
- package/dist/tiers/short-term.d.ts.map +0 -1
- package/dist/tiers/short-term.js +0 -90
- package/dist/tiers/short-term.js.map +0 -1
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent-Scoped Memory - Support for Claude Code's 3-scope agent memory directories
|
|
3
|
-
*
|
|
4
|
-
* Claude Code organizes agent memory into three scopes:
|
|
5
|
-
* - **project**: Shared across all collaborators (checked into git)
|
|
6
|
-
* - **local**: Machine-specific, not shared (gitignored)
|
|
7
|
-
* - **user**: Global per-user, spans all projects
|
|
8
|
-
*
|
|
9
|
-
* Each scope stores agent-specific memory in a named subdirectory,
|
|
10
|
-
* enabling isolated yet transferable knowledge between agents.
|
|
11
|
-
*
|
|
12
|
-
* @module @monomind/memory/agent-memory-scope
|
|
13
|
-
*/
|
|
14
|
-
import type { IMemoryBackend } from './types.js';
|
|
15
|
-
import { AutoMemoryBridge } from './auto-memory-bridge.js';
|
|
16
|
-
import type { AutoMemoryBridgeConfig, InsightCategory } from './auto-memory-bridge.js';
|
|
17
|
-
/** Claude Code's 3-scope agent memory system */
|
|
18
|
-
export type AgentMemoryScope = 'project' | 'local' | 'user';
|
|
19
|
-
/** Configuration for agent-scoped memory bridge */
|
|
20
|
-
export interface AgentScopedConfig extends AutoMemoryBridgeConfig {
|
|
21
|
-
/** Agent name (used in directory path) */
|
|
22
|
-
agentName: string;
|
|
23
|
-
/** Memory scope */
|
|
24
|
-
scope: AgentMemoryScope;
|
|
25
|
-
}
|
|
26
|
-
/** Options for knowledge transfer between agents */
|
|
27
|
-
export interface TransferOptions {
|
|
28
|
-
/** Source namespace to transfer from */
|
|
29
|
-
sourceNamespace: string;
|
|
30
|
-
/** Minimum confidence to include (default: 0.8) */
|
|
31
|
-
minConfidence?: number;
|
|
32
|
-
/** Maximum entries to transfer (default: 20) */
|
|
33
|
-
maxEntries?: number;
|
|
34
|
-
/** Filter by categories */
|
|
35
|
-
categories?: InsightCategory[];
|
|
36
|
-
}
|
|
37
|
-
/** Result of a knowledge transfer */
|
|
38
|
-
export interface TransferResult {
|
|
39
|
-
/** Number of entries transferred */
|
|
40
|
-
transferred: number;
|
|
41
|
-
/** Number of entries skipped (below threshold or duplicate) */
|
|
42
|
-
skipped: number;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Resolve the agent memory directory for a given agent name, scope, and working directory.
|
|
46
|
-
*
|
|
47
|
-
* Path resolution matches Claude Code binary behavior:
|
|
48
|
-
* ```
|
|
49
|
-
* project: <gitRoot>/.claude/agent-memory/<agentName>/
|
|
50
|
-
* local: <gitRoot>/.claude/agent-memory-local/<agentName>/
|
|
51
|
-
* user: ~/.claude/agent-memory/<agentName>/
|
|
52
|
-
* ```
|
|
53
|
-
*
|
|
54
|
-
* Agent names are sanitized to prevent path traversal attacks.
|
|
55
|
-
*
|
|
56
|
-
* @param agentName - The agent identifier
|
|
57
|
-
* @param scope - Memory scope: project, local, or user
|
|
58
|
-
* @param workingDir - Working directory for git root detection (defaults to cwd)
|
|
59
|
-
* @returns Absolute path to the agent's memory directory
|
|
60
|
-
*/
|
|
61
|
-
export declare function resolveAgentMemoryDir(agentName: string, scope: AgentMemoryScope, workingDir?: string): string;
|
|
62
|
-
/**
|
|
63
|
-
* Create an AutoMemoryBridge configured for a specific agent scope.
|
|
64
|
-
*
|
|
65
|
-
* This is the primary factory for creating scoped bridges. It resolves
|
|
66
|
-
* the correct memory directory based on agent name and scope, then
|
|
67
|
-
* delegates to AutoMemoryBridge for the actual sync logic.
|
|
68
|
-
*
|
|
69
|
-
* @param backend - the LanceDB memory backend
|
|
70
|
-
* @param config - Agent-scoped configuration
|
|
71
|
-
* @returns A configured AutoMemoryBridge instance
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* ```typescript
|
|
75
|
-
* const bridge = createAgentBridge(backend, {
|
|
76
|
-
* agentName: 'coder',
|
|
77
|
-
* scope: 'project',
|
|
78
|
-
* syncMode: 'on-write',
|
|
79
|
-
* });
|
|
80
|
-
* await bridge.recordInsight({ ... });
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
export declare function createAgentBridge(backend: IMemoryBackend, config: AgentScopedConfig): AutoMemoryBridge;
|
|
84
|
-
/**
|
|
85
|
-
* Transfer knowledge from a source backend namespace into a target bridge.
|
|
86
|
-
*
|
|
87
|
-
* Queries high-confidence entries from the source and records them as
|
|
88
|
-
* insights in the target bridge. Useful for cross-agent knowledge sharing
|
|
89
|
-
* or promoting learnings from one scope to another.
|
|
90
|
-
*
|
|
91
|
-
* @param sourceBackend - Backend to query entries from
|
|
92
|
-
* @param targetBridge - Bridge to record insights into
|
|
93
|
-
* @param options - Transfer options (namespace, filters, limits)
|
|
94
|
-
* @returns Transfer result with counts of transferred and skipped entries
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* ```typescript
|
|
98
|
-
* const result = await transferKnowledge(sourceBackend, targetBridge, {
|
|
99
|
-
* sourceNamespace: 'learnings',
|
|
100
|
-
* minConfidence: 0.9,
|
|
101
|
-
* maxEntries: 10,
|
|
102
|
-
* categories: ['architecture', 'security'],
|
|
103
|
-
* });
|
|
104
|
-
* console.log(`Transferred ${result.transferred}, skipped ${result.skipped}`);
|
|
105
|
-
* ```
|
|
106
|
-
*/
|
|
107
|
-
export declare function transferKnowledge(sourceBackend: IMemoryBackend, targetBridge: AutoMemoryBridge, options: TransferOptions): Promise<TransferResult>;
|
|
108
|
-
/**
|
|
109
|
-
* List all agent scopes and their agents for the current project.
|
|
110
|
-
*
|
|
111
|
-
* Scans the three scope directories (project, local, user) and returns
|
|
112
|
-
* the agent names found in each. Useful for discovery and diagnostics.
|
|
113
|
-
*
|
|
114
|
-
* @param workingDir - Working directory for git root detection (defaults to cwd)
|
|
115
|
-
* @returns Array of scope/agents pairs
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* ```typescript
|
|
119
|
-
* const scopes = listAgentScopes('/workspaces/my-project');
|
|
120
|
-
* // [
|
|
121
|
-
* // { scope: 'project', agents: ['coder', 'tester'] },
|
|
122
|
-
* // { scope: 'local', agents: ['researcher'] },
|
|
123
|
-
* // { scope: 'user', agents: ['planner'] },
|
|
124
|
-
* // ]
|
|
125
|
-
* ```
|
|
126
|
-
*/
|
|
127
|
-
export declare function listAgentScopes(workingDir?: string): Array<{
|
|
128
|
-
scope: AgentMemoryScope;
|
|
129
|
-
agents: string[];
|
|
130
|
-
}>;
|
|
131
|
-
//# sourceMappingURL=agent-memory-scope.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agent-memory-scope.d.ts","sourceRoot":"","sources":["../src/agent-memory-scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EACV,sBAAsB,EAEtB,eAAe,EAChB,MAAM,yBAAyB,CAAC;AAIjC,gDAAgD;AAChD,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,O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0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent-Scoped Memory - Support for Claude Code's 3-scope agent memory directories
|
|
3
|
-
*
|
|
4
|
-
* Claude Code organizes agent memory into three scopes:
|
|
5
|
-
* - **project**: Shared across all collaborators (checked into git)
|
|
6
|
-
* - **local**: Machine-specific, not shared (gitignored)
|
|
7
|
-
* - **user**: Global per-user, spans all projects
|
|
8
|
-
*
|
|
9
|
-
* Each scope stores agent-specific memory in a named subdirectory,
|
|
10
|
-
* enabling isolated yet transferable knowledge between agents.
|
|
11
|
-
*
|
|
12
|
-
* @module @monomind/memory/agent-memory-scope
|
|
13
|
-
*/
|
|
14
|
-
import * as path from 'node:path';
|
|
15
|
-
import { existsSync, readdirSync, statSync } from 'node:fs';
|
|
16
|
-
import { AutoMemoryBridge } from './auto-memory-bridge.js';
|
|
17
|
-
// ===== Internal Helpers =====
|
|
18
|
-
/**
|
|
19
|
-
* Find the git root directory by walking up from a starting directory.
|
|
20
|
-
* Synchronous variant for path resolution (no async needed for stat checks).
|
|
21
|
-
*/
|
|
22
|
-
// Cache git-root lookups — the result is stable for the process lifetime
|
|
23
|
-
const gitRootCache = new Map();
|
|
24
|
-
function findGitRootSync(dir) {
|
|
25
|
-
const resolved = path.resolve(dir);
|
|
26
|
-
if (gitRootCache.has(resolved))
|
|
27
|
-
return gitRootCache.get(resolved);
|
|
28
|
-
let current = resolved;
|
|
29
|
-
const root = path.parse(current).root;
|
|
30
|
-
while (current !== root) {
|
|
31
|
-
if (existsSync(path.join(current, '.git'))) {
|
|
32
|
-
gitRootCache.set(resolved, current);
|
|
33
|
-
return current;
|
|
34
|
-
}
|
|
35
|
-
current = path.dirname(current);
|
|
36
|
-
}
|
|
37
|
-
gitRootCache.set(resolved, null);
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* List agent subdirectories inside a given directory.
|
|
42
|
-
* Returns an empty array if the directory does not exist or is unreadable.
|
|
43
|
-
*/
|
|
44
|
-
function listAgentsInDir(dir) {
|
|
45
|
-
if (!existsSync(dir))
|
|
46
|
-
return [];
|
|
47
|
-
try {
|
|
48
|
-
return readdirSync(dir).filter((name) => {
|
|
49
|
-
try {
|
|
50
|
-
return statSync(path.join(dir, name)).isDirectory();
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
catch {
|
|
58
|
-
return [];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
// ===== Public Functions =====
|
|
62
|
-
/**
|
|
63
|
-
* Resolve the agent memory directory for a given agent name, scope, and working directory.
|
|
64
|
-
*
|
|
65
|
-
* Path resolution matches Claude Code binary behavior:
|
|
66
|
-
* ```
|
|
67
|
-
* project: <gitRoot>/.claude/agent-memory/<agentName>/
|
|
68
|
-
* local: <gitRoot>/.claude/agent-memory-local/<agentName>/
|
|
69
|
-
* user: ~/.claude/agent-memory/<agentName>/
|
|
70
|
-
* ```
|
|
71
|
-
*
|
|
72
|
-
* Agent names are sanitized to prevent path traversal attacks.
|
|
73
|
-
*
|
|
74
|
-
* @param agentName - The agent identifier
|
|
75
|
-
* @param scope - Memory scope: project, local, or user
|
|
76
|
-
* @param workingDir - Working directory for git root detection (defaults to cwd)
|
|
77
|
-
* @returns Absolute path to the agent's memory directory
|
|
78
|
-
*/
|
|
79
|
-
export function resolveAgentMemoryDir(agentName, scope, workingDir) {
|
|
80
|
-
// Sanitize agent name to prevent path traversal
|
|
81
|
-
const safeName = agentName.replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
82
|
-
if (scope === 'user') {
|
|
83
|
-
const home = process.env.HOME
|
|
84
|
-
|| process.env.USERPROFILE
|
|
85
|
-
|| (process.env.HOMEDRIVE && process.env.HOMEPATH ? process.env.HOMEDRIVE + process.env.HOMEPATH : '');
|
|
86
|
-
if (!home) {
|
|
87
|
-
throw new Error('Cannot determine home directory: HOME, USERPROFILE, and HOMEDRIVE+HOMEPATH are all undefined');
|
|
88
|
-
}
|
|
89
|
-
return path.join(home, '.claude', 'agent-memory', safeName);
|
|
90
|
-
}
|
|
91
|
-
// For project and local scopes, find git root
|
|
92
|
-
const effectiveDir = workingDir || process.cwd();
|
|
93
|
-
const gitRoot = findGitRootSync(effectiveDir);
|
|
94
|
-
const baseDir = gitRoot || effectiveDir;
|
|
95
|
-
if (scope === 'local') {
|
|
96
|
-
return path.join(baseDir, '.claude', 'agent-memory-local', safeName);
|
|
97
|
-
}
|
|
98
|
-
// scope === 'project'
|
|
99
|
-
return path.join(baseDir, '.claude', 'agent-memory', safeName);
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Create an AutoMemoryBridge configured for a specific agent scope.
|
|
103
|
-
*
|
|
104
|
-
* This is the primary factory for creating scoped bridges. It resolves
|
|
105
|
-
* the correct memory directory based on agent name and scope, then
|
|
106
|
-
* delegates to AutoMemoryBridge for the actual sync logic.
|
|
107
|
-
*
|
|
108
|
-
* @param backend - the LanceDB memory backend
|
|
109
|
-
* @param config - Agent-scoped configuration
|
|
110
|
-
* @returns A configured AutoMemoryBridge instance
|
|
111
|
-
*
|
|
112
|
-
* @example
|
|
113
|
-
* ```typescript
|
|
114
|
-
* const bridge = createAgentBridge(backend, {
|
|
115
|
-
* agentName: 'coder',
|
|
116
|
-
* scope: 'project',
|
|
117
|
-
* syncMode: 'on-write',
|
|
118
|
-
* });
|
|
119
|
-
* await bridge.recordInsight({ ... });
|
|
120
|
-
* ```
|
|
121
|
-
*/
|
|
122
|
-
export function createAgentBridge(backend, config) {
|
|
123
|
-
const memoryDir = resolveAgentMemoryDir(config.agentName, config.scope, config.workingDir);
|
|
124
|
-
return new AutoMemoryBridge(backend, {
|
|
125
|
-
...config,
|
|
126
|
-
memoryDir,
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Transfer knowledge from a source backend namespace into a target bridge.
|
|
131
|
-
*
|
|
132
|
-
* Queries high-confidence entries from the source and records them as
|
|
133
|
-
* insights in the target bridge. Useful for cross-agent knowledge sharing
|
|
134
|
-
* or promoting learnings from one scope to another.
|
|
135
|
-
*
|
|
136
|
-
* @param sourceBackend - Backend to query entries from
|
|
137
|
-
* @param targetBridge - Bridge to record insights into
|
|
138
|
-
* @param options - Transfer options (namespace, filters, limits)
|
|
139
|
-
* @returns Transfer result with counts of transferred and skipped entries
|
|
140
|
-
*
|
|
141
|
-
* @example
|
|
142
|
-
* ```typescript
|
|
143
|
-
* const result = await transferKnowledge(sourceBackend, targetBridge, {
|
|
144
|
-
* sourceNamespace: 'learnings',
|
|
145
|
-
* minConfidence: 0.9,
|
|
146
|
-
* maxEntries: 10,
|
|
147
|
-
* categories: ['architecture', 'security'],
|
|
148
|
-
* });
|
|
149
|
-
* console.log(`Transferred ${result.transferred}, skipped ${result.skipped}`);
|
|
150
|
-
* ```
|
|
151
|
-
*/
|
|
152
|
-
export async function transferKnowledge(sourceBackend, targetBridge, options) {
|
|
153
|
-
const { sourceNamespace, minConfidence = 0.8, maxEntries = 20, categories, } = options;
|
|
154
|
-
let transferred = 0;
|
|
155
|
-
let skipped = 0;
|
|
156
|
-
// Query high-confidence entries from source (fetch extra to allow for filtering)
|
|
157
|
-
const entries = await sourceBackend.query({
|
|
158
|
-
type: 'hybrid',
|
|
159
|
-
namespace: sourceNamespace,
|
|
160
|
-
tags: ['insight'],
|
|
161
|
-
limit: maxEntries * 2,
|
|
162
|
-
});
|
|
163
|
-
for (const entry of entries) {
|
|
164
|
-
if (transferred >= maxEntries)
|
|
165
|
-
break;
|
|
166
|
-
const confidence = entry.metadata?.confidence || 0;
|
|
167
|
-
if (confidence < minConfidence) {
|
|
168
|
-
skipped++;
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
// Filter by category if specified
|
|
172
|
-
const entryCategory = entry.metadata?.category;
|
|
173
|
-
if (categories &&
|
|
174
|
-
categories.length > 0 &&
|
|
175
|
-
entryCategory &&
|
|
176
|
-
!categories.includes(entryCategory)) {
|
|
177
|
-
skipped++;
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
// Record as insight in target bridge
|
|
181
|
-
const insight = {
|
|
182
|
-
category: entryCategory || 'project-patterns',
|
|
183
|
-
summary: entry.metadata?.summary || entry.content.split('\n')[0],
|
|
184
|
-
detail: entry.content,
|
|
185
|
-
source: `transfer:${sourceNamespace}`,
|
|
186
|
-
confidence,
|
|
187
|
-
memoryEntryId: entry.id,
|
|
188
|
-
};
|
|
189
|
-
await targetBridge.recordInsight(insight);
|
|
190
|
-
transferred++;
|
|
191
|
-
}
|
|
192
|
-
return { transferred, skipped };
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* List all agent scopes and their agents for the current project.
|
|
196
|
-
*
|
|
197
|
-
* Scans the three scope directories (project, local, user) and returns
|
|
198
|
-
* the agent names found in each. Useful for discovery and diagnostics.
|
|
199
|
-
*
|
|
200
|
-
* @param workingDir - Working directory for git root detection (defaults to cwd)
|
|
201
|
-
* @returns Array of scope/agents pairs
|
|
202
|
-
*
|
|
203
|
-
* @example
|
|
204
|
-
* ```typescript
|
|
205
|
-
* const scopes = listAgentScopes('/workspaces/my-project');
|
|
206
|
-
* // [
|
|
207
|
-
* // { scope: 'project', agents: ['coder', 'tester'] },
|
|
208
|
-
* // { scope: 'local', agents: ['researcher'] },
|
|
209
|
-
* // { scope: 'user', agents: ['planner'] },
|
|
210
|
-
* // ]
|
|
211
|
-
* ```
|
|
212
|
-
*/
|
|
213
|
-
export function listAgentScopes(workingDir) {
|
|
214
|
-
const effectiveDir = workingDir || process.cwd();
|
|
215
|
-
const gitRoot = findGitRootSync(effectiveDir);
|
|
216
|
-
const baseDir = gitRoot || effectiveDir;
|
|
217
|
-
const home = process.env.HOME
|
|
218
|
-
|| process.env.USERPROFILE
|
|
219
|
-
|| (process.env.HOMEDRIVE && process.env.HOMEPATH ? process.env.HOMEDRIVE + process.env.HOMEPATH : '')
|
|
220
|
-
|| '';
|
|
221
|
-
const projectDir = path.join(baseDir, '.claude', 'agent-memory');
|
|
222
|
-
const localDir = path.join(baseDir, '.claude', 'agent-memory-local');
|
|
223
|
-
const userDir = path.join(home, '.claude', 'agent-memory');
|
|
224
|
-
return [
|
|
225
|
-
{ scope: 'project', agents: listAgentsInDir(projectDir) },
|
|
226
|
-
{ scope: 'local', agents: listAgentsInDir(localDir) },
|
|
227
|
-
{ scope: 'user', agents: listAgentsInDir(userDir) },
|
|
228
|
-
];
|
|
229
|
-
}
|
|
230
|
-
//# sourceMappingURL=agent-memory-scope.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agent-memory-scope.js","sourceRoot":"","sources":["../src/agent-memory-scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAwC3D,+BAA+B;AAE/B;;;GAGG;AACH,yEAAyE;AACzE,MAAM,YAAY,GAAG,IAAI,GAAG,EAAyB,CAAC;AAEtD,SAAS,eAAe,CAAC,GAAW;IAClC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACnC,IAAI,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC;QAAE,OAAO,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAE,CAAC;IAEnE,IAAI,OAAO,GAAG,QAAQ,CAAC;IACvB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC;IAEtC,OAAO,OAAO,KAAK,IAAI,EAAE,CAAC;QACxB,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC;YAC3C,YAAY,CAAC,GAAG,CAAC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4
|
-
* Per ADR-048: Bridges Claude Code's auto memory (markdown files at
|
|
5
|
-
* ~/.claude/projects/<project>/memory/) with monomind's unified memory
|
|
6
|
-
* (LanceDB + ANN).
|
|
7
|
-
*
|
|
8
|
-
* Auto memory files are human-readable markdown that Claude loads into its
|
|
9
|
-
* system prompt. MEMORY.md (first 200 lines) is the entrypoint; topic files
|
|
10
|
-
* store detailed notes and are read on demand.
|
|
11
|
-
*
|
|
12
|
-
* @module @monomind/memory/auto-memory-bridge
|
|
13
|
-
*/
|
|
14
|
-
import { EventEmitter } from 'node:events';
|
|
15
|
-
import { type IMemoryBackend } from './types.js';
|
|
16
|
-
import { type LearningBridgeConfig } from './learning-bridge.js';
|
|
17
|
-
import { type MemoryGraphConfig } from './memory-graph.js';
|
|
18
|
-
/** Insight category for organization in MEMORY.md */
|
|
19
|
-
export type InsightCategory = 'project-patterns' | 'debugging' | 'architecture' | 'performance' | 'security' | 'preferences' | 'swarm-results';
|
|
20
|
-
/** Sync direction */
|
|
21
|
-
export type SyncDirection = 'to-auto' | 'from-auto' | 'bidirectional';
|
|
22
|
-
/** Sync mode determines when syncs occur */
|
|
23
|
-
export type SyncMode = 'on-write' | 'on-session-end' | 'periodic';
|
|
24
|
-
/** Prune strategy for keeping MEMORY.md under line limit */
|
|
25
|
-
export type PruneStrategy = 'confidence-weighted' | 'fifo' | 'lru';
|
|
26
|
-
/** Configuration for AutoMemoryBridge */
|
|
27
|
-
export interface AutoMemoryBridgeConfig {
|
|
28
|
-
/** Auto memory directory path (auto-resolved if not provided) */
|
|
29
|
-
memoryDir?: string;
|
|
30
|
-
/** Working directory for git root detection */
|
|
31
|
-
workingDir?: string;
|
|
32
|
-
/** Max lines for MEMORY.md index (default: 180, Claude reads first 200) */
|
|
33
|
-
maxIndexLines?: number;
|
|
34
|
-
/** Topic file mapping: category → filename */
|
|
35
|
-
topicMapping?: Partial<Record<InsightCategory, string>>;
|
|
36
|
-
/** Sync mode (default: 'on-session-end') */
|
|
37
|
-
syncMode?: SyncMode;
|
|
38
|
-
/** Periodic sync interval in ms (if syncMode is 'periodic') */
|
|
39
|
-
syncIntervalMs?: number;
|
|
40
|
-
/** Minimum confidence for syncing to auto memory (default: 0.7) */
|
|
41
|
-
minConfidence?: number;
|
|
42
|
-
/** Maximum lines per topic file (default: 500) */
|
|
43
|
-
maxTopicFileLines?: number;
|
|
44
|
-
/** Prune strategy for MEMORY.md (default: 'confidence-weighted') */
|
|
45
|
-
pruneStrategy?: PruneStrategy;
|
|
46
|
-
/**
|
|
47
|
-
* Learning bridge config (ADR-049). When set, insights trigger neural learning.
|
|
48
|
-
* Tip: pass `embedder: bridgeGenerateEmbedding` from @monomind/cli's memory-bridge
|
|
49
|
-
* to give LearningBridge real semantic embeddings instead of hash fallback.
|
|
50
|
-
*/
|
|
51
|
-
learning?: LearningBridgeConfig;
|
|
52
|
-
/** Knowledge graph config (ADR-049). When set, graph-aware curation is enabled. */
|
|
53
|
-
graph?: MemoryGraphConfig;
|
|
54
|
-
}
|
|
55
|
-
/** A memory insight to record */
|
|
56
|
-
export interface MemoryInsight {
|
|
57
|
-
/** Category for organization */
|
|
58
|
-
category: InsightCategory;
|
|
59
|
-
/** One-line summary for MEMORY.md index */
|
|
60
|
-
summary: string;
|
|
61
|
-
/** Detailed content (goes in topic file if > 2 lines) */
|
|
62
|
-
detail?: string;
|
|
63
|
-
/** Source: which agent/hook discovered this */
|
|
64
|
-
source: string;
|
|
65
|
-
/** Confidence score (0-1), used for curation priority */
|
|
66
|
-
confidence: number;
|
|
67
|
-
/** memory entry ID for cross-reference */
|
|
68
|
-
memoryEntryId?: string;
|
|
69
|
-
}
|
|
70
|
-
/** Result of a sync operation */
|
|
71
|
-
export interface SyncResult {
|
|
72
|
-
/** Number of entries synced */
|
|
73
|
-
synced: number;
|
|
74
|
-
/** Categories that were updated */
|
|
75
|
-
categories: string[];
|
|
76
|
-
/** Duration of sync in milliseconds */
|
|
77
|
-
durationMs: number;
|
|
78
|
-
/** Any errors encountered */
|
|
79
|
-
errors: string[];
|
|
80
|
-
}
|
|
81
|
-
/** Result of an import operation */
|
|
82
|
-
export interface ImportResult {
|
|
83
|
-
/** Number of entries imported */
|
|
84
|
-
imported: number;
|
|
85
|
-
/** Number of entries skipped (already stored) */
|
|
86
|
-
skipped: number;
|
|
87
|
-
/** Files processed */
|
|
88
|
-
files: string[];
|
|
89
|
-
/** Duration in milliseconds */
|
|
90
|
-
durationMs: number;
|
|
91
|
-
}
|
|
92
|
-
/** Parsed markdown entry from a topic file */
|
|
93
|
-
interface ParsedEntry {
|
|
94
|
-
heading: string;
|
|
95
|
-
content: string;
|
|
96
|
-
metadata: Record<string, string>;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Bidirectional bridge between Claude Code auto memory and LanceDB.
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```typescript
|
|
103
|
-
* const bridge = new AutoMemoryBridge(memoryBackend, {
|
|
104
|
-
* workingDir: '/workspaces/my-project',
|
|
105
|
-
* });
|
|
106
|
-
*
|
|
107
|
-
* // Record an insight
|
|
108
|
-
* await bridge.recordInsight({
|
|
109
|
-
* category: 'debugging',
|
|
110
|
-
* summary: 'HNSW index requires initialization before search',
|
|
111
|
-
* source: 'agent:tester',
|
|
112
|
-
* confidence: 0.95,
|
|
113
|
-
* });
|
|
114
|
-
*
|
|
115
|
-
* // Sync to auto memory files
|
|
116
|
-
* await bridge.syncToAutoMemory();
|
|
117
|
-
*
|
|
118
|
-
* // Import auto memory into LanceDB
|
|
119
|
-
* await bridge.importFromAutoMemory();
|
|
120
|
-
* ```
|
|
121
|
-
*/
|
|
122
|
-
export declare class AutoMemoryBridge extends EventEmitter {
|
|
123
|
-
private config;
|
|
124
|
-
private backend;
|
|
125
|
-
private lastSyncTime;
|
|
126
|
-
private syncTimer;
|
|
127
|
-
private insights;
|
|
128
|
-
/** Track memory keys of insights already written to files during this session */
|
|
129
|
-
private syncedInsightKeys;
|
|
130
|
-
/** Monotonic counter to prevent key collisions within the same ms */
|
|
131
|
-
private insightCounter;
|
|
132
|
-
/** Optional learning bridge (ADR-049) */
|
|
133
|
-
private learningBridge?;
|
|
134
|
-
/** Optional knowledge graph (ADR-049) */
|
|
135
|
-
private memoryGraph?;
|
|
136
|
-
constructor(backend: IMemoryBackend, config?: AutoMemoryBridgeConfig);
|
|
137
|
-
/** Get the resolved auto memory directory path */
|
|
138
|
-
getMemoryDir(): string;
|
|
139
|
-
/** Get the path to MEMORY.md */
|
|
140
|
-
getIndexPath(): string;
|
|
141
|
-
/** Get the path to a topic file */
|
|
142
|
-
getTopicPath(category: InsightCategory): string;
|
|
143
|
-
/**
|
|
144
|
-
* Record a memory insight.
|
|
145
|
-
* Stores in the in-memory buffer and optionally writes immediately.
|
|
146
|
-
*/
|
|
147
|
-
recordInsight(insight: MemoryInsight): Promise<void>;
|
|
148
|
-
/**
|
|
149
|
-
* Sync high-confidence memory entries to auto memory files.
|
|
150
|
-
* Called on session-end or periodically.
|
|
151
|
-
*/
|
|
152
|
-
syncToAutoMemory(): Promise<SyncResult>;
|
|
153
|
-
/**
|
|
154
|
-
* Import auto memory files into memory backend.
|
|
155
|
-
* Called on session-start to hydrate memory backend with previous learnings.
|
|
156
|
-
* Uses bulk insert for efficiency.
|
|
157
|
-
*/
|
|
158
|
-
importFromAutoMemory(): Promise<ImportResult>;
|
|
159
|
-
/**
|
|
160
|
-
* Curate MEMORY.md to stay under the line limit.
|
|
161
|
-
* Groups entries by category and prunes low-confidence items.
|
|
162
|
-
*/
|
|
163
|
-
curateIndex(): Promise<void>;
|
|
164
|
-
/**
|
|
165
|
-
* Get auto memory status: directory info, file count, line counts.
|
|
166
|
-
*/
|
|
167
|
-
getStatus(): {
|
|
168
|
-
memoryDir: string;
|
|
169
|
-
exists: boolean;
|
|
170
|
-
files: {
|
|
171
|
-
name: string;
|
|
172
|
-
lines: number;
|
|
173
|
-
}[];
|
|
174
|
-
totalLines: number;
|
|
175
|
-
indexLines: number;
|
|
176
|
-
lastSyncTime: number;
|
|
177
|
-
bufferedInsights: number;
|
|
178
|
-
};
|
|
179
|
-
/** Stop periodic sync and clean up */
|
|
180
|
-
destroy(): void;
|
|
181
|
-
private ensureMemoryDir;
|
|
182
|
-
private storeInsight;
|
|
183
|
-
private writeInsightToFiles;
|
|
184
|
-
private queryRecentInsights;
|
|
185
|
-
private classifyEntry;
|
|
186
|
-
private appendToTopicFile;
|
|
187
|
-
/** Fetch all existing content hashes from the auto-memory namespace in one query */
|
|
188
|
-
private fetchExistingContentHashes;
|
|
189
|
-
private startPeriodicSync;
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Resolve the auto memory directory for a given working directory.
|
|
193
|
-
* Mirrors Claude Code's path derivation from git root.
|
|
194
|
-
*/
|
|
195
|
-
export declare function resolveAutoMemoryDir(workingDir: string): string;
|
|
196
|
-
/**
|
|
197
|
-
* Find the git root directory by walking up from workingDir.
|
|
198
|
-
*/
|
|
199
|
-
export declare function findGitRoot(dir: string): string | null;
|
|
200
|
-
/**
|
|
201
|
-
* Parse markdown content into structured entries.
|
|
202
|
-
* Splits on ## headings and extracts content under each.
|
|
203
|
-
*/
|
|
204
|
-
export declare function parseMarkdownEntries(content: string): ParsedEntry[];
|
|
205
|
-
/**
|
|
206
|
-
* Extract clean one-line summaries from a topic file.
|
|
207
|
-
* Returns bullet-point items (lines starting with '- '), stripping
|
|
208
|
-
* metadata annotations like _(source, date, conf: 0.95)_.
|
|
209
|
-
*/
|
|
210
|
-
export declare function extractSummaries(content: string): string[];
|
|
211
|
-
/**
|
|
212
|
-
* Format an insight as a markdown line for topic files.
|
|
213
|
-
*/
|
|
214
|
-
export declare function formatInsightLine(insight: MemoryInsight): string;
|
|
215
|
-
/**
|
|
216
|
-
* Hash content for deduplication.
|
|
217
|
-
*/
|
|
218
|
-
export declare function hashContent(content: string): string;
|
|
219
|
-
/**
|
|
220
|
-
* Prune a topic file to stay under the line limit.
|
|
221
|
-
* Removes oldest entries (those closest to the top after the header).
|
|
222
|
-
*/
|
|
223
|
-
export declare function pruneTopicFile(content: string, maxLines: number): string;
|
|
224
|
-
/**
|
|
225
|
-
* Check if a summary already exists as a bullet line in topic file content.
|
|
226
|
-
* Uses exact bullet prefix matching (not substring) to avoid false positives.
|
|
227
|
-
*/
|
|
228
|
-
export declare function hasSummaryLine(content: string, summary: string): boolean;
|
|
229
|
-
export default AutoMemoryBridge;
|
|
230
|
-
//# sourceMappingURL=auto-memory-bridge.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auto-memory-bridge.d.ts","sourceRoot":"","sources":["../src/auto-memory-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C,OAAO,EAEL,KAAK,cAAc,EAIpB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAkB,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAIxE,qDAAqD;AACrD,MAAM,MAAM,eAAe,GACvB,kBAAkB,GAClB,WAAW,GACX,cAAc,GACd,aAAa,GACb,UAAU,GACV,aAAa,GACb,eAAe,CAAC;AAEpB,qBAAqB;AACrB,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,WAAW,GAAG,eAAe,CAAC;AAEtE,4CAA4C;AAC5C,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,gBAAgB,GAAG,UAAU,CAAC;AAElE,4DAA4D;AAC5D,MAAM,MAAM,aAAa,GAAG,qBAAqB,GAAG,MAAM,GAAG,KAAK,CAAC;AAEnE,yCAAyC;AACzC,MAAM,WAAW,sBAAsB;IACrC,iEAAiE;IACjE,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,+CAA+C;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,2EAA2E;IAC3E,aAAa,CAAC,EAAE,MAAM,C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