superclaude-org--superclaude_framework
116e9fc5f9
* fix: fill implementation gaps across core modules - Replace ConfidenceChecker placeholder methods with real implementations that search the codebase for duplicates, verify architecture docs exist, check research references, and validate root cause specificity - Fix intelligent_execute() error capture: collect actual errors from failed tasks instead of hardcoded None, format tracebacks as strings, and fix variable shadowing bug where loop var overwrote task parameter - Implement ReflexionPattern mindbase integration via HTTP API with graceful fallback when service is unavailable - Fix .gitignore: remove duplicate entries, add explicit !-rules for .claude/settings.json and .claude/skills/, remove Tests/ ignore - Remove unnecessary sys.path hack in cli/main.py - Fix FailureEntry.from_dict to not mutate input dict - Add comprehensive execution module tests: 62 new tests covering ParallelExecutor, ReflectionEngine, SelfCorrectionEngine, and the intelligent_execute orchestrator (136 total, all passing) https://claude.ai/code/session_01AnGJMAA6Qp2j9WKKHHZfB9 * chore: include test-generated reflexion artifacts https://claude.ai/code/session_01AnGJMAA6Qp2j9WKKHHZfB9 * fix: address 5 open GitHub issues (#536, #537, #531, #517, #534) Security fixes: - #536: Remove shell=True and user-controlled $SHELL from _run_command() to prevent arbitrary code execution. Use direct list-based subprocess.run without passing full os.environ to child processes. - #537: Add SHA-256 integrity verification for downloaded docker-compose and mcp-config files. Downloads are deleted on hash mismatch. Gateway config supports pinned hashes via docker_compose_sha256/mcp_config_sha256. Bug fixes: - #531: Add agent file installation to `superclaude install` and `update` commands. 20 agent markdown files are now copied to ~/.claude/agents/ alongside command installation. - #517: Fix MCP env var flag from --env to -e for API key passthrough, matching the Claude CLI's expected format. Usability: - #534: Replace Japanese trigger phrases and report labels in pm-agent.md and pm.md (both src/ and plugins/) with English equivalents for international accessibility. https://claude.ai/code/session_01AnGJMAA6Qp2j9WKKHHZfB9 * docs: align documentation with Claude Code and fix version/count gaps - Update CLAUDE.md project structure to include agents/ (20 agents), modes/ (7 modes), commands/ (30 commands), skills/, hooks/, mcp/, and core/ directories. Add Claude Code integration points section. - Fix version references: 4.1.5 -> 4.2.0 in installation.md, quick-start.md, and package.json (was 4.1.7) - Fix feature counts across all docs: - Commands: 21 -> 30 - Agents: 14/16 -> 20 - Modes: 6 -> 7 - MCP Servers: 6 -> 8 - Update README.md agent count from 16 to 20 - Add docs/user-guide/claude-code-integration.md explaining how SuperClaude maps to Claude Code's native features (commands, agents, hooks, skills, settings, MCP servers, pytest plugin) https://claude.ai/code/session_01AnGJMAA6Qp2j9WKKHHZfB9 * chore: update test-generated reflexion log https://claude.ai/code/session_01AnGJMAA6Qp2j9WKKHHZfB9 * docs: comprehensive Claude Code gap analysis and integration guide - Rewrite docs/user-guide/claude-code-integration.md with full feature mapping: all 28 hook events, skills system with YAML frontmatter, 5 settings scopes, permission rules, plan mode, extended thinking, agent teams, voice, desktop features, and session management. Includes detailed gap table showing where SuperClaude under-uses Claude Code capabilities (skills migration, hooks integration, plan mode, settings profiles). - Add Claude Code native features section to CLAUDE.md with extension points we use vs should use more (hooks, skills, plan mode, settings) - Add Claude Code integration gap analysis to KNOWLEDGE.md with prioritized action items for skills migration, hooks leverage, plan mode integration, and settings profiles https://claude.ai/code/session_01AnGJMAA6Qp2j9WKKHHZfB9 * chore: update test-generated reflexion log https://claude.ai/code/session_01AnGJMAA6Qp2j9WKKHHZfB9 * chore: bump version to 4.3.0 Bump version across all 15 files: - VERSION, pyproject.toml, package.json - src/superclaude/__init__.py, src/superclaude/__version__.py - CLAUDE.md, PLANNING.md, TASK.md, CHANGELOG.md - README.md, README-zh.md, README-ja.md, README-kr.md - docs/getting-started/installation.md, quick-start.md - docs/Development/pm-agent-integration.md Also fixes __version__.py which was out of sync at 0.4.0. Adds comprehensive CHANGELOG entry for v4.3.0. https://claude.ai/code/session_01AnGJMAA6Qp2j9WKKHHZfB9 * i18n: replace all Japanese/Chinese text with English in source files Replace CJK text with English across all non-translation files: - src/superclaude/commands/pm.md: 38 Japanese strings in PDCA cycle, error handling patterns, anti-patterns, document templates - src/superclaude/agents/pm-agent.md: 20 Japanese strings in PDCA phases, self-evaluation, documentation sections - plugins/superclaude/: synced from src/ copies - .github/workflows/readme-quality-check.yml: all Chinese comments, table headers, report strings, and PR comment text - .github/workflows/pull-sync-framework.yml: Japanese comment - .github/PULL_REQUEST_TEMPLATE.md: complete rewrite from Japanese Translation files (README-ja.md, docs/user-guide-jp/, etc.) are intentionally kept in their respective languages. https://claude.ai/code/session_01AnGJMAA6Qp2j9WKKHHZfB9 --------- Co-authored-by: Claude <noreply@anthropic.com>
205 行
7.1 KiB
Python
205 行
7.1 KiB
Python
"""
|
|
Unit tests for ReflectionEngine
|
|
|
|
Tests the 3-stage pre-execution confidence assessment:
|
|
1. Requirement clarity analysis
|
|
2. Past mistake pattern detection
|
|
3. Context sufficiency validation
|
|
"""
|
|
|
|
import json
|
|
|
|
import pytest
|
|
|
|
from superclaude.execution.reflection import (
|
|
ConfidenceScore,
|
|
ReflectionEngine,
|
|
ReflectionResult,
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def reflection_engine(tmp_path):
|
|
"""Create a ReflectionEngine with temporary repo path"""
|
|
return ReflectionEngine(tmp_path)
|
|
|
|
|
|
@pytest.fixture
|
|
def engine_with_mistakes(tmp_path):
|
|
"""Create a ReflectionEngine with past mistakes in memory"""
|
|
memory_dir = tmp_path / "docs" / "memory"
|
|
memory_dir.mkdir(parents=True)
|
|
|
|
reflexion_data = {
|
|
"mistakes": [
|
|
{
|
|
"task": "fix user authentication login flow",
|
|
"mistake": "Used wrong token validation method",
|
|
},
|
|
{
|
|
"task": "create database migration script",
|
|
"mistake": "Forgot to handle nullable columns",
|
|
},
|
|
],
|
|
"patterns": [],
|
|
"prevention_rules": [],
|
|
}
|
|
|
|
(memory_dir / "reflexion.json").write_text(json.dumps(reflexion_data))
|
|
return ReflectionEngine(tmp_path)
|
|
|
|
|
|
class TestReflectionResult:
|
|
"""Test ReflectionResult dataclass"""
|
|
|
|
def test_repr_high_score(self):
|
|
"""High score should show green checkmark"""
|
|
result = ReflectionResult(
|
|
stage="Test", score=0.9, evidence=["good"], concerns=[]
|
|
)
|
|
assert "✅" in repr(result)
|
|
|
|
def test_repr_medium_score(self):
|
|
"""Medium score should show warning"""
|
|
result = ReflectionResult(
|
|
stage="Test", score=0.6, evidence=[], concerns=["concern"]
|
|
)
|
|
assert "⚠️" in repr(result)
|
|
|
|
def test_repr_low_score(self):
|
|
"""Low score should show red X"""
|
|
result = ReflectionResult(
|
|
stage="Test", score=0.2, evidence=[], concerns=["bad"]
|
|
)
|
|
assert "❌" in repr(result)
|
|
|
|
|
|
class TestReflectionEngine:
|
|
"""Test suite for ReflectionEngine class"""
|
|
|
|
def test_reflect_specific_task(self, reflection_engine):
|
|
"""Specific task description should get higher clarity score"""
|
|
result = reflection_engine.reflect(
|
|
"Create a new REST API endpoint for /users/{id} in users.py",
|
|
context={"project_index": True, "current_branch": "main", "git_status": "clean"},
|
|
)
|
|
|
|
assert result.requirement_clarity.score > 0.5
|
|
assert result.should_proceed is True or result.confidence > 0.0
|
|
|
|
def test_reflect_vague_task(self, reflection_engine):
|
|
"""Vague task description should get lower clarity score"""
|
|
result = reflection_engine.reflect("improve something")
|
|
|
|
assert result.requirement_clarity.score < 0.7
|
|
assert any("vague" in c.lower() for c in result.requirement_clarity.concerns)
|
|
|
|
def test_reflect_short_task(self, reflection_engine):
|
|
"""Very short task should be flagged"""
|
|
result = reflection_engine.reflect("fix it")
|
|
|
|
assert result.requirement_clarity.score < 0.7
|
|
assert any("brief" in c.lower() for c in result.requirement_clarity.concerns)
|
|
|
|
def test_reflect_no_context(self, reflection_engine):
|
|
"""Missing context should lower context readiness score"""
|
|
result = reflection_engine.reflect(
|
|
"Create user authentication function in auth.py"
|
|
)
|
|
|
|
assert result.context_ready.score < 0.7
|
|
assert any("context" in c.lower() for c in result.context_ready.concerns)
|
|
|
|
def test_reflect_full_context(self, reflection_engine):
|
|
"""Full context should give high context readiness"""
|
|
# Create PROJECT_INDEX.md to satisfy freshness check
|
|
(reflection_engine.repo_path / "PROJECT_INDEX.md").write_text("# Index")
|
|
|
|
result = reflection_engine.reflect(
|
|
"Add validation to user registration",
|
|
context={
|
|
"project_index": "loaded",
|
|
"current_branch": "feature/auth",
|
|
"git_status": "clean",
|
|
},
|
|
)
|
|
|
|
assert result.context_ready.score >= 0.7
|
|
|
|
def test_reflect_no_past_mistakes(self, reflection_engine):
|
|
"""No reflexion file should give high mistake check score"""
|
|
result = reflection_engine.reflect("Create new feature")
|
|
|
|
assert result.mistake_check.score == 1.0
|
|
assert any("no past" in e.lower() for e in result.mistake_check.evidence)
|
|
|
|
def test_reflect_with_similar_mistakes(self, engine_with_mistakes):
|
|
"""Similar past mistakes should lower the score"""
|
|
result = engine_with_mistakes.reflect(
|
|
"fix user authentication token validation"
|
|
)
|
|
|
|
assert result.mistake_check.score < 1.0
|
|
assert any("similar" in c.lower() for c in result.mistake_check.concerns)
|
|
|
|
def test_confidence_threshold(self, reflection_engine):
|
|
"""Confidence below 70% should block execution"""
|
|
result = reflection_engine.reflect("maybe improve something")
|
|
|
|
if result.confidence < 0.7:
|
|
assert result.should_proceed is False
|
|
|
|
def test_confidence_above_threshold(self, reflection_engine):
|
|
"""Confidence above 70% should allow execution"""
|
|
(reflection_engine.repo_path / "PROJECT_INDEX.md").write_text("# Index")
|
|
|
|
result = reflection_engine.reflect(
|
|
"Create a new REST API endpoint for /users/{id} in users.py",
|
|
context={
|
|
"project_index": "loaded",
|
|
"current_branch": "main",
|
|
"git_status": "clean",
|
|
},
|
|
)
|
|
|
|
if result.confidence >= 0.7:
|
|
assert result.should_proceed is True
|
|
|
|
def test_record_reflection(self, reflection_engine):
|
|
"""Recording reflection should persist to file"""
|
|
confidence = ConfidenceScore(
|
|
requirement_clarity=ReflectionResult("Clarity", 0.8, ["ok"], []),
|
|
mistake_check=ReflectionResult("Mistakes", 1.0, ["none"], []),
|
|
context_ready=ReflectionResult("Context", 0.7, ["loaded"], []),
|
|
confidence=0.85,
|
|
should_proceed=True,
|
|
blockers=[],
|
|
recommendations=[],
|
|
)
|
|
|
|
reflection_engine.record_reflection("test task", confidence, "proceed")
|
|
|
|
log_file = reflection_engine.memory_path / "reflection_log.json"
|
|
assert log_file.exists()
|
|
|
|
data = json.loads(log_file.read_text())
|
|
assert len(data["reflections"]) == 1
|
|
assert data["reflections"][0]["task"] == "test task"
|
|
assert data["reflections"][0]["confidence"] == 0.85
|
|
|
|
def test_weights_sum_to_one(self, reflection_engine):
|
|
"""Weight values should sum to 1.0"""
|
|
total = sum(reflection_engine.WEIGHTS.values())
|
|
assert abs(total - 1.0) < 0.001
|
|
|
|
def test_clarity_specific_verbs_boost(self, reflection_engine):
|
|
"""Specific action verbs should boost clarity score"""
|
|
result_specific = reflection_engine._reflect_clarity(
|
|
"Create user registration endpoint", None
|
|
)
|
|
result_vague = reflection_engine._reflect_clarity(
|
|
"improve the system", None
|
|
)
|
|
|
|
assert result_specific.score > result_vague.score
|