simplify-code
Simplify Code
Review code for scope, reuse, quality, efficiency, clarity, and altitude issues, then fix them.
Step 1: Determine the Scope
Determine what to review:
- If a specific diff command was provided (e.g.,
git diff --cached), use that. - If a file list or directory was provided, review those files directly (read the full files, not a diff).
- If neither was provided, determine the appropriate diff command (e.g.,
git diff,git diff --cached,git diff HEAD) based on the current git state. When the branch is an open pull request, resolve its base withgh pr view --json baseRefName --jq '.baseRefName', rungit fetch origin <base-branch>, and diff againstorigin/<base-branch>...HEAD: a local branch of the same name can sit behind the remote, which puts the merge base before an already-merged pull request and pulls merged work into the scope. If there are no git changes, review the most recently modified files mentioned in the conversation.
State the resolved file list before launching the agents: add --name-only to a diff command, or list the files for a file or directory scope.
Step 2: Launch Six Review Agents in Parallel
Launch all six agents below with spawn_agent / wait_agent using inherited model defaults, issuing every call in one batch. Do not issue one and await its result before issuing the rest. Pass the scope from Step 1 to each agent. Every sub-agent's prompt must direct it to treat the shared working tree and its git index as read-only and to reach its findings by reading and reasoning; fixes happen in Step 3. For an empirical check that verifies a finding, the agent works in a copy of the checkout created at a uniquely named path of its own under $TMPDIR. Refer to that copy by absolute path in every command and join chained steps with &&, so a failed step cannot leave the rest running in the shared checkout. Give that copy its own dependency install rather than reaching the shared tree's install by any route. When its own install is not possible, the check is left unrun and reported as such. Before reporting, the agent deletes that copy, its dependency install included, as a command of its own, and confirms the path no longer exists. A copy it could not delete is named by path in its report. HEAD stays where it is: read other refs with git show <ref>:<path> rather than git checkout or git switch. Direct each agent to write its full findings to a file named for its review followed by a random tag, under $TMPDIR, and to return that path with its report, so a compaction before Step 3 leaves the findings recoverable.
Confine the sub-agent's prompt to what to review, plus the conventions and factual properties that bear on it. Pass a property of the existing code as a fact the sub-agent weighs, such as "the retry loop guards a dependency known to fail intermittently". Leave out any statement that tells the sub-agent what verdict to reach about that property, such as "the duplication here is intentional for readability, judge against that", because it binds the sub-agent to accept the very property the review exists to assess.