diff --git a/commands/evolve.md b/commands/evolve.md index 5525c3b..6f82c12 100644 --- a/commands/evolve.md +++ b/commands/evolve.md @@ -1,14 +1,21 @@ --- name: evolve description: Cluster related instincts into skills, commands, or agents -command: /evolve -implementation: python3 ~/.claude/skills/continuous-learning-v2/scripts/instinct-cli.py evolve +command: true --- # Evolve Command ## Implementation +Run the instinct CLI using the plugin root path: + +```bash +python3 "${CLAUDE_PLUGIN_ROOT}/skills/continuous-learning-v2/scripts/instinct-cli.py" evolve [--generate] +``` + +Or if `CLAUDE_PLUGIN_ROOT` is not set (manual installation): + ```bash python3 ~/.claude/skills/continuous-learning-v2/scripts/instinct-cli.py evolve [--generate] ``` diff --git a/commands/instinct-import.md b/commands/instinct-import.md index f482408..0dea62b 100644 --- a/commands/instinct-import.md +++ b/commands/instinct-import.md @@ -1,16 +1,23 @@ --- name: instinct-import description: Import instincts from teammates, Skill Creator, or other sources -command: /instinct-import -implementation: python3 ~/.claude/skills/continuous-learning-v2/scripts/instinct-cli.py import +command: true --- # Instinct Import Command ## Implementation +Run the instinct CLI using the plugin root path: + ```bash -python3 ~/.claude/skills/continuous-learning-v2/scripts/instinct-cli.py import [--dry-run] [--force] [--min-confidence 0.7] +python3 "${CLAUDE_PLUGIN_ROOT}/skills/continuous-learning-v2/scripts/instinct-cli.py" import [--dry-run] [--force] [--min-confidence 0.7] +``` + +Or if `CLAUDE_PLUGIN_ROOT` is not set (manual installation): + +```bash +python3 ~/.claude/skills/continuous-learning-v2/scripts/instinct-cli.py import ``` Import instincts from: diff --git a/commands/instinct-status.md b/commands/instinct-status.md index 12af6b1..346ed47 100644 --- a/commands/instinct-status.md +++ b/commands/instinct-status.md @@ -1,8 +1,7 @@ --- name: instinct-status description: Show all learned instincts with their confidence levels -command: /instinct-status -implementation: python3 ~/.claude/skills/continuous-learning-v2/scripts/instinct-cli.py status +command: true --- # Instinct Status Command @@ -11,6 +10,14 @@ Shows all learned instincts with their confidence scores, grouped by domain. ## Implementation +Run the instinct CLI using the plugin root path: + +```bash +python3 "${CLAUDE_PLUGIN_ROOT}/skills/continuous-learning-v2/scripts/instinct-cli.py" status +``` + +Or if `CLAUDE_PLUGIN_ROOT` is not set (manual installation), use: + ```bash python3 ~/.claude/skills/continuous-learning-v2/scripts/instinct-cli.py status ``` diff --git a/skills/continuous-learning-v2/SKILL.md b/skills/continuous-learning-v2/SKILL.md index 67e6386..8fb3138 100644 --- a/skills/continuous-learning-v2/SKILL.md +++ b/skills/continuous-learning-v2/SKILL.md @@ -92,7 +92,32 @@ Session Activity ### 1. Enable Observation Hooks -Add to your `~/.claude/settings.json`: +Add to your `~/.claude/settings.json`. + +**If installed as a plugin** (recommended): + +```json +{ + "hooks": { + "PreToolUse": [{ + "matcher": "*", + "hooks": [{ + "type": "command", + "command": "${CLAUDE_PLUGIN_ROOT}/skills/continuous-learning-v2/hooks/observe.sh pre" + }] + }], + "PostToolUse": [{ + "matcher": "*", + "hooks": [{ + "type": "command", + "command": "${CLAUDE_PLUGIN_ROOT}/skills/continuous-learning-v2/hooks/observe.sh post" + }] + }] + } +} +``` + +**If installed manually** to `~/.claude/skills`: ```json { @@ -117,18 +142,20 @@ Add to your `~/.claude/settings.json`: ### 2. Initialize Directory Structure +The Python CLI will create these automatically, but you can also create them manually: + ```bash mkdir -p ~/.claude/homunculus/{instincts/{personal,inherited},evolved/{agents,skills,commands}} touch ~/.claude/homunculus/observations.jsonl ``` -### 3. Run the Observer Agent (Optional) - -The observer can run in the background analyzing observations: +### 3. Use the Instinct Commands ```bash -# Start background observer -~/.claude/skills/continuous-learning-v2/agents/start-observer.sh +/instinct-status # Show learned instincts with confidence scores +/evolve # Cluster related instincts into skills/commands +/instinct-export # Export instincts for sharing +/instinct-import # Import instincts from others ``` ## Commands diff --git a/skills/continuous-learning-v2/commands/evolve.md b/skills/continuous-learning-v2/commands/evolve.md deleted file mode 100644 index 5525c3b..0000000 --- a/skills/continuous-learning-v2/commands/evolve.md +++ /dev/null @@ -1,186 +0,0 @@ ---- -name: evolve -description: Cluster related instincts into skills, commands, or agents -command: /evolve -implementation: python3 ~/.claude/skills/continuous-learning-v2/scripts/instinct-cli.py evolve ---- - -# Evolve Command - -## Implementation - -```bash -python3 ~/.claude/skills/continuous-learning-v2/scripts/instinct-cli.py evolve [--generate] -``` - -Analyzes instincts and clusters related ones into higher-level structures: -- **Commands**: When instincts describe user-invoked actions -- **Skills**: When instincts describe auto-triggered behaviors -- **Agents**: When instincts describe complex, multi-step processes - -## Usage - -``` -/evolve # Analyze all instincts and suggest evolutions -/evolve --domain testing # Only evolve instincts in testing domain -/evolve --dry-run # Show what would be created without creating -/evolve --threshold 5 # Require 5+ related instincts to cluster -``` - -## Evolution Rules - -### → Command (User-Invoked) -When instincts describe actions a user would explicitly request: -- Multiple instincts about "when user asks to..." -- Instincts with triggers like "when creating a new X" -- Instincts that follow a repeatable sequence - -Example: -- `new-table-step1`: "when adding a database table, create migration" -- `new-table-step2`: "when adding a database table, update schema" -- `new-table-step3`: "when adding a database table, regenerate types" - -→ Creates: `/new-table` command - -### → Skill (Auto-Triggered) -When instincts describe behaviors that should happen automatically: -- Pattern-matching triggers -- Error handling responses -- Code style enforcement - -Example: -- `prefer-functional`: "when writing functions, prefer functional style" -- `use-immutable`: "when modifying state, use immutable patterns" -- `avoid-classes`: "when designing modules, avoid class-based design" - -→ Creates: `functional-patterns` skill - -### → Agent (Needs Depth/Isolation) -When instincts describe complex, multi-step processes that benefit from isolation: -- Debugging workflows -- Refactoring sequences -- Research tasks - -Example: -- `debug-step1`: "when debugging, first check logs" -- `debug-step2`: "when debugging, isolate the failing component" -- `debug-step3`: "when debugging, create minimal reproduction" -- `debug-step4`: "when debugging, verify fix with test" - -→ Creates: `debugger` agent - -## What to Do - -1. Read all instincts from `~/.claude/homunculus/instincts/` -2. Group instincts by: - - Domain similarity - - Trigger pattern overlap - - Action sequence relationship -3. For each cluster of 3+ related instincts: - - Determine evolution type (command/skill/agent) - - Generate the appropriate file - - Save to `~/.claude/homunculus/evolved/{commands,skills,agents}/` -4. Link evolved structure back to source instincts - -## Output Format - -``` -🧬 Evolve Analysis -================== - -Found 3 clusters ready for evolution: - -## Cluster 1: Database Migration Workflow -Instincts: new-table-migration, update-schema, regenerate-types -Type: Command -Confidence: 85% (based on 12 observations) - -Would create: /new-table command -Files: - - ~/.claude/homunculus/evolved/commands/new-table.md - -## Cluster 2: Functional Code Style -Instincts: prefer-functional, use-immutable, avoid-classes, pure-functions -Type: Skill -Confidence: 78% (based on 8 observations) - -Would create: functional-patterns skill -Files: - - ~/.claude/homunculus/evolved/skills/functional-patterns.md - -## Cluster 3: Debugging Process -Instincts: debug-check-logs, debug-isolate, debug-reproduce, debug-verify -Type: Agent -Confidence: 72% (based on 6 observations) - -Would create: debugger agent -Files: - - ~/.claude/homunculus/evolved/agents/debugger.md - ---- -Run `/evolve --execute` to create these files. -``` - -## Flags - -- `--execute`: Actually create the evolved structures (default is preview) -- `--dry-run`: Preview without creating -- `--domain `: Only evolve instincts in specified domain -- `--threshold `: Minimum instincts required to form cluster (default: 3) -- `--type `: Only create specified type - -## Generated File Format - -### Command -```markdown ---- -name: new-table -description: Create a new database table with migration, schema update, and type generation -command: /new-table -evolved_from: - - new-table-migration - - update-schema - - regenerate-types ---- - -# New Table Command - -[Generated content based on clustered instincts] - -## Steps -1. ... -2. ... -``` - -### Skill -```markdown ---- -name: functional-patterns -description: Enforce functional programming patterns -evolved_from: - - prefer-functional - - use-immutable - - avoid-classes ---- - -# Functional Patterns Skill - -[Generated content based on clustered instincts] -``` - -### Agent -```markdown ---- -name: debugger -description: Systematic debugging agent -model: sonnet -evolved_from: - - debug-check-logs - - debug-isolate - - debug-reproduce ---- - -# Debugger Agent - -[Generated content based on clustered instincts] -``` diff --git a/skills/continuous-learning-v2/commands/instinct-export.md b/skills/continuous-learning-v2/commands/instinct-export.md deleted file mode 100644 index a93f4e2..0000000 --- a/skills/continuous-learning-v2/commands/instinct-export.md +++ /dev/null @@ -1,91 +0,0 @@ ---- -name: instinct-export -description: Export instincts for sharing with teammates or other projects -command: /instinct-export ---- - -# Instinct Export Command - -Exports instincts to a shareable format. Perfect for: -- Sharing with teammates -- Transferring to a new machine -- Contributing to project conventions - -## Usage - -``` -/instinct-export # Export all personal instincts -/instinct-export --domain testing # Export only testing instincts -/instinct-export --min-confidence 0.7 # Only export high-confidence instincts -/instinct-export --output team-instincts.yaml -``` - -## What to Do - -1. Read instincts from `~/.claude/homunculus/instincts/personal/` -2. Filter based on flags -3. Strip sensitive information: - - Remove session IDs - - Remove file paths (keep only patterns) - - Remove timestamps older than "last week" -4. Generate export file - -## Output Format - -Creates a YAML file: - -```yaml -# Instincts Export -# Generated: 2025-01-22 -# Source: personal -# Count: 12 instincts - -version: "2.0" -exported_by: "continuous-learning-v2" -export_date: "2025-01-22T10:30:00Z" - -instincts: - - id: prefer-functional-style - trigger: "when writing new functions" - action: "Use functional patterns over classes" - confidence: 0.8 - domain: code-style - observations: 8 - - - id: test-first-workflow - trigger: "when adding new functionality" - action: "Write test first, then implementation" - confidence: 0.9 - domain: testing - observations: 12 - - - id: grep-before-edit - trigger: "when modifying code" - action: "Search with Grep, confirm with Read, then Edit" - confidence: 0.7 - domain: workflow - observations: 6 -``` - -## Privacy Considerations - -Exports include: -- ✅ Trigger patterns -- ✅ Actions -- ✅ Confidence scores -- ✅ Domains -- ✅ Observation counts - -Exports do NOT include: -- ❌ Actual code snippets -- ❌ File paths -- ❌ Session transcripts -- ❌ Personal identifiers - -## Flags - -- `--domain `: Export only specified domain -- `--min-confidence `: Minimum confidence threshold (default: 0.3) -- `--output `: Output file path (default: instincts-export-YYYYMMDD.yaml) -- `--format `: Output format (default: yaml) -- `--include-evidence`: Include evidence text (default: excluded) diff --git a/skills/continuous-learning-v2/commands/instinct-import.md b/skills/continuous-learning-v2/commands/instinct-import.md deleted file mode 100644 index f482408..0000000 --- a/skills/continuous-learning-v2/commands/instinct-import.md +++ /dev/null @@ -1,135 +0,0 @@ ---- -name: instinct-import -description: Import instincts from teammates, Skill Creator, or other sources -command: /instinct-import -implementation: python3 ~/.claude/skills/continuous-learning-v2/scripts/instinct-cli.py import ---- - -# Instinct Import Command - -## Implementation - -```bash -python3 ~/.claude/skills/continuous-learning-v2/scripts/instinct-cli.py import [--dry-run] [--force] [--min-confidence 0.7] -``` - -Import instincts from: -- Teammates' exports -- Skill Creator (repo analysis) -- Community collections -- Previous machine backups - -## Usage - -``` -/instinct-import team-instincts.yaml -/instinct-import https://github.com/org/repo/instincts.yaml -/instinct-import --from-skill-creator acme/webapp -``` - -## What to Do - -1. Fetch the instinct file (local path or URL) -2. Parse and validate the format -3. Check for duplicates with existing instincts -4. Merge or add new instincts -5. Save to `~/.claude/homunculus/instincts/inherited/` - -## Import Process - -``` -📥 Importing instincts from: team-instincts.yaml -================================================ - -Found 12 instincts to import. - -Analyzing conflicts... - -## New Instincts (8) -These will be added: - ✓ use-zod-validation (confidence: 0.7) - ✓ prefer-named-exports (confidence: 0.65) - ✓ test-async-functions (confidence: 0.8) - ... - -## Duplicate Instincts (3) -Already have similar instincts: - ⚠️ prefer-functional-style - Local: 0.8 confidence, 12 observations - Import: 0.7 confidence - → Keep local (higher confidence) - - ⚠️ test-first-workflow - Local: 0.75 confidence - Import: 0.9 confidence - → Update to import (higher confidence) - -## Conflicting Instincts (1) -These contradict local instincts: - ❌ use-classes-for-services - Conflicts with: avoid-classes - → Skip (requires manual resolution) - ---- -Import 8 new, update 1, skip 3? -``` - -## Merge Strategies - -### For Duplicates -When importing an instinct that matches an existing one: -- **Higher confidence wins**: Keep the one with higher confidence -- **Merge evidence**: Combine observation counts -- **Update timestamp**: Mark as recently validated - -### For Conflicts -When importing an instinct that contradicts an existing one: -- **Skip by default**: Don't import conflicting instincts -- **Flag for review**: Mark both as needing attention -- **Manual resolution**: User decides which to keep - -## Source Tracking - -Imported instincts are marked with: -```yaml -source: "inherited" -imported_from: "team-instincts.yaml" -imported_at: "2025-01-22T10:30:00Z" -original_source: "session-observation" # or "repo-analysis" -``` - -## Skill Creator Integration - -When importing from Skill Creator: - -``` -/instinct-import --from-skill-creator acme/webapp -``` - -This fetches instincts generated from repo analysis: -- Source: `repo-analysis` -- Higher initial confidence (0.7+) -- Linked to source repository - -## Flags - -- `--dry-run`: Preview without importing -- `--force`: Import even if conflicts exist -- `--merge-strategy `: How to handle duplicates -- `--from-skill-creator `: Import from Skill Creator analysis -- `--min-confidence `: Only import instincts above threshold - -## Output - -After import: -``` -✅ Import complete! - -Added: 8 instincts -Updated: 1 instinct -Skipped: 3 instincts (2 duplicates, 1 conflict) - -New instincts saved to: ~/.claude/homunculus/instincts/inherited/ - -Run /instinct-status to see all instincts. -``` diff --git a/skills/continuous-learning-v2/commands/instinct-status.md b/skills/continuous-learning-v2/commands/instinct-status.md deleted file mode 100644 index 12af6b1..0000000 --- a/skills/continuous-learning-v2/commands/instinct-status.md +++ /dev/null @@ -1,79 +0,0 @@ ---- -name: instinct-status -description: Show all learned instincts with their confidence levels -command: /instinct-status -implementation: python3 ~/.claude/skills/continuous-learning-v2/scripts/instinct-cli.py status ---- - -# Instinct Status Command - -Shows all learned instincts with their confidence scores, grouped by domain. - -## Implementation - -```bash -python3 ~/.claude/skills/continuous-learning-v2/scripts/instinct-cli.py status -``` - -## Usage - -``` -/instinct-status -/instinct-status --domain code-style -/instinct-status --low-confidence -``` - -## What to Do - -1. Read all instinct files from `~/.claude/homunculus/instincts/personal/` -2. Read inherited instincts from `~/.claude/homunculus/instincts/inherited/` -3. Display them grouped by domain with confidence bars - -## Output Format - -``` -📊 Instinct Status -================== - -## Code Style (4 instincts) - -### prefer-functional-style -Trigger: when writing new functions -Action: Use functional patterns over classes -Confidence: ████████░░ 80% -Source: session-observation | Last updated: 2025-01-22 - -### use-path-aliases -Trigger: when importing modules -Action: Use @/ path aliases instead of relative imports -Confidence: ██████░░░░ 60% -Source: repo-analysis (github.com/acme/webapp) - -## Testing (2 instincts) - -### test-first-workflow -Trigger: when adding new functionality -Action: Write test first, then implementation -Confidence: █████████░ 90% -Source: session-observation - -## Workflow (3 instincts) - -### grep-before-edit -Trigger: when modifying code -Action: Search with Grep, confirm with Read, then Edit -Confidence: ███████░░░ 70% -Source: session-observation - ---- -Total: 9 instincts (4 personal, 5 inherited) -Observer: Running (last analysis: 5 min ago) -``` - -## Flags - -- `--domain `: Filter by domain (code-style, testing, git, etc.) -- `--low-confidence`: Show only instincts with confidence < 0.5 -- `--high-confidence`: Show only instincts with confidence >= 0.7 -- `--source `: Filter by source (session-observation, repo-analysis, inherited) -- `--json`: Output as JSON for programmatic use diff --git a/skills/continuous-learning-v2/hooks/observe.sh b/skills/continuous-learning-v2/hooks/observe.sh index 31ffa0c..225c90e 100755 --- a/skills/continuous-learning-v2/hooks/observe.sh +++ b/skills/continuous-learning-v2/hooks/observe.sh @@ -5,15 +5,31 @@ # Claude Code passes hook data via stdin as JSON. # # Hook config (in ~/.claude/settings.json): +# +# If installed as a plugin, use ${CLAUDE_PLUGIN_ROOT}: # { # "hooks": { # "PreToolUse": [{ # "matcher": "*", -# "hooks": [{ "type": "command", "command": "~/.claude/skills/continuous-learning-v2/hooks/observe.sh" }] +# "hooks": [{ "type": "command", "command": "${CLAUDE_PLUGIN_ROOT}/skills/continuous-learning-v2/hooks/observe.sh pre" }] # }], # "PostToolUse": [{ # "matcher": "*", -# "hooks": [{ "type": "command", "command": "~/.claude/skills/continuous-learning-v2/hooks/observe.sh" }] +# "hooks": [{ "type": "command", "command": "${CLAUDE_PLUGIN_ROOT}/skills/continuous-learning-v2/hooks/observe.sh post" }] +# }] +# } +# } +# +# If installed manually to ~/.claude/skills: +# { +# "hooks": { +# "PreToolUse": [{ +# "matcher": "*", +# "hooks": [{ "type": "command", "command": "~/.claude/skills/continuous-learning-v2/hooks/observe.sh pre" }] +# }], +# "PostToolUse": [{ +# "matcher": "*", +# "hooks": [{ "type": "command", "command": "~/.claude/skills/continuous-learning-v2/hooks/observe.sh post" }] # }] # } # }