mirror of
https://github.com/Egonex-AI/Understand-Anything.git
synced 2026-06-22 10:58:03 +08:00
fix(skills): prefer $PLUGIN_ROOT over relative path in generate-ignore.mjs
Addresses codex review feedback (P2). `resolve(__dirname, '../..')` breaks when `skills/understand/` is copied to a runtime skills directory whose parent is not the plugin checkout — exactly the case SKILL.md Phase 0 warns about and resolves via its multi-candidate $PLUGIN_ROOT search. This script now prefers $PLUGIN_ROOT from the env (validated via package.json presence) and falls back to the existing relative resolution. SKILL.md Phase 0.5 passes the env var in the invocation. Same latent pattern exists in scan-project / compute-batches / extract-import-map / extract-structure / build-fingerprints; hardening those is a separate concern (no behaviour change today for installs that already work). Refs #76 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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 <SKILL_DIR>/generate-ignore.mjs $PROJECT_ROOT
|
||||
PLUGIN_ROOT="$PLUGIN_ROOT" node <SKILL_DIR>/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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user