Files
noema/cmd/noemactl/workspace.go
T
Andy Dixon e9c1b25c80 feat: implement global workspace, working memory and the cognitive cycle
Phase 4 (ADR-0001). internal/attention scores thought candidates as a
normalised weighted sum over ten named features with a per-term
breakdown, ranked by (score, id) so ordering is total and replayable.
internal/workspace holds the capacity-limited workspace (refresh by
subject, decayed competition, explained admit/reject outcomes) and the
decaying working memory.

internal/brain runs one runtime per active mind: debounced wake-ups from
the event bus (own output never re-triggers), a settle window so
concurrently committing events are not skipped, bounded concurrent
Observe calls with per-process isolation and timeouts, deterministic
scoring, a loop detector that suppresses recurring thoughts and raises a
metacognition warning, executive dispatch by thought kind, and one
transaction per cycle whose events are published only after commit.
Every candidate, selection, attention shift and broadcast is an event
with provenance back to the triggering observation. Operators can run a
cycle, pause, resume, reset transient state and change attention
weights live; the manager reconciles runtimes with mind status.

cognition/attend is the first process: deterministic candidates from
external events using an urgency lexicon, novelty against context and
trust-based operator priority.
2026-06-18 22:54:07 +01:00

70 lines
2.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package main
import (
"encoding/json"
"fmt"
"os"
)
func init() {
extraCommands = append(extraCommands, command{"workspace", "show <mind>|cycle <mind>|pause <mind>|resume <mind>|reset <mind> – workspace and cognition control", cmdWorkspace})
}
func cmdWorkspace(args []string) int {
if len(args) < 2 {
fmt.Fprintln(os.Stderr, "usage: noemactl workspace show|cycle|pause|resume|reset <mind>")
return exitUsage
}
mind := args[1]
var v struct {
Running bool `json:"running"`
State struct {
Cycle int64 `json:"cycle"`
Mode string `json:"mode"`
Workspace []map[string]any `json:"workspace"`
WorkingMemory []map[string]any `json:"working_memory"`
} `json:"state"`
Candidates []map[string]any `json:"last_candidates"`
}
var code int
var err error
switch args[0] {
case "show":
code, err = apiRequest("GET", "/api/v1/minds/"+mind+"/workspace", nil, &v)
case "cycle":
code, err = apiRequest("POST", "/api/v1/minds/"+mind+"/cycle", map[string]any{}, &v)
case "pause":
code, err = apiRequest("POST", "/api/v1/minds/"+mind+"/mode", map[string]any{"mode": "paused"}, &v)
case "resume":
code, err = apiRequest("POST", "/api/v1/minds/"+mind+"/mode", map[string]any{"mode": "awake"}, &v)
case "reset":
code, err = apiRequest("POST", "/api/v1/minds/"+mind+"/reset", map[string]any{"workspace": true, "working_memory": true, "loops": true}, &v)
default:
fmt.Fprintln(os.Stderr, "unknown workspace subcommand", args[0])
return exitUsage
}
if err != nil {
return exitFor(code, err)
}
if len(args) > 2 && args[2] == "-json" {
json.NewEncoder(os.Stdout).Encode(v) //nolint:errcheck
return exitOK
}
fmt.Printf("mode: %s cycle: %d running: %v\n\nworkspace (%d):\n", v.State.Mode, v.State.Cycle, v.Running, len(v.State.Workspace))
for i, t := range v.State.Workspace {
fmt.Printf(" %d. [%.2f ×%.2f] %s (%s/%s)\n", i+1, num(t["score"]), num(t["activation"]), t["summary"], t["process"], t["kind"])
}
fmt.Printf("\nworking memory (%d):\n", len(v.State.WorkingMemory))
for _, it := range v.State.WorkingMemory {
fmt.Printf(" [%.2f] %s (%s)\n", num(it["activation"]), it["content"], it["kind"])
}
if len(v.Candidates) > 0 {
fmt.Printf("\nlast cycle candidates (%d):\n", len(v.Candidates))
for _, c := range v.Candidates {
md, _ := c["metadata"].(map[string]any)
fmt.Printf(" %-10v %.2f %s\n", md["fate"], num(c["salience"]), c["summary"])
}
}
return exitOK
}