Add kai findings run to trigger a review for a PR - #39
Open
AdamT wants to merge 1 commit into
Open
Conversation
Starts the exact review a GitHub webhook would start, from a laptop (or an
agent acting on a developer's behalf), against any kai-server — without
waiting for GitHub to deliver a webhook. Pairs with the new
POST /api/v1/orgs/{org}/repos/{repo}/reviews endpoint in kai-server.
kai findings run --pr 123
kai findings run --pr https://github.com/kaicontext/kai-server/pull/123
kai findings run --pr 123 --repo kai/kai-server --wait
--pr takes a bare number or a full GitHub PR URL. The URL form is the
reason github_repository is sent separately from --repo: the kai identity
(org/repo, which routes the API call) and the real GitHub owner/repo (which
the pod clones) can differ, so the URL's repo is authoritative for the
review target and never overridden by the origin remote.
Lands under `kai findings` rather than `kai review`, which is already taken
by changeset reviews — an unrelated concept.
findingsAPIPost is a POST sibling to findingsAPIGet with the same 401/403/
404 mapping, plus 409 and 422 surfaced verbatim so the server's "no review
workflow matched" guidance reaches the user unreworded. It returns the raw
body alongside the error because the 409 carries a run_id worth showing.
A 409 is deliberately NOT a failure: the review the caller wanted is
already running, so we report it and --wait watches the existing run. Every
genuine failure path returns a non-nil error with non-empty stderr and a
non-zero exit — a CLI must not inherit the pipeline's log-and-continue
habit, so the tests are table-driven over exactly that.
--wait polls the existing runs/{id} endpoint and exits non-zero if the run
concludes anything but success; a dedicated status endpoint can replace the
poll later without changing this command's UX.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015ruiguUJAqw6zhfGxgdut6
Kai review✅ Ready to merge — intent verified, nothing flagged.
+570 −2 · 2 files · reaches 1 View finding → · Awaiting your verdict — Kai never approves its own finding. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Starts the exact review a GitHub webhook would start for a PR — from a laptop (or an agent acting on a developer's behalf), against any kai-server — without waiting for GitHub to deliver a webhook.
Implements Task 6 of
temp_adam_tasks/local-review/01-trigger-review-api.md.Note
Depends on kaicontext/kai-server#69, which adds the
POST /api/v1/orgs/{org}/repos/{repo}/reviewsendpoint this calls. Merge that first — until it lands, this command gets a 404.Usage
kai findings run --pr 123 kai findings run --pr https://github.com/kaicontext/kai-server/pull/123 kai findings run --pr 123 --repo kai/kai-server --wait # the whole point of the initiative: KAI_SERVER=http://localhost:8080 kai findings run --pr 123 --repo demo/hello-kai --waitLands under
kai findingsrather thankai review, which is already taken by changeset reviews — an unrelated concept.Details worth a look
--prtakes a bare number or a full GitHub PR URL. The URL form is whygithub_repositoryis sent separately from--repo: the kai identity (org/repo, which routes the API call) and the real GitHubowner/repo(which the pod clones) can differ. So the URL's repo is authoritative for the review target and is never overridden by theoriginremote.findingsAPIPostis a POST sibling tofindingsAPIGetwith the same 401/403/404 mapping, plus 409 and 422 surfaced verbatim — the server's "no review workflow matched" guidance reaches the user unreworded. It returns the raw body alongside the error because the 409 carries arun_idworth showing.A 409 is deliberately not a failure. The review the caller wanted is already running, so we report it and — with
--wait— watch the existing run rather than erroring.--waitpolls the existingruns/{id}endpoint and exits non-zero if the run concludes anything but success. A dedicated status endpoint can replace the poll later without changing this command's UX.Testing
Every genuine failure path returns a non-nil error with non-empty stderr and a non-zero exit — a CLI must not inherit the pipeline's log-and-continue habit, so the tests are table-driven over exactly that. Coverage includes both
--prforms (asserting the URL form populatesgithub_repositoryfrom the URL, not the remote), the full status-code matrix against a fake control plane, and--waitreturning an error when the run concludesfailureeven though the trigger itself succeeded.Full
kai-clisuite passes.🤖 Generated with Claude Code
https://claude.ai/code/session_015ruiguUJAqw6zhfGxgdut6