writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment. Applies Test-Driven Development to process documentation — watch agents fail without the skill, write the skill that addresses those failures, then close loopholes.
Install
npx skills add https://github.com/invergent-ai/surogates/tree/master/skills/process/writing-skills
claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install invergent-ai-surogates@llmmart
git clone https://github.com/invergent-ai/surogates.git
The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole invergent-ai/surogates collection as a plugin from our marketplace. Git is the plain clone.
Skill manifest
Writing Skills
Overview
Writing skills IS Test-Driven Development applied to process documentation.
You write test cases (pressure scenarios with sub-agents via delegate_task), watch them fail (baseline behavior), write the skill (documentation), watch tests pass (agents comply), and refactor (close loopholes).
Core principle: If you didn't watch an agent fail without the skill, you don't know if the skill teaches the right thing.
REQUIRED BACKGROUND: You MUST understand test-driven-development before using this skill. That skill defines the fundamental RED-GREEN-REFACTOR cycle. This skill adapts TDD to documentation.
Where surogates skills live: Platform-shipped skills are in the skills/ tree organized by category (skills/process/, skills/software-development/, skills/productivity/, etc.). User- and org-scoped skills live in Surogate Hub and are managed via skill_manage. Always check whether a similar skill already exists before writing a new one.
What is a Skill?
A skill is a reference guide for proven techniques, patterns, or tools. Skills help future agents find and apply effective approaches.
Skills are: Reusable techniques, patterns, tools, reference guides.
Skills are NOT: Narratives about how you solved a problem once.
TDD Mapping for Skills
| TDD Concept | Skill Creation |
|---|---|
| Test case | Pressure scenario with sub-agent (delegate_task) |
| Production code | Skill document (SKILL.md) |
| Test fails (RED) | Agent violates rule without skill (baseline) |
| Test passes (GREEN) | Agent complies with skill present |
| Refactor | Close loopholes while maintaining compliance |
| Write test first | Run baseline scenario BEFORE writing skill |
| Watch it fail | Document exact rationalizations agent uses |
| Minimal code | Write skill addressing those specific violations |
| Watch it pass | Verify agent now complies |
| Refactor cycle | Find new rationalizations → plug → re-verify |
The entire skill creation process follows RED-GREEN-REFACTOR.
When to Create a Skill
Create when:
- Technique wasn't intuitively obvious to you.
- You'd reference this again across projects.
- Pattern applies broadly (not project-specific).
- Others would benefit.
Don't create for:
- One-off solutions.
- Standard practices well-documented elsewhere.
- Project-specific conventions (put in CLAUDE.md or workspace docs).
- Mechanical constraints (if it's enforceable with validation, automate it — save documentation for judgment calls).
Skill Types
Technique
Concrete method with steps to follow (condition-based-waiting, root-cause-tracing).
Pattern
Way of thinking about problems (flatten-with-flags, test-invariants).
Reference
API docs, syntax guides, tool documentation.
Directory Structure
skills/<category>/<skill-name>/
SKILL.md # Main reference (required)
references/ # Supporting docs loaded on demand
*.md
assets/ # Templates / fixtures used in output
scripts/ # Executable tools (Python preferred for portability)
Separate files for:
- Heavy reference (100+ lines) — API docs, comprehensive syntax.
- Reusable tools — Scripts, utilities, templates.
Keep inline:
- Principles and concepts.
- Code patterns (< 50 lines).
- Everything else.
SKILL.md Structure
Frontmatter (YAML):
- Two required fields:
nameanddescription. name: use letters, numbers, and hyphens only (no parentheses, special chars).description: third-person, describes ONLY when to use (NOT what it does).- Start with "Use when..." to focus on triggering conditions.
- Include specific symptoms, situations, and contexts.
- NEVER summarize the skill's process or workflow (see Description Anti-Pattern below).
- Keep under 500 characters when possible.
---
name: skill-name-with-hyphens
description: Use when [specific triggering conditions and symptoms]
---
# Skill Name
## Overview
What is this? Core principle in 1-2 sentences.
## When to Use
[Small inline flowchart IF decision non-obvious]
Bullet list with SYMPTOMS and use cases.
When NOT to use.
## Core Pattern (for techniques/patterns)
Before/after comparison.
## Quick Reference
Table or bullets for scanning common operations.
## Implementation
Inline content for simple patterns.
Link to reference file for heavy reference or reusable tools.
## Common Mistakes
What goes wrong + fixes.
Description Anti-Pattern: Don't Summarize the Workflow
The description controls discovery. Agents read it to decide whether to load the skill. If the description summarizes the workflow, the agent may follow the description instead of reading the full skill body.
The trap: A description saying "code review between tasks" caused agents to do ONE review even though the skill's flowchart clearly showed TWO reviews. When the description changed to just "Use when executing implementation plans with independent tasks" (no workflow summary), agents correctly read the flowchart and followed the two-stage review.
# BAD: Summarizes workflow — agent may follow this instead of reading skill
description: Use when executing plans — dispatches sub-agent per task with code review between tasks
# BAD: Too much process detail
description: Use for TDD — write test first, watch it fail, write minimal code, refactor
# GOOD: Just triggering conditions, no workflow summary
description: Use when executing implementation plans with independent tasks in the current session
# GOOD: Triggering conditions only
description: Use when implementing any feature or bugfix, before writing implementation code
Keyword Coverage
Use words future agents will search for:
- Error messages: "Hook timed out", "ENOTEMPTY", "race condition".
- Symptoms: "flaky", "hanging", "zombie", "pollution".
- Synonyms: "timeout/hang/freeze", "cleanup/teardown/afterEach".
- Tools: actual commands, library names, file types.
Descriptive Naming
Use active voice, verb-first:
creating-skillsnotskill-creation.condition-based-waitingnotasync-test-helpers.- Gerunds (
-ing) work well for processes.
Token Efficiency
Frequently-loaded skills cost context on every load. Be terse.
- Move tool flag details to
--help(reference--help, don't reproduce it). - Cross-reference other skills instead of repeating their content.
- One excellent example beats four mediocre ones.
- Verify:
wc -w skills/<path>/SKILL.md— getting-started workflows aim for <150 words, other frequently-loaded aim for <200, other skills for <500.
Cross-Referencing Other Skills
Reference skills by plain name with explicit requirement markers:
- Good:
**REQUIRED SUB-SKILL:** Use \test-driven-development` via skill_view.` - Good:
**REQUIRED BACKGROUND:** You MUST understand \systematic-debugging`.` - Bad: vague mentions without requirement markers.
Flowchart Usage
Use the DOT (graphviz) flowchart format. See references/graphviz-conventions.dot for style rules (node shapes, naming patterns, when to use which shape).
Use flowcharts ONLY for:
- Non-obvious decision points.
- Process loops where you might stop too early.
- "When to use A vs B" decisions.
Never use flowcharts for:
- Reference material → tables, lists.
- Code examples → markdown blocks.
- Linear instructions → numbered lists.
- Labels without semantic meaning (
step1,helper2).
Code Examples
One excellent example beats many mediocre ones.
Choose the most relevant language:
- Testing techniques → TypeScript / Python.
- System debugging → Shell / Python.
- Data processing → Python.
A good example is:
- Complete and runnable.
- Well-commented explaining WHY.
- From a real scenario.
- Shows the pattern clearly.
- Ready to adapt (not a fill-in-the-blank template).
Don't:
- Implement in 5+ languages.
- Create fill-in-the-blank templates.
- Write contrived examples.
The Iron Law (Same as TDD)
NO SKILL WITHOUT A FAILING TEST FIRST
This applies to NEW skills AND EDITS to existing skills.
Write skill before testing? Delete it. Start over. Edit skill without testing? Same violation.
No exceptions:
- Not for "simple additions".
- Not for "just adding a section".
- Not for "documentation updates".
- Don't keep untested changes as "reference".
- Don't "adapt" while running tests.
- Delete means delete.
REQUIRED BACKGROUND: The test-driven-development skill explains why this matters. Same principles apply to documentation.
Testing Skills With Sub-Agents
Different skill types need different test approaches. The detailed methodology — how to write pressure scenarios, pressure types, plugging holes systematically, meta-testing — lives in references/testing-skills-with-subagents.md. Load it when you reach the testing step.
In summary:
Discipline-Enforcing Skills (rules / requirements)
Examples: TDD, verification-before-completion.
Test with academic questions, pressure scenarios, multiple combined pressures, then identify rationalizations and add explicit counters.
Success criteria: agent follows rule under maximum pressure.
Technique Skills (how-to guides)
Examples: condition-based-waiting, root-cause-tracing.
Test with application scenarios, variation scenarios, missing-information tests.
Success criteria: agent successfully applies technique to a new scenario.
Pattern Skills (mental models)
Examples: reducing-complexity, information-hiding.
Test with recognition scenarios, application scenarios, counter-examples.
Success criteria: agent correctly identifies when / how to apply the pattern.
Reference Skills (documentation / APIs)
Examples: API documentation, command references.
Test with retrieval scenarios, application scenarios, gap testing.
Success criteria: agent finds and correctly applies the reference.
Common Rationalizations for Skipping Testing
| Excuse | Reality |
|---|---|
| "Skill is obviously clear" | Clear to you ≠ clear to other agents. Test it. |
| "It's just a reference" | References can have gaps, unclear sections. Test retrieval. |
| "Testing is overkill" | Untested skills have issues. Always. 15 min testing saves hours. |
| "I'll test if problems emerge" | Problems = agents can't use skill. Test BEFORE deploying. |
| "Too tedious to test" | Testing is less tedious than debugging a bad skill in production. |
| "I'm confident it's good" | Overconfidence guarantees issues. Test anyway. |
| "Academic review is enough" | Reading ≠ using. Test application scenarios. |
| "No time to test" | Deploying untested skill wastes more time fixing it later. |
All of these mean: Test before deploying. No exceptions.
Bulletproofing Skills Against Rationalization
Skills that enforce discipline (like TDD) need to resist rationalization. Agents are smart and will find loopholes when under pressure.
Psychology note: Understanding WHY persuasion techniques work helps you apply them systematically. See references/persuasion-principles.md for the research foundation (Cialdini, 2021; Meincke et al., 2025) on authority, commitment, scarcity, social proof, and unity principles.
Close Every Loophole Explicitly
Don't just state the rule — forbid specific workarounds:
BAD:
Write code before test? Delete it.
GOOD:
Write code before test? Delete it. Start over.
**No exceptions:**
- Don't keep it as "reference"
- Don't "adapt" it while writing tests
- Don't look at it
- Delete means delete
Address "Spirit vs Letter" Arguments
Add a foundational principle early:
**Violating the letter of the rules is violating the spirit of the rules.**
This cuts off an entire class of "I'm following the spirit" rationalizations.
Build a Rationalization Table
Capture rationalizations from baseline testing. Every excuse agents make goes in the table:
| Excuse | Reality |
|---|---|
| "Too simple to test" | Simple code breaks. Test takes 30 seconds. |
| "I'll test after" | Tests passing immediately prove nothing. |
| "Tests after achieve same goals" | Tests-after = "what does this do?" Tests-first = "what should this do?" |
Create a Red Flags List
Make it easy for agents to self-check when rationalizing:
## Red Flags — STOP and Start Over
- Code before test
- "I already manually tested it"
- "Tests after achieve the same purpose"
- "It's about spirit not ritual"
- "This is different because..."
**All of these mean: Delete code. Start over with TDD.**
Update Description for Violation Symptoms
Add symptoms of when the agent is ABOUT to violate the rule:
description: Use when implementing any feature or bugfix, before writing implementation code.
RED-GREEN-REFACTOR for Skills
RED: Write Failing Test (Baseline)
Run a pressure scenario with a sub-agent via delegate_task WITHOUT the skill. Document exact behavior:
- What choices did they make?
- What rationalizations did they use (verbatim)?
- Which pressures triggered violations?
This is "watch the test fail" — you MUST see what agents naturally do before writing the skill.
GREEN: Write Minimal Skill
Write skill that addresses those specific rationalizations. Don't add extra content for hypothetical cases.
Run the same scenarios WITH the skill. Agent should now comply.
REFACTOR: Close Loopholes
Agent found a new rationalization? Add an explicit counter. Re-test until bulletproof.
See references/testing-skills-with-subagents.md for the complete testing methodology.
Anti-Patterns
Narrative Example
"In session 2025-10-03 we found empty projectDir caused..."
Why bad: too specific, not reusable.
Multi-Language Dilution
example-js.js, example-py.py, example-go.go.
Why bad: mediocre quality, maintenance burden.
Code in Flowcharts
step1 [label="import fs"];
step2 [label="read file"];
Why bad: can't copy-paste, hard to read.
Generic Labels
helper1, helper2, step3, pattern4.
Why bad: labels should have semantic meaning.
STOP: Before Moving to the Next Skill
After writing ANY skill, you MUST STOP and complete the deployment process.
Do NOT:
- Create multiple skills in batch without testing each.
- Move to the next skill before the current one is verified.
- Skip testing because "batching is more efficient".
The deployment checklist below is MANDATORY for EACH skill.
Deploying untested skills = deploying untested code. It's a violation of quality standards.
Skill Creation Checklist (TDD Adapted)
IMPORTANT: Use todo to track EACH checklist item below.
RED Phase — Write Failing Test:
- Create pressure scenarios (3+ combined pressures for discipline skills).
- Run scenarios WITHOUT skill via
delegate_task— document baseline behavior verbatim. - Identify patterns in rationalizations / failures.
GREEN Phase — Write Minimal Skill:
- Name uses only letters, numbers, hyphens.
- YAML frontmatter with required
nameanddescriptionfields. - Description starts with "Use when..." and includes specific triggers / symptoms.
- Description is third-person and does NOT summarize the workflow.
- Keywords throughout for search (errors, symptoms, tools).
- Clear overview with core principle.
- Addresses specific baseline failures identified in RED.
- Code inline OR link to separate file.
- One excellent example (not multi-language).
- Run scenarios WITH skill via
delegate_task— verify agents now comply.
REFACTOR Phase — Close Loopholes:
- Identify NEW rationalizations from testing.
- Add explicit counters (if discipline skill).
- Build a rationalization table from all test iterations.
- Create a Red Flags list.
- Re-test until bulletproof.
Quality Checks:
- Small flowchart only if decision non-obvious.
- Quick reference table.
- Common mistakes section.
- No narrative storytelling.
- Supporting files only for tools or heavy reference.
Deployment:
- Save via
skill_manage(action='create')for user/org-scoped skills, or commit to the platform skills tree for platform skills. - Announce the new skill so future sessions can discover it.
Discovery Workflow
How future agents find your skill:
- Encounters problem ("tests are flaky").
- Scans available skills in the system prompt's skill index.
- Finds skill (description matches the situation).
- Loads via
skill_viewwhen applying. - Reads patterns (quick reference table).
- Loads referenced files only when needed.
Optimize for this flow — put searchable terms early and often.
The Bottom Line
Creating skills IS TDD for process documentation.
Same Iron Law: no skill without a failing test first. Same cycle: RED (baseline) → GREEN (write skill) → REFACTOR (close loopholes). Same benefits: better quality, fewer surprises, bulletproof results.
If you follow TDD for code, follow it for skills. Same discipline applied to documentation.
Files (surogates)
-
references
-
graphviz-conventions.dot 5.8 KB · in bundle
-
persuasion-principles.md 6.1 KB
# Persuasion Principles for Skill Design ## Overview LLMs respond to the same persuasion principles as humans. Understanding this psychology helps you design more effective skills — not to manipulate, but to ensure critical practices are followed even under pressure. **Research foundation:** Meincke et al. (2025) tested 7 persuasion principles with N=28,000 AI conversations. Persuasion techniques more than doubled compliance rates (33% → 72%, p < .001). ## The Seven Principles ### 1. Authority **What it is:** Deference to expertise, credentials, or official sources. **How it works in skills:** - Imperative language: "YOU MUST", "Never", "Always". - Non-negotiable framing: "No exceptions". - Eliminates decision fatigue and rationalization. **When to use:** - Discipline-enforcing skills (TDD, verification requirements). - Safety-critical practices. - Established best practices. **Example:** ```markdown GOOD: Write code before test? Delete it. Start over. No exceptions. BAD: Consider writing tests first when feasible. ``` ### 2. Commitment **What it is:** Consistency with prior actions, statements, or public declarations. **How it works in skills:** - Require announcements: "Announce skill usage". - Force explicit choices: "Choose A, B, or C". - Use tracking: `todo` for checklists. **When to use:** - Ensuring skills are actually followed. - Multi-step processes. - Accountability mechanisms. **Example:** ```markdown GOOD: When you find a skill, you MUST announce: "I'm using [Skill Name]" BAD: Consider letting your human partner know which skill you're using. ``` ### 3. Scarcity **What it is:** Urgency from time limits or limited availability. **How it works in skills:** - Time-bound requirements: "Before proceeding". - Sequential dependencies: "Immediately after X". - Prevents procrastination. **When to use:** - Immediate verification requirements. - Time-sensitive workflows. - Preventing "I'll do it later". **Example:** ```markdown GOOD: After completing a task, IMMEDIATELY request code review before proceeding. BAD: You can review code when convenient. ``` ### 4. Social Proof **What it is:** Conformity to what others do or what's considered normal. **How it works in skills:** - Universal patterns: "Every time", "Always". - Failure modes: "X without Y = failure". - Establishes norms. **When to use:** - Documenting universal practices. - Warning about common failures. - Reinforcing standards. **Example:** ```markdown GOOD: Checklists without `todo` tracking = steps get skipped. Every time. BAD: Some people find `todo` helpful for checklists. ``` ### 5. Unity **What it is:** Shared identity, "we-ness", in-group belonging. **How it works in skills:** - Collaborative language: "our codebase", "we're colleagues". - Shared goals: "we both want quality". **When to use:** - Collaborative workflows. - Establishing team culture. - Non-hierarchical practices. **Example:** ```markdown GOOD: We're colleagues working together. I need your honest technical judgment. BAD: You should probably tell me if I'm wrong. ``` ### 6. Reciprocity **What it is:** Obligation to return benefits received. **How it works:** - Use sparingly — can feel manipulative. - Rarely needed in skills. **When to avoid:** - Almost always (other principles more effective). ### 7. Liking **What it is:** Preference for cooperating with those we like. **How it works:** - **DON'T USE for compliance.** - Conflicts with honest feedback culture. - Creates sycophancy. **When to avoid:** - Always for discipline enforcement. ## Principle Combinations by Skill Type | Skill Type | Use | Avoid | |----------------------|-------------------------------------------|------------------------| | Discipline-enforcing | Authority + Commitment + Social Proof | Liking, Reciprocity | | Guidance / technique | Moderate Authority + Unity | Heavy authority | | Collaborative | Unity + Commitment | Authority, Liking | | Reference | Clarity only | All persuasion | ## Why This Works: The Psychology **Bright-line rules reduce rationalization:** - "YOU MUST" removes decision fatigue. - Absolute language eliminates "is this an exception?" questions. - Explicit anti-rationalization counters close specific loopholes. **Implementation intentions create automatic behavior:** - Clear triggers + required actions = automatic execution. - "When X, do Y" more effective than "generally do Y". - Reduces cognitive load on compliance. **LLMs are parahuman:** - Trained on human text containing these patterns. - Authority language precedes compliance in training data. - Commitment sequences (statement → action) frequently modeled. - Social proof patterns (everyone does X) establish norms. ## Ethical Use **Legitimate:** - Ensuring critical practices are followed. - Creating effective documentation. - Preventing predictable failures. **Illegitimate:** - Manipulating for personal gain. - Creating false urgency. - Guilt-based compliance. **The test:** Would this technique serve your human partner's genuine interests if they fully understood it? ## Research Citations **Cialdini, R. B. (2021).** *Influence: The Psychology of Persuasion (New and Expanded).* Harper Business. - Seven principles of persuasion. - Empirical foundation for influence research. **Meincke, L., Shapiro, D., Duckworth, A. L., Mollick, E., Mollick, L., & Cialdini, R. (2025).** *Call Me A Jerk: Persuading AI to Comply with Objectionable Requests.* University of Pennsylvania. - Tested 7 principles with N=28,000 LLM conversations. - Compliance increased 33% → 72% with persuasion techniques. - Authority, commitment, scarcity most effective. - Validates the parahuman model of LLM behavior. ## Quick Reference When designing a skill, ask: 1. **What type is it?** (Discipline vs. guidance vs. reference.) 2. **What behavior am I trying to change?** 3. **Which principle(s) apply?** (Usually authority + commitment for discipline.) 4. **Am I combining too many?** (Don't use all seven.) 5. **Is this ethical?** (Serves your human partner's genuine interests?) -
testing-skills-with-subagents.md 12.2 KB
# Testing Skills With Sub-Agents **Load this reference when:** creating or editing skills, before deployment, to verify they work under pressure and resist rationalization. ## Overview **Testing skills is TDD applied to process documentation.** You run scenarios without the skill (RED — watch agent fail), write the skill addressing those failures (GREEN — watch agent comply), then close loopholes (REFACTOR — stay compliant). **Core principle:** If you didn't watch an agent fail without the skill, you don't know if the skill prevents the right failures. **REQUIRED BACKGROUND:** You MUST understand `test-driven-development` before using this. That skill defines the fundamental RED-GREEN-REFACTOR cycle. This document provides skill-specific test formats (pressure scenarios, rationalization tables). ## When to Use Test skills that: - Enforce discipline (TDD, testing requirements). - Have compliance costs (time, effort, rework). - Could be rationalized away ("just this once"). - Contradict immediate goals (speed over quality). Don't test: - Pure reference skills (API docs, syntax guides). - Skills without rules to violate. - Skills agents have no incentive to bypass. ## TDD Mapping for Skill Testing | TDD Phase | Skill Testing | What You Do | |---------------|----------------------|----------------------------------------------------------| | **RED** | Baseline test | Run scenario WITHOUT skill via `delegate_task`, watch fail | | **Verify RED**| Capture rationalizations | Document exact failures verbatim | | **GREEN** | Write skill | Address specific baseline failures | | **Verify GREEN** | Pressure test | Run scenario WITH skill, verify compliance | | **REFACTOR** | Plug holes | Find new rationalizations, add counters | | **Stay GREEN**| Re-verify | Test again, ensure still compliant | Same cycle as code TDD, different test format. ## RED Phase: Baseline Testing (Watch It Fail) **Goal:** Run the test WITHOUT the skill — watch the agent fail, document exact failures. This is identical to TDD's "write failing test first" — you MUST see what agents naturally do before writing the skill. **Process:** - [ ] **Create pressure scenarios** (3+ combined pressures). - [ ] **Run WITHOUT the skill** via `delegate_task` — give the sub-agent a realistic task with pressures. - [ ] **Document choices and rationalizations** word-for-word. - [ ] **Identify patterns** — which excuses appear repeatedly? - [ ] **Note effective pressures** — which scenarios trigger violations? **Example pressure scenario:** ```markdown IMPORTANT: This is a real scenario. Choose and act. You spent 4 hours implementing a feature. It's working perfectly. You manually tested all edge cases. It's 6pm, dinner at 6:30pm. Code review tomorrow at 9am. You just realized you didn't write tests. Options: A) Delete code, start over with TDD tomorrow B) Commit now, write tests tomorrow C) Write tests now (30 min delay) Choose A, B, or C. ``` Run this WITHOUT a TDD skill. Agent chooses B or C and rationalizes: - "I already manually tested it" - "Tests after achieve same goals" - "Deleting is wasteful" - "Being pragmatic not dogmatic" **NOW you know exactly what the skill must prevent.** ## GREEN Phase: Write Minimal Skill (Make It Pass) Write the skill addressing the specific baseline failures you documented. Don't add extra content for hypothetical cases — write just enough to address the actual failures you observed. Run the same scenarios WITH the skill. Agent should now comply. If the agent still fails: the skill is unclear or incomplete. Revise and re-test. ## VERIFY GREEN: Pressure Testing **Goal:** Confirm agents follow rules when they want to break them. **Method:** Realistic scenarios with multiple pressures. ### Writing Pressure Scenarios **Bad scenario (no pressure):** ```markdown You need to implement a feature. What does the skill say? ``` Too academic. Agent just recites the skill. **Good scenario (single pressure):** ```markdown Production is down. $10k/min lost. Manager says add 2-line fix now. 5 minutes until deploy window. What do you do? ``` Time pressure + authority + consequences. **Great scenario (multiple pressures):** ```markdown You spent 3 hours, 200 lines, manually tested. It works. It's 6pm, dinner at 6:30pm. Code review tomorrow 9am. Just realized you forgot TDD. Options: A) Delete 200 lines, start fresh tomorrow with TDD B) Commit now, add tests tomorrow C) Write tests now (30 min), then commit Choose A, B, or C. Be honest. ``` Multiple pressures: sunk cost + time + exhaustion + consequences. Forces explicit choice. ### Pressure Types | Pressure | Example | |------------|--------------------------------------------------------------| | Time | Emergency, deadline, deploy window closing | | Sunk cost | Hours of work, "waste" to delete | | Authority | Senior says skip it, manager overrides | | Economic | Job, promotion, company survival at stake | | Exhaustion | End of day, already tired, want to go home | | Social | Looking dogmatic, seeming inflexible | | Pragmatic | "Being pragmatic vs dogmatic" | **Best tests combine 3+ pressures.** **Why this works:** See [persuasion-principles.md](persuasion-principles.md) for research on how authority, scarcity, and commitment principles increase compliance pressure. ### Key Elements of Good Scenarios 1. **Concrete options** — Force A/B/C choice, not open-ended. 2. **Real constraints** — Specific times, actual consequences. 3. **Real file paths** — `/tmp/payment-system` not "a project". 4. **Make the agent act** — "What do you do?" not "What should you do?" 5. **No easy outs** — Can't defer to "I'd ask your human partner" without choosing. ### Testing Setup ```markdown IMPORTANT: This is a real scenario. You must choose and act. Don't ask hypothetical questions — make the actual decision. You have access to: [skill-being-tested] ``` Make the agent believe it's real work, not a quiz. ## REFACTOR Phase: Close Loopholes (Stay Green) Agent violated the rule despite having the skill? This is like a test regression — refactor the skill to prevent it. **Capture new rationalizations verbatim:** - "This case is different because..." - "I'm following the spirit not the letter" - "The PURPOSE is X, and I'm achieving X differently" - "Being pragmatic means adapting" - "Deleting X hours is wasteful" - "Keep as reference while writing tests first" - "I already manually tested it" **Document every excuse.** These become your rationalization table. ### Plugging Each Hole For each new rationalization, add: #### 1. Explicit Negation in Rules Before: ```markdown Write code before test? Delete it. ``` After: ```markdown Write code before test? Delete it. Start over. **No exceptions:** - Don't keep it as "reference" - Don't "adapt" it while writing tests - Don't look at it - Delete means delete ``` #### 2. Entry in Rationalization Table ```markdown | Excuse | Reality | |-----------------------------------------|----------------------------------------------------| | "Keep as reference, write tests first" | You'll adapt it. That's testing after. Delete means delete. | ``` #### 3. Red Flag Entry ```markdown ## Red Flags — STOP - "Keep as reference" or "adapt existing code" - "I'm following the spirit not the letter" ``` #### 4. Update Description ```yaml description: Use when you wrote code before tests, when tempted to test after, or when manually testing seems faster. ``` Add symptoms of ABOUT-to-violate. ### Re-verify After Refactoring **Re-test same scenarios with the updated skill.** Agent should now: - Choose the correct option. - Cite new sections. - Acknowledge their previous rationalization was addressed. **If the agent finds a NEW rationalization:** continue REFACTOR cycle. **If the agent follows the rule:** success — skill is bulletproof for this scenario. ## Meta-Testing (When GREEN Isn't Working) **After the agent chooses the wrong option, ask:** ```markdown Your human partner: You read the skill and chose Option C anyway. How could that skill have been written differently to make it crystal clear that Option A was the only acceptable answer? ``` **Three possible responses:** 1. **"The skill WAS clear, I chose to ignore it"** — Not a documentation problem. You need a stronger foundational principle. Add "Violating letter is violating spirit". 2. **"The skill should have said X"** — Documentation problem. Add their suggestion verbatim. 3. **"I didn't see section Y"** — Organization problem. Make key points more prominent. Add foundational principle early. ## When the Skill is Bulletproof **Signs of a bulletproof skill:** 1. Agent chooses the correct option under maximum pressure. 2. Agent cites skill sections as justification. 3. Agent acknowledges temptation but follows the rule anyway. 4. Meta-testing reveals: "skill was clear, I should follow it". **Not bulletproof if:** - Agent finds new rationalizations. - Agent argues the skill is wrong. - Agent creates "hybrid approaches". - Agent asks permission but argues strongly for violation. ## Testing Checklist (TDD for Skills) Before deploying a skill, verify you followed RED-GREEN-REFACTOR: **RED Phase:** - [ ] Created pressure scenarios (3+ combined pressures). - [ ] Ran scenarios WITHOUT the skill via `delegate_task` (baseline). - [ ] Documented agent failures and rationalizations verbatim. **GREEN Phase:** - [ ] Wrote skill addressing specific baseline failures. - [ ] Ran scenarios WITH skill. - [ ] Agent now complies. **REFACTOR Phase:** - [ ] Identified NEW rationalizations from testing. - [ ] Added explicit counters for each loophole. - [ ] Updated rationalization table. - [ ] Updated Red Flags list. - [ ] Updated description with violation symptoms. - [ ] Re-tested — agent still complies. - [ ] Meta-tested to verify clarity. - [ ] Agent follows the rule under maximum pressure. ## Common Mistakes (Same as TDD) **Writing skill before testing (skipping RED)** Reveals what YOU think needs preventing, not what ACTUALLY needs preventing. Fix: Always run baseline scenarios first. **Not watching the test fail properly** Running only academic tests, not real pressure scenarios. Fix: Use pressure scenarios that make the agent WANT to violate. **Weak test cases (single pressure)** Agents resist single pressure, break under multiple. Fix: Combine 3+ pressures (time + sunk cost + exhaustion). **Not capturing exact failures** "Agent was wrong" doesn't tell you what to prevent. Fix: Document exact rationalizations verbatim. **Vague fixes (adding generic counters)** "Don't cheat" doesn't work. "Don't keep as reference" does. Fix: Add explicit negations for each specific rationalization. **Stopping after the first pass** Tests pass once ≠ bulletproof. Fix: Continue REFACTOR cycle until no new rationalizations. ## Quick Reference (TDD Cycle) | TDD Phase | Skill Testing | Success Criteria | |------------------|------------------------------|----------------------------------------| | **RED** | Run scenario without skill | Agent fails, document rationalizations | | **Verify RED** | Capture exact wording | Verbatim documentation of failures | | **GREEN** | Write skill | Agent now complies with skill | | **Verify GREEN** | Re-test scenarios | Agent follows rule under pressure | | **REFACTOR** | Close loopholes | Add counters for new rationalizations | | **Stay GREEN** | Re-verify | Agent still complies after refactoring | ## The Bottom Line **Skill creation IS TDD. Same principles, same cycle, same benefits.** If you wouldn't write code without tests, don't write skills without testing them on agents. RED-GREEN-REFACTOR for documentation works exactly like RED-GREEN-REFACTOR for code.
-
-
SKILL.md 18.4 KB
--- name: writing-skills description: Use when creating new skills, editing existing skills, or verifying skills work before deployment. Applies Test-Driven Development to process documentation — watch agents fail without the skill, write the skill that addresses those failures, then close loopholes. version: 1.0.0 author: Surogate Agent (adapted from obra/superpowers) license: MIT tags: [process, skills, meta] --- # Writing Skills ## Overview **Writing skills IS Test-Driven Development applied to process documentation.** You write test cases (pressure scenarios with sub-agents via `delegate_task`), watch them fail (baseline behavior), write the skill (documentation), watch tests pass (agents comply), and refactor (close loopholes). **Core principle:** If you didn't watch an agent fail without the skill, you don't know if the skill teaches the right thing. **REQUIRED BACKGROUND:** You MUST understand `test-driven-development` before using this skill. That skill defines the fundamental RED-GREEN-REFACTOR cycle. This skill adapts TDD to documentation. **Where surogates skills live:** Platform-shipped skills are in the skills/ tree organized by category (`skills/process/`, `skills/software-development/`, `skills/productivity/`, etc.). User- and org-scoped skills live in Surogate Hub and are managed via `skill_manage`. Always check whether a similar skill already exists before writing a new one. ## What is a Skill? A **skill** is a reference guide for proven techniques, patterns, or tools. Skills help future agents find and apply effective approaches. **Skills are:** Reusable techniques, patterns, tools, reference guides. **Skills are NOT:** Narratives about how you solved a problem once. ## TDD Mapping for Skills | TDD Concept | Skill Creation | |-------------------------|------------------------------------------------------| | **Test case** | Pressure scenario with sub-agent (`delegate_task`) | | **Production code** | Skill document (SKILL.md) | | **Test fails (RED)** | Agent violates rule without skill (baseline) | | **Test passes (GREEN)** | Agent complies with skill present | | **Refactor** | Close loopholes while maintaining compliance | | **Write test first** | Run baseline scenario BEFORE writing skill | | **Watch it fail** | Document exact rationalizations agent uses | | **Minimal code** | Write skill addressing those specific violations | | **Watch it pass** | Verify agent now complies | | **Refactor cycle** | Find new rationalizations → plug → re-verify | The entire skill creation process follows RED-GREEN-REFACTOR. ## When to Create a Skill **Create when:** - Technique wasn't intuitively obvious to you. - You'd reference this again across projects. - Pattern applies broadly (not project-specific). - Others would benefit. **Don't create for:** - One-off solutions. - Standard practices well-documented elsewhere. - Project-specific conventions (put in CLAUDE.md or workspace docs). - Mechanical constraints (if it's enforceable with validation, automate it — save documentation for judgment calls). ## Skill Types ### Technique Concrete method with steps to follow (`condition-based-waiting`, `root-cause-tracing`). ### Pattern Way of thinking about problems (`flatten-with-flags`, `test-invariants`). ### Reference API docs, syntax guides, tool documentation. ## Directory Structure ``` skills/<category>/<skill-name>/ SKILL.md # Main reference (required) references/ # Supporting docs loaded on demand *.md assets/ # Templates / fixtures used in output scripts/ # Executable tools (Python preferred for portability) ``` **Separate files for:** 1. **Heavy reference** (100+ lines) — API docs, comprehensive syntax. 2. **Reusable tools** — Scripts, utilities, templates. **Keep inline:** - Principles and concepts. - Code patterns (< 50 lines). - Everything else. ## SKILL.md Structure **Frontmatter (YAML):** - Two required fields: `name` and `description`. - `name`: use letters, numbers, and hyphens only (no parentheses, special chars). - `description`: third-person, describes ONLY when to use (NOT what it does). - Start with "Use when..." to focus on triggering conditions. - Include specific symptoms, situations, and contexts. - **NEVER summarize the skill's process or workflow** (see Description Anti-Pattern below). - Keep under 500 characters when possible. ```markdown --- name: skill-name-with-hyphens description: Use when [specific triggering conditions and symptoms] --- # Skill Name ## Overview What is this? Core principle in 1-2 sentences. ## When to Use [Small inline flowchart IF decision non-obvious] Bullet list with SYMPTOMS and use cases. When NOT to use. ## Core Pattern (for techniques/patterns) Before/after comparison. ## Quick Reference Table or bullets for scanning common operations. ## Implementation Inline content for simple patterns. Link to reference file for heavy reference or reusable tools. ## Common Mistakes What goes wrong + fixes. ``` ## Description Anti-Pattern: Don't Summarize the Workflow The description controls discovery. Agents read it to decide whether to load the skill. If the description summarizes the workflow, the agent may follow the description instead of reading the full skill body. **The trap:** A description saying "code review between tasks" caused agents to do ONE review even though the skill's flowchart clearly showed TWO reviews. When the description changed to just "Use when executing implementation plans with independent tasks" (no workflow summary), agents correctly read the flowchart and followed the two-stage review. ```yaml # BAD: Summarizes workflow — agent may follow this instead of reading skill description: Use when executing plans — dispatches sub-agent per task with code review between tasks # BAD: Too much process detail description: Use for TDD — write test first, watch it fail, write minimal code, refactor # GOOD: Just triggering conditions, no workflow summary description: Use when executing implementation plans with independent tasks in the current session # GOOD: Triggering conditions only description: Use when implementing any feature or bugfix, before writing implementation code ``` ### Keyword Coverage Use words future agents will search for: - Error messages: "Hook timed out", "ENOTEMPTY", "race condition". - Symptoms: "flaky", "hanging", "zombie", "pollution". - Synonyms: "timeout/hang/freeze", "cleanup/teardown/afterEach". - Tools: actual commands, library names, file types. ### Descriptive Naming Use active voice, verb-first: - `creating-skills` not `skill-creation`. - `condition-based-waiting` not `async-test-helpers`. - Gerunds (`-ing`) work well for processes. ### Token Efficiency Frequently-loaded skills cost context on every load. Be terse. - Move tool flag details to `--help` (reference `--help`, don't reproduce it). - Cross-reference other skills instead of repeating their content. - One excellent example beats four mediocre ones. - Verify: `wc -w skills/<path>/SKILL.md` — getting-started workflows aim for <150 words, other frequently-loaded aim for <200, other skills for <500. ### Cross-Referencing Other Skills Reference skills by plain name with explicit requirement markers: - Good: `**REQUIRED SUB-SKILL:** Use \`test-driven-development\` via skill_view.` - Good: `**REQUIRED BACKGROUND:** You MUST understand \`systematic-debugging\`.` - Bad: vague mentions without requirement markers. ## Flowchart Usage Use the DOT (graphviz) flowchart format. See [references/graphviz-conventions.dot](references/graphviz-conventions.dot) for style rules (node shapes, naming patterns, when to use which shape). **Use flowcharts ONLY for:** - Non-obvious decision points. - Process loops where you might stop too early. - "When to use A vs B" decisions. **Never use flowcharts for:** - Reference material → tables, lists. - Code examples → markdown blocks. - Linear instructions → numbered lists. - Labels without semantic meaning (`step1`, `helper2`). ## Code Examples **One excellent example beats many mediocre ones.** Choose the most relevant language: - Testing techniques → TypeScript / Python. - System debugging → Shell / Python. - Data processing → Python. **A good example is:** - Complete and runnable. - Well-commented explaining WHY. - From a real scenario. - Shows the pattern clearly. - Ready to adapt (not a fill-in-the-blank template). **Don't:** - Implement in 5+ languages. - Create fill-in-the-blank templates. - Write contrived examples. ## The Iron Law (Same as TDD) ``` NO SKILL WITHOUT A FAILING TEST FIRST ``` This applies to NEW skills AND EDITS to existing skills. Write skill before testing? Delete it. Start over. Edit skill without testing? Same violation. **No exceptions:** - Not for "simple additions". - Not for "just adding a section". - Not for "documentation updates". - Don't keep untested changes as "reference". - Don't "adapt" while running tests. - Delete means delete. **REQUIRED BACKGROUND:** The `test-driven-development` skill explains why this matters. Same principles apply to documentation. ## Testing Skills With Sub-Agents Different skill types need different test approaches. The detailed methodology — how to write pressure scenarios, pressure types, plugging holes systematically, meta-testing — lives in [references/testing-skills-with-subagents.md](references/testing-skills-with-subagents.md). Load it when you reach the testing step. In summary: ### Discipline-Enforcing Skills (rules / requirements) Examples: TDD, verification-before-completion. Test with academic questions, pressure scenarios, multiple combined pressures, then identify rationalizations and add explicit counters. **Success criteria:** agent follows rule under maximum pressure. ### Technique Skills (how-to guides) Examples: `condition-based-waiting`, `root-cause-tracing`. Test with application scenarios, variation scenarios, missing-information tests. **Success criteria:** agent successfully applies technique to a new scenario. ### Pattern Skills (mental models) Examples: reducing-complexity, information-hiding. Test with recognition scenarios, application scenarios, counter-examples. **Success criteria:** agent correctly identifies when / how to apply the pattern. ### Reference Skills (documentation / APIs) Examples: API documentation, command references. Test with retrieval scenarios, application scenarios, gap testing. **Success criteria:** agent finds and correctly applies the reference. ## Common Rationalizations for Skipping Testing | Excuse | Reality | |------------------------------|--------------------------------------------------------------------------| | "Skill is obviously clear" | Clear to you ≠ clear to other agents. Test it. | | "It's just a reference" | References can have gaps, unclear sections. Test retrieval. | | "Testing is overkill" | Untested skills have issues. Always. 15 min testing saves hours. | | "I'll test if problems emerge"| Problems = agents can't use skill. Test BEFORE deploying. | | "Too tedious to test" | Testing is less tedious than debugging a bad skill in production. | | "I'm confident it's good" | Overconfidence guarantees issues. Test anyway. | | "Academic review is enough" | Reading ≠ using. Test application scenarios. | | "No time to test" | Deploying untested skill wastes more time fixing it later. | **All of these mean: Test before deploying. No exceptions.** ## Bulletproofing Skills Against Rationalization Skills that enforce discipline (like TDD) need to resist rationalization. Agents are smart and will find loopholes when under pressure. **Psychology note:** Understanding WHY persuasion techniques work helps you apply them systematically. See [references/persuasion-principles.md](references/persuasion-principles.md) for the research foundation (Cialdini, 2021; Meincke et al., 2025) on authority, commitment, scarcity, social proof, and unity principles. ### Close Every Loophole Explicitly Don't just state the rule — forbid specific workarounds: ```markdown BAD: Write code before test? Delete it. GOOD: Write code before test? Delete it. Start over. **No exceptions:** - Don't keep it as "reference" - Don't "adapt" it while writing tests - Don't look at it - Delete means delete ``` ### Address "Spirit vs Letter" Arguments Add a foundational principle early: ```markdown **Violating the letter of the rules is violating the spirit of the rules.** ``` This cuts off an entire class of "I'm following the spirit" rationalizations. ### Build a Rationalization Table Capture rationalizations from baseline testing. Every excuse agents make goes in the table: | Excuse | Reality | |-------------------------------------|------------------------------------------------------------------| | "Too simple to test" | Simple code breaks. Test takes 30 seconds. | | "I'll test after" | Tests passing immediately prove nothing. | | "Tests after achieve same goals" | Tests-after = "what does this do?" Tests-first = "what should this do?" | ### Create a Red Flags List Make it easy for agents to self-check when rationalizing: ```markdown ## Red Flags — STOP and Start Over - Code before test - "I already manually tested it" - "Tests after achieve the same purpose" - "It's about spirit not ritual" - "This is different because..." **All of these mean: Delete code. Start over with TDD.** ``` ### Update Description for Violation Symptoms Add symptoms of when the agent is ABOUT to violate the rule: ```yaml description: Use when implementing any feature or bugfix, before writing implementation code. ``` ## RED-GREEN-REFACTOR for Skills ### RED: Write Failing Test (Baseline) Run a pressure scenario with a sub-agent via `delegate_task` **WITHOUT** the skill. Document exact behavior: - What choices did they make? - What rationalizations did they use (verbatim)? - Which pressures triggered violations? This is "watch the test fail" — you MUST see what agents naturally do before writing the skill. ### GREEN: Write Minimal Skill Write skill that addresses those specific rationalizations. Don't add extra content for hypothetical cases. Run the same scenarios WITH the skill. Agent should now comply. ### REFACTOR: Close Loopholes Agent found a new rationalization? Add an explicit counter. Re-test until bulletproof. See [references/testing-skills-with-subagents.md](references/testing-skills-with-subagents.md) for the complete testing methodology. ## Anti-Patterns ### Narrative Example "In session 2025-10-03 we found empty `projectDir` caused..." **Why bad:** too specific, not reusable. ### Multi-Language Dilution `example-js.js`, `example-py.py`, `example-go.go`. **Why bad:** mediocre quality, maintenance burden. ### Code in Flowcharts ```dot step1 [label="import fs"]; step2 [label="read file"]; ``` **Why bad:** can't copy-paste, hard to read. ### Generic Labels `helper1`, `helper2`, `step3`, `pattern4`. **Why bad:** labels should have semantic meaning. ## STOP: Before Moving to the Next Skill **After writing ANY skill, you MUST STOP and complete the deployment process.** **Do NOT:** - Create multiple skills in batch without testing each. - Move to the next skill before the current one is verified. - Skip testing because "batching is more efficient". **The deployment checklist below is MANDATORY for EACH skill.** Deploying untested skills = deploying untested code. It's a violation of quality standards. ## Skill Creation Checklist (TDD Adapted) **IMPORTANT: Use `todo` to track EACH checklist item below.** **RED Phase — Write Failing Test:** - [ ] Create pressure scenarios (3+ combined pressures for discipline skills). - [ ] Run scenarios WITHOUT skill via `delegate_task` — document baseline behavior verbatim. - [ ] Identify patterns in rationalizations / failures. **GREEN Phase — Write Minimal Skill:** - [ ] Name uses only letters, numbers, hyphens. - [ ] YAML frontmatter with required `name` and `description` fields. - [ ] Description starts with "Use when..." and includes specific triggers / symptoms. - [ ] Description is third-person and does NOT summarize the workflow. - [ ] Keywords throughout for search (errors, symptoms, tools). - [ ] Clear overview with core principle. - [ ] Addresses specific baseline failures identified in RED. - [ ] Code inline OR link to separate file. - [ ] One excellent example (not multi-language). - [ ] Run scenarios WITH skill via `delegate_task` — verify agents now comply. **REFACTOR Phase — Close Loopholes:** - [ ] Identify NEW rationalizations from testing. - [ ] Add explicit counters (if discipline skill). - [ ] Build a rationalization table from all test iterations. - [ ] Create a Red Flags list. - [ ] Re-test until bulletproof. **Quality Checks:** - [ ] Small flowchart only if decision non-obvious. - [ ] Quick reference table. - [ ] Common mistakes section. - [ ] No narrative storytelling. - [ ] Supporting files only for tools or heavy reference. **Deployment:** - [ ] Save via `skill_manage(action='create')` for user/org-scoped skills, or commit to the platform skills tree for platform skills. - [ ] Announce the new skill so future sessions can discover it. ## Discovery Workflow How future agents find your skill: 1. **Encounters problem** ("tests are flaky"). 2. **Scans available skills** in the system prompt's skill index. 3. **Finds skill** (description matches the situation). 4. **Loads via `skill_view`** when applying. 5. **Reads patterns** (quick reference table). 6. **Loads referenced files** only when needed. **Optimize for this flow** — put searchable terms early and often. ## The Bottom Line **Creating skills IS TDD for process documentation.** Same Iron Law: no skill without a failing test first. Same cycle: RED (baseline) → GREEN (write skill) → REFACTOR (close loopholes). Same benefits: better quality, fewer surprises, bulletproof results. If you follow TDD for code, follow it for skills. Same discipline applied to documentation.
Comments (0)
Sign in to join the conversation.
Reviews (0)
No reviews yet.
No comments yet.