Skip to content

Persistent Context Across Sessions for Every Agent – Captures everything your agent does during sessions, compresses it with AI, and injects relevant context back into future sessions. Works with Claude Code, OpenClaw, Codex, Gemini, Hermes, Copilot, OpenCode + More

1.6 KB
Raw Blame
export const DEFAULT_PLATFORM_SOURCE = 'claude';
/** Grok Build runs the Claude Code plugin's hooks; its sessions are stored under this source (#6419). */
export const GROK_BUILD_PLATFORM_SOURCE = 'grok-build';

function sanitizeRawSource(value: string): string {
  return value.trim().toLowerCase().replace(/\s+/g, '-');
}

export function normalizePlatformSource(value?: string | null): string {
  if (!value) return DEFAULT_PLATFORM_SOURCE;

  const source = sanitizeRawSource(value);
  if (!source) return DEFAULT_PLATFORM_SOURCE;

  if (source === 'transcript') return 'codex';
  if (source.includes('codex')) return 'codex';
  if (source.includes('cursor')) return 'cursor';
  if (source.includes('claude')) return 'claude';
  if (source.includes('kimi')) return 'kimi';
  if (source === 'pi-mono') return 'pi';
  // Exact tokens only: a substring match on "agy" would catch unrelated names.
  if (source === 'agy' || source === 'antigravity' || source.startsWith('antigravity-')) return 'antigravity-cli';

  return source;
}

export function normalizePlatformSourceOrNull(value?: string | null): string | null {
  if (typeof value !== 'string') return null;
  return normalizePlatformSource(value);
}

export function sortPlatformSources(sources: string[]): string[] {
  const priority = ['claude', 'codex', 'antigravity-cli', 'cursor', 'kimi'];

  return [...sources].sort((a, b) => {
    const aPriority = priority.indexOf(a);
    const bPriority = priority.indexOf(b);

    if (aPriority !== -1 || bPriority !== -1) {
      if (aPriority === -1) return 1;
      if (bPriority === -1) return -1;
      return aPriority - bPriority;
    }

    return a.localeCompare(b);
  });
}