Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Before main skill execution, perform guardrail checks.
.claude/skills/majiayu000-autonomous-agent/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-05 | ✗→✓ | ▲ Improved | 357% | 0% |
| case-06 | ✗→✓ | ▲ Improved | 387% | 0% |
| case-07 | ✗→✓ | ▲ Improved | 619% | 0% |
| case-10 | ✗→✓ | ▲ Improved | 816% | 0% |
| case-14 | ✗→✓ | ▲ Improved | 273% | 0% |
<input_guardrails>
Before main skill execution, perform guardrail checks.
Read .loa.config.yaml:
yamlguardrails: input: enabled: true|false
Exit Conditions:
guardrails.input.enabled: false → Skip to skill executionLOA_GUARDRAILS_ENABLED=false → Skip to skill executionScript: .claude/scripts/danger-level-enforcer.sh --skill autonomous-agent --mode {mode}
CRITICAL: This is a high danger level skill (full orchestration control).
| Mode | Behavior | | ----------- | --------------------------------------------- | | Interactive | Require explicit confirmation with reason | | Autonomous | BLOCK (high-risk skill requires --allow-high) |
Note: The autonomous-agent skill is classified as high rather than critical because it operates through other skills that have their own guardrails. The orchestrator itself doesn't directly execute dangerous operations.
Script: .claude/scripts/pii-filter.sh
Detect and redact sensitive data before orchestration begins. Important for multi-phase execution where data flows between skills.
Script: .claude/scripts/injection-detect.sh --threshold 0.65
Lower threshold (0.65 vs default 0.7) because autonomous orchestration has higher impact potential. More conservative detection.
Write to grimoires/loa/a2a/trajectory/guardrails-{date}.jsonl.
On error: Log to trajectory, fail-open (continue to skill). </input_guardrails>
<objective> Execute autonomous work with exhaustive Loa process compliance, mandatory quality gates, self-auditing, remediation loops, and continuous improvement. Match human-level discernment and quality on every deliverable. </objective>
<issue_integrations>
This skill incorporates solutions from open Loa issues:
| Issue | Title | Integration | | ----- | ----------------------- | ------------------------------------------------------ | | #71 | Unix Philosophy | construct.yaml with input/output contracts per phase | | #70 | construct.yaml manifest | Full manifest with skills, execution order, gates | | #29 | PRD Iteration Loop | Phase 7 includes PRD gap check and /refine-prd trigger | | #48 | Feedback Protocol | Phase 7 captures learnings in structured YAML | | #23 | NOTES.md cleanup | Structured note format with types and expiry |
construct.yaml - Skill packaging manifest (#70, #71)resources/operator-detection.md - AI/human adaptationresources/feedback-protocol.md - Upstream learning flow (#48)resources/prd-iteration.md - PRD refinement loop (#29)resources/structured-notes.md - Note format with expiry (#23)resources/phase-checklist.md - Completion criteriaresources/quality-gates.md - Gate definitions</issue_integrations>
<prime_directive>
NO SHORTCUTS. NO EXCEPTIONS.
You are operating autonomously. Every action reflects on your principal's reputation. Follow EVERY step. Pass EVERY gate. Audit EVERYTHING.
If uncertain: STOP and ASK rather than proceed with assumptions. </prime_directive>
<execution_model>
┌─────────────────────────────────────────────────────────────────┐
│ AUTONOMOUS EXECUTION FLOW │
├─────────────────────────────────────────────────────────────────┤
│ │
│ PREFLIGHT ──▶ DISCOVER ──▶ DESIGN ──▶ IMPLEMENT │
│ │ │ │
│ │ ▼ │
│ │ ┌────────────────────── AUDIT ◀─────┐ │
│ │ │ │ │ │
│ │ │ ┌─────────────────────┤ │ │
│ │ │ │ │ │ │
│ │ │ ▼ ▼ │ │
│ │ │ PASS? ──YES──▶ SUBMIT │
│ │ │ │ │ │
│ │ │ NO ▼ │
│ │ │ │ POST-PR-VAL ◀── (v1.25.0) │
│ │ │ ▼ │ │
│ │ └─ REMEDIATE READY_FOR_HITL │
│ │ │ │ │
│ │ │ loop > 3 ▼ │
│ │ ▼ DEPLOY ──▶ LEARN │
│ └────────── ESCALATE ─────────────────────────────────────│
│ │
└─────────────────────────────────────────────────────────────────┘</execution_model>
<operator_detection>
Loa adapts behavior based on operator type. See resources/operator-detection.md for full details.
yaml# .loa.config.yaml operator: type: auto | human | ai ai_config: enforce_autonomous_skill: true strict_quality_gates: true require_audit_before_pr: true
type: auto)MANDATORY: Check in this order, first match wins:
CLAWDBOT_GATEWAY_TOKEN env var exists → AI_OPERATORCLAWDBOT_GATEWAY_PORT env var exists → AI_OPERATOR$HOME/.clawdbot/clawdbot.json exists → AI_OPERATORCLAUDECODE=1 → AI_OPERATORLOA_OPERATOR=ai → AI_OPERATORCLAWDBOT_AGENT=true → AI_OPERATORAGENTS.md — Agent instructionsSOUL.md — Agent identity/personalityIDENTITY.md — Agent metadataHEARTBEAT.md — Cron/heartbeat configTOOLS.md — Tool configurationUSER.md — User contextWORKLEDGER.md — Work tracking| Operator | Behavior | | --------- | ----------------------------------------------------------- | | Human | Interactive, suggestions, flexible process | | AI | Auto-wrap with /autonomous, mandatory audit, strict gates |
When AI detected and enforce_autonomous_skill: true:
Human: /implement task-1
AI: /implement task-1 → auto-wrapped with → /autonomous --target implementAll quality gates enforced. No shortcuts. </operator_detection>
<phase_0_preflight>
Purpose: Restore context, verify integrity, detect operator, select work.
Purpose: Archive previous cycle artifacts to create clean workspace.
markdown1. Run workspace-cleanup.sh --yes --json 2. Parse JSON result 3. Check for security errors (exit 3) → HALT 4. Check for partial state (.staging/.failed exists) → HALT 5. Other errors → log warning, continue
Implementation:
bash# Run cleanup in autonomous mode CLEANUP_RESULT=$(.claude/scripts/workspace-cleanup.sh --grimoire grimoires/loa --yes --json 2>&1) CLEANUP_EXIT=$? case $CLEANUP_EXIT in 0) # Success - check for partial state if echo "$CLEANUP_RESULT" | jq -e '.partial_state != null' > /dev/null 2>&1; then PARTIAL=$(echo "$CLEANUP_RESULT" | jq -r '.partial_state[]? // empty') if [[ -n "$PARTIAL" ]]; then echo "HALT: Partial archive state detected - manual intervention required" echo "Found: $PARTIAL" exit 1 fi fi echo "✓ Workspace cleanup complete" ;; 3) # Security validation failure - HALT echo "HALT: Workspace cleanup security validation failed" exit 1 ;; *) # Other error - log and continue echo "WARNING: Workspace cleanup failed (exit $CLEANUP_EXIT), continuing..." ;; esac
Fail-Closed Policy: When operating autonomously, any security error or partial state MUST halt the workflow. This prevents propagating errors through subsequent phases.
markdown1. Check environment variables (LOA_OPERATOR, CLAWDBOT_AGENT) 2. Parse AGENTS.md for operator markers 3. Check for HEARTBEAT.md patterns 4. Detect TTY mode 5. Set operator_type: 'human' | 'ai' 6. Load ai_config if operator_type == 'ai'
markdown1. Read `grimoires/loa/NOTES.md` 2. Extract "Session Continuity" section 3. Check "Blockers" - if any CRITICAL, HALT 4. Load previous trajectory if continuing work
bash# MANDATORY - Run before any work IF .loa-version.json exists: echo "✓ Loa mounted" ELSE: echo "✗ Loa not mounted - run /mount first" EXIT 1
markdown1. Read WORKLEDGER.md (or equivalent work queue) 2. Select highest priority item with status "Ready" 3. If no work: check backlog or HEARTBEAT_OK 4. Log work item to trajectory
markdown1. Set token counters to 0 2. Load thresholds from config 3. Prepare for Tool Result Clearing
</phase_0_preflight>
<phase_1_discovery>
Purpose: Understand requirements fully before designing.
Trigger: New work without existing PRD
markdownIF target codebase not yet analyzed: 1. Run `/ride` on target repository 2. Wait for reality/ artifacts 3. Verify grounding claims have file:line citations
markdown1. Run `/plan-and-analyze` (discovering-requirements skill) 2. Follow ALL phases of discovery 3. Generate PRD at `grimoires/{project}/prd.md`
markdownVERIFY PRD contains: - [ ] Executive summary - [ ] Problem statement with evidence - [ ] Goals with measurable metrics - [ ] User stories with acceptance criteria - [ ] Technical constraints - [ ] Dependencies identified - [ ] Risks with mitigations
Purpose: Adversarial multi-model review of PRD before proceeding to Design.
`markdownIF flatline_protocol.enabled AND autonomous_mode.enabled: 1. Execute Flatline Protocol on PRD: ```bash result=$(.claude/scripts/flatline-orchestrator.sh \ --doc grimoires/loa/prd.md \ --phase prd \ --autonomous \ --run-id "$run_id" \ --json) ``` 2. Handle results per autonomous_mode.actions: ```bash .claude/scripts/flatline-result-handler.sh \ --mode autonomous \ --result "$result" \ --document grimoires/loa/prd.md \ --phase prd \ --run-id "$run_id" ``` 3. Exit code handling: - 0: Continue to Phase 2 - 1: BLOCKER halt → Generate escalation, STOP workflow - 4: Disputed threshold → Generate escalation, STOP workflow 4. Log summary to NOTES.md: "Flatline PRD Review: {N} integrated, {M} disputed, {K} blockers" ELSE: Skip Flatline review, log "Flatline disabled for PRD phase"
</phase_1_discovery>
<phase_2_design>
Purpose: Architecture and planning before implementation.
markdown1. Run `/architect` (designing-architecture skill) 2. Generate SDD at `grimoires/{project}/sdd.md` 3. Include: - System diagrams - Component design - Data flow - API contracts - Security considerations
markdown1. Run `/sprint-plan` (planning-sprints skill) 2. Generate sprint.md with: - Atomic tasks - Acceptance criteria per task - Dependencies mapped
Purpose: Adversarial multi-model review of SDD before sprint planning execution.
`markdownIF flatline_protocol.enabled AND autonomous_mode.enabled: 1. Execute Flatline Protocol on SDD: ```bash result=$(.claude/scripts/flatline-orchestrator.sh \ --doc grimoires/loa/sdd.md \ --phase sdd \ --autonomous \ --run-id "$run_id" \ --json) ``` 2. Handle results per autonomous_mode.actions: ```bash .claude/scripts/flatline-result-handler.sh \ --mode autonomous \ --result "$result" \ --document grimoires/loa/sdd.md \ --phase sdd \ --run-id "$run_id" ``` 3. Exit code handling: - 0: Continue to Sprint review - 1: BLOCKER halt → Generate escalation, STOP workflow - 4: Disputed threshold → Generate escalation, STOP workflow ELSE: Skip Flatline review, log "Flatline disabled for SDD phase"
markdownVERIFY: - [ ] SDD traces to PRD requirements - [ ] All PRD requirements covered - [ ] Tasks are atomic and testable - [ ] No circular dependencies
Purpose: Adversarial multi-model review of sprint plan before implementation.
`markdownIF flatline_protocol.enabled AND autonomous_mode.enabled: 1. Execute Flatline Protocol on sprint plan: ```bash result=$(.claude/scripts/flatline-orchestrator.sh \ --doc grimoires/loa/sprint.md \ --phase sprint \ --autonomous \ --run-id "$run_id" \ --json) ``` 2. Handle results per autonomous_mode.actions: ```bash .claude/scripts/flatline-result-handler.sh \ --mode autonomous \ --result "$result" \ --document grimoires/loa/sprint.md \ --phase sprint \ --run-id "$run_id" ``` 3. Exit code handling: - 0: Continue to Phase 3 (Implementation) - 1: BLOCKER halt → Generate escalation, STOP workflow - 4: Disputed threshold → Generate escalation, STOP workflow ELSE: Skip Flatline review, log "Flatline disabled for sprint phase"
</phase_2_design>
<phase_3_implementation>
Purpose: Build the solution with quality.
markdownFOR each task IN sprint.md: 1. Read task acceptance criteria 2. Run `/implement` for this task 3. Apply Tool Result Clearing after searches 4. Run relevant tests 5. Commit with conventional message 6. Log to trajectory 7. Update sprint.md status
markdownCONTINUOUSLY: - Run linters/formatters - Execute unit tests after changes - Check for security issues (no secrets, no vulns) - Respect attention budget
markdownAFTER every search/grep/find: IF results > 2000 tokens: 1. Extract top 10 relevant files 2. Synthesize to NOTES.md 3. Clear raw results 4. Keep only summary
</phase_3_implementation>
<phase_4_audit>
Purpose: Verify quality before any external action.
markdown1. Run `/audit-sprint` (auditing-security skill) 2. Audit ALL dimensions: - Security (auth, injection, secrets) - Architecture (patterns, coupling, cohesion) - Code Quality (complexity, duplication, naming) - DevOps (CI/CD, monitoring, docs) - Domain-specific (blockchain, API, etc.)
markdownFOR each dimension: Score 1-5 using RUBRICS.md criteria PASS if ALL dimensions >= audit_threshold (default: 4) FAIL if ANY dimension < audit_threshold
markdownGenerate audit report with: - Overall PASS/FAIL - Scores by dimension - Findings with severity - Remediation guidance - Evidence citations
markdownIF all_scores >= threshold: → Proceed to Phase 5 (Submit) ELSE: → Enter Phase 4.5 (Remediation)
</phase_4_audit>
<phase_4_5_remediation>
Purpose: Fix audit failures until quality passes.
markdown1. Parse audit findings 2. Sort by severity: CRITICAL > HIGH > MEDIUM > LOW 3. Identify root causes
markdownFOR finding IN sorted_findings: IF finding.severity IN [CRITICAL, HIGH]: 1. Understand the issue 2. Design minimal fix 3. Apply fix 4. Verify locally 5. Log to trajectory
markdown1. Run `/audit-sprint` again 2. Check if all scores >= threshold 3. Increment remediation_loop counter
markdownIF all_scores >= threshold: → BREAK, proceed to Phase 5 ELIF remediation_loop > max_remediation_loops (default: 3): → ESCALATE to human ELSE: → REPEAT from 4.5.1
markdownGenerate escalation report: - Summary of issue - Remediation attempts made - Remaining failures - Recommendation for human action HALT autonomous execution NOTIFY human via configured channel
</phase_4_5_remediation>
<phase_5_submit>
Purpose: Create high-quality PR.
Gate: Only enter if Phase 4 audit PASSED
markdown1. Push branch to fork/origin 2. Verify push succeeded
markdownCreate PR with: - Title: Conventional commit format - Body: - Summary from PRD - Changes from sprint.md - Link to audit report (if applicable) - Trajectory summary
markdownVERIFY PR: - [ ] Title is descriptive - [ ] Body explains context - [ ] No secrets in diff
</phase_5_submit>
<phase_5_5_post_pr_validation>
Purpose: Validate PR quality before human review.
Gate: Only enter if post_pr_validation.enabled: true in .loa.config.yaml
markdownIF post_pr_validation.enabled: 1. Invoke: .claude/scripts/post-pr-orchestrator.sh --pr-url <pr_url> --mode autonomous 2. Handle exit codes: - 0 (SUCCESS) → state = READY_FOR_HITL - 1 (ERROR) → state = HALTED, log error - 2 (TIMEOUT) → state = HALTED, escalate - 3 (PHASE_FAIL) → state = HALTED, check findings - 4 (BLOCKER) → state = HALTED, Flatline blocker found - 5 (USER_HALT) → state = HALTED, user intervention ELSE: → Skip to Phase 6 (Deploy) or Phase 7 (Learning)
The orchestrator executes these phases in sequence:
| Phase | Description | Fix Loop | | ----------------- | -------------------------------------- | ----------- | | POST_PR_AUDIT | Consolidated security/quality audit | Yes (max 5) | | CONTEXT_CLEAR | Checkpoint, prompt user to /clear | No | | E2E_TESTING | Fresh-eyes build and test verification | Yes (max 3) | | FLATLINE_PR | Optional multi-model review (~$1.50) | No |
State File: .run/post-pr-state.json
When user runs /autonomous --resume after context clear:
markdown1. Check post-PR state file (.run/post-pr-state.json) 2. If state == CONTEXT_CLEAR: - Load checkpoint from NOTES.md Session Continuity - Continue with: post-pr-orchestrator.sh --resume - E2E testing runs with fresh context 3. On completion: - state = READY_FOR_HITL - Continue to Phase 6 or Phase 7
yaml# .loa.config.yaml post_pr_validation: enabled: true phases: audit: { enabled: true, max_iterations: 5 } context_clear: { enabled: true } e2e: { enabled: true, max_iterations: 3 } flatline: { enabled: false } # Opt-in, ~$1.50 cost
Full Specification: .claude/commands/post-pr-validation.md </phase_5_5_post_pr_validation>
<phase_6_deploy>
Purpose: Safely deploy and verify.
Gate:
require_human_deploy_approval == false OR approval received)markdown1. Run `/deploy-production` 2. Monitor deployment progress 3. Capture deployment logs
markdown1. Run `/audit-deployment` 2. Verify: - Health checks passing - No error rate increase - Performance within bounds - Functionality working
markdownIF audit-deploy fails: 1. Initiate rollback 2. Verify rollback success 3. Log incident 4. Escalate to human
</phase_6_deploy>
<phase_7_learning>
Purpose: Improve from experience, iterate on PRD, feed learnings upstream.
See also:
resources/prd-iteration.md (Issue #29)resources/feedback-protocol.md (Issue #48)resources/structured-notes.md (Issue #23)markdownReview execution: - What worked well? - What required remediation? - New patterns discovered? - Process improvements? - Implementation gaps vs PRD?
markdown1. Parse trajectory for deviations from PRD 2. Identify gaps: - Requirements not fully met - Features added not in PRD - Better approaches discovered 3. Classify: major | minor 4. Decision: - Major gaps → invoke /refine-prd OR escalate - Minor gaps → log to NOTES.md for future
markdown1. Generate feedback entries: - Gaps → type: gap - Friction points → type: friction - Patterns observed → type: pattern - Improvement ideas → type: improvement 2. Write to grimoires/loa/feedback/{date}.yaml 3. Classify target: loa | clawdbot | registry | skill:{name} 4. Log to trajectory
markdown1. Create structured notes for significant items: - type: decision (never expires) - type: observation (14 day check) - type: synthesis (7 day expiry) 2. Update NOTES.md with session summary 3. If significant learning: - Update relevant documentation - Consider skill improvements 4. Feed to /compound (if enabled)
markdown1. Close trajectory log 2. Archive to trajectory/{date}.jsonl 3. Clear working memory (apply semantic decay)
markdown1. Mark work item complete 2. Update CHANGELOG.md (if applicable) 3. Commit workspace updates 4. If /refine-prd was invoked: - Wait for new sprint.md - Add new sprints to work queue 5. Ready for next work item
</phase_7_learning>
<resume_support>
The /autonomous --resume flag enables resumption of workflows halted by Flatline BLOCKER items.
`bashIF --resume flag provided: 1. Check for pending escalation report: ```bash escalation=$(.claude/scripts/flatline-escalation.sh list | jq '.[0]') ``` 2. IF escalation exists: - Extract run_id, phase, halted_at - Validate blocker concerns addressed - Resume from last completed phase 3. IF no escalation: - Check NOTES.md for "Flatline Halt" section - Resume from last checkpoint
`markdown1. Load escalation report: - run_id: Original Flatline run ID - phase: Phase where halt occurred (prd, sdd, sprint) - blockers: List of BLOCKER items that caused halt 2. Validate blockers addressed: FOR each blocker IN escalation.blockers: - Re-run Flatline on affected document - Verify blocker concern resolved - IF still present: HALT with "Blocker not addressed: {id}" 3. Resume execution: CASE phase: "prd": Resume from Phase 1.4 (Flatline PRD Review) "sdd": Resume from Phase 2.3 (Flatline SDD Review) "sprint": Resume from Phase 2.5 (Flatline Sprint Review) 4. Log resume event: ```json { "type": "flatline_resume", "original_run_id": "{run_id}", "phase": "{phase}", "blockers_resolved": N, "timestamp": "{ISO8601}" } ```
`### Resume Command
/autonomous --resume
/autonomous --resume --run-id flatline-run-abc123
`### Exit Criteria for Resume - [ ] Escalation report found and loaded - [ ] All blocker concerns addressed - [ ] Workflow resumed from correct phase - [ ] Resume event logged to trajectory ### Resume from Post-PR Context Clear (v1.25.0) When `/autonomous --resume` detects Post-PR Validation context clear state:
IF state file (.run/post-pr-state.json) shows state == CONTEXT_CLEAR:
**State File:** `.run/post-pr-state.json`
**Checkpoint Location:** `grimoires/loa/NOTES.md` → Session Continuity section
**Full Specification:** `.claude/commands/post-pr-validation.md`
</resume_support>
<attention_budget>
## Attention Budget
This skill MUST enforce attention budget throughout ALL phases.
### Thresholds
| Context | Limit | Action |
| ------------- | ------------- | ------------------ |
| Single search | 2,000 tokens | Apply TRC |
| Accumulated | 5,000 tokens | MANDATORY TRC |
| Session total | 15,000 tokens | Checkpoint & yield |
### Tool Result Clearing
After ANY tool returning >2K tokens:
1. **Extract**: Max 10 files, 20 words each
2. **Synthesize**: Write to NOTES.md
3. **Clear**: Remove raw output
4. **Summary**: Keep one-line reference
### Semantic Decay
| Stage | Age | Format |
| -------- | ------- | ------------------- |
| Active | 0-5min | Full synthesis |
| Decayed | 5-30min | Paths only |
| Archived | 30+min | Single-line summary |
</attention_budget>
<factual_grounding>
## Factual Grounding
ALL claims MUST be evidenced.
### Required Format
✓ GROUNDED: "Function validates JWT tokens" (src/auth/jwt.ts:45) ✗ UNGROUNDED: The system probably handles auth well ✓ FLAGGED: ASSUMPTION] Users likely prefer dark mode
### Verification
Before any synthesis:
1. Quote exact text from source
2. Cite with absolute path and line
3. Flag assumptions explicitly
</factual_grounding>
<trajectory_logging>
## Trajectory Logging
Log EVERY significant action to `grimoires/{project}/trajectory/{date}.jsonl`:
{"ts":"2026-01-30T22:30:00Z","agent":"autonomous-agent","phase":0,"action":"preflight_start","status":"started"} {"ts":"2026-01-30T22:30:05Z","agent":"autonomous-agent","phase":0,"action":"notes_loaded","status":"completed"} {"ts":"2026-01-30T22:30:10Z","agent":"autonomous-agent","phase":1,"action":"discover_start","skill":"discovering-requirements","status":"started"}
### Required Fields
- `ts`: ISO 8601 timestamp
- `agent`: "autonomous-agent"
- `phase`: Current phase number
- `action`: Verb describing action
- `status`: started | completed | failed | escalated
### Optional Fields
- `skill`: Invoked skill name
- `tokens_used`: Token count for this action
- `audit_score`: Scores if auditing
- `remediation_loop`: Loop counter if remediating
</trajectory_logging>
<quality_commitment>
## Quality Commitment
As an autonomous agent, I commit to:
1. **NEVER skip a phase** - Every phase has value
2. **NEVER skip an audit** - Quality is non-negotiable
3. **NEVER submit without passing** - Reputation matters
4. **ALWAYS log my work** - Transparency enables trust
5. **ALWAYS ask when uncertain** - Assumptions are risks
6. **ALWAYS learn from failures** - Every remediation teaches
This skill exists because autonomous work must be BETTER than rushed work, not just faster.
</quality_commitment>
<context_management>
## Context Management Protocol
For long-running executions that risk context overflow.
### Soft Limit (80K tokens)
When approaching 80K tokens:
1. Summarize completed phases
2. Clear old tool outputs
3. Keep decisions + artifact refs
4. Write checkpoint
### Hard Limit (150K tokens)
When approaching 150K tokens:
1. EMERGENCY: Write full state to checkpoint
2. Clear conversation history
3. Reload from checkpoint summary
4. Continue execution
### Checkpoint Schema
version: 1 execution_id: "exec-{timestamp}" phase: "design" summary: "Max 500 words..." decisions: ...] artifacts: ...] errors: ...]
</context_management>Other measured skills in the registry, with their headline benchmark lift.