Files
copilotkit__copilotkit/lefthook.yml
T

92 lines
4.1 KiB
YAML
Raw Normal View History

2026-03-02 14:59:16 +01:00
output:
- meta
- summary
- success
- failure
- execution
- execution_out
- execution_info
- skips
pre-commit:
2026-03-02 16:41:23 +01:00
parallel: true
commands:
check-binaries:
tags: binaries
run: bash scripts/hooks/check-binaries.sh
sync-lockfile:
tags: lockfile
glob: "{packages,examples,showcase/scripts}/**/package.json"
run: pnpm i --lockfile-only
stage_fixed: true
lint-fix:
2026-03-02 15:56:37 +01:00
tags: lint
# Scope oxlint and oxfmt to just the files staged for commit — running
# `--fix .` / `--write .` across the whole monorepo on every commit is
# both slow and blurs the hook's purpose (touch files that aren't part
# of this change). Guard against empty `{staged_files}` expansion: when
# a commit touches only non-matching files (markdown, YAML), lefthook
# still invokes this hook with an empty expansion, and oxlint/oxfmt
# would default to operating on the current directory, defeating the
# scoping entirely. stage_fixed re-stages whatever the hooks modify.
fix(lefthook): exclude json/jsonc/json5 from oxlint/oxfmt to prevent JSON5 mangling The lint-fix pre-commit step runs `oxlint --fix` + `oxfmt --write` over staged files. When `package.json` is part of the staged set, oxfmt rewrites the file into JSON5 syntax (4-space indent, trailing commas after the last key in every object, compacted single-line objects). The result is invalid strict JSON that pnpm rejects with `ERR_PNPM_JSON_PARSE` at line 8 column 5, blocking every commit that touches any `package.json`. This was bypassed in PRs #5054 and #5055 via `LEFTHOOK_EXCLUDE=lint-fix`; this commit fixes it at the source by removing `json,jsonc,json5` from the lint-fix glob. Reproduction (with the buggy glob): - Apply PR #5055's edit to packages/voice/package.json - git add + run `lefthook run pre-commit --command lint-fix` - oxfmt logs "1 file reformatted" - JSON.parse / pnpm install now fail on the rewritten file After the fix: - JSON-only staged sets cause lefthook to skip lint-fix ("no files for inspection") rather than mangle the JSON - TS/JS/etc. continue to flow through oxlint --fix + oxfmt --write unchanged - JSON formatting is left to pnpm and manual editing, both of which produce strict 2-space JSON oxfmt 0.36.0 exposes no per-file-type knob (printWidth/proseWrap/ ignorePatterns only); excluding json/jsonc/json5 from the glob is the minimal correct fix. A future oxfmt upgrade that ships a json formatter configurable via `.oxfmtrc.json` can re-add these extensions. This commit itself is being landed with `LEFTHOOK_EXCLUDE=lint-fix` because the bug being fixed currently blocks any path that exercises the lint-fix hook. The change touches only `lefthook.yml`, which is not a JSON file and would not be mangled — the exclude is purely defensive.
2026-05-27 13:49:31 -07:00
# Intentionally excludes json/jsonc/json5: oxfmt --write rewrites JSON
# files into JSON5 syntax (4-space indent, trailing commas, compact
# objects) when invoked via lefthook with staged file paths. The result
# is invalid strict JSON that pnpm rejects with ERR_PNPM_JSON_PARSE,
# blocking every commit that touches a package.json (see PRs #5054,
# #5055). JSON formatting is owned by pnpm/manual editing; oxfmt has
# no per-file knobs to keep package.json valid, so the only safe fix
# is to keep .json* out of this hook entirely.
glob: "*.{js,jsx,ts,tsx,mjs,cjs,md,css,yml,yaml,html,vue,py}"
# Mirror the ignorePatterns in .oxlintrc.json / .oxfmtrc.json at the
# hook layer. Without this, a docs-only commit expands {staged_files}
# to a single docs/** path; oxlint silently processes 0 files, then
# oxfmt exits 2 with "Expected at least one target file" and blocks
# the commit.
exclude:
- "docs/**"
- "showcase/aimock/shared/**"
- "showcase/aimock/d4/**"
- "showcase/aimock/d6/**"
# Use `set --` so the staged files become positional args; this is the
# only shell-portable way to test "are there any" without breaking on
# multi-file expansion. The old `[ -n "{staged_files}" ]` form failed
# with `sh: 1: [: <path>: unexpected operator` because lefthook
# interpolates the file list as space-separated words, not a single
# quoted string, so [ saw 3+ args and tried to parse a binary op.
run: |
set -- {staged_files}
if [ "$#" -gt 0 ]; then
pnpm exec oxlint --fix "$@"
# Defense-in-depth: filter package.json from explicit oxfmt args even though
# .oxfmtrc.json ignorePatterns covers it. Explicit-path invocations bypass the
# pattern in some tool versions; the shell filter makes the exclusion unconditional.
fmt_files=""; for f in "$@"; do case "$f" in */package.json|package.json) ;; *) fmt_files="$fmt_files $f" ;; esac; done
[ -n "$fmt_files" ] && pnpm exec oxfmt --write $fmt_files
# ruff v0.9+ formats JSON with trailing commas (JSONC), which breaks
# pnpm's JSON parser in the sync-lockfile hook. Scope it to .py only.
py_files=""; for f in "$@"; do case "$f" in *.py) py_files="$py_files $f";; esac; done
[ -n "$py_files" ] && ruff format $py_files 2>/dev/null || true
fi
stage_fixed: true
2026-03-02 16:09:55 +01:00
test-and-check-packages:
tags: test-packages
env:
NX_TUI: "false"
2026-03-02 16:09:55 +01:00
run: pnpm run test && pnpm run check:packages
check-plugin-skills:
tags: plugin-skills
glob: "{packages/*/skills/**,skills/runtime/**,skills/react-core/**,skills/a2ui-renderer/**,scripts/sync-plugin-skills.ts,.claude-plugin/**}"
run: pnpm check:plugin-skills
fail_text: |
Plugin skill mirror is out of sync with the Intent source.
Run: pnpm sync:plugin-skills
Then stage the changes and re-commit.
commit-msg:
commands:
commitlint:
2026-03-02 15:56:37 +01:00
tags: commitlint
run: pnpm commitlint --edit {1}