Files
ruflo/v3/@claude-flow/cli/src
rUv 3673138249 fix(security): retry plain import + actionable error for aidefence load (closes #1807) (#1813)
* fix(security): retry plain import + actionable error for aidefence load (#1807)

`mcp__ruflo__aidefence_*` tools were unconditionally failing on
npm-global installs of `claude-flow` (and any setup where the
auto-install of `@claude-flow/aidefence` lands somewhere Node's
standard module resolver doesn't search). The previous flow:

  1. `import('@claude-flow/aidefence')` — fails on first call
  2. `autoInstallPackage(...)` — runs `npm install --no-save` in cwd
  3. `require.resolve(...)` + file:// import — also fails because the
     install landed in a different prefix than the resolver searches
  4. Throws `AIDefence installed but failed to load: ... Try restarting
     the MCP server.` — user follows that advice and it still doesn't
     work.

Two changes:

  - **Add a plain `import(pkg)` retry between the auto-install and the
    file:// dance.** After the install, Node's standard resolver often
    picks up the new node_modules directory across the `await` boundary;
    that path succeeds where the first attempt failed.
  - **Replace the cryptic terminal error with an actionable one** that
    explains the npm-global root cause and lists three recovery paths
    (project-local install, run from a project dir, restart MCP).

If both retries succeed, log which path worked (`resolver path` vs
`file:// path`) so users diagnosing future regressions can see how
loading actually resolved.

This is the load-path fix only — bundling aidefence as a real
dependency vs documenting it as optional is tracked separately. The
auto-install behaviour is unchanged.

Closes #1807.

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

* fix(doctor): surface @claude-flow/aidefence availability (#1807)

Reviewing #1807 again: the reporter listed three suggested fixes and
this PR's load-path retry covered #2 ("make autoInstallPackage path
work"). They also asked for #3: surface the failure mode in
`claude-flow doctor` so operators know their AIDefence stack is
non-functional BEFORE they rely on it.

Add `checkAIDefence()` to the doctor health-check set. Probe is the
same dynamic `import('@claude-flow/aidefence')` the MCP tool's handler
uses — `pass` means the actual `aidefence_*` tools will work, `warn`
includes the actionable fix (`npm install --save` in the project, or
run mcp from a dir that has it).

Wired into both:
  - the default `allChecks[]` (so `ruflo doctor` shows it)
  - the `componentMap` (so `ruflo doctor -c aidefence` runs just this probe)

Stays as `warn` on absence — aidefence is genuinely an optional dep,
not a hard requirement, so missing != broken-system.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-06 16:53:12 -04:00
..
2026-01-04 23:50:45 +00:00
2026-01-05 19:40:01 +00:00
2026-01-07 04:36:20 +00:00
2026-01-14 18:48:53 +00:00