Files
ruflo/v3/plugins/hyperbolic-reasoning
Dragan Spiridonov b6f3988de7 fix(ruflo-mods): classify risky host calls and intercepting hooks (#3802)
* fix(ruflo-mods): trust gate also treats the agent.spawn, prompt.submit, tool.call, command.run, session.append and agent.register calls and the tool.describe and session.append hooks as risky (#3787, #3801)

Adversarial review of the previous commit: risk was checked per scanned
`calls` and `events` separately, and only the events side had agent.spawn
and prompt.submit, so a mod CALLING $.agent.spawn / $.prompt.submit /
$.tool.call still loaded under refuse-risky ("no risky calls or hooks").
session.append and agent.register, and the tool.describe and
session.append hooks (rewriting what the model reads).

Docs follow the code: README hardening note lists the first-party mods that
now need modTrustAllow under refuse-risky (agentdb, ruos, intelligence,
graph-intelligence, goals, iot-cognitum beside swarm and console), the
modTrust row and plugin.json description name the categories, and the
create-mod skill's list matches.

* fix(ruflo-mods): trust gate judges a glob or negation by what it selects; covers prompt sections/context, peer receive, model requests (#3801)

Re-review: the scan reports hook patterns as written, and riskOf matched
names exactly, so `on('tool.*')` or `on('!tool.describe')` loaded under
refuse-risky with "no risky calls or hooks" and could answer tool
permission verdicts (shown: tool.check returned allow). A glob now maps to
every risky event it selects, a negation to `*`, and any classic.* pattern
to the classic risk. Lookups use Object.hasOwn.

Same-category hooks added: prompt.section, prompt.context,
prompt.attachment, skill.prompt, session.receive, turn.step, and hooks on
process.run / http.fetch / mcp.call (they can answer other mods' calls).

Docs: every first-party mod with function hooks (43 of 43) is risky under
the gate's sets, so the README now says to allow-list each ruflo mod you
use under refuse-risky and points to `claude plugin validate`.

* fix(ruflo-mods): a hook on a risky call is a risky hook (fs.write, env.set, process.spawn, ...) (#3801)

Third review: every $ call is also an event a hook above the caller can
rewrite or answer for every other mod. Under refuse-risky a mod hooking only
fs.write loaded clean and redirected ruflo-mods' own heartbeat write to
.claude/settings.json; one hooking env.set rewrote RUFLO_MODS_OWNS; one on
process.spawn rewrote an allow-listed mod's argv; fs.* loaded too.

Hook risk is now derived: every RISKY_CALLS entry is also a risky event
("can rewrite or answer another mod's <call>"), on top of RISKY_EVENTS
(+ tool.register). Globs match against the union. Tests: fs.write, env.set
and fs.* refused (each fails on the previous head); the harmless-glob
control is clock.*, since command.run is a risky call. README and the
create-mod skill say so.

* fix(ruflo-mods): trust gate treats hooks that forge what other mods read, or replace the conversation, as risky (#3801)

Fourth review: a mod hooking only fs.stat (answer ENOENT for the policy
projection) or fs.read (return an empty observe projection) loaded under
refuse-risky and turned ruflo's own enforced deny into allow; one hooking
session.compact replaced the whole conversation. Added fs.read, fs.stat,
fs.exists, fs.list, settings.read, env.get, session.compact, prompt.edit
and attribution.text to the risky hooks; three tests (each fails on the
previous head). README states the gate is a list over the 2.1.289 engine
API, so an event added later is not judged until listed.

* fix(ruflo-mods): session.root, session.cwd, fs.ancestors and command.register hooks are risky; docs name ruflo-ruos (#3801)

Fifth review: a mod hooking only session.root moved ruflo-mods' project
root, so the enforced policy projection was read from elsewhere and a deny
became allow (the round-4 exploit through another input). Added those
inputs and command.register (consistent with tool.register), with a
root-forger test (fails on the previous head). Derived messages read
"another mod's fs.write, which writes files ..." instead of nesting
parentheses.

Docs: ruflo-ruos hooks only prompt.submit, so it is newly risky under
refuse-risky (#3787); README and PR body said every first-party mod was
already risky via a status file or tool.call, which was false for it.

* test(router): seed Thompson sampler convergence trajectory

* ci: retain one plugin smoke execution and its report

* Register smoke workflow test with its dedicated Node runner

* Prevent same-millisecond hierarchy embedding index collisions
2026-10-19 21:48:15 -04:00
..

@claude-flow/plugin-hyperbolic-reasoning

npm version license downloads

An exotic reasoning plugin implementing hyperbolic neural networks for superior hierarchical understanding. The plugin enables efficient representation of tree structures, taxonomic reasoning, and hierarchical entailment using Poincare ball embeddings with Mobius operations. Applications include improved ontology navigation, hierarchical code understanding, and organizational relationship modeling.

Installation

npm

npm install @claude-flow/plugin-hyperbolic-reasoning

CLI

npx claude-flow plugins install --name @claude-flow/plugin-hyperbolic-reasoning

Quick Start

import { HyperbolicReasoningPlugin } from '@claude-flow/plugin-hyperbolic-reasoning';

// Initialize the plugin
const plugin = new HyperbolicReasoningPlugin();
await plugin.initialize();

// Embed a file system hierarchy in hyperbolic space
const embedding = await plugin.embedHierarchy({
  hierarchy: {
    nodes: [
      { id: 'src', parent: null, features: { type: 'directory' } },
      { id: 'src/components', parent: 'src', features: { type: 'directory' } },
      { id: 'src/components/Button.tsx', parent: 'src/components', features: { type: 'file' } },
      { id: 'src/components/Modal.tsx', parent: 'src/components', features: { type: 'file' } },
      { id: 'src/utils', parent: 'src', features: { type: 'directory' } }
    ]
  },
  model: 'poincare_ball',
  parameters: {
    dimensions: 32,
    curvature: -1.0,
    learnCurvature: true
  }
});

console.log('Hierarchy embedded in hyperbolic space');

Available MCP Tools

1. hyperbolic/embed-hierarchy

Embed hierarchical data in hyperbolic space (Poincare ball).

const result = await mcp.call('hyperbolic/embed-hierarchy', {
  hierarchy: {
    nodes: [
      { id: 'Animal', parent: null, features: {} },
      { id: 'Mammal', parent: 'Animal', features: {} },
      { id: 'Dog', parent: 'Mammal', features: {} },
      { id: 'Cat', parent: 'Mammal', features: {} },
      { id: 'Bird', parent: 'Animal', features: {} }
    ],
    edges: []
  },
  model: 'poincare_ball',
  parameters: {
    dimensions: 32,
    curvature: -1.0,
    learnCurvature: true
  }
});

Models: poincare_ball, lorentz, klein, half_plane

Returns: Hyperbolic embeddings with learned curvature and embedding quality metrics.

2. hyperbolic/taxonomic-reason

Perform taxonomic reasoning using hyperbolic entailment.

const result = await mcp.call('hyperbolic/taxonomic-reason', {
  query: {
    type: 'is_a',
    subject: 'Dog',
    object: 'Mammal'
  },
  taxonomy: 'animal-taxonomy',
  inference: {
    transitive: true,
    fuzzy: false,
    confidence: 0.8
  }
});

Query Types: is_a, subsumption, lowest_common_ancestor, path, similarity

Returns: Reasoning result with confidence score and inference path.

Hierarchically-aware semantic search in hyperbolic space.

const result = await mcp.call('hyperbolic/semantic-search', {
  query: 'authentication middleware',
  index: 'codebase-hierarchy',
  searchMode: 'subtree',
  constraints: {
    maxDepth: 5,
    minDepth: 0,
    subtreeRoot: 'src/middleware'
  },
  topK: 10
});

Search Modes: nearest, subtree, ancestors, siblings, cone

Returns: Ranked results with hierarchical context and similarity scores.

4. hyperbolic/hierarchy-compare

Compare hierarchical structures using hyperbolic alignment.

const result = await mcp.call('hyperbolic/hierarchy-compare', {
  source: sourceHierarchy,
  target: targetHierarchy,
  alignment: 'gromov_wasserstein',
  metrics: ['structural_similarity', 'semantic_similarity', 'coverage']
});

Alignments: wasserstein, gromov_wasserstein, tree_edit, subtree_isomorphism

Returns: Alignment mapping with similarity metrics and structural correspondences.

5. hyperbolic/entailment-graph

Build and query entailment graphs using hyperbolic embeddings.

const result = await mcp.call('hyperbolic/entailment-graph', {
  action: 'build',
  concepts: [
    { id: 'error', text: 'An error occurred', type: 'event' },
    { id: 'network_error', text: 'Network connection failed', type: 'event' },
    { id: 'timeout', text: 'Request timed out', type: 'event' }
  ],
  entailmentThreshold: 0.7,
  transitiveClosure: true,
  pruneStrategy: 'transitive_reduction'
});

Actions: build, query, expand, prune

Returns: Entailment graph with directed edges indicating semantic entailment relationships.

Configuration Options

interface HyperbolicReasoningConfig {
  // Maximum nodes in hierarchy (default: 1000000)
  maxNodes: number;

  // Maximum edges (default: 10000000)
  maxEdges: number;

  // Embedding dimensions (default: 32)
  dimensions: number;

  // Default curvature (default: -1.0)
  curvature: number;

  // Memory limit in bytes (default: 2GB)
  memoryLimit: number;

  // CPU time limit for embedding (default: 300s)
  embeddingTimeout: number;

  // Numerical stability epsilon (default: 1e-10)
  boundaryEpsilon: number;
}

Hyperbolic Geometry Benefits

Property Euclidean Hyperbolic
Tree capacity O(n^d) O(exp(d))
Hierarchy distortion High Low
Dimensions needed Many Few
Parent-child relationship No natural representation Radial distance
Sibling relationship No natural representation Angular distance

Dimension Efficiency: 32-dim hyperbolic embeddings match the quality of 512-dim Euclidean embeddings for hierarchical data (16x memory reduction).

Performance Targets

Metric Target Improvement vs Euclidean
Embedding (10K nodes) <10s 3x faster
Hyperbolic search (1M embeddings) <5ms 10x faster
Taxonomic query <10ms 10x faster than graph traversal
Hierarchy comparison (10K nodes) <1s 30x faster than tree edit distance
Entailment graph (100K concepts) <30s 20x faster than pairwise
Memory efficiency 32-dim 16x less than 512-dim Euclidean

Security Considerations

  • Numerical Stability: Vectors are clipped to stay within Poincare ball boundary (1 - epsilon)
  • Input Validation: All inputs validated with Zod schemas; hierarchies validated for cycles, excessive depth (max 100), and excessive branching
  • Output Validation: All hyperbolic outputs validated for numerical sanity (finite values, within ball)
  • DoS Prevention: Limits on node count (1M), edge count (10M), and embedding timeout (300s)
  • Curvature Bounds: Curvature restricted to range [-10, -0.01] to prevent numerical issues
  • Cycle Detection: DAG validation prevents infinite loops in hierarchy traversal

WASM Security Constraints

Constraint Value Rationale
Memory Limit 2GB max Handle large hierarchies
CPU Time Limit 300 seconds Allow complex embedding operations
No Network Access Enforced Prevent data exfiltration
Numerical Epsilon 1e-10 Prevent boundary violations
Output Validation All vectors checked Ensure numerical stability

Input Limits

Constraint Limit
Max nodes 1,000,000
Max edges 10,000,000
Max dimensions 512
Max hierarchy depth 100
Max branching factor 10,000
CPU time for embedding 300 seconds
Memory limit 2GB

Rate Limits

Tool Requests/Minute Max Concurrent
embed-hierarchy 5 1
taxonomic-reason 60 5
semantic-search 60 5
hierarchy-compare 10 2
entailment-graph 10 2

Dependencies

  • ruvector-hyperbolic-hnsw-wasm - Hyperbolic nearest neighbor search
  • ruvector-attention-wasm - Hyperbolic attention mechanisms
  • ruvector-gnn-wasm - Hyperbolic graph neural networks
  • micro-hnsw-wasm - Tangent space approximation search
  • sona - Adaptive curvature learning

Mobius Operations

The plugin implements core Mobius operations for the Poincare ball:

// Mobius addition: x + y in hyperbolic space
mobius_add(x: Vector, y: Vector, c: number): Vector

// Mobius scalar multiplication
mobius_scalar(r: number, x: Vector, c: number): Vector

// Exponential map: tangent space -> hyperbolic
exp_map(v: Vector, c: number): Vector

// Logarithmic map: hyperbolic -> tangent space
log_map(x: Vector, c: number): Vector

// Hyperbolic distance
hyperbolic_distance(x: Vector, y: Vector, c: number): number

Curvature Learning

The plugin supports learning optimal curvature per hierarchy:

Hierarchy Type Typical Curvature
Flat hierarchy (organization chart) Low curvature (-0.1)
Deep hierarchy (taxonomy) High curvature (-2.0)
Mixed hierarchy Adaptive via SONA

Use Cases

  1. Ontology Navigation: Efficiently traverse and query large knowledge graphs
  2. Code Hierarchy Understanding: Model inheritance, module structure, and dependencies
  3. Organizational Analysis: Understand reporting structures and influence networks
  4. Taxonomic Classification: Improved classification with hierarchical awareness
  5. Concept Entailment: Determine semantic relationships between concepts
Plugin Description Synergy
@claude-flow/plugin-neural-coordination Multi-agent coordination Hierarchical embeddings enable efficient agent organization structures
@claude-flow/plugin-cognitive-kernel Cognitive augmentation Hyperbolic memory organization for improved episodic retrieval
@claude-flow/plugin-quantum-optimizer Quantum-inspired optimization Optimizes hierarchical constraint satisfaction and tree operations

License

MIT