mirror of
https://github.com/hanzoai/opencode-openai-codex-auth.git
synced 2026-09-24 17:01:02 +00:00
## CODEX_MODE Implementation
Added configurable CODEX_MODE that replaces OpenCode system prompts with
a Codex-OpenCode bridge prompt for better Codex CLI parity.
**Key Features:**
- Enabled by default for optimal Codex CLI compatibility
- Configurable via ~/.opencode/openai-codex-auth-config.json
- Environment variable override support (CODEX_MODE=0 or CODEX_MODE=1)
- Priority: env var > config file > default (true)
**Bridge Prompt:**
- ~450 tokens (~90% reduction vs full OpenCode prompt)
- Critical tool replacements (apply_patch → edit, update_plan → todowrite)
- Available tools list and verification checklist
- OpenCode working style guidelines
**Configuration:**
```json
{
"codexMode": true // default
}
```
## Library Reorganization
Restructured lib/ into semantic subfolders:
```
lib/
├── auth/ # OAuth authentication
│ ├── auth.ts
│ ├── browser.ts
│ └── server.ts
├── prompts/ # System prompts
│ ├── codex.ts
│ └── codex-opencode-bridge.ts
├── request/ # Request handling
│ ├── fetch-helpers.ts
│ ├── request-transformer.ts
│ └── response-handler.ts
├── config.ts # Plugin configuration
├── constants.ts
├── logger.ts
├── types.ts
└── oauth-success.html
```
## Files Changed
**New Files:**
- lib/config.ts - Plugin configuration loading
- lib/prompts/codex-opencode-bridge.ts - Bridge prompt
- test/plugin-config.test.ts - 12 new tests
**Modified:**
- lib/request/request-transformer.ts - CODEX_MODE parameter
- lib/request/fetch-helpers.ts - Pass codexMode through pipeline
- index.ts - Load config and determine codexMode
- lib/types.ts - Add PluginConfig type
- README.md - Document CODEX_MODE configuration
**Reorganized:**
- lib/*.ts → lib/{auth,prompts,request}/*.ts
- Updated all imports across codebase and tests
## Testing
- 123 total tests (added 12 new tests for config loading)
- All tests passing
- Comprehensive CODEX_MODE coverage:
- Config file loading (exists, missing, invalid)
- Priority order testing
- Environment variable override
- Bridge prompt vs tool remap behavior
## Documentation
Updated README.md:
- Added "Plugin Configuration" section
- Documented CODEX_MODE setting and priority
- Updated features list (123 tests, CODEX_MODE)
- Updated "How It Works" section
Co-authored-by: Hanzo Dev <[email protected]>
36 lines
994 B
TypeScript
36 lines
994 B
TypeScript
/**
|
|
* Browser utilities for OAuth flow
|
|
* Handles platform-specific browser opening
|
|
*/
|
|
|
|
import { spawn } from "node:child_process";
|
|
import { PLATFORM_OPENERS } from "../constants.js";
|
|
|
|
/**
|
|
* Gets the platform-specific command to open a URL in the default browser
|
|
* @returns Browser opener command for the current platform
|
|
*/
|
|
export function getBrowserOpener(): string {
|
|
const platform = process.platform;
|
|
if (platform === "darwin") return PLATFORM_OPENERS.darwin;
|
|
if (platform === "win32") return PLATFORM_OPENERS.win32;
|
|
return PLATFORM_OPENERS.linux;
|
|
}
|
|
|
|
/**
|
|
* Opens a URL in the default browser
|
|
* Silently fails if browser cannot be opened (user can copy URL manually)
|
|
* @param url - URL to open
|
|
*/
|
|
export function openBrowserUrl(url: string): void {
|
|
try {
|
|
const opener = getBrowserOpener();
|
|
spawn(opener, [url], {
|
|
stdio: "ignore",
|
|
shell: process.platform === "win32",
|
|
});
|
|
} catch (error) {
|
|
// Silently fail - user can manually open the URL from instructions
|
|
}
|
|
}
|