"use strict";
/**
 * Interactive REPL support — extracted from cli.ts so it can be unit tested
 * without spawning a process. The actual `doRepl()` function (which uses
 * readline and spawns child processes) still lives in cli.ts; this module
 * holds the pure pieces: command registry + tab-completion logic.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.REPL_COMMAND_NAMES = exports.REPL_COMMANDS = void 0;
exports.replCompleter = replCompleter;
exports.stripSlash = stripSlash;
exports.isKnownCommand = isKnownCommand;
exports.REPL_COMMANDS = [
    ['start', 'Start daemon + MCP (re-run safe)'],
    ['stop', 'Stop daemon'],
    ['setup', 'One-time project setup (idempotent)'],
    ['doctor', 'Health check — diagnose what\'s missing'],
    ['scan', 'Scan codebase + build layers'],
    ['analyze', 'AI prompts from scan data'],
    ['status', 'What Cell knows about you'],
    ['session', 'Last touched file + patterns'],
    ['decisions', 'Recent decisions with verdict'],
    ['team', 'Team collaboration (git-based)'],
    ['community', 'Community patterns + benchmarks'],
    ['watch', 'Live file watcher'],
    ['blindspots', 'Scan for blind spots (15+ types)'],
    ['branches', 'List known branches with context'],
    ['context', 'Inject @cell context block'],
    ['mcp-config', 'Auto-register MCP in Cursor/Antigravity/Codex/OpenCode'],
    ['replay', 'Replay session timeline'],
    ['continue', 'Continue last session'],
    ['bridge', 'WebSocket bridge to IDEs'],
    ['watch-editor', 'Monitor active editor'],
    ['switch-back', 'Restore branch context'],
    ['lessons', 'Engineering lessons from failures'],
    ['evolution', 'Project evolution map + skill progression'],
    ['focus', 'Focus report — active/stalled/abandoned projects'],
    ['why', 'Search decisions by topic'],
    ['help', 'Show this help (in REPL)'],
    ['version', 'Show Cell version'],
    ['exit', 'Exit REPL'],
];
exports.REPL_COMMAND_NAMES = exports.REPL_COMMANDS.map(([n]) => n);
/**
 * Tab-completion for the REPL. When the input starts with `/`, returns the
 * matching commands. Otherwise returns no completions (the user is typing
 * a command name without the prefix).
 *
 * @returns Tuple of [matches, originalString] per the Node readline API.
 */
function replCompleter(line) {
    if (line.startsWith('/')) {
        const query = line.slice(1);
        if (!query) {
            return [exports.REPL_COMMAND_NAMES, line];
        }
        const hits = exports.REPL_COMMAND_NAMES.filter((c) => c.startsWith(query));
        return [hits.length ? hits : exports.REPL_COMMAND_NAMES, line];
    }
    return [[], line];
}
/**
 * Strip a leading `/` from a command line (so users can type either
 * `/scan` or `scan`).
 */
function stripSlash(line) {
    return line.replace(/^\//, '');
}
/**
 * Return true if the given first token matches a known REPL command.
 * Used to validate user input and surface typos with a helpful hint.
 */
function isKnownCommand(firstToken) {
    return exports.REPL_COMMAND_NAMES.includes(firstToken);
}
//# sourceMappingURL=cli-repl.js.map