원클릭으로
foo-bar
Diagnose and repair selftest failures by running diagnostic commands and proposing fixes
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Diagnose and repair selftest failures by running diagnostic commands and proposing fixes
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Run linters/formatters on changed files and apply safe, mechanical fixes. Use in Flow 3 and Flow 4.
Run policy-as-code checks (e.g., OPA/Conftest) based on the policy_plan. Use in Flow 2 and Flow 4.
Run the relevant tests for the current change and summarize results. Use in Flow 3 (Build) and optionally in Flow 4 (Gate).
| name | heal_selftest |
| description | Diagnose and repair selftest failures by running diagnostic commands and proposing fixes |
| allowed-tools | Bash, Read, Write |
| category | governance |
| tier | critical |
You are a helper for diagnosing and repairing selftest failures in this repository. This skill teaches agents how to systematically identify, categorize, and fix problems that cause selftest steps to fail.
The skill provides a structured diagnostic procedure for:
Before using this skill:
uv, cargo, and standard Unix toolsUser reports: "Selftest is failing"
↓
Step 1: Check Kernel Health (make kernel-smoke)
↓ PASS → Continue
↓ FAIL → STOP, escalate
↓
Step 2: Show Selftest Plan (see all steps, tiers)
↓
Step 3: Identify Failed Steps (run selftest, capture output)
↓
Step 4: Run Failed Steps Individually (debug each one)
↓
Step 5: Categorize Errors (syntax, logic, dependency, etc.)
↓
Step 6: Propose Fixes (with code diffs, command changes, etc.)
↓
Step 7: Output Healing Report (findings + recommendations)
Purpose: Verify the repo isn't fundamentally broken. If kernel is broken, escalate immediately.
Command:
make kernel-smoke
# or
uv run swarm/tools/kernel_smoke.py --verbose
What to look for:
If kernel is broken:
STATUS: BLOCKED - Kernel health check failed
RECOMMENDATION: Stop here. The repository is fundamentally broken.
ESCALATION: Human must fix kernel issues before other selftest work can proceed.
If kernel is healthy:
STATUS: PASS - Kernel health check passed
RECOMMENDATION: Continue to Step 2
Purpose: Understand the full selftest structure—all steps, their tiers, and dependencies.
Command:
uv run swarm/tools/selftest.py --plan
# or
make selftest-plan
Output format (you'll see something like):
SELFTEST PLAN (16 steps)
├─ 1. core-checks [KERNEL] Rust cargo fmt, clippy, unit tests
├─ 2. skills-governance [GOVERNANCE] Skills linting and formatting
├─ 3. agents-governance [GOVERNANCE] Agent definitions linting
├─ 4. bdd [GOVERNANCE] BDD scenarios (cucumber features)
├─ 5. ac-status [GOVERNANCE] Validate acceptance criteria coverage
├─ 6. policy-tests [GOVERNANCE] OPA/Conftest policy validation
├─ 7. devex-contract [GOVERNANCE] Flows, commands, skills (depends: core-checks)
├─ 8. graph-invariants [GOVERNANCE] Flow graph connectivity (depends: devex-contract)
├─ 9. ac-coverage [OPTIONAL] Acceptance criteria coverage thresholds
└─ 10. extras [OPTIONAL] Experimental checks
What to record:
Purpose: Run the full selftest to see which steps fail.
Command:
uv run swarm/tools/selftest.py
# or
make selftest
Output format:
======================================================================
SELFTEST RUNNER
======================================================================
Mode: STRICT (KERNEL and GOVERNANCE failures block)
RUN core-checks ... PASS (242ms)
RUN skills-governance ... PASS (18ms)
RUN agents-governance ... FAIL (8ms) <-- FAILED
Error: .claude/agents/foo.md does not exist
RUN bdd ... SKIP <-- SKIPPED (due to dependency)
...
What to capture:
Record in your report:
Purpose: Get detailed error output for each failed step to understand root cause.
Command (for each failed step):
uv run swarm/tools/selftest.py --step <step-id> --verbose
# Examples:
uv run swarm/tools/selftest.py --step agents-governance --verbose
uv run swarm/tools/selftest.py --step devex-contract --verbose
What to capture:
Save to file:
uv run swarm/tools/selftest.py --step agents-governance --verbose 2>&1 | tee agents-governance-verbose.log
For each failed step, identify the root cause:
Typical causes:
cargo fmt violations (code not formatted)cargo clippy warnings treated as errorsDiagnostic commands:
# Check formatting
cargo fmt --check
# Check lints
cargo clippy --workspace --all-targets --all-features
# Run tests
cargo test --workspace --tests
Fix category: Code changes required (apply cargo fmt, fix clippy warnings, fix tests)
Typical causes:
.claude/skills/*/SKILL.md frontmatter not valid YAMLname, description, category, tierDiagnostic commands:
# Validate skills
uv run swarm/tools/validate_swarm.py --skills-only
# Or manually check frontmatter:
head -20 .claude/skills/*/SKILL.md
Fix category: File format/metadata (fix YAML frontmatter)
Typical causes:
.claude/agents/*.md frontmatter doesn't match swarm/config/agents/*.yamlname: field, and registry keyDiagnostic commands:
# Regenerate adapters from config
make gen-adapters
# Check for mismatches
make check-adapters
# Full validation
uv run swarm/tools/validate_swarm.py
Fix category: Agent config/registration (regenerate adapters, fix registry)
Typical causes:
.feature filesfeatures/ directoryDiagnostic commands:
# Check feature files exist
find features -name '*.feature'
# Check for Gherkin syntax errors
uv run swarm/tools/validate_swarm.py --features-only # if available
Fix category: Test scenario files (fix .feature syntax, add step definitions)
Typical causes:
Diagnostic commands:
# Check if AC file exists
ls -la RUN_BASE/signal/acceptance_criteria.md
# Check AC tracking
find . -name "*acceptance*" -o -name "*ac*" | head -10
Fix category: Requirements/documentation (define AC in specs)
Typical causes:
Diagnostic commands:
# Check for policy configuration
ls swarm/policies/ || echo "No policies defined"
# If OPA/Conftest installed:
conftest test <path>
Fix category: Code or policy update (adjust code to conform, or update policy rules)
Typical causes:
gen_adapters, gen_flows)Diagnostic commands:
# Full swarm validation
uv run swarm/tools/validate_swarm.py
# Regenerate flows from config
uv run swarm/tools/gen_flows.py --check
# Regenerate agent adapters from config
uv run swarm/tools/gen_adapters.py --platform claude --mode check-all
Fix category: Swarm infrastructure (regenerate adapters/flows, fix bijection)
Typical causes:
Diagnostic commands:
# Validate flow graph
uv run swarm/tools/flow_graph.py --validate
# Show graph structure
uv run swarm/tools/flow_graph.py --format dot | dot -Tpng > graph.png
Fix category: Flow specification (fix agent references, remove cycles, restructure flows)
Typical causes:
Diagnostic commands:
# Check coverage report
cargo tarpaulin --out Html || echo "Coverage tool not installed"
# Count AC vs tests
grep -r "Scenario:" features/ | wc -l
grep -r "#\[test\]" src/ | wc -l
Fix category: Test coverage (add tests, improve AC coverage)
Typical causes:
Diagnostic commands:
# Check extras step command
uv run swarm/tools/selftest.py --step extras --verbose
Fix category: Experimental (depends on specific check)
After categorizing errors, classify by impact:
| Tier | Failure? | Can Merge? | Action |
|---|---|---|---|
| KERNEL | Yes | NO | MUST fix before merge (P0) |
| GOVERNANCE | Yes | MAYBE | Can use --degraded short-term; should fix (P1-P2) |
| OPTIONAL | Yes | YES | Can ignore; fix later (P3) |
Severity Matrix:
KERNEL failures → P0 (blocking)
GOVERNANCE failures → P1/P2 (should fix; can warn)
OPTIONAL failures → P3 (informational)
For each failed step, suggest specific remediation with examples:
Error captured:
error: this boolean can be simplified
--> src/lib.rs:42:8
|
42 | if x == true { ... }
| ^^^^^^^^^^^
|
= note: `#[deny(clippy::bool_comparison)]` on by default
Fix:
- if x == true {
+ if x {
Confidence: HIGH (mechanical fix)
Error captured:
BIJECTION: Agent 'test-fixer' registered in AGENTS.md but
config file swarm/config/agents/test-fixer.yaml is missing
Fix options:
Create the config file:
cat > swarm/config/agents/test-fixer.yaml << 'EOF'
key: test-fixer
flows:
- build
category: implementation
color: green
source: project/user
short_role: "Fix failing tests"
model: inherit
EOF
Or remove from registry if agent is obsolete:
# Edit swarm/AGENTS.md and delete the row
Then regenerate:
make gen-adapters && make check-adapters
Confidence: HIGH (if config should exist)
Error captured:
Flow config swarm/config/flows/build.yaml has been modified
but markdown swarm/flows/flow-build.md is out of date
Fix:
uv run swarm/tools/gen_flows.py --write
make check-flows
Confidence: HIGH (regenerate from config)
Error captured:
Policy violation: Function 'dangerous_operation' not documented
Code must follow security policy: all functions handling secrets
must have @secure_documented marker
Fix options:
Add documentation to code:
/// @secure_documented
/// Handles sensitive credential data
fn dangerous_operation(secret: &str) { ... }
Or update policy if rule is too strict:
# In policies/security.rego
# Mark exception for this function:
exceptions["dangerous_operation"]
Confidence: MEDIUM (requires understanding policy intent)
Symptoms: core-checks failure with "cargo fmt --check"
Root cause: Code not formatted to project standard
Quick fix:
cargo fmt --all
cargo fmt --check # Verify
Symptoms: core-checks failure with clippy violations
Root cause: Code triggers clippy warnings
Quick fix:
cargo clippy --fix --workspace --allow-dirty
cargo fmt --all
cargo test # Verify fix doesn't break tests
Symptoms: agents-governance failure with "bijection" or "does not exist"
Root cause: Agent registered in AGENTS.md but no corresponding .claude/agents/*.md file
Quick fix:
# List missing agents
grep -v "^#" swarm/AGENTS.md | cut -f1 | while read key; do
if [ ! -f ".claude/agents/$key.md" ]; then
echo "Missing: $key"
fi
done
# Then create files or fix registry
Symptoms: devex-contract failure about flow mismatch
Root cause: Flow YAML config changed but markdown not regenerated
Quick fix:
make gen-flows
make check-flows
Symptoms: Multiple steps fail; some say "SKIP" instead of "FAIL"
Root cause: Step A failed, so Step B (which depends on A) was skipped
Solution: Fix Step A first, then re-run. Step B will no longer skip.
Example: If core-checks fails, then devex-contract will SKIP.
1. Fix core-checks (e.g., run `cargo fmt`)
2. Re-run: make selftest
3. devex-contract will now run instead of skip
When to use: A GOVERNANCE step is failing but you need to work around it temporarily.
Important: Degraded mode is a short-term workaround, not a solution. Document the issue and fix it as soon as possible.
Run the failing step in verbose mode:
uv run swarm/tools/selftest.py --step <step-id> --verbose
Document the root cause clearly.
Title: Selftest <step-id> failing: <brief problem>
Labels: [selftest, governance]
Body:
- **Step**: <step-id> (GOVERNANCE tier)
- **Failure**: <root cause>
- **Impact**: Can work around with --degraded mode
- **Fix**: <proposed solution>
- **Timeline**: Fix in next sprint
uv run swarm/tools/selftest.py --degraded
# or
make selftest-degraded
What happens:
Add a note to your change:
### Selftest Status: DEGRADED
**KERNEL**: PASS (all required checks passing)
**GOVERNANCE**: <step-id> failing (see issue #XYZ)
- Impact: <what's not being checked>
- Workaround: Running with --degraded flag
- Target: Fix in <sprint/date>
git add .
git commit -m "Work in progress: <description> (selftest <step-id> in degraded mode)"
git push origin <branch>
Stop fixing and escalate to human when:
Kernel smoke is broken
Multiple unrelated failures
Error message is cryptic or unclear
Selftest takes > 5 minutes
Unable to identify root cause after 30 min investigation
Fix requires changing core infrastructure or flow specs
Escalation format:
## Escalation: Selftest Issue
**Problem**: [Brief description]
**Diagnosis**:
- Steps taken: [list of diagnostic steps]
- Root cause: [if known]
- Why human intervention needed: [explain]
**Blocking**: [Yes/No - is this blocking work?]
**Evidence**:
- Error logs: [paste relevant output]
- Environment: [Python version, Rust version, OS]
**Recommendation**: [What should the human do next?]
These files will help you understand selftest system:
| File | Purpose |
|---|---|
SELFTEST_SYSTEM.md | Complete selftest architecture and philosophy |
swarm/tools/selftest_config.py | Step registry and data model |
swarm/tools/selftest.py | Main orchestrator (CLI modes, execution) |
swarm/tools/kernel_smoke.py | Lightweight kernel-only smoke test |
Makefile | Make targets for selftest (selftest, selftest-plan, selftest-degraded, kernel-smoke) |
CLAUDE.md | Agent and flow architecture overview |
.claude/agents/ | All domain agents and their prompts |
swarm/AGENTS.md | Agent registry |
swarm/config/agents/ | Agent configuration YAMLs |
swarm/config/flows/ | Flow configuration YAMLs |
When using this skill, the agent should:
Execute the diagnostic procedure step-by-step (kernel check → plan → identify failures → verbose debug → categorize → propose fixes)
Capture findings in a structured report
Output a healing report to RUN_BASE/build/selftest_healing_report.md with:
# Selftest Healing Report
## Kernel Health
**Status**: PASS | FAIL | BLOCKED
**Details**: Brief summary of kernel check
## Selftest Plan
**Steps**: 10
**Tiers**: KERNEL(1), GOVERNANCE(7), OPTIONAL(2)
## Failed Steps Identified
| Step ID | Tier | Status | Error (first 200 chars) |
|---------|------|--------|------------------------|
| core-checks | KERNEL | FAIL | cargo fmt --check: found unformatted code in src/lib.rs:42 |
| agents-governance | GOVERNANCE | FAIL | bijection: agent foo-bar registered but .claude/agents/foo-bar.md missing |
## Failure Categorization
### core-checks (KERNEL, P0)
- **Root cause**: Formatting violation
- **Error**: `src/lib.rs:42` has unformatted code
- **Fix**: Run `cargo fmt --all`
- **Severity**: P0 (blocking)
- **Confidence**: HIGH
### agents-governance (GOVERNANCE, P1)
- **Root cause**: Agent file missing
- **Error**: Agent 'foo-bar' in AGENTS.md but no .claude/agents/foo-bar.md
- **Fix**: Create the file or remove from registry
- **Severity**: P1 (should fix; can warn)
- **Confidence**: HIGH
## Proposed Fixes (in order)
### Fix 1: Format code
```bash
cargo fmt --all
Type: Mechanical (safe) Review: Not needed (formatting is deterministic)
cat > .claude/agents/foo-bar.md << 'EOF'
---
name: foo-bar
description: Brief description
color: green
model: inherit
---
You are the **Foo Bar** agent.
## Inputs
...
## Outputs
...
## Behavior
1. ...
EOF
Type: Configuration Review: Recommended (verify agent details are correct)
| Tier | Count | Status | Can Merge? |
|---|---|---|---|
| KERNEL | 1 | FAIL | NO (must fix) |
| GOVERNANCE | 1 | FAIL | MAYBE (can use --degraded) |
| OPTIONAL | 0 | PASS | YES |
Status: UNVERIFIED (can be fixed) Path forward: Apply fixes in order, then re-run selftest to verify Blocking: YES (KERNEL tier failure must be fixed before merge)
4. **Report back** with:
- Overall status (VERIFIED / UNVERIFIED / BLOCKED)
- Which fixes were applied
- Which require human review
- Next steps (re-run selftest, escalate, etc.)
---
## Key Points for Agents
- **Always start with kernel-smoke**: It's fast and tells you if the repo is broken
- **Respect tier semantics**: KERNEL failures block, GOVERNANCE can warn, OPTIONAL is informational
- **Understand dependencies**: If step A fails, step B might skip (not fail)
- **Propose specific fixes**: Don't just say "something is wrong"; give exact commands to fix it
- **Know when to escalate**: If you can't fix it in 30 minutes, escalate with full context
- **Document degraded mode usage**: If using `--degraded`, create a GitHub issue tracking the fix
- **Never force**: Don't use `--force` or skip validation; work within constraints
- **Test your fixes**: Re-run selftest after proposing fixes to verify they work