Compare commits

..

3 Commits

Author SHA1 Message Date
Sergey Novikov 9ce6ef31e8
Merge efc2152ad8 into 99c1fa940a 2026-02-22 14:10:09 +00:00
sno efc2152ad8 feat(monorepo): fix project_name resolution and variable leakage 2026-02-22 15:09:57 +01:00
Alex Verkhovsky 99c1fa940a
feat: add LLM audit prompt for file reference conventions (#1720)
tools/audit-file-refs.md — a repeatable prompt that spawns parallel
Haiku subagents to semantically audit new-format source files for
non-conforming file references. Includes a self-check that verifies
all files are accounted for before producing the final report.

Replaces the planned regex extension (Item 1 of the master plan) with
an approach that can handle the full surface area of reference patterns
without exhaustive pattern enumeration.

Also excludes .junie/ from Prettier checks (IDE integration folder,
user-specific, not in repo).

Refs #1718

Co-authored-by: Brian <bmadcode@gmail.com>
2026-02-20 20:42:33 -06:00
5 changed files with 72 additions and 7 deletions

View File

@ -29,6 +29,7 @@
<output>🚫 Error: Project context must only contain alphanumeric characters, dots, dashes, underscores, or slashes.</output> <output>🚫 Error: Project context must only contain alphanumeric characters, dots, dashes, underscores, or slashes.</output>
<action>HALT</action> <action>HALT</action>
</check> </check>
<action>Override project_name to {project_suffix}</action>
<action>Override output_folder to {project-root}/_bmad-output/{project_suffix}</action> <action>Override output_folder to {project-root}/_bmad-output/{project_suffix}</action>
</check> </check>

View File

@ -18,8 +18,8 @@
<flow> <flow>
<step n="1" title="Load and Initialize Workflow"> <step n="1" title="Load and Initialize Workflow">
<substep n="1a" title="Monorepo Context Injection"> <substep n="1a" title="Initialize Environment Variables">
{{monorepo_context_logic}} <action>Resolve system variables (date:system-generated) and paths ({project-root}, {installed_path})</action>
</substep> </substep>
<substep n="1b" title="Load Configuration and Resolve Variables"> <substep n="1b" title="Load Configuration and Resolve Variables">
@ -27,11 +27,14 @@
<mandate>Load config_source (REQUIRED for all modules)</mandate> <mandate>Load config_source (REQUIRED for all modules)</mandate>
<phase n="1">Load external config from config_source path</phase> <phase n="1">Load external config from config_source path</phase>
<phase n="2">Resolve all {config_source}: references with values from config</phase> <phase n="2">Resolve all {config_source}: references with values from config</phase>
<phase n="3">Resolve system variables (date:system-generated) and paths ({project-root}, {installed_path})</phase> <phase n="3">Ask user for input of any variables that are still unknown</phase>
<phase n="4">Ask user for input of any variables that are still unknown</phase>
</substep> </substep>
<substep n="1c" title="Load Required Components"> <substep n="1c" title="Monorepo Context Enforcement">
{{monorepo_context_logic}}
</substep>
<substep n="1d" title="Load Required Components">
<mandate>Instructions: Read COMPLETE file from path OR embedded list (REQUIRED)</mandate> <mandate>Instructions: Read COMPLETE file from path OR embedded list (REQUIRED)</mandate>
<check>If template path → Read COMPLETE template file</check> <check>If template path → Read COMPLETE template file</check>
<check>If validation path → Note path for later loading when needed</check> <check>If validation path → Note path for later loading when needed</check>
@ -39,7 +42,7 @@
<note>Data files (csv, json) → Store paths only, load on-demand when instructions reference them</note> <note>Data files (csv, json) → Store paths only, load on-demand when instructions reference them</note>
</substep> </substep>
<substep n="1d" title="Initialize Output" if="template-workflow"> <substep n="1e" title="Initialize Output" if="template-workflow">
<action>Resolve default_output_file path with all variables and {{date}}</action> <action>Resolve default_output_file path with all variables and {{date}}</action>
<action>Create output directory if doesn't exist</action> <action>Create output directory if doesn't exist</action>
<action>If template-workflow → Write template to output file with placeholders</action> <action>If template-workflow → Write template to output file with placeholders</action>

View File

@ -47,6 +47,7 @@
<action>HALT</action> <action>HALT</action>
</check> </check>
<action>Override project_name to {project_suffix}</action>
<action>Override output_folder to {project-root}/_bmad-output/{project_suffix}</action> <action>Override output_folder to {project-root}/_bmad-output/{project_suffix}</action>
<action>Override planning_artifacts to {project-root}/_bmad-output/{project_suffix}</action> <action>Override planning_artifacts to {project-root}/_bmad-output/{project_suffix}</action>
<action>Override implementation_artifacts to {project-root}/_bmad-output/{project_suffix}</action> <action>Override implementation_artifacts to {project-root}/_bmad-output/{project_suffix}</action>

59
tools/audit-file-refs.md Normal file
View File

@ -0,0 +1,59 @@
# audit-file-refs
Audit new-format BMAD source files for file-reference convention violations using parallel Haiku subagents.
## Convention
In new-format BMAD workflow and task files (`src/bmm/`, `src/core/`, `src/utility/`), every file path reference must use one of these **valid** forms:
- `{project-root}/_bmad/path/to/file.ext` — canonical form, always correct
- `{installed_path}/relative/path` — valid in new-format step files (always defined by workflow.md before any step is reached)
- Template/runtime variables: `{nextStepFile}`, `{workflowFile}`, `{{mustache}}`, `{output_folder}`, `{communication_language}`, etc. — skip these, they are substituted at runtime
**Flag any reference that uses:**
- `./step-NN.md` or `../something.md` — relative paths
- `step-NN.md` — bare filename with no path prefix
- `steps/step-NN.md` — bare steps-relative path (missing `{project-root}/_bmad/...` prefix)
- `` `_bmad/core/tasks/help.md` `` — bare `_bmad/` path (missing `{project-root}/`)
- `/Users/...`, `/home/...`, `C:\...` — absolute system paths
References inside fenced code blocks (``` ``` ```) are examples — skip them.
Old-format files in `src/bmm/workflows/4-implementation/` use `{installed_path}` by design within the XML calling chain — exclude that directory entirely.
## Steps
1. Run this command to get the file list:
```
find src/bmm src/core src/utility -type f \( -name "*.md" -o -name "*.yaml" \) | grep -v "4-implementation" | sort
```
2. Divide the resulting file paths into batches of roughly 20 files each.
3. For each batch, spawn a subagent (`subagent_type: "Explore"`, `model: "haiku"`) with this prompt (fill in the actual file paths):
> Read each of these files (use the Read tool on each):
> [list the file paths from this batch]
>
> For each file, identify every line that contains a file path reference that violates the convention described below. Skip references inside fenced code blocks. Skip template variables (anything containing `{` that isn't `{project-root}` or `{installed_path}`).
>
> **Valid references:** `{project-root}/_bmad/...`, `{installed_path}/...`, template variables.
> **Flag:** bare filenames (`step-NN.md`), `./` or `../` relative paths, bare `steps/` paths, bare `_bmad/` paths (without `{project-root}/`), absolute system paths.
>
> Return findings as a list:
> `path/to/file.md:LINE_NUMBER | VIOLATION_TYPE | offending text`
>
> If a file has no violations, include it as: `path/to/file.md | clean`
>
> End your response with a single line: `FILES CHECKED: N` where N is the exact number of files you read.
4. Collect all findings from all subagents.
5. **Self-check before reporting:** Count the total number of files returned by the `find` command. Sum the `FILES CHECKED: N` values across all subagent responses. If the totals do not match, identify which files are missing and re-run subagents for those files before proceeding. Do not produce the final report until all files are accounted for.
6. Output a final report:
- Group findings by violation type
- List each finding as `file:line — offending text`
- Show total count of violations and number of affected files
- If nothing found, say "All files conform to the convention."

View File

@ -36,7 +36,8 @@ const MONOREPO_CONTEXT_LOGIC = `
<action>HALT</action> <action>HALT</action>
</check> </check>
<!-- Step 4: Override path variables --> <!-- Step 4: Override path and identification variables -->
<action>Override project_name = {project_suffix}</action>
<action>Override output_folder = {project-root}/_bmad-output/{project_suffix}</action> <action>Override output_folder = {project-root}/_bmad-output/{project_suffix}</action>
<action>Override planning_artifacts = {output_folder}/planning-artifacts</action> <action>Override planning_artifacts = {output_folder}/planning-artifacts</action>
<action>Override implementation_artifacts = {output_folder}/implementation-artifacts</action> <action>Override implementation_artifacts = {output_folder}/implementation-artifacts</action>