[hooks] SessionStart injects the knowledge-update frontmatter on a CRLF checkout
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 86/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- node.js, typescript
調査の方向性
hooks/src/inject-claude-md.mtsを読み、特にstripFrontmatterとその呼び出し元のmainを確認します。hooks/src/skill-map-frontmatter.mtsにある、CRLFとBOMに対応した既存のパーサーと比較します。IssueにあるCRLF変換で再現し、両方のパートについてセッション開始フックを実行します。LF、CRLF、BOMの入力でフロントマターが省かれ、パート2が続きのヘッダーから始まれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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
- Someone installs the plugin on Windows. The marketplace install is a git clone, and the repo has no
.gitattributes, so Git for Windows withcore.autocrlf=truechecks every file out with CRLF (#119 showsi/lf w/crlfon a real checkout). - A session starts and
inject-claude-md.mjsreads SKILL.md, which now starts with---\r\n. stripFrontmatterruns/^---\n[\s\S]*?\n---\n?([\s\S]*)$/, which needs\nright after---, so it does not match and returns the whole file.- The whole frontmatter block (23 lines with the
---lines:name: knowledge-update,description: ...,metadata, ...) goes into the Claude Code text and the Cursoradditional_context. - 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 and its only caller, main in inject-claude-md.mts, Functions view in Architect

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!
- 主要言語
- TypeScript
- スター
- 336
- フォーク
- 80
- 平均マージ
- 3日 10時間
- マージ済み PR(30日)
- 68
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
vercel/vercel-plugin のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
vercel/vercel-plugin#388 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
vercel/vercel-plugin#312 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
vercel/vercel-plugin#311 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 半日 初心者へのやさしさ 78/100
vercel/vercel-plugin#199 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
vercel/vercel-plugin#182 ·
メンテナーはふだん 1 日以内に返信
vercel/vercel-plugin の issue をすべて見る
似ている issue
-
status/need-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
google-gemini/gemini-cli#30328 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
severity:medium triage:confirmed triage:in-progress triage:reproduced
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
Cotal-AI/Cotal#7231 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
boxlite-ai/boxlite#2777 ·
メンテナーはふだん 1 日以内に返信
-
bug P3
難易度 1/5 1時間未満 初心者へのやさしさ 87/100
メンテナーはふだん 1 日以内に返信