Skip to content

feat: engine resolution — claude code → codex → openrouter (harness runtime)#1

Merged
Sma1lboy merged 6 commits into
mainfrom
feat/engine-harness
Jul 6, 2026
Merged

feat: engine resolution — claude code → codex → openrouter (harness runtime)#1
Sma1lboy merged 6 commits into
mainfrom
feat/engine-harness

Conversation

@Sma1lboy

@Sma1lboy Sma1lboy commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

What changed

codefox-local no longer hardcodes OpenRouter. A new lib/engine/ layer resolves which AI engine backs the app, per process:

  1. Claude Codeclaude CLI on PATH + logged in (oauthAccount in ~/.claude.json). Default when present; uses the local subscription login, no API key.
  2. Codexcodex CLI on PATH + ~/.codex/auth.json credentials.
  3. OpenRouter — needs OPENROUTER_API_KEY.

Override with CODEFOX_ENGINE=claude|codex|openrouter. No engine available → clear error.

  • lib/engine/resolve.ts — detection + per-process cache.
  • lib/engine/local-sandbox.ts — harness sandbox provider that runs on this machine, rooted at the project dir (ported from kobe).
  • lib/engine/harness.ts — one HarnessAgent runtime per (vendor, project dir), stateful session per project, returns the turn as a UIMessage stream Response (same wire format as the streamText path, so the useChat client is engine-agnostic). Runtimes are stashed on globalThis to survive dev HMR; serverExternalPackages keeps the harness bridge unbundled.
  • app/api/chat/route.ts — resolves the engine per request. Harness path sends only the newest user message (the session is stateful) and passes no client tools — the runtime owns its own coding tools and edits the project files directly. OpenRouter path is unchanged.
  • README + .env.example — supported-engines list, resolution order, env vars.

Smoke-tested live: claude engine streamed a two-turn stateful conversation through POST /api/chat under next dev.

ai@7 upgrade

The harness packages require ai ^7, so: ai ^5 → ^7, @ai-sdk/react ^2 → ^4, and @openrouter/ai-sdk-provider (peers ai ^6, incompatible) replaced by @ai-sdk/openai ^4 with baseURL: https://openrouter.ai/api/v1 (chat/title routes). App-code breaks were mechanical: convertToModelMessages is now async; isToolOrDynamicToolUIPartisToolUIPart.

Pre-existing build fixes

HEAD did not build (next build fails before this PR): missing streamdown dependency, three tool renderers importing types removed from lib/tool-definitions, and lib/client-tools.ts calling a removed RightPanelRef.setUrl. Fixed minimally (added the dep, inlined the types locally, dropped the dead setPreviewUrl helper) to get the build gate green.

Notes

  • On harness engines the agent writes to ~/.codefox-local/projects/<id> directly; the Sandpack panel won't see those edits until it re-reads files (client writeFile tool only fires on the OpenRouter path). Follow-up if live-sync matters.
  • Title generation stays OpenRouter-only and degrades to no title without a key.
  • ⚠️ app/api/chat/route.ts has uncommitted WIP in a local checkout that may conflict on merge.

…ment and editing capabilities with project structure visibility
…de editing and preview capabilities; remove unnecessary components and integrate custom styles for improved UI
…ack functionality for real-time file operations; update project structure handling and improve initialization logic
- Updated chat API to accept files and file instructions in the request.
- Introduced new client-side tools for file writing and command execution.
- Added attemptCompletion tool to summarize task completion.
- Improved system prompt to include current project files and organization guidelines.
- Refactored right panel to expose Sandpack API for file operations.
- Adjusted UI components for better spacing and layout.
- Enhanced Sandpack editor and file explorer for improved usability.
- Updated project template with a more structured React setup and Tailwind CSS integration.
- Removed unused server-side tool definitions and related code.
…ve executeCommand functionality and integrate client-side tools
…untime)

Add lib/engine/ (resolve + harness + local sandbox, ported from kobe) so the
chat route auto-detects a locally logged-in claude/codex CLI and drives it via
@ai-sdk/harness rooted at the project directory, falling back to OpenRouter.
Upgrades ai to ^7 (@ai-sdk/react ^4, @ai-sdk/openai ^4 replacing the ai@6-only
openrouter provider) and fixes pre-existing HEAD build breaks (missing
streamdown dep, orphaned tool-definition type imports, removed setUrl).
@Sma1lboy Sma1lboy merged commit cfb7747 into main Jul 6, 2026
1 check passed
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