diff --git a/.cursor/skills/continuous-learning-v2/scripts/instinct-cli.py b/.cursor/skills/continuous-learning-v2/scripts/instinct-cli.py index bc7135c..b3f9d58 100755 --- a/.cursor/skills/continuous-learning-v2/scripts/instinct-cli.py +++ b/.cursor/skills/continuous-learning-v2/scripts/instinct-cli.py @@ -88,7 +88,8 @@ def load_all_instincts() -> list[dict]: for directory in [PERSONAL_DIR, INHERITED_DIR]: if not directory.exists(): continue - for file in directory.glob("*.yaml"): + yaml_files = sorted(set(directory.glob("*.yaml")) | set(directory.glob("*.yml"))) + for file in yaml_files: try: content = file.read_text() parsed = parse_instinct_file(content) @@ -433,15 +434,96 @@ def cmd_evolve(args): print() if args.generate: - print("\n[Would generate evolved structures here]") - print(" Skills would be saved to:", EVOLVED_DIR / "skills") - print(" Commands would be saved to:", EVOLVED_DIR / "commands") - print(" Agents would be saved to:", EVOLVED_DIR / "agents") + generated = _generate_evolved(skill_candidates, workflow_instincts, agent_candidates) + if generated: + print(f"\n✅ Generated {len(generated)} evolved structures:") + for path in generated: + print(f" {path}") + else: + print("\nNo structures generated (need higher-confidence clusters).") print(f"\n{'='*60}\n") return 0 +# ───────────────────────────────────────────── +# Generate Evolved Structures +# ───────────────────────────────────────────── + +def _generate_evolved(skill_candidates: list, workflow_instincts: list, agent_candidates: list) -> list[str]: + """Generate skill/command/agent files from analyzed instinct clusters.""" + generated = [] + + # Generate skills from top candidates + for cand in skill_candidates[:5]: + trigger = cand['trigger'].strip() + if not trigger: + continue + name = re.sub(r'[^a-z0-9]+', '-', trigger.lower()).strip('-')[:30] + if not name: + continue + + skill_dir = EVOLVED_DIR / "skills" / name + skill_dir.mkdir(parents=True, exist_ok=True) + + content = f"# {name}\n\n" + content += f"Evolved from {len(cand['instincts'])} instincts " + content += f"(avg confidence: {cand['avg_confidence']:.0%})\n\n" + content += f"## When to Apply\n\n" + content += f"Trigger: {trigger}\n\n" + content += f"## Actions\n\n" + for inst in cand['instincts']: + inst_content = inst.get('content', '') + action_match = re.search(r'## Action\s*\n\s*(.+?)(?:\n\n|\n##|$)', inst_content, re.DOTALL) + action = action_match.group(1).strip() if action_match else inst.get('id', 'unnamed') + content += f"- {action}\n" + + (skill_dir / "SKILL.md").write_text(content) + generated.append(str(skill_dir / "SKILL.md")) + + # Generate commands from workflow instincts + for inst in workflow_instincts[:5]: + trigger = inst.get('trigger', 'unknown') + cmd_name = re.sub(r'[^a-z0-9]+', '-', trigger.lower().replace('when ', '').replace('implementing ', '')) + cmd_name = cmd_name.strip('-')[:20] + if not cmd_name: + continue + + cmd_file = EVOLVED_DIR / "commands" / f"{cmd_name}.md" + content = f"# {cmd_name}\n\n" + content += f"Evolved from instinct: {inst.get('id', 'unnamed')}\n" + content += f"Confidence: {inst.get('confidence', 0.5):.0%}\n\n" + content += inst.get('content', '') + + cmd_file.write_text(content) + generated.append(str(cmd_file)) + + # Generate agents from complex clusters + for cand in agent_candidates[:3]: + trigger = cand['trigger'].strip() + agent_name = re.sub(r'[^a-z0-9]+', '-', trigger.lower()).strip('-')[:20] + if not agent_name: + continue + + agent_file = EVOLVED_DIR / "agents" / f"{agent_name}.md" + domains = ', '.join(cand['domains']) + instinct_ids = [i.get('id', 'unnamed') for i in cand['instincts']] + + content = f"---\nmodel: sonnet\ntools: Read, Grep, Glob\n---\n" + content += f"# {agent_name}\n\n" + content += f"Evolved from {len(cand['instincts'])} instincts " + content += f"(avg confidence: {cand['avg_confidence']:.0%})\n" + content += f"Domains: {domains}\n\n" + content += f"## Source Instincts\n\n" + for iid in instinct_ids: + content += f"- {iid}\n" + + agent_file.write_text(content) + generated.append(str(agent_file)) + + return generated + + # ───────────────────────────────────────────── # Main # ───────────────────────────────────────────── diff --git a/skills/continuous-learning-v2/scripts/instinct-cli.py b/skills/continuous-learning-v2/scripts/instinct-cli.py index bc7135c..b3f9d58 100755 --- a/skills/continuous-learning-v2/scripts/instinct-cli.py +++ b/skills/continuous-learning-v2/scripts/instinct-cli.py @@ -88,7 +88,8 @@ def load_all_instincts() -> list[dict]: for directory in [PERSONAL_DIR, INHERITED_DIR]: if not directory.exists(): continue - for file in directory.glob("*.yaml"): + yaml_files = sorted(set(directory.glob("*.yaml")) | set(directory.glob("*.yml"))) + for file in yaml_files: try: content = file.read_text() parsed = parse_instinct_file(content) @@ -433,15 +434,96 @@ def cmd_evolve(args): print() if args.generate: - print("\n[Would generate evolved structures here]") - print(" Skills would be saved to:", EVOLVED_DIR / "skills") - print(" Commands would be saved to:", EVOLVED_DIR / "commands") - print(" Agents would be saved to:", EVOLVED_DIR / "agents") + generated = _generate_evolved(skill_candidates, workflow_instincts, agent_candidates) + if generated: + print(f"\n✅ Generated {len(generated)} evolved structures:") + for path in generated: + print(f" {path}") + else: + print("\nNo structures generated (need higher-confidence clusters).") print(f"\n{'='*60}\n") return 0 +# ───────────────────────────────────────────── +# Generate Evolved Structures +# ───────────────────────────────────────────── + +def _generate_evolved(skill_candidates: list, workflow_instincts: list, agent_candidates: list) -> list[str]: + """Generate skill/command/agent files from analyzed instinct clusters.""" + generated = [] + + # Generate skills from top candidates + for cand in skill_candidates[:5]: + trigger = cand['trigger'].strip() + if not trigger: + continue + name = re.sub(r'[^a-z0-9]+', '-', trigger.lower()).strip('-')[:30] + if not name: + continue + + skill_dir = EVOLVED_DIR / "skills" / name + skill_dir.mkdir(parents=True, exist_ok=True) + + content = f"# {name}\n\n" + content += f"Evolved from {len(cand['instincts'])} instincts " + content += f"(avg confidence: {cand['avg_confidence']:.0%})\n\n" + content += f"## When to Apply\n\n" + content += f"Trigger: {trigger}\n\n" + content += f"## Actions\n\n" + for inst in cand['instincts']: + inst_content = inst.get('content', '') + action_match = re.search(r'## Action\s*\n\s*(.+?)(?:\n\n|\n##|$)', inst_content, re.DOTALL) + action = action_match.group(1).strip() if action_match else inst.get('id', 'unnamed') + content += f"- {action}\n" + + (skill_dir / "SKILL.md").write_text(content) + generated.append(str(skill_dir / "SKILL.md")) + + # Generate commands from workflow instincts + for inst in workflow_instincts[:5]: + trigger = inst.get('trigger', 'unknown') + cmd_name = re.sub(r'[^a-z0-9]+', '-', trigger.lower().replace('when ', '').replace('implementing ', '')) + cmd_name = cmd_name.strip('-')[:20] + if not cmd_name: + continue + + cmd_file = EVOLVED_DIR / "commands" / f"{cmd_name}.md" + content = f"# {cmd_name}\n\n" + content += f"Evolved from instinct: {inst.get('id', 'unnamed')}\n" + content += f"Confidence: {inst.get('confidence', 0.5):.0%}\n\n" + content += inst.get('content', '') + + cmd_file.write_text(content) + generated.append(str(cmd_file)) + + # Generate agents from complex clusters + for cand in agent_candidates[:3]: + trigger = cand['trigger'].strip() + agent_name = re.sub(r'[^a-z0-9]+', '-', trigger.lower()).strip('-')[:20] + if not agent_name: + continue + + agent_file = EVOLVED_DIR / "agents" / f"{agent_name}.md" + domains = ', '.join(cand['domains']) + instinct_ids = [i.get('id', 'unnamed') for i in cand['instincts']] + + content = f"---\nmodel: sonnet\ntools: Read, Grep, Glob\n---\n" + content += f"# {agent_name}\n\n" + content += f"Evolved from {len(cand['instincts'])} instincts " + content += f"(avg confidence: {cand['avg_confidence']:.0%})\n" + content += f"Domains: {domains}\n\n" + content += f"## Source Instincts\n\n" + for iid in instinct_ids: + content += f"- {iid}\n" + + agent_file.write_text(content) + generated.append(str(agent_file)) + + return generated + + # ───────────────────────────────────────────── # Main # ─────────────────────────────────────────────