name: Add Stage Hints and Solutions
description: Creates solutions and hints for specific base stages of a Codecrafters course in a given language. Use this skill when the user wants to implement solutions for stages beyond Stage 1 (e.g., 'Add solutions for base stages 2-5 in Rust').
compatibility: Requires bun, docker, and course-sdk CLI (read installation instructions at https://github.com/codecrafters-io/course-sdk.git).
Goal
Implement working solutions and hints for specified base stages of a programming language that already has Stage 1 support in the course.
Procedure
1. Environment Setup
Ensure all necessary tools are installed before proceeding:
- Bun: Check if Bun is installed. If not, run
curl -fsSL https://bun.sh/install | bashand source the shell configuration (e.g.,source ~/.bashrc). - Docker: Ensure Docker is installed. Start and verify the daemon:
sudo service docker startsudo docker info- cgroup workaround (Cursor Cloud / nested container environments): If
docker runfails with an error likeunable to apply cgroup configuration: cannot enter cgroupv2 ... with domain controllers -- it is in threaded mode, the--memoryand--cpusresource limit flags used bycourse-sdk testare incompatible with the host's cgroup configuration. Fix this by wrapping thedockerbinary to strip those flags:
This stripssudo mv /usr/bin/docker /usr/bin/docker.real sudo tee /usr/bin/docker << 'WRAPPER' #!/bin/bash args=() for arg in "$@"; do case "$arg" in --memory=*|--cpus=*) ;; *) args+=("$arg") ;; esac done exec /usr/bin/docker.real "${args[@]}" WRAPPER sudo chmod +x /usr/bin/docker--memoryand--cpusflags from alldocker runinvocations, allowingcourse-sdk testto work in environments where cgroupv2 resource controllers are unavailable.
- course-sdk: Might be installed but assume it is outdated. Run
bun installandmake installin the repository root to compile the SDK.
2. Gather Context
Before writing any code, understand what you're building:
- Identify the target language and stages from the user's request (e.g., "Add solutions for base stages 2-5 in Rust").
- Read the stage descriptions (
stage_descriptions/base-<stage-number>-<stage-slug>.mdor equivalent) to understand what each requested stage expects — inputs, expected outputs, and behavior. - Read existing solutions in 2-3 reference languages (e.g.,
solutions/python/,solutions/go/,solutions/rust/) for each requested stage. Pay close attention to:- The code diff or progression from one stage to the next.
- The
/code/config.ymlstructure — howhintsare written for each stage. - Any stage-specific patterns (e.g., new files introduced, dependency changes).
- Read the previous stage's solution for the target language at
solutions/<LANGUAGE>/<previous-stage>/code/— this is the baseline code you'll build on.
3. Implement Solutions Stage-by-Stage
For each requested stage, in order:
- Verify that
solutions/<LANGUAGE>/exists and contains the solution for the stage immediately before the first requested stage (e.g., if implementing stage 3, confirm stage 2's solution is present). - Create the stage directory following the naming convention from reference languages (e.g.,
solutions/<LANGUAGE>/<NN>-<stage-slug>/code/).- Constraint: Always verify the exact directory naming convention by inspecting an existing language's
solutions/folder. Stage directories typically follow a pattern like01-<slug>/,02-<slug>/, etc.
- Constraint: Always verify the exact directory naming convention by inspecting an existing language's
- Copy the previous stage's solution as the starting point:
- Copy from
solutions/<LANGUAGE>/<previous-stage>/code/into the new stage'scode/directory.
- Copy from
- Read the reference implementations for this specific stage in other languages to understand the expected logic.
- Implement the solution for this stage only — the minimal code change needed to pass this stage's tests.
- Constraint: Each stage's solution should be an incremental diff from the previous stage. Do NOT include logic for future stages.
- Constraint: Match the code style and complexity of reference implementations. Keep it minimal.
- Constraint: Use the same SDKs/dependencies established in the language's previous stage implementation.
- Constraint: Do NOT manually edit files in any directory other than
solutions/<LANGUAGE>/. - Contraint: Do NOT manually create
solutions/<LANGUAGE>/diffdirectory, the compile command handles that.
4. Write Hints
For each requested stage, add hints to solutions/<LANGUAGE>/<stage-number>-<stage-slug>/code/config.yml:
- Study the hints written for the same stages in reference languages'
config.ymlfiles. - Write hints that follow the same structure, tone, and level of detail as the reference hints.
- Match the formatting convention (e.g., markdown in YAML strings, number of hints per stage).
- Tailor hints to the target language's idioms, standard library, and SDK usage.
- Ensure the
config.ymlis valid YAML — watch for indentation, multiline strings, and special characters.
5. The Iteration Loop (Compile & Test)
For each stage, repeat until tests pass:
- Compile: Run
sudo -E course-sdk compile <LANGUAGE>.- If it fails: Read the error output, fix the issue in the solution code, and retry.
- Test: Run
sudo -E course-sdk test <LANGUAGE>.- If the current stage fails: Compare expected vs. actual output. Cross-reference with how reference languages handle the test case. Adjust and retry.
- Contraint: The previous stage solutions are guaranteed to not be the problem so do not change them.
- Move to the next stage only after the current stage passes.
6. Final Verification
Once all requested stages pass:
- Run a full
sudo -E course-sdk test <LANGUAGE>to confirm all implemented stages pass together. - Review each stage's solution to ensure:
- Each stage is an incremental, minimal change from the previous one.
- No future-stage logic leaked into earlier stages.
- Code style is clean and consistent with reference implementations.
- No unnecessary files were created.
- Review
config.ymlto ensure:- Hints exist for every requested stage.
- YAML is valid and properly formatted.
- Hint content is helpful, accurate, and matches the tone of reference languages.