Skip to content

fix(wiki-parser): exclude untracked and gitignored files from the wiki scan - #707

Open
royweisfeld wants to merge 1 commit into
Egonex-AI:mainfrom
royweisfeld:fix/parse-exclude-untracked-files
Open

royweisfeld wants to merge 1 commit into
Egonex-AI:mainfrom
royweisfeld:fix/parse-exclude-untracked-files

Conversation

@royweisfeld

Copy link
Copy Markdown

Problem

parse-knowledge-base.py discovered wiki articles with wiki_root.rglob("*.md") — every markdown file under the wiki root, including untracked files (locally generated cross-platform index pages, gitignored private-overlay mounts, scratch notes).

This had two failure modes observed on a real vault:

  1. Generated index files were ingested as articles, inflating the corpus with machine-generated routing pages.
  2. Worse, a privacy leak: such files often wikilink into private/gitignored areas of the vault. Those link targets were never traversed (Python rglob does not follow symlinked private mounts), but their paths and page titles landed in scan-manifest.json as knowledgeMeta.wikilinks and flowed into knowledge-graph.json, which downstream consumers (context hooks, semantic queries) surface.

Change

  • New git_tracked_files() + list_wiki_md_files() helpers: when the wiki root is inside a git work tree, scan only git-tracked files; surface the excluded count as a manifest warning (git-filter: excluded N untracked markdown file(s) …).
  • Applied at all four scan sites: detect_format, build_name_to_stem_map, article-ID precompute, and article-node building — so leaked targets can't re-enter via nodes, name maps, or link resolution.
  • Fallback preserved: vaults not inside a git repository keep the exact previous scan-everything behavior.

Tests

  • test_untracked_files_excluded_when_git_repo — a git repo with a tracked wiki plus an untracked generated index linking to ../_private/...: asserts the index is excluded, its private link target appears nowhere in the manifest, and the exclusion warning is present.
  • test_fallback_includes_all_files_without_git — non-git vaults keep the old behavior.
  • Full existing suite unchanged: tests/skill/knowledge/test_parse_knowledge_base.py 10 passed, 1 skipped.

Notes

  • pnpm test shows 1 pre-existing failure on clean main (tests/skill/understand/test_scan_project.test.mjs › .understandignore negation re-include) — reproduced with this branch stashed, so unrelated to this change.

The Karpathy wiki parser scanned every *.md file under the wiki root via
rglob, including locally generated, untracked, or gitignored files. When
a vault sits inside a git work tree, such files (generated cross-platform
index files, private overlay pages, scratch notes) could enter the scan
manifest — and their link targets (e.g. private-tier page paths) leaked
into the knowledge graph metadata even though the target files were
never traversed.

parse-knowledge-base.py now filters scan candidates through
git ls-files when the wiki root is inside a git work tree, at all scan
sites (format detection, name-resolution map, article ID precompute,
article node building). Exclusions are surfaced as a manifest warning.
Non-git vaults keep the previous scan-everything behavior.

Adds tests for both paths: untracked files excluded (with warning) in a
git repo, and the fallback including all files without git.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant