Repository navigation
feat(actions): add provider command library #278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| { | ||
| "schema_version": 1, | ||
| "defaults": { | ||
| "requested_by": "OPERATOR", | ||
| "execution_order": ["provider_control", "documented_command"], | ||
| "require_current_head_sha": true | ||
| }, | ||
| "providers": { | ||
| "coderabbit": { | ||
| "authors": ["coderabbitai[bot]", "coderabbitai"], | ||
| "commands": { | ||
| "review_incremental": { | ||
| "effect": "review_request", | ||
| "requires_confirm_branch_write": false, | ||
| "documented_command": "@coderabbitai review", | ||
| "control": { | ||
| "comment_kind": "issue_comment", | ||
| "labels": ["🔍 Trigger review", "Trigger review"] | ||
| } | ||
| }, | ||
| "review_full": { | ||
| "effect": "review_request", | ||
| "requires_confirm_branch_write": false, | ||
| "documented_command": "@coderabbitai full review", | ||
| "control": { | ||
| "comment_kind": "issue_comment", | ||
| "labels": ["🔍 Trigger review", "Trigger review"] | ||
| } | ||
| }, | ||
| "autofix_current": { | ||
| "effect": "branch_write", | ||
| "requires_confirm_branch_write": true, | ||
| "documented_command": "@coderabbitai autofix", | ||
| "control": { | ||
| "comment_kind": "issue_comment", | ||
| "labels": ["Push a commit to this branch"] | ||
| } | ||
| }, | ||
| "autofix_stacked": { | ||
| "effect": "stacked_pull_request", | ||
| "requires_confirm_branch_write": true, | ||
| "documented_command": "@coderabbitai autofix stacked pr", | ||
| "control": { | ||
| "comment_kind": "issue_comment", | ||
| "labels": ["Create a new PR with the fixes", "Create stacked PR"] | ||
| } | ||
| }, | ||
| "fix_ci_current": { | ||
| "effect": "branch_write", | ||
| "requires_confirm_branch_write": true, | ||
| "documented_command": "@coderabbitai fix-ci commit", | ||
| "control": { | ||
| "comment_kind": "issue_comment", | ||
| "labels": ["Commit on current branch"] | ||
| } | ||
| }, | ||
| "fix_ci_stacked": { | ||
| "effect": "stacked_pull_request", | ||
| "requires_confirm_branch_write": true, | ||
| "documented_command": "@coderabbitai fix-ci", | ||
| "control": { | ||
| "comment_kind": "issue_comment", | ||
| "labels": ["Create stacked PR"] | ||
| } | ||
| }, | ||
| "resolve_merge_conflict": { | ||
| "effect": "branch_write", | ||
| "requires_confirm_branch_write": true, | ||
| "documented_command": "@coderabbitai resolve merge conflict", | ||
| "control": { | ||
| "comment_kind": "issue_comment", | ||
| "labels": ["Resolve merge conflicts", "Resolve Merge Conflicts"] | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "qodo": { | ||
| "authors": ["qodo-code-review[bot]", "qodo-code-review", "qodo"], | ||
| "commands": { | ||
| "review": { | ||
| "effect": "review_request", | ||
| "requires_confirm_branch_write": false, | ||
| "documented_command": "/agentic_review" | ||
| } | ||
| } | ||
| }, | ||
| "devin": { | ||
| "authors": ["devin-ai-integration[bot]", "devin-ai-integration", "devin"], | ||
| "commands": { | ||
| "review": { | ||
| "effect": "review_request", | ||
| "requires_confirm_branch_write": false, | ||
| "documented_command": "/devin review" | ||
| }, | ||
| "autofix_enablement": { | ||
| "effect": "provider_configuration", | ||
| "dispatchable": false, | ||
| "requires_confirm_branch_write": false, | ||
| "documented_command": null, | ||
| "requires_provider_setting": "Devin Review Auto-Fix and trusted-bot response policy" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,223 @@ | ||
| name: Provider command dispatch | ||
|
|
||
| # Executes only explicit, allowlisted provider operations. The library is read | ||
| # from the trusted default branch, never from a pull-request head. | ||
|
qodo-code-review[bot] marked this conversation as resolved.
Resolved
Comment on lines
+1
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. Missing sentinel/pr0b3 ci jobs This PR adds a new GitHub Actions workflow but the repository CI configuration does not include required Sentinel and Pr0b3 scanning jobs. This violates the requirement that automated security scanners must pass before merging deployment/integration configuration changes. Agent Prompt
|
||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| pr_number: | ||
| description: Open pull-request number | ||
| required: true | ||
| type: string | ||
| provider: | ||
| description: Provider key from .github/agentic/provider-command-library.json | ||
| required: true | ||
| type: choice | ||
| options: [coderabbit, qodo, devin] | ||
| action: | ||
| description: Allowlisted provider action | ||
| required: true | ||
| type: string | ||
| head_sha: | ||
| description: Required current pull-request head SHA | ||
| required: true | ||
| type: string | ||
| confirm_branch_write: | ||
| description: Required for actions that can commit or create a stacked PR | ||
| required: false | ||
| default: false | ||
| type: boolean | ||
| repository_dispatch: | ||
| types: [provider-command] | ||
|
|
||
| concurrency: | ||
| group: provider-command-${{ github.event.inputs.pr_number || github.event.client_payload.pr_number || github.run_id }}-${{ github.event.inputs.provider || github.event.client_payload.provider || 'unknown' }}-${{ github.event.inputs.action || github.event.client_payload.action || 'unknown' }} | ||
| cancel-in-progress: false | ||
|
|
||
| permissions: {} | ||
|
|
||
| jobs: | ||
| dispatch: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
| permissions: | ||
| contents: read | ||
| issues: write | ||
| pull-requests: write | ||
| steps: | ||
| - name: Execute allowlisted provider command | ||
| uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0 | ||
| env: | ||
| OPERATOR_EXECUTOR_LOGINS: ${{ vars.OPERATOR_EXECUTOR_LOGINS || github.repository_owner }} | ||
| OPERATOR_COMMAND_ACTIONS: ${{ vars.OPERATOR_COMMAND_ACTIONS || 'coderabbit:review_incremental,coderabbit:review_full,coderabbit:autofix_current,coderabbit:autofix_stacked,coderabbit:fix_ci_current,coderabbit:fix_ci_stacked,coderabbit:resolve_merge_conflict,qodo:review,devin:review' }} | ||
| INPUT_PR_NUMBER: ${{ github.event.inputs.pr_number || github.event.client_payload.pr_number }} | ||
| INPUT_PROVIDER: ${{ github.event.inputs.provider || github.event.client_payload.provider }} | ||
| INPUT_ACTION: ${{ github.event.inputs.action || github.event.client_payload.action }} | ||
| INPUT_HEAD_SHA: ${{ github.event.inputs.head_sha || github.event.client_payload.head_sha }} | ||
| INPUT_CONFIRM_BRANCH_WRITE: ${{ github.event.inputs.confirm_branch_write || github.event.client_payload.confirm_branch_write || 'false' }} | ||
| with: | ||
| github-token: ${{ secrets.ARCHWIZ_GITHUB_TOKEN || secrets.OPERATOR_GITHUB_TOKEN || secrets.OPERATOR_TOKEN || github.token }} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 4. Devin fallback cannot trigger The token chain allows github.token to post /devin review without verifying that the commenting identity is linked to Devin, although the recorded provider contract requires a linked account with repository write access. The workflow can therefore create a successful dispatch receipt while Devin ignores the command. Agent Prompt
|
||
| script: | | ||
| const prNumberRaw = (process.env.INPUT_PR_NUMBER || '').trim(); | ||
| const provider = (process.env.INPUT_PROVIDER || '').trim().toLowerCase(); | ||
| const action = (process.env.INPUT_ACTION || '').trim().toLowerCase(); | ||
| const requestedSha = (process.env.INPUT_HEAD_SHA || '').trim(); | ||
| const confirmBranchWrite = String(process.env.INPUT_CONFIRM_BRANCH_WRITE).toLowerCase() === 'true'; | ||
| const marker = '<!-- operator-provider-command:v1 -->'; | ||
| const operatorLogins = new Set((process.env.OPERATOR_EXECUTOR_LOGINS || "") | ||
| .split(",").map(value => value.trim().toLowerCase()).filter(Boolean)); | ||
| const receiptAuthors = new Set([...operatorLogins, "github-actions[bot]"]); | ||
| const actorLogin = (context.actor || "").trim().toLowerCase(); | ||
| const allowedActions = new Set((process.env.OPERATOR_COMMAND_ACTIONS || '') | ||
| .split(',').map(value => value.trim().toLowerCase()).filter(Boolean)); | ||
| if (!prNumberRaw || !provider || !action || !requestedSha) { | ||
| core.setFailed('pr_number, provider, action, and head_sha are required.'); | ||
| return; | ||
| } | ||
| if (!operatorLogins.has(actorLogin)) { | ||
| core.setFailed(`Dispatch actor ${context.actor || "unknown"} is not in OPERATOR_EXECUTOR_LOGINS.`); | ||
| return; | ||
| } | ||
| if (!/^\d+$/.test(prNumberRaw)) { | ||
| core.setFailed('pr_number must be a positive decimal integer.'); | ||
| return; | ||
| } | ||
| const prNumber = Number(prNumberRaw); | ||
| if (!Number.isSafeInteger(prNumber) || prNumber <= 0) { | ||
| core.setFailed('pr_number must be a positive safe integer.'); | ||
| return; | ||
| } | ||
| if (!allowedActions.has(`${provider}:${action}`)) { | ||
| core.setFailed(`${provider}:${action} is not in OPERATOR_COMMAND_ACTIONS.`); | ||
| return; | ||
| } | ||
|
|
||
| const defaultBranch = context.payload.repository.default_branch; | ||
| const { data: libraryContent } = await github.rest.repos.getContent({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| path: '.github/agentic/provider-command-library.json', | ||
| ref: defaultBranch, | ||
| }); | ||
| if (Array.isArray(libraryContent) || !libraryContent.content) { | ||
| core.setFailed('Trusted provider command library is unavailable.'); | ||
| return; | ||
| } | ||
| const library = JSON.parse(Buffer.from(libraryContent.content, 'base64').toString('utf8')); | ||
| const providerEntry = library.providers?.[provider]; | ||
| const command = providerEntry?.commands?.[action]; | ||
| if (!providerEntry || !command) { | ||
| core.setFailed(`No library entry exists for ${provider}:${action}.`); | ||
| return; | ||
| } | ||
| if (command.dispatchable === false) { | ||
| core.setFailed(`${provider}:${action} requires provider-side configuration and is not dispatchable.`); | ||
| return; | ||
| } | ||
| if (command.requires_confirm_branch_write && !confirmBranchWrite) { | ||
| core.setFailed(`${provider}:${action} can modify a branch; confirm_branch_write=true is required.`); | ||
| return; | ||
| } | ||
|
|
||
| const { data: pr } = await github.rest.pulls.get({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| pull_number: prNumber, | ||
| }); | ||
| if (pr.state !== 'open') { | ||
| core.setFailed(`PR #${prNumber} is not open.`); | ||
| return; | ||
| } | ||
| if (pr.head.sha !== requestedSha) { | ||
| core.setFailed(`Stale head SHA: expected ${requestedSha}, current ${pr.head.sha}.`); | ||
| return; | ||
| } | ||
| const comments = await github.paginate(github.rest.issues.listComments, { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: prNumber, | ||
| per_page: 100, | ||
| }); | ||
| const alreadyRecorded = comments.some(comment => { | ||
| const author = (comment.user?.login || '').toLowerCase(); | ||
| return comment.body?.includes(marker) && | ||
| comment.body.includes('dispatch_receipt: true') && | ||
| comment.body.includes(`head_sha: ${requestedSha}`) && | ||
| comment.body.includes(`provider: ${provider}`) && | ||
| comment.body.includes(`action: ${action}`) && | ||
| (receiptAuthors.has(author) || providerEntry.authors.includes(author)); | ||
| }); | ||
| if (alreadyRecorded) { | ||
| core.info(`Already dispatched ${provider}:${action} for ${requestedSha}.`); | ||
| return; | ||
| } | ||
|
|
||
| const result = { mode: 'documented_command', control_id: null, source_comment_id: null }; | ||
| const labels = command.control?.labels || []; | ||
| if (command.control?.comment_kind === 'issue_comment' && labels.length) { | ||
| for (const comment of comments) { | ||
| const author = (comment.user?.login || '').toLowerCase(); | ||
| if (!providerEntry.authors.includes(author) || !comment.body) continue; | ||
| const checkboxes = [...comment.body.matchAll(/^- \[ \] (<!--\s*\{"checkboxId":"([^"]+)"\}\s*-->)\s*(.+)$/gm)]; | ||
| const checkbox = checkboxes.find(candidate => labels.includes(candidate[3].trim())); | ||
|
Comment on lines
+162
to
+163
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3. Stale controls get activated The dispatcher searches every historical provider comment and selects a matching unchecked checkbox without checking the comment's SHA, timestamp, or active review cycle. A stale control can be patched successfully and suppress the documented-command fallback even when the provider no longer treats that control as actionable. Agent Prompt
Comment on lines
+162
to
+163
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 5. Control parser rejects valid checkboxes The checkbox regex requires "checkboxId":"..." with no whitespace after the colon, but existing CodeRabbit controls use "checkboxId": "..."; consequently no declared CodeRabbit control matches and every such dispatch falls back to posting the documented command. This defeats the workflow’s configured provider-control route and records a documented-command execution instead of activating the existing control. Agent Prompt
|
||
| if (!checkbox) continue; | ||
| const updatedBody = [ | ||
| comment.body.replace(checkbox[0], `- [x] ${checkbox[1]} ${checkbox[3]}`), | ||
| '', | ||
| marker, | ||
| 'dispatch_receipt: true', | ||
| `head_sha: ${requestedSha}`, | ||
| `provider: ${provider}`, | ||
| `action: ${action}`, | ||
| `effect: ${command.effect}`, | ||
| 'request_actor: OPERATOR', | ||
| 'execution: provider_control_patch', | ||
| `control_id: ${checkbox[2]}`, | ||
| `source_comment_id: ${comment.id}`, | ||
| ].join('\n'); | ||
| try { | ||
| await github.rest.issues.updateComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| comment_id: comment.id, | ||
| body: updatedBody, | ||
| }); | ||
| result.mode = 'provider_control_patch'; | ||
| result.control_id = checkbox[2]; | ||
| result.source_comment_id = comment.id; | ||
| core.info(`Activated ${provider}:${action} control ${checkbox[2]}.`); | ||
| break; | ||
| } catch (error) { | ||
| core.warning(`Control patch for ${provider}:${action} failed: ${error.message}; using documented command.`); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (result.mode === 'documented_command' && command.documented_command) { | ||
| const { data: receipt } = await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: prNumber, | ||
| body: [ | ||
| command.documented_command, | ||
| '', | ||
| marker, | ||
| 'dispatch_receipt: true', | ||
| `head_sha: ${requestedSha}`, | ||
| `provider: ${provider}`, | ||
| `action: ${action}`, | ||
| `effect: ${command.effect}`, | ||
| 'request_actor: OPERATOR', | ||
| 'execution: documented_command', | ||
| 'control_id: none', | ||
|
Comment on lines
+210
to
+213
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. Receipt lacks actor attribution Receipts hard-code request_actor: OPERATOR instead of recording context.actor, so audits cannot attribute which allowed operator initiated a dispatch even though the docs claim an "attributable receipt". Agent Prompt
|
||
| 'source_comment_id: none', | ||
| '', | ||
| 'Autonomous allowlisted provider-command request and receipt. Provider completion remains independently verifiable.', | ||
| ].join('\n'), | ||
| }); | ||
| result.source_comment_id = receipt.id; | ||
| } else if (result.mode === 'documented_command') { | ||
| core.setFailed(`${provider}:${action} requires provider configuration and has no GitHub command fallback.`); | ||
| return; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2. Review modes share control
🐞 Bug≡ CorrectnessAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools