Yeachan-Heo/oh-my-codex · error · Error

mode must match ^[A-Za-z0-9_-]{1,64}$

Error message

mode must match ^[A-Za-z0-9_-]{1,64}$

What it means

Final pattern check in validateStateModeSegment: after passing the type, emptiness, '..' and separator checks, mode must match ^[A-Za-z0-9_-]{1,64}$ (dots are NOT allowed here, unlike filenames).

Source

Thrown at src/mcp/state-paths.ts:145

}


export function validateStateModeSegment(mode: unknown): string {
  if (typeof mode !== 'string') {
    throw new Error('mode must be a string');
  }
  const normalized = mode.trim();
  if (!normalized) {
    throw new Error('mode must be a non-empty string');
  }
  if (normalized.includes('..')) {
    throw new Error('mode must not contain ".."');
  }
  if (normalized.includes('/') || normalized.includes('\\')) {
    throw new Error('mode must not contain path separators');
  }
  if (!STATE_MODE_SEGMENT_PATTERN.test(normalized)) {
    throw new Error('mode must match ^[A-Za-z0-9_-]{1,64}$');
  }
  return normalized;
}

export function getStateFilename(mode: string): string {
  return `${validateStateModeSegment(mode)}${STATE_FILE_SUFFIX}`;
}

export function validateStateFileName(fileName: unknown): string {
  if (typeof fileName !== 'string') {
    throw new Error('fileName must be a string');
  }
  const normalized = fileName.trim();
  if (!normalized) {
    throw new Error('fileName must be a non-empty string');
  }
  if (normalized.includes('..')) {
    throw new Error('fileName must not contain ".."');

View on GitHub (pinned to 3ad79a8a6f)

Solutions

  1. Use only letters, digits, underscore, hyphen; <=64 chars
  2. Replace dots with hyphens: mode.replace(/\./g, "-")
  3. Shorten/hash overly long mode names

Example fix

// before
getStateFilename("v1.2.beta");
// after
getStateFilename("v1-2-beta");
Defensive patterns

Strategy: validation

Validate before calling

const MODE = /^[A-Za-z0-9_-]{1,64}$/;
if (!MODE.test(mode)) mode = mode.replace(/[^A-Za-z0-9_-]/g, '-').slice(0, 64);

Type guard

function isValidModeSegment(v: string): boolean { return /^[A-Za-z0-9_-]{1,64}$/.test(v); }

Prevention

When it happens

Trigger: mode: "night.mode" (dot rejected), mode longer than 64 chars, or mode with spaces/unicode.

Common situations: Reusing a filename-style slug that contains dots; long generated mode names; assuming filename rules apply to mode segments.

Related errors


AI-assisted analysis of Yeachan-Heo/oh-my-codex@3ad79a8a6f (2026-08-27). Data as JSON: /api/errors/6126a899b7c9cb03. Report an issue: GitHub.