agentleFS
IrMahoIrMaho/TeleDOM/.agents/skills/dom-mutation/SKILL.md

dom-mutation

Skill10 starsChanged 2 months agoApache-2.0View on GitHub

Apply first-class DOM mutations under the BEFORE → ACTION → AFTER → DIFF observability contract with transactions, immutable undo/redo records, and guaranteed side-effect-free previews.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

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

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

    Read the DOMMutationResult: BEFORE state, the action taken, AFTER state and the structural DIFF.

    line 31
  2. Very specific:

    Every result must show all four contract phases (BEFORE/ACTION/AFTER/DIFF).

    line 60
  3. Very specific:

    After a rollback, compare_page_states on snapshots taken before begin should report identical states.

    line 62
  4. Distinctive:

    Never ship mutations as fixes — they are experiments.

    line 67

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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

Skill: DOM Mutation

PURPOSE

Modify the live DOM like an engineer: every mutation is observable (BEFORE → ACTION → AFTER → DIFF), undoable (immutable inverse records), and previewable before touching anything. Failures become structured DOM_MUTATION_FAILED results — a failed operation can never corrupt the session state of subsequent operations.

WHEN TO USE

  • Prototyping a UI change before implementing it in real code.
  • Fixing a blocking overlay/bug long enough to complete a workflow on the live page.
  • Testing how the page reacts to structural changes (removal, reorder, wrapping).
  • Sandbox experiments — the mutation engine plus undo history is your safety net.

PREREQUISITES

  • Live page (extension or Node simulation; JSDOM applies mutations faithfully).
  • A resolved target and a clear intent. For anything destructive: preview first.
  • Discipline: never mutate a page state you have not snapshotted (capture_page_state) when the change matters.

WORKFLOW

  1. preview_dom_mutation {operation, target, ...params} — dry-run: validates the target, describes the expected change, counts affected nodes and warns about destructive operations. Guaranteed no side effects. (preview_command is the older alias with the same contract.)
  2. mutate_dom {operation, target, ...params} — apply one of the 18 operations:
    • attributes: set_attribute (attribute, value), remove_attribute (attribute)
    • content: set_text (text), replace_text (text + replacement), set_inner_html (html), set_outer_html (newElementHtml)
    • classes: add_class / remove_class / replace_class (classes, value)
    • styles: set_style (style map), remove_style (classes as prop names)
    • structure: add_element (newElementHtml, parent, position: before|after|prepend|append), remove_element, replace_element (newElementHtml), move_element (parent, position), wrap_element (newElementHtml), unwrap_element, clone_subtree (copyAttributes)
  3. Read the DOMMutationResult: BEFORE state, the action taken, AFTER state and the structural DIFF.
  4. Multi-step changes: mutate_dom_transaction {mode: "begin"} → your mutate_dom calls join the transaction → mutate_dom_transaction {mode: "commit"} (verify + all-or-nothing commit) or {mode: "rollback", reason} (reverts every step in reverse order; the reason is recorded).
  5. undo_dom_mutation {} — undo the last mutation (or the last step of the open transaction) via its immutable inverse record. Empty stack reports "nothing to undo" — safe to call speculatively.
  6. redo_dom_mutation {} — re-apply the last undone mutation only when safe (forward patch guarded).
  7. get_mutation_history {limit} — entries with operation, target, summary, undo/redo flags, plus undo depth, redo depth and the open transaction id.
  8. clone_dom_subtree {target, parent?, copyAttributes} — deep clone appended to a parent (or the original parent); ids are never duplicated.

TOOLS

mutate_dom, mutate_dom_transaction, undo_dom_mutation, redo_dom_mutation, get_mutation_history, preview_dom_mutation, preview_command, clone_dom_subtree, capture_page_state, compare_page_states

EXAMPLES

tools/call preview_dom_mutation { "operation": "remove_element", "target": { "selector": ".promo-overlay" } }
tools/call mutate_dom { "operation": "set_attribute", "target": { "selector": "button#checkout" }, "attribute": "disabled", "value": "true" }
tools/call mutate_dom { "operation": "add_class", "target": { "selector": "nav.main" }, "classes": ["collapsible"] }
tools/call mutate_dom_transaction { "mode": "begin" }
tools/call mutate_dom_transaction { "mode": "rollback", "reason": "layout broke at step 2" }
tools/call undo_dom_mutation {}
tools/call get_mutation_history { "limit": 20 }

FAILURE MODES

  • DOM_MUTATION_FAILED — structured failure with diagnostics (bad target, invalid HTML, forbidden operation); the engine never throws raw. Fix the inputs and retry; the undo stack stays intact.
  • Target unresolved mid-transaction — a step re-rendered the DOM; rollback the transaction rather than half-applying.
  • Undo "nothing to undo" — the stack is empty (fresh session, or history was for a different document — engines are keyed per document).
  • Redo refused — the forward patch is unsafe (page changed since the undo); re-apply via mutate_dom instead of forcing redo.
  • Mutations vanish — the app re-rendered and clobbered your change; that is app/framework behavior, use wait_for_dom_stable and re-apply, or accept it as evidence of dynamic re-rendering.

VALIDATION

  • Every result must show all four contract phases (BEFORE/ACTION/AFTER/DIFF); a missing DIFF means you got a preview-style response, not a mutation.
  • get_mutation_history undo depth increments on success; transaction entries reference the open transaction id.
  • After a rollback, compare_page_states on snapshots taken before begin should report identical states.

RECOVERY

  • Bad change: undo_dom_mutation (repeat per step) or transaction rollback; verify with capture_page_state + compare_page_states.
  • Deep mess: undo_dom_mutation until "nothing to undo", then reload_tab {bypassCache: true} for a ground-truth reset.
  • Never ship mutations as fixes — they are experiments; port validated changes into the app's source.

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.