$npx -y skills add bluzir/claude-code-design --skill apply-tweaksApply buffered tweaks from pending.yaml to the source HTML file. Invoked when user says "save tweaks", "apply tweaks", "persist panel changes", or runs /apply-tweaks.
| 1 | # Apply Tweaks |
| 2 | |
| 3 | Persist queued tweak changes (in `pending.yaml`) back to the source HTML via `Edit`. Pattern from claude-pipe: **files are state, Claude is the writer**. |
| 4 | |
| 5 | ## Session lookup |
| 6 | |
| 7 | `session-id` for `<html-path>` = `tweaks-{slugify(basename html-path without ext)}-{today YYYYMMDD}`. |
| 8 | Session dir: `artifacts/tweaks/<session-id>/`. |
| 9 | |
| 10 | If skipping date match (e.g. resume from yesterday), `Bash(ls artifacts/tweaks/)` and find the most recent matching prefix. |
| 11 | |
| 12 | ## Pipeline |
| 13 | |
| 14 | 1. **Read session state:** |
| 15 | ``` |
| 16 | Read artifacts/tweaks/<session-id>/state.yaml |
| 17 | Read artifacts/tweaks/<session-id>/pending.yaml |
| 18 | ``` |
| 19 | If `pending.yaml` is missing or empty — report "no pending tweaks" and stop. |
| 20 | |
| 21 | 2. **Read HTML + schema:** |
| 22 | - `Read` the target HTML (path from state.yaml or `$0`) |
| 23 | - Extract the `__tweak_schema` block (JSON inside `<script id="__tweak_schema">`) |
| 24 | |
| 25 | 3. **Validate each pending key:** |
| 26 | - Every key in `pending.yaml` must exist in schema |
| 27 | - Value type must match schema (color = hex, number = in [min..max], boolean) |
| 28 | - If any key invalid: report which + stop (do not partially apply) |
| 29 | |
| 30 | 4. **Apply:** for each key → value in pending: |
| 31 | - **Primary pattern — CSS var on `:root`:** find `--tweak-<key>: <old>;` and `Edit` to new value |
| 32 | - **Secondary pattern — marker block:** find `<!-- tweak:<key> -->...<!-- /tweak:<key> -->` and `Edit` the content inside |
| 33 | - If neither marker found → fail loudly (HTML didn't use `/make-tweakable` pattern) |
| 34 | |
| 35 | 5. **Atomic write via Edit:** each `Edit` is already atomic in Claude Code, so no tmp-rename dance needed. |
| 36 | |
| 37 | 6. **Append to log:** |
| 38 | ``` |
| 39 | ts=$(date -u +%Y%m%dT%H%M%SZ) |
| 40 | Write artifacts/tweaks/<session-id>/applied/$ts.yaml: |
| 41 | applied_at: $ts |
| 42 | changes: |
| 43 | <copy of pending.yaml> |
| 44 | ``` |
| 45 | |
| 46 | 7. **Clear pending:** `Write artifacts/tweaks/<session-id>/pending.yaml` with empty content (or `{}`) |
| 47 | |
| 48 | 8. **Update state:** |
| 49 | ``` |
| 50 | Edit artifacts/tweaks/<session-id>/state.yaml: |
| 51 | phase: idle → idle (no-op but bump timestamp) |
| 52 | last_applied_at: <ts> |
| 53 | ``` |
| 54 | |
| 55 | 9. **Verify:** `/done <html-path>` — confirms file still renders, new values visible in preview. |
| 56 | |
| 57 | 10. **Report:** "Applied N tweaks. Logged to `artifacts/tweaks/<session-id>/applied/<ts>.yaml`. Pending cleared." |
| 58 | |
| 59 | ## Revert path |
| 60 | |
| 61 | If user says "revert last tweaks": |
| 62 | 1. `Bash(ls -t artifacts/tweaks/<session-id>/applied/)` — get most recent |
| 63 | 2. `Read` that file — get the delta |
| 64 | 3. Reverse each change (find current value in HTML, restore previous) |
| 65 | 4. Append a new applied entry with `type: revert` and reference to reverted file |
| 66 | 5. `/done` |