opencode icon indicating copy to clipboard operation
opencode copied to clipboard

[FEATURE]: add self-reflection mechanism to improve code reliability

Open rayvoidx opened this issue 1 week ago • 1 comments

Feature hasn't been suggested before.

  • [x] I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Feature Description

To mitigate common AI coding errors such as overwrite conflicts and type mismatches, I propose adding a "Self-Reflection" mechanism to the main system prompt (anthropic.txt).

Problem

The current agent sometimes executes tool calls impulsively without verifying the context, leading to:

  • Overwrite Conflicts: Editing an outdated version of a file.
  • Type Errors: Breaking existing TypeScript definitions.
  • Over-engineering: Implementing complex solutions when simple ones exist.

Proposed Solution

Add a Critical Thinking & Self-Correction section to the system prompt that forces the agent to ask itself three critical questions before executing Edit or Write tools:

  1. "Did I read the latest version of the file?"
  2. "Does this change break existing types or tests?"
  3. "Is there a simpler way to do this?"

Expected Benefit

  • Reliability: Significantly reduces the rate of buggy code generation.
  • Safety: Prevents accidental data loss from overwriting.
  • Quality: Encourages idiomatic and simple code.

I have implemented this change in my fork and verified it locally. A PR will follow shortly.

rayvoidx avatar Jan 06 '26 05:01 rayvoidx