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
2 changes: 1 addition & 1 deletion modules/playground/components/ai-chat-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default function AIChatPanel({

// Memoize the file tree string to avoid re-computing on every render
const fileTree = useMemo(
() => templateData ? collectFilePaths(templateData.items).join("\n") : "",
() => templateData?.items ? collectFilePaths(templateData.items).join("\n") : "",

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. Ai-chat-panel.tsx over 500 lines 📘 Rule violation ⚙ Maintainability

modules/playground/components/ai-chat-panel.tsx is 510 lines long, exceeding the 500-line maximum.
This increases maintenance overhead and makes the component harder to review and safely evolve.
Agent Prompt
## Issue description
`modules/playground/components/ai-chat-panel.tsx` exceeds the 500-line limit (currently 510 lines), violating the project file-size compliance requirement.

## Issue Context
This PR modifies the file, so it is in the changed-path set and must comply with the 500-line cap.

## Fix Focus Areas
- modules/playground/components/ai-chat-panel.tsx[1-510]

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

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

2. Items not array-guarded 🐞 Bug ☼ Reliability

The new templateData?.items check only tests truthiness, so a truthy non-array items value can
still be passed to collectFilePaths(...) and throw during the for...of traversal. AIChatPanel
tool handlers also pass templateData.items into helpers that assume arrays, so malformed DB-parsed
template data can still crash later during tool execution.
Agent Prompt
## Issue description
`AIChatPanel` now checks `templateData?.items` before building `fileTree`, but this is only a truthy check. If `templateData` is malformed (e.g., parsed from DB JSON without `items`, or with `items` not being an array), the chat panel can still crash:
- In the `fileTree` memoization, by calling `collectFilePaths` with a non-array.
- In tool handlers (edit/delete), by passing `templateData.items` into helpers that expect arrays.

## Issue Context
`getPlaygroundById` parses template JSON from the DB without validating that it matches the expected `TemplateFolder` schema (including `items: TemplateItem[]`). This makes runtime malformed data plausible even if TypeScript types say otherwise.

## Fix Focus Areas
- modules/playground/components/ai-chat-panel.tsx[83-87]
- modules/playground/components/ai-chat-panel.tsx[207-292]
- modules/playground/actions/index.ts[121-156]
- modules/playground/hooks/useAI.ts[145-157]

## Suggested fix
1. Normalize once in `AIChatPanel`:
   - `const templateItems = Array.isArray(templateData?.items) ? templateData.items : [];`
2. Build `fileTree` from `templateItems`:
   - `useMemo(() => collectFilePaths(templateItems).join("\n"), [templateItems])`
3. In tool handlers, use `templateItems` (or guard with `Array.isArray(templateData?.items)` and return a user-friendly error) before calling `addOrUpdateFile/deleteFileByPath/findFileByPath`.
4. (Optional but stronger) Validate/repair the parsed DB JSON in `getPlaygroundById` (e.g., if parsed object lacks `items`, set `items: []` or treat it as invalid and fall back to scanning).

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

[templateData]
);

Expand Down
Loading