refactor-for-determinism
npx machina-cli add skill kasperjunge/agent-resources/refactor-for-determinism --openclawRefactor for Determinism
Build reliable skills by separating deterministic steps from judgment-based steps.
Core Principle
Deterministic steps belong in scripts. Use SKILL.md to orchestrate the workflow and reserve judgment for the non-deterministic parts.
Workflow
1. Identify Deterministic vs Non-Deterministic Work
For each step in the skill:
- Deterministic: repeatable, mechanical, or validation-heavy steps → script candidates
- Non-deterministic: judgment, interpretation, creative choices → keep in SKILL.md
Examples of deterministic steps:
- Running quality checks
- Verifying clean git state
- Updating version strings
- Promoting CHANGELOG sections
- Collecting diff context for review
Examples of non-deterministic steps:
- Writing changelog content
- Selecting a solution approach
- Code review judgments
- Deciding release timing
2. Design Scripts for Deterministic Steps
For each deterministic step:
- Create a script in
scripts/within the skill directory - Make it self-contained with clear error messages
- Validate inputs and exit non-zero on failure
- Prefer small, single-purpose scripts
3. Update SKILL.md to Use Scripts
- Replace manual command lists with script calls
- Reference scripts using relative paths:
scripts/... - Keep judgment steps explicit in prose
4. Document Boundaries
Make the line between scripted and non-scripted steps obvious:
- Use section headers like "Deterministic Steps" and "Judgment Steps"
- Call out where human/agent judgment is required
Output Format
## Determinism Audit
### Deterministic Steps (script candidates)
- [Step] → [script name]
### Non-Deterministic Steps (keep in SKILL.md)
- [Step] → [why it needs judgment]
### Script Plan
- scripts/[name] - [purpose, inputs, outputs]
### SKILL.md Updates
- [Where to call each script]
Common Mistakes
| Mistake | Fix |
|---|---|
| Scripting judgment | Keep decision-making in SKILL.md |
| One giant script | Split into small, focused scripts |
| Silent failures | Print clear errors and exit non-zero |
| Hardcoded paths | Use repo-relative paths |
| Forgetting SKILL.md updates | Always wire scripts into instructions |
What NOT to Do
- Do NOT hide decisions inside scripts
- Do NOT make scripts that require manual editing
- Do NOT mix multiple responsibilities into one script
- Do NOT add extra documentation files beyond SKILL.md
Source
git clone https://github.com/kasperjunge/agent-resources/blob/main/skills/skill-development/refactor-for-determinism/SKILL.mdView on GitHub Overview
Refactor for determinism helps design or refactor skills by clearly separating deterministic, repeatable steps from non-deterministic judgment. It advocates moving repeatable workflows into scripts/ and uses SKILL.md to orchestrate the workflow and document where human judgment is required.
How This Skill Works
Identify which steps are deterministic (repeatable, mechanical, or validation-heavy) and which require judgment. Create small, self-contained scripts under scripts/ for the deterministic steps, with clear error messages and input validation that exit non-zero on failure. Update SKILL.md to call these scripts using repo-relative paths (e.g., scripts/...), while keeping judgment-heavy decisions in prose to maintain clarity.
When to Use It
- Starting a new skill that includes repeatable checks, builds, or validations.
- Refactoring an existing skill to isolate deterministic steps into scripts for reliability.
- Preparing a release where version bumps, changelog handling, and diff collection are automated.
- Auditing a skill to clarify where scripted steps end and human judgment begins.
- Standardizing cross-skill workflows by centralizing deterministic tasks into reusable scripts.
Quick Start
- Step 1: Identify deterministic vs non-deterministic steps in your skill's workflow.
- Step 2: Create small, self-contained scripts under scripts/ for deterministic steps and wire them into the workflow.
- Step 3: Update SKILL.md to call the scripts with repo-relative paths and keep judgment steps in prose.
Best Practices
- Clearly label steps as Deterministic (scripted) or Non-Deterministic (judgment).
- Place small, single-purpose scripts under scripts/ and guard each with clear error messages.
- Validate inputs in scripts and exit non-zero on failure to prevent silent errors.
- Reference scripts in SKILL.md using relative paths like scripts/...
- Keep judgment steps in prose and avoid hiding decisions in scripts.
Example Use Cases
- An automated skill validates git state, runs tests, updates version strings, and captures diff context via scripts.
- A CHANGELOG promotion step is scripted while the rationale for entries remains described in SKILL.md.
- A deterministic packaging or release-prep task is automated with a small script, producing consistent outputs.
- Diff-context collection for code reviews is automated by a script rather than written manually.
- Scripts verify inputs and environment constraints to ensure consistent behavior across runs.