Skip to content

[Extensions] Add external extension ecosystem - #127

Merged
arnodelorme merged 69 commits into
developfrom
feature/eegprep-extension-completion
Jun 4, 2026
Merged

arnodelorme merged 69 commits into
developfrom
feature/eegprep-extension-completion

Conversation

@suraj-ranganath

@suraj-ranganath suraj-ranganath commented Jun 3, 2026 •

Copy link
Copy Markdown
Member

Add external extension SDK, entry-point discovery, runtime menu/help/console integration, Extension Manager/catalog UX, authoring examples, governance validation, and closeout hardening. Stacked on the previous EEGBrowser epic PR #111; review after that merges.

Fixes #112

[EEGBrowser] Implement eegplot browser foundation
Implement EEGBrowser Phase 2 UI shell
…nto phase/eegbrowser-3-marking

# Conflicts:
#	src/eegprep/functions/guifunc/eegbrowser.py
#	src/eegprep/functions/sigprocfunc/eegplot.py
#	tests/test_eegplot.py
[EEGBrowser] Add marking and rejection callbacks
Implement pop_eegplot menu session workflows
[EEGBrowser] Integrate rejection workflows
Implement advanced EEGBrowser display modes
[Extensions] Integrate runtime contributions
Add extension governance validation tooling
# Conflicts:
#	docs/source/api/extensions.rst
#	src/eegprep/__init__.py
#	src/eegprep/functions/adminfunc/plugin_menu.py
#	tests/test_package_exports.py
# Conflicts:
#	docs/source/api/extensions.rst
# Conflicts:
#	docs/source/user_guide/extensions.rst
#	docs/source/user_guide/index.rst
@claude

claude Bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 8m 12s —— View job


Code review — PR #127 (extension ecosystem)

Reviewed the extension-specific scope (git diff c18bb02..HEAD, ~9k lines: SDK/registry, entry-point discovery, runtime menu/help/console integration, Extension Manager catalog, governance tooling, and the five authoring examples). The EEGBrowser-epic files in the GitHub diff belong to the stacked base branch and were not re-reviewed here.

  • Overall assessment: Needs changes — two reachable GUI-dispatch bugs demonstrated by the shipped example extensions.
  • Highest-risk area: menu_actions.py extension action dispatch / result handling (_call_extension_target, _apply_extension_result, _is_eeg_selection).
  • Merge recommendation: Needs changes.

The SDK, registry, declarative-menu insertion, packaged-help routing (pophelp core-over-extension precedence), catalog parsing, and security posture (no network fetch, shlex.quoted non-executed install commands, escaped HTML, isolated entry_point.load() with --no-plugins opt-out) are all solid. Findings below are concentrated in GUI dispatch + a schema-collision trap.

Blocking

  • Importer-style extension actions get the current dataset forced as their first positional arg. menu_actions.py:961-965 — the pop_-prefix branch always passes the current EEG as positional 1. The canonical File>Import example pop_demo_import_csv(filename, …) thus receives EEG as filename (crashes), and won't run with no dataset loaded (importers must). Inline comment · Fix this →

  • Plot/browser model dicts get stored as datasets, silently corrupting CURRENTSET. menu_actions.py:1665-1668 — _is_eeg_selection treats any dict with setname (or nbchan/data) as an EEG. The Plot>Browser example returns a browser model dict + LASTCOM = …; _apply_extension_result stores it as the current dataset. EEGLAB plot actions only set LASTCOM. Fix: require data plus a second core field, and honor the LASTCOM = vs EEG = command-prefix convention. Inline comment

Both bugs live in core dispatch (_run_extension_action → _call_extension_target → _apply_extension_result) and are reachable from the menu — they happen to be exposed by two of the five shipped authoring examples, which are the documented reference for extension authors.

Important

  • Two incompatible JSON schemas share the "extension catalog" name, schema_version: 1, and the EEGPREP_EXTENSION_CATALOG file. extension_catalog.py ships a GUI/runtime loader (parse_extension_catalog → _parse_catalog_entry, requires name/source.url/package_name) and a separate curation/CLI loader (validate_catalog_entries, requires id/entry_point/extension_name/license/maintainer{}/source_url). The curation docs (extension_curation.rst) document the second schema, but the GUI manager loads EEGPREP_EXTENSION_CATALOG through the first parser — so a real curated catalog.json silently yields an empty GUI catalog (name is required). Nothing breaks today only because the packaged file is extensions: []. Disambiguate the two paths (distinct filenames/schema markers) and state in docs which loader consumes which.

  • Local imports without a cycle/optional-dependency justification. extensions.py:304-312 (_bundled_records) imports the five bundled-plugin menu modules inside the function body. AGENTS.md: "All imports go at the top. No local imports except for circular dependency breaks or optional dependency guards." Those modules only import menu_spec (stdlib-only), so there's no cycle to break — hoist them to module top, or add a comment if lazy-loading is deliberate.

Nits

  • extensions.py:967-993 _version_satisfies / _version_parts (re.findall(r"\d+")) silently degrades PEP440 prereleases (1.0.0a1) and malformed eegprep_requires specs to an == digit comparison instead of flagging invalid_spec. Catalog-side _VERSION_SPEC_RE gates the well-formed path, so low impact.
  • Display-path catalog parsing (_parse_catalog_entry) validates archive shape but not URL scheme, while the CI validator rejects non-http schemes via _is_web_url. A local catalog with "docs_url": "javascript:…" renders as a clickable Qt link. Apply the same scheme check on the display path.
  • Duplicated version helpers: plugin_menu.py:937-951 (_compare_version_parts/_version_parts) and extension_catalog.py:945 (_major_version) reimplement logic already in extensions.py (extension_version_satisfies). AGENTS.md discourages "Parallel implementations of existing helpers."
  • _call_extension_target injects a variant kwarg with no documented consumer or example — edges toward "No speculative configurability."

Test gaps

  • Console-workspace coverage missing. AGENTS.md requires console-reachable functions to be covered in tests/test_console_workspace.py for namespace sync / history / auto-store. That suite has zero extension references; extension pop_* console wiring is only tested in test_extension_integration.py/test_extension_runtime.py. Add a case constructing the workspace with an extension_runtime and asserting (a) the extension pop appears in namespace, (b) a bare call auto-stores once via after_execute.
  • from eegprep import <ext_pop> restore path unverified. console.py:_restore_imported_wrappers rebinds any pop_* alias via pop_wrapper (now extension-aware), but extension pops aren't importable from eegprep — pin the intended behavior with a test.
  • 4-tuple dataset-state result untested. _extension_dataset_state/_apply_extension_result handle an action returning (ALLEEG, EEG, CURRENTSET, command) and write session.ALLEEG/CURRENTSET, but test_extension_action_result_shapes_* only covers EEG-only, (EEG, com), command-only, and None. Add a 4-tuple case.

EEGLAB parity notes

  • The LASTCOM = vs EEG = command-prefix convention is the EEGLAB signal for "history-only vs store-dataset." Wiring _apply_extension_result to that prefix (rather than duck-typing the return dict) would fix the browser bug and make extension behavior predictable for EEGLAB users.
  • EXTENSION_NAMING_PREFIX = "eegprep-ext-" is exported but not enforced in validate_extension_spec, and there's no warning when an extension pop/action name shadows a core EEGPrep function (core silently wins). Both are advisory-only today; a doc note or a shadow warning would help authors.
    · branch feature/eegprep-extension-completion

@suraj-ranganath

Copy link
Copy Markdown
Member Author

🤖 Detailed epic specification and closeout notes for #127.

Stacking note

This PR targets origin/develop but is stacked on the EEGBrowser epic branch. Please merge or retarget after #111 lands; until then, the full diff against develop includes both the already-reviewed EEGBrowser stack and the isolated extension ecosystem delta. The extension-only delta is feature/eegbrowser-completion...feature/eegprep-extension-completion: 66 files, 8975 insertions, 168 deletions.

Parent epic

Fixes #112, Epic: Build EEGPrep external extension ecosystem.

Constituent phase issues

Phase 1, #113: Extension SDK, registry, discovery, and compatibility contract. Added the public extension SDK in src/eegprep/extensions.py: ExtensionSpec, ExtensionAction, ExtensionPopFunction, ExtensionMenu, ExtensionResource, LazyImport, ExtensionDependency, ExtensionRegistry, validation helpers, status/source enums, duplicate contribution detection, failed-import isolation, disabled/incompatible/missing-dependency states, and entry-point discovery through eegprep.extensions.

Phase 2, #114: Runtime integration for menus, actions, help, console, history, and bundled plugins. Added src/eegprep/extension_runtime.py and integrated registered extensions with the main menu tree, MenuActionDispatcher, pophelp, EEGPrepMainWindow, eegprep-console, and EEGPrepSession history/command echo behavior. Bundled plugin surfaces now share the same extension record model as external packages while still supporting --no-plugins.

Phase 3, #115: Extension Manager UX, curated catalog metadata, and safe install guidance. Expanded plugin_menu into the EEGPrep Extension Manager. It lists bundled, installed, curated-only, disabled, incompatible, missing-dependency, invalid, unknown, and failed extensions; shows details, errors, catalog conflicts, trust warnings, copyable uv/pip install/update commands, and never downloads, installs, updates, removes, or unzips code.

Phase 4, #116: Researcher authoring toolkit, template package, examples, and scaffolding. Added examples/extensions with a reusable template package, file I/O, GUI dialog, optional dependency, browser/plot, and signal-transform examples. Added extension author checklist and tests that show how to register menus, pop_* functions, help resources, sample data, package resources, and pyproject entry points.

Phase 4b, #119: Extension docs, trust levels, and agent skill. Added docs/source/user_guide/extensions.rst, docs/source/user_guide/extension_curation.rst, docs/source/api/extensions.rst, and the .agents/skills/eegprep-extension-development skill. The docs explain PyPI, GitHub, editable local, and private-index install paths; required extension format; trust levels; package-resource rules; console/history expectations; and the curated catalog process.

Phase 5, #117: Governance, security, catalog validation, compatibility policy, and extension test harness. Added src/eegprep/extension_catalog.py, tools/validate_extension_catalog.py, the eegprep-validate-extension-catalog CLI entry point, ExtensionTestHarness, catalog validation reports, curated metadata checks, package/entry-point verification, import checks, archive rejection, version compatibility policy, and trust-boundary messaging.

Phase 6, #118: Cross-platform hardening, performance, integration QA, and epic closeout. Added cross-platform-style tests for paths with spaces, real dist-info entry-point discovery, no-plugin startup safety, lazy startup checks, public API exports, package resource behavior, manager rendering, catalog validator CLI, and closeout docs. Final cleanup kept import eegprep lightweight and ensured extension entry points are not loaded at import time.

What this enables

Researchers can now build EEGPrep extensions as normal Python packages instead of asking maintainers to manually host or add zip submissions. Extensions can be distributed through PyPI, GitHub, editable local installs, private package indexes, or private lab repositories, then discovered in the same environment through Python entry points.

Extensions can declaratively contribute menu actions, pop_* functions, packaged help, package data, capabilities, dependencies, and compatibility metadata. GUI users see menu contributions automatically; console users get registered pop_* functions in eegprep-console with the same EEGPrepSession synchronization behavior as core pop_* functions.

One broken extension no longer has to break EEGPrep startup. Failed imports, invalid specs, missing dependencies, incompatible versions, disabled extensions, and catalog conflicts are visible in the Extension Manager and logs without becoming active runtime contributions.

The Extension Manager gives users safe copyable install/update guidance but deliberately does not execute package-manager commands. This keeps the trust boundary explicit: installing Python packages executes third-party code, so EEGPrep provides metadata and guidance rather than downloading arbitrary zips or running untrusted installs.

Core implementation surfaces

src/eegprep/extensions.py defines the extension SDK and registry. The registry imports only lightweight entry-point registration functions, validates ExtensionSpec objects, checks dependencies/resources/compatibility, marks duplicate contributions invalid, and keeps LazyImport targets unloaded until the user invokes an action.

src/eegprep/extension_runtime.py turns active records into menu contributions, action/pop-function lookup maps, help resources, and console resolvers. Menu insertion preserves existing EEGPrep menu order and anchors while logging missing paths rather than crashing.

src/eegprep/functions/adminfunc/plugin_menu.py provides the headless and Qt Extension Manager surfaces. It merges installed registry records with curated catalog metadata and exposes the same inventory through plugin_menu(show=False), format_plugin_menu(), and File > Manage EEGPrep extensions.

src/eegprep/functions/guifunc/menu_actions.py dispatches extension actions through the same session/history path as core GUI actions. It supports command-only results, EEG-only results, (EEG, com), and (ALLEEG, EEG, CURRENTSET, com) result shapes.

src/eegprep/functions/adminfunc/console.py binds extension pop_* functions into the synchronized console namespace. Bare console calls and assigned calls both update EEG/ALLEEG/CURRENTSET/LASTCOM/ALLCOM consistently through EEGPrepSession.

src/eegprep/functions/guifunc/pophelp.py resolves packaged extension help resources before failing clearly. Runtime code does not fall back to src/eegprep/eeglab for extension help.

src/eegprep/extension_catalog.py defines metadata-only catalog loading, safe command generation, compatibility checks, and catalog validation. The packaged catalog is intentionally empty at launch but the schema and validator are ready for curated entries.

Tests and evidence

Focused extension suite run on this branch:

uv run --no-sync pytest tests/test_extension_integration.py tests/test_extension_runtime.py tests/test_extension_catalog.py tests/test_extension_testing.py tests/test_extension_authoring_toolkit.py tests/test_extension_docs.py tests/test_plugin_menu.py tests/test_package_exports.py tests/test_extensions.py

Result: 110 passed.

Static and type checks run:

uv run --no-sync ruff check .
uv run --no-sync ruff format --check .
uv run --no-sync ty check

Results: all passed.

Catalog validator smoke run:

uv run --no-sync eegprep-validate-extension-catalog src/eegprep/resources/extension_catalog.json --json

Result: ok true, no errors, no warnings.

Manual sanity check confirmed bundled registry discovery, ExtensionRuntime menu contribution preparation, and headless Extension Manager inventory. The Extension Manager Qt surface is covered by tests/test_plugin_menu.py using an offscreen QDialog render path.

Review status

A regular github-pr-review-style pass found no validated actionable issues in the extension delta. The earlier OC autoreview helper could not complete due to a local Codex CLI service_tier configuration issue, not an EEGPrep code failure; after that, the requested regular review was completed with the checks above.

Known review note

Because this branch is stacked on #111, reviewers should avoid treating the EEGBrowser files in the full develop diff as new extension-epic work. Review the extension delta after #111 merges, or compare against origin/feature/eegbrowser-completion for the isolated scope.

@suraj-ranganath

Copy link
Copy Markdown
Member Author

🤖 GUI evidence for the extension epic.

The only new GUI surface in the isolated extension delta is the EEGPrep Extension Manager from Phase 3 (#124). That phase included this visual QA artifact:

eegprep_extension_manager_phase3.png

This is not committed on the final epic branch; it is linked here as review evidence. The final branch also keeps automated Qt coverage for the manager in tests/test_plugin_menu.py.

@arnodelorme
arnodelorme merged commit 7efc9a1 into develop Jun 4, 2026
9 checks passed
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.

Epic: Build EEGPrep external extension ecosystem

2 participants