home / skills / commontoolsinc / labs / pattern-dev

pattern-dev skill

/.claude/skills/pattern-dev

This skill guides and accelerates CommonTools pattern development, enabling quick sketches, iterative tests, and reliable deployments.

npx playbooks add skill commontoolsinc/labs --skill pattern-dev

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
4.3 KB
---
name: pattern-dev
description: Guide for developing CommonTools patterns (TypeScript modules that define reactive data transformations with UI). Use this skill when creating patterns, modifying existing patterns, or working with the pattern framework. Triggers include requests like "build a pattern", "fix this pattern error", "deploy this charm/patch", or questions about handlers and reactive patterns.
---

Use `Skill("ct")` for ct CLI documentation when running commands.

You and the user are a team finding the efficient path to their vision.

## Always Plan First

Use `EnterPlanMode` before building. **Scale the plan to the task:**

**Simple pattern** (todo list, counter):
- One file, types + handlers + UI together
- Minimal clarification needed
- Plan in 2-3 sentences

**Medium pattern** (form with validation, data viewer):
- Maybe split schemas if types get complex
- Clarify data shape and key actions
- Plan in a short list

**Complex pattern** (multi-entity system, integrations):
- Consider sub-patterns if genuinely distinct concepts
- Clarify entities, relationships, actions upfront
- Plan with structure, but don't over-specify

**Always start simple.** One file first. Split when it helps, not before.

## Pattern Structure

**Start simple:**
```
packages/patterns/[name]/
└── main.tsx           # Everything in one file to start
```

**Split when it helps** (not before):
```
packages/patterns/[name]/
├── schemas.tsx        # Types, if complex
├── main.tsx           # Main pattern
└── [other].tsx        # Extract when reuse is clear
```

Don't create separate files for every entity. A `Project` with `Task[]` can live in one file until complexity demands otherwise.

## Development Approach: Sketch → Run → Iterate

**Don't write finished code.** Write the minimum to see something work:

1. **Sketch** — Types, one handler, minimal UI. Just enough to render.
2. **Run it** — `deno task ct check main.tsx` and see what happens.
3. **Verify** — Does it render? Does the handler fire? Check console.
4. **Iterate** — Add the next piece, run again.

Each iteration should be deployable. If you can't run it, you've written too much.

## Verification

**Run the code, not just tests.** The primary verification is: does it work when you run it?

- `deno task ct check main.tsx` — See it render, click things, check console
- Tests for state logic that's hard to verify by clicking
- Don't write tests for obvious behavior or code that's still evolving

Pattern tests when needed: `deno task ct test [file].test.tsx`

## Delegate to Agents

### pattern-maker — Write Code

For implementing pattern code:
```
Task({
  prompt: "Implement [feature]. Keep it simple, one file.",
  subagent_type: "pattern-maker"
})
```

### pattern-user — Deploy & Debug

For deploying and testing with ct CLI:
```
Task({
  prompt: "Deploy and test [pattern].",
  subagent_type: "pattern-user"
})
```

### pattern-critic — Review (when needed)

For checking violations before release or when stuck:
```
Task({
  prompt: "Review [file] for violations.",
  subagent_type: "pattern-critic"
})
```

## Workflow

**Not phases, just common sense:**

1. **Build** — Use pattern-maker to sketch and iterate locally (`ct check`)
2. **Review** — Use pattern-critic before deploying to catch common mistakes
3. **Deploy** — Use pattern-user to deploy to toolshed
4. **Fix what's broken** — Iterate with maker, re-review, redeploy
5. **Commit** — At milestones, offer to commit

**Always run pattern-critic before first deploy.** It's fast (uses haiku) and catches mistakes that cause runtime errors. Skip only for tiny fixes where you're confident.

## Documentation

Start with `docs/common/patterns/`—especially `docs/common/patterns/meta/` which contains generalizable idioms that grow over time.

Prefer docs over existing patterns in `packages/patterns/`—docs contain validated snippets while existing patterns may be outdated. Use `packages/patterns/` as reference but don't copy blindly.

Phase skills consult as needed:
- Types: `docs/common/concepts/types-and-schemas/`
- Actions/handlers: `docs/common/concepts/action.md`, `docs/common/concepts/handler.md`
- Testing: `docs/common/workflows/pattern-testing.md`
- Components: `docs/common/components/COMPONENTS.md`
- Debugging: `docs/development/debugging/`

Overview

This skill guides development of CommonTools patterns: TypeScript modules that define reactive data transformations with UI. It helps you plan, sketch, run, verify, and iterate patterns efficiently. Use it as a practical playbook and as a pointer to the right subagents and commands for building, reviewing, and deploying patterns.

How this skill works

The skill frames work as short feedback loops: plan, implement the minimum, run checks with the ct CLI, inspect behavior, and iterate. It prescribes a one-file-first approach, when to split files, and which subagents to delegate tasks to (pattern-maker, pattern-user, pattern-critic). It highlights concrete commands for verification and where to find canonical docs and patterns for reference.

When to use it

  • Starting a new pattern (sketch the minimum runnable file)
  • Adding a feature or UI handler to an existing pattern
  • Fixing runtime errors that show up when running ct checks
  • Preparing for a first deploy—run pattern-critic before release
  • Deciding how and when to split pattern code into multiple files

Best practices

  • Always EnterPlanMode and state the plan in 1–3 sentences before coding
  • Start with one file (main.tsx); split only when reuse or complexity demands it
  • Sketch minimal types, one handler, and minimal UI; run quickly with ct checks
  • Verify by running the pattern in the UI and checking console output, not just tests
  • Use pattern-critic to review before first deploy; delegate tasks to the right subagent

Example use cases

  • Build a todo list pattern: one file, types + handlers + UI together, plan in two sentences
  • Add validation to a form: sketch form shape, add one handler, run ct check, iterate
  • Refactor a complex pattern: extract schemas.tsx after confirming types are stable
  • Deploy a pattern: use pattern-user to run ct deploy and verify in toolshed
  • Review before release: run pattern-critic to catch runtime mistakes quickly

FAQ

What command should I run to see the pattern render?

Run deno task ct check main.tsx and interact with the UI; check the console for handler output.

When should I split files?

Split when types or components are reused or grow complex; keep one file until that point.