@timmeck/brain-core 2.22.0 → 2.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- export type ThoughtType = 'perceiving' | 'analyzing' | 'discovering' | 'hypothesizing' | 'experimenting' | 'dreaming' | 'reflecting' | 'correlating' | 'predicting' | 'responding' | 'focusing' | 'explaining';
1
+ export type ThoughtType = 'perceiving' | 'analyzing' | 'discovering' | 'hypothesizing' | 'experimenting' | 'dreaming' | 'reflecting' | 'correlating' | 'predicting' | 'responding' | 'focusing' | 'explaining' | 'exploring';
2
2
  export type ThoughtSignificance = 'routine' | 'notable' | 'breakthrough';
3
3
  export interface Thought {
4
4
  id: string;
@@ -0,0 +1,170 @@
1
+ import type Database from 'better-sqlite3';
2
+ import type { ThoughtStream } from '../consciousness/thought-stream.js';
3
+ import type { AttentionEngine } from '../attention/attention-engine.js';
4
+ import type { KnowledgeDistiller } from '../research/knowledge-distiller.js';
5
+ import type { HypothesisEngine } from '../hypothesis/engine.js';
6
+ import type { ExperimentEngine } from '../research/experiment-engine.js';
7
+ import type { ResearchAgendaEngine } from '../research/agenda-engine.js';
8
+ import type { NarrativeEngine } from '../narrative/narrative-engine.js';
9
+ export interface CuriosityEngineConfig {
10
+ brainName: string;
11
+ /** UCB1 exploration constant (higher = more exploration). Default: 1.41 (√2) */
12
+ explorationConstant?: number;
13
+ /** Minimum cycles between re-exploring same topic. Default: 5 */
14
+ exploreCooldown?: number;
15
+ /** Max questions per topic. Default: 10 */
16
+ maxQuestionsPerTopic?: number;
17
+ /** Gap score threshold to consider a topic a knowledge gap. Default: 0.6 */
18
+ gapThreshold?: number;
19
+ }
20
+ export interface CuriosityDataSources {
21
+ attentionEngine?: AttentionEngine;
22
+ knowledgeDistiller?: KnowledgeDistiller;
23
+ hypothesisEngine?: HypothesisEngine;
24
+ experimentEngine?: ExperimentEngine;
25
+ agendaEngine?: ResearchAgendaEngine;
26
+ narrativeEngine?: NarrativeEngine;
27
+ }
28
+ export interface KnowledgeGap {
29
+ id?: number;
30
+ topic: string;
31
+ attentionScore: number;
32
+ knowledgeScore: number;
33
+ gapScore: number;
34
+ gapType: GapType;
35
+ questions: string[];
36
+ discoveredAt: string;
37
+ addressedAt: string | null;
38
+ explorationCount: number;
39
+ }
40
+ export type GapType = 'dark_zone' | 'shallow' | 'contradictory' | 'stale' | 'unexplored';
41
+ export interface CuriosityQuestion {
42
+ id?: number;
43
+ topic: string;
44
+ question: string;
45
+ questionType: QuestionType;
46
+ priority: number;
47
+ answered: boolean;
48
+ answer: string | null;
49
+ askedAt: string;
50
+ answeredAt: string | null;
51
+ }
52
+ export type QuestionType = 'what' | 'why' | 'how' | 'correlation' | 'prediction' | 'comparison';
53
+ export interface ExplorationRecord {
54
+ id?: number;
55
+ topic: string;
56
+ action: 'explore' | 'exploit';
57
+ reward: number;
58
+ context: string;
59
+ timestamp: string;
60
+ }
61
+ export interface BanditArm {
62
+ topic: string;
63
+ pulls: number;
64
+ totalReward: number;
65
+ averageReward: number;
66
+ ucbScore: number;
67
+ lastPulled: number | null;
68
+ }
69
+ export interface CuriosityStatus {
70
+ totalGaps: number;
71
+ activeGaps: number;
72
+ totalQuestions: number;
73
+ unansweredQuestions: number;
74
+ totalExplorations: number;
75
+ explorationRate: number;
76
+ topGaps: KnowledgeGap[];
77
+ topArms: BanditArm[];
78
+ uptime: number;
79
+ }
80
+ export interface ExplorationDecision {
81
+ topic: string;
82
+ action: 'explore' | 'exploit';
83
+ ucbScore: number;
84
+ reason: string;
85
+ suggestedActions: string[];
86
+ }
87
+ export declare function runCuriosityMigration(db: Database.Database): void;
88
+ export declare class CuriosityEngine {
89
+ private readonly db;
90
+ private readonly config;
91
+ private readonly log;
92
+ private ts;
93
+ private sources;
94
+ private startTime;
95
+ private readonly stmtInsertGap;
96
+ private readonly stmtUpdateGap;
97
+ private readonly stmtGetGap;
98
+ private readonly stmtGetGapByTopic;
99
+ private readonly stmtListGaps;
100
+ private readonly stmtActiveGapCount;
101
+ private readonly stmtInsertQuestion;
102
+ private readonly stmtAnswerQuestion;
103
+ private readonly stmtListQuestions;
104
+ private readonly stmtUnansweredCount;
105
+ private readonly stmtInsertExploration;
106
+ private readonly stmtGetExplorations;
107
+ private readonly stmtGetTopicStats;
108
+ private readonly stmtTotalExplorations;
109
+ constructor(db: Database.Database, config: CuriosityEngineConfig);
110
+ setThoughtStream(stream: ThoughtStream): void;
111
+ setDataSources(sources: CuriosityDataSources): void;
112
+ /**
113
+ * Scan attention topics and knowledge base to find gaps.
114
+ * A gap = high attention + low knowledge.
115
+ */
116
+ detectGaps(): KnowledgeGap[];
117
+ /**
118
+ * UCB1: Upper Confidence Bound algorithm.
119
+ * Balances exploration (trying under-explored topics) vs exploitation
120
+ * (deepening high-reward topics).
121
+ *
122
+ * UCB1(arm) = avg_reward + c * sqrt(ln(N) / n_i)
123
+ * where N = total pulls, n_i = pulls for arm i, c = exploration constant
124
+ */
125
+ selectTopic(): ExplorationDecision | null;
126
+ /**
127
+ * Record the outcome of an exploration/exploitation.
128
+ * Reward: 0-1 where 1 = highly valuable outcome.
129
+ */
130
+ recordOutcome(topic: string, action: 'explore' | 'exploit', reward: number, context?: string): void;
131
+ /**
132
+ * Generate concrete questions Brain should investigate.
133
+ * Uses knowledge context to formulate specific questions.
134
+ */
135
+ generateQuestions(topic?: string): CuriosityQuestion[];
136
+ /**
137
+ * Answer a question (e.g., when user or system provides an answer).
138
+ */
139
+ answerQuestion(questionId: number, answer: string): boolean;
140
+ /**
141
+ * Check for surprises: things that violated expectations.
142
+ * Compares predictions vs actual outcomes, hypothesis results vs expected.
143
+ */
144
+ detectSurprises(): Array<{
145
+ topic: string;
146
+ expected: string;
147
+ actual: string;
148
+ deviation: number;
149
+ }>;
150
+ getGaps(limit?: number): KnowledgeGap[];
151
+ getGap(id: number): KnowledgeGap | null;
152
+ getQuestions(limit?: number): CuriosityQuestion[];
153
+ getArms(): BanditArm[];
154
+ getExplorations(limit?: number): ExplorationRecord[];
155
+ getStatus(): CuriosityStatus;
156
+ /** Gather topics from attention, knowledge, and hypotheses. */
157
+ private gatherTopics;
158
+ /** Extract meaningful topic words from a statement. */
159
+ private extractTopicWords;
160
+ /** Get attention score for a topic (0-1 normalized). */
161
+ private getAttentionFor;
162
+ /** Get knowledge score for a topic (0-1). High = we know a lot. */
163
+ private getKnowledgeFor;
164
+ private classifyGap;
165
+ private generateQuestionsFor;
166
+ private inferQuestionType;
167
+ private suggestActions;
168
+ private toGap;
169
+ private toQuestion;
170
+ }