claude-flow 3.25.0 → 3.25.1
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 +1 -1
- package/v3/@claude-flow/cli/dist/src/mcp-tools/neural-tools.js +12 -11
- package/v3/@claude-flow/cli/dist/src/memory/embedding-policy.d.ts +21 -0
- package/v3/@claude-flow/cli/dist/src/memory/embedding-policy.js +30 -0
- package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.js +1 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/vector-db.js +2 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/wasm-embedder.d.ts +13 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/wasm-embedder.js +143 -0
- package/v3/@claude-flow/cli/package.json +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-flow",
|
|
3
|
-
"version": "3.25.
|
|
3
|
+
"version": "3.25.1",
|
|
4
4
|
"description": "Ruflo - Enterprise AI agent orchestration for Claude Code. Deploy 60+ specialized agents in coordinated swarms with self-learning, fault-tolerant consensus, vector memory, and MCP integration",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -89,26 +89,26 @@ function ensureEmbeddings() {
|
|
|
89
89
|
return embeddingsPromise;
|
|
90
90
|
embeddingsPromise = (async () => {
|
|
91
91
|
try {
|
|
92
|
-
// Tier -1 (PRIMARY):
|
|
93
|
-
//
|
|
94
|
-
//
|
|
95
|
-
//
|
|
92
|
+
// Tier -1 (PRIMARY): optional WASM embedder — a pluggable real embedder
|
|
93
|
+
// ahead of everything. OPT-IN (RUFLO_EMBED_WASM_PKG) + FAIL-CLOSED: unset
|
|
94
|
+
// or absent/init-fail ⇒ fall straight through to the existing
|
|
95
|
+
// ruvector-ONNX → hash tiers with zero regression.
|
|
96
96
|
try {
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
99
|
-
const model =
|
|
97
|
+
const we = await import('../ruvector/wasm-embedder.js').catch(() => null);
|
|
98
|
+
if (we && await we.wasmEmbedderAvailable()) {
|
|
99
|
+
const model = we.DEFAULT_EMBED_MODEL;
|
|
100
100
|
realEmbeddings = {
|
|
101
101
|
embed: async (text) => {
|
|
102
|
-
const v = await
|
|
102
|
+
const v = await we.wasmEmbed(text, model);
|
|
103
103
|
if (!v || !v.length)
|
|
104
|
-
throw new Error('
|
|
104
|
+
throw new Error('wasm embed failed'); // → generateEmbedding falls to next tier
|
|
105
105
|
return v;
|
|
106
106
|
},
|
|
107
107
|
};
|
|
108
|
-
embeddingServiceName = `
|
|
108
|
+
embeddingServiceName = `wasm-embedder/${model} (${we.wasmEmbedderModels().length} model${we.wasmEmbedderModels().length === 1 ? '' : 's'})`;
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
-
catch { /*
|
|
111
|
+
catch { /* not configured — fall through */ }
|
|
112
112
|
// Tier 0: ruvector@0.2.27 — bundled all-MiniLM-L6-v2 + parallel worker pool.
|
|
113
113
|
// Probe with isOnnxAvailable() and verify an actual embed succeeds (avoids
|
|
114
114
|
// the type-load-success-but-runtime-fails trap from ADR-086). The probe now
|
|
@@ -320,6 +320,7 @@ async function generateEmbedding(text, dims = 384) {
|
|
|
320
320
|
// Hash-based deterministic embedding (better than pure random for consistency)
|
|
321
321
|
// NOTE: No semantic meaning — only useful for consistent deduplication, not similarity search
|
|
322
322
|
if (text) {
|
|
323
|
+
(await import('../memory/embedding-policy.js')).enforceNoStub('neural-tools.generateEmbedding'); // "no stubs" strict mode
|
|
323
324
|
if (embeddingServiceName === 'none') {
|
|
324
325
|
embeddingServiceName = 'hash-fallback';
|
|
325
326
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Embedding policy — "no more stubs" enforcement.
|
|
3
|
+
*
|
|
4
|
+
* Every embedder in the codebase tries REAL models first (Lattice WASM →
|
|
5
|
+
* ruvector ONNX → AgentDB bridge → transformers.js) and only falls back to a
|
|
6
|
+
* deterministic HASH embedding when none loads. A hash embedding has no semantic
|
|
7
|
+
* meaning — it silently degrades similarity search into noise.
|
|
8
|
+
*
|
|
9
|
+
* This module makes that failure mode a POLICY choice instead of a silent
|
|
10
|
+
* default. With RUFLO_REQUIRE_REAL_EMBEDDINGS truthy, any hash last-resort throws
|
|
11
|
+
* loudly ("no stubs") rather than returning a meaningless vector — fail-closed,
|
|
12
|
+
* so a broken embedding substrate is a hard error, not corrupt retrieval.
|
|
13
|
+
*
|
|
14
|
+
* Default (unset): unchanged behavior (warn + degrade), so nothing breaks for
|
|
15
|
+
* installs where a real embedder genuinely can't load. Set the flag in any
|
|
16
|
+
* environment that must never serve pseudo-embeddings.
|
|
17
|
+
*/
|
|
18
|
+
export declare function requireRealEmbeddings(): boolean;
|
|
19
|
+
/** Throw the canonical "no stubs" error if strict mode is on; else no-op. */
|
|
20
|
+
export declare function enforceNoStub(where: string): void;
|
|
21
|
+
//# sourceMappingURL=embedding-policy.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Embedding policy — "no more stubs" enforcement.
|
|
3
|
+
*
|
|
4
|
+
* Every embedder in the codebase tries REAL models first (Lattice WASM →
|
|
5
|
+
* ruvector ONNX → AgentDB bridge → transformers.js) and only falls back to a
|
|
6
|
+
* deterministic HASH embedding when none loads. A hash embedding has no semantic
|
|
7
|
+
* meaning — it silently degrades similarity search into noise.
|
|
8
|
+
*
|
|
9
|
+
* This module makes that failure mode a POLICY choice instead of a silent
|
|
10
|
+
* default. With RUFLO_REQUIRE_REAL_EMBEDDINGS truthy, any hash last-resort throws
|
|
11
|
+
* loudly ("no stubs") rather than returning a meaningless vector — fail-closed,
|
|
12
|
+
* so a broken embedding substrate is a hard error, not corrupt retrieval.
|
|
13
|
+
*
|
|
14
|
+
* Default (unset): unchanged behavior (warn + degrade), so nothing breaks for
|
|
15
|
+
* installs where a real embedder genuinely can't load. Set the flag in any
|
|
16
|
+
* environment that must never serve pseudo-embeddings.
|
|
17
|
+
*/
|
|
18
|
+
export function requireRealEmbeddings() {
|
|
19
|
+
return /^(1|true|yes|on|strict)$/i.test(process.env.RUFLO_REQUIRE_REAL_EMBEDDINGS ?? '');
|
|
20
|
+
}
|
|
21
|
+
/** Throw the canonical "no stubs" error if strict mode is on; else no-op. */
|
|
22
|
+
export function enforceNoStub(where) {
|
|
23
|
+
if (requireRealEmbeddings()) {
|
|
24
|
+
throw new Error(`[no-stub] real embeddings required but only a hash fallback was available at ${where}. ` +
|
|
25
|
+
`RUFLO_REQUIRE_REAL_EMBEDDINGS is set — install a real embedder ` +
|
|
26
|
+
`(ruvector, or @claude-flow/embeddings with "embeddings init --download") ` +
|
|
27
|
+
`or unset the flag to allow degraded hash embeddings.`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=embedding-policy.js.map
|
|
@@ -2011,6 +2011,7 @@ export async function generateLocalEmbedding(text) {
|
|
|
2011
2011
|
}
|
|
2012
2012
|
// Deterministic hash-based fallback (for testing/demo without ONNX).
|
|
2013
2013
|
// AUDIT #3: backend='mock' — these vectors do NOT carry real semantics.
|
|
2014
|
+
(await import('./embedding-policy.js')).enforceNoStub('memory-initializer.generateLocalEmbedding'); // "no stubs" strict mode
|
|
2014
2015
|
const embedding = generateHashEmbedding(text, state.dimensions);
|
|
2015
2016
|
return {
|
|
2016
2017
|
embedding,
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import os from 'node:os';
|
|
14
14
|
import path from 'node:path';
|
|
15
15
|
import { randomUUID } from 'node:crypto';
|
|
16
|
+
import { enforceNoStub } from '../memory/embedding-policy.js';
|
|
16
17
|
// ============================================================================
|
|
17
18
|
// Fallback Implementation (when ruvector not available)
|
|
18
19
|
// ============================================================================
|
|
@@ -248,6 +249,7 @@ export function generateEmbedding(text, dimensions = 768) {
|
|
|
248
249
|
// Fall back to hash-based embedding
|
|
249
250
|
}
|
|
250
251
|
}
|
|
252
|
+
enforceNoStub('vector-db.generateEmbedding'); // "no stubs" strict mode → throw instead of hash
|
|
251
253
|
const embedding = generateHashEmbedding(text, dimensions);
|
|
252
254
|
// Tag the result so consumers can detect it came from hash fallback
|
|
253
255
|
Object.defineProperty(embedding, '_warning', {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package specifier for the optional WASM embedder. EMPTY by default (opt-in).
|
|
3
|
+
* `RUFLO_LATTICE_WASM_PKG` is accepted as a back-compat alias.
|
|
4
|
+
*/
|
|
5
|
+
export declare const EMBED_WASM_PKG: string;
|
|
6
|
+
export declare const DEFAULT_EMBED_MODEL: string;
|
|
7
|
+
/** Is an optional WASM embedder configured + installed + initializable? Cached; never throws. */
|
|
8
|
+
export declare function wasmEmbedderAvailable(): Promise<boolean>;
|
|
9
|
+
/** Models the configured WASM embedder reports (empty until available). */
|
|
10
|
+
export declare function wasmEmbedderModels(): string[];
|
|
11
|
+
/** Embed via the optional WASM embedder, or null (caller falls through). Never throws. */
|
|
12
|
+
export declare function wasmEmbed(text: string, model?: string): Promise<number[] | null>;
|
|
13
|
+
//# sourceMappingURL=wasm-embedder.d.ts.map
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional WASM embedder tier — a pluggable PRIMARY embedding tier ahead of
|
|
3
|
+
* ruvector-ONNX → hash.
|
|
4
|
+
*
|
|
5
|
+
* OPT-IN by design: there is NO default package (an earlier iteration defaulted
|
|
6
|
+
* to `@ruvector/lattice-wasm`, which does not exist — npm 404). Point
|
|
7
|
+
* `RUFLO_EMBED_WASM_PKG` at any real WASM embedder that follows the ruvnet
|
|
8
|
+
* wasm-bindgen convention (a text→vector embed export). With the env unset, this
|
|
9
|
+
* tier is INERT and everything resolves exactly as before (ruvector ONNX). Fully
|
|
10
|
+
* fail-closed; never throws.
|
|
11
|
+
*
|
|
12
|
+
* The adapter probes the module's API tolerantly and verifies a real embed
|
|
13
|
+
* succeeds before accepting the tier (guards the ADR-086 loads-but-runtime-fails
|
|
14
|
+
* trap), so an incompatible package simply reports unavailable.
|
|
15
|
+
*/
|
|
16
|
+
import { createRequire } from 'module';
|
|
17
|
+
import { readFileSync } from 'fs';
|
|
18
|
+
const require_ = createRequire(import.meta.url);
|
|
19
|
+
/**
|
|
20
|
+
* Package specifier for the optional WASM embedder. EMPTY by default (opt-in).
|
|
21
|
+
* `RUFLO_LATTICE_WASM_PKG` is accepted as a back-compat alias.
|
|
22
|
+
*/
|
|
23
|
+
export const EMBED_WASM_PKG = process.env.RUFLO_EMBED_WASM_PKG || process.env.RUFLO_LATTICE_WASM_PKG || '';
|
|
24
|
+
export const DEFAULT_EMBED_MODEL = process.env.RUFLO_EMBED_MODEL || 'default';
|
|
25
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
26
|
+
let _mod = null;
|
|
27
|
+
let _ready = false;
|
|
28
|
+
let _probed = false;
|
|
29
|
+
let _available = false;
|
|
30
|
+
let _models = [];
|
|
31
|
+
async function loadModule() {
|
|
32
|
+
if (!EMBED_WASM_PKG)
|
|
33
|
+
return null; // opt-in: no package configured ⇒ inert
|
|
34
|
+
if (_mod)
|
|
35
|
+
return _mod;
|
|
36
|
+
_mod = await import(EMBED_WASM_PKG).catch(() => null); // optional — absent ⇒ null ⇒ unavailable
|
|
37
|
+
return _mod;
|
|
38
|
+
}
|
|
39
|
+
async function ensureInit() {
|
|
40
|
+
if (_ready)
|
|
41
|
+
return true;
|
|
42
|
+
const mod = await loadModule();
|
|
43
|
+
if (!mod)
|
|
44
|
+
return false;
|
|
45
|
+
try {
|
|
46
|
+
if (typeof mod.initSync === 'function') {
|
|
47
|
+
let wasmBytes;
|
|
48
|
+
for (const cand of ['index_bg.wasm', 'embedder_bg.wasm', 'wasm_bg.wasm']) {
|
|
49
|
+
try {
|
|
50
|
+
wasmBytes = readFileSync(require_.resolve(`${EMBED_WASM_PKG}/${cand}`));
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
catch { /* try next */ }
|
|
54
|
+
}
|
|
55
|
+
mod.initSync(wasmBytes ? { module: wasmBytes } : undefined);
|
|
56
|
+
}
|
|
57
|
+
else if (typeof mod.default === 'function') {
|
|
58
|
+
await mod.default();
|
|
59
|
+
}
|
|
60
|
+
_ready = true;
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function toVec(r) {
|
|
68
|
+
const v = (r && typeof r === 'object' && 'embedding' in r) ? r.embedding : r;
|
|
69
|
+
if (!v)
|
|
70
|
+
return null;
|
|
71
|
+
if (Array.isArray(v))
|
|
72
|
+
return v;
|
|
73
|
+
if (v.length !== undefined)
|
|
74
|
+
return Array.from(v);
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
async function embedRaw(text, model) {
|
|
78
|
+
const mod = _mod;
|
|
79
|
+
if (!mod)
|
|
80
|
+
return null;
|
|
81
|
+
const attempts = [
|
|
82
|
+
() => typeof mod.embed === 'function' ? mod.embed(text, model) : undefined,
|
|
83
|
+
() => typeof mod.embed === 'function' ? mod.embed(text) : undefined,
|
|
84
|
+
() => typeof mod.embedText === 'function' ? mod.embedText(text, model) : undefined,
|
|
85
|
+
() => typeof mod.Embedder === 'function' ? new mod.Embedder(model).embed(text) : undefined,
|
|
86
|
+
];
|
|
87
|
+
for (const a of attempts) {
|
|
88
|
+
try {
|
|
89
|
+
const r = await a();
|
|
90
|
+
const v = toVec(r);
|
|
91
|
+
if (v)
|
|
92
|
+
return v;
|
|
93
|
+
}
|
|
94
|
+
catch { /* try next surface */ }
|
|
95
|
+
}
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
/** Is an optional WASM embedder configured + installed + initializable? Cached; never throws. */
|
|
99
|
+
export async function wasmEmbedderAvailable() {
|
|
100
|
+
if (_probed)
|
|
101
|
+
return _available;
|
|
102
|
+
_probed = true;
|
|
103
|
+
try {
|
|
104
|
+
if (!EMBED_WASM_PKG) {
|
|
105
|
+
_available = false;
|
|
106
|
+
return false;
|
|
107
|
+
} // opt-in; not configured
|
|
108
|
+
if (!(await ensureInit())) {
|
|
109
|
+
_available = false;
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
const mod = _mod;
|
|
113
|
+
try {
|
|
114
|
+
const list = typeof mod.listModels === 'function' ? mod.listModels() : (mod.models ?? mod.MODELS);
|
|
115
|
+
if (Array.isArray(list) && list.length)
|
|
116
|
+
_models = list;
|
|
117
|
+
}
|
|
118
|
+
catch { /* leave default */ }
|
|
119
|
+
if (!_models.length)
|
|
120
|
+
_models = [DEFAULT_EMBED_MODEL];
|
|
121
|
+
const probe = await embedRaw('probe', DEFAULT_EMBED_MODEL);
|
|
122
|
+
_available = !!probe && probe.length > 0;
|
|
123
|
+
return _available;
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
_available = false;
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/** Models the configured WASM embedder reports (empty until available). */
|
|
131
|
+
export function wasmEmbedderModels() { return [..._models]; }
|
|
132
|
+
/** Embed via the optional WASM embedder, or null (caller falls through). Never throws. */
|
|
133
|
+
export async function wasmEmbed(text, model = DEFAULT_EMBED_MODEL) {
|
|
134
|
+
try {
|
|
135
|
+
if (!(await wasmEmbedderAvailable()))
|
|
136
|
+
return null;
|
|
137
|
+
return await embedRaw(text, model);
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=wasm-embedder.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@claude-flow/cli",
|
|
3
|
-
"version": "3.25.
|
|
3
|
+
"version": "3.25.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Ruflo CLI - Enterprise AI agent orchestration with 60+ specialized agents, swarm coordination, MCP server, self-learning hooks, and vector memory for Claude Code",
|
|
6
6
|
"main": "dist/src/index.js",
|