Review

polish-loop

Polish rounds until the diff is stable, with three clear stop conditions.

Why this skill exists

One review round is not always sufficient: a fix can make a new problem, and a large function that the agent splits can still be too large. But "repeat until it is good" has no end, and each round costs time and money. This skill gives the loop a number to watch and three stop conditions. You know why it stopped.

When to use it

Use it when you want to polish a change until it is stable. The pr skill calls it by default.

  1. Interview. The round limit, and the questions of polish-once. The agent asks one time, before round 1.
  2. Baseline. The agent checks the scope one time and measures the quality score: the health of the change, from 0 to 100.
  3. Rounds. Each round is one polish-once. After each round, the loop tests the stop conditions in this order.
ConditionTestOutcome
StableThe round changed no file.STABLE
ScoreThe round changed files, and the score after the round is not higher than the score before it.SCORE
LimitThe round number is equal to the round limit.LIMIT

For LIMIT and SCORE, the result has a recommended next step and each finding that is not fixed, with the reason.

The interview from a real run

The recommended round limit was 5. The maintainer chose 2, to keep the cost of the example low: each round reads 52 files.

The request

Called by the pr skill: rounds=2 level=medium comments=yes base=origin/main.

The agent found these answers in the repo. It did not ask these questions.

  • Which review level do you want for each round?

    medium.

    Source The caller (pr) gives it; the maintainer chose it in the polish-once interview.

  • What is the round limit?

    2.

    Source The caller (pr) gives it; the maintainer chose it.

  • Do you want a commit and a comment after each round?

    yes. Case (b): each round makes one commit, writes round-<n>.md and prints it; no push.

    Source The caller (pr) gives it.

  • Which base do you want for the diff?

    origin/main (28deb79).

    Source The caller (pr) gives it.

A skip rule of the question bank removed these questions.

  • All four questions of the bank

    When a caller (pr) gives the arguments, ask nothing.

The maintainer saw these questions. The first option is the recommended one.

Question 1 of 1

What is the round limit for the polish loop on the switchyard design-skill change?

  • 5 Recommended

    It is sufficient for most changes, and the loop stops earlier when a round changes nothing or the score stops going up.

  • 2 Chosen

    A low budget: each round reads 52 files, so two rounds keep the cost of the example low.

  • 8

    For a large diff such as this one, when you want the best chance of a stable result.

The agent recorded these assumptions. Nobody answered them.

  • The round limit question was asked in the read-first phase of the chain, before the pr skill called the loop. In this run the loop itself asked nothing.
  • The loop baseline was measured two times. The first measurement ran while the unit tests ran: eslint gave no readable output (CQ-SIMP and CQ-BRANCH not measured, 21 broken limits) and the measurement included temporary test folders. The second, with a quiet tree, gave 63 and 33 broken limits, the same as the review.

The artifact from that run

The loop has no page of its own. Its result is the score of each round and one record for each round. The quality score went from 64 to 69 to 74, against a base score of 63.

  1. 64Before the loop
  2. 69After round 1
  3. 74After round 2

The loop stopped with the outcome LIMIT. The next step that the agent recommended: Add a browser test for the page script of a design, then run the loop again for packages/cli/src/design/player.ts.

These scores were computed again. The first run showed 63, then 68, then 74, and the direction of the report changed from DOWN to UP between two runs with the same base. This was a defect in the base score: the set of functions for the score before changed with each head, so the base was 70, 70 and 48. After the fix, the base score is 63 at each point, and the scores are 64, 69 and 74. The findings and the fixes are from the first rounds.

The rounds

RoundFindingsImportantNitFixedScoreCommit
1271981164 to 69debe71e
2241591069 to 7438a5b0f

The quality report of each point (base score: 63)

PointHeadHealthDirectionImportantNitGoodAccepted
Review6929aff64UP241550
After round 1debe71e69UP251496
After round 238a5b0f74UP512916

What round 1 fixed (11 of 27 findings)

  • packages/cli/src/design/player.ts:17 Simplify

    The three interfaces are gone. The page data type is now Analysis without the three fields that page.ts removes.

  • packages/cli/src/design/analyze.ts:717 Code quality

    Each job is now one function (readNotes, readReasons, checkEvents, checkActions, checkUi, checkHeader, checkedScxml, readTargets, runTours). analyzeDesign calls them in the same order, so the list of problems has the same order. It is now at complexity 13 and 57 lines, which is still above the limits.

  • packages/cli/src/design/analyze.ts:637 Code quality

    expectFailures now checks the expect of one step. The step function is at complexity 11.

  • packages/cli/src/index.ts:192 Code quality

    runDesign (packages/cli/src/index.ts:171) has the branch. run is at 17 and 54.

  • docs-app/designs/order/design.ts:8 Code quality

    The list is made from the members of Fulfilment.

  • packages/cli/src/design.ts:88 Code quality

    DESIGN_STATUSES is the one list. The type and the check (packages/cli/src/design/analyze.ts:338) use it.

  • docs-app/designs/order/design.ts:16 Code quality

    balance() has one if and one return for each state.

  • packages/interop/src/orm.ts:64 Code quality

    The state path is now a join of the parts that are not empty. The function is in the limit.

  • packages/cli/src/design/analyze.ts:705 Code review

    loadDesign now gives a DesignError with the path and the message. A new test (packages/cli/tests/design.test.ts:132) failed before the change.

  • packages/interop/src/orm.ts:171 Code review

    The constant name now goes through identifier(), which throws a clear error. A new test (packages/interop/tests/orm.test.ts:313) failed before the change.

  • packages/cli/src/design/analyze.ts:314 Security review

    The function refuses each link with a tab or a line break. A new test (packages/cli/tests/design.test.ts:255) failed before the change.

What round 2 fixed (10 of 24 findings)

  • packages/cli/src/design/analyze.ts:111 Simplify

    A Model object holds those values. Each check gets the model, and no function has more than three parameters.

  • packages/cli/src/design/docs.ts:100 Code quality

    It is now five functions: stateValue, namedEvents, decorators, readClass and visit. The largest has complexity 13 and 6 nested levels, which is still above the limits.

  • packages/cli/src/design/analyze.ts Code quality

    The JSDoc reader is in docs.ts, the SCXML writer in scxml.ts and the tour runner in tours.ts. analyze.ts has the checks and is below 400 code lines.

  • packages/cli/src/design/analyze.ts:224 Code quality

    checkSenders and checkParts have the two halves, and isJsonArray has the parse of data-args. Each one is in the limits.

  • packages/cli/src/design/scxml.ts:29 Code quality

    transition writes one transition, and the tag is one condition. The two functions are in the limits.

  • packages/cli/src/design/docs.ts:114 Code quality

    only() gives the one item of a list, or nothing.

  • packages/cli/src/index.ts:215 Code quality

    The option table is the constant OPTIONS, and formatOf selects the format. run now breaks no limit that the measurement reports.

  • packages/cli/src/design/commands.ts:29 Code quality

    checkWords has the check of the title and the owner. The function is in the limit.

  • docs-app/package.json:14 Code review

    The script calls node ../packages/cli/dist/cli.js. The script failed in this clone before the change, and it builds the two pages now.

  • .prettierignore:21 Code review

    .skillsaw/polish/ is in .prettierignore.

feat: design a machine as one interactive page

What and why

A team could not try a state machine before it built the screen. This change adds a design step: one page that runs the real machine with a rendered UI, a live chart, a live SCXML view and walkthroughs. The build runs each walkthrough as a check.

  • @switchyard-ts/cli: the commands switchyard design new, design check and design build make the page from three files: machine.ts, design.ts and ui.html.
  • @switchyard-ts/interop: toDrizzle, toPrisma and toRowCodec give a table, a model and the row functions for a server, with one state column for each region.
  • @switchyard-ts/skills: npx switchyard-skills also installs the switchyard-design skill and the rule .claude/rules/switchyard-state-machines.md.
  • The guide has a new page, "Design a machine", with two example designs: an order with a payment, and a text editor.

The work is the "Machine designs" section of SWITCHYARD_PLAN.md. It is not one of the numbered phases.

The risk is in the size: the page script (packages/cli/src/design/player.ts) has no test that runs it in a browser. The quality report in docs/quality/2026-12-02-feat-design-skill/ shows the health of the changed code and each finding of the review.

Checks
  • pnpm format:check && pnpm build && pnpm lint && pnpm typecheck && pnpm test
  • Decorators tested under both standard and legacy modes, if any changed: no decorator changed.
  • npx changeset added, if a published package changed: .changeset/design-skill.md.
  • SWITCHYARD_PLAN.md updated, if a decision changed: the "Machine designs" section.
Polish

Level medium, loop, 2 rounds, stopped at the round limit. The quality score went from 64 to 69 to 74. Round 1 (debe71e) fixed 11 of 27 findings, and round 2 (38a5b0f) fixed 10 of 24. The record of each round is in .skillsaw/polish/feat-design-skill/round-1.md and round-2.md.

Not fixed, for the maintainer: no test runs the page script of a design in a browser, and four of its functions are above the complexity limit.

Gates: pnpm format:check, pnpm lint, pnpm build and pnpm typecheck passed. pnpm test: 339 passed, 0 failed (Vitest), and 24 passed, 0 failed (script tests). pnpm test:ember: 16 passed, 0 failed.

Scores recomputed on 2026-12-02 with the fixed base score; the findings and fixes are from the original rounds.

Polish round 1 of 2 (level: medium)

Commit: debe71e. Quality score: 64 before, 69 after (up).

The round read each changed TypeScript source file in full. It skimmed the tests, ui.html, player.html, the Markdown files and the lock file. A row with more than one metric is one function that breaks more than one limit.

#PassSeverityLocationFindingRemediationState
1SimplifyImportantpackages/cli/src/design/player.ts:17The page script had its own copy of the graph types and of the page data type. The copy had type: string, so the compiler did not check === 'parallel'.The three interfaces are gone. The page data type is now Analysis without the three fields that page.ts removes.Fixed in debe71e
2SimplifyNitpackages/cli/src/design/page.ts:15The change has three functions that escape HTML text, in analyze.ts, page.ts and player.ts. Only one of them escapes the single quote.None.Not fixed: below the level
3SimplifyNitpackages/cli/src/design/commands.ts:63The text of a design with problems is made in two places, here and in page.ts:110.None.Not fixed: below the level
4SimplifyNitpackages/cli/src/design/player.ts:617The close button of a note clears noted and then shows a note for a path that no state has, which sets noted again.None.Not fixed: below the level
5Code qualityImportantpackages/cli/src/design/analyze.ts:717analyzeDesign did nine jobs in one body: complexity 115, 232 code lines, 7 nested levels, and too many statements for the linter.Each job is now one function (readNotes, readReasons, checkEvents, checkActions, checkUi, checkHeader, checkedScxml, readTargets, runTours). analyzeDesign calls them in the same order, so the list of problems has the same order. It is now at complexity 13 and 57 lines, which is still above the limits.Fixed in debe71e, in part
6Code qualityImportantpackages/cli/src/design/analyze.ts:637The step function of a tour had complexity 19.expectFailures now checks the expect of one step. The step function is at complexity 11.Fixed in debe71e, in part
7Code qualityImportantpackages/cli/src/index.ts:192run went from complexity 15 and 46 lines on the base to 21 and 67, because the design branch was in the same body.runDesign (packages/cli/src/index.ts:171) has the branch. run is at 17 and 54.Fixed in debe71e, in part
8Code qualityImportantdocs-app/designs/order/design.ts:8The timeline had its own list of the four fulfilment values as strings. A changed value in machine.ts gave no error and a timeline with no marks.The list is made from the members of Fulfilment.Fixed in debe71e
9Code qualityImportantpackages/cli/src/design.ts:88The three statuses of a design were in two places: the type, and a list in the check.DESIGN_STATUSES is the one list. The type and the check (packages/cli/src/design/analyze.ts:338) use it.Fixed in debe71e
10Code qualityImportantdocs-app/designs/order/design.ts:16The Balance text was a ternary chain with five levels over the payment state. The linter gave four findings for it.balance() has one if and one return for each state.Fixed in debe71e
11Code qualityImportantpackages/interop/src/orm.ts:64visit in tableOf was one step above the complexity limit (11).The state path is now a join of the parts that are not empty. The function is in the limit.Fixed in debe71e
12Code qualityImportantpackages/cli/src/design/analyze.ts:145visit in readDocs reads five kinds of code in one function: complexity 47, 63 code lines, 12 nested levels.None in this round.Not fixed: the round limit of one sitting; it is the first item of round 2
13Code qualityImportantpackages/cli/src/design/analyze.ts:257body in scxml has complexity 14.None.Not fixed: left for round 2
14Code qualityImportantpackages/cli/src/design/analyze.ts:222Two ternaries with two levels (lines 222 and 286).None.Not fixed: left for round 2
15Code qualityImportantpackages/cli/src/design/analyze.tsThe file has more than 400 code lines (575 before the round, 678 after it: the new functions have signatures and comments).None.Not fixed: a split of the file is a move of code that round 2 must decide
16Code qualityImportantpackages/cli/src/design/commands.ts:20newDesign has complexity 12. Each branch is one check of an input.None.Not fixed: left for round 2
17Code qualityImportantpackages/cli/src/design/player.ts:148Four functions of the page script are above the complexity limit: send (14, and 7 nested levels), drawUi (11), showNote (19) and drawXml (11). The file has 635 code lines.None.Not fixed: no test runs the page script, so a refactor has no check (see row 18)
18Code qualityImportantpackages/cli/src/design/player.ts:148No test loads the page. The page script can break with a green test run.None.Not fixed: the repo has no browser test for a built page; this needs a decision of the maintainer
19Code qualityImportantdocs-app/designs/order/design.ts:95Three ternaries with two levels in the order design (lines 95, 97, 105) and two in the text editor design (docs-app/designs/text-editor/design.ts:118).None.Not fixed: each one is short and reads well; the rule comes from the linter rules of skillsaw, and the linter config of the repo does not have it
20Code qualityNitdocs-app/designs/text-editor/design.tsThe file has 416 code lines against a limit of 400. Most lines are the steps of the walkthroughs.None.Not fixed: below the level
21Code qualityNitpackages/interop/src/orm.ts:238toRowCodec has 69 code lines. Most of them are the template of the source text that it generates.None.Not fixed: below the level
22Code qualityNitpackages/cli/src/design/page.ts:70The status key goes into the page with no escape. It is safe only because the check refuses an unknown status.None.Not fixed: below the level
23Code reviewImportantpackages/cli/src/design/analyze.ts:705When design.ts threw as it loaded, switchyard design check gave a stack trace from a cache file. The other commands print one message.loadDesign now gives a DesignError with the path and the message. A new test (packages/cli/tests/design.test.ts:132) failed before the change.Fixed in debe71e
24Code reviewImportantpackages/interop/src/orm.ts:171toDrizzle with the option table: '2024_orders' wrote source with a constant name that starts with a digit. That source does not compile.The constant name now goes through identifier(), which throws a clear error. A new test (packages/interop/tests/orm.test.ts:313) failed before the change.Fixed in debe71e
25Code reviewNitpackages/cli/src/design/analyze.ts:644A tour step that needs the page for its arguments gets a failure, and then the check calls the arguments function with no page. One cause can give two failures.None.Not fixed: below the level
26Security reviewImportantpackages/cli/src/design/analyze.ts:314isSafeLink accepted a link with a tab or a line break in its scheme. A browser removes those characters, so such a link can run script when a reader clicks it. The author of a design writes the links, thus this is not Critical.The function refuses each link with a tab or a line break. A new test (packages/cli/tests/design.test.ts:255) failed before the change.Fixed in debe71e
27Security reviewNitpackages/cli/src/design/analyze.ts:314A link that starts with // passes as a relative path, but it goes to a different host.None.Not fixed: below the level

Gates: pnpm format:check passed. pnpm lint passed. pnpm build passed. pnpm typecheck passed. Unit tests of the two changed packages (vitest run for @switchyard-ts/cli and @switchyard-ts/interop): 101 passed, 0 failed. The full pnpm test ran before the round: 332 passed and 4 failed, each by a timeout while the machine had a very high load.

An AI agent wrote this comment with the skillsaw polish-once skill.

Scores recomputed on 2026-12-02 with the fixed base score; the findings and fixes are from the original rounds.

Polish round 2 of 2 (level: medium)

Commit: 38a5b0f. Quality score: 69 before, 74 after (up).

The round read the code that round 1 changed, and each finding that round 1 did not fix. A row with more than one metric is one function that breaks more than one limit.

#PassSeverityLocationFindingRemediationState
1SimplifyImportantpackages/cli/src/design/analyze.ts:111The functions that round 1 made got the same five values in each call: the design, the graph, the states, the documents and the list of problems. Four of them had five parameters against a limit of four.A Model object holds those values. Each check gets the model, and no function has more than three parameters.Fixed in 38a5b0f
2SimplifyNitpackages/cli/src/design/page.ts:15Three functions escape HTML text, and only one escapes the single quote.None.Not fixed: below the level
3SimplifyNitpackages/cli/src/design/commands.ts:64The text of a design with problems is made in two places.None.Not fixed: below the level
4SimplifyNitpackages/cli/src/design/player.ts:617The close button of a note uses a path that no state has to clear the panel.None.Not fixed: below the level
5Code qualityImportantpackages/cli/src/design/docs.ts:100visit in readDocs had complexity 47, 63 code lines and 12 nested levels.It is now five functions: stateValue, namedEvents, decorators, readClass and visit. The largest has complexity 13 and 6 nested levels, which is still above the limits.Fixed in 38a5b0f, in part
6Code qualityImportantpackages/cli/src/design/analyze.tsThe file had 678 code lines and four jobs.The JSDoc reader is in docs.ts, the SCXML writer in scxml.ts and the tour runner in tours.ts. analyze.ts has the checks and is below 400 code lines.Fixed in 38a5b0f
7Code qualityImportantpackages/cli/src/design/analyze.ts:224The check of the UI bindings had complexity 19.checkSenders and checkParts have the two halves, and isJsonArray has the parse of data-args. Each one is in the limits.Fixed in 38a5b0f
8Code qualityImportantpackages/cli/src/design/scxml.ts:29body in scxml had complexity 14, and the tag of a state was a ternary with two levels.transition writes one transition, and the tag is one condition. The two functions are in the limits.Fixed in 38a5b0f
9Code qualityImportantpackages/cli/src/design/docs.ts:114The search for the document of a state path was a ternary with two levels.only() gives the one item of a list, or nothing.Fixed in 38a5b0f
10Code qualityImportantpackages/cli/src/index.ts:215run was at complexity 17 and 54 lines, above the base (15 and 46).The option table is the constant OPTIONS, and formatOf selects the format. run now breaks no limit that the measurement reports.Fixed in 38a5b0f
11Code qualityImportantpackages/cli/src/design/commands.ts:29newDesign had complexity 12.checkWords has the check of the title and the owner. The function is in the limit.Fixed in 38a5b0f
12Code qualityImportantpackages/cli/src/design/analyze.ts:376analyzeDesign has complexity 13 and 66 code lines. Round 2 added the Model object, which made it 9 lines longer.None.Not fixed: the body is the list of calls and the result object; a split of the result object gives no clearer code
13Code qualityImportantpackages/cli/src/design/analyze.ts:128Six check functions are 1 to 6 steps above the complexity limit: readNotes (16), readReasons (11), checkEvents (13), checkActions (12, and 7 nested levels), checkUi (13) and checkHeader (13). In tours.ts, the step function of a tour is at 11.None.Not fixed: each one is a list of checks with one branch for each rule, and the round limit is 2
14Code qualityImportantpackages/cli/src/design/player.ts:148Four functions of the page script are above the complexity limit, and the file has 635 code lines.None.Not fixed: no test runs the page script, so a refactor has no check
15Code qualityImportantpackages/cli/src/design/player.ts:148No test loads the page of a design.None.Not fixed: the repo has no browser test for a built page; this needs a decision of the maintainer
16Code qualityImportantdocs-app/designs/order/design.ts:95Five ternaries with two levels in the two example designs.None.Not fixed: each one is short and reads well, and the linter config of the repo does not have this rule
17Code qualityNitdocs-app/designs/text-editor/design.tsThe file has 416 code lines against a limit of 400. Most lines are the steps of the walkthroughs.None.Not fixed: below the level
18Code qualityNitpackages/interop/src/orm.ts:238toRowCodec has 69 code lines. Most of them are the template of the generated source.None.Not fixed: below the level
19Code qualityNitpackages/cli/src/design/page.ts:70The status key goes into the page with no escape.None.Not fixed: below the level
20Code reviewImportantdocs-app/package.json:14The designs script called the switchyard command by name. In a clone where the install ran before the first build, the command has no link, and pnpm --filter docs-app start stopped with "command not found".The script calls node ../packages/cli/dist/cli.js. The script failed in this clone before the change, and it builds the two pages now.Fixed in 38a5b0f
21Code reviewImportant.prettierignore:21The round comment of round 1 made pnpm format:check fail: the gate reads each Markdown file, and the comment table is not in the Prettier format..skillsaw/polish/ is in .prettierignore.Fixed in 38a5b0f
22Code reviewNitpackages/cli/src/design/tours.ts:79A tour step that needs the page for its arguments can give two failures for one cause.None.Not fixed: below the level
23Code reviewNitpackages/interop/src/orm.ts:171The error for a bad table name shows the constant name (2024Orders), not the table name that the caller gave.None.Not fixed: below the level
24Security reviewNitpackages/cli/src/design/analyze.ts:106A link that starts with // passes as a relative path, but it goes to a different host.None.Not fixed: below the level

The security review found no new Critical or Important finding. Round 2 added no input path, no dependency and no outside request.

Gates: pnpm format:check passed. pnpm lint passed. pnpm build passed. pnpm typecheck passed. pnpm test: 339 passed, 0 failed in Vitest, and 24 passed, 0 failed in the script tests. pnpm test:ember: 16 passed, 0 failed.

The loop stopped after round 2: the round number is equal to the round limit (2).

An AI agent wrote this comment with the skillsaw polish-once skill.

Scores recomputed on 2026-12-02 with the fixed base score; the findings and fixes are from the original rounds.

The quality report of each point is on the code-quality page.

The commands

git diff --shortstat origin/main...HEAD && git status --short   # the scope check of polish-once, one time
skillsaw quality measure --json --base origin/main   # baseline: score.after 64
polish-once round 1   # commit debe71e, score 64 to 69
polish-once round 2   # commit 38a5b0f, score 69 to 74; stop: LIMIT (round 2 of 2)

What we learned from this run

Config keys

All keys are optional. The agent reads these keys from .skillsaw/config.json. The CLI does not read them.

KeyDefaultMeaningWho reads it
polish.levelmediumThe default review level: low, medium or high.Agent: polish-once, polish-loop, pr
polish.rounds5The default round limit of polish-loop.Agent: polish-loop, pr
polish.commentsfalse (pr: true)true: each round makes a commit and posts a comment on the pull request, or writes it to .skillsaw/polish/ when there is no pull request.Agent: polish-once, polish-loop, pr
polish.gatesThe commands that the agent findsThe gate commands of the repo, as a list.Agent: polish-once
pr.baseThe default branch of the remoteThe base branch of the pull request and of the polish diff.Agent: pr, polish-once, polish-loop