feat: add goals, drives, affect state, predictions and curiosity

Phase 9. Goals form a mind-scoped tree with kind, priority, progress and
blockers; their deterministic relevance to a candidate feeds the
goal_relevance attention feature and a goal monitor raises stalled goals
and observations that touch one. Drives are a closed set of eight
scalars with operator-configured ranges and personality-derived
baselines; there is no self-preservation, replication or acquisition
drive and no way to add one at runtime. Affect is ten scalars moved by an
explicit rule table over events and decaying towards baseline; both
modulate attention weights each cycle and the effective weights are
recorded with every cycle and shown beside the configured ones.

Predictions carry a window and machine-checkable criteria (event terms
occurring or staying absent, a belief reaching a confidence, or operator
judgement). A resolver job judges them deterministically, keeps an
append-only outcome history for calibration (accuracy, Brier score,
confidence buckets, overconfidence flag), emits prediction_error events
scaled by how confident the miss was, and feeds the outcome back into the
linked belief as evidence. Causal hypotheses derive predictions
automatically. Curiosity turns misses, contradictions and unexplained
observations into questions that compete for attention and become
investigation goals when admitted.

Brain gains after-cycle hooks and goal/motivation state. API, UI (goals,
prediction dashboard, cognitive state panel, effective weights) and CLI
(goal, prediction, state). Demo scenario 4 verified end to end.
This commit is contained in:
Andy Dixon
2026-06-27 20:41:03 +01:00
parent 777e8f50b5
commit 9eb873cbe6
39 changed files with 3053 additions and 50 deletions
+11
View File
@@ -190,3 +190,14 @@ ol.messages { list-style: none; padding: 0; margin: 0 0 1rem; display: flex; fle
.msg-head { margin-bottom: .2rem; }
.chat-input input { min-width: 0; }
.badge.small { font-size: .65rem; }
/* Goals, predictions, state */
.badge.gs-active { background: var(--accent-soft); color: var(--accent); } .badge.gs-blocked { background: var(--warn-soft); color: var(--warn); } .badge.gs-completed { background: var(--ok-soft); color: var(--ok); } .badge.gs-abandoned, .badge.gs-paused { background: var(--surface-2); color: var(--muted); }
.badge.ps-open { background: var(--accent-soft); color: var(--accent); } .badge.ps-confirmed { background: var(--ok-soft); color: var(--ok); } .badge.ps-refuted { background: var(--danger-soft); color: var(--danger); } .badge.ps-expired, .badge.ps-withdrawn { background: var(--surface-2); color: var(--muted); }
.cal { position: relative; width: 140px; height: 10px; background: var(--surface-2); border-radius: 3px; }
.cal-bar { position: absolute; left: 0; top: 0; height: 100%; background: var(--accent-soft); border-radius: 3px; }
.cal-hit { position: absolute; top: -3px; width: 3px; height: 16px; background: var(--accent); margin-left: -1px; }
.dim { display: grid; grid-template-columns: 8rem 1fr 6rem; align-items: center; gap: .5rem; font-size: .85rem; margin: .2rem 0; }
.dim-bar { position: relative; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; } .dim-bar i { position: absolute; top: 0; height: 100%; background: var(--accent); left: 0; }
.dim-bar.bipolar::after { content: ""; position: absolute; left: 50%; top: 0; width: 1px; height: 100%; background: var(--muted); }
.dim-val { font-variant-numeric: tabular-nums; color: var(--muted); }
+37
View File
@@ -0,0 +1,37 @@
{{define "content"}}
{{$m := .Data.Mind}}
<div class="pagehead mindhead"><div><h1>{{$m.DisplayName}} <span class="muted small">goals</span></h1><p class="muted">{{range $k, $v := .Data.Stats.ByStatus}}<span class="badge gs-{{$k}}">{{$k}} {{$v}}</span> {{end}} Goals bias attention through goal relevance; they never grant capabilities.</p></div></div>
{{template "mind_tabs" (dict "M" $m "Active" "goals")}}
<section class="grid cols-3-1">
<div class="card">
{{if .Data.Goals}}
<table class="table compact">
<thead><tr><th>Goal</th><th>Kind</th><th>Status</th><th class="num">Priority</th><th>Progress</th><th>Owner</th><th>Progress at</th>{{if .Principal.User.Role.AtLeast "operator"}}<th></th>{{end}}</tr></thead>
<tbody>{{range .Data.Goals}}<tr>
<td>{{if .ParentID}}<span class="muted">↳ </span>{{end}}<strong>{{.Title}}</strong>{{if .Description}}<div class="small muted">{{.Description}}</div>{{end}}{{if .Blockers}}<div class="small danger">blocked: {{range .Blockers}}{{.}}; {{end}}</div>{{end}}{{if .OriginEvent}} <a class="small" href="/events/{{.OriginEvent}}">origin</a>{{end}}</td>
<td class="small">{{.Kind}}</td><td><span class="badge gs-{{.Status}}">{{.Status}}</span></td><td class="num">{{conf .Priority}}</td>
<td><span class="conf"><span class="conf-bar"><i style="width:{{pct .Progress}}"></i></span> {{pct .Progress}}</span></td><td class="small muted">{{.Owner}}</td><td class="small muted nowrap">{{ago .LastProgressAt}}</td>
{{if $.Principal.User.Role.AtLeast "operator"}}<td class="nowrap"><form method="post" action="/minds/{{$m.Slug}}/goals/{{.ID}}" class="inline"><input type="hidden" name="_csrf" value="{{$.CSRF}}">
<input type="number" name="progress" min="0" max="1" step="0.1" value="{{.Progress}}" size="3" aria-label="progress"><button class="btn small" name="action" value="progress">Set</button>
{{if ne .Status "completed"}}<button class="btn small" name="action" value="complete">Done</button>{{end}}{{if ne .Status "abandoned"}}<button class="btn small btn-danger" name="action" value="abandon" data-confirm="Abandon this goal?">Abandon</button>{{end}}</form></td>{{end}}
</tr>{{end}}</tbody>
</table>
{{else}}<p class="muted">No goals yet. Curiosity creates investigation goals from unexplained observations, prediction errors and contradictions; operators can set task goals here.</p>{{end}}
</div>
{{if .Principal.User.Role.AtLeast "operator"}}
<div class="card">
<h2>New goal</h2>
<form method="post" action="/minds/{{$m.Slug}}/goals" class="stack">
<input type="hidden" name="_csrf" value="{{.CSRF}}">
<label>Title <input name="title" required maxlength="300"></label>
<label>Description <textarea name="description" rows="2"></textarea></label>
<div class="grid cols-2 tight"><label>Kind <select name="kind"><option value="task">task</option><option value="investigation">investigation</option><option value="question">question</option><option value="maintenance">maintenance</option></select></label>
<label>Subject <input name="subject" placeholder="atlas" maxlength="80"></label></div>
<label class="slider"><span>Priority</span><input type="range" name="priority" min="0.1" max="1" step="0.1" value="0.5" data-out><output>0.5</output></label>
<label>Parent <select name="parent_id"><option value="">none</option>{{range .Data.Goals}}{{if eq .Status "active"}}<option value="{{.ID}}">{{trunc .Title 50}}</option>{{end}}{{end}}</select></label>
<div><button class="btn btn-primary" type="submit">Create</button></div>
</form>
</div>
{{end}}
</section>
{{end}}
+7
View File
@@ -42,6 +42,13 @@
</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>
+50
View File
@@ -0,0 +1,50 @@
{{define "content"}}
{{$m := .Data.Mind}}{{$c := .Data.Calibration}}
<div class="pagehead mindhead"><div><h1>{{$m.DisplayName}} <span class="muted small">predictions</span></h1><p class="muted">Explicit expectations with windows and checkable criteria. Misses become prediction errors that lower the linked belief.</p></div></div>
{{template "mind_tabs" (dict "M" $m "Active" "predictions")}}
<section class="grid cols-4">
<div class="card stat"><div class="stat-label">Open</div><div class="stat-value">{{index .Data.Stats "open"}}</div></div>
<div class="card stat"><div class="stat-label">Accuracy</div><div class="stat-value">{{if $c.Total}}{{pct $c.Accuracy}}{{else}}—{{end}}</div><div class="muted small">{{$c.Confirmed}} confirmed · {{$c.Refuted}} refuted · {{$c.Expired}} expired (90 days)</div></div>
<div class="card stat"><div class="stat-label">Brier score</div><div class="stat-value">{{if $c.Total}}{{conf $c.Brier}}{{else}}—{{end}}</div><div class="muted small">0 is perfect, 0.25 is chance</div></div>
<div class="card stat"><div class="stat-label">Calibration</div><div class="stat-value small">{{if $c.Overconfident}}<span class="warn">overconfident</span>{{else if $c.Total}}<span class="ok">in range</span>{{else}}—{{end}}</div></div>
</section>
<section class="grid cols-3-1">
<div class="stack">
<div class="card">
<h2>Calibration by stated confidence</h2>
{{if $c.Total}}<table class="table compact"><thead><tr><th>Stated</th><th class="num">n</th><th class="num">Mean stated</th><th class="num">Actual hit rate</th><th>Gap</th></tr></thead>
<tbody>{{range $c.Buckets}}<tr><td>{{.Label}}</td><td class="num">{{.Count}}</td><td class="num">{{if .Count}}{{conf .MeanConf}}{{else}}—{{end}}</td><td class="num">{{if .Count}}{{conf .HitRate}}{{else}}—{{end}}</td>
<td>{{if .Count}}<div class="cal"><span class="cal-bar" style="width:{{pct .MeanConf}}"></span><span class="cal-hit" style="left:{{pct .HitRate}}"></span></div>{{end}}</td></tr>{{end}}</tbody></table>
<p class="muted small">Bar: mean stated confidence. Marker: fraction that came true. A well-calibrated mind has the marker at the end of the bar.</p>
{{else}}<p class="muted">No resolved predictions yet.</p>{{end}}
</div>
<div class="card">
<h2>Predictions</h2>
{{if .Data.Predictions}}<table class="table compact"><thead><tr><th>Status</th><th>Statement</th><th class="num">Conf</th><th>Window</th><th>Criteria</th><th></th></tr></thead>
<tbody>{{range .Data.Predictions}}<tr>
<td><span class="badge ps-{{.Status}}">{{.Status}}</span></td>
<td>{{.Statement}}<div class="small muted">{{.Source}}{{if .BeliefID}} · <a href="/minds/{{$m.Slug}}/beliefs/{{.BeliefID}}">belief</a>{{end}}{{if .OriginEvent}} · <a href="/events/{{.OriginEvent}}">origin</a>{{end}}{{if .Resolution}} · {{payloadField .Resolution "reason"}}{{end}}</div></td>
<td class="num">{{conf .Confidence}}</td><td class="small nowrap">{{.WindowStart.Local.Format "01-02 15:04"}} → {{.WindowEnd.Local.Format "01-02 15:04"}}</td>
<td class="small mono">{{.Criteria.Kind}}{{if .Criteria.Terms}} {{.Criteria.Expect}}: {{range .Criteria.Terms}}{{.}} {{end}}{{end}}</td>
<td class="nowrap">{{if and (eq .Status "open") ($.Principal.User.Role.AtLeast "operator")}}<form method="post" action="/minds/{{$m.Slug}}/predictions/{{.ID}}/resolve" class="inline"><input type="hidden" name="_csrf" value="{{$.CSRF}}"><button class="btn small" name="outcome" value="confirmed">✓</button><button class="btn small" name="outcome" value="refuted">✗</button><button class="btn small btn-ghost" name="outcome" value="withdrawn">withdraw</button></form>{{end}}</td>
</tr>{{end}}</tbody></table>
{{else}}<p class="muted">None yet. Causal hypotheses create predictions automatically; operators can add them here.</p>{{end}}
</div>
</div>
{{if .Principal.User.Role.AtLeast "operator"}}
<div class="card">
<h2>New prediction</h2>
<form method="post" action="/minds/{{$m.Slug}}/predictions" class="stack">
<input type="hidden" name="_csrf" value="{{.CSRF}}">
<label>Statement <textarea name="statement" rows="2" required maxlength="1000" placeholder="server-01 will remain healthy for 24 hours"></textarea></label>
<label class="slider"><span>Confidence</span><input type="range" name="confidence" min="0.05" max="0.95" step="0.05" value="0.7" data-out><output>0.7</output></label>
<label>Window (hours) <input type="number" name="hours" min="1" max="8760" value="24"></label>
<label>Criteria <select name="kind"><option value="event_match">event terms</option><option value="operator">operator judges</option></select></label>
<div class="grid cols-2 tight"><label>Expect <select name="expect"><option value="occurs">terms occur</option><option value="absent">terms stay absent</option></select></label>
<label>Terms <input name="terms" placeholder="server-01, fail" maxlength="200"></label></div>
<div><button class="btn btn-primary" type="submit">Predict</button></div>
</form>
</div>
{{end}}
</section>
{{end}}
+2 -1
View File
@@ -71,7 +71,8 @@
<h2>Attention weights <span class="muted small">per feature; score = Σ value×weight / Σ weight</span></h2>
<form method="post" action="/minds/{{$m.Slug}}/workspace/weights" class="stack">
<input type="hidden" name="_csrf" value="{{.CSRF}}">
<div class="weights">{{range $f := features}}<label>{{title $f}} <input type="number" name="w.{{$f}}" min="0" max="5" step="0.1" value="{{index $m.Config.AttentionWeights $f}}"></label>{{end}}</div>
<div class="weights">{{range $f := features}}<label>{{title $f}} <input type="number" name="w.{{$f}}" min="0" max="5" step="0.1" value="{{index $m.Config.AttentionWeights $f}}">{{with $st.EffectiveWeights}}<span class="muted small">effective {{conf (index . $f)}}</span>{{end}}</label>{{end}}</div>
<p class="muted small">Effective weights are the configured weights after drive and affect modulation in the last cycle.</p>
<div class="grid cols-2 tight">
<label>Workspace capacity <input type="number" name="workspace_capacity" min="1" max="32" value="{{$m.Config.WorkspaceCapacity}}"></label>
<label>Working memory capacity <input type="number" name="working_memory_capacity" min="1" max="64" value="{{$m.Config.WorkingMemoryCapacity}}"></label>
+14
View File
@@ -0,0 +1,14 @@
{{define "state_panel"}}{{$s := .State}}{{$m := .Mind}}
<div class="card">
<h2>Cognitive state <span class="muted small">scalars updated by rule; not a claim of feeling</span></h2>
<div class="grid cols-2 tight">
<div><h3>Affect</h3>
{{range $k, $v := (affectMap $s.Affect)}}<div class="dim"><span class="dim-name">{{title $k}}</span><span class="dim-bar {{if eq $k "valence"}}bipolar{{end}}"><i style="{{if eq $k "valence"}}left:{{pct (valencePos $v)}};width:{{pct (valenceWidth $v)}}{{else}}width:{{pct $v}}{{end}}"></i></span><span class="dim-val">{{conf $v}}</span></div>{{end}}
</div>
<div><h3>Drives</h3>
{{range $s.Drives}}<div class="dim"><span class="dim-name">{{title .Name}}</span><span class="dim-bar"><i style="width:{{pct .Value}}"></i></span><span class="dim-val">{{conf .Value}} <span class="muted">[{{conf .Min}}–{{conf .Max}}]</span></span></div>{{end}}
</div>
</div>
{{if .CanOperate}}<form method="post" action="/minds/{{$m.Slug}}/state/reset" class="row"><input type="hidden" name="_csrf" value="{{.CSRF}}"><button class="btn small" data-confirm="Reset drives and affect to their baselines?">Reset transient state</button></form>{{end}}
</div>
{{end}}