Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .eslintignore

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules/
bun.lockb
.worktrees/

dist/
coverage/
Expand All @@ -17,4 +18,3 @@ tmp
.worktrees/
.envrc
.env

37 changes: 36 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,89 +3,124 @@
All notable changes to this project are documented here. Dates use the ISO format (YYYY-MM-DD).

## [3.3.0] - 2025-11-19

### Added

- Codex Max support that mirrors the Codex CLI: normalization for every `gpt-5.1-codex-max` alias, `reasoningEffort: "xhigh"`, and unit tests covering both the transformer and request body integration path.
- Documentation and configuration updates calling out Codex Max as the flagship preset, plus refreshed samples showing how to opt into the Extra High reasoning mode.

### Changed

- Sample configs (`full` + `minimal`), README tables, AGENTS.md, and the diagnostics script now prefer `gpt-5.1-codex-max`, keeping plugin defaults aligned with Codex CLI behaviour.

### Fixed

- Requests that specify `reasoningEffort: "xhigh"` for non-supported models are now automatically downgraded to `high`, preventing API errors when Codex Max isn't selected.

## [3.2.0] - 2025-11-13

### Added

- GPT-5.1 family integration: normalization for `gpt-5.1`/`gpt-5.1-codex`/`gpt-5.1-codex-mini`, expanded reasoning heuristics (including `reasoningEffort: "none"`), and preservation of the native `shell`/`apply_patch` tools emitted by Codex CLI.
- Updated configuration, diagnostics script, and docs to showcase the 5.1 lineup (low/medium/high plus `none`) while keeping GPT-5 presets available for backwards compatibility.

### Changed

- Default fallback model now targets `gpt-5.1`, and Codex Mini requests always use the new `gpt-5.1-codex-mini` slug to stay in sync with the latest Codex release.

### Fixed

- Prevented invalid reasoning combinations by clamping unsupported `none`/`minimal` requests on Codex models and ensuring parallel tool-call behavior matches both GPT-5 and GPT-5.1 Codex variants.

## [3.1.0] - 2025-11-11

### Added

- Codex Mini support end-to-end: normalization to the `codex-mini-latest` slug, proper reasoning defaults, and two new presets (`gpt-5-codex-mini-medium` / `gpt-5-codex-mini-high`).
- Documentation & configuration updates describing the Codex Mini tier (200k input / 100k output tokens) plus refreshed totals (11 presets, 160+ unit tests).

### Fixed

- Prevented Codex Mini from inheriting the lightweight (`minimal`) reasoning profile used by `gpt-5-mini`/`nano`, ensuring the API always receives supported effort levels.

## [3.0.0] - 2025-11-04

### Added

- Codex-style usage-limit messaging that mirrors the 5-hour and weekly windows reported by the Codex CLI.
- Documentation guidance noting that OpenCode's context auto-compaction and usage sidebar require the canonical `config/full-opencode.json`.
- Documentation guidance noting that OpenCode's usage sidebar requires the canonical `config/full-opencode.json`.

### Changed

- Prompt caching now relies solely on the host-supplied `prompt_cache_key`; conversation/session headers are forwarded only when OpenCode provides one.
- CODEX_MODE bridge prompt refreshed to the newest Codex CLI release so tool awareness stays in sync.

### Fixed

- Clarified README, docs, and configuration references so the canonical config matches shipped behaviour.
- Pinned `hono` (4.10.4) and `vite` (7.1.12) to resolve upstream security advisories.

## [2.1.2] - 2025-10-12

### Added

- Comprehensive compliance documentation (ToS guidance, security, privacy) and a full user/developer doc set.

### Fixed

- Per-model configuration lookup, stateless multi-turn conversations, case-insensitive model normalization, and GitHub instruction caching.

## [2.1.1] - 2025-10-04

### Fixed

- README cache-clearing snippet now runs in a subshell from the home directory to avoid path issues while removing cached plugin files.

## [2.1.0] - 2025-10-04

### Added

- Enhanced CODEX_MODE bridge prompt with Task tool and MCP awareness plus ETag-backed verification of OpenCode system prompts.

### Changed

- Request transformation made async to support prompt verification caching; AGENTS.md renamed to provide cross-agent guidance.

## [2.0.0] - 2025-10-03

### Added

- Full TypeScript rewrite with strict typing, 123 automated tests, and nine pre-configured model variants matching the Codex CLI.
- CODEX_MODE introduced (enabled by default) with a lightweight bridge prompt and configurability via config file or `CODEX_MODE` env var.

### Changed

- Library reorganized into semantic folders (auth, prompts, request, etc.) and OAuth flow polished with the new success page.

## [1.0.3] - 2025-10-02

### Changed

- Major internal refactor splitting the runtime into focused modules (logger, request/response handlers) and removing legacy debug output.

## [1.0.2] - 2025-10-02

### Added

- ETag-based GitHub caching for Codex instructions and release-tag tracking for more stable prompt updates.

### Fixed

- Default model fallback, text verbosity initialization, and standardized error logging prefixes.

## [1.0.1] - 2025-10-01

### Added

- README clarifications: opencode auto-installs plugins, config locations, and streamlined quick-start instructions.

## [1.0.0] - 2025-10-01

### Added

- Initial production release with ChatGPT Plus/Pro OAuth support, tool remapping, auto-updating Codex instructions, and zero runtime dependencies.
31 changes: 27 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,33 @@ Want to customize? Jump to [Configuration reference](#configuration-reference).

## Plugin-Level Settings

Set these in `~/.opencode/openhax-codex-config.json` (applies to all models):
Set these in `~/.opencode/openhax-codex-config.json` (applies to all models). Related env vars control runtime tweaks (e.g., request logging, env tail):

- `codexMode` (default `true`): enable the Codex ↔ OpenCode bridge prompt and tool remapping
- `enablePromptCaching` (default `true`): keep a stable `prompt_cache_key` so Codex can reuse cached prompts
- `logging` (optional): override log defaults and related env vars (`ENABLE_PLUGIN_REQUEST_LOGGING`, `DEBUG_CODEX_PLUGIN`, `CODEX_LOG_MAX_BYTES`, `CODEX_LOG_MAX_FILES`, `CODEX_LOG_QUEUE_MAX`, `CODEX_SHOW_WARNING_TOASTS`, `CODEX_LOG_WARNINGS_TO_CONSOLE`). Fields:
- `enableRequestLogging`: force request log persistence even without `ENABLE_PLUGIN_REQUEST_LOGGING=1`
- `debug`: force debug logging regardless of env
- `showWarningToasts`: show warning-level toasts in the OpenCode UI
- `logWarningsToConsole`: mirror warnings to console when toasts are off
- `logMaxBytes` (default `5_242_880` bytes): rotate rolling log after this size
- `logMaxFiles` (default `5`): rotated log files to retain (plus the active log)
- `logQueueMax` (default `1000`): max buffered log entries before oldest entries drop
- Env tail (optional): set `CODEX_APPEND_ENV_CONTEXT=1` to reattach env/files context as a trailing developer message (stripped from system prompts to keep the prefix stable). Default is unset/0 (env/files removed for maximum cache stability).
- Log inspection helper: `node scripts/inspect-codex-logs.mjs [--dir <path>] [--limit N] [--id X] [--stage after-transform]` summarizes cached request logs (shows model, prompt_cache_key, roles, etc.).

Example:

```json
{
"codexMode": true,
"enablePromptCaching": true,
"enableCodexCompaction": true,
"autoCompactTokenLimit": 120000,
"autoCompactMinMessages": 8
"logging": {
"enableRequestLogging": true,
"logMaxBytes": 5242880,
"logMaxFiles": 5,
"logQueueMax": 1000
}
}
```

Expand All @@ -85,6 +98,8 @@ Example:

**Prompt caching is enabled by default** to optimize your token usage and reduce costs.

> Optional: `CODEX_APPEND_ENV_CONTEXT=1` keeps env/files context by reattaching it as a trailing developer message while preserving a stable prefix. Leave unset to maximize cache stability.

### How Caching Works

- **Enabled by default**: `enablePromptCaching: true`
Expand All @@ -93,6 +108,14 @@ Example:
- **Reduces token consumption** by reusing cached prompts
- **Lowers costs** significantly for multi-turn conversations

### Reducing Cache Churn (keep `prompt_cache_key` stable)

- Why caches reset: OpenCode rebuilds the system/developer prompt every turn; the env block includes today’s date and a ripgrep tree of your workspace, so daily rollovers or file tree changes alter the prefix and trigger a new cache key.
- Keep the tree stable: ensure noisy/ephemeral dirs are ignored (e.g. `dist/`, `build/`, `.next/`, `coverage/`, `.cache/`, `logs/`, `tmp/`, `.turbo/`, `.vite/`, `.stryker-tmp/`, `artifacts/`, and similar). Put transient outputs under an ignored directory or `/tmp`.
- Don’t thrash the workspace mid-session: large checkouts, mass file generation, or moving directories will change the ripgrep listing and force a cache miss.
- Model/provider switches also change the system prompt (different base prompt), so avoid swapping models in the middle of a session if you want to reuse cache.
- Optional: set `CODEX_APPEND_ENV_CONTEXT=1` to reattach env/files at the end of the prompt instead of stripping them. This keeps the shared prefix stable (better cache reuse) while still sending env/files as a trailing developer message. Default is off (env/files stripped to maximize stability).

### Managing Caching

#### Recommended: Full Configuration (Codex CLI Experience)
Expand Down
14 changes: 11 additions & 3 deletions docs/code-cleanup-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
2. **Created InputItemUtils** - `lib/utils/input-item-utils.ts`
- Centralized text extraction logic used in multiple modules
- Added utility functions for role checking, filtering, and formatting
- Eliminates duplication in `request-transformer.ts`, `session-manager.ts`, and `codex-compaction.ts`
- Eliminates duplication in `request-transformer.ts` and `session-manager.ts`
- Functions: `extractTextFromItem()`, `hasTextContent()`, `formatRole()`, `formatEntry()`, `isSystemMessage()`, `isUserMessage()`, `isAssistantMessage()`, `filterByRole()`, `getLastUserMessage()`, `countConversationTurns()`

3. **Refactored Large Functions**
Expand Down Expand Up @@ -53,12 +53,14 @@
## Code Quality Improvements

### Before Refactoring

- **Code Duplication**: 3+ duplicate clone implementations
- **Large Functions**: `transformRequestBody()` 1130 lines with high complexity
- **Magic Numbers**: Scattered TTL values and limits throughout codebase
- **No Complexity Enforcement**: No cognitive complexity limits

### After Refactoring

- **Eliminated Duplication**: Single source of truth for cloning and text extraction
- **Reduced Complexity**: Large function now uses focused utility functions
- **Centralized Configuration**: All magic numbers in constants with descriptive names
Expand All @@ -67,44 +69,50 @@
## Files Modified

### New Files Created

- `lib/utils/clone.ts` - Shared cloning utilities
- `lib/utils/input-item-utils.ts` - InputItem processing utilities

### Files Updated

- `lib/constants.ts` - Added centralized configuration constants
- `biome.json` - Enhanced linting rules for complexity
- `lib/request/request-transformer.ts` - Updated to use shared utilities
- `lib/session/session-manager.ts` - Updated to use shared utilities and constants
- `lib/compaction/codex-compaction.ts` - Updated to use shared utilities
- `test/session-manager.test.ts` - Updated imports for new constants

## Impact

### Maintainability

- **Easier to modify** cloning behavior in one place
- **Clearer separation of concerns** with focused utility functions
- **Better discoverability** of common operations

### Performance

- **Optimized cloning** with `structuredClone` when available
- **Reduced memory allocation** through shared utilities
- **Consistent error handling** patterns

### Code Quality

- **Enforced complexity limits** to prevent future issues
- **Standardized patterns** across all modules
- **Improved type safety** with centralized utilities

## Next Steps

The codebase now has:

- **B+ code quality rating** (improved from existing baseline)
- **Zero critical code smells**
- **Comprehensive test coverage** maintained
- **Automated quality gates** in place

Future development will benefit from:

- Shared utilities reducing duplication
- Complexity limits preventing excessive nesting
- Centralized configuration for easy maintenance
- Consistent patterns across all modules
- Consistent patterns across all modules
Loading
Loading