moflo 4.0.1 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/.claude/guidance/agent-bootstrap.md +12 -6
  2. package/bin/setup-project.mjs +201 -0
  3. package/package.json +114 -109
  4. package/v3/@claude-flow/cli/dist/src/memory/memory-bridge.js +194 -81
  5. package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.js +1892 -1841
  6. package/v3/@claude-flow/memory/README.md +587 -0
  7. package/v3/@claude-flow/memory/dist/agent-memory-scope.d.ts +131 -0
  8. package/v3/@claude-flow/memory/dist/agent-memory-scope.js +223 -0
  9. package/v3/@claude-flow/memory/dist/agent-memory-scope.test.d.ts +8 -0
  10. package/v3/@claude-flow/memory/dist/agent-memory-scope.test.js +463 -0
  11. package/v3/@claude-flow/memory/dist/agentdb-adapter.d.ts +165 -0
  12. package/v3/@claude-flow/memory/dist/agentdb-adapter.js +806 -0
  13. package/v3/@claude-flow/memory/dist/agentdb-backend.d.ts +214 -0
  14. package/v3/@claude-flow/memory/dist/agentdb-backend.js +844 -0
  15. package/v3/@claude-flow/memory/dist/agentdb-backend.test.d.ts +7 -0
  16. package/v3/@claude-flow/memory/dist/agentdb-backend.test.js +258 -0
  17. package/v3/@claude-flow/memory/dist/application/commands/delete-memory.command.d.ts +65 -0
  18. package/v3/@claude-flow/memory/dist/application/commands/delete-memory.command.js +129 -0
  19. package/v3/@claude-flow/memory/dist/application/commands/store-memory.command.d.ts +48 -0
  20. package/v3/@claude-flow/memory/dist/application/commands/store-memory.command.js +72 -0
  21. package/v3/@claude-flow/memory/dist/application/index.d.ts +12 -0
  22. package/v3/@claude-flow/memory/dist/application/index.js +15 -0
  23. package/v3/@claude-flow/memory/dist/application/queries/search-memory.query.d.ts +72 -0
  24. package/v3/@claude-flow/memory/dist/application/queries/search-memory.query.js +143 -0
  25. package/v3/@claude-flow/memory/dist/application/services/memory-application-service.d.ts +121 -0
  26. package/v3/@claude-flow/memory/dist/application/services/memory-application-service.js +190 -0
  27. package/v3/@claude-flow/memory/dist/auto-memory-bridge.d.ts +226 -0
  28. package/v3/@claude-flow/memory/dist/auto-memory-bridge.js +709 -0
  29. package/v3/@claude-flow/memory/dist/auto-memory-bridge.test.d.ts +8 -0
  30. package/v3/@claude-flow/memory/dist/auto-memory-bridge.test.js +754 -0
  31. package/v3/@claude-flow/memory/dist/benchmark.test.d.ts +2 -0
  32. package/v3/@claude-flow/memory/dist/benchmark.test.js +277 -0
  33. package/v3/@claude-flow/memory/dist/cache-manager.d.ts +134 -0
  34. package/v3/@claude-flow/memory/dist/cache-manager.js +407 -0
  35. package/v3/@claude-flow/memory/dist/controller-registry.d.ts +216 -0
  36. package/v3/@claude-flow/memory/dist/controller-registry.js +893 -0
  37. package/v3/@claude-flow/memory/dist/controller-registry.test.d.ts +14 -0
  38. package/v3/@claude-flow/memory/dist/controller-registry.test.js +636 -0
  39. package/v3/@claude-flow/memory/dist/database-provider.d.ts +87 -0
  40. package/v3/@claude-flow/memory/dist/database-provider.js +410 -0
  41. package/v3/@claude-flow/memory/dist/database-provider.test.d.ts +7 -0
  42. package/v3/@claude-flow/memory/dist/database-provider.test.js +285 -0
  43. package/v3/@claude-flow/memory/dist/domain/entities/memory-entry.d.ts +143 -0
  44. package/v3/@claude-flow/memory/dist/domain/entities/memory-entry.js +226 -0
  45. package/v3/@claude-flow/memory/dist/domain/index.d.ts +11 -0
  46. package/v3/@claude-flow/memory/dist/domain/index.js +12 -0
  47. package/v3/@claude-flow/memory/dist/domain/repositories/memory-repository.interface.d.ts +102 -0
  48. package/v3/@claude-flow/memory/dist/domain/repositories/memory-repository.interface.js +11 -0
  49. package/v3/@claude-flow/memory/dist/domain/services/memory-domain-service.d.ts +105 -0
  50. package/v3/@claude-flow/memory/dist/domain/services/memory-domain-service.js +297 -0
  51. package/v3/@claude-flow/memory/dist/hnsw-index.d.ts +111 -0
  52. package/v3/@claude-flow/memory/dist/hnsw-index.js +781 -0
  53. package/v3/@claude-flow/memory/dist/hnsw-lite.d.ts +23 -0
  54. package/v3/@claude-flow/memory/dist/hnsw-lite.js +168 -0
  55. package/v3/@claude-flow/memory/dist/hybrid-backend.d.ts +245 -0
  56. package/v3/@claude-flow/memory/dist/hybrid-backend.js +569 -0
  57. package/v3/@claude-flow/memory/dist/hybrid-backend.test.d.ts +8 -0
  58. package/v3/@claude-flow/memory/dist/hybrid-backend.test.js +320 -0
  59. package/v3/@claude-flow/memory/dist/index.d.ts +208 -0
  60. package/v3/@claude-flow/memory/dist/index.js +362 -0
  61. package/v3/@claude-flow/memory/dist/infrastructure/index.d.ts +17 -0
  62. package/v3/@claude-flow/memory/dist/infrastructure/index.js +16 -0
  63. package/v3/@claude-flow/memory/dist/infrastructure/repositories/hybrid-memory-repository.d.ts +66 -0
  64. package/v3/@claude-flow/memory/dist/infrastructure/repositories/hybrid-memory-repository.js +409 -0
  65. package/v3/@claude-flow/memory/dist/learning-bridge.d.ts +137 -0
  66. package/v3/@claude-flow/memory/dist/learning-bridge.js +335 -0
  67. package/v3/@claude-flow/memory/dist/learning-bridge.test.d.ts +8 -0
  68. package/v3/@claude-flow/memory/dist/learning-bridge.test.js +578 -0
  69. package/v3/@claude-flow/memory/dist/memory-graph.d.ts +100 -0
  70. package/v3/@claude-flow/memory/dist/memory-graph.js +333 -0
  71. package/v3/@claude-flow/memory/dist/memory-graph.test.d.ts +8 -0
  72. package/v3/@claude-flow/memory/dist/memory-graph.test.js +609 -0
  73. package/v3/@claude-flow/memory/dist/migration.d.ts +68 -0
  74. package/v3/@claude-flow/memory/dist/migration.js +513 -0
  75. package/v3/@claude-flow/memory/dist/persistent-sona.d.ts +144 -0
  76. package/v3/@claude-flow/memory/dist/persistent-sona.js +332 -0
  77. package/v3/@claude-flow/memory/dist/query-builder.d.ts +211 -0
  78. package/v3/@claude-flow/memory/dist/query-builder.js +438 -0
  79. package/v3/@claude-flow/memory/dist/rvf-backend.d.ts +51 -0
  80. package/v3/@claude-flow/memory/dist/rvf-backend.js +481 -0
  81. package/v3/@claude-flow/memory/dist/rvf-learning-store.d.ts +139 -0
  82. package/v3/@claude-flow/memory/dist/rvf-learning-store.js +295 -0
  83. package/v3/@claude-flow/memory/dist/rvf-migration.d.ts +45 -0
  84. package/v3/@claude-flow/memory/dist/rvf-migration.js +254 -0
  85. package/v3/@claude-flow/memory/dist/sqlite-backend.d.ts +121 -0
  86. package/v3/@claude-flow/memory/dist/sqlite-backend.js +564 -0
  87. package/v3/@claude-flow/memory/dist/sqljs-backend.d.ts +128 -0
  88. package/v3/@claude-flow/memory/dist/sqljs-backend.js +601 -0
  89. package/v3/@claude-flow/memory/dist/types.d.ts +484 -0
  90. package/v3/@claude-flow/memory/dist/types.js +58 -0
  91. package/v3/@claude-flow/memory/package.json +46 -0
@@ -0,0 +1,131 @@
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 @claude-flow/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 AgentDB 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
@@ -0,0 +1,223 @@
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 @claude-flow/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
+ function findGitRootSync(dir) {
23
+ let current = path.resolve(dir);
24
+ const root = path.parse(current).root;
25
+ while (current !== root) {
26
+ if (existsSync(path.join(current, '.git'))) {
27
+ return current;
28
+ }
29
+ current = path.dirname(current);
30
+ }
31
+ return null;
32
+ }
33
+ /**
34
+ * List agent subdirectories inside a given directory.
35
+ * Returns an empty array if the directory does not exist or is unreadable.
36
+ */
37
+ function listAgentsInDir(dir) {
38
+ if (!existsSync(dir))
39
+ return [];
40
+ try {
41
+ return readdirSync(dir).filter((name) => {
42
+ try {
43
+ return statSync(path.join(dir, name)).isDirectory();
44
+ }
45
+ catch {
46
+ return false;
47
+ }
48
+ });
49
+ }
50
+ catch {
51
+ return [];
52
+ }
53
+ }
54
+ // ===== Public Functions =====
55
+ /**
56
+ * Resolve the agent memory directory for a given agent name, scope, and working directory.
57
+ *
58
+ * Path resolution matches Claude Code binary behavior:
59
+ * ```
60
+ * project: <gitRoot>/.claude/agent-memory/<agentName>/
61
+ * local: <gitRoot>/.claude/agent-memory-local/<agentName>/
62
+ * user: ~/.claude/agent-memory/<agentName>/
63
+ * ```
64
+ *
65
+ * Agent names are sanitized to prevent path traversal attacks.
66
+ *
67
+ * @param agentName - The agent identifier
68
+ * @param scope - Memory scope: project, local, or user
69
+ * @param workingDir - Working directory for git root detection (defaults to cwd)
70
+ * @returns Absolute path to the agent's memory directory
71
+ */
72
+ export function resolveAgentMemoryDir(agentName, scope, workingDir) {
73
+ // Sanitize agent name to prevent path traversal
74
+ const safeName = agentName.replace(/[^a-zA-Z0-9_-]/g, '_');
75
+ if (scope === 'user') {
76
+ const home = process.env.HOME
77
+ || process.env.USERPROFILE
78
+ || (process.env.HOMEDRIVE && process.env.HOMEPATH ? process.env.HOMEDRIVE + process.env.HOMEPATH : '');
79
+ if (!home) {
80
+ throw new Error('Cannot determine home directory: HOME, USERPROFILE, and HOMEDRIVE+HOMEPATH are all undefined');
81
+ }
82
+ return path.join(home, '.claude', 'agent-memory', safeName);
83
+ }
84
+ // For project and local scopes, find git root
85
+ const effectiveDir = workingDir || process.cwd();
86
+ const gitRoot = findGitRootSync(effectiveDir);
87
+ const baseDir = gitRoot || effectiveDir;
88
+ if (scope === 'local') {
89
+ return path.join(baseDir, '.claude', 'agent-memory-local', safeName);
90
+ }
91
+ // scope === 'project'
92
+ return path.join(baseDir, '.claude', 'agent-memory', safeName);
93
+ }
94
+ /**
95
+ * Create an AutoMemoryBridge configured for a specific agent scope.
96
+ *
97
+ * This is the primary factory for creating scoped bridges. It resolves
98
+ * the correct memory directory based on agent name and scope, then
99
+ * delegates to AutoMemoryBridge for the actual sync logic.
100
+ *
101
+ * @param backend - The AgentDB memory backend
102
+ * @param config - Agent-scoped configuration
103
+ * @returns A configured AutoMemoryBridge instance
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * const bridge = createAgentBridge(backend, {
108
+ * agentName: 'coder',
109
+ * scope: 'project',
110
+ * syncMode: 'on-write',
111
+ * });
112
+ * await bridge.recordInsight({ ... });
113
+ * ```
114
+ */
115
+ export function createAgentBridge(backend, config) {
116
+ const memoryDir = resolveAgentMemoryDir(config.agentName, config.scope, config.workingDir);
117
+ return new AutoMemoryBridge(backend, {
118
+ ...config,
119
+ memoryDir,
120
+ });
121
+ }
122
+ /**
123
+ * Transfer knowledge from a source backend namespace into a target bridge.
124
+ *
125
+ * Queries high-confidence entries from the source and records them as
126
+ * insights in the target bridge. Useful for cross-agent knowledge sharing
127
+ * or promoting learnings from one scope to another.
128
+ *
129
+ * @param sourceBackend - Backend to query entries from
130
+ * @param targetBridge - Bridge to record insights into
131
+ * @param options - Transfer options (namespace, filters, limits)
132
+ * @returns Transfer result with counts of transferred and skipped entries
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * const result = await transferKnowledge(sourceBackend, targetBridge, {
137
+ * sourceNamespace: 'learnings',
138
+ * minConfidence: 0.9,
139
+ * maxEntries: 10,
140
+ * categories: ['architecture', 'security'],
141
+ * });
142
+ * console.log(`Transferred ${result.transferred}, skipped ${result.skipped}`);
143
+ * ```
144
+ */
145
+ export async function transferKnowledge(sourceBackend, targetBridge, options) {
146
+ const { sourceNamespace, minConfidence = 0.8, maxEntries = 20, categories, } = options;
147
+ let transferred = 0;
148
+ let skipped = 0;
149
+ // Query high-confidence entries from source (fetch extra to allow for filtering)
150
+ const entries = await sourceBackend.query({
151
+ type: 'hybrid',
152
+ namespace: sourceNamespace,
153
+ tags: ['insight'],
154
+ limit: maxEntries * 2,
155
+ });
156
+ for (const entry of entries) {
157
+ if (transferred >= maxEntries)
158
+ break;
159
+ const confidence = entry.metadata?.confidence || 0;
160
+ if (confidence < minConfidence) {
161
+ skipped++;
162
+ continue;
163
+ }
164
+ // Filter by category if specified
165
+ const entryCategory = entry.metadata?.category;
166
+ if (categories &&
167
+ categories.length > 0 &&
168
+ entryCategory &&
169
+ !categories.includes(entryCategory)) {
170
+ skipped++;
171
+ continue;
172
+ }
173
+ // Record as insight in target bridge
174
+ const insight = {
175
+ category: entryCategory || 'project-patterns',
176
+ summary: entry.metadata?.summary || entry.content.split('\n')[0],
177
+ detail: entry.content,
178
+ source: `transfer:${sourceNamespace}`,
179
+ confidence,
180
+ agentDbId: entry.id,
181
+ };
182
+ await targetBridge.recordInsight(insight);
183
+ transferred++;
184
+ }
185
+ return { transferred, skipped };
186
+ }
187
+ /**
188
+ * List all agent scopes and their agents for the current project.
189
+ *
190
+ * Scans the three scope directories (project, local, user) and returns
191
+ * the agent names found in each. Useful for discovery and diagnostics.
192
+ *
193
+ * @param workingDir - Working directory for git root detection (defaults to cwd)
194
+ * @returns Array of scope/agents pairs
195
+ *
196
+ * @example
197
+ * ```typescript
198
+ * const scopes = listAgentScopes('/workspaces/my-project');
199
+ * // [
200
+ * // { scope: 'project', agents: ['coder', 'tester'] },
201
+ * // { scope: 'local', agents: ['researcher'] },
202
+ * // { scope: 'user', agents: ['planner'] },
203
+ * // ]
204
+ * ```
205
+ */
206
+ export function listAgentScopes(workingDir) {
207
+ const effectiveDir = workingDir || process.cwd();
208
+ const gitRoot = findGitRootSync(effectiveDir);
209
+ const baseDir = gitRoot || effectiveDir;
210
+ const home = process.env.HOME
211
+ || process.env.USERPROFILE
212
+ || (process.env.HOMEDRIVE && process.env.HOMEPATH ? process.env.HOMEDRIVE + process.env.HOMEPATH : '')
213
+ || '';
214
+ const projectDir = path.join(baseDir, '.claude', 'agent-memory');
215
+ const localDir = path.join(baseDir, '.claude', 'agent-memory-local');
216
+ const userDir = path.join(home, '.claude', 'agent-memory');
217
+ return [
218
+ { scope: 'project', agents: listAgentsInDir(projectDir) },
219
+ { scope: 'local', agents: listAgentsInDir(localDir) },
220
+ { scope: 'user', agents: listAgentsInDir(userDir) },
221
+ ];
222
+ }
223
+ //# sourceMappingURL=agent-memory-scope.js.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Tests for Agent-Scoped Memory
3
+ *
4
+ * TDD London School (mock-first) tests for the 3-scope agent memory system.
5
+ * Uses vi.mock for ESM-compatible fs mocking.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=agent-memory-scope.test.d.ts.map