协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
lint-and-validate【开发与工程】Implements intelligent lint and validate with multi-factor skill selection, fallback chains, and adherence to the 5 Laws of Elegant Defense
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
name: lint-and-validate compatibility: opencode completeness: 95 content-types:
Orchestrates intelligent skill selection and execution for lint and validate 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 extract_and_validate_targets(
project_root: str,
config: Dict[str, Any],
allowed_linters: List[str]
) -> Dict[str, Any]:
"""Extract lint targets and validate environment readiness.
Implements Law 2 (Parse at boundary) and Law 1 (Early exit).
Returns a validated execution plan with targets and tool configurations.
"""
# Law 1: Early exit on invalid paths
if not os.path.isdir(project_root):
raise ValueError(f"Project root not found: {project_root}")
# Law 2: Parse and validate config at boundary
if not config.get("linters"):
raise ValueError("No linters specified in configuration")
# Validate allowed tools against system availability
available_tools = _check_system_linters(allowed_linters)
if not available_tools:
return {"status": "skipped", "reason": "No compatible linters found"}
# Law 3: Return new structure, never mutate inputs
execution_plan = {
"targets": _discover_files(project_root, config.get("extensions", ["*.py", "*.js"])),
"tools": available_tools,
"rules": config.get("rules", {}),
"max_issues": config.get("max_issues", 50)
}
return execution_plan
def run_lint_pipeline(
plan: Dict[str, Any],
strict_mode: bool = True
) -> Dict[str, Any]:
"""Execute linting pipeline with fallback chain for tool failures.
Implements Law 4 (Fail fast/loud) and adaptive fallback.
Fallback: strict_linter -> lenient_linter -> static_analysis_report
"""
results = []
fallback_chain = ["ruff", "flake8", "bandit"] if strict_mode else ["pylint", "mypy"]
for tool in fallback_chain:
if tool not in plan["tools"]:
continue
try:
# Execute specific linter with timeout and strictness
output = subprocess.run(
[tool, "--output-format=json"] + plan["targets"],
capture_output=True, text=True, timeout=120
)
if output.returncode != 0:
issues = json.loads(output.stdout)
results.append({"tool": tool, "issues": issues, "severity": "high"})
# Law 4: Fail loud on critical security issues
if _has_critical_security_issues(issues):
raise LintCriticalError("Critical security vulnerabilities detected")
else:
results.append({"tool": tool, "issues": [], "severity": "pass"})
except subprocess.TimeoutExpired:
# Fallback: skip to next tool if timeout occurs
continue
except FileNotFoundError:
# Tool not found, try next in chain
continue
# Aggregate and return new structure
return {
"status": "failed" if any(r["severity"] == "high" for r in results) else "passed",
"total_issues": sum(len(r["issues"]) for r in results),
"details": results,
"fallback_used": len(results) > 1
}
code-philosophy (5 Laws of Elegant Defense) in all logicWhen applying this skill, produce:
| Skill | Purpose | |
Authoritative documentation links for this skill's domain. The model follows markdown links at load time to resolve external references and inline content.