feat: add mind model with versioned personality, templates and self-model
Phase 2. Minds are rows with a slug, status (active/disabled/archived), cognitive configuration and a pointer to the current personality version. Personalities are structured (identity, values, traits, communication, behaviour, free text) with a deterministic Brief() used by prompts and the editor preview. Every change appends a personality_versions row protected by the append-only trigger; restore copies an old version forward. Templates carry reusable personalities; minds record their overrides so a template can be re-applied without losing mind-specific edits. The self-model starts with structural limitations the mind cannot drop (no policy changes, no influence over shutdown, no cross-mind access). API, UI (list, overview, editor with sliders/diff/history/import/export, template editor) and noemactl mind/template commands. All mutations are audited with field-level diffs.
This commit is contained in:
@@ -40,6 +40,9 @@ type command struct {
|
||||
|
||||
var commands []command
|
||||
|
||||
// extraCommands are registered by other files in this package via init.
|
||||
var extraCommands []command
|
||||
|
||||
func main() {
|
||||
commands = []command{
|
||||
{"status", "show daemon status", cmdStatus},
|
||||
@@ -47,6 +50,7 @@ func main() {
|
||||
{"user", "create <username> [-role r] – manage users (offline)", cmdUser},
|
||||
{"version", "print version", func([]string) int { fmt.Println(version.Version); return exitOK }},
|
||||
}
|
||||
commands = append(commands, extraCommands...)
|
||||
if len(os.Args) < 2 || os.Args[1] == "-h" || os.Args[1] == "--help" || os.Args[1] == "help" {
|
||||
usage()
|
||||
os.Exit(exitUsage)
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
)
|
||||
|
||||
func init() {
|
||||
extraCommands = append(extraCommands,
|
||||
command{"mind", "list|create|inspect|clone|personality – manage minds", cmdMind},
|
||||
command{"template", "list – personality templates", cmdTemplate},
|
||||
)
|
||||
}
|
||||
|
||||
func cmdMind(args []string) int {
|
||||
if len(args) < 1 {
|
||||
fmt.Fprintln(os.Stderr, "usage: noemactl mind list|create <slug>|inspect <mind>|clone <mind> <new-slug>|personality <mind>")
|
||||
return exitUsage
|
||||
}
|
||||
switch args[0] {
|
||||
case "list":
|
||||
fs := flag.NewFlagSet("mind list", flag.ContinueOnError)
|
||||
all := fs.Bool("all", false, "include archived")
|
||||
asJSON := fs.Bool("json", false, "raw JSON")
|
||||
if fs.Parse(args[1:]) != nil {
|
||||
return exitUsage
|
||||
}
|
||||
var out struct{ Items []map[string]any }
|
||||
q := ""
|
||||
if *all {
|
||||
q = "?include_archived=true"
|
||||
}
|
||||
if code, err := apiRequest("GET", "/api/v1/minds"+q, nil, &out); err != nil {
|
||||
return exitFor(code, err)
|
||||
}
|
||||
if *asJSON {
|
||||
json.NewEncoder(os.Stdout).Encode(out.Items) //nolint:errcheck
|
||||
return exitOK
|
||||
}
|
||||
tw := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
|
||||
fmt.Fprintln(tw, "SLUG\tNAME\tSTATUS\tPERSONALITY\tID")
|
||||
for _, m := range out.Items {
|
||||
fmt.Fprintf(tw, "%v\t%v\t%v\tv%v\t%v\n", m["slug"], m["display_name"], m["status"], m["personality_version"], m["id"])
|
||||
}
|
||||
tw.Flush()
|
||||
return exitOK
|
||||
case "create":
|
||||
fs := flag.NewFlagSet("mind create", flag.ContinueOnError)
|
||||
name := fs.String("name", "", "display name")
|
||||
if len(args) < 2 || fs.Parse(args[2:]) != nil {
|
||||
fmt.Fprintln(os.Stderr, "usage: noemactl mind create <slug> [-name display]")
|
||||
return exitUsage
|
||||
}
|
||||
var m map[string]any
|
||||
if code, err := apiRequest("POST", "/api/v1/minds", map[string]any{"slug": args[1], "display_name": *name}, &m); err != nil {
|
||||
return exitFor(code, err)
|
||||
}
|
||||
fmt.Printf("created mind %v (%v)\n", m["slug"], m["id"])
|
||||
return exitOK
|
||||
case "inspect":
|
||||
if len(args) < 2 {
|
||||
fmt.Fprintln(os.Stderr, "usage: noemactl mind inspect <mind>")
|
||||
return exitUsage
|
||||
}
|
||||
var m map[string]any
|
||||
if code, err := apiRequest("GET", "/api/v1/minds/"+args[1], nil, &m); err != nil {
|
||||
return exitFor(code, err)
|
||||
}
|
||||
var sm map[string]any
|
||||
apiRequest("GET", "/api/v1/minds/"+args[1]+"/selfmodel", nil, &sm) //nolint:errcheck
|
||||
enc := json.NewEncoder(os.Stdout)
|
||||
enc.SetIndent("", " ")
|
||||
enc.Encode(map[string]any{"mind": m, "self_model": sm}) //nolint:errcheck
|
||||
return exitOK
|
||||
case "clone":
|
||||
if len(args) < 3 {
|
||||
fmt.Fprintln(os.Stderr, "usage: noemactl mind clone <mind> <new-slug>")
|
||||
return exitUsage
|
||||
}
|
||||
var m map[string]any
|
||||
if code, err := apiRequest("POST", "/api/v1/minds/"+args[1]+"/clone", map[string]any{"slug": args[2]}, &m); err != nil {
|
||||
return exitFor(code, err)
|
||||
}
|
||||
fmt.Printf("cloned into %v (%v)\n", m["slug"], m["id"])
|
||||
return exitOK
|
||||
case "personality":
|
||||
if len(args) < 2 {
|
||||
fmt.Fprintln(os.Stderr, "usage: noemactl mind personality <mind>")
|
||||
return exitUsage
|
||||
}
|
||||
var b map[string]string
|
||||
if code, err := apiRequest("GET", "/api/v1/minds/"+args[1]+"/personality/brief", nil, &b); err != nil {
|
||||
return exitFor(code, err)
|
||||
}
|
||||
fmt.Print(b["brief"])
|
||||
return exitOK
|
||||
}
|
||||
fmt.Fprintln(os.Stderr, "unknown mind subcommand", args[0])
|
||||
return exitUsage
|
||||
}
|
||||
|
||||
func cmdTemplate(args []string) int {
|
||||
var out struct{ Items []map[string]any }
|
||||
if code, err := apiRequest("GET", "/api/v1/personality-templates", nil, &out); err != nil {
|
||||
return exitFor(code, err)
|
||||
}
|
||||
tw := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
|
||||
fmt.Fprintln(tw, "NAME\tDESCRIPTION\tID")
|
||||
for _, t := range out.Items {
|
||||
fmt.Fprintf(tw, "%v\t%v\t%v\n", t["name"], t["description"], t["id"])
|
||||
}
|
||||
tw.Flush()
|
||||
return exitOK
|
||||
}
|
||||
+2
-1
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/andydixon/noema/internal/audit"
|
||||
"github.com/andydixon/noema/internal/auth"
|
||||
"github.com/andydixon/noema/internal/config"
|
||||
"github.com/andydixon/noema/internal/minds"
|
||||
"github.com/andydixon/noema/internal/observability"
|
||||
"github.com/andydixon/noema/internal/scheduler"
|
||||
"github.com/andydixon/noema/internal/storage"
|
||||
@@ -73,7 +74,7 @@ func run() error {
|
||||
metrics := observability.NewMetrics()
|
||||
authSvc := auth.NewService(db, cfg.SessionIdleTTL, cfg.SessionAbsoluteTTL)
|
||||
auditLog := audit.New(db, log)
|
||||
deps := app.Deps{Config: cfg, Log: log, DB: db, Auth: authSvc, Audit: auditLog, Metrics: metrics, Migrations: migrations.FS, Started: time.Now()}
|
||||
deps := app.Deps{Config: cfg, Log: log, DB: db, Auth: authSvc, Audit: auditLog, Metrics: metrics, Minds: minds.NewStore(db), Migrations: migrations.FS, Started: time.Now()}
|
||||
|
||||
if err := bootstrapAdmin(ctx, deps); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user