kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Add a `kolibri plugin create` scaffolder command

Open rtibbles opened this issue 5 months ago • 2 comments

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Overview

Recreate cookiecutter-kolibri-plugin as a built-in kolibri plugin create command that scaffolds a new Kolibri plugin. The cookiecutter is unmaintained (last touched 2022) and its template reflects an obsolete plugin structure, so it is rebuilt from current conventions rather than ported. Interactive by default, fully scriptable via flags.

Complexity: Medium Target branch: develop

Context

  • The kolibri CLI is click-based and already has a kolibri plugin group (enable/disable/apply/list in kolibri/utils/cli.py); the new subcommand joins it. Scaffolding needs no Django stack (cls=KolibriCommand).
  • Every plugin is discovered via a kolibri.plugins entry point. A package declares it in its own pyproject.toml; a module declares it in the nearest enclosing pyproject.toml.
  • A survey of the 26 in-repo plugins reduces to four reusable surfaces: backend-only, content viewer (ContentRendererHook), single-page app (NavigationHook + WebpackBundleHook + namespaced API), and global injector (FrontEndBaseSyncHook, injects into the base template).
  • No jinja2/cookiecutter dependency exists; Django's built-in template engine is used standalone via django.template.Engine (constructed directly — no app registry or initialize() needed) for placeholder substitution.

The Change

Add kolibri plugin create — an interactive scaffolder, fully overridable by flags (a flag supplied skips its prompt; all flags supplied = non-interactive).

Positional args (both required): the readable plugin name (e.g. "My Thing") and the target parent directory.

Flags / prompts:

  • --package / --module — package: a new self-contained package (<path>/kolibri-my-thing-plugin/, own pyproject.toml declaring the entry point). module: a bare module (<path>/my_thing/) registered in the nearest enclosing pyproject.toml. Default package. Mode is never auto-detected — walking up dirs would trip over python_packages/*/pyproject.toml.
  • --surface — backend-only | content-viewer | single-page-app | global-injector
  • --description, --author, --email (default Learning Equality)
  • single-page-app only: --url-slug

The name derives the directory, module, and MyThingPlugin class name; package mode uses kolibri-my-thing-plugin/kolibri_my_thing_plugin, module mode a short my_thing.

Each surface generates a working, discoverable plugin:

Surface kolibri_plugin.py Frontend Backend
backend-only bare KolibriPluginBase – –
content-viewer ContentRendererHook(bundle_id="main", presets=()) (empty placeholder) build config, frontend/module.js, starter view –
single-page-app WebpackBundleHook + NavigationHook frontend/{module.js, routes/, views/} api_urls.py + viewsets.py, urls.py
global-injector WebpackBundleHook + FrontEndBaseSyncHook build config, frontend/module.js –

Registration: package mode writes the kolibri.plugins entry point into the generated pyproject.toml; module mode auto-inserts it (sorted) into the nearest enclosing pyproject.toml's [project.entry-points."kolibri.plugins"] table, warning and printing the line if none is found.

Out of Scope

  • One-off hook kinds are not templated — theme, auth login/logout, OIDC provider, facility sync, network discovery. Authors copy the existing exemplar plugin.
  • No backend stubs beyond the single-page-app's default API: root_view_urls, django_settings, kolibri_options are not generated.
  • No RoleBasedRedirectHook wiring.
  • Archiving cookiecutter-kolibri-plugin — a separate follow-up, not this task.

Acceptance Criteria

General

  • [ ] kolibri plugin create is a subcommand of the kolibri plugin group and runs without booting Django.
  • [ ] Prompts interactively for name, target path, mode, surface, and metadata; each prompt is skipped when its flag is given; with all flags supplied it runs fully non-interactively.
  • [ ] The plugin name and target path are required positionals; a clear error is shown if either is missing.
  • [ ] Package mode creates <path>/kolibri-<name>-plugin/ with its own pyproject.toml declaring the kolibri.plugins entry point.
  • [ ] Module mode creates <path>/<name>/ and inserts the entry point (sorted) into the nearest enclosing pyproject.toml; if none is found, it warns and prints the line to add.
  • [ ] backend-only generates a bare KolibriPluginBase and no frontend or backend files.
  • [ ] content-viewer generates a ContentRendererHook with an empty presets=() plus the frontend build and starter view.
  • [ ] single-page-app generates WebpackBundleHook + NavigationHook, the frontend SPA files, and api_urls.py + viewsets.py + urls.py.
  • [ ] global-injector generates WebpackBundleHook + FrontEndBaseSyncHook plus the frontend build.
  • [ ] Templating uses Django's built-in template engine; no new runtime dependency is added.

Testing

  • [ ] For each surface, one test asserts the command generates the expected files (with correctly derived names) and a kolibri_plugin.py that imports.
  • [ ] Entry-point registration is covered once per mode: package writes its own pyproject.toml; module inserts into the enclosing one.
  • [ ] One integration test generates a single-page-app plugin and asserts it is discoverable and enable-able.

References

  • Archived-to-be source: https://github.com/learningequality/cookiecutter-kolibri-plugin
  • Exemplar plugins to imitate: kolibri/plugins/media_player (content-viewer), kolibri/plugins/user_profile (single-page-app), python_packages/kolibri-sentry-plugin (global-injector)

AI usage

Drafted with Claude Code, which surveyed the in-repo plugins and read the existing kolibri plugin CLI group; I drove every scope decision. I verified the surface archetypes and entry-point mechanism against the cited exemplar plugins and reviewed each section before creating the issue.

rtibbles avatar Jul 05 '26 03:07 rtibbles

Plan: Add kolibri plugin create — an interactive, fully-flag-overridable CLI scaffolder that generates a working, discoverable Kolibri plugin for one of four surfaces (backend-only, content-viewer, single-page-app, global-injector) in either package or module mode.

  • [ ] Name derivation (names.py)
  • [ ] Template rendering core (render.py)
  • [ ] Entry-point registration (entrypoint.py)
  • [ ] Surface manifest + orchestrator + backend-only surface
  • [ ] content-viewer surface
  • [ ] single-page-app surface
  • [ ] global-injector surface
  • [ ] kolibri plugin create CLI subcommand
  • [ ] Integration test — single-page-app discoverable and enable-able

@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly

How was this generated?
  • Implemented code following the pre-approved plan using test-driven development (red-green-refactor)
  • Ran the project's full test suite and linter before committing
  • For UI changes: captured live screenshots to verify rendering
  • For backend changes: verified with example API/CLI output

rtibblesbot avatar Jul 09 '26 23:07 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jul 10 '26 02:07 rtibblesbot