Skip to content

refactor(cli-rs): run script plugins as JavaScript only - #67944

Merged
simonklee merged 7 commits into
devfrom
script-js
Dec 3, 2026
Merged

simonklee merged 7 commits into
devfrom
script-js

Conversation

@simonklee

@simonklee simonklee commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Issue for this PR

N/A (follows psychoscript keeping TypeScript out of the interpreter; anomalyco/psychoscript#179 was closed)

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The native client's script plugins ran TypeScript through psychoscript's TS mode, which only exists on our integration branch: upstream psychoscript stays JavaScript-only and leaves type stripping to the host. Until we decide whether the client strips types itself, script plugins are JavaScript: the entry is init.js, modules are .js, and everything is compiled as plain JavaScript. An init.ts entry or an imported .ts module is refused with script plugins are JavaScript: rename init.ts to init.js and remove its types. Authors keep type checking: opencode-native plugin types writes the same .d.ts files and a tsconfig with allowJs, checkJs and strict, and plugin check runs it on .js. The in-repo example and parity plugins are converted (same emitted code, // @ts-check, JSDoc only where checkJs needs it), and the plugin docs say JavaScript.

This is a breaking change for script plugin authors, but no cli-rs release has shipped script plugins yet, and the ten known third-party ports are already converted. No feature flag for that reason. TS TUI plugins (tui.ts/tui.tsx on the JS host) are unchanged.

How did you verify your code works?

  • The ports twins against the ten converted third-party plugins: 10 of 10 at plugin level and 8 of 8 in the TUI, with their frozen traces unchanged.
  • check:plugin-types reports 0 errors on every in-repo script plugin and still refuses its four bad fixtures; opencode-cli --test plugin, opencode-plugin script::, loader::, script_loader_tests::, twin::, opencode-plugin-abi sdk, opencode-tui plugin_script::, plugin_machines::, plugin_twins::; P-PTY P.0b/foreground-title.
  • cargo fmt --check, clippy -D warnings, bun typecheck, check:drift. The merge lane's gate and full suites (P-CLI, P-PTY, ACP, P-TUI, drift, machines, Windows check, cargo deny) passed on 36c65f6fa0.

Screenshots / recordings

N/A (plugin loading and tooling; no UI change).

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Public API: script plugins: default entry init.ts → init.js; .ts entries and imports are now refused (breaking for TypeScript script plugins; TS TUI plugins unchanged)

psychoscript upstream will not take TypeScript mode, so the carrier
stops using it. A script plugin's entry is `init.js` and its modules are
`.js`, compiled as plain JavaScript; an `init.ts` entry is refused at
load with the rename that fixes it, and a `.ts` module a `.js` plugin
imports is refused the same way. Authors type-check the JavaScript
against the generated `opencode-plugin.d.ts` and `psychoscript.d.ts`.

The carrier's `opencode:plugin` prelude is unchanged and is now
`prelude.js`, which is what it always compiled to.
Script plugins are JavaScript only (O-229): the examples are init.js and
.js modules, checked with checkJs against the generated plugin types. The
converted files keep the same code, comments aside, so the counter and
hello twins still match their frozen traces.
Script plugins are JavaScript now: psychoscript takes no TypeScript mode, and
the client refuses a `.ts` entry. Convert life, other and title the way the ten
ports were, with `// @ts-check` and JSDoc for the checker, and point the life
machine, the P.0b fixture and the docs at `init.js`.

The code each file emits is the same, so the life state machine and the title
twins still reproduce their traces.
The five worker branches left a few places on the TypeScript entry: the
ports twin's fixture plugin wrote script/init.ts, the TUI script fixtures
built their plugins from init.ts (two with type annotations in their
source), and the F16 deviation still described stripped types.

plugin check now compiles before it runs tsc, so a .js plugin importing a
.ts module is refused with the loader's own wording instead of tsc's
import-extension error.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks sound from reading it, but I couldn't run it: the sandbox has no Rust toolchain, so I couldn't build opencode-native or run the crate tests, and check:plugin-types stops at the cargo-driven types step. I read the diff end to end. The manifest refuses a .ts entry, the build only links .js and maps an unresolved .ts import to the same refusal, and plugin check now builds before running tsc so its errors read like the loader's. I found no leftover init.ts assumptions in the plugin crate or docs.

Public API (script plugin file format), not backwards compatible for script plugins:

  • Default entry: init.ts, else init.js → init.js only.
  • An entry or import ending in .ts now fails to load with script plugins are JavaScript: rename <x>.ts to <x>.js and remove its types.
  • .ts modules are no longer compiled. The documented tsconfig drops allowImportingTsExtensions, erasableSyntaxOnly and verbatimModuleSyntax.
  • Existing TypeScript script plugins must rename to .js and move their types to JSDoc.
  • TS TUI plugins on the JS host are unchanged.

One small concern is inline: check-plugin-types.ts no longer skips plugin.toml directories that aren't script plugins.

The checker treated every plugin.toml as a script plugin, so a legacy
Luau directory (an init.luau, or an entry ending in .luau) counted as an
error and was told to rename init.luau to itself.

It now mirrors the loader's source::carrier and skips a directory routed
to the Luau carrier. A directory routed to Script keeps its refusal, and
an init.ts with no init.js is now named in that refusal rather than
reported as a missing init.js, as the loader's default entry does.

script/script-expect/luau is the row that holds this: it is scanned and
must be skipped, so a regression fails the check.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new commit fixes the earlier thread: check-plugin-types.ts now works out the carrier the way the loader's source::carrier does, and skips Luau plugins instead of refusing them. A script-expect/luau fixture covers the skip. I checked this by reading the diff; I couldn't run the script because the sandbox has no Rust toolchain. This commit changes no public API beyond what the earlier review noted. Nothing new to raise.

@simonklee
simonklee merged commit cacea78 into dev Dec 3, 2026
9 checks passed
@simonklee
simonklee deleted the script-js branch December 3, 2026 12:04
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.

1 participant