@lioneltay/claude-pilot 0.1.5 → 0.1.7

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/dist/cli.js CHANGED
@@ -375,7 +375,7 @@ Content-Type: ${u.type||"application/octet-stream"}\r
375
375
  Content-Length: ${r.length}\r
376
376
  Content-Type: application/json\r
377
377
  \r
378
- ${r}`),e.destroy(t)}function EA(t){if(typeof t!="function")throw new yA(typeof t);if(t.constructor.name==="AsyncFunction")throw new yA("AsyncFunction")}Co.exports=Xm;Co.exports.errorCodes=Mn;Co.exports.fastify=Xm;Co.exports.default=Xm});import{spawn as UJ}from"node:child_process";var _g=ig(yg(),1),{program:l8,createCommand:u8,createArgument:c8,createOption:f8,CommanderError:d8,InvalidArgumentError:h8,InvalidOptionArgumentError:p8,Command:Sg,Argument:m8,Option:g8,Help:y8}=_g.default;var yJ=ig(wA(),1);import{readFile as uJ,writeFile as cJ,mkdir as fJ}from"node:fs/promises";import{homedir as dJ}from"node:os";import{join as OA,dirname as hJ}from"node:path";var RA="Iv1.b507a08c87ecfe98";async function Qm(){let t=await fetch("https://github.com/login/device/code",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({client_id:RA,scope:"read:user"})});if(!t.ok)throw new Error(`Device flow initiation failed: ${t.statusText}`);return t.json()}async function Zm(t,e=5){let r=e;for(;;){await new Promise(i=>setTimeout(i,r*1e3));let s=await(await fetch("https://github.com/login/oauth/access_token",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({client_id:RA,device_code:t,grant_type:"urn:ietf:params:oauth:grant-type:device_code"})})).json();if(s.access_token)return s.access_token;if(s.error!=="authorization_pending"){if(s.error==="slow_down"){r+=5;continue}throw new Error(`Authentication failed: ${s.error||"Unknown error"}`)}}}async function Us(t){let e=await fetch("https://api.github.com/copilot_internal/v2/token",{method:"GET",headers:{Authorization:`Bearer ${t}`,Accept:"application/json"}});if(!e.ok){let n=await e.text();throw new Error(`Failed to get Copilot token: ${e.status} ${e.statusText} - ${n}`)}let r=await e.json();return{token:r.token,expiresAt:r.expires_at*1e3}}var pJ=OA(dJ(),".config","claude-pilot"),eg=OA(pJ,"auth.json");async function xr(t=eg){try{let e=await uJ(t,"utf-8");return JSON.parse(e)}catch{return null}}async function Pu(t,e=eg){await fJ(hJ(e),{recursive:!0}),await cJ(e,JSON.stringify(t,null,2))}async function Au(t,e=eg){let n=Date.now();if(t.copilotTokenExpiresAt-n>3e5)return t.copilotToken;console.log("Refreshing Copilot token...");let s=await Us(t.githubToken);return t.copilotToken=s.token,t.copilotTokenExpiresAt=s.expiresAt,await Pu(t,e),console.log("Copilot token refreshed"),s.token}var LQ=process.env.COPILOT_PATH||"copilot",qQ=parseInt(process.env.WEB_SEARCH_TIMEOUT||"60000",10),jQ=process.env.WEB_SEARCH_MODEL||"gpt-4.1";import{exec as mJ}from"child_process";import{promisify as gJ}from"util";var HQ=gJ(mJ);import{homedir as _J}from"node:os";import{join as Io}from"node:path";var yr=Io(_J(),".config","claude-pilot"),ft=Io(yr,"auth.json"),Cu=Io(yr,"daemon.json"),Iu=Io(yr,"server.log"),VZ=Io(yr,"requests.jsonl"),Nu=51080;async function TA(){console.log(`Claude Pilot - GitHub Copilot Authentication
378
+ ${r}`),e.destroy(t)}function EA(t){if(typeof t!="function")throw new yA(typeof t);if(t.constructor.name==="AsyncFunction")throw new yA("AsyncFunction")}Co.exports=Xm;Co.exports.errorCodes=Mn;Co.exports.fastify=Xm;Co.exports.default=Xm});import{spawn as UJ}from"node:child_process";var _g=ig(yg(),1),{program:l8,createCommand:u8,createArgument:c8,createOption:f8,CommanderError:d8,InvalidArgumentError:h8,InvalidOptionArgumentError:p8,Command:Sg,Argument:m8,Option:g8,Help:y8}=_g.default;var yJ=ig(wA(),1);import{readFile as uJ,writeFile as cJ,mkdir as fJ}from"node:fs/promises";import{homedir as dJ}from"node:os";import{join as OA,dirname as hJ}from"node:path";var RA="Iv1.b507a08c87ecfe98";async function Qm(){let t=await fetch("https://github.com/login/device/code",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({client_id:RA,scope:"read:user"})});if(!t.ok)throw new Error(`Device flow initiation failed: ${t.statusText}`);return t.json()}async function Zm(t,e=5){let r=e;for(;;){await new Promise(i=>setTimeout(i,r*1e3));let s=await(await fetch("https://github.com/login/oauth/access_token",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({client_id:RA,device_code:t,grant_type:"urn:ietf:params:oauth:grant-type:device_code"})})).json();if(s.access_token)return s.access_token;if(s.error!=="authorization_pending"){if(s.error==="slow_down"){r+=5;continue}throw new Error(`Authentication failed: ${s.error||"Unknown error"}`)}}}async function Us(t){let e=await fetch("https://api.github.com/copilot_internal/v2/token",{method:"GET",headers:{Authorization:`Bearer ${t}`,Accept:"application/json"}});if(!e.ok){let n=await e.text();throw new Error(`Failed to get Copilot token: ${e.status} ${e.statusText} - ${n}`)}let r=await e.json();return{token:r.token,expiresAt:r.expires_at*1e3}}var pJ=OA(dJ(),".config","claude-pilot"),eg=OA(pJ,"auth.json");async function xr(t=eg){try{let e=await uJ(t,"utf-8");return JSON.parse(e)}catch{return null}}async function Pu(t,e=eg){await fJ(hJ(e),{recursive:!0}),await cJ(e,JSON.stringify(t,null,2))}async function Au(t,e=eg){let n=Date.now();if(t.copilotTokenExpiresAt-n>3e5)return t.copilotToken;console.log("Refreshing Copilot token...");let s=await Us(t.githubToken);return t.copilotToken=s.token,t.copilotTokenExpiresAt=s.expiresAt,await Pu(t,e),console.log("Copilot token refreshed"),s.token}var LQ=process.env.COPILOT_PATH||"copilot",qQ=parseInt(process.env.WEB_SEARCH_TIMEOUT||"60000",10),jQ=process.env.WEB_SEARCH_MODEL||"gpt-4.1";import{exec as mJ}from"child_process";import{promisify as gJ}from"util";var HQ=gJ(mJ);import{homedir as _J}from"node:os";import{join as Io}from"node:path";var yr=Io(_J(),".config","claude-pilot"),ft=Io(yr,"auth.json"),Cu=Io(yr,"daemon.json"),Iu=Io(yr,"server.log"),zZ=Io(yr,"requests.jsonl"),Nu=51080;async function TA(){console.log(`Claude Pilot - GitHub Copilot Authentication
379
379
  `);let t=await xr(ft);if(t){console.log("Existing credentials found."),console.log(`To re-authenticate, delete ${ft}
380
380
  `);try{let s=await Us(t.githubToken);console.log("\u2713 Credentials are valid"),console.log(` Copilot token expires: ${new Date(s.expiresAt).toLocaleString()}`);return}catch{console.log(`\u2717 Credentials are invalid, re-authenticating...
381
381
  `)}}console.log(`Starting GitHub OAuth device flow...
@@ -391,7 +391,7 @@ Configure Claude Code with:`),console.log(` export ANTHROPIC_BASE_URL=http://lo
391
391
  \u{1F4E6} Update available: ${n} \u2192 ${t.latestVersion}`),console.log(` npm install -g @lioneltay/claude-pilot@latest
392
392
  `))}return}let r=zJ();if(VJ({lastCheck:e,latestVersion:r}),r){let n=kA();n&&r!==n&&(console.log(`
393
393
  \u{1F4E6} Update available: ${n} \u2192 ${r}`),console.log(` npm install -g @lioneltay/claude-pilot@latest
394
- `))}}catch{}})}import{readFileSync as BJ}from"node:fs";import{fileURLToPath as GJ}from"node:url";import{dirname as WJ,join as JJ}from"node:path";function KJ(){try{let t=GJ(import.meta.url),e=WJ(t),r=JJ(e,"..","package.json");return JSON.parse(BJ(r,"utf-8")).version||"0.0.0"}catch{return"0.0.0"}}var rg=KJ(),YJ=["login","logout","start","stop","status","dashboard","help"];function XJ(t){let e=t[0];return e?YJ.includes(e)||e.startsWith("-"):!1}async function QJ(t){let{running:e,state:r}=await Tt();if(e)HA(t,r.port);else{await xr(ft)||(console.error("Not authenticated. Run `claude-pilot login` first."),process.exit(1)),console.log("Proxy not running, starting..."),await tg({port:Nu});let{running:s,state:i}=await Tt();(!s||!i)&&(console.error("Failed to start proxy. Check logs with: cat ~/.config/claude-pilot/server.log"),process.exit(1)),console.log(),HA(t,i.port)}}function HA(t,e){let r=UJ("claude",t,{stdio:"inherit",env:{...process.env,ANTHROPIC_BASE_URL:`http://localhost:${e}`,ANTHROPIC_AUTH_TOKEN:"dummy"}});r.on("error",n=>{n.code==="ENOENT"?console.error("Claude CLI not found. Install it with: npm install -g @anthropic-ai/claude-code"):console.error("Failed to run claude:",n.message),process.exit(1)}),r.on("exit",n=>{process.exit(n??0)})}async function ZJ(){MA();let t=process.argv.slice(2);if(t.length===0||!XJ(t)){await QJ(t);return}let e=new Sg,r=FA(),n=r&&r!==rg?`${rg} (update available: ${r})`:rg;e.name("claude-pilot").description("Run Claude Code through GitHub Copilot API").version(n),e.command("login").description("Authenticate with GitHub Copilot").action(async()=>{try{await TA()}catch(s){console.error("Login failed:",s instanceof Error?s.message:s),process.exit(1)}}),e.command("logout").description("Clear credentials and stop proxy").action(async()=>{try{await PA()}catch(s){console.error("Logout failed:",s instanceof Error?s.message:s),process.exit(1)}}),e.command("start").description("Start the proxy server in background").option("-p, --port <port>","Port for proxy and dashboard").action(async s=>{try{await tg({port:s.port?parseInt(s.port,10):void 0})}catch(i){console.error("Start failed:",i instanceof Error?i.message:i),process.exit(1)}}),e.command("stop").description("Stop the running proxy server").action(async()=>{try{await xu()}catch(s){console.error("Stop failed:",s instanceof Error?s.message:s),process.exit(1)}}),e.command("status").description("Show proxy status and configuration").action(async()=>{try{await IA()}catch(s){console.error("Status failed:",s instanceof Error?s.message:s),process.exit(1)}}),e.command("dashboard").description("Open the log viewer dashboard in browser").action(async()=>{try{await NA()}catch(s){console.error("Dashboard failed:",s instanceof Error?s.message:s),process.exit(1)}}),e.parse()}ZJ().catch(t=>{console.error("Error:",t instanceof Error?t.message:t),process.exit(1)});
394
+ `))}}catch{}})}import{readFileSync as BJ}from"node:fs";import{fileURLToPath as GJ}from"node:url";import{dirname as WJ,join as JJ}from"node:path";function KJ(){try{let t=GJ(import.meta.url),e=WJ(t),r=JJ(e,"..","package.json");return JSON.parse(BJ(r,"utf-8")).version||"0.0.0"}catch{return"0.0.0"}}var rg=KJ(),YJ=["login","logout","start","stop","status","dashboard","help"];function XJ(t){let e=t[0];if(!e)return!1;let r=["--help","--version","-h","-V"];return YJ.includes(e)||r.includes(e)}async function QJ(t){let{running:e,state:r}=await Tt();if(e)HA(t,r.port);else{await xr(ft)||(console.error("Not authenticated. Run `claude-pilot login` first."),process.exit(1)),console.log("Proxy not running, starting..."),await tg({port:Nu});let{running:s,state:i}=await Tt();(!s||!i)&&(console.error("Failed to start proxy. Check logs with: cat ~/.config/claude-pilot/server.log"),process.exit(1)),console.log(),HA(t,i.port)}}function HA(t,e){let r=UJ("claude",t,{stdio:"inherit",env:{...process.env,ANTHROPIC_BASE_URL:`http://localhost:${e}`,ANTHROPIC_AUTH_TOKEN:"dummy"}});r.on("error",n=>{n.code==="ENOENT"?console.error("Claude CLI not found. Install it with: npm install -g @anthropic-ai/claude-code"):console.error("Failed to run claude:",n.message),process.exit(1)}),r.on("exit",n=>{process.exit(n??0)})}async function ZJ(){MA();let t=process.argv.slice(2);if(t.length===0||!XJ(t)){await QJ(t);return}let e=new Sg,r=FA(),n=r&&r!==rg?`${rg} (update available: ${r})`:rg;e.name("claude-pilot").description("Run Claude Code through GitHub Copilot API").version(n),e.command("login").description("Authenticate with GitHub Copilot").action(async()=>{try{await TA()}catch(s){console.error("Login failed:",s instanceof Error?s.message:s),process.exit(1)}}),e.command("logout").description("Clear credentials and stop proxy").action(async()=>{try{await PA()}catch(s){console.error("Logout failed:",s instanceof Error?s.message:s),process.exit(1)}}),e.command("start").description("Start the proxy server in background").option("-p, --port <port>","Port for proxy and dashboard").action(async s=>{try{await tg({port:s.port?parseInt(s.port,10):void 0})}catch(i){console.error("Start failed:",i instanceof Error?i.message:i),process.exit(1)}}),e.command("stop").description("Stop the running proxy server").action(async()=>{try{await xu()}catch(s){console.error("Stop failed:",s instanceof Error?s.message:s),process.exit(1)}}),e.command("status").description("Show proxy status and configuration").action(async()=>{try{await IA()}catch(s){console.error("Status failed:",s instanceof Error?s.message:s),process.exit(1)}}),e.command("dashboard").description("Open the log viewer dashboard in browser").action(async()=>{try{await NA()}catch(s){console.error("Dashboard failed:",s instanceof Error?s.message:s),process.exit(1)}}),e.parse()}ZJ().catch(t=>{console.error("Error:",t instanceof Error?t.message:t),process.exit(1)});
395
395
  /*! Bundled license information:
396
396
 
397
397
  @fastify/proxy-addr/index.js: