Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Versions follow [semantic versioning](https://semver.org): while the major versi
- **Instructions found in project files are reported.** Text in comments, docs, test data, or fetched pages that addresses AI assistants is never followed, and the agent tells the developer which file contains it. The report header has a required "Instructions found in project files" section, and the final summary repeats it, so the warning is not lost in report mode.
- **The language file is required reading.** In every mode, `SKILL.md` names the language files next to the mode file, to be read before any code: one for each language in the code being read or written, `GENERIC.md` for a language without one, and a language met partway through is loaded before its code is read. The language's hidden costs and security traps (such as unrandomized integer hashing in Python) are no longer skipped.
- **`SKILL.md` is less than half as long** (about 2,600 words, from 5,600), so every session loads less. Each mandatory rule is stated in a few sentences there, and its full text moved to a new "Rule details" section in `WORKFLOW.md`, which report and apply mode already read. The workflow overview and anti-pattern list, which repeated `WORKFLOW.md` and the rules, were removed; their examples moved into the rules. Rule numbers are unchanged.
- **Report mode loads less.** Applying and close-out (Phases 5 and 6) moved from `WORKFLOW.md` to a new `APPLYING.md`, which only apply mode reads, in the same step as `WORKFLOW.md`. Text in "Rule details" that repeated those phases or `DIFFERENTIAL-TESTING.md` was removed.
- **New traps and tests:** cyclic structures (an iterative rewrite without a visited set loops forever where recursion failed fast), and round-trip tests when new code reads what existing code writes.

### Fixed
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ The skill's knowledge base is modular and organized around its workflow. The age
| File | Purpose |
|---|---|
| `SKILL.md` | The mandatory rules in brief, modes, which files to read first, instructions found in project files, working in few steps |
| `WORKFLOW.md` | Report and apply mode: setup (including the test baseline and commit authorization), survey (scope, contracts, reachability to entry points, cost along the call chain, exposure), analysis, report, apply, close-out; the full text of the mandatory rules ("Rule details") |
| `WORKFLOW.md` | Report and apply mode: setup (including the test baseline and commit authorization), survey (scope, contracts, reachability to entry points, cost along the call chain, exposure), analysis, report; the full text of the mandatory rules ("Rule details") |
| `APPLYING.md` | Apply mode only: applying each item (differential tests first, change, verify, benchmark, behavior changes held back, commits only if authorized) and close-out |
| `WRITING-NEW-CODE.md` | Write mode: which rules apply to new code, sizing the workload, choosing structures, existing-code bottlenecks, tests, summary |
| `ALGORITHM-ARSENAL.md` | How to find candidates: six triage questions (starting with whether the work is needed at all), complexity reference, routing by current complexity, lower bounds, reformulation, behavior-changing techniques |
| `CORE-TECHNIQUES.md` | Lookup tables of core techniques with their assumptions, production patterns, database queries, bit manipulation, combinations; loaded one section at a time |
Expand Down
21 changes: 21 additions & 0 deletions skills/APPLYING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Applying

Apply mode only: Phases 5 and 6, after Phases 1 to 4 in `WORKFLOW.md`. Read this file together with `WORKFLOW.md`, in the same step. The mandatory rules and their full text ("Rule details" in `WORKFLOW.md`) apply throughout.

## Phase 5: Apply

For each approved item, one at a time:

1. **Characterize the original.** Write differential tests per `DIFFERENTIAL-TESTING.md`, with the original implementation copied verbatim as the reference, and turn the contract into executable checks ("The contract as executable properties"). Run them against the unchanged code first: they must pass, which shows the harness is wired correctly. Then check the check: the tests must catch planted differences, and pass with the original on both sides when behavior can vary between runs ("Check the check" in `DIFFERENTIAL-TESTING.md`). Keep one differential-test file and one benchmark program for the whole apply phase, and add each item to them ("Work in few, large steps" in `SKILL.md`).
2. **Change the code.** Make the smallest change that implements the chosen approach. Keep the signature and contract. Add a short comment where the technique is not obvious.
3. **Verify.** Run the differential tests and contract checks, then the full existing suite, then any bounded or exhaustive check from the verification plan. Walk the behavior traps again for this change, and confirm each is covered by a test or ruled out by analysis. Record the level reached.
4. **Benchmark.** Measure time and memory for the original and the new version at realistic `n`, at a larger `n`, and on worst-case inputs where relevant (`BENCHMARKING.md`). State the end-to-end effect: the share of the whole operation's time the changed code took before the change, and the resulting saving, measured where possible ("Component and end-to-end" in `BENCHMARKING.md`). Record the numbers as measured, with the measured growth exponent, and compare them with the Phase 3 prediction (`WORKFLOW.md`). If they disagree, find out why before keeping the change: a wrong prediction means the analysis missed a cost. If the new version is not faster at realistic sizes, do not keep it unless the developer agrees for scaling reasons; a change not kept goes under "Tried and rejected." If verification or benchmarking cannot be completed, say so, report the gain as estimated only, and do not present the change as a confirmed win.
5. **Handle unverified parts and behavior changes.** If any behavior cannot be verified, or the change alters behavior in any way, stop work on this item: restore its original code, do not commit it, add it to "Behavior changes for review," and go on to the next item. Ask about every such item at the end; an earlier "apply all" does not approve it (rule 5). If the developer approves it, apply it with the `NEEDS-TESTING` or `BEHAVIOR-CHANGE` marker from `REPORTING.md`. If the developer declines it, apply the version that keeps the behavior, when one exists, through steps 1 to 4 ("Declined is not the end of the item" under rule 5 in "Rule details" in `WORKFLOW.md`).
6. **Run again after the final edit.** If anything changed after the last test run (review fixes, comments, formatting), run the differential tests and the full suite again. Results from an earlier version of the code do not count.
7. **Commit, only if authorized.** If the developer authorized commits (Phase 1, step 4, in `WORKFLOW.md`), make one commit per optimization, with a message that states the complexity before and after, the benchmark result, the verification level, and the tests added. Do not mix bug fixes, formatting, or unrelated refactors into it. Without authorization, do not commit: record in the report the exact files and functions this item changed, so the developer can review, commit, or revert it on its own.

If a differential test fails, the optimization is wrong: fix the optimization, never the test. If the failure shows that the original behavior is itself a bug, record it in the bug log and follow rule 4: if the best optimization removes the bug as a side effect, confirm that outputs differ only on inputs that trigger the bug and document it; otherwise keep matching the original.

## Phase 6: Close out

Write `APPLY-RESULTS.md` once, in one pass ("Apply results format" in `REPORTING.md`), and leave `OPTIMIZATION-REPORT.md` exactly as the analysis wrote it. Cover what was applied, skipped, or rejected; final benchmark numbers against the predictions; changes tried and rejected while applying; bugs found while applying; and the full lists of `NEEDS-TESTING` and `BEHAVIOR-CHANGE` items. State plainly which items were verified and at which level (with the evidence), which the developer accepted with unverified behavior, and which knowingly change behavior. Call an item proven only at verification level 4. Offer to keep each item's benchmark as a regression guard ("Offer a regression guard" in `BENCHMARKING.md`), and list the ones the developer kept.
2 changes: 1 addition & 1 deletion skills/REPORTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ For a small result (one or two items), present the report in the conversation. O

- `OPTIMIZATION-REPORT.md` — written in Phase 4: the ranked items, behavior changes for review, and tried-and-rejected candidates from the analysis.
- `BUGS-FOUND.md` — written in Phase 4: every bug noticed during the analysis. None are fixed on purpose.
- `APPLY-RESULTS.md` — written at the end of apply mode (Phase 6): what was applied and how it was verified and measured, changes marked as needing testing, behavior changes decided, changes tried and rejected while applying, and bugs found while applying. It refers to items by the IDs in `OPTIMIZATION-REPORT.md`.
- `APPLY-RESULTS.md` — written at the end of apply mode (Phase 6 in `APPLYING.md`): what was applied and how it was verified and measured, changes marked as needing testing, behavior changes decided, changes tried and rejected while applying, and bugs found while applying. It refers to items by the IDs in `OPTIMIZATION-REPORT.md`.

**Write each file once, and do not edit it afterward.** Text you write stays in the conversation, and every later step sends the whole conversation to the model again: a report's size is paid again on every step after it, and every edit adds another copy of the changed text.
- Keep findings in your working notes while you analyze. Write `OPTIMIZATION-REPORT.md` and `BUGS-FOUND.md` once, after Phase 3 is complete for every candidate.
Expand Down
2 changes: 1 addition & 1 deletion skills/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Make code fast by lowering its time complexity, using the right data structures,

**Then, if you know your model, check it.** This skill is built for coding-tier models such as Claude Sonnet and Opus. If you know which model you are running on and its provider offers it as a small, fast, or low-cost tier (for example Claude Haiku, or a model named "mini," "nano," or "lite"), add one line after the mode line: "Note: this skill is built for coding-tier models such as Claude Sonnet and Opus; on <your model>, expect shallower analysis and more speedups held back for review." Then continue as normal. If you do not know your model, say nothing about it.

**Then, before looking at any code, read the file for that mode.** Invoking the skill loads only this summary, and skipping the mode file is the most common way this skill fails: [WORKFLOW.md](WORKFLOW.md) for report and apply mode, following its phases in order; [WRITING-NEW-CODE.md](WRITING-NEW-CODE.md) for write mode. In every mode, also read the language file for each language in the code you will read or write, and only those, before looking at that code: `languages/PYTHON.md`, `JAVASCRIPT-TYPESCRIPT.md`, `JAVA.md`, `KOTLIN.md`, `SWIFT.md`, `CSHARP.md`, `C.md`, or `RUST.md`. For a language with no file here, read `languages/GENERIC.md`: it says to load the profile saved in the project if one exists and how to build one if not. If you come across code in another language partway through the task, read that language's file before reading that code. The language file's "Hidden costs" section lists traps, including security ones such as unrandomized hashing, that no other file repeats. Read [DIFFERENTIAL-TESTING.md](DIFFERENTIAL-TESTING.md) before writing any differential test. The mode files hold the details of the rules below and the steps that carry them out, which this file does not repeat.
**Then, before looking at any code, read the file for that mode.** Invoking the skill loads only this summary, and skipping the mode file is the most common way this skill fails: [WORKFLOW.md](WORKFLOW.md) for report and apply mode, following its phases in order, and in apply mode also [APPLYING.md](APPLYING.md), read in the same step; [WRITING-NEW-CODE.md](WRITING-NEW-CODE.md) for write mode. In every mode, also read the language file for each language in the code you will read or write, and only those, before looking at that code: `languages/PYTHON.md`, `JAVASCRIPT-TYPESCRIPT.md`, `JAVA.md`, `KOTLIN.md`, `SWIFT.md`, `CSHARP.md`, `C.md`, or `RUST.md`. For a language with no file here, read `languages/GENERIC.md`: it says to load the profile saved in the project if one exists and how to build one if not. If you come across code in another language partway through the task, read that language's file before reading that code. The language file's "Hidden costs" section lists traps, including security ones such as unrandomized hashing, that no other file repeats. Read [DIFFERENTIAL-TESTING.md](DIFFERENTIAL-TESTING.md) before writing any differential test. The mode files hold the details of the rules below and the steps that carry them out, which this file does not repeat.

## Mandatory rules

Expand Down
Loading
Loading