Files
openclaw/extensions/codex/src/commands.ts
pashpashpash c3af812fe3 Show Codex subscription reset times in channel errors (#80456)
* fix(codex): refresh subscription limit resets

* fix(codex): format reset times for channels

* Update CHANGELOG with latest changes and fixes

Updated CHANGELOG with recent fixes and improvements.

* fix(codex): keep command load failures on codex surface

* fix(codex): format account rate limits as rows

* fix(codex): summarize account limits as usage status

* fix(codex): simplify account limit status
2026-05-11 09:42:06 +09:00

60 lines
2.1 KiB
TypeScript

import type {
OpenClawPluginCommandDefinition,
PluginCommandContext,
PluginCommandResult,
} from "openclaw/plugin-sdk/plugin-entry";
import { describeControlFailure } from "./app-server/capabilities.js";
import { formatCodexDisplayText } from "./command-formatters.js";
import type { CodexCommandDeps } from "./command-handlers.js";
type CodexCommandOptions = {
pluginConfig?: unknown;
deps?: Partial<CodexCommandDeps>;
};
type CodexSubcommandHandler = (
ctx: PluginCommandContext,
options: CodexCommandOptions,
) => Promise<PluginCommandResult>;
type CodexCommandInternalOptions = CodexCommandOptions & {
loadSubcommandHandler?: () => Promise<CodexSubcommandHandler>;
};
export function createCodexCommand(options: CodexCommandOptions): OpenClawPluginCommandDefinition {
return {
name: "codex",
description: "Inspect and control the Codex app-server harness",
ownership: "reserved",
agentPromptGuidance: [
"Native Codex app-server plugin is available (`/codex ...`). For Codex bind/control/thread/resume/steer/stop requests, prefer `/codex bind`, `/codex threads`, `/codex resume`, `/codex steer`, and `/codex stop` over ACP.",
"Use ACP for Codex only when the user explicitly asks for ACP/acpx or wants to test the ACP path.",
],
acceptsArgs: true,
requireAuth: true,
handler: (ctx) => handleCodexCommand(ctx, options),
};
}
export async function handleCodexCommand(
ctx: PluginCommandContext,
options: CodexCommandInternalOptions = {},
): Promise<PluginCommandResult> {
const { loadSubcommandHandler, ...subcommandOptions } = options;
try {
const handleCodexSubcommand = loadSubcommandHandler
? await loadSubcommandHandler()
: await loadDefaultCodexSubcommandHandler();
return await handleCodexSubcommand(ctx, subcommandOptions);
} catch (error) {
return {
text: `Codex command failed: ${formatCodexDisplayText(describeControlFailure(error))}`,
};
}
}
async function loadDefaultCodexSubcommandHandler(): Promise<CodexSubcommandHandler> {
const { handleCodexSubcommand } = await import("./command-handlers.js");
return handleCodexSubcommand;
}