@poolzin/pool-bot 2026.4.30 → 2026.4.31

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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2026.4.30",
3
- "commit": "5f9af9dece19adb17df979c3289aaaa316cc0b89",
4
- "builtAt": "2026-04-04T22:23:55.184Z"
2
+ "version": "2026.4.31",
3
+ "commit": "4486adc8409ed1305aa5fee2a37117ff7cab5aab",
4
+ "builtAt": "2026-04-04T22:45:58.617Z"
5
5
  }
@@ -1 +1 @@
1
- {"version":3,"file":"config-cli.d.ts","sourceRoot":"","sources":["../../src/cli/config-cli.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQzC,OAAO,EAAE,KAAK,UAAU,EAAkB,MAAM,eAAe,CAAC;AAyXhE,wBAAsB,YAAY,CAAC,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,UAAU,CAAA;CAAE,iBA4B9F;AAED,wBAAsB,cAAc,CAAC,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,UAAU,CAAA;CAAE,iBAqBhF;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,QAiOjD"}
1
+ {"version":3,"file":"config-cli.d.ts","sourceRoot":"","sources":["../../src/cli/config-cli.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQzC,OAAO,EAAE,KAAK,UAAU,EAAkB,MAAM,eAAe,CAAC;AA6XhE,wBAAsB,YAAY,CAAC,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,UAAU,CAAA;CAAE,iBA4B9F;AAED,wBAAsB,cAAc,CAAC,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,UAAU,CAAA;CAAE,iBAqBhF;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,QAkSjD"}
@@ -6,6 +6,10 @@ import { formatDocsLink } from "../terminal/links.js";
6
6
  import { formatCliCommand } from "./command-format.js";
7
7
  import { theme } from "../terminal/theme.js";
8
8
  import { shortenHomePath } from "../utils.js";
9
+ import { evolveSkill, findSkill } from "../infra/skill-evolution.js";
10
+ import { resolveAgentWorkspaceDir, resolveDefaultAgentId } from "../agents/agent-scope.js";
11
+ import { callGatewayFromCli } from "./gateway-rpc.js";
12
+ import { loadConfig } from "../config/config.js";
9
13
  function generateConfigJsonSchema() {
10
14
  return {
11
15
  $schema: "http://json-schema.org/draft-07/schema#",
@@ -633,4 +637,56 @@ export function registerConfigCli(program) {
633
637
  defaultRuntime.exit(1);
634
638
  }
635
639
  });
640
+ cmd
641
+ .command("evolve-skill")
642
+ .description("Evolve a skill file using LLM-based optimization (GEPA-inspired)")
643
+ .argument("<skill>", "Skill name or path to evolve")
644
+ .option("-n, --iterations <n>", "Number of optimization iterations", "5")
645
+ .option("--dry-run", "Show improvements without writing", false)
646
+ .action(async (skillName, opts) => {
647
+ try {
648
+ const cfg = loadConfig();
649
+ const agentId = resolveDefaultAgentId(cfg);
650
+ const workspaceDir = resolveAgentWorkspaceDir(cfg, agentId);
651
+ const skillsDir = `${workspaceDir}/skills`;
652
+ let skillPath = null;
653
+ // Check if it's a direct path
654
+ if (skillName.includes("/") || skillName.includes("\\")) {
655
+ skillPath = skillName;
656
+ }
657
+ else {
658
+ skillPath = findSkill(skillName, skillsDir);
659
+ }
660
+ if (!skillPath) {
661
+ defaultRuntime.error(danger(`Skill '${skillName}' not found in ${skillsDir}`));
662
+ defaultRuntime.exit(1);
663
+ return;
664
+ }
665
+ const iterations = parseInt(opts.iterations, 10) || 5;
666
+ const dryRun = opts.dryRun === true;
667
+ defaultRuntime.log(info(`Evolving skill: ${skillPath}`));
668
+ defaultRuntime.log(info(`Iterations: ${iterations}, Dry run: ${dryRun}`));
669
+ // LLM call via gateway
670
+ const llmCall = async (prompt, systemPrompt) => {
671
+ const result = await callGatewayFromCli("agent.chat", {}, {
672
+ message: prompt,
673
+ systemPrompt,
674
+ model: cfg.agents?.defaults?.model?.primary,
675
+ });
676
+ return result?.reply ?? "";
677
+ };
678
+ const result = await evolveSkill({ skillPath, llmCall, config: { iterations, dryRun } });
679
+ if (result.improved && result.bestCandidate) {
680
+ defaultRuntime.log(info(`✅ Improved! ${result.original.name}: ${result.bestCandidate.score.toFixed(3)} (was baseline)`));
681
+ }
682
+ else {
683
+ defaultRuntime.log(info(`No improvement found for ${result.original.name}`));
684
+ }
685
+ defaultRuntime.exit(0);
686
+ }
687
+ catch (err) {
688
+ defaultRuntime.error(danger(String(err)));
689
+ defaultRuntime.exit(1);
690
+ }
691
+ });
636
692
  }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Self-evolving skill optimizer for PoolBot.
3
+ *
4
+ * Inspired by Hermes Agent Self-Evolution (DSPy + GEPA).
5
+ * Uses the agent's own LLM to propose and evaluate skill improvements.
6
+ *
7
+ * Flow:
8
+ * 1. Load a skill file (SKILL.md or similar)
9
+ * 2. Generate improvement candidates via LLM
10
+ * 3. Evaluate candidates via LLM judge
11
+ * 4. Save the best candidate if it beats the baseline
12
+ */
13
+ export type SkillArtifact = {
14
+ path: string;
15
+ name: string;
16
+ content: string;
17
+ size: number;
18
+ };
19
+ export type EvalTask = {
20
+ input: string;
21
+ expectedBehavior: string;
22
+ };
23
+ export type EvalResult = {
24
+ correctness: number;
25
+ procedureFollowing: number;
26
+ conciseness: number;
27
+ lengthPenalty: number;
28
+ feedback: string;
29
+ };
30
+ export type CandidateScore = {
31
+ variant: string;
32
+ score: number;
33
+ eval: EvalResult;
34
+ };
35
+ export type EvolutionConfig = {
36
+ /** Max iterations (default: 5) */
37
+ iterations?: number;
38
+ /** Max skill size in chars (default: 15000) */
39
+ maxSize?: number;
40
+ /** Dry run — don't write changes (default: false) */
41
+ dryRun?: boolean;
42
+ };
43
+ export type LLMCallFn = (prompt: string, systemPrompt: string) => Promise<string>;
44
+ export declare function loadSkill(path: string): SkillArtifact;
45
+ export declare function findSkill(skillName: string, skillsDir: string): string | null;
46
+ export declare function generateCandidates(skill: SkillArtifact, count: number, llmCall: LLMCallFn): Promise<string[]>;
47
+ export declare function evaluateCandidate(original: SkillArtifact, candidate: string, llmCall: LLMCallFn): Promise<EvalResult>;
48
+ export declare function evolveSkill(params: {
49
+ skillPath: string;
50
+ llmCall: LLMCallFn;
51
+ config?: EvolutionConfig;
52
+ }): Promise<{
53
+ original: SkillArtifact;
54
+ bestCandidate: CandidateScore | null;
55
+ improved: boolean;
56
+ }>;
57
+ //# sourceMappingURL=skill-evolution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skill-evolution.d.ts","sourceRoot":"","sources":["../../src/infra/skill-evolution.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAWH,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,UAAU,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,kCAAkC;IAClC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+CAA+C;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qDAAqD;IACrD,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAIF,MAAM,MAAM,SAAS,GAAG,CACtB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,KACjB,OAAO,CAAC,MAAM,CAAC,CAAC;AAIrB,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAOrD;AAED,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAgB7E;AAoBD,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,aAAa,EACpB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,SAAS,GACjB,OAAO,CAAC,MAAM,EAAE,CAAC,CAgBnB;AA6BD,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,aAAa,EACvB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,SAAS,GACjB,OAAO,CAAC,UAAU,CAAC,CAgCrB;AAUD,wBAAsB,WAAW,CAAC,MAAM,EAAE;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,SAAS,CAAC;IACnB,MAAM,CAAC,EAAE,eAAe,CAAC;CAC1B,GAAG,OAAO,CAAC;IACV,QAAQ,EAAE,aAAa,CAAC;IACxB,aAAa,EAAE,cAAc,GAAG,IAAI,CAAC;IACrC,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC,CAiED"}
@@ -0,0 +1,183 @@
1
+ /**
2
+ * Self-evolving skill optimizer for PoolBot.
3
+ *
4
+ * Inspired by Hermes Agent Self-Evolution (DSPy + GEPA).
5
+ * Uses the agent's own LLM to propose and evaluate skill improvements.
6
+ *
7
+ * Flow:
8
+ * 1. Load a skill file (SKILL.md or similar)
9
+ * 2. Generate improvement candidates via LLM
10
+ * 3. Evaluate candidates via LLM judge
11
+ * 4. Save the best candidate if it beats the baseline
12
+ */
13
+ import { readFileSync, writeFileSync, existsSync } from "node:fs";
14
+ import { join } from "node:path";
15
+ import { createSubsystemLogger } from "../logging/subsystem.js";
16
+ const log = createSubsystemLogger("skill-evolution");
17
+ // ── Skill Loading ──────────────────────────────────────────────────────
18
+ export function loadSkill(path) {
19
+ if (!existsSync(path)) {
20
+ throw new Error(`Skill file not found: ${path}`);
21
+ }
22
+ const content = readFileSync(path, "utf-8");
23
+ const name = path.split("/").pop()?.replace(/\.(md|txt|skill)$/, "") ?? "unknown";
24
+ return { path, name, content, size: content.length };
25
+ }
26
+ export function findSkill(skillName, skillsDir) {
27
+ if (!existsSync(skillsDir))
28
+ return null;
29
+ // Try exact match with common extensions
30
+ for (const ext of [".md", ".txt", ".skill", ""]) {
31
+ const candidate = join(skillsDir, `${skillName}${ext}`);
32
+ if (existsSync(candidate))
33
+ return candidate;
34
+ }
35
+ // Try subdirectory
36
+ const subdir = join(skillsDir, skillName);
37
+ if (existsSync(subdir)) {
38
+ for (const ext of [".md", ".txt", ".skill", ""]) {
39
+ const candidate = join(subdir, `SKILL${ext}`);
40
+ if (existsSync(candidate))
41
+ return candidate;
42
+ }
43
+ }
44
+ return null;
45
+ }
46
+ // ── Candidate Generation ───────────────────────────────────────────────
47
+ const GENERATE_VARIANTS_PROMPT = `You are an expert prompt engineer optimizing agent skill instructions.
48
+
49
+ Current skill:
50
+ \`\`\`
51
+ {currentSkill}
52
+ \`\`\`
53
+
54
+ Generate {count} improved variants. Each variant should:
55
+ 1. Be clearer and more actionable
56
+ 2. Use specific, measurable language
57
+ 3. Include edge case handling
58
+ 4. Be concise (no unnecessary verbosity)
59
+ 5. Maintain the original skill's purpose
60
+
61
+ Return ONLY the variants, numbered 1 to {count}, each wrapped in \`\`\` markers.`;
62
+ export async function generateCandidates(skill, count, llmCall) {
63
+ const prompt = GENERATE_VARIANTS_PROMPT
64
+ .replace("{currentSkill}", skill.content)
65
+ .replace(/{count}/g, String(count));
66
+ const systemPrompt = "You are an expert prompt engineer. Generate improved skill variants. " +
67
+ "Return ONLY the numbered variants in code blocks. No explanations.";
68
+ const response = await llmCall(prompt, systemPrompt);
69
+ // Extract code blocks
70
+ const blocks = response.match(/```[\s\S]*?```/g) ?? [];
71
+ return blocks
72
+ .map((b) => b.replace(/^```[a-z]*\n?/i, "").replace(/```$/, "").trim())
73
+ .filter((b) => b.length > 0);
74
+ }
75
+ // ── Evaluation ─────────────────────────────────────────────────────────
76
+ const EVALUATE_PROMPT = `You are an expert evaluator of agent skill instructions.
77
+
78
+ Original skill:
79
+ \`\`\`
80
+ {originalSkill}
81
+ \`\`\`
82
+
83
+ Candidate variant:
84
+ \`\`\`
85
+ {candidateSkill}
86
+ \`\`\`
87
+
88
+ Evaluate the candidate on these dimensions (0.0 to 1.0 each):
89
+ 1. **correctness**: Does it cover the same ground as the original? Would it produce correct agent behavior?
90
+ 2. **clarity**: Is it clearer and less ambiguous than the original?
91
+ 3. **conciseness**: Is it appropriately concise without losing important details?
92
+
93
+ Also provide a length penalty (0.0 to 1.0, where 0 = no penalty):
94
+ - If the candidate is significantly longer than the original without proportional improvement, apply a penalty.
95
+
96
+ Return your evaluation as JSON:
97
+ {"correctness": 0.85, "clarity": 0.9, "conciseness": 0.8, "lengthPenalty": 0.1, "feedback": "Specific feedback"}
98
+
99
+ Do NOT include any other text.`;
100
+ export async function evaluateCandidate(original, candidate, llmCall) {
101
+ const prompt = EVALUATE_PROMPT
102
+ .replace("{originalSkill}", original.content)
103
+ .replace("{candidateSkill}", candidate);
104
+ const systemPrompt = "You are an expert evaluator. Score the candidate skill variant. " +
105
+ "Return ONLY a JSON object with correctness, clarity, conciseness, lengthPenalty, and feedback.";
106
+ const response = await llmCall(prompt, systemPrompt);
107
+ // Extract JSON
108
+ const jsonMatch = response.match(/\{[\s\S]*\}/);
109
+ if (!jsonMatch) {
110
+ log.warn("LLM judge did not return valid JSON, using fallback scores");
111
+ return {
112
+ correctness: 0.5,
113
+ procedureFollowing: 0.5,
114
+ conciseness: 0.5,
115
+ lengthPenalty: 0.2,
116
+ feedback: "LLM judge returned non-JSON response",
117
+ };
118
+ }
119
+ const parsed = JSON.parse(jsonMatch[0]);
120
+ return {
121
+ correctness: typeof parsed.correctness === "number" ? parsed.correctness : 0.5,
122
+ procedureFollowing: typeof parsed.clarity === "number" ? parsed.clarity : 0.5,
123
+ conciseness: typeof parsed.conciseness === "number" ? parsed.conciseness : 0.5,
124
+ lengthPenalty: typeof parsed.lengthPenalty === "number" ? parsed.lengthPenalty : 0.0,
125
+ feedback: typeof parsed.feedback === "string" ? parsed.feedback : "No feedback provided",
126
+ };
127
+ }
128
+ function computeFitness(r) {
129
+ const raw = 0.5 * r.correctness + 0.3 * r.procedureFollowing + 0.2 * r.conciseness;
130
+ return Math.max(0, raw - r.lengthPenalty);
131
+ }
132
+ // ── Main Evolution Loop ────────────────────────────────────────────────
133
+ export async function evolveSkill(params) {
134
+ const { skillPath, llmCall, config = {} } = params;
135
+ const iterations = config.iterations ?? 5;
136
+ const maxSize = config.maxSize ?? 15_000;
137
+ const dryRun = config.dryRun ?? false;
138
+ // 1. Load skill
139
+ const skill = loadSkill(skillPath);
140
+ log.info(`Evolving skill: ${skill.name} (${skill.size} chars, ${iterations} iterations)`);
141
+ if (skill.size > maxSize) {
142
+ log.warn(`Skill exceeds max size (${skill.size} > ${maxSize}), truncating for evolution`);
143
+ }
144
+ // 2. Evaluate baseline
145
+ const baselineEval = await evaluateCandidate(skill, skill.content, llmCall);
146
+ const baselineScore = computeFitness(baselineEval);
147
+ log.info(`Baseline fitness: ${baselineScore.toFixed(3)}`);
148
+ let bestCandidate = null;
149
+ // 3. Generate and evaluate candidates
150
+ for (let i = 0; i < iterations; i++) {
151
+ log.info(`Iteration ${i + 1}/${iterations}`);
152
+ const candidates = await generateCandidates(skill, 3, llmCall);
153
+ log.info(`Generated ${candidates.length} candidates`);
154
+ for (const candidate of candidates) {
155
+ if (candidate.length > maxSize) {
156
+ log.debug(`Candidate too long (${candidate.length} chars), skipping`);
157
+ continue;
158
+ }
159
+ const evalResult = await evaluateCandidate(skill, candidate, llmCall);
160
+ const score = computeFitness(evalResult);
161
+ if (!bestCandidate || score > bestCandidate.score) {
162
+ bestCandidate = { variant: candidate, score, eval: evalResult };
163
+ log.info(`New best: fitness=${score.toFixed(3)} (${evalResult.feedback.slice(0, 80)}...)`);
164
+ }
165
+ }
166
+ }
167
+ // 4. Check if best candidate beats baseline
168
+ const improved = bestCandidate !== null && bestCandidate.score > baselineScore;
169
+ if (improved && bestCandidate) {
170
+ log.info(`Improvement found! Baseline: ${baselineScore.toFixed(3)} → Best: ${bestCandidate.score.toFixed(3)} (+${((bestCandidate.score - baselineScore) * 100).toFixed(1)}%)`);
171
+ if (!dryRun) {
172
+ writeFileSync(skillPath, bestCandidate.variant, "utf-8");
173
+ log.info(`Skill updated: ${skillPath}`);
174
+ }
175
+ else {
176
+ log.info(`Dry run — would update: ${skillPath}`);
177
+ }
178
+ }
179
+ else {
180
+ log.info(`No improvement over baseline (${baselineScore.toFixed(3)})`);
181
+ }
182
+ return { original: skill, bestCandidate, improved };
183
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poolzin/pool-bot",
3
- "version": "2026.4.30",
3
+ "version": "2026.4.31",
4
4
  "description": "🎱 Pool Bot - AI assistant with PLCODE integrations",
5
5
  "keywords": [],
6
6
  "license": "MIT",