{"modulePath":"github.com/Quality-Max/qmax-code","version":"v1.40.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package codexrunner\n\nPackage codexrunner executes Codex CLI turns without depending on qmax-code's terminal or on any private cloud implementation.\n\nA first turn invokes \"codex exec \\[--model \\\u003cmodel\u003e] --json -\". A continued turn invokes \"codex exec resume \\[--model \\\u003cmodel\u003e] --json \\\u003cthread\\_id\u003e -\" with a validated, explicit thread ID. When a model is supplied, it is validated against an exact allowlist before process start and is preserved in durable checkpoints. Prompts are supplied only through stdin. Raw provider events and diagnostics are never exposed through the structural event interfaces.\n\nBecause \"codex exec resume\" resolves a thread from the local Codex session store, a checkpoint also records the path of the rollout backing its thread. The package locates that file and nothing more: it never reads, uploads, or logs a rollout. Hosts that move a session between sandboxes are responsible for shipping the file and for restoring it before they resume, and Continuity.Restore refuses a checkpoint whose rollout is not present rather than resuming into a thread this box cannot reconstruct.\n\n## Constants\n\n```go\nconst (\n\t// DefaultModel is the deterministic Codex model selected by QualityMax when\n\t// a product client chooses Auto or has no saved preference.\n\tDefaultModel = \"gpt-5.6-terra\"\n)\n```\n\n## Variables\n\n```go\nvar (\n\t// ErrInvalidThreadID means a caller or stream supplied a non-canonical UUID.\n\tErrInvalidThreadID = errors.New(\"codex runner: invalid thread ID\")\n\t// ErrInvalidRolloutPath means a checkpoint carried a rollout reference that\n\t// is not an absolute path, so it cannot be resolved on another box.\n\tErrInvalidRolloutPath = errors.New(\"codex runner: invalid rollout path\")\n\t// ErrRolloutUnavailable means a checkpoint named a rollout that is not\n\t// present on this box, which is the expected result of restoring a\n\t// checkpoint into a replacement sandbox. Callers must surface a recovery\n\t// reason and start a new thread rather than resume into an empty one.\n\tErrRolloutUnavailable = errors.New(\"codex runner: checkpoint rollout unavailable\")\n\t// ErrThreadMismatch means a resumed stream identified a different thread.\n\tErrThreadMismatch = errors.New(\"codex runner: resumed thread does not match checkpoint\")\n\t// ErrMissingThreadID means the stream ended without a thread.started event.\n\tErrMissingThreadID = errors.New(\"codex runner: thread ID missing from stream\")\n\t// ErrMalformedStream means stdout was not a valid Codex JSONL event stream.\n\tErrMalformedStream = errors.New(\"codex runner: malformed event stream\")\n\t// ErrStart means the Codex process could not be started.\n\tErrStart = errors.New(\"codex runner: process start failed\")\n\t// ErrProcess means Codex exited unsuccessfully.\n\tErrProcess = errors.New(\"codex runner: process failed\")\n\t// ErrModelUnavailable means Codex rejected the selected model. Raw CLI\n\t// diagnostics are never returned because they may contain provider data.\n\tErrModelUnavailable = errors.New(\"codex runner: selected model unavailable\")\n\t// ErrAuthentication means Codex reported that its local login is missing,\n\t// expired, or unauthorized.\n\tErrAuthentication = errors.New(\"codex runner: authentication required\")\n\t// ErrEventSink means a structural event consumer rejected an event.\n\tErrEventSink = errors.New(\"codex runner: event sink failed\")\n\t// ErrCheckpointSink means a checkpoint consumer rejected a checkpoint.\n\tErrCheckpointSink = errors.New(\"codex runner: checkpoint sink failed\")\n\t// ErrPresenter means the response presenter rejected an update.\n\tErrPresenter = errors.New(\"codex runner: presenter failed\")\n\t// ErrRunnerUnavailable means a Continuity was created without a Runner.\n\tErrRunnerUnavailable = errors.New(\"codex runner: runner unavailable\")\n)\n```\n\n```go\nvar (\n\t// ErrInvalidModel means a caller supplied a model outside the exact product\n\t// allowlist. The value is never forwarded to the process boundary.\n\tErrInvalidModel = errors.New(\"codex runner: invalid model\")\n)\n```\n\n## Functions\n\n```go\nfunc SupportedModels() []string\n```\nSupportedModels returns a defensive copy of the exact Codex model allowlist shared by the QualityMax coding-agent contract.\n\n```go\nfunc ValidateModel(model string) error\n```\nValidateModel accepts only exact allowlisted model IDs. Empty and \"auto\" are product-level choices that must be resolved before a durable handoff.\n\n## Types\n\n```go\ntype Cancellation interface {\n\tcontext.Context\n}\n```\nCancellation is the runner's cancellation boundary. A standard context.Context satisfies it, preserving deadlines and process teardown without coupling callers to a terminal implementation.\n\n```go\ntype Checkpoint struct {\n\tThreadID string\n\tModel    string\n\t// RolloutPath is the local Codex rollout for ThreadID, or \"\" when the\n\t// executor cannot locate one. Callers upload it and record the result as\n\t// checkpoint.codex.rollout_ref; this package never reads or ships the\n\t// file itself.\n\tRolloutPath string\n}\n```\nCheckpoint is the minimum durable state required to continue a Codex thread on the same exact model.\n\nThreadID alone is only sufficient on the box that produced it: \"codex exec resume\" resolves a thread from the local Codex session store, so a thread ID restored into a fresh sandbox names a rollout that no longer exists there. RolloutPath is what makes the thread portable.\n\n```go\ntype CheckpointSink interface {\n\tOnCheckpoint(context.Context, Checkpoint) error\n}\n```\nCheckpointSink persists a validated checkpoint as soon as thread.started is observed, including when the turn later fails or is canceled.\n\n```go\ntype CheckpointSinkFunc func(context.Context, Checkpoint) error\n```\nCheckpointSinkFunc adapts a function to CheckpointSink.\n\n```go\nfunc (f CheckpointSinkFunc) OnCheckpoint(ctx context.Context, checkpoint Checkpoint) error\n```\nOnCheckpoint implements CheckpointSink.\n\n```go\ntype CodexHomeLocator struct {\n\t// Home overrides the Codex home directory. Empty resolves $CODEX_HOME,\n\t// then $HOME/.codex.\n\tHome string\n}\n```\nCodexHomeLocator finds rollouts in a Codex session store. Codex writes one rollout per thread under sessions/\\\u003cyyyy\u003e/\\\u003cmm\u003e/\\\u003cdd\u003e/rollout-\\\u003ctimestamp\u003e-\\\u003cthread\\_id\u003e.jsonl.\n\n```go\nfunc (locator CodexHomeLocator) LocateRollout(threadID string) string\n```\nLocateRollout implements RolloutLocator. It returns an absolute path, or \"\" when the store is absent or holds no rollout for threadID.\n\n```go\ntype Command struct {\n\tExecutable       string\n\tArgs             []string\n\tStdin            io.Reader\n\tWorkingDirectory string\n}\n```\nCommand describes one direct process invocation. Stdin carries the prompt; Args is always one of the fixed, allowlisted command shapes documented by this package. Stderr is deliberately absent so raw diagnostics cannot be logged.\n\n```go\ntype Continuity struct {\n\t// contains filtered or unexported fields\n}\n```\nContinuity serializes turns and remembers only the exact validated thread and model checkpoint. It stores no prompts, responses, source, or provider payloads. Durable callers should also provide Hooks.Checkpoints on every turn.\n\n```go\nfunc NewContinuity(runner *Runner) *Continuity\n```\nNewContinuity creates an empty continuity adapter for runner.\n\n```go\nfunc (continuity *Continuity) Checkpoint() Checkpoint\n```\nCheckpoint returns the current exact continuity state.\n\n```go\nfunc (continuity *Continuity) Reset()\n```\nReset forgets the current thread so the next Run starts a new one.\n\n```go\nfunc (continuity *Continuity) Restore(checkpoint Checkpoint) error\n```\nRestore validates and installs a durable checkpoint. An empty checkpoint is equivalent to Reset.\n\nA checkpoint naming a rollout that is not present on this box is refused with ErrRolloutUnavailable and not installed, so a replacement sandbox cannot resume into a thread whose transcript it does not have. Callers recover by reporting the reason and restoring the same checkpoint with RolloutPath cleared, which starts a new thread.\n\n```go\nfunc (continuity *Continuity) Run(ctx Cancellation, prompt string, hooks Hooks) (Result, error)\n```\nRun executes a turn using the current checkpoint and atomically adopts the validated checkpoint emitted by the runner, even if the turn later fails.\n\n```go\ntype Event struct {\n\tKind  EventKind\n\tUsage Usage\n}\n```\nEvent is safe for lifecycle observation and metrics. It never contains raw provider content.\n\n```go\ntype EventKind uint8\n```\nEventKind identifies a safe structural lifecycle event. Events intentionally contain no prompt, response, source, tool arguments, provider message, or raw JSON payload.\n\n```go\nconst (\n\tEventThreadStarted EventKind = iota + 1\n\tEventTurnStarted\n\tEventAssistantMessage\n\tEventTurnCompleted\n\tEventProviderError\n\tEventPlanLimit\n)\n```\n\n```go\ntype EventSink interface {\n\tOnEvent(context.Context, Event) error\n}\n```\nEventSink consumes structural runner events.\n\n```go\ntype EventSinkFunc func(context.Context, Event) error\n```\nEventSinkFunc adapts a function to EventSink.\n\n```go\nfunc (f EventSinkFunc) OnEvent(ctx context.Context, event Event) error\n```\nOnEvent implements EventSink.\n\n```go\ntype Hooks struct {\n\tEvents      EventSink\n\tCheckpoints CheckpointSink\n\tPresenter   Presenter\n}\n```\nHooks are optional per-turn observation and presentation boundaries.\n\n```go\ntype OSExecutor struct{}\n```\nOSExecutor starts the local Codex executable directly, without a shell. Stderr is retained only in a small private buffer and reduced to safe error categories; raw provider diagnostics never cross the process boundary.\n\n```go\nfunc (OSExecutor) Start(ctx context.Context, command Command) (ToolProcess, error)\n```\nStart implements ToolExecutor.\n\n```go\ntype Options struct {\n\tExecutable       string\n\tWorkingDirectory string\n\tExecutor         ToolExecutor\n\t// Rollouts resolves the local rollout backing a thread. A nil locator uses\n\t// CodexHomeLocator.\n\tRollouts RolloutLocator\n}\n```\nOptions configures an immutable Runner.\n\n```go\ntype Presentation struct {\n\tKind PresentationKind\n\tText string\n}\n```\nPresentation is the only callback value that may contain response or tool content.\n\n```go\ntype PresentationKind uint8\n```\nPresentationKind distinguishes response text from a sanitized provider notice. PresentationText contains model output and must be rendered directly, not logged or copied into metrics.\n\n```go\nconst (\n\tPresentationText PresentationKind = iota + 1\n\tPresentationPlanLimit\n\t// PresentationTool carries exposed tool activity only to the content boundary.\n\tPresentationTool\n)\n```\n\n```go\ntype Presenter interface {\n\tPresent(context.Context, Presentation) error\n}\n```\nPresenter is the terminal-neutral rendering boundary. Cloud callers may omit it and consume Result.Response through their protected artifact boundary.\n\n```go\ntype PresenterFunc func(context.Context, Presentation) error\n```\nPresenterFunc adapts a function to Presenter.\n\n```go\nfunc (f PresenterFunc) Present(ctx context.Context, presentation Presentation) error\n```\nPresent implements Presenter.\n\n```go\ntype Result struct {\n\tThreadID  string\n\tModel     string\n\tResponse  string\n\tUsage     Usage\n\tCanceled  bool\n\tPlanLimit bool\n\t// RolloutPath mirrors Checkpoint.RolloutPath for the thread this turn ran\n\t// on, so a caller adopting a Result as durable state does not silently\n\t// drop the rollout reference the checkpoint sink already received.\n\tRolloutPath string\n}\n```\nResult contains the exact validated Codex thread ID, selected model, and response. Response is transcript data and must not be logged or placed in workflow history.\n\n```go\ntype RolloutLocator interface {\n\tLocateRollout(threadID string) string\n}\n```\nRolloutLocator resolves the local Codex rollout file backing a validated thread ID. It returns an empty path when no rollout can be found, which the runner records as \"not locatable\" rather than as an error: a checkpoint without a rollout is still a usable same-sandbox checkpoint.\n\nImplementations must not read or log rollout contents. A rollout is a full transcript, and this package never moves transcript data outside Presenter.\n\n```go\ntype RolloutLocatorFunc func(threadID string) string\n```\nRolloutLocatorFunc adapts a function to RolloutLocator.\n\n```go\nfunc (f RolloutLocatorFunc) LocateRollout(threadID string) string\n```\nLocateRollout implements RolloutLocator.\n\n```go\ntype Runner struct {\n\t// contains filtered or unexported fields\n}\n```\nRunner executes terminal-neutral Codex turns.\n\n```go\nfunc New(options Options) *Runner\n```\nNew returns a runner. An empty executable uses \"codex\", a nil executor uses the local OS process implementation, and a nil rollout locator uses CodexHomeLocator.\n\n```go\nfunc (r *Runner) Run(ctx Cancellation, turn Turn) (Result, error)\n```\nRun executes one turn. Cancellation is controlled exclusively by ctx.\n\n```go\ntype ToolExecutor interface {\n\tStart(context.Context, Command) (ToolProcess, error)\n}\n```\nToolExecutor starts Codex without coupling the runner to a terminal or a particular process host.\n\n```go\ntype ToolProcess interface {\n\tStdout() io.Reader\n\tWait() error\n}\n```\nToolProcess is the minimal process boundary required by Runner.\n\n```go\ntype Turn struct {\n\tPrompt   string\n\tThreadID string\n\tModel    string\n\tHooks    Hooks\n}\n```\nTurn contains the sensitive prompt, an optional exact continuity ID, and an optional exact model. When Model is present, it must be allowlisted and is passed on both initial and resumed commands. Callers must not log Prompt.\n\n```go\ntype Usage struct {\n\tInputTokens  int\n\tOutputTokens int\n}\n```\nUsage is aggregate token accounting reported by Codex for one turn.\n\n","path":"github.com/Quality-Max/qmax-code/codexrunner","name":"codexrunner","synopsis":"Package codexrunner executes Codex CLI turns without depending on qmax-code's terminal or on any private cloud implementation.","isRedistributable":true}
