@kernel.chat/kbot 3.39.0 → 3.41.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,288 @@
1
+ // kbot Memory Hot-Swap — Swap learning modules at runtime
2
+ //
3
+ // Load different expertise profiles for different projects
4
+ // without restarting kbot. Profiles contain patterns, solutions,
5
+ // user profile, and routing data.
6
+ //
7
+ // Stored at ~/.kbot/memory-profiles/{name}/
8
+ import { homedir } from 'node:os';
9
+ import { join } from 'node:path';
10
+ import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync, cpSync, rmSync, statSync, } from 'node:fs';
11
+ const KBOT_DIR = join(homedir(), '.kbot');
12
+ const MEMORY_DIR = join(KBOT_DIR, 'memory');
13
+ const PROFILES_DIR = join(KBOT_DIR, 'memory-profiles');
14
+ const ACTIVE_PROFILE_FILE = join(MEMORY_DIR, 'active-profile.json');
15
+ const BACKUP_NAME = '_backup';
16
+ /** Files that constitute a memory profile */
17
+ const PROFILE_FILES = [
18
+ 'patterns.json',
19
+ 'solutions.json',
20
+ 'profile.json',
21
+ 'routing-history.json',
22
+ 'knowledge.json',
23
+ 'corrections.json',
24
+ 'context.md',
25
+ ];
26
+ function ensureDir(dir) {
27
+ if (!existsSync(dir))
28
+ mkdirSync(dir, { recursive: true });
29
+ }
30
+ function ensureProfilesDir() {
31
+ ensureDir(PROFILES_DIR);
32
+ }
33
+ function ensureMemoryDir() {
34
+ ensureDir(MEMORY_DIR);
35
+ }
36
+ function profileDir(name) {
37
+ return join(PROFILES_DIR, name);
38
+ }
39
+ function loadJSON(path, fallback) {
40
+ if (!existsSync(path))
41
+ return fallback;
42
+ try {
43
+ return JSON.parse(readFileSync(path, 'utf-8'));
44
+ }
45
+ catch {
46
+ return fallback;
47
+ }
48
+ }
49
+ function countPatterns(dir) {
50
+ const patternsPath = join(dir, 'patterns.json');
51
+ const patterns = loadJSON(patternsPath, []);
52
+ return Array.isArray(patterns) ? patterns.length : 0;
53
+ }
54
+ /** Copy memory files from source directory to target directory */
55
+ function copyMemoryFiles(sourceDir, targetDir) {
56
+ ensureDir(targetDir);
57
+ let copied = 0;
58
+ for (const file of PROFILE_FILES) {
59
+ const src = join(sourceDir, file);
60
+ if (existsSync(src)) {
61
+ cpSync(src, join(targetDir, file));
62
+ copied++;
63
+ }
64
+ }
65
+ return copied;
66
+ }
67
+ /**
68
+ * Scan ~/.kbot/memory-profiles/ for saved profiles.
69
+ * Returns array of profile metadata.
70
+ */
71
+ export function listMemoryProfiles() {
72
+ ensureProfilesDir();
73
+ const entries = readdirSync(PROFILES_DIR, { withFileTypes: true });
74
+ const profiles = [];
75
+ for (const entry of entries) {
76
+ if (!entry.isDirectory())
77
+ continue;
78
+ // Skip the internal backup directory
79
+ if (entry.name === BACKUP_NAME)
80
+ continue;
81
+ const dir = profileDir(entry.name);
82
+ const metaPath = join(dir, 'metadata.json');
83
+ const meta = loadJSON(metaPath, {
84
+ name: entry.name,
85
+ description: '',
86
+ expertise: '',
87
+ created_at: '',
88
+ updated_at: '',
89
+ });
90
+ // If no created_at in metadata, use directory stat
91
+ let createdAt = meta.created_at;
92
+ if (!createdAt) {
93
+ try {
94
+ const stat = statSync(dir);
95
+ createdAt = stat.birthtime.toISOString();
96
+ }
97
+ catch {
98
+ createdAt = new Date().toISOString();
99
+ }
100
+ }
101
+ profiles.push({
102
+ name: meta.name || entry.name,
103
+ description: meta.description || '',
104
+ patterns_count: countPatterns(dir),
105
+ created_at: createdAt,
106
+ });
107
+ }
108
+ return profiles.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
109
+ }
110
+ /**
111
+ * Snapshot current ~/.kbot/memory/ into a named profile.
112
+ * Saves all learning data (patterns, solutions, profile, routing).
113
+ */
114
+ export function saveCurrentAsProfile(name, description) {
115
+ ensureMemoryDir();
116
+ ensureProfilesDir();
117
+ const sanitized = name.toLowerCase().replace(/[^a-z0-9_-]/g, '-').slice(0, 60);
118
+ const targetDir = profileDir(sanitized);
119
+ // Copy current memory files into the profile directory
120
+ copyMemoryFiles(MEMORY_DIR, targetDir);
121
+ // Count patterns in the snapshot
122
+ const patternsCount = countPatterns(targetDir);
123
+ // Write metadata
124
+ const meta = {
125
+ name: sanitized,
126
+ description: description || `Profile snapshot of ${name}`,
127
+ expertise: '',
128
+ created_at: new Date().toISOString(),
129
+ updated_at: new Date().toISOString(),
130
+ };
131
+ writeFileSync(join(targetDir, 'metadata.json'), JSON.stringify(meta, null, 2));
132
+ return { name: sanitized, patterns_saved: patternsCount };
133
+ }
134
+ /**
135
+ * Load a named profile into ~/.kbot/memory/.
136
+ * Backs up current memory to _backup first.
137
+ */
138
+ export function loadProfile(name) {
139
+ ensureProfilesDir();
140
+ ensureMemoryDir();
141
+ const sanitized = name.toLowerCase().replace(/[^a-z0-9_-]/g, '-').slice(0, 60);
142
+ const sourceDir = profileDir(sanitized);
143
+ if (!existsSync(sourceDir)) {
144
+ throw new Error(`Profile "${sanitized}" not found in ${PROFILES_DIR}`);
145
+ }
146
+ // Backup current memory
147
+ const backupDir = profileDir(BACKUP_NAME);
148
+ copyMemoryFiles(MEMORY_DIR, backupDir);
149
+ // Write backup metadata
150
+ const backupMeta = {
151
+ name: BACKUP_NAME,
152
+ description: 'Auto-backup before profile load',
153
+ expertise: '',
154
+ created_at: new Date().toISOString(),
155
+ updated_at: new Date().toISOString(),
156
+ };
157
+ writeFileSync(join(backupDir, 'metadata.json'), JSON.stringify(backupMeta, null, 2));
158
+ // Copy profile files into memory directory
159
+ copyMemoryFiles(sourceDir, MEMORY_DIR);
160
+ const patternsLoaded = countPatterns(MEMORY_DIR);
161
+ // Mark the active profile
162
+ const marker = {
163
+ name: sanitized,
164
+ loaded_at: new Date().toISOString(),
165
+ previous_backup: BACKUP_NAME,
166
+ };
167
+ writeFileSync(ACTIVE_PROFILE_FILE, JSON.stringify(marker, null, 2));
168
+ return {
169
+ name: sanitized,
170
+ patterns_loaded: patternsLoaded,
171
+ previous_backup: BACKUP_NAME,
172
+ };
173
+ }
174
+ /**
175
+ * Unload the current profile, restoring from _backup.
176
+ * Returns to the previous state before loadProfile was called.
177
+ */
178
+ export function unloadProfile() {
179
+ ensureMemoryDir();
180
+ ensureProfilesDir();
181
+ const active = getActiveProfile();
182
+ if (!active) {
183
+ return { restored: false, previous_profile: null };
184
+ }
185
+ const backupDir = profileDir(BACKUP_NAME);
186
+ if (!existsSync(backupDir)) {
187
+ throw new Error('No backup found. Cannot unload profile without a previous backup.');
188
+ }
189
+ const previousName = active.name;
190
+ // Restore backup into memory
191
+ copyMemoryFiles(backupDir, MEMORY_DIR);
192
+ // Remove the active profile marker
193
+ if (existsSync(ACTIVE_PROFILE_FILE)) {
194
+ rmSync(ACTIVE_PROFILE_FILE);
195
+ }
196
+ // Clean up backup
197
+ rmSync(backupDir, { recursive: true, force: true });
198
+ return { restored: true, previous_profile: previousName };
199
+ }
200
+ /**
201
+ * Create a new empty profile with metadata.
202
+ * Seeds initial routing preferences based on expertise string.
203
+ */
204
+ export function createProfile(name, description, expertise) {
205
+ ensureProfilesDir();
206
+ const sanitized = name.toLowerCase().replace(/[^a-z0-9_-]/g, '-').slice(0, 60);
207
+ const targetDir = profileDir(sanitized);
208
+ if (existsSync(targetDir)) {
209
+ throw new Error(`Profile "${sanitized}" already exists`);
210
+ }
211
+ ensureDir(targetDir);
212
+ // Write metadata
213
+ const meta = {
214
+ name: sanitized,
215
+ description,
216
+ expertise,
217
+ created_at: new Date().toISOString(),
218
+ updated_at: new Date().toISOString(),
219
+ };
220
+ writeFileSync(join(targetDir, 'metadata.json'), JSON.stringify(meta, null, 2));
221
+ // Seed empty patterns and solutions
222
+ writeFileSync(join(targetDir, 'patterns.json'), JSON.stringify([], null, 2));
223
+ writeFileSync(join(targetDir, 'solutions.json'), JSON.stringify([], null, 2));
224
+ // Seed routing preferences based on expertise
225
+ const routingPrefs = buildRoutingPreferences(expertise);
226
+ writeFileSync(join(targetDir, 'routing-history.json'), JSON.stringify(routingPrefs, null, 2));
227
+ // Seed profile with expertise info
228
+ const userProfile = {
229
+ expertise,
230
+ preferred_languages: [expertise],
231
+ created_at: new Date().toISOString(),
232
+ };
233
+ writeFileSync(join(targetDir, 'profile.json'), JSON.stringify(userProfile, null, 2));
234
+ return { name: sanitized, created: true };
235
+ }
236
+ /**
237
+ * Returns which profile is currently loaded.
238
+ * Reads ~/.kbot/memory/active-profile.json.
239
+ */
240
+ export function getActiveProfile() {
241
+ ensureMemoryDir();
242
+ if (!existsSync(ACTIVE_PROFILE_FILE))
243
+ return null;
244
+ try {
245
+ return JSON.parse(readFileSync(ACTIVE_PROFILE_FILE, 'utf-8'));
246
+ }
247
+ catch {
248
+ return null;
249
+ }
250
+ }
251
+ /** Build initial routing preferences from an expertise keyword */
252
+ function buildRoutingPreferences(expertise) {
253
+ const agentMap = {
254
+ python: 'coder',
255
+ react: 'coder',
256
+ typescript: 'coder',
257
+ rust: 'coder',
258
+ go: 'coder',
259
+ java: 'coder',
260
+ swift: 'coder',
261
+ ruby: 'coder',
262
+ devops: 'infrastructure',
263
+ docker: 'infrastructure',
264
+ terraform: 'infrastructure',
265
+ kubernetes: 'infrastructure',
266
+ security: 'guardian',
267
+ design: 'aesthete',
268
+ writing: 'writer',
269
+ research: 'researcher',
270
+ data: 'quant',
271
+ trading: 'quant',
272
+ strategy: 'strategist',
273
+ };
274
+ const agent = agentMap[expertise.toLowerCase()] || 'coder';
275
+ const now = new Date().toISOString();
276
+ return [
277
+ {
278
+ intent: expertise.toLowerCase(),
279
+ keywords: [expertise.toLowerCase()],
280
+ agent,
281
+ method: 'category',
282
+ success: true,
283
+ count: 1,
284
+ lastUsed: now,
285
+ },
286
+ ];
287
+ }
288
+ //# sourceMappingURL=memory-hotswap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-hotswap.js","sourceRoot":"","sources":["../src/memory-hotswap.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,EAAE;AACF,2DAA2D;AAC3D,iEAAiE;AACj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 type: string;
4
+ /** Programming language (if detected) */
5
+ language: string | null;
6
+ /** Framework (if detected) */
7
+ framework: string | null;
8
+ /** Success rate 0-1 */
9
+ successRate: number;
10
+ /** Tool names used */
11
+ toolsUsed: string[];
12
+ /** Agent that handled it */
13
+ agentUsed: string | null;
14
+ /** Number of times this pattern was observed */
15
+ hits: number;
16
+ /** Keywords (generic tech terms) */
17
+ keywords: string[];
18
+ /** Confidence score (0-1) */
19
+ confidence: number;
20
+ /** Number of contributing sources */
21
+ sampleCount: number;
22
+ /** Last updated timestamp */
23
+ lastUpdated: string;
24
+ /** Source: 'local' or 'collective' */
25
+ source: 'local' | 'collective';
26
+ }
27
+ export interface FeedEntry {
28
+ /** Human-readable insight */
29
+ insight: string;
30
+ /** Feed category */
31
+ category: FeedCategory;
32
+ /** Relevance score (higher = more relevant) */
33
+ score: number;
34
+ /** Underlying pattern */
35
+ pattern: FeedPattern;
36
+ }
37
+ export type FeedCategory = 'tools_that_worked' | 'best_agents' | 'common_solutions' | 'forged_tools';
38
+ export interface FeedResult {
39
+ entries: FeedEntry[];
40
+ total_patterns_scanned: number;
41
+ project_type: string | null;
42
+ }
43
+ /** Format a single pattern as a readable insight */
44
+ export declare function formatFeedEntry(pattern: FeedPattern): string;
45
+ /**
46
+ * Run the pattern feed. Reads local + collective patterns, scores them,
47
+ * groups by category, and returns the top 20 insights.
48
+ *
49
+ * @param options.projectType - Optional project type filter (react, python, etc.)
50
+ * @returns Feed result with entries, total patterns scanned, and project type
51
+ */
52
+ export declare function runPatternFeed(options?: {
53
+ projectType?: string;
54
+ }): FeedResult;
55
+ /**
56
+ * Get a feed filtered for a specific project type.
57
+ * Returns patterns that other users of the same stack found useful.
58
+ */
59
+ export declare function getFeedForProject(projectType: string): FeedResult;
60
+ /**
61
+ * Full-text search across all patterns.
62
+ * Returns matching insights with confidence scores.
63
+ */
64
+ export declare function searchFeed(query: string): FeedEntry[];
65
+ //# sourceMappingURL=pattern-feed.d.ts.map
@@ -0,0 +1 @@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