Introducing a new way to review your PRs.

Read the announcement

nklmilojevic / sofka

A Kubernetes TUI, reimagined in Rust - built on kube-rs and ratatui, async-first from the ground up.

View on GitHub

19 documents · Updated Nov 4, 2026

docs / plugin-ecosystem

Plugin ecosystem

The plugin ecosystem lets Sofka add cluster tools without changing the main application. It connects trusted catalogs and installed packages to declared commands, runtime safeguards, live activity, and reports. The plugin catalog and installation page covers discovery and package lifecycle. The plugin runtime and adapters page covers execution and external tool integration.

Ecosystem model

The ecosystem separates what a plugin is from where it comes from and how it runs. A catalog release describes a package and its expected behavior. Installation checks that the package matches those claims. The running application then turns the package commands into actions on selected resources or on the current context.

flowchart LR
    C[Catalog source] --> M[Release metadata]
    M --> I[Managed installation]
    I --> L[Loaded command]
    L --> G[Safety and scope checks]
    G --> A[External adapter]
    A --> R[Activity or report]
    R --> U[Sofka user interface]

Catalogs can be combined, so a plugin ID is not globally unique until its catalog source is known. The official catalog is enabled by default. A custom catalog must be explicitly trusted, and its packages remain tied to that source after installation. This separation lets teams use private catalogs without silently replacing an installed package from another source.

References: src/…/sources.rs• L4-34 src/…/sources.rs• L205-325 src/plugin_install.rs• L300-318

Plugin packages

A plugin package is a versioned unit that declares one or more commands in plugin.toml. The manifest gives Sofka the information it needs to show the command, check its inputs and requirements, apply safety rules, and start the right adapter. A package may be installed from a catalog or placed in the configuration directory by hand.

Package conceptPurpose
Package metadataIdentifies the release, publisher, license, supported Sofka versions, platforms, and search tags.
Command metadataDefines the user-facing name, scope, target, output form, and safety behavior.
Runtime requirementsNames external executables that the adapter may need and gives the user install guidance.
InputsDefines checked name=value values and their defaults.
AdapterPerforms tool-specific work and returns a result through the plugin protocol.

Schema 2 packages can group several commands while keeping each command's scope, inputs, and safety settings separate. Sofka also accepts the older single-command package form. A package is the install and update unit even when it contains several commands.

References: src/plugins.rs• L157-204 src/plugins.rs• L377-407 docs/plugin-authoring.md• L30-39 docs/plugin-authoring.md• L114-149

Catalog and installation lifecycle

The catalog and installation path turns published release metadata into a local command that Sofka can load. It chooses a compatible active release for the current Sofka version and platform, obtains the matching archive, checks its identity, and activates the complete package. The catalog entry and the package manifest must agree so that displayed behavior matches the code that runs.

  1. Sofka loads enabled catalog sources and validates their metadata.
  2. A search or install request identifies a plugin by ID and may name an exact version.
  3. Sofka selects the newest compatible stable release unless the request names a version.
  4. The installer verifies the archive and checks the package manifest against the selected release.
  5. Sofka records the package source, release, archive digest, and file state before activation.
  6. The application loads the package after the user runs :reload in an existing session.

Installation records distinguish managed packages from manual packages. Updates and removal protect local changes and do not take ownership of unmanaged or linked directories. Offline use relies on cached catalog data and matching archives. See plugin catalog and installation for the full lifecycle.

References: src/plugin_catalog.rs• L453-529 src/plugin_install.rs• L240-395 src/plugin_install.rs• L398-445 src/plugin_cli.rs• L407-415

Runtime integration

The runtime maps a plugin command to one or more jobs. A selection target runs against the selected or marked resources. A context target runs once for the current namespace scope. Sofka supplies resource and cluster context to package adapters and applies guardrails before it starts a process.

sequenceDiagram
    participant User
    participant Sofka
    participant Adapter
    participant Cluster as Cluster tool
    User->>Sofka: Invoke command
    Sofka->>Sofka: Resolve target, inputs, and safety rules
    Sofka->>Adapter: JSON request on standard input
    Adapter->>Cluster: Use inherited access or managed forward
    Cluster-->>Adapter: Tool result
    Adapter-->>Sofka: Diagnostics on stderr
    Adapter-->>Sofka: Report or text on stdout
    Sofka-->>User: Activity, result, or failure

When a command needs values, Sofka opens a form or parses supplied arguments. The form applies defaults and validates each value before a job starts. Sofka then resolves placeholders and creates one job per target. Context data travels as literal arguments or as a structured request for packaged commands, so a bulk action can use the same command definition for each resource.

Sofka creates one job for each target and can process a marked set without blocking the user interface. The selected target order remains the result order, while failures are collected so a bulk run can report partial success. A context command uses the current namespace scope instead of a selected resource. See plugin runtime and adapters for the execution flow.

Package commands use captured output modes. Popup and report modes show live diagnostics and retain a result. Background mode reports completion without opening the activity view. Interactive terminal mode remains available for inline plugins, but packaged commands use bounded captured output so a failing or noisy adapter cannot take over the application. A marked set cannot use terminal mode because terminal output cannot represent several jobs safely.

References: src/…/plugins.rs• L29-109 src/…/plugins.rs• L115-225 src/…/plugins.rs• L228-450 src/…/plugins.rs• L452-607 src/plugins.rs• L864-938

Metadata and safety contract

Plugin metadata is the contract between catalog authors, the installer, and the runtime. It describes behavior before execution so Sofka can choose compatible releases and show the user whether an action can change resources, create network load, or need confirmation. Missing or conflicting declarations are rejected for packages rather than treated as harmless defaults when they could change the published behavior.

The runtime uses these contract points:

  • target controls whether jobs use selected resources or the current context.
  • mutating controls access in read-only mode. The default is that a plugin may mutate resources.
  • network_load marks traffic-generating work and requires confirmation.
  • confirm and dangerous require a confirmation step before execution.
  • scopes limits commands to resource kinds where they make sense.
  • requires and package requirements describe tools outside Sofka. Sofka warns about missing tools but does not install them.
  • port_forward gives an adapter a managed local connection to a selected pod or service when the command needs one.

These declarations are guardrails, not a security sandbox. Adapters run with the user's permissions and inherited environment. The catalog's review status does not remove that trust requirement. Sofka also checks that a port-forward resolves to a valid port and applies only to pod or service targets before it creates the job.

References: src/plugins.rs• L447-533 src/…/plugins.rs• L168-225 src/…/plugins.rs• L277-379 src/…/plugins.rs• L392-449 docs/plugin-authoring.md• L457-484

Runtime activity

Runtime activity gives users progress and failure context without changing the result protocol. Adapters keep standard output for the final text or report and use standard error for diagnostics. Sofka sanitizes display control sequences and keeps only a bounded tail of activity, while the full captured streams remain subject to strict limits.

Only one plugin run is active at a time. A new run, navigation change, context change, cancellation, timeout, or process failure can end the current run. Bulk work may report partial failures, but completed results keep the order of the selected targets. A valid report can also request a supported application action, such as a kubeconfig reload; invalid or stale runs cannot trigger it. Completed popup and report output remains available as a document that the user can open after the activity view closes. See plugin runtime and adapters for protocol details.

References: src/…/activity.rs• L7-59 src/…/activity.rs• L123-212 src/…/plugins.rs• L503-607 src/…/plugins.rs• L609-719 src/…/plugins.rs• L722-825

Built-in and external adapters

Sofka supports two adapter sources under the same command model. External packages provide their own executable and speak the request and report protocol. Built-in packages use an adapter inside the Sofka executable, so they do not need a copied binary or another language runtime.

The bundled sanitize command shows the built-in form. The resource-summary example shows an external Python adapter. Both are described by a package manifest and can use declared inputs, resource scope, report output, and safety controls. The difference is ownership of the adapter process, not the user-facing plugin model.

References: src/plugins.rs• L410-437 plugins/…/plugin.toml• L1-24 examples/…/plugin.toml• L1-16 docs/plugin-authoring.md• L1-16

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep catalog execution metadata aligned with the package manifest because installation rejects mismatches.
  • Keep catalog source identity aligned with installation records because a package cannot be replaced by the same ID from a different source.
  • Keep command safety metadata aligned across catalog descriptions, runtime guardrails, and read-only behavior.
  • Keep request and report schema changes compatible with both bundled and external adapters.
  • Keep output mode changes aligned with activity handling and the rule that packaged commands use captured output.
  • Keep target and port-forward rules aligned with the resource kinds that can supply a valid endpoint.
  • Keep platform and Sofka compatibility metadata aligned with the artifacts that a catalog can actually install.

Important failure modes

TriggerConsequenceGuard
Catalog metadata differs from the archive manifestInstallation refuses the package before activationManifest-to-catalog reconciliation
The installed package has local file changesUpdate or removal refuses to overwrite itInstallation record and file verification
A package is requested from a different catalog sourceExisting installation is not replacedSource identity stored in the installation record
A marked set selects terminal outputSofka refuses to run the bulk actionTerminal mode is limited to one target
A port-forward uses an invalid port or unsupported resource kindThe job is not createdPort and pod/service validation
Adapter output exceeds request or stream limitsThe job fails and bounded activity remains availableRequest and per-stream output caps
A mutating or network-load command runs in read-only modeThe command is blocked before adapter executionRuntime safety metadata and read-only checks
An adapter times out or is cancelledThe run ends and its process group is stoppedPer-job timeout and process-group ownership

Key files

FileWhy to read it
src/plugins.rsDefines the shared manifest, package, input, report, and adapter execution model.
src/plugin_catalog.rsShows how release metadata, compatibility, platform artifacts, and catalog validation fit together.
src/…/sources.rsExplains official and trusted custom catalog sources and their identity rules.
src/plugin_install.rsShows how catalog archives become verified and managed local packages.
src/plugin_cli.rsConnects catalog operations to search, describe, install, update, list, and removal behavior.
src/…/plugins.rsShows how loaded commands become validated, guarded jobs and how runtime activity returns to the application.
src/…/activity.rsDefines the bounded diagnostic stream used by the activity view.
plugins/…/plugin.tomlIllustrates a bundled command that uses the shared plugin contract.
examples/…/plugin.tomlIllustrates an external package with an adapter requirement and validated input.
docs/plugin-catalog-and-installation.mdChild page for catalog resolution and installation lifecycle.
docs/plugin-runtime-and-adapters.mdChild page for runtime execution, activity, and adapter protocol.