mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-03-30 13:43:26 +08:00
- Load both .yaml and .yml files in load_all_instincts() (#216) The *.yaml-only glob missed .yml files, causing 'No instincts found' - Implement evolve --generate to create skill/command/agent files (#217) Previously printed a stub message. Now generates SKILL.md, command .md, and agent .md files from the clustering analysis into ~/.claude/homunculus/evolved/
This commit is contained in:
@@ -88,7 +88,8 @@ def load_all_instincts() -> list[dict]:
|
|||||||
for directory in [PERSONAL_DIR, INHERITED_DIR]:
|
for directory in [PERSONAL_DIR, INHERITED_DIR]:
|
||||||
if not directory.exists():
|
if not directory.exists():
|
||||||
continue
|
continue
|
||||||
for file in directory.glob("*.yaml"):
|
yaml_files = sorted(set(directory.glob("*.yaml")) | set(directory.glob("*.yml")))
|
||||||
|
for file in yaml_files:
|
||||||
try:
|
try:
|
||||||
content = file.read_text()
|
content = file.read_text()
|
||||||
parsed = parse_instinct_file(content)
|
parsed = parse_instinct_file(content)
|
||||||
@@ -433,15 +434,96 @@ def cmd_evolve(args):
|
|||||||
print()
|
print()
|
||||||
|
|
||||||
if args.generate:
|
if args.generate:
|
||||||
print("\n[Would generate evolved structures here]")
|
generated = _generate_evolved(skill_candidates, workflow_instincts, agent_candidates)
|
||||||
print(" Skills would be saved to:", EVOLVED_DIR / "skills")
|
if generated:
|
||||||
print(" Commands would be saved to:", EVOLVED_DIR / "commands")
|
print(f"\n✅ Generated {len(generated)} evolved structures:")
|
||||||
print(" Agents would be saved to:", EVOLVED_DIR / "agents")
|
for path in generated:
|
||||||
|
print(f" {path}")
|
||||||
|
else:
|
||||||
|
print("\nNo structures generated (need higher-confidence clusters).")
|
||||||
|
|
||||||
print(f"\n{'='*60}\n")
|
print(f"\n{'='*60}\n")
|
||||||
return 0
|
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
|
# Main
|
||||||
# ─────────────────────────────────────────────
|
# ─────────────────────────────────────────────
|
||||||
|
|||||||
@@ -88,7 +88,8 @@ def load_all_instincts() -> list[dict]:
|
|||||||
for directory in [PERSONAL_DIR, INHERITED_DIR]:
|
for directory in [PERSONAL_DIR, INHERITED_DIR]:
|
||||||
if not directory.exists():
|
if not directory.exists():
|
||||||
continue
|
continue
|
||||||
for file in directory.glob("*.yaml"):
|
yaml_files = sorted(set(directory.glob("*.yaml")) | set(directory.glob("*.yml")))
|
||||||
|
for file in yaml_files:
|
||||||
try:
|
try:
|
||||||
content = file.read_text()
|
content = file.read_text()
|
||||||
parsed = parse_instinct_file(content)
|
parsed = parse_instinct_file(content)
|
||||||
@@ -433,15 +434,96 @@ def cmd_evolve(args):
|
|||||||
print()
|
print()
|
||||||
|
|
||||||
if args.generate:
|
if args.generate:
|
||||||
print("\n[Would generate evolved structures here]")
|
generated = _generate_evolved(skill_candidates, workflow_instincts, agent_candidates)
|
||||||
print(" Skills would be saved to:", EVOLVED_DIR / "skills")
|
if generated:
|
||||||
print(" Commands would be saved to:", EVOLVED_DIR / "commands")
|
print(f"\n✅ Generated {len(generated)} evolved structures:")
|
||||||
print(" Agents would be saved to:", EVOLVED_DIR / "agents")
|
for path in generated:
|
||||||
|
print(f" {path}")
|
||||||
|
else:
|
||||||
|
print("\nNo structures generated (need higher-confidence clusters).")
|
||||||
|
|
||||||
print(f"\n{'='*60}\n")
|
print(f"\n{'='*60}\n")
|
||||||
return 0
|
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
|
# Main
|
||||||
# ─────────────────────────────────────────────
|
# ─────────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user