Skip to content

[CTX-0406] feat(plugin): external local-path install + lifecycle + runtime reload - #670

Merged
Xuepoo merged 2 commits into
mainfrom
ctx-0406/feat-plugin-e2e-install
Sep 14, 2026
Merged

Xuepoo merged 2 commits into
mainfrom
ctx-0406/feat-plugin-e2e-install

Conversation

@Xuepoo

@Xuepoo Xuepoo commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Priority: P2 | Area: plugins | Labels: feat,area:plugins,P2 | Milestone: v0.1.0 | RFC: OQ-053/OQ-072 | Task: CTX-0406

Closes #669

What already existed

  • bitty plugin CLI (CTX-0150): list|install|remove|enable|disable|info
    for bundled ids via a managed manifest; no plugin VM.
  • Runtime Gap A/B (CTX-0328/CTX-0329): per-plugin VM lifecycle, XDG store
    resolution with current.json, fail-closed manifest_hash/content_digest
    verification, --safe third-party skip.
  • bitty-plugin-host policy (manifest, capabilities, grants, host reload
    mechanics) and the accepted package-lifecycle / plugin-host-runtime RFCs.

What this builds (real, not mocked)

  • Install path: bitty plugin install <local-dir> verifies the
    bitty-plugin.toml with the runtime's bounded reader, requires init.lua,
    re-checks the ratified module-tree bounds (4096 files / 16 MiB / 1024-byte
    paths, native artifacts rejected), evaluates compat.bitty +
    compat.plugin-api against the running host, and diffs requested
    capabilities against the recorded grant. Added capabilities need explicit
    consent (--yes or [y/N], fail-closed on EOF). Content is copied into a
    quarantine dir, digested, atomically renamed to
    packages/<id>/<version>/, then current.json is switched last.
  • Store: accepted layout + owner-only 0700/0600 modes on Unix.
    Staged local-path records use a store-relative immutable root (digest
    mismatch fails closed); absolute dev roots keep the read-only
    drift-reported flow.
  • Lifecycle: list/info include installed packages with a source
    field; enable/disable rewrite the index atomically; re-install updates
    and retains the previous version; remove --force uninstalls record + tree.
  • Load + run + reload: PluginRuntime::reload disposes generation N
    before activating N+1 from the re-resolved store record; the recorded,
    manifest-hash-bound grant is enforced at activation (a record that does not
    cover the declared set fails closed before any VM is created).
  • Remote sources (git:/https:///ssh://) fail closed with a clear
    message; the SDK bitty-plugin-lint is not present yet, so the Rust
    validation path is authoritative.

Exact installed-plugin flow

bitty plugin install ./my-plugin --yes
  -> parse + validate manifest, require init.lua, scan module tree
  -> compat check (host bitty 0.0.20, plugin-api 1.0.0)
  -> capability diff vs recorded grant (consent gate)
  -> copy to packages/xuepoo.external/1.0.0.tmp-<pid>, 0700/0600, digest
  -> rename into place, write current.json atomically
runtime startup / reload
  -> read current.json, re-verify manifest_hash + content_digest
  -> activate in an isolated VM with the consented grant set
  -> dispatch `xuepoo.external:greet`
bitty plugin disable xuepoo.external   # index rewrite, discovery skips it
bitty plugin install ./my-plugin-v2 --yes  # update, previous version retained
bitty plugin remove xuepoo.external --force  # record + tree removed

Evidence

  • just check (bitty): fmt-check, workspace clippy -D warnings, full
    workspace tests, scratch-paths, pty-gate, actionlint, markdownlint — exit 0.
  • cargo check --target x86_64-pc-windows-gnu --workspace --all-targets --locked — exit 0.
  • cargo test -p bitty-runtime --test plugin_package (2 tests): real
    install → discover → activate → dispatch → update → reload → disable →
    uninstall, plus recorded-grant enforcement.
  • cargo test -p bitty-app --test cli_plugin (9 tests): real binary installs
    a real external fixture, asserts store layout/index, list/info JSON, then
    loads it with the real runtime and runs the command; consent decline/EOF
    fail closed; remote source rejected.
  • git diff --check clean.

Deliberately deferred

  • Remote git source resolution (CLI rejects it explicitly).
  • Live bitty plugin reload/IPC trigger surface (OQ-072 remains Open; the
    runtime reload API and update-pickup-on-next-start are shipped).
  • SDK bitty-plugin-lint conformance, draft seven-stage pipeline, rollback
    commands, package assets/.

Residual risks

  • Store current.json is user-writable state; integrity is enforced by
    re-verification and grant coverage, but a user can still intentionally
    disable a record. Grants cannot be widened without consent because a
    mismatch fails closed.
  • The staged local-path store-relative record root is a refinement of RFC
    B.4/B.5 (documented in bitty-plugins-docs); it should be folded into the
    next RFC revision.
  • PluginRuntime grants for bundled/dev packages still default to the full
    declared set (no record); only store records carry consented grants.

…ntime reload

Install or update an externally authored package from a local directory into
the XDG plugin store, verify it before staging, and prove the full
install -> load -> run -> disable -> update -> reload -> uninstall path.

- bitty-runtime: new plugin_runtime::package staging (bounded manifest read,
  entry point, module-tree bounds, compat ranges, capability-diff consent,
  quarantine copy, content digest, atomic current.json switch, owner-only
  modes, retained-version prune) and PluginRuntime::reload (teardown N before
  N+1).
- resolution: staged local-path records use a store-relative immutable root
  (digest mismatch fails closed) while absolute dev roots keep the read-only
  drift-reported flow.
- activation: the recorded, manifest-hash-bound grant is enforced; a record
  that does not cover the declared set fails closed before any VM.
- bitty-app: `bitty plugin install <path>`, list/info source column,
  enable/disable/remove on the store, remote sources fail closed.
- tests: package unit tests, runtime plugin_package e2e, CLI cli_plugin e2e
  with a real external fixture.
Address the CTX-0406 review findings on PR #670.

- S1 (security): consent is bound to a staged snapshot. install_local_dir
  copies the source into .tmp-* quarantine, hashes the staged body/tree, and
  passes a ConsentRequest to a callback; approval commits that same snapshot
  (source never re-read) with a post-consent hash re-verify. Regression test
  swaps the source mid-prompt and asserts only the reviewed grant commits.
- L1: read_store_manifest resolves through resolution::store_package_root
  (escape-checked); crafted `../` record roots are rejected.
- L2: store installs reject bundled-catalog ids (BundledIdReserved).
- L4: InvalidSource doc matches behavior (symlink-to-directory accepted and
  canonicalized; entry symlinks rejected by the copy/scan).
- S2: the installer pre-scan uses scan_module_tree_source, matching copy_tree
  exactly (VCS dirs skipped, symlinks rejected).

Follow-ups recorded: CTX-0416 (L3 compat re-check at resolve/activate),
CTX-0417 (L5 quarantine GC + prune-failure reporting).
@Xuepoo

Xuepoo commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

Review findings addressed on this branch (no merge). New head: 1eb240c (branch ctx-0406/feat-plugin-e2e-install).

Must-fix (bitty)

ID Severity Finding Resolution
S1 Medium (sec.) Interactive consent TOCTOU (approved transaction re-read the source and skipped the diff) Replaced the two-call approve flow with a consent callback bound to a staged snapshot. install_local_dir now validates, copies the source into .tmp-* quarantine, hashes the staged body/tree, and passes a ConsentRequest { manifest_hash, content_digest, added, granted } to the callback; on approval it commits that same snapshot (source never re-read) and re-verifies the staged manifest hash, failing closed if anything changed. Regression test consent_snapshot_ignores_source_swap swaps the source manifest mid-prompt (adding terminal.semantic-read) and asserts only the reviewed platform.notify grant is committed.
L1 Low Path traversal in read_store_manifest (../ record root) read_store_manifest now resolves through the new public resolution::store_package_root, which applies the same is_safe_relative + canonicalize-under-store guard as resolve_record. Unit test store_package_root_rejects_crafted_escape writes a crafted current.json with a ../ root and asserts rejection; CLI test plugin_store_display_rejects_escaped_record_root plants a manifest outside the store and asserts list never reads it.
L2 Low Store package could shadow a bundled id install_local_dir rejects any id present in the application-shipped catalog with the typed PackageOpError::BundledIdReserved (before any staging). Tests: bundled_id_is_reserved and CLI plugin_external_bundled_id_is_rejected.
L4 Low InvalidSource doc said symlinked sources are invalid while symlink-to-dir sources are accepted Chose to keep accepting a symlink-to-directory source (it is canonicalized; internal entry symlinks are already rejected by the copy/scan), and corrected the doc to say only an unresolvable path or non-directory target is invalid. Rationale: symlinked checkouts are legitimate; canonicalization resolves them and the escape guard still applies.
S2 Nit Pre-scan/copy rule mismatch (VCS dirs counted, symlinks treated differently) Made scan_module_tree mode-aware: the installer pre-scan uses scan_module_tree_source, which skips VCS metadata directories and rejects symlinked entries exactly like copy_package, while the staged/dev scan keeps following in-tree symlinks. Tests: source_scan_skips_vcs_and_rejects_symlinks, vcs_metadata_is_skipped_by_the_source_scan, symlinked_source_entry_is_rejected.

Recorded follow-ups (not fixed here)

  • L3 host-upgrade compat re-check at resolve/activate → CTX-0416.
  • L5 .tmp-* quarantine GC + post-commit prune-failure reporting → CTX-0417.

Tests added

  • crates/bitty-runtime/src/plugin_runtime/package.rs: consent_snapshot_ignores_source_swap, capability_increase_requires_consent_and_narrowing_carries_forward (deny/abort/approve), bundled_id_is_reserved, vcs_metadata_is_skipped_by_the_source_scan, symlinked_source_entry_is_rejected.
  • crates/bitty-runtime/src/plugin_runtime/resolution.rs: store_package_root_rejects_crafted_escape, source_scan_skips_vcs_and_rejects_symlinks.
  • crates/bitty-app/tests/cli_plugin.rs: plugin_external_bundled_id_is_rejected, plugin_store_display_rejects_escaped_record_root.

Gates (all green on 1eb240c)

  • just check (bitty): fmt-check + workspace clippy -D warnings + full workspace tests + scratch-paths + pty-gate + actionlint + markdownlint — exit 0.
  • cargo check --target x86_64-pc-windows-gnu --workspace --all-targets --locked — exit 0.
  • cargo test -p bitty-runtime --locked --lib plugin_runtime (20 passed), --test plugin_package (2 passed); cargo test -p bitty-app --locked --test cli_plugin (11 passed), --bin bitty plugin:: (17 passed).
  • git diff --check clean; no TODO/FIXME.

No merge; stopped at open PR.

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

Labels

area:plugins feat Feature P2 Priority: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CTX-0406] feat(plugin): end-to-end independent third-party plugin install (M5 ecosystem)

1 participant