feat: add validate_readme_structure (S2 Phase 1)

Validates MUST-Sections for tier=core (H1, Badges-Table, Topology-Block,
API, References) + section-order (API before References). Tier=community
returns empty (recommendation-only per spec section 3.1).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Axel Meyer
2026-05-16 13:37:35 +02:00
parent d71ea6df74
commit 4ab4bda0e7

View File

@@ -98,4 +98,35 @@ function M.generate_topology_block(manifest, engine_calls)
return table.concat(lines, "\n") return table.concat(lines, "\n")
end end
-- Validates README structure against MUST-sections for the given tier.
-- Tier "core" enforces: H1, Abstract, Badges-Table, Topology-Block, API, References.
-- Tier "community" enforces nothing (returns empty result).
-- Returns: { missing_sections = [...], section_order_ok = bool }
function M.validate_readme_structure(markdown_string, tier)
if tier ~= "core" then
return { missing_sections = {}, section_order_ok = true }
end
local missing = {}
local checks = {
{ name = "H1", pattern = "^#%s+%S" },
{ name = "Badges-Table", pattern = "\n|%s*Field%s*|" },
{ name = "Topology-Block", pattern = "<!%-%-%s*topology:start" },
{ name = "API", pattern = "\n##%s+API[%s\n]" },
{ name = "References", pattern = "\n##%s+References[%s\n]" },
}
for _, c in ipairs(checks) do
if not string.find(markdown_string, c.pattern) then
table.insert(missing, c.name)
end
end
-- Order check: API must appear before References in source order
local api_pos = string.find(markdown_string, "\n##%s+API[%s\n]")
local ref_pos = string.find(markdown_string, "\n##%s+References[%s\n]")
local order_ok = (api_pos and ref_pos and api_pos < ref_pos) or (not api_pos and not ref_pos)
return { missing_sections = missing, section_order_ok = order_ok }
end
return M return M