mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
fix(cli): fix prompt issue in mcp configure claude-code (#17599)
* Updates default Coder prompt. * Skips the directions to report tasks if the pre-requisites are not available (agent token and app slug). * Adds the capability to override the default Coder prompt via `CODER_MCP_CLAUDE_CODER_PROMPT`.
This commit is contained in:
@ -114,6 +114,7 @@ func (*RootCmd) mcpConfigureClaudeCode() *serpent.Command {
|
||||
claudeConfigPath string
|
||||
claudeMDPath string
|
||||
systemPrompt string
|
||||
coderPrompt string
|
||||
appStatusSlug string
|
||||
testBinaryName string
|
||||
|
||||
@ -176,8 +177,27 @@ func (*RootCmd) mcpConfigureClaudeCode() *serpent.Command {
|
||||
}
|
||||
cliui.Infof(inv.Stderr, "Wrote config to %s", claudeConfigPath)
|
||||
|
||||
// Determine if we should include the reportTaskPrompt
|
||||
var reportTaskPrompt string
|
||||
if agentToken != "" && appStatusSlug != "" {
|
||||
// Only include the report task prompt if both agent token and app
|
||||
// status slug are defined. Otherwise, reporting a task will fail
|
||||
// and confuse the agent (and by extension, the user).
|
||||
reportTaskPrompt = defaultReportTaskPrompt
|
||||
}
|
||||
|
||||
// If a user overrides the coder prompt, we don't want to append
|
||||
// the report task prompt, as it then becomes the responsibility
|
||||
// of the user.
|
||||
actualCoderPrompt := defaultCoderPrompt
|
||||
if coderPrompt != "" {
|
||||
actualCoderPrompt = coderPrompt
|
||||
} else if reportTaskPrompt != "" {
|
||||
actualCoderPrompt += "\n\n" + reportTaskPrompt
|
||||
}
|
||||
|
||||
// We also write the system prompt to the CLAUDE.md file.
|
||||
if err := injectClaudeMD(fs, systemPrompt, claudeMDPath); err != nil {
|
||||
if err := injectClaudeMD(fs, actualCoderPrompt, systemPrompt, claudeMDPath); err != nil {
|
||||
return xerrors.Errorf("failed to modify CLAUDE.md: %w", err)
|
||||
}
|
||||
cliui.Infof(inv.Stderr, "Wrote CLAUDE.md to %s", claudeMDPath)
|
||||
@ -222,6 +242,14 @@ func (*RootCmd) mcpConfigureClaudeCode() *serpent.Command {
|
||||
Value: serpent.StringOf(&systemPrompt),
|
||||
Default: "Send a task status update to notify the user that you are ready for input, and then wait for user input.",
|
||||
},
|
||||
{
|
||||
Name: "coder-prompt",
|
||||
Description: "The coder prompt to use for the Claude Code server.",
|
||||
Env: "CODER_MCP_CLAUDE_CODER_PROMPT",
|
||||
Flag: "claude-coder-prompt",
|
||||
Value: serpent.StringOf(&coderPrompt),
|
||||
Default: "", // Empty default means we'll use defaultCoderPrompt from the variable
|
||||
},
|
||||
{
|
||||
Name: "app-status-slug",
|
||||
Description: "The app status slug to use when running the Coder MCP server.",
|
||||
@ -567,22 +595,25 @@ func configureClaude(fs afero.Fs, cfg ClaudeConfig) error {
|
||||
}
|
||||
|
||||
var (
|
||||
coderPrompt = `YOU MUST REPORT YOUR STATUS IMMEDIATELY AFTER EACH USER MESSAGE.
|
||||
INTERRUPT READING FILES OR ANY OTHER TOOL CALL IF YOU HAVE NOT REPORTED A STATUS YET.
|
||||
You MUST use the mcp__coder__coder_report_task function with all required parameters:
|
||||
- summary: Short description of what you're doing
|
||||
- link: A relevant link for the status
|
||||
- done: Boolean indicating if the task is complete (true/false)
|
||||
- emoji: Relevant emoji for the status
|
||||
- need_user_attention: Boolean indicating if the task needs user attention (true/false)
|
||||
WHEN TO REPORT (MANDATORY):
|
||||
1. IMMEDIATELY after receiving ANY user message, before any other actions
|
||||
2. After completing any task
|
||||
3. When making significant progress
|
||||
4. When encountering roadblocks
|
||||
5. When asking questions
|
||||
6. Before and after using search tools or making code changes
|
||||
FAILING TO REPORT STATUS PROPERLY WILL RESULT IN INCORRECT BEHAVIOR.`
|
||||
defaultCoderPrompt = `You are a helpful Coding assistant. Aim to autonomously investigate
|
||||
and solve issues the user gives you and test your work, whenever possible.
|
||||
Avoid shortcuts like mocking tests. When you get stuck, you can ask the user
|
||||
but opt for autonomy.`
|
||||
|
||||
defaultReportTaskPrompt = `YOU MUST REPORT ALL TASKS TO CODER.
|
||||
When reporting tasks, you MUST follow these EXACT instructions:
|
||||
- IMMEDIATELY report status after receiving ANY user message.
|
||||
- Be granular. If you are investigating with multiple steps, report each step to coder.
|
||||
|
||||
Task state MUST be one of the following:
|
||||
- Use "state": "working" when actively processing WITHOUT needing additional user input.
|
||||
- Use "state": "complete" only when finished with a task.
|
||||
- Use "state": "failure" when you need ANY user input, lack sufficient details, or encounter blockers.
|
||||
|
||||
Task summaries MUST:
|
||||
- Include specifics about what you're doing.
|
||||
- Include clear and actionable steps for the user.
|
||||
- Be less than 160 characters in length.`
|
||||
|
||||
// Define the guard strings
|
||||
coderPromptStartGuard = "<coder-prompt>"
|
||||
@ -591,7 +622,7 @@ FAILING TO REPORT STATUS PROPERLY WILL RESULT IN INCORRECT BEHAVIOR.`
|
||||
systemPromptEndGuard = "</system-prompt>"
|
||||
)
|
||||
|
||||
func injectClaudeMD(fs afero.Fs, systemPrompt string, claudeMDPath string) error {
|
||||
func injectClaudeMD(fs afero.Fs, coderPrompt, systemPrompt, claudeMDPath string) error {
|
||||
_, err := fs.Stat(claudeMDPath)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
|
Reference in New Issue
Block a user