Skip to content

Add first-class TypeScript authoring for plugins (compile-to-JS, runtime unchanged) #169

@davidarny

Description

@davidarny

Problem

Plugin runtime is JS-only (QuickJS eval of manifest entry), but plugin logic is getting complex and currently lacks first-class type-safety and API autocomplete.

Current state:

  • Manifest entry is loaded as raw script text and eval’d.
  • Runtime expects globalThis.__openusage_plugin.probe.
  • No transpile step exists in dev/build plugin pipeline.

This makes plugin authoring more error-prone than needed.

Goal

Allow plugin authors to write plugins in TypeScript while keeping runtime execution model unchanged (compiled JS in QuickJS).

Proposal (MVP)

  • Keep runtime contract unchanged: manifest entry still points to JS file executed by QuickJS.
  • Add TS authoring convention:
    • plugins/<id>/src/plugin.ts (source)
    • plugins/<id>/plugin.js (generated artifact, committed)
  • Add plugin build command to transpile all plugin TS sources to single-file JS suitable for QuickJS.
  • Add typed SDK for plugin authors (e.g. ProbeContext, MetricLine, ctx.host.*, ctx.line.*) based on current host API.
  • Add CI check to fail if generated plugin.js is stale relative to source.
  • Update plugin docs/examples to TS-first authoring with JS runtime output.

Acceptance Criteria

  • A plugin can be authored in .ts with full IntelliSense for context/line builders/host APIs.
  • Generated plugin.js loads in current runtime without Rust changes.
  • Existing plugin behavior remains unchanged.
  • CI prevents drift between TS source and generated JS output.
  • Docs include TS workflow and migration example.

Non-goals

  • Running .ts directly in runtime.
  • Introducing npm package resolution inside plugin runtime.
  • Replacing QuickJS with Node/V8.

Implementation Notes

  • Output should be a self-contained script compatible with current eval/global registration pattern.
  • Prefer conservative JS target/format for QuickJS compatibility.
  • Ensure generated code still sets globalThis.__openusage_plugin = { id, probe }.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions