Skip to content

fix: rewrite claudemd-generator — Task→Agent tool, add MCP discovery + hook signals#1512

Closed
sparkling wants to merge 165 commits intoruvnet:mainfrom
sparkling:fix/claudemd-task-to-agent
Closed

fix: rewrite claudemd-generator — Task→Agent tool, add MCP discovery + hook signals#1512
sparkling wants to merge 165 commits intoruvnet:mainfrom
sparkling:fix/claudemd-task-to-agent

Conversation

@sparkling
Copy link
Copy Markdown

@sparkling sparkling commented Apr 3, 2026

Issue

Fixes #1511

Summary

  • Fix 14 "Task tool" references → "Agent tool" (renamed in Claude Code v2.1.63)
  • Add MCP Tool Discovery section with ToolSearch bootstrap (200+ deferred tools)
  • Add Hook Signals section binding [INTELLIGENCE] and [INFO] to actions
  • Add Task Complexity gate (when to spawn agents vs work directly)
  • Add Feature Workflow checklist (TDD loop)
  • Add "When to Use What" decision tree (Agent / MCP / CLI / Skill)
  • Remove phantom signals ([AGENT_BOOSTER_AVAILABLE], [TASK_MODEL_RECOMMENDATION])
  • Remove Project Config sub-section (daemon runtime config, not actionable)
  • Standard template drops from ~250 lines to ~112 lines

Test plan

  • Run npx @claude-flow/cli init --wizard and verify generated CLAUDE.md uses "Agent tool" not "Task tool"
  • Verify no [AGENT_BOOSTER_AVAILABLE] or TodoWrite in any template output
  • Verify MCP Tools section includes ToolSearch discovery queries
  • Verify Hook Signals section has before/during/after lifecycle
  • Verify standard template is under 120 lines

Fixes #1511

🤖 Generated with claude-flow

sparkling and others added 30 commits March 13, 2026 22:17
CLI's in-memory-repositories.ts imported from ../../../swarm/ using
relative paths, violating tsc rootDir constraint and preventing all
dist/ output (0 JS files emitted for the entire CLI package).

Fix: copy the 4 swarm type files (agent, task, and their repository
interfaces) into cli/src/infrastructure/_swarm-types/ and rewrite
imports to use local paths.

Co-Authored-By: claude-flow <ruv@ruv.net>
6 packages fixed for full type-check (ADR-0028):

- codex: src/types/fs-extra.d.ts
- mcp: src/types/express.d.ts, src/types/cors.d.ts
- shared: src/types/express.d.ts + fix ZodError.errors -> .issues
- performance: src/types/ruvector-attention.d.ts (PascalCase classes + computeRaw)
- embeddings: src/types/agentic-flow-embeddings.d.ts (getNeuralSubstrate, downloadModel)
- testing: src/types/vitest.d.ts (vi, Mock, describe, it, expect)

Co-Authored-By: claude-flow <ruv@ruv.net>
SG-004: Fix CLI cross-package imports
TS-001: Add type declarations for untyped dependencies
MCP servers should auto-start by default. The autoStart: false default
prevented MCP tools from being available without manual intervention.

Fix: set default to true in types.ts, omit autoStart property from
.mcp.json output (absence = auto-start enabled).

Co-Authored-By: claude-flow <ruv@ruv.net>
MC-001: Remove autoStart: false from MCP config
Package is type: module so tsc emits .js, not .cjs.

Co-Authored-By: claude-flow <ruv@ruv.net>
GB-001: Fix gastown-bridge main field
Hash fallback embeddings produce similarity ~0.05-0.28 (not semantic).
The hardcoded 0.3 threshold filtered out 90% of results, causing silent
empty search results when ONNX is unavailable.

Fix: detect embedding model at runtime and apply appropriate threshold:
  - ONNX (MiniLM-L6): 0.3 (meaningful similarity scores)
  - Hash fallback: 0.05 (permissive, ranking is noise)

Changed files:
  - memory-initializer.ts: getAdaptiveThreshold() helper, searchEntries()
  - memory-bridge.ts: _getAdaptiveThreshold() with cached model detection,
    bridgeSearchEntries(), bridgeSemanticSearch(), bridgeSearchPatterns(),
    bridgeLoadSessionPatterns()

Co-Authored-By: claude-flow <ruv@ruv.net>
FB-004: Adaptive search threshold for hash vs ONNX embeddings
SG-004 copied 4 swarm entity files (agent.ts, task.ts, and their
repository interfaces) into CLI. These 833 lines would silently
drift when upstream changes swarm types.

Replace with swarm-interfaces.ts: 100 lines of minimal interfaces
matching only the properties CLI actually uses (id, name, status,
role, domain, getUtilization, etc). No drift risk — if swarm adds
new fields, they only need adding here when CLI needs them.

Co-Authored-By: claude-flow <ruv@ruv.net>
SG-004-v2: Replace copied swarm files with minimal interfaces
Vector indexes were hardcoded to 768-dim but ONNX MiniLM-L6 produces
384-dim embeddings. HNSW index could never be built — all searches
fell back to brute-force. Neural training was capped at 256-dim,
preventing neural patterns from sharing the memory index.

Fixes:
- vector_indexes schema: 768 → 384 (matches MiniLM-L6 output)
- reasoningbank/agentic-flow fallback dimensions: 768 → 384
- neural --dim max/default: 256 → 384 (same dimension as memory)

Result: all embedding paths produce 384-dim vectors that match the
HNSW index configuration. HNSW can now be built and used.

Co-Authored-By: claude-flow <ruv@ruv.net>
DM-001: Fix dimension mismatch — align all embeddings to 384
)

Supersedes PR #21 (which set 384-dim). The target machine has 32 cores
+ 187GB RAM — can easily run all-mpnet-base-v2 (110M params, ~5ms/embed).

Changes:
- ONNX model: all-MiniLM-L6-v2 (384-dim) → all-mpnet-base-v2 (768-dim)
- Vector indexes: 384 → 768 (now matches model output)
- Neural --dim: max/default 384 → 768 (shares same HNSW index)
- All dimension fallbacks aligned to 768
- MCP tools: default model updated, MiniLM kept as enum option

All embedding paths now produce 768-dim vectors matching the HNSW index.

Co-Authored-By: claude-flow <ruv@ruv.net>
ONNX embeddings never loaded on fresh installs because @xenova/transformers
was dynamically imported but not declared as a dependency. Every user got
128-dim hash fallback embeddings that couldn't be inserted into the
768-dim HNSW index.

Fixes:
- Add @xenova/transformers ^2.17.0 as optionalDependency
- Hash fallback dimensions: 128 → 768 (matches HNSW index)
- Optional because: ~100MB download, may fail on some platforms

With ONNX available: all-mpnet-base-v2 produces 768-dim semantic vectors.
Without ONNX: hash fallback produces 768-dim non-semantic vectors (same
dimension, HNSW works, but FB-004 adaptive threshold applies).

Co-Authored-By: claude-flow <ruv@ruv.net>
@ruvector/core provides VectorDb for persistent HNSW vector indexing
(150x-12,500x faster than brute-force). Was dynamically imported but
not declared as a dependency, so HNSW never initialized on fresh
installs.

Added as optionalDependency because: native WASM bindings may fail
on some platforms. Without it, search falls back to O(n) cosine
similarity (still functional, just slower).

Co-Authored-By: claude-flow <ruv@ruv.net>
…6, WM-108: Port 10 runtime patches to TypeScript source

- HW-001: Change stdin from 'pipe' to 'ignore' in headless spawn to prevent hang
- HW-002: Propagate non-zero exit codes from headless workers instead of swallowing
- HW-003: Reduce aggressive intervals (audit 30m, optimize 60m, testgaps 60m) + settings-driven config
- HW-004: Raise worker timeout from 5min to 16min (above max headless 15min)
- DM-001: Fix always-empty daemon.log by using ESM appendFileSync instead of require('fs')
- DM-002: Raise maxCpuLoad from 2.0 to 28.0 for multi-core servers
- DM-003: Skip freemem check on macOS where os.freemem() reports near-zero
- DM-004: Add missing worker types to defaults + real preload/consolidation implementations
- DM-006: Add log rotation (7-day/500-file cleanup) to headless executor
- WM-108: Reduce consolidation interval to 10min, add bridge consolidation + shutdownBridge on stop

Co-Authored-By: claude-flow <ruv@ruv.net>
Config get/export now reads .claude-flow/config.json from disk and merges
with defaults, instead of returning hardcoded values.

Co-Authored-By: claude-flow <ruv@ruv.net>
Adds checkMemoryBackend() to doctor command that checks native dependency
availability for configured memory backend, with --install auto-rebuild.

Co-Authored-By: claude-flow <ruv@ruv.net>
…l, remove v3Mode

CF-006: Replace YAML parser with config.json reader, check config.json for init.
SG-005: Add 'start all' subcommand for memory+daemon+swarm+MCP.
SG-009: Remove v3Mode from swarm_init call.

Co-Authored-By: claude-flow <ruv@ruv.net>
Co-Authored-By: claude-flow <ruv@ruv.net>
Replace all config.yaml references with config.json in isInitialized(),
display strings, and JSON output paths.

Co-Authored-By: claude-flow <ruv@ruv.net>
Remove --v3-mode option, v3Mode variable, and conditional blocks.
Default topology changed to hierarchical-mesh. Flash Attention/AgentDB/SONA
lines always shown. V3 Mode row removed from status table.

Co-Authored-By: claude-flow <ruv@ruv.net>
Co-Authored-By: claude-flow <ruv@ruv.net>
Patches applied:
- HK-002: fail-loud bridge errors in postEdit/postCommand/postTask (#18)
- HK-003: real metrics from sona-patterns/intelligence files (#19)
- HK-004: respect daemon.autoStart from settings.json (#20)
- HK-005: cross-process daemon PID-file guard (#21)
- NS-001: search/list default namespace 'default' → 'all' (#22)
- NS-002: require explicit namespace for store/delete/retrieve (#23)
- NS-003: fix 'pattern' → 'patterns' namespace typo (#24)
- WM-103: MetadataFilter + MMR diversity in search pipeline (#25)
- WM-104: CausalRecall integration in routing (#26)
- WM-105: MemoryGraph importance scoring in store/search (#27)
- WM-106: activate LearningBridge in intelligence_learn (#28)
- WM-107: fix falsy-OR quality bug, fake session ID/stats (#29)
- WM-114: wire AttentionService across 4 controllers (ruvnet#30)

Co-Authored-By: claude-flow <ruv@ruv.net>
EM-001: Read embedding model name and dimensions from .claude-flow/embeddings.json
instead of hardcoding all-mpnet-base-v2. Add forceRebuild support with stale file
cleanup and metadata/early-return guards.

GV-001: After SQLite soft-delete, remove entry from persisted hnsw.metadata.json
and in-memory HNSW map to prevent ghost vectors in search results.

WM-102d/e: Fix SQL schema vector_indexes dimensions from 768 to 384 to match
bridge dimension (ADR-073 Gap F).

Co-Authored-By: claude-flow <ruv@ruv.net>
…s exit

CacheManager cleanup timer and SqljsBackend persist timer now call .unref()
so Node.js can exit cleanly without waiting for timer expiry.

Co-Authored-By: claude-flow <ruv@ruv.net>
WM-102: Wire .claude-flow/config.json into ControllerRegistry init. Replaces
hardcoded learningBridge:false with config-driven values. Adds neural.enabled
gate to skip bridge init when explicitly disabled.

WM-111: Enable EnhancedEmbeddingService in controllers block.

WM-115: Instantiate WASMVectorSearch with JS fallback after registry init.
Expose wasmComputeSimilarity helper for cosine similarity with 4x loop unrolling.

Co-Authored-By: claude-flow <ruv@ruv.net>
WM-116a: Replace null placeholder with dynamic import of agent-memory-scope.js
and call to createAgentBridge factory.

WM-116b: Auto-enable agentMemoryScope when backend is available instead of
requiring explicit opt-in.

Co-Authored-By: claude-flow <ruv@ruv.net>
sparkling and others added 22 commits March 18, 2026 12:25
N1: causal-query — clear orphaned setTimeout in try/finally
N2: pattern-store — cascading diagnostic errors (registry/db/store)
N3: semantic-route — return success:false when unavailable
N4: attention_metrics — notice field on empty metrics
N5: hierarchical-recall — add success field + empty notice
N6: embed — handle Float32Array from EnhancedEmbeddingService.embed()
    (was treating typed array as {embedding,dimension,provider} object)

Co-Authored-By: claude-flow <ruv@ruv.net>
bridgeSemanticRoute returns {route:null, error:"..."} which bypasses
the ?? null check. Now explicitly checks for error/null route and
wraps with success:false so X2 exit-code propagation triggers.

Co-Authored-By: claude-flow <ruv@ruv.net>
Embedding dimension: align to 384 (all-MiniLM-L6-v2) across all paths
- Was mixed 384/768 causing dimension mismatches
- Removed hard reject of non-768 embeddings in bridgeGenerateEmbedding
- 9 files, ~25 dimension references aligned
- Model already on disk (quantized ONNX, 23MB)

Memory ceiling: 16GB → 96GB (was using 8.5% of available RAM)
Rate limits: 10x increase (insert 1000, search 10000, batch 100)
Batch concurrency: 10 → 24 (for 32 threads)

Co-Authored-By: claude-flow <ruv@ruv.net>
- Memory ceiling: 16GB → 96GB
- Rate limits: 10x (insert=1000, search=10000, batch=100)
- Embedding cache: 100K → 500K entries
- Batch concurrency: 10 → 24 (32 threads)
- Default model: mpnet → nomic-ai/nomic-embed-text-v1.5
- All dimension defaults: 384 → 768 (12 occurrences)
- bridgeGetHNSWStatus: reads actual dim from registry config

Co-Authored-By: claude-flow <ruv@ruv.net>
Memory ceiling: 96GB → 160GB (dedicated server, nothing else running)
Memory cacheSize: 100 → 2048 MB (OPT-003)
SONA mode: balanced → real-time (OPT-004, 32 idle threads)
memoryGraph maxNodes: 5000 → 50000 (OPT-005)
similarityThreshold: 0.8 → 0.65 (OPT-006)
tickInterval: 300000 → 15000 ms (OPT-008)

Co-Authored-By: claude-flow <ruv@ruv.net>
Replace $CLAUDE_PROJECT_DIR with $(git rev-parse --show-toplevel)
in all hook path generation. $CLAUDE_PROJECT_DIR is unreliable
when Claude Code spawns agents in git worktrees.

5 locations fixed: hookHandlerCmd, autoMemoryCmd,
generateStatusLineConfig, permissions allow, check-patches.sh

Co-Authored-By: claude-flow <ruv@ruv.net>
memory-bridge: reads dimension from agentdb.getEmbeddingConfig()
  instead of hardcoded 768
memory-initializer: getHNSWIndex + loadEmbeddingModel read from
  agentdb config first, fall back to embeddings.json
generateEmbedding: applies task prefixes via applyTaskPrefix()
  (nomic search_query:/search_document:)
searchEntries: passes intent:'query' for search embeddings
controller-registry: JSDoc updated — dimension is config-derived

Co-Authored-By: claude-flow <ruv@ruv.net>
1. controller-registry: pass model from getEmbeddingConfig() to
   EnhancedEmbeddingService (was missing, defaulted to MiniLM)
2. memory-bridge: read model name from config, not hardcoded mpnet
3. memory-initializer: fix Xenova prefix for org-prefixed models
   (nomic-ai/... was becoming Xenova/nomic-ai/...)
4. memory-bridge: dimension check reads from config, not hardcoded 768

Co-Authored-By: claude-flow <ruv@ruv.net>
Neural: curiosity, dqn, a2c, decision-transformer accept inputDim
  via RLConfig (4 files)
Swarm: queen-coordinator accepts embeddingDim in config
Plugins: sona-learning, intent-router, semantic-code-search,
  vector-utils, semantic-search, quantization (6 files)
Memory: learning-bridge accepts embeddingDim in config
Registry: cached embeddingDimension from getEmbeddingConfig()
Bridge: model name from config (not hardcoded mpnet)

Co-Authored-By: claude-flow <ruv@ruv.net>
MCP tools: hooks-tools (9 edits), neural-tools (4), embeddings-tools
CLI: embeddings, performance, ruvector/setup (13 SQL DDL changes)
Memory: ewc-consolidation, intelligence
Runtime: headless benchmark
Packages: rvf-embedding-service, embedding-service (10 fallbacks),
  guidance/retriever, ruvector moe-router + lora-adapter + flash-attention
Neural: ppo.ts bug fix (ignored config.inputDim), sona, reasoning-bank,
  pattern-learner, reasoningbank-adapter

Co-Authored-By: claude-flow <ruv@ruv.net>
8 constant files created, 22 consumers wired:
- neural (10 files): EMBEDDING_DIM replaces all ?? 768 fallbacks
- embeddings (2 files): DEFAULT_DIMENSIONS → EMBEDDING_DIM
- cli/ruvector (4 files): INPUT_DIM, OUTPUT_DIM → EMBEDDING_DIM
- cli/mcp-tools (2 files): param defaults → EMBEDDING_DIM
- swarm, guidance, hooks, memory (1 each): defaults → EMBEDDING_DIM

To change dimension: update 8 embedding-constants.ts files
(or wire them to agentdb getEmbeddingConfig() later).

Co-Authored-By: claude-flow <ruv@ruv.net>
11 files changed across 3 packages:

memory: controller-registry.ts — 8× || 768 → || EMBEDDING_DIM
cli: new embedding-constants.ts + 7 consumers wired
  - ewc-consolidation, intelligence, headless, performance,
    embeddings (command), embeddings-tools, executor (MODEL_DIMS map)
shared: defaults.ts + schema.ts — 1536 → 768

Zero remaining raw 768 fallbacks in production code.
tsc --noEmit passes (pre-existing eagerMaxLevel only).

Co-Authored-By: claude-flow <ruv@ruv.net>
All per-package constants now read dimension from agentdb config
at import time with fallback to 768. Changing embeddings.json
propagates to ALL consumers.

Co-Authored-By: claude-flow <ruv@ruv.net>
Runtime fallbacks in embeddings.ts, hooks.ts, init.ts now use
dynamic import('agentdb').getEmbeddingConfig() instead of hardcoded
model names. Static flag metadata (choices, labels) show nomic as
default for CLI help text.

executor.ts generates embeddings.json with nomic/768/transformers.
providers.ts shows nomic as primary embedding provider.

tsc clean, 541/541 tests pass.

Co-Authored-By: claude-flow <ruv@ruv.net>
Generated embeddings.json now gets model/dimension/provider from
agentdb config resolution chain, with hardcoded fallbacks only
when agentdb is unavailable. MODEL_DIMS map retained for explicit
model override backward compat.

Co-Authored-By: claude-flow <ruv@ruv.net>
8 runtime defaults → EMBEDDING_DIM (from embedding-constants.ts)
5 JSDoc comments updated to reference nomic/768

These were copy-pasted from OpenAI tutorials by the upstream author.
The project has never used OpenAI embeddings.

Co-Authored-By: claude-flow <ruv@ruv.net>
…ing-predict, experience-record)

Brings total from 36 to 41 MCP tools. All use existing backend
methods via bridge controller access pattern.

Fixes sparkling/ruflo-patch#13

Co-Authored-By: claude-flow <ruv@ruv.net>
skill-create → skill_create, skill-search → skill_search,
learner-run → learner_run, learning-predict → learning_predict,
experience-record → experience_record

Matches upstream agentdb MCP server naming (skill_create, skill_search).

Co-Authored-By: claude-flow <ruv@ruv.net>
14 hyphenated tool names → underscores to match upstream agentdb
MCP server convention. All 41 tools now use consistent naming:
agentdb_{feature}_{action} (e.g., agentdb_reflexion_store).

Co-Authored-By: claude-flow <ruv@ruv.net>
Key upstream changes:
- P0: daemon startup, ESM controller-registry, memory-bridge fixes
- P1: ReasoningBank, SQLite path, namespace, init hooks fixes
- Security: audit remediation, terminal_execute, agent results fixes
- feat: autopilot persistent completion (ADR-072), guidance MCP tools
- feat: 22 stub CLI commands implemented with real functionality
- fix: hive-mind real agent state, MCP self-kill prevention
- fix: CPU-proportional daemon maxCpuLoad, statusline generator
- fix: ESM/CJS interop, attention class wrappers, semantic routing

Co-Authored-By: claude-flow <ruv@ruv.net>
- config.ts: use getConfig() (getAll/flatten don't exist on ConfigFileManager)
- memory-initializer.ts: remove duplicate entryId declaration from merge
- optional-modules.d.ts: add forward_count/reset_scope to WasmScopedLoRA type
- controller-registry.ts: add eagerMaxLevel to RuntimeConfig (ADR-0048)

Co-Authored-By: claude-flow <ruv@ruv.net>
causalRecall had a factory (line 1155) but was never auto-initialized
because it was missing from the INIT_LEVELS array. Depends on causalGraph
(level 4) and explainableRecall (level 3), so level 4 is correct.

Co-Authored-By: claude-flow <ruv@ruv.net>
@sparkling
Copy link
Copy Markdown
Author

Fixes #1511

sparkling and others added 2 commits April 3, 2026 22:49
…+ hook signals

claudemd-generator.ts generated CLAUDE.md files referencing a "Task tool"
that was renamed to "Agent" in Claude Code v2.1.63 (anthropics/claude-code#29677).
14 occurrences across 5 functions produced instructions for a nonexistent tool.

Changes:
- Replace swarmOrchestration() with agentOrchestration() — correct tool names
- Rewrite concurrencyRules() — "Agent tool", remove TodoWrite reference
- Add mcpToolDiscovery() — ToolSearch bootstrap for 200+ deferred MCP tools
- Add hookSignals() — bind [INTELLIGENCE] and [INFO] to concrete actions
- Add whenToUseWhat() — 5-row decision tree (Agent/MCP/CLI/Skill)
- Rewrite setupAndBoundary() — remove dead "Task tool" boundary rules
- Rewire all 6 template compositions — standard drops from ~250 to ~90 lines

Fixes sparkling/ruflo-patch#92
Upstream refs: ruvnet#1497, ruvnet#1476, ruvnet#1413

Co-Authored-By: claude-flow <ruv@ruv.net>
…ve Project Config

Additions from cross-repo CLAUDE.md analysis (ruflo, agentic-flow, ruvector):

- Add Task Complexity section: when to spawn agents vs work directly
- Add Feature Workflow checklist (TDD loop): test → implement → verify → commit
- Add single-test run command to Build & Test block
- Rewrite Hook Signals with before/during/after lifecycle structure
- Remove Project Config sub-section (topology/HNSW/neural) — this is daemon
  runtime config, not actionable Claude instructions
- Rename projectArchitecture param to _options (no longer consumed)

Follows up on sparkling/ruflo-patch#92 (CM-001)

Co-Authored-By: claude-flow <ruv@ruv.net>
@ruvnet
Copy link
Copy Markdown
Owner

ruvnet commented Apr 7, 2026

Closing: too stale to merge (130+ files, conflicts). Fixes applied directly to main in upcoming commit.

@ruvnet ruvnet closed this Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: claudemd-generator.ts references "Task tool" (renamed to "Agent" in Claude Code v2.1.63), missing ToolSearch/hook signal guidance

2 participants