---
name: coding
description: Project-specific coding conventions and constraints. Use when writing, modifying, or refactoring any code, implementing features, writing tests, or building MCP servers in this project.
title: coding
canonical_url: https://skilld.dev/gh/roby2358/skills/coding
last_updated: 2026-11-12T11:04:41.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install roby2358/skills/coding`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/coding`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/roby2358/skills/coding) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/coding`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/coding --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/coding --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Coding Conventions

## Two-Pass Process

Always use two passes: first get it working, then revise for reuse and clarity.

Both passes are essential — working code that's messy stays messy forever.

## Keep it Simple

Keep it simple. Focus on solving the specific problem first - we can collaborate to enhance and extend together once the core need is met. I love collaborating with you, and don't want you getting too far ahead!

Program close to the requirements.

## Structure

Identify central ideas and abstractions, and structure the code around those. Identify cross-cutting concerns that should be centralized. Factor these out for consistency, correctness, reuse, and clarity.

Look for opportunities to express logic as a state machine (see State Machines below).

## Functional / OO

The functional paradigm is powerful, and OO lends good organization. Favor a symbiotic approach with objects that contain functional constructions internally, and expose functional methods like map and flatmap.

## Structure Rules

- Code **MUST** be factored for reuse and clarity.
- Code **MUST NOT** be deeply nested. Code **SHOULD** use guard clauses, early exits, and granular functions to reduce nesting. Test for bad cases before the happy path.
- Code **SHOULD** avoid deep call stacks. Code **SHOULD** pass intermediate results from function to function.

## Discriminator Conditionals

Do not scatter conditionals that branch on a **discriminator** — a recurring mode/type/category value that answers *"what kind of thing is this?"* (e.g. `if allocationMethod == 'collect'`).

- Such a condition gets re-tested all over the code, so one variant's behavior smears across files and adding a variant becomes a scavenger hunt (Shotgun Surgery). Refactoring later is a tedious chore.
- Replace it with **parameterization, dispatch (lookup table / strategy), or first-class functions** — route the choice through ONE point keyed on the discriminator, so each variant is cohesive and extension is a single edit.

Conditionals on a transient value that answer *"what's true about this value right now?"* (e.g. `if x < 0`) are fine — that's just logic; leave it alone.

- **Litmus test:** "Will I write this same condition somewhere else?" / "Is it asking *what-kind* vs *what's-true-now*?" If what-kind, dispatch it.
- Don't over-apply: a small, stable case set is often clearer as a plain `if`/`switch` than as indirection.

## State Machines

Use a state machine when behavior depends on what has happened before. Common signs are several boolean flags that are checked together, a mode variable, or the same input handled differently at different times.

- Name each state. Keep the current state in one field.
- Write the transitions as a table that maps (state, event) to the next state and an action.
- Handle each event in one place, by looking up the current state in the table.
- An event that has no entry for the current state is ignored or rejected. Decide which, and do it the same way everywhere.
- Keep the table as data so it can be read, tested and drawn as a diagram.

Leave simple logic alone. Two states and one transition are usually clearer as a plain `if`.

## Shallow Call Chains

- Use shallow call chains and concrete objects to return.
- This reduces the need for mocks in tests, which reduces client-server contract drift in mocks.

## Default parameters

Default values for parameters are bad. They scatter values all over the code. Do not provide default values unless the user explicitly calls for it.

Better to fail fast. You MUST NOT provide inline defaults for missing values.

## Optional parameters

Avoid optional parameters to a function or method. The signature should be the signature, not 2^n variations of it.

## Code Quality

- Write clear, decoupled code with clear names and single responsibilities
- Solve the specific problem first; do not over-engineer ahead of requirements

## Parameter Rules

- **No default parameter values.** Fail fast on missing values. Never provide inline defaults unless explicitly requested.
- **No optional parameters.** The signature is the signature.

## Web Applications

The default preference is to write browser applications as html, css and js using script tags instead of ES modules so the user can double-click to launch the app.

If a project is already using ES modules, or I request it, then continue doing it that way. Don't change from one to the other without prompting.

## Migrations

In prototypes and early development, do not add migration or code versioning, since it's only the user. Instead, inform the user of changes that will break stored state.

Introduce migrations and versioning only after requested.

## Testing

NOTE: Some projects do not need tests at all, such as prototypes, games or generative art

Test scripts = When testing, never write throwaway scripts, use unit tests in the test directory - period. This is critical for our collaboration and lasting value of the project. The no throwaway tests is true even for prototypes that don't need tests (MAY write unit tests)

VERY IMPORTANT: When warranted, unit tests are critical to our process - I need you to always write tests as reusable unit tests in the test directory, not throwaway scripts. I know this might feel like extra work, but the long-term value is huge for us. This one's non-negotiable for our collaboration.

If you write small scripts for reuse, expose each one as a justfile recipe with a `cc-` prefix (e.g. `just cc-tc status`) and document the recipes in a skill local to the project to remind yourself they are available. Invoke the recipe, not the raw script path.

Make sure the code uses shallow call chains returning concrete objects to reduce client-server contract drift and reduce the use of mocks.

## MCP Servers

- Default to stdio transport
- Python MCP servers: use `from mcp.server.fastmcp import FastMCP` ((https://github.com/modelcontextprotocol/python-sdk))

## Tokens

Fable tokens are precious! Craft project-local scripts for repetitive tasks, expose them as `cc-` prefixed justfile recipes, and document them in a project-local skill
