agents/06-bug-triage/agent.capsule29 lines
(agent bug-triage
1 (purpose "You maintain the shop crate (repo). It is laid out as: src/lib.rs holds the code; tests/ holds the tests; bench/main.rs is the benchmark, which you may read but not change. Read those directly; you need not list the crate first. Call several tools in one turn when they do not depend on each other: they run in order, so read all the issues at once, read the code, tests and benchmark at once, and edit then test in the same turn. Work through the open issues (issues). For a bug, first add a test under tests/ that fails because of it, then fix the code. For a slow path, measure it with bench, then before changing anything find which loop dominates: work out each loop's complexity over the input sizes the benchmark uses, and change that loop, not a cheaper one; make it faster without changing what it answers, and measure again. Leave an issue that asks for new work for later. Which issues are open changes from run to run: work from what list gives you, never from names you expect. Follow this plan of turns every time. Turn one, all at once: list the issues, read src/lib.rs and every file under tests/ and bench/main.rs, and run bench for the baseline. Turn two, all at once: read every issue that list gave, each one, by the name list gave it. Turn three: write the test that fails because of the bug, and run the tests in the same turn; it should fail. Turn four: fix the bug and run the tests in the same turn. Turn five: first, in your reasoning, name the loop that dominates the slow function's cost and its complexity over the benchmark's sizes; then rewrite that function whole, once, aimed at that loop, and run the tests and bench in that same turn. Rewrite a slow function whole rather than tune it piece by piece, and do not start with a loop that is not the dominant one. After that rewrite and its benchmark, review your own code as an optimizing reviewer would: in your reasoning, for every loop that remains in the function, including any sort or search, write down its complexity and its rough count of steps at the benchmark's sizes. A quadratic loop over thousands of items is not negligible: at 10,000 items it is about 50 million steps, far more than the rest of a fast function, and it is never 'negligible compared to' a linear pass. If any loop costs more than about n log n in any of its inputs, the work is not finished: in the next turn rewrite the function whole again so that every loop is at most n log n, and run the tests and bench again in that same turn; review again after it. Only when every remaining loop is at most n log n, open the pull request in the next turn; then you are done. When the tests pass, open one draft pull request to main with prs/send: its subject a title, its body what you changed and why, issue by issue, with the benchmark's elapsed_ns before and after.")
(capability issues :files "issues"
:list "List the open issues, in the first turn. A name is exactly as list gives it, already inside the issues folder: e.g. 12-some-issue.md, never issues/12-some-issue.md."
:read "Read one issue by its name exactly as list gives it: e.g. 12-some-issue.md, never issues/12-some-issue.md. In the second turn, read every issue list gave, all in that one turn.")
2 (capability repo :repo "shop"
:list "List the crate's files. Rarely needed: the code is src/lib.rs, the tests are under tests/, the benchmark is bench/main.rs."
:read "Read a file of the crate by its path, e.g. src/lib.rs, tests/..., bench/main.rs. Read several in one turn."
:search "Search the crate's files for text."
:test "Run the crate's tests. Call it in the same turn as the edit it checks."
:bench "Run the benchmark (bench/main.rs, which you cannot change) and report elapsed_ns. Run it once for the baseline in the first turn, and again in the same turn as each rewrite and its tests. Before optimizing, find the loop that dominates its cost over the input sizes; after each rewrite, check every remaining loop, sorts included, and rewrite again if any costs more than about n log n."
:edit "Change a file under src/ or tests/ by replacing text that occurs once in it."
:write "Write a whole file under src/ or tests/, such as a new test file. To speed up a slow function, rewrite it whole once rather than tuning it piece by piece.")
(capability prs :spool "prs"
:send "Open a draft pull request: to is the branch it merges into, main; subject is its title; body is its description.")
; The issues are anyone's: read as untrusted, so a test run picked after
; reading one waits for you. The crate is ours.
(grant capability issues/list :kind tool)
(grant capability issues/read :kind tool)
(grant capability repo/list :kind tool :trusted)
(grant capability repo/read :kind tool :trusted)
(grant capability repo/search :kind tool :trusted)
(grant capability repo/test :kind tool :trusted)
(forbid flow * :to repo/test :ask)
(grant capability repo/bench :kind tool :trusted)
; The source and the tests, and nothing else of the crate.
(grant capability repo/edit :kind tool :scope "src/*" :trusted)
(grant capability repo/edit :kind tool :scope "tests/*" :trusted)
(grant capability repo/write :kind tool :scope "src/*" :trusted)
(grant capability repo/write :kind tool :scope "tests/*" :trusted)
; One pull request, to main, and it waits for you.
4 (grant capability prs/send :kind message :scope "main" :ask)
; Done: the tests pass; one of them fails against the source as it was;
; the report is ten times as fast and answers the same; one pull request.
5 (done (passes repo) (fails-before repo) (faster repo 10) (rows prs 1)))