Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
fix(open-knowledge): honor nested gitignore depth in content filter (#1918)
miles-kt-inkeep7f91085ca2b2
diff --git a/.changeset/fix-nested-gitignore-depth-prefix.md b/.changeset/fix-nested-gitignore-depth-prefix.mdnew file mode 100644index 000000000..a6f4673b1--- /dev/null+++ b/.changeset/fix-nested-gitignore-depth-prefix.md@@ -0,0 +1,9 @@+---+"@inkeep/open-knowledge-server": patch+---++fix(open-knowledge): honor nested .gitignore/.okignore depth when filtering content for sync++Patterns from a nested ignore file (for example `.blob-storage/` declared in `public/agents/.gitignore`) are flattened into the project-root ignore matcher by prefixing each with the file's directory. The prefix used to inject an embedded slash unconditionally, which the `ignore` library reads as root-anchored — silently collapsing a "match at any depth" basename rule down to "this exact level only." A `.blob-storage/` rule then matched `<dir>/.blob-storage` but missed `<dir>/agents-api/.blob-storage` one level deeper, so the sync walker gathered a git-ignored path and handed it to `git add`, which rejected it with the `addIgnoredFile` advice surfaced in the sync panel.++Non-anchored nested patterns now keep matching at any depth below their directory, while anchored patterns (leading or embedded slash) stay scoped to their own level. This restores parity between the content walker and `git add` (precedent #55) so gitignored paths are no longer offered for staging.diff --git a/packages/server/src/content-filter.test.ts b/packages/server/src/content-filter.test.tsindex 8cd5e99cd..313e0f3fe 100644--- a/packages/server/src/content-filter.test.ts+++ b/packages/server/src/content-filter.test.ts@@ -129,6 +129,50 @@ describe('ContentFilter', () => {});});+ describe('nested ignore depth semantics', () => {+ test('non-anchored nested pattern matches at any depth below its directory', () => {+ mkdirSync(join(projectDir, 'agents', 'agents-api', '.blob-storage'), { recursive: true });+ writeFileSync(join(projectDir, 'agents', '.gitignore'), '.blob-storage/\n');++ const filter = createContentFilter({ projectDir, contentDir: projectDir });++ expect(filter.isExcluded('agents/agents-api/.blob-storage/doc.md')).toBe(true);+ expect(filter.isDirExcluded('agents/agents-api/.blob-storage')).toBe(true);+ expect(filter.isDirExcluded('agents/.blob-storage')).toBe(true);+ expect(filter.isDirExcluded('other/.blob-storage')).toBe(false);+ });++ test('async factory: non-anchored nested pattern matches at any depth', async () => {+ mkdirSync(join(projectDir, 'agents', 'agents-api', '.blob-storage'), { recursive: true });+ writeFileSync(join(projectDir, 'agents', '.gitignore'), '.blob-storage/\n');++ const filter = await createContentFilterAsync({ projectDir, contentDir: projectDir });++ expect(filter.isExcluded('agents/agents-api/.blob-storage/doc.md')).toBe(true);+ expect(filter.isDirExcluded('agents/agents-api/.blob-storage')).toBe(true);+ });++ test('anchored nested pattern stays scoped to its own level (no over-match)', () => {+ mkdirSync(join(projectDir, 'pkg', 'src', 'generated'), { recursive: true });+ writeFileSync(join(projectDir, 'pkg', '.gitignore'), 'src/generated/\n');++ const filter = createContentFilter({ projectDir, contentDir: projectDir });++ expect(filter.isExcluded('pkg/src/generated/api.md')).toBe(true);+ expect(filter.isExcluded('pkg/nested/src/generated/api.md')).toBe(false);+ });++ test('non-anchored nested negation un-ignores at any depth', () => {+ mkdirSync(join(projectDir, 'logs', 'sub'), { recursive: true });+ writeFileSync(join(projectDir, 'logs', '.gitignore'), '*.md\n!keep.md\n');++ const filter = createContentFilter({ projectDir, contentDir: projectDir });++ expect(filter.isExcluded('logs/debug.md')).toBe(true);+ expect(filter.isExcluded('logs/sub/keep.md')).toBe(false);+ });+ });+describe('non-git graceful degradation', () => {test('works with no .gitignore and no .okignore', () => {const filter = createContentFilter({ projectDir, contentDir: projectDir });diff --git a/packages/server/src/content-filter.ts b/packages/server/src/content-filter.tsindex 57a658c79..0bbfe02b2 100644--- a/packages/server/src/content-filter.ts+++ b/packages/server/src/content-filter.ts@@ -585,8 +585,13 @@ function parseIgnorePatterns(content: string): string[] {}function prefixPattern(pattern: string, relPrefix: string): string {- if (pattern.startsWith('!')) return `!${relPrefix}/${pattern.slice(1)}`;- return `${relPrefix}/${pattern}`;+ const negated = pattern.startsWith('!');+ const body = negated ? pattern.slice(1) : pattern;+ const core = body.startsWith('/') ? body.slice(1) : body;+ const withoutTrailingSlash = core.endsWith('/') ? core.slice(0, -1) : core;+ const anchored = body.startsWith('/') || withoutTrailingSlash.includes('/');+ const reanchored = anchored ? `${relPrefix}/${core}` : `${relPrefix}/**/${core}`;+ return negated ? `!${reanchored}` : reanchored;}function loadNestedIgnoreFiles(