plugins/agent-agentic-os/skills/self-evolution/SKILL.md
Self-healing and self-evolving pattern for agents operating against repo capabilities, scripts, skills, sub-agents, selectors, workflows, and external systems. Classifies evolution events into four tiers — Friction/Workaround, Gap, Failure, Regression — applies repo-profile-gated edits with appropriate autonomy, verifies the fix, and updates domain reference files ("The Map, not the Diary"). Invoke whenever a tool call, subprocess, or workflow returns a failure OR whenever the agent used a workaround, bypass, guess, or manual substitute for an existing repo capability.
npx skillsauth add richfrem/agent-plugins-skills self-evolutionInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Trigger: Any tool call, subprocess, workflow, skill, sub-agent, helper, or documented repo capability fails, behaves ambiguously, or is bypassed through a workaround, guess, or manual substitute — and the fix or Map Debt entry is within allowed boundaries.
Core principle: The agent does not just retry — it learns. Every fix either patches a helper (so the failure can't recur) or updates a reference file (so future agents avoid the same dead end). Fixes that aren't recorded are not fixes; they are patches waiting to become the same bug again.
Before doing anything else, locate and read the repo's self-evolution profile:
<repo-root>/plugins/<plugin>/references/self-evolution-profile.md
If no profile exists for the current repo/plugin, create a conservative default one now using the template in Phase 0.1 below, then continue — but only proceed if the target edit is inside the default allowed directories.
Also read <plugin>/references/map-debt.md if it exists. Surface any open entry that
matches the current friction — if Repeat: YES, escalate immediately (go to Phase 6)
instead of deferring again.
The profile defines:
If no profile exists, write one at <plugin>/references/self-evolution-profile.md:
# Self-Evolution Profile — <Plugin Name>
## Allowed Edit Directories
- plugins/<plugin>/skills/
- plugins/<plugin>/scripts/
- plugins/<plugin>/references/
## Explicit Confirmation Required
- plugin.json
- CLAUDE.md
- .agent/rules/
- ADRs/
- docs/
- repository root files
- any file outside this plugin
- any rename, move, or deletion
## Error Pattern Classification
| Pattern | Tier |
|---------|------|
| workaround used / bypassed capability | Friction |
| element not found / selector missing | Regression |
| function not exported / module not found | Gap |
| TypeError / syntax error | Failure |
| subprocess timeout | Regression |
| JSON parse error | Failure |
## Domain Playbook Location
plugins/<plugin>/references/
## Evolution Log
plugins/<plugin>/references/evolution-log.md
## Map Debt
plugins/<plugin>/references/map-debt.md
First ask: did the task succeed only because of a workaround, bypass, guess, or manual substitute for an existing repo capability? If yes → classify as Tier 0 directly.
Otherwise, using the error message, stack trace, and context, classify into exactly one tier:
"The task completed, but the system did not improve."
Definition + signals: see .agent/rules/self-evolution-policy.md § Tier 0.
Response: If small + inside allowed edit boundaries — patch now, update The Map. If not safe or small — log as Map Debt (see Phase 7). If repeated or blocking — escalate.
"The capability doesn't exist yet."
Signals:
function not found, is not a function, module has no exportResponse: Build the missing piece. No evidence collection needed.
"Code exists but is broken."
Signals:
TypeError, SyntaxError, ReferenceError inside our own codeResponse: Debug the code. Read the relevant source, identify the bug, patch it.
"This worked before. Something external changed."
Signals:
element not found, cannot read property of null on a well-used DOM pathResponse: Collect evidence first (screenshot + DOM snapshot), then patch with a fallback selector or updated timing. Document the change in The Map.
If ambiguous between Failure and Regression: default to Regression and collect evidence — the cost of a screenshot is lower than patching the wrong layer.
Evidence collection is tier-dependent:
| Tier | Evidence to collect |
|------|-------------------|
| Friction / Workaround | Intended capability, what was bypassed, workaround used, why the intended path was not used, reproduction step |
| Gap | None — log the capability boundary in the evolution log |
| Failure | Error message + stack trace (last 20 lines of stderr) + relevant source lines |
| Regression | Screenshot of current UI state + DOM snapshot of the failing selector area + git log --oneline -5 on the affected file |
For Regression, run the DOM snapshot before touching any code:
// Inline Node snippet to dump selector context
const els = document.querySelectorAll('[data-name]');
console.log(JSON.stringify([...els].map(e => e.getAttribute('data-name')).filter(Boolean)));
Save evidence to temp/self-evolution/<timestamp>-evidence/.
Based on tier and evidence:
Gap: Identify the exact file and function to create. Check the allowed edit directories from the profile. If the target file is outside those dirs, escalate to the user (Phase 6).
Failure: Read the failing function. Identify the minimal fix. Prefer adding a guard or correcting an argument over rewriting logic.
Regression: Identify the old selector/timing from git history or the domain playbook. Find a new stable selector from the DOM snapshot. Plan a two-path patch: primary (new selector) + fallback (broader query with filter).
Write the plan as 3–5 bullet points before touching any file.
Check the edit type before writing:
| Edit type | Gate | |-----------|------| | Add new function / export | Auto-approved — proceed | | Add new selector / fallback path | Auto-approved — proceed | | Modify existing function logic | Auto-approved — append git diff to evolution log after edit | | Rename or move a file | Confirm with user: "About to rename X → Y. Confirm?" | | Delete any file or function | Hard stop — always confirm with user before proceeding |
Steps:
git diff <file> and save output to evolution log.Re-run the exact operation that originally failed:
# Re-run the specific command / test that triggered self-evolution
Pass: Proceed to Phase 6.
Fail (attempt 1): Return to Phase 3, reconsider the diagnosis. Try a different repair approach.
Fail (attempt 2): Return to Phase 3, broaden evidence collection.
Fail (attempt 3 — final): Escalate to user (Phase 6, escalation path). Do not make further edits. Present the full evidence bundle and the three approaches tried.
Whether or not the fix succeeded, update the domain reference files:
If fix succeeded:
references/*.md with the new selector
and a note: <!-- updated <date>: old=[...] new=[...] TV regression --><playbook-location> from the profile (see Playbook Format below)If escalating to user:
UNRESOLVED and the
three approaches tried — so the next agent doesn't repeat the same dead endsCreate <playbook-location>/<topic>-playbook.md:
# Playbook: <Topic>
**Status:** ACTIVE | UNRESOLVED
**Last verified:** YYYY-MM-DD
**Relevant files:** list of files
## What This Covers
One sentence.
## The Mechanics
Step-by-step: what works, what the exact selectors/timing are, why.
## Known Failure Modes
| Symptom | Tier | Fix applied |
|---------|------|-------------|
## Change History
| Date | What changed | Tier | Outcome |
Append one row to the evolution log (evolution-log.md from profile):
| <date> | <tier> | <what failed or friction observed (one line)> | <what was patched, OR "Map Debt: <reason>"> | <edit type> | <outcome: FIXED/MAP_DEBT/ESCALATED> |
When outcome is MAP_DEBT, also append an entry to <plugin>/references/map-debt.md
(create with header if missing). Map Debt is a working queue — items are resolved over time;
the evolution log is the immutable audit trail. Do not double-count: one write to each.
# Map Debt
| Logged | Cycle ID | Artifact | Friction | Why Not Fixed | Recommended Fix | Severity | Repeat | Status |
|--------|----------|----------|----------|---------------|-----------------|----------|--------|--------|
| <YYYY-MM-DD> | <CID from events.jsonl> | <file path or skill slug> | <friction in one sentence> | <reason> | <recommended fix> | S/M/L | YES/NO | OPEN |
Aging rule: At Phase 0 read, count completed cycles since the entry's Cycle ID. If an
OPEN entry is older than 3 completed cycles, auto-escalate before starting new work.
If the Cycle ID is from a prior session (not in current events.jsonl), fall back to
the Logged date: auto-escalate if (today - Logged) > 14 days.
Set Status to RESOLVED when fixed, ESCALATED when escalated to the user.
If the log file doesn't exist yet, create it with the header:
# Evolution Log
| Date | Tier | Failure | Patch | Edit Type | Outcome |
|------|------|---------|-------|-----------|---------|
When escalating to the user after 3 failed attempts:
Self-Evolution Escalation — [Tier: Regression/Failure/Gap]
Operation that failed:
<command>Error:<error message>Evidence:temp/self-evolution/<timestamp>-evidence/Three approaches tried:
<approach 1>→<result><approach 2>→<result><approach 3>→<result>What I need from you:
<specific question — e.g., "What is the new selector for the Indicators dialog?">Once you provide it, I will apply the fix and update The Map.
testing
Skill for creating and managing isolated git worktrees (`.worktrees/issue-NNN`) for issue execution branches. USE ONLY when setting up or cleaning up isolated git worktrees for specific issue execution. DO NOT USE for managing local task files (use `task-agent`) or escalating tasks to issues (use `github-issue-backlog-agent`).
data-ai
Skill for orchestrating the end-to-end GitHub issue lifecycle flow: Issue -> Worktree -> Implementation -> PR Creation -> Resolution Closure. USE ONLY when running or dry-running full lifecycle orchestration for resolving an issue with a PR. DO NOT USE for isolated worktree management only (use `issue-worktree-agent`) or logging issues (use `github-issue-agent`).
tools
Automatically ranks GitHub issues (P0-P3) based on friction tier, frequency, and blockages, synchronizing priority labels and GitHub Projects v2 custom fields.
testing
Bridge skill for escalating ephemeral local task scratchpad items (`tasks/*.md`) into durable, taxonomy-validated, evidence-rich GitHub Issues. USE ONLY when promoting a single-session local task into durable repository backlog. DO NOT USE for managing local kanban boards (use `task-agent` instead) or directly querying/commenting on issues (use `github-issue-agent` instead).