Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Honor .okignore in the all-files sidebar (#2862)

Dimitri POSTOLOV7c17ceb41566
diff --git a/.changeset/sidebar-okignore-rules.md b/.changeset/sidebar-okignore-rules.md
new file mode 100644
index 000000000..cb6bed99c
--- /dev/null
+++ b/.changeset/sidebar-okignore-rules.md
@@ -0,0 +1,5 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+Files and folders matched by `.okignore` no longer reappear in the all-files sidebar.
diff --git a/packages/app/tests/integration/sidebar-show-all-files.test.ts b/packages/app/tests/integration/sidebar-show-all-files.test.ts
index 4b62513e2..55502c6b8 100644
--- a/packages/app/tests/integration/sidebar-show-all-files.test.ts
+++ b/packages/app/tests/integration/sidebar-show-all-files.test.ts
@@ -3,7 +3,7 @@
*
* Verifies the runtime-bypass path through ContentFilter:
* - `.gitignored` files surface
- * - `.okignored` files surface
+ * - `.okignored` files stay hidden (`.okignore` remains authoritative)
* - content-bearing `BUILTIN_SKIP_DIRS` (dist/, build/, coverage/) surface
* - the always-skip floor (.git/, node_modules/, .ok/) stays PRUNED even
* under bypass — these never hold user markdown and walking them on a
@@ -106,7 +106,7 @@ describe('/api/documents?showAll=true', () => {
expect(docNames).not.toContain('node_modules/pkg/README');
});
- test('?showAll=true surfaces .gitignored / .okignored / content-bearing skip-dir markdown but prunes the always-skip floor', async () => {
+ test('?showAll=true surfaces .gitignored / content-bearing skip-dir markdown, honors .okignore, and prunes the always-skip floor', async () => {
const res = await fetch(`http://127.0.0.1:${server.port}/api/documents?showAll=true`);
expect(res.ok).toBe(true);
const body = DocumentListSuccessSchema.parse(await res.json());
@@ -121,8 +121,8 @@ describe('/api/documents?showAll=true', () => {
expect(docNames).toContain('secrets/api-key');
expect(docNames).toContain('build/compiled');
- // .okignored markdown surfaces.
- expect(docNames).toContain('drafts/wip');
+ // The user's explicit .okignore hide list remains authoritative.
+ expect(docNames).not.toContain('drafts/wip');
// `build/` is .gitignored AND in BUILTIN_SKIP_DIRS yet still surfaces
// (asserted above) — proving the floor is a strict subset, not all of
@@ -179,12 +179,12 @@ describe('/api/documents?showAll=true', () => {
const folderPaths = body.documents.filter((e) => e.kind === 'folder').map((e) => e.path);
- // Content-bearing dirs — including .gitignored (secrets/, build/) and
- // .okignored (drafts/) ones — still surface under Show All Files.
+ // Content-bearing dirs — including .gitignored (secrets/, build/) ones —
+ // still surface under Show All Files. Explicitly .okignored dirs do not.
expect(folderPaths).toContain('docs');
expect(folderPaths).toContain('secrets');
expect(folderPaths).toContain('build');
- expect(folderPaths).toContain('drafts');
+ expect(folderPaths).not.toContain('drafts');
expect(folderPaths).toContain('src');
// Always-skip floor: pruned even under bypass. Descending into these on a
diff --git a/packages/server/src/api-extension.ts b/packages/server/src/api-extension.ts
index b2186376c..2d0e3cfec 100644
--- a/packages/server/src/api-extension.ts
+++ b/packages/server/src/api-extension.ts
@@ -1503,8 +1503,9 @@ export interface WalkShowAllOpts extends StreamShowAllOpts {
* cap covers the shallow levels.
*
* Uses `ContentFilter.{isExcluded,isDirExcluded}` with `bypassFilters:true` so
- * `.gitignored` / `.okignored` / content-bearing `BUILTIN_SKIP_DIRS` (`dist/`,
- * `build/`, `coverage/`, …) surface. The `ALWAYS_SKIP_DIRS` floor still prunes
+ * `.gitignored` and content-bearing `BUILTIN_SKIP_DIRS` (`dist/`, `build/`,
+ * `coverage/`, …) surface. `.okignore` remains authoritative because it is the
+ * user's explicit hide list. The `ALWAYS_SKIP_DIRS` floor still prunes
* `.git/` / `node_modules/` / `.ok/` even under bypass (those trees are
* unbounded and never hold user markdown — pruning them is the Show All Files
* OOM guard); `showOk` re-admits `.ok` minus `worktrees`/`local`, the two
@@ -1532,7 +1533,7 @@ export async function* streamShowAllEntries(
// One opts object for every filter consultation: the dir gates, the
// `hasChildren` probe, and the file backstop must agree on admission, or a
// revealed folder probes childless / yields rows its own dir gate pruned.
- const filterOpts = { bypassFilters: true, showOk } as const;
+ const filterOpts = { bypassFilters: true, respectOkignore: true, showOk } as const;
showAllWalkInvocations += 1;
// Running count of yielded entries — the streaming analogue of the buffered
// `documents.length` cap probe. Shared across the whole traversal so the
@@ -1589,7 +1590,7 @@ export async function* streamShowAllEntries(
const relPath = relDir ? `${relDir}/${entry.name}` : entry.name;
const docName = stripDocExtension(relPath);
if (!collidingDocNames.has(docName)) continue;
- if (contentFilter.isExcluded(relPath, { bypassFilters: true })) continue;
+ if (contentFilter.isExcluded(relPath, filterOpts)) continue;
if (!passesDirFilter(relPath)) continue;
if (entry.isSymbolicLink()) {
@@ -1735,8 +1736,9 @@ export async function* streamShowAllEntries(
if (entry.isDirectory()) {
// bypassFilters:true admits gitignored + content-bearing skip-dirs
- // (dist/, build/), but the ALWAYS_SKIP_DIRS floor still prunes
- // .git/, node_modules/, .ok/ here — the Show All Files OOM guard.
+ // (dist/, build/), while respectOkignore:true keeps .okignore
+ // authoritative. The ALWAYS_SKIP_DIRS floor still prunes .git/,
+ // node_modules/, .ok/ here — the Show All Files OOM guard.
// showOk re-admits .ok minus worktrees/local for the tree reveal.
if (contentFilter.isDirExcluded(relPath, filterOpts)) continue;
@@ -6573,12 +6575,11 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {
// Show All Files mode — fresh on-demand disk walk via
// `ContentFilter.{isExcluded,isDirExcluded}` with `bypassFilters:true`.
- // Returns .gitignored / .okignored / content-bearing `BUILTIN_SKIP_DIRS`
- // files (`dist/`, `build/`, …), EXCEPT the `ALWAYS_SKIP_DIRS` floor
- // (`.git/` / `node_modules/` / `.ok/`, pruned even under bypass — the
- // OOM guard) and synthetic system + config doc names (unbypassable
- // STOP-rule gate inside ContentFilter). Per-request only — fileIndex
- // stays populated with the non-bypass set, so the next
+ // Returns .gitignored / content-bearing `BUILTIN_SKIP_DIRS` files
+ // (`dist/`, `build/`, …), while `.okignore` remains authoritative.
+ // The `ALWAYS_SKIP_DIRS` floor (`.git/` / `node_modules/` / `.ok/`) and
+ // synthetic system + config doc names remain unbypassable. Per-request
+ // only — fileIndex stays populated with the non-bypass set, so the next
// non-`?showAll=true` call serves today's filtered view unchanged.
if (showAll && contentFilter) {
// Single-flight: coalesce concurrent identical walks into one. Key by
diff --git a/packages/server/src/content-filter.test.ts b/packages/server/src/content-filter.test.ts
index c7e7916a8..f2ea55481 100644
--- a/packages/server/src/content-filter.test.ts
+++ b/packages/server/src/content-filter.test.ts
@@ -598,13 +598,13 @@ describe('ContentFilter', () => {
});
describe('always-skip floor survives bypassFilters (Show All Files OOM guard)', () => {
- // `?showAll=true` passes `{ bypassFilters: true }` so the sidebar can
- // surface .gitignored / .okignored content. The floor is the hard limit on
- // that bypass: `.git/`, `node_modules/`, `.ok/` (+ legacy state dirs) are
- // NEVER traversed or admitted, because walking them on a repo-root content
- // dir (a multi-GB `.git` object store, thousands of nested `node_modules`)
- // makes the recursive `?showAll=true` walk unbounded and exhausts the heap.
- const BYPASS = { bypassFilters: true } as const;
+ // `?showAll=true` bypasses Git/build filters while preserving `.okignore`.
+ // The floor remains the hard limit on that bypass: `.git/`, `node_modules/`,
+ // `.ok/` (+ legacy state dirs) are NEVER traversed or admitted, because
+ // walking them on a repo-root content dir (a multi-GB `.git` object store,
+ // thousands of nested `node_modules`) makes the recursive walk unbounded
+ // and exhausts the heap.
+ const BYPASS = { bypassFilters: true, respectOkignore: true } as const;
function assertFloor(filter: ContentFilter) {
// Directories on the floor are pruned even under bypass — this prune is
@@ -1453,6 +1453,12 @@ describe('ContentFilter', () => {
// State must reflect the OLD .okignore (drafts/), not the new one (archive/).
expect(filter.isExcluded('drafts/x.md')).toBe(true);
expect(filter.isExcluded('archive/x.md')).toBe(false);
+ expect(
+ filter.isExcluded('drafts/x.md', {
+ bypassFilters: true,
+ respectOkignore: true,
+ }),
+ ).toBe(true);
// watcherGlobs reflects the OLD patterns.
expect(filter.getWatcherIgnoreGlobs()).toContain('drafts/');
expect(filter.getWatcherIgnoreGlobs()).not.toContain('archive/');
@@ -1653,6 +1659,21 @@ describe('ContentFilter', () => {
expect(filter.isExcluded('drafts/wip.md', { bypassFilters: true })).toBe(false);
});
+ test('respectOkignore keeps .okignore patterns active while admitting .gitignored files', () => {
+ writeFileSync(join(projectDir, '.gitignore'), 'dist/\n');
+ writeFileSync(join(projectDir, '.okignore'), 'drafts/\n');
+ const filter = createContentFilter({ projectDir, contentDir: projectDir });
+
+ expect(filter.isExcluded('dist/out.md', { bypassFilters: true })).toBe(false);
+ expect(filter.isExcluded('drafts/wip.md', { bypassFilters: true })).toBe(false);
+
+ const showAllOpts = { bypassFilters: true, respectOkignore: true } as const;
+ expect(filter.isExcluded('dist/out.md', showAllOpts)).toBe(false);
+ expect(filter.isExcluded('drafts/wip.md', showAllOpts)).toBe(true);
+ expect(filter.isDirExcluded('dist', showAllOpts)).toBe(false);
+ expect(filter.isDirExcluded('drafts', showAllOpts)).toBe(true);
+ });
+
test('admits content-bearing BUILTIN_SKIP_DIRS (dist) in bypass mode', () => {
const filter = createContentFilter({ projectDir, contentDir: projectDir });
diff --git a/packages/server/src/content-filter.ts b/packages/server/src/content-filter.ts
index 9d1804c7c..0aa4f1a2e 100644
--- a/packages/server/src/content-filter.ts
+++ b/packages/server/src/content-filter.ts
@@ -233,10 +233,10 @@ function globBlocksSkillContent(pattern: string): boolean {
* useful in no mode. The file-level analogue of `ALWAYS_SKIP_DIRS`: pruned even
* under `bypassFilters: true`. The seeded `.gitignore` (`init-project.ts`)
* already keeps these out of the normal index-backed sidebar, but the Show All
- * Files walk runs with `bypassFilters: true` — it skips `.gitignore` /
- * `.okignore` precisely so gitignored content (`dist/`, `build/`, …) surfaces —
- * which would otherwise re-surface `.DS_Store` as a sidebar `asset` row. macOS
- * is the only supported platform, so this is macOS Finder metadata.
+ * Files walk bypasses `.gitignore` and built-in content rules so gitignored
+ * content (`dist/`, `build/`, …) surfaces. Without this floor it would also
+ * re-surface `.DS_Store` as a sidebar `asset` row. macOS is the only supported
+ * platform, so this is macOS Finder metadata.
*/
const BUILTIN_SKIP_FILES = new Set<string>(['.DS_Store', '.localized']);
@@ -589,11 +589,17 @@ export type RebuildResult =
* true` skips user-configurable rules (`.gitignore` / `.okignore` /
* `BUILTIN_SKIP_DIRS`) but PRESERVES the synthetic system + config doc gate
* (STOP rule — even in bypass mode, `__system__` / `__config__` /
- * `__user__` / `__local__` doc names MUST stay hidden). Per-request use
- * only — backs the `?showAll=true` flag on `GET /api/documents`.
+ * `__user__` / `__local__` doc names MUST stay hidden).
*/
interface ContentFilterReadOpts {
bypassFilters?: boolean;
+ /**
+ * Keep `.okignore` rules active while bypassing `.gitignore` and
+ * `BUILTIN_SKIP_DIRS`. Used by the all-files sidebar: files normally hidden
+ * by Git/build defaults surface, while the user's explicit OK hide list
+ * remains authoritative.
+ */
+ respectOkignore?: boolean;
/**
* Admit `.ok`-segment paths through the always-skip floor — `isExcluded` /
* `isDirExcluded` only; `isPathIgnored` (the asset-serve gate) keeps the
@@ -682,6 +688,7 @@ export function createContentFilter(opts: ContentFilterOptions): ContentFilter {
// Captured by the closure-bound API below. Replaced atomically on
// `rebuildIgnorePatterns()` so live references on consumers stay valid.
let ig: Ignore;
+ let okignoreIg: Ignore;
let rootIgnorePatterns: string[];
let watcherIgnoreGlobs: string[];
let lastPatternCount = 0;
@@ -702,6 +709,7 @@ export function createContentFilter(opts: ContentFilterOptions): ContentFilter {
bytes: number;
} {
const newIg = ignore();
+ const newOkignoreIg = ignore();
// Always exclude .git directory itself
newIg.add('.git');
@@ -720,6 +728,7 @@ export function createContentFilter(opts: ContentFilterOptions): ContentFilter {
const patterns = parseIgnorePatterns(content);
newRootPatterns.push(...patterns);
newIg.add(patterns);
+ if (name === '.okignore') newOkignoreIg.add(patterns);
} catch (err) {
log.warn({ path, err }, `Failed to read ${name} at ${path}`);
}
@@ -737,6 +746,7 @@ export function createContentFilter(opts: ContentFilterOptions): ContentFilter {
const patterns = parseIgnorePatterns(content);
const prefixed = patterns.map((p) => prefixPattern(p, contentRelPrefix));
newIg.add(prefixed);
+ if (name === '.okignore') newOkignoreIg.add(prefixed);
} catch (err) {
log.warn({ path, err }, `Failed to read ${name} at ${path}`);
}
@@ -745,7 +755,13 @@ export function createContentFilter(opts: ContentFilterOptions): ContentFilter {
// Pass 2b: Recursive nested files
const bytesAcc = { value: bytes };
- nestedFileCount += loadNestedIgnoreFiles(contentDir, projectDir, newIg, bytesAcc);
+ nestedFileCount += loadNestedIgnoreFiles(
+ contentDir,
+ projectDir,
+ newIg,
+ newOkignoreIg,
+ bytesAcc,
+ );
bytes = bytesAcc.value;
// Pass 3: per-clone `.git/info/exclude` + global excludesfile (XDG-default
@@ -768,6 +784,7 @@ export function createContentFilter(opts: ContentFilterOptions): ContentFilter {
// Atomic swap.
ig = newIg;
+ okignoreIg = newOkignoreIg;
rootIgnorePatterns = newRootPatterns;
watcherIgnoreGlobs = newWatcherGlobs;
lastPatternCount = newRootPatterns.length;
@@ -794,6 +811,12 @@ export function createContentFilter(opts: ContentFilterOptions): ContentFilter {
return ig.ignores(projectRelPath);
}
+ function isOkIgnored(relativePath: string): boolean {
+ if (contentOutsideProject) return false;
+ const projectRelPath = contentRelPrefix ? `${contentRelPrefix}/${relativePath}` : relativePath;
+ return okignoreIg.ignores(projectRelPath);
+ }
+
// Single-file mode skips the full-tree refcount walk: it walks the ENTIRE
// contentDir synchronously (a stall + privacy leak on a large parent like
// `~/` or `~/Downloads`), and its only job — sibling-asset admission via
@@ -901,11 +924,12 @@ export function createContentFilter(opts: ContentFilterOptions): ContentFilter {
// inert anyway — this short-circuit is the sole admission gate.
if (singleDocRelPath !== undefined) return relativePath !== singleDocRelPath;
- // (B) Bypass mode admits everything else (.gitignore + .okignore +
- // remaining BUILTIN_SKIP_DIRS skipped; extension + sibling-asset gates
- // also skipped so non-md/non-asset files like `package.json` / `LICENSE`
- // surface in the sidebar's Show All Files mode).
- if (opts?.bypassFilters) return false;
+ // (B) Bypass mode admits everything else. The all-files sidebar keeps
+ // `.okignore` active while bypassing Git/build defaults; other bypass
+ // callers retain the original full-bypass behavior.
+ if (opts?.bypassFilters) {
+ return opts.respectOkignore === true && isOkIgnored(relativePath);
+ }
// (1) Configurable path rules — BUILTIN_SKIP_DIRS + ignore patterns.
if (isRejectedByConfigurableRules(relativePath)) return true;
@@ -962,12 +986,15 @@ export function createContentFilter(opts: ContentFilterOptions): ContentFilter {
if (singleDocRelPath !== undefined) {
return !isSingleDocAncestorDir(relativePath, singleDocRelPath);
}
- // Bypass then admits every OTHER directory (Show All Files still surfaces
- // .gitignored content like `dist/` / `build/`). System-reserved doc names
- // never appear as real disk directories, so there's no parallel STOP-rule
- // gate here — the file-level `isReservedDocName` catches any leak at the
- // file (Hocuspocus document) admission boundary.
- if (opts?.bypassFilters) return false;
+ // Bypass then admits every OTHER directory. The all-files sidebar keeps
+ // `.okignore` active while still surfacing `.gitignored` content like
+ // `dist/` / `build/`.
+ if (opts?.bypassFilters) {
+ return (
+ opts.respectOkignore === true &&
+ (isOkIgnored(relativePath) || isOkIgnored(`${relativePath}/`))
+ );
+ }
// Fast-path: built-in skips are always excluded regardless of ignore-file config.
// Check ALL path segments, not just the top — handles nested `.ok/` (per-folder
// metadata directories), nested `node_modules/`, nested `dist/`, etc.
@@ -1045,6 +1072,7 @@ export function createContentFilter(opts: ContentFilterOptions): ContentFilter {
// Snapshot for rollback. dirCount is too large to snapshot — we re-walk
// it from the rolled-back ig instance if rebuild fails partway.
const prevIg = ig;
+ const prevOkignoreIg = okignoreIg;
const prevRootPatterns = rootIgnorePatterns;
const prevWatcherGlobs = watcherIgnoreGlobs;
const prevPatternCount = lastPatternCount;
@@ -1099,6 +1127,7 @@ export function createContentFilter(opts: ContentFilterOptions): ContentFilter {
// closure are restored so subsequent isExcluded / isDirExcluded
// calls behave as if the rebuild never happened.
ig = prevIg;
+ okignoreIg = prevOkignoreIg;
rootIgnorePatterns = prevRootPatterns;
watcherIgnoreGlobs = prevWatcherGlobs;
lastPatternCount = prevPatternCount;
@@ -1220,6 +1249,7 @@ function loadNestedIgnoreFiles(
dir: string,
projectDir: string,
ig: Ignore,
+ okignoreIg: Ignore,
bytesAcc: { value: number },
): number {
let entries: import('node:fs').Dirent[];
@@ -1256,6 +1286,7 @@ function loadNestedIgnoreFiles(
const patterns = parseIgnorePatterns(content);
const prefixed = patterns.map((p) => prefixPattern(p, relToProject));
ig.add(prefixed);
+ if (name === '.okignore') okignoreIg.add(prefixed);
count++;
} catch (err) {
log.warn({ path: filePath, err }, `Failed to read nested ${name} at ${filePath}`);
@@ -1263,7 +1294,7 @@ function loadNestedIgnoreFiles(
}
// Recurse into subdirectory
- count += loadNestedIgnoreFiles(dirPath, projectDir, ig, bytesAcc);
+ count += loadNestedIgnoreFiles(dirPath, projectDir, ig, okignoreIg, bytesAcc);
}
return count;
@@ -1284,6 +1315,7 @@ async function initContentDirStateAsync(
relPath: string,
projectDir: string,
ig: Ignore,
+ okignoreIg: Ignore,
contentRelPrefix: string,
contentOutsideProject: boolean,
dirCount: Map<string, number>,
@@ -1315,7 +1347,9 @@ async function initContentDirStateAsync(
if (!existsSync(filePath)) continue;
try {
const patterns = parseIgnorePatterns(await readFileAsync(filePath, 'utf-8'));
- ig.add(patterns.map((p) => prefixPattern(p, relToProject)));
+ const prefixed = patterns.map((p) => prefixPattern(p, relToProject));
+ ig.add(prefixed);
+ if (name === '.okignore') okignoreIg.add(prefixed);
} catch (err) {
log.warn({ path: filePath, err }, `Failed to read nested ${name} at ${filePath}`);
}
@@ -1328,6 +1362,7 @@ async function initContentDirStateAsync(
childRel,
projectDir,
ig,
+ okignoreIg,
contentRelPrefix,
contentOutsideProject,
dirCount,
@@ -1359,6 +1394,7 @@ export async function createContentFilterAsync(opts: ContentFilterOptions): Prom
// Mutable bindings — swapped atomically by rebuildIgnorePatterns().
let ig = ignore();
+ let okignoreIg = ignore();
let watcherIgnoreGlobs: string[] = [];
const dirCount = new Map<string, number>();
@@ -1377,6 +1413,12 @@ export async function createContentFilterAsync(opts: ContentFilterOptions): Prom
return ig.ignores(projectRelPath);
}
+ function isOkIgnored(relativePath: string): boolean {
+ if (contentOutsideProject) return false;
+ const projectRelPath = contentRelPrefix ? `${contentRelPrefix}/${relativePath}` : relativePath;
+ return okignoreIg.ignores(projectRelPath);
+ }
+
// Mirror of the sync variant's STOP-rule + configurable-rules split.
// Keeping the two predicates separated here lets `isExcluded` /
// `isPathIgnored` short-circuit safely in bypass mode without ever
@@ -1398,6 +1440,7 @@ export async function createContentFilterAsync(opts: ContentFilterOptions): Prom
async function buildAndSwapPatternState(): Promise<void> {
const newIg = ignore();
+ const newOkignoreIg = ignore();
newIg.add('.git');
const newRootPatterns: string[] = [];
@@ -1409,6 +1452,7 @@ export async function createContentFilterAsync(opts: ContentFilterOptions): Prom
const patterns = parseIgnorePatterns(await readFileAsync(path, 'utf-8'));
newRootPatterns.push(...patterns);
newIg.add(patterns);
+ if (name === '.okignore') newOkignoreIg.add(patterns);
} catch (err) {
log.warn({ path, err }, `Failed to read ${name} at ${path}`);
}
@@ -1420,7 +1464,9 @@ export async function createContentFilterAsync(opts: ContentFilterOptions): Prom
if (!existsSync(path)) continue;
try {
const patterns = parseIgnorePatterns(await readFileAsync(path, 'utf-8'));
- newIg.add(patterns.map((p) => prefixPattern(p, contentRelPrefix)));
+ const prefixed = patterns.map((p) => prefixPattern(p, contentRelPrefix));
+ newIg.add(prefixed);
+ if (name === '.okignore') newOkignoreIg.add(prefixed);
} catch (err) {
log.warn({ path, err }, `Failed to read ${name} at ${path}`);
}
@@ -1450,6 +1496,7 @@ export async function createContentFilterAsync(opts: ContentFilterOptions): Prom
'',
projectDir,
newIg,
+ newOkignoreIg,
contentRelPrefix,
contentOutsideProject,
newDirCount,
@@ -1458,6 +1505,7 @@ export async function createContentFilterAsync(opts: ContentFilterOptions): Prom
// Atomic swap.
ig = newIg;
+ okignoreIg = newOkignoreIg;
watcherIgnoreGlobs = newRootPatterns.filter(
(p) => p.length > 0 && !p.startsWith('!') && !p.startsWith('#') && !globBlocksSkillContent(p),
);
@@ -1495,7 +1543,9 @@ export async function createContentFilterAsync(opts: ContentFilterOptions): Prom
if (isAlwaysSkipFile(relativePath)) return true;
// Single-file scope — admit ONLY the one target doc (see sync variant).
if (singleDocRelPath !== undefined) return relativePath !== singleDocRelPath;
- if (opts?.bypassFilters) return false;
+ if (opts?.bypassFilters) {
+ return opts.respectOkignore === true && isOkIgnored(relativePath);
+ }
if (isRejectedByConfigurableRules(relativePath)) return true;
if (isSupportedDocFile(relativePath)) return false;
const ext = extname(relativePath).slice(1).toLowerCase();
@@ -1525,7 +1575,12 @@ export async function createContentFilterAsync(opts: ContentFilterOptions): Prom
if (singleDocRelPath !== undefined) {
return !isSingleDocAncestorDir(relativePath, singleDocRelPath);
}
- if (opts?.bypassFilters) return false;
+ if (opts?.bypassFilters) {
+ return (
+ opts.respectOkignore === true &&
+ (isOkIgnored(relativePath) || isOkIgnored(`${relativePath}/`))
+ );
+ }
for (const segment of relativePath.split('/')) {
if (BUILTIN_SKIP_DIRS.has(segment)) return true;
}
@@ -1590,6 +1645,7 @@ export async function createContentFilterAsync(opts: ContentFilterOptions): Prom
async rebuildIgnorePatterns(): Promise<RebuildResult> {
const prevIg = ig;
+ const prevOkignoreIg = okignoreIg;
const prevWatcherGlobs = watcherIgnoreGlobs;
const prevDirCount = new Map(dirCount);
const startedAt = Date.now();
@@ -1625,6 +1681,7 @@ export async function createContentFilterAsync(opts: ContentFilterOptions): Prom
};
} catch (err) {
ig = prevIg;
+ okignoreIg = prevOkignoreIg;
watcherIgnoreGlobs = prevWatcherGlobs;
dirCount.clear();
for (const [k, v] of prevDirCount) dirCount.set(k, v);
diff --git a/packages/server/src/showall-stream.test.ts b/packages/server/src/showall-stream.test.ts
index 2f9477e15..5050fb590 100644
--- a/packages/server/src/showall-stream.test.ts
+++ b/packages/server/src/showall-stream.test.ts
@@ -26,7 +26,7 @@ import {
streamShowAllEntries,
walkContentDirForShowAll,
} from './api-extension.ts';
-import { createContentFilter } from './content-filter.ts';
+import { createContentFilter, createContentFilterAsync } from './content-filter.ts';
import { getLogger } from './logger.ts';
function makeFlatFixture(fileCount: number): string {
@@ -179,6 +179,96 @@ function entryPath(e: DocumentListEntry): string {
return e.kind === 'document' ? e.docName : e.path;
}
+describe('streamShowAllEntries — .okignore', () => {
+ test('root patterns hide matching folders from the all-files sidebar', async () => {
+ const dir = realpathSync(mkdtempSync(join(tmpdir(), 'ok-showall-okignore-')));
+ mkdirSync(join(dir, 'src', 'adapters'), { recursive: true });
+ writeFileSync(join(dir, 'src', 'main.rs'), 'fn main() {}\n');
+ writeFileSync(join(dir, 'src', 'adapters', 'mod.rs'), 'pub mod adapter;\n');
+ mkdirSync(join(dir, 'example'));
+ writeFileSync(join(dir, 'example', 'demo.rs'), 'fn demo() {}\n');
+ mkdirSync(join(dir, 'target'));
+ writeFileSync(join(dir, 'target', 'debug.bin'), 'build output\n');
+ mkdirSync(join(dir, 'generated'));
+ writeFileSync(join(dir, 'generated', 'output.rs'), 'pub fn generated() {}\n');
+ writeFileSync(join(dir, 'Cargo.toml'), '[package]\nname = "demo"\n');
+ writeFileSync(join(dir, '.gitignore'), '/generated/\n');
+
+ const contentFilter = createContentFilter({ projectDir: dir, contentDir: dir });
+ writeFileSync(join(dir, '.okignore'), '/src/\n/example/\n');
+ expect((await contentFilter.rebuildIgnorePatterns()).ok).toBe(true);
+
+ const { entries } = await drain(
+ streamShowAllEntries({
+ contentDir: dir,
+ contentFilter,
+ dirFilter: null,
+ maxEntries: 50_000,
+ maxDepth: 1,
+ }),
+ );
+ const paths = entries.map(entryPath);
+
+ expect(paths).not.toContain('src');
+ expect(paths).not.toContain('example');
+ expect(paths).toContain('target');
+ expect(paths).toContain('generated');
+ expect(paths).toContain('Cargo.toml');
+ });
+
+ test('async content filters apply the same all-files hide rules', async () => {
+ const dir = realpathSync(mkdtempSync(join(tmpdir(), 'ok-showall-okignore-async-')));
+ mkdirSync(join(dir, 'src'));
+ writeFileSync(join(dir, 'src', 'main.rs'), 'fn main() {}\n');
+ mkdirSync(join(dir, 'target'));
+ writeFileSync(join(dir, 'target', 'debug.bin'), 'build output\n');
+ writeFileSync(join(dir, '.okignore'), '/src/\n');
+
+ const contentFilter = await createContentFilterAsync({
+ projectDir: dir,
+ contentDir: dir,
+ });
+ const { entries } = await drain(
+ streamShowAllEntries({
+ contentDir: dir,
+ contentFilter,
+ dirFilter: null,
+ maxEntries: 50_000,
+ maxDepth: 1,
+ }),
+ );
+ const paths = entries.map(entryPath);
+
+ expect(paths).not.toContain('src');
+ expect(paths).toContain('target');
+ });
+
+ test('nested .okignore patterns hide matching folders from the all-files sidebar', async () => {
+ const dir = realpathSync(mkdtempSync(join(tmpdir(), 'ok-showall-okignore-nested-')));
+ mkdirSync(join(dir, 'docs', 'drafts'), { recursive: true });
+ writeFileSync(join(dir, 'docs', 'drafts', 'wip.md'), '# Draft\n');
+ writeFileSync(join(dir, 'docs', 'guide.md'), '# Guide\n');
+ writeFileSync(join(dir, 'docs', '.okignore'), 'drafts/\n');
+
+ const contentFilter = createContentFilter({ projectDir: dir, contentDir: dir });
+ const { entries } = await drain(
+ streamShowAllEntries({
+ contentDir: dir,
+ contentFilter,
+ dirFilter: null,
+ maxEntries: 50_000,
+ maxDepth: 2,
+ }),
+ );
+ const paths = entries.map(entryPath);
+
+ expect(paths).toContain('docs');
+ expect(paths).toContain('docs/guide');
+ expect(paths).not.toContain('docs/drafts');
+ expect(paths).not.toContain('docs/drafts/wip');
+ });
+});
+
describe('streamShowAllEntries — level-order emission (PRD-6858)', () => {
// Root with several subtrees, each individually larger than the cap. Under
// a depth-first walk the cap was spent inside whichever subtree readdir