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
+8 -1
View File
@@ -11,6 +11,7 @@ import (
"github.com/andydixon/noema/internal/auth"
"github.com/andydixon/noema/internal/beliefs"
"github.com/andydixon/noema/internal/minds"
"github.com/andydixon/noema/internal/motivation"
"github.com/andydixon/noema/internal/storage"
"github.com/andydixon/noema/pkg/ids"
)
@@ -102,7 +103,13 @@ func (u *UI) mindOverview(w http.ResponseWriter, r *http.Request) {
ms, _ := u.deps.Memory.Stats(r.Context(), m.ID)
bs, _ := u.deps.Beliefs.Stats(r.Context(), m.ID)
top, _ := u.deps.Beliefs.List(r.Context(), m.ID, beliefs.Filter{Limit: 8})
u.render(w, r, "mind", m.DisplayName, map[string]any{"Mind": m, "Brief": m.Personality.Brief(), "SelfModel": sm, "Stats": st, "MemStats": ms, "BeliefStats": bs, "Beliefs": top})
motiv, _ := u.deps.Motivation.Load(r.Context(), u.deps.DB, m)
motivation.Decay(&motiv, motivation.Baselines(m.Personality), time.Since(motiv.Affect.UpdatedAt))
active, _ := u.deps.Goals.Active(r.Context(), m.ID)
if len(active) > 6 {
active = active[:6]
}
u.render(w, r, "mind", m.DisplayName, map[string]any{"Mind": m, "Brief": m.Personality.Brief(), "SelfModel": sm, "Stats": st, "MemStats": ms, "BeliefStats": bs, "Beliefs": top, "Motiv": motiv, "Goals": active})
}
func (u *UI) mindStatus(w http.ResponseWriter, r *http.Request) {
+146
View File
@@ -0,0 +1,146 @@
package ui
import (
"net/http"
"strconv"
"strings"
"time"
"github.com/andydixon/noema/internal/auth"
"github.com/andydixon/noema/internal/goals"
"github.com/andydixon/noema/internal/predictions"
"github.com/andydixon/noema/pkg/ids"
)
func (u *UI) motivationRoutes(m *http.ServeMux) {
m.Handle("GET /minds/{mind}/goals", u.require(auth.RoleObserver, u.goalsPage))
m.Handle("POST /minds/{mind}/goals", u.require(auth.RoleOperator, u.goalCreate))
m.Handle("POST /minds/{mind}/goals/{id}", u.require(auth.RoleOperator, u.goalUpdate))
m.Handle("GET /minds/{mind}/predictions", u.require(auth.RoleObserver, u.predictionsPage))
m.Handle("POST /minds/{mind}/predictions", u.require(auth.RoleOperator, u.predictionCreate))
m.Handle("POST /minds/{mind}/predictions/{id}/resolve", u.require(auth.RoleOperator, u.predictionResolve))
m.Handle("POST /minds/{mind}/state/reset", u.require(auth.RoleOperator, u.stateReset))
}
func (u *UI) goalsPage(w http.ResponseWriter, r *http.Request) {
m, ok := u.mind(w, r)
if !ok {
return
}
list, _ := u.deps.Goals.List(r.Context(), m.ID, nil, 0)
st, _ := u.deps.Goals.Stats(r.Context(), m.ID)
u.render(w, r, "goals", m.DisplayName+" · Goals", map[string]any{"Mind": m, "Goals": list, "Stats": st})
}
func (u *UI) goalCreate(w http.ResponseWriter, r *http.Request) {
m, ok := u.mind(w, r)
if !ok {
return
}
r.ParseForm() //nolint:errcheck
prio, _ := strconv.ParseFloat(r.PostFormValue("priority"), 64)
var parent ids.ID
if v := r.PostFormValue("parent_id"); v != "" {
parent, _ = ids.Parse(v)
}
if _, err := u.goalF(r, goals.New{MindID: m.ID, ParentID: parent, Title: r.PostFormValue("title"), Description: r.PostFormValue("description"), Kind: goals.Kind(r.PostFormValue("kind")), Priority: prio, Subject: r.PostFormValue("subject")}); err != nil {
u.flash(w, r, "error", err.Error(), "/minds/"+m.Slug+"/goals")
return
}
u.flash(w, r, "ok", "Goal created.", "/minds/"+m.Slug+"/goals")
}
func (u *UI) goalUpdate(w http.ResponseWriter, r *http.Request) {
m, ok := u.mind(w, r)
if !ok {
return
}
id, err := ids.Parse(r.PathValue("id"))
if err != nil {
u.flash(w, r, "error", "Bad goal.", "/minds/"+m.Slug+"/goals")
return
}
r.ParseForm() //nolint:errcheck
var up goals.Update
switch r.PostFormValue("action") {
case "progress":
p, _ := strconv.ParseFloat(r.PostFormValue("progress"), 64)
up.Progress = &p
case "complete":
st := goals.StatusCompleted
up.Status = &st
case "abandon":
st := goals.StatusAbandoned
up.Status = &st
}
if _, err := u.goalUpdF(r, m.ID, id, up); err != nil {
u.flash(w, r, "error", err.Error(), "/minds/"+m.Slug+"/goals")
return
}
u.flash(w, r, "ok", "Goal updated.", "/minds/"+m.Slug+"/goals")
}
func (u *UI) predictionsPage(w http.ResponseWriter, r *http.Request) {
m, ok := u.mind(w, r)
if !ok {
return
}
list, _ := u.deps.Predictions.List(r.Context(), m.ID, nil, 200)
stats, _ := u.deps.Predictions.Stats(r.Context(), m.ID)
cal, _ := u.deps.Predictions.Calibrate(r.Context(), m.ID, time.Now().Add(-90*24*time.Hour))
u.render(w, r, "predictions", m.DisplayName+" · Predictions", map[string]any{"Mind": m, "Predictions": list, "Stats": stats, "Calibration": cal})
}
func (u *UI) predictionCreate(w http.ResponseWriter, r *http.Request) {
m, ok := u.mind(w, r)
if !ok {
return
}
r.ParseForm() //nolint:errcheck
conf, _ := strconv.ParseFloat(r.PostFormValue("confidence"), 64)
hours, _ := strconv.Atoi(r.PostFormValue("hours"))
if hours <= 0 {
hours = 24
}
var terms []string
for _, t := range strings.Split(r.PostFormValue("terms"), ",") {
if t = strings.TrimSpace(t); t != "" {
terms = append(terms, t)
}
}
crit := predictions.Criteria{Kind: r.PostFormValue("kind"), Expect: r.PostFormValue("expect"), Terms: terms}
if _, err := u.predF(r, predictions.New{MindID: m.ID, Statement: r.PostFormValue("statement"), Confidence: conf, WindowEnd: time.Now().Add(time.Duration(hours) * time.Hour), Criteria: crit}); err != nil {
u.flash(w, r, "error", err.Error(), "/minds/"+m.Slug+"/predictions")
return
}
u.flash(w, r, "ok", "Prediction recorded.", "/minds/"+m.Slug+"/predictions")
}
func (u *UI) predictionResolve(w http.ResponseWriter, r *http.Request) {
m, ok := u.mind(w, r)
if !ok {
return
}
id, err := ids.Parse(r.PathValue("id"))
if err != nil {
u.flash(w, r, "error", "Bad prediction.", "/minds/"+m.Slug+"/predictions")
return
}
if _, err := u.resolveF(r, m.ID, id, predictions.Status(r.PostFormValue("outcome")), "resolved in the UI"); err != nil {
u.flash(w, r, "error", err.Error(), "/minds/"+m.Slug+"/predictions")
return
}
u.flash(w, r, "ok", "Prediction resolved.", "/minds/"+m.Slug+"/predictions")
}
func (u *UI) stateReset(w http.ResponseWriter, r *http.Request) {
m, ok := u.mind(w, r)
if !ok {
return
}
if _, err := u.resetF(r, m.ID); err != nil {
u.flash(w, r, "error", err.Error(), "/minds/"+m.Slug)
return
}
u.flash(w, r, "ok", "Drives and affect reset to baseline.", "/minds/"+m.Slug)
}
+53 -12
View File
@@ -22,8 +22,11 @@ import (
"github.com/andydixon/noema/internal/auth"
"github.com/andydixon/noema/internal/beliefs"
"github.com/andydixon/noema/internal/conversation"
"github.com/andydixon/noema/internal/goals"
"github.com/andydixon/noema/internal/llm"
"github.com/andydixon/noema/internal/minds"
"github.com/andydixon/noema/internal/motivation"
"github.com/andydixon/noema/internal/predictions"
"github.com/andydixon/noema/internal/version"
"github.com/andydixon/noema/pkg/concepts"
"github.com/andydixon/noema/pkg/ids"
@@ -32,16 +35,38 @@ import (
// UI holds handlers and the parsed template set.
type UI struct {
deps app.Deps
pages map[string]*template.Template
static fs.FS
statusF func(r *http.Request) any // system status provider injected by api
ctxF func(r *http.Request, id ids.ID) (api.EventContext, error) // event forensic context, shared with api
wsF func(r *http.Request, m minds.Mind) (api.WorkspaceView, error)
memF func(r *http.Request, mind, id ids.ID) (api.MemoryDetail, error)
belF func(r *http.Request, mind, id ids.ID) (api.BeliefDetail, error)
emitF func() beliefs.Emitter
postF func(r *http.Request, mind ids.ID, conv conversation.Conversation, text, who string) (conversation.Message, error)
deps app.Deps
pages map[string]*template.Template
static fs.FS
statusF func(r *http.Request) any // system status provider injected by api
ctxF func(r *http.Request, id ids.ID) (api.EventContext, error) // event forensic context, shared with api
wsF func(r *http.Request, m minds.Mind) (api.WorkspaceView, error)
memF func(r *http.Request, mind, id ids.ID) (api.MemoryDetail, error)
belF func(r *http.Request, mind, id ids.ID) (api.BeliefDetail, error)
emitF func() beliefs.Emitter
postF func(r *http.Request, mind ids.ID, conv conversation.Conversation, text, who string) (conversation.Message, error)
goalF func(r *http.Request, n goals.New) (goals.Goal, error)
goalUpdF func(r *http.Request, mind, id ids.ID, u goals.Update) (goals.Goal, error)
predF func(r *http.Request, n predictions.New) (predictions.Prediction, error)
resolveF func(r *http.Request, mind, id ids.ID, outcome predictions.Status, reason string) (predictions.Result, error)
resetF func(r *http.Request, mind ids.ID) (motivation.State, error)
}
// Actions groups the server-side operations the UI delegates to the API layer
// so both surfaces share one implementation and one audit path.
type Actions struct {
Status func(r *http.Request) any
Context func(r *http.Request, id ids.ID) (api.EventContext, error)
Workspace func(r *http.Request, m minds.Mind) (api.WorkspaceView, error)
Memory func(r *http.Request, mind, id ids.ID) (api.MemoryDetail, error)
Belief func(r *http.Request, mind, id ids.ID) (api.BeliefDetail, error)
Emitter func() beliefs.Emitter
Post func(r *http.Request, mind ids.ID, conv conversation.Conversation, text, who string) (conversation.Message, error)
Goal func(r *http.Request, n goals.New) (goals.Goal, error)
GoalUpdate func(r *http.Request, mind, id ids.ID, u goals.Update) (goals.Goal, error)
Predict func(r *http.Request, n predictions.New) (predictions.Prediction, error)
Resolve func(r *http.Request, mind, id ids.ID, outcome predictions.Status, reason string) (predictions.Result, error)
ResetState func(r *http.Request, mind ids.ID) (motivation.State, error)
}
// View is the data passed to every template.
@@ -62,7 +87,7 @@ const flashCookie = "noema_flash"
// New parses templates. In development, when ./web exists on disk, templates
// and static files are read from disk so edits show without a rebuild.
func New(deps app.Deps, statusF func(r *http.Request) any, ctxF func(r *http.Request, id ids.ID) (api.EventContext, error), wsF func(r *http.Request, m minds.Mind) (api.WorkspaceView, error), memF func(r *http.Request, mind, id ids.ID) (api.MemoryDetail, error), belF func(r *http.Request, mind, id ids.ID) (api.BeliefDetail, error), emitF func() beliefs.Emitter, postF func(r *http.Request, mind ids.ID, conv conversation.Conversation, text, who string) (conversation.Message, error)) (*UI, error) {
func New(deps app.Deps, a Actions) (*UI, error) {
tmplFS, staticFS := web.Templates(), web.Static()
if !deps.Config.Production() {
if st, err := os.Stat("web/templates"); err == nil && st.IsDir() {
@@ -70,7 +95,7 @@ func New(deps app.Deps, statusF func(r *http.Request) any, ctxF func(r *http.Req
deps.Log.Info("ui: serving templates and static files from ./web (development)")
}
}
u := &UI{deps: deps, static: staticFS, statusF: statusF, ctxF: ctxF, wsF: wsF, memF: memF, belF: belF, emitF: emitF, postF: postF}
u := &UI{deps: deps, static: staticFS, statusF: a.Status, ctxF: a.Context, wsF: a.Workspace, memF: a.Memory, belF: a.Belief, emitF: a.Emitter, postF: a.Post, goalF: a.Goal, goalUpdF: a.GoalUpdate, predF: a.Predict, resolveF: a.Resolve, resetF: a.ResetState}
if err := u.parse(tmplFS); err != nil {
return nil, err
}
@@ -123,6 +148,21 @@ func (u *UI) parse(fsys fs.FS) error {
"relations": func() []concepts.Relation { return concepts.AllRelations },
"llmRoles": func() []llm.RoleInfo { return llm.Roles },
"pretty": prettyRaw,
"affectMap": func(a motivation.Affect) map[string]float64 {
return map[string]float64{"valence": a.Valence, "arousal": a.Arousal, "curiosity": a.Curiosity, "concern": a.Concern, "frustration": a.Frustration, "confidence": a.Confidence, "uncertainty": a.Uncertainty, "engagement": a.Engagement, "task_pressure": a.TaskPressure, "load": a.Load}
},
"valencePos": func(v float64) float64 {
if v < 0 {
return 0.5 + v/2
}
return 0.5
},
"valenceWidth": func(v float64) float64 {
if v < 0 {
return -v / 2
}
return v / 2
},
"deref_id": func(id *ids.ID) ids.ID {
if id == nil {
return ids.Nil
@@ -301,6 +341,7 @@ func (u *UI) Register(m *http.ServeMux) {
u.beliefRoutes(m)
u.llmRoutes(m)
u.conversationRoutes(m)
u.motivationRoutes(m)
for _, p := range []struct{ path, title, note string }{
{"/approvals", "Approvals", "The approval centre arrives with the capability system."},