mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-23 21:59:14 +09:00
fix: browser ENOENT/args/hover + RaBitQ bridge store alignment (v3.6.6)
Browser MCP: ENOENT fallback to npx, --args passthrough with Linux sandbox auto-detect, hover @eN ref parity with click/fill. RaBitQ: buildRabitqIndex now reads through bridge (better-sqlite3) first so it sees WAL data from memory_store. Fixes vectorCount: 0 after store. embeddings_search defaults to namespace 'all'. Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
1 parent
234e3cee10
commit
911bd4e940
7 files changed
+194
-72
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "claude-flow",
|
||||
"version": "3.6.5",
|
||||
"version": "3.6.6",
|
||||
"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",
|
||||
"main": "dist/index.js",
|
||||
"type": "module",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ruflo",
|
||||
"version": "3.6.5",
|
||||
"version": "3.6.6",
|
||||
"description": "Ruflo - Enterprise AI agent orchestration platform. Deploy 60+ specialized agents in coordinated swarms with self-learning, fault-tolerant consensus, vector memory, and MCP integration",
|
||||
"main": "bin/ruflo.js",
|
||||
"type": "module",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@claude-flow/cli",
|
||||
"version": "3.6.5",
|
||||
"version": "3.6.6",
|
||||
"type": "module",
|
||||
"description": "Ruflo CLI - Enterprise AI agent orchestration with 60+ specialized agents, swarm coordination, MCP server, self-learning hooks, and vector memory for Claude Code",
|
||||
"main": "dist/src/index.js",
|
||||
|
||||
@@ -16,49 +16,89 @@ const browserSessions = new Map<string, {
|
||||
}>();
|
||||
|
||||
/**
|
||||
* Execute agent-browser CLI command
|
||||
* Execute agent-browser CLI command.
|
||||
* Tries global agent-browser first, falls back to npx if ENOENT.
|
||||
*/
|
||||
async function execBrowserCommand(args: string[], session = 'default'): Promise<MCPToolResult> {
|
||||
const { execFileSync } = await import('child_process');
|
||||
const fullArgs = ['--session', session, '--json', ...args];
|
||||
|
||||
let result: string;
|
||||
try {
|
||||
const fullArgs = ['--session', session, '--json', ...args];
|
||||
const result = execFileSync('agent-browser', fullArgs, {
|
||||
result = execFileSync('agent-browser', fullArgs, {
|
||||
encoding: 'utf-8',
|
||||
timeout: 30000,
|
||||
});
|
||||
|
||||
let data;
|
||||
try {
|
||||
data = JSON.parse(result);
|
||||
} catch {
|
||||
data = result.trim();
|
||||
}
|
||||
|
||||
// Update session activity
|
||||
const sessionInfo = browserSessions.get(session);
|
||||
if (sessionInfo) {
|
||||
sessionInfo.lastActivity = new Date().toISOString();
|
||||
}
|
||||
|
||||
return {
|
||||
content: [{
|
||||
type: 'text',
|
||||
text: JSON.stringify(data, null, 2),
|
||||
}],
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
content: [{
|
||||
type: 'text',
|
||||
text: JSON.stringify({
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
}),
|
||||
}],
|
||||
isError: true,
|
||||
};
|
||||
const err = error as NodeJS.ErrnoException;
|
||||
if (err.code === 'ENOENT') {
|
||||
try {
|
||||
result = execFileSync('npx', ['--yes', 'agent-browser', ...fullArgs], {
|
||||
encoding: 'utf-8',
|
||||
timeout: 60000,
|
||||
});
|
||||
} catch (npxError) {
|
||||
const npxErr = npxError as NodeJS.ErrnoException;
|
||||
return {
|
||||
content: [{
|
||||
type: 'text',
|
||||
text: JSON.stringify({
|
||||
success: false,
|
||||
error: npxErr.code === 'ENOENT'
|
||||
? 'Neither agent-browser nor npx found. Install with: npm i -g agent-browser'
|
||||
: npxErr instanceof Error ? npxErr.message : String(npxError),
|
||||
}),
|
||||
}],
|
||||
isError: true,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
content: [{
|
||||
type: 'text',
|
||||
text: JSON.stringify({
|
||||
success: false,
|
||||
error: err instanceof Error ? err.message : String(error),
|
||||
}),
|
||||
}],
|
||||
isError: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
let data;
|
||||
try {
|
||||
data = JSON.parse(result);
|
||||
} catch {
|
||||
data = result.trim();
|
||||
}
|
||||
|
||||
const sessionInfo = browserSessions.get(session);
|
||||
if (sessionInfo) {
|
||||
sessionInfo.lastActivity = new Date().toISOString();
|
||||
}
|
||||
|
||||
return {
|
||||
content: [{
|
||||
type: 'text',
|
||||
text: JSON.stringify(data, null, 2),
|
||||
}],
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect if Linux needs --no-sandbox for Chrome.
|
||||
*/
|
||||
function needsNoSandbox(): boolean {
|
||||
try {
|
||||
const { readFileSync, existsSync } = require('fs');
|
||||
if (process.platform !== 'linux') return false;
|
||||
const clonePath = '/proc/sys/kernel/unprivileged_userns_clone';
|
||||
if (existsSync(clonePath)) {
|
||||
return readFileSync(clonePath, 'utf-8').trim() === '0';
|
||||
}
|
||||
} catch { /* not Linux or can't read */ }
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,6 +123,11 @@ export const browserTools: MCPTool[] = [
|
||||
enum: ['load', 'domcontentloaded', 'networkidle'],
|
||||
description: 'Wait condition',
|
||||
},
|
||||
args: {
|
||||
type: 'array',
|
||||
items: { type: 'string' },
|
||||
description: 'Additional Chrome launch args (e.g., ["--no-sandbox", "--disable-dev-shm-usage"])',
|
||||
},
|
||||
},
|
||||
required: ['url'],
|
||||
},
|
||||
@@ -95,8 +140,13 @@ export const browserTools: MCPTool[] = [
|
||||
session?: string;
|
||||
waitUntil?: string;
|
||||
};
|
||||
const launchArgs = (input.args as string[] | undefined) || [];
|
||||
if (needsNoSandbox() && !launchArgs.includes('--no-sandbox')) {
|
||||
launchArgs.push('--no-sandbox');
|
||||
}
|
||||
const args = ['open', url];
|
||||
if (waitUntil) args.push('--wait-until', waitUntil);
|
||||
for (const a of launchArgs) args.push('--arg', a);
|
||||
|
||||
// Create session if new
|
||||
const sessionId = session || 'default';
|
||||
@@ -359,13 +409,13 @@ export const browserTools: MCPTool[] = [
|
||||
},
|
||||
{
|
||||
name: 'browser_hover',
|
||||
description: 'Hover over an element',
|
||||
description: 'Hover over an element using ref (@e1) or CSS selector',
|
||||
category: 'browser',
|
||||
tags: ['interaction'],
|
||||
inputSchema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
target: { type: 'string', description: 'Element ref or CSS selector' },
|
||||
target: { type: 'string', description: 'Element ref (@e1) or CSS selector' },
|
||||
session: { type: 'string', description: 'Session ID' },
|
||||
},
|
||||
required: ['target'],
|
||||
|
||||
@@ -471,7 +471,7 @@ export const embeddingsTools: MCPTool[] = [
|
||||
query,
|
||||
limit: topK,
|
||||
threshold,
|
||||
namespace: namespace || 'default'
|
||||
namespace: namespace || 'all'
|
||||
});
|
||||
|
||||
const searchTime = (performance.now() - startTime).toFixed(2);
|
||||
@@ -489,7 +489,7 @@ export const embeddingsTools: MCPTool[] = [
|
||||
model: config.model,
|
||||
topK,
|
||||
threshold,
|
||||
namespace: namespace || 'default',
|
||||
namespace: namespace || 'all',
|
||||
searchTime: `${searchTime}ms`,
|
||||
indexType: config.hyperbolic.enabled ? 'HNSW (hyperbolic)' : 'HNSW (euclidean)',
|
||||
resultCount: searchResult.results.length
|
||||
@@ -506,7 +506,7 @@ export const embeddingsTools: MCPTool[] = [
|
||||
model: config.model,
|
||||
topK,
|
||||
threshold,
|
||||
namespace: namespace || 'default',
|
||||
namespace: namespace || 'all',
|
||||
searchTime: `${searchTime}ms`,
|
||||
indexType: config.hyperbolic.enabled ? 'HNSW (hyperbolic)' : 'HNSW (euclidean)',
|
||||
},
|
||||
|
||||
@@ -1829,6 +1829,62 @@ export async function bridgeSemanticRoute(params: { input: string }): Promise<an
|
||||
} catch (e: any) { return { route: null, error: e.message }; }
|
||||
}
|
||||
|
||||
// ===== RaBitQ data export =====
|
||||
|
||||
/**
|
||||
* Export all embeddings from the bridge's better-sqlite3 connection.
|
||||
* Used by RaBitQ to build its index from the same data that memory_store writes.
|
||||
* Returns null if bridge is unavailable (caller falls back to sql.js).
|
||||
*/
|
||||
export async function bridgeGetAllEmbeddings(options?: {
|
||||
dimensions?: number;
|
||||
limit?: number;
|
||||
dbPath?: string;
|
||||
}): Promise<Array<{
|
||||
id: string;
|
||||
key: string;
|
||||
namespace: string;
|
||||
embedding: number[];
|
||||
}> | null> {
|
||||
const registry = await getRegistry(options?.dbPath);
|
||||
if (!registry) return null;
|
||||
|
||||
const ctx = getDb(registry);
|
||||
if (!ctx) return null;
|
||||
|
||||
try {
|
||||
const dims = options?.dimensions ?? 384;
|
||||
const maxRows = options?.limit ?? 50000;
|
||||
|
||||
const rows: any[] = ctx.db.prepare(`
|
||||
SELECT id, key, namespace, embedding
|
||||
FROM memory_entries
|
||||
WHERE status = 'active' AND embedding IS NOT NULL
|
||||
LIMIT ?
|
||||
`).all(maxRows);
|
||||
|
||||
const results: Array<{ id: string; key: string; namespace: string; embedding: number[] }> = [];
|
||||
|
||||
for (const row of rows) {
|
||||
if (!row.embedding) continue;
|
||||
try {
|
||||
const emb = JSON.parse(row.embedding) as number[];
|
||||
if (emb.length !== dims) continue;
|
||||
results.push({
|
||||
id: String(row.id),
|
||||
key: row.key || String(row.id),
|
||||
namespace: row.namespace || 'default',
|
||||
embedding: emb,
|
||||
});
|
||||
} catch { /* skip invalid */ }
|
||||
}
|
||||
|
||||
return results;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// ===== Utility =====
|
||||
|
||||
function cosineSim(a: number[], b: number[]): number {
|
||||
|
||||
@@ -95,45 +95,61 @@ export async function buildRabitqIndex(options?: {
|
||||
const swarmDir = path.resolve(process.cwd(), '.swarm');
|
||||
const dbPath = options?.dbPath ? path.resolve(options.dbPath) : path.join(swarmDir, 'memory.db');
|
||||
|
||||
if (!fs.existsSync(dbPath)) {
|
||||
rabitqInitializing = false;
|
||||
return { success: false, vectorCount: 0, dimensions, compressionRatio: 0, buildTimeMs: 0, error: 'Database not found' };
|
||||
}
|
||||
|
||||
// Load embeddings from SQLite
|
||||
const initSqlJs = (await import('sql.js')).default;
|
||||
const SQL = await initSqlJs();
|
||||
const fileBuffer = fs.readFileSync(dbPath);
|
||||
const db = new SQL.Database(fileBuffer);
|
||||
|
||||
const result = db.exec(`
|
||||
SELECT id, key, namespace, embedding
|
||||
FROM memory_entries
|
||||
WHERE status = 'active' AND embedding IS NOT NULL
|
||||
LIMIT 50000
|
||||
`);
|
||||
|
||||
const entries: RabitqEntry[] = [];
|
||||
const vectors: number[] = [];
|
||||
|
||||
if (result[0]?.values) {
|
||||
for (const row of result[0].values) {
|
||||
const [id, key, ns, embeddingJson] = row as [string, string, string, string];
|
||||
if (!embeddingJson) continue;
|
||||
// Try bridge first (reads via better-sqlite3, sees WAL data)
|
||||
let usedBridge = false;
|
||||
try {
|
||||
const { bridgeGetAllEmbeddings } = await import('./memory-bridge.js');
|
||||
const bridgeRows = await bridgeGetAllEmbeddings({ dimensions, dbPath: options?.dbPath });
|
||||
if (bridgeRows && bridgeRows.length > 0) {
|
||||
for (const row of bridgeRows) {
|
||||
entries.push({ id: row.id, key: row.key, namespace: row.namespace });
|
||||
vectors.push(...row.embedding);
|
||||
}
|
||||
usedBridge = true;
|
||||
}
|
||||
} catch { /* bridge unavailable, fall through */ }
|
||||
|
||||
try {
|
||||
const embedding = JSON.parse(embeddingJson) as number[];
|
||||
if (embedding.length !== dimensions) continue;
|
||||
// Fallback: read .swarm/memory.db via sql.js
|
||||
if (!usedBridge) {
|
||||
if (!fs.existsSync(dbPath)) {
|
||||
rabitqInitializing = false;
|
||||
return { success: false, vectorCount: 0, dimensions, compressionRatio: 0, buildTimeMs: 0, error: 'Database not found' };
|
||||
}
|
||||
|
||||
entries.push({ id: String(id), key: key || String(id), namespace: ns || 'default' });
|
||||
vectors.push(...embedding);
|
||||
} catch {
|
||||
// skip invalid
|
||||
const initSqlJs = (await import('sql.js')).default;
|
||||
const SQL = await initSqlJs();
|
||||
const fileBuffer = fs.readFileSync(dbPath);
|
||||
const db = new SQL.Database(fileBuffer);
|
||||
|
||||
const result = db.exec(`
|
||||
SELECT id, key, namespace, embedding
|
||||
FROM memory_entries
|
||||
WHERE status = 'active' AND embedding IS NOT NULL
|
||||
LIMIT 50000
|
||||
`);
|
||||
|
||||
if (result[0]?.values) {
|
||||
for (const row of result[0].values) {
|
||||
const [id, key, ns, embeddingJson] = row as [string, string, string, string];
|
||||
if (!embeddingJson) continue;
|
||||
|
||||
try {
|
||||
const embedding = JSON.parse(embeddingJson) as number[];
|
||||
if (embedding.length !== dimensions) continue;
|
||||
|
||||
entries.push({ id: String(id), key: key || String(id), namespace: ns || 'default' });
|
||||
vectors.push(...embedding);
|
||||
} catch {
|
||||
// skip invalid
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
db.close();
|
||||
db.close();
|
||||
}
|
||||
|
||||
if (entries.length < 2) {
|
||||
rabitqInitializing = false;
|
||||
|
||||
Reference in new issue
Block a user