How Pace calls Codex and APIs
The process arguments, request bodies, authentication sources, and completion rules for Pace 0.3.21 planner transports.
How Pace calls Codex and APIs
This guide follows the Pace 0.3.21 source. The requests below use illustrative prompts and contain no credentials.
How a turn picks a transport
BuddyPlannerClientFactory.makeDefault builds the client from the stored
planner tier. The dispatcher can resolve a local command before any model call.
Research and bounded answer routes can choose a different client for the turn.
The shared planner interface takes the current user prompt, system
instructions, available conversation history, and optional labeled images.
Each transport decides which inputs its wire protocol can carry.
| Route | Pace sends | Reply protocol |
|---|---|---|
| Codex CLI planner | Plain-text prompt over stdin and permitted JPEG files via --image |
Newline-delimited Codex JSON events on stdout |
| Retained Codex coding | JSON requests over the stdin of its workspace app-server process | Newline-delimited replies, notifications, and approval requests |
| Settings → Direct API | HTTP POST with Chat Completions messages |
Server-sent events with choices[0].delta.content |
| Optional fast answers | HTTP POST to OpenAI Responses with instructions and input |
Server-sent events validated at completion |
| CLI bridge | HTTP POST to the configured bridge’s /chat |
Server-sent events using the bridge’s own text/error shape |
| Local planner | Loopback LM Studio HTTP or in-process inference, depending on the selected backend | Local stream or in-process result |
Read client selection and turn dispatch.
Codex as the general planner
PaceLocalCLIPlannerClient resolves the installed codex executable and
launches it directly through Process. The CLI handles its own provider
authentication and model defaults. Pace builds the prompt by placing
System instructions: above the conversation turns and current request,
then writes it to the child process’s stdin. The request is scoped to an
ephemeral process run. Pace supplies the available history on each call.
The process runs in a private temporary directory with mode 0700.
These are some of the arguments Pace passes in the process array.
codex exec --json --ephemeral
--skip-git-repo-check
--ignore-user-config
--sandbox read-only
Pace also disables shell, hooks, apps, browser, computer-use, multi-agent,
and image-generation features for the planner invocation. Web search is
disabled for normal planning and enabled explicitly for research. A
permitted current-screen image is written as a JPEG inside the temporary
directory and supplied as --image <file>. Research runs are text-only.
Pace removes the temporary directory on exit.
The runner frames stdout into UTF-8 lines. The Codex parser extracts
item.text from item.completed events whose item type is
agent_message. It sends accumulated text to the planner callback.
The default completion policy seals valid, nonempty output at
turn.completed, then stops and reaps the owned process. The bounded
everyday CLI route buffers message items until the turn completes. Its
10-second budget differs from the default 120 seconds for general planning
and 300 seconds for research. Cancellation is checked during streaming and
after process cleanup.
Read arguments, prompt composition, and event parsing and the subprocess runner.
Codex as a retained coding session
The coding_session tool launches codex app-server --stdio in the
approved workspace. Pace sends one JSON object per line. An RPC request
contains an id, method, and params. A reply with that ID resolves
the pending request. A message with a method can carry a notification or
a server-initiated approval request.
The sequence starts with initialize and the initialized notification.
New sessions use thread/start. Existing ones use thread/read and
thread/resume with the stored thread ID. turn/start sends the new
task. turn/interrupt sends the owned thread and turn IDs for cancellation.
Pace matches completion notifications to the active turn, handles scoped
approval requests, and expires unanswered RPC requests after 30 seconds.
Process disconnect fails all pending RPCs.
The separate codex_session action opens an interactive Warp tab in the
requested folder. Image generation also has its own Codex invocation and
uses the image tool. Both have distinct entry points from chat planning.
Read stdio framing and handshake, session lifecycle, and image invocation.
Settings → Direct API
DirectAPIPlannerClient sends an OpenAI-compatible Chat Completions
request to the selected preset or custom endpoint. For the OpenAI preset
that is POST https://api.openai.com/v1/chat/completions. Pace reads the
configured provider’s key from macOS Keychain when the request is made.
OpenAI, OpenRouter, and custom endpoints get an Authorization bearer
header. The Anthropic preset sends x-api-key and
anthropic-version: 2023-06-01 with the same Chat Completions body.
The endpoint validator allows plain HTTP only for loopback hosts.
The body is text-only. Role-tagged history goes between the system message and current user message. If screen context is available, it can be part of the textual prompt. This client omits screenshot attachments.
{
"model": "gpt-4o-mini",
"messages": [
{ "role": "system", "content": "…" },
{ "role": "user", "content": "…" }
],
"max_tokens": 1024,
"temperature": 0.4,
"stream": true
}
URLSession.bytes(for:) reads the event stream. Pace accumulates content
deltas, strips thinking blocks, and forwards the text assembled so far.
[DONE] ends the stream. Non-2xx status and malformed nonempty SSE payloads
throw errors. HTTP 401 maps to an invalid-key error. The request and resource
timeouts are 300 and 360 seconds. The audit entry records provider/model,
outcome, character counts, and token counts when the upstream supplies them.
If the key is missing or the endpoint is invalid at setup, the factory uses
the local planner instead. That happens before any Direct API request.
Read HTTP request and response handling and messages construction.
Optional fast answers through OpenAI Responses
Fast replies have a separate opt-in under direct Codex. A simple eligible
text turn can send just the current question and fixed instructions. A
passive screen question also requires current screen permission and a valid
turn. That route sends the available conversation history and an
input_text block followed by permitted JPEGs as base64 input_image
data URLs. Action requests use the general planner and executor.
PaceOpenAIResponsesEverydayClient sends a bearer-authenticated
POST https://api.openai.com/v1/responses. Its JSON includes
model: gpt-6-luna, reasoning.effort: none, store: false,
max_output_tokens: 1024, text.verbosity: low, and stream: true.
PacePlannerCredentialStore uses the OpenAI Keychain entry or an explicitly
configured Infisical source. The Infisical credential cache is in memory.
HTTP 401 and 403 clear that cache.
Pace buffers up to 1 MiB of SSE with a 10-second request timeout. The parser
requires a complete response.completed event with status completed
and completed assistant output_text. Partial text does not reach speech.
For eligible failures such as a missing key, timeout, or rate limit, the
bounded route can fall back to the selected Codex planner. Cancellation,
revocation, refusal, and authentication or policy HTTP errors stop that
fallback. The passive-screen route also holds fallback output until it
rechecks authorization.
Read the Responses client, bounded routing and fallback, and credential handling.
Optional CLI bridge and local HTTP
CloudBridgePlannerClient posts provider, messages, and optional
systemPrompt and model to /chat on the configured bridge. The client
uses a text-only protocol. The bridge sends data: {"text":"…"},
data: {"error":"…"}, or data: [DONE]. Text events accumulate and
an error event fails the request. The bridge’s upstream CLI can contact
its provider even when the bridge itself listens on loopback.
LocalPlannerClient resolves a loopback endpoint. For structured actions,
it uses /v1/chat/completions with response_format: json_schema.
Eligible text requests prefer LM Studio’s /api/v1/chat with reasoning off.
If the native stream is unavailable before delivering text, the client can
use the OpenAI-compatible loopback route. Apple Foundation Models and the
bundled MLX planner perform inference in-process.
Read bridge protocol and local HTTP routing and request tuning.
Inspect a call without reading credentials
Use Usage in the chat options or the local PaceAPIAuditLog records
under Application Support. Compare entries sharing the same turn ID.
The direct CLI transport records planner.cliDirect, Chat Completions
planner.directAPI, submitted Responses planner.directAPI.responses,
and the bridge planner.cloudBridge. The Responses preflight uses
planner.openai.responses.preflight, which distinguishes a credential
or authorization failure before the HTTP request from a submitted attempt.
Routing decisions can appear as planner.routing. The request audits
record timing, outcome, and size or usage metadata.
The source tests cover the request shape, parser, process runner, and server lifecycle with fixtures. The isolated runner accepts suite names.
bash scripts/test-pace.sh \
PaceLocalCLIStreamJSONParserTests \
PaceCLIProcessRunnerTests \
PaceCLIDirectPlannerTierTests \
DirectAPIPlannerClientTests \
PaceEverydayAnswerClientTests \
CloudBridgePlannerClientTests \
PaceCodingSessionTests
Follow the returned proposal through the typed action parser and executor in the runtime traces.