* fix(security): dedup better-sqlite3 to patched 12.9.0 across dependency tree
Fixes#2736 (defense-in-depth mitigation).
SQLite's documented WAL-Reset Bug (sqlite.org/wal.html §11) is a race
between overlapping checkpoint operations and a WAL-resetting commit
that can make a later checkpoint skip a committed transaction, silently
losing acknowledged writes and/or corrupting index/table structure.
Affects SQLite 3.7.0-3.51.2; fixed in 3.51.3, backported to 3.44.6 and
3.50.7.
agentdb's own published dependency floor (`better-sqlite3@^11.8.1`,
confirmed in this tree resolving to 11.10.0, which bundles vulnerable
SQLite 3.49.2) created a mixed-engine tree alongside this repo's own
direct dependency on better-sqlite3 12.9.0 (patched SQLite 3.53.0, via
v3/@claude-flow/memory). Multiple concurrent connections (daemon, MCP
servers, CLI invocations) issuing wal_checkpoint(PASSIVE) after every
memory-bridge store is exactly the race precondition this bug requires.
This forces a single deduplicated better-sqlite3 build tree-wide via
pnpm overrides, pinned to the exact version this repo's own
@claude-flow/memory package already depends on directly (12.9.0,
bundling patched SQLite 3.53.0) — no new version to vet, just true
deduplication of agentdb's nested resolution into the already-patched
copy.
Changes (following this repo's existing #2112-lesson override
convention — multiple package.json files, each consumed a different
way):
- v3/package.json: pnpm.overrides (the v3 pnpm workspace root — this
is where agentdb's better-sqlite3@11.10.0 actually lived pre-fix)
- v3/@claude-flow/cli/package.json: npm-style overrides (effective
when @claude-flow/cli is npm-installed standalone via npx)
- package.json (root "claude-flow" umbrella): bumped the existing
">=12.8.0" override to an exact "12.9.0" pin, AND added a
pnpm.overrides block — the bare "overrides" key alone is silently
ignored by pnpm (only read by npm), so the pre-existing override was
a no-op for local `pnpm install` at repo root despite being present
in package.json for a while
- ruflo/package.json: bumped ">=12.8.0" to exact "12.9.0" (npm-style,
effective for `npx ruflo@latest`)
- v3/pnpm-lock.yaml, pnpm-lock.yaml: regenerated via `pnpm install`
Verification:
- `pnpm why -r better-sqlite3` (v3/) and `pnpm why better-sqlite3`
(root): exactly one resolved version, 12.9.0, everywhere
- Confirmed via realpath resolution (not hoisted symlink) from each of
the 4 installed agentdb versions' own on-disk directories
(1.6.1, 2.0.0-alpha.3.4, 2.0.0-alpha.3.7, 3.0.0-alpha.17) that each
now binds the same deduplicated better-sqlite3@12.9.0 copy
- `db.prepare('select sqlite_version()').get()` from that binding
returns 3.53.0 (>= 3.51.3 patched floor)
- v3/@claude-flow/memory test suite: 438/442 passing; the 4 failures
are pre-existing Windows path-separator and perf-threshold issues
unrelated to SQLite (none of the failing test files touch
better-sqlite3/sqlite at all)
Not fixed here (upstream, out of reach from this repo):
- agentdb's own published package.json floor (`^11.8.1`) is
unchanged — this override is a same-repo mitigation, not a fix to
agentdb itself. agentdb needs the same bump upstream.
Not touched here (explicitly out of scope, separate/riskier change):
- The wal_checkpoint(PASSIVE)-after-every-store pattern in
memory-bridge.ts (#2558) is left as-is; the issue calls that
"defense-in-depth" / optional, and dedup alone removes the
mixed-engine race precondition regardless.
Co-Authored-By: RuFlo <ruv@ruv.net>
* fix(deps): regenerate package-lock.json for better-sqlite3 dedup override
package.json pins the better-sqlite3 override to 12.9.0 (patched,
fixes the WAL-reset bug) but package-lock.json still resolved a stray
top-level better-sqlite3@12.10.0 and was missing the nested
better-sqlite3@12.9.0 entries under @claude-flow/memory, agentdb, and
agentic-flow — causing npm ci to fail in CI with "Missing:
better-sqlite3@12.9.0 from lock file".
Co-Authored-By: RuFlo <ruv@ruv.net>
* fix(deps): restore better-sqlite3 as direct root optionalDependency
The #2736 dedup fix pinned better-sqlite3 to 12.9.0 via a pure
"overrides" entry (no direct dependency), which removed the top-level
hoisted node_modules/better-sqlite3 that used to exist under the
looser ">=12.8.0" override. That silently broke the "graph schema
smoke (ADR-130 P1)" CI job: its "npm rebuild better-sqlite3" step
(and graph-edge-writer.ts's bare `await import('better-sqlite3')`,
which Node resolves by walking up node_modules from the importing
file) had nothing at the root to rebuild/resolve, so _openDb() failed
closed and insertGraphEdge() silently returned false — 8/22 assertions
failing.
Restoring the direct optionalDependency (matching what this file
already had historically, before the override-only refactor) gives
npm a concrete anchor to hoist a single deduplicated copy back to
root node_modules, preserving the override's version pin while
keeping the graph-edge-writer's resolution path intact. Regenerated
package-lock.json accordingly.
Verified locally: `npm rebuild better-sqlite3` now finds and rebuilds
the root copy, and a direct insertGraphEdge() call against a real
better-sqlite3 handle returns true.
Co-Authored-By: RuFlo <ruv@ruv.net>
* fix(deps): resync v3/pnpm-lock.yaml specifier after merging main
Merging main (which carries #2748's direct better-sqlite3 dependency
on @claude-flow/cli) forward into this branch left the recorded
lockfile specifier at the pre-override "^12.9.0" while this branch's
own overrides.better-sqlite3 pin ("12.9.0", exact) is now the
effective spec pnpm resolves against — a one-line drift causing
`pnpm install --frozen-lockfile` to fail across the whole v3-ci.yml
matrix. Regenerated to match.
Co-Authored-By: RuFlo <ruv@ruv.net>
* fix(memory): force WAL checkpoint before close in graph-edge-writer
The "graph schema smoke (ADR-130 P1)" CI job started failing
deterministically on Linux runners after the better-sqlite3 dedup
(this branch) pinned a single 12.9.0 build tree-wide: TEST 2/3
insert-then-reread assertions found embedding_ref/source_id undefined
immediately after _resetBridgeDb() closed the write connection.
_resetBridgeDb()'s close() relied on SQLite's implicit "last
connection close" PASSIVE auto-checkpoint to flush the WAL into the
main file before a same-process sql.js reader re-reads the raw file.
That's best-effort, not guaranteed synchronous, and evidently more
prone to leaving data in the WAL under Linux CI's I/O/lock timing than
on Windows (did not reproduce locally). Not a correctness regression
in 12.9.0 itself — a latent timing assumption the dedup made newly
observable by changing which exact build backs every connection.
Force a blocking `wal_checkpoint(TRUNCATE)` before close so the main
file always reflects committed writes before any other reader (same
process or otherwise) touches it, regardless of platform timing.
Co-Authored-By: RuFlo <ruv@ruv.net>
The repo carried 367 SKILL.md files across 5 locations, with 5–6x
duplicates of common skills (pair-programming, swarm-orchestration,
sparc-methodology, etc). Claude Code's session-start truncation
warning showed `pair-programming` listed twice in the dropped-skills
list — exactly the kind of duplication this PR removes.
Three structural changes:
1. **Rename `archive/v2/.claude/` → `archive/v2/_v2_claude_snapshot/`**
The legacy v2 directory shouldn't be discovered as a `.claude/`
config. 3.9k file renames, all under archive/, no behavior change
for live code.
2. **Delete `v3/@claude-flow/mcp/.claude/skills/` (29 files)**
100% duplicates of root `.claude/skills/`. The mcp package's
`package.json#files` doesn't even include `.claude` — these were
never published, pure local cruft.
3. **Delete `v3/@claude-flow/cli/.claude/skills/` (37 dups + 3 stray
`.yaml`/`.md` files at the wrong level), migrate the cli-only
`browser/` skill up to `.claude/skills/browser/`.**
The umbrella `claude-flow` package ships `.claude/skills/` from
the repo root, so end-users still get the canonical set. The
stray `aidefence.yaml`, `aidefence-scan.md`, `secure-review.md`
files weren't valid skills anyway (Claude Code expects
`<name>/SKILL.md`, not loose `.yaml` / `.md` files at the skills
root) — they were orphaned.
Net result on the developer's session:
- SKILL.md count: 367 → 196 (-47%)
- Duplicate `.claude/skills` paths: 5 → 1 (only root)
- Truncation warning: gone (verified in-session before this commit)
Refs #1834.
Root uses npm (package-lock.json + .github/workflows/ci.yml runs `npm ci`)
while v3/ uses pnpm workspaces (v3/pnpm-lock.yaml + v3-ci.yml runs `pnpm
install --frozen-lockfile` with cache-dependency-path: v3/pnpm-lock.yaml).
The root-level pnpm-lock.yaml was vestigial — no workflow, script, or
package.json `packageManager` field referenced it. It got regenerated in
899dcae93 alongside package-lock.json but only out of CI-noise habit, not
a real use case. Leaving it in would just guarantee drift from the npm
lockfile that's actually used.
Removes the 292KB file. Active lockfiles unchanged:
- package-lock.json — root, used by `npm ci` in ci.yml
- v3/pnpm-lock.yaml — used by `pnpm install` in v3-ci.yml
Co-Authored-By: RuFlo <ruv@ruv.net>
CI was failing with ERR_PNPM_OUTDATED_LOCKFILE because the lockfile
referenced typescript ^5.3.0 while several v3/@claude-flow/*
package.json files specified ^5.9.3. Running `pnpm install
--no-frozen-lockfile` regenerates the lockfile.
Should clear the V3 CI/CD pipeline (Type Check V3, Test V3 Packages)
which both fail at the install step before running any actual tests.