@kernel.chat/kbot 2.21.0 → 2.22.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.
@@ -0,0 +1,56 @@
1
+ export interface AgentContribution {
2
+ agentId: string;
3
+ content: string;
4
+ concepts: Set<string>;
5
+ timestamp: number;
6
+ }
7
+ export interface IntegrationScore {
8
+ /** Φ (phi) — integrated information (0-1, higher = more integrated) */
9
+ phi: number;
10
+ /** Information generated by the whole system */
11
+ wholeInformation: number;
12
+ /** Sum of information from individual parts */
13
+ partsInformation: number;
14
+ /** Concepts that emerged only in the synthesis (not in any individual part) */
15
+ emergentConcepts: string[];
16
+ /** Concepts shared across multiple agents (high integration) */
17
+ sharedConcepts: string[];
18
+ /** Assessment: fragmented, partial, integrated, or unified */
19
+ level: 'fragmented' | 'partial' | 'integrated' | 'unified';
20
+ }
21
+ export interface ConsciousnessState {
22
+ /** Running Φ across the session */
23
+ avgPhi: number;
24
+ /** Peak Φ observed */
25
+ peakPhi: number;
26
+ /** Number of integration measurements */
27
+ measurements: number;
28
+ /** Trend: rising, falling, or stable */
29
+ trend: 'rising' | 'falling' | 'stable';
30
+ }
31
+ /**
32
+ * Integrated Information Meter — measures Φ for multi-agent outputs.
33
+ *
34
+ * High Φ means agents are producing genuinely integrated reasoning.
35
+ * Low Φ means agents are working in parallel but not connecting ideas.
36
+ */
37
+ export declare class IntegrationMeter {
38
+ private history;
39
+ /**
40
+ * Measure Φ for a set of agent contributions and their synthesis.
41
+ *
42
+ * Φ = information(whole) - Σ information(parts)
43
+ * Normalized to [0, 1].
44
+ */
45
+ measure(contributions: AgentContribution[], synthesis: string): IntegrationScore;
46
+ /**
47
+ * Should the synthesis be re-run with deeper integration?
48
+ * Returns true if Φ is too low for the number of contributing agents.
49
+ */
50
+ needsDeeperSynthesis(phi: number, agentCount: number): boolean;
51
+ /** Get consciousness state summary */
52
+ getState(): ConsciousnessState;
53
+ /** Reset for new conversation */
54
+ reset(): void;
55
+ }
56
+ //# sourceMappingURL=integrated-information.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integrated-information.d.ts","sourceRoot":"","sources":["../src/integrated-information.ts"],"names":[],"mappings":"AAkBA,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACrB,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,uEAAuE;IACvE,GAAG,EAAE,MAAM,CAAA;IACX,gDAAgD;IAChD,gBAAgB,EAAE,MAAM,CAAA;IACxB,+CAA+C;IAC/C,gBAAgB,EAAE,MAAM,CAAA;IACxB,+EAA+E;IAC/E,gBAAgB,EAAE,MAAM,EAAE,CAAA;IAC1B,gEAAgE;IAChE,cAAc,EAAE,MAAM,EAAE,CAAA;IACxB,8DAA8D;IAC9D,KAAK,EAAE,YAAY,GAAG,SAAS,GAAG,YAAY,GAAG,SAAS,CAAA;CAC3D;AAED,MAAM,WAAW,kBAAkB;IACjC,mCAAmC;IACnC,MAAM,EAAE,MAAM,CAAA;IACd,sBAAsB;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,yCAAyC;IACzC,YAAY,EAAE,MAAM,CAAA;IACpB,wCAAwC;IACxC,KAAK,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAA;CACvC;AAgDD;;;;;GAKG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,OAAO,CAAyB;IAExC;;;;;OAKG;IACH,OAAO,CAAC,aAAa,EAAE,iBAAiB,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,gBAAgB;IAqEhF;;;OAGG;IACH,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO;IAM9D,sCAAsC;IACtC,QAAQ,IAAI,kBAAkB;IAqB9B,iCAAiC;IACjC,KAAK,IAAI,IAAI;CAGd"}
@@ -0,0 +1,165 @@
1
+ // K:BOT Integrated Information — Consciousness Metric (Φ)
2
+ //
3
+ // Based on Giulio Tononi's Integrated Information Theory (IIT, 2004-2024):
4
+ // Consciousness corresponds to integrated information (Φ) — the degree
5
+ // to which a system's whole is greater than the sum of its parts.
6
+ //
7
+ // For kbot: when multiple agents contribute to a response, Φ measures
8
+ // how much their contributions are genuinely synthesized vs. just
9
+ // concatenated. High Φ = emergent insight. Low Φ = parallel but disconnected.
10
+ //
11
+ // This module measures the "consciousness" of multi-agent collaboration
12
+ // and decides when deeper synthesis is needed.
13
+ //
14
+ // References:
15
+ // - Tononi, G. (2004). An information integration theory of consciousness.
16
+ // - Tononi, G. et al. (2016). Integrated information theory: from consciousness to its physical substrate.
17
+ // - Oizumi, M., Albantakis, L., & Tononi, G. (2014). From the phenomenology to the mechanisms of consciousness.
18
+ // Stopwords for concept extraction
19
+ const CONCEPT_STOPS = new Set([
20
+ 'the', 'a', 'an', 'is', 'are', 'was', 'were', 'be', 'been', 'being',
21
+ 'have', 'has', 'had', 'do', 'does', 'did', 'will', 'would', 'could',
22
+ 'should', 'may', 'might', 'shall', 'can', 'need', 'must', 'that',
23
+ 'this', 'these', 'those', 'it', 'its', 'they', 'them', 'their',
24
+ 'we', 'our', 'you', 'your', 'he', 'she', 'him', 'her', 'i', 'me',
25
+ 'my', 'and', 'or', 'but', 'not', 'no', 'nor', 'if', 'then', 'else',
26
+ 'when', 'where', 'how', 'what', 'which', 'who', 'whom', 'why',
27
+ 'for', 'with', 'from', 'into', 'to', 'of', 'in', 'on', 'at', 'by',
28
+ 'about', 'as', 'so', 'just', 'also', 'very', 'more', 'most', 'some',
29
+ 'any', 'all', 'each', 'every', 'both', 'few', 'many', 'much', 'own',
30
+ ]);
31
+ /** Extract meaningful concepts (bigrams + significant unigrams) from text */
32
+ function extractConcepts(text) {
33
+ const words = text.toLowerCase()
34
+ .replace(/[^a-z0-9\s-]/g, ' ')
35
+ .split(/\s+/)
36
+ .filter(w => w.length > 3 && !CONCEPT_STOPS.has(w));
37
+ const concepts = new Set();
38
+ // Significant unigrams (longer words more likely to be concepts)
39
+ for (const word of words) {
40
+ if (word.length >= 5)
41
+ concepts.add(word);
42
+ }
43
+ // Bigrams (adjacent word pairs — captures compound concepts)
44
+ for (let i = 0; i < words.length - 1; i++) {
45
+ if (words[i].length >= 3 && words[i + 1].length >= 3) {
46
+ concepts.add(`${words[i]} ${words[i + 1]}`);
47
+ }
48
+ }
49
+ return concepts;
50
+ }
51
+ /** Shannon entropy of a concept distribution */
52
+ function conceptEntropy(concepts, totalVocab) {
53
+ if (concepts.size === 0 || totalVocab === 0)
54
+ return 0;
55
+ const p = concepts.size / totalVocab;
56
+ if (p <= 0 || p >= 1)
57
+ return 0;
58
+ return -(p * Math.log2(p) + (1 - p) * Math.log2(1 - p));
59
+ }
60
+ /**
61
+ * Integrated Information Meter — measures Φ for multi-agent outputs.
62
+ *
63
+ * High Φ means agents are producing genuinely integrated reasoning.
64
+ * Low Φ means agents are working in parallel but not connecting ideas.
65
+ */
66
+ export class IntegrationMeter {
67
+ history = [];
68
+ /**
69
+ * Measure Φ for a set of agent contributions and their synthesis.
70
+ *
71
+ * Φ = information(whole) - Σ information(parts)
72
+ * Normalized to [0, 1].
73
+ */
74
+ measure(contributions, synthesis) {
75
+ // Extract concepts from each part
76
+ const partConcepts = contributions.map(c => c.concepts.size > 0 ? c.concepts : extractConcepts(c.content));
77
+ const synthesisConcepts = extractConcepts(synthesis);
78
+ // Total vocabulary (union of all concepts)
79
+ const allConcepts = new Set();
80
+ for (const pc of partConcepts) {
81
+ for (const c of pc)
82
+ allConcepts.add(c);
83
+ }
84
+ for (const c of synthesisConcepts)
85
+ allConcepts.add(c);
86
+ const totalVocab = allConcepts.size;
87
+ if (totalVocab === 0) {
88
+ return { phi: 0, wholeInformation: 0, partsInformation: 0, emergentConcepts: [], sharedConcepts: [], level: 'fragmented' };
89
+ }
90
+ // Information of the whole (synthesis)
91
+ const wholeInformation = conceptEntropy(synthesisConcepts, totalVocab);
92
+ // Sum of information of parts
93
+ const partsInformation = partConcepts.reduce((sum, pc) => sum + conceptEntropy(pc, totalVocab), 0) / Math.max(1, partConcepts.length);
94
+ // Emergent concepts: in synthesis but not in any individual part
95
+ const partUnion = new Set();
96
+ for (const pc of partConcepts) {
97
+ for (const c of pc)
98
+ partUnion.add(c);
99
+ }
100
+ const emergentConcepts = [...synthesisConcepts].filter(c => !partUnion.has(c));
101
+ // Shared concepts: appearing in 2+ agent contributions
102
+ const conceptCounts = new Map();
103
+ for (const pc of partConcepts) {
104
+ for (const c of pc) {
105
+ conceptCounts.set(c, (conceptCounts.get(c) ?? 0) + 1);
106
+ }
107
+ }
108
+ const sharedConcepts = [...conceptCounts.entries()]
109
+ .filter(([, count]) => count >= 2)
110
+ .map(([concept]) => concept);
111
+ // Φ = normalized integration
112
+ // Combines: emergent concept ratio + shared concept ratio + information gain
113
+ const emergentRatio = totalVocab > 0 ? emergentConcepts.length / totalVocab : 0;
114
+ const sharedRatio = partUnion.size > 0 ? sharedConcepts.length / partUnion.size : 0;
115
+ const informationGain = Math.max(0, wholeInformation - partsInformation);
116
+ const phi = Math.min(1, (emergentRatio * 0.4 + sharedRatio * 0.35 + informationGain * 0.25) * 2.5);
117
+ const level = phi < 0.2 ? 'fragmented' :
118
+ phi < 0.5 ? 'partial' :
119
+ phi < 0.8 ? 'integrated' : 'unified';
120
+ const score = {
121
+ phi,
122
+ wholeInformation,
123
+ partsInformation,
124
+ emergentConcepts: emergentConcepts.slice(0, 10),
125
+ sharedConcepts: sharedConcepts.slice(0, 10),
126
+ level,
127
+ };
128
+ this.history.push(score);
129
+ return score;
130
+ }
131
+ /**
132
+ * Should the synthesis be re-run with deeper integration?
133
+ * Returns true if Φ is too low for the number of contributing agents.
134
+ */
135
+ needsDeeperSynthesis(phi, agentCount) {
136
+ // More agents should produce higher integration
137
+ const threshold = Math.min(0.6, 0.2 + agentCount * 0.1);
138
+ return phi < threshold;
139
+ }
140
+ /** Get consciousness state summary */
141
+ getState() {
142
+ if (this.history.length === 0) {
143
+ return { avgPhi: 0, peakPhi: 0, measurements: 0, trend: 'stable' };
144
+ }
145
+ const avgPhi = this.history.reduce((sum, s) => sum + s.phi, 0) / this.history.length;
146
+ const peakPhi = Math.max(...this.history.map(s => s.phi));
147
+ // Trend: compare recent half to earlier half
148
+ let trend = 'stable';
149
+ if (this.history.length >= 4) {
150
+ const mid = Math.floor(this.history.length / 2);
151
+ const early = this.history.slice(0, mid).reduce((s, h) => s + h.phi, 0) / mid;
152
+ const late = this.history.slice(mid).reduce((s, h) => s + h.phi, 0) / (this.history.length - mid);
153
+ if (late - early > 0.1)
154
+ trend = 'rising';
155
+ else if (early - late > 0.1)
156
+ trend = 'falling';
157
+ }
158
+ return { avgPhi, peakPhi, measurements: this.history.length, trend };
159
+ }
160
+ /** Reset for new conversation */
161
+ reset() {
162
+ this.history = [];
163
+ }
164
+ }
165
+ //# sourceMappingURL=integrated-information.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integrated-information.js","sourceRoot":"","sources":["../src/integrated-information.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,EAAE;AACF,2EAA2E;AAC3E,uEAAuE;AACvE,kEAAkE;AAClE,EAAE;AACF,sEAAsE;AACtE,kEAAkE;AAClE,8EAA8E;AAC9E,EAAE;AACF,wEAAwE;AACxE,+CAA+C;AAC/C,EAAE;AACF,cAAc;AACd,6EAA6E;AAC7E,6GAA6G;AAC7G,kHAAkH;AAmClH,mCAAmC;AACnC,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO;IACnE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IACn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E,CAAA;IACtE,CAAC;IAED,iCAAiC;IACjC,KAAK;QACH,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;IACnB,CAAC;CACF"}
@@ -0,0 +1,79 @@
1
+ export interface Prediction {
2
+ /** What we predict the user will ask or do next */
3
+ predictedAction: string;
4
+ /** Confidence in this prediction (0-1) */
5
+ confidence: number;
6
+ /** Context that should be pre-loaded if prediction holds */
7
+ preloadContext: string[];
8
+ /** Tools likely to be needed */
9
+ likelyTools: string[];
10
+ /** Timestamp */
11
+ timestamp: number;
12
+ }
13
+ export interface PredictionError {
14
+ /** The prediction that was made */
15
+ prediction: Prediction;
16
+ /** What actually happened */
17
+ actual: string;
18
+ /** Error magnitude (0-1, Jaccard distance) */
19
+ magnitude: number;
20
+ /** What we learned from this error */
21
+ insight: string;
22
+ }
23
+ export interface PredictiveState {
24
+ /** Current prediction accuracy (0-1, exponential moving average) */
25
+ accuracy: number;
26
+ /** Number of predictions made */
27
+ totalPredictions: number;
28
+ /** Number of correct predictions (error < 0.4) */
29
+ correctPredictions: number;
30
+ /** Most common prediction errors (what we keep getting wrong) */
31
+ blindSpots: string[];
32
+ /** Current precision weighting (how much to trust predictions vs. observations) */
33
+ precisionWeight: number;
34
+ }
35
+ /**
36
+ * Predictive Processing Engine — anticipates user intent and
37
+ * pre-loads context, reducing latency and improving relevance.
38
+ *
39
+ * The engine maintains a generative model of user behavior and
40
+ * continuously updates it based on prediction errors.
41
+ */
42
+ export declare class PredictiveEngine {
43
+ private predictions;
44
+ private errors;
45
+ private messageHistory;
46
+ private toolHistory;
47
+ private accuracy;
48
+ private precisionWeight;
49
+ private readonly learningRate;
50
+ private readonly errorDecay;
51
+ private readonly maxHistory;
52
+ /**
53
+ * Generate a prediction for what the user will do next.
54
+ * Based on conversation patterns and tool usage history.
55
+ */
56
+ predict(recentMessages: string[], recentTools: string[]): Prediction;
57
+ /**
58
+ * Evaluate a prediction against what actually happened.
59
+ * Updates the generative model based on prediction error.
60
+ */
61
+ evaluate(prediction: Prediction, actualMessage: string, actualTools: string[]): PredictionError;
62
+ /**
63
+ * Detect the current conversation pattern.
64
+ */
65
+ private detectPattern;
66
+ /**
67
+ * Predict likely tools from recent tool usage patterns.
68
+ */
69
+ private predictToolsFromHistory;
70
+ /**
71
+ * Get blind spots — things the engine consistently predicts wrong.
72
+ */
73
+ getBlindSpots(): string[];
74
+ /** Get full predictive state */
75
+ getState(): PredictiveState;
76
+ /** Reset for new conversation */
77
+ reset(): void;
78
+ }
79
+ //# sourceMappingURL=predictive-processing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"predictive-processing.d.ts","sourceRoot":"","sources":["../src/predictive-processing.ts"],"names":[],"mappings":"AAmBA,MAAM,WAAW,UAAU;IACzB,mDAAmD;IACnD,eAAe,EAAE,MAAM,CAAA;IACvB,0CAA0C;IAC1C,UAAU,EAAE,MAAM,CAAA;IAClB,4DAA4D;IAC5D,cAAc,EAAE,MAAM,EAAE,CAAA;IACxB,gCAAgC;IAChC,WAAW,EAAE,MAAM,EAAE,CAAA;IACrB,gBAAgB;IAChB,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,mCAAmC;IACnC,UAAU,EAAE,UAAU,CAAA;IACtB,6BAA6B;IAC7B,MAAM,EAAE,MAAM,CAAA;IACd,8CAA8C;IAC9C,SAAS,EAAE,MAAM,CAAA;IACjB,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,oEAAoE;IACpE,QAAQ,EAAE,MAAM,CAAA;IAChB,iCAAiC;IACjC,gBAAgB,EAAE,MAAM,CAAA;IACxB,kDAAkD;IAClD,kBAAkB,EAAE,MAAM,CAAA;IAC1B,iEAAiE;IACjE,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,mFAAmF;IACnF,eAAe,EAAE,MAAM,CAAA;CACxB;AAWD;;;;;;GAMG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,WAAW,CAAmB;IACtC,OAAO,CAAC,MAAM,CAAwB;IACtC,OAAO,CAAC,cAAc,CAAe;IACrC,OAAO,CAAC,WAAW,CAAe;IAClC,OAAO,CAAC,QAAQ,CAAM;IACtB,OAAO,CAAC,eAAe,CAAM;IAG7B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAO;IACpC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAM;IACjC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAK;IAEhC;;;OAGG;IACH,OAAO,CAAC,cAAc,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,UAAU;IAyEpE;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,eAAe;IA0D/F;;OAEG;IACH,OAAO,CAAC,aAAa;IAsCrB;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAgB/B;;OAEG;IACH,aAAa,IAAI,MAAM,EAAE;IAoBzB,gCAAgC;IAChC,QAAQ,IAAI,eAAe;IAY3B,iCAAiC;IACjC,KAAK,IAAI,IAAI;CAQd"}
@@ -0,0 +1,250 @@
1
+ // K:BOT Predictive Processing — Anticipatory Cognition Engine
2
+ //
3
+ // Based on the Predictive Processing framework (Clark, 2013; Hohwy, 2013):
4
+ // The brain is fundamentally a prediction machine. It constantly generates
5
+ // top-down predictions about incoming sensory data, then updates when
6
+ // predictions are violated (prediction error).
7
+ //
8
+ // For kbot: predict what the user will ask next, pre-load relevant context,
9
+ // and measure prediction errors to identify what's most worth learning.
10
+ //
11
+ // High prediction error = high-value information (the user surprised us)
12
+ // Low prediction error = we understand the user well (act confidently)
13
+ //
14
+ // References:
15
+ // - Clark, A. (2013). Whatever next? Predictive brains, situated agents.
16
+ // - Hohwy, J. (2013). The Predictive Mind.
17
+ // - Rao, R.P. & Ballard, D.H. (1999). Predictive coding in the visual cortex.
18
+ // - Keller, G.B. & Mrsic-Flogel, T.D. (2018). Predictive processing.
19
+ /**
20
+ * Predictive Processing Engine — anticipates user intent and
21
+ * pre-loads context, reducing latency and improving relevance.
22
+ *
23
+ * The engine maintains a generative model of user behavior and
24
+ * continuously updates it based on prediction errors.
25
+ */
26
+ export class PredictiveEngine {
27
+ predictions = [];
28
+ errors = [];
29
+ messageHistory = [];
30
+ toolHistory = [];
31
+ accuracy = 0.5;
32
+ precisionWeight = 0.5;
33
+ // Hyperparameters
34
+ learningRate = 0.12;
35
+ errorDecay = 0.9;
36
+ maxHistory = 50;
37
+ /**
38
+ * Generate a prediction for what the user will do next.
39
+ * Based on conversation patterns and tool usage history.
40
+ */
41
+ predict(recentMessages, recentTools) {
42
+ const pattern = this.detectPattern(recentMessages);
43
+ const lastMessage = recentMessages[recentMessages.length - 1] || '';
44
+ const lastTool = recentTools[recentTools.length - 1] || '';
45
+ let predictedAction = '';
46
+ let confidence = 0.3;
47
+ let preloadContext = [];
48
+ let likelyTools = [];
49
+ switch (pattern) {
50
+ case 'iterative_refinement':
51
+ predictedAction = 'refine previous output with specific changes';
52
+ confidence = 0.7;
53
+ likelyTools = ['edit_file', 'write_file'];
54
+ preloadContext = ['previous output', 'user feedback'];
55
+ break;
56
+ case 'drill_down':
57
+ predictedAction = 'ask for more detail on current topic';
58
+ confidence = 0.6;
59
+ likelyTools = ['read_file', 'grep', 'web_search'];
60
+ preloadContext = ['current topic context', 'related files'];
61
+ break;
62
+ case 'verification':
63
+ predictedAction = 'test or verify previous changes';
64
+ confidence = 0.65;
65
+ likelyTools = ['bash', 'read_file', 'git_diff'];
66
+ preloadContext = ['recent changes', 'test commands'];
67
+ break;
68
+ case 'topic_switch':
69
+ predictedAction = 'start new unrelated task';
70
+ confidence = 0.4;
71
+ likelyTools = ['read_file', 'glob'];
72
+ preloadContext = [];
73
+ break;
74
+ case 'follow_up':
75
+ predictedAction = 'continue current thread naturally';
76
+ confidence = 0.5;
77
+ likelyTools = this.predictToolsFromHistory(recentTools);
78
+ preloadContext = ['recent context'];
79
+ break;
80
+ case 'meta_question':
81
+ predictedAction = 'ask about capabilities or process';
82
+ confidence = 0.6;
83
+ likelyTools = [];
84
+ preloadContext = ['agent capabilities'];
85
+ break;
86
+ }
87
+ // Boost confidence based on historical accuracy
88
+ confidence *= (0.5 + this.accuracy * 0.5);
89
+ const prediction = {
90
+ predictedAction,
91
+ confidence: Math.min(0.95, confidence),
92
+ preloadContext,
93
+ likelyTools,
94
+ timestamp: Date.now(),
95
+ };
96
+ this.predictions.push(prediction);
97
+ if (this.predictions.length > this.maxHistory) {
98
+ this.predictions.shift();
99
+ }
100
+ return prediction;
101
+ }
102
+ /**
103
+ * Evaluate a prediction against what actually happened.
104
+ * Updates the generative model based on prediction error.
105
+ */
106
+ evaluate(prediction, actualMessage, actualTools) {
107
+ // Compute prediction error (Jaccard distance between predicted and actual)
108
+ const predWords = new Set(prediction.predictedAction.toLowerCase().split(/\s+/));
109
+ const actualWords = new Set(actualMessage.toLowerCase().split(/\s+/).filter(w => w.length > 3));
110
+ let magnitude = 1.0;
111
+ if (predWords.size > 0 && actualWords.size > 0) {
112
+ const intersection = new Set([...predWords].filter(w => actualWords.has(w)));
113
+ const union = new Set([...predWords, ...actualWords]);
114
+ magnitude = 1 - (intersection.size / union.size);
115
+ }
116
+ // Tool prediction accuracy
117
+ const toolOverlap = prediction.likelyTools.filter(t => actualTools.includes(t)).length;
118
+ const toolAccuracy = prediction.likelyTools.length > 0
119
+ ? toolOverlap / prediction.likelyTools.length
120
+ : 0.5;
121
+ // Combined error
122
+ magnitude = magnitude * 0.6 + (1 - toolAccuracy) * 0.4;
123
+ // What we learned
124
+ const insight = magnitude > 0.6
125
+ ? `Prediction missed: expected "${prediction.predictedAction}" but user did something different`
126
+ : magnitude > 0.3
127
+ ? `Partial match: prediction was in the right direction`
128
+ : `Good prediction: model accurately anticipated user intent`;
129
+ const error = {
130
+ prediction,
131
+ actual: actualMessage.slice(0, 200),
132
+ magnitude,
133
+ insight,
134
+ };
135
+ this.errors.push(error);
136
+ if (this.errors.length > this.maxHistory) {
137
+ this.errors.shift();
138
+ }
139
+ // Update accuracy (exponential moving average)
140
+ const correct = magnitude < 0.4 ? 1 : 0;
141
+ this.accuracy = this.accuracy * (1 - this.learningRate) + correct * this.learningRate;
142
+ // Update precision weighting
143
+ // High accuracy → trust predictions more (higher precision)
144
+ // Low accuracy → trust observations more (lower precision)
145
+ this.precisionWeight = this.accuracy * 0.8 + 0.1;
146
+ // Track history
147
+ this.messageHistory.push(actualMessage);
148
+ for (const t of actualTools)
149
+ this.toolHistory.push(t);
150
+ if (this.messageHistory.length > this.maxHistory)
151
+ this.messageHistory.shift();
152
+ if (this.toolHistory.length > this.maxHistory * 3)
153
+ this.toolHistory.splice(0, this.toolHistory.length - this.maxHistory * 3);
154
+ return error;
155
+ }
156
+ /**
157
+ * Detect the current conversation pattern.
158
+ */
159
+ detectPattern(messages) {
160
+ if (messages.length < 2)
161
+ return 'follow_up';
162
+ const last = (messages[messages.length - 1] || '').toLowerCase();
163
+ const prev = (messages[messages.length - 2] || '').toLowerCase();
164
+ // Meta questions about the process
165
+ if (/\b(how do you|can you|what are you|what tools|capabilities)\b/.test(last)) {
166
+ return 'meta_question';
167
+ }
168
+ // Verification patterns
169
+ if (/\b(test|check|verify|does it work|run it|try it|show me)\b/.test(last)) {
170
+ return 'verification';
171
+ }
172
+ // Refinement patterns
173
+ if (/\b(change|modify|update|fix|adjust|instead|rather|but make|no,)\b/.test(last)) {
174
+ return 'iterative_refinement';
175
+ }
176
+ // Drill-down patterns
177
+ if (/\b(more about|explain|detail|deeper|elaborate|specifically|what about)\b/.test(last)) {
178
+ return 'drill_down';
179
+ }
180
+ // Topic similarity check
181
+ const lastWords = new Set(last.split(/\s+/).filter(w => w.length > 4));
182
+ const prevWords = new Set(prev.split(/\s+/).filter(w => w.length > 4));
183
+ const overlap = [...lastWords].filter(w => prevWords.has(w)).length;
184
+ const similarity = lastWords.size > 0 ? overlap / lastWords.size : 0;
185
+ if (similarity < 0.1)
186
+ return 'topic_switch';
187
+ if (similarity > 0.5)
188
+ return 'drill_down';
189
+ return 'follow_up';
190
+ }
191
+ /**
192
+ * Predict likely tools from recent tool usage patterns.
193
+ */
194
+ predictToolsFromHistory(recentTools) {
195
+ if (recentTools.length === 0)
196
+ return [];
197
+ // Count tool frequencies
198
+ const counts = new Map();
199
+ for (const t of recentTools.slice(-10)) {
200
+ counts.set(t, (counts.get(t) ?? 0) + 1);
201
+ }
202
+ // Return top 3 by frequency
203
+ return [...counts.entries()]
204
+ .sort((a, b) => b[1] - a[1])
205
+ .slice(0, 3)
206
+ .map(([tool]) => tool);
207
+ }
208
+ /**
209
+ * Get blind spots — things the engine consistently predicts wrong.
210
+ */
211
+ getBlindSpots() {
212
+ const recentErrors = this.errors.slice(-20).filter(e => e.magnitude > 0.6);
213
+ if (recentErrors.length < 3)
214
+ return [];
215
+ // Find common patterns in high-error predictions
216
+ const errorPatterns = new Map();
217
+ for (const err of recentErrors) {
218
+ const words = err.actual.toLowerCase().split(/\s+/).filter(w => w.length > 4);
219
+ for (const w of words) {
220
+ errorPatterns.set(w, (errorPatterns.get(w) ?? 0) + 1);
221
+ }
222
+ }
223
+ return [...errorPatterns.entries()]
224
+ .filter(([, count]) => count >= 2)
225
+ .sort((a, b) => b[1] - a[1])
226
+ .slice(0, 5)
227
+ .map(([word]) => word);
228
+ }
229
+ /** Get full predictive state */
230
+ getState() {
231
+ const correctCount = this.errors.filter(e => e.magnitude < 0.4).length;
232
+ return {
233
+ accuracy: this.accuracy,
234
+ totalPredictions: this.predictions.length,
235
+ correctPredictions: correctCount,
236
+ blindSpots: this.getBlindSpots(),
237
+ precisionWeight: this.precisionWeight,
238
+ };
239
+ }
240
+ /** Reset for new conversation */
241
+ reset() {
242
+ this.predictions = [];
243
+ this.errors = [];
244
+ this.messageHistory = [];
245
+ this.toolHistory = [];
246
+ this.accuracy = 0.5;
247
+ this.precisionWeight = 0.5;
248
+ }
249
+ }
250
+ //# sourceMappingURL=predictive-processing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"predictive-processing.js","sourceRoot":"","sources":["../src/predictive-processing.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,EAAE;AACF,2EAA2E;AAC3E,2EAA2E;AAC3E,sEAAsE;AACtE,+CAA+C;AAC/C,EAAE;AACF,4EAA4E;AAC5E,wEAAwE;AACxE,EAAE;AACF,yEAAyE;AACzE,uEAAuE;AACvE,EAAE;AACF,cAAc;AACd,2EAA2E;AAC3E,6CAA6C;AAC7C,gFAAgF;AAChF,uEAAuE;AAgDvE;;;;;;GAMG;AACH,MAAM,OAAO,gBAAgB;IACnB,WAAW,GAAiB,EAAE,CAAA;IAC9B,MAAM,GAAsB,EAAE,CAAA;IAC9B,cAAc,GAAa,EAAE,CAAA;IAC7B,WAAW,GAAa,EAAE,CAAA;IAC1B,QAAQ,GAAG,GAAG,CAAA;IACd,eAAe,GAAG,GAAG,CAAA;IAE7B,kBAAkB;IACD,YAAY,GAAG,IAAI,CAAA;IACnB,UAAU,GAAG,GAAG,CAAA;IAChB,UAAU,GAAG,EAAE,CAAA;IAEhC;;;OAGG;IACH,OAAO,CAAC,cAAwB,EAAE,WAAqB;QACrD,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC,CAAA;QAClD,MAAM,WAAW,GAAG,cAAc,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,CAAA;QACnE,MAAM,QAAQ,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,CAAA;QAE1D,IAAI,eAAe,GAAG,EAAE,CAAA;QACxB,IAAI,UAAU,GAAG,GAAG,CAAA;QACpB,IAAI,cAAc,GAAa,EAAE,CAAA;QACjC,IAAI,WAAW,GAAa,EAAE,CAAA;QAE9B,QAAQ,OAAO,EAAE,CAAC;YAChB,KAAK,sBAAsB;gBACzB,eAAe,GAAG,8CAA8C,CAAA;gBA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