/**
 * `olam kg classify <question>` — invoke the 4-layer classifier via kg-service.
 *
 * Thin HTTP wrapper around POST localhost:9997/classify. Optional --workspace
 * scopes the probe gate (L2) to a specific graph; --json prints the raw
 * response for scripting. Default output is operator-friendly text.
 */
import pc from 'picocolors';
import { classify, KgServiceUnreachableError } from '@olam/core/src/kg/kg-service-client.js';
import { printError, printInfo } from '../output.js';
export function registerKgClassifyCommand(kg) {
    kg.command('classify <question>')
        .description('Route a question to kg | grep | both via the 4-layer classifier (kg-service required)')
        .option('--workspace <name>', 'Scope the L2 probe gate to a specific workspace graph')
        .option('--json', 'Emit raw JSON instead of the formatted summary')
        .action(async (question, opts) => {
        try {
            const result = await classify({ q: question, workspace: opts.workspace });
            if (opts.json) {
                process.stdout.write(JSON.stringify(result, null, 2) + '\n');
                return;
            }
            // Operator-friendly summary
            const routeStr = result.route === 'kg'
                ? pc.cyan('kg')
                : result.route === 'grep'
                    ? pc.magenta('grep')
                    : pc.yellow('both');
            printInfo('route', `${routeStr}  (layer ${result.layer}, took ${result.took_ms}ms)`);
            printInfo('confidence', String(result.confidence));
            printInfo('reason', result.reason);
            if (result.rule_fired)
                printInfo('rule fired', result.rule_fired);
            if (result.top_match)
                printInfo('top match', `${result.top_match} (sim=${result.top_sim ?? '?'})`);
            if (result.candidate_symbols.length > 0) {
                printInfo('symbols', result.candidate_symbols.join(', '));
            }
        }
        catch (err) {
            if (err instanceof KgServiceUnreachableError) {
                printError(err.message);
                process.exitCode = 1;
                return;
            }
            printError(`classify failed: ${err instanceof Error ? err.message : String(err)}`);
            process.exitCode = 1;
        }
    });
}
//# sourceMappingURL=kg-classify.js.map