dsh-code-index 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/buildIndex.ts","../src/extract.ts","../src/scan.ts","../src/store.ts","../src/types.ts","../src/search.ts","../src/repomap.ts","../src/tools.ts","../src/config.ts","../src/index.ts"],"sourcesContent":["/** Build a RepoIndex for a workspace: scan -> extract -> persist. */\n\nimport { readFile, stat } from 'node:fs/promises'\nimport path from 'node:path'\nimport { extractAll, languageForFile } from './extract.js'\nimport { scanRepo, DEFAULT_EXCLUDED_DIRS } from './scan.js'\nimport {\n cacheKeyForRoot,\n defaultCachePath,\n legacyCachePath,\n loadIndex,\n saveIndex,\n} from './store.js'\nimport type { IndexOptions, IndexedFile, RepoIndex } from './types.js'\n\n/**\n * Full build: scan + extract every supported file. Existing per-file\n * extraction is reused when `previous` holds an identical mtime for the\n * same rel path (incremental refresh), so touched files alone re-parse.\n */\nexport async function buildIndex(\n root: string,\n options: IndexOptions = {},\n previous: RepoIndex | null = null,\n): Promise<RepoIndex> {\n const scanned = await scanRepo(root, options)\n\n // Index stale/current state from the previous run by rel path.\n const prevByPath = new Map((previous?.files ?? []).map((f) => [f.path, f]))\n const prevMtime = new Map((previous?.files ?? []).map((f) => [f.path, f.mtimeMs]))\n\n const files: IndexedFile[] = []\n const BATCH = 8\n for (let i = 0; i < scanned.length; i += BATCH) {\n const batch = scanned.slice(i, i + BATCH)\n const rows = await Promise.all(\n batch.map(async (f) => {\n const lang = languageForFile(f.abs)\n if (!lang) return null\n if (prevMtime.get(f.rel) === f.mtimeMs) {\n const cached = prevByPath.get(f.rel)!\n return {\n ...cached,\n mtimeMs: f.mtimeMs,\n symbols: cached.symbols.map((symbol) => ({ ...symbol, file: f.rel })),\n }\n }\n let code: string\n try {\n code = await readFile(f.abs, 'utf8')\n } catch {\n return null\n }\n const { symbols, imports } = await extractAll(code, lang)\n // Backfill the repo-relative path: the extractor is file-agnostic and\n // leaves SymbolInfo.file empty, but search/render depend on it.\n return {\n path: f.rel,\n lang,\n mtimeMs: f.mtimeMs,\n symbols: symbols.map((s) => ({ ...s, file: f.rel })),\n imports,\n } satisfies IndexedFile\n }),\n )\n for (const f of rows) {\n if (f) files.push(f)\n }\n }\n\n return {\n root,\n generatedAt: Date.now(),\n files,\n excludedDirs: [...DEFAULT_EXCLUDED_DIRS, ...(options.excludeDirs ?? [])],\n }\n}\n\n/** Convenience wrapper: evolve an on-disk cache if `root` exists. */\nexport async function buildIndexWithCache(\n root: string,\n options: IndexOptions = {},\n cacheDir?: string,\n): Promise<RepoIndex> {\n const cachePath = defaultCachePath(root, cacheDir)\n let prev = await loadIndex(cachePath)\n let loadedLegacy = false\n if (!prev) {\n const oldPath = legacyCachePath(root, cacheDir)\n if (oldPath !== cachePath) {\n prev = await loadIndex(oldPath)\n loadedLegacy = prev !== null\n }\n }\n const reusable = prev && cacheKeyForRoot(prev.root) === cacheKeyForRoot(root) ? prev : null\n const fresh = await buildIndex(root, options, reusable)\n if (prev && indexesEqual(prev, fresh)) {\n if (loadedLegacy) await saveIndex(cachePath, fresh)\n return loadedLegacy ? fresh : prev\n }\n await saveIndex(cachePath, fresh)\n return fresh\n}\n\nfunction indexesEqual(left: RepoIndex, right: RepoIndex): boolean {\n if (cacheKeyForRoot(left.root) !== cacheKeyForRoot(right.root)) return false\n if (left.files.length !== right.files.length) return false\n if (left.excludedDirs.length !== right.excludedDirs.length) return false\n if (left.excludedDirs.some((value, index) => value !== right.excludedDirs[index])) return false\n\n return left.files.every((file, fileIndex) => {\n const other = right.files[fileIndex]\n if (!other || file.path !== other.path || file.lang !== other.lang || file.mtimeMs !== other.mtimeMs) {\n return false\n }\n if (file.symbols.length !== other.symbols.length) return false\n return file.symbols.every((symbol, symbolIndex) => {\n const candidate = other.symbols[symbolIndex]\n return candidate !== undefined\n && symbol.name === candidate.name\n && symbol.kind === candidate.kind\n && symbol.file === candidate.file\n && symbol.line === candidate.line\n && symbol.endLine === candidate.endLine\n && symbol.exported === candidate.exported\n && symbol.signature === candidate.signature\n })\n })\n}\n\n/**\n * Locate the git repo root for a path by walking up to the nearest `.git`\n * directory. Bounded walk (max `maxLevels` levels); returns `null` when no\n * repo marker is found — callers must NOT index an untagged directory\n * (the fs root is the classic footgun: indexing `C:\\` by accident).\n */\nexport async function findRepoRoot(startDir: string, maxLevels = 12): Promise<string | null> {\n let dir = path.resolve(startDir)\n for (let level = 0; level < maxLevels; level++) {\n try {\n // stat() accepts BOTH a `.git` directory (normal repos) and a `.git`\n // file (worktrees / submodules) — readFile only handled the file form.\n await stat(path.join(dir, '.git'))\n return dir\n } catch {\n // not a repo here — keep walking\n }\n const parent = path.dirname(dir)\n if (parent === dir) return null\n dir = parent\n }\n return null\n}\n","/**\n * tree-sitter symbol extraction.\n *\n * Parses a source text with a per-language grammar (web-tree-sitter WASM,\n * static grammars from tree-sitter-wasms) and returns flat SymbolInfo rows.\n *\n * NOTE on the dependency pin: web-tree-sitter must stay at ^0.20.x — newer\n * releases expect dylinked grammar wasm, while tree-sitter-wasms ships\n * static builds. Verified working pair: web-tree-sitter@0.20.8 + tree-sitter-wasms@0.1.13.\n */\n\nimport { readFile } from 'node:fs/promises'\nimport { createRequire } from 'node:module'\nimport path from 'node:path'\nimport { type Node, Language, Parser, Query } from 'web-tree-sitter'\nimport type { SymbolInfo, SymbolKind } from './types.js'\n\nconst require = createRequire(import.meta.url)\n// web-tree-sitter ≥0.25 is ESM with named exports; 0.20.x was CJS\n// `export = Parser`. tsup externalizes the dep, so the import shape must\n// match the published ESM entry.\n\nexport type LanguageId =\n | 'typescript'\n | 'javascript'\n | 'python'\n | 'go'\n | 'rust'\n | 'java'\n | 'cpp'\n | 'c'\n\nconst WASM_DIR = path.dirname(require.resolve('tree-sitter-wasms/out/tree-sitter-typescript.wasm'))\n\nconst GRAMMAR_NAMES: Record<LanguageId, string> = {\n typescript: 'tree-sitter-typescript',\n javascript: 'tree-sitter-javascript',\n python: 'tree-sitter-python',\n go: 'tree-sitter-go',\n rust: 'tree-sitter-rust',\n java: 'tree-sitter-java',\n cpp: 'tree-sitter-cpp',\n c: 'tree-sitter-c',\n}\n\nconst EXT_TO_LANG: Record<string, LanguageId> = {\n '.ts': 'typescript',\n '.tsx': 'typescript',\n '.mts': 'typescript',\n '.cts': 'typescript',\n '.js': 'javascript',\n '.jsx': 'javascript',\n '.mjs': 'javascript',\n '.cjs': 'javascript',\n '.py': 'python',\n '.pyi': 'python',\n '.go': 'go',\n '.rs': 'rust',\n '.java': 'java',\n '.cpp': 'cpp',\n '.cc': 'cpp',\n '.cxx': 'cpp',\n '.c++': 'cpp',\n '.hpp': 'cpp',\n '.hxx': 'cpp',\n '.hh': 'cpp',\n '.h': 'cpp',\n '.ipp': 'cpp',\n '.tpp': 'cpp',\n '.inl': 'cpp',\n '.c': 'c',\n}\n\nexport function languageForFile(filePath: string): LanguageId | null {\n const ext = path.extname(filePath).toLowerCase()\n return EXT_TO_LANG[ext] ?? null\n}\n\n/** Kind of a capture per query. */\ntype CaptureDef = { kind: SymbolKind; exported?: boolean }\n\n// Query definitions per language. Captures bind to the DECLARATION node\n// (capture OUTSIDE the pattern: `(function_declaration) @function` — the\n// 0.20 query parser rejects a capture sitting directly after the node type\n// inside the parens). Names/signatures/export come from node fields.\nconst QUERIES: Record<LanguageId, string> = {\n typescript: `\n (function_declaration) @function\n (generator_function_declaration) @function\n (method_definition) @method\n (class_declaration) @class\n (interface_declaration) @interface\n (type_alias_declaration) @type\n (enum_declaration) @enum\n (variable_declarator) @variable\n (public_field_definition) @field\n (abstract_class_declaration) @class\n `,\n // JS shares the same query surface; type-related patterns simply never match.\n javascript: `\n (function_declaration) @function\n (generator_function_declaration) @function\n (method_definition) @method\n (class_declaration) @class\n (variable_declarator) @variable\n `,\n python: `\n (function_definition) @function\n (class_definition) @class\n `,\n go: `\n (function_declaration) @function\n (method_declaration) @method\n (type_spec) @type\n `,\n rust: `\n (function_item) @function\n (function_signature_item) @method\n (struct_item) @class\n (enum_item) @enum\n (trait_item) @interface\n `,\n java: `\n (class_declaration) @class\n (interface_declaration) @interface\n (enum_declaration) @enum\n (method_declaration) @method\n (constructor_declaration) @method\n `,\n // C++ grammar (superset of C — also serves .h headers). function names\n // live inside the declarator chain, so patterns stay broad and names,\n // kinds and signatures are resolved in code (cppNameOf / kindFor /\n // signatureFor). Top-level `declaration` covers prototypes, constructors\n // and globals; field_declaration covers class-body members.\n cpp: `\n (function_definition) @function\n (class_specifier body: (_)) @class\n (struct_specifier body: (_)) @class\n (enum_specifier body: (_)) @enum\n (type_definition) @type\n (alias_declaration) @type\n (namespace_definition) @module\n (field_declaration) @field\n (declaration) @variable\n `,\n // Plain C: same core nodes minus C++-only namespace/alias forms.\n c: `\n (function_definition) @function\n (struct_specifier body: (_)) @class\n (enum_specifier body: (_)) @enum\n (type_definition) @type\n (field_declaration) @field\n (declaration) @variable\n `,\n}\n\nconst CAPTURE_KINDS: Record<string, CaptureDef> = {\n function: { kind: 'function' },\n method: { kind: 'method' },\n class: { kind: 'class' },\n interface: { kind: 'interface' },\n type: { kind: 'type' },\n enum: { kind: 'enum' },\n variable: { kind: 'variable' },\n field: { kind: 'field' },\n module: { kind: 'module' },\n}\n\n// Import statements per language. Whole statements are captured; the module\n// specifier is read from node fields in code (string quoting, dotted vs\n// relative vs URL-style syntax differ per grammar). CommonJS require() is out\n// of scope — the ES import surface covers the modern plugin ecosystem.\nconst IMPORT_QUERIES: Record<LanguageId, string> = {\n typescript: `\n (import_statement) @import\n (export_statement) @reexport\n `,\n javascript: `\n (import_statement) @import\n (export_statement) @reexport\n `,\n python: `\n (import_from_statement) @import\n (import_statement) @import\n `,\n go: `\n (import_spec) @import\n `,\n rust: `\n (use_declaration) @use\n `,\n java: `\n (import_declaration) @import\n `,\n // C/C++: #include \"local.hpp\" — quoted form resolves in-repo; <system>\n // captures too but yields null and is dropped by the extractor.\n cpp: `\n (preproc_include) @import\n `,\n c: `\n (preproc_include) @import\n `,\n}\n\nlet parserPromise: Promise<Parser> | null = null\n\nasync function getParser(): Promise<Parser> {\n if (!parserPromise) {\n parserPromise = (async () => {\n const wasm = path.join(path.dirname(require.resolve('web-tree-sitter')), 'tree-sitter.wasm')\n await Parser.init({ locateFile: () => wasm })\n const p = new Parser()\n return p\n })()\n }\n return parserPromise\n}\n\nconst languageCache = new Map<LanguageId, Promise<Language>>()\n\nfunction getLanguage(id: LanguageId): Promise<Language> {\n let entry = languageCache.get(id)\n if (!entry) {\n entry = getParser().then(async () => {\n const grammarPath = path.join(WASM_DIR, `${GRAMMAR_NAMES[id]}.wasm`)\n const bytes = await readFile(grammarPath)\n const lang = await Language.load(bytes)\n // Precompile queries per language to catch authoring errors early.\n // (0.25 deprecates lang.query(); use the Query constructor.)\n new Query(lang, QUERIES[id]).delete()\n new Query(lang, IMPORT_QUERIES[id]).delete()\n return lang\n })\n languageCache.set(id, entry)\n }\n return entry\n}\n\n/**\n * Extract symbols and raw import specifiers from source text of the given\n * language, from a single parse. Returns rows ordered by file line. Never\n * throws for parse errors — a failed parse yields empty lists (the caller\n * logs and continues).\n */\nexport interface ExtractedFile {\n symbols: SymbolInfo[]\n /** Raw module specifiers, e.g. './util', 'node:fs', './utils' (py). */\n imports: string[]\n}\n\nexport async function extractAll(code: string, id: LanguageId): Promise<ExtractedFile> {\n const lang = await getLanguage(id)\n const parser = await getParser()\n parser.setLanguage(lang)\n const tree = parser.parse(code)\n if (!tree) throw new Error(`tree-sitter parse returned null for a ${id} source`)\n try {\n const symbols: SymbolInfo[] = []\n const symbolQuery = new Query(lang, QUERIES[id])\n try {\n const captures = symbolQuery.captures(tree.rootNode)\n for (const cap of captures) {\n const def = CAPTURE_KINDS[cap.name]\n if (!def) continue\n const node = cap.node\n // tree-sitter queries match at any depth; without this check the\n // variable_declarator pattern would also capture function-body\n // locals — pure index noise.\n if (def.kind === 'variable' && !isModuleLevelVariable(id, node)) continue\n const name = nameOf(id, node)\n if (!name) continue\n symbols.push({\n name,\n kind: kindFor(id, node, def.kind),\n file: '', // set by the caller (extractor is file-agnostic)\n line: node.startPosition.row + 1,\n endLine: node.endPosition.row + 1,\n exported: isExported(id, node),\n signature: signatureFor(id, node),\n })\n }\n } finally {\n symbolQuery.delete()\n }\n\n const imports: string[] = []\n const importQuery = new Query(lang, IMPORT_QUERIES[id])\n try {\n for (const cap of importQuery.captures(tree.rootNode)) {\n const spec = specifierOf(id, cap.node)\n if (spec) imports.push(spec)\n }\n } finally {\n importQuery.delete()\n }\n\n symbols.sort((a, b) => a.line - b.line)\n const seen = new Set<string>()\n const deduped = symbols.filter((s) => {\n const key = `${s.kind}|${s.name}|${s.line}`\n if (seen.has(key)) return false\n seen.add(key)\n return true\n })\n return { symbols: deduped, imports }\n } finally {\n tree.delete()\n }\n}\n\n/** Symbols only — see extractAll for the combined parse. */\nexport async function extractSymbols(code: string, id: LanguageId): Promise<SymbolInfo[]> {\n return (await extractAll(code, id)).symbols\n}\n\n/** The declared name of a declaration node — language-aware dispatch. */\nfunction nameOf(id: LanguageId, node: Node): string {\n if (id === 'cpp' || id === 'c') return cppNameOf(node)\n const field = node.childForFieldName?.('name')\n if (field) return field.text.trim()\n // e.g. an anonymous default export — skip those.\n return ''\n}\n\n/**\n * C/C++ declaration names hide in the declarator chain:\n * - function_definition → declarator:function_declarator → identifier |\n * qualified_identifier (A::b) | field_identifier (in-class method)\n * - class/struct/enum specifiers and alias_declaration carry `name`\n * - type_definition → declarator:type_identifier\n * Returns '' for anonymous declarations (skipped upstream).\n */\nfunction cppNameOf(node: Node): string {\n const nameField = node.childForFieldName?.('name')\n if (nameField) return nameField.text.trim()\n if (node.type === 'type_definition') {\n return node.childForFieldName?.('declarator')?.text.trim() ?? ''\n }\n let declarator = node.childForFieldName?.('declarator')\n if (declarator?.type === 'init_declarator') {\n declarator = declarator.childForFieldName?.('declarator')\n }\n if (declarator) {\n let current: Node | null = declarator\n while (current) {\n if (\n current.type === 'function_declarator' ||\n current.type === 'pointer_declarator' ||\n current.type === 'array_declarator' ||\n current.type === 'reference_declarator' ||\n current.type === 'parenthesized_declarator' ||\n current.type === 'init_declarator'\n ) {\n current = current.childForFieldName?.('declarator') ?? current.namedChildren[0] ?? null\n continue\n }\n if (current.type === 'qualified_identifier') {\n // app::main_entry — the bare name is the last segment.\n return current.childForFieldName?.('name')?.text.trim() ?? current.text.trim()\n }\n if (\n current.type === 'identifier' ||\n current.type === 'field_identifier' ||\n current.type === 'type_identifier'\n ) {\n return current.text.trim()\n }\n break\n }\n }\n return ''\n}\n\n/** Read the raw module specifier out of a captured import statement. */\nfunction specifierOf(id: LanguageId, node: Node): string | null {\n switch (node.type) {\n case 'import_statement':\n // ts/js: `import … from './x'` (source); python: `import a.b` (name)\n if (id === 'python') return dottedToPath(node.childForFieldName('name')?.text)\n return stripQuotes(node.childForFieldName('source')?.text)\n case 'export_statement':\n // ts/js re-export: `export … from './x'`; plain exports have no source\n return stripQuotes(node.childForFieldName('source')?.text)\n case 'import_from_statement': {\n // python: `from .utils import x` / `from mypkg.core import Thing`\n const raw = node.childForFieldName('module_name')?.text\n if (raw == null) return null\n return raw.startsWith('.') ? pythonRelative(raw) : dottedToPath(raw)\n }\n case 'import_spec': // go: `import \"example.com/foo/util\"`\n return stripQuotes(node.childForFieldName('path')?.text)\n case 'use_declaration': // rust: `use crate::a::b::{c, d}`\n return rustUsePath(node.childForFieldName('argument')?.text)\n case 'import_declaration': // java: `import com.example.Thing;`\n return dottedToPath(node.namedChildren[0]?.text)\n case 'preproc_include':\n // path field: string_literal for \"x.hpp\" (in-repo, resolvable) or\n // system_lib_string for <cstdio> (stripQuotes yields null → dropped).\n return stripQuotes(node.childForFieldName('path')?.text)\n default:\n return null\n }\n}\n\n/**\n * Rust use paths: 'crate::a::b' is root-relative, 'super::x' is parent-module\n * ('../x'), 'self::x' is current ('./x'); everything else (std, external\n * crates) stays root-relative and simply won't resolve in-repo. Use-lists\n * ('a::b::{c,d}') contribute their base path.\n */\nfunction rustUsePath(text: string | undefined | null): string | null {\n if (!text) return null\n const base = text.split('{')[0].trim()\n if (!base) return null\n const parts = base.split('::').filter(Boolean)\n if (parts[0] === 'crate') parts.shift()\n return parts.map((p) => (p === 'super' ? '..' : p === 'self' ? '.' : p)).join('/')\n}\n\nfunction stripQuotes(text: string | undefined | null): string | null {\n if (text == null || text.length < 2) return null\n const first = text[0]\n const last = text[text.length - 1]\n if ((first === \"'\" && last === \"'\") || (first === '\"' && last === '\"')) {\n return text.slice(1, -1)\n }\n return null\n}\n\n/** 'os.path' → 'os/path' — dotted module path to repo-relative-ish path. */\nfunction dottedToPath(text: string | undefined | null): string | null {\n if (!text) return null\n return text.trim().replace(/\\./g, '/')\n}\n\n/** '.utils' → './utils', '..pkg.mod' → '../pkg/mod' — python relative import. */\nfunction pythonRelative(raw: string): string {\n const dots = raw.match(/^\\.+/)?.[0].length ?? 0\n const rest = raw.slice(dots).replace(/\\./g, '/')\n const prefix = dots === 1 ? './' : '../'.repeat(dots - 1)\n return prefix + rest\n}\n\n/** Best-effort declaration signature: `name` + parameter list, if any. */\nfunction signatureFor(id: LanguageId, node: Node): string {\n const sig = rawSignature(id, node)\n return sig.length > 80 ? `${sig.slice(0, 77)}...` : sig\n}\n\nfunction rawSignature(id: LanguageId, node: Node): string {\n const name = nameOf(id, node)\n // Field first (go method_declaration has both a receiver and a parameters\n // parameter_list — the field picks the right one), type fallback otherwise.\n const params =\n node.childForFieldName?.('parameters') ??\n node.namedChildren.find(\n (c) =>\n c?.type === 'formal_parameters' ||\n c?.type === 'method_parameters' ||\n c?.type === 'parameters' ||\n c?.type === 'parameter_list',\n )\n if (params) {\n return `${name}${collapseSpace(params.text)}`\n }\n if (id === 'cpp' || id === 'c') {\n // C/C++: the parameter list hides inside the declarator chain.\n let current = node.childForFieldName?.('declarator')\n while (current) {\n if (current.type === 'function_declarator') {\n const list = current.childForFieldName?.('parameters')\n return list ? `${name}${collapseSpace(list.text)}` : name\n }\n current = current.childForFieldName?.('declarator') ?? current.namedChildren[0] ?? null\n if (current && !current.type.includes('declarator') && current.type !== 'identifier' && current.type !== 'qualified_identifier' && current.type !== 'field_identifier') break\n }\n }\n const first = node.namedChildren[0]\n return first ? collapseSpace(first.text) : name\n}\n\n/**\n * Signatures must stay one line: repo-map rows are budgeted per line, and a\n * multi-line parameter list would both wrap the format and burn chars.\n */\nfunction collapseSpace(text: string): string {\n return text\n .replace(/\\s+/g, ' ')\n .replace(/\\( /g, '(')\n .replace(/ \\)/g, ')')\n .replace(/ ,/g, ',')\n .replace(/,\\)/g, ')')\n .trim()\n}\n\n/**\n * A variable is indexable only at module level: its declaration must sit\n * directly inside the program (or the export_statement wrapping it). Anything\n * deeper — function bodies, blocks, for-of heads — is a local with no\n * navigation value.\n */\nfunction isModuleLevelVariable(id: LanguageId, node: Node): boolean {\n if (id === 'cpp' || id === 'c') {\n // A (field_)declaration is indexable at namespace/file scope or in a\n // class body — anything inside a function body is a local.\n for (let parent = node.parent; parent; parent = parent.parent) {\n if (parent.type === 'function_definition' || parent.type === 'compound_statement') return false\n if (parent.type === 'translation_unit' || parent.type === 'declaration_list' || parent.type === 'field_declaration_list') return true\n }\n return false\n }\n const declaration = node.parent // variable_declaration | lexical_declaration\n const container = declaration?.parent // program | export_statement | …\n return container?.type === 'program' || container?.type === 'export_statement'\n}\n\n/**\n * A symbol is exported when walking up from it reaches an export_statement\n * before any function or class body — only module-level declarations count.\n * A method inside `export class` must NOT inherit the class's export, and a\n * function nested inside an exported function is not exported either.\n */\nfunction isExported(id: LanguageId, node: Node): boolean {\n if (id === 'python') {\n // Python has no export syntax: a def/class directly under the module is\n // importable, anything nested (methods, inner functions) is not a\n // module-level symbol.\n return node.parent?.type === 'module'\n }\n if (id === 'go') {\n // Go exports by capitalisation, not by keyword.\n const name = nameOf(id, node)\n return !!name && /^[A-Z]/.test(name)\n }\n if (id === 'rust') {\n // `pub` = exported; `pub(crate)` & friends are crate-local, not public.\n return node.namedChildren.some(\n (c) => c?.type === 'visibility_modifier' && c.text === 'pub',\n )\n }\n if (id === 'java') {\n // Interface members are implicitly public.\n if (node.parent?.type === 'interface_body') return true\n return node.namedChildren.some((c) => c?.type === 'modifiers' && /\\bpublic\\b/.test(c?.text ?? ''))\n }\n if (id === 'cpp' || id === 'c') {\n return cppIsExported(node)\n }\n for (let parent = node.parent; parent; parent = parent.parent) {\n if (parent.type === 'export_statement') return true\n if (parent.type === 'statement_block' || parent.type === 'class_body') return false\n if (parent.type === 'program') return false\n }\n return false\n}\n\n/**\n * C/C++ export semantics:\n * - anything under `public:` in a class body is exported; `private:`/\n * `protected:` sections are not\n * - top-level declarations are exported unless marked `static`\n * (internal-linkage). C has no access sections; C++ namespaces stay\n * transparent — a symbol under namespace X is still module-level.\n */\nfunction cppIsExported(node: Node): boolean {\n const isStatic = node.namedChildren.some(\n (c) => c?.type === 'storage_class_specifier' && c.text === 'static',\n )\n for (let parent = node.parent; parent; parent = parent.parent) {\n if (parent.type === 'field_declaration_list') {\n const body = parent\n // Struct members default to public, class members to private (C++ rule).\n const structKind = body.parent?.type === 'struct_specifier' ? 'struct' : 'class'\n let current: string | null = structKind === 'struct' ? 'public' : 'private'\n for (let up: Node | null = node; up && up.id !== body.id; up = up.parent) {\n const next = up.parent\n if (next?.type === 'field_declaration_list') {\n const siblingIndex = next.namedChildren.findIndex((c) => c?.id === up.id)\n const accessBefore = next.namedChildren\n .slice(0, siblingIndex)\n .filter((c) => c?.type === 'access_specifier')\n if (accessBefore.length > 0) {\n current = accessBefore.at(-1)!.text.replace(':', '').trim()\n }\n }\n }\n return current === 'public' && !isStatic\n }\n if (parent.type === 'translation_unit') return !isStatic\n }\n return !isStatic\n}\n\n/**\n * Language quirks the query syntax can't express:\n * - python: no distinct method node — a def directly in a class body is one\n * - go: a type_spec is a class (struct) or interface by its type child\n * - rust: function_item directly in an impl body is a method\n */\nfunction kindFor(id: LanguageId, node: Node, kind: SymbolKind): SymbolKind {\n if (id === 'python' && kind === 'function') {\n const inClassBody = node.parent?.type === 'block' && node.parent?.parent?.type === 'class_definition'\n if (inClassBody) return 'method'\n }\n if (id === 'go' && node.type === 'type_spec') {\n const type = node.childForFieldName('type')?.type\n if (type === 'struct_type') return 'class'\n if (type === 'interface_type') return 'interface'\n return 'type'\n }\n if (id === 'rust' && node.type === 'function_item') {\n const inImpl = node.parent?.type === 'declaration_list' && node.parent?.parent?.type === 'impl_item'\n if (inImpl) return 'method'\n }\n if ((id === 'cpp' || id === 'c') && (kind === 'variable' || kind === 'field')) {\n // A declaration whose declarator chain holds a function_declarator is a\n // function prototype/definition — not a data member or global.\n let current = node.childForFieldName?.('declarator')\n while (current) {\n if (current.type === 'function_declarator') {\n return node.parent?.type === 'field_declaration_list' ? 'method' : 'function'\n }\n current = current.childForFieldName?.('declarator') ?? current.namedChildren[0] ?? null\n }\n return node.type === 'field_declaration' ? 'field' : 'variable'\n }\n if ((id === 'cpp' || id === 'c') && node.type === 'function_definition') {\n // A function defined directly in a class/struct body is a method.\n if (node.parent?.type === 'field_declaration_list') return 'method'\n }\n return kind\n}\n\n/** Compile a symbol query for a code sample (used by tests). */\nexport async function parseFileToSymbols(\n filePath: string,\n repoRoot: string,\n code?: string,\n): Promise<SymbolInfo[]> {\n const lang = languageForFile(filePath)\n if (!lang) return []\n const text = code ?? (await readFile(filePath, 'utf8'))\n const rows = await extractSymbols(text, lang)\n const rel = path.relative(repoRoot, filePath).split(path.sep).join('/')\n return rows.map((r) => ({ ...r, file: rel }))\n}","/** Workspace file discovery with dir exclusions and mtime tracking. */\n\nimport { readdir, stat } from 'node:fs/promises'\nimport path from 'node:path'\nimport type { IndexOptions } from './types.js'\n\nexport const DEFAULT_EXCLUDED_DIRS = [\n 'node_modules',\n '.git',\n '.idea',\n '.vscode',\n 'dist',\n 'build',\n 'out',\n 'coverage',\n '.next',\n '.nuxt',\n '.cache',\n 'target',\n 'vendor',\n '.dsh-code-index',\n]\n\n/** Language-agnostic source extensions we index. */\nexport const SUPPORTED_EXTS = new Set([\n '.ts',\n '.tsx',\n '.mts',\n '.cts',\n '.js',\n '.jsx',\n '.mjs',\n '.cjs',\n '.py',\n '.pyi',\n '.go',\n '.rs',\n '.java',\n '.cpp',\n '.cc',\n '.cxx',\n '.c++',\n '.hpp',\n '.hxx',\n '.hh',\n '.h',\n '.ipp',\n '.tpp',\n '.inl',\n '.c',\n])\n\nexport interface ScannedFile {\n /** Absolute path on disk. */\n abs: string\n /** Repo-relative path (forward-slash). */\n rel: string\n mtimeMs: number\n}\n\n/**\n * Recursively walk `root` and return indexed files, skipping excluded dir\n * components at any depth. Uses readdir with `withFileTypes` so we never\n * stat every entry; mtime comes from a targeted stat per candidate file.\n */\nexport async function scanRepo(\n root: string,\n options: IndexOptions = {},\n): Promise<ScannedFile[]> {\n const excluded = new Set([...DEFAULT_EXCLUDED_DIRS, ...(options.excludeDirs ?? [])])\n const results: ScannedFile[] = []\n const queue: Array<[string, string]> = [[root, '']] // [absDir, relDir]\n\n while (queue.length) {\n const [absDir, relDir] = queue.pop()!\n let entries\n try {\n entries = await readdir(absDir, { withFileTypes: true })\n } catch {\n continue // unreadable dir: skip into the void\n }\n for (const entry of entries) {\n const abs = path.join(absDir, entry.name)\n const rel = relDir ? `${relDir}/${entry.name}` : entry.name\n if (entry.isDirectory()) {\n if (excluded.has(entry.name)) continue\n queue.push([abs, rel])\n } else if (entry.isFile() && SUPPORTED_EXTS.has(path.extname(entry.name).toLowerCase())) {\n try {\n const st = await stat(abs)\n results.push({ abs, rel, mtimeMs: st.mtimeMs })\n } catch {\n // race: file deleted mid-scan — ignore\n }\n }\n }\n }\n\n results.sort((a, b) => a.rel.localeCompare(b.rel))\n return results\n}","/** On-disk JSON cache for RepoIndex, keyed by repo root. */\n\nimport { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises'\nimport path from 'node:path'\nimport { createHash, randomUUID } from 'node:crypto'\nimport type { RepoIndex } from './types.js'\n\nexport const CACHE_DIR_NAME = '.dsh-code-index'\n\n/** Stable root identity for cache hashing, including Windows case aliases. */\nexport function cacheKeyForRoot(root: string): string {\n const resolved = path.resolve(root)\n return process.platform === 'win32' ? resolved.toLowerCase() : resolved\n}\n\n/** Default cache location: `<repoRoot>/.dsh-code-index/index.json`. */\nexport function defaultCachePath(root: string, cacheDir?: string): string {\n const dir = cacheDir ?? path.join(root, CACHE_DIR_NAME)\n const hash = createHash('sha1').update(cacheKeyForRoot(root)).digest('hex').slice(0, 12)\n return path.join(dir, `${hash}.json`)\n}\n\n/** Cache filename used before Windows root casing was canonicalized. */\nexport function legacyCachePath(root: string, cacheDir?: string): string {\n const dir = cacheDir ?? path.join(root, CACHE_DIR_NAME)\n const hash = createHash('sha1').update(root).digest('hex').slice(0, 12)\n return path.join(dir, `${hash}.json`)\n}\n\nexport async function loadIndex(cachePath: string): Promise<RepoIndex | null> {\n try {\n const raw = await readFile(cachePath, 'utf8')\n const parsed = JSON.parse(raw) as RepoIndex\n if (!parsed || typeof parsed.root !== 'string' || !Array.isArray(parsed.files)) return null\n return healSymbolFiles(parsed)\n } catch {\n return null // missing or corrupt cache == no cache\n }\n}\n\n/**\n * Self-heal caches written before the per-symbol file backfill (the\n * \"SymbolInfo.file is always set\" invariant). Empty `file` fields are derived\n * from the containing IndexedFile path on load, so any consumer of loadIndex\n * sees consistent rows — and the next save persists the healed form.\n */\nexport function healSymbolFiles(index: RepoIndex): RepoIndex {\n for (const file of index.files) {\n for (const symbol of file.symbols) {\n if (!symbol.file) symbol.file = file.path\n }\n }\n return index\n}\n\nexport async function saveIndex(cachePath: string, index: RepoIndex): Promise<void> {\n await mkdir(path.dirname(cachePath), { recursive: true })\n const temporaryPath = `${cachePath}.${process.pid}.${randomUUID()}.tmp`\n try {\n await writeFile(temporaryPath, JSON.stringify(index, null, 2), { encoding: 'utf8', flag: 'wx' })\n await rename(temporaryPath, cachePath)\n } finally {\n await rm(temporaryPath, { force: true })\n }\n}\n","/** Shared data model for dsh-code-index. */\n\nexport type SymbolKind =\n | 'function'\n | 'method'\n | 'class'\n | 'interface'\n | 'type'\n | 'enum'\n | 'variable'\n | 'field'\n | 'import'\n | 'module'\n\nexport interface SymbolInfo {\n /** Symbol name (identifier / type id / member name). */\n name: string\n kind: SymbolKind\n /** Repo-relative path of the containing file, always forward-slash. */\n file: string\n /** 1-based start line. */\n line: number\n /** 1-based end line (inclusive). */\n endLine: number\n /** True when the symbol is exported at module level (export .. / export default). */\n exported: boolean\n /** Short human-readable signature, e.g. `greet(name: string)` — empty when n/a. */\n signature: string\n}\n\nexport interface IndexedFile {\n /** Repo-relative path (forward-slash). */\n path: string\n lang: string\n /** fs mtime of the source file at index time (milliseconds). */\n mtimeMs: number\n symbols: SymbolInfo[]\n /** Raw import specifiers found in this file ('./util', 'mypkg/core', …).\n * Optional because caches written before reference ranking lack it. */\n imports?: string[]\n}\n\nexport interface RepoIndex {\n /** Absolute source root this index describes. */\n root: string\n /** Unix ms when the index was generated. */\n generatedAt: number\n files: IndexedFile[]\n excludedDirs: string[]\n}\n\nexport function symbolCount(index: RepoIndex): number {\n return index.files.reduce((n, f) => n + f.symbols.length, 0)\n}\n\n/** Optional config consumed by the index build pipeline. */\nexport interface IndexOptions {\n /** Extra directories to exclude, appended to the defaults. */\n excludeDirs?: string[]\n /** Minimum mtime delta (ms) that forces a re-extract in refresh mode. */\n staleToleranceMs?: number\n}","/** Pure search / filter logic over a RepoIndex — unit-testable, no IO. */\n\nimport type { RepoIndex, SymbolInfo, SymbolKind } from './types.js'\n\nexport interface SymbolFilter {\n query?: string\n file?: string\n kind?: SymbolKind\n exportedOnly?: boolean\n}\n\nexport interface RankedHit extends SymbolInfo {\n /** 0..1 relevance. 1 = exact name match; lower = fuzzier. */\n score: number\n}\n\nfunction matchScore(name: string, query: string): number {\n const q = query.toLowerCase()\n const n = name.toLowerCase()\n if (n === q) return 1\n if (n.startsWith(q)) return 0.8\n if (n.includes(q)) return 0.5\n if (q.length >= 3 && isSubsequence(q, n)) return 0.3\n return 0\n}\n\n/**\n * Every query char appears in the name, in order — 'cfgldr' finds\n * 'configLoader'. Gated to 3+ chars so short queries don't match everything.\n */\nfunction isSubsequence(query: string, name: string): boolean {\n let i = 0\n for (const ch of name) {\n if (ch === query[i]) i++\n if (i === query.length) return true\n }\n return false\n}\n\n/** Filter symbols by file/kind/export, then score by name against query (if any). */\nexport function searchSymbols(\n index: RepoIndex,\n filter: SymbolFilter,\n limit = 50,\n): RankedHit[] {\n const q = (filter.query ?? '').trim()\n const filePat = filter.file?.trim().toLowerCase()\n const hits: RankedHit[] = []\n\n for (const file of index.files) {\n if (filePat && !file.path.toLowerCase().includes(filePat)) continue\n for (const sym of file.symbols) {\n if (filter.kind && sym.kind !== filter.kind) continue\n if (filter.exportedOnly && !sym.exported) continue\n const score = q ? matchScore(sym.name, q) : 0.4\n if (q && score === 0) continue\n hits.push({ ...sym, score })\n }\n }\n\n // Export boost, then relevance, then stable name order.\n hits.sort((a, b) => {\n const ab =\n Number(b.exported) - Number(a.exported) ||\n b.score - a.score ||\n a.name.localeCompare(b.name) ||\n a.file.localeCompare(b.file)\n return ab\n })\n return hits.slice(0, limit)\n}\n\n/** Neat one-line rendering of a hit for terminal/chat output. */\nexport function renderHit(hit: RankedHit): string {\n const exportMark = hit.exported ? 'export ' : ''\n const sig = hit.signature || hit.name\n const score = hit.score < 1 ? ` [${hit.score.toFixed(2)}]` : ''\n return `${exportMark}${hit.kind} ${sig}${score} — ${hit.file}:${hit.line}`\n}","/**\n * Bounded, ranked repo map generation — the \"aider-style\" overview the model\n * can turn to before browsing files. Pure logic, no IO.\n */\n\nimport path from 'node:path'\nimport { SUPPORTED_EXTS } from './scan.js'\nimport type { IndexedFile, RepoIndex, SymbolInfo, SymbolKind } from './types.js'\n\n/** Higher-weight symbols pull their file up the map. */\nexport const KIND_WEIGHT: Record<SymbolKind, number> = {\n class: 1.0,\n interface: 1.0,\n type: 0.8,\n function: 0.8,\n method: 0.7,\n enum: 0.9,\n variable: 0.25,\n field: 0.2,\n import: 0.05,\n module: 0.3,\n}\n\nexport interface RepoMapOptions {\n /** Max files to include (default 24). */\n topFiles?: number\n /** Max symbols per file (default 18). */\n symbolsPerFile?: number\n /** Hard cap on rendered characters (default 3200). */\n maxChars?: number\n}\n\nexport interface RepoMapEntry {\n path: string\n score: number\n symbols: Array<{ name: string; kind: SymbolKind; line: number; signature: string }>\n}\n\n/**\n * Paths that look like tests. A map led by test files reads as noise: tests\n * reference an API, they rarely explain it — and symbol density actively\n * favours them (many small functions), so they need an explicit damper.\n */\nconst TEST_PATH_RE =\n /(^|\\/)(tests?|__tests__)(\\/|$)|\\.(?:spec|test)\\.[cm]?[jt]sx?$|(^|\\/)(?:test_[^/]+\\.py|[^/]+_test\\.(?:py|go))$/\n\n/** Density-aware file score: weighted symbols minus bloat; test paths damped. */\nexport function scoreFile(file: IndexedFile): number {\n let score = 0\n for (const sym of file.symbols) {\n score += KIND_WEIGHT[sym.kind] ?? 0.3\n if (sym.exported) score += 0.3\n }\n score /= 1 + file.symbols.length * 0.04\n if (TEST_PATH_RE.test(file.path)) score *= 0.2\n return score\n}\n\n/** Rank files, take the top slice, cap per-file symbols. */\nexport function rankRepoMap(index: RepoIndex, options: RepoMapOptions = {}): RepoMapEntry[] {\n const topFiles = options.topFiles ?? 24\n const perFile = options.symbolsPerFile ?? 18\n const density = new Map<string, number>()\n for (const f of index.files) {\n if (f.symbols.length > 0) density.set(f.path, scoreFile(f))\n }\n const centrality = referencePageRank(index.files, density)\n const ranked = index.files\n .filter((f) => f.symbols.length > 0)\n .map((f) => ({\n file: f,\n score: (density.get(f.path) ?? 0) + REF_WEIGHT * (centrality.get(f.path) ?? 0),\n }))\n .sort((a, b) => b.score - a.score || a.file.path.localeCompare(b.file.path))\n .slice(0, topFiles)\n\n return ranked.map(({ file, score }) => ({\n path: file.path,\n score,\n symbols: file.symbols.slice(0, perFile).map((s) => ({\n name: s.name,\n kind: s.kind,\n line: s.line,\n signature: s.signature,\n })),\n }))\n}\n\n/** How much one unit of reference centrality is worth in map score. */\nconst REF_WEIGHT = 0.5\n\n/**\n * Count in-repo references: how many OTHER indexed files import each file.\n * Self-imports don't count; each (importer, target) pair counts once.\n */\nexport function countReferences(files: IndexedFile[]): Map<string, number> {\n const fileSet = new Set(files.map((f) => f.path))\n const counts = new Map<string, number>()\n for (const file of files) {\n const targets = new Set<string>()\n for (const spec of file.imports ?? []) {\n const target = resolveImport(spec, file.path, fileSet)\n if (target && target !== file.path) targets.add(target)\n }\n for (const target of targets) {\n counts.set(target, (counts.get(target) ?? 0) + 1)\n }\n }\n return counts\n}\n\n/** PageRank damping — the standard 0.85. */\nconst DAMPING = 0.85\n/** Stop the power iteration once total rank movement drops below this. */\nconst CONVERGENCE_TOL = 1e-6\n/** Hard cap; convergence on repo-sized graphs needs ~20-40. */\nconst MAX_ITERATIONS = 100\n\n/**\n * Personalized PageRank over the import graph: nodes are files, an edge\n * A → B means A imports B, so rank flows toward heavily-imported hubs — and\n * a hub that other hubs themselves import accumulates more than a merely\n * popular leaf, which flat in-degree counting cannot see.\n *\n * Teleport uses each file's density share instead of a uniform vector, so\n * sparsely-linked repos keep their 0.2.x ordering (with no edges the fixed\n * point IS the normalized density vector). Returns L1-normalized importance\n * mass per file.\n */\nfunction referencePageRank(files: IndexedFile[], density: Map<string, number>): Map<string, number> {\n const nodes = files.filter((f) => density.has(f.path)).map((f) => f.path)\n const n = nodes.length\n if (n === 0) return new Map()\n if (n === 1) return new Map([[nodes[0]!, 1]])\n\n const totalDensity = nodes.reduce((sum, p) => sum + (density.get(p) ?? 0), 0)\n const teleport = nodes.map((p) => (density.get(p) ?? 0) / totalDensity)\n\n const fileSet = new Set(nodes)\n const out = new Map<string, Set<string>>()\n for (const file of files) {\n if (!fileSet.has(file.path)) continue\n const targets = out.get(file.path) ?? new Set<string>()\n for (const spec of file.imports ?? []) {\n const target = resolveImport(spec, file.path, fileSet)\n if (target && target !== file.path) targets.add(target)\n }\n out.set(file.path, targets)\n }\n\n const incoming = new Map<string, Array<[fromIdx: number, weight: number]>>()\n for (const [from, targets] of out) {\n if (targets.size === 0) continue\n const weight = 1 / targets.size\n const fromIdx = nodes.indexOf(from)\n for (const target of targets) {\n const list = incoming.get(target) ?? []\n list.push([fromIdx, weight])\n incoming.set(target, list)\n }\n }\n\n let rank = teleport.slice()\n for (let iter = 0; iter < MAX_ITERATIONS; iter++) {\n let danglingMass = 0\n for (let i = 0; i < n; i++) {\n if (!out.get(nodes[i]!)?.size) danglingMass += rank[i]!\n }\n const next = new Array<number>(n)\n let delta = 0\n for (let i = 0; i < n; i++) {\n let flow = 0\n for (const [fromIdx, weight] of incoming.get(nodes[i]!) ?? []) {\n flow += rank[fromIdx]! * weight\n }\n next[i] = (1 - DAMPING) * teleport[i]! + DAMPING * (flow + danglingMass * teleport[i]!)\n delta += Math.abs(next[i]! - rank[i]!)\n }\n rank = next\n if (delta < CONVERGENCE_TOL) break\n }\n\n const result = new Map<string, number>()\n for (let i = 0; i < n; i++) result.set(nodes[i]!, rank[i]!)\n return result\n}\n\n/**\n * Resolve a raw import specifier against the indexed file set; returns the\n * repo-relative target path or null. Relative specifiers resolve against the\n * importing file; absolute ones against the repo root — with a suffix\n * fallback so Go module paths and Java package names match their in-repo\n * location without reading go.mod / package-info.\n */\nexport function resolveImport(spec: string, fromPath: string, fileSet: Set<string>): string | null {\n if (!spec) return null\n if (spec.startsWith('./') || spec.startsWith('../')) {\n const base = path.posix.normalize(path.posix.join(path.posix.dirname(fromPath), spec))\n return candidateFor(base, fileSet)\n }\n const segments = spec.split('/').filter(Boolean)\n for (let skip = 0; skip < segments.length; skip++) {\n const hit = candidateFor(segments.slice(skip).join('/'), fileSet)\n if (hit) return hit\n }\n return null\n}\n\n/** Extension and index-file candidates for a specifier base path. */\nfunction candidateFor(base: string, fileSet: Set<string>): string | null {\n // Bare path first: C/C++ includes already carry their extension\n // (\"net/socket.hpp\"), and matching the exact file beats guessing.\n if (fileSet.has(base)) return base\n for (const ext of SUPPORTED_EXTS) {\n if (fileSet.has(`${base}${ext}`)) return `${base}${ext}`\n }\n for (const ext of SUPPORTED_EXTS) {\n if (fileSet.has(`${base}/index${ext}`)) return `${base}/index${ext}`\n if (fileSet.has(`${base}/__init__${ext}`)) return `${base}/__init__${ext}`\n }\n return null\n}\n\n/** Render the ranked map as markdown, hard-truncated to maxChars. */\nexport function renderRepoMap(entries: RepoMapEntry[], options: RepoMapOptions = {}): string {\n const maxChars = options.maxChars ?? 3200\n const lines: string[] = ['# repo map']\n let totalSymbols = 0\n for (const e of entries) {\n totalSymbols += e.symbols.length\n lines.push(`## ${e.path} (${e.symbols.length})`)\n for (const s of e.symbols) {\n const label = s.signature || s.name\n lines.push(` ${s.kind} ${label} :${s.line}`)\n }\n }\n let text = lines.join('\\n')\n if (text.length > maxChars) {\n text = `${text.slice(0, maxChars)}\\n… truncated`\n }\n return totalSymbols > 0 ? text : ''\n}","/** Model-visible tools: code_index, code_symbols, code_search. */\n\nimport { defineTool, type JsonValue } from '@deepseek-ai/dsh-tools'\nimport path from 'node:path'\nimport { buildIndexWithCache, findRepoRoot } from './buildIndex.js'\nimport { renderHit, searchSymbols } from './search.js'\nimport { rankRepoMap, renderRepoMap } from './repomap.js'\nimport { getConfig, indexOptions } from './config.js'\nimport { cacheKeyForRoot } from './store.js'\nimport type { RepoIndex } from './types.js'\n\n/** Minimal structural types for the harness surfaces we touch. */\ninterface ToolCwdContext {\n agent?: {\n session?: { header?: { cwd?: string } }\n }\n}\ntype ToolRunExec = ToolCwdContext & { signal?: AbortSignal }\n\ninterface TextBlock {\n type: 'text'\n text: string\n}\n\nexport interface IndexCache {\n get(root: string, force?: boolean): Promise<RepoIndex>\n invalidate(): void\n}\n\n/** Retain completed indexes briefly while still coalescing concurrent refreshes. */\nexport function createIndexCache(\n load: (root: string) => Promise<RepoIndex>,\n ttlMs = 60_000,\n now: () => number = Date.now,\n): IndexCache {\n interface CompletedEntry {\n index: RepoIndex\n at: number\n epoch: number\n }\n interface LoadEntry {\n promise: Promise<RepoIndex>\n epoch: number\n }\n\n const completed = new Map<string, CompletedEntry>()\n const inFlight = new Map<string, LoadEntry>()\n let epoch = 0\n\n function startLoad(key: string, root: string, previous?: Promise<RepoIndex>): Promise<RepoIndex> {\n const loadEpoch = epoch\n const begin = previous\n ? previous.catch(() => undefined).then(() => load(root))\n : load(root)\n const promise = begin\n .then((index) => {\n if (loadEpoch === epoch) {\n completed.delete(key)\n completed.set(key, { index, at: now(), epoch: loadEpoch })\n while (completed.size > 16) completed.delete(completed.keys().next().value!)\n }\n return index\n })\n .finally(() => {\n if (inFlight.get(key)?.promise === promise) inFlight.delete(key)\n })\n inFlight.set(key, { promise, epoch: loadEpoch })\n return promise\n }\n\n return {\n get(root, force = false) {\n const resolvedRoot = path.resolve(root)\n const key = cacheKeyForRoot(resolvedRoot)\n const running = inFlight.get(key)\n if (running) {\n if (running.epoch === epoch && !force) return running.promise\n return startLoad(key, resolvedRoot, running.promise)\n }\n\n if (!force) {\n const cached = completed.get(key)\n if (cached && cached.epoch === epoch && now() - cached.at < ttlMs) {\n completed.delete(key)\n completed.set(key, cached)\n return Promise.resolve(cached.index)\n }\n if (cached) completed.delete(key)\n } else {\n completed.delete(key)\n }\n return startLoad(key, resolvedRoot)\n },\n invalidate() {\n epoch++\n completed.clear()\n },\n }\n}\n\nconst indexCache = createIndexCache((root) => buildIndexWithCache(root, indexOptions()))\n\nexport function getIndex(root: string, force = false): Promise<RepoIndex> {\n return indexCache.get(root, force)\n}\n\nexport function invalidateIndexCache(): void {\n indexCache.invalidate()\n}\n\nasync function resolveRoot(arg: string | undefined, exec: ToolRunExec): Promise<string> {\n const cwd = exec.agent?.session?.header?.cwd\n const base = arg ?? cwd ?? process.cwd()\n const root = await findRepoRoot(base)\n if (!root) throw new Error(`no git repository found from ${path.resolve(base)}`)\n return root\n}\n\nexport const tools = [\n defineTool({\n name: 'code_index',\n description:\n 'Manage the semantic repo index: status or (re)build it for the current workspace. Auto-builds the first time it is queried. Returns file/symbol counts and the index location.',\n parameters: {\n action: {\n type: 'string',\n enum: ['status', 'build'],\n description: '\"status\" (default) reports without forcing a rebuild; \"build\" forces a fresh scan.',\n },\n repoRoot: {\n type: 'string',\n description:\n 'Optional absolute repo path. Defaults to the workspace root of the current session.',\n },\n },\n output: {\n schema: { type: 'string' },\n render: (_args, value: string): TextBlock[] => [{ type: 'text', text: value }],\n },\n async execute(args: { action?: string; repoRoot?: string }, exec: ToolRunExec): Promise<string> {\n try {\n const root = await resolveRoot(args.repoRoot, exec)\n const index = await getIndex(root, args.action === 'build')\n const total = index.files.reduce((n, f) => n + f.symbols.length, 0)\n const langs = new Set(index.files.map((f) => f.lang))\n return [\n `repo: ${root}`,\n `files indexed: ${index.files.length}`,\n `symbols: ${total}`,\n `languages: ${[...langs].join(', ')}`,\n index.files.length === 0 ? 'no supported files found' : 'index up to date',\n ].join('\\n')\n } catch (error) {\n return `code_index: ${(error as Error).message ?? String(error)}`\n }\n },\n }),\n\n defineTool({\n name: 'code_symbols',\n description:\n 'List symbols (functions, classes, interfaces, types, methods, variables) in the current repo. Filter by name substring, file path substring, or symbol kind. Results are exported-first, alphabetically ordered.',\n parameters: {\n query: {\n type: 'string',\n description: 'Substring of the symbol name to match (case-insensitive). Omit to list all.',\n },\n file: {\n type: 'string',\n description: 'Substring of the repo-relative file path to match, e.g. \"src/core\".',\n },\n kind: {\n type: 'string',\n enum: ['function', 'method', 'class', 'interface', 'type', 'enum', 'variable', 'field'],\n description: 'Only return symbols of this kind.',\n },\n exportedOnly: {\n type: 'boolean',\n description: 'Only exported (module-level public) symbols.',\n },\n limit: {\n type: 'number',\n description: 'Max rows (default 50).',\n },\n repoRoot: {\n type: 'string',\n description: 'Optional absolute repo path; defaults to the session workspace root.',\n },\n },\n output: {\n schema: { type: 'array' },\n render: (_args, value: JsonValue[]): TextBlock[] =>\n value.map((v) => ({\n type: 'text' as const,\n text: renderHit(v as unknown as Parameters<typeof renderHit>[0]),\n })),\n },\n async execute(\n args: {\n query?: string\n file?: string\n kind?: 'function' | 'method' | 'class' | 'interface' | 'type' | 'enum' | 'variable' | 'field'\n exportedOnly?: boolean\n limit?: number\n repoRoot?: string\n },\n exec: ToolRunExec,\n ): Promise<JsonValue[]> {\n const root = await resolveRoot(args.repoRoot, exec)\n const index = await getIndex(root)\n const hits = searchSymbols(\n index,\n { query: args.query, file: args.file, kind: args.kind, exportedOnly: args.exportedOnly },\n args.limit ?? 50,\n )\n return hits as unknown as JsonValue[]\n },\n }),\n\n defineTool({\n name: 'code_search',\n description:\n 'Ranked symbol search over the repo index: exact > prefix > substring name matches, exported symbols first. Results carry a relevance score and file:line, so the model can locate definitions quickly.',\n parameters: {\n query: {\n type: 'string',\n required: true,\n description: 'Symbol name (or fragment) to find.',\n },\n limit: {\n type: 'number',\n description: 'Max hits (default 20).',\n },\n repoRoot: {\n type: 'string',\n description: 'Optional absolute repo path; defaults to the session workspace root.',\n },\n },\n output: {\n schema: { type: 'array' },\n render: (_args, value: JsonValue[]): TextBlock[] =>\n value.map((v) => ({\n type: 'text' as const,\n text: renderHit(v as unknown as Parameters<typeof renderHit>[0]),\n })),\n },\n async execute(\n args: { query: string; limit?: number; repoRoot?: string },\n exec: ToolRunExec,\n ): Promise<JsonValue[]> {\n const root = await resolveRoot(args.repoRoot, exec)\n const index = await getIndex(root)\n const hits = searchSymbols(index, { query: args.query }, args.limit ?? 20)\n return hits as unknown as JsonValue[]\n },\n }),\n\n defineTool({\n name: 'code_map',\n description:\n 'Return a bounded, ranked map of the current repo (top files by symbol density, with their key symbols and lines). The model can call this once per session to build an internal model of the codebase before browsing files.',\n parameters: {\n repoRoot: {\n type: 'string',\n description: 'Optional absolute repo path; defaults to the session workspace root.',\n },\n },\n output: {\n schema: { type: 'string' },\n render: (_args, value: string): TextBlock[] => [{ type: 'text', text: value }],\n },\n async execute(args: { repoRoot?: string }, exec: ToolRunExec): Promise<string> {\n try {\n const root = await resolveRoot(args.repoRoot, exec)\n const index = await getIndex(root)\n const cfg = getConfig()\n const map = renderRepoMap(\n rankRepoMap(index, { topFiles: cfg.mapTopFiles }),\n { maxChars: cfg.mapMaxChars },\n )\n if (!map) return 'no indexable symbols found in this repo'\n return map\n } catch (error) {\n return `code_index: ${(error as Error).message ?? String(error)}`\n }\n },\n }),\n]\n","/** Plugin configuration: merged once at apply time, read wherever needed. */\n\nimport type { IndexOptions } from './types.js'\n\nexport interface PluginConfig {\n /** Extra directories to exclude from indexing (appended to defaults). */\n excludeDirs?: string[]\n /** Max files in the ranked repo map (code_map / auto section). */\n mapTopFiles?: number\n /** Hard char cap for rendered maps. */\n mapMaxChars?: number\n /** Refresh interval for the auto-injected map (ms, min 1000). */\n mapTtlMs?: number\n /** Set false to disable the auto-injected system section. */\n autoInject?: boolean\n}\n\ninterface EffectiveConfig {\n excludeDirs: string[]\n mapTopFiles: number\n mapMaxChars: number\n mapTtlMs: number\n autoInject: boolean\n}\n\nconst DEFAULTS: EffectiveConfig = {\n excludeDirs: [],\n mapTopFiles: 24,\n mapMaxChars: 3200,\n mapTtlMs: 60_000,\n autoInject: true,\n}\n\nconst state: { current: EffectiveConfig } = { current: { ...DEFAULTS } }\n\n/** Merge a plugin-provided partial config over the defaults (idempotent). */\nexport function applyConfig(partial?: PluginConfig): void {\n state.current = {\n ...DEFAULTS,\n ...(partial ?? {}),\n excludeDirs: [...DEFAULTS.excludeDirs, ...(partial?.excludeDirs ?? [])],\n }\n // Coerce obviously wrong inputs.\n if (!Number.isFinite(state.current.mapTopFiles) || state.current.mapTopFiles < 1) {\n state.current.mapTopFiles = DEFAULTS.mapTopFiles\n }\n if (!Number.isFinite(state.current.mapMaxChars) || state.current.mapMaxChars < 200) {\n state.current.mapMaxChars = DEFAULTS.mapMaxChars\n }\n if (!Number.isFinite(state.current.mapTtlMs) || state.current.mapTtlMs < 1_000) {\n state.current.mapTtlMs = DEFAULTS.mapTtlMs\n }\n}\n\nexport function getConfig(): Readonly<EffectiveConfig> {\n return state.current\n}\n\n/** Map the effective config onto the index pipeline options. */\nexport function indexOptions(): IndexOptions {\n return { excludeDirs: state.current.excludeDirs }\n}","/**\n * dsh-code-index — DeepSeek Harness bundle entry.\n *\n * Registers four model-visible tools (code_index / code_symbols /\n * code_search / code_map) backed by a tree-sitter symbol index, and\n * injects a bounded auto-updating repo map for the default workspace\n * into the system prompt.\n */\n\ntype Disposer = void | (() => void)\n\n/** Minimal structural Context; the real @deepseek-ai/cordis type is a\n * runtime dependency we intentionally do not import in the bundle entry. */\ninterface MinimalContext {\n effect(fn: () => Disposer): void\n tools: { register(t: unknown): () => void }\n systemPrompt: {\n section(section: {\n name: string\n order: number\n text: string | ((context: unknown) => string)\n }): () => void\n }\n}\n\nexport const name = 'dsh-code-index'\n\n// Public API surface (consumable by other bundles / tests).\nexport { buildIndex, buildIndexWithCache, findRepoRoot } from './buildIndex.js'\nexport { extractSymbols, extractAll, languageForFile, parseFileToSymbols } from './extract.js'\nexport { scanRepo, DEFAULT_EXCLUDED_DIRS, SUPPORTED_EXTS } from './scan.js'\nexport { loadIndex, saveIndex, defaultCachePath, CACHE_DIR_NAME } from './store.js'\nexport { symbolCount } from './types.js'\nexport type { RepoIndex, IndexedFile, SymbolInfo, SymbolKind, IndexOptions } from './types.js'\nexport { searchSymbols, renderHit } from './search.js'\nexport { rankRepoMap, renderRepoMap, scoreFile } from './repomap.js'\nexport { tools } from './tools.js'\n\nimport { getIndex, invalidateIndexCache, tools } from './tools.js'\nimport { findRepoRoot } from './buildIndex.js'\nimport { rankRepoMap, renderRepoMap } from './repomap.js'\nimport { symbolCount } from './types.js'\nimport { applyConfig, getConfig, type PluginConfig } from './config.js'\n\nexport const inject = ['tools', 'systemPrompt'] as const\n\nexport function apply(ctx: MinimalContext, pluginConfig?: PluginConfig) {\n applyConfig(pluginConfig)\n invalidateIndexCache()\n ctx.effect(() => {\n const disposers: Array<() => void> = []\n console.log('[dsh-code-index] plugin loaded')\n for (const tool of tools) {\n disposers.push(ctx.tools.register(tool))\n console.log(`[dsh-code-index] registered tool: ${tool.name}`)\n }\n\n // Auto-inject a bounded repo map for the DEFAULT workspace (the dsh\n // launch directory, per the harness docs). Multi-workspace web sessions\n // should rely on the `code_map` tool, which resolves the per-session cwd.\n let cached: { root: string; at: number; text: string } | null = null\n\n async function warmMap(): Promise<void> {\n const now = Date.now()\n const cfg = getConfig()\n try {\n const root = await findRepoRoot(process.cwd())\n if (!root) {\n cached = { root: '', at: now, text: '' }\n return\n }\n const index = await getIndex(root)\n const text = renderRepoMap(\n rankRepoMap(index, { topFiles: cfg.mapTopFiles }),\n { maxChars: cfg.mapMaxChars },\n )\n const stats = symbolCount(index)\n cached = {\n root: index.root,\n at: Date.now(),\n text: text ? `${text}\\n\\n(summary: ${index.files.length} files, ${stats} symbols)` : '',\n }\n } catch {\n cached = { root: '', at: now, text: '' } // never let injection fail the boot\n }\n }\n\n // Warm eagerly at load so the first assembly already has the map.\n void warmMap()\n\n if (getConfig().autoInject) {\n disposers.push(ctx.systemPrompt.section({\n name: 'code-index:repo-map',\n order: 60, // before tool guidance (100–199), after persona (0)\n text: () => {\n const now = Date.now()\n if (cached && now - cached.at < getConfig().mapTtlMs) return cached.text\n void warmMap()\n return cached?.text ?? ''\n },\n }))\n }\n\n return () => {\n const errors: unknown[] = []\n for (const dispose of disposers.reverse()) {\n try {\n dispose()\n } catch (error) {\n errors.push(error)\n }\n }\n console.log('[dsh-code-index] plugin unloaded')\n if (errors.length > 0) throw new AggregateError(errors, 'failed to unload dsh-code-index')\n }\n })\n}\n"],"mappings":";AAEA,SAAS,YAAAA,WAAU,QAAAC,aAAY;AAC/B,OAAOC,WAAU;;;ACQjB,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAC9B,OAAO,UAAU;AACjB,SAAoB,UAAU,QAAQ,aAAa;AAGnD,IAAMC,WAAU,cAAc,YAAY,GAAG;AAe7C,IAAM,WAAW,KAAK,QAAQA,SAAQ,QAAQ,mDAAmD,CAAC;AAElG,IAAM,gBAA4C;AAAA,EAChD,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,IAAI;AAAA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Q,MAAM,SAAS,IAAI;AACjC,cAAM,OAAO;AAAA,UACX,YAAY,OAAO,EAAE,UAAU,IAAI,YAAY,CAAC;AAAA,UAChD,EAAE,UAAU,IAAI,YAAY;AAAA,QAC9B;AACA,cAAM,QAAQ,YAAY,KAAK;AAC/B,iBAAS;AAAA,UACP,MAAM,MAAM;AAAA,UACZ,IAAI,KAAK,IAAI;AAAA,UACb,MAAM,OAAO,GAAG,IAAI;AAAA;AAAA,YAAiB,MAAM,MAAM,MAAM,WAAW,KAAK,cAAc;AAAA,QACvF;AAAA,MACF,QAAQ;AACN,iBAAS,EAAE,MAAM,IAAI,IAAI,KAAK,MAAM,GAAG;AAAA,MACzC;AAAA,IACF;AAGA,SAAK,QAAQ;AAEb,QAAI,UAAU,EAAE,YAAY;AAC1B,gBAAU,KAAK,IAAI,aAAa,QAAQ;AAAA,QACtC,MAAM;AAAA,QACN,OAAO;AAAA;AAAA,QACP,MAAM,MAAM;AACV,gBAAM,MAAM,KAAK,IAAI;AACrB,cAAI,UAAU,MAAM,OAAO,KAAK,UAAU,EAAE,SAAU,QAAO,OAAO;AACpE,eAAK,QAAQ;AACb,iBAAO,QAAQ,QAAQ;AAAA,QACzB;AAAA,MACF,CAAC,CAAC;AAAA,IACJ;AAEA,WAAO,MAAM;AACX,YAAM,SAAoB,CAAC;AAC3B,iBAAW,WAAW,UAAU,QAAQ,GAAG;AACzC,YAAI;AACF,kBAAQ;AAAA,QACV,SAAS,OAAO;AACd,iBAAO,KAAK,KAAK;AAAA,QACnB;AAAA,MACF;AACA,cAAQ,IAAI,kCAAkC;AAC9C,UAAI,OAAO,SAAS,EAAG,OAAM,IAAI,eAAe,QAAQ,iCAAiC;AAAA,IAC3F;AAAA,EACF,CAAC;AACH;","names":["readFile","stat","path","require","name","path","readFile","path","readFile","path","stat","name","path","path","path","path"]}
1
+ {"version":3,"sources":["../src/buildIndex.ts","../src/extract.ts","../src/scan.ts","../src/store.ts","../src/types.ts","../src/refgraph.ts","../src/search.ts","../src/repomap.ts","../src/health.ts","../src/tools.ts","../src/config.ts","../src/settings.ts","../src/index.ts"],"sourcesContent":["/** Build a RepoIndex for a workspace: scan -> extract -> persist. */\n\nimport { readFile, stat } from 'node:fs/promises'\nimport path from 'node:path'\nimport { extractAll, languageForFile } from './extract.js'\nimport { scanRepo, DEFAULT_EXCLUDED_DIRS } from './scan.js'\nimport {\n cacheKeyForRoot,\n defaultCachePath,\n legacyCachePath,\n loadIndex,\n saveIndex,\n} from './store.js'\nimport type { IndexOptions, IndexedFile, RepoIndex } from './types.js'\n\n/**\n * Full build: scan + extract every supported file. Existing per-file\n * extraction is reused when `previous` holds an identical mtime for the\n * same rel path (incremental refresh), so touched files alone re-parse.\n */\nexport async function buildIndex(\n root: string,\n options: IndexOptions = {},\n previous: RepoIndex | null = null,\n): Promise<RepoIndex> {\n const scanned = await scanRepo(root, options)\n\n // Index stale/current state from the previous run by rel path.\n const prevByPath = new Map((previous?.files ?? []).map((f) => [f.path, f]))\n const prevMtime = new Map((previous?.files ?? []).map((f) => [f.path, f.mtimeMs]))\n\n const files: IndexedFile[] = []\n const BATCH = 8\n for (let i = 0; i < scanned.length; i += BATCH) {\n const batch = scanned.slice(i, i + BATCH)\n const rows = await Promise.all(\n batch.map(async (f) => {\n const lang = languageForFile(f.abs)\n if (!lang) return null\n if (prevMtime.get(f.rel) === f.mtimeMs) {\n const cached = prevByPath.get(f.rel)!\n return {\n ...cached,\n mtimeMs: f.mtimeMs,\n symbols: cached.symbols.map((symbol) => ({ ...symbol, file: f.rel })),\n }\n }\n let code: string\n try {\n code = await readFile(f.abs, 'utf8')\n } catch {\n return null\n }\n const { symbols, imports, calls } = await extractAll(code, lang)\n // Backfill the repo-relative path: the extractor is file-agnostic and\n // leaves SymbolInfo.file empty, but search/render depend on it.\n return {\n path: f.rel,\n lang,\n mtimeMs: f.mtimeMs,\n symbols: symbols.map((s) => ({ ...s, file: f.rel })),\n imports,\n calls,\n } satisfies IndexedFile\n }),\n )\n for (const f of rows) {\n if (f) files.push(f)\n }\n }\n\n return {\n root,\n generatedAt: Date.now(),\n files,\n excludedDirs: [...DEFAULT_EXCLUDED_DIRS, ...(options.excludeDirs ?? [])],\n }\n}\n\n/** Convenience wrapper: evolve an on-disk cache if `root` exists. */\nexport async function buildIndexWithCache(\n root: string,\n options: IndexOptions = {},\n cacheDir?: string,\n): Promise<RepoIndex> {\n const cachePath = defaultCachePath(root, cacheDir)\n let prev = await loadIndex(cachePath)\n let loadedLegacy = false\n if (!prev) {\n const oldPath = legacyCachePath(root, cacheDir)\n if (oldPath !== cachePath) {\n prev = await loadIndex(oldPath)\n loadedLegacy = prev !== null\n }\n }\n const reusable = prev && cacheKeyForRoot(prev.root) === cacheKeyForRoot(root) ? prev : null\n const fresh = await buildIndex(root, options, reusable)\n if (prev && indexesEqual(prev, fresh)) {\n if (loadedLegacy) await saveIndex(cachePath, fresh)\n return loadedLegacy ? fresh : prev\n }\n await saveIndex(cachePath, fresh)\n return fresh\n}\n\nfunction indexesEqual(left: RepoIndex, right: RepoIndex): boolean {\n if (cacheKeyForRoot(left.root) !== cacheKeyForRoot(right.root)) return false\n if (left.files.length !== right.files.length) return false\n if (left.excludedDirs.length !== right.excludedDirs.length) return false\n if (left.excludedDirs.some((value, index) => value !== right.excludedDirs[index])) return false\n\n return left.files.every((file, fileIndex) => {\n const other = right.files[fileIndex]\n if (!other || file.path !== other.path || file.lang !== other.lang || file.mtimeMs !== other.mtimeMs) {\n return false\n }\n if (file.symbols.length !== other.symbols.length) return false\n if (!callsEqual(file.calls, other.calls)) return false\n return file.symbols.every((symbol, symbolIndex) => {\n const candidate = other.symbols[symbolIndex]\n return candidate !== undefined\n && symbol.name === candidate.name\n && symbol.kind === candidate.kind\n && symbol.file === candidate.file\n && symbol.line === candidate.line\n && symbol.endLine === candidate.endLine\n && symbol.exported === candidate.exported\n && symbol.signature === candidate.signature\n })\n })\n}\n\n/**\n * Calls are compared so a cache written before call-graph support is treated as\n * stale and re-persisted, instead of silently shadowing the richer fresh index.\n */\nfunction callsEqual(left: IndexedFile['calls'], right: IndexedFile['calls']): boolean {\n const a = left ?? []\n const b = right ?? []\n if (a.length !== b.length) return false\n return a.every((call, index) => {\n const other = b[index]\n return other !== undefined\n && call.name === other.name\n && call.line === other.line\n && call.from === other.from\n })\n}\n\n/**\n * Locate the git repo root for a path by walking up to the nearest `.git`\n * directory. Bounded walk (max `maxLevels` levels); returns `null` when no\n * repo marker is found — callers must NOT index an untagged directory\n * (the fs root is the classic footgun: indexing `C:\\` by accident).\n */\nexport async function findRepoRoot(startDir: string, maxLevels = 12): Promise<string | null> {\n let dir = path.resolve(startDir)\n for (let level = 0; level < maxLevels; level++) {\n try {\n // stat() accepts BOTH a `.git` directory (normal repos) and a `.git`\n // file (worktrees / submodules) — readFile only handled the file form.\n await stat(path.join(dir, '.git'))\n return dir\n } catch {\n // not a repo here — keep walking\n }\n const parent = path.dirname(dir)\n if (parent === dir) return null\n dir = parent\n }\n return null\n}\n","/**\n * tree-sitter symbol extraction.\n *\n * Parses a source text with a per-language grammar (web-tree-sitter WASM,\n * static grammars from tree-sitter-wasms) and returns flat SymbolInfo rows.\n *\n * NOTE on the dependency pin: web-tree-sitter must stay at ^0.20.x — newer\n * releases expect dylinked grammar wasm, while tree-sitter-wasms ships\n * static builds. Verified working pair: web-tree-sitter@0.20.8 + tree-sitter-wasms@0.1.13.\n */\n\nimport { readFile } from 'node:fs/promises'\nimport { createRequire } from 'node:module'\nimport path from 'node:path'\nimport { type Node, Language, Parser, Query } from 'web-tree-sitter'\nimport type { CallInfo, SymbolInfo, SymbolKind } from './types.js'\n\nconst require = createRequire(import.meta.url)\n// web-tree-sitter ≥0.25 is ESM with named exports; 0.20.x was CJS\n// `export = Parser`. tsup externalizes the dep, so the import shape must\n// match the published ESM entry.\n\nexport type LanguageId =\n | 'typescript'\n | 'javascript'\n | 'python'\n | 'go'\n | 'rust'\n | 'java'\n | 'cpp'\n | 'c'\n\nconst WASM_DIR = path.dirname(require.resolve('tree-sitter-wasms/out/tree-sitter-typescript.wasm'))\n\nconst GRAMMAR_NAMES: Record<LanguageId, string> = {\n typescript: 'tree-sitter-typescript',\n javascript: 'tree-sitter-javascript',\n python: 'tree-sitter-python',\n go: 'tree-sitter-go',\n rust: 'tree-sitter-rust',\n java: 'tree-sitter-java',\n cpp: 'tree-sitter-cpp',\n c: 'tree-sitter-c',\n}\n\nconst EXT_TO_LANG: Record<string, LanguageId> = {\n '.ts': 'typescript',\n '.tsx': 'typescript',\n '.mts': 'typescript',\n '.cts': 'typescript',\n '.js': 'javascript',\n '.jsx': 'javascript',\n '.mjs': 'javascript',\n '.cjs': 'javascript',\n '.py': 'python',\n '.pyi': 'python',\n '.go': 'go',\n '.rs': 'rust',\n '.java': 'java',\n '.cpp': 'cpp',\n '.cc': 'cpp',\n '.cxx': 'cpp',\n '.c++': 'cpp',\n '.hpp': 'cpp',\n '.hxx': 'cpp',\n '.hh': 'cpp',\n '.h': 'cpp',\n '.ipp': 'cpp',\n '.tpp': 'cpp',\n '.inl': 'cpp',\n '.c': 'c',\n}\n\nexport function languageForFile(filePath: string): LanguageId | null {\n const ext = path.extname(filePath).toLowerCase()\n return EXT_TO_LANG[ext] ?? null\n}\n\n/** Kind of a capture per query. */\ntype CaptureDef = { kind: SymbolKind; exported?: boolean }\n\n// Query definitions per language. Captures bind to the DECLARATION node\n// (capture OUTSIDE the pattern: `(function_declaration) @function` — the\n// 0.20 query parser rejects a capture sitting directly after the node type\n// inside the parens). Names/signatures/export come from node fields.\nconst QUERIES: Record<LanguageId, string> = {\n typescript: `\n (function_declaration) @function\n (generator_function_declaration) @function\n (method_definition) @method\n (class_declaration) @class\n (interface_declaration) @interface\n (type_alias_declaration) @type\n (enum_declaration) @enum\n (variable_declarator) @variable\n (public_field_definition) @field\n (abstract_class_declaration) @class\n `,\n // JS shares the same query surface; type-related patterns simply never match.\n javascript: `\n (function_declaration) @function\n (generator_function_declaration) @function\n (method_definition) @method\n (class_declaration) @class\n (variable_declarator) @variable\n `,\n python: `\n (function_definition) @function\n (class_definition) @class\n `,\n go: `\n (function_declaration) @function\n (method_declaration) @method\n (type_spec) @type\n `,\n rust: `\n (function_item) @function\n (function_signature_item) @method\n (struct_item) @class\n (enum_item) @enum\n (trait_item) @interface\n `,\n java: `\n (class_declaration) @class\n (interface_declaration) @interface\n (enum_declaration) @enum\n (method_declaration) @method\n (constructor_declaration) @method\n `,\n // C++ grammar (superset of C — also serves .h headers). function names\n // live inside the declarator chain, so patterns stay broad and names,\n // kinds and signatures are resolved in code (cppNameOf / kindFor /\n // signatureFor). Top-level `declaration` covers prototypes, constructors\n // and globals; field_declaration covers class-body members.\n cpp: `\n (function_definition) @function\n (class_specifier body: (_)) @class\n (struct_specifier body: (_)) @class\n (enum_specifier body: (_)) @enum\n (type_definition) @type\n (alias_declaration) @type\n (namespace_definition) @module\n (field_declaration) @field\n (declaration) @variable\n `,\n // Plain C: same core nodes minus C++-only namespace/alias forms.\n c: `\n (function_definition) @function\n (struct_specifier body: (_)) @class\n (enum_specifier body: (_)) @enum\n (type_definition) @type\n (field_declaration) @field\n (declaration) @variable\n `,\n}\n\nconst CAPTURE_KINDS: Record<string, CaptureDef> = {\n function: { kind: 'function' },\n method: { kind: 'method' },\n class: { kind: 'class' },\n interface: { kind: 'interface' },\n type: { kind: 'type' },\n enum: { kind: 'enum' },\n variable: { kind: 'variable' },\n field: { kind: 'field' },\n module: { kind: 'module' },\n}\n\n// Import statements per language. Whole statements are captured; the module\n// specifier is read from node fields in code (string quoting, dotted vs\n// relative vs URL-style syntax differ per grammar). CommonJS require() is out\n// of scope — the ES import surface covers the modern plugin ecosystem.\nconst IMPORT_QUERIES: Record<LanguageId, string> = {\n typescript: `\n (import_statement) @import\n (export_statement) @reexport\n `,\n javascript: `\n (import_statement) @import\n (export_statement) @reexport\n `,\n python: `\n (import_from_statement) @import\n (import_statement) @import\n `,\n go: `\n (import_spec) @import\n `,\n rust: `\n (use_declaration) @use\n `,\n java: `\n (import_declaration) @import\n `,\n // C/C++: #include \"local.hpp\" — quoted form resolves in-repo; <system>\n // captures too but yields null and is dropped by the extractor.\n cpp: `\n (preproc_include) @import\n `,\n c: `\n (preproc_include) @import\n `,\n}\n\n// Call expressions per language. Each capture binds the CALLEE name node, so\n// the extractor can build a function-level call graph (see enclosingCallable).\n// Member/selector calls capture the property/field tail, which is what a\n// definition lookup matches; `new X()` is a construction call.\nconst CALL_QUERIES: Record<LanguageId, string> = {\n typescript: `\n (call_expression function: (identifier) @call)\n (call_expression function: (member_expression property: (property_identifier) @call))\n (new_expression constructor: (identifier) @call)\n `,\n javascript: `\n (call_expression function: (identifier) @call)\n (call_expression function: (member_expression property: (property_identifier) @call))\n (new_expression constructor: (identifier) @call)\n `,\n python: `\n (call function: (identifier) @call)\n (call function: (attribute attribute: (identifier) @call))\n `,\n go: `\n (call_expression function: (identifier) @call)\n (call_expression function: (selector_expression field: (field_identifier) @call))\n `,\n rust: `\n (call_expression function: (identifier) @call)\n (call_expression function: (field_expression field: (field_identifier) @call))\n (call_expression function: (scoped_identifier name: (identifier) @call))\n `,\n java: `\n (method_invocation name: (identifier) @call)\n (object_creation_expression type: (type_identifier) @call)\n `,\n cpp: `\n (call_expression function: (identifier) @call)\n (call_expression function: (field_expression field: (field_identifier) @call))\n (call_expression function: (qualified_identifier name: (identifier) @call))\n `,\n c: `\n (call_expression function: (identifier) @call)\n (call_expression function: (field_expression field: (field_identifier) @call))\n `,\n}\n\n// Ancestor node types that own a call body, per language. Walking up from a\n// call site to the nearest one yields the function whose callees they are.\nconst CALLABLE_NODES: Record<LanguageId, Set<string>> = {\n typescript: new Set([\n 'function_declaration',\n 'generator_function_declaration',\n 'method_definition',\n 'function_expression',\n 'arrow_function',\n ]),\n javascript: new Set([\n 'function_declaration',\n 'generator_function_declaration',\n 'method_definition',\n 'function_expression',\n 'arrow_function',\n ]),\n python: new Set(['function_definition']),\n go: new Set(['function_declaration', 'method_declaration', 'func_literal']),\n rust: new Set(['function_item', 'function_signature_item']),\n java: new Set(['method_declaration', 'constructor_declaration']),\n cpp: new Set(['function_definition', 'lambda_expression']),\n c: new Set(['function_definition']),\n}\n\nlet parserPromise: Promise<Parser> | null = null\n\nasync function getParser(): Promise<Parser> {\n if (!parserPromise) {\n parserPromise = (async () => {\n const wasm = path.join(path.dirname(require.resolve('web-tree-sitter')), 'tree-sitter.wasm')\n await Parser.init({ locateFile: () => wasm })\n const p = new Parser()\n return p\n })()\n }\n return parserPromise\n}\n\nconst languageCache = new Map<LanguageId, Promise<Language>>()\n\nfunction getLanguage(id: LanguageId): Promise<Language> {\n let entry = languageCache.get(id)\n if (!entry) {\n entry = getParser().then(async () => {\n const grammarPath = path.join(WASM_DIR, `${GRAMMAR_NAMES[id]}.wasm`)\n const bytes = await readFile(grammarPath)\n const lang = await Language.load(bytes)\n // Precompile queries per language to catch authoring errors early.\n // (0.25 deprecates lang.query(); use the Query constructor.)\n new Query(lang, QUERIES[id]).delete()\n new Query(lang, IMPORT_QUERIES[id]).delete()\n new Query(lang, CALL_QUERIES[id]).delete()\n return lang\n })\n languageCache.set(id, entry)\n }\n return entry\n}\n\n/**\n * Extract symbols and raw import specifiers from source text of the given\n * language, from a single parse. Returns rows ordered by file line. Never\n * throws for parse errors — a failed parse yields empty lists (the caller\n * logs and continues).\n */\nexport interface ExtractedFile {\n symbols: SymbolInfo[]\n /** Raw module specifiers, e.g. './util', 'node:fs', './utils' (py). */\n imports: string[]\n /** Call sites, ordered by line: callee name + enclosing function. */\n calls: CallInfo[]\n}\n\nexport async function extractAll(code: string, id: LanguageId): Promise<ExtractedFile> {\n const lang = await getLanguage(id)\n const parser = await getParser()\n parser.setLanguage(lang)\n const tree = parser.parse(code)\n if (!tree) throw new Error(`tree-sitter parse returned null for a ${id} source`)\n try {\n const symbols: SymbolInfo[] = []\n const symbolQuery = new Query(lang, QUERIES[id])\n try {\n const captures = symbolQuery.captures(tree.rootNode)\n for (const cap of captures) {\n const def = CAPTURE_KINDS[cap.name]\n if (!def) continue\n const node = cap.node\n // tree-sitter queries match at any depth; without this check the\n // variable_declarator pattern would also capture function-body\n // locals — pure index noise.\n if (def.kind === 'variable' && !isModuleLevelVariable(id, node)) continue\n const name = nameOf(id, node)\n if (!name) continue\n symbols.push({\n name,\n kind: kindFor(id, node, def.kind),\n file: '', // set by the caller (extractor is file-agnostic)\n line: node.startPosition.row + 1,\n endLine: node.endPosition.row + 1,\n exported: isExported(id, node),\n signature: signatureFor(id, node),\n })\n }\n } finally {\n symbolQuery.delete()\n }\n\n const imports: string[] = []\n const importQuery = new Query(lang, IMPORT_QUERIES[id])\n try {\n for (const cap of importQuery.captures(tree.rootNode)) {\n const spec = specifierOf(id, cap.node)\n if (spec) imports.push(spec)\n }\n } finally {\n importQuery.delete()\n }\n\n const calls: CallInfo[] = []\n const callQuery = new Query(lang, CALL_QUERIES[id])\n try {\n const seen = new Set<string>()\n for (const cap of callQuery.captures(tree.rootNode)) {\n const name = cap.node.text.trim()\n if (!name) continue\n const line = cap.node.startPosition.row + 1\n const from = enclosingCallable(id, cap.node)\n const key = `${from}|${name}|${line}`\n if (seen.has(key)) continue\n seen.add(key)\n calls.push({ name, line, from })\n }\n } finally {\n callQuery.delete()\n }\n calls.sort((a, b) => a.line - b.line || a.name.localeCompare(b.name))\n\n symbols.sort((a, b) => a.line - b.line)\n const seen = new Set<string>()\n const deduped = symbols.filter((s) => {\n const key = `${s.kind}|${s.name}|${s.line}`\n if (seen.has(key)) return false\n seen.add(key)\n return true\n })\n return { symbols: deduped, imports, calls }\n } finally {\n tree.delete()\n }\n}\n\n/** Symbols only — see extractAll for the combined parse. */\nexport async function extractSymbols(code: string, id: LanguageId): Promise<SymbolInfo[]> {\n return (await extractAll(code, id)).symbols\n}\n\n/** The declared name of a declaration node — language-aware dispatch. */\nfunction nameOf(id: LanguageId, node: Node): string {\n if (id === 'cpp' || id === 'c') return cppNameOf(node)\n const field = node.childForFieldName?.('name')\n if (field) return field.text.trim()\n // e.g. an anonymous default export — skip those.\n return ''\n}\n\n/**\n * C/C++ declaration names hide in the declarator chain:\n * - function_definition → declarator:function_declarator → identifier |\n * qualified_identifier (A::b) | field_identifier (in-class method)\n * - class/struct/enum specifiers and alias_declaration carry `name`\n * - type_definition → declarator:type_identifier\n * Returns '' for anonymous declarations (skipped upstream).\n */\nfunction cppNameOf(node: Node): string {\n const nameField = node.childForFieldName?.('name')\n if (nameField) return nameField.text.trim()\n if (node.type === 'type_definition') {\n return node.childForFieldName?.('declarator')?.text.trim() ?? ''\n }\n let declarator = node.childForFieldName?.('declarator')\n if (declarator?.type === 'init_declarator') {\n declarator = declarator.childForFieldName?.('declarator')\n }\n if (declarator) {\n let current: Node | null = declarator\n while (current) {\n if (\n current.type === 'function_declarator' ||\n current.type === 'pointer_declarator' ||\n current.type === 'array_declarator' ||\n current.type === 'reference_declarator' ||\n current.type === 'parenthesized_declarator' ||\n current.type === 'init_declarator'\n ) {\n current = current.childForFieldName?.('declarator') ?? current.namedChildren[0] ?? null\n continue\n }\n if (current.type === 'qualified_identifier') {\n // app::main_entry — the bare name is the last segment.\n return current.childForFieldName?.('name')?.text.trim() ?? current.text.trim()\n }\n if (\n current.type === 'identifier' ||\n current.type === 'field_identifier' ||\n current.type === 'type_identifier'\n ) {\n return current.text.trim()\n }\n break\n }\n }\n return ''\n}\n\n/**\n * The nearest enclosing function/method of a call site. Anonymous function\n * forms (arrow / function expression) borrow the name of the variable they are\n * assigned to; a call at module scope returns ''.\n */\nfunction enclosingCallable(id: LanguageId, node: Node): string {\n const callable = CALLABLE_NODES[id]\n for (let parent = node.parent; parent; parent = parent.parent) {\n if (!callable.has(parent.type)) continue\n const named = nameOf(id, parent)\n if (named) return named\n const declaration = parent.parent\n const field = declaration?.type === 'variable_declarator' ? 'name' : null\n if (field) return declaration?.childForFieldName?.(field)?.text.trim() ?? ''\n return ''\n }\n return ''\n}\n\n/** Read the raw module specifier out of a captured import statement. */\nfunction specifierOf(id: LanguageId, node: Node): string | null { switch (node.type) {\n case 'import_statement':\n // ts/js: `import … from './x'` (source); python: `import a.b` (name)\n if (id === 'python') return dottedToPath(node.childForFieldName('name')?.text)\n return stripQuotes(node.childForFieldName('source')?.text)\n case 'export_statement':\n // ts/js re-export: `export … from './x'`; plain exports have no source\n return stripQuotes(node.childForFieldName('source')?.text)\n case 'import_from_statement': {\n // python: `from .utils import x` / `from mypkg.core import Thing`\n const raw = node.childForFieldName('module_name')?.text\n if (raw == null) return null\n return raw.startsWith('.') ? pythonRelative(raw) : dottedToPath(raw)\n }\n case 'import_spec': // go: `import \"example.com/foo/util\"`\n return stripQuotes(node.childForFieldName('path')?.text)\n case 'use_declaration': // rust: `use crate::a::b::{c, d}`\n return rustUsePath(node.childForFieldName('argument')?.text)\n case 'import_declaration': // java: `import com.example.Thing;`\n return dottedToPath(node.namedChildren[0]?.text)\n case 'preproc_include':\n // path field: string_literal for \"x.hpp\" (in-repo, resolvable) or\n // system_lib_string for <cstdio> (stripQuotes yields null → dropped).\n return stripQuotes(node.childForFieldName('path')?.text)\n default:\n return null\n }\n}\n\n/**\n * Rust use paths: 'crate::a::b' is root-relative, 'super::x' is parent-module\n * ('../x'), 'self::x' is current ('./x'); everything else (std, external\n * crates) stays root-relative and simply won't resolve in-repo. Use-lists\n * ('a::b::{c,d}') contribute their base path.\n */\nfunction rustUsePath(text: string | undefined | null): string | null {\n if (!text) return null\n const base = text.split('{')[0].trim()\n if (!base) return null\n const parts = base.split('::').filter(Boolean)\n if (parts[0] === 'crate') parts.shift()\n return parts.map((p) => (p === 'super' ? '..' : p === 'self' ? '.' : p)).join('/')\n}\n\nfunction stripQuotes(text: string | undefined | null): string | null {\n if (text == null || text.length < 2) return null\n const first = text[0]\n const last = text[text.length - 1]\n if ((first === \"'\" && last === \"'\") || (first === '\"' && last === '\"')) {\n return text.slice(1, -1)\n }\n return null\n}\n\n/** 'os.path' → 'os/path' — dotted module path to repo-relative-ish path. */\nfunction dottedToPath(text: string | undefined | null): string | null {\n if (!text) return null\n return text.trim().replace(/\\./g, '/')\n}\n\n/** '.utils' → './utils', '..pkg.mod' → '../pkg/mod' — python relative import. */\nfunction pythonRelative(raw: string): string {\n const dots = raw.match(/^\\.+/)?.[0].length ?? 0\n const rest = raw.slice(dots).replace(/\\./g, '/')\n const prefix = dots === 1 ? './' : '../'.repeat(dots - 1)\n return prefix + rest\n}\n\n/** Best-effort declaration signature: `name` + parameter list, if any. */\nfunction signatureFor(id: LanguageId, node: Node): string {\n const sig = rawSignature(id, node)\n return sig.length > 80 ? `${sig.slice(0, 77)}...` : sig\n}\n\nfunction rawSignature(id: LanguageId, node: Node): string {\n const name = nameOf(id, node)\n // Field first (go method_declaration has both a receiver and a parameters\n // parameter_list — the field picks the right one), type fallback otherwise.\n const params =\n node.childForFieldName?.('parameters') ??\n node.namedChildren.find(\n (c) =>\n c?.type === 'formal_parameters' ||\n c?.type === 'method_parameters' ||\n c?.type === 'parameters' ||\n c?.type === 'parameter_list',\n )\n if (params) {\n return `${name}${collapseSpace(params.text)}`\n }\n if (id === 'cpp' || id === 'c') {\n // C/C++: the parameter list hides inside the declarator chain.\n let current = node.childForFieldName?.('declarator')\n while (current) {\n if (current.type === 'function_declarator') {\n const list = current.childForFieldName?.('parameters')\n return list ? `${name}${collapseSpace(list.text)}` : name\n }\n current = current.childForFieldName?.('declarator') ?? current.namedChildren[0] ?? null\n if (current && !current.type.includes('declarator') && current.type !== 'identifier' && current.type !== 'qualified_identifier' && current.type !== 'field_identifier') break\n }\n }\n const first = node.namedChildren[0]\n return first ? collapseSpace(first.text) : name\n}\n\n/**\n * Signatures must stay one line: repo-map rows are budgeted per line, and a\n * multi-line parameter list would both wrap the format and burn chars.\n */\nfunction collapseSpace(text: string): string {\n return text\n .replace(/\\s+/g, ' ')\n .replace(/\\( /g, '(')\n .replace(/ \\)/g, ')')\n .replace(/ ,/g, ',')\n .replace(/,\\)/g, ')')\n .trim()\n}\n\n/**\n * A variable is indexable only at module level: its declaration must sit\n * directly inside the program (or the export_statement wrapping it). Anything\n * deeper — function bodies, blocks, for-of heads — is a local with no\n * navigation value.\n */\nfunction isModuleLevelVariable(id: LanguageId, node: Node): boolean {\n if (id === 'cpp' || id === 'c') {\n // A (field_)declaration is indexable at namespace/file scope or in a\n // class body — anything inside a function body is a local.\n for (let parent = node.parent; parent; parent = parent.parent) {\n if (parent.type === 'function_definition' || parent.type === 'compound_statement') return false\n if (parent.type === 'translation_unit' || parent.type === 'declaration_list' || parent.type === 'field_declaration_list') return true\n }\n return false\n }\n const declaration = node.parent // variable_declaration | lexical_declaration\n const container = declaration?.parent // program | export_statement | …\n return container?.type === 'program' || container?.type === 'export_statement'\n}\n\n/**\n * A symbol is exported when walking up from it reaches an export_statement\n * before any function or class body — only module-level declarations count.\n * A method inside `export class` must NOT inherit the class's export, and a\n * function nested inside an exported function is not exported either.\n */\nfunction isExported(id: LanguageId, node: Node): boolean {\n if (id === 'python') {\n // Python has no export syntax: a def/class directly under the module is\n // importable, anything nested (methods, inner functions) is not a\n // module-level symbol.\n return node.parent?.type === 'module'\n }\n if (id === 'go') {\n // Go exports by capitalisation, not by keyword.\n const name = nameOf(id, node)\n return !!name && /^[A-Z]/.test(name)\n }\n if (id === 'rust') {\n // `pub` = exported; `pub(crate)` & friends are crate-local, not public.\n return node.namedChildren.some(\n (c) => c?.type === 'visibility_modifier' && c.text === 'pub',\n )\n }\n if (id === 'java') {\n // Interface members are implicitly public.\n if (node.parent?.type === 'interface_body') return true\n return node.namedChildren.some((c) => c?.type === 'modifiers' && /\\bpublic\\b/.test(c?.text ?? ''))\n }\n if (id === 'cpp' || id === 'c') {\n return cppIsExported(node)\n }\n for (let parent = node.parent; parent; parent = parent.parent) {\n if (parent.type === 'export_statement') return true\n if (parent.type === 'statement_block' || parent.type === 'class_body') return false\n if (parent.type === 'program') return false\n }\n return false\n}\n\n/**\n * C/C++ export semantics:\n * - anything under `public:` in a class body is exported; `private:`/\n * `protected:` sections are not\n * - top-level declarations are exported unless marked `static`\n * (internal-linkage). C has no access sections; C++ namespaces stay\n * transparent — a symbol under namespace X is still module-level.\n */\nfunction cppIsExported(node: Node): boolean {\n const isStatic = node.namedChildren.some(\n (c) => c?.type === 'storage_class_specifier' && c.text === 'static',\n )\n for (let parent = node.parent; parent; parent = parent.parent) {\n if (parent.type === 'field_declaration_list') {\n const body = parent\n // Struct members default to public, class members to private (C++ rule).\n const structKind = body.parent?.type === 'struct_specifier' ? 'struct' : 'class'\n let current: string | null = structKind === 'struct' ? 'public' : 'private'\n for (let up: Node | null = node; up && up.id !== body.id; up = up.parent) {\n const next = up.parent\n if (next?.type === 'field_declaration_list') {\n const siblingIndex = next.namedChildren.findIndex((c) => c?.id === up.id)\n const accessBefore = next.namedChildren\n .slice(0, siblingIndex)\n .filter((c) => c?.type === 'access_specifier')\n if (accessBefore.length > 0) {\n current = accessBefore.at(-1)!.text.replace(':', '').trim()\n }\n }\n }\n return current === 'public' && !isStatic\n }\n if (parent.type === 'translation_unit') return !isStatic\n }\n return !isStatic\n}\n\n/**\n * Language quirks the query syntax can't express:\n * - python: no distinct method node — a def directly in a class body is one\n * - go: a type_spec is a class (struct) or interface by its type child\n * - rust: function_item directly in an impl body is a method\n */\nfunction kindFor(id: LanguageId, node: Node, kind: SymbolKind): SymbolKind {\n if (id === 'python' && kind === 'function') {\n const inClassBody = node.parent?.type === 'block' && node.parent?.parent?.type === 'class_definition'\n if (inClassBody) return 'method'\n }\n if (id === 'go' && node.type === 'type_spec') {\n const type = node.childForFieldName('type')?.type\n if (type === 'struct_type') return 'class'\n if (type === 'interface_type') return 'interface'\n return 'type'\n }\n if (id === 'rust' && node.type === 'function_item') {\n const inImpl = node.parent?.type === 'declaration_list' && node.parent?.parent?.type === 'impl_item'\n if (inImpl) return 'method'\n }\n if ((id === 'cpp' || id === 'c') && (kind === 'variable' || kind === 'field')) {\n // A declaration whose declarator chain holds a function_declarator is a\n // function prototype/definition — not a data member or global.\n let current = node.childForFieldName?.('declarator')\n while (current) {\n if (current.type === 'function_declarator') {\n return node.parent?.type === 'field_declaration_list' ? 'method' : 'function'\n }\n current = current.childForFieldName?.('declarator') ?? current.namedChildren[0] ?? null\n }\n return node.type === 'field_declaration' ? 'field' : 'variable'\n }\n if ((id === 'cpp' || id === 'c') && node.type === 'function_definition') {\n // A function defined directly in a class/struct body is a method.\n if (node.parent?.type === 'field_declaration_list') return 'method'\n }\n return kind\n}\n\n/** Compile a symbol query for a code sample (used by tests). */\nexport async function parseFileToSymbols(\n filePath: string,\n repoRoot: string,\n code?: string,\n): Promise<SymbolInfo[]> {\n const lang = languageForFile(filePath)\n if (!lang) return []\n const text = code ?? (await readFile(filePath, 'utf8'))\n const rows = await extractSymbols(text, lang)\n const rel = path.relative(repoRoot, filePath).split(path.sep).join('/')\n return rows.map((r) => ({ ...r, file: rel }))\n}","/** Workspace file discovery with dir exclusions and mtime tracking. */\n\nimport { readdir, stat } from 'node:fs/promises'\nimport path from 'node:path'\nimport type { IndexOptions } from './types.js'\n\nexport const DEFAULT_EXCLUDED_DIRS = [\n 'node_modules',\n '.git',\n '.idea',\n '.vscode',\n 'dist',\n 'build',\n 'out',\n 'coverage',\n '.next',\n '.nuxt',\n '.cache',\n 'target',\n 'vendor',\n '.dsh-code-index',\n]\n\n/** Language-agnostic source extensions we index. */\nexport const SUPPORTED_EXTS = new Set([\n '.ts',\n '.tsx',\n '.mts',\n '.cts',\n '.js',\n '.jsx',\n '.mjs',\n '.cjs',\n '.py',\n '.pyi',\n '.go',\n '.rs',\n '.java',\n '.cpp',\n '.cc',\n '.cxx',\n '.c++',\n '.hpp',\n '.hxx',\n '.hh',\n '.h',\n '.ipp',\n '.tpp',\n '.inl',\n '.c',\n])\n\nexport interface ScannedFile {\n /** Absolute path on disk. */\n abs: string\n /** Repo-relative path (forward-slash). */\n rel: string\n mtimeMs: number\n}\n\n/**\n * Recursively walk `root` and return indexed files, skipping excluded dir\n * components at any depth. Uses readdir with `withFileTypes` so we never\n * stat every entry; mtime comes from a targeted stat per candidate file.\n */\nexport async function scanRepo(\n root: string,\n options: IndexOptions = {},\n): Promise<ScannedFile[]> {\n const excluded = new Set([...DEFAULT_EXCLUDED_DIRS, ...(options.excludeDirs ?? [])])\n const results: ScannedFile[] = []\n const queue: Array<[string, string]> = [[root, '']] // [absDir, relDir]\n\n while (queue.length) {\n const [absDir, relDir] = queue.pop()!\n let entries\n try {\n entries = await readdir(absDir, { withFileTypes: true })\n } catch {\n continue // unreadable dir: skip into the void\n }\n for (const entry of entries) {\n const abs = path.join(absDir, entry.name)\n const rel = relDir ? `${relDir}/${entry.name}` : entry.name\n if (entry.isDirectory()) {\n if (excluded.has(entry.name)) continue\n queue.push([abs, rel])\n } else if (entry.isFile() && SUPPORTED_EXTS.has(path.extname(entry.name).toLowerCase())) {\n try {\n const st = await stat(abs)\n results.push({ abs, rel, mtimeMs: st.mtimeMs })\n } catch {\n // race: file deleted mid-scan — ignore\n }\n }\n }\n }\n\n results.sort((a, b) => a.rel.localeCompare(b.rel))\n return results\n}","/** On-disk JSON cache for RepoIndex, keyed by repo root. */\n\nimport { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises'\nimport path from 'node:path'\nimport { createHash, randomUUID } from 'node:crypto'\nimport type { RepoIndex } from './types.js'\n\nexport const CACHE_DIR_NAME = '.dsh-code-index'\n\n/** Stable root identity for cache hashing, including Windows case aliases. */\nexport function cacheKeyForRoot(root: string): string {\n const resolved = path.resolve(root)\n return process.platform === 'win32' ? resolved.toLowerCase() : resolved\n}\n\n/** Default cache location: `<repoRoot>/.dsh-code-index/index.json`. */\nexport function defaultCachePath(root: string, cacheDir?: string): string {\n const dir = cacheDir ?? path.join(root, CACHE_DIR_NAME)\n const hash = createHash('sha1').update(cacheKeyForRoot(root)).digest('hex').slice(0, 12)\n return path.join(dir, `${hash}.json`)\n}\n\n/** Cache filename used before Windows root casing was canonicalized. */\nexport function legacyCachePath(root: string, cacheDir?: string): string {\n const dir = cacheDir ?? path.join(root, CACHE_DIR_NAME)\n const hash = createHash('sha1').update(root).digest('hex').slice(0, 12)\n return path.join(dir, `${hash}.json`)\n}\n\nexport async function loadIndex(cachePath: string): Promise<RepoIndex | null> {\n try {\n const raw = await readFile(cachePath, 'utf8')\n const parsed = JSON.parse(raw) as RepoIndex\n if (!parsed || typeof parsed.root !== 'string' || !Array.isArray(parsed.files)) return null\n return healSymbolFiles(parsed)\n } catch {\n return null // missing or corrupt cache == no cache\n }\n}\n\n/**\n * Self-heal caches written before the per-symbol file backfill (the\n * \"SymbolInfo.file is always set\" invariant). Empty `file` fields are derived\n * from the containing IndexedFile path on load, so any consumer of loadIndex\n * sees consistent rows — and the next save persists the healed form.\n */\nexport function healSymbolFiles(index: RepoIndex): RepoIndex {\n for (const file of index.files) {\n for (const symbol of file.symbols) {\n if (!symbol.file) symbol.file = file.path\n }\n }\n return index\n}\n\nexport async function saveIndex(cachePath: string, index: RepoIndex): Promise<void> {\n await mkdir(path.dirname(cachePath), { recursive: true })\n const temporaryPath = `${cachePath}.${process.pid}.${randomUUID()}.tmp`\n try {\n await writeFile(temporaryPath, JSON.stringify(index, null, 2), { encoding: 'utf8', flag: 'wx' })\n await rename(temporaryPath, cachePath)\n } finally {\n await rm(temporaryPath, { force: true })\n }\n}\n","/** Shared data model for dsh-code-index. */\n\nexport type SymbolKind =\n | 'function'\n | 'method'\n | 'class'\n | 'interface'\n | 'type'\n | 'enum'\n | 'variable'\n | 'field'\n | 'import'\n | 'module'\n\nexport interface SymbolInfo {\n /** Symbol name (identifier / type id / member name). */\n name: string\n kind: SymbolKind\n /** Repo-relative path of the containing file, always forward-slash. */\n file: string\n /** 1-based start line. */\n line: number\n /** 1-based end line (inclusive). */\n endLine: number\n /** True when the symbol is exported at module level (export .. / export default). */\n exported: boolean\n /** Short human-readable signature, e.g. `greet(name: string)` — empty when n/a. */\n signature: string\n}\n\n/** One call site: callee name, line, and the enclosing function ('' = module level). */\nexport interface CallInfo {\n /** Callee name as written (identifier, member/property, or qualified tail). */\n name: string\n /** 1-based line of the call expression. */\n line: number\n /** Enclosing function/method name, or '' for a module-level call. */\n from: string\n}\n\nexport interface IndexedFile {\n /** Repo-relative path (forward-slash). */\n path: string\n lang: string\n /** fs mtime of the source file at index time (milliseconds). */\n mtimeMs: number\n symbols: SymbolInfo[]\n /** Raw import specifiers found in this file ('./util', 'mypkg/core', …).\n * Optional because caches written before reference ranking lack it. */\n imports?: string[]\n /** Call sites found in this file (callee + line + enclosing function).\n * Optional because caches written before call-graph support lack it. */\n calls?: CallInfo[]\n}\n\nexport interface RepoIndex {\n /** Absolute source root this index describes. */\n root: string\n /** Unix ms when the index was generated. */\n generatedAt: number\n files: IndexedFile[]\n excludedDirs: string[]\n}\n\nexport function symbolCount(index: RepoIndex): number {\n return index.files.reduce((n, f) => n + f.symbols.length, 0)\n}\n\n/** Optional config consumed by the index build pipeline. */\nexport interface IndexOptions {\n /** Extra directories to exclude, appended to the defaults. */\n excludeDirs?: string[]\n /** Minimum mtime delta (ms) that forces a re-extract in refresh mode. */\n staleToleranceMs?: number\n}","/** Function-level call graph built from the cached index — pure, no IO. */\n\nimport type { RepoIndex, SymbolInfo } from './types.js'\n\n/** name -> definitions; several when same-named symbols live in different files. */\nexport function buildSymbolTable(index: RepoIndex): Map<string, SymbolInfo[]> {\n const table = new Map<string, SymbolInfo[]>()\n for (const file of index.files) {\n for (const symbol of file.symbols) {\n const list = table.get(symbol.name)\n if (list) list.push(symbol)\n else table.set(symbol.name, [symbol])\n }\n }\n for (const list of table.values()) {\n list.sort((a, b) => a.file.localeCompare(b.file) || a.line - b.line)\n }\n return table\n}\n\n/** One call site that invokes the queried symbol. */\nexport interface CallerHit {\n file: string\n line: number\n from: string\n}\n\n/** One distinct symbol the queried function calls, with its first call line. */\nexport interface CalleeHit {\n name: string\n line: number\n /** In-repo definitions matched by the callee name. */\n targets: SymbolInfo[]\n}\n\nexport interface SymbolRefs {\n /** Definitions of the queried symbol (empty when only call sites exist). */\n defs: SymbolInfo[]\n callers: CallerHit[]\n callees: CalleeHit[]\n}\n\n/** How many call sites reference each name — used to rank search hits. */\nexport function callerCounts(index: RepoIndex): Map<string, number> {\n const counts = new Map<string, number>()\n for (const file of index.files) {\n for (const call of file.calls ?? []) {\n counts.set(call.name, (counts.get(call.name) ?? 0) + 1)\n }\n }\n return counts\n}\n\n/**\n * Resolve one symbol to its callers (call sites invoking it anywhere) and its\n * callees (calls made inside the definition, attributed by the extracted\n * enclosing-function name). Name-based, so it is a best-effort view: like-named\n * symbols are reported as candidates rather than guessed apart.\n */\nexport function symbolRefs(index: RepoIndex, symbol: string, limit = 200): SymbolRefs {\n const table = buildSymbolTable(index)\n const defs = table.get(symbol) ?? []\n\n const callers: CallerHit[] = []\n const calleeFirstLine = new Map<string, number>()\n for (const file of index.files) {\n for (const call of file.calls ?? []) {\n if (call.name === symbol) {\n callers.push({ file: file.path, line: call.line, from: call.from })\n }\n if (call.from === symbol && !calleeFirstLine.has(call.name)) {\n calleeFirstLine.set(call.name, call.line)\n }\n }\n }\n\n callers.sort(\n (a, b) => a.file.localeCompare(b.file) || a.line - b.line || a.from.localeCompare(b.from),\n )\n\n const callees: CalleeHit[] = [...calleeFirstLine.entries()]\n .map(([name, line]) => ({ name, line, targets: table.get(name) ?? [] }))\n .sort((a, b) => a.line - b.line || a.name.localeCompare(b.name))\n\n return {\n defs,\n callers: callers.slice(0, limit),\n callees: callees.slice(0, limit),\n }\n}\n","/** Pure search / filter logic over a RepoIndex — unit-testable, no IO. */\n\nimport type { RepoIndex, SymbolInfo, SymbolKind } from './types.js'\nimport { callerCounts } from './refgraph.js'\n\nexport interface SymbolFilter {\n query?: string\n file?: string\n kind?: SymbolKind\n exportedOnly?: boolean\n}\n\nexport interface RankedHit extends SymbolInfo {\n /** 0..1 relevance. 1 = exact name match; lower = fuzzier. */\n score: number\n}\n\nfunction matchScore(name: string, query: string): number {\n const q = query.toLowerCase()\n const n = name.toLowerCase()\n if (n === q) return 1\n if (n.startsWith(q)) return 0.8\n if (n.includes(q)) return 0.5\n if (q.length >= 3 && isSubsequence(q, n)) return 0.3\n return 0\n}\n\n/**\n * Every query char appears in the name, in order — 'cfgldr' finds\n * 'configLoader'. Gated to 3+ chars so short queries don't match everything.\n */\nfunction isSubsequence(query: string, name: string): boolean {\n let i = 0\n for (const ch of name) {\n if (ch === query[i]) i++\n if (i === query.length) return true\n }\n return false\n}\n\n/** Filter symbols by file/kind/export, then score by name against query (if any). */\nexport function searchSymbols(\n index: RepoIndex,\n filter: SymbolFilter,\n limit = 50,\n): RankedHit[] {\n const q = (filter.query ?? '').trim()\n const filePat = filter.file?.trim().toLowerCase()\n const hits: RankedHit[] = []\n\n for (const file of index.files) {\n if (filePat && !file.path.toLowerCase().includes(filePat)) continue\n for (const sym of file.symbols) {\n if (filter.kind && sym.kind !== filter.kind) continue\n if (filter.exportedOnly && !sym.exported) continue\n const score = q ? matchScore(sym.name, q) : 0.4\n if (q && score === 0) continue\n hits.push({ ...sym, score })\n }\n }\n\n // Export boost, then relevance, then call fan-in, then stable name order.\n const refs = callerCounts(index)\n hits.sort((a, b) => {\n const ab =\n Number(b.exported) - Number(a.exported) ||\n b.score - a.score ||\n (refs.get(b.name) ?? 0) - (refs.get(a.name) ?? 0) ||\n a.name.localeCompare(b.name) ||\n a.file.localeCompare(b.file)\n return ab\n })\n return hits.slice(0, limit)\n}\n\n/** Neat one-line rendering of a hit for terminal/chat output. */\nexport function renderHit(hit: RankedHit): string {\n const exportMark = hit.exported ? 'export ' : ''\n const sig = hit.signature || hit.name\n const score = hit.score < 1 ? ` [${hit.score.toFixed(2)}]` : ''\n return `${exportMark}${hit.kind} ${sig}${score} — ${hit.file}:${hit.line}`\n}","/**\n * Bounded, ranked repo map generation — the \"aider-style\" overview the model\n * can turn to before browsing files. Pure logic, no IO.\n */\n\nimport path from 'node:path'\nimport { SUPPORTED_EXTS } from './scan.js'\nimport type { IndexedFile, RepoIndex, SymbolInfo, SymbolKind } from './types.js'\n\n/** Higher-weight symbols pull their file up the map. */\nexport const KIND_WEIGHT: Record<SymbolKind, number> = {\n class: 1.0,\n interface: 1.0,\n type: 0.8,\n function: 0.8,\n method: 0.7,\n enum: 0.9,\n variable: 0.25,\n field: 0.2,\n import: 0.05,\n module: 0.3,\n}\n\nexport interface RepoMapOptions {\n /** Max files to include (default 24). */\n topFiles?: number\n /** Max symbols per file (default 18). */\n symbolsPerFile?: number\n /** Hard cap on rendered characters (default 3200). */\n maxChars?: number\n}\n\nexport interface RepoMapEntry {\n path: string\n score: number\n symbols: Array<{ name: string; kind: SymbolKind; line: number; signature: string }>\n}\n\n/**\n * Paths that look like tests. A map led by test files reads as noise: tests\n * reference an API, they rarely explain it — and symbol density actively\n * favours them (many small functions), so they need an explicit damper.\n */\nconst TEST_PATH_RE =\n /(^|\\/)(tests?|__tests__)(\\/|$)|\\.(?:spec|test)\\.[cm]?[jt]sx?$|(^|\\/)(?:test_[^/]+\\.py|[^/]+_test\\.(?:py|go))$/\n\n/** Density-aware file score: weighted symbols minus bloat; test paths damped. */\nexport function scoreFile(file: IndexedFile): number {\n let score = 0\n for (const sym of file.symbols) {\n score += KIND_WEIGHT[sym.kind] ?? 0.3\n if (sym.exported) score += 0.3\n }\n score /= 1 + file.symbols.length * 0.04\n if (TEST_PATH_RE.test(file.path)) score *= 0.2\n return score\n}\n\n/** Rank files, take the top slice, cap per-file symbols. */\nexport function rankRepoMap(index: RepoIndex, options: RepoMapOptions = {}): RepoMapEntry[] {\n const topFiles = options.topFiles ?? 24\n const perFile = options.symbolsPerFile ?? 18\n const density = new Map<string, number>()\n for (const f of index.files) {\n if (f.symbols.length > 0) density.set(f.path, scoreFile(f))\n }\n const centrality = referencePageRank(index.files, density)\n const ranked = index.files\n .filter((f) => f.symbols.length > 0)\n .map((f) => ({\n file: f,\n score: (density.get(f.path) ?? 0) + REF_WEIGHT * (centrality.get(f.path) ?? 0),\n }))\n .sort((a, b) => b.score - a.score || a.file.path.localeCompare(b.file.path))\n .slice(0, topFiles)\n\n return ranked.map(({ file, score }) => ({\n path: file.path,\n score,\n symbols: file.symbols.slice(0, perFile).map((s) => ({\n name: s.name,\n kind: s.kind,\n line: s.line,\n signature: s.signature,\n })),\n }))\n}\n\n/** How much one unit of reference centrality is worth in map score. */\nconst REF_WEIGHT = 0.5\n\n/**\n * Count in-repo references: how many OTHER indexed files import each file.\n * Self-imports don't count; each (importer, target) pair counts once.\n */\nexport function countReferences(files: IndexedFile[]): Map<string, number> {\n const fileSet = new Set(files.map((f) => f.path))\n const counts = new Map<string, number>()\n for (const file of files) {\n const targets = new Set<string>()\n for (const spec of file.imports ?? []) {\n const target = resolveImport(spec, file.path, fileSet)\n if (target && target !== file.path) targets.add(target)\n }\n for (const target of targets) {\n counts.set(target, (counts.get(target) ?? 0) + 1)\n }\n }\n return counts\n}\n\n/** PageRank damping — the standard 0.85. */\nconst DAMPING = 0.85\n/** Stop the power iteration once total rank movement drops below this. */\nconst CONVERGENCE_TOL = 1e-6\n/** Hard cap; convergence on repo-sized graphs needs ~20-40. */\nconst MAX_ITERATIONS = 100\n\n/**\n * Personalized PageRank over the import graph: nodes are files, an edge\n * A → B means A imports B, so rank flows toward heavily-imported hubs — and\n * a hub that other hubs themselves import accumulates more than a merely\n * popular leaf, which flat in-degree counting cannot see.\n *\n * Teleport uses each file's density share instead of a uniform vector, so\n * sparsely-linked repos keep their 0.2.x ordering (with no edges the fixed\n * point IS the normalized density vector). Returns L1-normalized importance\n * mass per file.\n */\nfunction referencePageRank(files: IndexedFile[], density: Map<string, number>): Map<string, number> {\n const nodes = files.filter((f) => density.has(f.path)).map((f) => f.path)\n const n = nodes.length\n if (n === 0) return new Map()\n if (n === 1) return new Map([[nodes[0]!, 1]])\n\n const totalDensity = nodes.reduce((sum, p) => sum + (density.get(p) ?? 0), 0)\n const teleport = nodes.map((p) => (density.get(p) ?? 0) / totalDensity)\n\n const fileSet = new Set(nodes)\n const out = new Map<string, Set<string>>()\n for (const file of files) {\n if (!fileSet.has(file.path)) continue\n const targets = out.get(file.path) ?? new Set<string>()\n for (const spec of file.imports ?? []) {\n const target = resolveImport(spec, file.path, fileSet)\n if (target && target !== file.path) targets.add(target)\n }\n out.set(file.path, targets)\n }\n\n const incoming = new Map<string, Array<[fromIdx: number, weight: number]>>()\n for (const [from, targets] of out) {\n if (targets.size === 0) continue\n const weight = 1 / targets.size\n const fromIdx = nodes.indexOf(from)\n for (const target of targets) {\n const list = incoming.get(target) ?? []\n list.push([fromIdx, weight])\n incoming.set(target, list)\n }\n }\n\n let rank = teleport.slice()\n for (let iter = 0; iter < MAX_ITERATIONS; iter++) {\n let danglingMass = 0\n for (let i = 0; i < n; i++) {\n if (!out.get(nodes[i]!)?.size) danglingMass += rank[i]!\n }\n const next = new Array<number>(n)\n let delta = 0\n for (let i = 0; i < n; i++) {\n let flow = 0\n for (const [fromIdx, weight] of incoming.get(nodes[i]!) ?? []) {\n flow += rank[fromIdx]! * weight\n }\n next[i] = (1 - DAMPING) * teleport[i]! + DAMPING * (flow + danglingMass * teleport[i]!)\n delta += Math.abs(next[i]! - rank[i]!)\n }\n rank = next\n if (delta < CONVERGENCE_TOL) break\n }\n\n const result = new Map<string, number>()\n for (let i = 0; i < n; i++) result.set(nodes[i]!, rank[i]!)\n return result\n}\n\n/**\n * Resolve a raw import specifier against the indexed file set; returns the\n * repo-relative target path or null. Relative specifiers resolve against the\n * importing file; absolute ones against the repo root — with a suffix\n * fallback so Go module paths and Java package names match their in-repo\n * location without reading go.mod / package-info.\n */\nexport function resolveImport(spec: string, fromPath: string, fileSet: Set<string>): string | null {\n if (!spec) return null\n if (spec.startsWith('./') || spec.startsWith('../')) {\n const base = path.posix.normalize(path.posix.join(path.posix.dirname(fromPath), spec))\n return candidateFor(base, fileSet)\n }\n const segments = spec.split('/').filter(Boolean)\n for (let skip = 0; skip < segments.length; skip++) {\n const hit = candidateFor(segments.slice(skip).join('/'), fileSet)\n if (hit) return hit\n }\n return null\n}\n\n/** Extension and index-file candidates for a specifier base path. */\nfunction candidateFor(base: string, fileSet: Set<string>): string | null {\n // Bare path first: C/C++ includes already carry their extension\n // (\"net/socket.hpp\"), and matching the exact file beats guessing.\n if (fileSet.has(base)) return base\n for (const ext of SUPPORTED_EXTS) {\n if (fileSet.has(`${base}${ext}`)) return `${base}${ext}`\n }\n for (const ext of SUPPORTED_EXTS) {\n if (fileSet.has(`${base}/index${ext}`)) return `${base}/index${ext}`\n if (fileSet.has(`${base}/__init__${ext}`)) return `${base}/__init__${ext}`\n }\n return null\n}\n\n/** Render the ranked map as markdown, hard-truncated to maxChars. */\nexport function renderRepoMap(entries: RepoMapEntry[], options: RepoMapOptions = {}): string {\n const maxChars = options.maxChars ?? 3200\n const lines: string[] = ['# repo map']\n let totalSymbols = 0\n for (const e of entries) {\n totalSymbols += e.symbols.length\n lines.push(`## ${e.path} (${e.symbols.length})`)\n for (const s of e.symbols) {\n const label = s.signature || s.name\n lines.push(` ${s.kind} ${label} :${s.line}`)\n }\n }\n let text = lines.join('\\n')\n if (text.length > maxChars) {\n text = `${text.slice(0, maxChars)}\\n… truncated`\n }\n return totalSymbols > 0 ? text : ''\n}","/** Import-graph health checks: circular dependencies and orphan modules. */\n\nimport { resolveImport } from './repomap.js'\nimport type { RepoIndex } from './types.js'\n\nexport interface ModuleGraph {\n nodes: string[]\n edges: Map<string, Set<string>>\n}\n\n/** Nodes are indexed files; an edge A -> B means A imports B (self-edges dropped). */\nexport function buildModuleGraph(index: RepoIndex): ModuleGraph {\n const nodes = index.files.map((file) => file.path).sort((a, b) => a.localeCompare(b))\n const fileSet = new Set(nodes)\n const edges = new Map<string, Set<string>>()\n for (const file of index.files) {\n const targets = new Set<string>()\n for (const spec of file.imports ?? []) {\n const target = resolveImport(spec, file.path, fileSet)\n if (target && target !== file.path) targets.add(target)\n }\n edges.set(file.path, targets)\n }\n return { nodes, edges }\n}\n\n/** Tarjan strongly-connected components of size > 1 — i.e. import cycles. */\nexport function findCycles(index: RepoIndex): string[][] {\n const { nodes, edges } = buildModuleGraph(index)\n const discovery = new Map<string, number>()\n const low = new Map<string, number>()\n const onStack = new Set<string>()\n const stack: string[] = []\n const components: string[][] = []\n let counter = 0\n\n const visit = (node: string): void => {\n discovery.set(node, counter)\n low.set(node, counter)\n counter++\n stack.push(node)\n onStack.add(node)\n\n for (const next of edges.get(node) ?? []) {\n if (!discovery.has(next)) {\n visit(next)\n low.set(node, Math.min(low.get(node)!, low.get(next)!))\n } else if (onStack.has(next)) {\n low.set(node, Math.min(low.get(node)!, discovery.get(next)!))\n }\n }\n\n if (low.get(node) === discovery.get(node)) {\n const component: string[] = []\n for (;;) {\n const member = stack.pop()!\n onStack.delete(member)\n component.push(member)\n if (member === node) break\n }\n if (component.length > 1) components.push(component.sort())\n }\n }\n\n for (const node of nodes) {\n if (!discovery.has(node)) visit(node)\n }\n components.sort((a, b) => a[0]!.localeCompare(b[0]!))\n return components\n}\n\nconst ENTRY_RE =\n /(^|\\/)(index|main|cli|app|server|mod|lib|__init__)\\.[A-Za-z0-9]+$|(^|\\/)(bin|cmd|scripts)\\/|\\.config\\.[A-Za-z0-9]+$/\nconst TEST_RE =\n /(^|\\/)(tests?|__tests__)(\\/|$)|\\.(?:spec|test)\\.[cm]?[jt]sx?$|(^|\\/)(?:test_[^/]+\\.py|[^/]+_test\\.(?:py|go))$/\n\n/**\n * Symbol-bearing files that neither import nor are imported by any other file,\n * excluding conventional entry points and tests (which are legitimately\n * unreferenced). A cheap, low-false-positive stand-in for dead-code detection.\n */\nexport function findOrphanModules(index: RepoIndex): string[] {\n const { nodes, edges } = buildModuleGraph(index)\n const incoming = new Map<string, number>()\n for (const targets of edges.values()) {\n for (const target of targets) incoming.set(target, (incoming.get(target) ?? 0) + 1)\n }\n const withSymbols = new Set(\n index.files.filter((file) => file.symbols.length > 0).map((file) => file.path),\n )\n return nodes.filter(\n (path) =>\n withSymbols.has(path) &&\n (incoming.get(path) ?? 0) === 0 &&\n (edges.get(path)?.size ?? 0) === 0 &&\n !ENTRY_RE.test(path) &&\n !TEST_RE.test(path),\n )\n}\n","/** Model-visible tools: code_index, code_symbols, code_search. */\n\nimport { defineTool, type JsonValue } from '@deepseek-ai/dsh-tools'\nimport path from 'node:path'\nimport { buildIndexWithCache, findRepoRoot } from './buildIndex.js'\nimport { renderHit, searchSymbols } from './search.js'\nimport { rankRepoMap, renderRepoMap } from './repomap.js'\nimport { symbolRefs } from './refgraph.js'\nimport { findCycles, findOrphanModules } from './health.js'\nimport { getConfig, indexOptions } from './config.js'\nimport { cacheKeyForRoot } from './store.js'\nimport type { RepoIndex } from './types.js'\n\n/** Minimal structural types for the harness surfaces we touch. */\ninterface ToolCwdContext {\n agent?: {\n session?: { header?: { cwd?: string } }\n }\n}\ntype ToolRunExec = ToolCwdContext & { signal?: AbortSignal }\n\ninterface TextBlock {\n type: 'text'\n text: string\n}\n\nexport interface IndexCache {\n get(root: string, force?: boolean): Promise<RepoIndex>\n invalidate(): void\n}\n\n/** Retain completed indexes briefly while still coalescing concurrent refreshes. */\nexport function createIndexCache(\n load: (root: string) => Promise<RepoIndex>,\n ttlMs = 60_000,\n now: () => number = Date.now,\n): IndexCache {\n interface CompletedEntry {\n index: RepoIndex\n at: number\n epoch: number\n }\n interface LoadEntry {\n promise: Promise<RepoIndex>\n epoch: number\n }\n\n const completed = new Map<string, CompletedEntry>()\n const inFlight = new Map<string, LoadEntry>()\n let epoch = 0\n\n function startLoad(key: string, root: string, previous?: Promise<RepoIndex>): Promise<RepoIndex> {\n const loadEpoch = epoch\n const begin = previous\n ? previous.catch(() => undefined).then(() => load(root))\n : load(root)\n const promise = begin\n .then((index) => {\n if (loadEpoch === epoch) {\n completed.delete(key)\n completed.set(key, { index, at: now(), epoch: loadEpoch })\n while (completed.size > 16) completed.delete(completed.keys().next().value!)\n }\n return index\n })\n .finally(() => {\n if (inFlight.get(key)?.promise === promise) inFlight.delete(key)\n })\n inFlight.set(key, { promise, epoch: loadEpoch })\n return promise\n }\n\n return {\n get(root, force = false) {\n const resolvedRoot = path.resolve(root)\n const key = cacheKeyForRoot(resolvedRoot)\n const running = inFlight.get(key)\n if (running) {\n if (running.epoch === epoch && !force) return running.promise\n return startLoad(key, resolvedRoot, running.promise)\n }\n\n if (!force) {\n const cached = completed.get(key)\n if (cached && cached.epoch === epoch && now() - cached.at < ttlMs) {\n completed.delete(key)\n completed.set(key, cached)\n return Promise.resolve(cached.index)\n }\n if (cached) completed.delete(key)\n } else {\n completed.delete(key)\n }\n return startLoad(key, resolvedRoot)\n },\n invalidate() {\n epoch++\n completed.clear()\n },\n }\n}\n\nconst indexCache = createIndexCache((root) => buildIndexWithCache(root, indexOptions()))\n\nexport function getIndex(root: string, force = false): Promise<RepoIndex> {\n return indexCache.get(root, force)\n}\n\nexport function invalidateIndexCache(): void {\n indexCache.invalidate()\n}\n\nasync function resolveRoot(arg: string | undefined, exec: ToolRunExec): Promise<string> {\n const cwd = exec.agent?.session?.header?.cwd\n const base = arg ?? cwd ?? process.cwd()\n const root = await findRepoRoot(base)\n if (!root) throw new Error(`no git repository found from ${path.resolve(base)}`)\n return root\n}\n\n/** Group hit rows into the search card's matches shape for UI replay. */\nfunction hitsToSearchMeta(hits: JsonValue[]): JsonValue {\n const byFile = new Map<string, Array<{ lineNumber: number; line: string }>>()\n for (const raw of hits) {\n const hit = raw as unknown as {\n file?: string\n line?: number\n kind?: string\n name?: string\n signature?: string\n }\n if (!hit.file || typeof hit.line !== 'number') continue\n const label = `${hit.kind ?? ''} ${hit.signature || hit.name || ''}`.trim()\n const list = byFile.get(hit.file) ?? []\n list.push({ lineNumber: hit.line, line: label })\n byFile.set(hit.file, list)\n }\n return {\n shape: 'matches',\n files: [...byFile.entries()].map(([path, matches]) => ({ path, matches })),\n truncated: false,\n total: hits.length,\n }\n}\n\n/** Narrow persisted presentation metadata back into a completed search card. */\nfunction searchCardFromMeta(meta: JsonValue | undefined):\n | {\n card: 'search'\n shape: 'matches'\n files: Array<{ path: string; matches: Array<{ lineNumber: number; line: string }> }>\n truncated: boolean\n total: number\n }\n | undefined {\n if (!meta || typeof meta !== 'object' || Array.isArray(meta)) return undefined\n const record = meta as Record<string, JsonValue>\n if (record.shape !== 'matches' || !Array.isArray(record.files)) return undefined\n const files = record.files.filter(\n (entry): entry is { path: string; matches: Array<{ lineNumber: number; line: string }> } =>\n typeof entry === 'object' && entry !== null && !Array.isArray(entry),\n )\n return {\n card: 'search',\n shape: 'matches',\n files,\n truncated: record.truncated === true,\n total: typeof record.total === 'number' ? record.total : 0,\n }\n}\n\nexport const tools = [\n defineTool({\n name: 'code_index',\n description:\n 'Manage the semantic repo index: status or (re)build it for the current workspace. Auto-builds the first time it is queried. Returns file/symbol counts and the index location.',\n parameters: {\n action: {\n type: 'string',\n enum: ['status', 'build'],\n description: '\"status\" (default) reports without forcing a rebuild; \"build\" forces a fresh scan.',\n },\n repoRoot: {\n type: 'string',\n description:\n 'Optional absolute repo path. Defaults to the workspace root of the current session.',\n },\n },\n output: {\n schema: { type: 'string' },\n render: (_args, value: string): TextBlock[] => [{ type: 'text', text: value }],\n },\n async execute(args: { action?: string; repoRoot?: string }, exec: ToolRunExec): Promise<string> {\n try {\n const root = await resolveRoot(args.repoRoot, exec)\n const index = await getIndex(root, args.action === 'build')\n const total = index.files.reduce((n, f) => n + f.symbols.length, 0)\n const langs = new Set(index.files.map((f) => f.lang))\n return [\n `repo: ${root}`,\n `files indexed: ${index.files.length}`,\n `symbols: ${total}`,\n `languages: ${[...langs].join(', ')}`,\n index.files.length === 0 ? 'no supported files found' : 'index up to date',\n ].join('\\n')\n } catch (error) {\n return `code_index: ${(error as Error).message ?? String(error)}`\n }\n },\n }),\n\n defineTool({\n name: 'code_symbols',\n description:\n 'List symbols (functions, classes, interfaces, types, methods, variables) in the current repo. Filter by name substring, file path substring, or symbol kind. Results are exported-first, alphabetically ordered.',\n parameters: {\n query: {\n type: 'string',\n description: 'Substring of the symbol name to match (case-insensitive). Omit to list all.',\n },\n file: {\n type: 'string',\n description: 'Substring of the repo-relative file path to match, e.g. \"src/core\".',\n },\n kind: {\n type: 'string',\n enum: ['function', 'method', 'class', 'interface', 'type', 'enum', 'variable', 'field'],\n description: 'Only return symbols of this kind.',\n },\n exportedOnly: {\n type: 'boolean',\n description: 'Only exported (module-level public) symbols.',\n },\n limit: {\n type: 'number',\n description: 'Max rows (default 50).',\n },\n repoRoot: {\n type: 'string',\n description: 'Optional absolute repo path; defaults to the session workspace root.',\n },\n },\n output: {\n schema: { type: 'array' },\n render: (_args, value: JsonValue[]): TextBlock[] =>\n value.map((v) => ({\n type: 'text' as const,\n text: renderHit(v as unknown as Parameters<typeof renderHit>[0]),\n })),\n presentationMeta: (_args, value) => hitsToSearchMeta(value),\n },\n presentCall: (args) => ({\n card: 'generic',\n title: args.kind ? `List ${args.kind} symbols` : 'List symbols',\n kind: 'search',\n rawInput: { query: args.query, file: args.file, kind: args.kind },\n }),\n presentResult: (_args, result) => searchCardFromMeta(result.meta),\n async execute(\n args: {\n query?: string\n file?: string\n kind?: 'function' | 'method' | 'class' | 'interface' | 'type' | 'enum' | 'variable' | 'field'\n exportedOnly?: boolean\n limit?: number\n repoRoot?: string\n },\n exec: ToolRunExec,\n ): Promise<JsonValue[]> {\n const root = await resolveRoot(args.repoRoot, exec)\n const index = await getIndex(root)\n const hits = searchSymbols(\n index,\n { query: args.query, file: args.file, kind: args.kind, exportedOnly: args.exportedOnly },\n args.limit ?? 50,\n )\n return hits as unknown as JsonValue[]\n },\n }),\n\n defineTool({\n name: 'code_search',\n description:\n 'Ranked symbol search over the repo index: exact > prefix > substring name matches, exported symbols first. Results carry a relevance score and file:line, so the model can locate definitions quickly.',\n parameters: {\n query: {\n type: 'string',\n required: true,\n description: 'Symbol name (or fragment) to find.',\n },\n limit: {\n type: 'number',\n description: 'Max hits (default 20).',\n },\n repoRoot: {\n type: 'string',\n description: 'Optional absolute repo path; defaults to the session workspace root.',\n },\n },\n output: {\n schema: { type: 'array' },\n render: (_args, value: JsonValue[]): TextBlock[] =>\n value.map((v) => ({\n type: 'text' as const,\n text: renderHit(v as unknown as Parameters<typeof renderHit>[0]),\n })),\n presentationMeta: (_args, value) => hitsToSearchMeta(value),\n },\n presentCall: (args) => ({\n card: 'generic',\n title: `Search \"${args.query}\"`,\n kind: 'search',\n rawInput: { query: args.query },\n }),\n presentResult: (_args, result) => searchCardFromMeta(result.meta),\n async execute(\n args: { query: string; limit?: number; repoRoot?: string },\n exec: ToolRunExec,\n ): Promise<JsonValue[]> {\n const root = await resolveRoot(args.repoRoot, exec)\n const index = await getIndex(root)\n const hits = searchSymbols(index, { query: args.query }, args.limit ?? 20)\n return hits as unknown as JsonValue[]\n },\n }),\n\n defineTool({\n name: 'code_map',\n description:\n 'Return a bounded, ranked map of the current repo (top files by symbol density, with their key symbols and lines). The model can call this once per session to build an internal model of the codebase before browsing files.',\n parameters: {\n repoRoot: {\n type: 'string',\n description: 'Optional absolute repo path; defaults to the session workspace root.',\n },\n },\n output: {\n schema: { type: 'string' },\n render: (_args, value: string): TextBlock[] => [{ type: 'text', text: value }],\n },\n async execute(args: { repoRoot?: string }, exec: ToolRunExec): Promise<string> {\n try {\n const root = await resolveRoot(args.repoRoot, exec)\n const index = await getIndex(root)\n const cfg = getConfig()\n const map = renderRepoMap(\n rankRepoMap(index, { topFiles: cfg.mapTopFiles }),\n { maxChars: cfg.mapMaxChars },\n )\n if (!map) return 'no indexable symbols found in this repo'\n return map\n } catch (error) {\n return `code_index: ${(error as Error).message ?? String(error)}`\n }\n },\n }),\n\n defineTool({\n name: 'code_refs',\n description:\n 'Trace a symbol through the call graph: who calls it (callers) and what it calls (callees), resolved to in-repo definitions with file:line. Complements code_search — search finds a definition, code_refs shows how it is used. Resolution is name-based, so like-named symbols are reported as candidate definitions.',\n parameters: {\n symbol: {\n type: 'string',\n required: true,\n description: 'Symbol name to trace (case-sensitive).',\n },\n direction: {\n type: 'string',\n enum: ['callers', 'callees', 'both'],\n description: 'Which side of the call graph to return (default \"both\").',\n },\n limit: {\n type: 'number',\n description: 'Max rows per side (default 50).',\n },\n repoRoot: {\n type: 'string',\n description: 'Optional absolute repo path; defaults to the session workspace root.',\n },\n },\n output: {\n schema: { type: 'string' },\n render: (_args, value: string): TextBlock[] => [{ type: 'text', text: value }],\n },\n presentCall: (args) => ({\n card: 'generic',\n title: `Refs ${args.symbol}`,\n kind: 'search',\n rawInput: { symbol: args.symbol, direction: args.direction },\n }),\n async execute(\n args: { symbol: string; direction?: string; limit?: number; repoRoot?: string },\n exec: ToolRunExec,\n ): Promise<string> {\n try {\n const root = await resolveRoot(args.repoRoot, exec)\n const index = await getIndex(root)\n const refs = symbolRefs(index, args.symbol, args.limit ?? 50)\n const direction = args.direction ?? 'both'\n const lines: string[] = []\n\n if (refs.defs.length > 0) {\n lines.push('definitions:')\n for (const def of refs.defs) {\n lines.push(` ${def.kind} ${def.signature || def.name} — ${def.file}:${def.line}`)\n }\n } else {\n lines.push(`no definition of \"${args.symbol}\" in this repo`)\n }\n\n if (direction === 'callers' || direction === 'both') {\n lines.push('', `callers (${refs.callers.length}):`)\n if (refs.callers.length === 0) lines.push(' (none)')\n for (const caller of refs.callers) {\n lines.push(` ${caller.file}:${caller.line}${caller.from ? ` in ${caller.from}` : ''}`)\n }\n }\n\n if (direction === 'callees' || direction === 'both') {\n lines.push('', `callees (${refs.callees.length}):`)\n if (refs.callees.length === 0) lines.push(' (none)')\n for (const callee of refs.callees) {\n const target = callee.targets[0]\n lines.push(\n ` ${callee.name} :${callee.line}${target ? ` → ${target.file}:${target.line}` : ' (external)'}`,\n )\n }\n }\n\n return lines.join('\\n')\n } catch (error) {\n return `code_refs: ${(error as Error).message ?? String(error)}`\n }\n },\n }),\n\n defineTool({\n name: 'code_health',\n description:\n 'Report structural health from the import graph: circular dependencies (import cycles) and orphan modules (symbol-bearing files that nothing imports and that import nothing, excluding entry points and tests).',\n parameters: {\n limit: {\n type: 'number',\n description: 'Max cycles and orphan rows to list (default 50).',\n },\n repoRoot: {\n type: 'string',\n description: 'Optional absolute repo path; defaults to the session workspace root.',\n },\n },\n output: {\n schema: { type: 'string' },\n render: (_args, value: string): TextBlock[] => [{ type: 'text', text: value }],\n },\n presentCall: () => ({ card: 'generic', title: 'Code health', kind: 'read' }),\n async execute(args: { limit?: number; repoRoot?: string }, exec: ToolRunExec): Promise<string> {\n try {\n const root = await resolveRoot(args.repoRoot, exec)\n const index = await getIndex(root)\n const limit = args.limit ?? 50\n const cycles = findCycles(index)\n const orphans = findOrphanModules(index)\n\n const lines = [`repo health — ${index.files.length} files`]\n lines.push('', `circular dependencies (${cycles.length}):`)\n if (cycles.length === 0) lines.push(' (none)')\n for (const cycle of cycles.slice(0, limit)) lines.push(` ${cycle.join(' → ')}`)\n\n lines.push('', `orphan modules (${orphans.length}):`)\n if (orphans.length === 0) lines.push(' (none)')\n for (const orphan of orphans.slice(0, limit)) lines.push(` ${orphan}`)\n\n return lines.join('\\n')\n } catch (error) {\n return `code_health: ${(error as Error).message ?? String(error)}`\n }\n },\n }),\n]\n","/** Plugin configuration: merged once at apply time, read wherever needed. */\n\nimport type { IndexOptions } from './types.js'\n\nexport interface PluginConfig {\n /** Extra directories to exclude from indexing (appended to defaults). */\n excludeDirs?: string[]\n /** Max files in the ranked repo map (code_map / auto section). */\n mapTopFiles?: number\n /** Hard char cap for rendered maps. */\n mapMaxChars?: number\n /** Refresh interval for the auto-injected map (ms, min 1000). */\n mapTtlMs?: number\n /** Set false to disable the auto-injected system section. */\n autoInject?: boolean\n /** Register the code_health tool (circles / orphans). Off by default. */\n codeHealth?: boolean\n}\n\ninterface EffectiveConfig {\n excludeDirs: string[]\n mapTopFiles: number\n mapMaxChars: number\n mapTtlMs: number\n autoInject: boolean\n codeHealth: boolean\n}\n\nconst DEFAULTS: EffectiveConfig = {\n excludeDirs: [],\n mapTopFiles: 24,\n mapMaxChars: 3200,\n mapTtlMs: 60_000,\n autoInject: true,\n codeHealth: false,\n}\n\nconst state: { current: EffectiveConfig } = { current: { ...DEFAULTS } }\n\n/** Merge a plugin-provided partial config over the defaults (idempotent). */\nexport function applyConfig(partial?: PluginConfig): void {\n state.current = {\n ...DEFAULTS,\n ...(partial ?? {}),\n excludeDirs: [...DEFAULTS.excludeDirs, ...(partial?.excludeDirs ?? [])],\n }\n // Coerce obviously wrong inputs.\n if (!Number.isFinite(state.current.mapTopFiles) || state.current.mapTopFiles < 1) {\n state.current.mapTopFiles = DEFAULTS.mapTopFiles\n }\n if (!Number.isFinite(state.current.mapMaxChars) || state.current.mapMaxChars < 200) {\n state.current.mapMaxChars = DEFAULTS.mapMaxChars\n }\n if (!Number.isFinite(state.current.mapTtlMs) || state.current.mapTtlMs < 1_000) {\n state.current.mapTtlMs = DEFAULTS.mapTtlMs\n }\n}\n\nexport function getConfig(): Readonly<EffectiveConfig> {\n return state.current\n}\n\n/** Map the effective config onto the index pipeline options. */\nexport function indexOptions(): IndexOptions {\n return { excludeDirs: state.current.excludeDirs }\n}","/** Host-side settings namespace for the plugin's user-editable config. */\n\nimport Schema from '@deepseek-ai/schemastery'\nimport type { PluginConfig } from './config.js'\nexport const SETTINGS_NAMESPACE = 'code-index'\n\nexport const settingsSchema = Schema.object({\n excludeDirs: Schema.array(Schema.string()).default([]),\n mapTopFiles: Schema.number().default(24),\n mapMaxChars: Schema.number().default(3200),\n mapTtlMs: Schema.number().default(60_000),\n autoInject: Schema.boolean().default(true),\n codeHealth: Schema.boolean().default(false),\n})\n\ninterface SettingsScopeLike<T> {\n get(): T\n watch(callback: (next: T, prev: T) => void | Promise<void>): () => void\n}\n\ninterface SettingsServiceLike {\n register<T>(ns: string, schema: unknown, options?: { base?: Partial<T> }): SettingsScopeLike<T>\n}\n\n/**\n * Register the `code-index` settings namespace when a settings provider is\n * mounted, and mirror every resolved change into the plugin's live config.\n * Absent provider = the composed config stands, exactly as before.\n */\nexport function registerSettings(\n getService: (name: string) => unknown,\n pluginConfig: PluginConfig | undefined,\n onResolved: (config: PluginConfig) => void,\n): void {\n const service = getService('settings') as SettingsServiceLike | undefined\n if (!service) return\n const scope = service.register<PluginConfig>(SETTINGS_NAMESPACE, settingsSchema, {\n base: pluginConfig ?? {},\n })\n onResolved(scope.get())\n scope.watch((next) => {\n onResolved(next)\n })\n}\n","/**\n * dsh-code-index — DeepSeek Harness bundle entry.\n *\n * Registers five model-visible tools (code_index / code_symbols /\n * code_search / code_map / code_refs) plus an opt-in code_health\n * (config.codeHealth) backed by a tree-sitter symbol + call-graph index,\n * and injects a bounded auto-updating repo map for the default workspace\n * into the system prompt.\n */\n\ntype Disposer = void | (() => void)\n\n/** Minimal structural Context; the real @deepseek-ai/cordis type is a\n * runtime dependency we intentionally do not import in the bundle entry. */\ninterface MinimalContext {\n effect(fn: () => Disposer): void\n tools: { register(t: unknown): () => void }\n get?(name: string): unknown\n inject?(deps: string[], run: (ctx: MinimalContext) => void): unknown\n systemPrompt: {\n section(section: {\n name: string\n order: number\n text: string | ((context: unknown) => string)\n }): () => void\n }\n}\n\nexport const name = 'dsh-code-index'\n\n// Public API surface (consumable by other bundles / tests).\nexport { buildIndex, buildIndexWithCache, findRepoRoot } from './buildIndex.js'\nexport { extractSymbols, extractAll, languageForFile, parseFileToSymbols } from './extract.js'\nexport { scanRepo, DEFAULT_EXCLUDED_DIRS, SUPPORTED_EXTS } from './scan.js'\nexport { loadIndex, saveIndex, defaultCachePath, CACHE_DIR_NAME } from './store.js'\nexport { symbolCount } from './types.js'\nexport type { RepoIndex, IndexedFile, SymbolInfo, SymbolKind, IndexOptions } from './types.js'\nexport { searchSymbols, renderHit } from './search.js'\nexport { rankRepoMap, renderRepoMap, scoreFile } from './repomap.js'\nexport { symbolRefs, buildSymbolTable, callerCounts } from './refgraph.js'\nexport { findCycles, findOrphanModules, buildModuleGraph } from './health.js'\nexport { tools } from './tools.js'\n\nimport { getIndex, invalidateIndexCache, tools } from './tools.js'\nimport { findRepoRoot } from './buildIndex.js'\nimport { rankRepoMap, renderRepoMap } from './repomap.js'\nimport { symbolCount } from './types.js'\nimport { applyConfig, getConfig, type PluginConfig } from './config.js'\nimport { registerSettings } from './settings.js'\n\nexport const inject = ['tools', 'systemPrompt'] as const\n\nexport function apply(ctx: MinimalContext, pluginConfig?: PluginConfig) {\n applyConfig(pluginConfig)\n invalidateIndexCache()\n ctx.effect(() => {\n const disposers: Array<() => void> = []\n console.log('[dsh-code-index] plugin loaded')\n\n // User-editable settings resolve over the composed plugin row; when a\n // settings provider is mounted, every committed change reconfigures live.\n // The provider initializes asynchronously, so wait for the service rather\n // than reading it once at load (which can precede its availability).\n if (ctx.inject) {\n ctx.inject(['settings'], (settingsCtx) => {\n registerSettings(\n (name) => settingsCtx.get!(name),\n pluginConfig,\n (resolved) => applyConfig(resolved),\n )\n })\n }\n\n for (const tool of tools) {\n if (tool.name === 'code_health' && !getConfig().codeHealth) continue\n disposers.push(ctx.tools.register(tool))\n console.log(`[dsh-code-index] registered tool: ${tool.name}`)\n }\n\n // Auto-inject a bounded repo map for the DEFAULT workspace (the dsh\n // launch directory, per the harness docs). Multi-workspace web sessions\n // should rely on the `code_map` tool, which resolves the per-session cwd.\n let cached: { root: string; at: number; text: string } | null = null\n\n async function warmMap(): Promise<void> {\n const now = Date.now()\n const cfg = getConfig()\n try {\n const root = await findRepoRoot(process.cwd())\n if (!root) {\n cached = { root: '', at: now, text: '' }\n return\n }\n const index = await getIndex(root)\n const text = renderRepoMap(\n rankRepoMap(index, { topFiles: cfg.mapTopFiles }),\n { maxChars: cfg.mapMaxChars },\n )\n const stats = symbolCount(index)\n cached = {\n root: index.root,\n at: Date.now(),\n text: text ? `${text}\\n\\n(summary: ${index.files.length} files, ${stats} symbols)` : '',\n }\n } catch {\n cached = { root: '', at: now, text: '' } // never let injection fail the boot\n }\n }\n\n // Warm eagerly at load so the first assembly already has the map.\n void warmMap()\n\n if (getConfig().autoInject) {\n disposers.push(ctx.systemPrompt.section({\n name: 'code-index:repo-map',\n order: 60, // before tool guidance (100–199), after persona (0)\n text: () => {\n const now = Date.now()\n if (cached && now - cached.at < getConfig().mapTtlMs) return cached.text\n void warmMap()\n return cached?.text ?? ''\n },\n }))\n }\n\n return () => {\n const errors: unknown[] = []\n for (const dispose of disposers.reverse()) {\n try {\n dispose()\n } catch (error) {\n errors.push(error)\n }\n }\n console.log('[dsh-code-index] plugin unloaded')\n if (errors.length > 0) throw new AggregateError(errors, 'failed to unload dsh-code-index')\n }\n })\n}\n"],"mappings":";AAEA,SAAS,YAAAA,WAAU,QAAAC,aAAY;AAC/B,OAAOC,WAAU;;;ACQjB,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAC9B,OAAO,UAAU;AACjB,SAAoB,UAAU,QAAQ,aAAa;AAGnD,IAAMC,WAAU,cAAc,YAAY,GAAG;AAe7C,IAAM,WAAW,KAAK,QAAQA,SAAQ,QAAQ,mDAAmD,CAAC;AAElG,IAAM,gBAA4C;AAAA,EAChD,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,MAAM;AAAA,EACN,KAAK;AAAA,EACL,GAAG;AACL;AAEA,IAAM,cAA0C;AAAA,EAC9C,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,OAAO;AAAA,EACP,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,MAAM;AACR;AAEO,SAAS,gBAAgB,UAAqC;AACnE,QAAM,MAAM,KAAK,QAAQ,QAAQ,EAAE,YAAY;AAC/C,SAAO,YAAY,GAAG,KAAK;AAC7B;AASA,IAAM,UAAsC;AAAA,EAC1C,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaZ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MACF,QAAQ;AACN,iBAAS,EAAE,MAAM,IAAI,IAAI,KAAK,MAAM,GAAG;AAAA,MACzC;AAAA,IACF;AAGA,SAAK,QAAQ;AAEb,QAAI,UAAU,EAAE,YAAY;AAC1B,gBAAU,KAAK,IAAI,aAAa,QAAQ;AAAA,QACtC,MAAM;AAAA,QACN,OAAO;AAAA;AAAA,QACP,MAAM,MAAM;AACV,gBAAM,MAAM,KAAK,IAAI;AACrB,cAAI,UAAU,MAAM,OAAO,KAAK,UAAU,EAAE,SAAU,QAAO,OAAO;AACpE,eAAK,QAAQ;AACb,iBAAO,QAAQ,QAAQ;AAAA,QACzB;AAAA,MACF,CAAC,CAAC;AAAA,IACJ;AAEA,WAAO,MAAM;AACX,YAAM,SAAoB,CAAC;AAC3B,iBAAW,WAAW,UAAU,QAAQ,GAAG;AACzC,YAAI;AACF,kBAAQ;AAAA,QACV,SAAS,OAAO;AACd,iBAAO,KAAK,KAAK;AAAA,QACnB;AAAA,MACF;AACA,cAAQ,IAAI,kCAAkC;AAC9C,UAAI,OAAO,SAAS,EAAG,OAAM,IAAI,eAAe,QAAQ,iCAAiC;AAAA,IAC3F;AAAA,EACF,CAAC;AACH;","names":["readFile","stat","path","require","name","seen","path","readFile","path","readFile","path","stat","name","name","path","path","path","path","path","name"]}