carlos / platform Public

styleguide: deletion flow as built; drift check reads selectors only

Astra round 1 P2s. The guide now shows deletion as the console does it
(typed name, red button, passkey) and the confirm card with a rollback.
The drift check reads every class attribute form, errors on one it
cannot read, and counts a class only when a CSS selector names it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 55ace4272c4c38492e60ddd32ad8bbac5eafb222 parent 1aa6034
2 files changed, +109 −42
  • docs/console-styleguide.md +32 −18
  • internal/console/styleguide_test.go +77 −24

Intent

Human

<task-notification> <task-id>bg2e1k8lx</task-id> <tool-use-id>toolu_01NGVfrbvxvsPDhdnnNQXoSZ</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/a1de5273-c148-49b8-8267-3dee9d49c9c1/tasks/bg2e1k8lx.output</output-file> <status>completed</status> <summary>Background command "Confirm release approval to agent manager and controller" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>btwamq9t1</task-id> <tool-use-id>toolu_01HHt46eaCrU3ysjRHEt7pjo</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/83518551-672c-4121-970b-ef399c1bc6c2/tasks/btwamq9t1.output</output-file> <status>completed</status> <summary>Background command "mkdir -p ~/.cache/console-mockup-kit &amp;&amp; codex exec -m gpt-6-astra -c model_reasoning_effort="high" -s read-only -c 'sandbox_permissions=["disk-full-read-access"]' -o ~/.cache/console-mockup-kit/review-r1.md "You are reviewing repo at $(pwd), branch console-mockup-kit, commit 1aa603493cfee5ccc985d319295e2c32841f6ea8. Follow the brief at docs/superpowers/reviews/CODEX-REVIEW-BRIEF-console-mockup-kit.md exactly." &lt;/dev/null &gt; ~/.cache/console-mockup-kit/review-r1.log 2&gt;&amp;1; echo rc=$?; cat ~/.cache/console-mockup-kit/review-r1.md" completed (exit code 0)</summary> </task-notification>

diff --git a/docs/console-styleguide.md b/docs/console-styleguide.md
index 199bc2942..653a81997 100644
--- a/docs/console-styleguide.md
+++ b/docs/console-styleguide.md
@@ -114,7 +114,7 @@ page content. One banner at a time where you can.
<button type="submit" class="btn-secondary">Cancel</button>
<button type="submit" class="btn-sm">Rename</button>
<button type="submit" class="btn-sm btn-secondary">Restart</button>
-<button type="submit" class="btn-danger">Delete app</button>
+<button type="submit" class="btn-danger">Roll back to v41</button>
<a class="btn" href="/a/shop/apps/new">Create app</a>
<a class="btn btn-secondary" href="/a/shop/">Back to apps</a>
<button type="submit" class="linkish">Sign out</button>
@@ -126,8 +126,9 @@ page content. One banner at a time where you can.
navigation (`<a>`), never a `<button>` inside a link.
- `.btn-secondary` is for the other choices beside a primary.
- `.btn-sm` is for actions in a row, a table cell or a section head.
-- `.btn-danger` is for an action that destroys something, on the confirm
- step only. The button that opens the confirm step is ordinary.
+- `.btn-danger` is for the button that actually does something hard to
+ undo: the typed-name delete button in settings, or the button on a
+ confirm card. Not for a button that only opens a confirm step.
- `.linkish` is a button that reads as a link, for low-weight actions in
menus and tables; add `.danger` when it removes something.
@@ -279,44 +280,57 @@ Settings pages use the side-nav layout:
<h2>General</h2>
<p class="small">Settings for this app.</p>
<h2 class="danger-head">Delete this app</h2>
+ <p class="small">Deleting puts shop in the account's trash, where it can be restored for 30 days.</p>
<form method="post" action="/a/shop/apps/shop/delete" class="settings-row">
<input type="hidden" name="csrf" value="mockup">
- <button type="submit" class="btn-sm">Delete app</button>
+ <label class="visually-hidden" for="delete-confirm">Type the app's name to confirm</label>
+ <input type="text" id="delete-confirm" name="confirm" placeholder="type shop to confirm" autocomplete="off" required>
+ <button type="submit" class="btn-sm btn-danger">Delete shop</button>
</form>
+ <p class="small">Confirms with your passkey.</p>
</div>
</div>
```
-The destructive section goes last, under an `h2.danger-head`.
+The destructive section goes last, under an `h2.danger-head`. Deletion
+is confirmed in place: the reader types the name, presses the red
+button, then confirms with their passkey (the server checks
+`confirm=<name>`). It does not go through a confirm card.
## Confirm card
-The interstitial before anything that cannot be undone: what is about to
-happen, one button that does it, one link that does not.
+The interstitial before a consequential change to what is serving
+(promote, roll back, skip the safety delay, retire a canary, restart):
+what is about to happen, one button that does it, one link that does not.
+It is `templates/confirm_action.html`, filled from a `ConfirmView`
+(`confirm.go`).
```html
<div class="pagehead">
- <p class="eyebrow">App · shop</p>
- <h1>Delete shop?</h1>
+ <p class="eyebrow">Confirm · shop</p>
+ <h1>Roll back production to v41?</h1>
</div>
<div class="confirm-card">
- <p>This deletes the app, its releases and its addresses.</p>
- <p class="error">Its addresses stop answering straight away.</p>
- <form method="post" action="/a/shop/apps/shop/delete">
+ <p>production serves v42 now.</p>
+ <p>Rolling back re-points it to v41, the version before this one.</p>
+ <form method="post" action="/a/shop/apps/shop/rollback">
<input type="hidden" name="csrf" value="mockup">
+ <input type="hidden" name="channel" value="production">
+ <input type="hidden" name="target" value="v41">
<input type="hidden" name="confirmed" value="1">
<div class="actions">
- <button type="submit" class="btn-danger">Delete app</button>
- <a href="/a/shop/apps/shop/settings">Cancel</a>
+ <button type="submit" class="btn-danger">Roll back to v41</button>
+ <a href="/a/shop/apps/shop/releases">Cancel</a>
</div>
</form>
- <p class="small confirm-note">It moves to the Trash first, where you can still restore it.</p>
+ <p class="small confirm-note">Rollbacks skip the safety delay. It rolls out within a couple of minutes.</p>
</div>
```
-Use it for deletions, transfers and anything that costs money. Not as a
-general-purpose card for page content (that is a `.tile` or plain
-sections).
+Put a `<p class="error">` line in the card when the change carries a
+real risk the reader must weigh. Use the card for changes like these, not
+as a general-purpose card for page content (that is a `.tile` or plain
+sections), and not for deletion (see settings above).
## Done page
diff --git a/internal/console/styleguide_test.go b/internal/console/styleguide_test.go
index 5e6d76ce6..9ebee7263 100644
--- a/internal/console/styleguide_test.go
+++ b/internal/console/styleguide_test.go
@@ -1,6 +1,7 @@
package console
import (
+ "fmt"
"os"
"regexp"
"sort"
@@ -13,34 +14,57 @@ import (
var styleguideCSS = []string{"templates/console_chrome.html", "templates/fiesta.html"}
var (
- guideFence = regexp.MustCompile("(?s)```html\n(.*?)```")
- guideClass = regexp.MustCompile(`class="([^"]*)"`)
- cssComment = regexp.MustCompile(`(?s)/\*.*?\*/`)
- tmplComment = regexp.MustCompile(`(?s)\{\{/\*.*?\*/\}\}`)
+ guideFence = regexp.MustCompile("(?s)```html\n(.*?)```")
+ // guideClassAttr is a class attribute in any form HTML allows: double
+ // quotes, single quotes or none. Each form yields one submatch.
+ guideClassAttr = regexp.MustCompile(`(?i)\bclass\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>` + "`" + `]+))`)
+ // guideClassWord is any class= at all, so an attribute guideClassAttr
+ // could not read is an error rather than a silent skip.
+ guideClassWord = regexp.MustCompile(`(?i)\bclass\s*=`)
+ cssComment = regexp.MustCompile(`(?s)/\*.*?\*/`)
+ tmplAction = regexp.MustCompile(`(?s)\{\{.*?\}\}`)
+ cssString = regexp.MustCompile(`"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'`)
+ // cssPrelude is the text before a "{": a selector list or an at-rule.
+ // Declarations sit between "{" and "}" and are never matched, because
+ // the prelude cannot cross a brace.
+ cssPrelude = regexp.MustCompile(`([^{}]*)\{`)
cssClassName = regexp.MustCompile(`\.(-?[_a-zA-Z][_a-zA-Z0-9-]*)`)
)
// styleguideClasses is every class named in an ```html block of the guide.
-func styleguideClasses(guide string) map[string]bool {
+// It fails on a class attribute it cannot read, so no snippet class can
+// slip past the check.
+func styleguideClasses(guide string) (map[string]bool, error) {
out := map[string]bool{}
for _, block := range guideFence.FindAllStringSubmatch(guide, -1) {
- for _, attr := range guideClass.FindAllStringSubmatch(block[1], -1) {
- for _, c := range strings.Fields(attr[1]) {
+ attrs := guideClassAttr.FindAllStringSubmatch(block[1], -1)
+ if n := len(guideClassWord.FindAllStringIndex(block[1], -1)); n != len(attrs) {
+ return nil, fmt.Errorf("an html block has %d class attributes but only %d could be read:\n%s", n, len(attrs), block[1])
+ }
+ for _, attr := range attrs {
+ for _, c := range strings.Fields(attr[1] + " " + attr[2] + " " + attr[3]) {
out[c] = true
}
}
}
- return out
+ return out, nil
}
-// definedClasses is every class a selector in css names, comments removed
-// so a class mentioned only in prose does not count as styled.
+// definedClasses is every class a CSS selector in css names. Comments,
+// template actions, quoted strings and declaration values are not
+// selectors, so a class spelled only in one of those does not count.
func definedClasses(css string) map[string]bool {
- css = tmplComment.ReplaceAllString(css, "")
+ css = tmplAction.ReplaceAllString(css, "")
css = cssComment.ReplaceAllString(css, "")
+ css = cssString.ReplaceAllString(css, `""`)
out := map[string]bool{}
- for _, m := range cssClassName.FindAllStringSubmatch(css, -1) {
- out[m[1]] = true
+ for _, pre := range cssPrelude.FindAllStringSubmatch(css, -1) {
+ if strings.HasPrefix(strings.TrimSpace(pre[1]), "@") {
+ continue // @media, @supports, @keyframes: conditions, not selectors
+ }
+ for _, m := range cssClassName.FindAllStringSubmatch(pre[1], -1) {
+ out[m[1]] = true
+ }
}
return out
}
@@ -61,7 +85,10 @@ func TestConsoleStyleguideClassesExist(t *testing.T) {
}
css.Write(b)
}
- used := styleguideClasses(string(guide))
+ used, err := styleguideClasses(string(guide))
+ if err != nil {
+ t.Fatal(err)
+ }
if len(used) < 30 {
t.Fatalf("found only %d classes in the guide's html blocks; is the fence format still ```html?", len(used))
}
@@ -79,17 +106,43 @@ func TestConsoleStyleguideClassesExist(t *testing.T) {
}
}
-// TestStyleguideDriftCheckBites shows the check is not vacuous: a class the
-// CSS never defines, and one that appears only inside a CSS comment, are
-// both reported missing.
+// TestStyleguideDriftCheckBites shows the check is not vacuous. On the
+// guide side every attribute form is read and an unreadable one is an
+// error; on the CSS side a class spelled only in a comment, a template
+// action, a declaration value or an at-rule condition is not defined.
func TestStyleguideDriftCheckBites(t *testing.T) {
- guide := "```html\n<p class=\"banner no-such-class\">x</p>\n```\n<p class=\"prose-only\">"
- used := styleguideClasses(guide)
- if !used["banner"] || !used["no-such-class"] || used["prose-only"] {
- t.Fatalf("styleguideClasses = %v", used)
+ guide := "```html\n<p class=\"banner a\">x</p><p class='b c'>y</p><p CLASS=d>z</p>\n```\n<p class=\"prose-only\">"
+ used, err := styleguideClasses(guide)
+ if err != nil {
+ t.Fatal(err)
}
- defined := definedClasses(".banner { color: red; } /* .no-such-class is gone */ {{/* .also-gone */}}")
- if !defined["banner"] || defined["no-such-class"] || defined["also-gone"] {
- t.Fatalf("definedClasses = %v", defined)
+ for _, c := range []string{"banner", "a", "b", "c", "d"} {
+ if !used[c] {
+ t.Errorf("styleguideClasses missed %q: %v", c, used)
+ }
+ }
+ if used["prose-only"] {
+ t.Errorf("styleguideClasses read a class outside an html block: %v", used)
+ }
+ if _, err := styleguideClasses("```html\n<p class=>x</p>\n```"); err == nil {
+ t.Error("an unreadable class attribute was skipped, want an error")
+ }
+
+ defined := definedClasses(`{{define "x"}}
+.banner, main .tile:hover { color: red; }
+@media (min-width: 40rem) { .wide > p { margin: 0; } }
+p::before { content: ".in-string"; font-size: 1.5rem; }
+a[href=".in-attr"] { color: blue; }
+/* .in-comment is gone */ {{/* .in-tmpl-comment */}} {{.InAction}}
+{{end}}`)
+ for _, c := range []string{"banner", "tile", "wide"} {
+ if !defined[c] {
+ t.Errorf("definedClasses missed %q: %v", c, defined)
+ }
+ }
+ for _, c := range []string{"in-string", "in-attr", "in-comment", "in-tmpl-comment", "InAction", "5rem"} {
+ if defined[c] {
+ t.Errorf("definedClasses counted %q, which no selector names: %v", c, defined)
+ }
}
}