Skip to content

feat(token-optimizer): migrate prompt to gh-proxy mode with bash+jq efficiency guidance#29415

Merged
pelikhan merged 1 commit intomainfrom
copilot/update-token-optimizer-workflow
May 1, 2026
Merged

feat(token-optimizer): migrate prompt to gh-proxy mode with bash+jq efficiency guidance#29415
pelikhan merged 1 commit intomainfrom
copilot/update-token-optimizer-workflow

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 1, 2026

The token optimizer workflow prompt still referenced vague "cli-proxy" guidance and lacked concrete instructions for token-efficient GitHub API access, despite the frontmatter already declaring mode: gh-proxy.

Changes

  • New "Data Access Guidelines" section — explicitly declares no GitHub MCP tools are available; provides / examples showing gh api --jq filtering vs. loading full unfiltered payloads into context:

    # ✅ Extract only needed fields
    gh api "repos/$REPO/actions/workflows/my-workflow.yml/runs?per_page=10" \
      --jq '.workflow_runs[] | {id, name, conclusion, run_started_at}'
    
    # ❌ Drops entire response into context
    gh api "repos/$REPO/actions/workflows/my-workflow.yml/runs"
  • Phase 2 analysis matrix — "Tool usage" row now references gh api --jq '.content' | base64 -d | sed -n … to extract only frontmatter instead of the generic "via cli-proxy" phrase.

  • Phase 3 (Read Workflow Source) — replaced the paragraph with concrete bash snippets using gh api --jq + awk one-liners to slice out frontmatter or prompt body independently, avoiding full-file loads.

…fficiency guidance

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/957dfe49-1532-4eeb-aba9-20f065883a3d

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review May 1, 2026 02:00
Copilot AI review requested due to automatic review settings May 1, 2026 02:00
@pelikhan pelikhan merged commit 594dbed into main May 1, 2026
19 checks passed
@pelikhan pelikhan deleted the copilot/update-token-optimizer-workflow branch May 1, 2026 02:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Copilot Token Optimizer workflow prompt to better match mode: gh-proxy usage and to encourage token-efficient GitHub API access patterns (bash + gh api --jq + targeted slicing).

Changes:

  • Add a new “Data Access Guidelines” section with gh api --jq examples intended to reduce token waste from large JSON payloads.
  • Update Phase 2/3 instructions to reference extracting only frontmatter/prompt slices from workflow sources instead of generic “cli-proxy” wording.
  • Pass GH_AW_GITHUB_REPOSITORY into the “Interpolate variables and render templates” step in the locked workflow.
Show a summary per file
File Description
.github/workflows/copilot-token-optimizer.md Adds/updates prompt guidance for token-efficient gh api --jq usage and targeted extraction of workflow source sections.
.github/workflows/copilot-token-optimizer.lock.yml Adds GH_AW_GITHUB_REPOSITORY env var to the interpolate/render step environment.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comments suppressed due to low confidence (1)

.github/workflows/copilot-token-optimizer.md:226

  • This awk command does not extract only the prompt body after the closing ---. As written, it starts printing after the first ---, so it includes the entire frontmatter (and the closing delimiter) in the output. Update the command to begin output only after the second --- delimiter so the “prompt body only” instruction is accurate.
# Extract the prompt body only (everything after the closing ---)
gh api "repos/$REPO/contents/$WF_PATH" --jq '.content' | base64 -d \
  | awk 'f; /^---$/{f=1}'
  • Files reviewed: 2/2 changed files
  • Comments generated: 4


# Extract frontmatter only (tools, features, network, permissions)
gh api "repos/$REPO/contents/$WF_PATH" --jq '.content' | base64 -d \
| awk '/^---$/{n++; if(n==2) exit} n==1'
uses: actions/github-script@373c709c69115d41ff229c7e5df9f8788daa9553 # v9
env:
GH_AW_PROMPT: /tmp/gh-aw/aw-prompts/prompt.txt
GH_AW_GITHUB_REPOSITORY: ${{ github.repository }}

## Data Access Guidelines

All GitHub API access goes through the `gh` CLI via the cli-proxy — there are **no GitHub MCP tools** available. Always filter API responses with `--jq` or pipe through `jq` to extract only the fields you need. Loading full JSON payloads into context wastes tokens; every extra field is overhead.

# ✅ Combine multi-step reads into one bash block with pipes
gh api "repos/$REPO/contents/.github/workflows/my-workflow.md" \
--jq '.content' | base64 -d | sed -n '1,/^---$/{ /^---$/d; p }' | head -40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants