协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
build【开发与工程】Implements intelligent build with multi-factor skill selection, fallback chains, and adherence to the 5 Laws of Elegant Defense
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
name: build compatibility: opencode completeness: 95 content-types:
Orchestrates intelligent skill selection and execution for build 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_build_tool(
project_root: str,
available_build_systems: List[str],
build_config: Dict[str, Any]
) -> Dict[str, Any]:
"""Select optimal build tool based on project structure and configuration.
Evaluates project files (Makefile, CMakeLists.txt, package.json, etc.)
against available build systems to determine the most efficient runner.
Applies multi-factor scoring: file presence, dependency graph complexity,
and historical build success rates.
"""
if not os.path.isdir(project_root):
raise ValueError(f"Project root not found: {project_root}")
project_files = os.listdir(project_root)
scoring = {}
for tool in available_build_systems:
score = 0.0
if tool == "make" and "Makefile" in project_files:
score += 0.4
elif tool == "cmake" and "CMakeLists.txt" in project_files:
score += 0.4
elif tool == "npm" and "package.json" in project_files:
score += 0.3
elif tool == "bazel" and "BUILD" in project_files:
score += 0.5
# Factor in build config overrides
if build_config.get("preferred_tool") == tool:
score += 0.2
# Factor in historical success rate
score += build_config.get("historical_success", {}).get(tool, 0.0) * 0.4
scoring[tool] = score
best_tool = max(scoring, key=scoring.get)
if scoring[best_tool] < 0.5:
return {"tool": None, "reason": "insufficient_match"}
return {
"tool": best_tool,
"confidence": scoring[best_tool],
"config_path": os.path.join(project_root, f"{best_tool}.config.yaml"),
"timestamp": time.time()
}
def execute_build_pipeline(
build_spec: Dict[str, Any],
project_root: str,
fallback_targets: List[str] = None
) -> Dict[str, Any]:
"""Execute build pipeline with domain-specific fallback handling.
Runs the selected build tool, monitors output for common failure modes
(dependency resolution, compilation errors, cache misses), and applies
targeted fallbacks without breaking the build contract.
"""
if fallback_targets is None:
fallback_targets = ["clean_build", "cached_artifacts", "manual_review"]
build_cmd = build_spec.get("command", f"{build_spec['tool']} build")
env_vars = {**os.environ, "BUILD_ROOT": project_root}
for attempt in range(3):
try:
result = subprocess.run(
build_cmd.split(),
cwd=project_root,
env=env_vars,
capture_output=True,
text=True,
timeout=build_spec.get("timeout", 300)
)
if result.returncode == 0:
return {
"status": "success",
"artifacts": _scan_artifacts(project_root),
"stdout": result.stdout[-500:],
"attempts": attempt + 1
}
except subprocess.TimeoutExpired:
logger.warning(f"Build timed out on attempt {attempt + 1}")
continue
except FileNotFoundError:
# Tool missing, trigger fallback chain
return _apply_build_fallback(build_spec, fallback_targets)
# All attempts failed - escalate to fallback
return _apply_build_fallback(build_spec, fallback_targets)
code-philosophy (5 Laws of Elegant Defense) in all logicWhen applying this skill, produce:
| Skill | Purpose |
|---|---|
commit | Source control commit workflows |
Authoritative documentation links for this skill's domain. The model follows markdown links at load time to resolve external references and inline content.