moflo 4.8.17 → 4.8.20
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/.claude/guidance/shipped/moflo.md +45 -0
- package/.claude/helpers/statusline.cjs +1 -1
- package/.claude/workflow-state.json +9 -0
- package/bin/generate-code-map.mjs +91 -12
- package/package.json +2 -2
- package/src/@claude-flow/cli/bin/cli.js +5 -0
- package/src/@claude-flow/cli/dist/src/init/moflo-init.js +9 -0
- package/src/@claude-flow/cli/dist/src/init/statusline-generator.js +1 -1
- package/src/@claude-flow/cli/dist/src/services/agentic-flow-bridge.js +8 -0
- package/src/@claude-flow/cli/package.json +1 -1
- package/src/@claude-flow/memory/dist/agent-memory-scope.d.ts +131 -0
- package/src/@claude-flow/memory/dist/agent-memory-scope.js +223 -0
- package/src/@claude-flow/memory/dist/agent-memory-scope.test.d.ts +8 -0
- package/src/@claude-flow/memory/dist/agent-memory-scope.test.js +466 -0
- package/src/@claude-flow/memory/dist/agentdb-adapter.d.ts +165 -0
- package/src/@claude-flow/memory/dist/agentdb-adapter.js +806 -0
- package/src/@claude-flow/memory/dist/agentdb-backend.d.ts +212 -0
- package/src/@claude-flow/memory/dist/agentdb-backend.js +842 -0
- package/src/@claude-flow/memory/dist/agentdb-backend.test.d.ts +7 -0
- package/src/@claude-flow/memory/dist/agentdb-backend.test.js +258 -0
- package/src/@claude-flow/memory/dist/application/commands/delete-memory.command.d.ts +65 -0
- package/src/@claude-flow/memory/dist/application/commands/delete-memory.command.js +129 -0
- package/src/@claude-flow/memory/dist/application/commands/store-memory.command.d.ts +48 -0
- package/src/@claude-flow/memory/dist/application/commands/store-memory.command.js +72 -0
- package/src/@claude-flow/memory/dist/application/index.d.ts +12 -0
- package/src/@claude-flow/memory/dist/application/index.js +15 -0
- package/src/@claude-flow/memory/dist/application/queries/search-memory.query.d.ts +72 -0
- package/src/@claude-flow/memory/dist/application/queries/search-memory.query.js +143 -0
- package/src/@claude-flow/memory/dist/application/services/memory-application-service.d.ts +121 -0
- package/src/@claude-flow/memory/dist/application/services/memory-application-service.js +190 -0
- package/src/@claude-flow/memory/dist/auto-memory-bridge.d.ts +226 -0
- package/src/@claude-flow/memory/dist/auto-memory-bridge.js +709 -0
- package/src/@claude-flow/memory/dist/auto-memory-bridge.test.d.ts +8 -0
- package/src/@claude-flow/memory/dist/auto-memory-bridge.test.js +757 -0
- package/src/@claude-flow/memory/dist/benchmark.test.d.ts +2 -0
- package/src/@claude-flow/memory/dist/benchmark.test.js +277 -0
- package/src/@claude-flow/memory/dist/cache-manager.d.ts +134 -0
- package/src/@claude-flow/memory/dist/cache-manager.js +407 -0
- package/src/@claude-flow/memory/dist/controller-registry.d.ts +216 -0
- package/src/@claude-flow/memory/dist/controller-registry.js +893 -0
- package/src/@claude-flow/memory/dist/controller-registry.test.d.ts +14 -0
- package/src/@claude-flow/memory/dist/controller-registry.test.js +593 -0
- package/src/@claude-flow/memory/dist/database-provider.d.ts +87 -0
- package/src/@claude-flow/memory/dist/database-provider.js +372 -0
- package/src/@claude-flow/memory/dist/database-provider.test.d.ts +7 -0
- package/src/@claude-flow/memory/dist/database-provider.test.js +287 -0
- package/src/@claude-flow/memory/dist/domain/entities/memory-entry.d.ts +143 -0
- package/src/@claude-flow/memory/dist/domain/entities/memory-entry.js +226 -0
- package/src/@claude-flow/memory/dist/domain/index.d.ts +11 -0
- package/src/@claude-flow/memory/dist/domain/index.js +12 -0
- package/src/@claude-flow/memory/dist/domain/repositories/memory-repository.interface.d.ts +102 -0
- package/src/@claude-flow/memory/dist/domain/repositories/memory-repository.interface.js +11 -0
- package/src/@claude-flow/memory/dist/domain/services/memory-domain-service.d.ts +105 -0
- package/src/@claude-flow/memory/dist/domain/services/memory-domain-service.js +297 -0
- package/src/@claude-flow/memory/dist/hnsw-index.d.ts +111 -0
- package/src/@claude-flow/memory/dist/hnsw-index.js +781 -0
- package/src/@claude-flow/memory/dist/hnsw-lite.d.ts +23 -0
- package/src/@claude-flow/memory/dist/hnsw-lite.js +168 -0
- package/src/@claude-flow/memory/dist/index.d.ts +204 -0
- package/src/@claude-flow/memory/dist/index.js +358 -0
- package/src/@claude-flow/memory/dist/infrastructure/index.d.ts +17 -0
- package/src/@claude-flow/memory/dist/infrastructure/index.js +16 -0
- package/src/@claude-flow/memory/dist/infrastructure/repositories/hybrid-memory-repository.d.ts +66 -0
- package/src/@claude-flow/memory/dist/infrastructure/repositories/hybrid-memory-repository.js +409 -0
- package/src/@claude-flow/memory/dist/learning-bridge.d.ts +137 -0
- package/src/@claude-flow/memory/dist/learning-bridge.js +335 -0
- package/src/@claude-flow/memory/dist/learning-bridge.test.d.ts +8 -0
- package/src/@claude-flow/memory/dist/learning-bridge.test.js +578 -0
- package/src/@claude-flow/memory/dist/memory-graph.d.ts +100 -0
- package/src/@claude-flow/memory/dist/memory-graph.js +333 -0
- package/src/@claude-flow/memory/dist/memory-graph.test.d.ts +8 -0
- package/src/@claude-flow/memory/dist/memory-graph.test.js +609 -0
- package/src/@claude-flow/memory/dist/migration.d.ts +68 -0
- package/src/@claude-flow/memory/dist/migration.js +513 -0
- package/src/@claude-flow/memory/dist/persistent-sona.d.ts +144 -0
- package/src/@claude-flow/memory/dist/persistent-sona.js +332 -0
- package/src/@claude-flow/memory/dist/query-builder.d.ts +211 -0
- package/src/@claude-flow/memory/dist/query-builder.js +438 -0
- package/src/@claude-flow/memory/dist/rvf-backend.d.ts +51 -0
- package/src/@claude-flow/memory/dist/rvf-backend.js +481 -0
- package/src/@claude-flow/memory/dist/rvf-learning-store.d.ts +139 -0
- package/src/@claude-flow/memory/dist/rvf-learning-store.js +295 -0
- package/src/@claude-flow/memory/dist/rvf-migration.d.ts +45 -0
- package/src/@claude-flow/memory/dist/rvf-migration.js +234 -0
- package/src/@claude-flow/memory/dist/sqljs-backend.d.ts +127 -0
- package/src/@claude-flow/memory/dist/sqljs-backend.js +600 -0
- package/src/@claude-flow/memory/dist/types.d.ts +484 -0
- package/src/@claude-flow/memory/dist/types.js +58 -0
- package/src/@claude-flow/shared/dist/core/config/defaults.d.ts +41 -0
- package/src/@claude-flow/shared/dist/core/config/defaults.js +186 -0
- package/src/@claude-flow/shared/dist/core/config/index.d.ts +8 -0
- package/src/@claude-flow/shared/dist/core/config/index.js +12 -0
- package/src/@claude-flow/shared/dist/core/config/loader.d.ts +45 -0
- package/src/@claude-flow/shared/dist/core/config/loader.js +222 -0
- package/src/@claude-flow/shared/dist/core/config/schema.d.ts +1134 -0
- package/src/@claude-flow/shared/dist/core/config/schema.js +158 -0
- package/src/@claude-flow/shared/dist/core/config/validator.d.ts +92 -0
- package/src/@claude-flow/shared/dist/core/config/validator.js +147 -0
- package/src/@claude-flow/shared/dist/core/event-bus.d.ts +31 -0
- package/src/@claude-flow/shared/dist/core/event-bus.js +197 -0
- package/src/@claude-flow/shared/dist/core/index.d.ts +15 -0
- package/src/@claude-flow/shared/dist/core/index.js +19 -0
- package/src/@claude-flow/shared/dist/core/interfaces/agent.interface.d.ts +200 -0
- package/src/@claude-flow/shared/dist/core/interfaces/agent.interface.js +6 -0
- package/src/@claude-flow/shared/dist/core/interfaces/coordinator.interface.d.ts +310 -0
- package/src/@claude-flow/shared/dist/core/interfaces/coordinator.interface.js +7 -0
- package/src/@claude-flow/shared/dist/core/interfaces/event.interface.d.ts +224 -0
- package/src/@claude-flow/shared/dist/core/interfaces/event.interface.js +46 -0
- package/src/@claude-flow/shared/dist/core/interfaces/index.d.ts +10 -0
- package/src/@claude-flow/shared/dist/core/interfaces/index.js +15 -0
- package/src/@claude-flow/shared/dist/core/interfaces/memory.interface.d.ts +298 -0
- package/src/@claude-flow/shared/dist/core/interfaces/memory.interface.js +7 -0
- package/src/@claude-flow/shared/dist/core/interfaces/task.interface.d.ts +185 -0
- package/src/@claude-flow/shared/dist/core/interfaces/task.interface.js +6 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/event-coordinator.d.ts +35 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/event-coordinator.js +101 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/health-monitor.d.ts +60 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/health-monitor.js +166 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/index.d.ts +46 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/index.js +64 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/lifecycle-manager.d.ts +56 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/lifecycle-manager.js +195 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/session-manager.d.ts +83 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/session-manager.js +193 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/task-manager.d.ts +49 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/task-manager.js +253 -0
- package/src/@claude-flow/shared/dist/events/domain-events.d.ts +282 -0
- package/src/@claude-flow/shared/dist/events/domain-events.js +165 -0
- package/src/@claude-flow/shared/dist/events/event-store.d.ts +126 -0
- package/src/@claude-flow/shared/dist/events/event-store.js +432 -0
- package/src/@claude-flow/shared/dist/events/event-store.test.d.ts +8 -0
- package/src/@claude-flow/shared/dist/events/event-store.test.js +297 -0
- package/src/@claude-flow/shared/dist/events/example-usage.d.ts +10 -0
- package/src/@claude-flow/shared/dist/events/example-usage.js +193 -0
- package/src/@claude-flow/shared/dist/events/index.d.ts +21 -0
- package/src/@claude-flow/shared/dist/events/index.js +22 -0
- package/src/@claude-flow/shared/dist/events/projections.d.ts +177 -0
- package/src/@claude-flow/shared/dist/events/projections.js +421 -0
- package/src/@claude-flow/shared/dist/events/rvf-event-log.d.ts +82 -0
- package/src/@claude-flow/shared/dist/events/rvf-event-log.js +340 -0
- package/src/@claude-flow/shared/dist/events/state-reconstructor.d.ts +101 -0
- package/src/@claude-flow/shared/dist/events/state-reconstructor.js +263 -0
- package/src/@claude-flow/shared/dist/events.d.ts +80 -0
- package/src/@claude-flow/shared/dist/events.js +249 -0
- package/src/@claude-flow/shared/dist/hooks/example-usage.d.ts +42 -0
- package/src/@claude-flow/shared/dist/hooks/example-usage.js +351 -0
- package/src/@claude-flow/shared/dist/hooks/executor.d.ts +100 -0
- package/src/@claude-flow/shared/dist/hooks/executor.js +267 -0
- package/src/@claude-flow/shared/dist/hooks/hooks.test.d.ts +9 -0
- package/src/@claude-flow/shared/dist/hooks/hooks.test.js +322 -0
- package/src/@claude-flow/shared/dist/hooks/index.d.ts +52 -0
- package/src/@claude-flow/shared/dist/hooks/index.js +51 -0
- package/src/@claude-flow/shared/dist/hooks/registry.d.ts +133 -0
- package/src/@claude-flow/shared/dist/hooks/registry.js +277 -0
- package/src/@claude-flow/shared/dist/hooks/safety/bash-safety.d.ts +105 -0
- package/src/@claude-flow/shared/dist/hooks/safety/bash-safety.js +481 -0
- package/src/@claude-flow/shared/dist/hooks/safety/file-organization.d.ts +144 -0
- package/src/@claude-flow/shared/dist/hooks/safety/file-organization.js +328 -0
- package/src/@claude-flow/shared/dist/hooks/safety/git-commit.d.ts +158 -0
- package/src/@claude-flow/shared/dist/hooks/safety/git-commit.js +450 -0
- package/src/@claude-flow/shared/dist/hooks/safety/index.d.ts +17 -0
- package/src/@claude-flow/shared/dist/hooks/safety/index.js +17 -0
- package/src/@claude-flow/shared/dist/hooks/session-hooks.d.ts +234 -0
- package/src/@claude-flow/shared/dist/hooks/session-hooks.js +334 -0
- package/src/@claude-flow/shared/dist/hooks/task-hooks.d.ts +163 -0
- package/src/@claude-flow/shared/dist/hooks/task-hooks.js +326 -0
- package/src/@claude-flow/shared/dist/hooks/types.d.ts +267 -0
- package/src/@claude-flow/shared/dist/hooks/types.js +62 -0
- package/src/@claude-flow/shared/dist/hooks/verify-exports.test.d.ts +9 -0
- package/src/@claude-flow/shared/dist/hooks/verify-exports.test.js +93 -0
- package/src/@claude-flow/shared/dist/index.d.ts +20 -0
- package/src/@claude-flow/shared/dist/index.js +50 -0
- package/src/@claude-flow/shared/dist/mcp/connection-pool.d.ts +98 -0
- package/src/@claude-flow/shared/dist/mcp/connection-pool.js +364 -0
- package/src/@claude-flow/shared/dist/mcp/index.d.ts +69 -0
- package/src/@claude-flow/shared/dist/mcp/index.js +84 -0
- package/src/@claude-flow/shared/dist/mcp/server.d.ts +166 -0
- package/src/@claude-flow/shared/dist/mcp/server.js +593 -0
- package/src/@claude-flow/shared/dist/mcp/session-manager.d.ts +136 -0
- package/src/@claude-flow/shared/dist/mcp/session-manager.js +335 -0
- package/src/@claude-flow/shared/dist/mcp/tool-registry.d.ts +178 -0
- package/src/@claude-flow/shared/dist/mcp/tool-registry.js +439 -0
- package/src/@claude-flow/shared/dist/mcp/transport/http.d.ts +104 -0
- package/src/@claude-flow/shared/dist/mcp/transport/http.js +476 -0
- package/src/@claude-flow/shared/dist/mcp/transport/index.d.ts +102 -0
- package/src/@claude-flow/shared/dist/mcp/transport/index.js +238 -0
- package/src/@claude-flow/shared/dist/mcp/transport/stdio.d.ts +104 -0
- package/src/@claude-flow/shared/dist/mcp/transport/stdio.js +263 -0
- package/src/@claude-flow/shared/dist/mcp/transport/websocket.d.ts +133 -0
- package/src/@claude-flow/shared/dist/mcp/transport/websocket.js +396 -0
- package/src/@claude-flow/shared/dist/mcp/types.d.ts +438 -0
- package/src/@claude-flow/shared/dist/mcp/types.js +54 -0
- package/src/@claude-flow/shared/dist/plugin-interface.d.ts +544 -0
- package/src/@claude-flow/shared/dist/plugin-interface.js +23 -0
- package/src/@claude-flow/shared/dist/plugin-loader.d.ts +139 -0
- package/src/@claude-flow/shared/dist/plugin-loader.js +434 -0
- package/src/@claude-flow/shared/dist/plugin-registry.d.ts +183 -0
- package/src/@claude-flow/shared/dist/plugin-registry.js +457 -0
- package/src/@claude-flow/shared/dist/plugins/index.d.ts +10 -0
- package/src/@claude-flow/shared/dist/plugins/index.js +10 -0
- package/src/@claude-flow/shared/dist/plugins/official/hive-mind-plugin.d.ts +106 -0
- package/src/@claude-flow/shared/dist/plugins/official/hive-mind-plugin.js +241 -0
- package/src/@claude-flow/shared/dist/plugins/official/index.d.ts +10 -0
- package/src/@claude-flow/shared/dist/plugins/official/index.js +10 -0
- package/src/@claude-flow/shared/dist/plugins/official/maestro-plugin.d.ts +121 -0
- package/src/@claude-flow/shared/dist/plugins/official/maestro-plugin.js +355 -0
- package/src/@claude-flow/shared/dist/plugins/types.d.ts +93 -0
- package/src/@claude-flow/shared/dist/plugins/types.js +9 -0
- package/src/@claude-flow/shared/dist/resilience/bulkhead.d.ts +105 -0
- package/src/@claude-flow/shared/dist/resilience/bulkhead.js +206 -0
- package/src/@claude-flow/shared/dist/resilience/circuit-breaker.d.ts +132 -0
- package/src/@claude-flow/shared/dist/resilience/circuit-breaker.js +233 -0
- package/src/@claude-flow/shared/dist/resilience/index.d.ts +19 -0
- package/src/@claude-flow/shared/dist/resilience/index.js +19 -0
- package/src/@claude-flow/shared/dist/resilience/rate-limiter.d.ts +168 -0
- package/src/@claude-flow/shared/dist/resilience/rate-limiter.js +314 -0
- package/src/@claude-flow/shared/dist/resilience/retry.d.ts +91 -0
- package/src/@claude-flow/shared/dist/resilience/retry.js +159 -0
- package/src/@claude-flow/shared/dist/security/index.d.ts +10 -0
- package/src/@claude-flow/shared/dist/security/index.js +12 -0
- package/src/@claude-flow/shared/dist/security/input-validation.d.ts +73 -0
- package/src/@claude-flow/shared/dist/security/input-validation.js +201 -0
- package/src/@claude-flow/shared/dist/security/secure-random.d.ts +92 -0
- package/src/@claude-flow/shared/dist/security/secure-random.js +142 -0
- package/src/@claude-flow/shared/dist/services/index.d.ts +7 -0
- package/src/@claude-flow/shared/dist/services/index.js +7 -0
- package/src/@claude-flow/shared/dist/services/v3-progress.service.d.ts +124 -0
- package/src/@claude-flow/shared/dist/services/v3-progress.service.js +402 -0
- package/src/@claude-flow/shared/dist/types/agent.types.d.ts +137 -0
- package/src/@claude-flow/shared/dist/types/agent.types.js +6 -0
- package/src/@claude-flow/shared/dist/types/index.d.ts +11 -0
- package/src/@claude-flow/shared/dist/types/index.js +17 -0
- package/src/@claude-flow/shared/dist/types/mcp.types.d.ts +266 -0
- package/src/@claude-flow/shared/dist/types/mcp.types.js +7 -0
- package/src/@claude-flow/shared/dist/types/memory.types.d.ts +236 -0
- package/src/@claude-flow/shared/dist/types/memory.types.js +7 -0
- package/src/@claude-flow/shared/dist/types/swarm.types.d.ts +186 -0
- package/src/@claude-flow/shared/dist/types/swarm.types.js +65 -0
- package/src/@claude-flow/shared/dist/types/task.types.d.ts +178 -0
- package/src/@claude-flow/shared/dist/types/task.types.js +32 -0
- package/src/@claude-flow/shared/dist/types.d.ts +197 -0
- package/src/@claude-flow/shared/dist/types.js +21 -0
- package/src/@claude-flow/shared/dist/utils/secure-logger.d.ts +69 -0
- package/src/@claude-flow/shared/dist/utils/secure-logger.js +208 -0
|
@@ -31,6 +31,51 @@ npx flo doctor --fix # Verify everything is working
|
|
|
31
31
|
|
|
32
32
|
---
|
|
33
33
|
|
|
34
|
+
## Building from Source
|
|
35
|
+
|
|
36
|
+
Moflo is a TypeScript monorepo using **project references** (`tsc -b`). The root `tsconfig.json` is a solution-style config that delegates to `src/tsconfig.json`, which references all 17 `@claude-flow/*` sub-packages.
|
|
37
|
+
|
|
38
|
+
### Build Commands
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm run build # Runs tsc -b (project references build)
|
|
42
|
+
npm run build:ts # Build @claude-flow/cli only (legacy shortcut)
|
|
43
|
+
npm run build:guidance # Build @claude-flow/guidance only (legacy shortcut)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Architecture
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
tsconfig.json → Solution root (references src/)
|
|
50
|
+
src/tsconfig.json → References all @claude-flow/* packages
|
|
51
|
+
src/tsconfig.base.json → Shared compilerOptions (ES2022, bundler, composite)
|
|
52
|
+
src/@claude-flow/shared/ → Base types (no deps)
|
|
53
|
+
src/@claude-flow/cli/ → CLI + MCP server (depends on shared, swarm)
|
|
54
|
+
src/@claude-flow/hooks/ → Hook system (depends on shared, neural, memory)
|
|
55
|
+
src/@claude-flow/memory/ → Memory backends (no deps)
|
|
56
|
+
src/@claude-flow/guidance/ → Guidance indexing (depends on hooks)
|
|
57
|
+
src/@claude-flow/testing/ → Regression tests (depends on shared, memory, swarm)
|
|
58
|
+
... (17 packages total)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Important Rules
|
|
62
|
+
|
|
63
|
+
1. **Always build from root** — `npm run build` (which runs `tsc -b`) builds all packages in dependency order. Do NOT build individual packages in isolation unless you know what you're doing.
|
|
64
|
+
2. **Never bypass the build** — The `dist/` directories contain compiled JS that ships with `npm publish`. If you edit `.ts` source, you MUST rebuild before publishing.
|
|
65
|
+
3. **Do not work around build errors** — If `tsc -b` fails, fix the type errors. Do not manually compile individual packages to skip errors, as this leads to drift between source and compiled output.
|
|
66
|
+
4. **Sub-packages need `composite: true`** — Every sub-package tsconfig must have `"composite": true` in compilerOptions for project references to work.
|
|
67
|
+
5. **Cross-package imports need `paths`** — If package A imports from `@claude-flow/B`, package A's tsconfig needs both a `"references"` entry and a `"paths"` mapping pointing to B's source.
|
|
68
|
+
|
|
69
|
+
### Publishing
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npm version patch # Bump version (auto-syncs cli sub-package version)
|
|
73
|
+
npm run build # MUST succeed with zero errors
|
|
74
|
+
npm publish --otp=XXX # Requires 2FA OTP
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
34
79
|
## Session Start Automation
|
|
35
80
|
|
|
36
81
|
When a Claude Code session starts, moflo automatically runs three background indexers:
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* npx flo-codemap # Via npx
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
|
|
28
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync } from 'fs';
|
|
29
29
|
import { resolve, dirname, relative, basename, extname } from 'path';
|
|
30
30
|
import { fileURLToPath } from 'url';
|
|
31
31
|
import { createHash } from 'crypto';
|
|
@@ -177,23 +177,102 @@ function countNamespace(db) {
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
// ---------------------------------------------------------------------------
|
|
180
|
-
// Source file enumeration
|
|
180
|
+
// Source file enumeration — git ls-files with filesystem fallback
|
|
181
181
|
// ---------------------------------------------------------------------------
|
|
182
182
|
|
|
183
|
+
/** Read code_map config from moflo.yaml (directories, extensions, exclude). */
|
|
184
|
+
function readCodeMapConfig() {
|
|
185
|
+
const defaults = {
|
|
186
|
+
directories: ['src'],
|
|
187
|
+
extensions: ['.ts', '.tsx', '.js', '.mjs', '.jsx'],
|
|
188
|
+
exclude: [...EXCLUDE_DIRS],
|
|
189
|
+
};
|
|
190
|
+
try {
|
|
191
|
+
const yamlPath = resolve(projectRoot, 'moflo.yaml');
|
|
192
|
+
if (!existsSync(yamlPath)) return defaults;
|
|
193
|
+
const content = readFileSync(yamlPath, 'utf-8');
|
|
194
|
+
// Simple YAML parsing for code_map block
|
|
195
|
+
const block = content.match(/code_map:\s*\n((?:\s+\w+:.*\n?|\s+- .*\n?)+)/);
|
|
196
|
+
if (!block) return defaults;
|
|
197
|
+
const lines = block[1].split('\n');
|
|
198
|
+
let currentKey = null;
|
|
199
|
+
const result = { ...defaults };
|
|
200
|
+
for (const line of lines) {
|
|
201
|
+
const keyMatch = line.match(/^\s+(\w+):/);
|
|
202
|
+
const itemMatch = line.match(/^\s+- (.+)/);
|
|
203
|
+
if (keyMatch) {
|
|
204
|
+
currentKey = keyMatch[1];
|
|
205
|
+
// Inline array: extensions: [".ts", ".tsx"]
|
|
206
|
+
const inlineArray = line.match(/\[([^\]]+)\]/);
|
|
207
|
+
if (inlineArray && (currentKey === 'extensions' || currentKey === 'exclude' || currentKey === 'directories')) {
|
|
208
|
+
result[currentKey] = inlineArray[1].split(',').map(s => s.trim().replace(/^["']|["']$/g, ''));
|
|
209
|
+
}
|
|
210
|
+
} else if (itemMatch && currentKey) {
|
|
211
|
+
if (!Array.isArray(result[currentKey])) result[currentKey] = [];
|
|
212
|
+
result[currentKey].push(itemMatch[1].trim().replace(/^["']|["']$/g, ''));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return result;
|
|
216
|
+
} catch { return defaults; }
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** Walk a directory tree collecting source files (filesystem fallback). */
|
|
220
|
+
function walkDir(dir, extensions, excludeSet, maxDepth = 8, depth = 0) {
|
|
221
|
+
if (depth > maxDepth) return [];
|
|
222
|
+
const results = [];
|
|
223
|
+
let entries;
|
|
224
|
+
try {
|
|
225
|
+
entries = readdirSync(resolve(projectRoot, dir), { withFileTypes: true });
|
|
226
|
+
} catch { return []; }
|
|
227
|
+
for (const entry of entries) {
|
|
228
|
+
if (excludeSet.has(entry.name)) continue;
|
|
229
|
+
// Use forward slashes for consistent cross-platform paths
|
|
230
|
+
const rel = dir ? `${dir}/${entry.name}` : entry.name;
|
|
231
|
+
if (entry.isDirectory()) {
|
|
232
|
+
results.push(...walkDir(rel, extensions, excludeSet, maxDepth, depth + 1));
|
|
233
|
+
} else if (entry.isFile()) {
|
|
234
|
+
const ext = extname(entry.name);
|
|
235
|
+
if (extensions.has(ext)) results.push(rel);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return results;
|
|
239
|
+
}
|
|
240
|
+
|
|
183
241
|
function getSourceFiles() {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
242
|
+
// Try git ls-files first (fast, respects .gitignore)
|
|
243
|
+
try {
|
|
244
|
+
const raw = execSync(
|
|
245
|
+
`git ls-files -- "*.ts" "*.tsx" "*.js" "*.mjs" "*.jsx"`,
|
|
246
|
+
{ cwd: projectRoot, encoding: 'utf-8', maxBuffer: 10 * 1024 * 1024 }
|
|
247
|
+
).trim();
|
|
248
|
+
|
|
249
|
+
if (raw) {
|
|
250
|
+
const files = raw.split('\n').filter(f => {
|
|
251
|
+
for (const ex of EXCLUDE_DIRS) {
|
|
252
|
+
if (f.startsWith(ex + '/') || f.startsWith(ex + '\\')) return false;
|
|
253
|
+
}
|
|
254
|
+
return true;
|
|
255
|
+
});
|
|
256
|
+
if (files.length > 0) return files;
|
|
257
|
+
}
|
|
258
|
+
} catch {
|
|
259
|
+
// git not available or not a git repo — fall through
|
|
260
|
+
}
|
|
188
261
|
|
|
189
|
-
|
|
262
|
+
// Fallback: walk configured directories from moflo.yaml
|
|
263
|
+
log('git ls-files returned no files — falling back to filesystem walk');
|
|
264
|
+
const config = readCodeMapConfig();
|
|
265
|
+
const extSet = new Set(config.extensions);
|
|
266
|
+
const excludeSet = new Set(config.exclude);
|
|
267
|
+
const files = [];
|
|
190
268
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
269
|
+
for (const dir of config.directories) {
|
|
270
|
+
if (existsSync(resolve(projectRoot, dir))) {
|
|
271
|
+
files.push(...walkDir(dir, extSet, excludeSet));
|
|
194
272
|
}
|
|
195
|
-
|
|
196
|
-
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return files;
|
|
197
276
|
}
|
|
198
277
|
|
|
199
278
|
function computeFileListHash(files) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "moflo",
|
|
3
|
-
"version": "4.8.
|
|
3
|
+
"version": "4.8.20",
|
|
4
4
|
"description": "MoFlo — AI agent orchestration for Claude Code. Forked from ruflo/claude-flow with patches applied to source, plus feature-level orchestration.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
],
|
|
48
48
|
"scripts": {
|
|
49
49
|
"dev": "tsx watch src/index.ts",
|
|
50
|
-
"build": "tsc",
|
|
50
|
+
"build": "tsc -b",
|
|
51
51
|
"build:ts": "cd src/@claude-flow/cli && npm run build || true",
|
|
52
52
|
"build:guidance": "cd src/@claude-flow/guidance && npx tsc -p tsconfig.json || true",
|
|
53
53
|
"prepublishOnly": "npm run build:ts && npm run build:guidance",
|
|
@@ -8,6 +8,11 @@
|
|
|
8
8
|
* This allows: echo '{"jsonrpc":"2.0",...}' | npx @claude-flow/cli
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
// Suppress agentic-flow's agentdb-runtime-patch warning. The patch targets
|
|
12
|
+
// agentdb v1.x (dist/controllers/) but v3+ uses dist/src/controllers/ and
|
|
13
|
+
// already ships with correct .js extensions — the patch is unnecessary.
|
|
14
|
+
process.env.SKIP_AGENTDB_PATCH ??= '1';
|
|
15
|
+
|
|
11
16
|
import { randomUUID } from 'crypto';
|
|
12
17
|
|
|
13
18
|
// Check if we should run in MCP server mode
|
|
@@ -558,6 +558,15 @@ function generateHooks(root, force, answers) {
|
|
|
558
558
|
};
|
|
559
559
|
// Merge: preserve existing non-MoFlo hooks, add MoFlo hooks
|
|
560
560
|
existing.hooks = hooks;
|
|
561
|
+
// Ensure statusLine is always present (required for dashboard display).
|
|
562
|
+
// The executor.ts / settings-generator.ts code path adds this, but
|
|
563
|
+
// moflo-init.ts uses its own generateHooks() which was missing it.
|
|
564
|
+
if (!existing.statusLine) {
|
|
565
|
+
existing.statusLine = {
|
|
566
|
+
type: 'command',
|
|
567
|
+
command: 'node "$CLAUDE_PROJECT_DIR/.claude/helpers/statusline.cjs"',
|
|
568
|
+
};
|
|
569
|
+
}
|
|
561
570
|
fs.writeFileSync(settingsPath, JSON.stringify(existing, null, 2), 'utf-8');
|
|
562
571
|
return { name: '.claude/settings.json', status: existing.hooks ? 'updated' : 'created', detail: '14 hooks configured (gates, lifecycle, routing, session)' };
|
|
563
572
|
}
|
|
@@ -7,6 +7,14 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @module agentic-flow-bridge
|
|
9
9
|
*/
|
|
10
|
+
// Suppress the agentic-flow agentdb-runtime-patch warning.
|
|
11
|
+
// The patch targets agentdb v1.3.9 (dist/controllers/index.js) but
|
|
12
|
+
// agentdb v3+ moved to dist/src/controllers/ and already ships with
|
|
13
|
+
// correct .js extensions. The patch is unnecessary and prints a
|
|
14
|
+
// confusing "[AgentDB Patch] Controller index not found" warning.
|
|
15
|
+
if (typeof process !== 'undefined' && !process.env.SKIP_AGENTDB_PATCH) {
|
|
16
|
+
process.env.SKIP_AGENTDB_PATCH = '1';
|
|
17
|
+
}
|
|
10
18
|
// ---------------------------------------------------------------------------
|
|
11
19
|
// Cached module handles (Promise-based to prevent TOCTOU races)
|
|
12
20
|
// ---------------------------------------------------------------------------
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moflo/cli",
|
|
3
|
-
"version": "4.8.
|
|
3
|
+
"version": "4.8.20",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "MoFlo CLI — AI agent orchestration with specialized agents, swarm coordination, MCP server, self-learning hooks, and vector memory for Claude Code",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -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
|