@constellationdev/cli 0.2.3 → 0.2.4
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/main.js +1 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {base32}from'@scure/base';import {Readable}from'stream';import c from'ansi-colors';import*as ae from'os';import ae__default from'os';import {Agent,fetch as fetch$1}from'undici';import {execFile,spawn}from'child_process';import {promisify}from'util';import {createServer}from'http';import {randomBytes}from'crypto';import Ir from'enquirer';import*as A from'fs/promises';import A__default from'fs/promises';import*as Xe from'fs';import {readFileSync}from'fs';import mo from'tree-sitter';import*as _ from'path';import ___default,{dirname,join}from'path';import En from'ignore';import {z as z$1}from'zod';import ft from'zlib';import {pipeline}from'stream/promises';import {PYTHON_STDLIB_MODULES}from'@constellationdev/types';import {performance}from'perf_hooks';import {findAll,find,parse}from'tsconfck';import Bo from'tree-sitter-javascript';import Ho from'tree-sitter-python';import Uo from'tree-sitter-typescript';import {parseDocument,isMap,isSeq}from'yaml';import {simpleGit}from'simple-git';import {fileURLToPath}from'url';import {Command}from'commander';var Hr=Object.defineProperty;var m=(i,e)=>()=>(i&&(e=i(i=0)),e);var an=(i,e)=>{for(var t in e)Hr(i,t,{get:e[t],enumerable:true});};var Ne,ct=m(()=>{Ne=["help","--help","-h","--version","-V","-v"];});function cn(i){return base32.encode(Buffer.from(i))}var pn=m(()=>{});function gn(i,e,t){let n=`${i}:${e}${t?`:${t}`:""}`;return cn(n)}var dn=m(()=>{pn();});var Re,un=m(()=>{Re=class extends Readable{dataSource;sourceIterator;reading=false;constructor(e){super(),this.dataSource=e,this.sourceIterator=this.dataSource[Symbol.asyncIterator]();}async _read(){if(!this.reading){this.reading=true;try{for(;;){let{value:e,done:t}=await this.sourceIterator.next();if(t){this.push(null);break}let n=JSON.stringify(e)+`
|
|
3
3
|
`,r=Buffer.from(n,"utf8");if(!this.push(r))break}}catch(e){this.destroy(e);}finally{this.reading=false;}}}_destroy(e,t){this.dataSource.return?this.dataSource.return(null).then(()=>t(e),n=>t(e||n)):t(e);}};});function zr(){return process.env.CONSTELLATION_ASCII_MODE==="1"?false:process.env.CI?true:ae.platform()==="win32"?!!(process.env.WT_SESSION||process.env.TERM_PROGRAM==="vscode"||process.env.TERM_PROGRAM==="Hyper"||process.env.TERM&&process.env.TERM!=="cygwin"&&process.env.TERM!=="dumb"):true}var Kr,Vr,Jr,Yr,qr,Xr,Zr,Qr,eo,to,de,C,b,w,y,H,N=m(()=>{Kr="\u2714",Vr="\u2717",Jr="\u26A0",Yr="\u2139",qr="\u26A1",Xr="[OK]",Zr="[ERR]",Qr="[WARN]",eo="[INFO]",to="[>>]",de=zr(),C=c.green(de?Kr:Xr),b=c.red(de?Vr:Zr),w=c.yellow(de?Jr:Qr),y=c.blue(de?Yr:eo),H=c.yellow(de?qr:to);});var Ae,je,x,U,R,Q,pt=m(()=>{dn();un();N();Ae=class{constructor(e,t){this.config=e;this.accessKey=t;}apiVersion="intel/v1";features={};isFeatureEnabled(e){return this.features[e]===true}parseFeatureHeader(e){if(Object.keys(this.features).length>0)return;let t=e.headers.get("X-Features");if(t)for(let n of t.split(",")){let[r,o]=n.split("=");r&&o!==void 0&&(this.features[r]=o==="true");}}async getProjectState(){let e={"Content-Type":"application/x-ndjson; charset=utf-8","x-project-id":this.config.projectId,"x-branch-name":this.config.branch,Authorization:`Bearer ${this.accessKey}`},t=await this.sendRequest("project",void 0,"GET",e);return t&&!t.ok&&await this.handleProjectStateError(t),this.parseFeatureHeader(t),t.json()}async handleProjectStateError(e){try{let t=await e.json(),n=t?.code;switch(n){case "PROJECT_NOT_REGISTERED":throw new R(t?.message||"Project not registered",n,this.config.projectId);case "PROJECT_INACTIVE":throw new R(t?.message||"Project is inactive",n,this.config.projectId);case "INVALID_PROJECT_ID":throw new R(t?.message||"Invalid project ID format",n,this.config.projectId);case "PROJECT_NOT_FOUND":throw new U("Project not found - no previous index exists");default:throw e.status===404?new U("Project not found - no previous index exists"):new Error(`Unexpected API response (${e.status}): ${t?.message||e.statusText}`)}}catch(t){throw t instanceof R||t instanceof U?t:e.status===404?new U("Project not found - no previous index exists"):new Error(`Unexpected API response (${e.status})`)}}async getIndexStatus(e,t){let n=new URLSearchParams({branch:e});t&&n.set("commit",t);let r=`projects/${encodeURIComponent(this.config.projectId)}/index-status?${n.toString()}`;try{let o=await this.sendRequest(r,null,"GET");return !o||!o.ok?null:await o.json()}catch(o){if(o instanceof x)throw o;return null}}async deleteFiles(e){for(let t of e){let n=gn(this.config.projectId,this.config.branch,t);await this.delete(`/ast/${n}`);}}retryableStatusCodes=[500,502,503,504];async streamToApi(e,t,n,r,o,s){try{let{Readable:a}=await import('stream'),l=new Re(e),g=a.toWeb(l),d=new Agent({headersTimeout:0,bodyTimeout:0}),p=await fetch$1(`${this.config.apiUrl}/${this.apiVersion}/${t}`,{method:"POST",headers:{"Content-Type":"application/x-ndjson; charset=utf-8","x-project-id":n,"x-branch-name":r,"x-constellation-index":o?"incremental":"full",Authorization:`Bearer ${this.accessKey}`,...s&&{"x-commit-hash":s}},body:g,duplex:"half",dispatcher:d});if(p.status===401)throw new x("Authentication failed");if(p.status===409){let u="Indexing already in progress",P;try{let v=await p.json();u=v?.message||u,P=v?.details?.branchName;}catch{}throw new Q(u,P)}if(p.status===200)try{let u=await p.json();if(u?.status==="current")return console.log(`${C} Index already up to date for ${r} at commit ${u.commitHash||"unknown"}`),!0}catch{}if(p.ok||p.status===202)return !0;let f=`Server returned ${p.status}`;try{let u=await p.json();u?.message&&(f=Array.isArray(u.message)?u.message.join("; "):u.message);}catch{}throw new Error(f)}catch(a){if(a instanceof x||a instanceof Q)throw a;let l=a instanceof Error?a:new Error(String(a)),g="";if(l.message==="fetch failed"||a.code){let p=[],f=a.code||a.cause?.code;if(a.code&&p.push(`Error Code: ${a.code}`),a.cause){let u=a.cause;u.code&&p.push(`Cause Code: ${u.code}`),u.errno&&p.push(`Errno: ${u.errno}`),u.syscall&&p.push(`System Call: ${u.syscall}`),u.address&&p.push(`Address: ${u.address}`),u.port&&p.push(`Port: ${u.port}`);}f==="ERR_INVALID_ARG_VALUE"?g="Invalid argument value - check stream/body format and duplex option":f==="ECONNREFUSED"?g="Connection refused - service may be down or unreachable":f==="ENOTFOUND"?g="DNS lookup failed - check service URL":f==="ETIMEDOUT"?g="Connection timeout - service not responding":f==="ECONNRESET"?g="Connection reset by server":f==="EHOSTUNREACH"?g="Host unreachable - check network connectivity":g="Network failure",p.length>0&&(g+=` (${p.join(", ")})`);}else g=l.message;let d=new Error(`Failed to upload data to Constellation Service: ${g}`);throw d.cause=l,d.stack=`${d.stack}
|
|
4
|
-
Caused by: ${l.stack}`,d}}async sendRequest(e,t,n,r={},o=0,s=3,a=1e3,l=250){for(let g=1;g<=s;g++)try{let d=new AbortController,p;o>0&&(p=setTimeout(()=>d.abort(),o));let f={...r,"Content-Type":"application/json; charset=utf-8",Accepts:"application/json; charset=utf-8",Authorization:`Bearer ${this.accessKey}`},u=await fetch(`${this.config.apiUrl}/${this.apiVersion}/${e}`,{method:n,headers:f,body:t?JSON.stringify(t):void 0,signal:d.signal});if(p&&clearTimeout(p),u.status===401)throw new x("Authentication failed");if(!u.ok&&this.retryableStatusCodes.includes(u.status))throw new je(`${u.statusText} (${u.status})`);return u}catch(d){if(!(d instanceof x)){let p=d instanceof Error?`${d.message}${d.cause?` (Cause: ${d.cause})`:""}`:String(d);console.log(`HTTP request attempt ${g}/${s} failed: ${p}`);}if(g<s&&d instanceof je){let p=a+Math.floor(Math.random()*l);await new Promise(f=>setTimeout(f,p));}else throw d}}async reportErrors(e){try{let t=await this.sendRequest("error-reports",e,"POST",{},1e4,1,0,0);if(!t){console.warn("Failed to upload error report: no response received");return}if(t.status===403){console.warn("Error reporting is not available on your current plan");return}t.ok||console.warn(`Failed to upload error report: ${t.statusText} (${t.status})`);}catch(t){console.warn(`Failed to upload error report: ${t?.message||"Unknown error"}`);}}async delete(e){let t={"x-project-id":this.config.projectId,"x-branch-name":this.config.branch},n=await this.sendRequest(e,void 0,"DELETE",t);if(n&&!n.ok)throw new Error(`Failed sending HTTP DELETE to ${e}`)}},je=class extends Error{constructor(e){super(e),this.name="RetryableError";}},x=class extends Error{constructor(e){super(e),this.name="AuthenticationError";}},U=class extends Error{constructor(e){super(e),this.name="NotFoundError";}},R=class extends Error{constructor(t,n,r){super(t);this.code=n;this.projectId=r;this.name="ProjectValidationError";}},Q=class extends Error{constructor(t,n){super(t);this.branchName=n;this.name="IndexingInProgressError";}};});async function mn(i){if(!i.startsWith("http://")&&!i.startsWith("https://"))return false;try{switch(process.platform){case "darwin":return await gt("open",[i]),!0;case "linux":return await gt("xdg-open",[i]),!0;case "win32":return await gt("cmd",["/c","start","",i]),!0;default:return !1}}catch{return false}}var gt,hn=m(()=>{gt=promisify(execFile);});function yn(){return new Promise((i,e)=>{let t=createServer(),n,r=false;t.listen(0,"127.0.0.1",()=>{let o=t.address();if(!o||typeof o=="string"){t.close(),e(new Error("Failed to bind callback server"));return}i({port:o.port,close(){n&&(clearTimeout(n),n=void 0),t.close();},waitForCallback(s,a=3e5){return new Promise((l,g)=>{n=setTimeout(()=>{n=void 0,r=true,t.close(),g(new Error("Authentication timed out"));},a),t.on("request",(d,p)=>{let f=new URL(d.url??"/",`http://127.0.0.1:${o.port}`);if(f.pathname!=="/callback"){p.writeHead(404,{"Content-Type":"text/plain"}),p.end("Not found");return}let u=f.searchParams.get("key");if(f.searchParams.get("state")!==s){p.writeHead(400,{"Content-Type":"text/plain"}),p.end("Invalid state parameter");return}if(!u||!ao.test(u)){p.writeHead(400,{"Content-Type":"text/plain"}),p.end("Invalid key format");return}if(r)return;r=true;let v=f.searchParams.get("return_url");v?(p.writeHead(302,{Location:v}),p.end()):(p.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),p.end(lo)),n&&(clearTimeout(n),n=void 0),t.close(),l(u);});})}});}),t.on("error",o=>{e(o);});})}var ao,lo,wn=m(()=>{ao=/^ak:[0-9a-f]{32}$/i,lo=`<!DOCTYPE html>
|
|
4
|
+
Caused by: ${l.stack}`,d}}async sendRequest(e,t,n,r={},o=0,s=3,a=1e3,l=250){for(let g=1;g<=s;g++)try{let d=new AbortController,p;o>0&&(p=setTimeout(()=>d.abort(),o));let f={...r,"Content-Type":"application/json; charset=utf-8",Accepts:"application/json; charset=utf-8",Authorization:`Bearer ${this.accessKey}`},u=await fetch(`${this.config.apiUrl}/${this.apiVersion}/${e}`,{method:n,headers:f,body:t?JSON.stringify(t):void 0,signal:d.signal});if(p&&clearTimeout(p),u.status===401)throw new x("Authentication failed");if(!u.ok&&this.retryableStatusCodes.includes(u.status))throw new je(`${u.statusText} (${u.status})`);return u}catch(d){if(!(d instanceof x)){let p=d instanceof Error?`${d.message}${d.cause?` (Cause: ${d.cause})`:""}`:String(d);console.log(`HTTP request attempt ${g}/${s} failed: ${p}`);}if(g<s&&d instanceof je){let p=a+Math.floor(Math.random()*l);await new Promise(f=>setTimeout(f,p));}else throw d}}async reportErrors(e){try{let t=await this.sendRequest("error-reports",e,"POST",{"x-project-id":this.config.projectId,"x-branch-name":this.config.branch},1e4,1,0,0);if(!t){console.warn("Failed to upload error report: no response received");return}if(t.status===403){console.warn("Error reporting is not available on your current plan");return}t.ok||console.warn(`Failed to upload error report: ${t.statusText} (${t.status})`);}catch(t){console.warn(`Failed to upload error report: ${t?.message||"Unknown error"}`);}}async delete(e){let t={"x-project-id":this.config.projectId,"x-branch-name":this.config.branch},n=await this.sendRequest(e,void 0,"DELETE",t);if(n&&!n.ok)throw new Error(`Failed sending HTTP DELETE to ${e}`)}},je=class extends Error{constructor(e){super(e),this.name="RetryableError";}},x=class extends Error{constructor(e){super(e),this.name="AuthenticationError";}},U=class extends Error{constructor(e){super(e),this.name="NotFoundError";}},R=class extends Error{constructor(t,n,r){super(t);this.code=n;this.projectId=r;this.name="ProjectValidationError";}},Q=class extends Error{constructor(t,n){super(t);this.branchName=n;this.name="IndexingInProgressError";}};});async function mn(i){if(!i.startsWith("http://")&&!i.startsWith("https://"))return false;try{switch(process.platform){case "darwin":return await gt("open",[i]),!0;case "linux":return await gt("xdg-open",[i]),!0;case "win32":return await gt("cmd",["/c","start","",i]),!0;default:return !1}}catch{return false}}var gt,hn=m(()=>{gt=promisify(execFile);});function yn(){return new Promise((i,e)=>{let t=createServer(),n,r=false;t.listen(0,"127.0.0.1",()=>{let o=t.address();if(!o||typeof o=="string"){t.close(),e(new Error("Failed to bind callback server"));return}i({port:o.port,close(){n&&(clearTimeout(n),n=void 0),t.close();},waitForCallback(s,a=3e5){return new Promise((l,g)=>{n=setTimeout(()=>{n=void 0,r=true,t.close(),g(new Error("Authentication timed out"));},a),t.on("request",(d,p)=>{let f=new URL(d.url??"/",`http://127.0.0.1:${o.port}`);if(f.pathname!=="/callback"){p.writeHead(404,{"Content-Type":"text/plain"}),p.end("Not found");return}let u=f.searchParams.get("key");if(f.searchParams.get("state")!==s){p.writeHead(400,{"Content-Type":"text/plain"}),p.end("Invalid state parameter");return}if(!u||!ao.test(u)){p.writeHead(400,{"Content-Type":"text/plain"}),p.end("Invalid key format");return}if(r)return;r=true;let v=f.searchParams.get("return_url");v?(p.writeHead(302,{Location:v}),p.end()):(p.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),p.end(lo)),n&&(clearTimeout(n),n=void 0),t.close(),l(u);});})}});}),t.on("error",o=>{e(o);});})}var ao,lo,wn=m(()=>{ao=/^ak:[0-9a-f]{32}$/i,lo=`<!DOCTYPE html>
|
|
5
5
|
<html><head><title>Authentication Successful</title></head>
|
|
6
6
|
<body><h1>Authentication successful! You can close this tab.</h1></body></html>`;});function dt(i){console.log(`\u256D\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256E
|
|
7
7
|
\u2502 ${c.gray("'")} ${c.blueBright(".")} ${c.dim("`")} ${c.yellowBright("'")} ${c.blueBright("+")} ${c.whiteBright(".")} ${c.gray(".")} ${c.yellowBright("'")} ${c.yellowBright("*")} ${c.whiteBright("'")} ${c.blueBright("+")} ${c.gray(".")} ${c.yellowBright("*")} ${c.whiteBright(",")} ${c.gray.dim(".")}\u2502
|