@kernel.chat/kbot 3.6.1 → 3.7.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,92 @@
1
+ // Skills Loader — Auto-discover and load .md skill files
2
+ //
3
+ // Skill files are Markdown documents that inject domain knowledge, tool combinations,
4
+ // and project-specific patterns into the agent's context. They're the kbot equivalent
5
+ // of Copilot's "Agent Skills" or Cursor's "Rules for AI."
6
+ //
7
+ // Discovery locations (in priority order):
8
+ // 1. ./.kbot/skills/*.md — project-specific skills
9
+ // 2. ~/.kbot/skills/*.md — user global skills
10
+ //
11
+ // Token budget: 2000 tokens max (~8000 characters) to leave room for
12
+ // repo map, learning context, and memory.
13
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
14
+ import { join, basename } from 'node:path';
15
+ import { homedir } from 'node:os';
16
+ const MAX_SKILL_TOKENS = 2000;
17
+ const estimateTokens = (text) => Math.ceil(text.length / 4);
18
+ /**
19
+ * Discover and load skill files from project and global directories.
20
+ * Returns formatted string ready to inject into system prompt.
21
+ */
22
+ export function loadSkills(projectRoot) {
23
+ const skills = discoverSkillFiles(projectRoot);
24
+ if (skills.length === 0)
25
+ return '';
26
+ return formatSkillsForPrompt(skills);
27
+ }
28
+ /**
29
+ * Discover .md files from both project-local and global skill directories.
30
+ * Project skills take precedence (loaded first, consume token budget first).
31
+ */
32
+ export function discoverSkillFiles(projectRoot) {
33
+ const locations = [
34
+ join(projectRoot, '.kbot', 'skills'), // Project-specific
35
+ join(homedir(), '.kbot', 'skills'), // User global
36
+ ];
37
+ const skills = [];
38
+ const seen = new Set(); // Deduplicate by filename
39
+ for (const dir of locations) {
40
+ if (!existsSync(dir))
41
+ continue;
42
+ try {
43
+ const files = readdirSync(dir)
44
+ .filter(f => f.endsWith('.md'))
45
+ .sort(); // Alphabetical for deterministic ordering
46
+ for (const file of files) {
47
+ if (seen.has(file))
48
+ continue; // Project overrides global
49
+ seen.add(file);
50
+ try {
51
+ const path = join(dir, file);
52
+ const content = readFileSync(path, 'utf-8').trim();
53
+ if (content.length === 0)
54
+ continue;
55
+ skills.push({
56
+ name: basename(file, '.md'),
57
+ path,
58
+ content,
59
+ tokens: estimateTokens(content),
60
+ });
61
+ }
62
+ catch { /* permission denied, etc. */ }
63
+ }
64
+ }
65
+ catch { /* directory read error */ }
66
+ }
67
+ return skills;
68
+ }
69
+ /**
70
+ * Format skill files for prompt injection, respecting token budget.
71
+ */
72
+ function formatSkillsForPrompt(skills, maxTokens = MAX_SKILL_TOKENS) {
73
+ const parts = [];
74
+ let currentTokens = 0;
75
+ for (const skill of skills) {
76
+ if (currentTokens + skill.tokens > maxTokens) {
77
+ // Try to fit a truncated version
78
+ const remaining = maxTokens - currentTokens;
79
+ if (remaining > 100) {
80
+ const truncated = skill.content.slice(0, remaining * 4) + '\n...(truncated)';
81
+ parts.push(`## Skill: ${skill.name}\n${truncated}`);
82
+ }
83
+ break;
84
+ }
85
+ parts.push(`## Skill: ${skill.name}\n${skill.content}`);
86
+ currentTokens += skill.tokens;
87
+ }
88
+ if (parts.length === 0)
89
+ return '';
90
+ return `\n\n[Custom Skills]\n${parts.join('\n---\n')}`;
91
+ }
92
+ //# sourceMappingURL=skills-loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skills-loader.js","sourceRoot":"","sources":["../src/skills-loader.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,EAAE;AACF,sFAAsF;AACtF,sFAAsF;AACtF,0DAA0D;AAC1D,EAAE;AACF,2CAA2C;AAC3C,sDAAsD;AACtD,iDAAiD;AACjD,EAAE;AACF,qEAAqE;AACrE,0CAA0C;AAE1C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC/D,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEjC,MAAM,gBAAg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QACvD,aAAa,IAAI,KAAK,CAAC,MAAM,CAAA;IAC/B,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAA;IACjC,OAAO,wBAAwB,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAA;AACxD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kernel.chat/kbot",
3
- "version": "3.6.1",
3
+ "version": "3.7.0",
4
4
  "description": "The only AI agent that builds its own tools. Self-evolving terminal AI: 290 tools, 23 agents, 20 providers. Runtime tool forging via forge_tool, Forge Registry for community tools, autopoietic health monitoring, immune self-audit agent. Cost-aware model routing, fallback chains, Bayesian skill routing. Embedded llama.cpp, MCP server, programmatic SDK. MIT.",
5
5
  "type": "module",
6
6
  "repository": {