@kernel.chat/kbot 3.17.2 → 3.19.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/cli.js +72 -1
- package/dist/cli.js.map +1 -1
- package/dist/observer.d.ts +34 -0
- package/dist/observer.d.ts.map +1 -0
- package/dist/observer.js +246 -0
- package/dist/observer.js.map +1 -0
- package/dist/seed-knowledge.d.ts +22 -0
- package/dist/seed-knowledge.d.ts.map +1 -0
- package/dist/seed-knowledge.js +176 -0
- package/dist/seed-knowledge.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface ObservedToolCall {
|
|
2
|
+
ts: string;
|
|
3
|
+
tool: string;
|
|
4
|
+
args?: Record<string, unknown>;
|
|
5
|
+
result_length?: number;
|
|
6
|
+
session?: string;
|
|
7
|
+
error?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface ObserverStats {
|
|
10
|
+
totalObserved: number;
|
|
11
|
+
sessionsObserved: number;
|
|
12
|
+
toolFrequency: Record<string, number>;
|
|
13
|
+
sequencesLearned: number;
|
|
14
|
+
factsLearned: number;
|
|
15
|
+
lastIngested: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Append a tool call observation to the log.
|
|
19
|
+
* Called by the Claude Code PostToolUse hook.
|
|
20
|
+
*/
|
|
21
|
+
export declare function recordObservation(entry: ObservedToolCall): void;
|
|
22
|
+
/**
|
|
23
|
+
* Read new observations from the log file and feed them into kbot's learning engine.
|
|
24
|
+
* Returns the number of new entries processed.
|
|
25
|
+
*/
|
|
26
|
+
export declare function ingestObservations(): Promise<{
|
|
27
|
+
processed: number;
|
|
28
|
+
patterns: number;
|
|
29
|
+
facts: number;
|
|
30
|
+
sessions: string[];
|
|
31
|
+
}>;
|
|
32
|
+
export declare function getObserverStats(): ObserverStats;
|
|
33
|
+
export declare function getLogPath(): string;
|
|
34
|
+
//# sourceMappingURL=observer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observer.d.ts","sourceRoot":"","sources":["../src/observer.ts"],"names":[],"mappings":"AAsBA,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,aAAa,EAAE,MAAM,CAAA;IACrB,gBAAgB,EAAE,MAAM,CAAA;IACxB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACrC,gBAAgB,EAAE,MAAM,CAAA;IACxB,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;CACrB;AAeD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAG/D;AAkDD;;;GAGG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC;IAClD,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB,CAAC,CA+JD;AAED,wBAAgB,gBAAgB,IAAI,aAAa,CAEhD;AAED,wBAAgB,UAAU,IAAI,MAAM,CAEnC"}
|
package/dist/observer.js
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
// kbot Observer — Learns from external agent sessions (Claude Code, Cursor, etc.)
|
|
2
|
+
//
|
|
3
|
+
// Watches a JSONL log of tool calls and outcomes, extracts patterns,
|
|
4
|
+
// solutions, and knowledge, and feeds them into kbot's learning engine.
|
|
5
|
+
//
|
|
6
|
+
// Usage:
|
|
7
|
+
// kbot observe # ingest latest observations
|
|
8
|
+
// kbot observe --watch # continuously watch for new entries
|
|
9
|
+
// kbot observe --stats # show what's been learned
|
|
10
|
+
//
|
|
11
|
+
// The log file is written by a Claude Code hook (PostToolUse) that appends
|
|
12
|
+
// one JSON line per tool call to ~/.kbot/observer/session.jsonl
|
|
13
|
+
//
|
|
14
|
+
// Format per line:
|
|
15
|
+
// {"ts":"ISO","tool":"Read","args":{"file_path":"/src/foo.ts"},"result_length":1234,"session":"abc"}
|
|
16
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync, appendFileSync } from 'node:fs';
|
|
17
|
+
import { join } from 'node:path';
|
|
18
|
+
import { homedir } from 'node:os';
|
|
19
|
+
// ── Constants ──
|
|
20
|
+
const OBSERVER_DIR = join(homedir(), '.kbot', 'observer');
|
|
21
|
+
const LOG_FILE = join(OBSERVER_DIR, 'session.jsonl');
|
|
22
|
+
const CURSOR_FILE = join(OBSERVER_DIR, 'cursor.json');
|
|
23
|
+
const STATS_FILE = join(OBSERVER_DIR, 'stats.json');
|
|
24
|
+
function ensureDir() {
|
|
25
|
+
if (!existsSync(OBSERVER_DIR))
|
|
26
|
+
mkdirSync(OBSERVER_DIR, { recursive: true });
|
|
27
|
+
}
|
|
28
|
+
// ── Log Writing (called by Claude Code hook) ──
|
|
29
|
+
/**
|
|
30
|
+
* Append a tool call observation to the log.
|
|
31
|
+
* Called by the Claude Code PostToolUse hook.
|
|
32
|
+
*/
|
|
33
|
+
export function recordObservation(entry) {
|
|
34
|
+
ensureDir();
|
|
35
|
+
appendFileSync(LOG_FILE, JSON.stringify(entry) + '\n');
|
|
36
|
+
}
|
|
37
|
+
// ── Log Reading ──
|
|
38
|
+
function loadCursor() {
|
|
39
|
+
if (!existsSync(CURSOR_FILE))
|
|
40
|
+
return { offset: 0, lastSession: '' };
|
|
41
|
+
try {
|
|
42
|
+
return JSON.parse(readFileSync(CURSOR_FILE, 'utf8'));
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return { offset: 0, lastSession: '' };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function saveCursor(cursor) {
|
|
49
|
+
ensureDir();
|
|
50
|
+
writeFileSync(CURSOR_FILE, JSON.stringify(cursor));
|
|
51
|
+
}
|
|
52
|
+
function loadStats() {
|
|
53
|
+
if (!existsSync(STATS_FILE))
|
|
54
|
+
return {
|
|
55
|
+
totalObserved: 0, sessionsObserved: 0,
|
|
56
|
+
toolFrequency: {}, sequencesLearned: 0, factsLearned: 0, lastIngested: '',
|
|
57
|
+
};
|
|
58
|
+
try {
|
|
59
|
+
return JSON.parse(readFileSync(STATS_FILE, 'utf8'));
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return { totalObserved: 0, sessionsObserved: 0, toolFrequency: {}, sequencesLearned: 0, factsLearned: 0, lastIngested: '' };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function saveStats(stats) {
|
|
66
|
+
ensureDir();
|
|
67
|
+
writeFileSync(STATS_FILE, JSON.stringify(stats, null, 2));
|
|
68
|
+
}
|
|
69
|
+
// ── Tool Name Mapping (Claude Code → kbot) ──
|
|
70
|
+
const TOOL_MAP = {
|
|
71
|
+
'Read': 'read_file',
|
|
72
|
+
'Write': 'write_file',
|
|
73
|
+
'Edit': 'edit_file',
|
|
74
|
+
'Bash': 'bash',
|
|
75
|
+
'Glob': 'glob',
|
|
76
|
+
'Grep': 'grep',
|
|
77
|
+
'WebSearch': 'web_search',
|
|
78
|
+
'WebFetch': 'url_fetch',
|
|
79
|
+
'Agent': 'subagent',
|
|
80
|
+
'Skill': 'skill',
|
|
81
|
+
};
|
|
82
|
+
function mapToolName(name) {
|
|
83
|
+
return TOOL_MAP[name] || name.toLowerCase();
|
|
84
|
+
}
|
|
85
|
+
// ── Core: Ingest Observations ──
|
|
86
|
+
/**
|
|
87
|
+
* Read new observations from the log file and feed them into kbot's learning engine.
|
|
88
|
+
* Returns the number of new entries processed.
|
|
89
|
+
*/
|
|
90
|
+
export async function ingestObservations() {
|
|
91
|
+
ensureDir();
|
|
92
|
+
if (!existsSync(LOG_FILE))
|
|
93
|
+
return { processed: 0, patterns: 0, facts: 0, sessions: [] };
|
|
94
|
+
// Dynamic import to avoid circular deps
|
|
95
|
+
const { updateProfile, learnFact, extractKeywords, flushPendingWrites } = await import('./learning.js');
|
|
96
|
+
const cursor = loadCursor();
|
|
97
|
+
const stats = loadStats();
|
|
98
|
+
const content = readFileSync(LOG_FILE, 'utf8');
|
|
99
|
+
const lines = content.split('\n').filter(l => l.trim());
|
|
100
|
+
if (lines.length <= cursor.offset) {
|
|
101
|
+
return { processed: 0, patterns: 0, facts: 0, sessions: [] };
|
|
102
|
+
}
|
|
103
|
+
const newLines = lines.slice(cursor.offset);
|
|
104
|
+
const entries = [];
|
|
105
|
+
for (const line of newLines) {
|
|
106
|
+
try {
|
|
107
|
+
entries.push(JSON.parse(line));
|
|
108
|
+
}
|
|
109
|
+
catch { /* skip malformed */ }
|
|
110
|
+
}
|
|
111
|
+
if (entries.length === 0) {
|
|
112
|
+
return { processed: 0, patterns: 0, facts: 0, sessions: [] };
|
|
113
|
+
}
|
|
114
|
+
// Group by session
|
|
115
|
+
const sessions = new Map();
|
|
116
|
+
for (const e of entries) {
|
|
117
|
+
const sid = e.session || 'unknown';
|
|
118
|
+
if (!sessions.has(sid))
|
|
119
|
+
sessions.set(sid, []);
|
|
120
|
+
sessions.get(sid).push(e);
|
|
121
|
+
}
|
|
122
|
+
let patternsLearned = 0;
|
|
123
|
+
let factsLearned = 0;
|
|
124
|
+
for (const [sessionId, calls] of sessions) {
|
|
125
|
+
// Extract tool sequence
|
|
126
|
+
const toolSequence = calls.map(c => mapToolName(c.tool));
|
|
127
|
+
// Update profile with observed tool usage
|
|
128
|
+
for (const tool of toolSequence) {
|
|
129
|
+
stats.toolFrequency[tool] = (stats.toolFrequency[tool] || 0) + 1;
|
|
130
|
+
}
|
|
131
|
+
// Detect task type from tool patterns
|
|
132
|
+
let taskType = 'general';
|
|
133
|
+
if (toolSequence.includes('bash') && (toolSequence.includes('read_file') || toolSequence.includes('edit_file'))) {
|
|
134
|
+
taskType = 'build';
|
|
135
|
+
}
|
|
136
|
+
if (toolSequence.filter(t => t === 'read_file').length > 3) {
|
|
137
|
+
taskType = 'explain';
|
|
138
|
+
}
|
|
139
|
+
if (toolSequence.includes('grep') || toolSequence.includes('glob')) {
|
|
140
|
+
taskType = 'debug';
|
|
141
|
+
}
|
|
142
|
+
if (toolSequence.includes('web_search') || toolSequence.includes('url_fetch')) {
|
|
143
|
+
taskType = 'search';
|
|
144
|
+
}
|
|
145
|
+
// Extract tech terms from file paths
|
|
146
|
+
const techTerms = [];
|
|
147
|
+
for (const call of calls) {
|
|
148
|
+
const filePath = String(call.args?.file_path || call.args?.path || call.args?.command || '');
|
|
149
|
+
if (filePath.includes('.ts') || filePath.includes('typescript'))
|
|
150
|
+
techTerms.push('typescript');
|
|
151
|
+
if (filePath.includes('.py'))
|
|
152
|
+
techTerms.push('python');
|
|
153
|
+
if (filePath.includes('.rs'))
|
|
154
|
+
techTerms.push('rust');
|
|
155
|
+
if (filePath.includes('.go'))
|
|
156
|
+
techTerms.push('go');
|
|
157
|
+
if (filePath.includes('package.json') || filePath.includes('npm'))
|
|
158
|
+
techTerms.push('npm');
|
|
159
|
+
if (filePath.includes('docker') || filePath.includes('Dockerfile'))
|
|
160
|
+
techTerms.push('docker');
|
|
161
|
+
if (filePath.includes('supabase'))
|
|
162
|
+
techTerms.push('supabase');
|
|
163
|
+
if (filePath.includes('react') || filePath.includes('.tsx'))
|
|
164
|
+
techTerms.push('react');
|
|
165
|
+
}
|
|
166
|
+
// Update kbot's profile
|
|
167
|
+
updateProfile({
|
|
168
|
+
tokens: calls.length * 500, // estimate
|
|
169
|
+
agent: 'observed-claude-code',
|
|
170
|
+
taskType,
|
|
171
|
+
techTerms: [...new Set(techTerms)],
|
|
172
|
+
message: `Observed session: ${toolSequence.slice(0, 5).join(' → ')}`,
|
|
173
|
+
success: !calls.some(c => c.error),
|
|
174
|
+
});
|
|
175
|
+
// Extract knowledge from bash commands
|
|
176
|
+
for (const call of calls) {
|
|
177
|
+
if (call.tool === 'Bash' && call.args?.command) {
|
|
178
|
+
const cmd = String(call.args.command);
|
|
179
|
+
// Learn npm publish patterns
|
|
180
|
+
if (cmd.includes('npm publish')) {
|
|
181
|
+
learnFact(`npm publish workflow: build → type-check → publish`, 'context', 'observed');
|
|
182
|
+
factsLearned++;
|
|
183
|
+
}
|
|
184
|
+
// Learn deployment patterns
|
|
185
|
+
if (cmd.includes('supabase functions deploy')) {
|
|
186
|
+
const match = cmd.match(/deploy\s+(\S+)/);
|
|
187
|
+
if (match) {
|
|
188
|
+
learnFact(`Edge function "${match[1]}" deployed via supabase CLI`, 'context', 'observed');
|
|
189
|
+
factsLearned++;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
// Learn docker patterns
|
|
193
|
+
if (cmd.includes('docker build') || cmd.includes('docker push')) {
|
|
194
|
+
learnFact(`Docker workflow: build → tag → push to Docker Hub`, 'context', 'observed');
|
|
195
|
+
factsLearned++;
|
|
196
|
+
}
|
|
197
|
+
// Learn git workflow
|
|
198
|
+
if (cmd.includes('git push')) {
|
|
199
|
+
learnFact(`Git workflow: stage specific files → commit with Co-Authored-By → push`, 'context', 'observed');
|
|
200
|
+
factsLearned++;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
// Learn from file edits — which files get edited together
|
|
204
|
+
if (call.tool === 'Edit' || call.tool === 'Write') {
|
|
205
|
+
const filePath = String(call.args?.file_path || '');
|
|
206
|
+
if (filePath.includes('cli.ts')) {
|
|
207
|
+
learnFact(`cli.ts is the main entry point — new commands are registered here`, 'context', 'observed');
|
|
208
|
+
factsLearned++;
|
|
209
|
+
}
|
|
210
|
+
if (filePath.includes('matrix.ts')) {
|
|
211
|
+
learnFact(`matrix.ts holds BUILTIN_AGENTS — new agents must be added here`, 'context', 'observed');
|
|
212
|
+
factsLearned++;
|
|
213
|
+
}
|
|
214
|
+
if (filePath.includes('package.json') && filePath.includes('kbot')) {
|
|
215
|
+
learnFact(`Version bump in package.json before npm publish`, 'context', 'observed');
|
|
216
|
+
factsLearned++;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
patternsLearned++;
|
|
221
|
+
}
|
|
222
|
+
// Update stats
|
|
223
|
+
stats.totalObserved += entries.length;
|
|
224
|
+
stats.sessionsObserved += sessions.size;
|
|
225
|
+
stats.sequencesLearned += patternsLearned;
|
|
226
|
+
stats.factsLearned += factsLearned;
|
|
227
|
+
stats.lastIngested = new Date().toISOString();
|
|
228
|
+
saveStats(stats);
|
|
229
|
+
// Update cursor
|
|
230
|
+
saveCursor({ offset: lines.length, lastSession: [...sessions.keys()].pop() || '' });
|
|
231
|
+
// Flush learning data to disk
|
|
232
|
+
flushPendingWrites();
|
|
233
|
+
return {
|
|
234
|
+
processed: entries.length,
|
|
235
|
+
patterns: patternsLearned,
|
|
236
|
+
facts: factsLearned,
|
|
237
|
+
sessions: [...sessions.keys()],
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
export function getObserverStats() {
|
|
241
|
+
return loadStats();
|
|
242
|
+
}
|
|
243
|
+
export function getLogPath() {
|
|
244
|
+
return LOG_FILE;
|
|
245
|
+
}
|
|
246
|
+
//# sourceMappingURL=observer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observer.js","sourceRoot":"","sources":["../src/observer.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,EAAE;AACF,qEAAqE;AACrE,wEAAwE;AACxE,EAAE;AACF,SAAS;AACT,iEAAiE;AACjE,yEAAyE;AACzE,+DAA+D;AAC/D,EAAE;AACF,2EAA2E;AAC3E,gEAAgE;AAChE,EAAE;AACF,mBAAmB;AACnB,uGAAuG;AAEvG,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,cAAc,EAAY,MAAM,SAAS,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AACjB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface SeedPattern {
|
|
2
|
+
intent: string;
|
|
3
|
+
keywords: string[];
|
|
4
|
+
toolSequence: string[];
|
|
5
|
+
category: string;
|
|
6
|
+
}
|
|
7
|
+
export interface SeedKnowledge {
|
|
8
|
+
fact: string;
|
|
9
|
+
category: 'context' | 'fact' | 'preference' | 'workflow';
|
|
10
|
+
}
|
|
11
|
+
export declare const SEED_PATTERNS: SeedPattern[];
|
|
12
|
+
export declare const SEED_KNOWLEDGE: SeedKnowledge[];
|
|
13
|
+
/**
|
|
14
|
+
* Load seed knowledge into kbot's learning engine on first run.
|
|
15
|
+
* Only runs if no existing patterns/knowledge exist (new install).
|
|
16
|
+
*/
|
|
17
|
+
export declare function loadSeedKnowledge(): Promise<{
|
|
18
|
+
seeded: boolean;
|
|
19
|
+
patterns: number;
|
|
20
|
+
facts: number;
|
|
21
|
+
}>;
|
|
22
|
+
//# sourceMappingURL=seed-knowledge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed-knowledge.d.ts","sourceRoot":"","sources":["../src/seed-knowledge.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,SAAS,GAAG,MAAM,GAAG,YAAY,GAAG,UAAU,CAAA;CACzD;AAID,eAAO,MAAM,aAAa,EAAE,WAAW,EA4FtC,CAAA;AAID,eAAO,MAAM,cAAc,EAAE,aAAa,EA4BzC,CAAA;AAID;;;GAGG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAgDvG"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// kbot Seed Knowledge — Ships with the npm package
|
|
2
|
+
//
|
|
3
|
+
// Universal patterns and knowledge that every kbot user benefits from.
|
|
4
|
+
// Extracted from real usage across 50+ sessions of building software.
|
|
5
|
+
// NOT personal data — these are general engineering patterns.
|
|
6
|
+
//
|
|
7
|
+
// On first run, kbot loads these into the learning engine if no
|
|
8
|
+
// existing knowledge exists. Users who already have patterns keep theirs.
|
|
9
|
+
import { homedir } from 'node:os';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
12
|
+
// ── Seed Patterns: tool sequences that work ──
|
|
13
|
+
export const SEED_PATTERNS = [
|
|
14
|
+
// Build & Deploy
|
|
15
|
+
{
|
|
16
|
+
intent: 'build and publish npm package',
|
|
17
|
+
keywords: ['npm', 'publish', 'build', 'package', 'release'],
|
|
18
|
+
toolSequence: ['read_file', 'edit_file', 'bash', 'bash', 'bash'],
|
|
19
|
+
category: 'build',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
intent: 'type check typescript project',
|
|
23
|
+
keywords: ['typescript', 'type', 'check', 'tsc', 'errors'],
|
|
24
|
+
toolSequence: ['bash'],
|
|
25
|
+
category: 'build',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
intent: 'deploy edge function supabase',
|
|
29
|
+
keywords: ['supabase', 'deploy', 'edge', 'function'],
|
|
30
|
+
toolSequence: ['read_file', 'edit_file', 'bash'],
|
|
31
|
+
category: 'deploy',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
intent: 'build and push docker image',
|
|
35
|
+
keywords: ['docker', 'build', 'push', 'image', 'container'],
|
|
36
|
+
toolSequence: ['read_file', 'edit_file', 'bash', 'bash'],
|
|
37
|
+
category: 'deploy',
|
|
38
|
+
},
|
|
39
|
+
// Code Changes
|
|
40
|
+
{
|
|
41
|
+
intent: 'add new cli command',
|
|
42
|
+
keywords: ['cli', 'command', 'add', 'new', 'subcommand'],
|
|
43
|
+
toolSequence: ['read_file', 'read_file', 'edit_file', 'bash'],
|
|
44
|
+
category: 'build',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
intent: 'fix bug in code',
|
|
48
|
+
keywords: ['fix', 'bug', 'error', 'broken', 'failing'],
|
|
49
|
+
toolSequence: ['grep', 'read_file', 'edit_file', 'bash'],
|
|
50
|
+
category: 'debug',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
intent: 'add new feature module',
|
|
54
|
+
keywords: ['new', 'feature', 'module', 'create', 'add'],
|
|
55
|
+
toolSequence: ['read_file', 'write_file', 'edit_file', 'bash'],
|
|
56
|
+
category: 'build',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
intent: 'write tests for module',
|
|
60
|
+
keywords: ['test', 'write', 'tests', 'vitest', 'jest'],
|
|
61
|
+
toolSequence: ['read_file', 'write_file', 'bash'],
|
|
62
|
+
category: 'test',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
intent: 'refactor existing code',
|
|
66
|
+
keywords: ['refactor', 'clean', 'improve', 'restructure'],
|
|
67
|
+
toolSequence: ['read_file', 'read_file', 'edit_file', 'edit_file', 'bash'],
|
|
68
|
+
category: 'build',
|
|
69
|
+
},
|
|
70
|
+
// Research & Understanding
|
|
71
|
+
{
|
|
72
|
+
intent: 'explain project or codebase',
|
|
73
|
+
keywords: ['explain', 'what', 'does', 'project', 'how', 'works'],
|
|
74
|
+
toolSequence: ['read_file', 'read_file', 'glob', 'read_file'],
|
|
75
|
+
category: 'explain',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
intent: 'find where something is defined',
|
|
79
|
+
keywords: ['find', 'where', 'defined', 'located', 'search'],
|
|
80
|
+
toolSequence: ['grep', 'read_file'],
|
|
81
|
+
category: 'explain',
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
intent: 'research topic on web',
|
|
85
|
+
keywords: ['research', 'search', 'find', 'look', 'what', 'latest'],
|
|
86
|
+
toolSequence: ['web_search', 'url_fetch'],
|
|
87
|
+
category: 'search',
|
|
88
|
+
},
|
|
89
|
+
// Git & Version Control
|
|
90
|
+
{
|
|
91
|
+
intent: 'commit and push changes',
|
|
92
|
+
keywords: ['commit', 'push', 'git', 'save', 'ship'],
|
|
93
|
+
toolSequence: ['bash', 'bash', 'bash'],
|
|
94
|
+
category: 'build',
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
intent: 'review git changes',
|
|
98
|
+
keywords: ['diff', 'changes', 'what', 'changed', 'review'],
|
|
99
|
+
toolSequence: ['bash', 'bash'],
|
|
100
|
+
category: 'explain',
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
// ── Seed Knowledge: universal engineering facts ──
|
|
104
|
+
export const SEED_KNOWLEDGE = [
|
|
105
|
+
// Build workflows
|
|
106
|
+
{ fact: 'Always type-check (tsc --noEmit) before publishing to npm', category: 'workflow' },
|
|
107
|
+
{ fact: 'npm publish requires: version bump → build → type-check → publish', category: 'workflow' },
|
|
108
|
+
{ fact: 'Docker images should be tagged with version AND latest', category: 'workflow' },
|
|
109
|
+
{ fact: 'Supabase edge functions deploy via: npx supabase functions deploy <name> --project-ref <ref>', category: 'workflow' },
|
|
110
|
+
{ fact: 'Git commits should be atomic — one logical change per commit', category: 'workflow' },
|
|
111
|
+
// TypeScript/Node patterns
|
|
112
|
+
{ fact: 'package.json "files" field controls what ships to npm — only listed dirs are included', category: 'fact' },
|
|
113
|
+
{ fact: 'Commander.js subcommands need explicit process.exit(0) or they fall through to the default action', category: 'fact' },
|
|
114
|
+
{ fact: 'Dynamic imports (await import()) are better than static imports for CLI tools — faster startup', category: 'fact' },
|
|
115
|
+
{ fact: 'vitest tests use describe/it/expect — same API as Jest but faster', category: 'fact' },
|
|
116
|
+
// Architecture patterns
|
|
117
|
+
{ fact: 'New CLI commands go in cli.ts and must be added to the subcommand exit list', category: 'context' },
|
|
118
|
+
{ fact: 'New specialist agents must be added to BUILTIN_AGENTS in matrix.ts', category: 'context' },
|
|
119
|
+
{ fact: 'Agent count in README, share.ts, cli.ts status, and package.json description must all match', category: 'context' },
|
|
120
|
+
{ fact: 'The learning engine only records data from kbot sessions — external agent activity needs the observer', category: 'context' },
|
|
121
|
+
// Testing
|
|
122
|
+
{ fact: 'Write tests for new modules before publishing — untested code erodes trust', category: 'workflow' },
|
|
123
|
+
{ fact: 'Test edge cases and error paths, not just happy paths', category: 'workflow' },
|
|
124
|
+
// Distribution
|
|
125
|
+
{ fact: 'README is the npm landing page — it must be accurate and compelling for new users', category: 'workflow' },
|
|
126
|
+
{ fact: 'Docker Hub images go stale if not rebuilt after npm updates — check after every release', category: 'workflow' },
|
|
127
|
+
{ fact: 'Shields.io badges in README increase perceived professionalism and click-through', category: 'fact' },
|
|
128
|
+
];
|
|
129
|
+
// ── Seed Loading ──
|
|
130
|
+
/**
|
|
131
|
+
* Load seed knowledge into kbot's learning engine on first run.
|
|
132
|
+
* Only runs if no existing patterns/knowledge exist (new install).
|
|
133
|
+
*/
|
|
134
|
+
export async function loadSeedKnowledge() {
|
|
135
|
+
const memDir = join(homedir(), '.kbot', 'memory');
|
|
136
|
+
const patternsFile = join(memDir, 'patterns.json');
|
|
137
|
+
const knowledgeFile = join(memDir, 'knowledge.json');
|
|
138
|
+
// Check if user already has learning data — don't overwrite
|
|
139
|
+
const hasPatterns = existsSync(patternsFile) && JSON.parse(readFileSync(patternsFile, 'utf8')).length > 0;
|
|
140
|
+
const hasKnowledge = existsSync(knowledgeFile) && JSON.parse(readFileSync(knowledgeFile, 'utf8')).length > 2;
|
|
141
|
+
if (hasPatterns && hasKnowledge) {
|
|
142
|
+
return { seeded: false, patterns: 0, facts: 0 };
|
|
143
|
+
}
|
|
144
|
+
// Load learning engine and seed
|
|
145
|
+
const { learnFact, flushPendingWrites } = await import('./learning.js');
|
|
146
|
+
let factsSeeded = 0;
|
|
147
|
+
if (!hasKnowledge) {
|
|
148
|
+
for (const k of SEED_KNOWLEDGE) {
|
|
149
|
+
learnFact(k.fact, k.category, 'observed');
|
|
150
|
+
factsSeeded++;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// Seed patterns by writing directly (the learning engine API expects runtime usage)
|
|
154
|
+
let patternsSeeded = 0;
|
|
155
|
+
if (!hasPatterns) {
|
|
156
|
+
const { writeFileSync, mkdirSync } = await import('node:fs');
|
|
157
|
+
if (!existsSync(memDir))
|
|
158
|
+
mkdirSync(memDir, { recursive: true });
|
|
159
|
+
const seedPatterns = SEED_PATTERNS.map(p => ({
|
|
160
|
+
intent: p.intent,
|
|
161
|
+
keywords: p.keywords,
|
|
162
|
+
toolSequence: p.toolSequence,
|
|
163
|
+
hits: 3, // pretend each was used 3x so they have weight
|
|
164
|
+
successRate: 0.9,
|
|
165
|
+
lastUsed: new Date().toISOString(),
|
|
166
|
+
avgTokensSaved: 0,
|
|
167
|
+
}));
|
|
168
|
+
if (!existsSync(patternsFile) || JSON.parse(readFileSync(patternsFile, 'utf8')).length === 0) {
|
|
169
|
+
writeFileSync(patternsFile, JSON.stringify(seedPatterns, null, 2));
|
|
170
|
+
patternsSeeded = seedPatterns.length;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
flushPendingWrites();
|
|
174
|
+
return { seeded: true, patterns: patternsSeeded, facts: factsSeeded };
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=seed-knowledge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seed-knowledge.js","sourceRoot":"","sources":["../src/seed-knowledge.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,EAAE;AACF,uEAAuE;AACvE,sEAAsE;AACtE,8DAA8D;AAC9D,EAAE;AACF,gEAAgE;AAChE,0EAA0E;AAE1E,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,E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I,IAAI,EAAE,CAAC,WAAW,EAAE;YAClC,cAAc,EAAE,CAAC;SAClB,CAAC,CAAC,CAAA;QAEH,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7F,aAAa,CAAC,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;YAClE,cAAc,GAAG,YAAY,CAAC,MAAM,CAAA;QACtC,CAAC;IACH,CAAC;IAED,kBAAkB,EAAE,CAAA;IACpB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,WAAW,EAAE,CAAA;AACvE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kernel.chat/kbot",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.19.0",
|
|
4
4
|
"description": "The only AI agent that builds its own tools. Multi-channel cognitive engine: email agent, iMessage agent, consultation pipeline, 25 specialist agents, 290+ tools, 20 providers. Runtime tool forging, Forge Registry, autopoietic health, immune self-audit. Cost-aware model routing, fallback chains, Bayesian skill routing. Embedded llama.cpp, MCP server, SDK. MIT.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|