Skip to content

fix: OpenCode v2 compatibility (directory fallback, TTY guard, unref timers, and export schema) - #1

Open
markusbrand wants to merge 1 commit into
zeklop:mainfrom
markusbrand:fix/opencode-v2-compatibility
Open

markusbrand wants to merge 1 commit into
zeklop:mainfrom
markusbrand:fix/opencode-v2-compatibility

Conversation

@markusbrand

Copy link
Copy Markdown

Summary of Changes

This PR addresses several breaking changes and compatibility issues encountered when using @zeklop/opencode-antigravity-auth with OpenCode v2 (e.g. v2.0.12+):

  1. Default Export Schema for OpenCode v2 (index.ts):

    • OpenCode v2 requires a default export object containing { id: string, setup: Function }.
    • Added a default export mapping id: "antigravity-auth" and delegating to AntigravityCLIOAuthPlugin.
  2. Handle Optional / Undefined directory (src/plugin.ts, src/plugin/config/loader.ts):

    • In OpenCode v2, opencode run --standalone passes directory as undefined when running outside an explicit workspace.
    • getProjectConfigPath previously called join(undefined, ...) which caused TypeError [ERR_INVALID_ARG_TYPE].
    • Now safely falls back to process.cwd() and guards getProjectConfigPath.
  3. Guard Interactive CLI Prompts in Non-TTY Environments (src/plugin.ts):

    • OpenCode v2 runs web / server daemon processes where stdin and stdout are not TTYs.
    • Guarded if (inputs) in authorize() with process.stdout?.isTTY && process.stdin?.isTTY to prevent background processes from hanging indefinitely on readline terminal menus.
  4. Call .unref() on Background Timers (src/plugin/cache/signature-cache.ts, src/plugin/refresh-queue.ts, src/hooks/auto-update-checker/index.ts):

    • Active setInterval handles kept Node.js event loops alive indefinitely, causing one-shot CLI commands like opencode run "..." to hang after printing the model response.
    • Added .unref() on background intervals and timers so processes exit cleanly when execution finishes.
  5. Fix Recursion in Fallback Fetch (src/plugin.ts, src/plugin/request.ts):

    • Guarded isGenerativeLanguageRequest to support string, URL, and Request objects.
    • Delegated non-matching URLs directly to provider?.fetch ?? globalThis.fetch to prevent recursive intercept loops when non-Antigravity requests are made.

Testing

  • Ran full test suite (npm test): 41 test files passed, 1029 tests passing.
  • Ran npm run build: builds cleanly without errors.
  • Verified in OpenCode v2.0.12 CLI and standalone modes.

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