@github/copilot 0.0.354-12 → 0.0.354-13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -816,7 +816,7 @@ Read about how to prevent this error on https://github.com/vadimdemedes/ink/#isr
816
816
  `;if(this.options.debug){r&&(this.fullStaticOutput+=n),this.options.stdout.write(this.fullStaticOutput+e);return}if(lx){r&&this.options.stdout.write(n),this.lastOutput=e,this.lastOutputHeight=l;return}if(this.isScreenReaderEnabled){if(r){let s=this.lastOutputHeight>0?ap.eraseLines(this.lastOutputHeight):"";this.options.stdout.write(s+n),this.lastOutputHeight=0}if(e===this.lastOutput&&!r)return;let a=this.options.stdout.columns||80,I=FX(e,a,{trim:!1,hard:!0});if(r)this.options.stdout.write(I);else{let s=this.lastOutputHeight>0?ap.eraseLines(this.lastOutputHeight):"";this.options.stdout.write(s+I)}this.lastOutput=e,this.lastOutputHeight=I===""?0:I.split(`
817
817
  `).length;return}if(r&&(this.fullStaticOutput+=n),this.lastOutputHeight>=this.options.stdout.rows){this.options.stdout.write(ap.clearTerminal+this.fullStaticOutput+e),this.lastOutput=e,this.lastOutputHeight=l,this.log.sync(e);return}r&&(this.log.clear(),this.options.stdout.write(n),this.log(e)),!r&&e!==this.lastOutput&&this.throttledLog(e),this.lastOutput=e,this.lastOutputHeight=l};render(e){let l=z5e.default.createElement(XF.Provider,{value:{isScreenReaderEnabled:this.isScreenReaderEnabled}},z5e.default.createElement(ete,{stdin:this.options.stdin,stdout:this.options.stdout,stderr:this.options.stderr,writeToStdout:this.writeToStdout,writeToStderr:this.writeToStderr,exitOnCtrlC:this.options.exitOnCtrlC,onExit:this.unmount},e));HF.updateContainerSync(l,this.container,null,sut),HF.flushSyncWork()}writeToStdout(e){if(!this.isUnmounted){if(this.options.debug){this.options.stdout.write(e+this.fullStaticOutput+this.lastOutput);return}if(lx){this.options.stdout.write(e);return}this.log.clear(),this.options.stdout.write(e),this.log(this.lastOutput)}}writeToStderr(e){if(!this.isUnmounted){if(this.options.debug){this.options.stderr.write(e),this.options.stdout.write(this.fullStaticOutput+this.lastOutput);return}if(lx){this.options.stderr.write(e);return}this.log.clear(),this.options.stderr.write(e),this.log(this.lastOutput)}}unmount(e){this.isUnmounted||(this.calculateLayout(),this.onRender(),this.unsubscribeExit(),typeof this.restoreConsole=="function"&&this.restoreConsole(),typeof this.unsubscribeResize=="function"&&this.unsubscribeResize(),lx?this.options.stdout.write(this.lastOutput+`
818
818
  `):this.options.debug||this.log.done(),this.isUnmounted=!0,HF.updateContainerSync(null,this.container,null,sut),HF.flushSyncWork(),p_.delete(this.options.stdout),e instanceof Error?this.rejectExitPromise(e):this.resolveExitPromise())}async waitUntilExit(){return this.exitPromise||=new Promise((e,l)=>{this.resolveExitPromise=e,this.rejectExitPromise=l}),this.exitPromise}clear(){!lx&&!this.options.debug&&this.log.clear()}patchConsole(){this.options.debug||(this.restoreConsole=dhe((e,l)=>{e==="stdout"&&this.writeToStdout(l),e==="stderr"&&(l.startsWith("The above error occurred")||this.writeToStderr(l))}))}};var w1l=(t,e)=>{let l={stdout:zhe.stdout,stdin:zhe.stdin,stderr:zhe.stderr,debug:!1,exitOnCtrlC:!0,patchConsole:!0,maxFps:30,...Q1l(e)},n=F1l(l.stdout,()=>new tte(l));return n.render(t),{rerender:n.render,unmount(){n.unmount()},waitUntilExit:n.waitUntilExit,cleanup:()=>p_.delete(l.stdout),clear:n.clear}},lte=w1l,Q1l=(t={})=>t instanceof V1l?{stdout:t,stdin:zhe.stdin}:t,F1l=(t,e)=>{let l=p_.get(t);return l||(l=e(),p_.set(t,l)),l};var LF=$e($t(),1);function Phe(t){let{items:e,children:l,style:n}=t,[r,a]=(0,LF.useState)(0),I=(0,LF.useMemo)(()=>e.slice(r),[e,r]);(0,LF.useLayoutEffect)(()=>{a(e.length)},[e.length]);let s=I.map((c,d)=>l(c,r+d)),o=(0,LF.useMemo)(()=>({position:"absolute",flexDirection:"column",...n}),[n]);return LF.default.createElement("ink-box",{internal_static:!0,style:o},s)}var dut=$e($t(),1);var C1l=$e($t(),1);var v1l=$e($t(),1);var P5e=$e($t(),1);import{Buffer as f1l}from"node:buffer";var H1l=/^(?:\x1b)([a-zA-Z0-9])$/,X1l=/^(?:\x1b+)(O|N|\[|\[\[)(?:(\d+)(?:;(\d+))?([~^$])|(?:1;)?(\d+)?([a-zA-Z]))/,uut={OP:"f1",OQ:"f2",OR:"f3",OS:"f4","[11~":"f1","[12~":"f2","[13~":"f3","[14~":"f4","[[A":"f1","[[B":"f2","[[C":"f3","[[D":"f4","[[E":"f5","[15~":"f5","[17~":"f6","[18~":"f7","[19~":"f8","[20~":"f9","[21~":"f10","[23~":"f11","[24~":"f12","[A":"up","[B":"down","[C":"right","[D":"left","[E":"clear","[F":"end","[H":"home",OA:"up",OB:"down",OC:"right",OD:"left",OE:"clear",OF:"end",OH:"home","[1~":"home","[2~":"insert","[3~":"delete","[4~":"end","[5~":"pageup","[6~":"pagedown","[[5~":"pageup","[[6~":"pagedown","[7~":"home","[8~":"end","[a":"up","[b":"down","[c":"right","[d":"left","[e":"clear","[2$":"insert","[3$":"delete","[5$":"pageup","[6$":"pagedown","[7$":"home","[8$":"end",Oa:"up",Ob:"down",Oc:"right",Od:"left",Oe:"clear","[2^":"insert","[3^":"delete","[5^":"pageup","[6^":"pagedown","[7^":"home","[8^":"end","[Z":"tab"},mut=[...Object.values(uut),"backspace"],k1l=t=>["[a","[b","[c","[d","[e","[2$","[3$","[5$","[6$","[7$","[8$","[Z"].includes(t),L1l=t=>["Oa","Ob","Oc","Od","Oe","[2^","[3^","[5^","[6^","[7^","[8^"].includes(t),J1l=(t="")=>{let e;f1l.isBuffer(t)?t[0]>127&&t[1]===void 0?(t[0]-=128,t="\x1B"+String(t)):t=String(t):t!==void 0&&typeof t!="string"?t=String(t):t||(t="");let l={name:"",ctrl:!1,meta:!1,shift:!1,option:!1,sequence:t,raw:t};if(l.sequence=l.sequence||t||l.name,t==="\r")l.raw=void 0,l.name="return";else if(t===`
819
- `)l.name="enter";else if(t===" ")l.name="tab";else if(t==="\b"||t==="\x1B\b")l.name="backspace",l.meta=t.charAt(0)==="\x1B";else if(t==="\x7F"||t==="\x1B\x7F")l.name="delete",l.meta=t.charAt(0)==="\x1B";else if(t==="\x1B"||t==="\x1B\x1B")l.name="escape",l.meta=t.length===2;else if(t===" "||t==="\x1B ")l.name="space",l.meta=t.length===2;else if(t.length===1&&t<="")l.name=String.fromCharCode(t.charCodeAt(0)+97-1),l.ctrl=!0;else if(t.length===1&&t>="0"&&t<="9")l.name="number";else if(t.length===1&&t>="a"&&t<="z")l.name=t;else if(t.length===1&&t>="A"&&t<="Z")l.name=t.toLowerCase(),l.shift=!0;else if(e=H1l.exec(t))l.meta=!0,l.shift=/^[A-Z]$/.test(e[1]);else if(e=X1l.exec(t)){let n=[...t];n[0]==="\x1B"&&n[1]==="\x1B"&&(l.option=!0);let r=[e[1],e[2],e[4],e[6]].filter(Boolean).join(""),a=(e[3]||e[5]||1)-1;l.ctrl=!!(a&4),l.meta=!!(a&10),l.shift=!!(a&1),l.code=r,l.name=uut[r],l.shift=k1l(r)||l.shift,l.ctrl=L1l(r)||l.ctrl}return l},but=J1l;var Gut=$e($t(),1);var x1l=()=>(0,Gut.useContext)(Ohe),h_=x1l;var S1l=(t,e={})=>{let{stdin:l,setRawMode:n,internal_exitOnCtrlC:r,internal_eventEmitter:a}=h_();(0,P5e.useEffect)(()=>{if(e.isActive!==!1)return n(!0),()=>{n(!1)}},[e.isActive,n]),(0,P5e.useEffect)(()=>{if(e.isActive===!1)return;let I=s=>{let o=but(s),c={upArrow:o.name==="up",downArrow:o.name==="down",leftArrow:o.name==="left",rightArrow:o.name==="right",pageDown:o.name==="pagedown",pageUp:o.name==="pageup",return:o.name==="return",escape:o.name==="escape",ctrl:o.ctrl,shift:o.shift,tab:o.name==="tab",backspace:o.name==="backspace",delete:o.name==="delete",meta:o.meta||o.name==="escape"||o.option},d=o.ctrl?o.name:o.sequence;mut.includes(o.name)&&(d=""),d.startsWith("\x1B")&&(d=d.slice(1)),d.length===1&&typeof d[0]=="string"&&/[A-Z]/.test(d[0])&&(c.shift=!0),(!(d==="c"&&c.ctrl)||!r)&&HF.batchedUpdates(()=>{t(d,c)})};return a?.on("input",I),()=>{a?.removeListener("input",I)}},[e.isActive,l,r,t])},Z1=S1l;var B1l=$e($t(),1);var put=$e($t(),1);var T1l=()=>(0,put.useContext)(Uhe),OR=T1l;var O1l=$e($t(),1);var j5e=$e($t(),1);var U1l=$e($t(),1);var hut=$e($t(),1);var M1l=()=>{let{isScreenReaderEnabled:t}=(0,hut.useContext)(XF);return t},sx=M1l;var _1l=t=>({width:t.yogaNode?.getComputedWidth()??0,height:t.yogaNode?.getComputedHeight()??0}),jhe=_1l;var Bst=$e($t(),1);import Umr,{join as Sst}from"path";import{text as Mmr}from"stream/consumers";var ZZt=$e(dD(),1);var cp=[];for(let t=0;t<256;++t)cp.push((t+256).toString(16).slice(1));function zgt(t,e=0){return(cp[t[e+0]]+cp[t[e+1]]+cp[t[e+2]]+cp[t[e+3]]+"-"+cp[t[e+4]]+cp[t[e+5]]+"-"+cp[t[e+6]]+cp[t[e+7]]+"-"+cp[t[e+8]]+cp[t[e+9]]+"-"+cp[t[e+10]]+cp[t[e+11]]+cp[t[e+12]]+cp[t[e+13]]+cp[t[e+14]]+cp[t[e+15]]).toLowerCase()}import{randomFillSync as HLl}from"node:crypto";var Kge=new Uint8Array(256),jge=Kge.length;function EJe(){return jge>Kge.length-16&&(HLl(Kge),jge=0),Kge.slice(jge,jge+=16)}import{randomUUID as XLl}from"node:crypto";var RJe={randomUUID:XLl};function kLl(t,e,l){t=t||{};let n=t.random??t.rng?.()??EJe();if(n.length<16)throw new Error("Random bytes length must be >= 16");if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,e){if(l=l||0,l<0||l+16>e.length)throw new RangeError(`UUID byte range ${l}:${l+15} is out of buffer bounds`);for(let r=0;r<16;++r)e[l+r]=n[r];return e}return zgt(n)}function LLl(t,e,l){return RJe.randomUUID&&!e&&!t?RJe.randomUUID():kLl(t,e,l)}var cu=LLl;var zX=class{settings={};mergePartial(e,l){return{...e,...l}}setBlackbirdMode(e){return e!==void 0&&(e=="tool"||e=="initial-search")&&(this.settings.blackbird=this.mergePartial(this.settings.blackbird,{mode:e})),this}setSwebenchBaseCommit(e){return e!==void 0&&(this.settings.swebench_base_commit=e),this}setGithubUserName(e){if(e!==void 0){let l=this.settings.github?.user||{};this.settings.github=this.mergePartial(this.settings.github,{user:{...l,name:e}})}return this}setGithubUserEmail(e){if(e!==void 0){let l=this.settings.github?.user||{};this.settings.github=this.mergePartial(this.settings.github,{user:{...l,email:e}})}return this}setGithubToken(e){return e!==void 0&&(this.settings.github=this.mergePartial(this.settings.github,{token:e})),this}setGithubServerUrl(e){return e!==void 0&&(this.settings.github=this.mergePartial(this.settings.github,{serverUrl:e??"https://github.com"}),(!this.settings.github.host||!this.settings.github.hostProtocol)&&(this.settings.github=this.mergePartial(this.settings.github,new URL(e)))),this}setGithubHost(e){return e!==void 0&&(this.settings.github=this.mergePartial(this.settings.github,{host:e})),this}setGithubHostProtocol(e){return e!==void 0&&(this.settings.github=this.mergePartial(this.settings.github,{hostProtocol:e})),this}setGithubActorId(e){if(e!==void 0){let l=this.settings.github?.user||{};this.settings.github=this.mergePartial(this.settings.github,{user:{...l,actorId:e}})}return this}setGithubActorLogin(e){if(e!==void 0){let l=this.settings.github?.user||{};this.settings.github=this.mergePartial(this.settings.github,{user:{...l,actorLogin:e}})}return this}setAgentRuntimeVersion(e){return e!==void 0?this.settings.version=e:this.settings.version="latest",this}setGithubRepoName(e){if(e!==void 0){let l=this.settings.github?.repo||{};this.settings.github=this.mergePartial(this.settings.github,{repo:{...l,name:e}})}return this}setGithubRepoId(e){if(e!==void 0){let l=this.settings.github?.repo||{},n=Number(e);isNaN(n)||(this.settings.github=this.mergePartial(this.settings.github,{repo:{...l,id:n}}))}return this}setGithubRepoOwnerName(e){if(e!==void 0){let l=this.settings.github?.owner||{};this.settings.github=this.mergePartial(this.settings.github,{owner:{...l,name:e}})}return this}setGithubRepoOwnerId(e){if(e!==void 0){let l=this.settings.github?.owner||{},n=Number(e);isNaN(n)||(this.settings.github=this.mergePartial(this.settings.github,{owner:{...l,id:n}}))}return this}setGithubRepoBranch(e){if(e){let l=e.replace(/^refs\/heads\//,"");if(l.length===0)return this;let n=this.settings.github?.repo||{};this.settings.github=this.mergePartial(this.settings.github,{repo:{...n,branch:l}})}return this}setGithubRepoCommit(e){if(e!==void 0){let l=this.settings.github?.repo||{};this.settings.github=this.mergePartial(this.settings.github,{repo:{...l,commit:e}})}return this}setGithubRepoReadWrite(e){if(e!==void 0){let l=this.settings.github?.repo||{};this.settings.github=this.mergePartial(this.settings.github,{repo:{...l,readWrite:e}})}return this}setProblemStatement(e){return e!==void 0&&(this.settings.problem=this.mergePartial(this.settings.problem,{statement:e})),this}setProblemContentFilterMode(e){return e!==void 0&&(this.settings.problem=this.mergePartial(this.settings.problem,{contentFilterMode:e})),this}setProblemAction(e){return e!==void 0&&(this.settings.problem=this.mergePartial(this.settings.problem,{action:e})),this}setCustomAgentName(e){return e!==void 0&&(this.settings.problem=this.mergePartial(this.settings.problem,{customAgentName:e})),this}setGithubPRCommitCount(e){if(e!==void 0){let l=this.settings.github?.pr||{};this.settings.github=this.mergePartial(this.settings.github,{pr:{...l,commitCount:e}})}return this}setInstanceId(e){return this.settings.service=this.mergePartial(this.settings.service,{instance:{id:e??cu()}}),this}setAgentModel(e){if(e!==void 0){let l=this.settings.service?.agent||{};this.settings.service=this.mergePartial(this.settings.service,{agent:{...l,model:e}})}return this}setRequestHeaders(e){if(e!==void 0){let l=this.settings.service?.agent||{};this.settings.service=this.mergePartial(this.settings.service,{agent:{...l,requestHeaders:e}})}return this}setRetryPolicy(e){if(e!==void 0){let l=this.settings.service?.agent||{};this.settings.service=this.mergePartial(this.settings.service,{agent:{...l,retryPolicy:e}})}return this}setCallbackUrl(e){return e!==void 0&&(this.settings.service=this.mergePartial(this.settings.service,{callback:{url:e}})),this}setGitHubUploadsUrl(e){return e!==void 0&&(this.settings.github=this.mergePartial(this.settings.github,{uploadsUrl:e})),this}setGitHubDownloadsUrl(e){return e!==void 0&&(this.settings.github=this.mergePartial(this.settings.github,{downloadsUrl:e})),this}setAipSweAgentToken(e){return e!==void 0&&(this.settings.api=this.mergePartial(this.settings.api,{aipSweAgent:{token:e}})),this}setAnthropicApiKey(e){return e!==void 0&&(this.settings.api=this.mergePartial(this.settings.api,{anthropic:{key:e}})),this}setOpenAiApiKey(e){if(e!==void 0){let l=this.settings.api?.openai||{};this.settings.api=this.mergePartial(this.settings.api,{openai:{...l,apiKey:e}})}return this}setOpenAiBaseUrl(e){if(e!==void 0){let l=this.settings.api?.openai||{};this.settings.api=this.mergePartial(this.settings.api,{openai:{...l,baseUrl:e}})}return this}setAzureOpenAiUrl(e){if(e!==void 0){let l=this.settings.api?.openai||{};this.settings.api=this.mergePartial(this.settings.api,{openai:{...l,azure:{...l.azure,url:e}}})}return this}setAzureOpenAiApiVersion(e){if(e!==void 0){let l=this.settings.api?.openai||{};this.settings.api=this.mergePartial(this.settings.api,{openai:{...l,azure:{...l.azure,apiVersion:e}}})}return this}setAzureOpenAiKeyVaultUri(e){if(e!==void 0){let l=this.settings.api?.openai||{};this.settings.api=this.mergePartial(this.settings.api,{openai:{...l,azureKeyVaultUri:e}})}return this}setAzureOpenAiSecretName(e){if(e!==void 0){let l=this.settings.api?.openai||{};this.settings.api=this.mergePartial(this.settings.api,{openai:{...l,azureSecretName:e}})}return this}setCopilotUrl(e){if(e!==void 0){let l=this.settings.api?.copilot||{};this.settings.api=this.mergePartial(this.settings.api,{copilot:{...l,url:e}})}return this}setCopilotIntegrationId(e){if(e!==void 0){let l=this.settings.api?.copilot||{};this.settings.api=this.mergePartial(this.settings.api,{copilot:{...l,integrationId:e}})}return this}setCopilotHmacKey(e){if(e!==void 0){let l=this.settings.api?.copilot||{};this.settings.api=this.mergePartial(this.settings.api,{copilot:{...l,hmacKey:e}})}return this}setCopilotToken(e){if(e!==void 0){let l=this.settings.api?.copilot||{};this.settings.api=this.mergePartial(this.settings.api,{copilot:{...l,token:e}})}return this}setCopilotAzureKeyVaultUri(e){if(e!==void 0){let l=this.settings.api?.copilot||{};this.settings.api=this.mergePartial(this.settings.api,{copilot:{...l,azureKeyVaultUri:e}})}return this}setCopilotSessionId(e){if(e!==void 0){let l=this.settings.api?.copilot||{};this.settings.api=this.mergePartial(this.settings.api,{copilot:{...l,sessionId:e}})}return this}setCopilotPreviousSessionIds(e){if(e!==void 0){let l=this.settings.api?.copilot||{};this.settings.api=this.mergePartial(this.settings.api,{copilot:{...l,previousSessionIds:e.split(",").map(n=>n.trim()).filter(n=>n.length>0)}})}return this}setCopilotUseSessions(e){if(e!==void 0){let l=this.settings.api?.copilot||{};this.settings.api=this.mergePartial(this.settings.api,{copilot:{...l,useSessions:e}})}return this}setCopilotJobNonce(e){return e!==void 0&&(this.settings.job=this.mergePartial(this.settings.job,{nonce:e})),this}setCopilotJobEventType(e){return e!==void 0&&(this.settings.job=this.mergePartial(this.settings.job,{eventType:e})),this}setTrajectoryOutputFile(e){return e!==void 0&&(this.settings.trajectory=this.mergePartial(this.settings.trajectory,{outputFile:e})),this}setEventsLogDirectory(e){return e!==void 0&&(this.settings.logs=this.mergePartial(this.settings.logs,{eventsLogDir:e})),this}setDisableOnlineEvaluation(e){return e==!0&&this.settings.onlineEvaluation?.disableOnlineEvaluation!==!0&&(this.settings.onlineEvaluation=this.mergePartial(this.settings.onlineEvaluation,{disableOnlineEvaluation:e})),this}setEnableOnlineEvaluationOutputFile(e){return e==!0&&this.settings.onlineEvaluation?.enableOnlineEvaluationOutputFile!==!0&&(this.settings.onlineEvaluation=this.mergePartial(this.settings.onlineEvaluation,{enableOnlineEvaluationOutputFile:e})),this}setGitHubMCPServerToken(e){return e!==void 0&&(this.settings.api=this.mergePartial(this.settings.api,{github:{mcpServerToken:e}})),this}setFeatureFlagEnabled(e){return this.settings.featureFlags=this.mergePartial(this.settings.featureFlags,{[e]:!0}),this}setExperiment(e,l){return this.settings.experiments=this.mergePartial(this.settings.experiments,{[e]:l}),this}setTimeoutMs(e){return e!==void 0&&(this.settings.timeoutMs=e),this}setStartTimeMs(e){return e!==void 0&&(this.settings.startTimeMs=e),this}build(){return this.settings}};var qge=["GITHUB_TOKEN","GITHUB_COPILOT_API_TOKEN","CAPI_HMAC_KEY","CAPI_HMAC_KEY_OVERRIDE","ANTHROPIC_API_KEY","AIP_SWE_AGENT_TOKEN","CAPI_AZURE_KEY_VAULT_URI","COPILOT_JOB_NONCE","GITHUB_MCP_SERVER_TOKEN","OPENAI_BASE_URL","OPENAI_API_KEY","COPILOT_AGENT_REQUEST_HEADERS","AZURE_OPENAI_API_KEY","AZURE_OPENAI_API_ENDPOINT","AZURE_OPENAI_KEY_VAULT_URI","AZURE_OPENAI_KEY_VAULT_SECRET_NAME","BLACKBIRD_AUTH_METIS_API_KEY","BLACKBIRD_AUTH_MODEL_BASED_RETRIEVAL_TOKEN"],Pgt=["COPILOT_CALLBACK_URL","COPILOT_AGENT_MODEL","COPILOT_AGENT_JOB_ID","COPILOT_AGENT_PROMPT","COPILOT_AGENT_PUSH","COPILOT_FIREWALL_ENABLED","COPILOT_FIREWALL_ALLOW_LIST","GITHUB_COPILOT_INTEGRATION_ID","COPILOT_INTEGRATION_ID_OVERRIDE","COPILOT_AGENT_SESSION_ID","COPILOT_AGENT_PREVIOUS_SESSION_IDS","COPILOT_AGENT_EVENT_URL","COPILOT_AGENT_EVENT_TYPE","COPILOT_AGENT_ACTOR","COPILOT_AGENT_ACTOR_ID",...qge];async function jgt(){let t=new zX;t.setGithubServerUrl(process.env.GITHUB_SERVER_URL).setGithubHost(process.env.GITHUB_HOST).setGithubHostProtocol(process.env.GITHUB_HOST_PROTOCOL).setGithubToken(process.env.GITHUB_TOKEN).setGithubUserName(process.env.COPILOT_AGENT_COMMIT_LOGIN).setGithubUserEmail(process.env.COPILOT_AGENT_COMMIT_EMAIL).setGithubRepoOwnerId(process.env.GITHUB_REPOSITORY_OWNER_ID).setGithubRepoOwnerName(process.env.GITHUB_REPOSITORY_OWNER).setGithubRepoId(process.env.GITHUB_REPOSITORY_ID).setGithubRepoName(process.env.GITHUB_REPOSITORY).setGithubRepoBranch(process.env.COPILOT_AGENT_BRANCH_NAME).setGithubRepoCommit(process.env.COPILOT_AGENT_BASE_COMMIT).setAgentRuntimeVersion(process.env.COPILOT_AGENT_RUNTIME_VERSION),process.env.COPILOT_AGENT_PUSH!==void 0&&t.setGithubRepoReadWrite(process.env.COPILOT_AGENT_PUSH==="true"),t.setGithubPRCommitCount(process.env.COPILOT_AGENT_PR_COMMIT_COUNT?parseInt(process.env.COPILOT_AGENT_PR_COMMIT_COUNT,10):void 0),t.setProblemStatement(process.env.COPILOT_AGENT_PROMPT).setProblemContentFilterMode(process.env.COPILOT_AGENT_CONTENT_FILTER_MODE).setCustomAgentName(process.env.COPILOT_CUSTOM_AGENT);let e=process.env.COPILOT_AGENT_ACTION;if(e&&["fix","fix-pr-comment"].includes(e)&&t.setProblemAction(e),process.env.COPILOT_AGENT_ACTOR_ID&&t.setGithubActorId(parseInt(process.env.COPILOT_AGENT_ACTOR_ID,10)),process.env.COPILOT_AGENT_ACTOR&&t.setGithubActorLogin(process.env.COPILOT_AGENT_ACTOR),t.setInstanceId(process.env.COPILOT_AGENT_JOB_ID).setCopilotJobNonce(process.env.COPILOT_JOB_NONCE).setCopilotJobEventType(process.env.COPILOT_JOB_EVENT_TYPE).setAgentModel(process.env.COPILOT_AGENT_MODEL).setCallbackUrl(process.env.COPILOT_AGENT_CALLBACK_URL).setGitHubUploadsUrl(process.env.GITHUB_UPLOADS_URL).setGitHubDownloadsUrl(process.env.GITHUB_DOWNLOADS_URL),t.setAipSweAgentToken(process.env.AIP_SWE_AGENT_TOKEN).setAnthropicApiKey(process.env.ANTHROPIC_API_KEY).setCopilotUrl(process.env.COPILOT_API_URL).setCopilotIntegrationId(process.env.GITHUB_COPILOT_INTEGRATION_ID).setCopilotHmacKey(process.env.CAPI_HMAC_KEY).setCopilotToken(process.env.GITHUB_COPILOT_API_TOKEN).setCopilotAzureKeyVaultUri(process.env.CAPI_AZURE_KEY_VAULT_URI).setBlackbirdMode(process.env.BLACKBIRD_MODE||"initial-search").setCopilotSessionId(process.env.COPILOT_AGENT_SESSION_ID).setCopilotPreviousSessionIds(process.env.COPILOT_AGENT_PREVIOUS_SESSION_IDS).setSwebenchBaseCommit(process.env.SWEBENCH_BASE_COMMIT).setGitHubMCPServerToken(process.env.GITHUB_MCP_SERVER_TOKEN).setAzureOpenAiKeyVaultUri(process.env.AZURE_OPENAI_KEY_VAULT_URI).setAzureOpenAiSecretName(process.env.AZURE_OPENAI_KEY_VAULT_SECRET_NAME).setOpenAiBaseUrl(process.env.OPENAI_BASE_URL).setOpenAiApiKey(process.env.AZURE_OPENAI_API_KEY||process.env.OPENAI_API_KEY).setAzureOpenAiUrl(process.env.AZURE_OPENAI_API_ENDPOINT).setAzureOpenAiApiVersion(process.env.AZURE_OPENAI_API_VERSION),process.env.COPILOT_USE_SESSIONS!==void 0&&t.setCopilotUseSessions(process.env.COPILOT_USE_SESSIONS==="true"),t.setTrajectoryOutputFile(process.env.CPD_SAVE_TRAJECTORY_OUTPUT),t.setEventsLogDirectory(process.env.COPILOT_EVENTS_LOG_DIRECTORY),process.env.COPILOT_AGENT_ONLINE_EVALUATION_DISABLED!==void 0&&t.setDisableOnlineEvaluation(process.env.COPILOT_AGENT_ONLINE_EVALUATION_DISABLED==="true"),process.env.COPILOT_AGENT_ONLINE_EVALUATION_OUTPUT_FILE!==void 0&&t.setEnableOnlineEvaluationOutputFile(process.env.COPILOT_AGENT_ONLINE_EVALUATION_OUTPUT_FILE==="true"),process.env.COPILOT_FEATURE_FLAGS&&process.env.COPILOT_FEATURE_FLAGS.split(",").map(r=>r.trim()).filter(r=>r.length>0).forEach(r=>t.setFeatureFlagEnabled(r)),process.env.COPILOT_EXPERIMENTS&&process.env.COPILOT_EXPERIMENTS.split(",").map(r=>{let[a,I]=r.split(":");t.setExperiment(a,I)}),process.env.COPILOT_AGENT_ERROR_CODES_TO_RETRY){let r=process.env.COPILOT_AGENT_ERROR_CODES_TO_RETRY.split(",").map(a=>parseInt(a.trim(),10));t.setRetryPolicy({errorCodesToRetry:r})}if(process.env.COPILOT_AGENT_REQUEST_HEADERS)try{let r=JSON.parse(process.env.COPILOT_AGENT_REQUEST_HEADERS);t.setRequestHeaders(r)}catch{}let l=process.env.COPILOT_AGENT_TIMEOUT_MIN?parseInt(process.env.COPILOT_AGENT_TIMEOUT_MIN,10):void 0;l!==void 0&&!Number.isNaN(l)&&t.setTimeoutMs(l*60*1e3);let n=process.env.COPILOT_AGENT_START_TIME_SEC?parseInt(process.env.COPILOT_AGENT_START_TIME_SEC,10):void 0;return n!==void 0&&!Number.isNaN(n)&&t.setStartTimeMs(n*1e3),t.build()}var aZt=$e(qgt(),1);import{exec as rZt,execFile as BLl}from"child_process";var Ute=null;function bD(){return!!Ute}function YJe(){if(!Ute)throw new Error("Settings have not been initialized");return Ute}function $gt(t){return Ute=t,t}function Qx(){Ute=null}function to(t,e){return t?.featureFlags?.[e]??!1}function eZt(t,e){return t?.experiments?.[e]}function VJe(t){return Object.keys(t.featureFlags??{}).filter(e=>t.featureFlags?.[e]).join(",")}var xLl=["token","secret","key","hmacKey","modelBasedRetrievalToken","metisApiKey"];function wJe(t,e=[]){for(let[l,n]of Object.entries(t))if(n!==null)switch(typeof n){case"object":wJe(n,e);break;case"undefined":break;default:if(xLl.includes(l)){let r=n.toString().trim();r!=""&&e.push(r)}break}return e}function tZt(t,e){if(isNaN(e)||!isFinite(e)||e<=0)return{isWithin:!1,withinMs:e};if(e>1)return{isWithin:!1,withinMs:e};if(!t.timeoutMs)return{isWithin:!1,withinMs:e};let l=t.timeoutMs*e;return t.startTimeMs?{isWithin:Date.now()-t.startTimeMs>=t.timeoutMs-l,withinMs:l}:{isWithin:!1,withinMs:l}}import*as lZt from"process";function QJe(t){let e=lZt.env[t];if(e&&e.trim()!=="")return e}var SLl=[/\b(?:eyJ0eXAiOi|eyJhbGciOi|eyJ4NXQiOi|eyJraWQiOi)[^\s'";]+/g,/\bBearer\s+[^\s'";]+/g,/\b(?:Password|Pwd)=(?:[^\s'";]+|"[^"]+")/gi,/\s+-(?:Password|Pwd)\s+(?:[^\s'";]+|"[^"]+")/gi,/\bv1\.[0-9A-Fa-f]{40}\b/g,/\bgh[pousr]{1}_[A-Za-z0-9]{36}\b/g,/\bgithub_pat_[0-9][A-Za-z0-9]{21}_[A-Za-z0-9]{59}\b/g,/(?:[a-zA-Z][a-zA-Z\d+-.]*):\/\/([a-zA-Z\d\-._~!$&'()*+,;=%]+):([a-zA-Z\d\-._~!$&'()*+,;=:%]*)@/g,/\b[0-9A-Za-z-_~.]{3}7Q~[0-9A-Za-z-_~.]{31}\b|\b[0-9A-Za-z-_~.]{3}8Q~[0-9A-Za-z-_~.]{34}\b/g,/\b[0-9A-Za-z+/]{76}(APIM|ACDb|\+(ABa|AMC|ASt))[0-9A-Za-z+/]{5}[AQgw]==/g,/\b[0-9A-Za-z+/]{33}(AIoT|\+(ASb|AEh|ARm))[A-P][0-9A-Za-z+/]{5}=/g,/\b[0-9A-Za-z_-]{44}AzFu[0-9A-Za-z\-_]{5}[AQgw]==/g,/\b[0-9A-Za-z]{42}AzSe[A-D][0-9A-Za-z]{5}\b/g,/\b[0-9A-Za-z+/]{42}\+ACR[A-D][0-9A-Za-z+/]{5}\b/g,/\b[0-9A-Za-z]{33}AzCa[A-P][0-9A-Za-z]{5}=/g,/\boy2[a-p][0-9a-z]{15}[aq][0-9a-z]{11}[eu][bdfhjlnprtvxz357][a-p][0-9a-z]{11}[aeimquy4]\b/g,/\bnpm_[0-9A-Za-z]{36}\b/g,/\bx-ghcr-signature=[^&]+/g],nZt="******",X1=class t{static singleton;static getInstance(){return t.singleton||(t.singleton=new t),t.singleton}secretValuesToFilter;runner;logger;constructor(){}setRunner(e){this.runner=e,this.logger=e.logger,this.secretValuesToFilter=void 0}filterSecrets(e){let l=typeof e=="object"&&Object.prototype.hasOwnProperty.call(e,"message"),n=l?e.message??e.toString():e,r=this.getSecretValues();for(let a of r)n=n.replaceAll(a,nZt);for(let a of SLl)n=n.replaceAll(a,nZt);return l?(e.message=n,e):n}filterSecretsFromJsonString(e){try{let l=JSON.parse(e),n=this.filterSecretsFromObj(l);return JSON.stringify(n)}catch{return this.filterSecrets(e)}}filterSecretsFromObj(e){if(e==null)return e;if(typeof e=="string")return this.filterSecrets(e);if(typeof e=="number"){let l=this.filterSecrets(e.toString()),n=Number(l);return isNaN(n)?l:n}if(Array.isArray(e))return e.map(l=>this.filterSecretsFromObj(l));if(typeof e=="object"){let l={};for(let[n,r]of Object.entries(e))l[n]=this.filterSecretsFromObj(r);return l}return e}getSecretValues(){if(this.secretValuesToFilter)return this.secretValuesToFilter;let e={secretEnvVars:!1,runner:!1,settings:!1},l=new Set;for(let n of qge){let r=QJe(n);r&&FJe(l,r)}if(e.secretEnvVars=!0,this.runner){for(let n of this.runner.sensitiveKeys){let r=QJe(n);r&&FJe(l,r)}e.runner=!0}if(bD()){let n=wJe(YJe());for(let r of n)FJe(l,r);e.settings=!0}return Object.values(e).every(n=>n)&&(this.secretValuesToFilter=l,this.logger?.debug("Caching secret values to filter from all sources.")),l}};function FJe(t,e){t.add(e),t.add(Buffer.from(e,"utf8").toString("base64"))}function Mte(...t){let e=new Set(["DEBUG","COPILOT_AGENT_DEBUG",...t]);for(let l of e)if(process.env[l]==="1"||process.env[l]?.toLocaleLowerCase()==="true")return!0;return!1}var qF=class{logLevel;debugEnvironmentVariables;secretFilter=X1.getInstance();constructor(e,l){e===void 0?Mte(...l??[])?this.logLevel=15:this.logLevel=7:this.logLevel=e,this.debugEnvironmentVariables=l}filterSecrets(e){return typeof e=="string"?this.secretFilter.filterSecrets(e):this.secretFilter.filterSecrets(e)}shouldLog(e){return this.logLevel===void 0||(this.logLevel&e)===e}isDebug(){return Mte(...this.debugEnvironmentVariables??[])}};var XA=class{logger;constructor(e){this.logger=e}async exec(e,l,n,r=[]){let a=n?.silent??!1,I=n?.silentDebugLogging??!0;try{let s=(n?.isDirectAgentCommand?"Copilot: ":"")+(l?`${e} ${l.join(" ")}`:e);this.logger.startGroup(s,a?8:void 0);let o=await this._exec(e,l,n,r);if(o.error)throw o.error;return o.stdout&&(a?I&&this.logger.debug(o.stdout):this.logger.info(o.stdout)),o.stderr&&this.logger.error(o.stderr),0}catch(s){throw this.logger.error(s),s}finally{this.logger.endGroup(a?8:void 0)}}async execReturn(e,l,n,r=[]){let a=n?.silent??!1,I=n?.silentDebugLogging??!0;try{let s=(n?.isDirectAgentCommand?"Copilot: ":"")+(l?`${e} ${l.join(" ")}`:e);this.logger.startGroup(s,a?8:void 0);let o=await this._exec(e,l,n,r);if(o.error)throw o.error;return o.stdout&&(a?I&&this.logger.debug(o.stdout):this.logger.info(o.stdout)),o.stderr&&this.logger.error(o.stderr),{exitCode:o.exitCode,stdout:o.stdout,stderr:o.stderr}}catch(s){throw this.logger.error(s),s}finally{this.logger.endGroup(a?8:void 0)}}_exec(e,l,n,r=[]){n||(n={}),n.timeout||(n.timeout=9e5),l||(l=[]);let a={cwd:n.cwd,env:n.env,shell:n.shell,timeout:n.timeout,signal:n.abortSignal};return new Promise((I,s)=>{let o=n.shell&&l?.length===0?rZt(e,a):n.shell?rZt(`${e} ${(0,aZt.default)(l)}`,a):BLl(e,l,a),c="",d="";o.stdout?.on("data",m=>{c+=m}),o.stderr?.on("data",m=>{d+=m}),o.on("close",(m,G)=>{if(m!==0&&!n?.ignoreReturnCode){let p=this.filterCommand(e,l,r),A=new Error(`Command failed with exit code ${m}: ${p}`);A.cmd=p,A.code=m,A.stdout=c,A.stderr=d,A.signal=G,s(A)}else I({error:null,stdout:c,stderr:d,exitCode:m})}),o.on("error",m=>{m.stdout=c,m.stderr=d,m.cmd=this.filterCommand(e,l,r),s(m)}),n.input&&(o.stdin?.write(n.input),o.stdin?.end())})}filterCommand(e,l=[],n){let r=l.reduce((a,I)=>(n.includes(I)?a.push("REDACTED"):a.push(I),a),[]);return`${e} ${r.join(" ")}`}};import{randomUUID as TLl}from"crypto";import{cpSync as OLl,existsSync as AZt,mkdtempSync as ULl,rmSync as MLl}from"fs";import{homedir as gZt,tmpdir as _Ll}from"os";import{join as Pte}from"path";var $F=class t extends Error{cmd;killed;code;signal;stdout="";stderr="";errorType;skipReport;constructor(e,l,n=!1){if(!l){let r=e.code,a=e.message;"stdout"in e&&"stderr"in e&&(a+=`
819
+ `)l.name="enter";else if(t===" ")l.name="tab";else if(t==="\b"||t==="\x1B\b")l.name="backspace",l.meta=t.charAt(0)==="\x1B";else if(t==="\x7F"||t==="\x1B\x7F")l.name="delete",l.meta=t.charAt(0)==="\x1B";else if(t==="\x1B"||t==="\x1B\x1B")l.name="escape",l.meta=t.length===2;else if(t===" "||t==="\x1B ")l.name="space",l.meta=t.length===2;else if(t.length===1&&t<="")l.name=String.fromCharCode(t.charCodeAt(0)+97-1),l.ctrl=!0;else if(t.length===1&&t>="0"&&t<="9")l.name="number";else if(t.length===1&&t>="a"&&t<="z")l.name=t;else if(t.length===1&&t>="A"&&t<="Z")l.name=t.toLowerCase(),l.shift=!0;else if(e=H1l.exec(t))l.meta=!0,l.shift=/^[A-Z]$/.test(e[1]);else if(e=X1l.exec(t)){let n=[...t];n[0]==="\x1B"&&n[1]==="\x1B"&&(l.option=!0);let r=[e[1],e[2],e[4],e[6]].filter(Boolean).join(""),a=(e[3]||e[5]||1)-1;l.ctrl=!!(a&4),l.meta=!!(a&10),l.shift=!!(a&1),l.code=r,l.name=uut[r],l.shift=k1l(r)||l.shift,l.ctrl=L1l(r)||l.ctrl}return l},but=J1l;var Gut=$e($t(),1);var x1l=()=>(0,Gut.useContext)(Ohe),h_=x1l;var S1l=(t,e={})=>{let{stdin:l,setRawMode:n,internal_exitOnCtrlC:r,internal_eventEmitter:a}=h_();(0,P5e.useEffect)(()=>{if(e.isActive!==!1)return n(!0),()=>{n(!1)}},[e.isActive,n]),(0,P5e.useEffect)(()=>{if(e.isActive===!1)return;let I=s=>{let o=but(s),c={upArrow:o.name==="up",downArrow:o.name==="down",leftArrow:o.name==="left",rightArrow:o.name==="right",pageDown:o.name==="pagedown",pageUp:o.name==="pageup",return:o.name==="return",escape:o.name==="escape",ctrl:o.ctrl,shift:o.shift,tab:o.name==="tab",backspace:o.name==="backspace",delete:o.name==="delete",meta:o.meta||o.name==="escape"||o.option},d=o.ctrl?o.name:o.sequence;mut.includes(o.name)&&(d=""),d.startsWith("\x1B")&&(d=d.slice(1)),d.length===1&&typeof d[0]=="string"&&/[A-Z]/.test(d[0])&&(c.shift=!0),(!(d==="c"&&c.ctrl)||!r)&&HF.batchedUpdates(()=>{t(d,c)})};return a?.on("input",I),()=>{a?.removeListener("input",I)}},[e.isActive,l,r,t])},Z1=S1l;var B1l=$e($t(),1);var put=$e($t(),1);var T1l=()=>(0,put.useContext)(Uhe),OR=T1l;var O1l=$e($t(),1);var j5e=$e($t(),1);var U1l=$e($t(),1);var hut=$e($t(),1);var M1l=()=>{let{isScreenReaderEnabled:t}=(0,hut.useContext)(XF);return t},sx=M1l;var _1l=t=>({width:t.yogaNode?.getComputedWidth()??0,height:t.yogaNode?.getComputedHeight()??0}),jhe=_1l;var Bst=$e($t(),1);import Umr,{join as Sst}from"path";import{text as Mmr}from"stream/consumers";var ZZt=$e(dD(),1);var cp=[];for(let t=0;t<256;++t)cp.push((t+256).toString(16).slice(1));function zgt(t,e=0){return(cp[t[e+0]]+cp[t[e+1]]+cp[t[e+2]]+cp[t[e+3]]+"-"+cp[t[e+4]]+cp[t[e+5]]+"-"+cp[t[e+6]]+cp[t[e+7]]+"-"+cp[t[e+8]]+cp[t[e+9]]+"-"+cp[t[e+10]]+cp[t[e+11]]+cp[t[e+12]]+cp[t[e+13]]+cp[t[e+14]]+cp[t[e+15]]).toLowerCase()}import{randomFillSync as HLl}from"node:crypto";var Kge=new Uint8Array(256),jge=Kge.length;function EJe(){return jge>Kge.length-16&&(HLl(Kge),jge=0),Kge.slice(jge,jge+=16)}import{randomUUID as XLl}from"node:crypto";var RJe={randomUUID:XLl};function kLl(t,e,l){t=t||{};let n=t.random??t.rng?.()??EJe();if(n.length<16)throw new Error("Random bytes length must be >= 16");if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,e){if(l=l||0,l<0||l+16>e.length)throw new RangeError(`UUID byte range ${l}:${l+15} is out of buffer bounds`);for(let r=0;r<16;++r)e[l+r]=n[r];return e}return zgt(n)}function LLl(t,e,l){return RJe.randomUUID&&!e&&!t?RJe.randomUUID():kLl(t,e,l)}var cu=LLl;var zX=class{settings={};mergePartial(e,l){return{...e,...l}}setBlackbirdMode(e){return e!==void 0&&(e=="tool"||e=="initial-search")&&(this.settings.blackbird=this.mergePartial(this.settings.blackbird,{mode:e})),this}setSwebenchBaseCommit(e){return e!==void 0&&(this.settings.swebench_base_commit=e),this}setGithubUserName(e){if(e!==void 0){let l=this.settings.github?.user||{};this.settings.github=this.mergePartial(this.settings.github,{user:{...l,name:e}})}return this}setGithubUserEmail(e){if(e!==void 0){let l=this.settings.github?.user||{};this.settings.github=this.mergePartial(this.settings.github,{user:{...l,email:e}})}return this}setGithubToken(e){return e!==void 0&&(this.settings.github=this.mergePartial(this.settings.github,{token:e})),this}setGithubServerUrl(e){return e!==void 0&&(this.settings.github=this.mergePartial(this.settings.github,{serverUrl:e??"https://github.com"}),(!this.settings.github.host||!this.settings.github.hostProtocol)&&(this.settings.github=this.mergePartial(this.settings.github,new URL(e)))),this}setGithubHost(e){return e!==void 0&&(this.settings.github=this.mergePartial(this.settings.github,{host:e})),this}setGithubHostProtocol(e){return e!==void 0&&(this.settings.github=this.mergePartial(this.settings.github,{hostProtocol:e})),this}setGithubActorId(e){if(e!==void 0){let l=this.settings.github?.user||{};this.settings.github=this.mergePartial(this.settings.github,{user:{...l,actorId:e}})}return this}setGithubActorLogin(e){if(e!==void 0){let l=this.settings.github?.user||{};this.settings.github=this.mergePartial(this.settings.github,{user:{...l,actorLogin:e}})}return this}setAgentRuntimeVersion(e){return e!==void 0?this.settings.version=e:this.settings.version="latest",this}setGithubRepoName(e){if(e!==void 0){let l=this.settings.github?.repo||{};this.settings.github=this.mergePartial(this.settings.github,{repo:{...l,name:e}})}return this}setGithubRepoId(e){if(e!==void 0){let l=this.settings.github?.repo||{},n=Number(e);isNaN(n)||(this.settings.github=this.mergePartial(this.settings.github,{repo:{...l,id:n}}))}return this}setGithubRepoOwnerName(e){if(e!==void 0){let l=this.settings.github?.owner||{};this.settings.github=this.mergePartial(this.settings.github,{owner:{...l,name:e}})}return this}setGithubRepoOwnerId(e){if(e!==void 0){let l=this.settings.github?.owner||{},n=Number(e);isNaN(n)||(this.settings.github=this.mergePartial(this.settings.github,{owner:{...l,id:n}}))}return this}setGithubRepoBranch(e){if(e){let l=e.replace(/^refs\/heads\//,"");if(l.length===0)return this;let n=this.settings.github?.repo||{};this.settings.github=this.mergePartial(this.settings.github,{repo:{...n,branch:l}})}return this}setGithubRepoCommit(e){if(e!==void 0){let l=this.settings.github?.repo||{};this.settings.github=this.mergePartial(this.settings.github,{repo:{...l,commit:e}})}return this}setGithubRepoReadWrite(e){if(e!==void 0){let l=this.settings.github?.repo||{};this.settings.github=this.mergePartial(this.settings.github,{repo:{...l,readWrite:e}})}return this}setProblemStatement(e){return e!==void 0&&(this.settings.problem=this.mergePartial(this.settings.problem,{statement:e})),this}setProblemContentFilterMode(e){return e!==void 0&&(this.settings.problem=this.mergePartial(this.settings.problem,{contentFilterMode:e})),this}setProblemAction(e){return e!==void 0&&(this.settings.problem=this.mergePartial(this.settings.problem,{action:e})),this}setCustomAgentName(e){return e!==void 0&&(this.settings.problem=this.mergePartial(this.settings.problem,{customAgentName:e})),this}setGithubPRCommitCount(e){if(e!==void 0){let l=this.settings.github?.pr||{};this.settings.github=this.mergePartial(this.settings.github,{pr:{...l,commitCount:e}})}return this}setInstanceId(e){return this.settings.service=this.mergePartial(this.settings.service,{instance:{id:e??cu()}}),this}setAgentModel(e){if(e!==void 0){let l=this.settings.service?.agent||{};this.settings.service=this.mergePartial(this.settings.service,{agent:{...l,model:e}})}return this}setRequestHeaders(e){if(e!==void 0){let l=this.settings.service?.agent||{};this.settings.service=this.mergePartial(this.settings.service,{agent:{...l,requestHeaders:e}})}return this}setRetryPolicy(e){if(e!==void 0){let l=this.settings.service?.agent||{};this.settings.service=this.mergePartial(this.settings.service,{agent:{...l,retryPolicy:e}})}return this}setCallbackUrl(e){return e!==void 0&&(this.settings.service=this.mergePartial(this.settings.service,{callback:{url:e}})),this}setGitHubUploadsUrl(e){return e!==void 0&&(this.settings.github=this.mergePartial(this.settings.github,{uploadsUrl:e})),this}setGitHubDownloadsUrl(e){return e!==void 0&&(this.settings.github=this.mergePartial(this.settings.github,{downloadsUrl:e})),this}setAipSweAgentToken(e){return e!==void 0&&(this.settings.api=this.mergePartial(this.settings.api,{aipSweAgent:{token:e}})),this}setAnthropicApiKey(e){return e!==void 0&&(this.settings.api=this.mergePartial(this.settings.api,{anthropic:{key:e}})),this}setOpenAiApiKey(e){if(e!==void 0){let l=this.settings.api?.openai||{};this.settings.api=this.mergePartial(this.settings.api,{openai:{...l,apiKey:e}})}return this}setOpenAiBaseUrl(e){if(e!==void 0){let l=this.settings.api?.openai||{};this.settings.api=this.mergePartial(this.settings.api,{openai:{...l,baseUrl:e}})}return this}setAzureOpenAiUrl(e){if(e!==void 0){let l=this.settings.api?.openai||{};this.settings.api=this.mergePartial(this.settings.api,{openai:{...l,azure:{...l.azure,url:e}}})}return this}setAzureOpenAiApiVersion(e){if(e!==void 0){let l=this.settings.api?.openai||{};this.settings.api=this.mergePartial(this.settings.api,{openai:{...l,azure:{...l.azure,apiVersion:e}}})}return this}setAzureOpenAiKeyVaultUri(e){if(e!==void 0){let l=this.settings.api?.openai||{};this.settings.api=this.mergePartial(this.settings.api,{openai:{...l,azureKeyVaultUri:e}})}return this}setAzureOpenAiSecretName(e){if(e!==void 0){let l=this.settings.api?.openai||{};this.settings.api=this.mergePartial(this.settings.api,{openai:{...l,azureSecretName:e}})}return this}setCopilotUrl(e){if(e!==void 0){let l=this.settings.api?.copilot||{};this.settings.api=this.mergePartial(this.settings.api,{copilot:{...l,url:e}})}return this}setCopilotIntegrationId(e){if(e!==void 0){let l=this.settings.api?.copilot||{};this.settings.api=this.mergePartial(this.settings.api,{copilot:{...l,integrationId:e}})}return this}setCopilotHmacKey(e){if(e!==void 0){let l=this.settings.api?.copilot||{};this.settings.api=this.mergePartial(this.settings.api,{copilot:{...l,hmacKey:e}})}return this}setCopilotToken(e){if(e!==void 0){let l=this.settings.api?.copilot||{};this.settings.api=this.mergePartial(this.settings.api,{copilot:{...l,token:e}})}return this}setCopilotAzureKeyVaultUri(e){if(e!==void 0){let l=this.settings.api?.copilot||{};this.settings.api=this.mergePartial(this.settings.api,{copilot:{...l,azureKeyVaultUri:e}})}return this}setCopilotSessionId(e){if(e!==void 0){let l=this.settings.api?.copilot||{};this.settings.api=this.mergePartial(this.settings.api,{copilot:{...l,sessionId:e}})}return this}setCopilotPreviousSessionIds(e){if(e!==void 0){let l=this.settings.api?.copilot||{};this.settings.api=this.mergePartial(this.settings.api,{copilot:{...l,previousSessionIds:e.split(",").map(n=>n.trim()).filter(n=>n.length>0)}})}return this}setCopilotUseSessions(e){if(e!==void 0){let l=this.settings.api?.copilot||{};this.settings.api=this.mergePartial(this.settings.api,{copilot:{...l,useSessions:e}})}return this}setCopilotJobNonce(e){return e!==void 0&&(this.settings.job=this.mergePartial(this.settings.job,{nonce:e})),this}setCopilotJobEventType(e){return e!==void 0&&(this.settings.job=this.mergePartial(this.settings.job,{eventType:e})),this}setTrajectoryOutputFile(e){return e!==void 0&&(this.settings.trajectory=this.mergePartial(this.settings.trajectory,{outputFile:e})),this}setEventsLogDirectory(e){return e!==void 0&&(this.settings.logs=this.mergePartial(this.settings.logs,{eventsLogDir:e})),this}setDisableOnlineEvaluation(e){return e==!0&&this.settings.onlineEvaluation?.disableOnlineEvaluation!==!0&&(this.settings.onlineEvaluation=this.mergePartial(this.settings.onlineEvaluation,{disableOnlineEvaluation:e})),this}setEnableOnlineEvaluationOutputFile(e){return e==!0&&this.settings.onlineEvaluation?.enableOnlineEvaluationOutputFile!==!0&&(this.settings.onlineEvaluation=this.mergePartial(this.settings.onlineEvaluation,{enableOnlineEvaluationOutputFile:e})),this}setGitHubMCPServerToken(e){return e!==void 0&&(this.settings.api=this.mergePartial(this.settings.api,{github:{mcpServerToken:e}})),this}setFeatureFlagEnabled(e){return this.settings.featureFlags=this.mergePartial(this.settings.featureFlags,{[e]:!0}),this}setExperiment(e,l){return this.settings.experiments=this.mergePartial(this.settings.experiments,{[e]:l}),this}setTimeoutMs(e){return e!==void 0&&(this.settings.timeoutMs=e),this}setStartTimeMs(e){return e!==void 0&&(this.settings.startTimeMs=e),this}build(){return this.settings}};var qge=["GITHUB_TOKEN","COPILOT_GITHUB_TOKEN","GITHUB_COPILOT_API_TOKEN","CAPI_HMAC_KEY","CAPI_HMAC_KEY_OVERRIDE","ANTHROPIC_API_KEY","AIP_SWE_AGENT_TOKEN","CAPI_AZURE_KEY_VAULT_URI","COPILOT_JOB_NONCE","GITHUB_MCP_SERVER_TOKEN","OPENAI_BASE_URL","OPENAI_API_KEY","COPILOT_AGENT_REQUEST_HEADERS","AZURE_OPENAI_API_KEY","AZURE_OPENAI_API_ENDPOINT","AZURE_OPENAI_KEY_VAULT_URI","AZURE_OPENAI_KEY_VAULT_SECRET_NAME","BLACKBIRD_AUTH_METIS_API_KEY","BLACKBIRD_AUTH_MODEL_BASED_RETRIEVAL_TOKEN"],Pgt=["COPILOT_CALLBACK_URL","COPILOT_AGENT_MODEL","COPILOT_AGENT_JOB_ID","COPILOT_AGENT_PROMPT","COPILOT_AGENT_PUSH","COPILOT_FIREWALL_ENABLED","COPILOT_FIREWALL_ALLOW_LIST","GITHUB_COPILOT_INTEGRATION_ID","COPILOT_INTEGRATION_ID_OVERRIDE","COPILOT_AGENT_SESSION_ID","COPILOT_AGENT_PREVIOUS_SESSION_IDS","COPILOT_AGENT_EVENT_URL","COPILOT_AGENT_EVENT_TYPE","COPILOT_AGENT_ACTOR","COPILOT_AGENT_ACTOR_ID",...qge];async function jgt(){let t=new zX;t.setGithubServerUrl(process.env.GITHUB_SERVER_URL).setGithubHost(process.env.GITHUB_HOST).setGithubHostProtocol(process.env.GITHUB_HOST_PROTOCOL).setGithubToken(process.env.GITHUB_TOKEN).setGithubUserName(process.env.COPILOT_AGENT_COMMIT_LOGIN).setGithubUserEmail(process.env.COPILOT_AGENT_COMMIT_EMAIL).setGithubRepoOwnerId(process.env.GITHUB_REPOSITORY_OWNER_ID).setGithubRepoOwnerName(process.env.GITHUB_REPOSITORY_OWNER).setGithubRepoId(process.env.GITHUB_REPOSITORY_ID).setGithubRepoName(process.env.GITHUB_REPOSITORY).setGithubRepoBranch(process.env.COPILOT_AGENT_BRANCH_NAME).setGithubRepoCommit(process.env.COPILOT_AGENT_BASE_COMMIT).setAgentRuntimeVersion(process.env.COPILOT_AGENT_RUNTIME_VERSION),process.env.COPILOT_AGENT_PUSH!==void 0&&t.setGithubRepoReadWrite(process.env.COPILOT_AGENT_PUSH==="true"),t.setGithubPRCommitCount(process.env.COPILOT_AGENT_PR_COMMIT_COUNT?parseInt(process.env.COPILOT_AGENT_PR_COMMIT_COUNT,10):void 0),t.setProblemStatement(process.env.COPILOT_AGENT_PROMPT).setProblemContentFilterMode(process.env.COPILOT_AGENT_CONTENT_FILTER_MODE).setCustomAgentName(process.env.COPILOT_CUSTOM_AGENT);let e=process.env.COPILOT_AGENT_ACTION;if(e&&["fix","fix-pr-comment"].includes(e)&&t.setProblemAction(e),process.env.COPILOT_AGENT_ACTOR_ID&&t.setGithubActorId(parseInt(process.env.COPILOT_AGENT_ACTOR_ID,10)),process.env.COPILOT_AGENT_ACTOR&&t.setGithubActorLogin(process.env.COPILOT_AGENT_ACTOR),t.setInstanceId(process.env.COPILOT_AGENT_JOB_ID).setCopilotJobNonce(process.env.COPILOT_JOB_NONCE).setCopilotJobEventType(process.env.COPILOT_JOB_EVENT_TYPE).setAgentModel(process.env.COPILOT_AGENT_MODEL).setCallbackUrl(process.env.COPILOT_AGENT_CALLBACK_URL).setGitHubUploadsUrl(process.env.GITHUB_UPLOADS_URL).setGitHubDownloadsUrl(process.env.GITHUB_DOWNLOADS_URL),t.setAipSweAgentToken(process.env.AIP_SWE_AGENT_TOKEN).setAnthropicApiKey(process.env.ANTHROPIC_API_KEY).setCopilotUrl(process.env.COPILOT_API_URL).setCopilotIntegrationId(process.env.GITHUB_COPILOT_INTEGRATION_ID).setCopilotHmacKey(process.env.CAPI_HMAC_KEY).setCopilotToken(process.env.GITHUB_COPILOT_API_TOKEN).setCopilotAzureKeyVaultUri(process.env.CAPI_AZURE_KEY_VAULT_URI).setBlackbirdMode(process.env.BLACKBIRD_MODE||"initial-search").setCopilotSessionId(process.env.COPILOT_AGENT_SESSION_ID).setCopilotPreviousSessionIds(process.env.COPILOT_AGENT_PREVIOUS_SESSION_IDS).setSwebenchBaseCommit(process.env.SWEBENCH_BASE_COMMIT).setGitHubMCPServerToken(process.env.GITHUB_MCP_SERVER_TOKEN).setAzureOpenAiKeyVaultUri(process.env.AZURE_OPENAI_KEY_VAULT_URI).setAzureOpenAiSecretName(process.env.AZURE_OPENAI_KEY_VAULT_SECRET_NAME).setOpenAiBaseUrl(process.env.OPENAI_BASE_URL).setOpenAiApiKey(process.env.AZURE_OPENAI_API_KEY||process.env.OPENAI_API_KEY).setAzureOpenAiUrl(process.env.AZURE_OPENAI_API_ENDPOINT).setAzureOpenAiApiVersion(process.env.AZURE_OPENAI_API_VERSION),process.env.COPILOT_USE_SESSIONS!==void 0&&t.setCopilotUseSessions(process.env.COPILOT_USE_SESSIONS==="true"),t.setTrajectoryOutputFile(process.env.CPD_SAVE_TRAJECTORY_OUTPUT),t.setEventsLogDirectory(process.env.COPILOT_EVENTS_LOG_DIRECTORY),process.env.COPILOT_AGENT_ONLINE_EVALUATION_DISABLED!==void 0&&t.setDisableOnlineEvaluation(process.env.COPILOT_AGENT_ONLINE_EVALUATION_DISABLED==="true"),process.env.COPILOT_AGENT_ONLINE_EVALUATION_OUTPUT_FILE!==void 0&&t.setEnableOnlineEvaluationOutputFile(process.env.COPILOT_AGENT_ONLINE_EVALUATION_OUTPUT_FILE==="true"),process.env.COPILOT_FEATURE_FLAGS&&process.env.COPILOT_FEATURE_FLAGS.split(",").map(r=>r.trim()).filter(r=>r.length>0).forEach(r=>t.setFeatureFlagEnabled(r)),process.env.COPILOT_EXPERIMENTS&&process.env.COPILOT_EXPERIMENTS.split(",").map(r=>{let[a,I]=r.split(":");t.setExperiment(a,I)}),process.env.COPILOT_AGENT_ERROR_CODES_TO_RETRY){let r=process.env.COPILOT_AGENT_ERROR_CODES_TO_RETRY.split(",").map(a=>parseInt(a.trim(),10));t.setRetryPolicy({errorCodesToRetry:r})}if(process.env.COPILOT_AGENT_REQUEST_HEADERS)try{let r=JSON.parse(process.env.COPILOT_AGENT_REQUEST_HEADERS);t.setRequestHeaders(r)}catch{}let l=process.env.COPILOT_AGENT_TIMEOUT_MIN?parseInt(process.env.COPILOT_AGENT_TIMEOUT_MIN,10):void 0;l!==void 0&&!Number.isNaN(l)&&t.setTimeoutMs(l*60*1e3);let n=process.env.COPILOT_AGENT_START_TIME_SEC?parseInt(process.env.COPILOT_AGENT_START_TIME_SEC,10):void 0;return n!==void 0&&!Number.isNaN(n)&&t.setStartTimeMs(n*1e3),t.build()}var aZt=$e(qgt(),1);import{exec as rZt,execFile as BLl}from"child_process";var Ute=null;function bD(){return!!Ute}function YJe(){if(!Ute)throw new Error("Settings have not been initialized");return Ute}function $gt(t){return Ute=t,t}function Qx(){Ute=null}function to(t,e){return t?.featureFlags?.[e]??!1}function eZt(t,e){return t?.experiments?.[e]}function VJe(t){return Object.keys(t.featureFlags??{}).filter(e=>t.featureFlags?.[e]).join(",")}var xLl=["token","secret","key","hmacKey","modelBasedRetrievalToken","metisApiKey"];function wJe(t,e=[]){for(let[l,n]of Object.entries(t))if(n!==null)switch(typeof n){case"object":wJe(n,e);break;case"undefined":break;default:if(xLl.includes(l)){let r=n.toString().trim();r!=""&&e.push(r)}break}return e}function tZt(t,e){if(isNaN(e)||!isFinite(e)||e<=0)return{isWithin:!1,withinMs:e};if(e>1)return{isWithin:!1,withinMs:e};if(!t.timeoutMs)return{isWithin:!1,withinMs:e};let l=t.timeoutMs*e;return t.startTimeMs?{isWithin:Date.now()-t.startTimeMs>=t.timeoutMs-l,withinMs:l}:{isWithin:!1,withinMs:l}}import*as lZt from"process";function QJe(t){let e=lZt.env[t];if(e&&e.trim()!=="")return e}var SLl=[/\b(?:eyJ0eXAiOi|eyJhbGciOi|eyJ4NXQiOi|eyJraWQiOi)[^\s'";]+/g,/\bBearer\s+[^\s'";]+/g,/\b(?:Password|Pwd)=(?:[^\s'";]+|"[^"]+")/gi,/\s+-(?:Password|Pwd)\s+(?:[^\s'";]+|"[^"]+")/gi,/\bv1\.[0-9A-Fa-f]{40}\b/g,/\bgh[pousr]{1}_[A-Za-z0-9]{36}\b/g,/\bgithub_pat_[0-9][A-Za-z0-9]{21}_[A-Za-z0-9]{59}\b/g,/(?:[a-zA-Z][a-zA-Z\d+-.]*):\/\/([a-zA-Z\d\-._~!$&'()*+,;=%]+):([a-zA-Z\d\-._~!$&'()*+,;=:%]*)@/g,/\b[0-9A-Za-z-_~.]{3}7Q~[0-9A-Za-z-_~.]{31}\b|\b[0-9A-Za-z-_~.]{3}8Q~[0-9A-Za-z-_~.]{34}\b/g,/\b[0-9A-Za-z+/]{76}(APIM|ACDb|\+(ABa|AMC|ASt))[0-9A-Za-z+/]{5}[AQgw]==/g,/\b[0-9A-Za-z+/]{33}(AIoT|\+(ASb|AEh|ARm))[A-P][0-9A-Za-z+/]{5}=/g,/\b[0-9A-Za-z_-]{44}AzFu[0-9A-Za-z\-_]{5}[AQgw]==/g,/\b[0-9A-Za-z]{42}AzSe[A-D][0-9A-Za-z]{5}\b/g,/\b[0-9A-Za-z+/]{42}\+ACR[A-D][0-9A-Za-z+/]{5}\b/g,/\b[0-9A-Za-z]{33}AzCa[A-P][0-9A-Za-z]{5}=/g,/\boy2[a-p][0-9a-z]{15}[aq][0-9a-z]{11}[eu][bdfhjlnprtvxz357][a-p][0-9a-z]{11}[aeimquy4]\b/g,/\bnpm_[0-9A-Za-z]{36}\b/g,/\bx-ghcr-signature=[^&]+/g],nZt="******",X1=class t{static singleton;static getInstance(){return t.singleton||(t.singleton=new t),t.singleton}secretValuesToFilter;runner;logger;constructor(){}setRunner(e){this.runner=e,this.logger=e.logger,this.secretValuesToFilter=void 0}filterSecrets(e){let l=typeof e=="object"&&Object.prototype.hasOwnProperty.call(e,"message"),n=l?e.message??e.toString():e,r=this.getSecretValues();for(let a of r)n=n.replaceAll(a,nZt);for(let a of SLl)n=n.replaceAll(a,nZt);return l?(e.message=n,e):n}filterSecretsFromJsonString(e){try{let l=JSON.parse(e),n=this.filterSecretsFromObj(l);return JSON.stringify(n)}catch{return this.filterSecrets(e)}}filterSecretsFromObj(e){if(e==null)return e;if(typeof e=="string")return this.filterSecrets(e);if(typeof e=="number"){let l=this.filterSecrets(e.toString()),n=Number(l);return isNaN(n)?l:n}if(Array.isArray(e))return e.map(l=>this.filterSecretsFromObj(l));if(typeof e=="object"){let l={};for(let[n,r]of Object.entries(e))l[n]=this.filterSecretsFromObj(r);return l}return e}getSecretValues(){if(this.secretValuesToFilter)return this.secretValuesToFilter;let e={secretEnvVars:!1,runner:!1,settings:!1},l=new Set;for(let n of qge){let r=QJe(n);r&&FJe(l,r)}if(e.secretEnvVars=!0,this.runner){for(let n of this.runner.sensitiveKeys){let r=QJe(n);r&&FJe(l,r)}e.runner=!0}if(bD()){let n=wJe(YJe());for(let r of n)FJe(l,r);e.settings=!0}return Object.values(e).every(n=>n)&&(this.secretValuesToFilter=l,this.logger?.debug("Caching secret values to filter from all sources.")),l}};function FJe(t,e){t.add(e),t.add(Buffer.from(e,"utf8").toString("base64"))}function Mte(...t){let e=new Set(["DEBUG","COPILOT_AGENT_DEBUG",...t]);for(let l of e)if(process.env[l]==="1"||process.env[l]?.toLocaleLowerCase()==="true")return!0;return!1}var qF=class{logLevel;debugEnvironmentVariables;secretFilter=X1.getInstance();constructor(e,l){e===void 0?Mte(...l??[])?this.logLevel=15:this.logLevel=7:this.logLevel=e,this.debugEnvironmentVariables=l}filterSecrets(e){return typeof e=="string"?this.secretFilter.filterSecrets(e):this.secretFilter.filterSecrets(e)}shouldLog(e){return this.logLevel===void 0||(this.logLevel&e)===e}isDebug(){return Mte(...this.debugEnvironmentVariables??[])}};var XA=class{logger;constructor(e){this.logger=e}async exec(e,l,n,r=[]){let a=n?.silent??!1,I=n?.silentDebugLogging??!0;try{let s=(n?.isDirectAgentCommand?"Copilot: ":"")+(l?`${e} ${l.join(" ")}`:e);this.logger.startGroup(s,a?8:void 0);let o=await this._exec(e,l,n,r);if(o.error)throw o.error;return o.stdout&&(a?I&&this.logger.debug(o.stdout):this.logger.info(o.stdout)),o.stderr&&this.logger.error(o.stderr),0}catch(s){throw this.logger.error(s),s}finally{this.logger.endGroup(a?8:void 0)}}async execReturn(e,l,n,r=[]){let a=n?.silent??!1,I=n?.silentDebugLogging??!0;try{let s=(n?.isDirectAgentCommand?"Copilot: ":"")+(l?`${e} ${l.join(" ")}`:e);this.logger.startGroup(s,a?8:void 0);let o=await this._exec(e,l,n,r);if(o.error)throw o.error;return o.stdout&&(a?I&&this.logger.debug(o.stdout):this.logger.info(o.stdout)),o.stderr&&this.logger.error(o.stderr),{exitCode:o.exitCode,stdout:o.stdout,stderr:o.stderr}}catch(s){throw this.logger.error(s),s}finally{this.logger.endGroup(a?8:void 0)}}_exec(e,l,n,r=[]){n||(n={}),n.timeout||(n.timeout=9e5),l||(l=[]);let a={cwd:n.cwd,env:n.env,shell:n.shell,timeout:n.timeout,signal:n.abortSignal};return new Promise((I,s)=>{let o=n.shell&&l?.length===0?rZt(e,a):n.shell?rZt(`${e} ${(0,aZt.default)(l)}`,a):BLl(e,l,a),c="",d="";o.stdout?.on("data",m=>{c+=m}),o.stderr?.on("data",m=>{d+=m}),o.on("close",(m,G)=>{if(m!==0&&!n?.ignoreReturnCode){let p=this.filterCommand(e,l,r),A=new Error(`Command failed with exit code ${m}: ${p}`);A.cmd=p,A.code=m,A.stdout=c,A.stderr=d,A.signal=G,s(A)}else I({error:null,stdout:c,stderr:d,exitCode:m})}),o.on("error",m=>{m.stdout=c,m.stderr=d,m.cmd=this.filterCommand(e,l,r),s(m)}),n.input&&(o.stdin?.write(n.input),o.stdin?.end())})}filterCommand(e,l=[],n){let r=l.reduce((a,I)=>(n.includes(I)?a.push("REDACTED"):a.push(I),a),[]);return`${e} ${r.join(" ")}`}};import{randomUUID as TLl}from"crypto";import{cpSync as OLl,existsSync as AZt,mkdtempSync as ULl,rmSync as MLl}from"fs";import{homedir as gZt,tmpdir as _Ll}from"os";import{join as Pte}from"path";var $F=class t extends Error{cmd;killed;code;signal;stdout="";stderr="";errorType;skipReport;constructor(e,l,n=!1){if(!l){let r=e.code,a=e.message;"stdout"in e&&"stderr"in e&&(a+=`
820
820
  `+e.stderr?.trim()+`
821
821
  `+e.stdout?.trim()),a.includes("GH013: Repository rule violations found")||a.includes("unknown revision or path not in the working tree")?(l="protection rule",n=!0):a.includes("You may want to try Git Large File Storage")||a.includes("GH001: Large files detected")?(l="LFS",n=!0):r===1&&(a.includes("hook failed")||a.includes("husky -")||a.includes("hook declined")||a.includes("hook exited")||a.includes("vite ")||a.includes("eslint "))?(l="hook",n=!0):a.includes("use 'git pull' before pushing again")?(l="pull first",n=!0):a.includes("fetch first")?(l="fetch first",n=!0):a.includes("The requested URL returned error: 403")?(l="access denied",n=!1):a.includes("unexpected disconnect")?(l="disconnect",n=!1):(l="unknown",n=!(r==="ENOENT"||r===127||r===128||a.includes("fatal: ")))}super(`${l} git error: ${e.message}`);for(let r of Object.keys(e))this[r]=e[r];this.errorType=l??"unknown",this.skipReport=n,this.cause=e,Object.setPrototypeOf(this,t.prototype),this.name="GitError"}};var _te="https://api.githubcopilot.com";function IZt(t){if(!t.github?.user?.name)throw new Error("GitHub user name is required");return t.github.user.name}function sZt(t){if(!t.github?.user?.email)throw new Error("GitHub user email is required");return t.github.user.email}function oZt(t){let e=t.github?.user?.actorLogin,l=t.github?.user?.actorId;if(!(!e||!l))return{login:e,id:l}}function $ge(t){if(!t.github?.serverUrl)throw new Error("GitHub server URL is required");return t.github.serverUrl}function eZe(t){if(!t.github?.host)throw new Error("GitHub host is required");return t.github.host}function iZt(t){if(!t.github?.hostProtocol)throw new Error("GitHub host protocol is required");return t.github.hostProtocol}function Fx(t){if(!t.github?.token)throw new Error("GitHub token is required");return t.github.token}function tZe(t){if(!t.github?.repo?.name)throw new Error("GitHub repository name is required");return t.github.repo.name}function eC(t){if(!t.service?.instance?.id)throw new Error("Instance ID is required");return t.service.instance.id}function cZt(t){if(!t.service?.callback?.url)throw new Error("Callback URL is required");return t.service.callback.url}function dZt(t){if(!t.api?.anthropic?.key)throw new Error("Anthropic API key is required");return t.api.anthropic.key}function uZt(t){if(!t.api?.openai?.apiKey)throw new Error("OpenAI API key is required");return t.api.openai.apiKey}function mZt(t){if(!t.api?.openai?.azure?.url)throw new Error("Azure OpenAI deployment URL is required");return t.api.openai.azure.url}function bZt(t,e=_te){let l=t.api?.copilot?.url||e;if(!l)throw new Error("Copilot URL is required");return l}function Dte(t){if(!t.api?.copilot?.integrationId)throw new Error("Copilot integration ID is required");return t.api.copilot.integrationId}function zte(t){if(!t.api?.copilot?.token)throw new Error("Copilot token is required");return t.api.copilot.token}function GZt(t){if(!t.github?.uploadsUrl)throw new Error("GitHub uploads URL is required");return t.github.uploadsUrl}function pZt(t){if(!t.github?.downloadsUrl)throw new Error("GitHub downloads URL is required");return t.github.downloadsUrl}function hZt(t){return t.startsWith('"')&&t.endsWith('"')?(t=t.substring(1,t.length-1),t.replace(/\\([abfnrtv\\"]|[0-7]{1,3})/g,(e,l)=>{switch(l[0]){case"a":return"\x07";case"b":return"\b";case"f":return"\f";case"n":return`
822
822
  `;case"r":return"\r";case"t":return" ";case"v":return"\v";case"\\":return"\\";case'"':return'"';default:return String.fromCharCode(parseInt(l,8))}})):t}var CJe='!f() { test "$1" = get && echo "password=$GITHUB_TOKEN"; }; f',pZ=class{constructor(e,l){this.logger=e;this.exec=l}resolveGitUrl(e,l){let n=null,r="";try{r=$ge(e),n=new URL(r)}catch(a){this.logger.warning(`Failed to parse GITHUB_SERVER_URL "${r}". Falling back to GITHUB_HOST and GITHUB_GIT_HOST_PROTOCOL. Error: ${a.message??a}`);let I=iZt(e),s=eZe(e);try{n=URL.parse(`${I}://${s}`)}catch(o){this.logger.warning(`Unable to determine GITHUB_SERVER_URL. Falling back to "https://github.com". Error: ${o.message??o}`),n=URL.parse("https://github.com")}}if(!n)throw new Error("Could not determine the Git URL");return l&&(n.pathname=l),this.logger.info(`Using Git URL: ${n.href}`),n}async cloneRepo(e,l,n,r,a,I){process.env.GITHUB_TOKEN=process.env.GITHUB_TOKEN??Fx(e);let o=this.resolveGitUrl(e,l).href;if(a=a??1,a+=1,a<2&&(a=2),AZt(Pte(n,".git"))){let Z={cwd:n,silent:!0};if(this.logger.debug(`Repo ${l} already cloned to ${n}`),this.logger.debug(`Configuring git credential helper for ${l}`),await this.setGitConfig(e,Z,!1),await this.execGit(["remote","set-url","origin",o],Z,[o]),(await this.execGit(["rev-parse","--abbrev-ref","HEAD"],Z)).stdout.toString().trim()===r){this.logger.debug(`Already on branch ${r} in repo ${l}`);return}if((await this.execGit(["branch","--list",r],Z,[r])).stdout.toString().trim().length>0){this.logger.debug(`Local branch ${r} already exists in repo ${l}`),this.logger.debug(`Checking out branch ${r}`),await this.execGit(["checkout",r],Z,[r]);return}if(await this.hasRemoteBranch(r,n)){this.logger.debug(`Remote branch ${r} exists in repo ${l}`);let{stdout:V}=await this.execGit(["rev-parse","--is-shallow-repository"],Z);V.trim()==="true"?await this.execGit(["fetch","--unshallow","--update-head-ok","origin","+refs/heads/*:refs/heads/*"],Z):await this.execGit(["fetch","origin"],Z),this.logger.debug(`Pulling branch ${r} with depth ${a}`),await this.execGit(["pull","--depth",a.toString(),"origin",r],Z,[a.toString(),r]),this.logger.debug(`Checking out branch ${r}`),await this.execGit(["checkout",r],Z,[r]);return}if(I){this.logger.debug(`Base commit ${I} provided for branch ${r} in repo ${l}`),this.logger.debug(`Checking out branch ${r}`),await this.execGit(["checkout","-b",r,I],Z,[r,I]);return}throw new Error(`Branch ${r} does not exist in repo ${l} and no base commit was provided.`)}this.logger.debug(`Repo ${l} not cloned to ${n} yet`);let d=process.env.HOME||gZt(),m=ULl(Pte(_Ll(),`cpd-${TLl()}`));AZt(Pte(d,".gitconfig"))&&OLl(Pte(d,".gitconfig"),Pte(m,".gitconfig"));let G={...process.env,HOME:m},p={silent:!0,env:G},A={cwd:n,silent:!0,env:G};await this.setGitConfig(e,p,!0);try{this.logger.debug(`Cloning repo ${l} to ${n} with branch ${r} and depth ${a}`),await this.execGit(["clone","-b",r,"--single-branch","--depth",a.toString(),o,n],p,[o,n,r,a.toString()])}catch(Z){if(this.logger.debug(`Error cloning repo ${l} to ${n}: ${Z}`),I)this.logger.debug(`Base commit ${I} provided. Checking out branch ${r}`),await this.execGit(["clone",o,n],p,[o,n]),await this.execGit(["checkout","-b",r,I],A,[r,I]);else throw new Error(`Branch ${r} does not exist in repo ${l} and no base commit was provided.`)}finally{await this.cleanGitConfig(p,!0,!0)}await this.setGitConfig(e,A,!1)}async commitChanges(e,l,n,r,a=!1,I=!1){process.env.HOME||(process.env.HOME=gZt());let s={cwd:n,silent:!0},o=oZt(e);if(o){let m=`Co-authored-by: ${o.login} <${o.id}+${o.login}@users.noreply.github.com>`;r=r.trim()+`
@@ -2043,7 +2043,7 @@ ${a}`;await r.createOrUpdateMCPStartupToolCall({serverName:e,content:o,toolNames
2043
2043
  `).filter(A=>A.trim()),p=[];for(let A=0;A<G.length;A++)try{let Z=JSON.parse(G[A]),W=t(Z);p.push(W)}catch(Z){throw new Error(`Invalid event at line ${A+1} in ${d}: ${Z}`)}return p}catch(m){throw new Error(`Failed to read JSONL from ${d}: ${m}`)}},append:async(c,d)=>{let m=r(d),G=Array.isArray(c)?c:[c];try{await $zt(m);let p=G.map(A=>JSON.stringify(A)).join(`
2044
2044
  `)+`
2045
2045
  `;await Swe.runExclusive(m,()=>Cfn(m,p,{mode:384}))}catch(p){throw new Error(`Failed to append to JSONL file ${m}: ${p}`)}},path:r,directoryFiles:async()=>{let c=cN(l(),n());try{let m=(await Lwe(c,{withFileTypes:!0})).filter(p=>p.isFile()&&p.name.endsWith(".jsonl")).map(p=>p.name),G=await Promise.all(m.map(async p=>{let A=cN(c,p);try{let Z=await Jwe(A);return{file:p,mtime:Z.mtime}}catch{return{file:p,mtime:new Date}}}));return G.sort((p,A)=>A.mtime.getTime()-p.mtime.getTime()),G.map(p=>p.file)}catch{return[]}},directoryFilesWithMetadata:async()=>{let c=cN(l(),n());try{let m=(await Lwe(c,{withFileTypes:!0})).filter(p=>p.isFile()&&p.name.endsWith(".jsonl")).map(p=>p.name),G=await Promise.all(m.map(async p=>{let A=cN(c,p);try{let Z=await Jwe(A);return{file:p,mtime:Z.mtime,birthtime:Z.birthtime}}catch{return{file:p,mtime:new Date,birthtime:new Date}}}));return G.sort((p,A)=>A.mtime.getTime()-p.mtime.getTime()),G}catch{return[]}},home:l,directory:n}};var lPt=zl({host:Qt(),login:Qt()}),Lfn=zl({banner:G0(["always","once","never"]).optional(),beep:ro().optional(),last_logged_in_user:lPt.optional(),logged_in_users:Od(lPt).optional(),model:Qt().optional(),render_markdown:ro().optional(),screen_reader:ro().optional(),theme:Qt().optional(),trusted_folders:Od(Qt()).optional(),store_token_plaintext:ro().optional(),stream:ro().optional(),parallel_tool_execution:ro().optional(),feature_flags:zl({enabled:Od(Qt()).optional()}).optional(),asked_setup_terminals:Od(Qt()).optional(),capi_hmac_key:Qt().optional(),copilot_hmac_key:Qt().optional(),copilot_integration_id:Qt().optional(),copilot_tokens:rY(Qt(),Qt()).optional(),copilot_url:Qt().optional(),staff:ro().optional(),log_level:G0(["none","error","warning","info","debug","all","default"]).optional()}),Jfn=rY(Qt(),sKe()),xfn=Jfn.transform(t=>(0,nPt.default)(t,(e,l)=>{let n=l.toLowerCase();return n==="github_copilot_integration_id"?"copilot_integration_id":n})),Sfn=xfn.pipe(Lfn),Sr=Twe(Sfn.parse,"config");function BL(){return process.env.COPILOT_ENABLE_ALT_PROVIDERS==="true"}var Rf=["claude-sonnet-4.5","claude-sonnet-4","claude-haiku-4.5","gpt-5"];function Uwe(t,e){let l=" ".repeat(e);return t.map(n=>`${l}- "${n}"`).join(`
2046
- `)}function Qq(t){return Rf.includes(t)||BL()}function Ef(t,e){if(!e)return!0;let l=e.find(n=>n.id===t);return l?l.policy?l.policy.state!=="disabled":!0:!1}function Pqe(t){return Rf.find(e=>Ef(e,t))}function Fq(t,e){if(e&&e.length>0){let n=e.find(r=>r.id===t);if(n?.billing?.multiplier!==void 0)return n.billing.multiplier}return{"claude-sonnet-4":1,"gpt-5":1,"claude-sonnet-4.5":1,"claude-haiku-4.5":.33}[t]??1}async function dO(t,e,l,n){if(BL()&&process.env.COPILOT_AGENT_MODEL){let{model:I}=JB(process.env.COPILOT_AGENT_MODEL);if(I)return I}if(t){if(Ef(t,l))return t;n?.warning(`Model '${t}' from CLI argument is not available. Falling back to next option.`)}if(e){let I=await e?.getSelectedModel?.();if(I){if(Ef(I,l))return I;n?.warning(`Model '${I}' from session is not available. Falling back to next option.`)}}let r=process.env.COPILOT_MODEL;if(r&&Qq(r)){if(Ef(r,l))return r;n?.warning(`Model '${r}' from COPILOT_MODEL environment variable is not available. Falling back to next option.`)}try{let s=(await Sr.load()||{}).model;if(typeof s=="string"&&s&&Qq(s)){if(Ef(s,l))return s;n?.warning(`Model '${s}' from config file is not available. Falling back to default.`)}}catch{}let a=Pqe(l);return a&&n?.info(`Using default model: ${a}`),a}function _w(t){return"host"in t?t.host:"https://github.com"}function nme(t){return cY(t,{onHMACAuthInfo:()=>"Logged in with HMAC",onEnvAuthInfo:e=>`Logged in with ${e.envVar} as user: ${e.login}`,onUserAuthInfo:e=>`Logged in as user: ${lme(e)}`,onGhCliAuthInfo:e=>`Logged in with gh as user: ${lme(e)}`,onApiKeyAuthInfo:e=>`Logged in with API key to ${e.host}`})}function rme(t){return cY(t,{onHMACAuthInfo:()=>"Unknown (via HMAC)",onEnvAuthInfo:e=>`${e.login} (via ${e.envVar})`,onUserAuthInfo:e=>lme(e),onGhCliAuthInfo:e=>`${e.login} (via gh)`,onApiKeyAuthInfo:e=>`${e.host} (via API key)`})}function jqe(t,e){return cY(t,{onHMACAuthInfo:l=>e.type==="hmac"&&l.hmac===e.hmac,onEnvAuthInfo:l=>e.type==="env"&&l.envVar===e.envVar&&l.login===e.login,onUserAuthInfo:l=>e.type==="user"&&uO(l,e),onGhCliAuthInfo:l=>e.type==="gh-cli"&&uO(l,e),onApiKeyAuthInfo:l=>e.type==="api-key"&&l.host===e.host&&l.apiKey===e.apiKey})}async function rPt(t,e){let l=await t.getAllAuthAvailable(),n=">",r="-";return l.map(a=>`${e&&jqe(a.authInfo,e)?n:r} ${rme(a.authInfo)}`)}function lme(t){return t.host!==JL?`${t.login} (${t.host})`:t.login}async function aPt(){let t=await Sr.load()||{};return t?.last_logged_in_user??t.logged_in_users?.[0]??void 0}async function Kqe(t){await Sr.writeKey("last_logged_in_user",t)}async function Mwe(){return(await Sr.load()||{}).logged_in_users||[]}async function IPt(t,e){await Sr.writeKey("last_logged_in_user",t),await Sr.writeKey("logged_in_users",e)}async function sPt(t){let e=await Mwe();return e.some(n=>uO(n,t))?(e=e.filter(n=>!uO(n,t)),await IPt(void 0,e),e.length>0):!1}async function oPt(t){let e=await Mwe();e.some(n=>uO(n,t))||(e.push(t),await IPt(t,e))}function uO(t,e){return t.login===e.login&&t.host===e.host}async function iPt(t,e){try{let l=Bfn(),n=await e.execReturn("gh",["auth","token","--hostname",l],{silent:!0,ignoreReturnCode:!0});if(n.exitCode!==0||!n.stdout.trim()){let a=`Failed to retrieve GitHub token from CLI (exit code: ${n.exitCode})`,I=n.stderr?.trim();return I?t.debug(`${a}: ${I}`):t.debug(a),null}let r=n.stdout.trim();return r.startsWith("ghp_")?(t.debug("GitHub token is a classic PAT"),null):(t.debug("GitHub CLI authenticated with valid token"),{token:r,host:l})}catch(l){let n=`Error checking GitHub CLI: ${l}`;return l&&typeof l=="object"&&"stderr"in l&&typeof l.stderr=="string"&&(n+=` (stderr: ${l.stderr.trim()})`),t.debug(n),null}}function Bfn(){return process.env.GH_HOST||"github.com"}function qqe(){let t=process.env.GH_HOST;return t?t.startsWith("https://")?t:`https://${t}`:JL}import{existsSync as uPt}from"fs";var _we="copilot-cli",Dwe;async function zwe(){if(Dwe)return Dwe;let t=await Promise.resolve().then(()=>$e(dPt(),1));return Dwe=t.default||t,Dwe}var Ime=(t,e)=>{if(!(!t||!e))return`${t}:${e}`},Ufn=()=>{let t=new Map,e=async(o,c)=>{let d=Ime(o,c);if(d)if(uPt(Sr.path()))try{let p=(await Sr.load())?.copilot_tokens?.[d];t.set(d,p&&p.trim()!==""?p:void 0)}catch{t.set(d,void 0)}else t.set(d,void 0)},l=async()=>{if(uPt(Sr.path()))try{let c=(await Sr.load())?.copilot_tokens;if(c){let d=Object.values(c).filter(m=>m&&m.trim()!=="");if(d.length>0)return d[0]}}catch{return}},n=async(o,c)=>{let d=Ime(o,c);if(!d)return;if(t.has(d))return t.get(d);if((await Sr.load())?.store_token_plaintext)return await e(o,c),t.get(d);try{let p=await(await zwe()).getPassword(_we,d);p?t.set(d,p):await e(o,c)}catch{await e(o,c)}return t.get(d)},r=async()=>{if(t.size>0)return t.values().next().value;if((await Sr.load())?.store_token_plaintext)return await l();let c;try{c=await(await zwe()).findPassword(_we)}catch{}return c||(c=await l()),c},a=async(o,c)=>{let d=Ime(o,c);if(d){t.delete(d);try{return(await zwe()).deletePassword(_we,d)}catch{let p=(await Sr.load())?.copilot_tokens??{};return delete p[d],await Sr.writeKey("copilot_tokens",p),Promise.resolve(!0)}}},I=async(o,c,d)=>{if(!o)throw new Error("No token provided to store");let m=Ime(c,d);if(!m)return;if(t.set(m,o),(await Sr.load())?.store_token_plaintext)return await s(c,d),!0;try{return await(await zwe()).setPassword(_we,m,o),!0}catch{return!1}},s=async(o,c)=>{let d=Ime(o,c);if(!d)return;let m=t.get(d);if(!m)return;let p=(await Sr.load())?.copilot_tokens??{};p[d]=m,await Sr.writeKey("copilot_tokens",p)};return{getToken:n,getAnyToken:r,removeToken:a,storeToken:I,storeCurrentTokenInConfig:s}},Vf=Ufn();function cY(t,e){switch(t.type){case"hmac":return e.onHMACAuthInfo(t);case"env":return e.onEnvAuthInfo(t);case"user":return e.onUserAuthInfo(t);case"gh-cli":return e.onGhCliAuthInfo(t);case"api-key":return e.onApiKeyAuthInfo(t);default:{let l=t;throw new Error(`unexpected auth info type: ${JSON.stringify(t)}`)}}}async function Iy(t){return await cY(t,{onHMACAuthInfo:async()=>process.env.GITHUB_MCP_SERVER_TOKEN,onEnvAuthInfo:async e=>e.token,onUserAuthInfo:async e=>await Vf.getToken(e.host,e.login)||void 0,onGhCliAuthInfo:async e=>e.token,onApiKeyAuthInfo:async()=>{}})}var $qe=class{currentAuthInfo=null;logger=new xd;authCallbacks=[];setLogger(e){this.logger=e}onAuthChange(e){this.authCallbacks.push(e)}removeAuthCallback(e){let l=this.authCallbacks.indexOf(e);l>-1&&this.authCallbacks.splice(l,1)}async notifyAuthChange(e,l){this.currentAuthInfo=e;for(let n of this.authCallbacks)try{await n(e,l)}catch(r){this.logger.error(`Error in auth change callback: ${r}`)}}async tryHMACLogin(){let e=await Sr.load()||{},l=e.copilot_hmac_key||e.capi_hmac_key||process.env.CAPI_HMAC_KEY||process.env.COPILOT_HMAC_KEY;return l?[{authInfo:{type:"hmac",hmac:l}}]:[]}async tryGitHubTokenLogin(){let e=process.env.GH_TOKEN||process.env.GITHUB_TOKEN;if(!e)return[];if(e.startsWith("ghp_"))return this.logger.error("Classic PATs are not supported. Please use fine-grained PATs or other supported token types."),[];if(!e.startsWith("gho_")&&!e.startsWith("ghu_")&&!e.startsWith("github_pat_"))return this.logger.error("Unsupported token type, ignoring."),[];let l=qqe();try{let n=await yq(l,e);return[{authInfo:{type:"env",host:l,login:n,token:e,envVar:process.env.GH_TOKEN?"GH_TOKEN":"GITHUB_TOKEN"},token:e}]}catch(n){n instanceof LL?this.logger.error(`Failed to fetch PAT user login (${n.status}): ${n.message}`):this.logger.error("Failed to fetch PAT user login")}return[]}async tryGhCliTokenLogin(){let e=new XA(this.logger),l=await iPt(this.logger,e);if(!l)return[];let{token:n,host:r}=l;try{let a=r.startsWith("https://")?r:`https://${r}`,I=await yq(a,n);return[{authInfo:{type:"gh-cli",host:a,login:I,token:n},token:n}]}catch(a){a instanceof LL?this.logger.error(`Failed to fetch GitHub CLI user login (${a.status}): ${a.message}`):this.logger.error("Failed to fetch GitHub CLI user login")}return[]}async tryApiKeyLogin(){if(!BL())return[];let e,l;return process.env.ANTHROPIC_API_KEY?(e=process.env.ANTHROPIC_API_KEY,l="https://api.anthropic.com"):process.env.OPENAI_API_KEY?(e=process.env.OPENAI_API_KEY,l=process.env.OPENAI_BASE_URL||"https://api.openai.com"):process.env.AZURE_OPENAI_API_KEY&&(e=process.env.AZURE_OPENAI_API_KEY,l=process.env.AZURE_OPENAI_API_ENDPOINT),!e||!l?[]:[{authInfo:{type:"api-key",apiKey:e,host:l}}]}async tryLoginToken(){let e=await aPt(),l;if(e){if(l=await Vf.getToken(e.host,e.login),!l||l.trim()==="")return[]}else{if(l=await Vf.getAnyToken(),!l||l.trim()==="")return[];let n=qqe();e={host:n,login:await yq(n,l)}}return[{authInfo:{type:"user",host:e.host,login:e.login},token:l}]}async getAllGitHubLoginTokens(){let l=(await this.tryGitHubTokenLogin()).at(0),n=await Mwe(),r=[];for(let a of n){if(l?.authInfo.type==="user"&&uO(a,l.authInfo))continue;let I=await Vf.getToken(a.host,a.login);I&&r.push({authInfo:{type:"user",host:a.host,login:a.login},token:I})}return r}async getAllAuthAvailable(){let e=[],l=this.getPrioritizedAuthMethods(!0);for(let n of l){let r=await n();e.push(...r)}return e}getPrioritizedAuthMethods(e){return[this.tryHMACLogin.bind(this),this.tryApiKeyLogin.bind(this),this.tryGitHubTokenLogin.bind(this),e?this.getAllGitHubLoginTokens.bind(this):this.tryLoginToken.bind(this),this.tryGhCliTokenLogin.bind(this)]}async loadAuthInfo(){let e=this.currentAuthInfo!==null;this.currentAuthInfo=null;let l=this.getPrioritizedAuthMethods(!1);for(let n of l){let r=await n();if(r.length>0){let{authInfo:a,token:I}=r[0];a.type==="user"&&Kqe({host:a.host,login:a.login}),this.currentAuthInfo=a,e||await this.notifyAuthChange(a,I);return}}}async getCurrentAuthInfo(){return this.currentAuthInfo||await this.loadAuthInfo(),this.currentAuthInfo}async loginUser(e,l){let n={host:e,login:l},r={type:"user",...n};await oPt(n);let a=await Iy(r);await this.notifyAuthChange(r,a)}async switchToAuth(e){this.currentAuthInfo=e.authInfo,e.authInfo.type==="user"&&await Kqe({host:e.authInfo.host,login:e.authInfo.login}),await this.notifyAuthChange(e.authInfo,e.token)}async logout(){if(!this.currentAuthInfo)return!1;let e=await cY(this.currentAuthInfo,{onHMACAuthInfo:async()=>!1,onEnvAuthInfo:async()=>!1,onUserAuthInfo:async l=>(await Vf.removeToken(l.host,l.login),await sPt(l)),onGhCliAuthInfo:async()=>!1,onApiKeyAuthInfo:async()=>!1});return await this.notifyAuthChange(null),e}},Mfn=new $qe,Pwe=Mfn;var wf=class t extends kL{constructor(l,n,r,a,I){super(l,n,a,"direct");this.exec=r;this.enableAllGithubMcpTools=I??!1}static GITHUB_SERVER_NAME="github-mcp-server";static CLI_DEFAULT_GITHUB_MCP_TOOLS=["get_file_contents","search_code","search_repositories","list_branches","list_commits","get_commit","get_issue","list_issues","get_issue_comments","search_issues","pull_request_read","list_pull_requests","search_pull_requests","list_workflow_runs","get_job_logs","get_workflow_run","list_workflows","get_workflow_run_logs","web_search","search_users"];static BUILTIN_SERVERS=[t.GITHUB_SERVER_NAME];static getBuiltInServerNames(){return[...t.BUILTIN_SERVERS]}hasUserConfiguredGitHubServer=!1;lastGitHubAuthInfo=null;githubMcpToken;enableAllGithubMcpTools;async configureGitHubAuth(l){if(this.isServerDisabled(t.GITHUB_SERVER_NAME))return this.logger.debug("GitHub MCP server is disabled, skipping auto-configuration"),!1;if(this.hasUserConfiguredGitHubServer)return this.logger.debug("User has explicitly configured github-mcp-server, ignoring auth changes"),!1;if(await this.shouldHandleGitHubAuth(l)){let r=await Iy(l);if(!r)return this.logger.debug("No token available for GitHub authentication"),!1;if(this.lastGitHubAuthInfo=l,r===this.githubMcpToken)return!1;this.githubMcpToken=r;let a=await this.createGitHubServerConfig(r,l);try{return await this.restartServer(t.GITHUB_SERVER_NAME,a),this.logger.log("GitHub MCP server configured after authentication"),!0}catch(I){return this.logger.error(`Failed to configure GitHub MCP server after auth: ${I}`),!1}}return!1}async removeGitHubAuth(){if(this.hasUserConfiguredGitHubServer)return this.logger.debug("User has explicitly configured github-mcp-server, ignoring auth changes"),!1;this.githubMcpToken=void 0;try{return this.isServerRunning(t.GITHUB_SERVER_NAME)?(await this.stopServer(t.GITHUB_SERVER_NAME),this.logger.debug("Removed GitHub MCP server"),!0):!1}catch(l){return this.logger.error(`Failed to remove GitHub server: ${l}`),!1}}async shouldHandleGitHubAuth(l){return await cY(l,{onHMACAuthInfo:async()=>!!process.env.GITHUB_MCP_SERVER_TOKEN,onEnvAuthInfo:async()=>!0,onUserAuthInfo:async()=>!0,onGhCliAuthInfo:async()=>!0,onApiKeyAuthInfo:async()=>!1})}async createGitHubServerConfig(l,n){let r="https://api.githubcopilot.com/mcp/readonly";try{let a=await cY(n,{onHMACAuthInfo:async()=>"https://github.com",onEnvAuthInfo:async s=>s.host,onUserAuthInfo:async s=>s.host,onGhCliAuthInfo:async s=>s.host,onApiKeyAuthInfo:async s=>s.host}),I=await E0(a,l,this.logger);r=new URL("/mcp/readonly",I).toString()}catch(a){this.logger.error(`Failed to fetch Copilot URL, using default: ${a}`)}return{type:"http",url:r,headers:{Authorization:"Bearer "+l,"X-MCP-Toolsets":"repos,issues,users,pull_requests,code_security,secret_protection,actions,web_search","X-MCP-Host":"copilot-cli"},tools:this.enableAllGithubMcpTools?["*"]:t.CLI_DEFAULT_GITHUB_MCP_TOOLS,isDefaultServer:!0,filterMapping:{get_issue:"markdown",get_issue_comments:"markdown",get_pull_request:"markdown",get_pull_request_comments:"markdown",get_pull_request_reviews:"markdown"}}}async injectDefaultServers(l){if(l.mcpServers[t.GITHUB_SERVER_NAME]){this.hasUserConfiguredGitHubServer=!0,this.logger.debug("User has already configured github-mcp-server, skipping auto-configuration");return}}async startBuiltInServer(l){l===t.GITHUB_SERVER_NAME&&!this.hasUserConfiguredGitHubServer?this.lastGitHubAuthInfo?(this.logger.log("Attempting to configure GitHub MCP server using stored authentication"),await this.configureGitHubAuth(this.lastGitHubAuthInfo)?this.logger.log("GitHub MCP server configured successfully after enabling"):this.logger.log("GitHub MCP server enabled but could not be configured - authentication may be invalid or insufficient")):this.logger.log("GitHub MCP server enabled - will be configured automatically when authentication becomes available"):await super.startBuiltInServer(l)}};var _fn=zl({commandHistory:Od(Qt())}),e7e=Owe(_fn.parse,"command-history");var Dfn=50,t7e=class{commandHistory=[];historyIndex=-1;isNavigatingHistory=!1;unSubmittedCommand=null;async initialize(){try{let e=await e7e.load();this.commandHistory=e?.commandHistory||[],this.resetNavigation()}catch{this.commandHistory=[]}}async addCommand(e){this.commandHistory=this.commandHistory.filter(l=>l!==e),this.commandHistory.unshift(e),this.commandHistory=this.commandHistory.slice(0,Dfn),this.resetNavigation(),this.unSubmittedCommand=null,await this.saveHistory()}async updateCurrentCommand(e){this.historyIndex!==-1?(this.commandHistory[this.historyIndex]=e,await this.saveHistory()):this.unSubmittedCommand=e}navigateUp(e){if(this.commandHistory.length===0)return;let l=this.historyIndex+1;if(l<this.commandHistory.length){this.historyIndex=l,this.isNavigatingHistory=!0;let n=this.getCurrentHistoryItem();n&&e.setText(n)}}navigateDown(e){if(this.historyIndex===-1)return;if(this.historyIndex===0)this.resetNavigation();else{let n=this.historyIndex-1;this.historyIndex=n,this.isNavigatingHistory=!0}let l=this.getCurrentHistoryItem();l?(e.setText(l),e.setCursorPosition(0)):e.clear()}resetNavigation(){this.historyIndex=-1,this.isNavigatingHistory=!1}getHistoryIndex(){return this.historyIndex}getHistory(){return this.commandHistory}getCurrentHistoryItem(){return this.historyIndex===-1?this.unSubmittedCommand?this.unSubmittedCommand:void 0:this.commandHistory[this.historyIndex]}isNavigating(){return this.isNavigatingHistory}setNavigating(e){this.isNavigatingHistory=e}async saveHistory(){try{await e7e.write({commandHistory:this.commandHistory})}catch{}}},dY=new t7e;function bPt(t,e){var l=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable})),l.push.apply(l,n)}return l}function GPt(t){for(var e=1;e<arguments.length;e++){var l=arguments[e]!=null?arguments[e]:{};e%2?bPt(Object(l),!0).forEach(function(n){zfn(t,n,l[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(l)):bPt(Object(l)).forEach(function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(l,n))})}return t}function zfn(t,e,l){return e=Pfn(e),e in t?Object.defineProperty(t,e,{value:l,enumerable:!0,configurable:!0,writable:!0}):t[e]=l,t}function Pfn(t){var e=jfn(t,"string");return typeof e=="symbol"?e:String(e)}function jfn(t,e){if(typeof t!="object"||t===null)return t;var l=t[Symbol.toPrimitive];if(l!==void 0){var n=l.call(t,e||"default");if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}var Kfn=hPt({}),pPt=Kfn;function hPt(t){return e.withOptions=l=>hPt(GPt(GPt({},t),l)),e;function e(l,...n){let r=typeof l=="string"?[l]:l.raw,{escapeSpecialCharacters:a=Array.isArray(l),trimWhitespace:I=!0}=t,s="";for(let d=0;d<r.length;d++){let m=r[d];a&&(m=m.replace(/\\\n[ \t]*/g,"").replace(/\\`/g,"`").replace(/\\\$/g,"$").replace(/\\\{/g,"{")),s+=m,d<n.length&&(s+=n[d])}let o=s.split(`
2046
+ `)}function Qq(t){return Rf.includes(t)||BL()}function Ef(t,e){if(!e)return!0;let l=e.find(n=>n.id===t);return l?l.policy?l.policy.state!=="disabled":!0:!1}function Pqe(t){return Rf.find(e=>Ef(e,t))}function Fq(t,e){if(e&&e.length>0){let n=e.find(r=>r.id===t);if(n?.billing?.multiplier!==void 0)return n.billing.multiplier}return{"claude-sonnet-4":1,"gpt-5":1,"claude-sonnet-4.5":1,"claude-haiku-4.5":.33}[t]??1}async function dO(t,e,l,n){if(BL()&&process.env.COPILOT_AGENT_MODEL){let{model:I}=JB(process.env.COPILOT_AGENT_MODEL);if(I)return I}if(t){if(Ef(t,l))return t;n?.warning(`Model '${t}' from CLI argument is not available. Falling back to next option.`)}if(e){let I=await e?.getSelectedModel?.();if(I){if(Ef(I,l))return I;n?.warning(`Model '${I}' from session is not available. Falling back to next option.`)}}let r=process.env.COPILOT_MODEL;if(r&&Qq(r)){if(Ef(r,l))return r;n?.warning(`Model '${r}' from COPILOT_MODEL environment variable is not available. Falling back to next option.`)}try{let s=(await Sr.load()||{}).model;if(typeof s=="string"&&s&&Qq(s)){if(Ef(s,l))return s;n?.warning(`Model '${s}' from config file is not available. Falling back to default.`)}}catch{}let a=Pqe(l);return a&&n?.info(`Using default model: ${a}`),a}function _w(t){return"host"in t?t.host:"https://github.com"}function nme(t){return cY(t,{onHMACAuthInfo:()=>"Logged in with HMAC",onEnvAuthInfo:e=>`Logged in with ${e.envVar} as user: ${e.login}`,onUserAuthInfo:e=>`Logged in as user: ${lme(e)}`,onGhCliAuthInfo:e=>`Logged in with gh as user: ${lme(e)}`,onApiKeyAuthInfo:e=>`Logged in with API key to ${e.host}`})}function rme(t){return cY(t,{onHMACAuthInfo:()=>"Unknown (via HMAC)",onEnvAuthInfo:e=>`${e.login} (via ${e.envVar})`,onUserAuthInfo:e=>lme(e),onGhCliAuthInfo:e=>`${e.login} (via gh)`,onApiKeyAuthInfo:e=>`${e.host} (via API key)`})}function jqe(t,e){return cY(t,{onHMACAuthInfo:l=>e.type==="hmac"&&l.hmac===e.hmac,onEnvAuthInfo:l=>e.type==="env"&&l.envVar===e.envVar&&l.login===e.login,onUserAuthInfo:l=>e.type==="user"&&uO(l,e),onGhCliAuthInfo:l=>e.type==="gh-cli"&&uO(l,e),onApiKeyAuthInfo:l=>e.type==="api-key"&&l.host===e.host&&l.apiKey===e.apiKey})}async function rPt(t,e){let l=await t.getAllAuthAvailable(),n=">",r="-";return l.map(a=>`${e&&jqe(a.authInfo,e)?n:r} ${rme(a.authInfo)}`)}function lme(t){return t.host!==JL?`${t.login} (${t.host})`:t.login}async function aPt(){let t=await Sr.load()||{};return t?.last_logged_in_user??t.logged_in_users?.[0]??void 0}async function Kqe(t){await Sr.writeKey("last_logged_in_user",t)}async function Mwe(){return(await Sr.load()||{}).logged_in_users||[]}async function IPt(t,e){await Sr.writeKey("last_logged_in_user",t),await Sr.writeKey("logged_in_users",e)}async function sPt(t){let e=await Mwe();return e.some(n=>uO(n,t))?(e=e.filter(n=>!uO(n,t)),await IPt(void 0,e),e.length>0):!1}async function oPt(t){let e=await Mwe();e.some(n=>uO(n,t))||(e.push(t),await IPt(t,e))}function uO(t,e){return t.login===e.login&&t.host===e.host}async function iPt(t,e){try{let l=Bfn(),n=await e.execReturn("gh",["auth","token","--hostname",l],{silent:!0,ignoreReturnCode:!0});if(n.exitCode!==0||!n.stdout.trim()){let a=`Failed to retrieve GitHub token from CLI (exit code: ${n.exitCode})`,I=n.stderr?.trim();return I?t.debug(`${a}: ${I}`):t.debug(a),null}let r=n.stdout.trim();return r.startsWith("ghp_")?(t.debug("GitHub token is a classic PAT"),null):(t.debug("GitHub CLI authenticated with valid token"),{token:r,host:l})}catch(l){let n=`Error checking GitHub CLI: ${l}`;return l&&typeof l=="object"&&"stderr"in l&&typeof l.stderr=="string"&&(n+=` (stderr: ${l.stderr.trim()})`),t.debug(n),null}}function Bfn(){return process.env.GH_HOST||"github.com"}function qqe(){let t=process.env.GH_HOST;return t?t.startsWith("https://")?t:`https://${t}`:JL}import{existsSync as uPt}from"fs";var _we="copilot-cli",Dwe;async function zwe(){if(Dwe)return Dwe;let t=await Promise.resolve().then(()=>$e(dPt(),1));return Dwe=t.default||t,Dwe}var Ime=(t,e)=>{if(!(!t||!e))return`${t}:${e}`},Ufn=()=>{let t=new Map,e=async(o,c)=>{let d=Ime(o,c);if(d)if(uPt(Sr.path()))try{let p=(await Sr.load())?.copilot_tokens?.[d];t.set(d,p&&p.trim()!==""?p:void 0)}catch{t.set(d,void 0)}else t.set(d,void 0)},l=async()=>{if(uPt(Sr.path()))try{let c=(await Sr.load())?.copilot_tokens;if(c){let d=Object.values(c).filter(m=>m&&m.trim()!=="");if(d.length>0)return d[0]}}catch{return}},n=async(o,c)=>{let d=Ime(o,c);if(!d)return;if(t.has(d))return t.get(d);if((await Sr.load())?.store_token_plaintext)return await e(o,c),t.get(d);try{let p=await(await zwe()).getPassword(_we,d);p?t.set(d,p):await e(o,c)}catch{await e(o,c)}return t.get(d)},r=async()=>{if(t.size>0)return t.values().next().value;if((await Sr.load())?.store_token_plaintext)return await l();let c;try{c=await(await zwe()).findPassword(_we)}catch{}return c||(c=await l()),c},a=async(o,c)=>{let d=Ime(o,c);if(d){t.delete(d);try{return(await zwe()).deletePassword(_we,d)}catch{let p=(await Sr.load())?.copilot_tokens??{};return delete p[d],await Sr.writeKey("copilot_tokens",p),Promise.resolve(!0)}}},I=async(o,c,d)=>{if(!o)throw new Error("No token provided to store");let m=Ime(c,d);if(!m)return;if(t.set(m,o),(await Sr.load())?.store_token_plaintext)return await s(c,d),!0;try{return await(await zwe()).setPassword(_we,m,o),!0}catch{return!1}},s=async(o,c)=>{let d=Ime(o,c);if(!d)return;let m=t.get(d);if(!m)return;let p=(await Sr.load())?.copilot_tokens??{};p[d]=m,await Sr.writeKey("copilot_tokens",p)};return{getToken:n,getAnyToken:r,removeToken:a,storeToken:I,storeCurrentTokenInConfig:s}},Vf=Ufn();function cY(t,e){switch(t.type){case"hmac":return e.onHMACAuthInfo(t);case"env":return e.onEnvAuthInfo(t);case"user":return e.onUserAuthInfo(t);case"gh-cli":return e.onGhCliAuthInfo(t);case"api-key":return e.onApiKeyAuthInfo(t);default:{let l=t;throw new Error(`unexpected auth info type: ${JSON.stringify(t)}`)}}}async function Iy(t){return await cY(t,{onHMACAuthInfo:async()=>process.env.GITHUB_MCP_SERVER_TOKEN,onEnvAuthInfo:async e=>e.token,onUserAuthInfo:async e=>await Vf.getToken(e.host,e.login)||void 0,onGhCliAuthInfo:async e=>e.token,onApiKeyAuthInfo:async()=>{}})}var $qe=class{currentAuthInfo=null;logger=new xd;authCallbacks=[];setLogger(e){this.logger=e}onAuthChange(e){this.authCallbacks.push(e)}removeAuthCallback(e){let l=this.authCallbacks.indexOf(e);l>-1&&this.authCallbacks.splice(l,1)}async notifyAuthChange(e,l){this.currentAuthInfo=e;for(let n of this.authCallbacks)try{await n(e,l)}catch(r){this.logger.error(`Error in auth change callback: ${r}`)}}async tryHMACLogin(){let e=await Sr.load()||{},l=e.copilot_hmac_key||e.capi_hmac_key||process.env.CAPI_HMAC_KEY||process.env.COPILOT_HMAC_KEY;return l?[{authInfo:{type:"hmac",hmac:l}}]:[]}async tryGitHubTokenLogin(){let e=process.env.COPILOT_GITHUB_TOKEN||process.env.GH_TOKEN||process.env.GITHUB_TOKEN;if(!e)return[];if(e.startsWith("ghp_"))return this.logger.error("Classic PATs are not supported. Please use fine-grained PATs or other supported token types."),[];if(!e.startsWith("gho_")&&!e.startsWith("ghu_")&&!e.startsWith("github_pat_"))return this.logger.error("Unsupported token type, ignoring."),[];let l=qqe();try{let n=await yq(l,e);return[{authInfo:{type:"env",host:l,login:n,token:e,envVar:process.env.COPILOT_GITHUB_TOKEN?"COPILOT_GITHUB_TOKEN":process.env.GH_TOKEN?"GH_TOKEN":"GITHUB_TOKEN"},token:e}]}catch(n){n instanceof LL?this.logger.error(`Failed to fetch PAT user login (${n.status}): ${n.message}`):this.logger.error("Failed to fetch PAT user login")}return[]}async tryGhCliTokenLogin(){let e=new XA(this.logger),l=await iPt(this.logger,e);if(!l)return[];let{token:n,host:r}=l;try{let a=r.startsWith("https://")?r:`https://${r}`,I=await yq(a,n);return[{authInfo:{type:"gh-cli",host:a,login:I,token:n},token:n}]}catch(a){a instanceof LL?this.logger.error(`Failed to fetch GitHub CLI user login (${a.status}): ${a.message}`):this.logger.error("Failed to fetch GitHub CLI user login")}return[]}async tryApiKeyLogin(){if(!BL())return[];let e,l;return process.env.ANTHROPIC_API_KEY?(e=process.env.ANTHROPIC_API_KEY,l="https://api.anthropic.com"):process.env.OPENAI_API_KEY?(e=process.env.OPENAI_API_KEY,l=process.env.OPENAI_BASE_URL||"https://api.openai.com"):process.env.AZURE_OPENAI_API_KEY&&(e=process.env.AZURE_OPENAI_API_KEY,l=process.env.AZURE_OPENAI_API_ENDPOINT),!e||!l?[]:[{authInfo:{type:"api-key",apiKey:e,host:l}}]}async tryLoginToken(){let e=await aPt(),l;if(e){if(l=await Vf.getToken(e.host,e.login),!l||l.trim()==="")return[]}else{if(l=await Vf.getAnyToken(),!l||l.trim()==="")return[];let n=qqe();e={host:n,login:await yq(n,l)}}return[{authInfo:{type:"user",host:e.host,login:e.login},token:l}]}async getAllGitHubLoginTokens(){let l=(await this.tryGitHubTokenLogin()).at(0),n=await Mwe(),r=[];for(let a of n){if(l?.authInfo.type==="user"&&uO(a,l.authInfo))continue;let I=await Vf.getToken(a.host,a.login);I&&r.push({authInfo:{type:"user",host:a.host,login:a.login},token:I})}return r}async getAllAuthAvailable(){let e=[],l=this.getPrioritizedAuthMethods(!0);for(let n of l){let r=await n();e.push(...r)}return e}getPrioritizedAuthMethods(e){return[this.tryHMACLogin.bind(this),this.tryApiKeyLogin.bind(this),this.tryGitHubTokenLogin.bind(this),e?this.getAllGitHubLoginTokens.bind(this):this.tryLoginToken.bind(this),this.tryGhCliTokenLogin.bind(this)]}async loadAuthInfo(){let e=this.currentAuthInfo!==null;this.currentAuthInfo=null;let l=this.getPrioritizedAuthMethods(!1);for(let n of l){let r=await n();if(r.length>0){let{authInfo:a,token:I}=r[0];a.type==="user"&&Kqe({host:a.host,login:a.login}),this.currentAuthInfo=a,e||await this.notifyAuthChange(a,I);return}}}async getCurrentAuthInfo(){return this.currentAuthInfo||await this.loadAuthInfo(),this.currentAuthInfo}async loginUser(e,l){let n={host:e,login:l},r={type:"user",...n};await oPt(n);let a=await Iy(r);await this.notifyAuthChange(r,a)}async switchToAuth(e){this.currentAuthInfo=e.authInfo,e.authInfo.type==="user"&&await Kqe({host:e.authInfo.host,login:e.authInfo.login}),await this.notifyAuthChange(e.authInfo,e.token)}async logout(){if(!this.currentAuthInfo)return!1;let e=await cY(this.currentAuthInfo,{onHMACAuthInfo:async()=>!1,onEnvAuthInfo:async()=>!1,onUserAuthInfo:async l=>(await Vf.removeToken(l.host,l.login),await sPt(l)),onGhCliAuthInfo:async()=>!1,onApiKeyAuthInfo:async()=>!1});return await this.notifyAuthChange(null),e}},Mfn=new $qe,Pwe=Mfn;var wf=class t extends kL{constructor(l,n,r,a,I){super(l,n,a,"direct");this.exec=r;this.enableAllGithubMcpTools=I??!1}static GITHUB_SERVER_NAME="github-mcp-server";static CLI_DEFAULT_GITHUB_MCP_TOOLS=["get_file_contents","search_code","search_repositories","list_branches","list_commits","get_commit","get_issue","list_issues","get_issue_comments","search_issues","pull_request_read","list_pull_requests","search_pull_requests","list_workflow_runs","get_job_logs","get_workflow_run","list_workflows","get_workflow_run_logs","web_search","search_users"];static BUILTIN_SERVERS=[t.GITHUB_SERVER_NAME];static getBuiltInServerNames(){return[...t.BUILTIN_SERVERS]}hasUserConfiguredGitHubServer=!1;lastGitHubAuthInfo=null;githubMcpToken;enableAllGithubMcpTools;async configureGitHubAuth(l){if(this.isServerDisabled(t.GITHUB_SERVER_NAME))return this.logger.debug("GitHub MCP server is disabled, skipping auto-configuration"),!1;if(this.hasUserConfiguredGitHubServer)return this.logger.debug("User has explicitly configured github-mcp-server, ignoring auth changes"),!1;if(await this.shouldHandleGitHubAuth(l)){let r=await Iy(l);if(!r)return this.logger.debug("No token available for GitHub authentication"),!1;if(this.lastGitHubAuthInfo=l,r===this.githubMcpToken)return!1;this.githubMcpToken=r;let a=await this.createGitHubServerConfig(r,l);try{return await this.restartServer(t.GITHUB_SERVER_NAME,a),this.logger.log("GitHub MCP server configured after authentication"),!0}catch(I){return this.logger.error(`Failed to configure GitHub MCP server after auth: ${I}`),!1}}return!1}async removeGitHubAuth(){if(this.hasUserConfiguredGitHubServer)return this.logger.debug("User has explicitly configured github-mcp-server, ignoring auth changes"),!1;this.githubMcpToken=void 0;try{return this.isServerRunning(t.GITHUB_SERVER_NAME)?(await this.stopServer(t.GITHUB_SERVER_NAME),this.logger.debug("Removed GitHub MCP server"),!0):!1}catch(l){return this.logger.error(`Failed to remove GitHub server: ${l}`),!1}}async shouldHandleGitHubAuth(l){return await cY(l,{onHMACAuthInfo:async()=>!!process.env.GITHUB_MCP_SERVER_TOKEN,onEnvAuthInfo:async()=>!0,onUserAuthInfo:async()=>!0,onGhCliAuthInfo:async()=>!0,onApiKeyAuthInfo:async()=>!1})}async createGitHubServerConfig(l,n){let r="https://api.githubcopilot.com/mcp/readonly";try{let a=await cY(n,{onHMACAuthInfo:async()=>"https://github.com",onEnvAuthInfo:async s=>s.host,onUserAuthInfo:async s=>s.host,onGhCliAuthInfo:async s=>s.host,onApiKeyAuthInfo:async s=>s.host}),I=await E0(a,l,this.logger);r=new URL("/mcp/readonly",I).toString()}catch(a){this.logger.error(`Failed to fetch Copilot URL, using default: ${a}`)}return{type:"http",url:r,headers:{Authorization:"Bearer "+l,"X-MCP-Toolsets":"repos,issues,users,pull_requests,code_security,secret_protection,actions,web_search","X-MCP-Host":"copilot-cli"},tools:this.enableAllGithubMcpTools?["*"]:t.CLI_DEFAULT_GITHUB_MCP_TOOLS,isDefaultServer:!0,filterMapping:{get_issue:"markdown",get_issue_comments:"markdown",get_pull_request:"markdown",get_pull_request_comments:"markdown",get_pull_request_reviews:"markdown"}}}async injectDefaultServers(l){if(l.mcpServers[t.GITHUB_SERVER_NAME]){this.hasUserConfiguredGitHubServer=!0,this.logger.debug("User has already configured github-mcp-server, skipping auto-configuration");return}}async startBuiltInServer(l){l===t.GITHUB_SERVER_NAME&&!this.hasUserConfiguredGitHubServer?this.lastGitHubAuthInfo?(this.logger.log("Attempting to configure GitHub MCP server using stored authentication"),await this.configureGitHubAuth(this.lastGitHubAuthInfo)?this.logger.log("GitHub MCP server configured successfully after enabling"):this.logger.log("GitHub MCP server enabled but could not be configured - authentication may be invalid or insufficient")):this.logger.log("GitHub MCP server enabled - will be configured automatically when authentication becomes available"):await super.startBuiltInServer(l)}};var _fn=zl({commandHistory:Od(Qt())}),e7e=Owe(_fn.parse,"command-history");var Dfn=50,t7e=class{commandHistory=[];historyIndex=-1;isNavigatingHistory=!1;unSubmittedCommand=null;async initialize(){try{let e=await e7e.load();this.commandHistory=e?.commandHistory||[],this.resetNavigation()}catch{this.commandHistory=[]}}async addCommand(e){this.commandHistory=this.commandHistory.filter(l=>l!==e),this.commandHistory.unshift(e),this.commandHistory=this.commandHistory.slice(0,Dfn),this.resetNavigation(),this.unSubmittedCommand=null,await this.saveHistory()}async updateCurrentCommand(e){this.historyIndex!==-1?(this.commandHistory[this.historyIndex]=e,await this.saveHistory()):this.unSubmittedCommand=e}navigateUp(e){if(this.commandHistory.length===0)return;let l=this.historyIndex+1;if(l<this.commandHistory.length){this.historyIndex=l,this.isNavigatingHistory=!0;let n=this.getCurrentHistoryItem();n&&e.setText(n)}}navigateDown(e){if(this.historyIndex===-1)return;if(this.historyIndex===0)this.resetNavigation();else{let n=this.historyIndex-1;this.historyIndex=n,this.isNavigatingHistory=!0}let l=this.getCurrentHistoryItem();l?(e.setText(l),e.setCursorPosition(0)):e.clear()}resetNavigation(){this.historyIndex=-1,this.isNavigatingHistory=!1}getHistoryIndex(){return this.historyIndex}getHistory(){return this.commandHistory}getCurrentHistoryItem(){return this.historyIndex===-1?this.unSubmittedCommand?this.unSubmittedCommand:void 0:this.commandHistory[this.historyIndex]}isNavigating(){return this.isNavigatingHistory}setNavigating(e){this.isNavigatingHistory=e}async saveHistory(){try{await e7e.write({commandHistory:this.commandHistory})}catch{}}},dY=new t7e;function bPt(t,e){var l=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable})),l.push.apply(l,n)}return l}function GPt(t){for(var e=1;e<arguments.length;e++){var l=arguments[e]!=null?arguments[e]:{};e%2?bPt(Object(l),!0).forEach(function(n){zfn(t,n,l[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(l)):bPt(Object(l)).forEach(function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(l,n))})}return t}function zfn(t,e,l){return e=Pfn(e),e in t?Object.defineProperty(t,e,{value:l,enumerable:!0,configurable:!0,writable:!0}):t[e]=l,t}function Pfn(t){var e=jfn(t,"string");return typeof e=="symbol"?e:String(e)}function jfn(t,e){if(typeof t!="object"||t===null)return t;var l=t[Symbol.toPrimitive];if(l!==void 0){var n=l.call(t,e||"default");if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}var Kfn=hPt({}),pPt=Kfn;function hPt(t){return e.withOptions=l=>hPt(GPt(GPt({},t),l)),e;function e(l,...n){let r=typeof l=="string"?[l]:l.raw,{escapeSpecialCharacters:a=Array.isArray(l),trimWhitespace:I=!0}=t,s="";for(let d=0;d<r.length;d++){let m=r[d];a&&(m=m.replace(/\\\n[ \t]*/g,"").replace(/\\`/g,"`").replace(/\\\$/g,"$").replace(/\\\{/g,"{")),s+=m,d<n.length&&(s+=n[d])}let o=s.split(`
2047
2047
  `),c=null;for(let d of o){let m=d.match(/^(\s+)\S+/);if(m){let G=m[1].length;c?c=Math.min(c,G):c=G}}if(c!==null){let d=c;s=o.map(m=>m[0]===" "||m[0]===" "?m.slice(d):m).join(`
2048
2048
  `)}return I&&(s=s.trim()),a&&(s=s.replace(/\\n/g,`
2049
2049
  `)),s}}import{homedir as Bjt}from"node:os";import w4n,{resolve as Q4n}from"node:path";function qfn(t){return t.length>0&&/^[0-9a-zA-Z_-]+$/.test(t)}function gPt(t){return!t||t.length===0?{valid:!1,error:"MCP server name cannot be empty"}:/^[0-9a-zA-Z_-]+$/.test(t)?{valid:!0}:{valid:!1,error:"MCP server name must only contain alphanumeric characters, underscores, and hyphens"}}var APt=G0(["none","markdown","hidden_characters"]),ZPt=zl({tools:Od(Qt()),type:Qt().optional(),isDefaultServer:ro().optional(),filterMapping:rY(Qt(),APt).or(APt).optional()}),$fn=ZPt.extend({type:pr("local").optional(),command:Qt(),args:Od(Qt()),env:rY(Qt(),Qt()).optional()}),eHn=ZPt.extend({type:pr("http").or(pr("sse")),url:Qt(),headers:rY(Qt(),Qt()).optional()}),l7e=zl({mcpServers:rY(Qt().min(1,"MCP server name cannot be empty").refine(qfn,{message:"MCP server name must only contain alphanumeric characters, underscores, and hyphens"}),$fn.or(eHn))}),uY=Twe(l7e.parse,"mcp");function NPt(t){let e=t.r/255,l=t.g/255,n=t.b/255,r=Math.max(e,l,n),a=Math.min(e,l,n),I=r-a,s=0,o=0,c=(r+a)/2;if(I!==0){switch(o=c>.5?I/(2-r-a):I/(r+a),r){case e:s=(l-n)/I+(l<n?6:0);break;case l:s=(n-e)/I+2;break;case n:s=(e-l)/I+4;break}s/=6}return{h:s*360,s:o,l:c}}function tHn(t){if(t.length<12||t.length>18)return null;let e=t.match(/rgb:([0-9a-f]+)\/([0-9a-f]+)\/([0-9a-f]+)/i);if(!e)return null;let[,l,n,r]=e,a=c=>c.length>=2?parseInt(c.substring(0,2),16):c.length===1?parseInt(c+c,16):0,I=a(l),s=a(n),o=a(r);return{r:I,g:s,b:o}}var WPt=["#000000","#800000","#008000","#808000","#000080","#800080","#008080","#c0c0c0","#808080","#ff0000","#00ff00","#ffff00","#0000ff","#ff00ff","#00ffff","#ffffff","#000000","#00005f","#000087","#0000af","#0000d7","#0000ff","#005f00","#005f5f","#005f87","#005faf","#005fd7","#005fff","#008700","#00875f","#008787","#0087af","#0087d7","#0087ff","#00af00","#00af5f","#00af87","#00afaf","#00afd7","#00afff","#00d700","#00d75f","#00d787","#00d7af","#00d7d7","#00d7ff","#00ff00","#00ff5f","#00ff87","#00ffaf","#00ffd7","#00ffff","#5f0000","#5f005f","#5f0087","#5f00af","#5f00d7","#5f00ff","#5f5f00","#5f5f5f","#5f5f87","#5f5faf","#5f5fd7","#5f5fff","#5f8700","#5f875f","#5f8787","#5f87af","#5f87d7","#5f87ff","#5faf00","#5faf5f","#5faf87","#5fafaf","#5fafd7","#5fafff","#5fd700","#5fd75f","#5fd787","#5fd7af","#5fd7d7","#5fd7ff","#5fff00","#5fff5f","#5fff87","#5fffaf","#5fffd7","#5fffff","#870000","#87005f","#870087","#8700af","#8700d7","#8700ff","#875f00","#875f5f","#875f87","#875faf","#875fd7","#875fff","#878700","#87875f","#878787","#8787af","#8787d7","#8787ff","#87af00","#87af5f","#87af87","#87afaf","#87afd7","#87afff","#87d700","#87d75f","#87d787","#87d7af","#87d7d7","#87d7ff","#87ff00","#87ff5f","#87ff87","#87ffaf","#87ffd7","#87ffff","#af0000","#af005f","#af0087","#af00af","#af00d7","#af00ff","#af5f00","#af5f5f","#af5f87","#af5faf","#af5fd7","#af5fff","#af8700","#af875f","#af8787","#af87af","#af87d7","#af87ff","#afaf00","#afaf5f","#afaf87","#afafaf","#afafd7","#afafff","#afd700","#afd75f","#afd787","#afd7af","#afd7d7","#afd7ff","#afff00","#afff5f","#afff87","#afffaf","#afffd7","#afffff","#d70000","#d7005f","#d70087","#d700af","#d700d7","#d700ff","#d75f00","#d75f5f","#d75f87","#d75faf","#d75fd7","#d75fff","#d78700","#d7875f","#d78787","#d787af","#d787d7","#d787ff","#d7af00","#d7af5f","#d7af87","#d7afaf","#d7afd7","#d7afff","#d7d700","#d7d75f","#d7d787","#d7d7af","#d7d7d7","#d7d7ff","#d7ff00","#d7ff5f","#d7ff87","#d7ffaf","#d7ffd7","#d7ffff","#ff0000","#ff005f","#ff0087","#ff00af","#ff00d7","#ff00ff","#ff5f00","#ff5f5f","#ff5f87","#ff5faf","#ff5fd7","#ff5fff","#ff8700","#ff875f","#ff8787","#ff87af","#ff87d7","#ff87ff","#ffaf00","#ffaf5f","#ffaf87","#ffafaf","#ffafd7","#ffafff","#ffd700","#ffd75f","#ffd787","#ffd7af","#ffd7d7","#ffd7ff","#ffff00","#ffff5f","#ffff87","#ffffaf","#ffffd7","#ffffff","#080808","#121212","#1c1c1c","#262626","#303030","#3a3a3a","#444444","#4e4e4e","#585858","#626262","#6c6c6c","#767676","#808080","#8a8a8a","#949494","#9e9e9e","#a8a8a8","#b2b2b2","#bcbcbc","#c6c6c6","#d0d0d0","#dadada","#e4e4e4","#eeeeee"];function lHn(t){let e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return e?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:{r:0,g:0,b:0}}function nHn(t){return t<0||t>=WPt.length?{r:0,g:0,b:0}:lHn(WPt[t])}function yPt(t){if(t.length<15||t.length>30)return null;let e=t;e.endsWith("\x07")?e=e.slice(0,-1):e.endsWith("\x1B\\")?e=e.slice(0,-2):e.endsWith("\x9C")&&(e=e.slice(0,-1));let l=e;return l.startsWith("11;")&&(l=l.substring(3)),l.startsWith("rgb:")?tHn(l):null}async function rHn(t=100){return new Promise(e=>{if(!process.stdout.isTTY||!process.stdin.isTTY){e(null);return}let l="",n=null,r=()=>{process.stdin.removeListener("data",a),process.stdin.setRawMode(!1),n&&clearTimeout(n)},a=I=>{l+=I.toString();let s=l.match(/\x1b\]11;([^\x07\x1b\x9c]*?)(?:\x07|\x1b\\|\x9c)/);if(s){r();let c=`11;${s[1]}`;e(yPt(c));return}let o=l.match(/11;rgb:([0-9a-f/]+)(?:\x07|\x1b\\|\x9c)/i);if(o){r(),e(yPt(`11;rgb:${o[1]}`));return}};n=setTimeout(()=>{r(),e(null)},t);try{process.stdin.setRawMode(!0),process.stdin.on("data",a),process.stdout.write("\x1B]11;?\x1B\\")}catch{r(),e(null)}})}function aHn(){let t=process.env.COLORFGBG;if(!t||!t.includes(";"))return null;let e=t.split(";"),l=e[e.length-1],n=parseInt(l,10);return isNaN(n)?null:nHn(n)}async function EPt(){try{let t=await rHn();if(t)return NPt(t).l<.5;let e=aHn();return e?NPt(e).l<.5:!0}catch{return!0}}var RPt={FG:"whiteBright",ACCENT:"blue",SUCCESS:"green",DIFF_ADDED_HIGHLIGHT_FG:"black",DIFF_REMOVED_HIGHLIGHT_FG:"whiteBright",ERROR:"red",WARNING:"yellow",COPILOT:"magenta",COPILOT_BRIGHT:"magentaBright",MUTED:"white",SELECTED:"cyan",BORDER:"blackBright"},IHn={FG:"black",ACCENT:"blue",SUCCESS:"green",DIFF_ADDED_HIGHLIGHT_FG:"black",DIFF_REMOVED_HIGHLIGHT_FG:"whiteBright",ERROR:"red",WARNING:"yellow",COPILOT:"magenta",COPILOT_BRIGHT:"magentaBright",MUTED:"blackBright",SELECTED:"cyan",BORDER:"blackBright"};function n7e(t){return t==="auto"||t==="dark"||t==="light"}function jwe(t){switch(t){case"dark":return RPt;case"light":return IHn;default:return RPt}}var Kwe=await EPt();async function qwe(){let e=(await Sr.load())?.theme||"";return n7e(e)?e:"auto"}async function YPt(t){await Sr.writeKey("theme",t)}var VPt=t=>{let e=t?Sl.whiteBright:Sl.black,l=t?Sl.cyanBright:Sl.blueBright,n=t?Sl.magentaBright:Sl.magenta;return{text:e,paragraph:e,html:e,table:e,blockquote:e,heading:Sl.bold,firstHeading:Sl.whiteBright.bold,strong:Sl.bold,em:Sl.italic,del:Sl.strikethrough,hr:Sl.white,link:l,href:l,image:(r,a,I)=>n(I?`Image: ${I} \u2192 ${r}`:`Image: ${r}`),codespan:Sl.cyan,code:Sl.cyan,list:(r,a,I)=>{let s=r.replace(/^(\s*)\* /gm,"$1- ");return I&&(s=s.split(`
@@ -2545,7 +2545,7 @@ ${Uwe(Rf,4)}
2545
2545
  `},{name:"commands",summary:"Interactive Mode Commands",content:`Interactive Mode Commands:
2546
2546
 
2547
2547
  ${Mjt(bQe({customAgentsEnabled:dpe.CUSTOM_AGENTS,ccaDelegateEnabled:dpe.CCA_DELEGATE}),2)}
2548
- `},{name:"environment",summary:"Environment Variables",content:'Environment Variables:\n\n `COLORFGBG`: fallback to detect dark / light backgrounds; uses form of "fg;bg" where each field is a number from 0-15 corresponding to ANSI colors.\n\n `COPILOT_ALLOW_ALL`: allow all tools to run automatically without confirmation when set to "true".\n\n `COPILOT_CUSTOM_INSTRUCTIONS_DIRS`: comma-separated list of additional directories to search for custom instructions files (in addition to git root and current working directory).\n\n `COPILOT_MODEL`: optionally set the agent model. Allowed values are "gpt-5", "claude-sonnet-4", or "claude-sonnet-4.5" (default). Can be overridden by the --model command line option or the /model command.\n\n `GH_TOKEN`, `GITHUB_TOKEN` (in order of precedence): an authentication token that takes precedence over previously stored credentials.\n\n `XDG_CONFIG_HOME`: override the directory where configuration files are stored; defaults to `$HOME/.copilot`.\n\n `XDG_STATE_HOME`: override the directory where state files are stored; defaults to `$HOME/.copilot`.'},{name:"logging",summary:"Logging",content:`Log Levels:
2548
+ `},{name:"environment",summary:"Environment Variables",content:'Environment Variables:\n\n `COLORFGBG`: fallback to detect dark / light backgrounds; uses form of "fg;bg" where each field is a number from 0-15 corresponding to ANSI colors.\n\n `COPILOT_ALLOW_ALL`: allow all tools to run automatically without confirmation when set to "true".\n\n `COPILOT_CUSTOM_INSTRUCTIONS_DIRS`: comma-separated list of additional directories to search for custom instructions files (in addition to git root and current working directory).\n\n `COPILOT_MODEL`: optionally set the agent model. Allowed values are "gpt-5", "claude-sonnet-4", or "claude-sonnet-4.5" (default). Can be overridden by the --model command line option or the /model command.\n\n `COPILOT_GITHUB_TOKEN`, `GH_TOKEN`, `GITHUB_TOKEN` (in order of precedence): an authentication token that takes precedence over previously stored credentials.\n\n `XDG_CONFIG_HOME`: override the directory where configuration files are stored; defaults to `$HOME/.copilot`.\n\n `XDG_STATE_HOME`: override the directory where state files are stored; defaults to `$HOME/.copilot`.'},{name:"logging",summary:"Logging",content:`Log Levels:
2549
2549
 
2550
2550
  none No logging output
2551
2551
  error Only error messages
@@ -2642,7 +2642,7 @@ Copilot can be authenticated with GitHub using an OAuth Token or a Fine-Grained
2642
2642
 
2643
2643
  To authenticate, you can use any of the following methods:
2644
2644
  \u2022 Start 'copilot' and run the '/login' command
2645
- \u2022 Set the GH_TOKEN or GITHUB_TOKEN environment variable
2645
+ \u2022 Set the COPILOT_GITHUB_TOKEN, GH_TOKEN, or GITHUB_TOKEN environment variable
2646
2646
  \u2022 Run 'gh auth login' to authenticate with the GitHub CLI`+`
2647
2647
  `),c.error("No authentication information found."),process.exit(1));let R=await Cnt(process.cwd()),{agents:V,warnings:v}=await vnt(c,G,W,Umr.join(U4(),"agents"),R);v.forEach(x=>c.warning(x));let X=await _c(async()=>{if(!t.agent)return;let x=V.find(U=>U.id===t.agent);return x||B$(`No such agent: ${t.agent}, available: ${V.map(U=>U.id).join(", ")}`,c),{name:x.id,prompt:await x.prompt(),mcpServers:x.mcpServers||{}}});await rpl({integrationId:G,prompt:Z,allowAllTools:!!t.allowAllTools,allowAllPaths:!!t.allowAllPaths,rules:l,authInfo:W,session:a,sessionManager:r,logger:c,customAgents:V,enableStreaming:p??JU.stream??!0,trajectoryOutputFile:t.saveTrajectoryOutput,additionalDirs:t.addDir,disabledMcpServers:m,additionalMcpConfig:e,cliModel:t.model,showLlmTiming:t.showTiming,noCustomInstructions:!t.customInstructions,disableParallelToolsExecution:t.disableParallelToolsExecution,disallowTempDir:t.disallowTempDir,enableAllGithubMcpTools:t.enableAllGithubMcpTools,selectedCustomAgent:X})}catch(W){let R=`Error executing prompt: ${String(W)}`;process.stderr.write(R+`
2648
2648
  `),c.error(R),process.exit(1)}})()}}).addCommand(new FXe("help").description("Display help information").argument("[topic]","Help topic (e.g., environment)").action(t=>{t||(jEl.outputHelp(),process.exit(0));let e=fHe.find(l=>l.name===t);e&&(console.log(e.content),process.exit(0)),console.log(`Unknown help topic: ${t}`),console.log(`Available topics:
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@github/copilot",
3
3
  "description": "GitHub Copilot CLI brings the power of Copilot coding agent directly to your terminal.",
4
- "version": "0.0.354-12",
4
+ "version": "0.0.354-13",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "type": "module",
7
7
  "repository": {
@@ -37,6 +37,6 @@
37
37
  "worker/**/*"
38
38
  ],
39
39
  "buildMetadata": {
40
- "gitCommit": "cb73f24"
40
+ "gitCommit": "299739e"
41
41
  }
42
42
  }