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

Aperta Adatta ai principianti
#429 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@abhiramshaji-cyber ci sta già lavorando.

Dal 17/11/2026.

  • #430 di @abhiramshaji-cyber — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
86/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, typescript
Ambito
backend, devtools

Direzione di ricerca

Leggi hooks/src/inject-claude-md.mts, in particolare stripFrontmatter e il suo chiamante, main; confrontalo con il parser esistente che gestisce CRLF e BOM in hooks/src/skill-map-frontmatter.mts. Riproduci il problema con la conversione CRLF dell’issue ed esegui l’hook di avvio della sessione per entrambe le parti. Il lavoro è concluso quando gli input LF, CRLF e BOM omettono il frontmatter e la parte 2 inizia con l’intestazione continuata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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!

Lingua principale
TypeScript
Stelle
336
Fork
80
Merge medio
3g 10h
PR unite (30g)
68

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di vercel/vercel-plugin

Tutte le issue di vercel/vercel-plugin

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.