Would require “Indoors”.
If there are not enough buildings nearby and you have enough energy and resources, build a new structure.
Villagers choose an area that has enough space (overlapping with no existing buildings) and builds on the lowest solid point exposed to sky. They will remove anything in the way.
Villagers have access to recipes that relate to the buildings they can construct. They will seek out necessary base resources, crafting them into tools and building materials.
Certain types of villagers can build certain types of village buildings. Tool/Armor/Weapon Smiths can build forges, librarians can build libraries, etc.
Need to figure out how to handle doorless and/or concave structures like blacksmiths, wells and farms, so that they don’t get built over. Maybe certain structure types give particular block positions an owner or some other “protected” variable? And you can’t build on blocks that have that? Would/How would this apply to player-created structures?