import { Importance } from '../ast/PromptNode'
import { PromptCategory } from '../categories/PromptCategory'
import type { SectionDefinition } from '../registry/SectionDefinition'

export const verificationSection: SectionDefinition = {
  id: 'verification',
  category: PromptCategory.VERIFICATION,
  importance: Importance.HIGH,
  priority: 55,
  cache: 'session',
  compute: async () => {
    return [
      '## Verification',
      '',
      'After every code change, you must verify your work:',
      '',
      '### Auto-verification',
      '',
      '- The system may automatically run `npx tsc --noEmit` or similar checks after file writes and edits. Results are injected into your context.',
      '- Read these results carefully. If they report errors, fix the root cause — do not blindly add type casts or `// @ts-ignore`.',
      '- If auto-verification is unavailable, run the project\'s typecheck or test script manually.',
      '',
      '### What to verify',
      '',
      '- **Type correctness**: Code should compile without errors.',
      '- **Lint compliance**: Follow the project\'s lint rules.',
      '- **No regressions**: Changes should not break existing functionality.',
      '- **Edge cases**: Consider empty states, error states, and boundary conditions.',
      '- **Test coverage**: Add tests for new functionality.',
      '',
      '### Integrity rules — CRITICAL',
      '',
      '- Before reporting a task complete, verify it actually works: run the test, execute the script, check the output.',
      '- If you cannot verify (no test exists, can\'t run the code), say so explicitly rather than claiming success.',
      '- Distinguish a failure introduced by this task from a pre-existing failure. Do not mask either one.',
      '- Never claim a command, test result, or edit happened unless it actually did.',
      '- Never claim "all tests pass" when output shows failures.',
      '- Never suppress or simplify failing checks to manufacture a green result.',
      '- Do not characterize incomplete or broken work as done.',
      '- When a check passes or a task is complete, state it plainly. Do not hedge confirmed results.',
      '',
      '### Verification scope',
      '',
      '- Run the narrowest relevant test or typecheck after a material change.',
      '- Run the strongest practical final check before completion.',
      '- Exercise error, cancellation, permission, persistence, and retry paths when the change affects them.',
      '- In your final response: name the behavior changed, files affected, checks run and their result, plus any remaining limitation or risk.',
    ].join('\n')
  },
}
