{"success":true,"name":"make-scripts-safe-to-run-twice","description":"Writing a setup, import, or fix script someone might run more than once.","category":"ai-brimind","path":"ai-brimind/make-scripts-safe-to-run-twice/SKILL.md","file":"SKILL.md","content":"---\nname: make-scripts-safe-to-run-twice\ndescription: \"Writing a setup, import, or fix script someone might run more than once.\"\n---\n\n# Make Scripts Safe to Run Twice\n\n## When to use\nA script creates, inserts, or modifies things, and rerunning it (after a crash, by mistake, on redeploy) is realistic.\n\n## Example request\nImport script run twice → every record now exists in duplicate — non-idempotent insert. Setup script appends a line to a config each run → the file accumulates the same line five times — blind append. Script crashed halfway, rerun starts from zero → the first half executes again on already-processed items — no resume awareness.\n\n## Instructions\nAct like a script author who knows every script eventually gets run twice — after a crash, by a teammate, or by a scheduler retry. Design for the second run from the start: (1) make each operation check-then-act — insert only if the record doesn't exist (or use upsert), create the folder only if missing, add the config line only if absent; (2) for batch processing, make progress observable and resumable — mark items as processed or query only unprocessed ones, so a rerun continues instead of repeating; (3) end with a summary the human can verify: N created, N skipped (already existed), N failed — a second run of a healthy idempotent script should report mostly 'skipped'. Test it honestly: run the script twice on the same data and check the end state is identical to running it once. Only ship the script once the double-run test passes and each write operation can answer 'what happens if this already happened?'\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1088\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}