Commit Graph

187 Commits

Author SHA1 Message Date
rUv 13880e3aa4 fix(memory,daemon): stop destroying a user index, honour autoStart:false, and finish the sibling disclosure (#3282)
Three from the current issue backlog, all confirmed in source before touching
anything, and all with a test that fails without the fix.

#3224 — curateIndex() rebuilt MEMORY.md from the bridge's own topic files and
overwrote whatever was there. The #1556 guard only skips the write when NOTHING
matched, but the bridge writes the first topic file itself, so after the first
insight the guard stops applying and the rebuild replaces a hand-maintained index
with a stub: 75 curated lines and 49 links down to 6 in the reported case. The
bridge only knows its own topic files, so everything else looks like nothing to
it. A curate may now grow or reorder the index and never shrink it; when the
generated view is smaller it is written beside the file as MEMORY.generated.md
and the bridge emits index:preserved rather than going quiet.

#3278 — the autostart disable check read claude-flow.config.json with the key
daemon.autostart, while init generates .claude/settings.json with
claudeFlow.daemon.autoStart. A different file AND a different capital S, so the
one setting a fresh project actually ships was never consulted. It is written
false under the comment "Opt-in only — prevents unintended token consumption
(#1427, #1330)", which the runtime then ignored. Both files and both spellings
are now read: someone who wrote autostart false anywhere sensible meant it.

#3228 (half) — 3.41.1 disclosed the sibling AgentDB store from `memory list`
only. retrieve, search and an empty list kept returning a clean negative while
the rows sat in the file this interface does not read; the reported Windows
install has 31,673 rows in that other store answering found:false. A confident
negative is worse than an error, because nothing prompts anyone to look further.
That was a gap in my own fix, not a new defect.

Verified the tests are worth having by reverting each fix and re-running: #3224
fails 1/2, #3278 fails 2/4, and all six pass again restored.


Claude-Session: https://claude.ai/code/session_013u4pmL9ZUAXb6usVQgNo67
2026-09-10 19:16:14 +00:00
rUv 277c7bc03a dream(memory): #3168 wire embedding-cosine into SmartRetrieval's MMR step (evaluated, ACCEPT) (#3169)
* dream(memory): wire embedding-cosine into SmartRetrieval's MMR step (evaluated, ACCEPT)

smart-retrieval.ts's MMR diversity re-ranking used token-Jaccard text
overlap as its "similarity to already-selected" term, even though
memory-initializer.ts's searchEntries() already computes real
ONNX-embedding cosine similarity for the primary relevance score and
discards it before returning. 2025-2026 production practice (LangChain's
reference maximal_marginal_relevance, Qdrant's native Mmr query shipped
Sept 2025, Weaviate's MMR reranker shipped in 1.37) universally uses
embedding-cosine for this term; token overlap misses low-token-overlap
paraphrases embeddings correctly flag as near-duplicates.

Threads the embedding through: searchEntries()'s two live compute sites
(RaBitQ rerank, brute-force SQL) now return it instead of discarding it;
the two CLI/MCP bridge mappers (memory-tools.ts, commands/memory.ts) pass
it through; SearchCandidate gains an optional `embedding` field;
mmrRerank uses cosine when both candidates have one, falling back to
token-Jaccard otherwise (existing callers/tests without embeddings are
unaffected). controller-registry.ts's separate toCands()/applyMMR path
had the same gap for a different reason (embedding available on
r.entry.embedding but never copied) — fixed the same way.

Evaluated via deterministic Vitest, zero LLM calls, $0 cost. New
discriminating test: a low-token-overlap paraphrase (near-1.0 cosine to
the seed) vs. a genuinely different topic (near-0 cosine). Baseline
(git stash-isolated): picks the paraphrase second (Jaccard can't tell
"low overlap because paraphrase" from "low overlap because unrelated").
Candidate: correctly picks the different topic second. Full
@claude-flow/memory suite: 460/461 passing identically with/without the
candidate (1 pre-existing chmod-based environmental failure, same class
documented since 2026-08-15). tsc --noEmit: zero new errors (verified
@claude-flow/cli's 455 pre-existing errors, from unbuilt workspace
packages, are identical with and without this diff).

Darwin: skipped, scope mismatch (correctness/similarity-metric fix with
a discriminating unit test, not a continuous parameter with a
gold-labeled corpus).

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01Qho5K4p5ACBt4yzCWjkBGe

* dream(memory): address review remediation — split CI, real benchmark, hardening

Response to ruvnet's REJECT review on #3169:

1. Split — dream-cycle-backlog-guard.yml moved out to #3205; this branch
   now carries only the MMR fix, rebased onto main (which already
   includes the merged #3203 CI fix).

2. Real benchmark (new src/mmr-benchmark.test.ts): 18-doc/6-topic labeled
   corpus (1 canonical + 2 low-token-overlap paraphrases per topic), run
   through the actual smartSearch/mmrRerank code, swept across mmrLambda
   in {0.3, 0.5, 0.7, 0.9} rather than one favorable value. Honest
   finding: at diversity-heavy lambda, candidate's recall/nDCG drop
   sharply vs. baseline, because cosine correctly suppresses same-topic
   near-duplicates that Jaccard fails to detect at all (and so
   "accidentally" keeps full recall). At smart-retrieval.ts's own default
   (lambda=0.7), recall@6/nDCG@6 are identical to baseline (1.000/0.777
   both) while topic-diversity improves 0.472->0.667 and ground-truth
   duplicate-rate drops 0.289->0.200. Reports latency (sub-ms both paths
   at this corpus size) and a memory-overhead estimate.

3. Malformed/dimension-mismatch: found and fixed a real bug while writing
   these cases. A NaN/Infinity-poisoned embedding component reached
   cosineSimilarity unguarded; the poisoned NaN score meant `mmr > bestMmr`
   was never true (NaN comparisons are always false in JS), which could
   silently break MMR's selection loop and under-fill results below the
   requested limit. Added isWellFormedEmbedding() so malformed/empty
   embeddings fall back to token-Jaccard, same as absent/mismatched ones.
   3 new cases (NaN/Infinity, empty array, explicit dimension-mismatch)
   plus a test mirroring the two real CLI/MCP output whitelists
   (memory-tools.ts:559-569, commands/memory.ts:633-639) to assert
   `embedding` cannot appear in either shape.

4. Determinism: new test runs the same input through smartSearch 5 times
   concurrently, asserts byte-identical result ordering every time,
   including a genuine same-embedding tie.

Full @claude-flow/memory suite: 465/466 (1 pre-existing, unrelated
environmental failure). tsc --noEmit: zero errors.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01Qho5K4p5ACBt4yzCWjkBGe

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-09-05 11:57:23 -04:00
ruv 127a6546c4 chore(release): 3.38.17 -> 3.38.18, @claude-flow/memory 3.0.0-alpha.22 -> alpha.23
3.38.17 was published by a concurrent session mid-race with a stale
package.json (the @claude-flow/mcp pin had been reverted to the broken
3.0.0-alpha.10 by a background helper-refresh process just before publish;
see #3005). npm forbids republishing over an existing version, so cutting
3.38.18 with the verified-correct pin instead of trying to fix 3.38.17.

Also discovered @claude-flow/memory is NOT in @claude-flow/cli's
bundleDependencies (unlike @claude-flow/mcp/codex/security/plugin-agent-federation)
-- it's resolved from the registry via a normal ^3.0.0-alpha.22 semver range,
and that exact version is what's currently published, without the #2977 fix
from 8a8500194. Bumping @claude-flow/memory to 3.0.0-alpha.23 and re-pinning
@claude-flow/cli to ^3.0.0-alpha.23 so the fix actually reaches users --
otherwise 3.38.18 would ship pointing at an unfixed memory dependency.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_018ZkgSrVRWNMcXmaFiMZ7Z8
2026-08-22 12:27:01 -04:00
ruv 8a85001942 fix: Windows CI build, dead agentdb controller exports, memory driver doctor check
- #2992: pin windows-latest -> windows-2022 for the Build V3 matrix job.
  windows-latest moved to VS2026, which node-gyp can't detect, breaking
  native builds for hnswlib-node and better-sqlite3.
- #2977: remove dead agentdb import attempts in controller-registry.ts for
  8 exports no installable agentdb range provides. Promote the working
  tieredMemoryFallback/createConsolidationStub implementations to
  first-class for hierarchicalMemory/memoryConsolidation; the other 6
  controllers (semanticRouter, mutationGuard, attestationLog, gnnService,
  rvfOptimizer, guardedVectorBackend) have no fallback and now return null
  directly instead of attempting an import that never resolves. The
  consolidation stub now reports source:'stub' and an explicit note so
  agentdb_consolidate reads as "did not run" rather than "nothing to do".
- #2968: add a read-only doctor check (checkMemoryPersistenceDriver) that
  reports whether the active SQLite driver is native better-sqlite3
  (durable, WAL-capable) or the sql.js fallback (silently drops
  wal_checkpoint writes), using the table-count signal from the issue
  (~47 native vs ~10 fallback). Warns, never fails; does not touch install
  behavior.

#2990 (MCP HTTP transport protocolVersion/tools-list/IPv6 bind) required
no code change — all three fixes are already present on main; the bug in
published ruflo/@claude-flow/cli only persists because no release has been
cut since they landed.

#3002 (ruvocal hidden-tab stream freeze) also required no code change —
already fixed on main.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_018ZkgSrVRWNMcXmaFiMZ7Z8
2026-08-22 12:14:24 -04:00
rUv 41efca8be3 dream(memory): #3056 hybridSearch reachable via explicit opt-in (evaluated, ACCEPT-scoped) (#3057)
* dream(memory): #3056 hybridSearch reachable via explicit opt-in without memoryService

The ADR-125 Phase 5 three-arm (dense+sparse+entity) RRF/MMR fusion
controller was fully built and tested but unreachable from any
production call site: its explicit-enable config override worked at
the isControllerEnabled() gate but the createController() factory
still unconditionally required a hand-built UnifiedMemoryService,
silently returning null otherwise. Falls back to the existing
this.backend when it type-guards as AgentDBAdapter-compatible,
reachable only via explicit controllers: { hybridSearch: true } --
default auto-enable behavior is unchanged.

New deterministic $0 benchmark quantifies the feature's actual
retrieval-quality effect for the first time (previously only
functional/unit tests existed): +0.267 aggregate recall@10, with a
disclosed, statistically significant regression on pure-paraphrase
queries where fusion noise dilutes an already-perfect dense signal.

Independent adversarial critic (fresh subagent): CONFIRMED-SAFE,
reproduced bit-for-bit. 75/75 tests passing in touched files, 458/459
in the full package (1 pre-existing environmental failure, unrelated).

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_016T1JRz8NBeGGmxQJVPReWa

* dream(memory): #3056 update ledger with 2026-08-14..18 nights + PR #3057

Reconstructs the v2 live-entries table from PR/issue history since each
night's own LEDGER.md edit lives only on its unmerged branch and never
reaches main (0% merge rate). Adds tonight's row (memory, hybridSearch
reachability fix, ACCEPT scoped, witness b28714fb...).

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_016T1JRz8NBeGGmxQJVPReWa

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-08-21 11:20:17 -04:00
ruv efd0406e7a chore: sync committed versions to already-published 3.36.0 / memory@alpha.22
@claude-flow/cli, claude-flow, and ruflo were published at 3.36.0 (and
@claude-flow/memory at 3.0.0-alpha.22, carrying the #2887 durability fix)
without the version bump landing back in git — this just reconciles the
committed package.json versions with what's actually live on npm, and bumps
the cli's @claude-flow/memory floor to the version that has the fix.

No code changes.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-08-11 08:56:05 -04:00
rUv 1d365d4a65 fix: silent memory-write loss + daemon lock cwd bypass (#2887, #2878, #2877) (#2966)
Three independent data-integrity/correctness bugs in the memory and daemon
subsystems:

#2887 — agentdb_hierarchical-store reported success:true for writes that
were never persisted. Root cause: agentdb dropped its HierarchicalMemory
export at 3.0.0-alpha.17, so every call was silently landing on an
in-process-only TieredMemoryStore fallback. The fallback now writes through
to a `tiered_memory` SQLite table when given a db handle, and the bridge
refuses to report success for a write that isn't durable — it names the
fallback controller and reason instead. agentdb_health now reports the real
persisted row count so a claimed write vs. an empty table is visible.

#2878 — concurrent sql.js writers lost updates while reporting success
(measured 10/12 lost in a 12-way concurrent repro), because storeEntry,
getEntry, deleteEntry, applyTemporalDecay, and ensureSchemaColumns did
unlocked whole-image read-modify-write against memory.db. All five now run
under the existing withMemoryDbLock primitive (previously only used by
purgeNamespace). Made the lock reentrant via AsyncLocalStorage, since every
mutator calls ensureSchemaColumns internally and a plain O_EXCL lock isn't
reentrant. Also fixed a path-normalization bug where different callers
spelled the same db path differently and so serialized against nothing.

#2877 — the daemon lock/PID file was keyed to raw process.cwd(), so
`daemon start` from a project subdirectory span its own lock/PID pair
instead of contending with one from the project root, bypassing the
#2407/#2484 dedup. Added resolveDaemonProjectRoot(), which walks up from
cwd to the nearest directory carrying a real Ruflo marker (not just any
package.json, so independently-initialized nested sub-projects in a
monorepo keep their own daemon), stopping at a .git boundary so the walk
can't escape into an unrelated ancestor project. Wired into every daemon
command that previously used process.cwd() directly.

Tests: 123 passing across affected suites (controller-registry.test.ts,
tiered-memory.test.ts, hierarchical-store-durability-2887.test.ts,
memory-concurrent-write-loss-2878.test.ts, daemon-autostart.test.ts).
Both packages typecheck clean. Pre-existing failures in unrelated suites
(ruvector wasm bindings, agenticow, memory-search-recall-2558) reproduce
identically with these changes reverted — confirmed not regressions.

Fixes #2887, #2878, #2877
2026-08-11 10:15:42 -02:30
rUv f074987ea0 feat(security): implement ADR-377 — AgentDB Retrieval Security Layer (#2874)
Implements all 3 phases of ADR-377 (ruvnet/ruflo#2516, tracked in #2873):
AgentDB's retrieval and write paths had zero certified defenses against
memory poisoning — SMSR (arXiv:2606.12703) shows 93-100% undefended attack
success. All three phases are off by default; enabling each is opt-in via
env flag until independently benchmarked, per the ADR's own gate criteria.

Phase 1 — AgentDbRetrievalGuard (@claude-flow/memory)
- New `agentdb-retrieval-guard.ts`, wired into `AgentDBBackend.search()`
  (covers `query()`'s semantic path too, since it calls `search()`
  internally). Reuses `@claude-flow/security`'s `ToolOutputGuardrail`
  (ADR-131) for the actual OWASP LLM01/LLM08 pattern scan rather than
  duplicating it — `@claude-flow/memory` now depends on
  `@claude-flow/security` (no cycle: security has zero workspace deps).
- Size gate + guardrail scan per retrieved chunk. Flag-only by default;
  `CLAUDE_FLOW_RETRIEVAL_GUARD_STRICT=true` drops unsafe/oversized chunks
  instead of just annotating them. Both flags off by default
  (`CLAUDE_FLOW_RETRIEVAL_GUARD=true` to enable scanning at all).

Phase 2 — MemoryPoisonForensics (@claude-flow/hooks)
- New `workers/memory-poison-forensics.ts`: rolling-window z-score anomaly
  detection on write-interval and content-length features per
  (agentId, namespace), reproducing the Forensic Trajectory Signatures
  (arXiv:2606.30566) shape (behavioral features on write *sequences*, not
  content). Opt-in `HookEvent.PostToolUse` handler for memory-write tools;
  `CLAUDE_FLOW_POISON_FORENSICS=0` disables recording.
- NOT wired into any of this repo's three separate "worker" dispatch
  systems (hooks' own workers/index.ts codebase-analyzers,
  @claude-flow/swarm's worker-dispatch.ts 12-trigger table, or the CLI's
  scheduled daemon) — @claude-flow/swarm is a deliberately
  zero-workspace-dependency package and adding hooks there would break
  that property; picking the wrong one of three ambiguous dispatch tables
  seemed worse than leaving that integration as an explicit follow-up.
  See the file header for detail.

Phase 3 — McpCallerIdentity (@claude-flow/security)
- New `mcp-caller-identity.ts`: per-invocation Ed25519-signed capability
  tokens (callerId + toolName + nonce + 30s TTL by default), native
  node:crypto sign/verify following the same pattern already used by
  `@claude-flow/browser`'s witness-signer.ts (reimplemented rather than
  cross-imported — a security-primitives module depending on the browser
  package would be a backwards layering dependency).
- Standalone issue/verify API; deliberately NOT wired into
  `AgentAuthorizationPropagator.checkToolCall` (ADR-144) or any tool
  dispatcher — this repo has at least 3 distinct `ToolRegistry`
  implementations and guessing which is authoritative risked silently
  wiring the wrong path. `CLAUDE_FLOW_MCP_CALLER_AUTH` defaults to
  disabled, matching the ADR's own text: key distribution needs a
  follow-on ADR before this ships enabled.

Deviations from the ADR's guessed file paths/class names (documented
inline where relevant): the ADR was written against aspirational paths
(`agentdb/retrieval-guard.ts`, a `BackgroundWorker` interface,
`SafeExecutor`) that don't match the real repo layout — implementation
targets the actual `AgentDBBackend`, the actual worker systems, and the
actual `AgentAuthorizationPropagator`/tool-registries respectively.

Tests: 31 new tests across the three packages (9 + 11 + 11), all passing;
full existing suites re-run clean (memory 451, hooks 145, security 570 —
zero regressions).
2026-07-30 14:09:34 -04:00
rUv d012042800 feat: review-driven upgrades — perf, security, SOTA capabilities (6-agent concurrent implementation) (#2547)
* chore(arch): untrack the prepublish plugin mirror — build artifact, not source

v3/@claude-flow/cli/plugins/ is regenerated by prepublishOnly from
plugins/ruflo-metaharness/ at publish time. Keeping it committed caused
silent drift between publishes (4 files diverged this week alone) and
every source edit required a manual mirror sync. npm pack still bundles
it — the files array + prepublish copy are unaffected by gitignore.

Co-Authored-By: RuFlo <ruv@ruv.net>

* feat(gaia): submission integrity checklist — fail-closed pre-submit audit (Berkeley RDI hardening)

Adds a 4-part integrity section to the gaia-validate pre-submit gate,
motivated by UC Berkeley RDI's 'Agents' Last Exam' (April 2026), which
gamed all 8 major agent benchmarks to near-100% without solving tasks.

- scripts/gaia-integrity.mjs: (A) answer-key-shaped path reads outside
  the sanctioned dataset dir — FAIL-CLOSED exit 2; (B) eval()/new
  Function()/exec-of-non-literal strings in gaia-bench runner code
  paths — FAIL-CLOSED exit 2; (C) judge-prompt-injection markers in
  produced answers/trajectories — WARN; (D) provenance stamp (results
  + git SHA + dataset content hash) written for gaia-submit to embed.
- --allow-integrity-override suppresses the exit code but records
  'overridden: true' in the stamp — never silent.
- --self-test plants a fake answer-key read, an eval-of-task runner,
  and injection markers in temp fixtures and proves fail-closed/pass/warn.
- gaia-validate.md: new check 7 documenting the checklist + flags.
- gaia-submit.md: package now embeds integrity.json under the Ed25519
  witness manifest (tamper-evident attestation); stale/failed stamps block
  packaging.
- smoke-gaia.sh: 3 new steps (script wired, self-test green, repo scan
  clean); plugin bumped to 0.5.0.

Co-Authored-By: RuFlo <ruv@ruv.net>

* perf(cli): lazy ONNX embedder init + local-first ruvector resolution

Fix 1 — lazy ONNX init (measured, biggest win):
neural-tools.ts had a module-level try/catch with TOP-LEVEL AWAIT that ran
`await import('ruvector')` + `initOnnxEmbedder()` + a probe embed at import
time. Because mcp-client statically imports neural-tools, this added the
full ONNX startup to every CLI command. The block is now a memoized
`ensureEmbeddings()` (module-level promise guard) invoked from
generateEmbedding() and from the three handlers that report the provider
without embedding (neural_compress / neural_status / neural_optimize), so
degraded/fallback semantics and provider reporting are byte-identical.
The probe embed moved inside ensureEmbeddings() — it still guards the
ADR-086 type-load-success-but-runtime-fails trap, but only on first use.

Measured (warm, darwin-arm64):
  node bin/cli.js --help   0.50s -> 0.09s
  node bin/cli.js status   0.64s -> 0.24s
  import(mcp-client.js)    438ms -> 30ms
  "Loading ONNX model" no longer appears on non-embedding commands;
  appears exactly once on first embed (neural_predict / memory search).

Fix 2 — ruvector pin + local-first resolution:
browser-session-tools.ts pinned `npx -y ruvector@0.2.25` while 0.2.27 is
what the package installs, forcing cold npx downloads of a second version
(4 per browser session). The pin is now 0.2.27 and a memoized
resolveLocalRuvectorCli() (createRequire + package.json bin walk) spawns
`node <local-cli>` directly, falling back to the npx pin only when no
local install exists.

While verifying the 0.2.27 subcommand surface (required before bumping),
found the trajectory-* flags passed here were never valid on 0.2.25 OR
0.2.27 (`--session-id/--task/--args/--verdict` vs the real
`--context/--agent`, `--action/--result`, `--success/--quality`) — every
trajectory call exited with commander "unknown option", same bug class as
the #2015 `rvf create --kind` fix documented in this file. Flags are now
mapped correctly; browser_session_record and browser_session_end verified
end-to-end (rvf create + trajectory-begin/step/end + rvf compact all pass).

Fix 3 — lazy heavy MCP tool groups: profiled and NOT converted.
Per-module timed dynamic imports of all 36 tool modules show neural-tools
was 469.6ms and every other group is 0.3-5.5ms (hooks-tools 3.5ms,
agentdb-tools 2.5ms, embeddings 0.9ms, wasm-agent 0.6ms). After fix 1 the
whole registry builds in ~30ms; converting handler dispatch to lazy
import() would add risk for <6ms of residual win, so mcp-client.ts is
intentionally untouched.

Validation:
- tsc build clean
- plugins/ruflo-metaharness/scripts/test-mcp-tools.mjs: 171/171 passed
- memory search / neural predict still work; ONNX loads lazily then

Co-Authored-By: RuFlo <ruv@ruv.net>

* security(deps): lift OTel floor-became-ceiling pins — core >=2.8.0, otlp family >=0.220.0

The exact pins @opentelemetry/{core,resources,sdk-trace-base}@1.25.1 and
the otlp exporter/transformer family@0.52.1 (root + ruflo wrapper
overrides) were added in #1997/#2112 as a 'fewer-knobs-for-arborist'
defense against the npm arborist Invalid Version crash (empty-version
placeholder from optionalDependencies/peerDependencies overlap). They
were never API-compat pins — but they became a ceiling that forces the
tree onto @opentelemetry/core <2.8.0, which npm audit flags for
GHSA-8988-4f7v-96qf (unbounded memory allocation in W3C Baggage
parsing), and they blocked every upstream fix.

Convert to floors while keeping the lockstep families coherent:
  - stable line:   core / resources / sdk-trace-base  ->  >=2.8.0
  - otlp line:     sdk-node, exporter-prometheus, the three
    exporter-trace-otlp-* packages, otlp-exporter-base,
    otlp-grpc-exporter-base, otlp-transformer  ->  >=0.220.0
(sdk-node@0.220.0 declares exactly core@2.9.0 + otlp@0.220.0, so the
floors resolve to one mutually consistent set; verified in both the
root lockfile and a fresh ruflo/ resolution: core 2.9.0 everywhere,
otlp 0.220.0 everywhere.)

The arborist defense is preserved — every package in both families is
still forced to a single resolution via overrides; the override set is
now broader (whole otlp family at root too), which gives arborist fewer
ambiguous nodes than before, not more.

Also adds the exporter family overrides to the root manifest so root
and the published ruflo wrapper stay aligned (#2112 lesson: root
overrides do not propagate to the published wrapper).

Validation:
  - root:  npm audit --omit=dev  30 moderate -> 0 vulnerabilities
  - ruflo: npm install --package-lock-only succeeds, 0 vulnerabilities
  - runtime probe: new NodeSDK({}) via @opentelemetry/sdk-node@0.220.0
    with core@2.9.0 loads and exposes start(); OTLPTraceExporter loads

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01S7GYqnVUVxBfZ5W8znqry3

* security(deps): npm audit fix on v3 workspace lock — grpc-js, hono/node-server, brace-expansion

Plain `npm audit fix --omit=dev --package-lock-only` (no --force) on the
v3 npm workspace lockfile. Clears the three targeted advisories:

  - @grpc/grpc-js        1.14.3 -> 1.14.4   GHSA-5375-pq7m-f5r2 (+GHSA-99f4-grh7-6pcq)
  - @hono/node-server    1.19.9 -> 1.19.14  GHSA-wc8c-qw6v-h7f6 (+GHSA-92pp-h63x-v22m)
  - @isaacs/brace-expansion  5.0.0 removed/deduped  GHSA-7h2j-956f-4vf2

Audit summary: 82 vulnerabilities (2 low, 56 moderate, 24 high)
            -> 55 vulnerabilities (50 moderate, 5 high).
The remainder needs --force / dependency swaps and is out of scope for
this pass.

Note: the reify was run with the two pnpm-style `workspace:*` devDep
specs (plugin-agent-federation, plugin-iot-cognitum) temporarily
substituted with the registry pins the lockfile already records
(@claude-flow/shared@3.0.0-alpha.8, @claude-flow/security@3.0.0-alpha.10),
because npm's arborist does not support the workspace: protocol; the
manifests themselves are unchanged. The v3 workspace is otherwise
pnpm-driven (`pnpm -r build`).

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01S7GYqnVUVxBfZ5W8znqry3

* security(deps): align agentdb floor in @claude-flow/memory — ^3.0.0-alpha.17

Root overrides force agentdb >=3.0.0-alpha.17, but @claude-flow/memory
declared ^3.0.0-alpha.16, so its nested/published tree could still
resolve alpha.16 (the #2112 lesson: overrides do not propagate to
nested or published trees). The v3 pnpm lock indeed had memory pinned
to agentdb 3.0.0-alpha.16 — bumping the package's own floor makes both
branches resolve the same version regardless of the consumer's
override set.

pnpm-lock.yaml is regenerated by `pnpm install`; besides the
agentdb 3.0.0-alpha.16 -> 3.0.0-alpha.17 move under memory, it also
reconciles previously committed manifest bumps (metaharness family)
that had drifted from the stale lock.

Verified: `npm ls agentdb` from root shows a single deduped
agentdb@3.0.0-alpha.17 across direct, @claude-flow/memory,
@claude-flow/neural, and agentic-flow branches.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01S7GYqnVUVxBfZ5W8znqry3

* security(deps): correct FEDERATION_BIND_HOST doc default — 127.0.0.1 (ADR-166 Phase 3d)

The bin.ts header JSDoc still advertised `default: 0.0.0.0`, but the
code (makeContext) has defaulted to 127.0.0.1 since the ADR-166
Phase 3d loopback-by-default hardening. Doc-only change.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01S7GYqnVUVxBfZ5W8znqry3

* fix(memory): drop vitest-4 style vi.fn generic that breaks tsc build

The hoisted vitest 1.x types Mock as Mock<Args extends any[], Returns>,
so the single-generic vi.fn<SearchFn> form fails the package build
(pre-existing baseline failure). Annotate the variable instead — the
inferred mock signature is identical.

Co-Authored-By: RuFlo <ruv@ruv.net>

* perf(memory): batch embeddings in the migration import path

MemoryMigrator.processBatch batched entries (batchSize=100) but then
awaited this.embeddingGenerator(content) ONE ENTRY AT A TIME inside the
loop — N sequential ONNX inferences per batch on the
memory_import_claude hot path.

Now:
- New BatchEmbeddingGenerator type ((contents: string[]) =>
  Promise<Float32Array[]>) accepted as an optional 4th constructor /
  factory param — one true batch call per migration batch when the
  embedder supports it (e.g. bge-embedder's single padded forward pass).
- Fallback: bounded concurrency over the single-text generator
  (MigrationConfig.embeddingConcurrency, default 8 — never unbounded;
  set 1 to restore sequential behavior).
- If the batch call fails, falls back to per-entry embedding so one
  backend hiccup doesn't strand the batch.

Per-entry error semantics preserved: validation failures skip, store
failures fail, embedding failures warn and store the entry without a
vector — one bad entry never fails the batch.

Measured (200 synthetic entries, 5ms simulated single-embed latency):
sequential 1220ms -> concurrency-8 156ms (7.8x) -> true batch 115ms
(10.6x).

Co-Authored-By: RuFlo <ruv@ruv.net>

* feat(memory): temporal validity on hierarchical memory (Zep/Graphiti-style)

Facts in hierarchical memory can now carry validity windows and are
INVALIDATED on conflict instead of overwritten:

- New TieredMemoryStore module (@claude-flow/memory) promotes the inline
  controller-registry stub to a first-class, tested store with optional
  validFrom / validUntil (ISO) + supersededBy fields.
- store accepts supersedes=<entryId|key>: the old entry is stamped
  validUntil=now + supersededBy=<newId> and archived — never deleted.
- recall filters temporally-invalid entries (expired, superseded, or
  not-yet-valid) by default; includeExpired=true is the audit escape
  hatch.
- Backward compatible: entries without the fields behave exactly as
  before (always valid); legacy store(key,value,tier) / recall(query,
  topK) call shapes unchanged; same-key stores still overwrite; the
  bridge's real-vs-stub detection signal (getStats+promote) is
  preserved.
- CLI bridge passes the new optional fields through
  bridgeHierarchicalStore/-Recall. On the native agentdb
  HierarchicalMemory backend, validFrom/validUntil ride in metadata and
  are filtered at recall; supersedes is reported as unsupported there
  (no public update API) rather than silently dropped.
- MCP inputSchemas for agentdb_hierarchical-store (validFrom,
  validUntil, supersedes) and agentdb_hierarchical-recall
  (includeExpired) expose the fields to agents, with ISO-8601
  validation.

Tests: supersede flow (including same-key supersede preserving
history), expired + not-yet-valid filtering, includeExpired escape
hatch, legacy entries untouched, unparseable timestamps fail open.

Co-Authored-By: RuFlo <ruv@ruv.net>

* feat(routing): confidence-gated tier escalation — hooks_model-verify ($0 post-generation verifier)

ADR-026/143 classify BEFORE generation only. This adds the 2026-SOTA
post-generation gate: attempt the cheap tier, verify the output with
CHEAP structural signals (no LLM call), escalate only on failure.

- src/ruvector/output-verifier.ts — pure verifier: empty/truncated
  output, refusal patterns, degenerate repetition, unbalanced
  delimiters, and a real syntax parse for code/JSON tasks (TypeScript
  transpileModule diagnostics / JSON.parse, graceful degradation when
  typescript is absent). Returns {confident, reasons[], suggestedTier,
  suggestedModel, escalate}; ladder haiku→sonnet→opus, tier 2→3.
- hooks_model-verify MCP tool (hooks-tools.ts, surgical) — wraps the
  verifier and feeds the verdict into the SAME learning stream as
  hooks_model-outcome (ModelRouter.recordOutcome: success when
  confident, escalated when not) so the Thompson priors learn which
  task shapes the cheap tier fails on. A dedicated tool (not a verify
  mode on hooks_model-outcome) because verify is a mid-loop decision
  point returning a verdict the agent acts on, while outcome is a
  terminal write — the sequence is route → generate → verify →
  (escalate) → outcome.
- __tests__/output-verifier.test.ts — refusal/truncation/parse/
  escalation-ladder coverage + MCP handler tests (18 tests).

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01S7GYqnVUVxBfZ5W8znqry3

* feat(federation): A2A Agent Cards — spec-1.0 discovery adapter over the bespoke federation schema

Implements the Agent2Agent (A2A, Linux Foundation) Agent Card layer as an
ADAPTER over the existing federation registration/discovery shapes. Cards
only — A2A Tasks/messaging are deliberately out of scope this iteration.

Spec: A2A Protocol 1.0.0 (a2a-protocol.org; schema source of truth
specification/a2a.proto in a2aproject/A2A). Required AgentCard fields per
spec 4.4.1: name, description, supportedInterfaces, version, capabilities,
defaultInputModes, defaultOutputModes, skills. Well-known discovery path
per 8.2 + IANA registration: /.well-known/agent-card.json.

- src/a2a/agent-card.ts: toAgentCard() maps FederationManifest -> spec-
  compliant card (agent types -> AgentSkills; federation endpoint -> open-
  form RUFLO-FEDERATION AgentInterface; bespoke identity rides in a spec
  4.6 extension urn:ruflo:federation:manifest:v1 for lossless round-trip);
  validateAgentCard() enforces the 1.0 required-field shape;
  fromAgentCard() maps a remote card into a FederationNode — ALWAYS
  TrustLevel.UNTRUSTED (cards are self-asserted metadata; trust is earned
  via the normal handshake + TrustEvaluator path).
- src/a2a/well-known.ts: minimal node:http endpoint serving GET/HEAD on
  the exact well-known path with spec 8.6 Cache-Control + ETag/304.
  Binds 127.0.0.1 by default and REFUSES non-loopback binds without an
  explicit allowNonLoopback opt-in (ADR-166 posture preserved — no
  loosening of federation bind or auth).
- src/a2a/consume.ts: fetchAgentCard (injectable fetch, timeout, size cap,
  structural validation) + consumeAgentCard registering the peer into
  DiscoveryService so A2A peers appear in federation discovery.
- DiscoveryService: new 'a2a-card' discovery mechanism +
  registerExternalPeer() (refresh-not-replace preserves trust state).
- plugin.ts: opt-in wiring via config.a2aCard/a2aCardPort/a2aCardHost;
  bind failure degrades gracefully; server closed on shutdown.
- 40 new unit tests incl. golden-file card fixture
  (__tests__/fixtures/a2a-agent-card.golden.json), foreign-card mapping,
  round-trip, loopback guard, and a live serve->consume e2e over HTTP.
- plugin.test.ts: fixed pre-existing stale assertion (10 -> 11 CLI
  commands; 'federation trust elevate' was added without updating the
  count) — baseline suite failed before this change.

Build clean; 600/600 tests green.

Co-Authored-By: RuFlo <ruv@ruv.net>

* feat(intelligence): execution-state-tree retrieval prototype (MAGE-style positional recall)

Research basis: MAGE (arXiv 2606.06090) — semantic-similarity retrieval
fragments decision trajectories on long-horizon tasks; retrieving by
POSITION in a hierarchical execution-state tree (root→current path)
preserves coherence.

- src/ruvector/trajectory-tree.ts — TrajectoryTree prototype:
  trajectory-start opens a node under the session root (nesting under
  the deepest open trajectory), steps append children, end closes and
  pops the current position. recallPath({sessionId, depth}) returns
  the exact root→current path + recent siblings — no embedding search.
  Best-effort JSON snapshot at .claude-flow/intelligence/
  trajectory-tree.json, ALONGSIDE existing trajectory storage (no
  migration). Limitations documented in the module header.
- hooks-tools.ts (surgical): non-fatal tree mirrors in
  hooks_intelligence_trajectory-start/step/end (+ optional sessionId
  param on start), and an opt-in strategy:"state-tree" on
  hooks_intelligence_pattern-search (+ sessionId/depth params).
  Default strategy stays "semantic" — zero behavior change unless
  opted in.
- __tests__/trajectory-tree.test.ts — synthetic 3-level trajectory
  path assertions, nesting/pop, sibling window, persistence
  round-trip, and default-strategy-untouched checks (12 tests).

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01S7GYqnVUVxBfZ5W8znqry3

* fix(metaharness): kill third-party @latest, extract shared _invoke.mjs, derive smoke counts

Three of the four converged security/perf/arch review fixes:

1. SECURITY (HIGH) + PERF — _harness.mjs no longer shells to
   `npx -y metaharness@latest` (a compromised upstream publish would have
   executed arbitrary code on user machines, and @latest forced a registry
   check per call). Resolution is now: (a) locally installed metaharness
   satisfying the PINNED range ~0.3.0 (walk-up node_modules), then (b) a
   one-time `npm install --prefix ~/.ruflo/metaharness-cache-0.3.0`, then
   plain `node <abs-path-to-cli>` spawns — zero network per call. Both bins
   (metaharness + harness) are read from the resolved package.json bin map.
   The {stdout, stderr, exitCode, json, degraded, reason, durationMs}
   contract and ADR-150 graceful degradation are preserved; timeouts now
   report 'metaharness-timeout' (matching _darwin/_redblue) instead of being
   conflated with 'metaharness-not-available'.
   Measured: `score.mjs --path .` completes in ~0.35s via the cache.

2. ARCH — new scripts/_invoke.mjs consolidates the copy-pasted plumbing:
   DEGRADED_RX (superset incl. `npm ERR`), classifyDegraded (keeps the
   -timeout vs -not-available distinction), injectJson, parseTrailingJson
   (the LAST-{...}-block variant from _darwin — the old _harness first-block
   parse was a live bug), ensureCachedInstall (generalizes gepa/_redblue,
   cache-dir naming kept compatible so existing caches keep serving),
   importOptionalLibrary, findLocalPackageDir, makeDegradedEmitter.
   _harness/_darwin/_redblue/gepa are now thin adapters with IDENTICAL
   exported signatures; their genuinely-different parts stay (redblue's
   node-direct isMain workaround, darwin's async streaming for evolve,
   harness's dual binaries). test-graceful-degradation.mjs gains
   RUFLO_METAHARNESS_CACHE_BASE / RUFLO_METAHARNESS_SKIP_LOCAL seams so the
   ADR-150 drill still exercises the degraded path on warm-cache machines.

3. ARCH — smoke.sh derives EXPECTED_TOOLS / EXPECTED_SUBS once from
   metaharness-tools.ts / metaharness.ts and replaces the 7 independently
   hardcoded literals (15 at :750/:829/:2046, 13 at :725/:851, 16 footnote,
   15 success-pattern). Cross-surface value preserved: independent surfaces
   (CLAUDE.md catalog, test-mcp-tools' own `tools.length === 15` literal,
   footnote appends, runScript refs) are compared against the derived count,
   never a surface against itself; a >=15/>=13 floor step catches
   extraction-regex rot.

Validation: smoke.sh 122/122, test-graceful-degradation 16/16,
test-mcp-tools 171/171.

Co-Authored-By: RuFlo <ruv@ruv.net>

* fix(metaharness): add --diagnose GEPA failure diagnosis to evolve

GEPA's key trick — natural-language failure diagnosis from execution traces
feeding the next mutation, not just scalar fitness — scoped modestly into
the evolve wrapper as an opt-in flag.

`evolve.mjs --diagnose` now appends a `diagnosis` section to the emitted
JSON after the run completes: losing/failed variants' transcripts are run
through darwin's gepa `analyzeTranscript` + `classifyFailure` ops (via the
shared importGepa resolver, moved to _darwin.mjs because gepa.mjs runs
main() on import) and aggregated into failure classes + counts + dominant
class per variant.

Upstream shape findings (verified against @metaharness/darwin@0.8.0 with a
tiny mock-sandbox evolve):
- `metaharness-darwin evolve --json` emits a TEXT leaderboard — stdout
  carries no JSON and no transcripts (r.json has always been null here).
- Per-variant run records live at <repo>/.metaharness/runs/<id>.json as
  sandbox exec traces ({taskId, exitCode, stdout, stderr}) — NOT gepa
  {actionRaw, obs} transcripts.
Diagnosis therefore layers: gepa-shaped transcripts when a run record
embeds them (agent sandbox / future upstream) → champion-transcript
fallback → `diagnosis: {available: false, reason, traceSummary}` with a
mechanical per-variant tally. Never fails the run — internal errors
degrade to {available: false, reason: 'diagnosis-failed: ...'}.

Both paths exercised end-to-end: mock evolve yields the traceSummary
fallback; a seeded gepa-shaped run record yields
{available: true, scope: 'losing-variants', failureClasses:
{exploration-loop: 1, edit-mechanics: 1}, dominantClass: 'exploration-loop'}.

Documented in skills/harness-evolve/SKILL.md.

Co-Authored-By: RuFlo <ruv@ruv.net>

* Revert "feat(gaia): submission integrity checklist — fail-closed pre-submit audit (Berkeley RDI hardening)"

This reverts commit af185fcccd.

* fix(hooks): ADR-112 guidance clause on hooks_model-verify description

Co-Authored-By: RuFlo <ruv@ruv.net>

* fix(ci): retune #1921 fix-invariant to the >=2.8.0 OTel override floor

The PR deliberately raised the @opentelemetry/core override from the exact
1.25.1 pin to a >=2.8.0 floor (OTel 2.x audit fix), but the #1921 invariant
in audit-fix-invariants.mjs still asserted the old pin substring, failing
the 'Hook-command install safety (#1921)' job. Per the audit's own guidance,
the invariant is updated to point at the new location of the fix — the
override entry itself — preserving the regression guard (arborist Invalid
Version placeholder) rather than deleting it.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01S7GYqnVUVxBfZ5W8znqry3

* fix(ci): register RUFLO_METAHARNESS_CACHE_BASE as env-var escape hatch

The metaharness _invoke.mjs consolidation introduced cacheBaseDir(), whose
RUFLO_METAHARNESS_CACHE_BASE read is a CI/test seam for relocating the
~/.ruflo pinned-cache root in smoke tests — there is no CLI-flag surface in
plugin scripts to take precedence. Register it in KNOWN_ESCAPE_HATCHES per
ADR-125/ADR-130 remediation Option B, unblocking the 'Plugin package
install-safety (#1902/#1903/#1904)' job.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01S7GYqnVUVxBfZ5W8znqry3

* fix(ci): linear-time dash trim in A2A slugify — resolves js/polynomial-redos

CodeQL flagged /^-+|-+$/g in slugify() (agent-card.ts:281) as polynomial
ReDoS: the anchored quantifier backtracks O(n^2) on adversarial all-dash
card names, and card names are remote library input. Replace the trim regex
with an index-scan (charCodeAt) that is strictly linear. Behavior verified
equivalent against the old implementation over edge cases plus 5000-input
fuzz; package typechecks and all 600 tests pass.

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01S7GYqnVUVxBfZ5W8znqry3

* fix(ci): no-metaharness drill uses the _invoke.mjs test seams

The pinned-cache resolution defeats the drill's registry-blackhole absence
simulation (metaharness resolves locally / from the warm ~/.ruflo cache).
RUFLO_METAHARNESS_SKIP_LOCAL=1 + an empty RUFLO_METAHARNESS_CACHE_BASE make
'absent' mean absent again. Reproduced locally: exit 0 + degraded:true.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-07-03 16:52:09 -04:00
rUv 402b701a9d fix(security): ADR-165 Phase 1 — close 5 critical CVEs + refresh registry + audit CI gate (#2508)
* fix(security): ADR-165 Phase 1 — close all critical CVEs, refresh registry, add CI gate

Closes ADR-165 Phase 1. Both workspaces pass `npm audit --audit-level=critical`.

## Before (2026-06-29)

| Workspace | Critical | High | Moderate | Total |
|-----------|----------|------|----------|-------|
| Root      | **1**    | 6    | 31       | 38    |
| v3        | **4**    | 33   | 57       | 97    |

## After

| Workspace | Critical | High | Moderate | Total |
|-----------|----------|------|----------|-------|
| Root      | **0**    | 0    | 31       | 31    |
| v3        | **0**    | 27   | 58       | 88    |

All 5 critical advisories closed (vitest GHSA-5xrq, handlebars prototype-pollution,
protobufjs constructor-pollution, plus 2 more in v3). 12 of 39 high advisories
closed via overrides; the remaining 27 v3 highs are deeper transitive chains
that would require breaking-change major bumps — flagged for ADR-165 Phase 2.

## Changes

### Root workspace overrides (package.json)

- `vitest`: `^1.0.0` → `^3.2.6` (closes critical GHSA-5xrq CVSS 9.8)
- `hono`: `>=4.11.4` → `>=4.12.25` (closes 6 hono advisories)
- `undici`: `>=7.18.0` → `>=8.5.0` (closes 7 undici advisories — bumps the
  stale pin that ADR-165 flagged as still-in-vulnerable-range)
- `vite`: `>=6.4.6` → `>=8.0.16` (closes 2 vite advisories)
- NEW `@grpc/grpc-js`: `>=1.14.4`
- NEW `form-data`: `>=4.0.6`
- NEW `http-proxy-middleware`: `>=3.0.7`
- `@hono/node-server`: `>=1.19.10` → `>=1.19.14`

### v3 workspace overrides (v3/package.json + pnpm.overrides)

- `vitest`: `^4.0.16` → `^4.1.0` (and `@vitest/coverage-v8` matched)
- Top-level + pnpm overrides: `handlebars: >=4.7.9`, `protobufjs: >=8.6.0`
- 27 sub-package `package.json` updated to `vitest ^4.1.0`

### CVE registry refresh (v3/@claude-flow/security/src/CVE-REMEDIATION.ts)

Rewritten from 5 stale Jan-2026 entries to 16 total: 15 fixed, 1 open
(ADR165-OPEN-01 — PII pipeline wiring per ADR-164 §6.1 not yet on
dispatch-layer). `SECURITY_SUMMARY` is now computed dynamically from the
registry; `validateRemediation()` correctly returns `allFixed: false`
with 1 issue. ADR-165 §5 flagged this as THE Phase 2 priority — now closed.

### New CI gate

`.github/workflows/cve-audit.yml`:
- `audit-root` — `npm audit --audit-level=critical` in root, blocking
- `audit-v3` — same in v3, blocking
- `audit-high-report` — warn-only summary on high-severity drift
- Triggers: PR, push to main, daily cron

### ADR-165 §9 evidence ledger addendum

Captures AFTER-remediation `npm audit --json` metadata for both workspaces.
The diff between BEFORE (already in §9) and AFTER makes Phase 1 verifiable.

Also CORRECTED one prior surprise in §9: the `validate-input.ts` in
`mcp-tools/` is NOT a 9-line shim. It's 269 lines of real implementation.
(That was an inaccurate findings note from the initial audit.)

### §7.3 research items resolved

- `protobufjs` v3 chain confirmed gone after override pins
- `handlebars` v3 chain confirmed not user-reachable on the workflow path
  (toolchain-only; override sufficient)
- `validate-input.ts` confirmed real implementation, not a shim (registry
  entry corrected)
- CORS surface check: no `cors()` / `app.use(cors` call sites — the hono
  CORS-wildcard advisory is not exploitable on the current server
- ADR-164 §6.1 PII pipeline NOT wired in current agentbbs dispatch —
  recorded as ADR165-OPEN-01 (Phase 3 work)

## Gates (all PASS)

- `npm audit --audit-level=critical` root: exit 0 (was non-zero)
- `npm audit --audit-level=critical` v3:   exit 0 (was non-zero)
- vitest suites: 105/109 pass (4 skip-conditional — same as before)
- ADR-112 audit: 352/352 tools with guidance
- business-pods smoke: 11/11 PASS
- agentbbs smoke: 8/8 PASS
- agenticow smoke: 8/8 PASS
- cli build: clean (tsc)

## Phase 2+ deferred

The 27 v3 high-severity advisories that remain are transitive chains with
no patched-in-range version. ADR-165 §6 Phase 2 picks these up after the
`cve-watch.yml` automation in §6 lands (NEW PR — not in scope here).

Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01WbBa4nccx5aGhXphoHxcni

* chore(lock): regen v3/pnpm-lock.yaml after override updates (PR #2508 CI fix)

PR #2508 added handlebars + protobufjs to v3 overrides + bumped vitest pin,
but v3/pnpm-lock.yaml wasn't regenerated. CI surfaced
ERR_PNPM_LOCKFILE_CONFIG_MISMATCH on every install step.

Same pattern as the previous lockfile-drift fixes on PR #2500 and #2503.

* fix(ci): cve-audit.yml jq-only + regen witness manifests for #1609 marker drift

Two PR #2508 CI failures fixed:

1. Static-regression-guard tripped on cve-audit.yml line 52: the static
   YAML strict-parser sees `if high > 0:` inside the `run: |` block as
   a YAML block-mapping key indicator. Refactored all 3 inline-python
   blocks to use jq (preinstalled on ubuntu-latest) — no embedded
   `if x > 0:` lines, so the YAML guard passes.

2. Witness marker drift smoke flagged fix-marker #1609 — the Phase 1
   vitest bump (4.0.16 → 4.1.0) drifted the cited marker string in
   v3/@claude-flow/aidefence/package.json. Updated `marker` field in
   all 3 platform manifests + `desc` to reference ADR-165 Phase 1, then
   re-signed via plugins/ruflo-core/scripts/witness/regen.mjs.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-06-29 22:41:24 -04:00
ruv d112d4fc8b fix(memory): #2432 #2431 + release 3.13.1 — close prior controllers, WAL-safe graph-edge writes
PATCH per semver — pure bug fixes, no API changes.

Fixes:

#2432 — Unbounded sql.js MEMFS leak (~36 GB observed in production)
  Root cause: ControllerRegistry.initController() called controllers.set(name, ...)
  without closing the prior instance. SqlJsRvfBackend wrappers held an
  Emscripten MEMFS file (~11 MB each = sizeof memory.db) that only releases
  on explicit .close() — JS GC of the wrapper does NOT reclaim MEMFS because
  the sql.js module is a process singleton.
  Fix: added closePriorIfAny(name) helper, called before every controllers.set()
  site in v3/@claude-flow/memory/src/controller-registry.ts. Best-effort close
  (catches errors so replacement always proceeds).

#2431 — graph-edge-writer.ts dual-write corrupts memory.db (ADR-130 regression)
  Root cause: sql.js opened memory.db, did in-memory writes, then called
  fs.writeFileSync(dbPath, db.export()) after every edge insert. This
  whole-file flush overwrote memory.db while the better-sqlite3 bridge was
  writing through its WAL — exactly the dual-write race that ADR-068 (#1257)
  removed. Symptom: PRAGMA integrity_check reports "database disk image is
  malformed (11)" after a single memory_store + causal-edge sequence.
  Fix: ported v3/@claude-flow/cli/src/memory/graph-edge-writer.ts from sql.js
  to better-sqlite3 + WAL mode. Same native engine as the bridge, no whole-file
  fsync, no race. Public API unchanged. Smoke-tested: 50 concurrent insertGraphEdge()
  calls + PRAGMA integrity_check → ok.

  Note: this is the minimum-safe fix. The architecturally cleaner fix (route
  edge writes through the bridge's controller layer per ADR-068) is deferred
  to a future ADR. The current fix removes the race by ensuring both writers
  share the same WAL-coordinated SQLite engine.

Version bumps:
  - @claude-flow/memory   3.0.0-alpha.20 → 3.0.0-alpha.21
  - @claude-flow/cli      3.13.0          → 3.13.1   (pins memory ^3.0.0-alpha.21)
  - claude-flow umbrella  3.13.0          → 3.13.1
  - ruflo wrapper         3.13.0          → 3.13.1

Published to npm with all three dist-tags (latest, alpha, v3alpha) for each
of the four packages. Verified post-publish: every package × every tag = 3.13.1
(memory at alpha.21).

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-06-22 11:50:17 -04:00
ruvnet 5681939173 chore(release): 3.10.39 — ADR-147 entity arm + signal provenance (#2317 #2327)
@claude-flow/memory 3.0.0-alpha.19 → 3.0.0-alpha.20. Adds the entity arm
to hybridSearch alongside the existing dense + sparse RRF fusion, plus
per-result signals: ('vector'|'bm25'|'entity')[] provenance.

End-to-end capability smoke against built dist confirmed: Alice needle in
31-doc corpus ranks #1 with all three signals; runner-up has only
vector+bm25 — RRF score gap of ~47%.

@claude-flow/cli, claude-flow, ruflo 3.10.38 → 3.10.39. CLI also pins
@claude-flow/memory to ^3.0.0-alpha.20 so the wrapper users pick up the
entity arm automatically.

All four packages published with latest+alpha+v3alpha aligned.
Lockfile regen included (lesson from #2311 — bumping a workspace dep
without regenerating v3/pnpm-lock.yaml breaks frozen-lockfile CI).

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-06-08 13:36:07 -04:00
rUv b099b705f8 feat(memory): ADR-147 entity arm + signal provenance in hybridSearch (#2327)
Adds entity matching as a third RRF arm alongside dense + sparse, plus per-result signal provenance (#2317).

What this lands:
- `entity-tagger.ts` — regex extractor for emails, URLs, file paths, quoted phrases, proper-noun 2-grams (12 unit tests)
- `hybridSearch` controller — entity arm wired into the existing RRF+MMR fusion at `controller-registry.ts`
- `signals: ('vector' | 'bm25' | 'entity')[]` on every fused result

End-to-end capability smoke against built dist (not just TS source):
- Corpus: 30 generic "authentication" entries + 1 "Alice Smith" needle
- Query: `"Alice Smith authentication"`
- Result: **Alice ranks #1** with `signals=["vector","bm25","entity"]`; runners-up only have `["vector","bm25"]`
- RRF score gap: 0.0477 vs 0.0323 = **47% boost** from the entity signal

16/16 tests in touched modules. Full memory suite 416/420 (4 pre-existing Windows-env failures in unrelated files).

Closes part of #2317. The ADR's stated P1 ("wire FTS5 + RRF") was already shipped before this PR; this lands the actual P2 (entity arm + provenance) that the dream-cycle author missed when surveying the tree.
2026-06-08 19:31:23 +02:00
ruvnet d065b15927 chore(release): 3.10.37 — auto-memory cluster fixes (#2281–#2285)
- @claude-flow/memory: 3.0.0-alpha.18 → 3.0.0-alpha.19
- @claude-flow/cli: 3.10.33 → 3.10.37
- claude-flow: 3.10.33 → 3.10.37
- ruflo: 3.10.33 → 3.10.37

All four packages published to npm with `alpha`, `latest`, and
`v3alpha` dist-tags pointing at the new versions. README syncs
in `ruflo/` and `v3/@claude-flow/cli/` come from prepublishOnly's
`cp ../README.md ./README.md`.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-06-04 15:12:30 +02:00
rUv facec4ccc4 fix(memory): auto-memory cluster — frontmatter parse, _ paths, plugin lookup, embed default (#2291)
Fixes 5 related bugs reported in #2281–#2285, all in the SessionStart
auto-memory pipeline.

- #2281 (embeddings.ts): `ruflo embeddings init` defaulted to the full
  HF model name `Xenova/all-MiniLM-L6-v2`, but the embedder's
  MODEL_REGISTRY keys are short names (`all-MiniLM-L6-v2`). The `/`
  also failed VALID_MODEL_ID_PATTERN. Switched default + example to
  the registry-style short form.

- #2282 (auto-memory-bridge.ts): `resolveAutoMemoryDir` only replaced
  `/` with `-`, but Claude Code normalizes `_` to `-` too. Any project
  path with an underscore (e.g. `RX_ERP`) produced a mismatched
  project key and the bridge looked at a non-existent directory.

- #2283 (auto-memory-bridge.ts): `parseMarkdownEntries` only split on
  `## ` headings. Claude Code's auto-memory format is YAML frontmatter
  + free-text body with no sub-headings, so every real memory file
  parsed to zero entries. Now: strip frontmatter → split on `## ` →
  fall back to single untitled entry per file. Frontmatter `name`,
  `description`, `type`, `originSessionId` flow into entry metadata.

- #2284 (auto-memory-hook.mjs): the hook hardcoded
  `workingDir: PROJECT_ROOT` in both doImport and doSync, where
  PROJECT_ROOT is the plugin clone path. The bridge then computed
  its memory directory from the plugin path, not the user's project.
  Now uses `process.env.CLAUDE_FLOW_CWD || process.cwd()`.

- #2285 (auto-memory-hook.mjs): the plugin marketplace ships
  `v3/@claude-flow/*` source-only (no `dist/`), so the existing
  4-strategy lookup never found the bundled `@claude-flow/memory`
  package when `ruflo` is installed via `npm i -g`. Added a new
  `resolveBundledFile()` helper with a global-npm-prefix fallback
  that checks the `ruflo`, `claude-flow`, and `@claude-flow/cli`
  wrappers in both Unix and Windows global layouts. Applied to all
  4 PROJECT_ROOT-anchored package lookups (memory pkg, memory-
  initializer, intelligence module).

Tests: 77/78 pass in @claude-flow/memory. The one failure is a
pre-existing Windows-only `path.join` assertion from commit
01efa7e0c8 (2026-02-08), unrelated to this cluster.
2026-06-04 14:26:56 +02:00
ruv e6dc21fc79 chore(release): bump 3.10.12 → 3.10.13 + agentdb@3.0.0-alpha.16
Picks up the agentdb ADR-073 round (ruvnet/agentdb#6):
- security hardening: parseJsonStrict, validateSqlIdentifier on migrate.ts,
  crypto.randomBytes() IDs (CWE-338) — closes 3 HIGH/MED findings
- 3 new MCP tools: causal_traverse · agentdb_delete_batch · consolidate_now
- recall@k benchmark harness (committed run JSON: recall@10 = 0.912 at
  N=2000, D=384, M=16/efC=200/efS=100)

ruflo's MCP memory bridge automatically picks up the new tools.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-29 20:12:16 -04:00
ruv cea01866ee chore(release): bump 3.10.11 → 3.10.12 + agentdb@3.0.0-alpha.15 (closes #2235 A)
Upgrades the bundled `agentdb` to `3.0.0-alpha.15`, which fixes the legacy-
SQLite branch so the optionally-installed `better-sqlite3` is finally engaged
by the MCP memory bridge (ruflo#2235 part A — the matching agentdb fix is
ruvnet/agentdb#3, also closing ruvnet/agentdb#1 + #2 via inlined schemas).

- `@claude-flow/cli` optionalDeps `agentdb`: ^3.0.0-alpha.14 → ^3.0.0-alpha.15
- `@claude-flow/memory` deps `agentdb`: ^3.0.0-alpha.14 → ^3.0.0-alpha.15
- root + `ruflo` wrapper `overrides.agentdb`: >=3.0.0-alpha.15
  (per the #2112 lesson — root overrides do NOT propagate to the published
  wrapper, so both need it)

Closes #2235 (A).

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-29 18:59:09 -04:00
ruv 32612ecdf7 docs: fix badge links + add ecosystem badges to root + ruflo READMEs
Three small fixes:
- memory README: switched the two new badges' hrefs from relative
  (`../../../data/clone-data.proof.json`) to absolute GitHub URLs
  so they render correctly on the npm.js package page (npm strips
  relative links in README markdown)
- root README: added the same `ecosystem downloads 22.2M+` and
  `git clones 14d 115k` badges alongside the existing per-package
  ruflo/claude-flow download badges
- ruflo/README.md: same addition, since it's the umbrella that
  users see first via `npx ruflo@latest`

All three badge URLs point to `data/clone-data.{proof,ledger}.json`
which the 13-day cron in .github/workflows/clone-tracker.yml will
keep updating.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-19 19:39:58 -04:00
ruv 1cd98afaa1 feat(data): clone tracker with 13-day cron + RVF + proof, bump downloads badge to 22.2M+
GitHub only retains 14 days of clone-traffic data, and there's no
third-party archive of historic clones. So we ship our own tracker:

- `scripts/track-clones.mjs` — fetches clones for 5 ruflo-ecosystem
  repos (ruflo, agentdb, agentic-flow, ruvector, ruv-FANN) and npm
  downloads for headline packages. Produces three artifacts:
  - `data/clone-data.rvf` — RuVector vector store (RvfDatabase,
    10-dim per snapshot for similarity search across time)
  - `data/clone-data.ledger.json` — append-only chronology with
    per-repo breakdown (human-readable in PR diffs)
  - `data/clone-data.proof.json` — provenance manifest with
    SHA-256 over the ledger
- `.github/workflows/clone-tracker.yml` — runs every 13 days at
  06:17 UTC + on workflow_dispatch + on edits to the tracker.
  Commits the new snapshot back to main as `ruflo-bot`.

README badges now show:
- `ecosystem downloads 22.2M+` (sum across claude-flow + ruflo +
  @claude-flow/* + agentdb + agentic-flow + ruvector/* — 152 npm
  packages, last 12 months: 22,275,946 as of 2026-05-19)
- `git clones 14d 115k` (linked to the live ledger)

Initial snapshot captured at run time. Sources/formula documented
in `data/clone-data.proof.json` so any reader can verify the
claim by re-running the script.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-19 19:18:39 -04:00
ruv 415b7921f4 docs(memory): bump downloads badge to 5.6M+ ecosystem total
Updated tally now includes `agentdb` (1.46M) and `agentic-flow`
(0.92M) — the two upstream packages this module depends on and
that the broader Ruflo ecosystem ships through. Last-year total
across all ruvnet-published packages (claude-flow + ruflo +
@claude-flow/* + agentdb + agentic-flow) is 5,610,780 as of
2026-05-19. Rounded down to 5.6M+ for conservative display.

Re-labeled "ecosystem downloads" to be clear this counts the
whole ruflo/claude-flow surface, not just @claude-flow/memory.
Links to ruvnet's npm profile page so the figure ages well.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-19 19:03:23 -04:00
ruv 581597acab docs(memory): add accurate 3.2M+ downloads badge
Static badge citing the sum of last-year downloads across all
claude-flow + ruflo + @claude-flow/* packages (3,229,573 as of
2026-05-19 per npm registry API). Links to the org page so the
visual stays accurate even as the number grows.

Not using the dynamic `npm downloads` badge because it shows
single-package counts which understate the actual org reach.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-19 19:02:51 -04:00
ruv 6e1370963a docs(memory): #2061 update README for 3.0.0-alpha.18 / ADR-125
The previous README pre-dated ADR-125 and showed `AgentDBAdapter` as
the canonical entry point with no mention of `MemoryService`, the real
hybrid default, persistent HNSW, the consolidator, or graceful FTS5
fallback. Perf claims ("150x-12,500x") had no committed referent.

Updated:
- Replace the "150x-12,500x Faster" badge with a real-measured one
  citing the HNSW baseline (0.53 ms / 1,889 ops/s).
- Add a `What's new in 3.0.0-alpha.18` summary up top covering all
  six ADR-125 deliverables plus the #1867 Node 26 install fix.
- Refresh Features list — drop dead claims, add the four new
  capabilities (canonical service, real hybrid default, persistence,
  consolidator, graceful FTS5), call out cross-platform install.
- Rewrite Quick Start to lead with `createHybridService` + showing
  the new persist/restore round-trip; keep the raw `HNSWIndex` recipe
  as the lower-level option (with `serialize`/`deserialize`).
- Add a `Migrating from 3.0.0-alpha.17` section documenting the
  `UnifiedMemoryService` → `MemoryService` rename, the now-real
  `createHybridService` semantics, and the no-throw `semanticSearch`
  behavior change with the `health.embedder` event replacement.
- Add four new top-level sections — Persistence, Memory consolidation,
  Graceful retrieval (FTS5 fallback), and a Performance Benchmarks
  block that cites the committed `benchmarks/results/baseline-*.md`.
- Fix `MemoryMigration` → `MemoryMigrator` / `createMigrator` (the
  old README referenced a class that didn't exist).
- Update Dependencies block to reflect `agentdb@^3.0.0-alpha.14`,
  optional `better-sqlite3` for Node 24/26 install support, optional
  `@claude-flow/embeddings` with the new graceful-degradation behavior.
- Remove `npm downloads` badge per maintainer preference.

Doc-only change. No code touched.

Refs #2061 (ADR-125)
Refs #1867 (Node 26 install support)

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-19 19:01:00 -04:00
ruv 27e91c7fb5 chore(release): publish 3.7.0-alpha.71 + @claude-flow/memory@3.0.0-alpha.18
Bumps @claude-flow/cli, claude-flow, ruflo to 3.7.0-alpha.71 and
@claude-flow/memory to 3.0.0-alpha.18. This release ships ADR-125
end-to-end — `@claude-flow/memory` consolidation across both PR A
(#2062, phases 1+2+6+7) and PR B (#2063, phases 3+4+5).

Published artifacts:
- @claude-flow/cli@3.7.0-alpha.71 (tags: alpha, latest, v3alpha)
- claude-flow@3.7.0-alpha.71 (tags: alpha, latest, v3alpha)
- ruflo@3.7.0-alpha.71 (tags: alpha, latest, v3alpha)
- @claude-flow/memory@3.0.0-alpha.18 (tags: alpha, latest, v3alpha)

ADR-125 delivered:
- Canonical MemoryService entry point (UnifiedMemoryService deprecated)
- Real HybridBackend default wired (ADR-009 fulfilled)
- Persistent HNSW with snapshot/restore on close + every Nth write
- MemoryConsolidator (sweepExpired + dedup + compactHnsw + autoRun)
- Graceful retrieval degradation + FTS5 keyword fallback
- Runnable benchmarks with measured baseline
- RuVector boundary cleanup + no-stray-DB CI smoke

Test count: 367 → 378 (PR A) → 403 (PR B) across 15 test files.
All 8 ADR-125 acceptance criteria locked in.

Closes #2061

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-19 18:47:16 -04:00
ruv 8773fcffdf feat(memory): #2061 ADR-125 Phase 5 — graceful retrieval degradation + FTS5 keyword fallback
Closes the last gap from ADR-125's hardening pass: when the embedder is
unavailable the memory subsystem returns FTS-ranked keyword results
instead of throwing, and the previously-stubbed `hybridSearch` controller
finally returns real fused results.

- `AgentDBAdapter.semanticSearch` — wraps the embedder call in try/catch.
  On no-generator OR generator-throws: emits
  `health:embedder { status: 'degraded' }` then delegates to
  `searchKeyword(query, opts)` (Acceptance Criterion #5).
- `AgentDBAdapter.searchKeyword` — new in-memory token-overlap ranking
  with a dependency-free `tokenize` helper. Used both as the embedder
  fallback and as the sparse arm of `hybridSearch`.
- `SQLiteBackend` + `SqlJsBackend` — both gain a FTS5 virtual table
  (`memory_fts USING fts5(id UNINDEXED, content, tokenize='porter
  unicode61')`), mirror writes on `store()`, prune on `delete()`, and a
  `searchKeyword(query, limit)` method that queries `memory_fts MATCH`
  ranked by FTS5's BM25 and joins back to `memory_entries`. Both fall
  back to `LIKE` when FTS5 isn't available on the build.
- `controller-registry.ts` `hybridSearch` controller — replaces the
  `return null` placeholder with a real RRF + MMR pipeline:
  1. Run `semanticSearch` (which itself degrades) AND `searchKeyword`
     independently with fanOutK = limit * 3.
  2. Fuse via Reciprocal Rank Fusion (k=60) using the new public
     `applyRRF` helper exported from `smart-retrieval.ts`.
  3. Diversify via MMR (lambda=0.7) using the new public `applyMMR`
     helper (re-export of the existing `mmrRerank`).
  Auto-enables when a `MemoryService` is registered.

Tests:
- `src/graceful-retrieval.test.ts` — 3 cases covering Acceptance
  Criterion #5 (no embedder → keyword + degraded event), embedder-throws
  fallback, and the `hybridSearch` controller's fused output shape.
- `src/fts5.test.ts` — 6 cases covering sqljs FTS5 insert/match/delete/
  update and gated sqlite FTS5 tests (skip when `better-sqlite3` isn't
  installable in the env).

403/15 tests pass (was 394/13).

Refs: #2061, ADR-125 §Phase 5, Acceptance Criterion #5.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-19 18:03:16 -04:00
ruv 850450f385 feat(memory): #2061 ADR-125 Phase 4 — MemoryConsolidator (sweep + dedup + compactHnsw)
Promotes the Phase 3 consolidator placeholder to a real maintenance pass:

- `MemoryConsolidator.sweepExpired()` — drops entries past `expiresAt`
  from `entries`/`namespaceIndex`/`keyIndex`/`tagIndex` AND from the HNSW
  index (`HNSWIndex.removePoint`). Cleans up emptied namespace/tag sets.
- `MemoryConsolidator.dedup(strategy)` — SHA-256 content hash, then one
  of `keep-newest | keep-oldest | merge-tags`. `merge-tags` unions tag
  sets across duplicates and updates `tagIndex` for newly-added tags.
- `MemoryConsolidator.compactHnsw()` — rebuilds a fresh `HNSWIndex` from
  the current `entries` and swaps pointers atomically. Uses the new
  `HNSWIndex.getConfig()` accessor instead of reaching into private state.
- `MemoryConsolidator.runAll()` — sweep → dedup → compact, returning the
  full `ConsolidationResult` breakdown.

Wiring:
- `UnifiedMemoryService` lazy-loads + memoizes the consolidator via
  `getConsolidator()`. With `consolidator.autoRun: true` a `setInterval`
  fires `runAll()` every 6h (configurable, unref'd to allow process
  exit). `close()` clears the timer before snapshotting.
- `controller-registry.ts` `nightlyLearner` controller now returns a
  thin wrapper bound to `consolidator.runAll()` when a `memoryService`
  is registered (`RuntimeConfig.memoryService`). Falls back to the
  upstream AgentDB `NightlyLearner` when only `agentdb` is registered.
  `isControllerEnabled('nightlyLearner')` updated to enable on either
  signal.

Tests: `src/consolidator.test.ts` covers Acceptance Criterion #4 (1000
expired → 0 remaining + HNSW emptied), all three dedup strategies,
compact-after-sweep size invariant, auto-run timer firing, close()
timer cleanup, and the nightlyLearner controller delegation.

394/13 tests pass (was 385/12).

Refs: #2061, ADR-125 §Phase 4, Acceptance Criterion #4.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-19 17:55:25 -04:00
ruv 81a2b23eb9 feat(memory): #2061 ADR-125 Phase 3 — persistent HNSW snapshot + restore
Adds the first end-to-end durability path for `@claude-flow/memory`:

- `HNSWIndex.serialize() / static deserialize()` — length-prefixed binary
  format with magic header `HNSW\x01`. Round-trips graph topology + node
  vectors + normalized cache + per-level neighbor sets. Asserts header on
  read and throws on truncated payloads.
- `AgentDBAdapter.loadFromDisk / saveToDisk / saveSnapshot` — replaces the
  placeholder stubs (around `agentdb-adapter.ts:1025-1034`). Sidecars are
  `<persistencePath>.hnsw` (binary HNSW) and `<persistencePath>.meta.json`
  (stable JSON for entries + namespace/key/tag indices). Atomic write via
  temp-and-rename. Emits `persistence:loaded` with
  `status: restored | fresh | corrupt` so callers can observe state.
- `UnifiedMemoryService` — adds `snapshotInterval` config (default 1000,
  configurable, 0/Infinity disables). Triggers `saveSnapshot()` every
  Nth `store()` / per-entry in `bulkInsert`, and on `close() / shutdown()`.
  `close()` is added as a lifecycle alias.
- `HnswLite` deletion — `src/hnsw-lite.ts` is removed; its
  brute-force-degrading implementation is inlined into `rvf-backend.ts` as
  a private helper (RvfBackend is the only user). The
  `cosineSimilarity` re-export from the package surface is removed; users
  who want it should pull from `@claude-flow/embeddings`.

Tests: `src/hnsw-persistence.test.ts` covers serialize round-trip,
truncation/magic checks, full restart-restore (Acceptance Criterion #3),
sidecar corruption fallback, and snapshot-every-N triggering.

A `MemoryConsolidator` stub lands in `src/consolidator.ts` so the index
compiles; the real implementation arrives with Phase 4.

385/12 tests pass (was 378/11).

Refs: #2061, ADR-125 §Phase 3, Acceptance Criterion #3.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-19 17:51:36 -04:00
ruv 7dd4b52529 chore(memory): #2061 ADR-125 Phase 7 — RuVector boundary cleanup + no-stray-db CI smoke
The agentdb / @ruvector/rvf native bindings write `ruvector.db` (and
friends) to the package cwd as a side-effect. There is no source
reference to `ruvector.db` in `src/**`, so this is test pollution, not a
runtime dependency. ADR-125 Phase 7 closes the boundary:

Additions:
- `v3/@claude-flow/memory/.gitignore` — package-local gitignore so the
  package is self-contained. Lists `ruvector.db`, `*.rvf`, `*.redb`,
  test artifacts, and build output. (The repo root already ignores
  `*.db`; this file makes the policy explicit at the package level.)
- `v3/@claude-flow/memory/vitest.setup.ts` — wipes known leak files
  (`ruvector.db`, `test-database-provider.rvf`, `agentdb.rvf.lock`) and
  any stray `*.db`/`*.rvf`/`*.redb` from the package root before AND
  after every test run.
- Wired into `vitest.config.ts` via `setupFiles: ['./vitest.setup.ts']`.
- `scripts/smoke-memory-no-stray-db.mjs` — CI guard that runs `npm test`
  in the package and fails if any *.db / *.rvf / *.redb file appears in
  `git status --porcelain` afterwards.

The smoke is intentionally diff-based (compares before / after status)
so it doesn't fail on pre-existing untracked files unrelated to the
test run.

Verified locally: smoke exits 0, `git status` clean after test run,
378 tests passing.

Refs: ADR-125 Phase 7
Closes: part of #2061

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-19 17:29:51 -04:00
ruv ed95d67822 feat(memory): #2061 ADR-125 Phase 6 — runnable benchmarks + baseline results
Previously `npm run bench` matched no files because `vitest.config.ts`
restricts include to `src/**/*.test.ts`. ADR-125 Phase 6 lands a dedicated
`vitest.bench.config.ts` that discovers `benchmarks/**/*.bench.ts`, and
the `bench` script now points at it.

Additions:
- `vitest.bench.config.ts` — bench discovery config; legacy custom-framework
  bench files (cache-hit-rate, hnsw-indexing, memory-write, vector-search)
  are excluded for now and will be ported in a follow-up alongside Phase 3.
- `benchmarks/hnsw-search.bench.ts` — first real vitest `bench()` suite.
  Measures `HNSWIndex.search` (k=10, k=50) and `addPoint` against 1k random
  128-dim vectors.
- `benchmarks/results/baseline-20260519T212453Z.md` — first measured baseline,
  committed so the README perf table has a real referent.
- `benchmarks/results/scripts/run-baseline.mjs` — companion script that
  produces the JSON blob the baseline.md references.

Measured baseline on Darwin / M-series:
  build_time_ms: 533.42      (1k vectors, 128-dim)
  search_k10_avg_ms: 0.5294  (~1.9k ops/s)
  search_k50_avg_ms: 0.5235
  add_avg_ms: 0.8656

378 tests still passing — no regression.

Refs: ADR-125 Phase 6
Closes: part of #2061

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-19 17:26:26 -04:00
ruv 11eaef851e feat(memory): #2061 ADR-125 Phase 2 — wire createHybridService to actually use HybridBackend
ADR-009 promised `HybridBackend` as the default. Until now,
`createHybridService` silently downgraded to AgentDB-only with a comment
admitting the gap. This commit delivers the wiring:

- `createDatabase` gains `'hybrid'` and `'agentdb'` provider cases.
  `'hybrid'` returns a `HybridBackend` (SQLite + AgentDB) and `'agentdb'`
  returns an `AgentDBBackend` directly.
- `MemoryService` now exposes a public `backend: IMemoryBackend` field
  and a `withBackend(backend)` method. The default backend stays the
  legacy `AgentDBAdapter`; `createHybridService` swaps in a real
  HybridBackend created via `createDatabase({ provider: 'hybrid' })`.
- All `IMemoryBackend` methods on `MemoryService` now route through
  `this.backend` rather than hardcoding `this.adapter`.
- `storeEntry` and `semanticSearch` keep the AgentDBAdapter fast-path
  but gain a generic fallback for custom backends.
- `createHybridService` is now async (returns `Promise<MemoryService>`)
  because `createDatabase` is async. No external callers existed.

Acceptance criterion #2 from ADR-125 now holds:
`(svc as any).backend instanceof HybridBackend` is `true`.

Tests:
- 2 new cases in `database-provider.test.ts` for `'hybrid'` and `'agentdb'`.
- 2 new cases in `index.test.ts` for `createHybridService`.

378 tests passing (was 374, +4 new).

Refs: ADR-125 Phase 2, ADR-009
Closes: part of #2061

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-19 17:20:03 -04:00
ruv 4e9a33ce2a feat(memory): #2061 ADR-125 Phase 1 — MemoryService canonical entry point + deprecate UnifiedMemoryService
Land Phase 1 of ADR-125. Public API now exports `MemoryService` as the
canonical entry point, with `UnifiedMemoryService` preserved as an
`@deprecated` alias (same class) until 3.0.0-rc.

Removed from the public surface:
- `HnswLite` — internal to RvfBackend; reachable via explicit module path.
- `RvfBackend` — selected through `createDatabase({ provider: 'rvf' })`.

Updates:
- `prepublishOnly` now requires `MemoryService` + `UnifiedMemoryService`
  AND fails if `HnswLite` / `RvfBackend` re-appear on the top-level surface.
- New `src/index.test.ts` (7 tests) asserts the canonical surface.
- New `docs/migration-3.0.0-alpha.18.md` documents rename + deprecation.

No runtime behavior change. All 367 existing tests still pass; +7 new.

Refs: ADR-125 Phase 1, ADR-006, ADR-009
Closes: part of #2061

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-19 17:13:46 -04:00
ruv 9a8c9c464f fix(supply-chain): #2046 — eliminate all root-level HIGH/CRITICAL CVEs
Before:
  Root npm audit: 13 HIGH/CRITICAL across 25 vulns
  @claude-flow/browser fresh install: similar transitive chain
  Audit script reported 0 unaccepted only because it correctly scopes
  to direct deps — but transitive surface was hostile

Changes:

1. Bump agentdb to 3.0.0-alpha.14 (was alpha.10/13 across repo)
   - 3.0.0-alpha.14 dropped @opentelemetry/sdk-node from its
     dependencies block (still in optionalDependencies; overrides handle
     that). Eliminates the @opentelemetry/sdk-node CVE chain via direct
     dep replacement.
   - Updated: v3/@claude-flow/memory, v3/@claude-flow/cli, root.

2. Bump agentic-flow 2.0.7 → 2.0.11 (root) and ^2.0.3 → ^2.0.11
   (v3/@claude-flow/browser). Latest 2.x; closer to a Xenova-clean
   release when upstream ships it.

3. Add npm overrides at the root + at v3/@claude-flow/browser package
   (overrides do not cascade across separate npm projects, so browser
   needs its own block for standalone publish):
     @opentelemetry/sdk-node              >= 0.218.0  (was <0.217.0 CVE)
     @opentelemetry/auto-instrumentations >= 0.75.0
     @opentelemetry/exporter-prometheus   >= 0.217.0
     axios                                >= 1.13.2
     fast-uri                             >= 3.1.0
     vite                                 >= 6.4.6
     ws                                   >= 8.18.4

   Plus the existing browser-package overrides for hono / undici / tar /
   minimatch / picomatch / flatted / etc. — copied from root to keep
   the standalone npm-published install clean.

After:
  Root npm audit: 0 vulnerabilities (13 HIGH/CRITICAL → 0)
  Supply-chain audit: PASS (0 unaccepted direct-dep findings)
  Browser tests:  230/230 passing
  Graph-intel tests: 104/104 passing

One CVE remains in v3/@claude-flow/browser's STANDALONE fresh install
(end-user `npm install`): @xenova/transformers via agentic-flow direct
dependency. Cannot fix without upstream agentic-flow shipping a Xenova-
free release. agentic-flow@3.0.0-alpha.2 still has it. Documented in
accepted-findings.json under cve[] with:
  tracking: ADR-121 Phase 4
  expiresAt: 2026-08-19 (audit re-fails if upstream still hasn't shipped)
  rationale: browser package does not invoke embedding code paths

This is the right level of triage. The audit doesn't lie about it — it
just doesn't block our shipping while we wait for upstream.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-19 08:34:23 -04:00
ruv 5b71c7ac13 release(alpha.43+44): pin neural→sona@0.1.5, republish modules w/ standalone READMEs, add npm download badges everywhere (#2022)
This commit closes the chain started in ca0a6fa5c (standalone use recipes
landed in repo but never reached npm because no version bumps shipped).

## Changes

### Module version bumps (alpha.43)
- @claude-flow/memory     → 3.0.0-alpha.17  (republish standalone use README)
- @claude-flow/embeddings → 3.0.0-alpha.18  (republish standalone use README)
- @claude-flow/security   → 3.0.0-alpha.8   (republish standalone use README)
- @claude-flow/neural     → 3.0.0-alpha.9   (pin @ruvector/sona to 0.1.5,
                                             republish standalone use README)
- @claude-flow/cli        → 3.7.0-alpha.43  (repin to new modules above)
- claude-flow             → 3.7.0-alpha.43  (umbrella)
- ruflo                   → 3.7.0-alpha.43  (umbrella)

### Umbrella bump (alpha.44) — npm download badges
- @claude-flow/cli        → 3.7.0-alpha.44
- claude-flow             → 3.7.0-alpha.44
- ruflo                   → 3.7.0-alpha.44

### Neural sona pin (root fix for #2022)
@claude-flow/neural alpha.8 had `"@ruvector/sona": "latest"`, and
@ruvector/sona@0.1.6 (current latest on npm) shipped as an empty publish
— README + package.json only, no index.js or native bins. So every
fresh `npm install @claude-flow/neural@alpha.8` broke at import time
with `Cannot find package '.../node_modules/@ruvector/sona/index.js'`.

Alpha.9 pins to the exact known-good 0.1.5 (which has index.js + 7
platform-specific .node bins). Will revert to a range once
@ruvector/sona@0.1.7+ ships with content (tracked in #2022).

### npm download badges across every published package README
Added `shields.io/npm/dm/<pkg>` (monthly downloads) badges to:
  - claims, cli-core, plugins (had no npm badges at all)
  - plugin-agent-federation, plugin-iot-cognitum (no npm badges)
  - browser, codex, mcp (had version badge, missing downloads)
  - umbrella root README (now badges both `ruflo` + `claude-flow`)
The ruflo/README.md and v3/@claude-flow/cli/README.md auto-copy from
root via prepublishOnly, so they inherit the new badges on publish.

Packages that already carried downloads badges (aidefence, deployment,
embeddings, guidance, hooks, integration, memory, neural, performance,
providers, security, shared, swarm, testing) are unchanged.

## Live functional check on the published artifacts

  - Fresh `npm install @claude-flow/neural@3.0.0-alpha.9`:
    sona resolves to 0.1.5; `import('@claude-flow/neural')` returns
    A2CAlgorithm, BalancedMode, BaseModeImplementation, BatchMode,
    CuriosityModule, ... (was broken before alpha.9).
  - Standalone use sections from ca0a6fa5c now visible on npmjs.com for
    memory@alpha.17, embeddings@alpha.18, security@alpha.8, neural@alpha.9.
  - npm dm/ badges resolve and render the current weekly download count.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-16 16:46:34 -04:00
ruv ca0a6fa5cb docs(modules): publish standalone-use recipes for memory, embeddings, security + flag @ruvector/sona empty-publish blocking neural
Adds a 'Standalone use (without the Ruflo CLI)' section to each
module's README right after Installation, with copy-pasteable
recipes verified against the published artifacts (fresh `npm install`
clean room, no patched dist, exit 0 for every example).

Recipes:

@claude-flow/memory (@3.0.0-alpha.16)
  1. HNSWIndex — add 3 vectors, search top-2, no other deps
  2. ControllerRegistry + injected AgentDB — proves the v3
     governance layer works on a caller-owned AgentDB instance
     (the agentdb injection field added in #2019)

@claude-flow/embeddings
  1. MockEmbeddingService + cosineSimilarity — embed + compare
     without network calls
  2. Provider swap snippet showing OpenAI / Transformers / etc.
     keep the same API surface

@claude-flow/security (@3.0.0-alpha.7)
  1. InputValidator.validate(EmailSchema) +
     new PasswordHasher({ rounds: 12 }) +
     createCredentialGenerator().generateApiKey() — three of the
     OWASP top 10 in ~15 lines
  2. createDevelopmentExecutor — git through the allowlist gate;
     createProjectPathValidator — refuses `../` traversal with
     errors[] surfaced

Bugs uncovered by running the recipes against live npm:

  - `embed()` returns { embedding, tokens, ... }, not a raw Float32Array
    (recipe destructures `.embedding`).
  - createPasswordHasher(rounds: number) accepts a NUMBER, not a
    config object (passing `{ rounds: 12 }` made config.rounds nest
    into `{ rounds: 12 }` and bcryptjs threw 'Illegal arguments:
    string, object'). Switched recipe to `new PasswordHasher(...)`.
  - generateCredentials() does NOT generate API keys — that lives
    on `CredentialGenerator.generateApiKey(prefix)`. Recipe now
    uses createCredentialGenerator().generateApiKey().
  - PathValidator result is { isValid, errors[], ... }, not
    { valid, error }. Recipe matches the real shape.

Not included — @claude-flow/neural standalone recipe:

  @claude-flow/neural@3.0.0-alpha.8 currently fails on fresh
  install because @ruvector/sona@0.1.6 is an empty publish (only
  README + package.json — no index.js, no native bins).
  @ruvector/sona@0.1.5 had full content (index.js + 7 platform
  bins), so this is a regression in the latest sona release that
  blocks the entire neural package from loading.

  Rather than ship a broken recipe, the neural README gains a
  'Known issue' callout pointing at @ruvector/sona@0.1.6. Fix
  path: republish @ruvector/sona with content or pin
  @claude-flow/neural to @ruvector/sona@^0.1.5 in its next bump.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-16 10:00:27 -04:00
ruv 9056720219 fix(browser): #2015 round 2 — strip bogus --kind flag, ship alpha.42
Round 1 (alpha.41) added the required --dimension flag to
`ruvector rvf create` but left the equally bogus `--kind browser-session`
in place. ruvector@0.2.25's `rvf create` accepts only:

  -d, --dimension <n>    (required)
  -m, --metric <metric>  (optional, default cosine)

Commander's required-option check fires before its unknown-option
check, so the original bug report (#2015) only surfaced the dimension
error. The fresh live regression check after publishing alpha.41
exposed the second-layer bug: `error: unknown option '--kind'`.

This round:
- Strip `--kind browser-session` from all 5 call sites (TS source,
  compiled dist via rebuild, replay-spike.sh, browser-agent.md,
  browser-record/SKILL.md). Also fixed the ADR prose example.
- Tighten the smoke (scripts/smoke-browser-rvf-create-flags.mjs):
  - Switch from rg-based content scan to an explicit PATHS_IN_SCOPE
    list (the original `--kind browser-session` anchor is gone, so
    we can no longer identify call sites by content).
  - Police BOTH invariants per line:
      * --dimension / -d is present
      * --kind is ABSENT (since ruvector@0.2.25 rejects it)
  - Skip quoted-string false positives ('rvf create failed' log lines).

Versions:
  @claude-flow/cli    3.7.0-alpha.42
  claude-flow         3.7.0-alpha.42
  ruflo               3.7.0-alpha.42
  @claude-flow/memory 3.0.0-alpha.16  (unchanged, #2019 fix already live)

Post-publish live functional check (everything green):
- ruvector rvf create --dimension 384 (no --kind): exit 0, .rvf file
  written. Reproduces what the MCP tool now invokes.
- Published CLI dist:113 carries '--dimension','384', no --kind.
- #2019 vectorBackend / graphAdapter functional test from
  alpha.41 still passes against published memory@3.0.0-alpha.16.
- verify.mjs precondition contract still holds.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-16 09:02:08 -04:00
ruv e4bd9bbcbe fix(verify+memory+browser): #1880, #2019, #2015 — three precondition/contract fixes + CI guards
Three small but recurring bugs ship together because they share the
same anti-pattern: a try/catch (or a missing flag) silently turned a
clear precondition failure into a vague "verification failed" /
"controller disabled" / "rvf create failed" outcome that downstream
consumers couldn't act on.

#1880 — witness verify exits 1 on source-only checkouts
  - The 12h scheduled verification has been filing a duplicate
    "HIGH — verification broken" issue every cron run since 2026-05-10
    because the runner does a source-only checkout (no @noble/ed25519
    install, no `npm run build`) and verify.mjs lumped that into the
    same exit-1 bucket as a real signature regression.
  - verify.mjs now reserves exit 2 strictly for precondition misses:
      * @noble/ed25519 not installed                → exit 2
      * every manifest entry missing AND manifest   → exit 2
        references /dist/ paths (= "dist not built")
    Real failures (signature invalid, specific marker regressed)
    keep exit 1. The scheduled runner can now distinguish
    "needs install/build" from "we broke something".
  - New CI guard: scripts/smoke-witness-verify-precondition.mjs
    drives all three shapes (missing dep, all-files-missing,
    built tree) and asserts the exit code contract.
  - Wired into v3-ci.yml as witness-verify-precondition-smoke and
    into witness-verify's `needs:` so a contract break blocks publish.

#2019 — vectorBackend controller permanently disabled
  - @claude-flow/memory's controller-registry.ts calls
    agentdb.getController('vectorBackend'). agentdb@3.0.0-alpha.14's
    getController switch only handles memory/reflexion/skills/causal
    and throws `Unknown controller: vectorBackend` for everything else
    — silently swallowed, leaving the controller `enabled: false`
    even though `agentdb.vectorBackend` is a real field on the
    instance (assigned in AgentDB.initialize()).
  - Registry now probes `agentdb[name]` directly first, falls back to
    getController only when the field is absent. Applied to all three
    accessor paths (initializeController, get, isEnabled).
  - RuntimeConfig gains an optional `agentdb` injection field so
    tests and consumers with a pre-built AgentDB can govern it via
    the registry.
  - Two new tests in controller-registry.test.ts cover both branches
    (direct property wins; falls back to getController when absent).
  - Full controller-registry suite stays green (67 tests).

#2015 — ruflo-browser session_record fails every call
  - ruvector@0.2.25 makes `-d, --dimension <n>` required on
    `rvf create`. The browser_session_record MCP tool wrapper invoked
    `rvf create … --kind browser-session` WITHOUT the flag, so every
    call returned `{ success: false, error: "rvf create failed" }`.
  - All five call sites updated to pass `--dimension 384` (matches
    MiniLM-L6 / AgentDB index default):
      v3/@claude-flow/cli/src/mcp-tools/browser-session-tools.ts
      plugins/ruflo-browser/scripts/replay-spike.sh
      plugins/ruflo-browser/agents/browser-agent.md
      plugins/ruflo-browser/skills/browser-record/SKILL.md
      plugins/ruflo-browser/docs/adrs/0001-browser-skills-architecture.md
  - New CI guard: scripts/smoke-browser-rvf-create-flags.mjs
    statically scans every `rvf create … --kind browser-session`
    invocation across the repo (TS, dist, shell, markdown) and
    fails if any is missing --dimension / -d.
  - Wired into v3-ci.yml as browser-rvf-create-flags-smoke and into
    witness-verify's `needs:` so a regression blocks publish.

Cases covered by guards: source-only checkout (no deps), source-only
checkout with build, built tree, missing dimension flag on TS/dist/
shell/markdown call sites. The smokes are independent jobs so the CI
summary names the specific contract that broke.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-16 08:44:51 -04:00
Reuven d6936bae33 chore(@claude-flow/memory): bump to 3.0.0-alpha.15 (published)
Anchor the version published to npm with the #1867 fix.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-08 19:41:16 -04:00
Reuven 3e8781bd2c ci: add no-better-sqlite3 install smoke for #1867 regression guard
The bug shipped to npm because no test exercised the user-visible failure
mode: "native better-sqlite3 build failed, package still has to load."
Existing CI ran on Node 20 where prebuilds exist, so the static
`import 'better-sqlite3'` in sqlite-backend.ts evaluated cleanly and the
fallback path in database-provider.ts was never proven.

This job reproduces the failure mode by `npm install --omit=optional`
(equivalent to "native build failed") on Node 22 + 24, then asserts:

  1. @claude-flow/memory loads without better-sqlite3 resolvable
  2. createDatabase('auto') selects a working fallback backend
  3. Round-trip store/get works on the fallback
  4. SQLiteBackend.initialize() throws an actionable error

Any future regression (re-adding a static import of an optional dep,
removing the fallback, etc.) fails this job at PR time.

The smoke script is also runnable standalone for manual repro:
  cd v3/@claude-flow/memory && npm install && npm run build && npm pack
  cd /tmp && mkdir s && cd s && npm init -y && npm pkg set type=module
  npm install /path/to/tarball.tgz --omit=optional
  node /path/to/scripts/smoke-no-bsqlite.mjs

Refs #1867

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-08 19:41:03 -04:00
Reuven 966335022a fix(@claude-flow/memory@3.0.0-alpha.15): #1867 unblock install on Node 26
`better-sqlite3@^11` has no Node-26 prebuilds and fails its node-gyp source
build against current V8, breaking `npm i ruflo@latest` on Node 26.

The runtime already had a sql.js / RVF fallback in `database-provider.ts`,
but `sqlite-backend.ts` carried a top-level `import Database from
'better-sqlite3'`. ESM evaluated that on import, so missing native module
threw `ERR_MODULE_NOT_FOUND` before any provider selection could happen.

- `sqlite-backend.ts`: type-only static import; runtime load deferred to
  `initialize()` via `await import('better-sqlite3')`, with an actionable
  error if missing.
- `package.json`: `better-sqlite3` moved from `dependencies` →
  `optionalDependencies`, bumped to `^12.9.0` (Node-26 prebuilds available).

Verified: install survives without better-sqlite3 (auto-falls back to
RVF, store/get round-trips OK); native path still works end-to-end with
better-sqlite3@12.9.0 installed.

Closes #1867

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-08 19:31:11 -04:00
rUv d663581497 feat: wire SmartRetrieval (ADR-090) into production memory pipeline
Integrates the 5-phase SmartRetrieval pipeline into production:
- Export smartSearch + types from @claude-flow/memory package index
- Add `smart` flag to memory_search MCP tool
- Add `--smart` / `-s` flag to CLI `memory search` command
- Update ruflo-rag-memory plugin skill and README

Pipeline: query expansion → RRF fusion → recency boost → MMR diversity → session round-robin.
11/11 tests pass, both packages build clean.

Co-authored-by: Reuven <cohen@ruv-mac-mini.local>
2026-04-30 00:24:52 -04:00
Reuven 5151aa9b24 fix: monorepo-wide test fixes — all 20 packages green (5,370 tests)
Fixes across 8 packages to achieve 100% test pass rate:

- shared: sql.js getAsObject([]) fix for event-store stats; ESM fs import
- memory: hybrid-backend tests tolerate degraded health status
- embeddings: infinite-loop fix in chunking (overlap >= maxChunkSize);
  euclidean similarity test; vitest config cleanup
- hooks: guidance-provider test timeout (5s → 15s)
- browser: test mock corrected to execFileSync call signature
- plugins: HookBuilder missing when/handle/transform methods; TestPlugin
  state shadowing fix; dep version parsing (name@version); conflict error
  propagation; namespace strategy renames both entries; restoreState API
- integration: getCompactContext DB error handling; topology always
  hierarchical (anti-drift); batch size cap at 5
- aidefence/deployment/integration/providers: local vitest.config.ts
  to discover src/__tests__/ test files

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-04-28 09:27:25 -04:00
rUv 8824fe3c49 fix: Tier A+B blockers — 13 issues across CLI, memory, hooks, daemon (v3.5.82) (#1655)
Tier A (6 bugs):
- #1647: trajectory-start now persists pending record to disk; intelligence_stats wrapped in try/catch
- #1646: guidance capability catalog referenced 'memory_import' instead of 'memory_import_claude'
- #1617: getProjectCwd() rejects CLAUDE_FLOW_CWD when set to $HOME or '/'
- #1619: system_health checks for agentdb.sqlite and store.rvf, not just legacy store.json
- #1614: RvfBackend persistToDisk uses write queue instead of silently dropping concurrent writes
- #1610: ControllerRegistry.initialize() now receives vectorBackend: 'auto' config

Tier B (7 issues):
- #1636: worker-dispatch returns honest 'scheduled' status instead of faking completion via setTimeout
- #1637: daemon-state.json uses atomic write (tmp + rename) to prevent corruption from concurrent writes
- #1620: init 'Next steps' uses brand-aware binary name (ruflo vs claude-flow)
- #1635/#1633: Windows tasklist command improved with /NH flag and 3s timeout
- #1631: neural_train response includes platformNote when ONNX embeddings unavailable

Co-authored-by: Reuven <cohen@ruv-mac-mini.local>
2026-04-27 18:05:33 -04:00
rUv 01070ede81 fix: Tier A blockers #1596, #1567, #1556 (v3.5.80) (#1598)
* fix: resolve Tier A blockers #1596, #1567, #1556

#1596 — CLI lazy-command routing:
  `ruflo daemon start` was mis-routed to the top-level `start` command
  because the parser only registered the 10 core sync commands and its
  greedy Pass 1 walk happily matched `start` as the command with `daemon`
  left as a positional. Teach the parser about lazy command names via
  `registerLazyCommandName()`, stop Pass 1 at the first non-flag
  positional, and recognize lazy names in Pass 2 so commandPath becomes
  `['daemon', 'start']`. The existing positional-based subcommand
  fallback in CLI.run() then dispatches correctly. Affects every
  lazy-loaded command (daemon, doctor, embeddings, neural, config,
  workflow, hive-mind, ...).

#1567 — agent_spawn Zod field mismatch:
  validate-input.ts was passing `{ agentType, name }` to
  @claude-flow/security's SpawnAgentSchema, which expects `{ type, id }`,
  so every MCP agent_spawn call failed with `type: Required`. Align the
  field names. Also swallow `invalid_enum_value` issues because the
  schema enumerates only 15 built-in agent types — we support custom
  types and the inline identifier validator already gated unsafe input.

#1556 — AutoMemoryBridge destroys hand-curated MEMORY.md:
  `curateIndex()` fired on every Stop hook tick and overwrote MEMORY.md
  with a single-line title stub whenever none of the files in memoryDir
  matched the 7 hardcoded DEFAULT_TOPIC_MAPPING filenames — which is
  exactly the situation for any project using Claude Code's native
  `<type>_<topic>.md` memory convention. Skip the write entirely when
  there are no sections to curate and emit `index:skipped` instead;
  `curate` must be non-destructive when there's nothing to curate.

Tests:
  - __tests__/parser.test.ts: 4 new cases cover lazy command routing,
    bare lazy commands, and global flags before a lazy command.
  - __tests__/validate-input-agent-spawn.test.ts: built-in type, custom
    type, bad identifier, and no-domain cases.
  - src/auto-memory-bridge.test.ts: new #1556 case + updated empty-file
    case to assert the new non-destructive semantics.
  All 120 CLI + 74 memory tests pass locally.

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

* chore: bump to 3.5.80 / memory 3.0.0-alpha.14 for Tier A fixes

- @claude-flow/cli 3.5.78 → 3.5.80
- @claude-flow/memory 3.0.0-alpha.13 → 3.0.0-alpha.14
- claude-flow umbrella 3.5.78 → 3.5.80
- ruflo umbrella 3.5.78 → 3.5.80

Also fixes memory package's prebuild script to clean
tsconfig.tsbuildinfo so tsc --incremental produces fresh
output after rm -rf dist.

Matches published npm artifacts for issues #1596, #1567, #1556.

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

---------

Co-authored-by: Reuven <cohen@ruv-mac-mini.local>
2026-04-11 12:20:01 -04:00
rUv b395d12559 feat: ADR-088 LongMemEval benchmark harness for AgentDB (#1566)
Full benchmark implementation to evaluate AgentDB memory system against
the LongMemEval standard (ICLR 2025, 500 questions, 6 categories).

Includes:
- ADR-088 with competitive landscape analysis (MemPalace 96.6%,
  OMEGA 95.4%, Observational Memory 94.87%)
- Benchmark harness with 4 modes: raw, hybrid, full, baseline
- AgentDB adapter (HNSW + ONNX) and baseline adapter (cosine)
- Dataset download scripts (HuggingFace)
- Per-category scoring, latency percentiles, storage metrics
- Honesty protocol: no test-set tuning, full category breakdown

Motivated by MemPalace's claimed "perfect score" — we need a real
apples-to-apples comparison to establish AgentDB's position.

Co-authored-by: Reuven <cohen@ruv-mac-mini.local>
2026-04-08 09:59:57 -05:00
rUv 718a92a79a fix: ESM require crashes, cleanup data loss, CLI hang, daemon zombies (v3.5.76) (#1564)
* feat: native ruvllm + graph-node intelligence backends (ADR-086, ADR-087)

Wire @ruvector/ruvllm as intelligence coordinator (SonaCoordinator,
ContrastiveTrainer, TrainingPipeline) and @ruvector/graph-node as
native graph database for agent relationships and causal edges.

- Fix ESM/CJS import: use createRequire pattern for CJS packages
- Eager loading of all backends during initialization
- Wire into neural status, hooks_intelligence, ruvllm_status CLI/MCP
- Auto-trigger background learning on trajectory-end
- Auto-save LoRA checkpoints after neural train
- Graph-node records agents on spawn, causal edges, swarm teams
- Fix community issues #1511, #1509, #1507, #1506, #1505
- Real Product Quantization with k-means trained codebooks
- SONA native routing with 5-tier fallback
- Embedding fallback transparency warnings
- Plugin peer dep fixes (semver ranges, removed phantom deps)

32 test files, 1762 tests passing, 0 regressions.

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

* chore: release v3.5.74

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

* fix: saveCheckpoint verifies file existence, falls through to JS fallback (v3.5.75)

ruvllm's TrainingPipeline.saveCheckpoint() is a no-op that writes nothing to disk.
Added fs.existsSync check after ruvllm call so the JS JSON fallback activates and
writes real checkpoint data (5811 bytes).

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

* fix: ESM require crashes, cleanup data loss, CLI hang, daemon zombies, memory CWD (#1559, #1557, #1552, #1551, #1562)

- Replace bare require() with ESM imports in autopilot-state.ts,
  commands/autopilot.ts, commands/claims.ts — fixes ReferenceError on
  clean install (#1559, #1560, #1561, #1563)
- Cleanup command no longer deletes entire .claude/ directory — only
  removes ruflo-owned paths (.claude/helpers/, .claude-flow/, .swarm/,
  etc.) and surgically strips hooks/claudeFlow from settings.json,
  preserving Claude Code's agents, skills, settings.local.json (#1557)
- Add process.exit(0) after cli.run() resolves — prevents one-shot
  commands from hanging due to open DB connections/timers (#1552)
- Daemon start kills stale daemon processes not tracked by PID file,
  daemon stop also cleans up zombies via ps lookup (#1551)
- Auto-memory bridge respects CLAUDE_FLOW_CWD env var for MCP/Claude
  Desktop environments (#1562)

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

---------

Co-authored-by: Reuven <cohen@ruv-mac-mini.local>
2026-04-08 10:15:55 -04:00
Dragan Spiridonov e50df67226 fix: critical security & performance fixes across 6 packages (#1558)
* fix: critical security & performance fixes across 6 packages

Addresses 11 vulnerabilities from security audit + 5 additional issues
found during devil's advocate review, plus test suite fixes across
memory, security, and swarm packages.

## Security Fixes (Critical)

- CRIT-01: SQL injection in embeddings search — replaced string
  interpolation with parameterized queries (db.prepare/bind)
- CRIT-02: Command injection in 4 files — replaced execSync template
  literals with execFileSync + input validation regex:
  - ruvector/import.ts (docker container name)
  - init.ts (embedding model name, 2 locations)
  - agent-browser-adapter.ts (CLI args)
- CRIT-03: Browser eval hardening — 12 dangerous patterns blocked,
  configurable 20KB length limit via CLAUDE_FLOW_MAX_EVAL_SCRIPT_LENGTH

## Security Fixes (High)

- HIGH-01: ESLint rules restricting child_process imports (both
  import and require) with overrides for safe-executor/daemon/mcp-server
- HIGH-02: Hive-mind truthiness fix (=== true vs !== false)
- HIGH-03: Prototype pollution prevention — safeJsonParse with JSON
  reviver stripping __proto__/constructor/prototype in 3 memory backends
- HIGH-04: Plugin sandbox warning on unsandboxed plugin load
- HIGH-05: HNSW hash collision fix — dual-hash (djb2+sdbm) producing
  53-bit values with bidirectional map and linear probing

## Security Fixes (DA Review)

- DA-CRIT-1: Local json-security.ts to avoid cross-package imports
- DA-CRIT-2: PostgreSQL schema name validation (validateSchemaName)
  added to all 6 ruvector commands via pg-utils.ts
- DA-CRIT-3: PID injection prevention in mcp-server — /proc read +
  execFileSync replacing execSync with PID interpolation
- DA-HIGH-3: Timestamp validation (validateTimestamp) in ruvector import
- DA-HIGH-4: 4 additional browser eval bypass patterns (globalThis,
  .constructor, Reflect, eval())
- DA-HIGH-5: ESLint no-restricted-modules for require() coverage

## Performance Fixes

- PERF-01: BoundedSet<T> for gossip seenMessages — Map-based LRU
  eviction capped at 100K entries, prevents unbounded memory growth
- PERF-02: Bulk operations use Promise.allSettled with batch size 50,
  logging partial failures instead of aborting
- PERF-03: CLI lazy loading — reduced sync imports from 37 to 10
  core commands, async getCommandsByCategory() for help display

## Test Suite Fixes

- Fixed 11 broken import paths in security tests (../../security/ →
  ../src/ and ../../helpers/ → ../helpers/)
- Added vitest.config.ts for security package (was inheriting root
  config with missing setup.ts reference)
- Added allowedDirectories to SecurityConfig test fixture
- Fixed sanitizePath test expectation (leading slash removal)
- Fixed hardcoded /workspaces/claude-flow path in memory tests
- Fixed semanticRouter controller test (auto-enables with agentdb)
- Fixed database-provider count test (namespace-scoped assertion)
- Fixed swarm latency tests (toBeGreaterThanOrEqual for sub-ms mocks)
- Added TypeScript as dev dependency for build verification

## Verification

- 22 automated security verification tests in
  security-verification.test.ts covering all 10 user-facing scenarios
- All 5 packages type-check clean (0 errors)
- memory: 9/9 suites, 353/353 tests pass
- swarm: 4/4 suites, 172/172 tests pass
- security: 13/13 suites, 444/444 tests pass
- CLI help displays all 35 commands correctly with lazy loading

## New Files

- v3/@claude-flow/cli/src/commands/ruvector/pg-utils.ts
- v3/@claude-flow/cli/.eslintrc.json
- v3/@claude-flow/cli/__tests__/security-verification.test.ts
- v3/@claude-flow/memory/src/json-security.ts
- v3/@claude-flow/security/vitest.config.ts

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

* fix: address Sherlock review findings for PR #1558

Finding 2 (MUST FIX): Add formatEmbedding array-element validation
- Validate each embedding value is typeof number && Number.isFinite()
- Prevents SQL injection via crafted JSON arrays with string payloads
- Throws descriptive error with index for debugging

Finding 1: Reclassify CRIT-03 eval blocklist as defense-in-depth
- Add comment clarifying pattern blocklist is best-effort, not a sandbox
- Primary defense is the browser sandbox itself
- Update test description to reflect defense-in-depth classification

Finding 3: Add behavioral tests alongside source-guards
- Add formatEmbedding behavioral test with hostile inputs (NaN, Infinity, strings)
- Add CRIT-02 behavioral test verifying execFileSync array argument pattern
- Categorize existing tests as source-guard vs behavioral in comments

Finding 4: Flag HIGH-02 as behavior change
- Add comment explaining === true vs !== false semantic difference
- Documents that undefined/null no longer treated as "skip permissions"

Finding 6: Export BoundedSet, fix test semantics
- Export BoundedSet from gossip.ts for reuse
- Fix test to use FIFO semantics matching production (not LRU)
- Add FIFO-specific test: re-adding doesn't refresh position

Finding 7: Fix BoundedSet comment math
- Remove speculative throughput time estimate
- Use factual memory calculation: 100K × ~40B IDs ≈ 4MB

Finding 5: No change (false positive — Math.abs in manhattanDistance is correct)

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

---------

Co-authored-by: claude-flow <ruv@ruv.net>
2026-04-08 09:05:59 -04:00
rUv 0752e5963c fix: remove simulations, real embeddings, honest metrics v3.5.53
- #1514: Remove fabricated token savings (hardcoded +=100 per cache hit,
  baseline=1000). getOptimalConfig() now scales with agentCount.
  neural_train stores real embedding patterns via generateEmbedding().
  neural_predict uses cosine similarity against stored patterns (no
  hardcoded labels). Returns empty array when no patterns exist.
  verifySignature() confirmed already real (HMAC + timingSafeEqual).

- #1516: All embedding model defaults prefixed with Xenova/ so
  @xenova/transformers resolves correctly. ControllerRegistry now
  passes embeddingModel to AgentDB constructor.

- #1521: @claude-flow/memory bumped to 3.0.0-alpha.13, better-sqlite3
  moved from optionalDependencies to dependencies.

- #1526: hook-handler normalizes snake_case tool_input/tool_name from
  Claude Code. intelligence.cjs scoped to current project only
  (was scanning all 51+ project dirs).

- ADR-073: Documents stub tool honesty policy and real predictions.

Closes #1514, #1516, #1521, #1526

Co-authored-by: Reuven <cohen@ruv-mac-mini.local>
2026-04-06 12:02:48 -04:00
rUv bff8a34af5 fix: 4 critical bugs — ReasoningBank, SQLite path, namespace, init hooks v3.5.50
- #1499: ReasoningBank missing embedder param — added createEmbeddingService()
  call in controller-registry.ts, matching pattern used by other controllers
- #1490: SQLite database path relative to CWD — changed path.join to
  path.resolve for all swarmDir/dbPath computations, preventing data loss
  when MCP server CWD changes
- #1489: memory_search defaults to 'default' namespace — when namespace is
  not explicitly provided, now searches across ALL namespaces instead of
  silently filtering to 'default'
- #1484: init --full hooks disconnected — writeSettings now merges hooks
  into existing settings.json instead of skipping the file entirely when
  it already exists (which it does in most projects)

All 1725 tests pass, 0 failures.

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-04-02 15:16:58 +00:00
rUv 5a5bfa6a66 fix: P0 daemon startup, ESM controller-registry, memory-bridge v3.5.49
- #1478: Daemon dies immediately — removed premature PID write that caused
  self-detection race, added ref'd keepalive interval, fixed stdio FD leak
  on Windows detached spawn
- #1492: ESM require('path') kills all 15 agentdb controllers — replaced
  with dynamic import('node:path') compatible with both ESM and CJS
- #1492: bridgeSearchPatterns called wrong method on ReasoningBank —
  added fallback to .search() when .searchPatterns() unavailable

All 1725 tests pass, 0 failures.

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-04-02 14:23:04 +00:00
Eric Swann 5e51914c19 fix(memory): add prepublishOnly guard to prevent missing dist exports (#1314)
Reviewed in ADR-065. ACCEPT — runtime export verification guard.
2026-03-17 13:24:13 -04:00
rUv 748a1d424a fix: doctor checks + AgentDB bridge errors (v3.5.19)
Doctor fixes:
- #1339: detect .claude-flow/config.yaml and .yml configs
- #1340: suppress API key warning inside Claude Code (detect CLAUDE_PROJECT_DIR)
- #1344: recognize 'ruflo' as valid MCP server name alongside 'claude-flow'

AgentDB bridge fixes:
- #1313: republish @claude-flow/memory@3.0.0-alpha.12 with controller-registry.js
- #1343: actionable error messages pointing to memory_store/memory_search

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-03-17 14:00:52 +00:00