From 98632404a9a71f3fdcc922045850e688e3723aca Mon Sep 17 00:00:00 2001 From: Paulo Castellano Date: Thu, 21 May 2026 18:53:37 -0300 Subject: [PATCH] chore: update AI agent guidelines and refactor prompt handling - Added guidelines for AI agents to avoid embedding prompts in PHP and to store them in Blade files under `resources/views/prompts/`. - Updated `PostImageRegenerator` to render prompts using Blade instead of heredocs, improving maintainability and consistency with project standards. - Enhanced documentation in `CLAUDE.md` and `.cursor/rules` files to reflect these changes. --- .cursor/rules/laravel-patterns.mdc | 6 ++++++ .cursor/rules/project-context.mdc | 1 + CLAUDE.md | 6 ++++++ app/Ai/Agents/PostImageRegenerator.php | 18 +++--------------- .../prompts/post_image/regenerator.blade.php | 12 ++++++++++++ 5 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 resources/views/prompts/post_image/regenerator.blade.php diff --git a/.cursor/rules/laravel-patterns.mdc b/.cursor/rules/laravel-patterns.mdc index b91419c6..4c975c05 100644 --- a/.cursor/rules/laravel-patterns.mdc +++ b/.cursor/rules/laravel-patterns.mdc @@ -61,3 +61,9 @@ If you hit `Illuminate\Foundation\ViteException: Unable to locate file in Vite m ## Deployment Laravel can be deployed using [Laravel Cloud](https://cloud.laravel.com/) — the fastest path to production for Laravel apps. + +## AI agents (`app/Ai/Agents`) + +- Do not write prompts inside agent classes (no heredocs, no long strings in `instructions()`). +- Store prompt copy in `resources/views/prompts/**/*.blade.php` and render with `view('prompts....', $vars)->render()`. +- Follow `PostContentStreamer`, `PostContentReviewer`, or `BrandAnalyzer` for structure. diff --git a/.cursor/rules/project-context.mdc b/.cursor/rules/project-context.mdc index 55f578f9..956a8059 100644 --- a/.cursor/rules/project-context.mdc +++ b/.cursor/rules/project-context.mdc @@ -29,6 +29,7 @@ This project has domain-specific skills in `.claude/skills/` (e.g. `pest-testing - Follow existing code conventions. Check sibling files for structure, approach and naming before creating or editing. - In Vue ``, primary action button first in markup, then cancel/secondary (see `vue-typescript.mdc` and `CLAUDE.md`). +- AI agents: prompts live in `resources/views/prompts/`; `instructions()` uses `view(...)->render()` only — never heredocs or inline prompt strings in `app/Ai/Agents/` (see `CLAUDE.md`). - Use descriptive names (`isRegisteredForDiscounts`, not `discount()`). - Reuse existing components before writing new ones. - Stick to existing directory structure. Do not create new base folders without approval. diff --git a/CLAUDE.md b/CLAUDE.md index 82e54bc9..bd1ecea6 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -235,6 +235,12 @@ ## Dialogs - In ``, put the **primary action button first** in the markup, then secondary/cancel (e.g. Save → Cancel). `DialogFooter` uses `flex-col-reverse` on mobile and `sm:flex-row sm:justify-start` on desktop, so the first child is the leftmost action on larger screens. - Match sibling dialogs in the same feature area before inventing a new footer layout. +## AI agents (`app/Ai/Agents`) + +- **Never** embed prompts in PHP (`<<render()` and pass only the variables the Blade file needs — same pattern as `PostContentStreamer`, `PostContentReviewer`, and `BrandAnalyzer`. + ## Icons (@tabler/icons-vue) - This project uses `@tabler/icons-vue` for all icons. NEVER use `lucide-vue-next`. diff --git a/app/Ai/Agents/PostImageRegenerator.php b/app/Ai/Agents/PostImageRegenerator.php index 58d838bc..8e3b94b4 100644 --- a/app/Ai/Agents/PostImageRegenerator.php +++ b/app/Ai/Agents/PostImageRegenerator.php @@ -23,21 +23,9 @@ public function __construct( public function instructions(): string { - $language = $this->workspace->content_language ?: 'en'; - - return << $this->workspace->content_language ?: 'en', + ])->render(); } public function schema(JsonSchema $schema): array diff --git a/resources/views/prompts/post_image/regenerator.blade.php b/resources/views/prompts/post_image/regenerator.blade.php new file mode 100644 index 00000000..1a4af529 --- /dev/null +++ b/resources/views/prompts/post_image/regenerator.blade.php @@ -0,0 +1,12 @@ +You are editing text that will be printed inside a social media image. + +Your job: +- Apply the user's instruction to the current title/body/keywords. +- Keep the same language as the input unless the instruction explicitly asks to change it. +- Fix spelling and grammar when needed. +- Keep output concise and suitable for image overlays. +- Preserve intent and topic; only change what is needed. + +Return JSON only, following the schema. + +Language preference: {{ $content_language ?? 'en' }}.