[hooks] SessionStart injects the knowledge-update frontmatter on a CRLF checkout

Đang mở Phù hợp với người mới
#429 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@abhiramshaji-cyber đang làm issue này rồi.

Từ ngày 17/11/2026.

  • #430 của @abhiramshaji-cyber — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
86/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
node.js, typescript
Lĩnh vực
backend, devtools

Hướng nghiên cứu

Đọc hooks/src/inject-claude-md.mts, đặc biệt là stripFrontmatter và hàm gọi nó, main; so sánh với trình phân tích cú pháp hiện có trong hooks/src/skill-map-frontmatter.mts, có xử lý CRLF và BOM. Tái hiện lỗi bằng cách chuyển đổi CRLF của issue và chạy hook bắt đầu phiên cho cả hai phần. Hoàn tất khi các đầu vào LF, CRLF và BOM bỏ qua frontmatter, và phần 2 bắt đầu bằng tiêu đề tiếp nối.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Hope you're doing well! On a checkout with CRLF line endings, the SessionStart hook injects the whole YAML frontmatter of skills/knowledge-update/SKILL.md into the session context, because its frontmatter regex only matches LF.

What this code is for

hooks/inject-claude-md.mjs runs at SessionStart for Claude Code and Cursor (--part 1/2 and --part 2/2 in hooks.json). It reads vercel-session.md and skills/knowledge-update/SKILL.md with a plain readFileSync (safeReadFile), drops the SKILL.md frontmatter, and splits the result into parts that stay under Claude Code's hook output cap. The splitting work from the recent PRs is really nice, and it is why the part 2 header matters below.

Current behaviour

  1. Someone installs the plugin on Windows. The marketplace install is a git clone, and the repo has no .gitattributes, so Git for Windows with core.autocrlf=true checks every file out with CRLF (#119 shows i/lf w/crlf on a real checkout).
  2. A session starts and inject-claude-md.mjs reads SKILL.md, which now starts with ---\r\n.
  3. stripFrontmatter runs /^---\n[\s\S]*?\n---\n?([\s\S]*)$/, which needs \n right after ---, so it does not match and returns the whole file.
  4. The whole frontmatter block (23 lines with the --- lines: name: knowledge-update, description: ..., metadata, ...) goes into the Claude Code text and the Cursor additional_context.
  5. The first line of the knowledge update is now ---, not # Vercel Knowledge Updates (...), so part 2 loses its (continued) header, and every line keeps its \r.

Expected behaviour

The frontmatter is dropped the same way on LF, CRLF and BOM files, and part 2 starts with # Vercel Knowledge Updates (...) (continued).

Minimal repro (on main at 90cc681)

mkdir /tmp/vp && cp -R hooks skills vercel-session.md /tmp/vp/ && cd "$(cd /tmp/vp && pwd -P)"
perl -pi -e 's/\n/\r\n/' skills/knowledge-update/SKILL.md
echo '{"session_id":"x"}' | VERCEL_PLUGIN_GREENFIELD=true node "$PWD/hooks/inject-claude-md.mjs" | grep -c '^name: knowledge-update'
# 1, expected 0
echo '{"session_id":"x"}' | VERCEL_PLUGIN_GREENFIELD=true node "$PWD/hooks/inject-claude-md.mjs" --part 2/2 | head -1 | cat -v
# ## New products LLMs may not know about^M   (no "(continued)" header, and a \r on every line)

(pwd -P because the hook only runs when its real path matches argv[1], and /tmp is a symlink on macOS; the greenfield flag just makes it inject outside a Vercel project.)

Why only this entry point

hooks/src/skill-map-frontmatter.mts already has a CRLF and BOM aware extractFrontmatter, and the OpenCode entry point already uses it for the same file (extractFrontmatter(knowledgeUpdate).body.trim()). inject-claude-md has its own copy that never got the CRLF handling.

stripFrontmatter has one caller, main in inject-claude-md.mts

stripFrontmatter and its only caller, main in inject-claude-md.mts, Functions view in Architect

extractFrontmatter callers: readMarkdown and buildSessionContext in opencode-plugin.mts, and scanSkillsDir

extractFrontmatter and its callers, the OpenCode buildSessionContext among them, Functions view in Architect

flowchart LR

classDef box fill:#eef1ff,stroke:#4c5bd4,color:#111827
classDef bad fill:#ffd6d6,stroke:#cc0000,color:#111827,stroke-width:3px
classDef good fill:#c8f0c8,stroke:#008800,color:#111827,stroke-width:3px

F["SKILL.md checked out with CRLF"] --> C["inject-claude-md main, Claude Code and Cursor"]
F --> O["opencode-plugin buildSessionContext"]
C --> S{"stripFrontmatter, LF only"}
O --> E{"extractFrontmatter, CRLF and BOM aware"}
S -->|"no match"| SB["frontmatter injected, no continued header"]
E -->|"match"| EB["body only"]

class F,C,O box
class S,SB bad
class E,EB good

This is related to #119 (CRLF in the build scripts) but a separate path, since this one runs on every session start.

A question

Would you be happy with inject-claude-md reusing extractFrontmatter so both entry points share one parser? I have a small PR ready that does that, also has the part splitter work on LF text, and adds a CRLF and BOM test for the session start output. I left .gitattributes out of it on purpose. Would a * text=auto eol=lf there be welcome too, maybe together with #119, or would you rather keep the code tolerant and not touch checkout settings? Happy to go either way, and thanks for taking a look!

Ngôn ngữ chính
TypeScript
Star
336
Fork
80
Merge trung bình
3 ngày 10 giờ
Pull request đã merge (30 ngày)
68

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của vercel/vercel-plugin

Tất cả issue của vercel/vercel-plugin

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.