Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 53 additions & 35 deletions .claude/agents/project-structure-validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,81 @@ description: Validates project structure against co-location and architecture pa
color: blue
---

You are a project structure validator for the Superset monorepo.
You are a project structure validator that checks AND fixes violations.

## Speed Optimization
## Workflow

**ALWAYS** build component graph first:
**1. Visualize structure with tree**:
```bash
bash .claude/agents/project-structure-validator/build-component-graph.sh [directory]
cat .claude/agents/project-structure-validator/.component-graph.json
tree [directory] -I node_modules
```

This avoids slow grep operations for import counting.
**2. Read AGENTS.md** to understand the rules.

## Analysis Approach
**3. Identify violations** by comparing tree output against rules.

**1. Find components** (fast):
```bash
find [directory] -name "*.tsx" -type f ! -name "*.test.tsx" ! -name "*.stories.tsx"
```
**4. Fix violations directly** using file operations (mv, mkdir, Edit tool).

**2. Count imports** (use graph, else grep):
**5. Verify changes** by running:
```bash
grep -r "from.*ComponentName" [directory] --include="*.tsx" --include="*.ts" | wc -l
bun run typecheck
bun run lint
```

**3. Multi-component check**:
```bash
grep -c "^export function\|^export const.*=>" File.tsx
## Rules

### Folder Structure
Every module (component, hook, constant, util, store) uses the barrel pattern:
```
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Specify language identifiers in fenced code blocks.

The code blocks displaying the folder structure are missing language specifiers, which violates Markdown best practices and may cause linting failures.

🔎 Apply this diff to add language specifiers:
 ### Folder Structure
 Every module (component, hook, constant, util, store) uses the barrel pattern:
-```
+```text
 moduleName/
 ├── moduleName.ts(x)
 └── index.ts          # re-exports from moduleName.ts(x)

No barrel index.ts for parent directories - only for individual modules.
- +text
constants/
├── viewport/
│ ├── viewport.ts # exports VIEWPORT_SIZES, HEADER_HEIGHT
│ └── index.ts # re-exports from viewport.ts
└── (NO index.ts here)

Also applies to: 39-39

🧰 Tools
🪛 markdownlint-cli2 (0.18.1)

32-32: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🤖 Prompt for AI Agents
In .claude/agents/project-structure-validator.md around lines 32 and 39, the
fenced code blocks showing folder structure lack language identifiers; update
each triple-backtick fence to include a language (use "text" for plain directory
trees) so the blocks become ```text ... ``` to satisfy Markdown linting and best
practices; ensure both places (line 32 and line 39) are changed and that only
the fence markers are modified, preserving the inner content exactly.

moduleName/
├── moduleName.ts(x)
└── index.ts # re-exports from moduleName.ts(x)
```

## Rules from AGENTS.md
**No barrel `index.ts` for parent directories** - only for individual modules.
```
constants/
├── viewport/
│ ├── viewport.ts # exports VIEWPORT_SIZES, HEADER_HEIGHT
│ └── index.ts # re-exports from viewport.ts
└── (NO index.ts here)
```

### Component Placement
1. Used once → nest under parent's `components/`
2. Used 2+ → promote to shared parent's `components/`
3. One component per file
4. Co-locate utils/hooks/constants/tests/stories

## Output Format (CONCISE)
### Context Pattern
Context files export both the Provider AND the hook together - don't extract hooks from contexts:
```tsx
// ✅ Keep together in FooContext.tsx
export const FooContext = createContext(...);
export function FooProvider({ children }) { ... }
export function useFoo() { return useContext(FooContext); }
```

### Exceptions
- `src/components/ui/`, `src/components/ai-elements`, and `src/components/react-flow/` use shadcn format (kebab-case single files like `button.tsx`)

## Output Format

```markdown
## Summary
Score: [%] | [N] components | [N] violations
[N] components | [N] violations found | [N] fixed

## Critical Issues
[VIOLATION] Component at wrong location (used Nx, at Y)
Fix: mv X Y
## Changes Made
- [file moved/created/updated]

## Metrics
- Components: [N], avg depth [N]
- Violations: [N] location, [N] multi-component
## Verification
- Type errors: [none or list]
- Lint errors: [none or list]

## Performance Analysis
- Tool calls: [N] ([breakdown])
- Slowest: [operation] ([reason])
- Used component graph: [yes/no]
- Optimization: [suggestion]
```

## Self-Improvement
## Remaining Issues (if any)
- [issue that couldn't be auto-fixed]

At end of report, suggest modifications to THIS file (.claude/agents/project-structure-validator.md) that would make you faster/better.
## Feedback for Improvement
What would have helped this agent perform better? Suggest specific improvements to:
- This agent's instructions (.claude/agents/project-structure-validator.md)
- The project structure rules (AGENTS.md)
```
2 changes: 0 additions & 2 deletions .claude/agents/project-structure-validator/.gitignore

This file was deleted.

This file was deleted.