Repository navigation
New exercise for "Commands and Arguments" concept #980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
glennj
wants to merge
4
commits into
exercism:main
Choose a base branch
from
glennj:concept-exercise-shopping
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,522
−220
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,222 @@ | ||
| --- | ||
| name: add-concept-exercise | ||
| description: Scaffold a complete concept exercise for the Exercism Bash track, given a concept slug. Creates the exercise directory under exercises/concept/, all student-facing and meta files, and the track-level config.json entry, then validates everything. | ||
| --- | ||
|
|
||
| # Add a Concept Exercise (Bash track) | ||
|
|
||
| This track has concept _documentation_ (`concepts/<slug>/`) but the learning syllabus is incomplete: there are few or no concept _exercises_ (`exercises/concept/<slug>/`). | ||
| This skill walks through adding one correctly. | ||
|
|
||
| ## Inputs | ||
|
|
||
| Collect these before starting (ask the user for anything missing): | ||
|
|
||
| - **concept slug** (required): one of the slugs in `concepts/` and in the top-level `config.json` `concepts` array, e.g. `variables`, `arrays`, `conditionals`, `looping`, `arithmetic`, `quoting`, `pipelines`, `functions`, `redirection`, `heredocs`, `commands-and-arguments`, `more-arrays`. | ||
| - **exercise slug** (required): kebab-case, matching `[a-z0-9-]+`, named after the **story/theme**, NOT after the concept (`lasagna`, `bird-count`, `log-line-parser` are good; `floating-point-numbers` is not). | ||
| - **exercise name** (required): display name, e.g. `Lucian's Luscious Lasagna`. | ||
| - **story/theme**: a short narrative framing the tasks. | ||
| - **author handle**: the user's GitHub/Exercism handle for `.meta/config.json`. | ||
|
|
||
| Prefer reusing an existing Exercism story when one fits the concept: it comes with a ready-made exercise icon and cross-track familiarity. | ||
| The canonical story list is at <https://exercism.org/docs/building/tracks/stories>. | ||
| A novel story works too, but the exercise will need an icon eventually (see "Follow-ups" below). | ||
|
|
||
| ## Prerequisites: where the exercise fits in the syllabus | ||
|
|
||
| `docs/SYLLABUS.md` defines the intended concept ordering. | ||
| The exercise's `prerequisites` are the concepts the student must already have unlocked before attempting this one. | ||
| Read `docs/SYLLABUS.md` and the target concept's `concepts/<slug>/introduction.md` and `about.md` before writing anything. | ||
|
|
||
| ## Step 1: Scaffold the exercise directory | ||
|
|
||
| Create `exercises/concept/<slug>/` (kebab-case directory) with these files. | ||
| Filenames use snake_case derived from the slug (e.g. `bird-count` → `bird_count.sh` / `bird_count.bats`). | ||
|
|
||
| ### `<snake_slug>.sh` — student stub | ||
|
|
||
| - Shebang `#!/usr/bin/env bash`. | ||
| - Guiding comments only: describe the input, the expected output, and hints about structure. | ||
| NEVER include a working solution in the stub. | ||
| - Match the tone of existing stubs, e.g. `exercises/practice/two-fer/two_fer.sh`. | ||
|
|
||
| ### `<snake_slug>.bats` — tests | ||
|
|
||
| - Start with `#!/usr/bin/env bats` and `load bats-extra`. | ||
| - **Concept exercise tests have NO skip directives.** | ||
| The `[[ $BATS_RUN_SKIPPED == "true" ]] || skip` convention applies only to practice exercises. | ||
| `bin/validate_one_exercise` enforces this split automatically (it only checks skips outside `exercises/concept/`). | ||
| - Use `test_snake_case_names() { # @test` and keep test order aligned with the numbered tasks in `.docs/instructions.md`. | ||
| - Use `run bash <snake_slug>.sh ...` and the `assert_success` / `assert_failure` / `assert_output` family from `bats-extra.bash`. | ||
| - Tests are hand-written: concept exercises have no `.meta/template.j2` or `.meta/tests.toml`, and `bin/generate_tests` does not apply. | ||
|
|
||
| ### `bats-extra.bash` — vendored assertion library | ||
|
|
||
| Copy it verbatim from any practice exercise, e.g.: | ||
|
|
||
| ```bash | ||
| cp exercises/practice/two-fer/bats-extra.bash exercises/concept/<slug>/ | ||
| ``` | ||
|
|
||
| Do not modify it. | ||
|
|
||
| ### `.docs/introduction.md` — concept intro for this exercise | ||
|
|
||
| - Introduces the concept(s) the exercise teaches, as the student will see it alongside the exercise. | ||
| - Derive it from `concepts/<slug>/introduction.md`, but condense: cover only what the tasks require. | ||
| It is fine to copy sections verbatim. | ||
|
|
||
| ### `.docs/instructions.md` — story and tasks | ||
|
|
||
| - Open with the story, then numbered tasks (`## 1. ...`, `## 2. ...`). | ||
| - Each task states exactly what the program must output for given inputs; include example invocations (`bash <snake_slug>.sh ...`) and expected output where it helps. | ||
| - See `../jq` track concept exercises (e.g. `exercises/concept/lasagna/.docs/instructions.md`) for the house style. | ||
|
|
||
| ### `.docs/hints.md` — hints | ||
|
|
||
| - A `## General` section, then one section per task mirroring the instruction headings. | ||
| - Link to relevant reference docs (GNU bash manual sections, the track's own concept pages). | ||
|
|
||
| ### `.meta/config.json` — exercise metadata | ||
|
|
||
| ```json | ||
| { | ||
| "authors": ["<author-handle>"], | ||
| "files": { | ||
| "solution": ["<snake_slug>.sh"], | ||
| "test": ["<snake_slug>.bats"], | ||
| "exemplar": [".meta/exemplar.sh"], | ||
| "invalidator": ["bats-extra.bash"] | ||
| }, | ||
| "blurb": "<one-sentence description of what the exercise teaches>" | ||
| } | ||
| ``` | ||
|
|
||
| Note the key is `exemplar`, not `example` — concept exercises use an _exemplar_ solution, and the track-level `config.json` `files` section already maps `"exemplar": [".meta/exemplar.sh"]`. | ||
|
|
||
| ### `.meta/exemplar.sh` — reference solution | ||
|
|
||
| - The reference solution; must pass every test in `<snake_slug>.bats`. | ||
| - Must be ShellCheck-clean (`bin/lint` covers exercise shell files). | ||
| - Follow POLICIES.md (Google Shell Style Guide) and the track's bash conventions: quote expansions, use `local` in functions, prefer builtins where appropriate. | ||
| - Exemplars should model good style: this is what "done well" looks like. | ||
|
|
||
| ### `.meta/design.md` — design document | ||
|
|
||
| Use this structure (adapted from the jq track's concept exercises): | ||
|
|
||
| ```markdown | ||
| # Design | ||
|
|
||
| ## Goal | ||
|
|
||
| The goal of this exercise is to introduce <concept>. | ||
|
|
||
| ## Learning objectives | ||
|
|
||
| - <specific, testable things the student learns> | ||
|
|
||
| ## Out of scope | ||
|
|
||
| - <related things deliberately not covered> | ||
|
|
||
| ## Concepts | ||
|
|
||
| The Concepts this exercise unlocks are: | ||
|
|
||
| - `<concept-slug>` | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - `<prerequisite-concept-slug>` | ||
| ``` | ||
|
|
||
| Every learning objective must be addressable in the exercise itself. | ||
| For each objective, be able to point to where the student learns it (`.docs/introduction.md`, stub comments) and, where practical, where the student practices it (a task in `.docs/instructions.md` and its tests). | ||
| If an objective is neither taught nor exercised, reword the objective or change the exercise. | ||
|
|
||
| ## Step 2: Register the exercise in the track config | ||
|
|
||
| Edit the top-level `config.json`: | ||
|
|
||
| 1. If there is no `exercises.concept` key yet, add it; otherwise append to it. | ||
| Concept exercises are listed in syllabus order (prerequisites first): | ||
|
|
||
| ```json | ||
| "concept": [ | ||
| { | ||
| "slug": "<slug>", | ||
| "name": "<Exercise Name>", | ||
| "uuid": "<new uuid>", | ||
| "concepts": ["<concept-slug>"], | ||
| "prerequisites": ["<prereq-slug>", "..."], | ||
| "status": "wip" | ||
| } | ||
| ] | ||
| ``` | ||
|
|
||
| 2. Generate the uuid with `uuidgen | tr 'A-F' 'a-f'` (or `bin/configlet uuid` if configlet is available). | ||
| Never reuse or invent non-random uuids. | ||
| 3. New exercises start as `"status": "wip"`. | ||
| Flip to `"beta"` (and later `"active"`) once reviewed. | ||
| 4. `status.concept_exercises` at the top level stays `false` until the first concept exercise ships as `beta`/`active`; set it to `true` at that point. | ||
| 5. Do not touch `exercises.practice` or `exercises.foregone`. | ||
| 6. Preserve the existing JSON formatting (2-space indent) and LF line endings. | ||
|
|
||
| ## Step 3: Validate | ||
|
|
||
| Run these in order and report the results honestly: | ||
|
|
||
| 1. **Learning objectives coverage review (manual):** | ||
| For each learning objective in `.meta/design.md`, name the file(s) that address it (introduction, instructions task, hints, stub, or tests). | ||
| Confirm no task requires knowledge listed under "Out of scope". | ||
| Resolve any objective that is neither taught nor exercised before proceeding. | ||
|
|
||
| 2. **Exercise tests against the exemplar:** | ||
|
|
||
| ```bash | ||
| bin/validate_one_exercise exercises/concept/<slug> | ||
| ``` | ||
|
|
||
| This copies the exemplar over the stub name in a temp dir and runs the bats suite. | ||
| It must pass all tests with zero skips. | ||
|
|
||
| 3. **ShellCheck:** | ||
|
|
||
| ```bash | ||
| bin/lint | ||
| ``` | ||
|
|
||
| Note: `bin/lint` derives its file list from `config.json` and skips exercises with `"status": "wip"`, so it will NOT cover a brand-new exercise. | ||
| Also run shellcheck directly on the new files: | ||
|
|
||
| ```bash | ||
| shellcheck exercises/concept/<slug>/<snake_slug>.sh \ | ||
| exercises/concept/<slug>/.meta/exemplar.sh | ||
| ``` | ||
|
|
||
| 4. **Configlet** (metadata/config consistency): | ||
|
|
||
| ```bash | ||
| bin/configlet lint | ||
| ``` | ||
|
|
||
| If `bin/configlet` does not exist, run `bin/fetch-configlet` first. | ||
| If configlet cannot be fetched or run, say so — never claim it passed. | ||
|
|
||
| 5. **Review the diff:** `git status` and `git diff` — changes should be limited to the new exercise directory and the `exercises.concept` / `status` entries in `config.json`. | ||
|
|
||
| ## Gotchas | ||
|
|
||
| - Bats `run` merges stdout and stderr into `$output`: exemplar code must not print diagnostics. | ||
| While debugging tests, write to fd 3 (`printf '...\n' >&3`) and remove it before finishing. | ||
| - Concept exercises have no skip directives and no `tests.toml`/`template.j2`. | ||
| - Keep LF line endings everywhere. | ||
| - The stub must remain a stub — do not let exemplar code leak into it. | ||
| - If debugging output is added to track tooling (scripts under `bin/`), write it to stderr and remove it before finishing. | ||
|
|
||
| ## Follow-ups (mention these to the user; do only if asked) | ||
|
|
||
| - Update `docs/SYLLABUS.md` to link the new exercise. | ||
| - If the story is novel (not forked from another track), the exercise needs an icon: open an issue in the exercism/website-icons repository. | ||
| - When the exercise (and enough of the syllabus) is ready for students, change its status from `wip` to `beta` and set top-level `status.concept_exercises` to `true`. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding LLM instructions to the repo may encourage LLM based PRs which I'm generally not a fan of reviewing as fly by PRs. Do we want to do this? If we do, should |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| # Exercism Bash Track Agent Instructions | ||
|
|
||
| ## Scope | ||
|
|
||
| This repository maintains the Exercism Bash track: exercises, tests, example solutions, documentation, configuration, and track tooling. | ||
|
|
||
| Students solve exercises on the Exercism website or in their own Exercism CLI workspaces. | ||
| Do not treat this repository as a student workspace or fill in student stubs with completed solutions. | ||
|
|
||
| Follow `POLICIES.md`. | ||
| Keep changes scoped to the requested exercise or track component, preserve existing work, and avoid unrelated formatting or generated-file churn. | ||
|
|
||
| ## Exercise layout | ||
|
|
||
| Practice exercises live in `exercises/practice/<slug>/`. | ||
| Read each exercise's `.meta/config.json` to confirm its configured filenames. | ||
|
|
||
| - `<snake_slug>.sh`: student-facing stub; normally remains incomplete. | ||
| - `<snake_slug>.bats`: tests delivered to students. | ||
| - `.meta/example.sh`: reference solution; must pass all tests. | ||
| - `.meta/template.j2`: test-generation template, when present. | ||
| - `.meta/tests.toml`: canonical test selection and metadata. | ||
| - `.meta/config.json`: exercise metadata and file mappings. | ||
| - `.docs/`: student-facing instructions and documentation. | ||
| - `bats-extra.bash`: vendored Bats support/assertion library. | ||
|
|
||
| ## Maintaining exercises | ||
|
|
||
| - Keep instructions, tests, example solutions, stubs, and metadata consistent. | ||
| - When tests change, ensure `.meta/example.sh` demonstrates the intended behavior and passes the complete test suite. | ||
| - Preserve the student-facing stub's intended level of guidance; do not turn it into another example solution. | ||
| - For exercises with `.meta/template.j2`, treat the `.bats` file as generated. | ||
| Change the template or shared `bin/generator_macros.j2`, then regenerate rather than making generated edits that would be overwritten. | ||
| - Use canonical data from `problem-specifications` and `.meta/tests.toml`. | ||
| Do not invent canonical UUIDs or silently omit canonical cases. | ||
| - Preserve the skip convention: the first skip directive is commented out and later tests have active directives. | ||
| Validation uses `BATS_RUN_SKIPPED=true` to run all tests. | ||
| - Do not modify `bats-extra.bash` unless updating the vendored library is part of the task. | ||
|
|
||
| Regenerate tests only for affected exercises when possible: | ||
|
|
||
| ```bash | ||
| bin/generate_tests two-fer | ||
| ``` | ||
|
|
||
| The generator requires Python 3.11 or newer, Jinja2, and the cached problem-specifications repository. | ||
| Report missing prerequisites rather than claiming generation succeeded. | ||
|
|
||
| ## Skills | ||
|
|
||
| Task-specific skills live in `.agents/skills/`. | ||
| Use `.agents/skills/add-concept-exercise/SKILL.md` when adding a concept exercise for one of the concepts documented in `concepts/`. | ||
|
|
||
| ## Bash conventions | ||
|
|
||
| - Target Bash, not POSIX `sh`; POSIX compatibility is not required. | ||
| - Follow `POLICIES.md`, including the Google Shell Style Guide, while matching the surrounding file's established style. | ||
| - Use `#!/usr/bin/env bash` where a shebang is needed. | ||
| - Quote expansions unless splitting or globbing is explicitly intended. | ||
| Correctly handle whitespace, empty strings, and glob characters. | ||
| - Prefer clear Bash conditionals, arrays, functions, and builtins where appropriate. | ||
| Use `local` for function-local variables. | ||
| - Ensure exercise programs produce exactly the output and exit status expected by their tests. | ||
| Bats `run` collects both stdout and stderr in `$output`, so writing diagnostics to either stream can break `assert_output`, `refute_output`, and related assertions. | ||
| - When diagnostic output is needed while validating an exercise, write it to file descriptor 3 so Bats does not include it in `$output`: | ||
|
|
||
| ```bash | ||
| printf 'debug: value=%q\n' "$value" >&3 | ||
| ``` | ||
|
|
||
| - In standalone track-maintenance scripts, such as those under `bin/` or `.github/scripts/`, write diagnostics to stderr instead: | ||
|
|
||
| ```bash | ||
| printf 'error: invalid exercise configuration\n' >&2 | ||
| ``` | ||
|
|
||
| - Remove temporary diagnostic output before finishing unless the user explicitly asks to retain it. | ||
| - Avoid unnecessary dependencies and unrelated rewrites. | ||
| - Preserve LF line endings. | ||
|
|
||
| ## Validation | ||
|
|
||
| After changing an exercise's tests, template, or example solution, run: | ||
|
|
||
| ```bash | ||
| bin/validate_one_exercise exercises/practice/two-fer | ||
| ``` | ||
|
|
||
| This script copies the example solution, tests, `bats-extra.bash`, and any configured editor files into a temporary directory, then runs all Bats tests there against the example. | ||
| The temporary directory is removed on exit. | ||
| It validates the **example solution**, not student code. | ||
| The exercise directory, including the student-facing stub, is never modified, so uncommitted changes to it are safe. | ||
|
|
||
| Pass `-D` to run the tests inside the `exercism/bash-test-runner` Docker image instead of locally: | ||
|
|
||
| ```bash | ||
| bin/validate_one_exercise -D exercises/practice/two-fer | ||
| ``` | ||
|
|
||
| For broad exercise changes, validate all exercises: | ||
|
|
||
| ```bash | ||
| bin/validate_exercises | ||
| ``` | ||
|
|
||
| Run ShellCheck over active exercise shell files with: | ||
|
|
||
| ```bash | ||
| bin/lint | ||
| ``` | ||
|
|
||
| For configuration or metadata changes, also run: | ||
|
|
||
| ```bash | ||
| bin/configlet lint | ||
| ``` | ||
|
|
||
| Use `bin/fetch-configlet` only when configlet is needed and fetching it is acceptable. | ||
| Do not install global dependencies without approval. | ||
|
|
||
| Before finishing, inspect the relevant diff and working-tree status. | ||
| Report which checks ran and any that could not run; never claim unrun checks passed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the
configlettool be used?