"""Audit metadata consistency across all knowledge documents.""" import os docs_dir = r'E:\workspace\dan\num\knowledge\research' results = [] for f in sorted(os.listdir(docs_dir)): if not f.endswith('.md'): continue path = os.path.join(docs_dir, f) content = open(path, 'r', encoding='utf-8').read() lines = content.split('\n') # Check frontmatter has_frontmatter = content.startswith('---') if not has_frontmatter: results.append((f, 'NO_FRONTMATTER')) continue # Parse frontmatter in_frontmatter = False tags = [] title = '' confidence = '' has_tags = False for line in lines[:40]: if line.strip() == '---': in_frontmatter = not in_frontmatter continue if in_frontmatter: if line.startswith('title:'): title = line.replace('title:', '').strip().strip('"').strip("'") elif line.startswith('confidence:'): confidence = line.split(':')[1].strip() elif line.startswith('tags:'): has_tags = True elif line.strip().startswith('- ') and in_frontmatter: tags.append(line.strip().lstrip('- ').strip()) file_size = os.path.getsize(path) line_count = len(lines) # Determine which layer (A/B/C/D/E/other) the doc belongs to layer = 'OTHER' if f.startswith('A') or '命盘24位置' in f: layer = 'A' elif f.startswith('B') or '八星' in f or '联合密码' in f or '三角命盘组合' in f: layer = 'B' elif f.startswith('C') or '维度手册' in f or '五区三组' in f or '数字0与5' in f: layer = 'C' elif f.startswith('D') or '递进' in f or '组合能量' in f: layer = 'D' elif f.startswith('E') or '天赋数' in f: layer = 'E' print(f'{layer} | {f:40s} | tags={len(tags):2d} | conf={confidence:8s} | {line_count:4d}行 | {file_size:6d}B') if not has_tags: print(f' >>> WARNING: No tags found in {f}') if not confidence: print(f' >>> WARNING: No confidence in {f}')