From 7dbd89a44b6067ceba9fc557e79fe1bf500df035 Mon Sep 17 00:00:00 2001 From: Lum1104 Date: Fri, 27 Mar 2026 17:08:48 +0800 Subject: [PATCH] =?UTF-8?q?perf(understand):=20replace=20allProjectFiles?= =?UTF-8?q?=20with=20batchImportData=20in=20file-analyzer=20=E2=80=94=20im?= =?UTF-8?q?port=20resolution=20now=20done=20by=20scanner?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 (1M context) --- .../skills/understand/file-analyzer-prompt.md | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/understand-anything-plugin/skills/understand/file-analyzer-prompt.md b/understand-anything-plugin/skills/understand/file-analyzer-prompt.md index 6b90665..e7c2d2f 100644 --- a/understand-anything-plugin/skills/understand/file-analyzer-prompt.md +++ b/understand-anything-plugin/skills/understand/file-analyzer-prompt.md @@ -20,11 +20,14 @@ Write a script that reads each source file in your batch and extracts determinis ```json { "projectRoot": "/path/to/project", - "allProjectFiles": ["src/index.ts", "src/utils.ts", "..."], "batchFiles": [ {"path": "src/index.ts", "language": "typescript", "sizeLines": 150}, {"path": "src/utils.ts", "language": "typescript", "sizeLines": 80} - ] + ], + "batchImportData": { + "src/index.ts": ["src/utils.ts", "src/config.ts"], + "src/utils.ts": [] + } } ``` 2. **Write** results JSON to the path given as the second argument. @@ -45,10 +48,9 @@ For each file in `batchFiles`, read the file content and extract: - Detection approach: match `class `, `interface `, `type =`, `struct `, `trait `, `impl ` as appropriate **Imports:** -- Source module path (exactly as written in the import statement) -- Imported specifiers (named imports, default import, namespace import) -- Line number -- For relative imports (starting with `./` or `../`), compute the resolved path relative to project root. Cross-reference against `allProjectFiles` to confirm the resolved path exists. Mark unresolvable imports. +- Do NOT extract imports in the script. Import resolution has already been performed by the project scanner. +- The pre-resolved imports for each file are provided in `batchImportData` in the input JSON. +- Do not include an `imports` field in the script output — import edges will be created in Phase 2 using `batchImportData` directly. **Exports:** - Exported names and their line numbers @@ -82,10 +84,6 @@ The script must write this exact JSON structure to the output file: "classes": [ {"name": "App", "startLine": 50, "endLine": 140, "methods": ["init", "run"], "properties": ["config", "logger"]} ], - "imports": [ - {"source": "./utils", "resolvedPath": "src/utils.ts", "specifiers": ["formatDate", "sanitize"], "line": 1, "isExternal": false}, - {"source": "express", "resolvedPath": null, "specifiers": ["default"], "line": 2, "isExternal": true} - ], "exports": [ {"name": "App", "line": 50, "isDefault": true}, {"name": "createApp", "line": 145, "isDefault": false} @@ -114,8 +112,8 @@ Before writing the script, create its input JSON file. **IMPORTANT:** Use the ba cat > $PROJECT_ROOT/.understand-anything/tmp/ua-file-analyzer-input-.json << 'ENDJSON' { "projectRoot": "", - "allProjectFiles": [], - "batchFiles": [] + "batchFiles": [], + "batchImportData": } ENDJSON ``` @@ -202,7 +200,7 @@ Using the script's import, export, and structural data, create edges: | Edge Type | When to Create | Weight | Direction | |---|---|---|---| | `contains` | File contains a function or class node you created | `1.0` | `forward` | -| `imports` | File imports from another project file (use `resolvedPath` from script, skip external imports where `isExternal: true`) | `0.7` | `forward` | +| `imports` | File imports from another project file (use `batchImportData[filePath]` from input JSON — external imports already filtered out) | `0.7` | `forward` | | `calls` | A function in this file calls a function in another file (infer from imports + function names when confident) | `0.8` | `forward` | | `inherits` | A class extends another class in the project | `0.9` | `forward` | | `implements` | A class implements an interface in the project | `0.9` | `forward` | @@ -210,7 +208,7 @@ Using the script's import, export, and structural data, create edges: | `depends_on` | File has runtime dependency on another project file (broader than imports -- includes dynamic requires, lazy loads) | `0.6` | `forward` | | `tested_by` | Source file is tested by a test file (infer from test file imports and naming conventions) | `0.5` | `forward` | -**Import edge creation rule:** For each import in the script output where `isExternal` is `false` and `resolvedPath` is non-null, create an `imports` edge from the current file node to `file:`. Do NOT create edges for external package imports. +**Import edge creation rule:** For each resolved path in `batchImportData[filePath]` (provided in the input JSON), create an `imports` edge from the current file node to `file:`. The `batchImportData` values contain only resolved project-internal paths — external packages have already been filtered out. Do NOT attempt to re-resolve imports from source. Do NOT use edge types not listed in this table. @@ -327,10 +325,10 @@ Use these hints to improve tag and edge accuracy for common patterns. Your train ## Critical Constraints - NEVER invent file paths. Every `filePath` and every file reference in node IDs must correspond to a real file from the script's output or the project file list provided to you. -- NEVER create edges to nodes that do not exist. If an import target is external (`isExternal: true` in script output), do NOT create an edge for it. +- NEVER create edges to nodes that do not exist. Only create import edges for paths listed in `batchImportData` — these are already verified project-internal paths. - ALWAYS create a `file:` node for EVERY file in your batch, even if the file is trivial. - Only create `function:` and `class:` nodes for significant code elements (see significance filter above). -- For import edges, use the script's `resolvedPath` field directly. Do NOT attempt to resolve import paths yourself -- the script already did this deterministically. +- For import edges, use `batchImportData[filePath]` directly from the input JSON. Do NOT attempt to resolve import paths yourself -- the project scanner already did this deterministically. - NEVER produce duplicate node IDs within your batch. - NEVER create self-referencing edges (where source equals target). - Trust the script's structural extraction. Do NOT re-read source files to re-extract functions, classes, or imports that the script already captured. Only re-read a file if you need deeper understanding for writing a summary.