Phase 11, part 3: approvals for what agents send out

Agents can now ask to publish or schedule a post, send an email, add
someone to a mailing list, or apply an SEO change. Each waits on the
Approvals page (with a count in the sidebar) for an admin or a member with
edit on its module, who can edit it first, approve or refuse it, and let
the agent take that class of action on its own with a cap per day. A
rotation after a leak revokes the old keys and withdraws everything
allowed. All of it is in the audit log.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 10:54:53 -07:00
co-authored by Claude Opus 5.5
parent bfb74e7700
commit 311d2e815b
17 changed files with 1396 additions and 13 deletions
+15 -1
View File
@@ -29,12 +29,26 @@
</tbody>
</table>
<div class="actions">
<form class="inline" method="post" action="/settings/agents/{{$a.ID}}/rotate"><button type="submit" class="secondary">Rotate the key</button></form>
<form class="inline row" method="post" action="/settings/agents/{{$a.ID}}/rotate"><button type="submit" class="secondary">Rotate the key</button>
<label class="check small"><input type="checkbox" name="leaked"> It leaked: stop the old keys now, and withdraw what it may do on its own</label></form>
<form class="inline row" method="post" action="/settings/agents/{{$a.ID}}/new-key"><label class="small">Expires <input type="date" name="expires"></label><button type="submit" class="secondary">Add a key</button></form>
</div>
<p class="help"><strong>Rotate</strong> makes a new key; the old one keeps working for a day, so whatever uses it can be switched over. After a leak, <strong>revoke</strong> it instead: it stops at once.</p>
</section>
<section class="card" id="allowed">
<h2>On its own</h2>
{{if .Allowed}}
<p class="help">What {{$a.Name}} may do without asking, approved on the Approvals page. Everything else it asks for waits there for a person.</p>
<table class="list"><tbody>{{range .Allowed}}<tr>
<td>{{.Label}}</td><td>{{if .DailyCap}}up to {{.DailyCap}} a day{{else}}no cap{{end}}</td><td>{{ago .Granted}}{{with by .GrantedBy}} {{.}}{{end}}</td>
<td><form class="inline" method="post" action="/approvals/allowed/withdraw"><input type="hidden" name="agent" value="{{.Agent}}"><input type="hidden" name="class" value="{{.Class}}"><button type="submit" class="secondary small">Withdraw</button></form></td>
</tr>{{end}}</tbody></table>
{{else}}<p class="help">Nothing: everything it asks to send out (posts, emails, mailing-list adds, changes to the sites) waits on <a href="/approvals">Approvals</a> for a person.</p>{{end}}
{{if .Asked}}<h3>Lately</h3>
<ul class="small">{{range .Asked}}<li>{{.Summary}}: {{if eq .Status "waiting"}}waiting{{else if eq .Status "refused"}}refused{{else if eq .Status "failed"}}failed{{else if .OnItsOwn}}done on its own{{else}}approved{{end}}, {{ago .Created}}</li>{{end}}</ul>{{end}}
</section>
<section class="card">
<div class="actions">
{{if eq $a.Status "disabled"}}
+67
View File
@@ -0,0 +1,67 @@
{{define "content"}}{{with .Data}}
<div class="page-head">
<h1>Approvals</h1>
<p class="lede">What agents ask to send out of Supermarket: posts, emails, mailing-list adds, changes to the sites. Nothing goes until a person approves it, unless that kind of action has been allowed on its own. Edit it first if you like.</p>
</div>
{{if .Waiting}}
{{range .Waiting}}{{$req := .}}
<form class="card approval" method="post" action="/approvals/{{.ID}}/approve" id="r-{{.ID}}">
<p class="meta"><strong>{{.Agent}}</strong> <span class="pill">agent</span> asks to: <strong>{{.Summary}}</strong> · {{ago .Created}}</p>
{{with .Draft}}
{{if eq .Channel "reddit"}}<label class="small">Title <input name="title" value="{{.Title}}" maxlength="300"></label>
<p class="small muted">r/{{.Target}}</p>{{end}}
<textarea name="content" rows="{{if eq .Channel "x"}}5{{else}}10{{end}}" data-count="{{.Channel}}" data-limit="{{.Limit}}" data-reserve="{{if eq .Channel "x"}}{{xreserve .SourceURL}}{{else}}0{{end}}">{{.Content}}</textarea>
{{with .SourceURL}}<p class="small">Source: <a href="{{.}}" target="_blank" rel="noopener noreferrer">{{.}}</a></p>{{end}}
{{if $req.Accounts}}<label class="small inline-label">From
<select name="account">{{range $req.Accounts}}<option value="{{.ID}}" {{if eq (printf "post:%d" .ID) $req.Class}}selected{{end}}>{{.Label}}</option>{{end}}</select></label>
{{else}}<p class="warn-text small">You can't post to any account for this channel: an admin can let you (Settings → Posting accounts).</p>{{end}}
{{if not $req.At.IsZero}}<p class="small">To go out {{$req.At.Local.Format "Mon 2 Jan 2006, 15:04"}} (or at once, if that's passed).</p>{{end}}
{{end}}
{{with .Message}}
<p class="small">To <strong>{{.Contact.Name}}</strong> &lt;{{.To}}&gt;{{with .Company}} at {{.}}{{end}}</p>
<label class="small">Subject <input name="subject" value="{{.Subject}}"></label>
<textarea name="body" rows="10">{{.Body}}</textarea>
{{end}}
{{with .Change}}
<p class="small">{{.Page}}</p>
<label class="small">Title <input name="title" value="{{.NewTitle}}"></label>
<label class="small">Description <textarea name="description" rows="3">{{.NewDescription}}</textarea></label>
{{end}}
<div class="actions">
<button type="submit">Approve</button>
<button type="submit" class="secondary danger" formaction="/approvals/{{.ID}}/refuse">Refuse</button>
</div>
<label class="check small"><input type="checkbox" name="trust"> <span>And let {{.Agent}} {{.ClassLabel}} on its own from now on, up to <input name="cap" type="number" min="0" value="5" size="3" class="tiny"> a day (0: no cap)</span></label>
</form>
{{end}}
{{else}}
<section class="card empty"><p>Nothing waiting for you.</p></section>
{{end}}
{{if .Allowed}}
<section class="card">
<h2>What agents may do on their own</h2>
<table class="list">
<thead><tr><th>Agent</th><th>May</th><th>Cap</th><th>Since</th><th></th></tr></thead>
<tbody>{{range .Allowed}}<tr>
<td>{{.Agent}}</td><td>{{.Label}}</td><td>{{if .DailyCap}}{{.DailyCap}} a day{{else}}none{{end}}</td><td>{{ago .Granted}}{{with by .GrantedBy}} {{.}}{{end}}</td>
<td>{{if .Mine}}<form class="inline" method="post" action="/approvals/allowed/withdraw"><input type="hidden" name="agent" value="{{.Grant.Agent}}"><input type="hidden" name="class" value="{{.Class}}"><button type="submit" class="secondary small">Withdraw</button></form>{{end}}</td>
</tr>{{end}}</tbody>
</table>
</section>
{{end}}
{{if .Recent}}
<section class="card">
<h2>Decided</h2>
<table class="list">
<thead><tr><th>When</th><th>Agent</th><th>Asked to</th><th>Outcome</th></tr></thead>
<tbody>{{range .Recent}}<tr>
<td>{{ago .Decided}}</td><td>{{.Agent}}</td><td>{{.Summary}}</td>
<td>{{if eq .Status "refused"}}Refused{{with by .DecidedBy}} {{.}}{{end}}{{else if eq .Status "failed"}}<span class="error-text">Failed</span>: {{truncate 120 .Result}}{{else if .OnItsOwn}}Done on its own{{with .Result}}: {{truncate 120 .}}{{end}}{{else}}Approved{{with by .DecidedBy}} {{.}}{{end}}{{with .Result}}: {{truncate 120 .}}{{end}}{{end}}</td>
</tr>{{end}}</tbody>
</table>
</section>
{{end}}
{{end}}{{end}}
+1
View File
@@ -35,6 +35,7 @@
</form>
<nav class="nav" aria-label="Main">
<a href="/" {{if eq .Nav "home"}}aria-current="page"{{end}}>{{template "icon" "overview"}}<span>Overview</span></a>
<a href="/approvals" {{if eq .Nav "approvals"}}aria-current="page"{{end}}>{{template "icon" "ai"}}<span>Approvals</span>{{with .Approvals}} <span class="count-badge" title="{{.}} waiting for you">{{.}}</span>{{end}}</a>
{{if .Can "market"}}<a href="/market" {{if eq .Nav "inventory"}}aria-current="page"{{end}}>{{template "icon" "inventory"}}<span>Market</span></a>{{end}}
{{if .Modules}}<div class="nav-label">Modules</div>{{end}}
+1 -1
View File
@@ -10,7 +10,7 @@
<thead><tr><th>Person</th>{{range .Accounts}}<th>{{.Label}}<br><span class="muted small">{{if eq .Owner 0}}the company's{{else}}{{index $d.Owners .Owner}}'s own{{end}}{{if not (index $d.Working .ID)}} · not working{{end}}</span></th>{{end}}</tr></thead>
<tbody>
{{range $p := .People}}<tr>
<td>{{if .Name}}{{.Name}}{{else}}{{.Email}}{{end}}<br><span class="muted small">{{if .Admin}}admin{{else if .Can "content" true}}member{{else}}no Content: can't post{{end}}</span></td>
<td>{{if .Name}}{{.Name}}{{else}}{{.Email}}{{end}}<br><span class="muted small">{{if eq .Kind "agent"}}agent{{if not (.Can "content" true)}}, without Content: can't post{{end}}{{else if .Admin}}admin{{else if .Can "content" true}}member{{else}}no Content: can't post{{end}}</span></td>
{{range $a := $d.Accounts}}<td>
{{if $p.Admin}}<input type="checkbox" checked disabled title="Admins may post to every account">
{{else if eq $a.Owner $p.ID}}<input type="checkbox" checked disabled title="Their own account">