diff --git a/.github/workflows/kompass-pr-review-comment.yml b/.github/workflows/kompass-pr-review-comment.yml new file mode 100644 index 0000000..a35fa80 --- /dev/null +++ b/.github/workflows/kompass-pr-review-comment.yml @@ -0,0 +1,55 @@ +name: Kompass PR Review Comment + +on: + issue_comment: + types: [created] + +jobs: + review: + if: github.event.issue.pull_request && startsWith(github.event.comment.body, '/review') && contains(fromJson('["OWNER","MEMBER"]'), github.event.comment.author_association) + runs-on: ubuntu-latest + steps: + - name: Generate GitHub App Token + id: token + uses: actions/create-github-app-token@v1 + with: + app-id: ${{ secrets.KOMPASS_APP_ID }} + private-key: ${{ secrets.KOMPASS_APP_PRIVATE_KEY }} + + - name: Get PR details + id: pr + env: + GH_TOKEN: ${{ steps.token.outputs.token }} + run: | + gh api /repos/${{ github.repository }}/pulls/${{ github.event.issue.number }} > pr_data.json + echo "head_repo=$(jq -r .head.repo.full_name pr_data.json)" >> "$GITHUB_OUTPUT" + echo "head_ref=$(jq -r .head.ref pr_data.json)" >> "$GITHUB_OUTPUT" + + - name: Checkout code + uses: actions/checkout@v4 + with: + repository: ${{ steps.pr.outputs.head_repo }} + ref: ${{ steps.pr.outputs.head_ref }} + fetch-depth: 0 + token: ${{ steps.token.outputs.token }} + + - name: Setup Bun + uses: oven-sh/setup-bun@v1 + with: + bun-version: latest + + - name: Install dependencies + run: bun install + + - name: Install Kompass Tooling + uses: ./.github/actions/kompass-opencode-install + + - name: Run Kompass PR Review + env: + GITHUB_TOKEN: ${{ steps.token.outputs.token }} + OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }} + run: opencode run --model="${{ vars.OPENCODE_MODEL }}" --variant="${{ vars.OPENCODE_VARIANT }}" --thinking --command="pr/review" "${{ github.event.issue.number }}" + + - name: Export Kompass Session + if: always() + uses: ./.github/actions/kompass-opencode-session-export diff --git a/.github/workflows/kompass-pr-review.yml b/.github/workflows/kompass-pr-review.yml index 2ed528e..0cf51a6 100644 --- a/.github/workflows/kompass-pr-review.yml +++ b/.github/workflows/kompass-pr-review.yml @@ -6,7 +6,7 @@ on: jobs: review: - if: github.event.pull_request.draft == false + if: github.event.pull_request.draft == false && github.event.pull_request.head.repo.full_name == github.repository runs-on: ubuntu-latest steps: - name: Generate GitHub App Token diff --git a/kompass.jsonc b/kompass.jsonc index 664c0df..9cad009 100644 --- a/kompass.jsonc +++ b/kompass.jsonc @@ -51,6 +51,7 @@ }, "components": { + "align-pr-branch": { "enabled": true }, "change-summary": { "enabled": true }, "changes-summary": { "enabled": true }, "commit": { "enabled": true }, diff --git a/kompass.schema.json b/kompass.schema.json index dc9620d..94a0647 100644 --- a/kompass.schema.json +++ b/kompass.schema.json @@ -215,6 +215,9 @@ "type": "object", "additionalProperties": false, "properties": { + "align-pr-branch": { + "$ref": "#/$defs/componentConfig" + }, "change-summary": { "$ref": "#/$defs/componentConfig" }, @@ -243,7 +246,7 @@ "type": "array", "items": { "type": "string", - "enum": ["change-summary", "changes-summary", "commit", "dev-flow", "load-pr", "load-ticket", "skill-authoring", "summarize-changes"] + "enum": ["align-pr-branch", "change-summary", "changes-summary", "commit", "dev-flow", "load-pr", "load-ticket", "skill-authoring", "summarize-changes"] }, "uniqueItems": true, "deprecated": true @@ -251,7 +254,7 @@ "paths": { "type": "object", "propertyNames": { - "enum": ["change-summary", "changes-summary", "commit", "dev-flow", "load-pr", "load-ticket", "skill-authoring", "summarize-changes"] + "enum": ["align-pr-branch", "change-summary", "changes-summary", "commit", "dev-flow", "load-pr", "load-ticket", "skill-authoring", "summarize-changes"] }, "additionalProperties": { "type": "string" diff --git a/packages/core/commands/pr/fix.md b/packages/core/commands/pr/fix.md index 24a97a8..846b05e 100644 --- a/packages/core/commands/pr/fix.md +++ b/packages/core/commands/pr/fix.md @@ -30,13 +30,7 @@ $ARGUMENTS ### Align Local Branch -- If `` is unavailable, STOP and report that the PR head branch could not be determined -- If `` differs from ``: - - Checkout `` before analyzing repository files or making code changes for this PR - - After checkout, store the active branch as `` - - If checkout fails, STOP and report that the PR branch could not be checked out locally -- Otherwise, store `` as `` -- Do not inspect or modify local code for this PR until `` equals `` +<%~ include("@align-pr-branch", { action: "analyzing repository files or making code changes for this PR", scope: "inspect or modify local code for this PR" }) %> ### Analyze Feedback diff --git a/packages/core/commands/pr/review.md b/packages/core/commands/pr/review.md index 01fbf7e..960b8d4 100644 --- a/packages/core/commands/pr/review.md +++ b/packages/core/commands/pr/review.md @@ -26,13 +26,7 @@ $ARGUMENTS ### Align Local Branch -- If `` is unavailable, STOP and report that the PR head branch could not be determined -- If `` differs from ``: - - Checkout `` before inspecting local repository files for this PR review - - After checkout, store the active branch as `` - - If checkout fails, STOP and report that the PR branch could not be checked out locally -- Otherwise, store `` as `` -- Do not inspect local repository code for this PR until `` equals `` +<%~ include("@align-pr-branch", { action: "inspecting local repository files for this PR review", scope: "inspect local repository code for this PR" }) %> ### Load Ticket Context diff --git a/packages/core/components/align-pr-branch.md b/packages/core/components/align-pr-branch.md new file mode 100644 index 0000000..ebabe6c --- /dev/null +++ b/packages/core/components/align-pr-branch.md @@ -0,0 +1,5 @@ +- If `` is unavailable, STOP and report that the PR head branch could not be determined +- Run `gh pr checkout ` before <%= it.action %> +- After checkout, store the active branch as `` +- If checkout fails, STOP and report that the PR branch could not be checked out locally +- Do not <%= it.scope %> until `` equals `` diff --git a/packages/core/kompass.jsonc b/packages/core/kompass.jsonc index 664c0df..9cad009 100644 --- a/packages/core/kompass.jsonc +++ b/packages/core/kompass.jsonc @@ -51,6 +51,7 @@ }, "components": { + "align-pr-branch": { "enabled": true }, "change-summary": { "enabled": true }, "changes-summary": { "enabled": true }, "commit": { "enabled": true }, diff --git a/packages/core/lib/config.ts b/packages/core/lib/config.ts index eda73a2..9537d0c 100644 --- a/packages/core/lib/config.ts +++ b/packages/core/lib/config.ts @@ -48,6 +48,7 @@ export const DEFAULT_COMMAND_NAMES = [ export const DEFAULT_AGENT_NAMES = ["worker", "navigator", "planner", "reviewer"] as const; export const DEFAULT_COMPONENT_NAMES = [ + "align-pr-branch", "change-summary", "changes-summary", "commit", @@ -129,6 +130,7 @@ export interface KompassConfig { ticket_load?: ToolConfig; }; components?: { + "align-pr-branch"?: ComponentConfig; "change-summary"?: ComponentConfig; "changes-summary"?: ComponentConfig; commit?: ComponentConfig; @@ -443,6 +445,7 @@ const defaultAgentPlanner: AgentDefinition = { }; const defaultComponentPaths: Record = { + "align-pr-branch": "components/align-pr-branch.md", "change-summary": "components/change-summary.md", "changes-summary": "components/changes-summary.md", "commit": "components/commit.md", diff --git a/packages/opencode/.opencode/commands/pr/fix.md b/packages/opencode/.opencode/commands/pr/fix.md index d940f8f..dcb2539 100644 --- a/packages/opencode/.opencode/commands/pr/fix.md +++ b/packages/opencode/.opencode/commands/pr/fix.md @@ -45,11 +45,9 @@ $ARGUMENTS ### Align Local Branch - If `` is unavailable, STOP and report that the PR head branch could not be determined -- If `` differs from ``: - - Checkout `` before analyzing repository files or making code changes for this PR - - After checkout, store the active branch as `` - - If checkout fails, STOP and report that the PR branch could not be checked out locally -- Otherwise, store `` as `` +- Run `gh pr checkout ` before analyzing repository files or making code changes for this PR +- After checkout, store the active branch as `` +- If checkout fails, STOP and report that the PR branch could not be checked out locally - Do not inspect or modify local code for this PR until `` equals `` ### Analyze Feedback diff --git a/packages/opencode/.opencode/commands/pr/review.md b/packages/opencode/.opencode/commands/pr/review.md index 8566573..0900457 100644 --- a/packages/opencode/.opencode/commands/pr/review.md +++ b/packages/opencode/.opencode/commands/pr/review.md @@ -41,11 +41,9 @@ $ARGUMENTS ### Align Local Branch - If `` is unavailable, STOP and report that the PR head branch could not be determined -- If `` differs from ``: - - Checkout `` before inspecting local repository files for this PR review - - After checkout, store the active branch as `` - - If checkout fails, STOP and report that the PR branch could not be checked out locally -- Otherwise, store `` as `` +- Run `gh pr checkout ` before inspecting local repository files for this PR review +- After checkout, store the active branch as `` +- If checkout fails, STOP and report that the PR branch could not be checked out locally - Do not inspect local repository code for this PR until `` equals `` ### Load Ticket Context diff --git a/packages/opencode/kompass.jsonc b/packages/opencode/kompass.jsonc index 664c0df..9cad009 100644 --- a/packages/opencode/kompass.jsonc +++ b/packages/opencode/kompass.jsonc @@ -51,6 +51,7 @@ }, "components": { + "align-pr-branch": { "enabled": true }, "change-summary": { "enabled": true }, "changes-summary": { "enabled": true }, "commit": { "enabled": true }, diff --git a/packages/web/src/content/docs/docs/reference/components/align-pr-branch.mdx b/packages/web/src/content/docs/docs/reference/components/align-pr-branch.mdx new file mode 100644 index 0000000..ab4d956 --- /dev/null +++ b/packages/web/src/content/docs/docs/reference/components/align-pr-branch.mdx @@ -0,0 +1,12 @@ +--- +title: align-pr-branch +description: Shared partial for aligning PR-scoped commands to the pull request branch. +--- + +## Behavior + +- requires the caller to provide `` +- runs `gh pr checkout ` before local PR analysis or edits +- stores the active branch as `` after checkout +- stops if checkout fails or if the active branch does not match `` +- accepts caller-provided wording through `it.action` and `it.scope` diff --git a/packages/web/src/content/docs/docs/reference/components/index.mdx b/packages/web/src/content/docs/docs/reference/components/index.mdx index b756ad4..faf18d1 100644 --- a/packages/web/src/content/docs/docs/reference/components/index.mdx +++ b/packages/web/src/content/docs/docs/reference/components/index.mdx @@ -7,6 +7,7 @@ Kompass command templates can include reusable Eta partials from `packages/core/ Bundled components: +- `align-pr-branch` - `change-summary` - `changes-summary` - `commit` @@ -18,6 +19,10 @@ Bundled components: ## Bundled components +### `align-pr-branch` + +Guides PR-scoped commands to switch onto the PR head branch with `gh pr checkout`, capture the active branch, and stop if local work is not aligned to the PR branch. + ### `change-summary` Loads changes with `changes_load`, analyzes file-level diffs, and groups the work into concise what/why themes.