Skip to content

Phase 2: Runtime integration for menus, actions, help, console, history, and bundled plugins #114

Closed

Description

@suraj-ranganath

Summary

Wire registered extensions into the real EEGPrep user experience: main-window menus, action dispatch, help resources, pop_* public functions, eegprep-console, EEGPrepSession, and history.

Key Work

  • Let extension specs contribute MenuItemSpec items by stable menu path/tag instead of direct Qt mutation.
  • Let extension specs register GUI actions and pop_* callables through a registry-backed dispatcher.
  • Ensure extension pop_* functions can support return_com=True and valid Python console command echo.
  • Expose registered extension pop_* functions in eegprep-console wrappers with the same auto-store/history behavior as built-in functions.
  • Add help-resource lookup for extension-packaged Markdown resources.
  • Refactor bundled plugin menu contributions to use the same extension path where practical, without broad unrelated churn.
  • Preserve include_plugins=False and --no-plugins behavior.
  • Keep GUI refresh and session synchronization centralized through EEGPrepSession helpers.

Edge Cases To Cover

  • Extension menu action enabled/disabled state across startup, no dataset, continuous, epoched, ICA present/absent, STUDY, and multi-dataset states.
  • Extension action raises after the menu is clicked.
  • Extension action returns EEG only, (EEG, com), command only, or no mutation.
  • Extension help resource missing or malformed.
  • Extension command should be shown in console and history exactly once.
  • Two extensions try to add the same menu/action.
  • Extension contributes a menu under a missing path.

Acceptance Criteria

  • A fake test extension can add a menu item, run an action, update EEG, append history, and refresh the GUI/session.
  • The same fake extension works from eegprep-console with bare and assigned pop_* calls.
  • Built-in bundled plugins still appear and behave as before.
  • --no-plugins hides extension contributions without hiding core menus.
  • Tests cover menu inventory, dispatcher behavior, console namespace/history, help lookup, and failure handling.
  • GUI-visible changes use visual parity checks where menus/dialogs change.

/goal Prompt

/goal Integrate registered EEGPrep extensions into menu construction, action dispatch, help resources, eegprep-console, EEGPrepSession synchronization, and history. Refactor bundled plugins only as needed to share the extension path. Verify with fake extension tests, bundled plugin regression tests, GUI/menu inventory tests, console/history tests, visual checks for visible changes, and lint/type/focused pytest.

Activity

  1. added
    phase
    on Jun 2, 2026
  2. claude commented on Jun 2, 2026

    @claude
    Contributor

    🤖 Plan:

    Research

    Phase 2 wires a registry-backed extension system into menus, dispatch, help, console, and history. It depends on the Phase 1 SDK (#113), which is still open and not present in the codebase — there is no ExtensionSpec, no registry module, no eegprep.extensions entry-point group, and no pyproject.toml entry-point group declaration. Today's only "extension" surface is a hardcoded bundled-plugin inventory plus dispatcher branches; everything Phase 2 lists ("registered extensions", "registry-backed dispatcher", "extension help-resource lookup") presumes the Phase 1 contract.

    Today's integration points Phase 2 must extend (all currently hardcoded for the five bundled plugins):

    Relevant code

    • src/eegprep/functions/adminfunc/plugin_menu.py#L14-L80 — frozen tuple of bundled plugin records (no discovery)
    • src/eegprep/functions/guifunc/eeglab_menu.py#L380-L455 — eeglab_menus(..., include_plugins=...); plugin items spliced by hardcoded _insert_* helpers
    • src/eegprep/functions/guifunc/menu_spec.py#L12-L29 — MenuItemSpec (already has origin, tag; suitable contribution unit)
    • src/eegprep/functions/guifunc/menu_actions.py#L208-L436 — MenuActionDispatcher.dispatch is a long if base == ... chain; no registry hook
    • src/eegprep/functions/adminfunc/console.py#L345-L389 — namespace bind iterates eegprep.__all__; only built-in pop_* get ConsolePopFunction wrappers
    • src/eegprep/functions/guifunc/pophelp.py#L12-L93 — help lookup is hardwired to eegprep.resources.help package, no per-extension fallback
    • src/eegprep/functions/adminfunc/eeglab.py#L19-L112 and console.py#L443-L462 — --no-plugins / include_plugins already plumbed into eeglab_menus; Phase 2 needs to honor this for extensions too

    Proposed Approach

    Scope is multi-module (menus, dispatcher, console, help, session) and almost certainly >500 LOC across src/eegprep/functions/{adminfunc,guifunc}/ plus tests. Per fix-issue/SKILL.md this requires a design comment, not a PR. Phase 2 should not start until Phase 1 (#113) merges, because every section below names a Phase 1 type.

    Design sketch:

    1. Registry contract (consumed, not defined here). Phase 1 owns ExtensionSpec (name, version, api_version, package, menus, actions, pop_funcs, help_resources, status) and a registry that exposes iter_active_extensions() and lazy load_action(name). Phase 2 only imports those and never reads entry points directly. If Phase 1 lands with a different shape, the integration points below adapt; the structure does not change.

    2. Menu contribution by path/tag. Each ExtensionSpec contributes a list of (parent_path, MenuItemSpec) where parent_path is a stable tag tuple like ("file", "import") or ("tools", "filter"). Add an apply_extension_menus(core_menus, extensions) helper next to eeglab_menus that walks the spec tree and inserts contributions immutably (mirrors today's _insert_* helpers but data-driven). eeglab_menus(include_plugins=False) already skips bundled inserts; gate extension inserts on the same flag. Two extensions hitting the same parent path append in deterministic (name, version) order; missing path logs a warning and skips that contribution (per Phase 1 failure-isolation rule). Mark extension-origin items with origin="extension:<name>" so menu_to_inventory and visual-parity tests can distinguish them.

    3. Action dispatcher hook. Replace the long if base == ... ladder for extension actions with a registry lookup at the top of dispatch(): if base is an extension-registered action and not a core/bundled action, call registry.load_action(base)(self.session, parent, variant=variant, return_com=True). Core actions are untouched. The handler contract is (EEG_or_None, command_or_None):

      • returns (EEG, com) → session.store_current(eeg, command=com)
      • returns EEG alone → store_current(eeg, command="") and synthesize EEG = <name>(EEG, ...) history (mirrors _run_pop_function)
      • returns (None, com) → session.add_history(com) only (no mutation)
      • returns None → log and exit, no history
      • raises → existing dispatch_gui try/except already shows the warning; logs include the extension name
        Bundled plugins keep their dedicated branches; the comment from issue 114 explicitly says refactor those "without broad unrelated churn" — only migrate one (e.g. pop_iclabel) opportunistically as proof-of-concept.
    4. Console namespace and history. Extend EEGPrepConsoleWorkspace._bind_exports (console.py#L349-L359) so after binding eegprep.__all__ it also iterates active extensions and binds each registered pop_* callable through ConsolePopFunction(name, self, fn). This automatically gives bare pop_foo(EEG, ...) auto-store, history echo, and return_com handling because ConsolePopFunction already does that. Update _restore_imported_wrappers to recognize from <ext_pkg> import pop_foo aliases too (use the registry to know which import paths are extension pop_*).

    5. Help-resource lookup. Add an optional package argument to pophelp_text(function_name, *, package=None) defaulting to HELP_PACKAGE. For extension-owned functions, the registry maps pop_<name> → declaring package's help subpackage (e.g. myext.resources.help); call sites in extension pop_* use the same pophelp('<name>') string. Missing/malformed resources stay loud per AGENTS.md ("missing help resources should fail clearly").

    6. Session synchronization. All session writes already go through store_current, add_history, notify_changed — Phase 2 must not introduce GUI-only mutation paths. Add a MenuActionDispatcher helper _run_extension_action(name, parent, variant) that mirrors _run_pop_function so refresh, history, and command echo behave identically.

    7. include_plugins=False / --no-plugins. Already gates bundled menu inserts in eeglab_menus; extend the same gate to extension contributions and to the console namespace bind (skip extension pop_* wrappers under the flag). Core menus remain untouched in both modes.

    8. Tests (extend, do not duplicate):

      • tests/test_eeglab_menu.py — fake extension with one menu item under each top-level path; duplicate contribution; missing path; include_plugins=False parity
      • tests/test_menu_actions.py — fake extension action exercising all four return shapes plus the raise case; agent-generated history string check
      • tests/test_console_workspace.py — bare pop_fakeext(EEG) auto-stores; from fakeext import pop_fakeext as f aliases through _restore_imported_wrappers; command echoed exactly once
      • tests/test_pophelp.py (or nearest) — extension-packaged Markdown found; missing resource raises cleanly
      • tests/test_plugin_menu.py — bundled inventory regression unchanged
      • GUI visual-parity case under tools/visual_parity/ for any menu the extension touches
    9. Out of scope for this issue. Extension Manager UX (Phase 3: Extension Manager UX, curated catalog metadata, and safe install guidance #115), curated catalog (Phase 5: Governance, security, catalog validation, compatibility policy, and extension test harness #117), authoring toolkit (Phase 4: Researcher authoring toolkit, template package, examples, and scaffolding #116), full bundled-plugin migration to the new path. Mention bundled-plugin migration as follow-up.

    Open questions for the human reviewer before implementation:

    • Phase 1 PR is not open yet; should Phase 2 block on its merge, or proceed against a stubbed Phase 1 contract on a long-lived feature/eegprep-extension-completion branch as the epic (Epic: Build EEGPrep external extension ecosystem #112) suggests?
    • Which bundled plugin (if any) should be the proof-of-concept migration to the new contribution path in this PR? Suggest firfilt because its menu insertion is the cleanest.
    • Should extension pop_* functions appear in eegprep.__all__ / dir(eegprep) automatically, or stay namespaced under eegprep.extensions.<name>? Affects discoverability vs. namespace pollution.
    • For the dispatcher, prefer (a) a single extensions branch at the top of dispatch() that delegates to the registry, or (b) a precomputed action_handlers: dict[str, Callable] map built once at dispatcher construction? (b) is cleaner but requires registry events when extensions are enabled/disabled at runtime — is runtime enable/disable in scope for Phase 2 or deferred to Phase 3: Extension Manager UX, curated catalog metadata, and safe install guidance #115?

    Awaiting reviewer direction before opening a PR.

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

Metadata

Metadata

Labels

phase

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions