/** * "Symbols available at the cursor" context, from the TypeScript language * service, used both to build training data (pipeline/src/symbol-context.ts) * and at inference time (daemon). Keep the output format stable: Stage C was * trained on it. * * Context, in priority order: * 1. member completions when the cursor follows `expr.` / `expr.partial` (optional) * 2. hover signatures of imported symbols (ones used near the cursor first); * repo-local interfaces/types/classes include their declaration source * Trimmed to a token budget. */ import fs from 'node:fs' import path from 'node:path' import ts from 'typescript' import { parse as parseSfc } from '@vue/compiler-sfc' import type { SymbolLang } from './symbol-lang.ts' export { symbolLang, type SymbolLang } from './symbol-lang.ts' export interface SymbolsRequest { /** Absolute path of the file being edited (it may not exist on disk yet). */ filePath: string lang: SymbolLang /** The file as it is at completion time (prefix + suffix). */ visible: string /** Cursor offset in `visible`. */ cursor: number budget: number countTokens: (s: string) => number /** Include member completions when the cursor follows `expr.` (default true, as in training). */ members?: boolean } export interface SymbolsResult { context: string; items: number; hasMembers: boolean } /**