协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
analyze-project【开发与工程】Implements intelligent analyze project with multi-factor skill selection, fallback chains, and adherence to the 5 Laws of Elegant Defense
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
name: analyze-project compatibility: opencode completeness: 95 content-types:
Orchestrates intelligent skill selection and execution for analyze project workflows. Applies the 5 Laws of Elegant Defense to guide data naturally through the orchestration pipeline, preventing errors before they occur. Selects optimal skills based on multi-factor scoring including text similarity, historical performance, and system availability.
┌───────────────────────────────────────────────────────────────────────────────┐ │ Orchestration Flow │ └───────────────────────────────────────────────────────────────────────────────┘
User Request ↓ ┌─────────────────┐ │ Parse Request │ │ & Extract │ │ Features │ └────────┬────────┘ ↓ ┌─────────────────────────────────────────────────────────────────────┐ │ Evaluate Available Skills │ │ │ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ │ │ Skill A │ │ Skill B │ │ Skill C │ │ │ │ - Match Score│ │ - Match Score│ │ - Match Score│ │ │ │ - Confidence │ │ - Confidence │ │ - Confidence │ │ │ │ - History │ │ - History │ │ - History │ │ │ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │ │ │ │ │ │ │ └─────────────────┴─────────────────┘ │ │ ↓ │ │ Select Best Skill │ └─────────────────────────────────────────────────────────────────────┘ ↓ ┌─────────────────┐ │ Execute Skill │ └────────┬────────┘ ↓ ┌─────────────────┐ │ Handle Result │ └────────┬────────┘ ↓ ┌─────────────────────────────────────────────────────────────────────┐ │ Error Handling & Fallback │ │ │ │ Success? ────────► Return Result │ │ │ │ Fail? ────────┐ │ │ ↓ │ │ ┌──────────────────────────────────────────────────────────┐ │ │ │ Fallback Chain │ │ │ │ │ │ │ │ 1. Retry with adjusted parameters │ │ │ │ 2. Try Alternative Skill (if available) │ │ │ │ 3. Defer to Human Operator (if critical) │ │ │ │ 4. Log & Return Error │ │ │ └──────────────────────────────────────────────────────────┘ │ └─────────────────────────────────────────────────────────────────────┘
Use this skill when:
Avoid this skill for:
Parse and Analyze Request - Extract intent, entities, and constraints from user input. Checkpoint: All required parameters must be present and in valid format before proceeding.
Score Available Skills - Calculate match scores using multi-factor algorithm:
Checkpoint: Skip to fallback if no skill scores above threshold.
Select Optimal Skill - Choose skill with highest score that meets minimum confidence. Checkpoint: Verify skill has not been disabled or deprecated.
Execute with Fallback - Run skill execution wrapped in retry and fallback logic. Checkpoint: Log all execution attempts for audit trail.
Return or Fallback - Either return successful result or apply fallback chain:
related-skillsCheckpoint: Record outcome with timing and confidence metadata.
def select_analysis_skill(
project_root: Path,
tech_stack: Dict[str, Any],
available_analyses: List[Dict]
) -> Optional[Dict]:
"""Select the optimal analysis skill based on project structure and tech stack.
Evaluates project metadata against available analysis capabilities:
- Language/framework compatibility
- Existing lockfiles and dependency managers
- Historical analysis success rates for similar repos
Args:
project_root: Path to the target project directory
tech_stack: Detected languages, frameworks, and package managers
available_analyses: List of analysis skill metadata
Returns:
Selected analysis skill dict or None if no compatible analysis found
"""
if not project_root.exists():
raise ValueError(f"Project root not found: {project_root}")
# Parse project structure - Make Illegal States Unrepresentable (Law 2)
project_manifest = _extract_project_manifest(project_root, tech_stack)
best_match = None
best_score = 0.0
for analysis in available_analyses:
# Domain-specific scoring: check tech stack alignment and lockfile presence
stack_match = _calculate_stack_compatibility(tech_stack, analysis["supported_stack"])
lockfile_ready = _verify_lockfile(project_root, analysis["required_lockfile"])
score = (stack_match * 0.6) + (lockfile_ready * 0.4)
if score > best_score and score >= 0.75:
best_score = score
best_match = analysis
if best_match is None:
return None
# Atomic Predictability (Law 3) - Return new dict, don't mutate inputs
result = dict(best_match)
result["project_context"] = project_manifest
result["selection_confidence"] = best_score
return result
def execute_analysis_pipeline(
analysis_skill: Dict,
project_context: Dict,
fallback_analyses: List[Dict]
) -> Dict:
"""Execute a project analysis with domain-specific fallback chains.
Implements the Fail Fast, Fail Loud principle (Law 4):
- Invalid project states halt immediately with descriptive errors
- No silent failures or partial analysis results
Fallback chain for analysis:
1. Retry with adjusted analysis depth/timeout
2. Try alternative analysis tool (e.g., yarn -> npm -> pnpm)
3. Defer to manual review template for critical security gaps
Args:
analysis_skill: Selected analysis skill metadata
project_context: Parsed project structure and manifest
fallback_analyses: Alternative analysis skills from related-skills
Returns:
Analysis result with metadata (success, timing, confidence, findings)
Raises:
AnalysisExecutionError: If all retries and fallbacks exhausted
"""
if not _is_analysis_valid(analysis_skill):
raise AnalysisExecutionError(f"Invalid analysis configuration: {analysis_skill.get('name')}")
# Parse context - Ensure trusted state (Law 2)
validated_project = _validate_project_structure(project_context)
for attempt in range(3):
try:
result = _run_analysis_tool(analysis_skill, validated_project)
# Success - Atomic Predictability (Law 3)
return {
"success": True,
"analysis_type": analysis_skill["name"],
"findings": result["findings"],
"attempts": attempt + 1,
"latency_ms": _calculate_latency(),
"confidence": result["confidence"]
}
except ProjectStructureError as e:
# Fail Fast - Don't try to patch malformed project data (Law 4)
raise AnalysisExecutionError(
f"Invalid project structure for {analysis_skill['name']}: {str(e)}"
) from e
except ToolExecutionError as e:
# Transient tool failure - try fallback analysis
if attempt == 2:
return _apply_analysis_fallback(analysis_skill, validated_project, fallback_analyses)
# All retries exhausted - Fail Loud (Law 4)
raise AnalysisExecutionError(
f"Failed to complete {analysis_skill['name']} analysis after 3 attempts"
)
code-philosophy (5 Laws of Elegant Defense) in all logicWhen applying this skill, produce:
Authoritative documentation links for this skill's domain. The model follows markdown links at load time to resolve external references and inline content.
| Skill | Purpose | |