State/bin/evolve/run.ts (proposer + applier). .md file to compare - side-by-side diff against evolve
evolve
description: "Triggers on prompt mention of 'evolve'."
What it does for you
Lets your assistant keep improving itself and only keeps changes that help.
What it produces
A recent result, so you can see the kind of work it returns.
loading…
How to get it
These run inside the Snappy workspace. Want this working in your business? I set skills like this up with you, in one focused week.
For developers how this skill is built, graded, and how it runs
at a glance- the short version
what's inside - the parts that make up a skill 2/4 present
A skill is just a few plain-text files. Only the main one is required. The rest are optional, added as the work needs them. This is what the skill is made of; how it runs is just below.
state/skills/evolve/SKILL.md
present
state/lib/evolve.ts
not present
state/bin/evolve/
not present
state/skills/evolve/AGENTS.md
present
how it's graded - what counts as a good run 5 criteria · 4 deterministic · 1 judge
Each row is one thing a good run has to get right. deterministic means a quick check decides, pass or fail. judge means the AI reads the result and rates it. Grading each piece on its own (instead of one overall score) shows exactly where a run fell short, so the fix is obvious.
how it runs - the shared frame every skill uses 5/5 present
Every skill runs the same way. One part does the work, a separate part checks it, and a short loader hands the AI exactly what it needs for the job. Anything this skill doesn't use shows a one-line note saying why, on purpose, not by accident.
state/log/evals.ndjson - NEVER disable or weaken the revert primitive — it is the ONLY safety. No "pause on N regressions", no "stop if score drops", no manual confirm.
- NEVER skip measure() — a committed mutation without a measurement is a silent bias in baseline.
- NEVER rewrite rows in state/log/evolve.ndjson — the log is append-only; it is the artifact.
- ALWAYS start from a clean working tree (harness exits 3 if dirty). Stash first, don't force.
- DO NOT push to remote from inside the harness. Local commits only; operator chooses when to push.
- Mutations MUST be idempotent — a no-op candidate SKIPs cleanly, never double-commits.
what it has learned - fixes written back in over time sample
When a run hits something this skill didn't handle, the fix gets written back into the skill so it doesn't happen again. FIXED means it was corrected on the spot. LOGGED means it's queued for a bigger rewrite. Either way, the skill gets a little better and never makes the same mistake twice.
- Loading feedback rows…
how the work flows- who makes it, who checks it
npx tsx state/bin/evolve/run.ts --max=<n>` (default 10)
what this step does
what this step does
SKILL.md- the skill, written out in plain English
evolve
The machine version of chaos-injection. snappy-os runs mutations on itself indefinitely, reverting what regresses and keeping what compounds. No human in the loop - the revert primitive IS the safety. No stop condition; "999 and then another 999" is the doctrine.
Steps
1. Scope - no side effects
Read state/log/evolve.ndjson to see what stuck and what didn't. This is the audit surface.
2. Gate
Working tree MUST be clean before starting. Any uncommitted change is a failure mode - the harness can't distinguish a regression from operator noise. The harness aborts with exit 3 if the tree is dirty.
3. Act - the loop
npx tsx state/bin/evolve/run.ts --max=3 # smoke (3 iterations)
npx tsx state/bin/evolve/run.ts --max=10 # default sanity
npx tsx state/bin/evolve/run.ts --max=999 # real session
Each iteration:
propose_mutation(i)- deterministic, rotating over a 5-candidate catalog.apply_candidate()- edit +git add+git commit(local only).measure()- recomputehealth_score.keep_or_revert()- keep if Δ > 0.005, elsegit revert HEAD --no-edit.- Append one row to
state/log/evolve.ndjson.
4. Log + eval
The harness itself appends to state/log/evolve.ndjson. Eval is shape-based: row presence + fields {i, candidate, baseline, new, delta, kept, wall_time_ms} intact. The delta sign determines whether the mutation landed.
Health score
Composite metric in [0, 1]:
| Weight | Component | Source |
|---|---|---|
| 0.35 | rolling-20 eval mean | state/log/evals.ndjson |
| 0.25 | open-breakage inverted | state/log/breakage-report.ndjson (latest-per-area) |
| 0.20 | parity mean across runtimes | state/log/parity.ndjson (last batch) |
| 0.10 | sync-drift inverted | state/log/sync-events.ndjson (tail 500) |
| 0.10 | recurring-area inverted | state/log/breakage-report.ndjson (open-row count by area, last 7d) |
Mutation catalog
Five seed candidates (rotated by (i-1) % N). Three earlier candidates (tune-breaker-cooldown, tighten-graduation-bar, swap-tui-view-order) were pruned 2026-04-26 because their target files (autopilot/break.sh, byline/tui.sh) and concept (graduation bar) were retired.
add-lint-rule-trailing-newline- new warn rule instate/lint/check.tsextend-parity-canonical-5-to-6- addopstoCANONICAL_SKILLSinstate/lint/parity-test.tstighten-lint-rule- promoteeval-unknownlint from warn → error instate/lint/check.tsadd-eval-gate-threshold- raise auto-eval gate0.50 → 0.55instate/lint/check.tsprune-redundant-skill- new warn rule: skills must have a paired<name>/AGENTS.mdloader
Mutations are idempotent - already-applied mutations SKIP cleanly (logged, no commit).
Eval
Actor: state/bin/evolve/run.ts (proposer + applier). Auditor: health_score() reading ndjson logs the actor does NOT write.
The actor cannot game the score because the score is sourced from independent logs (evals, breakage, parity, sync-events, pid-trends).
Score convention:
| Outcome | Score |
|---|---|
| Row appended with all required fields | 1.0 |
| Row missing fields / malformed | 0.0 |
The kept/reverted decision is the evolutionary signal, not the eval.
Gotchas
- Working tree MUST be clean before invoke - exit 3 otherwise.
- Mutations are staged as local commits and NOT pushed. Operator decides
when (or whether) to push.
- The revert is the safety. There is no "pause on N regressions" knob -
that would cap the harness's agency (doctrine).
- Do not add LLM calls on the hot path - determinism lets the harness run
overnight without operator babysitting.
- Iterations are append-only; never rewrite rows in
evolve.ndjson.
Graduation
Graduated on first commit - this skill is born with a sidecar. The prose is documentation, not the implementation.
Rubric
criteria:
- name: working_tree_clean_exit_code
kind: deterministic
check: "The skill script exits with code 3 if the working tree is not clean at invocation."
- name: log_integrity_and_completeness
kind: deterministic
check: "Each iteration appends a well-formed row to 'state/log/evolve.ndjson' containing fields {i, candidate, baseline, new, delta, kept, wall_time_ms} as specified."
- name: mutation_catalog_adherence
kind: deterministic
check: "The 'candidate' field in 'state/log/evolve.ndjson' logs matches one of the 8 specified mutation names in the documented catalog for its corresponding iteration 'i'."
- name: keep_revert_logic_adherence
kind: deterministic
check: "For each iteration, the 'kept' field in 'state/log/evolve.ndjson' is true if 'delta' > 0.005, and false otherwise, reflecting the 'keep_or_revert()' logic."
- name: side_effect_honesty
kind: judge
check: "The skill only modifies the local git repository and 'state/log/evolve.ndjson', without pushing commits or altering other system states not explicitly mentioned."AGENTS.md- what the AI loads when this skill comes up
evolve - loader
Per-turn rules for the evolve skill. Full reference: state/skills/evolve/SKILL.md. Do not skip these.
Critical Rules
- NEVER disable or weaken the revert primitive - it is the ONLY safety. No "pause on N regressions", no "stop if score drops", no manual confirm.
- NEVER skip
measure()- a committed mutation without a measurement is a silent bias in baseline. - NEVER rewrite rows in
state/log/evolve.ndjson- the log is append-only; it is the artifact. - ALWAYS start from a clean working tree (harness exits 3 if dirty). Stash first, don't force.
- DO NOT push to remote from inside the harness. Local commits only; operator chooses when to push.
- Mutations MUST be idempotent - a no-op candidate SKIPs cleanly, never double-commits.
Commands
| ui dashboard | state/skills/evolve/resources/ui.openui | |invoke: npx tsx state/bin/evolve/run.ts --max=<n> (default 10) |smoke: npx tsx state/bin/evolve/run.ts --max=3 |real: npx tsx state/bin/evolve/run.ts --max=999 |log: state/log/evolve.ndjson (append-only)
OpenUI Resource
- Skill-owned OpenUI Lang resource:
state/skills/evolve/resources/ui.openui. Read it before rendering or editing this skill's generated component surface. - Treat this resource as a first-class artifact of the skill, not a generic chat response. Improve it when the skill's user-facing output needs to become richer.
- System resources compose OpenUI primitives and inherit SnappyChat tokens. Use
ui_contract: brandedin SKILL.md only for deliberate platform or client visuals.
Known Pitfalls
- Statusline/hook runs can dirty the working tree between iterations - if a revert leaves drift, the harness aborts (exit 4). Investigate the hook, don't patch the harness.
pid-trends.tsis invoked per-iteration; if absent, recurring-area component defaults to 1.0 (no penalty) - don't confuse absence with perfection.health_scorereadsevals.ndjsontail-20 - if the log was recently truncated, baseline may be artificially low. Use a longer window for real sessions.
Self-Test
- [ ] Is the working tree clean before invoke?
- [ ] Is the mutation catalog idempotent (re-running the same iter is a no-op)?
- [ ] Does every iteration append exactly one row to
evolve.ndjson? - [ ] Does a reverted iteration leave the working tree clean?
Self-report
If this loader fell short, append a line:
echo "[$(date -u +%FT%TZ)] evolve: <what was missing>" >> state/log/loader-feedback.log
<!-- kernel-ok: historical attribution for the PID-loader pattern. -->
Self-correcting loader (PID feedback)
This is the rule that makes loaders learn. Ported from snappy-kernel, where it demonstrably worked: the snappy-dom-cartographer skill mapped Skool admin UI once, every later ship-agent inherited the full map for free.
Before you finish, do two things:
1. Fix gaps (P - proportional). MANDATORY. If this loader didn't cover your case - if you had to read another file, run an undocumented command, work around a wrong selector, or discover a quirk - you MUST attempt an Edit to this AGENTS.md before you log.
- Default action: edit this file. Surgical. Add the missing line, table
row, or code example where it belongs. No restructuring.
- Only
LOGGEDis allowed when: the fix needs >10 lines, spans multiple
files, or requires a structural rewrite. In that case the state/regen/drain.sh queue picks it up asynchronously.
- "I didn't have time" / "it's minor" / "the next agent will figure it out"
are NOT valid reasons. Minor gaps compound - that's the whole point of this loop.
- Concrete example of a valid P-fix: discover
agent-browser screenshot
takes path positionally not as --output <path>. One line in a table. Edit it in. Do not just log it.
- The goal: the next agent never has to leave the loader.
2. Log the result.
echo "[$(date -u +%FT%TZ)] evolve: <what was missing or fixed> [FIXED|LOGGED]" >> state/log/loader-feedback.log
FIXED= you patched this loader inline (P-fix).LOGGED= too large for inline; the PostToolUse enqueue + Stop-hook drain
will rewrite the loader from scratch on next session-end.
Do not skip this. Every agent run must leave the system better than it found it. The loader is the setpoint; you are the sensor; the gap is the error signal; closing the gap is the correction.
api.ts- the code it can call
⚠ no api.ts - this skill has no typed action surface
scripts- helper scripts it can run
prose-only skill - 2 inline code blocks live in SKILL.md above (no state/bin/ sidecar yet).
how we check it- the checks, plus the last 10 runs
| timestamp | verb | score | primary_issue | artifact |
|---|---|---|---|---|
| 2026-04-26 23:47Z | - | 0.50 | - | - |
| 2026-04-25 04:11Z | - | 1.00 | - | - |
| 2026-04-21 15:58Z | - | 1.00 | - | - |
| 2026-04-21 15:56Z | - | 1.00 | - | - |
| 2026-04-21 03:53Z | - | 1.00 | - | - |
| 2026-04-26 23:47Z | - | 0.50 | - | - |
| 2026-04-25 04:11Z | - | 1.00 | - | - |
| 2026-04-21 15:58Z | - | 1.00 | - | - |
| 2026-04-21 15:56Z | - | 1.00 | - | - |
| 2026-04-21 03:53Z | - | 1.00 | - | - |