Skip to content

feat: add PTY_WEB_AUTOSTART environment variable support for V1 and V2 (#60) - #62

Open
kumar-shivang wants to merge 1 commit into
shekohex:mainfrom
kumar-shivang:feat/web-autostart-env
Open

kumar-shivang wants to merge 1 commit into
shekohex:mainfrom
kumar-shivang:feat/web-autostart-env

Conversation

@kumar-shivang

Copy link
Copy Markdown
Contributor

Resolves #60

Motivation

As reported in #60, users running OpenCode (especially in V1 or via scripts configuring PTY_WEB_PORT) want to keep the Web UI open in a browser tab and view or interact with running PTY sessions without needing to wait or manually trigger /pty-open-background-spy or /pty-show-server-url.

In V1, the server was previously only instantiated on-demand when executing those slash commands. In V2, autostart was only configurable via ctx.options.autostart in opencode.json and did not inspect environment variables.

Summary of Changes

  1. PTY_WEB_AUTOSTART Environment Variable:
    • Added PTYServer.isAutostartEnabled() helper supporting PTY_WEB_AUTOSTART and alias PTY_AUTOSTART (true, 1, yes, on).
  2. OpenCode V1 Support (src/plugin.ts):
    • Automatically initializes and starts PTYServer during plugin setup if autostart is enabled.
    • Seamlessly reuses the already-running server instance when slash commands are invoked.
  3. OpenCode V2 Support (src/v2/index.ts):
    • Falls back to PTYServer.isAutostartEnabled() when options.autostart is not explicitly provided in ctx.options.
    • Explicit options.autostart: false in config continues to take precedence over the environment variable.
  4. Server Lifecycle Coordination:
    • Unified active server instance lifecycle management on PTYServer, delegating cleanly between V1 and V2.
  5. Documentation:
    • Documented PTY_WEB_AUTOSTART in README.md under ### Environment Variables and updated the V2 options table.
  6. Tests:
    • Added test/v1.test.ts verifying V1 autostart lifecycle and server reuse.
    • Added unit tests in test/v2.test.ts covering environment variable autostart and explicit config overrides.
    • All 89 tests pass across 17 test files with 0 lint/format/typecheck errors.

…hekohex#60)

- Add `PTYServer.isAutostartEnabled()` supporting `PTY_WEB_AUTOSTART` and alias `PTY_AUTOSTART`
- Autostart Web UI server on OpenCode V1 plugin initialization when enabled
- Fallback to `PTY_WEB_AUTOSTART` in OpenCode V2 when `options.autostart` is not explicitly configured
- Share and coordinate `PTYServer` singleton instance between V1 and V2 adapters
- Document `PTY_WEB_AUTOSTART` in README Environment Variables and V2 options tables
- Add unit tests for V1 and V2 autostart lifecycle
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.

[Feature]: Setting to have the web ui running even without /pty-... command

1 participant