Skip to content

Feat/32 codex provider - #33

Merged
Estevaobonatto merged 10 commits into
mainfrom
feat/32-codex-provider
Aug 2, 2026
Merged

Feat/32 codex provider#33
Estevaobonatto merged 10 commits into
mainfrom
feat/32-codex-provider

Conversation

@Estevaobonatto

Copy link
Copy Markdown
Contributor

Tipo de Mudança

Marque exatamente uma:

  • type:bug — correção que não quebra API
  • type:feat — nova funcionalidade
  • type:chore — build, dependência, manutenção
  • type:refactor — refatoração sem mudança de comportamento
  • type:perf — performance
  • type:docs — apenas documentação
  • type:test — apenas testes

Issue

  • Closes #
  • Refs #

Área e Milestone

  • Área (auto):
  • Milestone:

Descrição

  • ...
  • ...
  • ...

Como Testar

  1. git fetch <remote> && git switch <branch>
  2. pnpm install
  3. ...
  4. Resultado esperado: ...

Checklist Agente

  • gh auth status ok
  • Branch segue <type>/<issue#>-<scope>-<slug>
  • PR title segue Conventional Commits
  • pnpm lint passa sem erros
  • pnpm typecheck passa sem erros
  • pnpm test passa (e adicionados testes para mudança)
  • cargo fmt --check && cargo clippy (se Rust mudou; warnings são informativos)
  • Sem placeholders (TODO, FIXME, // implement later)
  • Sem console.log / println! de debug
  • Commits atômicos, sem co-mistura de escopo
  • Sem git push --force em main ou PR aberta
  • docs/ atualizado se houve mudança de contrato/arquitetura
  • AGENTS.md / docs/WORKFLOW.md atualizado se mudou convenção

Breaking Changes

  • Esta PR não introduz breaking change
  • Esta PR introduz breaking change — descrita em Descrição e adicionada nota no CHANGELOG

Screenshots / Vídeos

Merge (humano executar)

gh pr merge <N> --squash \
  --body "$(gh pr view <N> --json title -q .title)"

O título deste PR (validado por CI) será a mensagem do commit de squash.
A branch não é deletada automaticamente — fica a critério do humano.

Adds full Codex support (issue #32): OpenAI's Codex CLI driven through a Bun-compiled sidecar wrapping @openai/codex-sdk.

- packages/codex-sidecar: NDJSON stdin/stdout protocol, one agentic turn per request; resolves the user-installed Codex CLI (PATH, ~/.codex/bin, ChatGPT/Codex desktop app bundled CLI, npm .cmd shims)
- Rust commands/codex.rs: codex_run/codex_cancel (real process kill), codex_login/logout/login_status (ChatGPT OAuth via CLI), codex_cli_status (CLI detection + version)
- CodexProvider + CodexInvoke in ai-providers; registered always when the transport is available (API key optional, ChatGPT login supported)
- Settings UI: CodexAuthRow with install prompt + sign-in flow, setup guide, provider catalog (gpt-5.6 sol/terra/luna, gpt-5.5/5.4/5.4-mini)
- Bundling: bundle.externalBin for both sidecars (triple-tagged by scripts/tag-sidecar-triple.mjs); beforeDev/BuildCommand build sidecars; Inno installer ships them; CI builds sidecars on ubuntu/windows/macos incl. new macOS release job
- The Codex CLI itself is user-installed (npm install -g @openai/codex) and detected at runtime — never bundled

Refs #32
The sidecar in a running dev session could predate the CLI-discovery fix (manual copy:sidecars was the only way to refresh target/debug before externalBin). Harden detection and make failures diagnosable:

- sidecar + Rust now also find the CLI bundled with the VS Code ChatGPT extension (~/.vscode/extensions/openai.chatgpt-*/bin/<triple>/codex.exe)
- 'Codex CLI not found' error now lists every location checked (PATH, ~/.codex/bin, %LOCALAPPDATA%\\OpenAI\\Codex\\bin, VS Code extension)
- new Rust unit test for the VS Code extension lookup (9/9 codex tests pass)

Refs #32
…viders

Codex / Claude Agent execute tools internally; the streamed tool calls are informational evidence, not requests for the harness to route.

- ProviderCapabilities.agenticToolExecution flag (set on CodexProvider + ClaudeAgentProvider)
- Harness: for agentic providers, tool calls emit tool_call_start/tool_call_result (renders tool cards in the chat), are recorded in history + turn summary, and end the iteration normally instead of being routed (previously 'shell'/'apply_patch' would hit Unknown tool errors)
- New harness test for the informational path (220 tests pass)

Refs #32
Codex streams one agent_message item per interim step; the harness concatenated every text_delta into a single assistant message per iteration, gluing the agent's working notes and the final answer into one paragraph.

- New message_boundary StreamChunk (ai-providers types)
- Sidecar: emits message_boundary lazily before each subsequent non-empty agent_message (no trailing boundary, so the final segment stays the response)
- Transport maps it; harness finalizes the completed segment (history + transcript_message + new assistant_segment_end event) and resets buffers
- Bridge: assistant_segment_end flushes the current message and begins a new assistant message
- Tests: harness segment-splitting (221 pass), Rust boundary parse (10 pass)

Refs #32
…pricing)

Updated from developers.openai.com/api/docs/models (2026-08):

- gpt-5.6-sol: 1.05M ctx, \.00/\.50/\.00
- gpt-5.6-terra: 1.05M ctx, \.00/\.20/\.00
- gpt-5.6-luna: 1.05M ctx, \.20/\.02/\.20
- gpt-5.5: 1.05M ctx, \.00/\.50/\.00
- gpt-5.4: 1.05M ctx, \.50/\.25/\.00
- gpt-5.4-mini: 400K ctx, \.75/\.075/\.50

(input / cached input / output per 1M tokens). Docs table updated with a note about the >272K-token 2x/1.5x surcharge.

Refs #32
An empty model with an explicit providerId (provider switch with no enabled models, stale selection) was forwarded as model:'' — the Codex SDK treats '' as 'no --model flag', silently making the CLI use its own default model.

- registry.chat: empty model now falls back to the provider's first catalog model (all providers)
- CodexProvider.chat: guards params.model || first catalog model (last line of defense)
- New test: empty model → gpt-5.6-sol (32 ai-providers tests pass)

Refs #32
Stop support: the harness abort signal is now forwarded through CodexInvoke to the transport, which calls codex_cancel — Rust kills the sidecar process and emits the terminal 'Cancelled by user' chunk, so the stop button works immediately instead of waiting for the turn to finish.

Agent modes: ChatParams.agentMode (set by the harness from the agent type) is mapped to the Codex CLI native sandbox so mode restrictions are enforced, not just prompted:
- chat/review → read-only
- plan → workspace-write
- build/debug → danger-full-access
(unknown/empty → danger-full-access, previous behavior)

Chain: request-preparation → provider (AGENT_MODE_TO_SANDBOX) → transport → codex_run (sandbox_mode) → sidecar startThread({ sandboxMode }). New tests: signal forwarding + 7-case sandbox mapping table (34 ai-providers tests pass).

Refs #32
The mode system prompts referenced HysCode-only tools (read_file, edit_file, search_code, request_mode_switch, spawn_subagent, ask_user, memory tools...) that Codex does not have — noise that misdirected the agent.

- agents.ts: CODEX_AGENTIC base prompt (same structure: intent analysis, context verification, language, thinking, core principles; tool guidance adapted to shell/apply_patch/code search/web/AGENTS.md; HysCode mechanics replaced with agentic equivalents) + AGENTIC_MODE_FIXES (16 verbatim swaps across the chat/build/review/debug/plan role sections) + exported adaptSystemPromptForAgentic()
- context-manager: buildSnapshot(..., agenticExecution) adapts the base prompt (user overrides untouched)
- harness: resolves the provider before the snapshot and passes agenticToolExecution
- agents.test.ts: completeness guard — no HysCode tool name survives in any of the 5 adapted mode prompts; Codex guidance present; catches prompt drift (it already caught a real leftover, git_diff in the debug prompt)
- docs: AI_PROVIDERS.md sandbox mapping note

227 agent-harness tests pass (6 new), typecheck/lint/preflight green.

Refs #32
The assistant message now shows only the 'Agent' label (with the streaming indicator); the Sparkles avatar column and the consecutive-message spacer were removed. The icon remains in the empty state.

Refs #32
@github-actions github-actions Bot added area:desktop apps/desktop (Tauri shell, React UI) area:agent-harness packages/agent-harness area:ai-providers packages/ai-providers area:infra CI, build, release, dependências area:docs docs/, README, AGENTS, WORKFLOW labels Aug 2, 2026
@Estevaobonatto
Estevaobonatto merged commit aa72b85 into main Aug 2, 2026
2 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent-harness packages/agent-harness area:ai-providers packages/ai-providers area:desktop apps/desktop (Tauri shell, React UI) area:docs docs/, README, AGENTS, WORKFLOW area:infra CI, build, release, dependências

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant