diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index 282b68f..32e78be 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "fstack", "description": "Federico Mastrini's agent skills for everyday software engineering work.", - "version": "0.17.0", + "version": "0.17.1", "author": { "name": "Federico Mastrini", "url": "https://fedemas.dev" diff --git a/README.md b/README.md index 8b90699..5a0b8b8 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ **A short stack of agent skills for everyday software engineering work.** [![Claude Code plugin](https://img.shields.io/badge/Claude%20Code-plugin-D97757?style=flat-square)](https://www.fedemas.dev/fstack) -[![Version](https://img.shields.io/badge/version-0.17.0-B4A7E5?style=flat-square)](.claude-plugin/plugin.json) +[![Version](https://img.shields.io/badge/version-0.17.1-B4A7E5?style=flat-square)](.claude-plugin/plugin.json) [![License: MIT](https://img.shields.io/badge/license-MIT-93D3BB?style=flat-square)](LICENSE) diff --git a/gemini-extension.json b/gemini-extension.json index 0840765..3b9f22d 100644 --- a/gemini-extension.json +++ b/gemini-extension.json @@ -1,5 +1,5 @@ { "name": "fstack", - "version": "0.17.0", + "version": "0.17.1", "description": "Federico Mastrini's agent skills for everyday software engineering work." } diff --git a/plugin.json b/plugin.json index 495cbad..a45eda7 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json", "name": "fstack", - "version": "0.17.0", + "version": "0.17.1", "description": "Federico Mastrini's agent skills for everyday software engineering work.", "author": { "name": "Federico Mastrini", diff --git a/skills/implement/SKILL.md b/skills/implement/SKILL.md index 55c9f31..8cc2ba6 100644 --- a/skills/implement/SKILL.md +++ b/skills/implement/SKILL.md @@ -10,19 +10,30 @@ Write the code as if the requirement had been a founding assumption: the **end s When another skill called this one (such as implement-issue), its rules win wherever the two differ: scope, test handling, stop rules, and the reply. -## 1. Design the end state - -Read the code the change touches and its callers, and run the project's checks once so you know what already fails. The checks are the ones the project already has (its test, typecheck, lint, and build scripts or CI steps); a kind it lacks is reported as not run, never installed or borrowed for the occasion. Then decide, before editing, what the code would look like had this requirement been there from the start. Settle the types and stored shape before the functions that use them: trace how the data is read and written, and fit the structure to the dominant paths. The right shape makes the logic obvious. +## Principles + +Each principle is a short file in `references/` with the rule and the test that checks it. Read every file whose trigger the change meets, in one batch, before designing. + +| Read | When the change | +| --- | --- | +| [redesign-from-first-principles.md](references/redesign-from-first-principles.md) | adds a requirement to existing code | +| [subtract-before-you-add.md](references/subtract-before-you-add.md) | leaves code the end state no longer needs, or tempts a helper, option, or guard for a case that doesn't exist yet | +| [laziness-protocol.md](references/laziness-protocol.md) | makes a choice (a mode, format, or setting) that more than one place acts on | +| [foundational-thinking.md](references/foundational-thinking.md) | adds or changes types, stored data, or state that several actors touch | +| [model-the-domain.md](references/model-the-domain.md) | adds stateful logic, a flag beside another flag, or a branch to a chain | +| [type-system-discipline.md](references/type-system-discipline.md) | designs or changes types | +| [boundary-discipline.md](references/boundary-discipline.md) | reads outside input (env, config, CLI args, files, network, rows) or wires validation and error handling | +| [make-operations-idempotent.md](references/make-operations-idempotent.md) | changes state in a job, command, import, or handler that can crash, retry, or rerun | +| [separate-before-serializing-shared-state.md](references/separate-before-serializing-shared-state.md) | has concurrent workers, processes, or branches writing the same file, key, or object | +| [migrate-callers-then-delete-legacy-apis.md](references/migrate-callers-then-delete-legacy-apis.md) | replaces an internal API, helper, or module | +| [outcome-oriented-execution.md](references/outcome-oriented-execution.md) | is a rewrite or migration planned in several steps | +| [build-the-lever.md](references/build-the-lever.md) | is more than a couple of obvious edits: repeated edits, a data fix, an analysis, or a claim no test proves | +| [test-behavior-not-implementation.md](references/test-behavior-not-implementation.md) | writes, changes, or keeps a test | +| [minimize-reader-load.md](references/minimize-reader-load.md) | adds or moves code a reader must trace (every change, for step 3) | -- **Invariants.** Put each rule that must always hold where nothing can bypass it: a type (a union or state machine over flags that must agree, a typed model over loose parameters, a distinct type for look-alike primitives, an exhaustive match), a schema constraint (a unique key, a foreign key), or one parse at the boundary. A second flag that must stay in sync with the first is asking for one. -- **Branches.** Encode the domain in data: a map or registry instead of a branch chain spread across files, one reducer instead of state changed from several places. A change that adds one more branch to a chain is asking for one. -- **Boundaries.** Parse raw input (env, config, CLI args, files, network, rows) once, where it enters, into typed values; pass those in and trust them inside. When a schema already owns the shape (OpenAPI, protobuf, a validation or database schema), derive the type from it. Business logic stays pure and free of framework types. -- **Decisions.** Make each choice once, behind one source of truth, and pass the result in as a plain value. DRY the structure, not every line. -- **Reruns.** An operation that changes state converges: derive each step from the current state and apply only the difference, so a second run or a run after a crash at any point ends the same. Leftovers (locks, temp files, half-written records) are recognizable as stale; write to a temp path and rename into place. -- **Shared state.** Give each concurrent actor its own file, key, or record and merge where it is read; serialize only when one shared writer is a real invariant. -- **Subtraction.** List what the end state no longer needs, in the change's path: dead code, unreachable branches, checks the types now guarantee, pass-through layers (a wrapper with one caller, an adapter with one implementation), the API being replaced. Deleting it is part of the change. Dead code elsewhere goes in follow-ups. +## 1. Design the end state -Plain code stays plain when its shape is local and unlikely to grow: an abstraction earns its place by deleting branches or invalid states. +Read the code the change touches and its callers, and run the project's checks once so you know what already fails. The checks are the ones the project already has (its test, typecheck, lint, and build scripts or CI steps); a kind it lacks is reported as not run, never installed or borrowed for the occasion. Then decide, before editing, what the code would look like had this requirement been there from the start, following the principles you read. When the end state changes something outside the repo is known to rely on (a public API, a CLI, a schema or file format another program reads), ask before building: the bolt-on, the redesign, the cost of each, your recommendation first. With no one to answer, take the option that keeps outside callers working and say so. State only this code reads (its own files and caches, and what its docs say about them) is the code's to change; say how what is already on disk carries over. @@ -33,21 +44,16 @@ Done when you can state the end state in a few lines: its types, where parsing h Reach the end state in single-purpose steps, behavior and structure apart, in this order: delete what nothing uses, lay the shared shape (types, schema, the boundary parse, test fakes), build on it, and delete what it replaced last. After each step, run the narrowest check that covers it (the one test file, typecheck or lint on the touched files). - **Behavior changes** go test-first: a failing test through the public interface with the expected value taken from the requirement, then the code. Follow the test-driven-development skill when the user or a calling skill asks for it. -- **Refactors** keep every observable result. The tests are the net; one that breaks while behavior holds was pinned to internals, so rewrite it through the public interface and report it. -- **Replacing an API.** Move every caller, then delete the old API and the tests that only covered it, so one way remains. Each caller keeps what the old API did for it (normalizing input, defaults, error mapping): that moves into the new API or the caller, with a test. -- **Planned multi-step rewrites** converge on the end state instead of keeping each intermediate step green with throwaway compatibility code. Say which checks may be red between which steps; everything is green at the end. -- **Lever.** Non-trivial work gets a tool that does it or proves it: a codemod or script for repeated edits, a script for a data fix or an analysis, a generator for repeated code, a rerunnable check for a claim no test makes (every caller moved, every row fixed). A behavior change's failing-first test already proves it. The bar is triviality, not repetition: only a couple of obvious edits go without a tool. Do the first unit by hand, then build the smallest tool, never a framework, and prove it by rerunning it on that unit; make it safe to rerun. A deterministic tool beats fanning out to subagents; to fan out, write the recipe, the verification contract, and the fences as one skill the delegates read and cannot edit. Keep the tool in the diff when the work outlives the session, else delete it once it has run; name it in the report either way. +- **Refactors** keep every observable result. A test that breaks while behavior holds was pinned to internals: rewrite it through the public interface and report it. - **Propagate** every reference to what changed: types, call sites, docs, README tables, examples, rationale. -Add a helper, layer, option, flag, guard, or dependency only for duplication, branches, or inputs that exist now; guards and fallbacks live at boundaries. - Done when the end state stands: every caller moved, every listed deletion made, every reference propagated, and each lever built. ## 3. Check -Rerun the checks on the final tree and match or beat the first run; when no check exercises a changed command, job, or server, run it once. Read the whole diff once as a new reader would, and fix what you find: a pass-through layer, mutable state that could be a return value or derived, a check repeated past the boundary, a decision made in two places, leftovers (debug output, commented-out code, unused imports). +Rerun the checks on the final tree and match or beat the first run; when no check exercises a changed command, job, or server, run it once. Read the whole diff once as a new reader would, against the tests in the principles you read, and fix what you find. -Done when the checks match or beat the first run and, for each value the diff touches, a new reader finds where it comes from and what can change it in one place. +Done when the checks match or beat the first run and the diff passes each principle's test. ## Report @@ -55,7 +61,7 @@ Reply in this shape, dropping empty lines: ``` -End state: +End state: Removed: Levers: Verified: diff --git a/skills/implement/evals/discount-code-expiry/case.yaml b/skills/implement/evals/discount-code-expiry/case.yaml new file mode 100644 index 0000000..0eccf11 --- /dev/null +++ b/skills/implement/evals/discount-code-expiry/case.yaml @@ -0,0 +1,14 @@ +schema_version: "1.1" +name: discount-code-expiry +expected_outcome: | + The catalog gains an expiry per code (SPRING25's last valid day is 2026-05-31, the others none), an + expired code raises its own error type (such as ExpiredCode) that checkout turns into an "expired" message + distinct from "That code doesn't exist", and the current date reaches the expiry check as a value (a + parameter or an injected clock) read once at the entry point, not by patching datetime in tests. The new + tests drive apply_code or checkout with concrete dates and literal expected totals, cover both sides of the + boundary (31 May still discounts, 1 June is refused), and assert the error type or checkout's result rather + than message text. The old tests pinned to internals (patching _lookup and asserting the call, patching + _CODES with the old shape, comparing the exception message) are rewritten through the public interface + rather than re-pointed at new internals. The unittest suite passes. +context: + scaffold_script: place-files.sh diff --git a/skills/implement/evals/discount-code-expiry/files/till/README.md b/skills/implement/evals/discount-code-expiry/files/till/README.md new file mode 100644 index 0000000..556ff92 --- /dev/null +++ b/skills/implement/evals/discount-code-expiry/files/till/README.md @@ -0,0 +1,4 @@ +# till + +Checkout for the shop's tills. `python3 -m till cart.json [CODE]` prints the total for a cart; +`checkout()` is what the till screen calls. Run the tests with `python3 -m unittest discover -s tests -t .`. diff --git a/skills/implement/evals/discount-code-expiry/files/till/tests/__init__.py b/skills/implement/evals/discount-code-expiry/files/till/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/skills/implement/evals/discount-code-expiry/files/till/tests/test_checkout.py b/skills/implement/evals/discount-code-expiry/files/till/tests/test_checkout.py new file mode 100644 index 0000000..30967d0 --- /dev/null +++ b/skills/implement/evals/discount-code-expiry/files/till/tests/test_checkout.py @@ -0,0 +1,18 @@ +import unittest + +from till.checkout import checkout + +CART = [{"price_cents": 1500, "qty": 2}, {"price_cents": 500, "qty": 1}] + + +class CheckoutTest(unittest.TestCase): + def test_totals_the_cart(self): + self.assertEqual(checkout(CART), {"total_cents": 3500, "error": None}) + + def test_applies_a_code(self): + self.assertEqual(checkout(CART, "STAFF50")["total_cents"], 1750) + + def test_unknown_code_keeps_the_full_total(self): + self.assertEqual( + checkout(CART, "NOPE"), {"total_cents": 3500, "error": "That code doesn't exist"} + ) diff --git a/skills/implement/evals/discount-code-expiry/files/till/tests/test_discounts.py b/skills/implement/evals/discount-code-expiry/files/till/tests/test_discounts.py new file mode 100644 index 0000000..e16615a --- /dev/null +++ b/skills/implement/evals/discount-code-expiry/files/till/tests/test_discounts.py @@ -0,0 +1,23 @@ +import unittest +from unittest import mock + +from till import discounts + + +class ApplyCodeTest(unittest.TestCase): + def test_looks_up_the_code(self): + with mock.patch.object(discounts, "_lookup", return_value=10) as lookup: + discounts.apply_code(1000, "WELCOME10") + lookup.assert_called_once_with("WELCOME10") + + def test_applies_the_rate(self): + with mock.patch.dict(discounts._CODES, {"TEST20": 20}): + self.assertEqual(discounts.apply_code(1000, "TEST20"), 800) + + def test_unknown_code_message(self): + with self.assertRaises(ValueError) as ctx: + discounts.apply_code(1000, "NOPE") + self.assertEqual(str(ctx.exception), "unknown code: NOPE") + + def test_codes_ignore_case_and_spaces(self): + self.assertEqual(discounts.apply_code(1000, " welcome10 "), 900) diff --git a/skills/implement/evals/discount-code-expiry/files/till/till/__init__.py b/skills/implement/evals/discount-code-expiry/files/till/till/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/skills/implement/evals/discount-code-expiry/files/till/till/__main__.py b/skills/implement/evals/discount-code-expiry/files/till/till/__main__.py new file mode 100644 index 0000000..d6a61f4 --- /dev/null +++ b/skills/implement/evals/discount-code-expiry/files/till/till/__main__.py @@ -0,0 +1,17 @@ +import json +import sys + +from till.checkout import checkout + + +def main(argv): + with open(argv[0]) as f: + cart = json.load(f) + result = checkout(cart, argv[1] if len(argv) > 1 else None) + if result["error"]: + print(result["error"], file=sys.stderr) + print(f"Total: {result['total_cents'] / 100:.2f}") + + +if __name__ == "__main__": + main(sys.argv[1:]) diff --git a/skills/implement/evals/discount-code-expiry/files/till/till/checkout.py b/skills/implement/evals/discount-code-expiry/files/till/till/checkout.py new file mode 100644 index 0000000..168fbdc --- /dev/null +++ b/skills/implement/evals/discount-code-expiry/files/till/till/checkout.py @@ -0,0 +1,12 @@ +from till import discounts + + +def checkout(cart, code=None): + """Total a cart of {"price_cents", "qty"} lines, applying an optional discount code.""" + total = sum(line["price_cents"] * line["qty"] for line in cart) + if code: + try: + total = discounts.apply_code(total, code) + except discounts.UnknownCode: + return {"total_cents": total, "error": "That code doesn't exist"} + return {"total_cents": total, "error": None} diff --git a/skills/implement/evals/discount-code-expiry/files/till/till/discounts.py b/skills/implement/evals/discount-code-expiry/files/till/till/discounts.py new file mode 100644 index 0000000..84a5113 --- /dev/null +++ b/skills/implement/evals/discount-code-expiry/files/till/till/discounts.py @@ -0,0 +1,24 @@ +"""Discount codes for checkout.""" + +_CODES = { + "WELCOME10": 10, + "SPRING25": 25, + "STAFF50": 50, +} + + +class UnknownCode(ValueError): + """The code isn't in the catalog.""" + + +def _lookup(code): + rate = _CODES.get(code.strip().upper()) + if rate is None: + raise UnknownCode(f"unknown code: {code}") + return rate + + +def apply_code(total_cents, code): + """Return the total in cents after applying a discount code.""" + rate = _lookup(code) + return total_cents - total_cents * rate // 100 diff --git a/skills/implement/evals/discount-code-expiry/graders/01-the-current-date-reaches-the.md b/skills/implement/evals/discount-code-expiry/graders/01-the-current-date-reaches-the.md new file mode 100644 index 0000000..1c2bad8 --- /dev/null +++ b/skills/implement/evals/discount-code-expiry/graders/01-the-current-date-reaches-the.md @@ -0,0 +1,7 @@ +--- +type: llm +focus: trace +weight: 1 +--- + +The current date reaches the expiry check as a value (a `today`/`on`/`now` parameter or an injected clock) that the entry point supplies once, and the new tests pass concrete dates instead of patching datetime/date or freezing time. diff --git a/skills/implement/evals/discount-code-expiry/graders/02-tests-cover-both-sides-of.md b/skills/implement/evals/discount-code-expiry/graders/02-tests-cover-both-sides-of.md new file mode 100644 index 0000000..64f63e6 --- /dev/null +++ b/skills/implement/evals/discount-code-expiry/graders/02-tests-cover-both-sides-of.md @@ -0,0 +1,7 @@ +--- +type: llm +focus: trace +weight: 1 +--- + +Tests cover both sides of SPRING25's expiry: on 2026-05-31 the code still discounts (with a literal expected total), and on 2026-06-01 it is refused. diff --git a/skills/implement/evals/discount-code-expiry/graders/03-an-expired-code-has-its.md b/skills/implement/evals/discount-code-expiry/graders/03-an-expired-code-has-its.md new file mode 100644 index 0000000..627dedd --- /dev/null +++ b/skills/implement/evals/discount-code-expiry/graders/03-an-expired-code-has-its.md @@ -0,0 +1,7 @@ +--- +type: llm +focus: trace +weight: 1 +--- + +An expired code raises its own error type (or result variant) distinct from an unknown code, checkout turns it into a message that says the code expired, and the tests assert the error type or checkout's returned result rather than comparing exception message text. diff --git a/skills/implement/evals/discount-code-expiry/graders/04-no-test-in-the-final.md b/skills/implement/evals/discount-code-expiry/graders/04-no-test-in-the-final.md new file mode 100644 index 0000000..a1d3b25 --- /dev/null +++ b/skills/implement/evals/discount-code-expiry/graders/04-no-test-in-the-final.md @@ -0,0 +1,7 @@ +--- +type: llm +focus: trace +weight: 1 +--- + +No test in the final tree patches or asserts calls to till's private internals (`_lookup`, `_CODES`, or their replacements); the tests that did were rewritten to drive apply_code or checkout through their public interface, and the old test comparing `str(exception)` to "unknown code: NOPE" now asserts the error type or checkout's result. diff --git a/skills/implement/evals/discount-code-expiry/graders/05-python3-m-unittest-discover-s.md b/skills/implement/evals/discount-code-expiry/graders/05-python3-m-unittest-discover-s.md new file mode 100644 index 0000000..3253a0e --- /dev/null +++ b/skills/implement/evals/discount-code-expiry/graders/05-python3-m-unittest-discover-s.md @@ -0,0 +1,7 @@ +--- +type: llm +focus: trace +weight: 1 +--- + +python3 -m unittest discover -s tests -t . passes at the end of the run. diff --git a/skills/implement/evals/discount-code-expiry/place-files.sh b/skills/implement/evals/discount-code-expiry/place-files.sh new file mode 100755 index 0000000..93bc4d7 --- /dev/null +++ b/skills/implement/evals/discount-code-expiry/place-files.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -eu +cp -R "$(dirname "$0")/files/." . +git -C till init -q -b main +git -C till add -A +git -C till -c user.name=fixture -c user.email=fixture@example.org commit -qm "Till" diff --git a/skills/implement/evals/discount-code-expiry/prompt.md b/skills/implement/evals/discount-code-expiry/prompt.md new file mode 100644 index 0000000..67530c3 --- /dev/null +++ b/skills/implement/evals/discount-code-expiry/prompt.md @@ -0,0 +1,12 @@ +--- +tags: [implement] +max_turns: 80 +timeout_seconds: 1500 +allowed_tools: [Read, Glob, Grep, Skill, Write, Edit, Bash] +--- + +discount codes in till/ need expiry dates. SPRING25 is valid through 31 May 2026 and stops working on 1 June; the other codes don't expire. when someone uses an expired code the till should say it expired, not that it doesn't exist + +(Nobody can answer questions during this run.) + +Input files: till/ diff --git a/skills/implement/evals/report-json-flag/case.yaml b/skills/implement/evals/report-json-flag/case.yaml new file mode 100644 index 0000000..e77b88a --- /dev/null +++ b/skills/implement/evals/report-json-flag/case.yaml @@ -0,0 +1,13 @@ +schema_version: "1.1" +name: report-json-flag +expected_outcome: | + `tally report --json ` prints the summary as JSON (projects with their hours, and the total) that + parses with a JSON parser, and the text output stays byte-for-byte the same. The choice between text and + JSON is made once, where the CLI parses its arguments, and passed down as a value (a render function or + formatter), not threaded as a flag through ReportService to be checked again below. The run adds nothing + beyond the request: no --format with other choices, no config or env setting, no registry or plugin + machinery. ReportService, a one-caller layer that only forwards, and the single-implementation Formatter + base class are collapsed or the run says why they stay. A test runs the CLI with --json and checks the parsed + output against literal values. The README documents --json. The unittest suite passes. +context: + scaffold_script: place-files.sh diff --git a/skills/implement/evals/report-json-flag/files/tally/README.md b/skills/implement/evals/report-json-flag/files/tally/README.md new file mode 100644 index 0000000..2f31839 --- /dev/null +++ b/skills/implement/evals/report-json-flag/files/tally/README.md @@ -0,0 +1,8 @@ +# tally + +Timesheet reports. Each line of a timesheet CSV is `date,project,hours`. + + python3 -m tally report hours.csv + +prints the hours per project, largest first, and the total. Run the tests with +`python3 -m unittest discover -s tests -t .`. diff --git a/skills/implement/evals/report-json-flag/files/tally/tally/__init__.py b/skills/implement/evals/report-json-flag/files/tally/tally/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/skills/implement/evals/report-json-flag/files/tally/tally/__main__.py b/skills/implement/evals/report-json-flag/files/tally/tally/__main__.py new file mode 100644 index 0000000..13f43ef --- /dev/null +++ b/skills/implement/evals/report-json-flag/files/tally/tally/__main__.py @@ -0,0 +1,19 @@ +import argparse +import sys + +from tally.loader import CsvLoader +from tally.service import ReportService + + +def main(argv=None): + parser = argparse.ArgumentParser(prog="tally") + commands = parser.add_subparsers(dest="command", required=True) + report = commands.add_parser("report", help="hours per project") + report.add_argument("path") + args = parser.parse_args(argv) + print(ReportService(CsvLoader()).render(args.path)) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/skills/implement/evals/report-json-flag/files/tally/tally/formatting.py b/skills/implement/evals/report-json-flag/files/tally/tally/formatting.py new file mode 100644 index 0000000..b6d277e --- /dev/null +++ b/skills/implement/evals/report-json-flag/files/tally/tally/formatting.py @@ -0,0 +1,15 @@ +from abc import ABC, abstractmethod + + +class Formatter(ABC): + @abstractmethod + def format(self, summary): + ... + + +class TextFormatter(Formatter): + def format(self, summary): + width = max([len(name) for name, _ in summary["projects"]] + [5]) + lines = [f"{name:<{width}} {hours:6.1f}" for name, hours in summary["projects"]] + lines.append(f"{'Total':<{width}} {summary['total']:6.1f}") + return "\n".join(lines) diff --git a/skills/implement/evals/report-json-flag/files/tally/tally/loader.py b/skills/implement/evals/report-json-flag/files/tally/tally/loader.py new file mode 100644 index 0000000..710f843 --- /dev/null +++ b/skills/implement/evals/report-json-flag/files/tally/tally/loader.py @@ -0,0 +1,15 @@ +import csv +from dataclasses import dataclass + + +@dataclass(frozen=True) +class Entry: + date: str + project: str + hours: float + + +class CsvLoader: + def load(self, path): + with open(path, newline="") as f: + return [Entry(row[0], row[1], float(row[2])) for row in csv.reader(f) if row] diff --git a/skills/implement/evals/report-json-flag/files/tally/tally/service.py b/skills/implement/evals/report-json-flag/files/tally/tally/service.py new file mode 100644 index 0000000..f5dc756 --- /dev/null +++ b/skills/implement/evals/report-json-flag/files/tally/tally/service.py @@ -0,0 +1,12 @@ +from tally.formatting import TextFormatter +from tally.summary import summarize + + +class ReportService: + def __init__(self, loader): + self.loader = loader + self.formatter = TextFormatter() + + def render(self, path): + entries = self.loader.load(path) + return self.formatter.format(summarize(entries)) diff --git a/skills/implement/evals/report-json-flag/files/tally/tally/summary.py b/skills/implement/evals/report-json-flag/files/tally/tally/summary.py new file mode 100644 index 0000000..e52a0d3 --- /dev/null +++ b/skills/implement/evals/report-json-flag/files/tally/tally/summary.py @@ -0,0 +1,7 @@ +def summarize(entries): + """Hours per project, largest first, and the total.""" + per_project = {} + for entry in entries: + per_project[entry.project] = per_project.get(entry.project, 0) + entry.hours + rows = sorted(per_project.items(), key=lambda item: (-item[1], item[0])) + return {"projects": rows, "total": sum(hours for _, hours in rows)} diff --git a/skills/implement/evals/report-json-flag/files/tally/tests/__init__.py b/skills/implement/evals/report-json-flag/files/tally/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/skills/implement/evals/report-json-flag/files/tally/tests/test_report.py b/skills/implement/evals/report-json-flag/files/tally/tests/test_report.py new file mode 100644 index 0000000..63509ec --- /dev/null +++ b/skills/implement/evals/report-json-flag/files/tally/tests/test_report.py @@ -0,0 +1,26 @@ +import contextlib +import io +import os +import tempfile +import unittest + +from tally.__main__ import main + +CSV = "2026-03-02,atlas,3.5\n2026-03-02,birch,2\n2026-03-03,atlas,4\n" + + +class ReportTest(unittest.TestCase): + def setUp(self): + fd, self.path = tempfile.mkstemp(suffix=".csv") + with os.fdopen(fd, "w") as f: + f.write(CSV) + self.addCleanup(os.remove, self.path) + + def test_prints_hours_per_project_and_total(self): + out = io.StringIO() + with contextlib.redirect_stdout(out): + main(["report", self.path]) + self.assertEqual( + out.getvalue(), + "atlas 7.5\nbirch 2.0\nTotal 9.5\n", + ) diff --git a/skills/implement/evals/report-json-flag/graders/01-the-text-or-json-choice.md b/skills/implement/evals/report-json-flag/graders/01-the-text-or-json-choice.md new file mode 100644 index 0000000..d7e23a9 --- /dev/null +++ b/skills/implement/evals/report-json-flag/graders/01-the-text-or-json-choice.md @@ -0,0 +1,7 @@ +--- +type: llm +focus: trace +weight: 1 +--- + +The text-or-JSON choice is made in one place, where the CLI handles its arguments, and lower layers receive a ready value (a render function, a formatter object, or the summary to render) instead of a json/format flag they check again. diff --git a/skills/implement/evals/report-json-flag/graders/02-the-change-adds-nothing-beyond.md b/skills/implement/evals/report-json-flag/graders/02-the-change-adds-nothing-beyond.md new file mode 100644 index 0000000..dbd7fd8 --- /dev/null +++ b/skills/implement/evals/report-json-flag/graders/02-the-change-adds-nothing-beyond.md @@ -0,0 +1,7 @@ +--- +type: llm +focus: trace +weight: 1 +--- + +The change adds nothing beyond the --json request: no --format option with other choices (yaml, csv, ...), no new config file or environment setting, and no formatter registry or plugin mechanism. diff --git a/skills/implement/evals/report-json-flag/graders/03-reportservice-and-the-single-implementation.md b/skills/implement/evals/report-json-flag/graders/03-reportservice-and-the-single-implementation.md new file mode 100644 index 0000000..c9eadfe --- /dev/null +++ b/skills/implement/evals/report-json-flag/graders/03-reportservice-and-the-single-implementation.md @@ -0,0 +1,7 @@ +--- +type: llm +focus: trace +weight: 1 +--- + +ReportService (a one-caller layer that only forwards) and the Formatter abstract base class are removed or inlined in the final code, or the run's reply gives a concrete reason for keeping each one. diff --git a/skills/implement/evals/report-json-flag/graders/04-a-test-runs-the-cli.md b/skills/implement/evals/report-json-flag/graders/04-a-test-runs-the-cli.md new file mode 100644 index 0000000..fb24ee9 --- /dev/null +++ b/skills/implement/evals/report-json-flag/graders/04-a-test-runs-the-cli.md @@ -0,0 +1,7 @@ +--- +type: llm +focus: trace +weight: 1 +--- + +A test runs the CLI (main) with --json, parses its stdout with a JSON parser, and compares it with literal expected values (atlas 7.5, birch 2.0, total 9.5 or equivalent), and the existing text-output test still passes unchanged. diff --git a/skills/implement/evals/report-json-flag/graders/05-readme-md-documents-the-json.md b/skills/implement/evals/report-json-flag/graders/05-readme-md-documents-the-json.md new file mode 100644 index 0000000..2ec2165 --- /dev/null +++ b/skills/implement/evals/report-json-flag/graders/05-readme-md-documents-the-json.md @@ -0,0 +1,7 @@ +--- +type: llm +focus: { source: file, path: tally/README.md } +weight: 1 +--- + +README.md documents the --json option of `tally report`. diff --git a/skills/implement/evals/report-json-flag/graders/06-python3-m-unittest-discover-s.md b/skills/implement/evals/report-json-flag/graders/06-python3-m-unittest-discover-s.md new file mode 100644 index 0000000..3253a0e --- /dev/null +++ b/skills/implement/evals/report-json-flag/graders/06-python3-m-unittest-discover-s.md @@ -0,0 +1,7 @@ +--- +type: llm +focus: trace +weight: 1 +--- + +python3 -m unittest discover -s tests -t . passes at the end of the run. diff --git a/skills/implement/evals/report-json-flag/place-files.sh b/skills/implement/evals/report-json-flag/place-files.sh new file mode 100755 index 0000000..d65db1e --- /dev/null +++ b/skills/implement/evals/report-json-flag/place-files.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -eu +cp -R "$(dirname "$0")/files/." . +git -C tally init -q -b main +git -C tally add -A +git -C tally -c user.name=fixture -c user.email=fixture@example.org commit -qm "Tally" diff --git a/skills/implement/evals/report-json-flag/prompt.md b/skills/implement/evals/report-json-flag/prompt.md new file mode 100644 index 0000000..253254f --- /dev/null +++ b/skills/implement/evals/report-json-flag/prompt.md @@ -0,0 +1,12 @@ +--- +tags: [implement] +max_turns: 80 +timeout_seconds: 1500 +allowed_tools: [Read, Glob, Grep, Skill, Write, Edit, Bash] +--- + +can you add a --json option to `tally report`? want to pipe it into jq + +(Nobody can answer questions during this run.) + +Input files: tally/ diff --git a/skills/implement/references/boundary-discipline.md b/skills/implement/references/boundary-discipline.md new file mode 100644 index 0000000..02c748f --- /dev/null +++ b/skills/implement/references/boundary-discipline.md @@ -0,0 +1,10 @@ +# Boundary discipline + +Validate, narrow types, and handle errors where data crosses into the system: CLI args, env vars, config files, request bodies, external APIs, files, database rows. Inside, trust the types. + +- Parse raw input once, where it enters, into typed domain values, with clear errors for bad input. Pass those values in; the code inside relies on them without re-validating or adding null checks. +- Keep transport and framework types (request objects, ORM rows, SDK responses) at the edge. The core's public functions take and return domain types. +- Put business logic in pure functions with no framework dependency. The shell that calls them (a handler, a CLI entry point, a job runner) stays thin: parse, call, render. +- Guards, retries, and fallbacks live at the boundary too. + +**Test:** for each check in the diff, ask whether this data is crossing a boundary right here; when it isn't, the check goes. For each piece of logic, ask whether it could be a pure function the shell calls; when it could, extract it. diff --git a/skills/implement/references/build-the-lever.md b/skills/implement/references/build-the-lever.md new file mode 100644 index 0000000..028765d --- /dev/null +++ b/skills/implement/references/build-the-lever.md @@ -0,0 +1,10 @@ +# Build the lever + +Non-trivial work gets a tool that does it or proves it: a codemod or script for repeated edits, a script for a data fix or an analysis, a generator for repeated code, a rerunnable check for a claim no test makes (every caller moved, every row fixed). The tool is what a reviewer can rerun. A behavior change's failing-first test already proves it. + +- The bar is triviality, not repetition: only a couple of obvious edits go without a tool. +- Do the first unit by hand, then build the smallest tool that does or proves the job, never a framework. Prove it by rerunning it on that unit, and make it safe to rerun: a second run changes nothing. +- A deterministic tool beats fanning out to subagents. To fan out, write the recipe, the verification contract, and the fences as one skill the delegates read and cannot edit. +- Keep the tool in the diff when the work outlives the session (other branches, future data, a recurring check), with a line on how to run it; otherwise delete it once it has run. + +**Test:** the report's Levers line names each tool, what it did or proved, and whether it stayed. diff --git a/skills/implement/references/foundational-thinking.md b/skills/implement/references/foundational-thinking.md new file mode 100644 index 0000000..63726b0 --- /dev/null +++ b/skills/implement/references/foundational-thinking.md @@ -0,0 +1,10 @@ +# Foundational thinking + +Get the data shape right before writing logic. The right shape makes the logic obvious. + +- Define the core types and the stored shape first. Trace every place the data is read and written, and pick the structure that fits the main paths: a map for lookups by key, an ordered list for scans, one normalized record instead of copies kept in sync. +- DRY the structure, not every line: each shape has one definition, while two similar lines of logic can stay. +- Before state is shared between actors (threads, workers, processes, requests), ask what happens when another one changes it at the same time. Unless the answer is "nothing", give each actor its own (see separate-before-serializing-shared-state.md). +- Scaffold first. After removing dead code, lay what every later step builds on (shared types, the schema, test fakes, the check you will rerun), then the feature. Keep each step, and each commit, to one purpose. + +**Test:** the logic that uses the new shape has fewer branches than before, not more. diff --git a/skills/implement/references/laziness-protocol.md b/skills/implement/references/laziness-protocol.md new file mode 100644 index 0000000..bcc9548 --- /dev/null +++ b/skills/implement/references/laziness-protocol.md @@ -0,0 +1,9 @@ +# Laziness protocol + +Make the smallest change that fully solves the problem, and make each decision once. + +- **One source of truth per decision.** When a choice (a mode, an output format, an environment, a feature switch) affects several places, make it once, where the input arrives, and pass the result in as a plain value: a function, an enum, a config object. The places that use it act on that value instead of asking the question again. +- **Smallest diff.** Fewer lines beat elegant boilerplate. An edit in one place beats a new layer with one implementation. +- Measure "smallest" against the end state, not the old design: a redesign that deletes more than it adds is a small diff. + +**Test:** search for the decision (the flag name, the mode string): it is read in one place. Each added line is needed for the requirement or removes more than it costs. diff --git a/skills/implement/references/make-operations-idempotent.md b/skills/implement/references/make-operations-idempotent.md new file mode 100644 index 0000000..8b0b2cb --- /dev/null +++ b/skills/implement/references/make-operations-idempotent.md @@ -0,0 +1,10 @@ +# Make operations idempotent + +An operation that changes state (a job, an import, a migration, a deploy step, a handler that retries) reaches the same correct end state however many times it runs and wherever the previous run stopped. + +- Derive each step from the state that exists, not from what the previous run meant to do: read the current state, compare it with the goal, and apply only the difference. Keys that turn a repeated write into a no-op (a natural unique key, an upsert) and progress records written in the same transaction as the work are the usual tools. +- Make anything a run leaves behind (a lock, a temp file, a half-written record, a claimed job) recognizable as stale by the next run, through evidence that holds wherever the previous run stopped: an expired lease, a process that is gone, a temp name. +- Write a file to a temp path and rename it into place, so readers see the old file or the new one, never half of one. +- When existing data already breaks the rule the change adds, say how it carries over: a migration that repairs it, or what will fail and how to fix it. + +**Test:** ask what happens when this runs twice, and when the previous run crashed at each possible point, including between two writes. When the answer depends on what was left behind, add a step that reconciles. A test reruns the operation, or stops it partway and reruns it, and checks the end state. diff --git a/skills/implement/references/migrate-callers-then-delete-legacy-apis.md b/skills/implement/references/migrate-callers-then-delete-legacy-apis.md new file mode 100644 index 0000000..b2b4d15 --- /dev/null +++ b/skills/implement/references/migrate-callers-then-delete-legacy-apis.md @@ -0,0 +1,12 @@ +# Migrate callers, then delete legacy APIs + +When a new internal API replaces an old one, move every caller to the new API and delete the old one in the same change, so one way remains. The old name leaves with no alias, wrapper, re-export, or deprecation shim. + +- Find every caller first, including tests, scripts, docs, and examples. With more than a couple, build a lever (see build-the-lever.md). +- Each caller keeps what the old API did for it: normalizing input, defaults, error mapping, logging. That behavior moves into the new API or into the caller, with a test. +- Tests assert the new contract through the public interface. Tests that only protected the old API's internals are deleted, after any behavior they covered moves into tests of the new API. +- Delete the old API last, once nothing references it. + +This holds when only code you can change depends on the old API. When something outside the repo relies on it (a published package, a public endpoint, a CLI, a file format another program reads), follow SKILL.md's rule for outside contracts. + +**Test:** a search for the old name finds nothing in the tree. diff --git a/skills/implement/references/minimize-reader-load.md b/skills/implement/references/minimize-reader-load.md new file mode 100644 index 0000000..1f11daa --- /dev/null +++ b/skills/implement/references/minimize-reader-load.md @@ -0,0 +1,10 @@ +# Minimize reader load + +Reader load is the work a new reader does to understand the code: the layers between a question and its answer, and the hidden or mutable state they must hold in their head. Cut both. + +- Collapse layers that only forward: a wrapper with one caller, an adapter with one implementation, a pass-through method. Inline them. +- Shrink the scope of state: a return value over a mutation, a local over a field, a field over module state, module state over a global. Derive a value instead of keeping a copy in sync. +- Name an invariant once, at the boundary, instead of rechecking it in every consumer. +- Clear the leftovers: debug output, commented-out code, unused imports and variables. + +**Test:** for each value the diff touches, a new reader answers "where does this come from?" and "what can change it?" in under 30 seconds, by reading one place. diff --git a/skills/implement/references/model-the-domain.md b/skills/implement/references/model-the-domain.md new file mode 100644 index 0000000..3f5b77f --- /dev/null +++ b/skills/implement/references/model-the-domain.md @@ -0,0 +1,13 @@ +# Model the domain + +Encode the domain in a data structure instead of spreading it across conditionals. The right structure makes invalid states unrepresentable and deletes branches. + +- One status field (a union, enum, or state machine) instead of booleans or phase checks that must agree. +- A typed model instead of loose parameters that travel together. +- A map, registry, or discriminated union instead of a branch chain spread across files. +- One reducer or transition function instead of state changed from several places. +- An index, queue, or normalized collection where the access pattern calls for one. + +Keep plain code plain when its shape is clear, local, and unlikely to grow. An abstraction earns its place by deleting branches or invalid states; one that only adds indirection goes. + +**Test:** the change adds no branch to an existing if/else chain and no boolean that must stay in sync with another. diff --git a/skills/implement/references/outcome-oriented-execution.md b/skills/implement/references/outcome-oriented-execution.md new file mode 100644 index 0000000..7124c2c --- /dev/null +++ b/skills/implement/references/outcome-oriented-execution.md @@ -0,0 +1,11 @@ +# Outcome-oriented execution + +In a rewrite or migration planned in several steps, converge on the end state instead of keeping each intermediate step green with throwaway compatibility code. Shims written to keep step two of five stable tend to stay for years. + +- Write down the steps and say which checks may be red between which steps, and why. Planned breakage is fine when it is scoped to those steps and reversible. +- While migrating, keep running the high-signal checks on the area you are touching (its test file, the type check on the touched module) after each step. +- At the end everything is green: the full test suite, type check, lint, build, and one run of each changed command, job, or server that no check covers. + +A single change outside such a plan goes test-first and stays green. + +**Test:** the final diff has no adapter, alias, or dual code path that exists only to bridge two steps. diff --git a/skills/implement/references/redesign-from-first-principles.md b/skills/implement/references/redesign-from-first-principles.md new file mode 100644 index 0000000..5264343 --- /dev/null +++ b/skills/implement/references/redesign-from-first-principles.md @@ -0,0 +1,10 @@ +# Redesign from first principles + +Fit a new requirement into the design as if it had been a founding assumption, instead of bolting it onto the design as it stands. + +- Read every file the change touches and its callers until you can say how the current design works and why it has that shape. +- Ask: written from scratch with this requirement, what would we build? That answer is the end state. It decides the types, where each rule lives, and what the old design no longer needs. +- Think through the whole redesign, then deliver it in small steps that each move toward it. +- Propagate the change through every reference: types, call sites, docs, README tables, examples, and comments that give the rationale. + +**Test:** a reader of the final code can't tell which requirement came last. A bolt-on shows as a flag or branch beside the old design, a parameter only the new caller passes, a wrapper around the old function, or docs that still describe the old shape. diff --git a/skills/implement/references/separate-before-serializing-shared-state.md b/skills/implement/references/separate-before-serializing-shared-state.md new file mode 100644 index 0000000..3fe7a62 --- /dev/null +++ b/skills/implement/references/separate-before-serializing-shared-state.md @@ -0,0 +1,9 @@ +# Separate before serializing shared state + +When concurrent actors (workers, processes, threads, CI jobs, branches) might write the same file, key, branch, or object, first ask whether they need one shared object or are each publishing their own facts. + +- Separate by default: give each actor its own file, key, record, or directory, and merge where the state is read. Workers that each write their own field into one shared file still share it, because every write rewrites the whole file. +- Serialize only when one shared write target is a real invariant (a counter that must be exact, one ordered log), and then do it structurally: a lock file, a single writer, sequential phases, or compare-and-swap. +- Concurrency control lives in the code. A comment, a doc, or an instruction asking actors to take turns controls nothing. + +**Test:** for each write to shared state, name the invariant that needs it shared. With none, split it. "We need a lock" or "add a queue" is the first idea to question. diff --git a/skills/implement/references/subtract-before-you-add.md b/skills/implement/references/subtract-before-you-add.md new file mode 100644 index 0000000..fe69352 --- /dev/null +++ b/skills/implement/references/subtract-before-you-add.md @@ -0,0 +1,11 @@ +# Subtract before you add + +Remove complexity first, then build on the simpler base. Leave the design a little simpler and more capable, behind the same or a smaller surface. + +- Remove before you build: delete what nothing uses, build the change, then delete what the new code replaced. +- List what the end state no longer needs in the change's path, and delete it as part of the change: dead code, unreachable branches, checks the types now guarantee, pass-through layers, the API being replaced, tests that only covered deleted code, and docs that describe something gone. Dead code elsewhere goes in Follow-ups. +- Build for the usage you can see. Add a helper, layer, option, flag, guard, parser, or dependency only for duplication, branches, or inputs that exist now; guards and fallbacks live at boundaries. +- Cut before you polish: reach the smallest version that works, then improve it. +- When a doc section, comment, or reference has nothing left to say, delete it rather than leave a stub. + +**Test:** every line the diff adds serves the requirement, and the Removed line of the report lists what the end state no longer needed. diff --git a/skills/implement/references/test-behavior-not-implementation.md b/skills/implement/references/test-behavior-not-implementation.md new file mode 100644 index 0000000..a62fcd8 --- /dev/null +++ b/skills/implement/references/test-behavior-not-implementation.md @@ -0,0 +1,17 @@ +# Test behavior, not implementation + +A test is a claim about what users of the code can observe through its interface: return values, raised errors, state they can read back, and effects on outside systems (what a mail server, database, or HTTP API receives). Private helpers, internal call order, and intermediate data are implementation. + +Judge each test you write, change, or keep against two imagined edits: + +- **Break the behavior** (a wrong value, a skipped or doubled effect). The test fails. When it still passes it proves nothing; the usual causes are a loose assertion, an expected value computed by the code under test, and an assertion on data the test built itself. +- **Change the internals** and keep every observable result. The test passes. When it fails, it is pinned to the implementation. + +Keep the tests that catch the first edit and survive the second; rewrite or delete the rest. + +- Drive the code through its public interface with concrete inputs, and write the expected value out as a literal taken from the requirement. +- Pass in what lies outside the system (the clock, the network, the mail transport) as a fake, and assert what it received. Patching an internal helper, or asserting that it was called, pins the test to the implementation. +- Pair each "this never happens" with a case where it does, so the test can't pass by doing nothing. +- Where the code already raises an error type or code that callers branch on, assert that rather than the message text. + +**Test:** for each test in the diff, name the behavior change that would make it fail. When only an internal rename would, rewrite it. diff --git a/skills/implement/references/type-system-discipline.md b/skills/implement/references/type-system-discipline.md new file mode 100644 index 0000000..89278e1 --- /dev/null +++ b/skills/implement/references/type-system-discipline.md @@ -0,0 +1,13 @@ +# Type system discipline + +Let the type checker reject impossible states, mixed-up primitives, and unhandled cases. + +- **Invalid states can't be written.** A union, enum, or sum type instead of flags that must agree; a required field instead of an optional one that is always set. +- **Look-alike primitives get their own types.** When two values share a primitive type but mean different things (a user id and an order id, cents and dollars, milliseconds and seconds), give each its own type (a branded type, newtype, or value class) and validate once where it is created. +- **Outside data is untyped until parsed.** JSON, RPC payloads, CLI args, config, env vars, and database rows go through one parse function at the boundary that returns the typed model. +- **Types come from the schema that owns the shape.** When OpenAPI, protobuf, GraphQL, or a validation or database schema defines it, derive the type from that schema instead of writing a parallel one by hand. +- **Matches are exhaustive.** A switch over a union fails the type check when someone adds a variant: `never` in TypeScript, no wildcard arm in Rust, `assert_never` in typed Python. + +In a dynamic language, the same ideas hold through the project's own tools: enums and dataclasses, type hints its checker enforces, a validation schema at the boundary. + +**Test:** adding a variant breaks the type check at every place that must handle it, and no function takes two same-typed parameters a caller could swap.