mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-07 08:26:51 +00:00
refactor: revert changes unrelated to pattern-specific rules
This PR originally attempted to fix pattern-specific rule persistence by: 1. Modifying the condensing prompt to preserve conversational rules 2. Adding debug logging for system-level custom instructions 3. Adding tests for conversational rule preservation However, pattern-specific rules (from .roo/rules/ directories) already persist correctly because: - They are loaded fresh from disk before every API request via loadRuleFiles() - The system prompt is regenerated with these rules each time - No conversation condensing affects them since they're not in conversation history The changes in this PR were addressing conversational rules (ephemeral, stated during chat) and system-level custom instructions (from settings), not pattern-specific rules. This commit reverts those unrelated changes to avoid confusion.
This commit is contained in:
parent
3f180a496d
commit
26caccbcd4
3 changed files with 13 additions and 170 deletions
|
|
@ -59,56 +59,6 @@ describe("Condense", () => {
|
|||
})
|
||||
|
||||
describe("summarizeConversation", () => {
|
||||
it("should include user rules and custom instructions in the summary prompt", async () => {
|
||||
// Create a mock handler that captures the prompt used
|
||||
let capturedPrompt = ""
|
||||
class CapturingMockApiHandler extends MockApiHandler {
|
||||
override createMessage(prompt?: any, messages?: any): any {
|
||||
capturedPrompt = prompt || ""
|
||||
const mockStream = {
|
||||
async *[Symbol.asyncIterator]() {
|
||||
yield {
|
||||
type: "text",
|
||||
text: "Summary with preserved rules:\n1. User Rules and Custom Instructions:\n- Always use TypeScript\n- Add comprehensive error handling\n2. Previous Conversation: Task discussion",
|
||||
}
|
||||
yield { type: "usage", inputTokens: 100, outputTokens: 50, totalCost: 0.01 }
|
||||
},
|
||||
}
|
||||
return mockStream
|
||||
}
|
||||
}
|
||||
|
||||
const capturingHandler = new CapturingMockApiHandler()
|
||||
const messages: ApiMessage[] = [
|
||||
{
|
||||
role: "user",
|
||||
content:
|
||||
"First message - please follow these rules: always use TypeScript and add comprehensive error handling",
|
||||
},
|
||||
{ role: "assistant", content: "I'll follow those rules" },
|
||||
{ role: "user", content: "Write a function" },
|
||||
{ role: "assistant", content: "Here's the TypeScript function with error handling" },
|
||||
{ role: "user", content: "Add more features" },
|
||||
{ role: "assistant", content: "Added features with error handling" },
|
||||
{ role: "user", content: "Great work" },
|
||||
{ role: "assistant", content: "Thank you" },
|
||||
{ role: "user", content: "Continue with the task" },
|
||||
]
|
||||
|
||||
const result = await summarizeConversation(messages, capturingHandler, "System prompt", taskId, 5000, false)
|
||||
|
||||
// Verify the prompt includes instructions about preserving user rules
|
||||
expect(capturedPrompt).toContain("User Rules and Custom Instructions")
|
||||
expect(capturedPrompt).toContain(
|
||||
"CRITICAL: You must preserve any user-defined rules, custom instructions, or specific guidelines",
|
||||
)
|
||||
|
||||
// Verify the summary includes the preserved rules
|
||||
expect(result.summary).toContain("User Rules and Custom Instructions")
|
||||
expect(result.summary).toContain("TypeScript")
|
||||
expect(result.summary).toContain("error handling")
|
||||
})
|
||||
|
||||
it("should preserve the first message when summarizing", async () => {
|
||||
const messages: ApiMessage[] = [
|
||||
{ role: "user", content: "First message with /prr command content" },
|
||||
|
|
@ -254,87 +204,6 @@ describe("Condense", () => {
|
|||
expect(result.messages).toEqual(messages)
|
||||
expect(result.cost).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
it("should preserve user rules when using custom condensing prompt", async () => {
|
||||
// Mock handler that returns a summary with rules preserved
|
||||
class RulesPreservingMockApiHandler extends MockApiHandler {
|
||||
override createMessage(): any {
|
||||
const mockStream = {
|
||||
async *[Symbol.asyncIterator]() {
|
||||
// Simulate a summary that includes user rules
|
||||
yield {
|
||||
type: "text",
|
||||
text: "Summary:\n1. User Rules and Custom Instructions:\n- Use async/await patterns\n- Follow ESLint rules\n2. Previous Conversation: Development work\n3. Current Work: Implementing features",
|
||||
}
|
||||
yield { type: "usage", inputTokens: 150, outputTokens: 75, totalCost: 0.015 }
|
||||
},
|
||||
}
|
||||
return mockStream
|
||||
}
|
||||
}
|
||||
|
||||
const rulesHandler = new RulesPreservingMockApiHandler()
|
||||
const customPrompt =
|
||||
"Create a summary that includes all user rules and custom instructions at the beginning."
|
||||
|
||||
const messages: ApiMessage[] = [
|
||||
{
|
||||
role: "user",
|
||||
content: "Please follow these rules: use async/await patterns and follow ESLint rules",
|
||||
},
|
||||
{ role: "assistant", content: "I'll follow those coding standards" },
|
||||
{ role: "user", content: "Implement the API" },
|
||||
{ role: "assistant", content: "API implemented with async/await" },
|
||||
{ role: "user", content: "Add validation" },
|
||||
{ role: "assistant", content: "Validation added following ESLint" },
|
||||
{ role: "user", content: "Perfect" },
|
||||
{ role: "assistant", content: "Thank you" },
|
||||
{ role: "user", content: "Continue" },
|
||||
]
|
||||
|
||||
const result = await summarizeConversation(
|
||||
messages,
|
||||
rulesHandler,
|
||||
"System prompt",
|
||||
taskId,
|
||||
5000,
|
||||
false,
|
||||
customPrompt,
|
||||
rulesHandler,
|
||||
)
|
||||
|
||||
// Verify the summary includes user rules
|
||||
expect(result.summary).toContain("User Rules and Custom Instructions")
|
||||
expect(result.summary).toContain("async/await")
|
||||
expect(result.summary).toContain("ESLint")
|
||||
|
||||
// Verify the summary message is marked as a summary
|
||||
const summaryMessage = result.messages.find((msg) => msg.isSummary)
|
||||
expect(summaryMessage).toBeTruthy()
|
||||
expect(summaryMessage?.content).toContain("User Rules")
|
||||
})
|
||||
|
||||
it("should handle summaries without user rules gracefully", async () => {
|
||||
// This tests backward compatibility - summaries that don't have explicit user rules section
|
||||
const messages: ApiMessage[] = [
|
||||
{ role: "user", content: "First message" },
|
||||
{ role: "assistant", content: "Response" },
|
||||
{ role: "user", content: "Continue" },
|
||||
{ role: "assistant", content: "Continuing" },
|
||||
{ role: "user", content: "More work" },
|
||||
{ role: "assistant", content: "Working" },
|
||||
{ role: "user", content: "Final task" },
|
||||
{ role: "assistant", content: "Completed" },
|
||||
{ role: "user", content: "Thanks" },
|
||||
]
|
||||
|
||||
const result = await summarizeConversation(messages, mockApiHandler, "System prompt", taskId, 5000, false)
|
||||
|
||||
// Should still produce a valid summary even without explicit rules
|
||||
expect(result.summary).toBeTruthy()
|
||||
expect(result.error).toBeUndefined()
|
||||
expect(result.messages.length).toBeGreaterThan(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe("getMessagesSinceLastSummary", () => {
|
||||
|
|
|
|||
|
|
@ -15,33 +15,25 @@ const SUMMARY_PROMPT = `\
|
|||
Your task is to create a detailed summary of the conversation so far, paying close attention to the user's explicit requests and your previous actions.
|
||||
This summary should be thorough in capturing technical details, code patterns, and architectural decisions that would be essential for continuing with the conversation and supporting any continuing tasks.
|
||||
|
||||
CRITICAL: You must preserve any user-defined rules, custom instructions, or specific guidelines that have been established during this conversation. These rules shape how you should behave and respond throughout the entire task.
|
||||
|
||||
Your summary should be structured as follows:
|
||||
Context: The context to continue the conversation with. If applicable based on the current task, this should include:
|
||||
1. User Rules and Custom Instructions: List ALL user-defined rules, custom instructions, or specific guidelines that have been established. These could be about code style, communication style, technical preferences, or any other behavioral instructions. This is CRITICAL for maintaining consistency.
|
||||
2. Previous Conversation: High level details about what was discussed throughout the entire conversation with the user. This should be written to allow someone to be able to follow the general overarching conversation flow.
|
||||
3. Current Work: Describe in detail what was being worked on prior to this request to summarize the conversation. Pay special attention to the more recent messages in the conversation.
|
||||
4. Key Technical Concepts: List all important technical concepts, technologies, coding conventions, and frameworks discussed, which might be relevant for continuing with this work.
|
||||
5. Relevant Files and Code: If applicable, enumerate specific files and code sections examined, modified, or created for the task continuation. Pay special attention to the most recent messages and changes.
|
||||
6. Problem Solving: Document problems solved thus far and any ongoing troubleshooting efforts.
|
||||
7. Pending Tasks and Next Steps: Outline all pending tasks that you have explicitly been asked to work on, as well as list the next steps you will take for all outstanding work, if applicable. Include code snippets where they add clarity. For any next steps, include direct quotes from the most recent conversation showing exactly what task you were working on and where you left off. This should be verbatim to ensure there's no information loss in context between tasks.
|
||||
1. Previous Conversation: High level details about what was discussed throughout the entire conversation with the user. This should be written to allow someone to be able to follow the general overarching conversation flow.
|
||||
2. Current Work: Describe in detail what was being worked on prior to this request to summarize the conversation. Pay special attention to the more recent messages in the conversation.
|
||||
3. Key Technical Concepts: List all important technical concepts, technologies, coding conventions, and frameworks discussed, which might be relevant for continuing with this work.
|
||||
4. Relevant Files and Code: If applicable, enumerate specific files and code sections examined, modified, or created for the task continuation. Pay special attention to the most recent messages and changes.
|
||||
5. Problem Solving: Document problems solved thus far and any ongoing troubleshooting efforts.
|
||||
6. Pending Tasks and Next Steps: Outline all pending tasks that you have explicitly been asked to work on, as well as list the next steps you will take for all outstanding work, if applicable. Include code snippets where they add clarity. For any next steps, include direct quotes from the most recent conversation showing exactly what task you were working on and where you left off. This should be verbatim to ensure there's no information loss in context between tasks.
|
||||
|
||||
Example summary structure:
|
||||
1. User Rules and Custom Instructions:
|
||||
- [Rule 1: e.g., "Always use TypeScript strict mode"]
|
||||
- [Rule 2: e.g., "Prefer functional programming patterns"]
|
||||
- [Rule 3: e.g., "Add comprehensive error handling"]
|
||||
- [Any other user-defined guidelines or preferences]
|
||||
2. Previous Conversation:
|
||||
1. Previous Conversation:
|
||||
[Detailed description]
|
||||
3. Current Work:
|
||||
2. Current Work:
|
||||
[Detailed description]
|
||||
4. Key Technical Concepts:
|
||||
3. Key Technical Concepts:
|
||||
- [Concept 1]
|
||||
- [Concept 2]
|
||||
- [...]
|
||||
5. Relevant Files and Code:
|
||||
4. Relevant Files and Code:
|
||||
- [File Name 1]
|
||||
- [Summary of why this file is important]
|
||||
- [Summary of the changes made to this file, if any]
|
||||
|
|
@ -49,9 +41,9 @@ Example summary structure:
|
|||
- [File Name 2]
|
||||
- [Important Code Snippet]
|
||||
- [...]
|
||||
6. Problem Solving:
|
||||
5. Problem Solving:
|
||||
[Detailed description]
|
||||
7. Pending Tasks and Next Steps:
|
||||
6. Pending Tasks and Next Steps:
|
||||
- [Task 1 details & next steps]
|
||||
- [Task 2 details & next steps]
|
||||
- [...]
|
||||
|
|
|
|||
|
|
@ -2538,15 +2538,6 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
|
|||
|
||||
const state = await this.providerRef.deref()?.getState()
|
||||
|
||||
// Debug logging to track custom instructions persistence
|
||||
if (!state) {
|
||||
console.warn(
|
||||
`[Task#${this.taskId}] getSystemPrompt: state is undefined, custom instructions may be missing`,
|
||||
)
|
||||
} else if (!state.customInstructions && !state.customModePrompts) {
|
||||
console.debug(`[Task#${this.taskId}] getSystemPrompt: No custom instructions or mode prompts in state`)
|
||||
}
|
||||
|
||||
const {
|
||||
browserViewportSize,
|
||||
mode,
|
||||
|
|
@ -2580,15 +2571,6 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
|
|||
|
||||
const canUseBrowserTool = modelSupportsBrowser && modeSupportsBrowser && (browserToolEnabled ?? true)
|
||||
|
||||
// Ensure custom instructions are passed even if empty string
|
||||
const effectiveCustomInstructions = customInstructions ?? ""
|
||||
|
||||
// Log system prompt generation for debugging
|
||||
console.debug(
|
||||
`[Task#${this.taskId}] Generating system prompt with mode: ${mode ?? defaultModeSlug}, ` +
|
||||
`customInstructions: ${effectiveCustomInstructions.length} chars`,
|
||||
)
|
||||
|
||||
return SYSTEM_PROMPT(
|
||||
provider.context,
|
||||
this.cwd,
|
||||
|
|
@ -2599,7 +2581,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
|
|||
mode ?? defaultModeSlug,
|
||||
customModePrompts,
|
||||
customModes,
|
||||
effectiveCustomInstructions,
|
||||
customInstructions,
|
||||
this.diffEnabled,
|
||||
experiments,
|
||||
enableMcpServerCreation,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue