Phase 11, part 1: agents and their keys

Agents are users of kind agent, each given modules to read, or to read
and act on, and the CRM scope. Admins make them under Settings → Agents,
on every edition; keys (sm_…) are shown once and kept as hashes, can
expire, be rotated (the old one works a day) or revoked, and record their
last use. /mcp takes agent keys and offers each agent only the tools its
scopes allow. On the local edition, mcp-token is the key of a built-in
Hermes agent with the CRM and the Market.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 10:26:31 -07:00
co-authored by Claude Opus 5.5
parent da16736fb4
commit da2d56f8d2
19 changed files with 1323 additions and 138 deletions
+17
View File
@@ -0,0 +1,17 @@
{{define "content"}}{{template "settings-start" .}}{{with .Data}}
<p><a href="/settings/agents/{{.Agent.ID}}">← {{.Agent.Name}}</a></p>
<h2>{{if eq .Why "rotated"}}{{.Agent.Name}}'s new key{{else}}{{.Agent.Name}}'s key{{end}}</h2>
<section class="card">
<p><strong>Copy it now: it isn't shown again.</strong> Only a hash of it is kept.</p>
<pre id="key">{{.Key}}</pre>
<button type="button" class="secondary" data-copy="key">Copy</button>
{{if eq .Why "rotated"}}<p class="help">The old key keeps working for another day; switch whatever uses it to this one.</p>{{end}}
{{if .Hermes}}<p class="help">It's also in <code>mcp-token</code> in the data folder now. Hermes itself uses the socket and needs nothing; Claude Code's setup needs the new key: <code>claude mcp remove supermarket</code>, then add it again as below.</p>{{end}}
</section>
<section class="card">
<h2>Using it</h2>
<p>An MCP client reaches <code>{{.MCPURL}}</code> (streamable HTTP) with the header <code>Authorization: Bearer &lt;key&gt;</code>. For Claude Code:</p>
<pre id="claude">claude mcp add --transport http supermarket {{.MCPURL}} --header "Authorization: Bearer {{.Key}}"</pre>
<button type="button" class="secondary small" data-copy="claude">Copy</button>
</section>
{{end}}{{template "settings-end"}}{{end}}
+49
View File
@@ -0,0 +1,49 @@
{{define "content"}}{{template "settings-start" .}}{{with .Data}}{{$d := .}}{{$a := .Row}}
<p><a href="/settings/agents">← Agents</a></p>
<h2>{{$a.Name}}{{if $a.BuiltIn}} <span class="pill">built in</span>{{end}}{{if eq $a.Status "disabled"}} <span class="pill">turned off</span>{{end}}</h2>
{{with .Problem}}<p class="error" role="alert">{{.}}</p>{{end}}
<form class="card" method="post" action="/settings/agents/{{$a.ID}}/save">
<label>Name <input name="name" value="{{$a.Name}}" required></label>
<label>What it's for <textarea name="description" rows="2">{{$a.Description}}</textarea></label>
{{template "agent-scopes" (dict "Scopes" $a.Modules "Grants" .Grants)}}
<button type="submit">Save</button>
</form>
<section class="card" id="keys">
<h2>Keys</h2>
<table class="list">
<thead><tr><th>Key</th><th>Made</th><th>Expires</th><th>Last used</th><th></th></tr></thead>
<tbody>
{{range $a.Keys}}<tr>
<td><code>{{.Prefix}}…</code>
{{if not .Revoked.IsZero}} <span class="pill">revoked {{ago .Revoked}}</span>
{{else if not (.Working $d.Now)}} <span class="pill">stopped</span>
{{else if not .Retires.IsZero}} <span class="pill warn">replaced: works until {{.Retires.Local.Format "2 Jan 15:04"}}</span>
{{else}} <span class="pill ok">working</span>{{end}}</td>
<td>{{.Created.Local.Format "2 Jan 2006"}}</td>
<td>{{if .Expires.IsZero}}<span class="muted">never</span>{{else}}{{.Expires.Local.Format "2 Jan 2006"}}{{end}}</td>
<td>{{if .Used.IsZero}}<span class="muted">never</span>{{else}}{{ago .Used}}{{with .UsedFrom}} <span class="muted small">from {{.}}</span>{{end}}{{end}}</td>
<td>{{if .Working $d.Now}}<form class="inline" method="post" action="/settings/agents/{{$a.ID}}/revoke" data-confirm="Revoke this key? Whatever uses it stops at once."><input type="hidden" name="key" value="{{.ID}}"><button type="submit" class="secondary small danger">Revoke</button></form>{{end}}</td>
</tr>{{else}}<tr><td colspan="5" class="muted">No keys.</td></tr>{{end}}
</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}}/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">
<div class="actions">
{{if eq $a.Status "disabled"}}
<form class="inline" method="post" action="/settings/agents/{{$a.ID}}/enable"><button type="submit" class="secondary">Turn it back on</button></form>
{{else}}
<form class="inline" method="post" action="/settings/agents/{{$a.ID}}/disable"><button type="submit" class="secondary danger">Turn it off</button></form>
{{end}}
{{if not $a.BuiltIn}}<form class="inline" method="post" action="/settings/agents/{{$a.ID}}/remove" data-confirm="Remove {{$a.Name}} and its keys for good?"><button type="submit" class="danger">Remove</button></form>{{end}}
</div>
<p class="help">Turned off, none of its keys work, until it's turned back on.</p>
</section>
{{end}}{{template "settings-end"}}{{end}}
+33
View File
@@ -0,0 +1,33 @@
{{define "content"}}{{template "settings-start" .}}{{with .Data}}{{$d := .}}
<h2>Agents</h2>
<p class="lede">Programs that use Supermarket over MCP, each with its own key, given modules to read, or to read and act on. Agents reach <code>{{.MCPURL}}</code> with <code>Authorization: Bearer &lt;key&gt;</code>.</p>
{{if .Rows}}
<section class="card">
<table class="list">
<thead><tr><th>Agent</th><th>May</th><th>Keys</th><th>Last used</th></tr></thead>
<tbody>
{{range .Rows}}<tr>
<td><a href="/settings/agents/{{.ID}}">{{.Name}}</a>{{if .BuiltIn}} <span class="pill">built in</span>{{end}}{{if eq .Status "disabled"}} <span class="pill">turned off</span>{{end}}{{with .Description}}<br><span class="muted small">{{truncate 120 .}}</span>{{end}}</td>
<td>{{.Access}}</td>
<td>{{if .Working}}{{.Working}} working{{else}}<span class="warn-text">none working</span>{{end}}</td>
<td>{{with .Last}}{{ago .Used}}{{with .UsedFrom}} <span class="muted small">from {{.}}</span>{{end}}{{else}}<span class="muted">never</span>{{end}}</td>
</tr>{{end}}
</tbody>
</table>
</section>
{{end}}
<form class="card" method="post" action="/settings/agents" id="new">
<h2>New agent</h2>
{{with .Problem}}<p class="error" role="alert">{{.}}</p>{{end}}
<div class="cols">
<label>Name <input name="name" value="{{.Form.Name}}" required placeholder="e.g. Morning writer"></label>
<label>Key expires <span class="muted">(optional)</span> <input type="date" name="expires" value="{{.Form.Expires}}"></label>
</div>
<label>What it's for <textarea name="description" rows="2" placeholder="e.g. Drafts posts from What to write next, every morning">{{.Form.Description}}</textarea></label>
{{template "agent-scopes" (dict "Scopes" .Form.Scopes "Grants" .Grants)}}
<p class="help">Its key is shown once, after this. Only a hash of it is kept.</p>
<button type="submit">Create the agent</button>
</form>
{{end}}{{template "settings-end"}}{{end}}
+17
View File
@@ -146,6 +146,7 @@
<a href="/settings/profile" {{if eq .Nav "settings/profile"}}aria-current="page"{{end}}>{{template "icon" "profile"}}Profile</a>
<div class="nav-label">Connections</div>
<a href="/settings/connections" {{if eq .Nav "settings/connections"}}aria-current="page"{{end}}>{{template "icon" "core"}}All connections</a>
<a href="/settings/agents" {{if eq .Nav "settings/agents"}}aria-current="page"{{end}}>{{template "icon" "ai"}}Agents</a>
<a href="/settings/posting" {{if eq .Nav "settings/posting"}}aria-current="page"{{end}}>{{template "icon" "accounts"}}Posting accounts</a>
<a href="/settings/accounts" {{if eq .Nav "settings/accounts"}}aria-current="page"{{end}}>{{template "icon" "accounts"}}Social accounts</a>
<a href="/settings/core" {{if eq .Nav "settings/core"}}aria-current="page"{{end}}>{{template "icon" "core"}}Core &amp; Hermes</a>
@@ -278,6 +279,22 @@
</section>
{{end}}
{{/* An agent's scopes: {{template "agent-scopes" (dict "Scopes" … "Grants" …)}} */}}
{{define "agent-scopes"}}{{$sc := .Scopes}}
<fieldset class="access">
<legend>May</legend>
<table class="list access-grid"><tbody>
{{range .Grants}}{{$a := print (index $sc .ID)}}<tr>
<td>{{.Name}}</td>
<td><label class="check"><input type="radio" name="scope:{{.ID}}" value="" {{if eq $a ""}}checked{{end}}> Nothing</label></td>
<td><label class="check"><input type="radio" name="scope:{{.ID}}" value="read" {{if eq $a "view"}}checked{{end}}> Read</label></td>
<td><label class="check"><input type="radio" name="scope:{{.ID}}" value="act" {{if eq $a "edit"}}checked{{end}}> Read and act</label></td>
</tr>{{end}}
</tbody></table>
<p class="help"><em>Read and act</em> lets it change things, such as writing drafts. Anything that leaves Supermarket (a post, an email, a site push) waits for a person's approval (Phase 11, part 3).</p>
</fieldset>
{{end}}
{{/* Users (Settings → Users, and one user's page). */}}
{{define "user-status"}}{{if eq .Status "invited"}}{{if .InviteEnd.IsZero}}<span class="pill warn">Invitation expired</span>{{else}}<span class="pill">Invited</span> <span class="muted small">until {{.InviteEnd.Local.Format "2 Jan"}}</span>{{end}}{{else if eq .Status "disabled"}}<span class="pill">Turned off</span>{{else if .Locked}}<span class="pill warn">Locked</span>{{else}}<span class="pill ok">Active</span>{{if .TwoFactor}} <span class="muted small">two-factor</span>{{end}}{{end}}{{end}}