anomalyco / anomalyco/opencode

feat(tui): diff plugin generations on reconcile instead of full teardown

Open
#39,777 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Context

#39776 adds hot reloading of local TUI plugins: PluginProvider watches plugin sources and re-runs reconcile() on change. reconcile predates that PR and rebuilds the whole plugin generation imperatively: it deactivates every plugin (builtins included), wipes all registrations/slots/routes, then replays the entry list. Config plugins changes always behaved this way; hot reload just makes it fire on every file save.

Consequences per save:

  • every plugin's in-memory state resets, not just the edited one
  • all slots unmount/remount (visible churn), all routes re-register
  • manual activate/deactivate toggles from the plugins dialog reset
  • a save that fails to import drops the plugin entirely until the next successful reconcile

Proposal: fold-then-diff

Replace the imperative replay in packages/tui/src/plugin/context.tsx with:

  1. Fold the entry list (discovered files + config directives, including - disables and selectors) into a desired end state: id -> { target, version, options, enabled }. For local files, version is the entrypoint mtime, which freshSpecifier already stats.
  2. Diff against current registrations:
    • same target/version/options: leave untouched (no cleanup, no setup, slots stay mounted)
    • version or options changed: deactivate that plugin, re-import, re-activate
    • added/removed: activate/deactivate individually
    • builtins are static and never churn
  3. Keep-last-good: when a changed source fails to re-import, keep the previous instance active and mark the state failed, instead of dropping the plugin.

This mirrors the core registry's versioned-generation semantics (packages/core/src/plugin/*: replacing a plugin with the same ID retains order; only the replacement is torn down), and makes a no-change reconcile a near-no-op, so spurious watch events (sibling files in a watched parent directory) cost a readdir + stats instead of a full rebuild.

Edge semantics to decide

  • plugin renames its id on edit: treat as remove old + add new
  • options changed in config: reload that plugin
  • ordering: end-state fold must preserve current directive semantics (later entries win)

Scope

TUI only. No change to the core plugin supervisor.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in packages/tui/src/plugin/context.tsx and trace the current reconcile flow, including freshSpecifier and the PluginProvider watcher behavior described in #39776. Read the related versioned-generation logic under packages/core/src/plugin/* before resolving the listed rename, option-change, and ordering semantics. Done means unchanged plugins remain mounted, changed plugins reload individually, builtins do not churn, and failed imports retain the last good instance.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.