We have a pre-commit hook that forces the Cursor Background Agent to resolve all compilation errors, linting errors, and Jest test with sufficient coverage before allowing the commit to go through:
if git rev-parse -q --verify MERGE_HEAD >/dev/null || \
[ "$GITHUB_WORKFLOW" = "Release" ] || \
[ "$GITHUB_JOB" = "release" ]; then
echo "Merge commit or semantic-release workflow detected, skipping pre-commit hooks"
exit 0
fi
current_branch=$(git symbolic-ref --short HEAD 2>/dev/null)
if [[ $current_branch == test* ]]; then
echo "Test branch detected, skipping pre-commit hooks"
exit 0
fi
# Check if this is a Cursor Background Agent environment
if [ "$CURSOR_BACKGROUND_AGENT" = "true" ]; then
echo "Cursor Background Agent environment detected"
echo "Running enhanced pre-commit checks for Cursor Background Agent..."
# Run lint-staged
npx lint-staged
if [ $? -ne 0 ]; then
echo "Error: Linting failed. Please fix linting errors before committing."
exit 1
fi
# Run tests with coverage requirement for Cursor agents
if ! npm run test; then
echo "Error: Tests failed. All tests must pass before committing from Cursor Background Agent with sufficient coverage."
exit 1
fi
# Check TypeScript compilation for the frontend
# if ! npx tsc --project functions/tsconfig.json --noEmit; then
# echo "Error: TypeScript compilation failed. Please fix TypeScript errors."
# exit 1
# fi
echo "All Cursor Background Agent pre-commit checks passed!"
else
# Standard pre-commit for regular development
echo "Running standard pre-commit checks..."
npx lint-staged
fi
Our dream is that we could have the Background Agent run until this pre-commit executes without any errors. Basically, force the agent to keep going until a given script passes.
This request is also equally valid for local agents.