`compact.mjs` only worked when the caller ran from a cwd where
`@claude-flow/integration` resolved — which on a pnpm-workspace
marketplace install means `cwd=v3/@claude-flow/integration/` specifically
(pnpm doesn't hoist into `v3/node_modules/`). The skill's documented
`cd v3 && node ...` path failed with `Cannot find module
@claude-flow/integration/token-optimizer`.
The script also imported agentic-flow indirectly, which binds
`process.env.HEALTH_PORT || 8080` at module-load time and EADDRINUSE'd
on any host with something else already on 8080.
Fix:
1. Resolution chain (#1930 step 5) — try in order:
- createRequire(cwd) — works for npm-style hoisted installs
- createRequire(script-dir) — works when run from inside the plugin
- absolute path walk from `import.meta.url` up to 6 levels looking
for `v3/@claude-flow/integration/dist/token-optimizer.js` — works
on the marketplace layout regardless of cwd
2. HEALTH_PORT (#1930 step 4) — set to `0` by default (OS picks a free
port) before the dynamic import runs. Users can still override.
3. dist/-missing (#1930 step 1) — when the resolver finds a path that
doesn't exist on disk, surface a clear error pointing at the build
command (`cd v3/@claude-flow/integration && pnpm run build`) instead
of the generic MODULE_NOT_FOUND.
Steps 2 (agentic-flow not in workspace deps) and 3 (sharp prebuild
missing) are install-environment issues outside the script's reach.
The graceful-fallback path already reports `agenticFlowAvailable: false`
when the bridge can't load, which covers those cases truthfully.
Resolves#1930 (script-level — the deeper packaging fix to ship a built
`@claude-flow/integration/dist` in marketplace bundles is separate).
Co-authored-by: Reuven <cohen@ruv-mac-mini.local>
Drops the inline `node --input-type=module -e '...'` block from
cost-compact-context. Replaced with a proper script that:
- resolves @claude-flow/integration from process.cwd() (so users can
`cd v3 && node ../plugins/.../compact.mjs "<query>"`)
- prints a markdown table by default, JSON via COMPACT_QUIET=1
- catches bridge-unavailable cases cleanly
True MCP-tool wrapping (modifying @claude-flow/cli) is deferred —
directive excludes unrelated v3 changes. This is the plugin-local
equivalent: one entry point, no inline JS in skill text.
Live verified from v3/: returns documented fallback shape
(agenticFlowAvailable: false, "bridge returns inert results") because
agentic-flow isn't installed in v3/node_modules.
Smoke: 37/37. Version: 0.7.0 → 0.8.0.
Co-Authored-By: RuFlo <ruv@ruv.net>