Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
feat(open-knowledge): all-files search surfaces (PRD-7117 Part 2) (#1941)
Andrew Mikofalvye913b2b01c06
diff --git a/.changeset/allfiles-search-surfaces.md b/.changeset/allfiles-search-surfaces.mdnew file mode 100644index 000000000..2b438d984--- /dev/null+++ b/.changeset/allfiles-search-surfaces.md@@ -0,0 +1,16 @@+---+"@inkeep/open-knowledge": minor+---++Search and the ⌘K omnibar now surface **every file in your project**, not just markdown notes. Part 1 made the sidebar tree show all files; this extends that to search so the two agree.++- Type part of any filename or folder path in ⌘K to jump to it — `data.csv`, `FileTree.tsx`, an image, a config file — regardless of type. Markdown is still ranked first; non-markdown files match by name and path.+- Folders that contain only non-markdown files are now searchable, and partial folder-path queries (e.g. `server/src`) resolve.+- Tracked dot-path files (`.changeset/`, `.github/`) are searchable (rank-deprioritized) without being sent to the embeddings provider.+- A link to an existing non-markdown file no longer renders dead; a genuinely missing target still does.+- The move/rename and new-file destination pickers list the same all-files set the tree shows.+- The omnibar shows a one-line hint when a query matches only file names (no content), and an empty-results note pointing to the file tree when a query matches nothing.+- MCP `search` returns all files by name/path and points agents at `exec` `grep` for exhaustive content search.+- Intentional hardening: secret-bearing files and directories (`.env*`, SSH private keys including `id_ed25519`/`id_ecdsa`/`id_dsa`, `.netrc`/`.npmrc`/`.pgpass`/`.git-credentials`, `*.pem`/`*.key`/`*.p12`/`*.pfx`/`*.keystore`/`*.jks`/`*.ppk`, and the `.ssh`/`.aws`/`.gnupg`/`.kube`/`.docker` directories) are excluded from **all** surfaces — the Part 1 "Show All Files" tree as well as search and `/api/documents`. The unauthenticated local HTTP API is bindable to non-loopback hosts; closing this name-egress channel is the floor whether or not `.gitignore` covers the path.++The file index now indexes names/paths for all files and full content for markdown only, with ContentFilter kept on (gitignored/build content stays out of search) and a 50,000-entry cap on the name-only tier (`OK_SEARCH_MAX_ENTRIES`).diff --git a/packages/app/src/components/CommandPalette.tsx b/packages/app/src/components/CommandPalette.tsxindex a977b9885..a015ee912 100644--- a/packages/app/src/components/CommandPalette.tsx+++ b/packages/app/src/components/CommandPalette.tsx@@ -38,6 +38,7 @@ import {} from '@/components/command-palette-recents';import {buildWorkspaceEntries,+ classifyOmnibarSearchHint,fetchWorkspaceSearchEntries,matchesCommandQuery,SEMANTIC_RESULT_LIMIT,@@ -155,6 +156,40 @@ function NavigationItem({);}+function SearchHint({+ mode,+ inExclusiveMode,+ paletteModeKind,+}: {+ mode: ReturnType<typeof classifyOmnibarSearchHint>;+ inExclusiveMode: boolean;+ paletteModeKind: 'normal' | 'tag-list' | 'tag-docs';+}) {+ if (inExclusiveMode) return null;+ if (paletteModeKind !== 'normal') return null;+ if (mode === 'idle' || mode === 'content') return null;+ return (+ <div+ aria-live="polite"+ data-testid={`command-palette-search-hint-${mode}`}+ className="border-t px-3 py-2 text-muted-foreground text-xs"+ >+ {mode === 'name-only' ? (+ <Trans>+ Search matches file names, paths, and folders. Open a file to search its body (⌘F).+ </Trans>+ ) : mode === 'truncated' ? (+ <Trans>+ Results capped — this workspace has more files than search can index. A missing file may+ be a cap artifact, not a typo.+ </Trans>+ ) : (+ <Trans>No matches. Some files are excluded from search (hidden or ignored files).</Trans>+ )}+ </div>+ );+}+function HighlightedText({ text, query }: { text: string; query: string }) {const segments = splitTextByQueryMatches(text, query);return (@@ -197,6 +232,7 @@ export function CommandPalette({ bridge = null, open, onOpenChange }: CommandPalconst [searchStatus, setSearchStatus] = useState<'idle' | 'loading' | 'success' | 'error'>('idle',);+ const [searchTruncated, setSearchTruncated] = useState(false);const [isSemanticMode, setIsSemanticMode] = useState(false);const [semanticResults, setSemanticResults] = useState<WorkspaceSearchEntry[]>([]);const [semanticFiredQuery, setSemanticFiredQuery] = useState<string | null>(null);@@ -222,7 +258,7 @@ export function CommandPalette({ bridge = null, open, onOpenChange }: CommandPalconst semanticAbortRef = useRef<AbortController | null>(null);const semanticTimerRef = useRef<number | null>(null);const { activeDocName, activeTarget } = useDocumentContext();- const { pages, pageTitles, pageMeta, folderPaths } = usePageList();+ const { pages, pageTitles, pageMeta, folderPaths, filePaths } = usePageList();const workspace = useWorkspace();const { states: installStates, refresh: refreshInstallStates } = useInstalledAgents();const { dispatch: dispatchHandoff } = useHandoffDispatch();@@ -243,7 +279,13 @@ export function CommandPalette({ bridge = null, open, onOpenChange }: CommandPal}, [open, isSemanticMode, semanticIndexing]);const handoffInput = buildHandoffInput({ docName: activeDocName, workspace });- const workspaceEntries = buildWorkspaceEntries(pages, folderPaths, pageTitles, pageMeta);+ const workspaceEntries = buildWorkspaceEntries(+ pages,+ folderPaths,+ pageTitles,+ pageMeta,+ filePaths,+ );const validRecentKeys = new Set(workspaceEntries.map((entry) => makeOmnibarRecentKey(entry.kind, entry.path)),);@@ -380,6 +422,7 @@ export function CommandPalette({ bridge = null, open, onOpenChange }: CommandPalif (!open || !trimmedDeferredQuery || inExclusiveMode) {setSearchResults([]);setSearchStatus('idle');+ setSearchTruncated(false);return;}@@ -391,12 +434,14 @@ export function CommandPalette({ bridge = null, open, onOpenChange }: CommandPalcontroller.abort();setSearchResults([]);setSearchStatus('error');+ setSearchTruncated(false);}, COMMAND_PALETTE_SEARCH_TIMEOUT_MS);void fetchWorkspaceSearchEntries(trimmedDeferredQuery, { signal: controller.signal })- .then((results) => {+ .then(({ entries, truncated }) => {window.clearTimeout(timeout);- setSearchResults(results);+ setSearchResults(entries);+ setSearchTruncated(truncated);setSearchStatus('success');}).catch((error: unknown) => {@@ -404,6 +449,7 @@ export function CommandPalette({ bridge = null, open, onOpenChange }: CommandPalif (error instanceof Error && error.name === 'AbortError' && !timedOut) return;setSearchResults([]);setSearchStatus('error');+ setSearchTruncated(false);});return () => {@@ -584,9 +630,9 @@ export function CommandPalette({ bridge = null, open, onOpenChange }: CommandPalsemantic: true,limit: SEMANTIC_RESULT_LIMIT,})- .then((results) => {+ .then(({ entries }) => {clearThisFire(timeout, controller);- setSemanticResults(results);+ setSemanticResults(entries);setSemanticFiredQuery(q);setSemanticStatus('success');})@@ -1184,6 +1230,20 @@ export function CommandPalette({ bridge = null, open, onOpenChange }: CommandPal</CommandGroup>) : null}</CommandList>++ {/* Search-hint affordance, rendered OUTSIDE `<CommandList>` (which+ cmdk gives `role="listbox"`; only option/group children are+ valid there) but still INSIDE `CommandDialog` so it shares the+ dialog's framing. Absent when at least one server hit carries a+ body snippet. The empty-query branch (`'idle'`) renders nothing+ so the Recents view is unaffected. */}+ <SearchHint+ mode={classifyOmnibarSearchHint(trimmedDeferredQuery, visibleSearchResults, {+ truncated: searchTruncated,+ })}+ inExclusiveMode={inExclusiveMode}+ paletteModeKind={paletteMode.kind}+ /></CommandDialog><NewItemDialogdiff --git a/packages/app/src/components/PageListContext.tsx b/packages/app/src/components/PageListContext.tsxindex 9522d4f27..eb525f427 100644--- a/packages/app/src/components/PageListContext.tsx+++ b/packages/app/src/components/PageListContext.tsx@@ -25,6 +25,7 @@ interface PageListContextValue {pageMeta: ReadonlyMap<string, PageMeta>;folderPaths: Set<string>;assetPaths: Set<string>;+ filePaths: Set<string>;loading: boolean;error: string | null;refetch: () => void;@@ -43,7 +44,7 @@ interface PageSummary {}interface DocumentListEntry {- kind?: 'document' | 'asset' | 'folder';+ kind?: 'document' | 'asset' | 'folder' | 'file';path?: string;}@@ -95,14 +96,18 @@ async function loadPages(): Promise<PageSummary[]> {return [];}-async function loadDocumentListSummary(): Promise<{ assetPaths: string[]; folderPaths: string[] }> {+async function loadDocumentListSummary(): Promise<{+ assetPaths: string[];+ folderPaths: string[];+ filePaths: string[];+}> {const r = await fetch('/api/documents');if (!r.ok) {const body = (await r.json().catch(() => null)) as unknown;throw new Error(parseApiError(body) ?? `/api/documents responded with ${r.status}`);}const data: { documents?: DocumentListEntry[] } = await r.json();- if (!Array.isArray(data.documents)) return { assetPaths: [], folderPaths: [] };+ if (!Array.isArray(data.documents)) return { assetPaths: [], folderPaths: [], filePaths: [] };const assetPaths = data.documents.filter((entry): entry is DocumentListEntry & { kind: 'asset'; path: string } => {return entry.kind === 'asset' && typeof entry.path === 'string' && entry.path.length > 0;@@ -113,7 +118,12 @@ async function loadDocumentListSummary(): Promise<{ assetPaths: string[]; folderreturn entry.kind === 'folder' && typeof entry.path === 'string' && entry.path.length > 0;}).map((entry) => entry.path);- return { assetPaths, folderPaths };+ const filePaths = data.documents+ .filter((entry): entry is DocumentListEntry & { kind: 'file'; path: string } => {+ return entry.kind === 'file' && typeof entry.path === 'string' && entry.path.length > 0;+ })+ .map((entry) => entry.path);+ return { assetPaths, folderPaths, filePaths };}function logLoadPagesError(err: unknown) {@@ -130,6 +140,7 @@ export function PageListProvider({ children }: { children: ReactNode }) {const [serverPageMeta, setServerPageMeta] = useState(new Map<string, PageMeta>());const [serverAssetPaths, setServerAssetPaths] = useState(new Set<string>());const [serverFolderPaths, setServerFolderPaths] = useState(new Set<string>());+ const [serverFilePaths, setServerFilePaths] = useState(new Set<string>());const [optimisticPages, setOptimisticPages] = useState(new Set<string>());const [loading, setLoading] = useState(true);const [error, setError] = useState<string | null>(null);@@ -141,7 +152,7 @@ export function PageListProvider({ children }: { children: ReactNode }) {loadPages(),loadDocumentListSummary().catch((err) => {logLoadAssetsError(err);- return { assetPaths: [], folderPaths: [] };+ return { assetPaths: [], folderPaths: [], filePaths: [] };}),]).then(([pageSummaries, documentList]) => {@@ -169,6 +180,7 @@ export function PageListProvider({ children }: { children: ReactNode }) {);setServerAssetPaths(new Set(documentList.assetPaths));setServerFolderPaths(new Set(documentList.folderPaths));+ setServerFilePaths(new Set(documentList.filePaths));setOptimisticPages((prev) => pruneConfirmedOptimisticPages(prev, pageNames));setError(null);})@@ -219,6 +231,7 @@ export function PageListProvider({ children }: { children: ReactNode }) {const pageTitles = mergePageTitles(serverPageTitles, optimisticPages);const pageMeta: ReadonlyMap<string, PageMeta> = serverPageMeta;const assetPaths = serverAssetPaths;+ const filePaths = serverFilePaths;const folderPaths = new Set([...deriveKnownFolderPaths(pages), ...serverFolderPaths]);const pagesBySlug = buildPagesBySlugIndex(pages, toWikiLinkSlug);const pagesByBasename = buildPagesByBasenameIndex(pages, toWikiLinkSlug);@@ -231,9 +244,10 @@ export function PageListProvider({ children }: { children: ReactNode }) {pagesBySlug,pagesByBasename,assetPaths,+ filePaths,pageIcons,});- }, [pages, folderPaths, pagesBySlug, pagesByBasename, assetPaths, pageIcons]);+ }, [pages, folderPaths, pagesBySlug, pagesByBasename, assetPaths, filePaths, pageIcons]);return (<PageListContext@@ -245,6 +259,7 @@ export function PageListProvider({ children }: { children: ReactNode }) {pageMeta,folderPaths,assetPaths,+ filePaths,loading,error,refetch,diff --git a/packages/app/src/components/command-palette-search.test.ts b/packages/app/src/components/command-palette-search.test.tsindex 61ff4f285..80468ab74 100644--- a/packages/app/src/components/command-palette-search.test.ts+++ b/packages/app/src/components/command-palette-search.test.ts@@ -1,11 +1,14 @@import { afterEach, describe, expect, test } from 'bun:test';import {buildWorkspaceEntries,+ classifyOmnibarSearchHint,EMPTY_QUERY_NAV_LIMIT,fetchWorkspaceSearchEntries,matchesCommandQuery,searchWorkspaceEntries,splitTextByQueryMatches,+ type WorkspaceEntry,+ type WorkspaceSearchEntry,} from './command-palette-search';const originalFetch = globalThis.fetch;@@ -29,6 +32,75 @@ describe('buildWorkspaceEntries', () => {{ kind: 'file', path: 'notes/zebra', name: 'zebra' },]);});+ test('admits non-markdown filePaths as kind:file entries with bodyIndexed:false', () => {+ const entries = buildWorkspaceEntries(+ new Set(['notes/guide']),+ new Set(['notes']),+ new Map(),+ new Map(),+ new Set(['data/example.csv', 'packages/app/src/index.ts']),+ );++ expect(entries).toEqual([+ { kind: 'file', path: 'data/example.csv', name: 'example.csv', bodyIndexed: false },+ { kind: 'folder', path: 'notes', name: 'notes' },+ { kind: 'file', path: 'notes/guide', name: 'guide' },+ {+ kind: 'file',+ path: 'packages/app/src/index.ts',+ name: 'index.ts',+ bodyIndexed: false,+ },+ ]);+ });+ test('skips a non-markdown file already present in pages', () => {+ const entries = buildWorkspaceEntries(+ new Set(['data/example.csv']),+ new Set(),+ new Map(),+ new Map(),+ new Set(['data/example.csv']),+ );+ expect(entries).toEqual([{ kind: 'file', path: 'data/example.csv', name: 'example.csv' }]);+ });+});++describe('searchWorkspaceEntries with non-markdown files', () => {+ const entries = buildWorkspaceEntries(+ new Set(['notes/guide', 'roadmap']),+ new Set(['notes', 'docs']),+ new Map(),+ new Map(),+ new Set(['data/example.csv', 'packages/app/src/components/FileTree.tsx']),+ );++ test('finds a non-markdown file by basename', () => {+ const results = searchWorkspaceEntries(entries, 'FileTree');+ expect(results.map((entry) => entry.path)).toContain(+ 'packages/app/src/components/FileTree.tsx',+ );+ });++ test('finds a non-markdown file by extension', () => {+ const results = searchWorkspaceEntries(entries, 'csv');+ expect(results.map((entry) => entry.path)).toContain('data/example.csv');+ });++ test('finds a non-markdown file by partial folder path', () => {+ const results = searchWorkspaceEntries(entries, 'components');+ expect(results.map((entry) => entry.path)).toContain(+ 'packages/app/src/components/FileTree.tsx',+ );+ });++ test('a markdown page maps to the page tier and outranks a lexically-tied non-markdown sibling', () => {+ const tieEntries: WorkspaceEntry[] = [+ { kind: 'file', path: 'data/alpha', name: 'alpha', bodyIndexed: false },+ { kind: 'file', path: 'notes/alpha', name: 'alpha' },+ ];+ const results = searchWorkspaceEntries(tieEntries, 'alpha');+ expect(results[0]).toEqual({ kind: 'file', path: 'notes/alpha', name: 'alpha' });+ });});describe('searchWorkspaceEntries', () => {@@ -65,6 +137,76 @@ describe('searchWorkspaceEntries', () => {});});+describe('classifyOmnibarSearchHint', () => {+ test('idle on empty / whitespace query regardless of results', () => {+ expect(classifyOmnibarSearchHint('', [])).toBe('idle');+ expect(classifyOmnibarSearchHint(' ', [])).toBe('idle');+ const someResults: WorkspaceEntry[] = [{ kind: 'file', path: 'notes/foo', name: 'foo' }];+ expect(classifyOmnibarSearchHint('', someResults)).toBe('idle');+ });++ test('empty on non-empty query with zero results', () => {+ expect(classifyOmnibarSearchHint('mystery', [])).toBe('empty');+ });++ test('name-only when results exist but no entry carries a snippet', () => {+ const results: WorkspaceEntry[] = [+ { kind: 'file', path: 'notes/foo', name: 'foo' },+ { kind: 'folder', path: 'notes', name: 'notes' },+ { kind: 'file', path: 'data/example.csv', name: 'example.csv', bodyIndexed: false },+ ];+ expect(classifyOmnibarSearchHint('foo', results)).toBe('name-only');+ });++ test('content when at least one entry carries a non-empty snippet', () => {+ const results: WorkspaceSearchEntry[] = [+ {+ kind: 'file',+ path: 'notes/foo',+ name: 'foo',+ snippet: '… the matched body fragment …',+ },+ ];+ expect(classifyOmnibarSearchHint('matched', results)).toBe('content');+ });++ test('an empty-string snippet does NOT count as a content hit', () => {+ const results: WorkspaceSearchEntry[] = [+ { kind: 'file', path: 'notes/foo', name: 'foo', snippet: '' },+ ];+ expect(classifyOmnibarSearchHint('foo', results)).toBe('name-only');+ });++ test('mixed name-only + one content hit still classifies as content (hint absent)', () => {+ const results: Array<WorkspaceEntry | WorkspaceSearchEntry> = [+ { kind: 'folder', path: 'docs', name: 'docs' },+ { kind: 'file', path: 'notes/x', name: 'x' },+ { kind: 'file', path: 'notes/body-match', name: 'body-match', snippet: '… excerpt …' },+ ];+ expect(classifyOmnibarSearchHint('excerpt', results)).toBe('content');+ });++ test('truncated:true overrides name-only when there are results', () => {+ const results: WorkspaceEntry[] = [{ kind: 'file', path: 'notes/foo', name: 'foo' }];+ expect(classifyOmnibarSearchHint('foo', results, { truncated: true })).toBe('truncated');+ });++ test('truncated:true overrides content when at least one snippet is present', () => {+ const results: WorkspaceSearchEntry[] = [+ { kind: 'file', path: 'notes/foo', name: 'foo', snippet: '… match …' },+ ];+ expect(classifyOmnibarSearchHint('match', results, { truncated: true })).toBe('truncated');+ });++ test('truncated does NOT override empty (no surviving results means no surface to point at)', () => {+ expect(classifyOmnibarSearchHint('foo', [], { truncated: true })).toBe('empty');+ });++ test('truncated does NOT override idle (no query → no hint at all)', () => {+ expect(classifyOmnibarSearchHint('', [], { truncated: true })).toBe('idle');+ });+});+describe('matchesCommandQuery', () => {test('matches empty query', () => {expect(matchesCommandQuery('New file', '')).toBe(true);@@ -120,16 +262,16 @@ describe('fetchWorkspaceSearchEntries', () => {);}) as typeof fetch;- const results = await fetchWorkspaceSearchEntries('homepage');+ const { entries, truncated } = await fetchWorkspaceSearchEntries('homepage');expect(requestBody).toEqual({query: 'homepage',intent: 'full_text',- scopes: ['page', 'folder', 'content'],+ scopes: ['page', 'folder', 'content', 'file'],limit: 30,source: 'omnibar',});- expect(results).toEqual([+ expect(entries).toEqual([{kind: 'file',path: 'THIRD_PARTY_NOTICES',@@ -140,6 +282,7 @@ describe('fetchWorkspaceSearchEntries', () => {},{ kind: 'folder', path: 'docs', name: 'docs', title: 'docs', score: 12 },]);+ expect(truncated).toBe(false);});test('semantic submit adds semantic:true (keeps full_text + scopes + source:omnibar)', async () => {@@ -154,10 +297,48 @@ describe('fetchWorkspaceSearchEntries', () => {expect(requestBody).toEqual({query: 'auth retries',intent: 'full_text',- scopes: ['page', 'folder', 'content'],+ scopes: ['page', 'folder', 'content', 'file'],limit: 30,source: 'omnibar',semantic: true,});});++ test('maps a kind:file server row to a client kind:file entry', async () => {+ globalThis.fetch = (async () =>+ new Response(+ JSON.stringify({+ results: [+ {+ kind: 'file',+ path: 'data/example.csv',+ title: 'data/example.csv',+ score: 7,+ },+ ],+ }),+ { status: 200 },+ )) as typeof fetch;++ const { entries } = await fetchWorkspaceSearchEntries('csv');++ expect(entries).toEqual([+ {+ kind: 'file',+ path: 'data/example.csv',+ name: 'example.csv',+ title: 'data/example.csv',+ score: 7,+ },+ ]);+ });++ test('threads `truncated:true` from the server response into the result', async () => {+ globalThis.fetch = (async () =>+ new Response(JSON.stringify({ results: [], truncated: true }), {+ status: 200,+ })) as typeof fetch;+ const { truncated } = await fetchWorkspaceSearchEntries('overflowing');+ expect(truncated).toBe(true);+ });});diff --git a/packages/app/src/components/command-palette-search.ts b/packages/app/src/components/command-palette-search.tsindex 304086188..ba809a164 100644--- a/packages/app/src/components/command-palette-search.ts+++ b/packages/app/src/components/command-palette-search.ts@@ -15,6 +15,7 @@ export interface WorkspaceEntry {name: string;title?: string;modifiedTs?: number;+ bodyIndexed?: boolean;}export interface WorkspaceSearchEntry extends WorkspaceEntry {@@ -61,10 +62,13 @@ export function buildWorkspaceEntries(folderPaths: ReadonlySet<string>,pageTitles: ReadonlyMap<string, string> = new Map(),pageMeta: ReadonlyMap<string, PageMeta> = new Map(),+ filePaths: ReadonlySet<string> = new Set(),): WorkspaceEntry[] {const entries: WorkspaceEntry[] = [];+ const seenFilePaths = new Set<string>();for (const path of pages) {+ seenFilePaths.add(path);const modified = pageMeta.get(path)?.modified;const title = pageTitles.get(path);entries.push({@@ -75,6 +79,16 @@ export function buildWorkspaceEntries(...(modified ? { modifiedTs: Date.parse(modified) } : {}),});}+ for (const path of filePaths) {+ if (seenFilePaths.has(path)) continue;+ seenFilePaths.add(path);+ entries.push({+ kind: 'file',+ path,+ name: workspaceSearchBasename(path),+ bodyIndexed: false,+ });+ }for (const path of folderPaths) {entries.push({ kind: 'folder', path, name: workspaceSearchBasename(path) });}@@ -90,8 +104,10 @@ export function buildWorkspaceEntries(}function toSearchDocument(entry: WorkspaceEntry): WorkspaceSearchDocument {+ const searchKind: 'page' | 'folder' | 'file' =+ entry.kind === 'folder' ? 'folder' : entry.bodyIndexed === false ? 'file' : 'page';return createWorkspaceSearchDocument({- kind: entry.kind === 'file' ? 'page' : 'folder',+ kind: searchKind,path: entry.path,title: entry.title ?? entry.name,modifiedTs: entry.modifiedTs ?? 0,@@ -102,7 +118,11 @@ function buildWorkspaceEntrySearchCorpus(entries: readonly WorkspaceEntry[],): WorkspaceEntrySearchCorpus {const byId = new Map(- entries.map((entry) => [`${entry.kind === 'file' ? 'page' : 'folder'}:${entry.path}`, entry]),+ entries.map((entry) => {+ const searchKind: 'page' | 'folder' | 'file' =+ entry.kind === 'folder' ? 'folder' : entry.bodyIndexed === false ? 'file' : 'page';+ return [`${searchKind}:${entry.path}`, entry];+ }),);return {entries,@@ -115,7 +135,7 @@ function workspaceEntriesFingerprint(entries: readonly WorkspaceEntry[]): stringreturn entries.map((entry) =>- `${entry.kind}\u0000${entry.path}\u0000${entry.title ?? ''}\u0000${entry.modifiedTs ?? 0}`,+ `${entry.kind}\u0000${entry.path}\u0000${entry.title ?? ''}\u0000${entry.modifiedTs ?? 0} ${entry.bodyIndexed === false ? '0' : '1'}`,).join('\u0001');}@@ -153,7 +173,7 @@ function searchWorkspaceEntryCorpus(return searchWorkspaceCorpus(entryCorpus.corpus, normalizedQuery, {intent: 'omnibar',limit,- scopes: ['page', 'folder'],+ scopes: ['page', 'folder', 'file'],}).map((result) => entryCorpus.byId.get(result.document.id)).filter((entry): entry is WorkspaceEntry => entry !== undefined);@@ -188,15 +208,26 @@ interface WorkspaceSearchApiResponse {snippet?: string;score?: number;}>;+ truncated?: boolean;+}++export interface WorkspaceSearchFetchResult {+ entries: WorkspaceSearchEntry[];+ truncated: boolean;}function toWorkspaceSearchEntry(row: NonNullable<WorkspaceSearchApiResponse['results']>[number],): WorkspaceSearchEntry | null {- if ((row.kind !== 'page' && row.kind !== 'folder') || typeof row.path !== 'string') return null;+ if (+ (row.kind !== 'page' && row.kind !== 'folder' && row.kind !== 'file') ||+ typeof row.path !== 'string'+ ) {+ return null;+ }const name = workspaceSearchBasename(row.path);return {- kind: row.kind === 'page' ? 'file' : 'folder',+ kind: row.kind === 'folder' ? 'folder' : 'file',path: row.path,name,...(row.title && { title: row.title }),@@ -208,9 +239,9 @@ function toWorkspaceSearchEntry(export async function fetchWorkspaceSearchEntries(query: string,options: { signal?: AbortSignal; limit?: number; semantic?: boolean } = {},-): Promise<WorkspaceSearchEntry[]> {+): Promise<WorkspaceSearchFetchResult> {const normalizedQuery = query.trim();- if (!normalizedQuery) return [];+ if (!normalizedQuery) return { entries: [], truncated: false };const response = await fetch('/api/search', {method: 'POST',@@ -218,7 +249,7 @@ export async function fetchWorkspaceSearchEntries(body: JSON.stringify({query: normalizedQuery,intent: 'full_text',- scopes: ['page', 'folder', 'content'],+ scopes: ['page', 'folder', 'content', 'file'],limit: options.limit ?? API_SEARCH_LIMIT,source: 'omnibar',...(options.semantic ? { semantic: true } : {}),@@ -231,8 +262,9 @@ export async function fetchWorkspaceSearchEntries(}const payload = (await response.json()) as WorkspaceSearchApiResponse;+ const entries = (payload.results ?? []).map(toWorkspaceSearchEntry).filter((entry) => !!entry);- return (payload.results ?? []).map(toWorkspaceSearchEntry).filter((entry) => !!entry);+ return { entries, truncated: payload.truncated === true };}export function matchesCommandQuery(@@ -245,3 +277,21 @@ export function matchesCommandQuery(const haystack = normalize([label, ...keywords].join(' '));return haystack.includes(normalizedQuery);}++export type OmnibarSearchHintMode = 'idle' | 'content' | 'name-only' | 'empty' | 'truncated';++export function classifyOmnibarSearchHint(+ query: string,+ visibleResults: readonly (WorkspaceEntry | WorkspaceSearchEntry)[],+ options: { truncated?: boolean } = {},+): OmnibarSearchHintMode {+ if (query.trim() === '') return 'idle';+ if (visibleResults.length === 0) return 'empty';+ if (options.truncated) return 'truncated';+ for (const entry of visibleResults) {+ if ('snippet' in entry && typeof entry.snippet === 'string' && entry.snippet.length > 0) {+ return 'content';+ }+ }+ return 'name-only';+}diff --git a/packages/app/src/components/file-tree-utils.ts b/packages/app/src/components/file-tree-utils.tsindex f6783ead2..7078d3f33 100644--- a/packages/app/src/components/file-tree-utils.ts+++ b/packages/app/src/components/file-tree-utils.ts@@ -80,6 +80,22 @@ export function toFileEntries(entries: readonly DocumentListEntry[]): FileEntry[referencedBy: entry.referencedBy,});break;+ case 'file': {+ if (entry.path === undefined) {+ dropped += 1;+ break;+ }+ mapped.push({+ kind: 'asset',+ path: entry.path,+ assetExt: entry.assetExt ?? synthesizeFileAssetExt(entry.path),+ mediaKind: null,+ size: entry.size,+ modified: entry.modified,+ referencedBy: [],+ });+ break;+ }case 'folder':if (entry.path === undefined) {dropped += 1;@@ -107,6 +123,16 @@ export function toFileEntries(entries: readonly DocumentListEntry[]): FileEntry[return mapped;}+function synthesizeFileAssetExt(path: string): string {+ const basename = path.includes('/') ? (path.split('/').pop() ?? path) : path;+ const dotIndex = basename.lastIndexOf('.');+ if (dotIndex > 0 && dotIndex < basename.length - 1) {+ return basename.slice(dotIndex + 1).toLowerCase();+ }+ if (basename.startsWith('.') && basename.length > 1) return basename.slice(1).toLowerCase();+ return 'file';+}+export function computeAncestors(docName: string | null): string[] {if (!docName) return [];const segments = docName.split('/').filter(Boolean);diff --git a/packages/app/src/editor/extensions/WikiLinkPropPanel.tsx b/packages/app/src/editor/extensions/WikiLinkPropPanel.tsxindex 217bd7815..a3afda29b 100644--- a/packages/app/src/editor/extensions/WikiLinkPropPanel.tsx+++ b/packages/app/src/editor/extensions/WikiLinkPropPanel.tsx@@ -60,6 +60,7 @@ interface EditWikiLinkDialogProps {anchor: string | null;pages: Set<string>;assetPaths: Set<string>;+ filePaths: Set<string>;loading: boolean;onOpenChange: (open: boolean) => void;onSave: (target: string, alias: string | null, anchor: string | null) => void;@@ -72,6 +73,7 @@ function EditWikiLinkDialog({anchor,pages,assetPaths,+ filePaths,loading,onOpenChange,onSave,@@ -85,8 +87,8 @@ function EditWikiLinkDialog({const headingListId = useId();const { t } = useLingui();- const editAssetPath = resolveWikiLinkAssetTarget(editTarget, assetPaths);- const isEditTargetResolved = isResolvedWikiLinkTarget(editTarget, pages, assetPaths);+ const editAssetPath = resolveWikiLinkAssetTarget(editTarget, assetPaths, filePaths);+ const isEditTargetResolved = isResolvedWikiLinkTarget(editTarget, pages, assetPaths, filePaths);const headings = useHeadings(editTarget, isEditTargetResolved && !editAssetPath && open);const prevOpenRef = useRef(false);@@ -270,13 +272,21 @@ export function WikiLinkPropPanel({ editor, getPos, onClose, onNavigate }: WikiLconst anchor = normalizeNullableString(node?.attrs.anchor);const label = getWikiLinkText({ target, alias, anchor });- const { addPage, assetPaths, folderPaths, pages, pagesBySlug, pagesByBasename, loading } =- usePageList();+ const {+ addPage,+ assetPaths,+ filePaths,+ folderPaths,+ pages,+ pagesBySlug,+ pagesByBasename,+ loading,+ } = usePageList();const classifiedTarget = classifyWikiLinkTarget(target, anchor);const externalTarget = classifiedTarget?.kind === 'external' ? classifiedTarget : null;const assetPath =classifiedTarget?.kind === 'asset'- ? (resolveWikiLinkAssetTarget(classifiedTarget.url, assetPaths) ??+ ? (resolveWikiLinkAssetTarget(classifiedTarget.url, assetPaths, filePaths) ??classifiedTarget.url.replace(/^\//, '')): null;const linkIntent = assetPath@@ -570,6 +580,7 @@ export function WikiLinkPropPanel({ editor, getPos, onClose, onNavigate }: WikiLanchor={anchor}pages={pages}assetPaths={assetPaths}+ filePaths={filePaths}loading={loading}onOpenChange={setEditDialogOpen}onSave={handleSaveEdit}diff --git a/packages/app/src/editor/extensions/internal-link.ts b/packages/app/src/editor/extensions/internal-link.tsindex 24b37469d..e222db812 100644--- a/packages/app/src/editor/extensions/internal-link.ts+++ b/packages/app/src/editor/extensions/internal-link.ts@@ -79,11 +79,10 @@ export const InternalLink = LinkFidelity.extend<InternalLinkOptions>({}const cache = getPageListCache();if (cache === null) return false;- if (- cache.assetPaths !== undefined &&- !isResolvedAssetHref(url, docName, cache.assetPaths)- ) {- return false;+ if (cache.assetPaths !== undefined || cache.filePaths !== undefined) {+ if (!isResolvedAssetHref(url, docName, cache.assetPaths, cache.filePaths)) {+ return false;+ }}activateAssetLink({url,diff --git a/packages/app/src/editor/extensions/link-resolution.test.ts b/packages/app/src/editor/extensions/link-resolution.test.tsindex 6f81c39ba..ea9a479c8 100644--- a/packages/app/src/editor/extensions/link-resolution.test.ts+++ b/packages/app/src/editor/extensions/link-resolution.test.ts@@ -12,12 +12,14 @@ function makeCache(opts: {pages?: Iterable<string>;folderPaths?: Iterable<string>;assetPaths?: Iterable<string>;+ filePaths?: Iterable<string>;}): PageListCacheSnapshot {const pages = new Set(opts.pages ?? []);return {pages,folderPaths: new Set(opts.folderPaths ?? []),assetPaths: opts.assetPaths === undefined ? undefined : new Set(opts.assetPaths),+ filePaths: opts.filePaths === undefined ? undefined : new Set(opts.filePaths),pagesBySlug: buildPagesBySlugIndex(pages, toWikiLinkSlug),};}@@ -141,6 +143,26 @@ describe('computeLinkResolutionState', () => {expect(computeLinkResolutionState('./Characters.base', 'vault/note', cache)).toBe('unresolved');});+ test('relative non-asset file href resolves against filePaths', () => {+ const cache = makeCache({ pages: [], assetPaths: [], filePaths: ['data/example.csv'] });+ expect(computeLinkResolutionState('./data/example.csv', 'README', cache)).toBe('asset');+ });++ test('relative non-asset file href that is missing renders unresolved', () => {+ const cache = makeCache({ pages: [], assetPaths: [], filePaths: ['data/example.csv'] });+ expect(computeLinkResolutionState('./data/missing.csv', 'README', cache)).toBe('unresolved');+ });++ test('non-asset file href stays optimistic when BOTH partitions absent (cold cache)', () => {+ const cache = makeCache({ pages: [] });+ expect(computeLinkResolutionState('./data/example.csv', 'README', cache)).toBe('asset');+ });++ test('non-asset file href is unresolved when only assetPaths is set (no filePaths) and target missing', () => {+ const cache = makeCache({ pages: [], assetPaths: [] });+ expect(computeLinkResolutionState('./data/example.csv', 'README', cache)).toBe('unresolved');+ });+test('doc href with cache, target is folder → folder', () => {const cache = makeCache({ pages: [], folderPaths: ['subfolder'] });expect(computeLinkResolutionState('./subfolder', 'README', cache)).toBe('folder');diff --git a/packages/app/src/editor/extensions/link-resolution.ts b/packages/app/src/editor/extensions/link-resolution.tsindex 3c441d5bb..ff6b308b0 100644--- a/packages/app/src/editor/extensions/link-resolution.ts+++ b/packages/app/src/editor/extensions/link-resolution.ts@@ -25,10 +25,13 @@ export function isResolvedAssetHref(href: string,sourceDocName: string,assetPaths: ReadonlySet<string> | undefined,+ filePaths?: ReadonlySet<string> | undefined,): boolean {- if (!assetPaths) return false;const projectRelPath = resolveAssetProjectPath(href, sourceDocName);- return projectRelPath !== null && setHasPathCaseInsensitive(assetPaths, projectRelPath);+ if (projectRelPath === null) return false;+ if (assetPaths && setHasPathCaseInsensitive(assetPaths, projectRelPath)) return true;+ if (filePaths && setHasPathCaseInsensitive(filePaths, projectRelPath)) return true;+ return false;}export function computeLinkResolutionState(@@ -44,8 +47,8 @@ export function computeLinkResolutionState(if (cache === null) return 'loading';if (target.kind === 'asset') {- if (cache.assetPaths === undefined) return 'asset';- return isResolvedAssetHref(target.url, sourceDocName, cache.assetPaths)+ if (cache.assetPaths === undefined && cache.filePaths === undefined) return 'asset';+ return isResolvedAssetHref(target.url, sourceDocName, cache.assetPaths, cache.filePaths)? 'asset': 'unresolved';}diff --git a/packages/app/src/editor/extensions/wiki-link-helpers.test.ts b/packages/app/src/editor/extensions/wiki-link-helpers.test.tsindex d4f34be44..09862fdb3 100644--- a/packages/app/src/editor/extensions/wiki-link-helpers.test.ts+++ b/packages/app/src/editor/extensions/wiki-link-helpers.test.ts@@ -77,6 +77,72 @@ describe('resolveWikiLinkAssetTarget', () => {});});+describe('resolveWikiLinkAssetTarget — file-paths partition', () => {+ test('resolves a tracked non-markdown file by exact path', () => {+ const assets = new Set<string>();+ const files = new Set(['data/example.csv']);+ expect(resolveWikiLinkAssetTarget('data/example.csv', assets, files)).toBe('data/example.csv');+ });++ test('resolves a tracked non-markdown file by leading-slash content path', () => {+ const assets = new Set<string>();+ const files = new Set(['data/example.csv']);+ expect(resolveWikiLinkAssetTarget('/data/example.csv', assets, files)).toBe('data/example.csv');+ });++ test('resolves a tracked non-markdown file by case-insensitive basename', () => {+ const assets = new Set<string>();+ const files = new Set(['packages/app/src/components/FileTree.tsx']);+ expect(resolveWikiLinkAssetTarget('FileTree.tsx', assets, files)).toBe(+ 'packages/app/src/components/FileTree.tsx',+ );+ expect(resolveWikiLinkAssetTarget('filetree.tsx', assets, files)).toBe(+ 'packages/app/src/components/FileTree.tsx',+ );+ });++ test('returns null when the target is not in either partition', () => {+ const assets = new Set(['images/diagram.png']);+ const files = new Set(['data/example.csv']);+ expect(resolveWikiLinkAssetTarget('missing.csv', assets, files)).toBeNull();+ });++ test('asset partition still wins when both partitions hold the target path', () => {+ const assets = new Set(['shared.png']);+ const files = new Set(['shared.png']);+ expect(resolveWikiLinkAssetTarget('shared.png', assets, files)).toBe('shared.png');+ });+});++describe('isResolvedWikiLinkTarget — non-markdown file existence (US-009)', () => {+ test('a tracked non-markdown file resolves as existing', () => {+ const pages = new Set(['notes/guide']);+ const assets = new Set<string>();+ const files = new Set(['data/example.csv']);+ expect(isResolvedWikiLinkTarget('data/example.csv', pages, assets, files)).toBe(true);+ });++ test('a NOT-tracked non-markdown file renders as missing', () => {+ const pages = new Set(['notes/guide']);+ const assets = new Set<string>();+ const files = new Set(['data/example.csv']);+ expect(isResolvedWikiLinkTarget('data/missing.csv', pages, assets, files)).toBe(false);+ });++ test('non-markdown file resolution composes with the snapshot input shape', () => {+ const snapshot = {+ pages: new Set<string>(),+ folderPaths: new Set<string>(),+ pagesBySlug: new Map<string, string>(),+ pagesByBasename: new Map<string, string>(),+ assetPaths: new Set<string>(),+ filePaths: new Set(['data/example.csv']),+ };+ expect(isResolvedWikiLinkTarget('data/example.csv', snapshot)).toBe(true);+ expect(isResolvedWikiLinkTarget('data/missing.csv', snapshot)).toBe(false);+ });+});+describe('isResolvedWikiLinkTarget — case-insensitive resolution against case-preserved pages cache', () => {test('lowercased slug resolves against case-preserved cache entry', () => {const pages = new Set(['README']);diff --git a/packages/app/src/editor/extensions/wiki-link-helpers.ts b/packages/app/src/editor/extensions/wiki-link-helpers.tsindex 9b933b04a..184c22f35 100644--- a/packages/app/src/editor/extensions/wiki-link-helpers.ts+++ b/packages/app/src/editor/extensions/wiki-link-helpers.ts@@ -17,6 +17,10 @@ function getAssetPathsSet(input: PagesLookupInput, assetPaths?: ReadonlySet<strireturn isSnapshot(input) ? (input.assetPaths ?? new Set<string>()) : (assetPaths ?? new Set());}+function getFilePathsSet(input: PagesLookupInput, filePaths?: ReadonlySet<string>) {+ return isSnapshot(input) ? (input.filePaths ?? new Set<string>()) : (filePaths ?? new Set());+}+function slugLookup(target: string, input: PagesLookupInput): string | undefined {const targetSlug = toWikiLinkSlug(target);if (!targetSlug) return undefined;@@ -125,22 +129,32 @@ function normalizeAssetTarget(target: string): string {export function resolveWikiLinkAssetTarget(target: string,assetPaths: ReadonlySet<string>,+ filePaths?: ReadonlySet<string>,): string | null {const normalized = normalizeAssetTarget(target);if (!normalized) return null;- if (assetPaths.has(normalized)) return normalized;const lowerTarget = normalized.toLowerCase();- for (const path of assetPaths) {- if (path.toLowerCase() === lowerTarget) return path;+ const partitions: ReadonlyArray<ReadonlySet<string>> = filePaths+ ? [assetPaths, filePaths]+ : [assetPaths];++ for (const partition of partitions) {+ if (partition.has(normalized)) return normalized;+ for (const path of partition) {+ if (path.toLowerCase() === lowerTarget) return path;+ }}if (normalized.includes('/')) return null;- const matches = [...assetPaths].filter((path) => {- const slash = path.lastIndexOf('/');- const basename = slash === -1 ? path : path.slice(slash + 1);- return basename.toLowerCase() === lowerTarget;- });+ const matches: string[] = [];+ for (const partition of partitions) {+ for (const path of partition) {+ const slash = path.lastIndexOf('/');+ const basename = slash === -1 ? path : path.slice(slash + 1);+ if (basename.toLowerCase() === lowerTarget) matches.push(path);+ }+ }if (matches.length === 0) return null;return matches.sort((a, b) => a.localeCompare(b))[0] ?? null;}@@ -149,10 +163,19 @@ export function isResolvedWikiLinkTarget(target: string,pages: PagesLookupInput,assetPaths?: ReadonlySet<string>,+ filePaths?: ReadonlySet<string>,): boolean {const trimmed = target.trim();if (!trimmed) return false;- if (resolveWikiLinkAssetTarget(trimmed, getAssetPathsSet(pages, assetPaths))) return true;+ if (+ resolveWikiLinkAssetTarget(+ trimmed,+ getAssetPathsSet(pages, assetPaths),+ getFilePathsSet(pages, filePaths),+ )+ ) {+ return true;+ }const pagesSet = getPagesSet(pages);if (pagesSet.has(trimmed)) return true;diff --git a/packages/app/src/editor/extensions/wiki-link.ts b/packages/app/src/editor/extensions/wiki-link.tsindex 9976606a7..fac9aed90 100644--- a/packages/app/src/editor/extensions/wiki-link.ts+++ b/packages/app/src/editor/extensions/wiki-link.ts@@ -192,10 +192,12 @@ export const WikiLink = BaseWikiLink.extend<{ docName: string }>({return true;}if (classified.kind === 'asset') {+ const cache = getPageListCache();const assetPath =resolveWikiLinkAssetTarget(classified.url,- getPageListCache()?.assetPaths ?? new Set<string>(),+ cache?.assetPaths ?? new Set<string>(),+ cache?.filePaths,) ?? classified.url.replace(/^\//, '');if (newTab) {openHashHrefInNewTab(hashFromAssetPath(assetPath));diff --git a/packages/app/src/editor/page-list-cache.ts b/packages/app/src/editor/page-list-cache.tsindex 6eedcbd13..81507857e 100644--- a/packages/app/src/editor/page-list-cache.ts+++ b/packages/app/src/editor/page-list-cache.ts@@ -2,6 +2,7 @@ export interface PageListCacheSnapshot {readonly pages: ReadonlySet<string>;readonly folderPaths: ReadonlySet<string>;readonly assetPaths?: ReadonlySet<string>;+ readonly filePaths?: ReadonlySet<string>;readonly pageIcons?: ReadonlyMap<string, string>;readonly pagesBySlug: ReadonlyMap<string, string>;@@ -33,6 +34,7 @@ export function snapshotsEqual(setsEqual(prev.pages, next.pages) &&setsEqual(prev.folderPaths, next.folderPaths) &&setsEqual(prev.assetPaths ?? new Set(), next.assetPaths ?? new Set()) &&+ setsEqual(prev.filePaths ?? new Set(), next.filePaths ?? new Set()) &&pageIconsEqual(prev.pageIcons, next.pageIcons));}diff --git a/packages/app/src/locales/en/messages.json b/packages/app/src/locales/en/messages.jsonindex a803ab02b..008bd8e13 100644--- a/packages/app/src/locales/en/messages.json+++ b/packages/app/src/locales/en/messages.json@@ -23,7 +23,13 @@"-gdcIo": ["Auto-sync is on — your commits push and remote changes pull on intervals."],"-i7ik4": ["Collapse burst ", ["burstNumber"], " diff"],"-lCAuQ": ["Loading graph"],+ "-q4abP": [+ "Results capped — this workspace has more files than search can index. A missing file may be a cap artifact, not a typo."+ ],"-slrNR": ["Toggle a task list."],+ "-wePNM": [+ "Search matches file names, paths, and folders. Open a file to search its body (⌘F)."+ ],"0-31GV": ["Removing"],"02P3hL": ["Upload failed: ", ["message"]],"04RA0-": ["Failed to enable sync — ", ["detail"]],@@ -466,6 +472,7 @@"DPfwMq": ["Done"],"DVh_Tb": ["Failed to clean up after trash"],"D_WKe_": ["Click an agent's avatar in the presence bar to view their session."],+ "DbILZA": ["No matches. Some files are excluded from search (hidden or ignored files)."],"DeDYLr": ["Unrecognized wiki link"],"DhLHEb": ["Failed to load activity"],"DiFKSL": ["Counting markdown files"],diff --git a/packages/app/src/locales/en/messages.po b/packages/app/src/locales/en/messages.poindex 41a4815e6..6a789291d 100644--- a/packages/app/src/locales/en/messages.po+++ b/packages/app/src/locales/en/messages.po@@ -3627,6 +3627,10 @@ msgstr "No links yet. Add wiki links or markdown links to build a graph."msgid "No location selected. Use Browse to choose a folder."msgstr "No location selected. Use Browse to choose a folder."+#: src/components/CommandPalette.tsx+msgid "No matches. Some files are excluded from search (hidden or ignored files)."+msgstr "No matches. Some files are excluded from search (hidden or ignored files)."+#: src/components/CommandPalette.tsxmsgid "No matching commands."msgstr "No matching commands."@@ -4717,6 +4721,10 @@ msgstr "Restore to this point?"msgid "Restore with remote changes"msgstr "Restore with remote changes"+#: src/components/CommandPalette.tsx+msgid "Results capped — this workspace has more files than search can index. A missing file may be a cap artifact, not a typo."+msgstr "Results capped — this workspace has more files than search can index. A missing file may be a cap artifact, not a typo."+#: src/components/ActivityModeContent.tsx#: src/components/ConnectingBanner.tsx#: src/components/PublishToGitHubDialog.tsx@@ -4873,6 +4881,10 @@ msgstr "Search files, folders, and commands for the current workspace."msgid "Search files, folders, or commands"msgstr "Search files, folders, or commands"+#: src/components/CommandPalette.tsx+msgid "Search matches file names, paths, and folders. Open a file to search its body (⌘F)."+msgstr "Search matches file names, paths, and folders. Open a file to search its body (⌘F)."+#: src/components/ProjectSwitcher.tsxmsgid "Search recent projects"msgstr "Search recent projects"diff --git a/packages/app/src/locales/pseudo/messages.json b/packages/app/src/locales/pseudo/messages.jsonindex a09438dec..56f492a4c 100644--- a/packages/app/src/locales/pseudo/messages.json+++ b/packages/app/src/locales/pseudo/messages.json@@ -23,7 +23,13 @@"-gdcIo": ["Àũţō-śŷńć ĩś ōń — ŷōũŕ ćōḿḿĩţś ƥũśĥ àńď ŕēḿōţē ćĥàńĝēś ƥũĺĺ ōń ĩńţēŕvàĺś."],"-i7ik4": ["Ćōĺĺàƥśē ƀũŕśţ ", ["burstNumber"], " ďĩƒƒ"],"-lCAuQ": ["Ĺōàďĩńĝ ĝŕàƥĥ"],+ "-q4abP": [+ "Ŕēśũĺţś ćàƥƥēď — ţĥĩś ŵōŕķśƥàćē ĥàś ḿōŕē ƒĩĺēś ţĥàń śēàŕćĥ ćàń ĩńďēx. À ḿĩśśĩńĝ ƒĩĺē ḿàŷ ƀē à ćàƥ àŕţĩƒàćţ, ńōţ à ţŷƥō."+ ],"-slrNR": ["Ţōĝĝĺē à ţàśķ ĺĩśţ."],+ "-wePNM": [+ "Śēàŕćĥ ḿàţćĥēś ƒĩĺē ńàḿēś, ƥàţĥś, àńď ƒōĺďēŕś. Ōƥēń à ƒĩĺē ţō śēàŕćĥ ĩţś ƀōďŷ (⌘Ƒ)."+ ],"0-31GV": ["Ŕēḿōvĩńĝ"],"02P3hL": ["Ũƥĺōàď ƒàĩĺēď: ", ["message"]],"04RA0-": ["Ƒàĩĺēď ţō ēńàƀĺē śŷńć — ", ["detail"]],@@ -466,6 +472,7 @@"DPfwMq": ["Ďōńē"],"DVh_Tb": ["Ƒàĩĺēď ţō ćĺēàń ũƥ àƒţēŕ ţŕàśĥ"],"D_WKe_": ["Ćĺĩćķ àń àĝēńţ'ś àvàţàŕ ĩń ţĥē ƥŕēśēńćē ƀàŕ ţō vĩēŵ ţĥēĩŕ śēśśĩōń."],+ "DbILZA": ["Ńō ḿàţćĥēś. Śōḿē ƒĩĺēś àŕē ēxćĺũďēď ƒŕōḿ śēàŕćĥ (ĥĩďďēń ōŕ ĩĝńōŕēď ƒĩĺēś)."],"DeDYLr": ["Ũńŕēćōĝńĩźēď ŵĩķĩ ĺĩńķ"],"DhLHEb": ["Ƒàĩĺēď ţō ĺōàď àćţĩvĩţŷ"],"DiFKSL": ["Ćōũńţĩńĝ ḿàŕķďōŵń ƒĩĺēś"],diff --git a/packages/app/src/locales/pseudo/messages.po b/packages/app/src/locales/pseudo/messages.poindex 6bfac3fd3..9616c5d08 100644--- a/packages/app/src/locales/pseudo/messages.po+++ b/packages/app/src/locales/pseudo/messages.po@@ -3622,6 +3622,10 @@ msgstr ""msgid "No location selected. Use Browse to choose a folder."msgstr ""+#: src/components/CommandPalette.tsx+msgid "No matches. Some files are excluded from search (hidden or ignored files)."+msgstr ""+#: src/components/CommandPalette.tsxmsgid "No matching commands."msgstr ""@@ -4712,6 +4716,10 @@ msgstr ""msgid "Restore with remote changes"msgstr ""+#: src/components/CommandPalette.tsx+msgid "Results capped — this workspace has more files than search can index. A missing file may be a cap artifact, not a typo."+msgstr ""+#: src/components/ActivityModeContent.tsx#: src/components/ConnectingBanner.tsx#: src/components/PublishToGitHubDialog.tsx@@ -4868,6 +4876,10 @@ msgstr ""msgid "Search files, folders, or commands"msgstr ""+#: src/components/CommandPalette.tsx+msgid "Search matches file names, paths, and folders. Open a file to search its body (⌘F)."+msgstr ""+#: src/components/ProjectSwitcher.tsxmsgid "Search recent projects"msgstr ""diff --git a/packages/app/tests/integration/sidebar-assets.test.ts b/packages/app/tests/integration/sidebar-assets.test.tsindex ecc529c74..d87541a0d 100644--- a/packages/app/tests/integration/sidebar-assets.test.ts+++ b/packages/app/tests/integration/sidebar-assets.test.ts@@ -110,9 +110,15 @@ describe('/api/documents sidebar asset rows', () => {referencedBy: ['docs/guide'],});- expect(body.documents.some((entry) => entry.path === 'docs/media/unreferenced.png')).toBe(- false,+ const unreferenced = body.documents.find(+ (entry) => entry.path === 'docs/media/unreferenced.png',);+ expect(unreferenced).toMatchObject({+ kind: 'file',+ docName: 'docs/media/unreferenced.png',+ assetExt: 'png',+ });+expect(body.documents.some((entry) => entry.path === 'https://example.com/remote.png')).toBe(false,);diff --git a/packages/app/tests/meta/getfileindex-allfiles-coverage.test.ts b/packages/app/tests/meta/getfileindex-allfiles-coverage.test.tsnew file mode 100644index 000000000..cdaf2bacf--- /dev/null+++ b/packages/app/tests/meta/getfileindex-allfiles-coverage.test.ts@@ -0,0 +1,116 @@+import { describe, expect, test } from 'bun:test';+import { readdirSync, readFileSync, statSync } from 'node:fs';+import { join } from 'node:path';++const SERVER_SRC_ROOT = join(import.meta.dirname, '../../../server/src');+const API_EXT_PATH = join(SERVER_SRC_ROOT, 'api-extension.ts');+const FILE_WATCHER_PATH = join(SERVER_SRC_ROOT, 'file-watcher.ts');+const SERVER_FACTORY_PATH = join(SERVER_SRC_ROOT, 'server-factory.ts');++const ALLOWLISTED_SITES: ReadonlySet<string> = new Set<string>([+ 'applyDiskEventToLiveAllFilesIndex',+ 'buildWorkspaceSearchDocumentsFromIndex',+ 'workspaceSearchFingerprint',+ 'deriveFolderSearchDocuments',+ 'handleDocumentList',+]);++function findEnclosingFn(source: string, offset: number): string {+ const fragment = source.slice(0, offset);+ const fnMatches = [...fragment.matchAll(/(?:async\s+)?function\s+([A-Za-z_$][\w$]*)\s*\(/g)];+ const constMatches = [...fragment.matchAll(/\bconst\s+([A-Za-z_$][\w$]*)\s*=\s*\S/g)];+ const lastFn = fnMatches.length > 0 ? fnMatches[fnMatches.length - 1] : null;+ const lastConst = constMatches.length > 0 ? constMatches[constMatches.length - 1] : null;++ const fnIdx = lastFn?.index ?? -1;+ const constIdx = lastConst?.index ?? -1;+ if (fnIdx === -1 && constIdx === -1) return '<unknown>';+ if (fnIdx >= constIdx) return lastFn?.[1] ?? '<unknown>';+ return lastConst?.[1] ?? '<unknown>';+}++function windowFiltersOnKind(window: string): boolean {+ return /\.kind\s*(?:===|!==)\s*['"](markdown|file)['"]/.test(window);+}++interface CallSite {+ file: string;+ line: number;+ fn: string;+ window: string;+}++function collectAllFilesCallSites(filePath: string): CallSite[] {+ const source = readFileSync(filePath, 'utf8');+ const sites: CallSite[] = [];+ for (const match of source.matchAll(/getAllFilesIndex\s*\(/g)) {+ const offset = match.index ?? 0;+ const line = source.slice(0, offset).split('\n').length;+ const fn = findEnclosingFn(source, offset);+ const window = source.slice(Math.max(0, offset - 600), Math.min(source.length, offset + 600));+ sites.push({ file: filePath, line, fn, window });+ }+ return sites;+}++function listProductionTsFiles(dir: string): string[] {+ const out: string[] = [];+ for (const entry of readdirSync(dir)) {+ const full = join(dir, entry);+ const st = statSync(full);+ if (st.isDirectory()) {+ out.push(...listProductionTsFiles(full));+ } else if (st.isFile() && entry.endsWith('.ts') && !entry.endsWith('.test.ts')) {+ out.push(full);+ }+ }+ return out;+}++describe('PRD-7117 US-002 — getAllFilesIndex caller coverage (D12 §13-A)', () => {+ test('every getAllFilesIndex() call site in api-extension.ts is allowlisted or kind-filtered', () => {+ const sites = collectAllFilesCallSites(API_EXT_PATH);+ const failures: string[] = [];+ for (const site of sites) {+ const allowed = ALLOWLISTED_SITES.has(site.fn);+ const filtered = windowFiltersOnKind(site.window);+ if (!allowed && !filtered) {+ failures.push(+ `${site.file}:${site.line} — enclosing fn "${site.fn}" is neither on ALLOWLISTED_SITES nor narrows on \`.kind\`. ` ++ 'A new getAllFilesIndex() consumer must be added to ALLOWLISTED_SITES (with rationale) ' ++ 'OR must structurally guard via `entry.kind === "markdown"` / similar inside the call site.',+ );+ }+ }+ expect(failures).toEqual([]);+ });++ test('getAllFilesIndex() is not called from any other server-side production file', () => {+ const allowedFiles = new Set([FILE_WATCHER_PATH, API_EXT_PATH, SERVER_FACTORY_PATH]);+ const offenders: string[] = [];+ for (const file of listProductionTsFiles(SERVER_SRC_ROOT)) {+ if (allowedFiles.has(file)) continue;+ const source = readFileSync(file, 'utf8');+ if (/getAllFilesIndex\s*\(/.test(source)) {+ offenders.push(file);+ }+ }+ expect(offenders).toEqual([]);+ });++ test('ALLOWLISTED_SITES function names actually exist in api-extension.ts', () => {+ const source = readFileSync(API_EXT_PATH, 'utf8');+ const missing: string[] = [];+ for (const name of ALLOWLISTED_SITES) {+ const fnRe = new RegExp(`(?:async\\s+)?function\\s+${name}\\s*\\(`);+ const constRe = new RegExp(`\\bconst\\s+${name}\\s*=\\s*\\S`);+ if (!fnRe.test(source) && !constRe.test(source)) {+ missing.push(+ `${name}: function declaration not found in api-extension.ts — either rename/remove dropped the site, ` ++ 'or the allowlist entry is stale.',+ );+ }+ }+ expect(missing).toEqual([]);+ });+});diff --git a/packages/core/src/schemas/api/document-read.test.ts b/packages/core/src/schemas/api/document-read.test.tsindex cf3793f97..6edb614db 100644--- a/packages/core/src/schemas/api/document-read.test.ts+++ b/packages/core/src/schemas/api/document-read.test.ts@@ -241,6 +241,69 @@ describe('DocumentListEntrySchema', () => {}).success,).toBe(false);});+ test('parses a file entry with path (and optional assetExt)', () => {+ expect(+ DocumentListEntrySchema.safeParse({+ kind: 'file',+ path: 'packages/app/src/components/FileTree.tsx',+ size: 4096,+ modified: '2026-04-30T00:00:00Z',+ assetExt: 'tsx',+ }).success,+ ).toBe(true);+ });+ test('parses a file entry with no extension', () => {+ expect(+ DocumentListEntrySchema.safeParse({+ kind: 'file',+ path: 'LICENSE',+ size: 1024,+ modified: '2026-04-30T00:00:00Z',+ }).success,+ ).toBe(true);+ });+ test('parses a file entry with docName mirror of path', () => {+ expect(+ DocumentListEntrySchema.safeParse({+ kind: 'file',+ docName: 'data/example.csv',+ path: 'data/example.csv',+ size: 64,+ modified: '2026-04-30T00:00:00Z',+ }).success,+ ).toBe(true);+ });+ test('rejects a file entry without path', () => {+ expect(+ DocumentListEntrySchema.safeParse({+ kind: 'file',+ size: 0,+ modified: '2026-04-30T00:00:00Z',+ }).success,+ ).toBe(false);+ });+ test('rejects a file entry with mediaKind populated', () => {+ expect(+ DocumentListEntrySchema.safeParse({+ kind: 'file',+ path: 'data/example.csv',+ size: 0,+ modified: '2026-04-30T00:00:00Z',+ mediaKind: 'text',+ }).success,+ ).toBe(false);+ });+ test('rejects a file entry with referencedBy populated', () => {+ expect(+ DocumentListEntrySchema.safeParse({+ kind: 'file',+ path: 'data/example.csv',+ size: 0,+ modified: '2026-04-30T00:00:00Z',+ referencedBy: ['guide'],+ }).success,+ ).toBe(false);+ });});describe('DocumentListSuccessSchema', () => {diff --git a/packages/core/src/schemas/api/document-read.ts b/packages/core/src/schemas/api/document-read.tsindex 9c404dcac..f33481ca7 100644--- a/packages/core/src/schemas/api/document-read.ts+++ b/packages/core/src/schemas/api/document-read.ts@@ -20,7 +20,7 @@ export type DocumentReadSuccess = z.infer<typeof DocumentReadSuccessSchema>;export const DocumentListEntrySchema = z.object({- kind: z.enum(['document', 'asset', 'folder']).default('document'),+ kind: z.enum(['document', 'asset', 'folder', 'file']).default('document'),docName: z.string().min(1).optional(),docExt: z.string().min(1).default('.md'),size: z.number().int().nonnegative(),@@ -56,6 +56,14 @@ export const DocumentListEntrySchema = zentry.referencedBy === undefined);}+ if (entry.kind === 'file') {+ return (+ entry.path !== undefined &&+ entry.mediaKind === undefined &&+ entry.referencedBy === undefined &&+ entry.hasChildren === undefined+ );+ }return (entry.path !== undefined &&entry.assetExt !== undefined &&@@ -65,7 +73,7 @@ export const DocumentListEntrySchema = z},{message:- 'document/asset/folder kind must match its required fields (document → docName; asset → path+assetExt+referencedBy; folder → path only, no docName)',+ 'document/asset/folder/file kind must match its required fields (document → docName; asset → path+assetExt+referencedBy; folder → path only, no docName; file → path, no mediaKind/referencedBy/hasChildren)',},) satisfies StandardSchemaV1;export type DocumentListEntry = z.infer<typeof DocumentListEntrySchema>;diff --git a/packages/core/src/schemas/api/tags-search.ts b/packages/core/src/schemas/api/tags-search.tsindex d79a20478..950d7ab9a 100644--- a/packages/core/src/schemas/api/tags-search.ts+++ b/packages/core/src/schemas/api/tags-search.ts@@ -158,7 +158,7 @@ export const SearchRequestSchema = z.object({query: z.string().optional(),intent: z.enum(['autocomplete', 'full_text', 'omnibar']).optional(),- scopes: z.array(z.enum(['page', 'folder', 'content'])).optional(),+ scopes: z.array(z.enum(['page', 'folder', 'content', 'file'])).optional(),scope: z.string().optional(),limit: z.number().int().nonnegative().optional(),semantic: z.boolean().optional(),@@ -171,7 +171,7 @@ export type SearchSource = NonNullable<SearchRequest['source']>;export const SearchResultEntrySchema = z.object({- kind: z.enum(['page', 'folder', 'content']),+ kind: z.enum(['page', 'folder', 'content', 'file']),path: z.string().min(1),title: z.string(),score: z.number(),@@ -214,6 +214,7 @@ export const SearchSuccessSchema = zresults: z.array(SearchResultEntrySchema),elapsedMs: z.number().nonnegative(),semantic: SearchSemanticStatusSchema.optional(),+ truncated: z.boolean().optional(),}).loose() satisfies StandardSchemaV1;export type SearchSuccess = z.infer<typeof SearchSuccessSchema>;diff --git a/packages/core/src/search/workspace-search.test.ts b/packages/core/src/search/workspace-search.test.tsindex 5301e473c..0adf50688 100644--- a/packages/core/src/search/workspace-search.test.ts+++ b/packages/core/src/search/workspace-search.test.ts@@ -76,3 +76,168 @@ describe('searchWorkspaceDocuments', () => {expect(results.map((result) => result.document.path)).toEqual(['new/research', 'old/research']);});});++describe('file-kind documents', () => {+ const mixed = [+ createWorkspaceSearchDocument({+ kind: 'page',+ path: 'notes/data',+ title: 'Data Notes',+ content: 'analysis prose about spreadsheets',+ modifiedTs: 10,+ }),+ createWorkspaceSearchDocument({ kind: 'file', path: 'data.csv', modifiedTs: 20 }),+ createWorkspaceSearchDocument({+ kind: 'file',+ path: 'packages/server/src/file-watcher.ts',+ modifiedTs: 30,+ }),+ ];++ test('a file entry is findable by basename under the default omnibar scope', () => {+ const results = searchWorkspaceDocuments(mixed, 'data.csv', { intent: 'omnibar' });+ const hit = results.find((result) => result.document.path === 'data.csv');+ expect(hit).toBeDefined();+ expect(hit?.document.kind).toBe('file');+ });++ test('a file entry is findable by a partial path segment under the default omnibar scope', () => {+ const results = searchWorkspaceDocuments(mixed, 'file-watcher', { intent: 'omnibar' });+ expect(results.map((result) => result.document.path)).toContain(+ 'packages/server/src/file-watcher.ts',+ );+ });++ test('the explicit file scope returns only file entries', () => {+ const results = searchWorkspaceDocuments(mixed, 'data', {+ intent: 'omnibar',+ scopes: ['file'],+ });+ expect(results.length).toBeGreaterThan(0);+ expect(results.every((result) => result.document.kind === 'file')).toBe(true);+ expect(results.map((result) => result.document.path)).toContain('data.csv');+ });++ test('file entries carry no content and never match on body text', () => {+ const fileDoc = mixed.find((document) => document.kind === 'file');+ expect(fileDoc?.content).toBe('');++ const results = searchWorkspaceDocuments(mixed, 'analysis', { intent: 'full_text' });+ expect(results.map((result) => result.document.path)).toContain('notes/data');+ expect(results.map((result) => result.document.path)).not.toContain('data.csv');+ });++ test('autocomplete excludes kind:file rows even when the corpus contains them', () => {+ const corpus = [+ createWorkspaceSearchDocument({+ kind: 'page',+ path: 'notes/data',+ title: 'Data Notes',+ modifiedTs: 10,+ }),+ createWorkspaceSearchDocument({ kind: 'file', path: 'data.csv', modifiedTs: 20 }),+ createWorkspaceSearchDocument({+ kind: 'file',+ path: 'data.json',+ modifiedTs: 30,+ }),+ ];+ const results = searchWorkspaceDocuments(corpus, 'data', { intent: 'autocomplete' });+ expect(results.length).toBeGreaterThan(0);+ expect(results.every((result) => result.document.kind === 'page')).toBe(true);+ expect(results.map((result) => result.document.path)).not.toContain('data.csv');+ expect(results.map((result) => result.document.path)).not.toContain('data.json');+ });+});++describe('hidden / dot-path ranking — searchable but rank-deprioritized', () => {+ const visible = createWorkspaceSearchDocument({+ kind: 'page',+ path: 'notes/release',+ title: 'Release',+ modifiedTs: 50,+ });+ const hidden = createWorkspaceSearchDocument({+ kind: 'page',+ path: '.changeset/release',+ title: 'Release',+ modifiedTs: 50,+ });++ test('a hidden dot-path document is still returned by search', () => {+ const results = searchWorkspaceDocuments([hidden], 'release', { intent: 'omnibar' });+ expect(results.map((result) => result.document.path)).toContain('.changeset/release');+ });++ test('a hidden dot-path hit carries half the lexical bracket of an equivalent visible hit', () => {+ const results = searchWorkspaceDocuments([visible, hidden], 'release', { intent: 'omnibar' });+ const v = results.find((result) => result.document.path === 'notes/release');+ const h = results.find((result) => result.document.path === '.changeset/release');+ expect(v?.signals.lexical).toBeGreaterThan(0);+ expect(h?.signals.lexical).toBe((v?.signals.lexical ?? 0) * 0.5);+ });++ test('the visible twin outranks the hidden one on an exact-stem collision', () => {+ const results = searchWorkspaceDocuments([visible, hidden], 'release', { intent: 'omnibar' });+ const visibleRank = results.findIndex((result) => result.document.path === 'notes/release');+ const hiddenRank = results.findIndex((result) => result.document.path === '.changeset/release');+ expect(visibleRank).toBeGreaterThanOrEqual(0);+ expect(hiddenRank).toBeGreaterThanOrEqual(0);+ expect(visibleRank).toBeLessThan(hiddenRank);+ });+});++describe('canonical-kind ranking — markdown outranks a same-stem file (D5)', () => {+ test('a markdown page ranks above a same-stem non-markdown file', () => {+ const docs = [+ createWorkspaceSearchDocument({ kind: 'page', path: 'foo', title: 'foo', modifiedTs: 10 }),+ createWorkspaceSearchDocument({ kind: 'file', path: 'foo.ts', modifiedTs: 10 }),+ ];+ const ranked = searchWorkspaceDocuments(docs, 'foo', { intent: 'omnibar' });+ expect(ranked[0]?.document.path).toBe('foo');+ });++ test('a markdown page outranks a same-bracket file even when the file is newer (kind demotion dominates recency)', () => {+ const page = createWorkspaceSearchDocument({+ kind: 'page',+ path: 'config',+ title: 'config',+ modifiedTs: 10,+ });+ const newerFile = createWorkspaceSearchDocument({+ kind: 'file',+ path: 'sub/config',+ modifiedTs: 100,+ });+ const ranked = searchWorkspaceDocuments([page, newerFile], 'config', { intent: 'omnibar' });+ const pageRank = ranked.findIndex((r) => r.document.path === 'config');+ const fileRank = ranked.findIndex((r) => r.document.path === 'sub/config');+ expect(pageRank).toBeGreaterThanOrEqual(0);+ expect(fileRank).toBeGreaterThanOrEqual(0);+ expect(pageRank).toBeLessThan(fileRank);+ });+});++describe('alias / symlink handling — inode-dedup + alias paths searchable (D16)', () => {+ test('a file is findable by EITHER its canonical or an alias path segment, once', () => {+ const doc = createWorkspaceSearchDocument({+ kind: 'file',+ path: 'canonical/report.csv',+ aliases: ['linked/report.csv'],+ modifiedTs: 10,+ });+ const byCanonical = searchWorkspaceDocuments([doc], 'canonical', { intent: 'omnibar' });+ expect(byCanonical.map((r) => r.document.path)).toEqual(['canonical/report.csv']);+ const byAlias = searchWorkspaceDocuments([doc], 'linked', { intent: 'omnibar' });+ expect(byAlias.map((r) => r.document.path)).toEqual(['canonical/report.csv']);+ });++ test('no aliases → pathSegments is byte-identical to the canonical-only form', () => {+ expect(createWorkspaceSearchDocument({ kind: 'file', path: 'a/b/c.ts' }).pathSegments).toBe(+ 'a b c.ts',+ );+ expect(createWorkspaceSearchDocument({ kind: 'page', path: 'a/x/a' }).pathSegments).toBe(+ 'a x a',+ );+ });+});diff --git a/packages/core/src/search/workspace-search.ts b/packages/core/src/search/workspace-search.tsindex 5a93ff6ec..46bed3929 100644--- a/packages/core/src/search/workspace-search.ts+++ b/packages/core/src/search/workspace-search.ts@@ -1,6 +1,7 @@import { type AnyOrama, create, insertMultiple, search } from '@orama/orama';+import { isHiddenDocName } from '../util/doc-name.ts';-export type WorkspaceSearchKind = 'page' | 'folder';+export type WorkspaceSearchKind = 'page' | 'folder' | 'file';export type WorkspaceSearchIntent = 'omnibar' | 'autocomplete' | 'full_text';export type WorkspaceSearchScope = WorkspaceSearchKind | 'content';@@ -91,17 +92,27 @@ export function createWorkspaceSearchDocument(input: {title?: string | null;content?: string | null;modifiedTs?: number | null;+ aliases?: readonly string[] | null;}): WorkspaceSearchDocument {const name = workspaceSearchBasename(input.path);const title = input.title?.trim() || name;const modifiedTs = input.modifiedTs ?? 0;+ const baseSegments = input.path.split('/').filter(Boolean);+ const baseSet = new Set(baseSegments);+ const aliasSegments = [+ ...new Set(+ (input.aliases ?? [])+ .flatMap((alias) => alias.split('/').filter(Boolean))+ .filter((segment) => !baseSet.has(segment)),+ ),+ ];return {id: `${input.kind}:${input.path}`,kind: input.kind,path: input.path,title,name,- pathSegments: workspaceSearchPathSegments(input.path),+ pathSegments: [...baseSegments, ...aliasSegments].join(' '),content: input.content ?? '',modifiedTs: Number.isFinite(modifiedTs) ? modifiedTs : 0,};@@ -137,8 +148,8 @@ function getWorkspaceSearchIndex(corpus: WorkspaceSearchCorpus): WorkspaceSearchfunction defaultScopes(intent: WorkspaceSearchIntent): readonly WorkspaceSearchScope[] {if (intent === 'autocomplete') return ['page'];- if (intent === 'full_text') return ['page', 'content'];- return ['page', 'folder'];+ if (intent === 'full_text') return ['page', 'content', 'file'];+ return ['page', 'folder', 'file'];}function scopeAllows(document: WorkspaceSearchDocument, scopes: ReadonlySet<WorkspaceSearchScope>) {@@ -146,7 +157,7 @@ function scopeAllows(document: WorkspaceSearchDocument, scopes: ReadonlySet<Workreturn document.kind === 'page' && scopes.has('content');}-function lexicalScore(document: WorkspaceSearchDocument, query: string): number {+function lexicalBracket(document: WorkspaceSearchDocument, query: string): number {const normalizedQuery = normalize(query);if (!normalizedQuery) return 0;@@ -164,6 +175,20 @@ function lexicalScore(document: WorkspaceSearchDocument, query: string): numberreturn -1;}+const HIDDEN_DOC_LEXICAL_PENALTY = 0.5;++function lexicalScore(document: WorkspaceSearchDocument, query: string): number {+ const bracket = lexicalBracket(document, query);+ if (bracket <= 0) return bracket;+ return isHiddenDocName(document.path) ? bracket * HIDDEN_DOC_LEXICAL_PENALTY : bracket;+}++const FILE_KIND_SCORE_DEMOTION = 60;++function canonicalKindAdjustment(kind: WorkspaceSearchKind): number {+ return kind === 'file' ? -FILE_KIND_SCORE_DEMOTION : 0;+}+function recencyScores(documents: readonly WorkspaceSearchDocument[]): Map<string, number> {const modifiedValues = documents.map((document) => document.modifiedTs)@@ -274,7 +299,7 @@ export function searchWorkspaceCorpus(const recencyScore = recency.get(document.id) ?? 0;return {document,- score: lexical + fullText * 20 + recencyScore,+ score: lexical + fullText * 20 + recencyScore + canonicalKindAdjustment(document.kind),signals: { lexical, fullText, recency: recencyScore },};})@@ -350,7 +375,7 @@ function rankWithVector(args: {const qualifies = cosine !== undefined && cosine >= floor;return {document,- score: lexical + fullText * 20 + recencyScore,+ score: lexical + fullText * 20 + recencyScore + canonicalKindAdjustment(document.kind),signals: qualifies? { lexical, fullText, recency: recencyScore, vector: cosine }: { lexical, fullText, recency: recencyScore },diff --git a/packages/server/src/api-document-list-ready-gate.test.ts b/packages/server/src/api-document-list-ready-gate.test.tsindex 226fc84a9..b0107f7a9 100644--- a/packages/server/src/api-document-list-ready-gate.test.ts+++ b/packages/server/src/api-document-list-ready-gate.test.ts@@ -82,6 +82,7 @@ describe('handleDocumentList ready gating', () => {canonicalPath: join(tmp, 'log.md'),inode: 0,aliases: [],+ kind: 'markdown',});fileIndex.set('notes', {size: 9,@@ -89,6 +90,7 @@ describe('handleDocumentList ready gating', () => {canonicalPath: join(tmp, 'notes.md'),inode: 0,aliases: [],+ kind: 'markdown',});resolveReady();@@ -108,6 +110,89 @@ describe('handleDocumentList ready gating', () => {}});+ test('emits kind:file rows for non-markdown index entries via getAllFilesIndex', async () => {+ const tmp = mkdtempSync(join(tmpdir(), 'ok-document-list-file-kind-'));+ try {+ mkdirSync(tmp, { recursive: true });+ const now = new Date().toISOString();+ const fileIndex = new Map<string, FileIndexEntry>([+ [+ 'notes/page',+ {+ size: 9,+ modified: now,+ canonicalPath: join(tmp, 'notes/page.md'),+ inode: 0,+ aliases: [],+ kind: 'markdown',+ },+ ],+ [+ 'data/example.csv',+ {+ size: 64,+ modified: now,+ canonicalPath: join(tmp, 'data/example.csv'),+ inode: 1,+ aliases: [],+ kind: 'file',+ },+ ],+ ]);++ const hocuspocus = new Hocuspocus({ quiet: true });+ const ext = createApiExtension({+ hocuspocus,+ sessionManager: {+ closeSession: async () => {},+ closeAllForDoc: async () => {},+ } as unknown as Parameters<typeof createApiExtension>[0]['sessionManager'],+ contentDir: tmp,+ getFileIndex: () => {+ const view = new Map<string, FileIndexEntry>();+ for (const [k, v] of fileIndex) if (v.kind === 'markdown') view.set(k, v);+ return view;+ },+ getAllFilesIndex: () => fileIndex,+ getFolderIndex: () => new Map(),+ serverInstanceId: 'test-instance',+ });++ const req = makeReq('/api/documents');+ const { res, captured } = makeRes();+ await (+ ext as {+ onRequest: (ctx: { request: IncomingMessage; response: ServerResponse }) => Promise<void>;+ }+ ).onRequest({ request: req, response: res });++ expect(captured.status).toBe(200);+ const body = JSON.parse(captured.body) as {+ documents: Array<{+ kind: string;+ docName?: string;+ path?: string;+ assetExt?: string;+ }>;+ };+ const documents = body.documents;+ expect(documents.filter((d) => d.kind === 'document').map((d) => d.docName)).toEqual([+ 'notes/page',+ ]);+ const fileRows = documents.filter((d) => d.kind === 'file');+ expect(fileRows).toEqual([+ expect.objectContaining({+ kind: 'file',+ docName: 'data/example.csv',+ path: 'data/example.csv',+ assetExt: 'csv',+ }),+ ]);+ } finally {+ rmSync(tmp, { recursive: true, force: true });+ }+ });+test('responds normally when ready is omitted (test-construction path)', async () => {const tmp = mkdtempSync(join(tmpdir(), 'ok-ready-gate-'));try {@@ -121,6 +206,7 @@ describe('handleDocumentList ready gating', () => {canonicalPath: join(tmp, 'only.md'),inode: 0,aliases: [],+ kind: 'markdown',},],]);diff --git a/packages/server/src/api-extension.ts b/packages/server/src/api-extension.tsindex 8afe4072f..3e03fca6b 100644--- a/packages/server/src/api-extension.ts+++ b/packages/server/src/api-extension.ts@@ -350,6 +350,7 @@ import {import { extractActorIdentity } from './extract-actor-identity.ts';import {contentHash,+ type DiskEvent,type FileIndexEntry,type FolderIndexEntry,registerWrite,@@ -533,6 +534,16 @@ function agentWriteContentDivergenceCounter(): ReturnType<return _agentWriteContentDivergenceCounter;}+let _searchCorpusTruncatedCounter: ReturnType<ReturnType<typeof getMeter>['createCounter']> | null =+ null;+function searchCorpusTruncatedCounter(): ReturnType<ReturnType<typeof getMeter>['createCounter']> {+ _searchCorpusTruncatedCounter ||= getMeter().createCounter('ok.search.corpus_truncated_total', {+ description:+ 'Count of search-corpus rebuilds where the name-only file tier hit OK_SEARCH_MAX_ENTRIES and dropped deepest-tail paths. One increment per truncated build; non-truncated builds do not increment.',+ });+ return _searchCorpusTruncatedCounter;+}+type DivergenceHandler = 'agent-write-md' | 'agent-patch' | 'rollback';function recordContentDivergenceGate(@@ -864,6 +875,14 @@ export function getShowAllMaxEntries(): number {return Number.isInteger(parsed) && parsed > 0 ? parsed : DEFAULT_SHOWALL_MAX_ENTRIES;}+export const DEFAULT_SEARCH_MAX_ENTRIES = 50_000;+export function getSearchMaxEntries(): number {+ const raw = process.env.OK_SEARCH_MAX_ENTRIES;+ if (raw === undefined) return DEFAULT_SEARCH_MAX_ENTRIES;+ const parsed = Number(raw);+ return Number.isInteger(parsed) && parsed > 0 ? parsed : DEFAULT_SEARCH_MAX_ENTRIES;+}+let showAllWalkInvocations = 0;let showAllWalkAborts = 0;export function __getShowAllWalkStatsForTesting(): { invocations: number; aborts: number } {@@ -1555,6 +1574,9 @@ export interface ApiExtensionOptions {ephemeral?: boolean;serverInstanceId: string;getFileIndex: () => ReadonlyMap<string, FileIndexEntry>;+ getAllFilesIndex?: () => ReadonlyMap<string, FileIndexEntry>;+ getFileIndexGeneration?: () => number;+ mutateFileIndex?: (event: DiskEvent) => void;getFolderIndex?: () => ReadonlyMap<string, FolderIndexEntry>;onReferencedAssetsCacheInvalidator?: (invalidate: () => void) => void;getAliasMap?: () => ReadonlyMap<string, string>;@@ -1594,7 +1616,8 @@ export interface ApiExtensionOptions {interface WorkspaceSearchCacheEntry {fingerprint: string;corpus?: WorkspaceSearchCorpus;- pending?: Promise<WorkspaceSearchCorpus>;+ truncated?: boolean;+ pending?: Promise<{ corpus: WorkspaceSearchCorpus; truncated: boolean }>;}const workspaceSearchCaches = new Map<string, WorkspaceSearchCacheEntry>();@@ -1626,6 +1649,16 @@ export function isSafeDocName(docName: string): boolean {);}+function applyDiskEventToLiveAllFilesIndex(+ event: DiskEvent,+ getAllFilesIndex: () => ReadonlyMap<string, FileIndexEntry>,+): void {+ const live = getAllFilesIndex();+ if (live instanceof Map) {+ updateFileIndex(event, live);+ }+}+export function createApiExtension(options: ApiExtensionOptions): Extension {const {hocuspocus,@@ -1633,6 +1666,10 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {contentDir,serverInstanceId,getFileIndex,+ getAllFilesIndex = getFileIndex,+ mutateFileIndex = (event: DiskEvent) =>+ applyDiskEventToLiveAllFilesIndex(event, getAllFilesIndex),+ getFileIndexGeneration,getFolderIndex,onReferencedAssetsCacheInvalidator,getAliasMap,@@ -2133,13 +2170,7 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {registerWrite(filePath, contentHash(markdown));setReconciledBase(docName, markdown);- const fileIndex = getFileIndex();- if (fileIndex instanceof Map) {- updateFileIndex(- { kind: 'update', path: filePath, docName, content: markdown },- fileIndex as Map<string, FileIndexEntry>,- );- }+ mutateFileIndex?.({ kind: 'update', path: filePath, docName, content: markdown });}function applyManagedRenameMapToLoadedDocument(@@ -2830,20 +2861,14 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {);setReconciledBase(toDocName, renamedSource.markdown);- const fileIndex = getFileIndex();- if (fileIndex instanceof Map) {- updateFileIndex(- {- kind: 'rename',- oldPath: sourcePath,- newPath: destinationPath,- oldDocName: fromDocName,- newDocName: toDocName,- content: renamedSource.markdown,- },- fileIndex as Map<string, FileIndexEntry>,- );- }+ mutateFileIndex?.({+ kind: 'rename',+ oldPath: sourcePath,+ newPath: destinationPath,+ oldDocName: fromDocName,+ newDocName: toDocName,+ content: renamedSource.markdown,+ });backlinkIndex.renameDocument(fromDocName, toDocName, renamedSource.markdown);if (renamedSource.rewrites > 0) {@@ -3927,6 +3952,7 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {}const index = getFileIndex();+ const allFiles = getAllFilesIndex();const folderIndex = getFolderIndex?.() ?? new Map<string, FolderIndexEntry>();const documents: DocumentListEntry[] = [];@@ -3944,38 +3970,6 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {});}- for (const [docName, entry] of index) {- if (dir && !docName.startsWith(`${dir}/`) && docName !== dir) continue;-- const docExt = getDocExtension(docName);-- documents.push({- kind: 'document',- docName,- docExt,- size: entry.size,- modified: entry.modified,- isSymlink: false,- canonicalDocName: null,- targetPath: null,- });-- for (const alias of entry.aliases) {- if (dir && !alias.startsWith(`${dir}/`) && alias !== dir) continue;- const targetRelPath = relative(contentDir, entry.canonicalPath);- documents.push({- kind: 'document',- docName: alias,- docExt,- size: entry.size,- modified: entry.modified,- isSymlink: true,- canonicalDocName: docName,- targetPath: targetRelPath,- });- }- }-let assets: ReturnType<typeof collectReferencedAssets> = [];try {const assetSignature = referencedAssetsSignature(index);@@ -4001,8 +3995,11 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {referencedAssetsCache = null;console.warn('[document-list] asset collection failed; returning documents only:', err);}++ const assetPaths = new Set<string>();for (const asset of assets) {if (dir && !asset.path.startsWith(`${dir}/`) && asset.path !== dir) continue;+ assetPaths.add(asset.path);documents.push({kind: 'asset',docName: asset.path,@@ -4019,6 +4016,76 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {});}+ for (const [docName, entry] of allFiles) {+ if (entry.kind === 'markdown') {+ if (dir && !docName.startsWith(`${dir}/`) && docName !== dir) continue;++ const docExt = getDocExtension(docName);++ documents.push({+ kind: 'document',+ docName,+ docExt,+ size: entry.size,+ modified: entry.modified,+ isSymlink: false,+ canonicalDocName: null,+ targetPath: null,+ });++ for (const alias of entry.aliases) {+ if (dir && !alias.startsWith(`${dir}/`) && alias !== dir) continue;+ const targetRelPath = relative(contentDir, entry.canonicalPath);+ documents.push({+ kind: 'document',+ docName: alias,+ docExt,+ size: entry.size,+ modified: entry.modified,+ isSymlink: true,+ canonicalDocName: docName,+ targetPath: targetRelPath,+ });+ }+ continue;+ }++ const passesDir = !dir || docName === dir || docName.startsWith(`${dir}/`);+ if (passesDir && !assetPaths.has(docName)) {+ const assetExt = synthesizeShowAllAssetExt(docName);+ documents.push({+ kind: 'file',+ docName,+ path: docName,+ docExt: `.${assetExt}`,+ assetExt,+ size: entry.size,+ modified: entry.modified,+ isSymlink: false,+ canonicalDocName: null,+ targetPath: null,+ });+ }+ for (const alias of entry.aliases) {+ const aliasPassesDir = !dir || alias === dir || alias.startsWith(`${dir}/`);+ if (!aliasPassesDir || assetPaths.has(alias)) continue;+ const targetRelPath = relative(contentDir, entry.canonicalPath);+ const assetExt = synthesizeShowAllAssetExt(alias);+ documents.push({+ kind: 'file',+ docName: alias,+ path: alias,+ docExt: `.${assetExt}`,+ assetExt,+ size: entry.size,+ modified: entry.modified,+ isSymlink: true,+ canonicalDocName: docName,+ targetPath: targetRelPath,+ });+ }+ }+documents.sort((a, b) => {const aPath = a.kind === 'folder' ? (a.path ?? '') : (a.docName ?? a.path ?? '');const bPath = b.kind === 'folder' ? (b.path ?? '') : (b.docName ?? b.path ?? '');@@ -6359,13 +6426,7 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {);}}- const fileIndex = typeof getFileIndex === 'function' ? getFileIndex() : null;- if (fileIndex instanceof Map) {- updateFileIndex(- { kind: 'create', path: fullPath, docName, content: initialContent },- fileIndex as Map<string, FileIndexEntry>,- );- }+ mutateFileIndex?.({ kind: 'create', path: fullPath, docName, content: initialContent });if (backlinkIndex) {backlinkIndex.updateDocumentFromMarkdown(docName, initialContent);void backlinkIndex.saveToDisk().catch((err) => {@@ -6565,7 +6626,6 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {}}- const fileIndex = typeof getFileIndex === 'function' ? getFileIndex() : null;let duplicatedPath: string;let duplicatedDocNames: string[] = [];@@ -6633,12 +6693,12 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {didIncrementMdDir = true;}registerWrite(destinationPath, contentHash(content));- if (fileIndex instanceof Map) {- updateFileIndex(- { kind: 'create', path: destinationPath, docName: duplicatedPath, content },- fileIndex as Map<string, FileIndexEntry>,- );- }+ mutateFileIndex?.({+ kind: 'create',+ path: destinationPath,+ docName: duplicatedPath,+ content,+ });backlinkIndex?.updateDocumentFromMarkdown(duplicatedPath, content);duplicatedDocNames = [duplicatedPath];} catch (err) {@@ -6654,12 +6714,11 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {if (contentFilter && didIncrementMdDir) {contentFilter.decrementMdDir(dirname(duplicatedPath));}- if (fileIndex instanceof Map) {- updateFileIndex(- { kind: 'delete', path: destinationPath, docName: duplicatedPath },- fileIndex as Map<string, FileIndexEntry>,- );- }+ mutateFileIndex?.({+ kind: 'delete',+ path: destinationPath,+ docName: duplicatedPath,+ });throw err;}} else {@@ -6709,17 +6768,12 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {contentFilter.incrementMdDir(dirname(doc.docName));}registerWrite(doc.fullPath, contentHash(doc.content));- if (fileIndex instanceof Map) {- updateFileIndex(- {- kind: 'create',- path: doc.fullPath,- docName: doc.docName,- content: doc.content,- },- fileIndex as Map<string, FileIndexEntry>,- );- }+ mutateFileIndex?.({+ kind: 'create',+ path: doc.fullPath,+ docName: doc.docName,+ content: doc.content,+ });backlinkIndex?.updateDocumentFromMarkdown(doc.docName, doc.content);}} catch (err) {@@ -7270,18 +7324,12 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {}invalidateReferencedAssetsCache();- const fileIndex = getFileIndex();- if (fileIndex instanceof Map) {- for (const docName of deletedDocNames) {- updateFileIndex(- {- kind: 'delete',- path: resolve(contentDir, `${docName}${getDocExtension(docName)}`),- docName,- },- fileIndex as Map<string, FileIndexEntry>,- );- }+ for (const docName of deletedDocNames) {+ mutateFileIndex?.({+ kind: 'delete',+ path: resolve(contentDir, `${docName}${getDocExtension(docName)}`),+ docName,+ });}signalChannel?.('files');@@ -7406,18 +7454,12 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {}}- const fileIndex = getFileIndex();- if (fileIndex instanceof Map) {- for (const docName of deletedDocNames) {- updateFileIndex(- {- kind: 'delete',- path: resolve(contentDir, `${docName}${getDocExtension(docName)}`),- docName,- },- fileIndex as Map<string, FileIndexEntry>,- );- }+ for (const docName of deletedDocNames) {+ mutateFileIndex?.({+ kind: 'delete',+ path: resolve(contentDir, `${docName}${getDocExtension(docName)}`),+ docName,+ });}if (kind === 'folder') {removeFolderIndexEntries(path);@@ -9932,7 +9974,7 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {if (!rawScopes) return undefined;const scopes = rawScopes.filter((scope): scope is WorkspaceSearchScope =>- scope === 'page' || scope === 'folder' || scope === 'content',+ scope === 'page' || scope === 'folder' || scope === 'content' || scope === 'file',);return scopes.length > 0 ? scopes : undefined;}@@ -9962,18 +10004,19 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {semanticParam: boolean | undefined,corpus: WorkspaceSearchCorpus,): Promise<SemanticResolution> {- const pageTotal = corpus.documents.reduce((n, d) => n + (d.kind === 'page' ? 1 : 0), 0);+ const embeddableDocs = corpus.documents.filter((d) => !isHiddenDocName(d.path));+ const pageTotal = embeddableDocs.reduce((n, d) => n + (d.kind === 'page' ? 1 : 0), 0);if (!semanticSearch?.isEnabled() || semanticParam !== true) {return { queryEmbedMs: null, pageTotal, capable: false };}- void semanticSearch.embedCorpus(corpus.documents);+ void semanticSearch.embedCorpus(embeddableDocs);let input: WorkspaceSemanticInput | undefined;let queryEmbedMs: number | null = null;if (intent === 'full_text' && query.trim().length >= SEMANTIC_MIN_QUERY_LENGTH) {const startedAt = performance.now();- const scores = await semanticSearch.queryScores(query, corpus.documents);+ const scores = await semanticSearch.queryScores(query, embeddableDocs);queryEmbedMs = performance.now() - startedAt;if (scores && scores.size > 0) {const similarityFloor = getSemanticSimilarityFloor?.();@@ -10028,7 +10071,7 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {source: SearchSource;}): Promise<SearchSuccess> {const startedAt = performance.now();- const corpus = await getWorkspaceSearchCorpus();+ const { corpus, truncated } = await getWorkspaceSearchCorpus();const semantic = await resolveSemantic(params.query,params.intent,@@ -10075,13 +10118,29 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {results: entries,elapsedMs: Math.max(0, performance.now() - startedAt),...(semanticStatus ? { semantic: semanticStatus } : {}),+ ...(truncated ? { truncated: true } : {}),};}- async function buildWorkspaceSearchDocumentsFromIndex(): Promise<WorkspaceSearchDocument[]> {+ async function buildWorkspaceSearchDocumentsFromIndex(): Promise<{+ documents: WorkspaceSearchDocument[];+ truncated: boolean;+ }> {const pages: WorkspaceSearchDocument[] = [];- for (const [docName, entry] of getFileIndex()) {- if (isSystemDoc(docName) || isConfigDoc(docName) || isHiddenDocName(docName)) continue;+ const files: WorkspaceSearchDocument[] = [];+ for (const [docName, entry] of getAllFilesIndex()) {+ if (isSystemDoc(docName) || isConfigDoc(docName)) continue;+ if (entry.kind === 'file') {+ files.push(+ createWorkspaceSearchDocument({+ kind: 'file',+ path: docName,+ modifiedTs: Date.parse(entry.modified),+ aliases: entry.aliases,+ }),+ );+ continue;+ }let content = '';let title = docName;try {@@ -10097,17 +10156,46 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {title,content,modifiedTs: Date.parse(entry.modified),+ aliases: entry.aliases,}),);}- return [...pages, ...deriveFolderSearchDocuments(pages)];+ const maxFiles = getSearchMaxEntries();+ let admittedFiles = files;+ let truncated = false;+ if (files.length > maxFiles) {+ truncated = true;+ admittedFiles = [...files]+ .sort((a, b) => {+ const depthA = a.path.split('/').length;+ const depthB = b.path.split('/').length;+ return depthA - depthB || a.path.localeCompare(b.path);+ })+ .slice(0, maxFiles);+ getLogger('search').warn(+ {+ dropped: files.length - admittedFiles.length,+ retained: admittedFiles.length,+ limit: maxFiles,+ },+ '[search] corpus name-only file tier truncated at OK_SEARCH_MAX_ENTRIES',+ );+ searchCorpusTruncatedCounter().add(1);+ }+ const documents = [+ ...pages,+ ...admittedFiles,+ ...deriveFolderSearchDocuments([...pages, ...admittedFiles]),+ ];+ return { documents, truncated };}function workspaceSearchFingerprint(): string {- return [...getFileIndex()]- .filter(- ([docName]) => !isSystemDoc(docName) && !isConfigDoc(docName) && !isHiddenDocName(docName),- )+ if (getFileIndexGeneration) {+ return `gen:${getFileIndexGeneration()}`;+ }+ return [...getAllFilesIndex()]+ .filter(([docName]) => !isSystemDoc(docName) && !isConfigDoc(docName)).sort(([a], [b]) => a.localeCompare(b)).map(([docName, entry]) =>@@ -10116,27 +10204,38 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {.join('');}- async function getWorkspaceSearchCorpus(): Promise<WorkspaceSearchCorpus> {+ async function getWorkspaceSearchCorpus(): Promise<{+ corpus: WorkspaceSearchCorpus;+ truncated: boolean;+ }> {const cacheKey = `${contentDir} ${projectDir ?? ''}`;const fingerprint = workspaceSearchFingerprint();const workspaceSearchCache = workspaceSearchCaches.get(cacheKey);if (workspaceSearchCache?.fingerprint === fingerprint && workspaceSearchCache.corpus) {- return workspaceSearchCache.corpus;+ return {+ corpus: workspaceSearchCache.corpus,+ truncated: workspaceSearchCache.truncated ?? false,+ };}if (workspaceSearchCache?.fingerprint === fingerprint && workspaceSearchCache.pending) {return workspaceSearchCache.pending;}- const pending = buildWorkspaceSearchDocumentsFromIndex().then((documents) =>- createWorkspaceSearchCorpus(documents),- );+ const pending = buildWorkspaceSearchDocumentsFromIndex().then(({ documents, truncated }) => ({+ corpus: createWorkspaceSearchCorpus(documents),+ truncated,+ }));workspaceSearchCaches.set(cacheKey, { fingerprint, pending });try {- const corpus = await pending;+ const result = await pending;if (workspaceSearchCaches.get(cacheKey)?.pending === pending) {- workspaceSearchCaches.set(cacheKey, { fingerprint, corpus });+ workspaceSearchCaches.set(cacheKey, {+ fingerprint,+ corpus: result.corpus,+ truncated: result.truncated,+ });}- return corpus;+ return result;} catch (err) {if (workspaceSearchCaches.get(cacheKey)?.pending === pending) {workspaceSearchCaches.delete(cacheKey);diff --git a/packages/server/src/api-search-semantic-factory.test.ts b/packages/server/src/api-search-semantic-factory.test.tsindex e0eea2224..a749f3fb1 100644--- a/packages/server/src/api-search-semantic-factory.test.ts+++ b/packages/server/src/api-search-semantic-factory.test.ts@@ -172,7 +172,9 @@ describe('createServer boot — flag-ON semantic search (factory glue)', () => {expect(rotation?.signals.vector ?? 0).toBeGreaterThan(0.3);expect(result?.results?.find((r) => r.path === 'archive/old-secrets')).toBeUndefined();- expect(result?.results?.find((r) => r.path.startsWith('.cursor/'))).toBeUndefined();+ const hiddenHit = result?.results?.find((r) => r.path.startsWith('.cursor/'));+ expect(hiddenHit, 'hidden dot-path is searchable').toBeDefined();+ expect(hiddenHit?.signals.vector, 'but a hidden dot-path is never embedded').toBeUndefined();expect(existsSync(join(tmpDir, '.ok', 'local', 'embeddings'))).toBe(true);}, 30_000);@@ -206,7 +208,7 @@ describe('createServer boot — flag-ON semantic search (factory glue)', () => {});for (const r of results ?? []) expect('vector' in r.signals).toBe(false);expect(results?.find((r) => r.path === 'guides/credential-rotation')).toBeUndefined();- expect(results?.find((r) => r.path.startsWith('.cursor/'))).toBeUndefined();+ expect(results?.find((r) => r.path.startsWith('.cursor/'))).toBeDefined();expect(semantic).toBeUndefined();});diff --git a/packages/server/src/api-search.test.ts b/packages/server/src/api-search.test.tsindex 8f24c5c4f..37b42944b 100644--- a/packages/server/src/api-search.test.ts+++ b/packages/server/src/api-search.test.ts@@ -4,7 +4,11 @@ import type { IncomingMessage, ServerResponse } from 'node:http';import { tmpdir } from 'node:os';import { join } from 'node:path';import { Readable } from 'node:stream';-import { createApiExtension } from './api-extension.ts';+import {+ createApiExtension,+ DEFAULT_SEARCH_MAX_ENTRIES,+ getSearchMaxEntries,+} from './api-extension.ts';import type { FileIndexEntry } from './file-watcher.ts';interface CapturedResponse {@@ -51,6 +55,7 @@ function buildFileIndex(dir: string, base = ''): ReadonlyMap<string, FileIndexEncanonicalPath: join(dir, entry.name),inode: stat.ino,aliases: [],+ kind: 'markdown',});}}@@ -175,3 +180,495 @@ describe('GET /api/search', () => {}});});++function indexEntry(canonicalPath: string, kind: FileIndexEntry['kind']): FileIndexEntry {+ const stat = statSync(canonicalPath);+ return {+ size: stat.size,+ modified: stat.mtime.toISOString(),+ canonicalPath,+ inode: stat.ino,+ aliases: [],+ kind,+ };+}++async function runSearch(+ contentDir: string,+ allFilesIndex: ReadonlyMap<string, FileIndexEntry>,+ url: string,+ method = 'GET',+ body = '',+): Promise<CapturedResponse> {+ const markdownOnly = new Map([...allFilesIndex].filter(([, entry]) => entry.kind === 'markdown'));+ const ext = createApiExtension({+ hocuspocus: {} as unknown as Parameters<typeof createApiExtension>[0]['hocuspocus'],+ sessionManager: {} as unknown as Parameters<typeof createApiExtension>[0]['sessionManager'],+ contentDir,+ serverInstanceId: 'test-server',+ getFileIndex: () => markdownOnly,+ getAllFilesIndex: () => allFilesIndex,+ });+ const req = makeReq(method, url, body);+ const { res, captured } = makeRes();+ await (+ ext as {+ onRequest: (ctx: { request: IncomingMessage; response: ServerResponse }) => Promise<void>;+ }+ ).onRequest({ request: req, response: res });+ return captured;+}++function resultPaths(captured: CapturedResponse): string[] {+ const body = JSON.parse(captured.body) as { results?: Array<{ path: string }> };+ return (body.results ?? []).map((row) => row.path);+}++describe('GET /api/search — all-files coverage', () => {+ test('a non-markdown file is returned as a kind:file result with no content snippet', async () => {+ const dir = mkdtempSync(join(tmpdir(), 'ok-search-files-'));+ try {+ writeFileSync(join(dir, 'guide.md'), '# Guide\n\nReference body.\n', 'utf-8');+ writeFileSync(join(dir, 'data.csv'), 'a,b\n1,2\n', 'utf-8');+ const index = new Map<string, FileIndexEntry>([+ ['guide', indexEntry(join(dir, 'guide.md'), 'markdown')],+ ['data.csv', indexEntry(join(dir, 'data.csv'), 'file')],+ ]);++ const captured = await runSearch(dir, index, '/api/search?query=data.csv&intent=omnibar');+ expect(captured.status).toBe(200);+ const body = JSON.parse(captured.body) as {+ results: Array<{ kind: string; path: string; snippet?: string }>;+ };+ const hit = body.results.find((row) => row.path === 'data.csv');+ expect(hit).toBeDefined();+ expect(hit?.kind).toBe('file');+ expect(hit?.snippet).toBeUndefined();+ } finally {+ rmSync(dir, { recursive: true, force: true });+ }+ });++ test('the search corpus is built from the index, not the disk — a file pruned from the index is not searchable (AC4)', async () => {+ const dir = mkdtempSync(join(tmpdir(), 'ok-search-ac4-'));+ try {+ writeFileSync(join(dir, 'guide.md'), '# Guide\n', 'utf-8');+ writeFileSync(join(dir, 'present.log'), 'x', 'utf-8');+ writeFileSync(join(dir, 'pruned.log'), 'x', 'utf-8');+ const index = new Map<string, FileIndexEntry>([+ ['guide', indexEntry(join(dir, 'guide.md'), 'markdown')],+ ['present.log', indexEntry(join(dir, 'present.log'), 'file')],+ ]);++ expect(resultPaths(await runSearch(dir, index, '/api/search?query=present.log'))).toContain(+ 'present.log',+ );+ expect(+ resultPaths(await runSearch(dir, index, '/api/search?query=pruned.log')),+ ).not.toContain('pruned.log');+ } finally {+ rmSync(dir, { recursive: true, force: true });+ }+ });++ test('changing a non-markdown file invalidates the corpus cache (fingerprint covers kind:file)', async () => {+ const dir = mkdtempSync(join(tmpdir(), 'ok-search-fp-'));+ try {+ writeFileSync(join(dir, 'guide.md'), '# Guide\n', 'utf-8');+ writeFileSync(join(dir, 'first.csv'), 'x', 'utf-8');+ const index = new Map<string, FileIndexEntry>([+ ['guide', indexEntry(join(dir, 'guide.md'), 'markdown')],+ ['first.csv', indexEntry(join(dir, 'first.csv'), 'file')],+ ]);+ const getAll = () => index;+ const markdownOnly = () =>+ new Map([...index].filter(([, entry]) => entry.kind === 'markdown'));+ const ext = createApiExtension({+ hocuspocus: {} as unknown as Parameters<typeof createApiExtension>[0]['hocuspocus'],+ sessionManager: {} as unknown as Parameters<typeof createApiExtension>[0]['sessionManager'],+ contentDir: dir,+ serverInstanceId: 'test-server',+ getFileIndex: markdownOnly,+ getAllFilesIndex: getAll,+ });+ const run = async (url: string): Promise<string[]> => {+ const req = makeReq('GET', url);+ const { res, captured } = makeRes();+ await (+ ext as {+ onRequest: (ctx: {+ request: IncomingMessage;+ response: ServerResponse;+ }) => Promise<void>;+ }+ ).onRequest({ request: req, response: res });+ return resultPaths(captured);+ };++ expect(await run('/api/search?query=second.csv')).not.toContain('second.csv');++ writeFileSync(join(dir, 'second.csv'), 'y', 'utf-8');+ index.set('second.csv', indexEntry(join(dir, 'second.csv'), 'file'));++ expect(await run('/api/search?query=second.csv')).toContain('second.csv');+ } finally {+ rmSync(dir, { recursive: true, force: true });+ }+ });+});++describe('GET /api/search — folder synthesis from all paths', () => {+ test('a folder containing only non-markdown files appears as a folder result (AC2)', async () => {+ const dir = mkdtempSync(join(tmpdir(), 'ok-search-folder-'));+ try {+ writeFileSync(join(dir, 'guide.md'), '# Guide\n', 'utf-8');+ mkdirSync(join(dir, 'assets'), { recursive: true });+ writeFileSync(join(dir, 'assets', 'logo.png'), 'x', 'utf-8');+ const index = new Map<string, FileIndexEntry>([+ ['guide', indexEntry(join(dir, 'guide.md'), 'markdown')],+ ['assets/logo.png', indexEntry(join(dir, 'assets', 'logo.png'), 'file')],+ ]);++ const captured = await runSearch(dir, index, '/api/search?query=assets&intent=omnibar');+ expect(captured.status).toBe(200);+ const body = JSON.parse(captured.body) as { results: Array<{ kind: string; path: string }> };+ expect(body.results.some((r) => r.kind === 'folder' && r.path === 'assets')).toBe(true);+ } finally {+ rmSync(dir, { recursive: true, force: true });+ }+ });++ test('a partial folder-path query resolves a markdown-free folder (AC16)', async () => {+ const dir = mkdtempSync(join(tmpdir(), 'ok-search-folderpath-'));+ try {+ writeFileSync(join(dir, 'readme.md'), '# Root\n', 'utf-8');+ const deep = join(dir, 'packages', 'server', 'src');+ mkdirSync(deep, { recursive: true });+ writeFileSync(join(deep, 'server-factory.ts'), 'export {};\n', 'utf-8');+ const index = new Map<string, FileIndexEntry>([+ ['readme', indexEntry(join(dir, 'readme.md'), 'markdown')],+ [+ 'packages/server/src/server-factory.ts',+ indexEntry(join(deep, 'server-factory.ts'), 'file'),+ ],+ ]);++ const captured = await runSearch(+ dir,+ index,+ `/api/search?query=${encodeURIComponent('server/src')}&intent=omnibar`,+ );+ expect(captured.status).toBe(200);+ const body = JSON.parse(captured.body) as { results: Array<{ kind: string; path: string }> };+ expect(+ body.results.some((r) => r.kind === 'folder' && r.path === 'packages/server/src'),+ ).toBe(true);+ } finally {+ rmSync(dir, { recursive: true, force: true });+ }+ });+});++describe('GET /api/search — name-only file tier admission cap (D6)', () => {+ const KEY = 'OK_SEARCH_MAX_ENTRIES';++ test('caps the file tier deepest-first, keeps markdown, and signals truncated (AC6)', async () => {+ const dir = mkdtempSync(join(tmpdir(), 'ok-search-cap-'));+ const prev = process.env[KEY];+ process.env[KEY] = '2';+ try {+ writeFileSync(join(dir, 'data-notes.md'), '# Data Notes\n', 'utf-8');+ writeFileSync(join(dir, 'data-a.txt'), 'x', 'utf-8');+ mkdirSync(join(dir, 'x'), { recursive: true });+ writeFileSync(join(dir, 'x', 'data-b.txt'), 'x', 'utf-8');+ mkdirSync(join(dir, 'x', 'y'), { recursive: true });+ writeFileSync(join(dir, 'x', 'y', 'data-c.txt'), 'x', 'utf-8');+ const index = new Map<string, FileIndexEntry>([+ ['data-notes', indexEntry(join(dir, 'data-notes.md'), 'markdown')],+ ['data-a.txt', indexEntry(join(dir, 'data-a.txt'), 'file')],+ ['x/data-b.txt', indexEntry(join(dir, 'x', 'data-b.txt'), 'file')],+ ['x/y/data-c.txt', indexEntry(join(dir, 'x', 'y', 'data-c.txt'), 'file')],+ ]);++ const captured = await runSearch(+ dir,+ index,+ '/api/search?query=data&intent=omnibar&limit=100',+ );+ expect(captured.status).toBe(200);+ const body = JSON.parse(captured.body) as {+ truncated?: boolean;+ results: Array<{ kind: string; path: string }>;+ };+ const paths = body.results.map((r) => r.path);+ expect(body.truncated).toBe(true);+ expect(paths).toContain('data-a.txt');+ expect(paths).toContain('x/data-b.txt');+ expect(paths).not.toContain('x/y/data-c.txt');+ expect(paths).toContain('data-notes');+ } finally {+ if (prev === undefined) delete process.env[KEY];+ else process.env[KEY] = prev;+ rmSync(dir, { recursive: true, force: true });+ }+ });++ test('no truncated flag when the file tier is under the cap', async () => {+ const dir = mkdtempSync(join(tmpdir(), 'ok-search-uncapped-'));+ const prev = process.env[KEY];+ process.env[KEY] = '1000';+ try {+ writeFileSync(join(dir, 'report.csv'), 'x', 'utf-8');+ const index = new Map<string, FileIndexEntry>([+ ['report.csv', indexEntry(join(dir, 'report.csv'), 'file')],+ ]);+ const captured = await runSearch(dir, index, '/api/search?query=report&intent=omnibar');+ const body = JSON.parse(captured.body) as { truncated?: boolean };+ expect(body.truncated).toBeUndefined();+ } finally {+ if (prev === undefined) delete process.env[KEY];+ else process.env[KEY] = prev;+ rmSync(dir, { recursive: true, force: true });+ }+ });++ test('cap tie-break: at equal depth the locale-earlier path wins', async () => {+ const dir = mkdtempSync(join(tmpdir(), 'ok-search-tiebreak-'));+ const prev = process.env[KEY];+ process.env[KEY] = '1';+ try {+ writeFileSync(join(dir, 'data-aaa.csv'), 'x', 'utf-8');+ writeFileSync(join(dir, 'data-bbb.csv'), 'x', 'utf-8');+ const index = new Map<string, FileIndexEntry>([+ ['data-aaa.csv', indexEntry(join(dir, 'data-aaa.csv'), 'file')],+ ['data-bbb.csv', indexEntry(join(dir, 'data-bbb.csv'), 'file')],+ ]);+ const captured = await runSearch(dir, index, '/api/search?query=data&intent=omnibar');+ const body = JSON.parse(captured.body) as {+ truncated?: boolean;+ results: Array<{ kind: string; path: string }>;+ };+ expect(body.truncated).toBe(true);+ const filePaths = body.results.filter((r) => r.kind === 'file').map((r) => r.path);+ expect(filePaths).toContain('data-aaa.csv');+ expect(filePaths).not.toContain('data-bbb.csv');+ } finally {+ if (prev === undefined) delete process.env[KEY];+ else process.env[KEY] = prev;+ rmSync(dir, { recursive: true, force: true });+ }+ });++ test('truncated persists across a corpus-cache hit (same instance, second request)', async () => {+ const dir = mkdtempSync(join(tmpdir(), 'ok-search-truncated-cache-'));+ const prev = process.env[KEY];+ process.env[KEY] = '1';+ try {+ writeFileSync(join(dir, 'data-a.csv'), 'x', 'utf-8');+ writeFileSync(join(dir, 'data-b.csv'), 'x', 'utf-8');+ const index = new Map<string, FileIndexEntry>([+ ['data-a.csv', indexEntry(join(dir, 'data-a.csv'), 'file')],+ ['data-b.csv', indexEntry(join(dir, 'data-b.csv'), 'file')],+ ]);+ const getAll = () => index;+ const markdownOnly = () =>+ new Map([...index].filter(([, entry]) => entry.kind === 'markdown'));+ const ext = createApiExtension({+ hocuspocus: {} as unknown as Parameters<typeof createApiExtension>[0]['hocuspocus'],+ sessionManager: {} as unknown as Parameters<typeof createApiExtension>[0]['sessionManager'],+ contentDir: dir,+ serverInstanceId: 'test-server',+ getFileIndex: markdownOnly,+ getAllFilesIndex: getAll,+ });+ const run = async (url: string): Promise<{ truncated?: boolean }> => {+ const req = makeReq('GET', url);+ const { res, captured } = makeRes();+ await (+ ext as {+ onRequest: (ctx: {+ request: IncomingMessage;+ response: ServerResponse;+ }) => Promise<void>;+ }+ ).onRequest({ request: req, response: res });+ return JSON.parse(captured.body) as { truncated?: boolean };+ };++ const first = await run('/api/search?query=data&intent=omnibar');+ expect(first.truncated).toBe(true);+ const second = await run('/api/search?query=data-a&intent=omnibar');+ expect(second.truncated).toBe(true);+ } finally {+ if (prev === undefined) delete process.env[KEY];+ else process.env[KEY] = prev;+ rmSync(dir, { recursive: true, force: true });+ }+ });+});++describe('getSearchMaxEntries — env parse', () => {+ const KEY = 'OK_SEARCH_MAX_ENTRIES';+ const cases: Array<[string, number]> = [+ ['0', DEFAULT_SEARCH_MAX_ENTRIES],+ ['-1', DEFAULT_SEARCH_MAX_ENTRIES],+ ['1.5', DEFAULT_SEARCH_MAX_ENTRIES],+ ['abc', DEFAULT_SEARCH_MAX_ENTRIES],+ ['7', 7],+ ];+ for (const [raw, expected] of cases) {+ test(`env=${JSON.stringify(raw)} → ${expected}`, () => {+ const prev = process.env[KEY];+ process.env[KEY] = raw;+ try {+ expect(getSearchMaxEntries()).toBe(expected);+ } finally {+ if (prev === undefined) delete process.env[KEY];+ else process.env[KEY] = prev;+ }+ });+ }++ test('missing env → default', () => {+ const prev = process.env[KEY];+ delete process.env[KEY];+ try {+ expect(getSearchMaxEntries()).toBe(DEFAULT_SEARCH_MAX_ENTRIES);+ } finally {+ if (prev !== undefined) process.env[KEY] = prev;+ }+ });+});++describe('GET /api/search — symlink alias handling (D16)', () => {+ test('a symlinked file is findable by either path and appears once (AC17)', async () => {+ const dir = mkdtempSync(join(tmpdir(), 'ok-search-symlink-'));+ try {+ writeFileSync(join(dir, 'data.csv'), 'x', 'utf-8');+ const entry: FileIndexEntry = {+ ...indexEntry(join(dir, 'data.csv'), 'file'),+ aliases: ['mirror/data.csv'],+ };+ const index = new Map<string, FileIndexEntry>([['data.csv', entry]]);++ const byCanonical = resultPaths(+ await runSearch(dir, index, '/api/search?query=data.csv&intent=omnibar'),+ );+ expect(byCanonical.filter((p) => p === 'data.csv')).toEqual(['data.csv']);++ const byAlias = resultPaths(+ await runSearch(dir, index, '/api/search?query=mirror&intent=omnibar'),+ );+ expect(byAlias.filter((p) => p === 'data.csv')).toEqual(['data.csv']);+ } finally {+ rmSync(dir, { recursive: true, force: true });+ }+ });+});++describe('GET /api/search — operational budget (D15)', () => {+ test('a name-only file entry is searchable without its content being read (AC20)', async () => {+ const dir = mkdtempSync(join(tmpdir(), 'ok-search-noread-'));+ try {+ const index = new Map<string, FileIndexEntry>([+ [+ 'ghost-data.csv',+ {+ size: 1,+ modified: new Date(0).toISOString(),+ canonicalPath: join(dir, 'does-not-exist.csv'),+ inode: 1,+ aliases: [],+ kind: 'file',+ },+ ],+ ]);+ const paths = resultPaths(+ await runSearch(dir, index, '/api/search?query=ghost&intent=omnibar'),+ );+ expect(paths).toContain('ghost-data.csv');+ } finally {+ rmSync(dir, { recursive: true, force: true });+ }+ });++ test('builds a large all-files corpus within budget (AC18/AC19, measured)', async () => {+ const dir = mkdtempSync(join(tmpdir(), 'ok-search-scale-'));+ try {+ const N = 5000;+ const index = new Map<string, FileIndexEntry>();+ for (let i = 0; i < N; i++) {+ const path = `pkg${i % 50}/mod${i % 20}/file-${i}.ts`;+ index.set(path, {+ size: 1,+ modified: new Date(0).toISOString(),+ canonicalPath: join(dir, `f${i}`),+ inode: i + 1,+ aliases: [],+ kind: 'file',+ });+ }+ const rssBefore = process.memoryUsage().rss;+ const startedAt = performance.now();+ const captured = await runSearch(+ dir,+ index,+ '/api/search?query=file-42&intent=omnibar&limit=20',+ );+ const elapsedMs = performance.now() - startedAt;+ const rssDeltaMb = (process.memoryUsage().rss - rssBefore) / 1e6;+ console.warn(+ `[US-013] ${N}-file corpus: build+search ${elapsedMs.toFixed(0)}ms, rssDelta ${rssDeltaMb.toFixed(1)}MB`,+ );+ expect(captured.status).toBe(200);+ expect(resultPaths(captured).length).toBeGreaterThan(0);+ expect(elapsedMs).toBeLessThan(10_000);+ } finally {+ rmSync(dir, { recursive: true, force: true });+ }+ });+});++describe('GET /api/search — dot-path searchability', () => {+ test('a tracked dot-path markdown is searchable (AC3)', async () => {+ const dir = mkdtempSync(join(tmpdir(), 'ok-search-dotpath-'));+ try {+ writeFileSync(join(dir, 'guide.md'), '# Guide\n', 'utf-8');+ mkdirSync(join(dir, '.changeset'), { recursive: true });+ writeFileSync(+ join(dir, '.changeset', 'release.md'),+ '# Release\n\nChangeset notes.\n',+ 'utf-8',+ );+ const index = new Map<string, FileIndexEntry>([+ ['guide', indexEntry(join(dir, 'guide.md'), 'markdown')],+ ['.changeset/release', indexEntry(join(dir, '.changeset', 'release.md'), 'markdown')],+ ]);++ expect(+ resultPaths(await runSearch(dir, index, '/api/search?query=release&intent=omnibar')),+ ).toContain('.changeset/release');+ } finally {+ rmSync(dir, { recursive: true, force: true });+ }+ });++ test('a config synthetic doc stays out of search even with the dot-path filter softened', async () => {+ const dir = mkdtempSync(join(tmpdir(), 'ok-search-configdoc-'));+ try {+ writeFileSync(join(dir, 'guide.md'), '# Guide\n', 'utf-8');+ mkdirSync(join(dir, '__config__'), { recursive: true });+ writeFileSync(join(dir, '__config__', 'project.md'), '# Project Config\n', 'utf-8');+ const index = new Map<string, FileIndexEntry>([+ ['guide', indexEntry(join(dir, 'guide.md'), 'markdown')],+ ['__config__/project', indexEntry(join(dir, '__config__', 'project.md'), 'markdown')],+ ]);++ expect(+ resultPaths(await runSearch(dir, index, '/api/search?query=project&intent=omnibar')),+ ).not.toContain('__config__/project');+ } finally {+ rmSync(dir, { recursive: true, force: true });+ }+ });+});diff --git a/packages/server/src/content-filter.test.ts b/packages/server/src/content-filter.test.tsindex 313e0f3fe..425e40645 100644--- a/packages/server/src/content-filter.test.ts+++ b/packages/server/src/content-filter.test.ts@@ -511,6 +511,73 @@ describe('ContentFilter', () => {expect(filter.isExcluded('archive.DS_Store', BYPASS)).toBe(false);expect(filter.isExcluded('notes/my.DS_Store.md', BYPASS)).toBe(false);+ expect(filter.isExcluded('.env', BYPASS)).toBe(true);+ expect(filter.isExcluded('.env.local', BYPASS)).toBe(true);+ expect(filter.isExcluded('.env.production', BYPASS)).toBe(true);+ expect(filter.isExcluded('packages/server/.env', BYPASS)).toBe(true);+ expect(filter.isExcluded('aws-prod-root-key.pem', BYPASS)).toBe(true);+ expect(filter.isExcluded('SERVER.PEM', BYPASS)).toBe(true);+ expect(filter.isExcluded('secrets/cert.key', BYPASS)).toBe(true);+ expect(filter.isExcluded('artifacts/cert.p12', BYPASS)).toBe(true);+ expect(filter.isExcluded('id_rsa', BYPASS)).toBe(true);+ expect(filter.isExcluded('id_rsa.pub', BYPASS)).toBe(true);+ expect(filter.isExcluded('.aws/credentials', BYPASS)).toBe(true);+ expect(filter.isExcluded('credentials', BYPASS)).toBe(true);+ expect(filter.isPathIgnored('.env', BYPASS)).toBe(true);+ expect(filter.isPathIgnored('packages/.env.local', BYPASS)).toBe(true);+ expect(filter.isPathIgnored('aws-prod-root-key.pem', BYPASS)).toBe(true);+ expect(filter.isPathIgnored('id_rsa', BYPASS)).toBe(true);+ expect(filter.isDirExcluded('.ssh', BYPASS)).toBe(true);+ expect(filter.isDirExcluded('.aws', BYPASS)).toBe(true);+ expect(filter.isDirExcluded('.gnupg', BYPASS)).toBe(true);+ expect(filter.isDirExcluded('.kube', BYPASS)).toBe(true);+ expect(filter.isDirExcluded('.docker', BYPASS)).toBe(true);+ expect(filter.isDirExcluded('home/user/.ssh', BYPASS)).toBe(true);+ expect(filter.isDirExcluded('home/user/.kube', BYPASS)).toBe(true);+ expect(filter.isDirExcluded('home/user/.docker', BYPASS)).toBe(true);+ expect(filter.isExcluded('.ssh/id_ed25519', BYPASS)).toBe(true);+ expect(filter.isExcluded('.kube/config', BYPASS)).toBe(true);+ expect(filter.isExcluded('.docker/config.json', BYPASS)).toBe(true);+ expect(filter.isExcluded('home/user/.aws/credentials', BYPASS)).toBe(true);+ expect(filter.isPathIgnored('.ssh/known_hosts', BYPASS)).toBe(true);+ expect(filter.isExcluded('id_ed25519', BYPASS)).toBe(true);+ expect(filter.isExcluded('id_ecdsa', BYPASS)).toBe(true);+ expect(filter.isExcluded('id_dsa', BYPASS)).toBe(true);+ expect(filter.isExcluded('id_ed25519.pub', BYPASS)).toBe(true);+ expect(filter.isPathIgnored('id_ed25519', BYPASS)).toBe(true);+ expect(filter.isExcluded('.netrc', BYPASS)).toBe(true);+ expect(filter.isExcluded('.npmrc', BYPASS)).toBe(true);+ expect(filter.isExcluded('.pgpass', BYPASS)).toBe(true);+ expect(filter.isExcluded('.git-credentials', BYPASS)).toBe(true);+ expect(filter.isExcluded('notes/.netrc', BYPASS)).toBe(true);+ expect(filter.isExcluded('packages/.npmrc', BYPASS)).toBe(true);+ expect(filter.isPathIgnored('.netrc', BYPASS)).toBe(true);+ expect(filter.isPathIgnored('.git-credentials', BYPASS)).toBe(true);+ expect(filter.isExcluded('certs/server.pfx', BYPASS)).toBe(true);+ expect(filter.isExcluded('certs/SERVER.PFX', BYPASS)).toBe(true);+ expect(filter.isExcluded('app/release.keystore', BYPASS)).toBe(true);+ expect(filter.isExcluded('release.jks', BYPASS)).toBe(true);+ expect(filter.isExcluded('windows-id.ppk', BYPASS)).toBe(true);+ expect(filter.isPathIgnored('release.jks', BYPASS)).toBe(true);+ expect(filter.isExcluded('docs/.environment.md', BYPASS)).toBe(false);+ expect(filter.isExcluded('docs/keymap.md', BYPASS)).toBe(false);+ expect(filter.isExcluded('packages/foo/keynote.md', BYPASS)).toBe(false);+ expect(filter.isExcluded('docs/.npmrc.example', BYPASS)).toBe(false);+ expect(filter.isExcluded('docs/mynetrc.md', BYPASS)).toBe(false);++ expect(filter.isExcluded('.ENV', BYPASS)).toBe(true);+ expect(filter.isExcluded('packages/server/.Env.Production', BYPASS)).toBe(true);+ expect(filter.isExcluded('ID_RSA', BYPASS)).toBe(true);+ expect(filter.isExcluded('ID_ED25519', BYPASS)).toBe(true);+ expect(filter.isExcluded('CREDENTIALS', BYPASS)).toBe(true);+ expect(filter.isExcluded('.GIT-CREDENTIALS', BYPASS)).toBe(true);+ expect(filter.isPathIgnored('.ENV', BYPASS)).toBe(true);+ expect(filter.isDirExcluded('.SSH', BYPASS)).toBe(true);+ expect(filter.isDirExcluded('home/user/.AWS', BYPASS)).toBe(true);+ expect(filter.isExcluded('.SSH/known_hosts', BYPASS)).toBe(true);+ expect(filter.isExcluded('docs/.Environment.md', BYPASS)).toBe(false);+ expect(filter.isExcluded('docs/KEYMAP.md', BYPASS)).toBe(false);+expect(filter.isDirExcluded('dist', BYPASS)).toBe(false);expect(filter.isDirExcluded('build', BYPASS)).toBe(false);expect(filter.isDirExcluded('coverage', BYPASS)).toBe(false);diff --git a/packages/server/src/content-filter.ts b/packages/server/src/content-filter.tsindex 0bbfe02b2..5c304dc49 100644--- a/packages/server/src/content-filter.ts+++ b/packages/server/src/content-filter.ts@@ -97,6 +97,41 @@ function isAlwaysSkipFile(relativePath: string): boolean {return BUILTIN_SKIP_FILES.has(relativePath.slice(relativePath.lastIndexOf('/') + 1));}+const SECRET_BEARING_DIRS = new Set(['.ssh', '.aws', '.gnupg', '.kube', '.docker']);++function pathHasSecretBearingDirSegment(relativePath: string): boolean {+ for (const segment of relativePath.split('/')) {+ if (SECRET_BEARING_DIRS.has(segment.toLowerCase())) return true;+ }+ return false;+}++const SECRET_CREDENTIAL_BASENAMES = new Set([+ 'credentials',+ '.netrc',+ '.npmrc',+ '.pgpass',+ '.git-credentials',+]);+const SECRET_KEY_SUFFIXES = ['.pem', '.key', '.p12', '.pfx', '.keystore', '.jks', '.ppk'] as const;+function isSecretBearingFile(relativePath: string): boolean {+ const lower = relativePath.slice(relativePath.lastIndexOf('/') + 1).toLowerCase();+ if (lower === '.env' || lower.startsWith('.env.')) return true;+ if (SECRET_CREDENTIAL_BASENAMES.has(lower)) return true;+ if (+ lower.startsWith('id_rsa') ||+ lower.startsWith('id_ed25519') ||+ lower.startsWith('id_ecdsa') ||+ lower.startsWith('id_dsa')+ ) {+ return true;+ }+ for (const suffix of SECRET_KEY_SUFFIXES) {+ if (lower.endsWith(suffix)) return true;+ }+ return false;+}+function isSingleDocAncestorDir(relativeDir: string, singleDocRelPath: string): boolean {return singleDocRelPath === relativeDir || singleDocRelPath.startsWith(`${relativeDir}/`);}@@ -394,6 +429,9 @@ export function createContentFilter(opts: ContentFilterOptions): ContentFilter {if (isAlwaysSkipFile(relativePath)) return true;+ if (isSecretBearingFile(relativePath)) return true;+ if (pathHasSecretBearingDirSegment(relativePath)) return true;+if (singleDocRelPath !== undefined) return relativePath !== singleDocRelPath;if (opts?.bypassFilters) return false;@@ -414,6 +452,7 @@ export function createContentFilter(opts: ContentFilterOptions): ContentFilter {isDirExcluded(relativePath: string, opts?: ContentFilterReadOpts): boolean {if (pathHasAlwaysSkipSegment(relativePath)) return true;+ if (pathHasSecretBearingDirSegment(relativePath)) return true;if (singleDocRelPath !== undefined) {return !isSingleDocAncestorDir(relativePath, singleDocRelPath);}@@ -432,6 +471,8 @@ export function createContentFilter(opts: ContentFilterOptions): ContentFilter {if (isReservedDocName(relativePath)) return true;if (pathHasAlwaysSkipSegment(relativePath)) return true;if (isAlwaysSkipFile(relativePath)) return true;+ if (isSecretBearingFile(relativePath)) return true;+ if (pathHasSecretBearingDirSegment(relativePath)) return true;if (opts?.bypassFilters) return false;return isRejectedByConfigurableRules(relativePath);},@@ -803,6 +844,8 @@ export async function createContentFilterAsync(opts: ContentFilterOptions): Promif (isReservedDocName(relativePath)) return true;if (pathHasAlwaysSkipSegment(relativePath)) return true;if (isAlwaysSkipFile(relativePath)) return true;+ if (isSecretBearingFile(relativePath)) return true;+ if (pathHasSecretBearingDirSegment(relativePath)) return true;if (singleDocRelPath !== undefined) return relativePath !== singleDocRelPath;if (opts?.bypassFilters) return false;if (isRejectedByConfigurableRules(relativePath)) return true;@@ -818,6 +861,7 @@ export async function createContentFilterAsync(opts: ContentFilterOptions): PromisDirExcluded(relativePath: string, opts?: ContentFilterReadOpts): boolean {if (pathHasAlwaysSkipSegment(relativePath)) return true;+ if (pathHasSecretBearingDirSegment(relativePath)) return true;if (singleDocRelPath !== undefined) {return !isSingleDocAncestorDir(relativePath, singleDocRelPath);}@@ -836,6 +880,8 @@ export async function createContentFilterAsync(opts: ContentFilterOptions): Promif (isReservedDocName(relativePath)) return true;if (pathHasAlwaysSkipSegment(relativePath)) return true;if (isAlwaysSkipFile(relativePath)) return true;+ if (isSecretBearingFile(relativePath)) return true;+ if (pathHasSecretBearingDirSegment(relativePath)) return true;if (opts?.bypassFilters) return false;return isRejectedByConfigurableRules(relativePath);},diff --git a/packages/server/src/file-watcher-allfiles.test.ts b/packages/server/src/file-watcher-allfiles.test.tsnew file mode 100644index 000000000..f5b783296--- /dev/null+++ b/packages/server/src/file-watcher-allfiles.test.ts@@ -0,0 +1,250 @@+import { afterEach, beforeEach, describe, expect, test } from 'bun:test';+import { mkdirSync, realpathSync, symlinkSync, writeFileSync } from 'node:fs';+import { mkdtemp, rm } from 'node:fs/promises';+import { tmpdir } from 'node:os';+import { resolve } from 'node:path';+import { createContentFilter } from './content-filter.ts';+import { handleRawEvents, lastKnownHash, startWatcher } from './file-watcher.ts';++describe('PRD-7117 US-001 — kind discriminator + all-files admission', () => {+ let tmpDir: string;+ let contentDir: string;++ beforeEach(async () => {+ tmpDir = realpathSync(await mkdtemp(resolve(tmpdir(), 'ok-allfiles-')));+ contentDir = resolve(tmpDir, 'content');+ mkdirSync(contentDir, { recursive: true });+ lastKnownHash.clear();+ });++ afterEach(async () => {+ await rm(tmpDir, { recursive: true, force: true });+ });++ test('seed admits markdown and non-markdown with the right kind discriminator', async () => {+ writeFileSync(resolve(contentDir, 'readme.md'), '# README\n');+ writeFileSync(resolve(contentDir, 'data.csv'), 'a,b,c\n1,2,3\n');+ writeFileSync(resolve(contentDir, 'config.json'), '{"x":1}');+ mkdirSync(resolve(contentDir, 'src'));+ writeFileSync(resolve(contentDir, 'src', 'index.ts'), 'export const x = 1;');++ const handle = await startWatcher(contentDir, async () => {});+ try {+ const all = handle.getAllFilesIndex();+ expect(all.has('readme')).toBe(true);+ expect(all.has('data.csv')).toBe(true);+ expect(all.has('config.json')).toBe(true);+ expect(all.has('src/index.ts')).toBe(true);++ expect(all.get('readme')?.kind).toBe('markdown');+ expect(all.get('data.csv')?.kind).toBe('file');+ expect(all.get('config.json')?.kind).toBe('file');+ expect(all.get('src/index.ts')?.kind).toBe('file');+ } finally {+ await handle.unsubscribe();+ }+ });++ test('getFileIndex() returns markdown-only view (D12 invert-default)', async () => {+ writeFileSync(resolve(contentDir, 'note.md'), '# Note\n');+ writeFileSync(resolve(contentDir, 'image.png'), Buffer.from([0x89, 0x50, 0x4e, 0x47]));+ writeFileSync(resolve(contentDir, 'script.ts'), 'export const y = 2;');++ const handle = await startWatcher(contentDir, async () => {});+ try {+ const md = handle.getFileIndex();+ expect(md.has('note')).toBe(true);+ expect(md.has('image.png')).toBe(false);+ expect(md.has('script.ts')).toBe(false);++ expect(md.size).toBe(1);++ expect([...md.keys()]).toEqual(['note']);+ expect([...md.values()].every((e) => e.kind === 'markdown')).toBe(true);+ const collected: string[] = [];+ md.forEach((_v, k) => {+ collected.push(k);+ });+ expect(collected).toEqual(['note']);++ expect(handle.getAllFilesIndex().size).toBe(3);+ } finally {+ await handle.unsubscribe();+ }+ });++ test('AC20: seed performs NO content read / hash for kind:"file" entries', async () => {+ writeFileSync(resolve(contentDir, 'one.md'), '# One\n');+ writeFileSync(resolve(contentDir, 'two.md'), '# Two\n');+ writeFileSync(resolve(contentDir, 'logo.svg'), '<svg/>');+ writeFileSync(resolve(contentDir, 'data.csv'), 'col\nval\n');+ writeFileSync(resolve(contentDir, 'binary.bin'), Buffer.alloc(64, 0xff));+ writeFileSync(resolve(contentDir, 'shell.sh'), '#!/bin/sh\n');++ const handle = await startWatcher(contentDir, async () => {});+ try {+ expect(lastKnownHash.has(resolve(contentDir, 'one.md'))).toBe(true);+ expect(lastKnownHash.has(resolve(contentDir, 'two.md'))).toBe(true);+ expect(lastKnownHash.has(resolve(contentDir, 'logo.svg'))).toBe(false);+ expect(lastKnownHash.has(resolve(contentDir, 'data.csv'))).toBe(false);+ expect(lastKnownHash.has(resolve(contentDir, 'binary.bin'))).toBe(false);+ expect(lastKnownHash.has(resolve(contentDir, 'shell.sh'))).toBe(false);++ expect(lastKnownHash.size).toBe(2);++ const all = handle.getAllFilesIndex();+ expect(all.has('logo.svg')).toBe(true);+ expect(all.has('data.csv')).toBe(true);+ expect(all.has('binary.bin')).toBe(true);+ expect(all.has('shell.sh')).toBe(true);+ expect(all.get('logo.svg')?.kind).toBe('file');+ } finally {+ await handle.unsubscribe();+ }+ });++ test('admission keeps ContentFilter on — gitignored non-md is NOT in the index', async () => {+ writeFileSync(resolve(tmpDir, '.gitignore'), 'dist/\n');+ mkdirSync(resolve(contentDir, 'dist'), { recursive: true });+ writeFileSync(resolve(contentDir, 'dist', 'bundle.js'), 'console.log(1);');+ writeFileSync(resolve(contentDir, 'app.ts'), 'export const z = 3;');+ writeFileSync(resolve(contentDir, 'readme.md'), '# README\n');++ const filter = createContentFilter({ projectDir: tmpDir, contentDir });+ const handle = await startWatcher(contentDir, async () => {}, filter);+ try {+ const all = handle.getAllFilesIndex();+ expect(all.has('app.ts')).toBe(true);+ expect(all.get('app.ts')?.kind).toBe('file');+ expect(all.has('readme')).toBe(true);+ expect(all.has('dist/bundle.js')).toBe(false);+ } finally {+ await handle.unsubscribe();+ }+ });++ test('live file-create event admits a new non-md file as kind:"file"', async () => {+ writeFileSync(resolve(contentDir, 'starter.md'), '# Start\n');+ const handle = await startWatcher(contentDir, async () => {});+ try {+ const newFile = resolve(contentDir, 'fresh.ts');+ writeFileSync(newFile, 'export const fresh = true;');+ await handleRawEvents(+ [{ type: 'create', path: newFile }],+ contentDir,+ undefined,+ // biome-ignore lint/suspicious/noExplicitAny: test reaches the inner map for live admission verification+ handle.getAllFilesIndex() as any,+ // biome-ignore lint/suspicious/noExplicitAny: test reaches the inner map for live admission verification+ handle.getFolderIndex() as any,+ async () => {},+ );++ const all = handle.getAllFilesIndex();+ expect(all.has('fresh.ts')).toBe(true);+ expect(all.get('fresh.ts')?.kind).toBe('file');+ expect(lastKnownHash.has(newFile)).toBe(false);+ } finally {+ await handle.unsubscribe();+ }+ });++ test('live file-delete event removes a non-md entry without touching markdown siblings', async () => {+ writeFileSync(resolve(contentDir, 'doc.md'), '# Doc\n');+ writeFileSync(resolve(contentDir, 'old.txt'), 'old');+ const handle = await startWatcher(contentDir, async () => {});+ try {+ expect(handle.getAllFilesIndex().has('old.txt')).toBe(true);+ expect(handle.getAllFilesIndex().has('doc')).toBe(true);++ await handleRawEvents(+ [{ type: 'delete', path: resolve(contentDir, 'old.txt') }],+ contentDir,+ undefined,+ // biome-ignore lint/suspicious/noExplicitAny: see above+ handle.getAllFilesIndex() as any,+ // biome-ignore lint/suspicious/noExplicitAny: see above+ handle.getFolderIndex() as any,+ async () => {},+ );++ expect(handle.getAllFilesIndex().has('old.txt')).toBe(false);+ expect(handle.getAllFilesIndex().has('doc')).toBe(true);+ expect(handle.getAllFilesIndex().get('doc')?.kind).toBe('markdown');+ } finally {+ await handle.unsubscribe();+ }+ });++ test('mutateFileIndex purges the LIVE map (regression: snapshot-cast was a no-op)', async () => {+ writeFileSync(resolve(contentDir, 'doomed.md'), '# Doomed\n');+ writeFileSync(resolve(contentDir, 'survives.md'), '# Survives\n');+ writeFileSync(resolve(contentDir, 'doomed.txt'), 'bye\n');++ const handle = await startWatcher(contentDir, async () => {});+ try {+ expect(handle.getFileIndex().has('doomed')).toBe(true);+ expect(handle.getAllFilesIndex().has('doomed')).toBe(true);+ expect(handle.getAllFilesIndex().has('doomed.txt')).toBe(true);++ handle.mutateFileIndex({+ kind: 'delete',+ path: resolve(contentDir, 'doomed.md'),+ docName: 'doomed',+ });+ handle.mutateFileIndex({+ kind: 'file-delete',+ path: resolve(contentDir, 'doomed.txt'),+ relativePath: 'doomed.txt',+ });++ expect(handle.getAllFilesIndex().has('doomed')).toBe(false);+ expect(handle.getAllFilesIndex().has('doomed.txt')).toBe(false);+ expect(handle.getFileIndex().has('doomed')).toBe(false);+ expect(handle.getFileIndex().has('survives')).toBe(true);+ } finally {+ await handle.unsubscribe();+ }+ });++ test('getFileIndex view is memoized across calls without mutation', async () => {+ writeFileSync(resolve(contentDir, 'a.md'), '# A\n');+ writeFileSync(resolve(contentDir, 'b.md'), '# B\n');++ const handle = await startWatcher(contentDir, async () => {});+ try {+ const first = handle.getFileIndex();+ const second = handle.getFileIndex();+ expect(second).toBe(first);++ handle.mutateFileIndex({+ kind: 'create',+ path: resolve(contentDir, 'c.md'),+ docName: 'c',+ content: '# C\n',+ });+ const third = handle.getFileIndex();+ expect(third).not.toBe(first);+ expect(third.has('c')).toBe(true);+ } finally {+ await handle.unsubscribe();+ }+ });++ test('symlink to non-md target produces a kind:"file" entry (one side, inode-dedup)', async () => {+ writeFileSync(resolve(contentDir, 'real.csv'), 'a\nb\n');+ symlinkSync(resolve(contentDir, 'real.csv'), resolve(contentDir, 'alias.csv'));++ const handle = await startWatcher(contentDir, async () => {});+ try {+ const all = handle.getAllFilesIndex();+ const hasReal = all.has('real.csv');+ const hasAlias = all.has('alias.csv');+ expect(Number(hasReal) + Number(hasAlias)).toBe(1);+ const present = hasReal ? all.get('real.csv') : all.get('alias.csv');+ expect(present?.kind).toBe('file');+ } finally {+ await handle.unsubscribe();+ }+ });+});diff --git a/packages/server/src/file-watcher.test.ts b/packages/server/src/file-watcher.test.tsindex add33bed7..1ea2ec262 100644--- a/packages/server/src/file-watcher.test.ts+++ b/packages/server/src/file-watcher.test.ts@@ -916,7 +916,7 @@ describe('file-watcher ContentFilter refcount hooks', () => {);const kinds = collected.map((e) => e.kind).sort();- expect(kinds).toEqual(['asset-create', 'create']);+ expect(kinds).toEqual(['asset-create', 'create', 'file-create']);const asset = collected.find((e) => e.kind === 'asset-create');expect(asset?.kind).toBe('asset-create');if (asset?.kind === 'asset-create') {@@ -954,7 +954,7 @@ describe('file-watcher ContentFilter refcount hooks', () => {);const kinds = collected.map((e) => e.kind).sort();- expect(kinds).toEqual(['asset-create', 'create']);+ expect(kinds).toEqual(['asset-create', 'create', 'file-create']);const asset = collected.find((e) => e.kind === 'asset-create');if (asset?.kind === 'asset-create') {expect(asset.relativePath).toBe('canvas-test/board.base');diff --git a/packages/server/src/file-watcher.ts b/packages/server/src/file-watcher.tsindex 422c91042..77bf71ae8 100644--- a/packages/server/src/file-watcher.ts+++ b/packages/server/src/file-watcher.ts@@ -46,7 +46,26 @@ type FolderDiskEvent =| { kind: 'folder-create'; path: string; relativePath: string }| { kind: 'folder-delete'; path: string; relativePath: string };-export type DiskEvent = MarkdownDiskEvent | AssetDiskEvent | FolderDiskEvent;+type FileDiskEvent =+ | {+ kind: 'file-create';+ path: string;+ relativePath: string;+ size: number;+ modifiedTs: number;+ inode: number;+ }+ | {+ kind: 'file-update';+ path: string;+ relativePath: string;+ size: number;+ modifiedTs: number;+ inode: number;+ }+ | { kind: 'file-delete'; path: string; relativePath: string };++export type DiskEvent = MarkdownDiskEvent | AssetDiskEvent | FolderDiskEvent | FileDiskEvent;export function assertNeverDiskEvent(event: never): never {throw new Error(`[DiskEvent] unhandled variant: ${JSON.stringify(event)}`);@@ -58,6 +77,7 @@ export interface FileIndexEntry {canonicalPath: string;inode: number;aliases: string[];+ kind: 'markdown' | 'file';}export interface FolderIndexEntry {@@ -67,11 +87,24 @@ export interface FolderIndexEntry {inode: number;}+function markdownIndexView(+ inner: ReadonlyMap<string, FileIndexEntry>,+): ReadonlyMap<string, FileIndexEntry> {+ const snapshot = new Map<string, FileIndexEntry>();+ for (const [k, v] of inner) {+ if (v.kind === 'markdown') snapshot.set(k, v);+ }+ return snapshot;+}+export interface WatcherHandle {unsubscribe: () => Promise<void>;getFileIndex: () => ReadonlyMap<string, FileIndexEntry>;+ getAllFilesIndex: () => ReadonlyMap<string, FileIndexEntry>;+ getFileIndexGeneration: () => number;getFolderIndex: () => ReadonlyMap<string, FolderIndexEntry>;getAliasMap: () => ReadonlyMap<string, string>;+ mutateFileIndex: (event: DiskEvent) => void;pruneFileIndexNowExcluded: () => number;pruneFolderIndexNowExcluded: () => number;rescanFromDisk: () => Promise<void>;@@ -505,6 +538,7 @@ async function seedLastKnownHashes(canonicalPath: canonical,inode: canonStat.ino,aliases: [aliasDocName],+ kind: 'markdown',});} catch (err) {const code = (err as NodeJS.ErrnoException).code;@@ -512,6 +546,21 @@ async function seedLastKnownHashes(console.warn(`[file-watcher] Failed to seed hash for ${canonical}:`, err);}}+ } else if (canonStat.isFile()) {+ if (contentFilter) {+ const relPath = relative(contentDir, canonical);+ if (contentFilter.isPathIgnored(relPath)) continue;+ }+ const docName = pathToDocName(fullPath, contentDir);+ if (isSystemDoc(docName) || isConfigDoc(docName)) continue;+ fileIndex.set(docName, {+ size: canonStat.size,+ modified: canonStat.mtime.toISOString(),+ canonicalPath: canonical,+ inode: canonStat.ino,+ aliases: [],+ kind: 'file',+ });}} catch (e) {console.warn(`[file-watcher] Failed to stat symlink target ${canonical}:`, e);@@ -560,6 +609,7 @@ async function seedLastKnownHashes(canonicalPath: fullPath,inode: lst.ino,aliases: [],+ kind: 'markdown',});} catch (err) {const code = (err as NodeJS.ErrnoException).code;@@ -571,6 +621,24 @@ async function seedLastKnownHashes(console.warn(`[file-watcher] Failed to seed hash for ${fullPath}:`, err);}}+ } else if (lst.isFile()) {+ if (visited.has(lst.ino)) continue;+ visited.add(lst.ino);++ if (contentFilter) {+ const relPath = relative(contentDir, fullPath);+ if (contentFilter.isPathIgnored(relPath)) continue;+ }+ const docName = pathToDocName(fullPath, contentDir);+ if (isSystemDoc(docName) || isConfigDoc(docName)) continue;+ fileIndex.set(docName, {+ size: lst.size,+ modified: lst.mtime.toISOString(),+ canonicalPath: fullPath,+ inode: lst.ino,+ aliases: [],+ kind: 'file',+ });}}} catch (err) {@@ -590,6 +658,32 @@ export function updateFileIndex(event: DiskEvent, fileIndex: Map<string, FileInd) {return;}+ if (+ event.kind === 'file-create' ||+ event.kind === 'file-update' ||+ event.kind === 'file-delete'+ ) {+ const docName = event.relativePath;+ if (isSystemDoc(docName) || isConfigDoc(docName)) return;+ if (event.kind === 'file-delete') {+ const existing = fileIndex.get(docName);+ if (existing && existing.kind === 'file') {+ fileIndex.delete(docName);+ }+ return;+ }+ const existing = fileIndex.get(docName);+ if (existing && existing.kind === 'markdown') return;+ fileIndex.set(docName, {+ size: event.size,+ modified: new Date(event.modifiedTs).toISOString(),+ canonicalPath: existing?.canonicalPath ?? event.path,+ inode: event.inode || existing?.inode || 0,+ aliases: existing?.aliases ?? [],+ kind: 'file',+ });+ return;+ }const docName = event.kind === 'rename' ? event.newDocName : event.docName;if (isSystemDoc(docName) || isConfigDoc(docName)) return;switch (event.kind) {@@ -606,6 +700,7 @@ export function updateFileIndex(event: DiskEvent, fileIndex: Map<string, FileIndcanonicalPath: existing?.canonicalPath ?? event.path,inode: existing?.inode ?? 0,aliases: existing?.aliases ?? [],+ kind: 'markdown',});break;}@@ -636,6 +731,7 @@ export function updateFileIndex(event: DiskEvent, fileIndex: Map<string, FileIndcanonicalPath: existing?.canonicalPath ?? event.newPath,inode: existing?.inode ?? 0,aliases: existing?.aliases ?? [],+ kind: 'markdown',});break;}@@ -777,13 +873,21 @@ export async function handleRawEvents(const assetEvents = safeEvents.filter((e) =>isSupportedAssetFile(e.path, LINKABLE_ASSET_EXTENSIONS),);+ const nonMdRawEvents = safeEvents.filter((e) => !isSupportedDocFile(e.path));const folderEvents = updateFolderIndexFromRawEvents(safeEvents,contentDir,contentFilter,folderIndex,);- if (mdEvents.length === 0 && assetEvents.length === 0 && folderEvents.length === 0) return;+ if (+ mdEvents.length === 0 &&+ assetEvents.length === 0 &&+ folderEvents.length === 0 &&+ nonMdRawEvents.length === 0+ ) {+ return;+ }const diskEvents =mdEvents.length > 0 ? await classifyEvents(mdEvents, contentDir, contentFilter, aliasMap) : [];@@ -909,6 +1013,53 @@ export async function handleRawEvents(: { kind: 'asset-create', path: raw.path, relativePath };await onDiskEvent(event);}++ for (const raw of nonMdRawEvents) {+ const relativePath = relative(contentDir, raw.path);+ if (contentFilter?.isPathIgnored(relativePath)) continue;+ if (isSystemDoc(relativePath) || isConfigDoc(relativePath)) continue;++ if (raw.type === 'delete') {+ const event: DiskEvent = { kind: 'file-delete', path: raw.path, relativePath };+ updateFileIndex(event, fileIndex);+ await onDiskEvent(event);+ continue;+ }++ let st: ReturnType<typeof lstatSync>;+ try {+ st = lstatSync(raw.path);+ if (st.isSymbolicLink()) st = statSync(raw.path);+ } catch (e) {+ const code = (e as NodeJS.ErrnoException).code;+ if (code !== 'ENOENT') {+ console.warn(`[file-watcher] file-event lstat failed for ${raw.path} (${code})`);+ }+ continue;+ }+ if (!st.isFile()) continue;++ const event: DiskEvent =+ raw.type === 'create'+ ? {+ kind: 'file-create',+ path: raw.path,+ relativePath,+ size: st.size,+ modifiedTs: st.mtime.getTime(),+ inode: Number(st.ino),+ }+ : {+ kind: 'file-update',+ path: raw.path,+ relativePath,+ size: st.size,+ modifiedTs: st.mtime.getTime(),+ inode: Number(st.ino),+ };+ updateFileIndex(event, fileIndex);+ await onDiskEvent(event);+ }}let _fwEventsCounterCache: ReturnType<ReturnType<typeof getMeter>['createCounter']> | null = null;@@ -926,6 +1077,7 @@ async function startParcelWatcher(folderIndex: Map<string, FolderIndexEntry>,onDiskEvent: (event: DiskEvent) => Promise<void>,aliasMap: Map<string, string>,+ onAfterMutation: () => void,): Promise<AsyncSubscription | null> {let parcel: typeof import('@parcel/watcher');try {@@ -960,6 +1112,7 @@ async function startParcelWatcher(onDiskEvent,aliasMap,);+ onAfterMutation();} catch (handleErr) {console.error('[file-watcher] parcel batch error:', handleErr);}@@ -981,6 +1134,7 @@ async function startChokidarWatcher(folderIndex: Map<string, FolderIndexEntry>,onDiskEvent: (event: DiskEvent) => Promise<void>,aliasMap: Map<string, string>,+ onAfterMutation: () => void,): Promise<AsyncSubscription> {const { watch } = await import('chokidar');@@ -1017,7 +1171,9 @@ async function startChokidarWatcher(folderIndex,onDiskEvent,aliasMap,- ).catch((err) => console.error('[file-watcher] chokidar batch error:', err));+ )+ .then(onAfterMutation)+ .catch((err) => console.error('[file-watcher] chokidar batch error:', err));}, BATCH_WINDOW_MS);}@@ -1055,6 +1211,13 @@ export async function startWatcher(const folderIndex = new Map<string, FolderIndexEntry>();const aliasMap = new Map<string, string>();+ let fileIndexGeneration = 0;+ let cachedMarkdownView: ReadonlyMap<string, FileIndexEntry> | null = null;+ let cachedMarkdownViewGeneration = -1;+ const bumpFileIndexGeneration = (): void => {+ fileIndexGeneration++;+ };+await seedLastKnownHashes(contentDir,contentDir,@@ -1063,6 +1226,7 @@ export async function startWatcher(folderIndex,aliasMap,);+ bumpFileIndexGeneration();const evictionInterval = setInterval(evictStaleTrackerEntries, WRITE_TRACKER_TTL_MS);@@ -1076,6 +1240,7 @@ export async function startWatcher(folderIndex,onDiskEvent,aliasMap,+ bumpFileIndexGeneration,);if (parcelSub) {subscription = parcelSub;@@ -1088,6 +1253,7 @@ export async function startWatcher(folderIndex,onDiskEvent,aliasMap,+ bumpFileIndexGeneration,);backend = 'chokidar';}@@ -1108,24 +1274,44 @@ export async function startWatcher(return originalUnsubscribe();},getFileIndex() {+ if (cachedMarkdownView && cachedMarkdownViewGeneration === fileIndexGeneration) {+ return cachedMarkdownView;+ }+ cachedMarkdownView = markdownIndexView(fileIndex);+ cachedMarkdownViewGeneration = fileIndexGeneration;+ return cachedMarkdownView;+ },+ getAllFilesIndex() {return fileIndex;},+ getFileIndexGeneration() {+ return fileIndexGeneration;+ },getFolderIndex() {return folderIndex;},getAliasMap() {return aliasMap;},+ mutateFileIndex(event) {+ updateFileIndex(event, fileIndex);+ bumpFileIndexGeneration();+ },pruneFileIndexNowExcluded() {if (!contentFilter) return 0;let pruned = 0;for (const [docName, entry] of fileIndex) {const relPath = relative(contentDir, entry.canonicalPath);- if (contentFilter.isExcluded(relPath)) {+ const excluded =+ entry.kind === 'file'+ ? contentFilter.isPathIgnored(relPath)+ : contentFilter.isExcluded(relPath);+ if (excluded) {fileIndex.delete(docName);pruned++;}}+ if (pruned > 0) bumpFileIndexGeneration();return pruned;},pruneFolderIndexNowExcluded() {@@ -1139,8 +1325,8 @@ export async function startWatcher(}return pruned;},- rescanFromDisk() {- return seedLastKnownHashes(+ async rescanFromDisk() {+ await seedLastKnownHashes(contentDir,contentDir,contentFilter,@@ -1148,6 +1334,7 @@ export async function startWatcher(folderIndex,aliasMap,);+ bumpFileIndexGeneration();},};}diff --git a/packages/server/src/mcp/tools/search.test.ts b/packages/server/src/mcp/tools/search.test.tsindex 9bb949750..50f21bec0 100644--- a/packages/server/src/mcp/tools/search.test.ts+++ b/packages/server/src/mcp/tools/search.test.ts@@ -99,6 +99,12 @@ describe('search MCP tool — registration', () => {expect(DESCRIPTION.slice(0, 200)).toContain('grep');});+ test('description advertises all-files name coverage + the two-tier grep model (PRD-7117 D17)', () => {+ expect(DESCRIPTION).toContain('ALL non-ignored files');+ expect(DESCRIPTION.toLowerCase()).toContain('name/path');+ expect(DESCRIPTION.toLowerCase()).toContain('in parallel');+ });+test('inputSchema exposes query, intent, scopes, limit, semantic, cwd', () => {const { server, registered } = makeFakeServer();register(server, {@@ -298,6 +304,61 @@ describe('search MCP tool — happy path', () => {expect(text).toContain('12/40');});+ test("kind:'file' rows survive into structured results (PRD-7117 all-files MCP)", async () => {+ mockFetchOk({+ ok: true,+ query: 'data',+ intent: 'full_text',+ results: [+ {+ kind: 'file',+ path: 'data.csv',+ title: 'data.csv',+ score: 200,+ signals: { lexical: 200, fullText: 0, recency: 0 },+ },+ ],+ elapsedMs: 1,+ });+ const { server, registered } = makeFakeServer();+ register(server, {+ resolveCwd: async () => '/tmp/proj',+ config: DEFAULT_CONFIG,+ serverUrl: 'http://localhost:1234',+ });+ const tool = expectOneRegisteredTool(registered);+ const result = await tool.handler({ query: 'data', cwd: '/tmp/proj' });+ const structured = result.structuredContent as {+ resultCount: number;+ results: Array<{ kind: string; path: string }>;+ };+ expect(structured.resultCount).toBe(1);+ expect(structured.results[0]?.kind).toBe('file');+ expect(structured.results[0]?.path).toBe('data.csv');+ });++ test("scopes:['file'] is forwarded to /api/search (Zod accepts 'file')", async () => {+ const captured: { body?: string } = {};+ globalThis.fetch = mock(async (_url: string, init?: RequestInit) => {+ captured.body = String(init?.body);+ return new Response(JSON.stringify({ ok: true, results: [] }), {+ status: 200,+ headers: { 'content-type': 'application/json' },+ });+ }) as unknown as typeof fetch;+ const { server, registered } = makeFakeServer();+ register(server, {+ resolveCwd: async () => '/tmp/proj',+ config: DEFAULT_CONFIG,+ serverUrl: 'http://localhost:1234',+ });+ const tool = expectOneRegisteredTool(registered);+ const result = await tool.handler({ query: 'q', scopes: ['file'], cwd: '/tmp/proj' });+ expect(result.isError ?? false).toBe(false);+ const body = JSON.parse(String(captured.body)) as Record<string, unknown>;+ expect(body.scopes).toEqual(['file']);+ });+test('zero results returns "No matches" text + structured.resultCount = 0', async () => {mockFetchOk({ ok: true, query: 'nope', intent: 'full_text', results: [], elapsedMs: 0.1 });const { server, registered } = makeFakeServer();diff --git a/packages/server/src/mcp/tools/search.ts b/packages/server/src/mcp/tools/search.tsindex e20013c9a..27d720c40 100644--- a/packages/server/src/mcp/tools/search.ts+++ b/packages/server/src/mcp/tools/search.ts@@ -17,16 +17,18 @@ import {} from './shared.ts';export const DESCRIPTION = [- '[Requires: Hocuspocus server] Ranked page retrieval for a query (title boost + body BM25 + recency — the cmd-K engine). For literal search across every line, use `exec` (`grep`) instead.',+ '[Requires: Hocuspocus server] Ranked retrieval across ALL non-ignored files (markdown by title/body, other file types by name/path, plus folders) — pair with `exec` `grep` for exhaustive content search. The cmd-K engine (title boost + body BM25 + recency).',+ '',+ 'NAMES/paths are indexed for all files; BODY content for markdown only. Two-tier agent model: run this fast indexed `search` (all files by name/path + markdown content) IN PARALLEL with `exec` (`grep`) for exhaustive literal-string content search across every file — instant ranked hits plus full content coverage. Reach for `exec` grep when you need to match content inside code/config/data files.','','When semantic search is enabled for the workspace (an opt-in setting with an API key), an embeddings signal is additionally fused into `full_text` ranking, surfacing conceptually-related pages that share no keywords. This tool opts in by default; the `semantic` block in the response reports coverage. Note: with semantic enabled, the query and matching page content are sent to the configured embeddings provider (content egress). Set `semantic: false` to force pure-lexical ranking for a call.','',- 'Returns scored page (and folder, with `omnibar` intent) hits, each with a body snippet and a `signals` breakdown (lexical / fullText / recency / vector). `exec`-grep covers every occurrence and needs no server.',+ 'Returns scored `page`, `folder`, and name-only `file` hits, each with a `signals` breakdown (lexical / fullText / recency / vector); markdown `page` hits also carry a body snippet (`file` hits never do — name-only). `exec`-grep covers every content occurrence and needs no server.','','**Parameters:**','- `query` — Free-form; tokenized across title, name, path segments, and (with `full_text`) body.','- `intent` (optional) — `omnibar` searches title/path/folders only (fast); `full_text` includes body. Default `full_text`.',- '- `scopes` (optional) — Result scope: `page` | `folder` | `content`. Defaults derive from `intent`.',+ '- `scopes` (optional) — Result scope: `page` | `folder` | `file` | `content`. Defaults derive from `intent`.','- `limit` (optional) — Max rows; default 20, max 100.','- `semantic` (optional) — Set `false` to force pure-lexical ranking even when semantic search is enabled. Omit to use semantic when available.','',@@ -39,7 +41,7 @@ interface SearchDeps {serverUrl: ServerUrlOrResolver;}-const SCOPE_VALUES = ['page', 'folder', 'content'] as const;+const SCOPE_VALUES = ['page', 'folder', 'content', 'file'] as const;const INTENT_VALUES = ['omnibar', 'full_text'] as const;const InputSchema = {@@ -54,7 +56,7 @@ const InputSchema = {.array(z.enum(SCOPE_VALUES)).optional().describe(- "Override the default scope set. Members: 'page', 'folder', 'content'. Defaults derive from intent.",+ "Override the default scope set. Members: 'page', 'folder', 'file', 'content'. Defaults derive from intent.",),limit: z.number().int().min(1).max(100).optional().describe('Max rows; default 20, max 100.'),semantic: z@@ -67,7 +69,7 @@ const InputSchema = {} as const;const SearchResultRowSchema = z.object({- kind: z.enum(['page', 'folder']),+ kind: z.enum(['page', 'folder', 'file']),path: z.string(),docName: z.string(),title: z.string().nullable(),@@ -99,7 +101,7 @@ const OutputSchema = outputSchemaWithText({semantic: SearchSemanticStatusSchema.optional(),});-type SearchKind = 'page' | 'folder';+type SearchKind = 'page' | 'folder' | 'file';interface SearchApiRow {kind?: SearchKind;@@ -156,7 +158,7 @@ interface SearchStructuredResult {}function isSearchKind(value: unknown): value is SearchKind {- return value === 'page' || value === 'folder';+ return value === 'page' || value === 'folder' || value === 'file';}function normalizeSignals(signals: SearchApiRow['signals']): {diff --git a/packages/server/src/server-factory.ts b/packages/server/src/server-factory.tsindex 3a7a61395..6a253261b 100644--- a/packages/server/src/server-factory.ts+++ b/packages/server/src/server-factory.ts@@ -682,6 +682,9 @@ export function createServer(options: ServerOptions): ServerInstance {contentFilter,serverInstanceId,getFileIndex: () => (watcher ? watcher.getFileIndex() : new Map()),+ getAllFilesIndex: () => (watcher ? watcher.getAllFilesIndex() : new Map()),+ getFileIndexGeneration: () => watcher?.getFileIndexGeneration() ?? 0,+ mutateFileIndex: (event) => watcher?.mutateFileIndex(event),getFolderIndex: () => (watcher ? watcher.getFolderIndex() : new Map()),getAliasMap: () => (watcher ? watcher.getAliasMap() : new Map()),rescanFiles: () => watcher?.rescanFromDisk(),@@ -829,6 +832,9 @@ export function createServer(options: ServerOptions): ServerInstance {case 'asset-delete':case 'folder-create':case 'folder-delete':+ case 'file-create':+ case 'file-update':+ case 'file-delete':return event.relativePath;case 'create':case 'update':@@ -1127,6 +1133,12 @@ export function createServer(options: ServerOptions): ServerInstance {signalChannel('files');break;}+ case 'file-create':+ case 'file-update':+ case 'file-delete': {+ signalChannel('files');+ break;+ }default:assertNeverDiskEvent(event);}