Understand any codebase instantly. System intelligence for codebases, built for humans and AI.
TypeScript aiai-memoryclaude-codeclicode-analysiscode-mappingcode-memorycodebase-understandingcodexdeveloper-toolsllmopenclawpersistent-memoryprogram-analysissoftware-architecturesystem-intelligencesystem-mapping
Markdown & TOML Parsing Support (#147)
josephismikhailce8b5bf14dbe
diff --git a/core-ingestion/src/__tests__/queries.markdown.test.ts b/core-ingestion/src/__tests__/queries.markdown.test.tsnew file mode 100644index 00000000..158dbb7e--- /dev/null+++ b/core-ingestion/src/__tests__/queries.markdown.test.ts@@ -0,0 +1,348 @@+import { describe, expect, it } from 'vitest';++import { parseFile } from '../index.js';+import { languageFromPath, SupportedLanguages } from '../languages.js';++describe('Markdown parsing', () => {+ it('recognizes .md and .markdown extensions', () => {+ expect(languageFromPath('/repo/README.md')).toBe(SupportedLanguages.Markdown);+ expect(languageFromPath('/repo/guide.markdown')).toBe(SupportedLanguages.Markdown);+ });++ it('parses a single top-level heading', () => {+ const result = parseFile('/repo/README.md', '# Getting Started\n\nSome text here.');++ expect(result).not.toBeNull();+ expect(result!.language).toBe(SupportedLanguages.Markdown);+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'Getting Started',+ kind: 'heading',+ language: SupportedLanguages.Markdown,+ container: undefined,+ }));+ expect(result!.relationships).toContainEqual({+ srcName: 'README.md',+ dstName: 'Getting Started',+ predicate: 'CONTAINS',+ });+ });++ it('nests h2 headings under the nearest h1', () => {+ const result = parseFile(+ '/repo/README.md',+ ['# Title', '## Installation', '## Usage'].join('\n'),+ );++ expect(result).not.toBeNull();+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'Installation',+ kind: 'heading',+ container: 'Title',+ }));+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'Usage',+ kind: 'heading',+ container: 'Title',+ }));+ expect(result!.relationships).toContainEqual({+ srcName: 'Title',+ dstName: 'Installation',+ predicate: 'CONTAINS',+ });+ });++ it('nests h3 under h2, not h1', () => {+ const result = parseFile(+ '/repo/docs.md',+ ['# Guide', '## Setup', '### Prerequisites'].join('\n'),+ );++ expect(result).not.toBeNull();+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'Prerequisites',+ kind: 'heading',+ container: 'Setup',+ }));+ expect(result!.relationships).toContainEqual({+ srcName: 'Setup',+ dstName: 'Prerequisites',+ predicate: 'CONTAINS',+ });+ });++ it('resets heading scope when a higher-level heading appears', () => {+ const result = parseFile(+ '/repo/docs.md',+ ['# Part One', '## Chapter A', '# Part Two', '## Chapter B'].join('\n'),+ );++ expect(result).not.toBeNull();+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'Chapter A',+ container: 'Part One',+ }));+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'Chapter B',+ container: 'Part Two',+ }));+ });++ it('emits section chunks for each heading', () => {+ const result = parseFile(+ '/repo/README.md',+ ['# Title', 'intro text', '## Install', 'install steps'].join('\n'),+ );++ expect(result).not.toBeNull();+ expect(result!.chunks).toContainEqual(expect.objectContaining({+ name: 'Title',+ chunkKind: 'section',+ contentHash: expect.stringMatching(/^[0-9a-f]{64}$/),+ }));+ expect(result!.chunks).toContainEqual(expect.objectContaining({+ name: 'Install',+ chunkKind: 'section',+ }));+ });++ it('parent section spans full subtree including nested headings', () => {+ // H1 section should extend to EOF (no sibling H1), spanning all 4 lines.+ // H2 section should extend to EOF as well (no next H2 or H1 after it).+ const source = ['# Title', 'intro text', '## Install', 'install steps'].join('\n');+ const result = parseFile('/repo/README.md', source);++ expect(result).not.toBeNull();+ const titleSection = result!.chunks.find(c => c.name === 'Title' && c.chunkKind === 'section');+ const installSection = result!.chunks.find(c => c.name === 'Install' && c.chunkKind === 'section');++ expect(titleSection).toBeDefined();+ expect(installSection).toBeDefined();++ // Title (H1) section must span to end of file — it has no sibling H1 after it+ expect(titleSection!.lineEnd).toBe(4);+ // Install (H2) section spans to end of file+ expect(installSection!.lineEnd).toBe(4);++ // Title section must start before Install section+ expect(titleSection!.lineStart).toBeLessThan(installSection!.lineStart);+ // Title section must end no earlier than Install section+ expect(titleSection!.lineEnd).toBeGreaterThanOrEqual(installSection!.lineEnd);+ });++ it('parses YAML frontmatter', () => {+ const result = parseFile(+ '/repo/post.md',+ ['---', 'title: Hello', 'date: 2024-01-01', '---', '# Content'].join('\n'),+ );++ expect(result).not.toBeNull();+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'frontmatter',+ kind: 'frontmatter',+ }));+ expect(result!.chunks).toContainEqual(expect.objectContaining({+ name: 'frontmatter',+ chunkKind: 'frontmatter',+ }));+ expect(result!.relationships).toContainEqual({+ srcName: 'post.md',+ dstName: 'frontmatter',+ predicate: 'CONTAINS',+ });+ // Heading after frontmatter still parsed+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'Content',+ kind: 'heading',+ }));+ });++ it('skips headings inside fenced code blocks', () => {+ const result = parseFile(+ '/repo/README.md',+ ['# Real Heading', '```', '# Not A Heading', '```'].join('\n'),+ );++ expect(result).not.toBeNull();+ const headings = result!.entities.filter(e => e.kind === 'heading');+ expect(headings).toHaveLength(1);+ expect(headings[0].name).toBe('Real Heading');+ });++ it('produces file_body chunk for files with no headings', () => {+ const result = parseFile('/repo/notes.md', 'Just some plain text.\nNo headings here.');++ expect(result).not.toBeNull();+ expect(result!.chunks).toHaveLength(1);+ expect(result!.chunks[0].chunkKind).toBe('file_body');+ });++ it('produces file_body chunk for empty file', () => {+ const result = parseFile('/repo/empty.md', '');++ expect(result).not.toBeNull();+ expect(result!.chunks).toHaveLength(1);+ expect(result!.chunks[0].chunkKind).toBe('file_body');+ });++ it('handles ATX headings with closing hashes', () => {+ const result = parseFile('/repo/README.md', '## Section ##\nContent.');++ expect(result).not.toBeNull();+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'Section',+ kind: 'heading',+ }));+ });++ it('strips VitePress anchor ID suffix {#...} from heading names', () => {+ const result = parseFile('/repo/docs.md', '## What is Vue? {#what-is-vue}');+ expect(result!.entities).toContainEqual(expect.objectContaining({ name: 'What is Vue?', kind: 'heading' }));+ });++ it('preserves component names inside backticks when heading contains angle brackets', () => {+ const result = parseFile('/repo/docs.md', '## `<Transition>` {#transition}');+ expect(result!.entities).toContainEqual(expect.objectContaining({ name: '<Transition>', kind: 'heading' }));+ });++ it('handles backslash-escaped angle brackets in heading names', () => {+ const result = parseFile('/repo/docs.md', '# \\<script setup> {#script-setup}');+ expect(result!.entities).toContainEqual(expect.objectContaining({ name: '<script setup>', kind: 'heading' }));+ });++ it('strips backtick delimiters and VitePress stability markers', () => {+ const result = parseFile('/repo/docs.md', '### `ref()` \\*\\* {#ref}');+ expect(result!.entities).toContainEqual(expect.objectContaining({ name: 'ref()', kind: 'heading' }));+ });++ it('strips inline HTML badges and normalizes whitespace', () => {+ const result = parseFile(+ '/repo/docs.md',+ '## app.onUnmount() <sup class="vt-badge" data-text="3.5+" /> {#app-onunmount}',+ );+ expect(result!.entities).toContainEqual(expect.objectContaining({ name: 'app.onUnmount()', kind: 'heading' }));+ });++ it('handles component names in backticks combined with inline HTML badges', () => {+ const result = parseFile(+ '/repo/docs.md',+ '## `<Suspense>` <sup class="vt-badge experimental" /> {#suspense}',+ );+ expect(result!.entities).toContainEqual(expect.objectContaining({ name: '<Suspense>', kind: 'heading' }));+ });++ // Bug 1: frontmatter + no headings+ it('produces file_body chunk for body content when file has frontmatter but no headings', () => {+ const result = parseFile(+ '/repo/post.md',+ ['---', 'title: Hello', '---', '', 'Some body content.'].join('\n'),+ );++ expect(result).not.toBeNull();+ expect(result!.chunks).toContainEqual(expect.objectContaining({ chunkKind: 'frontmatter' }));+ expect(result!.chunks).toContainEqual(expect.objectContaining({ chunkKind: 'file_body' }));+ });++ // Bug 2: setext headings+ it('parses setext h1 headings (=== underline)', () => {+ const result = parseFile(+ '/repo/README.md',+ ['My Project', '==========', '', 'Some text.'].join('\n'),+ );++ expect(result).not.toBeNull();+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'My Project',+ kind: 'heading',+ }));+ });++ it('parses setext h2 headings (--- underline)', () => {+ const result = parseFile(+ '/repo/README.md',+ ['Overview', '--------', '', 'Details.'].join('\n'),+ );++ expect(result).not.toBeNull();+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'Overview',+ kind: 'heading',+ }));+ });++ it('nests setext heading under a preceding ATX heading', () => {+ const result = parseFile(+ '/repo/README.md',+ ['# Guide', '', 'Installation', '------------'].join('\n'),+ );++ expect(result).not.toBeNull();+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'Installation',+ kind: 'heading',+ container: 'Guide',+ }));+ });++ it('does not parse setext underline inside a fenced code block', () => {+ const result = parseFile(+ '/repo/README.md',+ ['# Real', '```', 'not a heading', '=============', '```'].join('\n'),+ );++ const headings = result!.entities.filter(e => e.kind === 'heading');+ expect(headings).toHaveLength(1);+ expect(headings[0].name).toBe('Real');+ });++ // Bug 3: fenced code block delimiter matching+ it('does not close a backtick fence with a tilde line', () => {+ const result = parseFile(+ '/repo/README.md',+ ['# Real', '```', '~~~', '# Not A Heading', '~~~', '```'].join('\n'),+ );++ const headings = result!.entities.filter(e => e.kind === 'heading');+ expect(headings).toHaveLength(1);+ expect(headings[0].name).toBe('Real');+ });++ it('does not close a tilde fence with a backtick line', () => {+ const result = parseFile(+ '/repo/README.md',+ ['# Real', '~~~', '```', '# Not A Heading', '```', '~~~'].join('\n'),+ );++ const headings = result!.entities.filter(e => e.kind === 'heading');+ expect(headings).toHaveLength(1);+ expect(headings[0].name).toBe('Real');+ });++ it('parses single-line HTML headings commonly used in docs', () => {+ const result = parseFile(+ '/repo/docs.md',+ ['<h1 align="center">Fastify</h1>', '', '## Routes'].join('\n'),+ );++ expect(result).not.toBeNull();+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'Fastify',+ kind: 'heading',+ container: undefined,+ }));+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'Routes',+ kind: 'heading',+ container: 'Fastify',+ }));+ expect(result!.relationships).toContainEqual({+ srcName: 'docs.md',+ dstName: 'Fastify',+ predicate: 'CONTAINS',+ });+ expect(result!.relationships).toContainEqual({+ srcName: 'Fastify',+ dstName: 'Routes',+ predicate: 'CONTAINS',+ });+ });+});diff --git a/core-ingestion/src/__tests__/queries.toml.test.ts b/core-ingestion/src/__tests__/queries.toml.test.tsnew file mode 100644index 00000000..c47f5ecb--- /dev/null+++ b/core-ingestion/src/__tests__/queries.toml.test.ts@@ -0,0 +1,263 @@+import { describe, expect, it } from 'vitest';++import { parseFile } from '../index.js';+import { languageFromPath, SupportedLanguages } from '../languages.js';++describe('TOML parsing', () => {+ it('recognizes .toml as TOML', () => {+ expect(languageFromPath('/repo/Cargo.toml')).toBe(SupportedLanguages.TOML);+ expect(languageFromPath('/repo/pyproject.toml')).toBe(SupportedLanguages.TOML);+ });++ it('parses top-level key = value pairs', () => {+ const result = parseFile(+ '/repo/config.toml',+ [+ 'name = "my-app"',+ 'version = "1.0.0"',+ 'debug = false',+ ].join('\n'),+ );++ expect(result).not.toBeNull();+ expect(result!.language).toBe(SupportedLanguages.TOML);+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'name',+ kind: 'config_entry',+ language: SupportedLanguages.TOML,+ container: undefined,+ }));+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'version',+ kind: 'config_entry',+ container: undefined,+ }));+ expect(result!.relationships).toContainEqual({+ srcName: 'config.toml',+ dstName: 'name',+ predicate: 'CONTAINS',+ });+ });++ it('parses [table] headers and keys within them', () => {+ const result = parseFile(+ '/repo/config.toml',+ [+ '[database]',+ 'host = "localhost"',+ 'port = 5432',+ ].join('\n'),+ );++ expect(result).not.toBeNull();+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'database',+ kind: 'config_entry',+ container: undefined,+ }));+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'host',+ kind: 'config_entry',+ container: 'database',+ }));+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'port',+ kind: 'config_entry',+ container: 'database',+ }));+ expect(result!.relationships).toContainEqual({+ srcName: 'config.toml',+ dstName: 'database',+ predicate: 'CONTAINS',+ });+ expect(result!.relationships).toContainEqual({+ srcName: 'database',+ dstName: 'host',+ predicate: 'CONTAINS',+ });+ });++ it('parses nested [section.subsection] tables', () => {+ const result = parseFile(+ '/repo/config.toml',+ [+ '[server.tls]',+ 'cert = "/etc/ssl/cert.pem"',+ 'key = "/etc/ssl/key.pem"',+ ].join('\n'),+ );++ expect(result).not.toBeNull();+ // Intermediate node+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'server',+ kind: 'config_entry',+ container: undefined,+ }));+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'tls',+ kind: 'config_entry',+ container: 'server',+ }));+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'cert',+ kind: 'config_entry',+ container: 'server.tls',+ }));+ expect(result!.relationships).toContainEqual({+ srcName: 'config.toml',+ dstName: 'server',+ predicate: 'CONTAINS',+ });+ expect(result!.relationships).toContainEqual({+ srcName: 'server',+ dstName: 'tls',+ predicate: 'CONTAINS',+ });+ expect(result!.relationships).toContainEqual({+ srcName: 'server.tls',+ dstName: 'cert',+ predicate: 'CONTAINS',+ });+ });++ it('emits intermediate nodes for dotted table paths', () => {+ const result = parseFile(+ '/repo/Cargo.toml',+ [+ '[profile.release]',+ 'lto = true',+ ].join('\n'),+ );++ expect(result).not.toBeNull();+ // Intermediate node+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'profile',+ kind: 'config_entry',+ container: undefined,+ }));+ // Leaf node+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'release',+ kind: 'config_entry',+ container: 'profile',+ }));+ // Key within leaf+ expect(result!.entities).toContainEqual(expect.objectContaining({+ name: 'lto',+ kind: 'config_entry',+ container: 'profile.release',+ }));+ // Chain of CONTAINS relationships+ expect(result!.relationships).toContainEqual({+ srcName: 'Cargo.toml',+ dstName: 'profile',+ predicate: 'CONTAINS',+ });+ expect(result!.relationships).toContainEqual({+ srcName: 'profile',+ dstName: 'release',+ predicate: 'CONTAINS',+ });+ expect(result!.relationships).toContainEqual({+ srcName: 'profile.release',+ dstName: 'lto',+ predicate: 'CONTAINS',+ });+ });++ it('does not duplicate intermediate nodes across sibling table headers', () => {+ const result = parseFile(+ '/repo/Cargo.toml',+ [+ '[profile.release]',+ 'lto = true',+ '[profile.dev]',+ 'opt-level = 0',+ ].join('\n'),+ );++ expect(result).not.toBeNull();+ const profileNodes = result!.entities.filter(e => e.name === 'profile');+ expect(profileNodes).toHaveLength(1);+ });++ it('parses [[array-of-tables]] headers', () => {+ const result = parseFile(+ '/repo/config.toml',+ [+ '[[servers]]',+ 'name = "alpha"',+ '',+ '[[servers]]',+ 'name = "beta"',+ ].join('\n'),+ );++ expect(result).not.toBeNull();+ // Both [[servers]] headers produce a 'servers' entity+ const serverEntities = result!.entities.filter(e => e.name === 'servers');+ expect(serverEntities.length).toBe(2);+ expect(result!.entities.filter(e => e.name === 'name').length).toBe(2);+ });++ it('ignores comment lines and blank lines', () => {+ const result = parseFile(+ '/repo/config.toml',+ [+ '# This is a comment',+ '',+ 'key = "value"',+ '# another comment',+ ].join('\n'),+ );++ expect(result).not.toBeNull();+ const nonFileEntities = result!.entities.filter(e => e.kind !== 'file');+ expect(nonFileEntities).toHaveLength(1);+ expect(nonFileEntities[0].name).toBe('key');+ });++ it('produces a file_body chunk for empty or comment-only files', () => {+ const result = parseFile('/repo/config.toml', '# just a comment\n');++ expect(result).not.toBeNull();+ expect(result!.chunks).toHaveLength(1);+ expect(result!.chunks[0].chunkKind).toBe('file_body');+ });++ it('produces config_key chunks with content hashes', () => {+ const result = parseFile('/repo/Cargo.toml', 'name = "my-crate"\n');++ expect(result).not.toBeNull();+ expect(result!.chunks).toContainEqual(expect.objectContaining({+ name: 'name',+ chunkKind: 'config_key',+ contentHash: expect.stringMatching(/^[0-9a-f]{64}$/),+ }));+ });++ it('parses a realistic Cargo.toml', () => {+ const result = parseFile(+ '/repo/Cargo.toml',+ [+ '[package]',+ 'name = "my-crate"',+ 'version = "0.1.0"',+ 'edition = "2021"',+ '',+ '[dependencies]',+ 'serde = { version = "1", features = ["derive"] }',+ 'tokio = "1"',+ ].join('\n'),+ );++ expect(result).not.toBeNull();+ expect(result!.entities).toContainEqual(expect.objectContaining({ name: 'package' }));+ expect(result!.entities).toContainEqual(expect.objectContaining({ name: 'name', container: 'package' }));+ expect(result!.entities).toContainEqual(expect.objectContaining({ name: 'dependencies' }));+ expect(result!.entities).toContainEqual(expect.objectContaining({ name: 'serde', container: 'dependencies' }));+ expect(result!.entities).toContainEqual(expect.objectContaining({ name: 'tokio', container: 'dependencies' }));+ });+});diff --git a/core-ingestion/src/index.ts b/core-ingestion/src/index.tsindex 51cce190..1162820f 100644--- a/core-ingestion/src/index.ts+++ b/core-ingestion/src/index.ts@@ -213,7 +213,7 @@ function builtinsForLanguage(lang: SupportedLanguages): Set<string> {export function isGrammarSupported(filePath: string): boolean {const language = languageFromPath(filePath);if (!language) return false;- if (language === SupportedLanguages.YAML || language === SupportedLanguages.Dockerfile || language === SupportedLanguages.SQL || language === SupportedLanguages.JSON) return true;+ if (language === SupportedLanguages.YAML || language === SupportedLanguages.Dockerfile || language === SupportedLanguages.SQL || language === SupportedLanguages.JSON || language === SupportedLanguages.TOML || language === SupportedLanguages.Markdown) return true;if (filePath.endsWith('.tsx')) return true; // TSX uses TypeScript.tsx, always availablereturn GRAMMAR_MAP[language] !== undefined;}@@ -388,6 +388,345 @@ function parseYamlFile(filePath: string, source: string): FileParseResult {};}+function parseTomlFile(filePath: string, source: string): FileParseResult {+ const language = SupportedLanguages.TOML;+ const fileName = nodePath.basename(filePath);+ const sourceLineCount = countSourceLines(source);+ const fileRole = classifyFileRole(filePath);+ const entities: ParsedEntity[] = [+ { name: fileName, kind: 'file', lineStart: 1, lineEnd: sourceLineCount, language },+ ];+ const chunks: ParsedChunk[] = [];+ const relationships: ParsedRelationship[] = [];+ const lineStarts = computeLineStarts(source);+ const lines = source.split(/\r?\n/);++ // [table] or [[array-of-tables]] headers set the current section context.+ const tableHeaderPattern = /^\s*\[{1,2}([^\[\]]+)\]{1,2}\s*(?:#.*)?$/;+ // key = value lines (bare keys, quoted keys, dotted keys).+ // Quoted keys handled separately to avoid ReDoS from spaces overlapping with \s*.+ const keyPattern = /^\s*("[^"]*"|'[^']*'|[A-Za-z0-9_-][A-Za-z0-9_.-]*)\s*=/;++ let currentTable: string | null = null;+ const seenTablePaths = new Set<string>();++ for (let i = 0; i < lines.length; i++) {+ const line = lines[i];+ const trimmed = line.trimStart();+ if (!trimmed || trimmed.startsWith('#')) continue;++ const tableMatch = tableHeaderPattern.exec(line);+ if (tableMatch) {+ const tablePath = tableMatch[1].trim();+ currentTable = tablePath;+ const parts = tablePath.split('.');+ const lineNumber = i + 1;+ const startByte = lineStarts[i] ?? 0;++ // Emit intermediate nodes for each prefix segment (e.g. [a.b.c] → emit a, a.b)+ for (let p = 1; p < parts.length; p++) {+ const prefixPath = parts.slice(0, p).join('.');+ if (!seenTablePaths.has(prefixPath)) {+ seenTablePaths.add(prefixPath);+ const prefixKey = parts[p - 1];+ const prefixParent = p > 1 ? parts.slice(0, p - 1).join('.') : null;+ entities.push({+ name: prefixKey,+ kind: 'config_entry',+ lineStart: lineNumber,+ lineEnd: lineNumber,+ language,+ container: prefixParent ?? undefined,+ });+ relationships.push({+ srcName: prefixParent ?? fileName,+ dstName: prefixKey,+ predicate: 'CONTAINS',+ });+ }+ }++ const key = parts[parts.length - 1];+ const parent = parts.length > 1 ? parts.slice(0, -1).join('.') : null;++ seenTablePaths.add(tablePath);+ entities.push({+ name: key,+ kind: 'config_entry',+ lineStart: lineNumber,+ lineEnd: lineNumber,+ language,+ container: parent ?? undefined,+ });+ chunks.push({+ name: key,+ chunkKind: 'config_key',+ lineStart: lineNumber,+ lineEnd: lineNumber,+ startByte,+ endByte: startByte + line.length,+ contentHash: crypto.createHash('sha256').update(line).digest('hex'),+ language,+ container: parent ?? undefined,+ });+ relationships.push({+ srcName: parent ?? fileName,+ dstName: key,+ predicate: 'CONTAINS',+ });+ continue;+ }++ const keyMatch = keyPattern.exec(line);+ if (keyMatch) {+ const key = keyMatch[1].trim().replace(/^["']|["']$/g, '');+ const lineNumber = i + 1;+ const startByte = lineStarts[i] ?? 0;++ entities.push({+ name: key,+ kind: 'config_entry',+ lineStart: lineNumber,+ lineEnd: lineNumber,+ language,+ container: currentTable ?? undefined,+ });+ chunks.push({+ name: key,+ chunkKind: 'config_key',+ lineStart: lineNumber,+ lineEnd: lineNumber,+ startByte,+ endByte: startByte + line.length,+ contentHash: crypto.createHash('sha256').update(line).digest('hex'),+ language,+ container: currentTable ?? undefined,+ });+ relationships.push({+ srcName: currentTable ?? fileName,+ dstName: key,+ predicate: 'CONTAINS',+ });+ }+ }++ if (chunks.length === 0) {+ chunks.push({+ name: null,+ chunkKind: 'file_body',+ lineStart: 1,+ lineEnd: Math.max(sourceLineCount, 1),+ startByte: 0,+ endByte: source.length,+ contentHash: crypto.createHash('sha256').update(source).digest('hex'),+ language,+ });+ }++ return { filePath, language, entities, chunks, relationships, fileRole };+}++function cleanHeadingName(raw: string): string {+ // 1. Strip VitePress anchor ID suffix {#...}+ // Use string methods to avoid ReDoS from overlapping \s* / [^}]+ quantifiers.+ let s = raw;+ const anchorStart = raw.lastIndexOf('{#');+ if (anchorStart !== -1) {+ const closeIdx = raw.indexOf('}', anchorStart + 2);+ if (closeIdx !== -1 && raw.slice(closeIdx + 1).trim() === '') {+ s = raw.slice(0, anchorStart).trimEnd();+ }+ }+ // 2. Unescape backslash-escaped angle brackets before HTML stripping+ s = s.replace(/\\</g, '\x01LT\x01').replace(/\\>/g, '\x01GT\x01');+ // 3. Protect inline code spans from HTML stripping+ const spans: string[] = [];+ s = s.replace(/`[^`]+`/g, (m) => { spans.push(m); return `\x00${spans.length - 1}\x00`; });+ // 4. Strip HTML tags (iteratively to handle split tags like <scr<x>ipt>).+ let prev: string;+ do {+ prev = s;+ s = s.replace(/<[^>]+>/g, '');+ } while (s !== prev);+ // 5. Restore inline code spans and strip their backtick delimiters+ s = s.replace(/\x00(\d+)\x00/g, (_, i) => spans[Number(i)].replace(/`/g, ''));+ // 6. Restore escaped angle brackets+ s = s.replace(/\x01LT\x01/g, '<').replace(/\x01GT\x01/g, '>');+ // 7. Strip VitePress stability markers (\* \*\* \*\*\*)+ s = s.replace(/\\\*+/g, '');+ // 8. Normalize whitespace+ s = s.replace(/\s{2,}/g, ' ').trim();+ return s;+}++function parseMarkdownFile(filePath: string, source: string): FileParseResult {+ const language = SupportedLanguages.Markdown;+ const fileName = nodePath.basename(filePath);+ const sourceLineCount = countSourceLines(source);+ const fileRole = classifyFileRole(filePath);+ const entities: ParsedEntity[] = [+ { name: fileName, kind: 'file', lineStart: 1, lineEnd: sourceLineCount, language },+ ];+ const chunks: ParsedChunk[] = [];+ const relationships: ParsedRelationship[] = [];+ const lineStarts = computeLineStarts(source);+ const lines = source.split(/\r?\n/);++ let startLine = 0;++ // Parse YAML frontmatter delimited by --- ... ---+ if (lines[0]?.trim() === '---') {+ let fmEnd = -1;+ for (let j = 1; j < lines.length; j++) {+ if (lines[j].trim() === '---' || lines[j].trim() === '...') {+ fmEnd = j;+ break;+ }+ }+ if (fmEnd > 0) {+ startLine = fmEnd + 1;+ const endByte = (lineStarts[fmEnd] ?? 0) + lines[fmEnd].length;+ const fmContent = lines.slice(0, fmEnd + 1).join('\n');+ entities.push({ name: 'frontmatter', kind: 'frontmatter', lineStart: 1, lineEnd: fmEnd + 1, language });+ chunks.push({+ name: 'frontmatter',+ chunkKind: 'frontmatter',+ lineStart: 1,+ lineEnd: fmEnd + 1,+ startByte: 0,+ endByte,+ contentHash: crypto.createHash('sha256').update(fmContent).digest('hex'),+ language,+ });+ relationships.push({ srcName: fileName, dstName: 'frontmatter', predicate: 'CONTAINS' });+ }+ }++ // headingStack[level] = heading name currently active at that depth (1–6)+ const headingStack: (string | null)[] = [null, null, null, null, null, null, null];+ // \S[^\r\n]* requires content to start with non-whitespace, eliminating the+ // \s+/(.*\S) overlap that caused polynomial backtracking. Trailing whitespace+ // and closing ## markers are stripped in code below.+ const headingPattern = /^(#{1,6})[ \t]+(\S[^\r\n]*)$/;+ // Greedy .* with specific closing tag as anchor avoids (.*?)\s*$ overlap (ReDoS).+ const htmlHeadingPattern = /^<h([1-6])\b[^>]*>(.*)<\/h\1>/i;+ const headingLines: { level: number; name: string; lineNum: number; container: string | null }[] = [];++ // Bug 3 fix: track opening fence char+length so only matching delimiter closes the block+ let fenceState: { char: string; len: number } | null = null;+ for (let i = startLine; i < lines.length; i++) {+ const line = lines[i];++ // Toggle fenced code block — only close with same character and >= opening length+ const fenceMatch = /^(`{3,}|~{3,})/.exec(line.trimStart());+ if (fenceMatch) {+ const matchChar = fenceMatch[1][0];+ const matchLen = fenceMatch[1].length;+ if (fenceState === null) {+ fenceState = { char: matchChar, len: matchLen };+ } else if (matchChar === fenceState.char && matchLen >= fenceState.len) {+ fenceState = null;+ }+ continue;+ }+ if (fenceState !== null) continue;++ const headingMatch = headingPattern.exec(line);+ const htmlHeadingMatch = headingMatch ? null : htmlHeadingPattern.exec(line.trim());++ // Bug 2 fix: detect setext-style headings (text line followed by === or --- underline)+ let setextLevel: number | null = null;+ if (!headingMatch && !htmlHeadingMatch && line.trim() !== '') {+ const nextLine = lines[i + 1];+ if (nextLine !== undefined) {+ if (/^=+\s*$/.test(nextLine)) setextLevel = 1;+ else if (/^-+\s*$/.test(nextLine)) setextLevel = 2;+ }+ }++ if (!headingMatch && !htmlHeadingMatch && setextLevel === null) continue;++ const level = headingMatch ? headingMatch[1].length : (htmlHeadingMatch ? Number(htmlHeadingMatch![1]) : setextLevel!);+ // Strip optional ATX closing markers (e.g. "Title ##") that (.*\S) now includes.+ // Use string walk instead of regex to avoid ReDoS on +#+$ backtracking.+ let atxRaw = headingMatch ? headingMatch[2].trimEnd() : null;+ if (atxRaw !== null && atxRaw[atxRaw.length - 1] === '#') {+ let i = atxRaw.length - 1;+ while (i >= 0 && atxRaw[i] === '#') i--;+ if (i >= 0 && (atxRaw[i] === ' ' || atxRaw[i] === '\t')) atxRaw = atxRaw.slice(0, i);+ }+ const rawName = atxRaw !== null ? atxRaw : (htmlHeadingMatch ? htmlHeadingMatch![2] : line.trim());+ const name = cleanHeadingName(rawName);+ if (!name) continue;+ const lineNum = i + 1;++ if (setextLevel !== null) i++; // skip the underline line++ // Find nearest ancestor at a shallower level+ let container: string | null = null;+ for (let l = level - 1; l >= 1; l--) {+ if (headingStack[l] !== null) {+ container = headingStack[l];+ break;+ }+ }++ // Reset all deeper levels when a heading resets scope+ for (let l = level; l <= 6; l++) headingStack[l] = null;+ headingStack[level] = name;++ entities.push({ name, kind: 'heading', lineStart: lineNum, lineEnd: lineNum, language, container: container ?? undefined });+ relationships.push({ srcName: container ?? fileName, dstName: name, predicate: 'CONTAINS' });+ headingLines.push({ level, name, lineNum, container });+ }++ // Build one section chunk per heading spanning to the line before the next heading at the same or+ // shallower level. This ensures parent sections contain their nested sub-sections' content.+ for (let h = 0; h < headingLines.length; h++) {+ const { level: currentLevel, name, lineNum, container } = headingLines[h];+ let nextLineNum = sourceLineCount;+ for (let k = h + 1; k < headingLines.length; k++) {+ if (headingLines[k].level <= currentLevel) {+ nextLineNum = headingLines[k].lineNum - 1;+ break;+ }+ }+ const startByte = lineStarts[lineNum - 1] ?? 0;+ const endByte = nextLineNum < lines.length ? (lineStarts[nextLineNum] ?? source.length) : source.length;+ const sectionContent = lines.slice(lineNum - 1, nextLineNum).join('\n');+ chunks.push({+ name,+ chunkKind: 'section',+ lineStart: lineNum,+ lineEnd: nextLineNum,+ startByte,+ endByte,+ contentHash: crypto.createHash('sha256').update(sectionContent).digest('hex'),+ language,+ container: container ?? undefined,+ });+ }++ // Bug 1 fix: emit file_body when no section chunks exist, regardless of frontmatter chunk+ if (headingLines.length === 0) {+ const bodyLineStart = startLine + 1;+ const bodyStartByte = lineStarts[startLine] ?? 0;+ const bodyContent = source.slice(bodyStartByte);+ chunks.push({+ name: null,+ chunkKind: 'file_body',+ lineStart: bodyLineStart,+ lineEnd: Math.max(sourceLineCount, 1),+ startByte: bodyStartByte,+ endByte: source.length,+ contentHash: crypto.createHash('sha256').update(bodyContent).digest('hex'),+ language,+ });+ }++ return { filePath, language, entities, chunks, relationships, fileRole };+}+function parseDockerfileFile(filePath: string, source: string): FileParseResult {const language = SupportedLanguages.Dockerfile;const fileName = nodePath.basename(filePath);@@ -841,6 +1180,8 @@ export function parseFile(filePath: string, source: string): FileParseResult | nif (language === SupportedLanguages.Dockerfile) return parseDockerfileFile(filePath, source);if (language === SupportedLanguages.SQL) return parseSqlFile(filePath, source);if (language === SupportedLanguages.JSON) return parseJsonFile(filePath, source);+ if (language === SupportedLanguages.TOML) return parseTomlFile(filePath, source);+ if (language === SupportedLanguages.Markdown) return parseMarkdownFile(filePath, source);// TypeScript TSX uses a separate grammarconst isTsx = filePath.endsWith('.tsx');diff --git a/core-ingestion/src/languages.ts b/core-ingestion/src/languages.tsindex 85464017..321f3ed5 100644--- a/core-ingestion/src/languages.ts+++ b/core-ingestion/src/languages.ts@@ -17,6 +17,8 @@ export enum SupportedLanguages {Dockerfile = 'dockerfile',SQL = 'sql',JSON = 'json',+ TOML = 'toml',+ Markdown = 'markdown',}const EXT_MAP: Record<string, SupportedLanguages> = {@@ -49,6 +51,9 @@ const EXT_MAP: Record<string, SupportedLanguages> = {'.dockerfile': SupportedLanguages.Dockerfile,'.sql': SupportedLanguages.SQL,'.json': SupportedLanguages.JSON,+ '.toml': SupportedLanguages.TOML,+ '.md': SupportedLanguages.Markdown,+ '.markdown': SupportedLanguages.Markdown,};export function languageFromPath(filePath: string): SupportedLanguages | null {diff --git a/core-ingestion/src/patch-builder.ts b/core-ingestion/src/patch-builder.tsindex 8b2ac80b..890e388d 100644--- a/core-ingestion/src/patch-builder.ts+++ b/core-ingestion/src/patch-builder.ts@@ -51,11 +51,11 @@ function sourceType(filePath: string): string {}export function extractorName(): string {- return `tree-sitter/1.20`;+ return `tree-sitter/1.21`;}/** Previous extractor versions — their patches are superseded when re-ingesting. */-export const PREVIOUS_EXTRACTORS = ['tree-sitter/1.19', 'tree-sitter/1.18', 'tree-sitter/1.17', 'tree-sitter/1.16', 'tree-sitter/1.15', 'tree-sitter/1.14', 'tree-sitter/1.13', 'tree-sitter/1.12', 'tree-sitter/1.11', 'tree-sitter/1.10', 'tree-sitter/1.9', 'tree-sitter/1.8', 'tree-sitter/1.7', 'tree-sitter/1.6', 'tree-sitter/1.5', 'tree-sitter/1.4', 'tree-sitter/1.3', 'tree-sitter/1.2', 'tree-sitter/1.1'];+export const PREVIOUS_EXTRACTORS = ['tree-sitter/1.20', 'tree-sitter/1.19', 'tree-sitter/1.18', 'tree-sitter/1.17', 'tree-sitter/1.16', 'tree-sitter/1.15', 'tree-sitter/1.14', 'tree-sitter/1.13', 'tree-sitter/1.12', 'tree-sitter/1.11', 'tree-sitter/1.10', 'tree-sitter/1.9', 'tree-sitter/1.8', 'tree-sitter/1.7', 'tree-sitter/1.6', 'tree-sitter/1.5', 'tree-sitter/1.4', 'tree-sitter/1.3', 'tree-sitter/1.2', 'tree-sitter/1.1'];/** Compute a patchId for a (filePath, sourceHash, extractorVersion) triple. */function computePatchId(filePath: string, sourceHash: string, extractor: string): string {@@ -146,10 +146,11 @@ export function buildPatch(for (const chunk of chunks) {const cid = chunkId(filePath, chunk.chunkKind, chunk.name, chunk.lineStart);const chunkName = chunk.name ?? `file_body:${chunk.lineStart}`;+ const chunkNodeKind = chunk.chunkKind === 'section' ? 'section' : 'chunk';ops.push({type: 'UpsertNode',id: cid,- kind: 'chunk',+ kind: chunkNodeKind,name: chunkName,attrs: {file_uri: filePath,@@ -340,10 +341,11 @@ export function buildPatchWithResolution(for (const chunk of chunks) {const cid = chunkId(filePath, chunk.chunkKind, chunk.name, chunk.lineStart);const chunkName = chunk.name ?? `file_body:${chunk.lineStart}`;+ const chunkNodeKind2 = chunk.chunkKind === 'section' ? 'section' : 'chunk';ops.push({type: 'UpsertNode',id: cid,- kind: 'chunk',+ kind: chunkNodeKind2,name: chunkName,attrs: {file_uri: filePath,diff --git a/core-ingestion/src/queries.ts b/core-ingestion/src/queries.tsindex c6f70893..979651ff 100644--- a/core-ingestion/src/queries.ts+++ b/core-ingestion/src/queries.ts@@ -1183,5 +1183,7 @@ export const LANGUAGE_QUERIES: Record<SupportedLanguages, string> = {[SupportedLanguages.Dockerfile]: '',[SupportedLanguages.SQL]: '',[SupportedLanguages.JSON]: '',+ [SupportedLanguages.TOML]: '',+ [SupportedLanguages.Markdown]: '',};diff --git a/ix-cli/src/cli/commands/contains.ts b/ix-cli/src/cli/commands/contains.tsindex 8b9ae688..fb130f95 100644--- a/ix-cli/src/cli/commands/contains.ts+++ b/ix-cli/src/cli/commands/contains.ts@@ -9,14 +9,15 @@ export function registerContainsCommand(program: Command): void {.command("contains <symbol>").description("Show members contained by the given entity (class, module, file)").option("--kind <kind>", "Filter target entity by kind")+ .option("--path <path>", "Filter target entity by file path (substring match)").option("--pick <n>", "Pick Nth candidate from ambiguous results (1-based)").option("--limit <n>", "Max results to show", "50").option("--format <fmt>", "Output format (text|json)", "text")- .addHelpText("after", "\nExamples:\n ix contains IngestionService\n ix contains auth.py --kind file --format json\n ix contains MyClass --limit 20")- .action(async (symbol: string, opts: { kind?: string; pick?: string; limit: string; format: string }) => {+ .addHelpText("after", "\nExamples:\n ix contains IngestionService\n ix contains auth.py --kind file --format json\n ix contains MyClass --limit 20\n ix contains package --path crates/regex/Cargo.toml")+ .action(async (symbol: string, opts: { kind?: string; path?: string; pick?: string; limit: string; format: string }) => {const client = new IxClient(getEndpoint());const limit = parseInt(opts.limit, 10);- const resolveOpts = { kind: opts.kind, pick: opts.pick ? parseInt(opts.pick, 10) : undefined };+ const resolveOpts = { kind: opts.kind, path: opts.path, pick: opts.pick ? parseInt(opts.pick, 10) : undefined };const target = await resolveFileOrEntity(client, symbol, resolveOpts);if (!target) return;if (opts.format !== "json") printResolved(target);diff --git a/ix-cli/src/cli/commands/explain.ts b/ix-cli/src/cli/commands/explain.tsindex c4489910..3a79cf88 100644--- a/ix-cli/src/cli/commands/explain.ts+++ b/ix-cli/src/cli/commands/explain.ts@@ -121,6 +121,7 @@ async function rawExplain(// Extract snippet fields from attrsconst signature = node.attrs?.signature || node.attrs?.summary;const docstring = node.attrs?.docstring || node.attrs?.description;+ const chunkKind = node.attrs?.chunk_kind || node.attrs?.chunkKind || (node.kind === "section" ? "section" : undefined);// Get actual callee details from outgoing CALLS edgesconst calleeEdges = callEdges.filter((e: any) => e.src === target.id);@@ -181,6 +182,7 @@ async function rawExplain(name: node.name || node.attrs?.name || target.name,id: target.id,file: relativePath(sourceUri),+ chunkKind,container: container ? { kind: container.kind, name: container.name || container.attrs?.name || "(unknown)" } : undefined,introducedRev: node.createdRev ?? node.created_rev,calledBy: callEdges.filter((e: any) => e.dst === target.id).length,diff --git a/ix-cli/src/cli/commands/ingest.ts b/ix-cli/src/cli/commands/ingest.tsindex bab31737..e4b97a33 100644--- a/ix-cli/src/cli/commands/ingest.ts+++ b/ix-cli/src/cli/commands/ingest.ts@@ -37,6 +37,8 @@ const SUPPORTED_EXTENSIONS = new Set(['.dockerfile','.sql','.json',+ '.toml',+ '.md', '.markdown',]);export function isSupportedSourceFile(filePath: string): boolean {diff --git a/ix-cli/src/cli/commands/search.ts b/ix-cli/src/cli/commands/search.tsindex 14c9bceb..4760d047 100644--- a/ix-cli/src/cli/commands/search.ts+++ b/ix-cli/src/cli/commands/search.ts@@ -1,7 +1,7 @@import type { Command } from "commander";import chalk from "chalk";import { IxClient } from "../../client/api.js";-import { getEndpoint } from "../config.js";+import { getActiveWorkspaceRoot, getEndpoint } from "../config.js";import { formatNodes, relativePath } from "../format.js";import { scoreCandidate } from "../resolve.js";import { applyRoleFilter, roleHint } from "../role-filter.js";@@ -80,6 +80,10 @@ function searchSort(return aName.localeCompare(bName);}+function normalizePath(value: string | undefined): string {+ return (value ?? "").toLowerCase().replace(/\\/g, "/");+}+export function registerSearchCommand(program: Command): void {program.command("search <term>")@@ -112,20 +116,27 @@ Examples:}) => {const client = new IxClient(getEndpoint());const limit = parseInt(opts.limit, 10);+ const effectivePathFilter = opts.path ?? getActiveWorkspaceRoot();// Fetch more results than requested so we can re-rank and trimconst fetchLimit = Math.min(limit * 3, 60);- const nodes = await client.search(term, {+ const rawNodes = await client.search(term, {limit: fetchLimit,kind: opts.kind,language: opts.language,asOfRev: opts.asOf ? parseInt(opts.asOf, 10) : undefined,});+ const nodes = effectivePathFilter+ ? rawNodes.filter((node: any) => {+ const sourceUri = normalizePath(node.provenance?.sourceUri ?? node.provenance?.source_uri ?? "");+ return sourceUri.includes(normalizePath(effectivePathFilter));+ })+ : rawNodes;// Re-rank client-side using shared scoring + backend weightconst scored = nodes.map(n => ({node: n,- rank: rankScore(n, term, opts.kind, opts.path),+ rank: rankScore(n, term, opts.kind, effectivePathFilter),}));scored.sort(searchSort);@@ -167,7 +178,7 @@ Examples:})),summary: {count: ranked.length,- totalCandidates: nodes.length,+ totalCandidates: rawNodes.length,},diagnostics,}, null, 2));diff --git a/ix-cli/src/cli/config.ts b/ix-cli/src/cli/config.tsindex ccd4c79b..dc85155c 100644--- a/ix-cli/src/cli/config.ts+++ b/ix-cli/src/cli/config.ts@@ -14,6 +14,7 @@ export interface WorkspaceConfig {export interface IxConfig {endpoint: string;format: string;+ workspace?: string;workspaces?: WorkspaceConfig[];}@@ -59,6 +60,20 @@ export function getDefaultWorkspace(): WorkspaceConfig | undefined {return loadWorkspaces().find(w => w.default);}+export function getActiveWorkspaceRoot(): string | undefined {+ const cwd = process.cwd();+ const nearest = findWorkspaceForCwd(cwd);+ if (nearest) return nearest.root_path;++ const cfg = loadConfig();+ if (cfg.workspace) {+ const named = loadWorkspaces().find(w => w.workspace_name === cfg.workspace);+ if (named) return named.root_path;+ }++ return getDefaultWorkspace()?.root_path;+}+export function resolveWorkspaceRoot(explicitRoot?: string): string {// 1. Explicit --rootif (explicitRoot) return explicitRoot;@@ -66,13 +81,19 @@ export function resolveWorkspaceRoot(explicitRoot?: string): string {const cwd = process.cwd();const nearest = findWorkspaceForCwd(cwd);if (nearest) return nearest.root_path;- // 3. Configured default workspace+ // 3. Named workspace from `ix config set workspace <name>`+ const cfg = loadConfig();+ if (cfg.workspace) {+ const named = loadWorkspaces().find(w => w.workspace_name === cfg.workspace);+ if (named) return named.root_path;+ }+ // 4. Configured default workspaceconst defaultWs = getDefaultWorkspace();if (defaultWs) return defaultWs.root_path;- // 4. Git root+ // 5. Git roottry {return execSync("git rev-parse --show-toplevel", { encoding: "utf-8" }).trim();} catch {}- // 5. cwd fallback+ // 6. cwd fallbackreturn cwd;}diff --git a/ix-cli/src/cli/explain/render.ts b/ix-cli/src/cli/explain/render.tsindex 52f6fd0c..ff590586 100644--- a/ix-cli/src/cli/explain/render.ts+++ b/ix-cli/src/cli/explain/render.ts@@ -272,6 +272,8 @@ export function renderExplanation(// ── Context ───────────────────────────────────────────────────────────const contextLines: string[] = [];+ contextLines.push(`Kind: ${facts.kind}`);+if (facts.path) {contextLines.push(`Defined in: ${facts.path}`);}diff --git a/ix-cli/src/cli/format.ts b/ix-cli/src/cli/format.tsindex 6dbcab76..e579c350 100644--- a/ix-cli/src/cli/format.ts+++ b/ix-cli/src/cli/format.ts@@ -520,6 +520,7 @@ export interface ExplainResult {name: string;id: string;file?: string;+ chunkKind?: string;container?: { kind: string; name: string };introducedRev: number;calledBy: number;@@ -541,6 +542,7 @@ export function formatExplain(result: ExplainResult, format: string): void {name: result.name,id: result.id,file: relativePath(result.file),+ chunkKind: result.chunkKind ?? null,container: result.container,introducedRev: result.introducedRev,calledBy: result.calledBy,@@ -573,6 +575,9 @@ export function formatExplain(result: ExplainResult, format: string): void {if (result.file) {console.log(` ${chalk.dim("file")} ${result.file}`);}+ if (result.chunkKind) {+ console.log(` ${chalk.dim("chunk kind")} ${result.chunkKind}`);+ }console.log(` ${chalk.dim("introduced rev")} ${result.introducedRev}`);if (result.calledBy > 0) console.log(` ${chalk.dim("called by")} ${result.calledBy} methods`);if (result.callList && result.callList.length > 0) {diff --git a/ix-cli/src/cli/resolve.ts b/ix-cli/src/cli/resolve.tsindex 62678d86..e54fb268 100644--- a/ix-cli/src/cli/resolve.ts+++ b/ix-cli/src/cli/resolve.ts@@ -1,6 +1,7 @@import * as path from "node:path";import chalk from "chalk";import type { IxClient } from "../client/api.js";+import { getActiveWorkspaceRoot } from "./config.js";import { stderr } from "./stderr.js";import { applyRoleFilter } from "./role-filter.js";@@ -147,9 +148,10 @@ export async function resolveEntityFull(preferredKinds: string[],opts?: { kind?: string; path?: string; pick?: number; includeTests?: boolean; testsOnly?: boolean; searchLimit?: number }): Promise<ResolveResult> {+ const effectivePath = opts?.path ?? getActiveWorkspaceRoot();const kindFilter = opts?.kind;const nodes = await client.search(symbol, {- limit: opts?.searchLimit ?? (opts?.path ? 200 : looksTypeLikeSymbol(symbol) ? 50 : 20),+ limit: opts?.searchLimit ?? (effectivePath ? 200 : looksTypeLikeSymbol(symbol) ? 50 : 20),kind: kindFilter,nameOnly: true,});@@ -165,15 +167,15 @@ export async function resolveEntityFull(// Hard path filter: when --path is provided, exclude candidates whose sourceUri does not// contain the filter string. If no candidates survive, return "not found" rather than// falling back to cross-repo results.- const filteredNodes = opts?.path+ const filteredNodes = effectivePath? roleFiltered.filter((n: any) => {const uri = normalizeForPathMatch(n.provenance?.sourceUri ?? n.provenance?.source_uri ?? "");- return uri.includes(normalizeForPathMatch(opts.path));+ return uri.includes(normalizeForPathMatch(effectivePath));}): roleFiltered;- if (opts?.path && filteredNodes.length === 0) {- stderr(`No entity named "${symbol}" found in paths matching "${opts.path}".`);+ if (effectivePath && filteredNodes.length === 0) {+ stderr(`No entity named "${symbol}" found in paths matching "${effectivePath}".`);return { resolved: false, ambiguous: false, hiddenTestCount };}@@ -195,7 +197,7 @@ export async function resolveEntityFull(// Score exact-name candidatesif (exactName.length > 0) {- const winner = pickBest(exactName, symbol, preferredKinds, opts);+ const winner = pickBest(exactName, symbol, preferredKinds, { ...opts, path: effectivePath });if (winner) {const picked = applyPick(winner, opts);if (picked) return { ...picked, hiddenTestCount } as ResolveResult;@@ -204,7 +206,7 @@ export async function resolveEntityFull(}// ── Phase 2: Fall back to all candidates ────────────────────────────- const winner = pickBest(filteredNodes, symbol, preferredKinds, opts);+ const winner = pickBest(filteredNodes, symbol, preferredKinds, { ...opts, path: effectivePath });if (winner) {const picked = applyPick(winner, opts);if (picked) return { ...picked, hiddenTestCount } as ResolveResult;@@ -506,6 +508,23 @@ export async function resolveFileOrEntity(}}+ // 1.5 Short ID prefix (8–31 hex chars, e.g. "aacc3359" from CLI output)+ if (/^[0-9a-f]{8,31}$/i.test(target)) {+ try {+ const fullId = await client.resolvePrefix(target);+ const details = await client.entity(fullId);+ const n = details.node as any;+ return {+ id: fullId,+ kind: n.kind || "unknown",+ name: n.name || target,+ resolutionMode: "exact",+ };+ } catch {+ // Not a valid entity prefix — fall through to normal resolution+ }+ }+// 2. File-like input → try graph file searchif (looksFileLike(target)) {const fileEntity = await tryFileGraphMatch(client, target, opts);@@ -577,10 +596,11 @@ async function tryFileGraphMatch(): Promise<ResolvedEntity | null> {const basename = path.basename(target);const targetHasPath = target.includes("/") || target.includes("\\");+ const effectivePath = opts?.path ?? getActiveWorkspaceRoot();// Search for file entities matching the basenameconst nodes = await client.search(basename, {- limit: opts?.path ? 200 : 20,+ limit: effectivePath ? 200 : 20,kind: "file",nameOnly: true,});@@ -589,15 +609,17 @@ async function tryFileGraphMatch(const targetLower = normalizeForPathMatch(target);const basenameLower = basename.toLowerCase();const basenameNoExt = basename.replace(/\.[^.]+$/, "").toLowerCase();- const normalizedPathHint = normalizeForPathMatch(opts?.path);+ const normalizedPathHint = normalizeForPathMatch(effectivePath);const matches: Array<{ node: any; quality: number }> = [];for (const n of nodes as any[]) {const name = (n.name || "").toLowerCase();const uri = normalizeForPathMatch(n.provenance?.sourceUri ?? n.provenance?.source_uri ?? "");- // Exact path match (best)- if (targetHasPath && (uri.endsWith(targetLower) || uri === targetLower)) {+ // Exact path match (best): covers both absolute URIs matching absolute target,+ // and relative URIs that are a suffix of an absolute target path.+ if (targetHasPath && (uri.endsWith(targetLower) || uri === targetLower+ || (uri.includes("/") && targetLower.endsWith(uri)))) {matches.push({ node: n, quality: 0 });}// Filename match in user-requested path@@ -616,8 +638,13 @@ async function tryFileGraphMatch(if (matches.length === 0) return null;- // Sort by quality then pick best- matches.sort((a, b) => a.quality - b.quality);+ // Sort by quality then by URI length ascending (shorter = closer to root = more prominent)+ matches.sort((a, b) => {+ if (a.quality !== b.quality) return a.quality - b.quality;+ const uriA = normalizeForPathMatch(a.node.provenance?.sourceUri ?? a.node.provenance?.source_uri ?? "");+ const uriB = normalizeForPathMatch(b.node.provenance?.sourceUri ?? b.node.provenance?.source_uri ?? "");+ return uriA.length - uriB.length;+ });// If multiple matches at same quality, prefer path-matching targetconst best = matches[0];@@ -625,7 +652,9 @@ async function tryFileGraphMatch(// Disambiguate by path when user provided a pathconst pathMatch = matches.find(m => {const uri = normalizeForPathMatch(m.node.provenance?.sourceUri ?? m.node.provenance?.source_uri ?? "");- return uri.endsWith(targetLower) || (!!normalizedPathHint && uri.includes(normalizedPathHint));+ return uri.endsWith(targetLower) || uri === targetLower+ || (uri.includes("/") && targetLower.endsWith(uri))+ || (!!normalizedPathHint && uri.includes(normalizedPathHint));});if (pathMatch) {return nodeToResolved(pathMatch.node, pathMatch.node.name, "exact");