-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat: rig edition — tier routing, typed envelopes, quota failover, fanout/council/cloud verbs #488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nategarelik
wants to merge
5
commits into
openai:main
Choose a base branch
from
nategarelik:feat/rig-edition
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8b49e99
fix: stop wrapping Windows spawns in process.env.SHELL
nategarelik 31090c0
fix: resolve cmd.exe via SystemRoot instead of trusting ComSpec
nategarelik 59c9306
feat: add rig-edition tier routing, envelope validation, and quota fa…
nategarelik a422769
feat: add rig-edition fanout, council, and cloud verbs
nategarelik 94026da
fix: contain fanout worktree-creation failures to a single worker
nategarelik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| /** | ||
| * Rig-edition cloud verb: a thin, envelope-wrapping passthrough over the | ||
| * `codex cloud` CLI surface (EXPERIMENTAL upstream; verified 0.144.1). | ||
| * | ||
| * `codex cloud` browses and drives OpenAI-hosted Codex Cloud tasks -- a | ||
| * different execution target than the local app-server turns the rest of | ||
| * rig-edition drives. It is not an app-server JSON-RPC session, so there is | ||
| * no structured Codex-side envelope to parse; this module builds one from | ||
| * the CLI's exit status instead. | ||
| * | ||
| * Verified subcommand surface (codex cloud --help / <subcommand> --help, | ||
| * 0.144.1): exec, status, list, apply, diff. `exec` requires --env <ENV_ID> | ||
| * (a Codex Cloud environment id, not a local worktree) and takes an | ||
| * optional --branch/--attempts; `list` supports --env/--limit/--cursor/ | ||
| * --json; `status`/`apply`/`diff` take a positional task id, with | ||
| * apply/diff also accepting --attempt. | ||
| */ | ||
| import { runCommand } from "./process.mjs"; | ||
|
|
||
| export const CLOUD_SUBCOMMANDS = Object.freeze(["exec", "status", "list", "apply", "diff"]); | ||
|
|
||
| function pushValueArg(args, flag, value) { | ||
| if (value === undefined || value === null || value === "") { | ||
| return; | ||
| } | ||
| args.push(flag, String(value)); | ||
| } | ||
|
|
||
| function requireTaskId(options) { | ||
| if (!isNonEmptyString(options.taskId)) { | ||
| throw new Error("This `codex cloud` subcommand requires a task id."); | ||
| } | ||
| return String(options.taskId); | ||
| } | ||
|
|
||
| function isNonEmptyString(value) { | ||
| return typeof value === "string" && value.trim().length > 0; | ||
| } | ||
|
|
||
| function buildExecArgs(options) { | ||
| if (!isNonEmptyString(options.env)) { | ||
| throw new Error("`codex cloud exec` requires --env <ENV_ID>."); | ||
| } | ||
| const args = ["--env", String(options.env)]; | ||
| pushValueArg(args, "--attempts", options.attempts); | ||
| pushValueArg(args, "--branch", options.branch); | ||
| if (isNonEmptyString(options.query)) { | ||
| args.push(String(options.query)); | ||
| } | ||
| return args; | ||
| } | ||
|
|
||
| function buildStatusArgs(options) { | ||
| return [requireTaskId(options)]; | ||
| } | ||
|
|
||
| function buildListArgs(options) { | ||
| const args = []; | ||
| pushValueArg(args, "--env", options.env); | ||
| pushValueArg(args, "--limit", options.limit); | ||
| pushValueArg(args, "--cursor", options.cursor); | ||
| if (options.json) { | ||
| args.push("--json"); | ||
| } | ||
| return args; | ||
| } | ||
|
|
||
| function buildApplyArgs(options) { | ||
| const args = [requireTaskId(options)]; | ||
| pushValueArg(args, "--attempt", options.attempt); | ||
| return args; | ||
| } | ||
|
|
||
| function buildDiffArgs(options) { | ||
| const args = [requireTaskId(options)]; | ||
| pushValueArg(args, "--attempt", options.attempt); | ||
| return args; | ||
| } | ||
|
|
||
| const ARG_BUILDERS = Object.freeze({ | ||
| exec: buildExecArgs, | ||
| status: buildStatusArgs, | ||
| list: buildListArgs, | ||
| apply: buildApplyArgs, | ||
| diff: buildDiffArgs | ||
| }); | ||
|
|
||
| /** | ||
| * Builds the full `codex cloud <subcommand> ...` argv for a given verb and | ||
| * options, applying the same validation the upstream CLI would enforce. | ||
| * @param {string} subcommand | ||
| * @param {Record<string, unknown>} [options] | ||
| * @returns {string[]} | ||
| */ | ||
| export function buildCloudArgs(subcommand, options = {}) { | ||
| const builder = ARG_BUILDERS[subcommand]; | ||
| if (!builder) { | ||
| throw new Error(`Unknown "codex cloud" subcommand "${subcommand}". Use one of: ${CLOUD_SUBCOMMANDS.join(", ")}.`); | ||
| } | ||
| return ["cloud", subcommand, ...builder(options)]; | ||
| } | ||
|
|
||
| function buildEnvelope(subcommand, result) { | ||
| const stdout = (result.stdout ?? "").trim(); | ||
| const stderr = (result.stderr ?? "").trim(); | ||
| const succeeded = !result.error && result.status === 0; | ||
|
|
||
| return Object.freeze({ | ||
| status: succeeded ? "DONE" : "BLOCKED", | ||
| summary: succeeded ? `codex cloud ${subcommand} completed.` : `codex cloud ${subcommand} failed.`, | ||
| files_modified: Object.freeze([]), | ||
| concerns: Object.freeze(succeeded ? [] : [stderr || stdout || `exit ${result.status}`]), | ||
| blocked_reason: succeeded ? null : "CLOUD_COMMAND_FAILED" | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Runs a `codex cloud` subcommand and wraps the result in a typed envelope. | ||
| * @param {string} subcommand | ||
| * @param {Record<string, unknown> & { cwd?: string, runCommand?: typeof runCommand }} [options] | ||
| */ | ||
| export function runCloudCommand(subcommand, options = {}) { | ||
| const runner = options.runCommand ?? runCommand; | ||
| const args = buildCloudArgs(subcommand, options); | ||
| const result = runner("codex", args, { cwd: options.cwd, shell: false }); | ||
|
|
||
| return Object.freeze({ | ||
| exitStatus: result.status, | ||
| stdout: result.stdout, | ||
| stderr: result.stderr, | ||
| envelope: buildEnvelope(subcommand, result) | ||
| }); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This forces
runCommandto bypass its Windows default shell. For npm-installed Codex on Windows the executable is thecodex.cmdshim (the adjacent app-server spawn was changed for this), socodex cloud ...fails before the CLI starts whenever only that shim is on PATH; letrunCommandchoose its default shell or use the resolved Windows shell on win32.Useful? React with 👍 / 👎.