moflo 4.8.63 → 4.8.64

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moflo",
3
- "version": "4.8.63",
3
+ "version": "4.8.64",
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",
@@ -112,7 +112,7 @@
112
112
  "@types/js-yaml": "^4.0.9",
113
113
  "@types/node": "^20.19.37",
114
114
  "eslint": "^8.0.0",
115
- "moflo": "^4.8.61",
115
+ "moflo": "^4.8.63",
116
116
  "tsx": "^4.21.0",
117
117
  "typescript": "^5.9.3",
118
118
  "vitest": "^4.0.0"
@@ -0,0 +1,79 @@
1
+ /**
2
+ * AgentDB-backed VectorStore adapter for AIDefence.
3
+ *
4
+ * Wraps the CLI memory-bridge (AgentDB v3 + HNSW + embeddings) so the
5
+ * 6 aidefence_* MCP tools persist learned threat patterns and mitigation
6
+ * strategies across process restarts with 150x-12,500x faster search.
7
+ *
8
+ * @moflo/aidefence stays pure-lib: this adapter lives in the CLI package
9
+ * where the bridge is already available. Arbitrary values are JSON-serialised
10
+ * into the bridge's `content` field; namespaces are prefixed with
11
+ * `aidefence:` to isolate from general memory entries.
12
+ */
13
+ import { bridgeStoreEntry, bridgeSearchEntries, bridgeGetEntry, bridgeDeleteEntry, isBridgeAvailable, } from '../memory/memory-bridge.js';
14
+ // Structural duck-typed shape of @moflo/aidefence's VectorStore interface.
15
+ // Declared locally to avoid cross-package type resolution fragility; TypeScript
16
+ // verifies compatibility structurally when passed to createAIDefence().
17
+ const NS_PREFIX = 'aidefence:';
18
+ function prefixNs(namespace) {
19
+ return `${NS_PREFIX}${namespace}`;
20
+ }
21
+ function safeParse(raw) {
22
+ try {
23
+ return JSON.parse(raw);
24
+ }
25
+ catch {
26
+ return raw;
27
+ }
28
+ }
29
+ export class AgentDBAIDefenceStore {
30
+ async store(params) {
31
+ await bridgeStoreEntry({
32
+ namespace: prefixNs(params.namespace),
33
+ key: params.key,
34
+ value: JSON.stringify(params.value),
35
+ ttl: params.ttl,
36
+ upsert: true,
37
+ });
38
+ }
39
+ async search(params) {
40
+ const queryStr = typeof params.query === 'string' ? params.query : JSON.stringify(params.query);
41
+ const result = await bridgeSearchEntries({
42
+ namespace: prefixNs(params.namespace),
43
+ query: queryStr,
44
+ limit: params.k ?? 10,
45
+ threshold: params.minSimilarity ?? 0,
46
+ });
47
+ if (!result?.results)
48
+ return [];
49
+ return result.results.map(r => ({
50
+ key: r.key,
51
+ value: safeParse(r.content),
52
+ similarity: r.score,
53
+ }));
54
+ }
55
+ async get(namespace, key) {
56
+ const result = await bridgeGetEntry({
57
+ namespace: prefixNs(namespace),
58
+ key,
59
+ });
60
+ if (!result?.found || !result.entry)
61
+ return null;
62
+ return safeParse(result.entry.content);
63
+ }
64
+ async delete(namespace, key) {
65
+ await bridgeDeleteEntry({
66
+ namespace: prefixNs(namespace),
67
+ key,
68
+ });
69
+ }
70
+ }
71
+ /**
72
+ * Return an AgentDB-backed store if the memory bridge is available,
73
+ * otherwise null so the caller can fall back to the default in-memory store.
74
+ */
75
+ export async function tryCreateAgentDBStore() {
76
+ const available = await isBridgeAvailable();
77
+ return available ? new AgentDBAIDefenceStore() : null;
78
+ }
79
+ //# sourceMappingURL=aidefence-agentdb-store.js.map
@@ -10,6 +10,7 @@
10
10
  * Created with ❤️ by motailz.com
11
11
  */
12
12
  import { autoInstallPackage } from './auto-install.js';
13
+ import { tryCreateAgentDBStore } from './aidefence-agentdb-store.js';
13
14
  import { createRequire } from 'module';
14
15
  // Create require for resolving module paths
15
16
  const require = createRequire(import.meta.url);
@@ -17,6 +18,20 @@ const require = createRequire(import.meta.url);
17
18
  let aidefenceInstance = null;
18
19
  // Track if we've attempted install this session
19
20
  let installAttempted = false;
21
+ /**
22
+ * Build createAIDefence config, attaching an AgentDB-backed vector store
23
+ * when the memory bridge is available. Falls back to the package default
24
+ * (InMemoryVectorStore) otherwise so the MCP tools still function standalone.
25
+ */
26
+ async function buildAIDefenceConfig() {
27
+ const store = await tryCreateAgentDBStore();
28
+ if (store) {
29
+ console.error('[claude-flow] aidefence: using AgentDB-backed vector store (HNSW)');
30
+ return { enableLearning: true, vectorStore: store };
31
+ }
32
+ console.error('[claude-flow] aidefence: AgentDB bridge unavailable, using in-memory store');
33
+ return { enableLearning: true };
34
+ }
20
35
  /**
21
36
  * Get or create AIDefence instance (throws if unavailable)
22
37
  */
@@ -28,7 +43,8 @@ async function getAIDefence() {
28
43
  // First attempt - try to load via dynamic import (ESM)
29
44
  try {
30
45
  const aidefence = await import(packageName);
31
- const instance = aidefence.createAIDefence({ enableLearning: true });
46
+ const config = await buildAIDefenceConfig();
47
+ const instance = aidefence.createAIDefence(config);
32
48
  if (!instance) {
33
49
  throw new Error('createAIDefence returned null');
34
50
  }
@@ -60,7 +76,8 @@ async function getAIDefence() {
60
76
  const modulePath = require.resolve(packageName);
61
77
  const cacheBust = `?t=${Date.now()}`;
62
78
  const aidefence = await import(pathToFileURL(modulePath).href + cacheBust);
63
- const instance = aidefence.createAIDefence({ enableLearning: true });
79
+ const config = await buildAIDefenceConfig();
80
+ const instance = aidefence.createAIDefence(config);
64
81
  if (!instance) {
65
82
  throw new Error('createAIDefence returned null after install');
66
83
  }
@@ -2,5 +2,5 @@
2
2
  * Auto-generated by build. Do not edit manually.
3
3
  * Source of truth: root package.json → scripts/sync-version.mjs
4
4
  */
5
- export const VERSION = '4.8.63';
5
+ export const VERSION = '4.8.64';
6
6
  //# sourceMappingURL=version.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moflo/cli",
3
- "version": "4.8.63",
3
+ "version": "4.8.64",
4
4
  "type": "module",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",