mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
2.8 KiB
2.8 KiB
GUI extensions
Built-in features of the desktop and web app, each behind the SDK in src/sdk/. The renderer host lives in packages/app/src/runtime/extension/, the main-process host in packages/desktop/src/main/extension/.
Structure
- One folder per extension:
index.ts(Extension.define({ id, os?, i18n })),contract.ts,renderer.tsx, optionalmain.ts, andi18n/<locale>.ts. src/renderer.tsandsrc/main.tsare the only files that list the built-ins. Main never imports renderer code.- Another extension may import only your
contract.ts(tokens and schemas, no runtime code). Every consumer must still work when the provider is disabled:ctx.use(Service)is an accessor that can returnundefined. - Never import
@opencode/app,@opencode/desktop, or@/paths. Import CSS with?inlineand contribute it throughctx.add(Style, css). No module-level state: keep state insidesetup.bun run lintenforces these rules.
Host boundary
- Host code must not name an extension or know its internals: no extension ids, command ids, DOM selectors, or stored key formats. When the host needs something from extensions, add a generic, documented field to the SDK (for example
PanelTab.file,Command.featured,Command.section). - Accepted exceptions: the built-in lists, the keybind rename map in
packages/app/src/settings/keybinds/migration.ts, the legacytype: "browser"comment decode inpackages/app/src/composer/schema.ts(drafts and message metadata written before extension notes), and the crash page's use of the updater contract.
Performance
- Keep
renderer.tsxsmall and put heavy UI behindlazy(). Preload a chunk withonIdle(() => void Chunk.preload())from setup, so it compiles while the app idles (e.g. on Home) instead of when a session first opens. Never import it on the startup path. - Return stable objects from
Panel.listand reactive contributions, so the host never remounts a trigger or a panel. - Never add work to timeline rows. The session header slot is the only timeline surface.
Localization
- Each extension owns its copy in
i18n/en.tswith short keys.ctx.tfalls back to the app's keys only for shared vocabulary such ascommon.*; feature copy belongs to the extension. - When moving copy, keep the English byte-for-byte and carry every locale's translation. The localization rules in
packages/app/AGENTS.mdapply.
Tests
- Follow the Tests section of
packages/app/AGENTS.md. - Unit-test pure logic that carries a contract: path and security checks, storage migration, protocol parsing, archive validation.
- UI behavior is proven by the app e2e keeper suites. Do not add unit tests that repeat them.
- Test a main-process entry through its
Remotecontract with real inputs, not through Electron mocks.