diff --git a/understand-anything-plugin/skills/understand/SKILL.md b/understand-anything-plugin/skills/understand/SKILL.md index 36560f8..02a2135 100644 --- a/understand-anything-plugin/skills/understand/SKILL.md +++ b/understand-anything-plugin/skills/understand/SKILL.md @@ -200,9 +200,9 @@ Determine whether to run a full analysis or incremental update. Set up and verify the `.understandignore` file before scanning. 1. Check if `$PROJECT_ROOT/.understand-anything/.understandignore` exists. -2. **If it does NOT exist**, generate a starter file by invoking the bundled script (delegates to `generateStarterIgnoreFile` in `@understand-anything/core`, which reads `.gitignore`, deduplicates against built-in defaults, and emits language-grouped test-file suggestions): +2. **If it does NOT exist**, generate a starter file by invoking the bundled script (delegates to `generateStarterIgnoreFile` in `@understand-anything/core`, which reads `.gitignore`, deduplicates against built-in defaults, and emits language-grouped test-file suggestions). Pass `$PLUGIN_ROOT` via the env so the script doesn't have to re-derive it from its own path (which breaks for copied skill installs): ```bash - node /generate-ignore.mjs $PROJECT_ROOT + PLUGIN_ROOT="$PLUGIN_ROOT" node /generate-ignore.mjs $PROJECT_ROOT ``` - Report to the user: > Generated `.understand-anything/.understandignore` with suggested exclusions based on your project structure. Please review it and uncomment any patterns you'd like to exclude from analysis. When ready, confirm to continue. diff --git a/understand-anything-plugin/skills/understand/generate-ignore.mjs b/understand-anything-plugin/skills/understand/generate-ignore.mjs index b684d8d..049a835 100644 --- a/understand-anything-plugin/skills/understand/generate-ignore.mjs +++ b/understand-anything-plugin/skills/understand/generate-ignore.mjs @@ -17,6 +17,12 @@ * * Mirrors the @understand-anything/core resolution dance used by * scan-project.mjs: workspace-linked package first, plugin-cache dist fallback. + * + * Plugin root resolution: prefer $PLUGIN_ROOT from the environment (set by + * SKILL.md Phase 0 via its multi-candidate search) over the + * `resolve(__dirname, '../..')` heuristic. The relative path breaks when + * `skills/understand/` is copied into a runtime skills directory whose + * parent is not the plugin checkout. */ import { createRequire } from 'node:module'; @@ -25,8 +31,16 @@ import { fileURLToPath, pathToFileURL } from 'node:url'; import { existsSync, mkdirSync, writeFileSync } from 'node:fs'; const __dirname = dirname(fileURLToPath(import.meta.url)); -// skills/understand/ -> plugin root is two dirs up -const pluginRoot = resolve(__dirname, '../..'); + +function resolvePluginRoot() { + const envRoot = process.env.PLUGIN_ROOT; + if (envRoot && existsSync(join(envRoot, 'package.json'))) { + return envRoot; + } + return resolve(__dirname, '../..'); +} + +const pluginRoot = resolvePluginRoot(); const require = createRequire(resolve(pluginRoot, 'package.json')); let core;