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.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
{{define "content"}}
|
||||
{{$m := .Data.Mind}}
|
||||
<div class="pagehead mindhead"><div><h1>{{$m.DisplayName}} <span class="muted small">consolidation & reflection</span></h1><p class="muted">Background cognition: generalising episodes into semantic memory, and reviewing recent mistakes. Both are scheduled, budgeted and inspectable.</p></div>
|
||||
<div class="row">{{if .Data.Paused}}<span class="badge warn">consolidation paused globally</span>{{end}}</div></div>
|
||||
{{template "mind_tabs" (dict "M" $m "Active" "consolidation")}}
|
||||
<section class="grid cols-2">
|
||||
<div class="card">
|
||||
<h2>Consolidation <span class="muted small">every {{$m.Config.ConsolidationInterval}} · min {{$m.Config.ConsolidationMinEpisodes}} episodes · {{$m.Config.ConsolidationLLMCalls}} model calls per run{{if not $m.Config.ConsolidationEnabled}} · <span class="danger">disabled</span>{{end}}</span></h2>
|
||||
{{if .Principal.User.Role.AtLeast "operator"}}<form method="post" action="/minds/{{$m.Slug}}/consolidation/run" class="row"><input type="hidden" name="_csrf" value="{{.CSRF}}"><button class="btn">Run consolidation now</button>
|
||||
{{if .Principal.User.Role.AtLeast "administrator"}}<button class="btn btn-ghost" formaction="/consolidation/pause" name="paused" value="{{if .Data.Paused}}0{{else}}1{{end}}">{{if .Data.Paused}}Resume scheduled runs{{else}}Pause scheduled runs{{end}}</button>{{end}}</form>{{end}}
|
||||
{{if .Data.Jobs}}<table class="table compact"><thead><tr><th>When</th><th>Status</th><th>Trigger</th><th class="num">Clusters</th><th class="num">Produced</th><th>Outputs</th></tr></thead>
|
||||
<tbody>{{range .Data.Jobs}}<tr><td class="small muted nowrap">{{ago .CreatedAt}}</td><td><span class="badge {{if eq .Status "done"}}ok{{else if eq .Status "failed"}}danger{{else}}warn{{end}}">{{.Status}}</span>{{with .Error}} <span class="small danger">{{.}}</span>{{end}}</td><td class="small">{{.Trigger}} {{.CreatedBy}}</td><td class="num">{{.Clusters}}</td><td class="num">{{.Produced}}</td>
|
||||
<td>{{range outputs .Outputs}}<div class="small"><a href="/minds/{{$m.Slug}}/memory/{{.MemoryID}}">{{trunc .Proposition 90}}</a> <span class="muted">({{conf .Confidence}}, {{len .Episodes}} episodes, {{.Wording}})</span>
|
||||
{{if $.Principal.User.Role.AtLeast "operator"}}<form method="post" action="/minds/{{$m.Slug}}/consolidation/reject" class="inline"><input type="hidden" name="_csrf" value="{{$.CSRF}}"><input type="hidden" name="memory_id" value="{{.MemoryID}}"><input name="reason" placeholder="why it is wrong" size="14"><button class="btn small btn-danger" data-confirm="Reject this generalisation? Episodes are kept.">reject</button></form>{{end}}</div>{{end}}</td></tr>{{end}}</tbody></table>
|
||||
{{else}}<p class="muted">No runs yet.</p>{{end}}
|
||||
</div>
|
||||
<div class="card">
|
||||
<h2>Reflection <span class="muted small">every {{$m.Config.ReflectionInterval}}{{if not $m.Config.ReflectionEnabled}} · <span class="danger">disabled</span>{{end}}</span></h2>
|
||||
{{if .Principal.User.Role.AtLeast "operator"}}<form method="post" action="/minds/{{$m.Slug}}/reflections/run" class="row"><input type="hidden" name="_csrf" value="{{.CSRF}}"><button class="btn">Reflect now</button></form>{{end}}
|
||||
{{range .Data.Reflections}}<div class="reflection"><div class="small muted">{{date .CreatedAt}} · {{.PeriodStart.Local.Format "01-02 15:04"}} → {{.PeriodEnd.Local.Format "01-02 15:04"}} {{if .LLMCallID}}· <span class="badge small">model prose</span>{{end}} {{if .EventID}}· <a href="/events/{{.EventID}}">event</a>{{end}}</div><pre class="brief">{{.Prose}}</pre></div>{{else}}<p class="muted">No reflections yet.</p>{{end}}
|
||||
</div>
|
||||
</section>
|
||||
{{end}}
|
||||
@@ -19,6 +19,11 @@
|
||||
{{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}}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
{{define "content"}}
|
||||
<div class="pagehead mindhead"><div><h1>Notifications</h1><p class="muted">What the minds decided warranted attention, and why. Repeats within the cooldown are aggregated.</p></div>
|
||||
{{if .Data.Items}}<form method="post" action="/notifications/read-all"><input type="hidden" name="_csrf" value="{{.CSRF}}"><button class="btn small">Mark all read</button></form>{{end}}</div>
|
||||
<div class="card">
|
||||
{{if .Data.Items}}<table class="table compact"><thead><tr><th>Level</th><th>Mind</th><th>Title</th><th>Reason</th><th class="num">×</th><th>When</th><th></th></tr></thead>
|
||||
<tbody>{{range .Data.Items}}<tr class="{{if eq .Status "new"}}unread{{end}}">
|
||||
<td><span class="badge nl-{{.Level}}">{{.Level}}</span></td><td class="small">{{index $.Data.MindNames .MindID}}</td>
|
||||
<td><strong>{{.Title}}</strong><div class="small muted">{{.Body}}</div></td>
|
||||
<td class="small"><code>{{.Rule}}</code> <span class="muted mono">{{printf "%s" .Reason}}</span></td>
|
||||
<td class="num">{{.Count}}</td><td class="small muted nowrap">{{ago .UpdatedAt}}</td>
|
||||
<td class="nowrap">{{if .SourceEvent}}<a class="small" href="/events/{{.SourceEvent}}">event</a>{{end}} {{if eq .Status "new"}}<form method="post" action="/notifications/{{.ID}}/read" class="inline"><input type="hidden" name="_csrf" value="{{$.CSRF}}"><button class="btn small btn-ghost">read</button></form>{{end}}</td>
|
||||
</tr>{{end}}</tbody></table>
|
||||
{{else}}<p class="muted">Nothing needs your attention.</p>{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
Reference in New Issue
Block a user