Skip to content

feat(opencode): add AI psychosis detector with heartbeat-based instance tracking#29183

Open
Aditya190803 wants to merge 1 commit into
anomalyco:devfrom
Aditya190803:feat/psychosis-detector
Open

feat(opencode): add AI psychosis detector with heartbeat-based instance tracking#29183
Aditya190803 wants to merge 1 commit into
anomalyco:devfrom
Aditya190803:feat/psychosis-detector

Conversation

@Aditya190803
Copy link
Copy Markdown

@Aditya190803 Aditya190803 commented May 25, 2026

Issue for this PR

Closes # (no issue — feature request from discussion)

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds an opt-in "AI psychosis detector" that warns users when they have too many opencode instances running for too long.

Each process writes a heartbeat file to ~/.config/opencode/instances/{runID}.json on startup. On check, it scans all live heartbeat files and computes severity based on instance count and duration. Cleanup happens on exit / SIGTERM; stale files (>48h) are automatically filtered.

Warnings escalate through four tiers:

  • mild (3+ instances or 12+ hours): playful tone
  • concerned (5+ instances or 12+ hours): "you might want to step away"
  • worried (8+ instances or 24+ hours): "we are genuinely concerned"
  • urgent (10+ instances or 48+ hours): wellness check

Delivery varies by mode:

  • CLI non-interactive: printed to stderr before the prompt
  • Split-footer interactive TUI: printed before the runtime lifecycle starts
  • Full TUI: toast notification, guarded by a Ctrl+P palette toggle (app.toggle.psychosis_detector)

The feature is disabled by default. Enable via opencode.json:

{ "psychosis_detector": { "enabled": true } }

How did you verify your code works?

  • bun typecheck passes cleanly
  • All 91 existing config tests pass
  • Changes are scoped to only the new feature files and the integration points

Screenshots / recordings

N/A — CLI/TUI feature, no visual changes to existing UI.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels May 25, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant