Skip to content
Open
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
4 changes: 3 additions & 1 deletion modules/playground/hooks/useAI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ export function collectFilePaths(items: FileSystemItem[], prefix = ""): string[]
paths.push(...collectFilePaths(item.items, fp));
} else {
const ext = item.fileExtension ? `.${item.fileExtension}` : "";
paths.push(prefix ? `${prefix}/${item.filename}${ext}` : `${item.filename}${ext}`);
const fileName = `${item.filename}${ext}`;
if (fileName.includes(".test.") || fileName.includes(".spec.")) continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Informational

2. Misleading helper contract 🐞 Bug ⚙ Maintainability

The JSDoc for collectFilePaths() states it collects “all file paths,” but the implementation now
intentionally omits some files, which can cause future callers to silently miss paths. This is
especially risky because the helper is exported and used as a general-purpose utility.
Agent Prompt
### Issue description
`collectFilePaths()` is documented as collecting all file paths, but it now filters out some entries. This makes the function contract misleading and can cause subtle bugs if the helper is reused elsewhere expecting a complete enumeration.

### Issue Context
Filtering was added for AI context optimization, but the function name/JSDoc still describes unfiltered behavior.

### Fix Focus Areas
- modules/playground/hooks/useAI.ts[137-157]

### Implementation notes
Choose one:
- Update the JSDoc to explicitly document the exclusions (e.g., excludes files matching `.test.`/`.spec.` and any other patterns you add).
- Or, split responsibilities: keep `collectFilePaths()` as a true “collect all paths” helper and apply filtering at the call site (e.g., in `ai-chat-panel.tsx`) or via a new wrapper like `collectFilePathsForAIContext()`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

paths.push(prefix ? `${prefix}/${fileName}` : fileName);
Comment on lines +154 to +156

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remediation recommended

1. Incomplete test filtering 🐞 Bug ≡ Correctness

collectFilePaths() only skips files whose basename contains ".test." or ".spec.", so test-support
files in common locations like "tests/setup.ts" or "__mocks__/*" will still be included in the AI
fileTree and keep consuming context tokens. This can reduce the effectiveness of the PR’s goal for
projects that organize tests by directory rather than filename suffix.
Agent Prompt
### Issue description
`collectFilePaths()` currently filters only by `fileName.includes(".test.")` / `fileName.includes(".spec.")`, which won’t exclude test-support files that don’t use those suffixes (e.g., `tests/setup.ts`, files under `__mocks__/`). Since `AIChatPanel` sends `collectFilePaths(...).join("\n")` as `fileTree` system context, these files will still be sent and waste tokens.

### Issue Context
The PR intends to exclude test files from the AI context window, but the current rule set is filename-only and does not consider common test directory conventions.

### Fix Focus Areas
- modules/playground/hooks/useAI.ts[145-157]
- modules/playground/components/ai-chat-panel.tsx[83-134]

### Implementation notes
- Compute `fullPath = prefix ? `${prefix}/${fileName}` : fileName` first, and filter using a single predicate against `fullPath.toLowerCase()`.
- Extend the predicate to exclude common test directory segments (e.g., `"/tests/"`, `"/__tests__/"`, `"/__mocks__/"`) and optionally handle suffixes like `.test` / `.spec` when there is no further extension.
- Keep the final returned format unchanged (folder entries still end with `/`).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

}
}
return paths;
Expand Down
Loading