Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

feat(cos): enhance prompt template to research codebase before generating agent prompt

Adam Eivy458360af523b
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index be5a98f2bc..39fa48cb4b 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -8,6 +8,7 @@
## Changed
- **CoS feature-ideas task** — Agents now implement the next unchecked PLAN.md item instead of inventing features. When user clarification is needed, agents create a `.plan-questions.md` marker and a `plan_question` notification linking to the Documents tab. Added `{appId}` template variable for prompt linking.
+- **CoS task prompt enhancement** — Enhance prompt now instructs the LLM to research the codebase (find relevant files, patterns, conventions), plan the approach, and produce a codebase-grounded prompt with specific file paths and implementation steps instead of generic advice
## Fixed
diff --git a/server/services/taskEnhancer.js b/server/services/taskEnhancer.js
index 946157c02c..8cc7433c3d 100644
--- a/server/services/taskEnhancer.js
+++ b/server/services/taskEnhancer.js
@@ -16,16 +16,37 @@ const STAGE_NAME = 'cos-task-enhance';
/**
* Fallback enhancement prompt template (used if stage template not found)
*/
-const FALLBACK_PROMPT = `You are a task prompt enhancer for an AI agent system. Your job is to take a brief task description and expand it into a comprehensive, detailed prompt that an AI coding agent can execute effectively.
+const FALLBACK_PROMPT = `You are a task prompt enhancer for an AI agent system. Your job is to take a brief task description, research the relevant parts of the codebase, and produce a comprehensive, codebase-informed prompt that an AI coding agent can execute effectively.
-## Guidelines
+## Process
-1. **Preserve the original intent** - Don't change what the user wants, just make it clearer and more actionable
-2. **Add specific steps** - Break down the task into clear, sequential steps when appropriate
-3. **Include relevant context** - Mention file paths, patterns, or conventions that should be followed
-4. **Define success criteria** - What does "done" look like?
-5. **Anticipate edge cases** - Mention potential issues to watch out for
-6. **Keep it focused** - Don't add unrelated tasks or scope creep
+### Step 1: Research the Codebase
+
+Before writing the enhanced prompt, investigate the codebase to understand:
+- Which files and directories are relevant to this task
+- Existing patterns, conventions, and code structure in those areas
+- Related functionality that may be affected
+- Any tests, configs, or documentation that should be updated
+
+Use your tools to search for files, read relevant code, and understand the current state. Focus your research on what's directly relevant to the task.
+
+### Step 2: Plan the Approach
+
+Based on your research, determine:
+- The specific files that need to be created or modified
+- The order of changes and any dependencies between them
+- Patterns to follow from existing code
+- Tests that should be run or written
+- Potential pitfalls or edge cases specific to this codebase
+
+### Step 3: Write the Enhanced Prompt
+
+Produce a detailed prompt that gives the executing agent everything it needs to complete the task without redundant exploration. Include:
+- Specific file paths discovered during research
+- Code patterns and conventions to follow (with examples from the codebase)
+- Step-by-step implementation plan grounded in the actual code structure
+- Success criteria and verification steps
+- Any caveats or constraints discovered during research
## Original Task Description
{description}
@@ -34,7 +55,7 @@ const FALLBACK_PROMPT = `You are a task prompt enhancer for an AI agent system.
## Your Enhanced Prompt
-Provide an enhanced version of this task that an AI agent can execute. Output ONLY the enhanced prompt text, nothing else. Do not include any preamble like "Here is the enhanced prompt:" - just output the prompt itself.`;
+Research the codebase, then provide an enhanced version of this task that an AI agent can execute. The prompt should be grounded in actual file paths, existing patterns, and codebase structure — not generic advice. Output ONLY the enhanced prompt text, nothing else. Do not include any preamble like "Here is the enhanced prompt:" - just output the prompt itself.`;
/**
* Enhance a task prompt using AI