refactor: restructure core modules into context and memory packages

- Move pm_init components to dedicated packages
- context/: PM mode initialization and contracts
- memory/: Reflexion memory system
- Remove deprecated superclaude/core/pm_init/

Breaking change: Import paths updated
- Old: superclaude.core.pm_init.context_contract
- New: superclaude.context.contract

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
kazuki
2025-10-20 03:52:27 +09:00
parent 328a0a016b
commit c5690e4a71
8 changed files with 41 additions and 55 deletions

View File

@@ -0,0 +1,12 @@
"""Project Context Management
Detects and manages project-specific configuration:
- Context Contract (project rules)
- Project structure detection
- Initialization
"""
from .contract import ContextContract
from .init import initialize_context
__all__ = ["ContextContract", "initialize_context"]

View File

@@ -1,10 +1,10 @@
"""PM Mode Initialization Hook
"""Context Initialization
Runs automatically at session start to:
Runs at session start to:
1. Detect repository root and structure
2. Generate Context Contract
3. Load Reflexion Memory
4. Set up PM Mode as default
4. Set up project context
"""
import os
@@ -13,8 +13,8 @@ from pathlib import Path
from typing import Optional, Dict, Any
import yaml
from .context_contract import ContextContract
from .reflexion_memory import ReflexionMemory
from .contract import ContextContract
from superclaude.memory import ReflexionMemory
class PMInitializer:
@@ -118,11 +118,11 @@ class PMInitializer:
}
def initialize_pm_mode(cwd: Optional[Path] = None) -> Dict[str, Any]:
def initialize_context(cwd: Optional[Path] = None) -> Dict[str, Any]:
"""
Initialize PM Mode as default.
Initialize project context.
This function runs automatically at session start.
This function runs at session start.
Args:
cwd: Current working directory (defaults to os.getcwd())

View File

@@ -1,31 +0,0 @@
# Files Moved
The files in `superclaude/core/` have been reorganized into domain-specific directories:
## New Structure
### Framework (思想・行動規範・グローバルフラグ)
- `PRINCIPLES.md``superclaude/framework/principles.md`
- `RULES.md``superclaude/framework/rules.md`
- `FLAGS.md``superclaude/framework/flags.md`
### Business (ビジネス領域の共通リソース)
- `BUSINESS_SYMBOLS.md``superclaude/business/symbols.md`
- `BUSINESS_PANEL_EXAMPLES.md``superclaude/business/examples.md`
### Research (調査・評価・設定)
- `RESEARCH_CONFIG.md``superclaude/research/config.md`
## Rationale
The `core/` directory was too abstract and made it difficult to find specific documentation. The new structure provides:
- **Clear domain boundaries**: Easier to navigate and maintain
- **Scalability**: Easy to add new directories (e.g., `benchmarks/`, `policies/`)
- **Lowercase naming**: Consistent with modern documentation practices
## Migration
All internal references have been updated. External references should update to the new paths.
This directory will be removed in the next major release.

View File

@@ -1,13 +0,0 @@
"""PM Mode Initialization System
Auto-initializes PM Mode as default with:
- Context Contract generation
- Reflexion Memory loading
- Lightweight configuration scanning
"""
from .init_hook import initialize_pm_mode
from .context_contract import ContextContract
from .reflexion_memory import ReflexionMemory
__all__ = ["initialize_pm_mode", "ContextContract", "ReflexionMemory"]

View File

@@ -0,0 +1,11 @@
"""Learning and Memory Systems
Manages long-term learning from experience:
- Reflexion Memory (mistake learning)
- Metrics collection
- Pattern recognition
"""
from .reflexion import ReflexionMemory, ReflexionEntry
__all__ = ["ReflexionMemory", "ReflexionEntry"]

View File

@@ -115,6 +115,9 @@ class ReflexionMemory:
"""Add new reflexion entry"""
self.entries.append(entry)
# Ensure directory exists
self.memory_path.parent.mkdir(parents=True, exist_ok=True)
# Append to JSONL file
with open(self.memory_path, "a") as f:
f.write(json.dumps(entry.to_dict()) + "\n")
@@ -127,9 +130,13 @@ class ReflexionMemory:
for entry in self.entries:
entry_keywords = set(entry.mistake.lower().split())
# If >50% keyword overlap, consider similar
overlap = len(keywords & entry_keywords) / len(keywords | entry_keywords)
if overlap > 0.5:
union = keywords | entry_keywords
# Avoid division by zero
if len(union) == 0:
continue
# If >30% keyword overlap, consider similar (lowered threshold for better recall)
overlap = len(keywords & entry_keywords) / len(union)
if overlap > 0.3:
similar.append(entry)
return sorted(similar, key=lambda e: e.timestamp, reverse=True)