Skip to content

[copilot-token-optimizer] Architecture Guardian: reduce 47-turn analysis via bash pre-step consolidation#28141

Merged
pelikhan merged 2 commits intomainfrom
copilot/optimize-bash-pre-step-consolidation
Apr 23, 2026
Merged

[copilot-token-optimizer] Architecture Guardian: reduce 47-turn analysis via bash pre-step consolidation#28141
pelikhan merged 2 commits intomainfrom
copilot/optimize-bash-pre-step-consolidation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 23, 2026

Architecture Guardian was running ~47 agent turns per execution (~1.97M tokens) because the agent was iterating file-by-file with individual wc, grep, and awk calls. ~50% of turns were deterministic data-gathering that had no reason to involve the AI.

Changes

Bash pre-step (primary change, ~800K–1M token savings)

Added a steps: block that runs before the agent and collects all metrics in one deterministic pass:

  • Changed Go/JS files in the last 24 hours (with vendor/test exclusions)
  • Per-file: line count, function sizes via awk, export counts via grep
  • Single go list ./... | grep "import cycle" across all packages
  • Writes structured JSON to /tmp/gh-aw/agent/arch-metrics.json

The agent reads one file and classifies violations, instead of issuing 20–30 shell commands across turns. Expected turn reduction: ~47 → ~15–20.

steps:
  - name: Collect architecture metrics
    run: |
      # ... collects all metrics into /tmp/gh-aw/agent/arch-metrics.json
      jq -n ... '{noop: false, thresholds: {...}, files: $files, import_cycles: $import_cycles}' \
        > /tmp/gh-aw/agent/arch-metrics.json

Tool footprint reduction (~40K–70K token savings)

  • Removed github: toolsets: [repos] — all analysis is local; no GitHub API calls needed
  • Removed edit: — workflow is read-only; tool was listed but never invoked

Prompt restructure (~50K–100K token savings)

  • Collapsed 6-step prompt to 3 steps: read JSON → classify → post report
  • Replaced verbose per-violation narrative (what/why/concrete plan) with compact 2-line templated format: `file` — N lines (limit: X) · **Fix**: one-sentence hint

Analysis correctness improvements

  • Expanded JS function detection to cover arrow functions (const f = () =>), export function, and class methods alongside the existing named/expression patterns
  • Added clarifying comment on Go awk pattern confirming it matches both regular functions and receiver methods via the ^func prefix

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh gh repo view --json owner,name --jq .owner.login + "/" + .name x_amd64/compile GOINSECURE g/x/crypto/interrev-parse GOMODCACHE x_amd64/compile (http block)
    • Triggering command: /usr/bin/gh gh repo view owner/repo env 216578226 wyMD/ZnqvKWWFy1YdeRMpwyMD 64/pkg/tool/linux_amd64/link GOINSECURE t/feature/pluralrev-parse GOMODCACHE 64/pkg/tool/linux_amd64/link (http block)
    • Triggering command: /usr/bin/gh gh repo view owner/repo env 216578226 GO111MODULE ache/go/1.25.8/x64/pkg/tool/linux_amd64/vet GOINSECURE osh-tekuri/jsonsrev-parse GOMODCACHE ache/go/1.25.8/x64/pkg/tool/linu-buildtags (http block)
  • https://api.github.com/orgs/test-owner/actions/secrets
    • Triggering command: /usr/bin/gh gh api /orgs/test-owner/actions/secrets --jq .secrets[].name -json GO111MODULE x_amd64/compile GOINSECURE GOMOD GOMODCACHE x_amd64/compile env -json 1.5.0/mcp/client-ifaceassert x_amd64/compile GOINSECURE GOMOD GOMODCACHE x_amd64/compile (http block)
  • https://api.github.com/repos/actions/ai-inference/git/ref/tags/v1
    • Triggering command: /usr/bin/gh gh api /repos/actions/ai-inference/git/ref/tags/v1 --jq [.object.sha, .object.type] | @tsv --get-regexp ^remote\..*\.gh-resolved$ /usr/bin/git md .cfg 64/pkg/tool/linu--show-toplevel git -C /tmp/gh-aw-test-runs/20260423-180909-35259/test-1331950784 rev-parse /usr/bin/git Ahfx/EOBK6ELuzyenode GO111MODULE ache/go/1.25.8/xinstall git (http block)
  • https://api.github.com/repos/actions/checkout/git/ref/tags/v3
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v3 --jq [.object.sha, .object.type] | @tsv k/gh-aw/gh-aw/.github/workflows/agent-performance-analyzer.md -test.v=true /usr/bin/docker -test.timeout=10git -test.run=^Test -test.short=true--show-toplevel docker pull�� test/race-image:v1.0.0 l /usr/bin/git -json GO111MODULE x_amd64/vet git (http block)
  • https://api.github.com/repos/actions/checkout/git/ref/tags/v5
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v5 --jq [.object.sha, .object.type] | @tsv 046088/b206/impo--workflow -trimpath ache/go/1.25.8/x--limit -p io/fs -lang=go1.25 ache/go/1.25.8/x--name-only -o st-257962632/.github/workflows -trimpath 64/pkg/tool/linux_amd64/vet -p vendor/golang.orrev-parse -lang=go1.25 64/pkg/tool/linux_amd64/vet (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v5 --jq [.object.sha, .object.type] | @tsv --show-toplevel /tmp/gh-aw-merge-2982760931/new.md /usr/bin/git se 0935880/b139/vet\n .cfg git rev-�� --show-toplevel ache/go/1.25.8/x64/pkg/tool/linu-dwarf=false /usr/bin/git 0909-35259/test-git 0935880/b259/vetrev-parse ache/go/1.25.8/x--show-toplevel git (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v5 --jq [.object.sha, .object.type] | @tsv --show-toplevel git /usr/bin/git /home/REDACTED/worgit l ache/node/24.14.--show-toplevel git rev-�� --show-toplevel git /usr/bin/git sistency_KeyOrdegit rev-parse /usr/bin/git git (http block)
  • https://api.github.com/repos/actions/checkout/git/ref/tags/v6
    • Triggering command: /usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v6 --jq [.object.sha, .object.type] | @tsv --show-toplevel x_amd64/compile /usr/bin/git -json GO111MODULE x_amd64/compile git -C /tmp/gh-aw-test-runs/20260423-180909-35259/test--s l /usr/bin/git remote.origin.urgit GO111MODULE x_amd64/vet git (http block)
  • https://api.github.com/repos/actions/github-script/git/ref/tags/v8
    • Triggering command: /usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v8 --jq [.object.sha, .object.type] | @tsv --show-toplevel Fr/vLW-tx2f42dcm-MlvCPy/t6M8s7Cmremote1 /usr/bin/git se 0935880/b210/vetcommit 0935880/b203/vet-m git rev-�� --show-toplevel /opt/hostedtoolcache/go/1.25.8/x64/pkg/tool/linuremote.origin.url /usr/bin/git -unreachable=falgit /tmp/go-build209rev-parse 1/x64/bin/node git (http block)
  • https://api.github.com/repos/actions/github-script/git/ref/tags/v9
    • Triggering command: /usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v9 --jq [.object.sha, .object.type] | @tsv -json GO111MODULE x_amd64/compile GOINSECURE GOMOD GOMODCACHE x_amd64/compile env -json GO111MODULE x_amd64/compile GOINSECURE GOMOD GOMODCACHE x_amd64/compile (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v9 --jq [.object.sha, .object.type] | @tsv -json o x_amd64/compile GOINSECURE GOMOD GOMODCACHE x_amd64/compile env -json GO111MODULE x_amd64/vet GOINSECURE GOMOD GOMODCACHE x_amd64/vet (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v9 --jq [.object.sha, .object.type] | @tsv -json GO111MODULE x_amd64/asm GOINSECURE GOMOD GOMODCACHE x_amd64/asm env -json GO111MODULE x_amd64/vet GOINSECURE GOMOD GOMODCACHE x_amd64/vet (http block)
  • https://api.github.com/repos/actions/setup-go/git/ref/tags/v4
    • Triggering command: /usr/bin/gh gh api /repos/actions/setup-go/git/ref/tags/v4 --jq [.object.sha, .object.type] | @tsv --show-toplevel x_amd64/compile /usr/bin/git g_.a GO111MODULE 64/pkg/tool/linu--show-toplevel git rev-�� --show-toplevel 64/pkg/tool/linu-importcfg /usr/bin/git Q8UqI7Ugv om/modelcontextprev-parse 64/pkg/tool/linu--show-toplevel git (http block)
  • https://api.github.com/repos/actions/setup-node/git/ref/tags/v4
    • Triggering command: /usr/bin/gh gh api /repos/actions/setup-node/git/ref/tags/v4 --jq [.object.sha, .object.type] | @tsv /tmp/TestGuardPolicyMinIntegrityOnlymin-integrity_only_defaults_repo2846006235/001 remote /usr/bin/gh -json GO111MODULE x_amd64/compile gh api /repos/actions/github-script/git/ref/tags/v9 --jq /usr/bin/git -json GO111MODULE x_amd64/link git (http block)
    • Triggering command: /usr/bin/gh gh api /repos/actions/setup-node/git/ref/tags/v4 --jq [.object.sha, .object.type] | @tsv --git-dir 64/pkg/tool/linux_amd64/compile /opt/hostedtoolcache/node/24.14.1/x64/bin/node g_.a eJpt1zLU2 64/pkg/tool/linu--show-toplevel /opt/hostedtoolcache/node/24.14.1/x64/bin/node /tmp�� No expressions here 64/pkg/tool/linuInitial commit /usr/bin/git cmPoR4jzD GO111MODULE x_amd64/link git (http block)
  • https://api.github.com/repos/actions/upload-artifact/git/ref/tags/v4
    • Triggering command: /usr/bin/gh gh api /repos/actions/upload-artifact/git/ref/tags/v4 --jq [.object.sha, .object.type] | @tsv --show-toplevel -dwarf=false /usr/bin/infocmp go1.25.8 -c=4 -nolocalimports infocmp -1 s/test.md /tmp/go-build2090935880/b424/_testmain.go /opt/hostedtoolcache/node/24.14.1/x64/bin/node -json GO111MODULE x_amd64/compile node (http block)
  • https://api.github.com/repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b
    • Triggering command: /usr/bin/gh gh api /repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b --jq [.object.sha, .object.type] | @tsv 12f41b9505b4b8054cc184e8 ings.cjs k/_temp/uv-python-dir/node -m Auth cleanup fai-V=full k/gh-aw/gh-aw/node_modules/.bin/feature && echo hacked forks.js k/gh�� -u st/suppress-warnings.cjs tions/setup/js/node_modules/.bin/git e/git t _modules/.bin/gi--require st/dist/workers//home/REDACTED/work/gh-aw/gh-aw/actions/setup/js/node_modules/vitest/suppress-warnings.cjs (http block)
    • Triggering command: /usr/bin/gh gh api /repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b --jq [.object.sha, .object.type] | @tsv b1b633c7..HEAD git $name) { hasDiscussionsEnabled } } user.name Test User /home/REDACTED/.lo-m git show�� --verify b1b633c7..HEAD ode_modules/.bin/git --bare commit es/.bin/git git (http block)
    • Triggering command: /usr/bin/gh gh api /repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b --jq [.object.sha, .object.type] | @tsv b1b633c7..HEAD git git user.email test@example.com--experimental-import-meta-resolve bin/git git show�� --verify b1b633c7..HEAD 86_64/node --bare gin/token-optionapi odules/npm/node_graphql git (http block)
  • https://api.github.com/repos/github/gh-aw-actions/git/ref/tags/v0.1.2
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw-actions/git/ref/tags/v0.1.2 --jq [.object.sha, .object.type] | @tsv --git-dir 64/pkg/tool/linuTest User /opt/hostedtoolcache/node/24.14.1/x64/bin/node rtcfg Ffa_H-Eee x_amd64/vet /opt/hostedtoolcache/node/24.14.1/x64/bin/node /tmp�� steps.test.outputs.result x_amd64/vet /usr/bin/git rtcfg GO111MODULE 64/pkg/tool/linu--show-toplevel git (http block)
  • https://api.github.com/repos/github/gh-aw-actions/git/ref/tags/v1.0.0
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw-actions/git/ref/tags/v1.0.0 --jq [.object.sha, .object.type] | @tsv 0935880/b462/_pkg_.a remote 0935880/b462=> -json .go x_amd64/compile git -C byx2/jNQYSQDdMsvnnTZDbyx2 l /usr/bin/git -json GO111MODULE x_amd64/vet git (http block)
  • https://api.github.com/repos/github/gh-aw-actions/git/ref/tags/v1.2.3
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw-actions/git/ref/tags/v1.2.3 --jq [.object.sha, .object.type] | @tsv bility_SameInputSameOutput1544395470/001/stability-test.md rev-parse /usr/bin/git plate-expressiongit h1291056340/001'rev-parse -nolocalimports git -C /tmp/gh-aw-test-runs/20260423-180909-35259/test-216578226 rev-parse /usr/bin/git 1 GO111MODULE x_amd64/vet git (http block)
  • https://api.github.com/repos/github/gh-aw/actions/runs/1/artifacts
    • Triggering command: /usr/bin/gh gh api --paginate repos/{owner}/{repo}/actions/runs/1/artifacts --jq .artifacts[].name .cfg 64/pkg/tool/linux_amd64/vet GOINSECURE GOMOD GOMODCACHE 64/pkg/tool/linux_amd64/vet env 046088/b141/_pkg_.a 7gve/JS7DQw3o9RuNG8R67gve x_amd64/compile GOINSECURE contextprotocol/rev-parse GOMODCACHE x_amd64/compile (http block)
    • Triggering command: /usr/bin/gh gh run download 1 --dir test-logs/run-1 .cfg x_amd64/vet GOINSECURE /go-yaml/parser GOMODCACHE x_amd64/vet (http block)
  • https://api.github.com/repos/github/gh-aw/actions/runs/12345/artifacts
    • Triggering command: /usr/bin/gh gh api --paginate repos/{owner}/{repo}/actions/runs/12345/artifacts --jq .artifacts[].name .cfg 64/pkg/tool/linux_amd64/vet GOINSECURE GOMOD 046088/b012/symauser.email 64/pkg/tool/linutest@example.com env 4024507259 BHdz/-6z_QJDvZKLbBouUBHdz x_amd64/link GOINSECURE GOMOD GOMODCACHE x_amd64/link (http block)
    • Triggering command: /usr/bin/gh gh run download 12345 --dir test-logs/run-12345 .cfg 64/pkg/tool/linux_amd64/vet GOINSECURE /cpu GOMODCACHE 64/pkg/tool/linux_amd64/vet env 216578226 GO111MODULE ache/go/1.25.8/x64/pkg/tool/linux_amd64/vet GOINSECURE osh-tekuri/jsonsrev-parse GOMODCACHE ache/go/1.25.8/x64/pkg/tool/linu-buildtags (http block)
  • https://api.github.com/repos/github/gh-aw/actions/runs/12346/artifacts
    • Triggering command: /usr/bin/gh gh api --paginate repos/{owner}/{repo}/actions/runs/12346/artifacts --jq .artifacts[].name .cfg 64/pkg/tool/linux_amd64/vet GOINSECURE sysrand 046088/b021/syma--git-dir 64/pkg/tool/linux_amd64/vet env 4024507259 REzZ/UVSmm-gThuyfG0BeREzZ ache/go/1.25.8/x64/pkg/tool/linux_amd64/vet GOINSECURE t/internal/catmsrev-parse GOMODCACHE ache/go/1.25.8/x64/pkg/tool/linu-buildtags (http block)
    • Triggering command: /usr/bin/gh gh run download 12346 --dir test-logs/run-12346 .cfg 64/pkg/tool/linux_amd64/vet GOINSECURE GOMOD GOMODCACHE 64/pkg/tool/linux_amd64/vet env 216578226 Kv-X/SrddFjc3EqPBzwz7Kv-X ache/go/1.25.8/x64/pkg/tool/linux_amd64/vet GOINSECURE osh-tekuri/jsonsrev-parse GOMODCACHE ache/go/1.25.8/x64/pkg/tool/linu-importcfg (http block)
  • https://api.github.com/repos/github/gh-aw/actions/runs/2/artifacts
    • Triggering command: /usr/bin/gh gh api --paginate repos/{owner}/{repo}/actions/runs/2/artifacts --jq .artifacts[].name .cfg 64/pkg/tool/linux_amd64/vet GOINSECURE ntio/asm/cpu ache/go/1.25.8/x--show-toplevel 64/pkg/tool/linux_amd64/vet env 046088/b140/_pkg_.a GO111MODULE ache/go/1.25.8/x64/pkg/tool/linu-buildmode=exe GOINSECURE contextprotocol/rev-parse GOMODCACHE ache/go/1.25.8/x64/pkg/tool/linu-test.v=true (http block)
    • Triggering command: /usr/bin/gh gh run download 2 --dir test-logs/run-2 .cfg 64/pkg/tool/linux_amd64/compile GOINSECURE 046088/b133/ 046088/b087/syma--show-toplevel 64/pkg/tool/linux_amd64/compile (http block)
  • https://api.github.com/repos/github/gh-aw/actions/runs/3/artifacts
    • Triggering command: /usr/bin/gh gh api --paginate repos/{owner}/{repo}/actions/runs/3/artifacts --jq .artifacts[].name .cfg 64/pkg/tool/linux_amd64/vet GOINSECURE ntio/asm/keyset GOMODCACHE sY5xy3c/9ezsDU_Vtest@example.com env 1285125824/.github/workflows GO111MODULE ache/go/1.25.8/x64/pkg/tool/linux_amd64/vet GOINSECURE b/gh-aw/pkg/workrev-parse GOMODCACHE ache/go/1.25.8/x64/pkg/tool/linurev-parse (http block)
    • Triggering command: /usr/bin/gh gh run download 3 --dir test-logs/run-3 _VvF/FyImW2PzFURYGaDW_VvF 64/pkg/tool/linux_amd64/vet GOINSECURE /go-yaml GOMODCACHE 64/pkg/tool/linux_amd64/vet (http block)
  • https://api.github.com/repos/github/gh-aw/actions/runs/4/artifacts
    • Triggering command: /usr/bin/gh gh api --paginate repos/{owner}/{repo}/actions/runs/4/artifacts --jq .artifacts[].name .cfg 64/pkg/tool/linux_amd64/vet GOINSECURE fips140/bigmod GOMODCACHE 64/pkg/tool/linux_amd64/vet env 1285125824/.github/workflows c9ZF/KtTFKQuDD_Pbt7zDc9ZF ache/go/1.25.8/x64/pkg/tool/linu-nolocalimports GOINSECURE contextprotocol/rev-parse GOMODCACHE ache/go/1.25.8/x64/pkg/tool/linu-buildtags (http block)
    • Triggering command: /usr/bin/gh gh run download 4 --dir test-logs/run-4 .cfg 64/pkg/tool/linux_amd64/vet GOINSECURE GOMOD GOMODCACHE 64/pkg/tool/linux_amd64/vet env 249477132/.github/workflows .cfg 64/pkg/tool/linux_amd64/compile GOINSECURE GOMOD 046088/b133/syma--show-toplevel 64/pkg/tool/linux_amd64/compile (http block)
  • https://api.github.com/repos/github/gh-aw/actions/runs/5/artifacts
    • Triggering command: /usr/bin/gh gh api --paginate repos/{owner}/{repo}/actions/runs/5/artifacts --jq .artifacts[].name .cfg 64/pkg/tool/linux_amd64/vet GOINSECURE light 046088/b036/symauser.name 64/pkg/tool/linuTest User env 1285125824/.github/workflows 28ie/dWadUuI3oiBsYAOo28ie ache/go/1.25.8/x64/pkg/tool/linux_amd64/vet GOINSECURE b/gh-aw/pkg/parsrev-parse GOMODCACHE ache/go/1.25.8/x64/pkg/tool/linux_amd64/vet (http block)
    • Triggering command: /usr/bin/gh gh run download 5 --dir test-logs/run-5 .cfg 64/pkg/tool/linux_amd64/vet GOINSECURE /go-yaml/ast GOMODCACHE 64/pkg/tool/linux_amd64/vet env 249477132 GO111MODULE ache/go/1.25.8/x64/pkg/tool/linux_amd64/vet GOINSECURE b/gh-aw/tmp GOMODCACHE ache/go/1.25.8/x64/pkg/tool/linu-importcfg (http block)
  • https://api.github.com/repos/github/gh-aw/actions/workflows
    • Triggering command: /usr/bin/gh gh workflow list --json name,state,path 46787846/001' 46787846/001' -importcfg /tmp/go-build2090935880/b419/importcfg -pack /home/REDACTED/work/gh-aw/gh-aw/pkg/fileutil/fileutil.go /home/REDACTED/work/gh-aw/gh-aw/pkg/fileutil/tar.go env -json GO111MODULE x_amd64/compile GOINSECURE GOMOD GOMODCACHE x_amd64/compile (http block)
    • Triggering command: /usr/bin/gh gh run list --json databaseId,number,url,status,conclusion,workflowName,createdAt,startedAt,updatedAt,event,headBranch,headSha,displayTitle --workflow nonexistent-workflow-12345 --limit 100 GOMOD GOMODCACHE x_amd64/vet env -json GO111MODULE x_amd64/vet GOINSECURE GOMOD GOMODCACHE x_amd64/vet (http block)
    • Triggering command: /usr/bin/gh gh run list --json databaseId,number,url,status,conclusion,workflowName,createdAt,startedAt,updatedAt,event,headBranch,headSha,displayTitle --workflow nonexistent-workflow-12345 --limit 6 fips140/check GOMODCACHE 64/pkg/tool/linux_amd64/vet env l.go l_test.go .cfg GOINSECURE fips140/ecdh GOMODCACHE ache/go/1.25.8/x64/pkg/tool/linux_amd64/compile (http block)
  • https://api.github.com/repos/github/gh-aw/contents/.github/workflows/shared/reporting.md
    • Triggering command: /tmp/go-build2090935880/b404/cli.test /tmp/go-build2090935880/b404/cli.test -test.testlogfile=/tmp/go-build2090935880/b404/testlog.txt -test.paniconexit0 -test.v=true -test.parallel=4 -test.timeout=10m0s -test.run=^Test -test.short=true GOINSECURE GOMOD GOMODCACHE x_amd64/asm env -json GO111MODULE x_amd64/compile GOINSECURE GOMOD GOMODCACHE x_amd64/compile (http block)
  • https://api.github.com/repos/github/gh-aw/git/ref/tags/v0.47.4
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v0.47.4 --jq [.object.sha, .object.type] | @tsv --show-toplevel x_amd64/link /usr/bin/git P82kiP9ch 0935880/b217/vetrev-parse ache/go/1.25.8/x--show-toplevel git rev-�� --show-toplevel Bh/hKJC44cVKMHVnpBvTgXO/G1KutSxXHjoE8hqd2SJr /usr/bin/git /tmp/go-build418ls stmain.go ceutil.test git (http block)
  • https://api.github.com/repos/github/gh-aw/git/ref/tags/v1.0.0
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v1.0.0 --jq [.object.sha, .object.type] | @tsv sole.test 0935880/b041/vet.cfg ortcfg.link GOINSECURE GOMOD GOMODCACHE KRbIgVmOMS9AxCcARB/L1Wa7eeJiw1neQqQx3T_/AukKNLXarev-parse (http block)
  • https://api.github.com/repos/github/gh-aw/git/ref/tags/v1.2.3
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v1.2.3 --jq [.object.sha, .object.type] | @tsv -json GO111MODULE x_amd64/vet GOINSECURE GOMOD GOMODCACHE x_amd64/vet 7878�� _.a GO111MODULE x_amd64/vet GOINSECURE GOMOD GOMODCACHE x_amd64/vet (http block)
  • https://api.github.com/repos/github/gh-aw/git/ref/tags/v2.0.0
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v2.0.0 --jq [.object.sha, .object.type] | @tsv -json GO111MODULE x_amd64/vet GOINSECURE GOMOD GOMODCACHE x_amd64/vet env lGitmain_branch446787846/001' lGitmain_branch446787846/001' x_amd64/vet GOINSECURE GOMOD GOMODCACHE x_amd64/vet (http block)
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v2.0.0 --jq [.object.sha, .object.type] | @tsv -json GO111MODULE x_amd64/vet GOINSECURE GOMOD GOMODCACHE x_amd64/vet env _.a GO111MODULE x_amd64/vet GOINSECURE order GOMODCACHE x_amd64/vet (http block)
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v2.0.0 --jq [.object.sha, .object.type] | @tsv -json GO111MODULE x_amd64/vet GOINSECURE GOMOD GOMODCACHE x_amd64/vet env _.a @v1.19.2/scanner/context.go x_amd64/vet GOINSECURE GOMOD GOMODCACHE x_amd64/vet (http block)
  • https://api.github.com/repos/github/gh-aw/git/ref/tags/v3.0.0
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v3.0.0 --jq [.object.sha, .object.type] | @tsv echo "Running wasm-opt -Oz (size-p GO111MODULE x_amd64/vet GOINSECURE GOMOD GOMODCACHE x_amd64/vet env -json GO111MODULE x_amd64/vet GOINSECURE GOMOD GOMODCACHE x_amd64/vet (http block)
  • https://api.github.com/repos/nonexistent/action/git/ref/tags/v999.999.999
    • Triggering command: /usr/bin/gh gh api /repos/nonexistent/action/git/ref/tags/v999.999.999 --jq [.object.sha, .object.type] | @tsv g_.a 0935880/b043/vet.cfg .cfg GOINSECURE GOMOD GOMODCACHE ache/go/1.25.8/x64/pkg/tool/linu-trimpath -o roGRtQo2l -trimpath ache/go/1.25.8/x64/pkg/tool/linu-lang=go1.25 -p maps -lang=go1.25 ache/go/1.25.8/x12345 (http block)
  • https://api.github.com/repos/nonexistent/repo/actions/runs/12345
    • Triggering command: /usr/bin/gh gh run view 12345 --repo nonexistent/repo --json status,conclusion GOINSECURE GOMOD GOMODCACHE 64/pkg/tool/linu/home/REDACTED/work/gh-aw/gh-aw/pkg/typeutil/convert_test.go (http block)
  • https://api.github.com/repos/owner/repo/actions/workflows
    • Triggering command: /usr/bin/gh gh workflow list --json name,state,path --repo owner/repo x_amd64/compile GOINSECURE GOMOD GOMODCACHE x_amd64/compile env -json GO111MODULE 64/bin/go GOINSECURE GOMOD ic/asm.s go (http block)
    • Triggering command: /usr/bin/gh gh workflow list --json name,state,path --repo owner/repo x_amd64/compile GOINSECURE GOMOD GOMODCACHE x_amd64/compile env -json GO111MODULE 64/bin/go GOINSECURE GOMOD abi/abi_test.s go (http block)
    • Triggering command: /usr/bin/gh gh workflow list --repo owner/repo --json name,path,state x_amd64/link GOINSECURE GOMOD GOMODCACHE x_amd64/link (http block)
  • https://api.github.com/repos/test-owner/test-repo/actions/secrets
    • Triggering command: /usr/bin/gh gh api /repos/test-owner/test-repo/actions/secrets --jq .secrets[].name -json x86.go x_amd64/compile GOINSECURE GOMOD GOMODCACHE x_amd64/compile env -json GO111MODULE x_amd64/compile GOINSECURE GOMOD GOMODCACHE x_amd64/compile (http block)
  • https://api.github.com/repos/test/repo
    • Triggering command: /usr/bin/gh gh api /repos/test/repo --jq .default_branch se 0935880/b009/vet.cfg 64/pkg/tool/linux_amd64/vet GOINSECURE 046088/b133/aritrev-parse ache/go/1.25.8/x--show-toplevel 64/pkg/tool/linux_amd64/vet -p crypto/internal/boring/sig -trimpath ache/go/1.25.8/x64/pkg/tool/linux_amd64/vet -I /tmp/go-build418-1 -I ache/go/1.25.8/x64/pkg/tool/linux_amd64/vet (http block)
  • invalid.example.invalid
    • Triggering command: /usr/lib/git-core/git-remote-https /usr/lib/git-core/git-remote-https origin https://invalid.example.invalid/nonexistent-repo.git git conf�� --local --get ode_modules/.bin/git cal/bin/git git /git git add . git tions/setup/node_modules/.bin/git -M main bin/git git (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

- Add bash pre-step that collects all file metrics upfront into
  /tmp/gh-aw/agent/arch-metrics.json, replacing ~20-30 per-file
  agent turns with a single deterministic bash step
- Remove github: toolsets: [repos] (unused in local static analysis)
- Remove edit: tool (workflow is read-only, tool was never called)
- Simplify violation reporting to 2-line templated format per violation
  instead of verbose 3-part narrative suggestions
- Improve Go receiver method detection in awk pattern
- Expand JS function detection to cover arrow functions and exports
- Add comment explaining go list error handling
- Add instruction for agent to replace template placeholders

Estimated savings: ~800K-1.1M tokens per run (~40-55% reduction)
Reduces expected turns from 47 to ~15-20

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/8b9b7035-c5bd-4617-9684-7537d0c6b157

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot AI changed the title [WIP] Reduce 47-turn analysis via bash pre-step consolidation [copilot-token-optimizer] Architecture Guardian: reduce 47-turn analysis via bash pre-step consolidation Apr 23, 2026
Copilot AI requested a review from lpcox April 23, 2026 18:20
@pelikhan pelikhan marked this pull request as ready for review April 23, 2026 18:32
Copilot AI review requested due to automatic review settings April 23, 2026 18:32
@pelikhan pelikhan merged commit 2de817e into main Apr 23, 2026
@pelikhan pelikhan deleted the copilot/optimize-bash-pre-step-consolidation branch April 23, 2026 18:32
@github-actions github-actions Bot mentioned this pull request Apr 23, 2026
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

Optimizes the Architecture Guardian agentic workflow to reduce AI turn/token usage by consolidating deterministic repository analysis into a single pre-execution bash step and simplifying the agent prompt.

Changes:

  • Added a pre-execution steps: bash block to compute architecture metrics (line counts, exports, function data, import cycles) and write them to /tmp/gh-aw/agent/arch-metrics.json.
  • Restructured the agent prompt to read the pre-computed JSON and produce a compact issue report format.
  • Updated documentation/schema references (frontmatter fields and workflow index) to reflect new/clarified workflow configuration options.
Show a summary per file
File Description
docs/src/content/docs/reference/frontmatter-full.md Documents/clarifies workflow frontmatter options (needs, pre-agent-steps wording, fallback labels).
docs/src/content/docs/agent-factory-status.mdx Adds new workflows to the Agent Factory status table.
.github/workflows/architecture-guardian.md Introduces metrics pre-step and simplifies the agent instructions to consume JSON instead of running many shell commands.
.github/workflows/architecture-guardian.lock.yml Regenerates the compiled workflow to include the new pre-step and updated tool allowlist/actions.

Copilot's findings

Tip

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

  • Files reviewed: 4/4 changed files
  • Comments generated: 4

Comment on lines +48 to +55
b=$(grep -E '^\s*file_lines_blocker:' .architecture.yml 2>/dev/null | awk '{print $2}' | tr -d '"' | head -1 || true)
w=$(grep -E '^\s*file_lines_warning:' .architecture.yml 2>/dev/null | awk '{print $2}' | tr -d '"' | head -1 || true)
f=$(grep -E '^\s*function_lines:' .architecture.yml 2>/dev/null | awk '{print $2}' | tr -d '"' | head -1 || true)
e=$(grep -E '^\s*max_exports:' .architecture.yml 2>/dev/null | awk '{print $2}' | tr -d '"' | head -1 || true)
[[ -n "${b:-}" && "$b" =~ ^[0-9]+$ ]] && FILE_LINES_BLOCKER=$b
[[ -n "${w:-}" && "$w" =~ ^[0-9]+$ ]] && FILE_LINES_WARNING=$w
[[ -n "${f:-}" && "$f" =~ ^[0-9]+$ ]] && FUNCTION_LINES=$f
[[ -n "${e:-}" && "$e" =~ ^[0-9]+$ ]] && MAX_EXPORTS=$e
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

The threshold parsing regex uses \s with grep -E, but \s is not whitespace in ERE. In this repo .architecture.yml keys are indented under thresholds: (e.g., file_lines_blocker:), so these greps will fail and the workflow will always fall back to defaults. Use [[:space:]]* (or grep -P), and consider scoping to the thresholds: block to avoid accidental matches.

Copilot uses AI. Check for mistakes.
Comment on lines 180 to 183
### WARNING (should be addressed soon)
- Files exceeding 500 lines (configurable)
- Functions/methods exceeding 80 lines (configurable)
- `files[].lines` > `thresholds.file_lines_warning` (default 500)
- Any function in `files[].func_data` with line count > `thresholds.function_lines` (default 80)

Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

FUNC_DATA for JS is populated with grep -n output (line numbers + source), but later the workflow instructs to treat func_data as having line counts and to warn when a function exceeds thresholds.function_lines. With the current metrics format, the agent cannot reliably determine JS function sizes from func_data. Either compute per-function line counts for JS in the pre-step (similar to the Go awk approach) or update the classification rules to only apply the function-size check to Go entries.

Copilot uses AI. Check for mistakes.
Comment on lines +94 to +98
FUNC_DATA=$(grep -nE "^function |^const [a-zA-Z_$][a-zA-Z0-9_$]* = (function|\(|async \(|async function)|^(export (default )?function|export const [a-zA-Z_$][a-zA-Z0-9_$]* =)|^[a-zA-Z_$][a-zA-Z0-9_$]*\s*\([^)]*\)\s*\{" "$FILE" 2>/dev/null | head -50 || true)
CJS_COUNT=$(grep -cE "^module\.exports|^exports\." "$FILE" 2>/dev/null || echo 0)
ESM_COUNT=$(grep -cE "^export " "$FILE" 2>/dev/null || echo 0)
EXPORT_COUNT=$((CJS_COUNT + ESM_COUNT))
EXPORT_NAMES=$(grep -nE "^export |^module\.exports|^exports\." "$FILE" 2>/dev/null | head -20 || true)
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

The JS function detection regex is anchored to the beginning of the line (e.g., ^function, ^const, ^[a-zA-Z_$]...), so it won't match indented class methods ( myMethod() {}) and will miss many methods inside class { ... }. If class methods are intended to be included, allow optional leading whitespace and/or explicitly match class bodies / method patterns with indentation.

Suggested change
FUNC_DATA=$(grep -nE "^function |^const [a-zA-Z_$][a-zA-Z0-9_$]* = (function|\(|async \(|async function)|^(export (default )?function|export const [a-zA-Z_$][a-zA-Z0-9_$]* =)|^[a-zA-Z_$][a-zA-Z0-9_$]*\s*\([^)]*\)\s*\{" "$FILE" 2>/dev/null | head -50 || true)
CJS_COUNT=$(grep -cE "^module\.exports|^exports\." "$FILE" 2>/dev/null || echo 0)
ESM_COUNT=$(grep -cE "^export " "$FILE" 2>/dev/null || echo 0)
EXPORT_COUNT=$((CJS_COUNT + ESM_COUNT))
EXPORT_NAMES=$(grep -nE "^export |^module\.exports|^exports\." "$FILE" 2>/dev/null | head -20 || true)
FUNC_DATA=$(grep -nE "^[[:space:]]*function |^[[:space:]]*const [a-zA-Z_$][a-zA-Z0-9_$]* = (function|\(|async \(|async function)|^[[:space:]]*(export (default )?function|export const [a-zA-Z_$][a-zA-Z0-9_$]* =)|^[[:space:]]*[a-zA-Z_$][a-zA-Z0-9_$]*\s*\([^)]*\)\s*\{" "$FILE" 2>/dev/null | head -50 || true)
CJS_COUNT=$(grep -cE "^[[:space:]]*module\.exports|^[[:space:]]*exports\." "$FILE" 2>/dev/null || echo 0)
ESM_COUNT=$(grep -cE "^[[:space:]]*export " "$FILE" 2>/dev/null || echo 0)
EXPORT_COUNT=$((CJS_COUNT + ESM_COUNT))
EXPORT_NAMES=$(grep -nE "^[[:space:]]*export |^[[:space:]]*module\.exports|^[[:space:]]*exports\." "$FILE" 2>/dev/null | head -20 || true)

Copilot uses AI. Check for mistakes.
if [[ "$EXT" == "go" ]]; then
# Function sizes: "func declaration\tline_count" per function
# Pattern matches both regular functions (^func Name) and receiver methods (^func (r *T) Name)
FUNC_DATA=$(awk '/^func /{if(start>0 && name!="") printf "%s\t%d\n", name, NR-start; name=$0; start=NR} END{if(start>0 && name!="") printf "%s\t%d\n", name, NR-start+1}' "$FILE" 2>/dev/null | head -50 || true)
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

The Go FUNC_DATA output is truncated with head -50, which can hide oversized functions if they appear after the first 50 func declarations in a file. To avoid missing real violations, consider keeping all functions, or selecting the top N largest functions (e.g., sort by computed length) rather than the first N.

Suggested change
FUNC_DATA=$(awk '/^func /{if(start>0 && name!="") printf "%s\t%d\n", name, NR-start; name=$0; start=NR} END{if(start>0 && name!="") printf "%s\t%d\n", name, NR-start+1}' "$FILE" 2>/dev/null | head -50 || true)
FUNC_DATA=$(awk '/^func /{if(start>0 && name!="") printf "%s\t%d\n", name, NR-start; name=$0; start=NR} END{if(start>0 && name!="") printf "%s\t%d\n", name, NR-start+1}' "$FILE" 2>/dev/null || true)

Copilot uses AI. Check for mistakes.
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.

[copilot-token-optimizer] Architecture Guardian: reduce 47-turn analysis via bash pre-step consolidation

4 participants