diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..e730dd7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,45 @@ +# Normalize line endings and mark binaries for cross-platform consistency + +# Default: text with LF (cross-platform canonical) +* text=auto eol=lf + +# Windows scripts keep CRLF +*.ps1 text eol=crlf +*.cmd text eol=crlf +*.bat text eol=crlf + +# Shell/Unix scripts use LF +*.sh text eol=lf + +# Obsidian text artifacts +*.md text eol=lf +*.base text eol=lf +*.canvas binary +*.json text eol=lf +*.yaml text eol=lf +*.yml text eol=lf + +# Binary assets (no diff noise, no line-ending conversion) +*.png binary +*.jpg binary +*.jpeg binary +*.gif binary +*.webp binary +*.ico binary +*.svg binary +*.pdf binary +*.epub binary +*.docx binary +*.pptx binary +*.xlsx binary +*.mp4 binary +*.mov binary +*.webm binary +*.mp3 binary +*.wav binary +*.zip binary +*.gz binary +*.7z binary +*.tar binary +*.exe binary +*.dll binary diff --git a/.githooks/post-merge b/.githooks/post-merge index 665f8c7..e00c735 100644 --- a/.githooks/post-merge +++ b/.githooks/post-merge @@ -1,5 +1,12 @@ #!/bin/sh -# post-merge — git pull/merge 后自动更新 qmd 索引 +# post-merge — refresh qmd index + hint to reload Obsidian after config pull + echo "=== post-merge: Updating qmd index ===" node "C:\Users\hhhh2024\AppData\Roaming\npm\node_modules\@tobilu\qmd\dist\cli\qmd.js" update 2>/dev/null || echo " qmd update skipped (not installed?)" + +# If .obsidian configs changed in this merge, hint reload +if ! git diff --quiet HEAD@{1} HEAD -- .obsidian 2>/dev/null; then + echo "=== .obsidian config changed: reload Obsidian (Ctrl+R) to apply ===" +fi + echo "=== Done ===" diff --git a/.githooks/pre-commit b/.githooks/pre-commit index dc80ebb..7b9c3a1 100644 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -1,11 +1,40 @@ #!/bin/sh -# pre-commit — 验证被修改的 wiki 页面 frontmatter -CHANGED=$(git diff --cached --name-only --diff-filter=ACM | grep '^wiki/.*\.md$') -if [ -z "$CHANGED" ]; then exit 0; fi +# pre-commit — frontmatter validation + large file guard + secret scan -python tools/scripts/validate-frontmatter.py --git-hook -if [ $? -ne 0 ]; then - echo "ERROR: Frontmatter validation failed. Commit rejected." - echo "Run 'python tools/scripts/validate-frontmatter.py --files ' to check." +# 1. Frontmatter validation for wiki pages +CHANGED=$(git diff --cached --name-only --diff-filter=ACM | grep '^wiki/.*\.md$') +if [ -n "$CHANGED" ]; then + python tools/scripts/validate-frontmatter.py --git-hook + if [ $? -ne 0 ]; then + echo "ERROR: Frontmatter validation failed. Commit rejected." + echo "Run 'python tools/scripts/validate-frontmatter.py --files ' to check." + exit 1 + fi +fi + +# 2. Large file guard (>10MB) — prevent accidental PDF/video/attachment commits +MAX_SIZE=10485760 # 10 MB +REJECT="" +for f in $(git diff --cached --name-only --diff-filter=ACM); do + [ -f "$f" ] || continue + FSIZE=$(wc -c < "$f" 2>/dev/null | tr -d ' ') + [ -z "$FSIZE" ] && FSIZE=0 + if [ "$FSIZE" -gt "$MAX_SIZE" ]; then + REJECT="$REJECT + $f ($FSIZE bytes)" + fi +done +if [ -n "$REJECT" ]; then + echo "ERROR: Files exceed 10MB limit (rejected):$REJECT" + echo "Use Git LFS or add to .gitignore." exit 1 fi + +# 3. Secret scan — long hex tokens (40+ chars) in staged diff (warning only) +LEAK=$(git diff --cached -U0 2>/dev/null | grep -iE '[0-9a-f]{40,}' | grep -v 'sha' | head -5) +if [ -n "$LEAK" ]; then + echo "WARN: Possible token/secret in staged diff (review before push):" + echo "$LEAK" +fi + +exit 0 diff --git a/.gitignore b/.gitignore index 2a0e1b5..2562c20 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,52 @@ -# 排除所有文件 +# Obsidian vault — whitelist strategy +# Ignore everything at repo root, explicitly allow specific dirs/files. +# Rationale: keep LLM Wiki layer + infra in git; track .obsidian configs too. + /* -# 但保留这些目录和文件 + +# === Tracked content (LLM Wiki layer + infrastructure) === !raw/ !wiki/ !Templates/ +!tools/ +!.githooks/ !AGENTS.md !.gitignore -# 保留目录内的所有内容 +!.gitattributes +!.mailmap + +# Allow everything inside tracked dirs !raw/** !wiki/** !Templates/** +!tools/** +!.githooks/** + +# === Obsidian config — track but ignore high-churn state/caches === +!.obsidian/ +!.obsidian/** + +# Device-specific workspace state (frequent churn, causes merge conflicts) +.obsidian/workspace.json +.obsidian/workspace.json.tmp +.obsidian/workspace_*.json +.obsidian/workspace_*_Conflict.json + +# Large derived indexes +.obsidian/copilot-index-*.json + +# Plugin internals: binaries, deps, backups, high-churn caches +.obsidian/plugins/*/node_modules/ +.obsidian/plugins/*/*.exe +.obsidian/plugins/*/*.dll +.obsidian/plugins/*/data.json.bak +.obsidian/plugins/recent-files-obsidian/data.json + +# === Python === +**/__pycache__/ +*.pyc + +# === OS junk === +**/Thumbs.db +**/.DS_Store +**/desktop.ini diff --git a/.mailmap b/.mailmap new file mode 100644 index 0000000..b38681f --- /dev/null +++ b/.mailmap @@ -0,0 +1,2 @@ +hehaiguang1123 豆儿雷锋大道 +hehaiguang1123 hehaiguang1123 diff --git a/AGENTS.md b/AGENTS.md index ce5a84f..8769e6a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1007,6 +1007,33 @@ node "C:\Users\hhhh2024\AppData\Roaming\npm\node_modules\@tobilu\qmd\dist\cli\qm **Skill**: 已安装到 `.agents/skills/qmd/SKILL.md` +### 6.4 提交信息规范(Conventional Commits) + +所有提交(手动与 obsidian-git 自动备份)统一采用 Conventional Commits + vault scope: + +| Scope | 用途 | 示例 | +|-------|------|------| +| `feat(wiki)` | 新建/更新 Wiki 页面 | `feat(wiki): 添加 [[人物]] 实体页` | +| `docs(raw)` | 摄入新来源到 raw/ | `docs(raw): 摄入 ALEKS 研究` | +| `fix(tools)` | 修复脚本/工具 | `fix(tools): validate-frontmatter GBK 编码` | +| `chore(vault)` | obsidian-git 自动备份 | `chore(vault): backup 2026-07-01 10:00:00` | +| `refactor(schema)` | AGENTS.md/规范调整 | `refactor(schema): Phase 1 关系字段` | +| `style(vault)` | frontmatter/格式修正 | `style(vault): 统一 frontmatter 布尔值` | + +**规则**: +- obsidian-git 自动备份提交信息已配置为 `chore(vault): backup {{date}}` +- 手动提交须语义化,避免 "update" / "修改" 等无信息标题 +- 提交者身份:`hehaiguang1123 `(历史身份经 `.mailmap` 合并) + +**Git 配置约定**: +- `.gitattributes`:文本统一 LF,Windows 脚本(`.ps1/.cmd/.bat`)CRLF,媒体文件标记 binary +- `.gitignore`:根目录白名单策略,仅跟踪 `raw/ wiki/ Templates/ tools/ .githooks/` + `.obsidian/` 配置 +- `.githooks/`(`core.hooksPath=.githooks`): + - `pre-commit`:frontmatter 校验 + 10MB 大文件防护 + token 扫描 + - `post-merge`:qmd 索引刷新 + `.obsidian` 变更重载提示 +- 远程凭证不内嵌 token,使用 Windows Credential Manager +- **多端同步工具冲突警示**:obsidian-git 为本库唯一同步机制;`obsidian-livesync` 插件虽存在于 `plugins/` 但**未启用**,若多端启用会与 git 双写产生不可恢复冲突,禁止同时启用 + --- ## 7. Wiki 维护工作流