协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
github-actions-templates【开发与工程】Implements intelligent github actions templates with multi-factor skill selection, fallback chains, and adherence to the 5 Laws of Elegant Defense
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
name: github-actions-templates compatibility: opencode completeness: 95 content-types:
Orchestrates intelligent skill selection and execution for github actions templates 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 generate_github_action_template(
task_description: str,
available_templates: List[Dict],
min_confidence: float = 0.7
) -> Optional[Dict]:
"""Generate a GitHub Actions workflow template based on task description.
Selects the most appropriate base template (CI, CD, Lint, etc.) using
multi-factor scoring: trigger type, language/framework, and historical usage.
Applies Law 1 (Early Exit) and Law 2 (Immutable State).
Args:
task_description: Natural language description of the automation task
available_templates: List of template metadata with triggers and languages
min_confidence: Minimum match threshold for template selection
Returns:
Rendered workflow dict with metadata, or None if no suitable template
"""
if not task_description or not task_description.strip():
raise ValueError("Task description cannot be empty")
if not available_templates:
raise ValueError("No GitHub Actions templates available")
# Extract intent features (Law 2: Parse at boundary)
intent = _extract_workflow_intent(task_description)
best_template = None
best_score = 0.0
for tmpl in available_templates:
score = _calculate_template_match(intent, tmpl)
if score > best_score and score >= min_confidence:
best_score = score
best_template = tmpl
if best_template is None:
return None
# Law 3: Return new structure, never mutate input template
workflow = {
"name": best_template["name"],
"on": best_template["triggers"],
"jobs": {},
"metadata": {
"source_template": best_template["id"],
"confidence": best_score,
"generated_at": time.time()
}
}
return workflow
def render_and_validate_template(
workflow_template: Dict,
context_vars: Dict,
fallback_templates: List[Dict] = None
) -> Dict:
"""Render a GitHub Actions workflow with variable substitution and validation.
Implements fallback chain (Law 4: Fail Fast, Fail Loud):
1. Attempt full rendering with provided context
2. Fallback to simplified template if complex variables fail
3. Defer to manual review if YAML validation fails
Args:
workflow_template: Base workflow structure from Pattern 1
context_vars: User-provided variables (e.g., python-version, os)
fallback_templates: Alternative templates to try on failure
Returns:
Validated workflow YAML string with execution metadata
"""
if not workflow_template or "jobs" not in workflow_template:
raise ValueError("Invalid workflow template structure")
# Law 2: Validate context before rendering
validated_vars = _sanitize_context_vars(context_vars)
try:
# Attempt primary render
rendered_yaml = _apply_jinja2_template(workflow_template, validated_vars)
_validate_github_actions_schema(rendered_yaml)
return {
"success": True,
"yaml": rendered_yaml,
"strategy": "primary",
"validation": "passed"
}
except SchemaValidationError as e:
# Law 4: Fail fast on invalid state
if fallback_templates:
# Fallback 1: Try simplified template variant
for alt in fallback_templates:
try:
alt_yaml = _apply_jinja2_template(alt, validated_vars)
_validate_github_actions_schema(alt_yaml)
return {
"success": True,
"yaml": alt_yaml,
"strategy": "fallback_simplified",
"validation": "passed"
}
except SchemaValidationError:
continue
# Fallback 2: Return structured error for human review
return {
"success": False,
"error": f"Template validation failed: {str(e)}",
"strategy": "defer_human",
"raw_context": validated_vars
}
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.