@@ -16,6 +16,7 @@ ARG_ALLOW_ALL_TOOLS=${ARG_ALLOW_ALL_TOOLS:-false}
1616ARG_ALLOW_TOOLS=${ARG_ALLOW_TOOLS:- }
1717ARG_DENY_TOOLS=${ARG_DENY_TOOLS:- }
1818ARG_TRUSTED_DIRECTORIES=${ARG_TRUSTED_DIRECTORIES:- }
19+ ARG_EXTERNAL_AUTH_ID=${ARG_EXTERNAL_AUTH_ID:- github}
1920
2021validate_copilot_installation () {
2122 if ! command_exists copilot; then
@@ -81,6 +82,31 @@ configure_copilot_model() {
8182 fi
8283}
8384
85+ setup_github_authentication () {
86+ echo " Setting up GitHub authentication..."
87+
88+ if command_exists coder; then
89+ local github_token
90+ if github_token=$( coder external-auth access-token " ${ARG_EXTERNAL_AUTH_ID} " 2> /dev/null) ; then
91+ if [ -n " $github_token " ] && [ " $github_token " != " null" ]; then
92+ export GITHUB_TOKEN=" $github_token "
93+ export GH_TOKEN=" $github_token "
94+ echo " GitHub authentication: via Coder external auth"
95+ return 0
96+ fi
97+ fi
98+ fi
99+
100+ if command_exists gh && gh auth status > /dev/null 2>&1 ; then
101+ echo " GitHub authentication: via GitHub CLI"
102+ return 0
103+ fi
104+
105+ echo " WARNING: No GitHub authentication found. Copilot CLI requires authentication."
106+ echo " Please ensure GitHub external auth is configured in Coder or run 'gh auth login'"
107+ return 1
108+ }
109+
84110start_agentapi () {
85111 echo " Starting in directory: $ARG_WORKDIR "
86112 cd " $ARG_WORKDIR "
@@ -99,7 +125,7 @@ start_agentapi() {
99125configure_copilot_model
100126
101127echo " COPILOT_MODEL=${ARG_COPILOT_MODEL:- ${COPILOT_MODEL:- not set} } "
102- echo " GitHub authentication: via Coder external auth"
103128
129+ setup_github_authentication
104130validate_copilot_installation
105131start_agentapi
0 commit comments