Skip to content

Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.

fix(chanakya): guard /chanakya fix against false completions

Rishabh Bajpai6e0efb20dc5c
diff --git a/.github/workflows/chanakya.yml b/.github/workflows/chanakya.yml
index 0caa1c8..3cec3be 100644
--- a/.github/workflows/chanakya.yml
+++ b/.github/workflows/chanakya.yml
@@ -275,6 +275,12 @@ jobs:
with:
fetch-depth: 0
persist-credentials: false
+ - name: Capture base state
+ id: base
+ run: |
+ echo "base_ref=$(git rev-parse --abbrev-ref HEAD)" >> "$GITHUB_OUTPUT"
+ echo "base_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
+ echo "is_pr=${{ github.event.issue.pull_request != null && 'true' || 'false' }}" >> "$GITHUB_OUTPUT"
- name: Chanakya fix
run: |
export HOME="${CHANAKYA_HOME:-$HOME}"
@@ -305,8 +311,73 @@ jobs:
5. Never introduce secrets, hardcoded credentials, or unsafe patterns; prefer safe APIs.
6. If the request is ambiguous or implies product decisions, implement the most reasonable interpretation and clearly note any assumptions you made.
+ ### COMPLETION REQUIREMENT (MANDATORY)
+ Stopping after exploration/analysis and posting only a plan or a scoping note is a FAILURE. A `/chanakya fix` run is complete ONLY when ALL of these hold:
+ 1. Your implemented changes exist in the working tree.
+ 2. They are committed and pushed — to a new `opencode/issue<#>-<timestamp>` branch for issue triggers, or directly to the PR's branch for PR triggers.
+ 3. A pull request is open.
+ If scope is uncertain, implement the most reasonable interpretation and note your assumptions — do NOT stop to ask or stop after analyzing. If you genuinely cannot make the change, say so explicitly in your final reply, but treat that as an exceptional outcome.
+
### REPORT
When done, post a concise summary of: what you changed, the files touched, how you verified it, and any follow-ups or assumptions.
+ - name: Verify changes were actually delivered
+ env:
+ GITHUB_TOKEN: ${{ github.token }}
+ run: |
+ set -euo pipefail
+ BASE_REF="${{ steps.base.outputs.base_ref }}"
+ BASE_SHA="${{ steps.base.outputs.base_sha }}"
+ IS_PR="${{ steps.base.outputs.is_pr }}"
+ CUR="$(git rev-parse --abbrev-ref HEAD)"
+ HEAD_SHA="$(git rev-parse HEAD)"
+
+ echo "::group::Chanakya delivery verification"
+ echo "base_ref=$BASE_REF base_sha=$BASE_SHA is_pr=$IS_PR"
+ echo "current_branch=$CUR head_sha=$HEAD_SHA"
+
+ branch_http() {
+ curl -sS -o /dev/null -w "%{http_code}" \
+ -H "Authorization: Bearer ${GITHUB_TOKEN}" \
+ -H "Accept: application/vnd.github+json" \
+ "https://api.github.com/repos/${GITHUB_REPOSITORY}/branches/$1"
+ }
+
+ if [[ "$IS_PR" == "true" ]]; then
+ if [[ "$HEAD_SHA" == "$BASE_SHA" ]]; then
+ echo "::error::Chanakya finished without producing any commit (HEAD unchanged at ${BASE_SHA}). Run reported success but delivered nothing."
+ echo "::endgroup::"
+ exit 1
+ fi
+ echo "OK: PR branch advanced ${BASE_SHA} -> ${HEAD_SHA}"
+ echo "::endgroup::"
+ exit 0
+ fi
+
+ if [[ "$CUR" == "$BASE_REF" ]]; then
+ echo "::error::Chanakya finished without creating a branch (still on '${CUR}'). No code was written — false completion, no PR produced. Re-run '/chanakya fix'."
+ echo "::endgroup::"
+ exit 1
+ fi
+
+ HTTP=$(branch_http "$CUR")
+ if [[ "$HTTP" != "200" ]]; then
+ echo "::error::Branch '${CUR}' exists locally but was never pushed to origin (branch API returned ${HTTP}). Changes were not delivered."
+ echo "::endgroup::"
+ exit 1
+ fi
+
+ PR_COUNT=$(curl -sS -H "Authorization: Bearer ${GITHUB_TOKEN}" \
+ -H "Accept: application/vnd.github+json" \
+ "https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls?head=${GITHUB_REPOSITORY%%/*}:${CUR}&state=open" \
+ | grep -o '"number"' | wc -l | tr -d ' ' || true)
+ if [[ "$PR_COUNT" == "0" ]]; then
+ echo "::error::Branch '${CUR}' was pushed but no open pull request exists for it. Run reported success but the PR deliverable is missing."
+ echo "::endgroup::"
+ exit 1
+ fi
+
+ echo "OK: branch '${CUR}' pushed and ${PR_COUNT} open PR(s) found — changes delivered."
+ echo "::endgroup::"
# ── /chanakya <free text> ─────────────────────────────────────────────────
general: