Skip to content

Fix Copilot agent path to use identifier instead of full path#3686

Merged
pelikhan merged 8 commits into
mainfrom
copilot/investigate-github-workspace-encoding
Nov 12, 2025
Merged

Fix Copilot agent path to use identifier instead of full path#3686
pelikhan merged 8 commits into
mainfrom
copilot/investigate-github-workspace-encoding

Conversation

Copilot AI commented Nov 12, 2025

Copy link
Copy Markdown
Contributor

The Copilot CLI's --agent flag expects an agent identifier (filename without extension), not a full file path. This fix extracts the identifier from the agent file path for Copilot while maintaining full path usage for Claude and Codex engines that need to read file content.

Root Cause

The Copilot CLI discovers agents automatically and references them by identifier:

# Incorrect - passes full path
copilot --agent "${GITHUB_WORKSPACE}/.github/agents/cli-consistency-checker.md"
# Error: No such agent: /workspaces/gh-aw/.github/agents/cli-consistency-checker.md

# Correct - passes identifier
copilot --agent cli-consistency-checker
# Works!

Changes

  • pkg/workflow/engine_helpers.go:

    • Added ExtractAgentIdentifier() to extract filename without extension
    • Updated ResolveAgentFilePath() to properly quote full paths for Claude/Codex
  • pkg/workflow/copilot_engine.go: Updated to use agent identifier instead of full path

  • pkg/workflow/engine_helpers_test.go: Added tests for identifier extraction and updated existing tests

  • pkg/workflow/engine_agent_import_test.go: Updated Copilot test to expect agent identifier

Result

Copilot engine: Uses agent identifier

--agent cli-consistency-checker

Claude/Codex engines: Use full path with proper quoting for file reading

"${GITHUB_WORKSPACE}/.github/agents/test-agent.md"
Original prompt

Investigate incorrect encoding of the encoding GITHUB_WORKSPACE variable.

See error https://github.com/githubnext/gh-aw/actions/runs/19285890449/job/55146633195#step:24:1


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Nov 12, 2025
Copilot AI and others added 3 commits November 12, 2025 04:33
- Change ResolveAgentFilePath to wrap entire path in double quotes
- Previously: "${GITHUB_WORKSPACE}"/.github/agents/test.md (broken)
- Now: "${GITHUB_WORKSPACE}/.github/agents/test.md" (working)
- Update all affected tests to expect correct format
- Fixes shell variable expansion issue in Copilot engine

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- Add TestShellVariableExpansionInAgentPath to verify correct quoting
- Add TestShellEscapeArgWithFullyQuotedAgentPath to verify no re-escaping
- Tests validate that ${GITHUB_WORKSPACE} will be expanded by shell
- Tests verify no single quotes are added that would prevent expansion

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Investigate incorrect encoding of GITHUB_WORKSPACE variable Fix GITHUB_WORKSPACE variable expansion in agent file paths Nov 12, 2025
Copilot AI requested a review from pelikhan November 12, 2025 04:50
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot the --agent option takes the agent identifier, ie. the file name without extension. Here is a cli output to test the feature::

@pelikhan ➜ /workspaces/gh-aw (copilot/investigate-github-workspace-encoding) $ copilot --agent /workspaces/gh-aw/.github/agents/cli-consistency-checker.md -p "hello"
No such agent: /workspaces/gh-aw/.github/agents/cli-consistency-checker.md, available: cli-consistency-checker, copilot-add-safe-output-type, create-agentic-workflow, create-shared-agentic-workflow, improve-json-schema-descriptions, setup-agentic-workflows, shell-2-script, technical-doc-writer
@pelikhan ➜ /workspaces/gh-aw (copilot/investigate-github-workspace-encoding) $ copilot --agent cli-consistency-checker -p "hello"

- Add ExtractAgentIdentifier() to extract filename without extension
- Update Copilot engine to pass agent identifier, not full path
- Keep Claude/Codex engines using full path for file reading
- Add comprehensive tests for agent identifier extraction
- Update Copilot engine test to expect agent identifier

Copilot CLI expects agent identifiers like "cli-consistency-checker",
not paths like "${GITHUB_WORKSPACE}/.github/agents/cli-consistency-checker.md"

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Nov 12, 2025

Copy link
Copy Markdown
Contributor Author

@copilot the --agent option takes the agent identifier, ie. the file name without extension. Here is a cli output to test the feature::

...

Fixed in 0e4255e. The Copilot CLI now receives the agent identifier cli-consistency-checker instead of the full path.

Claude and Codex engines continue using the full path since they read file content with awk.

Copilot AI changed the title Fix GITHUB_WORKSPACE variable expansion in agent file paths Fix Copilot agent path to use identifier instead of full path Nov 12, 2025
@pelikhan pelikhan marked this pull request as ready for review November 12, 2025 05:46
Copilot AI review requested due to automatic review settings November 12, 2025 05:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes how the Copilot CLI agent path is passed by using the agent identifier (filename without extension) instead of the full file path. The Copilot CLI auto-discovers agents and expects identifiers, while Claude and Codex engines need full paths to read file content.

Key Changes

  • Added ExtractAgentIdentifier() function to extract filename without extension from agent file paths
  • Updated ResolveAgentFilePath() to properly quote full paths with ${GITHUB_WORKSPACE} for Claude/Codex
  • Updated Copilot engine to use agent identifier instead of full path
  • Updated tests to match new expectations

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/workflow/engine_helpers.go Added ExtractAgentIdentifier() function and updated ResolveAgentFilePath() quoting
pkg/workflow/copilot_engine.go Changed to use ExtractAgentIdentifier() for Copilot CLI --agent flag
pkg/workflow/engine_helpers_test.go Added tests for identifier extraction and updated path format tests
pkg/workflow/engine_agent_import_test.go Updated Copilot test to expect identifier, Claude/Codex tests updated for new quoting
.github/workflows/technical-doc-writer.lock.yml Regenerated lock file (appears incomplete - see bug below)
.github/workflows/cli-consistency-checker.md Removed agent import, inlined agent instructions
.github/workflows/cli-consistency-checker.lock.yml Regenerated lock file after removing agent import

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

Comment thread .github/workflows/technical-doc-writer.lock.yml
Comment thread pkg/workflow/engine_helpers_test.go
@pelikhan pelikhan merged commit 61b1d87 into main Nov 12, 2025
14 checks passed
@pelikhan pelikhan deleted the copilot/investigate-github-workspace-encoding branch November 12, 2025 05:50
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