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:
Andy Dixon
2026-06-28 22:19:38 +01:00
parent 9eb873cbe6
commit 703d080d13
38 changed files with 2321 additions and 26 deletions
+94
View File
@@ -0,0 +1,94 @@
package main
import (
"fmt"
"os"
)
func init() {
extraCommands = append(extraCommands,
command{"narrative", "<mind> – current internal narrative", cmdNarrative},
command{"consolidate", "<mind> – run consolidation now", cmdConsolidate},
command{"reflect", "<mind> – run reflection now", cmdReflect},
command{"notifications", "list [-mind m]|read-all – notifications", cmdNotifications},
)
}
func cmdNarrative(args []string) int {
if len(args) < 1 {
fmt.Fprintln(os.Stderr, "usage: noemactl narrative <mind>")
return exitUsage
}
var n map[string]any
if code, err := apiRequest("GET", "/api/v1/minds/"+args[0]+"/narrative", nil, &n); err != nil {
return exitFor(code, err)
}
fmt.Println(n["text"])
return exitOK
}
func cmdConsolidate(args []string) int {
if len(args) < 1 {
fmt.Fprintln(os.Stderr, "usage: noemactl consolidate <mind>")
return exitUsage
}
var j map[string]any
if code, err := apiRequest("POST", "/api/v1/minds/"+args[0]+"/consolidation/run", map[string]any{}, &j); err != nil {
return exitFor(code, err)
}
fmt.Printf("consolidation %v: %v cluster(s), %v generalisation(s)\n", j["status"], j["clusters"], j["produced"])
if outs, ok := j["outputs"].([]any); ok {
for _, o := range outs {
om, _ := o.(map[string]any)
fmt.Printf(" %.2f %v (%v episodes, %v)\n", num(om["confidence"]), om["proposition"], len(om["episodes"].([]any)), om["wording"])
}
}
return exitOK
}
func cmdReflect(args []string) int {
if len(args) < 1 {
fmt.Fprintln(os.Stderr, "usage: noemactl reflect <mind>")
return exitUsage
}
var r map[string]any
if code, err := apiRequest("POST", "/api/v1/minds/"+args[0]+"/reflections/run", map[string]any{}, &r); err != nil {
return exitFor(code, err)
}
fmt.Println(r["prose"])
return exitOK
}
func cmdNotifications(args []string) int {
if len(args) < 1 {
fmt.Fprintln(os.Stderr, "usage: noemactl notifications list [-mind m] | read-all")
return exitUsage
}
switch args[0] {
case "list":
path := "/api/v1/notifications"
if len(args) >= 3 && args[1] == "-mind" {
path = "/api/v1/minds/" + args[2] + "/notifications"
}
var out struct {
Items []map[string]any
Unread int
}
if code, err := apiRequest("GET", path, nil, &out); err != nil {
return exitFor(code, err)
}
for _, n := range out.Items {
fmt.Printf("%-6v %-5v ×%v %v — %v [%v]\n", n["level"], n["status"], n["count"], n["title"], n["body"], n["rule"])
}
fmt.Printf("(%d unread)\n", out.Unread)
return exitOK
case "read-all":
var res map[string]any
if code, err := apiRequest("POST", "/api/v1/notifications/read-all", map[string]any{}, &res); err != nil {
return exitFor(code, err)
}
fmt.Println("marked", res["marked"])
return exitOK
}
return exitUsage
}