@ccusage/codex
Version:
Usage analysis tool for OpenAI Codex sessions
1,069 lines • 306 kB
JavaScript
#!/usr/bin/env node
import { createRequire } from "node:module";
import process$1 from "node:process";
import { formatWithOptions } from "node:util";
import os from "node:os";
import path, { basename, dirname, normalize, posix, relative, resolve, sep } from "node:path";
import a, { readFile, stat } from "node:fs/promises";
import * as nativeFs from "node:fs";
import b from "node:fs";
import { fileURLToPath } from "node:url";
import * as tty from "node:tty";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i$1 = 0, n$2 = keys.length, key; i$1 < n$2; i$1++) {
key = keys[i$1];
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: ((k$1) => from[k$1]).bind(null, key),
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod));
var __require$1 = /* @__PURE__ */ createRequire(import.meta.url);
const DEFAULT_LOCALE$1 = "en-US";
const BUILT_IN_PREFIX = "_";
const ARG_PREFIX = "arg";
const BUILT_IN_KEY_SEPARATOR = ":";
const ANONYMOUS_COMMAND_NAME = "(anonymous)";
const NOOP = () => {};
const COMMON_ARGS = {
help: {
type: "boolean",
short: "h",
description: "Display this help message"
},
version: {
type: "boolean",
short: "v",
description: "Display this version"
}
};
const COMMAND_OPTIONS_DEFAULT = {
name: void 0,
description: void 0,
version: void 0,
cwd: void 0,
usageSilent: false,
subCommands: void 0,
leftMargin: 2,
middleMargin: 10,
usageOptionType: false,
usageOptionValue: true,
renderHeader: void 0,
renderUsage: void 0,
renderValidationErrors: void 0,
translationAdapterFactory: void 0
};
function isLazyCommand(cmd) {
return typeof cmd === "function" && "commandName" in cmd && !!cmd.commandName;
}
async function resolveLazyCommand(cmd, name$1, needRunResolving = false) {
let command;
if (isLazyCommand(cmd)) {
command = Object.assign(create(), {
name: cmd.commandName,
description: cmd.description,
args: cmd.args,
examples: cmd.examples,
resource: cmd.resource
});
if (needRunResolving) {
const loaded = await cmd();
if (typeof loaded === "function") command.run = loaded;
else if (typeof loaded === "object") {
if (loaded.run == null) throw new TypeError(`'run' is required in command: ${cmd.name || name$1}`);
command.run = loaded.run;
command.name = loaded.name;
command.description = loaded.description;
command.args = loaded.args;
command.examples = loaded.examples;
command.resource = loaded.resource;
} else throw new TypeError(`Cannot resolve command: ${cmd.name || name$1}`);
}
} else command = Object.assign(create(), cmd);
if (command.name == null && name$1) command.name = name$1;
return deepFreeze(command);
}
function resolveBuiltInKey(key) {
return `${BUILT_IN_PREFIX}${BUILT_IN_KEY_SEPARATOR}${key}`;
}
function resolveArgKey(key) {
return `${ARG_PREFIX}${BUILT_IN_KEY_SEPARATOR}${key}`;
}
async function resolveExamples(ctx, examples) {
return typeof examples === "string" ? examples : typeof examples === "function" ? await examples(ctx) : "";
}
function mapResourceWithBuiltinKey(resource) {
return Object.entries(resource).reduce((acc, [key, value]) => {
acc[resolveBuiltInKey(key)] = value;
return acc;
}, create());
}
function create(obj = null) {
return Object.create(obj);
}
function log$3(...args) {
console.log(...args);
}
function deepFreeze(obj) {
if (obj === null || typeof obj !== "object") return obj;
for (const key of Object.keys(obj)) {
const value = obj[key];
if (typeof value === "object" && value !== null) deepFreeze(value);
}
return Object.freeze(obj);
}
var en_US_default = {
COMMAND: "COMMAND",
COMMANDS: "COMMANDS",
SUBCOMMAND: "SUBCOMMAND",
USAGE: "USAGE",
ARGUMENTS: "ARGUMENTS",
OPTIONS: "OPTIONS",
EXAMPLES: "EXAMPLES",
FORMORE: "For more info, run any command with the `--help` flag:",
NEGATABLE: "Negatable of",
DEFAULT: "default",
CHOICES: "choices",
help: "Display this help message",
version: "Display this version"
};
function createTranslationAdapter(options) {
return new DefaultTranslation(options);
}
var DefaultTranslation = class {
#resources = /* @__PURE__ */ new Map();
#options;
constructor(options) {
this.#options = options;
this.#resources.set(options.locale, create());
if (options.locale !== options.fallbackLocale) this.#resources.set(options.fallbackLocale, create());
}
getResource(locale) {
return this.#resources.get(locale);
}
setResource(locale, resource) {
this.#resources.set(locale, resource);
}
getMessage(locale, key) {
const resource = this.getResource(locale);
if (resource) return resource[key];
}
translate(locale, key, values = create()) {
let message = this.getMessage(locale, key);
if (message === void 0 && locale !== this.#options.fallbackLocale) message = this.getMessage(this.#options.fallbackLocale, key);
if (message === void 0) return;
return message.replaceAll(/\{\{(\w+)\}\}/g, (_$1, name$1) => {
return values[name$1] == null ? "" : values[name$1].toString();
});
}
};
const BUILT_IN_PREFIX_CODE = BUILT_IN_PREFIX.codePointAt(0);
async function createCommandContext({ args, values, positionals, rest, argv: argv$2, tokens, command, cliOptions, callMode = "entry", omitted = false }) {
const _args = Object.entries(args).reduce((acc, [key, value]) => {
acc[key] = Object.assign(create(), value);
return acc;
}, create());
const env$3 = Object.assign(create(), COMMAND_OPTIONS_DEFAULT, cliOptions);
const locale = resolveLocale(cliOptions.locale);
const localeStr = locale.toString();
const adapter = (cliOptions.translationAdapterFactory || createTranslationAdapter)({
locale: localeStr,
fallbackLocale: DEFAULT_LOCALE$1
});
const localeResources = /* @__PURE__ */ new Map();
let builtInLoadedResources;
localeResources.set(DEFAULT_LOCALE$1, mapResourceWithBuiltinKey(en_US_default));
if (DEFAULT_LOCALE$1 !== localeStr) try {
builtInLoadedResources = (await import(`./locales/${localeStr}.json`, { with: { type: "json" } })).default;
localeResources.set(localeStr, mapResourceWithBuiltinKey(builtInLoadedResources));
} catch {}
function translate(key, values$1 = create()) {
const strKey = key;
if (strKey.codePointAt(0) === BUILT_IN_PREFIX_CODE) return (localeResources.get(localeStr) || localeResources.get(DEFAULT_LOCALE$1))[strKey] || strKey;
else return adapter.translate(locale.toString(), strKey, values$1) || "";
}
let cachedCommands;
async function loadCommands() {
if (cachedCommands) return cachedCommands;
const subCommands$1 = [...cliOptions.subCommands || []];
return cachedCommands = await Promise.all(subCommands$1.map(async ([name$1, cmd]) => await resolveLazyCommand(cmd, name$1)));
}
const ctx = deepFreeze(Object.assign(create(), {
name: getCommandName(command),
description: command.description,
omitted,
callMode,
locale,
env: env$3,
args: _args,
values,
positionals,
rest,
_: argv$2,
tokens,
toKebab: command.toKebab,
log: cliOptions.usageSilent ? NOOP : log$3,
loadCommands,
translate
}));
const defaultCommandResource = Object.entries(args).map(([key, arg]) => {
const description$1 = arg.description || "";
return [key, description$1];
}).reduce((res, [key, value]) => {
res[resolveArgKey(key)] = value;
return res;
}, create());
defaultCommandResource.description = command.description || "";
defaultCommandResource.examples = await resolveExamples(ctx, command.examples);
adapter.setResource(DEFAULT_LOCALE$1, defaultCommandResource);
const originalResource = await loadCommandResource(ctx, command);
if (originalResource) {
const resource = Object.assign(create(), originalResource, { examples: await resolveExamples(ctx, originalResource.examples) });
if (builtInLoadedResources) {
resource.help = builtInLoadedResources.help;
resource.version = builtInLoadedResources.version;
}
adapter.setResource(localeStr, resource);
}
return ctx;
}
function getCommandName(cmd) {
if (isLazyCommand(cmd)) return cmd.commandName || cmd.name || ANONYMOUS_COMMAND_NAME;
else if (typeof cmd === "object") return cmd.name || ANONYMOUS_COMMAND_NAME;
else return ANONYMOUS_COMMAND_NAME;
}
function resolveLocale(locale) {
return locale instanceof Intl.Locale ? locale : typeof locale === "string" ? new Intl.Locale(locale) : new Intl.Locale(DEFAULT_LOCALE$1);
}
async function loadCommandResource(ctx, command) {
let resource;
try {
resource = await command.resource?.(ctx);
} catch {}
return resource;
}
function define(definition) {
return definition;
}
/**
* @author kazuya kawaguchi (a.k.a. kazupon)
* @license MIT
*/
function kebabnize(str) {
return str.replace(/[A-Z]/g, (match, offset) => (offset > 0 ? "-" : "") + match.toLowerCase());
}
function renderHeader(ctx) {
const title = ctx.env.description || ctx.env.name || "";
return Promise.resolve(title ? `${title} (${ctx.env.name || ""}${ctx.env.version ? ` v${ctx.env.version}` : ""})` : title);
}
const COMMON_ARGS_KEYS = Object.keys(COMMON_ARGS);
async function renderUsage(ctx) {
const messages$1 = [];
if (!ctx.omitted) {
const description$1 = resolveDescription(ctx);
if (description$1) messages$1.push(description$1, "");
}
messages$1.push(...await renderUsageSection(ctx), "");
if (ctx.omitted && await hasCommands(ctx)) messages$1.push(...await renderCommandsSection(ctx), "");
if (hasPositionalArgs(ctx)) messages$1.push(...await renderPositionalArgsSection(ctx), "");
if (hasOptionalArgs(ctx)) messages$1.push(...await renderOptionalArgsSection(ctx), "");
const examples = await renderExamplesSection(ctx);
if (examples.length > 0) messages$1.push(...examples, "");
return messages$1.join("\n");
}
async function renderPositionalArgsSection(ctx) {
const messages$1 = [];
messages$1.push(`${ctx.translate(resolveBuiltInKey("ARGUMENTS"))}:`);
messages$1.push(await generatePositionalArgsUsage(ctx));
return messages$1;
}
async function renderOptionalArgsSection(ctx) {
const messages$1 = [];
messages$1.push(`${ctx.translate(resolveBuiltInKey("OPTIONS"))}:`);
messages$1.push(await generateOptionalArgsUsage(ctx, getOptionalArgsPairs(ctx)));
return messages$1;
}
async function renderExamplesSection(ctx) {
const messages$1 = [];
const resolvedExamples = await resolveExamples$1(ctx);
if (resolvedExamples) {
const examples = resolvedExamples.split("\n").map((example) => example.padStart(ctx.env.leftMargin + example.length));
messages$1.push(`${ctx.translate(resolveBuiltInKey("EXAMPLES"))}:`, ...examples);
}
return messages$1;
}
async function renderUsageSection(ctx) {
const messages$1 = [`${ctx.translate(resolveBuiltInKey("USAGE"))}:`];
if (ctx.omitted) {
const defaultCommand = `${resolveEntry(ctx)}${await hasCommands(ctx) ? ` [${resolveSubCommand(ctx)}]` : ""} ${[generateOptionsSymbols(ctx), generatePositionalSymbols(ctx)].filter(Boolean).join(" ")}`;
messages$1.push(defaultCommand.padStart(ctx.env.leftMargin + defaultCommand.length));
if (await hasCommands(ctx)) {
const commandsUsage = `${resolveEntry(ctx)} <${ctx.translate(resolveBuiltInKey("COMMANDS"))}>`;
messages$1.push(commandsUsage.padStart(ctx.env.leftMargin + commandsUsage.length));
}
} else {
const usageStr = `${resolveEntry(ctx)} ${resolveSubCommand(ctx)} ${[generateOptionsSymbols(ctx), generatePositionalSymbols(ctx)].filter(Boolean).join(" ")}`;
messages$1.push(usageStr.padStart(ctx.env.leftMargin + usageStr.length));
}
return messages$1;
}
async function renderCommandsSection(ctx) {
const messages$1 = [`${ctx.translate(resolveBuiltInKey("COMMANDS"))}:`];
const loadedCommands = await ctx.loadCommands();
const commandMaxLength = Math.max(...loadedCommands.map((cmd) => (cmd.name || "").length));
const commandsStr = await Promise.all(loadedCommands.map((cmd) => {
const key = cmd.name || "";
const desc = cmd.description || "";
const command = `${key.padEnd(commandMaxLength + ctx.env.middleMargin)}${desc} `;
return `${command.padStart(ctx.env.leftMargin + command.length)} `;
}));
messages$1.push(...commandsStr, "", ctx.translate(resolveBuiltInKey("FORMORE")));
messages$1.push(...loadedCommands.map((cmd) => {
const commandHelp = `${ctx.env.name} ${cmd.name} --help`;
return `${commandHelp.padStart(ctx.env.leftMargin + commandHelp.length)}`;
}));
return messages$1;
}
function resolveEntry(ctx) {
return ctx.env.name || ctx.translate(resolveBuiltInKey("COMMAND"));
}
function resolveSubCommand(ctx) {
return ctx.name || ctx.translate(resolveBuiltInKey("SUBCOMMAND"));
}
function resolveDescription(ctx) {
return ctx.translate("description") || ctx.description || "";
}
async function resolveExamples$1(ctx) {
const ret = ctx.translate("examples");
if (ret) return ret;
const command = ctx.env.subCommands?.get(ctx.name || "");
return await resolveExamples(ctx, command?.examples);
}
async function hasCommands(ctx) {
return (await ctx.loadCommands()).length > 1;
}
function hasOptionalArgs(ctx) {
return !!(ctx.args && Object.values(ctx.args).some((arg) => arg.type !== "positional"));
}
function hasPositionalArgs(ctx) {
return !!(ctx.args && Object.values(ctx.args).some((arg) => arg.type === "positional"));
}
function hasAllDefaultOptions(ctx) {
return !!(ctx.args && Object.values(ctx.args).every((arg) => arg.default));
}
function generateOptionsSymbols(ctx) {
return hasOptionalArgs(ctx) ? hasAllDefaultOptions(ctx) ? `[${ctx.translate(resolveBuiltInKey("OPTIONS"))}]` : `<${ctx.translate(resolveBuiltInKey("OPTIONS"))}>` : "";
}
function makeShortLongOptionPair(schema, name$1, toKebab) {
let key = `--${toKebab || schema.toKebab ? kebabnize(name$1) : name$1}`;
if (schema.short) key = `-${schema.short}, ${key}`;
return key;
}
function getOptionalArgsPairs(ctx) {
return Object.entries(ctx.args).reduce((acc, [name$1, schema]) => {
if (schema.type === "positional") return acc;
let key = makeShortLongOptionPair(schema, name$1, ctx.toKebab);
if (schema.type !== "boolean") {
const displayName = ctx.toKebab || schema.toKebab ? kebabnize(name$1) : name$1;
key = schema.default ? `${key} [${displayName}]` : `${key} <${displayName}>`;
}
acc[name$1] = key;
if (schema.type === "boolean" && schema.negatable && !COMMON_ARGS_KEYS.includes(name$1)) {
const displayName = ctx.toKebab || schema.toKebab ? kebabnize(name$1) : name$1;
acc[`no-${name$1}`] = `--no-${displayName}`;
}
return acc;
}, create());
}
const resolveNegatableKey = (key) => key.split("no-")[1];
function resolveNegatableType(key, ctx) {
return ctx.args[key.startsWith("no-") ? resolveNegatableKey(key) : key].type;
}
function generateDefaultDisplayValue(ctx, schema) {
return `${ctx.translate(resolveBuiltInKey("DEFAULT"))}: ${schema.default}`;
}
function resolveDisplayValue(ctx, key) {
if (COMMON_ARGS_KEYS.includes(key)) return "";
const schema = ctx.args[key];
if ((schema.type === "boolean" || schema.type === "number" || schema.type === "string" || schema.type === "custom") && schema.default !== void 0) return `(${generateDefaultDisplayValue(ctx, schema)})`;
if (schema.type === "enum") {
const _default = schema.default !== void 0 ? generateDefaultDisplayValue(ctx, schema) : "";
const choices = `${ctx.translate(resolveBuiltInKey("CHOICES"))}: ${schema.choices.join(" | ")}`;
return `(${_default ? `${_default}, ${choices}` : choices})`;
}
return "";
}
async function generateOptionalArgsUsage(ctx, optionsPairs) {
const optionsMaxLength = Math.max(...Object.entries(optionsPairs).map(([_$1, value]) => value.length));
const optionSchemaMaxLength = ctx.env.usageOptionType ? Math.max(...Object.entries(optionsPairs).map(([key]) => resolveNegatableType(key, ctx).length)) : 0;
return (await Promise.all(Object.entries(optionsPairs).map(([key, value]) => {
let rawDesc = ctx.translate(resolveArgKey(key));
if (!rawDesc && key.startsWith("no-")) {
const name$1 = resolveNegatableKey(key);
const schema = ctx.args[name$1];
const optionKey = makeShortLongOptionPair(schema, name$1, ctx.toKebab);
rawDesc = `${ctx.translate(resolveBuiltInKey("NEGATABLE"))} ${optionKey}`;
}
const optionsSchema = ctx.env.usageOptionType ? `[${resolveNegatableType(key, ctx)}] ` : "";
const valueDesc = key.startsWith("no-") ? "" : resolveDisplayValue(ctx, key);
const desc = `${optionsSchema ? optionsSchema.padEnd(optionSchemaMaxLength + 3) : ""}${rawDesc}`;
const option = `${value.padEnd(optionsMaxLength + ctx.env.middleMargin)}${desc}${valueDesc ? ` ${valueDesc}` : ""}`;
return `${option.padStart(ctx.env.leftMargin + option.length)}`;
}))).join("\n");
}
function getPositionalArgs(ctx) {
return Object.entries(ctx.args).filter(([_$1, schema]) => schema.type === "positional");
}
async function generatePositionalArgsUsage(ctx) {
const positionals = getPositionalArgs(ctx);
const argsMaxLength = Math.max(...positionals.map(([name$1]) => name$1.length));
return (await Promise.all(positionals.map(([name$1]) => {
const desc = ctx.translate(resolveArgKey(name$1)) || ctx.args[name$1].description || "";
const arg = `${name$1.padEnd(argsMaxLength + ctx.env.middleMargin)} ${desc}`;
return `${arg.padStart(ctx.env.leftMargin + arg.length)}`;
}))).join("\n");
}
function generatePositionalSymbols(ctx) {
return hasPositionalArgs(ctx) ? getPositionalArgs(ctx).map(([name$1]) => `<${name$1}>`).join(" ") : "";
}
function renderValidationErrors(_ctx, error) {
const messages$1 = [];
for (const err of error.errors) messages$1.push(err.message);
return Promise.resolve(messages$1.join("\n"));
}
const HYPHEN_CHAR = "-";
const HYPHEN_CODE = HYPHEN_CHAR.codePointAt(0);
const EQUAL_CHAR = "=";
const EQUAL_CODE = EQUAL_CHAR.codePointAt(0);
const TERMINATOR = "--";
const SHORT_OPTION_PREFIX = HYPHEN_CHAR;
const LONG_OPTION_PREFIX = "--";
function parseArgs(args, options = {}) {
const { allowCompatible = false } = options;
const tokens = [];
const remainings = [...args];
let index = -1;
let groupCount = 0;
let hasShortValueSeparator = false;
while (remainings.length > 0) {
const arg = remainings.shift();
if (arg == void 0) break;
const nextArg = remainings[0];
if (groupCount > 0) groupCount--;
else index++;
if (arg === TERMINATOR) {
tokens.push({
kind: "option-terminator",
index
});
const mapped = remainings.map((arg$1) => {
return {
kind: "positional",
index: ++index,
value: arg$1
};
});
tokens.push(...mapped);
break;
}
if (isShortOption(arg)) {
const shortOption = arg.charAt(1);
let value;
let inlineValue;
if (groupCount) {
tokens.push({
kind: "option",
name: shortOption,
rawName: arg,
index,
value,
inlineValue
});
if (groupCount === 1 && hasOptionValue(nextArg)) {
value = remainings.shift();
if (hasShortValueSeparator) {
inlineValue = true;
hasShortValueSeparator = false;
}
tokens.push({
kind: "option",
index,
value,
inlineValue
});
}
} else tokens.push({
kind: "option",
name: shortOption,
rawName: arg,
index,
value,
inlineValue
});
if (value != null) ++index;
continue;
}
if (isShortOptionGroup(arg)) {
const expanded = [];
let shortValue = "";
for (let i$1 = 1; i$1 < arg.length; i$1++) {
const shortableOption = arg.charAt(i$1);
if (hasShortValueSeparator) shortValue += shortableOption;
else if (!allowCompatible && shortableOption.codePointAt(0) === EQUAL_CODE) hasShortValueSeparator = true;
else expanded.push(`${SHORT_OPTION_PREFIX}${shortableOption}`);
}
if (shortValue) expanded.push(shortValue);
remainings.unshift(...expanded);
groupCount = expanded.length;
continue;
}
if (isLongOption(arg)) {
const longOption = arg.slice(2);
tokens.push({
kind: "option",
name: longOption,
rawName: arg,
index,
value: void 0,
inlineValue: void 0
});
continue;
}
if (isLongOptionAndValue(arg)) {
const equalIndex = arg.indexOf(EQUAL_CHAR);
const longOption = arg.slice(2, equalIndex);
const value = arg.slice(equalIndex + 1);
tokens.push({
kind: "option",
name: longOption,
rawName: `${LONG_OPTION_PREFIX}${longOption}`,
index,
value,
inlineValue: true
});
continue;
}
tokens.push({
kind: "positional",
index,
value: arg
});
}
return tokens;
}
function isShortOption(arg) {
return arg.length === 2 && arg.codePointAt(0) === HYPHEN_CODE && arg.codePointAt(1) !== HYPHEN_CODE;
}
function isShortOptionGroup(arg) {
if (arg.length <= 2) return false;
if (arg.codePointAt(0) !== HYPHEN_CODE) return false;
if (arg.codePointAt(1) === HYPHEN_CODE) return false;
return true;
}
function isLongOption(arg) {
return hasLongOptionPrefix(arg) && !arg.includes(EQUAL_CHAR, 3);
}
function isLongOptionAndValue(arg) {
return hasLongOptionPrefix(arg) && arg.includes(EQUAL_CHAR, 3);
}
function hasLongOptionPrefix(arg) {
return arg.length > 2 && ~arg.indexOf(LONG_OPTION_PREFIX);
}
function hasOptionValue(value) {
return !(value == null) && value.codePointAt(0) !== HYPHEN_CODE;
}
const SKIP_POSITIONAL_DEFAULT = -1;
function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKIP_POSITIONAL_DEFAULT, toKebab = false } = {}) {
const skipPositionalIndex = typeof skipPositional === "number" ? Math.max(skipPositional, SKIP_POSITIONAL_DEFAULT) : SKIP_POSITIONAL_DEFAULT;
const rest = [];
const optionTokens = [];
const positionalTokens = [];
let currentLongOption;
let currentShortOption;
const expandableShortOptions = [];
function toShortValue() {
if (expandableShortOptions.length === 0) return void 0;
else {
const value = expandableShortOptions.map((token) => token.name).join("");
expandableShortOptions.length = 0;
return value;
}
}
function applyLongOptionValue(value = void 0) {
if (currentLongOption) {
currentLongOption.value = value;
optionTokens.push({ ...currentLongOption });
currentLongOption = void 0;
}
}
function applyShortOptionValue(value = void 0) {
if (currentShortOption) {
currentShortOption.value = value || toShortValue();
optionTokens.push({ ...currentShortOption });
currentShortOption = void 0;
}
}
const schemas = Object.values(args);
let terminated = false;
for (let i$1 = 0; i$1 < tokens.length; i$1++) {
const token = tokens[i$1];
if (token.kind === "positional") {
if (terminated && token.value) {
rest.push(token.value);
continue;
}
if (currentShortOption) {
if (schemas.find((schema) => schema.short === currentShortOption.name && schema.type === "boolean")) positionalTokens.push({ ...token });
} else if (currentLongOption) {
if (args[currentLongOption.name]?.type === "boolean") positionalTokens.push({ ...token });
} else positionalTokens.push({ ...token });
applyLongOptionValue(token.value);
applyShortOptionValue(token.value);
} else if (token.kind === "option") if (token.rawName) {
if (hasLongOptionPrefix(token.rawName)) {
applyLongOptionValue();
if (token.inlineValue) optionTokens.push({ ...token });
else currentLongOption = { ...token };
applyShortOptionValue();
} else if (isShortOption(token.rawName)) if (currentShortOption) {
if (currentShortOption.index === token.index) if (shortGrouping) {
currentShortOption.value = token.value;
optionTokens.push({ ...currentShortOption });
currentShortOption = { ...token };
} else expandableShortOptions.push({ ...token });
else {
currentShortOption.value = toShortValue();
optionTokens.push({ ...currentShortOption });
currentShortOption = { ...token };
}
applyLongOptionValue();
} else {
currentShortOption = { ...token };
applyLongOptionValue();
}
} else {
if (currentShortOption && currentShortOption.index == token.index && token.inlineValue) {
currentShortOption.value = token.value;
optionTokens.push({ ...currentShortOption });
currentShortOption = void 0;
}
applyLongOptionValue();
}
else {
if (token.kind === "option-terminator") terminated = true;
applyLongOptionValue();
applyShortOptionValue();
}
}
applyLongOptionValue();
applyShortOptionValue();
const values = Object.create(null);
const errors = [];
function checkTokenName(option, schema, token) {
return token.name === (schema.type === "boolean" ? schema.negatable && token.name?.startsWith("no-") ? `no-${option}` : option : option);
}
const positionalItemCount = tokens.filter((token) => token.kind === "positional").length;
function getPositionalSkipIndex() {
return Math.min(skipPositionalIndex, positionalItemCount);
}
let positionalsCount = 0;
for (const [rawArg, schema] of Object.entries(args)) {
const arg = toKebab || schema.toKebab ? kebabnize(rawArg) : rawArg;
if (schema.required) {
if (!optionTokens.find((token) => {
return schema.short && token.name === schema.short || token.rawName && hasLongOptionPrefix(token.rawName) && token.name === arg;
})) {
errors.push(createRequireError(arg, schema));
continue;
}
}
if (schema.type === "positional") {
if (skipPositionalIndex > SKIP_POSITIONAL_DEFAULT) while (positionalsCount <= getPositionalSkipIndex()) positionalsCount++;
const positional = positionalTokens[positionalsCount];
if (positional != null) values[rawArg] = positional.value;
else errors.push(createRequireError(arg, schema));
positionalsCount++;
continue;
}
for (let i$1 = 0; i$1 < optionTokens.length; i$1++) {
const token = optionTokens[i$1];
if (checkTokenName(arg, schema, token) && token.rawName != void 0 && hasLongOptionPrefix(token.rawName) || schema.short === token.name && token.rawName != void 0 && isShortOption(token.rawName)) {
const invalid = validateRequire(token, arg, schema);
if (invalid) {
errors.push(invalid);
continue;
}
if (schema.type === "boolean") token.value = void 0;
const [parsedValue, error] = parse$2(token, arg, schema);
if (error) errors.push(error);
else if (schema.multiple) {
values[rawArg] ||= [];
values[rawArg].push(parsedValue);
} else values[rawArg] = parsedValue;
}
}
if (values[rawArg] == null && schema.default != null) values[rawArg] = schema.default;
}
return {
values,
positionals: positionalTokens.map((token) => token.value),
rest,
error: errors.length > 0 ? new AggregateError(errors) : void 0
};
}
function parse$2(token, option, schema) {
switch (schema.type) {
case "string": return typeof token.value === "string" ? [token.value || schema.default, void 0] : [void 0, createTypeError(option, schema)];
case "boolean": return token.value ? [token.value || schema.default, void 0] : [!(schema.negatable && token.name.startsWith("no-")), void 0];
case "number":
if (!isNumeric(token.value)) return [void 0, createTypeError(option, schema)];
return token.value ? [+token.value, void 0] : [+(schema.default || ""), void 0];
case "enum":
if (schema.choices && !schema.choices.includes(token.value)) return [void 0, new ArgResolveError(`Optional argument '--${option}' ${schema.short ? `or '-${schema.short}' ` : ""}should be chosen from '${schema.type}' [${schema.choices.map((c$1) => JSON.stringify(c$1)).join(", ")}] values`, option, "type", schema)];
return [token.value || schema.default, void 0];
case "custom":
if (typeof schema.parse !== "function") throw new TypeError(`argument '${option}' should have a 'parse' function`);
try {
return [schema.parse(token.value || String(schema.default || "")), void 0];
} catch (error) {
return [void 0, error];
}
default: throw new Error(`Unsupported argument type '${schema.type}' for option '${option}'`);
}
}
function createRequireError(option, schema) {
const message = schema.type === "positional" ? `Positional argument '${option}' is required` : `Optional argument '--${option}' ${schema.short ? `or '-${schema.short}' ` : ""}is required`;
return new ArgResolveError(message, option, "required", schema);
}
var ArgResolveError = class extends Error {
name;
schema;
type;
constructor(message, name$1, type, schema) {
super(message);
this.name = name$1;
this.type = type;
this.schema = schema;
}
};
function validateRequire(token, option, schema) {
if (schema.required && schema.type !== "boolean" && !token.value) return createRequireError(option, schema);
}
function isNumeric(str) {
return str.trim() !== "" && !isNaN(str);
}
function createTypeError(option, schema) {
return new ArgResolveError(`Optional argument '--${option}' ${schema.short ? `or '-${schema.short}' ` : ""}should be '${schema.type}'`, option, "type", schema);
}
async function cli(argv$2, entry, options = {}) {
const cliOptions = resolveCliOptions(options, entry);
const tokens = parseArgs(argv$2);
const subCommand = getSubCommand(tokens);
const { commandName: name$1, command, callMode } = await resolveCommand(subCommand, entry, cliOptions);
if (!command) throw new Error(`Command not found: ${name$1 || ""}`);
const args = resolveArguments(getCommandArgs(command));
const { values, positionals, rest, error } = resolveArgs(args, tokens, {
shortGrouping: true,
toKebab: command.toKebab,
skipPositional: cliOptions.subCommands.size > 0 ? 0 : -1
});
const ctx = await createCommandContext({
args,
values,
positionals,
rest,
argv: argv$2,
tokens,
omitted: !subCommand,
callMode,
command,
cliOptions
});
if (values.version) {
showVersion(ctx);
return;
}
const usageBuffer = [];
const header = await showHeader(ctx);
if (header) usageBuffer.push(header);
if (values.help) {
const usage = await showUsage(ctx);
if (usage) usageBuffer.push(usage);
return usageBuffer.join("\n");
}
if (error) {
await showValidationErrors(ctx, error);
return;
}
await executeCommand(command, ctx, name$1 || "");
}
function getCommandArgs(cmd) {
if (isLazyCommand(cmd)) return cmd.args || create();
else if (typeof cmd === "object") return cmd.args || create();
else return create();
}
function resolveArguments(args) {
return Object.assign(create(), args, COMMON_ARGS);
}
function resolveCliOptions(options, entry) {
const subCommands$1 = new Map(options.subCommands);
if (options.subCommands) {
if (isLazyCommand(entry)) subCommands$1.set(entry.commandName, entry);
else if (typeof entry === "object" && entry.name) subCommands$1.set(entry.name, entry);
}
return Object.assign(create(), COMMAND_OPTIONS_DEFAULT, options, { subCommands: subCommands$1 });
}
function getSubCommand(tokens) {
const firstToken = tokens[0];
return firstToken && firstToken.kind === "positional" && firstToken.index === 0 && firstToken.value ? firstToken.value : "";
}
async function showUsage(ctx) {
if (ctx.env.renderUsage === null) return;
const usage = await (ctx.env.renderUsage || renderUsage)(ctx);
if (usage) {
ctx.log(usage);
return usage;
}
}
function showVersion(ctx) {
ctx.log(ctx.env.version);
}
async function showHeader(ctx) {
if (ctx.env.renderHeader === null) return;
const header = await (ctx.env.renderHeader || renderHeader)(ctx);
if (header) {
ctx.log(header);
ctx.log();
return header;
}
}
async function showValidationErrors(ctx, error) {
if (ctx.env.renderValidationErrors === null) return;
const render = ctx.env.renderValidationErrors || renderValidationErrors;
ctx.log(await render(ctx, error));
}
const CANNOT_RESOLVE_COMMAND = { callMode: "unexpected" };
async function resolveCommand(sub, entry, options) {
const omitted = !sub;
async function doResolveCommand() {
if (typeof entry === "function") if ("commandName" in entry && entry.commandName) return {
commandName: entry.commandName,
command: entry,
callMode: "entry"
};
else return {
command: { run: entry },
callMode: "entry"
};
else if (typeof entry === "object") return {
commandName: resolveEntryName(entry),
command: entry,
callMode: "entry"
};
else return CANNOT_RESOLVE_COMMAND;
}
if (omitted || options.subCommands?.size === 0) return doResolveCommand();
const cmd = options.subCommands?.get(sub);
if (cmd == null) return {
commandName: sub,
callMode: "unexpected"
};
if (isLazyCommand(cmd) && cmd.commandName == null) cmd.commandName = sub;
else if (typeof cmd === "object" && cmd.name == null) cmd.name = sub;
return {
commandName: sub,
command: cmd,
callMode: "subCommand"
};
}
function resolveEntryName(entry) {
return entry.name || ANONYMOUS_COMMAND_NAME;
}
async function executeCommand(cmd, ctx, name$1) {
const resolved = isLazyCommand(cmd) ? await resolveLazyCommand(cmd, name$1, true) : cmd;
if (resolved.run == null) throw new Error(`'run' not found on Command \`${name$1}\``);
await resolved.run(ctx);
}
var name = "@ccusage/codex";
var version = "17.1.2";
var description = "Usage analysis tool for OpenAI Codex sessions";
var require_debug = /* @__PURE__ */ __commonJSMin(((exports, module) => {
let messages = [];
let level = 0;
const debug$3 = (msg, min) => {
if (level >= min) messages.push(msg);
};
debug$3.WARN = 1;
debug$3.INFO = 2;
debug$3.DEBUG = 3;
debug$3.reset = () => {
messages = [];
};
debug$3.setDebugLevel = (v$1) => {
level = v$1;
};
debug$3.warn = (msg) => debug$3(msg, debug$3.WARN);
debug$3.info = (msg) => debug$3(msg, debug$3.INFO);
debug$3.debug = (msg) => debug$3(msg, debug$3.DEBUG);
debug$3.debugMessages = () => messages;
module.exports = debug$3;
}));
var require_ansi_regex = /* @__PURE__ */ __commonJSMin(((exports, module) => {
module.exports = ({ onlyFirst = false } = {}) => {
const pattern = ["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"].join("|");
return new RegExp(pattern, onlyFirst ? void 0 : "g");
};
}));
var require_strip_ansi = /* @__PURE__ */ __commonJSMin(((exports, module) => {
const ansiRegex$3 = require_ansi_regex();
module.exports = (string$1) => typeof string$1 === "string" ? string$1.replace(ansiRegex$3(), "") : string$1;
}));
var require_is_fullwidth_code_point = /* @__PURE__ */ __commonJSMin(((exports, module) => {
const isFullwidthCodePoint$1 = (codePoint) => {
if (Number.isNaN(codePoint)) return false;
if (codePoint >= 4352 && (codePoint <= 4447 || codePoint === 9001 || codePoint === 9002 || 11904 <= codePoint && codePoint <= 12871 && codePoint !== 12351 || 12880 <= codePoint && codePoint <= 19903 || 19968 <= codePoint && codePoint <= 42182 || 43360 <= codePoint && codePoint <= 43388 || 44032 <= codePoint && codePoint <= 55203 || 63744 <= codePoint && codePoint <= 64255 || 65040 <= codePoint && codePoint <= 65049 || 65072 <= codePoint && codePoint <= 65131 || 65281 <= codePoint && codePoint <= 65376 || 65504 <= codePoint && codePoint <= 65510 || 110592 <= codePoint && codePoint <= 110593 || 127488 <= codePoint && codePoint <= 127569 || 131072 <= codePoint && codePoint <= 262141)) return true;
return false;
};
module.exports = isFullwidthCodePoint$1;
module.exports.default = isFullwidthCodePoint$1;
}));
var require_emoji_regex$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
module.exports = function() {
return /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F|\uD83D\uDC68(?:\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68\uD83C\uDFFB|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|[\u2695\u2696\u2708]\uFE0F|\uD83D[\uDC66\uDC67]|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708])\uFE0F|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C[\uDFFB-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)\uD83C\uDFFB|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB\uDFFC])|\uD83D\uDC69(?:\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB-\uDFFD])|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|(?:(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)\uFE0F|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\u200D[\u2640\u2642])|\uD83C\uDFF4\u200D\u2620)\uFE0F|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF4\uD83C\uDDF2|\uD83C\uDDF6\uD83C\uDDE6|[#\*0-9]\uFE0F\u20E3|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83D\uDC69(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270A-\u270D]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC70\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDCAA\uDD74\uDD7A\uDD90\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD36\uDDB5\uDDB6\uDDBB\uDDD2-\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5\uDEEB\uDEEC\uDEF4-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g;
};
}));
var require_string_width = /* @__PURE__ */ __commonJSMin(((exports, module) => {
const stripAnsi$3 = require_strip_ansi();
const isFullwidthCodePoint = require_is_fullwidth_code_point();
const emojiRegex$2 = require_emoji_regex$1();
const stringWidth$4 = (string$1) => {
if (typeof string$1 !== "string" || string$1.length === 0) return 0;
string$1 = stripAnsi$3(string$1);
if (string$1.length === 0) return 0;
string$1 = string$1.replace(emojiRegex$2(), " ");
let width = 0;
for (let i$1 = 0; i$1 < string$1.length; i$1++) {
const code = string$1.codePointAt(i$1);
if (code <= 31 || code >= 127 && code <= 159) continue;
if (code >= 768 && code <= 879) continue;
if (code > 65535) i$1++;
width += isFullwidthCodePoint(code) ? 2 : 1;
}
return width;
};
module.exports = stringWidth$4;
module.exports.default = stringWidth$4;
}));
var require_utils$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
const stringWidth$3 = require_string_width();
function codeRegex(capture) {
return capture ? /\u001b\[((?:\d*;){0,5}\d*)m/g : /\u001b\[(?:\d*;){0,5}\d*m/g;
}
function strlen(str) {
let code = codeRegex();
return ("" + str).replace(code, "").split("\n").reduce(function(memo, s$1) {
return stringWidth$3(s$1) > memo ? stringWidth$3(s$1) : memo;
}, 0);
}
function repeat(str, times) {
return Array(times + 1).join(str);
}
function pad(str, len, pad$1, dir) {
let length = strlen(str);
if (len + 1 >= length) {
let padlen = len - length;
switch (dir) {
case "right":
str = repeat(pad$1, padlen) + str;
break;
case "center": {
let right = Math.ceil(padlen / 2);
let left = padlen - right;
str = repeat(pad$1, left) + str + repeat(pad$1, right);
break;
}
default:
str = str + repeat(pad$1, padlen);
break;
}
}
return str;
}
let codeCache = {};
function addToCodeCache(name$1, on, off) {
on = "\x1B[" + on + "m";
off = "\x1B[" + off + "m";
codeCache[on] = {
set: name$1,
to: true
};
codeCache[off] = {
set: name$1,
to: false
};
codeCache[name$1] = {
on,
off
};
}
addToCodeCache("bold", 1, 22);
addToCodeCache("italics", 3, 23);
addToCodeCache("underline", 4, 24);
addToCodeCache("inverse", 7, 27);
addToCodeCache("strikethrough", 9, 29);
function updateState(state, controlChars) {
let controlCode = controlChars[1] ? parseInt(controlChars[1].split(";")[0]) : 0;
if (controlCode >= 30 && controlCode <= 39 || controlCode >= 90 && controlCode <= 97) {
state.lastForegroundAdded = controlChars[0];
return;
}
if (controlCode >= 40 && controlCode <= 49 || controlCode >= 100 && controlCode <= 107) {
state.lastBackgroundAdded = controlChars[0];
return;
}
if (controlCode === 0) {
for (let i$1 in state)
/* istanbul ignore else */
if (Object.prototype.hasOwnProperty.call(state, i$1)) delete state[i$1];
return;
}
let info$1 = codeCache[controlChars[0]];
if (info$1) state[info$1.set] = info$1.to;
}
function readState(line) {
let code = codeRegex(true);
let controlChars = code.exec(line);
let state = {};
while (controlChars !== null) {
updateState(state, controlChars);
controlChars = code.exec(line);
}
return state;
}
function unwindState(state, ret) {
let lastBackgroundAdded = state.lastBackgroundAdded;
let lastForegroundAdded = state.lastForegroundAdded;
delete state.lastBackgroundAdded;
delete state.lastForegroundAdded;
Object.keys(state).forEach(function(key) {
if (state[key]) ret += codeCache[key].off;
});
if (lastBackgroundAdded && lastBackgroundAdded != "\x1B[49m") ret += "\x1B[49m";
if (lastForegroundAdded && lastForegroundAdded != "\x1B[39m") ret += "\x1B[39m";
return ret;
}
function rewindState(state, ret) {
let lastBackgroundAdded = state.lastBackgroundAdded;
let lastForegroundAdded = state