Files
noema/web/templates/pages/mind.html
T
Andy Dixon 703d080d13 feat: add metacognition, reflection, consolidation, narrative and notifications
Phase 10. Metacognition is a cognitive process with deterministic
self-checks (insufficient evidence, single-source reliance, model output
without evidence, repeated failed hypotheses, stale contradictions,
calibration overconfidence); its warnings compete for attention and,
when admitted, add counter-evidence or open an investigation goal.

Reflection reviews the period since the last run (prediction errors,
rejected beliefs, corrections, status changes, completed goals,
contradictions, calibration), turns repeated failures into procedural
lessons written once, and records a reflection event; a model may only
word the prose within the mind's budget.

Consolidation clusters unconsolidated episodes by shared stemmed terms,
creates a belief whose confidence is computed from the episodes as
evidence and a semantic memory linked to each episode by derived_from,
and records jobs with inputs and outputs. Wording may come from the
consolidate prompt within a per-run model budget; the job says which.
Operators can run, pause and reject; originals are never touched.

The narrative hook keeps a five-part first-person narrative built from
state and stored with narrative_updated events. The notification hook
applies explicit thresholded rules, aggregates repeats within a cooldown
and records suppressions with reasons. A scheduled job runs
consolidation and reflection per mind, switching the runtime mode while
it works. API, Background tab, notifications page with unread badge,
overview narrative and warnings, CLI commands, docs/cognition.md.
2026-06-28 22:19:38 +01:00

112 lines
7.6 KiB
HTML

{{define "content"}}
{{$m := .Data.Mind}}
<div class="pagehead mindhead">
<div><h1>{{$m.DisplayName}} <span class="muted mono small">{{$m.Slug}}</span></h1>
<p class="muted">{{$m.Personality.Identity.Role}}{{with $m.Personality.Identity.Description}} · {{.}}{{end}}</p></div>
<div class="row">{{template "status_badge" $m.Status}}</div>
</div>
{{template "mind_tabs" (dict "M" $m "Active" "overview")}}
<section class="grid cols-3">
<div class="card">
<h2>Identity</h2>
<dl class="kv">
<dt>Name</dt><dd>{{$m.Personality.Identity.Name}}</dd>
<dt>Role</dt><dd>{{$m.Personality.Identity.Role}}</dd>
{{with $m.Personality.Identity.Pronouns}}<dt>Pronouns</dt><dd>{{.}}</dd>{{end}}
<dt>Created</dt><dd>{{date $m.CreatedAt}}</dd>
<dt>Personality</dt><dd>v{{$m.PersonalityVersion}} {{if $m.TemplateID}}<span class="badge accent">templated</span>{{end}} · <a href="/minds/{{$m.Slug}}/personality">edit</a></dd>
{{if $m.ClonedFromMind}}<dt>Cloned from</dt><dd class="mono small">{{$m.ClonedFromMind}}</dd>{{end}}
{{with $m.Notes}}<dt>Notes</dt><dd>{{.}}</dd>{{end}}
</dl>
</div>
<div class="card">
<h2>Internal narrative <span class="muted small">{{if .Data.Narrative.UpdatedAt.IsZero}}{{else}}{{ago .Data.Narrative.UpdatedAt}}{{end}}</span></h2>
<div class="narrative">{{.Data.Narrative.Text}}</div>
{{if .Data.Warnings}}<h3>Metacognitive warnings</h3><ul class="plain small warnlist">{{range .Data.Warnings}}<li><span class="badge warn">{{index .Metadata "check"}}</span> <a href="/events/{{.ID}}">{{.Summary}}</a> <span class="muted">{{ago .OccurredAt}}</span></li>{{end}}</ul>{{end}}
</div>
<div class="card">
<h2>Recent activity</h2>
{{$st := .Data.Stats}}
<div class="stat-value small">{{$st.Total}} <span class="muted small">events in 24h</span></div>
<div class="cats small">{{range $k, $v := $st.ByCategory}}<span class="etype cat-{{$k}}">{{$k}} {{$v}}</span> {{end}}</div>
<p class="small"><a href="/minds/{{$m.Slug}}/thoughts">Open thought stream</a> · <a href="/minds/{{$m.Slug}}/memory">{{.Data.MemStats.Total}} memories</a>{{range $k, $v := .Data.MemStats.ByKind}} <span class="badge k-{{$k}}">{{$k}} {{$v}}</span>{{end}}</p>
{{if .Principal.User.Role.AtLeast "operator"}}
<form method="post" action="/minds/{{$m.Slug}}/observe" class="stack" style="margin-top:.75rem">
<input type="hidden" name="_csrf" value="{{.CSRF}}">
<label>Inject observation <span class="muted small">as operator</span> <textarea name="text" rows="2" maxlength="20000" placeholder="e.g. server-01 reported SMART CRC errors at 09:12" required></textarea></label>
<div><button class="btn small" type="submit">Observe</button></div>
</form>{{end}}
</div>
<div class="card">
<h2>Cognitive configuration</h2>
<dl class="kv">
<dt>Workspace capacity</dt><dd>{{$m.Config.WorkspaceCapacity}}</dd>
<dt>Working memory</dt><dd>{{$m.Config.WorkingMemoryCapacity}} items · decay {{$m.Config.WorkingMemoryDecay}}</dd>
<dt>Cycle interval</dt><dd>{{$m.Config.CycleMinInterval}} min · {{$m.Config.IdleCycleInterval}} idle · max {{$m.Config.MaxCyclesPerMinute}}/min</dd>
<dt>LLM per cycle</dt><dd>{{$m.Config.LLMCallsPerCycle}} calls · {{$m.Config.DailyTokenBudget}} tokens/day</dd>
</dl>
</div>
</section>
<section class="grid cols-2">
{{template "state_panel" (dict "State" .Data.Motiv "Mind" $m "CSRF" .CSRF "CanOperate" (.Principal.User.Role.AtLeast "operator"))}}
<div class="card">
<h2>Active goals <span class="muted small"><a href="/minds/{{$m.Slug}}/goals">all</a></span></h2>
{{if .Data.Goals}}<table class="table compact"><tbody>{{range .Data.Goals}}<tr><td><span class="badge gs-{{.Status}}">{{.Status}}</span></td><td>{{.Title}}<div class="muted small">{{.Kind}} · priority {{conf .Priority}}</div></td><td><span class="conf"><span class="conf-bar"><i style="width:{{pct .Progress}}"></i></span></span></td></tr>{{end}}</tbody></table>{{else}}<p class="muted small">No active goals.</p>{{end}}
</div>
</section>
<section class="grid cols-2">
<div class="card">
<h2>Important beliefs <span class="muted small"><a href="/minds/{{$m.Slug}}/beliefs">{{.Data.BeliefStats.Total}} total</a></span></h2>
{{if .Data.Beliefs}}<table class="table compact"><tbody>{{range .Data.Beliefs}}<tr><td><span class="badge st-{{.Status}}">{{.Status}}</span></td><td><a href="/minds/{{$m.Slug}}/beliefs/{{.ID}}">{{.Proposition}}</a></td><td class="num"><span class="conf"><span class="conf-bar"><i style="width:{{pct .Confidence}}"></i></span> {{conf .Confidence}}</span></td></tr>{{end}}</tbody></table>
{{else}}<p class="muted small">No beliefs yet.</p>{{end}}
</div>
</section>
<section class="grid cols-2">
<div class="card">
<h2>Personality brief <span class="muted small">what cognitive prompts receive</span></h2>
<pre class="brief">{{.Data.Brief}}</pre>
</div>
<div class="card">
<h2>Self-model</h2>
{{$sm := .Data.SelfModel}}
<h3>Capabilities</h3>
{{if $sm.Capabilities}}<ul class="plain">{{range $sm.Capabilities}}<li><code>{{.Name}}</code> <span class="badge {{if eq .Policy "allow"}}ok{{else if eq .Policy "ask"}}warn{{else}}danger{{end}}">{{.Policy}}</span> <span class="muted small">{{.Description}}</span></li>{{end}}</ul>
{{else}}<p class="muted small">No capabilities granted. This mind cannot act on external systems.</p>{{end}}
<h3>Known limitations</h3>
<ul class="small">{{range $sm.Limitations}}<li>{{.}}</li>{{end}}</ul>
{{if $sm.KnowledgeGaps}}<h3>Knowledge gaps</h3><ul class="small">{{range $sm.KnowledgeGaps}}<li>{{.}}</li>{{end}}</ul>{{end}}
<p class="muted small">Updated {{ago $sm.UpdatedAt}}</p>
</div>
</section>
{{if .Principal.User.Role.AtLeast "administrator"}}
<section class="grid cols-2">
<div class="card">
<h2>Lifecycle</h2>
<form method="post" action="/minds/{{$m.Slug}}/status" class="row">
<input type="hidden" name="_csrf" value="{{.CSRF}}">
{{if ne $m.Status "active"}}<button class="btn" name="status" value="active">Enable</button>{{end}}
{{if eq $m.Status "active"}}<button class="btn" name="status" value="disabled" data-confirm="Disable {{$m.DisplayName}}? Cognition stops; history is kept.">Disable</button>{{end}}
{{if ne $m.Status "archived"}}<button class="btn btn-danger" name="status" value="archived" data-confirm="Archive {{$m.DisplayName}}? It is hidden from lists but nothing is deleted.">Archive</button>{{end}}
</form>
<p class="muted small">Cognitive history is never hard-deleted by these actions.</p>
<form method="post" action="/minds/{{$m.Slug}}/notes" class="stack">
<input type="hidden" name="_csrf" value="{{.CSRF}}">
<label>Operator notes <textarea name="notes" rows="2">{{$m.Notes}}</textarea></label>
<div><button class="btn small" type="submit">Save notes</button></div>
</form>
</div>
<div class="card">
<h2>Clone</h2>
<p class="muted small">Same personality and configuration, fresh experience. Forking with memories arrives with snapshots.</p>
<form method="post" action="/minds/{{$m.Slug}}/clone" class="stack">
<input type="hidden" name="_csrf" value="{{.CSRF}}">
<label>New slug <input name="slug" required pattern="[a-z0-9][a-z0-9-]{0,62}" placeholder="{{$m.Slug}}-experiment"></label>
<label>Display name <input name="display_name"></label>
<div><button class="btn" type="submit">Clone</button></div>
</form>
</div>
</section>
{{end}}
{{end}}
{{define "status_badge"}}{{if eq . "active"}}<span class="badge ok">active</span>{{else if eq . "disabled"}}<span class="badge warn">disabled</span>{{else}}<span class="badge">archived</span>{{end}}{{end}}