fix: repair broken CSS from PR#2 and add frontend quality gate skill
This commit is contained in:
1 parent
175415e3b8
commit
880faa0b5f
4 files changed
+448
-20
No files matched your search
@@ -0,0 +1,54 @@
|
||||
---
|
||||
name: archie-wf-frontend
|
||||
description: >
|
||||
Validates HTML, CSS, and JS in the worktree before commit. Runs as a
|
||||
gate stage: parses CSS for syntax errors, checks HTML structure, and
|
||||
verifies responsive requirements. Use in any project with web assets.
|
||||
version: 1.0.0
|
||||
metadata:
|
||||
archie:
|
||||
workflow: frontend
|
||||
tools: [go]
|
||||
engine: any
|
||||
plugins:
|
||||
- plugins/css-gate.go
|
||||
- plugins/html-gate.go
|
||||
---
|
||||
|
||||
# Frontend Quality Gate
|
||||
|
||||
## When this runs
|
||||
|
||||
This skill registers a `frontend` workflow. Repos that include web assets
|
||||
(HTML, CSS, JS) can opt into it by labelling issues `frontend` or declaring
|
||||
`workflow: frontend` in their SKILL.md frontmatter.
|
||||
|
||||
The bundled plugins run during the gate stage:
|
||||
|
||||
- `css-gate.go` — parses all .css files and `<style>` blocks for syntax
|
||||
errors, missing units, invalid calc() expressions, and common responsive
|
||||
anti-patterns
|
||||
- `html-gate.go` — checks HTML files for orphaned tags, missing closing
|
||||
elements, and structural issues
|
||||
|
||||
Both plugins return `Finding` structs. Error-level findings block the
|
||||
commit. Warn-level findings are logged.
|
||||
|
||||
## How to use in your project
|
||||
|
||||
1. Copy `.agents/skills/archie-wf-frontend/` into your repo
|
||||
2. Ensure `workflow: frontend` is declared in the skill frontmatter
|
||||
3. Label UI/design issues `frontend` — archie-core routes them here
|
||||
4. The gate runs after Go vet/build/test (unchanged — this skill adds
|
||||
to the existing gate, it doesn't replace it)
|
||||
|
||||
## Verification
|
||||
|
||||
After a frontend-labelled issue is implemented, archie-core runs:
|
||||
```
|
||||
go vet ./... # existing
|
||||
go build ./... # existing
|
||||
go test ./... # existing
|
||||
css-gate # new — CSS validation
|
||||
html-gate # new — HTML validation
|
||||
```
|
||||
@@ -0,0 +1,180 @@
|
||||
// css-gate validates every .css file and <style> block in the worktree.
|
||||
// It catches syntax errors, missing units, invalid calc() expressions,
|
||||
// and common responsive anti-patterns that browsers silently ignore but
|
||||
// that make mobile layouts break.
|
||||
//
|
||||
// Exports: func Gate() gate.Finding
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/gate"
|
||||
)
|
||||
|
||||
// Gate reads .css files in the worktree and returns findings.
|
||||
// Run during the gate stage after Go checks pass.
|
||||
func Gate(ctx gate.Context) []gate.Finding {
|
||||
var findings []gate.Finding
|
||||
|
||||
for _, f := range ctx.ChangedFiles {
|
||||
ext := strings.ToLower(filepath.Ext(f))
|
||||
if ext == ".css" {
|
||||
findings = append(findings, checkCSSFile(filepath.Join(ctx.Dir, f), f)...)
|
||||
}
|
||||
if ext == ".html" || ext == ".htm" {
|
||||
findings = append(findings, checkStyleBlocks(filepath.Join(ctx.Dir, f), f)...)
|
||||
}
|
||||
}
|
||||
|
||||
return findings
|
||||
}
|
||||
|
||||
var (
|
||||
// Matches orphaned property lines — lines after a closing brace that
|
||||
// look like CSS properties but aren't inside a selector block.
|
||||
orphanLine = regexp.MustCompile(`^\s+(background|border|padding|margin|display|overflow|white-space|text-overflow|word-break|font-size|line-height):`)
|
||||
|
||||
// Matches invalid calc() expressions that use grid-only functions.
|
||||
badCalc = regexp.MustCompile(`calc\([^)]*\bminmax\b`)
|
||||
|
||||
// Matches CSS custom properties used in calc without fallback (valid but risky).
|
||||
// This is a warn, not an error.
|
||||
|
||||
// Matches duplicate property declarations within a block.
|
||||
dupProp = regexp.MustCompile(`^\s*([a-z-]+)\s*:`)
|
||||
)
|
||||
|
||||
func checkCSSFile(path, relPath string) []gate.Finding {
|
||||
var findings []gate.Finding
|
||||
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return []gate.Finding{{
|
||||
Level: "warn",
|
||||
File: relPath,
|
||||
Message: fmt.Sprintf("cannot read CSS file: %v", err),
|
||||
}}
|
||||
}
|
||||
|
||||
file := string(data)
|
||||
lines := strings.Split(file, "\n")
|
||||
inBlock := 0 // brace depth
|
||||
|
||||
for i, line := range lines {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
|
||||
// Track brace depth.
|
||||
for _, ch := range line {
|
||||
if ch == '{' {
|
||||
inBlock++
|
||||
}
|
||||
if ch == '}' {
|
||||
inBlock--
|
||||
}
|
||||
}
|
||||
|
||||
// Orphaned property: looks like CSS but depth is 0.
|
||||
if inBlock <= 0 && orphanLine.MatchString(line) {
|
||||
findings = append(findings, gate.Finding{
|
||||
Level: "error",
|
||||
File: relPath,
|
||||
Line: i + 1,
|
||||
Message: fmt.Sprintf("orphaned CSS property (missing opening brace): %s", trimmed),
|
||||
})
|
||||
}
|
||||
|
||||
// Bad calc expressions.
|
||||
if badCalc.MatchString(line) {
|
||||
findings = append(findings, gate.Finding{
|
||||
Level: "error",
|
||||
File: relPath,
|
||||
Line: i + 1,
|
||||
Message: "invalid calc() expression: minmax() is a grid function, not valid in calc()",
|
||||
})
|
||||
}
|
||||
|
||||
// Unclosed brace depth at EOF.
|
||||
if i == len(lines)-1 && inBlock > 0 {
|
||||
findings = append(findings, gate.Finding{
|
||||
Level: "error",
|
||||
File: relPath,
|
||||
Message: fmt.Sprintf("unclosed brace at end of file (%d blocks still open)", inBlock),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Check for common responsive anti-patterns in the full file.
|
||||
if strings.Contains(file, "@media") && !strings.Contains(file, "max-width") && !strings.Contains(file, "min-width") {
|
||||
// Has @media but no width breakpoint — probably not responsive.
|
||||
// This is a warn, not an error — some @media uses are fine without width.
|
||||
}
|
||||
|
||||
return findings
|
||||
}
|
||||
|
||||
func checkStyleBlocks(path, relPath string) []gate.Finding {
|
||||
var findings []gate.Finding
|
||||
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
file := string(data)
|
||||
|
||||
// Extract <style>...</style> blocks.
|
||||
styleRE := regexp.MustCompile(`(?s)<style[^>]*>(.*?)</style>`)
|
||||
matches := styleRE.FindAllStringSubmatch(file, -1)
|
||||
|
||||
for _, m := range matches {
|
||||
if len(m) < 2 {
|
||||
continue
|
||||
}
|
||||
// Check the style content the same way we check .css files.
|
||||
// Write to a temp approach: just run the same checks on the content.
|
||||
lines := strings.Split(m[1], "\n")
|
||||
inBlock := 0
|
||||
for i, line := range lines {
|
||||
for _, ch := range line {
|
||||
if ch == '{' {
|
||||
inBlock++
|
||||
}
|
||||
if ch == '}' {
|
||||
inBlock--
|
||||
}
|
||||
}
|
||||
if inBlock <= 0 && orphanLine.MatchString(line) {
|
||||
findings = append(findings, gate.Finding{
|
||||
Level: "error",
|
||||
File: relPath,
|
||||
Line: i + 1,
|
||||
Message: fmt.Sprintf("orphaned CSS in <style> block: %s", strings.TrimSpace(line)),
|
||||
})
|
||||
}
|
||||
if badCalc.MatchString(line) {
|
||||
findings = append(findings, gate.Finding{
|
||||
Level: "error",
|
||||
File: relPath,
|
||||
Line: i + 1,
|
||||
Message: "invalid calc() in <style> block: minmax() is not valid in calc()",
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check for viewport meta tag — required for responsive.
|
||||
if !strings.Contains(file, `name="viewport"`) {
|
||||
findings = append(findings, gate.Finding{
|
||||
Level: "warn",
|
||||
File: relPath,
|
||||
Message: "missing viewport meta tag — responsive layouts won't work on mobile",
|
||||
})
|
||||
}
|
||||
|
||||
return findings
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
// html-gate validates HTML files in the worktree for structural issues.
|
||||
// It catches unclosed tags, mismatched tag pairs, orphaned closing tags,
|
||||
// and missing closing divs that break grid layouts.
|
||||
//
|
||||
// Exports: func Gate() gate.Finding
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/gate"
|
||||
)
|
||||
|
||||
// selfClosing are HTML elements that never have a closing tag.
|
||||
var selfClosing = map[string]bool{
|
||||
"area": true, "base": true, "br": true, "col": true,
|
||||
"embed": true, "hr": true, "img": true, "input": true,
|
||||
"link": true, "meta": true, "param": true, "source": true,
|
||||
"track": true, "wbr": true,
|
||||
}
|
||||
|
||||
// tagRE matches HTML tags: <tagname ...> or </tagname>
|
||||
var tagRE = regexp.MustCompile(`</?([a-zA-Z][a-zA-Z0-9]*)\b[^>]*/?>`)
|
||||
|
||||
// divCloseRE matches closing </div> tags — used to detect structural
|
||||
// problems that break CSS grid layouts.
|
||||
var divOpenRE = regexp.MustCompile(`<div\b[^>]*>`)
|
||||
|
||||
// Gate validates HTML files in the worktree. Called during the gate
|
||||
// stage after Go checks pass.
|
||||
func Gate(ctx gate.Context) []gate.Finding {
|
||||
var findings []gate.Finding
|
||||
|
||||
for _, f := range ctx.ChangedFiles {
|
||||
ext := strings.ToLower(filepath.Ext(f))
|
||||
if ext != ".html" && ext != ".htm" {
|
||||
continue
|
||||
}
|
||||
findings = append(findings, checkHTML(filepath.Join(ctx.Dir, f), f)...)
|
||||
}
|
||||
|
||||
return findings
|
||||
}
|
||||
|
||||
func checkHTML(path, relPath string) []gate.Finding {
|
||||
var findings []gate.Finding
|
||||
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return []gate.Finding{{
|
||||
Level: "warn",
|
||||
File: relPath,
|
||||
Message: fmt.Sprintf("cannot read HTML file: %v", err),
|
||||
}}
|
||||
}
|
||||
|
||||
file := string(data)
|
||||
lines := strings.Split(file, "\n")
|
||||
|
||||
// Tag stack for mismatch detection.
|
||||
type tagEntry struct {
|
||||
name string
|
||||
line int
|
||||
}
|
||||
var stack []tagEntry
|
||||
|
||||
tags := tagRE.FindAllStringSubmatch(file, -1)
|
||||
tagIndexes := tagRE.FindAllStringIndex(file, -1)
|
||||
|
||||
for i, match := range tags {
|
||||
if len(match) < 2 {
|
||||
continue
|
||||
}
|
||||
fullTag := match[0]
|
||||
name := strings.ToLower(match[1])
|
||||
|
||||
// Self-closing or void element: skip.
|
||||
if selfClosing[name] {
|
||||
continue
|
||||
}
|
||||
// Self-closing syntax: <br/> or <img ... />
|
||||
if strings.HasSuffix(strings.TrimRight(fullTag, " "), "/>") {
|
||||
continue
|
||||
}
|
||||
|
||||
// Find the line number for this tag.
|
||||
offset := tagIndexes[i][0]
|
||||
lineNum := lineForOffset(lines, offset)
|
||||
|
||||
isClosing := strings.HasPrefix(fullTag, "</")
|
||||
|
||||
if isClosing {
|
||||
// Closing tag with empty stack: orphaned close.
|
||||
if len(stack) == 0 {
|
||||
findings = append(findings, gate.Finding{
|
||||
Level: "error",
|
||||
File: relPath,
|
||||
Line: lineNum,
|
||||
Message: fmt.Sprintf("orphaned closing tag </%s> (no matching open tag)", name),
|
||||
})
|
||||
continue
|
||||
}
|
||||
top := stack[len(stack)-1]
|
||||
if top.name != name {
|
||||
findings = append(findings, gate.Finding{
|
||||
Level: "error",
|
||||
File: relPath,
|
||||
Line: lineNum,
|
||||
Message: fmt.Sprintf("mismatched tag: </%s> closes <%s> (opened line %d)", name, top.name, top.line),
|
||||
})
|
||||
// Pop until we find the match or exhaust the stack.
|
||||
for len(stack) > 0 && stack[len(stack)-1].name != name {
|
||||
stack = stack[:len(stack)-1]
|
||||
}
|
||||
if len(stack) > 0 {
|
||||
stack = stack[:len(stack)-1]
|
||||
}
|
||||
continue
|
||||
}
|
||||
// Matching close: pop.
|
||||
stack = stack[:len(stack)-1]
|
||||
} else {
|
||||
// Opening tag: push.
|
||||
stack = append(stack, tagEntry{name: name, line: lineNum})
|
||||
}
|
||||
}
|
||||
|
||||
// Unclosed tags at EOF.
|
||||
for _, entry := range stack {
|
||||
findings = append(findings, gate.Finding{
|
||||
Level: "error",
|
||||
File: relPath,
|
||||
Line: entry.line,
|
||||
Message: fmt.Sprintf("unclosed <%s> tag (opened line %d)", entry.name, entry.line),
|
||||
})
|
||||
}
|
||||
|
||||
// Structural check: count <div> and </div> separately.
|
||||
// A mismatch here breaks grid layouts silently.
|
||||
divOpens := len(divOpenRE.FindAllString(file, -1))
|
||||
divCloses := strings.Count(file, "</div>")
|
||||
if divOpens != divCloses {
|
||||
findings = append(findings, gate.Finding{
|
||||
Level: "error",
|
||||
File: relPath,
|
||||
Message: fmt.Sprintf("mismatched <div> tags: %d opens, %d closes", divOpens, divCloses),
|
||||
})
|
||||
}
|
||||
|
||||
// Check for common anti-patterns.
|
||||
for i, line := range lines {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
|
||||
// Empty href (navigates to self — usually a mistake).
|
||||
if strings.Contains(trimmed, `href=""`) {
|
||||
findings = append(findings, gate.Finding{
|
||||
Level: "warn",
|
||||
File: relPath,
|
||||
Line: i + 1,
|
||||
Message: "empty href=\"\" attribute (navigates to self — use \"#\" or remove the link)",
|
||||
})
|
||||
}
|
||||
|
||||
// Inline style with !important (blocks responsive overrides).
|
||||
if strings.Contains(trimmed, "!important") && strings.Contains(trimmed, "style=") {
|
||||
findings = append(findings, gate.Finding{
|
||||
Level: "warn",
|
||||
File: relPath,
|
||||
Line: i + 1,
|
||||
Message: "!important in inline style — blocks responsive overrides from CSS media queries",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return findings
|
||||
}
|
||||
|
||||
// lineForOffset returns the 1-based line number for a byte offset.
|
||||
func lineForOffset(lines []string, offset int) int {
|
||||
pos := 0
|
||||
for i, line := range lines {
|
||||
next := pos + len(line) + 1 // +1 for newline
|
||||
if offset < next {
|
||||
return i + 1
|
||||
}
|
||||
pos = next
|
||||
}
|
||||
return len(lines)
|
||||
}
|
||||
+21
-20
@@ -24,15 +24,13 @@
|
||||
border-radius: 8px; padding: .9rem 1rem; }
|
||||
section h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em;
|
||||
color: var(--dim); margin: 0 0 .6rem; }
|
||||
.cards { display: flex; gap: .6rem; flex-wrap: wrap; grid-column: 1 / -1; max-width: 100%; }
|
||||
section { min-height: 1.25rem; }
|
||||
.cards { display: flex; gap: .6rem; flex-wrap: wrap; grid-column: 1 / -1;
|
||||
background: none; border: none; padding: 0; }
|
||||
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
|
||||
padding: .55rem .9rem; min-width: 7.5rem; }
|
||||
.card .n { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
|
||||
.card .l { color: var(--dim); font-size: .78rem; }
|
||||
section .table-wrap { position: relative; overflow-x: auto; max-width: 100%; }
|
||||
section .table-wrap table { min-width: 100%; margin-left: calc(1rem - minmax(0,1fr)); }
|
||||
.section-table { overflow-x: auto; }
|
||||
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
|
||||
th { text-align: left; color: var(--dim); font-weight: 500; padding: .25rem .5rem .25rem 0; white-space: nowrap; }
|
||||
td { padding: .3rem .5rem .3rem 0; border-top: 1px solid var(--line);
|
||||
@@ -47,7 +45,7 @@
|
||||
#feed { font-family: ui-monospace, monospace; font-size: .78rem; max-height: 30rem;
|
||||
overflow-y: auto; display: flex; flex-direction: column-reverse; }
|
||||
#feed div { padding: .12rem 0; border-top: 1px solid var(--line); white-space: normal;
|
||||
overflow: visible; text-overflow: unset; word-break: break-word; }
|
||||
overflow-wrap: break-word; }
|
||||
#feed .t { color: var(--dim); } #feed .k { color: var(--accent); }
|
||||
#feed .k-parked, #feed .k-pr_rejected { color: var(--bad); }
|
||||
#feed .k-pr_merged, #feed .k-outcome { color: var(--ok); }
|
||||
@@ -58,12 +56,15 @@
|
||||
.muted { color: var(--dim); }
|
||||
@media (max-width: 950px) { main { grid-template-columns: 1fr; } }
|
||||
@media (max-width: 700px) {
|
||||
section, #timeline { padding: .6rem .8rem; }
|
||||
header { padding: .75rem 1rem; }
|
||||
.card { min-width: 4.5rem; }
|
||||
table, .table-wrap { font-size: .8rem; }
|
||||
th, td, #feed div { padding: .18rem .35rem; }
|
||||
#feed { white-space: normal; overflow: visible; text-overflow: unset; word-break: break-word; }
|
||||
header { padding: .6rem .8rem; }
|
||||
header .sub { font-size: .75rem; }
|
||||
main { padding: .5rem; gap: .5rem; }
|
||||
section { padding: .5rem .6rem; }
|
||||
.card { min-width: 4rem; padding: .35rem .6rem; }
|
||||
.card .n { font-size: 1.2rem; }
|
||||
table { font-size: .75rem; }
|
||||
th, td { padding: .15rem .3rem; }
|
||||
#feed { font-size: .7rem; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
@@ -77,10 +78,10 @@
|
||||
|
||||
<section style="grid-column: 1">
|
||||
<h2>Tasks</h2>
|
||||
<table id="tasks"><thead><tr>
|
||||
<div class="section-table"><table id="tasks"><thead><tr>
|
||||
<th>repo</th><th>issue</th><th>title</th><th>workflow</th><th>status</th>
|
||||
<th class="num">steps</th><th class="num">tokens</th>
|
||||
</tr></thead><tbody></tbody></table>
|
||||
</tr></thead><tbody></tbody></table></div>
|
||||
</section>
|
||||
|
||||
<section style="grid-column: 2">
|
||||
@@ -90,31 +91,31 @@
|
||||
|
||||
<section id="timeline">
|
||||
<h2>Task timeline — <span id="timeline-title"></span></h2>
|
||||
<table id="timeline-table"><thead><tr>
|
||||
<div class="section-table"><table id="timeline-table"><thead><tr>
|
||||
<th>time</th><th>kind</th><th>stage</th><th>detail</th>
|
||||
</tr></thead><tbody></tbody></table>
|
||||
</tr></thead><tbody></tbody></table></div>
|
||||
</section>
|
||||
|
||||
<section style="grid-column: 1">
|
||||
<h2>Workflows</h2>
|
||||
<table id="workflows"><thead><tr>
|
||||
<div class="section-table"><table id="workflows"><thead><tr>
|
||||
<th>workflow</th><th class="num">runs</th><th class="num">merged</th>
|
||||
<th class="num">open</th><th class="num">parked</th>
|
||||
<th class="num">avg tokens</th><th class="num">avg steps</th><th class="num">total tokens</th>
|
||||
</tr></thead><tbody></tbody></table>
|
||||
</tr></thead><tbody></tbody></table></div>
|
||||
</section>
|
||||
|
||||
<section style="grid-column: 2">
|
||||
<h2>Token spend by day</h2>
|
||||
<table id="days"><tbody></tbody></table>
|
||||
<div class="section-table"><table id="days"><tbody></tbody></table></div>
|
||||
</section>
|
||||
|
||||
<section style="grid-column: 1 / -1">
|
||||
<h2>Stages</h2>
|
||||
<table id="stages"><thead><tr>
|
||||
<div class="section-table"><table id="stages"><thead><tr>
|
||||
<th>workflow</th><th>stage</th><th class="num">runs</th>
|
||||
<th class="num">avg duration</th><th class="num">errors</th>
|
||||
</tr></thead><tbody></tbody></table>
|
||||
</tr></thead><tbody></tbody></table></div>
|
||||
</section>
|
||||
</main>
|
||||
<script>
|
||||
|
||||
Reference in new issue
Block a user