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:
@@ -280,8 +280,11 @@ func scan(row pgx.Row) (Belief, error) {
|
||||
return b, nil
|
||||
}
|
||||
|
||||
// Get fetches a belief scoped to a mind.
|
||||
// Get fetches a belief scoped to a mind. A nil q reads from the pool.
|
||||
func (s *Store) Get(ctx context.Context, q storage.Querier, mind, id ids.ID) (Belief, error) {
|
||||
if q == nil {
|
||||
q = s.db
|
||||
}
|
||||
return scan(q.QueryRow(ctx, `SELECT `+cols+` FROM beliefs b WHERE b.id=$1 AND b.mind_id=$2`, id, mind))
|
||||
}
|
||||
|
||||
@@ -341,8 +344,11 @@ func (s *Store) List(ctx context.Context, mind ids.ID, f Filter) ([]Belief, erro
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
// EvidenceFor returns all evidence rows of a belief.
|
||||
// EvidenceFor returns all evidence rows of a belief. A nil q reads from the pool.
|
||||
func (s *Store) EvidenceFor(ctx context.Context, q storage.Querier, mind, id ids.ID) ([]EvidenceRow, error) {
|
||||
if q == nil {
|
||||
q = s.db
|
||||
}
|
||||
rows, err := q.Query(ctx, `SELECT id, direction, kind, ref_id, source, weight, credibility, retracted, note, event_id, created_at FROM belief_evidence WHERE belief_id=$1 AND mind_id=$2 ORDER BY created_at`, id, mind)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user