agentleFS
crywolfecrywolfe/claude-code-design/.claude/skills/apply-edits/SKILL.md

apply-edits

Skill0 starsChanged 7 days agoMITView on GitHub

Apply buffered click-to-edit changes from artifacts/edits/<session>/pending.yaml to the source HTML. Invoked when user says "apply edits", "save edits", "persist the edits", or runs /apply-edits.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Write artifacts/edits/<session-id>/applied/<ts>.yaml: applied_at: <ts> changes:

    line 84
  2. Very specific:

    Write artifacts/edits/<session-id>/pending.yaml (empty) Edit state.yaml: last_applied_at: <ts>

    line 96

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Apply edits

Files are state, Claude is the writer. Spec: docs/plans/local-editor-plan.md §2.3–2.5.

Session lookup

session-id = edits-{slug}-{YYYYMMDD} for $0. If that directory does not exist, Bash(ls artifacts/edits/) and take the most recent directory whose name starts with edits-{slug}-.

Phase 1 — Read

Read state.yaml, pending.yaml, and $0. If pending is empty, report "no pending edits" and stop. If the user pasted YAML into chat instead, use that text as pending (only the entries under # pending.yaml).

Phase 2 — Validate (all or nothing)

Validation is done by code, not by you. If the edits came from pasted chat text, first Write them to artifacts/edits/<session-id>/pending.yaml. Then run:

Bash(node scripts/validate-pending.mjs edits artifacts/edits/<session-id>/pending.yaml --html $0)
  • Non-zero exit: stop. Show the script's output (one line per invalid entry) to the user. Do not apply a partial set and do not "fix" entries yourself.
  • Exit 0: the JSON on stdout is the validated set. Apply exactly those entries in Phase 3, nothing from the raw YAML that is not in that JSON.

The script enforces: __edits block and edits-generation meta present; target is e + 3 digits and appears on exactly one tag (tag-anchored, so the __edits block's own selectors never count); kind is text, style or hidden; text targets are leaves, with no <, > or newline and length ≤ 500; style prop/value pairs match the allowlist (colors #rrggbb; lengths 0 or number + px|rem|em|%; font-weight 100-900; opacity 0-1; text-align left/center/right/justify); hidden is true or false. The allowlist lives in the script, not in this file.

Phase 3 — Apply

  • text: Edit with old_string = the element's full opening tag (containing data-edit="<target>") plus its current text content plus its closing tag; new_string = same tags with the new text, with every & written as &amp;. Anchor on the tag, never on text alone.
  • hidden: Edit the opening tag to add hidden after the data-edit attribute (true) or remove it (false). The base rule in __edits makes it take effect.
  • style: collect all style entries. Read the existing <style id="__edits"> block, parse its per-target rules into {target: {prop: value}} (skip the comment line and the base rule), merge the new entries on top — an entry whose value is null deletes that (target, prop) from the map instead of setting it (this is how a style revert removes a rule that had no previous value). Emit the block exactly as:

    <style id="__edits">
    /* generated by /apply-edits — one rule per (target, prop); do not hand-edit */
    [data-edit][hidden] { display: none !important; }
    [data-edit="e004"] { color: #111111 !important; font-size: 48px !important; }
    </style>

    targets sorted ascending, props sorted alphabetically, every declaration ending in !important;, one rule per line. Edit the whole old block to the new one.

  • generation: Edit <meta name="edits-generation" content="N"> to N+1. This invalidates the overlay's localStorage buffer for the values just applied.

Phase 4 — Log and clear

While applying in Phase 3, note each entry's previous value: the old text, the old __edits value for that (target, prop) or null, the old hidden state. The log stores both so revert needs no other source.

Bash(date -u +%Y%m%dT%H%M%SZ)   → copy the printed value as <ts>
Write artifacts/edits/<session-id>/applied/<ts>.yaml:
  applied_at: <ts>
  changes:
    - target: e002
      kind: text
      value: "Hello"
      previous: "Editable smoke"
    - target: e004
      kind: style
      prop: background-color
      value: "#0a5c36"
      previous: null
Write artifacts/edits/<session-id>/pending.yaml   (empty)
Edit state.yaml: last_applied_at: <ts>

Verify

/done http://127.0.0.1:4567/<relative path>. Console clean, new text and styles visible.

Report

"Applied N edits (T text, S style, H hidden). Logged to artifacts/edits/<session-id>/applied/<ts>.yaml. Pending cleared."

Revert

On "revert last edits": Bash(ls artifacts/edits/<session-id>/applied/). Filenames sort by timestamp, so the last one is the newest. Read it and build a pending set from it where every entry's value is its previous (a style entry with previous: null becomes "remove this rule from __edits", written as value: null). Write that set to artifacts/edits/<session-id>/pending.yaml in the buffer format (text and style values as double-quoted strings, hidden as true/false), then run Bash(node scripts/validate-pending.mjs edits artifacts/edits/<session-id>/pending.yaml --html $0 --allow-null) and stop on a non-zero exit. Run Phase 3 on the validated set, then log it as applied/<ts>.yaml with type: revert and reverts: <old filename>.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.