You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .github/workflows/copilot-token-optimizer.md
+48-2Lines changed: 48 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -126,6 +126,33 @@ You are the Copilot Token Optimizer. Pick one high-cost workflow, audit recent r
126
126
3. Propose safe, high-impact optimizations with evidence.
127
127
4. Publish one issue and update optimization history.
128
128
129
+
## Data Access Guidelines
130
+
131
+
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.
132
+
133
+
**Preferred patterns:**
134
+
135
+
```bash
136
+
REPO="${{ github.repository }}"
137
+
138
+
# ✅ Extract only the fields you need from a file
139
+
gh api "repos/$REPO/contents/.github/workflows/my-workflow.md" \
140
+
--jq '.content'| base64 -d
141
+
142
+
# ✅ List workflow runs — keep only essential metadata
143
+
gh api "repos/$REPO/actions/workflows/my-workflow.yml/runs?per_page=10" \
# ✅ Combine multi-step reads into one bash block with pipes
147
+
gh api "repos/$REPO/contents/.github/workflows/my-workflow.md" \
148
+
--jq '.content'| base64 -d | sed -n '1,/^---$/{ /^---$/d; p }'| head -40
149
+
150
+
# ❌ Never load full unfiltered responses — drops everything into context
151
+
gh api "repos/$REPO/actions/workflows/my-workflow.yml/runs"
152
+
```
153
+
154
+
Prefer `--jq` on `gh api` calls over a separate `| jq` step when the filter is simple — it avoids piping the full response through the shell. Use `| jq` for multi-step transformations or when chaining with other commands.
155
+
129
156
## Data Inputs
130
157
131
158
-`/tmp/gh-aw/token-audit/all-runs.json`: full 7-day run data (`gh aw logs --json`).
@@ -157,7 +184,7 @@ Use this compact analysis matrix:
157
184
158
185
| Area | Required checks | Output |
159
186
|---|---|---|
160
-
| Tool usage | Compare configured tools from workflow source (read via`gh api` through cli-proxy) vs observed usage across multiple runs | Keep / Consider removing / Remove |
187
+
| Tool usage | Compare configured tools from workflow source (read with`gh api … --jq '.content' \| base64 -d \| sed -n …` to extract only the frontmatter) vs observed usage across multiple runs | Keep / Consider removing / Remove |
Use `gh` CLI requests (via cli-proxy) to read the target workflow `.md` source and validate. Run `gh` commands normally in bash steps; cli-proxy forwards them over its HTTP interface:
210
+
Use `gh api` with `--jq` (via cli-proxy) to read the target workflow `.md` source. Extract only the sections you need — do not load the whole file if a targeted slice is sufficient.
211
+
212
+
```bash
213
+
REPO="${{ github.repository }}"
214
+
# Replace <workflow-name> with the actual .md filename, e.g. "copilot-agent-analysis"
215
+
WF_PATH=".github/workflows/<workflow-name>.md"
216
+
217
+
# Read the full source (only when necessary — prefer targeted slices below)
218
+
gh api "repos/$REPO/contents/$WF_PATH" --jq '.content'| base64 -d
219
+
220
+
# Extract frontmatter only (tools, features, network, permissions)
221
+
gh api "repos/$REPO/contents/$WF_PATH" --jq '.content'| base64 -d \
222
+
| awk '/^---$/{n++; if(n==2) exit} n==1'
223
+
224
+
# Extract the prompt body only (everything after the closing ---)
225
+
gh api "repos/$REPO/contents/$WF_PATH" --jq '.content'| base64 -d \
0 commit comments