import { readFile } from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
/** Feature keys advertised by this build. Missing still means unsupported. */
const FEATURES = {
    'cli.health.v1': true,
    'cli.probe.v1': true,
    'code.searchSymbols': true,
    'code.projectContext': true,
    'code.directoryTree': true,
    'code.directoryTree.tokens': true,
    'code.tokens.persistedCounts.v1': true,
    'code.query.budgetEarlyExit.v1': true,
    'code.inlineContext.v1': true,
    'code.citations.v1': true,
    'code.map.changed': true,
    'code.map.budgetEmittedFormat.v1': true,
    'code.blobStructure.v1': true,
    'code.blobStructure.receipt.v1': true,
    'code.blobStructure.v2': true,
    'code.blobStructure.receipt.v2': true,
    'code.blobStructure.stream.v2': true,
    'code.atoms.v1': true,
    'code.atoms.receipt.v1': true,
    'code.atoms.v2': true,
    'code.atoms.receipt.v2': true,
    'code.atoms.stream.v2': true,
    'code.atoms.cursor.v2': true,
    'code.coordinates.gitNative.v1': true,
    'code.coordinateVerification.v1': true,
    'code.entityGraph.v1': true,
    'code.entityGraph.receipt.v1': true,
    'code.entityGraph.v2': true,
    'code.entityGraph.receipt.v2': true,
    'code.entityGraph.stream.v2': true,
    'git.capture.v1': true,
    'git.cochange': true,
    'metrics.fileComplexity': true,
    'code.index.symbolNodeIds': true,
    'code.index.symbolNodeIds.v2': true,
    'code.index.schema.v1': true,
    'code.index.exactSpans.v1': true,
    'code.index.parserProvenance.v2': true,
    'code.index.callExtraction.v2': true,
    'code.index.observedCapabilities': true,
    'code.index.resolutionEvidence.v1': true,
    'code.index.richSignatures': true,
    'store.peekMetadata': true,
    'store.isFresh': true,
    'session.refresh.signal': true,
    'defaults.excludeDirs': true,
    'output.deterministicOrdering.v2': true,
    'output.compactJson.v1': true,
    'output.honestyEnvelope.v1': true,
    'output.narrowing.v1': true,
    'cli.codeIndexStore.v1': true,
    'cli.entityBounds.v1': true,
    'cache.prune.v1': true,
    'code.symbol.bodyHash': true,
    'code.symbol.exactSpanHash.v1': true,
    'code.symbol.verification': true,
    'code.symbol.verification.v2': true,
    'code.typescriptChecker': true,
    'code.doc': true,
    'code.seams': true,
    'git.historyScope': true,
    'code.entityIntelligence': true,
    'code.entity.honesty.evidenceGaps': true,
    'code.entity.lineage.grammarReverify': true,
    'code.entity.lineage.boundOrphans': true,
    'code.entities.envelope.v1': true,
    'code.entity.diff': true,
    'code.entity.diff.semanticExit': true,
    'code.entity.diff.semanticVerdict': true,
    'code.entity.diff.wholeDiffSemanticVerdict': ['whole-file-cst-v4'],
    'code.entity.diff.triviaClassification.v1': true,
    'code.moduleClusters.v1': true,
    'code.flowTraces.v1': true,
    'code.entity.diff.obligations': true,
    'code.entity.diff.obligations.coverage': true,
    'code.entity.diff.textEvidenceGaps': true,
    'code.entity.diff.failOnUnknown': true,
    'evidence.requireComplete.v1': true,
    'code.entity.blobLineage.v1': true,
    'code.entity.blobLineage.v2': true,
    'code.facts': true,
    'code.facts.capabilityGate': true,
    'code.facts.untestedEntrypoints.entityImpact': true,
    'code.tsquery': true,
    'code.tsquery.nodeIdSpanJoin': true,
    'code.ast': true,
    'code.treeSitter.tsJs': ['javascript', 'typescript', 'tsx'],
    'code.entity.impact': true,
    'code.entity.blame': true,
    'code.entity.history': true,
    'code.entity.hotspots': true,
    'code.entity.cochange': true,
    'code.entity.context': true,
    'code.entity.context.closure.v1': true,
    'code.drift.v1': true,
    'code.drift.documents.v1': true,
    'code.parsers.vueTemplate.v1': true,
    'code.anchors.verify.v1': true,
    'code.map.stableLayout.v1': true,
    'code.find.fused.pageRank.v1': true,
    'code.find.fused.symbols.v1': true,
    'code.entities.fuzzy.v1': true,
    'code.entity.anchor.v1': true,
    'mcp.anchor.v1': true,
    'mcp.entityIntelligence': true,
    'code.entity.search.directory': true,
    'code.entity.diff.formats': true,
    'code.formats.parseFailureHonesty': true,
    'code.entity.diff.rangeMode': true,
    'code.entity.diff.treeEndpoints': true,
    'code.entity.diff.crossFileMove': true,
    'code.entity.ref': true,
    'code.entity.walkBack': true,
    'probe.runtime': true,
    'code.entity.session.progress': true,
    'code.entity.session.isolated': true,
    'code.entity.session.freshness': true,
    'code.entity.store.peekMetadata': true,
    'code.entity.store.appendExtend.v1': true,
    'code.entity.store.sharedBlobCache.v1': true,
    'code.status.cli.v1': true,
    'mcp.status': true,
    'mcp.refresh': true,
    'mcp.bounds': true,
    'mcp.errorClasses.v1': true,
    'mcp.pattern.utils': true,
    'mcp.progress.v1': true,
    'mcp.responseFormat.v1': true,
    'mcp.source.v1': true,
    'code.entity.impact.testSelectors': true,
    'code.entity.session.update': true,
    'code.entity.contextMany': true,
    'code.entity.diff.unrelatedTrees': true,
    'probe.documentParsers': true,
    'probe.grammarVersions': true,
    'scan.jsonDiagnostics.v1': true,
    'scan.tokenBudget.structured.v1': true,
    'code.pattern': true,
    'code.pattern.engine': ['ast-grep@0.45.1'],
    'code.facts.rules': true,
    'doc.inspect.formats': ['docx', 'pdf', 'odt'],
    'sheet.inspect.formats': ['xlsx', 'ods'],
    'slide.inspect.formats': ['pptx', 'odp'],
    'table.inspect.formats': ['docx', 'xlsx', 'pptx', 'odt', 'odp'],
};
let cachedVersion;
async function readVersion() {
    if (cachedVersion)
        return cachedVersion;
    const directory = path.dirname(fileURLToPath(import.meta.url));
    for (const rel of ['..', '../..']) {
        try {
            const raw = await readFile(path.resolve(directory, rel, 'package.json'), 'utf8');
            const parsed = JSON.parse(raw);
            if (parsed.version) {
                cachedVersion = parsed.version;
                return parsed.version;
            }
        }
        catch {
            // Try next package.json location.
        }
    }
    cachedVersion = '0.0.0';
    return cachedVersion;
}
export async function health() {
    return {
        available: true,
        version: await readVersion(),
        capabilities: {
            code: true,
            workspace: true,
            documents: true,
            tables: true,
            health: true,
        },
        features: Object.fromEntries(Object.entries(FEATURES).map(([key, value]) => [key, Array.isArray(value) ? [...value] : value])),
    };
}
//# sourceMappingURL=health.js.map