@hlix/cli 0.5.1 → 0.5.3
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/README.md +8 -6
- package/dist/index-mpmj2yxq.js +204 -0
- package/dist/index.js +2 -2
- package/dist/main-jdcfzt1f.js +60 -0
- package/dist/{package-3m9rgs58.js → package-ef5qa8w8.js} +1 -1
- package/package.json +1 -1
- package/skills/hlix/SKILL.md +13 -5
- package/dist/index-mwwmk5q2.js +0 -202
- package/dist/main-n4cj07p6.js +0 -61
package/dist/index-mwwmk5q2.js
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{y as jo}from"./index-f303pf32.js";class y extends Error{code;constructor(e,t){super(t);this.name="CliError",this.code=e}}var Qa=1,j=(e,t)=>({schemaVersion:1,command:e,data:t}),xe=(e,t)=>({schemaVersion:1,command:e,error:t});function k(e){return`${JSON.stringify(e,null,2)}
|
|
3
|
-
`}function A(e){let t=Math.max(0,...e.map(([n])=>n.length));return e.map(([n,r])=>`${n.padEnd(t)} ${r}`).join(`
|
|
4
|
-
`)}function X(e,t){let n=e.map((o,s)=>Math.max(o.length,...t.map((i)=>(i[s]??"").length))),r=(o)=>o.map((s,i)=>s.padEnd(n[i])).join(" ").trimEnd();return[r(e),r(n.map((o)=>"-".repeat(o))),...t.map(r)].join(`
|
|
5
|
-
`)}import{statSync as io}from"node:fs";import{dirname as ao,resolve as co}from"node:path";import{closeSync as Ot,constants as Ie,existsSync as at,fsyncSync as dr,lstatSync as At,mkdirSync as Ws,openSync as pr,readFileSync as ur,renameSync as Vs,statSync as mr,unlinkSync as fr,writeFileSync as Ys}from"node:fs";import{homedir as Xs}from"node:os";import{dirname as Zs,join as Ft}from"node:path";function me(e=process.env){let t=e.HLIX_CONFIG_HOME??e.XDG_CONFIG_HOME??Ft(Xs(),".config");return Ft(t,"hlix","credentials.json")}function gr(e=process.env){let t=e.HLIX_API_KEY;if(!t&&e.HLIX_SESSION_TOKEN)return{baseUrl:e.HLIX_BASE_URL??"https://server.hlix.ai",apiKey:"",sessionToken:e.HLIX_SESSION_TOKEN,...e.HLIX_WORKSPACE_ID?{organizationId:e.HLIX_WORKSPACE_ID}:{}};if(t)return{baseUrl:e.HLIX_BASE_URL??"https://server.hlix.ai",apiKey:t,...e.HLIX_WORKSPACE_ID?{organizationId:e.HLIX_WORKSPACE_ID}:{}};try{let n=JSON.parse(ur(me(e),"utf8"));return n.apiKey&&n.baseUrl?n:null}catch{return null}}function hr(e=process.env){let t=me(e);return at(t)?t:null}function Nt(e=process.env){let t=me(e);if(!at(t))return{path:t,removed:!1,reason:"absent"};let n=At(t);if(n.isSymbolicLink()||!n.isFile())throw Error("Refusing to remove a credential path that is not a regular file.");let r=process.getuid?.();if(r!==void 0&&mr(t).uid!==r)throw Error("Refusing to remove a credential file owned by another user.");let o;try{o=JSON.parse(ur(t,"utf8"))}catch{o=null}let s=o;if(!s||typeof s.apiKey!=="string"||typeof s.baseUrl!=="string")throw Error(`Refusing to remove ${t}: it is not a credential written by this CLI.`);return fr(t),{path:t,removed:!0,reason:"removed"}}function yr(e,t=process.env){let n=me(t),r=Zs(n);if(Ws(r,{recursive:!0,mode:448}),At(r).isSymbolicLink())throw Error("Refusing to write credentials through a symlinked directory.");if(at(n)){let i=At(n);if(i.isSymbolicLink()||!i.isFile())throw Error("Refusing to replace a credential path that is not a regular file.");let c=process.getuid?.();if(c!==void 0&&mr(n).uid!==c)throw Error("Refusing to replace a credential file owned by another user.")}let o=Ft(r,`.credentials.${process.pid}.${crypto.randomUUID()}.tmp`),s;try{s=pr(o,Ie.O_WRONLY|Ie.O_CREAT|Ie.O_EXCL|Ie.O_NOFOLLOW,384),Ys(s,`${JSON.stringify(e,null,2)}
|
|
6
|
-
`,"utf8"),dr(s),Ot(s),s=void 0,Vs(o,n);let i=pr(r,Ie.O_RDONLY);try{try{dr(i)}catch(c){let a=c.code;if(a!=="EINVAL"&&a!=="ENOTSUP")throw c}}finally{Ot(i)}}catch(i){if(s!==void 0)Ot(s);if(at(o))fr(o);throw i}return n}import{constants as ct,existsSync as lt,lstatSync as vr,mkdirSync as Qs,openSync as eo,closeSync as wr,fsyncSync as to,readFileSync as kr,renameSync as no,unlinkSync as ro,writeFileSync as Lt}from"node:fs";import{dirname as so,join as Re,resolve as dt}from"node:path";function oo(e){if(!lt(e))return;let t=vr(e);if(t.isSymbolicLink()||!t.isFile())throw Error(`Refusing to replace a non-regular Hlix file: ${e}`)}function Te(e,t){let n=so(e);if(Qs(n,{recursive:!0,mode:448}),vr(n).isSymbolicLink())throw Error(`Refusing to write through a symlinked Hlix directory: ${n}`);oo(e);let r=Re(n,`.hlix-${process.pid}-${crypto.randomUUID()}.tmp`),o;try{o=eo(r,ct.O_WRONLY|ct.O_CREAT|ct.O_EXCL|ct.O_NOFOLLOW,384),Lt(o,`${JSON.stringify(t,null,2)}
|
|
7
|
-
`,"utf8"),to(o),wr(o),o=void 0,no(r,e)}catch(s){if(o!==void 0)wr(o);if(lt(r))ro(r);throw s}}function _e(e){return Re(dt(e),".hlix","config.json")}function Sr(e){return Re(dt(e),".hlix","state.json")}function fe(e){try{let t=JSON.parse(kr(_e(e),"utf8"));return t.schemaVersion===1&&t.workspaceId&&t.apiUrl?t:null}catch{return null}}function Oe(e,t){Te(_e(e),t);let n=Re(dt(e),".hlix",".gitignore");if(!lt(n))Lt(n,`state.json
|
|
8
|
-
`,{mode:420,flag:"wx"});let r=Re(dt(e),".hlixignore");if(!lt(r))Lt(r,`# Additional project-local paths to exclude from Hlix snapshots.
|
|
9
|
-
`,{mode:420,flag:"wx"})}function Ae(e,t){Te(Sr(e),t)}function pt(e){try{let t=JSON.parse(kr(Sr(e),"utf8"));return t.schemaVersion===1&&t.revisionId&&t.generation>0?t:null}catch{return null}}var Ht="https://server.hlix.ai";function mt(e){if(!e.credential)return null;if(e.credentialSource==="session")return"session (desktop)";if(e.credentialSource==="env")return"environment (HLIX_API_KEY)";return`file (${e.credentialPath})`}function N(e){let t=co(e);for(;;){let n=fe(t);if(n)return{root:t,config:n};let r=ao(t);if(r===t)return null;t=r}}function jr(e){try{return io(e).isDirectory()}catch{return!1}}function ut(e){if(typeof e!=="string")return;let t=e.trim();return t?t:void 0}var br=(e,t)=>e.replace(/\/+$/,"")===t.replace(/\/+$/,"");function J(e){let{env:t,flags:n,cwd:r}=e,o=N(r),s=gr(t),i=s?t.HLIX_API_KEY?"env":t.HLIX_SESSION_TOKEN?"session":"file":null,c=i==="file"?s:null,a=ut(n["base-url"]),l=ut(t.HLIX_BASE_URL),u=ut(n.workspace),d=ut(t.HLIX_WORKSPACE_ID),m=a??l??o?.config.apiUrl??c?.baseUrl??Ht,S=a?"flag":l?"env":o?.config.apiUrl?"project":c?.baseUrl?"credential":"default",g=u??d??o?.config.workspaceId??c?.organizationId??null,p=u?"flag":d?"env":o?.config.workspaceId?"project":c?.organizationId?"credential":null;return{baseUrl:m,baseUrlSource:S,workspaceId:g,workspaceSource:p,credential:s,credentialSource:i,credentialPath:me(t),binding:o,conflict:lo(o,{flagBaseUrl:a,envBaseUrl:l,flagWorkspace:u,envWorkspace:d})}}function lo(e,t){if(!e)return null;let n=`${e.root} is bound to`,r="Drop the override, or point --cwd at a folder bound to it.";if(t.flagWorkspace&&t.flagWorkspace!==e.config.workspaceId)return`${n} workspace ${e.config.workspaceId}, but --workspace names ${t.flagWorkspace}. ${r}`;if(t.envWorkspace&&t.envWorkspace!==e.config.workspaceId)return`${n} workspace ${e.config.workspaceId}, but HLIX_WORKSPACE_ID names ${t.envWorkspace}. ${r}`;if(t.flagBaseUrl&&!br(t.flagBaseUrl,e.config.apiUrl))return`${n} ${e.config.apiUrl}, but --base-url names ${t.flagBaseUrl}. ${r}`;if(t.envBaseUrl&&!br(t.envBaseUrl,e.config.apiUrl))return`${n} ${e.config.apiUrl}, but HLIX_BASE_URL names ${t.envBaseUrl}. ${r}`;return null}import{resolve as Eo}from"node:path";import{parseArgs as $o}from"node:util";import po from"openapi-fetch";function Mt(e){return po({baseUrl:e.baseUrl,headers:e.headers,fetch:e.fetch})}var ge=(e)=>({kind:"apiKey",apiKey:e});var Ut=(e)=>({kind:"bearer",token:e});function uo(e){switch(e.kind){case"apiKey":return{"x-api-key":e.apiKey};case"session":return{cookie:e.cookie};case"bearer":return{authorization:`Bearer ${e.token}`}}}function mo(e){return e?{"X-Organization-Id":e}:{}}function Er(e,t){return{...uo(e),...mo(t)}}function fo(e){if(typeof e!=="object"||e===null)return null;let{error:t}=e;return typeof t==="string"?t:null}class D extends Error{status;body;requestId;method;url;constructor(e,t){super(e);this.name=new.target.name,this.status=t.status,this.body=t.body,this.requestId=t.requestId??null,this.method=t.method,this.url=t.url}}class Fe extends D{issues;constructor(e,t,n){super(e,t);this.issues=n}}class Ne extends D{}class Le extends D{}class He extends D{}class Me extends D{}class Ue extends D{}class ze extends D{retryAfter;constructor(e,t,n){super(e,t);this.retryAfter=n}}class Be extends D{}class De extends D{}class he extends Error{method;url;constructor(e,t){super(e,{cause:t.cause});this.name="HlixTransportError",this.method=t.method,this.url=t.url}}function go(e){if(typeof e!=="object"||e===null)return null;let t=e;if(t.success!==!1)return null;let n=t.error?.message;if(typeof n!=="string")return null;try{let r=JSON.parse(n);return Array.isArray(r)?r:[]}catch{return[]}}function ho(e){let t=e.get("retry-after");if(!t)return null;let n=Number(t);return Number.isFinite(n)&&n>=0?n:null}function ye(e,t,n){let r={status:e.status,body:t,requestId:e.headers.get("x-request-id"),method:n.method,url:n.url},o=fo(t),s=`${n.method} ${n.url} failed with ${e.status}`,i=go(t);if(i)return new Fe(`${n.method} ${n.url}: request body failed validation`,r,i);let c=o??s;switch(e.status){case 400:return new Ne(c,r);case 401:return new Le(c,r);case 403:return new He(c,r);case 404:return new Me(c,r);case 409:return new Ue(c,r);case 429:return new ze(c,r,ho(e.headers));case 501:return new Be(c,r);default:return e.status>=500?new De(c,r):new D(c,r)}}var $r=new Set(["GET","HEAD","PUT","DELETE","OPTIONS","TRACE"]);function ft(e){return $r.has(e.toUpperCase())}var yo=new Set([429,500,502,503,504]);function wo(e){return yo.has(e)}var zt={attempts:3,baseDelayMs:200,maxDelayMs:5000};function Bt(e,t,n,r=Math.random){if(n!==null)return Math.min(n*1000,t.maxDelayMs);let o=Math.min(t.baseDelayMs*2**e,t.maxDelayMs);return Math.round(r()*o)}function Dt(e){if(!ft(e.method))return!1;if(e.attempt+1>=e.policy.attempts)return!1;return e.status===null||wo(e.status)}var vo=(e)=>new Promise((t)=>setTimeout(t,e));function ko(e){let t=e.headers.get("retry-after");if(!t)return null;let n=Number(t);return Number.isFinite(n)&&n>=0?n:null}function Pr(e){let{base:t,policy:n}=e,r=e.sleep??vo,o=e.random??Math.random;return async(s)=>{let i=s.method.toUpperCase(),c=ft(i)?s.clone():null;for(let a=0;;a+=1){let l=a===0?s:c.clone(),u;try{u=await t(l)}catch(d){if(!c||!Dt({method:i,attempt:a,policy:n,status:null}))throw new he(`${i} ${s.url}: ${d instanceof Error?d.message:String(d)}`,{method:i,url:s.url,cause:d});await r(Bt(a,n,null,o));continue}if(!Dt({method:i,attempt:a,policy:n,status:u.status}))return u;if(!c)return u;await r(Bt(a,n,ko(u),o))}}}function b(e,t){if(e.response.ok)return e.data;throw ye(e.response,e.error??e.data,t)}var Ke=(e)=>typeof e==="string"?e:"";function Kt(e){let t;try{t=JSON.parse(e)}catch{return null}if(typeof t!=="object"||t===null)return null;let n=t;switch(n.type){case"idle":return{type:"idle"};case"done":return{type:"done"};case"active":return typeof n.runId==="string"?{type:"active",runId:n.runId}:{type:"active"};case"on_chat_model_stream":return{type:"on_chat_model_stream",delta:Ke(n.delta)};case"reasoning":return{type:"reasoning",delta:Ke(n.delta)};case"on_tool_start":return{type:"on_tool_start",name:Ke(n.name),input:n.input};case"on_tool_end":return{type:"on_tool_end",name:Ke(n.name),output:n.output};case"error":return{type:"error",message:Ke(n.message)};default:return null}}var Jt=(e)=>e.type==="done"||e.type==="idle"||e.type==="error";var So=()=>({event:null,data:[],id:null,retry:null});function Cr(e,t,n){switch(t){case"event":e.event=n;return;case"data":e.data.push(n);return;case"id":if(!n.includes("\x00"))e.id=n;return;case"retry":{if(/^\d+$/.test(n))e.retry=Number(n);return}default:return}}function Ir(e){let t=e.data.join(`
|
|
10
|
-
`),n=e.event,r=e.id;if(e.data=[],e.event=null,t==="")return null;return{event:n,data:t,id:r,retry:e.retry}}function xr(e,t){if(t==="")return Ir(e);if(t.startsWith(":"))return null;let n=t.indexOf(":");if(n===-1)return Cr(e,t,""),null;let r=t.slice(0,n),o=t.slice(n+1);if(o.startsWith(" "))o=o.slice(1);return Cr(e,r,o),null}function bo(e){let t=[],n=0;for(let r=0;r<e.length;r+=1){let o=e[r];if(o!==`
|
|
11
|
-
`&&o!=="\r")continue;if(t.push(e.slice(n,r)),o==="\r"&&e[r+1]===`
|
|
12
|
-
`)r+=1;n=r+1}return{lines:t,rest:e.slice(n)}}async function*Gt(e,t){let n=e.getReader(),r=new TextDecoder,o=So(),s="",i=()=>void n.cancel().catch(()=>{});t?.addEventListener("abort",i,{once:!0});try{for(;;){let{done:a,value:l}=await n.read();if(a)break;s+=r.decode(l,{stream:!0});let{lines:u,rest:d}=bo(s);s=d;for(let m of u){let S=xr(o,m);if(S)yield S}if(t?.aborted)return}if(s+=r.decode(),s!==""){let a=xr(o,s);if(a)yield a}let c=Ir(o);if(c)yield c}finally{t?.removeEventListener("abort",i),n.releaseLock()}}class we{raw;baseUrl;headers;fetcher;constructor(e){this.baseUrl=e.baseUrl.replace(/\/+$/,""),this.headers=Er(e.credential,e.organizationId);let t={...zt,...e.retry},n=e.fetch??((r)=>globalThis.fetch(r));this.fetcher=Pr({base:n,policy:t}),this.raw=Mt({baseUrl:this.baseUrl,headers:this.headers,fetch:this.fetcher})}at(e,t){return{method:e,url:`${this.baseUrl}${t}`}}workspaces={list:async()=>b(await this.raw.GET("/v1/api/workspaces"),this.at("GET","/v1/api/workspaces"))};projects={list:async()=>b(await this.raw.GET("/v1/api/projects"),this.at("GET","/v1/api/projects")),get:async(e)=>b(await this.raw.GET("/v1/api/projects/{id}",{params:{path:{id:e}}}),this.at("GET",`/v1/api/projects/${e}`)),create:async(e)=>b(await this.raw.POST("/v1/api/projects",{body:e}),this.at("POST","/v1/api/projects")),delete:async(e)=>b(await this.raw.DELETE("/v1/api/projects/{id}",{params:{path:{id:e}}}),this.at("DELETE",`/v1/api/projects/${e}`)),start:async(e,t)=>b(await this.raw.POST("/v1/api/projects/{id}/start",{params:{path:{id:e}},body:t}),this.at("POST",`/v1/api/projects/${e}/start`)),refreshPreview:async(e)=>b(await this.raw.POST("/v1/api/projects/{id}/preview/refresh",{params:{path:{id:e}}}),this.at("POST",`/v1/api/projects/${e}/preview/refresh`)),terminal:async(e)=>b(await this.raw.GET("/v1/api/projects/{id}/terminal",{params:{path:{id:e}}}),this.at("GET",`/v1/api/projects/${e}/terminal`)),observeAgent:(e,t,n)=>this.observeAgent(e,t,n),workspace:(e)=>({environment:async()=>b(await this.raw.GET("/v1/api/projects/{id}/environment",{params:{path:{id:e}}}),this.at("GET",`/v1/api/projects/${e}/environment`)),fs:async(t)=>b(await this.raw.POST("/v1/api/projects/{id}/workspace/fs",{params:{path:{id:e}},body:t}),this.at("POST",`/v1/api/projects/${e}/workspace/fs`)),exec:async(t)=>b(await this.raw.POST("/v1/api/projects/{id}/workspace/exec",{params:{path:{id:e}},body:t}),this.at("POST",`/v1/api/projects/${e}/workspace/exec`))})};secrets={listEntries:async(e)=>b(await this.raw.GET("/v1/api/secrets/project/{projectId}/entries",{params:{path:{projectId:e}}}),this.at("GET",`/v1/api/secrets/project/${e}/entries`)),upsertEntries:async(e,t)=>b(await this.raw.PUT("/v1/api/secrets/project/{projectId}/entries",{params:{path:{projectId:e}},body:t}),this.at("PUT",`/v1/api/secrets/project/${e}/entries`)),importFiles:async(e,t)=>b(await this.raw.PUT("/v1/api/secrets/project/{projectId}/files",{params:{path:{projectId:e}},body:{files:t}}),this.at("PUT",`/v1/api/secrets/project/${e}/files`)),deleteEntry:async(e,t,n)=>b(await this.raw.DELETE("/v1/api/secrets/project/{projectId}/entries/{key}",{params:{path:{projectId:e,key:t},...n===void 0?{}:{query:{source:n}}}}),this.at("DELETE",`/v1/api/secrets/project/${e}/entries/${encodeURIComponent(t)}`)),exportEntries:async(e,t={})=>{let n=`/v1/api/secrets/project/${e}/export`,r=`${this.baseUrl}${n}`,o=await this.fetcher(new Request(r,{method:"POST",headers:{...this.headers,"content-type":"application/json"},body:JSON.stringify({...t.source===void 0?{}:{source:t.source},...t.format===void 0?{}:{format:t.format}})}));if(!o.ok)throw ye(o,await o.json().catch(()=>{return}),{method:"POST",url:r});return o.text()}};imports={create:async(e)=>{let t=await this.raw.POST("/v1/api/imports",{body:e});return b(t,this.at("POST","/v1/api/imports"))},get:async(e)=>b(await this.raw.GET("/v1/api/imports/{id}",{params:{path:{id:e}}}),this.at("GET",`/v1/api/imports/${e}`)),finalize:async(e,t)=>{let n=await this.raw.POST("/v1/api/imports/{id}/finalize",{params:{path:{id:e}},body:t});return b(n,this.at("POST",`/v1/api/imports/${e}/finalize`))},uploadBundle:async(e,t,n={})=>{let r=n.chunkSize??8388608;if(r<=0||r%262144!==0)throw Error("Import upload chunkSize must be a positive multiple of 256 KiB");let o=e.url.startsWith("/")?`${this.baseUrl}${e.url}`:e.url;if(e.kind==="hlix-stream"){let i=new Request(o,{method:"PUT",headers:{...this.headers,"content-type":"application/x-git-bundle","content-length":String(t.size)},body:t,signal:n.signal}),c=await this.fetcher(i);if(!c.ok)await this.throwUploadError(c,o);n.onProgress?.(t.size,t.size);return}let s=0;while(s<t.size){let i=Math.min(s+r,t.size),c=new Request(o,{method:"PUT",headers:{"content-type":"application/x-git-bundle","content-length":String(i-s),"content-range":`bytes ${s}-${i-1}/${t.size}`},body:t.slice(s,i),signal:n.signal}),a=await this.fetcher(c);if(a.status!==308&&!a.ok)await this.throwUploadError(a,o);let l=a.headers.get("range")?.match(/bytes=0-(\d+)/)?.[1];if(s=l?Number(l)+1:i,!Number.isSafeInteger(s)||s<i||s>t.size)throw Error("Import upload server returned an invalid acknowledged range");n.onProgress?.(s,t.size)}}};revisions={head:async(e)=>b(await this.raw.GET("/v1/api/projects/{id}/revisions/head",{params:{path:{id:e}}}),this.at("GET",`/v1/api/projects/${e}/revisions/head`)),protectedFiles:async(e)=>b(await this.raw.GET("/v1/api/projects/{id}/protected-files",{params:{path:{id:e}}}),this.at("GET",`/v1/api/projects/${e}/protected-files`)),createUpload:async(e,t)=>{let n=await this.raw.POST("/v1/api/projects/{id}/revisions/uploads",{params:{path:{id:e}},body:t});return b(n,this.at("POST",`/v1/api/projects/${e}/revisions/uploads`))},finalize:async(e,t,n)=>{let r=await this.raw.POST("/v1/api/projects/{id}/revisions/uploads/{uploadId}/finalize",{params:{path:{id:e,uploadId:t}},body:n});return b(r,this.at("POST",`/v1/api/projects/${e}/revisions/uploads/${t}/finalize`))},uploadBundle:async(e,t,n={})=>this.imports.uploadBundle(e,t,n),downloadBundle:async(e,t)=>{let n=`/v1/api/projects/${e}/revisions/${t}/bundle`,r=new Request(`${this.baseUrl}${n}`,{method:"GET",headers:this.headers}),o=await this.fetcher(r);if(!o.ok)await this.throwUploadError(o,`${this.baseUrl}${n}`);return o.blob()}};resources={importSkill:async(e,t)=>b(await this.raw.POST("/v1/api/projects/{id}/resources/skill",{params:{path:{id:e}},body:t}),this.at("POST",`/v1/api/projects/${e}/resources/skill`)),importAgent:async(e,t)=>b(await this.raw.POST("/v1/api/projects/{id}/resources/agent",{params:{path:{id:e}},body:t}),this.at("POST",`/v1/api/projects/${e}/resources/agent`)),importMcp:async(e,t)=>b(await this.raw.POST("/v1/api/projects/{id}/resources/mcp",{params:{path:{id:e}},body:t}),this.at("POST",`/v1/api/projects/${e}/resources/mcp`))};async throwUploadError(e,t){let n=null;try{n=await e.json()}catch{n=await e.text().catch(()=>null)}throw ye(e,n,{method:"PUT",url:t})}tasks={list:async(e)=>b(await this.raw.GET("/v1/api/tasks",{params:{query:e??{}}}),this.at("GET","/v1/api/tasks")),get:async(e)=>b(await this.raw.GET("/v1/api/tasks/{id}",{params:{path:{id:e}}}),this.at("GET",`/v1/api/tasks/${e}`)),create:async(e)=>b(await this.raw.POST("/v1/api/tasks",{body:e}),this.at("POST","/v1/api/tasks")),update:async(e,t)=>b(await this.raw.PATCH("/v1/api/tasks/{id}",{params:{path:{id:e}},body:t}),this.at("PATCH",`/v1/api/tasks/${e}`)),listComments:async(e)=>b(await this.raw.GET("/v1/api/tasks/{id}/comments",{params:{path:{id:e}}}),this.at("GET",`/v1/api/tasks/${e}/comments`)),addComment:async(e,t)=>b(await this.raw.POST("/v1/api/tasks/{id}/comments",{params:{path:{id:e}},body:t}),this.at("POST",`/v1/api/tasks/${e}/comments`)),review:async(e)=>b(await this.raw.GET("/v1/api/tasks/{id}/review",{params:{path:{id:e}}}),this.at("GET",`/v1/api/tasks/${e}/review`)),stream:(e,t)=>this.stream(`/v1/api/tasks/${e}/stream`,t)};modelConfig={setProjectHarness:async(e,t)=>b(await this.raw.PUT("/v1/api/model-config/harness/{projectId}",{params:{path:{projectId:e}},body:{harness:t}}),this.at("PUT",`/v1/api/model-config/harness/${e}`)),clearProjectHarness:async(e)=>b(await this.raw.DELETE("/v1/api/model-config/harness/{projectId}",{params:{path:{projectId:e}}}),this.at("DELETE",`/v1/api/model-config/harness/${e}`)),setHarness:async(e)=>b(await this.raw.PUT("/v1/api/model-config/harness",{body:{harness:e}}),this.at("PUT","/v1/api/model-config/harness")),clearHarness:async()=>b(await this.raw.DELETE("/v1/api/model-config/harness"),this.at("DELETE","/v1/api/model-config/harness")),resolvedHarness:async()=>b(await this.raw.GET("/v1/api/model-config/harness/resolved"),this.at("GET","/v1/api/model-config/harness/resolved")),resolvedProjectHarness:async(e)=>b(await this.raw.GET("/v1/api/model-config/harness/{projectId}/resolved",{params:{path:{projectId:e}}}),this.at("GET",`/v1/api/model-config/harness/${e}/resolved`))};ai={models:async(e,t)=>b(await this.raw.GET("/v1/api/ai/w/{workspaceId}/models",{params:{path:{workspaceId:e}},...t?.signal?{signal:t.signal}:{}}),this.at("GET",`/v1/api/ai/w/${e}/models`))};cycles={list:async(e)=>b(await this.raw.GET("/v1/api/cycles",{params:{query:e??{}}}),this.at("GET","/v1/api/cycles")),get:async(e)=>b(await this.raw.GET("/v1/api/cycles/{id}",{params:{path:{id:e}}}),this.at("GET",`/v1/api/cycles/${e}`)),propose:async(e)=>b(await this.raw.POST("/v1/api/cycles",{body:e}),this.at("POST","/v1/api/cycles")),stream:(e,t)=>this.stream(`/v1/api/cycles/${e}/stream`,t)};clientInvoices={list:async(e)=>b(await this.raw.GET("/v1/api/client-billing/invoices",{params:{query:e??{}}}),this.at("GET","/v1/api/client-billing/invoices")),get:async(e)=>b(await this.raw.GET("/v1/api/client-billing/invoices/{id}",{params:{path:{id:e}}}),this.at("GET",`/v1/api/client-billing/invoices/${e}`)),createDraft:async(e)=>b(await this.raw.POST("/v1/api/client-billing/invoices",{body:e}),this.at("POST","/v1/api/client-billing/invoices")),issue:async(e)=>b(await this.raw.POST("/v1/api/client-billing/invoices/{id}/issue",{params:{path:{id:e}},body:{}}),this.at("POST",`/v1/api/client-billing/invoices/${e}/issue`)),void:async(e,t)=>b(await this.raw.POST("/v1/api/client-billing/invoices/{id}/void",{params:{path:{id:e}},body:{reason:t}}),this.at("POST",`/v1/api/client-billing/invoices/${e}/void`)),pay:async(e)=>b(await this.raw.POST("/v1/api/client-billing/invoices/{id}/pay",{params:{path:{id:e}},body:{}}),this.at("POST",`/v1/api/client-billing/invoices/${e}/pay`)),paymentLink:async(e,t={})=>b(await this.raw.POST("/v1/api/client-billing/invoices/{id}/payment-link",{params:{path:{id:e}},body:t}),this.at("POST",`/v1/api/client-billing/invoices/${e}/payment-link`))};async*observeAgent(e,t,n){let r=`/v1/api/projects/${e}/agents/${t}/observe`;for await(let o of this.stream(r,n)){let s=Kt(o.data);if(!s)continue;if(yield s,Jt(s))return}}async*stream(e,t){let n=`${this.baseUrl}${e}`,r=new Request(n,{headers:{...this.headers,accept:"text/event-stream"},signal:t?.signal}),o=await globalThis.fetch(r);if(!o.ok||!o.body){let s=null;try{s=await o.json()}catch{s=null}throw ye(o,s,{method:"GET",url:n})}yield*Gt(o.body,t?.signal)}}function Vt(e){if(e instanceof y)return{code:e.code,status:null};if(e instanceof Fe)return{code:"invalid_request",status:400};if(e instanceof Ne)return{code:"bad_request",status:400};if(e instanceof Le)return{code:"unauthenticated",status:401};if(e instanceof He)return{code:"forbidden",status:403};if(e instanceof Me)return{code:"not_found",status:404};if(e instanceof Ue)return{code:"conflict",status:409};if(e instanceof ze)return{code:"rate_limited",status:429};if(e instanceof Be)return{code:"not_implemented",status:501};if(e instanceof De)return{code:"server_error",status:e.status};if(e instanceof he)return{code:"unreachable",status:null};return{code:"unknown",status:null}}var qt=(e)=>e instanceof Error?e.message:String(e);function Po(e,t){let n=J({env:e,flags:t.flags,cwd:t.cwd});if(n.conflict)throw new y("workspace_mismatch",n.conflict);if(!n.credential)throw new y("unauthenticated","No credential. Run `hlix auth login`, or set HLIX_API_KEY for CI.");return new we({baseUrl:n.baseUrl,credential:n.credential.sessionToken?Ut(n.credential.sessionToken):ge(n.credential.apiKey),...n.workspaceId?{organizationId:n.workspaceId}:{}})}function Rr(e){let t=Math.max(...e.map((r)=>r.name.length));return`hlix — the hlix control-plane CLI
|
|
13
|
-
|
|
14
|
-
Usage:
|
|
15
|
-
hlix <command> [options]
|
|
16
|
-
|
|
17
|
-
Commands:
|
|
18
|
-
${[` hlix ${"".padEnd(t)} Open Hlix Code (interactive)`,...e.map((r)=>` hlix ${r.name.padEnd(t)} ${r.summary}`)].join(`
|
|
19
|
-
`)}
|
|
20
|
-
|
|
21
|
-
Options:
|
|
22
|
-
--json Machine-readable output (a versioned, stable contract)
|
|
23
|
-
--cwd <dir> Operate on another directory instead of the current one
|
|
24
|
-
--workspace <id> Workspace to act in, overriding the folder's binding
|
|
25
|
-
--base-url <url> API to talk to, overriding the folder's binding
|
|
26
|
-
--help Show this help
|
|
27
|
-
--version Show the installed CLI version
|
|
28
|
-
|
|
29
|
-
Hlix Code (hlix with no command):
|
|
30
|
-
--sandbox <choice> cloud, docker or local; --local is short for local
|
|
31
|
-
--docker-image <r> image the docker sandbox runs in
|
|
32
|
-
--harness <name> which coder does the work
|
|
33
|
-
--project <id> project to act in, when this folder is not bound
|
|
34
|
-
-p "<prompt>" one turn, print the answer, exit
|
|
35
|
-
--json with -p: one JSON object per event instead of prose
|
|
36
|
-
--allow-writes with -p: let the turn change files and run commands
|
|
37
|
-
--yolo approve every tool call for the whole session
|
|
38
|
-
|
|
39
|
-
A command targets the workspace named by, in order: an explicit flag, the
|
|
40
|
-
HLIX_* environment, the nearest .hlix/config.json, then the stored credential.
|
|
41
|
-
Run \`hlix status\` to see which one applied.
|
|
42
|
-
`}function _r(e,t){let n=[...Array(t.length+1).keys()];for(let r=1;r<=e.length;r+=1){let o=[r];for(let s=1;s<=t.length;s+=1)o[s]=Math.min(n[s]+1,o[s-1]+1,n[s-1]+(e[r-1]===t[s-1]?0:1));n=o}return n[t.length]}function Co(e,t,n){let r=/Unknown option '--([^'=]+)/.exec(n)?.[1];if(!r)return n;let o=t.findIndex((a)=>a.startsWith("-")),s=o===-1?t:t.slice(0,o),i=new Set(["json","help","version","cwd","workspace","base-url",...Wt(e,s)?.command.options??[]]),c=null;for(let a of i){let l=_r(r,a);if(l<=2&&(!c||l<c.distance))c={name:a,distance:l}}return c?`${n}
|
|
43
|
-
Did you mean --${c.name}?`:n}function Tr(e,t){let n=new Set;for(let o of e)n.add(o.name),n.add(o.name.split(" ")[0]);let r=null;for(let o of n){let s=_r(t,o);if(s<=2&&(!r||s<r.distance))r={name:o,distance:s}}return r?r.name:null}function Wt(e,t){for(let n of[...e].sort((r,o)=>o.name.length-r.name.length)){let r=n.name.split(" ");if(r.every((o,s)=>t[s]===o))return{command:n,rest:t.slice(r.length)}}return null}async function Gc(e,t,n){if(t.some((v)=>v==="--api-key"||v.startsWith("--api-key=")))return n.stderr("error: API keys are never accepted as command-line arguments. Run `hlix auth login` and use the hidden prompt.\n"),2;let r;try{r=$o({args:t,allowPositionals:!0,strict:!0,options:{json:{type:"boolean"},help:{type:"boolean"},version:{type:"boolean"},cwd:{type:"string"},"base-url":{type:"string"},workspace:{type:"string"},"dry-run":{type:"boolean"},print:{type:"boolean"},web:{type:"boolean"},"env-file":{type:"string"},history:{type:"string"},name:{type:"string"},stack:{type:"string"},status:{type:"string"},project:{type:"string"},yes:{type:"boolean"},global:{type:"boolean"},org:{type:"boolean"},title:{type:"string"},description:{type:"string"},force:{type:"boolean"},runtime:{type:"string"},duty:{type:"string"},profile:{type:"string"},server:{type:"string"},"allow-stdio":{type:"boolean"},source:{type:"string"},format:{type:"string"},out:{type:"string"},"from-stdin":{type:"boolean"}}})}catch(v){let _=t.includes("--json"),H=Co(e,t,qt(v));if(_)n.stdout(k(xe("cli",{code:"invalid_usage",message:H,status:null})));else n.stderr(`${H}
|
|
44
|
-
`);return 2}let o=r.values.json===!0,s=r.positionals;if(r.values.version===!0){let{version:v}=await import("./package-3m9rgs58.js");return n.stdout(`${v}
|
|
45
|
-
`),0}if(s.length===0||r.values.help===!0){let v=Wt(e,s);return n.stdout(v?`${v.command.usage}
|
|
46
|
-
`:Rr(e)),s.length===0&&r.values.help!==!0?1:0}let i=Wt(e,s);if(!i){let v=s.join(" "),_=Tr(e,v)??Tr(e,s[0]),H=_?`Unknown command: ${v}
|
|
47
|
-
Did you mean \`hlix ${_}\`?`:`Unknown command: ${v}`;if(o)n.stdout(k(xe(v,{code:"unknown_command",message:H,status:null})));else n.stderr(`${H}
|
|
48
|
-
|
|
49
|
-
${Rr(e)}`);return 2}let c=new Set(["json","help","version","cwd","workspace","base-url"]),a=new Set(i.command.options??[]),l=Object.entries(r.values).filter(([v,_])=>_!==void 0&&!c.has(v)&&!a.has(v)).map(([v])=>`--${v}`),u=i.command.args??{min:0,max:0},d=i.rest.length<u.min?{code:"missing_argument",message:i.command.usage.split(`
|
|
50
|
-
`)[0]}:i.rest.length>u.max?{code:"invalid_usage",message:i.command.usage.split(`
|
|
51
|
-
`)[0]}:null,m=typeof r.values.cwd==="string"?r.values.cwd:void 0,S=Eo(m??"."),g=m!==void 0&&!jr(S)?{code:"invalid_usage",message:`--cwd is not a directory: ${S}`}:null,p=l.length>0?{code:"invalid_usage",message:`Unsupported option for ${i.command.name}: ${l.join(", ")}`}:g??d;if(p){if(o)n.stdout(k(xe(i.command.name,{...p,status:null})));else{let v=i.command.usage.startsWith(p.message)?i.command.usage:`${p.message}
|
|
52
|
-
|
|
53
|
-
${i.command.usage}`;n.stderr(`error: ${v}
|
|
54
|
-
`)}return 2}let f=r.values,I={...n,args:i.rest,json:o,flags:f,cwd:S,requireClient:(v)=>Po(n.env,{cwd:v??S,flags:f})};try{return await i.command.run(I)}catch(v){let{code:_,status:H}=Vt(v);if(o)n.stdout(k(xe(i.command.name,{code:_,message:qt(v),status:H})));else n.stderr(`error: ${qt(v)}
|
|
55
|
-
`);return _==="unauthenticated"||_==="forbidden"?3:1}}import{readFileSync as xo}from"node:fs";import{homedir as Io}from"node:os";import{join as Ro}from"node:path";var Ar=20000;function To(e){if(e===void 0)return;let t=typeof e==="number"?e:Number(e.trim());return Number.isInteger(t)&&t>=Ar?t:void 0}var Or=["cloud","docker","local"],ve=["claude-code","codex","cursor-agent","hlix"],nl="hlix",Fr={dockerImage:"docker sandbox only",harness:"local and docker sandboxes only",memoryTokens:"all sandboxes",model:"local and docker sandboxes only",sandbox:"all sandboxes",yolo:"all sandboxes"},ke=["dockerImage","harness","memoryTokens","model","sandbox","yolo"],Yt=["projectId","workspaceId","apiUrl"];function Xt(e=process.env){return Ro(e.HLIX_CONFIG_HOME??Io(),".hlix","config.json")}function Nr(e=process.env){try{let t=JSON.parse(xo(Xt(e),"utf8"));return t.schemaVersion===1?t:null}catch{return null}}function Zt(e,t=process.env){let n=Nr(t),r=N(e),o=r?.root??null,s=r?.config??null,i={},c={},a=(l)=>{let u=s?.[l],d=n?.[l];if(u!==void 0)i[l]=u,c[l]="project";else if(d!==void 0)i[l]=d,c[l]="global"};for(let l of ke)a(l);for(let l of Yt){let u=s?.[l];if(u!==void 0)i[l]=u,c[l]="project"}return{merged:i,sources:c,global:n,project:s,paths:{global:Xt(t),project:o?_e(o):null}}}function Lr(e){return[...ke,...Yt].map((n)=>({key:n,value:e.merged[n]??null,source:e.sources[n]??"default"}))}function _o(e,t){if(e==="sandbox"&&!Or.includes(t))return`sandbox must be one of ${Or.join(", ")}; got "${t}".`;if(e==="harness"&&!ve.includes(t))return`harness must be one of ${ve.join(", ")}; got "${t}".`;if(e==="model"&&t.trim()==="")return"model must not be empty.";if(e==="memoryTokens"&&To(t)===void 0)return`memoryTokens must be a whole number of tokens, at least ${Ar}; got "${t}".`;if(e==="dockerImage"&&t.trim()==="")return"dockerImage must not be empty.";if(e==="yolo"&&Oo(t)===void 0)return`yolo must be true or false; got "${t}".`;return null}function Oo(e){if(e===void 0)return;let t=e.trim().toLowerCase();if(["true","1","yes","on"].includes(t))return!0;if(["false","0","no","off"].includes(t))return!1;return}function Qt(e){if(ke.includes(e))return e;let t=Yt.includes(e);throw new y("invalid_usage",t?`${e} is written by \`hlix init\` and \`hlix import\`, not by \`hlix config set\`.`:`Unknown setting: ${e}. Known settings: ${ke.join(", ")}.`)}function Hr(e,t){let n=_o(e,t);if(n)throw new y("invalid_usage",n);return t}function Mr(e){if(e.scope==="global"){let r=Xt(e.env),o=Nr(e.env)??{schemaVersion:1};return Te(r,{...o,[e.key]:e.value}),r}let t=N(e.cwd);if(!t)throw new y("not_initialized","This folder is not bound to hlix. Run `hlix init` here, or set it machine-wide with --global.");let n=_e(t.root);return Te(n,{...t.config,[e.key]:e.value}),n}import{createHash as Ao}from"node:crypto";import{mkdirSync as Fo,readdirSync as Kr,readFileSync as No,rmSync as Lo,statSync as Jr,writeFileSync as Ho}from"node:fs";import{homedir as Mo,tmpdir as Uo}from"node:os";import{basename as Gr,isAbsolute as zo,join as x,relative as Bo}from"node:path";var gt=(e=process.env)=>e.HOME??e.USERPROFILE??Mo();function z(e){try{if(!Jr(e).isFile())return null;return No(e,"utf8")}catch{return null}}function Do(e){try{return Jr(e).isDirectory()}catch{return!1}}function Ge(e,t){try{return Kr(e,{withFileTypes:!0}).filter((n)=>n.isFile()&&n.name.endsWith(t)).map((n)=>x(e,n.name)).sort()}catch{return[]}}function Ko(e){try{return Kr(e,{withFileTypes:!0}).filter((t)=>t.isDirectory()||t.isSymbolicLink()).map((t)=>x(e,t.name)).sort()}catch{return[]}}function tn(e){let t=e.replace(/^\uFEFF/,""),n=t.indexOf(`
|
|
56
|
-
`);if(!t.startsWith("---")||n===-1)return{fields:{},body:t.trim()};let r=t.indexOf(`
|
|
57
|
-
---`,n);if(r===-1)return{fields:{},body:t.trim()};let o={};for(let i of t.slice(n+1,r).split(`
|
|
58
|
-
`)){let c=/^([A-Za-z_][\w-]*)\s*:\s*(.*)$/.exec(i);if(!c)continue;o[c[1]]=c[2].trim().replace(/^["']|["']$/g,"")}let s=t.indexOf(`
|
|
59
|
-
`,r+1);return{fields:o,body:s===-1?"":t.slice(s+1).trim()}}function Jo(e){let t=e.trimStart(),n=/^"((?:[^"\\]|\\.)*)"/.exec(t)??/^'([^']*)'/.exec(t);if(n)return n[1].replace(/\\"/g,'"').replace(/\\n/g,`
|
|
60
|
-
`);if(t.startsWith("["))return[...t.matchAll(/"((?:[^"\\]|\\.)*)"|'([^']*)'/g)].map((o)=>o[1]??o[2]??"");if(t.startsWith("{")){let o={};for(let s of t.matchAll(/([A-Za-z0-9_.-]+)\s*=\s*"((?:[^"\\]|\\.)*)"/g))o[s[1]]=s[2].replace(/\\"/g,'"');return o}let r=/^[^\s#]+/.exec(t)?.[0];if(r===void 0)return;if(r==="true"||r==="false")return r==="true";if(/^-?\d+(\.\d+)?$/.test(r))return Number(r);return r}function qr(e){let t={"":{}},n="",r=e.split(`
|
|
61
|
-
`);for(let o=0;o<r.length;o+=1){let i=r[o].trim();if(!i||i.startsWith("#"))continue;let c=/^\[\[?([^\]]+)\]\]?$/.exec(i);if(c){n=c[1].trim(),t[n]??={};continue}let a=/^([A-Za-z0-9_.-]+|"[^"]+")\s*=\s*(.*)$/.exec(i);if(!a)continue;let l=a[1].replace(/^"|"$/g,""),u=a[2];if(u.startsWith('"""')){let m=[],S=u.slice(3);if(S.includes('"""'))m.push(S.slice(0,S.indexOf('"""')));else{if(S)m.push(S);while(o+1<r.length){o+=1;let g=r[o],p=g.indexOf('"""');if(p===-1){m.push(g);continue}m.push(g.slice(0,p));break}}t[n][l]=m.join(`
|
|
62
|
-
`).replace(/^\n/,"");continue}let d=Jo(u);if(d!==void 0)t[n][l]=d}return t}function en(e,t){return e.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)(?::-([^}]*))?\}/g,(n,r,o)=>{let s=t[r];return s!==void 0&&s!==""?s:o??""})}var Ur=(e,t)=>{let n={};for(let[r,o]of Object.entries(e))if(typeof o==="string")n[r]=en(o,t);return n},Go=[{relative:"GEMINI.md",source:"gemini"},{relative:x(".gemini","GEMINI.md"),source:"gemini"},{relative:".cursorrules",source:"cursor"},{relative:".windsurfrules",source:"windsurf"},{relative:x(".github","copilot-instructions.md"),source:"copilot"}],qo=[{relative:x(".gemini","GEMINI.md"),source:"gemini"}],Wo=[{relative:x(".cursor","rules"),source:"cursor",extension:".mdc"},{relative:x(".windsurf","rules"),source:"windsurf",extension:".md"}];function Vo(e,t){let n=x(e,".clinerules"),r=Do(n)?Ge(n,".md"):[n],o=[];for(let s of r){let i=z(s)?.trim();if(i)o.push({path:s,source:"cline",scope:t,content:i})}return o}function Yo(e,t,n){let{fields:r,body:o}=tn(t);if(r.alwaysApply==="false")return{path:e,source:"cursor",scope:n,reason:"alwaysApply: false"};if(!o)return{path:e,source:"cursor",scope:n,reason:"no rule body"};let s=r.globs?.replace(/^\[|\]$/g,"").trim();return{path:e,source:"cursor",scope:n,content:o,...s?{note:`Applies to: ${s}`}:{}}}var Xo=["AGENTS.md","CLAUDE.md"],Wr=["",".claude"],cl=["commands"];function Zo(e,t){let n=[],r=new Set;for(let o of[...Wr,t])for(let s of Xo){let i=x(e,o,s),c=z(i)?.trim();if(!c||r.has(c))continue;r.add(c),n.push({path:i,content:c})}return n}function zr(e,t){return Zo(e,t).map((n)=>n.content)}var nn=["AGENTS.md","CLAUDE.md","GEMINI.md"];function rn(e,t){for(let n of nn)for(let r of[...Wr,t]){let o=x(e,r,n),s=z(o)?.trim();if(s)return{path:o,content:s}}return null}var sn=(e=process.env)=>x(e.HLIX_CONFIG_HOME??x(gt(e),".hlix"),"AGENTS.md");function Vr(e){let t=e.env??process.env,n=sn(t),r=z(n)?.trim();return{global:r?{path:n,content:r}:null,project:rn(e.cwd,e.configDir)}}var Br=(e)=>{let t=Math.round(e.length/4);return t>=1000?`${(t/1000).toFixed(1)}k tokens`:`${t} tokens`};function ll(e,t,n=process.env){let r=[...e.global?[Qr(e.global.path,n)]:[],...e.project?[qe(e.project.path,t)]:[]];return r.length===0?"":`rules: ${r.join(" + ")}`}function Yr(e,t,n=process.env,r=[]){let o=(s,i,c)=>i?`${s.padEnd(8)} ${c(i.path)} (${Br(i.content)})`:`${s.padEnd(8)} none`;return[o("user",e.global,(s)=>Qr(s,n)),o("project",e.project,(s)=>qe(s,t)),...r.map((s)=>`${"nested".padEnd(8)} ${qe(s.path,t)} (${Br(s.content)})`),"","User rules go first, the project's after, so the project wins a conflict.",r.length===0?"A subdirectory's own rules file is added when the agent first works in it.":"A nested file was added when the agent first touched a path under it.","Edit them with `hlix rules --edit` (this project) or `hlix rules --edit --global`."].join(`
|
|
63
|
-
`)}var Qo=[{dir:".claude",source:"claude",harnessReads:!0},{dir:".agents",source:"agents",harnessReads:!0},{dir:".hlix",source:"hlix",harnessReads:!0},{dir:".codex",source:"codex",harnessReads:!1}],ei=[{relative:x(".cursor","commands"),source:"cursor"},{relative:x(".codex","prompts"),source:"codex"}],ti=[{relative:x(".cursor","mcp.json"),source:"cursor",key:"mcpServers",format:"json"},{relative:x(".windsurf","mcp.json"),source:"windsurf",key:"mcpServers",format:"json"},{relative:x(".gemini","settings.json"),source:"gemini",key:"mcpServers",format:"json"},{relative:x(".vscode","mcp.json"),source:"vscode",key:"servers",format:"json"},{relative:x(".codex","config.toml"),source:"codex",key:"mcp_servers",format:"toml"},{relative:".mcp.json",source:"claude",key:"mcpServers",format:"json"}];function Xr(e){return[...ti,{relative:x(e,"mcp.json"),source:"hlix",key:"mcpServers",format:"json"}]}var ni="found, not loaded (machine-wide; enable per project by copying into .hlix/mcp.json)",ri=(e)=>Xr(e).filter((t)=>t.source!=="vscode");function si(e,t){if(!e||typeof e!=="object"||Array.isArray(e))return{reason:"not an object"};let n=e;if(n.enabled===!1||n.disabled===!0)return{reason:"disabled"};let r=typeof n.command==="string"&&n.command!=="",o=typeof n.url==="string"&&n.url!=="";if(r&&o)return{reason:'has both "command" and "url"'};if(r){let a=Array.isArray(n.args)?n.args.filter((u)=>typeof u==="string"):void 0,l=n.env&&typeof n.env==="object"&&!Array.isArray(n.env)?Ur(n.env,t):void 0;return{config:{command:n.command,...a&&a.length>0?{args:a}:{},...l&&Object.keys(l).length>0?{env:l}:{}}}}if(!o)return{reason:'missing "command" or "url"'};let s=n.headers??n.http_headers,i=s&&typeof s==="object"&&!Array.isArray(s)?Ur(s,t):{},c=n.bearer_token_env_var;if(typeof c==="string"&&/^[A-Za-z_][A-Za-z0-9_]*$/.test(c)&&!Object.keys(i).some((a)=>a.toLowerCase()==="authorization"))i.Authorization=`Bearer ${en(`\${${c}}`,t)}`;return{config:{url:en(n.url,t),...Object.keys(i).length>0?{headers:i}:{}}}}function Dr(e,t,n,r){let o=z(e),s=[],i=[];if(o===null)return{servers:s,skipped:i};let c=[];if(t.format==="toml"){let a=qr(o);c=Object.entries(a).filter(([l])=>l.startsWith(`${t.key}.`)).map(([l,u])=>[l.slice(t.key.length+1),u])}else try{let l=JSON.parse(o)?.[t.key];if(l&&typeof l==="object"&&!Array.isArray(l))c=Object.entries(l)}catch{return i.push({path:e,source:t.source,scope:n,reason:"not valid JSON"}),{servers:s,skipped:i}}for(let[a,l]of c){let u=si(l,r);if("reason"in u){i.push({path:e,source:t.source,scope:n,reason:`${a}: ${u.reason}`});continue}s.push({path:e,source:t.source,scope:n,name:a,config:u.config})}return{servers:s,skipped:i}}function oi(e,t,n){let{fields:r,body:o}=tn(t);if(!o)return{path:e,source:"claude",scope:n,reason:"no instructions"};let s=r.tools?.replace(/^\[|\]$/g,"").split(",").map((i)=>i.trim()).filter(Boolean);return{path:e,source:"claude",scope:n,name:r.name||Gr(e,".md"),description:r.description??"",instructions:o,...s&&s.length>0&&s[0]!=="*"?{tools:s}:{},...r.model?{model:r.model}:{}}}function ii(e){let t=qr(e)[""]??{},n=typeof t.prompt==="string"?t.prompt.trim():"";if(!n)return null;return{description:typeof t.description==="string"?t.description:"",body:n}}function Zr(e,t,n={}){let r=n.configDir??".hlix",o=n.env??process.env,s={instructions:[],skills:[],commands:[],generatedCommands:[],mcpServers:[],subagents:[],skipped:[]},i=(g)=>{if("reason"in g)s.skipped.push(g);else s.instructions.push(g)};for(let g of Go){let p=x(e,g.relative),f=z(p)?.trim();if(f)s.instructions.push({path:p,source:g.source,scope:"project",content:f})}for(let g of Wo)for(let p of Ge(x(e,g.relative),g.extension)){let f=z(p);if(f===null)continue;if(g.source==="cursor"){i(Yo(p,f,"project"));continue}let{body:I}=tn(f);if(I)s.instructions.push({path:p,source:g.source,scope:"project",content:I})}for(let g of Vo(e,"project"))i(g);let c=zr(e,r),a=x(e,".codex","AGENTS.md"),l=z(a)?.trim();if(l&&c.includes(l))s.skipped.push({path:a,source:"codex",scope:"project",reason:"same content as the project's AGENTS.md"});else if(l)s.instructions.push({path:a,source:"codex",scope:"project",content:l});for(let g of qo){let p=x(t,g.relative),f=z(p)?.trim();if(f)s.instructions.push({path:p,source:g.source,scope:"global",content:f})}let u=x(t,".codex","AGENTS.md"),d=z(u)?.trim(),m=zr(t,r);if(d&&m.includes(d))s.skipped.push({path:u,source:"codex",scope:"global",reason:"same content as the machine's AGENTS.md"});else if(d)s.instructions.push({path:u,source:"codex",scope:"global",content:d});for(let[g,p]of[[e,"project"],[t,"global"]])for(let f of Qo){let I=x(g,f.dir===".hlix"?r:f.dir,"skills");if(!Ko(I).some((_)=>z(x(_,"SKILL.md"))!==null))continue;s.skills.push({path:I,source:f.source,scope:p,harnessReads:f.harnessReads})}for(let[g,p]of[[e,"project"],[t,"global"]]){for(let f of ei){let I=x(g,f.relative);if(Ge(I,".md").length===0)continue;s.commands.push({path:I,source:f.source,scope:p})}for(let f of Ge(x(g,".gemini","commands"),".toml")){let I=z(f),v=I===null?null:ii(I);if(!v){s.skipped.push({path:f,source:"gemini",scope:p,reason:"no prompt field"});continue}s.generatedCommands.push({path:f,source:"gemini",scope:p,name:Gr(f,".toml"),body:`---
|
|
64
|
-
description: ${v.description}
|
|
65
|
-
---
|
|
66
|
-
|
|
67
|
-
${v.body}
|
|
68
|
-
`})}}for(let g of Xr(r)){let p=Dr(x(e,g.relative),g,"project",o);s.skipped.push(...p.skipped);for(let f of p.servers){let I=s.mcpServers.findIndex((v)=>v.name===f.name);if(I===-1)s.mcpServers.push(f);else s.mcpServers[I]=f}}for(let g of ri(r)){let p=Dr(x(t,g.relative),g,"global",o);for(let f of p.servers)s.skipped.push({path:f.path,source:f.source,scope:"global",reason:`${f.name}: ${ni}`})}let S=[{dir:x(".claude","agents"),source:"claude"},{dir:x(r,"agents"),source:"hlix"}];for(let[g,p]of[[e,"project"],[t,"global"]])for(let f of S.flatMap((I)=>Ge(x(g,I.dir),".md"))){let I=z(f);if(I===null)continue;let v=oi(f,I,p);if("reason"in v)s.skipped.push(v);else if(s.subagents.some((_)=>_.name===v.name))s.skipped.push({path:f,source:"claude",scope:p,reason:`a project agent already claims the name ${v.name}`});else s.subagents.push(v)}return s}function dl(e,t){if(e.length===0)return null;let n=x(Uo(),"hlix-standards-commands",Ao("sha256").update(t).digest("hex").slice(0,16));try{Lo(n,{recursive:!0,force:!0}),Fo(n,{recursive:!0});for(let r of e)Ho(x(n,`${r.name}.md`),r.body,"utf8");return n}catch{return null}}var ai=60000,qe=(e,t)=>{let n=Bo(t,e);return!n||n.startsWith("..")||zo(n)?e:n},Qr=(e,t=process.env)=>{let n=t.HLIX_CONFIG_HOME;if(n&&e.startsWith(`${n}/`))return`~/.hlix/${e.slice(n.length+1)}`;let r=gt(t);return r&&e.startsWith(`${r}/`)?`~/${e.slice(r.length+1)}`:e};function pl(e,t,n=ai){if(e.length===0)return"";let r=["# Project standards from other agent tools","","These files were written for other coding agents working in this same","project. Treat them as the project's instructions and follow them."].join(`
|
|
69
|
-
`),o=[],s=r.length,i=!1;for(let a of e){let l=`# From ${qe(a.path,t)} (${a.source})`,u=a.note?`${l}
|
|
70
|
-
${a.note}`:l,d=n-s-u.length-4;if(d<=0){i=!0;break}let m=a.content.length<=d?a.content:`${a.content.slice(0,d)}
|
|
71
|
-
[truncated]`;if(m.length<a.content.length)i=!0;o.push(`${u}
|
|
72
|
-
|
|
73
|
-
${m}`),s+=u.length+m.length+4}let c=i?`
|
|
74
|
-
|
|
75
|
-
[The standards block reached its ${n}-character cap; some rules above are cut short or omitted.]`:"";return`${r}
|
|
76
|
-
|
|
77
|
-
${o.join(`
|
|
78
|
-
|
|
79
|
-
`)}${c}`}var Je=(e,t,n)=>`${e} ${e===1?t:n}`;function ul(e){let t=[];if(e.instructions.length>0)t.push(Je(e.instructions.length,"instruction file","instruction files"));if(e.skills.length>0)t.push(Je(e.skills.length,"skill directory","skill directories"));let n=e.commands.length+e.generatedCommands.length;if(n>0)t.push(Je(n,"command source","command sources"));if(e.mcpServers.length>0)t.push(Je(e.mcpServers.length,"mcp server","mcp servers"));if(e.subagents.length>0)t.push(Je(e.subagents.length,"subagent","subagents"));if(t.length===0)return"";let r=[...new Set([...e.instructions,...e.skills,...e.commands,...e.generatedCommands,...e.mcpServers,...e.subagents].map((o)=>o.source))].sort();return`standards: ${t.join(" · ")} (${r.join(", ")})`}function es(e,t){let n=[],r=(s,i)=>{if(i.length===0)return;n.push(s,...i.map((c)=>` ${c}`),"")},o=(s)=>`${s.source}${s.scope==="global"?" (global)":""} ${qe(s.path,t)}`;if(r("Instructions",e.instructions.map((s)=>`${o(s)}${s.note?` — ${s.note}`:""}`)),r("Skills",e.skills.map((s)=>`${o(s)}${s.harnessReads?" — already read by the harness":""}`)),r("Commands",[...e.commands.map(o),...e.generatedCommands.map((s)=>`${o(s)} → /${s.name}`)]),r("MCP servers",e.mcpServers.map((s)=>`${o(s)} → ${s.name} (${"command"in s.config?"stdio":"http"})`)),r("Subagents",e.subagents.map((s)=>`${o(s)} → ${s.name}`)),r("Skipped",e.skipped.map((s)=>`${o(s)} — ${s.reason}`)),n.length===0)return`No standards from other agent tools were found in this folder.
|
|
80
|
-
`;return`${n.join(`
|
|
81
|
-
`).trimEnd()}
|
|
82
|
-
`}async function ci(e,t,n){let r=t.map((c)=>c.id);if(n){if(!r.includes(n))throw new y("workspace_mismatch",t.length===0?`This key belongs to a user who is not a member of any workspace, including ${n}.`:`This key cannot act in workspace ${n}. Available: ${r.join(", ")}.`);return n}if(t.length===0)throw new y("workspace_required","This key belongs to a user who is not a member of any workspace. Create or join one first.");let o=t[0];if(o&&t.length===1)return e.stderr(`Using your only workspace: ${o.name} (${o.id})
|
|
83
|
-
`),o.id;if(e.json||!e.promptChoice)throw new y("missing_argument",`--workspace is required here: this key can act in ${t.length} workspaces. Pass one of: ${r.join(", ")}.`);let s=Math.max(...t.map((c)=>c.name.length));e.stderr(`${t.map((c,a)=>` ${a+1}) ${c.name.padEnd(s)} ${c.slug} ${c.role} ${c.id}`).join(`
|
|
84
|
-
`)}
|
|
85
|
-
`);let i=await e.promptChoice(`Workspace [1-${t.length}]: `,t.length);return r[i]}var on={name:"auth login",summary:"Verify and store a credential for this machine",usage:["Usage: hlix auth login [--workspace <id>] [--base-url <url>]",""," --base-url Defaults to https://server.hlix.ai"," --workspace Workspace (organization) id to act in. Optional: the key's"," own workspaces are listed after it is read, and the only"," one is taken automatically.","","The API key is read from a hidden prompt and never accepted as an argument.","For CI, set HLIX_API_KEY and HLIX_WORKSPACE_ID in the environment."].join(`
|
|
86
|
-
`),supportsJson:!0,options:["base-url","workspace"],async run(e){let t=typeof e.flags.workspace==="string"?e.flags.workspace:e.env.HLIX_WORKSPACE_ID,n=e.env.HLIX_API_KEY??await e.readSecret?.("Hlix API key: ")??"";if(!n)throw new y("missing_credential","No API key entered. Run from a terminal or set HLIX_API_KEY for CI.");let r=typeof e.flags["base-url"]==="string"?e.flags["base-url"]:e.env.HLIX_BASE_URL??Ht,o=new URL(r),s=o.hostname==="localhost"||o.hostname==="127.0.0.1"||o.hostname==="::1";if(o.protocol!=="https:"&&!(o.protocol==="http:"&&s))throw new y("invalid_base_url","--base-url must use HTTPS (HTTP is allowed only for localhost).");let i=new we({baseUrl:r,credential:ge(n),retry:{attempts:1}}),c=await ci(e,await i.workspaces.list(),t);await new we({baseUrl:r,credential:ge(n),organizationId:c,retry:{attempts:1}}).projects.list();let l=yr({baseUrl:r,apiKey:n,organizationId:c},e.env);if(e.json)e.stdout(k(j(on.name,{baseUrl:r,organizationId:c,credentialPath:l})));else e.stdout(`Signed in to ${r}
|
|
87
|
-
Credential stored at ${l}
|
|
88
|
-
`);return 0}},an={name:"auth status",summary:"Show which credential is in use, where it came from, and whether it works",usage:["Usage: hlix auth status [--json]","","Names the SOURCE of the credential — the stored file, HLIX_API_KEY, or the","desktop app's own session when hlix was opened from its Terminal tab — and","verifies it against the API. The credential itself is never printed, not even","a prefix: machine output gets piped into logs."].join(`
|
|
89
|
-
`),supportsJson:!0,async run(e){let t=J({env:e.env,flags:e.flags,cwd:e.cwd});if(t.conflict)throw new y("workspace_mismatch",t.conflict);if(!t.credential)throw new y("unauthenticated","No credential. Run `hlix auth login`, or set HLIX_API_KEY for CI.");try{await e.requireClient().projects.list()}catch(r){throw e.stderr(`credential from ${t.credentialSource}, workspace ${t.workspaceId??"none"}, api ${t.baseUrl}
|
|
90
|
-
`),r}let n={credentialSource:t.credentialSource,credentialPath:t.credentialSource==="file"?t.credentialPath:null,baseUrl:t.baseUrl,baseUrlSource:t.baseUrlSource,workspaceId:t.workspaceId,workspaceSource:t.workspaceSource,valid:!0};if(e.json)return e.stdout(k(j(an.name,n))),0;return e.stdout(`${A([["credential",mt(t)??"none"],["api",`${t.baseUrl} (from ${t.baseUrlSource})`],["workspace",t.workspaceId?`${t.workspaceId} (from ${t.workspaceSource})`:"none"],["status","valid"]])}
|
|
91
|
-
`),0}},Se={name:"auth logout",summary:"Remove the stored credential from this machine",usage:["Usage: hlix auth logout [--yes] [--json]","","Removes ~/.config/hlix/credentials.json after confirming. A credential","supplied through HLIX_API_KEY is not removed — unset it in the shell that","set it — and neither is the desktop app's own session; sign out in the app."].join(`
|
|
92
|
-
`),supportsJson:!0,options:["yes"],async run(e){let t=J({env:e.env,flags:e.flags,cwd:e.cwd});if(t.credentialSource==="env"||t.credentialSource==="session"){let r=t.credentialSource==="session",o=r?"session":"environment",s=r?"This session belongs to the Hlix desktop app; sign out there to end it.":"HLIX_API_KEY is set in this environment; unset it there to sign out.",i=hr(e.env);if(!i){let a={removed:!1,reason:o,path:null};if(e.json)e.stdout(k(j(Se.name,a)));else e.stdout(`${s}
|
|
93
|
-
`);return 0}if(e.flags.yes!==!0){let a={removed:!1,reason:o,path:i};if(e.json)e.stdout(k(j(Se.name,a)));else e.stdout(`${s}
|
|
94
|
-
A stored credential also exists at ${i} — repeat with --yes to remove it.
|
|
95
|
-
`);return 0}let c=Nt(e.env);if(e.json)e.stdout(k(j(Se.name,c)));else e.stdout(`Removed ${c.path}
|
|
96
|
-
${r?"The desktop app's session is still in use; sign out there to finish.":"HLIX_API_KEY is still set in this environment; unset it there to finish signing out."}
|
|
97
|
-
`);return 0}if(e.flags.yes!==!0&&t.credential){if(e.json||!e.confirm)throw new y("approval_required","Removing the stored credential needs approval. Repeat with `--yes`.");if(!await e.confirm(`Remove the stored credential at ${t.credentialPath}? Signing back in needs the API key again.`))throw new y("cancelled","Logout cancelled.")}let n=Nt(e.env);if(e.json)e.stdout(k(j(Se.name,n)));else e.stdout(n.removed?`Removed ${n.path}
|
|
98
|
-
`:`No stored credential at ${n.path}
|
|
99
|
-
`);return 0}};var ts=ke.join(" | "),cn={name:"config list",summary:"Show every setting in effect and which file supplied it",usage:["Usage: hlix config list [--cwd <dir>] [--json]","","Merges the machine-wide file with this folder's, per key, and names the","source of each value: project, global, or default (no file names it)."].join(`
|
|
100
|
-
`),supportsJson:!0,async run(e){let t=Zt(e.cwd,e.env),n=Lr(t);if(e.json)return e.stdout(k(j(cn.name,{settings:n,paths:t.paths}))),0;return e.stdout(`${X(["setting","value","source","applies to"],n.map((r)=>[r.key,r.value??"-",r.source,Fr[r.key]??"this folder's binding"]))}
|
|
101
|
-
`),e.stdout(`
|
|
102
|
-
global ${t.paths.global}
|
|
103
|
-
`),e.stdout(`project ${t.paths.project??"- (this folder is not bound to hlix)"}
|
|
104
|
-
`),0}},ln={name:"config get",summary:"Print one setting's effective value",usage:[`Usage: hlix config get <${ts}> [--cwd <dir>] [--json]`,"","Prints the value the cascade resolves for one key, or exits 1 when no","file names it."].join(`
|
|
105
|
-
`),supportsJson:!0,args:{min:1,max:1},async run(e){let t=Qt(e.args[0]),n=Zt(e.cwd,e.env),r=n.merged[t]??null,o=n.sources[t]??"default";if(e.json)return e.stdout(k(j(ln.name,{key:t,value:r,source:o}))),r===null?1:0;if(r===null)return e.stderr(`${t} is not set. Set it with \`hlix config set ${t} <value>\`.
|
|
106
|
-
`),1;return e.stdout(`${r}
|
|
107
|
-
`),0}},dn={name:"config set",summary:"Set one setting for this folder, or for the machine with --global",usage:[`Usage: hlix config set <${ts}> <value> [--global] [--cwd <dir>] [--json]`,"","Writes this folder's .hlix/config.json, or the machine-wide file with","--global. Other keys in the file are left untouched. The binding keys","(projectId, workspaceId, apiUrl) are written by init/import and are","refused here."].join(`
|
|
108
|
-
`),supportsJson:!0,options:["global"],args:{min:2,max:2},async run(e){let t=Qt(e.args[0]),n=Hr(t,e.args[1]),r=e.flags.global===!0?"global":"project",o=Mr({key:t,value:n,scope:r,cwd:e.cwd,env:e.env});if(e.json)return e.stdout(k(j(dn.name,{key:t,value:n,scope:r,path:o}))),0;return e.stdout(`${t} = ${n} (${r}: ${o})
|
|
109
|
-
`),0}};function ae(e,t){if(typeof e!=="object"||e===null)return"";let n=e[t];return n===null||n===void 0?"":String(n)}var pn={name:"projects list",summary:"List the projects in your workspace",usage:"Usage: hlix projects list [--json]",supportsJson:!0,async run(e){let t=await e.requireClient().projects.list();if(e.json)return e.stdout(k(j(pn.name,t))),0;let n=Array.isArray(t)?t:[];if(n.length===0)return e.stdout(`No projects.
|
|
110
|
-
`),0;return e.stdout(`${X(["ID","NAME","STACK"],n.map((r)=>[ae(r,"id"),ae(r,"name"),ae(r,"stack")]))}
|
|
111
|
-
`),0}},un={name:"projects get",summary:"Show one project, defaulting to the one this folder is bound to",usage:["Usage: hlix projects get [project-id] [--json]","","With no id, the project this folder is bound to is used."].join(`
|
|
112
|
-
`),supportsJson:!0,args:{min:0,max:1},async run(e){let t=e.args[0]??N(e.cwd)?.config.projectId;if(!t)throw new y("missing_argument","A project id is required, or run this inside a folder bound to a project.");let n=await e.requireClient().projects.get(t);if(e.json)return e.stdout(k(j(un.name,n))),0;let r=n.repos;return e.stdout(`${A([["id",ae(n,"id")],["name",ae(n,"name")],["stack",ae(n,"stack")],["status",ae(n,"status")],["repos",Array.isArray(r)?String(r.length):""]].filter(([,o])=>o!==""))}
|
|
113
|
-
`),0}};function mn(e,t){let n=e.args[0];if(!n)throw new y("missing_argument",`A ${t} id is required.`);return n}function ns(e,t){let n=e.flags[t];return typeof n==="string"&&n.trim()?n.trim():void 0}function G(e,t){if(typeof e!=="object"||e===null)return"";let n=e[t];return n===null||n===void 0?"":String(n)}var fn={name:"tasks list",summary:"List tasks, defaulting to the project this folder is bound to",usage:["Usage: hlix tasks list [--project <id>] [--status <status>] [--json]","","With no --project, a folder bound to a project lists that project's tasks;","anywhere else it lists the workspace's tasks."].join(`
|
|
114
|
-
`),supportsJson:!0,options:["project","status"],async run(e){let t=ns(e,"project")??N(e.cwd)?.config.projectId,n=ns(e,"status"),r=await e.requireClient().tasks.list({...t?{projectId:t}:{},...n?{status:n}:{}});if(e.json)return e.stdout(k(j(fn.name,r))),0;let o=Array.isArray(r)?r:[];if(o.length===0)return e.stdout(`No tasks.
|
|
115
|
-
`),0;return e.stdout(`${X(["ID","STATUS","TITLE"],o.map((s)=>[G(s,"id"),G(s,"status"),G(s,"title")||G(s,"description").split(`
|
|
116
|
-
`)[0]||""]))}
|
|
117
|
-
`),0}},gn={name:"tasks get",summary:"Show one task",usage:"Usage: hlix tasks get <task-id> [--json]",supportsJson:!0,args:{min:1,max:1},async run(e){let t=mn(e,"task"),n=await e.requireClient().tasks.get(t);if(e.json)return e.stdout(k(j(gn.name,n))),0;return e.stdout(`${A([["id",G(n,"id")],["status",G(n,"status")],["title",G(n,"title")],["project",G(n,"projectId")],["description",G(n,"description")]])}
|
|
118
|
-
`),0}},hn={name:"tasks review",summary:"Show the verified review evidence for a task",usage:"Usage: hlix tasks review <task-id> [--json]",supportsJson:!0,args:{min:1,max:1},async run(e){let t=mn(e,"task"),n=await e.requireClient().tasks.review(t);if(e.json)return e.stdout(k(j(hn.name,n))),0;return e.stdout(`${JSON.stringify(n,null,2)}
|
|
119
|
-
`),0}},yn={name:"tasks watch",summary:"Stream a task's status changes until it finishes",usage:["Usage: hlix tasks watch <task-id> [--json]","","Streams the task's server-sent status frames and exits when the task","reaches a terminal status or the server closes the stream.","","With --json, each frame is printed as one envelope per line (JSONL) so a","consumer can read them as they arrive."].join(`
|
|
120
|
-
`),supportsJson:!0,args:{min:1,max:1},async run(e){let t=mn(e,"task"),n=e.requireClient();for await(let r of n.tasks.stream(t)){let o;try{o=JSON.parse(r.data)}catch{o=r.data}if(e.json)e.stdout(`${JSON.stringify(j(yn.name,o))}
|
|
121
|
-
`);else{let s=G(o,"status"),i=G(o,"error");e.stdout(i?`error: ${i}
|
|
122
|
-
`:`${s||r.data}
|
|
123
|
-
`)}}return 0}};import{realpath as Di}from"node:fs/promises";import{resolve as Ki}from"node:path";import{createHash as gs}from"node:crypto";import{createReadStream as fi}from"node:fs";import{lstat as hs,readFile as yt,readdir as gi,readlink as hi,realpath as ys,stat as yi}from"node:fs/promises";import{basename as le,join as ws,relative as cs,resolve as ls,sep as wi}from"node:path";import{spawnSync as vi}from"node:child_process";import ds from"ignore";import{readFile as di}from"node:fs/promises";import{join as pi}from"node:path";function li(e){let t=e.trim();if(!t||/^[|>[{]/.test(t))return null;let n=t.match(/^(["'])([\s\S]*)\1$/);if(!n&&/^["']/.test(t))return null;return(n?n[2].trim():t.replace(/(?:^|\s)#.*$/,"").trim())||null}function rs(e){let t=e.split(/\r?\n/),n=t.findIndex((i)=>/^tasks:\s*(?:#.*)?$/.test(i));if(n===-1)return{tasks:[],partial:/^tasks:\s*\S/m.test(e)};let r=[],o=!1,s=-1;for(let i of t.slice(n+1)){if(!i.trim()||/^\s*#/.test(i))continue;let c=i.length-i.trimStart().length,a=i.match(/^(\s*-(?:\s+|$))(.*)$/);if(a){if(s!==-1&&c>=s)continue;if(r.push({}),s=a[2]?a[1].length:-1,!a[2])continue}else if(c===0)break;else if(r.length===0)continue;else if(s===-1)s=c;else if(c!==s)continue;let l=(a?a[2]:i.trim()).match(/^([A-Za-z_][A-Za-z0-9_-]*):\s*(.*)$/);if(!l)continue;let u=l[1];if(u!=="name"&&u!=="before"&&u!=="init"&&u!=="command")continue;let d=li(l[2]);if(d===null)o=!0;else r[r.length-1][u]=d}return{tasks:r,partial:o}}async function ce(e,t){try{return await di(pi(e,...t.split("/")),"utf8")}catch(n){if(n.code==="ENOENT")return null;throw n}}function ss(e){try{let t=e.replace(/(^|[^:\\])\/\/.*$/gm,"$1").replace(/\/\*[\s\S]*?\*\//g,"").replace(/,\s*([}\]])/g,"$1");return JSON.parse(t)}catch{return null}}function se(e){if(typeof e==="string"&&e.trim())return[e.trim()];if(Array.isArray(e))return e.flatMap(se);if(e&&typeof e==="object")return Object.values(e).flatMap(se);return[]}function wn(e){if(!e||typeof e!=="object")return[];return Object.keys(e).filter((t)=>/^[A-Za-z_][A-Za-z0-9_]*$/.test(t))}function ui(e,t){let n=new Set,r=[/\bprocess\.env\.([A-Za-z_][A-Za-z0-9_]*)/g,/\bimport\.meta\.env\.([A-Za-z_][A-Za-z0-9_]*)/g,/\bos\.(?:getenv|environ\.get)\(\s*["']([A-Za-z_][A-Za-z0-9_]*)/g,/\bos\.Getenv\(\s*["']([A-Za-z_][A-Za-z0-9_]*)/g,/\bENV\[\s*["']([A-Za-z_][A-Za-z0-9_]*)/g];if(t)r.push(/\$\{([A-Za-z_][A-Za-z0-9_]*)(?::[-?][^}]*)?\}/g);for(let o of r)for(let s of e.matchAll(o))n.add(s[1]);return[...n]}function mi(e,t){if(e.has("bun.lock")||e.has("bun.lockb")||t?.startsWith("bun@"))return"bun install --frozen-lockfile";if(e.has("pnpm-lock.yaml")||t?.startsWith("pnpm@"))return"pnpm install --frozen-lockfile";if(e.has("yarn.lock")||t?.startsWith("yarn@"))return"yarn install --immutable";if(e.has("package-lock.json")||e.has("npm-shrinkwrap.json"))return"npm ci";if(e.has("package.json"))return"npm install";return null}function os(e){let t=typeof e==="number"?e:Number(e);return Number.isInteger(t)&&t>0&&t<=65535?t:null}function K(e,t,n){if(!e.some((r)=>r.path===t&&r.kind===n))e.push({path:t,kind:n})}async function is(e,t,n){let r=[],o=[],s=[],i=[],c=new Map,a=new Set,l=new Set,u=[],d={},m=null,S=0,g=await ce(e,".cursor/environment.json");if(g){K(r,".cursor/environment.json","cursor");let w=ss(g);if(!w)u.push("Could not parse .cursor/environment.json; it remains quarantined.");else{o.push(...se(w.install));let R=se(w.start);if(R[0])m=R[0];if(Array.isArray(w.terminals))for(let P of w.terminals){if(!P||typeof P!=="object")continue;let T=P;if(typeof T.command!=="string"||!T.command.trim())continue;i.push({name:typeof T.name==="string"&&T.name.trim()?T.name.trim():"Terminal",command:T.command.trim(),...typeof T.cwd==="string"&&T.cwd.trim()?{cwd:T.cwd.trim()}:{}})}}}let p=t.has(".devcontainer/devcontainer.json")?".devcontainer/devcontainer.json":t.has("devcontainer.json")?"devcontainer.json":null;if(p){K(r,p,"devcontainer");let w=ss(n.get(p)??await ce(e,p)??"");if(!w)u.push(`Could not parse ${p}; it remains quarantined.`);else{o.push(...se(w.onCreateCommand),...se(w.updateContentCommand),...se(w.postCreateCommand));let R=se(w.postStartCommand);if(!m&&R[0])m=R[0];for(let P of wn(w.secrets))a.add(P);for(let P of[...wn(w.containerEnv),...wn(w.remoteEnv)])a.add(P);if(Array.isArray(w.forwardPorts))for(let P of w.forwardPorts){let T=os(P);if(T)c.set(T,{port:T,visibility:"private"})}}}if(t.has(".gitpod.yml")){K(r,".gitpod.yml","gitpod");let w=n.get(".gitpod.yml")??await ce(e,".gitpod.yml");if(w===null)u.push("Could not read .gitpod.yml; its task commands were not imported.");else{let R=rs(w);S=R.tasks.filter((P)=>P.before).length;for(let P of R.tasks){if(P.before)o.push(P.before);if(P.init)o.push(P.init);if(!P.command)continue;if(!m)m=P.command;else i.push({name:P.name??"Terminal",command:P.command})}if(R.partial)u.push("Some .gitpod.yml task values are not plain `key: value` scalars and were not imported; review .gitpod.yml before approving cloud setup.")}}for(let w of["Dockerfile","docker-compose.yml","docker-compose.yaml","compose.yml","compose.yaml"])if(t.has(w))K(r,w,"docker");for(let w of["project.toml","nixpacks.toml","railpack.json","Aptfile"])if(t.has(w))K(r,w,"buildpack");for(let w of["fly.toml","railway.json","render.yaml","vercel.json","netlify.toml"])if(t.has(w))K(r,w,"platform");let f=n.get("package.json")??await ce(e,"package.json");if(f){K(r,"package.json","package");try{let w=JSON.parse(f);if(w.engines?.node)d.node=w.engines.node;let R=mi(t,w.packageManager);if(R&&o.length===S)o.push(R);if(w.scripts?.build&&s.length===0)s.push(`${w.packageManager?.split("@")[0]??(t.has("bun.lock")?"bun":"npm")} run build`);let P=w.scripts?.dev?`${t.has("bun.lock")?"bun":"npm"} run dev`:null,T=w.scripts?.start?`${t.has("bun.lock")?"bun":"npm"} run start`:P;if(!m&&T)m=T}catch{u.push("Could not parse package.json for environment discovery.")}}if(t.has("uv.lock"))o.push("uv sync --frozen");else if(t.has("poetry.lock"))o.push("poetry install --no-interaction");else if(t.has("requirements.txt"))o.push("python -m pip install -r requirements.txt");if(t.has("go.mod"))o.push("go mod download");if(t.has("Procfile")){K(r,"Procfile","procfile");let R=(n.get("Procfile")??"").split(/\r?\n/).find((P)=>/^web\s*:/.test(P));if(R)m=R.replace(/^web\s*:\s*/,"").trim()||m}let I=[[".node-version","node"],[".nvmrc","node"],[".python-version","python"]];for(let[w,R]of I){let P=(n.get(w)??await ce(e,w))?.trim();if(P)d[R]=P,K(r,w,"tool-version")}let v=n.get(".tool-versions")??await ce(e,".tool-versions");if(v){K(r,".tool-versions","tool-version");for(let w of v.split(/\r?\n/)){let[R,P]=w.trim().split(/\s+/,2);if(!P)continue;if(R==="nodejs")d.node=P;else if(R==="python")d.python=P;else if(R==="bun")d.bun=P}}let _=n.get("mise.toml")??await ce(e,"mise.toml");if(_){K(r,"mise.toml","tool-version");for(let w of _.matchAll(/^\s*(node|python|bun)\s*=\s*["']([^"']+)["']/gm))d[w[1]]=w[2]}for(let[w,R]of n){let P=/(?:^|\/)(?:Dockerfile|Procfile)$/i.test(w)||/\.(?:jsonc?|ya?ml|toml|ini|conf|config|env|sh|bash|zsh|fish)$/i.test(w);for(let T of ui(R,P))l.add(T);for(let T of R.matchAll(/(?:--port(?:=|\s+)|PORT\s*=\s*)(\d{2,5})/g)){let te=os(T[1]);if(te)c.set(te,{port:te,visibility:"private"})}}if(r.length===0&&t.size>0)K(r,"repository","detected");let H=(w)=>[...new Set(w.filter(Boolean))],Ee=r.length+o.length+(m?1:0);return{sources:r.sort((w,R)=>w.path.localeCompare(R.path)),toolchain:d,install:H(o),build:H(s),start:m,terminals:i,ports:[...c.values()].sort((w,R)=>w.port-R.port),requiredSecretKeys:[...a].sort(),observedSecretKeys:[...l].sort(),confidence:Ee>=4?"high":Ee>=2?"medium":"low",warnings:u}}var as=2;var ki=300000,Si=25000,bi=52428800,ji=524288000,wt=1e4,ht=1048576,We=20971520,ps=[".git/",".hlix/","node_modules/",".next/",".turbo/",".cache/","dist/","build/","coverage/","__pycache__/",".venv/","venv/","target/",".DS_Store"],jn="Required project environment value was not found locally: ",Ei=/(^|\/)\.env\.(example|sample|template)$/i,$i=/(^|\/)\.env(?:\.[^/]+)?$/i,Pi=/(^|\/)(?:\.envrc|\.netrc|\.npmrc|\.pypirc|credentials(?:\.[^/]+)?(?:\.json|\.toml)?|service-account[^/]*\.json|firebase-adminsdk[^/]*\.json|application_default_credentials\.json|\.docker\/config\.json|\.cargo\/credentials(?:\.toml)?|\.gem\/credentials|\.bundle\/config|(?:pip|pypi)\.conf|\.aws\/credentials|[^/]+\.(?:pem|key|p12|pfx)|[^/]*\.(?:auto\.)?tfvars(?:\.json)?|application[^/]*\.(?:properties|ya?ml)|(?:local|keystore|gradle|secrets?)\.properties|appsettings[^/]*\.json|local\.settings\.json|config\/database\.ya?ml|wrangler\.toml|fly\.toml|serverless\.ya?ml|(?:credentials|secrets?)[^/]*\.(?:json|ya?ml|toml|ini|conf|cfg))$/i,Ci=/(^|\/)(?:\.mcp\.json|mcp\.json|claude_desktop_config\.json)$/i,xi=/(^|\/)(?:AGENTS\.md|CLAUDE\.md|\.cursorrules|\.github\/copilot-instructions\.md)$/i,Ii=/(^|\/)(?:\.agents|\.claude)\/skills\//i,Ri=/-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----|npm_[A-Za-z0-9]{30,}|gh[opusr]_[A-Za-z0-9_]{30,}|glpat-[A-Za-z0-9_-]{20,}|AKIA[0-9A-Z]{16}|AIza[0-9A-Za-z_-]{30,}|(?:sk|rk)_(?:live|test)_[A-Za-z0-9]{16,}|xox[baprs]-[A-Za-z0-9-]{20,}/,Ti=/\.(?:json|ya?ml|toml|ini|conf|config)$/i,_i=/(?:^|[,{\s])(?:["']?(?:api[_-]?key|access[_-]?token|auth(?:orization)?|client[_-]?secret|password|private[_-]?key|secret|token)["']?)\s*(?::|=)\s*["']?(?!\$\{|process\.env|import\.meta\.env|os\.(?:getenv|environ\.get)|<|replace|example|changeme)[A-Za-z0-9+/_=.:-]{12,}/im,Ve=/^HLIX_[A-Za-z0-9_]*$/,vn=new Set(["CI","HOME","LANG","LOGNAME","NODE_ENV","OLDPWD","PATH","PORT","PWD","SHELL","SHLVL","TERM","TMPDIR","USER","_"]);function Ye(e){return e.split(wi).join("/")}function q(e){if(e>=1048576)return`${(e/1048576).toFixed(1)} MB`;if(e>=1024)return`${(e/1024).toFixed(1)} KB`;return`${e} bytes`}function kn(e,t=5){return[...e].sort((n,r)=>r.size-n.size||n.path.localeCompare(r.path)).slice(0,t).map((n)=>`${n.path} (${q(n.size)})`).join(", ")}function Sn(e,t=5){let n=new Map;for(let r of e){let o=r.indexOf("/"),s=o===-1?".":r.slice(0,o);n.set(s,(n.get(s)??0)+1)}return[...n].sort((r,o)=>o[1]-r[1]||r[0].localeCompare(o[0])).slice(0,t).map(([r,o])=>`${r}/ (${o} files)`).join(", ")}function oe(e,t,n=10485760){return vi("git",["-C",e,...t],{encoding:"utf8",timeout:ki,maxBuffer:n,stdio:["ignore","pipe","pipe"]})}async function Oi(e){let t=gs("sha256");for await(let n of fi(e))t.update(n);return t.digest("hex")}function bn(e){if(Array.isArray(e))return`[${e.map(bn).join(",")}]`;if(e&&typeof e==="object")return`{${Object.entries(e).sort(([t],[n])=>t.localeCompare(n)).map(([t,n])=>`${JSON.stringify(t)}:${bn(n)}`).join(",")}}`;return JSON.stringify(e)}function vs(e){let t={};for(let[n,r]of String(e).replace(/^\uFEFF/,"").split(/\r?\n/).entries()){let o=r.trim();if(!o||o.startsWith("#"))continue;let i=(o.startsWith("export ")?o.slice(7).trimStart():o).match(/^([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/);if(!i)throw Error(`Invalid dotenv assignment on line ${n+1}`);let c=i[2]??"";if(c.startsWith('"')){if(!c.endsWith('"'))throw Error(`Unclosed dotenv quote on line ${n+1}`);c=c.slice(1,-1).replace(/\\n/g,`
|
|
124
|
-
`).replace(/\\r/g,"\r")}else if(c.startsWith("'")){if(!c.endsWith("'"))throw Error(`Unclosed dotenv quote on line ${n+1}`);c=c.slice(1,-1)}else c=c.replace(/\s+#.*$/,"").trimEnd();t[i[1]]=c}return t}function Ai(e){let t=null;for(let n=0;n<e.length;n+=1){let r=e[n];if(r==="\\"&&t!=="single"){if(e[n+1]!=="$")return!0;n+=1;continue}if(r==="'"&&t!=="double"){t=t==="single"?null:"single";continue}if(r==='"'&&t!=="single"){t=t==="double"?null:"double";continue}if(t!=="single"&&(r==="$"||r==="`"))return!0;if(t===null&&(r==="<"||r===">")&&e[n+1]==="(")return!0}return t!==null}function Fi(e){let t={},n=new Set,r=new Set;for(let o of String(e).replace(/^\uFEFF/,"").split(/\r?\n/)){let s=o.trim();if(!s||s.startsWith("#"))continue;let c=(s.startsWith("export ")?s.slice(7).trimStart():s).match(/^([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/);if(!c)continue;let a=c[1],l=c[2]??"";if(n.add(a),Ai(l)){delete t[a],r.add(a);continue}try{let d=vs(`${a}=${l}`)[a];if(d===void 0)throw Error("missing literal");t[a]=l.trimStart().startsWith("'")?d:d.replace(/\\\$/g,"$"),r.delete(a)}catch{delete t[a],r.add(a)}}return{values:t,keys:[...n].sort(),dynamicKeys:[...r].sort()}}async function Ni(e){let t=oe(e,["rev-parse","--show-toplevel"]);if(t.status!==0)return!1;try{return await ys(t.stdout.trim())===e}catch{return!1}}function Li(e,t){if(!t)return new Set;let n=oe(e,["ls-files","-z"]);if(n.status!==0)throw Error("Could not enumerate tracked files.");return new Set(n.stdout.split("\x00").filter(Boolean).map(Ye))}async function Hi(e){let t=ds().add(ps),n=ds().add(ps),r=[];for(let o of[".gitignore",".hlixignore"])try{let s=ws(e,o),i=await hs(s);if(i.isFile())n.add(await yt(s,"utf8"));else if(i.isSymbolicLink())r.push(o)}catch(s){if(s.code!=="ENOENT")throw s}return{hardMatcher:t,matcher:n,symlinked:r}}function us(e){if(Ci.test(e))return"mcp";if(Ii.test(e))return"skill";if(xi.test(e))return"agent";return null}function ms(e){if($i.test(e)&&!Ei.test(e))return"dotenv";if(Pi.test(e))return"credential";return null}function Mi(e){if(e.has("package.json"))return"typescript";if(e.has("pyproject.toml")||e.has("requirements.txt"))return"python";if(e.has("go.mod"))return"go";if(e.has("Cargo.toml"))return"rust";if(e.has("composer.json"))return"php";if(e.has("Gemfile"))return"ruby";return"other"}function Ui(e,t){if(t)return[Ye(t)];let n=new Map([[".env",0],[".env.development",1],[".env.local",2],[".env.development.local",3]]),r=e.filter((o)=>n.has(le(o).toLocaleLowerCase("en-US"))).sort((o,s)=>o.slice(0,-le(o).length).localeCompare(s.slice(0,-le(s).length))||n.get(le(o).toLocaleLowerCase("en-US"))-n.get(le(s).toLocaleLowerCase("en-US")));return r.length>0?r:e.length===1?[...e]:[]}function zi(e,t){try{let n=JSON.parse(t);if(!n.mcpServers||typeof n.mcpServers!=="object")return[];return Object.entries(n.mcpServers).map(([r,o])=>{let s=o&&typeof o==="object"?o:{},i=s.type==="http"||s.type==="sse"||s.type==="stdio"?s.type:typeof s.command==="string"?"stdio":typeof s.url==="string"?"http":"unknown",c=s.env&&typeof s.env==="object"?s.env:{};return{sourcePath:e,name:r,transport:i,...typeof s.command==="string"?{command:s.command}:{},...Array.isArray(s.args)&&s.args.every((a)=>typeof a==="string")?{args:s.args}:{},...typeof s.url==="string"?{url:s.url}:{},envKeys:Object.keys(c).sort(),enabled:!1}})}catch{return[]}}function fs(e,t){let n=[],r="unknown";for(let o of e.split(/\r?\n/)){if(o.startsWith("@@"))r=o.slice(2);else if(o.trim())n.push({commit:r,path:Ye(o.trim()),reason:t});if(n.length>=100)break}return n}function Bi(e,t){if(!t)return{head:null,branch:null,refs:[],commitCount:0,complete:!0,findings:[]};let n=oe(e,["rev-parse","HEAD"]).stdout.trim()||null,r=oe(e,["symbolic-ref","--short","-q","HEAD"]),o=r.status===0?r.stdout.trim()||null:null,s=Number.parseInt(oe(e,["rev-list","--count","--all"]).stdout.trim(),10)||0,i=oe(e,["for-each-ref","--format=%(refname)%00%(objectname)","refs/heads","refs/tags"]),c=i.stdout.split(`
|
|
125
|
-
`).filter(Boolean).map((m)=>{let[S,g]=m.split("\x00");return{name:S,oid:g}}).filter(({name:m,oid:S})=>/^refs\/(?:heads|tags)\/.+/.test(m)&&/^[0-9a-f]{40,64}$/.test(S)).sort((m,S)=>m.name.localeCompare(S.name)),a=["log","--all",`--max-count=${wt}`,"--pretty=format:@@%H","--name-only"],l=oe(e,[...a,"--",".env",".env.*","*.pem","*.key",".npmrc","*.tfvars"]),u=oe(e,["log","--all",`--max-count=${wt}`,"-G","BEGIN (RSA |EC |OPENSSH )?PRIVATE KEY|npm_[A-Za-z0-9]{30,}|gh[opusr]_[A-Za-z0-9_]{30,}|AKIA[0-9A-Z]{16}|xox[baprs]-[A-Za-z0-9-]{20,}","--pretty=format:@@%H","--name-only"]),d=new Map;for(let m of[...fs(l.stdout,"sensitive-path"),...fs(u.stdout,"secret-pattern")])d.set(`${m.commit}:${m.path}:${m.reason}`,m);return{head:n,branch:o,refs:c,commitCount:s,complete:s<=wt&&c.length<=1000&&i.status===0&&l.status===0&&u.status===0,findings:[...d.values()].slice(0,100)}}async function W(e,t={}){let n=await ys(ls(e));if(!(await yi(n)).isDirectory())throw Error("Import target must be a directory.");let r=await Ni(n),o=Li(n,r),{hardMatcher:s,matcher:i,symlinked:c}=await Hi(n),a=[],l=[],u=[],d=[],m=[],S=[],g=[],p=[],f=t.envFile?Ye(cs(n,ls(n,t.envFile))):void 0,I=f!==void 0&&f!==""&&f!==".."&&!f.startsWith("../");if(t.envFile&&!I)p.push(`Selected environment file must stay inside the project: ${t.envFile}`);let v=new Map,_=new Map,H=new Map,Ee=new Map,w=[],R=[],P=[],T=new Map,te=t.maxFiles??Si,tr=t.maxFileBytes??bi,nr=t.maxTotalBytes??ji,Ct=0,ne=0,rr=()=>a.length+l.length+d.length+m.length,sr=async(h)=>{let E=await gi(h,{withFileTypes:!0});E.sort((O,M)=>O.name.localeCompare(M.name));for(let O of E){let M=ws(h,O.name),C=Ye(cs(n,M));if(O.name===".git"){if(C!==".git")p.push(`Nested Git repository is not supported: ${C}`);continue}let L=await hs(M),cr=O.isDirectory()?`${C}/`:C,_t=o.has(C),lr=!_t&&i.ignores(cr),Gs=!_t&&s.ignores(cr);if(L.isSymbolicLink()){if(lr)continue;if(rr()>=te){p.push(`Project exceeds the ${te} file limit, reached at ${C}. Largest folders: ${Sn(a.map((F)=>F.path))}. Exclude generated folders with .hlixignore.`);return}if(l.push({path:C,target:await hi(M)}),us(C)||ms(C))u.push(C);continue}if(O.isDirectory()){if(Gs)continue;await sr(M);continue}let Pe=us(C),Ce=ms(C);if(lr&&!Pe&&!Ce)continue;if(!O.isFile()){g.push({path:C,reason:"non-regular-file"});continue}if(rr()>=te){p.push(`Project exceeds the ${te} file limit, reached at ${C}. Largest folders: ${Sn(a.map((F)=>F.path))}. Exclude generated folders with .hlixignore.`);return}if(L.size>tr){p.push(`File ${C} is ${q(L.size)}, over the ${q(tr)} per-file limit. Exclude it with .hlixignore.`);continue}if(Ct+=L.size,Ct>nr){p.push(`Project files total at least ${q(Ct)}, over the ${q(nr)} limit. Largest so far: ${kn([...a,{path:C,size:L.size}])}. Exclude large files with .hlixignore.`);return}let ot=await Oi(M);if(Pe){if(L.size>ht){p.push(`Protected configuration ${C} is ${q(L.size)}, over the ${q(ht)} per-file limit. Move the large content out of it, or exclude it with .hlixignore.`);continue}let F=await yt(M);if(ne+=F.byteLength,P.push({path:C,size:F.byteLength}),ne>We)continue;if(m.push({path:C,kind:Pe,size:L.size,sha256:ot}),R.push({path:C,kind:Pe,contentBase64:F.toString("base64")}),Pe==="mcp")S.push(...zi(C,F.toString("utf8")));continue}if(Ce){if(L.size>ht){p.push(`Protected file ${C} is ${q(L.size)}, over the ${q(ht)} per-file limit. Move the large content out of it, or exclude it with .hlixignore.`);continue}let F=await yt(M);if(ne+=F.byteLength,P.push({path:C,size:F.byteLength}),ne>We)continue;let ie=[];if(Ce==="dotenv")try{let it=vs(F),pe={};for(let[re,ue]of Object.entries(it)){if(Ve.test(re)){p.push(`Hlix control-plane environment keys cannot be imported into a project: ${re}`);continue}pe[re]=ue}v.set(C,pe),ie=Object.keys(pe).sort()}catch{p.push(`Could not parse environment file: ${C}`)}else if(le(C)===".envrc"){let it=Fi(F),pe={},re=new Set,ue=[];for(let[U,qs]of Object.entries(it.values)){if(Ve.test(U)){p.push(`Hlix control-plane environment keys cannot be imported into a project: ${U}`);continue}if(vn.has(U)){w.push(`Ignored ambient runtime assignment in ${C}: ${U}`);continue}re.add(U),pe[U]=qs}_.set(C,pe);for(let U of it.dynamicKeys){if(Ve.test(U)){p.push(`Hlix control-plane environment keys cannot be imported into a project: ${U}`);continue}if(vn.has(U)){w.push(`Ignored ambient runtime assignment in ${C}: ${U}`);continue}re.add(U),ue.push(U)}if(H.set(C,[...re].sort()),Ee.set(C,ue.sort()),ie=[...re].sort(),ue.length>0)w.push(`Did not execute dynamic .envrc assignments; collect their resolved local values when available: ${ue.join(", ")}`)}d.push({path:C,kind:Ce,keys:ie,size:L.size,sha256:ot}),R.push({path:C,kind:Ce,contentBase64:F.toString("base64")});continue}if(L.size<=1048576){let F=await yt(M),ie=F.toString("utf8");if(T.set(C,ie),Ri.test(ie)||Ti.test(C)&&_i.test(ie)){if(ne+=F.byteLength,P.push({path:C,size:F.byteLength}),ne>We)continue;d.push({path:C,kind:"detected-content",keys:[],size:L.size,sha256:ot}),R.push({path:C,kind:"detected-content",contentBase64:F.toString("base64")});continue}}a.push({path:C,size:L.size,sha256:ot,tracked:_t,executable:(L.mode&73)!==0})}};if(await sr(n),u.length>0){let h=u.slice(0,5).join(", "),E=u.length-5;w.push(`Imported as symlinks, so no content was read or uploaded for them and the cloud recreates the link: ${h}${E>0?`, +${E} more`:""}`)}for(let h of c)p.push(`Ignore file ${h} is a symlink, so its rules were not applied. Replace it with a regular file inside the project.`);if(ne>We)p.push(`Protected project files total ${q(ne)}, over the ${q(We)} limit. Largest: ${kn(P)}. Move large assets out of skill and config folders, or add them to .hlixignore.`);if(d.length>2000)p.push(`Project has ${d.length} environment and credential files, over the 2000 limit. Largest: ${kn(d)}. Exclude the ones the cloud project does not need with .hlixignore.`);if(m.length>5000)p.push(`Project has ${m.length} agent, skill and MCP files, over the 5000 limit. Largest folders: ${Sn(m.map((h)=>h.path))}. Exclude the ones the cloud project does not need with .hlixignore.`);a.sort((h,E)=>h.path.localeCompare(E.path)),l.sort((h,E)=>h.path.localeCompare(E.path)),d.sort((h,E)=>h.path.localeCompare(E.path)),m.sort((h,E)=>h.path.localeCompare(E.path)),S.sort((h,E)=>`${h.sourcePath}:${h.name}`.localeCompare(`${E.sourcePath}:${E.name}`));let xt=Ui([...v.keys()].sort(),I?f:void 0);if(t.envFile&&I&&!v.has(xt[0]))p.push(`Selected environment file was not found or is not a dotenv file: ${t.envFile}`);let $e=new Map;for(let[h,E]of v)for(let O of Object.keys(E))$e.set(O,[...$e.get(O)??[],h]);for(let[h,E]of H)for(let O of E)$e.set(O,[...$e.get(O)??[],h]);let zs=[...$e].filter(([,h])=>h.length>1).map(([h,E])=>({key:h,paths:E.sort()})).sort((h,E)=>h.key.localeCompare(E.key)),V={};for(let h of xt)Object.assign(V,v.get(h)??{});let Bs=[..._.keys()].sort((h,E)=>{if(h===".envrc")return 1;if(E===".envrc")return-1;return h.localeCompare(E)}),It=new Set;for(let h of Bs){let E=new Set(Ee.get(h)??[]);for(let O of H.get(h)??[]){if(E.has(O)){delete V[O],It.add(O);continue}let M=_.get(h)?.[O];if(M!==void 0)V[O]=M;It.delete(O)}}let Rt=t.historyMode??"abort_on_findings",B=Bi(n,r);if(!B.complete&&Rt!=="preserve")p.push(`Git history scan exceeded ${wt} commits or failed; import requires explicit --history preserve.`);if(B.findings.length>0&&Rt==="abort_on_findings")p.push([`Potential secrets exist in Git history (${B.findings.length} finding${B.findings.length===1?"":"s"}${B.findings.length>10?", first 10 shown":""}):`,...B.findings.slice(0,10).map((h)=>` ${h.commit.slice(0,7)} ${h.path} — ${h.reason}`)," Sanitize the repository, or re-run with --history preserve to import it as it is."].join(`
|
|
126
|
-
`));let or=new Set(a.map((h)=>h.path)),Ds=await is(n,or,T),{observedSecretKeys:Ks,...Y}=Ds;Y.warnings.push(...w);let Tt=new Set(Y.requiredSecretKeys);for(let h of It)Tt.add(h);for(let h of S)for(let E of h.envKeys)Tt.add(E);Y.requiredSecretKeys=[...Tt].sort();for(let h of Y.requiredSecretKeys){if(Ve.test(h)){p.push(`Hlix control-plane environment keys cannot be imported into a project: ${h}`);continue}if(V[h]!==void 0)continue;let E=t.environment?.[h];if(E===void 0){p.push(`${jn}${h}`);continue}V[h]=E}for(let h of Ks){if(Ve.test(h)){Y.warnings.push(`Ignored reserved Hlix control-plane environment reference: ${h}`);continue}if(vn.has(h))continue;if(V[h]!==void 0)continue;let E=t.environment?.[h];if(E===void 0){Y.warnings.push(`Observed environment reference has no local value: ${h}`);continue}V[h]=E}Y.warnings=[...new Set(Y.warnings)].sort();let ir={schemaVersion:as,rootName:t.rootName??le(n),stack:Mi(or),git:{detected:r,head:B.head,branch:B.branch,refs:B.refs,commitCount:B.commitCount,historyScanComplete:B.complete,historyMode:Rt},files:a,symlinks:l,secretFiles:d,activeEnvFiles:xt,secretKeys:Object.keys(V).sort(),envCollisions:zs,quarantinedResources:m,mcpServers:S,historicalSecretFindings:B.findings,skipped:g,environment:Y,totals:{files:a.length,bytes:a.reduce((h,E)=>h+E.size,0)}},ar=bn(ir),Js=gs("sha256").update(ar).digest("hex");return{root:n,manifest:ir,manifestJson:ar,manifestSha256:Js,secretValues:V,protectedFiles:R.sort((h,E)=>h.path.localeCompare(E.path)),blocking:[...new Set(p)]}}var En={name:"init",summary:"Configure a local folder for Hlix",usage:["Usage: hlix init [folder] [--project <id>] [--json]","","Creates .hlix/config.json, .hlix/.gitignore, and .hlixignore.","Project configuration is safe to commit; local revision state is ignored.",""," --project <id> Bind the folder to an existing cloud project (then `hlix pull`)"].join(`
|
|
127
|
-
`),supportsJson:!0,options:["project"],args:{min:0,max:1},async run(e){if(e.args.length>1)throw Error("init accepts at most one folder.");let t=await Di(Ki(e.cwd,e.args[0]??".")),n=J({env:e.env,flags:e.flags,cwd:t});if(n.conflict)throw new y("workspace_mismatch",n.conflict);if(!n.workspaceId)throw Error("No workspace selected. Run `hlix auth login --workspace <id>` first.");let r=e.requireClient(t);await r.projects.list();let o=fe(t),s=typeof e.flags.project==="string"?e.flags.project:void 0;if(s&&o?.projectId&&o.projectId!==s)throw new y("workspace_mismatch",`This folder is bound to project ${o.projectId}; refusing to rebind it to ${s}.`);if(s)await r.projects.get(s);let i={...o??{schemaVersion:1,workspaceId:n.workspaceId,apiUrl:n.baseUrl},...s?{projectId:s}:{}};Oe(t,i);let c=await W(t,{environment:e.env}),a={root:t,config:i,scan:{files:c.manifest.totals.files,bytes:c.manifest.totals.bytes,secretFiles:c.manifest.secretFiles.map((l)=>l.path),quarantinedResources:c.manifest.quarantinedResources.map((l)=>l.path),blocking:c.blocking}};if(e.json)e.stdout(k(j(En.name,a)));else if(e.stdout(`Initialized ${t}
|
|
128
|
-
Project: ${i.projectId??"not imported yet"}
|
|
129
|
-
Workspace: ${i.workspaceId}
|
|
130
|
-
`),c.blocking.length)e.stdout(`
|
|
131
|
-
Review before import:
|
|
132
|
-
${c.blocking.map((l)=>`- ${l}`).join(`
|
|
133
|
-
`)}
|
|
134
|
-
`);return 0}};import{createHash as ea}from"node:crypto";import{readFile as ta,realpath as na}from"node:fs/promises";import{basename as ra,resolve as sa}from"node:path";import{createHash as Ji}from"node:crypto";import{createReadStream as Gi}from"node:fs";import{chmod as $n,copyFile as qi,lstat as ks,mkdir as Pn,mkdtemp as Wi,readdir as Vi,readlink as Yi,rm as Cn,symlink as Xi}from"node:fs/promises";import{tmpdir as Zi}from"node:os";import{dirname as Ss,join as Q}from"node:path";import{spawnSync as Xe}from"node:child_process";var Ze=300000;function Z(e,t){let n=Xe("git",["-C",e,...t],{encoding:"utf8",timeout:Ze,maxBuffer:20971520,stdio:["ignore","pipe","pipe"]});if(n.status!==0){let r=n.stderr.trim().split(`
|
|
135
|
-
`).at(-1)??"git command failed";throw Error(r)}return n.stdout.trim()}async function bs(e){let t=Ji("sha256");for await(let n of Gi(e))t.update(n);return t.digest("hex")}async function Qi(e){for(let t of await Vi(e)){if(t===".git")continue;await Cn(Q(e,t),{recursive:!0,force:!0})}}async function vt(e){if(e.blocking.length>0)throw Error(`Project scan has blocking findings:
|
|
136
|
-
- ${e.blocking.join(`
|
|
137
|
-
- `)}`);let t=await Wi(Q(Zi(),"hlix-snapshot-"));await $n(t,448);let n=Q(t,"repo"),r=Q(t,"source.git"),o=Q(t,"project.bundle");try{if(e.manifest.git.detected){let d=Xe("git",["clone","--mirror","--no-hardlinks",e.root,r],{encoding:"utf8",timeout:Ze,stdio:["ignore","pipe","pipe"]});if(d.status!==0)throw Error(d.stderr.trim()||"Could not mirror repository.");let m=new Map(Z(r,["for-each-ref","--format=%(refname)%00%(objectname)","refs/heads","refs/tags"]).split(`
|
|
138
|
-
`).filter(Boolean).map((g)=>g.split("\x00",2)));for(let g of e.manifest.git.refs)if(m.get(g.name)!==g.oid)throw Error(`Git ref changed after scan: ${g.name}`);let S=Xe("git",["clone","--no-hardlinks",r,n],{encoding:"utf8",timeout:Ze,stdio:["ignore","pipe","pipe"]});if(S.status!==0)throw Error(S.stderr.trim()||"Could not create snapshot clone.");if(!e.manifest.git.head)throw Error("Git repository has no HEAD commit.");Z(n,["checkout","-B","main",e.manifest.git.head])}else await Pn(n,{recursive:!0,mode:448}),Z(n,["init","-b","main"]);await Qi(n);for(let d of e.manifest.files){let m=Q(e.root,...d.path.split("/")),S=await ks(m);if(!S.isFile()||S.isSymbolicLink())throw Error(`Source changed after scan: ${d.path}`);if(S.size!==d.size||await bs(m)!==d.sha256)throw Error(`Source changed after scan: ${d.path}`);let g=Q(n,...d.path.split("/"));await Pn(Ss(g),{recursive:!0,mode:493}),await qi(m,g),await $n(g,d.executable?493:420)}for(let d of e.manifest.symlinks){let m=Q(e.root,...d.path.split("/"));if(await Yi(m).catch(()=>null)!==d.target)throw Error(`Source changed after scan: ${d.path}`);let S=Q(n,...d.path.split("/"));await Pn(Ss(S),{recursive:!0,mode:493}),await Xi(d.target,S)}Z(n,["config","user.name","Hlix Import"]),Z(n,["config","user.email","import@hlix.ai"]),Z(n,["add","-A"]),Z(n,["commit","--allow-empty","-m","chore(hlix): import snapshot"]);let s=Z(n,["rev-parse","HEAD"]),i=e.manifest.git.refs.filter((d)=>d.name!=="refs/heads/main");if(i.length>0){let d=Xe("git",["-C",n,"update-ref","--stdin"],{encoding:"utf8",timeout:Ze,input:i.map((m)=>`update ${m.name} ${m.oid}`).join(`
|
|
139
|
-
`)+`
|
|
140
|
-
`,stdio:["pipe","pipe","pipe"]});if(d.status!==0)throw Error(d.stderr.trim()||"Could not recreate the approved Git refs.")}let c=i.map((d)=>d.name),a=Xe("git",["-C",n,"bundle","create",o,"--stdin"],{encoding:"utf8",timeout:Ze,input:["refs/heads/main",...c].join(`
|
|
141
|
-
`)+`
|
|
142
|
-
`,stdio:["pipe","pipe","pipe"]});if(a.status!==0)throw Error(a.stderr.trim()||"Could not create the approved Git bundle.");Z(n,["bundle","verify",o]),await $n(o,384);let l=(await ks(o)).size,u=await bs(o);return{bundlePath:o,bundleSha256:u,bundleSize:l,commitSha:s,dispose:()=>Cn(t,{recursive:!0,force:!0})}}catch(s){throw await Cn(t,{recursive:!0,force:!0}),s}}function Qe(e,t){let n=e[t];return typeof n==="string"&&n.trim()?n.trim():void 0}function oa(e,t){return ea("sha256").update(`project-import-v1\x00${e}\x00${t}`).digest("hex")}function ia(e){let t=e.manifest.environment.install,n=e.manifest.secretFiles.length+e.manifest.quarantinedResources.length;if(t.length===0&&n===0&&e.manifest.secretKeys.length===0)return null;let r=["Hlix will upload this project and encrypted protected files to your selected workspace."];if(t.length>0)r.push("Detected cloud setup commands:",...t.map((o)=>`- ${o}`));if(e.manifest.secretKeys.length>0)r.push("Project secret keys available to cloud tasks:",...e.manifest.secretKeys.map((o)=>`- ${o}`));if(e.manifest.quarantinedResources.length>0)r.push("Quarantined resources (preserved but not activated):",...e.manifest.quarantinedResources.map((o)=>`- ${o.kind}: ${o.path}`));if(e.manifest.environment.warnings.length>0)r.push("Environment warnings:",...e.manifest.environment.warnings.map((o)=>`- ${o}`));return r.push("Setup runs inside the isolated Coding Workspace and may access project secrets."),r.join(`
|
|
143
|
-
`)}var kt={name:"import",summary:"Import a local project into your Hlix workspace",usage:["Usage: hlix import [folder] [options]","","Options:"," --dry-run Scan and report without uploading"," --env-file <path> Override automatic development dotenv precedence"," --history <mode> abort-on-findings (default) or preserve"," --name <name> Cloud project name (defaults to folder name)"," --stack <stack> Override detected stack"," --yes Approve the reviewed upload and cloud setup"," --json Machine-readable output (never contains secret values)"].join(`
|
|
144
|
-
`),supportsJson:!0,options:["dry-run","env-file","history","name","stack","yes"],args:{min:0,max:1},async run(e){if(e.args.length>1)throw Error("import accepts at most one folder.");let t=await na(sa(e.cwd,e.args[0]??".")),n=J({env:e.env,flags:e.flags,cwd:t});if(n.conflict)throw new y("workspace_mismatch",n.conflict);if(!n.workspaceId||!n.credential)throw new y("workspace_required","No workspace selected. Run `hlix auth login` first.");let r=fe(t);if(r?.projectId)throw new y("already_imported","This folder is already bound to an Hlix project. Use `hlix push`.");let o=Qe(e.flags,"history");if(o&&o!=="preserve"&&o!=="abort-on-findings")throw Error("--history must be `abort-on-findings` or `preserve`.");if(!r&&e.flags["dry-run"]!==!0)Oe(t,{schemaVersion:1,workspaceId:n.workspaceId,apiUrl:n.baseUrl});let s=await W(t,{...Qe(e.flags,"env-file")?{envFile:Qe(e.flags,"env-file")}:{},environment:e.env,historyMode:o==="preserve"?"preserve":"abort_on_findings"});if(e.flags["dry-run"]!==!0&&s.blocking.length===0){let a=ia(s);if(a&&e.flags.yes!==!0){if(e.json||!e.confirm)throw new y("approval_required","Import needs approval for protected files or cloud setup. Review with `hlix import --dry-run`, then repeat with `--yes`.");if(!await e.confirm(a))throw new y("cancelled","Import cancelled.")}}let i={root:t,name:Qe(e.flags,"name")??ra(t),stack:Qe(e.flags,"stack")??s.manifest.stack,files:s.manifest.totals.files,bytes:s.manifest.totals.bytes,symlinks:s.manifest.symlinks,activeEnvFiles:s.manifest.activeEnvFiles,secretKeys:s.manifest.secretKeys,protectedFiles:s.manifest.secretFiles.length+s.manifest.quarantinedResources.length,environment:s.manifest.environment,historicalSecretFindings:s.manifest.historicalSecretFindings,quarantinedResources:s.manifest.quarantinedResources,mcpServers:s.manifest.mcpServers,skipped:s.manifest.skipped,blocking:s.blocking,manifestSha256:s.manifestSha256};if(e.flags["dry-run"]===!0){if(e.json)e.stdout(k(j(kt.name,i)));else{let a=[...s.manifest.secretFiles.map((l)=>`${l.kind}: ${l.path}`),...s.manifest.quarantinedResources.map((l)=>`${l.kind}: ${l.path}`)];e.stdout([`Project: ${i.name}`,`Stack: ${i.stack}`,`Files: ${i.files}`,`Bytes: ${i.bytes}`,`Environment confidence: ${i.environment.confidence}`,`History findings: ${i.historicalSecretFindings.length}`,"","Environment evidence:",...i.environment.sources.length?i.environment.sources.map((l)=>`- ${l.kind}: ${l.path}`):["- none detected"],"","Cloud setup commands:",...i.environment.install.length?i.environment.install.map((l)=>`- ${l}`):["- none detected"],"","Required secret keys:",...i.environment.requiredSecretKeys.length?i.environment.requiredSecretKeys.map((l)=>`- ${l}`):["- none detected"],"","Collected secret keys:",...i.secretKeys.length?i.secretKeys.map((l)=>`- ${l}`):["- none detected"],"","Protected and quarantined paths:",...a.length?a.map((l)=>`- ${l}`):["- none"],"","Environment warnings:",...i.environment.warnings.length?i.environment.warnings.map((l)=>`- ${l}`):["- none"],"","Symlinks (stored as links, targets never read):",...i.symlinks.length?i.symlinks.map((l)=>`- ${l.path} -> ${l.target}`):["- none"],"","Skipped paths:",...i.skipped.length?i.skipped.map((l)=>`- ${l.reason}: ${l.path}`):["- none"],...i.blocking.length?["","Blocking findings:",...i.blocking.map((l)=>`- ${l}`)]:[]].join(`
|
|
145
|
-
`)+`
|
|
146
|
-
`)}return s.blocking.length?1:0}if(s.blocking.length)throw new y("scan_blocked",`Project scan blocked import:
|
|
147
|
-
- ${s.blocking.join(`
|
|
148
|
-
- `)}`);let c=await vt(s);try{let a=e.requireClient(t),l=await a.imports.create({idempotencyKey:oa(s.manifestSha256,c.bundleSha256),name:i.name,stack:i.stack,defaultBranch:"main",historyMode:s.manifest.git.historyMode,manifest:s.manifest,manifestSha256:s.manifestSha256,bundleSha256:c.bundleSha256,bundleSize:c.bundleSize,commitSha:c.commitSha});if(l.import.status==="pending_upload"){if(!l.upload)throw Error(`Import ${l.import.id} is ${l.import.status} but has no upload target.`);await a.imports.uploadBundle(l.upload,new Blob([Uint8Array.from(await ta(c.bundlePath))]),{onProgress:(g,p)=>{if(!e.json)e.stderr(`Uploading ${g}/${p} bytes\r`)}})}let d=(l.import.status==="ready"?{import:l.import}:await a.imports.finalize(l.import.id,{secrets:s.secretValues,protectedFiles:s.protectedFiles})).import,m=d.projectId??d.requestedProjectId;if(!m||!d.revisionId||!d.generation)throw Error("Import completed without project revision metadata.");Oe(t,{schemaVersion:1,projectId:m,workspaceId:n.workspaceId,apiUrl:n.baseUrl}),Ae(t,{schemaVersion:1,revisionId:d.revisionId,generation:d.generation,commitSha:c.commitSha,manifestSha256:s.manifestSha256,historyMode:s.manifest.git.historyMode,rootName:s.manifest.rootName});let S={projectId:m,revisionId:d.revisionId,generation:d.generation,commitSha:c.commitSha,files:s.manifest.totals.files,bytes:s.manifest.totals.bytes};if(e.json)e.stdout(k(j(kt.name,S)));else e.stderr(`
|
|
149
|
-
`),e.stdout(`Imported ${i.name}
|
|
150
|
-
Project ID: ${m}
|
|
151
|
-
Revision: ${d.generation}
|
|
152
|
-
`);return 0}finally{await c.dispose()}}};import{spawnSync as aa}from"node:child_process";import{existsSync as ca,mkdirSync as la,writeFileSync as da}from"node:fs";import{dirname as pa}from"node:path";function ua(e){return e==="global"?["# My rules","","Hlix Code reads this file in every project you open, before the project's","own rules. Write how you want an agent to work with you: the tone, the","things to always do, the things to never do.",""].join(`
|
|
153
|
-
`):["# Project rules","","Hlix Code and every other coding agent that opens this repository read","this file. Write the rules that are true of THIS project: how to run its","tests, its conventions, what not to touch.",""].join(`
|
|
154
|
-
`)}function ma(e){return e.VISUAL?.trim()||e.EDITOR?.trim()||"vi"}var xn={name:"rules",summary:"Show or edit the rules files the coding agent reads",usage:["Usage: hlix rules [--edit] [--global] [--cwd <dir>] [--json]","","Without --edit it reports which files Hlix Code loads and how big they are.","","--edit opens one in $EDITOR, creating it with a short header if it does not","exist yet. --global edits your own rules (~/.hlix/AGENTS.md, read in every",`project); without it the project's file (${nn.join(", then ")}).`].join(`
|
|
155
|
-
`),supportsJson:!0,options:["edit","global"],async run(e){let t=Vr({cwd:e.cwd,configDir:".hlix",env:e.env}),n=e.flags.global===!0;if(e.flags.edit===!0){if(e.json)throw new y("invalid_usage","`hlix rules --edit` opens an editor, so it has no --json form.");let r=n?sn(e.env):rn(e.cwd,".hlix")?.path??`${e.cwd}/AGENTS.md`;if(!ca(r))la(pa(r),{recursive:!0}),da(r,ua(n?"global":"project"),"utf8"),e.stdout(`Created ${r}.
|
|
156
|
-
`);let o=ma(e.env),s=aa(o,[r],{stdio:"inherit"});if(s.error)throw new y("invalid_usage",`Could not run ${o}: ${s.error.message}`);return s.status??0}if(e.json){let r=(o)=>o?{path:o.path,characters:o.content.length}:null;return e.stdout(k(j(xn.name,{user:r(t.global),project:r(t.project)}))),0}return e.stdout(`${Yr(t,e.cwd)}
|
|
157
|
-
`),0}};var In={name:"standards",summary:"Show the standards other agent tools left in this folder",usage:["Usage: hlix standards [--cwd <dir>] [--json]","","Reads the instruction files, skills, slash commands, MCP servers and","subagents this project already carries for Claude Code, Cursor, Windsurf,","Gemini, Codex, Cline, Copilot and VS Code, and shows where each came from.","Hlix Code loads all of it at startup; nothing has to be copied or rewritten.","","Server urls, headers and environment values are never printed."].join(`
|
|
158
|
-
`),supportsJson:!0,async run(e){let t=Zr(e.cwd,gt(e.env),{env:e.env});if(e.json)return e.stdout(k(j(In.name,{instructions:t.instructions.map((n)=>({path:n.path,source:n.source,scope:n.scope,characters:n.content.length,...n.note?{note:n.note}:{}})),skills:t.skills,commands:[...t.commands.map((n)=>({path:n.path,source:n.source,scope:n.scope})),...t.generatedCommands.map((n)=>({path:n.path,source:n.source,scope:n.scope,command:n.name}))],mcpServers:t.mcpServers.map((n)=>({path:n.path,source:n.source,scope:n.scope,name:n.name,transport:"command"in n.config?"stdio":"http"})),subagents:t.subagents.map((n)=>({path:n.path,source:n.source,scope:n.scope,name:n.name,description:n.description,...n.model?{model:n.model}:{}})),skipped:t.skipped}))),0;return e.stdout(es(t,e.cwd)),0}};var js=(e)=>e instanceof Error?e.message:String(e),fa=(e)=>e.split(/\s*\n\s*/).join(" ").trim();async function ga(e,t,n,r,o){try{let s=await W(t,{historyMode:n,environment:e.env,rootName:r});return{files:s.manifest.totals.files,manifestSha256:s.manifestSha256,changed:o?s.manifestSha256!==o:null,blocking:s.blocking,error:null}}catch(s){return{files:null,manifestSha256:null,changed:null,blocking:[],error:js(s)}}}var Rn={name:"status",summary:"Show the workspace, folder binding, and local-vs-cloud drift",usage:["Usage: hlix status [--cwd <dir>] [--json]","","Reports the resolved workspace and API with the source that decided each,","whether this folder is bound to a project, and whether the working tree or","the cloud head has moved since the last sync. Every finding is a line in","the output, so the command itself always exits 0; only an argument error","(rejected before it runs) exits 2."].join(`
|
|
159
|
-
`),supportsJson:!0,async run(e){let t=J({env:e.env,flags:e.flags,cwd:e.cwd}),n=t.binding,r=n?pt(n.root):null,o=n?await ga(e,n.root,r?.historyMode??"preserve",r?.rootName,r?.manifestSha256):null,s=null;if(n?.config.projectId&&t.credential&&!t.conflict)try{let a=(await e.requireClient().revisions.head(n.config.projectId)).revision;s={revisionId:a.id,generation:a.generation,changed:r?a.id!==r.revisionId||a.generation!==r.generation:null,error:null,errorMessage:null}}catch(a){s={revisionId:"",generation:0,changed:null,error:Vt(a).code,errorMessage:js(a)}}let i={cwd:e.cwd,workspace:{id:t.workspaceId,source:t.workspaceSource},api:{baseUrl:t.baseUrl,source:t.baseUrlSource},credential:{present:t.credential!==null,source:t.credentialSource,path:t.credentialPath},conflict:t.conflict,project:n?{root:n.root,projectId:n.config.projectId??null,workspaceId:n.config.workspaceId,apiUrl:n.config.apiUrl}:null,revision:r?{id:r.revisionId,generation:r.generation,commitSha:r.commitSha}:null,local:o,cloud:s};if(e.json)return e.stdout(k(j(Rn.name,i))),0;let c=[["folder",e.cwd],["workspace",t.workspaceId?`${t.workspaceId} (from ${t.workspaceSource})`:"none — run `hlix auth login --workspace <id>`"],["api",`${t.baseUrl} (from ${t.baseUrlSource})`],["credential",mt(t)??"none — run `hlix auth login`"],["project",n?n.config.projectId??`initialized at ${n.root}, not imported yet`:"none — run `hlix import .` to bind this folder"]];if(r)c.push(["revision",`generation ${r.generation} (${r.revisionId})`]);if(o){if(c.push(["local",o.error?`could not scan: ${o.error}`:o.changed===null?`${o.files} files, no synced base revision`:o.changed?`${o.files} files, modified since the last sync`:`${o.files} files, matches the last sync`]),o.blocking.length>0)c.push(["blocking",o.blocking.join("; ")])}if(s)c.push(["cloud",s.error?`not checked — ${fa(s.errorMessage??s.error)}`:s.changed?`generation ${s.generation} available — run \`hlix pull\``:`generation ${s.generation}, up to date`]);if(t.conflict)c.push(["conflict",t.conflict]);return e.stdout(`${A(c)}
|
|
160
|
-
`),0}};import{spawnSync as Es}from"node:child_process";var Tn={name:"terminal",summary:"Open a shell into the project's Coding Workspace",usage:["Usage: hlix terminal [project-id] [--print] [--web] [--json]","","With no id, the project this folder is bound to is used."," --print Show the ssh command and browser url instead of connecting"," --web Open the browser terminal instead of ssh"].join(`
|
|
161
|
-
`),supportsJson:!0,options:["print","web"],args:{min:0,max:1},async run(e){let t=e.args[0]??N(e.cwd)?.config.projectId;if(!t)throw new y("missing_argument","A project id is required, or run this inside a folder bound to a project.");let n=await e.requireClient().projects.terminal(t);if(e.json)return e.stdout(k(j(Tn.name,n))),n.available?0:1;if(!n.available){let i=n.environmentState?` (environment: ${n.environmentState})`:"";throw new y("not_found",`${n.reason??"Terminal unavailable"}${i}`)}let r=e.flags.print===!0,o=e.flags.web===!0;if(r||o&&!n.webTerminalUrl||!o&&!n.sshCommand)return e.stdout(`${A([["ssh",n.sshCommand??"not available"],["browser",n.webTerminalUrl??"not available"]])}
|
|
162
|
-
`),0;if(o){if(Es(process.platform==="darwin"?"open":"xdg-open",[n.webTerminalUrl],{stdio:"ignore"}).status!==0)e.stdout(`${n.webTerminalUrl}
|
|
163
|
-
`);return 0}return Es("sh",["-c",n.sshCommand],{stdio:"inherit"}).status??1}};import{createHash as _a}from"node:crypto";import{readFile as Oa,realpath as Aa}from"node:fs/promises";import{createHash as ha}from"node:crypto";import{constants as St}from"node:fs";import{chmod as $s,copyFile as ya,lstat as _n,mkdir as wa,mkdtemp as va,open as ka,realpath as Sa,rename as ba,rm as de,symlink as ja,writeFile as Ea}from"node:fs/promises";import{tmpdir as $a}from"node:os";import{dirname as Is,join as ee,relative as Pa,resolve as Ca,sep as Ps}from"node:path";import{spawnSync as xa}from"node:child_process";var Ia=300000;function Rs(e){let t=e;if(typeof t==="string")try{t=JSON.parse(t)}catch{return{}}if(!t||typeof t!=="object")return{};let n=t,r=n.git&&typeof n.git==="object"?n.git:{},o=r.historyMode==="preserve"||r.historyMode==="abort_on_findings"?r.historyMode:void 0,s=typeof n.rootName==="string"&&n.rootName.trim()?n.rootName:void 0;return{historyMode:o,rootName:s}}function Ts(e,t){let n=e;if(typeof n==="string")try{n=JSON.parse(n)}catch{return[]}if(!n||typeof n!=="object")return[];let r=n[t];if(!Array.isArray(r))return[];return r.filter((o)=>!!o&&typeof o==="object")}function _s(e){return Ts(e,"files").flatMap((t)=>typeof t.path==="string"&&typeof t.sha256==="string"?[{path:t.path,sha256:t.sha256}]:[])}function On(e){return Ts(e,"symlinks").flatMap((t)=>typeof t.path==="string"&&typeof t.target==="string"?[{path:t.path,target:t.target}]:[])}function et(e,t){let n=xa("git",["-C",e,...t],{encoding:"utf8",timeout:Ia,maxBuffer:52428800,stdio:["ignore","pipe","pipe"]});if(n.status!==0)throw Error(n.stderr.trim().split(`
|
|
164
|
-
`).at(-1)??"Git command failed");return n.stdout.trim()}function Cs(e){return ha("sha256").update(e).digest("hex")}async function bt(e,t,n){let r=await Sa(e),o=Ca(r,...t.split("/"));if(o!==r&&!o.startsWith(r+Ps))throw Error(`Protected path escapes the project: ${t}`);let s=Pa(r,Is(o)),i=r;for(let c of s.split(Ps).filter(Boolean)){i=ee(i,c);try{let a=await _n(i);if(a.isSymbolicLink()&&n){n.push(i);break}if(!a.isDirectory()||a.isSymbolicLink())throw Error(`Protected path crosses a non-directory: ${t}`)}catch(a){if(a.code!=="ENOENT")throw a;if(!n)await wa(i,{mode:448})}}return o}async function xs(e,t,n){let r=await bt(e,t);try{let i=await _n(r);if(!i.isFile()||i.isSymbolicLink())throw Error(`Refusing to replace non-regular protected file: ${t}`)}catch(i){if(i.code!=="ENOENT")throw i}let o=ee(Is(r),`.hlix-pull-${crypto.randomUUID()}.tmp`),s=await ka(o,St.O_WRONLY|St.O_CREAT|St.O_EXCL|St.O_NOFOLLOW,384);try{await s.writeFile(n),await s.sync()}finally{await s.close()}try{await ba(o,r)}catch(i){throw await de(o,{force:!0}),i}}async function Ra(e,t,n){let r=n.length,o=await bt(e,t,n);if(n.length>r)return;try{let s=await _n(o);if(s.isSymbolicLink()){n.push(o);return}if(!s.isFile())throw Error(`Refusing to replace non-regular project file: ${t}`)}catch(s){if(s.code!=="ENOENT")throw s}}async function Os(e,t,n,r,o){let s=await va(ee($a(),"hlix-pull-"));await $s(s,448);let i=ee(s,"project.bundle"),c=ee(s,"checkout");try{let a=Buffer.from(await r.arrayBuffer());if(a.byteLength!==n.bundleSize||Cs(a)!==n.bundleSha256)throw Error("Downloaded revision bundle failed integrity verification.");if(await Ea(i,a,{mode:384}),et(s,["clone","--no-hardlinks","--branch","main",i,c]),et(c,["bundle","verify",i]),et(c,["rev-parse","HEAD"])!==n.commitSha)throw Error("Downloaded revision bundle does not match the cloud commit.");let l=n.manifest,u=new Map;for(let p of[...l.secretFiles,...l.quarantinedResources])u.set(p.path,p);if(o.files.length!==u.size)throw Error("Cloud protected files do not match the revision manifest.");let d=new Map;for(let p of o.files){let f=u.get(p.path),I=Buffer.from(p.contentBase64,"base64");if(I.toString("base64").replace(/=+$/,"")!==p.contentBase64.replace(/=+$/,"")||!f||f.kind!==p.kind||I.byteLength!==f.size||Cs(I)!==f.sha256)throw Error(`Cloud protected file failed integrity verification: ${p.path}`);d.set(p.path,I)}let m=On(n.manifest),S=new Set([...l.files.map((p)=>p.path),...m.map((p)=>p.path),...t.manifest.secretFiles.map((p)=>p.path),...t.manifest.quarantinedResources.map((p)=>p.path),...d.keys()]),g=[];for(let p of[...S].sort())await Ra(e,p,g);for(let[p,f]of d)await xs(c,p,f);for(let p of[...new Set(g)].sort())await de(p,{force:!0});if(t.manifest.git.detected){et(e,["fetch",i,"refs/heads/main"]),et(e,["reset","--hard","FETCH_HEAD"]);let p=new Set([...l.files.map((f)=>f.path),...m.map((f)=>f.path)]);for(let f of[...t.manifest.files,...t.manifest.symlinks])if(!p.has(f.path))await de(ee(e,...f.path.split("/")),{force:!0})}else{for(let p of[...t.manifest.files,...t.manifest.symlinks])await de(ee(e,...p.path.split("/")),{force:!0});for(let p of l.files){let f=await bt(e,p.path);await ya(ee(c,...p.path.split("/")),f),await $s(f,p.executable?493:420)}for(let p of m){let f=await bt(e,p.path);await de(f,{force:!0}),await ja(p.target,f)}}for(let p of[...t.manifest.secretFiles,...t.manifest.quarantinedResources])if(!d.has(p.path))await de(ee(e,...p.path.split("/")),{force:!0});for(let[p,f]of d)await xs(e,p,f)}finally{await de(s,{recursive:!0,force:!0})}}function be(e,t,n){let r=new Map([..._s(n.manifest).map((a)=>[a.path,`blob:${a.sha256}`]),...On(n.manifest).map((a)=>[a.path,`link:${a.target}`])]),o=new Map([...e.manifest.files.map((a)=>[a.path,`blob:${a.sha256}`]),...e.manifest.symlinks.map((a)=>[a.path,`link:${a.target}`])]),s=0,i=0;for(let[a,l]of o){let u=r.get(a);if(u===void 0)s+=1;else if(u!==l)i+=1}let c=0;for(let a of r.keys())if(!o.has(a))c+=1;return{localChanged:!t.manifestSha256||e.manifestSha256!==t.manifestSha256,cloudChanged:n.id!==t.revisionId||n.generation!==t.generation,local:{revisionId:t.revisionId,generation:t.generation},cloud:{revisionId:n.id,generation:n.generation,commitSha:n.commitSha},files:{local:o.size,cloud:r.size,localOnly:s,cloudOnly:c,differing:i}}}function An(e,t,n){let{localChanged:r,cloudChanged:o}=t;if(e==="push")return o?"conflict":r?"push":"none";if(e==="pull"){if(!o)return"none";return r&&!n?"conflict":"pull"}if(r&&o)return"conflict";return r?"push":o?"pull":"none"}function Fn(e,t,n){return e==="pull"&&t.localChanged&&!n}var Ta={push:{push:"Would push the local changes as a new cloud revision.",pull:"",none:"Nothing to push — local matches the last synced revision.",conflict:"Would refuse: the cloud changed since this folder's base revision."},pull:{push:"",pull:"Would replace local files with the cloud revision.",none:"Nothing to pull — the cloud head is the local base revision.",conflict:"Would refuse: local files changed. Re-run with --force to replace them."},sync:{push:"Would push the local changes as a new cloud revision.",pull:"Would pull the cloud revision into this folder.",none:"Already in sync.",conflict:"Would refuse: local and cloud both changed since the last sync."}};function As(e,t,n,r){let o=n.files;return[`${e} --dry-run: ${Ta[e][t]}`,...r?["Requires --yes (or interactive approval) to execute."]:[],"",A([["local",`generation ${n.local.generation} (${n.local.revisionId})${n.localChanged?" — modified":""}`],["cloud",`generation ${n.cloud.generation} (${n.cloud.revisionId})${n.cloudChanged?" — ahead":""}`],["files",`${o.local} local, ${o.cloud} cloud — ${o.localOnly} local-only, ${o.cloudOnly} cloud-only, ${o.differing} differing`]])].join(`
|
|
165
|
-
`)}function Fa(e,t,n){return _a("sha256").update(`project-push-v1\x00${e}\x00${t}\x00${n}`).digest("hex")}var Na={schemaVersion:1,revisionId:"",generation:0,commitSha:""};async function je(e,{allowUnsynced:t=!1}={}){let n=N(e);if(!n?.config.projectId)throw new y("not_initialized","This folder is not bound to an imported Hlix project. Run `hlix import .` first.");let r=pt(n.root)??(t?Na:null);if(!r)throw new y("not_initialized","This folder is bound to a project but has never been pulled. Run `hlix pull` first.");return{root:await Aa(n.root),config:n.config,state:r}}async function tt(e,t,n,r){let o=await W(e,{historyMode:n,environment:t,rootName:r});if(o.blocking.length>0)throw new y("scan_blocked",`Project scan blocked sync:
|
|
166
|
-
- ${o.blocking.join(`
|
|
167
|
-
- `)}`);return o}async function Nn(e,t,n,r){let{state:o,config:s}=await je(r,{allowUnsynced:n==="pull"}),i=e.requireClient(),[c,a]=await Promise.all([tt(r,e.env,o.historyMode??"preserve",o.rootName),i.revisions.head(s.projectId)]),l=be(c,o,a.revision),u=An(n,l,e.flags.force===!0),d=Fn(u,l,e.flags.yes===!0);if(e.json)e.stdout(k(j(t,{dryRun:!0,action:u,approvalRequired:d,...l})));else e.stdout(`${As(n,u,l,d)}
|
|
168
|
-
`);return u==="conflict"?1:0}async function La(e,t){if(e.flags.yes===!0)return;if(e.json||!e.confirm)throw new y("approval_required","`pull --force` replaces local files. Review with `hlix pull --dry-run`, then repeat with `--yes`.");let n=[`hlix pull --force will replace this folder with cloud revision ${t.cloud.generation}.`,`Local-only files to delete: ${t.files.localOnly}`,`Files to replace with the cloud copy: ${t.files.differing}`,"Local changes that were never pushed cannot be recovered by Hlix."].join(`
|
|
169
|
-
`);if(!await e.confirm(n))throw new y("cancelled","Pull cancelled.")}async function Fs(e,t,n,r){let{state:o,config:s}=await je(e),i=t.requireClient(),c=o.historyMode??"preserve",a=n??await tt(e,t.env,c,o.rootName),l=r??(await i.revisions.head(s.projectId)).revision;if(l.id!==o.revisionId||l.generation!==o.generation)throw new y("conflict","Cloud changed since the local base. Run `hlix pull` or resolve with `hlix sync`.");if(o.manifestSha256&&a.manifestSha256===o.manifestSha256)return{action:"none",revisionId:o.revisionId,generation:o.generation};let u=await vt(a);try{let d=await i.revisions.createUpload(s.projectId,{idempotencyKey:Fa(o.revisionId,a.manifestSha256,u.bundleSha256),expectedRevisionId:o.revisionId,expectedGeneration:o.generation,manifest:a.manifest,manifestSha256:a.manifestSha256,bundleSha256:u.bundleSha256,bundleSize:u.bundleSize,commitSha:u.commitSha});if(d.revisionUpload.status==="pending_upload"){if(!d.upload)throw Error("Revision upload has no bundle target.");await i.revisions.uploadBundle(d.upload,new Blob([Uint8Array.from(await Oa(u.bundlePath))]),{onProgress:(S,g)=>{if(!t.json)t.stderr(`Uploading ${S}/${g} bytes\r`)}})}let m=await i.revisions.finalize(s.projectId,d.revisionUpload.id,{secrets:a.secretValues,protectedFiles:a.protectedFiles});if(!m.revision)throw Error("Revision finalized without head metadata.");return Ae(e,{schemaVersion:1,revisionId:m.revision.id,generation:m.revision.generation,commitSha:m.revision.commitSha,manifestSha256:m.revision.manifestSha256,historyMode:c,rootName:o.rootName??a.manifest.rootName}),{action:"push",...m.revision}}finally{await u.dispose()}}async function Ns(e,t,n,r,o){let{state:s,config:i}=await je(e,{allowUnsynced:!0}),c=t.requireClient(),a=s.historyMode??"preserve",l=r??await tt(e,t.env,a,s.rootName),u=o??(await c.revisions.head(i.projectId)).revision;if(u.id===s.revisionId&&u.generation===s.generation)return{action:"none",revisionId:s.revisionId,generation:s.generation};let d=s.manifestSha256?l.manifestSha256!==s.manifestSha256:(()=>{let{files:v}=be(l,s,u);return v.localOnly+v.differing>0})();if(d&&!n)throw new y("conflict","Local files changed since the last sync. Push them, or use `hlix pull --force` to replace them.");if(d)await La(t,be(l,s,u));let[m,S]=await Promise.all([c.revisions.downloadBundle(i.projectId,u.id),c.revisions.protectedFiles(i.projectId)]);await Os(e,l,u,m,S);let g=Rs(u.manifest),p=g.historyMode??a,f=g.rootName??s.rootName??l.manifest.rootName,I=await tt(e,t.env,p,f);return Ae(e,{schemaVersion:1,revisionId:u.id,generation:u.generation,commitSha:u.commitSha,manifestSha256:I.manifestSha256,historyMode:p,rootName:f}),{action:"pull",revisionId:u.id,generation:u.generation,commitSha:u.commitSha}}function Ln(e,t,n){if(e.json)e.stdout(k(j(t,n)));else if("action"in n&&n.action==="none")e.stdout(`Already in sync.
|
|
170
|
-
`);else e.stdout(`${String("action"in n?n.action:"sync")} complete.
|
|
171
|
-
`)}var jt={name:"push",summary:"Push local changes as an immutable cloud revision",usage:"Usage: hlix push [--dry-run] [--json]",supportsJson:!0,options:["dry-run"],async run(e){if(e.args.length)throw Error("push accepts no positional arguments.");let{root:t}=await je(e.cwd);if(e.flags["dry-run"]===!0)return Nn(e,jt.name,"push",t);return Ln(e,jt.name,await Fs(t,e)),0}},Et={name:"pull",summary:"Pull the cloud head into the local project",usage:["Usage: hlix pull [--force] [--yes] [--dry-run] [--json]",""," --force Replace local changes with the cloud revision"," --yes Skip the confirmation --force otherwise requires"," --dry-run Report the divergence and change nothing"].join(`
|
|
172
|
-
`),supportsJson:!0,options:["force","yes","dry-run"],async run(e){if(e.args.length)throw Error("pull accepts no positional arguments.");let{root:t}=await je(e.cwd,{allowUnsynced:!0});if(e.flags["dry-run"]===!0)return Nn(e,Et.name,"pull",t);return Ln(e,Et.name,await Ns(t,e,e.flags.force===!0)),0}},$t={name:"sync",summary:"Reconcile local and cloud changes without guessing conflicts",usage:"Usage: hlix sync [--dry-run] [--json]",supportsJson:!0,options:["dry-run"],async run(e){if(e.args.length)throw Error("sync accepts no positional arguments.");let{root:t,state:n,config:r}=await je(e.cwd);if(e.flags["dry-run"]===!0)return Nn(e,$t.name,"sync",t);let o=e.requireClient(),[s,i]=await Promise.all([tt(t,e.env,n.historyMode??"preserve",n.rootName),o.revisions.head(r.projectId)]),c=i.revision,a=be(s,n,c);if(a.localChanged&&a.cloudChanged)throw new y("conflict","Both local and cloud changed since the last sync. Pull or push explicitly after reviewing the conflict.");let l=a.localChanged?await Fs(t,e,s,c):a.cloudChanged?await Ns(t,e,!1,s,c):{action:"none",revisionId:n.revisionId,generation:n.generation};return Ln(e,$t.name,l),0}};import{lstat as Ls,readFile as Ha,realpath as Ma}from"node:fs/promises";import{basename as Hn,dirname as Ua,extname as za,join as Ba,parse as Hs,resolve as Mn}from"node:path";function nt(e,t){let n=e.flags[t];return typeof n==="string"&&n.trim()?n.trim():void 0}function Un(e){let t=N(e);if(!t?.config.projectId)throw new y("not_initialized","This folder is not bound to an Hlix project. Run `hlix import .` first.");return{root:t.root,projectId:t.config.projectId}}async function zn(e,t){let n=await Ls(e);if(n.isSymbolicLink()||!n.isFile())throw Error(`Refusing to import a non-regular file: ${e}`);if(n.size>t)throw Error(`Import file exceeds ${t} bytes: ${e}`);return{path:await Ma(e),content:await Ha(e,"utf8")}}function Bn(e,t,n,r){if(e.json)e.stdout(k(j(t,n)));else e.stdout(`${r}
|
|
173
|
-
`)}var Dn={name:"skill import",summary:"Activate a local skill for the bound cloud project",usage:"Usage: hlix skill import <SKILL.md|folder> [--name <slug>] [--json]",supportsJson:!0,options:["name"],args:{min:1,max:1},async run(e){if(e.args.length!==1)throw Error("skill import requires one file or folder.");let t=Un(e.cwd),n=Mn(e.cwd,e.args[0]),r=await Ls(n);if(r.isSymbolicLink())throw Error(`Refusing to import a symlink: ${n}`);let o=r.isDirectory()?Ba(n,"SKILL.md"):n,s=await zn(o,200000),i=r.isDirectory()?Hn(n):Hn(o)==="SKILL.md"?Hn(Ua(o)):Hs(o).name,c=nt(e,"name")??i;if(!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(c))throw Error("Skill name must be a lowercase kebab-case slug.");let a=await e.requireClient().resources.importSkill(t.projectId,{slug:c,content:s.content});return Bn(e,Dn.name,a.skill,`Imported skill ${c}`),0}},Kn={name:"agent import",summary:"Create a project-scoped agent from a local Markdown brief",usage:"Usage: hlix agent import <markdown-file> [--name <name>] [--runtime <runtime>] [--duty <duty>] [--profile <profile>] [--json]",supportsJson:!0,options:["name","runtime","duty","profile"],args:{min:1,max:1},async run(e){if(e.args.length!==1)throw Error("agent import requires one Markdown file.");let t=Un(e.cwd),n=Mn(e.cwd,e.args[0]);if(![".md",".mdx"].includes(za(n).toLowerCase()))throw Error("Agent imports must be Markdown files.");let r=await zn(n,20000),o=nt(e,"runtime")??"hlix";if(!["claude-code","codex","cursor-agent","hlix"].includes(o))throw Error("--runtime must be claude-code, codex, cursor-agent, or hlix.");let s=nt(e,"duty")??"executor";if(s!=="executor"&&s!=="intake")throw Error("--duty must be executor or intake.");let i=nt(e,"name")??Hs(n).name.replace(/[-_]+/g," "),c=await e.requireClient().resources.importAgent(t.projectId,{name:i,instructions:r.content,runtimeKind:o,duty:s});return Bn(e,Kn.name,c.agent,c.agent.duty==="intake"?`Imported agent ${c.agent.name} as this project's intake agent`:`Imported agent ${c.agent.name}`),0}},Jn={name:"mcp import",summary:"Explicitly activate one validated local MCP server",usage:"Usage: hlix mcp import <.mcp.json> [--server <name>] [--allow-stdio] [--json]",supportsJson:!0,options:["server","allow-stdio"],args:{min:1,max:1},async run(e){if(e.args.length!==1)throw Error("mcp import requires one MCP JSON file.");let t=Un(e.cwd),n=await zn(Mn(e.cwd,e.args[0]),200000),r;try{r=JSON.parse(n.content)}catch{throw Error("MCP config is not valid JSON.")}let o=Object.entries(r.mcpServers??{});if(o.length===0)throw Error("MCP config contains no servers.");let s=nt(e,"server");if(!s&&o.length>1)throw Error("MCP config contains multiple servers; select one with --server <name>.");let i=s?o.find(([p])=>p===s):o[0];if(!i)throw Error(`MCP server not found: ${s}`);let[c,a]=i,l=a.type==="http"||a.type==="sse"?a.type:typeof a.command==="string"?"stdio":typeof a.url==="string"?"http":null;if(!l)throw Error(`MCP server ${c} has no supported transport.`);if(l==="stdio"&&e.flags["allow-stdio"]!==!0)throw Error("Stdio MCP servers execute a local command in the cloud; repeat with --allow-stdio.");let u=a.env&&typeof a.env==="object"&&!Array.isArray(a.env)?a.env:{},d=a.headers&&typeof a.headers==="object"&&!Array.isArray(a.headers)?a.headers:{};if(Object.values(d).some((p)=>typeof p!=="string"))throw Error(`MCP server ${c} headers must be strings.`);let m=Object.values(d).flatMap((p)=>[...p.matchAll(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g)].map((f)=>f[1]));if(Object.keys(d).length>0&&m.length===0)throw Error("MCP remote headers must use ${KEY} placeholders; literal credentials are refused.");let S=/^(?:(?:Bearer|Basic|Token) )?\$\{[A-Za-z_][A-Za-z0-9_]*\}$/i;if(Object.values(d).some((p)=>!S.test(p)))throw Error("MCP remote headers must be ${KEY} or an approved auth scheme followed by ${KEY}.");let g=await e.requireClient().resources.importMcp(t.projectId,{name:c,transport:l,...typeof a.command==="string"?{command:a.command}:{},...Array.isArray(a.args)&&a.args.every((p)=>typeof p==="string")?{args:a.args}:{},...typeof a.url==="string"?{url:a.url}:{},...Object.keys(d).length>0?{headers:d}:{},envKeys:[...new Set([...Object.keys(u),...m])].sort()});return Bn(e,Jn.name,g.mcpServer,`Imported MCP server ${c}`),0}};import{spawnSync as Da}from"node:child_process";import{chmod as Ka,realpath as Ja,writeFile as Ga}from"node:fs/promises";import{basename as qa,dirname as Wa,relative as Va,resolve as Us,sep as Ya}from"node:path";var Ms=64;function st(e){let t=N(e.cwd),r=(typeof e.flags.project==="string"?e.flags.project:void 0)??t?.config.projectId;if(!r)throw new y("not_initialized","This folder is not bound to a Hlix project. Run `hlix import .`, or pass --project <id>.");return{projectId:r,root:t?.root??e.cwd}}var rt=(e,t)=>typeof e[t]==="string"?e[t]:void 0,Gn={name:"secrets list",summary:"Show every secret the project holds, masked, with its source file",usage:["Usage: hlix secrets list [--project <id>] [--json]","","One row per (key, source file). Values are masked to their last four","characters and there is no flag that unmasks them — `hlix secrets export`","is the one command that returns plaintext, and it is audited."].join(`
|
|
174
|
-
`),supportsJson:!0,options:["project"],async run(e){let{projectId:t}=st(e),n=await e.requireClient().secrets.listEntries(t);if(e.json)return e.stdout(k(j(Gn.name,n))),0;if(n.entries.length===0)e.stdout(`No secrets stored for this project.
|
|
175
|
-
`);else e.stdout(`${X(["key","source","format","value","updated"],n.entries.map((r)=>[r.key,r.source,r.format||"-",r.maskedValue,r.updatedAt?.slice(0,10)??"-"]))}
|
|
176
|
-
`);for(let r of n.warnings)e.stderr(`warning: ${r}
|
|
177
|
-
`);return 0}},qn={name:"secrets set",summary:"Create or replace one secret in the store",usage:["Usage: hlix secrets set <KEY> [value] [--from-stdin] [--source <file>] [--project <id>] [--json]",""," --from-stdin Read the value from stdin instead of the argument, so it"," never reaches shell history or `ps`. Use this for real"," credentials: `pbpaste | hlix secrets set API_KEY --from-stdin`."," --source The file the value belongs to, e.g. apps/api/.env.local."," Omitted means the project root .env.","","Exactly one trailing newline is stripped from stdin, so a piped value does","not acquire the shell's."].join(`
|
|
178
|
-
`),supportsJson:!0,options:["from-stdin","source","project"],args:{min:1,max:2},async run(e){let{projectId:t}=st(e),n=e.args[0],r=e.flags["from-stdin"]===!0;if(r&&e.args.length>1)throw new y("invalid_usage","Pass the value as an argument or with --from-stdin, not both.");if(!r&&e.args.length<2)throw new y("missing_argument","A value is required. Pass it as an argument, or pipe it with --from-stdin.");let o;if(r){if(!e.readStdin)throw new y("invalid_usage","--from-stdin is not available in this context.");o=(await e.readStdin()).replace(/\r?\n$/,"")}else o=e.args[1];let s=rt(e.flags,"source"),i=await e.requireClient().secrets.upsertEntries(t,{entries:[{key:n,value:o,...s?{source:s}:{}}]});if(e.json)return e.stdout(k(j(qn.name,i))),i.written>0?0:1;if(i.written===0)throw new y("bad_request",`The store refused ${n}: --source must be a project-relative file path.`);return e.stdout(`${A([["key",n],["source",s??".env"]])}
|
|
179
|
-
`),0}},Wn={name:"secrets delete",summary:"Remove one secret from the store",usage:["Usage: hlix secrets delete <KEY> [--source <file>] [--project <id>] [--json]","","Without --source the key is removed from EVERY file that declares it,",'which is what "delete this secret" usually means. Removing nothing exits 1.'].join(`
|
|
180
|
-
`),supportsJson:!0,options:["source","project"],args:{min:1,max:1},async run(e){let{projectId:t}=st(e),n=e.args[0],r=rt(e.flags,"source"),o=await e.requireClient().secrets.deleteEntry(t,n,r);if(e.json)return e.stdout(k(j(Wn.name,o))),o.removed>0?0:1;if(o.removed===0)return e.stderr(`No stored secret named ${n}${r?` in ${r}`:""}.
|
|
181
|
-
`),1;return e.stdout(`Removed ${o.removed} entr${o.removed===1?"y":"ies"} for ${n}.
|
|
182
|
-
`),0}},Pt={name:"secrets import",summary:"Load this folder's secret files into the project secrets store",usage:["Usage: hlix secrets import [file...] [--project <id>] [--json]","","With no arguments, every secret file the project scanner detects. Naming","files narrows it to those; a named file the scanner does not consider a","secret is refused rather than uploaded.","","The files are uploaded as bytes and the server parses them, so every shape","it knows lands here: dotenv and .envrc, Terraform variables, Java","properties, Spring YAML, .NET appsettings, Azure Functions local settings,","npm credentials, Rails database.yml, wrangler/fly TOML and Serverless all","become readable entries under their own path. An opaque credential (a","private key, a keystore, a service-account JSON) is kept byte-exact","instead. A file whose plaintext this platform does not hold — SOPS,","Ansible Vault, git-crypt — and a .env.example are reported as skipped.","","A file that holds key/value pairs REPLACES what the store held for that","path: the file on this machine is the truth."].join(`
|
|
183
|
-
`),supportsJson:!0,options:["project"],args:{min:0,max:64},async run(e){let{projectId:t,root:n}=st(e),r=await W(n,{historyMode:"preserve",environment:e.env}),o=r.blocking.filter((d)=>!d.startsWith(jn));if(o.length>0)throw new y("scan_blocked",`Project scan blocked the import:
|
|
184
|
-
- ${o.join(`
|
|
185
|
-
- `)}`);let s=r.protectedFiles.filter((d)=>d.kind==="dotenv"||d.kind==="credential"),i=await Ja(e.cwd),c=e.args.map((d)=>Va(r.root,Us(i,d)).split(Ya).join("/")),a=c.filter((d)=>!s.some((m)=>m.path===d));if(a.length>0)throw new y("invalid_usage",`Not a secret file in this project: ${a.join(", ")}`);let l=c.length>0?s.filter((d)=>c.includes(d.path)):s;if(l.length===0)return e.stdout(e.json?k(j(Pt.name,{imported:[],skipped:[],warnings:[],written:0,rejected:[]})):`No secret files found in this project.
|
|
186
|
-
`),0;if(l.length>Ms)throw new y("invalid_usage",`${l.length} secret files exceeds the ${Ms} the store accepts in one request. Name the files to import, a batch at a time.`);let u=await e.requireClient().secrets.importFiles(t,l.map((d)=>({path:d.path,contentBase64:d.contentBase64})));if(e.json)return e.stdout(k(j(Pt.name,u))),0;if(u.imported.length>0)e.stdout(`${X(["source","format","stored"],u.imported.map((d)=>[d.path,d.format||"-",d.kind==="file"?"as file":`${d.entries} entr${d.entries===1?"y":"ies"}`]))}
|
|
187
|
-
`);e.stdout(`${u.written} value${u.written===1?"":"s"} stored.
|
|
188
|
-
`);for(let d of u.skipped)e.stderr(`skipped ${d.path}: ${d.reason}
|
|
189
|
-
`);for(let d of u.warnings)e.stderr(`warning: ${d}
|
|
190
|
-
`);for(let d of u.rejected)e.stderr(`rejected ${d}: the store refused its source path
|
|
191
|
-
`);return 0}};function Xa(e){return Da("git",["-C",Wa(e),"ls-files","--error-unmatch","--",qa(e)],{encoding:"utf8",stdio:["ignore","pipe","pipe"]}).status===0}var Vn={name:"secrets export",summary:"Render one source file back out of the store, values in clear",usage:["Usage: hlix secrets export [--source <file>] [--format <id>] [--out <path>] [--project <id>] [--json]",""," --source Which stored file to render. Omitted means the root .env."," --format Re-render it as a different shape (dotenv, tfvars, …)."," Omitted means the shape the values were parsed as."," --out Write it to this path, mode 0600, instead of stdout. A path"," git TRACKS is refused: an exported file carries plaintext and"," must not become a commit.","","This is the one command that returns secret values, and the server writes","an audit row for every call."].join(`
|
|
192
|
-
`),supportsJson:!0,options:["source","format","out","project"],async run(e){let{projectId:t}=st(e),n=rt(e.flags,"source"),r=rt(e.flags,"format"),o=rt(e.flags,"out"),s=o===void 0?void 0:Us(e.cwd,o);if(s!==void 0&&Xa(s))throw new y("invalid_usage",`Refusing to overwrite a git-tracked file with secret values: ${s}`);let i=await e.requireClient().secrets.exportEntries(t,{...n?{source:n}:{},...r?{format:r}:{}});if(s!==void 0)await Ga(s,i,{mode:384}),await Ka(s,384);if(e.json)return e.stdout(k(j(Vn.name,{source:n??null,format:r??null,out:s??null,bytes:Buffer.byteLength(i),...s===void 0?{content:i}:{}}))),0;if(s===void 0)e.stdout(i);else e.stdout(`${A([["wrote",s],["mode","0600"],["bytes",String(Buffer.byteLength(i))]])}
|
|
193
|
-
`);return 0}};function Yn(e,t){let n=e[t];if(typeof n!=="string"||n.trim()==="")throw new y("missing_argument",`--${t} is required.`);return n}var Xn={name:"cycles create",summary:"Propose a cycle, which starts the project working on it",usage:["Usage: hlix cycles create <project-id> --title <t> --description <d> [--json]","","This is the command that DISPATCHES work. The proposal enters the project's","own loop, which plans the cycle, creates its tasks and starts the coders —","using the project's harness (see `hlix harness get`).","","`adopted` is true when the loop took it on this call, false when it was","recorded and will be planned on the next pass. Neither is an error. The API","returns no cycle id: the roadmap owns cycles, so find it with `hlix tasks","list --project <id>` once planning has run."].join(`
|
|
194
|
-
`),supportsJson:!0,options:["title","description"],args:{min:1,max:1},async run(e){let t=e.args[0],n=Yn(e.flags,"title"),r=Yn(e.flags,"description"),o=await e.requireClient().cycles.propose({projectId:t,title:n,description:r});if(e.json)return e.stdout(k(j(Xn.name,o))),0;return e.stdout(`${A([["project",t],["title",n],["status",o.adopted?"adopted — the project is planning it now":"recorded — it will be planned on the next pass"]])}
|
|
195
|
-
`),0}},Zn={name:"tasks create",summary:"Add a task to a project's board",usage:["Usage: hlix tasks create <project-id> --description <d> [--title <t>] [--json]","","Creates the task row. It does NOT start it: standalone task execution is","not implemented server-side and answers 501 by design. Work is dispatched","by its cycle — use `hlix cycles create` for that."].join(`
|
|
196
|
-
`),supportsJson:!0,options:["title","description"],args:{min:1,max:1},async run(e){let t=e.args[0],n=Yn(e.flags,"description"),r=typeof e.flags.title==="string"?e.flags.title:void 0,o=await e.requireClient().tasks.create({projectId:t,description:n,...r?{title:r}:{}});if(e.json)return e.stdout(k(j(Zn.name,o))),0;return e.stdout(`${A([["task",o.id],["project",t],["status",o.status??"queued"],["note","not started — dispatch with `hlix cycles create`"]])}
|
|
197
|
-
`),0}},Qn={name:"harness get",summary:"Show which coder runs, and which setting chose it",usage:["Usage: hlix harness get [project-id] [--json]","","With a project id, what that project would run. Without one, the","workspace-wide answer. `source` names the setting that decided: a project","preference, the workspace preference, or the system default."].join(`
|
|
198
|
-
`),supportsJson:!0,args:{min:0,max:1},async run(e){let t=e.args[0],n=e.requireClient(),r=t?await n.modelConfig.resolvedProjectHarness(t):await n.modelConfig.resolvedHarness();if(e.json)return e.stdout(k(j(Qn.name,r))),0;return e.stdout(`${A([["scope",t?`project ${t}`:"workspace"],["harness",r.harness],["source",r.source]])}
|
|
199
|
-
`),0}},er={name:"harness set",summary:"Choose the coder a project or the workspace runs",usage:[`Usage: hlix harness set <${ve.join("|")}> [project-id] [--org] [--json]`,"","With a project id, sets that project's preference. With --org, the","workspace-wide one that projects fall back to. This is a PERSISTENT server","setting that every future run on that scope uses, and it is audited.","","It is not the same thing as the local `harness` config key, which only","picks the coder Hlix Code spawns on this machine."].join(`
|
|
200
|
-
`),supportsJson:!0,options:["org"],args:{min:1,max:2},async run(e){let t=e.args[0];if(!ve.includes(t))throw new y("invalid_usage",`harness must be one of ${ve.join(", ")}; got "${t}".`);let n=e.args[1],r=e.flags.org===!0;if(n&&r)throw new y("invalid_usage","Name a project or pass --org, not both: they are different scopes.");if(!n&&!r)throw new y("invalid_usage","Name the project to set, or pass --org for the whole workspace.");let o=e.requireClient(),s=n?await o.modelConfig.setProjectHarness(n,t):await o.modelConfig.setHarness(t);if(e.json)return e.stdout(k(j(er.name,s))),0;return e.stdout(`${A([["scope",n?`project ${n}`:"workspace"],["harness",t]])}
|
|
201
|
-
`),0}};var Hp=[on,an,Se,Rn,Tn,In,xn,cn,ln,dn,En,kt,$t,Et,jt,Dn,Kn,Jn,Gn,qn,Wn,Pt,Vn,pn,un,fn,gn,hn,yn,Zn,Xn,Qn,er];
|
|
202
|
-
export{y as a,Qa as b,N as c,J as d,Po as e,Gc as f,To as g,Or as h,ve as i,nl as j,Zt as k,Oo as l,Mr as m,gt as n,cl as o,nn as p,Vr as q,ll as r,Yr as s,Zr as t,dl as u,pl as v,ul as w,Hp as x};
|