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

オープン 初心者向け
#429 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@abhiramshaji-cyber がすでに取り組んでいます。

2026年11月17日 から。

  • #430 @abhiramshaji-cyber による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
86/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
node.js, typescript
領域
backend, devtools

調査の方向性

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

  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!

主要言語
TypeScript
スター
336
フォーク
80
平均マージ
3日 10時間
マージ済み PR(30日)
68

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

vercel/vercel-plugin のほかの issue

vercel/vercel-plugin の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。