@kernel.chat/kbot 3.94.0 → 3.97.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.
package/dist/agent.js CHANGED
@@ -54,6 +54,7 @@ import { generateReflections, getRelevantReflections, formatReflectionsForPrompt
54
54
  import { getSynthesisContext } from './memory-synthesis.js';
55
55
  import { getActiveCorrectionsPrompt } from './synthesis-engine.js';
56
56
  import { recordTrace, shouldEvolve, evolvePrompt, getPromptAmendment, updateMutationScore } from './prompt-evolution.js';
57
+ import { getCoordinator } from './coordinator.js';
57
58
  const MAX_TOOL_LOOPS = 75;
58
59
  /** Maximum cumulative cost (USD) before auto-stopping tool loops */
59
60
  const MAX_COST_CEILING = 1.00;
@@ -1102,6 +1103,18 @@ Always quote file paths that contain spaces. Never reference internal system nam
1102
1103
  const anticipated = anticipateNext([originalMessage], originalMessage);
1103
1104
  }
1104
1105
  catch { /* cognitive stack is non-critical — never block the agent loop */ }
1106
+ // ── Intelligence Coordinator: unified pre-processing ──
1107
+ let coordinatorContext = '';
1108
+ try {
1109
+ const coordinator = getCoordinator();
1110
+ const preResult = await coordinator.preProcess(originalMessage, sessionId);
1111
+ if (preResult.systemPromptAddition)
1112
+ coordinatorContext = preResult.systemPromptAddition;
1113
+ if (preResult.needsClarification) {
1114
+ telemetry.emit('tool_call_end', { tool: 'coordinator', duration_ms: 0, error: preResult.clarificationReason });
1115
+ }
1116
+ }
1117
+ catch { /* coordinator is non-critical */ }
1105
1118
  // Change 5: Apply cognitive policy to system prompt
1106
1119
  // explore → broader thinking, exploit → direct proven approaches
1107
1120
  try {
@@ -1115,6 +1128,8 @@ Always quote file paths that contain spaces. Never reference internal system nam
1115
1128
  if (cognitiveToolBias.preferred.length > 0) {
1116
1129
  systemContext += `\n\nPreferred tools based on learned patterns: ${cognitiveToolBias.preferred.join(', ')}`;
1117
1130
  }
1131
+ if (coordinatorContext)
1132
+ systemContext += `\n\n${coordinatorContext}`;
1118
1133
  }
1119
1134
  catch { /* cognitive prompt injection is non-critical */ }
1120
1135
  // ── Tool execution pipeline ──
@@ -1126,6 +1141,14 @@ Always quote file paths that contain spaces. Never reference internal system nam
1126
1141
  },
1127
1142
  runPostHook: (name, args, result) => { runPostToolHook(name, args, result, options.agent || 'kernel'); },
1128
1143
  executeTool: async (name, args) => {
1144
+ // Coordinator tool oversight
1145
+ try {
1146
+ const coord = getCoordinator();
1147
+ const eval_ = coord.evaluateToolCall(name, args);
1148
+ if (eval_.warn)
1149
+ process.stderr.write(`\n \x1b[2m[coordinator] ${eval_.warn}\x1b[0m\n`);
1150
+ }
1151
+ catch { /* non-critical */ }
1129
1152
  const r = await executeTool({ id: name, name, arguments: args });
1130
1153
  return { result: r.result, error: r.error ? r.result : undefined };
1131
1154
  },
@@ -1478,6 +1501,13 @@ Always quote file paths that contain spaces. Never reference internal system nam
1478
1501
  }
1479
1502
  catch { /* silent */ }
1480
1503
  }
1504
+ // ── Intelligence Coordinator: post-response self-evaluation ──
1505
+ try {
1506
+ const coord = getCoordinator();
1507
+ coord.postProcess(originalMessage, content, toolSequenceLog, sessionId)
1508
+ .catch(() => { });
1509
+ }
1510
+ catch { /* coordinator is non-critical */ }
1481
1511
  // ── Prompt Evolution (GEPA): record trace and evolve if threshold met ──
1482
1512
  try {
1483
1513
  const traceAgent = lastResponse.agent || 'kernel';
@@ -0,0 +1,132 @@
1
+ export interface Goal {
2
+ id: string;
3
+ description: string;
4
+ priority: number;
5
+ status: 'active' | 'completed' | 'abandoned';
6
+ created: string;
7
+ toolsUsed: string[];
8
+ }
9
+ export interface Insight {
10
+ id: string;
11
+ content: string;
12
+ source: string;
13
+ confidence: number;
14
+ timestamp: string;
15
+ }
16
+ export interface Conflict {
17
+ modules: [string, string];
18
+ description: string;
19
+ resolution: string | null;
20
+ timestamp: string;
21
+ }
22
+ export interface SelfEval {
23
+ sessionId: string;
24
+ messageHash: string;
25
+ score: number;
26
+ toolSuccessRate: number;
27
+ responseAppropriate: boolean;
28
+ patternsMatched: number;
29
+ timestamp: string;
30
+ }
31
+ export interface PreProcessResult {
32
+ agent: string | null;
33
+ confidence: number;
34
+ graphContext: string;
35
+ reasoning: string;
36
+ toolHints: string[];
37
+ systemPromptAddition: string;
38
+ needsClarification: boolean;
39
+ clarificationReason?: string;
40
+ drives: {
41
+ dominant: string;
42
+ level: number;
43
+ } | null;
44
+ anticipation: string | null;
45
+ }
46
+ export interface ToolEvaluation {
47
+ allow: boolean;
48
+ warn?: string;
49
+ alternatives?: string[];
50
+ anticipated: boolean;
51
+ }
52
+ export interface PostProcessResult {
53
+ score: number;
54
+ patternsExtracted: number;
55
+ insightsGenerated: number;
56
+ graphUpdates: number;
57
+ consolidationTriggered: boolean;
58
+ }
59
+ export interface ConsolidationResult {
60
+ patternsConsolidated: number;
61
+ rulesAdded: number;
62
+ insightsFound: number;
63
+ graphPruned: {
64
+ nodes: number;
65
+ edges: number;
66
+ };
67
+ routingAccuracy: number;
68
+ }
69
+ export interface CoordinatorStats {
70
+ totalInteractions: number;
71
+ successRate: number;
72
+ patternsLearnedToday: number;
73
+ routingAccuracy: number;
74
+ activeGoals: number;
75
+ recentInsights: number;
76
+ conflicts: number;
77
+ lastConsolidation: string | null;
78
+ policy: 'explore' | 'exploit' | 'balanced';
79
+ confidenceThreshold: number;
80
+ uptimeMs: number;
81
+ }
82
+ export interface CoordinatorState {
83
+ lastPolicy: 'explore' | 'exploit' | 'balanced';
84
+ confidenceThreshold: number;
85
+ totalInteractions: number;
86
+ successRate: number;
87
+ activeGoals: Goal[];
88
+ recentInsights: Insight[];
89
+ conflictLog: Conflict[];
90
+ evalHistory: SelfEval[];
91
+ patternsLearnedToday: number;
92
+ patternsLearnedDate: string;
93
+ routingAccuracy: number;
94
+ lastConsolidation: string | null;
95
+ startedAt: string;
96
+ }
97
+ export declare class IntelligenceCoordinator {
98
+ private state;
99
+ private anticipatedTools;
100
+ private currentSessionId;
101
+ private pendingRouteAgent;
102
+ private initTime;
103
+ constructor();
104
+ preProcess(message: string, sessionId: string): Promise<PreProcessResult>;
105
+ evaluateToolCall(toolName: string, args: Record<string, unknown>, _context?: {
106
+ sessionId?: string;
107
+ agent?: string;
108
+ message?: string;
109
+ }): ToolEvaluation;
110
+ postProcess(message: string, response: string, toolsUsed: string[], sessionId: string): Promise<PostProcessResult>;
111
+ consolidate(): Promise<ConsolidationResult>;
112
+ private selfEvaluate;
113
+ private synthesizePolicy;
114
+ private logToolToGraph;
115
+ private addInsight;
116
+ addGoal(description: string, priority?: number): Goal;
117
+ completeGoal(goalId: string): void;
118
+ recordConflict(modules: [string, string], description: string, resolution?: string): void;
119
+ load(): void;
120
+ save(): void;
121
+ getStats(): CoordinatorStats;
122
+ getHealthReport(): string;
123
+ getState(): Readonly<CoordinatorState>;
124
+ /** Adjust the confidence threshold (e.g., user prefers fewer clarification requests) */
125
+ setConfidenceThreshold(threshold: number): void;
126
+ /** Reset all state (for testing or fresh start) */
127
+ reset(): void;
128
+ }
129
+ export declare function getCoordinator(): IntelligenceCoordinator;
130
+ /** Register coordinator tools with the kbot tool registry */
131
+ export declare function registerCoordinatorTools(): void;
132
+ //# sourceMappingURL=coordinator.d.ts.map